AkRtpc.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 "AkRtpc.h"
  16. #if WITH_EDITORONLY_DATA
  17. #include "Wwise/WwiseProjectDatabase.h"
  18. #include "Wwise/WwiseResourceCooker.h"
  19. #include "AkAudioDevice.h"
  20. #endif
  21. void UAkRtpc::Serialize(FArchive& Ar)
  22. {
  23. Super::Serialize(Ar);
  24. if (HasAnyFlags(RF_ClassDefaultObject))
  25. {
  26. return;
  27. }
  28. #if !UE_SERVER
  29. #if WITH_EDITORONLY_DATA
  30. if (Ar.IsCooking() && Ar.IsSaving() && !Ar.CookingTarget()->IsServerOnly())
  31. {
  32. FWwiseGameParameterCookedData CookedDataToArchive;
  33. if (auto* ResourceCooker = FWwiseResourceCooker::GetForArchive(Ar))
  34. {
  35. ResourceCooker->PrepareCookedData(CookedDataToArchive, GetValidatedInfo(RtpcInfo));
  36. }
  37. CookedDataToArchive.Serialize(Ar);
  38. }
  39. #else
  40. GameParameterCookedData.Serialize(Ar);
  41. #endif
  42. #endif
  43. }
  44. #if WITH_EDITORONLY_DATA
  45. void UAkRtpc::GetGameParameterCookedData()
  46. {
  47. SCOPED_AKAUDIO_EVENT_2(TEXT("GetGameParameterCookedData"));
  48. if (!IWwiseProjectDatabaseModule::ShouldInitializeProjectDatabase())
  49. {
  50. return;
  51. }
  52. auto* ProjectDatabase = FWwiseProjectDatabase::Get();
  53. if (!ProjectDatabase || !ProjectDatabase->IsProjectDatabaseParsed())
  54. {
  55. UE_LOG(LogAkAudio, VeryVerbose, TEXT("UAkRtpc::GetGameParameterCookedData: Not loading '%s' because project database is not parsed."), *GetName())
  56. return;
  57. }
  58. auto* ResourceCooker = FWwiseResourceCooker::GetDefault();
  59. if (UNLIKELY(!ResourceCooker))
  60. {
  61. return;
  62. }
  63. ResourceCooker->PrepareCookedData(GameParameterCookedData, GetValidatedInfo(RtpcInfo));
  64. }
  65. void UAkRtpc::FillInfo()
  66. {
  67. auto* ResourceCooker = FWwiseResourceCooker::GetDefault();
  68. if (UNLIKELY(!ResourceCooker))
  69. {
  70. UE_LOG(LogAkAudio, Error, TEXT("UAkRtpc::FillInfo: ResourceCooker not initialized"));
  71. return;
  72. }
  73. auto ProjectDatabase = ResourceCooker->GetProjectDatabase();
  74. if (UNLIKELY(!ProjectDatabase))
  75. {
  76. UE_LOG(LogAkAudio, Error, TEXT("UAkRtpc::FillInfo: ProjectDatabase not initialized"));
  77. return;
  78. }
  79. FWwiseObjectInfo* AudioTypeInfo = &RtpcInfo;
  80. const FWwiseRefGameParameter GameParameterRef = FWwiseDataStructureScopeLock(*ProjectDatabase).GetGameParameter(
  81. GetValidatedInfo(RtpcInfo));
  82. if (GameParameterRef.GameParameterName().IsNone() || !GameParameterRef.GameParameterGuid().IsValid() || GameParameterRef.GameParameterId() == AK_INVALID_UNIQUE_ID)
  83. {
  84. UE_LOG(LogAkAudio, Warning, TEXT("UAkRtpc::FillInfo: Valid object not found in Project Database"));
  85. return;
  86. }
  87. AudioTypeInfo->WwiseName = GameParameterRef.GameParameterName();
  88. AudioTypeInfo->WwiseGuid = GameParameterRef.GameParameterGuid();
  89. AudioTypeInfo->WwiseShortId = GameParameterRef.GameParameterId();
  90. }
  91. bool UAkRtpc::ObjectIsInSoundBanks()
  92. {
  93. auto* ResourceCooker = FWwiseResourceCooker::GetDefault();
  94. if (UNLIKELY(!ResourceCooker))
  95. {
  96. UE_LOG(LogAkAudio, Error, TEXT("UAkRtpc::GetWwiseRef: ResourceCooker not initialized"));
  97. return false;
  98. }
  99. auto ProjectDatabase = ResourceCooker->GetProjectDatabase();
  100. if (UNLIKELY(!ProjectDatabase))
  101. {
  102. UE_LOG(LogAkAudio, Error, TEXT("UAkRtpc::GetWwiseRef: ProjectDatabase not initialized"));
  103. return false;
  104. }
  105. FWwiseObjectInfo* AudioTypeInfo = &RtpcInfo;
  106. const FWwiseRefGameParameter GameParameterRef = FWwiseDataStructureScopeLock(*ProjectDatabase).GetGameParameter(
  107. GetValidatedInfo(RtpcInfo));
  108. return GameParameterRef.IsValid();
  109. }
  110. #endif