- moved sync structure into the playerstruct for easier maintenance.

This commit is contained in:
Christoph Oelckers 2020-09-23 16:56:04 +02:00
parent 5a76dce5f8
commit f4fff5ee30
12 changed files with 36 additions and 37 deletions

View file

@ -1853,7 +1853,7 @@ void moveweapons_d(void)
if (s->picnum == SPIT) if (s->picnum == SPIT)
{ {
playerAddHoriz(&ps[p].q16horiz, &ps[p].horizAdjust, 32); playerAddHoriz(&ps[p].q16horiz, &ps[p].horizAdjust, 32);
sync[p].actions |= SB_CENTERVIEW; ps[p].sync.actions |= SB_CENTERVIEW;
if (ps[p].loogcnt == 0) if (ps[p].loogcnt == 0)
{ {

View file

@ -1400,7 +1400,7 @@ void moveweapons_r(void)
} }
playerAddHoriz(&ps[p].q16horiz, &ps[p].horizAdjust, 32); playerAddHoriz(&ps[p].q16horiz, &ps[p].horizAdjust, 32);
sync[p].actions |= SB_CENTERVIEW; ps[p].sync.actions |= SB_CENTERVIEW;
if (ps[p].loogcnt == 0) if (ps[p].loogcnt == 0)
{ {

View file

@ -49,9 +49,9 @@ void GameInterface::Ticker()
// Make copies so that the originals do not have to be modified. // Make copies so that the originals do not have to be modified.
for (int i = 0; i < MAXPLAYERS; i++) for (int i = 0; i < MAXPLAYERS; i++)
{ {
auto oldactions = sync[i].actions; auto oldactions = ps[i].sync.actions;
sync[i] = playercmds[i].ucmd; ps[i].sync = playercmds[i].ucmd;
if (oldactions & SB_CENTERVIEW) sync[i].actions |= SB_CENTERVIEW; if (oldactions & SB_CENTERVIEW) ps[i].sync.actions |= SB_CENTERVIEW;
} }
if (rtsplaying > 0) rtsplaying--; if (rtsplaying > 0) rtsplaying--;

View file

@ -58,7 +58,6 @@ 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;
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;

View file

@ -46,7 +46,6 @@ 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 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;

View file

@ -128,53 +128,53 @@ 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].actions) & bit)); return (!!((ps[pl].sync.actions) & bit));
} }
inline ESyncBits PlayerInputBits(int pl, ESyncBits bits) inline ESyncBits PlayerInputBits(int pl, ESyncBits bits)
{ {
return (sync[pl].actions & bits); return (ps[pl].sync.actions & bits);
} }
inline void PlayerSetInput(int pl, ESyncBits bit) inline void PlayerSetInput(int pl, ESyncBits bit)
{ {
sync[pl].actions |= bit; ps[pl].sync.actions |= bit;
} }
inline int PlayerNewWeapon(int pl) inline int PlayerNewWeapon(int pl)
{ {
return sync[pl].getNewWeapon(); return ps[pl].sync.getNewWeapon();
} }
inline void PlayerSetItemUsed(int pl, int num) inline void PlayerSetItemUsed(int pl, int num)
{ {
sync[pl].setItemUsed(num - 1); ps[pl].sync.setItemUsed(num - 1);
} }
inline bool PlayerUseItem(int pl, int num) inline bool PlayerUseItem(int pl, int num)
{ {
return sync[pl].isItemUsed(num - 1); return ps[pl].sync.isItemUsed(num - 1);
} }
inline int PlayerInputSideVel(int pl) inline int PlayerInputSideVel(int pl)
{ {
return sync[pl].svel; return ps[pl].sync.svel;
} }
inline int PlayerInputForwardVel(int pl) inline int PlayerInputForwardVel(int pl)
{ {
return sync[pl].fvel; return ps[pl].sync.fvel;
} }
inline fixed_t PlayerInputAngVel(int pl) inline fixed_t PlayerInputAngVel(int pl)
{ {
return sync[pl].q16avel; return ps[pl].sync.q16avel;
} }
inline fixed_t PlayerHorizon(int pl) inline fixed_t PlayerHorizon(int pl)
{ {
return sync[pl].q16horz; return ps[pl].sync.q16horz;
} }
inline void clearfriction() inline void clearfriction()

View file

