AkEnvironmentIndex.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 "AkEnvironmentIndex.h"
  16. #include "AkAudioDevice.h"
  17. void FAkEnvironmentOctreeSemantics::SetElementId(AK_OCTREE_TYPE<FAkEnvironmentOctreeElement, FAkEnvironmentOctreeSemantics>& OctreeOwner, const FAkEnvironmentOctreeElement& Element, AK_OCTREE_ELEMENT_ID Id)
  18. {
  19. static_cast<UAkEnvironmentOctree&>(OctreeOwner).ObjectToOctreeId.Add(Element.Component->GetUniqueID(), Id);
  20. }
  21. void FAkEnvironmentIndex::Add(USceneComponent* EnvironmentToAdd)
  22. {
  23. UWorld* CurrentWorld = EnvironmentToAdd->GetWorld();
  24. TUniquePtr<UAkEnvironmentOctree>& Octree = Map.FindOrAdd(CurrentWorld);
  25. if (Octree == nullptr)
  26. {
  27. Octree = MakeUnique<UAkEnvironmentOctree>();
  28. }
  29. if (Octree != nullptr)
  30. {
  31. FAkEnvironmentOctreeElement Element(EnvironmentToAdd);
  32. Octree->AddElement(Element);
  33. }
  34. }
  35. bool FAkEnvironmentIndex::Remove(USceneComponent* EnvironmentToRemove)
  36. {
  37. UWorld* CurrentWorld = EnvironmentToRemove->GetWorld();
  38. TUniquePtr<UAkEnvironmentOctree>* Octree = Map.Find(CurrentWorld);
  39. if (Octree != nullptr && EnvironmentToRemove != nullptr)
  40. {
  41. AK_OCTREE_ELEMENT_ID* Id = (*Octree)->ObjectToOctreeId.Find(EnvironmentToRemove->GetUniqueID());
  42. if (Id != nullptr && (*Octree)->IsValidElementId(*Id))
  43. {
  44. (*Octree)->RemoveElement(*Id);
  45. }
  46. (*Octree)->ObjectToOctreeId.Remove(EnvironmentToRemove->GetUniqueID());
  47. return true;
  48. }
  49. return false;
  50. }
  51. void FAkEnvironmentIndex::Update(USceneComponent* Environment)
  52. {
  53. Remove(Environment);
  54. Add(Environment);
  55. }
  56. void FAkEnvironmentIndex::Clear(const UWorld* World)
  57. {
  58. Map.Remove(World);
  59. }
  60. bool FAkEnvironmentIndex::IsEmpty(const UWorld* World)
  61. {
  62. TUniquePtr<UAkEnvironmentOctree>* Octree = Map.Find(World);
  63. return Octree == nullptr;
  64. }