On macOS: Runs CFRunLoop to process main queue (required for JIT GLFW) On other platforms: Simple blocking wait
229{
230 LILA_INFO(Emitter::SYSTEM,
"Entering main event loop");
231
232#ifdef MAYAFLUX_PLATFORM_MACOS
233 while (!
m_shutdown_requested.load(std::memory_order_acquire) && (!external_flag || external_flag->load(std::memory_order_acquire))) {
235 LILA_ERROR(Emitter::SYSTEM,
"Server stopped unexpectedly");
236 break;
237 }
239 }
240
241#elif defined(MAYAFLUX_PLATFORM_WINDOWS)
242 if (MayaFlux::Parallel::g_MainThreadId == 0) {
243 MayaFlux::Parallel::g_MainThreadId = GetCurrentThreadId();
244 }
245
246 MSG msg;
247 PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);
248
250 && (!external_flag || external_flag->load(std::memory_order_acquire))) {
252 LILA_ERROR(Emitter::SYSTEM,
"Server stopped unexpectedly");
253 break;
254 }
255
256 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
257 if (msg.message == WM_QUIT) {
259 break;
260 }
261
262 if (msg.message == MAYAFLUX_WM_DISPATCH) {
263 auto* task = reinterpret_cast<std::function<void()>*>(msg.lParam);
264 if (task) {
265 (*task)();
266 task->~function();
267 HeapFree(GetProcessHeap(), 0, task);
268 }
269 } else {
270 TranslateMessage(&msg);
271 DispatchMessage(&msg);
272 }
273 }
274
275 std::this_thread::sleep_for(
277 }
278
279#else
280 while (!
m_shutdown_requested.load(std::memory_order_acquire) && (!external_flag || external_flag->load(std::memory_order_acquire))) {
282 LILA_ERROR(Emitter::SYSTEM,
"Server stopped unexpectedly");
283 break;
284 }
285 std::this_thread::sleep_for(std::chrono::milliseconds(
static_cast<int>(
server_loop_rate * 1000)));
286 }
287#endif
288
289 LILA_INFO(Emitter::SYSTEM,
"Exiting main event loop");
290}
float server_loop_rate
Server loop rate in seconds.
bool is_server_running() const
Checks if the server is currently running.
std::atomic< bool > m_shutdown_requested