From 6f545f178e4c840b593605bb3f77ab433f3d431c Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Sun, 15 Jun 2025 09:10:38 +0500 Subject: [PATCH] engine: host: move main loop contents into separate function --- engine/common/host.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/engine/common/host.c b/engine/common/host.c index c33e0894..ca40dc30 100644 --- a/engine/common/host.c +++ b/engine/common/host.c @@ -1185,6 +1185,14 @@ static void Sys_Quit_f( void ) Sys_Quit( "command" ); } +static void Host_MainLoop( void *userdata ) +{ + double *poldtime = (double *)userdata; + double newtime = Sys_DoubleTime(); + COM_Frame( newtime - *poldtime ); + *poldtime = newtime; +} + /* ================= Host_Main @@ -1192,7 +1200,7 @@ Host_Main */ int EXPORT Host_Main( int argc, char **argv, const char *progname, int bChangeGame, pfnChangeGame func ) { - static double oldtime, newtime; + static double oldtime; string demoname, exename; host.starttime = Sys_DoubleTime(); @@ -1344,15 +1352,14 @@ int EXPORT Host_Main( int argc, char **argv, const char *progname, int bChangeGa return error_on_exit; #endif // XASH_ANDROID +#if !XASH_EMSCRIPTEN // main window message loop while( host.status != HOST_CRASHED ) - { - newtime = Sys_DoubleTime (); - COM_Frame( newtime - oldtime ); - oldtime = newtime; - } + Host_MainLoop( &oldtime ); +#else // XASH_EMSCRIPTEN + emscripten_set_main_loop_arg( Host_MainLoop, &oldtime, 0, false ); +#endif // XASH_EMSCRIPTEN - // never reached return 0; }