-
Notifications
You must be signed in to change notification settings - Fork 357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add com_gameHz to play with higher HZ/FPS #297
base: master
Are you sure you want to change the base?
Changes from all commits
65d12cb
6d9f3d3
9ab12b7
8738450
695d050
15f4e5e
d6c7304
bb0dd7d
168b027
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -248,6 +248,7 @@ void idGameLocal::Clear( void ) { | |
framenum = 0; | ||
previousTime = 0; | ||
time = 0; | ||
preciseTime = 0.0f; | ||
vacuumAreaNum = 0; | ||
mapFileName.Clear(); | ||
mapFile = NULL; | ||
|
@@ -309,6 +310,10 @@ void idGameLocal::Init( void ) { | |
const idDict *dict; | ||
idAAS *aas; | ||
|
||
msec = 16.0; //60fps | ||
gameMsec = msec; | ||
gameFps = 60; //60fps | ||
|
||
#ifndef GAME_DLL | ||
|
||
TestGameAPI(); | ||
|
@@ -326,6 +331,12 @@ void idGameLocal::Init( void ) { | |
|
||
#endif | ||
|
||
//Update MSEC and gameFps | ||
gameFps = cvarSystem->GetCVarInteger("com_gameHz"); | ||
msec = 1000.0f / cvarSystem->GetCVarFloat("com_gameHz"); | ||
msec *= 0.96f*0.96f; //HACK to emulate OG D3 msec error, in order to have exactly the same game logic speed | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That was a mistake from me. I thought that I needed to do that twice because common frame was already working at 16.666 hz, but multiplying by 0.96f twice was a mistake. In fact that product for 0.96f is something I don't like at all. It is some kind of "duct-tape" ugly code. I will look at this feature in some days or weeks in order to see if with a fresh mind I can actually figure out something better. |
||
gameMsec = msec; | ||
|
||
Printf( "----- Initializing Game -----\n" ); | ||
Printf( "gamename: %s\n", GAME_VERSION ); | ||
Printf( "gamedate: %s\n", __DATE__ ); | ||
|
@@ -594,12 +605,14 @@ void idGameLocal::SaveGame( idFile *f ) { | |
savegame.WriteBool( isMultiplayer ); | ||
savegame.WriteInt( gameType ); | ||
|
||
savegame.WriteFloat(preciseTime); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this breaks savegame compatibility :-( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for letting me know this. I will try to find a way to avoid that, in fact I was looking at the BFG Edition code like a lot, and there are many things that I don't like about this pull request after looking at that. So I will try to find a way to improve this or actually try this again but most similar to the BFG Edition approach. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the best way to do this is to bump |
||
|
||
savegame.WriteInt( framenum ); | ||
savegame.WriteInt( previousTime ); | ||
savegame.WriteInt( time ); | ||
|
||
#ifdef _D3XP | ||
savegame.WriteInt( msec ); | ||
savegame.WriteFloat( msec ); | ||
#endif | ||
|
||
savegame.WriteInt( vacuumAreaNum ); | ||
|
@@ -1000,6 +1013,7 @@ void idGameLocal::LoadMap( const char *mapName, int randseed ) { | |
|
||
previousTime = 0; | ||
time = 0; | ||
preciseTime = 0.0f; | ||
framenum = 0; | ||
sessionCommand = ""; | ||
nextGibTime = 0; | ||
|
@@ -1473,12 +1487,14 @@ bool idGameLocal::InitFromSaveGame( const char *mapName, idRenderWorld *renderWo | |
savegame.ReadBool( isMultiplayer ); | ||
savegame.ReadInt( (int &)gameType ); | ||
|
||
savegame.ReadFloat(preciseTime); | ||
|
||
savegame.ReadInt( framenum ); | ||
savegame.ReadInt( previousTime ); | ||
savegame.ReadInt( time ); | ||
|
||
#ifdef _D3XP | ||
savegame.ReadInt( msec ); | ||
savegame.ReadFloat( msec ); | ||
#endif | ||
|
||
savegame.ReadInt( vacuumAreaNum ); | ||
|
@@ -1520,7 +1536,7 @@ bool idGameLocal::InitFromSaveGame( const char *mapName, idRenderWorld *renderWo | |
} | ||
} | ||
if ( gameSoundWorld ) { | ||
gameSoundWorld->SetSlowmoSpeed( slowmoMsec / (float)USERCMD_MSEC ); | ||
gameSoundWorld->SetSlowmoSpeed( slowmoMsec / (float)gameMsec ); | ||
} | ||
#endif | ||
|
||
|
@@ -2431,7 +2447,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 | ||
|
@@ -3812,7 +3829,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 ); | ||
} | ||
} | ||
|
@@ -4225,7 +4242,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 ); | ||
|
@@ -4821,7 +4838,7 @@ void idGameLocal::ComputeSlowMsec() { | |
|
||
// stop the state | ||
slowmoState = SLOWMO_STATE_OFF; | ||
slowmoMsec = USERCMD_MSEC; | ||
slowmoMsec = gameMsec; | ||
} | ||
|
||
// check the player state | ||
|
@@ -4842,7 +4859,7 @@ void idGameLocal::ComputeSlowMsec() { | |
slowmoMsec = msec; | ||
if ( gameSoundWorld ) { | ||
gameSoundWorld->SetSlowmo( true ); | ||
gameSoundWorld->SetSlowmoSpeed( slowmoMsec / (float)USERCMD_MSEC ); | ||
gameSoundWorld->SetSlowmoSpeed( slowmoMsec / gameMsec ); | ||
} | ||
} | ||
else if ( !powerupOn && slowmoState == SLOWMO_STATE_ON ) { | ||
|
@@ -4856,25 +4873,25 @@ void idGameLocal::ComputeSlowMsec() { | |
|
||
// do any necessary ramping | ||
if ( slowmoState == SLOWMO_STATE_RAMPUP ) { | ||
delta = 4 - slowmoMsec; | ||
delta = 4.0 * 60.0 / (float)gameFps - slowmoMsec; | ||
|
||
if ( fabs( delta ) < g_slowmoStepRate.GetFloat() ) { | ||
slowmoMsec = 4; | ||
slowmoMsec = 4.0 * 60.0 / (float)gameFps; | ||
slowmoState = SLOWMO_STATE_ON; | ||
} | ||
else { | ||
slowmoMsec += delta * g_slowmoStepRate.GetFloat(); | ||
} | ||
|
||
if ( gameSoundWorld ) { | ||
gameSoundWorld->SetSlowmoSpeed( slowmoMsec / (float)USERCMD_MSEC ); | ||
gameSoundWorld->SetSlowmoSpeed( slowmoMsec / gameMsec ); | ||
} | ||
} | ||
else if ( slowmoState == SLOWMO_STATE_RAMPDOWN ) { | ||
delta = 16 - slowmoMsec; | ||
delta = 16.0 * 60.0 / gameFps - slowmoMsec; | ||
|
||
if ( fabs( delta ) < g_slowmoStepRate.GetFloat() ) { | ||
slowmoMsec = 16; | ||
slowmoMsec = 16.0*60.0/(float)gameFps; | ||
slowmoState = SLOWMO_STATE_OFF; | ||
if ( gameSoundWorld ) { | ||
gameSoundWorld->SetSlowmo( false ); | ||
|
@@ -4885,7 +4902,7 @@ void idGameLocal::ComputeSlowMsec() { | |
} | ||
|
||
if ( gameSoundWorld ) { | ||
gameSoundWorld->SetSlowmoSpeed( slowmoMsec / (float)USERCMD_MSEC ); | ||
gameSoundWorld->SetSlowmoSpeed( slowmoMsec / gameMsec ); | ||
} | ||
} | ||
} | ||
|
@@ -4896,19 +4913,19 @@ idGameLocal::ResetSlowTimeVars | |
============ | ||
*/ | ||
void idGameLocal::ResetSlowTimeVars() { | ||
msec = USERCMD_MSEC; | ||
slowmoMsec = USERCMD_MSEC; | ||
msec = gameMsec; | ||
slowmoMsec = gameMsec; | ||
slowmoState = SLOWMO_STATE_OFF; | ||
|
||
fast.framenum = 0; | ||
fast.previousTime = 0; | ||
fast.time = 0; | ||
fast.msec = USERCMD_MSEC; | ||
fast.msec = gameMsec; | ||
|
||
slow.framenum = 0; | ||
slow.previousTime = 0; | ||
slow.time = 0; | ||
slow.msec = USERCMD_MSEC; | ||
slow.msec = gameMsec; | ||
} | ||
|
||
/* | ||
|
@@ -4985,4 +5002,4 @@ void idGameLocal::SwitchTeam( int clientNum, int team ) { | |
idGameLocal::GetMapLoadingGUI | ||
=============== | ||
*/ | ||
void idGameLocal::GetMapLoadingGUI( char gui[ MAX_STRING_CHARS ] ) { } | ||
void idGameLocal::GetMapLoadingGUI( char gui[ MAX_STRING_CHARS ] ) { } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please put a space after "//", e.g.
// 60fps
(yes, always, not just here), like it's done in the existing code(it also just looks better)