MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / Update

Method Update

Source/Engine/Networking/NetworkReplicationHierarchy.cpp:108–170  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

106}
107
108void NetworkReplicationNode::Update(NetworkReplicationHierarchyUpdateResult* result)
109{
110 CHECK(result);
111 const float networkFPS = NetworkManager::NetworkFPS / result->ReplicationScale;
112 for (NetworkReplicationHierarchyObject& obj : Objects)
113 {
114 if (obj.ReplicationFPS < -ZeroTolerance) // < 0
115 {
116 if (obj.ReplicationUpdatesLeft)
117 {
118 // Marked as dirty to sync manually
119 obj.ReplicationUpdatesLeft = 0;
120 result->AddObject(obj.Object);
121 }
122 continue;
123 }
124 else if (obj.ReplicationFPS < ZeroTolerance) // == 0
125 {
126 // Always relevant
127 result->AddObject(obj.Object);
128 }
129 else if (obj.ReplicationUpdatesLeft > 0)
130 {
131 // Move to the next frame
132 obj.ReplicationUpdatesLeft--;
133 }
134 else
135 {
136 NetworkClientsMask targetClients = result->GetClientsMask();
137 if (result->_clientsHaveLocation && obj.CullDistance > 0.0f)
138 {
139 // Cull object against viewers locations
140 if (const Actor* actor = obj.GetActor())
141 {
142 const Vector3 objPosition = actor->GetPosition();
143 const Real cullDistanceSq = Math::Square(obj.CullDistance);
144 for (int32 clientIndex = 0; clientIndex < result->_clients.Count(); clientIndex++)
145 {
146 const auto& client = result->_clients[clientIndex];
147 if (client.HasLocation)
148 {
149 const Real distanceSq = Vector3::DistanceSquared(objPosition, client.Location);
150 // TODO: scale down replication FPS when object is far away from all clients (eg. by 10-50%)
151 if (distanceSq >= cullDistanceSq)
152 {
153 // Object is too far from this viewer so don't send data to him
154 targetClients.UnsetBit(clientIndex);
155 }
156 }
157 }
158 }
159 }
160 if (targetClients && obj.Object)
161 {
162 // Replicate this frame
163 result->AddObject(obj.Object, targetClients);
164 }
165

Callers

nothing calls this directly

Calls 7

SquareFunction · 0.85
RoundToIntFunction · 0.50
MinFunction · 0.50
AddObjectMethod · 0.45
GetActorMethod · 0.45
GetPositionMethod · 0.45
CountMethod · 0.45

Tested by

no test coverage detected