- 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.
This commit is contained in:
Christoph Oelckers 2020-08-26 17:12:48 +02:00
parent d05c839d79
commit abf715eace
25 changed files with 273 additions and 266 deletions

View file

@ -40,7 +40,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
BEGIN_BLD_NS BEGIN_BLD_NS
GINPUT gInput, gNetInput; InputPacket gInput, gNetInput;
bool bSilentAim = false; bool bSilentAim = false;
int iTurnCount = 0; int iTurnCount = 0;
@ -133,7 +133,7 @@ void ctrlGetInput(void)
if (paused) if (paused)
return; return;
GINPUT input = {}; InputPacket input = {};
bool mouseaim = in_mousemode || buttonMap.ButtonDown(gamefunc_Mouse_Aiming); bool mouseaim = in_mousemode || buttonMap.ButtonDown(gamefunc_Mouse_Aiming);
if (!mouseaim) gInput.syncFlags.lookCenter = 1; if (!mouseaim) gInput.syncFlags.lookCenter = 1;

View file

@ -24,60 +24,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
BEGIN_BLD_NS BEGIN_BLD_NS
#pragma pack(push, 1) #include "packet.h"
enum extern InputPacket gInput, gNetInput;
{
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 bool bSilentAim; extern bool bSilentAim;
extern fix16_t gViewLook, gViewAngle; extern fix16_t gViewLook, gViewAngle;

View file

@ -44,7 +44,7 @@ int gNetFifoTail = 0;
int gNetFifoHead[8]; int gNetFifoHead[8];
int gPredictTail = 0; int gPredictTail = 0;
int gNetFifoMasterTail = 0; int gNetFifoMasterTail = 0;
GINPUT gFifoInput[256][8]; InputPacket gFifoInput[256][8];
int myMinLag[8]; int myMinLag[8];
int otherMinLag = 0; int otherMinLag = 0;
int myMaxLag = 0; int myMaxLag = 0;
@ -108,7 +108,7 @@ void netGetInput(void)
for (int p = connecthead; p >= 0; p = connectpoint2[p]) for (int p = connecthead; p >= 0; p = connectpoint2[p])
if (gNetFifoHead[myconnectindex]-200 > gNetFifoHead[p]) if (gNetFifoHead[myconnectindex]-200 > gNetFifoHead[p])
return; return;
GINPUT &input = gFifoInput[gNetFifoHead[myconnectindex]&255][myconnectindex]; InputPacket &input = gFifoInput[gNetFifoHead[myconnectindex]&255][myconnectindex];
input = gNetInput; input = gNetInput;
gNetFifoHead[myconnectindex]++; gNetFifoHead[myconnectindex]++;
if (gGameOptions.nGameType == 0 || numplayers == 1) if (gGameOptions.nGameType == 0 || numplayers == 1)
@ -117,9 +117,9 @@ void netGetInput(void)
{ {
if (p != myconnectindex) if (p != myconnectindex)
{ {
GINPUT *pInput1 = &gFifoInput[(gNetFifoHead[p]-1)&255][p]; InputPacket *pInput1 = &gFifoInput[(gNetFifoHead[p]-1)&255][p];
GINPUT *pInput2 = &gFifoInput[gNetFifoHead[p]&255][p]; InputPacket *pInput2 = &gFifoInput[gNetFifoHead[p]&255][p];
memcpy(pInput2, pInput1, sizeof(GINPUT)); memcpy(pInput2, pInput1, sizeof(InputPacket));
gNetFifoHead[p]++; gNetFifoHead[p]++;
} }
} }

View file

@ -49,7 +49,7 @@ extern int gNetFifoTail;
extern int gNetFifoHead[8]; extern int gNetFifoHead[8];
extern int gPredictTail; extern int gPredictTail;
extern int gNetFifoMasterTail; extern int gNetFifoMasterTail;
extern GINPUT gFifoInput[256][8]; extern InputPacket gFifoInput[256][8];
extern int myMinLag[8]; extern int myMinLag[8];
extern int otherMinLag; extern int otherMinLag;
extern int myMaxLag; extern int myMaxLag;

View file

@ -641,7 +641,7 @@ void playerResetPosture(PLAYER* pPlayer) {
void playerStart(int nPlayer, int bNewLevel) void playerStart(int nPlayer, int bNewLevel)
{ {
PLAYER* pPlayer = &gPlayer[nPlayer]; PLAYER* pPlayer = &gPlayer[nPlayer];
GINPUT* pInput = &pPlayer->input; InputPacket* pInput = &pPlayer->input;
ZONE* pStartZone = NULL; ZONE* pStartZone = NULL;
// normal start position // normal start position
@ -1299,7 +1299,7 @@ void ProcessInput(PLAYER *pPlayer)
XSPRITE *pXSprite = pPlayer->pXSprite; XSPRITE *pXSprite = pPlayer->pXSprite;
int nSprite = pPlayer->nSprite; int nSprite = pPlayer->nSprite;
POSTURE *pPosture = &pPlayer->pPosture[pPlayer->lifeMode][pPlayer->posture]; POSTURE *pPosture = &pPlayer->pPosture[pPlayer->lifeMode][pPlayer->posture];
GINPUT *pInput = &pPlayer->input; InputPacket *pInput = &pPlayer->input;
if (pPlayer == gMe && numplayers == 1) if (pPlayer == gMe && numplayers == 1)
{ {

View file

@ -86,7 +86,7 @@ struct PLAYER
spritetype* pSprite; spritetype* pSprite;
XSPRITE* pXSprite; XSPRITE* pXSprite;
DUDEINFO* pDudeInfo; DUDEINFO* pDudeInfo;
GINPUT input; InputPacket input;
uint8_t newWeapon; uint8_t newWeapon;
int used1; // something related to game checksum int used1; // something related to game checksum
int weaponQav; int weaponQav;

View file

@ -49,7 +49,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
BEGIN_BLD_NS BEGIN_BLD_NS
void fakePlayerProcess(PLAYER* pPlayer, GINPUT* pInput); void fakePlayerProcess(PLAYER* pPlayer, InputPacket* pInput);
void fakeActProcessSprites(void); void fakeActProcessSprites(void);
bool gPrediction = true; bool gPrediction = true;
@ -101,7 +101,7 @@ void viewInitializePrediction(void)
} }
} }
void viewUpdatePrediction(GINPUT *pInput) void viewUpdatePrediction(InputPacket *pInput)
{ {
predictOld = predict; predictOld = predict;
short bakCstat = gMe->pSprite->cstat; 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; 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]; 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; predict.at2c = (-fix16_to_int(predict.at24))<<7;
} }
void fakePlayerProcess(PLAYER *pPlayer, GINPUT *pInput) void fakePlayerProcess(PLAYER *pPlayer, InputPacket *pInput)
{ {
spritetype *pSprite = pPlayer->pSprite; spritetype *pSprite = pPlayer->pSprite;
XSPRITE *pXSprite = pPlayer->pXSprite; XSPRITE *pXSprite = pPlayer->pXSprite;

View file

@ -144,7 +144,7 @@ extern double gInterpolate;
void hudDraw(PLAYER* gView, int nSectnum, int defaultHoriz, double bobx, double boby, double zDelta, int basepal); void hudDraw(PLAYER* gView, int nSectnum, int defaultHoriz, double bobx, double boby, double zDelta, int basepal);
void viewInitializePrediction(void); void viewInitializePrediction(void);
void viewUpdatePrediction(GINPUT *pInput); void viewUpdatePrediction(InputPacket *pInput);
void viewCorrectPrediction(void); void viewCorrectPrediction(void);
void viewBackupView(int nPlayer); void viewBackupView(int nPlayer);
void viewCorrectViewOffsets(int nPlayer, vec3_t const *oldpos); void viewCorrectViewOffsets(int nPlayer, vec3_t const *oldpos);

191
source/core/packet.h Normal file
View file

@ -0,0 +1,191 @@
#pragma once
#include <stdint.h>
#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<ESyncBits_, uint32_t>;
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;
};

View file

@ -64,7 +64,7 @@ int htimer = 0;
int EndLevel = false; int EndLevel = false;
LocalInput localInput; InputPacket localInput;
//////// ////////

View file

@ -20,23 +20,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#define __input_h__ #define __input_h__
#include "compat.h" #include "compat.h"
#include "packet.h"
BEGIN_PS_NS 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 // 32 bytes
struct PlayerInput struct PlayerInput
{ {
@ -49,15 +36,6 @@ struct PlayerInput
int8_t nItem; int8_t nItem;
}; };
struct LocalInput
{
int svel;
int fvel;
fix16_t q16avel;
uint16_t buttons;
fix16_t q16horz;
};
void InitInput(); void InitInput();
void UpdateInputs(); void UpdateInputs();
@ -67,7 +45,7 @@ void ClearSpaceBar(short nPlayer);
int GetLocalInput(); int GetLocalInput();
extern PlayerInput sPlayerInput[]; extern PlayerInput sPlayerInput[];
extern LocalInput localInput; extern InputPacket localInput;
extern int nNetMoves; extern int nNetMoves;
extern int lLocalCodes; extern int lLocalCodes;

View file

@ -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<ESyncBits_, uint32_t>;
DEFINE_TFLAGS_OPERATORS(ESyncBits)
enum EQuote enum EQuote
{ {

View file

@ -2,6 +2,7 @@
#include "screenjob.h" #include "screenjob.h"
#include "constants.h" #include "constants.h"
#include "packet.h"
struct MapRecord; struct MapRecord;

View file

@ -44,7 +44,7 @@ BEGIN_DUKE_NS
// All access to the input queues should go through this function interface. // 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 movefifoend[MAXPLAYERS];
static int movefifoplc; static int movefifoplc;
static int bufferjitter; static int bufferjitter;
@ -60,7 +60,7 @@ void clearfifo(void)
static inline void GetNextInput() static inline void GetNextInput()
{ {
for (int i = connecthead; i >= 0; i = connectpoint2[i]) 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++; movefifoplc++;
} }
@ -70,7 +70,7 @@ static void advancequeue(int myconnectindex)
movefifoend[myconnectindex]++; movefifoend[myconnectindex]++;
} }
static input_t& nextinput(int myconnectindex) static InputPacket& nextinput(int myconnectindex)
{ {
return inputfifo[movefifoend[myconnectindex] & (MOVEFIFOSIZ - 1)][myconnectindex]; return inputfifo[movefifoend[myconnectindex] & (MOVEFIFOSIZ - 1)][myconnectindex];
} }

View file

@ -58,12 +58,12 @@ int otherp;
TileInfo tileinfo[MAXTILES]; // This is not from EDuke32. TileInfo tileinfo[MAXTILES]; // This is not from EDuke32.
ActorInfo actorinfo[MAXTILES]; ActorInfo actorinfo[MAXTILES];
int actor_tog; int actor_tog;
input_t sync[MAXPLAYERS]; InputPacket sync[MAXPLAYERS];
int16_t max_ammo_amount[MAX_WEAPONS]; int16_t max_ammo_amount[MAX_WEAPONS];
int16_t weaponsandammosprites[15]; int16_t weaponsandammosprites[15];
int PHEIGHT = PHEIGHT_DUKE; int PHEIGHT = PHEIGHT_DUKE;
int duke3d_globalflags; int duke3d_globalflags;
input_t loc; InputPacket loc;
uint8_t ready2send; uint8_t ready2send;
int gamequit; int gamequit;
int playerswhenstarted; int playerswhenstarted;

View file

@ -45,13 +45,13 @@ extern ActorInfo actorinfo[MAXTILES]; // static state
extern int actor_tog; // cheat state extern int actor_tog; // cheat state
extern intptr_t apScriptGameEvent[]; extern intptr_t apScriptGameEvent[];
extern TArray<int> ScriptCode; extern TArray<int> ScriptCode;
extern input_t sync[MAXPLAYERS]; extern InputPacket sync[MAXPLAYERS];
extern int16_t max_ammo_amount[MAX_WEAPONS]; extern int16_t max_ammo_amount[MAX_WEAPONS];
extern int16_t weaponsandammosprites[15]; extern int16_t weaponsandammosprites[15];
extern int32_t PHEIGHT; extern int32_t PHEIGHT;
extern int duke3d_globalflags; extern int duke3d_globalflags;
extern uint8_t ready2send; extern uint8_t ready2send;
extern input_t loc; extern InputPacket loc;
extern int gamequit; extern int gamequit;
extern int playerswhenstarted; extern int playerswhenstarted;
extern int show_shareware; extern int show_shareware;

View file

@ -118,22 +118,22 @@ inline bool isIn(int value, const std::initializer_list<int>& list)
// these are mainly here to avoid directly accessing the input data so that it can be more easily refactored later. // 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) inline bool PlayerInput(int pl, ESyncBits bit)
{ {
return (!!((sync[pl].bits) & bit)); return (!!((sync[pl].sbits) & bit));
} }
inline void PlayerSetInput(int pl, ESyncBits bit) inline void PlayerSetInput(int pl, ESyncBits bit)
{ {
sync[pl].bits |= bit; sync[pl].sbits |= bit;
} }
inline void PlayerClearInput(int pl, ESyncBits bit) inline void PlayerClearInput(int pl, ESyncBits bit)
{ {
sync[pl].bits &= ~bit; sync[pl].sbits &= ~bit;
} }
inline ESyncBits PlayerInputBits(int pl, ESyncBits bits) inline ESyncBits PlayerInputBits(int pl, ESyncBits bits)
{ {
return (sync[pl].bits & bits); return (sync[pl].sbits & bits);
} }
inline int PlayerInputSideVel(int pl) inline int PlayerInputSideVel(int pl)

View file

@ -623,39 +623,39 @@ enum
static void processInputBits(player_struct *p, ControlInfo &info) static void processInputBits(player_struct *p, ControlInfo &info)
{ {
bool onVehicle = p->OnMotorcycle || p->OnBoat; bool onVehicle = p->OnMotorcycle || p->OnBoat;
if (buttonMap.ButtonDown(gamefunc_Fire)) loc.bits |= SKB_FIRE; if (buttonMap.ButtonDown(gamefunc_Fire)) loc.sbits |= SKB_FIRE;
if (buttonMap.ButtonDown(gamefunc_Open)) loc.bits |= SKB_OPEN; if (buttonMap.ButtonDown(gamefunc_Open)) loc.sbits |= SKB_OPEN;
// These 3 bits are only available when not riding a bike or boat. // These 3 bits are only available when not riding a bike or boat.
if (onVehicle) BitsToSend &= ~(SKB_HOLSTER|SKB_TURNAROUND|SKB_CENTER_VIEW); if (onVehicle) BitsToSend &= ~(SKB_HOLSTER|SKB_TURNAROUND|SKB_CENTER_VIEW);
loc.bits |= BitsToSend; loc.sbits |= BitsToSend;
BitsToSend = 0; BitsToSend = 0;
if (buttonMap.ButtonDown(gamefunc_Dpad_Select)) 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.sbits |= 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_RIGHT;
} }
if (gamequit) loc.bits |= SKB_GAMEQUIT; if (gamequit) loc.sbits |= SKB_GAMEQUIT;
if (!onVehicle) 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) if (buttonMap.ButtonDown(gamefunc_Crouch) || buttonMap.ButtonDown(gamefunc_Toggle_Crouch) || p->crouch_toggle)
{ {
loc.bits |= SKB_CROUCH; loc.sbits |= SKB_CROUCH;
if (isRR()) loc.bits &= ~SKB_JUMP; 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_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.bits |= SKB_AIM_DOWN; 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.bits |= SKB_RUN; if (G_CheckAutorun(buttonMap.ButtonDown(gamefunc_Run))) loc.sbits |= SKB_RUN;
if (buttonMap.ButtonDown(gamefunc_Look_Left) || (isRR() && p->drink_amt > 88)) loc.bits |= SKB_LOOK_LEFT; if (buttonMap.ButtonDown(gamefunc_Look_Left) || (isRR() && p->drink_amt > 88)) loc.sbits |= SKB_LOOK_LEFT;
if (buttonMap.ButtonDown(gamefunc_Look_Right)) loc.bits |= SKB_LOOK_RIGHT; if (buttonMap.ButtonDown(gamefunc_Look_Right)) loc.sbits |= SKB_LOOK_RIGHT;
if (buttonMap.ButtonDown(gamefunc_Look_Up)) loc.bits |= SKB_LOOK_UP; if (buttonMap.ButtonDown(gamefunc_Look_Up)) loc.sbits |= SKB_LOOK_UP;
if (buttonMap.ButtonDown(gamefunc_Look_Down) || (isRR() && p->drink_amt > 99)) loc.bits |= SKB_LOOK_DOWN; if (buttonMap.ButtonDown(gamefunc_Look_Down) || (isRR() && p->drink_amt > 99)) loc.sbits |= SKB_LOOK_DOWN;
if (buttonMap.ButtonDown(gamefunc_Quick_Kick)) loc.bits |= SKB_QUICK_KICK; if (buttonMap.ButtonDown(gamefunc_Quick_Kick)) loc.sbits |= SKB_QUICK_KICK;
if (in_mousemode || buttonMap.ButtonDown(gamefunc_Mouse_Aiming)) loc.bits |= SKB_AIMMODE; if (in_mousemode || buttonMap.ButtonDown(gamefunc_Mouse_Aiming)) loc.sbits |= SKB_AIMMODE;
int j = WeaponToSend; int j = WeaponToSend;
WeaponToSend = 0; 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 = 11;
if (buttonMap.ButtonDown(gamefunc_Dpad_Select) && info.dz < 0) j = 12; if (buttonMap.ButtonDown(gamefunc_Dpad_Select) && info.dz < 0) j = 12;
if (j && (loc.bits & SKB_WEAPONMASK_BITS) == 0) if (j && (loc.sbits & SKB_WEAPONMASK_BITS) == 0)
loc.bits |= ESyncBits::FromInt(j * SKB_FIRST_WEAPON_BIT); 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); 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? 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); 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 (p->OnBoat || !p->moto_underwater)
{ {
if (buttonMap.ButtonDown(gamefunc_Move_Forward) || buttonMap.ButtonDown(gamefunc_Strafe)) if (buttonMap.ButtonDown(gamefunc_Move_Forward) || buttonMap.ButtonDown(gamefunc_Strafe))
loc.bits |= SKB_JUMP; loc.sbits |= SKB_JUMP;
if (buttonMap.ButtonDown(gamefunc_Move_Backward)) if (buttonMap.ButtonDown(gamefunc_Move_Backward))
loc.bits |= SKB_AIM_UP; loc.sbits |= SKB_AIM_UP;
if (buttonMap.ButtonDown(gamefunc_Run)) if (buttonMap.ButtonDown(gamefunc_Run))
loc.bits |= SKB_CROUCH; loc.sbits |= SKB_CROUCH;
} }
if (turnl) if (turnl)
loc.bits |= SKB_AIM_DOWN; loc.sbits |= SKB_AIM_DOWN;
if (turnr) if (turnr)
loc.bits |= SKB_LOOK_LEFT; loc.sbits |= SKB_LOOK_LEFT;
double turnvel; 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]; auto p = &ps[playerNum];
bool blocked = movementBlocked(playerNum) || sprite[p->i].extra <= 0 || (p->dead_flag && !ud.god); bool blocked = movementBlocked(playerNum) || sprite[p->i].extra <= 0 || (p->dead_flag && !ud.god);
@ -1139,7 +1139,7 @@ void GetInput()
if (paused) if (paused)
{ {
loc = {}; loc = {};
if (gamequit) loc.bits |= SKB_GAMEQUIT; if (gamequit) loc.sbits |= SKB_GAMEQUIT;
return; return;
} }
@ -1151,7 +1151,7 @@ void GetInput()
double scaleAdjust = !cl_syncinput ? elapsedInputTicks * REALGAMETICSPERSEC / 1000.0 : 1; double scaleAdjust = !cl_syncinput ? elapsedInputTicks * REALGAMETICSPERSEC / 1000.0 : 1;
ControlInfo info; ControlInfo info;
CONTROL_GetInput(&info); CONTROL_GetInput(&info);
input_t input{}; InputPacket input{};
if (isRRRA() && (p->OnMotorcycle || p->OnBoat)) if (isRRRA() && (p->OnMotorcycle || p->OnBoat))
{ {
@ -1178,7 +1178,7 @@ void GetInput()
// Do these in the same order as the old code. // Do these in the same order as the old code.
calcviewpitch(p, scaleAdjust); calcviewpitch(p, scaleAdjust);
applylook(myconnectindex, scaleAdjust, input.q16avel); applylook(myconnectindex, scaleAdjust, input.q16avel);
sethorizon(myconnectindex, loc.bits, scaleAdjust, input.q16horz); sethorizon(myconnectindex, loc.sbits, scaleAdjust, input.q16horz);
} }
} }

