public override void _Ready() { MDStatics.GI = this; // Configuration first CreateConfiguration(); // Init static classes first MDLog.Initialize(GetLogDirectory()); MDArguments.PopulateArgs(); MDProfiler.Initialize(); MDOnScreenDebug.Initialize(); // Hook up events GetTree().Connect("node_added", this, nameof(OnNodeAdded_Internal)); GetTree().Connect("node_removed", this, nameof(OnNodeRemoved_Internal)); // Init instances CreateGameSession(); CreateGameSynchronizer(); CreateReplicator(); CreateInterfaceManager(); RegisterNodeAndChildren(GetTree().Root); }
// 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)); } } } } }