| 1108 | } |
| 1109 | |
| 1110 | int Application::mainLogic(Application* app) { |
| 1111 | app->_logicThreadID = std::this_thread::get_id(); |
| 1112 | |
| 1113 | if (!SharedBGFX.init(app->_platformData)) { |
| 1114 | Error("bgfx failed to initialize!"); |
| 1115 | return 1; |
| 1116 | } |
| 1117 | |
| 1118 | SharedPoolManager.push(); |
| 1119 | if (!SharedDirector.init()) { |
| 1120 | Error("Director failed to initialize!"); |
| 1121 | return 1; |
| 1122 | } |
| 1123 | |
| 1124 | if (app->_mainFunc) { |
| 1125 | if (!app->_mainFunc()) { |
| 1126 | Error("Failed to start main!"); |
| 1127 | return 1; |
| 1128 | } |
| 1129 | } |
| 1130 | |
| 1131 | #if BX_PLATFORM_OSX || BX_PLATFORM_WINDOWS || BX_PLATFORM_LINUX |
| 1132 | for (int i = 0; i < 3; i++) { |
| 1133 | app->_frame = bgfx::frame(); |
| 1134 | } |
| 1135 | app->invokeInRender([app]() { |
| 1136 | SDL_ShowWindow(app->_sdlWindow); |
| 1137 | }); |
| 1138 | #else |
| 1139 | app->_frame = bgfx::frame(); |
| 1140 | #endif |
| 1141 | |
| 1142 | app->makeTimeNow(); |
| 1143 | app->_startTime = app->_lastTime; |
| 1144 | |
| 1145 | SharedPoolManager.pop(); |
| 1146 | |
| 1147 | while (app->_logicRunning) { |
| 1148 | auto startTime = app->getElapsedTime(); |
| 1149 | |
| 1150 | SharedPoolManager.push(); |
| 1151 | |
| 1152 | // poll events from render thread |
| 1153 | for (Own<QEvent> event = app->_logicEvent.poll(); |
| 1154 | event != nullptr; |
| 1155 | event = app->_logicEvent.poll()) { |
| 1156 | switch (Switch::hash(event->getName())) { |
| 1157 | case "SDLEvent"_hash: { |
| 1158 | SDL_Event sdlEvent; |
| 1159 | event->get(sdlEvent); |
| 1160 | switch (sdlEvent.type) { |
| 1161 | case SDL_QUIT: { |
| 1162 | app->_logicRunning = false; |
| 1163 | app->quitHandler(); |
| 1164 | // Info("singleton reference tree:\n{}", Life::getRefTree()); |
| 1165 | break; |
| 1166 | } |
| 1167 | default: |
nothing calls this directly
no test coverage detected