- transition weapon selection in SW.

Thanks to the macro insanity for trivial operations in this code base this turned out to be a lot more troublesome than Duke...
This commit is contained in:
Christoph Oelckers 2020-08-27 00:06:59 +02:00
parent e768a2bf24
commit c7e667a17a
8 changed files with 18 additions and 29 deletions

View file

@ -113,16 +113,6 @@ union SYNCFLAGS
// NETWORK - REDEFINABLE SHARED (SYNC) KEYS BIT POSITIONS // 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_BIT0 4
#define SK_INV_HOTKEY_BIT1 5 #define SK_INV_HOTKEY_BIT1 5
#define SK_INV_HOTKEY_BIT2 6 #define SK_INV_HOTKEY_BIT2 6

View file

@ -664,8 +664,7 @@ 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.actions & SB_WEAPONMASK_BITS) == 0) if (j) loc.SetNewWeapon(j);
loc.SetNewWeapon(j);
} }

View file

@ -1002,6 +1002,7 @@ struct PLAYERstruct
PLAYER_ACTION_FUNCp DoPlayerAction; PLAYER_ACTION_FUNCp DoPlayerAction;
int Flags, Flags2; int Flags, Flags2;
ESyncBits KeyPressBits;
int KeyPressFlags; int KeyPressFlags;
SECTOR_OBJECTp sop_control; // sector object pointer SECTOR_OBJECTp sop_control; // sector object pointer

View file

@ -343,8 +343,7 @@ getinput(InputPacket *loc, SWBOOL tied)
if (WeaponToSend > 0) if (WeaponToSend > 0)
{ {
loc->bits &= ~SK_WEAPON_MASK; loc->SetNewWeapon(WeaponToSend);
loc->bits |= WeaponToSend;
WeaponToSend = 0; WeaponToSend = 0;
} }
else if (WeaponToSend == -1) else if (WeaponToSend == -1)

View file

@ -84,6 +84,7 @@ typedef struct
fix16_t q16ang; fix16_t q16ang;
fix16_t q16horz; fix16_t q16horz;
int32_t bits; int32_t bits;
ESyncBits actions;
} SW_AVERAGE_PACKET; } SW_AVERAGE_PACKET;
int MovesPerPacket = 1; int MovesPerPacket = 1;
@ -204,8 +205,12 @@ UpdateInputs(void)
AveragePacket.q16ang = Player[myconnectindex].camq16ang; AveragePacket.q16ang = Player[myconnectindex].camq16ang;
AveragePacket.q16horz = Player[myconnectindex].camq16horiz; AveragePacket.q16horz = Player[myconnectindex].camq16horiz;
SET(AveragePacket.bits, loc.bits); SET(AveragePacket.bits, loc.bits);
SET(AveragePacket.actions, loc.actions);
// The above would or the weapon numbers together. Undo that now. The last one should win.
AveragePacket.actions &= ~SB_WEAPONMASK_BITS;
AveragePacket.actions |= ESyncBits::FromInt(loc.getNewWeapon()) & SB_WEAPONMASK_BITS;
Bmemset(&loc, 0, sizeof(loc)); memset(&loc, 0, sizeof(loc));
pp = Player + myconnectindex; pp = Player + myconnectindex;
@ -226,6 +231,7 @@ UpdateInputs(void)
loc.q16ang = AveragePacket.q16ang; loc.q16ang = AveragePacket.q16ang;
loc.q16horz = AveragePacket.q16horz; loc.q16horz = AveragePacket.q16horz;
loc.bits = AveragePacket.bits; loc.bits = AveragePacket.bits;
loc.actions = AveragePacket.actions;
memset(&AveragePacket, 0, sizeof(AveragePacket)); memset(&AveragePacket, 0, sizeof(AveragePacket));

View file

