/* ============ CG_ProcessSnapshots We are trying to set up a renderable view, so determine what the simulated time is, and try to get snapshots both before and after that time if available. If we don't have a valid cg.snap after exiting this function, then a 3D game view cannot be rendered. This should only happen right after the initial connection. After cg.snap has been valid once, it will never turn invalid. Even if cg.snap is valid, cg.nextSnap may not be, if the snapshot hasn't arrived yet (it becomes an extrapolating situation instead of an interpolating one) ============ */ void CG_ProcessSnapshots( void ) { snapshot_t *snap; int n; // see what the latest snapshot the client system has is trap_GetCurrentSnapshotNumber( &n, &cg.latestSnapshotTime ); if ( n != cg.latestSnapshotNum ) { if ( n < cg.latestSnapshotNum ) { // this should never happen CG_Error( "CG_ProcessSnapshots: n < cg.latestSnapshotNum" ); } cg.latestSnapshotNum = n; } // If we have yet to receive a snapshot, check for it. // Once we have gotten the first snapshot, cg.snap will // always have valid data for the rest of the game while ( !cg.snap ) { snap = CG_ReadNextSnapshot(); if ( !snap ) { // we can't continue until we get a snapshot return; } // set our weapon selection to what // the playerstate is currently using if ( !( snap->snapFlags & SNAPFLAG_NOT_ACTIVE ) ) { CG_SetInitialSnapshot( snap ); } } // loop until we either have a valid nextSnap with a serverTime // greater than cg.time to interpolate towards, or we run // out of available snapshots do { // if we don't have a nextframe, try and read a new one in if ( !cg.nextSnap ) { snap = CG_ReadNextSnapshot(); // if we still don't have a nextframe, we will just have to // extrapolate if ( !snap ) { break; } CG_SetNextSnap( snap ); // if time went backwards, we have a level restart if ( cg.nextSnap->serverTime < cg.snap->serverTime ) { CG_Error( "CG_ProcessSnapshots: Server time went backwards" ); } } // if our time is < nextFrame's, we have a nice interpolating state if ( cg.time >= cg.snap->serverTime && cg.time < cg.nextSnap->serverTime ) { break; } // we have passed the transition from nextFrame to frame CG_TransitionSnapshot(); } while ( 1 ); // JUHOX: stop-movers-mechanism for lens flare editor #if MAPLENSFLARES if (cgs.editMode == EM_mlf) { if (cg.lfEditor.moversStopped) { int num; for (num = MAX_CLIENTS; num < ENTITYNUM_MAX_NORMAL; num++) { centity_t* cent; cent = &cg_entities[num]; if (cent->currentState.eType != ET_MOVER) continue; CG_StopMover(cent); } } else if ( cg.lfEditor.selectedLFEnt && cg.lfEditor.selectedLFEnt->lock ) { CG_StopMover(cg.lfEditor.selectedLFEnt->lock); } } #endif // assert our valid conditions upon exiting if ( cg.snap == NULL ) { CG_Error( "CG_ProcessSnapshots: cg.snap == NULL" ); } if ( cg.time < cg.snap->serverTime ) { // this can happen right after a vid_restart cg.time = cg.snap->serverTime; } if ( cg.nextSnap != NULL && cg.nextSnap->serverTime <= cg.time ) { CG_Error( "CG_ProcessSnapshots: cg.nextSnap->serverTime <= cg.time" ); } }
/* ============ CG_ProcessSnapshots We are trying to set up a renderable view, so determine what the simulated time is, and try to get snapshots both before and after that time if available. If we don't have a valid cg.snap after exiting this function, then a 3D game view cannot be rendered. This should only happen right after the initial connection. After cg.snap has been valid once, it will never turn invalid. Even if cg.snap is valid, cg.nextSnap may not be, if the snapshot hasn't arrived yet (it becomes an extrapolating situation instead of an interpolating one) ============ */ void CG_ProcessSnapshots( void ) { snapshot_t *snap; int n; // see what the latest snapshot the client system has is trap_GetCurrentSnapshotNumber( &n, &cg.latestSnapshotTime ); if ( n != cg.latestSnapshotNum ) { if ( n < cg.latestSnapshotNum ) { // this should never happen CG_Error( "CG_ProcessSnapshots: n < cg.latestSnapshotNum" ); } cg.latestSnapshotNum = n; } // If we have yet to receive a snapshot, check for it. // Once we have gotten the first snapshot, cg.snap will // always have valid data for the rest of the game while ( !cg.snap ) { snap = CG_ReadNextSnapshot(); if ( !snap ) { // we can't continue until we get a snapshot return; } // set our weapon selection to what // the playerstate is currently using if ( !( snap->snapFlags & SNAPFLAG_NOT_ACTIVE ) ) { CG_SetInitialSnapshot( snap ); } } // loop until we either have a valid nextSnap with a serverTime // greater than cg.time to interpolate towards, or we run // out of available snapshots do { // if we don't have a nextframe, try and read a new one in if ( !cg.nextSnap ) { snap = CG_ReadNextSnapshot(); // if we still don't have a nextframe, we will just have to // extrapolate if ( !snap ) { break; } CG_SetNextSnap( snap ); // if time went backwards, we have a level restart if ( cg.nextSnap->serverTime < cg.snap->serverTime ) { CG_Error( "CG_ProcessSnapshots: Server time went backwards" ); } } // if our time is < nextFrame's, we have a nice interpolating state if ( cg.time >= cg.snap->serverTime && cg.time < cg.nextSnap->serverTime ) { break; } // we have passed the transition from nextFrame to frame CG_TransitionSnapshot(); } while ( 1 ); // assert our valid conditions upon exiting if ( cg.snap == NULL ) { CG_Error( "CG_ProcessSnapshots: cg.snap == NULL" ); } if ( cg.time < cg.snap->serverTime ) { // this can happen right after a vid_restart cg.time = cg.snap->serverTime; } if ( cg.nextSnap != NULL && cg.nextSnap->serverTime <= cg.time ) { CG_Error( "CG_ProcessSnapshots: cg.nextSnap->serverTime <= cg.time" ); } }
void demoProcessSnapShots( qboolean hadSkip ) { int i; snapshot_t *snap; // see what the latest snapshot the client system has is trap_GetCurrentSnapshotNumber( &cg.latestSnapshotNum, &cg.latestSnapshotTime ); if (hadSkip || !cg.snap) { cgs.processedSnapshotNum = max(cg.latestSnapshotNum - 3, -1); if (cg.nextSnap) cgs.serverCommandSequence = cg.nextSnap->serverCommandSequence; else if (cg.snap) cgs.serverCommandSequence = cg.snap->serverCommandSequence; cg.snap = 0; cg.nextSnap = 0; cg.nextNextSnap = 0; for (i=-1;i<MAX_GENTITIES;i++) { centity_t *cent = i < 0 ? &cg.predictedPlayerEntity : &cg_entities[i]; cent->trailTime = cg.time; cent->snapShotTime = cg.time; cent->currentValid = qfalse; cent->interpolate = qfalse; cent->muzzleFlashTime = cg.time - MUZZLE_FLASH_TIME - 1; cent->previousEvent = 0; if (cent->currentState.eType == ET_PLAYER) { memset( ¢->pe, 0, sizeof( cent->pe ) ); cent->pe.legs.yawAngle = cent->lerpAngles[YAW]; cent->pe.torso.yawAngle = cent->lerpAngles[YAW]; cent->pe.torso.pitchAngle = cent->lerpAngles[PITCH]; } } } /* Check if we have some transition between snapsnots */ if (!cg.snap) { entityState_t pes; snap = CG_ReadNextSnapshot(); if (!snap) return; cg.snap = snap; BG_PlayerStateToEntityState( &snap->ps, &cg_entities[ snap->ps.clientNum ].currentState, qfalse ); CG_BuildSolidList(); CG_ExecuteNewServerCommands( snap->serverCommandSequence ); CG_UpdateTps( snap, qtrue ); BG_PlayerStateToEntityStateExtraPolate( &snap->ps, &pes, snap->ps.commandTime, qfalse ); CG_AddToHistory( snap->serverTime, &pes, &cg_entities[snap->ps.clientNum] ); for ( i = 0 ; i < cg.snap->numEntities ; i++ ) { entityState_t *state = &cg.snap->entities[ i ]; centity_t *cent = &cg_entities[ state->number ]; memcpy(¢->currentState, state, sizeof(entityState_t)); cent->interpolate = qfalse; cent->currentValid = qtrue; CG_AddToHistory( snap->serverTime, state, cent ); if (cent->currentState.eType > ET_EVENTS) cent->previousEvent = 1; else cent->previousEvent = cent->currentState.event; } } do { if (!cg.nextSnap) { snap = CG_ReadNextSnapshot(); if (!snap) break; CG_SetNextSnap( snap ); } if ( !cg.nextNextSnap ) { snap = CG_ReadNextSnapshot(); if ( !snap ) break; CG_SetNextNextSnap( snap ); } if ( cg.timeFraction >= cg.snap->serverTime - cg.time && cg.timeFraction < cg.nextSnap->serverTime - cg.time ) break; //Todo our own transition checking if we wanna hear certain sounds CG_TransitionSnapshot(); } while (1); }