// oldtime is where the simulation is at now // newtime is the time we want the simulation to progress to // maxtime (not implemented yet) is the longst realworld time that the simulation update is allowed to take. // The function will return the time it progressed to is this one is set and the progression is continues on the next frame. // skipto decides if we progress by updating on all keypoints or just jump to the the new time. // If a playback of simulation data or realtime data occurs we can jump. If we however is generating simulation data we can not skip since it will break the simulation. private double ProgressSimulation(double oldtime, double newtime, double maxtime, bool skipto) { bool forward = ((newtime - oldtime) > 0); double keytime; int i = 0; if (skipto) { SetTime(newtime); UpdateAllExpiered(); return(newtime); } if (forward) { while (closestNext != null && closestNext.NeedUpdate(newtime)) { i++; if (i > 100) { print("break"); } keytime = closestNext.GetNext(); if (keytime < time) { keytime = time; } if (keytime > newtime) { break; } SetTime(keytime); closestNext.ResetNext(); closestNext.UpdateSim(time); closestNext = FindNextClosest(time); } closestPrev = FindPrevClosest(time); } else { while (closestPrev != null && closestPrev.NeedUpdate(newtime)) { i++; if (i > 100) { print("break"); } keytime = closestPrev.GetPrev(); if (keytime > time) { keytime = time; } if (keytime < newtime) { break; } SetTime(keytime); closestNext.ResetPrev(); closestPrev.UpdateSim(time); closestPrev = FindPrevClosest(time); } closestNext = FindNextClosest(time); } SetTime(newtime); return(newtime); }