From c84d9f24fdc0a45db6ca9715ed11fe21a9a728b5 Mon Sep 17 00:00:00 2001 From: James R Date: Mon, 14 Aug 2023 01:55:00 -0700 Subject: [PATCH] P_DemoCameraMovement: don't let A button press from menu carry over to rise camera --- src/m_menu.c | 1 + src/menus/transient/pause-replay.c | 261 +++++++++++++++++++++++++++++ src/p_local.h | 8 + src/p_user.c | 17 +- 4 files changed, 283 insertions(+), 4 deletions(-) create mode 100644 src/menus/transient/pause-replay.c diff --git a/src/m_menu.c b/src/m_menu.c index dd68f5db1..e023026ea 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -4223,6 +4223,7 @@ void M_PlaybackToggleFreecam(INT32 choice) if (!demo.freecam) // toggle on { demo.freecam = true; + democam.button_a_held = 2; } else // toggle off { diff --git a/src/menus/transient/pause-replay.c b/src/menus/transient/pause-replay.c new file mode 100644 index 000000000..46c0a6cfb --- /dev/null +++ b/src/menus/transient/pause-replay.c @@ -0,0 +1,261 @@ +/// \file menus/transient/pause-replay.c +/// \brief Replay popup menu + +#include "../../k_menu.h" +#include "../../s_sound.h" +#include "../../p_tick.h" // leveltime +#include "../../i_time.h" +#include "../../r_main.h" // R_ExecuteSetViewSize +#include "../../p_local.h" // P_InitCameraCmd +#include "../../d_main.h" // D_StartTitle + +static void M_PlaybackTick(void); + +menuitem_t PAUSE_PlaybackMenu[] = +{ + {IT_CALL | IT_STRING, "Hide Menu", NULL, "M_PHIDE", {.routine = M_SelectableClearMenus}, 0, 0}, + + {IT_CALL | IT_STRING, "Rewind", NULL, "M_PREW", {.routine = M_PlaybackRewind}, 20, 0}, + {IT_CALL | IT_STRING, "Pause", NULL, "M_PPAUSE", {.routine = M_PlaybackPause}, 36, 0}, + {IT_CALL | IT_STRING, "Fast-Forward", NULL, "M_PFFWD", {.routine = M_PlaybackFastForward}, 52, 0}, + {IT_CALL | IT_STRING, "Backup Frame", NULL, "M_PSTEPB", {.routine = M_PlaybackRewind}, 20, 0}, + {IT_CALL | IT_STRING, "Resume", NULL, "M_PRESUM", {.routine = M_PlaybackPause}, 36, 0}, + {IT_CALL | IT_STRING, "Advance Frame", NULL, "M_PFADV", {.routine = M_PlaybackAdvance}, 52, 0}, + + {IT_ARROWS | IT_STRING, "View Count", NULL, "M_PVIEWS", {.routine = M_PlaybackSetViews}, 72, 0}, + {IT_ARROWS | IT_STRING, "Viewpoint", NULL, "M_PNVIEW", {.routine = M_PlaybackAdjustView}, 88, 0}, + {IT_ARROWS | IT_STRING, "Viewpoint 2", NULL, "M_PNVIEW", {.routine = M_PlaybackAdjustView}, 104, 0}, + {IT_ARROWS | IT_STRING, "Viewpoint 3", NULL, "M_PNVIEW", {.routine = M_PlaybackAdjustView}, 120, 0}, + {IT_ARROWS | IT_STRING, "Viewpoint 4", NULL, "M_PNVIEW", {.routine = M_PlaybackAdjustView}, 136, 0}, + + {IT_CALL | IT_STRING, "Toggle Free Camera", NULL, "M_PVIEWS", {.routine = M_PlaybackToggleFreecam}, 156, 0}, + {IT_CALL | IT_STRING, "Stop Playback", NULL, "M_PEXIT", {.routine = M_PlaybackQuit}, 172, 0}, +}; + +menu_t PAUSE_PlaybackMenuDef = { + sizeof (PAUSE_PlaybackMenu) / sizeof (menuitem_t), + NULL, + 0, + PAUSE_PlaybackMenu, + BASEVIDWIDTH/2 - 88, 2, + 0, 0, + MBF_UD_LR_FLIPPED, + NULL, + 0, 0, + M_DrawPlaybackMenu, + M_PlaybackTick, + NULL, + NULL, + NULL +}; + +void M_EndModeAttackRun(void) +{ + G_CheckDemoStatus(); // Cancel recording + + Command_ExitGame_f(); // Clear a bunch of state + + modeattacking = ATTACKING_NONE; // Kept until now because of Command_ExitGame_f + + if (demo.title == true) + { + D_StartTitle(); + } + else + { + D_ClearState(); + M_StartControlPanel(); + } +} + +// Replay Playback Menu + +tic_t playback_last_menu_interaction_leveltime = 0; + +static void M_PlaybackTick(void) +{ + INT16 i; + + if (leveltime - playback_last_menu_interaction_leveltime >= 6*TICRATE) + playback_last_menu_interaction_leveltime = leveltime - 6*TICRATE; + + // Toggle items + if (paused && !demo.rewinding) + { + PAUSE_PlaybackMenu[playback_pause].status = PAUSE_PlaybackMenu[playback_fastforward].status = PAUSE_PlaybackMenu[playback_rewind].status = IT_DISABLED; + PAUSE_PlaybackMenu[playback_resume].status = PAUSE_PlaybackMenu[playback_advanceframe].status = PAUSE_PlaybackMenu[playback_backframe].status = IT_CALL|IT_STRING; + + if (itemOn >= playback_rewind && itemOn <= playback_fastforward) + itemOn += playback_backframe - playback_rewind; + } + else + { + PAUSE_PlaybackMenu[playback_pause].status = PAUSE_PlaybackMenu[playback_fastforward].status = PAUSE_PlaybackMenu[playback_rewind].status = IT_CALL|IT_STRING; + PAUSE_PlaybackMenu[playback_resume].status = PAUSE_PlaybackMenu[playback_advanceframe].status = PAUSE_PlaybackMenu[playback_backframe].status = IT_DISABLED; + + if (itemOn >= playback_backframe && itemOn <= playback_advanceframe) + itemOn -= playback_backframe - playback_rewind; + } + + if (modeattacking) + { + for (i = playback_viewcount; i <= playback_view4; i++) + PAUSE_PlaybackMenu[i].status = IT_DISABLED; + + //PAUSE_PlaybackMenu[playback_moreoptions].mvar1 = 72; + //PAUSE_PlaybackMenu[playback_quit].mvar1 = 88; + PAUSE_PlaybackMenu[playback_quit].mvar1 = 72; + + //currentMenu->x = BASEVIDWIDTH/2 - 52; + currentMenu->x = BASEVIDWIDTH/2 - 44; + } + else + { + PAUSE_PlaybackMenu[playback_viewcount].status = IT_ARROWS|IT_STRING; + + for (i = 0; i <= r_splitscreen; i++) + PAUSE_PlaybackMenu[playback_view1+i].status = IT_ARROWS|IT_STRING; + for (i = r_splitscreen+1; i < 4; i++) + PAUSE_PlaybackMenu[playback_view1+i].status = IT_DISABLED; + + //PAUSE_PlaybackMenu[playback_moreoptions].mvar1 = 156; + //PAUSE_PlaybackMenu[playback_quit].mvar1 = 172; + PAUSE_PlaybackMenu[playback_quit].mvar1 = 156; + + //currentMenu->x = BASEVIDWIDTH/2 - 94; + currentMenu->x = BASEVIDWIDTH/2 - 88; + } +} + +void M_SetPlaybackMenuPointer(void) +{ + itemOn = playback_pause; +} + +void M_PlaybackRewind(INT32 choice) +{ + static tic_t lastconfirmtime; + + (void)choice; + + if (!demo.rewinding) + { + if (paused) + { + G_ConfirmRewind(leveltime-1); + paused = true; + S_PauseAudio(); + } + else + demo.rewinding = paused = true; + } + else if (lastconfirmtime + TICRATE/2 < I_GetTime()) + { + lastconfirmtime = I_GetTime(); + G_ConfirmRewind(leveltime); + } + + CV_SetValue(&cv_playbackspeed, 1); +} + +void M_PlaybackPause(INT32 choice) +{ + (void)choice; + + paused = !paused; + + if (demo.rewinding) + { + G_ConfirmRewind(leveltime); + paused = true; + S_PauseAudio(); + } + else if (paused) + S_PauseAudio(); + else + S_ResumeAudio(); + + CV_SetValue(&cv_playbackspeed, 1); +} + +void M_PlaybackFastForward(INT32 choice) +{ + (void)choice; + + if (demo.rewinding) + { + G_ConfirmRewind(leveltime); + paused = false; + S_ResumeAudio(); + } + CV_SetValue(&cv_playbackspeed, cv_playbackspeed.value == 1 ? 4 : 1); +} + +void M_PlaybackAdvance(INT32 choice) +{ + (void)choice; + + paused = false; + TryRunTics(1); + paused = true; +} + +void M_PlaybackSetViews(INT32 choice) +{ + if (choice > 0) + { + if (r_splitscreen < 3) + G_AdjustView(r_splitscreen + 2, 0, true); + } + else if (r_splitscreen) + { + if (choice == 0) + { + r_splitscreen--; + } + else + { + r_splitscreen = 0; + } + R_ExecuteSetViewSize(); + } +} + +void M_PlaybackAdjustView(INT32 choice) +{ + G_AdjustView(itemOn - playback_viewcount, (choice > 0) ? 1 : -1, true); +} + +// this one's rather tricky +void M_PlaybackToggleFreecam(INT32 choice) +{ + (void)choice; + M_ClearMenus(true); + + // remove splitscreen: + splitscreen = 0; + R_ExecuteSetViewSize(); + + if (!demo.freecam) // toggle on + { + demo.freecam = true; + democam.button_a_held = 2; + } + else // toggle off + { + demo.freecam = false; + } +} + +void M_PlaybackQuit(INT32 choice) +{ + (void)choice; + G_StopDemo(); + + if (modeattacking) + M_EndModeAttackRun(); + else if (restoreMenu) + M_StartControlPanel(); + else + D_StartTitle(); +} diff --git a/src/p_local.h b/src/p_local.h index 35c6eb6cd..1ebcecbff 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -133,6 +133,14 @@ struct camera_t angle_t old_angle, old_aiming; }; +// demo freecam or something before i commit die +struct demofreecam_s { + + UINT8 button_a_held; // A button was held since entering from menu, so don't move camera +}; + +extern struct demofreecam_s democam; + extern camera_t camera[MAXSPLITSCREENPLAYERS]; extern consvar_t cv_cam_dist[MAXSPLITSCREENPLAYERS], cv_cam_still[MAXSPLITSCREENPLAYERS], cv_cam_height[MAXSPLITSCREENPLAYERS]; extern consvar_t cv_cam_speed[MAXSPLITSCREENPLAYERS], cv_cam_rotate[MAXSPLITSCREENPLAYERS]; diff --git a/src/p_user.c b/src/p_user.c index bb954160c..3d6b81d5c 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -2644,6 +2644,7 @@ fixed_t t_cam_height[MAXSPLITSCREENPLAYERS] = {-42,-42,-42,-42}; fixed_t t_cam_rotate[MAXSPLITSCREENPLAYERS] = {-42,-42,-42,-42}; static ticcmd_t cameracmd; +struct demofreecam_s democam; // called by m_menu to reinit cam input every time it's toggled void P_InitCameraCmd(void) @@ -2666,10 +2667,18 @@ void P_DemoCameraMovement(camera_t *cam) cam->aiming = G_ClipAimingPitch((INT32 *)&cam->aiming); // camera movement: - if (cmd->buttons & BT_ACCELERATE) - cam->z += 32*mapobjectscale; - else if (cmd->buttons & BT_BRAKE) - cam->z -= 32*mapobjectscale; + if (!democam.button_a_held) + { + if (cmd->buttons & BT_ACCELERATE) + cam->z += 32*mapobjectscale; + else if (cmd->buttons & BT_BRAKE) + cam->z -= 32*mapobjectscale; + } + + if (!(cmd->buttons & BT_ACCELERATE) && democam.button_a_held) + { + democam.button_a_held--; + } // if you hold item, you will lock on to displayplayer. (The last player you were ""f12-ing"") if (demo.freecam && cmd->buttons & BT_ATTACK)