UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ChangeMaskUtil.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
5
6class FMemStackBase;
7
8namespace UE::Net::Private
9{
10
12
14{
15 void* Alloc(uint32 Size, uint32 Alignment);
16 void Free(void* Pointer);
17};
18
27
29{
30public:
32
33 static constexpr bool UseInlinedStorage(uint32 BitCount) { return BitCount <= 64; }
34 static constexpr uint32 GetStorageSize(uint32 BitCount) { return FNetBitArrayView::CalculateRequiredWordCount(BitCount) * sizeof(StorageWordType); }
35
36 inline StorageWordType* GetPointer(uint32 BitCount);
37 inline const StorageWordType* GetPointer(uint32 BitCount) const;
38
39public:
40 inline FChangeMaskStorageOrPointer() : ChangeMaskOrPointer(0) {}
41
42 // Allocate storage for ChangeMask
43 // If the changemask fits in the storage pointer no memory is allocated, if it does not fit memory is allocated from the provided Allocator
44 template <typename AllocatorType>
45 static void Alloc(FChangeMaskStorageOrPointer& Storage, uint32 BitCount, AllocatorType& Allocator);
46
47 template <typename AllocatorType>
48 static FNetBitArrayView AllocAndInitBitArray(FChangeMaskStorageOrPointer& Storage, uint32 BitCount, AllocatorType& Allocator);
49
50 // Free memory (if) allocated for ChangeMask
51 template <typename AllocatorType>
52 static void Free(const FChangeMaskStorageOrPointer& Storage, uint32 BitCount, AllocatorType& Allocator);
53
54private:
55 uint64 ChangeMaskOrPointer;
56};
57
59{
60 // Construct a changemask from storage and bitcount
61 // Storage must be allocated
62 static inline FNetBitArrayView MakeChangeMask(const FChangeMaskStorageOrPointer& Storage, uint32 BitCount);
63 static inline void CopyChangeMask(FChangeMaskStorageOrPointer& DestStorage, const FNetBitArrayView& ChangeMask);
65 static inline void CopyChangeMask(ChangeMaskStorageType* DstData, const ChangeMaskStorageType* SrcData, uint32 BitCount);
66};
67
69// FChangeMaskStorageOrPointer Impl
71
73{
74 uint64* Ptr = UseInlinedStorage(BitCount) ? reinterpret_cast<uint64*>(&ChangeMaskOrPointer) : reinterpret_cast<uint64*>(ChangeMaskOrPointer);
75 return reinterpret_cast<StorageWordType*>(Ptr);
76}
77
79{
80 const uint64* Ptr = UseInlinedStorage(BitCount) ? reinterpret_cast<const uint64*>(&ChangeMaskOrPointer) : reinterpret_cast<const uint64*>(ChangeMaskOrPointer);
81 return reinterpret_cast<const StorageWordType*>(Ptr);
82}
83
84template <typename AllocatorType>
86{
87 if (!UseInlinedStorage(BitCount))
88 {
89 Storage.ChangeMaskOrPointer = (uint64)(Allocator.Alloc(GetStorageSize(BitCount), alignof(StorageWordType)));
90 }
91}
92
93template <typename AllocatorType>
95{
96 if (!UseInlinedStorage(BitCount))
97 {
98 Storage.ChangeMaskOrPointer = (uint64)(Allocator.Alloc(GetStorageSize(BitCount), alignof(StorageWordType)));
99 }
100
101 return FNetBitArrayView(Storage.GetPointer(BitCount), BitCount, FNetBitArrayView::ResetOnInit);
102}
103
104template <typename AllocatorType>
106{
107 if (!UseInlinedStorage(BitCount))
108 {
109 Allocator.Free((void*)Storage.ChangeMaskOrPointer);
110 }
111}
112
114// FChangeMaskUtil Impl
116
118{
119 return MakeNetBitArrayView(Storage.GetPointer(BitCount), BitCount);
120}
121
126
131
133{
134 const uint32 BitCount = ChangeMask.GetNumBits();
136 DstChangeMask.Copy(ChangeMask);
137}
138
139}
FPlatformTypes::uint64 uint64
A 64-bit unsigned integer.
Definition Platform.h:1117
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
uint32 Size
Definition VulkanMemory.cpp:4034
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition MemStack.h:78
uint32 StorageWordType
Definition NetBitArray.h:50
@ ResetOnInit
Definition NetBitArray.h:48
@ NoResetNoValidate
Definition NetBitArray.h:47
Definition NetBitArray.h:337
uint32 GetNumBits() const
Definition NetBitArray.h:1587
static constexpr uint32 CalculateRequiredWordCount(uint32 BitCount)
Definition NetBitArray.h:1414
Definition ChangeMaskUtil.h:29
static FNetBitArrayView AllocAndInitBitArray(FChangeMaskStorageOrPointer &Storage, uint32 BitCount, AllocatorType &Allocator)
Definition ChangeMaskUtil.h:94
StorageWordType * GetPointer(uint32 BitCount)
Definition ChangeMaskUtil.h:72
static void Alloc(FChangeMaskStorageOrPointer &Storage, uint32 BitCount, AllocatorType &Allocator)
Definition ChangeMaskUtil.h:85
static void Free(const FChangeMaskStorageOrPointer &Storage, uint32 BitCount, AllocatorType &Allocator)
Definition ChangeMaskUtil.h:105
static constexpr bool UseInlinedStorage(uint32 BitCount)
Definition ChangeMaskUtil.h:33
static constexpr uint32 GetStorageSize(uint32 BitCount)
Definition ChangeMaskUtil.h:34
ChangeMaskStorageType StorageWordType
Definition ChangeMaskUtil.h:31
FChangeMaskStorageOrPointer()
Definition ChangeMaskUtil.h:40
Definition NetworkVersion.cpp:28
FNetBitArrayView::StorageWordType ChangeMaskStorageType
Definition ChangeMaskUtil.h:11
FNetBitArrayView MakeNetBitArrayView(const FNetBitArrayView::StorageWordType *Storage, uint32 BitCount)
Definition NetBitArray.h:1677
static UE_FORCEINLINE_HINT void * Memcpy(void *Dest, const void *Src, SIZE_T Count)
Definition GenericPlatformMemory.h:591
Definition ChangeMaskUtil.h:59
static void CopyChangeMask(FChangeMaskStorageOrPointer &DestStorage, const FNetBitArrayView &ChangeMask)
Definition ChangeMaskUtil.h:132
static FNetBitArrayView MakeChangeMask(const FChangeMaskStorageOrPointer &Storage, uint32 BitCount)
Definition ChangeMaskUtil.h:117
Definition ChangeMaskUtil.h:14
void * Alloc(uint32 Size, uint32 Alignment)
Definition ChangeMaskUtil.cpp:10
FMemStackBase * MemStack
Definition ChangeMaskUtil.h:21
void * Alloc(uint32 Size, uint32 Alignment)
Definition ChangeMaskUtil.cpp:25