mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
Avoid a busy loop
This commit is contained in:
parent
d087333e48
commit
5aa0b5f5c2
@ -82,9 +82,7 @@ func main() {
|
|||||||
case e := <-inputStateUpdated:
|
case e := <-inputStateUpdated:
|
||||||
game.OnInputStateUpdated(e)
|
game.OnInputStateUpdated(e)
|
||||||
case _, ok := <-screenSizeUpdated:
|
case _, ok := <-screenSizeUpdated:
|
||||||
if ok {
|
if !ok {
|
||||||
// Do nothing
|
|
||||||
} else {
|
|
||||||
screenSizeUpdated = nil
|
screenSizeUpdated = nil
|
||||||
}
|
}
|
||||||
case <-windowClosed:
|
case <-windowClosed:
|
||||||
@ -98,15 +96,19 @@ func main() {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
frameTime := time.Duration(int64(time.Second) / 120)
|
||||||
|
tick := time.Tick(frameTime)
|
||||||
for {
|
for {
|
||||||
ui.PollEvents()
|
ui.PollEvents()
|
||||||
select {
|
select {
|
||||||
default:
|
default:
|
||||||
window.Draw(func(actualCanvas graphics.Canvas) {
|
|
||||||
drawing <- graphics.NewLazyCanvas()
|
drawing <- graphics.NewLazyCanvas()
|
||||||
canvas := <-drawing
|
canvas := <-drawing
|
||||||
|
window.Draw(func(actualCanvas graphics.Canvas) {
|
||||||
canvas.Flush(actualCanvas)
|
canvas.Flush(actualCanvas)
|
||||||
})
|
})
|
||||||
|
// To avoid a busy loop, take a rest after drawing.
|
||||||
|
<-tick
|
||||||
case <-quit:
|
case <-quit:
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user