- consolidation of invprev, invnext and invuse.

This commit is contained in:
Christoph Oelckers 2020-08-27 22:19:24 +02:00
parent 43de0d8312
commit 447573aa36
13 changed files with 111 additions and 118 deletions

View file

@ -349,10 +349,7 @@ void registerinputcommands()
C_RegisterFunction("pause", nullptr, [](CCmdFuncPtr)->int { BitsToSend.pause = 1; sendPause = true; return CCMD_OK; });
C_RegisterFunction("centerview", nullptr, [](CCmdFuncPtr)->int { BitsToSend.lookCenter = 1; return CCMD_OK; });
C_RegisterFunction("holsterweapon", nullptr, [](CCmdFuncPtr)->int { BitsToSend.holsterWeapon = 1; return CCMD_OK; });
C_RegisterFunction("invprev", nullptr, [](CCmdFuncPtr)->int { BitsToSend.prevItem = 1; return CCMD_OK; });
C_RegisterFunction("invnext", nullptr, [](CCmdFuncPtr)->int { BitsToSend.nextItem = 1; return CCMD_OK; });
C_RegisterFunction("turnaround", nullptr, [](CCmdFuncPtr)->int { BitsToSend.spin180 = 1; return CCMD_OK; });
C_RegisterFunction("invuse", nullptr, [](CCmdFuncPtr)->int { BitsToSend.useItem = 1; return CCMD_OK; });
}
// This is called from ImputState::ClearAllInput and resets all static state being used here.

View file

@ -1635,19 +1635,19 @@ void ProcessInput(PLAYER *pPlayer)
pPlayer->q16slopehoriz = 0;
}
pPlayer->slope = (-fix16_to_int(pPlayer->q16horiz))<<7;
if (pInput->syncFlags.prevItem)
if (pInput->actions & SB_INVPREV)
{
pInput->syncFlags.prevItem = 0;
pInput->actions&= ~SB_INVPREV;
packPrevItem(pPlayer);
}
if (pInput->syncFlags.nextItem)
if (pInput->actions & SB_INVNEXT)
{
pInput->syncFlags.nextItem = 0;
pInput->actions &= ~SB_INVNEXT;
packNextItem(pPlayer);
}
if (pInput->syncFlags.useItem)
if (pInput->actions & SB_INVUSE)
{
pInput->syncFlags.useItem = 0;
pInput->actions &= ~SB_INVUSE;
if (pPlayer->packSlots[pPlayer->packItemId].curAmount > 0)
packUseItem(pPlayer, pPlayer->packItemId);
}

View file

