Skip to content

Commit

Permalink
add: _UNLOCKEDFPS precompile def to have compatibility with com_gameH…
Browse files Browse the repository at this point in the history
…z that is still not present in dhewm3 master but in my local branch yes
  • Loading branch information
Stradex committed Jun 11, 2020
1 parent 5cd9013 commit 7f87c0b
Show file tree
Hide file tree
Showing 15 changed files with 137 additions and 4 deletions.
1 change: 1 addition & 0 deletions d3xp/Entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5232,6 +5232,7 @@ void idEntity::Event_SetGui( int guiNum, const char *guiName) {
}

if( gui ) {

*gui = uiManager->FindGui( guiName, true, false );
UpdateGuiParms( *gui, &spawnArgs );
UpdateChangeableSpawnArgs( NULL );
Expand Down
8 changes: 8 additions & 0 deletions game/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,11 @@ void idCameraAnim::Think( void ) {
//int realUserTime = gameLocal.isClient ? gameLocal.clientsideTime : gameLocal.time;
int realUserTime = gameLocal.time;

#ifdef _UNLOCKEDFPS
if ( frameRate == gameLocal.gameFps ) {
#else
if ( frameRate == USERCMD_HZ ) {
#endif
frameTime = realUserTime - starttime;
frame = frameTime / gameLocal.msec;
} else {
Expand Down Expand Up @@ -683,7 +687,11 @@ void idCameraAnim::GetViewParms( renderView_t *view ) {
//int realUserTime = gameLocal.isClient ? gameLocal.clientsideTime : gameLocal.time;
int realUserTime = gameLocal.time;

#ifdef _UNLOCKEDFPS
if ( frameRate == gameLocal.gameFps ) {
#else
if ( frameRate == USERCMD_HZ ) {
#endif
frameTime = realUserTime - starttime;
frame = frameTime / gameLocal.msec;
lerp = 0.0f;
Expand Down
58 changes: 57 additions & 1 deletion game/Game_local.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,11 @@ void idGameLocal::Init( void ) {
const idDict *dict;
idAAS *aas;

#ifdef _UNLOCKEDFPS
msec = 16; //60fps
gameFps = 60; //60fps
#endif

#ifndef GAME_DLL

TestGameAPI();
Expand All @@ -312,6 +317,12 @@ void idGameLocal::Init( void ) {

#endif

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

Printf( "----- Initializing Game -----\n" );
Printf( "gamename: %s\n", GAME_VERSION );
Printf( "gamedate: %s\n", __DATE__ );
Expand Down Expand Up @@ -360,6 +371,10 @@ void idGameLocal::Init( void ) {
gamestate = GAMESTATE_NOMAP;

Printf( "...%d aas types\n", aasList.Num() );

#ifdef _UNLOCKEDFPS
SetScriptFPS(static_cast<const float>(this->gameFps));
#endif
}

/*
Expand Down Expand Up @@ -1389,6 +1404,10 @@ bool idGameLocal::InitFromSaveGame( const char *mapName, idRenderWorld *renderWo
gameRenderWorld = renderWorld;
gameSoundWorld = soundWorld;

#ifdef _UNLOCKEDFPS
SetScriptFPS(static_cast<const float>(this->gameFps));
#endif

idRestoreGame savegame( saveGameFile );

savegame.ReadBuildNumber();
Expand Down Expand Up @@ -5094,4 +5113,41 @@ void idGameLocal::SetCameraCoop( idCamera *cam ) {
}
}
}
}
}

#ifdef _UNLOCKEDFPS

/*
===================
idGameLocal::SetScriptFPS
===================
*/
void idGameLocal::SetScriptFPS(const float tCom_gameHz)
{
idVarDef* fpsDef = program.GetDef(&type_float, "GAME_FPS", &def_namespace);
if (fpsDef != NULL) {
eval_t fpsValue;
fpsValue._float = tCom_gameHz;
fpsDef->SetValue(fpsValue, false);

common->Printf("GAME_FPS: %f\n", tCom_gameHz);
}
else {
common->Printf("Unable to find GAME_FPS def\n");
}

float frameRate = 1.0 / tCom_gameHz;
idVarDef* frameRateDef = program.GetDef(&type_float, "GAME_FRAMETIME", &def_namespace);
if (frameRateDef != NULL) {
eval_t frameRateValue;
frameRateValue._float = frameRate;
frameRateDef->SetValue(frameRateValue, false);

common->Printf("GAME_FRAMETIME to: %f\n", frameRate);
}
else {
common->Printf("Unable to find GAME_FRAMETIME def\n");
}
}

#endif
10 changes: 10 additions & 0 deletions game/Game_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,13 @@ class idGameLocal : public idGame {
int previousTime; // time in msec of last frame
int previousClientsideTime; // time in msec of last frame (for clientsidecoop)
int time; // in msec

#ifdef _UNLOCKEDFPS
int msec; // time since last update in milliseconds
int gameFps; //added by Stradex for com_gameHz
#else
static const int msec = USERCMD_MSEC; // time since last update in milliseconds
#endif

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

Expand Down Expand Up @@ -616,6 +622,10 @@ class idGameLocal : public idGame {

void InitScriptForMap( void );

#ifdef _UNLOCKEDFPS
void SetScriptFPS(const float tCom_gameHz);
#endif

void InitConsoleCommands( void );
void ShutdownConsoleCommands( void );

Expand Down
4 changes: 4 additions & 0 deletions game/Game_network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2980,7 +2980,11 @@ void idGameLocal::sendServerOverflowEvents( void )
}
if (serverEventsCount > 0) {
common->Warning("[COOP] Server Events overflow!, using serverOverflowEvents queue list to avoid the crash for clients\n");
#ifdef _UNLOCKEDFPS
overflowEventCountdown=idMath::Rint((float)SERVER_EVENT_OVERFLOW_WAIT*(float)gameFps/60.0);
#else
overflowEventCountdown=SERVER_EVENT_OVERFLOW_WAIT;
#endif
}
if (overflowEventCountdown > 0) {
serverEventsCount=MAX_SERVER_EVENTS_PER_FRAME; //FIXME: Ugly way for doing this. Not pretty
Expand Down
8 changes: 8 additions & 0 deletions game/Moveable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,14 +394,22 @@ bool idMoveable::FollowInitialSplinePath( void ) {
if ( initialSpline != NULL ) {
if ( gameLocal.time < initialSpline->GetTime( initialSpline->GetNumValues() - 1 ) ) {
idVec3 splinePos = initialSpline->GetCurrentValue( gameLocal.time );
#ifdef _UNLOCKEDFPS
idVec3 linearVelocity = ( splinePos - physicsObj.GetOrigin() ) * gameLocal.gameFps;
#else
idVec3 linearVelocity = ( splinePos - physicsObj.GetOrigin() ) * USERCMD_HZ;
#endif
physicsObj.SetLinearVelocity( linearVelocity );

idVec3 splineDir = initialSpline->GetCurrentFirstDerivative( gameLocal.time );
idVec3 dir = initialSplineDir * physicsObj.GetAxis();
idVec3 angularVelocity = dir.Cross( splineDir );
angularVelocity.Normalize();
#ifdef _UNLOCKEDFPS
angularVelocity *= idMath::ACos16( dir * splineDir / splineDir.Length() ) * gameLocal.gameFps;
#else
angularVelocity *= idMath::ACos16( dir * splineDir / splineDir.Length() ) * USERCMD_HZ;
#endif
physicsObj.SetAngularVelocity( angularVelocity );
return true;
} else {
Expand Down
6 changes: 5 additions & 1 deletion game/Mover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2845,8 +2845,12 @@ void idMover_Binary::Use_BinaryMover( idEntity *activator ) {
if ( moverState == MOVER_POS1 ) {
// FIXME: start moving USERCMD_MSEC later, because if this was player
// triggered, gameLocal.time hasn't been advanced yet
MatchActivateTeam( MOVER_1TO2, gameLocal.time + USERCMD_MSEC );

#ifdef _UNLOCKEDFPS
MatchActivateTeam( MOVER_1TO2, gameLocal.time + gameLocal.msec );
#else
MatchActivateTeam( MOVER_1TO2, gameLocal.time + USERCMD_MSEC );
#endif
SetGuiStates( guiBinaryMoverStates[MOVER_1TO2] );
// open areaportal
ProcessEvent( &EV_Mover_OpenPortal );
Expand Down
3 changes: 3 additions & 0 deletions game/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1561,6 +1561,9 @@ void idPlayer::Init( void ) {
stamina = pm_stamina.GetFloat();

// air always initialized to maximum too
#ifdef _UNLOCKEDFPS
pm_airTics.SetFloat((static_cast<float>(gameLocal.gameFps) / 60.0) * pm_airTics.GetFloat()); //update for com_gameHz
#endif
airTics = pm_airTics.GetFloat();
airless = false;

Expand Down
8 changes: 8 additions & 0 deletions game/Projectile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1443,7 +1443,11 @@ idGuidedProjectile::Spawn
void idGuidedProjectile::Spawn( void ) {
if (gameLocal.mpGame.IsGametypeCoopBased() && gameLocal.isClient) {
rndScale = spawnArgs.GetAngles( "random", "15 15 0" );
#ifdef _UNLOCKEDFPS
turn_max = spawnArgs.GetFloat( "turn_max", "180" ) / ( float )gameLocal.gameFps;
#else
turn_max = spawnArgs.GetFloat( "turn_max", "180" ) / ( float )USERCMD_HZ;
#endif
clamp_dist = spawnArgs.GetFloat( "clamp_dist", "256" );
burstMode = spawnArgs.GetBool( "burstMode" );
unGuided = false;
Expand Down Expand Up @@ -1624,7 +1628,11 @@ void idGuidedProjectile::Launch( const idVec3 &start, const idVec3 &dir, const i
angles = vel.ToAngles();
speed = vel.Length();
rndScale = spawnArgs.GetAngles( "random", "15 15 0" );
#ifdef _UNLOCKEDFPS
turn_max = spawnArgs.GetFloat( "turn_max", "180" ) / ( float )gameLocal.gameFps;
#else
turn_max = spawnArgs.GetFloat( "turn_max", "180" ) / ( float )USERCMD_HZ;
#endif
clamp_dist = spawnArgs.GetFloat( "clamp_dist", "256" );
burstMode = spawnArgs.GetBool( "burstMode" );
unGuided = false;
Expand Down
4 changes: 4 additions & 0 deletions game/SmokeParticles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,11 @@ bool idSmokeParticles::EmitSmoke( const idDeclParticle *smoke, const int systemS
if ( nowCount >= stage->totalParticles ) {
nowCount = stage->totalParticles-1;
}
#ifdef _UNLOCKEDFPS
prevCount = floor( ((float)( deltaMsec - gameLocal.msec ) / finalParticleTime) * stage->totalParticles );
#else
prevCount = floor( ((float)( deltaMsec - USERCMD_MSEC ) / finalParticleTime) * stage->totalParticles );
#endif
if ( prevCount < -1 ) {
prevCount = -1;
}
Expand Down
10 changes: 9 additions & 1 deletion game/physics/Force_Drag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ If you have questions concerning this license or the applicable additional terms
#include "sys/platform.h"
#include "framework/UsercmdGen.h"

#ifdef _UNLOCKEDFPS
#include "Game_local.h"
#endif
#include "physics/Physics.h"

#include "physics/Force_Drag.h"
Expand Down Expand Up @@ -139,9 +142,14 @@ void idForce_Drag::Evaluate( int time ) {
l2 = dir2.Normalize();

rotation.Set( centerOfMass, dir2.Cross( dir1 ), RAD2DEG( idMath::ACos( dir1 * dir2 ) ) );
#ifdef _UNLOCKEDFPS
physics->SetAngularVelocity( rotation.ToAngularVelocity() / MS2SEC( gameLocal.msec ), id );
velocity = physics->GetLinearVelocity( id ) * damping + dir1 * ( ( l1 - l2 ) * ( 1.0f - damping ) / MS2SEC( gameLocal.msec ) );
#else
physics->SetAngularVelocity( rotation.ToAngularVelocity() / MS2SEC( USERCMD_MSEC ), id );

velocity = physics->GetLinearVelocity( id ) * damping + dir1 * ( ( l1 - l2 ) * ( 1.0f - damping ) / MS2SEC( USERCMD_MSEC ) );
#endif

physics->SetLinearVelocity( velocity, id );
}

Expand Down
6 changes: 6 additions & 0 deletions game/physics/Physics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ idPhysics::SnapTimeToPhysicsFrame
*/
int idPhysics::SnapTimeToPhysicsFrame( int t ) {
int s;

#ifdef _UNLOCKEDFPS
s = t + gameLocal.msec - 1;
return ( s - s % gameLocal.msec );
#else
s = t + USERCMD_MSEC - 1;
return ( s - s % USERCMD_MSEC );
#endif
}
6 changes: 6 additions & 0 deletions game/physics/Physics_AF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6620,7 +6620,13 @@ idPhysics_AF::idPhysics_AF( void ) {

memset( &current, 0, sizeof( current ) );
current.atRest = -1;

#ifdef _UNLOCKEDFPS
current.lastTimeStep = gameLocal.msec;
#else
current.lastTimeStep = USERCMD_MSEC;
#endif

saved = current;

linearFriction = 0.005f;
Expand Down
5 changes: 4 additions & 1 deletion game/physics/Physics_RigidBody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,11 @@ idPhysics_RigidBody::idPhysics_RigidBody( void ) {
memset( &current, 0, sizeof( current ) );

current.atRest = -1;
#ifdef _UNLOCKEDFPS
current.lastTimeStep = gameLocal.msec;
#else
current.lastTimeStep = USERCMD_MSEC;

#endif
current.i.position.Zero();
current.i.orientation.Identity();

Expand Down
4 changes: 4 additions & 0 deletions game/script/Script_Thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1788,7 +1788,11 @@ idThread::Event_GetTicsPerSecond
================
*/
void idThread::Event_GetTicsPerSecond( void ) {
#ifdef _UNLOCKEDFPS
idThread::ReturnFloat( gameLocal.gameFps );
#else
idThread::ReturnFloat( USERCMD_HZ );
#endif
}

/*
Expand Down

0 comments on commit 7f87c0b

Please sign in to comment.