From bd989239ea90c29f748caee0f06383b75d55115f Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 3 Jan 2025 01:18:30 +0100 Subject: [PATCH] add another local ticcmd builder so it can guess if we "moved" and put us into freecam state and shit --- src/d_player.h | 2 - src/g_game.c | 108 ++++++++++++++++++++++++++++++++----------------- src/p_mobj.c | 2 - src/p_user.c | 21 ++++------ 4 files changed, 79 insertions(+), 54 deletions(-) diff --git a/src/d_player.h b/src/d_player.h index a34094572..140a4a748 100644 --- a/src/d_player.h +++ b/src/d_player.h @@ -538,8 +538,6 @@ typedef struct player_s INT32 awayviewtics; angle_t awayviewaiming; // Used for cut-away view - boolean speccam; - boolean spectator; UINT8 bot; diff --git a/src/g_game.c b/src/g_game.c index aced49428..7558f32b8 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -848,6 +848,76 @@ static fixed_t forwardmove[2] = {25<>16, 50<>16}; static fixed_t sidemove[2] = {2<>16, 4<>16}; static fixed_t angleturn[3] = {KART_FULLTURN/2, KART_FULLTURN, KART_FULLTURN/4}; // + slow turn +// this is absolutely awful +// but we need this if we dont want spectators to move but be able to go to freecam from watching someone +static void G_BuildLocalTiccmd(UINT8 ssplayer) +{ + const UINT8 forplayer = ssplayer-1; + boolean forward, side, axis; //i + boolean usejoystick; + boolean turnleft, turnright; + + ticcmd_t *cmd = D_LocalTiccmd(forplayer); + + const boolean analogjoystickmove = cv_usejoystick[forplayer].value && !Joystick[forplayer].bGamepadStyle; + const boolean gamepadjoystickmove = cv_usejoystick[forplayer].value && Joystick[forplayer].bGamepadStyle; + + usejoystick = (analogjoystickmove || gamepadjoystickmove); + + turnright = InputDown(gc_turnright, ssplayer); + turnleft = InputDown(gc_turnleft, ssplayer); + + axis = JoyAxis(AXISTURN, ssplayer); + + if (gamepadjoystickmove && axis != 0) + { + turnright = turnright || (axis > 0); + turnleft = turnleft || (axis < 0); + } + side = (turnright || turnleft || (analogjoystickmove && axis != 0)); + + forward = false; + axis = JoyAxis(AXISAIM, ssplayer); + if (InputDown(gc_aimforward, ssplayer) || (usejoystick && axis < 0)) + forward = true; + if (InputDown(gc_aimbackward, ssplayer) || (usejoystick && axis > 0)) + forward = true; + + axis = JoyAxis(AXISMOVE, ssplayer); + if (InputDown(gc_accelerate, ssplayer) || (usejoystick && axis > 0)) + cmd->buttons |= BT_ACCELERATE; + axis = JoyAxis(AXISBRAKE, ssplayer); + if (InputDown(gc_brake, ssplayer) || (usejoystick && axis > 0)) + cmd->buttons |= BT_BRAKE; + axis = JoyAxis(AXISFIRE, ssplayer); + if (InputDown(gc_fire, ssplayer) || (usejoystick && axis > 0)) + cmd->buttons |= BT_ATTACK; + + // drift with any button/key + axis = JoyAxis(AXISDRIFT, ssplayer); + if (InputDown(gc_drift, ssplayer) || (usejoystick && axis > 0)) + cmd->buttons |= BT_DRIFT; + + // Lua scriptable buttons + axis = JoyAxis(AXISCUSTOM1, ssplayer); + if (InputDown(gc_custom1, ssplayer) || (usejoystick && axis > 0)) + cmd->buttons |= BT_CUSTOM1; + axis = JoyAxis(AXISCUSTOM2, ssplayer); + if (InputDown(gc_custom2, ssplayer) || (usejoystick && axis > 0)) + cmd->buttons |= BT_CUSTOM2; + axis = JoyAxis(AXISCUSTOM3, ssplayer); + if (InputDown(gc_custom3, ssplayer) || (usejoystick && axis > 0)) + cmd->buttons |= BT_CUSTOM3; + + //Reset away view if a command is given. + if ((forward || side || cmd->buttons) + && displayplayers[0] != consoleplayer && ssplayer == 1) + { + displayplayers[0] = consoleplayer; + G_FixCamera(1); + } +} + void G_BuildTiccmd(ticcmd_t *cmd, INT32 realtics, UINT8 ssplayer) { const UINT8 forplayer = ssplayer-1; @@ -916,43 +986,7 @@ void G_BuildTiccmd(ticcmd_t *cmd, INT32 realtics, UINT8 ssplayer) // lmfao this is beyond hellish if (player->spectator) { - usejoystick = (analogjoystickmove || gamepadjoystickmove); - - axis = JoyAxis(AXISMOVE, ssplayer); - if (InputDown(gc_accelerate, ssplayer) || (usejoystick && axis > 0)) - cmd->buttons |= BT_ACCELERATE; - axis = JoyAxis(AXISBRAKE, ssplayer); - if (InputDown(gc_brake, ssplayer) || (usejoystick && axis > 0)) - cmd->buttons |= BT_BRAKE; - axis = JoyAxis(AXISFIRE, ssplayer); - if (InputDown(gc_fire, ssplayer) || (usejoystick && axis > 0)) - cmd->buttons |= BT_ATTACK; - - // drift with any button/key - axis = JoyAxis(AXISDRIFT, ssplayer); - if (InputDown(gc_drift, ssplayer) || (usejoystick && axis > 0)) - cmd->buttons |= BT_DRIFT; - - // Lua scriptable buttons - axis = JoyAxis(AXISCUSTOM1, ssplayer); - if (InputDown(gc_custom1, ssplayer) || (usejoystick && axis > 0)) - cmd->buttons |= BT_CUSTOM1; - axis = JoyAxis(AXISCUSTOM2, ssplayer); - if (InputDown(gc_custom2, ssplayer) || (usejoystick && axis > 0)) - cmd->buttons |= BT_CUSTOM2; - axis = JoyAxis(AXISCUSTOM3, ssplayer); - if (InputDown(gc_custom3, ssplayer) || (usejoystick && axis > 0)) - cmd->buttons |= BT_CUSTOM3; - - // Reset camera - if (InputDown(gc_camreset, ssplayer)) - { - if (thiscam->chase && !rd) - P_ResetCamera(player, thiscam); - rd = true; - } - else - rd = false; + G_BuildLocalTiccmd(ssplayer); if (gamestate == GS_LEVEL) LUA_HookTiccmd(player, cmd, HOOK(PlayerCmd)); diff --git a/src/p_mobj.c b/src/p_mobj.c index b77392f89..e1e25a3aa 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -10710,7 +10710,6 @@ void P_SpawnPlayer(INT32 playernum) else if (!G_GametypeHasSpectators()) { p->spectator = false; - p->speccam = false; } else if (netgame && p->jointime <= 1 && pcount) { @@ -10745,7 +10744,6 @@ void P_SpawnPlayer(INT32 playernum) else // Otherwise, never spectator. { p->spectator = false; - p->speccam = false; } } diff --git a/src/p_user.c b/src/p_user.c index 353d127a0..6325e662e 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -2272,9 +2272,9 @@ static void P_MovePlayer(player_t *player) } } + // have to keep this crap for synch reasons if (player->spectator) { - player->speccam = true; P_SpectatorMovement(player); return; } @@ -3360,17 +3360,14 @@ static void P_DemoCameraMovement(camera_t *cam, UINT8 num) // if you hold item, you will lock on to displayplayer. (The last player you were ""f12-ing"") // well this only really works in replays for us, since we still move our spec player around which causes displayplayer to be the spec player - if (demo.playback) + if (cmd->buttons & BT_ATTACK) { - if (cmd->buttons & BT_ATTACK) - { - lastp = &players[displayplayers[0]]; // Fun fact, I was trying displayplayers[0]->mo as if it was Lua like an absolute idiot. + lastp = &players[displayplayers[0]]; // Fun fact, I was trying displayplayers[0]->mo as if it was Lua like an absolute idiot. - const fixed_t dist = R_PointToDist2(cam->x, cam->y, lastp->mo->x, lastp->mo->y); - cam->angle = R_PointToAngle2(cam->x, cam->y, lastp->mo->x, lastp->mo->y); - cam->aiming = R_PointToAngle2(0, cam->z, dist, lastp->mo->z + lastp->mo->scale*128*P_MobjFlip(lastp->mo)); // This is still unholy. Aim a bit above their heads. - cam->reset_aiming = false; - } + const fixed_t dist = R_PointToDist2(cam->x, cam->y, lastp->mo->x, lastp->mo->y); + cam->angle = R_PointToAngle2(cam->x, cam->y, lastp->mo->x, lastp->mo->y); + cam->aiming = R_PointToAngle2(0, cam->z, dist, lastp->mo->z + lastp->mo->scale*128*P_MobjFlip(lastp->mo)); // This is still unholy. Aim a bit above their heads. + cam->reset_aiming = false; } if (cmd->forwardmove != 0) @@ -3721,7 +3718,7 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall num = 0; } - if (thiscam->freecam || (player->spectator && player->speccam == true)) + if (thiscam->freecam || player->spectator) { P_DemoCameraMovement(thiscam, num); return true; @@ -4101,7 +4098,6 @@ boolean P_SpectatorJoinGame(player_t *player) player->mo = NULL; } player->spectator = false; - player->speccam = false; player->pflags &= ~PF_WANTSTOJOIN; player->kartstuff[k_spectatewait] = 0; player->ctfteam = changeto; @@ -4130,7 +4126,6 @@ boolean P_SpectatorJoinGame(player_t *player) player->mo = NULL; } player->spectator = false; - player->speccam = false; player->pflags &= ~PF_WANTSTOJOIN; player->kartstuff[k_spectatewait] = 0; player->playerstate = PST_REBORN;