8#include "Engine/GameViewportClient.h"
11#include "Async/ParallelFor.h"
40 Super::EndPlay(EndPlayReason);
59 if (GEngine || GEngine->GameViewport)
61 UWorld* World = GEngine->GameViewport->GetWorld();
70 case ETickType::FullFrameTaskParallel:
73 case ETickType::FullFrameTaskBeforeLateTickParallel:
76 case ETickType::EarlyTickParallel:
79 case ETickType::LateTickParallel:
83 UE_LOG(LogTemp, Warning, TEXT(
"TickManager.cpp: Unsupported ETickType in AddTick."));
102 FullFrameTask = FFunctionGraphTask::CreateAndDispatchWhenReady([
this, DeltaSeconds]()
105 }, TStatId(),
nullptr, ENamedThreads::AnyBackgroundHiPriTask);
115 }, TStatId(),
nullptr, ENamedThreads::AnyBackgroundHiPriTask);
142 FTaskGraphInterface::Get().WaitUntilTaskCompletes(
FullFrameTask);
150 bool foundNull =
false;
152 const int size = functions.size();
153 ParallelFor(size, [&](int32 index)
156 if (tickEntry.
Owner !=
nullptr)
158 tickEntry.Tick(DeltaTime);
164 }, EParallelForFlags::Unbalanced);
168 functions.erase(std::remove_if(functions.begin(), functions.end(), [](
const FTickEntry& Entry) { return Entry.Owner == nullptr; }), functions.end());
182 case ETickType::FullFrameTaskParallel:
185 case ETickType::FullFrameTaskBeforeLateTickParallel:
188 case ETickType::EarlyTickParallel:
191 case ETickType::LateTickParallel:
195 UE_LOG(LogTemp, Warning, TEXT(
"TickManager.cpp: Unsupported ETickType in RemoveTick."));
212 UE_LOG(LogTemp, Warning, TEXT(
"TickManager.cpp: Destroying as there are no more ticks."));
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override
FDelegateHandle OnPreTickDelegate
static std::vector< FTickEntry > LateTickFunctions
static std::vector< FTickEntry > TicksToRemove
void PreTick(UWorld *World, ELevelTick TickType, float DeltaSeconds)
static std::vector< FTickEntry > FullFrameTaskBeforeLateTickFunctions
static std::vector< FTickEntry > EarlyTickFunctions
void PostTick(UWorld *World, ELevelTick TickType, float DeltaSeconds)
static void AddTickInternal(std::vector< FTickEntry > &to, const FTickEntry &newTickEntry)
FGraphEventRef FullFrameTask
FDelegateHandle OnPostTickDelegate
static void RemoveTick(FTickEntry TickEntry)
static ATickManager * Instance
FGraphEventRef FullFrameTaskBeforeLateTick
static std::vector< FTickEntry > FullFrameTaskFunctions
virtual void BeginPlay() override
void TickFunctionsParallel(std::vector< FTickEntry > &functions, const float DeltaTime)
static void RemoveTickInternal(std::vector< FTickEntry > &from, FTickEntry tickEntry)
static FTickEntry AddTick(UObject *Object, std::function< void(float)> Function, ETickType Type)