From e768a2bf24f5ebd93e2199eefe28c3775c5393ba Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 26 Aug 2020 23:02:55 +0200 Subject: [PATCH] - use new bitmask for weapon selection in Duke. --- source/core/packet.h | 48 ++++++++++++++++++++++++--------- source/games/duke/src/inlines.h | 10 +++++++ source/games/duke/src/input.cpp | 8 +++--- 3 files changed, 50 insertions(+), 16 deletions(-) diff --git a/source/core/packet.h b/source/core/packet.h index 9ec2768c8..6960e80cf 100644 --- a/source/core/packet.h +++ b/source/core/packet.h @@ -5,6 +5,20 @@ #include "tflags.h" +enum ESyncBits_ : uint32_t +{ + SB_FIRST_WEAPON_BIT = 1 << 0, + + SB_WEAPONMASK_BITS = (15u * SB_FIRST_WEAPON_BIT), // Weapons take up 4 bits + + SB_INTERFACE_BITS = (SB_WEAPONMASK_BITS) +}; + +// enforce type safe operations on the input bits. +using ESyncBits = TFlags; +DEFINE_TFLAGS_OPERATORS(ESyncBits) + + // Blood flags enum { @@ -13,7 +27,7 @@ enum }; -enum ESyncBits_ : uint32_t +enum EDukeSyncBits_ : uint32_t { SKB_JUMP = 1 << 0, SKB_CROUCH = 1 << 1, @@ -45,8 +59,7 @@ enum ESyncBits_ : uint32_t SKB_INVENTORY = 1 << 30, SKB_ESCAPE = 1u << 31, - SKB_WEAPONMASK_BITS = (15u * SKB_FIRST_WEAPON_BIT), - SKB_INTERFACE_BITS = (SKB_WEAPONMASK_BITS | SKB_STEROIDS | SKB_NIGHTVISION | SKB_MEDKIT | SKB_QUICK_KICK | \ + SKB_INTERFACE_BITS = (SKB_STEROIDS | SKB_NIGHTVISION | SKB_MEDKIT | SKB_QUICK_KICK | \ SKB_HOLSTER | SKB_INV_LEFT | SKB_PAUSE | SKB_HOLODUKE | SKB_JETPACK | SKB_INV_RIGHT | \ SKB_TURNAROUND | SKB_OPEN | SKB_INVENTORY | SKB_ESCAPE), @@ -56,7 +69,7 @@ enum ESyncBits_ : uint32_t }; // enforce type safe operations on the input bits. -using EDukeSyncBits = TFlags; +using EDukeSyncBits = TFlags; DEFINE_TFLAGS_OPERATORS(EDukeSyncBits) union SYNCFLAGS @@ -175,17 +188,28 @@ struct InputPacket fix16_t q16horz; fix16_t q16aimvel; // only used by SW fix16_t q16ang; // only used by SW + ESyncBits actions; // Making this a union lets some constructs fail. Since these names are transitional only the added memory use doesn't really matter. - // for Duke - EDukeSyncBits sbits; + // for Duke + EDukeSyncBits sbits; - // for SW - int32_t bits; + // for SW + int32_t bits; - // for Blood - SYNCFLAGS syncFlags; + // for Blood + SYNCFLAGS syncFlags; - // For Exhumed - uint16_t buttons; + // For Exhumed + uint16_t buttons; + + int getNewWeapon() const + { + return (actions & SB_WEAPONMASK_BITS).GetValue(); + } + + void SetNewWeapon(int weap) + { + actions = (actions & ~SB_WEAPONMASK_BITS) | (ESyncBits::FromInt(weap) & SB_WEAPONMASK_BITS); + } }; diff --git a/source/games/duke/src/inlines.h b/source/games/duke/src/inlines.h index 69841ba76..4d9075237 100644 --- a/source/games/duke/src/inlines.h +++ b/source/games/duke/src/inlines.h @@ -136,6 +136,16 @@ inline EDukeSyncBits PlayerInputBits(int pl, EDukeSyncBits bits) return (sync[pl].sbits & bits); } +inline ESyncBits PlayerInputBits(int pl, ESyncBits bits) +{ + return (sync[pl].actions & bits); +} + +inline int PlayerNewWeapon(int pl) +{ + return sync[pl].getNewWeapon(); +} + inline int PlayerInputSideVel(int pl) { return sync[pl].svel; diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index f5b3ce3d8..2fe35fbec 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -195,7 +195,7 @@ void hud_input(int snum) } if (!PlayerInput(snum, SKB_QUICK_KICK)) p->quick_kick_msg = false; - if (!PlayerInputBits(snum, SKB_INTERFACE_BITS)) + if (!PlayerInputBits(snum, SKB_INTERFACE_BITS) && ! PlayerInputBits(snum, SB_INTERFACE_BITS)) p->interface_toggle_flag = 0; else if (p->interface_toggle_flag == 0) { @@ -339,7 +339,7 @@ void hud_input(int snum) if (dainv >= 1 && dainv < 8) FTA(invquotes[dainv - 1], p); } - j = (PlayerInputBits(snum, SKB_WEAPONMASK_BITS) / SKB_FIRST_WEAPON_BIT) - 1; + j = PlayerNewWeapon(snum) - 1; if (j >= 0) { int a = 0; @@ -664,8 +664,8 @@ 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.sbits & SKB_WEAPONMASK_BITS) == 0) - loc.sbits |= EDukeSyncBits::FromInt(j * SKB_FIRST_WEAPON_BIT); + if (j && (loc.actions & SB_WEAPONMASK_BITS) == 0) + loc.SetNewWeapon(j); }