Created
May 10, 2023 10:03
-
-
Save ivo-alves/aee5e76fdb55515e0a487b209d26447e to your computer and use it in GitHub Desktop.
Unreal's built-in task graph system async task (runs on main thread)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// start Foreground worker | |
FGraphEventRef Task = FFunctionGraphTask::CreateAndDispatchWhenReady([this]() { | |
AsyncHadronTick(); | |
}, TStatId(), nullptr, ENamedThreads::AnyThread); | |
void AVehicleTest::AsyncHadronTick() | |
{ | |
double LastStepTime = FPlatformTime::Seconds(); | |
while (IsHadronPlaying) | |
{ | |
double StartTime = FPlatformTime::Seconds(); | |
{ | |
TRACE_CPUPROFILER_EVENT_SCOPE(Vehicle::TestFunction::TraceCost); | |
} | |
double EndTime = FPlatformTime::Seconds(); | |
double ExecutionTime = EndTime - StartTime; | |
double TargetTime = 1.0f / 100.0f; | |
double DelayTime = TargetTime - ExecutionTime; | |
if (DelayTime > 0) | |
{ | |
FPlatformProcess::Sleep(DelayTime); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment