Engine:
authorsmxx
Wed, 31 Mar 2010 10:59:30 +0000
changeset 3201 400c98815100
parent 3200 cb0b37553eac
child 3202 b470d7875f23
Engine: * Enable uSound to not play a sound if it's already/still playing
hedgewars/uSound.pas
--- a/hedgewars/uSound.pas	Wed Mar 31 02:33:05 2010 +0000
+++ b/hedgewars/uSound.pas	Wed Mar 31 10:59:30 2010 +0000
@@ -38,6 +38,7 @@
 procedure SoundLoad;
 procedure PlaySound(snd: TSound);
 procedure PlaySound(snd: TSound; voicepack: PVoicepack);
+procedure PlaySound(snd: TSound; voicepack: PVoicepack; keepPlaying: boolean);
 function LoopSound(snd: TSound): LongInt;
 function LoopSound(snd: TSound; voicepack: PVoicepack): LongInt;
 procedure PlayMusic;
@@ -162,13 +163,21 @@
 
 procedure PlaySound(snd: TSound);
 begin
-    PlaySound(snd, nil);
+    PlaySound(snd, nil, false);
 end;
 
 procedure PlaySound(snd: TSound; voicepack: PVoicepack);
 begin
+    PlaySound(snd, voicepack, false);
+end;
+
+procedure PlaySound(snd: TSound; voicepack: PVoicepack; keepPlaying: boolean);
+begin
 if (not isSoundEnabled) or fastUntilLag then exit;
 
+if keepPlaying and (lastChan[snd] <> -1) and (Mix_Playing(lastChan[snd]) <> 0) then
+    exit;
+
 if (voicepack <> nil) and (voicepack^.chunks[snd] <> nil) then
     lastChan[snd]:= Mix_PlayChannelTimed(-1, voicepack^.chunks[snd], 0, -1)
 else