mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
uidriver/mobile: Refactoring
This commit is contained in:
parent
ffb9871839
commit
ca907e2846
@ -73,7 +73,10 @@ type contextImpl struct {
|
||||
worker mgl.Worker
|
||||
}
|
||||
|
||||
func (c *context) doWork(chDone <-chan struct{}) error {
|
||||
// doWork consumes the queued GL tasks.
|
||||
//
|
||||
// doWork is called only on gomobile-bind.
|
||||
func (c *context) doWork(done <-chan struct{}) error {
|
||||
if c.worker == nil {
|
||||
panic("opengl: worker must be initialized but not")
|
||||
}
|
||||
@ -84,7 +87,7 @@ loop:
|
||||
select {
|
||||
case <-workAvailable:
|
||||
c.worker.DoWork()
|
||||
case <-chDone:
|
||||
case <-done:
|
||||
break loop
|
||||
}
|
||||
}
|
||||
|
@ -20,8 +20,8 @@ import (
|
||||
"golang.org/x/mobile/gl"
|
||||
)
|
||||
|
||||
func (d *Driver) DoWork(chDone <-chan struct{}) error {
|
||||
return d.context.doWork(chDone)
|
||||
func (d *Driver) DoWork(done <-chan struct{}) error {
|
||||
return d.context.doWork(done)
|
||||
}
|
||||
|
||||
func (d *Driver) Init() {
|
||||
|
@ -37,8 +37,13 @@ import (
|
||||
|
||||
var (
|
||||
glContextCh = make(chan gl.Context)
|
||||
|
||||
// renderCh recieves when updating starts.
|
||||
renderCh = make(chan struct{})
|
||||
renderChEnd = make(chan struct{})
|
||||
|
||||
// renderEndCh receives when updating finishes.
|
||||
renderEndCh = make(chan struct{})
|
||||
|
||||
theUI = &UserInterface{}
|
||||
)
|
||||
|
||||
@ -62,7 +67,7 @@ func (u *UserInterface) Render(chError <-chan error) error {
|
||||
case err := <-chError:
|
||||
return err
|
||||
case renderCh <- struct{}{}:
|
||||
return opengl.Get().DoWork(renderChEnd)
|
||||
return opengl.Get().DoWork(renderEndCh)
|
||||
case <-time.After(500 * time.Millisecond):
|
||||
// This function must not be blocked. We need to break for timeout.
|
||||
return nil
|
||||
@ -127,7 +132,7 @@ func (u *UserInterface) appMain(a app.App) {
|
||||
continue
|
||||
}
|
||||
renderCh <- struct{}{}
|
||||
<-renderChEnd
|
||||
<-renderEndCh
|
||||
a.Publish()
|
||||
a.Send(paint.Event{})
|
||||
case touch.Event:
|
||||
@ -253,7 +258,7 @@ render:
|
||||
context.ResumeAudio()
|
||||
|
||||
defer func() {
|
||||
renderChEnd <- struct{}{}
|
||||
renderEndCh <- struct{}{}
|
||||
}()
|
||||
|
||||
if err := context.Update(func() {
|
||||
|
Loading…
Reference in New Issue
Block a user