- little bit of code cleanup

dead code removal and splitting app_main in two to separate its init part from the game loop
This commit is contained in:
Christoph Oelckers 2019-11-06 14:12:50 +01:00
parent 88bf056176
commit cf6b4c64b1
3 changed files with 19 additions and 92 deletions

View file

@ -290,7 +290,7 @@ void G_GameExit(const char *msg)
{ {
if (!(msg[0] == ' ' && msg[1] == 0)) if (!(msg[0] == ' ' && msg[1] == 0))
{ {
I_Error(msg); I_Error("%s", msg);
} }
} }
@ -6121,6 +6121,8 @@ void G_MaybeAllocPlayer(int32_t pnum)
EDUKE32_STATIC_ASSERT(sizeof(actor_t)%4 == 0); EDUKE32_STATIC_ASSERT(sizeof(actor_t)%4 == 0);
EDUKE32_STATIC_ASSERT(sizeof(DukePlayer_t)%4 == 0); EDUKE32_STATIC_ASSERT(sizeof(DukePlayer_t)%4 == 0);
void app_loop();
int GameInterface::app_main() int GameInterface::app_main()
{ {
g_skillCnt = 4; g_skillCnt = 4;
@ -6143,7 +6145,7 @@ int GameInterface::app_main()
g_logFlushWindow = 0; g_logFlushWindow = 0;
#ifndef EDUKE32_STANDALONE
G_SetupCheats(); G_SetupCheats();
if (SHAREWARE) if (SHAREWARE)
@ -6155,7 +6157,6 @@ int GameInterface::app_main()
g_Shareware = 1; g_Shareware = 1;
} }
} }
#endif
// gotta set the proper title after we compile the CONs if this is the full version // gotta set the proper title after we compile the CONs if this is the full version
@ -6340,30 +6341,19 @@ int GameInterface::app_main()
ReadSaveGameHeaders(); ReadSaveGameHeaders();
#if 0
// previously, passing -0 through -9 on the command line would load the save in that slot #
// this code should be reusable for a new parameter that takes a filename, if desired
if (/* havesavename */ && (!g_netServer && ud.multimode < 2))
{
clearview(0L);
//psmy.palette = palette;
//G_FadePalette(0,0,0,0);
P_SetGamePalette(g_player[myconnectindex].ps, BASEPAL, 0); // JBF 20040308
rotatesprite_fs(160<<16,100<<16,65536L,0,LOADSCREEN,0,0,2+8+64+BGSTRETCH);
menutext_center(105,"Loading saved game...");
nextpage();
if (G_LoadPlayer(/* savefile */))
/* havesavename = false; */
}
#endif
FX_StopAllSounds(); FX_StopAllSounds();
S_ClearSoundLocks(); S_ClearSoundLocks();
// getpackets(); // getpackets();
VM_OnEvent(EVENT_INITCOMPLETE); VM_OnEvent(EVENT_INITCOMPLETE);
app_loop();
}
void app_loop()
{
auto &myplayer = *g_player[myconnectindex].ps;
MAIN_LOOP_RESTART: MAIN_LOOP_RESTART:
totalclock = 0; totalclock = 0;
@ -6501,13 +6491,6 @@ MAIN_LOOP_RESTART:
{ {
G_MoveLoop(); G_MoveLoop();
S_Update(); S_Update();
#ifdef __ANDROID__
inputfifo[0][myconnectindex].fvel = 0;
inputfifo[0][myconnectindex].svel = 0;
inputfifo[0][myconnectindex].avel = 0;
inputfifo[0][myconnectindex].horz = 0;
#endif
} }
if (totalclock - moveClock >= (TICSPERFRAME>>1)) if (totalclock - moveClock >= (TICSPERFRAME>>1))
@ -6581,8 +6564,6 @@ MAIN_LOOP_RESTART:
goto MAIN_LOOP_RESTART; goto MAIN_LOOP_RESTART;
} }
while (1); while (1);
return 0; // not reached (duh)
} }
GAME_STATIC GAME_INLINE int32_t G_MoveLoop() GAME_STATIC GAME_INLINE int32_t G_MoveLoop()

View file

