Make it possible to repeat a sound played with [sound] using repeat=.
Fix a bug with sound playing endlessly when fade is used.
This commit is contained in:
parent
79fb29a9a5
commit
e1701913da
3 changed files with 12 additions and 10 deletions
|
@ -629,8 +629,9 @@ bool event_handler::handle_event_command(const queued_event& event_info,
|
|||
|
||||
else if(cmd == "sound") {
|
||||
std::string sound = cfg["name"];
|
||||
const int repeats = lexical_cast_default<int>(cfg["repeat"], 0);
|
||||
assert(state_of_game != NULL);
|
||||
sound::play_sound(sound);
|
||||
sound::play_sound(sound, sound::SOUND_FX, repeats);
|
||||
}
|
||||
|
||||
else if(cmd == "colour_adjust") {
|
||||
|
|
|
@ -41,7 +41,7 @@ std::vector<Mix_Chunk*> channel_chunks;
|
|||
// is playing on a channel for fading/panning)
|
||||
std::vector<int> channel_ids;
|
||||
|
||||
static bool play_sound_internal(const std::string& files, channel_group group, bool sound_on,
|
||||
static bool play_sound_internal(const std::string& files, channel_group group, bool sound_on, unsigned int repeats=0,
|
||||
unsigned int distance=0, int id=-1, int loop_ticks=0, int fadein_ticks=0);
|
||||
}
|
||||
|
||||
|
@ -695,10 +695,11 @@ void stop_sound(int id)
|
|||
|
||||
void play_sound_positioned(const std::string &files, int id, unsigned int distance)
|
||||
{
|
||||
play_sound_internal(files, SOUND_SOURCES, preferences::sound_on(), distance, id);
|
||||
play_sound_internal(files, SOUND_SOURCES, preferences::sound_on(), 0, distance, id);
|
||||
}
|
||||
|
||||
bool play_sound_internal(const std::string& files, channel_group group, bool sound_on, unsigned int distance, int id, int loop_ticks, int fadein_ticks)
|
||||
bool play_sound_internal(const std::string& files, channel_group group, bool sound_on, unsigned int repeats,
|
||||
unsigned int distance, int id, int loop_ticks, int fadein_ticks)
|
||||
{
|
||||
if(files.empty() || distance >= DISTANCE_SILENT || !sound_on || !mix_ok) {
|
||||
return false;
|
||||
|
@ -773,9 +774,9 @@ bool play_sound_internal(const std::string& files, channel_group group, bool sou
|
|||
}
|
||||
} else {
|
||||
if(fadein_ticks > 0) {
|
||||
res = Mix_FadeInChannel(channel, it->get_data(), -1, fadein_ticks);
|
||||
res = Mix_FadeInChannel(channel, it->get_data(), repeats, fadein_ticks);
|
||||
} else {
|
||||
res = Mix_PlayChannel(channel, it->get_data(), 0);
|
||||
res = Mix_PlayChannel(channel, it->get_data(), repeats);
|
||||
}
|
||||
}
|
||||
if(res < 0) {
|
||||
|
@ -789,9 +790,9 @@ bool play_sound_internal(const std::string& files, channel_group group, bool sou
|
|||
return true;
|
||||
}
|
||||
|
||||
void play_sound(const std::string& files, channel_group group)
|
||||
void play_sound(const std::string& files, channel_group group, unsigned int repeats)
|
||||
{
|
||||
play_sound_internal(files, group, preferences::sound_on());
|
||||
play_sound_internal(files, group, preferences::sound_on(), repeats);
|
||||
}
|
||||
|
||||
// Play bell with separate volume setting
|
||||
|
@ -803,7 +804,7 @@ void play_bell(const std::string& files)
|
|||
// Play timer with separate volume setting
|
||||
void play_timer(const std::string& files, int loop_ticks, int fadein_ticks)
|
||||
{
|
||||
play_sound_internal(files, SOUND_TIMER, true, 0, -1, loop_ticks, fadein_ticks);
|
||||
play_sound_internal(files, SOUND_TIMER, true, 0, 0, -1, loop_ticks, fadein_ticks);
|
||||
}
|
||||
|
||||
// Play UI sounds on separate volume than soundfx
|
||||
|
|
|
@ -63,7 +63,7 @@ bool is_sound_playing(int id);
|
|||
void stop_sound(int id);
|
||||
|
||||
// Play sound, or random one of comma-separated sounds.
|
||||
void play_sound(const std::string& files, channel_group group = SOUND_FX);
|
||||
void play_sound(const std::string& files, channel_group group = SOUND_FX, unsigned int repeats = 0);
|
||||
|
||||
// Play sound, or random one of comma-separated sounds. Use specified
|
||||
// distance and associate it with specified id (of a sound source).
|
||||
|
|
Loading…
Add table
Reference in a new issue