UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
DebugSubstep.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Misc/Build.h"
6
7#ifndef CHAOS_DEBUG_SUBSTEP
8#define CHAOS_DEBUG_SUBSTEP !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
9#endif
10
11#if CHAOS_DEBUG_SUBSTEP
12
13#include "HAL/CriticalSection.h"
14#include "HAL/ThreadSafeBool.h"
15#include "Containers/Queue.h"
16
17class FEvent;
18
19namespace Chaos
20{
22 class FDebugSubstep final
23 {
24 friend class FDebugSolverTask;
25 friend class FDebugSolverTasks;
26
27 public:
30
32 bool IsEnabled() const { return bIsEnabled; }
33
40 FORCEINLINE void Add(const TCHAR* Label = nullptr) const { Add(false, Label); }
41
43 CHAOS_API void Enable(bool bEnable);
44
47
50
51 private:
52 FDebugSubstep(const FDebugSubstep&) = delete;
53 FDebugSubstep& operator=(const FDebugSubstep&) = delete;
54
56 CHAOS_API void Initialize();
57
59 CHAOS_API void Release();
60
62 FORCEINLINE bool IsInitialized() const { return !!ProgressEvent && !!SubstepEvent; }
63
64 /*
65 * Disable and wait for the completion of the debug thread.
66 * Not thread safe. Must be called from within the physics thread or with the physics thread locked.
67 * Once shutdown, the debug thread can still be restarted when SyncAdvance is called.
68 */
69 CHAOS_API void Shutdown();
70
72 CHAOS_API void AssumeThisThread();
73
80 CHAOS_API bool SyncAdvance(bool bIsSolverEnabled);
81
87 CHAOS_API void Add(bool bInStep, const TCHAR* Label) const;
88
90 CHAOS_API void Start();
91
93 CHAOS_API void Stop();
94
96 CHAOS_API void Substep(bool bShouldStep);
97
98 private:
99 enum class ECommand { Enable, Disable, ProgressToSubstep, ProgressToStep };
100
101 FThreadSafeBool bIsEnabled; // Status of the debugging thread. Can find itself in a race condition while the Add() method is ran outside of the debug thread, hence the FThreadSafeBool.
102 TQueue<ECommand, EQueueMode::Mpsc> CommandQueue; // Command queue, thread safe, Multiple-producers single-consumer (MPSC) model.
103 FEvent* ProgressEvent; // Progress synchronization event.
104 FEvent* SubstepEvent; // Substep synchronization event.
105 uint32 ThreadId; // Thread id used to check that the debug substep code is still running within the debug thread.
106 mutable bool bWaitForStep; // Boolean used to flag the completion of a step. Set within the a const function, hence the mutable.
107 bool bShouldEnable; // Whether an enable command has been requested. The debugging thread might not be ready yet (e.g. disabled solver), this will ensure it still enable the debug substepping once it is ready.
108 };
109}
110
111#else // #if CHAOS_DEBUG_SUBSTEP
112
113#include "HAL/Platform.h"
114
115namespace Chaos
116{
120 class FDebugSubstep final
121 {
122 public:
123 FDebugSubstep() {}
124 ~FDebugSubstep() {}
125
126 bool IsEnabled() const { return false; }
127
128 void Add(const TCHAR* /*Label*/ = nullptr) {}
129
130 void Enable(bool /*bEnable*/) {}
131
132 void ProgressToSubstep() {}
133 void ProgressToStep() {}
134
135 private:
136 FDebugSubstep(const FDebugSubstep&) = delete;
137 FDebugSubstep& operator=(const FDebugSubstep&) = delete;
138 };
139}
140
141#endif // #if CHAOS_DEBUG_SUBSTEP #else
#define FORCEINLINE
Definition AndroidPlatform.h:140
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
@ Stop
Definition PrecomputedVolumetricLightmapStreaming.cpp:26
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition DebugSolverTasks.h:79
Definition DebugSubstep.h:23
bool IsEnabled() const
Definition DebugSubstep.h:32
CHAOS_API void ProgressToStep()
FORCEINLINE void Add(const TCHAR *Label=nullptr) const
Definition DebugSubstep.h:40
friend class FDebugSolverTask
Definition DebugSubstep.h:24
CHAOS_API void ProgressToSubstep()
CHAOS_API ~FDebugSubstep()
CHAOS_API void Enable(bool bEnable)
Definition Event.h:21
Definition ThreadSafeBool.h:17
Definition Queue.h:48
Definition SkeletalMeshComponent.h:307
@ Add
Definition PendingSpatialData.h:18