UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
MovieSceneInitialValueCache.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
6#include "Containers/Map.h"
11#include "HAL/Platform.h"
13#include "Misc/Optional.h"
14#include "Misc/TVariant.h"
17#include "Templates/Tuple.h"
18#include "Templates/TypeHash.h"
19#include "Templates/UniquePtr.h"
21#include "UObject/NameTypes.h"
22#include "UObject/ObjectKey.h"
23
24class UObject;
25
26namespace UE
27{
28namespace MovieScene
29{
30
31template<typename PropertyTraits> struct TPropertyValueStorage;
32
39
42{
44
47};
48
56{
61
62
69
70public:
71
79 {
80 if (TUniquePtr<IPropertyValueStorage>* Storage = StorageByComponent.Find(InitialValueType))
81 {
82 Storage->Get()->Reset(InitialValueIndices);
83 }
84 }
85
94 template<typename PropertyTraits>
96 {
98 {
99 return Storage;
100 }
101
103 StorageByComponent.Add(InitialValueType, TUniquePtr<IPropertyValueStorage>(NewStorage));
104 return NewStorage;
105 }
106
113 template<typename PropertyTraits>
118
119
128 template<typename PropertyTraits>
130 {
131 if (TUniquePtr<IPropertyValueStorage>* Existing = StorageByComponent.Find(InitialValueType))
132 {
133 // If the ptr exists, it cannot be null
134 check(Existing->IsValid());
135 return static_cast<TPropertyValueStorage<PropertyTraits>*>(Existing->Get());
136 }
137
138 return nullptr;
139 }
140
141
148 template<typename PropertyTraits>
153
154private:
155
157};
158
164template<typename PropertyTraits>
166{
167 using StorageType = typename PropertyTraits::StorageType;
168
174 virtual void Reset(TArrayView<const FInitialValueIndex> Indices) override
175 {
176 for (FInitialValueIndex Index : Indices)
177 {
178 if (PropertyValues.IsValidIndex(Index.Index))
179 {
180 PropertyValues.RemoveAt(Index.Index);
181 }
182 }
183 bLUTContainsInvalidEntries = true;
184 }
185
186
202
203
219
220
231 {
232 FKeyType Key{ FObjectKey(BoundObject), FPropertyKey(TInPlaceType<FName>(), SlowBindings->GetPropertyPath())};
233
234 return AddInitialValue(Key, InValue);
235 }
236
237
248 {
249 FKeyType Key{ FObjectKey(BoundObject), FPropertyKey(TInPlaceType<FName>(), PropertyPath)};
250
251 return AddInitialValue(Key, InValue);
252 }
253
254
263
264
273
274
280 {
281 CleanupStaleEntries();
282 return FindPropertyIndex(FKeyType{ FObjectKey(BoundObject), FPropertyKey(TInPlaceType<FName>(), PropertyPath) });
283 }
284
285
290 {
292 return Index.IsSet() ? &PropertyValues[Index.GetValue().Index] : nullptr;
293 }
294
295
299 const StorageType* FindCachedValue(UObject* BoundObject, FCustomPropertyIndex CustomIndex)
300 {
301 TOptional<FInitialValueIndex> Index = FindPropertyIndex(BoundObject, CustomIndex);
302 return Index.IsSet() ? &PropertyValues[Index.GetValue().Index] : nullptr;
303 }
304
305
311 {
313 return Index.IsSet() ? &PropertyValues[Index.GetValue().Index] : nullptr;
314 }
315
321 {
322 return PropertyValues[Index.Index];
323 }
324
325private:
326
328
329 struct FKeyType
330 {
331 FObjectKey Object;
332 FPropertyKey Property;
333
334 friend uint32 GetTypeHash(const FKeyType& InKey)
335 {
336 // Hash only considers the _type_ of the resolved property
337 // which defers the final comparison to the equality operator
338 uint32 Hash = GetTypeHash(InKey.Object);
339 Hash = HashCombine(Hash, static_cast<uint32>(InKey.Property.GetIndex()));
340 return Hash;
341 }
342 friend bool operator==(const FKeyType& A, const FKeyType& B)
343 {
344 if (A.Object != B.Object || A.Property.GetIndex() != B.Property.GetIndex())
345 {
346 return false;
347 }
348 switch (A.Property.GetIndex())
349 {
350 case 0: return A.Property.template Get<uint16>() == B.Property.template Get<uint16>();
351 case 1: return A.Property.template Get<FCustomPropertyIndex>().Value == B.Property.template Get<FCustomPropertyIndex>().Value;
352 case 2: return A.Property.template Get<FName>() == B.Property.template Get<FName>();
353 }
354 return true;
355 }
356 };
357
358 inline void CleanupStaleEntries()
359 {
360 if (!bLUTContainsInvalidEntries)
361 {
362 return;
363 }
364 for (auto It = KeyToPropertyIndex.CreateIterator(); It; ++It)
365 {
366 if (!PropertyValues.IsValidIndex(It.Value()))
367 {
368 It.RemoveCurrent();
369 }
370 }
371 PropertyValues.Shrink();
372 bLUTContainsInvalidEntries = false;
373 }
374
376 {
377 CleanupStaleEntries();
378
379 const uint16* Index = KeyToPropertyIndex.Find(InKey);
380 return Index ? TOptional<FInitialValueIndex>(FInitialValueIndex{*Index}) : TOptional<FInitialValueIndex>();
381 }
382
383 FInitialValueIndex AddInitialValue(const FKeyType& InKey, const StorageType& InValue)
384 {
385 checkSlow(!KeyToPropertyIndex.Contains(InKey));
386
387 const int32 NewIndex = PropertyValues.Add(InValue);
388 check(NewIndex < int32(uint16(0xFFFF)));
389
390 const uint16 NarrowIndex = static_cast<uint16>(NewIndex);
391 KeyToPropertyIndex.Add(InKey, NarrowIndex);
392
393 return FInitialValueIndex{NarrowIndex};
394 }
395
397 TSparseArray<StorageType> PropertyValues;
399 TMap<FKeyType, uint16> KeyToPropertyIndex;
401 bool bLUTContainsInvalidEntries = false;
402};
403
404
405} // namespace MovieScene
406} // namespace UE
407
#define checkSlow(expr)
Definition AssertionMacros.h:332
#define check(expr)
Definition AssertionMacros.h:314
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
constexpr uint32 HashCombine(uint32 A, uint32 C)
Definition TypeHash.h:36
uint16_t uint16
Definition binka_ue_file_header.h:7
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition NameTypes.h:617
Definition TrackInstancePropertyBindings.h:143
Definition MovieScene.Build.cs:6
Definition PropertyPath.Build.cs:6
Definition ArrayView.h:139
Definition UnrealString.h.inl:34
Definition SharedPointer.h:692
bool IsValidIndex(int32 Index) const
Definition SparseArray.h:481
void Shrink()
Definition SparseArray.h:256
Definition SparseArray.h:524
void RemoveAt(int32 Index, int32 Count=1)
Definition SparseArray.h:650
int32 Add(const ElementType &Element)
Definition SparseArray.h:564
Definition UniquePtr.h:107
Definition Object.h:95
Definition AdvancedWidgetsModule.cpp:13
U16 Index
Definition radfft.cpp:71
Definition ObjectKey.h:19
Definition TVariant.h:13
Definition Optional.h:131
Definition MovieSceneEntityIDs.h:174
Definition MovieScenePropertySystemTypes.h:23
Definition MovieSceneInitialValueCache.h:56
TPropertyValueStorage< PropertyTraits > * GetStorage(FComponentTypeID InitialValueType)
Definition MovieSceneInitialValueCache.h:95
TPropertyValueStorage< PropertyTraits > * GetStorage(const TPropertyComponents< PropertyTraits > &PropertyComponents)
Definition MovieSceneInitialValueCache.h:114
static MOVIESCENE_API TSharedPtr< FInitialValueCache > GetGlobalInitialValues()
Definition MovieSceneInitialValueCache.cpp:18
static MOVIESCENE_API TEntitySystemLinkerExtensionID< FInitialValueCache > GetExtensionID()
Definition MovieSceneInitialValueCache.cpp:12
void Reset(FComponentTypeID InitialValueType, TArrayView< const FInitialValueIndex > InitialValueIndices)
Definition MovieSceneInitialValueCache.h:78
TPropertyValueStorage< PropertyTraits > * FindStorage(FComponentTypeID InitialValueType)
Definition MovieSceneInitialValueCache.h:129
TPropertyValueStorage< PropertyTraits > * FindStorage(const TPropertyComponents< PropertyTraits > &PropertyComponents)
Definition MovieSceneInitialValueCache.h:149
Definition MovieSceneInitialValueCache.h:36
uint16 Index
Definition MovieSceneInitialValueCache.h:37
Definition MovieSceneInitialValueCache.h:42
virtual ~IPropertyValueStorage()
Definition MovieSceneInitialValueCache.h:43
virtual void Reset(TArrayView< const FInitialValueIndex > Indices)=0
Definition MovieSceneEntitySystemLinkerExtension.h:21
Definition MovieScenePropertySystemTypes.h:299
Definition MovieSceneInitialValueCache.h:166
FInitialValueIndex AddInitialValue(UObject *BoundObject, const StorageType &InValue, FTrackInstancePropertyBindings *SlowBindings)
Definition MovieSceneInitialValueCache.h:230
TOptional< FInitialValueIndex > FindPropertyIndex(UObject *BoundObject, FCustomPropertyIndex AccessorIndex)
Definition MovieSceneInitialValueCache.h:268
const StorageType * FindCachedValue(UObject *BoundObject, FCustomPropertyIndex CustomIndex)
Definition MovieSceneInitialValueCache.h:299
FInitialValueIndex AddInitialValue(UObject *BoundObject, const StorageType &InValue, const FName &PropertyPath)
Definition MovieSceneInitialValueCache.h:247
const StorageType & GetCachedValue(FInitialValueIndex Index)
Definition MovieSceneInitialValueCache.h:320
typename PropertyTraits::StorageType StorageType
Definition MovieSceneInitialValueCache.h:167
FInitialValueIndex AddInitialValue(UObject *BoundObject, const StorageType &InValue, uint16 ResolvedPropertyOffset)
Definition MovieSceneInitialValueCache.h:196
TOptional< FInitialValueIndex > FindPropertyIndex(UObject *BoundObject, uint16 ResolvedPropertyOffset)
Definition MovieSceneInitialValueCache.h:258
const StorageType * FindCachedValue(UObject *BoundObject, const FName &PropertyPath)
Definition MovieSceneInitialValueCache.h:310
const StorageType * FindCachedValue(UObject *BoundObject, uint16 ResolvedPropertyOffset)
Definition MovieSceneInitialValueCache.h:289
TOptional< FInitialValueIndex > FindPropertyIndex(UObject *BoundObject, const FName &PropertyPath)
Definition MovieSceneInitialValueCache.h:279
FInitialValueIndex AddInitialValue(UObject *BoundObject, const StorageType &InValue, FCustomPropertyIndex AccessorIndex)
Definition MovieSceneInitialValueCache.h:213
virtual void Reset(TArrayView< const FInitialValueIndex > Indices) override
Definition MovieSceneInitialValueCache.h:174