-
Notifications
You must be signed in to change notification settings - Fork 0
Coding Style
LegendGuard edited this page Apr 6, 2023
·
1 revision
To contribute Bid For Power (BFP) source code, you need to follow the Carmack or id dev coding style, this coding style exists on Quake 3 source code. Thus, the progammer can read much better the code and there isn't much clutter. Like the following examples:
- Way to write conditionals:
if ( cent->currentState.number == cg.snap->ps.clientNum ) {
Com_Printf( "That is your client number!/n" );
} else if ( cent->currentState.number != cg.snap->ps.clientNum ) {
Com_Printf( "This is not your client number, it is other client number, so, it is other guy!/n" );
} else {
Com_Printf( "No client number... what is that?/n" );
}- Way to write conditionals to check player status:
if ( cg.predictedPlayerState.pm_flags & PMF_KI_BOOST ) {
Com_Printf( "It is boosting!\n" );
} else if ( !( cent->currentState.eFlags & EF_DEAD ) ) {
Com_Printf( "It is alive!\n" );
}- Way to write conditionals if there are && and ||, only if these are longer:
if ( cg_thirdPerson.integer < 1
&& cent->currentState.number == cg.snap->ps.clientNum
&& !( cent->currentState.eFlags & EF_DEAD ) ) {
Com_Printf( "Using 1st person\n" );
}
if ( !( cg.predictedPlayerState.pm_flags & PMF_KI_BOOST )
|| !( cent->currentState.eFlags & EF_DEAD ) ) {
Com_Printf( "It is alive and it is not boosting\n" );
}- Way to write a new function, example:
/*
=================================
SomeFunction
Some description of this function
=================================
*/
void SomeFunction( int someParameter ) { // BFP - Some function for such feature
...
}- Way to call a function:
CG_Camera( cent, &torso, ci->torsoModel );Also, important: always comment labeling // BFP - Title/Description if the code was needed to change.
- Label
// BFP - TODO: Descriptionif the changed code needs a TODO task in that part. - Label
// BFP - TOFIX: Descriptionif the changed code needs a TOFIX task in that part. - Label
// BFP - NOTE: Descriptionif the changed code needs a note in that part.
It would better trying to avoid removing Quake 3 code to make know what/where was changed. So, if you comment some large code, use #if 0 macro instead /* */. Like this example:
// BFP - no team skin and model
#if 0
// fall back to default team name
if( cgs.gametype >= GT_TEAM) {
// keep skin name
if( ci->team == TEAM_BLUE ) {
Q_strncpyz(teamname, DEFAULT_BLUETEAM_NAME, sizeof(teamname) );
} else {
Q_strncpyz(teamname, DEFAULT_REDTEAM_NAME, sizeof(teamname) );
}
if ( !CG_RegisterClientModelname( ci, DEFAULT_TEAM_MODEL, ci->skinName, DEFAULT_TEAM_HEAD, ci->skinName, teamname ) ) {
CG_Error( "DEFAULT_TEAM_MODEL / skin (%s/%s) failed to register", DEFAULT_TEAM_MODEL, ci->skinName );
}
} else {
if ( !CG_RegisterClientModelname( ci, DEFAULT_MODEL, "default", DEFAULT_MODEL, "default", teamname ) ) {
CG_Error( "DEFAULT_MODEL (%s) failed to register", DEFAULT_MODEL );
}
}
#endif