mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
internal/ui: refactoring
This commit is contained in:
parent
e9248c6f33
commit
01eb1a0bca
@ -26,31 +26,29 @@ func (u *userInterfaceImpl) Run(game Game, options *RunOptions) error {
|
||||
|
||||
// Initialize the main thread first so the thread is available at u.run (#809).
|
||||
u.mainThread = thread.NewOSThread()
|
||||
|
||||
graphicscommand.SetRenderingThread(u.mainThread)
|
||||
|
||||
u.setRunning(true)
|
||||
defer u.setRunning(false)
|
||||
|
||||
if err := u.init(options); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ch := make(chan error, 1)
|
||||
go func() {
|
||||
defer u.mainThread.Stop()
|
||||
|
||||
defer close(ch)
|
||||
|
||||
var err error
|
||||
if u.mainThread.Call(func() {
|
||||
err = u.init(options)
|
||||
}); err != nil {
|
||||
ch <- err
|
||||
return
|
||||
}
|
||||
|
||||
if err := u.loop(); err != nil {
|
||||
if err := u.loopGame(); err != nil {
|
||||
ch <- err
|
||||
return
|
||||
}
|
||||
}()
|
||||
|
||||
u.setRunning(true)
|
||||
defer u.mainThread.Stop()
|
||||
u.mainThread.Loop()
|
||||
u.setRunning(false)
|
||||
|
||||
return <-ch
|
||||
}
|
||||
|
||||
|
@ -29,16 +29,16 @@ func (u *userInterfaceImpl) Run(game Game, options *RunOptions) error {
|
||||
graphicscommand.SetRenderingThread(u.mainThread)
|
||||
|
||||
u.setRunning(true)
|
||||
defer u.setRunning(false)
|
||||
|
||||
if err := u.init(options); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := u.loop(); err != nil {
|
||||
if err := u.loopGame(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
u.setRunning(false)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -849,6 +849,7 @@ event:
|
||||
u.framebufferSizeCallbackCh = nil
|
||||
}
|
||||
|
||||
// init must be called from the main thread.
|
||||
func (u *userInterfaceImpl) init(options *RunOptions) error {
|
||||
glfw.WindowHint(glfw.AutoIconify, glfw.False)
|
||||
|
||||
@ -1065,7 +1066,7 @@ func (u *userInterfaceImpl) update() (float64, float64, error) {
|
||||
return outsideWidth, outsideHeight, nil
|
||||
}
|
||||
|
||||
func (u *userInterfaceImpl) loop() error {
|
||||
func (u *userInterfaceImpl) loopGame() error {
|
||||
defer u.mainThread.Call(func() {
|
||||
u.window.Destroy()
|
||||
glfw.Terminate()
|
||||
|
Loading…
Reference in New Issue
Block a user