Files
RP412/MUNGA/INPUTSCRIPT.h
T
CydandClaude Fable 5 af52476603 The pod can drive a scripted lap
RP412INPUTSCRIPT names a timeline file - one row per change, throttle,
stick X and Y, pedals, held until the next row's time - and the pod
drives it instead of listening to the controls. Times are SIMULATION
seconds from the green light, evaluated per step in the one place every
mapper funnels through (VTVControlsMapper::InterpretControls), so the
same script is the same lap at any frame rate. Rows hold rather than
interpolate on purpose: interpolation would sample differently at
different physics rates, and nothing on this path is allowed to.

The script shares the green-light anchor with RP412PHYSTRACE - its
clock starts at the instant the vehicle is stopped dead - because a
timeline that starts when the loader happens to finish is a different
lap every run.

A race is only deterministic if somebody DRIVES it, and a human cannot
drive the same lap twice. The first scripted lap - full throttle, a
steer, a crash at speed - earned the harness immediately:

- The drive, the crash, the death and the respawn teleport were all
  BIT-EXACT between identical runs, through t=13.5. Collisions with
  world geometry and the damage path are step-deterministic, which is
  better news than the code reading suggested.

- The first divergence is the step AFTER the respawn: the DropZoneReply
  that stands a dead pod back up is posted at wall-clock Now()+1.0
  (RPPLAYER.cpp), so the reset lands on a different sim step every run
  and everything after is time-shifted. The crash is deterministic; the
  RECOVERY is not. That is the next fix, and it is now a measurement,
  not a theory.

Values are clamped at load, once and visibly, so a script asking for
throttle 2.0 cannot trip the mapper's own range Verifies. Off unless
the environment names a file; it would be a cheat in a real race.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-09 21:03:03 -05:00

53 lines
2.0 KiB
C++

#pragma once
//##########################################################################
// RP412INPUTSCRIPT - scripted analog input, on the simulation's clock.
//
// A race cannot be called deterministic until somebody DRIVES it, and a
// human cannot drive the same lap twice. This feeds the four analog
// channels the controls mapper interprets - throttle, stick X/Y, pedals -
// from a timeline file instead, evaluated against the mapper's own step
// clock, so the same script produces the same race at any frame rate.
//
// The file named by RP412INPUTSCRIPT= holds one row per change:
//
// # t throttle stickX stickY pedals
// 0.0 0.0 0 0 0
// 2.0 1.0 0 0 0
// 6.0 1.0 0.5 0 0
//
// Times are seconds of SIMULATION time from the green light. Each row
// HOLDS until the next row's time - a step function, no interpolation,
// because interpolation would sample differently at different physics
// rates and the whole point is that nothing does.
//
// Armed by the green-light anchor in Application::ExecuteForeground (the
// same instant RP412PHYSTRACE stops the pod dead), so the script clock,
// the trace clock and the vehicle's state all start together.
//
// Test harness: off unless the environment names a file, costs nothing
// when off, and it would be a cheat in a real race.
//##########################################################################
class Time;
// is a script named and readable? (parsed once, on first ask)
int
RPInputScript_Active();
// the green light: script time zero is this instant
void
RPInputScript_Arm(const Time &origin);
// evaluate at 'now' (a simulation clock, normally GetLastPerformance()).
// Returns 0 before Arm or with no script - callers leave their own
// values alone. Outputs are clamped to the mapper's legal ranges.
int
RPInputScript_Sample(
const Time &now,
float *throttle_out, // 0..1
float *stick_x_out, // -1..1
float *stick_y_out, // -1..1
float *pedals_out // -1..1
);