Skip to content

Commit

Permalink
savegame: add triggered music tracks to the savegame
Browse files Browse the repository at this point in the history
Resolves #371.
  • Loading branch information
walkawayy committed Aug 11, 2023
1 parent 5b5c339 commit 9929592
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## [Unreleased](https://github.com/rr-/Tomb1Main/compare/stable...develop) - ××××-××-××
- added the current music track and timestamp to the savegame so they now persist on load (#419)
- added the triggered music tracks to the savegame so one shot tracks don't replay on load (#371)
- changed the installer to always overwrite all essential files such as the gameflow and injections (#904)
- fixed Natla's gun moving while she is in her semi death state (#878)
- fixed an error message from showing on exiting the game when the gym level is not present in the gameflow (#899)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ Not all options are turned on by default. Refer to `Tomb1Main_ConfigTool.exe` fo
- added an option to turn off sound effect pitching
- added an option to use the PlayStation Uzi sound effects
- added the current music track and timestamp to the savegame so they now persist on load
- added the triggered music tracks to the savegame so one shot tracks don't replay on load
- fixed the sound of collecting a secret killing the music
- fixed audio mixer stopping playing sounds on big explosions
- fixed game audio not muting when game is minimized
Expand Down
2 changes: 2 additions & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ bool Config_ReadFromJSON(const char *cfg_data)
READ_BOOL(enable_swing_cancel, true);
READ_BOOL(enable_tr2_jumping, false);
READ_BOOL(load_current_music, true);
READ_BOOL(load_music_triggers, true);

CLAMP(g_Config.start_lara_hitpoints, 1, LARA_HITPOINTS);
CLAMP(g_Config.fov_value, 30, 255);
Expand Down Expand Up @@ -417,6 +418,7 @@ bool Config_Write(void)
WRITE_BOOL(enable_swing_cancel);
WRITE_BOOL(enable_tr2_jumping);
WRITE_BOOL(load_current_music);
WRITE_BOOL(load_music_triggers);

// User settings
WRITE_BOOL(rendering.enable_bilinear_filter);
Expand Down
1 change: 1 addition & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ typedef struct {
bool enable_swing_cancel;
bool enable_tr2_jumping;
bool load_current_music;
bool load_music_triggers;

struct {
int32_t layout;
Expand Down
42 changes: 42 additions & 0 deletions src/game/savegame/savegame_bson.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ static bool Savegame_BSON_LoadLOT(struct json_object_s *lot_obj, LOT_INFO *lot);
static bool Savegame_BSON_LoadLara(
struct json_object_s *lara_obj, LARA_INFO *lara);
static bool SaveGame_BSON_LoadCurrentMusic(struct json_object_s *music_obj);
static bool SaveGame_BSON_LoadMusicTrackFlags(
struct json_array_s *music_track_arr);
static struct json_array_s *Savegame_BSON_DumpResumeInfo(
RESUME_INFO *game_info);
static struct json_object_s *Savegame_BSON_DumpMisc(GAME_INFO *game_info);
Expand All @@ -76,6 +78,7 @@ static struct json_object_s *Savegame_BSON_DumpAmmo(AMMO_INFO *ammo);
static struct json_object_s *Savegame_BSON_DumpLOT(LOT_INFO *lot);
static struct json_object_s *Savegame_BSON_DumpLara(LARA_INFO *lara);
static struct json_object_s *SaveGame_BSON_DumpCurrentMusic(void);
static struct json_array_s *SaveGame_BSON_DumpMusicTrackFlags(void);

static void SaveGame_BSON_SaveRaw(
MYFILE *fp, struct json_value_s *root, int32_t version)
Expand Down Expand Up @@ -822,6 +825,27 @@ static bool SaveGame_BSON_LoadCurrentMusic(struct json_object_s *music_obj)
current_track, timestamp);
}
}
return true;
}

static bool SaveGame_BSON_LoadMusicTrackFlags(
struct json_array_s *music_track_arr)
{
if (!music_track_arr) {
LOG_WARNING("Malformed save: invalid or missing music track array");
return true;
}

if ((signed)music_track_arr->length != MAX_CD_TRACKS) {
LOG_WARNING(
"Malformed save: expected %d music track flags, got %d",
MAX_CD_TRACKS, music_track_arr->length);
return true;
}

for (int i = 0; i < (signed)music_track_arr->length; i++) {
g_MusicTrackFlags[i] = json_array_get_int(music_track_arr, i, 0);
}

return true;
}
Expand Down Expand Up @@ -1146,6 +1170,15 @@ static struct json_object_s *SaveGame_BSON_DumpCurrentMusic(void)
return current_music_obj;
}

static struct json_array_s *SaveGame_BSON_DumpMusicTrackFlags(void)
{
struct json_array_s *music_track_arr = json_array_new();
for (int i = 0; i < MAX_CD_TRACKS; i++) {
json_array_append_int(music_track_arr, g_MusicTrackFlags[i]);
}
return music_track_arr;
}

char *Savegame_BSON_GetSaveFileName(int32_t slot)
{
size_t out_size = snprintf(NULL, 0, g_GameFlow.savegame_fmt_bson, slot) + 1;
Expand Down Expand Up @@ -1266,6 +1299,13 @@ bool Savegame_BSON_LoadFromFile(MYFILE *fp, GAME_INFO *game_info)
}
}

if (header.version >= VERSION_3) {
if (!SaveGame_BSON_LoadMusicTrackFlags(
json_object_get_array(root_obj, "music_track_flags"))) {
goto cleanup;
}
}

ret = true;

cleanup:
Expand Down Expand Up @@ -1335,6 +1375,8 @@ void Savegame_BSON_SaveToFile(MYFILE *fp, GAME_INFO *game_info)
root_obj, "lara", Savegame_BSON_DumpLara(&g_Lara));
json_object_append_object(
root_obj, "music", SaveGame_BSON_DumpCurrentMusic());
json_object_append_array(
root_obj, "music_track_flags", SaveGame_BSON_DumpMusicTrackFlags());

struct json_value_s *root = json_value_from_object(root_obj);
SaveGame_BSON_SaveRaw(fp, root, SAVEGAME_CURRENT_VERSION);
Expand Down

0 comments on commit 9929592

Please sign in to comment.