123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- #pragma once
- #include "Wwise/WwiseExecutionQueue.h"
- #include "WwiseUnrealDefines.h"
- namespace AK
- {
- class IAkGlobalPluginContext;
- }
- enum class WWISECONCURRENCY_API EWwiseDeferredAsyncResult
- {
-
- Done,
-
- KeepRunning
- };
- struct WWISECONCURRENCY_API FWwiseDeferredQueue
- {
- using FFunction = TUniqueFunction<EWwiseDeferredAsyncResult()>;
- using FSyncFunction = TUniqueFunction<EWwiseDeferredAsyncResult (AK::IAkGlobalPluginContext*)>;
- #if UE_5_1_OR_LATER
- DECLARE_TS_MULTICAST_DELEGATE_OneParam(FThreadSafeDelegate, AK::IAkGlobalPluginContext*);
- #else
- DECLARE_MULTICAST_DELEGATE_OneParam(FThreadSafeDelegate, AK::IAkGlobalPluginContext*);
- #endif
- DECLARE_MULTICAST_DELEGATE(FGameThreadDelegate);
- #define WWISE_DQ_NAME(name) TEXT(name ## " Deferred Queue worker")
- FWwiseDeferredQueue(const TCHAR* InDebugName);
- ~FWwiseDeferredQueue();
-
- void AsyncDefer(FFunction&& InFunction);
-
- void SyncDefer(FSyncFunction&& InFunction);
-
- void GameDefer(FFunction&& InFunction);
- void Run(AK::IAkGlobalPluginContext* InContext);
- void Wait();
- bool IsEmpty() const { return AsyncOpQueue.IsEmpty() && SyncOpQueue.IsEmpty() && GameOpQueue.IsEmpty(); }
- FGameThreadDelegate OnGameRun;
- FThreadSafeDelegate OnSyncRunTS;
- protected:
- FWwiseExecutionQueue AsyncExecutionQueue;
- using FOps = TQueue<FFunction, EQueueMode::Mpsc>;
- using FSyncOps = TQueue<FSyncFunction, EQueueMode::Mpsc>;
- FOps AsyncOpQueue;
- FSyncOps SyncOpQueue;
- FOps GameOpQueue;
- TAtomic<int> GameThreadExecuting {0};
- bool bSyncThreadDone = false;
- bool bClosing = false;
- AK::IAkGlobalPluginContext* Context { nullptr };
- private:
- void AsyncExec();
- void SyncExec();
- void SyncExecLoop();
- void GameThreadExec();
- void GameThreadExecLoop();
- };
|