Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/gameinput.md
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ line is logged when it takes effect); tracking goes on underneath, so clearing i
| `LEONIDA_PROMPTS_SWITCH_MS` | `300` | shortest time between two changes of the active input family, 0..2000 ms |
| `LEONIDA_GAMEINPUT_THREAD` | `1` | `0` stops the background poll thread; only `rt::gameinput::poll()` then reads the pads (tests) |
| `LEONIDA_KEYBOARD_PAD` | `off` | `1` adds the [keyboard pad](#keyboard-pad), read while this process has focus; `always` reads keys whatever has focus |
| `LEONIDA_INPUT_SCRIPT` | unset | Comma-separated `button@seconds` entries, e.g. `a@2,a@4,start@6`. With SDL3 they drive the keyboard pad, which has to be enabled; without SDL3 they drive [one scripted pad](#scripted-input-without-sdl3), the only device. The first pad update (without SDL3, the first `GameInputCreate`) reads the script once at startup and starts the clock. `reload_config()` does not reread it. Each press lasts 300 ms, or `hold` seconds when the entry is `button@seconds:hold` (more than 0, at most 600). With SDL3 a press then stays down until the title has read the pads six times since it began, but never past 5 s from its start (or its hold, if longer). A title reads its pad once a frame, so at a few seconds a frame a 300 ms press can fall between two reads and never arrive: on the retail title's "Couldn't autosave" prompt, three 300 ms `b` presses did nothing, while 120 presses 0.5 s apart got through; one `b@1100:3` replaces them. Buttons are `a b x y start back lb rb up down left right`. Spaces around entries are allowed. Empty entries, unknown buttons, invalid times (including negative or non-finite values) and invalid holds (0 or less, more than 600, not a number) are counted and ignored. |
| `LEONIDA_INPUT_SCRIPT` | unset | Comma-separated `button@seconds` entries, e.g. `a@2,a@4,start@6`. With SDL3 they drive the keyboard pad, which has to be enabled (`LEONIDA_KEYBOARD_PAD=always` for an unattended run): with the pad off the script is not read, and the shim logs once `[rt] gameinput: LEONIDA_INPUT_SCRIPT is set but the keyboard pad is off, ...` so the cause is in the log; without SDL3 they drive [one scripted pad](#scripted-input-without-sdl3), the only device. The first pad update (without SDL3, the first `GameInputCreate`) reads the script once at startup and starts the clock. `reload_config()` does not reread it. Each press lasts 300 ms, or `hold` seconds when the entry is `button@seconds:hold` (more than 0, at most 600). With SDL3 a press then stays down until the title has read the pads six times since it began, but never past 5 s from its start (or its hold, if longer). A title reads its pad once a frame, so at a few seconds a frame a 300 ms press can fall between two reads and never arrive: on the retail title's "Couldn't autosave" prompt, three 300 ms `b` presses did nothing, while 120 presses 0.5 s apart got through; one `b@1100:3` replaces them. Buttons are `a b x y start back lb rb up down left right`. Spaces around entries are allowed. Empty entries, unknown buttons, invalid times (including negative or non-finite values) and invalid holds (0 or less, more than 600, not a number) are counted and ignored. |
| `LEONIDA_MOUSE_SENSITIVITY` | `1` | scales how far the mouse moves the keyboard pad's right stick, 0.1..10 |

SDL's own hints (`SDL_JOYSTICK_*`, see SDL's `SDL_hints.h`) also apply, for example `SDL_JOYSTICK_HIDAPI_PS5=0` to
Expand Down
7 changes: 7 additions & 0 deletions runtime/shims/gameinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,13 @@ rt::gameinput::Config read_config() {
else if (!k.empty() && k != "0" && k != "off")
std::fprintf(stderr, "[rt] gameinput: LEONIDA_KEYBOARD_PAD=%s unknown (1, always or off), keyboard pad off\n",
k.c_str());
// A script with no pad to drive would otherwise do nothing and say nothing (gameinput_script.h, pad_off_note).
// Once a process: reload_config reads the configuration again and the answer does not need repeating.
if (const char* note = rt::gameinput::script::pad_off_note(
env("LEONIDA_INPUT_SCRIPT"), c.keyboard_pad != rt::gameinput::KeyboardPadMode::Off)) {
static std::atomic<bool> said{false};
if (!said.exchange(true)) std::fprintf(stderr, "[rt] gameinput: %s\n", note);
}
using leonida::InputFamily;
const std::string p = env("LEONIDA_PROMPTS");
if (p == "xbox") c.prompts = InputFamily::Xbox;
Expand Down
14 changes: 14 additions & 0 deletions runtime/shims/gameinput_script.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,20 @@ inline uint32_t ui_navigation(const gi::GameInputGamepadState& g) {
return u;
}

// With SDL3 the script drives the keyboard pad, and the pad's update is also where the script is read. A script with
// the pad off is therefore never parsed and no press ever happens: the title waits at its first prompt and the log has
// nothing about the script. The SDL3 shim prints this line once for that case. Null when there is nothing to say: no
// script (unset, or only white space), or a pad for it to drive.
inline const char* pad_off_note(const std::string& script_text, bool keyboard_pad_on) {
if (keyboard_pad_on) return nullptr;
const bool has_script = std::any_of(script_text.begin(), script_text.end(),
[](unsigned char c) { return !std::isspace(c); });
if (!has_script) return nullptr;
return "LEONIDA_INPUT_SCRIPT is set but the keyboard pad is off, so the script is not read and no scripted "
"press will happen: with SDL3 the script drives the keyboard pad (set LEONIDA_KEYBOARD_PAD=always for an "
"unattended run, or 1)";
}

// An environment variable in lower case, of any length (a script is easily longer than a fixed buffer, and a value
// that did not fit used to read as unset). Empty when unset.
inline std::string env_lower(const char* name) {
Expand Down
17 changes: 17 additions & 0 deletions runtime/test/gameinput_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include "gameinput.h"
#include "gameinput_abi.h"
#include "gameinput_script.h"
#include "shims.h"

using namespace gi;
Expand Down Expand Up @@ -1693,6 +1694,21 @@ void test_haptic_motors(IGameInput* input) {

} // namespace

// INPUT-SCRIPT-PAD-OFF-NOTE: a script with the keyboard pad off is never read, so the shim has to say so. The decision
// is a pure function; the shim prints its text once at configuration time.
void test_script_pad_off_note() {
namespace script = rt::gameinput::script;
const char* note = script::pad_off_note("a@40,a@50", false);
check(note != nullptr, "pad-off note: a script with the keyboard pad off is reported");
check(note && std::strstr(note, "LEONIDA_INPUT_SCRIPT") && std::strstr(note, "LEONIDA_KEYBOARD_PAD=always"),
"pad-off note: it names the script variable and the setting that makes it run");
check(script::pad_off_note("a@40,a@50", true) == nullptr, "pad-off note: silent when the pad is on");
check(script::pad_off_note("", false) == nullptr, "pad-off note: silent without a script");
check(script::pad_off_note(" \t ", false) == nullptr, "pad-off note: a script of white space is no script");
check(script::pad_off_note("unknown@0", false) != nullptr,
"pad-off note: a script whose entries would all be rejected is still reported (it is not parsed here)");
}

int main(int argc, char** argv) {
// Only virtual pads: no real controller on the test machine may show up.
for (const char* hint : {SDL_HINT_JOYSTICK_HIDAPI, SDL_HINT_JOYSTICK_RAWINPUT, SDL_HINT_JOYSTICK_WGI,
Expand All @@ -1705,6 +1721,7 @@ int main(int argc, char** argv) {
set_env("LEONIDA_DS_LIGHTBAR", nullptr);
set_env("LEONIDA_RUMBLE", nullptr);
test_add_ref_if_live();
test_script_pad_off_note();

auto create = reinterpret_cast<GameInputCreateFn>(rt::shims::find("gameinput.dll", "GameInputCreate"));
check(create != nullptr, "gameinput.dll!GameInputCreate is registered");
Expand Down
Loading