From bbb28d20836c1f8464e912b9a1f6cdac29f85bb6 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Mon, 13 Jan 2014 16:02:44 +0900 Subject: [PATCH] Add wait at drawing --- ui/cocoa/game_window.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ui/cocoa/game_window.go b/ui/cocoa/game_window.go index 342c5d65d..5f7515766 100644 --- a/ui/cocoa/game_window.go +++ b/ui/cocoa/game_window.go @@ -21,6 +21,7 @@ import ( "github.com/hajimehoshi/go-ebiten/graphics/opengl" "github.com/hajimehoshi/go-ebiten/ui" "runtime" + "time" "unsafe" ) @@ -98,14 +99,18 @@ func (w *GameWindow) loop(context *opengl.Context, glContext *C.NSOpenGLContext) } func (w *GameWindow) Draw(f func(graphics.Context)) { - //after := time.After(time.Duration(int64(time.Second) / 120)) - //defer <-after - select { case <-w.closed: return default: } + + // Wait 10 millisecond at least to avoid busy loop. + after := time.After(time.Duration(int64(time.Millisecond) * 10)) + defer func() { + <-after + }() + w.useGLContext(func(context *opengl.Context) { context.Update(f) })