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