@ -67,7 +67,7 @@ void hud_input(int snum)
i = p->aim_mode; i = p->aim_mode;
p->aim_mode = !PlayerInput(snum, SB_AIMMODE); p->aim_mode = !PlayerInput(snum, SB_AIMMODE);
if (p->aim_mode < i) if (p->aim_mode < i)
sync[snum].actions |= SB_CENTERVIEW; ps[snum].sync.actions |= SB_CENTERVIEW;
// Backup weapon here as hud_input() is the first function where any one of the weapon variables can change. // Backup weapon here as hud_input() is the first function where any one of the weapon variables can change.
backupweapon(p); backupweapon(p);
@ -483,7 +483,7 @@ void hud_input(int snum)
OnEvent(EVENT_TURNAROUND, -1, snum, -1); OnEvent(EVENT_TURNAROUND, -1, snum, -1);
if (GetGameVarID(g_iReturnVarID, -1, snum) != 0) if (GetGameVarID(g_iReturnVarID, -1, snum) != 0)
{ {
sync[snum].actions &= ~SB_TURNAROUND; ps[snum].sync.actions &= ~SB_TURNAROUND;
} }
} }
} }
@ -963,7 +963,7 @@ static void FinalizeInput(int playerNum, InputPacket& input, bool vehicle)
loc.q16avel = input.q16avel = 0; loc.q16avel = input.q16avel = 0;
} }
if (p->newowner == -1 && !(sync[playerNum].actions & SB_CENTERVIEW)) if (p->newowner == -1 && !(ps[playerNum].sync.actions & SB_CENTERVIEW))
{ {
loc.q16horz = clamp(loc.q16horz + input.q16horz, IntToFixed(-MAXHORIZVEL), IntToFixed(MAXHORIZVEL)); loc.q16horz = clamp(loc.q16horz + input.q16horz, IntToFixed(-MAXHORIZVEL), IntToFixed(MAXHORIZVEL));
} }
@ -1025,8 +1025,8 @@ static void GetInputInternal(InputPacket &locInput, ControlInfo* const hidInput)
// 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);
processq16avel(p, &input.q16avel); processq16avel(p, &input.q16avel);
applylook(&p->q16ang, &p->q16look_ang, &p->q16rotscrnang, &p->one_eighty_count, input.q16avel, &sync[myconnectindex].actions, scaleAdjust, p->crouch_toggle || sync[myconnectindex].actions & SB_CROUCH); applylook(&p->q16ang, &p->q16look_ang, &p->q16rotscrnang, &p->one_eighty_count, input.q16avel, &ps[myconnectindex].sync.actions, scaleAdjust, p->crouch_toggle || ps[myconnectindex].sync.actions & SB_CROUCH);
sethorizon(&p->q16horiz, input.q16horz, &sync[myconnectindex].actions, scaleAdjust); sethorizon(&p->q16horiz, input.q16horz, &ps[myconnectindex].sync.actions, scaleAdjust);
} }
playerProcessHelpers(&p->q16ang, &p->angAdjust, &p->angTarget, &p->q16horiz, &p->horizAdjust, &p->horizTarget, scaleAdjust); playerProcessHelpers(&p->q16ang, &p->angAdjust, &p->angTarget, &p->q16horiz, &p->horizAdjust, &p->horizTarget, scaleAdjust);

View file

@ -165,7 +165,7 @@ void forceplayerangle(int snum)
n = 128 - (krand() & 255); n = 128 - (krand() & 255);
playerAddHoriz(&p->q16horiz, &p->horizAdjust, 64); playerAddHoriz(&p->q16horiz, &p->horizAdjust, 64);
sync[snum].actions |= SB_CENTERVIEW; ps[snum].sync.actions |= SB_CENTERVIEW;
p->setlookang(n >> 1); p->setlookang(n >> 1);
p->setrotscrnang(n >> 1); p->setrotscrnang(n >> 1);
} }
@ -407,7 +407,7 @@ void dokneeattack(int snum, int pi, const std::initializer_list<int> & respawnli
{ {
p->knee_incs++; p->knee_incs++;
playerAddHoriz(&p->q16horiz, &p->horizAdjust, -48); playerAddHoriz(&p->q16horiz, &p->horizAdjust, -48);
sync[snum].actions |= SB_CENTERVIEW; ps[snum].sync.actions |= SB_CENTERVIEW;
if (p->knee_incs > 15) if (p->knee_incs > 15)
{ {
p->knee_incs = 0; p->knee_incs = 0;
@ -961,11 +961,11 @@ void playerCenterView(int snum)
OnEvent(EVENT_RETURNTOCENTER, p->i, snum, -1); OnEvent(EVENT_RETURNTOCENTER, p->i, snum, -1);
if (GetGameVarID(g_iReturnVarID, p->i, snum) == 0) if (GetGameVarID(g_iReturnVarID, p->i, snum) == 0)
{ {
sync[snum].actions |= SB_CENTERVIEW; ps[snum].sync.actions |= SB_CENTERVIEW;
} }
else else
{ {
sync[snum].actions &= ~SB_CENTERVIEW; ps[snum].sync.actions &= ~SB_CENTERVIEW;
} }
} }
@ -976,11 +976,11 @@ void playerLookUp(int snum, ESyncBits actions)
OnEvent(EVENT_LOOKUP, p->i, snum, -1); OnEvent(EVENT_LOOKUP, p->i, snum, -1);
if (GetGameVarID(g_iReturnVarID, p->i, snum) == 0) if (GetGameVarID(g_iReturnVarID, p->i, snum) == 0)
{ {
sync[snum].actions |= SB_CENTERVIEW; ps[snum].sync.actions |= SB_CENTERVIEW;
} }
else else
{ {
sync[snum].actions &= ~SB_LOOK_UP; ps[snum].sync.actions &= ~SB_LOOK_UP;
} }
} }
@ -991,11 +991,11 @@ void playerLookDown(int snum, ESyncBits actions)
OnEvent(EVENT_LOOKDOWN, p->i, snum, -1); OnEvent(EVENT_LOOKDOWN, p->i, snum, -1);
if (GetGameVarID(g_iReturnVarID, p->i, snum) == 0) if (GetGameVarID(g_iReturnVarID, p->i, snum) == 0)
{ {
sync[snum].actions |= SB_CENTERVIEW; ps[snum].sync.actions |= SB_CENTERVIEW;
} }
else else
{ {
sync[snum].actions &= ~SB_LOOK_DOWN; ps[snum].sync.actions &= ~SB_LOOK_DOWN;
} }
} }
@ -1006,7 +1006,7 @@ void playerAimUp(int snum, ESyncBits actions)
OnEvent(EVENT_AIMUP, p->i, snum, -1); OnEvent(EVENT_AIMUP, p->i, snum, -1);
if (GetGameVarID(g_iReturnVarID, p->i, snum) != 0) if (GetGameVarID(g_iReturnVarID, p->i, snum) != 0)
{ {
sync[snum].actions &= ~SB_AIM_UP; ps[snum].sync.actions &= ~SB_AIM_UP;
} }
} }
@ -1017,7 +1017,7 @@ void playerAimDown(int snum, ESyncBits actions)
OnEvent(EVENT_AIMDOWN, p->i, snum, -1); OnEvent(EVENT_AIMDOWN, p->i, snum, -1);
if (GetGameVarID(g_iReturnVarID, p->i, snum) != 0) if (GetGameVarID(g_iReturnVarID, p->i, snum) != 0)
{ {
sync[snum].actions &= ~SB_AIM_DOWN; ps[snum].sync.actions &= ~SB_AIM_DOWN;
} }
} }

