delta time!

This commit is contained in:
Morrígan 2025-06-26 22:32:55 +02:00
parent 22d1469b0f
commit 266adb051e
Signed by: morrigan
GPG key ID: CACB010F463A77D0
2 changed files with 22 additions and 8 deletions

View file

@ -11,6 +11,8 @@ Game :: struct {
render: ^sdl3.Renderer,
units: [dynamic]Unit,
player: Unit,
time: u64,
delta: f32,
input_state: map[sdl3.Scancode]bool,
}
@ -30,10 +32,16 @@ main :: proc() {
append(&units, Unit{faction = Faction.Allied, position = Position{x = 500, y = 500}, hp = 100})
append(&units, Unit{faction = Faction.Enemy, position = Position{x = 700, y = 700}, hp = 100})
input_state := make(map[sdl3.Scancode]bool)
time := sdl3.GetTicksNS()
game := Game {
render = render,
units = units,
player = Unit{faction = Faction.Player, position = Position{x = 255, y = 255}, hp = 100},
time = time,
delta = 0.0,
input_state = input_state,
}
@ -65,4 +73,9 @@ RenderGame :: proc(game: ^Game) {
RenderUnit(game.player, game)
sdl3.RenderPresent(game.render)
new_time := sdl3.GetTicksNS()
delta_ns := new_time - game.time
game.time = new_time
game.delta = f32(delta_ns) / f32(sdl3.NS_PER_SECOND)
}