UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
TimeSynchronizationSource.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
6#include "UObject/Object.h"
7
9#include "Misc/FrameRate.h"
10#include "Misc/FrameTime.h"
11#include "Misc/Timecode.h"
12
14
15#include "TimeSynchronizationSource.generated.h"
16
17#if WITH_EDITOR
18class SWidget;
19#endif
20
33
43
52UCLASS(Abstract, MinimalAPI)
54{
56
57public:
58
60 UPROPERTY(EditAnywhere, Category = Synchronization)
61 bool bUseForSynchronization;
62
68 UPROPERTY(EditAnywhere, Category = Synchronization)
69 int32 FrameOffset;
70
71public:
72
73#if WITH_EDITOR
76#endif
77
83
89
91 virtual FFrameRate GetFrameRate() const PURE_VIRTUAL(UTimeSynchronizationSource::GetFrameRate, return FFrameRate();)
92
94 virtual bool IsReady() const PURE_VIRTUAL(UTimeSynchronizationSource::IsReady, return false;)
95
98
101
104
106 virtual FString GetDisplayName() const PURE_VIRTUAL(UTimeSynchronizationSource::GetDisplayName, return FString();)
107
108public:
109
121 inline static bool IsFrameBetweenWithRolloverModulus(const FFrameTime& ToCheck, const FFrameTime& LowerBound, const FFrameTime& UpperBound, const FFrameTime& RolloverModulus)
122 {
123 if (LowerBound <= UpperBound)
124 {
125 return LowerBound <= ToCheck && ToCheck <= UpperBound;
126 }
127 else
128 {
129 return (LowerBound <= ToCheck && ToCheck <= RolloverModulus) || (FFrameTime(0) <= ToCheck && ToCheck <= UpperBound);
130 }
131 }
132
135 {
136 return FTimecode::FromFrameNumber(FrameTime.GetFrame(), FrameRate);
137 }
138
148 {
149 const FFrameTime WithOffset = FrameTime + Offset;
150 const int32 RolloverFrameValue = RolloverModulus.GetFrame().Value;
151 return FFrameTime((WithOffset.GetFrame().Value + RolloverFrameValue) % RolloverFrameValue, WithOffset.GetSubFrame());
152 }
153
165 {
166 int32 Offset = (EndFrameTime.GetFrame().Value - StartFrameTime.GetFrame().Value);
167 bDidRollover = false;
168
169 if (RolloverModulus.IsSet())
170 {
171 // At this point, we don't know if a rollover has occurred.
172 // Any comparisons will be useless, because we don't know the real order.
173
174 // If we assume the "real world" distance between these frames is usually small, then
175 // we can figure out ordering based on distance.
176 // Here, we'll define relatively small as being less than half the time of our roll over range.
177 // That is, if we roll over every 24 hours, "small" will be 12 hours or less.
178 // The reason for this choice is because if 2 values are half the roll over distance apart,
179 // they are equidistant in modulo space. Anything greater than half implies
180 // that a roll over has occurred, while anything less than half implies no roll over.
181
182 const int32 RolloverTimeValue = RolloverModulus->GetFrame().Value;
183
184 if (FMath::Abs(Offset) > (RolloverTimeValue / 2))
185 {
186 // At this point, we know that a roll over has occurred between the frames.
187 // If Offset is negative, then Start was greater than End, we'll assume the roll over happened between then, and our output should be positive.
188 // If Offset is positive, the inverse is true (and our output will be negative).
189 // To correct for that, we need to "unroll" modulo space by adding or subtracting
190 // the full rollover value.
191
193 bDidRollover = true;
194 }
195 }
196
197 return Offset;
198 }
199};
#define PURE_VIRTUAL(func,...)
Definition CoreMiscDefines.h:103
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
JsonWriter Close()
const bool
Definition NetworkReplayStreaming.h:178
#define UPROPERTY(...)
UObject definition macros.
Definition ObjectMacros.h:744
#define GENERATED_UCLASS_BODY(...)
Definition ObjectMacros.h:768
#define UCLASS(...)
Definition ObjectMacros.h:776
uint32 Offset
Definition VulkanMemory.cpp:4033
Definition SWidget.h:165
Definition SharedPointer.h:153
Definition Object.h:95
Definition TimeSynchronizationSource.h:54
static FTimecode ConvertFrameTimeToTimecode(const FFrameTime &FrameTime, const FFrameRate &FrameRate)
Definition TimeSynchronizationSource.h:134
static int32 FindDistanceBetweenFramesWithRolloverModulus(const FFrameTime &StartFrameTime, const FFrameTime &EndFrameTime, const TOptional< FFrameTime > &RolloverModulus, bool &bDidRollover)
Definition TimeSynchronizationSource.h:164
static FFrameTime AddOffsetWithRolloverModulus(const FFrameTime &FrameTime, const int32 Offset, const FFrameTime &RolloverModulus)
Definition TimeSynchronizationSource.h:147
@ false
Definition radaudio_common.h:23
Definition FrameRate.h:21
Definition FrameTime.h:16
Definition TimeSynchronizationSource.h:22
FFrameRate SynchronizationFrameRate
Definition TimeSynchronizationSource.h:24
TOptional< FFrameTime > RolloverFrame
Definition TimeSynchronizationSource.h:31
Values that will be sent to sources when synchronization has been successfully started.
Definition TimeSynchronizationSource.h:36
FFrameTime StartFrame
Definition TimeSynchronizationSource.h:41
Definition Timecode.h:19
static FTimecode FromFrameNumber(const FFrameNumber &InFrameNumber, const FFrameRate &InFrameRate, bool InbDropFrame)
Definition Timecode.h:161
Definition Optional.h:131