From c0e95997d9e9fcaa220704c8c67b50d6761d1b66 Mon Sep 17 00:00:00 2001 From: Tim Angus Date: Mon, 9 Sep 2002 23:32:27 +0000 Subject: * General tidy up and beautification of code * Removal of most of the legacy Q3A stuff * Cursor no longer displayed on load screen * (Biggest commit EVAR?) --- src/cgame/cg_players.c | 1225 +++++++++++++++++++++++------------------------- 1 file changed, 595 insertions(+), 630 deletions(-) (limited to 'src/cgame/cg_players.c') diff --git a/src/cgame/cg_players.c b/src/cgame/cg_players.c index 09098e31..b553fbc2 100644 --- a/src/cgame/cg_players.c +++ b/src/cgame/cg_players.c @@ -17,7 +17,8 @@ #include "cg_local.h" -char *cg_customSoundNames[MAX_CUSTOM_SOUNDS] = { +char *cg_customSoundNames[ MAX_CUSTOM_SOUNDS ] = +{ "*death1.wav", "*death2.wav", "*death3.wav", @@ -40,23 +41,23 @@ CG_CustomSound ================ */ -sfxHandle_t CG_CustomSound( int clientNum, const char *soundName ) { - clientInfo_t *ci; - int i; +sfxHandle_t CG_CustomSound( int clientNum, const char *soundName ) +{ + clientInfo_t *ci; + int i; - if ( soundName[0] != '*' ) { + if( soundName[ 0 ] != '*' ) return trap_S_RegisterSound( soundName, qfalse ); - } - if ( clientNum < 0 || clientNum >= MAX_CLIENTS ) { + if( clientNum < 0 || clientNum >= MAX_CLIENTS ) clientNum = 0; - } + ci = &cgs.clientinfo[ clientNum ]; - for ( i = 0 ; i < MAX_CUSTOM_SOUNDS && cg_customSoundNames[i] ; i++ ) { - if ( !strcmp( soundName, cg_customSoundNames[i] ) ) { - return ci->sounds[i]; - } + for( i = 0; i < MAX_CUSTOM_SOUNDS && cg_customSoundNames[ i ]; i++ ) + { + if( !strcmp( soundName, cg_customSoundNames[ i ] ) ) + return ci->sounds[ i ]; } CG_Error( "Unknown custom sound: %s", soundName ); @@ -81,30 +82,33 @@ Read a configuration file containing animation coutns and rates models/players/visor/animation.cfg, etc ====================== */ -static qboolean CG_ParseAnimationFile( const char *filename, clientInfo_t *ci ) { - char *text_p, *prev; - int len; - int i; - char *token; - float fps; - int skip; - char text[20000]; +static qboolean CG_ParseAnimationFile( const char *filename, clientInfo_t *ci ) +{ + char *text_p, *prev; + int len; + int i; + char *token; + float fps; + int skip; + char text[ 20000 ]; fileHandle_t f; - animation_t *animations; + animation_t *animations; animations = ci->animations; // load the file len = trap_FS_FOpenFile( filename, &f, FS_READ ); - if ( len <= 0 ) { + if( len <= 0 ) return qfalse; - } - if ( len >= sizeof( text ) - 1 ) { + + if( len >= sizeof( text ) - 1 ) + { CG_Printf( "File %s too long\n", filename ); return qfalse; } + trap_FS_Read( text, len, f ); - text[len] = 0; + text[ len ] = 0; trap_FS_FCloseFile( f ); // parse the text @@ -118,166 +122,184 @@ static qboolean CG_ParseAnimationFile( const char *filename, clientInfo_t *ci ) ci->fixedtorso = qfalse; // read optional parameters - while ( 1 ) { + while( 1 ) + { prev = text_p; // so we can unget token = COM_Parse( &text_p ); - if ( !token ) { + + if( !token ) break; - } - if ( !Q_stricmp( token, "footsteps" ) ) { + + if( !Q_stricmp( token, "footsteps" ) ) + { token = COM_Parse( &text_p ); - if ( !token ) { + if( !token ) break; - } - if ( !Q_stricmp( token, "default" ) || !Q_stricmp( token, "normal" ) ) { + + if( !Q_stricmp( token, "default" ) || !Q_stricmp( token, "normal" ) ) ci->footsteps = FOOTSTEP_NORMAL; - } else if ( !Q_stricmp( token, "boot" ) ) { + else if( !Q_stricmp( token, "boot" ) ) ci->footsteps = FOOTSTEP_BOOT; - } else if ( !Q_stricmp( token, "flesh" ) ) { + else if( !Q_stricmp( token, "flesh" ) ) ci->footsteps = FOOTSTEP_FLESH; - } else if ( !Q_stricmp( token, "mech" ) ) { + else if( !Q_stricmp( token, "mech" ) ) ci->footsteps = FOOTSTEP_MECH; - } else if ( !Q_stricmp( token, "energy" ) ) { + else if( !Q_stricmp( token, "energy" ) ) ci->footsteps = FOOTSTEP_ENERGY; - } else { + else CG_Printf( "Bad footsteps parm in %s: %s\n", filename, token ); - } + continue; - } else if ( !Q_stricmp( token, "headoffset" ) ) { - for ( i = 0 ; i < 3 ; i++ ) { + } + else if( !Q_stricmp( token, "headoffset" ) ) + { + for( i = 0 ; i < 3 ; i++ ) + { token = COM_Parse( &text_p ); - if ( !token ) { + if( !token ) break; - } - ci->headOffset[i] = atof( token ); + + ci->headOffset[ i ] = atof( token ); } + continue; - } else if ( !Q_stricmp( token, "sex" ) ) { + } + else if( !Q_stricmp( token, "sex" ) ) + { token = COM_Parse( &text_p ); - if ( !token ) { + + if( !token ) break; - } - if ( token[0] == 'f' || token[0] == 'F' ) { + + if( token[ 0 ] == 'f' || token[ 0 ] == 'F' ) ci->gender = GENDER_FEMALE; - } else if ( token[0] == 'n' || token[0] == 'N' ) { + else if( token[ 0 ] == 'n' || token[ 0 ] == 'N' ) ci->gender = GENDER_NEUTER; - } else { + else ci->gender = GENDER_MALE; - } + continue; - } else if ( !Q_stricmp( token, "fixedlegs" ) ) { + } + else if( !Q_stricmp( token, "fixedlegs" ) ) + { ci->fixedlegs = qtrue; continue; - } else if ( !Q_stricmp( token, "fixedtorso" ) ) { + } + else if( !Q_stricmp( token, "fixedtorso" ) ) + { ci->fixedtorso = qtrue; continue; } // if it is a number, start parsing animations - if ( token[0] >= '0' && token[0] <= '9' ) { + if( token[ 0 ] >= '0' && token[ 0 ] <= '9' ) + { text_p = prev; // unget the token break; } + Com_Printf( "unknown token '%s' is %s\n", token, filename ); } // read information for each frame - for ( i = 0 ; i < MAX_PLAYER_ANIMATIONS ; i++ ) { - + for( i = 0; i < MAX_PLAYER_ANIMATIONS; i++ ) + { token = COM_Parse( &text_p ); - if ( !*token ) { - if( i >= TORSO_GETFLAG && i <= TORSO_NEGATIVE ) { - animations[i].firstFrame = animations[TORSO_GESTURE].firstFrame; - animations[i].frameLerp = animations[TORSO_GESTURE].frameLerp; - animations[i].initialLerp = animations[TORSO_GESTURE].initialLerp; - animations[i].loopFrames = animations[TORSO_GESTURE].loopFrames; - animations[i].numFrames = animations[TORSO_GESTURE].numFrames; - animations[i].reversed = qfalse; - animations[i].flipflop = qfalse; + + if( !*token ) + { + if( i >= TORSO_GETFLAG && i <= TORSO_NEGATIVE ) + { + animations[ i ].firstFrame = animations[ TORSO_GESTURE ].firstFrame; + animations[ i ].frameLerp = animations[ TORSO_GESTURE ].frameLerp; + animations[ i ].initialLerp = animations[ TORSO_GESTURE ].initialLerp; + animations[ i ].loopFrames = animations[ TORSO_GESTURE ].loopFrames; + animations[ i ].numFrames = animations[ TORSO_GESTURE ].numFrames; + animations[ i ].reversed = qfalse; + animations[ i ].flipflop = qfalse; continue; } + break; } - animations[i].firstFrame = atoi( token ); + + animations[ i ].firstFrame = atoi( token ); + // leg only frames are adjusted to not count the upper body only frames - if ( i == LEGS_WALKCR ) { - skip = animations[LEGS_WALKCR].firstFrame - animations[TORSO_GESTURE].firstFrame; - } - if ( i >= LEGS_WALKCR && i= LEGS_WALKCR && ilegsSkin = trap_R_RegisterSkin( filename ); - if (!ci->legsSkin) { + if( !ci->legsSkin ) Com_Printf( "Leg skin load failure: %s\n", filename ); - } Com_sprintf( filename, sizeof( filename ), "models/players/%s/upper_%s.skin", modelName, skinName ); ci->torsoSkin = trap_R_RegisterSkin( filename ); - if (!ci->torsoSkin) { + if( !ci->torsoSkin ) Com_Printf( "Torso skin load failure: %s\n", filename ); - } Com_sprintf( filename, sizeof( filename ), "models/players/%s/head_%s.skin", modelName, skinName ); ci->headSkin = trap_R_RegisterSkin( filename ); - if (!ci->headSkin) { + if( !ci->headSkin ) Com_Printf( "Head skin load failure: %s\n", filename ); - } - if ( !ci->legsSkin || !ci->torsoSkin || !ci->headSkin ) { + if( !ci->legsSkin || !ci->torsoSkin || !ci->headSkin ) return qfalse; - } return qtrue; } @@ -319,48 +338,55 @@ static qboolean CG_RegisterClientSkin( clientInfo_t *ci, const char *modelName, CG_RegisterClientModelname ========================== */ -static qboolean CG_RegisterClientModelname( clientInfo_t *ci, const char *modelName, const char *skinName ) { - char filename[MAX_QPATH*2]; +static qboolean CG_RegisterClientModelname( clientInfo_t *ci, const char *modelName, const char *skinName ) +{ + char filename[ MAX_QPATH * 2 ]; // load cmodels before models so filecache works Com_sprintf( filename, sizeof( filename ), "models/players/%s/lower.md3", modelName ); ci->legsModel = trap_R_RegisterModel( filename ); - if ( !ci->legsModel ) { + if( !ci->legsModel ) + { Com_Printf( "Failed to load model file %s\n", filename ); return qfalse; } Com_sprintf( filename, sizeof( filename ), "models/players/%s/upper.md3", modelName ); ci->torsoModel = trap_R_RegisterModel( filename ); - if ( !ci->torsoModel ) { + if( !ci->torsoModel ) + { Com_Printf( "Failed to load model file %s\n", filename ); return qfalse; } Com_sprintf( filename, sizeof( filename ), "models/players/%s/head.md3", modelName ); ci->headModel = trap_R_RegisterModel( filename ); - if ( !ci->headModel ) { + if( !ci->headModel ) + { Com_Printf( "Failed to load model file %s\n", filename ); return qfalse; } // if any skins failed to load, return failure - if ( !CG_RegisterClientSkin( ci, modelName, skinName ) ) { + if( !CG_RegisterClientSkin( ci, modelName, skinName ) ) + { Com_Printf( "Failed to load skin file: %s : %s\n", modelName, skinName ); return qfalse; } // load the animations Com_sprintf( filename, sizeof( filename ), "models/players/%s/animation.cfg", modelName ); - if ( !CG_ParseAnimationFile( filename, ci ) ) { + if( !CG_ParseAnimationFile( filename, ci ) ) + { Com_Printf( "Failed to load animation file %s\n", filename ); return qfalse; } Com_sprintf( filename, sizeof( filename ), "models/players/%s/icon_%s.tga", modelName, skinName ); ci->modelIcon = trap_R_RegisterShaderNoMip( filename ); - if ( !ci->modelIcon ) { + if( !ci->modelIcon ) + { Com_Printf( "Failed to load icon file: %s\n", filename ); return qfalse; } @@ -373,27 +399,28 @@ static qboolean CG_RegisterClientModelname( clientInfo_t *ci, const char *modelN CG_ColorFromString ==================== */ -static void CG_ColorFromString( const char *v, vec3_t color ) { +static void CG_ColorFromString( const char *v, vec3_t color ) +{ int val; VectorClear( color ); val = atoi( v ); - if ( val < 1 || val > 7 ) { + if( val < 1 || val > 7 ) + { VectorSet( color, 1, 1, 1 ); return; } - if ( val & 1 ) { - color[2] = 1.0f; - } - if ( val & 2 ) { - color[1] = 1.0f; - } - if ( val & 4 ) { - color[0] = 1.0f; - } + if( val & 1 ) + color[ 2 ] = 1.0f; + + if( val & 2 ) + color[ 1 ] = 1.0f; + + if( val & 4 ) + color[ 0 ] = 1.0f; } @@ -405,16 +432,17 @@ Load it now, taking the disk hits. This will usually be deferred to a safe time =================== */ -static void CG_LoadClientInfo( clientInfo_t *ci ) { +static void CG_LoadClientInfo( clientInfo_t *ci ) +{ const char *dir, *fallback; - int i; + int i; const char *s; - int clientNum; + int clientNum; - if ( !CG_RegisterClientModelname( ci, ci->modelName, ci->skinName ) ) { - if ( cg_buildScript.integer ) { + if( !CG_RegisterClientModelname( ci, ci->modelName, ci->skinName ) ) + { + if( cg_buildScript.integer ) CG_Error( "CG_RegisterClientModelname( %s, %s ) failed", ci->modelName, ci->skinName ); - } // fall back if( !CG_RegisterClientModelname( ci, DEFAULT_MODEL, "default" ) ) @@ -425,15 +453,16 @@ static void CG_LoadClientInfo( clientInfo_t *ci ) { dir = ci->modelName; fallback = DEFAULT_MODEL; - for ( i = 0 ; i < MAX_CUSTOM_SOUNDS ; i++ ) { - s = cg_customSoundNames[i]; - if ( !s ) { + for( i = 0 ; i < MAX_CUSTOM_SOUNDS ; i++ ) + { + s = cg_customSoundNames[ i ]; + + if( !s ) break; - } - ci->sounds[i] = trap_S_RegisterSound( va("sound/player/%s/%s", dir, s + 1), qfalse ); - if ( !ci->sounds[i] ) { - ci->sounds[i] = trap_S_RegisterSound( va("sound/player/%s/%s", fallback, s + 1), qfalse ); - } + + ci->sounds[ i ] = trap_S_RegisterSound( va( "sound/player/%s/%s", dir, s + 1 ), qfalse ); + if( !ci->sounds[ i ] ) + ci->sounds[ i ] = trap_S_RegisterSound( va( "sound/player/%s/%s", fallback, s + 1 ), qfalse ); } ci->deferred = qfalse; @@ -443,11 +472,11 @@ static void CG_LoadClientInfo( clientInfo_t *ci ) { if( clientNum <= MAX_CLIENTS ) { clientNum = ci - cgs.clientinfo; - for ( i = 0 ; i < MAX_GENTITIES ; i++ ) { - if ( cg_entities[i].currentState.clientNum == clientNum - && cg_entities[i].currentState.eType == ET_PLAYER ) { - CG_ResetPlayerEntity( &cg_entities[i] ); - } + for( i = 0; i < MAX_GENTITIES; i++ ) + { + if( cg_entities[ i ].currentState.clientNum == clientNum && + cg_entities[ i ].currentState.eType == ET_PLAYER ) + CG_ResetPlayerEntity( &cg_entities[ i ] ); } } } @@ -457,7 +486,8 @@ static void CG_LoadClientInfo( clientInfo_t *ci ) { CG_CopyClientInfoModel ====================== */ -static void CG_CopyClientInfoModel( clientInfo_t *from, clientInfo_t *to ) { +static void CG_CopyClientInfoModel( clientInfo_t *from, clientInfo_t *to ) +{ VectorCopy( from->headOffset, to->headOffset ); to->footsteps = from->footsteps; to->gender = from->gender; @@ -480,24 +510,27 @@ static void CG_CopyClientInfoModel( clientInfo_t *from, clientInfo_t *to ) { CG_GetCorpseNum ====================== */ -static int CG_GetCorpseNum( int pclass ) { +static int CG_GetCorpseNum( int pclass ) +{ int i; clientInfo_t *match; char *modelName; modelName = BG_FindModelNameForClass( pclass ); - for ( i = PCL_NONE + 1 ; i < PCL_NUM_CLASSES; i++ ) + for( i = PCL_NONE + 1; i < PCL_NUM_CLASSES; i++ ) { match = &cgs.corpseinfo[ i ]; - if ( !match->infoValid ) + + if( !match->infoValid ) continue; - if ( match->deferred ) + if( match->deferred ) continue; - if ( !Q_stricmp( modelName, match->modelName ) - /*&& !Q_stricmp( modelName, match->skinName )*/ ) { + if( !Q_stricmp( modelName, match->modelName ) + /*&& !Q_stricmp( modelName, match->skinName )*/ ) + { // this clientinfo is identical, so use it's handles return i; } @@ -513,22 +546,24 @@ static int CG_GetCorpseNum( int pclass ) { CG_ScanForExistingClientInfo ====================== */ -static qboolean CG_ScanForExistingClientInfo( clientInfo_t *ci ) { +static qboolean CG_ScanForExistingClientInfo( clientInfo_t *ci ) +{ int i; clientInfo_t *match; - for ( i = 0 ; i < cgs.maxclients ; i++ ) { + for( i = 0 ; i < cgs.maxclients ; i++ ) + { match = &cgs.clientinfo[ i ]; - if ( !match->infoValid ) { + if( !match->infoValid ) continue; - } - if ( match->deferred ) { + + if( match->deferred ) continue; - } - if ( !Q_stricmp( ci->modelName, match->modelName ) - && !Q_stricmp( ci->skinName, match->skinName ) ) { - // this clientinfo is identical, so use it's handles + if( !Q_stricmp( ci->modelName, match->modelName ) && + !Q_stricmp( ci->skinName, match->skinName ) ) + { + // this clientinfo is identical, so use it's handles ci->deferred = qfalse; CG_CopyClientInfoModel( match, ci ); @@ -549,16 +584,17 @@ We aren't going to load it now, so grab some other client's info to use until we have some spare time. ====================== */ -static void CG_SetDeferredClientInfo( clientInfo_t *ci ) { - int i; +static void CG_SetDeferredClientInfo( clientInfo_t *ci ) +{ + int i; clientInfo_t *match; // find the first valid clientinfo and grab its stuff - for ( i = 0 ; i < cgs.maxclients ; i++ ) { + for( i = 0; i < cgs.maxclients; i++ ) + { match = &cgs.clientinfo[ i ]; - if ( !match->infoValid ) { + if( !match->infoValid ) continue; - } ci->deferred = qtrue; CG_CopyClientInfoModel( match, ci ); @@ -577,28 +613,28 @@ static void CG_SetDeferredClientInfo( clientInfo_t *ci ) { CG_PrecacheClientInfo ====================== */ -void CG_PrecacheClientInfo( int clientNum ) { - clientInfo_t *ci; - clientInfo_t newInfo; - const char *configstring; - const char *v; - char *slash; +void CG_PrecacheClientInfo( int clientNum ) +{ + clientInfo_t *ci; + clientInfo_t newInfo; + const char *configstring; + const char *v; + char *slash; ci = &cgs.corpseinfo[ clientNum ]; //CG_Printf( "%d %d\n", clientNum, (clientNum - MAX_CLIENTS ) ); configstring = CG_ConfigString( clientNum + CS_PRECACHES ); - if ( !configstring[0] ) { + if( !configstring[ 0 ] ) return; // player just left - } // build into a temp buffer so the defer checks can use // the old value memset( &newInfo, 0, sizeof( newInfo ) ); // isolate the player's name - v = Info_ValueForKey(configstring, "n"); + v = Info_ValueForKey( configstring, "n" ); Q_strncpyz( newInfo.name, v, sizeof( newInfo.name ) ); // colors @@ -630,27 +666,30 @@ void CG_PrecacheClientInfo( int clientNum ) { // team task v = Info_ValueForKey( configstring, "tt" ); - newInfo.teamTask = atoi(v); + newInfo.teamTask = atoi( v ); // team leader v = Info_ValueForKey( configstring, "tl" ); - newInfo.teamLeader = atoi(v); + newInfo.teamLeader = atoi( v ); v = Info_ValueForKey( configstring, "g_redteam" ); - Q_strncpyz(newInfo.redTeam, v, MAX_TEAMNAME); + Q_strncpyz( newInfo.redTeam, v, MAX_TEAMNAME ); v = Info_ValueForKey( configstring, "g_blueteam" ); - Q_strncpyz(newInfo.blueTeam, v, MAX_TEAMNAME); + Q_strncpyz( newInfo.blueTeam, v, MAX_TEAMNAME ); // model v = Info_ValueForKey( configstring, "model" ); Q_strncpyz( newInfo.modelName, v, sizeof( newInfo.modelName ) ); slash = strchr( newInfo.modelName, '/' ); - if ( !slash ) { + if( !slash ) + { // modelName didn not include a skin name Q_strncpyz( newInfo.skinName, "default", sizeof( newInfo.skinName ) ); - } else { + } + else + { Q_strncpyz( newInfo.skinName, slash + 1, sizeof( newInfo.skinName ) ); // truncate modelName *slash = 0; @@ -663,10 +702,14 @@ void CG_PrecacheClientInfo( int clientNum ) { Q_strncpyz( newInfo.headModelName, v, sizeof( newInfo.headModelName ) ); slash = strchr( newInfo.headModelName, '/' ); - if ( !slash ) { + + if( !slash ) + { // modelName didn not include a skin name Q_strncpyz( newInfo.headSkinName, "default", sizeof( newInfo.headSkinName ) ); - } else { + } + else + { Q_strncpyz( newInfo.headSkinName, slash + 1, sizeof( newInfo.headSkinName ) ); // truncate modelName *slash = 0; @@ -684,17 +727,19 @@ void CG_PrecacheClientInfo( int clientNum ) { CG_NewClientInfo ====================== */ -void CG_NewClientInfo( int clientNum ) { - clientInfo_t *ci; - clientInfo_t newInfo; - const char *configstring; - const char *v; - char *slash; +void CG_NewClientInfo( int clientNum ) +{ + clientInfo_t *ci; + clientInfo_t newInfo; + const char *configstring; + const char *v; + char *slash; - ci = &cgs.clientinfo[clientNum]; + ci = &cgs.clientinfo[ clientNum ]; configstring = CG_ConfigString( clientNum + CS_PLAYERS ); - if ( !configstring[0] ) { + if( !configstring[0] ) + { memset( ci, 0, sizeof( *ci ) ); return; // player just left } @@ -704,7 +749,7 @@ void CG_NewClientInfo( int clientNum ) { memset( &newInfo, 0, sizeof( newInfo ) ); // isolate the player's name - v = Info_ValueForKey(configstring, "n"); + v = Info_ValueForKey( configstring, "n" ); Q_strncpyz( newInfo.name, v, sizeof( newInfo.name ) ); // colors @@ -736,27 +781,31 @@ void CG_NewClientInfo( int clientNum ) { // team task v = Info_ValueForKey( configstring, "tt" ); - newInfo.teamTask = atoi(v); + newInfo.teamTask = atoi( v ); // team leader v = Info_ValueForKey( configstring, "tl" ); - newInfo.teamLeader = atoi(v); + newInfo.teamLeader = atoi( v ); v = Info_ValueForKey( configstring, "g_redteam" ); - Q_strncpyz(newInfo.redTeam, v, MAX_TEAMNAME); + Q_strncpyz( newInfo.redTeam, v, MAX_TEAMNAME ); v = Info_ValueForKey( configstring, "g_blueteam" ); - Q_strncpyz(newInfo.blueTeam, v, MAX_TEAMNAME); + Q_strncpyz( newInfo.blueTeam, v, MAX_TEAMNAME ); // model v = Info_ValueForKey( configstring, "model" ); Q_strncpyz( newInfo.modelName, v, sizeof( newInfo.modelName ) ); slash = strchr( newInfo.modelName, '/' ); - if ( !slash ) { + + if( !slash ) + { // modelName didn not include a skin name Q_strncpyz( newInfo.skinName, "default", sizeof( newInfo.skinName ) ); - } else { + } + else + { Q_strncpyz( newInfo.skinName, slash + 1, sizeof( newInfo.skinName ) ); // truncate modelName *slash = 0; @@ -769,10 +818,14 @@ void CG_NewClientInfo( int clientNum ) { Q_strncpyz( newInfo.headModelName, v, sizeof( newInfo.headModelName ) ); slash = strchr( newInfo.headModelName, '/' ); - if ( !slash ) { + + if( !slash ) + { // modelName didn not include a skin name Q_strncpyz( newInfo.headSkinName, "default", sizeof( newInfo.headSkinName ) ); - } else { + } + else + { Q_strncpyz( newInfo.headSkinName, slash + 1, sizeof( newInfo.headSkinName ) ); // truncate modelName *slash = 0; @@ -780,18 +833,18 @@ void CG_NewClientInfo( int clientNum ) { // scan for an existing clientinfo that matches this modelname // so we can avoid loading checks if possible - if ( !CG_ScanForExistingClientInfo( &newInfo ) ) { + if( !CG_ScanForExistingClientInfo( &newInfo ) ) + { qboolean forceDefer; - forceDefer = trap_MemoryRemaining() < 4000000; + forceDefer = trap_MemoryRemaining( ) < 4000000; // if we are defering loads, just have it pick the first valid //TA: we should only defer models when ABSOLUTELY TOTALLY necessary since models are precached - if ( forceDefer ) //|| ( cg_deferPlayers.integer && !cg_buildScript.integer && !cg.loading ) ) + if( forceDefer ) { // keep whatever they had if it won't violate team skins - if ( ci->infoValid && - ( !Q_stricmp( newInfo.skinName, ci->skinName ) ) ) + if ( ci->infoValid && ( !Q_stricmp( newInfo.skinName, ci->skinName ) ) ) { CG_CopyClientInfoModel( ci, &newInfo ); newInfo.deferred = qtrue; @@ -803,16 +856,14 @@ void CG_NewClientInfo( int clientNum ) { } // if we are low on memory, leave them with this model - if ( forceDefer ) + if( forceDefer ) { CG_Printf( "Memory is low. Using deferred model.\n" ); newInfo.deferred = qfalse; } } else - { CG_LoadClientInfo( &newInfo ); - } } // replace whatever was there with the new one @@ -831,21 +882,25 @@ and the scoreboard is up so deferred players can be loaded ====================== */ -void CG_LoadDeferredPlayers( void ) { - int i; +void CG_LoadDeferredPlayers( void ) +{ + int i; clientInfo_t *ci; // scan for a deferred player to load - for ( i = 0, ci = cgs.clientinfo ; i < cgs.maxclients ; i++, ci++ ) { - if ( ci->infoValid && ci->deferred ) { + for( i = 0, ci = cgs.clientinfo; i < cgs.maxclients; i++, ci++ ) + { + if( ci->infoValid && ci->deferred ) + { // if we are low on memory, leave it deferred - if ( trap_MemoryRemaining() < 4000000 ) { + if( trap_MemoryRemaining( ) < 4000000 ) + { CG_Printf( "Memory is low. Using deferred model.\n" ); ci->deferred = qfalse; continue; } + CG_LoadClientInfo( ci ); -// break; } } } @@ -866,24 +921,23 @@ CG_SetLerpFrameAnimation may include ANIM_TOGGLEBIT =============== */ -static void CG_SetLerpFrameAnimation( clientInfo_t *ci, lerpFrame_t *lf, int newAnimation ) { +static void CG_SetLerpFrameAnimation( clientInfo_t *ci, lerpFrame_t *lf, int newAnimation ) +{ animation_t *anim; lf->animationNumber = newAnimation; newAnimation &= ~ANIM_TOGGLEBIT; - if ( newAnimation < 0 || newAnimation >= MAX_PLAYER_TOTALANIMATIONS ) { + if( newAnimation < 0 || newAnimation >= MAX_PLAYER_TOTALANIMATIONS ) CG_Error( "Bad animation number: %i", newAnimation ); - } anim = &ci->animations[ newAnimation ]; lf->animation = anim; lf->animationTime = lf->frameTime + anim->initialLerp; - if ( cg_debugAnim.integer ) { + if( cg_debugAnim.integer ) CG_Printf( "Anim: %i\n", newAnimation ); - } } /* @@ -894,85 +948,92 @@ Sets cg.snap, cg.oldFrame, and cg.backlerp cg.time should be between oldFrameTime and frameTime after exit =============== */ -static void CG_RunLerpFrame( clientInfo_t *ci, lerpFrame_t *lf, int newAnimation, float speedScale ) { - int f, numFrames; +static void CG_RunLerpFrame( clientInfo_t *ci, lerpFrame_t *lf, int newAnimation, float speedScale ) +{ + int f, numFrames; animation_t *anim; // debugging tool to get no animations - if ( cg_animSpeed.integer == 0 ) { + if( cg_animSpeed.integer == 0 ) + { lf->oldFrame = lf->frame = lf->backlerp = 0; return; } // see if the animation sequence is switching - if ( newAnimation != lf->animationNumber || !lf->animation ) { + if( newAnimation != lf->animationNumber || !lf->animation ) + { CG_SetLerpFrameAnimation( ci, lf, newAnimation ); } // if we have passed the current frame, move it to // oldFrame and calculate a new frame - if ( cg.time >= lf->frameTime ) { + if( cg.time >= lf->frameTime ) + { lf->oldFrame = lf->frame; lf->oldFrameTime = lf->frameTime; // get the next frame based on the animation anim = lf->animation; - if ( !anim->frameLerp ) { + if( !anim->frameLerp ) return; // shouldn't happen - } - if ( cg.time < lf->animationTime ) { + + if( cg.time < lf->animationTime ) lf->frameTime = lf->animationTime; // initial lerp - } else { + else lf->frameTime = lf->oldFrameTime + anim->frameLerp; - } + f = ( lf->frameTime - lf->animationTime ) / anim->frameLerp; f *= speedScale; // adjust for haste, etc numFrames = anim->numFrames; - if (anim->flipflop) { + + if( anim->flipflop ) numFrames *= 2; - } - if ( f >= numFrames ) { + + if( f >= numFrames ) + { f -= numFrames; - if ( anim->loopFrames ) { + if( anim->loopFrames ) + { f %= anim->loopFrames; f += anim->numFrames - anim->loopFrames; - } else { + } + else + { f = numFrames - 1; // the animation is stuck at the end, so it // can immediately transition to another sequence lf->frameTime = cg.time; } } - if ( anim->reversed ) { + + if( anim->reversed ) lf->frame = anim->firstFrame + anim->numFrames - 1 - f; - } - else if (anim->flipflop && f>=anim->numFrames) { - lf->frame = anim->firstFrame + anim->numFrames - 1 - (f%anim->numFrames); - } - else { + else if( anim->flipflop && f>=anim->numFrames ) + lf->frame = anim->firstFrame + anim->numFrames - 1 - ( f % anim->numFrames ); + else lf->frame = anim->firstFrame + f; - } - if ( cg.time > lf->frameTime ) { + + if( cg.time > lf->frameTime ) + { lf->frameTime = cg.time; - if ( cg_debugAnim.integer ) { - CG_Printf( "Clamp lf->frameTime\n"); - } + + if( cg_debugAnim.integer ) + CG_Printf( "Clamp lf->frameTime\n" ); } } - if ( lf->frameTime > cg.time + 200 ) { + if( lf->frameTime > cg.time + 200 ) lf->frameTime = cg.time; - } - if ( lf->oldFrameTime > cg.time ) { + if( lf->oldFrameTime > cg.time ) lf->oldFrameTime = cg.time; - } + // calculate current lerp value - if ( lf->frameTime == lf->oldFrameTime ) { + if( lf->frameTime == lf->oldFrameTime ) lf->backlerp = 0; - } else { + else lf->backlerp = 1.0 - (float)( cg.time - lf->oldFrameTime ) / ( lf->frameTime - lf->oldFrameTime ); - } } @@ -981,7 +1042,8 @@ static void CG_RunLerpFrame( clientInfo_t *ci, lerpFrame_t *lf, int newAnimation CG_ClearLerpFrame =============== */ -static void CG_ClearLerpFrame( clientInfo_t *ci, lerpFrame_t *lf, int animationNumber ) { +static void CG_ClearLerpFrame( clientInfo_t *ci, lerpFrame_t *lf, int animationNumber ) +{ lf->frameTime = lf->oldFrameTime = cg.time; CG_SetLerpFrameAnimation( ci, lf, animationNumber ); lf->oldFrame = lf->frame = lf->animation->firstFrame; @@ -994,32 +1056,27 @@ CG_PlayerAnimation =============== */ static void CG_PlayerAnimation( centity_t *cent, int *legsOld, int *legs, float *legsBackLerp, - int *torsoOld, int *torso, float *torsoBackLerp ) { + int *torsoOld, int *torso, float *torsoBackLerp ) +{ clientInfo_t *ci; - int clientNum; - float speedScale; + int clientNum; + float speedScale = 1.0f; clientNum = cent->currentState.clientNum; - if ( cg_noPlayerAnims.integer ) { + if( cg_noPlayerAnims.integer ) + { *legsOld = *legs = *torsoOld = *torso = 0; return; } - /*if ( cent->currentState.powerups & ( 1 << PW_HASTE ) ) { - speedScale = 1.5; - } else*/ { - speedScale = 1; - } - ci = &cgs.clientinfo[ clientNum ]; // do the shuffle turn frames locally - if ( cent->pe.legs.yawing && ( cent->currentState.legsAnim & ~ANIM_TOGGLEBIT ) == LEGS_IDLE ) { + if( cent->pe.legs.yawing && ( cent->currentState.legsAnim & ~ANIM_TOGGLEBIT ) == LEGS_IDLE ) CG_RunLerpFrame( ci, ¢->pe.legs, LEGS_TURN, speedScale ); - } else { + else CG_RunLerpFrame( ci, ¢->pe.legs, cent->currentState.legsAnim, speedScale ); - } *legsOld = cent->pe.legs.oldFrame; *legs = cent->pe.legs.frame; @@ -1046,46 +1103,54 @@ CG_SwingAngles ================== */ static void CG_SwingAngles( float destination, float swingTolerance, float clampTolerance, - float speed, float *angle, qboolean *swinging ) { + float speed, float *angle, qboolean *swinging ) +{ float swing; float move; float scale; - if ( !*swinging ) { + if( !*swinging ) + { // see if a swing should be started swing = AngleSubtract( *angle, destination ); - if ( swing > swingTolerance || swing < -swingTolerance ) { + + if( swing > swingTolerance || swing < -swingTolerance ) *swinging = qtrue; - } } - if ( !*swinging ) { + if( !*swinging ) return; - } // modify the speed depending on the delta // so it doesn't seem so linear swing = AngleSubtract( destination, *angle ); scale = fabs( swing ); - if ( scale < swingTolerance * 0.5 ) { + + if( scale < swingTolerance * 0.5 ) scale = 0.5; - } else if ( scale < swingTolerance ) { + else if( scale < swingTolerance ) scale = 1.0; - } else { + else scale = 2.0; - } // swing towards the destination angle - if ( swing >= 0 ) { + if( swing >= 0 ) + { move = cg.frametime * scale * speed; - if ( move >= swing ) { + + if( move >= swing ) + { move = swing; *swinging = qfalse; } *angle = AngleMod( *angle + move ); - } else if ( swing < 0 ) { + } + else if( swing < 0 ) + { move = cg.frametime * scale * -speed; - if ( move <= swing ) { + + if( move <= swing ) + { move = swing; *swinging = qfalse; } @@ -1094,11 +1159,10 @@ static void CG_SwingAngles( float destination, float swingTolerance, float clamp // clamp to no more than tolerance swing = AngleSubtract( destination, *angle ); - if ( swing > clampTolerance ) { - *angle = AngleMod( destination - (clampTolerance - 1) ); - } else if ( swing < -clampTolerance ) { - *angle = AngleMod( destination + (clampTolerance - 1) ); - } + if( swing > clampTolerance ) + *angle = AngleMod( destination - ( clampTolerance - 1 ) ); + else if( swing < -clampTolerance ) + *angle = AngleMod( destination + ( clampTolerance - 1 ) ); } /* @@ -1106,22 +1170,22 @@ static void CG_SwingAngles( float destination, float swingTolerance, float clamp CG_AddPainTwitch ================= */ -static void CG_AddPainTwitch( centity_t *cent, vec3_t torsoAngles ) { +static void CG_AddPainTwitch( centity_t *cent, vec3_t torsoAngles ) +{ int t; float f; t = cg.time - cent->pe.painTime; - if ( t >= PAIN_TWITCH_TIME ) { + + if( t >= PAIN_TWITCH_TIME ) return; - } f = 1.0 - (float)t / PAIN_TWITCH_TIME; - if ( cent->pe.painDirection ) { - torsoAngles[ROLL] += 20 * f; - } else { - torsoAngles[ROLL] -= 20 * f; - } + if( cent->pe.painDirection ) + torsoAngles[ ROLL ] += 20 * f; + else + torsoAngles[ ROLL ] -= 20 * f; } @@ -1139,26 +1203,28 @@ Handles seperate torso motion if < 45 degrees, also show in torso =============== */ -static void CG_PlayerAngles( centity_t *cent, vec3_t srcAngles, vec3_t legs[3], vec3_t torso[3], vec3_t head[3] ) +static void CG_PlayerAngles( centity_t *cent, vec3_t srcAngles, + vec3_t legs[ 3 ], vec3_t torso[ 3 ], vec3_t head[ 3 ] ) { - vec3_t legsAngles, torsoAngles, headAngles; - float dest; - static int movementOffsets[8] = { 0, 22, 45, -22, 0, 22, -45, -22 }; - vec3_t velocity; - float speed; - int dir, clientNum; + vec3_t legsAngles, torsoAngles, headAngles; + float dest; + static int movementOffsets[ 8 ] = { 0, 22, 45, -22, 0, 22, -45, -22 }; + vec3_t velocity; + float speed; + int dir, clientNum; clientInfo_t *ci; VectorCopy( srcAngles, headAngles ); - headAngles[YAW] = AngleMod( headAngles[YAW] ); + headAngles[ YAW ] = AngleMod( headAngles[ YAW ] ); VectorClear( legsAngles ); VectorClear( torsoAngles ); // --------- yaw ------------- // allow yaw to drift a bit - if ( ( cent->currentState.legsAnim & ~ANIM_TOGGLEBIT ) != LEGS_IDLE - || ( cent->currentState.torsoAnim & ~ANIM_TOGGLEBIT ) != TORSO_STAND ) { + if( ( cent->currentState.legsAnim & ~ANIM_TOGGLEBIT ) != LEGS_IDLE || + ( cent->currentState.torsoAnim & ~ANIM_TOGGLEBIT ) != TORSO_STAND ) + { // if not standing still, always point all in the same direction cent->pe.torso.yawing = qtrue; // always center cent->pe.torso.pitching = qtrue; // always center @@ -1166,56 +1232,60 @@ static void CG_PlayerAngles( centity_t *cent, vec3_t srcAngles, vec3_t legs[3], } // adjust legs for movement dir - if ( cent->currentState.eFlags & EF_DEAD ) { + if( cent->currentState.eFlags & EF_DEAD ) + { // don't let dead bodies twitch dir = 0; - } else { + } + else + { //TA: did use angles2.. now uses time2.. looks a bit funny but time2 isn't used othwise dir = cent->currentState.time2; - if ( dir < 0 || dir > 7 ) { + if( dir < 0 || dir > 7 ) CG_Error( "Bad player movement angle" ); - } } - legsAngles[YAW] = headAngles[YAW] + movementOffsets[ dir ]; - torsoAngles[YAW] = headAngles[YAW] + 0.25 * movementOffsets[ dir ]; + + legsAngles[ YAW ] = headAngles[ YAW ] + movementOffsets[ dir ]; + torsoAngles[ YAW ] = headAngles[ YAW ] + 0.25 * movementOffsets[ dir ]; // torso if( cent->currentState.eFlags & EF_DEAD ) { - CG_SwingAngles( torsoAngles[YAW], 0, 0, cg_swingSpeed.value, + CG_SwingAngles( torsoAngles[ YAW ], 0, 0, cg_swingSpeed.value, ¢->pe.torso.yawAngle, ¢->pe.torso.yawing ); - CG_SwingAngles( legsAngles[YAW], 0, 0, cg_swingSpeed.value, + CG_SwingAngles( legsAngles[ YAW ], 0, 0, cg_swingSpeed.value, ¢->pe.legs.yawAngle, ¢->pe.legs.yawing ); } else { - CG_SwingAngles( torsoAngles[YAW], 25, 90, cg_swingSpeed.value, + CG_SwingAngles( torsoAngles[ YAW ], 25, 90, cg_swingSpeed.value, ¢->pe.torso.yawAngle, ¢->pe.torso.yawing ); - CG_SwingAngles( legsAngles[YAW], 40, 90, cg_swingSpeed.value, + CG_SwingAngles( legsAngles[ YAW ], 40, 90, cg_swingSpeed.value, ¢->pe.legs.yawAngle, ¢->pe.legs.yawing ); } - torsoAngles[YAW] = cent->pe.torso.yawAngle; - legsAngles[YAW] = cent->pe.legs.yawAngle; + torsoAngles[ YAW ] = cent->pe.torso.yawAngle; + legsAngles[ YAW ] = cent->pe.legs.yawAngle; // --------- pitch ------------- // only show a fraction of the pitch angle in the torso - if ( headAngles[PITCH] > 180 ) { - dest = (-360 + headAngles[PITCH]) * 0.75f; - } else { - dest = headAngles[PITCH] * 0.75f; - } + if( headAngles[ PITCH ] > 180 ) + dest = ( -360 + headAngles[ PITCH ] ) * 0.75f; + else + dest = headAngles[ PITCH ] * 0.75f; + CG_SwingAngles( dest, 15, 30, 0.1f, ¢->pe.torso.pitchAngle, ¢->pe.torso.pitching ); - torsoAngles[PITCH] = cent->pe.torso.pitchAngle; + torsoAngles[ PITCH ] = cent->pe.torso.pitchAngle; // clientNum = cent->currentState.clientNum; - if ( clientNum >= 0 && clientNum < MAX_CLIENTS ) { + + if( clientNum >= 0 && clientNum < MAX_CLIENTS ) + { ci = &cgs.clientinfo[ clientNum ]; - if ( ci->fixedtorso ) { - torsoAngles[PITCH] = 0.0f; - } + if( ci->fixedtorso ) + torsoAngles[ PITCH ] = 0.0f; } // --------- roll ------------- @@ -1224,28 +1294,34 @@ static void CG_PlayerAngles( centity_t *cent, vec3_t srcAngles, vec3_t legs[3], // lean towards the direction of travel VectorCopy( cent->currentState.pos.trDelta, velocity ); speed = VectorNormalize( velocity ); - if ( speed ) { - vec3_t axis[3]; - float side; + + if( speed ) + { + vec3_t axis[ 3 ]; + float side; speed *= 0.05f; AnglesToAxis( legsAngles, axis ); - side = speed * DotProduct( velocity, axis[1] ); - legsAngles[ROLL] -= side; + side = speed * DotProduct( velocity, axis[ 1 ] ); + legsAngles[ ROLL ] -= side; - side = speed * DotProduct( velocity, axis[0] ); - legsAngles[PITCH] += side; + side = speed * DotProduct( velocity, axis[ 0 ] ); + legsAngles[ PITCH ] += side; } // clientNum = cent->currentState.clientNum; - if ( clientNum >= 0 && clientNum < MAX_CLIENTS ) { + + if( clientNum >= 0 && clientNum < MAX_CLIENTS ) + { ci = &cgs.clientinfo[ clientNum ]; - if ( ci->fixedlegs ) { - legsAngles[YAW] = torsoAngles[YAW]; - legsAngles[PITCH] = 0.0f; - legsAngles[ROLL] = 0.0f; + + if( ci->fixedlegs ) + { + legsAngles[ YAW ] = torsoAngles[ YAW ]; + legsAngles[ PITCH ] = 0.0f; + legsAngles[ ROLL ] = 0.0f; } } @@ -1263,70 +1339,6 @@ static void CG_PlayerAngles( centity_t *cent, vec3_t srcAngles, vec3_t legs[3], //========================================================================== -/* -=============== -CG_HasteTrail -=============== -*/ -static void CG_HasteTrail( centity_t *cent ) { - localEntity_t *smoke; - vec3_t origin; - int anim; - - if ( cent->trailTime > cg.time ) { - return; - } - anim = cent->pe.legs.animationNumber & ~ANIM_TOGGLEBIT; - if ( anim != LEGS_RUN && anim != LEGS_BACK ) { - return; - } - - cent->trailTime += 100; - if ( cent->trailTime < cg.time ) { - cent->trailTime = cg.time; - } - - VectorCopy( cent->lerpOrigin, origin ); - origin[2] -= 16; - - smoke = CG_SmokePuff( origin, vec3_origin, - 8, - 1, 1, 1, 1, - 500, - cg.time, - 0, - 0, - cgs.media.hastePuffShader ); - - // use the optimized local entity add - smoke->leType = LE_SCALE_FADE; -} - -/* -=============== -CG_TrailItem -=============== -*/ -static void CG_TrailItem( centity_t *cent, qhandle_t hModel ) { - refEntity_t ent; - vec3_t angles; - vec3_t axis[3]; - - VectorCopy( cent->lerpAngles, angles ); - angles[PITCH] = 0; - angles[ROLL] = 0; - AnglesToAxis( angles, axis ); - - memset( &ent, 0, sizeof( ent ) ); - VectorMA( cent->lerpOrigin, -16, axis[0], ent.origin ); - ent.origin[2] += 16; - angles[YAW] += 90; - AnglesToAxis( angles, ent.axis ); - - ent.hModel = hModel; - trap_R_AddRefEntityToScene( &ent ); -} - #define JET_SPREAD 30.0f #define JET_LIFETIME 1500 @@ -1404,37 +1416,6 @@ static void CG_PlayerUpgrades( centity_t *cent, refEntity_t *torso ) } } } - /*powerups = cent->currentState.powerups; - if ( !powerups ) { - return; - } - - // quad gives a dlight - if ( powerups & ( 1 << PW_QUAD ) ) { - trap_R_AddLightToScene( cent->lerpOrigin, 200 + (rand()&31), 0.2, 0.2, 1 ); - } - - // flight plays a looped sound - if ( powerups & ( 1 << PW_FLIGHT ) ) { - trap_S_AddLoopingSound( cent->currentState.number, cent->lerpOrigin, vec3_origin, cgs.media.flightSound ); - } - - // redflag - if ( powerups & ( 1 << PW_REDFLAG ) ) { - CG_TrailItem( cent, cgs.media.redFlagModel ); - trap_R_AddLightToScene( cent->lerpOrigin, 200 + (rand()&31), 1, 0.2, 0.2 ); - } - - // blueflag - if ( powerups & ( 1 << PW_BLUEFLAG ) ) { - CG_TrailItem( cent, cgs.media.blueFlagModel ); - trap_R_AddLightToScene( cent->lerpOrigin, 200 + (rand()&31), 0.2, 0.2, 1 ); - } - - // haste leaves smoke trails - if ( powerups & ( 1 << PW_HASTE ) ) { - CG_HasteTrail( cent ); - }*/ } @@ -1445,27 +1426,27 @@ CG_PlayerFloatSprite Float a sprite over the player's head =============== */ -static void CG_PlayerFloatSprite( centity_t *cent, qhandle_t shader ) { - int rf; +static void CG_PlayerFloatSprite( centity_t *cent, qhandle_t shader ) +{ + int rf; refEntity_t ent; - if ( cent->currentState.number == cg.snap->ps.clientNum && !cg.renderingThirdPerson ) { + if( cent->currentState.number == cg.snap->ps.clientNum && !cg.renderingThirdPerson ) rf = RF_THIRD_PERSON; // only show in mirrors - } else { + else rf = 0; - } memset( &ent, 0, sizeof( ent ) ); VectorCopy( cent->lerpOrigin, ent.origin ); - ent.origin[2] += 48; + ent.origin[ 2 ] += 48; ent.reType = RT_SPRITE; ent.customShader = shader; ent.radius = 10; ent.renderfx = rf; - ent.shaderRGBA[0] = 255; - ent.shaderRGBA[1] = 255; - ent.shaderRGBA[2] = 255; - ent.shaderRGBA[3] = 255; + ent.shaderRGBA[ 0 ] = 255; + ent.shaderRGBA[ 1 ] = 255; + ent.shaderRGBA[ 2 ] = 255; + ent.shaderRGBA[ 3 ] = 255; trap_R_AddRefEntityToScene( &ent ); } @@ -1503,38 +1484,31 @@ Returns the Z component of the surface being shadowed =============== */ #define SHADOW_DISTANCE 128 -static qboolean CG_PlayerShadow( centity_t *cent, float *shadowPlane ) { - vec3_t end, mins = {-15, -15, 0}, maxs = {15, 15, 2}; +static qboolean CG_PlayerShadow( centity_t *cent, float *shadowPlane ) +{ + vec3_t end, mins = { -15, -15, 0 }, maxs = { 15, 15, 2 }; trace_t trace; - float alpha; + float alpha; *shadowPlane = 0; - if ( cg_shadows.integer == 0 ) { - return qfalse; - } - - // no shadows when invisible - /*if ( cent->currentState.powerups & ( 1 << PW_INVIS ) ) { + if( cg_shadows.integer == 0 ) return qfalse; - }*/ // send a trace down from the player to the ground VectorCopy( cent->lerpOrigin, end ); - end[2] -= SHADOW_DISTANCE; + end[ 2 ] -= SHADOW_DISTANCE; trap_CM_BoxTrace( &trace, cent->lerpOrigin, end, mins, maxs, 0, MASK_PLAYERSOLID ); // no shadow if too high - if ( trace.fraction == 1.0 || trace.startsolid || trace.allsolid ) { + if( trace.fraction == 1.0 || trace.startsolid || trace.allsolid ) return qfalse; - } - *shadowPlane = trace.endpos[2] + 1; + *shadowPlane = trace.endpos[ 2 ] + 1; - if ( cg_shadows.integer != 1 ) { // no mark for stencil or projection shadows + if( cg_shadows.integer != 1 ) // no mark for stencil or projection shadows return qtrue; - } // fade the shadow out with height alpha = 1.0 - trace.fraction; @@ -1542,7 +1516,7 @@ static qboolean CG_PlayerShadow( centity_t *cent, float *shadowPlane ) { // add the mark as a temporary, so it goes directly to the renderer // without taking a spot in the cg_marks array CG_ImpactMark( cgs.media.shadowMarkShader, trace.endpos, trace.plane.normal, - cent->pe.legs.yawAngle, alpha,alpha,alpha,1, qfalse, 24, qtrue ); + cent->pe.legs.yawAngle, alpha,alpha,alpha,1, qfalse, 24, qtrue ); return qtrue; } @@ -1555,82 +1529,81 @@ CG_PlayerSplash Draw a mark at the water surface =============== */ -static void CG_PlayerSplash( centity_t *cent ) { - vec3_t start, end; - trace_t trace; - int contents; - polyVert_t verts[4]; +static void CG_PlayerSplash( centity_t *cent ) +{ + vec3_t start, end; + trace_t trace; + int contents; + polyVert_t verts[ 4 ]; - if ( !cg_shadows.integer ) { + if( !cg_shadows.integer ) return; - } VectorCopy( cent->lerpOrigin, end ); - end[2] -= 24; + end[ 2 ] -= 24; // if the feet aren't in liquid, don't make a mark // this won't handle moving water brushes, but they wouldn't draw right anyway... contents = trap_CM_PointContents( end, 0 ); - if ( !( contents & ( CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ) ) ) { + + if( !( contents & ( CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ) ) ) return; - } VectorCopy( cent->lerpOrigin, start ); - start[2] += 32; + start[ 2 ] += 32; // if the head isn't out of liquid, don't make a mark contents = trap_CM_PointContents( start, 0 ); - if ( contents & ( CONTENTS_SOLID | CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ) ) { + + if( contents & ( CONTENTS_SOLID | CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ) ) return; - } // trace down to find the surface trap_CM_BoxTrace( &trace, start, end, NULL, NULL, 0, ( CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ) ); - if ( trace.fraction == 1.0 ) { + if( trace.fraction == 1.0 ) return; - } // create a mark polygon - VectorCopy( trace.endpos, verts[0].xyz ); - verts[0].xyz[0] -= 32; - verts[0].xyz[1] -= 32; - verts[0].st[0] = 0; - verts[0].st[1] = 0; - verts[0].modulate[0] = 255; - verts[0].modulate[1] = 255; - verts[0].modulate[2] = 255; - verts[0].modulate[3] = 255; - - VectorCopy( trace.endpos, verts[1].xyz ); - verts[1].xyz[0] -= 32; - verts[1].xyz[1] += 32; - verts[1].st[0] = 0; - verts[1].st[1] = 1; - verts[1].modulate[0] = 255; - verts[1].modulate[1] = 255; - verts[1].modulate[2] = 255; - verts[1].modulate[3] = 255; - - VectorCopy( trace.endpos, verts[2].xyz ); - verts[2].xyz[0] += 32; - verts[2].xyz[1] += 32; - verts[2].st[0] = 1; - verts[2].st[1] = 1; - verts[2].modulate[0] = 255; - verts[2].modulate[1] = 255; - verts[2].modulate[2] = 255; - verts[2].modulate[3] = 255; - - VectorCopy( trace.endpos, verts[3].xyz ); - verts[3].xyz[0] += 32; - verts[3].xyz[1] -= 32; - verts[3].st[0] = 1; - verts[3].st[1] = 0; - verts[3].modulate[0] = 255; - verts[3].modulate[1] = 255; - verts[3].modulate[2] = 255; - verts[3].modulate[3] = 255; + VectorCopy( trace.endpos, verts[ 0 ].xyz ); + verts[ 0 ].xyz[ 0 ] -= 32; + verts[ 0 ].xyz[ 1 ] -= 32; + verts[ 0 ].st[ 0 ] = 0; + verts[ 0 ].st[ 1 ] = 0; + verts[ 0 ].modulate[ 0 ] = 255; + verts[ 0 ].modulate[ 1 ] = 255; + verts[ 0 ].modulate[ 2 ] = 255; + verts[ 0 ].modulate[ 3 ] = 255; + + VectorCopy( trace.endpos, verts[ 1 ].xyz ); + verts[ 1 ].xyz[ 0 ] -= 32; + verts[ 1 ].xyz[ 1 ] += 32; + verts[ 1 ].st[ 0 ] = 0; + verts[ 1 ].st[ 1 ] = 1; + verts[ 1 ].modulate[ 0 ] = 255; + verts[ 1 ].modulate[ 1 ] = 255; + verts[ 1 ].modulate[ 2 ] = 255; + verts[ 1 ].modulate[ 3 ] = 255; + + VectorCopy( trace.endpos, verts[ 2 ].xyz ); + verts[ 2 ].xyz[ 0 ] += 32; + verts[ 2 ].xyz[ 1 ] += 32; + verts[ 2 ].st[ 0 ] = 1; + verts[ 2 ].st[ 1 ] = 1; + verts[ 2 ].modulate[ 0 ] = 255; + verts[ 2 ].modulate[ 1 ] = 255; + verts[ 2 ].modulate[ 2 ] = 255; + verts[ 2 ].modulate[ 3 ] = 255; + + VectorCopy( trace.endpos, verts[ 3 ].xyz ); + verts[ 3 ].xyz[ 0 ] += 32; + verts[ 3 ].xyz[ 1 ] -= 32; + verts[ 3 ].st[ 0 ] = 1; + verts[ 3 ].st[ 1 ] = 0; + verts[ 3 ].modulate[ 0 ] = 255; + verts[ 3 ].modulate[ 1 ] = 255; + verts[ 3 ].modulate[ 2 ] = 255; + verts[ 3 ].modulate[ 3 ] = 255; trap_R_AddPolyToScene( cgs.media.wakeMarkShader, 4, verts ); } @@ -1645,33 +1618,9 @@ Adds a piece with modifications or duplications for powerups Also called by CG_Missile for quad rockets, but nobody can tell... =============== */ -void CG_AddRefEntityWithPowerups( refEntity_t *ent, int powerups, int team ) { - - /*if ( powerups & ( 1 << PW_INVIS ) ) { - ent->customShader = cgs.media.invisShader; - trap_R_AddRefEntityToScene( ent ); - } else {*/ - trap_R_AddRefEntityToScene( ent ); - - /*if ( powerups & ( 1 << PW_QUAD ) ) - { - if (team == TEAM_HUMANS) - ent->customShader = cgs.media.redQuadShader; - else - ent->customShader = cgs.media.quadShader; - trap_R_AddRefEntityToScene( ent ); - } - if ( powerups & ( 1 << PW_REGEN ) ) { - if ( ( ( cg.time / 100 ) % 10 ) == 1 ) { - ent->customShader = cgs.media.regenShader; - trap_R_AddRefEntityToScene( ent ); - } - } - if ( powerups & ( 1 << PW_BATTLESUIT ) ) { - ent->customShader = cgs.media.battleSuitShader; - trap_R_AddRefEntityToScene( ent ); - } - }*/ +void CG_AddRefEntityWithPowerups( refEntity_t *ent, int powerups, int team ) +{ + trap_R_AddRefEntityToScene( ent ); } @@ -1688,36 +1637,43 @@ int CG_LightVerts( vec3_t normal, int numVerts, polyVert_t *verts ) vec3_t lightDir; vec3_t directedLight; - trap_R_LightForPoint( verts[0].xyz, ambientLight, directedLight, lightDir ); + trap_R_LightForPoint( verts[ 0 ].xyz, ambientLight, directedLight, lightDir ); - for (i = 0; i < numVerts; i++) { - incoming = DotProduct (normal, lightDir); - if ( incoming <= 0 ) { - verts[i].modulate[0] = ambientLight[0]; - verts[i].modulate[1] = ambientLight[1]; - verts[i].modulate[2] = ambientLight[2]; - verts[i].modulate[3] = 255; + for( i = 0; i < numVerts; i++ ) + { + incoming = DotProduct( normal, lightDir ); + + if( incoming <= 0 ) + { + verts[ i ].modulate[ 0 ] = ambientLight[ 0 ]; + verts[ i ].modulate[ 1 ] = ambientLight[ 1 ]; + verts[ i ].modulate[ 2 ] = ambientLight[ 2 ]; + verts[ i ].modulate[ 3 ] = 255; continue; } - j = ( ambientLight[0] + incoming * directedLight[0] ); - if ( j > 255 ) { + + j = ( ambientLight[ 0 ] + incoming * directedLight[ 0 ] ); + + if( j > 255 ) j = 255; - } - verts[i].modulate[0] = j; + + verts[ i ].modulate[ 0 ] = j; - j = ( ambientLight[1] + incoming * directedLight[1] ); - if ( j > 255 ) { + j = ( ambientLight[ 1 ] + incoming * directedLight[ 1 ] ); + + if( j > 255 ) j = 255; - } - verts[i].modulate[1] = j; - j = ( ambientLight[2] + incoming * directedLight[2] ); - if ( j > 255 ) { + verts[ i ].modulate[ 1 ] = j; + + j = ( ambientLight[ 2 ] + incoming * directedLight[ 2 ] ); + + if( j > 255 ) j = 255; - } - verts[i].modulate[2] = j; - verts[i].modulate[3] = 255; + verts[ i ].modulate[ 2 ] = j; + + verts[ i ].modulate[ 3 ] = 255; } return qtrue; } @@ -1739,33 +1695,38 @@ int CG_LightFromDirection( vec3_t point, vec3_t direction ) trap_R_LightForPoint( point, ambientLight, directedLight, lightDir ); - incoming = DotProduct (direction, lightDir); - if ( incoming <= 0 ) { - result[0] = ambientLight[0]; - result[1] = ambientLight[1]; - result[2] = ambientLight[2]; - return (int)((float)( result[0] + result[1] + result[2] ) / 3.0f ); + incoming = DotProduct( direction, lightDir ); + + if( incoming <= 0 ) + { + result[ 0 ] = ambientLight[ 0 ]; + result[ 1 ] = ambientLight[ 1 ]; + result[ 2 ] = ambientLight[ 2 ]; + return (int)( (float)( result[ 0 ] + result[ 1 ] + result[ 2 ] ) / 3.0f ); } - j = ( ambientLight[0] + incoming * directedLight[0] ); - if ( j > 255 ) { + j = ( ambientLight[ 0 ] + incoming * directedLight[ 0 ] ); + + if( j > 255 ) j = 255; - } - result[0] = j; - j = ( ambientLight[1] + incoming * directedLight[1] ); - if ( j > 255 ) { + result[ 0 ] = j; + + j = ( ambientLight[ 1 ] + incoming * directedLight[ 1 ] ); + + if( j > 255 ) j = 255; - } - result[1] = j; - j = ( ambientLight[2] + incoming * directedLight[2] ); - if ( j > 255 ) { + result[ 1 ] = j; + + j = ( ambientLight[ 2 ] + incoming * directedLight[ 2 ] ); + + if( j > 255 ) j = 255; - } - result[2] = j; - return (int)((float)( result[0] + result[1] + result[2] ) / 3.0f ); + result[ 2 ] = j; + + return (int)((float)( result[ 0 ] + result[ 1 ] + result[ 2 ] ) / 3.0f ); } @@ -1783,10 +1744,10 @@ int CG_AmbientLight( vec3_t point ) trap_R_LightForPoint( point, ambientLight, directedLight, lightDir ); - result[0] = ambientLight[0]; - result[1] = ambientLight[1]; - result[2] = ambientLight[2]; - return (int)((float)( result[0] + result[1] + result[2] ) / 3.0f ); + result[ 0 ] = ambientLight[ 0 ]; + result[ 1 ] = ambientLight[ 1 ]; + result[ 2 ] = ambientLight[ 2 ]; + return (int)((float)( result[ 0 ] + result[ 1 ] + result[ 2 ] ) / 3.0f ); } #define TRACE_DEPTH 128.0f @@ -1864,7 +1825,7 @@ void CG_Player( centity_t *cent ) // get the animation state (after rotation, to allow feet shuffle) CG_PlayerAnimation( cent, &legs.oldframe, &legs.frame, &legs.backlerp, - &torso.oldframe, &torso.frame, &torso.backlerp ); + &torso.oldframe, &torso.frame, &torso.backlerp ); // add the talk baloon or disconnect icon CG_PlayerSprites( cent ); @@ -1990,14 +1951,15 @@ void CG_Corpse( centity_t *cent ) refEntity_t legs; refEntity_t torso; refEntity_t head; - int corpseNum; - int renderfx; - qboolean shadow; - float shadowPlane; - vec3_t origin, liveZ, deadZ; + int corpseNum; + int renderfx; + qboolean shadow; + float shadowPlane; + vec3_t origin, liveZ, deadZ; corpseNum = CG_GetCorpseNum( cent->currentState.clientNum ); - if ( corpseNum < 0 || corpseNum >= MAX_CLIENTS ) + + if( corpseNum < 0 || corpseNum >= MAX_CLIENTS ) CG_Error( "Bad corpseNum on corpse entity: %d", corpseNum ); ci = &cgs.corpseinfo[ corpseNum ]; @@ -2007,9 +1969,9 @@ void CG_Corpse( centity_t *cent ) if( !ci->infoValid ) return; - memset( &legs, 0, sizeof(legs) ); - memset( &torso, 0, sizeof(torso) ); - memset( &head, 0, sizeof(head) ); + memset( &legs, 0, sizeof( legs ) ); + memset( &torso, 0, sizeof( torso ) ); + memset( &head, 0, sizeof( head ) ); VectorCopy( cent->lerpOrigin, origin ); BG_FindBBoxForClass( cent->currentState.clientNum, liveZ, NULL, NULL, deadZ, NULL ); @@ -2020,7 +1982,7 @@ void CG_Corpse( centity_t *cent ) CG_PlayerAngles( cent, cent->lerpAngles, legs.axis, torso.axis, head.axis ); //set the correct frame (should always be dead) - if ( cg_noPlayerAnims.integer ) + if( cg_noPlayerAnims.integer ) legs.oldframe = legs.frame = torso.oldframe = torso.frame = 0; else { @@ -2041,6 +2003,7 @@ void CG_Corpse( centity_t *cent ) // get the player model information renderfx = 0; + if( cg_shadows.integer == 3 && shadow ) renderfx |= RF_SHADOW_PLANE; @@ -2057,7 +2020,7 @@ void CG_Corpse( centity_t *cent ) VectorCopy( origin, legs.lightingOrigin ); legs.shadowPlane = shadowPlane; legs.renderfx = renderfx; - VectorCopy (legs.origin, legs.oldorigin); // don't positionally lerp at all + VectorCopy( legs.origin, legs.oldorigin ); // don't positionally lerp at all //CG_AddRefEntityWithPowerups( &legs, cent->currentState.powerups, ci->team ); trap_R_AddRefEntityToScene( &legs ); @@ -2077,7 +2040,7 @@ void CG_Corpse( centity_t *cent ) VectorCopy( origin, torso.lightingOrigin ); - CG_PositionRotatedEntityOnTag( &torso, &legs, ci->legsModel, "tag_torso"); + CG_PositionRotatedEntityOnTag( &torso, &legs, ci->legsModel, "tag_torso" ); torso.shadowPlane = shadowPlane; torso.renderfx = renderfx; @@ -2110,7 +2073,7 @@ void CG_Corpse( centity_t *cent ) cent->currentState.powerups == 65535 ) //65535 = 16bit signed -1 { //draw indicator - CG_PlayerFloatSprite( cent, cgs.media.medalImpressive ); + CG_PlayerFloatSprite( cent, cgs.media.friendShader ); } } } @@ -2125,12 +2088,15 @@ CG_ResetPlayerEntity A player just came into view or teleported, so reset all animation info =============== */ -void CG_ResetPlayerEntity( centity_t *cent ) { +void CG_ResetPlayerEntity( centity_t *cent ) +{ cent->errorTime = -99999; // guarantee no error decay added cent->extrapolated = qfalse; - CG_ClearLerpFrame( &cgs.clientinfo[ cent->currentState.clientNum ], ¢->pe.legs, cent->currentState.legsAnim ); - CG_ClearLerpFrame( &cgs.clientinfo[ cent->currentState.clientNum ], ¢->pe.torso, cent->currentState.torsoAnim ); + CG_ClearLerpFrame( &cgs.clientinfo[ cent->currentState.clientNum ], + ¢->pe.legs, cent->currentState.legsAnim ); + CG_ClearLerpFrame( &cgs.clientinfo[ cent->currentState.clientNum ], + ¢->pe.torso, cent->currentState.torsoAnim ); BG_EvaluateTrajectory( ¢->currentState.pos, cg.time, cent->lerpOrigin ); BG_EvaluateTrajectory( ¢->currentState.apos, cg.time, cent->lerpAngles ); @@ -2139,19 +2105,18 @@ void CG_ResetPlayerEntity( centity_t *cent ) { VectorCopy( cent->lerpAngles, cent->rawAngles ); memset( ¢->pe.legs, 0, sizeof( cent->pe.legs ) ); - cent->pe.legs.yawAngle = cent->rawAngles[YAW]; + cent->pe.legs.yawAngle = cent->rawAngles[ YAW ]; cent->pe.legs.yawing = qfalse; cent->pe.legs.pitchAngle = 0; cent->pe.legs.pitching = qfalse; memset( ¢->pe.torso, 0, sizeof( cent->pe.legs ) ); - cent->pe.torso.yawAngle = cent->rawAngles[YAW]; + cent->pe.torso.yawAngle = cent->rawAngles[ YAW ]; cent->pe.torso.yawing = qfalse; - cent->pe.torso.pitchAngle = cent->rawAngles[PITCH]; + cent->pe.torso.pitchAngle = cent->rawAngles[ PITCH ]; cent->pe.torso.pitching = qfalse; - if ( cg_debugPosition.integer ) { - CG_Printf("%i ResetPlayerEntity yaw=%i\n", cent->currentState.number, cent->pe.torso.yawAngle ); - } + if( cg_debugPosition.integer ) + CG_Printf( "%i ResetPlayerEntity yaw=%i\n", cent->currentState.number, cent->pe.torso.yawAngle ); } -- cgit