From abf715eace77731837d52da55127e87bd2535b1e Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 26 Aug 2020 17:12:48 +0200 Subject: [PATCH] - unified the packet structures of all games. Currently the bit fields are still separate and they have to be merged, but for now the added memory does not matter. Having this structure in the common parts will allow work on consolidating the input code, though. --- source/blood/src/controls.cpp | 4 +- source/blood/src/controls.h | 55 +-------- source/blood/src/network.cpp | 10 +- source/blood/src/network.h | 2 +- source/blood/src/player.cpp | 4 +- source/blood/src/player.h | 2 +- source/blood/src/prediction.cpp | 8 +- source/blood/src/view.h | 2 +- source/core/packet.h | 191 +++++++++++++++++++++++++++++ source/exhumed/src/exhumed.cpp | 2 +- source/exhumed/src/ps_input.h | 26 +--- source/games/duke/src/constants.h | 45 ------- source/games/duke/src/funct.h | 1 + source/games/duke/src/gameloop.cpp | 6 +- source/games/duke/src/global.cpp | 4 +- source/games/duke/src/global.h | 4 +- source/games/duke/src/inlines.h | 8 +- source/games/duke/src/input.cpp | 62 +++++----- source/games/duke/src/types.h | 8 +- source/sw/src/game.cpp | 2 +- source/sw/src/game.h | 71 +---------- source/sw/src/input.cpp | 2 +- source/sw/src/network.cpp | 12 +- source/sw/src/player.cpp | 6 +- source/sw/src/save.cpp | 2 +- 25 files changed, 273 insertions(+), 266 deletions(-) create mode 100644 source/core/packet.h diff --git a/source/blood/src/controls.cpp b/source/blood/src/controls.cpp index 3677727a0..384c515ef 100644 --- a/source/blood/src/controls.cpp +++ b/source/blood/src/controls.cpp @@ -40,7 +40,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. BEGIN_BLD_NS -GINPUT gInput, gNetInput; +InputPacket gInput, gNetInput; bool bSilentAim = false; int iTurnCount = 0; @@ -133,7 +133,7 @@ void ctrlGetInput(void) if (paused) return; - GINPUT input = {}; + InputPacket input = {}; bool mouseaim = in_mousemode || buttonMap.ButtonDown(gamefunc_Mouse_Aiming); if (!mouseaim) gInput.syncFlags.lookCenter = 1; diff --git a/source/blood/src/controls.h b/source/blood/src/controls.h index 4f39e1e3a..82ab79bf8 100644 --- a/source/blood/src/controls.h +++ b/source/blood/src/controls.h @@ -24,60 +24,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. BEGIN_BLD_NS -#pragma pack(push, 1) +#include "packet.h" -enum -{ - flag_buttonmask = 127, - flag_buttonmask_norun = 126 -}; - -union SYNCFLAGS -{ - uint32_t value; - struct - { - unsigned int run : 1; - unsigned int jump : 1; - unsigned int crouch : 1; - unsigned int shoot : 1; - unsigned int shoot2 : 1; - unsigned int lookUp : 1; - unsigned int lookDown : 1; - unsigned int action : 1; - unsigned int jab : 1; - unsigned int prevItem : 1; - unsigned int nextItem : 1; - unsigned int useItem : 1; - unsigned int prevWeapon : 1; - unsigned int nextWeapon : 1; - unsigned int holsterWeapon : 1; - unsigned int lookCenter : 1; - unsigned int lookLeft : 1; - unsigned int lookRight : 1; - unsigned int spin180 : 1; - unsigned int pause : 1; - unsigned int quit : 1; - unsigned int restart : 1; - unsigned int useBeastVision : 1; - unsigned int useCrystalBall : 1; - unsigned int useJumpBoots : 1; - unsigned int useMedKit : 1; - unsigned int newWeapon : 4; - }; -}; -struct GINPUT -{ - SYNCFLAGS syncFlags; - int16_t fvel; - int16_t svel; - fix16_t q16avel; - fix16_t q16horz; -}; - -#pragma pack(pop) - -extern GINPUT gInput, gNetInput; +extern InputPacket gInput, gNetInput; extern bool bSilentAim; extern fix16_t gViewLook, gViewAngle; diff --git a/source/blood/src/network.cpp b/source/blood/src/network.cpp index bcb2a7d7d..a1f786b3b 100644 --- a/source/blood/src/network.cpp +++ b/source/blood/src/network.cpp @@ -44,7 +44,7 @@ int gNetFifoTail = 0; int gNetFifoHead[8]; int gPredictTail = 0; int gNetFifoMasterTail = 0; -GINPUT gFifoInput[256][8]; +InputPacket gFifoInput[256][8]; int myMinLag[8]; int otherMinLag = 0; int myMaxLag = 0; @@ -108,7 +108,7 @@ void netGetInput(void) for (int p = connecthead; p >= 0; p = connectpoint2[p]) if (gNetFifoHead[myconnectindex]-200 > gNetFifoHead[p]) return; - GINPUT &input = gFifoInput[gNetFifoHead[myconnectindex]&255][myconnectindex]; + InputPacket &input = gFifoInput[gNetFifoHead[myconnectindex]&255][myconnectindex]; input = gNetInput; gNetFifoHead[myconnectindex]++; if (gGameOptions.nGameType == 0 || numplayers == 1) @@ -117,9 +117,9 @@ void netGetInput(void) { if (p != myconnectindex) { - GINPUT *pInput1 = &gFifoInput[(gNetFifoHead[p]-1)&255][p]; - GINPUT *pInput2 = &gFifoInput[gNetFifoHead[p]&255][p]; - memcpy(pInput2, pInput1, sizeof(GINPUT)); + InputPacket *pInput1 = &gFifoInput[(gNetFifoHead[p]-1)&255][p]; + InputPacket *pInput2 = &gFifoInput[gNetFifoHead[p]&255][p]; + memcpy(pInput2, pInput1, sizeof(InputPacket)); gNetFifoHead[p]++; } } diff --git a/source/blood/src/network.h b/source/blood/src/network.h index 0ea414a45..1b829a2b5 100644 --- a/source/blood/src/network.h +++ b/source/blood/src/network.h @@ -49,7 +49,7 @@ extern int gNetFifoTail; extern int gNetFifoHead[8]; extern int gPredictTail; extern int gNetFifoMasterTail; -extern GINPUT gFifoInput[256][8]; +extern InputPacket gFifoInput[256][8]; extern int myMinLag[8]; extern int otherMinLag; extern int myMaxLag; diff --git a/source/blood/src/player.cpp b/source/blood/src/player.cpp index fefccf784..fc88c07d7 100644 --- a/source/blood/src/player.cpp +++ b/source/blood/src/player.cpp @@ -641,7 +641,7 @@ void playerResetPosture(PLAYER* pPlayer) { void playerStart(int nPlayer, int bNewLevel) { PLAYER* pPlayer = &gPlayer[nPlayer]; - GINPUT* pInput = &pPlayer->input; + InputPacket* pInput = &pPlayer->input; ZONE* pStartZone = NULL; // normal start position @@ -1299,7 +1299,7 @@ void ProcessInput(PLAYER *pPlayer) XSPRITE *pXSprite = pPlayer->pXSprite; int nSprite = pPlayer->nSprite; POSTURE *pPosture = &pPlayer->pPosture[pPlayer->lifeMode][pPlayer->posture]; - GINPUT *pInput = &pPlayer->input; + InputPacket *pInput = &pPlayer->input; if (pPlayer == gMe && numplayers == 1) { diff --git a/source/blood/src/player.h b/source/blood/src/player.h index aafab87b8..f90fe6900 100644 --- a/source/blood/src/player.h +++ b/source/blood/src/player.h @@ -86,7 +86,7 @@ struct PLAYER spritetype* pSprite; XSPRITE* pXSprite; DUDEINFO* pDudeInfo; - GINPUT input; + InputPacket input; uint8_t newWeapon; int used1; // something related to game checksum int weaponQav; diff --git a/source/blood/src/prediction.cpp b/source/blood/src/prediction.cpp index cfda834d4..629076764 100644 --- a/source/blood/src/prediction.cpp +++ b/source/blood/src/prediction.cpp @@ -49,7 +49,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. BEGIN_BLD_NS -void fakePlayerProcess(PLAYER* pPlayer, GINPUT* pInput); +void fakePlayerProcess(PLAYER* pPlayer, InputPacket* pInput); void fakeActProcessSprites(void); bool gPrediction = true; @@ -101,7 +101,7 @@ void viewInitializePrediction(void) } } -void viewUpdatePrediction(GINPUT *pInput) +void viewUpdatePrediction(InputPacket *pInput) { predictOld = predict; short bakCstat = gMe->pSprite->cstat; @@ -124,7 +124,7 @@ static void sub_158B4(PLAYER *pPlayer) predict.at40 = predict.at58 - pPlayer->pPosture[pPlayer->lifeMode][predict.at48].weaponAboveZ; } -static void fakeProcessInput(PLAYER *pPlayer, GINPUT *pInput) +static void fakeProcessInput(PLAYER *pPlayer, InputPacket *pInput) { POSTURE *pPosture = &pPlayer->pPosture[pPlayer->lifeMode][predict.at48]; @@ -322,7 +322,7 @@ static void fakeProcessInput(PLAYER *pPlayer, GINPUT *pInput) predict.at2c = (-fix16_to_int(predict.at24))<<7; } -void fakePlayerProcess(PLAYER *pPlayer, GINPUT *pInput) +void fakePlayerProcess(PLAYER *pPlayer, InputPacket *pInput) { spritetype *pSprite = pPlayer->pSprite; XSPRITE *pXSprite = pPlayer->pXSprite; diff --git a/source/blood/src/view.h b/source/blood/src/view.h index 46f7f7f36..a7ef252f6 100644 --- a/source/blood/src/view.h +++ b/source/blood/src/view.h @@ -144,7 +144,7 @@ extern double gInterpolate; void hudDraw(PLAYER* gView, int nSectnum, int defaultHoriz, double bobx, double boby, double zDelta, int basepal); void viewInitializePrediction(void); -void viewUpdatePrediction(GINPUT *pInput); +void viewUpdatePrediction(InputPacket *pInput); void viewCorrectPrediction(void); void viewBackupView(int nPlayer); void viewCorrectViewOffsets(int nPlayer, vec3_t const *oldpos); diff --git a/source/core/packet.h b/source/core/packet.h new file mode 100644 index 000000000..2727a960b --- /dev/null +++ b/source/core/packet.h @@ -0,0 +1,191 @@ +#pragma once + +#include +#include "fix16.h" +#include "tflags.h" + + +// Blood flags +enum +{ + flag_buttonmask = 127, + flag_buttonmask_norun = 126 +}; + + +enum ESyncBits_ : uint32_t +{ + SKB_JUMP = 1 << 0, + SKB_CROUCH = 1 << 1, + SKB_FIRE = 1 << 2, + SKB_AIM_UP = 1 << 3, + SKB_AIM_DOWN = 1 << 4, + SKB_RUN = 1 << 5, + SKB_LOOK_LEFT = 1 << 6, + SKB_LOOK_RIGHT = 1 << 7, + SKB_FIRST_WEAPON_BIT = 1 << 8, + SKB_STEROIDS = 1 << 12, + SKB_LOOK_UP = 1 << 13, + SKB_LOOK_DOWN = 1 << 14, + SKB_NIGHTVISION = 1 << 15, + SKB_MEDKIT = 1 << 16, + SKB_MULTIFLAG = 1 << 17, + SKB_CENTER_VIEW = 1 << 18, + SKB_HOLSTER = 1 << 19, + SKB_INV_LEFT = 1 << 20, + SKB_PAUSE = 1 << 21, + SKB_QUICK_KICK = 1 << 22, + SKB_AIMMODE = 1 << 23, + SKB_HOLODUKE = 1 << 24, + SKB_JETPACK = 1 << 25, + SKB_GAMEQUIT = 1 << 26, + SKB_INV_RIGHT = 1 << 27, + SKB_TURNAROUND = 1 << 28, + SKB_OPEN = 1 << 29, + 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_HOLSTER | SKB_INV_LEFT | SKB_PAUSE | SKB_HOLODUKE | SKB_JETPACK | SKB_INV_RIGHT | \ + SKB_TURNAROUND | SKB_OPEN | SKB_INVENTORY | SKB_ESCAPE), + + SKB_NONE = 0, + SKB_ALL = ~0u + +}; + +// enforce type safe operations on the input bits. +using ESyncBits = TFlags; +DEFINE_TFLAGS_OPERATORS(ESyncBits) + +union SYNCFLAGS +{ + uint32_t value; + struct + { + unsigned int run : 1; + unsigned int jump : 1; + unsigned int crouch : 1; + unsigned int shoot : 1; + unsigned int shoot2 : 1; + unsigned int lookUp : 1; + unsigned int lookDown : 1; + unsigned int action : 1; + unsigned int jab : 1; + unsigned int prevItem : 1; + unsigned int nextItem : 1; + unsigned int useItem : 1; + unsigned int prevWeapon : 1; + unsigned int nextWeapon : 1; + unsigned int holsterWeapon : 1; + unsigned int lookCenter : 1; + unsigned int lookLeft : 1; + unsigned int lookRight : 1; + unsigned int spin180 : 1; + unsigned int pause : 1; + unsigned int quit : 1; + unsigned int restart : 1; + unsigned int useBeastVision : 1; + unsigned int useCrystalBall : 1; + unsigned int useJumpBoots : 1; + unsigned int useMedKit : 1; + unsigned int newWeapon : 4; + }; +}; + +// SW + +// +// 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 +#define SK_INV_HOTKEY_MASK (BIT(SK_INV_HOTKEY_BIT0)|BIT(SK_INV_HOTKEY_BIT1)|BIT(SK_INV_HOTKEY_BIT2)) + +#define SK_AUTO_AIM 7 +#define SK_CENTER_VIEW 8 +#define SK_PAUSE 9 + +#define SK_MESSAGE 11 +#define SK_LOOK_UP 12 +#define SK_LOOK_DOWN 13 +#define SK_CRAWL_LOCK 14 +#define SK_FLY 15 + +#define SK_RUN 16 +#define SK_SHOOT 17 +#define SK_OPERATE 18 +#define SK_JUMP 19 +#define SK_CRAWL 20 +#define SK_SNAP_UP 21 +#define SK_SNAP_DOWN 22 +#define SK_QUIT_GAME 23 + +#define SK_MULTI_VIEW 24 + +#define SK_TURN_180 25 + +#define SK_INV_LEFT 26 +#define SK_INV_RIGHT 27 + +#define SK_INV_USE 29 +#define SK_HIDE_WEAPON 30 +#define SK_SPACE_BAR 31 + + +// Exhumed + +enum { + kButtonJump = 0x1, + kButtonOpen = 0x4, + kButtonFire = 0x8, + kButtonCrouch = 0x10, + kButtonCheatGuns = 0x20, + kButtonCheatGodMode = 0x40, + kButtonCheatKeys = 0x80, + kButtonCheatItems = 0x100, + + kButtonWeaponShift = 13, + kButtonWeaponBits = 7 << kButtonWeaponShift, // upper 3 bits. +}; + + + + + + +struct InputPacket +{ + int16_t svel; + int16_t fvel; + fix16_t q16avel; + fix16_t q16horz; + fix16_t q16aimvel; // only used by SW + fix16_t q16ang; // only used by SW + + // Making this a union lets some constructs fail. Since these names are transitional only the added memory use doesn't really matter. + // for Duke + ESyncBits sbits; + + // for SW + int32_t bits; + + // for Blood + SYNCFLAGS syncFlags; + + // For Exhumed + uint16_t buttons; +}; diff --git a/source/exhumed/src/exhumed.cpp b/source/exhumed/src/exhumed.cpp index 465e7fcbf..95bcf9a75 100644 --- a/source/exhumed/src/exhumed.cpp +++ b/source/exhumed/src/exhumed.cpp @@ -64,7 +64,7 @@ int htimer = 0; int EndLevel = false; -LocalInput localInput; +InputPacket localInput; //////// diff --git a/source/exhumed/src/ps_input.h b/source/exhumed/src/ps_input.h index 0c298fe62..5350e5fb1 100644 --- a/source/exhumed/src/ps_input.h +++ b/source/exhumed/src/ps_input.h @@ -20,23 +20,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #define __input_h__ #include "compat.h" +#include "packet.h" BEGIN_PS_NS -enum { - kButtonJump = 0x1, - kButtonOpen = 0x4, - kButtonFire = 0x8, - kButtonCrouch = 0x10, - kButtonCheatGuns = 0x20, - kButtonCheatGodMode = 0x40, - kButtonCheatKeys = 0x80, - kButtonCheatItems = 0x100, - - kButtonWeaponShift = 13, - kButtonWeaponBits = 7 << kButtonWeaponShift, // upper 3 bits. -}; - // 32 bytes struct PlayerInput { @@ -49,15 +36,6 @@ struct PlayerInput int8_t nItem; }; -struct LocalInput -{ - int svel; - int fvel; - fix16_t q16avel; - uint16_t buttons; - fix16_t q16horz; -}; - void InitInput(); void UpdateInputs(); @@ -67,7 +45,7 @@ void ClearSpaceBar(short nPlayer); int GetLocalInput(); extern PlayerInput sPlayerInput[]; -extern LocalInput localInput; +extern InputPacket localInput; extern int nNetMoves; extern int lLocalCodes; diff --git a/source/games/duke/src/constants.h b/source/games/duke/src/constants.h index 5d7e5e247..64822083a 100644 --- a/source/games/duke/src/constants.h +++ b/source/games/duke/src/constants.h @@ -187,51 +187,6 @@ enum dukeinvicon_t }; -enum ESyncBits_ : uint32_t -{ - SKB_JUMP = 1 << 0, - SKB_CROUCH = 1 << 1, - SKB_FIRE = 1 << 2, - SKB_AIM_UP = 1 << 3, - SKB_AIM_DOWN = 1 << 4, - SKB_RUN = 1 << 5, - SKB_LOOK_LEFT = 1 << 6, - SKB_LOOK_RIGHT = 1 << 7, - SKB_FIRST_WEAPON_BIT = 1 << 8, - SKB_STEROIDS = 1 << 12, - SKB_LOOK_UP = 1 << 13, - SKB_LOOK_DOWN = 1 << 14, - SKB_NIGHTVISION = 1 << 15, - SKB_MEDKIT = 1 << 16, - SKB_MULTIFLAG = 1 << 17, - SKB_CENTER_VIEW = 1 << 18, - SKB_HOLSTER = 1 << 19, - SKB_INV_LEFT = 1 << 20, - SKB_PAUSE = 1 << 21, - SKB_QUICK_KICK = 1 << 22, - SKB_AIMMODE = 1 << 23, - SKB_HOLODUKE = 1 << 24, - SKB_JETPACK = 1 << 25, - SKB_GAMEQUIT = 1 << 26, - SKB_INV_RIGHT = 1 << 27, - SKB_TURNAROUND = 1 << 28, - SKB_OPEN = 1 << 29, - 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_HOLSTER | SKB_INV_LEFT | SKB_PAUSE | SKB_HOLODUKE | SKB_JETPACK | SKB_INV_RIGHT | \ - SKB_TURNAROUND | SKB_OPEN | SKB_INVENTORY | SKB_ESCAPE), - - SKB_NONE = 0, - SKB_ALL = ~0u - -}; - -// enforce type safe operations on the input bits. -using ESyncBits = TFlags; -DEFINE_TFLAGS_OPERATORS(ESyncBits) enum EQuote { diff --git a/source/games/duke/src/funct.h b/source/games/duke/src/funct.h index 317c7ee32..5621a1127 100644 --- a/source/games/duke/src/funct.h +++ b/source/games/duke/src/funct.h @@ -2,6 +2,7 @@ #include "screenjob.h" #include "constants.h" +#include "packet.h" struct MapRecord; diff --git a/source/games/duke/src/gameloop.cpp b/source/games/duke/src/gameloop.cpp index 2ce8b3612..c0ec5f9bc 100644 --- a/source/games/duke/src/gameloop.cpp +++ b/source/games/duke/src/gameloop.cpp @@ -44,7 +44,7 @@ BEGIN_DUKE_NS // All access to the input queues should go through this function interface. // //--------------------------------------------------------------------------- -static input_t inputfifo[MOVEFIFOSIZ][MAXPLAYERS]; +static InputPacket inputfifo[MOVEFIFOSIZ][MAXPLAYERS]; static int movefifoend[MAXPLAYERS]; static int movefifoplc; static int bufferjitter; @@ -60,7 +60,7 @@ void clearfifo(void) static inline void GetNextInput() { for (int i = connecthead; i >= 0; i = connectpoint2[i]) - memcpy(&sync[i], &inputfifo[movefifoplc & (MOVEFIFOSIZ - 1)][i], sizeof(input_t)); + memcpy(&sync[i], &inputfifo[movefifoplc & (MOVEFIFOSIZ - 1)][i], sizeof(InputPacket)); movefifoplc++; } @@ -70,7 +70,7 @@ static void advancequeue(int myconnectindex) movefifoend[myconnectindex]++; } -static input_t& nextinput(int myconnectindex) +static InputPacket& nextinput(int myconnectindex) { return inputfifo[movefifoend[myconnectindex] & (MOVEFIFOSIZ - 1)][myconnectindex]; } diff --git a/source/games/duke/src/global.cpp b/source/games/duke/src/global.cpp index e9ef53281..cbe177461 100644 --- a/source/games/duke/src/global.cpp +++ b/source/games/duke/src/global.cpp @@ -58,12 +58,12 @@ int otherp; TileInfo tileinfo[MAXTILES]; // This is not from EDuke32. ActorInfo actorinfo[MAXTILES]; int actor_tog; -input_t sync[MAXPLAYERS]; +InputPacket sync[MAXPLAYERS]; int16_t max_ammo_amount[MAX_WEAPONS]; int16_t weaponsandammosprites[15]; int PHEIGHT = PHEIGHT_DUKE; int duke3d_globalflags; -input_t loc; +InputPacket loc; uint8_t ready2send; int gamequit; int playerswhenstarted; diff --git a/source/games/duke/src/global.h b/source/games/duke/src/global.h index c4f31bd17..b9ac45b74 100644 --- a/source/games/duke/src/global.h +++ b/source/games/duke/src/global.h @@ -45,13 +45,13 @@ extern ActorInfo actorinfo[MAXTILES]; // static state extern int actor_tog; // cheat state extern intptr_t apScriptGameEvent[]; extern TArray ScriptCode; -extern input_t sync[MAXPLAYERS]; +extern InputPacket sync[MAXPLAYERS]; extern int16_t max_ammo_amount[MAX_WEAPONS]; extern int16_t weaponsandammosprites[15]; extern int32_t PHEIGHT; extern int duke3d_globalflags; extern uint8_t ready2send; -extern input_t loc; +extern InputPacket loc; extern int gamequit; extern int playerswhenstarted; extern int show_shareware; diff --git a/source/games/duke/src/inlines.h b/source/games/duke/src/inlines.h index 76de0f1b2..b8907cc08 100644 --- a/source/games/duke/src/inlines.h +++ b/source/games/duke/src/inlines.h @@ -118,22 +118,22 @@ inline bool isIn(int value, const std::initializer_list& list) // these are mainly here to avoid directly accessing the input data so that it can be more easily refactored later. inline bool PlayerInput(int pl, ESyncBits bit) { - return (!!((sync[pl].bits) & bit)); + return (!!((sync[pl].sbits) & bit)); } inline void PlayerSetInput(int pl, ESyncBits bit) { - sync[pl].bits |= bit; + sync[pl].sbits |= bit; } inline void PlayerClearInput(int pl, ESyncBits bit) { - sync[pl].bits &= ~bit; + sync[pl].sbits &= ~bit; } inline ESyncBits PlayerInputBits(int pl, ESyncBits bits) { - return (sync[pl].bits & bits); + return (sync[pl].sbits & bits); } inline int PlayerInputSideVel(int pl) diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index e40eb1255..9bad5c595 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -623,39 +623,39 @@ enum static void processInputBits(player_struct *p, ControlInfo &info) { bool onVehicle = p->OnMotorcycle || p->OnBoat; - if (buttonMap.ButtonDown(gamefunc_Fire)) loc.bits |= SKB_FIRE; - if (buttonMap.ButtonDown(gamefunc_Open)) loc.bits |= SKB_OPEN; + if (buttonMap.ButtonDown(gamefunc_Fire)) loc.sbits |= SKB_FIRE; + if (buttonMap.ButtonDown(gamefunc_Open)) loc.sbits |= SKB_OPEN; // These 3 bits are only available when not riding a bike or boat. if (onVehicle) BitsToSend &= ~(SKB_HOLSTER|SKB_TURNAROUND|SKB_CENTER_VIEW); - loc.bits |= BitsToSend; + loc.sbits |= BitsToSend; BitsToSend = 0; if (buttonMap.ButtonDown(gamefunc_Dpad_Select)) { - if (info.dx < 0 || info.dyaw < 0) loc.bits |= SKB_INV_LEFT; - if (info.dx > 0 || info.dyaw < 0) loc.bits |= SKB_INV_RIGHT; + if (info.dx < 0 || info.dyaw < 0) loc.sbits |= SKB_INV_LEFT; + if (info.dx > 0 || info.dyaw < 0) loc.sbits |= SKB_INV_RIGHT; } - if (gamequit) loc.bits |= SKB_GAMEQUIT; + if (gamequit) loc.sbits |= SKB_GAMEQUIT; if (!onVehicle) { - if (buttonMap.ButtonDown(gamefunc_Jump)) loc.bits |= SKB_JUMP; + if (buttonMap.ButtonDown(gamefunc_Jump)) loc.sbits |= SKB_JUMP; if (buttonMap.ButtonDown(gamefunc_Crouch) || buttonMap.ButtonDown(gamefunc_Toggle_Crouch) || p->crouch_toggle) { - loc.bits |= SKB_CROUCH; - if (isRR()) loc.bits &= ~SKB_JUMP; + loc.sbits |= SKB_CROUCH; + if (isRR()) loc.sbits &= ~SKB_JUMP; } - if (buttonMap.ButtonDown(gamefunc_Aim_Up) || (buttonMap.ButtonDown(gamefunc_Dpad_Aiming) && info.dz > 0)) loc.bits |= SKB_AIM_UP; - if ((buttonMap.ButtonDown(gamefunc_Aim_Down) || (buttonMap.ButtonDown(gamefunc_Dpad_Aiming) && info.dz < 0))) loc.bits |= SKB_AIM_DOWN; - if (G_CheckAutorun(buttonMap.ButtonDown(gamefunc_Run))) loc.bits |= SKB_RUN; - if (buttonMap.ButtonDown(gamefunc_Look_Left) || (isRR() && p->drink_amt > 88)) loc.bits |= SKB_LOOK_LEFT; - if (buttonMap.ButtonDown(gamefunc_Look_Right)) loc.bits |= SKB_LOOK_RIGHT; - if (buttonMap.ButtonDown(gamefunc_Look_Up)) loc.bits |= SKB_LOOK_UP; - if (buttonMap.ButtonDown(gamefunc_Look_Down) || (isRR() && p->drink_amt > 99)) loc.bits |= SKB_LOOK_DOWN; - if (buttonMap.ButtonDown(gamefunc_Quick_Kick)) loc.bits |= SKB_QUICK_KICK; - if (in_mousemode || buttonMap.ButtonDown(gamefunc_Mouse_Aiming)) loc.bits |= SKB_AIMMODE; + if (buttonMap.ButtonDown(gamefunc_Aim_Up) || (buttonMap.ButtonDown(gamefunc_Dpad_Aiming) && info.dz > 0)) loc.sbits |= SKB_AIM_UP; + if ((buttonMap.ButtonDown(gamefunc_Aim_Down) || (buttonMap.ButtonDown(gamefunc_Dpad_Aiming) && info.dz < 0))) loc.sbits |= SKB_AIM_DOWN; + if (G_CheckAutorun(buttonMap.ButtonDown(gamefunc_Run))) loc.sbits |= SKB_RUN; + if (buttonMap.ButtonDown(gamefunc_Look_Left) || (isRR() && p->drink_amt > 88)) loc.sbits |= SKB_LOOK_LEFT; + if (buttonMap.ButtonDown(gamefunc_Look_Right)) loc.sbits |= SKB_LOOK_RIGHT; + if (buttonMap.ButtonDown(gamefunc_Look_Up)) loc.sbits |= SKB_LOOK_UP; + if (buttonMap.ButtonDown(gamefunc_Look_Down) || (isRR() && p->drink_amt > 99)) loc.sbits |= SKB_LOOK_DOWN; + if (buttonMap.ButtonDown(gamefunc_Quick_Kick)) loc.sbits |= SKB_QUICK_KICK; + if (in_mousemode || buttonMap.ButtonDown(gamefunc_Mouse_Aiming)) loc.sbits |= SKB_AIMMODE; int j = WeaponToSend; WeaponToSend = 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.bits & SKB_WEAPONMASK_BITS) == 0) - loc.bits |= ESyncBits::FromInt(j * SKB_FIRST_WEAPON_BIT); + if (j && (loc.sbits & SKB_WEAPONMASK_BITS) == 0) + loc.sbits |= ESyncBits::FromInt(j * SKB_FIRST_WEAPON_BIT); } @@ -723,7 +723,7 @@ int getticssincelastupdate() // //--------------------------------------------------------------------------- -static void processMovement(player_struct *p, input_t &input, ControlInfo &info, double scaleFactor) +static void processMovement(player_struct *p, InputPacket &input, ControlInfo &info, double scaleFactor) { bool mouseaim = in_mousemode || buttonMap.ButtonDown(gamefunc_Mouse_Aiming); @@ -1001,7 +1001,7 @@ static double boatApplyTurn(player_struct *p, int turnl, int turnr, int boat_tur // //--------------------------------------------------------------------------- -static void processVehicleInput(player_struct *p, ControlInfo& info, input_t& input, double scaleAdjust) +static void processVehicleInput(player_struct *p, ControlInfo& info, InputPacket& input, double scaleAdjust) { auto turnspeed = info.mousex + scaleAdjust * info.dyaw * (1. / 32); // originally this was 64, not 32. Why the change? int turnl = buttonMap.ButtonDown(gamefunc_Turn_Left) || buttonMap.ButtonDown(gamefunc_Strafe_Left); @@ -1019,17 +1019,17 @@ static void processVehicleInput(player_struct *p, ControlInfo& info, input_t& in if (p->OnBoat || !p->moto_underwater) { if (buttonMap.ButtonDown(gamefunc_Move_Forward) || buttonMap.ButtonDown(gamefunc_Strafe)) - loc.bits |= SKB_JUMP; + loc.sbits |= SKB_JUMP; if (buttonMap.ButtonDown(gamefunc_Move_Backward)) - loc.bits |= SKB_AIM_UP; + loc.sbits |= SKB_AIM_UP; if (buttonMap.ButtonDown(gamefunc_Run)) - loc.bits |= SKB_CROUCH; + loc.sbits |= SKB_CROUCH; } if (turnl) - loc.bits |= SKB_AIM_DOWN; + loc.sbits |= SKB_AIM_DOWN; if (turnr) - loc.bits |= SKB_LOOK_LEFT; + loc.sbits |= SKB_LOOK_LEFT; double turnvel; @@ -1059,7 +1059,7 @@ static void processVehicleInput(player_struct *p, ControlInfo& info, input_t& in // //--------------------------------------------------------------------------- -static void FinalizeInput(int playerNum, input_t& input, bool vehicle) +static void FinalizeInput(int playerNum, InputPacket& input, bool vehicle) { auto p = &ps[playerNum]; bool blocked = movementBlocked(playerNum) || sprite[p->i].extra <= 0 || (p->dead_flag && !ud.god); @@ -1139,7 +1139,7 @@ void GetInput() if (paused) { loc = {}; - if (gamequit) loc.bits |= SKB_GAMEQUIT; + if (gamequit) loc.sbits |= SKB_GAMEQUIT; return; } @@ -1151,7 +1151,7 @@ void GetInput() double scaleAdjust = !cl_syncinput ? elapsedInputTicks * REALGAMETICSPERSEC / 1000.0 : 1; ControlInfo info; CONTROL_GetInput(&info); - input_t input{}; + InputPacket input{}; if (isRRRA() && (p->OnMotorcycle || p->OnBoat)) { @@ -1178,7 +1178,7 @@ void GetInput() // Do these in the same order as the old code. calcviewpitch(p, scaleAdjust); applylook(myconnectindex, scaleAdjust, input.q16avel); - sethorizon(myconnectindex, loc.bits, scaleAdjust, input.q16horz); + sethorizon(myconnectindex, loc.sbits, scaleAdjust, input.q16horz); } } diff --git a/source/games/duke/src/types.h b/source/games/duke/src/types.h index c7728812d..7ab4ae0f8 100644 --- a/source/games/duke/src/types.h +++ b/source/games/duke/src/types.h @@ -1,5 +1,6 @@ #pragma once #include "names.h" +#include "packet.h" BEGIN_DUKE_NS @@ -47,13 +48,6 @@ struct TileInfo int flags; }; -struct input_t // original name was input which is too generic for a type name. -{ - fixed_t q16avel, q16horz; // These were expanded to 16.16 fixed point. - short fvel, svel; - ESyncBits bits; -}; - struct user_defs { unsigned char god, cashman, eog; diff --git a/source/sw/src/game.cpp b/source/sw/src/game.cpp index b1d5a9c84..3a68114ab 100644 --- a/source/sw/src/game.cpp +++ b/source/sw/src/game.cpp @@ -89,7 +89,7 @@ BEGIN_SW_NS void Logo(const CompletionFunc& completion); void StatScreen(int FinishAnim, CompletionFunc completion); -void getinput(SW_PACKET*, SWBOOL); +void getinput(InputPacket*, SWBOOL); void pClearSpriteList(PLAYERp pp); diff --git a/source/sw/src/game.h b/source/sw/src/game.h index 93b2062e7..33e268378 100644 --- a/source/sw/src/game.h +++ b/source/sw/src/game.h @@ -49,6 +49,7 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms #include "c_cvars.h" #include "mapinfo.h" #include "gamecontrol.h" +#include "packet.h" EXTERN_CVAR(Bool, sw_ninjahack) EXTERN_CVAR(Bool, sw_darts) @@ -204,56 +205,6 @@ extern SWBOOL MenuInputMode; // dist at which actors roam about on their own #define MIN_ACTIVE_RANGE 20000 -// -// 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 -#define SK_INV_HOTKEY_MASK (BIT(SK_INV_HOTKEY_BIT0)|BIT(SK_INV_HOTKEY_BIT1)|BIT(SK_INV_HOTKEY_BIT2)) - -#define SK_AUTO_AIM 7 -#define SK_CENTER_VIEW 8 -#define SK_PAUSE 9 - -#define SK_MESSAGE 11 -#define SK_LOOK_UP 12 -#define SK_LOOK_DOWN 13 -#define SK_CRAWL_LOCK 14 -#define SK_FLY 15 - -#define SK_RUN 16 -#define SK_SHOOT 17 -#define SK_OPERATE 18 -#define SK_JUMP 19 -#define SK_CRAWL 20 -#define SK_SNAP_UP 21 -#define SK_SNAP_DOWN 22 -#define SK_QUIT_GAME 23 - -#define SK_MULTI_VIEW 24 - -#define SK_TURN_180 25 - -#define SK_INV_LEFT 26 -#define SK_INV_RIGHT 27 - -#define SK_INV_USE 29 -#define SK_HIDE_WEAPON 30 -#define SK_SPACE_BAR 31 - - // REDEFINABLE PLAYER KEYS NUMBERS #define PK_FORWARD 0 @@ -921,19 +872,7 @@ enum }; -// TODO: Support compatible read/write of struct for big-endian -struct SW_PACKET -{ - int16_t fvel; - int16_t svel; - fix16_t q16avel; - fix16_t q16aimvel; - fix16_t q16ang; - fix16_t q16horz; - int32_t bits; -}; - -extern SW_PACKET loc; +extern InputPacket loc; #define PACK 1 @@ -1042,11 +981,11 @@ struct PLAYERstruct int bob_z, obob_z; //Multiplayer variables - SW_PACKET input; + InputPacket input; //FIFO queue to hold values while faketimerhandler is called from within the drawing routing #define MOVEFIFOSIZ 256 - SW_PACKET inputfifo[MOVEFIFOSIZ]; + InputPacket inputfifo[MOVEFIFOSIZ]; int movefifoend; @@ -2254,7 +2193,7 @@ void post_analyzesprites(void); // draw.c int COVERsetgamemode(int mode, int xdim, int ydim, int bpp); // draw.c void ScreenCaptureKeys(void); // draw.c -void computergetinput(int snum,SW_PACKET *syn); // jplayer.c +void computergetinput(int snum,InputPacket *syn); // jplayer.c void DrawOverlapRoom(int tx,int ty,int tz,fix16_t tq16ang,fix16_t tq16horiz,short tsectnum); // rooms.c void SetupMirrorTiles(void); // rooms.c diff --git a/source/sw/src/input.cpp b/source/sw/src/input.cpp index 3a6904acc..06e386318 100644 --- a/source/sw/src/input.cpp +++ b/source/sw/src/input.cpp @@ -86,7 +86,7 @@ void GameInterface::ResetFollowPos(bool) } void -getinput(SW_PACKET *loc, SWBOOL tied) +getinput(InputPacket *loc, SWBOOL tied) { int i; PLAYERp pp = Player + myconnectindex; diff --git a/source/sw/src/network.cpp b/source/sw/src/network.cpp index 33717e79d..e1fa0c5f9 100644 --- a/source/sw/src/network.cpp +++ b/source/sw/src/network.cpp @@ -43,7 +43,7 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms BEGIN_SW_NS -void getinput(SW_PACKET *, SWBOOL); +void getinput(InputPacket *, SWBOOL); static uint8_t tempbuf[576], packbuf[576]; int PlayClock; @@ -52,13 +52,13 @@ gNET gNet; #define TIMERUPDATESIZ 32 -//SW_PACKET fsync; +//InputPacket fsync; //Local multiplayer variables // should move this to a local scope of faketimerhandler - do it when able to test -SW_PACKET loc; +InputPacket loc; -//SW_PACKET oloc; +//InputPacket oloc; SWBOOL ready2send = 0; @@ -73,7 +73,7 @@ extern char sync_first[MAXSYNCBYTES][60]; extern int sync_found; // -// Tic Duplication - so you can move multiple times per packet. This is SW_PACKET with the 16 bit values extended to 32 bit. +// Tic Duplication - so you can move multiple times per packet. This is InputPacket with the 16 bit values extended to 32 bit. // typedef struct { @@ -213,7 +213,7 @@ UpdateInputs(void) { memcpy(&pp->inputfifo[pp->movefifoend & (MOVEFIFOSIZ - 1)], &pp->inputfifo[(pp->movefifoend-1) & (MOVEFIFOSIZ - 1)], - sizeof(SW_PACKET)); + sizeof(InputPacket)); pp->movefifoend++; return; diff --git a/source/sw/src/player.cpp b/source/sw/src/player.cpp index 91c6df1ff..bfe7944e6 100644 --- a/source/sw/src/player.cpp +++ b/source/sw/src/player.cpp @@ -1757,7 +1757,7 @@ DoPlayerTurnTurret(PLAYERp pp) short new_ang; short diff; SECTOR_OBJECTp sop = pp->sop; - SW_PACKET last_input; + InputPacket last_input; int fifo_ndx; if (!Prediction) @@ -2859,7 +2859,7 @@ DoPlayerMoveBoat(PLAYERp pp) short save_sectnum; SECTOR_OBJECTp sop = pp->sop; - SW_PACKET last_input; + InputPacket last_input; int fifo_ndx; if (Prediction) @@ -3222,7 +3222,7 @@ DoPlayerMoveTank(PLAYERp pp) int j,k; short startwall,endwall; - SW_PACKET last_input; + InputPacket last_input; int fifo_ndx; SWBOOL RectClip = !!TEST(sop->flags, SOBJ_RECT_CLIP); diff --git a/source/sw/src/save.cpp b/source/sw/src/save.cpp index 93a7262c5..067ec1205 100644 --- a/source/sw/src/save.cpp +++ b/source/sw/src/save.cpp @@ -85,7 +85,7 @@ extern short BossSpriteNum[3]; #define PANEL_SAVE 1 #define ANIM_SAVE 1 -extern SW_PACKET loc; +extern InputPacket loc; extern STATE s_NotRestored[]; OrgTileListP otlist[] = {&orgwalllist, &orgwalloverlist, &orgsectorceilinglist, &orgsectorfloorlist};