Skip to content

Commit

Permalink
tr1/savegame: save and load ambient music timestamp
Browse files Browse the repository at this point in the history
This will save the current music track and a flag to indicate whether
or not it's looped, so that on load, the correct start-up for it is
applied. This also changes the related config option from a bool to an
enum with options for never, non-ambient, and always.

Resolves #1769.
  • Loading branch information
lahm86 committed Nov 3, 2024
1 parent 432f7bd commit fec71a2
Show file tree
Hide file tree
Showing 12 changed files with 92 additions and 32 deletions.
1 change: 1 addition & 0 deletions docs/tr1/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
- `\{ammo shotgun}`
- `\{ammo magnums}`
- `\{ammo uzis}`
- changed the music timestamp loading behaviour and config option to support ambient tracks (#1769)
- fixed missing pushblock SFX in Natla's Mines (#1714)
- fixed crash reports not working in certain circumstances (#1738)
- fixed missing trapdoor triggers in City of Khamoon (#1744)
Expand Down
11 changes: 11 additions & 0 deletions src/tr1/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@ static void M_LoadLegacyOptions(JSON_OBJECT *const parent_obj)
parent_obj, "enemy_healthbar_showing_mode",
g_Config.enemy_healthbar_show_mode, ENUM_MAP_NAME(BAR_SHOW_MODE));
}

// 2.16..4.5.1 load_current_music
{
const JSON_VALUE *const value =
JSON_ObjectGetValue(parent_obj, "load_current_music");
if (JSON_ValueIsTrue(value)) {
g_Config.music_load_condition = MUSIC_LOAD_NON_AMBIENT;
} else if (JSON_ValueIsFalse(value)) {
g_Config.music_load_condition = MUSIC_LOAD_NEVER;
}
}
}

