Esempio n. 1
0
        /// <inheritdoc />
        public void OnFrameCompleted(NetworkConnectionDelta connectionDelta)
        {
            if (!isUpdatedThisFrame)
            {
                isUpdatedThisFrame = true;

                if (TransformBroadcaster != null && (isActiveAndEnabled || UpdateWhenDisabled))
                {
                    // Make sure the transform syncs before any other components sync
                    if (TransformBroadcaster != this)
                    {
                        TransformBroadcaster.OnFrameCompleted(connectionDelta);
                    }

                    BeginUpdatingFrame(connectionDelta);

                    // The TransformBroadcaster might detect that this component is destroyed.
                    // If so, don't continue updating.
                    if (this.enabled)
                    {
                        EnsureComponentInitialized();

                        IReadOnlyList <INetworkConnection> connectionsNeedingCompleteChanges;
                        IReadOnlyList <INetworkConnection> filteredEndpointsNeedingDeltaChanges;
                        IReadOnlyList <INetworkConnection> filteredEndpointsNeedingCompleteChanges;
                        using (StateSynchronizationPerformanceMonitor.Instance.MeasureEventDuration(PerformanceComponentName, "ProcessConnectionDelta"))
                        {
                            TransformBroadcaster.ProcessConnectionDelta(connectionDelta, out connectionsNeedingCompleteChanges, out filteredEndpointsNeedingDeltaChanges, out filteredEndpointsNeedingCompleteChanges);
                        }

                        if (connectionsNeedingCompleteChanges != null &&
                            connectionsNeedingCompleteChanges.Count > 0)
                        {
                            SendComponentCreation(connectionsNeedingCompleteChanges);
                        }

                        if (filteredEndpointsNeedingDeltaChanges != null &&
                            filteredEndpointsNeedingDeltaChanges.Count > 0)
                        {
                            TChangeFlags changeFlags = CalculateDeltaChanges();
                            if (HasChanges(changeFlags))
                            {
                                SendDeltaChanges(filteredEndpointsNeedingDeltaChanges, changeFlags);
                            }
                        }

                        if (filteredEndpointsNeedingCompleteChanges != null &&
                            filteredEndpointsNeedingCompleteChanges.Count > 0)
                        {
                            SendCompleteChanges(filteredEndpointsNeedingCompleteChanges);
                        }

                        if (connectionDelta.RemovedConnections != null &&
                            connectionDelta.RemovedConnections.Count > 0)
                        {
                            RemoveDisconnectedEndpoints(connectionDelta.RemovedConnections);
                        }

                        EndUpdatingFrame();
                    }
                }
            }
        }
Esempio n. 2
0
        /// <inheritdoc />
        public void OnFrameCompleted(SocketEndpointConnectionDelta connectionDelta)
        {
            if (!isUpdatedThisFrame)
            {
                isUpdatedThisFrame = true;

                if (TransformBroadcaster != null && (isActiveAndEnabled || UpdateWhenDisabled))
                {
                    // Make sure the transform syncs before any other components sync
                    if (TransformBroadcaster != this)
                    {
                        TransformBroadcaster.OnFrameCompleted(connectionDelta);
                    }

                    BeginUpdatingFrame(connectionDelta);

                    // The TransformBroadcaster might detect that this component is destroyed.
                    // If so, don't continue updating.
                    if (this.enabled)
                    {
                        EnsureComponentInitialized();

                        endpointsNeedingCompleteChanges.Clear();
                        endpointsNeedingDeltaChanges.Clear();

                        filteredEndpointsNeedingCompleteChanges.Clear();
                        filteredEndpointsNeedingDeltaChanges.Clear();
                        filteredEndpointsNotNeedingDeltaChanges.Clear();

                        foreach (SocketEndpoint endpoint in connectionDelta.AddedConnections)
                        {
                            endpointsNeedingCompleteChanges.Add(endpoint);
                            if (ShouldSendChanges(endpoint))
                            {
                                filteredEndpointsNeedingCompleteChanges.Add(endpoint);
                            }
                        }

                        foreach (SocketEndpoint endpoint in connectionDelta.ContinuedConnections)
                        {
                            if (fullyInitializedEndpoints.Contains(endpoint))
                            {
                                endpointsNeedingDeltaChanges.Add(endpoint);
                                if (ShouldSendChanges(endpoint))
                                {
                                    filteredEndpointsNeedingDeltaChanges.Add(endpoint);
                                }
                                else
                                {
                                    filteredEndpointsNotNeedingDeltaChanges.Add(endpoint);
                                }
                            }
                            else
                            {
                                endpointsNeedingCompleteChanges.Add(endpoint);

                                if (ShouldSendChanges(endpoint))
                                {
                                    filteredEndpointsNeedingCompleteChanges.Add(endpoint);
                                }
                            }
                        }

                        SendComponentCreation(endpointsNeedingCompleteChanges);

                        TChangeFlags changeFlags = CalculateDeltaChanges();
                        if (HasChanges(changeFlags) && filteredEndpointsNeedingDeltaChanges.Any())
                        {
                            SendDeltaChanges(filteredEndpointsNeedingDeltaChanges, changeFlags);
                        }

                        if (filteredEndpointsNeedingCompleteChanges.Count > 0)
                        {
                            SendCompleteChanges(filteredEndpointsNeedingCompleteChanges);

                            foreach (SocketEndpoint endpoint in filteredEndpointsNeedingCompleteChanges)
                            {
                                fullyInitializedEndpoints.Add(endpoint);
                            }
                        }

                        foreach (SocketEndpoint endpoint in endpointsNeedingDeltaChanges)
                        {
                            if (!ShouldSendChanges(endpoint))
                            {
                                fullyInitializedEndpoints.Remove(endpoint);
                            }
                        }
                        UpdateRemovedConnections(connectionDelta);

                        EndUpdatingFrame();
                    }
                }
            }
        }