- Exhumed: Eliminate PlayerInput struct in favour of InputPacket object PlayerList::input.

This commit is contained in:
Mitchell Richters 2023-03-13 21:08:11 +11:00
parent 67c7dd65f9
commit 9ffc65fa48
6 changed files with 27 additions and 55 deletions

View file

@ -98,8 +98,6 @@ void InitCheats();
int EndLevel = 0;
InputPacket localInput;
////////
void ResetEngine()
@ -375,9 +373,14 @@ void GameInterface::Ticker()
// disable synchronised input if set by game.
resetForcedSyncInput();
// set new player input, factoring in previous view centering.
auto oldactions = PlayerList[nLocalPlayer].input.actions;
PlayerList[nLocalPlayer].input = playercmds[nLocalPlayer].ucmd;
if (oldactions & SB_CENTERVIEW) PlayerList[nLocalPlayer].input.actions |= SB_CENTERVIEW;
auto& lPlayerVel = PlayerList[nLocalPlayer].pActor->vel.XY();
auto inputvect = DVector2(localInput.fvel, localInput.svel).Rotated(inita) * 0.375;
auto inputvect = DVector2(PlayerList[nLocalPlayer].input.fvel, PlayerList[nLocalPlayer].input.svel).Rotated(inita) * 0.375;
for (int i = 0; i < 4; i++)
{
@ -387,7 +390,7 @@ void GameInterface::Ticker()
}
UpdateInterpolations();
if (localInput.actions & SB_INVPREV)
if (PlayerList[nLocalPlayer].input.actions & SB_INVPREV)
{
int nItem = PlayerList[nLocalPlayer].nItem;
@ -404,7 +407,7 @@ void GameInterface::Ticker()
if (i > 0) PlayerList[nLocalPlayer].nItem = nItem;
}
if (localInput.actions & SB_INVNEXT)
if (PlayerList[nLocalPlayer].input.actions & SB_INVNEXT)
{
int nItem = PlayerList[nLocalPlayer].nItem;
@ -421,19 +424,19 @@ void GameInterface::Ticker()
if (i > 0) PlayerList[nLocalPlayer].nItem = nItem;
}
if (localInput.actions & SB_INVUSE)
if (PlayerList[nLocalPlayer].input.actions & SB_INVUSE)
{
if (PlayerList[nLocalPlayer].nItem != -1)
{
localInput.setItemUsed(PlayerList[nLocalPlayer].nItem);
PlayerList[nLocalPlayer].input.setItemUsed(PlayerList[nLocalPlayer].nItem);
}
}
for (int i = 0; i < 6; i++)
{
if (localInput.isItemUsed(i))
if (PlayerList[nLocalPlayer].input.isItemUsed(i))
{
localInput.clearItemUsed(i);
PlayerList[nLocalPlayer].input.clearItemUsed(i);
if (PlayerList[nLocalPlayer].items[i] > 0)
{
if (nItemMagic[i] <= PlayerList[nLocalPlayer].nMagic)
@ -446,7 +449,7 @@ void GameInterface::Ticker()
}
auto currWeap = PlayerList[nLocalPlayer].nCurrentWeapon;
int weap2 = localInput.getNewWeapon();
int weap2 = PlayerList[nLocalPlayer].input.getNewWeapon();
if (weap2 == WeaponSel_Next)
{
auto newWeap = currWeap == 6 ? 0 : currWeap + 1;
@ -455,7 +458,7 @@ void GameInterface::Ticker()
newWeap++;
if (newWeap > 6) newWeap = 0;
}
localInput.setNewWeapon(newWeap + 1);
PlayerList[nLocalPlayer].input.setNewWeapon(newWeap + 1);
}
else if (weap2 == WeaponSel_Prev)
{
@ -464,7 +467,7 @@ void GameInterface::Ticker()
{
newWeap--;
}
localInput.setNewWeapon(newWeap + 1);
PlayerList[nLocalPlayer].input.setNewWeapon(newWeap + 1);
}
else if (weap2 == WeaponSel_Alt)
{
@ -472,15 +475,8 @@ void GameInterface::Ticker()
}
// make weapon selection persist until it gets used up.
int weap = sPlayerInput[nLocalPlayer].getNewWeapon();
if (weap2 <= 0 || weap2 > 7) sPlayerInput[nLocalPlayer].SetNewWeapon(weap);
auto oldactions = sPlayerInput[nLocalPlayer].actions;
sPlayerInput[nLocalPlayer].actions = localInput.actions;
if (oldactions & SB_CENTERVIEW) sPlayerInput[nLocalPlayer].actions |= SB_CENTERVIEW;
sPlayerInput[nLocalPlayer].nAngle = localInput.avel;
sPlayerInput[nLocalPlayer].pan = localInput.horz;
int weap = PlayerList[nLocalPlayer].input.getNewWeapon();
if (weap2 <= 0 || weap2 > 7) PlayerList[nLocalPlayer].input.setNewWeapon(weap);
PlayerList[nLocalPlayer].pTarget = Ra[nLocalPlayer].pTarget = bestTarget;

View file

@ -25,7 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
BEGIN_PS_NS
PlayerInput sPlayerInput[kMaxPlayers];
static InputPacket localInput;
//---------------------------------------------------------------------------
//
@ -35,7 +35,7 @@ PlayerInput sPlayerInput[kMaxPlayers];
void ClearSpaceBar(int nPlayer)
{
sPlayerInput[nPlayer].actions &= SB_OPEN;
PlayerList[nPlayer].input.actions &= SB_OPEN;
buttonMap.ClearButton(gamefunc_Open);
}

View file

@ -29,31 +29,7 @@ enum {
kButtonCheatItems = 0x100,
};
// 32 bytes
struct PlayerInput
{
float nAngle;
float pan;
ESyncBits actions;
int getNewWeapon() const
{
return (actions & SB_WEAPONMASK_BITS).GetValue();
}
void SetNewWeapon(int weap)
{
actions = (actions & ~SB_WEAPONMASK_BITS) | (ESyncBits::FromInt(weap) & SB_WEAPONMASK_BITS);
}
};
void ClearSpaceBar(int nPlayer);
int GetLocalInput();
extern PlayerInput sPlayerInput[];
extern InputPacket localInput;
END_PS_NS

View file

@ -432,7 +432,6 @@ void RestartPlayer(int nPlayer)
plr->ototalvel = plr->totalvel = 0;
memset(&sPlayerInput[nPlayer], 0, sizeof(PlayerInput));
PlayerList[nPlayer].nCurrentItem = -1;
plr->nDeathType = 0;
@ -982,7 +981,7 @@ void AIPlayer::Tick(RunListEvent* ev)
// loc_1A494:
if (SyncInput())
{
PlayerList[nPlayer].pActor->spr.Angles.Yaw += DAngle::fromDeg(sPlayerInput[nPlayer].nAngle);
PlayerList[nPlayer].pActor->spr.Angles.Yaw += DAngle::fromDeg(PlayerList[nPlayer].input.avel);
}
PlayerList[nPlayer].Angles.doYawKeys(&sPlayerInput[nLocalPlayer].actions);
@ -1215,7 +1214,7 @@ sectdone:
int var_5C = pViewSect->Flag & kSectUnderwater;
auto actions = sPlayerInput[nPlayer].actions;
auto actions = PlayerList[nPlayer].input.actions;
// loc_1AEF5:
if (PlayerList[nPlayer].nHealth > 0)
@ -2425,7 +2424,7 @@ sectdone:
// loc_1BE70:
// Handle player pressing number keys to change weapon
uint8_t var_90 = sPlayerInput[nPlayer].getNewWeapon();
uint8_t var_90 = PlayerList[nPlayer].input.getNewWeapon();
if (var_90)
{
@ -2469,12 +2468,12 @@ sectdone:
if (SyncInput())
{
pPlayer->pActor->spr.Angles.Pitch += DAngle::fromDeg(sPlayerInput[nPlayer].pan);
pPlayer->pActor->spr.Angles.Pitch += DAngle::fromDeg(PlayerList[nPlayer].input.horz);
}
pPlayer->Angles.doPitchKeys(&sPlayerInput[nLocalPlayer].actions, sPlayerInput[nPlayer].pan);
pPlayer->Angles.doPitchKeys(&PlayerList[nLocalPlayer].input.actions, PlayerList[nPlayer].input.pan);
if (actions & (SB_AIM_UP | SB_AIM_DOWN) || sPlayerInput[nPlayer].pan)
if (actions & (SB_AIM_UP | SB_AIM_DOWN) || PlayerList[nPlayer].input.horz)
{
pPlayer->nDestVertPan = pPlayer->pActor->spr.Angles.Pitch;
pPlayer->bPlayerPan = pPlayer->bLockPan = true;

View file

@ -79,6 +79,7 @@ struct Player
bool bPlayerPan, bLockPan;
DAngle nDestVertPan;
InputPacket input;
PlayerAngles Angles;
sectortype* pPlayerPushSect;
sectortype* pPlayerViewSect;

View file

@ -196,7 +196,7 @@ void DoSpiritHead()
static int dimSectCount = 0;
auto pSpiritSpr = pSpiritSprite;
sPlayerInput[0].actions |= SB_CENTERVIEW;
PlayerList[0].input.actions |= SB_CENTERVIEW;
switch (nHeadStage)
{