mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
Refactoring
This commit is contained in:
parent
80c666b266
commit
ab558db683
@ -76,21 +76,19 @@ 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
|
ticket := <-ch
|
||||||
game.Draw(g, offscreen)
|
game.Draw(g, offscreen)
|
||||||
ch<- true
|
ch<- ticket
|
||||||
})
|
})
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
const frameTime = time.Second / 60
|
const frameTime = time.Second / 60
|
||||||
lastTime := time.Now()
|
tick := time.Tick(frameTime)
|
||||||
for {
|
for {
|
||||||
<-ch
|
<-tick
|
||||||
|
ticket := <-ch
|
||||||
game.Update()
|
game.Update()
|
||||||
ch<- true
|
ch<- ticket
|
||||||
now := time.Now()
|
|
||||||
time.Sleep(frameTime - now.Sub(lastTime))
|
|
||||||
lastTime = now
|
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
ch<- true
|
ch<- true
|
||||||
|
@ -92,7 +92,3 @@ func NewTextureFromRGBA(image *image.RGBA) *Texture {
|
|||||||
func (texture *Texture) IsAvailable() bool {
|
func (texture *Texture) IsAvailable() bool {
|
||||||
return texture.id != 0
|
return texture.id != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
|
||||||
// TODO: Initialize OpenGL here?
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user