fixup failing music callback - don't let music play failure spam the event queue
This commit is contained in:
parent
4a5a9dbf67
commit
76dc64d3a5
2 changed files with 16 additions and 2 deletions
src/sound
|
@ -63,11 +63,18 @@ bool CallbackMusic; /// flag true callback ccl if stops
|
|||
*/
|
||||
static void MusicFinishedCallback()
|
||||
{
|
||||
static long MusicCallbackDebounce = 0;
|
||||
long ticks = SDL_GetTicks();
|
||||
if (MusicCallbackDebounce + 1000 < ticks) {
|
||||
// only accept music finished callbacks for music playing longer than 1s
|
||||
return;
|
||||
}
|
||||
MusicCallbackDebounce = ticks;
|
||||
SDL_Event event;
|
||||
SDL_zero(event);
|
||||
event.type = SDL_SOUND_FINISHED;
|
||||
event.user.code = 1;
|
||||
event.user.data1 = CheckMusicFinished;
|
||||
event.user.data1 = (void*) CheckMusicFinished;
|
||||
SDL_PeepEvents(&event, 1, SDL_ADDEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT);
|
||||
}
|
||||
|
||||
|
|
|
@ -269,16 +269,23 @@ bool UnitSoundIsPlaying(Origin *origin)
|
|||
*/
|
||||
static void ChannelFinished(int channel)
|
||||
{
|
||||
static long ChannelCallbackDebounce[MaxChannels] = {0};
|
||||
if (channel < 0 || channel >= MaxChannels) {
|
||||
fprintf(stderr, "ERROR: Out of bounds channel (how?)\n");
|
||||
return;
|
||||
}
|
||||
long ticks = SDL_GetTicks();
|
||||
if (ChannelCallbackDebounce[channel] + 200 < ticks) {
|
||||
// only accept sound finished callbacks for sounds playing longer than 0.2s
|
||||
return;
|
||||
}
|
||||
ChannelCallbackDebounce[channel] = ticks;
|
||||
if (Channels[channel].FinishedCallback != NULL) {
|
||||
SDL_Event event;
|
||||
SDL_zero(event);
|
||||
event.type = SDL_SOUND_FINISHED;
|
||||
event.user.code = channel;
|
||||
event.user.data1 = Channels[channel].FinishedCallback;
|
||||
event.user.data1 = (void*) Channels[channel].FinishedCallback;
|
||||
SDL_PeepEvents(&event, 1, SDL_ADDEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT);
|
||||
}
|
||||
delete Channels[channel].Unit;
|
||||
|
|
Loading…
Add table
Reference in a new issue