mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +01:00
Refactoring: Remove updater
This commit is contained in:
parent
364823e70c
commit
61646e5d03
@ -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
|
||||
}
|
||||
|
28
run.go
28
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.
|
||||
|
Loading…
Reference in New Issue
Block a user