AntiLight Programming Style Guide
Naming Conventions
Variable Prefixes (Hungarian Notation)
We use a readable form of Hungarian notation to indicate scope and type. Here's how:
| Prefix | Meaning | Example |
|---|---|---|
g_ |
Global variable | g_flFrameTime |
s_ |
Static variable | s_nCachedCount |
m_ |
Member variable | m_bIsReloading |
p |
Pointer | pOwner, ppOutput |
f |
Float | flDeltaTime, m_flSpeed |
n |
Integer | nIndex, m_nHealth |
b |
Boolean | bShouldFire, m_bAlive |
c |
Counter | cBullets, m_cShotsFired |
sz |
C-style string | szPlayerName, m_szModelPath |
Example Combination:
float m_flPreviousTime; // float member variable
bool m_bIsJumping; // boolean member variable
int m_nAmmo; // integer member variable
char m_szPlayerName[32]; // character array member variable
Type & Identifier Naming
Classes and Structs:
- Classes: PascalCase with
Cprefix →CBasePlayer,CWeaponBase - Structs: PascalCase →
Vector,Color
Enums:
- Enum Type: PascalCase →
PlayerState - Enum Values:
- For classic
enum: Use ALL_CAPS →PLAYER_IDLE,PLAYER_RUNNING - For
enum class: Use PascalCase →AssetType::Texture2D,RenderMode::Wire - For bitflags: Use ALL_CAPS with prefix →
RENDER_FLAG_SHADOW,PHYSICS_FLAG_STATIC
- For classic
Function & Method Naming
- Use PascalCase →
UpdatePosition(),GetHealth() - Boolean-returning methods use
Is,Has,Canprefixes →IsAlive(),HasAmmo(),CanJump()
Constants & Macros
- Use ALL_CAPS with underscores →
MAX_CLIENTS,PLAYER_HEIGHT - Prefer
constexprorinlinefunctions over#definemacros when possible
File Naming
We use lowercase file names with underscores, not class-style C prefixes.
General Rules
- Use lowercase letters with underscores (
snake_case). - Header files use
.h - Source files use
.cpp - File names reflect functionality, not the class name exactly.
- No
Cprefix in filenames, even if the class uses it.
Examples
| File Name | Class Name |
|---|---|
| weapon_rpg.cpp | CWeaponRPG |
| baseplayer.h | CBasePlayer |
| viewrender.cpp | CViewRender |
| client_render_targets.cpp | (Subsystem) |
| beamdraw.cpp | CBeam |
Avoid
CWeaponRPG.cppWeaponRPG.cpp
Prefer
weapon_rpg.cppviewrender.h
Notes
- Keep one class or module per
.cpp/.hpair whenever possible. - Match filenames to subsystems or key concepts when not tied to a single class.
Formatting and Syntax
Braces
For statements like if, else, for, while, etc, opening braces should be on the same line:
if (condition) {
DoSomething();
} else {
DoSomethingElse();
}
For function definitions and class/struct declarations opening braces should be on a new line:
void MyFunction()
{
// ...
}
Indentation
- Use tabs, not spaces
- Use 4-space visual alignment
Commenting
// Single-line
/* Multi-line */
/**
* Doxygen-style
*/
int GetHealth();
Best Practices
- Prefer clarity over cleverness
- Avoid magic numbers — use constants instead
- Use
nullptrinstead ofNULL - Explicitly initialize members in constructors
Example Class
class CPlayer
{
public:
CPlayer();
void Update(float flDeltaTime);
bool IsAlive() const;
private:
float m_flPreviousTime;
int m_nHealth;
bool m_bIsAlive;
char m_szName[64];
};