]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
Darkplaces now works
authorLock l00p <hakzstudios@gmail.com>
Sun, 8 Oct 2023 04:09:37 +0000 (04:09 +0000)
committerLock l00p <hakzstudios@gmail.com>
Sun, 8 Oct 2023 04:09:37 +0000 (04:09 +0000)
host.c
sys_sdl.c

diff --git a/host.c b/host.c
index a20903a9823c7d156920999aac66077ac778bbf1..5a65ce2b03e7a71ffbfa2e27dd4e7721ddb65b67 100644 (file)
--- 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 <emscripten.h>
+#include <emscripten/html5.h>
+#endif
+
 #include <time.h>
 #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;
 }
index 94925886b0710d28b133c0e4e9fba27a45cc529a..0ef76f8d618bc54545f04684607b0d38178976c0 100644 (file)
--- 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);