moisesjpelaez - Fix pausing and resuming updates

This commit is contained in:
2025-06-02 16:32:28 +00:00
parent 7f5786d47c
commit ae91f8801f

View File

@ -1,7 +1,13 @@
package iron.system; package iron.system;
class Time { class Time {
public static var scale = 1.0;
static var frequency: Null<Int> = null;
static function initFrequency() {
frequency = kha.Display.primary != null ? kha.Display.primary.frequency : 60;
}
public static var step(get, never): Float; public static var step(get, never): Float;
static function get_step(): Float { static function get_step(): Float {
if (frequency == null) initFrequency(); if (frequency == null) initFrequency();
@ -14,37 +20,39 @@ class Time {
return _fixedStep; return _fixedStep;
} }
public static function initFixedStep(value: Float = 1 / 60) { public static function initFixedStep(value: Float = 1 / 60) {
_fixedStep = value; _fixedStep = value;
} }
static var lastTime = 0.0; static var lastTime = 0.0;
public static var delta = 0.0; static var _delta = 0.0;
public static var delta(get, never): Float;
static function get_delta(): Float {
return _delta;
}
static var lastRenderTime = 0.0; static var lastRenderTime = 0.0;
public static var renderDelta = 0.0; static var _renderDelta = 0.0;
public static var renderDelta(get, never): Float;
static function get_renderDelta(): Float {
return _renderDelta;
}
public static inline function time(): Float { public static inline function time(): Float {
return kha.Scheduler.time(); return kha.Scheduler.time();
} }
public static inline function realTime(): Float { public static inline function realTime(): Float {
return kha.Scheduler.realTime(); return kha.Scheduler.realTime();
} }
static var frequency: Null<Int> = null;
static function initFrequency() {
frequency = kha.Display.primary != null ? kha.Display.primary.frequency : 60;
}
public static function update() { public static function update() {
delta = (realTime() - lastTime) * scale; _delta = realTime() - lastTime;
lastTime = realTime(); lastTime = realTime();
} }
public static function render() { public static function render() {
renderDelta = (realTime() - lastRenderTime) * scale; _renderDelta = realTime() - lastRenderTime;
lastRenderTime = realTime(); lastRenderTime = realTime();
} }
} }