mirror of
https://github.com/ZDoom/Raze.git
synced 2024-11-15 08:51:24 +00:00
- work on the savegame writer.
It saves, reloading not implemented yet.
This commit is contained in:
parent
a4c5fbe295
commit
ce1a78fd62
11 changed files with 68 additions and 50 deletions
|
@ -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
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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 <string.h>
|
||||
#include <cstdio> // for printf
|
||||
#include <cstdlib>
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 <stdio.h>
|
||||
|
@ -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;
|
||||
|
|
|
@ -2039,6 +2039,9 @@ LABEL_28:
|
|||
|
||||
static SavegameHelper sgh("menu",
|
||||
SA(nCinemaSeen),
|
||||
SA(energytile),
|
||||
SV(nButtonColor),
|
||||
SV(word_9AB5B),
|
||||
nullptr);
|
||||
|
||||
END_PS_NS
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<SavegameHelper*> sghelpers(TArray<SavegameHelper*>::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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue