- Exhumed also handled.

This commit is contained in:
Christoph Oelckers 2020-08-27 00:58:21 +02:00
parent 99486cba7e
commit 4b299fa412
7 changed files with 239 additions and 230 deletions

View file

@ -158,9 +158,6 @@ enum {
kButtonCheatGodMode = 0x40,
kButtonCheatKeys = 0x80,
kButtonCheatItems = 0x100,
kButtonWeaponShift = 13,
kButtonWeaponBits = 7 << kButtonWeaponShift, // upper 3 bits.
};

View file

@ -483,7 +483,7 @@ void GameTicker()
lastTic = currentTic;
int lLocalButtons = GetLocalInput(); // shouldn't this be placed in localInput?
PlayerInterruptKeys();
PlayerInterruptKeys(false);
nPlayerDAng = fix16_sadd(nPlayerDAng, localInput.q16avel);
inita &= kAngleMask;
@ -500,8 +500,11 @@ void GameTicker()
sPlayerInput[nLocalPlayer].xVel = lPlayerXVel;
sPlayerInput[nLocalPlayer].yVel = lPlayerYVel;
// make weapon selection persist until it gets used up.
if ((lLocalButtons & kButtonWeaponBits) == 0) lLocalButtons |= sPlayerInput[nLocalPlayer].buttons & kButtonWeaponBits;
sPlayerInput[nLocalPlayer].buttons = lLocalButtons | lLocalCodes;
int weap = sPlayerInput[nLocalPlayer].getNewWeapon();
sPlayerInput[nLocalPlayer].actions = localInput.actions;
int weap2 = localInput.getNewWeapon();
if (weap2 <= 0 || weap2 > 7) sPlayerInput[nLocalPlayer].SetNewWeapon(weap);
sPlayerInput[nLocalPlayer].nTarget = besttarget;
Ra[nLocalPlayer].nTarget = besttarget;

View file

@ -257,7 +257,7 @@ void GameLoop()
{
CheckKeys();
GameTicker();
PlayerInterruptKeys();
PlayerInterruptKeys(true);
UpdateSounds();
CheckKeys2();
}

View file

@ -28,7 +28,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
BEGIN_PS_NS
extern short bPlayerPan;
extern short bLockPan;
int WeaponToSend, BitsToSend;
bool g_MyAimMode;
short nInputStack = 0;
@ -82,8 +86,6 @@ int GetLocalInput()
{
lLocalButtons = (buttonMap.ButtonDown(gamefunc_Crouch) << 4) | (buttonMap.ButtonDown(gamefunc_Fire) << 3)
| (buttonMap.ButtonDown(gamefunc_Jump) << 0);
lLocalButtons |= (WeaponToSend << 13);
WeaponToSend = 0;
}
else
{
@ -156,6 +158,221 @@ void CheckKeys2()
}
void PlayerInterruptKeys(bool after)
{
ControlInfo info;
memset(&info, 0, sizeof(ControlInfo)); // this is done within CONTROL_GetInput() anyway
CONTROL_GetInput(&info);
static double lastInputTicks;
auto const currentHiTicks = I_msTimeF();
double const elapsedInputTicks = currentHiTicks - lastInputTicks;
lastInputTicks = currentHiTicks;
auto scaleAdjustmentToInterval = [=](double x) { return x * (120 / 4) / (1000.0 / elapsedInputTicks); };
if (paused)
return;
localInput = {};
InputPacket input{};
fix16_t input_angle = 0;
if (PlayerList[nLocalPlayer].nHealth == 0)
{
lPlayerYVel = 0;
lPlayerXVel = 0;
nPlayerDAng = 0;
return;
}
// JBF: Run key behaviour is selectable
int const playerRunning = G_CheckAutorun(buttonMap.ButtonDown(gamefunc_Run));
int const turnAmount = playerRunning ? 12 : 8;
int const keyMove = playerRunning ? 12 : 6;
if (buttonMap.ButtonDown(gamefunc_Strafe))
{
input.svel -= info.mousex * 4.f;
input.svel -= info.dyaw * keyMove;
}
else
{
input_angle = fix16_sadd(input_angle, fix16_from_float(info.mousex));
input_angle = fix16_sadd(input_angle, fix16_from_dbl(scaleAdjustmentToInterval(info.dyaw)));
}
g_MyAimMode = in_mousemode || buttonMap.ButtonDown(gamefunc_Mouse_Aiming);
if (g_MyAimMode)
input.q16horz = fix16_sadd(input.q16horz, fix16_from_float(info.mousey));
else
input.fvel -= info.mousey * 8.f;
if (!in_mouseflip) input.q16horz = -input.q16horz;
input.q16horz = fix16_ssub(input.q16horz, fix16_from_dbl(scaleAdjustmentToInterval(info.dpitch)));
input.svel -= info.dx * keyMove;
input.fvel -= info.dz * keyMove;
if (buttonMap.ButtonDown(gamefunc_Strafe))
{
if (buttonMap.ButtonDown(gamefunc_Turn_Left))
input.svel -= -keyMove;
if (buttonMap.ButtonDown(gamefunc_Turn_Right))
input.svel -= keyMove;
}
else
{
static int turn = 0;
static int counter = 0;
// normal, non strafing movement
if (buttonMap.ButtonDown(gamefunc_Turn_Left))
{
turn -= 2;
if (turn < -turnAmount)
turn = -turnAmount;
}
else if (buttonMap.ButtonDown(gamefunc_Turn_Right))
{
turn += 2;
if (turn > turnAmount)
turn = turnAmount;
}
if (turn < 0)
{
turn++;
if (turn > 0)
turn = 0;
}
if (turn > 0)
{
turn--;
if (turn < 0)
turn = 0;
}
//if ((counter++) % 4 == 0) // what was this for???
input_angle = fix16_sadd(input_angle, fix16_from_dbl(scaleAdjustmentToInterval(turn * 2)));
}
if (buttonMap.ButtonDown(gamefunc_Strafe_Left))
input.svel += keyMove;
if (buttonMap.ButtonDown(gamefunc_Strafe_Right))
input.svel += -keyMove;
if (buttonMap.ButtonDown(gamefunc_Move_Forward))
input.fvel += keyMove;
if (buttonMap.ButtonDown(gamefunc_Move_Backward))
input.fvel += -keyMove;
localInput.fvel = clamp(localInput.fvel + input.fvel, -12, 12);
localInput.svel = clamp(localInput.svel + input.svel, -12, 12);
localInput.q16avel = fix16_sadd(localInput.q16avel, input_angle);
if (!after)
{
if (WeaponToSend > 0)
localInput.SetNewWeapon(WeaponToSend);
WeaponToSend = 0;
}
if (!nFreeze)
{
PlayerList[nLocalPlayer].q16angle = fix16_sadd(PlayerList[nLocalPlayer].q16angle, input_angle) & 0x7FFFFFF;
// A horiz diff of 128 equal 45 degrees,
// so we convert horiz to 1024 angle units
float const horizAngle = clamp(atan2f(PlayerList[nLocalPlayer].q16horiz - fix16_from_int(92), fix16_from_int(128)) * (512.f / fPI) + fix16_to_float(input.q16horz), -255.f, 255.f);
PlayerList[nLocalPlayer].q16horiz = fix16_from_int(92) + Blrintf(fix16_from_int(128) * tanf(horizAngle * (fPI / 512.f)));
// Look/aim up/down functions.
if (buttonMap.ButtonDown(gamefunc_Look_Up) || buttonMap.ButtonDown(gamefunc_Aim_Up))
{
bLockPan = false;
if (PlayerList[nLocalPlayer].q16horiz < fix16_from_int(180)) {
PlayerList[nLocalPlayer].q16horiz = fix16_sadd(PlayerList[nLocalPlayer].q16horiz, fix16_from_dbl(scaleAdjustmentToInterval(4)));
}
bPlayerPan = true;
nDestVertPan[nLocalPlayer] = PlayerList[nLocalPlayer].q16horiz;
}
else if (buttonMap.ButtonDown(gamefunc_Look_Down) || buttonMap.ButtonDown(gamefunc_Aim_Down))
{
bLockPan = false;
if (PlayerList[nLocalPlayer].q16horiz > fix16_from_int(4)) {
PlayerList[nLocalPlayer].q16horiz = fix16_ssub(PlayerList[nLocalPlayer].q16horiz, fix16_from_dbl(scaleAdjustmentToInterval(4)));
}
bPlayerPan = true;
nDestVertPan[nLocalPlayer] = PlayerList[nLocalPlayer].q16horiz;
}
}
// loc_1C048:
if (totalvel[nLocalPlayer] > 20) {
bPlayerPan = false;
}
if (g_MyAimMode)
bLockPan = true;
// loc_1C05E
fix16_t ecx = nDestVertPan[nLocalPlayer] - PlayerList[nLocalPlayer].q16horiz;
if (g_MyAimMode)
{
ecx = 0;
}
if (!nFreeze)
{
if (ecx)
{
if (ecx / 4 == 0)
{
if (ecx >= 0) {
ecx = 1;
}
else
{
ecx = -1;
}
}
else
{
ecx /= 4;
if (ecx > fix16_from_int(4))
{
ecx = fix16_from_int(4);
}
else if (ecx < -fix16_from_int(4))
{
ecx = -fix16_from_int(4);
}
}
PlayerList[nLocalPlayer].q16horiz = fix16_sadd(PlayerList[nLocalPlayer].q16horiz, ecx);
}
PlayerList[nLocalPlayer].q16horiz = fix16_clamp(PlayerList[nLocalPlayer].q16horiz, fix16_from_int(0), fix16_from_int(184));
}
}
//---------------------------------------------------------------------------
//
// CCMD based input. The basics are from Randi's ZDuke but this uses dynamic

