- savegame and mapinfo cleanup in DN3D and RR frontends.

Also added an "end game" flag to the mapinfo. For those who like to assemble single levels into custom episodes. More features for that to come. ;)
This commit is contained in:
Christoph Oelckers 2019-12-10 22:22:59 +01:00
parent 4cc22e155f
commit 0e19d4262e
18 changed files with 142 additions and 139 deletions

View file

@ -48,6 +48,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "view.h" #include "view.h"
#include "savegamehelp.h" #include "savegamehelp.h"
#include "z_music.h" #include "z_music.h"
#include "mapinfo.h"
BEGIN_BLD_NS BEGIN_BLD_NS
@ -209,7 +210,13 @@ bool GameInterface::SaveGame(FSaveGameNode* node)
return false; return false;
} }
auto & li = gEpisodeInfo[gGameOptions.nEpisode].at28[gGameOptions.nLevel]; auto & li = gEpisodeInfo[gGameOptions.nEpisode].at28[gGameOptions.nLevel];
G_WriteSaveHeader(node->SaveTitle, FStringf("%s.map", li.at0), li.at90); // workaround until the level info here has been transitioned.
MapRecord mr;
mr.name = li.at90;
mr.labelName = li.at0;
mr.fileName.Format("%s.map", li.at0);
currentLevel = &mr;
G_WriteSaveHeader(node->SaveTitle);
LoadSave::hSFile = NULL; LoadSave::hSFile = NULL;
return FinishSavegameWrite(); return FinishSavegameWrite();

View file

@ -31,8 +31,10 @@
#include "enet.h" #include "enet.h"
#endif #endif
MapRecord mapList[512]; // Due to how this gets used it needs to be static. EDuke defines 7 episode plus one spare episode with 64 potential levels each and relies on the static array which is freely accessible by scripts. MapRecord mapList[512]; // Due to how this gets used it needs to be static. EDuke defines 7 episode plus one spare episode with 64 potential levels each and relies on the static array which is freely accessible by scripts.
MapRecord *currentLevel; MapRecord *currentLevel; // level that is currently played. (The real level, not what script hacks modfifying the current level index can pretend.)
MapRecord* lastLevel; // Same here, for the last level.
MapRecord userMapRecord; // stand-in for the user map.
void C_CON_SetAliases(); void C_CON_SetAliases();
InputState inputState; InputState inputState;
@ -428,6 +430,7 @@ int CONFIG_Init()
InitStatistics(); InitStatistics();
M_Init(); M_Init();
SetDefaultStrings(); SetDefaultStrings();
if (g_gameType & GAMEFLAG_RR) InitRREndMap(); // this needs to be done better later
return gi->app_main(); return gi->app_main();
} }

View file

@ -11,6 +11,11 @@ inline void MakeStringLocalizable(FString &quote)
if (quote.Len() > 0 && quote[0] != '$' && GStrings[quote]) quote.Insert(0, "$"); if (quote.Len() > 0 && quote[0] != '$' && GStrings[quote]) quote.Insert(0, "$");
} }
enum
{
MI_FORCEEOG = 1,
};
struct MapRecord struct MapRecord
{ {
int parTime; int parTime;
@ -27,6 +32,7 @@ struct MapRecord
int messageStart; // messages are stored in the quote array to reduce clutter. int messageStart; // messages are stored in the quote array to reduce clutter.
FString author; FString author;
// bool fog, weather; // Blood defines these but they aren't used. // bool fog, weather; // Blood defines these but they aren't used.
int flags;
const char *DisplayName() const char *DisplayName()
{ {
@ -47,4 +53,19 @@ struct MapRecord
}; };
extern MapRecord mapList[512]; extern MapRecord mapList[512];
extern MapRecord *currentLevel; extern MapRecord userMapRecord;
extern MapRecord *currentLevel;
extern MapRecord* lastLevel;
inline void InitRREndMap()
{
// RR defines its end map ad-hoc so give it a proper entry to reference (the last one in episode 2 because it needs to be in Ep. 2.)
mapList[127].SetName("$TXT_CLOSEENCOUNTERS");
mapList[127].SetFileName("endmap.map");
}
enum
{
RRENDSLOT = 127
};

View file

@ -492,6 +492,7 @@ bool M_SetMenu(FName menu, int param, FName caller)
M_StartMessage (GStrings("SAVEDEAD"), 1, -1); M_StartMessage (GStrings("SAVEDEAD"), 1, -1);
return true; return true;
} }
break;
case NAME_QuitMenu: case NAME_QuitMenu:
// This is no separate class // This is no separate class

