Beispiel #1
0
void CG_RestartLevel( void ) {
	int		snapshotNum;
	int		r;

	snapshotNum = cg.processedSnapshotNum;

/*
Ghoul2 Insert Start
*/

//	memset( cg_entities, 0, sizeof( cg_entities ) );
	CG_Init_CGents();
// this is a No-No now we have stl vector classes in here.
//	memset( &cg, 0, sizeof( cg ) );
	CG_Init_CG();
/*
Ghoul2 Insert End
*/


	CG_LinkCentsToGents();
	CG_InitLocalEntities();
	CG_InitMarkPolys();

	// regrab the first snapshot of the restart

	cg.processedSnapshotNum = snapshotNum;
	r = cgi_GetSnapshot( cg.processedSnapshotNum, &cg.activeSnapshots[0] );
	if ( !r ) {
		CG_Error( "cgi_GetSnapshot failed on restart" );
	}

	CG_SetInitialSnapshot( &cg.activeSnapshots[0] );
	cg.time = cg.snap->serverTime;
}
static void CG_RestartLevel( void ) {
	int		snapshotNum;
	int		r;

	snapshotNum = cg.processedSnapshotNum;

	memset( cg_entities, 0, sizeof( cg_entities ) );
	CG_Init_CG();

	CG_LinkCentsToGents();
	CG_InitLocalEntities();
	CG_InitMarkPolys();

	// regrab the first snapshot of the restart

	cg.processedSnapshotNum = snapshotNum;
	r = cgi_GetSnapshot( cg.processedSnapshotNum, &cg.activeSnapshots[0] );
	if ( !r ) {
		CG_Error( "cgi_GetSnapshot failed on restart" );
	}

	CG_SetInitialSnapshot( &cg.activeSnapshots[0] );
	cg.time = cg.snap->serverTime;
}
Beispiel #3
0
/*
============
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" );
	}
}
/*
========================
CG_ReadNextSnapshot

This is the only place new snapshots are requested
This may increment cgs.processedSnapshotNum multiple
times if the client system fails to return a
valid snapshot.
========================
*/
static snapshot_t *CG_ReadNextSnapshot( void ) {
	qboolean	r;
	snapshot_t	*dest;

	if ( cg.latestSnapshotNum > cgs.processedSnapshotNum + 1000 ) {
		CG_Printf( "[skipnotify]WARNING: CG_ReadNextSnapshot: way out of range, %i > %i\n", 
			cg.latestSnapshotNum, cgs.processedSnapshotNum );
	}

	while ( cgs.processedSnapshotNum < cg.latestSnapshotNum ) {
		// decide which of the two slots to load it into
		if ( cg.snap == &cg.activeSnapshots[0] ) {
			dest = &cg.activeSnapshots[1];
		} else {
			dest = &cg.activeSnapshots[0];
		}

		// try to read the snapshot from the client system
		cgs.processedSnapshotNum++;
		r = trap_GetSnapshot( cgs.processedSnapshotNum, dest );

		// FIXME: why would trap_GetSnapshot return a snapshot with the same server time
		if ( cg.snap && r && dest->serverTime == cg.snap->serverTime ) {
			//continue;
		}

		// if it succeeded, return
		if ( r ) {
			CG_AddLagometerSnapshotInfo( dest );
			// server has been restarted
			if ( cg.snap && ( dest->snapFlags ^ cg.snap->snapFlags ) & SNAPFLAG_SERVERCOUNT ) {
				cg.damageTime = 0;
				cg.duckTime = -1;
				cg.landTime = -1;
				cg.stepTime = -1;
#ifdef SAVEGAME_SUPPORT
				// savegame: we should use this as our new base snapshot
				if( CG_IsSinglePlayer() ) {
					int i;
					centity_t backupCent;
					CG_SetInitialSnapshot( dest );
					cg.nextFrameTeleport = qtrue;
					// loadgame hasn't occured yet, so this is likely wrong
					//cg.weaponSelect = cg.snap->ps.weapon;
					cg.weaponSelectTime = cg.time;
					memset( cg.viewDamage, 0, sizeof(cg.viewDamage) );
				//	memset( cg.cameraShake, 0, sizeof(cg.cameraShake) );
					// go through an reset the cent's
					for (i=0; i<MAX_GENTITIES; i++) {
						backupCent = cg_entities[i];
						memset( &cg_entities[i], 0, sizeof(centity_t) );
						cg_entities[i].currentState = backupCent.currentState;
						cg_entities[i].nextState = backupCent.nextState;
						cg_entities[i].currentValid = backupCent.currentValid;
						cg_entities[i].interpolate = backupCent.interpolate;
					}
					// reset the predicted cent
					memset( &cg.predictedPlayerEntity, 0, sizeof(centity_t) );
					cg.predictedPlayerEntity.currentState = backupCent.currentState;
					cg.predictedPlayerEntity.nextState = backupCent.nextState;
					cg.predictedPlayerEntity.currentValid = backupCent.currentValid;
					cg.predictedPlayerEntity.interpolate = backupCent.interpolate;

					return NULL;
				}
#endif // SAVEGAME_SUPPORT
			}
//
			return dest;
		}

		// a GetSnapshot will return failure if the snapshot
		// never arrived, or  is so old that its entities
		// have been shoved off the end of the circular
		// buffer in the client system.

		// record as a dropped packet
		CG_AddLagometerSnapshotInfo( NULL );

		// If there are additional snapshots, continue trying to
		// read them.
	}

	// nothing left to read
	return NULL;
}
Beispiel #5
0
/*
============
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" );
	}

}