The Missile entity family is reconstructed: Projectile : Mover gets a real make-path ctor; Missile hosts the Seeker + MissleThruster roster (the AUTHENTIC surviving SEEKER.HPP / MISTHRST.HPP interfaces -- the 1995 misspelling included) and flies the binary's guided integrator (@004bef78): age/lifetime, seeker re-lead with the decoded loft constants (200/50/300/0.1), thruster burn, steering (gain 4.0, deadband 1e-4), and the proximity fuse delivering the cluster damage ONCE with the launcher as inflictor. Live-verified end-to-end: LAUNCH -> flight telemetry (thruster visibly accelerating) -> DETONATE on the target ~0.9s out. OPEN: the first ~Missile off the death row completes, then the frame page-faults with EIP in the heap -- the first entity/subsystem teardown the reconstructed sim has ever run. The spawn path is therefore OPT-IN (BT_MISSILE_FLIGHT=1); default SRM delivery stays the 5.3.18a instant-hit cluster (verified 1:1, zero exceptions). Forensics + engine truths (SearchList crashes on non-directory ids; MakeMessages need FAMILY resource ids; explosionModelFile is a model-list INDEX) in MISSILE.NOTES.md. Also fixed on the way: the Subsystem NAME ctor left damageZone UNINITIALIZED (latent garbage for every name-built subsystem). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
305 lines
7.3 KiB
C++
305 lines
7.3 KiB
C++
# if !defined(MUNGA_HPP)
|
|
# include <munga.hpp>
|
|
# endif
|
|
#pragma hdrstop
|
|
|
|
# if !defined(SUBSYSTM_HPP)
|
|
# include <subsystm.hpp>
|
|
# endif
|
|
# if !defined(FILEUTIL_HPP)
|
|
# include <fileutil.hpp>
|
|
# endif
|
|
# if !defined(NOTATION_HPP)
|
|
# include <notation.hpp>
|
|
# endif
|
|
# if !defined(NAMELIST_HPP)
|
|
# include <namelist.hpp>
|
|
# endif
|
|
|
|
Subsystem::SharedData
|
|
Subsystem::DefaultData(
|
|
Subsystem::ClassDerivations,
|
|
Subsystem::MessageHandlers,
|
|
Subsystem::AttributeIndex,
|
|
Subsystem::StateCount
|
|
);
|
|
|
|
Derivation
|
|
Subsystem::ClassDerivations(Simulation::ClassDerivations, "Subsystem");
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
//
|
|
void
|
|
Subsystem::WriteUpdateRecord(
|
|
UpdateRecord *message,
|
|
int update_model
|
|
)
|
|
{
|
|
Check(this);
|
|
Check_Pointer(message);
|
|
|
|
Simulation::WriteUpdateRecord(message, update_model);
|
|
message->subsystemID = (Word)(subsystemID+1);
|
|
}
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
//
|
|
Subsystem::Subsystem(
|
|
Entity *entity,
|
|
int subsystem_ID,
|
|
SubsystemResource *model,
|
|
SharedData &shared_data
|
|
):
|
|
Simulation(model->classID, shared_data)
|
|
{
|
|
owningEntity = entity;
|
|
subsystemID = subsystem_ID;
|
|
size_t name_size = strlen(model->subsystemName)+1;
|
|
subsystemName = new char[name_size];
|
|
Register_Pointer(subsystemName);
|
|
Str_Copy(subsystemName, model->subsystemName, name_size);
|
|
segmentIndex = model->segmentIndex;
|
|
simulationFlags = model->subsystemFlags;
|
|
damageZone = NULL;
|
|
}
|
|
|
|
Subsystem::Subsystem(
|
|
Entity *entity,
|
|
int subsystem_id,
|
|
const char* subsystem_name,
|
|
RegisteredClass::ClassID class_id,
|
|
SharedData &shared_data
|
|
):
|
|
Simulation(class_id, shared_data)
|
|
{
|
|
owningEntity = entity;
|
|
subsystemID = subsystem_id;
|
|
size_t name_size = strlen(subsystem_name)+1;
|
|
subsystemName = new char[name_size];
|
|
Register_Pointer(subsystemName);
|
|
Str_Copy(subsystemName, subsystem_name, name_size);
|
|
segmentIndex = -1;
|
|
//
|
|
// (Was UNINITIALIZED in this ctor variant only -- the resource ctor
|
|
// NULLs it. Garbage here is a latent crash for any name-built
|
|
// subsystem whose dtor path or damage query walks the zone pointer.)
|
|
//
|
|
damageZone = NULL;
|
|
}
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
//
|
|
Subsystem::~Subsystem()
|
|
{
|
|
Unregister_Pointer(subsystemName);
|
|
delete[] subsystemName;
|
|
}
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
//
|
|
ResourceDescription::ResourceID
|
|
Subsystem::CreateStreamedSubsystem(
|
|
NotationFile *model_file,
|
|
const char *model_name,
|
|
const char *subsystem_name,
|
|
SubsystemResource *subsystem_resource,
|
|
NotationFile *subsystem_file,
|
|
const ResourceDirectories *directories
|
|
)
|
|
{
|
|
Check(model_file);
|
|
Check_Pointer(model_name);
|
|
Check_Pointer(subsystem_name);
|
|
Check_Pointer(subsystem_resource);
|
|
Check(subsystem_file);
|
|
Check_Pointer(directories);
|
|
|
|
for(int ii=0; ii<(sizeof(subsystem_resource->subsystemName));ii++)
|
|
{
|
|
subsystem_resource->subsystemName[ii] = '\0';
|
|
}
|
|
subsystem_resource->subsystemModelSize = sizeof(*subsystem_resource);
|
|
|
|
if (strlen(subsystem_name) > sizeof(subsystem_resource->subsystemName)-1)
|
|
{
|
|
DEBUG_STREAM << subsystem_name << " is too long. Maximum name size is "
|
|
<< (sizeof(subsystem_resource->subsystemName)-1) << " character!\n";
|
|
return False;
|
|
}
|
|
Str_Copy(
|
|
subsystem_resource->subsystemName,
|
|
subsystem_name,
|
|
sizeof(subsystem_resource->subsystemName)-1
|
|
);
|
|
|
|
//
|
|
//------------------------------------------
|
|
// If any flags were specified, read them in
|
|
//------------------------------------------
|
|
//
|
|
const char* flags;
|
|
subsystem_resource->subsystemFlags = 0;
|
|
if(
|
|
subsystem_file->GetEntry(
|
|
subsystem_name,
|
|
"SubsystemFlags",
|
|
&flags
|
|
)
|
|
)
|
|
{
|
|
if (!strcmp(flags,"DontReplicateFlag"))
|
|
{
|
|
subsystem_resource->subsystemFlags |= Subsystem::DontReplicateFlag;
|
|
}
|
|
else
|
|
{
|
|
DEBUG_STREAM << subsystem_name << " has an unknown subsystem flag!\n" << flush;
|
|
return False;
|
|
}
|
|
}
|
|
|
|
//
|
|
//--------------------------------------------------
|
|
// Get the Segment Name to locate in the .skl file
|
|
//--------------------------------------------------
|
|
//
|
|
const char* desired_page;
|
|
subsystem_resource->segmentIndex = -1;
|
|
if(
|
|
subsystem_file->GetEntry(
|
|
subsystem_name,
|
|
"SegmentPageName",
|
|
&desired_page
|
|
)
|
|
)
|
|
{
|
|
subsystem_resource->segmentIndex =
|
|
Get_Segment_Index(model_file, model_name, directories, desired_page);
|
|
}
|
|
return True;
|
|
}
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
//
|
|
Logical
|
|
Subsystem::TestInstance() const
|
|
{
|
|
return IsDerivedFrom(ClassDerivations);
|
|
}
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
//
|
|
Logical
|
|
Subsystem::GenerateFault(int /*fault_index*/)
|
|
{
|
|
Check(this);
|
|
Check_Fpu();
|
|
return False; // fault not generated
|
|
}
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
//
|
|
int
|
|
Get_Segment_Index(
|
|
NotationFile *model_file,
|
|
const char* model_name,
|
|
const ResourceDirectories *directories,
|
|
const char *desired_page
|
|
)
|
|
{
|
|
//------------------------------------------
|
|
// Get the Segment Index from the .skl file
|
|
//------------------------------------------
|
|
//
|
|
const char* skl_entry;
|
|
if (
|
|
!model_file->GetEntry(
|
|
"video",
|
|
"skeleton",
|
|
&skl_entry
|
|
)
|
|
)
|
|
{
|
|
cerr << model_name << " is missing .skl file specification!\n";
|
|
return -1;
|
|
}
|
|
|
|
char *skl_filename =
|
|
MakePathedFilename(directories->videoDirectory, skl_entry);
|
|
Register_Pointer(skl_filename);
|
|
|
|
NotationFile *skl_file = new NotationFile(skl_filename);
|
|
Register_Object(skl_file);
|
|
if (!skl_file->PageCount())
|
|
{
|
|
cerr << skl_filename << " is empty or missing!\n";
|
|
Dump_And_Die:
|
|
Unregister_Pointer(skl_filename);
|
|
delete[] skl_filename;
|
|
Unregister_Object(skl_file);
|
|
delete skl_file;
|
|
return ResourceDescription::NullResourceID;
|
|
}
|
|
|
|
//
|
|
// Make a pagelist of all the segments
|
|
//
|
|
NameList *segment_pages = skl_file->MakePageList();
|
|
Register_Object(segment_pages);
|
|
|
|
NameList::Entry *segment_entry = segment_pages->GetFirstEntry();
|
|
char
|
|
segment_page_name[32];
|
|
int
|
|
segment_index = -1;
|
|
int
|
|
current_index = 0;
|
|
while(segment_entry)
|
|
{
|
|
Str_Copy(
|
|
segment_page_name,
|
|
segment_entry->GetName(),
|
|
sizeof(segment_page_name)
|
|
);
|
|
//
|
|
//---------------------------------------
|
|
// skip labonly and damagezones
|
|
//---------------------------------------
|
|
//
|
|
if(
|
|
(strcmp(segment_page_name, "LAB_ONLY") == 0) ||
|
|
(strcmp(segment_page_name,"DamageZones") ==0)
|
|
)
|
|
{
|
|
segment_entry = segment_entry->GetNextEntry();
|
|
continue;
|
|
}
|
|
//
|
|
//-------------------------------------
|
|
// if names match save the index
|
|
//-------------------------------------
|
|
//
|
|
else if(strcmp(segment_page_name,desired_page) ==0)
|
|
{
|
|
segment_index = current_index;
|
|
break;
|
|
}
|
|
++current_index;
|
|
segment_entry = segment_entry->GetNextEntry();
|
|
}
|
|
if(segment_index == -1)
|
|
{
|
|
cout<<desired_page <<" SegmentPageName Not in "<< skl_filename <<endl;
|
|
return False;
|
|
}
|
|
Unregister_Pointer(skl_filename);
|
|
delete[] skl_filename;
|
|
Unregister_Object(skl_file);
|
|
delete skl_file;
|
|
Unregister_Object(segment_pages);
|
|
delete segment_pages;
|
|
|
|
return segment_index;
|
|
}
|
|
|