Files
TeslaRel410/restoration/source410/MUNGA/APP.HPP
T
CydandClaude Fable 5 475ae3106e BT410 5.3.59: A MISSION RUNS -- the RIO serial port was blocking every load
pod_render_norio.conf is pod_render_rec.conf with one line changed,
serial1=disabled instead of the vrio named pipe.  Same binary, same egg.  With
it, our build launches and the mech walks:

  [launch] state=2 minPriorityEmpty=1 ticks=85316
  [queues] p0=- p1=- p2=BUSY p3=- p4=-
  BTL4Application::RunMissionMessageHandler
  Turning Plasma Score Display On
  [sim] pos=(180.466,10,-358.703) yaw=-0.275605 spd=14.4
  [sim] pos=(251.959,10,-250.498) yaw=-0.89103  spd=14.4

No fault, 290 log lines and counting.  This is the first time the
reconstruction has reached a running mission on the pod.

The hang was never starvation, a deadlock, or a refill loop -- it was VOLUME,
the first candidate I listed and then talked myself out of.  530 renderer
events queue at priority 0 during load; BackgroundTasks::Execute runs exactly
one task per call round-robin over seven tasks, and the 1ms frame budget is
always blown here so no extra background passes happen.  That is ~9 events per
real second, so a load legitimately takes ~60s.  The fault arrived at ~40s,
before the backlog could clear.  Every 'the queue never drains' reading was
really 'the process dies before it can'.

The disproof was already in hand: the post tally climbed to 530 and went FLAT,
which means nothing was refilling.  p0=BUSY with nextReady=1 is equally
consistent with a large finite backlog still draining, and I read it as refill.

Why the RIO port: the pipe has no server attached, which should behave as an
unplugged cable.  The emulator log shows steady serial1 RX overruns, our build
prints 'RIO never came back from test mode!', and the SHIPPED binary prints
'lost RIO analog request' and launches anyway on this identical rig.  So an
unplugged RIO is survivable and our handling of it is not -- a real defect, not
a rig artifact, since a pod with an unplugged RIO cable should still boot.

The wild reference at EulerAngles::operator=(const LinearMatrix&)+0x19 is still
unexplained, but it is now reproducible on demand by enabling serial1 rather
than being a coin flip.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-28 23:23:29 -05:00

829 lines
16 KiB
C++