View file

@ -53,7 +53,6 @@ fix16_t nPlayerDAng = 0;
short obobangle = 0, bobangle = 0;
short bPlayerPan = 0;
short bLockPan = 0;
bool g_MyAimMode;
static actionSeq ActionSeq[] = {
{18, 0}, {0, 0}, {9, 0}, {27, 0}, {63, 0},
@ -130,224 +129,6 @@ short PlayerCount;
short nNetStartSprites;
short nCurStartSprite;
/*
typedef struct
{
fixed dx;
fixed dy;
fixed dz;
fixed dyaw;
fixed dpitch;
fixed droll;
} ControlInfo;
*/
void PlayerInterruptKeys()
{
ControlInfo info;
memset(&info, 0, sizeof(ControlInfo)); // this is done within CONTROL_GetInput() anyway
CONTROL_GetInput(&info);
static double lastInputTicks;
auto const currentHiTicks = I_msTimeF();
double const elapsedInputTicks = currentHiTicks - lastInputTicks;
lastInputTicks = currentHiTicks;
auto scaleAdjustmentToInterval = [=](double x) { return x * (120 / 4) / (1000.0 / elapsedInputTicks); };
if (paused)
return;
localInput = {};
InputPacket input {};
fix16_t input_angle = 0;
if (PlayerList[nLocalPlayer].nHealth == 0)
{
lPlayerYVel = 0;
lPlayerXVel = 0;
nPlayerDAng = 0;
return;
}
// JBF: Run key behaviour is selectable
int const playerRunning = G_CheckAutorun(buttonMap.ButtonDown(gamefunc_Run));
int const turnAmount = playerRunning ? 12 : 8;
int const keyMove = playerRunning ? 12 : 6;
if (buttonMap.ButtonDown(gamefunc_Strafe))
{
input.svel -= info.mousex * 4.f;
input.svel -= info.dyaw * keyMove;
}
else
{
input_angle = fix16_sadd(input_angle, fix16_from_float(info.mousex));
input_angle = fix16_sadd(input_angle, fix16_from_dbl(scaleAdjustmentToInterval(info.dyaw)));
}
g_MyAimMode = in_mousemode || buttonMap.ButtonDown(gamefunc_Mouse_Aiming);
if (g_MyAimMode)
input.q16horz = fix16_sadd(input.q16horz, fix16_from_float(info.mousey));
else
input.fvel -= info.mousey * 8.f;
if (!in_mouseflip) input.q16horz = -input.q16horz;
input.q16horz = fix16_ssub(input.q16horz, fix16_from_dbl(scaleAdjustmentToInterval(info.dpitch)));
input.svel -= info.dx * keyMove;
input.fvel -= info.dz * keyMove;
if (buttonMap.ButtonDown(gamefunc_Strafe))
{
if (buttonMap.ButtonDown(gamefunc_Turn_Left))
input.svel -= -keyMove;
if (buttonMap.ButtonDown(gamefunc_Turn_Right))
input.svel -= keyMove;
}
else
{
static int turn = 0;
static int counter = 0;
// normal, non strafing movement
if (buttonMap.ButtonDown(gamefunc_Turn_Left))
{
turn -= 2;
if (turn < -turnAmount)
turn = -turnAmount;
}
else if (buttonMap.ButtonDown(gamefunc_Turn_Right))
{
turn += 2;
if (turn > turnAmount)
turn = turnAmount;
}
if (turn < 0)
{
turn++;
if (turn > 0)
turn = 0;
}
if (turn > 0)
{
turn--;
if (turn < 0)
turn = 0;
}
//if ((counter++) % 4 == 0) // what was this for???
input_angle = fix16_sadd(input_angle, fix16_from_dbl(scaleAdjustmentToInterval(turn * 2)));
}
if (buttonMap.ButtonDown(gamefunc_Strafe_Left))
input.svel += keyMove;
if (buttonMap.ButtonDown(gamefunc_Strafe_Right))
input.svel += -keyMove;
if (buttonMap.ButtonDown(gamefunc_Move_Forward))
input.fvel += keyMove;
if (buttonMap.ButtonDown(gamefunc_Move_Backward))
input.fvel += -keyMove;
localInput.fvel = clamp(localInput.fvel + input.fvel, -12, 12);
localInput.svel = clamp(localInput.svel + input.svel, -12, 12);
localInput.q16avel = fix16_sadd(localInput.q16avel, input_angle);
if (!nFreeze)
{
PlayerList[nLocalPlayer].q16angle = fix16_sadd(PlayerList[nLocalPlayer].q16angle, input_angle) & 0x7FFFFFF;
// A horiz diff of 128 equal 45 degrees,
// so we convert horiz to 1024 angle units
float const horizAngle = clamp(atan2f(PlayerList[nLocalPlayer].q16horiz - fix16_from_int(92), fix16_from_int(128)) * (512.f / fPI) + fix16_to_float(input.q16horz), -255.f, 255.f);
PlayerList[nLocalPlayer].q16horiz = fix16_from_int(92) + Blrintf(fix16_from_int(128) * tanf(horizAngle * (fPI / 512.f)));
// Look/aim up/down functions.
if (buttonMap.ButtonDown(gamefunc_Look_Up) || buttonMap.ButtonDown(gamefunc_Aim_Up))
{
bLockPan = false;
if (PlayerList[nLocalPlayer].q16horiz < fix16_from_int(180)) {
PlayerList[nLocalPlayer].q16horiz = fix16_sadd(PlayerList[nLocalPlayer].q16horiz, fix16_from_dbl(scaleAdjustmentToInterval(4)));
}
bPlayerPan = true;
nDestVertPan[nLocalPlayer] = PlayerList[nLocalPlayer].q16horiz;
}
else if (buttonMap.ButtonDown(gamefunc_Look_Down) || buttonMap.ButtonDown(gamefunc_Aim_Down))
{
bLockPan = false;
if (PlayerList[nLocalPlayer].q16horiz > fix16_from_int(4)) {
PlayerList[nLocalPlayer].q16horiz = fix16_ssub(PlayerList[nLocalPlayer].q16horiz, fix16_from_dbl(scaleAdjustmentToInterval(4)));
}
bPlayerPan = true;
nDestVertPan[nLocalPlayer] = PlayerList[nLocalPlayer].q16horiz;
}
}
// loc_1C048:
if (totalvel[nLocalPlayer] > 20) {
bPlayerPan = false;
}
if (g_MyAimMode)
bLockPan = true;
// loc_1C05E
fix16_t ecx = nDestVertPan[nLocalPlayer] - PlayerList[nLocalPlayer].q16horiz;
if (g_MyAimMode)
{
ecx = 0;
}
if (!nFreeze)
{
if (ecx)
{
if (ecx / 4 == 0)
{
if (ecx >= 0) {
ecx = 1;
}
else
{
ecx = -1;
}
}
else
{
ecx /= 4;
if (ecx > fix16_from_int(4))
{
ecx = fix16_from_int(4);
}
else if (ecx < -fix16_from_int(4))
{
ecx = -fix16_from_int(4);
}
}
PlayerList[nLocalPlayer].q16horiz = fix16_sadd(PlayerList[nLocalPlayer].q16horiz, ecx);
}
PlayerList[nLocalPlayer].q16horiz = fix16_clamp(PlayerList[nLocalPlayer].q16horiz, fix16_from_int(0), fix16_from_int(184));
}
}
void RestoreSavePoint(int nPlayer, int *x, int *y, int *z, short *nSector, short *nAngle)
{
*x = sPlayerSave[nPlayer].x;
@ -2884,7 +2665,7 @@ loc_1BD2E:
// loc_1BE70:
// Handle player pressing number keys to change weapon
uint8_t var_90 = (buttons >> 13) & 0xF;
uint8_t var_90 = sPlayerInput[nPlayer].getNewWeapon();
if (var_90)
{
@ -3108,7 +2889,6 @@ static SavegameHelper sgh("player",
SV(bobangle),
SV(bPlayerPan),
SV(bLockPan),
SV(g_MyAimMode),
SV(nStandHeight),
SV(PlayerCount),
SV(nNetStartSprites),

View file

@ -23,7 +23,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
BEGIN_PS_NS
void PlayerInterruptKeys();
void PlayerInterruptKeys(bool after);
void RestoreSavePoint(int nPlayer, int *x, int *y, int *z, short *nSector, short *nAngle);
void SetSavePoint(int nPlayer, int x, int y, int z, short nSector, short nAngle);
void InitPlayer();

View file

@ -33,6 +33,18 @@ struct PlayerInput
short nTarget;
fix16_t horizon;
int8_t nItem;
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 InitInput();