File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,7 +2,6 @@ import gg
22import gx
33import math
44import rand
5- import time
65import sokol.audio
76import os.asset
87import sokol.sgl
@@ -295,16 +294,12 @@ fn main() {
295294 width: g.width
296295 height: g.height
297296 window_title: 'V Breakout'
298- sample_count: 2
299- init_fn: fn (mut g Game) {
300- spawn fn (mut g Game) {
301- for {
302- g.update ()
303- time.sleep (16666 * time.microsecond)
304- }
305- }(mut g)
306- }
307297 frame_fn: fn (mut g Game) {
298+ dt := g.ctx.timer.elapsed ().milliseconds ()
299+ if dt > 15 {
300+ g.update ()
301+ g.ctx.timer.restart ()
302+ }
308303 g.draw ()
309304 }
310305 click_fn: fn (x f32 , y f32 , btn gg.MouseButton, mut g Game) {
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ module gg
66import os
77import os.font
88import gx
9+ import time
910import sokol.sapp
1011import sokol.sgl
1112import sokol.gfx
@@ -202,6 +203,7 @@ pub mut:
202203 font_inited bool
203204 ui_mode bool // do not redraw everything 60 times/second, but only when the user requests
204205 frame u64 // the current frame counted from the start of the application; always increasing
206+ timer time.StopWatch
205207
206208 mbtn_mask u8
207209 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) {
285287 ctx.pipeline = & PipelineContainer{}
286288 ctx.pipeline.init_pipeline ()
287289
290+ ctx.timer = time.new_stopwatch ()
288291 if ctx.config.init_fn != unsafe { nil } {
289292 $if android {
290293 // NOTE on Android sokol can emit resize events *before* the init function is
You can’t perform that action at this time.
0 commit comments