| 106 | } |
| 107 | |
| 108 | void 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 |
nothing calls this directly
no test coverage detected