Skip to content

Android gamepad support - #804

Closed
rzer wants to merge 2 commits into
bvschaik:masterfrom
rzer:android-gamepad-support
Closed

rzer wants to merge 2 commits into
bvschaik:masterfrom
rzer:android-gamepad-support

Conversation

@rzer

@rzer rzer commented Nov 10, 2026

Copy link
Copy Markdown

Summary

Adds a full gamepad layout for Android, so the game is playable with a controller only.

Button layout (Android)

Input Action
Left stick Mouse cursor
Right stick Map scrolling, same as pushing the cursor against a screen edge
X / Y Left / right mouse button
A Empire map (trade routes)
B Problems overlay (T)
D-pad ← → ↓ ↑ Fire / damage / crime / water overlays (F / D / C / W)
RT Toggle game speed 100% ↔ 70%
Start Pause (P)
Back Open the save dialog prefilled with the current date and time; press again to save
LB / RB Select and press the previous / next key of 1 2 3 4 5 6 7 8 9 0 - =
LT Press the currently selected key again (defaults to 1)

Overlay and number buttons send real key presses through the hotkey system, so they respect custom hotkey mappings.
Speed changes and key selection show a short on-screen message in the city view.

Cursor

  • Analog movement: radial threshold (15%), quadratic response curve and an acceleration ramp (starts at 30% speed, full speed of 700 px/s after 700 ms). This allows both precise small movements and fast travel. All values are constants at the top of src/input/joystick.c.
  • Visible cursor: Android has no visible hardware cursor without a mouse, so the standard game cursor is drawn in software while the gamepad drives it. It is hidden again on touch or real mouse input.
  • Fix: SDL_WarpMouseInWindow is no longer called on Android. SDL cannot warp the pointer there, and instead emits a synthetic motion event with wrongly scaled coordinates, which pulled the cursor towards the top-left corner every frame.

Map scrolling

The right stick does not feed analog values into the arrow-key scrolling. Analog values on both axes produced unwanted diagonal movement, because the scroll code only knows 8 directions and the vertical speed is half the horizontal speed on the isometric map.

Instead, the stick now emulates the cursor pushed against the middle of one of the four screen edges, through a new scroll_set_virtual_edge(). Scrolling starts at 50% stick travel, stops below 40%, and only changes direction 15° past the sector border.

Other changes

  • Axis inputs bound to button-like actions (e.g. triggers) must now pass a digital threshold (DIGITAL_AXIS_THRESHOLD), so a light touch on a trigger no longer fires the action. This applies to all platforms.
  • New window_file_dialog_show_with_name() to open the file dialog with a prefilled name.

Vita, Switch and the generic (non-game-controller) joystick mappings are unchanged, except for the digital trigger threshold above.

Testing

  • Built assembleDebug with NDK 28.1 / SDL 2.32.8 / SDL_mixer 2.8.1.
  • Tested on a OnePlus 13s with a wired gamepad: cursor movement, clicks, overlays, speed toggle, empire map, quick save, quick keys and map scrolling in all four directions.

🤖 Generated with Claude Code

rzer and others added 2 commits November 10, 2026 13:26
- New Android-specific SDL game controller mapping:
  X/Y left/right click, A empire map, B problems overlay,
  D-pad fire/damage/crime/water overlays, RT toggles game speed 100%/70%,
  Start pauses, Back opens the save dialog prefilled with the current
  date and time (pressing Back again confirms), LB/RB select and press
  the previous/next key of 1-0,-,= and LT repeats the selected key
- Left stick moves the cursor with a radial threshold, response curve
  and acceleration ramp for precise small movements
- Right stick emulates the mouse cursor pushed against one of the four
  screen edges, with a start/release threshold and angular hysteresis
- Draw the standard game cursor in software on Android while the gamepad
  drives it; hide it again on touch or real mouse input
- Do not warp the mouse on Android: SDL emits a synthetic motion event
  with wrongly scaled coordinates that dragged the cursor to the top-left
- Require trigger axes bound to button-like actions to be pressed past
  a digital threshold
- Add scroll_set_virtual_edge() and window_file_dialog_show_with_name()

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rzer rzer closed this Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant