Files
RP411/MUNGA/PLUG.cpp
T
CydandClaude Opus 4.8 4abbf8879f Initial import of Red Planet v4.10 Win32 source
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>
2026-06-30 07:59:51 -05:00

491 lines
9.3 KiB
C++

#include "munga.h"
#pragma hdrstop
#include "plug.h"
#include "objstrm.h"
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Plug ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//#############################################################################
// Plug
//#############################################################################
//
Plug::Plug(ClassID class_id):
RegisteredClass(class_id)
{
linkHead = NULL;
}
//
//#############################################################################
// Plug
//#############################################################################
//
Plug::Plug(PlugStream *stream):
RegisteredClass(stream)
{
linkHead = NULL;
}
//
//###########################################################################
// ~Plug
//###########################################################################
//
Plug::~Plug()
{
while (linkHead != NULL)
{
Unregister_Object(linkHead);
delete(linkHead);
}
}
//
//###########################################################################
// TestInstance
//###########################################################################
//
Logical
Plug::TestInstance() const
{
if (linkHead != NULL)
{
Check(linkHead);
}
return True;
}
//
//#############################################################################
// ReceivePlugCommand
//#############################################################################
//
// Considering removal
#if 0
int
Plug::ReceivePlugCommand(
Plug::CommandID,
void*
)
{
return 0;
}
#endif
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PlugIterator ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//#############################################################################
// PlugIterator
//#############################################################################
//
PlugIterator::PlugIterator(
const Plug *plug,
RegisteredClass::ClassID class_to_iterate
)
{
Check(plug);
this->plug = plug;
classToIterate = class_to_iterate;
currentLink = plug->linkHead;
}
PlugIterator::PlugIterator(const PlugIterator &iterator)
{
Check(&iterator);
plug = iterator.plug;
classToIterate = iterator.classToIterate;
currentLink = iterator.currentLink;
}
//
//#############################################################################
// PlugIterator
//#############################################################################
//
PlugIterator::~PlugIterator()
{
}
//
//###########################################################################
// TestInstance
//###########################################################################
//
Logical
PlugIterator::TestInstance() const
{
if (currentLink != NULL)
{
Check(currentLink);
}
return True;
}
//
//###########################################################################
// First
//###########################################################################
//
void
PlugIterator::First()
{
Check(plug);
currentLink = plug->linkHead;
NextNode();
}
//
//###########################################################################
// Last
//###########################################################################
//
void
PlugIterator::Last()
{
if (currentLink == NULL)
{
Check(plug);
if ((currentLink = plug->linkHead) == NULL)
return;
}
Check(currentLink);
while(currentLink->nextLink != NULL)
{
currentLink = currentLink->nextLink;
Check(currentLink);
}
PreviousNode();
}
//
//###########################################################################
// Next
//###########################################################################
//
void
PlugIterator::Next()
{
Check(currentLink);
currentLink = currentLink->nextLink;
NextNode();
}
//
//###########################################################################
// Previous
//###########################################################################
//
void
PlugIterator::Previous()
{
Check(currentLink);
currentLink = currentLink->prevLink;
PreviousNode();
}
//
//###########################################################################
// ReadAndNextImplementation
//###########################################################################
//
void*
PlugIterator::ReadAndNextImplementation()
{
if (currentLink != NULL)
{
Node *node;
Check(currentLink);
Check(currentLink->socket);
node = currentLink->socket->GetReleaseNode();
currentLink = currentLink->nextLink;
NextNode();
return node;
}
return NULL;
}
//
//###########################################################################
// ReadAndPreviousImplementation
//###########################################################################
//
void*
PlugIterator::ReadAndPreviousImplementation()
{
if (currentLink != NULL)
{
Node *node;
Check(currentLink);
Check(currentLink->socket);
node = currentLink->socket->GetReleaseNode();
currentLink = currentLink->prevLink;
PreviousNode();
return node;
}
return NULL;
}
//
//###########################################################################
// GetCurrentImplementation
//###########################################################################
//
void*
PlugIterator::GetCurrentImplementation()
{
if (currentLink != NULL)
{
Check(currentLink);
Check(currentLink->socket);
return currentLink->socket->GetReleaseNode();
}
return NULL;
}
//
//###########################################################################
// GetSize
//###########################################################################
//
#if 0
CollectionSize
PlugIterator::GetSize()
{
Link *link;
CollectionSize count;
Check(plug);
count = 0;
for
(
link = plug->linkHead;
link != NULL;
link = link->nextLink
)
{
Check(link);
Check(link->socket);
if (link->socket->GetReleaseNode() != NULL)
count++;
}
return count;
}
#else
CollectionSize
PlugIterator::GetSize()
{
CollectionSize i = 0;
First();
while (GetCurrentImplementation() != NULL)
{
i++;
Next();
}
return i;
}
#endif
//
//###########################################################################
// GetNthImplementation
//###########################################################################
//
#if 0
void*
PlugIterator::GetNthImplementation(
CollectionSize index
)
{
Link *link;
CollectionSize count;
Check(plug);
count = 0;
for
(
link = plug->linkHead;
link != NULL;
link = link->nextLink
)
{
Check(link);
if (count == index) {
currentLink = link;
Check(currentLink);
Check(currentLink->socket);
return currentLink->socket->GetReleaseNode();
}
count++;
}
return NULL;
}
#else
void*
PlugIterator::GetNthImplementation(
CollectionSize index
)
{
CollectionSize i = 0;
void *item;
First();
while ((item = GetCurrentImplementation()) != NULL)
{
if (i == index)
return item;
Next();
i++;
}
return NULL;
}
#endif
//
//###########################################################################
// NextNode
//###########################################################################
//
void
PlugIterator::NextNode()
{
while (currentLink != NULL)
{
Node *node;
Check(currentLink);
Check(currentLink->socket);
if ((node = currentLink->socket->GetReleaseNode()) != NULL)
{
Check(node);
if (
node->GetClassID() == classToIterate ||
classToIterate == RegisteredClass::NullClassID
)
{
return;
}
}
currentLink = currentLink->nextLink;
}
return;
}
//
//###########################################################################
// PreviousNode
//###########################################################################
//
void
PlugIterator::PreviousNode()
{
while (currentLink != NULL)
{
Node *node;
Check(currentLink);
Check(currentLink->socket);
if ((node = currentLink->socket->GetReleaseNode()) != NULL)
{
Check(node);
if (
node->GetClassID() == classToIterate ||
classToIterate == RegisteredClass::NullClassID
)
{
return;
}
}
currentLink = currentLink->prevLink;
}
return;
}
//
//###########################################################################
// Remove
//###########################################################################
//
void
PlugIterator::Remove()
{
Link *old_link;
Check(currentLink);
old_link = currentLink;
currentLink = currentLink->nextLink;
Unregister_Object(old_link);
delete old_link;
}
//
//#############################################################################
// SendNodeCommand
//#############################################################################
//
int
PlugIterator::SendNodeCommand(
NodeCommandID node_command,
void *info
)
{
int ret;
Node *node;
First();
while ((node = (Node *)GetCurrentImplementation()) != NULL)
{
Check(node);
if ((ret = node->ReceiveNodeCommand(node_command, info)) != 0)
return ret;
Next();
}
return 0;
}
//
//###########################################################################
// RemoveSocket
//###########################################################################
//
void
PlugIterator::RemoveSocket(Socket *socket)
{
Link *link;
Check(socket);
Check(plug);
for
(
link = plug->linkHead;
link != NULL;
link = link->nextLink
)
{
Check(link);
if (link->GetSocket() == socket)
{
currentLink = link->nextLink;
Unregister_Object(link);
delete link;
return;
}
}
}