From 1729f8fa3873e97df1fc0676c3aed959438dd11f Mon Sep 17 00:00:00 2001 From: helixhorned Date: Wed, 5 Sep 2012 17:25:43 +0000 Subject: [PATCH] Factor out some repeated code into G_{Load,Save}PlayerMaybeMulti. This currently says that MP saving/loading isn't supported, but doesn't really work correctly. Also, properly bound-check the immediate argument to CON's 'save' command and one more ... -> G_HandleAsync(). git-svn-id: https://svn.eduke32.com/eduke32@2999 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/demo.c | 3 +-- polymer/eduke32/source/game.c | 27 +++---------------------- polymer/eduke32/source/gameexec.c | 11 ++++------- polymer/eduke32/source/menus.c | 31 ++++------------------------- polymer/eduke32/source/savegame.c | 33 +++++++++++++++++++++++++++++++ polymer/eduke32/source/savegame.h | 2 ++ 6 files changed, 47 insertions(+), 60 deletions(-) diff --git a/polymer/eduke32/source/demo.c b/polymer/eduke32/source/demo.c index b27fb4d5d..210911fc9 100644 --- a/polymer/eduke32/source/demo.c +++ b/polymer/eduke32/source/demo.c @@ -738,8 +738,7 @@ nextdemo: rotatesprite_fs((320-50)<<16,9<<16,65536L,0,BETAVERSION,0,0,2+8+16+128); } - handleevents(); - Net_GetPackets(); + G_HandleAsync(); if (!ud.recstat) nextpage(); diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index bf2d76719..a5aca6b05 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -7936,16 +7936,8 @@ FAKE_F3: /* inputloc = Bstrlen(&ud.savegame[g_lastSaveSlot][0]); g_currentMenu = 360+g_lastSaveSlot; probey = g_lastSaveSlot; */ - if (g_netServer || ud.multimode > 1) - { - Bstrcpy(ScriptQuotes[QUOTE_RESERVED4], "Multiplayer Saving Not Yet Supported"); - P_DoQuote(QUOTE_RESERVED4, g_player[myconnectindex].ps); - //G_SavePlayer(-1-(g_lastSaveSlot)); - } - else - { - G_SavePlayer(g_lastSaveSlot); - } + + G_SavePlayerMaybeMulti(g_lastSaveSlot); } } @@ -8003,20 +7995,7 @@ FAKE_F3: KB_ClearKeysDown(); FX_StopAllSounds(); - if (g_netServer || ud.multimode > 1) - { - Bstrcpy(ScriptQuotes[QUOTE_RESERVED4], "Multiplayer Loading Not Yet Supported"); - P_DoQuote(QUOTE_RESERVED4, g_player[myconnectindex].ps); - -// G_LoadPlayer(-1-g_lastSaveSlot); -// g_player[myconnectindex].ps->gm = MODE_GAME; - } - else - { - i = G_LoadPlayer(g_lastSaveSlot); - if (i == 0) - g_player[myconnectindex].ps->gm = MODE_GAME; - } + G_LoadPlayerMaybeMulti(g_lastSaveSlot); } } diff --git a/polymer/eduke32/source/gameexec.c b/polymer/eduke32/source/gameexec.c index 2dbb36308..dab76f315 100644 --- a/polymer/eduke32/source/gameexec.c +++ b/polymer/eduke32/source/gameexec.c @@ -3032,16 +3032,14 @@ nullquote: case CON_SAVE: insptr++; { - time_t curtime; - g_lastSaveSlot = *insptr++; - if (g_lastSaveSlot > 9) + if ((unsigned)g_lastSaveSlot >= 10) continue; if (tw == CON_SAVE || ud.savegame[g_lastSaveSlot][0] == 0) { - curtime = time(NULL); + time_t curtime = time(NULL); Bstrcpy(tempbuf,asctime(localtime(&curtime))); clearbufbyte(ud.savegame[g_lastSaveSlot],sizeof(ud.savegame[g_lastSaveSlot]),0); Bsprintf(ud.savegame[g_lastSaveSlot],"Auto"); @@ -3059,9 +3057,8 @@ nullquote: g_screenCapture = 1; G_DrawRooms(myconnectindex,65536); g_screenCapture = 0; - if ((g_netServer || ud.multimode > 1)) - G_SavePlayer(-1-(g_lastSaveSlot)); - else G_SavePlayer(g_lastSaveSlot); + + G_SavePlayerMaybeMulti(g_lastSaveSlot); continue; } diff --git a/polymer/eduke32/source/menus.c b/polymer/eduke32/source/menus.c index 188e02c64..84836a1fd 100644 --- a/polymer/eduke32/source/menus.c +++ b/polymer/eduke32/source/menus.c @@ -1453,20 +1453,7 @@ void M_DisplayMenus(void) KB_ClearKeysDown(); FX_StopAllSounds(); - if (g_netServer || ud.multimode > 1) - { - Bstrcpy(ScriptQuotes[QUOTE_RESERVED4], "Multiplayer Loading Not Yet Supported"); - P_DoQuote(QUOTE_RESERVED4, g_player[myconnectindex].ps); - -// G_LoadPlayer(-1-g_lastSaveSlot); -// g_player[myconnectindex].ps->gm = MODE_GAME; - } - else - { - c = G_LoadPlayer(g_lastSaveSlot); - if (c == 0) - g_player[myconnectindex].ps->gm = MODE_GAME; - } + G_LoadPlayerMaybeMulti(g_lastSaveSlot); } break; @@ -1622,9 +1609,7 @@ void M_DisplayMenus(void) totalclock = ototalclock; } - c = G_LoadPlayer(g_lastSaveSlot); - if (c == 0) - g_player[myconnectindex].ps->gm = MODE_GAME; + G_LoadPlayerMaybeMulti(g_lastSaveSlot); break; } @@ -4853,16 +4838,8 @@ cheat_for_port_credits: ud.savegame[g_currentMenu-360][20] = 127; } - if (g_netServer || ud.multimode > 1) - { - Bstrcpy(ScriptQuotes[QUOTE_RESERVED4], "Multiplayer Saving Not Yet Supported"); - P_DoQuote(QUOTE_RESERVED4, g_player[myconnectindex].ps); - //G_SavePlayer(-1-(g_currentMenu-360)); - } - else - { - G_SavePlayer(g_currentMenu-360); - } + G_SavePlayerMaybeMulti(g_currentMenu-360); + g_lastSaveSlot = g_currentMenu-360; g_player[myconnectindex].ps->gm = MODE_GAME; diff --git a/polymer/eduke32/source/savegame.c b/polymer/eduke32/source/savegame.c index cfca9e446..4d622a3b4 100644 --- a/polymer/eduke32/source/savegame.c +++ b/polymer/eduke32/source/savegame.c @@ -361,6 +361,39 @@ int32_t G_SavePlayer(int32_t spot) return 0; } +void G_LoadPlayerMaybeMulti(int32_t slot) +{ + if (g_netServer || ud.multimode > 1) + { + Bstrcpy(ScriptQuotes[QUOTE_RESERVED4], "Multiplayer Loading Not Yet Supported"); + P_DoQuote(QUOTE_RESERVED4, g_player[myconnectindex].ps); + +// G_LoadPlayer(-1-g_lastSaveSlot); +// g_player[myconnectindex].ps->gm = MODE_GAME; + } + else + { + int32_t c = G_LoadPlayer(slot); + if (c == 0) + g_player[myconnectindex].ps->gm = MODE_GAME; + } +} + +void G_SavePlayerMaybeMulti(int32_t slot) +{ + Bassert(slot >= 0); + + if (g_netServer || ud.multimode > 1) + { + Bstrcpy(ScriptQuotes[QUOTE_RESERVED4], "Multiplayer Saving Not Yet Supported"); + P_DoQuote(QUOTE_RESERVED4, g_player[myconnectindex].ps); +// G_SavePlayer(-1-slot); + } + else + { + G_SavePlayer(slot); + } +} ////////// GENERIC SAVING/LOADING SYSTEM ////////// diff --git a/polymer/eduke32/source/savegame.h b/polymer/eduke32/source/savegame.h index 208ef5fe3..f8b194956 100644 --- a/polymer/eduke32/source/savegame.h +++ b/polymer/eduke32/source/savegame.h @@ -60,6 +60,8 @@ int32_t G_LoadPlayer(int32_t spot); int32_t G_LoadSaveHeaderNew(int32_t spot, savehead_t *saveh); //int32_t G_LoadSaveHeader(char spot,struct savehead_ *saveh); void ReadSaveGameHeaders(void); +void G_SavePlayerMaybeMulti(int32_t slot); +void G_LoadPlayerMaybeMulti(int32_t slot); #ifdef YAX_ENABLE extern void sv_postyaxload(void);