From 5a1a407ed116cc76971135fbe313b2c0a90f26af Mon Sep 17 00:00:00 2001 From: Joe DiPrima Date: Sat, 1 Aug 2026 20:11:06 -0500 Subject: [PATCH] pre-ship: resolve the new audio diagnostic gates ONCE instead of per frame RunSequence and AudioIdleWatcher::Execute run per sequence per frame, so the BT_ATTRBIND_LOG probes added while chasing #99 were calling getenv ~2700x/sec on a 15-sequence mech. Small, but this is the same path the source-pooling fix (#32) just bought 10% of frame time in, and an unset diagnostic should cost nothing. Cached in function-static flags. Pre-ship smoke (combat, 2 kills, a respawn, clean teardown): frame time 7.18 / 8.27 / 8.71 ms -- matches the post-pooling 7.79ms baseline 0 asserts, 0 access violations, 0 audio acquireFails Co-Authored-By: Claude Opus 5 (1M context) --- engine/MUNGA/AUDSEQ.cpp | 7 ++++--- engine/MUNGA/AUDWTHR.cpp | 3 ++- scratchpad/night8/preship.sh | 14 ++++++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 scratchpad/night8/preship.sh diff --git a/engine/MUNGA/AUDSEQ.cpp b/engine/MUNGA/AUDSEQ.cpp index f66f4ff..9df6360 100644 --- a/engine/MUNGA/AUDSEQ.cpp +++ b/engine/MUNGA/AUDSEQ.cpp @@ -475,7 +475,8 @@ void // // #99 probe: PER-SEQUENCE throttle. A single shared counter here hid the // alarm sequence entirely -- the busy sequences ate every slot. - if (getenv("BT_ATTRBIND_LOG") && isLooped) { if (runProbeCount < 6) + static const int s_seqDiag = (getenv("BT_ATTRBIND_LOG") != 0); // hot path: resolve once + if (s_seqDiag && isLooped) { if (runProbeCount < 6) { ++runProbeCount; DEBUG_STREAM << "[seqrun] seq=" << (void *)this << " isRunning=" << (int)isRunning @@ -494,7 +495,7 @@ void Check(audioControlEventIterator); control_event = audioControlEventIterator->GetCurrent(); - if (getenv("BT_ATTRBIND_LOG")) { static int s_nr=0; + if (s_seqDiag) { static int s_nr=0; if (control_event != NULL && !IsEventReady(control_event) && (s_nr++ % 500)==0) { AudioTime off(startTime); @@ -539,7 +540,7 @@ void // Send the controller to the connected audio component // Check(control_event); - if (getenv("BT_ATTRBIND_LOG")) { static int s_se=0; if (s_se++<60) + if (s_seqDiag) { static int s_se=0; if (s_se++<60) DEBUG_STREAM << "[seqsend] seq=" << (void *)this << " -> comp=" << (void *)audioComponentSocket.GetCurrent() << " ctl=" << (int)control_event->audioControlID diff --git a/engine/MUNGA/AUDWTHR.cpp b/engine/MUNGA/AUDWTHR.cpp index 9deb1eb..ded3eaf 100644 --- a/engine/MUNGA/AUDWTHR.cpp +++ b/engine/MUNGA/AUDWTHR.cpp @@ -112,7 +112,8 @@ void { Check(this); Check(audioComponentSocket.GetCurrent()); - if (getenv("BT_ATTRBIND_LOG")) { static int s_iw=0; if ((s_iw++ % 400)==0) + static const int s_idleDiag = (getenv("BT_ATTRBIND_LOG") != 0); // hot path: resolve once + if (s_idleDiag) { static int s_iw=0; if ((s_iw++ % 400)==0) DEBUG_STREAM << "[idlewatch] #" << s_iw << " comp=" << (void *)audioComponentSocket.GetCurrent() << std::endl; } audioComponentSocket.GetCurrent()->ReceiveControl( diff --git a/scratchpad/night8/preship.sh b/scratchpad/night8/preship.sh new file mode 100644 index 0000000..e1c73f3 --- /dev/null +++ b/scratchpad/night8/preship.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +# Pre-ship smoke: combat, no diagnostics, measure frame time + confirm no crash. +set -x +. /c/git/bt411/scratchpad/night6/bench_common.sh +cd /c/git/bt411/content || exit 1 +taskkill //F //IM btl4.exe > /dev/null 2>&1 +sleep 2 +sed "s/^map=.*/map=grass/; s/^time=.*/time=day/" MP.EGG > SHIP.EGG +rm -f preship.log +export BT_SPAWN_ENEMY=2 BT_AUTOFIRE=1 BT_GOTO=enemy BT_GOTO_STOP=40 +bt_launch preship.log SHIP.EGG 0x03 +sleep 120 +taskkill //F //IM btl4.exe > /dev/null 2>&1 +sleep 2