mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 03:38:55 +01:00
interna/uidriver: refactoring: remove initFPSMode
This commit is contained in:
parent
a6e5be608d
commit
5ee2ff56ca
@ -87,7 +87,6 @@ type UserInterface struct {
|
|||||||
initFullscreenHeightInDIP int
|
initFullscreenHeightInDIP int
|
||||||
|
|
||||||
initTitle string
|
initTitle string
|
||||||
initFPSMode driver.FPSMode
|
|
||||||
initFullscreen bool
|
initFullscreen bool
|
||||||
initCursorMode driver.CursorMode
|
initCursorMode driver.CursorMode
|
||||||
initWindowDecorated bool
|
initWindowDecorated bool
|
||||||
@ -130,7 +129,6 @@ var (
|
|||||||
maxWindowHeightInDIP: glfw.DontCare,
|
maxWindowHeightInDIP: glfw.DontCare,
|
||||||
origPosX: invalidPos,
|
origPosX: invalidPos,
|
||||||
origPosY: invalidPos,
|
origPosY: invalidPos,
|
||||||
initFPSMode: driver.FPSModeVsyncOn,
|
|
||||||
initCursorMode: driver.CursorModeVisible,
|
initCursorMode: driver.CursorModeVisible,
|
||||||
initWindowDecorated: true,
|
initWindowDecorated: true,
|
||||||
initWindowPositionXInDIP: invalidPos,
|
initWindowPositionXInDIP: invalidPos,
|
||||||
@ -299,13 +297,6 @@ func (u *UserInterface) setInitTitle(title string) {
|
|||||||
u.m.RUnlock()
|
u.m.RUnlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserInterface) getInitFPSMode() driver.FPSMode {
|
|
||||||
u.m.RLock()
|
|
||||||
v := u.initFPSMode
|
|
||||||
u.m.RUnlock()
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
|
|
||||||
func (u *UserInterface) isInitFullscreen() bool {
|
func (u *UserInterface) isInitFullscreen() bool {
|
||||||
u.m.RLock()
|
u.m.RLock()
|
||||||
v := u.initFullscreen
|
v := u.initFullscreen
|
||||||
@ -582,20 +573,14 @@ func (u *UserInterface) IsRunnableOnUnfocused() bool {
|
|||||||
|
|
||||||
func (u *UserInterface) SetFPSMode(mode driver.FPSMode) {
|
func (u *UserInterface) SetFPSMode(mode driver.FPSMode) {
|
||||||
if !u.isRunning() {
|
if !u.isRunning() {
|
||||||
// In general, m is used for locking init* values.
|
|
||||||
// m is not used for updating vsync in setWindowSize so far, but
|
|
||||||
// it should be OK since any goroutines can't reach here when
|
|
||||||
// the game already starts and setWindowSize can be called.
|
|
||||||
u.m.Lock()
|
u.m.Lock()
|
||||||
u.initFPSMode = mode
|
u.fpsMode = mode
|
||||||
u.m.Unlock()
|
u.m.Unlock()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_ = u.t.Call(func() error {
|
_ = u.t.Call(func() error {
|
||||||
if !u.fpsModeInited {
|
if !u.fpsModeInited {
|
||||||
u.m.Lock()
|
u.fpsMode = mode
|
||||||
u.initFPSMode = mode
|
|
||||||
u.m.Unlock()
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
u.setFPSMode(mode)
|
u.setFPSMode(mode)
|
||||||
@ -606,14 +591,13 @@ func (u *UserInterface) SetFPSMode(mode driver.FPSMode) {
|
|||||||
|
|
||||||
func (u *UserInterface) FPSMode() driver.FPSMode {
|
func (u *UserInterface) FPSMode() driver.FPSMode {
|
||||||
if !u.isRunning() {
|
if !u.isRunning() {
|
||||||
return u.getInitFPSMode()
|
u.m.Lock()
|
||||||
|
m := u.fpsMode
|
||||||
|
u.m.Unlock()
|
||||||
|
return m
|
||||||
}
|
}
|
||||||
var v driver.FPSMode
|
var v driver.FPSMode
|
||||||
_ = u.t.Call(func() error {
|
_ = u.t.Call(func() error {
|
||||||
if !u.fpsModeInited {
|
|
||||||
v = u.getInitFPSMode()
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
v = u.fpsMode
|
v = u.fpsMode
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
@ -983,9 +967,14 @@ func (u *UserInterface) updateSize() (float64, float64) {
|
|||||||
|
|
||||||
// setFPSMode must be called from the main thread.
|
// setFPSMode must be called from the main thread.
|
||||||
func (u *UserInterface) setFPSMode(fpsMode driver.FPSMode) {
|
func (u *UserInterface) setFPSMode(fpsMode driver.FPSMode) {
|
||||||
|
needUpdate := u.fpsMode != fpsMode || !u.fpsModeInited
|
||||||
u.fpsMode = fpsMode
|
u.fpsMode = fpsMode
|
||||||
u.fpsModeInited = true
|
u.fpsModeInited = true
|
||||||
|
|
||||||
|
if !needUpdate {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
sticky := glfw.True
|
sticky := glfw.True
|
||||||
if fpsMode == driver.FPSModeVsyncOffMinimum {
|
if fpsMode == driver.FPSModeVsyncOffMinimum {
|
||||||
sticky = glfw.False
|
sticky = glfw.False
|
||||||
@ -1015,7 +1004,7 @@ func (u *UserInterface) update() (float64, float64, error) {
|
|||||||
// Initialize vsync after SetMonitor is called. See the comment in updateVsync.
|
// Initialize vsync after SetMonitor is called. See the comment in updateVsync.
|
||||||
// Calling this inside setWindowSize didn't work (#1363).
|
// Calling this inside setWindowSize didn't work (#1363).
|
||||||
if !u.fpsModeInited {
|
if !u.fpsModeInited {
|
||||||
u.setFPSMode(u.getInitFPSMode())
|
u.setFPSMode(u.fpsMode)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call updateVsync even though fpsMode is not updated.
|
// Call updateVsync even though fpsMode is not updated.
|
||||||
|
Loading…
Reference in New Issue
Block a user