upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/shims/gameinput_script.h
diff options
context:
space:
mode:
authorJan Trencansky <jan.trencansky@protonmail.com>2026-11-26 16:55:04 -0500
committerJan Trencansky <jan.trencansky@protonmail.com>2026-11-26 16:55:04 -0500
commitdf92abca8ee2a8f9093efea7fcaa4dadc3ddaebc (patch)
tree97ef8f95544fe263049d3f7360823f16100de209 /runtime/shims/gameinput_script.h
parent49a0b69fcdb80db1f2a44ce7ca0ab8dfdec1e403 (diff)
parente5a7c8942678b323f655939c81f5d8855d20c248 (diff)
Merge main e5a7c8942 into shadow-aliased-guard (#1867)
One conflict, runtime/README.md: this branch rewrote the LEONIDA_SHADOW_ALIAS_MS row, main (#2163) added the LEONIDA_SHADOW_KEEP row after it. Both rows kept; the keep row's "aliased" now reads "aliased while they can't be guarded at every address", since aliased pages are no longer copied without a sign of a write. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/shims/gameinput_script.h')
-rw-r--r--runtime/shims/gameinput_script.h30
1 files changed, 20 insertions, 10 deletions
diff --git a/runtime/shims/gameinput_script.h b/runtime/shims/gameinput_script.h
index 759506750..5be554424 100644
--- a/runtime/shims/gameinput_script.h
+++ b/runtime/shims/gameinput_script.h
@@ -5,10 +5,13 @@
5// 5//
6// LEONIDA_INPUT_SCRIPT="a@70,a@85,start@120" 6// LEONIDA_INPUT_SCRIPT="a@70,a@85,start@120"
7// 7//
8// Each entry is button@seconds, the seconds counted from the shim's first update. A press is held for kHoldSeconds, 8// Each entry is button@seconds[:hold], the seconds counted from the shim's first update. A press is held for `hold`
9// then released. Buttons: a b x y start back lb rb up down left right; rsup and rsdown throw the right stick fully up 9// seconds (kHoldSeconds when the entry has none), then released: a longer hold reaches a title that reads its pad
10// or down for the same time (they replay the stick throws the press log writes). Spaces around an entry are allowed; 10// only every few seconds, as the retail title does at world-start frame rates. Buttons: a b x y start back lb rb
11// empty entries, unknown buttons and invalid times (negative, non-finite, trailing text) are counted as rejected. 11// up down left right; rsup and rsdown throw the right stick fully up or down for the same time (they replay the
12// stick throws the press log writes). Spaces around an entry are allowed; empty entries, unknown buttons, invalid
13// times (negative, non-finite, trailing text) and invalid holds (zero, negative, non-finite, more than
14// kMaxHoldSeconds) are counted as rejected.
12#pragma once 15#pragma once
13#include <algorithm> 16#include <algorithm>
14#include <cctype> 17#include <cctype>
@@ -24,6 +27,7 @@
24namespace rt::gameinput::script { 27namespace rt::gameinput::script {
25 28
26constexpr double kHoldSeconds = 0.3; 29constexpr double kHoldSeconds = 0.3;
30constexpr double kMaxHoldSeconds = 600; // a typo such as b@10:1100 should not hold B for the whole run
27 31
28// One scriptable button: its name in the script and the press log, its GameInput gamepad bit, and its SDL3 32// One scriptable button: its name in the script and the press log, its GameInput gamepad bit, and its SDL3
29// SDL_GamepadButton number, which the "scripted press of button <n>" line has always carried (tools/stage_timeline.py 33// SDL_GamepadButton number, which the "scripted press of button <n>" line has always carried (tools/stage_timeline.py
@@ -46,6 +50,7 @@ struct Press {
46 uint32_t button = 0; // a GameInput gamepad bit, or 0 for a stick throw 50 uint32_t button = 0; // a GameInput gamepad bit, or 0 for a stick throw
47 int stick = 0; // +1 rsup, -1 rsdown (GameInput's +Y is up) 51 int stick = 0; // +1 rsup, -1 rsdown (GameInput's +Y is up)
48 double at = 0; // seconds 52 double at = 0; // seconds
53 double hold = kHoldSeconds;
49}; 54};
50 55
51struct Script { 56struct Script {
@@ -72,17 +77,22 @@ inline Script parse(std::string text) {
72 const char* time = item.c_str() + sep + 1; 77 const char* time = item.c_str() + sep + 1;
73 char* tail; 78 char* tail;
74 const double seconds = std::strtod(time, &tail); 79 const double seconds = std::strtod(time, &tail);
75 if (tail == time || !std::isfinite(seconds) || seconds < 0 || 80 if (tail == time || !std::isfinite(seconds) || seconds < 0) continue;
76 item.find_first_not_of(whitespace, static_cast<size_t>(tail - item.c_str())) != std::string::npos) 81 double hold = kHoldSeconds;
77 continue; 82 if (*tail == ':') {
83 const char* hold_text = tail + 1;
84 hold = std::strtod(hold_text, &tail);
85 if (tail == hold_text || !std::isfinite(hold) || hold <= 0 || hold > kMaxHoldSeconds) continue;
86 }
87 if (item.find_first_not_of(whitespace, static_cast<size_t>(tail - item.c_str())) != std::string::npos) continue;
78 const auto is = [&](const char* name) { return item.compare(first, sep - first, name) == 0; }; 88 const auto is = [&](const char* name) { return item.compare(first, sep - first, name) == 0; };
79 if (is("rsup") || is("rsdown")) { 89 if (is("rsup") || is("rsdown")) {
80 out.presses.push_back({0, is("rsup") ? 1 : -1, seconds}); 90 out.presses.push_back({0, is("rsup") ? 1 : -1, seconds, hold});
81 continue; 91 continue;
82 } 92 }
83 for (const Button& b : kButtons) { 93 for (const Button& b : kButtons) {
84 if (is(b.name)) { 94 if (is(b.name)) {
85 out.presses.push_back({b.bit, 0, seconds}); 95 out.presses.push_back({b.bit, 0, seconds, hold});
86 out.named |= b.bit; 96 out.named |= b.bit;
87 break; 97 break;
88 } 98 }
@@ -102,7 +112,7 @@ struct Held {
102inline Held held_at(const Script& script, double seconds) { 112inline Held held_at(const Script& script, double seconds) {
103 Held h; 113 Held h;
104 for (const Press& p : script.presses) { 114 for (const Press& p : script.presses) {
105 if (seconds < p.at || seconds >= p.at + kHoldSeconds) continue; 115 if (seconds < p.at || seconds >= p.at + p.hold) continue;
106 if (p.stick) h.stick = p.stick; 116 if (p.stick) h.stick = p.stick;
107 else h.buttons |= p.button; 117 else h.buttons |= p.button;
108 } 118 }