- Add initial support for up/down movement within the game, either by key or joystick axis.

* Started with Duke's jetpack, other games to follow for swimming, etc.
This commit is contained in:
Mitchell Richters 2023-04-23 19:34:59 +10:00
parent 87144564fd
commit a731db95ae
7 changed files with 34 additions and 7 deletions

View file

@ -1034,6 +1034,7 @@ void NetUpdate (void)
float svel = 0;
float fvel = 0;
float uvel = 0;
float avel = 0;
float horz = 0;
@ -1042,12 +1043,14 @@ void NetUpdate (void)
modp = (mod + tic) % LOCALCMDTICS;
svel += localcmds[modp].ucmd.svel;
fvel += localcmds[modp].ucmd.fvel;
uvel += localcmds[modp].ucmd.uvel;
avel += localcmds[modp].ucmd.avel;
horz += localcmds[modp].ucmd.horz;
}
svel /= ticdup;
fvel /= ticdup;
uvel /= ticdup;
avel /= ticdup;
horz /= ticdup;
@ -1056,6 +1059,7 @@ void NetUpdate (void)
modp = (mod + tic) % LOCALCMDTICS;
localcmds[modp].ucmd.svel = svel;
localcmds[modp].ucmd.fvel = fvel;
localcmds[modp].ucmd.uvel = uvel;
localcmds[modp].ucmd.avel = avel;
localcmds[modp].ucmd.horz = horz;
}

View file

@ -167,6 +167,8 @@ int UnpackUserCmd (InputPacket *ucmd, const InputPacket *basis, uint8_t **stream
ucmd->fvel = ReadFloat(stream);
if (flags & UCMDF_SIDEMOVE)
ucmd->svel = ReadFloat(stream);
if (flags & UCMDF_UPMOVE)
ucmd->uvel = ReadFloat(stream);
}
return int(*stream - start);
@ -213,6 +215,11 @@ int PackUserCmd (const InputPacket *ucmd, const InputPacket *basis, uint8_t **st
flags |= UCMDF_SIDEMOVE;
WriteFloat (ucmd->svel, stream);
}
if (ucmd->uvel != basis->uvel)
{
flags |= UCMDF_UPMOVE;
WriteFloat (ucmd->uvel, stream);
}
// Write the packing bits
WriteByte (flags, &temp);
@ -239,7 +246,8 @@ FSerializer &Serialize(FSerializer &arc, const char *key, InputPacket &cmd, Inpu
("horz", cmd.horz)
("avel", cmd.avel)
("fvel", cmd.fvel)
("svwl", cmd.svel)
("svel", cmd.svel)
("uvel", cmd.uvel)
.EndObject();
}
return arc;
@ -253,7 +261,8 @@ int WriteUserCmdMessage (InputPacket *ucmd, const InputPacket *basis, uint8_t **
ucmd->horz != 0 ||
ucmd->avel != 0 ||
ucmd->fvel != 0 ||
ucmd->svel != 0)
ucmd->svel != 0 ||
ucmd->uvel != 0)
{
WriteByte (DEM_USERCMD, stream);
return PackUserCmd (ucmd, basis, stream) + 1;
@ -264,7 +273,8 @@ int WriteUserCmdMessage (InputPacket *ucmd, const InputPacket *basis, uint8_t **
ucmd->horz != basis->horz ||
ucmd->avel != basis->avel ||
ucmd->fvel != basis->fvel ||
ucmd->svel != basis->svel)
ucmd->svel != basis->svel ||
ucmd->uvel != basis->uvel)
{
WriteByte (DEM_USERCMD, stream);
return PackUserCmd (ucmd, basis, stream) + 1;

View file

@ -128,6 +128,10 @@ void GameInput::processMovement(PlayerAngles* const plrAngles, const float scale
buttonMap.ButtonDown(gamefunc_Strafe_Left) -
joyAxes[JOYAXIS_Side] * scaleAdjust;
const auto soaring = buttonMap.ButtonDown(gamefunc_Move_Up) -
buttonMap.ButtonDown(gamefunc_Move_Down) +
joyAxes[JOYAXIS_Up] * scaleAdjust;
// process player yaw input.
if (!(buttonMap.ButtonDown(gamefunc_Strafe) && allowstrafe))
{
@ -160,6 +164,7 @@ void GameInput::processMovement(PlayerAngles* const plrAngles, const float scale
// process movement input.
thisInput.fvel += moving * keymove;
thisInput.svel += strafing * keymove * allowstrafe;
thisInput.uvel += soaring; // this isn't scaled by running.
// process RR's drunk state.
if (isRR() && drink_amt >= 66 && drink_amt <= 87)
@ -170,6 +175,7 @@ void GameInput::processMovement(PlayerAngles* const plrAngles, const float scale
// add collected input to game's local input accumulation packet.
inputBuffer.fvel = clamp(inputBuffer.fvel + thisInput.fvel, -(float)keymove, (float)keymove);
inputBuffer.svel = clamp(inputBuffer.svel + thisInput.svel, -(float)keymove, (float)keymove);
inputBuffer.uvel = clamp(inputBuffer.uvel + thisInput.uvel, -1.00f, 1.00f);
inputBuffer.avel = clamp(inputBuffer.avel + thisInput.avel, -179.f, 179.f);
inputBuffer.horz = clamp(inputBuffer.horz + thisInput.horz, -179.f, 179.f);

View file

@ -110,6 +110,8 @@ void SetupGameButtons()
"Dpad_Aiming",
"Toggle_Crouch",
"Quick_Kick",
"Move_Up",
"Move_Down",
"AM_PanLeft",
"AM_PanRight",
"AM_PanUp",

View file

@ -88,6 +88,8 @@ enum GameFunction_t
gamefunc_Dpad_Aiming,
gamefunc_Toggle_Crouch,
gamefunc_Quick_Kick,
gamefunc_Move_Up,
gamefunc_Move_Down,
gamefunc_AM_PanLeft,
gamefunc_AM_PanRight,
gamefunc_AM_PanUp,

View file

@ -72,6 +72,7 @@ struct InputPacket
{
float svel;
float fvel;
float uvel;
float avel;
float horz;
ESyncBits actions;

View file

@ -600,26 +600,28 @@ static void operateJetpack(int snum, ESyncBits actions, int psectlotag, double f
S_PlayActorSound(DUKE_JETPACK_IDLE, pact);
}
if (actions & SB_JUMP) //A (soar high)
if ((actions & SB_JUMP) || p->sync.uvel > 0) //A (soar high)
{
// jump
SetGameVarID(g_iReturnVarID, 0, pact, snum);
OnEvent(EVENT_SOARUP, snum, pact, -1);
if (GetGameVarID(g_iReturnVarID, pact, snum).value() == 0)
{
pact->spr.pos.Z -= dist;
pact->spr.pos.Z -= dist * !!(actions & SB_JUMP);
pact->spr.pos.Z -= dist * p->sync.uvel;
p->crack_time = CRACK_TIME;
}
}
if (actions & SB_CROUCH) //Z (soar low)
if ((actions & SB_CROUCH) || p->sync.uvel < 0) //Z (soar low)
{
// crouch
SetGameVarID(g_iReturnVarID, 0, pact, snum);
OnEvent(EVENT_SOARDOWN, snum, pact, -1);
if (GetGameVarID(g_iReturnVarID, pact, snum).value() == 0)
{
pact->spr.pos.Z += dist;
pact->spr.pos.Z += dist * !!(actions & SB_CROUCH);
pact->spr.pos.Z -= dist * p->sync.uvel;
p->crack_time = CRACK_TIME;
}
}