public void Simulate() { Serializer.OnSimulateBefore(); Iterator <Command> it; if (IsOwner) { foreach (IEntityBehaviour eb in Behaviours) { try { if (eb != null && ((MonoBehaviour)(object)eb) && eb.Invoke && ReferenceEquals(eb.entity, this.UnityObject)) { eb.SimulateOwner(); } } catch (Exception exn) { Debug.LogException(exn); } } } else { //FIXED: Entities getting frozen on clients after 10 seconds. //if (AscensionNetwork.IsClient) //{ // var diff = AscensionNetwork.ServerFrame - (Serializer as NetworkState).Frames.Last.Frame; // if (diff > 600) // { // Freeze(true); // } //} } if (HasControl) { NetAssert.Null(Controller); // execute all old commands (in order) it = CommandQueue.GetIterator(); while (it.Next()) { NetAssert.True(it.val.Flags & CommandFlags.HAS_EXECUTED); var resetState = ReferenceEquals(it.val, CommandQueue.First); if (resetState) { it.val.SmoothCorrection(); } // exec old command ExecuteCommand(it.val, resetState); } try { canQueueCommands = true; foreach (IEntityBehaviour eb in Behaviours) { if (eb.Invoke && ReferenceEquals(eb.entity, this.UnityObject)) { eb.SimulateController(); } } } finally { canQueueCommands = false; } // execute all new commands (in order) it = CommandQueue.GetIterator(); while (it.Next()) { if (it.val.Flags & CommandFlags.HAS_EXECUTED) { continue; } ExecuteCommand(it.val, false); } // if this is a local entity we are controlling // we should dispose all commands (there is no need to store them) if (IsOwner) { while (CommandQueue.Count > 0) { CommandQueue.RemoveFirst(); } //RemoveOldCommandCallbacks(CommandSequence); } else { //if (CommandQueue.count > 0) { // RemoveOldCommandCallbacks(CommandQueue.First.Sequence); //} } } else { if (Controller != null) { //if (CommandQueue.count > 0) { // RemoveOldCommandCallbacks(CommandQueue.First.Sequence); //} if (ExecuteCommandsFromRemote() == 0) { Command cmd = CommandQueue.LastOrDefault; for (int i = 0; i < Behaviours.Length; ++i) { if (ReferenceEquals(Behaviours[i].entity, this.UnityObject)) { Behaviours[i].MissingCommand(cmd); } } } } } Serializer.OnSimulateAfter(); }