ebiten: Remove the deprecated functions and constants

Updates #1127
This commit is contained in:
Hajime Hoshi 2020-10-04 04:39:32 +09:00
parent bf515bb594
commit 1d4ff9a906
6 changed files with 24 additions and 365 deletions

View File

@ -67,15 +67,6 @@ func (c *ColorM) Concat(other ColorM) {
c.impl = c.impl.Concat(other.impl) c.impl = c.impl.Concat(other.impl)
} }
// Add adds a matrix, but in a wrong way.
//
// Deprecated: (as of 1.5.0) Do not use this.
//
// Note that this doesn't make sense as an operation for affine matrices.
func (c *ColorM) Add(other ColorM) {
c.impl = c.impl.Add(other.impl)
}
// Scale scales the matrix by (r, g, b, a). // Scale scales the matrix by (r, g, b, a).
func (c *ColorM) Scale(r, g, b, a float64) { func (c *ColorM) Scale(r, g, b, a float64) {
c.impl = c.impl.Scale(float32(r), float32(g), float32(b), float32(a)) c.impl = c.impl.Scale(float32(r), float32(g), float32(b), float32(a))
@ -123,39 +114,3 @@ func (c *ColorM) IsInvertible() bool {
func (c *ColorM) Invert() { func (c *ColorM) Invert() {
c.impl = c.impl.Invert() c.impl = c.impl.Invert()
} }
// Monochrome returns a color matrix for monochrome.
//
// Deprecated: (as of 1.6.0) Use ChangeHSV(0, 0, 1) instead.
func Monochrome() ColorM {
c := ColorM{}
c.ChangeHSV(0, 0, 1)
return c
}
// ScaleColor returns a color matrix for scaling.
//
// Deprecated: (as of 1.2.0) Use Scale instead.
func ScaleColor(r, g, b, a float64) ColorM {
c := ColorM{}
c.Scale(r, g, b, a)
return c
}
// TranslateColor returns a color matrix for translating.
//
// Deprecated: (as of 1.2.0) Use Translate instead.
func TranslateColor(r, g, b, a float64) ColorM {
c := ColorM{}
c.Translate(r, g, b, a)
return c
}
// RotateHue returns a color matrix for chanting the hue.
//
// Deprecated: (as of 1.2.0-alpha) Use RotateHue member function instead.
func RotateHue(theta float64) ColorM {
c := ColorM{}
c.RotateHue(theta)
return c
}

View File

@ -36,23 +36,6 @@ import (
) )
var ( var (
// flagLegacy represents whether the legacy APIs are used or not.
// If flagLegacy is true, these legacy APIs are used:
//
// * ebiten.Run
// * ebiten.ScreenScale
// * ebiten.SetScreenScale
// * ebiten.SetScreenSize
//
// If flagLegacy is false, these APIs are used:
//
// * ebiten.RunGame
// * ebiten.SetWindowSize
// * ebiten.WindowSize
//
// A resizable window is available only when flagLegacy is false.
flagLegacy = flag.Bool("legacy", false, "use the legacy API")
flagFullscreen = flag.Bool("fullscreen", false, "fullscreen") flagFullscreen = flag.Bool("fullscreen", false, "fullscreen")
flagResizable = flag.Bool("resizable", false, "make the window resizable") flagResizable = flag.Bool("resizable", false, "make the window resizable")
flagWindowPosition = flag.String("windowposition", "", "window position (e.g., 100,200)") flagWindowPosition = flag.String("windowposition", "", "window position (e.g., 100,200)")
@ -120,23 +103,18 @@ func (g *game) Update(screen *ebiten.Image) error {
screenHeight int screenHeight int
screenScale float64 screenScale float64
) )
if *flagLegacy { screenWidth = g.width
screenWidth, screenHeight = screen.Size() screenHeight = g.height
screenScale = ebiten.ScreenScale() if ww, wh := ebiten.WindowSize(); ww > 0 && wh > 0 {
screenScale = math.Min(float64(ww)/float64(g.width), float64(wh)/float64(g.height))
} else { } else {
screenWidth = g.width // ebiten.WindowSize can return (0, 0) on browsers or mobiles.
screenHeight = g.height screenScale = 1
if ww, wh := ebiten.WindowSize(); ww > 0 && wh > 0 {
screenScale = math.Min(float64(ww)/float64(g.width), float64(wh)/float64(g.height))
} else {
// ebiten.WindowSize can return (0, 0) on browsers or mobiles.
screenScale = 1
}
} }
fullscreen := ebiten.IsFullscreen() fullscreen := ebiten.IsFullscreen()
runnableOnUnfocused := ebiten.IsRunnableOnUnfocused() runnableOnUnfocused := ebiten.IsRunnableOnUnfocused()
cursorVisible := ebiten.IsCursorVisible() cursorVisible := ebiten.CursorMode() == ebiten.CursorModeVisible
vsyncEnabled := ebiten.IsVsyncEnabled() vsyncEnabled := ebiten.IsVsyncEnabled()
tps := ebiten.MaxTPS() tps := ebiten.MaxTPS()
decorated := ebiten.IsWindowDecorated() decorated := ebiten.IsWindowDecorated()
@ -242,18 +220,17 @@ func (g *game) Update(screen *ebiten.Image) error {
} }
if toUpdateWindowSize { if toUpdateWindowSize {
if *flagLegacy { g.width = screenWidth
ebiten.SetScreenSize(screenWidth, screenHeight) g.height = screenHeight
ebiten.SetScreenScale(screenScale) ebiten.SetWindowSize(int(float64(screenWidth)*screenScale), int(float64(screenHeight)*screenScale))
} else {
g.width = screenWidth
g.height = screenHeight
ebiten.SetWindowSize(int(float64(screenWidth)*screenScale), int(float64(screenHeight)*screenScale))
}
} }
ebiten.SetFullscreen(fullscreen) ebiten.SetFullscreen(fullscreen)
ebiten.SetRunnableOnUnfocused(runnableOnUnfocused) ebiten.SetRunnableOnUnfocused(runnableOnUnfocused)
ebiten.SetCursorVisible(cursorVisible) if cursorVisible {
ebiten.SetCursorMode(ebiten.CursorModeVisible)
} else {
ebiten.SetCursorMode(ebiten.CursorModeHidden)
}
ebiten.SetVsyncEnabled(vsyncEnabled) ebiten.SetVsyncEnabled(vsyncEnabled)
ebiten.SetMaxTPS(tps) ebiten.SetMaxTPS(tps)
ebiten.SetWindowDecorated(decorated) ebiten.SetWindowDecorated(decorated)
@ -269,10 +246,7 @@ func (g *game) Update(screen *ebiten.Image) error {
if restore { if restore {
ebiten.RestoreWindow() ebiten.RestoreWindow()
} }
if !*flagLegacy { ebiten.SetWindowResizable(resizable)
// A resizable window is available only with RunGame.
ebiten.SetWindowResizable(resizable)
}
if inpututil.IsKeyJustPressed(ebiten.KeyI) { if inpututil.IsKeyJustPressed(ebiten.KeyI) {
ebiten.SetWindowIcon([]image.Image{createRandomIconImage()}) ebiten.SetWindowIcon([]image.Image{createRandomIconImage()})
@ -311,13 +285,7 @@ func (g *game) Draw(screen *ebiten.Image) {
} }
msgM := strings.Join(lines, "\n") msgM := strings.Join(lines, "\n")
var msgS string msgR := "[R] Switch the window resizable state (only for desktops)\n"
var msgR string
if *flagLegacy {
msgS = "[S] Change the window scale (only for desktops)\n"
} else {
msgR = "[R] Switch the window resizable state (only for desktops)\n"
}
fg := "Yes" fg := "Yes"
if !ebiten.IsFocused() { if !ebiten.IsFocused() {
fg = "No" fg = "No"
@ -335,13 +303,12 @@ func (g *game) Draw(screen *ebiten.Image) {
[L] Switch the window floating state (only for desktops) [L] Switch the window floating state (only for desktops)
[W] Switch whether to skip clearing the screen [W] Switch whether to skip clearing the screen
%s %s
%s
IsFocused?: %s IsFocused?: %s
Windows Position: (%d, %d) Windows Position: (%d, %d)
Cursor: (%d, %d) Cursor: (%d, %d)
TPS: Current: %0.2f / Max: %s TPS: Current: %0.2f / Max: %s
FPS: %0.2f FPS: %0.2f
Device Scale Factor: %0.2f`, msgS, msgM, msgR, fg, wx, wy, cx, cy, ebiten.CurrentTPS(), tpsStr, ebiten.CurrentFPS(), ebiten.DeviceScaleFactor()) Device Scale Factor: %0.2f`, msgM, msgR, fg, wx, wy, cx, cy, ebiten.CurrentTPS(), tpsStr, ebiten.CurrentFPS(), ebiten.DeviceScaleFactor())
ebitenutil.DebugPrint(screen, msg) ebitenutil.DebugPrint(screen, msg)
} }
@ -369,10 +336,6 @@ func main() {
w, h := ebiten.ScreenSizeInFullscreen() w, h := ebiten.ScreenSizeInFullscreen()
fmt.Printf("Screen size in fullscreen: %d, %d\n", w, h) fmt.Printf("Screen size in fullscreen: %d, %d\n", w, h)
if !*flagLegacy {
fmt.Println("Tip: With -autoadjusting flag, you can make an adjustable game screen.")
}
// Decode image from a byte slice instead of a file so that // Decode image from a byte slice instead of a file so that
// this example works in any working directory. // this example works in any working directory.
// If you want to use a file, there are some options: // If you want to use a file, there are some options:
@ -415,9 +378,6 @@ func main() {
} }
ebiten.SetVsyncEnabled(*flagVsync) ebiten.SetVsyncEnabled(*flagVsync)
if *flagAutoAdjusting { if *flagAutoAdjusting {
if *flagLegacy {
log.Println("-autoadjusting flag cannot work with -legacy flag")
}
ebiten.SetWindowResizable(true) ebiten.SetWindowResizable(true)
} }
@ -427,27 +387,11 @@ func main() {
} }
const title = "Window Size (Ebiten Demo)" const title = "Window Size (Ebiten Demo)"
if *flagLegacy { ww := int(float64(g.width) * initScreenScale)
update := func(screen *ebiten.Image) error { wh := int(float64(g.height) * initScreenScale)
if err := g.Update(screen); err != nil { ebiten.SetWindowSize(ww, wh)
return err ebiten.SetWindowTitle(title)
} if err := ebiten.RunGame(g); err != nil {
if ebiten.IsDrawingSkipped() { log.Fatal(err)
return nil
}
g.Draw(screen)
return nil
}
if err := ebiten.Run(update, g.width, g.height, initScreenScale, title); err != nil {
log.Fatal(err)
}
} else {
w := int(float64(g.width) * initScreenScale)
h := int(float64(g.height) * initScreenScale)
ebiten.SetWindowSize(w, h)
ebiten.SetWindowTitle(title)
if err := ebiten.RunGame(g); err != nil {
log.Fatal(err)
}
} }
} }

41
geom.go
View File

@ -98,20 +98,6 @@ func (g *GeoM) Concat(other GeoM) {
g.ty = ty g.ty = ty
} }
// Add adds a matrix, but in a wrong way.
//
// Deprecated: (as of 1.5.0) Do not use this.
//
// Note that this doesn't make sense as an operation for affine matrices.
func (g *GeoM) Add(other GeoM) {
g.a_1 += other.a_1
g.b += other.b
g.c += other.c
g.d_1 += other.d_1
g.tx += other.tx
g.ty += other.ty
}
// Scale scales the matrix by (x, y). // Scale scales the matrix by (x, y).
func (g *GeoM) Scale(x, y float64) { func (g *GeoM) Scale(x, y float64) {
a := (g.a_1 + 1) * x a := (g.a_1 + 1) * x
@ -232,30 +218,3 @@ func (g *GeoM) SetElement(i, j int, element float64) {
panic("ebiten: i or j is out of index") panic("ebiten: i or j is out of index")
} }
} }
// ScaleGeo returns a geometry matrix for scaling.
//
// Deprecated: (as of 1.2.0) Use Scale instead.
func ScaleGeo(x, y float64) GeoM {
g := GeoM{}
g.Scale(x, y)
return g
}
// TranslateGeo returns a geometry matrix for translating.
//
// Deprecated: (as of 1.2.0) Use Translate instead.
func TranslateGeo(tx, ty float64) GeoM {
g := GeoM{}
g.Translate(tx, ty)
return g
}
// RotateGeo returns a geometry matrix for rotating.
//
// Deprecated: (as of 1.2.0) Use Rotate instead.
func RotateGeo(theta float64) GeoM {
g := GeoM{}
g.Rotate(theta)
return g
}

