Skip to content

Commit

Permalink
savegame: add triggered music tracks to the savegame (#905)
Browse files Browse the repository at this point in the history
Resolves #371.
  • Loading branch information
walkawayy authored and rr- committed Aug 15, 2023
1 parent 2a40424 commit a03f76c
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 4 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
40 changes: 40 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 @@ -1264,6 +1297,11 @@ bool Savegame_BSON_LoadFromFile(MYFILE *fp, GAME_INFO *game_info)
json_object_get_object(root_obj, "music"))) {
goto cleanup;
}

if (!SaveGame_BSON_LoadMusicTrackFlags(
json_object_get_array(root_obj, "music_track_flags"))) {
goto cleanup;
}
}

ret = true;
Expand Down Expand Up @@ -1335,6 +1373,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
4 changes: 4 additions & 0 deletions tools/config/Tomb1Main_ConfigTool/Resources/Lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,10 @@
"Title": "Load music track",
"Description": "Loads the music track that was playing when the game was saved."
},
"load_music_triggers": {
"Title": "Remember played music",
"Description": "Loads previously triggered music so music tracks do not replay."
},
"enable_music_in_menu": {
"Title": "Enable main menu music",
"Description": "Plays music in the main menu."
Expand Down
8 changes: 4 additions & 4 deletions tools/config/Tomb1Main_ConfigTool/Resources/Lang/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,14 @@
"Title": "Cargar pista de música",
"Description": "Carga la pista de música que se estaba reproduciendo cuando se guardó el juego."
},
"enable_music_in_menu": {
"Title": "Habilitar música en menú principal",
"Description": "Reproduce música en el menú principal."
},
"load_music_triggers": {
"Title": "Recordar la música reproducida",
"Description": "Carga música activada previamente para que las pistas de música no se reproduzcan."
},
"enable_music_in_menu": {
"Title": "Habilitar música en menú principal",
"Description": "Reproduce música en el menú principal."
},
"enable_numeric_keys": {
"Title": "Uso rápido de teclas numéricas",
"Description": "Permite cambiar rápidamente de armas y usar botiquines.\n- 1: Pistolas\n- 2: Escopeta\n- 3: Magnums\n- 4: Uzis\n- 8: Botiquín pequeño\n- 9: Botiquín grande"
Expand Down
4 changes: 4 additions & 0 deletions tools/config/Tomb1Main_ConfigTool/Resources/Lang/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,10 @@
"Title": "Load music track",
"Description": "Charge la musique qui était en cours de lecture lors de la sauvegarde."
},
"load_music_triggers": {
"Title": "Garder en mémoire les musiques jouées",
"Description": "Garde en mémoire les musiques précédement déclenchées, pour que les pistes ne puissent pas se répéter à un rechargement de partie."
},
"enable_music_in_menu": {
"Title": "Activer la musique dans le menu principal",
"Description": "Chosir d'activer ou non la musique dans le menu principal."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,11 @@
"DataType": "Bool",
"DefaultValue": true
},
{
"Field": "load_music_triggers",
"DataType": "Bool",
"DefaultValue": true
},
{
"Field": "enable_music_in_menu",
"DataType": "Bool",
Expand Down

0 comments on commit a03f76c

Please sign in to comment.