diff --git a/Source/Engine/Audio/OpenAL/AudioBackendOAL.cpp b/Source/Engine/Audio/OpenAL/AudioBackendOAL.cpp index fb883f952..715ede74f 100644 --- a/Source/Engine/Audio/OpenAL/AudioBackendOAL.cpp +++ b/Source/Engine/Audio/OpenAL/AudioBackendOAL.cpp @@ -682,30 +682,28 @@ void AudioBackendOAL::Base_OnActiveDeviceChanged() if (ALC::Inited) { // Reload all audio clips to recreate their buffers - for (Asset* asset : Content::GetAssets()) + for (AudioClip* audioClip : Content::GetAssets()) { - if (auto* audioClip = ScriptingObject::Cast(asset)) + audioClip->WaitForLoaded(); + ScopeLock lock(audioClip->Locker); + + // Clear old buffer IDs + for (uint32& bufferID : audioClip->Buffers) + bufferID = 0; + + if (audioClip->IsStreamable()) { - ScopeLock lock(audioClip->Locker); + // Let the streaming recreate missing buffers + audioClip->RequestStreamingUpdate(); + } + else + { + // Reload audio clip + auto assetLock = audioClip->Storage->Lock(); + audioClip->LoadChunk(0); + audioClip->Buffers[0] = AudioBackend::Buffer::Create(); + audioClip->WriteBuffer(0); - // Clear old buffer IDs - for (uint32& bufferID : audioClip->Buffers) - bufferID = 0; - - if (audioClip->IsStreamable()) - { - // Let the streaming recreate missing buffers - audioClip->RequestStreamingUpdate(); - } - else - { - // Reload audio clip - auto assetLock = audioClip->Storage->Lock(); - audioClip->LoadChunk(0); - audioClip->Buffers[0] = AudioBackend::Buffer::Create(); - audioClip->WriteBuffer(0); - - } } } diff --git a/Source/Engine/Content/Content.cpp b/Source/Engine/Content/Content.cpp index 4a9ea500b..59d2dfffa 100644 --- a/Source/Engine/Content/Content.cpp +++ b/Source/Engine/Content/Content.cpp @@ -684,6 +684,19 @@ Array Content::GetAssets() return assets; } +Array Content::GetAssets(const MClass* type) +{ + Array assets; + AssetsLocker.Lock(); + for (auto& e : Assets) + { + if (e.Value->Is(type)) + assets.Add(e.Value); + } + AssetsLocker.Unlock(); + return assets; +} + const Dictionary& Content::GetAssetsRaw() { AssetsLocker.Lock(); diff --git a/Source/Engine/Content/Content.h b/Source/Engine/Content/Content.h index f6dcf59f0..15da20a9c 100644 --- a/Source/Engine/Content/Content.h +++ b/Source/Engine/Content/Content.h @@ -122,7 +122,26 @@ public: /// Gets the assets (loaded or during load). /// /// The collection of assets. - static Array GetAssets(); + API_FUNCTION() static Array GetAssets(); + + /// + /// Gets the assets (loaded or during load). + /// + /// Type of the assets to search for. Includes any assets derived from the type. + /// Found actors list. + API_FUNCTION() static Array GetAssets(API_PARAM(Attributes="TypeReference(typeof(Actor))") const MClass* type); + + /// + /// Gets the assets (loaded or during load). + /// + /// Type of the object. + /// Found actors list. + template + static Array GetAssets() + { + Array assets = GetAssets(T::GetStaticClass()); + return *(Array*) & assets; + } /// /// Gets the raw dictionary of assets (loaded or during load).