WwiseGlobalCallbacks.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. /*******************************************************************************
  2. The content of this file includes portions of the proprietary AUDIOKINETIC Wwise
  3. Technology released in source code form as part of the game integration package.
  4. The content of this file may not be used without valid licenses to the
  5. AUDIOKINETIC Wwise Technology.
  6. Note that the use of the game engine is subject to the Unreal(R) Engine End User
  7. License Agreement at https://www.unrealengine.com/en-US/eula/unreal
  8. License Usage
  9. Licensees holding valid licenses to the AUDIOKINETIC Wwise Technology may use
  10. this file in accordance with the end user license agreement provided with the
  11. software or, alternatively, in accordance with the terms contained
  12. in a written agreement between you and Audiokinetic Inc.
  13. Copyright (c) 2023 Audiokinetic Inc.
  14. *******************************************************************************/
  15. #include "Wwise/WwiseGlobalCallbacks.h"
  16. #include "Wwise/API/WwiseSoundEngineAPI.h"
  17. #include "Wwise/Stats/Concurrency.h"
  18. #include "AkUnrealHelper.h"
  19. FWwiseGlobalCallbacks::~FWwiseGlobalCallbacks()
  20. {
  21. if (UNLIKELY(bInitialized))
  22. {
  23. UE_LOG(LogWwiseConcurrency, Error, TEXT("GlobalCallbacks not terminated at destruction."));
  24. }
  25. }
  26. bool FWwiseGlobalCallbacks::Initialize()
  27. {
  28. if (UNLIKELY(bInitialized))
  29. {
  30. UE_LOG(LogWwiseConcurrency, Fatal, TEXT("Global Callbacks already initialized"));
  31. return false;
  32. }
  33. auto* SoundEngine = IWwiseSoundEngineAPI::Get();
  34. if (UNLIKELY(!SoundEngine))
  35. {
  36. UE_LOG(LogWwiseConcurrency, Fatal, TEXT("Could not implement callbacks."));
  37. return false;
  38. }
  39. bInitialized = true;
  40. bool bResult = true;
  41. AKRESULT Result;
  42. Result = SoundEngine->RegisterGlobalCallback(&FWwiseGlobalCallbacks::OnRegisterCallbackStatic, AkGlobalCallbackLocation_Register, (void*)this);
  43. UE_CLOG(Result != AK_Success, LogWwiseConcurrency, Error, TEXT("Cannot Register `Register` Callback: %d (%s)"), Result, AkUnrealHelper::GetResultString(Result));
  44. bResult = bResult && (Result == AK_Success);
  45. Result = SoundEngine->RegisterGlobalCallback(&FWwiseGlobalCallbacks::OnBeginCallbackStatic, AkGlobalCallbackLocation_Begin, (void*)this);
  46. UE_CLOG(Result != AK_Success, LogWwiseConcurrency, Error, TEXT("Cannot Register `Begin` Callback: %d (%s)"), Result, AkUnrealHelper::GetResultString(Result));
  47. bResult = bResult && (Result == AK_Success);
  48. Result = SoundEngine->RegisterGlobalCallback(&FWwiseGlobalCallbacks::OnPreProcessMessageQueueForRenderCallbackStatic, AkGlobalCallbackLocation_PreProcessMessageQueueForRender, (void*)this);
  49. UE_CLOG(Result != AK_Success, LogWwiseConcurrency, Error, TEXT("Cannot Register `PreProcessMessageQueueForRender` Callback: %d (%s)"), Result, AkUnrealHelper::GetResultString(Result));
  50. bResult = bResult && (Result == AK_Success);
  51. Result = SoundEngine->RegisterGlobalCallback(&FWwiseGlobalCallbacks::OnPostMessagesProcessedCallbackStatic, AkGlobalCallbackLocation_PostMessagesProcessed, (void*)this);
  52. UE_CLOG(Result != AK_Success, LogWwiseConcurrency, Error, TEXT("Cannot Register `PostMessagesProcessed` Callback: %d (%s)"), Result, AkUnrealHelper::GetResultString(Result));
  53. bResult = bResult && (Result == AK_Success);
  54. Result = SoundEngine->RegisterGlobalCallback(&FWwiseGlobalCallbacks::OnBeginRenderCallbackStatic, AkGlobalCallbackLocation_BeginRender, (void*)this);
  55. UE_CLOG(Result != AK_Success, LogWwiseConcurrency, Error, TEXT("Cannot Register `BeginRender` Callback: %d (%s)"), Result, AkUnrealHelper::GetResultString(Result));
  56. bResult = bResult && (Result == AK_Success);
  57. Result = SoundEngine->RegisterGlobalCallback(&FWwiseGlobalCallbacks::OnEndRenderCallbackStatic, AkGlobalCallbackLocation_EndRender, (void*)this);
  58. UE_CLOG(Result != AK_Success, LogWwiseConcurrency, Error, TEXT("Cannot Register `EndRender` Callback: %d (%s)"), Result, AkUnrealHelper::GetResultString(Result));
  59. bResult = bResult && (Result == AK_Success);
  60. Result = SoundEngine->RegisterGlobalCallback(&FWwiseGlobalCallbacks::OnEndCallbackStatic, AkGlobalCallbackLocation_End, (void*)this);
  61. UE_CLOG(Result != AK_Success, LogWwiseConcurrency, Error, TEXT("Cannot Register `End` Callback: %d (%s)"), Result, AkUnrealHelper::GetResultString(Result));
  62. bResult = bResult && (Result == AK_Success);
  63. Result = SoundEngine->RegisterGlobalCallback(&FWwiseGlobalCallbacks::OnTermCallbackStatic, AkGlobalCallbackLocation_Term, (void*)this);
  64. UE_CLOG(Result != AK_Success, LogWwiseConcurrency, Error, TEXT("Cannot Register `Term` Callback: %d (%s)"), Result, AkUnrealHelper::GetResultString(Result));
  65. bResult = bResult && (Result == AK_Success);
  66. Result = SoundEngine->RegisterGlobalCallback(&FWwiseGlobalCallbacks::OnMonitorCallbackStatic, AkGlobalCallbackLocation_Monitor, (void*)this);
  67. UE_CLOG(Result != AK_Success, LogWwiseConcurrency, Error, TEXT("Cannot Register `Monitor` Callback: %d (%s)"), Result, AkUnrealHelper::GetResultString(Result));
  68. bResult = bResult && (Result == AK_Success);
  69. Result = SoundEngine->RegisterGlobalCallback(&FWwiseGlobalCallbacks::OnMonitorRecapCallbackStatic, AkGlobalCallbackLocation_MonitorRecap, (void*)this);
  70. UE_CLOG(Result != AK_Success, LogWwiseConcurrency, Error, TEXT("Cannot Register `MonitorRecap` Callback: %d (%s)"), Result, AkUnrealHelper::GetResultString(Result));
  71. bResult = bResult && (Result == AK_Success);
  72. Result = SoundEngine->RegisterGlobalCallback(&FWwiseGlobalCallbacks::OnInitCallbackStatic, AkGlobalCallbackLocation_Init, (void*)this);
  73. UE_CLOG(Result != AK_Success, LogWwiseConcurrency, Error, TEXT("Cannot Register `Init` Callback: %d (%s)"), Result, AkUnrealHelper::GetResultString(Result));
  74. bResult = bResult && (Result == AK_Success);
  75. Result = SoundEngine->RegisterGlobalCallback(&FWwiseGlobalCallbacks::OnSuspendCallbackStatic, AkGlobalCallbackLocation_Suspend, (void*)this);
  76. UE_CLOG(Result != AK_Success, LogWwiseConcurrency, Error, TEXT("Cannot Register `Suspend` Callback: %d (%s)"), Result, AkUnrealHelper::GetResultString(Result));
  77. bResult = bResult && (Result == AK_Success);
  78. Result = SoundEngine->RegisterGlobalCallback(&FWwiseGlobalCallbacks::OnWakeupFromSuspendCallbackStatic, AkGlobalCallbackLocation_WakeupFromSuspend, (void*)this);
  79. UE_CLOG(Result != AK_Success, LogWwiseConcurrency, Error, TEXT("Cannot Register `WakeupFromSuspend` Callback: %d (%s)"), Result, AkUnrealHelper::GetResultString(Result));
  80. bResult = bResult && (Result == AK_Success);
  81. return bResult;
  82. }
  83. void FWwiseGlobalCallbacks::Terminate()
  84. {
  85. if (!bInitialized)
  86. {
  87. return;
  88. }
  89. auto* SoundEngine = IWwiseSoundEngineAPI::Get();
  90. if (UNLIKELY(!SoundEngine))
  91. {
  92. return;
  93. }
  94. bInitialized = false;
  95. AKRESULT Result;
  96. Result = SoundEngine->UnregisterGlobalCallback(&FWwiseGlobalCallbacks::OnRegisterCallbackStatic, AkGlobalCallbackLocation_Register);
  97. UE_CLOG(Result != AK_Success && Result != AK_InvalidParameter, LogWwiseConcurrency, Verbose, TEXT("Cannot Unregister `Register` Callback: %d (%s)"), Result, AkUnrealHelper::GetResultString(Result));
  98. Result = SoundEngine->UnregisterGlobalCallback(&FWwiseGlobalCallbacks::OnBeginCallbackStatic, AkGlobalCallbackLocation_Begin);
  99. UE_CLOG(Result != AK_Success && Result != AK_InvalidParameter, LogWwiseConcurrency, Verbose, TEXT("Cannot Unregister `Begin` Callback: %d (%s)"), Result, AkUnrealHelper::GetResultString(Result));
  100. Result = SoundEngine->UnregisterGlobalCallback(&FWwiseGlobalCallbacks::OnPreProcessMessageQueueForRenderCallbackStatic, AkGlobalCallbackLocation_PreProcessMessageQueueForRender);
  101. UE_CLOG(Result != AK_Success && Result != AK_InvalidParameter, LogWwiseConcurrency, Verbose, TEXT("Cannot Unregister `PreProcessMessageQueueForRender` Callback: %d (%s)"), Result, AkUnrealHelper::GetResultString(Result));
  102. Result = SoundEngine->UnregisterGlobalCallback(&FWwiseGlobalCallbacks::OnPostMessagesProcessedCallbackStatic, AkGlobalCallbackLocation_PostMessagesProcessed);
  103. UE_CLOG(Result != AK_Success && Result != AK_InvalidParameter, LogWwiseConcurrency, Verbose, TEXT("Cannot Unregister `PostMessagesProcessed` Callback: %d (%s)"), Result, AkUnrealHelper::GetResultString(Result));
  104. Result = SoundEngine->UnregisterGlobalCallback(&FWwiseGlobalCallbacks::OnBeginRenderCallbackStatic, AkGlobalCallbackLocation_BeginRender);
  105. UE_CLOG(Result != AK_Success && Result != AK_InvalidParameter, LogWwiseConcurrency, Verbose, TEXT("Cannot Unregister `BeginRender` Callback: %d (%s)"), Result, AkUnrealHelper::GetResultString(Result));
  106. Result = SoundEngine->UnregisterGlobalCallback(&FWwiseGlobalCallbacks::OnEndRenderCallbackStatic, AkGlobalCallbackLocation_EndRender);
  107. UE_CLOG(Result != AK_Success && Result != AK_InvalidParameter, LogWwiseConcurrency, Verbose, TEXT("Cannot Unregister `EndRender` Callback: %d (%s)"), Result, AkUnrealHelper::GetResultString(Result));
  108. Result = SoundEngine->UnregisterGlobalCallback(&FWwiseGlobalCallbacks::OnEndCallbackStatic, AkGlobalCallbackLocation_End);
  109. UE_CLOG(Result != AK_Success && Result != AK_InvalidParameter, LogWwiseConcurrency, Verbose, TEXT("Cannot Unregister `End` Callback: %d (%s)"), Result, AkUnrealHelper::GetResultString(Result));
  110. Result = SoundEngine->UnregisterGlobalCallback(&FWwiseGlobalCallbacks::OnTermCallbackStatic, AkGlobalCallbackLocation_Term);
  111. UE_CLOG(Result != AK_Success && Result != AK_InvalidParameter, LogWwiseConcurrency, Verbose, TEXT("Cannot Unregister `Term` Callback: %d (%s)"), Result, AkUnrealHelper::GetResultString(Result));
  112. Result = SoundEngine->UnregisterGlobalCallback(&FWwiseGlobalCallbacks::OnMonitorCallbackStatic, AkGlobalCallbackLocation_Monitor);
  113. UE_CLOG(Result != AK_Success && Result != AK_InvalidParameter, LogWwiseConcurrency, Verbose, TEXT("Cannot Unregister `Monitor` Callback: %d (%s)"), Result, AkUnrealHelper::GetResultString(Result));
  114. Result = SoundEngine->UnregisterGlobalCallback(&FWwiseGlobalCallbacks::OnMonitorRecapCallbackStatic, AkGlobalCallbackLocation_MonitorRecap);
  115. UE_CLOG(Result != AK_Success && Result != AK_InvalidParameter, LogWwiseConcurrency, Verbose, TEXT("Cannot Unregister `MonitorRecap` Callback: %d (%s)"), Result, AkUnrealHelper::GetResultString(Result));
  116. Result = SoundEngine->UnregisterGlobalCallback(&FWwiseGlobalCallbacks::OnInitCallbackStatic, AkGlobalCallbackLocation_Init);
  117. UE_CLOG(Result != AK_Success && Result != AK_InvalidParameter, LogWwiseConcurrency, Verbose, TEXT("Cannot Unregister `Init` Callback: %d (%s)"), Result, AkUnrealHelper::GetResultString(Result));
  118. Result = SoundEngine->UnregisterGlobalCallback(&FWwiseGlobalCallbacks::OnSuspendCallbackStatic, AkGlobalCallbackLocation_Suspend);
  119. UE_CLOG(Result != AK_Success && Result != AK_InvalidParameter, LogWwiseConcurrency, Verbose, TEXT("Cannot Unregister `Suspend` Callback: %d (%s)"), Result, AkUnrealHelper::GetResultString(Result));
  120. Result = SoundEngine->UnregisterGlobalCallback(&FWwiseGlobalCallbacks::OnWakeupFromSuspendCallbackStatic, AkGlobalCallbackLocation_WakeupFromSuspend);
  121. UE_CLOG(Result != AK_Success && Result != AK_InvalidParameter, LogWwiseConcurrency, Verbose, TEXT("Cannot Unregister `WakeupFromSuspend` Callback: %d (%s)"), Result, AkUnrealHelper::GetResultString(Result));
  122. }
  123. void FWwiseGlobalCallbacks::RegisterSync(FSyncFunction&& InFunction)
  124. {
  125. RegisterQueue.SyncDefer(MoveTemp(InFunction));
  126. }
  127. void FWwiseGlobalCallbacks::RegisterCompletion(FCompletionPromise&& Promise)
  128. {
  129. RegisterAsync([Promise = MoveTemp(Promise)]() mutable
  130. {
  131. Promise.EmplaceValue();
  132. return EWwiseDeferredAsyncResult::Done;
  133. });
  134. }
  135. void FWwiseGlobalCallbacks::WaitForRegister()
  136. {
  137. SCOPED_WWISECONCURRENCY_EVENT_4(TEXT("FWwiseGlobalCallbacks::WaitForRegister"));
  138. FEventRef Event;
  139. RegisterAsync([&Event]() {Event->Trigger(); return EWwiseDeferredAsyncResult::Done; });
  140. Event->Wait();
  141. Event->Reset();
  142. }
  143. void FWwiseGlobalCallbacks::BeginSync(FSyncFunction&& InFunction)
  144. {
  145. BeginQueue.SyncDefer(MoveTemp(InFunction));
  146. }
  147. void FWwiseGlobalCallbacks::BeginCompletion(FCompletionPromise&& Promise)
  148. {
  149. BeginAsync([Promise = MoveTemp(Promise)]() mutable
  150. {
  151. Promise.EmplaceValue();
  152. return EWwiseDeferredAsyncResult::Done;
  153. });
  154. }
  155. void FWwiseGlobalCallbacks::WaitForBegin()
  156. {
  157. SCOPED_WWISECONCURRENCY_EVENT_4(TEXT("FWwiseGlobalCallbacks::WaitForBegin"));
  158. FEventRef Event;
  159. BeginAsync([&Event]() {Event->Trigger(); return EWwiseDeferredAsyncResult::Done; });
  160. Event->Wait();
  161. Event->Reset();
  162. }
  163. void FWwiseGlobalCallbacks::PreProcessMessageQueueForRenderSync(FSyncFunction&& InFunction)
  164. {
  165. PreProcessMessageQueueForRenderQueue.SyncDefer(MoveTemp(InFunction));
  166. }
  167. void FWwiseGlobalCallbacks::PreProcessMessageQueueForRenderCompletion(FCompletionPromise&& Promise)
  168. {
  169. PreProcessMessageQueueForRenderAsync([Promise = MoveTemp(Promise)]() mutable
  170. {
  171. Promise.EmplaceValue();
  172. return EWwiseDeferredAsyncResult::Done;
  173. });
  174. }
  175. void FWwiseGlobalCallbacks::WaitForPreProcessMessageQueueForRender()
  176. {
  177. SCOPED_WWISECONCURRENCY_EVENT_4(TEXT("FWwiseGlobalCallbacks::WaitForPreProcessMessageQueueForRender"));
  178. FEventRef Event;
  179. PreProcessMessageQueueForRenderAsync([&Event]() {Event->Trigger(); return EWwiseDeferredAsyncResult::Done; });
  180. Event->Wait();
  181. Event->Reset();
  182. }
  183. void FWwiseGlobalCallbacks::PostMessagesProcessedSync(FSyncFunction&& InFunction)
  184. {
  185. PostMessagesProcessedQueue.SyncDefer(MoveTemp(InFunction));
  186. }
  187. void FWwiseGlobalCallbacks::PostMessagesProcessedCompletion(FCompletionPromise&& Promise)
  188. {
  189. PostMessagesProcessedAsync([Promise = MoveTemp(Promise)]() mutable
  190. {
  191. Promise.EmplaceValue();
  192. return EWwiseDeferredAsyncResult::Done;
  193. });
  194. }
  195. void FWwiseGlobalCallbacks::WaitForPostMessagesProcessed()
  196. {
  197. SCOPED_WWISECONCURRENCY_EVENT_4(TEXT("FWwiseGlobalCallbacks::WaitForPostMessagesProcessed"));
  198. FEventRef Event;
  199. PostMessagesProcessedAsync([&Event]() {Event->Trigger(); return EWwiseDeferredAsyncResult::Done; });
  200. Event->Wait();
  201. Event->Reset();
  202. }
  203. void FWwiseGlobalCallbacks::BeginRenderSync(FSyncFunction&& InFunction)
  204. {
  205. BeginRenderQueue.SyncDefer(MoveTemp(InFunction));
  206. }
  207. void FWwiseGlobalCallbacks::BeginRenderCompletion(FCompletionPromise&& Promise)
  208. {
  209. BeginRenderAsync([Promise = MoveTemp(Promise)]() mutable
  210. {
  211. Promise.EmplaceValue();
  212. return EWwiseDeferredAsyncResult::Done;
  213. });
  214. }
  215. void FWwiseGlobalCallbacks::WaitForBeginRender()
  216. {
  217. SCOPED_WWISECONCURRENCY_EVENT_4(TEXT("FWwiseGlobalCallbacks::WaitForBeginRender"));
  218. FEventRef Event;
  219. BeginRenderAsync([&Event]() {Event->Trigger(); return EWwiseDeferredAsyncResult::Done; });
  220. Event->Wait();
  221. Event->Reset();
  222. }
  223. void FWwiseGlobalCallbacks::EndRenderSync(FSyncFunction&& InFunction)
  224. {
  225. EndRenderQueue.SyncDefer(MoveTemp(InFunction));
  226. }
  227. void FWwiseGlobalCallbacks::EndRenderCompletion(FCompletionPromise&& Promise)
  228. {
  229. EndRenderAsync([Promise = MoveTemp(Promise)]() mutable
  230. {
  231. Promise.EmplaceValue();
  232. return EWwiseDeferredAsyncResult::Done;
  233. });
  234. }
  235. void FWwiseGlobalCallbacks::WaitForEndRender()
  236. {
  237. SCOPED_WWISECONCURRENCY_EVENT_4(TEXT("FWwiseGlobalCallbacks::WaitForEndRender"));
  238. FEventRef Event;
  239. EndRenderAsync([&Event]() {Event->Trigger(); return EWwiseDeferredAsyncResult::Done; });
  240. Event->Wait();
  241. Event->Reset();
  242. }
  243. void FWwiseGlobalCallbacks::EndSync(FSyncFunction&& InFunction)
  244. {
  245. EndQueue.SyncDefer(MoveTemp(InFunction));
  246. }
  247. void FWwiseGlobalCallbacks::EndCompletion(FCompletionPromise&& Promise, int Count)
  248. {
  249. if (Count <= 0)
  250. {
  251. return Promise.EmplaceValue();
  252. }
  253. EndAsync([Promise = MoveTemp(Promise), Count = Count - 1]() mutable
  254. {
  255. auto* WwiseGlobalCallbacks = FWwiseGlobalCallbacks::Get();
  256. WwiseGlobalCallbacks->EndCompletion(MoveTemp(Promise), Count);
  257. return EWwiseDeferredAsyncResult::Done;
  258. });
  259. }
  260. void FWwiseGlobalCallbacks::WaitForEnd()
  261. {
  262. SCOPED_WWISECONCURRENCY_EVENT_4(TEXT("FWwiseGlobalCallbacks::WaitForEnd"));
  263. FEventRef Event;
  264. EndAsync([&Event]() {Event->Trigger(); return EWwiseDeferredAsyncResult::Done; });
  265. Event->Wait();
  266. Event->Reset();
  267. }
  268. void FWwiseGlobalCallbacks::TermSync(FSyncFunction&& InFunction)
  269. {
  270. TermQueue.SyncDefer(MoveTemp(InFunction));
  271. }
  272. void FWwiseGlobalCallbacks::TermCompletion(FCompletionPromise&& Promise)
  273. {
  274. TermAsync([Promise = MoveTemp(Promise)]() mutable
  275. {
  276. Promise.EmplaceValue();
  277. return EWwiseDeferredAsyncResult::Done;
  278. });
  279. }
  280. void FWwiseGlobalCallbacks::WaitForTerm()
  281. {
  282. SCOPED_WWISECONCURRENCY_EVENT_4(TEXT("FWwiseGlobalCallbacks::WaitForTerm"));
  283. FEventRef Event;
  284. TermAsync([&Event]() {Event->Trigger(); return EWwiseDeferredAsyncResult::Done; });
  285. Event->Wait();
  286. Event->Reset();
  287. }
  288. void FWwiseGlobalCallbacks::MonitorSync(FSyncFunction&& InFunction)
  289. {
  290. MonitorQueue.SyncDefer(MoveTemp(InFunction));
  291. }
  292. void FWwiseGlobalCallbacks::MonitorCompletion(FCompletionPromise&& Promise)
  293. {
  294. MonitorAsync([Promise = MoveTemp(Promise)]() mutable
  295. {
  296. Promise.EmplaceValue();
  297. return EWwiseDeferredAsyncResult::Done;
  298. });
  299. }
  300. void FWwiseGlobalCallbacks::WaitForMonitor()
  301. {
  302. SCOPED_WWISECONCURRENCY_EVENT_4(TEXT("FWwiseGlobalCallbacks::WaitForMonitor"));
  303. FEventRef Event;
  304. MonitorAsync([&Event]() {Event->Trigger(); return EWwiseDeferredAsyncResult::Done; });
  305. Event->Wait();
  306. Event->Reset();
  307. }
  308. void FWwiseGlobalCallbacks::MonitorRecapSync(FSyncFunction&& InFunction)
  309. {
  310. MonitorRecapQueue.SyncDefer(MoveTemp(InFunction));
  311. }
  312. void FWwiseGlobalCallbacks::MonitorRecapCompletion(FCompletionPromise&& Promise)
  313. {
  314. MonitorRecapAsync([Promise = MoveTemp(Promise)]() mutable
  315. {
  316. Promise.EmplaceValue();
  317. return EWwiseDeferredAsyncResult::Done;
  318. });
  319. }
  320. void FWwiseGlobalCallbacks::WaitForMonitorRecap()
  321. {
  322. SCOPED_WWISECONCURRENCY_EVENT_4(TEXT("FWwiseGlobalCallbacks::WaitForMonitorRecap"));
  323. FEventRef Event;
  324. MonitorRecapAsync([&Event]() {Event->Trigger(); return EWwiseDeferredAsyncResult::Done; });
  325. Event->Wait();
  326. Event->Reset();
  327. }
  328. void FWwiseGlobalCallbacks::InitSync(FSyncFunction&& InFunction)
  329. {
  330. InitQueue.SyncDefer(MoveTemp(InFunction));
  331. }
  332. void FWwiseGlobalCallbacks::InitCompletion(FCompletionPromise&& Promise)
  333. {
  334. InitAsync([Promise = MoveTemp(Promise)]() mutable
  335. {
  336. Promise.EmplaceValue();
  337. return EWwiseDeferredAsyncResult::Done;
  338. });
  339. }
  340. void FWwiseGlobalCallbacks::WaitForInit()
  341. {
  342. SCOPED_WWISECONCURRENCY_EVENT_4(TEXT("FWwiseGlobalCallbacks::WaitForInit"));
  343. FEventRef Event;
  344. InitAsync([&Event]() {Event->Trigger(); return EWwiseDeferredAsyncResult::Done; });
  345. Event->Wait();
  346. Event->Reset();
  347. }
  348. void FWwiseGlobalCallbacks::SuspendSync(FSyncFunction&& InFunction)
  349. {
  350. SuspendQueue.SyncDefer(MoveTemp(InFunction));
  351. }
  352. void FWwiseGlobalCallbacks::SuspendCompletion(FCompletionPromise&& Promise)
  353. {
  354. SuspendAsync([Promise = MoveTemp(Promise)]() mutable
  355. {
  356. Promise.EmplaceValue();
  357. return EWwiseDeferredAsyncResult::Done;
  358. });
  359. }
  360. void FWwiseGlobalCallbacks::WaitForSuspend()
  361. {
  362. SCOPED_WWISECONCURRENCY_EVENT_4(TEXT("FWwiseGlobalCallbacks::WaitForSuspend"));
  363. FEventRef Event;
  364. SuspendAsync([&Event]() {Event->Trigger(); return EWwiseDeferredAsyncResult::Done; });
  365. Event->Wait();
  366. Event->Reset();
  367. }
  368. void FWwiseGlobalCallbacks::WakeupFromSuspendSync(FSyncFunction&& InFunction)
  369. {
  370. WakeupFromSuspendQueue.SyncDefer(MoveTemp(InFunction));
  371. }
  372. void FWwiseGlobalCallbacks::WakeupFromSuspendCompletion(FCompletionPromise&& Promise)
  373. {
  374. WakeupFromSuspendAsync([Promise = MoveTemp(Promise)]() mutable
  375. {
  376. Promise.EmplaceValue();
  377. return EWwiseDeferredAsyncResult::Done;
  378. });
  379. }
  380. void FWwiseGlobalCallbacks::WaitForWakeupFromSuspend()
  381. {
  382. SCOPED_WWISECONCURRENCY_EVENT_4(TEXT("FWwiseGlobalCallbacks::WaitForWakeupFromSuspend"));
  383. FEventRef Event;
  384. WakeupFromSuspendAsync([&Event]() {Event->Trigger(); return EWwiseDeferredAsyncResult::Done; });
  385. Event->Wait();
  386. Event->Reset();
  387. }
  388. void FWwiseGlobalCallbacks::OnRegisterCallback(AK::IAkGlobalPluginContext* in_pContext)
  389. {
  390. RegisterQueue.Run(in_pContext);
  391. }
  392. void FWwiseGlobalCallbacks::OnBeginCallback(AK::IAkGlobalPluginContext* in_pContext)
  393. {
  394. BeginQueue.Run(in_pContext);
  395. }
  396. void FWwiseGlobalCallbacks::OnPreProcessMessageQueueForRenderCallback(AK::IAkGlobalPluginContext* in_pContext)
  397. {
  398. PreProcessMessageQueueForRenderQueue.Run(in_pContext);
  399. }
  400. void FWwiseGlobalCallbacks::OnPostMessagesProcessedCallback(AK::IAkGlobalPluginContext* in_pContext)
  401. {
  402. PostMessagesProcessedQueue.Run(in_pContext);
  403. }
  404. void FWwiseGlobalCallbacks::OnBeginRenderCallback(AK::IAkGlobalPluginContext* in_pContext)
  405. {
  406. BeginRenderQueue.Run(in_pContext);
  407. }
  408. void FWwiseGlobalCallbacks::OnEndRenderCallback(AK::IAkGlobalPluginContext* in_pContext)
  409. {
  410. EndRenderQueue.Run(in_pContext);
  411. }
  412. void FWwiseGlobalCallbacks::OnEndCallback(AK::IAkGlobalPluginContext* in_pContext)
  413. {
  414. EndQueue.Run(in_pContext);
  415. }
  416. void FWwiseGlobalCallbacks::OnTermCallback(AK::IAkGlobalPluginContext* in_pContext)
  417. {
  418. TermQueue.Run(in_pContext);
  419. }
  420. void FWwiseGlobalCallbacks::OnMonitorCallback(AK::IAkGlobalPluginContext* in_pContext)
  421. {
  422. MonitorQueue.Run(in_pContext);
  423. }
  424. void FWwiseGlobalCallbacks::OnMonitorRecapCallback(AK::IAkGlobalPluginContext* in_pContext)
  425. {
  426. MonitorRecapQueue.Run(in_pContext);
  427. }
  428. void FWwiseGlobalCallbacks::OnInitCallback(AK::IAkGlobalPluginContext* in_pContext)
  429. {
  430. InitQueue.Run(in_pContext);
  431. }
  432. void FWwiseGlobalCallbacks::OnSuspendCallback(AK::IAkGlobalPluginContext* in_pContext)
  433. {
  434. SuspendQueue.Run(in_pContext);
  435. }
  436. void FWwiseGlobalCallbacks::OnWakeupFromSuspendCallback(AK::IAkGlobalPluginContext* in_pContext)
  437. {
  438. WakeupFromSuspendQueue.Run(in_pContext);
  439. }
  440. void FWwiseGlobalCallbacks::OnRegisterCallbackStatic(AK::IAkGlobalPluginContext* in_pContext,
  441. AkGlobalCallbackLocation in_eLocation, void* in_pCookie)
  442. {
  443. static_cast<FWwiseGlobalCallbacks*>(in_pCookie)->OnRegisterCallback(in_pContext);
  444. }
  445. void FWwiseGlobalCallbacks::OnBeginCallbackStatic(AK::IAkGlobalPluginContext* in_pContext,
  446. AkGlobalCallbackLocation in_eLocation, void* in_pCookie)
  447. {
  448. static_cast<FWwiseGlobalCallbacks*>(in_pCookie)->OnBeginCallback(in_pContext);
  449. }
  450. void FWwiseGlobalCallbacks::OnPreProcessMessageQueueForRenderCallbackStatic(AK::IAkGlobalPluginContext* in_pContext,
  451. AkGlobalCallbackLocation in_eLocation, void* in_pCookie)
  452. {
  453. static_cast<FWwiseGlobalCallbacks*>(in_pCookie)->OnPreProcessMessageQueueForRenderCallback(in_pContext);
  454. }
  455. void FWwiseGlobalCallbacks::OnPostMessagesProcessedCallbackStatic(AK::IAkGlobalPluginContext* in_pContext,
  456. AkGlobalCallbackLocation in_eLocation, void* in_pCookie)
  457. {
  458. static_cast<FWwiseGlobalCallbacks*>(in_pCookie)->OnPostMessagesProcessedCallback(in_pContext);
  459. }
  460. void FWwiseGlobalCallbacks::OnBeginRenderCallbackStatic(AK::IAkGlobalPluginContext* in_pContext,
  461. AkGlobalCallbackLocation in_eLocation, void* in_pCookie)
  462. {
  463. static_cast<FWwiseGlobalCallbacks*>(in_pCookie)->OnBeginRenderCallback(in_pContext);
  464. }
  465. void FWwiseGlobalCallbacks::OnEndRenderCallbackStatic(AK::IAkGlobalPluginContext* in_pContext,
  466. AkGlobalCallbackLocation in_eLocation, void* in_pCookie)
  467. {
  468. static_cast<FWwiseGlobalCallbacks*>(in_pCookie)->OnEndRenderCallback(in_pContext);
  469. }
  470. void FWwiseGlobalCallbacks::OnEndCallbackStatic(AK::IAkGlobalPluginContext* in_pContext,
  471. AkGlobalCallbackLocation in_eLocation, void* in_pCookie)
  472. {
  473. static_cast<FWwiseGlobalCallbacks*>(in_pCookie)->OnEndCallback(in_pContext);
  474. }
  475. void FWwiseGlobalCallbacks::OnTermCallbackStatic(AK::IAkGlobalPluginContext* in_pContext,
  476. AkGlobalCallbackLocation in_eLocation, void* in_pCookie)
  477. {
  478. static_cast<FWwiseGlobalCallbacks*>(in_pCookie)->OnTermCallback(in_pContext);
  479. }
  480. void FWwiseGlobalCallbacks::OnMonitorCallbackStatic(AK::IAkGlobalPluginContext* in_pContext,
  481. AkGlobalCallbackLocation in_eLocation, void* in_pCookie)
  482. {
  483. static_cast<FWwiseGlobalCallbacks*>(in_pCookie)->OnMonitorCallback(in_pContext);
  484. }
  485. void FWwiseGlobalCallbacks::OnMonitorRecapCallbackStatic(AK::IAkGlobalPluginContext* in_pContext,
  486. AkGlobalCallbackLocation in_eLocation, void* in_pCookie)
  487. {
  488. static_cast<FWwiseGlobalCallbacks*>(in_pCookie)->OnMonitorRecapCallback(in_pContext);
  489. }
  490. void FWwiseGlobalCallbacks::OnInitCallbackStatic(AK::IAkGlobalPluginContext* in_pContext,
  491. AkGlobalCallbackLocation in_eLocation, void* in_pCookie)
  492. {
  493. static_cast<FWwiseGlobalCallbacks*>(in_pCookie)->OnInitCallback(in_pContext);
  494. }
  495. void FWwiseGlobalCallbacks::OnSuspendCallbackStatic(AK::IAkGlobalPluginContext* in_pContext,
  496. AkGlobalCallbackLocation in_eLocation, void* in_pCookie)
  497. {
  498. static_cast<FWwiseGlobalCallbacks*>(in_pCookie)->OnSuspendCallback(in_pContext);
  499. }
  500. void FWwiseGlobalCallbacks::OnWakeupFromSuspendCallbackStatic(AK::IAkGlobalPluginContext* in_pContext,
  501. AkGlobalCallbackLocation in_eLocation, void* in_pCookie)
  502. {
  503. static_cast<FWwiseGlobalCallbacks*>(in_pCookie)->OnWakeupFromSuspendCallback(in_pContext);
  504. }