UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ReplicationStateDescriptorImplementationMacros.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreTypes.h"
11
12//
13// $IRIS: TEMPORARY TO HELP WITH FAKE GENERATING REPLICATIONSTATES
14// define macros to declare and implement the fake Generated State
15// The idea is to generate this automatically for native iris replication
16//
17
18namespace UE::Net::Private
19{
20
26
28{
29 return MemberIndex == 0 ? 0u : Align(MemberDescriptors[MemberIndex - 1].InternalMemberOffset + InternalTypeInfo[MemberIndex - 1].Size, InternalTypeInfo[MemberIndex].Alignment);
30}
31
32template <typename T>
33constexpr uint32 GetInternalStateSize(const T& MemberDescriptors, const FInternalTypeInfo* InternalTypeInfo)
34{
35 const uint32 Count = UE_ARRAY_COUNT(MemberDescriptors);
36
37 if (Count == 0)
38 {
39 return 0;
40 }
41
42 return MemberDescriptors[Count - 1].InternalMemberOffset + InternalTypeInfo[Count - 1].Size;
43}
44
45template <typename T>
46constexpr uint16 GetInternalStateAlignment(const T& MemberDescriptors, const FInternalTypeInfo* InternalTypeInfo)
47{
48 const uint32 Count = UE_ARRAY_COUNT(MemberDescriptors);
49
50 uint16 Alignment = 1;
51
52 for (uint32 It = 0; It < Count; ++It)
53 {
54 Alignment = FPlatformMath::Max<uint16>(Alignment, static_cast<uint16>(InternalTypeInfo[It].Alignment));
55 }
56
57 return Alignment;
58}
59
60template <typename T>
61constexpr uint32 GetMemberChangeMaskSize(const T& MemberChangeMaskDescriptors)
62{
63 constexpr uint32 Count = UE_ARRAY_COUNT(MemberChangeMaskDescriptors);
64 return Count > 0u ? MemberChangeMaskDescriptors[Count - 1].BitOffset + MemberChangeMaskDescriptors[Count - 1].BitCount : 0u;
65}
66
67}
68
69//
70// IMPLEMENTATION MACROS
71//
72
73// Used to declare an temporary array with serializer, config size and alignment for the internal types used by the specified serializes
74// This is used by our fake generated states to make the declarations more readable.
75#define IRIS_BEGIN_INTERNAL_TYPE_INFO(StateName) static const UE::Net::Private::FInternalTypeInfo StateName ## TypeInfoData[] = {
76#define IRIS_INTERNAL_TYPE_INFO(SerializerName) { UE_NET_GET_SERIALIZER_INTERNAL_TYPE_SIZE(SerializerName), UE_NET_GET_SERIALIZER_INTERNAL_TYPE_ALIGNMENT(SerializerName) },
77#define IRIS_END_INTERNAL_TYPE_INFO() };
78
79// Used to declare the array of member serializer descriptors
80#define IRIS_BEGIN_SERIALIZER_DESCRIPTOR(StateName) const UE::Net::FReplicationStateMemberSerializerDescriptor StateName::sReplicationStateDescriptorMemberSerializerDescriptors[] = {
81#define IRIS_SERIALIZER_DESCRIPTOR(SerializerName, ConfigPointer) { &UE_NET_GET_SERIALIZER(SerializerName), ConfigPointer ? ConfigPointer : UE_NET_GET_SERIALIZER_DEFAULT_CONFIG(SerializerName)},
82#define IRIS_END_SERIALIZER_DESCRIPTOR() };
83
84// Used to declare the array of member traits descriptors
85#define IRIS_BEGIN_TRAITS_DESCRIPTOR(StateName) const UE::Net::FReplicationStateMemberTraitsDescriptor StateName::sReplicationStateDescriptorMemberTraitsDescriptors[] = {
86#define IRIS_TRAITS_DESCRIPTOR(Traits) { Traits },
87#define IRIS_END_TRAITS_DESCRIPTOR() };
88
89// Used to declare the optional array of member tag descriptors. Since tags are optional we need to create a fake one to prevent a zero-sized array.
90#define IRIS_BEGIN_TAG_DESCRIPTOR(StateName) const UE::Net::FReplicationStateMemberTagDescriptor StateName::sReplicationStateDescriptorMemberTagDescriptors[] = {
91#define IRIS_TAG_DESCRIPTOR(Tag, MemberIndex) { Tag, MemberIndex, uint16(~0) },
92#define IRIS_END_TAG_DESCRIPTOR() { UE::Net::FRepTag(0) /* UE::Net::GetInvalidRepTag() */, uint16(~0), uint16(~0) } };
93
94// Used to declare the optional array of member function descriptors. Since functions are optional we need to create a fake one to prevent a zero-sized array.
95#define IRIS_BEGIN_FUNCTION_DESCRIPTOR(StateName) const UE::Net::FReplicationStateMemberFunctionDescriptor StateName::sReplicationStateDescriptorMemberFunctionDescriptors[] = {
96#define IRIS_FUNCTION_DESCRIPTOR(Function, Descriptor) { Function, Descriptor },
97#define IRIS_END_FUNCTION_DESCRIPTOR() { {} } };
98
99// Used to declare the optional array of member reference descriptors. Since references are optional we need to create a fake one to prevent a zero-sized array.
100#define IRIS_BEGIN_REFERENCE_DESCRIPTOR(StateName) const UE::Net::FReplicationStateMemberReferenceDescriptor StateName::sReplicationStateDescriptorMemberReferenceDescriptors[] = {
101#define IRIS_END_REFERENCE_DESCRIPTOR() { {} } };
102
103// Declare an entry in the ReplicationStateMemberDescriptor array, requires the temporary TypeInfoData array to be declared
104#define IRIS_BEGIN_MEMBER_DESCRIPTOR(StateName) const UE::Net::FReplicationStateMemberDescriptor StateName::sReplicationStateDescriptorMemberDescriptors[] = {
105#define IRIS_MEMBER_DESCRIPTOR(StateName, MemberName, MemberIndex) { offsetof(StateName, MemberName), UE::Net::Private::GetInternalMemberOffset(sReplicationStateDescriptorMemberDescriptors, StateName ## TypeInfoData, MemberIndex) },
106#define IRIS_END_MEMBER_DESCRIPTOR() };
107
108// Used to declare the mandatory array of member debug descriptors
109#define IRIS_BEGIN_MEMBER_DEBUG_DESCRIPTOR(StateName) const UE::Net::FReplicationStateMemberDebugDescriptor StateName::sReplicationStateDescriptorMemberDebugDescriptors[] = {
110#define IRIS_MEMBER_DEBUG_DESCRIPTOR(StateName, MemberDebugName) { UE::Net::CreatePersistentNetDebugName(TEXT(#MemberDebugName)), },
111#define IRIS_END_MEMBER_DEBUG_DESCRIPTOR() };
112
113// Implement the required construct and destruct functions
114#define IRIS_IMPLEMENT_CONSTRUCT_AND_DESTRUCT(StateName) \
115void Construct##StateName(uint8* StateBuffer, const UE::Net::FReplicationStateDescriptor* Descriptor) { new (StateBuffer) StateName(); } \
116void Destruct##StateName(uint8* StateBuffer, const UE::Net::FReplicationStateDescriptor* Descriptor) { StateName* State = reinterpret_cast<StateName*>(StateBuffer); State->~StateName(); }
117
118// Implement the ReplicationStateDescriptor for the faked state
119
120#define IRIS_IMPLEMENT_REPLICATIONSTATEDESCRIPTOR_WITH_TRAITS(StateName, Traits) \
121const UE::Net::FReplicationStateDescriptor StateName::sReplicationStateDescriptor = \
122{ \
123 &sReplicationStateDescriptorMemberDescriptors[0], \
124 &sReplicationStateChangeMaskDescriptors[0], \
125 &sReplicationStateDescriptorMemberSerializerDescriptors[0], \
126 &sReplicationStateDescriptorMemberTraitsDescriptors[0], \
127 (UE_ARRAY_COUNT(sReplicationStateDescriptorMemberFunctionDescriptors) > 1 ? &sReplicationStateDescriptorMemberFunctionDescriptors[0] : static_cast<const UE::Net::FReplicationStateMemberFunctionDescriptor*>(nullptr)), \
128 (UE_ARRAY_COUNT(sReplicationStateDescriptorMemberTagDescriptors) > 1 ? &sReplicationStateDescriptorMemberTagDescriptors[0] : static_cast<const UE::Net::FReplicationStateMemberTagDescriptor*>(nullptr)), \
129 (UE_ARRAY_COUNT(sReplicationStateDescriptorMemberReferenceDescriptors) > 1 ? &sReplicationStateDescriptorMemberReferenceDescriptors[0] : static_cast<const UE::Net::FReplicationStateMemberReferenceDescriptor*>(nullptr)), \
130 static_cast<const FProperty**>(nullptr), /* MemberProperties */ \
131 static_cast<const UE::Net::FReplicationStateMemberPropertyDescriptor*>(nullptr), \
132 static_cast<const UE::Net::FReplicationStateMemberLifetimeConditionDescriptor*>(nullptr), \
133 static_cast<const UE::Net::FReplicationStateMemberRepIndexToMemberIndexDescriptor*>(nullptr), \
134 static_cast<const UScriptStruct*>(nullptr), \
135 UE::Net::CreatePersistentNetDebugName(TEXT(#StateName)), \
136 &sReplicationStateDescriptorMemberDebugDescriptors[0],\
137 sizeof(StateName), \
138 UE::Net::Private::GetInternalStateSize(sReplicationStateDescriptorMemberDescriptors, StateName ## TypeInfoData), \
139 alignof(StateName), \
140 UE::Net::Private::GetInternalStateAlignment(sReplicationStateDescriptorMemberDescriptors, StateName ## TypeInfoData), \
141 static_cast<uint16>(UE_ARRAY_COUNT(sReplicationStateDescriptorMemberDescriptors)), /* MemberCount */ \
142 static_cast<uint16>(UE_ARRAY_COUNT(sReplicationStateDescriptorMemberFunctionDescriptors) - 1U), /* FunctionCount */ \
143 static_cast<uint16>(UE_ARRAY_COUNT(sReplicationStateDescriptorMemberTagDescriptors) - 1U), /* TagCount */ \
144 static_cast<uint16>(UE_ARRAY_COUNT(sReplicationStateDescriptorMemberReferenceDescriptors) - 1U), /* ObjectReferenceCount */ \
145 static_cast<uint16>(0U), /* RepIndexCount */ \
146 static_cast<uint16>(UE::Net::Private::GetMemberChangeMaskSize(sReplicationStateChangeMaskDescriptors)), /* ChangeMaskBitCount */ \
147 offsetof(StateName, ChangeMask), \
148 [](){return UE::Net::FReplicationStateIdentifier({ CityHash64(#StateName, strlen(#StateName))});}(), \
149 Construct##StateName, \
150 Destruct##StateName, \
151 static_cast<UE::Net::CreateAndRegisterReplicationFragmentFunc>(nullptr), \
152 Traits, \
153 {}, \
154};
155
156#define IRIS_IMPLEMENT_REPLICATIONSTATEDESCRIPTOR(StateName) IRIS_IMPLEMENT_REPLICATIONSTATEDESCRIPTOR_WITH_TRAITS(StateName, UE::Net::EReplicationStateTraits::None)
constexpr T Align(T Val, uint64 Alignment)
Definition AlignmentTemplates.h:18
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define UE_ARRAY_COUNT(array)
Definition UnrealTemplate.h:212
uint32 Size
Definition VulkanMemory.cpp:4034
uint16_t uint16
Definition binka_ue_file_header.h:7
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition NetworkVersion.cpp:28
constexpr uint32 GetMemberChangeMaskSize(const T &MemberChangeMaskDescriptors)
Definition ReplicationStateDescriptorImplementationMacros.h:61
constexpr uint32 GetInternalStateSize(const T &MemberDescriptors, const FInternalTypeInfo *InternalTypeInfo)
Definition ReplicationStateDescriptorImplementationMacros.h:33
constexpr uint32 GetInternalMemberOffset(const FReplicationStateMemberDescriptor *MemberDescriptors, const FInternalTypeInfo *InternalTypeInfo, uint32 MemberIndex)
Definition ReplicationStateDescriptorImplementationMacros.h:27
constexpr uint16 GetInternalStateAlignment(const T &MemberDescriptors, const FInternalTypeInfo *InternalTypeInfo)
Definition ReplicationStateDescriptorImplementationMacros.h:46
Definition ReplicationStateDescriptor.h:30
Definition ReplicationStateDescriptorImplementationMacros.h:22
uint32 Alignment
Definition ReplicationStateDescriptorImplementationMacros.h:24
uint32 Size
Definition ReplicationStateDescriptorImplementationMacros.h:23