codemp/cgame/cg_snapshot.c File Reference

#include "cg_local.h"

Go to the source code of this file.

Functions

void CG_SetInitialSnapshot (snapshot_t *snap)
qboolean CG_UsingEWeb (void)
void CG_ProcessSnapshots (void)


Function Documentation

void CG_ProcessSnapshots void   ) 
 

Definition at line 338 of file cg_snapshot.c.

References cg, CG_Error(), CG_SetInitialSnapshot(), cg_t::latestSnapshotNum, cg_t::latestSnapshotTime, cg_t::nextSnap, NULL, snapshot_t::serverTime, cg_t::snap, SNAPFLAG_NOT_ACTIVE, snapshot_t::snapFlags, cg_t::time, and trap_GetCurrentSnapshotNumber().

Referenced by CG_DrawActiveFrame().

00338                                  {
00339         snapshot_t              *snap;
00340         int                             n;
00341 
00342         // see what the latest snapshot the client system has is
00343         trap_GetCurrentSnapshotNumber( &n, &cg.latestSnapshotTime );
00344         if ( n != cg.latestSnapshotNum ) {
00345                 if ( n < cg.latestSnapshotNum ) {
00346                         // this should never happen
00347                         CG_Error( "CG_ProcessSnapshots: n < cg.latestSnapshotNum" );
00348                 }
00349                 cg.latestSnapshotNum = n;
00350         }
00351 
00352         // If we have yet to receive a snapshot, check for it.
00353         // Once we have gotten the first snapshot, cg.snap will
00354         // always have valid data for the rest of the game
00355         while ( !cg.snap ) {
00356                 snap = CG_ReadNextSnapshot();
00357                 if ( !snap ) {
00358                         // we can't continue until we get a snapshot
00359                         return;
00360                 }
00361 
00362                 // set our weapon selection to what
00363                 // the playerstate is currently using
00364                 if ( !( snap->snapFlags & SNAPFLAG_NOT_ACTIVE ) ) {
00365                         CG_SetInitialSnapshot( snap );
00366                 }
00367         }
00368 
00369         // loop until we either have a valid nextSnap with a serverTime
00370         // greater than cg.time to interpolate towards, or we run
00371         // out of available snapshots
00372         do {
00373                 // if we don't have a nextframe, try and read a new one in
00374                 if ( !cg.nextSnap ) {
00375                         snap = CG_ReadNextSnapshot();
00376 
00377                         // if we still don't have a nextframe, we will just have to
00378                         // extrapolate
00379                         if ( !snap ) {
00380                                 break;
00381                         }
00382 
00383                         CG_SetNextSnap( snap );
00384 
00385 
00386                         // if time went backwards, we have a level restart
00387                         if ( cg.nextSnap->serverTime < cg.snap->serverTime ) {
00388                                 CG_Error( "CG_ProcessSnapshots: Server time went backwards" );
00389                         }
00390                 }
00391 
00392                 // if our time is < nextFrame's, we have a nice interpolating state
00393                 if ( cg.time >= cg.snap->serverTime && cg.time < cg.nextSnap->serverTime ) {
00394                         break;
00395                 }
00396 
00397                 // we have passed the transition from nextFrame to frame
00398                 CG_TransitionSnapshot();
00399         } while ( 1 );
00400 
00401         // assert our valid conditions upon exiting
00402         if ( cg.snap == NULL ) {
00403                 CG_Error( "CG_ProcessSnapshots: cg.snap == NULL" );
00404         }
00405         if ( cg.time < cg.snap->serverTime ) {
00406                 // this can happen right after a vid_restart
00407                 cg.time = cg.snap->serverTime;
00408         }
00409         if ( cg.nextSnap != NULL && cg.nextSnap->serverTime <= cg.time ) {
00410                 CG_Error( "CG_ProcessSnapshots: cg.nextSnap->serverTime <= cg.time" );
00411         }
00412 
00413 }

void CG_SetInitialSnapshot snapshot_t snap  ) 
 

Definition at line 80 of file cg_snapshot.c.

References BG_PlayerStateToEntityState(), centity_t, cg, CG_BuildSolidList(), CG_CheckEvents(), CG_CopyG2WeaponInstance(), cg_entities, CG_ExecuteNewServerCommands(), CG_Respawn(), cgs, cgs_t::clientinfo, playerState_s::clientNum, centity_s::currentState, centity_s::currentValid, snapshot_t::entities, entityState_t, FIRST_WEAPON, centity_s::interpolate, memcpy(), NULL, entityState_s::number, snapshot_t::numEntities, snapshot_t::ps, qfalse, qtrue, snapshot_t::serverCommandSequence, cg_t::snap, trap_G2_HaveWeGhoul2Models(), trap_G2API_AddBolt(), and trap_G2API_DuplicateGhoul2Instance().

Referenced by CG_ProcessSnapshots().

00080                                                {
00081         int                             i;
00082         centity_t               *cent;
00083         entityState_t   *state;
00084 
00085         cg.snap = snap; 
00086 
00087         if ((cg_entities[snap->ps.clientNum].ghoul2 == NULL) && trap_G2_HaveWeGhoul2Models(cgs.clientinfo[snap->ps.clientNum].ghoul2Model))
00088         {
00089                 trap_G2API_DuplicateGhoul2Instance(cgs.clientinfo[snap->ps.clientNum].ghoul2Model, &cg_entities[snap->ps.clientNum].ghoul2);
00090                 CG_CopyG2WeaponInstance(&cg_entities[snap->ps.clientNum], FIRST_WEAPON, cg_entities[snap->ps.clientNum].ghoul2);
00091                 
00092                 if (trap_G2API_AddBolt(cg_entities[snap->ps.clientNum].ghoul2, 0, "face") == -1)
00093                 { //check now to see if we have this bone for setting anims and such
00094                         cg_entities[snap->ps.clientNum].noFace = qtrue;
00095                 }
00096         }
00097         BG_PlayerStateToEntityState( &snap->ps, &cg_entities[ snap->ps.clientNum ].currentState, qfalse );
00098 
00099         // sort out solid entities
00100         CG_BuildSolidList();
00101 
00102         CG_ExecuteNewServerCommands( snap->serverCommandSequence );
00103 
00104         // set our local weapon selection pointer to
00105         // what the server has indicated the current weapon is
00106         CG_Respawn();
00107 
00108         for ( i = 0 ; i < cg.snap->numEntities ; i++ ) {
00109                 state = &cg.snap->entities[ i ];
00110                 cent = &cg_entities[ state->number ];
00111 
00112                 memcpy(&cent->currentState, state, sizeof(entityState_t));
00113                 //cent->currentState = *state;
00114                 cent->interpolate = qfalse;
00115                 cent->currentValid = qtrue;
00116 
00117                 CG_ResetEntity( cent );
00118 
00119                 // check for events
00120                 CG_CheckEvents( cent );
00121         }
00122 }

qboolean CG_UsingEWeb void   ) 
 

Definition at line 920 of file cg_predict.c.

References cg, cg_entities, playerState_s::emplacedIndex, cg_t::predictedPlayerState, qboolean, qfalse, qtrue, playerState_s::weapon, WP_EMPLACED_GUN, and WP_NONE.

Referenced by CG_PredictPlayerState().

00921 {
00922         if (cg.predictedPlayerState.weapon == WP_EMPLACED_GUN && cg.predictedPlayerState.emplacedIndex &&
00923                 cg_entities[cg.predictedPlayerState.emplacedIndex].currentState.weapon == WP_NONE)
00924         {
00925                 return qtrue;
00926         }
00927 
00928         return qfalse;
00929 }