mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-13 22:47:26 +01:00
Refactoring
This commit is contained in:
parent
5b77d00e84
commit
80c666b266
@ -76,22 +76,24 @@ func main() {
|
|||||||
game := &DemoGame{}
|
game := &DemoGame{}
|
||||||
device = graphics.NewDevice(screenWidth, screenHeight, screenScale,
|
device = graphics.NewDevice(screenWidth, screenHeight, screenScale,
|
||||||
func(g *graphics.GraphicsContext, offscreen *graphics.Texture) {
|
func(g *graphics.GraphicsContext, offscreen *graphics.Texture) {
|
||||||
ch<- true
|
|
||||||
game.Draw(g, offscreen)
|
|
||||||
<-ch
|
<-ch
|
||||||
|
game.Draw(g, offscreen)
|
||||||
|
ch<- true
|
||||||
})
|
})
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
const frameTime = time.Second / 60
|
const frameTime = time.Second / 60
|
||||||
lastTime := time.Now()
|
lastTime := time.Now()
|
||||||
for {
|
for {
|
||||||
ch<- true
|
|
||||||
game.Update()
|
|
||||||
<-ch
|
<-ch
|
||||||
time.Sleep(frameTime - time.Since(lastTime))
|
game.Update()
|
||||||
lastTime = time.Now()
|
ch<- true
|
||||||
|
now := time.Now()
|
||||||
|
time.Sleep(frameTime - now.Sub(lastTime))
|
||||||
|
lastTime = now
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
ch<- true
|
||||||
|
|
||||||
C.glutMainLoop()
|
C.glutMainLoop()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user