public void EndMatch() { LagController.OnMatchFinished(); SyncChangesController.OnEndMatch(); _view.OnEndMatch(); _isPlaying = false; }
public static void GoToPast(float timeShift) { //Debug.Log ("go to past on "+timeShift.ToString()); if (_wentToPast) { Debug.LogError("GoToPast cant go to past second time while previous trip not returned."); return; } if (timeShift < 0) { Debug.LogError("GoToPast timeShift should be non-negative" + timeShift.ToString()); return; } _futureFramesFromServer.Clear(); float currShift = 0; while (currShift < timeShift && _frames.Count > 0) { FrameStamp frame = _frames [_frames.Count - 1]; //Debug.Log ("undoing change on dt="+frame.deltaTime.ToString()); _frames.RemoveAt(_frames.Count - 1); if (frame.IsFromServer) { _futureFramesFromServer.Insert(0, frame); frame.deltaTime = timeShift - currShift; } foreach (var change in frame.Changes) { //Debug.LogFormat ("frame change = (before={0}, after={1})", change.Before.ToString(), change.After.ToString()); SyncChangesController.UndoChange(change); } currShift += frame.deltaTime; Timer.GoToPast(frame.deltaTime); //SyncChangesController.LogCharPos ("after undoing change"); } if (currShift < timeShift) { Debug.LogError("Cant go to past so much " + timeShift.ToString()); return; } //Debug.Log ("little goforward on "+(currShift - timeShift).ToString()); GoForward(currShift - timeShift); _wentToPast = true; }
public static void GoForward(float timeShift) { //Debug.Log ("go forward on "+timeShift.ToString()); if (timeShift < 0) { Debug.LogError("GoForward timeShift should be non-negative" + timeShift.ToString()); return; } float currShift = 0; while (currShift < timeShift) { float delta = Mathf.Min(MaxStep, timeShift - currShift); float deltaFromServer = float.PositiveInfinity; if (_futureFramesFromServer.Count > 0) { deltaFromServer = _futureFramesFromServer [0].deltaTime; } bool applyServerChange = delta > deltaFromServer; delta = Mathf.Min(delta, deltaFromServer); //Debug.Log ("going forward on "+delta.ToString()); if (delta > 0) { currShift += delta; MatchController.Instance.UpdateWithDelta(delta); } //SyncChangesController.LogCharPos ("after forward simulation"); if (applyServerChange) { FrameStamp frame = _futureFramesFromServer [0]; _futureFramesFromServer.RemoveAt(0); foreach (var change in frame.Changes) { SyncChangesController.ApplyChange(change); } } //SyncChangesController.LogCharPos ("after apply server change in forward simulation"); foreach (var frame in _futureFramesFromServer) { frame.deltaTime -= delta; } } _wentToPast = false; }
public void StartMatch(bool multiplayer) { var systems = new List <EntitySystem>() { new MovingSystem() }; if (multiplayer) { systems.Add(new NetworkMatchSystem()); systems.Add(new NetworkInputSystem()); } else { systems.Add(new SinglePlayerMatchSystem()); systems.Add(new InputControlSystem()); } LagController.OnMatchStarted(); TimeMachiene.OnStartMatch(); Entities.Init(systems); SyncChangesController.OnStartMatch(); _view.OnStartMatch(); _isPlaying = true; }