DEADSOFTWARE

Revert "Revert "no more delay between weapon switching: now player should release...
authorDeaDDooMER <deaddoomer@deadsoftware.ru>
Fri, 4 Jan 2019 19:58:38 +0000 (22:58 +0300)
committerDeaDDooMER <deaddoomer@deadsoftware.ru>
Fri, 4 Jan 2019 19:58:38 +0000 (22:58 +0300)
src/game/g_game.pas
src/game/g_player.pas
src/game/g_window.pas

index 1fdf62b2ab96e5d7cc16ce0880d91f1078732f43..972f268810ca4c5a3fe949186dcb4f78bd760ff2 100644 (file)
@@ -1504,11 +1504,18 @@ begin
   result := false;
 end;
 
   result := false;
 end;
 
+function isOneKeyPressed (key1: Word): Boolean;
+begin
+  if (key1 <> 0) and e_KeyPressed(key1) then begin result := true; exit; end;
+  result := false;
+end;
+
 procedure processPlayerControls (plr: TPlayer; var ctrl: TPlayerControl; var MoveButton: Byte; p2hack: Boolean=false);
 var
   time: Word;
   strafeDir: Byte;
   i: Integer;
 procedure processPlayerControls (plr: TPlayer; var ctrl: TPlayerControl; var MoveButton: Byte; p2hack: Boolean=false);
 var
   time: Word;
   strafeDir: Byte;
   i: Integer;
+  rwk: Boolean;
 begin
   if (plr = nil) then exit;
   if (p2hack) then time := 1000 else time := 1;
 begin
   if (plr = nil) then exit;
   if (p2hack) then time := 1000 else time := 1;
@@ -1552,13 +1559,42 @@ begin
     if isKeyPressed(KeyUp, KeyUp2) then plr.PressKey(KEY_UP, time);
     if isKeyPressed(KeyDown, KeyDown2) then plr.PressKey(KEY_DOWN, time);
     if isKeyPressed(KeyFire, KeyFire2) then plr.PressKey(KEY_FIRE);
     if isKeyPressed(KeyUp, KeyUp2) then plr.PressKey(KEY_UP, time);
     if isKeyPressed(KeyDown, KeyDown2) then plr.PressKey(KEY_DOWN, time);
     if isKeyPressed(KeyFire, KeyFire2) then plr.PressKey(KEY_FIRE);
-    if isKeyPressed(KeyNextWeapon, KeyNextWeapon2) then plr.PressKey(KEY_NEXTWEAPON);
-    if isKeyPressed(KeyPrevWeapon, KeyPrevWeapon2) then plr.PressKey(KEY_PREVWEAPON);
+    if isKeyPressed(KeyNextWeapon, KeyNextWeapon2) then
+    begin
+      rwk := plr.isWeaponSwitchKeyReleased(-1);
+      if rwk then plr.PressKey(KEY_NEXTWEAPON);
+      plr.weaponSwitchKeysStateChange(-1, true);
+    end
+    else
+    begin
+      plr.weaponSwitchKeysStateChange(-1, false);
+    end;
+    if isKeyPressed(KeyPrevWeapon, KeyPrevWeapon2) then
+    begin
+      rwk := plr.isWeaponSwitchKeyReleased(-2);
+      if rwk then plr.PressKey(KEY_PREVWEAPON);
+      plr.weaponSwitchKeysStateChange(-2, true);
+    end
+    else
+    begin
+      plr.weaponSwitchKeysStateChange(-2, false);
+    end;
     if isKeyPressed(KeyOpen, KeyOpen2) then plr.PressKey(KEY_OPEN);
 
     for i := 0 to High(KeyWeapon) do
     if isKeyPressed(KeyOpen, KeyOpen2) then plr.PressKey(KEY_OPEN);
 
     for i := 0 to High(KeyWeapon) do
+    begin
       if isKeyPressed(KeyWeapon[i], KeyWeapon2[i]) then
       if isKeyPressed(KeyWeapon[i], KeyWeapon2[i]) then
-        plr.QueueWeaponSwitch(i); // all choices are passed there, and god will take the best
+      begin
+        rwk := plr.isWeaponSwitchKeyReleased(i);
+        //writeln('rwk:', rwk);
+        plr.weaponSwitchKeysStateChange(i, true);
+        if rwk then plr.QueueWeaponSwitch(i); // all choices are passed there, and god will take the best
+      end
+      else
+      begin
+        plr.weaponSwitchKeysStateChange(i, false);
+      end;
+    end;
   end;
 
   // HACK: add dynlight here
   end;
 
   // HACK: add dynlight here
index 5dd29a6c4633bd97984551f7f9ae6f93665b5397..137ab818e6c4d7bbee6ec089ca7abb7c72c12dd5 100644 (file)
@@ -163,7 +163,7 @@ type
     FSecrets:   Integer;
     FCurrWeap:  Byte;
     FNextWeap:  WORD;
     FSecrets:   Integer;
     FCurrWeap:  Byte;
     FNextWeap:  WORD;
-    FNextWeapDelay: Byte; // frames
+    FNextWeapDelay: Byte; // frames (unused)
     FBFGFireCounter: SmallInt;
     FLastSpawnerUID: Word;
     FLastHit:   Byte;
     FBFGFireCounter: SmallInt;
     FLastSpawnerUID: Word;
     FLastHit:   Byte;
@@ -200,6 +200,9 @@ type
     FNetTime: LongWord;
     mEDamageType: Integer;
 
     FNetTime: LongWord;
     mEDamageType: Integer;
 
