Skip to content

Commit

Permalink
Fix #2602: music doesn't change immediately on loading a save
Browse files Browse the repository at this point in the history
This time I added an option to disable the feature to allow the currently
playing track to finish when changing the playlist. This allows more
fine-grained control of distinct use cases.

In wesnoth.cpp:do_gameloop(), I reversed the order of the title screen
music and default music because otherwise adding the default music would
enable play_once for the title screen music and prevent instant music
change when the player loads a save. I play title screen music with
immediate=yes, so it's still played first.
  • Loading branch information
jyrkive committed Jun 5, 2018
1 parent cafede4 commit 91afbfd
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/playsingle_controller.cpp
Expand Up @@ -222,7 +222,7 @@ LEVEL_RESULT playsingle_controller::play_scenario(const config& level)

// Start music.
for(const config &m : level.child_range("music")) {
sound::play_music_config(m);
sound::play_music_config(m, true);
}
sound::commit_music_changes();

Expand Down
4 changes: 2 additions & 2 deletions src/scripting/lua_audio.cpp
Expand Up @@ -137,7 +137,7 @@ static int impl_music_set(lua_State* L) {
// Remove the track at that index and add the new one in its place
// It's a little inefficient though...
sound::remove_track(i);
sound::play_music_config(cfg, i);
sound::play_music_config(cfg, false, i);
}
} else {
lua_music_track& track = *get_track(L, 3);
Expand Down Expand Up @@ -206,7 +206,7 @@ static int intf_music_add(lua_State* L) {
return luaL_argerror(L, i, "unrecognized argument");
}
}
sound::play_music_config(cfg, index);
sound::play_music_config(cfg, false, index);
return 0;
}

Expand Down
5 changes: 3 additions & 2 deletions src/sound.cpp
Expand Up @@ -663,7 +663,7 @@ void play_music_repeatedly(const std::string& id)
last_track.reset();
}

void play_music_config(const config& music_node, int i)
void play_music_config(const config& music_node, bool allow_interrupt_current_track, int i)
{
//
// FIXME: there is a memory leak somewhere in this function, seemingly related to the shared_ptrs
Expand Down Expand Up @@ -720,7 +720,8 @@ void play_music_config(const config& music_node, int i)
current_track = *iter;
current_track_index = iter - current_track_list.begin();
play_music();
} else if(!track.append() && current_track) { // Make sure the current track is finished
} else if(!track.append() && !allow_interrupt_current_track && current_track) {
// Make sure the current track will finish first
current_track->set_play_once(true);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/sound.hpp
Expand Up @@ -43,7 +43,7 @@ void stop_UI_sound();
void stop_bell();

// Read config entry, alter track list accordingly.
void play_music_config(const config &music_node, int i = -1);
void play_music_config(const config &music_node, bool allow_interrupt_current_track = false, int i = -1);
// Act on any track list changes from above.
void commit_music_changes();

Expand Down
8 changes: 5 additions & 3 deletions src/wesnoth.cpp
Expand Up @@ -744,13 +744,15 @@ static int do_gameloop(const std::vector<std::string>& args)
if(!game->is_loading()) {
const config& cfg = config_manager.game_config().child("titlescreen_music");
if(cfg) {
sound::play_music_repeatedly(game_config::title_music);

for(const config& i : cfg.child_range("music")) {
sound::play_music_config(i);
}

sound::commit_music_changes();
config title_music_config;
title_music_config["name"] = game_config::title_music;
title_music_config["append"] = true;
title_music_config["immediate"] = true;
sound::play_music_config(title_music_config);
} else {
sound::empty_playlist();
sound::stop_music();
Expand Down

0 comments on commit 91afbfd

Please sign in to comment.