mirror of https://github.com/OpenRCT2/OpenRCT2.git
Pass context object as argument, don't use singleton
This commit is contained in:
parent
23ec1d29e7
commit
100a63a743
|
@ -98,6 +98,7 @@ namespace OpenRCT2
|
||||||
uint32 _lastTick = 0;
|
uint32 _lastTick = 0;
|
||||||
uint32 _accumulator = 0;
|
uint32 _accumulator = 0;
|
||||||
uint32 _lastUpdateTick = 0;
|
uint32 _lastUpdateTick = 0;
|
||||||
|
bool _variableFrame = false;
|
||||||
|
|
||||||
/** If set, will end the OpenRCT2 game loop. Intentially private to this module so that the flag can not be set back to false. */
|
/** If set, will end the OpenRCT2 game loop. Intentially private to this module so that the flag can not be set back to false. */
|
||||||
bool _finished = false;
|
bool _finished = false;
|
||||||
|
@ -107,9 +108,6 @@ namespace OpenRCT2
|
||||||
// Remove this when GetContext() is no longer called so that
|
// Remove this when GetContext() is no longer called so that
|
||||||
// multiple instances can be created in parallel
|
// multiple instances can be created in parallel
|
||||||
static Context * Instance;
|
static Context * Instance;
|
||||||
static void RunFixedFrameFunc() {
|
|
||||||
Instance->RunFixedFrame();
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Context(IPlatformEnvironment * env, IAudioContext * audioContext, IUiContext * uiContext)
|
Context(IPlatformEnvironment * env, IAudioContext * audioContext, IUiContext * uiContext)
|
||||||
|
@ -549,6 +547,28 @@ namespace OpenRCT2
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void RunGameTick(void * vctx)
|
||||||
|
{
|
||||||
|
Context * ctx = reinterpret_cast<Context *>(vctx);
|
||||||
|
bool useVariableFrame = ctx->ShouldRunVariableFrame();
|
||||||
|
// Make sure we catch the state change and reset it.
|
||||||
|
if (ctx->_variableFrame != useVariableFrame)
|
||||||
|
{
|
||||||
|
ctx->_lastTick = 0;
|
||||||
|
ctx->_variableFrame = useVariableFrame;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (useVariableFrame)
|
||||||
|
{
|
||||||
|
ctx->RunVariableFrame();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ctx->RunFixedFrame();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run the main game loop until the finished flag is set.
|
* Run the main game loop until the finished flag is set.
|
||||||
*/
|
*/
|
||||||
|
@ -558,30 +578,15 @@ namespace OpenRCT2
|
||||||
_finished = false;
|
_finished = false;
|
||||||
|
|
||||||
#ifndef __EMSCRIPTEN__
|
#ifndef __EMSCRIPTEN__
|
||||||
bool variableFrame = ShouldRunVariableFrame();
|
_variableFrame = ShouldRunVariableFrame();
|
||||||
bool useVariableFrame;
|
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
useVariableFrame = ShouldRunVariableFrame();
|
RunGameTick(this);
|
||||||
// Make sure we catch the state change and reset it.
|
|
||||||
if (variableFrame != useVariableFrame)
|
|
||||||
{
|
|
||||||
_lastTick = 0;
|
|
||||||
variableFrame = useVariableFrame;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (useVariableFrame)
|
|
||||||
{
|
|
||||||
RunVariableFrame();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
RunFixedFrame();
|
|
||||||
}
|
|
||||||
} while (!_finished);
|
} while (!_finished);
|
||||||
#else
|
#else
|
||||||
emscripten_set_main_loop(RunFixedFrameFunc, 0, 1);
|
emscripten_set_main_loop_arg(RunGameTick, this, 0, 1);
|
||||||
#endif // __EMSCRIPTEN__
|
#endif // __EMSCRIPTEN__
|
||||||
log_verbose("finish openrct2 loop");
|
log_verbose("finish openrct2 loop");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue