WwiseResourceLoaderImpl.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  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. #pragma once
  16. #include "WwiseResourceLoaderModule.h"
  17. #include "Wwise/WwiseExecutionQueue.h"
  18. #include "Wwise/CookedData/WwiseAuxBusCookedData.h"
  19. #include "Wwise/CookedData/WwiseEventCookedData.h"
  20. #include "Wwise/CookedData/WwiseShareSetCookedData.h"
  21. #include "Wwise/Loaded/WwiseLoadedAuxBus.h"
  22. #include "Wwise/Loaded/WwiseLoadedSoundBank.h"
  23. #include "Wwise/Loaded/WwiseLoadedEvent.h"
  24. #include "Wwise/Loaded/WwiseLoadedExternalSource.h"
  25. #include "Wwise/Loaded/WwiseLoadedGroupValue.h"
  26. #include "Wwise/Loaded/WwiseLoadedInitBank.h"
  27. #include "Wwise/Loaded/WwiseLoadedMedia.h"
  28. #include "Wwise/Loaded/WwiseLoadedShareSet.h"
  29. #include "Wwise/WwiseResourceLoaderFuture.h"
  30. #include "Wwise/WwiseSharedGroupValueKey.h"
  31. #include "Wwise/WwiseSharedLanguageId.h"
  32. #include "Wwise/WwiseSharedPlatformId.h"
  33. #include "Wwise/Stats/ResourceLoader.h"
  34. #if WITH_EDITORONLY_DATA
  35. #include "Engine/EngineTypes.h"
  36. #include "UObject/SoftObjectPath.h"
  37. #endif
  38. #include "WwiseResourceLoaderImpl.generated.h"
  39. class IWwiseSoundBankManager;
  40. class IWwiseMediaManager;
  41. class IWwiseExternalSourceManager;
  42. /**
  43. * @brief What reload strategy should be used for language changes
  44. */
  45. UENUM()
  46. enum EWwiseReloadLanguage
  47. {
  48. /// Don't reload anything. The game is fully responsible to reload elements. This doesn't call
  49. /// any operation on the SoundEngine side, so everything will keep on working as usual.
  50. Manual,
  51. /// Reloads immediately without stopping anything. Game is responsible for stopping and restarting
  52. /// possibly affected sounds or else they might cause audible breaks. This is useful when some
  53. /// sounds can keep on playing, such as music and ambient sounds, while the dialogues are being
  54. /// internally reloaded.
  55. ///
  56. /// Depending on the quantity of currently loaded localized banks, the operation can take a long time.
  57. ///
  58. /// \warning Affected events needs to be restarted once the operation is done.
  59. Immediate,
  60. /// Stops all sounds first, unloads all the localized banks, and reloads the new language. This will
  61. /// cause an audible break while the operation is done.
  62. ///
  63. /// Depending on the quantity of currently loaded localized banks, the operation can take a long time.
  64. ///
  65. /// \warning Affected events needs to be restarted once the operation is done.
  66. Safe
  67. };
  68. /**
  69. * @brief Whether the WwiseResourceLoader is allowed to load/unload assets
  70. */
  71. enum class EWwiseResourceLoaderState
  72. {
  73. /// Do not allow the WwiseResourceLoader to load/unload assets
  74. AlwaysDisabled,
  75. /// Allow the WwiseResourceLoader to load/unload assets
  76. Enabled,
  77. };
  78. struct WWISERESOURCELOADER_API FWwiseSwitchContainerLeafGroupValueUsageCount
  79. {
  80. /**
  81. * @brief SwitchContainer Leaf this structure represents.
  82. */
  83. const FWwiseSwitchContainerLeafCookedData Key;
  84. /**
  85. * @brief Number of GroupValues present in this key that are already loaded.
  86. */
  87. TSet<FWwiseGroupValueCookedData> LoadedGroupValues;
  88. /**
  89. * @brief Resources represented by the Key that were successfully loaded.
  90. */
  91. struct WWISERESOURCELOADER_API FLoadedData
  92. {
  93. FLoadedData();
  94. TArray<const FWwiseSoundBankCookedData*> LoadedSoundBanks;
  95. TArray<const FWwiseExternalSourceCookedData*> LoadedExternalSources;
  96. TArray<const FWwiseMediaCookedData*> LoadedMedia;
  97. int IsProcessing{0};
  98. bool IsLoaded() const;
  99. } LoadedData;
  100. FWwiseSwitchContainerLeafGroupValueUsageCount(const FWwiseSwitchContainerLeafCookedData& InKey);
  101. bool HaveAllKeys() const;
  102. };
  103. struct WWISERESOURCELOADER_API FWwiseSwitchContainerLoadedGroupValueInfo
  104. {
  105. /**
  106. * @brief GroupValue key this structure represents.
  107. */
  108. FWwiseSharedGroupValueKey Key;
  109. /**
  110. * @brief Number of times this particular GroupValue got loaded in the currently loaded maps.
  111. *
  112. * Any value higher than 0 means there's a chance the Leaves might be required.
  113. */
  114. int LoadCount;
  115. /**
  116. * @brief Leaves that uses this particular GroupValue.
  117. *
  118. * @note The ownership of this pointer is uniquely created and discarded during SwitchContainerLeaf loading and unloading.
  119. */
  120. TSet<TSharedRef<FWwiseSwitchContainerLeafGroupValueUsageCount, ESPMode::ThreadSafe>> Leaves;
  121. FWwiseSwitchContainerLoadedGroupValueInfo(const FWwiseSharedGroupValueKey& InKey) :
  122. Key(InKey),
  123. LoadCount(0),
  124. Leaves()
  125. {}
  126. bool ShouldBeLoaded() const
  127. {
  128. check(LoadCount >= 0);
  129. return LoadCount > 0;
  130. }
  131. bool operator ==(const FWwiseSwitchContainerLoadedGroupValueInfo& InRhs) const
  132. {
  133. return Key == InRhs.Key;
  134. }
  135. bool operator !=(const FWwiseSwitchContainerLoadedGroupValueInfo& InRhs) const
  136. {
  137. return Key != InRhs.Key;
  138. }
  139. bool operator <(const FWwiseSwitchContainerLoadedGroupValueInfo& InRhs) const
  140. {
  141. return Key < InRhs.Key;
  142. }
  143. bool operator <=(const FWwiseSwitchContainerLoadedGroupValueInfo& InRhs) const
  144. {
  145. return Key <= InRhs.Key;
  146. }
  147. bool operator >(const FWwiseSwitchContainerLoadedGroupValueInfo& InRhs) const
  148. {
  149. return Key > InRhs.Key;
  150. }
  151. bool operator >=(const FWwiseSwitchContainerLoadedGroupValueInfo& InRhs) const
  152. {
  153. return Key >= InRhs.Key;
  154. }
  155. bool operator ==(const FWwiseSharedGroupValueKey& InRhs) const
  156. {
  157. return Key == InRhs;
  158. }
  159. bool operator !=(const FWwiseSharedGroupValueKey& InRhs) const
  160. {
  161. return Key != InRhs;
  162. }
  163. };
  164. inline uint32 GetTypeHash(const FWwiseSwitchContainerLoadedGroupValueInfo& InValue)
  165. {
  166. return GetTypeHash(InValue.Key);
  167. }
  168. class WWISERESOURCELOADER_API FWwiseResourceLoaderImpl
  169. {
  170. public:
  171. using FWwiseSetLanguageFuture = TWwiseFuture<void>;
  172. using FWwiseSetLanguagePromise = TWwisePromise<void>;
  173. static FWwiseResourceLoaderImpl* Instantiate()
  174. {
  175. if (auto* Module = IWwiseResourceLoaderModule::GetModule())
  176. {
  177. return Module->InstantiateResourceLoaderImpl();
  178. }
  179. return nullptr;
  180. }
  181. EWwiseResourceLoaderState WwiseResourceLoaderState = EWwiseResourceLoaderState::Enabled;
  182. /**
  183. * @brief Currently targeted platform for this runtime
  184. */
  185. FWwiseSharedPlatformId CurrentPlatform;
  186. /**
  187. * @brief Currently targeted language for this runtime
  188. */
  189. FWwiseLanguageCookedData CurrentLanguage;
  190. /**
  191. * @brief Location in the staged product where the SoundBank medias are found
  192. */
  193. FString StagePath;
  194. #if WITH_EDITORONLY_DATA
  195. /**
  196. * @brief Location where the Wwise Generated SoundBanks product is found on disk relative to the project
  197. */
  198. FDirectoryPath GeneratedSoundBanksPath;
  199. #endif
  200. ENamedThreads::Type TaskThread = ENamedThreads::AnyThread;
  201. /**
  202. * Constructor used when creating a default Resource Loader implementation. You should not create or use one yourself,
  203. * and you should use the WwiseResourceLoader::Get class accessor to retrieve a valid Resource Loader instance.
  204. *
  205. * This can be called by derived classes if you want to modify the default Resource Loader behavior.
  206. */
  207. FWwiseResourceLoaderImpl();
  208. /**
  209. * Constructor used for mock testing the Resource Loader. Hard-codes the different managers.
  210. *
  211. * @param ExternalSourceManager External Source Manager file handler to be used in this instance
  212. * @param MediaManager Media Manager file handler to be used in this instance
  213. * @param SoundBankManager SoundBank Manager file handler to be used in this instance
  214. */
  215. FWwiseResourceLoaderImpl(IWwiseExternalSourceManager& ExternalSourceManager, IWwiseMediaManager& MediaManager, IWwiseSoundBankManager& SoundBankManager);
  216. virtual ~FWwiseResourceLoaderImpl() {}
  217. FName GetUnrealExternalSourcePath() const;
  218. FString GetUnrealPath() const;
  219. FString GetUnrealPath(const FName& InPath) const { return GetUnrealPath(InPath.ToString()); }
  220. FString GetUnrealPath(const FString& InPath) const;
  221. FString GetUnrealStagePath(const FName& InPath) const;
  222. FString GetUnrealStagePath(const FString& InPath) const;
  223. #if WITH_EDITORONLY_DATA
  224. FString GetUnrealGeneratedSoundBanksPath(const FName& InPath) const { return GetUnrealGeneratedSoundBanksPath(InPath.ToString());}
  225. FString GetUnrealGeneratedSoundBanksPath(const FString& InPath) const;
  226. #endif
  227. virtual EWwiseResourceLoaderState GetResourceLoaderState();
  228. virtual void SetResourceLoaderState(EWwiseResourceLoaderState State);
  229. virtual bool IsEnabled();
  230. virtual void Disable();
  231. virtual void Enable();
  232. virtual void SetLanguageAsync(FWwiseSetLanguagePromise&& Promise, const FWwiseLanguageCookedData& InLanguage, EWwiseReloadLanguage InReloadLanguage);
  233. void SetPlatform(const FWwiseSharedPlatformId& InPlatform);
  234. virtual FWwiseLoadedAuxBusPtr CreateAuxBusNode(const FWwiseLocalizedAuxBusCookedData& InAuxBusCookedData, const FWwiseLanguageCookedData* InLanguageOverride);
  235. virtual void LoadAuxBusAsync(FWwiseLoadedAuxBusPromise&& Promise, FWwiseLoadedAuxBusPtr&& InAuxBusListNode);
  236. virtual void UnloadAuxBusAsync(FWwiseResourceUnloadPromise&& Promise, FWwiseLoadedAuxBusPtr&& InAuxBusListNode);
  237. virtual FWwiseLoadedEventPtr CreateEventNode(const FWwiseLocalizedEventCookedData& InEventCookedData, const FWwiseLanguageCookedData* InLanguageOverride);
  238. virtual void LoadEventAsync(FWwiseLoadedEventPromise&& Promise, FWwiseLoadedEventPtr&& InEventListNode);
  239. virtual void UnloadEventAsync(FWwiseResourceUnloadPromise&& Promise, FWwiseLoadedEventPtr&& InEventListNode);
  240. virtual FWwiseLoadedExternalSourcePtr CreateExternalSourceNode(const FWwiseExternalSourceCookedData& InExternalSourceCookedData);
  241. virtual void LoadExternalSourceAsync(FWwiseLoadedExternalSourcePromise&& Promise, FWwiseLoadedExternalSourcePtr&& InExternalSourceListNode);
  242. virtual void UnloadExternalSourceAsync(FWwiseResourceUnloadPromise&& Promise, FWwiseLoadedExternalSourcePtr&& InExternalSourceListNode);
  243. virtual FWwiseLoadedGroupValuePtr CreateGroupValueNode(const FWwiseGroupValueCookedData& InGroupValueCookedData);
  244. virtual void LoadGroupValueAsync(FWwiseLoadedGroupValuePromise&& Promise, FWwiseLoadedGroupValuePtr&& InGroupValueListNode);
  245. virtual void UnloadGroupValueAsync(FWwiseResourceUnloadPromise&& Promise, FWwiseLoadedGroupValuePtr&& InGroupValueListNode);
  246. virtual FWwiseLoadedInitBankPtr CreateInitBankNode(const FWwiseInitBankCookedData& InInitBankCookedData);
  247. virtual void LoadInitBankAsync(FWwiseLoadedInitBankPromise&& Promise, FWwiseLoadedInitBankPtr&& InInitBankListNode);
  248. virtual void UnloadInitBankAsync(FWwiseResourceUnloadPromise&& Promise, FWwiseLoadedInitBankPtr&& InInitBankListNode);
  249. virtual FWwiseLoadedMediaPtr CreateMediaNode(const FWwiseMediaCookedData& InMediaCookedData);
  250. virtual void LoadMediaAsync(FWwiseLoadedMediaPromise&& Promise, FWwiseLoadedMediaPtr&& InMediaListNode);
  251. virtual void UnloadMediaAsync(FWwiseResourceUnloadPromise&& Promise, FWwiseLoadedMediaPtr&& InMediaListNode);
  252. virtual FWwiseLoadedShareSetPtr CreateShareSetNode(const FWwiseLocalizedShareSetCookedData& InShareSetCookedData, const FWwiseLanguageCookedData* InLanguageOverride);
  253. virtual void LoadShareSetAsync(FWwiseLoadedShareSetPromise&& Promise, FWwiseLoadedShareSetPtr&& InShareSetListNode);
  254. virtual void UnloadShareSetAsync(FWwiseResourceUnloadPromise&& Promise, FWwiseLoadedShareSetPtr&& InShareSetListNode);
  255. virtual FWwiseLoadedSoundBankPtr CreateSoundBankNode(const FWwiseLocalizedSoundBankCookedData& InSoundBankCookedData, const FWwiseLanguageCookedData* InLanguageOverride);
  256. virtual void LoadSoundBankAsync(FWwiseLoadedSoundBankPromise&& Promise, FWwiseLoadedSoundBankPtr&& InSoundBankListNode);
  257. virtual void UnloadSoundBankAsync(FWwiseResourceUnloadPromise&& Promise, FWwiseLoadedSoundBankPtr&& InSoundBankListNode);
  258. // Checks whether no element remains pending in the Resource Loader at this point. Used for unit testing.
  259. bool IsEmpty() const
  260. {
  261. return LoadedAuxBusList.Num() == 0
  262. && LoadedEventList.Num() == 0
  263. && LoadedExternalSourceList.Num() == 0
  264. && LoadedGroupValueList.Num() == 0
  265. && LoadedInitBankList.Num() == 0
  266. && LoadedMediaList.Num() == 0
  267. && LoadedShareSetList.Num() == 0
  268. && LoadedSoundBankList.Num() == 0;
  269. }
  270. /**
  271. * Synchronously cleans up the Group Value info set. This is used for unit testing, and shouldn't be used by a final product.
  272. * @return true if the final set is empty
  273. */
  274. bool TrimGroupValueInfo();
  275. protected:
  276. using FLoadFileCallback = TUniqueFunction<void(bool bInResult)>;
  277. using FUnloadFileCallback = TUniqueFunction<void()>;
  278. using FCompletionCallback = TUniqueFunction<void()>;
  279. using FCompletionPromise = TWwisePromise<void>;
  280. using FCompletionFuture = TWwiseFuture<void>;
  281. using FCompletionFutureArray = TArray<FCompletionFuture>;
  282. FCriticalSection ListUpdateCriticalSection;
  283. /**
  284. * @brief List of all the loaded Auxiliary Bus Wwise Objects.
  285. *
  286. * This list is maintained through the LoadAuxBusAsync and UnloadAuxBusAsync operations.
  287. *
  288. * @note To modify this list, you must call the operation asynchronously through ListExecutionQueue.
  289. */
  290. FWwiseLoadedAuxBusList LoadedAuxBusList;
  291. /**
  292. * @brief List of all the loaded Event Wwise Objects.
  293. *
  294. * This list is maintained through the LoadEventAsync and UnloadEventAsync operations.
  295. *
  296. * @note To modify this list, you must call the operation asynchronously through ListExecutionQueue.
  297. */
  298. FWwiseLoadedEventList LoadedEventList;
  299. /**
  300. * @brief List of all the loaded External Source Wwise Objects.
  301. *
  302. * This list is maintained through the LoadExternalSourceAsync and UnloadExternalSourceAsync operations.
  303. *
  304. * External Sources are component parts of many other Wwise objects. Events, for example, can contain
  305. * their own External Sources. This list only contains the External Sources that were added independently,
  306. * not those that are already included in objects such as Events.
  307. *
  308. * @note To modify this list, you must call the operation asynchronously through ListExecutionQueue.
  309. */
  310. FWwiseLoadedExternalSourceList LoadedExternalSourceList;
  311. /**
  312. * @brief List of all the loaded GroupValue (States, Switches) Wwise Objects.
  313. *
  314. * This list is maintained through the LoadGroupValueAsync and UnloadGroupValueAsync operations.
  315. *
  316. * GroupValues are component parts of many other Wwise objects. Events, for example, can contain
  317. * their own GroupValues. This list only contains the GroupValues that were added independently,
  318. * not those that are already included in objects such as Events.
  319. *
  320. * @note To modify this list, you must call the operation asynchronously through ListExecutionQueue.
  321. */
  322. FWwiseLoadedGroupValueList LoadedGroupValueList;
  323. /**
  324. * @brief List of all the loaded Init Bank Wwise Objects.
  325. *
  326. * This list is maintained through the LoadInitBankAsync and UnloadInitBankAsync operations.
  327. *
  328. * @note In order to modify this list (add or remove), you must call the operation asynchronously through the
  329. * ListExecutionQueue.
  330. *
  331. * @warning Although this is a list, it can only include a single Init Bank. Each project supports one Init Bank,
  332. * which is used for the duration of the Sound Engine's lifespan.
  333. */
  334. FWwiseLoadedInitBankList LoadedInitBankList;
  335. /**
  336. * @brief List of all the loaded Media Wwise Objects.
  337. *
  338. * This list is maintained through the LoadMediaAsync and UnloadMediaAsync operations.
  339. *
  340. * Media objects are component parts of many other Wwise objects. Events, for example, can contain their
  341. * own Media objects. This list only contains the Media objects that were added independently, not those
  342. * that are already included in objects such as Events.
  343. *
  344. * @note To modify this list, you must call the operation asynchronously through ListExecutionQueue.
  345. */
  346. FWwiseLoadedMediaList LoadedMediaList;
  347. /**
  348. * @brief List of all the loaded Share Set Wwise Objects.
  349. *
  350. * This list is maintained through the LoadShareSetAsync and UnloadShareSetAsync operations.
  351. *
  352. * @note To modify this list, you must call the operation asynchronously through ListExecutionQueue.
  353. */
  354. FWwiseLoadedShareSetList LoadedShareSetList;
  355. /**
  356. * @brief List of all the loaded SoundBank Wwise Objects.
  357. *
  358. * This list is maintained through the LoadSoundBankAsync and UnloadSoundBankAsync operations.
  359. *
  360. * SoundBanks are building blocks of multiple other Wwise objects. An Event is included (and thus require) inside
  361. * a SoundBank. This list only contains the independently added SoundBanks, as the different objects, such as
  362. * Events, are responsible for keeping track of their own required sub-objects.
  363. *
  364. * @note To modify this list, you must call the operation asynchronously through ListExecutionQueue.
  365. */
  366. FWwiseLoadedSoundBankList LoadedSoundBankList;
  367. /**
  368. * @brief Set of all known GroupValues, each of which contains the list of the Switch Containers that require them.
  369. *
  370. * This set uses a leaking pattern: every known GroupValue appears but is never deleted. Realistically, games have
  371. * fewer than ten thousand different Switches and States, so the effect on memory and performance is minimal.
  372. *
  373. * @note To modify this list, you must call the operation asynchronously through FileExecutionQueue.
  374. */
  375. TSet<FWwiseSwitchContainerLoadedGroupValueInfo> LoadedGroupValueInfo;
  376. mutable FWwiseExecutionQueue ExecutionQueue;
  377. mutable IWwiseExternalSourceManager* ExternalSourceManager{nullptr};
  378. mutable IWwiseMediaManager* MediaManager{nullptr};
  379. mutable IWwiseSoundBankManager* SoundBankManager{nullptr};
  380. virtual void LoadAuxBusResources(FWwiseResourceLoadPromise&& Promise, FWwiseLoadedAuxBusInfo::FLoadedData& LoadedData, const FWwiseAuxBusCookedData& InCookedData);
  381. virtual void LoadEventResources(FWwiseResourceLoadPromise&& Promise, FWwiseLoadedEventInfo::FLoadedData& LoadedData, const FWwiseEventCookedData& InCookedData);
  382. virtual void LoadEventSwitchContainerResources(FWwiseResourceLoadPromise&& Promise, FWwiseLoadedEventInfo::FLoadedData& LoadedData, const FWwiseEventCookedData& InCookedData);
  383. virtual void LoadExternalSourceResources(FWwiseResourceLoadPromise&& Promise, FWwiseLoadedExternalSourceInfo::FLoadedData& LoadedData, const FWwiseExternalSourceCookedData& InCookedData);
  384. virtual void LoadGroupValueResources(FWwiseResourceLoadPromise&& Promise, FWwiseLoadedGroupValueInfo::FLoadedData& LoadedData, const FWwiseGroupValueCookedData& InCookedData);
  385. virtual void LoadInitBankResources(FWwiseResourceLoadPromise&& Promise, FWwiseLoadedInitBankInfo::FLoadedData& LoadedData, const FWwiseInitBankCookedData& InCookedData);
  386. virtual void LoadMediaResources(FWwiseResourceLoadPromise&& Promise, FWwiseLoadedMediaInfo::FLoadedData& LoadedData, const FWwiseMediaCookedData& InCookedData);
  387. virtual void LoadShareSetResources(FWwiseResourceLoadPromise&& Promise, FWwiseLoadedShareSetInfo::FLoadedData& LoadedData, const FWwiseShareSetCookedData& InCookedData);
  388. virtual void LoadSoundBankResources(FWwiseResourceLoadPromise&& Promise, FWwiseLoadedSoundBankInfo::FLoadedData& LoadedData, const FWwiseSoundBankCookedData& InCookedData);
  389. virtual void LoadSwitchContainerLeafResources(FCompletionPromise&& Promise, TSharedRef<FWwiseSwitchContainerLeafGroupValueUsageCount, ESPMode::ThreadSafe> UsageCount);
  390. virtual void UnloadAuxBusResources(FWwiseResourceUnloadPromise&& Promise, FWwiseLoadedAuxBusInfo::FLoadedData& LoadedData, const FWwiseAuxBusCookedData& InCookedData);
  391. virtual void UnloadEventResources(FWwiseResourceUnloadPromise&& Promise, FWwiseLoadedEventInfo::FLoadedData& LoadedData, const FWwiseEventCookedData& InCookedData);
  392. virtual void UnloadEventSwitchContainerResources(FWwiseResourceUnloadPromise&& Promise, FWwiseLoadedEventInfo::FLoadedData& LoadedData, const FWwiseEventCookedData& InCookedData);
  393. virtual void UnloadExternalSourceResources(FWwiseResourceUnloadPromise&& Promise, FWwiseLoadedExternalSourceInfo::FLoadedData& LoadedData, const FWwiseExternalSourceCookedData& InCookedData);
  394. virtual void UnloadGroupValueResources(FWwiseResourceUnloadPromise&& Promise, FWwiseLoadedGroupValueInfo::FLoadedData& LoadedData, const FWwiseGroupValueCookedData& InCookedData);
  395. virtual void UnloadInitBankResources(FWwiseResourceUnloadPromise&& Promise, FWwiseLoadedInitBankInfo::FLoadedData& LoadedData, const FWwiseInitBankCookedData& InCookedData);
  396. virtual void UnloadMediaResources(FWwiseResourceUnloadPromise&& Promise, FWwiseLoadedMediaInfo::FLoadedData& LoadedData, const FWwiseMediaCookedData& InCookedData);
  397. virtual void UnloadShareSetResources(FWwiseResourceUnloadPromise&& Promise, FWwiseLoadedShareSetInfo::FLoadedData& LoadedData, const FWwiseShareSetCookedData& InCookedData);
  398. virtual void UnloadSoundBankResources(FWwiseResourceUnloadPromise&& Promise, FWwiseLoadedSoundBankInfo::FLoadedData& LoadedData, const FWwiseSoundBankCookedData& InCookedData);
  399. virtual void UnloadSwitchContainerLeafResources(FWwiseResourceUnloadPromise&& Promise, TSharedRef<FWwiseSwitchContainerLeafGroupValueUsageCount, ESPMode::ThreadSafe> UsageCount);
  400. virtual void AttachAuxBusNode(FWwiseLoadedAuxBusListNode* AuxBusListNode);
  401. virtual void AttachEventNode(FWwiseLoadedEventListNode* EventListNode);
  402. virtual void AttachExternalSourceNode(FWwiseLoadedExternalSourceListNode* ExternalSourceListNode);
  403. virtual void AttachGroupValueNode(FWwiseLoadedGroupValueListNode* GroupValueListNode);
  404. virtual void AttachInitBankNode(FWwiseLoadedInitBankListNode* InitBankListNode);
  405. virtual void AttachMediaNode(FWwiseLoadedMediaListNode* MediaListNode);
  406. virtual void AttachShareSetNode(FWwiseLoadedShareSetListNode* ShareSetListNode);
  407. virtual void AttachSoundBankNode(FWwiseLoadedSoundBankListNode* SoundBankListNode);
  408. virtual void DetachAuxBusNode(FWwiseLoadedAuxBusListNode* AuxBusListNode);
  409. virtual void DetachEventNode(FWwiseLoadedEventListNode* EventListNode);
  410. virtual void DetachExternalSourceNode(FWwiseLoadedExternalSourceListNode* ExternalSourceListNode);
  411. virtual void DetachGroupValueNode(FWwiseLoadedGroupValueListNode* GroupValueListNode);
  412. virtual void DetachInitBankNode(FWwiseLoadedInitBankListNode* InitBankListNode);
  413. virtual void DetachMediaNode(FWwiseLoadedMediaListNode* MediaListNode);
  414. virtual void DetachShareSetNode(FWwiseLoadedShareSetListNode* ShareSetListNode);
  415. virtual void DetachSoundBankNode(FWwiseLoadedSoundBankListNode* SoundBankListNode);
  416. void AddLoadExternalSourceFutures(FCompletionFutureArray& FutureArray, TArray<const FWwiseExternalSourceCookedData*>& LoadedExternalSources,
  417. const TArray<FWwiseExternalSourceCookedData>& InExternalSources, const TCHAR* InType, const FString& InDebugName, uint32 InShortId) const;
  418. void AddUnloadExternalSourceFutures(FCompletionFutureArray& FutureArray, TArray<const FWwiseExternalSourceCookedData*>& LoadedExternalSources,
  419. const TCHAR* InType, const FString& InDebugName, uint32 InShortId) const;
  420. void AddLoadMediaFutures(FCompletionFutureArray& FutureArray, TArray<const FWwiseMediaCookedData*>& LoadedMedia,
  421. const TArray<FWwiseMediaCookedData>& InMedia, const TCHAR* InType, const FString& InDebugName, uint32 InShortId) const;
  422. void AddUnloadMediaFutures(FCompletionFutureArray& FutureArray, TArray<const FWwiseMediaCookedData*>& LoadedMedia,
  423. const TCHAR* InType, const FString& InDebugName, uint32 InShortId) const;
  424. void AddLoadSoundBankFutures(FCompletionFutureArray& FutureArray, TArray<const FWwiseSoundBankCookedData*>& LoadedSoundBanks,
  425. const TArray<FWwiseSoundBankCookedData>& InSoundBank, const TCHAR* InType, const FString& InDebugName, uint32 InShortId) const;
  426. void AddUnloadSoundBankFutures(FCompletionFutureArray& FutureArray, TArray<const FWwiseSoundBankCookedData*>& LoadedSoundBanks,
  427. const TCHAR* InType, const FString& InDebugName, uint32 InShortId) const;
  428. void WaitForFutures(FCompletionFutureArray&& FutureArray, FCompletionCallback&& Callback, int NextId = 0) const;
  429. void LoadSoundBankFile(const FWwiseSoundBankCookedData& InSoundBank, FLoadFileCallback&& InCallback) const;
  430. void UnloadSoundBankFile(const FWwiseSoundBankCookedData& InSoundBank, FUnloadFileCallback&& InCallback) const;
  431. void LoadMediaFile(const FWwiseMediaCookedData& InMedia, FLoadFileCallback&& InCallback) const;
  432. void UnloadMediaFile(const FWwiseMediaCookedData& InMedia, FUnloadFileCallback&& InCallback) const;
  433. void LoadExternalSourceFile(const FWwiseExternalSourceCookedData& InExternalSource, FLoadFileCallback&& InCallback) const;
  434. void UnloadExternalSourceFile(const FWwiseExternalSourceCookedData& InExternalSource, FUnloadFileCallback&& InCallback) const;
  435. template<typename MapValue>
  436. inline const FWwiseLanguageCookedData* GetLanguageMapKey(const TMap<FWwiseLanguageCookedData, MapValue>& Map, const FWwiseLanguageCookedData* InLanguageOverride, const FName& InDebugName) const;
  437. template<typename T>
  438. static inline void LogLoad(const T& Object);
  439. template<typename T>
  440. static inline void LogUnload(const T& Object);
  441. template<typename T>
  442. static inline void LogLoadResources(const T& Object);
  443. template<typename T>
  444. static inline void LogUnloadResources(const T& Object);
  445. template<typename T>
  446. static inline void LogLoadResources(const T& Object, void* Ptr);
  447. template<typename T>
  448. static inline void LogUnloadResources(const T& Object, void* Ptr);
  449. public:
  450. struct WWISERESOURCELOADER_API Test
  451. {
  452. #if defined(WITH_LOW_LEVEL_TESTS) && WITH_LOW_LEVEL_TESTS || defined(WITH_AUTOMATION_TESTS) || (WITH_DEV_AUTOMATION_TESTS || WITH_PERF_AUTOMATION_TESTS)
  453. #define WWISE_RESOURCELOADERIMPL_TEST_CONST
  454. #else
  455. #define WWISE_RESOURCELOADERIMPL_TEST_CONST const
  456. #endif
  457. static WWISE_RESOURCELOADERIMPL_TEST_CONST bool bMockSleepOnMediaLoad;
  458. };
  459. };
  460. template <typename T>
  461. void FWwiseResourceLoaderImpl::LogLoad(const T& Object)
  462. {
  463. UE_LOG(LogWwiseResourceLoader, Verbose, TEXT("Loading %s"), *Object.GetDebugString());
  464. }
  465. template <typename T>
  466. void FWwiseResourceLoaderImpl::LogUnload(const T& Object)
  467. {
  468. UE_LOG(LogWwiseResourceLoader, Verbose, TEXT("Unloading %s"), *Object.GetDebugString());
  469. }
  470. template <typename T>
  471. void FWwiseResourceLoaderImpl::LogLoadResources(const T& Object)
  472. {
  473. UE_LOG(LogWwiseResourceLoader, VeryVerbose, TEXT("Loading resources for %s"), *Object.GetDebugString());
  474. }
  475. template <typename T>
  476. void FWwiseResourceLoaderImpl::LogUnloadResources(const T& Object)
  477. {
  478. UE_LOG(LogWwiseResourceLoader, VeryVerbose, TEXT("Unloading resources for %s"), *Object.GetDebugString());
  479. }
  480. template <typename T>
  481. void FWwiseResourceLoaderImpl::LogLoadResources(const T& Object, void* Ptr)
  482. {
  483. UE_LOG(LogWwiseResourceLoader, VeryVerbose, TEXT("Loading resources for %s @ %p"), *Object.GetDebugString(), Ptr);
  484. }
  485. template <typename T>
  486. void FWwiseResourceLoaderImpl::LogUnloadResources(const T& Object, void* Ptr)
  487. {
  488. UE_LOG(LogWwiseResourceLoader, VeryVerbose, TEXT("Unloading resources for %s @ %p"), *Object.GetDebugString(), Ptr);
  489. }
  490. template<typename MapValue>
  491. inline const FWwiseLanguageCookedData* FWwiseResourceLoaderImpl::GetLanguageMapKey(const TMap<FWwiseLanguageCookedData, MapValue>& Map, const FWwiseLanguageCookedData* InLanguageOverride, const FName& InDebugName) const
  492. {
  493. if (InLanguageOverride)
  494. {
  495. if (Map.Find(*InLanguageOverride))
  496. {
  497. return InLanguageOverride;
  498. }
  499. UE_LOG(LogWwiseResourceLoader, Log, TEXT("GetLanguageMapKey: Could not find overridden language %s while processing asset %s. Defaulting to language %s"),
  500. *InLanguageOverride->GetLanguageName().ToString(), *InDebugName.ToString(), *CurrentLanguage.GetLanguageName().ToString());
  501. }
  502. if (LIKELY(Map.Contains(FWwiseLanguageCookedData::Sfx)))
  503. {
  504. return &FWwiseLanguageCookedData::Sfx;
  505. }
  506. if (Map.Find(CurrentLanguage))
  507. {
  508. return &CurrentLanguage;
  509. }
  510. UE_LOG(LogWwiseResourceLoader, Warning, TEXT("GetLanguageMapKey: Could not find language %s while processing asset %s."),
  511. *CurrentLanguage.GetLanguageName().ToString(), *InDebugName.ToString());
  512. return nullptr;
  513. }