mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
internal/ui: refactoring: remove an error value from runOnAnotherThreadFromMainThread
This commit is contained in:
parent
ce3f83958e
commit
e09c1bf8f1
@ -60,7 +60,7 @@ func (u *UserInterface) Run(game Game) error {
|
||||
// u.t is updated to the new thread until runOnAnotherThreadFromMainThread is called.
|
||||
//
|
||||
// Inside f, another functions that must be called from the main thread can be called safely.
|
||||
func (u *UserInterface) runOnAnotherThreadFromMainThread(f func() error) error {
|
||||
func (u *UserInterface) runOnAnotherThreadFromMainThread(f func()) {
|
||||
// As this function is called from the main thread, u.t should never be accessed and can be updated here.
|
||||
t := u.t
|
||||
defer func() {
|
||||
@ -71,11 +71,9 @@ func (u *UserInterface) runOnAnotherThreadFromMainThread(f func() error) error {
|
||||
u.t = thread.NewOSThread()
|
||||
graphicscommand.SetRenderingThread(u.t)
|
||||
|
||||
var err error
|
||||
go func() {
|
||||
defer u.t.Stop()
|
||||
err = f()
|
||||
f()
|
||||
}()
|
||||
u.t.Loop()
|
||||
return err
|
||||
}
|
||||
|
@ -43,6 +43,6 @@ func (u *UserInterface) Run(game Game) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *UserInterface) runOnAnotherThreadFromMainThread(f func() error) error {
|
||||
return f()
|
||||
func (u *UserInterface) runOnAnotherThreadFromMainThread(f func()) {
|
||||
f()
|
||||
}
|
||||
|
@ -109,6 +109,7 @@ type UserInterface struct {
|
||||
defaultFramebufferSizeCallback glfw.FramebufferSizeCallback
|
||||
framebufferSizeCallbackCh chan struct{}
|
||||
|
||||
// t is the main thread == the rendering thread.
|
||||
t thread.Thread
|
||||
m sync.RWMutex
|
||||
}
|
||||
@ -701,33 +702,29 @@ func (u *UserInterface) registerWindowSetSizeCallback() {
|
||||
return
|
||||
}
|
||||
|
||||
if err := u.runOnAnotherThreadFromMainThread(func() error {
|
||||
var outsideWidth, outsideHeight float64
|
||||
var deviceScaleFactor float64
|
||||
if width != 0 || height != 0 {
|
||||
w := int(u.dipFromGLFWPixel(float64(width), u.currentMonitor()))
|
||||
h := int(u.dipFromGLFWPixel(float64(height), u.currentMonitor()))
|
||||
u.setWindowSizeInDIP(w, h, u.isFullscreen())
|
||||
}
|
||||
|
||||
u.t.Call(func() {
|
||||
if width != 0 || height != 0 {
|
||||
w := int(u.dipFromGLFWPixel(float64(width), u.currentMonitor()))
|
||||
h := int(u.dipFromGLFWPixel(float64(height), u.currentMonitor()))
|
||||
u.setWindowSizeInDIP(w, h, u.isFullscreen())
|
||||
}
|
||||
outsideWidth, outsideHeight := u.updateSize()
|
||||
deviceScaleFactor := u.deviceScaleFactor(u.currentMonitor())
|
||||
|
||||
outsideWidth, outsideHeight = u.updateSize()
|
||||
deviceScaleFactor = u.deviceScaleFactor(u.currentMonitor())
|
||||
})
|
||||
// In the game's update, u.t.Call might be called.
|
||||
// In order to call it safely, use runOnAnotherThreadFromMainThread.
|
||||
var err error
|
||||
u.runOnAnotherThreadFromMainThread(func() {
|
||||
u.context.layout(outsideWidth, outsideHeight)
|
||||
if err := u.context.forceUpdateFrame(deviceScaleFactor); err != nil {
|
||||
return err
|
||||
}
|
||||
if graphics().IsGL() {
|
||||
u.t.Call(func() {
|
||||
u.swapBuffers()
|
||||
})
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
err = u.context.forceUpdateFrame(deviceScaleFactor)
|
||||
})
|
||||
if err != nil {
|
||||
u.err = err
|
||||
}
|
||||
|
||||
if graphics().IsGL() {
|
||||
u.swapBuffers()
|
||||
}
|
||||
})
|
||||
}
|
||||
u.window.SetSizeCallback(u.sizeCallback)
|
||||
|
Loading…
Reference in New Issue
Block a user