// // Created by darman on 9/24/26. // #include "SimClock.h" #include namespace SiegeDeck::Engine { SimClock::SimClock(double stepDt, int32 maxStepsPerFrame) : stepDt(stepDt), maxBacklog(stepDt * maxStepsPerFrame) { if (stepDt <= 0.0 || maxStepsPerFrame < 1) throw std::invalid_argument("SimClock needs a positive step and at least one step per frame"); } void SimClock::Accumulate(double realDt) { // Capping here, not in the step loop, keeps the caller's loop a plain while. It also // means a stall loses its excess time for good instead of piling up across frames. accumulator = std::min(accumulator + realDt * speed, maxBacklog); } bool SimClock::ConsumeStep() { if (accumulator < stepDt) return false; accumulator -= stepDt; ++stepIndex; return true; } void SimClock::SetSpeed(double newSpeed) { // The accumulator is kept on pause, so Alpha() holds still and paused entities don't snap. speed = std::max(newSpeed, 0.0); } }