From a731db95aecf335abd8aaf8992db9c28563a6975 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Sun, 23 Apr 2023 19:34:59 +1000 Subject: [PATCH] - 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. --- source/core/d_net.cpp | 4 ++++ source/core/d_protocol.cpp | 16 +++++++++++++--- source/core/gameinput.cpp | 6 ++++++ source/core/inputstate.cpp | 2 ++ source/core/inputstate.h | 2 ++ source/core/packet.h | 1 + source/games/duke/src/player_d.cpp | 10 ++++++---- 7 files changed, 34 insertions(+), 7 deletions(-) diff --git a/source/core/d_net.cpp b/source/core/d_net.cpp index 511ebc560..e1d4d8939 100644 --- a/source/core/d_net.cpp +++ b/source/core/d_net.cpp @@ -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; } diff --git a/source/core/d_protocol.cpp b/source/core/d_protocol.cpp index be7c8196e..15525471e 100644 --- a/source/core/d_protocol.cpp +++ b/source/core/d_protocol.cpp @@ -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; diff --git a/source/core/gameinput.cpp b/source/core/gameinput.cpp index cb4307251..615299d8c 100644 --- a/source/core/gameinput.cpp +++ b/source/core/gameinput.cpp @@ -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); diff --git a/source/core/inputstate.cpp b/source/core/inputstate.cpp index 6c2e36d40..f69e18066 100644 --- a/source/core/inputstate.cpp +++ b/source/core/inputstate.cpp @@ -110,6 +110,8 @@ void SetupGameButtons() "Dpad_Aiming", "Toggle_Crouch", "Quick_Kick", + "Move_Up", + "Move_Down", "AM_PanLeft", "AM_PanRight", "AM_PanUp", diff --git a/source/core/inputstate.h b/source/core/inputstate.h index 3d9dbca8e..e88310455 100644 --- a/source/core/inputstate.h +++ b/source/core/inputstate.h @@ -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, diff --git a/source/core/packet.h b/source/core/packet.h index 0f579dd96..76d9e3a4b 100644 --- a/source/core/packet.h +++ b/source/core/packet.h @@ -72,6 +72,7 @@ struct InputPacket { float svel; float fvel; + float uvel; float avel; float horz; ESyncBits actions; diff --git a/source/games/duke/src/player_d.cpp b/source/games/duke/src/player_d.cpp index 25a827416..84bda1033 100644 --- a/source/games/duke/src/player_d.cpp +++ b/source/games/duke/src/player_d.cpp @@ -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; } }