class_name SimulationClock
extends RefCounted

var tick_interval: float
var accumulator := 0.0
var elapsed_ticks := 0


func _init(interval: float = 1.0) -> void:
	tick_interval = maxf(interval, 0.0001)


func advance(delta: float) -> int:
	accumulator += maxf(delta, 0.0)
	var ticks_due := 0
	while accumulator >= tick_interval:
		accumulator -= tick_interval
		elapsed_ticks += 1
		ticks_due += 1
	return ticks_due


func reset() -> void:
	accumulator = 0.0
	elapsed_ticks = 0
