mirror of
https://github.com/LostArtefacts/TRX.git
synced 2025-04-28 20:58:07 +03:00
tr1/savegame: move misc properties to module
This moves the counter, total save count and initial version properties to the main savegame module rather than using globals.
This commit is contained in:
parent
fc09a0cf90
commit
12edeaee37
7 changed files with 48 additions and 21 deletions
|
@ -229,7 +229,8 @@ static void M_SetPage(
|
|||
|
||||
static void M_DeterminePages(void)
|
||||
{
|
||||
const bool has_saves = g_SavedGamesCount > 0 && Savegame_GetSlotCount() > 0;
|
||||
const bool has_saves =
|
||||
Savegame_GetTotalCount() > 0 && Savegame_GetSlotCount() > 0;
|
||||
|
||||
switch (g_InvMode) {
|
||||
case INV_TITLE_MODE:
|
||||
|
@ -568,7 +569,7 @@ static void M_NewGame(void)
|
|||
g_InputDB = (INPUT_STATE) {};
|
||||
m_State.mode = PASSPORT_MODE_NEW_GAME;
|
||||
} else {
|
||||
g_GameInfo.save_initial_version = SAVEGAME_CURRENT_VERSION;
|
||||
Savegame_SetInitialVersion(SAVEGAME_CURRENT_VERSION);
|
||||
g_GameInfo.passport_selection = PASSPORT_MODE_NEW_GAME;
|
||||
}
|
||||
} else if (m_State.mode == PASSPORT_MODE_NEW_GAME) {
|
||||
|
@ -593,7 +594,7 @@ static void M_NewGame(void)
|
|||
break;
|
||||
}
|
||||
g_GameInfo.passport_selection = PASSPORT_MODE_NEW_GAME;
|
||||
g_GameInfo.save_initial_version = SAVEGAME_CURRENT_VERSION;
|
||||
Savegame_SetInitialVersion(SAVEGAME_CURRENT_VERSION);
|
||||
} else if (
|
||||
g_InvMode != INV_SAVE_MODE && g_InvMode != INV_SAVE_CRYSTAL_MODE
|
||||
&& g_InvMode != INV_LOAD_MODE) {
|
||||
|
|
|
@ -64,3 +64,8 @@ void Savegame_PersistGameToCurrentInfo(const GF_LEVEL *level);
|
|||
|
||||
void Savegame_ProcessItemsBeforeLoad(void);
|
||||
void Savegame_ProcessItemsBeforeSave(void);
|
||||
|
||||
SAVEGAME_VERSION Savegame_GetInitialVersion(void);
|
||||
void Savegame_SetInitialVersion(SAVEGAME_VERSION version);
|
||||
int32_t Savegame_GetCounter(void);
|
||||
int32_t Savegame_GetTotalCount(void);
|
||||
|
|
|
@ -44,8 +44,11 @@ typedef struct {
|
|||
|
||||
static int32_t m_SaveSlots = 0;
|
||||
static int16_t m_NewestSlot = -1;
|
||||
static int32_t m_SaveCounter = 0;
|
||||
static int32_t m_SavedGames = 0;
|
||||
static SAVEGAME_INFO *m_SavegameInfo = nullptr;
|
||||
static RESUME_INFO *m_ResumeInfo = nullptr;
|
||||
static SAVEGAME_VERSION m_InitialVersion = VERSION_LEGACY;
|
||||
|
||||
static const SAVEGAME_STRATEGY m_Strategies[] = {
|
||||
{
|
||||
|
@ -508,7 +511,7 @@ bool Savegame_Load(const int32_t slot_num)
|
|||
M_LoadPostprocess();
|
||||
}
|
||||
|
||||
g_GameInfo.save_initial_version = m_SavegameInfo[slot_num].initial_version;
|
||||
m_InitialVersion = m_SavegameInfo[slot_num].initial_version;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -534,6 +537,8 @@ bool Savegame_Save(const int32_t slot_num)
|
|||
|
||||
SAVEGAME_INFO *savegame_info = &m_SavegameInfo[slot_num];
|
||||
const bool was_slot_empty = savegame_info->full_path == nullptr;
|
||||
|
||||
m_SaveCounter++;
|
||||
const SAVEGAME_STRATEGY *strategy = m_Strategies;
|
||||
while (strategy->format != 0) {
|
||||
if (strategy->allow_save && strategy->save_to_file != nullptr) {
|
||||
|
@ -543,12 +548,11 @@ bool Savegame_Save(const int32_t slot_num)
|
|||
|
||||
MYFILE *const fp = File_Open(full_path, FILE_OPEN_WRITE);
|
||||
if (fp != nullptr) {
|
||||
g_SaveCounter++;
|
||||
strategy->save_to_file(fp, savegame_info);
|
||||
savegame_info->format = strategy->format;
|
||||
Memory_FreePointer(&savegame_info->full_path);
|
||||
savegame_info->full_path = Memory_DupStr(File_GetPath(fp));
|
||||
savegame_info->counter = g_SaveCounter;
|
||||
savegame_info->counter = m_SaveCounter;
|
||||
savegame_info->level_num = current_level->num;
|
||||
savegame_info->level_title = level_title != nullptr
|
||||
? Memory_DupStr(level_title)
|
||||
|
@ -566,9 +570,11 @@ bool Savegame_Save(const int32_t slot_num)
|
|||
if (ret) {
|
||||
m_NewestSlot = slot_num;
|
||||
if (was_slot_empty) {
|
||||
g_SavedGamesCount++;
|
||||
m_SavedGames++;
|
||||
}
|
||||
Savegame_HighlightNewestSlot();
|
||||
} else {
|
||||
m_SaveCounter--;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -618,7 +624,7 @@ bool Savegame_LoadOnlyResumeInfo(int32_t slot_num)
|
|||
strategy++;
|
||||
}
|
||||
|
||||
g_GameInfo.save_initial_version = m_SavegameInfo[slot_num].initial_version;
|
||||
m_InitialVersion = m_SavegameInfo[slot_num].initial_version;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -628,8 +634,8 @@ void Savegame_ScanSavedGames(void)
|
|||
BENCHMARK benchmark = Benchmark_Start();
|
||||
M_ClearSlots();
|
||||
|
||||
g_SaveCounter = 0;
|
||||
g_SavedGamesCount = 0;
|
||||
m_SaveCounter = 0;
|
||||
m_SavedGames = 0;
|
||||
m_NewestSlot = -1;
|
||||
|
||||
M_ScanSavedGamesDir(SAVES_DIR);
|
||||
|
@ -638,11 +644,11 @@ void Savegame_ScanSavedGames(void)
|
|||
for (int32_t i = 0; i < m_SaveSlots; i++) {
|
||||
SAVEGAME_INFO *savegame_info = &m_SavegameInfo[i];
|
||||
if (savegame_info->level_title != nullptr) {
|
||||
if (savegame_info->counter > g_SaveCounter) {
|
||||
g_SaveCounter = savegame_info->counter;
|
||||
if (savegame_info->counter > m_SaveCounter) {
|
||||
m_SaveCounter = savegame_info->counter;
|
||||
m_NewestSlot = i;
|
||||
}
|
||||
g_SavedGamesCount++;
|
||||
m_SavedGames++;
|
||||
}
|
||||
}
|
||||
Benchmark_End(&benchmark, nullptr);
|
||||
|
@ -720,3 +726,23 @@ bool Savegame_RestartAvailable(int32_t slot_num)
|
|||
SAVEGAME_INFO *savegame_info = &m_SavegameInfo[slot_num];
|
||||
return savegame_info->features.restart;
|
||||
}
|
||||
|
||||
SAVEGAME_VERSION Savegame_GetInitialVersion(void)
|
||||
{
|
||||
return m_InitialVersion;
|
||||
}
|
||||
|
||||
void Savegame_SetInitialVersion(const SAVEGAME_VERSION version)
|
||||
{
|
||||
m_InitialVersion = version;
|
||||
}
|
||||
|
||||
int32_t Savegame_GetCounter(void)
|
||||
{
|
||||
return m_SaveCounter;
|
||||
}
|
||||
|
||||
int32_t Savegame_GetTotalCount(void)
|
||||
{
|
||||
return m_SavedGames;
|
||||
}
|
||||
|
|
|
@ -109,7 +109,7 @@ static void M_SaveRaw(MYFILE *fp, JSON_VALUE *root, int32_t version)
|
|||
|
||||
SAVEGAME_BSON_HEADER header = {
|
||||
.magic = SAVEGAME_BSON_MAGIC,
|
||||
.initial_version = g_GameInfo.save_initial_version,
|
||||
.initial_version = Savegame_GetInitialVersion(),
|
||||
.version = version,
|
||||
.compressed_size = compressed_size,
|
||||
.uncompressed_size = uncompressed_size,
|
||||
|
@ -122,7 +122,7 @@ static void M_SaveRaw(MYFILE *fp, JSON_VALUE *root, int32_t version)
|
|||
const GF_LEVEL *const level = Game_GetCurrentLevel();
|
||||
SAVEGAME_BSON_EXTENDED_HEADER extra_header = {
|
||||
.flags = Game_GetBonusFlag(),
|
||||
.counter = g_SaveCounter,
|
||||
.counter = Savegame_GetCounter(),
|
||||
.level_num = level->num,
|
||||
.title_size = strlen(level->title),
|
||||
};
|
||||
|
@ -1506,7 +1506,7 @@ void Savegame_BSON_SaveToFile(
|
|||
JSON_OBJECT *root_obj = JSON_ObjectNew();
|
||||
|
||||
JSON_ObjectAppendString(root_obj, "level_title", current_level->title);
|
||||
JSON_ObjectAppendInt(root_obj, "save_counter", g_SaveCounter);
|
||||
JSON_ObjectAppendInt(root_obj, "save_counter", Savegame_GetCounter());
|
||||
JSON_ObjectAppendInt(root_obj, "level_num", current_level->num);
|
||||
|
||||
JSON_ObjectAppendObject(root_obj, "misc", M_DumpMisc());
|
||||
|
|
|
@ -158,7 +158,6 @@ typedef struct {
|
|||
} RESUME_INFO;
|
||||
|
||||
typedef struct {
|
||||
int16_t save_initial_version;
|
||||
PASSPORT_MODE passport_selection;
|
||||
int32_t select_save_slot;
|
||||
int32_t select_level_num;
|
||||
|
|
|
@ -15,8 +15,6 @@ float g_FltResZBuf;
|
|||
LARA_INFO g_Lara = {};
|
||||
ITEM *g_LaraItem = nullptr;
|
||||
GAME_INFO g_GameInfo = { .select_save_slot = -1 };
|
||||
int32_t g_SavedGamesCount = 0;
|
||||
int32_t g_SaveCounter = 0;
|
||||
bool g_LevelComplete = false;
|
||||
int32_t g_OverlayFlag = 0;
|
||||
|
||||
|
|
|
@ -23,8 +23,6 @@ extern int32_t g_FPSCounter;
|
|||
extern LARA_INFO g_Lara;
|
||||
extern ITEM *g_LaraItem;
|
||||
extern GAME_INFO g_GameInfo;
|
||||
extern int32_t g_SavedGamesCount;
|
||||
extern int32_t g_SaveCounter;
|
||||
extern bool g_LevelComplete;
|
||||
extern int32_t g_OverlayFlag;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue