all repos — engine.git @ 70d5a5f53436c4848616132f2ff47c4036adc224

Unnamed repository; edit this file 'description' to name the repository.

src/common/time.odin

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
package common

import "core:time"

Clock :: struct {
	frames: u64,
	period: time.Duration,
	lastTick: time.Tick,
}

ClockUpdate :: proc(clk: ^Clock, callback: proc(clk: ^Clock)) {
	if time.tick_since(clk.lastTick) >= clk.period {
		callback(clk)
		clk.frames += 1
		clk.lastTick = time.tick_now()
	}
}