@ -43,6 +43,8 @@
static int WeaponToSend = 0;
ESyncBits ActionsToSend = 0;
static int dpad_lock = 0;
//==========================================================================
//
//
@ -112,6 +114,9 @@ void InputState::ClearAllInput()
{
memset(KeyStatus, 0, sizeof(KeyStatus));
AnyKeyStatus = false;
ActionsToSend = 0;
WeaponToSend = 0;
dpad_lock = 0;
buttonMap.ResetButtonStates(); // this is important. If all input is cleared, the buttons must be cleared as well.
gi->clearlocalinputstate(); // also clear game local input state.
}
@ -274,6 +279,20 @@ CCMD(useitem)
}
}
CCMD(invprev)
{
ActionsToSend |= SB_INVPREV;
}
CCMD(invnext)
{
ActionsToSend |= SB_INVNEXT;
}
CCMD(invuse)
{
ActionsToSend |= SB_INVUSE;
}
@ -281,18 +300,25 @@ void ApplyGlobalInput(InputPacket& input, ControlInfo *info)
{
if (WeaponToSend != 0) input.setNewWeapon(WeaponToSend);
WeaponToSend = 0;
if (info)
{
if (buttonMap.ButtonDown(gamefunc_Dpad_Select) && info->dz > 0) input.setNewWeapon(WeaponSel_Prev);
if (buttonMap.ButtonDown(gamefunc_Dpad_Select) && info->dz < 0) input.setNewWeapon(WeaponSel_Next);
}
if (buttonMap.ButtonDown(gamefunc_Dpad_Select))
if (info && buttonMap.ButtonDown(gamefunc_Dpad_Select))
{
// These buttons should not autorepeat. The game handlers are not really equipped for that.
if (info->dz > 0 && !(dpad_lock & 1)) { dpad_lock |= 1; input.setNewWeapon(WeaponSel_Prev); }
else dpad_lock &= ~1;
if (info->dz < 0 && !(dpad_lock & 2)) { dpad_lock |= 2; input.setNewWeapon(WeaponSel_Next); }
else dpad_lock &= ~2;
if ((info->dx < 0 || info->dyaw < 0) && !(dpad_lock & 4)) { dpad_lock |= 4; input.actions |= SB_INVPREV; }
else dpad_lock &= ~4;
if ((info->dx > 0 || info->dyaw > 0) && !(dpad_lock & 8)) { dpad_lock |= 8; input.actions |= SB_INVNEXT; }
else dpad_lock &= ~8;
// This eats the controller input for regular use
info->dx = 0;
info->dz = 0;
info->dyaw = 0;
}
else dpad_lock = 0;
input.actions |= ActionsToSend;
ActionsToSend = 0;

View file

@ -15,14 +15,16 @@ enum ESyncBits_ : uint32_t
SB_ITEM_BIT_6 = 1 << 9,
SB_ITEM_BIT_7 = 1 << 10,
// Exhumed has 6 items but doesn't use the network packet to activate them. Need to change
SB_INVPREV = 1 << 11,
SB_INVNEXT = 1 << 12,
SB_INVUSE = 1 << 13,
SB_WEAPONMASK_BITS = (15u * SB_FIRST_WEAPON_BIT), // Weapons take up 4 bits
SB_ITEMUSE_BITS = (127u * SB_ITEM_BIT_1),
SB_BUTTON_MASK = 0, // all input from buttons (i.e. active while held)
SB_INTERFACE_MASK = 0, // all input from CCMDs
SB_INTERFACE_MASK = (SB_INVPREV|SB_INVNEXT|SB_INVUSE), // all input from CCMDs
SB_INTERFACE_BITS = (SB_WEAPONMASK_BITS | SB_ITEMUSE_BITS | SB_INTERFACE_MASK)
};
@ -68,20 +70,17 @@ enum EDukeSyncBits_ : uint32_t
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_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_INTERFACE_BITS = (SKB_QUICK_KICK | \
SKB_HOLSTER | SKB_INV_LEFT | SKB_PAUSE | SKB_INV_RIGHT | \
SKB_TURNAROUND | SKB_OPEN | SKB_INVENTORY | SKB_ESCAPE),
SKB_HOLSTER | SKB_PAUSE | \
SKB_TURNAROUND | SKB_OPEN | SKB_ESCAPE),
SKB_NONE = 0,
SKB_ALL = ~0u
@ -106,9 +105,6 @@ union SYNCFLAGS
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 holsterWeapon : 1;
unsigned int lookCenter : 1;
unsigned int lookLeft : 1;
@ -148,10 +144,6 @@ union SYNCFLAGS
#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

View file

