AkInitBank.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 "AkInitBank.h"
  16. #include "Platforms/AkPlatformInfo.h"
  17. #include "Wwise/WwiseResourceLoader.h"
  18. #include "Wwise/Stats/AkAudio.h"
  19. #if WITH_EDITORONLY_DATA
  20. #include "Wwise/WwiseResourceCooker.h"
  21. #endif
  22. #if WITH_EDITORONLY_DATA
  23. void UAkInitBank::CookAdditionalFilesOverride(const TCHAR* PackageFilename, const ITargetPlatform* TargetPlatform,
  24. TFunctionRef<void(const TCHAR* Filename, void* Data, int64 Size)> WriteAdditionalFile)
  25. {
  26. auto* ResourceCooker = FWwiseResourceCooker::GetForPlatform(TargetPlatform);
  27. if (!ResourceCooker)
  28. {
  29. return;
  30. }
  31. ResourceCooker->SetSandboxRootPath(PackageFilename);
  32. ResourceCooker->CookInitBank(FWwiseObjectInfo::DefaultInitBank, WriteAdditionalFile);
  33. }
  34. void UAkInitBank::BeginCacheForCookedPlatformData(const ITargetPlatform* TargetPlatform)
  35. {
  36. auto PlatformID = UAkPlatformInfo::GetSharedPlatformInfo(TargetPlatform->IniPlatformName());
  37. FWwiseResourceCooker::CreateForPlatform(TargetPlatform, PlatformID, EWwiseExportDebugNameRule::Name);
  38. }
  39. #endif
  40. void UAkInitBank::Serialize(FArchive& Ar)
  41. {
  42. bAutoLoad = false;
  43. Super::Serialize(Ar);
  44. if (HasAnyFlags(RF_ClassDefaultObject))
  45. {
  46. return;
  47. }
  48. #if !UE_SERVER
  49. #if WITH_EDITORONLY_DATA
  50. if (Ar.IsCooking() && Ar.IsSaving() && !Ar.CookingTarget()->IsServerOnly())
  51. {
  52. FWwiseInitBankCookedData CookedDataToArchive;
  53. if (auto* ResourceCooker = FWwiseResourceCooker::GetForArchive(Ar))
  54. {
  55. ResourceCooker->PrepareCookedData(CookedDataToArchive, FWwiseObjectInfo::DefaultInitBank);
  56. }
  57. CookedDataToArchive.Serialize(Ar);
  58. }
  59. #else
  60. InitBankCookedData.Serialize(Ar);
  61. #endif
  62. #endif
  63. }
  64. void UAkInitBank::UnloadInitBank(bool bAsync)
  65. {
  66. if (LoadedInitBank)
  67. {
  68. auto* ResourceLoader = FWwiseResourceLoader::Get();
  69. if (UNLIKELY(!ResourceLoader))
  70. {
  71. return;
  72. }
  73. if (bAsync)
  74. {
  75. FWwiseLoadedInitBankPromise Promise;
  76. Promise.EmplaceValue(MoveTemp(LoadedInitBank));
  77. ResourceUnload = ResourceLoader->UnloadInitBankAsync(Promise.GetFuture());
  78. }
  79. else
  80. {
  81. ResourceLoader->UnloadInitBank(MoveTemp(LoadedInitBank));
  82. }
  83. LoadedInitBank = nullptr;
  84. }
  85. }
  86. #if WITH_EDITORONLY_DATA
  87. void UAkInitBank::PrepareCookedData()
  88. {
  89. if (IWwiseProjectDatabaseModule::IsInACookingCommandlet())
  90. {
  91. return;
  92. }
  93. auto* ResourceCooker = FWwiseResourceCooker::GetDefault();
  94. if (UNLIKELY(!ResourceCooker))
  95. {
  96. return;
  97. }
  98. if (UNLIKELY(!ResourceCooker->PrepareCookedData(InitBankCookedData, FWwiseObjectInfo::DefaultInitBank)))
  99. {
  100. return;
  101. }
  102. }
  103. #endif
  104. TArray<FWwiseLanguageCookedData> UAkInitBank::GetLanguages()
  105. {
  106. #if WITH_EDITORONLY_DATA
  107. PrepareCookedData();
  108. #endif
  109. return InitBankCookedData.Language;
  110. }
  111. void UAkInitBank::UnloadData(bool bAsync)
  112. {
  113. UnloadInitBank(bAsync);
  114. }
  115. void UAkInitBank::LoadInitBank()
  116. {
  117. SCOPED_AKAUDIO_EVENT_2(TEXT("LoadInitBank"));
  118. auto* ResourceLoader = FWwiseResourceLoader::Get();
  119. if (UNLIKELY(!ResourceLoader))
  120. {
  121. return;
  122. }
  123. if (LoadedInitBank)
  124. {
  125. UnloadInitBank(false);
  126. }
  127. #if WITH_EDITORONLY_DATA
  128. PrepareCookedData();
  129. #endif
  130. LoadedInitBank = ResourceLoader->LoadInitBank(InitBankCookedData);
  131. }
  132. #if WITH_EDITORONLY_DATA
  133. void UAkInitBank::MigrateWwiseObjectInfo()
  134. {
  135. //Do nothing because the DefaultInitBank info is used
  136. }
  137. FWwiseObjectInfo* UAkInitBank::GetInfoMutable()
  138. {
  139. return new FWwiseObjectInfo(FWwiseObjectInfo::DefaultInitBank.WwiseGuid, FWwiseObjectInfo::DefaultInitBank.WwiseShortId, FWwiseObjectInfo::DefaultInitBank.WwiseName);
  140. }
  141. #endif