tr2/input: allow holding up/down in menus

This mimics the TR1 behaviour of allowing up/down to be held in menus
such as save/load.

Resolves #1644.
This commit is contained in:
lahm86 2024-11-02 11:45:26 +00:00 committed by Marcin Kurczewski
parent 9a3a2ddfb2
commit a6cf2ee02f
5 changed files with 43 additions and 0 deletions

View file

@ -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

View file

@ -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

View file

@ -1,5 +1,7 @@
#include "game/clock.h"
#include <libtrx/game/const.h>
#include <windows.h>
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;
}

View file

@ -1,3 +1,6 @@
#pragma once
#include <stdint.h>
double Clock_GetHighPrecisionCounter(void);
int32_t Clock_GetLogicalFrame(void);

View file

@ -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 <libtrx/game/input/backends/controller.h>
#include <libtrx/game/input/backends/keyboard.h>
#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;
}