PostEventAsync.cpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 "BlueprintNodes/PostEventAsync.h"
  16. #include "AkGameplayTypes.h"
  17. #include "AkAudioEvent.h"
  18. #include "TimerManager.h"
  19. UPostEventAsync* UPostEventAsync::PostEventAsync(
  20. const UObject* WorldContextObject,
  21. UAkAudioEvent* AkEvent,
  22. AActor* Actor,
  23. int32 CallbackMask,
  24. const FOnAkPostEventCallback& PostEventCallback,
  25. bool bStopWhenAttachedToDestroyed
  26. )
  27. {
  28. UPostEventAsync* newNode = NewObject<UPostEventAsync>();
  29. newNode->WorldContextObject = WorldContextObject;
  30. newNode->AkEvent = AkEvent;
  31. newNode->Actor = Actor;
  32. newNode->CallbackMask = CallbackMask;
  33. newNode->PostEventCallback = PostEventCallback;
  34. newNode->bStopWhenAttachedToDestroyed = bStopWhenAttachedToDestroyed;
  35. return newNode;
  36. }
  37. void UPostEventAsync::Activate()
  38. {
  39. if (AkEvent == nullptr)
  40. {
  41. UE_LOG(LogAkAudio, Warning, TEXT("PostEventAsync: No Event specified!"));
  42. Completed.Broadcast(AK_INVALID_PLAYING_ID);
  43. return;
  44. }
  45. if (Actor == nullptr)
  46. {
  47. UE_LOG(LogAkAudio, Warning, TEXT("PostEventAsync: NULL Actor specified!"));
  48. Completed.Broadcast(AK_INVALID_PLAYING_ID);
  49. return;
  50. }
  51. AkDeviceAndWorld DeviceAndWorld(Actor);
  52. if (DeviceAndWorld.IsValid())
  53. {
  54. AkCallbackType AkCallbackMask = AkCallbackTypeHelpers::GetCallbackMaskFromBlueprintMask(CallbackMask);
  55. AkEvent->PostOnActor(Actor, PostEventCallback, AkCallbackMask, false);
  56. WorldContextObject->GetWorld()->GetTimerManager().SetTimer(Timer, this, &UPostEventAsync::PollPostEventFuture, 1.f / 60.f, true);
  57. }
  58. else
  59. {
  60. Completed.Broadcast(AK_INVALID_PLAYING_ID);
  61. }
  62. }
  63. void UPostEventAsync::PollPostEventFuture()
  64. {
  65. if (PlayingIDFuture.IsReady())
  66. {
  67. AkPlayingID PlayingID = PlayingIDFuture.Get();
  68. WorldContextObject->GetWorld()->GetTimerManager().ClearTimer(Timer);
  69. Timer.Invalidate();
  70. Completed.Broadcast(PlayingID);
  71. }
  72. }