Refactoring

This commit is contained in:
Hajime Hoshi 2013-06-18 21:16:37 +09:00
parent 80c666b266
commit ab558db683
2 changed files with 6 additions and 12 deletions

View File

@ -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

View File

@ -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?
}