WwiseGlobalCallbacks.cpp 25 KB

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