WwiseProjectDatabase.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  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/WwiseProjectDatabase.h"
  16. #include "Wwise/WwiseResourceLoader.h"
  17. #include "Wwise/WwiseProjectDatabaseDelegates.h"
  18. #include "Async/Async.h"
  19. #include "Misc/ScopedSlowTask.h"
  20. #include "Wwise/Metadata/WwiseMetadataPlatformInfo.h"
  21. #define LOCTEXT_NAMESPACE "WwiseProjectDatabase"
  22. FWwiseDataStructureScopeLock::FWwiseDataStructureScopeLock(const FWwiseProjectDatabase& InProjectDatabase) :
  23. FRWScopeLock(const_cast<FRWLock&>(InProjectDatabase.GetLockedDataStructure()->Lock), SLT_ReadOnly),
  24. DataStructure(*InProjectDatabase.GetLockedDataStructure()),
  25. CurrentLanguage(InProjectDatabase.GetCurrentLanguage()),
  26. CurrentPlatform(InProjectDatabase.GetCurrentPlatform()),
  27. bDisableDefaultPlatforms(InProjectDatabase.DisableDefaultPlatforms())
  28. {
  29. }
  30. const WwiseAcousticTextureGlobalIdsMap& FWwiseDataStructureScopeLock::GetAcousticTextures() const
  31. {
  32. static const auto Empty = WwiseAcousticTextureGlobalIdsMap();
  33. const auto* PlatformData = GetCurrentPlatformData();
  34. if (UNLIKELY(!PlatformData)) return Empty;
  35. return PlatformData->AcousticTextures;
  36. }
  37. FWwiseRefAcousticTexture FWwiseDataStructureScopeLock::GetAcousticTexture(const FWwiseObjectInfo& InInfo) const
  38. {
  39. const auto* PlatformData = GetCurrentPlatformData();
  40. if (UNLIKELY(!PlatformData)) return {};
  41. FWwiseRefAcousticTexture Result;
  42. PlatformData->GetRef(Result, GetCurrentLanguage(), InInfo);
  43. return Result;
  44. }
  45. const WwiseAudioDeviceGlobalIdsMap& FWwiseDataStructureScopeLock::GetAudioDevices() const
  46. {
  47. static const auto Empty = WwiseAudioDeviceGlobalIdsMap();
  48. const auto* PlatformData = GetCurrentPlatformData();
  49. if (UNLIKELY(!PlatformData)) return Empty;
  50. return PlatformData->AudioDevices;
  51. }
  52. FWwiseRefAudioDevice FWwiseDataStructureScopeLock::GetAudioDevice(const FWwiseObjectInfo& InInfo) const
  53. {
  54. const auto* PlatformData = GetCurrentPlatformData();
  55. if (UNLIKELY(!PlatformData)) return {};
  56. FWwiseRefAudioDevice Result;
  57. PlatformData->GetRef(Result, GetCurrentLanguage(), InInfo);
  58. return Result;
  59. }
  60. const WwiseAuxBusGlobalIdsMap& FWwiseDataStructureScopeLock::GetAuxBusses() const
  61. {
  62. static const auto Empty = WwiseAuxBusGlobalIdsMap();
  63. const auto* PlatformData = GetCurrentPlatformData();
  64. if (UNLIKELY(!PlatformData)) return Empty;
  65. return PlatformData->AuxBusses;
  66. }
  67. FWwiseRefAuxBus FWwiseDataStructureScopeLock::GetAuxBus(const FWwiseObjectInfo& InInfo) const
  68. {
  69. const auto* PlatformData = GetCurrentPlatformData();
  70. if (UNLIKELY(!PlatformData)) return {};
  71. FWwiseRefAuxBus Result;
  72. PlatformData->GetRef(Result, GetCurrentLanguage(), InInfo);
  73. return Result;
  74. }
  75. const WwiseBusGlobalIdsMap& FWwiseDataStructureScopeLock::GetBusses() const
  76. {
  77. static const auto Empty = WwiseBusGlobalIdsMap();
  78. const auto* PlatformData = GetCurrentPlatformData();
  79. if (UNLIKELY(!PlatformData)) return Empty;
  80. return PlatformData->Busses;
  81. }
  82. FWwiseRefBus FWwiseDataStructureScopeLock::GetBus(const FWwiseObjectInfo& InInfo) const
  83. {
  84. const auto* PlatformData = GetCurrentPlatformData();
  85. if (UNLIKELY(!PlatformData)) return {};
  86. FWwiseRefBus Result;
  87. PlatformData->GetRef(Result, GetCurrentLanguage(), InInfo);
  88. return Result;
  89. }
  90. const WwiseCustomPluginGlobalIdsMap& FWwiseDataStructureScopeLock::GetCustomPlugins() const
  91. {
  92. static const auto Empty = WwiseCustomPluginGlobalIdsMap();
  93. const auto* PlatformData = GetCurrentPlatformData();
  94. if (UNLIKELY(!PlatformData)) return Empty;
  95. return PlatformData->CustomPlugins;
  96. }
  97. FWwiseRefCustomPlugin FWwiseDataStructureScopeLock::GetCustomPlugin(const FWwiseObjectInfo& InInfo) const
  98. {
  99. const auto* PlatformData = GetCurrentPlatformData();
  100. if (UNLIKELY(!PlatformData)) return {};
  101. FWwiseRefCustomPlugin Result;
  102. PlatformData->GetRef(Result, GetCurrentLanguage(), InInfo);
  103. return Result;
  104. }
  105. const WwiseDialogueArgumentGlobalIdsMap& FWwiseDataStructureScopeLock::GetDialogueArguments() const
  106. {
  107. static const auto Empty = WwiseDialogueArgumentGlobalIdsMap();
  108. const auto* PlatformData = GetCurrentPlatformData();
  109. if (UNLIKELY(!PlatformData)) return Empty;
  110. return PlatformData->DialogueArguments;
  111. }
  112. FWwiseRefDialogueArgument FWwiseDataStructureScopeLock::GetDialogueArgument(const FWwiseObjectInfo& InInfo) const
  113. {
  114. const auto* PlatformData = GetCurrentPlatformData();
  115. if (UNLIKELY(!PlatformData)) return {};
  116. FWwiseRefDialogueArgument Result;
  117. PlatformData->GetRef(Result, GetCurrentLanguage(), InInfo);
  118. return Result;
  119. }
  120. const WwiseDialogueEventGlobalIdsMap& FWwiseDataStructureScopeLock::GetDialogueEvents() const
  121. {
  122. static const auto Empty = WwiseDialogueEventGlobalIdsMap();
  123. const auto* PlatformData = GetCurrentPlatformData();
  124. if (UNLIKELY(!PlatformData)) return Empty;
  125. return PlatformData->DialogueEvents;
  126. }
  127. FWwiseRefDialogueEvent FWwiseDataStructureScopeLock::GetDialogueEvent(const FWwiseObjectInfo& InInfo) const
  128. {
  129. const auto* PlatformData = GetCurrentPlatformData();
  130. if (UNLIKELY(!PlatformData)) return {};
  131. FWwiseRefDialogueEvent Result;
  132. PlatformData->GetRef(Result, GetCurrentLanguage(), InInfo);
  133. return Result;
  134. }
  135. const WwiseEventGlobalIdsMap& FWwiseDataStructureScopeLock::GetEvents() const
  136. {
  137. static const auto Empty = WwiseEventGlobalIdsMap();
  138. const auto* PlatformData = GetCurrentPlatformData();
  139. if (UNLIKELY(!PlatformData)) return Empty;
  140. return PlatformData->Events;
  141. }
  142. TSet<FWwiseRefEvent> FWwiseDataStructureScopeLock::GetEvent(const FWwiseEventInfo& InInfo) const
  143. {
  144. const auto* PlatformData = GetCurrentPlatformData();
  145. if (UNLIKELY(!PlatformData)) return {};
  146. TSet<FWwiseRefEvent> Result;
  147. PlatformData->GetRef(Result, GetCurrentLanguage(), InInfo);
  148. return Result;
  149. }
  150. const WwiseExternalSourceGlobalIdsMap& FWwiseDataStructureScopeLock::GetExternalSources() const
  151. {
  152. static const auto Empty = WwiseExternalSourceGlobalIdsMap();
  153. const auto* PlatformData = GetCurrentPlatformData();
  154. if (UNLIKELY(!PlatformData)) return Empty;
  155. return PlatformData->ExternalSources;
  156. }
  157. FWwiseRefExternalSource FWwiseDataStructureScopeLock::GetExternalSource(const FWwiseObjectInfo& InInfo) const
  158. {
  159. const auto* PlatformData = GetCurrentPlatformData();
  160. if (UNLIKELY(!PlatformData)) return {};
  161. FWwiseRefExternalSource Result;
  162. PlatformData->GetRef(Result, GetCurrentLanguage(), InInfo);
  163. return Result;
  164. }
  165. const WwiseGameParameterGlobalIdsMap& FWwiseDataStructureScopeLock::GetGameParameters() const
  166. {
  167. static const auto Empty = WwiseGameParameterGlobalIdsMap();
  168. const auto* PlatformData = GetCurrentPlatformData();
  169. if (UNLIKELY(!PlatformData)) return Empty;
  170. return PlatformData->GameParameters;
  171. }
  172. FWwiseRefGameParameter FWwiseDataStructureScopeLock::GetGameParameter(const FWwiseObjectInfo& InInfo) const
  173. {
  174. const auto* PlatformData = GetCurrentPlatformData();
  175. if (UNLIKELY(!PlatformData)) return {};
  176. FWwiseRefGameParameter Result;
  177. PlatformData->GetRef(Result, GetCurrentLanguage(), InInfo);
  178. return Result;
  179. }
  180. const WwiseMediaGlobalIdsMap& FWwiseDataStructureScopeLock::GetMediaFiles() const
  181. {
  182. static const auto Empty = WwiseMediaGlobalIdsMap();
  183. const auto* PlatformData = GetCurrentPlatformData();
  184. if (UNLIKELY(!PlatformData)) return Empty;
  185. return PlatformData->MediaFiles;
  186. }
  187. FWwiseRefMedia FWwiseDataStructureScopeLock::GetMediaFile(const FWwiseObjectInfo& InInfo) const
  188. {
  189. const auto* PlatformData = GetCurrentPlatformData();
  190. if (UNLIKELY(!PlatformData)) return {};
  191. FWwiseRefMedia Result;
  192. PlatformData->GetRef(Result, GetCurrentLanguage(), InInfo);
  193. return Result;
  194. }
  195. const WwisePluginLibGlobalIdsMap& FWwiseDataStructureScopeLock::GetPluginLibs() const
  196. {
  197. static const auto Empty = WwisePluginLibGlobalIdsMap();
  198. const auto* PlatformData = GetCurrentPlatformData();
  199. if (UNLIKELY(!PlatformData)) return Empty;
  200. return PlatformData->PluginLibs;
  201. }
  202. FWwiseRefPluginLib FWwiseDataStructureScopeLock::GetPluginLib(const FWwiseObjectInfo& InInfo) const
  203. {
  204. const auto* PlatformData = GetCurrentPlatformData();
  205. if (UNLIKELY(!PlatformData)) return {};
  206. FWwiseRefPluginLib Result;
  207. PlatformData->GetRef(Result, GetCurrentLanguage(), InInfo);
  208. return Result;
  209. }
  210. const WwisePluginShareSetGlobalIdsMap& FWwiseDataStructureScopeLock::GetPluginShareSets() const
  211. {
  212. static const auto Empty = WwisePluginShareSetGlobalIdsMap();
  213. const auto* PlatformData = GetCurrentPlatformData();
  214. if (UNLIKELY(!PlatformData)) return Empty;
  215. return PlatformData->PluginShareSets;
  216. }
  217. FWwiseRefPluginShareSet FWwiseDataStructureScopeLock::GetPluginShareSet(const FWwiseObjectInfo& InInfo) const
  218. {
  219. const auto* PlatformData = GetCurrentPlatformData();
  220. if (UNLIKELY(!PlatformData)) return {};
  221. FWwiseRefPluginShareSet Result;
  222. PlatformData->GetRef(Result, GetCurrentLanguage(), InInfo);
  223. return Result;
  224. }
  225. const WwiseSoundBankGlobalIdsMap& FWwiseDataStructureScopeLock::GetSoundBanks() const
  226. {
  227. static const auto Empty = WwiseSoundBankGlobalIdsMap();
  228. const auto* PlatformData = GetCurrentPlatformData();
  229. if (UNLIKELY(!PlatformData)) return Empty;
  230. return PlatformData->SoundBanks;
  231. }
  232. FWwiseRefSoundBank FWwiseDataStructureScopeLock::GetSoundBank(const FWwiseObjectInfo& InInfo) const
  233. {
  234. const auto* PlatformData = GetCurrentPlatformData();
  235. if (UNLIKELY(!PlatformData)) return {};
  236. FWwiseRefSoundBank Result;
  237. PlatformData->GetRef(Result, GetCurrentLanguage(), InInfo);
  238. return Result;
  239. }
  240. const WwiseStateGlobalIdsMap& FWwiseDataStructureScopeLock::GetStates() const
  241. {
  242. static const auto Empty = WwiseStateGlobalIdsMap();
  243. const auto* PlatformData = GetCurrentPlatformData();
  244. if (UNLIKELY(!PlatformData)) return Empty;
  245. return PlatformData->States;
  246. }
  247. FWwiseRefState FWwiseDataStructureScopeLock::GetState(const FWwiseGroupValueInfo& InInfo) const
  248. {
  249. const auto* PlatformData = GetCurrentPlatformData();
  250. if (UNLIKELY(!PlatformData)) return {};
  251. FWwiseRefState Result;
  252. PlatformData->GetRef(Result, GetCurrentLanguage(), InInfo);
  253. return Result;
  254. }
  255. const WwiseStateGroupGlobalIdsMap& FWwiseDataStructureScopeLock::GetStateGroups() const
  256. {
  257. static const auto Empty = WwiseStateGroupGlobalIdsMap();
  258. const auto* PlatformData = GetCurrentPlatformData();
  259. if (UNLIKELY(!PlatformData)) return Empty;
  260. return PlatformData->StateGroups;
  261. }
  262. FWwiseRefStateGroup FWwiseDataStructureScopeLock::GetStateGroup(const FWwiseObjectInfo& InInfo) const
  263. {
  264. const auto* PlatformData = GetCurrentPlatformData();
  265. if (UNLIKELY(!PlatformData)) return {};
  266. FWwiseRefStateGroup Result;
  267. PlatformData->GetRef(Result, GetCurrentLanguage(), InInfo);
  268. return Result;
  269. }
  270. const WwiseSwitchGlobalIdsMap& FWwiseDataStructureScopeLock::GetSwitches() const
  271. {
  272. static const auto Empty = WwiseSwitchGlobalIdsMap();
  273. const auto* PlatformData = GetCurrentPlatformData();
  274. if (UNLIKELY(!PlatformData)) return Empty;
  275. return PlatformData->Switches;
  276. }
  277. FWwiseRefSwitch FWwiseDataStructureScopeLock::GetSwitch(const FWwiseGroupValueInfo& InInfo) const
  278. {
  279. const auto* PlatformData = GetCurrentPlatformData();
  280. if (UNLIKELY(!PlatformData)) return {};
  281. FWwiseRefSwitch Result;
  282. PlatformData->GetRef(Result, GetCurrentLanguage(), InInfo);
  283. return Result;
  284. }
  285. const WwiseSwitchGroupGlobalIdsMap& FWwiseDataStructureScopeLock::GetSwitchGroups() const
  286. {
  287. static const auto Empty = WwiseSwitchGroupGlobalIdsMap();
  288. const auto* PlatformData = GetCurrentPlatformData();
  289. if (UNLIKELY(!PlatformData)) return Empty;
  290. return PlatformData->SwitchGroups;
  291. }
  292. FWwiseRefSwitchGroup FWwiseDataStructureScopeLock::GetSwitchGroup(const FWwiseObjectInfo& InInfo) const
  293. {
  294. const auto* PlatformData = GetCurrentPlatformData();
  295. if (UNLIKELY(!PlatformData)) return {};
  296. FWwiseRefSwitchGroup Result;
  297. PlatformData->GetRef(Result, GetCurrentLanguage(), InInfo);
  298. return Result;
  299. }
  300. const WwiseTriggerGlobalIdsMap& FWwiseDataStructureScopeLock::GetTriggers() const
  301. {
  302. static const auto Empty = WwiseTriggerGlobalIdsMap();
  303. const auto* PlatformData = GetCurrentPlatformData();
  304. if (UNLIKELY(!PlatformData)) return Empty;
  305. return PlatformData->Triggers;
  306. }
  307. FWwiseRefTrigger FWwiseDataStructureScopeLock::GetTrigger(const FWwiseObjectInfo& InInfo) const
  308. {
  309. const auto* PlatformData = GetCurrentPlatformData();
  310. if (UNLIKELY(!PlatformData)) return {};
  311. FWwiseRefTrigger Result;
  312. PlatformData->GetRef(Result, GetCurrentLanguage(), InInfo);
  313. return Result;
  314. }
  315. const FWwisePlatformDataStructure* FWwiseDataStructureScopeLock::GetCurrentPlatformData() const
  316. {
  317. if (DisableDefaultPlatforms())
  318. {
  319. UE_LOG(LogWwiseProjectDatabase, VeryVerbose, TEXT("Trying to access current platform data when none is loaded by design (cooking)"));
  320. return nullptr;
  321. }
  322. const auto& Platform = GetCurrentPlatform();
  323. const auto* PlatformData = DataStructure.Platforms.Find(Platform);
  324. if (UNLIKELY(!PlatformData))
  325. {
  326. UE_LOG(LogWwiseProjectDatabase, Error, TEXT("Current platform %s not found"), *Platform.GetPlatformName().ToString());
  327. return nullptr;
  328. }
  329. return PlatformData;
  330. }
  331. const TSet<FWwiseSharedLanguageId>& FWwiseDataStructureScopeLock::GetLanguages() const
  332. {
  333. return DataStructure.RootData.Languages;
  334. }
  335. const TSet<FWwiseSharedPlatformId>& FWwiseDataStructureScopeLock::GetPlatforms() const
  336. {
  337. return DataStructure.RootData.Platforms;
  338. }
  339. FWwiseRefPlatform FWwiseDataStructureScopeLock::GetPlatform(const FWwiseSharedPlatformId& InPlatformId) const
  340. {
  341. if (const auto* Platform = DataStructure.RootData.PlatformGuids.Find(InPlatformId.GetPlatformGuid()))
  342. {
  343. return *Platform;
  344. }
  345. return {};
  346. }
  347. FWwiseDataStructureWriteScopeLock::FWwiseDataStructureWriteScopeLock(FWwiseProjectDatabase& InProjectDatabase) :
  348. FRWScopeLock(InProjectDatabase.GetLockedDataStructure()->Lock, SLT_Write),
  349. DataStructure(*InProjectDatabase.GetLockedDataStructure())
  350. {
  351. }
  352. #if PLATFORM_LINUX
  353. const FGuid FWwiseProjectDatabase::BasePlatformGuid(0xbd0bdf13, 0x3125454f, 0x8bfd3195, 0x37169f81);
  354. #elif PLATFORM_MAC
  355. const FGuid FWwiseProjectDatabase::BasePlatformGuid(0x9c6217d5, 0xdd114795, 0x87c16ce0, 0x2853c540);
  356. #elif PLATFORM_WINDOWS
  357. const FGuid FWwiseProjectDatabase::BasePlatformGuid(0x6e0cb257, 0xc6c84c5c, 0x83662740, 0xdfc441eb);
  358. #else
  359. static_assert(false);
  360. #endif
  361. FWwiseSharedLanguageId FWwiseProjectDatabase::GetCurrentLanguage() const
  362. {
  363. auto* ResourceLoader = GetResourceLoader();
  364. if (UNLIKELY(!ResourceLoader))
  365. {
  366. return {};
  367. }
  368. const auto CurrentLanguage = ResourceLoader->GetCurrentLanguage();
  369. return FWwiseSharedLanguageId(CurrentLanguage.GetLanguageId(), CurrentLanguage.GetLanguageName(), CurrentLanguage.LanguageRequirement);
  370. }
  371. FWwiseSharedPlatformId FWwiseProjectDatabase::GetCurrentPlatform() const
  372. {
  373. auto* ResourceLoader = GetResourceLoader();
  374. if (UNLIKELY(!ResourceLoader))
  375. {
  376. return {};
  377. }
  378. return ResourceLoader->GetCurrentPlatform();
  379. }
  380. bool FWwiseProjectDatabase::DisableDefaultPlatforms() const
  381. {
  382. return UNLIKELY(IWwiseProjectDatabaseModule::IsInACookingCommandlet()) && (Get() == this);
  383. }
  384. #undef LOCTEXT_NAMESPACE