Files
TeslaRel410/CODE/RP/MUNGA/WATCHER.HPP
T
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

338 lines
8.8 KiB
C++

//===========================================================================//
// File: watcher.hh //
// Project: MUNGA Brick: Renderer //
// Contents: //
//---------------------------------------------------------------------------//
// Date Who Modification //
// -------- --- -----------------------------------------------------------//
// 12/14/94 ECH Initial coding. //
//---------------------------------------------------------------------------//
// Copyright (C) 1994-1995, Virtual World Entertainment, Inc. //
// All Rights reserved worldwide //
// This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL //
//===========================================================================//
#if !defined(WATCHER_HPP)
# define WATCHER_HPP
# if !defined(CMPNNT_HPP)
# include <cmpnnt.hpp>
# endif
# if !defined(SLOT_HPP)
# include <slot.hpp>
# endif
# if !defined(MEMSTRM_HPP)
# include <memstrm.hpp>
# endif
class PlugStream;
class Simulation;
class Entity;
//##########################################################################
//########################### AttributeWatcher #######################
//##########################################################################
class AttributeWatcher:
public Component
{
public:
//
//-----------------------------------------------------------------------
// Destructor
//-----------------------------------------------------------------------
//
~AttributeWatcher();
Logical
TestInstance() const;
//
//-----------------------------------------------------------------------
// DidAttributeChange
//
// Returns True if attribute has changed since the last time
// DidAttributeChange was called.
//-----------------------------------------------------------------------
//
Logical
DidAttributeChange();
protected:
//
//-----------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------
//
AttributeWatcher(
PlugStream *stream,
Entity *entity
);
//
//-----------------------------------------------------------------------
// SendNotificationOfChange
//-----------------------------------------------------------------------
//
virtual void
SendNotificationOfChange();
//
//-----------------------------------------------------------------------
// BuildFromPage
//-----------------------------------------------------------------------
//
static void
BuildFromPage(
PlugStream *stream,
NameList *name_list,
ClassID class_ID,
ObjectID object_ID
);
//
//-----------------------------------------------------------------------
// Protected data
//-----------------------------------------------------------------------
//
Simulation*
simulation;
void*
attributePointer;
Logical
attributeChanged;
Logical
sendNotificationOnChange;
};
//##########################################################################
//########################### AttributeWatcherOf #####################
//##########################################################################
template <class T> class AttributeWatcherOf:
public AttributeWatcher
{
public:
~AttributeWatcherOf();
//
//-----------------------------------------------------------------------
// Accessors
//-----------------------------------------------------------------------
//
T
GetCurrentValue()
{return currentValue;}
T*
GetCurrentPointer()
{return &currentValue;}
//
//-----------------------------------------------------------------------
// Execute
//-----------------------------------------------------------------------
//
void
Execute();
//
//-----------------------------------------------------------------------
// PrimeWatcher
//-----------------------------------------------------------------------
//
void
PrimeWatcher();
protected:
//
//-----------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------
//
AttributeWatcherOf(
PlugStream *stream,
Entity *entity
);
//
//-----------------------------------------------------------------------
// BuildFromPage
//-----------------------------------------------------------------------
//
static void
BuildFromPage(
PlugStream *stream,
NameList *name_list,
ClassID class_ID,
ObjectID object_ID
);
private:
//
//-----------------------------------------------------------------------
// InitializeCurrentValue
//-----------------------------------------------------------------------
//
void
InitializeCurrentValue();
//
//-----------------------------------------------------------------------
// GrabCurrentValue
//-----------------------------------------------------------------------
//
void
GrabCurrentValue();
//
//-----------------------------------------------------------------------
// DumpValue
//-----------------------------------------------------------------------
//
virtual void
DumpValue(const T *attribute_ptr);
//
//-----------------------------------------------------------------------
// Private data
//-----------------------------------------------------------------------
//
T
currentValue;
#if DEBUG_LEVEL>0
Logical
dumpValue;
#endif
};
//~~~~~~~~~~~~~~~~~~~~~~~~ AttributeWatcherOf templates ~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
template <class T>
AttributeWatcherOf<T>::~AttributeWatcherOf()
{
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
template <class T>
AttributeWatcherOf<T>::AttributeWatcherOf(
PlugStream *stream,
Entity *entity
):
AttributeWatcher(stream, entity)
{
Check_Pointer(this);
Logical dump_value;
MemoryStream_Read(stream, &dump_value);
#if DEBUG_LEVEL>0
dumpValue = dump_value;
if (dumpValue)
{
Tell(
"AttributeWatcherOf<T>::AttributeWatcherOf - " <<
*(T*)attributePointer <<
"\n"
);
}
#endif
InitializeCurrentValue();
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
template <class T> void
AttributeWatcherOf<T>::BuildFromPage(
PlugStream *stream,
NameList *name_list,
ClassID class_ID,
ObjectID object_ID
)
{
Check(stream);
Check(name_list);
AttributeWatcher::BuildFromPage(stream, name_list, class_ID, object_ID);
//
// Store dump_value
//
MEM_STRM_WRITE_ENTRY(*stream, name_list, Logical, dump_value);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
template <class T> void
AttributeWatcherOf<T>::PrimeWatcher()
{
Check(this);
#if DEBUG_LEVEL>0
if (dumpValue)
{
DumpValue((T*)attributePointer);
}
#endif
GrabCurrentValue();
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
template <class T> void
AttributeWatcherOf<T>::Execute()
{
Check(this);
Check_Pointer(attributePointer);
if (!(currentValue == *(T*)attributePointer))
{
#if DEBUG_LEVEL>0
if (dumpValue)
{
DumpValue((T*)attributePointer);
}
#endif
GrabCurrentValue();
}
Check_Fpu();
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
template <class T> void
AttributeWatcherOf<T>::InitializeCurrentValue()
{
Check_Pointer(attributePointer);
currentValue = *(T*)attributePointer;
Verify(currentValue == *(T*)attributePointer);
Check_Fpu();
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
template <class T> void
AttributeWatcherOf<T>::GrabCurrentValue()
{
InitializeCurrentValue();
attributeChanged = True;
if (sendNotificationOnChange)
{
SendNotificationOfChange();
}
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#if DEBUG_LEVEL>0
template <class T> void
AttributeWatcherOf<T>::DumpValue(const T *attribute_ptr)
#else
template <class T> void
AttributeWatcherOf<T>::DumpValue(const T*)
#endif
{
Check_Pointer(attribute_ptr);
Tell((void *)attribute_ptr << " = " << *attribute_ptr << "\n");
}
#endif