From: Lock l00p Date: Sun, 8 Oct 2023 04:09:37 +0000 (+0000) Subject: Darkplaces now works X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=47c8b75208d8b6bd7d5959d09bfe019df46124c0;p=xonotic%2Fdarkplaces.git Darkplaces now works --- diff --git a/host.c b/host.c index a20903a9..5a65ce2b 100644 --- a/host.c +++ b/host.c @@ -22,11 +22,17 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "quakedef.h" +#ifdef __EMSCRIPTEN__ +#include +#include +#endif + #include #include "libcurl.h" #include "taskqueue.h" #include "utf8lib.h" +double timee, oldtime, sleeptime; /* A server can always be started, even if the system started out as a client @@ -723,9 +729,26 @@ static inline double Host_UpdateTime (double newtime, double oldtime) return time; } +void Host_Loop(void){ + // Something bad happened, or the server disconnected + if (setjmp(host.abortframe)) + { + host.state = host_active; // In case we were loading + } + + host.dirtytime = Sys_DirtyTime(); + host.realtime += timee = Host_UpdateTime(host.dirtytime, oldtime); + + sleeptime = Host_Frame(timee); + oldtime = host.dirtytime; + ++host.framecount; + + sleeptime -= Sys_DirtyTime() - host.dirtytime; // execution time + host.sleeptime = Host_Sleep(sleeptime); +} + void Host_Main(void) { - double time, oldtime, sleeptime; Host_Init(); // Start! @@ -733,25 +756,13 @@ void Host_Main(void) oldtime = Sys_DirtyTime(); // Main event loop + #ifdef __EMSCRIPTEN__ + emscripten_set_main_loop(Host_Loop,60,true); + #else while(host.state != host_shutdown) { - // Something bad happened, or the server disconnected - if (setjmp(host.abortframe)) - { - host.state = host_active; // In case we were loading - continue; - } - - host.dirtytime = Sys_DirtyTime(); - host.realtime += time = Host_UpdateTime(host.dirtytime, oldtime); - - sleeptime = Host_Frame(time); - oldtime = host.dirtytime; - ++host.framecount; - - sleeptime -= Sys_DirtyTime() - host.dirtytime; // execution time - host.sleeptime = Host_Sleep(sleeptime); + Host_Loop(); } - + #endif return; } diff --git a/sys_sdl.c b/sys_sdl.c index 94925886..0ef76f8d 100644 --- a/sys_sdl.c +++ b/sys_sdl.c @@ -142,7 +142,7 @@ char *Sys_ConsoleInput(void) len = 0; } #else - #ifndef DP_WASM + #ifndef __EMSCRIPTEN__ fd_set fdset; struct timeval timeout; FD_ZERO(&fdset);