| 72 | } |
| 73 | |
| 74 | void GameLoop::start() |
| 75 | { |
| 76 | init(); |
| 77 | initProcessMessages(); |
| 78 | |
| 79 | Lua::Callbacks::call(Lua::NamedLuaFunction::CallbackStartup); |
| 80 | |
| 81 | while (1) |
| 82 | { |
| 83 | bool exitMsg = startFrameMessages(); |
| 84 | if (exitMsg) { |
| 85 | loopExit(); |
| 86 | return; |
| 87 | } |
| 88 | |
| 89 | emit uiChanged(); |
| 90 | emit newFrame(); |
| 91 | |
| 92 | /* We are at a frame boundary */ |
| 93 | /* If we did not yet receive the game window id, just make the game running */ |
| 94 | bool endInnerLoop = false; |
| 95 | if (context->game_window ) do { |
| 96 | |
| 97 | /* Check if game is still running */ |
| 98 | int ret = waitpid(fork_pid, nullptr, WNOHANG); |
| 99 | if (ret == fork_pid) { |
| 100 | emit alertToShow(QString("Game was closed")); |
| 101 | loopExit(); |
| 102 | return; |
| 103 | } |
| 104 | |
| 105 | int eventFlag = gameEvents->handleEvent(); |
| 106 | |
| 107 | if (eventFlag & GameEvents::RETURN_FLAG_UPDATE) |
| 108 | emit uiChanged(); |
| 109 | |
| 110 | endInnerLoop = context->config.sc.running || |
| 111 | (eventFlag & GameEvents::RETURN_FLAG_ADVANCE) || |
| 112 | (context->status == Context::QUITTING); |
| 113 | |
| 114 | if (!endInnerLoop) { |
| 115 | sleepSendPreview(); |
| 116 | } |
| 117 | } while (!endInnerLoop); |
| 118 | |
| 119 | AllInputs ai; |
| 120 | processInputs(ai); |
| 121 | |
| 122 | /* Set the status to restart */ |
| 123 | if (ai.misc && (ai.misc->flags & (1 << SingleInput::FLAG_RESTART))) { |
| 124 | context->status = Context::RESTARTING; |
| 125 | } |
| 126 | |
| 127 | bool shouldQuit = false; |
| 128 | |
| 129 | /* Toggle pause when reaching a marker */ |
| 130 | if (context->config.editor_marker_pause) { |
| 131 | if (movie.editor->markers.count(context->framecount+1)) { |
no test coverage detected