#if !defined(APP_HPP)
# define APP_HPP
# if !defined(NETWORK_HPP)
# include <network.hpp>
# endif
# if !defined(EVENT_HPP)
# include <event.hpp>
# endif
# if !defined(STATE_HPP)
# include <state.hpp>
# endif
# if !defined(CSTR_HPP)
# include <cstr.hpp>
# endif
#if defined(TRACE_FOREGROUND_PROCESSING)
extern BitTrace Foreground_Processing;
#define SET_FOREGROUND_PROCESSING() Foreground_Processing.Set()
#define CLEAR_FOREGROUND_PROCESSING() Foreground_Processing.Clear()
#else
#define SET_FOREGROUND_PROCESSING()
#define CLEAR_FOREGROUND_PROCESSING()
#endif
#if defined(TRACE_UPDATE_MANAGER)
extern BitTrace Update_Manager;
#define SET_UPDATE_MANAGER() Update_Manager.Set()
#define CLEAR_UPDATE_MANAGER() Update_Manager.Clear()
#else
#define SET_UPDATE_MANAGER()
#define CLEAR_UPDATE_MANAGER()
#endif
#if defined(TRACE_RENDERER_MANAGER)
extern BitTrace Renderer_Manager;
#define SET_RENDERER_MANAGER() Renderer_Manager.Set()
#define CLEAR_RENDERER_MANAGER() Renderer_Manager.Clear()
#else
#define SET_RENDERER_MANAGER()
#define CLEAR_RENDERER_MANAGER()
#endif
class Mission;
class Registry;
class InterestManager;
class HostManager;
class UpdateManager;
class RendererManager;
class ControlsManager;
class Entity;
class EntityManager;
class Renderer;
class BackgroundTasks;
class ApplicationManager;
class CameraShip;
class SpoolFile;
class AudioRenderer;
class VideoRenderer;
class GaugeRenderer;
class IcomManager;
class ModeManager;
class Player;
class GeneralEventQueue;
class Entity__MakeMessage;
class ResourceFile;
//##########################################################################
//######################### Application ##############################
//##########################################################################
class Application__StateQueryMessage;
class Application__CheckLoadMessage;
class Application__RunMissionMessage;
class Application__StopMissionMessage;
class Application__SuspendMissionMessage;
class Application__ResumeMissionMessage;
class Application__AbortMissionMessage;
enum EventPriorities
{
MinEventPriority = 0,
LowEventPriority,
DefaultEventPriority,
HighEventPriority,
MaxEventPriority
};
const EventPriorities ControlsEventPriority = HighEventPriority;
const EventPriorities CreationEventPriority = HighEventPriority;
const EventPriorities DestructionEventPriority = HighEventPriority;
const EventPriorities UpdateEventPriority = MaxEventPriority;
const EventPriorities HighInterestEventPriority = DefaultEventPriority;
const EventPriorities LowInterestEventPriority = LowEventPriority;
const EventPriorities EntityManagerEventPriority = DefaultEventPriority;
const EventPriorities EntityInvalidEventPriority = LowEventPriority;
enum ApplicationID
{
RPL4,
BTL4,
NDL4
};
#define EVENT_PRIORITIES_COUNT (5)
class Application:
public NetworkClient
{
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Construction, Destruction, and Testing
//
public:
Application(
ResourceFile *resource_file,
ApplicationID application_id,
ClassID class_ID=ApplicationClassID,
SharedData &shared_data=DefaultData
);
~Application();
Logical
TestInstance() const;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Execution control
//
public:
virtual void Initialize();
virtual void
LoadBackgroundTasks();
virtual Logical
ExecuteForeground(
Time start_of_frame,
Scalar frame_duration
);
virtual void
ExecuteBackgroundTask();
void
Stop();
virtual Logical
Shutdown(int remainingApps = 0);
virtual void
Terminate();
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Creation Callbacks
//
public:
void
CreateMission(NotationFile *egg_notation_file);
virtual Entity*
MakeAndLinkViewpointEntity(Entity__MakeMessage *message);
protected:
virtual Mission*
MakeMission(
NotationFile *notation_file,
ResourceFile *resources
);
virtual Entity*
MakeViewpointEntity(Entity__MakeMessage *message);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Current mission
//
public:
Mission*
GetCurrentMission();
Player*
GetMissionPlayer()
{return missionPlayer;}
SpoolFile*
GetSpoolFile()
{return spoolFile;}
protected:
Player
*missionPlayer;
SpoolFile*
spoolFile;
Time
lastCreationMessage;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Application State
//
public:
enum {
InitializingState = 0,
WaitingForEgg,
LoadingMission,
WaitingForLaunch,
LaunchingMission,
RunningMission,
EndingMission,
StoppingMission,
SuspendingMission,
ResumingMission,
AbortingMission,
CreatingMission,
ApplicationStateCount
};
Enumeration
GetApplicationState();
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// System level event processing
//
public:
void
Post(
int priority,
Receiver *target,
Receiver::Message *message,
const Time &when=Time::Null
);
void
SendEvent(
int priority,
HostID host_ID,
NetworkManager::ClientID client_ID,
Receiver::Message *message,
Time when=Time::Null
);
void
BroadcastEvent(
int priority,
NetworkManager::ClientID client_ID,
Receiver::Message *message,
Time when=Time::Null
);
void
ExclusiveBroadcastEvent(
int priority,
NetworkManager::ClientID client_ID,
Receiver::Message *message,
Time when=Time::Null
);
#if defined(TRACE_EVENT_COUNT)
size_t
GetEventCount();
#endif
void
DumpEventQueue();
#if 0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Creation and Interest Event Posting
//
public:
void
PostCreationEvent(
Receiver::Message *message,
const Time &when=Time::Null
);
void
PostInterestEvent(
Entity *entity,
Renderer *renderer
);
void
PostUpdateEvent(
Entity *entity,
Receiver::Message *message
);
void
PostDestructionEvent(
Entity *entity,
Receiver::Message *message
);
#endif
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// System level message processing
//
public:
void
SendMessage(
HostID host_ID,
NetworkManager::ClientID client_ID,
Receiver::Message *message
);
void
BroadcastMessage(
NetworkManager::ClientID client_ID,
Receiver::Message *message
);
void
ExclusiveBroadcastMessage(
NetworkManager::ClientID client_ID,
Receiver::Message *message
);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Event level event processing
//
public:
Logical
ProcessOneEvent(int min_priority=0);
void
ProcessAllEvents(int min_priority=0);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Accessors
//
public:
Scalar
GetApplicationLoopFrameRate();
Scalar
GetSecondsRemainingInGame()
{return secondsRemainingInGame;}
ApplicationID
GetApplicationID()
{return applicationID;}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Module accessors
//
public:
//
// Managers
//
NetworkManager*
GetNetworkManager();
EntityManager*
GetEntityManager();
Registry*
GetRegistry();
HostManager*
GetHostManager();
InterestManager*
GetInterestManager();
UpdateManager*
GetUpdateManager();
RendererManager*
GetRendererManager();
ControlsManager*
GetControlsManager();
IcomManager*
GetIntercomManager();
AudioRenderer*
GetAudioRenderer();
VideoRenderer*
GetVideoRenderer();
GaugeRenderer*
GetGaugeRenderer();
ModeManager*
GetModeManager();
//
// StreamableResourceFile
//
ResourceFile*
GetResourceFile();
void
SetResourceFile(ResourceFile *resources);
ApplicationManager*
GetApplicationManager();
//
// Viewpoint entity
//
Entity*
GetViewpointEntity();
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Message Support
//
public:
enum {
StateQueryMessageID = NetworkClient::NextMessageID,
CheckLoadMessageID,
RunMissionMessageID,
StopMissionMessageID,
KeyCommandMessageID,
SuspendMissionMessageID,
ResumeMissionMessageID,
LoadMissionMessageID,
AbortMissionMessageID,
NextMessageID
};
typedef Application__StateQueryMessage StateQueryMessage;
typedef Application__CheckLoadMessage CheckLoadMessage;
typedef Application__RunMissionMessage RunMissionMessage;
typedef Application__StopMissionMessage StopMissionMessage;
typedef Application__SuspendMissionMessage SuspendMissionMessage;
typedef Application__ResumeMissionMessage ResumeMissionMessage;
typedef Application__AbortMissionMessage AbortMissionMessage;
static const HandlerEntry
MessageHandlerEntries[];
//static MessageHandlerSet MessageHandlers;
static MessageHandlerSet MessageHandlers;
void
StateQueryMessageHandler(StateQueryMessage *message);
void
CheckLoadMessageHandler(CheckLoadMessage *message);
void
RunMissionMessageHandler(RunMissionMessage *message);
void
StopMissionMessageHandler(StopMissionMessage *message);
void
SuspendMissionMessageHandler(SuspendMissionMessage *message);
void
ResumeMissionMessageHandler(ResumeMissionMessage *message);
void
KeyCommandMessageHandler(ReceiverDataMessageOf<int> *message);
void
LoadMissionMessageHandler(Message *message);
void
AbortMissionMessageHandler(AbortMissionMessage *message);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Shared Data Support
//
public:
static Derivation ClassDerivations;
static SharedData DefaultData;
static Logical DoSuppressGauges() { return suppressGauges; }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Modules
//
protected:
//
// Managers
//
NetworkManager
*networkManager;
EntityManager
*entityManager;
Registry
*registry;
HostManager
*hostManager;
InterestManager
*interestManager;
UpdateManager
*updateManager;
RendererManager
*rendererManager;
ControlsManager
*controlsManager;
IcomManager
*intercomManager;
AudioRenderer
*audioRenderer;
VideoRenderer
*videoRenderer;
GaugeRenderer
*gaugeRenderer;
ModeManager
*modeManager;
static Logical suppressGauges;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Module Creation
//
protected:
//
// Managers
//
virtual NetworkManager*
MakeNetworkManager();
virtual Registry*
MakeRegistry();
virtual ControlsManager*
MakeControlsManager();
virtual IcomManager*
MakeIntercomManager();
virtual InterestManager*
MakeInterestManager();
virtual AudioRenderer*
MakeAudioRenderer();
virtual VideoRenderer*
MakeVideoRenderer();
virtual GaugeRenderer*
MakeGaugeRenderer();
virtual ModeManager*
MakeModeManager();
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Private data
//
protected:
ApplicationID
applicationID;
Scalar
secondsRemainingInGame;
Time
gameStarted;
GeneralEventQueue
*eventQueue;
BackgroundTasks
*backgroundTasks;
ResourceFile
*resourceFile;
Entity
*viewpointEntity;
Logical
executeFrames;
StateIndicator
applicationState;
Mission
*currentMission;
Logical
routePacketFinished;
};
extern Application *application;
extern int Exit_Code;
//~~~~~~~~~~~~~~~~~~~~ Application__CheckLoadMessage ~~~~~~~~~~~~~~~~~~~~~~~
class Application__CheckLoadMessage:
public NetworkClient::Message
{
public:
Application__CheckLoadMessage();
};
//~~~~~~~~~~~~~~~~~~~~~~~~~ Application inlines ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
inline Mission*
Application::GetCurrentMission()
{
Check(this);
return currentMission;
}
inline Enumeration
Application::GetApplicationState()
{
Check(this);
return applicationState.GetState();
}
//
// POST TALLY, by message ID, for priority 0 only.
//
// Measured: priority 0 is never empty, nothing above it is busy, and
// PeekAtNextEvent always reports a ready event while the pump drains ~143 per
// simulated second. That is a REFILL loop -- something re-posts priority-0
// work as fast as it is consumed -- and the counters are identical to the byte
// across runs, so it is deterministic rather than a race.
//
// Only the interest manager posts at priority 0 (it maps every renderer event
// there while the application is not RunningMission), so naming the message
// names the flooder.
//
#define POST_TALLY_IDS 64
extern long
postTally[POST_TALLY_IDS];
inline void
Application::Post(
int priority,
Receiver *target,
Receiver::Message *message,
const Time &when
)
{
Check(this);
if (priority == MinEventPriority && message != NULL)
{
Check(message);
if (
(int)message->messageID >= 0 &&
(int)message->messageID < POST_TALLY_IDS
)
{
postTally[(int)message->messageID]++;
}
}
eventQueue->Post(priority,target,message,when);
}
inline void
Application::SendEvent(
int priority,
HostID host_ID,
NetworkClient::ClientID client_ID,
Receiver::Message *message,
Time when
)
{
Check(this);
eventQueue->SendEvent(priority,host_ID,client_ID,message,when);
}
inline void
Application::BroadcastEvent(
int priority,
NetworkClient::ClientID client_ID,
Receiver::Message *message,
Time when
)
{
Check(this);
eventQueue->BroadcastEvent(priority,client_ID,message,when);
}
inline void
Application::ExclusiveBroadcastEvent(
int priority,
NetworkClient::ClientID client_ID,
Receiver::Message *message,
Time when
)
{
Check(this);
eventQueue->ExclusiveBroadcastEvent(priority,client_ID,message,when);
}
#if defined(GET_EVENT_COUNT)
inline size_t
Application::GetEventCount()
{
return eventQueue->GetEventCount();
}
#endif
inline void
Application::DumpEventQueue()
{
eventQueue->DumpEventQueue();
}
inline void
Application::SendMessage(
HostID host_ID,
NetworkClient::ClientID client_ID,
Receiver::Message *message
)
{
Check(this);
networkManager->Send(message,client_ID,host_ID);
}
inline void
Application::BroadcastMessage(
NetworkManager::ClientID client_ID,
Receiver::Message *message
)
{
Check(this);
networkManager->Broadcast(message,client_ID);
}
inline void
Application::ExclusiveBroadcastMessage(
NetworkManager::ClientID client_ID,
Receiver::Message *message
)
{
Check(this);
networkManager->ExclusiveBroadcast(message,client_ID);
}
//
// EVENT-PUMP COUNTERS (read by the BT_STACK_LOG probe in ExecuteForeground).
//
// The application parks in LoadingMission because IsPriorityEmpty(0) never
// becomes true, and priority 0 is where the interest manager queues every
// renderer event while the mission loads. Three very different faults look
// identical from outside -- the pump never runs, the pump runs but finds
// nothing (so something else holds the queue), or the pump drains events as
// fast as they are re-posted. Counting calls against hits separates them in
// a single run.
//
extern long
eventPumpCalls;
extern long
eventPumpHits;
inline Logical
Application::ProcessOneEvent(int min_priority)
{
Check(this);
Logical processed;
eventPumpCalls++;
processed = eventQueue->ProcessOneEvent(min_priority);
if (processed)
{
eventPumpHits++;
}
return processed;
}
inline void
Application::ProcessAllEvents(int min_priority)
{
Check(this);
eventQueue->ProcessAllEvents(min_priority);
}
inline NetworkManager*
Application::GetNetworkManager()
{
Check(networkManager);
return networkManager;
}
inline EntityManager*
Application::GetEntityManager()
{
return entityManager;
}
inline Registry*
Application::GetRegistry()
{
return registry;
}
inline HostManager*
Application::GetHostManager()
{
return hostManager;
}
inline InterestManager*
Application::GetInterestManager()
{
return interestManager;
}
inline UpdateManager*
Application::GetUpdateManager()
{
return updateManager;
}
inline RendererManager*
Application::GetRendererManager()
{
return rendererManager;
}
inline ControlsManager*
Application::GetControlsManager()
{
return controlsManager;
}
inline IcomManager*
Application::GetIntercomManager()
{
return intercomManager;
}
inline ResourceFile*
Application::GetResourceFile()
{
return resourceFile;
}
inline void
Application::SetResourceFile(ResourceFile *resources)
{
resourceFile = resources;
}
inline Entity*
Application::GetViewpointEntity()
{
return viewpointEntity;
}
inline AudioRenderer*
Application::GetAudioRenderer()
{
return audioRenderer;
}
inline VideoRenderer*
Application::GetVideoRenderer()
{
return videoRenderer;
}
inline GaugeRenderer*
Application::GetGaugeRenderer()
{
return gaugeRenderer;
}
inline ModeManager*
Application::GetModeManager()
{
return modeManager;
}
#endif