WwiseRetriggerableAsyncTask.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 "Wwise/WwiseRetriggerableAsyncTask.h"
  16. #include "Async/TaskGraphInterfaces.h"
  17. #include "Wwise/WwiseConcurrencyModule.h"
  18. #include "Wwise/Stats/Concurrency.h"
  19. #include "Async/Async.h"
  20. #include <inttypes.h>
  21. static constexpr const auto DEBUG_WWISERETRIGGERABLEASYNCTASK = false;
  22. FWwiseRetriggerableAsyncTask::FWwiseRetriggerableAsyncTask(ENamedThreads::Type DesiredThread, FFunction&& InFunction)
  23. : NamedThread(DesiredThread)
  24. , Task(MoveTemp(InFunction))
  25. {}
  26. FWwiseRetriggerableAsyncTask::~FWwiseRetriggerableAsyncTask()
  27. {
  28. UE_CLOG(DEBUG_WWISERETRIGGERABLEASYNCTASK, LogWwiseConcurrency, VeryVerbose, TEXT("Destroying FWwiseRetriggerableAsyncTask"));
  29. }
  30. void FWwiseRetriggerableAsyncTask::ScheduleTask()
  31. {
  32. UE_CLOG(DEBUG_WWISERETRIGGERABLEASYNCTASK, LogWwiseConcurrency, Verbose, TEXT("FWwiseRetriggerableAsyncTask: Scheduling task. Ticks = %llu"), FDateTime::Now().GetTicks());
  33. AsyncTask(NamedThread, [this]() mutable
  34. {
  35. UE_CLOG(DEBUG_WWISERETRIGGERABLEASYNCTASK, LogWwiseConcurrency, Verbose, TEXT("FWwiseRetriggerableAsyncTask: running task. Ticks = %llu"), FDateTime::Now().GetTicks());
  36. if (Task() == EWwiseDeferredAsyncResult::KeepRunning)
  37. {
  38. UE_CLOG(DEBUG_WWISERETRIGGERABLEASYNCTASK, LogWwiseConcurrency, Verbose, TEXT("FWwiseRetriggerableAsyncTask is not done, rescheduling"));
  39. ScheduleTask();
  40. }
  41. else
  42. {
  43. UE_CLOG(DEBUG_WWISERETRIGGERABLEASYNCTASK, LogWwiseConcurrency, Verbose, TEXT("FWwiseRetriggerableAsyncTask finished successfully!"));
  44. delete this;
  45. }
  46. });
  47. }