Skip to content

Add nudging support#560

Merged
freezy merged 25 commits into
masterfrom
feature/nudge
Jul 5, 2026
Merged

Add nudging support#560
freezy merged 25 commits into
masterfrom
feature/nudge

Conversation

@freezy

@freezy freezy commented Jul 4, 2026

Copy link
Copy Markdown
Owner

This PR adds the VPE nudge stack: keyboard cabinet motion, plumb tilt simulation, native analog cabinet sensors, visual cabinet movement, and editor tooling for KL25Z/Pinscape calibration.

  • Adds cabinet nudge physics primitives and keyboard nudge models.
  • Adds plumb tilt simulation driven by cabinet acceleration.
  • Adds native sensor mapping support for position, velocity, and acceleration channels.
  • Adds KL25Z/Pinscape-oriented calibration tooling in the SimulationThreadComponent inspector.
  • Adds live native input/device graphing, calibrated mapping graphing, and mount orientation controls.
  • Adds visual cabinet nudge offset for render-only table motion.
  • Exposes nudge telemetry for player/settings/debug UI.
  • Wires native input axis events through the simulation thread and physics engine.
  • Defaults imported/direct-play tables toward the simulation thread path.
  • Adds focused tests for sensor mapping, cabinet physics, plumb tilt, keyboard rebound damping, and mount transforms.
vpe-nudge-3m.mp4

freezy added 15 commits July 4, 2026 23:30
- Push keyboard nudge and plumb settings into the physics env at Start:
  config applied between Awake and Start (the player app does this on
  table load) previously only reached the component fields and was lost.
- Resolve device ids for axis events from an immutable snapshot owned by
  NativeInputManager, rebuilt when polling starts; the input callback no
  longer re-enumerates devices or mutates shared dictionaries off the
  main thread.
- Fix default-keyboard-nudge suppression on the Unity input path: the
  nudge counter is now snapshotted before each input-system update and
  evaluated after all callbacks ran, instead of comparing against a
  stale index from the previous key press.
- Defer the suppression check behind the queued switch dispatch for
  main-thread gamelogic engines, so a graph-driven Nudge() suppresses
  the default nudge instead of doubling it.
- Apply sensor strength once in direct cabinet mode (the reference
  multiplies it twice, scaling with strength squared — upstream bug).
- Compact gain-calibrator samples in place when the buffer fills instead
  of splitting the segment, keeping the rest-to-rest assumption intact
  for motion longer than 255 ms.
- Preserve plumb state on reconfiguration and emit a release edge when
  disabling while tilted, so the tilt switch cannot stay stuck closed.
- Route plumb tilt through the main thread in simulation-thread mode so
  switch status and key wires update like in single-threaded mode.
- Decode native device names as UTF-8, parse sensor mappings with
  semicolons in the device id, always clamp to the mapping limit, and
  cap the pending nudge queues with drop warnings.
- Cover strength linearity, single-impulse intent, calibrator compaction
  and mapping round-trips in tests.
@freezy freezy self-assigned this Jul 4, 2026
@greptile-apps

greptile-apps Bot commented Jul 4, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds cabinet nudging support across input, physics, rendering, and editor tooling. The main changes are:

  • New keyboard, analog sensor, cabinet motion, and plumb tilt physics paths.
  • Native input mapping and calibration support for cabinet sensors.
  • Visual cabinet nudge offsets for render-only table motion.
  • Tilt bob routing and import defaults for newly loaded tables.
  • Editor graphs and controls for device mapping, calibration, and mount orientation.
  • Tests covering sensor mapping, cabinet physics, plumb tilt, and mount transforms.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.

Important Files Changed

