Files
BT411/engine/MUNGA/UPDATE.cpp
arcattackandClaude Opus 4.8 7b7d465e5e Initial commit: bt411 -- standalone Windows BattleTech (Tesla 4.10 port)
Clean, self-contained extraction of the BattleTech-specific work from the
reverse-engineering workspace -- engine + game + content + build, with nothing
from Red Planet or the raw archive dumps. Builds green (Win32) and runs the
single-player drive->animate->target->fire->damage->destroy loop out of the box.

Layout:
  engine/   MUNGA + MUNGA_L4 shared 2007 engine, carrying our BT render/loader
            work (bgfload/L4D3D/L4VIDEO: BSL bit-slice decode, LOD/ground/shadow
            models) + image codec; the minimal rp/ headers the audio HAL needs
  game/     reconstructed BT logic + surviving-original BT source + fwd shims
            + WinMain launcher
  content/  full runtime tree (BTL4.RES, VIDEO/, GAUGE/, AUDIO/, eggs, BTDPL.INI)
  docs/     format specs + reconstruction ledgers
  reference/ raw Ghidra pseudocode (recon source-of-truth) + decomp exporter
  tools/    MP console emulator + map/resource scanners

One top-level CMake builds munga_engine lib + bt410_l4 game lib + btl4.exe.
All paths relativized (186 fwd shims + ~437 CMake abs paths -> repo-relative);
DXSDK is the one external, overridable via -DDXSDK. Verified: builds to a
byte-identical 2.27MB exe and runs combat (TARGET DESTROYED, 0 crashes) against
the bundled content.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-05 21:03:40 -05:00

254 lines
6.7 KiB
C++

