mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-18 09:09:56 -04:00
Swing the shake key's stick by the game's updates instead of the clock, two updates a side at any frame rate.
shake_stick picked the side from the time since the press, 67 ms a side (two frames at the game's 30 fps), so above 30 fps each side lasted more of the game's updates: 8 at 120 fps and 16 at 240, slower swings than the game reads at its own rate. The side now comes from the game's present count, which frame_rate.c already kept for the flight recorder and now gives through frame_step_presents, two presents a side. The press still swings for 800 ms of the clock and a hold keeps it going, as before; while no present comes (a load) the stick keeps its side. Not reproduced before the change (read from the code). The new tests/shake_key_check.py builds shake_stick from input.c and passes (it fails 118 times on the old code); the runtime compile check and the -Wall comparison of input.c and frame_rate.c show no new warnings. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -425,7 +425,10 @@ static double ocarina_step_s(void) {
|
||||
return base * speed / 60.0;
|
||||
}
|
||||
|
||||
static _Atomic uint64_t guest_presents; // frame_step_present calls so far (frame_step_flight)
|
||||
static _Atomic uint64_t guest_presents; // frame_step_present calls so far (frame_step_flight, frame_step_presents)
|
||||
|
||||
// The game's presents so far, one per update of the game at any frame rate (input.c shake_stick counts its updates).
|
||||
uint64_t frame_step_presents(void) { return atomic_load_explicit(&guest_presents, memory_order_relaxed); }
|
||||
|
||||
// The flight recorder's view of the step at a host present (flight.c, render thread): the newest step the patch page
|
||||
// holds in 60 Hz frames per update (set ostep; -1 without), the game's own step from its time manager in 60 Hz frames
|
||||
|
||||
@@ -469,6 +469,7 @@ void frame_rate_sound_gate_host(Cpu *c); // the sound job at wh
|
||||
void frame_rate_sound_step_host(Cpu *c); // the step the sound job hands on (set osound, page +0xf00)
|
||||
float frame_step_frames(void); // the 60 Hz frames the game steps per update (set ostep), else 1
|
||||
void frame_step_flight(float *page, float *game, uint64_t *presents); // flight.c: the step at a host present
|
||||
uint64_t frame_step_presents(void); // the game's presents so far: one per update of the game
|
||||
// rtss_limit.c: RivaTuner Statistics Server takes the frame limit where it runs
|
||||
void rtss_limit_want(int64_t mhz); // the pacer's limit in millihertz: >0, 0 none; or why RTSS is
|
||||
// kept out (rtss_decide.h RTSS_OUT_*)
|
||||
|
||||
@@ -1032,21 +1032,23 @@ static void pick(int32_t *x, int32_t *y, int32_t kx, int32_t ky) {
|
||||
}
|
||||
|
||||
// The shake key (B_SHAKE): the game detaches a part fused to the held object when the right stick swings left and
|
||||
// right a few times. A press swings it for SHAKE_NS, holding keeps it swinging; each side lasts SHAKE_SIDE_NS, two
|
||||
// frames at the game's 30 fps, so every side is read even at 20 fps. Returns the stick x, 0 while not shaking.
|
||||
// right a few times. A press swings it for SHAKE_NS, holding keeps it swinging. Each side lasts SHAKE_SIDE_STEPS
|
||||
// updates of the game, counted by its presents (frame_rate.c frame_step_presents), as two frames at the game's 30 fps
|
||||
// did, so the game sees the same swings at any frame rate. A side of a fixed time (two 30 fps frames, 67 ms) lasted 8
|
||||
// updates at 120 fps and 16 at 240. Returns the stick x, 0 while not shaking.
|
||||
// Under lock.
|
||||
#define SHAKE_NS 800000000ull
|
||||
#define SHAKE_SIDE_NS 66666667ull
|
||||
#define SHAKE_SIDE_STEPS 2
|
||||
static int32_t shake_stick(int held) {
|
||||
static int was;
|
||||
static uint64_t from, until;
|
||||
uint64_t now = plat_now_ns();
|
||||
if (held && !was && now >= until) from = now;
|
||||
uint64_t now = plat_now_ns(), steps = frame_step_presents();
|
||||
if (held && !was && now >= until) from = steps;
|
||||
if (held && !was) until = now + SHAKE_NS;
|
||||
if (held && until < now) until = now;
|
||||
was = held;
|
||||
if (now >= until && !held) return 0;
|
||||
return (now - from) / SHAKE_SIDE_NS % 2 ? STICK_MAX : -STICK_MAX;
|
||||
return (steps - from) / SHAKE_SIDE_STEPS % 2 ? STICK_MAX : -STICK_MAX;
|
||||
}
|
||||
|
||||
// Under lock and inside sdl_enter (the gamepads' state is up to date), state 1: the open gamepad's inputs by position
|
||||
|
||||
Reference in New Issue
Block a user