Lua trace/veto hooks for the ambient bed and level music - #644
Lua trace/veto hooks for the ambient bed and level music#644damiansirbu wants to merge 2 commits into
Conversation
Only HUD sounds had a Lua seam (COnBeforePlayHudSound). Mods driving
atmosphere could neither trace nor suppress the engine's own ambient
plays. Add a named _G callback at each site, mirroring COnBeforePlayHudSound:
the engine calls it only when the global is set (zero cost when absent)
and applies { volume_mult } from the return (0 vetoes/silences, <1
attenuates, nil = vanilla). Neutral lever, no engine-side condition.
- COnAmbientBed: System A per-weather background bed (WeathersUpdate);
skip on veto, set_volume on attenuate.
- COnLevelMusic: level music track (SMusicTrack::Play); volume-only.
Manifest entries added to lua_help_ex.script.
|
Add |
Add the _G.C* relay plus AddScriptCallback for on_before_play_ambient_bed and on_before_play_level_music, so a third party subscribes via RegisterScriptCallback and scales or vetoes through the result table. Mirrors COnBeforePlayHudSound. Drop the lua_help_ex engine-callbacks block: a script callback is documented at its registration, not in the bind manifest.
|
Done. Both PRs now define the I put the relays in Tested in-game (Anomaly 1.5.3, DX11): all six register and fire with correct args. A |
|
Yea, callbacks_ script is the better place. Thanks |
Summary
Only HUD sounds have a Lua seam (
COnBeforePlayHudSound). Mods driving atmosphere can neither trace nor suppress the engine's own ambient plays. This adds a named_Gcallback at two ambient sound play sites, same pattern: the engine calls it only when the global is set (zero cost when absent) and applies{ volume_mult }from the return -0vetoes/silences,<1attenuates,nil= vanilla. Neutral lever, no engine-side condition.Hooks
COnAmbientBed(section, file, pos)- the per-weather background bed play site inCGamePersistent::WeathersUpdate(thesound_channelsstatic bed, the one ambient path scripts cannot reach:sound_ambient.scriptowns onlysound_channels_dynamic). Skip on veto,set_volumeon attenuate; the channel reschedules on its own period either way.COnLevelMusic(file)- level music track inSMusicTrack::Play(level_sounds.cpp). Volume-only: applied viaSetVolume(0 silences the track), since skipping the play would makeIsPlaying()false and the manager would re-select every frame.Use cases
Files changed
src/xrGame/GamePersistent.cpp(+28) - bed hook + sharedambient_hook_volume_multhelper.src/xrGame/level_sounds.cpp(+24) - music hook (same helper, static linkage).gamedata/scripts/lua_help_ex.script(+6) - manifest entries for both callbacks.Lua usage
Testing
Built locally (DX11, 0 errors) and deployed to a live install; a Lua consumer registered both callbacks and returned
{ volume_mult = 0 }. Verified engine-side via a temporaryMsgat both branches (removed for this commit):background_forest_day, Agroprom Undergroundugrnd_ambient+ugrnd_bkg_1(multi-channel bed). 400+ veto events logged:play_at_posskipped, channel cadence intact (~26s period unchanged).music\level\day_normal\music_05,music_06).nilreturn / no global defined): bed plays vanilla (PLAYED vol[1.00]observed before the consumer registered).0 < volume_mult < 1) reuses the veto-tested return-parse and the sameset_volumecallsound_ambient.scriptmakes; not separately exercised in-game.