mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-23 17:32:02 +01:00
ebiten: undeprecate SetVsyncEnabled / IsVsyncEnabled
This change deprecates FPSMode and SetFPSMode. Closes #2342
This commit is contained in:
parent
066029539e
commit
ac6843639d
@ -55,8 +55,10 @@ func (g *Game) Update() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *Game) Draw(screen *ebiten.Image) {
|
func (g *Game) Draw(screen *ebiten.Image) {
|
||||||
// If there is no inpnut, skip draw. Ebitengine skips GPU usages in this case.
|
// If there is no inpnut, skip draw.
|
||||||
if !g.input && g.introShown {
|
if !g.input && g.introShown {
|
||||||
|
// As SetScreenClearedEveryFrame(false) is called, the screen is not modified.
|
||||||
|
// In this case, Ebitengine optimizes and reduces GPU usages.
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,7 +125,7 @@ func (g *game) Update() error {
|
|||||||
fullscreen := ebiten.IsFullscreen()
|
fullscreen := ebiten.IsFullscreen()
|
||||||
runnableOnUnfocused := ebiten.IsRunnableOnUnfocused()
|
runnableOnUnfocused := ebiten.IsRunnableOnUnfocused()
|
||||||
cursorMode := ebiten.CursorMode()
|
cursorMode := ebiten.CursorMode()
|
||||||
fpsMode := ebiten.FPSMode()
|
vsyncEnabled := ebiten.IsVsyncEnabled()
|
||||||
tps := ebiten.TPS()
|
tps := ebiten.TPS()
|
||||||
decorated := ebiten.IsWindowDecorated()
|
decorated := ebiten.IsWindowDecorated()
|
||||||
positionX, positionY := ebiten.WindowPosition()
|
positionX, positionY := ebiten.WindowPosition()
|
||||||
@ -206,16 +206,7 @@ func (g *game) Update() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if inpututil.IsKeyJustPressed(ebiten.KeyV) {
|
if inpututil.IsKeyJustPressed(ebiten.KeyV) {
|
||||||
switch fpsMode {
|
vsyncEnabled = !vsyncEnabled
|
||||||
case ebiten.FPSModeVsyncOn:
|
|
||||||
fpsMode = ebiten.FPSModeVsyncOffMaximum
|
|
||||||
case ebiten.FPSModeVsyncOffMaximum:
|
|
||||||
fpsMode = ebiten.FPSModeVsyncOffMinimum
|
|
||||||
case ebiten.FPSModeVsyncOffMinimum:
|
|
||||||
fpsMode = ebiten.FPSModeVsyncOn
|
|
||||||
// Reset TPS
|
|
||||||
tps = 60
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if inpututil.IsKeyJustPressed(ebiten.KeyT) {
|
if inpututil.IsKeyJustPressed(ebiten.KeyT) {
|
||||||
switch tps {
|
switch tps {
|
||||||
@ -274,8 +265,8 @@ func (g *game) Update() error {
|
|||||||
|
|
||||||
// Set FPS mode enabled only when this is needed.
|
// Set FPS mode enabled only when this is needed.
|
||||||
// This makes a bug around FPS mode initialization more explicit (#1364).
|
// This makes a bug around FPS mode initialization more explicit (#1364).
|
||||||
if fpsMode != ebiten.FPSMode() {
|
if vsyncEnabled != ebiten.IsVsyncEnabled() {
|
||||||
ebiten.SetFPSMode(fpsMode)
|
ebiten.SetVsyncEnabled(vsyncEnabled)
|
||||||
}
|
}
|
||||||
ebiten.SetTPS(tps)
|
ebiten.SetTPS(tps)
|
||||||
ebiten.SetWindowDecorated(decorated)
|
ebiten.SetWindowDecorated(decorated)
|
||||||
@ -347,7 +338,7 @@ func (g *game) Draw(screen *ebiten.Image) {
|
|||||||
[U] Switch the runnable-on-unfocused state
|
[U] Switch the runnable-on-unfocused state
|
||||||
[C] Switch the cursor mode (visible, hidden, or captured)
|
[C] Switch the cursor mode (visible, hidden, or captured)
|
||||||
[I] Change the window icon (only for desktops)
|
[I] Change the window icon (only for desktops)
|
||||||
[V] Switch the FPS mode
|
[V] Switch the vsync
|
||||||
[T] Switch TPS (ticks per second)
|
[T] Switch TPS (ticks per second)
|
||||||
[D] Switch the window decoration (only for desktops)
|
[D] Switch the window decoration (only for desktops)
|
||||||
[L] Switch the window floating state (only for desktops)
|
[L] Switch the window floating state (only for desktops)
|
||||||
@ -421,7 +412,7 @@ func main() {
|
|||||||
ebiten.MaximizeWindow()
|
ebiten.MaximizeWindow()
|
||||||
}
|
}
|
||||||
if !*flagVsync {
|
if !*flagVsync {
|
||||||
ebiten.SetFPSMode(ebiten.FPSModeVsyncOffMaximum)
|
ebiten.SetVsyncEnabled(false)
|
||||||
}
|
}
|
||||||
if *flagAutoAdjusting {
|
if *flagAutoAdjusting {
|
||||||
ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
|
ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
|
||||||
|
20
run.go
20
run.go
@ -378,16 +378,12 @@ func DeviceScaleFactor() float64 {
|
|||||||
|
|
||||||
// IsVsyncEnabled returns a boolean value indicating whether
|
// IsVsyncEnabled returns a boolean value indicating whether
|
||||||
// the game uses the display's vsync.
|
// the game uses the display's vsync.
|
||||||
//
|
|
||||||
// Deprecated: as of v2.2. Use FPSMode instead.
|
|
||||||
func IsVsyncEnabled() bool {
|
func IsVsyncEnabled() bool {
|
||||||
return ui.FPSMode() == ui.FPSModeVsyncOn
|
return ui.FPSMode() == ui.FPSModeVsyncOn
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetVsyncEnabled sets a boolean value indicating whether
|
// SetVsyncEnabled sets a boolean value indicating whether
|
||||||
// the game uses the display's vsync.
|
// the game uses the display's vsync.
|
||||||
//
|
|
||||||
// Deprecated: as of v2.2. Use SetFPSMode instead.
|
|
||||||
func SetVsyncEnabled(enabled bool) {
|
func SetVsyncEnabled(enabled bool) {
|
||||||
if enabled {
|
if enabled {
|
||||||
ui.SetFPSMode(ui.FPSModeVsyncOn)
|
ui.SetFPSMode(ui.FPSModeVsyncOn)
|
||||||
@ -397,11 +393,15 @@ func SetVsyncEnabled(enabled bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FPSModeType is a type of FPS modes.
|
// FPSModeType is a type of FPS modes.
|
||||||
|
//
|
||||||
|
// Deprecated: as of v2.5. Use SetVsyncEnabled instead.
|
||||||
type FPSModeType = ui.FPSModeType
|
type FPSModeType = ui.FPSModeType
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// FPSModeVsyncOn indicates that the game tries to sync the display's refresh rate.
|
// FPSModeVsyncOn indicates that the game tries to sync the display's refresh rate.
|
||||||
// FPSModeVsyncOn is the default mode.
|
// FPSModeVsyncOn is the default mode.
|
||||||
|
//
|
||||||
|
// Deprecated: as of v2.5. Use SetVsyncEnabled(true) instead.
|
||||||
FPSModeVsyncOn FPSModeType = ui.FPSModeVsyncOn
|
FPSModeVsyncOn FPSModeType = ui.FPSModeVsyncOn
|
||||||
|
|
||||||
// FPSModeVsyncOffMaximum indicates that the game doesn't sync with vsync, and
|
// FPSModeVsyncOffMaximum indicates that the game doesn't sync with vsync, and
|
||||||
@ -411,6 +411,8 @@ const (
|
|||||||
//
|
//
|
||||||
// In FPSModeVsyncOffMaximum, the game's Draw is called almost without sleeping.
|
// In FPSModeVsyncOffMaximum, the game's Draw is called almost without sleeping.
|
||||||
// The game's Update is called based on the specified TPS.
|
// The game's Update is called based on the specified TPS.
|
||||||
|
//
|
||||||
|
// Deprecated: as of v2.5. Use SetVsyncEnabled(false) instead.
|
||||||
FPSModeVsyncOffMaximum FPSModeType = ui.FPSModeVsyncOffMaximum
|
FPSModeVsyncOffMaximum FPSModeType = ui.FPSModeVsyncOffMaximum
|
||||||
|
|
||||||
// FPSModeVsyncOffMinimum indicates that the game doesn't sync with vsync, and
|
// FPSModeVsyncOffMinimum indicates that the game doesn't sync with vsync, and
|
||||||
@ -421,12 +423,17 @@ const (
|
|||||||
// In FPSModeVsyncOffMinimum, the game's Update and Draw are called only when
|
// In FPSModeVsyncOffMinimum, the game's Update and Draw are called only when
|
||||||
// 1) new inputting except for gamepads is detected, or 2) ScheduleFrame is called.
|
// 1) new inputting except for gamepads is detected, or 2) ScheduleFrame is called.
|
||||||
// In FPSModeVsyncOffMinimum, TPS is SyncWithFPS no matter what TPS is specified at SetTPS.
|
// In FPSModeVsyncOffMinimum, TPS is SyncWithFPS no matter what TPS is specified at SetTPS.
|
||||||
|
//
|
||||||
|
// Deprecated: as of v2.5. Use SetVsyncEnabled(false) and SetScreenClearedEveryFrame(false) instead.
|
||||||
|
// See examples/skipdraw for GPU optimization with SetScreenClearedEveryFrame(false).
|
||||||
FPSModeVsyncOffMinimum FPSModeType = ui.FPSModeVsyncOffMinimum
|
FPSModeVsyncOffMinimum FPSModeType = ui.FPSModeVsyncOffMinimum
|
||||||
)
|
)
|
||||||
|
|
||||||
// FPSMode returns the current FPS mode.
|
// FPSMode returns the current FPS mode.
|
||||||
//
|
//
|
||||||
// FPSMode is concurrent-safe.
|
// FPSMode is concurrent-safe.
|
||||||
|
//
|
||||||
|
// Deprecated: as of v2.5. Use SetVsyncEnabled instead.
|
||||||
func FPSMode() FPSModeType {
|
func FPSMode() FPSModeType {
|
||||||
return ui.FPSMode()
|
return ui.FPSMode()
|
||||||
}
|
}
|
||||||
@ -435,6 +442,8 @@ func FPSMode() FPSModeType {
|
|||||||
// The default FPS mode is FPSModeVsyncOn.
|
// The default FPS mode is FPSModeVsyncOn.
|
||||||
//
|
//
|
||||||
// SetFPSMode is concurrent-safe.
|
// SetFPSMode is concurrent-safe.
|
||||||
|
//
|
||||||
|
// Deprecated: as of v2.5. Use SetVsyncEnabled instead.
|
||||||
func SetFPSMode(mode FPSModeType) {
|
func SetFPSMode(mode FPSModeType) {
|
||||||
ui.SetFPSMode(mode)
|
ui.SetFPSMode(mode)
|
||||||
}
|
}
|
||||||
@ -442,6 +451,9 @@ func SetFPSMode(mode FPSModeType) {
|
|||||||
// ScheduleFrame schedules a next frame when the current FPS mode is FPSModeVsyncOffMinimum.
|
// ScheduleFrame schedules a next frame when the current FPS mode is FPSModeVsyncOffMinimum.
|
||||||
//
|
//
|
||||||
// ScheduleFrame is concurrent-safe.
|
// ScheduleFrame is concurrent-safe.
|
||||||
|
//
|
||||||
|
// Deprecated: as of v2.5. Use SetScreenClearedEveryFrame(false) instead.
|
||||||
|
// See examples/skipdraw for GPU optimization with SetScreenClearedEveryFrame(false).
|
||||||
func ScheduleFrame() {
|
func ScheduleFrame() {
|
||||||
ui.Get().ScheduleFrame()
|
ui.Get().ScheduleFrame()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user