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>
295 lines
7.6 KiB
C++
295 lines
7.6 KiB
C++
#pragma once
|
|
|
|
#include "node.h"
|
|
#include "srtskt.h"
|
|
#include "memblock.h"
|
|
|
|
class VChain;
|
|
class VChainIterator;
|
|
|
|
class VChainLink : public Link
|
|
{
|
|
friend class VChain;
|
|
friend class VChainIterator;
|
|
|
|
public:
|
|
~VChainLink();
|
|
Logical TestInstance() const;
|
|
|
|
protected:
|
|
VChainLink(VChain *vchain, Plug *plug);
|
|
|
|
private:
|
|
void SetupVChainLinks(VChainLink *next, VChainLink *prev);
|
|
|
|
VChainLink *next;
|
|
VChainLink *prev;
|
|
};
|
|
|
|
#define VCHAINLINK_MEMORYBLOCK_ALLOCATION (100)
|
|
|
|
template <class V> class VChainLinkOf : public VChainLink
|
|
{
|
|
public:
|
|
VChainLinkOf(VChain *vchain, Plug *plug, const V &value);
|
|
~VChainLinkOf();
|
|
|
|
void* operator new(size_t);
|
|
void operator delete(void *where);
|
|
|
|
V GetValue() { return value; }
|
|
V* GetValuePointer() { return &value; }
|
|
|
|
private:
|
|
static MemoryBlock *allocatedMemory;
|
|
static CollectionSize allocationCount;
|
|
|
|
V value;
|
|
};
|
|
|
|
template <class V> MemoryBlock* VChainLinkOf<V>::allocatedMemory = NULL;
|
|
template <class V> CollectionSize VChainLinkOf<V>::allocationCount = 0;
|
|
|
|
template <class V> VChainLinkOf<V>::VChainLinkOf(VChain *vchain, Plug *plug, const V &value)
|
|
: VChainLink(vchain, plug)
|
|
{
|
|
this->value = value;
|
|
}
|
|
|
|
template <class V> VChainLinkOf<V>::~VChainLinkOf() {}
|
|
|
|
#if 0
|
|
template <class V> void *VChainLinkOf<V>::operator new(size_t)
|
|
{
|
|
if (allocatedMemory == NULL)
|
|
allocatedMemory = new MemoryBlock(sizeof(VChainLinkOf<V>), VCHAINLINK_MEMORYBLOCK_ALLOCATION, VCHAINLINE_MEMORYBLOCK_ALLOCATION);
|
|
Check(allocatedMemory);
|
|
return allocatedMemory->New();
|
|
}
|
|
|
|
template <class V> void VChainLinkOf<V>::operator delete(void *where)
|
|
{
|
|
Check(allocatedMemory);
|
|
allocatedMemory->Delete(where);
|
|
}
|
|
#else
|
|
template <class V> void *VChainLinkOf<V>::operator new(size_t)
|
|
{
|
|
Verify(allocationCount >= 0);
|
|
if (allocationCount++ == 0)
|
|
{
|
|
allocatedMemory = new MemoryBlock(sizeof(VChainLinkOf<V>), VCHAINLINK_MEMORYBLOCK_ALLOCATION, VCHAINLINK_MEMORYBLOCK_ALLOCATION, "VChainLinkOf");
|
|
Register_Object(allocatedMemory);
|
|
}
|
|
Verify(allocationCount < INT_MAX);
|
|
Check(allocatedMemory);
|
|
return allocatedMemory->New();
|
|
}
|
|
|
|
template <class V> void VChainLinkOf<V>::operator delete(void *where)
|
|
{
|
|
Check(allocatedMemory);
|
|
allocatedMemory->Delete(where);
|
|
if (--allocationCount == 0)
|
|
{
|
|
Unregister_Object(allocatedMemory);
|
|
delete allocatedMemory;
|
|
allocatedMemory = NULL;
|
|
}
|
|
Verify(allocationCount >= 0);
|
|
}
|
|
#endif
|
|
|
|
class VChain : public SortedSocket
|
|
{
|
|
friend class VChainLink;
|
|
friend class VChainIterator;
|
|
|
|
public:
|
|
VChain(Node *node, Logical has_unique_entries);
|
|
~VChain();
|
|
|
|
Logical TestInstance() const;
|
|
static Logical TestClass();
|
|
static Logical ProfileClass();
|
|
|
|
protected:
|
|
void AddImplementation(Plug *);
|
|
void AddValueImplementation(Plug *plug, const void *value);
|
|
Plug *FindImplementation(const void *value);
|
|
|
|
private:
|
|
virtual VChainLink *MakeVChainLink(Plug *plug, const void *value);
|
|
virtual int CompareVChainLinks(VChainLink *link1, VChainLink *link2);
|
|
virtual int CompareValueToVChainLink(const void *value, VChainLink *link);
|
|
|
|
VChainLink *SearchForValue(const void *value);
|
|
|
|
VChainLink *head;
|
|
VChainLink *tail;
|
|
};
|
|
|
|
#define VCHAIN_MEMORYBLOCK_ALLOCATION (100)
|
|
|
|
template <class T, class V> class VChainOf : public VChain
|
|
{
|
|
public:
|
|
VChainOf(Node *node, Logical has_unique_entries);
|
|
~VChainOf();
|
|
|
|
void *operator new(size_t);
|
|
void operator delete(void *where);
|
|
|
|
void AddValue(T plug, const V &value) { AddValueImplementation(Cast_Object(Plug*, plug), &value); }
|
|
T Find(const V &value) { return (T)FindImplementation(&value); }
|
|
|
|
private:
|
|
VChainLink *MakeVChainLink(Plug *plug, const void *value) { return new VChainLinkOf<V>(this, plug, *(V*)value); }
|
|
int CompareVChainLinks(VChainLink *link1, VChainLink *link2);
|
|
int CompareValueToVChainLink(const void *value, VChainLink *link);
|
|
|
|
static MemoryBlock *allocatedMemory;
|
|
static CollectionSize allocationCount;
|
|
};
|
|
|
|
template <class T, class V> MemoryBlock* VChainOf<T, V>::allocatedMemory = NULL;
|
|
template <class T, class V> CollectionSize VChainOf<T, V>::allocationCount = 0;
|
|
|
|
template <class T, class V> VChainOf<T, V>::VChainOf(Node *node, Logical has_unique_entries)
|
|
: VChain(node, has_unique_entries)
|
|
{
|
|
}
|
|
|
|
template <class T, class V> VChainOf<T, V>::~VChainOf()
|
|
{
|
|
}
|
|
|
|
template <class T, class V> int VChainOf<T, V>::CompareVChainLinks(VChainLink *link1, VChainLink *link2)
|
|
{
|
|
V *ptr1 = Cast_Object(VChainLinkOf<V>*, link1)->GetValuePointer();
|
|
V *ptr2 = Cast_Object(VChainLinkOf<V>*, link2)->GetValuePointer();
|
|
|
|
Check_Pointer(ptr1);
|
|
Check_Pointer(ptr2);
|
|
|
|
if (*ptr1 == *ptr2)
|
|
return 0;
|
|
else
|
|
return ((*ptr1 > *ptr2) ? 1 : -1);
|
|
}
|
|
|
|
template <class T, class V> int VChainOf<T, V>::CompareValueToVChainLink(const void *value, VChainLink *link)
|
|
{
|
|
Check_Pointer(value);
|
|
|
|
V *ptr = Cast_Object(VChainLinkOf<V>*, link)->GetValuePointer();
|
|
Check_Pointer(ptr);
|
|
|
|
if (*(V*)value == *ptr)
|
|
return 0;
|
|
else
|
|
return (*(V*)value > *ptr) ? 1 : -1;
|
|
}
|
|
|
|
#if 0
|
|
template <class T, class V> void *VChainOf<T, V>::operator new(size_t)
|
|
{
|
|
if (allocatedMemory == NULL)
|
|
allocatedMemory = new MemoryBlock(sizeof(VChainOf<T, V>), VCHAIN_MEMORYBLOCK_ALLOCATION, VCHAIN_MEMORYBLOCK_ALLOCATION);
|
|
Check(allocatedMemory);
|
|
return allocatedMemory->New();
|
|
}
|
|
|
|
template <class T, class V> void VChainOf<T, V>::operator delete(void *where)
|
|
{
|
|
Check(allocatedMemory);
|
|
allocatedMemory->Delete(where);
|
|
}
|
|
#else
|
|
template <class T, class V> void *VChainOf<T, V>::operator new(size_t)
|
|
{
|
|
Verify(allocationCount >= 0);
|
|
if (allocationCount++ == 0)
|
|
{
|
|
allocatedMemory = new MemoryBlock(sizeof(VChainOf<T, V>), VCHAIN_MEMORYBLOCK_ALLOCATION, VCHAIN_MEMORYBLOCK_ALLOCATION, "VChainOf");
|
|
Register_Object(allocatedMemory);
|
|
}
|
|
Verify(allocationCount < INT_MAX);
|
|
Check(allocatedMemory);
|
|
return allocatedMemory->New();
|
|
}
|
|
|
|
template <class T, class V> void VChainOf<T, V>::operator delete(void *where)
|
|
{
|
|
Check(allocatedMemory);
|
|
allocatedMemory->Delete(where);
|
|
if (--allocationCount == 0)
|
|
{
|
|
Unregister_Object(allocatedMemory);
|
|
delete allocatedMemory;
|
|
allocatedMemory = NULL;
|
|
}
|
|
Verify(allocationCount >= 0);
|
|
}
|
|
#endif
|
|
|
|
class VChainIterator : public SortedIterator
|
|
{
|
|
public:
|
|
VChainIterator(VChain *vchain);
|
|
VChainIterator(const VChainIterator *iterator);
|
|
~VChainIterator();
|
|
Logical TestInstance() const;
|
|
|
|
void First();
|
|
void Last();
|
|
void Next();
|
|
void Previous();
|
|
CollectionSize GetSize();
|
|
void Remove();
|
|
|
|
protected:
|
|
void *ReadAndNextImplementation();
|
|
void *ReadAndPreviousImplementation();
|
|
void *GetCurrentImplementation();
|
|
void *GetNthImplementation(CollectionSize index);
|
|
Plug *FindImplementation(const void *value);
|
|
|
|
protected:
|
|
VChainLink *currentLink;
|
|
|
|
private:
|
|
void ReceiveMemo(IteratorMemo memo, void *content);
|
|
};
|
|
|
|
template <class T, class V> class VChainIteratorOf : public VChainIterator
|
|
{
|
|
public:
|
|
VChainIteratorOf(VChainOf<T, V> *vchain);
|
|
VChainIteratorOf(VChainOf<T, V> &vchain);
|
|
VChainIteratorOf(const VChainIteratorOf<T, V> &iterator);
|
|
~VChainIteratorOf();
|
|
|
|
T ReadAndNext() { return (T)ReadAndNextImplementation(); }
|
|
T ReadAndPrevious() { return (T)ReadAndPrevousImplementation(); }
|
|
T GetCurrent() { return (T)GetCurrentImplementation(); }
|
|
T GetNth(CollectionSize index) { return (T)GetNthImplementation(index); }
|
|
T Find(const V &value) { return (T)FindImplementation(&value); }
|
|
V GetValue() { return Cast_Object(VChainLinkOf<V>*, currentLink)->GetValue(); }
|
|
};
|
|
|
|
template <class T, class V> VChainIteratorOf<T, V>::VChainIteratorOf(VChainOf<T, V> *vchain) : VChainIterator(vchain)
|
|
{
|
|
}
|
|
|
|
template <class T, class V> VChainIteratorOf<T, V>::VChainIteratorOf(VChainOf<T, V> &vchain) : VChainIterator(&vchain)
|
|
{
|
|
}
|
|
|
|
template <class T, class V> VChainIteratorOf<T, V>::VChainIteratorOf(const VChainIteratorOf<T, V> &iterator) : VChainIterator(&iterator)
|
|
{
|
|
}
|
|
|
|
template <class T, class V> VChainIteratorOf<T, V>::~VChainIteratorOf()
|
|
{
|
|
} |