From c7e667a17aec28902cd417bd1cab919df830aa34 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 27 Aug 2020 00:06:59 +0200 Subject: [PATCH] - transition weapon selection in SW. Thanks to the macro insanity for trivial operations in this code base this turned out to be a lot more troublesome than Duke... --- source/core/packet.h | 10 ---------- source/games/duke/src/input.cpp | 3 +-- source/sw/src/game.h | 1 + source/sw/src/input.cpp | 3 +-- source/sw/src/network.cpp | 8 +++++++- source/sw/src/panel.cpp | 17 +++++------------ source/sw/src/player.cpp | 1 + source/sw/src/predict.cpp | 4 ++-- 8 files changed, 18 insertions(+), 29 deletions(-) diff --git a/source/core/packet.h b/source/core/packet.h index 6960e80cf..4c8156d19 100644 --- a/source/core/packet.h +++ b/source/core/packet.h @@ -113,16 +113,6 @@ union SYNCFLAGS // NETWORK - REDEFINABLE SHARED (SYNC) KEYS BIT POSITIONS // -// weapons takes up 4 bits -#define SK_WEAPON_BIT0 0 -#define SK_WEAPON_BIT1 1 -#define SK_WEAPON_BIT2 2 -#define SK_WEAPON_BIT3 3 -#define SK_WEAPON_MASK (BIT(SK_WEAPON_BIT0)| \ - BIT(SK_WEAPON_BIT1)| \ - BIT(SK_WEAPON_BIT2)| \ - BIT(SK_WEAPON_BIT3)) // 16 possible numbers 0-15 - #define SK_INV_HOTKEY_BIT0 4 #define SK_INV_HOTKEY_BIT1 5 #define SK_INV_HOTKEY_BIT2 6 diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index 2fe35fbec..4343e7e05 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -664,8 +664,7 @@ static void processInputBits(player_struct *p, ControlInfo &info) if (buttonMap.ButtonDown(gamefunc_Dpad_Select) && info.dz > 0) j = 11; if (buttonMap.ButtonDown(gamefunc_Dpad_Select) && info.dz < 0) j = 12; - if (j && (loc.actions & SB_WEAPONMASK_BITS) == 0) - loc.SetNewWeapon(j); + if (j) loc.SetNewWeapon(j); } diff --git a/source/sw/src/game.h b/source/sw/src/game.h index 33e268378..2f21873bc 100644 --- a/source/sw/src/game.h +++ b/source/sw/src/game.h @@ -1002,6 +1002,7 @@ struct PLAYERstruct PLAYER_ACTION_FUNCp DoPlayerAction; int Flags, Flags2; + ESyncBits KeyPressBits; int KeyPressFlags; SECTOR_OBJECTp sop_control; // sector object pointer diff --git a/source/sw/src/input.cpp b/source/sw/src/input.cpp index 06e386318..0fff211b7 100644 --- a/source/sw/src/input.cpp +++ b/source/sw/src/input.cpp @@ -343,8 +343,7 @@ getinput(InputPacket *loc, SWBOOL tied) if (WeaponToSend > 0) { - loc->bits &= ~SK_WEAPON_MASK; - loc->bits |= WeaponToSend; + loc->SetNewWeapon(WeaponToSend); WeaponToSend = 0; } else if (WeaponToSend == -1) diff --git a/source/sw/src/network.cpp b/source/sw/src/network.cpp index e1fa0c5f9..a101554ab 100644 --- a/source/sw/src/network.cpp +++ b/source/sw/src/network.cpp @@ -84,6 +84,7 @@ typedef struct fix16_t q16ang; fix16_t q16horz; int32_t bits; + ESyncBits actions; } SW_AVERAGE_PACKET; int MovesPerPacket = 1; @@ -204,8 +205,12 @@ UpdateInputs(void) AveragePacket.q16ang = Player[myconnectindex].camq16ang; AveragePacket.q16horz = Player[myconnectindex].camq16horiz; SET(AveragePacket.bits, loc.bits); + SET(AveragePacket.actions, loc.actions); + // The above would or the weapon numbers together. Undo that now. The last one should win. + AveragePacket.actions &= ~SB_WEAPONMASK_BITS; + AveragePacket.actions |= ESyncBits::FromInt(loc.getNewWeapon()) & SB_WEAPONMASK_BITS; - Bmemset(&loc, 0, sizeof(loc)); + memset(&loc, 0, sizeof(loc)); pp = Player + myconnectindex; @@ -226,6 +231,7 @@ UpdateInputs(void) loc.q16ang = AveragePacket.q16ang; loc.q16horz = AveragePacket.q16horz; loc.bits = AveragePacket.bits; + loc.actions = AveragePacket.actions; memset(&AveragePacket, 0, sizeof(AveragePacket)); diff --git a/source/sw/src/panel.cpp b/source/sw/src/panel.cpp index 9d4eabd42..e10e2d9b7 100644 --- a/source/sw/src/panel.cpp +++ b/source/sw/src/panel.cpp @@ -191,15 +191,8 @@ void pToggleCrosshair(void) void DoPlayerChooseYell(PLAYERp pp) { int choose_snd = 0; - short weapon; - weapon = TEST(pp->input.bits, SK_WEAPON_MASK); - - if (weapon == WPN_FIST) - { - if (RANDOM_RANGE(1000) < 900) return; - } - else if (RANDOM_RANGE(1000) < 990) return; + if (RANDOM_RANGE(1000) < 990) return; choose_snd = STD_RANDOM_RANGE(MAX_YELLSOUNDS); @@ -487,13 +480,13 @@ int WeaponOperate(PLAYERp pp) } } - weapon = TEST(pp->input.bits, SK_WEAPON_MASK); + weapon = pp->input.getNewWeapon(); if (weapon) { - if (FLAG_KEY_PRESSED(pp, SK_WEAPON_BIT0)) + if (pp->KeyPressBits & SB_FIRST_WEAPON_BIT) { - FLAG_KEY_RELEASE(pp, SK_WEAPON_BIT0); + pp->KeyPressBits &= ~SB_FIRST_WEAPON_BIT; weapon -= 1; @@ -640,7 +633,7 @@ int WeaponOperate(PLAYERp pp) } else { - FLAG_KEY_RESET(pp, SK_WEAPON_BIT0); + pp->KeyPressBits |= SB_FIRST_WEAPON_BIT; } // Shut that computer chick up if weapon has changed! diff --git a/source/sw/src/player.cpp b/source/sw/src/player.cpp index bfe7944e6..21ad39895 100644 --- a/source/sw/src/player.cpp +++ b/source/sw/src/player.cpp @@ -7806,6 +7806,7 @@ InitAllPlayers(void) pp->WpnGotOnceFlags = 0; pp->DoPlayerAction = DoPlayerBeginRun; + pp->KeyPressBits = ESyncBits::FromInt(0xFFFFFFFF); pp->KeyPressFlags = 0xFFFFFFFF; memset(pp->KilledPlayer,0,sizeof(pp->KilledPlayer)); diff --git a/source/sw/src/predict.cpp b/source/sw/src/predict.cpp index 1e1c3d2fc..84b7687a3 100644 --- a/source/sw/src/predict.cpp +++ b/source/sw/src/predict.cpp @@ -83,12 +83,13 @@ DoPrediction(PLAYERp ppp) // get rid of input bits so it doesn't go into other code branches that would // get it out of sync + ppp->input.actions &= ~(SB_WEAPONMASK_BITS); + ppp->KeyPressBits |= (SB_WEAPONMASK_BITS); RESET(ppp->input.bits, BIT(SK_SHOOT)|BIT(SK_OPERATE)|BIT(SK_INV_LEFT)|BIT(SK_INV_RIGHT)| BIT(SK_INV_USE)|BIT(SK_HIDE_WEAPON)| BIT(SK_AUTO_AIM)| BIT(SK_CENTER_VIEW)| - SK_WEAPON_MASK| SK_INV_HOTKEY_MASK ); @@ -97,7 +98,6 @@ DoPrediction(PLAYERp ppp) BIT(SK_INV_USE)|BIT(SK_HIDE_WEAPON)| BIT(SK_AUTO_AIM)| BIT(SK_CENTER_VIEW)| - SK_WEAPON_MASK| SK_INV_HOTKEY_MASK );