View File

@ -851,10 +851,3 @@ func newScreenFramebufferImage(width, height int) *Image {
i.addr = i i.addr = i
return i return i
} }
// MaxImageSize represented the maximum size of an image, but now this constant is deprecated.
//
// Deprecated: (as of 1.7.0) No replacement so far.
//
// TODO: Make this replacement (#541)
var MaxImageSize = 4096

View File

@ -214,44 +214,3 @@ func TouchPosition(id int) (int, int) {
return uiDriver().Input().TouchPosition(id) return uiDriver().Input().TouchPosition(id)
} }
// Touch represents a touch.
//
// Deprecated: (as of 1.7.0). Use TouchPosition instead.
type Touch interface {
// ID returns an identifier for one stroke.
ID() int
// Position returns the position of the touch.
Position() (x, y int)
}
type touch struct {
id int
x int
y int
}
func (t *touch) ID() int {
return t.id
}
func (t *touch) Position() (x, y int) {
return t.x, t.y
}
// Touches returns the current touches.
//
// Deprecated: (as of 1.7.0) Use TouchIDs instead.
func Touches() []Touch {
var ts []Touch
for _, id := range TouchIDs() {
x, y := TouchPosition(id)
ts = append(ts, &touch{
id: id,
x: x,
y: y,
})
}
return ts
}

