File tree 2 files changed +8
-10
lines changed
2 files changed +8
-10
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,6 @@ import gg
2
2
import gx
3
3
import math
4
4
import rand
5
- import time
6
5
import sokol.audio
7
6
import os.asset
8
7
import sokol.sgl
@@ -295,16 +294,12 @@ fn main() {
295
294
width: g.width
296
295
height: g.height
297
296
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
- }
307
297
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
+ }
308
303
g.draw ()
309
304
}
310
305
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
6
6
import os
7
7
import os.font
8
8
import gx
9
+ import time
9
10
import sokol.sapp
10
11
import sokol.sgl
11
12
import sokol.gfx
@@ -202,6 +203,7 @@ pub mut:
202
203
font_inited bool
203
204
ui_mode bool // do not redraw everything 60 times/second, but only when the user requests
204
205
frame u64 // the current frame counted from the start of the application; always increasing
206
+ timer time.StopWatch
205
207
206
208
mbtn_mask u8
207
209
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) {
285
287
ctx.pipeline = & PipelineContainer{}
286
288
ctx.pipeline.init_pipeline ()
287
289
290
+ ctx.timer = time.new_stopwatch ()
288
291
if ctx.config.init_fn != unsafe { nil } {
289
292
$if android {
290
293
// 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