Files
BT411/engine/MUNGA_L4/L4PADRIO.h
T
arcattackandClaude Opus 4.8 390d4ddce7 Issue #36: direct-axis RELEASE EDGE -- centering an axis now releases its channel
Night-2 (RajelAran): 'the game is not seeing axis release for turn --
the mech may keep turning when control is released.'  Root cause: the
direct-mode axis write was gated on raw != 0, so an axis returning
INSIDE the deadzone just stopped writing and the channel LATCHED at
the last deflection -- fatal on channels with no keyboard spring (the
Turn composite in the twin-stick profile).

Fix: per-binding previous-value tracking (pad + joystick paths); the
outside->inside transition writes 0 exactly once, then the centered
axis leaves the channel to other inputs (composition preserved; slew
bindings excluded by design -- a lever stays where slewed).  Plus the
#24 rule, axis edition: a pad/stick that DIES while deflected releases
its direct channels (throttle keeps the last lever position -- safer
than an all-stop mid-fight).

Verified: build + 45s glass mission with an idle XInput pad (no
spurious writes, no regression).  The deflect-release cycle itself
needs a human hand -- awaiting RajelAran's next session.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-23 23:40:27 -05:00

162 lines
4.8 KiB
C++

#pragma once
//###########################################################################
//
// L4PADRIO -- the hardware-less cockpit device (BT_GLASS only).
//
// PadRIO synthesizes the pod's abstract control surface (RIOBase: the five
// analog Scalars + button/keypad events + lamps) from an XInput controller
// and the PC keyboard, so the whole stock RIO path above the seam -- the
// LBE4ControlsManager push, MechRIOMapper, streamed .CTL mappings, lamp
// writes -- runs with no serial hardware. Selected at runtime with
// L4CONTROLS=PAD (the factory arm in L4CTRL.cpp).
//
// Input model (bindings: L4PADBINDINGS.h, content\bindings.txt):
// - keyboard keys emit button/keypad edge events and drive the analog
// channels (spring-stick deflect / throttle-lever slew / detent set)
// - XInput pad buttons emit button events; pad axes drive the channels
// directly (or as slew rates); hot-plug re-probe every ~3 s
// - on-screen cockpit buttons (the L4PADPANEL window, or any WndProc)
// inject through the static SetScreenButton() entry
// - lamps are recorded in lampState[] for the on-screen panel to render
//
// The keyboard is only read while a window of THIS process has focus.
// L4PADFLIP=1 inverts both stick axes.
//
//###########################################################################
#include "l4rio.h"
#include "l4padbindings.h"
class PadRIO :
public RIOBase
{
public:
PadRIO();
~PadRIO();
Logical
GetNextEvent(RIOEvent *destinationPointer);
void
SetLamp(int lampNumber, int state);
Logical
IsOperational() const
{ return True; }
//
// The on-screen panel / WndProc entries. Safe no-ops when no PadRIO
// is active (pod build never links this TU; a glass build without
// L4CONTROLS=PAD never constructs one). Same-thread use only: the
// panel WndProc runs on the app thread's message pump.
//
static Logical
IsActive();
static void
SetScreenButton(int unit, int pressed);
static int
GetLampState(int unit);
//
// Legacy typed-channel suppression (the btinput BTInputSuppressKey
// pattern, glass-side). A key CLAIMED by a bindings.txt row (or by the
// hardcoded `/V view-toggle and J/K/L preset-cycle keys) is swallowed
// from the engine's WM_CHAR/WM_KEYUP key-command feed (L4CTRL.cpp:1506
// block) -- otherwise every bound letter double-dispatches into the 1995
// in-cockpit dispatcher ('w' = pilot select 0, 'a'/'s'/'d'/'f' = MFD2
// preset pages, NUMPAD key-up VKs alias to 'b'/'d'/'e' hotkeys, ...).
// Unbound keys keep their authentic 1995 typed meaning. Returns 0 when
// no PadRIO is active (the feed flows untouched on dev/pod builds).
//
static int
SuppressKey(unsigned int key_value, int is_char);
enum { LampCount = 128 };
protected:
void
Poll();
void
PushEvent(const RIOEvent &event);
void
EmitButton(int address, int pressed);
void
EmitKeypad(int unit, int key);
PadBindingProfile
bindings;
//
// Event queue (ring; drop-newest on overflow, logged).
//
enum { EventQueueSize = 128 };
RIOEvent
eventQueue[EventQueueSize];
int
eventHead, eventTail;
//
// Poll state.
//
unsigned long
lastPollMilliseconds;
unsigned long
lastPadProbeMilliseconds;
int
padIndex; // connected XInput slot, -1 = none
unsigned
previousPadButtons;
unsigned char
previousKeyHeld[192]; // per key BINDING (parallel to the profile)
//
// Generic-joystick edge state, per BINDING (parallel to the profile's
// joy tables -- the previousKeyHeld pattern). A device detach reads
// everything as released, so held buttons let go automatically (the
// issue-#24 rule).
//
unsigned char
previousJoyButtonHeld[48];
unsigned char
previousJoyHatHeld[16];
//
// Direct-axis RELEASE EDGES (issue #36, night-2: "the mech may keep
// turning when control is released"). A direct-mode axis write was
// gated on raw != 0, so an axis returning INSIDE the deadzone simply
// stopped writing -- the channel LATCHED at the last deflection (fatal
// on channels with no keyboard spring, e.g. the Turn composite). Track
// the previous post-deadzone value per binding: the outside->inside
// transition writes 0 exactly once, then leaves the channel to other
// inputs (the composition model is preserved).
//
float
previousPadAxisRaw[12]; // parallel to padAxisBindings
float
previousJoyAxisRaw[24]; // parallel to joyAxisBindings
float
channelValue[PadBindingProfile::ChannelCount];
float
channelReturnRate[PadBindingProfile::ChannelCount];
int
flipStickAxes; // L4PADFLIP
int
lampState[LampCount];
//
// Typed-channel suppression tables (built from the loaded bindings +
// the hardcoded view/preset keys; see SuppressKey).
//
unsigned char
suppressChar[256]; // WM_CHAR values
unsigned char
suppressKeyUp[256]; // WM_KEYUP values (VK aliases)
void
AddKeySuppression(int virtual_key);
void
BuildKeySuppression();
static PadRIO
*activeInstance;
};