| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
#include "cg_local.h" |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
static void CG_ResetEntity( centity_t *cent ) { |
| 36 |
|
| 37 |
|
| 38 |
if ( cent->snapShotTime < cg.time - EVENT_VALID_MSEC ) { |
| 39 |
cent->previousEvent = 0; |
| 40 |
} |
| 41 |
|
| 42 |
cent->trailTime = cg.snap->serverTime; |
| 43 |
|
| 44 |
VectorCopy (cent->currentState.origin, cent->lerpOrigin); |
| 45 |
VectorCopy (cent->currentState.angles, cent->lerpAngles); |
| 46 |
if ( cent->currentState.eType == ET_PLAYER ) { |
| 47 |
CG_ResetPlayerEntity( cent ); |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
static void CG_TransitionEntity( centity_t *cent ) { |
| 59 |
cent->currentState = cent->nextState; |
| 60 |
cent->currentValid = qtrue; |
| 61 |
|
| 62 |
|
| 63 |
if ( !cent->interpolate ) { |
| 64 |
CG_ResetEntity( cent ); |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
cent->interpolate = qfalse; |
| 69 |
|
| 70 |
|
| 71 |
CG_CheckEvents( cent ); |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
void CG_SetInitialSnapshot( snapshot_t *snap ) { |
| 84 |
int i; |
| 85 |
centity_t *cent; |
| 86 |
entityState_t *state; |
| 87 |
|
| 88 |
cg.snap = snap; |
| 89 |
|
| 90 |
BG_PlayerStateToEntityState( &snap->ps, &cg_entities[ snap->ps.clientNum ].currentState, qfalse ); |
| 91 |
|
| 92 |
|
| 93 |
CG_BuildSolidList(); |
| 94 |
|
| 95 |
CG_ExecuteNewServerCommands( snap->serverCommandSequence ); |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
CG_Respawn(); |
| 100 |
|
| 101 |
for ( i = 0 ; i < cg.snap->numEntities ; i++ ) { |
| 102 |
state = &cg.snap->entities[ i ]; |
| 103 |
cent = &cg_entities[ state->number ]; |
| 104 |
|
| 105 |
memcpy(¢->currentState, state, sizeof(entityState_t)); |
| 106 |
|
| 107 |
cent->interpolate = qfalse; |
| 108 |
cent->currentValid = qtrue; |
| 109 |
|
| 110 |
CG_ResetEntity( cent ); |
| 111 |
|
| 112 |
|
| 113 |
CG_CheckEvents( cent ); |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
static void CG_TransitionSnapshot( void ) { |
| 126 |
centity_t *cent; |
| 127 |
snapshot_t *oldFrame; |
| 128 |
int i; |
| 129 |
|
| 130 |
if ( !cg.snap ) { |
| 131 |
CG_Error( "CG_TransitionSnapshot: NULL cg.snap" ); |
| 132 |
} |
| 133 |
if ( !cg.nextSnap ) { |
| 134 |
CG_Error( "CG_TransitionSnapshot: NULL cg.nextSnap" ); |
| 135 |
} |
| 136 |
|
| 137 |
|
| 138 |
CG_ExecuteNewServerCommands( cg.nextSnap->serverCommandSequence ); |
| 139 |
|
| 140 |
|
| 141 |
if ( cg.mapRestart ) { |
| 142 |
} |
| 143 |
|
| 144 |
|
| 145 |
for ( i = 0 ; i < cg.snap->numEntities ; i++ ) { |
| 146 |
cent = &cg_entities[ cg.snap->entities[ i ].number ]; |
| 147 |
cent->currentValid = qfalse; |
| 148 |
} |
| 149 |
|
| 150 |
|
| 151 |
oldFrame = cg.snap; |
| 152 |
cg.snap = cg.nextSnap; |
| 153 |
|
| 154 |
BG_PlayerStateToEntityState( &cg.snap->ps, &cg_entities[ cg.snap->ps.clientNum ].currentState, qfalse ); |
| 155 |
cg_entities[ cg.snap->ps.clientNum ].interpolate = qfalse; |
| 156 |
|
| 157 |
for ( i = 0 ; i < cg.snap->numEntities ; i++ ) { |
| 158 |
cent = &cg_entities[ cg.snap->entities[ i ].number ]; |
| 159 |
CG_TransitionEntity( cent ); |
| 160 |
|
| 161 |
|
| 162 |
cent->snapShotTime = cg.snap->serverTime; |
| 163 |
} |
| 164 |
|
| 165 |
cg.nextSnap = NULL; |
| 166 |
|
| 167 |
|
| 168 |
if ( oldFrame ) { |
| 169 |
playerState_t *ops, *ps; |
| 170 |
|
| 171 |
ops = &oldFrame->ps; |
| 172 |
ps = &cg.snap->ps; |
| 173 |
|
| 174 |
if ( ( ps->eFlags ^ ops->eFlags ) & EF_TELEPORT_BIT ) { |
| 175 |
cg.thisFrameTeleport = qtrue; |
| 176 |
} |
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
if ( cg.demoPlayback || (cg.snap->ps.pm_flags & PMF_FOLLOW) |
| 181 |
|| cg_nopredict.integer || cg_synchronousClients.integer ) { |
| 182 |
CG_TransitionPlayerState( ps, ops ); |
| 183 |
} |
| 184 |
} |
| 185 |
|
| 186 |
} |
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
static void CG_SetNextSnap( snapshot_t *snap ) { |
| 197 |
int num; |
| 198 |
entityState_t *es; |
| 199 |
centity_t *cent; |
| 200 |
|
| 201 |
cg.nextSnap = snap; |
| 202 |
|
| 203 |
BG_PlayerStateToEntityState( &snap->ps, &cg_entities[ snap->ps.clientNum ].nextState, qfalse ); |
| 204 |
cg_entities[ cg.snap->ps.clientNum ].interpolate = qtrue; |
| 205 |
|
| 206 |
|
| 207 |
for ( num = 0 ; num < snap->numEntities ; num++ ) { |
| 208 |
es = &snap->entities[num]; |
| 209 |
cent = &cg_entities[ es->number ]; |
| 210 |
|
| 211 |
memcpy(¢->nextState, es, sizeof(entityState_t)); |
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
if ( !cent->currentValid || ( ( cent->currentState.eFlags ^ es->eFlags ) & EF_TELEPORT_BIT ) ) { |
| 217 |
cent->interpolate = qfalse; |
| 218 |
} else { |
| 219 |
cent->interpolate = qtrue; |
| 220 |
} |
| 221 |
} |
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
if ( cg.snap && ( ( snap->ps.eFlags ^ cg.snap->ps.eFlags ) & EF_TELEPORT_BIT ) ) { |
| 226 |
cg.nextFrameTeleport = qtrue; |
| 227 |
} else { |
| 228 |
cg.nextFrameTeleport = qfalse; |
| 229 |
} |
| 230 |
|
| 231 |
|
| 232 |
if ( cg.nextSnap->ps.clientNum != cg.snap->ps.clientNum ) { |
| 233 |
cg.nextFrameTeleport = qtrue; |
| 234 |
} |
| 235 |
|
| 236 |
|
| 237 |
if ( ( cg.nextSnap->snapFlags ^ cg.snap->snapFlags ) & SNAPFLAG_SERVERCOUNT ) { |
| 238 |
cg.nextFrameTeleport = qtrue; |
| 239 |
} |
| 240 |
|
| 241 |
|
| 242 |
CG_BuildSolidList(); |
| 243 |
} |
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
static snapshot_t *CG_ReadNextSnapshot( void ) { |
| 257 |
qboolean r; |
| 258 |
snapshot_t *dest; |
| 259 |
|
| 260 |
if ( cg.latestSnapshotNum > cgs.processedSnapshotNum + 1000 ) { |
| 261 |
CG_Printf( "WARNING: CG_ReadNextSnapshot: way out of range, %i > %i\n", |
| 262 |
cg.latestSnapshotNum, cgs.processedSnapshotNum ); |
| 263 |
} |
| 264 |
|
| 265 |
while ( cgs.processedSnapshotNum < cg.latestSnapshotNum ) { |
| 266 |
|
| 267 |
if ( cg.snap == &cg.activeSnapshots[0] ) { |
| 268 |
dest = &cg.activeSnapshots[1]; |
| 269 |
} else { |
| 270 |
dest = &cg.activeSnapshots[0]; |
| 271 |
} |
| 272 |
|
| 273 |
|
| 274 |
cgs.processedSnapshotNum++; |
| 275 |
r = trap_GetSnapshot( cgs.processedSnapshotNum, dest ); |
| 276 |
|
| 277 |
|
| 278 |
if ( cg.snap && r && dest->serverTime == cg.snap->serverTime ) { |
| 279 |
|
| 280 |
} |
| 281 |
|
| 282 |
|
| 283 |
if ( r ) { |
| 284 |
CG_AddLagometerSnapshotInfo( dest ); |
| 285 |
return dest; |
| 286 |
} |
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
CG_AddLagometerSnapshotInfo( NULL ); |
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
} |
| 299 |
|
| 300 |
|
| 301 |
return NULL; |
| 302 |
} |
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
void CG_ProcessSnapshots( void ) { |
| 325 |
snapshot_t *snap; |
| 326 |
int n; |
| 327 |
|
| 328 |
|
| 329 |
trap_GetCurrentSnapshotNumber( &n, &cg.latestSnapshotTime ); |
| 330 |
if ( n != cg.latestSnapshotNum ) { |
| 331 |
if ( n < cg.latestSnapshotNum ) { |
| 332 |
|
| 333 |
CG_Error( "CG_ProcessSnapshots: n < cg.latestSnapshotNum" ); |
| 334 |
} |
| 335 |
cg.latestSnapshotNum = n; |
| 336 |
} |
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
while ( !cg.snap ) { |
| 342 |
snap = CG_ReadNextSnapshot(); |
| 343 |
if ( !snap ) { |
| 344 |
|
| 345 |
return; |
| 346 |
} |
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
if ( !( snap->snapFlags & SNAPFLAG_NOT_ACTIVE ) ) { |
| 351 |
CG_SetInitialSnapshot( snap ); |
| 352 |
} |
| 353 |
} |
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
do { |
| 359 |
|
| 360 |
if ( !cg.nextSnap ) { |
| 361 |
snap = CG_ReadNextSnapshot(); |
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
if ( !snap ) { |
| 366 |
break; |
| 367 |
} |
| 368 |
|
| 369 |
CG_SetNextSnap( snap ); |
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
if ( cg.nextSnap->serverTime < cg.snap->serverTime ) { |
| 374 |
CG_Error( "CG_ProcessSnapshots: Server time went backwards" ); |
| 375 |
} |
| 376 |
} |
| 377 |
|
| 378 |
|
| 379 |
if ( cg.time >= cg.snap->serverTime && cg.time < cg.nextSnap->serverTime ) { |
| 380 |
break; |
| 381 |
} |
| 382 |
|
| 383 |
|
| 384 |
CG_TransitionSnapshot(); |
| 385 |
} while ( 1 ); |
| 386 |
|
| 387 |
|
| 388 |
if ( cg.snap == NULL ) { |
| 389 |
CG_Error( "CG_ProcessSnapshots: cg.snap == NULL" ); |
| 390 |
} |
| 391 |
if ( cg.time < cg.snap->serverTime ) { |
| 392 |
|
| 393 |
cg.time = cg.snap->serverTime; |
| 394 |
} |
| 395 |
if ( cg.nextSnap != NULL && cg.nextSnap->serverTime <= cg.time ) { |
| 396 |
CG_Error( "CG_ProcessSnapshots: cg.nextSnap->serverTime <= cg.time" ); |
| 397 |
} |
| 398 |
|
| 399 |
} |
| 400 |
|