From 8f00c8fbf58750980a580b3745e032503bfbd221 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 4 Oct 2020 17:42:54 +0900 Subject: [PATCH] ebiten: Remove the argument from Update Fixes #1260 --- doc.go | 2 +- examples/2048/2048/game.go | 2 +- examples/additive/main.go | 2 +- examples/address/main.go | 2 +- examples/airship/main.go | 2 +- examples/alphablending/main.go | 2 +- examples/animation/main.go | 2 +- examples/audio/main.go | 2 +- examples/audioinfiniteloop/main.go | 2 +- examples/audiopanning/main.go | 2 +- examples/blocks/blocks/game.go | 2 +- examples/blur/main.go | 2 +- examples/camera/main.go | 2 +- examples/chipmunk/main.go | 2 +- examples/contextlost/main.go | 2 +- examples/doomfire/main.go | 2 +- examples/drag/main.go | 2 +- examples/filter/main.go | 2 +- examples/flappy/main.go | 2 +- examples/flood/main.go | 2 +- examples/font/main.go | 2 +- examples/fullscreen/main.go | 2 +- examples/gamepad/main.go | 2 +- examples/highdpi/main.go | 2 +- examples/hsv/main.go | 2 +- examples/hue/main.go | 2 +- examples/infinitescroll/main.go | 2 +- examples/keyboard/main.go | 2 +- examples/life/main.go | 2 +- examples/mandelbrot/main.go | 2 +- examples/mascot/main.go | 2 +- examples/masking/main.go | 2 +- examples/minify/main.go | 2 +- examples/moire/main.go | 2 +- examples/mosaic/main.go | 2 +- examples/noise/main.go | 2 +- examples/paint/main.go | 2 +- examples/particles/main.go | 2 +- examples/pcm/main.go | 2 +- examples/perspective/main.go | 2 +- examples/piano/main.go | 2 +- examples/platformer/main.go | 2 +- examples/polygons/main.go | 2 +- examples/raycasting/main.go | 2 +- examples/rotate/main.go | 2 +- examples/set/main.go | 2 +- examples/shader/main.go | 2 +- examples/shapes/main.go | 2 +- examples/sinewave/main.go | 2 +- examples/snake/main.go | 2 +- examples/sprites/main.go | 2 +- examples/spriteshd/main.go | 2 +- examples/squiral/main.go | 2 +- examples/text/main.go | 2 +- examples/tiles/main.go | 2 +- examples/typewriter/main.go | 2 +- examples/ui/main.go | 2 +- examples/vector/main.go | 2 +- examples/wav/main.go | 2 +- examples/wheel/main.go | 2 +- examples/windowsize/main.go | 2 +- imagedumper_desktop.go | 16 +++++---- imagedumper_notdesktop.go | 6 ++-- internal/buffered/image_test.go | 2 +- internal/testing/testing.go | 2 +- run.go | 55 ++++++++++-------------------- uicontext.go | 8 +---- 67 files changed, 95 insertions(+), 116 deletions(-) diff --git a/doc.go b/doc.go index 2bbb3a701..e5138c54d 100644 --- a/doc.go +++ b/doc.go @@ -21,7 +21,7 @@ // // // Update proceeds the game state. // // Update is called every tick (1/60 [s] by default). -// func (g *Game) Update(screen *ebiten.Image) error { +// func (g *Game) Update() error { // // Write your game's logical update. // return nil // } diff --git a/examples/2048/2048/game.go b/examples/2048/2048/game.go index 88eaf71cf..380a54098 100644 --- a/examples/2048/2048/game.go +++ b/examples/2048/2048/game.go @@ -57,7 +57,7 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeigh } // Update updates the current game state. -func (g *Game) Update(*ebiten.Image) error { +func (g *Game) Update() error { g.input.Update() if err := g.board.Update(g.input); err != nil { return err diff --git a/examples/additive/main.go b/examples/additive/main.go index edcec396a..15d82bd16 100644 --- a/examples/additive/main.go +++ b/examples/additive/main.go @@ -38,7 +38,7 @@ var ( type Game struct{} -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { return nil } diff --git a/examples/address/main.go b/examples/address/main.go index 8809f33fa..77b9f250f 100644 --- a/examples/address/main.go +++ b/examples/address/main.go @@ -104,7 +104,7 @@ func drawRect(screen *ebiten.Image, img *ebiten.Image, x, y, width, height float type Game struct{} -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { return nil } diff --git a/examples/airship/main.go b/examples/airship/main.go index 23e8fd149..778df4435 100644 --- a/examples/airship/main.go +++ b/examples/airship/main.go @@ -241,7 +241,7 @@ func NewGame() *Game { } } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { // Manipulate the player by the input. if ebiten.IsKeyPressed(ebiten.KeySpace) { g.player.MoveForward() diff --git a/examples/alphablending/main.go b/examples/alphablending/main.go index 6fff8e950..644e1585a 100644 --- a/examples/alphablending/main.go +++ b/examples/alphablending/main.go @@ -40,7 +40,7 @@ type Game struct { count int } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { g.count++ g.count %= ebiten.MaxTPS() * 10 return nil diff --git a/examples/animation/main.go b/examples/animation/main.go index 1471ee3e9..7f4714537 100644 --- a/examples/animation/main.go +++ b/examples/animation/main.go @@ -45,7 +45,7 @@ type Game struct { count int } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { g.count++ return nil } diff --git a/examples/audio/main.go b/examples/audio/main.go index 75c5cef52..f99aeca32 100644 --- a/examples/audio/main.go +++ b/examples/audio/main.go @@ -284,7 +284,7 @@ func NewGame() (*Game, error) { }, nil } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { select { case p := <-g.musicPlayerCh: g.musicPlayer = p diff --git a/examples/audioinfiniteloop/main.go b/examples/audioinfiniteloop/main.go index 8eee5c409..d688ff3ee 100644 --- a/examples/audioinfiniteloop/main.go +++ b/examples/audioinfiniteloop/main.go @@ -51,7 +51,7 @@ type Game struct { player *audio.Player } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { if g.player != nil { return nil } diff --git a/examples/audiopanning/main.go b/examples/audiopanning/main.go index 40164cd22..394e8b025 100644 --- a/examples/audiopanning/main.go +++ b/examples/audiopanning/main.go @@ -94,7 +94,7 @@ func lerp(a, b, t float64) float64 { return a*(1-t) + b*t } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { g.initAudio() g.count++ r := float64(g.count) * ((1.0 / 60.0) * 2 * math.Pi) * 0.1 // full cycle every 10 seconds diff --git a/examples/blocks/blocks/game.go b/examples/blocks/blocks/game.go index 2d3ef588e..0e1341859 100644 --- a/examples/blocks/blocks/game.go +++ b/examples/blocks/blocks/game.go @@ -32,7 +32,7 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeigh return ScreenWidth, ScreenHeight } -func (g *Game) Update(*ebiten.Image) error { +func (g *Game) Update() error { if g.sceneManager == nil { g.sceneManager = &SceneManager{} g.sceneManager.GoTo(&TitleScene{}) diff --git a/examples/blur/main.go b/examples/blur/main.go index 8f5fee85f..9744a8320 100644 --- a/examples/blur/main.go +++ b/examples/blur/main.go @@ -37,7 +37,7 @@ var ( type Game struct{} -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { return nil } diff --git a/examples/camera/main.go b/examples/camera/main.go index 8c030f389..7c61c112b 100644 --- a/examples/camera/main.go +++ b/examples/camera/main.go @@ -133,7 +133,7 @@ type Game struct { camera Camera } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { if ebiten.IsKeyPressed(ebiten.KeyA) || ebiten.IsKeyPressed(ebiten.KeyLeft) { g.camera.Position[0] -= 1 } diff --git a/examples/chipmunk/main.go b/examples/chipmunk/main.go index f39d4bd9d..fda93e80d 100644 --- a/examples/chipmunk/main.go +++ b/examples/chipmunk/main.go @@ -90,7 +90,7 @@ func NewGame() *Game { } } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { g.space.Step(1.0 / float64(ebiten.MaxTPS())) return nil } diff --git a/examples/contextlost/main.go b/examples/contextlost/main.go index 0afdf585e..78763cde8 100644 --- a/examples/contextlost/main.go +++ b/examples/contextlost/main.go @@ -78,7 +78,7 @@ func (g *Game) loseAndRestoreContext(context js.Value) { }() } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { if inpututil.IsKeyJustPressed(ebiten.KeySpace) { doc := js.Global().Get("document") canvas := doc.Call("getElementsByTagName", "canvas").Index(0) diff --git a/examples/doomfire/main.go b/examples/doomfire/main.go index b78e78562..652495e17 100644 --- a/examples/doomfire/main.go +++ b/examples/doomfire/main.go @@ -125,7 +125,7 @@ func (g *Game) renderFire() { } } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { g.updateFirePixels() return nil } diff --git a/examples/drag/main.go b/examples/drag/main.go index ed03af417..9265a54b5 100644 --- a/examples/drag/main.go +++ b/examples/drag/main.go @@ -266,7 +266,7 @@ func (g *Game) updateStroke(stroke *Stroke) { stroke.SetDraggingObject(nil) } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonLeft) { s := NewStroke(&MouseStrokeSource{}) s.SetDraggingObject(g.spriteAt(s.Position())) diff --git a/examples/filter/main.go b/examples/filter/main.go index e10dd876e..fdc8d1d4d 100644 --- a/examples/filter/main.go +++ b/examples/filter/main.go @@ -39,7 +39,7 @@ var ( type Game struct { } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { return nil } diff --git a/examples/flappy/main.go b/examples/flappy/main.go index a8f4a3838..09b722b69 100644 --- a/examples/flappy/main.go +++ b/examples/flappy/main.go @@ -203,7 +203,7 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) { return screenWidth, screenHeight } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { switch g.mode { case ModeTitle: if jump() { diff --git a/examples/flood/main.go b/examples/flood/main.go index c8cb04e50..933b01552 100644 --- a/examples/flood/main.go +++ b/examples/flood/main.go @@ -49,7 +49,7 @@ var ( type Game struct { } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { return nil } diff --git a/examples/font/main.go b/examples/font/main.go index 0ae5a2693..1157c396e 100644 --- a/examples/font/main.go +++ b/examples/font/main.go @@ -124,7 +124,7 @@ type Game struct { kanjiTextColor color.RGBA } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { // Change the text color for each second. if g.counter%ebiten.MaxTPS() == 0 { g.kanjiText = nil diff --git a/examples/fullscreen/main.go b/examples/fullscreen/main.go index 1a32a8dbe..927a2d725 100644 --- a/examples/fullscreen/main.go +++ b/examples/fullscreen/main.go @@ -79,7 +79,7 @@ type Game struct { count int } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { g.count++ if ebiten.IsKeyPressed(ebiten.KeyQ) { diff --git a/examples/gamepad/main.go b/examples/gamepad/main.go index ac56268ea..9b27c797f 100644 --- a/examples/gamepad/main.go +++ b/examples/gamepad/main.go @@ -39,7 +39,7 @@ type Game struct { pressedButtons map[int][]string } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { if g.gamepadIDs == nil { g.gamepadIDs = map[int]struct{}{} } diff --git a/examples/highdpi/main.go b/examples/highdpi/main.go index d8643629d..49cd844c2 100644 --- a/examples/highdpi/main.go +++ b/examples/highdpi/main.go @@ -49,7 +49,7 @@ type Game struct { highDPIImage *ebiten.Image } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { // TODO: DeviceScaleFactor() might return different values for different monitors. // Add a mode to adjust the screen size along with the current device scale (#705). // Now this example uses the device scale initialized at the beginning of this application. diff --git a/examples/hsv/main.go b/examples/hsv/main.go index abf7e0601..681dcfa69 100644 --- a/examples/hsv/main.go +++ b/examples/hsv/main.go @@ -68,7 +68,7 @@ func NewGame() *Game { } } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { // Adjust HSV values along with the user's input. if ebiten.IsKeyPressed(ebiten.KeyQ) { g.hue128-- diff --git a/examples/hue/main.go b/examples/hue/main.go index 0a3c0c8a2..e30f04fe0 100644 --- a/examples/hue/main.go +++ b/examples/hue/main.go @@ -40,7 +40,7 @@ type Game struct { count int } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { g.count++ return nil } diff --git a/examples/infinitescroll/main.go b/examples/infinitescroll/main.go index 779421ac4..be864dcd5 100644 --- a/examples/infinitescroll/main.go +++ b/examples/infinitescroll/main.go @@ -78,7 +78,7 @@ type Game struct { viewport viewport } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { g.viewport.Move() return nil } diff --git a/examples/keyboard/main.go b/examples/keyboard/main.go index 27844e0db..5db2a3fc3 100644 --- a/examples/keyboard/main.go +++ b/examples/keyboard/main.go @@ -49,7 +49,7 @@ type Game struct { pressed []ebiten.Key } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { g.pressed = nil for k := ebiten.Key(0); k <= ebiten.KeyMax; k++ { if ebiten.IsKeyPressed(k) { diff --git a/examples/life/main.go b/examples/life/main.go index 11ff25d18..e969bd464 100644 --- a/examples/life/main.go +++ b/examples/life/main.go @@ -160,7 +160,7 @@ type Game struct { pixels []byte } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { g.world.Update() return nil } diff --git a/examples/mandelbrot/main.go b/examples/mandelbrot/main.go index 3fbcd6357..fd74ac58a 100644 --- a/examples/mandelbrot/main.go +++ b/examples/mandelbrot/main.go @@ -81,7 +81,7 @@ func init() { type Game struct { } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { return nil } diff --git a/examples/mascot/main.go b/examples/mascot/main.go index ac483ab27..7c9a2ab59 100644 --- a/examples/mascot/main.go +++ b/examples/mascot/main.go @@ -87,7 +87,7 @@ func (m *mascot) Layout(outsideWidth, outsideHeight int) (int, int) { return width, height } -func (m *mascot) Update(screen *ebiten.Image) error { +func (m *mascot) Update() error { m.count++ sw, sh := ebiten.ScreenSizeInFullscreen() diff --git a/examples/masking/main.go b/examples/masking/main.go index 0db407762..e27ec1764 100644 --- a/examples/masking/main.go +++ b/examples/masking/main.go @@ -96,7 +96,7 @@ func NewGame() *Game { } } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { if g.spotLightVX == 0 { g.spotLightVX = 1 } diff --git a/examples/minify/main.go b/examples/minify/main.go index 7dad518b7..af498526f 100644 --- a/examples/minify/main.go +++ b/examples/minify/main.go @@ -48,7 +48,7 @@ type Game struct { counter int } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { g.counter++ if g.counter == 480 { g.counter = 0 diff --git a/examples/moire/main.go b/examples/moire/main.go index cc048db3e..f7c306ba8 100644 --- a/examples/moire/main.go +++ b/examples/moire/main.go @@ -66,7 +66,7 @@ func (g *game) Layout(outsideWidth, outsideHeight int) (int, int) { return screenWidth, screenHeight } -func (g *game) Update(screen *ebiten.Image) error { +func (g *game) Update() error { fullscreen := ebiten.IsFullscreen() if inpututil.IsKeyJustPressed(ebiten.KeyS) { diff --git a/examples/mosaic/main.go b/examples/mosaic/main.go index e52fb2933..e279b3418 100644 --- a/examples/mosaic/main.go +++ b/examples/mosaic/main.go @@ -58,7 +58,7 @@ func init() { type Game struct { } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { return nil } diff --git a/examples/noise/main.go b/examples/noise/main.go index 71c9151c3..0959ec66e 100644 --- a/examples/noise/main.go +++ b/examples/noise/main.go @@ -49,7 +49,7 @@ type Game struct { noiseImage *image.RGBA } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { // Generate the noise with random RGB values. const l = screenWidth * screenHeight for i := 0; i < l; i++ { diff --git a/examples/paint/main.go b/examples/paint/main.go index 2f36b6c8b..c09e37885 100644 --- a/examples/paint/main.go +++ b/examples/paint/main.go @@ -63,7 +63,7 @@ type Game struct { count int } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { drawn := false // Paint the brush by mouse dragging diff --git a/examples/particles/main.go b/examples/particles/main.go index c17f39b32..fd3f50703 100644 --- a/examples/particles/main.go +++ b/examples/particles/main.go @@ -141,7 +141,7 @@ type Game struct { sprites *list.List } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { if g.sprites == nil { g.sprites = list.New() } diff --git a/examples/pcm/main.go b/examples/pcm/main.go index 049c44e41..dbbd20109 100644 --- a/examples/pcm/main.go +++ b/examples/pcm/main.go @@ -137,7 +137,7 @@ type Game struct { currentNote rune } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { // Play notes for each half second. if g.frames%30 == 0 && audioContext.IsReady() { g.currentNote = playNote(g.scoreIndex) diff --git a/examples/perspective/main.go b/examples/perspective/main.go index 599fb2866..7579e7a25 100644 --- a/examples/perspective/main.go +++ b/examples/perspective/main.go @@ -37,7 +37,7 @@ var ( type Game struct{} -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { return nil } diff --git a/examples/piano/main.go b/examples/piano/main.go index 2a5273add..358234659 100644 --- a/examples/piano/main.go +++ b/examples/piano/main.go @@ -207,7 +207,7 @@ var ( type Game struct { } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { // The piano data is still being initialized. // Get the progress if available. if !pianoNoteSamplesInited { diff --git a/examples/platformer/main.go b/examples/platformer/main.go index 2b29c376c..fbb3d4038 100644 --- a/examples/platformer/main.go +++ b/examples/platformer/main.go @@ -124,7 +124,7 @@ type Game struct { gopher *char } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { if g.gopher == nil { g.gopher = &char{x: 50 * unit, y: groundY * unit} } diff --git a/examples/polygons/main.go b/examples/polygons/main.go index ac4faa1dd..15d517d31 100644 --- a/examples/polygons/main.go +++ b/examples/polygons/main.go @@ -98,7 +98,7 @@ type Game struct { prevNgon int } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { if inpututil.IsKeyJustPressed(ebiten.KeyLeft) { g.ngon-- if g.ngon < 1 { diff --git a/examples/raycasting/main.go b/examples/raycasting/main.go index bcb3c9620..41a0cfac6 100644 --- a/examples/raycasting/main.go +++ b/examples/raycasting/main.go @@ -221,7 +221,7 @@ type Game struct { objects []object } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { if inpututil.IsKeyJustPressed(ebiten.KeyEscape) { return errors.New("game ended by player") } diff --git a/examples/rotate/main.go b/examples/rotate/main.go index 7c692d430..a996b4cd2 100644 --- a/examples/rotate/main.go +++ b/examples/rotate/main.go @@ -40,7 +40,7 @@ type Game struct { count int } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { g.count++ return nil } diff --git a/examples/set/main.go b/examples/set/main.go index 5dc8e20bb..bc9c0cec6 100644 --- a/examples/set/main.go +++ b/examples/set/main.go @@ -45,7 +45,7 @@ func init() { type Game struct { } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { w, h := offscreen.Size() x := rand.Intn(w) y := rand.Intn(h) diff --git a/examples/shader/main.go b/examples/shader/main.go index db6dffbb2..848975448 100644 --- a/examples/shader/main.go +++ b/examples/shader/main.go @@ -96,7 +96,7 @@ type Game struct { time int } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { g.time++ if inpututil.IsKeyJustPressed(ebiten.KeyDown) { g.idx++ diff --git a/examples/shapes/main.go b/examples/shapes/main.go index 078de6fc0..458f7a914 100644 --- a/examples/shapes/main.go +++ b/examples/shapes/main.go @@ -154,7 +154,7 @@ func rect(x, y, w, h float32, clr color.RGBA) ([]ebiten.Vertex, []uint16) { }, []uint16{0, 1, 2, 1, 2, 3} } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { g.count++ g.count %= 240 return nil diff --git a/examples/sinewave/main.go b/examples/sinewave/main.go index 797f9b9b0..407907ee0 100644 --- a/examples/sinewave/main.go +++ b/examples/sinewave/main.go @@ -97,7 +97,7 @@ type Game struct { player *audio.Player } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { if g.player == nil { // Pass the (infinite) stream to audio.NewPlayer. // After calling Play, the stream never ends as long as the player object lives. diff --git a/examples/snake/main.go b/examples/snake/main.go index 2b6196bc3..8dc823a0f 100644 --- a/examples/snake/main.go +++ b/examples/snake/main.go @@ -102,7 +102,7 @@ func (g *Game) reset() { g.moveDirection = dirNone } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { if inpututil.IsKeyJustPressed(ebiten.KeyLeft) || inpututil.IsKeyJustPressed(ebiten.KeyA) { if g.moveDirection != dirRight { g.moveDirection = dirLeft diff --git a/examples/sprites/main.go b/examples/sprites/main.go index 92fdfaa86..9c395401f 100644 --- a/examples/sprites/main.go +++ b/examples/sprites/main.go @@ -163,7 +163,7 @@ func rightTouched() bool { return false } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { if !g.inited { g.init() } diff --git a/examples/spriteshd/main.go b/examples/spriteshd/main.go index d511ab150..c655ae2ae 100644 --- a/examples/spriteshd/main.go +++ b/examples/spriteshd/main.go @@ -145,7 +145,7 @@ func (g *Game) init() { var regularTermination = errors.New("regular termination") -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { if !g.inited { g.init() } diff --git a/examples/squiral/main.go b/examples/squiral/main.go index 5586f61a8..6052d1ffa 100644 --- a/examples/squiral/main.go +++ b/examples/squiral/main.go @@ -289,7 +289,7 @@ func init() { type Game struct{} -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { reset := false if inpututil.IsKeyJustPressed(ebiten.KeyB) { diff --git a/examples/text/main.go b/examples/text/main.go index 1513e4b5d..6a07d3083 100644 --- a/examples/text/main.go +++ b/examples/text/main.go @@ -79,7 +79,7 @@ type Game struct { kanjiTextColor color.RGBA } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { return nil } diff --git a/examples/tiles/main.go b/examples/tiles/main.go index b7303d966..f7b6d505b 100644 --- a/examples/tiles/main.go +++ b/examples/tiles/main.go @@ -63,7 +63,7 @@ type Game struct { layers [][]int } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { return nil } diff --git a/examples/typewriter/main.go b/examples/typewriter/main.go index 353e57aa4..2db259c4a 100644 --- a/examples/typewriter/main.go +++ b/examples/typewriter/main.go @@ -51,7 +51,7 @@ type Game struct { counter int } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { // Add a string from InputChars, that returns string input by users. // Note that InputChars result changes every frame, so you need to call this // every frame. diff --git a/examples/ui/main.go b/examples/ui/main.go index f3b38ed09..e6a0e1de7 100644 --- a/examples/ui/main.go +++ b/examples/ui/main.go @@ -490,7 +490,7 @@ func init() { }) } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { g.button1.Update() g.button2.Update() g.checkBox.Update() diff --git a/examples/vector/main.go b/examples/vector/main.go index b730df2d7..15c9fd94c 100644 --- a/examples/vector/main.go +++ b/examples/vector/main.go @@ -175,7 +175,7 @@ type Game struct { counter int } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { g.counter++ return nil } diff --git a/examples/wav/main.go b/examples/wav/main.go index 08f3990b5..1f992df69 100644 --- a/examples/wav/main.go +++ b/examples/wav/main.go @@ -74,7 +74,7 @@ func init() { } } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { if ebiten.IsKeyPressed(ebiten.KeyP) && !g.audioPlayer.IsPlaying() { // As audioPlayer has one stream and remembers the playing position, // rewinding is needed before playing when reusing audioPlayer. diff --git a/examples/wheel/main.go b/examples/wheel/main.go index 4431cf379..e0dc48548 100644 --- a/examples/wheel/main.go +++ b/examples/wheel/main.go @@ -42,7 +42,7 @@ type Game struct { y float64 } -func (g *Game) Update(screen *ebiten.Image) error { +func (g *Game) Update() error { dx, dy := ebiten.Wheel() g.x += dx g.y += dy diff --git a/examples/windowsize/main.go b/examples/windowsize/main.go index c31d6398a..32536fcf4 100644 --- a/examples/windowsize/main.go +++ b/examples/windowsize/main.go @@ -97,7 +97,7 @@ func (g *game) Layout(outsideWidth, outsideHeight int) (int, int) { return g.width, g.height } -func (g *game) Update(screen *ebiten.Image) error { +func (g *game) Update() error { var ( screenWidth int screenHeight int diff --git a/imagedumper_desktop.go b/imagedumper_desktop.go index a51190680..c7a12da77 100644 --- a/imagedumper_desktop.go +++ b/imagedumper_desktop.go @@ -84,7 +84,7 @@ func dumpInternalImages() error { } type imageDumper struct { - f func(screen *Image) error + g Game keyState map[Key]int @@ -95,15 +95,21 @@ type imageDumper struct { hasDumpInternalImagesKey bool dumpInternalImagesKey Key toDumpInternalImages bool + + err error } -func (i *imageDumper) update(screen *Image) error { +func (i *imageDumper) update() error { + if i.err != nil { + return i.err + } + const ( envScreenshotKey = "EBITEN_SCREENSHOT_KEY" envInternalImagesKey = "EBITEN_INTERNAL_IMAGES_KEY" ) - if err := i.f(screen); err != nil { + if err := i.g.Update(); err != nil { return err } @@ -153,9 +159,7 @@ func (i *imageDumper) update(screen *Image) error { i.keyState[key] = 0 } } - - // TODO: As the screen will be available only from Draw, move this to a drawing function. - return i.dump(screen) + return nil } func (i *imageDumper) dump(screen *Image) error { diff --git a/imagedumper_notdesktop.go b/imagedumper_notdesktop.go index bea6f382d..b80f39929 100644 --- a/imagedumper_notdesktop.go +++ b/imagedumper_notdesktop.go @@ -17,11 +17,11 @@ package ebiten type imageDumper struct { - f func(screen *Image) error + g Game } -func (i *imageDumper) update(screen *Image) error { - return i.f(screen) +func (i *imageDumper) update() error { + return i.g.Update() } func (i *imageDumper) dump(screen *Image) error { diff --git a/internal/buffered/image_test.go b/internal/buffered/image_test.go index 363465a0a..56f5bff56 100644 --- a/internal/buffered/image_test.go +++ b/internal/buffered/image_test.go @@ -42,7 +42,7 @@ type game struct { code int } -func (g *game) Update(*ebiten.Image) error { +func (g *game) Update() error { select { case f := <-mainCh: f() diff --git a/internal/testing/testing.go b/internal/testing/testing.go index d92d02e83..fa57d21ba 100644 --- a/internal/testing/testing.go +++ b/internal/testing/testing.go @@ -30,7 +30,7 @@ type game struct { code int } -func (g *game) Update(*ebiten.Image) error { +func (g *game) Update() error { g.code = g.m.Run() return regularTermination } diff --git a/run.go b/run.go index 98846169b..ceeaca527 100644 --- a/run.go +++ b/run.go @@ -25,20 +25,14 @@ import ( type Game interface { // Update updates a game by one tick. The given argument represents a screen image. // - // Basically Update updates the game logic. Whether Update also draws the screen or not depends on the - // existence of Draw implementation. - // - // The Draw function's definition is: - // - // Draw(screen *Image) - // // Update updates only the game logic and Draw draws the screen. - // In this case, the argument screen's updated content by Update is not adopted for the actual game screen, - // and the screen's updated content by Draw is adopted instead. + // // In the first frame, it is ensured that Update is called at least once before Draw. You can use Update - // to initialize the game state. After the first frame, Update might not be called or might be called once + // to initialize the game state. + // + // After the first frame, Update might not be called or might be called once // or more for one frame. The frequency is determined by the current TPS (tick-per-second). - Update(screen *Image) error + Update() error // Draw draws the game screen by one frame. // @@ -102,32 +96,20 @@ func IsScreenClearedEveryFrame() bool { return atomic.LoadInt32(&isScreenClearedEveryFrame) != 0 } -type imageDumperGame struct { +type imageDumperGameWithDraw struct { game Game d *imageDumper + err error } -func (i *imageDumperGame) Update(screen *Image) error { - if i.d == nil { - i.d = &imageDumper{f: i.game.Update} - } - return i.d.update(screen) -} - -func (i *imageDumperGame) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int) { - return i.game.Layout(outsideWidth, outsideHeight) -} - -type imageDumperGameWithDraw struct { - imageDumperGame - err error -} - -func (i *imageDumperGameWithDraw) Update(screen *Image) error { +func (i *imageDumperGameWithDraw) Update() error { if i.err != nil { return i.err } - return i.imageDumperGame.Update(screen) + if i.d == nil { + i.d = &imageDumper{g: i.game} + } + return i.d.update() } func (i *imageDumperGameWithDraw) Draw(screen *Image) { @@ -136,14 +118,13 @@ func (i *imageDumperGameWithDraw) Draw(screen *Image) { } i.game.Draw(screen) - - // Call dump explicitly. IsDrawingSkipped always returns true when Draw is defined. - if i.d == nil { - i.d = &imageDumper{f: i.game.Update} - } i.err = i.d.dump(screen) } +func (i *imageDumperGameWithDraw) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int) { + return i.game.Layout(outsideWidth, outsideHeight) +} + // RunGame starts the main loop and runs the game. // game's Update function is called every tick to update the game logic. // game's Draw function is, if it exists, called every frame to draw the screen. @@ -188,7 +169,7 @@ func (i *imageDumperGameWithDraw) Draw(screen *Image) { func RunGame(game Game) error { fixWindowPosition(WindowSize()) return runGame(&imageDumperGameWithDraw{ - imageDumperGame: imageDumperGame{game: game}, + game: game, }, 0) } @@ -211,7 +192,7 @@ func runGame(game Game, scale float64) error { func RunGameWithoutMainLoop(game Game) { fixWindowPosition(WindowSize()) game = &imageDumperGameWithDraw{ - imageDumperGame: imageDumperGame{game: game}, + game: game, } theUIContext.set(game, 0) uiDriver().RunWithoutMainLoop(theUIContext) diff --git a/uicontext.go b/uicontext.go index 7192a7dc8..6e0000f16 100644 --- a/uicontext.go +++ b/uicontext.go @@ -194,13 +194,7 @@ func (c *uiContext) update() error { if err := hooks.RunBeforeUpdateHooks(); err != nil { return err } - - // Multiple successive Clear call should be integrated into one graphics command, then - // calling Clear on every Update should not affect the performance. - if IsScreenClearedEveryFrame() { - c.offscreen.Clear() - } - if err := c.game.Update(c.offscreen); err != nil { + if err := c.game.Update(); err != nil { return err } uiDriver().ResetForFrame()