mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-02-13 11:33:14 +01:00
uidriver/glfw: Eliminate (*thread).Call at (*UserInterface).update
Updates #1367
This commit is contained in:
parent
ee50f611ee
commit
cbb70d045c
@ -791,11 +791,11 @@ func (u *UserInterface) updateSize() (float64, float64, bool) {
|
|||||||
return w, h, true
|
return w, h, true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserInterface) update() error {
|
// update must be called from the main thread.
|
||||||
if err := u.t.Call(func() error {
|
func (u *UserInterface) update() (float64, float64, bool, error) {
|
||||||
shouldClose := u.window.ShouldClose()
|
shouldClose := u.window.ShouldClose()
|
||||||
if shouldClose {
|
if shouldClose {
|
||||||
return driver.RegularTermination
|
return 0, 0, false, driver.RegularTermination
|
||||||
}
|
}
|
||||||
|
|
||||||
if u.isInitFullscreen() {
|
if u.isInitFullscreen() {
|
||||||
@ -819,25 +819,8 @@ func (u *UserInterface) update() error {
|
|||||||
u.reqWidth = 0
|
u.reqWidth = 0
|
||||||
u.reqHeight = 0
|
u.reqHeight = 0
|
||||||
|
|
||||||
return nil
|
outsideWidth, outsideHeight, outsideSizeChanged := u.updateSize()
|
||||||
}); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
var w, h float64
|
|
||||||
var changed bool
|
|
||||||
|
|
||||||
// This call is needed for initialization.
|
|
||||||
_ = u.t.Call(func() error {
|
|
||||||
w, h, changed = u.updateSize()
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
|
|
||||||
if changed {
|
|
||||||
u.context.Layout(w, h)
|
|
||||||
}
|
|
||||||
|
|
||||||
_ = u.t.Call(func() error {
|
|
||||||
glfw.PollEvents()
|
glfw.PollEvents()
|
||||||
u.input.update(u.window, u.context)
|
u.input.update(u.window, u.context)
|
||||||
|
|
||||||
@ -848,10 +831,8 @@ func (u *UserInterface) update() error {
|
|||||||
time.Sleep(time.Second / 60)
|
time.Sleep(time.Second / 60)
|
||||||
glfw.PollEvents()
|
glfw.PollEvents()
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
})
|
|
||||||
|
|
||||||
return nil
|
return outsideWidth, outsideHeight, outsideSizeChanged, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserInterface) loop() error {
|
func (u *UserInterface) loop() error {
|
||||||
@ -876,9 +857,20 @@ func (u *UserInterface) loop() error {
|
|||||||
if unfocused {
|
if unfocused {
|
||||||
t1 = time.Now()
|
t1 = time.Now()
|
||||||
}
|
}
|
||||||
if err := u.update(); err != nil {
|
|
||||||
|
var outsideWidth, outsideHeight float64
|
||||||
|
var outsideSizeChanged bool
|
||||||
|
if err := u.t.Call(func() error {
|
||||||
|
var err error
|
||||||
|
outsideWidth, outsideHeight, outsideSizeChanged, err = u.update()
|
||||||
|
return err
|
||||||
|
}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if outsideSizeChanged {
|
||||||
|
u.context.Layout(outsideWidth, outsideHeight)
|
||||||
|
}
|
||||||
|
|
||||||
if err := u.context.Update(); err != nil {
|
if err := u.context.Update(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user