gg,examples: use a timer to limit the rate of updates in breakout, instead of a separate thread, restore ability to run in a browser through emscripten

This commit is contained in:
Delyan Angelov 2025-03-09 08:45:21 +02:00
parent 77a9e6e1b8
commit 2860152e82
No known key found for this signature in database
GPG key ID: 66886C0F12D595ED
2 changed files with 8 additions and 10 deletions

View file

@ -2,7 +2,6 @@ import gg
import gx
import math
import rand
import time
import sokol.audio
import os.asset
import sokol.sgl
@ -295,16 +294,12 @@ fn main() {
width: g.width
height: g.height
window_title: 'V Breakout'
sample_count: 2
init_fn: fn (mut g Game) {
spawn fn (mut g Game) {
for {
g.update()
time.sleep(16666 * time.microsecond)
}
}(mut g)
}
frame_fn: fn (mut g Game) {
dt := g.ctx.timer.elapsed().milliseconds()
if dt > 15 {
g.update()
g.ctx.timer.restart()
}
g.draw()
}
click_fn: fn (x f32, y f32, btn gg.MouseButton, mut g Game) {