// Broadcasts out replicated modified variables if we're the server, propagates changes recieved from the server if client. private void TickReplication() { bool paused = GetTree().Paused; #if DEBUG using (MDProfiler Profiler = new MDProfiler("MDReplicator.TickReplication")) #endif { if (MDStatics.IsNetworkActive() == false) { return; } // First process any outstanding clocked calls CheckClockedRemoteCalls(); int JIPPeerId = CheckForNewPlayer(); HashSet <MDReplicatedMember> CurrentReplicationList = GroupManager.GetMembersToReplicate(); for (int i = NodeList.Count - 1; i >= 0; --i) { ReplicatedNode RepNode = NodeList[i]; Node Instance = RepNode.Instance.GetRef() as Node; if (!IsInstanceValid(Instance)) { NodeList.RemoveAt(i); } else { RepNode.CheckForNetworkChanges(Instance.GetNetworkMaster()); foreach (MDReplicatedMember RepMember in RepNode.Members) { RepMember.CheckForValueUpdate(); if (!RepMember.ShouldReplicate() || paused && !RepMember.ProcessWhilePaused || RepMember.GetReplicatedType() == MDReplicatedType.JoinInProgress && JIPPeerId == -1) { continue; } MDLog.CTrace(JIPPeerId != -1, LOG_CAT, $"Replicating {RepMember.GetUniqueKey()} to JIP Player {JIPPeerId}"); MDLog.CTrace(JIPPeerId == -1, LOG_CAT, $"Replicating {RepMember.GetUniqueKey()}"); RepMember.Replicate(JIPPeerId, CurrentReplicationList.Contains(RepMember)); } } } } }