public MDReplicatedCommandReplicator(MemberInfo Member, bool Reliable, MDReplicatedType ReplicatedType, WeakRef NodeRef, MDReplicatedSetting[] Settings) : base(Member, true, ReplicatedType, NodeRef, Settings) { GameSession = MDStatics.GetGameSession(); Replicator = GameSession.Replicator; GameClock = GameSession.GetGameClock(); Node node = NodeRef.GetRef() as Node; IMDCommandReplicator CommandReplicator = InitializeCommandReplicator(Member, node); CommandReplicator.MDSetSettings(Settings); }
private IMDCommandReplicator InitializeCommandReplicator(MemberInfo Member, Node Node) { if (Member.GetValue(Node) != null) { return(GetCommandReplicator()); } Type MemberType = Member.GetUnderlyingType(); if (MemberType != null && MemberType.GetInterface(nameof(IMDCommandReplicator)) != null) { IMDCommandReplicator CommandReplicator = Activator.CreateInstance(MemberType) as IMDCommandReplicator; Member.SetValue(Node, CommandReplicator); return(CommandReplicator); } return(null); }
public override void Replicate(int JoinInProgressPeerId, bool IsIntervalReplicationTime) { IMDCommandReplicator CommandReplicator = GetCommandReplicator(); Node Instance = NodeRef.GetRef() as Node; if (CommandReplicator == null) { MDLog.Error(LOG_CAT, $"Command replicator is null for member {Instance.GetPath()}#{Member.Name}"); return; } if ((GetReplicatedType() == MDReplicatedType.Interval && IsIntervalReplicationTime) || (GetReplicatedType() == MDReplicatedType.OnChange)) { // We do a check here to see if anything has updated GetCommandReplicator().MDShouldBeReplicated(); List <object[]> commands = GetCommandReplicator().MDGetCommands(); if (commands.Count > 0) { // Do replication to all except joining peer if we got one commands.ForEach(value => { foreach (int PeerId in GameSession.GetAllPeerIds()) { if (PeerId != JoinInProgressPeerId && PeerId != MDStatics.GetPeerId()) { ReplicateCommandToPeer(value, PeerId); } } }); CheckCallLocalOnChangeCallback(); } } if (JoinInProgressPeerId != -1) { // Replicate current data to joining peer and send current command we are at List <object[]> newPlayerCommands = CommandReplicator.MDGetCommandsForNewPlayer(); newPlayerCommands.ForEach(value => ReplicateCommandToPeer(value, JoinInProgressPeerId)); } }
public MDDisposableList(IEnumerable <T> collection, IMDCommandReplicator ListRef) : base(collection) { MDListRef = ListRef; }