diff --git a/examples/breakout/breakout.v b/examples/breakout/breakout.v index ce2bd5d184..fab8375e68 100644 --- a/examples/breakout/breakout.v +++ b/examples/breakout/breakout.v @@ -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) { diff --git a/vlib/gg/gg.c.v b/vlib/gg/gg.c.v index 6086c400b7..f4e0fef823 100644 --- a/vlib/gg/gg.c.v +++ b/vlib/gg/gg.c.v @@ -6,6 +6,7 @@ module gg import os import os.font import gx +import time import sokol.sapp import sokol.sgl import sokol.gfx @@ -202,6 +203,7 @@ pub mut: font_inited bool ui_mode bool // do not redraw everything 60 times/second, but only when the user requests frame u64 // the current frame counted from the start of the application; always increasing + timer time.StopWatch mbtn_mask u8 mouse_buttons MouseButtons // typed version of mbtn_mask; easier to use for user programs @@ -285,6 +287,7 @@ fn gg_init_sokol_window(user_data voidptr) { ctx.pipeline = &PipelineContainer{} ctx.pipeline.init_pipeline() + ctx.timer = time.new_stopwatch() if ctx.config.init_fn != unsafe { nil } { $if android { // NOTE on Android sokol can emit resize events *before* the init function is