+    // client-side only
+    weaponSwitchKeyReleased: array[0..16] of Boolean; // true: was release
+
 
     function CollideLevel(XInc, YInc: Integer): Boolean;
     function StayOnStep(XInc, YInc: Integer): Boolean;
 
     function CollideLevel(XInc, YInc: Integer): Boolean;
     function StayOnStep(XInc, YInc: Integer): Boolean;
@@ -334,6 +337,10 @@ type
     procedure getMapBox (out x, y, w, h: Integer); inline;
     procedure moveBy (dx, dy: Integer); inline;
 
     procedure getMapBox (out x, y, w, h: Integer); inline;
     procedure moveBy (dx, dy: Integer); inline;
 
+    procedure releaseAllWeaponSwitchKeys ();
+    procedure weaponSwitchKeysStateChange (index: Integer; pressed: Boolean);
+    function isWeaponSwitchKeyReleased (index: Integer): Boolean;
+
   public
     property    Vel: TPoint2i read FObj.Vel;
     property    Obj: TObj read FObj;
   public
     property    Vel: TPoint2i read FObj.Vel;
     property    Obj: TObj read FObj;
@@ -2130,8 +2137,38 @@ begin
   FNetTime := 0;
 
   resetWeaponQueue();
   FNetTime := 0;
 
   resetWeaponQueue();
+  releaseAllWeaponSwitchKeys();
+end;
+
+
+procedure TPlayer.releaseAllWeaponSwitchKeys ();
+var
+  f: Integer;
+begin
+  for f := 0 to High(weaponSwitchKeyReleased) do weaponSwitchKeyReleased[f] := true;
+end;
+
+procedure TPlayer.weaponSwitchKeysStateChange (index: Integer; pressed: Boolean);
+begin
+  Inc(index, 2); // -2: prev; -1: next
+  if (index < 0) or (index > High(weaponSwitchKeyReleased)) then exit;
+  weaponSwitchKeyReleased[index] := not pressed;
 end;
 
 end;
 
+function TPlayer.isWeaponSwitchKeyReleased (index: Integer): Boolean;
+begin
+  Inc(index, 2); // -2: prev; -1: next
+  if (index < 0) or (index > High(weaponSwitchKeyReleased)) then
+  begin
+    result := true;
+  end
+  else
+  begin
+    result := weaponSwitchKeyReleased[index];
+  end;
+end;
+
+
 procedure TPlayer.positionChanged (); inline;
 begin
 end;
 procedure TPlayer.positionChanged (); inline;
 begin
 end;
@@ -3680,7 +3717,7 @@ begin
       begin
         //e_WriteLog(Format(' SWITCH: cur=%d; new=%d (dir=%d; log=%d)', [FCurrWeap, rwidx, dir, cwi]), TMsgType.Warning);
         result := Byte(rwidx);
       begin
         //e_WriteLog(Format(' SWITCH: cur=%d; new=%d (dir=%d; log=%d)', [FCurrWeap, rwidx, dir, cwi]), TMsgType.Warning);
         result := Byte(rwidx);
-        FNextWeapDelay := 10;
+        //FNextWeapDelay := 10; //k8: not needed anymore
         exit;
       end;
     end;
         exit;
       end;
     end;
@@ -3747,7 +3784,7 @@ begin
       // i found her!
       result := Byte(rwidx);
       resetWeaponQueue();
       // i found her!
       result := Byte(rwidx);
       resetWeaponQueue();
-      FNextWeapDelay := 10; // anyway, 'cause why not
+      //FNextWeapDelay := 10; // anyway, 'cause why not; k8: not needed anymore
       exit;
     end;
   end;
       exit;
     end;
   end;
@@ -3777,7 +3814,9 @@ var
 begin
   //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
   //FNextWeap := FNextWeap and $1FFF;
 begin
   //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
   //FNextWeap := FNextWeap and $1FFF;
-  if FNextWeapDelay > 0 then Dec(FNextWeapDelay); // "alteration delay"
+  //HACK: alteration delay will be reset when player released any weapon switch key
+  FNextWeapDelay := 0; //k8: just in case
+  //if FNextWeapDelay > 0 then Dec(FNextWeapDelay); // "alteration delay"
 
   if not switchAllowed then
   begin
 
   if not switchAllowed then
   begin
index 3958d24d12df79b518b6dc351942a53d487acc52..8336ea9b82cb39b11cd0b5b95c8e992e8cc3b0dd 100644 (file)
@@ -314,6 +314,8 @@ begin
     SDL_WINDOWEVENT_MINIMIZED:
     begin
       e_UnpressAllKeys();
     SDL_WINDOWEVENT_MINIMIZED:
     begin
       e_UnpressAllKeys();
+      if (gPlayer1 <> nil) then gPlayer1.releaseAllWeaponSwitchKeys();
+      if (gPlayer2 <> nil) then gPlayer2.releaseAllWeaponSwitchKeys();
       if not wMinimized then
       begin
         e_ResizeWindow(0, 0);
       if not wMinimized then
       begin
         e_ResizeWindow(0, 0);
@@ -402,6 +404,8 @@ begin
     begin
       wDeactivate := true;
       e_UnpressAllKeys();
     begin
       wDeactivate := true;
       e_UnpressAllKeys();
+      if (gPlayer1 <> nil) then gPlayer1.releaseAllWeaponSwitchKeys();
+      if (gPlayer2 <> nil) then gPlayer2.releaseAllWeaponSwitchKeys();
       //e_WriteLog('window lost focus!', MSG_NOTIFY);
     end;
   end;
       //e_WriteLog('window lost focus!', MSG_NOTIFY);
     end;
   end;