Skip to content

Commit

Permalink
tr2/input: allow holding up/down in menus
Browse files Browse the repository at this point in the history
This mimics the TR1 behaviour of allowing up/down to be held in menus
such as save/load.

Resolves LostArtefacts#1644.
  • Loading branch information
lahm86 authored and rr- committed Nov 2, 2024
1 parent 9a3a2dd commit a6cf2ee
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/tr2/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions docs/tr2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/tr2/game/clock.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "game/clock.h"

#include <libtrx/game/const.h>

#include <windows.h>

double Clock_GetHighPrecisionCounter(void)
Expand All @@ -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;
}
3 changes: 3 additions & 0 deletions src/tr2/game/clock.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#pragma once

#include <stdint.h>

double Clock_GetHighPrecisionCounter(void);
int32_t Clock_GetLogicalFrame(void);
29 changes: 29 additions & 0 deletions src/tr2/game/input.c
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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);
Expand All @@ -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;
}
Expand Down

0 comments on commit a6cf2ee

Please sign in to comment.