View file

@ -198,7 +198,7 @@ void FSavegameManager::ReadSaveStrings()
} }
auto fr = info->NewReader(); auto fr = info->NewReader();
FString title; FString title;
int check = G_ValidateSavegame(fr, &title); int check = G_ValidateSavegame(fr, &title, true);
fr.Close(); fr.Close();
delete savegame; delete savegame;
if (check != 0) if (check != 0)
@ -377,7 +377,7 @@ unsigned FSavegameManager::ExtractSaveData(int index)
FString comment = sjson_get_string(root, "Creation Time", ""); FString comment = sjson_get_string(root, "Creation Time", "");
FString fcomment = sjson_get_string(root, "Map File", ""); FString fcomment = sjson_get_string(root, "Map Label", "");
FString ncomment = sjson_get_string(root, "Map Name", ""); FString ncomment = sjson_get_string(root, "Map Name", "");
FStringf pcomment("%s - %s\n", fcomment.GetChars(), ncomment.GetChars()); FStringf pcomment("%s - %s\n", fcomment.GetChars(), ncomment.GetChars());
comment += pcomment; comment += pcomment;

View file

@ -45,6 +45,7 @@
#include "secrets.h" #include "secrets.h"
#include "s_music.h" #include "s_music.h"
#include "quotemgr.h" #include "quotemgr.h"
#include "mapinfo.h"
static CompositeSavegameWriter savewriter; static CompositeSavegameWriter savewriter;
static FResourceFile *savereader; static FResourceFile *savereader;
@ -81,8 +82,21 @@ bool OpenSaveGameForRead(const char *name)
SECRET_Load(); SECRET_Load();
MUS_Restore(); MUS_Restore();
quoteMgr.ReadFromSavegame(); quoteMgr.ReadFromSavegame();
}
auto file = ReadSavegameChunk("info.json");
if (!file.isOpen())
{
FinishSavegameRead();
delete savereader;
return false;
}
if (G_ValidateSavegame(file, nullptr, false) <= 0)
{
FinishSavegameRead();
delete savereader;
return false;
}
}
return savereader != nullptr; return savereader != nullptr;
} }
@ -116,7 +130,7 @@ void FinishSavegameRead()
// //
//============================================================================= //=============================================================================
void G_WriteSaveHeader(const char *name, const char*mapname, const char *maptitle) void G_WriteSaveHeader(const char *name)
{ {
sjson_context* ctx = sjson_create_context(0, 0, NULL); sjson_context* ctx = sjson_create_context(0, 0, NULL);
if (!ctx) if (!ctx)
@ -128,16 +142,20 @@ void G_WriteSaveHeader(const char *name, const char*mapname, const char *maptitl
sjson_put_int(ctx, root, "Save Version", savesig.currentsavever); sjson_put_int(ctx, root, "Save Version", savesig.currentsavever);
sjson_put_string(ctx, root, "Engine", savesig.savesig); sjson_put_string(ctx, root, "Engine", savesig.savesig);
sjson_put_string(ctx, root, "Game Resource", fileSystem.GetResourceFileName(1)); sjson_put_string(ctx, root, "Game Resource", fileSystem.GetResourceFileName(1));
sjson_put_string(ctx, root, "Map Name", maptitle); sjson_put_string(ctx, root, "Map Name", currentLevel->DisplayName());
sjson_put_string(ctx, root, "Title", name); sjson_put_string(ctx, root, "Title", name);
if (*mapname == '/') mapname++; sjson_put_string(ctx, root, "Map File", currentLevel->fileName);
sjson_put_string(ctx, root, "Map File", mapname); sjson_put_string(ctx, root, "Map Label", currentLevel->labelName);
auto fileno = fileSystem.FindFile(mapname); const char *fn = currentLevel->fileName;
auto mapfile = fileSystem.GetFileContainer(fileno); if (*fn == '/') fn++;
auto mapcname = fileSystem.GetResourceFileName(mapfile); if (!strncmp(fn, "file://", 7) != 0) // this only has meaning for non-usermaps
if (mapcname) sjson_put_string(ctx, root, "Map Resource", mapcname); {
else return; // this should never happen. Saving on a map that isn't present is impossible. auto fileno = fileSystem.FindFile(fn);
auto mapfile = fileSystem.GetFileContainer(fileno);
auto mapcname = fileSystem.GetResourceFileName(mapfile);
if (mapcname) sjson_put_string(ctx, root, "Map Resource", mapcname);
else return; // this should never happen. Saving on a map that isn't present is impossible.
}
char* encoded = sjson_stringify(ctx, root, " "); char* encoded = sjson_stringify(ctx, root, " ");
@ -172,6 +190,10 @@ static bool CheckSingleFile (const char *name, bool &printRequires, bool printwa
{ {
return true; return true;
} }
if (!strncmp(name, "file://", 7) == 0)
{
return FileExists(name + 7); // User maps must be present to be validated.
}
if (fileSystem.CheckIfResourceFileLoaded(name) < 0) if (fileSystem.CheckIfResourceFileLoaded(name) < 0)
{ {
if (printwarn) if (printwarn)
@ -222,7 +244,7 @@ static bool G_CheckSaveGameWads (const char *gamegrp, const char *mapgrp, bool p
// //
//============================================================================= //=============================================================================
int G_ValidateSavegame(FileReader &fr, FString *savetitle) int G_ValidateSavegame(FileReader &fr, FString *savetitle, bool formenu)
{ {
auto data = fr.ReadPadded(1); auto data = fr.ReadPadded(1);
@ -237,6 +259,7 @@ int G_ValidateSavegame(FileReader &fr, FString *savetitle)
FString gamegrp = sjson_get_string(root, "Game Resource", ""); FString gamegrp = sjson_get_string(root, "Game Resource", "");
FString mapgrp = sjson_get_string(root, "Map Resource", ""); FString mapgrp = sjson_get_string(root, "Map Resource", "");
FString title = sjson_get_string(root, "Title", ""); FString title = sjson_get_string(root, "Title", "");
FString filename = sjson_get_string(root, "Map File", "");
auto savesig = gi->GetSaveSig(); auto savesig = gi->GetSaveSig();
sjson_destroy_context(ctx); sjson_destroy_context(ctx);
@ -248,6 +271,30 @@ int G_ValidateSavegame(FileReader &fr, FString *savetitle)
// not our business. Leave it alone. // not our business. Leave it alone.
return 0; return 0;
} }
MapRecord *curLevel = nullptr;
if (!strncmp(filename, "file://", 7) != 0)
{
for (auto& mr : mapList)
{
if (mr.fileName.Compare(filename) == 0)
{
curLevel = &mr;
}
}
}
else
{
curLevel = &userMapRecord;
if (!formenu)
{
userMapRecord.name = "";
userMapRecord.SetFileName(filename);
}
}
if (!curLevel) return 0;
if (!formenu) currentLevel = curLevel;
if (savever < savesig.minsavever) if (savever < savesig.minsavever)

View file

@ -15,8 +15,8 @@ void FinishSavegameRead();
class FileReader; class FileReader;
FString G_BuildSaveName (const char *prefix); FString G_BuildSaveName (const char *prefix);
int G_ValidateSavegame(FileReader &fr, FString *savetitle); int G_ValidateSavegame(FileReader &fr, FString *savetitle, bool formenu);
void G_WriteSaveHeader(const char *name, const char*mapname, const char *title); void G_WriteSaveHeader(const char* name);
#define SAVEGAME_EXT ".dsave" #define SAVEGAME_EXT ".dsave"

View file

@ -5764,7 +5764,8 @@ static int G_EndOfLevel(void)
{ {
auto &p = *g_player[myconnectindex].ps; auto &p = *g_player[myconnectindex].ps;
STAT_Update(ud.eog); if ((currentLevel->flags & MI_FORCEEOG)) ud.eog = 1; // if the finished level says to end the game, end it!
STAT_Update(ud.eog);
P_SetGamePalette(&p, BASEPAL, 0); P_SetGamePalette(&p, BASEPAL, 0);
P_UpdateScreenPal(&p); P_UpdateScreenPal(&p);
@ -5789,7 +5790,7 @@ static int G_EndOfLevel(void)
// Clear potentially loaded per-map ART only after the bonus screens. // Clear potentially loaded per-map ART only after the bonus screens.
artClearMapArt(); artClearMapArt();
if (ud.eog || G_HaveUserMap()) if (ud.eog || G_HaveUserMap() || (currentLevel->flags & MI_FORCEEOG))
{ {
ud.eog = 0; ud.eog = 0;
if ((!g_netServer && ud.multimode < 2)) if ((!g_netServer && ud.multimode < 2))
@ -5799,8 +5800,6 @@ static int G_EndOfLevel(void)
G_DoOrderScreen(); G_DoOrderScreen();
#endif #endif
p.gm = 0; p.gm = 0;
M_StartControlPanel(false);
M_SetMenu(NAME_MainMenu);
return 2; return 2;
} }
else else

View file

@ -68,7 +68,6 @@ G_EXTERN actor_t actor[MAXSPRITES];
G_EXTERN tiledata_t g_tile[MAXTILES]; G_EXTERN tiledata_t g_tile[MAXTILES];
G_EXTERN animwalltype animwall[MAXANIMWALLS]; G_EXTERN animwalltype animwall[MAXANIMWALLS];
G_EXTERN char *label; G_EXTERN char *label;
G_EXTERN int32_t g_musicIndex;
G_EXTERN char g_loadFromGroupOnly; G_EXTERN char g_loadFromGroupOnly;
G_EXTERN char g_skillCnt; G_EXTERN char g_skillCnt;
G_EXTERN char pus,pub; G_EXTERN char pus,pub;

View file

@ -1720,7 +1720,7 @@ void G_SetupFilenameBasedMusic(char *nameBuf, const char *fileName)
if (FileExists(nameBuf)) if (FileExists(nameBuf))
{ {
mapList[USERMAPMUSICFAKESLOT].music = nameBuf; userMapRecord.music = nameBuf;
return; return;
} }
} }
@ -1728,7 +1728,7 @@ void G_SetupFilenameBasedMusic(char *nameBuf, const char *fileName)
auto &usermapMusic = mapList[MUS_USERMAP].music; auto &usermapMusic = mapList[MUS_USERMAP].music;
if (usermapMusic.IsNotEmpty()) if (usermapMusic.IsNotEmpty())
{ {
mapList[USERMAPMUSICFAKESLOT].music = usermapMusic; userMapRecord.music = usermapMusic;
return; return;
} }
@ -1738,7 +1738,7 @@ void G_SetupFilenameBasedMusic(char *nameBuf, const char *fileName)
auto &e1l8 = mapList[7].music; auto &e1l8 = mapList[7].music;
if (e1l8.IsNotEmpty()) if (e1l8.IsNotEmpty())
{ {
mapList[USERMAPMUSICFAKESLOT].music = e1l8; userMapRecord.music = e1l8;
return; return;
} }
} }
@ -1849,7 +1849,10 @@ int G_EnterLevel(int gameMode)
OSD_Printf(OSD_ERROR "Map \"%s\" not found or invalid map version!\n", boardfilename); OSD_Printf(OSD_ERROR "Map \"%s\" not found or invalid map version!\n", boardfilename);
return 1; return 1;
} }
STAT_NewLevel(boardfilename); userMapRecord.name = "";
userMapRecord.SetFileName(boardfilename);
currentLevel = &userMapRecord;
STAT_NewLevel(boardfilename);
G_LoadMapHack(levelName, boardfilename); G_LoadMapHack(levelName, boardfilename);
G_SetupFilenameBasedMusic(levelName, boardfilename); G_SetupFilenameBasedMusic(levelName, boardfilename);
} }
@ -1860,6 +1863,7 @@ int G_EnterLevel(int gameMode)
} }
else else
{ {
currentLevel = &mm;
STAT_NewLevel(mm.fileName); STAT_NewLevel(mm.fileName);
G_LoadMapHack(levelName, mm.fileName); G_LoadMapHack(levelName, mm.fileName);
} }
@ -1894,15 +1898,7 @@ int G_EnterLevel(int gameMode)
{ {
S_PlayLevelMusicOrNothing(USERMAPMUSICFAKESLOT); S_PlayLevelMusicOrNothing(USERMAPMUSICFAKESLOT);
} }
else if (mapList[g_musicIndex].music.IsEmpty() || mm.music.IsEmpty() || mapList[g_musicIndex].music.CompareNoCase(mm.music) == 0 || else S_PlayLevelMusicOrNothing(mapidx);
g_musicSize == 0 || ud.last_level == -1)
{
S_PlayLevelMusicOrNothing(mapidx);
}
else
{
S_ContinueLevelMusic();
}
} }
M_ClearMenus(); M_ClearMenus();

