Partial timer cleanup

After this revision, the only place timerUpdate() is called is from within handleevents(). S_Cleanup(), MUSIC_Update(), and G_HandleSpecialKeys() are now called from a timer callback set with timerSetCallback(). This more or less deprecates the usage of faketimerhandler() in EDuke32 and Mapster32, but other games still rely on the functionality.

git-svn-id: https://svn.eduke32.com/eduke32@8139 1a8010ca-5511-0410-912e-c29ae57300e0

# Conflicts:
#	source/duke3d/src/astub.cpp
This commit is contained in:
terminx 2019-10-19 23:41:35 +00:00 committed by Christoph Oelckers
parent 593b5740e3
commit 802f69d324
7 changed files with 23 additions and 43 deletions

View File

@ -478,7 +478,6 @@ int32_t Anim_Play(const char *fn)
gltexapplyprops(); gltexapplyprops();
#endif #endif
timerUpdate();
ototalclock = totalclock; ototalclock = totalclock;
i = 1; i = 1;

View File

@ -184,6 +184,15 @@ enum gametokens
T_USERCONTENT, T_USERCONTENT,
}; };
static void gameTimerHandler(void)
{
S_Cleanup();
MUSIC_Update();
G_HandleSpecialKeys();
}
void G_HandleSpecialKeys(void) void G_HandleSpecialKeys(void)
{ {
auto &myplayer = *g_player[myconnectindex].ps; auto &myplayer = *g_player[myconnectindex].ps;
@ -6024,6 +6033,7 @@ static void G_Startup(void)
set_memerr_handler(&G_HandleMemErr); set_memerr_handler(&G_HandleMemErr);
timerInit(TICRATE); timerInit(TICRATE);
timerSetCallback(gameTimerHandler);
initcrc32table(); initcrc32table();
@ -6807,14 +6817,12 @@ MAIN_LOOP_RESTART:
do //main loop do //main loop
{ {
if (handleevents() && quitevent) if (G_HandleAsync() && quitevent)
{ {
KB_KeyDown[sc_Escape] = 1; KB_KeyDown[sc_Escape] = 1;
quitevent = 0; 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 // 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)); CONTROL_BindsEnabled = !!(myplayer.gm & (MODE_GAME|MODE_DEMO));
@ -6845,11 +6853,7 @@ MAIN_LOOP_RESTART:
} }
else else
#endif #endif
{
S_Cleanup();
MUSIC_Update();
G_HandleLocalKeys(); G_HandleLocalKeys();
}
OSD_DispatchQueued(); OSD_DispatchQueued();
@ -6865,8 +6869,6 @@ MAIN_LOOP_RESTART:
do do
{ {
timerUpdate();
if (ready2send == 0) break; if (ready2send == 0) break;
ototalclock += TICSPERFRAME; ototalclock += TICSPERFRAME;
@ -6877,6 +6879,8 @@ MAIN_LOOP_RESTART:
(myplayer.gm & MODE_GAME)) (myplayer.gm & MODE_GAME))
{ {
G_MoveLoop(); G_MoveLoop();
S_Update();
#ifdef __ANDROID__ #ifdef __ANDROID__
inputfifo[0][myconnectindex].fvel = 0; inputfifo[0][myconnectindex].fvel = 0;
inputfifo[0][myconnectindex].svel = 0; inputfifo[0][myconnectindex].svel = 0;
@ -6885,8 +6889,6 @@ MAIN_LOOP_RESTART:
#endif #endif
} }
timerUpdate();
if (totalclock - moveClock >= TICSPERFRAME) if (totalclock - moveClock >= TICSPERFRAME)
{ {
// computing a tic takes longer than a tic, so we're slowing // computing a tic takes longer than a tic, so we're slowing

View File

@ -440,10 +440,10 @@ extern int G_StartRTS(int lumpNum, int localPlayer);
extern void G_MaybeAllocPlayer(int32_t pnum); extern void G_MaybeAllocPlayer(int32_t pnum);
static inline void G_HandleAsync(void) static inline int32_t G_HandleAsync(void)
{ {
handleevents();
Net_GetPackets(); Net_GetPackets();
return handleevents();
} }
static inline int32_t calc_smoothratio_demo(ClockTicks totalclk, ClockTicks ototalclk) static inline int32_t calc_smoothratio_demo(ClockTicks totalclk, ClockTicks ototalclk)

View File

@ -1222,7 +1222,7 @@ void Screen_Play(void)
do do
{ {
G_HandleAsync(); gameHandleEvents();
ototalclock = totalclock + 1; // pause game like ANMs ototalclock = totalclock + 1; // pause game like ANMs

View File

@ -65,22 +65,9 @@ int32_t g_networkMode = NET_CLIENT;
typedef TYPE_PUNNED int32_t NetChunk32; typedef TYPE_PUNNED int32_t NetChunk32;
void faketimerhandler(void) { ; }
// Unfortunately faketimerhandler needs extra "help" because the Build Engine source doesn't include network.h. #ifndef NETCODE_DISABLE
#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);
}
static void Net_Disconnect(void); static void Net_Disconnect(void);
static void Net_HandleClientPackets(void); static void Net_HandleClientPackets(void);
static void Net_HandleServerPackets(void); static void Net_HandleServerPackets(void);
@ -88,13 +75,10 @@ static void Net_HandleServerPackets(void);
void Net_GetPackets(void) void Net_GetPackets(void)
{ {
timerUpdate();
MUSIC_Update();
S_Update();
G_HandleSpecialKeys();
#ifndef NETCODE_DISABLE #ifndef NETCODE_DISABLE
if (g_netServer == NULL && g_netClient == NULL)
return;
if (g_netDisconnect) if (g_netDisconnect)
{ {
Net_Disconnect(); Net_Disconnect();
@ -106,14 +90,12 @@ void Net_GetPackets(void)
return; return;
} }
enet_host_service(g_netServer ? g_netServer : g_netClient, NULL, 0);
if (g_netServer) if (g_netServer)
{
Net_HandleClientPackets(); Net_HandleClientPackets();
}
else if (g_netClient) else if (g_netClient)
{
Net_HandleServerPackets(); Net_HandleServerPackets();
}
#endif #endif
} }

View File

@ -481,7 +481,6 @@ void G_CacheMapData(void)
{ {
Bsprintf(tempbuf, "Loaded %d%% (%d/%d textures)\n", percentDisplayed, cnt, g_precacheCount); Bsprintf(tempbuf, "Loaded %d%% (%d/%d textures)\n", percentDisplayed, cnt, g_precacheCount);
G_DoLoadScreen(tempbuf, percentDisplayed); G_DoLoadScreen(tempbuf, percentDisplayed);
timerUpdate();
if (totalclock - clock >= 1) if (totalclock - clock >= 1)
{ {

View File

@ -703,8 +703,6 @@ static void G_SaveTimers(void)
static void G_RestoreTimers(void) static void G_RestoreTimers(void)
{ {
timerUpdate();
totalclock = g_timers.totalclock; totalclock = g_timers.totalclock;
totalclocklock = g_timers.totalclocklock; totalclocklock = g_timers.totalclocklock;
ototalclock = g_timers.ototalclock; ototalclock = g_timers.ototalclock;