Doom 3 C++ Coding Style Conventions
Doom 3 C++ Coding Style Conventions
And
float f = 1.0f;
Instead of
float f = 1.f;
Function names start with an upper case:
void Function( void );
In multi-word function names each word starts with an upper case:
void ThisFunctionDoesSomething( void );
The standard header for functions is:
/*
====================
FunctionName
Description
====================
*/
Variable names start with a lower case character.
float x;
In multi-word variable names the first word starts with a lower case
character and each successive word starts with an upper case.
float maxDistanceFromPlane;
Typedef names use the same naming convention as variables, however
they always end with "_t".
typedef int fileHandle_t;
Struct names use the same naming convention as variables, however they
always end with "_t".
struct renderEntity_t;
Enum names use the same naming convention as variables, however they
always end with "_t". The enum constants use all upper case
characters. Multiple words are separated with an underscore.
enum contact_t {
CONTACT_NONE,
CONTACT_EDGE,
CONTACT_MODELVERTEX,
CONTACT_TRMVERTEX
};
Names of recursive functions end with "_r"
void WalkBSP_r( int node );
Defined names use all upper case characters. Multiple words are
separated with an underscore.
#define SIDE_FRONT
Class names start with "id" and each successive word starts with an
upper case.
class idVec3;
Class variables have the same naming convention as variables.
class idVec3 {
float
float
float
}
x;
y;
z;
Indent the names of class variables and class methods to make nice
columns. The variable type or method return type is in the first
column and the variable name or method name is in the second column.
class idVec3 {
float
float
float
float
const float *
}
x;
y;
z;
Length( void ) const;
ToFloatPtr( void ) const;
1.
2.
3.
4.
5.
6.
7.
For example,
//
//
//
//
//
dialog class
dialog control class
frame window
view window
any other class
FILE NAMES
--------Each class should be in a seperate source file unless it makes sense
to group several smaller classes.
The file name should be the same as the name of the class without the
"id" prefix. (Upper/lower case is preserved.)
class idWinding;
files:
Winding.cpp
Winding.h
When a class spans across multiple files these files have a name that
starts with the name of the class without "id", followed by an
underscore and a subsection name.
class idRenderWorld;
files:
RenderWorld_load.cpp
RenderWorld_demo.cpp
RenderWorld_portals.cpp
When a class is a public virtual interface to a subsystem the public
interface is implemented in a header file with the name of the class
without "id". The definition of the class that implements the
subsystem is placed in a header file with the name of the class
without "id" and ends with "_local.h". The implementation of the
subsystem is placed in a cpp file with the name of the class without
"id".
class idRenderWorld;
RenderWorld.h
RenderWorld_local.h
RenderWorld.cpp