@ -528,6 +528,46 @@ void GameTicker()
weap2 = SelectAltWeapon(weap2);
}
if (localInput.actions & SB_INVPREV)
{
int nItem = nPlayerItem[nLocalPlayer];
for (int i = 6; i > 0; i--)
{
nItem--;
if (nItem < 0) nItem = 5;
if (PlayerList[nLocalPlayer].items[nItem] != 0)
break;
}
if (i > 0) SetPlayerItem(nLocalPlayer, nItem);
}
if (localInput.actions & SB_INVNEXT)
{
int nItem = nPlayerItem[nLocalPlayer];
for (int i = 6; i > 0; i--)
{
nItem++;
if (nItem == 6) nItem = 0;
if (PlayerList[nLocalPlayer].items[nItem] != 0)
break;
}
if (i > 0) SetPlayerItem(nLocalPlayer, nItem);
}
if (localInput.actions & SB_INVUSE)
{
if (nPlayerItem[nLocalPlayer] != -1)
{
localInput.setItemUsed(nPlayerItem[nLocalPlayer]);
}
}
for (int i = 0; i < 6; i++)
{
if (localInput.isItemUsed(i))

View file

@ -386,9 +386,6 @@ void registerinputcommands()
{
C_RegisterFunction("pause", nullptr, [](CCmdFuncPtr)->int { /*BitsToSend |= SKB_PAUSE;*/ sendPause = true; return CCMD_OK; });
C_RegisterFunction("centerview", nullptr, ccmd_centerview);
C_RegisterFunction("invprev", nullptr, [](CCmdFuncPtr)->int { if (PlayerList[nLocalPlayer].nHealth > 0) SetPrevItem(nLocalPlayer); return CCMD_OK; });
C_RegisterFunction("invnext", nullptr, [](CCmdFuncPtr)->int { if (PlayerList[nLocalPlayer].nHealth > 0) SetNextItem(nLocalPlayer); return CCMD_OK; });
//C_RegisterFunction("invuse", nullptr, [](CCmdFuncPtr)->int { if (PlayerList[nLocalPlayer].nHealth > 0) UseCurItem(nLocalPlayer); return CCMD_OK; });
// These are only here to silence the engine when the keys bound to them are pressed. The functions do not exist.
C_RegisterFunction("turnaround", nullptr, [](CCmdFuncPtr)->int { return CCMD_OK; });

View file

@ -384,51 +384,6 @@ void SetPlayerItem(short nPlayer, short nItem)
}
}
void SetNextItem(int nPlayer)
{
short nItem = nPlayerItem[nPlayer];
int i;
for (i = 6; i > 0; i--)
{
nItem++;
if (nItem == 6)
nItem = 0;
if (PlayerList[nPlayer].items[nItem] != 0)
break;
}
if (i > 0) {
SetPlayerItem(nPlayer, nItem);
}
}
void SetPrevItem(int nPlayer)
{
if (nPlayerItem[nPlayer] == -1)
return;
int nItem = nPlayerItem[nPlayer];
int i;
for (i = 6; i > 0; i--)
{
nItem--;
if (nItem < 0)
nItem = 5;
if (PlayerList[nPlayer].items[nItem] != 0)
break;
}
if (i > 0) {
SetPlayerItem(nPlayer, nItem);
}
}
void MoveStatus()
{
if (nItemSeq >= 0)

View file

@ -36,8 +36,6 @@ void MoveStatus();
void DrawSnakeCamStatus();
void DrawStatus();
int BuildStatusAnim(int val, int nFlags);
void SetNextItem(int nPlayer);
void SetPrevItem(int nPlayer);
void SetCounter(short nVal);
void SetCounterImmediate(short nVal);

View file

@ -136,6 +136,11 @@ inline EDukeSyncBits PlayerInputBits(int pl, EDukeSyncBits bits)
return (sync[pl].sbits & bits);
}
inline bool PlayerInput(int pl, ESyncBits bit)
{
return (!!((sync[pl].actions) & bit));
}
inline ESyncBits PlayerInputBits(int pl, ESyncBits bits)
{
return (sync[pl].actions & bits);

View file

@ -204,7 +204,7 @@ void hud_input(int snum)
if (sprite[p->i].extra <= 0) return;
// Activate an inventory item. This just forwards to the other inventory bits. If the inventory selector was taken out of the playsim this could be removed.
if (PlayerInput(snum, SKB_INVENTORY) && p->newowner == -1)
if (PlayerInput(snum, SB_INVUSE) && p->newowner == -1)
{
SetGameVarID(g_iReturnVarID, 0, -1, snum);
OnEvent(EVENT_INVENTORY, -1, snum, -1);
@ -245,11 +245,11 @@ void hud_input(int snum)
return;
}
if (PlayerInput(snum, SKB_INV_LEFT) || PlayerInput(snum, SKB_INV_RIGHT))
if (PlayerInput(snum, SB_INVPREV) || PlayerInput(snum, SB_INVNEXT))
{
p->invdisptime = 26 * 2;
if (PlayerInput(snum, SKB_INV_RIGHT)) k = 1;
if (PlayerInput(snum, SB_INVNEXT)) k = 1;
else k = 0;
dainv = p->inven_icon;
@ -311,13 +311,13 @@ void hud_input(int snum)
else dainv = 0;
// These events force us to keep the inventory selector in the playsim as opposed to the UI where it really belongs.
if (PlayerInput(snum, SKB_INV_LEFT))
if (PlayerInput(snum, SB_INVPREV))
{
SetGameVarID(g_iReturnVarID, dainv, -1, snum);
OnEvent(EVENT_INVENTORYLEFT, -1, snum, -1);
dainv = GetGameVarID(g_iReturnVarID, -1, snum);
}
if (PlayerInput(snum, SKB_INV_RIGHT))
if (PlayerInput(snum, SB_INVNEXT))
{
SetGameVarID(g_iReturnVarID, dainv, -1, snum);
OnEvent(EVENT_INVENTORYRIGHT, -1, snum, -1);
@ -617,12 +617,6 @@ static void processInputBits(player_struct *p, ControlInfo &info)
loc.sbits |= BitsToSend;
BitsToSend = 0;
if (buttonMap.ButtonDown(gamefunc_Dpad_Select)) // todo: This must go to global code.
{
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.sbits |= SKB_GAMEQUIT;
if (!onVehicle)
@ -1163,10 +1157,8 @@ void registerinputcommands()
C_RegisterFunction("pause", nullptr, [](CCmdFuncPtr)->int { BitsToSend |= SKB_PAUSE; sendPause = true; return CCMD_OK; });
C_RegisterFunction("centerview", nullptr, [](CCmdFuncPtr)->int { BitsToSend |= SKB_CENTER_VIEW; return CCMD_OK; });
C_RegisterFunction("holsterweapon", nullptr, [](CCmdFuncPtr)->int { BitsToSend |= SKB_HOLSTER; return CCMD_OK; });
C_RegisterFunction("invprev", nullptr, [](CCmdFuncPtr)->int { BitsToSend |= SKB_INV_LEFT; return CCMD_OK; });
C_RegisterFunction("invnext", nullptr, [](CCmdFuncPtr)->int { BitsToSend |= SKB_INV_RIGHT; return CCMD_OK; });
C_RegisterFunction("turnaround", nullptr, [](CCmdFuncPtr)->int { BitsToSend |= SKB_TURNAROUND; return CCMD_OK; });
C_RegisterFunction("invuse", nullptr, [](CCmdFuncPtr)->int { BitsToSend |= SKB_INVENTORY; return CCMD_OK; });
C_RegisterFunction("backoff", nullptr, [](CCmdFuncPtr)->int { BitsToSend |= SKB_ESCAPE; return CCMD_OK; });
}

View file

@ -37,7 +37,6 @@ BEGIN_SW_NS
SWBOOL MultiPlayQuitFlag = FALSE;
int BitsToSend = 0;
int inv_hotkey = 0;
void
@ -473,17 +472,14 @@ void registerinputcommands()
C_RegisterFunction("pause", nullptr, [](CCmdFuncPtr)->int { BitsToSend |= BIT(SK_PAUSE); sendPause = true; return CCMD_OK; });
C_RegisterFunction("centerview", nullptr, [](CCmdFuncPtr)->int { BitsToSend |= BIT(SK_CENTER_VIEW); return CCMD_OK; });
C_RegisterFunction("holsterweapon", nullptr, [](CCmdFuncPtr)->int { BitsToSend |= BIT(SK_HIDE_WEAPON); return CCMD_OK; });
C_RegisterFunction("invprev", nullptr, [](CCmdFuncPtr)->int { BitsToSend |= BIT(SK_INV_LEFT); return CCMD_OK; });
C_RegisterFunction("invnext", nullptr, [](CCmdFuncPtr)->int { BitsToSend |= BIT(SK_INV_RIGHT); return CCMD_OK; });
C_RegisterFunction("turnaround", nullptr, [](CCmdFuncPtr)->int { BitsToSend |= BIT(SK_TURN_180); return CCMD_OK; });
C_RegisterFunction("invuse", nullptr, [](CCmdFuncPtr)->int { BitsToSend |= BIT(SK_INV_USE); return CCMD_OK; });
}
// This is called from ImputState::ClearAllInput and resets all static state being used here.
void GameInterface::clearlocalinputstate()
{
BitsToSend = 0;
inv_hotkey = 0;
}

View file

@ -412,14 +412,12 @@ StopInventoryNightVision(PLAYERp pp, short InventoryNum)
void InventoryKeys(PLAYERp pp)
{
short inv_hotkey;
// scroll SPELLs left
if (TEST_SYNC_KEY(pp, SK_INV_LEFT))
if (pp->input.actions & SB_INVPREV)
{
if (FLAG_KEY_PRESSED(pp, SK_INV_LEFT))
if (pp->KeyPressBits & SB_INVPREV)
{
FLAG_KEY_RELEASE(pp, SK_INV_LEFT);
pp->KeyPressBits &= ~SB_INVPREV;
pp->InventoryBarTics = SEC(2);
PlayerUpdateInventory(pp, pp->InventoryNum - 1);
PutStringInfo(pp, InventoryData[pp->InventoryNum].Name);
@ -427,15 +425,15 @@ void InventoryKeys(PLAYERp pp)
}
else
{
FLAG_KEY_RESET(pp, SK_INV_LEFT);
pp->KeyPressBits |= SB_INVPREV;
}
// scroll SPELLs right
if (TEST_SYNC_KEY(pp, SK_INV_RIGHT))
if (pp->input.actions & SB_INVNEXT)
{
if (FLAG_KEY_PRESSED(pp, SK_INV_RIGHT))
if (pp->KeyPressBits & SB_INVNEXT)
{
FLAG_KEY_RELEASE(pp, SK_INV_RIGHT);
pp->KeyPressBits &= ~SB_INVNEXT;
pp->InventoryBarTics = SEC(2);
PlayerUpdateInventory(pp, pp->InventoryNum + 1);
PutStringInfo(pp, InventoryData[pp->InventoryNum].Name);
@ -443,15 +441,14 @@ void InventoryKeys(PLAYERp pp)
}
else
{
FLAG_KEY_RESET(pp, SK_INV_RIGHT);
pp->KeyPressBits |= SB_INVNEXT;
}
if (TEST_SYNC_KEY(pp, SK_INV_USE))
if (pp->input.actions & SB_INVUSE)
{
if (FLAG_KEY_PRESSED(pp, SK_INV_USE))
if (pp->KeyPressBits & SB_INVUSE)
{
FLAG_KEY_RELEASE(pp, SK_INV_USE);
pp->KeyPressBits &= ~SB_INVUSE;
if (InventoryData[pp->InventoryNum].Init)
{
if (pp->InventoryAmount[pp->InventoryNum])
@ -468,7 +465,7 @@ void InventoryKeys(PLAYERp pp)
}
else
{
FLAG_KEY_RESET(pp, SK_INV_USE);
pp->KeyPressBits |= SB_INVUSE;
}
// test all 7 items

View file

@ -84,17 +84,15 @@ DoPrediction(PLAYERp ppp)
// get rid of input bits so it doesn't go into other code branches that would
// get it out of sync
ppp->input.actions &= ~(SB_WEAPONMASK_BITS|SB_ITEMUSE_BITS);
ppp->KeyPressBits |= (SB_WEAPONMASK_BITS|SB_ITEMUSE_BITS);
ppp->KeyPressBits |= (SB_WEAPONMASK_BITS|SB_ITEMUSE_BITS|SB_INVNEXT|SB_INVPREV|SB_INVUSE);
RESET(ppp->input.bits,
BIT(SK_SHOOT)|BIT(SK_OPERATE)|BIT(SK_INV_LEFT)|BIT(SK_INV_RIGHT)|
BIT(SK_INV_USE)|BIT(SK_HIDE_WEAPON)|
BIT(SK_SHOOT)|BIT(SK_OPERATE)|BIT(SK_HIDE_WEAPON)|
BIT(SK_AUTO_AIM)|
BIT(SK_CENTER_VIEW)
);
SET(ppp->KeyPressFlags,
BIT(SK_SHOOT)|BIT(SK_OPERATE)|BIT(SK_INV_LEFT)|BIT(SK_INV_RIGHT)|
BIT(SK_INV_USE)|BIT(SK_HIDE_WEAPON)|
BIT(SK_SHOOT)|BIT(SK_OPERATE)|BIT(SK_HIDE_WEAPON)|
BIT(SK_AUTO_AIM)|
BIT(SK_CENTER_VIEW)
);