View file

@ -151,18 +151,7 @@ static FileReader *OpenSavegame(const char *fn)
{ {
return nullptr; return nullptr;
} }
auto file = ReadSavegameChunk("info.json"); auto file = ReadSavegameChunk("snapshot.dat");
if (!file.isOpen())
{
FinishSavegameRead();
return nullptr;
}
if (G_ValidateSavegame(file, nullptr) <= 0)
{
FinishSavegameRead();
return nullptr;
}
file = ReadSavegameChunk("snapshot.dat");
if (!file.isOpen()) if (!file.isOpen())
{ {
FinishSavegameRead(); FinishSavegameRead();
@ -182,24 +171,6 @@ int32_t G_LoadSaveHeaderNew(char const *fn, savehead_t *saveh)
if (i < 0) if (i < 0)
goto corrupt; goto corrupt;
ssfil = ReadSavegameChunk("screenshot.dat");
TileFiles.tileCreate(TILE_LOADSHOT, 200, 320);
if (ssfil.isOpen())
{
if (ssfil.Read(tileData(TILE_LOADSHOT), 320 * 200) != 320 * 200)
{
OSD_Printf("G_LoadSaveHeaderNew(): failed reading screenshot in \"%s\"\n", fn);
goto corrupt;
}
}
else
{
Bmemset(tileData(TILE_LOADSHOT), 0, 320*200);
}
ssfil.Close();
tileInvalidate(TILE_LOADSHOT, 0, 255);
delete fil; delete fil;
FinishSavegameRead(); FinishSavegameRead();
return 0; return 0;
@ -1468,8 +1439,7 @@ int32_t sv_saveandmakesnapshot(FileWriter &fil, char const *name, int8_t spot, i
auto fw = WriteSavegameChunk("header.dat"); auto fw = WriteSavegameChunk("header.dat");
fw->Write(&h, sizeof(savehead_t)); fw->Write(&h, sizeof(savehead_t));
auto& mii = mapList[(MAXLEVELS * ud.volume_number) + ud.level_number]; G_WriteSaveHeader(name);
G_WriteSaveHeader(name, mii.fileName, mii.DisplayName());
} }
else else
{ {
@ -1487,13 +1457,14 @@ int32_t sv_saveandmakesnapshot(FileWriter &fil, char const *name, int8_t spot, i
// write header // write header
#if 0 // not usable anymore
if (spot >= 0 && tileData(TILE_SAVESHOT)) if (spot >= 0 && tileData(TILE_SAVESHOT))
{ {
auto fw = WriteSavegameChunk("screenshot.dat"); auto fw = WriteSavegameChunk("screenshot.dat");
fw->Write(tileData(TILE_SAVESHOT), 320*200); fw->Write(tileData(TILE_SAVESHOT), 320*200);
} }
#endif
if (spot >= 0) if (spot >= 0)

View file

@ -134,7 +134,6 @@ void S_MenuSound(void)
static void S_SetMusicIndex(unsigned int m) static void S_SetMusicIndex(unsigned int m)
{ {
g_musicIndex = m;
ud.music_episode = m / MAXLEVELS; ud.music_episode = m / MAXLEVELS;
ud.music_level = m % MAXLEVELS; ud.music_level = m % MAXLEVELS;
} }
@ -148,7 +147,9 @@ void S_PlayLevelMusicOrNothing(unsigned int m)
if (retval >= 0) if (retval >= 0)
{ {
Mus_Play(mapList[m].fileName, mapList[m].music, true); // Thanks to scripting that stupid slot hijack cannot be refactored - but we'll store the real data elsewhere anyway!
auto &mr = m == USERMAPMUSICFAKESLOT ? userMapRecord : mapList[m];
Mus_Play(mr.fileName, mr.music, true);
S_SetMusicIndex(m); S_SetMusicIndex(m);
} }
} }

View file

@ -7196,7 +7196,7 @@ void G_BackToMenu(void)
static int G_EndOfLevel(void) static int G_EndOfLevel(void)
{ {
STAT_Update(ud.eog); STAT_Update(ud.eog || (currentLevel->flags & MI_FORCEEOG));
P_SetGamePalette(g_player[myconnectindex].ps, BASEPAL, 0); P_SetGamePalette(g_player[myconnectindex].ps, BASEPAL, 0);
P_UpdateScreenPal(g_player[myconnectindex].ps); P_UpdateScreenPal(g_player[myconnectindex].ps);
@ -7226,7 +7226,7 @@ static int G_EndOfLevel(void)
// Clear potentially loaded per-map ART only after the bonus screens. // Clear potentially loaded per-map ART only after the bonus screens.
artClearMapArt(); artClearMapArt();
if (ud.eog) if (ud.eog || (currentLevel->flags & MI_FORCEEOG))
{ {
ud.eog = 0; ud.eog = 0;
if ((!g_netServer && ud.multimode < 2)) if ((!g_netServer && ud.multimode < 2))
@ -7234,8 +7234,6 @@ static int G_EndOfLevel(void)
if (!VOLUMEALL) if (!VOLUMEALL)
G_DoOrderScreen(); G_DoOrderScreen();
g_player[myconnectindex].ps->gm = 0; g_player[myconnectindex].ps->gm = 0;
M_StartControlPanel(false);
M_SetMenu(NAME_MainMenu);
return 2; return 2;
} }
else else

View file

@ -73,7 +73,6 @@ G_EXTERN actor_t actor[MAXSPRITES];
G_EXTERN tiledata_t g_tile[MAXTILES]; G_EXTERN tiledata_t g_tile[MAXTILES];
G_EXTERN animwalltype animwall[MAXANIMWALLS]; G_EXTERN animwalltype animwall[MAXANIMWALLS];
G_EXTERN char *label; G_EXTERN char *label;
G_EXTERN int32_t g_musicIndex;
G_EXTERN char g_loadFromGroupOnly; G_EXTERN char g_loadFromGroupOnly;
G_EXTERN char g_skillCnt; G_EXTERN char g_skillCnt;
G_EXTERN char pus,pub; G_EXTERN char pus,pub;

View file

@ -2243,7 +2243,7 @@ static void G_LoadMapHack(char *outbuf, const char *filename)
} }
// levnamebuf should have at least size BMAX_PATH // levnamebuf should have at least size BMAX_PATH
void G_SetupFilenameBasedMusic(char *nameBuf, const char *fileName, int levelNum) void G_SetupFilenameBasedMusic(char *nameBuf, const char *fileName)
{ {
char *p; char *p;
char const *exts[] = { char const *exts[] = {
@ -2277,12 +2277,12 @@ void G_SetupFilenameBasedMusic(char *nameBuf, const char *fileName, int levelNum
if (FileExists(nameBuf)) if (FileExists(nameBuf))
{ {
mapList[levelNum].music = nameBuf; userMapRecord.music = nameBuf;
return; return;
} }
} }
mapList[levelNum].music = "dethtoll.mid"; userMapRecord.music = "dethtoll.mid";
} }
int G_EnterLevel(int gameMode) int G_EnterLevel(int gameMode)
@ -2378,10 +2378,12 @@ int G_EnterLevel(int gameMode)
OSD_Printf(OSD_ERROR "Map \"%s\" not found or invalid map version!\n", boardfilename); OSD_Printf(OSD_ERROR "Map \"%s\" not found or invalid map version!\n", boardfilename);
return 1; return 1;
} }
userMapRecord.name = "";
STAT_NewLevel(boardfilename); userMapRecord.SetFileName(boardfilename);
currentLevel = &userMapRecord;
STAT_NewLevel(boardfilename);
G_LoadMapHack(levelName, boardfilename); G_LoadMapHack(levelName, boardfilename);
G_SetupFilenameBasedMusic(levelName, boardfilename, m_level_number); G_SetupFilenameBasedMusic(levelName, boardfilename);
} }
else if (engineLoadBoard(mi.fileName, VOLUMEONE, &pPlayer->pos, &lbang, &pPlayer->cursectnum) < 0) else if (engineLoadBoard(mi.fileName, VOLUMEONE, &pPlayer->pos, &lbang, &pPlayer->cursectnum) < 0)
{ {
@ -2390,6 +2392,7 @@ int G_EnterLevel(int gameMode)
} }
else else
{ {
currentLevel = &mi;
STAT_NewLevel(mi.fileName); STAT_NewLevel(mi.fileName);
G_LoadMapHack(levelName, mi.fileName); G_LoadMapHack(levelName, mi.fileName);
} }
@ -2434,14 +2437,7 @@ int G_EnterLevel(int gameMode)
if (ud.recstat != 2) if (ud.recstat != 2)
{ {
if (mapList[g_musicIndex].music.IsEmpty() || S_PlayLevelMusicOrNothing(mii);
mi.music.IsEmpty() ||
mi.music.CompareNoCase(mapList[g_musicIndex].music) ||
g_musicSize == 0 ||
ud.last_level == -1)
{
S_PlayLevelMusicOrNothing(mii);
}
} }
if (RR && !(gameMode & MODE_DEMO)) if (RR && !(gameMode & MODE_DEMO))