@ -191,15 +191,8 @@ void pToggleCrosshair(void)
void DoPlayerChooseYell(PLAYERp pp) void DoPlayerChooseYell(PLAYERp pp)
{ {
int choose_snd = 0; int choose_snd = 0;
short weapon;
weapon = TEST(pp->input.bits, SK_WEAPON_MASK); if (RANDOM_RANGE(1000) < 990) return;
if (weapon == WPN_FIST)
{
if (RANDOM_RANGE(1000) < 900) return;
}
else if (RANDOM_RANGE(1000) < 990) return;
choose_snd = STD_RANDOM_RANGE(MAX_YELLSOUNDS); choose_snd = STD_RANDOM_RANGE(MAX_YELLSOUNDS);
@ -487,13 +480,13 @@ int WeaponOperate(PLAYERp pp)
} }
} }
weapon = TEST(pp->input.bits, SK_WEAPON_MASK); weapon = pp->input.getNewWeapon();
if (weapon) if (weapon)
{ {
if (FLAG_KEY_PRESSED(pp, SK_WEAPON_BIT0)) if (pp->KeyPressBits & SB_FIRST_WEAPON_BIT)
{ {
FLAG_KEY_RELEASE(pp, SK_WEAPON_BIT0); pp->KeyPressBits &= ~SB_FIRST_WEAPON_BIT;
weapon -= 1; weapon -= 1;
@ -640,7 +633,7 @@ int WeaponOperate(PLAYERp pp)
} }
else else
{ {
FLAG_KEY_RESET(pp, SK_WEAPON_BIT0); pp->KeyPressBits |= SB_FIRST_WEAPON_BIT;
} }
// Shut that computer chick up if weapon has changed! // Shut that computer chick up if weapon has changed!

View file

@ -7806,6 +7806,7 @@ InitAllPlayers(void)
pp->WpnGotOnceFlags = 0; pp->WpnGotOnceFlags = 0;
pp->DoPlayerAction = DoPlayerBeginRun; pp->DoPlayerAction = DoPlayerBeginRun;
pp->KeyPressBits = ESyncBits::FromInt(0xFFFFFFFF);
pp->KeyPressFlags = 0xFFFFFFFF; pp->KeyPressFlags = 0xFFFFFFFF;
memset(pp->KilledPlayer,0,sizeof(pp->KilledPlayer)); memset(pp->KilledPlayer,0,sizeof(pp->KilledPlayer));

View file

@ -83,12 +83,13 @@ DoPrediction(PLAYERp ppp)
// get rid of input bits so it doesn't go into other code branches that would // get rid of input bits so it doesn't go into other code branches that would
// get it out of sync // get it out of sync
ppp->input.actions &= ~(SB_WEAPONMASK_BITS);
ppp->KeyPressBits |= (SB_WEAPONMASK_BITS);
RESET(ppp->input.bits, RESET(ppp->input.bits,
BIT(SK_SHOOT)|BIT(SK_OPERATE)|BIT(SK_INV_LEFT)|BIT(SK_INV_RIGHT)| BIT(SK_SHOOT)|BIT(SK_OPERATE)|BIT(SK_INV_LEFT)|BIT(SK_INV_RIGHT)|
BIT(SK_INV_USE)|BIT(SK_HIDE_WEAPON)| BIT(SK_INV_USE)|BIT(SK_HIDE_WEAPON)|
BIT(SK_AUTO_AIM)| BIT(SK_AUTO_AIM)|
BIT(SK_CENTER_VIEW)| BIT(SK_CENTER_VIEW)|
SK_WEAPON_MASK|
SK_INV_HOTKEY_MASK SK_INV_HOTKEY_MASK
); );
@ -97,7 +98,6 @@ DoPrediction(PLAYERp ppp)
BIT(SK_INV_USE)|BIT(SK_HIDE_WEAPON)| BIT(SK_INV_USE)|BIT(SK_HIDE_WEAPON)|
BIT(SK_AUTO_AIM)| BIT(SK_AUTO_AIM)|
BIT(SK_CENTER_VIEW)| BIT(SK_CENTER_VIEW)|
SK_WEAPON_MASK|
SK_INV_HOTKEY_MASK SK_INV_HOTKEY_MASK
); );