Refactoring: unify preUpdate and calling f

This commit is contained in:
Hajime Hoshi 2016-02-27 23:39:06 +09:00
parent 05eaec6dd9
commit e2f528d206
2 changed files with 9 additions and 7 deletions

View File

@ -32,8 +32,14 @@ type graphicsContext struct {
screenScale int
}
func (c *graphicsContext) preUpdate() error {
return c.screen.Clear()
func (c *graphicsContext) update(f func(*Image) error) error {
if err := c.screen.Clear(); err != nil {
return err
}
if err := f(c.screen); err != nil {
return err
}
return nil
}
func (c *graphicsContext) postUpdate() error {

6
run.go
View File

@ -98,11 +98,7 @@ func Run(f func(*Image) error, width, height, scale int, title string) error {
}
for gameTime < now {
gameTime += int64(time.Second / 60)
if err := graphicsContext.preUpdate(); err != nil {
return err
}
if err := f(graphicsContext.screen); err != nil {
if err := graphicsContext.update(f); err != nil {
return err
}
}