mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 19:28:57 +01:00
internal/ui: use atomic.Int32 instead of atomic.Store/LoadInt32
Updates #2422
This commit is contained in:
parent
59fb259181
commit
bb799da51f
@ -76,7 +76,7 @@ type UserInterface struct {
|
||||
errM sync.Mutex
|
||||
|
||||
isScreenClearedEveryFrame atomic.Bool
|
||||
graphicsLibrary int32
|
||||
graphicsLibrary atomic.Int32
|
||||
running atomic.Bool
|
||||
terminated atomic.Bool
|
||||
|
||||
@ -106,10 +106,9 @@ func Get() *UserInterface {
|
||||
|
||||
// newUserInterface must be called from the main thread.
|
||||
func newUserInterface() (*UserInterface, error) {
|
||||
u := &UserInterface{
|
||||
graphicsLibrary: int32(GraphicsLibraryUnknown),
|
||||
}
|
||||
u := &UserInterface{}
|
||||
u.isScreenClearedEveryFrame.Store(true)
|
||||
u.graphicsLibrary.Store(int32(GraphicsLibraryUnknown))
|
||||
|
||||
u.whiteImage = u.NewImage(3, 3, atlas.ImageTypeRegular)
|
||||
pix := make([]byte, 4*u.whiteImage.width*u.whiteImage.height)
|
||||
@ -204,11 +203,11 @@ func (u *UserInterface) SetScreenClearedEveryFrame(cleared bool) {
|
||||
}
|
||||
|
||||
func (u *UserInterface) setGraphicsLibrary(library GraphicsLibrary) {
|
||||
atomic.StoreInt32(&u.graphicsLibrary, int32(library))
|
||||
u.graphicsLibrary.Store(int32(library))
|
||||
}
|
||||
|
||||
func (u *UserInterface) GraphicsLibrary() GraphicsLibrary {
|
||||
return GraphicsLibrary(atomic.LoadInt32(&u.graphicsLibrary))
|
||||
return GraphicsLibrary(u.graphicsLibrary.Load())
|
||||
}
|
||||
|
||||
func (u *UserInterface) isRunning() bool {
|
||||
|
@ -97,7 +97,7 @@ type userInterfaceImpl struct {
|
||||
inputState InputState
|
||||
touches []TouchForInput
|
||||
|
||||
fpsMode int32
|
||||
fpsMode atomic.Int32
|
||||
renderRequester RenderRequester
|
||||
|
||||
m sync.RWMutex
|
||||
@ -228,11 +228,11 @@ func (u *UserInterface) SetRunnableOnUnfocused(runnableOnUnfocused bool) {
|
||||
}
|
||||
|
||||
func (u *UserInterface) FPSMode() FPSModeType {
|
||||
return FPSModeType(atomic.LoadInt32(&u.fpsMode))
|
||||
return FPSModeType(u.fpsMode.Load())
|
||||
}
|
||||
|
||||
func (u *UserInterface) SetFPSMode(mode FPSModeType) {
|
||||
atomic.StoreInt32(&u.fpsMode, int32(mode))
|
||||
u.fpsMode.Store(int32(mode))
|
||||
u.updateExplicitRenderingModeIfNeeded(mode)
|
||||
}
|
||||
|
||||
@ -294,7 +294,7 @@ func (u *UserInterface) Monitor() *Monitor {
|
||||
|
||||
func (u *UserInterface) UpdateInput(keys map[Key]struct{}, runes []rune, touches []TouchForInput) {
|
||||
u.updateInputStateFromOutside(keys, runes, touches)
|
||||
if FPSModeType(atomic.LoadInt32(&u.fpsMode)) == FPSModeVsyncOffMinimum {
|
||||
if FPSModeType(u.fpsMode.Load()) == FPSModeVsyncOffMinimum {
|
||||
u.renderRequester.RequestRenderIfNeeded()
|
||||
}
|
||||
}
|
||||
@ -306,11 +306,11 @@ type RenderRequester interface {
|
||||
|
||||
func (u *UserInterface) SetRenderRequester(renderRequester RenderRequester) {
|
||||
u.renderRequester = renderRequester
|
||||
u.updateExplicitRenderingModeIfNeeded(FPSModeType(atomic.LoadInt32(&u.fpsMode)))
|
||||
u.updateExplicitRenderingModeIfNeeded(FPSModeType(u.fpsMode.Load()))
|
||||
}
|
||||
|
||||
func (u *UserInterface) ScheduleFrame() {
|
||||
if u.renderRequester != nil && FPSModeType(atomic.LoadInt32(&u.fpsMode)) == FPSModeVsyncOffMinimum {
|
||||
if u.renderRequester != nil && FPSModeType(u.fpsMode.Load()) == FPSModeVsyncOffMinimum {
|
||||
u.renderRequester.RequestRenderIfNeeded()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user