From 61646e5d03fdcec2eabaa6654c1e13f7beac1511 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 6 Jan 2018 23:30:11 +0900 Subject: [PATCH] Refactoring: Remove updater --- graphicscontext.go | 11 ++++++++++- run.go | 28 +--------------------------- 2 files changed, 11 insertions(+), 28 deletions(-) diff --git a/graphicscontext.go b/graphicscontext.go index c9ebc2539..7ec03fd17 100644 --- a/graphicscontext.go +++ b/graphicscontext.go @@ -17,6 +17,8 @@ package ebiten import ( "math" + "github.com/hajimehoshi/ebiten/internal/audiobinding" + "github.com/hajimehoshi/ebiten/internal/clock" "github.com/hajimehoshi/ebiten/internal/restorable" "github.com/hajimehoshi/ebiten/internal/ui" "github.com/hajimehoshi/ebiten/internal/web" @@ -95,7 +97,14 @@ func drawWithFittingScale(dst *Image, src *Image) { _ = dst.DrawImage(src, op) } -func (c *graphicsContext) Update(updateCount int, afterFrameUpdate func()) error { +func (c *graphicsContext) Update(afterFrameUpdate func()) error { + select { + case err := <-audiobinding.Error(): + return err + default: + } + updateCount := clock.Update() + if err := c.initializeIfNeeded(); err != nil { return err } diff --git a/run.go b/run.go index d1b08368f..307485013 100644 --- a/run.go +++ b/run.go @@ -18,7 +18,6 @@ import ( "image" "sync/atomic" - "github.com/hajimehoshi/ebiten/internal/audiobinding" "github.com/hajimehoshi/ebiten/internal/clock" "github.com/hajimehoshi/ebiten/internal/devicescale" "github.com/hajimehoshi/ebiten/internal/ui" @@ -63,7 +62,7 @@ func IsRunningSlowly() bool { var theGraphicsContext atomic.Value func run(width, height int, scale float64, title string, g *graphicsContext) error { - if err := ui.Run(width, height, scale, title, &updater{g}); err != nil { + if err := ui.Run(width, height, scale, title, g); err != nil { if _, ok := err.(*ui.RegularTermination); ok { return nil } @@ -72,31 +71,6 @@ func run(width, height int, scale float64, title string, g *graphicsContext) err return nil } -type updater struct { - g *graphicsContext -} - -func (u *updater) SetSize(width, height int, scale float64) { - u.g.SetSize(width, height, scale) -} - -func (u *updater) Update(afterFrameUpdate func()) error { - select { - case err := <-audiobinding.Error(): - return err - default: - } - n := clock.Update() - if err := u.g.Update(n, afterFrameUpdate); err != nil { - return err - } - return nil -} - -func (u *updater) Invalidate() { - u.g.Invalidate() -} - // Run runs the game. // f is a function which is called at every frame. // The argument (*Image) is the render target that represents the screen.