Skip to content

Commit

Permalink
update: support for d3xp
Browse files Browse the repository at this point in the history
  • Loading branch information
Stradex committed Jun 13, 2020
1 parent 695d050 commit 15f4e5e
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 34 deletions.
32 changes: 17 additions & 15 deletions neo/d3xp/Game_local.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ void idGameLocal::Clear( void ) {
framenum = 0;
previousTime = 0;
time = 0;
preciseTime = 0.0f;
vacuumAreaNum = 0;
mapFileName.Clear();
mapFile = NULL;
Expand Down Expand Up @@ -309,7 +310,7 @@ void idGameLocal::Init( void ) {
const idDict *dict;
idAAS *aas;

msec = 16; //60fps
msec = 16.0; //60fps
gameMsec = msec;
gameFps = 60; //60fps

Expand All @@ -332,7 +333,7 @@ void idGameLocal::Init( void ) {

//Update MSEC and gameFps
gameFps = cvarSystem->GetCVarInteger("com_gameHz");
msec = idMath::FtoiFast(1000.0f / static_cast<float>(cvarSystem->GetCVarInteger("com_gameHz")));
msec = 1000.0f / cvarSystem->GetCVarFloat("com_gameHz");
gameMsec = msec;

Printf( "----- Initializing Game -----\n" );
Expand Down Expand Up @@ -608,7 +609,7 @@ void idGameLocal::SaveGame( idFile *f ) {
savegame.WriteInt( time );

#ifdef _D3XP
savegame.WriteInt( msec );
savegame.WriteFloat( msec );
#endif

savegame.WriteInt( vacuumAreaNum );
Expand Down Expand Up @@ -1487,7 +1488,7 @@ bool idGameLocal::InitFromSaveGame( const char *mapName, idRenderWorld *renderWo
savegame.ReadInt( time );

#ifdef _D3XP
savegame.ReadInt( msec );
savegame.ReadFloat( msec );
#endif

savegame.ReadInt( vacuumAreaNum );
Expand Down Expand Up @@ -2440,7 +2441,8 @@ gameReturn_t idGameLocal::RunFrame( const usercmd_t *clientCmds ) {
// update the game time
framenum++;
previousTime = time;
time += msec;
preciseTime += msec;
time = (int)idMath::Rint(preciseTime);
realClientTime = time;

#ifdef _D3XP
Expand Down Expand Up @@ -3821,7 +3823,7 @@ idGameLocal::AlertAI
void idGameLocal::AlertAI( idEntity *ent ) {
if ( ent && ent->IsType( idActor::Type ) ) {
// alert them for the next frame
lastAIAlertTime = time + msec;
lastAIAlertTime = time + (int)idMath::Rint(msec);
lastAIAlertEntity = static_cast<idActor *>( ent );
}
}
Expand Down Expand Up @@ -4234,7 +4236,7 @@ void idGameLocal::SetCamera( idCamera *cam ) {

} else {
inCinematic = false;
cinematicStopTime = time + msec;
cinematicStopTime = time + idMath::Rint(msec);

// restore r_znear
cvarSystem->SetCVarFloat( "r_znear", 3.0f );
Expand Down Expand Up @@ -4830,7 +4832,7 @@ void idGameLocal::ComputeSlowMsec() {

// stop the state
slowmoState = SLOWMO_STATE_OFF;
slowmoMsec = (float)gameMsec;
slowmoMsec = gameMsec;
}

// check the player state
Expand All @@ -4851,7 +4853,7 @@ void idGameLocal::ComputeSlowMsec() {
slowmoMsec = msec;
if ( gameSoundWorld ) {
gameSoundWorld->SetSlowmo( true );
gameSoundWorld->SetSlowmoSpeed( slowmoMsec / (float)gameMsec );
gameSoundWorld->SetSlowmoSpeed( slowmoMsec / gameMsec );
}
}
else if ( !powerupOn && slowmoState == SLOWMO_STATE_ON ) {
Expand All @@ -4865,25 +4867,25 @@ void idGameLocal::ComputeSlowMsec() {

// do any necessary ramping
if ( slowmoState == SLOWMO_STATE_RAMPUP ) {
delta = idMath::Rint(4.0 * 60.0 / (float)gameFps) - slowmoMsec;
delta = 4.0 * 60.0 / (float)gameFps - slowmoMsec;

if ( fabs( delta ) < g_slowmoStepRate.GetFloat() ) {
slowmoMsec = idMath::Rint(4.0 * 60.0 / (float)gameFps);
slowmoMsec = 4.0 * 60.0 / (float)gameFps;
slowmoState = SLOWMO_STATE_ON;
}
else {
slowmoMsec += delta * g_slowmoStepRate.GetFloat();
}

if ( gameSoundWorld ) {
gameSoundWorld->SetSlowmoSpeed( slowmoMsec / (float)gameMsec );
gameSoundWorld->SetSlowmoSpeed( slowmoMsec / gameMsec );
}
}
else if ( slowmoState == SLOWMO_STATE_RAMPDOWN ) {
delta = idMath::Rint(16.0 * 60.0 / (float)gameFps) - slowmoMsec;
delta = 16.0 * 60.0 / gameFps - slowmoMsec;

if ( fabs( delta ) < g_slowmoStepRate.GetFloat() ) {
slowmoMsec = idMath::Rint(16.0*60.0/(float)gameFps);
slowmoMsec = 16.0*60.0/(float)gameFps;
slowmoState = SLOWMO_STATE_OFF;
if ( gameSoundWorld ) {
gameSoundWorld->SetSlowmo( false );
Expand All @@ -4894,7 +4896,7 @@ void idGameLocal::ComputeSlowMsec() {
}

if ( gameSoundWorld ) {
gameSoundWorld->SetSlowmoSpeed( slowmoMsec / (float)gameMsec );
gameSoundWorld->SetSlowmoSpeed( slowmoMsec / gameMsec );
}
}
}
Expand Down
17 changes: 9 additions & 8 deletions neo/d3xp/Game_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,14 @@ class idEntityPtr {
struct timeState_t {
int time;
int previousTime;
int msec;
float msec;
int framenum;
int realClientTime;

void Set( int t, int pt, int ms, int f, int rct ) { time = t; previousTime = pt; msec = ms; framenum = f; realClientTime = rct; };
void Get( int& t, int& pt, int& ms, int& f, int& rct ) { t = time; pt = previousTime; ms = msec; f = framenum; rct = realClientTime; };
void Save( idSaveGame *savefile ) const { savefile->WriteInt( time ); savefile->WriteInt( previousTime ); savefile->WriteInt( msec ); savefile->WriteInt( framenum ); savefile->WriteInt( realClientTime ); }
void Restore( idRestoreGame *savefile ) { savefile->ReadInt( time ); savefile->ReadInt( previousTime ); savefile->ReadInt( msec ); savefile->ReadInt( framenum ); savefile->ReadInt( realClientTime ); }
void Set( int t, int pt, float ms, int f, int rct ) { time = t; previousTime = pt; msec = ms; framenum = f; realClientTime = rct; };
void Get( int& t, int& pt, float& ms, int& f, int& rct ) { t = time; pt = previousTime; ms = msec; f = framenum; rct = realClientTime; };
void Save( idSaveGame *savefile ) const { savefile->WriteInt( time ); savefile->WriteInt( previousTime ); savefile->WriteFloat( msec ); savefile->WriteInt( framenum ); savefile->WriteInt( realClientTime ); }
void Restore( idRestoreGame *savefile ) { savefile->ReadInt( time ); savefile->ReadInt( previousTime ); savefile->ReadFloat( msec ); savefile->ReadInt( framenum ); savefile->ReadInt( realClientTime ); }
void Increment() { framenum++; previousTime = time; time += msec; realClientTime = time; };
};

Expand Down Expand Up @@ -298,9 +298,10 @@ class idGameLocal : public idGame {
int framenum;
int previousTime; // time in msec of last frame
int time; // in msec
int msec; // time since last update in milliseconds
float msec; // time since last update in milliseconds
float preciseTime; // added by Stradex for cm_gameHz fidelity
int gameFps; //added by Stradex for com_gameHz
int gameMsec; //added by Stradex for com_gameHz (ROE)
float gameMsec; //added by Stradex for com_gameHz (ROE)

int vacuumAreaNum; // -1 if level doesn't have any outside areas

Expand Down Expand Up @@ -485,7 +486,7 @@ class idGameLocal : public idGame {
// added the following to assist licensees with merge issues
int GetFrameNum() const { return framenum; };
int GetTime() const { return time; };
int GetMSec() const { return msec; };
float GetMSec() const { return msec; };

int GetNextClientNum( int current ) const;
idPlayer * GetClientByNum( int current ) const;
Expand Down
5 changes: 3 additions & 2 deletions neo/d3xp/Game_network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ void idGameLocal::ClientReadSnapshot( int clientNum, int sequence, const int gam
// update the game time
framenum = gameFrame;
time = gameTime;
previousTime = time - msec;
previousTime = time - idMath::Rint(msec);

// so that StartSound/StopSound doesn't risk skipping
isNewFrame = true;
Expand Down Expand Up @@ -1532,7 +1532,8 @@ gameReturn_t idGameLocal::ClientPrediction( int clientNum, const usercmd_t *clie
// update the game time
framenum++;
previousTime = time;
time += msec;
preciseTime += msec;
time = (int)idMath::Rint(preciseTime);

// update the real client time and the new frame flag
if ( time > realClientTime ) {
Expand Down
2 changes: 1 addition & 1 deletion neo/d3xp/SmokeParticles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ bool idSmokeParticles::EmitSmoke( const idDeclParticle *smoke, const int systemS
if ( nowCount >= stage->totalParticles ) {
nowCount = stage->totalParticles-1;
}
prevCount = floor( ((float)( deltaMsec - gameLocal.msec /*_D3XP - FIX - was gameLocal.msec*/ ) / finalParticleTime) * stage->totalParticles );
prevCount = floor( ((float)( deltaMsec - (int)idMath::Rint(gameLocal.msec) /*_D3XP - FIX - was gameLocal.msec*/ ) / finalParticleTime) * stage->totalParticles );
if ( prevCount < -1 ) {
prevCount = -1;
}
Expand Down
4 changes: 2 additions & 2 deletions neo/d3xp/physics/Physics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ idPhysics::SnapTimeToPhysicsFrame
*/
int idPhysics::SnapTimeToPhysicsFrame( int t ) {
int s;
s = t + gameLocal.gameMsec - 1;
return ( s - s % gameLocal.gameMsec );
s = t + (int)idMath::Rint(gameLocal.gameMsec) - 1;
return ( s - s % (int)idMath::Rint(gameLocal.gameMsec) );
}
4 changes: 2 additions & 2 deletions neo/d3xp/script/Script_Thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ bool idThread::Execute( void ) {
if ( waitingUntil > lastExecuteTime ) {
PostEventMS( &EV_Thread_Execute, waitingUntil - lastExecuteTime );
} else if ( interpreter.MultiFrameEventInProgress() ) {
PostEventMS( &EV_Thread_Execute, gameLocal.msec );
PostEventMS( &EV_Thread_Execute, idMath::Rint(gameLocal.msec) );
}
}

Expand Down Expand Up @@ -932,7 +932,7 @@ void idThread::WaitFrame( void ) {
// manual control threads don't set waitingUntil so that they can be run again
// that frame if necessary.
if ( !manualControl ) {
waitingUntil = gameLocal.time + gameLocal.msec;
waitingUntil = gameLocal.time + idMath::Rint(gameLocal.msec);
}
}

Expand Down
2 changes: 1 addition & 1 deletion neo/game/Projectile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ void idProjectile::Explode( const trace_t &collision, idEntity *ignore ) {
renderLight.shaderParms[SHADERPARM_TIMEOFFSET] = -MS2SEC( gameLocal.time );
light_fadetime = spawnArgs.GetFloat( "explode_light_fadetime", "0.5" );
lightStartTime = gameLocal.time;
lightEndTime = gameLocal.time + SEC2MS( light_fadetime );
lightEndTime = MSEC_ALIGN_TO_FRAME(gameLocal.time + SEC2MS( light_fadetime ));
BecomeActive( TH_THINK );
}

Expand Down
4 changes: 1 addition & 3 deletions neo/game/physics/Physics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,5 @@ idPhysics::SnapTimeToPhysicsFrame
================
*/
int idPhysics::SnapTimeToPhysicsFrame( int t ) {
int s;
s = t + (int)idMath::Rint(gameLocal.msec) - 1;
return ( s - s % (int)idMath::Rint(gameLocal.msec));
return MSEC_ALIGN_TO_FRAME(t);
}

0 comments on commit 15f4e5e

Please sign in to comment.