Filename Overview
VisualPinball.Unity/VisualPinball.Unity/Physics/Cabinet/NudgeState.cs Adds cabinet nudge source selection with keyboard priority and timestamp-based analog sensor takeover.
VisualPinball.Unity/VisualPinball.Unity/Game/NudgeSystem.cs Adds the bridge from native analog input events to physics-thread nudge samples.
VisualPinball.Unity/VisualPinball.Unity/Input/SensorMapping.cs Adds serializable raw-axis mapping with center calibration, dead zone, limit, and scale handling.
VisualPinball.Unity/VisualPinball.Unity.Editor/Simulation/SimulationThreadComponentInspector.cs Adds Play Mode sensor mapping, calibration controls, live input graphs, and mount transform previews.
VisualPinball.Unity/VisualPinball.Unity/Game/WirePlayer.cs Updates wire input dispatch so Unity InputSystem callbacks do not run while native polling owns the input stream.

Reviews (4): Last reviewed commit: "editor: Don't pre-clamp raw value in map..." | Re-trigger Greptile

Comment thread VisualPinball.Unity/VisualPinball.Unity/Game/PhysicsEngine.cs
Comment thread VisualPinball.Unity/VisualPinball.Unity/Input/SensorMapping.cs
freezy added 3 commits July 4, 2026 23:48
The native input plugin now reports device arrivals/removals with a
DevicesChanged event. Handle it before the window-focus gate (the cache
must not go stale while unfocused), rebuild the device-id snapshot and
expose a DevicesChanged event for UI consumers.
@freezy

freezy commented Jul 4, 2026

Copy link
Copy Markdown
Owner Author

Addressed the outside-diff WirePlayer note by applying the same native-polling guard used by SwitchPlayer, so Unity InputSystem wire callbacks are ignored while native polling owns input.

freezy added 5 commits July 5, 2026 13:12
Add keyboard nudge, plumb tilt and visual nudge property fields to
the PhysicsEngine inspector, reconfiguring the engine live on change.
Also surface the table's NudgeTime property in the table inspector.
Introduce GetNudgeSettings/ConfigureNudge on PhysicsEngine and
GetCabinetInputSettings/ApplyCabinetInputSettings on
SimulationThreadComponent so nudge and native-input configuration
flow through the shared CabinetInputSettings/CabinetNudgeSettings
objects instead of many individual Configure* calls.

Unpacking now builds a CabinetNudgeSettings and applies it in one
call, and sensor conversion delegates to CabinetNudgeSensorSettings.
Native input polling can now be reconciled while Play Mode is
already running.
Introduce a TiltBobComponent that acts as the table author's routing
point for the tilt switch, owning switch dispatch. The player's
cabinet settings decide whether the signal originates from the
physics plumb-bob simulation or a real mapped cabinet switch.

Move plumb-tilt event dispatch out of PhysicsEngine and route it
through the tilt-bob component via the simulation thread. Plumb
settings on PhysicsEngine are now hidden and default off; older
packages still deserialize them but new packages route tilt through
the component plus player cabinet settings.

Add shared CabinetInputSettings/CabinetNudgeSettings objects (plus a
CabinetInputSettingsAsset wrapper) so the same serializable shape can
drive runtime config, player JSON, and editor presets, replacing the
per-component nudge configuration path.

Auto-add the tilt-bob component on VPX import and drop the plumb
fields from the physics engine inspector.
Move plumb-bob damping and tilt-threshold tuning off the shared
physics/nudge settings and onto TiltBobComponent, where the values
are authored, range-clamped, and normalized via OnValidate.

Persist the tuning through a new TiltBobPackable so it survives
pack/unpack, and keep the legacy CabinetPlumbSettings fields only
for JSON compatibility.
Rename the TiltBobMode.Mapped enum value and its related APIs
(UsesMappedInput, DispatchMappedTiltInputToMainThread) to Physical
to better describe a real cabinet plumb bob wired into the
controller.

Add a TiltBobInspector exposing plumb damping and threshold angle,
and document nudging and tilt bobs in the creators and developer
guides.
The raw value was clamped to [-1,1] before subtracting the center,
which distorted the displayed direction for off-center inputs. Use
the raw value directly so the graph reflects true input offset.
@freezy freezy merged commit d6ea43f into master Jul 5, 2026
15 checks passed
@freezy freezy deleted the feature/nudge branch July 5, 2026 15:52
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