From ce1a78fd620360d668272df0af7e0cb1091ac43f Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 27 Dec 2019 10:52:40 +0100 Subject: [PATCH] - work on the savegame writer. It saves, reloading not implemented yet. --- source/common/version.h | 2 +- source/exhumed/src/bubbles.cpp | 6 +++--- source/exhumed/src/bullet.cpp | 18 +++++++++--------- source/exhumed/src/d_menu.cpp | 5 ----- source/exhumed/src/exhumed.cpp | 31 ++++++++++++++++++++++++++++--- source/exhumed/src/exhumed.h | 4 +++- source/exhumed/src/init.cpp | 25 ++++--------------------- source/exhumed/src/menu.cpp | 3 +++ source/exhumed/src/record.cpp | 4 ++-- source/exhumed/src/save.cpp | 18 ++++++++++++++---- source/exhumed/src/save.h | 2 +- 11 files changed, 68 insertions(+), 50 deletions(-) diff --git a/source/common/version.h b/source/common/version.h index a822d642b..992c09a92 100644 --- a/source/common/version.h +++ b/source/common/version.h @@ -64,7 +64,7 @@ const char *GetVersionString(); #define SAVESIG_BLD GAMENAME "Blood" #define SAVESIG_RR GAMENAME "Redneck" #define SAVESIG_SW GAMENAME "SW" -#define SAVESIG_PS GAMENAME "Powerslave" +#define SAVESIG_PS GAMENAME ".Exhumed" #define MINSAVEVER_DN3D 1 #define MINSAVEVER_BLD 1 diff --git a/source/exhumed/src/bubbles.cpp b/source/exhumed/src/bubbles.cpp index cc8c9a4fd..bc5713d01 100644 --- a/source/exhumed/src/bubbles.cpp +++ b/source/exhumed/src/bubbles.cpp @@ -60,9 +60,9 @@ machine Machine[kMaxMachines]; Bubble BubbleList[kMaxBubbles]; static SavegameHelper sgh("bubbles", - SA(BubbleCount), - SA(nFreeCount), - SA(nMachineCount), + SV(BubbleCount), + SV(nFreeCount), + SV(nMachineCount), SA(nBubblesFree), SA(Machine), SA(BubbleList), diff --git a/source/exhumed/src/bullet.cpp b/source/exhumed/src/bullet.cpp index cedc2beb2..6aabdb4eb 100644 --- a/source/exhumed/src/bullet.cpp +++ b/source/exhumed/src/bullet.cpp @@ -76,15 +76,15 @@ short nRadialBullet = 0; static SavegameHelper sgh("bullet", SV(BulletFree), - SV(BulletList), - SV(nBulletEnemy), - SA(nBulletsFree), - SA(lasthitz), - SA(lasthitx), - SA(lasthity), - SA(lasthitsect), - SA(lasthitsprite), - SA(lasthitwall), + SA(BulletList), + SA(nBulletEnemy), + SV(nBulletsFree), + SV(lasthitz), + SV(lasthitx), + SV(lasthity), + SV(lasthitsect), + SV(lasthitsprite), + SV(lasthitwall), SV(nBulletCount), SV(nRadialBullet), nullptr); diff --git a/source/exhumed/src/d_menu.cpp b/source/exhumed/src/d_menu.cpp index dee1db491..5b750a4be 100644 --- a/source/exhumed/src/d_menu.cpp +++ b/source/exhumed/src/d_menu.cpp @@ -182,11 +182,6 @@ void GameInterface::MenuClosed() } -bool GameInterface::CanSave() -{ - return MenuStartCondition == 1; -} - void GameInterface::StartGame(FGameStartup& gs) { MenuExitCondition = gs.Episode; // Gross hack. The main loop needs to be redone for better handling. diff --git a/source/exhumed/src/exhumed.cpp b/source/exhumed/src/exhumed.cpp index 75ef2dbb4..5d1c01696 100644 --- a/source/exhumed/src/exhumed.cpp +++ b/source/exhumed/src/exhumed.cpp @@ -63,6 +63,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "trigdat.h" #include "record.h" #include "lighting.h" +#include "mapinfo.h" #include #include // for printf #include @@ -1857,6 +1858,19 @@ int GameInterface::app_main() int stopTitle = kFalse; levelnew = 1; + // Create the global level table. Parts of the engine need it, even though the game itself does not. + for (int i = 0; i <= 32; i++) + { + auto mi = &mapList[i]; + mi->fileName.Format("LEV%d.MAP", i); + mi->labelName.Format("LEV%d", i); + mi->name.Format("$TXT_EX_MAP%02d", i); + + int nTrack = i; + if (nTrack != 0) nTrack--; + mi->cdSongId = (nTrack % 8) + 11; + } + // REVERT - change back to kTrue // short bDoTitle = kFalse; @@ -3391,12 +3405,12 @@ int DoSpiritHead() return 0; } -#if 0 bool GameInterface::CanSave() { return !bRecord && !bPlayback && !bPause && !bInDemo && nTotalPlayers == 1; } -#endif + + ::GameInterface* CreateInterface() { return new GameInterface; @@ -3466,13 +3480,18 @@ void SaveTextureState() auto fw = WriteSavegameChunk("texture"); int pupOffset = pPupData? int(pPupData - cPupData) : -1; - // There is really no good way to restore these two tiles, so it's probably best to save them as well, so that they can be reloaded with the saved data. + // There is really no good way to restore these tiles, so it's probably best to save them as well, so that they can be reloaded with the exact state they were left in fw->Write(&pupOffset, 4); uint8_t loaded = !!Worktile; fw->Write(&loaded, 1); if (Worktile) fw->Write(Worktile, WorktileSize); auto pixels = TileFiles.tileMakeWritable(kTile3603); fw->Write(pixels, tilesiz[kTile3603].x * tilesiz[kTile3603].y); + pixels = TileFiles.tileMakeWritable(kEnergy1); + fw->Write(pixels, tilesiz[kEnergy1].x * tilesiz[kEnergy1].y); + pixels = TileFiles.tileMakeWritable(kEnergy2); + fw->Write(pixels, tilesiz[kEnergy2].x * tilesiz[kEnergy2].y); + } void LoadTextureState() @@ -3490,8 +3509,14 @@ void LoadTextureState() } auto pixels = TileFiles.tileMakeWritable(kTile3603); fr.Read(pixels, tilesiz[kTile3603].x * tilesiz[kTile3603].y); + pixels = TileFiles.tileMakeWritable(kEnergy1); + fr.Read(pixels, tilesiz[kEnergy1].x * tilesiz[kEnergy1].y); + pixels = TileFiles.tileMakeWritable(kEnergy2); + fr.Read(pixels, tilesiz[kEnergy2].x * tilesiz[kEnergy2].y); TileFiles.InvalidateTile(kTileRamsesWorkTile); TileFiles.InvalidateTile(kTile3603); + TileFiles.InvalidateTile(kEnergy1); + TileFiles.InvalidateTile(kEnergy2); } diff --git a/source/exhumed/src/exhumed.h b/source/exhumed/src/exhumed.h index e55c12308..a6b5bdd40 100644 --- a/source/exhumed/src/exhumed.h +++ b/source/exhumed/src/exhumed.h @@ -283,10 +283,12 @@ struct GameInterface : ::GameInterface void MenuSound(EMenuSounds snd) override; void MenuClosed() override; void StartGame(FGameStartup& gs) override; - bool CanSave() override; FSavegameInfo GetSaveSig() override; void DrawCenteredTextScreen(const DVector2& origin, const char* text, int position, bool bg) override; void DrawMenuCaption(const DVector2& origin, const char* text) override; + bool LoadGame(FSaveGameNode* sv) override; + bool SaveGame(FSaveGameNode* sv) override; + bool CanSave() override; FString statFPS() override; //GameStats getStats() override; diff --git a/source/exhumed/src/init.cpp b/source/exhumed/src/init.cpp index b02131306..78ec790f7 100644 --- a/source/exhumed/src/init.cpp +++ b/source/exhumed/src/init.cpp @@ -39,6 +39,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "anims.h" #include "ps_input.h" #include "util.h" +#include "mapinfo.h" #include "gamecontrol.h" #include "rendering/v_video.h" #include @@ -81,27 +82,9 @@ uint8_t bIsVersion6 = kTrue; uint8_t LoadLevel(int nMap) { - char fileName_1[80]; - char fileName_2[32]; - initspritelists(); -// nMap = 1; - -// sprintf(fileName_2, "queen"); - sprintf(fileName_2, "lev%d", nMap); -// sprintf(fileName_2, "sentry"); -// sprintf(fileName_2, "bjd"); -// sprintf(fileName_2, "door"); -// sprintf(fileName_2, "ceil"); -// sprintf(fileName_2, "scarab"); -// sprintf(fileName_2, "guns"); -// sprintf(fileName_2, "wasp"); -// sprintf(fileName_2, "items"); - - fileName_1[0] = '\0'; - strcat(fileName_1, fileName_2); - strcat(fileName_1, ".map"); + currentLevel = &mapList[nMap]; // init stuff { @@ -162,9 +145,9 @@ uint8_t LoadLevel(int nMap) } vec3_t startPos; - int status = engineLoadBoard(fileName_1, 0, &startPos, &inita, &initsect); + int status = engineLoadBoard(currentLevel->fileName, 0, &startPos, &inita, &initsect); if (status == -2) - status = engineLoadBoardV5V6(fileName_1, 0, &startPos, &inita, &initsect); + status = engineLoadBoardV5V6(currentLevel->fileName, 0, &startPos, &inita, &initsect); initx = startPos.x; inity = startPos.y; initz = startPos.z; diff --git a/source/exhumed/src/menu.cpp b/source/exhumed/src/menu.cpp index df675a662..ebd6204a1 100644 --- a/source/exhumed/src/menu.cpp +++ b/source/exhumed/src/menu.cpp @@ -2039,6 +2039,9 @@ LABEL_28: static SavegameHelper sgh("menu", SA(nCinemaSeen), + SA(energytile), + SV(nButtonColor), + SV(word_9AB5B), nullptr); END_PS_NS diff --git a/source/exhumed/src/record.cpp b/source/exhumed/src/record.cpp index 9871a0139..2aca7a446 100644 --- a/source/exhumed/src/record.cpp +++ b/source/exhumed/src/record.cpp @@ -153,7 +153,7 @@ int CloseRecord() { if (record_mode == 1) { - loadgame(0); + //loadgame(0); ??? if (record_index) { @@ -164,7 +164,7 @@ int CloseRecord() } else if (record_mode == 2 || record_mode == 3) { - loadgame(1); + //loadgame(1); ??? } fclose(record_file); diff --git a/source/exhumed/src/save.cpp b/source/exhumed/src/save.cpp index 212bdb931..6f235fbc8 100644 --- a/source/exhumed/src/save.cpp +++ b/source/exhumed/src/save.cpp @@ -30,10 +30,17 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. BEGIN_PS_NS +void SaveTextureState(); +void LoadTextureState(); + static TArray sghelpers(TArray::NoInit); -int savegame(int nSlot) +bool GameInterface::SaveGame(FSaveGameNode* sv) { + OpenSaveGameForWrite(sv->Filename); + // workaround until the level info here has been transitioned. + G_WriteSaveHeader(sv->SaveTitle); + auto fw = WriteSavegameChunk("engine"); fw->Write(&numsectors, sizeof(numsectors)); fw->Write(sector, sizeof(sectortype) * numsectors); @@ -66,11 +73,14 @@ int savegame(int nSlot) fw->Write(show2dsector, sizeof(show2dsector)); for (auto sgh : sghelpers) sgh->Save(); + SaveTextureState(); + FinishSavegameWrite(); return 1; // CHECKME } -int loadgame(int nSlot) +bool GameInterface::LoadGame(FSaveGameNode* sv) { + OpenSaveGameForRead(sv->Filename); auto fr = ReadSavegameChunk("engine"); if (fr.isOpen()) { @@ -107,6 +117,8 @@ int loadgame(int nSlot) } for (auto sgh : sghelpers) sgh->Load(); + LoadTextureState(); + FinishSavegameRead(); // reset the sky in case it hasn't been done yet. psky_t* pSky = tileSetupSky(0); @@ -122,8 +134,6 @@ int loadgame(int nSlot) g_visibility = 2048; ototalclock = totalclock; - - return 1; // CHECKME } diff --git a/source/exhumed/src/save.h b/source/exhumed/src/save.h index 32dff75a5..d200e887f 100644 --- a/source/exhumed/src/save.h +++ b/source/exhumed/src/save.h @@ -36,7 +36,7 @@ struct SavegameHelper }; #define SV(v) &v, sizeof(v) -#define SA(a) a, sizeof(a) +#define SA(a) &a, sizeof(a) END_PS_NS