@ -7522,7 +7522,7 @@ void G_MaybeAllocPlayer(int32_t pnum)
g_player[pnum].inputBits = (input_t *)Xcalloc(1, sizeof(input_t)); g_player[pnum].inputBits = (input_t *)Xcalloc(1, sizeof(input_t));
} }
void app_loop();
// TODO: reorder (net)actor_t to eliminate slop and update assertion // TODO: reorder (net)actor_t to eliminate slop and update assertion
EDUKE32_STATIC_ASSERT(sizeof(actor_t)%4 == 0); EDUKE32_STATIC_ASSERT(sizeof(actor_t)%4 == 0);
@ -7753,28 +7753,14 @@ int GameInterface::app_main()
ReadSaveGameHeaders(); ReadSaveGameHeaders();
#if 0
// previously, passing -0 through -9 on the command line would load the save in that slot #
// this code should be reusable for a new parameter that takes a filename, if desired
if (/* havesavename */ && (!g_netServer && ud.multimode < 2))
{
clearview(0L);
//g_player[myconnectindex].ps->palette = palette;
//G_FadePalette(0,0,0,0);
P_SetGamePalette(g_player[myconnectindex].ps, BASEPAL, 0); // JBF 20040308
rotatesprite_fs(160<<16,100<<16,65536L,0,LOADSCREEN,0,0,2+8+64+BGSTRETCH);
menutext_center(105,"Loading saved game...");
nextpage();
if (G_LoadPlayer(/* savefile */))
/* havesavename = false; */
}
#endif
FX_StopAllSounds(); FX_StopAllSounds();
S_ClearSoundLocks(); S_ClearSoundLocks();
app_loop();
// getpackets(); }
void app_loop()
{
auto &myplayer = g_player[myconnectindex].ps;
MAIN_LOOP_RESTART: MAIN_LOOP_RESTART:
totalclock = 0; totalclock = 0;
@ -7913,12 +7899,6 @@ MAIN_LOOP_RESTART:
(g_player[myconnectindex].ps->gm&MODE_GAME)) (g_player[myconnectindex].ps->gm&MODE_GAME))
{ {
G_MoveLoop(); G_MoveLoop();
#ifdef __ANDROID__
inputfifo[0][myconnectindex].fvel = 0;
inputfifo[0][myconnectindex].svel = 0;
inputfifo[0][myconnectindex].avel = 0;
inputfifo[0][myconnectindex].horz = 0;
#endif
} }
timerUpdate(); timerUpdate();

View file

@ -1816,29 +1816,6 @@ void Net_GetInput(void)
avgfvel = avgsvel = avgavel = avghorz = avgbits = avgextbits = 0; avgfvel = avgsvel = avgavel = avghorz = avgbits = avgextbits = 0;
g_player[myconnectindex].movefifoend++; g_player[myconnectindex].movefifoend++;
#if 0
if (numplayers < 2)
{
if (ud.multimode > 1)
{
for (int TRAVERSE_CONNECT(i))
{
if (i != myconnectindex)
{
//clearbufbyte(&inputfifo[g_player[i].movefifoend&(MOVEFIFOSIZ-1)][i],sizeof(input_t),0L);
if (ud.playerai)
{
computergetinput(i, &inputfifo[g_player[i].movefifoend&(MOVEFIFOSIZ - 1)][i]);
inputfifo[g_player[i].movefifoend&(MOVEFIFOSIZ - 1)][i].svel++;
inputfifo[g_player[i].movefifoend&(MOVEFIFOSIZ - 1)][i].fvel++;
}
g_player[i].movefifoend++;
}
}
}
return;
}
#endif
for (int TRAVERSE_CONNECT(i)) for (int TRAVERSE_CONNECT(i))
if (i != myconnectindex) if (i != myconnectindex)
@ -1847,24 +1824,13 @@ void Net_GetInput(void)
g_player[i].myminlag = min(g_player[i].myminlag,k); g_player[i].myminlag = min(g_player[i].myminlag,k);
mymaxlag = max(mymaxlag,k); mymaxlag = max(mymaxlag,k);
} }
#if 0
if (((g_player[myconnectindex].movefifoend - 1) & (TIMERUPDATESIZ - 1)) == 0)
{
i = mymaxlag - bufferjitter;
mymaxlag = 0;
if (i > 0)
bufferjitter += ((2 + i) >> 2);
else if (i < 0)
bufferjitter -= ((2 - i) >> 2);
}
#else
if (((g_player[myconnectindex].movefifoend-1)&(TIMERUPDATESIZ-1)) == 0) if (((g_player[myconnectindex].movefifoend-1)&(TIMERUPDATESIZ-1)) == 0)
{ {
int i = mymaxlag-bufferjitter; mymaxlag = 0; int i = mymaxlag-bufferjitter; mymaxlag = 0;
if (i > 0) bufferjitter += ((3+i)>>2); if (i > 0) bufferjitter += ((3+i)>>2);
else if (i < 0) bufferjitter -= ((1-i)>>2); else if (i < 0) bufferjitter -= ((1-i)>>2);
} }
#endif
if (g_networkBroadcastMode == 1) if (g_networkBroadcastMode == 1)
{ {