Trying to prevent audio mute from endlessly spamming. Untested.
authornemo
Tue, 05 Feb 2013 17:28:12 -0500
changeset 8471 7681d14b9f01
parent 8470 01ddeb241c21
child 8472 da6b569ac930
Trying to prevent audio mute from endlessly spamming. Untested.
hedgewars/uGame.pas
hedgewars/uSound.pas
hedgewars/uWorld.pas
--- a/hedgewars/uGame.pas	Sat Feb 02 14:33:35 2013 +0100
+++ b/hedgewars/uGame.pas	Tue Feb 05 17:28:12 2013 -0500
@@ -26,12 +26,13 @@
 ////////////////////
     implementation
 ////////////////////
-uses uInputHandler, uTeams, uIO, uAI, uGears, uSound, 
+uses uInputHandler, uTeams, uIO, uAI, uGears, uSound, uLocale, uCaptions,
     uVisualGears, uTypes, uVariables, uCommands, uConsts
     {$IFDEF USE_TOUCH_INTERFACE}, uTouch{$ENDIF};
 
 procedure DoGameTick(Lag: LongInt);
-var i: LongInt;
+var i,j : LongInt;
+    s: shortstring;
 begin
 if isPaused then
     exit;
@@ -61,6 +62,23 @@
         else if cOnlyStats then
             Lag:= High(LongInt)
     end;
+inc(SoundTimerTicks, Lag);
+if SoundTimerTicks >= 50 then
+    begin
+    SoundTimerTicks:= 0;
+    if cVolumeDelta <> 0 then
+        begin
+        j:= Volume;
+        i:= ChangeVolume(cVolumeDelta);
+        if isAudioMuted and (j<>i) then
+            AddCaption(trmsg[sidMute], cWhiteColor, capgrpVolume)
+        else if not isAudioMuted then
+            begin
+            str(i, s);
+            AddCaption(Format(trmsg[sidVolume], s), cWhiteColor, capgrpVolume)
+            end
+        end;
+    end;
 PlayNextVoice;
 i:= 1;
 while (GameState <> gsExit) and (i <= Lag) do
--- a/hedgewars/uSound.pas	Sat Feb 02 14:33:35 2013 +0100
+++ b/hedgewars/uSound.pas	Tue Feb 05 17:28:12 2013 -0500
@@ -105,12 +105,13 @@
 function  AskForVoicepack(name: shortstring): Pointer;
 
 
+var Volume: LongInt;
+    SoundTimerTicks: Longword;
 implementation
 uses uVariables, uConsole, uCommands, uDebug, uPhysFSLayer;
 
 const chanTPU = 32;
-var Volume: LongInt;
-    cInitVolume: LongInt;
+var cInitVolume: LongInt;
     previousVolume: LongInt; // cached volume value
     lastChan: array [TSound] of LongInt;
     voicepacks: array[0..cMaxTeams] of TVoicepack;
@@ -712,6 +713,7 @@
     isAudioMuted:= false;
     isSEBackup:= isSoundEnabled;
     Volume:= 0;
+    SoundTimerTicks:= 0;
     defVoicepack:= AskForVoicepack('Default');
 
     for i:= Low(TSound) to High(TSound) do
--- a/hedgewars/uWorld.pas	Sat Feb 02 14:33:35 2013 +0100
+++ b/hedgewars/uWorld.pas	Tue Feb 05 17:28:12 2013 -0500
@@ -74,7 +74,6 @@
     timeTexture: PTexture;
     FPS: Longword;
     CountTicks: Longword;
-    SoundTimerTicks: Longword;
     prevPoint, prevTargetPoint: TPoint;
     amSel: TAmmoType = amNothing;
     missionTex: PTexture;
@@ -1514,22 +1513,8 @@
         if fpsTexture <> nil then
             DrawTexture((cScreenWidth shr 1) - 60 - offsetY, offsetX, fpsTexture);
         end;
-
-    // lag warning (?)
-    inc(SoundTimerTicks, Lag);
 end;
 
-if SoundTimerTicks >= 50 then
-begin
-    SoundTimerTicks:= 0;
-    if cVolumeDelta <> 0 then
-    begin
-        str(ChangeVolume(cVolumeDelta), s);
-        AddCaption(Format(trmsg[sidVolume], s), cWhiteColor, capgrpVolume);
-    end;
-    if isAudioMuted then
-        AddCaption(trmsg[sidMute], cWhiteColor, capgrpVolume)
-end;
 
 if GameState = gsConfirm then
     DrawTextureCentered(0, (cScreenHeight shr 1), ConfirmTexture);