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>
343 lines
6.9 KiB
C++
343 lines
6.9 KiB
C++
#pragma once
|
|
|
|
#include "time.h"
|
|
#include "slot.h"
|
|
#include "network.h"
|
|
|
|
class GeneralEventQueue;
|
|
class EventQueue;
|
|
class DeferredEventQueue;
|
|
class Entity;
|
|
|
|
//##########################################################################
|
|
//######################## AbstractEvent #############################
|
|
//##########################################################################
|
|
|
|
class AbstractEvent:
|
|
public Node
|
|
{
|
|
friend class GeneralEventQueue;
|
|
friend class EventStatisticsManager;
|
|
|
|
//##########################################################################
|
|
// Event Functionality
|
|
//
|
|
protected:
|
|
AbstractEvent(
|
|
Receiver::Message *message,
|
|
Time time,
|
|
ClassID class_id
|
|
);
|
|
~AbstractEvent();
|
|
|
|
public:
|
|
virtual void
|
|
Process();
|
|
virtual void
|
|
DumpData();
|
|
|
|
protected:
|
|
Time alarmTime;
|
|
Receiver::Message* messageToSend;
|
|
};
|
|
|
|
//##########################################################################
|
|
//############################ Event #################################
|
|
//##########################################################################
|
|
|
|
class Event:
|
|
public AbstractEvent
|
|
{
|
|
friend class GeneralEventQueue;
|
|
friend class EventQueue;
|
|
friend class Receiver;
|
|
friend class DeferredEventQueue;
|
|
friend class Entity;
|
|
friend class EventStatisticsManager;
|
|
|
|
//##########################################################################
|
|
// Node Support
|
|
//
|
|
private:
|
|
void
|
|
ReleaseLinkHandler(
|
|
Socket *socket,
|
|
Plug *plug
|
|
);
|
|
|
|
//##########################################################################
|
|
// Memory Allocation Support
|
|
//
|
|
private:
|
|
static MemoryBlock* GetAllocatedMemory();
|
|
|
|
void* operator new(size_t) { return GetAllocatedMemory()->New(); }
|
|
void operator delete(void *where) { GetAllocatedMemory()->Delete(where); }
|
|
|
|
|
|
//##########################################################################
|
|
// Event Functionality
|
|
//
|
|
private:
|
|
Event(
|
|
Receiver *target,
|
|
Receiver::Message *message,
|
|
Time time
|
|
);
|
|
~Event();
|
|
|
|
public:
|
|
void
|
|
Repost(
|
|
EventQueue *queue,
|
|
int priority,
|
|
Time new_time=Time::Null
|
|
);
|
|
|
|
void
|
|
Defer();
|
|
|
|
void
|
|
Process();
|
|
void
|
|
DumpData();
|
|
|
|
private:
|
|
SlotOf<Receiver*> targetReceiver;
|
|
};
|
|
|
|
//##########################################################################
|
|
//######################## NetworkEvent ##############################
|
|
//##########################################################################
|
|
|
|
class NetworkEvent:
|
|
public AbstractEvent
|
|
{
|
|
friend class GeneralEventQueue;
|
|
|
|
//##########################################################################
|
|
// Event Functionality
|
|
//
|
|
private:
|
|
enum EventStyle
|
|
{
|
|
SendStyle,
|
|
BroadcastStyle,
|
|
ExclusiveBroadcastStyle
|
|
};
|
|
|
|
NetworkEvent(
|
|
HostID hostID,
|
|
NetworkManager::ClientID client_ID,
|
|
EventStyle event_style,
|
|
Receiver::Message *message,
|
|
Time time
|
|
);
|
|
~NetworkEvent();
|
|
|
|
public:
|
|
void
|
|
Process();
|
|
|
|
private:
|
|
HostID
|
|
hostID;
|
|
NetworkManager::ClientID
|
|
clientID;
|
|
EventStyle
|
|
eventStyle;
|
|
};
|
|
|
|
//##########################################################################
|
|
//#################### GeneralEventQueue ############################
|
|
//##########################################################################
|
|
//
|
|
// NOTE: Do not create any static event queues! new must be used to allocate
|
|
// all event queue objects
|
|
//
|
|
class GeneralEventQueue:
|
|
public Node
|
|
{
|
|
friend class Event;
|
|
|
|
//##########################################################################
|
|
// EventQueue Allocation
|
|
//
|
|
public:
|
|
GeneralEventQueue(ClassID class_ID);
|
|
GeneralEventQueue();
|
|
~GeneralEventQueue();
|
|
|
|
static GeneralEventQueue*
|
|
Make(
|
|
int priorities,
|
|
const char* trace_name=NULL
|
|
);
|
|
|
|
protected:
|
|
int
|
|
priorityLevels;
|
|
ChainOf<AbstractEvent*>
|
|
pendingEvents;
|
|
ChainOf<AbstractEvent*>
|
|
timedEvents;
|
|
int
|
|
eventCount;
|
|
#if defined(TRACE_EVENT_COUNT)
|
|
TraceOf<int>
|
|
*eventCountTrace;
|
|
#endif
|
|
|
|
//##########################################################################
|
|
// EventQueue Functionality
|
|
//
|
|
public:
|
|
void
|
|
Post(
|
|
int priority,
|
|
Receiver *target,
|
|
Receiver::Message *message,
|
|
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
|
|
);
|
|
int
|
|
GetEventCount()
|
|
{return eventCount;}
|
|
|
|
AbstractEvent*
|
|
PeekAtNextEvent(int min_priority=0);
|
|
Logical
|
|
IsPriorityEmpty(int priority);
|
|
|
|
Logical
|
|
ProcessOneEvent(int min_priority=0);
|
|
void
|
|
ProcessAllEvents(int min_priority=0);
|
|
|
|
void
|
|
FlushAllEvents(int max_priority=-1);
|
|
void
|
|
FlushMatchingEvents(
|
|
Receiver::MessageID target_message,
|
|
int max_priority=-1
|
|
);
|
|
|
|
void
|
|
Enqueue(
|
|
int priority,
|
|
AbstractEvent *event
|
|
);
|
|
|
|
//##########################################################################
|
|
// Testing Support
|
|
//
|
|
public:
|
|
void
|
|
DumpEventQueue();
|
|
};
|
|
|
|
//##########################################################################
|
|
//######################### EventQueue ###############################
|
|
//##########################################################################
|
|
|
|
class EventQueue:
|
|
public GeneralEventQueue
|
|
{
|
|
//##########################################################################
|
|
// EventQueue Allocation
|
|
//
|
|
public:
|
|
EventQueue();
|
|
static EventQueue*
|
|
Make(
|
|
int priorities,
|
|
const char* trace_name=NULL
|
|
);
|
|
~EventQueue();
|
|
|
|
//##########################################################################
|
|
// EventQueue Posting & Processing
|
|
//
|
|
public:
|
|
Event*
|
|
PeekAtNextEvent(int min_priority=0)
|
|
{
|
|
return
|
|
(Event*)GeneralEventQueue::PeekAtNextEvent(min_priority);
|
|
}
|
|
|
|
void
|
|
ProcessMatchingEvents(
|
|
Receiver *receiver,
|
|
Receiver::MessageID message_ID=Receiver::AnyMessageID
|
|
);
|
|
|
|
//##########################################################################
|
|
// Testing Support
|
|
//
|
|
public:
|
|
static Logical
|
|
TestClass();
|
|
};
|
|
|
|
//##########################################################################
|
|
//##################### DeferredEventQueue ###########################
|
|
//##########################################################################
|
|
//
|
|
// NOTE: Do not create any static event queues! new must be used to allocate
|
|
// all event queue objects
|
|
//
|
|
class DeferredEventQueue:
|
|
public Node
|
|
{
|
|
friend class Event;
|
|
|
|
//##########################################################################
|
|
// Node Support
|
|
//
|
|
private:
|
|
void
|
|
ReleaseLinkHandler(
|
|
Socket *socket,
|
|
Plug *plug
|
|
);
|
|
|
|
//##########################################################################
|
|
// Deferred Queue Functionality
|
|
//
|
|
public:
|
|
DeferredEventQueue(Receiver *target);
|
|
~DeferredEventQueue();
|
|
|
|
void
|
|
ProcessAllEvents()
|
|
{Check(this); deferredEvents->ProcessAllEvents();}
|
|
|
|
private:
|
|
EventQueue
|
|
*deferredEvents;
|
|
SlotOf<Receiver*>
|
|
waitingReceiver;
|
|
};
|