From 80c666b2665d1698484f04373c418608b5420e33 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Tue, 18 Jun 2013 10:45:44 +0900 Subject: [PATCH] Refactoring --- examples/glut/main.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/examples/glut/main.go b/examples/glut/main.go index fb4b795cd..5fd6ba7dc 100644 --- a/examples/glut/main.go +++ b/examples/glut/main.go @@ -76,22 +76,24 @@ func main() { game := &DemoGame{} device = graphics.NewDevice(screenWidth, screenHeight, screenScale, func(g *graphics.GraphicsContext, offscreen *graphics.Texture) { - ch<- true - game.Draw(g, offscreen) <-ch + game.Draw(g, offscreen) + ch<- true }) go func() { const frameTime = time.Second / 60 lastTime := time.Now() for { - ch<- true - game.Update() <-ch - time.Sleep(frameTime - time.Since(lastTime)) - lastTime = time.Now() + game.Update() + ch<- true + now := time.Now() + time.Sleep(frameTime - now.Sub(lastTime)) + lastTime = now } }() + ch<- true C.glutMainLoop() }