From a9ab7bf0c72e15b932b20aad24b10db60138bb21 Mon Sep 17 00:00:00 2001 From: Ketmar Dark Date: Mon, 1 Oct 2018 09:32:06 +0300 Subject: [PATCH] Revert "Revert "no more delay between weapon switching: now player should release switching key and press it again -- look ma no pause!"" This reverts commit aea87456d131c418ed632d30b57280dfeefe16de. --- src/game/g_game.pas | 42 +++++++++++++++++++++++++++++++++++--- src/game/g_player.pas | 47 +++++++++++++++++++++++++++++++++++++++---- src/game/g_window.pas | 4 ++++ 3 files changed, 86 insertions(+), 7 deletions(-) diff --git a/src/game/g_game.pas b/src/game/g_game.pas index 1dcbcd2..de729fa 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -1504,11 +1504,18 @@ begin 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; + rwk: Boolean; 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(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 + begin 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 diff --git a/src/game/g_player.pas b/src/game/g_player.pas index 980aec7..fa2dcfc 100644 --- a/src/game/g_player.pas +++ b/src/game/g_player.pas @@ -163,7 +163,7 @@ type FSecrets: Integer; FCurrWeap: Byte; FNextWeap: WORD; - FNextWeapDelay: Byte; // frames + FNextWeapDelay: Byte; // frames (unused) FBFGFireCounter: SmallInt; FLastSpawnerUID: Word; FLastHit: Byte; @@ -200,6 +200,9 @@ type 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; @@ -333,6 +336,10 @@ type 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; @@ -2128,8 +2135,38 @@ begin 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; +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; @@ -3659,7 +3696,7 @@ begin 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; @@ -3726,7 +3763,7 @@ begin // 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; @@ -3756,7 +3793,9 @@ var 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 diff --git a/src/game/g_window.pas b/src/game/g_window.pas index 3958d24..8336ea9 100644 --- a/src/game/g_window.pas +++ b/src/game/g_window.pas @@ -314,6 +314,8 @@ begin 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); @@ -402,6 +404,8 @@ begin 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; -- 2.29.2