From e010d437637da49a4b9338dbe1b471ec2242730b Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Tue, 24 Mar 2015 20:42:20 +0000 Subject: [PATCH] Add load and save audio options. Fix all sounds not pausing --- src/addresses.h | 1 + src/audio/audio.c | 36 ++++++++++++++++++++++++++++++++---- src/audio/audio.h | 5 +---- src/config.c | 2 ++ src/config.h | 2 ++ src/windows/options.c | 13 ++++++++----- 6 files changed, 46 insertions(+), 13 deletions(-) diff --git a/src/addresses.h b/src/addresses.h index 94ab6853b4..9148002e12 100644 --- a/src/addresses.h +++ b/src/addresses.h @@ -67,6 +67,7 @@ #define RCT2_ADDRESS_DSOUND_GUID 0x009AAC5D #define RCT2_ADDRESS_CONFIG_SOUND_SW_BUFFER 0x009AAC6E +// When all sounds reversed replace with gConfigSound.ride_music #define RCT2_ADDRESS_CONFIG_MUSIC 0x009AAC72 #define RCT2_ADDRESS_CONFIG_FLAGS 0x009AAC74 diff --git a/src/audio/audio.c b/src/audio/audio.c index b8f0af5a9c..de5413da31 100644 --- a/src/audio/audio.c +++ b/src/audio/audio.c @@ -1768,6 +1768,18 @@ void audio_init2(int device) RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_FLAGS, uint8) |= 1 << 4; config_save_default(); } + + // When all sound code is reversed this can be removed. + if (!gConfigSound.sound){ + toggle_all_sounds(); + } + + // When all sound code is reversed this can be removed. + if (!gConfigSound.ride_music){ + RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_MUSIC, uint8) ^= 1; + if (RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_MUSIC, uint8) == 0) + stop_ride_music(); + } } /** @@ -1794,19 +1806,34 @@ void audio_close() } } +/* rct2: 0x006BAB8A */ +void toggle_all_sounds(){ + // When all sound code is reversed replace with gConfigSound.sound + RCT2_GLOBAL(0x009AF59D, uint8) ^= 1; + if (RCT2_GLOBAL(0x009AF59D, uint8) == 0) { + stop_title_music(); + pause_sounds(); + } + else{ + unpause_sounds(); + } +} + /** * * rct2: 0x006BABB4 */ void pause_sounds() { - if (++RCT2_GLOBAL(0x009AF59C, uint8) == 1) { + // When all sound code is reversed replace with gConfigSound.sound + RCT2_GLOBAL(0x009AF59C, uint8) = 1; + if (RCT2_GLOBAL(0x009AF59C, uint8) == 1) { stop_other_sounds(); stop_vehicle_sounds(); stop_ride_music(); stop_crowd_sound(); } - g_sounds_disabled = 1; + gConfigSound.sound = 0; } /** @@ -1815,8 +1842,9 @@ void pause_sounds() */ void unpause_sounds() { - RCT2_GLOBAL(0x009AF59C, uint8)--; - g_sounds_disabled = 0; + // When all sound code is reversed replace with gConfigSound.sound + RCT2_GLOBAL(0x009AF59C, uint8) = 0; + gConfigSound.sound = 1; } /** diff --git a/src/audio/audio.h b/src/audio/audio.h index 3c2621afa9..3bea50adfd 100644 --- a/src/audio/audio.h +++ b/src/audio/audio.h @@ -218,13 +218,10 @@ void audio_init1(); void audio_init2(int device); void audio_close(); void pause_sounds(); +void toggle_all_sounds(); void unpause_sounds(); void stop_vehicle_sounds(); -// 0x009AF59C probably does the same job -// once it's confirmed and calls in pause_sounds() are reversed, it can be used instead of this -int g_sounds_disabled; - typedef enum { SOUND_LIFT_1 = 0, SOUND_TRACK_FRICTION_1 = 1, diff --git a/src/config.c b/src/config.c index c8b4b6e515..060a4501dd 100644 --- a/src/config.c +++ b/src/config.c @@ -172,6 +172,8 @@ config_property_definition _soundDefinitions[] = { { offsetof(sound_configuration, forced_software_buffering), "forced_software_buffering", CONFIG_VALUE_TYPE_BOOLEAN, false, NULL }, { offsetof(sound_configuration, sound_quality), "sound_quality", CONFIG_VALUE_TYPE_UINT8, 2, NULL }, { offsetof(sound_configuration, title_music), "title_music", CONFIG_VALUE_TYPE_UINT8, 2, NULL }, + { offsetof(sound_configuration, sound), "sound", CONFIG_VALUE_TYPE_BOOLEAN, true, NULL }, + { offsetof(sound_configuration, ride_music), "ride_music", CONFIG_VALUE_TYPE_BOOLEAN, true, NULL }, }; config_section_definition _sectionDefinitions[] = { diff --git a/src/config.h b/src/config.h index 5c3302a022..7dfb68c5af 100644 --- a/src/config.h +++ b/src/config.h @@ -141,6 +141,8 @@ typedef struct { sint8 forced_software_buffering; sint8 sound_quality; uint8 title_music; + uint8 sound; + uint8 ride_music; } sound_configuration; typedef struct { diff --git a/src/windows/options.c b/src/windows/options.c index 832ce790c6..a7dac9f9f8 100644 --- a/src/windows/options.c +++ b/src/windows/options.c @@ -345,14 +345,17 @@ static void window_options_mouseup() window_invalidate(w); break; case WIDX_SOUND_CHECKBOX: - if (g_sounds_disabled) - unpause_sounds(); - else - pause_sounds(); + toggle_all_sounds(); + config_save_default(); window_invalidate(w); break; case WIDX_MUSIC_CHECKBOX: RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_MUSIC, uint8) ^= 1; + if (RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_MUSIC, uint8) == 0) + stop_ride_music(); + + gConfigSound.ride_music ^= 1; + config_save_default(); window_invalidate(w); break; } @@ -730,7 +733,7 @@ static void window_options_invalidate() // sound quality: low/medium/high RCT2_GLOBAL(0x013CE952 + 10, uint16) = STR_SOUND_LOW + gConfigSound.sound_quality; - widget_set_checkbox_value(w, WIDX_SOUND_CHECKBOX, !g_sounds_disabled); + widget_set_checkbox_value(w, WIDX_SOUND_CHECKBOX, gConfigSound.sound); widget_set_checkbox_value(w, WIDX_MUSIC_CHECKBOX, RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_MUSIC, uint8)); window_options_widgets[WIDX_SOUND].type = WWT_DROPDOWN;