mirror of
https://github.com/LostArtefacts/TRX.git
synced 2025-04-28 20:58:07 +03:00
tr1/savegame: remove passing of game info
The savegame strategies no longer require to receive the game info object so this updates all relevant function signatures.
This commit is contained in:
parent
41c6e32f15
commit
161846e4d3
7 changed files with 29 additions and 50 deletions
|
@ -88,8 +88,7 @@ static DECLARE_GF_EVENT_HANDLER(M_HandlePlayLevel)
|
|||
// select level feature
|
||||
Savegame_InitCurrentInfo();
|
||||
if (level->num > GF_GetFirstLevel()->num) {
|
||||
Savegame_LoadOnlyResumeInfo(
|
||||
g_GameInfo.select_save_slot, &g_GameInfo);
|
||||
Savegame_LoadOnlyResumeInfo(g_GameInfo.select_save_slot);
|
||||
const GF_LEVEL *tmp_level = level;
|
||||
while (tmp_level != nullptr) {
|
||||
Savegame_ResetCurrentInfo(tmp_level);
|
||||
|
|
|
@ -43,7 +43,7 @@ void Savegame_SetCurrentInfo(int32_t current_slot, int32_t src_slot);
|
|||
int32_t Savegame_GetLevelNumber(int32_t slot_num);
|
||||
|
||||
bool Savegame_UpdateDeathCounters(int32_t slot_num, int32_t death_count);
|
||||
bool Savegame_LoadOnlyResumeInfo(int32_t slot_num, GAME_INFO *game_info);
|
||||
bool Savegame_LoadOnlyResumeInfo(int32_t slot_num);
|
||||
|
||||
void Savegame_ScanSavedGames(void);
|
||||
void Savegame_FillAvailableSaves(REQUEST_INFO *req);
|
||||
|
|
|
@ -36,10 +36,9 @@ typedef struct {
|
|||
SAVEGAME_FORMAT format;
|
||||
const char *(*get_save_filename_pattern)(void);
|
||||
bool (*fill_info)(MYFILE *fp, SAVEGAME_INFO *info);
|
||||
bool (*load_from_file)(MYFILE *fp, GAME_INFO *game_info);
|
||||
bool (*load_only_resume_info)(MYFILE *fp, GAME_INFO *game_info);
|
||||
void (*save_to_file)(
|
||||
MYFILE *fp, GAME_INFO *game_info, SAVEGAME_INFO *savegame_info);
|
||||
bool (*load_from_file)(MYFILE *fp);
|
||||
bool (*load_only_resume_info)(MYFILE *fp);
|
||||
void (*save_to_file)(MYFILE *fp, SAVEGAME_INFO *savegame_info);
|
||||
bool (*update_death_counters)(MYFILE *fp, int32_t death_count);
|
||||
} SAVEGAME_STRATEGY;
|
||||
|
||||
|
@ -486,7 +485,6 @@ bool Savegame_IsSlotFree(const int32_t slot_num)
|
|||
|
||||
bool Savegame_Load(const int32_t slot_num)
|
||||
{
|
||||
GAME_INFO *const game_info = &g_GameInfo;
|
||||
SAVEGAME_INFO *savegame_info = &m_SavegameInfo[slot_num];
|
||||
ASSERT(savegame_info->format != 0);
|
||||
|
||||
|
@ -498,7 +496,7 @@ bool Savegame_Load(const int32_t slot_num)
|
|||
if (savegame_info->format == strategy->format) {
|
||||
MYFILE *fp = File_Open(savegame_info->full_path, FILE_OPEN_READ);
|
||||
if (fp) {
|
||||
ret = strategy->load_from_file(fp, game_info);
|
||||
ret = strategy->load_from_file(fp);
|
||||
File_Close(fp);
|
||||
}
|
||||
break;
|
||||
|
@ -517,7 +515,6 @@ bool Savegame_Load(const int32_t slot_num)
|
|||
|
||||
bool Savegame_Save(const int32_t slot_num)
|
||||
{
|
||||
GAME_INFO *const game_info = &g_GameInfo;
|
||||
bool ret = false;
|
||||
Savegame_BindSlot(slot_num);
|
||||
|
||||
|
@ -547,7 +544,7 @@ 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, game_info, savegame_info);
|
||||
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));
|
||||
|
@ -602,9 +599,8 @@ bool Savegame_UpdateDeathCounters(
|
|||
return ret;
|
||||
}
|
||||
|
||||
bool Savegame_LoadOnlyResumeInfo(int32_t slot_num, GAME_INFO *game_info)
|
||||
bool Savegame_LoadOnlyResumeInfo(int32_t slot_num)
|
||||
{
|
||||
ASSERT(game_info != nullptr);
|
||||
SAVEGAME_INFO *savegame_info = &m_SavegameInfo[slot_num];
|
||||
ASSERT(savegame_info->format != 0);
|
||||
|
||||
|
@ -614,7 +610,7 @@ bool Savegame_LoadOnlyResumeInfo(int32_t slot_num, GAME_INFO *game_info)
|
|||
if (savegame_info->format == strategy->format) {
|
||||
MYFILE *fp = File_Open(savegame_info->full_path, FILE_OPEN_READ);
|
||||
if (fp) {
|
||||
ret = strategy->load_only_resume_info(fp, game_info);
|
||||
ret = strategy->load_only_resume_info(fp);
|
||||
File_Close(fp);
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -60,8 +60,7 @@ static JSON_VALUE *M_ParseFromFile(MYFILE *fp, int32_t *version_out);
|
|||
static bool M_LoadResumeInfo(JSON_ARRAY *levels_arr, uint16_t header_version);
|
||||
static bool M_LoadDiscontinuedStartInfo(JSON_ARRAY *start_arr);
|
||||
static bool M_LoadDiscontinuedEndInfo(JSON_ARRAY *end_arr);
|
||||
static bool M_LoadMisc(
|
||||
JSON_OBJECT *misc_obj, GAME_INFO *game_info, uint16_t header_version);
|
||||
static bool M_LoadMisc(JSON_OBJECT *misc_obj, uint16_t header_version);
|
||||
static bool M_LoadInventory(JSON_OBJECT *inv_obj);
|
||||
static bool M_LoadFlipmaps(JSON_OBJECT *flipmap_obj);
|
||||
static bool M_LoadCameras(JSON_ARRAY *cameras_arr);
|
||||
|
@ -75,7 +74,7 @@ static bool M_LoadLara(
|
|||
static bool M_LoadCurrentMusic(JSON_OBJECT *music_obj);
|
||||
static bool M_LoadMusicTrackFlags(JSON_ARRAY *music_track_arr);
|
||||
static JSON_ARRAY *M_DumpResumeInfo(void);
|
||||
static JSON_OBJECT *M_DumpMisc(GAME_INFO *game_info);
|
||||
static JSON_OBJECT *M_DumpMisc(void);
|
||||
static JSON_OBJECT *M_DumpInventory(void);
|
||||
static JSON_OBJECT *M_DumpFlipmaps(void);
|
||||
static JSON_ARRAY *M_DumpCameras(void);
|
||||
|
@ -394,9 +393,8 @@ static bool M_LoadDiscontinuedEndInfo(JSON_ARRAY *end_arr)
|
|||
}
|
||||
|
||||
static bool M_LoadMisc(
|
||||
JSON_OBJECT *misc_obj, GAME_INFO *game_info, uint16_t header_version)
|
||||
JSON_OBJECT *const misc_obj, const uint16_t header_version)
|
||||
{
|
||||
ASSERT(game_info != nullptr);
|
||||
if (!misc_obj) {
|
||||
LOG_ERROR("Malformed save: invalid or missing misc info");
|
||||
return false;
|
||||
|
@ -1030,9 +1028,8 @@ static JSON_ARRAY *M_DumpResumeInfo(void)
|
|||
return resume_arr;
|
||||
}
|
||||
|
||||
static JSON_OBJECT *M_DumpMisc(GAME_INFO *game_info)
|
||||
static JSON_OBJECT *M_DumpMisc(void)
|
||||
{
|
||||
ASSERT(game_info != nullptr);
|
||||
JSON_OBJECT *misc_obj = JSON_ObjectNew();
|
||||
JSON_ObjectAppendInt(misc_obj, "bonus_flag", Game_GetBonusFlag());
|
||||
|
||||
|
@ -1389,10 +1386,8 @@ bool Savegame_BSON_FillInfo(MYFILE *fp, SAVEGAME_INFO *info)
|
|||
return ret;
|
||||
}
|
||||
|
||||
bool Savegame_BSON_LoadFromFile(MYFILE *fp, GAME_INFO *game_info)
|
||||
bool Savegame_BSON_LoadFromFile(MYFILE *const fp)
|
||||
{
|
||||
ASSERT(game_info != nullptr);
|
||||
|
||||
bool ret = false;
|
||||
|
||||
int32_t version;
|
||||
|
@ -1419,8 +1414,7 @@ bool Savegame_BSON_LoadFromFile(MYFILE *fp, GAME_INFO *game_info)
|
|||
}
|
||||
}
|
||||
|
||||
if (!M_LoadMisc(
|
||||
JSON_ObjectGetObject(root_obj, "misc"), game_info, version)) {
|
||||
if (!M_LoadMisc(JSON_ObjectGetObject(root_obj, "misc"), version)) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
@ -1470,10 +1464,8 @@ cleanup:
|
|||
return ret;
|
||||
}
|
||||
|
||||
bool Savegame_BSON_LoadOnlyResumeInfo(MYFILE *fp, GAME_INFO *game_info)
|
||||
bool Savegame_BSON_LoadOnlyResumeInfo(MYFILE *const fp)
|
||||
{
|
||||
ASSERT(game_info != nullptr);
|
||||
|
||||
bool ret = false;
|
||||
|
||||
int32_t version;
|
||||
|
@ -1508,11 +1500,8 @@ cleanup:
|
|||
}
|
||||
|
||||
void Savegame_BSON_SaveToFile(
|
||||
MYFILE *const fp, GAME_INFO *const game_info,
|
||||
SAVEGAME_INFO *const savegame_info)
|
||||
MYFILE *const fp, SAVEGAME_INFO *const savegame_info)
|
||||
{
|
||||
ASSERT(game_info != nullptr);
|
||||
|
||||
const GF_LEVEL *const current_level = Game_GetCurrentLevel();
|
||||
JSON_OBJECT *root_obj = JSON_ObjectNew();
|
||||
|
||||
|
@ -1520,7 +1509,7 @@ void Savegame_BSON_SaveToFile(
|
|||
JSON_ObjectAppendInt(root_obj, "save_counter", g_SaveCounter);
|
||||
JSON_ObjectAppendInt(root_obj, "level_num", current_level->num);
|
||||
|
||||
JSON_ObjectAppendObject(root_obj, "misc", M_DumpMisc(game_info));
|
||||
JSON_ObjectAppendObject(root_obj, "misc", M_DumpMisc());
|
||||
JSON_ObjectAppendArray(root_obj, "current_info", M_DumpResumeInfo());
|
||||
JSON_ObjectAppendObject(root_obj, "inventory", M_DumpInventory());
|
||||
JSON_ObjectAppendObject(root_obj, "flipmap", M_DumpFlipmaps());
|
||||
|
|
|
@ -11,8 +11,7 @@
|
|||
|
||||
const char *Savegame_BSON_GetSaveFilePattern(void);
|
||||
bool Savegame_BSON_FillInfo(MYFILE *fp, SAVEGAME_INFO *info);
|
||||
bool Savegame_BSON_LoadFromFile(MYFILE *fp, GAME_INFO *game_info);
|
||||
bool Savegame_BSON_LoadOnlyResumeInfo(MYFILE *fp, GAME_INFO *game_info);
|
||||
void Savegame_BSON_SaveToFile(
|
||||
MYFILE *fp, GAME_INFO *game_info, SAVEGAME_INFO *savegame_info);
|
||||
bool Savegame_BSON_LoadFromFile(MYFILE *fp);
|
||||
bool Savegame_BSON_LoadOnlyResumeInfo(MYFILE *fp);
|
||||
void Savegame_BSON_SaveToFile(MYFILE *fp, SAVEGAME_INFO *savegame_info);
|
||||
bool Savegame_BSON_UpdateDeathCounters(MYFILE *fp, int32_t death_count);
|
||||
|
|
|
@ -83,7 +83,7 @@ static void M_ReadAmmoInfo(AMMO_INFO *ammo_info);
|
|||
static void M_ReadLara(LARA_INFO *lara);
|
||||
static void M_ReadLOT(LOT_INFO *lot);
|
||||
static void M_SetCurrentPosition(int32_t level_num);
|
||||
static void M_ReadResumeInfo(MYFILE *fp, GAME_INFO *game_info);
|
||||
static void M_ReadResumeInfo(MYFILE *fp);
|
||||
|
||||
static bool M_ItemHasSaveFlags(const OBJECT *const obj, ITEM *const item)
|
||||
{
|
||||
|
@ -330,7 +330,7 @@ static void M_SetCurrentPosition(const int32_t level_num)
|
|||
}
|
||||
}
|
||||
|
||||
static void M_ReadResumeInfo(MYFILE *const fp, GAME_INFO *const game_info)
|
||||
static void M_ReadResumeInfo(MYFILE *const fp)
|
||||
{
|
||||
const GF_LEVEL_TABLE *const level_table = GF_GetLevelTable(GFLT_MAIN);
|
||||
for (int32_t i = 0; i < level_table->count; i++) {
|
||||
|
@ -424,10 +424,8 @@ bool Savegame_Legacy_FillInfo(MYFILE *const fp, SAVEGAME_INFO *const info)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Savegame_Legacy_LoadFromFile(MYFILE *const fp, GAME_INFO *const game_info)
|
||||
bool Savegame_Legacy_LoadFromFile(MYFILE *const fp)
|
||||
{
|
||||
ASSERT(game_info != nullptr);
|
||||
|
||||
char *buffer = Memory_Alloc(File_Size(fp));
|
||||
File_Seek(fp, 0, FILE_SEEK_SET);
|
||||
File_ReadData(fp, buffer, File_Size(fp));
|
||||
|
@ -441,7 +439,7 @@ bool Savegame_Legacy_LoadFromFile(MYFILE *const fp, GAME_INFO *const game_info)
|
|||
M_Skip(SAVEGAME_LEGACY_TITLE_SIZE); // level title
|
||||
M_Skip(sizeof(int32_t)); // save counter
|
||||
|
||||
M_ReadResumeInfo(fp, game_info);
|
||||
M_ReadResumeInfo(fp);
|
||||
g_Lara.holsters_gun_type = LGT_UNKNOWN;
|
||||
g_Lara.back_gun_type = LGT_UNKNOWN;
|
||||
|
||||
|
@ -559,10 +557,8 @@ bool Savegame_Legacy_LoadFromFile(MYFILE *const fp, GAME_INFO *const game_info)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Savegame_Legacy_LoadOnlyResumeInfo(MYFILE *fp, GAME_INFO *game_info)
|
||||
bool Savegame_Legacy_LoadOnlyResumeInfo(MYFILE *fp)
|
||||
{
|
||||
ASSERT(game_info != nullptr);
|
||||
|
||||
char *buffer = Memory_Alloc(File_Size(fp));
|
||||
File_Seek(fp, 0, FILE_SEEK_SET);
|
||||
File_ReadData(fp, buffer, File_Size(fp));
|
||||
|
@ -570,7 +566,7 @@ bool Savegame_Legacy_LoadOnlyResumeInfo(MYFILE *fp, GAME_INFO *game_info)
|
|||
M_Skip(SAVEGAME_LEGACY_TITLE_SIZE); // level title
|
||||
M_Skip(sizeof(int32_t)); // save counter
|
||||
|
||||
M_ReadResumeInfo(fp, game_info);
|
||||
M_ReadResumeInfo(fp);
|
||||
|
||||
Memory_FreePointer(&buffer);
|
||||
return true;
|
||||
|
|
|
@ -11,5 +11,5 @@
|
|||
|
||||
const char *Savegame_Legacy_GetSaveFilePattern(void);
|
||||
bool Savegame_Legacy_FillInfo(MYFILE *fp, SAVEGAME_INFO *info);
|
||||
bool Savegame_Legacy_LoadFromFile(MYFILE *fp, GAME_INFO *game_info);
|
||||
bool Savegame_Legacy_LoadOnlyResumeInfo(MYFILE *fp, GAME_INFO *game_info);
|
||||
bool Savegame_Legacy_LoadFromFile(MYFILE *fp);
|
||||
bool Savegame_Legacy_LoadOnlyResumeInfo(MYFILE *fp);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue