private InterpolateStep GetFromStep() { if (steps.Count < 2) { return(null); } InterpolateStep toReturn = null; InterpolateStep afterToReturn = steps.Peek(); while (true) { if (afterToReturn.timestamp > interpTime) { break; } toReturn = steps.Dequeue(); if (steps.Count > 0) { afterToReturn = steps.Peek(); } else { break; } } return(toReturn); }
public void AcceptState(InterpolateStep step) { /*if(steps.Count > 0 && step.timestamp < steps.Peek().timestamp) { * //throw away out-of-order messages * return; * }*/ steps.Enqueue(step); offServerTime = (float)(Utils.Timestamp - step.timestamp) / Utils.TICKS_PER_SEC; }
public void AcceptState(InterpolateStep step) { if (lastTruth != null && step.timestamp < lastTruth.timestamp) { //throwaway out-of-order messages return; } long now = Utils.Timestamp; lastTruth = step; //new step is the truth lastTruth.profile.RestoreSelfToGameObject(gameObject); long lastKnownTime = lastTruth.timestamp; knownLag = (now - lastKnownTime) / Utils.TICKS_PER_SEC; if (previousInputs.Count < 1) { //Debug.Log("no saved inputs"); return; } //deque all the ones older than this step InputSnapshot snap = previousInputs.Peek(); while (snap != null && snap.timeSent < lastKnownTime) { previousInputs.Dequeue(); if (previousInputs.Count < 1) { break; } snap = previousInputs.Peek(); } //for the rest use physics magikery to simulate everything Physics.autoSimulation = false; //for each step simulate the futures foreach (InputSnapshot futureSnap in previousInputs) { //simulate teh future InputConsumer.inst.ConsumeInput(-1, futureSnap, false); Physics.Simulate((float)(futureSnap.timeSent - lastKnownTime) / Utils.TICKS_PER_SEC); lastKnownTime = futureSnap.timeSent; } Physics.autoSimulation = true; }
private void Update() { if (steps.Count == 0) { return; } interpTime = (long)(Utils.Timestamp - (lerpDelay * Utils.TICKS_PER_SEC)); from = GetFromStep(); to = GetToStep(); if (to != null && from != null) { double lerpVal = (interpTime - from.timestamp) / (to.timestamp - from.timestamp); LerpAllTheThings(from.profile, to.profile, (float)lerpVal); } else { //Debug.Log(to != null ? "Missing the future step" : "Missing the past step"); } }