upleb.uk

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

summaryrefslogtreecommitdiff
path: root/runtime/shims/gameinput.cpp
diff options
context:
space:
mode:
authorMoriz82 <72836413+Moriz82@users.noreply.github.com>2026-11-24 11:42:12 -0600
committerMoriz82 <72836413+Moriz82@users.noreply.github.com>2026-11-24 11:42:12 -0600
commit273b3bdf9d6e736442ad584ad464df6e86ee928b (patch)
tree3886a0af7c74ffa7d9415d662d8dc0fb708f1c08 /runtime/shims/gameinput.cpp
parentece4ba5b31ebc6f345c8e29eae1261f2f780057a (diff)
[integration] Linux/Proton and native Windows: boot through the story load (RT-PROTON-STORY-LOAD)
One squashed commit of a fork that was developed on a Linux/Proton machine and tested on two native Windows machines. On all of them the retail 1.0.2.1 package now launches, shows its launch movie, first-run pages and landing prompt, runs the story load to its end with the loading slideshow drawing its artwork, and enters the world phase. A first world frame is not verified yet. docs/linux_proton.md has the setup, a healthy boot's timeline, the machines and where it stops. Runtime: frames in the title's own window; DirectStorage pinned reads, page-list scatter/gather, BCPack and unshuffle with a locally generated predictor file; pooled, device-local and deferred image backing for streamed and placed textures; enhanced barriers into LAYOUT_UNDEFINED; a bindless table that degrades instead of refusing a submission; a descriptor hash finalizer (off until a library carries it); directly indexed heap offsets for compute dispatches and VS/PS/GS draws; title buffer windows outside a fragmented arena; opt-in device-local copies of streamed buffer views; write-fault retries under the tracker lock, shared trackers and write-watched title memory for native Windows; device-loss, compute-input and memory probes. Translator: loop bounds at structured exits, the eight FidelityFX programs that use a packed-dot form the disassembler skips, buffer bounds modes per view kind, a compaction option, the hash finalizer option. Tools and scripts: Linux boot scripts (Wine/Proton, no network), a Windows boot script, the paired compute translation script. No game data. AI-assisted (Claude Code and Codex agents), reviewed and booted by people on the machines named in docs/linux_proton.md. Co-authored-by: Plaaasma <47513553+Plaaasma@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Diffstat (limited to 'runtime/shims/gameinput.cpp')
-rw-r--r--runtime/shims/gameinput.cpp106
1 files changed, 101 insertions, 5 deletions
diff --git a/runtime/shims/gameinput.cpp b/runtime/shims/gameinput.cpp
index 402179cde..4dd0e34a6 100644
--- a/runtime/shims/gameinput.cpp
+++ b/runtime/shims/gameinput.cpp
@@ -132,10 +132,14 @@ const rt::gameinput::HapticApi& haptics() { return *g_haptic_api.load(); }
132// ---- configuration ---------------------------------------------------------------------------------------------- 132// ---- configuration ----------------------------------------------------------------------------------------------
133 133
134std::string env(const char* name) { 134std::string env(const char* name) {
135 char buf[64]; 135 // Any length: an input script (LEONIDA_INPUT_SCRIPT) is easily longer than a fixed buffer, and a value that did
136 const DWORD n = GetEnvironmentVariableA(name, buf, sizeof buf); 136 // not fit used to read as unset.
137 if (n == 0 || n >= sizeof buf) return {}; 137 const DWORD need = GetEnvironmentVariableA(name, nullptr, 0); // with the terminator
138 std::string s(buf, n); 138 if (need == 0) return {};
139 std::string s(need, '\0');
140 const DWORD n = GetEnvironmentVariableA(name, s.data(), need);
141 if (n == 0 || n >= need) return {};
142 s.resize(n);
139 for (auto& c : s) c = static_cast<char>(std::tolower(static_cast<unsigned char>(c))); 143 for (auto& c : s) c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
140 return s; 144 return s;
141} 145}
@@ -1890,11 +1894,76 @@ void update_keyboard_pad() {
1890 } 1894 }
1891 clip_cursor(active && g_raw_ready && g_cursor_pos.load() == system_cursor_pos && foreground_is_ours()); 1895 clip_cursor(active && g_raw_ready && g_cursor_pos.load() == system_cursor_pos && foreground_is_ours());
1892 for (const auto& b : kKeyBindings) SDL_SetJoystickVirtualButton(g_keyboard.js, b.sdl_button, down[b.sdl_button]); 1896 for (const auto& b : kKeyBindings) SDL_SetJoystickVirtualButton(g_keyboard.js, b.sdl_button, down[b.sdl_button]);
1897 // LEONIDA_INPUT_SCRIPT="a@70,a@85,start@120" (with LEONIDA_KEYBOARD_PAD=always): timed presses on the keyboard
1898 // pad, in seconds since the pad's first update, each held 300 ms. For unattended boots: the title's first prompt
1899 // waits for a button with no timeout (docs/re/notes/firstframe.md, step 5). Buttons: a b x y start back lb rb
1900 // up down left right. The rsup and rsdown entries replay the right-stick throws logged below.
1901 int right_y = g_keyboard.right_y;
1902 struct ScriptedPress {
1903 SDL_GamepadButton button;
1904 double at;
1905 int right_y = 0;
1906 };
1907 static const std::vector<ScriptedPress> script = [] {
1908 std::vector<ScriptedPress> out;
1909 static const std::pair<const char*, SDL_GamepadButton> names[] = {
1910 {"a", SDL_GAMEPAD_BUTTON_SOUTH}, {"b", SDL_GAMEPAD_BUTTON_EAST},
1911 {"x", SDL_GAMEPAD_BUTTON_WEST}, {"y", SDL_GAMEPAD_BUTTON_NORTH},
1912 {"start", SDL_GAMEPAD_BUTTON_START}, {"back", SDL_GAMEPAD_BUTTON_BACK},
1913 {"lb", SDL_GAMEPAD_BUTTON_LEFT_SHOULDER}, {"rb", SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER},
1914 {"up", SDL_GAMEPAD_BUTTON_DPAD_UP}, {"down", SDL_GAMEPAD_BUTTON_DPAD_DOWN},
1915 {"left", SDL_GAMEPAD_BUTTON_DPAD_LEFT}, {"right", SDL_GAMEPAD_BUTTON_DPAD_RIGHT}};
1916 const std::string text = env("LEONIDA_INPUT_SCRIPT");
1917 for (size_t at = 0; at < text.size();) {
1918 const size_t end = std::min(text.find(',', at), text.size());
1919 const std::string item = text.substr(at, end - at);
1920 const size_t sep = item.find('@');
1921 if (sep != std::string::npos) {
1922 const double when = std::atof(item.c_str() + sep + 1);
1923 const auto name = item.substr(0, sep);
1924 if (name == "rsup" || name == "rsdown")
1925 out.push_back({SDL_GAMEPAD_BUTTON_INVALID, when, name == "rsup" ? -kStickFull : kStickFull});
1926 else
1927 for (const auto& n : names)
1928 if (name == n.first) out.push_back({n.second, when});
1929 }
1930 at = end + 1;
1931 }
1932 if (!out.empty())
1933 std::fprintf(stderr, "[rt] gameinput: LEONIDA_INPUT_SCRIPT: %zu scripted press(es)\n", out.size());
1934 return out;
1935 }();
1936 if (!script.empty()) {
1937 static const ULONGLONG origin = GetTickCount64();
1938 const double now = (GetTickCount64() - origin) / 1000.0;
1939 // One decision per button: a later entry for the same button must not release what an earlier entry holds
1940 // (it did: with several entries only the last one ever reached the title).
1941 bool scripted[SDL_GAMEPAD_BUTTON_COUNT] = {};
1942 bool named[SDL_GAMEPAD_BUTTON_COUNT] = {};
1943 for (const auto& press : script) {
1944 const bool held = now >= press.at && now < press.at + 0.3;
1945 if (press.right_y) {
1946 if (held) right_y = press.right_y;
1947 } else {
1948 named[press.button] = true;
1949 scripted[press.button] |= held;
1950 }
1951 }
1952 for (int button = 0; button < SDL_GAMEPAD_BUTTON_COUNT; ++button) {
1953 if (!named[button]) continue;
1954 SDL_SetJoystickVirtualButton(g_keyboard.js, static_cast<SDL_GamepadButton>(button),
1955 scripted[button] || down[button]);
1956 static bool was[SDL_GAMEPAD_BUTTON_COUNT] = {};
1957 if (scripted[button] && !was[button])
1958 std::fprintf(stderr, "[rt] gameinput: scripted press of button %d at %.1f s\n", button, now);
1959 was[button] = scripted[button];
1960 }
1961 }
1893 const int reach = lx && ly ? kStickDiagonal : kStickFull; 1962 const int reach = lx && ly ? kStickDiagonal : kStickFull;
1894 SDL_SetJoystickVirtualAxis(g_keyboard.js, SDL_GAMEPAD_AXIS_LEFTX, static_cast<Sint16>(lx * reach)); 1963 SDL_SetJoystickVirtualAxis(g_keyboard.js, SDL_GAMEPAD_AXIS_LEFTX, static_cast<Sint16>(lx * reach));
1895 SDL_SetJoystickVirtualAxis(g_keyboard.js, SDL_GAMEPAD_AXIS_LEFTY, static_cast<Sint16>(ly * reach)); 1964 SDL_SetJoystickVirtualAxis(g_keyboard.js, SDL_GAMEPAD_AXIS_LEFTY, static_cast<Sint16>(ly * reach));
1896 SDL_SetJoystickVirtualAxis(g_keyboard.js, SDL_GAMEPAD_AXIS_RIGHTX, static_cast<Sint16>(g_keyboard.right_x)); 1965 SDL_SetJoystickVirtualAxis(g_keyboard.js, SDL_GAMEPAD_AXIS_RIGHTX, static_cast<Sint16>(g_keyboard.right_x));
1897 SDL_SetJoystickVirtualAxis(g_keyboard.js, SDL_GAMEPAD_AXIS_RIGHTY, static_cast<Sint16>(g_keyboard.right_y)); 1966 SDL_SetJoystickVirtualAxis(g_keyboard.js, SDL_GAMEPAD_AXIS_RIGHTY, static_cast<Sint16>(right_y));
1898 // SDL maps a full-range virtual axis to the trigger, so -32768 is released, 0 half pulled, 32767 full. 1967 // SDL maps a full-range virtual axis to the trigger, so -32768 is released, 0 half pulled, 32767 full.
1899 SDL_SetJoystickVirtualAxis(g_keyboard.js, SDL_GAMEPAD_AXIS_LEFT_TRIGGER, aim ? 32767 : -32768); 1968 SDL_SetJoystickVirtualAxis(g_keyboard.js, SDL_GAMEPAD_AXIS_LEFT_TRIGGER, aim ? 32767 : -32768);
1900 SDL_SetJoystickVirtualAxis(g_keyboard.js, SDL_GAMEPAD_AXIS_RIGHT_TRIGGER, fire ? 32767 : -32768); 1969 SDL_SetJoystickVirtualAxis(g_keyboard.js, SDL_GAMEPAD_AXIS_RIGHT_TRIGGER, fire ? 32767 : -32768);
@@ -1965,6 +2034,33 @@ void poll_once() {
1965 read_raw(d, &snap); 2034 read_raw(d, &snap);
1966 const bool guide_changed = d->last_snap.guide != snap.guide; 2035 const bool guide_changed = d->last_snap.guide != snap.guide;
1967 const bool changed = !(d->last_snap == snap); 2036 const bool changed = !(d->last_snap == snap);
2037 // Every press is logged in LEONIDA_INPUT_SCRIPT's own form (name@seconds), so a session played by hand can
2038 // be replayed unattended: join the logged items with commas. The right stick's vertical throws (what scrolls
2039 // a page) are logged as rsup/rsdown. LEONIDA_INPUT_LOG=0 turns the lines off.
2040 {
2041 static const bool log_presses = env("LEONIDA_INPUT_LOG") != "0";
2042 static const ULONGLONG log_origin = GetTickCount64();
2043 if (log_presses) {
2044 static const std::pair<uint32_t, const char*> kNames[] = {
2045 {GameInputGamepadA, "a"}, {GameInputGamepadB, "b"},
2046 {GameInputGamepadX, "x"}, {GameInputGamepadY, "y"},
2047 {GameInputGamepadMenu, "start"}, {GameInputGamepadView, "back"},
2048 {GameInputGamepadLeftShoulder, "lb"}, {GameInputGamepadRightShoulder, "rb"},
2049 {GameInputGamepadDPadUp, "up"}, {GameInputGamepadDPadDown, "down"},
2050 {GameInputGamepadDPadLeft, "left"}, {GameInputGamepadDPadRight, "right"}};
2051 const double at = (GetTickCount64() - log_origin) / 1000.0;
2052 const uint32_t pressed = snap.gamepad.buttons & ~d->last_snap.gamepad.buttons;
2053 for (const auto& n : kNames)
2054 if (pressed & n.first)
2055 std::fprintf(stderr, "[rt] gameinput: press %s@%.1f (%s)\n", n.second, at, d->name.c_str());
2056 const auto throw_of = [](float y) { return y > 0.6f ? 1 : y < -0.6f ? -1 : 0; };
2057 const int was = throw_of(d->last_snap.gamepad.rightThumbstickY);
2058 const int is = throw_of(snap.gamepad.rightThumbstickY);
2059 if (is != was && is != 0)
2060 std::fprintf(stderr, "[rt] gameinput: press %s@%.1f (%s)\n", is > 0 ? "rsup" : "rsdown", at,
2061 d->name.c_str());
2062 }
2063 }
1968 d->last_snap = snap; 2064 d->last_snap = snap;
1969 // A newly opened pad's first sample here is its baseline (active_input.h), so connecting a pad with a button 2065 // A newly opened pad's first sample here is its baseline (active_input.h), so connecting a pad with a button
1970 // held changes nothing. 2066 // held changes nothing.