UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
PhysScene_AsyncPhysicsStateJobQueue.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Tasks/Pipe.h"
6#include "Tasks/Task.h"
8#include "UObject/Object.h"
11
13{
16
17 enum class EJobType
18 {
21 };
22
23 struct FJob
24 {
29
30 bool IsValid() const
31 {
33 }
34
35 bool Execute(UE::FTimeout& Timeout) const;
36 void OnPreExecute_GameThread() const;
37 void OnPostExecute_GameThread() const;
38
39 inline bool operator == (const FJob& Other) const
40 {
41 return (Processor == Other.Processor) && (Type == Other.Type);
42 }
43
44 friend inline uint32 GetTypeHash(const FJob& InJob)
45 {
47 }
48
51 };
52
53 void Tick(bool bWaitForCompletion = false);
54 void AddJob(const FJob& Job);
55 void RemoveJob(const FJob& Job);
56 bool IsCompleted() const;
57
58private:
59
60 void LaunchAsyncJobTask();
61 void ExecuteJobsAsync(double TimeBudgetSeconds);
62 void OnUpdateLevelStreamingDone();
63
64 // GameThread variables
65 FPhysScene* PhysScene = nullptr; // The Physics scene
66 UE::Tasks::FTask AsyncJobTask; // The async task
67
68 // Async Task variables
69 int32 TaskEpoch = 0; // Last epoch used by the async task
70 double UsedAsyncTaskTimeBudgetSec = 0; // Time used in the async task since the last epoch update
71
72 // Variables access/modified by both the GameThread and the async task
73 mutable FRWLock JobsLock; // Lock used to protect jobs to execute, executing and completed
74 TArray<FJob> JobsToExecute;
75 TOptional<FJob> ExecutingJob;
76 TArray<FJob> CompletedJobs;
77
78 std::atomic<bool> bIsBlocking = false; // Notifies to the async task that we are block waiting for the task to complete
79 std::atomic<int32> GameThreadEpoch = 0; // Epoch updated by the GameThread at every frame and used by the async task to reset UsedAsyncTaskTimeBudgetSec
80};
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition PhysScene_Chaos.h:116
Definition AsyncPhysicsStateProcessorInterface.h:14
virtual UObject * GetAsyncPhysicsStateObject() const
Definition AsyncPhysicsStateProcessorInterface.h:26
Definition Array.h:670
Definition CriticalSection.h:14
Definition Timeout.h:21
Definition PhysScene_AsyncPhysicsStateJobQueue.h:24
bool operator==(const FJob &Other) const
Definition PhysScene_AsyncPhysicsStateJobQueue.h:39
FJob(IAsyncPhysicsStateProcessor *InProcessor, EJobType InType)
Definition PhysScene_AsyncPhysicsStateJobQueue.h:25
IAsyncPhysicsStateProcessor * Processor
Definition PhysScene_AsyncPhysicsStateJobQueue.h:49
friend uint32 GetTypeHash(const FJob &InJob)
Definition PhysScene_AsyncPhysicsStateJobQueue.h:44
void OnPreExecute_GameThread() const
Definition PhysScene_AsyncPhysicsStateJobQueue.cpp:240
void OnPostExecute_GameThread() const
Definition PhysScene_AsyncPhysicsStateJobQueue.cpp:281
bool IsValid() const
Definition PhysScene_AsyncPhysicsStateJobQueue.h:30
EJobType Type
Definition PhysScene_AsyncPhysicsStateJobQueue.h:50
Definition PhysScene_AsyncPhysicsStateJobQueue.h:13
bool IsCompleted() const
Definition PhysScene_AsyncPhysicsStateJobQueue.cpp:99
~FPhysScene_AsyncPhysicsStateJobQueue()
Definition PhysScene_AsyncPhysicsStateJobQueue.cpp:24
void AddJob(const FJob &Job)
Definition PhysScene_AsyncPhysicsStateJobQueue.cpp:35
void RemoveJob(const FJob &Job)
Definition PhysScene_AsyncPhysicsStateJobQueue.cpp:45
EJobType
Definition PhysScene_AsyncPhysicsStateJobQueue.h:18
Definition Optional.h:131
Definition Tuple.h:652