mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-23 15:52:55 +01: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:
committed by
Michael Steenbeek
parent
c11e925f40
commit
ad4eaff323
@@ -25,6 +25,7 @@
|
|||||||
#include "core/FileScanner.h"
|
#include "core/FileScanner.h"
|
||||||
#include "core/FileStream.hpp"
|
#include "core/FileStream.hpp"
|
||||||
#include "core/Guard.hpp"
|
#include "core/Guard.hpp"
|
||||||
|
#include "core/Math.hpp"
|
||||||
#include "core/MemoryStream.h"
|
#include "core/MemoryStream.h"
|
||||||
#include "core/Path.hpp"
|
#include "core/Path.hpp"
|
||||||
#include "core/String.hpp"
|
#include "core/String.hpp"
|
||||||
@@ -361,7 +362,7 @@ namespace OpenRCT2
|
|||||||
}
|
}
|
||||||
network_begin_server(gNetworkStartPort, gNetworkStartAddress);
|
network_begin_server(gNetworkStartPort, gNetworkStartAddress);
|
||||||
}
|
}
|
||||||
#endif // DISABLE_NETWORK
|
#endif // DISABLE_NETWORK
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case STARTUP_ACTION_EDIT:
|
case STARTUP_ACTION_EDIT:
|
||||||
@@ -442,23 +443,18 @@ namespace OpenRCT2
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32 elapsed = currentTick - _lastTick;
|
uint32 elapsed = currentTick - _lastTick;
|
||||||
if (elapsed > UPDATE_TIME_MS)
|
|
||||||
{
|
|
||||||
elapsed = UPDATE_TIME_MS;
|
|
||||||
}
|
|
||||||
|
|
||||||
_lastTick = currentTick;
|
_lastTick = currentTick;
|
||||||
_accumulator += elapsed;
|
_accumulator = Math::Min(_accumulator + elapsed, (uint32)GAME_UPDATE_MAX_THRESHOLD);
|
||||||
|
|
||||||
_uiContext->ProcessMessages();
|
_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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_accumulator -= UPDATE_TIME_MS;
|
_accumulator -= GAME_UPDATE_TIME_MS;
|
||||||
|
|
||||||
Update();
|
Update();
|
||||||
if (!_isWindowMinimised && !gOpenRCT2Headless)
|
if (!_isWindowMinimised && !gOpenRCT2Headless)
|
||||||
@@ -480,17 +476,13 @@ namespace OpenRCT2
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32 elapsed = currentTick - _lastTick;
|
uint32 elapsed = currentTick - _lastTick;
|
||||||
if (elapsed > UPDATE_TIME_MS)
|
|
||||||
{
|
|
||||||
elapsed = UPDATE_TIME_MS;
|
|
||||||
}
|
|
||||||
|
|
||||||
_lastTick = currentTick;
|
_lastTick = currentTick;
|
||||||
_accumulator += elapsed;
|
_accumulator = Math::Min(_accumulator + elapsed, (uint32)GAME_UPDATE_MAX_THRESHOLD);
|
||||||
|
|
||||||
_uiContext->ProcessMessages();
|
_uiContext->ProcessMessages();
|
||||||
|
|
||||||
while (_accumulator >= UPDATE_TIME_MS)
|
while (_accumulator >= GAME_UPDATE_TIME_MS)
|
||||||
{
|
{
|
||||||
// Get the original position of each sprite
|
// Get the original position of each sprite
|
||||||
if(draw)
|
if(draw)
|
||||||
@@ -498,7 +490,7 @@ namespace OpenRCT2
|
|||||||
|
|
||||||
Update();
|
Update();
|
||||||
|
|
||||||
_accumulator -= UPDATE_TIME_MS;
|
_accumulator -= GAME_UPDATE_TIME_MS;
|
||||||
|
|
||||||
// Get the next position of each sprite
|
// Get the next position of each sprite
|
||||||
if(draw)
|
if(draw)
|
||||||
@@ -507,7 +499,7 @@ namespace OpenRCT2
|
|||||||
|
|
||||||
if (draw)
|
if (draw)
|
||||||
{
|
{
|
||||||
const float alpha = (float)_accumulator / UPDATE_TIME_MS;
|
const float alpha = (float)_accumulator / GAME_UPDATE_TIME_MS;
|
||||||
sprite_position_tween_all(alpha);
|
sprite_position_tween_all(alpha);
|
||||||
|
|
||||||
drawing_engine_draw();
|
drawing_engine_draw();
|
||||||
|
|||||||
@@ -103,15 +103,23 @@ namespace OpenRCT2
|
|||||||
IContext * CreateContext();
|
IContext * CreateContext();
|
||||||
IContext * CreateContext(IPlatformEnvironment * env, Audio::IAudioContext * audioContext, Ui::IUiContext * uiContext);
|
IContext * CreateContext(IPlatformEnvironment * env, Audio::IAudioContext * audioContext, Ui::IUiContext * uiContext);
|
||||||
IContext * GetContext();
|
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
|
#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
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -294,8 +294,8 @@ void game_update()
|
|||||||
if (gGameSpeed > 1) {
|
if (gGameSpeed > 1) {
|
||||||
numUpdates = 1 << (gGameSpeed - 1);
|
numUpdates = 1 << (gGameSpeed - 1);
|
||||||
} else {
|
} else {
|
||||||
numUpdates = gTicksSinceLastUpdate / 31;
|
numUpdates = gTicksSinceLastUpdate / GAME_UPDATE_TIME_MS;
|
||||||
numUpdates = clamp(1, numUpdates, 4);
|
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) {
|
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;
|
break;
|
||||||
case TITLE_SCRIPT_WAIT:
|
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
|
// 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;
|
break;
|
||||||
case TITLE_SCRIPT_LOADMM:
|
case TITLE_SCRIPT_LOADMM:
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user