View file

@ -2840,7 +2840,7 @@ void processinput_d(int snum)
// may still be needed later for demo recording // may still be needed later for demo recording
processq16avel(p, &sb_avel); processq16avel(p, &sb_avel);
applylook(&p->q16ang, &p->q16look_ang, &p->q16rotscrnang, &p->one_eighty_count, sb_avel, &sync[snum].actions, 1, p->crouch_toggle || actions & SB_CROUCH); applylook(&p->q16ang, &p->q16look_ang, &p->q16rotscrnang, &p->one_eighty_count, sb_avel, &ps[snum].sync.actions, 1, p->crouch_toggle || actions & SB_CROUCH);
} }
if (p->spritebridge == 0) if (p->spritebridge == 0)
@ -3072,7 +3072,7 @@ HORIZONLY:
if (cl_syncinput) if (cl_syncinput)
{ {
sethorizon(&p->q16horiz, PlayerHorizon(snum), &sync[snum].actions, 1); sethorizon(&p->q16horiz, PlayerHorizon(snum), &ps[snum].sync.actions, 1);
} }
checkhardlanding(p); checkhardlanding(p);

View file

@ -3741,7 +3741,7 @@ void processinput_r(int snum)
// may still be needed later for demo recording // may still be needed later for demo recording
processq16avel(p, &sb_avel); processq16avel(p, &sb_avel);
applylook(&p->q16ang, &p->q16look_ang, &p->q16rotscrnang, &p->one_eighty_count, sb_avel, &sync[snum].actions, 1, p->crouch_toggle || actions & SB_CROUCH); applylook(&p->q16ang, &p->q16look_ang, &p->q16rotscrnang, &p->one_eighty_count, sb_avel, &ps[snum].sync.actions, 1, p->crouch_toggle || actions & SB_CROUCH);
apply_seasick(p, 1); apply_seasick(p, 1);
} }
@ -4097,7 +4097,7 @@ HORIZONLY:
if (cl_syncinput) if (cl_syncinput)
{ {
sethorizon(&p->q16horiz, PlayerHorizon(snum), &sync[snum].actions, 1); sethorizon(&p->q16horiz, PlayerHorizon(snum), &ps[snum].sync.actions, 1);
} }
checkhardlanding(p); checkhardlanding(p);

View file

@ -119,7 +119,7 @@ void resetplayerstats(int snum)
p->bobcounter = 0; p->bobcounter = 0;
p->on_ground = 0; p->on_ground = 0;
p->player_par = 0; p->player_par = 0;
sync[snum].actions |= SB_CENTERVIEW; ps[snum].sync.actions |= SB_CENTERVIEW;
p->airleft = 15*26; p->airleft = 15*26;
p->rapid_fire_hold = 0; p->rapid_fire_hold = 0;
p->toggle_key_flag = 0; p->toggle_key_flag = 0;

View file

@ -209,6 +209,7 @@ struct player_struct
// input stuff. // input stuff.
double horizAdjust, angAdjust; double horizAdjust, angAdjust;
fixed_t horizTarget, angTarget; fixed_t horizTarget, angTarget;
InputPacket sync;
// Access helpers for the widened angle and horizon fields. // Access helpers for the widened angle and horizon fields.