View file

@ -1,5 +1,6 @@
#pragma once #pragma once
#include "names.h" #include "names.h"
#include "packet.h"
BEGIN_DUKE_NS BEGIN_DUKE_NS
@ -47,13 +48,6 @@ struct TileInfo
int flags; 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 struct user_defs
{ {
unsigned char god, cashman, eog; unsigned char god, cashman, eog;

View file

@ -89,7 +89,7 @@ BEGIN_SW_NS
void Logo(const CompletionFunc& completion); void Logo(const CompletionFunc& completion);
void StatScreen(int FinishAnim, CompletionFunc completion); void StatScreen(int FinishAnim, CompletionFunc completion);
void getinput(SW_PACKET*, SWBOOL); void getinput(InputPacket*, SWBOOL);
void pClearSpriteList(PLAYERp pp); void pClearSpriteList(PLAYERp pp);

View file

@ -49,6 +49,7 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms
#include "c_cvars.h" #include "c_cvars.h"
#include "mapinfo.h" #include "mapinfo.h"
#include "gamecontrol.h" #include "gamecontrol.h"
#include "packet.h"
EXTERN_CVAR(Bool, sw_ninjahack) EXTERN_CVAR(Bool, sw_ninjahack)
EXTERN_CVAR(Bool, sw_darts) EXTERN_CVAR(Bool, sw_darts)
@ -204,56 +205,6 @@ extern SWBOOL MenuInputMode;
// dist at which actors roam about on their own // dist at which actors roam about on their own
#define MIN_ACTIVE_RANGE 20000 #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 // REDEFINABLE PLAYER KEYS NUMBERS
#define PK_FORWARD 0 #define PK_FORWARD 0
@ -921,19 +872,7 @@ enum
}; };
// TODO: Support compatible read/write of struct for big-endian extern InputPacket loc;
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;
#define PACK 1 #define PACK 1
@ -1042,11 +981,11 @@ struct PLAYERstruct
int bob_z, obob_z; int bob_z, obob_z;
//Multiplayer variables //Multiplayer variables
SW_PACKET input; InputPacket input;
//FIFO queue to hold values while faketimerhandler is called from within the drawing routing //FIFO queue to hold values while faketimerhandler is called from within the drawing routing
#define MOVEFIFOSIZ 256 #define MOVEFIFOSIZ 256
SW_PACKET inputfifo[MOVEFIFOSIZ]; InputPacket inputfifo[MOVEFIFOSIZ];
int movefifoend; int movefifoend;
@ -2254,7 +2193,7 @@ void post_analyzesprites(void); // draw.c
int COVERsetgamemode(int mode, int xdim, int ydim, int bpp); // draw.c int COVERsetgamemode(int mode, int xdim, int ydim, int bpp); // draw.c
void ScreenCaptureKeys(void); // 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 DrawOverlapRoom(int tx,int ty,int tz,fix16_t tq16ang,fix16_t tq16horiz,short tsectnum); // rooms.c
void SetupMirrorTiles(void); // rooms.c void SetupMirrorTiles(void); // rooms.c

View file

@ -86,7 +86,7 @@ void GameInterface::ResetFollowPos(bool)
} }
void void
getinput(SW_PACKET *loc, SWBOOL tied) getinput(InputPacket *loc, SWBOOL tied)
{ {
int i; int i;
PLAYERp pp = Player + myconnectindex; PLAYERp pp = Player + myconnectindex;

View file

@ -43,7 +43,7 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms
BEGIN_SW_NS BEGIN_SW_NS
void getinput(SW_PACKET *, SWBOOL); void getinput(InputPacket *, SWBOOL);
static uint8_t tempbuf[576], packbuf[576]; static uint8_t tempbuf[576], packbuf[576];
int PlayClock; int PlayClock;
@ -52,13 +52,13 @@ gNET gNet;
#define TIMERUPDATESIZ 32 #define TIMERUPDATESIZ 32
//SW_PACKET fsync; //InputPacket fsync;
//Local multiplayer variables //Local multiplayer variables
// should move this to a local scope of faketimerhandler - do it when able to test // 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; SWBOOL ready2send = 0;
@ -73,7 +73,7 @@ extern char sync_first[MAXSYNCBYTES][60];
extern int sync_found; 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 typedef struct
{ {
@ -213,7 +213,7 @@ UpdateInputs(void)
{ {
memcpy(&pp->inputfifo[pp->movefifoend & (MOVEFIFOSIZ - 1)], memcpy(&pp->inputfifo[pp->movefifoend & (MOVEFIFOSIZ - 1)],
&pp->inputfifo[(pp->movefifoend-1) & (MOVEFIFOSIZ - 1)], &pp->inputfifo[(pp->movefifoend-1) & (MOVEFIFOSIZ - 1)],
sizeof(SW_PACKET)); sizeof(InputPacket));
pp->movefifoend++; pp->movefifoend++;
return; return;

View file

@ -1757,7 +1757,7 @@ DoPlayerTurnTurret(PLAYERp pp)
short new_ang; short new_ang;
short diff; short diff;
SECTOR_OBJECTp sop = pp->sop; SECTOR_OBJECTp sop = pp->sop;
SW_PACKET last_input; InputPacket last_input;
int fifo_ndx; int fifo_ndx;
if (!Prediction) if (!Prediction)
@ -2859,7 +2859,7 @@ DoPlayerMoveBoat(PLAYERp pp)
short save_sectnum; short save_sectnum;
SECTOR_OBJECTp sop = pp->sop; SECTOR_OBJECTp sop = pp->sop;
SW_PACKET last_input; InputPacket last_input;
int fifo_ndx; int fifo_ndx;
if (Prediction) if (Prediction)
@ -3222,7 +3222,7 @@ DoPlayerMoveTank(PLAYERp pp)
int j,k; int j,k;
short startwall,endwall; short startwall,endwall;
SW_PACKET last_input; InputPacket last_input;
int fifo_ndx; int fifo_ndx;
SWBOOL RectClip = !!TEST(sop->flags, SOBJ_RECT_CLIP); SWBOOL RectClip = !!TEST(sop->flags, SOBJ_RECT_CLIP);

View file

@ -85,7 +85,7 @@ extern short BossSpriteNum[3];
#define PANEL_SAVE 1 #define PANEL_SAVE 1
#define ANIM_SAVE 1 #define ANIM_SAVE 1
extern SW_PACKET loc; extern InputPacket loc;
extern STATE s_NotRestored[]; extern STATE s_NotRestored[];
OrgTileListP otlist[] = {&orgwalllist, &orgwalloverlist, &orgsectorceilinglist, &orgsectorfloorlist}; OrgTileListP otlist[] = {&orgwalllist, &orgwalloverlist, &orgsectorceilinglist, &orgsectorfloorlist};