Persistent sounds & threaded OpenAL#548
Draft
Couls wants to merge 2 commits into
Draft
Conversation
Owner
|
Add new lua exports into lua_help_ex please |
Owner
Owner
Contributor
|
Hope this gon fix issue with rain sounds during loading screens when you alt+tab. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary
This PR adds an engine-level persistent sound capability and moves OpenAL buffer updates onto a dedicated background thread, so 2D streams (music, PDA radio) keep playing seamlessly across level transitions and during the load screen, and remain fully controllable from Lua afterward. mtSound remains a console command and can be set to 0 to disable multithreaded sound implementation
Motivation
In the engine, every emitter is destroyed when a level unloads (
_clear), and the main thread is blocked for seconds during loading, so any streamed audio stops dead. Mods that want continuous music (e.g. a PDA radio) have no clean way to keep a stream alive and re-bind to it after the new level spawns. This PR solves both problems at the source.What's included
1. Persistent emitters (survive level unload)
CSound_emitter::set_persistent(bool)/is_persistent()— a persistent emitter is forced to 2D and is not destroyed during_clear.s_persistent_refs) so the stream survives Lua GC._clear, persistent survivors are detached from their render target (enter "simulating" state), kept ins_emitters, and their backingCSound_sourceis preserved while every non-persistent emitter/source is released as before.2. Per-emitter "persist in menu" flag
set_persistent_in_menu(bool)/is_persistent_in_menu()controls whether a given persistent emitter keeps playing while the game is paused in a menu, replacing the old global toggle.pause_emitters()honors it per-emitter.3. Owner re-binding after transition
sound_object(new owner pointer) while the persistent emitter is still playing, the engine reconnects them:reconcile_emitter_feedback()re-linksowner_data->feedback, matching by source handle when the owner pointer changed.stop_emitters_for_owner(),has_playing_emitter_for_owner(), consolidated through a singlefind_emitter_for_owner()lookup.ref_sound::stop()/has_playing_emitter()now work even when the cached feedback pointer was lost across a load.4. Threaded OpenAL update
SoundRender_UpdateThread; the main thread only publishes a listener snapshot, so audio does not stutter while the main thread is blocked loading a level.sound_api_enter/leave, which also makes the AL context current per thread).5. Console command
snd_stop_persistent— force-stops all persistent emitters (cleanup / safety).Lua API
The feature is exposed on the existing
sound_object: