Save playlist in snapshot:
fixes https://gna.org/bugs/index.php?func=detailitem&item_id=5108 Also commit changes on loading level, so new music starts immediately.
This commit is contained in:
parent
d0c9df6c17
commit
1624d28e0d
4 changed files with 30 additions and 0 deletions
|
@ -269,6 +269,7 @@ LEVEL_RESULT play_level(const game_data& gameinfo, const config& game_config,
|
|||
for (i = m.begin(); i != m.end(); i++) {
|
||||
sound::play_music_config(**i);
|
||||
}
|
||||
sound::commit_music_changes();
|
||||
} else {
|
||||
const std::string& music = lvl["music"];
|
||||
if(music != "") {
|
||||
|
|
|
@ -1806,6 +1806,8 @@ void turn_info::write_game_snapshot(config& start) const
|
|||
start.add_child("terrain_graphics", **tg);
|
||||
}
|
||||
|
||||
sound::write_music_play_list(start);
|
||||
|
||||
write_game(state_of_game_,start /*,WRITE_SNAPSHOT_ONLY*/);
|
||||
|
||||
// Clobber gold values to make sure the snapshot uses the values
|
||||
|
|
|
@ -43,6 +43,8 @@ struct music_track
|
|||
music_track(const std::string &tname,
|
||||
const std::string &ms_before_str,
|
||||
const std::string &ms_after_str);
|
||||
void write(config &snapshot, bool append);
|
||||
|
||||
std::string name;
|
||||
unsigned int ms_before, ms_after;
|
||||
bool once;
|
||||
|
@ -68,6 +70,16 @@ music_track::music_track(const std::string &tname,
|
|||
ms_after = lexical_cast<int,std::string>(ms_after_str);
|
||||
}
|
||||
|
||||
void music_track::write(config &snapshot, bool append)
|
||||
{
|
||||
config& m = snapshot.add_child("music");
|
||||
m["name"] = name;
|
||||
m["ms_before"] = lexical_cast<std::string>(ms_before);
|
||||
m["ms_after"] = lexical_cast<std::string>(ms_after);
|
||||
if (append)
|
||||
m["append"] = "yes";
|
||||
}
|
||||
|
||||
std::vector<music_track> current_track_list;
|
||||
struct music_track current_track("");
|
||||
|
||||
|
@ -284,6 +296,18 @@ void commit_music_changes()
|
|||
play_music();
|
||||
}
|
||||
|
||||
void write_music_play_list(config& snapshot)
|
||||
{
|
||||
std::vector<music_track>::iterator i;
|
||||
bool append = false;
|
||||
|
||||
// First entry clears playlist, others append to it.
|
||||
for (i = current_track_list.begin(); i != current_track_list.end(); i++) {
|
||||
i->write(snapshot, append);
|
||||
append = true;
|
||||
}
|
||||
}
|
||||
|
||||
void play_sound(const std::string& file)
|
||||
{
|
||||
if(preferences::sound_on() && mix_ok) {
|
||||
|
|
|
@ -47,6 +47,9 @@ void play_sound(const std::string& file);
|
|||
// Called from event loop to see if we need new music track.
|
||||
void think_about_music(void);
|
||||
|
||||
// Save music playlist for snapshot
|
||||
void write_music_play_list(config& snapshot);
|
||||
|
||||
void set_music_volume(int vol);
|
||||
void set_sound_volume(int vol);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue