WwiseProjectDatabaseImpl.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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/WwiseProjectDatabaseImpl.h"
  16. #include "WwiseUnrealHelper.h"
  17. #include "Wwise/Metadata/WwiseMetadataPlatformInfo.h"
  18. #include "Wwise/WwiseResourceLoader.h"
  19. #include "Wwise/WwiseProjectDatabaseDelegates.h"
  20. #include "Async/Async.h"
  21. #include "Misc/ScopedSlowTask.h"
  22. #define LOCTEXT_NAMESPACE "WwiseProjectDatabase"
  23. FWwiseProjectDatabaseImpl::FWwiseProjectDatabaseImpl() :
  24. ResourceLoaderOverride(nullptr),
  25. LockedDataStructure(new FWwiseDataStructure())
  26. {
  27. }
  28. FWwiseProjectDatabaseImpl::~FWwiseProjectDatabaseImpl()
  29. {
  30. }
  31. void FWwiseProjectDatabaseImpl::UpdateDataStructure(const FDirectoryPath* InUpdateGeneratedSoundBanksPath, const FGuid* InBasePlatformGuid)
  32. {
  33. SCOPED_WWISEPROJECTDATABASE_EVENT_2(TEXT("FWwiseProjectDatabaseImpl::UpdateDataStructure"));
  34. FWwiseSharedPlatformId Platform;
  35. FDirectoryPath SourcePath;
  36. {
  37. auto* ResourceLoader = GetResourceLoader();
  38. if (UNLIKELY(!ResourceLoader))
  39. {
  40. return;
  41. }
  42. if (InUpdateGeneratedSoundBanksPath)
  43. {
  44. ResourceLoader->SetUnrealGeneratedSoundBanksPath(*InUpdateGeneratedSoundBanksPath);
  45. }
  46. Platform = ResourceLoader->GetCurrentPlatform();
  47. SourcePath = ResourceLoader->GetUnrealGeneratedSoundBanksPath();
  48. }
  49. {
  50. FWriteScopeLock WLock(LockedDataStructure->Lock);
  51. auto& DataStructure = LockedDataStructure.Get();
  52. if (DisableDefaultPlatforms())
  53. {
  54. UE_LOG(LogWwiseProjectDatabase, Log, TEXT("UpdateDataStructure: Retrieving root data structure in (%s)"), *SourcePath.Path);
  55. FScopedSlowTask SlowTask(0, LOCTEXT("WwiseProjectDatabaseUpdate", "Retrieving Wwise data structure root..."));
  56. {
  57. FWwiseDataStructure UpdatedDataStructure(SourcePath, nullptr, nullptr);
  58. DataStructure = MoveTemp(UpdatedDataStructure);
  59. }
  60. }
  61. else
  62. {
  63. UE_LOG(LogWwiseProjectDatabase, Log, TEXT("UpdateDataStructure: Retrieving data structure for %s (Base: %s) in (%s)"),
  64. *Platform.GetPlatformName().ToString(), InBasePlatformGuid ? *InBasePlatformGuid->ToString() : TEXT("null"), *SourcePath.Path);
  65. FScopedSlowTask SlowTask(0, FText::Format(
  66. LOCTEXT("WwiseProjectDatabaseUpdate", "Retrieving Wwise data structure for platform {0}..."),
  67. FText::FromName(Platform.GetPlatformName())));
  68. {
  69. FWwiseDataStructure UpdatedDataStructure(SourcePath, &Platform.GetPlatformName(), InBasePlatformGuid);
  70. DataStructure = MoveTemp(UpdatedDataStructure);
  71. // Update platform according to data found if different
  72. FWwiseSharedPlatformId FoundSimilarPlatform = Platform;
  73. for (const auto& LoadedPlatform : DataStructure.Platforms)
  74. {
  75. FoundSimilarPlatform = LoadedPlatform.Key;
  76. if (FoundSimilarPlatform == Platform)
  77. {
  78. break;
  79. }
  80. }
  81. //Update SharedPlatformId with parsed root paths
  82. if (DataStructure.Platforms.Contains(FoundSimilarPlatform) )
  83. {
  84. const FWwisePlatformDataStructure& PlatformEntry = DataStructure.Platforms.FindRef(FoundSimilarPlatform);
  85. FoundSimilarPlatform.Platform->ExternalSourceRootPath = PlatformEntry.PlatformRef.GetPlatformInfo()->RootPaths.ExternalSourcesOutputRoot;
  86. }
  87. //Update the resource loader current platform as internal data may have changed
  88. auto* ResourceLoader = GetResourceLoader();
  89. if (UNLIKELY(!ResourceLoader))
  90. {
  91. return;
  92. }
  93. ResourceLoader->SetPlatform(FoundSimilarPlatform);
  94. }
  95. if (UNLIKELY(DataStructure.Platforms.Num() == 0))
  96. {
  97. if(!InBasePlatformGuid)
  98. {
  99. UE_LOG(LogWwiseProjectDatabase, Error, TEXT("JSON metadata files are not generated. Make sure the SoundBanks are generated and that the \"Generate JSON Metadata\" setting is enabled in your Wwise Project Settings, under the SoundBanks tab."));
  100. return;
  101. }
  102. UE_LOG(LogWwiseProjectDatabase, Error, TEXT("UpdateDataStructure: Could not find suitable platform for %s (Base: %s) in (%s)"),
  103. *Platform.GetPlatformName().ToString(), InBasePlatformGuid ? *InBasePlatformGuid->ToString() : TEXT("null"), *SourcePath.Path);
  104. return;
  105. }
  106. }
  107. bIsDatabaseParsed = true;
  108. UE_LOG(LogWwiseProjectDatabase, Log, TEXT("UpdateDataStructure: Done."));
  109. }
  110. if (Get() == this && bShouldBroadcast) // Only broadcast database updates on main project.
  111. {
  112. //Stop multiple threads from Broadcasting this delegate at the same time.
  113. bShouldBroadcast = false;
  114. FWwiseProjectDatabaseDelegates::Get()->GetOnDatabaseUpdateCompletedDelegate().Broadcast();
  115. bShouldBroadcast = true;
  116. }
  117. }
  118. void FWwiseProjectDatabaseImpl::PrepareProjectDatabaseForPlatform(FWwiseResourceLoader*&& InResourceLoader)
  119. {
  120. ResourceLoaderOverride.Reset(InResourceLoader);
  121. }
  122. FWwiseResourceLoader* FWwiseProjectDatabaseImpl::GetResourceLoader()
  123. {
  124. if (ResourceLoaderOverride.IsValid())
  125. {
  126. return ResourceLoaderOverride.Get();
  127. }
  128. else
  129. {
  130. return FWwiseResourceLoader::Get();
  131. }
  132. }
  133. const FWwiseResourceLoader* FWwiseProjectDatabaseImpl::GetResourceLoader() const
  134. {
  135. if (ResourceLoaderOverride.IsValid())
  136. {
  137. return ResourceLoaderOverride.Get();
  138. }
  139. else
  140. {
  141. return FWwiseResourceLoader::Get();
  142. }
  143. }
  144. #undef LOCTEXT_NAMESPACE