AkGroupValue.cpp 4.3 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 "AkGroupValue.h"
  16. #include "AkAudioDevice.h"
  17. #include "Wwise/WwiseResourceLoader.h"
  18. #include <inttypes.h>
  19. void UAkGroupValue::UnloadGroupValue(bool bAsync)
  20. {
  21. auto PreviouslyLoadedGroupValue = LoadedGroupValue.exchange(nullptr);
  22. if (PreviouslyLoadedGroupValue)
  23. {
  24. auto* ResourceLoader = FWwiseResourceLoader::Get();
  25. if (UNLIKELY(!ResourceLoader))
  26. {
  27. return;
  28. }
  29. if (bAsync)
  30. {
  31. FWwiseLoadedGroupValuePromise Promise;
  32. Promise.EmplaceValue(MoveTemp(PreviouslyLoadedGroupValue));
  33. ResourceUnload = ResourceLoader->UnloadGroupValueAsync(Promise.GetFuture());
  34. }
  35. else
  36. {
  37. ResourceLoader->UnloadGroupValue(MoveTemp(PreviouslyLoadedGroupValue));
  38. }
  39. }
  40. }
  41. #if WITH_EDITORONLY_DATA
  42. void UAkGroupValue::MigrateWwiseObjectInfo()
  43. {
  44. FString GroupName;
  45. FString ValueName;
  46. SplitAssetName( GroupName, ValueName);
  47. if (GroupShortID_DEPRECATED != AK_INVALID_UNIQUE_ID )
  48. {
  49. GroupValueInfo.GroupShortId = GroupShortID_DEPRECATED;
  50. }
  51. else
  52. {
  53. GroupValueInfo.GroupShortId = FAkAudioDevice::GetShortIDFromString(GroupName);
  54. }
  55. if (ShortID_DEPRECATED != AK_INVALID_UNIQUE_ID)
  56. {
  57. GroupValueInfo.WwiseShortId = ShortID_DEPRECATED;
  58. }
  59. else
  60. {
  61. GroupValueInfo.WwiseShortId = FAkAudioDevice::GetShortIDFromString(ValueName);
  62. }
  63. if (ID_DEPRECATED.IsValid())
  64. {
  65. GroupValueInfo.WwiseGuid = ID_DEPRECATED;
  66. }
  67. GroupValueInfo.WwiseName = FName(ValueName);
  68. }
  69. void UAkGroupValue::ValidateShortID(FWwiseObjectInfo& WwiseInfo) const
  70. {
  71. if (WwiseInfo.WwiseShortId != AK_INVALID_UNIQUE_ID && WwiseInfo.WwiseShortId != FAkAudioDevice::GetShortIDFromString(WwiseInfo.WwiseName.ToString()))
  72. {
  73. UE_LOG(LogAkAudio, Log, TEXT("UAkGroupValue::ValidateShortID: WwiseShortId does not match ShortID derived from WwiseName. Asset: %s - WwiseName %s - WwiseShortID: %" PRIu32 " instead of %" PRIu32 "."), *GetName(), *WwiseInfo.WwiseName.ToString(), WwiseInfo.WwiseShortId, FAkAudioDevice::GetShortIDFromString(WwiseInfo.WwiseName.ToString()));
  74. }
  75. if (WwiseInfo.WwiseShortId == AK_INVALID_UNIQUE_ID)
  76. {
  77. if (!WwiseInfo.WwiseName.ToString().IsEmpty())
  78. {
  79. WwiseInfo.WwiseShortId = FAkAudioDevice::GetShortIDFromString(WwiseInfo.WwiseName.ToString());
  80. }
  81. else
  82. {
  83. FString GroupName;
  84. FString ValueName;
  85. SplitAssetName( GroupName, ValueName);
  86. UE_LOG(LogAkAudio, Warning, TEXT("UAkGroupValue::ValidateShortID: Using ShortID based on asset name '%s'. Assumed value name is '%s'."), *GetName(), *ValueName);
  87. WwiseInfo.WwiseShortId = FAkAudioDevice::GetShortIDFromString(ValueName);
  88. }
  89. }
  90. if ( auto WwiseGroupInfo = static_cast<FWwiseGroupValueInfo*>(&WwiseInfo))
  91. {
  92. if (WwiseGroupInfo->GroupShortId == AK_INVALID_UNIQUE_ID)
  93. {
  94. FString GroupName;
  95. FString ValueName;
  96. SplitAssetName(GroupName, ValueName);
  97. UE_LOG(LogAkAudio, Warning, TEXT("UAkGroupValue::ValidateShortID: Using ShortID for group based on asset name '%s'. Assumed group name is '%s'."), *GetName(), *GroupName);
  98. WwiseGroupInfo->GroupShortId = FAkAudioDevice::GetShortIDFromString(GroupName);
  99. }
  100. }
  101. }
  102. bool UAkGroupValue::SplitAssetName(FString& OutGroupName, FString& OutValueName) const
  103. {
  104. auto AssetName = GetName();
  105. if (AssetName.Contains(TEXT("-")))
  106. {
  107. AssetName.Split(TEXT("-"), &OutGroupName, &OutValueName);
  108. return true;
  109. }
  110. UE_LOG(LogAkAudio, Warning, TEXT("UAkAudioType::GetAssetSplitNames: Couldn't parse group and value names from asset named '%s'."), *GetName());
  111. return false;
  112. }
  113. #endif