User: "when I start moving all the sounds fade away, no footsteps." Diagnosis chain (all empirical, BT_AUDIO_SPATIAL/BT_ATTRBIND_LOG traces): - The audio head DOES track the mech (listener-relative positioning verified while driving) -- not a spatial bug. - The idle sounds correctly STOP on leaving the standing state; the MOVING sounds never started because every POLLED audio watcher was dead: the reconstructed Mech::PerformAndWatch replaced the engine performance but dropped the ExecuteWatchers() step from the engine tail (Simulation:: PerformAndWatch = Perform -> ExecuteWatchers -> WriteSimulationUpdate). Only PUSHED StateIndicator watchers (SetState->Execute) ever fired -- which is exactly why state sounds worked but footsteps/motion-scaled audio didn't. FIX: poll ExecuteWatchers() (AreWatchersDelayed-gated) before the update write. Immediately unlocks the polled family: MissileLoaded01/LaserLoaded01 ready dings, ProgramButton01, motion scales (PlayNote 15 -> 30 per run). - FootStep (0x1e) backed REAL: was the inert attrPad (an AudioLogicalTrigger polls it -- threshold-crossing pulse per foot plant). New footStep member, pulsed by SetBodyAnimation on entering any locomotion clip 1..0x17 (runtime stride alternation MEASURED as body states 12<->13 -- the enum-name numbering does not match runtime clip ids), decayed by IntegrateMotion (~1/3 s). - Footstep volume is speed-scaled (AudioMotionScale on LocalVelocity): at standstill the transient start computes volume 0 and the renderer drops it (LowAudioVolumeThreshold) -- so footfalls are audible at real walking speed. Diagnostics kept (BT_AUDIO_SPATIAL): spatial dist/vol per source, CLIPPED/DROP/ START at the request gate, vol=0 factor breakdown, scale->0 sends, trigger notifications, watcher poll-rate probe. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
319 lines
7.5 KiB
C++
319 lines
7.5 KiB
C++
#pragma once
|
|
#include <cstdlib>
|
|
|
|
#include "cmpnnt.h"
|
|
#include "slot.h"
|
|
#include "memstrm.h"
|
|
|
|
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 ¤tValue;}
|
|
|
|
//
|
|
//-----------------------------------------------------------------------
|
|
// 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 (getenv("BT_AUDIO_SPATIAL")) { // poll-rate probe: total watcher polls + change events
|
|
static long s_polls=0; if ((++s_polls % 2000)==0)
|
|
DEBUG_STREAM << "[watchpoll] total polls=" << s_polls << "\n" << std::flush;
|
|
}
|
|
if (!(currentValue == *(T*)attributePointer))
|
|
{
|
|
if (getenv("BT_AUDIO_SPATIAL")) { static int s_chg=0; if (s_chg++<60)
|
|
DEBUG_STREAM << "[watchpoll] CHANGE attrPtr=" << (void*)attributePointer << "\n" << std::flush; }
|
|
#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");
|
|
}
|