#include "munga.h"
#pragma hdrstop
#include "update.h"
#include "app.h"
#include "hostmgr.h"
#include "interest.h"
#include "entity.h"
#if defined(TRACE_UPDATE_REPLICANTS)
static BitTrace Update_Replicants("Update Replicants");
#define SET_UPDATE_REPLICANTS() Update_Replicants.Set()
#define CLEAR_UPDATE_REPLICANTS() Update_Replicants.Clear()
#else
#define SET_UPDATE_REPLICANTS()
#define CLEAR_UPDATE_REPLICANTS()
#endif
#if defined(TRACE_UPDATE_MASTERS)
static BitTrace Update_Masters("Update Masters");
#define SET_UPDATE_MASTERS() Update_Masters.Set()
#define CLEAR_UPDATE_MASTERS() Update_Masters.Clear()
#else
#define SET_UPDATE_MASTERS()
#define CLEAR_UPDATE_MASTERS()
#endif
MemoryBlock *SimulationEncore::GetAllocatedMemory()
{
static MemoryBlock allocatedMemory(sizeof(SimulationEncore), 10, 10, "Simulation Encores");
return &allocatedMemory;
}
SimulationEncore::SimulationEncore(
Simulation *sim,
Simulation::Encore callback
)
{
encoreSimulation = sim;
encoreCallback = callback;
runWatchers = True;
}
SimulationEncore::~SimulationEncore()
{
}
//
//#############################################################################
//#############################################################################
//
UpdateManager::UpdateManager():
simulationEncores(NULL)
{
}
//
//#############################################################################
//#############################################################################
//
UpdateManager::~UpdateManager()
{
ChainIteratorOf<SimulationEncore*> encores(simulationEncores);
SimulationEncore *encore;
while ((encore = encores.ReadAndNext()) != NULL)
{
Unregister_Object(encore);
delete encore;
}
}
//
//#############################################################################
//#############################################################################
//
Logical
UpdateManager::TestInstance() const
{
Node::TestInstance();
return True;
}
//
//#############################################################################
//#############################################################################
//
void
UpdateManager::Execute(Time target_render_time)
{
Check(this);
//
//--------------------------------------------------------------------------
// Execute the replicants and masters that are interesting and dynamic
//--------------------------------------------------------------------------
//
Check(application);
Check(application->GetHostManager());
HostManager::DynamicReplicantEntityIterator
replicant_entity_iterator(application->GetHostManager());
HostManager::DynamicMasterEntityIterator
master_entity_iterator(application->GetHostManager());
//
//--------------------------------------------------------------------------
// Execute the replicants
//--------------------------------------------------------------------------
//
SET_UPDATE_REPLICANTS();
Entity
*replicant;
while ((replicant = replicant_entity_iterator.ReadAndNext()) != NULL)
{
Check(replicant);
// BT bring-up trace (env BT_NET_TRACE): replicant scheduling visibility.
if (getenv("BT_NET_TRACE"))
{
static int s_replTrace = 0;
if (s_replTrace++ < 400 && (int)replicant->GetEntityID() >= 20)
{
DEBUG_STREAM << "[upd-repl] entity " << replicant->GetEntityID()
<< " executable=" << (int)replicant->IsReplicantExecutable()
<< "\n" << std::flush;
}
}
if (replicant->IsReplicantExecutable())
{
replicant->Execute(target_render_time);
}
}
CLEAR_UPDATE_REPLICANTS();
//
//--------------------------------------------------------------------------
// Execute the master entities, if they need to be updated then send
// update messages, and notify the interest manager of moved entities
//--------------------------------------------------------------------------
//
SET_UPDATE_MASTERS();
Entity
*entity;
Entity::UpdateMessage
*update_message;
while ((entity = master_entity_iterator.ReadAndNext()) != NULL)
{
Check(entity);
//
//-----------------------------------------------------------------------
// If the entity is not interesting then skip it
//-----------------------------------------------------------------------
//
if (!entity->IsInteresting() || !entity->IsNonReplicantExecutable())
{
continue;
}
//
//-----------------------------------------------------------------------
// Run the execute method
//-----------------------------------------------------------------------
//
update_message = entity->Execute(target_render_time);
//
//-----------------------------------------------------------------------
// Update the interest zone id
//-----------------------------------------------------------------------
//
Check(application);
Check(application->GetInterestManager());
application->GetInterestManager()->EntityUpdateInterestZone(entity);
//
//-----------------------------------------------------------------------
// If update message is not null then send the change
//-----------------------------------------------------------------------
//
if (update_message != NULL)
{
Check(update_message);
Check(application);
application->GetInterestManager()->EntityUpdateReplicants(
entity,
update_message
);
}
}
//
//--------------------------------------------------------------------------
// Lastly, run through and do any requested encores
//--------------------------------------------------------------------------
//
ChainIteratorOf<SimulationEncore*>
encores(simulationEncores);
SimulationEncore
*encore;
while ((encore = encores.ReadAndNext()) != NULL)
{
Check(encore);
Check(encore->encoreSimulation);
(encore->encoreSimulation->*encore->encoreCallback)();
if (encore->runWatchers)
{
encore->encoreSimulation->ExecuteWatchers();
encore->encoreSimulation->ClearWatcherDelay();
}
Unregister_Object(encore);
delete encore;
}
CLEAR_UPDATE_MASTERS();
}
//
//#############################################################################
//#############################################################################
//
void
UpdateManager::RequestEncore(
Simulation *simulation,
Simulation::Encore encore
)
{
//
//----------------------------------------------------------------------
// Make sure that we only run the watcher on a given simulation once per
// frame
//----------------------------------------------------------------------
//
ChainIteratorOf<SimulationEncore*> encores(simulationEncores);
SimulationEncore *i;
while ((i = encores.ReadAndNext()) != NULL)
{
if (i->encoreSimulation == simulation && i->runWatchers)
{
i->runWatchers = False;
break;
}
}
SimulationEncore *request = new SimulationEncore(simulation, encore);
Register_Object(request);
simulationEncores.Add(request);
}