View file

@ -146,18 +146,7 @@ static FileReader *OpenSavegame(const char *fn)
{ {
return nullptr; return nullptr;
} }
auto file = ReadSavegameChunk("info.json"); auto file = ReadSavegameChunk("snapshot.dat");
if (!file.isOpen())
{
FinishSavegameRead();
return nullptr;
}
if (G_ValidateSavegame(file, nullptr) <= 0)
{
FinishSavegameRead();
return nullptr;
}
file = ReadSavegameChunk("snapshot.dat");
if (!file.isOpen()) if (!file.isOpen())
{ {
FinishSavegameRead(); FinishSavegameRead();
@ -182,24 +171,6 @@ int32_t G_LoadSaveHeaderNew(char const *fn, savehead_t *saveh)
if (i < 0) if (i < 0)
goto corrupt; goto corrupt;
ssfil = ReadSavegameChunk("screenshot.dat");
TileFiles.tileCreate(TILE_LOADSHOT, 200, 320);
if (ssfil.isOpen())
{
if (ssfil.Read(tileData(TILE_LOADSHOT), 320 * 200) != 320 * 200)
{
OSD_Printf("G_LoadSaveHeaderNew(): failed reading screenshot in \"%s\"\n", fn);
goto corrupt;
}
}
else
{
Bmemset(tileData(TILE_LOADSHOT), 0, 320*200);
}
ssfil.Close();
tileInvalidate(TILE_LOADSHOT, 0, 255);
delete fil; delete fil;
FinishSavegameRead(); FinishSavegameRead();
return 0; return 0;
@ -1169,9 +1140,7 @@ int32_t sv_saveandmakesnapshot(FileWriter &fil, char const *name, int8_t spot, i
Bstrncpyz(h.savename, name, sizeof(h.savename)); Bstrncpyz(h.savename, name, sizeof(h.savename));
auto fw = WriteSavegameChunk("header.dat"); auto fw = WriteSavegameChunk("header.dat");
fw->Write(&h, sizeof(savehead_t)); fw->Write(&h, sizeof(savehead_t));
G_WriteSaveHeader(name);
auto& mi = mapList[(MAXLEVELS * ud.volume_number) + ud.level_number];
G_WriteSaveHeader(name, mi.fileName, mi.DisplayName());
} }
else else
{ {
@ -1190,12 +1159,14 @@ int32_t sv_saveandmakesnapshot(FileWriter &fil, char const *name, int8_t spot, i
// write header // write header
#if 0 // not usable anymore
if (spot >= 0 && tileData(TILE_SAVESHOT)) if (spot >= 0 && tileData(TILE_SAVESHOT))
{ {
auto fw = WriteSavegameChunk("screenshot.dat"); auto fw = WriteSavegameChunk("screenshot.dat");
fw->Write(tileData(TILE_SAVESHOT), 320*200); fw->Write(tileData(TILE_SAVESHOT), 320*200);
} }
#endif
if (spot >= 0) if (spot >= 0)

View file

@ -123,17 +123,9 @@ void S_MenuSound(void)
} }
static void S_SetMusicIndex(unsigned int m)
{
g_musicIndex = m;
ud.music_episode = m / MAXLEVELS;
ud.music_level = m % MAXLEVELS;
}
void S_PlayLevelMusicOrNothing(unsigned int m) void S_PlayLevelMusicOrNothing(unsigned int m)
{ {
Mus_Play(mapList[m].fileName, RR ? nullptr : mapList[m].music, true); Mus_Play(mapList[m].fileName, RR ? nullptr : mapList[m].music, true);
S_SetMusicIndex(m);
} }
int S_TryPlaySpecialMusic(unsigned int m) int S_TryPlaySpecialMusic(unsigned int m)
@ -145,7 +137,6 @@ int S_TryPlaySpecialMusic(unsigned int m)
{ {
if (!Mus_Play(nullptr, musicfn, 1)) if (!Mus_Play(nullptr, musicfn, 1))
{ {
S_SetMusicIndex(m);
return 0; return 0;
} }
} }
@ -169,10 +160,7 @@ void S_PlayRRMusic(int newTrack)
void S_PlaySpecialMusicOrNothing(unsigned int m) void S_PlaySpecialMusicOrNothing(unsigned int m)
{ {
if (S_TryPlaySpecialMusic(m)) S_TryPlaySpecialMusic(m);
{
S_SetMusicIndex(m);
}
} }
void S_Cleanup(void) void S_Cleanup(void)

View file

@ -58,6 +58,7 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms
#include "i_specialpaths.h" #include "i_specialpaths.h"
#include "savegamehelp.h" #include "savegamehelp.h"
#include "z_music.h" #include "z_music.h"
#include "mapinfo.h"
//void TimerFunc(task * Task); //void TimerFunc(task * Task);
BEGIN_SW_NS BEGIN_SW_NS
@ -250,7 +251,12 @@ bool GameInterface::SaveGame(FSaveGameNode *sv)
auto game_name = G_BuildSaveName(sv->Filename); auto game_name = G_BuildSaveName(sv->Filename);
OpenSaveGameForWrite(game_name); OpenSaveGameForWrite(game_name);
G_WriteSaveHeader(sv->SaveTitle, LevelInfo[Level].LevelName, LevelInfo[Level].Description); // workaround until the level info here has been transitioned.
MapRecord mr;
mr.SetFileName(LevelInfo[Level].Description);
mr.labelName = LevelInfo[Level].Description;
currentLevel = &mr;
G_WriteSaveHeader(sv->SaveTitle);
fil = WriteSavegameChunk("snapshot.sw"); fil = WriteSavegameChunk("snapshot.sw");
MWRITE(&GameVersion,sizeof(GameVersion),1,fil); MWRITE(&GameVersion,sizeof(GameVersion),1,fil);