Imports the current Win32 source for the pod-racing game 'Red Planet', built on the MUNGA engine and its L4 (Win32/DirectX) platform layer: - MUNGA / MUNGA_L4: cross-platform engine core and Win32 backend - RP / RP_L4: Red Planet game logic and Win32 application - DivLoader, Setup1: asset loader and installer project - lib, MUNGA_L4/openal, MUNGA_L4/sos: third-party audio dependencies Removed stale Subversion metadata and added .gitignore/.gitattributes. Co-Authored-By: Claude Opus 4.8 <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()
|
|
{
|
|
} |