mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 03:38:55 +01:00
internal/ui: refactoring: remove fpsMode from globalState
This commit is contained in:
parent
beabe9c6ee
commit
a89aaa0756
@ -31,7 +31,6 @@ type globalState struct {
|
||||
err_ error
|
||||
errM sync.Mutex
|
||||
|
||||
fpsMode_ int32
|
||||
isScreenClearedEveryFrame_ int32
|
||||
graphicsLibrary_ int32
|
||||
}
|
||||
@ -50,14 +49,6 @@ func (g *globalState) setError(err error) {
|
||||
}
|
||||
}
|
||||
|
||||
func (g *globalState) fpsMode() FPSModeType {
|
||||
return FPSModeType(atomic.LoadInt32(&g.fpsMode_))
|
||||
}
|
||||
|
||||
func (g *globalState) setFPSMode(fpsMode FPSModeType) {
|
||||
atomic.StoreInt32(&g.fpsMode_, int32(fpsMode))
|
||||
}
|
||||
|
||||
func (g *globalState) isScreenClearedEveryFrame() bool {
|
||||
return atomic.LoadInt32(&g.isScreenClearedEveryFrame_) != 0
|
||||
}
|
||||
@ -78,15 +69,6 @@ func (g *globalState) graphicsLibrary() GraphicsLibrary {
|
||||
return GraphicsLibrary(atomic.LoadInt32(&g.graphicsLibrary_))
|
||||
}
|
||||
|
||||
func FPSMode() FPSModeType {
|
||||
return theGlobalState.fpsMode()
|
||||
}
|
||||
|
||||
func (u *UserInterface) SetFPSMode(fpsMode FPSModeType) {
|
||||
theGlobalState.setFPSMode(fpsMode)
|
||||
u.setFPSMode(fpsMode)
|
||||
}
|
||||
|
||||
func IsScreenClearedEveryFrame() bool {
|
||||
return theGlobalState.isScreenClearedEveryFrame()
|
||||
}
|
||||
|
@ -138,7 +138,6 @@ func (u *UserInterface) init() error {
|
||||
initWindowPositionYInDIP: invalidPos,
|
||||
initWindowWidthInDIP: 640,
|
||||
initWindowHeightInDIP: 480,
|
||||
fpsMode: FPSModeVsyncOn,
|
||||
origWindowPosX: invalidPos,
|
||||
origWindowPosY: invalidPos,
|
||||
savedCursorX: math.NaN(),
|
||||
@ -727,14 +726,20 @@ func (u *UserInterface) IsRunnableOnUnfocused() bool {
|
||||
return u.isRunnableOnUnfocused()
|
||||
}
|
||||
|
||||
func (u *UserInterface) setFPSMode(mode FPSModeType) {
|
||||
func (u *UserInterface) FPSMode() FPSModeType {
|
||||
u.m.Lock()
|
||||
defer u.m.Unlock()
|
||||
return u.fpsMode
|
||||
}
|
||||
|
||||
func (u *UserInterface) SetFPSMode(mode FPSModeType) {
|
||||
if u.isTerminated() {
|
||||
return
|
||||
}
|
||||
if !u.isRunning() {
|
||||
u.m.Lock()
|
||||
defer u.m.Unlock()
|
||||
u.fpsMode = mode
|
||||
u.m.Unlock()
|
||||
return
|
||||
}
|
||||
|
||||
@ -746,7 +751,7 @@ func (u *UserInterface) setFPSMode(mode FPSModeType) {
|
||||
u.fpsMode = mode
|
||||
return
|
||||
}
|
||||
if err := u.setFPSModeImpl(mode); err != nil {
|
||||
if err := u.setFPSMode(mode); err != nil {
|
||||
theGlobalState.setError(err)
|
||||
return
|
||||
}
|
||||
@ -1290,8 +1295,8 @@ func (u *UserInterface) outsideSize() (float64, float64, error) {
|
||||
return w, h, nil
|
||||
}
|
||||
|
||||
// setFPSModeImpl must be called from the main thread.
|
||||
func (u *UserInterface) setFPSModeImpl(fpsMode FPSModeType) error {
|
||||
// setFPSMode must be called from the main thread.
|
||||
func (u *UserInterface) setFPSMode(fpsMode FPSModeType) error {
|
||||
needUpdate := u.fpsMode != fpsMode || !u.fpsModeInited
|
||||
u.fpsMode = fpsMode
|
||||
u.fpsModeInited = true
|
||||
@ -1361,7 +1366,7 @@ func (u *UserInterface) update() (float64, float64, error) {
|
||||
// Initialize vsync after SetMonitor is called. See the comment in updateVsync.
|
||||
// Calling this inside setWindowSize didn't work (#1363).
|
||||
if !u.fpsModeInited {
|
||||
if err := u.setFPSModeImpl(u.fpsMode); err != nil {
|
||||
if err := u.setFPSMode(u.fpsMode); err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
}
|
||||
|
@ -186,7 +186,11 @@ func (u *UserInterface) IsRunnableOnUnfocused() bool {
|
||||
return u.runnableOnUnfocused
|
||||
}
|
||||
|
||||
func (u *UserInterface) setFPSMode(mode FPSModeType) {
|
||||
func (u *UserInterface) FPSMode() FPSModeType {
|
||||
return u.fpsMode
|
||||
}
|
||||
|
||||
func (u *UserInterface) SetFPSMode(mode FPSModeType) {
|
||||
u.fpsMode = mode
|
||||
}
|
||||
|
||||
|
@ -119,7 +119,7 @@ type userInterfaceImpl struct {
|
||||
inputState InputState
|
||||
touches []TouchForInput
|
||||
|
||||
fpsMode FPSModeType
|
||||
fpsMode int32
|
||||
renderRequester RenderRequester
|
||||
|
||||
renderThread *thread.OSThread
|
||||
@ -399,16 +399,20 @@ func (u *UserInterface) SetRunnableOnUnfocused(runnableOnUnfocused bool) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
func (u *UserInterface) setFPSMode(mode FPSModeType) {
|
||||
u.fpsMode = mode
|
||||
u.updateExplicitRenderingModeIfNeeded()
|
||||
func (u *UserInterface) FPSMode() FPSModeType {
|
||||
return FPSModeType(atomic.LoadInt32(&u.fpsMode))
|
||||
}
|
||||
|
||||
func (u *UserInterface) updateExplicitRenderingModeIfNeeded() {
|
||||
func (u *UserInterface) SetFPSMode(mode FPSModeType) {
|
||||
atomic.StoreInt32(&u.fpsMode, int32(mode))
|
||||
u.updateExplicitRenderingModeIfNeeded(mode)
|
||||
}
|
||||
|
||||
func (u *UserInterface) updateExplicitRenderingModeIfNeeded(fpsMode FPSModeType) {
|
||||
if u.renderRequester == nil {
|
||||
return
|
||||
}
|
||||
u.renderRequester.SetExplicitRenderingMode(u.fpsMode == FPSModeVsyncOffMinimum)
|
||||
u.renderRequester.SetExplicitRenderingMode(fpsMode == FPSModeVsyncOffMinimum)
|
||||
}
|
||||
|
||||
func (u *UserInterface) DeviceScaleFactor() float64 {
|
||||
@ -452,7 +456,7 @@ func (u *UserInterface) Monitor() *Monitor {
|
||||
|
||||
func (u *UserInterface) UpdateInput(keys map[Key]struct{}, runes []rune, touches []TouchForInput) {
|
||||
u.updateInputStateFromOutside(keys, runes, touches)
|
||||
if u.fpsMode == FPSModeVsyncOffMinimum {
|
||||
if FPSModeType(atomic.LoadInt32(&u.fpsMode)) == FPSModeVsyncOffMinimum {
|
||||
u.renderRequester.RequestRenderIfNeeded()
|
||||
}
|
||||
}
|
||||
@ -464,11 +468,11 @@ type RenderRequester interface {
|
||||
|
||||
func (u *UserInterface) SetRenderRequester(renderRequester RenderRequester) {
|
||||
u.renderRequester = renderRequester
|
||||
u.updateExplicitRenderingModeIfNeeded()
|
||||
u.updateExplicitRenderingModeIfNeeded(FPSModeType(atomic.LoadInt32(&u.fpsMode)))
|
||||
}
|
||||
|
||||
func (u *UserInterface) ScheduleFrame() {
|
||||
if u.renderRequester != nil && u.fpsMode == FPSModeVsyncOffMinimum {
|
||||
if u.renderRequester != nil && FPSModeType(atomic.LoadInt32(&u.fpsMode)) == FPSModeVsyncOffMinimum {
|
||||
u.renderRequester.RequestRenderIfNeeded()
|
||||
}
|
||||
}
|
||||
|
@ -182,7 +182,11 @@ func (*UserInterface) IsRunnableOnUnfocused() bool {
|
||||
func (*UserInterface) SetRunnableOnUnfocused(runnableOnUnfocused bool) {
|
||||
}
|
||||
|
||||
func (*UserInterface) setFPSMode(mode FPSModeType) {
|
||||
func (*UserInterface) FPSMode() FPSModeType {
|
||||
return FPSModeVsyncOn
|
||||
}
|
||||
|
||||
func (*UserInterface) SetFPSMode(mode FPSModeType) {
|
||||
}
|
||||
|
||||
func (*UserInterface) ScheduleFrame() {
|
||||
|
4
run.go
4
run.go
@ -470,7 +470,7 @@ func DeviceScaleFactor() float64 {
|
||||
// IsVsyncEnabled returns a boolean value indicating whether
|
||||
// the game uses the display's vsync.
|
||||
func IsVsyncEnabled() bool {
|
||||
return ui.FPSMode() == ui.FPSModeVsyncOn
|
||||
return ui.Get().FPSMode() == ui.FPSModeVsyncOn
|
||||
}
|
||||
|
||||
// SetVsyncEnabled sets a boolean value indicating whether
|
||||
@ -526,7 +526,7 @@ const (
|
||||
//
|
||||
// Deprecated: as of v2.5. Use SetVsyncEnabled instead.
|
||||
func FPSMode() FPSModeType {
|
||||
return ui.FPSMode()
|
||||
return ui.Get().FPSMode()
|
||||
}
|
||||
|
||||
// SetFPSMode sets the FPS mode.
|
||||
|
Loading…
Reference in New Issue
Block a user