151
run.go
View File

@ -72,11 +72,6 @@ type Game interface {
// TPS represents a default ticks per second, that represents how many times game updating happens in a second. // TPS represents a default ticks per second, that represents how many times game updating happens in a second.
const DefaultTPS = 60 const DefaultTPS = 60
// FPS represents the default TPS (tick per second). This is for backward compatibility.
//
// Deprecated: (as of 1.8.0) Use DefaultTPS instead.
const FPS = DefaultTPS
// CurrentFPS returns the current number of FPS (frames per second), that represents // CurrentFPS returns the current number of FPS (frames per second), that represents
// how many swapping buffer happens per second. // how many swapping buffer happens per second.
// //
@ -152,79 +147,6 @@ func IsDrawingSkipped() bool {
return atomic.LoadInt32(&isDrawingSkipped) != 0 return atomic.LoadInt32(&isDrawingSkipped) != 0
} }
// IsRunningSlowly is an old name for IsDrawingSkipped.
//
// Deprecated: (as of 1.8.0) Use Game's Draw function instead.
func IsRunningSlowly() bool {
return IsDrawingSkipped()
}
// Run starts the main loop and runs the game.
//
// Deprecated: (as of 1.12.0) Use RunGame instead.
//
// f is a function which is called at every frame.
// The argument (*Image) is the render target that represents the screen.
// The screen size is based on the given values (width and height).
//
// Run is a shorthand for RunGame, but there are some restrictions.
// If you want to resize the window by dragging, use RunGame instead.
//
// A window size is based on the given values (width, height and scale).
//
// scale is used to enlarge the screen on desktops.
// scale is ignored on browsers or mobiles.
// Note that the actual screen is multiplied not only by the given scale but also
// by the device scale on high-DPI display.
// If you pass inverse of the device scale,
// you can disable this automatical device scaling as a result.
// You can get the device scale by DeviceScaleFactor function.
//
// On browsers, the scale is automatically adjusted.
// It is strongly recommended to use iframe if you embed an Ebiten application in your website.
// scale works as this as of 1.10.0-alpha.
// Before that, scale affected the rendering scale.
//
// On mobiles, if you use ebitenmobile command, the scale is automatically adjusted.
//
// Run must be called on the main thread.
// Note that Ebiten bounds the main goroutine to the main OS thread by runtime.LockOSThread.
//
// Ebiten tries to call f 60 times a second by default. In other words,
// TPS (ticks per second) is 60 by default.
// This is not related to framerate (display's refresh rate).
//
// f is not called when the window is in background by default.
// This setting is configurable with SetRunnableOnUnfocused.
//
// The given scale is ignored on fullscreen mode or gomobile-build mode.
//
// On non-GopherJS environments, Run returns error when 1) OpenGL error happens, 2) audio error happens or
// 3) f returns error. In the case of 3), Run returns the same error.
//
// On GopherJS, Run returns immediately.
// It is because the 'main' goroutine cannot be blocked on GopherJS due to the bug (gopherjs/gopherjs#826).
// When an error happens, this is shown as an error on the console.
//
// The size unit is device-independent pixel.
//
// Don't call Run twice or more in one process.
func Run(f func(*Image) error, width, height int, scale float64, title string) error {
if IsWindowResizable() {
panic("ebiten: a resizable window works with RunGame, not Run")
}
game := &defaultGame{
update: (&imageDumper{f: f}).update,
width: width,
height: height,
}
ww, wh := int(float64(width)*scale), int(float64(height)*scale)
fixWindowPosition(ww, wh)
SetWindowSize(ww, wh)
SetWindowTitle(title)
return runGame(game, scale)
}
type imageDumperGame struct { type imageDumperGame struct {
game Game game Game
d *imageDumper d *imageDumper
@ -366,40 +288,6 @@ func ScreenSizeInFullscreen() (int, int) {
return uiDriver().ScreenSizeInFullscreen() return uiDriver().ScreenSizeInFullscreen()
} }
// MonitorSize is an old name for ScreenSizeInFullscreen.
//
// Deprecated: (as of 1.8.0) Use ScreenSizeInFullscreen instead.
func MonitorSize() (int, int) {
return ScreenSizeInFullscreen()
}
// SetScreenSize sets the game screen size and resizes the window.
//
// Deprecated: (as of 1.11.0) Use SetWindowSize and RunGame (Game's Layout) instead.
func SetScreenSize(width, height int) {
if width <= 0 || height <= 0 {
panic("ebiten: width and height must be positive")
}
theUIContext.setScreenSize(width, height)
}
// SetScreenScale sets the game screen scale and resizes the window.
//
// Deprecated: (as of 1.11.0-alpha). Use SetWindowSize instead.
func SetScreenScale(scale float64) {
if scale <= 0 {
panic("ebiten: scale must be positive")
}
theUIContext.setScaleForWindow(scale)
}
// ScreenScale returns the game screen scale.
//
// Deprecated: (as of 1.11.0-alpha) Use WindowSize instead.
func ScreenScale() float64 {
return theUIContext.getScaleForWindow()
}
// CursorMode returns the current cursor mode. // CursorMode returns the current cursor mode.
// //
// On browsers, only CursorModeVisible and CursorModeHidden are supported. // On browsers, only CursorModeVisible and CursorModeHidden are supported.
@ -425,31 +313,6 @@ func SetCursorMode(mode CursorModeType) {
uiDriver().SetCursorMode(driver.CursorMode(mode)) uiDriver().SetCursorMode(driver.CursorMode(mode))
} }
// IsCursorVisible reports whether the cursor is visible or not.
//
// Deprecated: (as of 1.11.0-alpha) Use CursorMode instead.
func IsCursorVisible() bool {
return CursorMode() == CursorModeVisible
}
// SetCursorVisible sets the cursor visibility.
//
// Deprecated: (as of 1.11.0-alpha) Use SetCursorMode instead.
func SetCursorVisible(visible bool) {
if visible {
SetCursorMode(CursorModeVisible)
} else {
SetCursorMode(CursorModeHidden)
}
}
// SetCursorVisibility sets the cursor visibility.
//
// Deprecated: (as of 1.6.0-alpha) Use SetCursorMode instead.
func SetCursorVisibility(visible bool) {
SetCursorVisible(visible)
}
// IsFullscreen reports whether the current mode is fullscreen or not. // IsFullscreen reports whether the current mode is fullscreen or not.
// //
// IsFullscreen always returns false on browsers. // IsFullscreen always returns false on browsers.
@ -500,13 +363,6 @@ func IsRunnableOnUnfocused() bool {
return uiDriver().IsRunnableOnUnfocused() return uiDriver().IsRunnableOnUnfocused()
} }
// IsRunnableInBackground is an old name for IsRunnableOnUnfocused.
//
// Deprecated: (as of 1.11.0) Use IsRunnableOnUnfocused instead.
func IsRunnableInBackground() bool {
return IsRunnableOnUnfocused()
}
// SetRunnableOnUnfocused sets the state if the game runs even in background. // SetRunnableOnUnfocused sets the state if the game runs even in background.
// //
// If the given value is true, the game runs in background e.g. when losing focus. // If the given value is true, the game runs in background e.g. when losing focus.
@ -522,13 +378,6 @@ func SetRunnableOnUnfocused(runnableOnUnfocused bool) {
uiDriver().SetRunnableOnUnfocused(runnableOnUnfocused) uiDriver().SetRunnableOnUnfocused(runnableOnUnfocused)
} }
// SetRunnableInBackground is an old name for SetRunnableOnUnfocused.
//
// Deprecated: (as of 1.11.0-alpha) Use SetRunnableOnUnfocused instead.
func SetRunnableInBackground(runnableInBackground bool) {
SetRunnableOnUnfocused(runnableInBackground)
}
// DeviceScaleFactor returns a device scale factor value of the current monitor which the window belongs to. // DeviceScaleFactor returns a device scale factor value of the current monitor which the window belongs to.
// //
// DeviceScaleFactor returns a meaningful value on high-DPI display environment, // DeviceScaleFactor returns a meaningful value on high-DPI display environment,