Files
CydandClaude Fable 5 fdd9ac9d97 Initial import: Tesla Release 4.10 (Tesla:BattleTech & Tesla:Red Planet)
Archival snapshot of the Virtual World Entertainment Tesla cockpit
software, 1994-1996: MUNGA engine and L4 pod layer source (Borland
C++ 5.0), BT/RP game code, and game content (models, audio, maps,
gauges, Division renderer data). Includes third-party libraries:
Division dVS/DPL graphics, HMI SOS audio, WATTCP networking.

Files are preserved byte-for-byte (.gitattributes disables all
line-ending conversion). README.md documents the layout, target
hardware, and toolchain.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-02 13:21:58 -05:00

524 lines
12 KiB
C++

//===========================================================================//
// File: plug.cc //
// Project: MUNGA Brick: Connection Library //
// Contents: Implementation details for plugs and their iterators //
//---------------------------------------------------------------------------//
// Date Who Modification //
// -------- --- -----------------------------------------------------------//
// 09/82/94 ECH Initial coding. //
// 10/20/94 JMA Fixed style stuff, merged PLGITR.CPP, added Remove() to //
// PlugIterator //
// 10/23/94 ECH Added greater deletion safety //
// 10/28/94 JMA Made compatible with SGI CC //
// 11/02/94 ECH Restored base ReceivePlugCommand //
// 11/03/94 ECH Made compatible with BC4.0 //
// 11/03/94 JMA Made constructor/destructor out-of-line, moved the //
// ReleasePlugLink into the virtual data, made compatible //
// with GNU C++ //
// 11/08/94 ECH Made compatible with BC4.0 //
// 12/01/94 JMA Made compatible with SGI CC //
// 12/12/94 ECH Removed release handler //
// 02/16/95 ECH Removed plug commands, added node command //
//---------------------------------------------------------------------------//
// Copyright (C) 1994-1995, Virtual World Entertainment, Inc. //
// All Rights reserved worldwide //
// This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL //
//===========================================================================//
#include <munga.hpp>
#pragma hdrstop
#if !defined(PLUG_HPP)
#include <plug.hpp>
#endif
#if !defined(OBJSTRM_HPP)
#include <objstrm.hpp>
#endif
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 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;
}
}
}