public void UpdateHolograms() { if (frames.Count == 0) { return; } float displayTime = (TimeSynchronizer.IsInitialized ? TimeSynchronizer.Instance.GetHologramTime() : Time.time) + localToPackageTimeDelta; // Perform all full updates, but make sure the last frame is not consumed, as it's possible // that network updates are still coming in for that frame, and consuming that frame // before the complete packet is available can result in rendering artifacts for the frame. while (frames.Count > 1 && frames[0].TimeStamp <= displayTime) { FramePackages package = frames[0]; foreach (var d in package.Data) { using (MemoryStream stream = new MemoryStream(d)) using (BinaryReader reader = new BinaryReader(stream)) { StateSynchronizationSceneManager.Instance.ReceiveMessage(currentConnection, reader); } } lastDisplayedPackageTimeStamp = frames[0].TimeStamp; lastLerpTimeStamp = lastDisplayedPackageTimeStamp; frames.RemoveAt(0); } // Perform lerps to next update, but make sure the last frame is not consumed, as it's possible // that network updates are still coming in for that frame, and consuming that frame // before the complete packet is available can result in rendering artifacts for the frame. if (frames.Count > 1) { float lerpVal = Mathf.InverseLerp(lastLerpTimeStamp, frames[0].TimeStamp, displayTime); if (lerpVal > 0.0f) { FramePackages package = frames[0]; foreach (var d in package.Data) { using (MemoryStream stream = new MemoryStream(d)) using (BinaryReader reader = new BinaryReader(stream)) { StateSynchronizationSceneManager.Instance.LerpReceiveMessage(reader, lerpVal); } } lastLerpTimeStamp = displayTime; } } }
private FramePackages GetOrInsertFramePackages(float timeStamp) { FramePackages package = frames.Find((f) => f.TimeStamp == timeStamp); if (package == null) { package = new FramePackages() { TimeStamp = timeStamp }; int i = 0; //Insert sort while (i < frames.Count && frames[i].TimeStamp < timeStamp) { i++; } frames.Insert(i, package); } return(package); }