Skip to content

Code Style

markitus18 edited this page Mar 11, 2016 · 44 revisions

#####Macros

Use ALL_CAPS separated by an underscore.

#define IN_RANGE

If macro’s replacement is not literal, it will be enclosed in parentheses.

#define RADTODEG( a ) (a * 180 / 3.1416 )

If macro needs more than one line, it will be defined by backslashes aligned at the end of the line.

#define CAP(x, m, M)    \  
{			            \  
    if (x < m)			\      
        x = m;			\
    if (x > M)			\ 
        x = M;			\
}

#####Enumerations
Enumerations names will be snake_case with uppercase in initials. It’s name will define what one component is.

enum Unit_Type

Enumerations components will be defined as well as macros.

enum Collision_State
{
    NONE,
    IN_PROCESS
    RESOLVED
}

#####File Names
File will be introduced by an uppercase letter acording to the file type, follow by an underscore and the file name. Files that dont have one of the file types won’t be introduced by the uppercase letter.

M_Input.cpp

File types will be:

  • Module
  • Container
  • Scene
  • UI

#####Variable Names
camelCase will be used for variable names, trying to define the variable purpose as clear as posible In case a variable has a sub-type, the variable name will be followed by an undrescore and the sub-type name

position_x
hpBar_mid

#####Functions
Function names will be in PascalCase

void ManageInput()

Function parameters: in case a function parameter needs the same name as a class variable, the parameter name will be introduced by an underscore

void SetPosition( _position )

Open braces come at the next line of the function declaration. Close braces come aligned to their respective braces.

void SetPosition( _position )
{
    if (_position != position)
    {
        position = _position;
        posChanged = true;
    }
    else
    {
        pasChanged = false;
    }
}

“Else” and “else if” come at the next line after the “if” closing braces, aligned with “if” position.

Clone this wiki locally