diff --git a/source/duke3d/src/anim.cpp b/source/duke3d/src/anim.cpp index b95c6fd6c..407ba9c0d 100644 --- a/source/duke3d/src/anim.cpp +++ b/source/duke3d/src/anim.cpp @@ -478,7 +478,6 @@ int32_t Anim_Play(const char *fn) gltexapplyprops(); #endif - timerUpdate(); ototalclock = totalclock; i = 1; diff --git a/source/duke3d/src/game.cpp b/source/duke3d/src/game.cpp index d5a8323b8..7fdb8e96f 100644 --- a/source/duke3d/src/game.cpp +++ b/source/duke3d/src/game.cpp @@ -184,6 +184,15 @@ enum gametokens T_USERCONTENT, }; +static void gameTimerHandler(void) +{ + S_Cleanup(); + MUSIC_Update(); + + G_HandleSpecialKeys(); +} + + void G_HandleSpecialKeys(void) { auto &myplayer = *g_player[myconnectindex].ps; @@ -6024,6 +6033,7 @@ static void G_Startup(void) set_memerr_handler(&G_HandleMemErr); timerInit(TICRATE); + timerSetCallback(gameTimerHandler); initcrc32table(); @@ -6807,14 +6817,12 @@ MAIN_LOOP_RESTART: do //main loop { - if (handleevents() && quitevent) + if (G_HandleAsync() && quitevent) { KB_KeyDown[sc_Escape] = 1; quitevent = 0; } - Net_GetPackets(); - // only allow binds to function if the player is actually in a game (not in a menu, typing, et cetera) or demo CONTROL_BindsEnabled = !!(myplayer.gm & (MODE_GAME|MODE_DEMO)); @@ -6845,11 +6853,7 @@ MAIN_LOOP_RESTART: } else #endif - { - S_Cleanup(); - MUSIC_Update(); G_HandleLocalKeys(); - } OSD_DispatchQueued(); @@ -6865,8 +6869,6 @@ MAIN_LOOP_RESTART: do { - timerUpdate(); - if (ready2send == 0) break; ototalclock += TICSPERFRAME; @@ -6877,6 +6879,8 @@ MAIN_LOOP_RESTART: (myplayer.gm & MODE_GAME)) { G_MoveLoop(); + S_Update(); + #ifdef __ANDROID__ inputfifo[0][myconnectindex].fvel = 0; inputfifo[0][myconnectindex].svel = 0; @@ -6885,8 +6889,6 @@ MAIN_LOOP_RESTART: #endif } - timerUpdate(); - if (totalclock - moveClock >= TICSPERFRAME) { // computing a tic takes longer than a tic, so we're slowing diff --git a/source/duke3d/src/game.h b/source/duke3d/src/game.h index ed24c2c79..e6453683b 100644 --- a/source/duke3d/src/game.h +++ b/source/duke3d/src/game.h @@ -440,10 +440,10 @@ extern int G_StartRTS(int lumpNum, int localPlayer); extern void G_MaybeAllocPlayer(int32_t pnum); -static inline void G_HandleAsync(void) +static inline int32_t G_HandleAsync(void) { - handleevents(); Net_GetPackets(); + return handleevents(); } static inline int32_t calc_smoothratio_demo(ClockTicks totalclk, ClockTicks ototalclk) diff --git a/source/duke3d/src/gameexec.cpp b/source/duke3d/src/gameexec.cpp index 8742efefa..167945775 100644 --- a/source/duke3d/src/gameexec.cpp +++ b/source/duke3d/src/gameexec.cpp @@ -1222,7 +1222,7 @@ void Screen_Play(void) do { - G_HandleAsync(); + gameHandleEvents(); ototalclock = totalclock + 1; // pause game like ANMs diff --git a/source/duke3d/src/network.cpp b/source/duke3d/src/network.cpp index 16c99c1c2..572b8812b 100644 --- a/source/duke3d/src/network.cpp +++ b/source/duke3d/src/network.cpp @@ -65,22 +65,9 @@ int32_t g_networkMode = NET_CLIENT; typedef TYPE_PUNNED int32_t NetChunk32; +void faketimerhandler(void) { ; } -// Unfortunately faketimerhandler needs extra "help" because the Build Engine source doesn't include network.h. -#ifdef NETCODE_DISABLE -void faketimerhandler(void) -{ - ; -} -#else -void faketimerhandler(void) -{ - if (g_netServer == NULL && g_netClient == NULL) - return; - - enet_host_service(g_netServer ? g_netServer : g_netClient, NULL, 0); -} - +#ifndef NETCODE_DISABLE static void Net_Disconnect(void); static void Net_HandleClientPackets(void); static void Net_HandleServerPackets(void); @@ -88,13 +75,10 @@ static void Net_HandleServerPackets(void); void Net_GetPackets(void) { - timerUpdate(); - MUSIC_Update(); - S_Update(); - - G_HandleSpecialKeys(); - #ifndef NETCODE_DISABLE + if (g_netServer == NULL && g_netClient == NULL) + return; + if (g_netDisconnect) { Net_Disconnect(); @@ -106,14 +90,12 @@ void Net_GetPackets(void) return; } + enet_host_service(g_netServer ? g_netServer : g_netClient, NULL, 0); + if (g_netServer) - { Net_HandleClientPackets(); - } else if (g_netClient) - { Net_HandleServerPackets(); - } #endif } diff --git a/source/duke3d/src/premap.cpp b/source/duke3d/src/premap.cpp index f6855c554..69d073c5d 100644 --- a/source/duke3d/src/premap.cpp +++ b/source/duke3d/src/premap.cpp @@ -481,7 +481,6 @@ void G_CacheMapData(void) { Bsprintf(tempbuf, "Loaded %d%% (%d/%d textures)\n", percentDisplayed, cnt, g_precacheCount); G_DoLoadScreen(tempbuf, percentDisplayed); - timerUpdate(); if (totalclock - clock >= 1) { diff --git a/source/duke3d/src/savegame.cpp b/source/duke3d/src/savegame.cpp index f716861d7..4cacde44f 100644 --- a/source/duke3d/src/savegame.cpp +++ b/source/duke3d/src/savegame.cpp @@ -703,8 +703,6 @@ static void G_SaveTimers(void) static void G_RestoreTimers(void) { - timerUpdate(); - totalclock = g_timers.totalclock; totalclocklock = g_timers.totalclocklock; ototalclock = g_timers.ototalclock;