diff --git a/docs/tr2/CHANGELOG.md b/docs/tr2/CHANGELOG.md index 6e54912b8..337cbd1da 100644 --- a/docs/tr2/CHANGELOG.md +++ b/docs/tr2/CHANGELOG.md @@ -4,6 +4,7 @@ - added a level skip cheat key (#1640) - added the ability to skip end credits with the action and escape keys (#1800) - added the ability to skip FMVs with the action key (#1650) +- added the ability to hold forward/back to move through menus more quickly (#1644) - changed the inputs backend from DirectX to SDL (#1695) - improved controller support to match TR1X - changed the number of custom layouts to 3 diff --git a/docs/tr2/README.md b/docs/tr2/README.md index 67e37c9cc..e22e02655 100644 --- a/docs/tr2/README.md +++ b/docs/tr2/README.md @@ -40,6 +40,9 @@ decompilation process. We recognize that there is much work to be done. - fixed the dragon counting as more than one kill if allowed to revive - fixed enemies that are run over by the skidoo not being counted in the statistics +#### Input +- added the ability to hold forward/back to move through menus more quickly + #### Visuals - fixed TGA screenshots crashing the game diff --git a/src/tr2/game/clock.c b/src/tr2/game/clock.c index b43fbe6fa..e7f32aa2d 100644 --- a/src/tr2/game/clock.c +++ b/src/tr2/game/clock.c @@ -1,5 +1,7 @@ #include "game/clock.h" +#include + #include double Clock_GetHighPrecisionCounter(void) @@ -10,3 +12,8 @@ double Clock_GetHighPrecisionCounter(void) QueryPerformanceCounter(&counter); return counter.QuadPart * 1000.0 / frequency.QuadPart; } + +int32_t Clock_GetLogicalFrame(void) +{ + return Clock_GetHighPrecisionCounter() * LOGIC_FPS / 1000.0; +} diff --git a/src/tr2/game/clock.h b/src/tr2/game/clock.h index 5b4d9b743..8904d045d 100644 --- a/src/tr2/game/clock.h +++ b/src/tr2/game/clock.h @@ -1,3 +1,6 @@ #pragma once +#include + double Clock_GetHighPrecisionCounter(void); +int32_t Clock_GetLogicalFrame(void); diff --git a/src/tr2/game/input.c b/src/tr2/game/input.c index 077bb1ab7..7547ebce7 100644 --- a/src/tr2/game/input.c +++ b/src/tr2/game/input.c @@ -1,6 +1,7 @@ #include "game/input.h" #include "config.h" +#include "game/clock.h" #include "game/console/common.h" #include "game/game_string.h" #include "game/shell.h" @@ -11,6 +12,12 @@ #include #include +#define DELAY_FRAMES 12 +#define HOLD_FRAMES 3 + +static int32_t m_HoldBack = 0; +static int32_t m_HoldForward = 0; + static INPUT_STATE M_GetDebounced(INPUT_STATE input); static void M_UpdateFromBackend( INPUT_STATE *s, const INPUT_BACKEND_IMPL *backend, INPUT_LAYOUT layout); @@ -20,6 +27,28 @@ static INPUT_STATE M_GetDebounced(const INPUT_STATE input) INPUT_STATE result; result.any = input.any & ~g_OldInputDB.any; + const int32_t frame = Clock_GetLogicalFrame(); + if (input.forward || !input.back) { + m_HoldBack = 0; + } else if (input.back && m_HoldBack == 0) { + m_HoldBack = frame; + } else if (input.back && frame - m_HoldBack >= DELAY_FRAMES + HOLD_FRAMES) { + result.back = 1; + result.menu_down = 1; + m_HoldBack = frame - DELAY_FRAMES; + } + + if (!input.forward || input.back) { + m_HoldForward = 0; + } else if (input.forward && m_HoldForward == 0) { + m_HoldForward = frame; + } else if ( + input.forward && frame - m_HoldForward >= DELAY_FRAMES + HOLD_FRAMES) { + result.forward = 1; + result.menu_up = 1; + m_HoldForward = frame - DELAY_FRAMES; + } + g_OldInputDB = input; return result; }