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) {
|
||||
// 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 {
|
||||
// As SetScreenClearedEveryFrame(false) is called, the screen is not modified.
|
||||
// In this case, Ebitengine optimizes and reduces GPU usages.
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -125,7 +125,7 @@ func (g *game) Update() error {
|
||||
fullscreen := ebiten.IsFullscreen()
|
||||
runnableOnUnfocused := ebiten.IsRunnableOnUnfocused()
|
||||
cursorMode := ebiten.CursorMode()
|
||||
fpsMode := ebiten.FPSMode()
|
||||
vsyncEnabled := ebiten.IsVsyncEnabled()
|
||||
tps := ebiten.TPS()
|
||||
decorated := ebiten.IsWindowDecorated()
|
||||
positionX, positionY := ebiten.WindowPosition()
|
||||
@ -206,16 +206,7 @@ func (g *game) Update() error {
|
||||
}
|
||||
}
|
||||
if inpututil.IsKeyJustPressed(ebiten.KeyV) {
|
||||
switch fpsMode {
|
||||
case ebiten.FPSModeVsyncOn:
|
||||
fpsMode = ebiten.FPSModeVsyncOffMaximum
|
||||
case ebiten.FPSModeVsyncOffMaximum:
|
||||
fpsMode = ebiten.FPSModeVsyncOffMinimum
|
||||
case ebiten.FPSModeVsyncOffMinimum:
|
||||
fpsMode = ebiten.FPSModeVsyncOn
|
||||
// Reset TPS
|
||||
tps = 60
|
||||
}
|
||||
vsyncEnabled = !vsyncEnabled
|
||||
}
|
||||
if inpututil.IsKeyJustPressed(ebiten.KeyT) {
|
||||
switch tps {
|
||||
@ -274,8 +265,8 @@ func (g *game) Update() error {
|
||||
|
||||
// Set FPS mode enabled only when this is needed.
|
||||
// This makes a bug around FPS mode initialization more explicit (#1364).
|
||||
if fpsMode != ebiten.FPSMode() {
|
||||
ebiten.SetFPSMode(fpsMode)
|
||||
if vsyncEnabled != ebiten.IsVsyncEnabled() {
|
||||
ebiten.SetVsyncEnabled(vsyncEnabled)
|
||||
}
|
||||
ebiten.SetTPS(tps)
|
||||
ebiten.SetWindowDecorated(decorated)
|
||||
@ -347,7 +338,7 @@ func (g *game) Draw(screen *ebiten.Image) {
|
||||
[U] Switch the runnable-on-unfocused state
|
||||
[C] Switch the cursor mode (visible, hidden, or captured)
|
||||
[I] Change the window icon (only for desktops)
|
||||
[V] Switch the FPS mode
|
||||
[V] Switch the vsync
|
||||
[T] Switch TPS (ticks per second)
|
||||
[D] Switch the window decoration (only for desktops)
|
||||
[L] Switch the window floating state (only for desktops)
|
||||
@ -421,7 +412,7 @@ func main() {
|
||||
ebiten.MaximizeWindow()
|
||||
}
|
||||
if !*flagVsync {
|
||||
ebiten.SetFPSMode(ebiten.FPSModeVsyncOffMaximum)
|
||||
ebiten.SetVsyncEnabled(false)
|
||||
}
|
||||
if *flagAutoAdjusting {
|
||||
ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
|
||||
|
20
run.go
20
run.go
@ -378,16 +378,12 @@ func DeviceScaleFactor() float64 {
|
||||
|
||||
// IsVsyncEnabled returns a boolean value indicating whether
|
||||
// the game uses the display's vsync.
|
||||
//
|
||||
// Deprecated: as of v2.2. Use FPSMode instead.
|
||||
func IsVsyncEnabled() bool {
|
||||
return ui.FPSMode() == ui.FPSModeVsyncOn
|
||||
}
|
||||
|
||||
// SetVsyncEnabled sets a boolean value indicating whether
|
||||
// the game uses the display's vsync.
|
||||
//
|
||||
// Deprecated: as of v2.2. Use SetFPSMode instead.
|
||||
func SetVsyncEnabled(enabled bool) {
|
||||
if enabled {
|
||||
ui.SetFPSMode(ui.FPSModeVsyncOn)
|
||||
@ -397,11 +393,15 @@ func SetVsyncEnabled(enabled bool) {
|
||||
}
|
||||
|
||||
// FPSModeType is a type of FPS modes.
|
||||
//
|
||||
// Deprecated: as of v2.5. Use SetVsyncEnabled instead.
|
||||
type FPSModeType = ui.FPSModeType
|
||||
|
||||
const (
|
||||
// FPSModeVsyncOn indicates that the game tries to sync the display's refresh rate.
|
||||
// FPSModeVsyncOn is the default mode.
|
||||
//
|
||||
// Deprecated: as of v2.5. Use SetVsyncEnabled(true) instead.
|
||||
FPSModeVsyncOn FPSModeType = ui.FPSModeVsyncOn
|
||||
|
||||
// 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.
|
||||
// The game's Update is called based on the specified TPS.
|
||||
//
|
||||
// Deprecated: as of v2.5. Use SetVsyncEnabled(false) instead.
|
||||
FPSModeVsyncOffMaximum FPSModeType = ui.FPSModeVsyncOffMaximum
|
||||
|
||||
// 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
|
||||
// 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.
|
||||
//
|
||||
// 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
|
||||
)
|
||||
|
||||
// FPSMode returns the current FPS mode.
|
||||
//
|
||||
// FPSMode is concurrent-safe.
|
||||
//
|
||||
// Deprecated: as of v2.5. Use SetVsyncEnabled instead.
|
||||
func FPSMode() FPSModeType {
|
||||
return ui.FPSMode()
|
||||
}
|
||||
@ -435,6 +442,8 @@ func FPSMode() FPSModeType {
|
||||
// The default FPS mode is FPSModeVsyncOn.
|
||||
//
|
||||
// SetFPSMode is concurrent-safe.
|
||||
//
|
||||
// Deprecated: as of v2.5. Use SetVsyncEnabled instead.
|
||||
func SetFPSMode(mode FPSModeType) {
|
||||
ui.SetFPSMode(mode)
|
||||
}
|
||||
@ -442,6 +451,9 @@ func SetFPSMode(mode FPSModeType) {
|
||||
// ScheduleFrame schedules a next frame when the current FPS mode is FPSModeVsyncOffMinimum.
|
||||
//
|
||||
// ScheduleFrame is concurrent-safe.
|
||||
//
|
||||
// Deprecated: as of v2.5. Use SetScreenClearedEveryFrame(false) instead.
|
||||
// See examples/skipdraw for GPU optimization with SetScreenClearedEveryFrame(false).
|
||||
func ScheduleFrame() {
|
||||
ui.Get().ScheduleFrame()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user