AkReverbZone.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. /*=============================================================================
  16. AkReverbZone.cpp:
  17. =============================================================================*/
  18. #include "AkReverbZone.h"
  19. AAkReverbZone::AAkReverbZone(const class FObjectInitializer& ObjectInitializer) :
  20. Super(ObjectInitializer)
  21. {
  22. // Set default values
  23. Room->WallOcclusion = 0;
  24. SurfaceReflectorSet->bEnableSurfaceReflectors = false;
  25. }
  26. void AAkReverbZone::UpdateParentSpatialAudioVolume(AAkSpatialAudioVolume* InParentSpatialAudioVolume)
  27. {
  28. if (ParentSpatialAudioVolume != InParentSpatialAudioVolume)
  29. {
  30. ParentSpatialAudioVolume = InParentSpatialAudioVolume;
  31. bReverbZoneNeedsUpdate = true;
  32. }
  33. }
  34. void AAkReverbZone::UpdateTransitionRegionWidth(float InTransitionRegionWidth)
  35. {
  36. if (InTransitionRegionWidth < 0.f)
  37. InTransitionRegionWidth = 0.f;
  38. if (TransitionRegionWidth != InTransitionRegionWidth)
  39. {
  40. TransitionRegionWidth = InTransitionRegionWidth;
  41. bReverbZoneNeedsUpdate = true;
  42. }
  43. }
  44. void AAkReverbZone::BeginPlay()
  45. {
  46. Super::BeginPlay();
  47. SetReverbZone();
  48. }
  49. void AAkReverbZone::EndPlay(const EEndPlayReason::Type EndPlayReason)
  50. {
  51. Super::EndPlay(EndPlayReason);
  52. if (Room == nullptr)
  53. {
  54. return;
  55. }
  56. Room->RemoveReverbZone();
  57. }
  58. void AAkReverbZone::Tick(float DeltaSeconds)
  59. {
  60. Super::Tick(DeltaSeconds);
  61. if (bReverbZoneNeedsUpdate)
  62. {
  63. SetReverbZone();
  64. bReverbZoneNeedsUpdate = false;
  65. }
  66. }
  67. #if WITH_EDITOR
  68. void AAkReverbZone::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
  69. {
  70. Super::PostEditChangeProperty(PropertyChangedEvent);
  71. const FName memberPropertyName = (PropertyChangedEvent.MemberProperty != nullptr) ? PropertyChangedEvent.MemberProperty->GetFName() : NAME_None;
  72. if (memberPropertyName == GET_MEMBER_NAME_CHECKED(AAkReverbZone, ParentSpatialAudioVolume))
  73. {
  74. bReverbZoneNeedsUpdate = true;
  75. }
  76. if (memberPropertyName == GET_MEMBER_NAME_CHECKED(AAkReverbZone, TransitionRegionWidth))
  77. {
  78. if (TransitionRegionWidth < 0.f)
  79. TransitionRegionWidth = 0.f;
  80. bReverbZoneNeedsUpdate = true;
  81. }
  82. }
  83. #endif
  84. void AAkReverbZone::SetReverbZone()
  85. {
  86. if (Room == nullptr || (Room && !Room->bEnable))
  87. {
  88. UE_LOG(LogAkAudio, Error, TEXT("AkReverbZone %s: child Room component is not enabled. A Reverb Zone needs to be a Spatial Audio Room."), *GetName());
  89. return;
  90. }
  91. UAkRoomComponent* ParentRoomComponent = nullptr;
  92. if (ParentSpatialAudioVolume != nullptr)
  93. {
  94. if (ParentSpatialAudioVolume->Room == nullptr || (ParentSpatialAudioVolume->Room && !ParentSpatialAudioVolume->Room->bEnable))
  95. {
  96. UE_LOG(LogAkAudio, Error, TEXT("AkReverbZone %s: child Room component of the parent Spatial Audio Volume %s is not enabled. A Reverb Zone needs a Parent Spatial Audio Room."), *GetName(), *ParentSpatialAudioVolume->GetName());
  97. return;
  98. }
  99. else
  100. {
  101. ParentRoomComponent = ParentSpatialAudioVolume->Room;
  102. }
  103. }
  104. Room->SetReverbZone(ParentRoomComponent, TransitionRegionWidth);
  105. }
  106. AkRoomID AAkReverbZone::GetParentRoomID()
  107. {
  108. AkRoomID ParentRoomID = AK::SpatialAudio::kOutdoorRoomID;
  109. if (ParentSpatialAudioVolume != nullptr && ParentSpatialAudioVolume->Room != nullptr)
  110. {
  111. ParentRoomID = ParentSpatialAudioVolume->Room->GetRoomID();
  112. }
  113. return ParentRoomID;
  114. }