mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-27 03:02:49 +01:00
Add wait at drawing
This commit is contained in:
parent
144b890558
commit
bbb28d2083
@ -21,6 +21,7 @@ import (
|
|||||||
"github.com/hajimehoshi/go-ebiten/graphics/opengl"
|
"github.com/hajimehoshi/go-ebiten/graphics/opengl"
|
||||||
"github.com/hajimehoshi/go-ebiten/ui"
|
"github.com/hajimehoshi/go-ebiten/ui"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"time"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -98,14 +99,18 @@ func (w *GameWindow) loop(context *opengl.Context, glContext *C.NSOpenGLContext)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *GameWindow) Draw(f func(graphics.Context)) {
|
func (w *GameWindow) Draw(f func(graphics.Context)) {
|
||||||
//after := time.After(time.Duration(int64(time.Second) / 120))
|
|
||||||
//defer <-after
|
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-w.closed:
|
case <-w.closed:
|
||||||
return
|
return
|
||||||
default:
|
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) {
|
w.useGLContext(func(context *opengl.Context) {
|
||||||
context.Update(f)
|
context.Update(f)
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user