Skip to content

Complete gamepad input ownership and virtual controls - #124

Open
H3nb wants to merge 157 commits into
alphafrom
feature/extend-gamepad-support
Open

H3nb wants to merge 157 commits into
alphafrom
feature/extend-gamepad-support

Conversation

@H3nb

@H3nb H3nb commented Sep 14, 2026

Copy link
Copy Markdown
Owner

Summary

This PR redesigns controller and virtual-control input around a strict HOST/GUEST boundary while preserving the existing universal MIDlet key mapping.

  • Keep all digital guest mapping in the existing KeyMapper / ProfileModel.keyMappings; keyboard, phone keys and gamepad buttons share one many-to-one mapping model.
  • Expose the intended logical targets only: 0–9, *, #, directions, FIRE, Soft Left/Right, GAME A–D, and M for the runtime MIDlet menu.
  • Do not reserve START/SELECT/L1/R1 as emulator shortcuts. They remain ordinary assignable physical inputs. Any additional physical key/button mapped to M opens the runtime menu through the same KeyMapper contract, while Android Back preserves its established Activity/Back behavior.
  • Separate HOST navigation (JL-Mod Plus UI, dialogs and runtime menu) from GUEST input (MIDlet runtime) so host modals cannot leak actions into the game behind them.
  • Add analog stick processing with calibration, deadzone, response shaping and hysteresis. Direction output supports:
    • 4-Way: Up/Down/Left/Right
    • 8-Way: cardinal + simultaneous diagonal pairs
    • Numeric: 7/2/9, 4/6, 1/8/3
  • Keep host analog navigation independent from per-MIDlet analog output mode.
  • Add grouped touch controls: one D-pad and one analog stick, each moved/resized as a whole with normalized persistent geometry and edit-grid snapping.
  • Preserve existing keyboard and virtual-keypad repeat behavior; controller timing does not replace legacy repeat semantics.
  • Harden lifecycle/ownership so digital input is not sacrificed to an analog neutral gate, unknown/vendor buttons remain available to KeyMapper, and held outputs are released safely across focus/target/device changes.
  • Cache controller capability signatures off the motion hot path and retain analog/controller configuration as an opaque-compatible profile subtree.

Virtual-control follow-up

  • Keep the existing layout templates and default unchanged; append D-pad Standard and Analog Standard.
  • Simplify the runtime Virtual Controls page to Edit Layout / Finish Editing, Layout Templates, and Show Or Hide Controls.
  • Include grouped D-pad/analog visibility in the existing show/hide flow instead of separate runtime toggles.
  • Move Analog Stick into Controls > Key Input and place Calibrate Controller beside the other key/input options.
  • Keep Analog Stick configurable without connected hardware; enable calibration only while a compatible controller is available.
  • Reduce analog-layout editing work on the touch/render hot path by rendering live edit geometry and rebuilding the gameplay analog-stick object only after the edit is committed.
  • Refine D-pad Standard and Analog Standard without changing the existing template family/default: use a smaller movement control, keep L/R as the upper-right pair and */0 directly below them, center F between those two rows, and align the D-pad/analog center horizontally with F.
  • Preserve the standard-template identity until the user customizes it, and regenerate its deterministic geometry when the control viewport changes size/orientation.
  • Make the standard-template geometry MIDlet-viewport aware instead of relying on fixed global percentages: wide layouts place movement in the real left gutter and the action cluster in the real right gutter when those regions fit; tall layouts prefer the free deck below the MIDlet; full-screen/tight layouts fall back to a compact lower overlay.
  • Reflow when either host bounds or MIDlet viewport bounds change, so screen scaling/aspect changes are handled in addition to portrait/landscape rotation.
  • Switching to any legacy built-in template disables grouped D-pad/analog controls and restores that template's historical control set; Custom continues to preserve explicitly customized grouped-control visibility.

Automated coverage

Relevant coverage includes ControllerLifecycleGateTest, ControllerInputRouterTest, KeyOwnershipLedgerTest, ControllerHostOwnershipLedgerTest, StickProcessorTest, VirtualDpadTest, VirtualAnalogStickTest, VirtualAnalogDirectionAdapterTest, LegacyVirtualKeypadRepeatTest, pointer tests, GameCanvasKeyStateTest, ControllerConfigTest, profile persistence tests, and StandardVirtualControlsLayoutTest.

StandardVirtualControlsLayoutTest covers the screenshot-like wide case (1820×864 with centered MIDlet side gutters), the portrait bottom-deck case, and full-screen fallback bounds.

Android instrumentation includes KeyMapperMappingRulesTest, runtime-menu virtual-control interaction coverage in RuntimeMenuComposeTest, and GamepadInputPreferencesComposeTest for offline analog selection, controller-gated calibration, and preservation of the legacy template order.

Android CI run 1486 completed successfully on head 08dbb56a2aefed8f07ae299fba387abd58f95132. Lint, JVM tests, APK assembly, CI diagnostics, and arm64 emulator debug APK upload all passed.

Hardware validation still needed

No physical gamepad is available in the development environment, so this PR does not claim universal hardware certification. A physical smoke matrix is still recommended before release: common buttons/D-pad, remapped M, all three analog direction modes, reconnect/focus loss, modal isolation, grouped touch-control persistence, template selection, portrait/landscape viewport-aware template reflow, calibration availability, and pointer modes.

Implementation details and the current test/hardware boundary are documented in docs/gamepad-implementation-status.md.

@H3nb H3nb changed the title Add complete gamepad support across the emulator Complete gamepad input ownership and virtual controls Sep 14, 2026
H3nb added 30 commits September 18, 2026 16:20
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