public override void CheckForValueUpdate() { if (ShouldReplicate()) { return; } // Find the most recent update uint CurrentTick = GameClock.GetRemoteTick(); if (ValueList.Count == 0 || CurrentTick == LastTickValueWasChanged) { return; } uint NextValue = FindNextValue(); if (NextValue == 0) { // We got no more values in queue return; } // Nothing to interpolate yet if (LastClockedValue.Key == 0) { T Val = GetValueForTick(NextValue); Node node = NodeRef.GetRef() as Node; if (HasValueChanged((T)Member.GetValue(node), Val)) { UpdateValue(Val); } return; } // Interpolate between last and current float TicksSinceLastValue = CurrentTick - LastClockedValue.Key; float TicksBetweenUpdates = NextValue - LastClockedValue.Key; // Set the value T Value = GetValueForTick(NextValue); float Alpha = Mathf.Clamp(TicksSinceLastValue / TicksBetweenUpdates, 0f, 1f); UpdateValue(LinearInterpolate(LastClockedValue.Value, Value, Alpha)); LastTickValueWasChanged = GameClock.GetRemoteTick(); }
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 override void CheckForValueUpdate() { // Check if we are the owner of this if (ShouldReplicate()) { return; } uint RemoteTick = GameClock.GetRemoteTick(); bool ValueChanged = false; // Find the most recent update List <uint> touchedKeys = new List <uint>(); foreach (uint key in ValueList.Keys) { if (key > RemoteTick) { break; } ValueList[key].ForEach(parameters => GetCommandReplicator().MDProcessCommand((object[])parameters)); ValueChanged = true; touchedKeys.Add(key); } if (ValueChanged) { // Remove old touchedKeys.ForEach(k => ValueList.Remove(k)); // Send event if (OnValueChangedCallback != null) { Node Instance = NodeRef.GetRef() as Node; OnValueChangedCallback.Invoke(Instance, null); } } }
public override void SetValues(uint Tick, params object[] Parameters) { // If the tick this update is for is past the current tick if (GameClock.GetRemoteTick() >= Tick || IsSynchInProgress()) { GetCommandReplicator().MDProcessCommand(Parameters); if (OnValueChangedCallback != null) { Node Instance = NodeRef.GetRef() as Node; OnValueChangedCallback.Invoke(Instance, null); } } else { if (!ValueList.ContainsKey(Tick)) { ValueList.Add(Tick, new List <object>()); } ValueList[Tick].Add(Parameters); } }
private IMDCommandReplicator GetCommandReplicator() { Node node = NodeRef.GetRef() as Node; return((IMDCommandReplicator)Member.GetValue(node)); }