mirror of
https://github.com/OpenRCT2/OpenRCT2.git
synced 2025-01-23 10:51:58 -05:00
Fix game not allowing to catch up if rendering is slow.
Refactored game_update to use the given parameters from context.
This commit is contained in:
parent
c11e925f40
commit
ad4eaff323
4 changed files with 26 additions and 26 deletions
|
@ -25,6 +25,7 @@
|
|||
#include "core/FileScanner.h"
|
||||
#include "core/FileStream.hpp"
|
||||
#include "core/Guard.hpp"
|
||||
#include "core/Math.hpp"
|
||||
#include "core/MemoryStream.h"
|
||||
#include "core/Path.hpp"
|
||||
#include "core/String.hpp"
|
||||
|
@ -361,7 +362,7 @@ namespace OpenRCT2
|
|||
}
|
||||
network_begin_server(gNetworkStartPort, gNetworkStartAddress);
|
||||
}
|
||||
#endif // DISABLE_NETWORK
|
||||
#endif // DISABLE_NETWORK
|
||||
break;
|
||||
}
|
||||
case STARTUP_ACTION_EDIT:
|
||||
|
@ -442,23 +443,18 @@ namespace OpenRCT2
|
|||
}
|
||||
|
||||
uint32 elapsed = currentTick - _lastTick;
|
||||
if (elapsed > UPDATE_TIME_MS)
|
||||
{
|
||||
elapsed = UPDATE_TIME_MS;
|
||||
}
|
||||
|
||||
_lastTick = currentTick;
|
||||
_accumulator += elapsed;
|
||||
_accumulator = Math::Min(_accumulator + elapsed, (uint32)GAME_UPDATE_MAX_THRESHOLD);
|
||||
|
||||
_uiContext->ProcessMessages();
|
||||
|
||||
if (_accumulator < UPDATE_TIME_MS)
|
||||
if (_accumulator < GAME_UPDATE_TIME_MS)
|
||||
{
|
||||
platform_sleep(UPDATE_TIME_MS - _accumulator - 1);
|
||||
platform_sleep(GAME_UPDATE_TIME_MS - _accumulator - 1);
|
||||
return;
|
||||
}
|
||||
|
||||
_accumulator -= UPDATE_TIME_MS;
|
||||
_accumulator -= GAME_UPDATE_TIME_MS;
|
||||
|
||||
Update();
|
||||
if (!_isWindowMinimised && !gOpenRCT2Headless)
|
||||
|
@ -480,17 +476,13 @@ namespace OpenRCT2
|
|||
}
|
||||
|
||||
uint32 elapsed = currentTick - _lastTick;
|
||||
if (elapsed > UPDATE_TIME_MS)
|
||||
{
|
||||
elapsed = UPDATE_TIME_MS;
|
||||
}
|
||||
|
||||
_lastTick = currentTick;
|
||||
_accumulator += elapsed;
|
||||
_accumulator = Math::Min(_accumulator + elapsed, (uint32)GAME_UPDATE_MAX_THRESHOLD);
|
||||
|
||||
_uiContext->ProcessMessages();
|
||||
|
||||
while (_accumulator >= UPDATE_TIME_MS)
|
||||
while (_accumulator >= GAME_UPDATE_TIME_MS)
|
||||
{
|
||||
// Get the original position of each sprite
|
||||
if(draw)
|
||||
|
@ -498,7 +490,7 @@ namespace OpenRCT2
|
|||
|
||||
Update();
|
||||
|
||||
_accumulator -= UPDATE_TIME_MS;
|
||||
_accumulator -= GAME_UPDATE_TIME_MS;
|
||||
|
||||
// Get the next position of each sprite
|
||||
if(draw)
|
||||
|
@ -507,7 +499,7 @@ namespace OpenRCT2
|
|||
|
||||
if (draw)
|
||||
{
|
||||
const float alpha = (float)_accumulator / UPDATE_TIME_MS;
|
||||
const float alpha = (float)_accumulator / GAME_UPDATE_TIME_MS;
|
||||
sprite_position_tween_all(alpha);
|
||||
|
||||
drawing_engine_draw();
|
||||
|
|
|
@ -103,15 +103,23 @@ namespace OpenRCT2
|
|||
IContext * CreateContext();
|
||||
IContext * CreateContext(IPlatformEnvironment * env, Audio::IAudioContext * audioContext, Ui::IUiContext * uiContext);
|
||||
IContext * GetContext();
|
||||
|
||||
// The game update inverval in milliseconds, (1000 / 40fps) = 25ms
|
||||
constexpr uint32 UPDATE_TIME_MS = 25;
|
||||
// The number of logical update / ticks per second.
|
||||
constexpr uint32 UPDATE_FPS = 40;
|
||||
}
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
enum
|
||||
{
|
||||
// The game update inverval in milliseconds, (1000 / 40fps) = 25ms
|
||||
GAME_UPDATE_TIME_MS = 25,
|
||||
// The number of logical update / ticks per second.
|
||||
GAME_UPDATE_FPS = 40,
|
||||
// The maximum amount of updates in case rendering is slower
|
||||
GAME_MAX_UPDATES = 4,
|
||||
// The maximum threshold to advance.
|
||||
GAME_UPDATE_MAX_THRESHOLD = GAME_UPDATE_TIME_MS * GAME_MAX_UPDATES,
|
||||
};
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
|
|
|
@ -294,8 +294,8 @@ void game_update()
|
|||
if (gGameSpeed > 1) {
|
||||
numUpdates = 1 << (gGameSpeed - 1);
|
||||
} else {
|
||||
numUpdates = gTicksSinceLastUpdate / 31;
|
||||
numUpdates = clamp(1, numUpdates, 4);
|
||||
numUpdates = gTicksSinceLastUpdate / GAME_UPDATE_TIME_MS;
|
||||
numUpdates = clamp(1, numUpdates, GAME_MAX_UPDATES);
|
||||
}
|
||||
|
||||
if (network_get_mode() == NETWORK_MODE_CLIENT && network_get_status() == NETWORK_STATUS_CONNECTED && network_get_authstatus() == NETWORK_AUTH_OK) {
|
||||
|
|
|
@ -248,7 +248,7 @@ private:
|
|||
break;
|
||||
case TITLE_SCRIPT_WAIT:
|
||||
// The waitCounter is measured in 25-ms game ticks. Previously it was seconds * 40 ticks/second, now it is ms / 25 ms/tick
|
||||
_waitCounter = Math::Max<sint32>(1, command->Milliseconds / UPDATE_TIME_MS);
|
||||
_waitCounter = Math::Max<sint32>(1, command->Milliseconds / (uint32)GAME_UPDATE_TIME_MS);
|
||||
break;
|
||||
case TITLE_SCRIPT_LOADMM:
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue