1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-15 11:03:00 +01:00

Fix #4522: Theme music doesn't stop when connected to paused server

Refactor audio initialisation and stop all music and sounds when the screen mode changes.
This commit is contained in:
Ted John
2016-10-03 18:14:34 +01:00
parent 744bc05906
commit 862b715003
9 changed files with 44 additions and 29 deletions

View File

@@ -121,11 +121,22 @@ void audio_stop_channel(void **channel);
void audio_init()
{
int result = SDL_Init(SDL_INIT_AUDIO);
if (result >= 0)
if (result < 0) {
log_error("SDL_Init %s", SDL_GetError());
return;
}
log_fatal("SDL_Init %s", SDL_GetError());
exit(-1);
if (str_is_null_or_empty(gConfigSound.device)) {
Mixer_Init(NULL);
gAudioCurrentDevice = 0;
} else {
Mixer_Init(gConfigSound.device);
for (int i = 0; i < gAudioDeviceCount; i++) {
if (strcmp(gAudioDevices[i].name, gConfigSound.device) == 0) {
gAudioCurrentDevice = i;
}
}
}
}
void audio_quit()
@@ -296,6 +307,15 @@ void audio_stop_ride_music()
}
}
void audio_stop_all_music_and_sounds()
{
audio_stop_title_music();
audio_stop_vehicle_sounds();
audio_stop_ride_music();
audio_stop_crowd_sound();
audio_stop_rain_sound();
}
void audio_stop_crowd_sound()
{
audio_stop_channel(&gCrowdSoundChannel);

View File

@@ -281,4 +281,6 @@ void audio_toggle_all_sounds();
*/
void audio_unpause_sounds();
void audio_stop_all_music_and_sounds();
#endif

View File

@@ -84,8 +84,7 @@ void editor_load()
{
rct_window *mainWindow;
audio_pause_sounds();
audio_unpause_sounds();
audio_stop_all_music_and_sounds();
object_manager_unload_all_objects();
object_list_load();
map_init(150);
@@ -168,6 +167,7 @@ void trackdesigner_load()
{
rct_window *mainWindow;
audio_stop_all_music_and_sounds();
gScreenFlags = SCREEN_FLAGS_TRACK_DESIGNER;
gScreenAge = 0;
@@ -207,6 +207,7 @@ void trackmanager_load()
{
rct_window *mainWindow;
audio_stop_all_music_and_sounds();
gScreenFlags = SCREEN_FLAGS_TRACK_MANAGER;
gScreenAge = 0;

View File

@@ -289,7 +289,6 @@ void game_update()
// Update the game one or more times
for (i = 0; i < numUpdates; i++) {
game_logic_update();
audio_start_title_music();
if (gGameSpeed > 1)
continue;
@@ -853,6 +852,7 @@ void game_load_init()
rct_window *mainWindow;
gScreenFlags = SCREEN_FLAGS_PLAYING;
audio_stop_all_music_and_sounds();
viewport_init_all();
game_create_windows();
mainWindow = window_get_main();

View File

@@ -233,6 +233,13 @@ bool openrct2_initialise()
// return false;
// }
if (!rct2_init_directories()) {
return false;
}
if (!rct2_startup_checks()) {
return false;
}
if (!gOpenRCT2Headless) {
audio_init();
audio_populate_devices();
@@ -260,20 +267,6 @@ bool openrct2_initialise()
chat_init();
openrct2_copy_original_user_files_over();
// TODO move to audio initialise function
if (str_is_null_or_empty(gConfigSound.device)) {
Mixer_Init(NULL);
gAudioCurrentDevice = 0;
} else {
Mixer_Init(gConfigSound.device);
for (int i = 0; i < gAudioDeviceCount; i++) {
if (strcmp(gAudioDevices[i].name, gConfigSound.device) == 0) {
gAudioCurrentDevice = i;
}
}
}
return true;
}

View File

@@ -151,11 +151,6 @@ bool rct2_init()
gScenarioTicks = 0;
util_srand((unsigned int)time(0));
if (!rct2_init_directories())
return false;
if (!rct2_startup_checks())
return false;
config_reset_shortcut_keys();
config_shortcut_keys_load();

View File

@@ -288,6 +288,8 @@ extern char gRCT2AddressObjectDataPath[];
extern char gRCT2AddressTracksPath[];
bool rct2_init();
int rct2_init_directories();
int rct2_startup_checks();
void rct2_dispose();
void rct2_update();
void substitute_path(char *dest, const char *path, const char *filename);

View File

@@ -14,6 +14,7 @@
*****************************************************************************/
#pragma endregion
#include "audio/audio.h"
#include "cheats.h"
#include "config.h"
#include "game.h"
@@ -150,7 +151,10 @@ void scenario_begin()
{
rct_window *mainWindow;
audio_stop_title_music();
gScreenFlags = SCREEN_FLAGS_PLAYING;
audio_stop_all_music_and_sounds();
viewport_init_all();
game_create_windows();
mainWindow = window_get_main();

View File

@@ -125,15 +125,14 @@ void title_load()
window_staff_list_init_vars();
map_update_tile_pointers();
reset_sprite_spatial_index();
audio_stop_ride_music();
audio_stop_crowd_sound();
//stop_other_sounds();
audio_stop_all_music_and_sounds();
viewport_init_all();
news_item_init_queue();
window_main_open();
title_create_windows();
title_init_showcase();
gfx_invalidate_screen();
audio_start_title_music();
gScreenAge = 0;
if (gOpenRCT2ShowChangelog) {
@@ -529,7 +528,6 @@ void title_update()
for (i = 0; i < numUpdates; i++) {
game_logic_update();
}
audio_start_title_music();
}
gInputFlags &= ~INPUT_FLAG_VIEWPORT_SCROLLING;