Fix precise volume change being a bit buggy
authorWuzzy <Wuzzy2@mail.ru>
Tue, 05 Feb 2019 03:39:03 +0100
changeset 14686 bd43e703608b
parent 14685 d74517fdb34f
child 14687 204fb862d0e4
Fix precise volume change being a bit buggy
hedgewars/uCommandHandlers.pas
hedgewars/uVariables.pas
--- a/hedgewars/uCommandHandlers.pas	Tue Feb 05 03:09:50 2019 +0100
+++ b/hedgewars/uCommandHandlers.pas	Tue Feb 05 03:39:03 2019 +0100
@@ -33,6 +33,23 @@
 var cTagsMasks : array[0..15] of byte = (7, 0, 0, 0, 0, 4, 5, 6, 15, 8, 8, 8, 8, 12, 13, 14);
     cTagsMasksNoHealth: array[0..15] of byte = (3, 0, 1, 2, 0, 0, 0, 0, 11, 8, 9, 10, 8, 8, 8, 8);
 
+// helper function for volume
+procedure updateVolumeDelta(precise: boolean);
+begin
+if cVolumeUpKey and (not cVolumeDownKey) then
+    if precise then
+        cVolumeDelta:= 1
+    else
+        cVolumeDelta:= 3
+else if cVolumeDownKey and (not cVolumeUpKey) then
+    if precise then
+        cVolumeDelta:= -1
+    else
+        cVolumeDelta:= -3
+else
+    cVolumeDelta:= 0;
+end;
+
 procedure chGenCmd(var s: shortstring);
 begin
 case s[1] of
@@ -277,6 +294,7 @@
 procedure chPrecise_p(var s: shortstring);
 begin
 s:= s; // avoid compiler hint
+updateVolumeDelta(true);
 if CheckNoTeamOrHH then
     exit;
 if not isExternalSource then
@@ -285,15 +303,12 @@
 with CurrentHedgehog^.Gear^ do
     Message:= Message or (gmPrecise and InputMask);
     ScriptCall('onPrecise');
-if cVolumeDelta > 0 then
-    cVolumeDelta:= 1;
-if cVolumeDelta < 0 then
-    cVolumeDelta:= -1;
 end;
 
 procedure chPrecise_m(var s: shortstring);
 begin
 s:= s; // avoid compiler hint
+updateVolumeDelta(false);
 if CheckNoTeamOrHH then
     exit;
 if not isExternalSource then
@@ -301,10 +316,6 @@
 with CurrentHedgehog^.Gear^ do
     Message:= Message and (not (gmPrecise and InputMask));
     ScriptCall('onPreciseUp');
-if cVolumeDelta > 0 then
-    cVolumeDelta:= 3;
-if cVolumeDelta < 0 then
-    cVolumeDelta:= -3;
 end;
 
 procedure chLJump(var s: shortstring);
@@ -600,22 +611,32 @@
     end
 end;
 
-procedure chVol_p(var s: shortstring);
+procedure chVolUp_p(var s: shortstring);
+begin
+s:= s; // avoid compiler hint
+cVolumeUpKey:= true;
+updateVolumeDelta((LocalMessage and gmPrecise) <> 0);
+end;
+
+procedure chVolUp_m(var s: shortstring);
 begin
 s:= s; // avoid compiler hint
-if (LocalMessage and gmPrecise) <> 0 then
-    inc(cVolumeDelta, 1)
-else
-    inc(cVolumeDelta, 3);
+cVolumeUpKey:= false;
+updateVolumeDelta((LocalMessage and gmPrecise) <> 0);
 end;
 
-procedure chVol_m(var s: shortstring);
+procedure chVolDown_p(var s: shortstring);
 begin
 s:= s; // avoid compiler hint
-if (LocalMessage and gmPrecise) <> 0 then
-    dec(cVolumeDelta, 1)
-else
-    dec(cVolumeDelta, 3);
+cVolumeDownKey:= true;
+updateVolumeDelta((LocalMessage and gmPrecise) <> 0);
+end;
+
+procedure chVolDown_m(var s: shortstring);
+begin
+s:= s; // avoid compiler hint
+cVolumeDownKey:= false;
+updateVolumeDelta((LocalMessage and gmPrecise) <> 0);
 end;
 
 procedure chMute(var s: shortstring);
@@ -988,10 +1009,10 @@
     RegisterVariable('timer'   , @chTimer        , false, true);
     RegisterVariable('taunt'   , @chTaunt        , false);
     RegisterVariable('put'     , @chPut          , false);
-    RegisterVariable('+volup'  , @chVol_p        , true );
-    RegisterVariable('-volup'  , @chVol_m        , true );
-    RegisterVariable('+voldown', @chVol_m        , true );
-    RegisterVariable('-voldown', @chVol_p        , true );
+    RegisterVariable('+volup'  , @chVolUp_p      , true );
+    RegisterVariable('-volup'  , @chVolUp_m      , true );
+    RegisterVariable('+voldown', @chVolDown_p    , true );
+    RegisterVariable('-voldown', @chVolDown_m    , true );
     RegisterVariable('mute'    , @chMute         , true );
     RegisterVariable('findhh'  , @chFindhh       , true );
     RegisterVariable('pause'   , @chPause        , true );
--- a/hedgewars/uVariables.pas	Tue Feb 05 03:09:50 2019 +0100
+++ b/hedgewars/uVariables.pas	Tue Feb 05 03:39:03 2019 +0100
@@ -179,6 +179,8 @@
     cSeed           : shortstring;
     cIsSoundEnabled : boolean; // If the sound system is enabled
     cVolumeDelta    : LongInt;
+    cVolumeUpKey    : boolean;
+    cVolumeDownKey  : boolean;
     cMuteToggle     : boolean; // Mute toggle requested
     cHasFocus       : boolean;
     cInactDelay     : Longword;
@@ -2877,6 +2879,8 @@
     cSeed           := '';
     cIsSoundEnabled := false;
     cVolumeDelta    := 0;
+    cVolumeUpKey    := false;
+    cVolumeDownKey  := false;
     cMuteToggle     := false;
     cHasFocus       := true;
     cInactDelay     := 100;