Files
TeslaRel410/restoration/source410/BT/HUD.CPP
T
CydandClaude Fable 5 59a0c109c9 BT410 5.3.112: the hot path stops paying for its own diagnostics -- plus the HUD's confident half
PERFORMANCE, measured not guessed (operator report: "vastly slower than the
original").  The audit found and fixed:

  THE [crash] FLOOD: the collision-block log printed EVERY BLOCKED FRAME --
  5,487 lines in one wall-grinding run (~13/s sustained), each a float-heavy
  iostream format pushed through the COM3 serial redirect.  The shipped exe
  prints nothing, ever.  Now logs the CONTACT EDGE only (the same
  collisionState 0->1 gate the audio uses).

  ~100 UNCACHED getenv SCANS PER FRAME: every gated log site walked the DOS
  environment block per call, and the control mapper ran FOUR getenv + atof
  parses per frame in the input path whether logging was on or not.  All
  hot-path gates now cache in function-local statics (the donor's own
  idiom); the force-input overrides parse once.

  Ruled out: the debug macros (DEBUG_LEVEL=0 nulls Check/Verify wholesale,
  DEBUGOFF.HPP) and optimization (-O2, the authentic OPT flags).

  MEASURED RESULT: crash lines 5487 -> 0 on the same mission; the SOS frame
  pacing is 16.67 ticks/frame with drift=0 in BOTH the flooded and fixed
  runs -- the fixed-tick sim never actually lost its clock on the rig, so
  the flood's cost was wall-time in the serial path, not sim drift.

  THE OTHER HALF OF THE ANSWER, for the operator: since 5.3.95 the hull's
  speed is STRIDE-DRIVEN.  The mech steps off at ~7 u/s and winds up
  through the walk band (capped 18.5) to the run only across clip-boundary
  transitions -- seconds, like the real pod -- where the old bring-up model
  hit 26.9 instantly.  Walls also now stop the mech dead.  If "slower"
  means acceleration feel rather than frame rate, that is the AUTHENTIC
  gait arriving, not a defect.

ALSO IN: HUD::HudSimulation's confident half (base tick, heat/voltage page
gating off the 5.3.109 mirrors, the blink -- with >= on the flicker compare
where the decomp shard's literal != would toggle every tick), registered on
the master; the reticle/lock/torso-horizon math stays STAGED, matching the
donor's own unfinished state.  Stub census: 17 across 11 files.

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

174 lines
4.4 KiB
C++

//===========================================================================//
// File: hud.cpp //
// Project: BattleTech Brick: Mech subsystems //
// Contents: HUD -- head-up display / targeting reticle //
//---------------------------------------------------------------------------//
// Copyright (C) 1995, Virtual World Entertainment, Inc. //
// All Rights reserved worldwide //
// This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL //
//===========================================================================//
#include <bt.hpp>
#pragma hdrstop
#if !defined(HUD_HPP)
# include <hud.hpp>
#endif
#if !defined(MECH_HPP)
# include <mech.hpp>
#endif
static const Point3D HudZeroVector(0.0f, 0.0f, 0.0f);
Derivation
HUD::ClassDerivations(
PowerWatcher::ClassDerivations,
"HUD"
);
HUD::SharedData
HUD::DefaultData(
HUD::ClassDerivations,
Subsystem::MessageHandlers,
Subsystem::AttributeIndex,
Subsystem::StateCount
);
HUD::HUD(
Mech *owner,
int subsystem_ID,
SubsystemResource *subsystem_resource,
SharedData &shared_data
):
PowerWatcher(owner, subsystem_ID, subsystem_resource, shared_data)
{
Check(owner);
Check_Pointer(subsystem_resource);
flickerRate = 0.0f;
rotationOfTorsoHorizontal = 0.0f;
torsoLimitRight = 0.0f;
torsoLimitLeft = 0.0f;
torsoSpeed = 0.0f;
rangeToTarget = 0.0f;
scratch1F0 = 0;
visible = True;
lockFlag = False;
hotBoxVector = HudZeroVector;
threatVector = HudZeroVector;
compassHeading = 0.0f;
blinkTimer = 0.0f;
flickerTimer = 0.0f;
blinkState = True;
transitionFlag = False;
previousHorizontal = 0.0f;
statusAlarm.Initialize(2);
freeAimSlew = 0.0f;
scratch290 = 0.0f;
horizontalTorsoOffset = 0.0f;
flickerRate = subsystem_resource->flickerRate;
horizontalMovementPerSecond = subsystem_resource->horizontalMovementPerSecond;
horizontalLimit = subsystem_resource->horizontalLimit;
//
// The torso-orientation source is a Mech link not yet live at
// construction time; HudSimulation refreshes these per-frame.
//
linkedEntity = 0;
flickerActive = 0;
//
// The master instance runs the HUD per-frame.
//
if (owner->GetInstance() != Entity::ReplicantInstance)
{
SetPerformance(&HUD::HudSimulation);
}
Check_Fpu();
}
HUD::~HUD()
{
}
Logical
HUD::TestClass(Mech &)
{
return True;
}
Logical
HUD::TestInstance() const
{
return IsDerivedFrom(ClassDerivations);
}
//
//#############################################################################
// @004b7830 -- the per-frame HUD, PARTIAL: the base tick, the heat/voltage
// page gating and the blink are reconstructed (the donor's confident half);
// the reticle / target-lock / torso-horizon math (its blocks 4-6) survives
// only as summarised offsets in the recovered shard and stays STAGED --
// the page visibility is the cockpit-bound behaviour, and it is real.
//
// The blink comparison is >= (the decomp shard's literal != would toggle
// every tick through float inequality; the shard's own banner describes
// "compared against flickerRate; on expiry ... toggles").
//#############################################################################
//
void
HUD::HudSimulation(Scalar time_slice)
{
Check(this);
PowerWatcher::Simulation(time_slice);
//
// Page gating off our own mirrored alarms (the watchers, 5.3.109):
// a heat failure or an unpowered watched subsystem hides the page.
//
Logical
page_visible = True;
if (watchdogAlarm.GetLevel() != PoweredSubsystem::Ready)
{
page_visible = False;
}
if (heatAlarm.GetLevel() == HeatSink::FailureHeat)
{
page_visible = False;
}
//
// The blink.
//
if (transitionFlag == 0)
{
blinkTimer += time_slice;
if (blinkTimer >= flickerRate)
{
blinkTimer = 0.0f;
blinkState = (blinkState == 0);
}
}
else if (transitionFlag == 1)
{
blinkState = True;
}
visible = (page_visible && blinkState) ? 1 : 0;
//
// STAGED (donor blocks 4-6): engine/start flag mirror, target lock +
// sliding range + compass, and the torso-horizon slew -- summarised
// offsets only in the recovered shard (part_013.c @004b7830).
//
Check_Fpu();
}