static void M_DumpKeyboardLayout(
Expand Down
2 changes: 1 addition & 1 deletion src/tr1/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ typedef struct {
bool enable_tr2_jumping;
bool enable_tr2_swimming;
bool enable_wading;
bool load_current_music;
MUSIC_LOAD_CONDITION music_load_condition;
bool load_music_triggers;
bool fix_item_rots;
bool restore_ps1_enemies;
Expand Down
2 changes: 1 addition & 1 deletion src/tr1/config_map.def
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ CFG_BOOL(g_Config, enable_swing_cancel, true)
CFG_BOOL(g_Config, enable_tr2_jumping, false)
CFG_BOOL(g_Config, enable_tr2_swimming, false)
CFG_BOOL(g_Config, enable_wading, true)
CFG_BOOL(g_Config, load_current_music, true)
CFG_ENUM(g_Config, music_load_condition, MUSIC_LOAD_NON_AMBIENT, MUSIC_LOAD_CONDITION)
CFG_BOOL(g_Config, load_music_triggers, true)
CFG_BOOL(g_Config, fix_item_rots, true)
CFG_BOOL(g_Config, restore_ps1_enemies, false)
Expand Down
22 changes: 17 additions & 5 deletions src/tr1/game/savegame/savegame_bson.c
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ static bool M_LoadLara(

static bool M_LoadCurrentMusic(JSON_OBJECT *music_obj)
{
if (!g_Config.load_current_music) {
if (g_Config.music_load_condition == MUSIC_LOAD_NEVER) {
return true;
}

Expand All @@ -877,7 +877,17 @@ static bool M_LoadCurrentMusic(JSON_OBJECT *music_obj)
int16_t current_track = JSON_ObjectGetInt(music_obj, "current_track", -1);
double timestamp = JSON_ObjectGetDouble(music_obj, "timestamp", -1.0);
if (current_track != MX_INACTIVE) {
Music_Play(current_track);
const bool is_ambient =
JSON_ObjectGetBool(music_obj, "is_ambient", false);
if (is_ambient) {
if (g_Config.music_load_condition == MUSIC_LOAD_NON_AMBIENT) {
return true;
}
Music_PlayLooped(current_track);
} else {
Music_Play(current_track);
}

if (!Music_SeekTimestamp(timestamp)) {
LOG_WARNING(
"Could not load current track %d at timestamp %" PRId64 ".",
Expand Down Expand Up @@ -1246,11 +1256,13 @@ static JSON_OBJECT *M_DumpLara(LARA_INFO *lara)

static JSON_OBJECT *M_DumpCurrentMusic(void)
{
JSON_OBJECT *current_music_obj = JSON_ObjectNew();
JSON_ObjectAppendInt(
current_music_obj, "current_track", Music_GetCurrentPlayingTrack());
const MUSIC_TRACK_ID current_track = Music_GetCurrentPlayingTrack();
const bool is_ambient = current_track == Music_GetCurrentLoopedTrack();
JSON_OBJECT *const current_music_obj = JSON_ObjectNew();
JSON_ObjectAppendInt(current_music_obj, "current_track", current_track);
JSON_ObjectAppendDouble(
current_music_obj, "timestamp", Music_GetTimestamp());
JSON_ObjectAppendBool(current_music_obj, "is_ambient", is_ambient);

return current_music_obj;
}
Expand Down
4 changes: 4 additions & 0 deletions src/tr1/global/enum_map.def
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,7 @@ ENUM_MAP_DEFINE(UNDERWATER_MUSIC_MODE, UMM_QUIET, "quiet")
ENUM_MAP_DEFINE(UNDERWATER_MUSIC_MODE, UMM_FULL_NO_AMBIENT, "full_no_ambient")
ENUM_MAP_DEFINE(UNDERWATER_MUSIC_MODE, UMM_QUIET_NO_AMBIENT, "quiet_no_ambient")
ENUM_MAP_DEFINE(UNDERWATER_MUSIC_MODE, UMM_NONE, "none")

ENUM_MAP_DEFINE(MUSIC_LOAD_CONDITION, MUSIC_LOAD_NEVER, "never")
ENUM_MAP_DEFINE(MUSIC_LOAD_CONDITION, MUSIC_LOAD_NON_AMBIENT, "non-ambient")
ENUM_MAP_DEFINE(MUSIC_LOAD_CONDITION, MUSIC_LOAD_ALWAYS, "always")
6 changes: 6 additions & 0 deletions src/tr1/global/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -909,3 +909,9 @@ typedef enum {
TLM_SEMI,
TLM_NONE,
} TARGET_LOCK_MODE;

typedef enum {
MUSIC_LOAD_NEVER,
MUSIC_LOAD_NON_AMBIENT,
MUSIC_LOAD_ALWAYS,
} MUSIC_LOAD_CONDITION;
31 changes: 18 additions & 13 deletions tools/tr1/config/TR1X_ConfigTool/Resources/Lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,22 @@
"bottom-center": "Bottom center",
"bottom-right": "Bottom right"
},
"target_mode": {
"full-lock": "Full lock",
"semi-lock": "Semi lock",
"no-lock": "No lock"
},
"underwater_music": {
"full": "Full",
"quiet": "Quiet",
"full_no_ambient": "Full but no ambient",
"quiet_no_ambient": "Quiet but no ambient",
"none": "None"
"target_mode": {
"full-lock": "Full lock",
"semi-lock": "Semi lock",
"no-lock": "No lock"
},
"underwater_music": {
"full": "Full",
"quiet": "Quiet",
"full_no_ambient": "Full but no ambient",
"quiet_no_ambient": "Quiet but no ambient",
"none": "None"
},
"music_load_condition": {
"never": "Never",
"non-ambient": "Non-ambient",
"always": "Always"
}
},
"Properties": {
Expand Down Expand Up @@ -331,9 +336,9 @@
"Title": "Screenshot format",
"Description": "Screenshot file format."
},
"load_current_music": {
"music_load_condition": {
"Title": "Load music track",
"Description": "Loads the music track that was playing when the game was saved."
"Description": "Loads the music track that was playing when the game was saved.\n- Never: do not restore music tracks on load.\n- Non-ambient: restore only non-ambient music tracks on load.\n- Always: restore any kind of music track on load."
},
"load_music_triggers": {
"Title": "Remember played music",
Expand Down
9 changes: 7 additions & 2 deletions tools/tr1/config/TR1X_ConfigTool/Resources/Lang/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@
"full_no_ambient": "Completo pero sin ambiente",
"quiet_no_ambient": "Tranquilo pero sin ambientet",
"none": "Ninguno"
},
"music_load_condition": {
"never": "Nunca",
"non-ambient": "No ambiental",
"always": "Siempre"
}
},
"Properties": {
Expand Down Expand Up @@ -203,9 +208,9 @@
"Title": "Habilitar sonidos de juegos en el inventario",
"Description": "Permite que los sonidos del juego continúen reproduciéndose en la pantalla de inventario."
},
"load_current_music": {
"music_load_condition": {
"Title": "Cargar pista de música",
"Description": "Carga la pista de música que se estaba reproduciendo cuando se guardó el juego."
"Description": "Carga la pista de música que se estaba reproduciendo cuando se guardó el juego.\n- Nunca: no restaura pistas de música al cargar.\n- No ambiental: restaura solo pistas de música no ambientales al cargar.\n- Siempre: restaura cualquier tipo de pista de música al cargar."
},
"load_music_triggers": {
"Title": "Recordar la música reproducida",
Expand Down
13 changes: 9 additions & 4 deletions tools/tr1/config/TR1X_ConfigTool/Resources/Lang/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,19 @@
"full-lock": "Full lock",
"semi-lock": "Semi lock",
"no-lock": "No lock"
},
},
"underwater_music": {
"full": "Complète",
"quiet": "Calme",
"full_no_ambient": "Plein mais sans ambiance",
"quiet_no_ambient": "Calme mais sans ambiance",
"none": "Aucune"
}
},
"music_load_condition": {
"never": "Jamais",
"non-ambient": "Non ambiant",
"always": "Toujours"
}
},
"Properties": {
"enable_tr3_sidesteps": {
Expand Down Expand Up @@ -331,9 +336,9 @@
"Title": "Format des screenshots",
"Description": "Selectionner le format voulu pour les captures d'écran en jeu."
},
"load_current_music": {
"music_load_condition": {
"Title": "Load music track",
"Description": "Charge la musique qui était en cours de lecture lors de la sauvegarde."
"Description": "Charge la musique qui était en cours de lecture lors de la sauvegarde.\n- Jamais : ne restaure pas les morceaux de musique au chargement.\n- Non ambiant : restaure uniquement les morceaux de musique non ambiants au chargement.\n- Toujours : restaure tout type de morceau de musique au chargement."
},
"load_music_triggers": {
"Title": "Garder en mémoire les musiques jouées",
Expand Down
11 changes: 8 additions & 3 deletions tools/tr1/config/TR1X_ConfigTool/Resources/Lang/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@
"full_no_ambient": "Completa ma senza suoni ambientali",
"quiet_no_ambient": "Attenuata ma senza suoni ambientali",
"none": "Assente"
}
},
"music_load_condition": {
"never": "Mai",
"non-ambient": "Non ambientale",
"always": "Sempre"
}
},
"Properties": {
"enable_tr3_sidesteps": {
Expand Down Expand Up @@ -331,9 +336,9 @@
"Title": "Formato screenshot",
"Description": "Formato del file da utilizzare per gli screenshot."
},
"load_current_music": {
"music_load_condition": {
"Title": "Carica la traccia musicale",
"Description": "Carica la traccia musicale che era in riproduzione al momento del salvataggio della partita."
"Description": "Carica la traccia musicale che era in riproduzione al momento del salvataggio della partita.\n- Mai: non ripristina le tracce musicali durante il caricamento.\n- Non ambientale: ripristina solo le tracce musicali non ambientali durante il caricamento.\n- Sempre: ripristina qualsiasi tipo di traccia musicale durante il caricamento."
},
"load_music_triggers": {
"Title": "Ricorda la musica riprodotta",
Expand Down
12 changes: 9 additions & 3 deletions tools/tr1/config/TR1X_ConfigTool/Resources/specification.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@
"full_no_ambient",
"quiet_no_ambient",
"none"
],
"music_load_condition": [
"never",
"non-ambient",
"always"
]
},
"CategorisedProperties": [
Expand Down Expand Up @@ -439,9 +444,10 @@
"Image": "Graphics/graphic6.jpg",
"Properties": [
{
"Field": "load_current_music",
"DataType": "Bool",
"DefaultValue": true
"Field": "music_load_condition",
"DataType": "Enum",
"EnumKey": "music_load_condition",
"DefaultValue": "non-ambient"
},
{
"Field": "load_music_triggers",
Expand Down

0 comments on commit fec71a2

Please sign in to comment.