UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ObjectPollFrequencyLimiter.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"
6#include "Containers/Array.h"
8
9namespace UE::Net::Private
10{
12}
13
14namespace UE::Net::Private
15{
16
18{
19public:
21
22 void Init(uint32 MaxActiveObjectCount);
23 void Deinit();
24
26
28
30
36
38 static constexpr uint32 GetMaxPollingFrames()
39 {
40 return static_cast<uint32>(std::numeric_limits<uint8>::max());
41 }
42
43private:
44
45 uint32 MaxInternalHandle = 0;
46 uint32 FrameIndex = 0;
47 // We store the number of frames between updates as a byte to be able to process 16 objects per instruction.
48 // This limits polling to at least every 256th frame. At 30Hz this means every 8.5 seconds.
49 uint8 FrameIndexOffsets[256] = {};
50 TArray<uint8> FramesBetweenUpdates;
51 TArray<uint8> FrameCounters;
52};
53
54
56{
57 MaxInternalHandle = FPlatformMath::Max(MaxInternalHandle, InternalIndex);
58
59 FramesBetweenUpdates[InternalIndex] = PollFramePeriod;
60 // Spread the polling of objects with the same frequency so that if you add lots of objects the same frame they won't be polled at the same time. The update loop decrements counters so we need to be careful with how we offset things.
61 const uint8 FrameOffset = --FrameIndexOffsets[PollFramePeriod];
62 FrameCounters[InternalIndex] = static_cast<uint8>(uint32(~(FrameIndex + FrameOffset)) % uint32(PollFramePeriod + 1U));
63}
64
66{
67 MaxInternalHandle = FPlatformMath::Max(MaxInternalHandle, InternalIndex);
68
69 // Copy state from object to poll with
70 FramesBetweenUpdates[InternalIndex] = FramesBetweenUpdates[ObjectToPollWithInternalIndex];
71 FrameCounters[InternalIndex] = FrameCounters[ObjectToPollWithInternalIndex];
72}
73
74}
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
void Init()
Definition LockFreeList.h:4
int32 InternalIndex
Definition VulkanMemory.cpp:4036
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Array.h:670
Definition NetBitArray.h:337
Definition ObjectPollFrequencyLimiter.h:18
void SetPollFramePeriod(FInternalNetRefIndex InternalIndex, uint8 PollFramePeriod)
Definition ObjectPollFrequencyLimiter.h:55
void Deinit()
Definition ObjectPollFrequencyLimiter.cpp:26
FObjectPollFrequencyLimiter()
Definition ObjectPollFrequencyLimiter.cpp:12
static constexpr uint32 GetMaxPollingFrames()
Definition ObjectPollFrequencyLimiter.h:38
void SetPollWithObject(FInternalNetRefIndex ObjectToPollWithInternalIndex, FInternalNetRefIndex InternalIndex)
Definition ObjectPollFrequencyLimiter.h:65
void OnMaxInternalNetRefIndexIncreased(FInternalNetRefIndex NewMaxInternalIndex)
Definition ObjectPollFrequencyLimiter.cpp:32
Definition NetworkVersion.cpp:28
uint32 FInternalNetRefIndex
Definition ReplicationStateStorage.h:20