mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-15 01:24:45 +02:00
Moved main loop to game engine class
This commit is contained in:
@ -104,27 +104,33 @@ void GameEngine::fakeMouseMove()
|
||||
});
|
||||
}
|
||||
|
||||
void GameEngine::renderFrame()
|
||||
[[noreturn]] void GameEngine::mainLoop()
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
std::scoped_lock interfaceLock(ENGINE->interfaceMutex);
|
||||
|
||||
engineUser->onUpdate();
|
||||
|
||||
handleEvents();
|
||||
windows().simpleRedraw();
|
||||
|
||||
if (settings["video"]["showfps"].Bool())
|
||||
drawFPSCounter();
|
||||
|
||||
screenHandlerInstance->updateScreenTexture();
|
||||
|
||||
windows().onFrameRendered();
|
||||
ENGINE->cursor().update();
|
||||
input().fetchEvents();
|
||||
updateFrame();
|
||||
screenHandlerInstance->presentScreenTexture();
|
||||
framerate().framerateDelay(); // holds a constant FPS
|
||||
}
|
||||
}
|
||||
|
||||
screenHandlerInstance->presentScreenTexture();
|
||||
framerate().framerateDelay(); // holds a constant FPS
|
||||
void GameEngine::updateFrame()
|
||||
{
|
||||
std::scoped_lock interfaceLock(ENGINE->interfaceMutex);
|
||||
|
||||
engineUser->onUpdate();
|
||||
|
||||
handleEvents();
|
||||
windows().simpleRedraw();
|
||||
|
||||
if (settings["video"]["showfps"].Bool())
|
||||
drawFPSCounter();
|
||||
|
||||
screenHandlerInstance->updateScreenTexture();
|
||||
|
||||
windows().onFrameRendered();
|
||||
ENGINE->cursor().update();
|
||||
}
|
||||
|
||||
GameEngine::GameEngine()
|
||||
|
@ -55,6 +55,8 @@ private:
|
||||
|
||||
IGameEngineUser *engineUser = nullptr;
|
||||
|
||||
void updateFrame();
|
||||
|
||||
public:
|
||||
std::mutex interfaceMutex;
|
||||
|
||||
@ -107,7 +109,7 @@ public:
|
||||
~GameEngine();
|
||||
|
||||
void init();
|
||||
void renderFrame();
|
||||
[[noreturn]] void mainLoop();
|
||||
|
||||
/// called whenever SDL_WINDOWEVENT_RESTORED is reported or the user selects a different resolution, requiring to center/resize all windows
|
||||
void onScreenResize(bool resolutionChanged);
|
||||
|
@ -68,11 +68,7 @@ namespace po_style = boost::program_options::command_line_style;
|
||||
static std::atomic<bool> headlessQuit = false;
|
||||
static std::optional<std::string> criticalInitializationError;
|
||||
|
||||
#ifndef VCMI_IOS
|
||||
void processCommand(const std::string &message);
|
||||
#endif
|
||||
[[noreturn]] static void quitApplication();
|
||||
static void mainLoop();
|
||||
|
||||
static CBasicLogConfigurator *logConfig;
|
||||
|
||||
@ -387,12 +383,15 @@ int main(int argc, char * argv[])
|
||||
GAME->mainmenu()->playMusic();
|
||||
}
|
||||
|
||||
std::vector<std::string> names;
|
||||
#ifndef VCMI_UNIX
|
||||
// on Linux, name of main thread is also name of our process. Which we don't want to change
|
||||
setThreadName("MainGUI");
|
||||
#endif
|
||||
|
||||
if(!settings["session"]["headless"].Bool())
|
||||
{
|
||||
checkForModLoadingFailure();
|
||||
mainLoop();
|
||||
ENGINE->mainLoop();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -404,23 +403,6 @@ int main(int argc, char * argv[])
|
||||
quitApplication();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void mainLoop()
|
||||
{
|
||||
#ifndef VCMI_UNIX
|
||||
// on Linux, name of main thread is also name of our process. Which we don't want to change
|
||||
setThreadName("MainGUI");
|
||||
#endif
|
||||
|
||||
while(1) //main SDL events loop
|
||||
{
|
||||
ENGINE->input().fetchEvents();
|
||||
ENGINE->renderFrame();
|
||||
}
|
||||
}
|
||||
|
||||
[[noreturn]] static void quitApplicationImmediately(int error_code)
|
||||
{
|
||||
// Perform quick exit without executing static destructors and let OS cleanup anything that we did not
|
||||
|
Reference in New Issue
Block a user