Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
feat(milesaudio): record -wav from a mix the logic clock moves
Olcay Seygandc7c7133a983
diff --git a/GeneralsMD/Code/BuildFingerprint.manifest b/GeneralsMD/Code/BuildFingerprint.manifestindex 26409d1d0..b2fd910cc 100644--- a/GeneralsMD/Code/BuildFingerprint.manifest+++ b/GeneralsMD/Code/BuildFingerprint.manifest@@ -113,6 +113,7 @@ Data/Patch.strData/Scenarios/airbelow.txtData/Scenarios/airbelowfar.txtData/Scenarios/alphaaurora.txt+Data/Scenarios/ambulanceclean.txtData/Scenarios/aurorafog.txtData/Scenarios/avengerlasers.txtData/Scenarios/blastcheck.txt@@ -128,6 +129,8 @@ Data/Scenarios/dragonfirewall.txtData/Scenarios/dragonflame.txtData/Scenarios/driveby.txtData/Scenarios/empfriendly.txt+Data/Scenarios/exitmovebuild.txt+Data/Scenarios/exitorders.txtData/Scenarios/explreel.txtData/Scenarios/glowbase.txtData/Scenarios/glowfight.txt@@ -180,6 +183,7 @@ Data/Scenarios/nukefade.txtData/Scenarios/obeyorders.txtData/Scenarios/overlordbridge.txtData/Scenarios/overlordlong.txt+Data/Scenarios/overlordrush.txtData/Scenarios/parade.txtData/Scenarios/particles100k.txtData/Scenarios/reachshot.txt@@ -208,12 +212,14 @@ Data/Scenarios/sentryattack.txtData/Scenarios/sentrydrone.txtData/Scenarios/shiftorders.txtData/Scenarios/shiftqueue.txt+Data/Scenarios/spectre_reaim.txtData/Scenarios/squad30.txtData/Scenarios/stance.txtData/Scenarios/standinbuild.txtData/Scenarios/standinfake.txtData/Scenarios/stashbeside.txtData/Scenarios/statues.txt+Data/Scenarios/stealthintruder.txtData/Scenarios/swhole.txtData/Scenarios/swpair.txtData/Scenarios/techrespawn.txt@@ -227,6 +233,7 @@ Data/Scenarios/trailer_fourway.txtData/Scenarios/trailer_intro.txtData/Scenarios/tunnelattack.txtData/Scenarios/tunnelfull.txt+Data/Scenarios/tunnelgap.txtData/Scenarios/tunnelqueue.txtData/Scenarios/tunnelshortcut.txtData/Scenarios/tunnelsplit.txt@@ -1849,8 +1856,10 @@ Libraries/Source/WWVegas/Bink/ffmpeg/bink_ffmpeg.cppLibraries/Source/WWVegas/Bink/include/bink.hLibraries/Source/WWVegas/Miles6/.gitignoreLibraries/Source/WWVegas/Miles6/include/MSS/MSS.h+Libraries/Source/WWVegas/Miles6/include/MSS/mss_backend_names.hLibraries/Source/WWVegas/Miles6/include/MSS/mss_ex_pcm.hLibraries/Source/WWVegas/Miles6/include/Mss.h+Libraries/Source/WWVegas/Miles6/miles_dispatch.cppLibraries/Source/WWVegas/Miles6/miniaudio/miles_miniaudio.cppLibraries/Source/WWVegas/Miles6/xaudio2/miles_xaudio2.cppLibraries/Source/WWVegas/WW3D2/DX8 Rationalizations.txtdiff --git a/GeneralsMD/Code/CMakeLists.txt b/GeneralsMD/Code/CMakeLists.txtindex 11bdfdb07..b096ec85c 100644--- a/GeneralsMD/Code/CMakeLists.txt+++ b/GeneralsMD/Code/CMakeLists.txt@@ -139,7 +139,8 @@ set(VENDORED# portable includes.if(ZH_PLATFORM_WINDOWS)list(APPEND VENDORED- ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/DirectX/Include/d3d8.h)+ ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/DirectX/Include/d3d8.h+ ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/Source/miniaudio/miniaudio.c)set(VENDOR_HINT "Run Tools\\vendor.ps1 (build.bat does it for you).")else()# SDL3 and miniaudio are the platform layer everywhere but Windows (decision 3).@@ -1693,9 +1694,18 @@ add_library(binkvideo STATIC ${WW}/Bink/ffmpeg/bink_ffmpeg.cpp)target_include_directories(binkvideo PRIVATE ${WW}/Bink/include ${FFMPEG_DIR}/include)target_link_libraries(binkvideo PRIVATE ${FFMPEG_CORE} ${FFMPEG_DIR}/lib/swscale.lib xaudio2)-add_library(milesaudio STATIC ${WW}/Miles6/xaudio2/miles_xaudio2.cpp)-target_include_directories(milesaudio PRIVATE ${WW}/Miles6/include ${FFMPEG_DIR}/include)-target_link_libraries(milesaudio PRIVATE ${FFMPEG_CORE} xaudio2)+# Two Miles backends in one library: XAudio2 for what a player hears, and miniaudio's mix, the one+# off Windows, for -wav, where the logic clock has to move the mix and XAudio2 cannot be stepped.+# Each is compiled under its own prefix (MSS/mss_backend_names.h) and miles_dispatch.cpp owns the+# plain names. miniaudio opens no device here: AIL_ex_offline_mix puts it on the null backend.+add_library(miniaudio STATIC ${LIBSRC}/miniaudio/miniaudio.c)+target_include_directories(miniaudio PUBLIC ${LIBSRC}/miniaudio)+add_library(milesaudio STATIC ${WW}/Miles6/xaudio2/miles_xaudio2.cpp ${WW}/Miles6/miniaudio/miles_miniaudio.cpp+ ${WW}/Miles6/miles_dispatch.cpp)+set_source_files_properties(${WW}/Miles6/xaudio2/miles_xaudio2.cpp PROPERTIES COMPILE_DEFINITIONS MSS_BACKEND_PREFIX=XA_)+set_source_files_properties(${WW}/Miles6/miniaudio/miles_miniaudio.cpp PROPERTIES COMPILE_DEFINITIONS MSS_BACKEND_PREFIX=MA_)+target_include_directories(milesaudio PRIVATE ${WW}/Miles6/include ${FFMPEG_DIR}/include ${WW}/WWLib)+target_link_libraries(milesaudio PRIVATE ${FFMPEG_CORE} xaudio2 miniaudio)add_library(gameenginedevice STATIC ${GAMEENGINEDEVICE_SOURCES})diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cppindex dbc341956..a0d51104e 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp@@ -2725,8 +2725,8 @@ void GameEngine::update( void )of an unattended run. */fastMode = fastMode || TheGlobalData->m_headless;- /* -turbo: the same for a run that draws, unless a network or a sound recording owns the clock.- The five seconds before a -screenshot run at the real rate. Taken straight out of+ /* -turbo: the same for a run that draws, unless a network owns the clock. A -wav recording does+ not: its mix moves with the logic frames, not the wall clock (updateSoundCapture). The five seconds before a -screenshot run at the real rate. Taken straight out offast-forward, a shot differed from its own repeat on 5.6% of the pixels; settled first, on0.01%, where two paced runs differ on 0.1%. */const Int TURBO_SETTLE_FRAMES = 150;@@ -2734,8 +2734,7 @@ void GameEngine::update( void )const Bool turboSettling = TheGlobalData->m_screenShotFrame > 0&& turboFrame + TURBO_SETTLE_FRAMES >= TheGlobalData->m_screenShotFrame&& turboFrame <= TheGlobalData->m_screenShotFrame;- fastMode = fastMode || ( TheGlobalData->m_turbo && !turboSettling && TheNetwork == NULL- && TheGlobalData->m_wavEndFrame == 0 );+ fastMode = fastMode || ( TheGlobalData->m_turbo && !turboSettling && TheNetwork == NULL );/* -video: one logic frame a pass across the range being recorded, so the draw in front of eachlogic frame is the one picture of it. Paced by the wall clock, a pass that fell behind woulddiff --git a/GeneralsMD/Code/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp b/GeneralsMD/Code/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cppindex 60096cf4f..37eed13f2 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp@@ -523,38 +523,25 @@ void MilesAudioManager::reset()//-------------------------------------------------------------------------------------------------/** -wav <from> <to> [name]: record the finished mix over a range of logic frames.*- * The mixer plays at the speed a person hears, and -video saves frames at the speed the disk takes- * them, so one run cannot make both halves of a film. This is the other run: the same seed and the- * same shot list play the same match, and what comes out lines up with the picture as long as the- * run held 30 logic frames a second. That is the one thing worth checking, so the closing line says- * how much sound was recorded against how much the picture is going to be.- *- * A run that is not pacing itself cannot be recorded from at all, which is why -headless and a- * lifted frame limit are refused here rather than producing something quietly wrong. */+ * A -wav run opens no audio device (openDevice): the mix is moved by the logic clock, here, by+ * exactly 1/30 of a second of sound per logic frame, however long the frame took on the wall clock.+ * So the file is as long as the frames it spans and lines up with the picture of the same frames,+ * in a run that plays at the speed a person hears, in a -directorrecord run that crawls, and on a+ * machine with no speakers. A sound asked for during frame N starts N/30 seconds in, because the+ * requests are only played after this has mixed up to N. Nothing is heard while it runs. */static void updateSoundCapture( void ){static Bool recording = FALSE;static Bool finished = FALSE;-#if defined(_WIN32)- static __int64 startTicks = 0;-#else- static Int64 startTicks = 0;-#endif-- if (TheGlobalData->m_wavEndFrame <= 0 || finished)- return;- if (TheGameLogic == NULL || !TheGameLogic->isInGame() || TheGameLogic->isInShellGame())- return;- if (TheGlobalData->m_headless || !TheGlobalData->m_useFpsLimit)- {- finished = TRUE;- DEBUG_LOG(("AUDIO: -wav needs a run that plays at the speed a person hears it, so -headless "- "and -noFPSLimit record nothing\n"));+ if (TheGlobalData->m_wavEndFrame <= 0 || TheGameLogic == NULL)return;- }const UnsignedInt frame = TheGameLogic->getFrame();+ AIL_ex_mix_to_frame((S32)frame);++ if (finished || !TheGameLogic->isInGame() || TheGameLogic->isInShellGame())+ return;if (frame < (UnsignedInt)TheGlobalData->m_wavStartFrame)return;@@ -578,7 +565,6 @@ static void updateSoundCapture( void )}recording = TRUE;- startTicks = Clock_Ticks();DEBUG_LOG(("AUDIO: recording logic frames %d to %d into %s\n",TheGlobalData->m_wavStartFrame, TheGlobalData->m_wavEndFrame, pathname));return;@@ -590,19 +576,14 @@ static void updateSoundCapture( void )finished = TRUE;AIL_ex_stop_capture();-#if defined(_WIN32)- __int64 nowTicks = 0;- __int64 ticksPerSecond = 0;-#else- Int64 nowTicks = 0;- Int64 ticksPerSecond = 0;-#endif- nowTicks = Clock_Ticks();- ticksPerSecond = Clock_Ticks_Per_Second();- const Real recordedSeconds = (Real)(nowTicks - startTicks) / (Real)ticksPerSecond;- const Real pictureSeconds = (Real)(frame - TheGlobalData->m_wavStartFrame) / LOGICFRAMES_PER_SECONDS_REAL;- DEBUG_LOG(("AUDIO: recorded %.2f seconds of sound for %.2f seconds of picture, %.2f adrift\n",- recordedSeconds, pictureSeconds, recordedSeconds - pictureSeconds));+ // The file's own length, counted in samples written, against the frames the capture spanned.+ S32 samples = 0;+ S32 rate = 0;+ AIL_ex_capture_length(&samples, &rate);+ const double recordedSeconds = rate > 0 ? (double)samples / (double)rate : 0.0;+ const double pictureSeconds = (double)(frame - TheGlobalData->m_wavStartFrame) / LOGICFRAMES_PER_SECONDS_REAL;+ DEBUG_LOG(("AUDIO: recorded %.3f seconds of sound (%d samples at %d Hz) for %.3f seconds of picture, "+ "%.3f adrift\n", recordedSeconds, (Int)samples, (Int)rate, pictureSeconds, recordedSeconds - pictureSeconds));}//-------------------------------------------------------------------------------------------------@@ -1697,6 +1678,10 @@ void MilesAudioManager::openDevice( void )}AIL_set_redist_directory("MSS\\");+ // -wav records from a mix the logic clock moves (updateSoundCapture), so the run plays no sound+ // and needs no audio device.+ if (TheGlobalData->m_wavEndFrame > 0)+ AIL_ex_offline_mix();AIL_startup();Int retval = 0;diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/.gitignore b/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/.gitignoreindex 7bb6d5a25..2c4a2296d 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/.gitignore+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/.gitignore@@ -14,6 +14,10 @@!include/MSS/MSS.h# mss_ex_pcm.h: miniaudio's pushed-PCM voice for the movies (V1), declared beside it.!include/MSS/mss_ex_pcm.h+# Windows links both backends: each under its own prefix (mss_backend_names.h), miles_dispatch.cpp+# owning the plain names.+!include/MSS/mss_backend_names.h+!miles_dispatch.cpp!xaudio2/!xaudio2/miles_xaudio2.cpp!miniaudio/diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/include/MSS/MSS.h b/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/include/MSS/MSS.hindex 82f844f5a..03b9e65ce 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/include/MSS/MSS.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/include/MSS/MSS.h@@ -23,6 +23,12 @@#ifndef MSS_H#define MSS_H+/* Windows links both backends into one exe, XAudio2 for play and miniaudio for a -wav run, each+ compiled under its own prefix; miles_dispatch.cpp owns the plain names and picks one. */+#ifdef MSS_BACKEND_PREFIX+#include "mss_backend_names.h"+#endif+/* The real Mss.H pulls in the Windows multimedia headers; WWAudio relies on* that for LPWAVEFORMAT in its Miles-facing signatures. */#if defined(_WIN32)@@ -263,6 +269,15 @@ void AILCALL AIL_quick_set_volume(HAUDIO audio, F32 volume, F32 extravol);S32 AILCALL AIL_ex_start_capture(const char *pathname);void AILCALL AIL_ex_stop_capture(void);+/* The logic clock's mix, for -wav. AIL_ex_offline_mix, called before AIL_startup, opens no audio+ device: the mix moves only when AIL_ex_mix_to_frame asks it to, logicFrame * rate / 30 frames from+ the start, so a capture holds exactly the sound of the logic frames it spans however fast or slow+ the run went. Nothing is heard meanwhile. AIL_ex_capture_length reports what the last finished+ capture wrote, in frames at its rate; the XAudio2 backend does not count and says zero. */+void AILCALL AIL_ex_offline_mix(void);+void AILCALL AIL_ex_mix_to_frame(S32 logicFrame);+void AILCALL AIL_ex_capture_length(S32 *frames, S32 *rate);+/* ---- distance falloff -------------------------------------------------- *//* Not Miles. Nonzero makes every 3D sample fall off in a straight line from min_dist to max_distinstead of Miles' min_dist / distance; MilesAudioManager passes AudioSettings.ini'sdiff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/include/MSS/mss_backend_names.h b/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/include/MSS/mss_backend_names.hnew file mode 100644index 000000000..5ff7c4a47--- /dev/null+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/include/MSS/mss_backend_names.h@@ -0,0 +1,90 @@+/*+ * Every MSS.h entry point under the prefix MSS_BACKEND_PREFIX names, for a backend compiled beside+ * another in one exe (Windows: XA_ for miles_xaudio2.cpp, MA_ for miles_miniaudio.cpp).+ * miles_dispatch.cpp defines the plain names and forwards each to one of the two. A function added+ * to MSS.h goes here and into mss_api.inl, or the second backend's copy collides at link.+ */++#ifndef MSS_BACKEND_NAMES_H+#define MSS_BACKEND_NAMES_H++#define MSS_BACKEND_JOIN2(a, b) a##b+#define MSS_BACKEND_JOIN(a, b) MSS_BACKEND_JOIN2(a, b)+#define MSS_BACKEND_NAME(name) MSS_BACKEND_JOIN(MSS_BACKEND_PREFIX, name)++#define AIL_startup MSS_BACKEND_NAME(AIL_startup)+#define AIL_shutdown MSS_BACKEND_NAME(AIL_shutdown)+#define AIL_quick_startup MSS_BACKEND_NAME(AIL_quick_startup)+#define AIL_quick_handles MSS_BACKEND_NAME(AIL_quick_handles)+#define AIL_set_redist_directory MSS_BACKEND_NAME(AIL_set_redist_directory)+#define AIL_lock MSS_BACKEND_NAME(AIL_lock)+#define AIL_unlock MSS_BACKEND_NAME(AIL_unlock)+#define AIL_get_timer_highest_delay MSS_BACKEND_NAME(AIL_get_timer_highest_delay)+#define AIL_set_file_callbacks MSS_BACKEND_NAME(AIL_set_file_callbacks)+#define AIL_enumerate_3D_providers MSS_BACKEND_NAME(AIL_enumerate_3D_providers)+#define AIL_open_3D_provider MSS_BACKEND_NAME(AIL_open_3D_provider)+#define AIL_close_3D_provider MSS_BACKEND_NAME(AIL_close_3D_provider)+#define AIL_enumerate_filters MSS_BACKEND_NAME(AIL_enumerate_filters)+#define AIL_set_3D_speaker_type MSS_BACKEND_NAME(AIL_set_3D_speaker_type)+#define AIL_set_sample_processor MSS_BACKEND_NAME(AIL_set_sample_processor)+#define AIL_set_filter_sample_preference MSS_BACKEND_NAME(AIL_set_filter_sample_preference)+#define AIL_allocate_sample_handle MSS_BACKEND_NAME(AIL_allocate_sample_handle)+#define AIL_release_sample_handle MSS_BACKEND_NAME(AIL_release_sample_handle)+#define AIL_init_sample MSS_BACKEND_NAME(AIL_init_sample)+#define AIL_set_sample_file MSS_BACKEND_NAME(AIL_set_sample_file)+#define AIL_start_sample MSS_BACKEND_NAME(AIL_start_sample)+#define AIL_stop_sample MSS_BACKEND_NAME(AIL_stop_sample)+#define AIL_resume_sample MSS_BACKEND_NAME(AIL_resume_sample)+#define AIL_end_sample MSS_BACKEND_NAME(AIL_end_sample)+#define AIL_set_sample_volume_pan MSS_BACKEND_NAME(AIL_set_sample_volume_pan)+#define AIL_sample_volume_pan MSS_BACKEND_NAME(AIL_sample_volume_pan)+#define AIL_set_sample_playback_rate MSS_BACKEND_NAME(AIL_set_sample_playback_rate)+#define AIL_sample_playback_rate MSS_BACKEND_NAME(AIL_sample_playback_rate)+#define AIL_set_sample_user_data MSS_BACKEND_NAME(AIL_set_sample_user_data)+#define AIL_sample_user_data MSS_BACKEND_NAME(AIL_sample_user_data)+#define AIL_register_EOS_callback MSS_BACKEND_NAME(AIL_register_EOS_callback)+#define AIL_get_DirectSound_info MSS_BACKEND_NAME(AIL_get_DirectSound_info)+#define AIL_allocate_3D_sample_handle MSS_BACKEND_NAME(AIL_allocate_3D_sample_handle)+#define AIL_release_3D_sample_handle MSS_BACKEND_NAME(AIL_release_3D_sample_handle)+#define AIL_set_3D_sample_file MSS_BACKEND_NAME(AIL_set_3D_sample_file)+#define AIL_start_3D_sample MSS_BACKEND_NAME(AIL_start_3D_sample)+#define AIL_stop_3D_sample MSS_BACKEND_NAME(AIL_stop_3D_sample)+#define AIL_resume_3D_sample MSS_BACKEND_NAME(AIL_resume_3D_sample)+#define AIL_end_3D_sample MSS_BACKEND_NAME(AIL_end_3D_sample)+#define AIL_set_3D_sample_volume MSS_BACKEND_NAME(AIL_set_3D_sample_volume)+#define AIL_set_3D_sample_playback_rate MSS_BACKEND_NAME(AIL_set_3D_sample_playback_rate)+#define AIL_3D_sample_playback_rate MSS_BACKEND_NAME(AIL_3D_sample_playback_rate)+#define AIL_set_3D_sample_distances MSS_BACKEND_NAME(AIL_set_3D_sample_distances)+#define AIL_set_3D_sample_occlusion MSS_BACKEND_NAME(AIL_set_3D_sample_occlusion)+#define AIL_set_3D_user_data MSS_BACKEND_NAME(AIL_set_3D_user_data)+#define AIL_3D_user_data MSS_BACKEND_NAME(AIL_3D_user_data)+#define AIL_register_3D_EOS_callback MSS_BACKEND_NAME(AIL_register_3D_EOS_callback)+#define AIL_open_3D_listener MSS_BACKEND_NAME(AIL_open_3D_listener)+#define AIL_close_3D_listener MSS_BACKEND_NAME(AIL_close_3D_listener)+#define AIL_set_3D_position MSS_BACKEND_NAME(AIL_set_3D_position)+#define AIL_set_3D_orientation MSS_BACKEND_NAME(AIL_set_3D_orientation)+#define AIL_set_3D_velocity_vector MSS_BACKEND_NAME(AIL_set_3D_velocity_vector)+#define AIL_open_stream MSS_BACKEND_NAME(AIL_open_stream)+#define AIL_close_stream MSS_BACKEND_NAME(AIL_close_stream)+#define AIL_start_stream MSS_BACKEND_NAME(AIL_start_stream)+#define AIL_pause_stream MSS_BACKEND_NAME(AIL_pause_stream)+#define AIL_set_stream_loop_count MSS_BACKEND_NAME(AIL_set_stream_loop_count)+#define AIL_stream_loop_count MSS_BACKEND_NAME(AIL_stream_loop_count)+#define AIL_set_stream_volume_pan MSS_BACKEND_NAME(AIL_set_stream_volume_pan)+#define AIL_stream_volume_pan MSS_BACKEND_NAME(AIL_stream_volume_pan)+#define AIL_stream_ms_position MSS_BACKEND_NAME(AIL_stream_ms_position)+#define AIL_register_stream_callback MSS_BACKEND_NAME(AIL_register_stream_callback)+#define AIL_quick_load_and_play MSS_BACKEND_NAME(AIL_quick_load_and_play)+#define AIL_quick_unload MSS_BACKEND_NAME(AIL_quick_unload)+#define AIL_quick_set_volume MSS_BACKEND_NAME(AIL_quick_set_volume)+#define AIL_ex_start_capture MSS_BACKEND_NAME(AIL_ex_start_capture)+#define AIL_ex_stop_capture MSS_BACKEND_NAME(AIL_ex_stop_capture)+#define AIL_ex_offline_mix MSS_BACKEND_NAME(AIL_ex_offline_mix)+#define AIL_ex_mix_to_frame MSS_BACKEND_NAME(AIL_ex_mix_to_frame)+#define AIL_ex_capture_length MSS_BACKEND_NAME(AIL_ex_capture_length)+#define AIL_ex_set_3D_linear_falloff MSS_BACKEND_NAME(AIL_ex_set_3D_linear_falloff)+#define AIL_WAV_info MSS_BACKEND_NAME(AIL_WAV_info)+#define AIL_decompress_ADPCM MSS_BACKEND_NAME(AIL_decompress_ADPCM)+#define AIL_mem_free_lock MSS_BACKEND_NAME(AIL_mem_free_lock)++#endif /* MSS_BACKEND_NAMES_H */diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/include/MSS/mss_ex_pcm.h b/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/include/MSS/mss_ex_pcm.hindex 12a565ec0..110072c4b 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/include/MSS/mss_ex_pcm.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/include/MSS/mss_ex_pcm.h@@ -35,7 +35,9 @@#ifndef MSS_EX_PCM_H#define MSS_EX_PCM_H-#if defined(_WIN32)+/* Windows builds miles_miniaudio.cpp too, for -wav (miles_dispatch.cpp), and it defines these under+ their plain names; the movies there keep their own XAudio2 engine and call none of them. */+#if defined(_WIN32) && !defined(MSS_BACKEND_PREFIX)#error "mss_ex_pcm.h is miles_miniaudio's; on Windows the movies keep their own XAudio2 engine"#endifdiff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/miles_dispatch.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/miles_dispatch.cppnew file mode 100644index 000000000..f8694afc7--- /dev/null+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/miles_dispatch.cpp@@ -0,0 +1,127 @@+/*+ * The Miles surface's plain names on Windows, each forwarding to one of two backends linked beside+ * each other: miles_xaudio2.cpp (XA_) for everything a player hears, miles_miniaudio.cpp (MA_) for a+ * -wav run. XAudio2 mixes on the device's clock and has no way to be stepped, so a capture made+ * through it is as long as the device played, glitches and dropped passes and all, and needs a+ * device to exist. miniaudio's mix is this port's own code, so the logic clock can pull it.+ *+ * The choice is made once, before AIL_startup: AIL_ex_offline_mix selects miniaudio and nothing+ * else does. Off Windows miniaudio is the only backend and this file is not built. Bink's movie+ * sound opens its own XAudio2 on Windows and goes through neither.+ */++#include "MSS/MSS.h"++#define MSS_API_LIST \+ MSS_API(S32, AIL_startup, (void), ()) \+ MSS_API(void, AIL_shutdown, (void), ()) \+ MSS_API(S32, AIL_quick_startup, (S32 use_digital, S32 use_MIDI, U32 output_rate, S32 output_bits, S32 output_channels), (use_digital, use_MIDI, output_rate, output_bits, output_channels)) \+ MSS_API(void, AIL_quick_handles, (HDIGDRIVER *pdig, HMDIDRIVER *pmdi, HDLSDEVICE *pdls), (pdig, pmdi, pdls)) \+ MSS_API(char *, AIL_set_redist_directory, (const char *dir), (dir)) \+ MSS_API(void, AIL_lock, (void), ()) \+ MSS_API(void, AIL_unlock, (void), ()) \+ MSS_API(S32, AIL_get_timer_highest_delay, (void), ()) \+ MSS_API(void, AIL_set_file_callbacks, (AILFILEOPENCB opencb, AILFILECLOSECB closecb, AILFILESEEKCB seekcb, AILFILEREADCB readcb), (opencb, closecb, seekcb, readcb)) \+ MSS_API(S32, AIL_enumerate_3D_providers, (HPROENUM *next, HPROVIDER *dest, char **name), (next, dest, name)) \+ MSS_API(S32, AIL_open_3D_provider, (HPROVIDER lib), (lib)) \+ MSS_API(void, AIL_close_3D_provider, (HPROVIDER lib), (lib)) \+ MSS_API(S32, AIL_enumerate_filters, (HPROENUM *next, HPROVIDER *dest, char **name), (next, dest, name)) \+ MSS_API(void, AIL_set_3D_speaker_type, (HPROVIDER lib, S32 speaker_type), (lib, speaker_type)) \+ MSS_API(HPROVIDER, AIL_set_sample_processor, (HSAMPLE sample, S32 pipeline_stage, HPROVIDER provider), (sample, pipeline_stage, provider)) \+ MSS_API(void, AIL_set_filter_sample_preference, (HSAMPLE sample, const char *name, const void *val), (sample, name, val)) \+ MSS_API(HSAMPLE, AIL_allocate_sample_handle, (HDIGDRIVER dig), (dig)) \+ MSS_API(void, AIL_release_sample_handle, (HSAMPLE sample), (sample)) \+ MSS_API(void, AIL_init_sample, (HSAMPLE sample), (sample)) \+ MSS_API(S32, AIL_set_sample_file, (HSAMPLE sample, const void *file_image, S32 block), (sample, file_image, block)) \+ MSS_API(void, AIL_start_sample, (HSAMPLE sample), (sample)) \+ MSS_API(void, AIL_stop_sample, (HSAMPLE sample), (sample)) \+ MSS_API(void, AIL_resume_sample, (HSAMPLE sample), (sample)) \+ MSS_API(void, AIL_end_sample, (HSAMPLE sample), (sample)) \+ MSS_API(void, AIL_set_sample_volume_pan, (HSAMPLE sample, F32 volume, F32 pan), (sample, volume, pan)) \+ MSS_API(void, AIL_sample_volume_pan, (HSAMPLE sample, F32 *volume, F32 *pan), (sample, volume, pan)) \+ MSS_API(void, AIL_set_sample_playback_rate, (HSAMPLE sample, S32 playback_rate), (sample, playback_rate)) \+ MSS_API(S32, AIL_sample_playback_rate, (HSAMPLE sample), (sample)) \+ MSS_API(void, AIL_set_sample_user_data, (HSAMPLE sample, U32 index, S32 value), (sample, index, value)) \+ MSS_API(S32, AIL_sample_user_data, (HSAMPLE sample, U32 index), (sample, index)) \+ MSS_API(AILSAMPLECB, AIL_register_EOS_callback, (HSAMPLE sample, AILSAMPLECB EOS), (sample, EOS)) \+ MSS_API(void, AIL_get_DirectSound_info, (HSAMPLE sample, AILLPDIRECTSOUND *lplpDS, AILLPDIRECTSOUNDBUFFER *lplpDSB), (sample, lplpDS, lplpDSB)) \+ MSS_API(H3DSAMPLE, AIL_allocate_3D_sample_handle, (HPROVIDER lib), (lib)) \+ MSS_API(void, AIL_release_3D_sample_handle, (H3DSAMPLE sample), (sample)) \+ MSS_API(S32, AIL_set_3D_sample_file, (H3DSAMPLE sample, const void *file_image), (sample, file_image)) \+ MSS_API(void, AIL_start_3D_sample, (H3DSAMPLE sample), (sample)) \+ MSS_API(void, AIL_stop_3D_sample, (H3DSAMPLE sample), (sample)) \+ MSS_API(void, AIL_resume_3D_sample, (H3DSAMPLE sample), (sample)) \+ MSS_API(void, AIL_end_3D_sample, (H3DSAMPLE sample), (sample)) \+ MSS_API(void, AIL_set_3D_sample_volume, (H3DSAMPLE sample, F32 volume), (sample, volume)) \+ MSS_API(void, AIL_set_3D_sample_playback_rate, (H3DSAMPLE sample, S32 playback_rate), (sample, playback_rate)) \+ MSS_API(S32, AIL_3D_sample_playback_rate, (H3DSAMPLE sample), (sample)) \+ MSS_API(void, AIL_set_3D_sample_distances, (H3DSAMPLE sample, F32 max_dist, F32 min_dist), (sample, max_dist, min_dist)) \+ MSS_API(void, AIL_set_3D_sample_occlusion, (H3DSAMPLE sample, F32 occlusion), (sample, occlusion)) \+ MSS_API(void, AIL_set_3D_user_data, (H3DPOBJECT obj, U32 index, S32 value), (obj, index, value)) \+ MSS_API(S32, AIL_3D_user_data, (H3DPOBJECT obj, U32 index), (obj, index)) \+ MSS_API(AIL3DSAMPLECB, AIL_register_3D_EOS_callback, (H3DSAMPLE sample, AIL3DSAMPLECB EOS), (sample, EOS)) \+ MSS_API(H3DPOBJECT, AIL_open_3D_listener, (HPROVIDER lib), (lib)) \+ MSS_API(void, AIL_close_3D_listener, (H3DPOBJECT listener), (listener)) \+ MSS_API(void, AIL_set_3D_position, (H3DPOBJECT obj, F32 X, F32 Y, F32 Z), (obj, X, Y, Z)) \+ MSS_API(void, AIL_set_3D_orientation, (H3DPOBJECT obj, F32 X_face, F32 Y_face, F32 Z_face, F32 X_up, F32 Y_up, F32 Z_up), (obj, X_face, Y_face, Z_face, X_up, Y_up, Z_up)) \+ MSS_API(void, AIL_set_3D_velocity_vector, (H3DPOBJECT obj, F32 dX, F32 dY, F32 dZ), (obj, dX, dY, dZ)) \+ MSS_API(HSTREAM, AIL_open_stream, (HDIGDRIVER dig, const char *filename, S32 stream_mem), (dig, filename, stream_mem)) \+ MSS_API(void, AIL_close_stream, (HSTREAM stream), (stream)) \+ MSS_API(void, AIL_start_stream, (HSTREAM stream), (stream)) \+ MSS_API(void, AIL_pause_stream, (HSTREAM stream, S32 onoff), (stream, onoff)) \+ MSS_API(void, AIL_set_stream_loop_count, (HSTREAM stream, S32 count), (stream, count)) \+ MSS_API(S32, AIL_stream_loop_count, (HSTREAM stream), (stream)) \+ MSS_API(void, AIL_set_stream_volume_pan, (HSTREAM stream, F32 volume, F32 pan), (stream, volume, pan)) \+ MSS_API(void, AIL_stream_volume_pan, (HSTREAM stream, F32 *volume, F32 *pan), (stream, volume, pan)) \+ MSS_API(void, AIL_stream_ms_position, (HSTREAM stream, S32 *total_milliseconds, S32 *current_milliseconds), (stream, total_milliseconds, current_milliseconds)) \+ MSS_API(AILSTREAMCB, AIL_register_stream_callback, (HSTREAM stream, AILSTREAMCB callback), (stream, callback)) \+ MSS_API(HAUDIO, AIL_quick_load_and_play, (const char *filename, U32 loop_count, S32 wait_request), (filename, loop_count, wait_request)) \+ MSS_API(void, AIL_quick_unload, (HAUDIO audio), (audio)) \+ MSS_API(void, AIL_quick_set_volume, (HAUDIO audio, F32 volume, F32 extravol), (audio, volume, extravol)) \+ MSS_API(S32, AIL_ex_start_capture, (const char *pathname), (pathname)) \+ MSS_API(void, AIL_ex_stop_capture, (void), ()) \+ MSS_API(void, AIL_ex_set_3D_linear_falloff, (S32 linear), (linear)) \+ MSS_API(S32, AIL_WAV_info, (const void *data, AILSOUNDINFO *info), (data, info)) \+ MSS_API(S32, AIL_decompress_ADPCM, (const AILSOUNDINFO *info, void **outdata, U32 *outsize), (info, outdata, outsize)) \+ MSS_API(void, AIL_mem_free_lock, (void *ptr), (ptr))++extern "C" {++#define MSS_API(ret, name, params, args) ret AILCALL XA_##name params; ret AILCALL MA_##name params;+MSS_API_LIST+#undef MSS_API++void AILCALL MA_AIL_ex_offline_mix(void);+void AILCALL MA_AIL_ex_mix_to_frame(S32 logicFrame);+void AILCALL MA_AIL_ex_capture_length(S32 *frames, S32 *rate);++static bool g_offline = false;++#define MSS_API(ret, name, params, args) ret AILCALL name params { return g_offline ? MA_##name args : XA_##name args; }+MSS_API_LIST+#undef MSS_API++void AILCALL AIL_ex_offline_mix(void)+{+ g_offline = true;+ MA_AIL_ex_offline_mix();+}++void AILCALL AIL_ex_mix_to_frame(S32 logicFrame)+{+ if (g_offline) {+ MA_AIL_ex_mix_to_frame(logicFrame);+ }+}++void AILCALL AIL_ex_capture_length(S32 *frames, S32 *rate)+{+ if (g_offline) {+ MA_AIL_ex_capture_length(frames, rate);+ return;+ }+ *frames = 0;+ *rate = 0;+}++} // extern "C"diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/miniaudio/miles_miniaudio.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/miniaudio/miles_miniaudio.cppindex c046b3779..1499bb7e5 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/miniaudio/miles_miniaudio.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/miniaudio/miles_miniaudio.cpp@@ -507,7 +507,7 @@ struct Capturestruct Engine{Engine() : contextReady(false), deviceReady(false), serviceRunning(false), started(false), deviceRate(0),- capture(NULL) {}+ capture(NULL), offline(false), mixAnchored(false), mixedFrames(0), capturedFrames(0), capturedRate(0) {}// A process can end without AIL_shutdown - a test, or a game that exits in a hurry - and a// std::thread still joinable at destruction calls std::terminate. The Windows build's service@@ -543,6 +543,16 @@ struct Enginebool started;unsigned deviceRate;Capture *capture;++ // AIL_ex_offline_mix: the device is opened on the null backend and never started, and the mix+ // moves only through AIL_ex_mix_to_frame. mixedFrames is where the logic clock has it, in output+ // frames from logic frame zero. Game thread only.+ bool offline;+ bool mixAnchored;+ long long mixedFrames;+ // What the last finished capture wrote, for AIL_ex_capture_length.+ unsigned capturedFrames;+ unsigned capturedRate;};Engine g_engine;@@ -1084,7 +1094,7 @@ void dataCallback(ma_device *, void *output, const void *, ma_uint32 frameCount)bool useNullBackend(){const char *backend = getenv("ZH_AUDIO_BACKEND");- return backend != NULL && strcmp(backend, "null") == 0;+ return g_engine.offline || (backend != NULL && strcmp(backend, "null") == 0);}} // namespace@@ -1137,7 +1147,7 @@ S32 AILCALL AIL_quick_startup(S32 use_digital, S32, U32, S32, S32)}g_engine.deviceRate = g_engine.device.sampleRate;g_engine.deviceReady = true;- if (ma_device_start(&g_engine.device) != MA_SUCCESS) {+ if (!g_engine.offline && ma_device_start(&g_engine.device) != MA_SUCCESS) {ma_device_uninit(&g_engine.device);ma_context_uninit(&g_engine.context);g_engine.deviceReady = false;@@ -1296,10 +1306,49 @@ void AILCALL AIL_ex_stop_capture(void)if (capture != NULL) {writeCaptureSizes(capture);fclose(capture->file);+ g_engine.capturedFrames = capture->dataBytes / (capture->channels * sizeof(short));+ g_engine.capturedRate = capture->samplesPerSecond;delete capture;}}+void AILCALL AIL_ex_offline_mix(void)+{+ g_engine.offline = true;+}++// The logic runs 30 frames a second of game time (LOGICFRAMES_PER_SECOND), whatever the wall clock+// does. Each target is computed from the absolute frame, so the remainders of a rate 30 does not+// divide never add up: frames a to b always mix (b - a) * rate / 30, give or take one sample.+void AILCALL AIL_ex_mix_to_frame(S32 logicFrame)+{+ const long long LOGIC_FRAMES_PER_SECOND = 30;+ if (!g_engine.offline || !g_engine.deviceReady) {+ return;+ }+ const long long target = (long long)logicFrame * g_engine.deviceRate / LOGIC_FRAMES_PER_SECOND;+ // The first call, and a logic clock that went back (a new match starts at frame 0), place the mix+ // rather than make it play the difference.+ if (!g_engine.mixAnchored || target < g_engine.mixedFrames) {+ g_engine.mixAnchored = true;+ g_engine.mixedFrames = target;+ return;+ }+ float out[MIX_CHUNK_FRAMES * OUTPUT_CHANNELS];+ while (g_engine.mixedFrames < target) {+ const unsigned frames = target - g_engine.mixedFrames < MIX_CHUNK_FRAMES+ ? (unsigned)(target - g_engine.mixedFrames) : MIX_CHUNK_FRAMES;+ dataCallback(&g_engine.device, out, NULL, frames);+ g_engine.mixedFrames += frames;+ }+}++void AILCALL AIL_ex_capture_length(S32 *frames, S32 *rate)+{+ *frames = (S32)g_engine.capturedFrames;+ *rate = (S32)g_engine.capturedRate;+}+void AILCALL AIL_shutdown(void){AIL_ex_stop_capture();diff --git a/GeneralsMD/Code/Main/WinMain.cpp b/GeneralsMD/Code/Main/WinMain.cppindex 6be292052..463b0bc42 100644--- a/GeneralsMD/Code/Main/WinMain.cpp+++ b/GeneralsMD/Code/Main/WinMain.cpp@@ -604,7 +604,9 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT message,ClipCursor( NULL );isCursorClippedToWindow = false;- if (TheAudio)+ // A -wav run is heard by its file, not a person: muting it here silenced the+ // capture whenever another window took the focus.+ if (TheAudio && TheGlobalData->m_wavEndFrame <= 0)TheAudio->loseFocus();} // end ifelsediff --git a/GeneralsMD/Code/Tools/vendor.ps1 b/GeneralsMD/Code/Tools/vendor.ps1index b720e61d6..cd289b19c 100644--- a/GeneralsMD/Code/Tools/vendor.ps1+++ b/GeneralsMD/Code/Tools/vendor.ps1@@ -185,6 +185,20 @@ function Install-Nanosvg {Step "nanosvg -> Libraries\Source\nanosvg"}+# --- miniaudio 0.11.25, the one header and its one implementation file, the same pin as vendor.sh.+# Windows plays through XAudio2 but records -wav through miniaudio's mix (miles_dispatch.cpp), the+# one the logic clock can move. Copied file by file so the committed .gitignore is left alone.+function Install-Miniaudio {+ $destination = Join-Path $libraries 'Source\miniaudio'+ if ((Test-Path (Join-Path $destination 'miniaudio.c')) -and -not $Force) { return }+ $archive = Get-File 'https://github.com/mackron/miniaudio/archive/9634bedb5b5a2ca38c1ee7108a9358a4e233f14d.zip' (Join-Path $work 'miniaudio-0.11.25.zip')+ $source = Expand-Source $archive 'miniaudio'+ foreach ($name in @('miniaudio.h', 'miniaudio.c', 'LICENSE')) {+ Copy-Item (Join-Path $source $name) (Join-Path $destination $name) -Force+ }+ Step "miniaudio 0.11.25 -> Libraries\Source\miniaudio"+}+# --- The fork's own upscaled art: every 3D texture at twice its size, and the ground. Not in git -# ReforgedTextures.big alone is a gigabyte, ten times# what GitHub takes in a file, and LFS in a fork is billed to the parent repository.@@ -294,11 +308,12 @@ Install-GameSpyInstall-LitehtmlInstall-LitehtmlPatchInstall-Nanosvg-# SDL3 and miniaudio are the platform layer for everything that is not Windows (decision 3 in-# PORTING.md). Windows keeps Win32Device and Miles, so they are not fetched here;-# vendor.sh fetches them, and says it skips DirectX the same way. The same holds for SDL3's Metal patch,-# Libraries\Source\sdl3-metal-windowless.patch: vendor.sh applies it, and there is nothing here to apply.-Step 'skipping SDL3 and miniaudio: not Windows, and vendor.sh is what fetches them'+Install-Miniaudio+# SDL3 is the platform layer for everything that is not Windows (decision 3 in PORTING.md). Windows+# keeps Win32Device, so it is not fetched here; vendor.sh fetches it, and says it skips DirectX the+# same way. The same holds for SDL3's Metal patch, Libraries\Source\sdl3-metal-windowless.patch:+# vendor.sh applies it, and there is nothing here to apply.+Step 'skipping SDL3: not Windows, and vendor.sh is what fetches it'# glslang, SPIRV-Cross and SDL_shadercross compile the shader generators' SDL3 GPU target (decision 4).# Windows compiles the D3D11 target with d3dcompiler_47.dll, so they are not fetched here.Step 'skipping glslang, SPIRV-Cross and SDL_shadercross: the SDL3 GPU shader path, vendor.sh fetches them'