Files
BT411/engine/MUNGA_L4/L4PADRIO.h
T
arcattackandClaude Opus 5 23229e573e Reverse thrust was dead on the desktop (user report): wire the 0x3F throttle-handle button
LALT -> button 0x3F was bound in both binding layers and PadRIO pushed the RIO
ButtonPressed event correctly, but nothing ever set the mapper's ReverseThrust:

 - the authentic route is BTL4.RES 'L4' streamed record [2] (Button Throttle1
   0x3F -> attr 6 ReverseThrust@0x124), but our streamed BUTTON mappings are
   not consumed at all -- MechControlsMapper::AddOrErase is still the
   unreconstructed Fail stub, so the event never reaches the attribute;
 - the ONLY writer of reverseThrust was the keyboard bridge's
   'key_throttle < 0' test, which is bypassed whenever a RIO is operational
   (the pad RIO always is, so the bridge is OFF on the desktop) AND is
   unreachable regardless, because L4PADRIO clamps the Throttle channel to
   [0,1].  Net: Alt did nothing and the flag was re-zeroed every frame.

FIX: publish the 0x3F hold state from PadRIO::EmitButton -- the one chokepoint
every desktop source funnels through (keyboard, gamepad, DirectInput joystick,
glass-panel clicks via SetScreenButton) -- and apply it in InterpretControls
gated on BTPadRIOActive() so real pod hardware is untouched (there the streamed
mapping owns the flag).  Marked [T3]; delete once streamed button mappings land.
Reverse is a HOLD (manual: hold the red throttle button, release = forward).

Verified with scratchpad/revtest.py (keybd_event injection, BT_KEY_NOFOCUS):
forward = rev=0 dmd +61.501; LALT held = rev=1 dmd -61.501; release edge logged.

KB: pod-hardware.md now records the streamed-button-mapping gap + this seam.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0166KTsC7ADm7VXEi1HF1jNg
2026-07-24 19:19:21 -05:00

170 lines
5.1 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;
public:
//
// Is the desktop pad RIO the live input device? (0 on real pod hardware,
// whose RIO is the serial Ranger board -- see BTPadRIOActive.)
//
static int
HasActiveInstance() { return activeInstance != 0; }
};