mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
driver: Remove the return value from RunWithoutMainLoop
This commit is contained in:
parent
aef4b4ba53
commit
d59aea1db1
@ -32,7 +32,7 @@ var RegularTermination = errors.New("regular termination")
|
||||
|
||||
type UI interface {
|
||||
Run(context UIContext) error
|
||||
RunWithoutMainLoop(context UIContext) <-chan error
|
||||
RunWithoutMainLoop(context UIContext)
|
||||
|
||||
DeviceScaleFactor() float64
|
||||
CursorMode() CursorMode
|
||||
|
@ -543,7 +543,7 @@ func (u *UserInterface) Run(uicontext driver.UIContext) error {
|
||||
return <-ch
|
||||
}
|
||||
|
||||
func (u *UserInterface) RunWithoutMainLoop(context driver.UIContext) <-chan error {
|
||||
func (u *UserInterface) RunWithoutMainLoop(context driver.UIContext) {
|
||||
panic("glfw: RunWithoutMainLoop is not implemented")
|
||||
}
|
||||
|
||||
|
@ -425,7 +425,7 @@ func (u *UserInterface) Run(context driver.UIContext) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *UserInterface) RunWithoutMainLoop(context driver.UIContext) <-chan error {
|
||||
func (u *UserInterface) RunWithoutMainLoop(context driver.UIContext) {
|
||||
panic("js: RunWithoutMainLoop is not implemented")
|
||||
}
|
||||
|
||||
|
@ -47,6 +47,7 @@ var (
|
||||
|
||||
theUI = &UserInterface{
|
||||
foreground: true,
|
||||
errCh: make(chan error),
|
||||
|
||||
// Give a default outside size so that the game can start without initializing them.
|
||||
outsideWidth: 640,
|
||||
@ -64,12 +65,18 @@ func Get() *UserInterface {
|
||||
}
|
||||
|
||||
// Update is called from mobile/ebitenmobileview.
|
||||
func (u *UserInterface) Update() {
|
||||
func (u *UserInterface) Update() error {
|
||||
select {
|
||||
case err := <-u.errCh:
|
||||
return err
|
||||
default:
|
||||
}
|
||||
|
||||
u.m.Lock()
|
||||
fg := u.foreground
|
||||
u.m.Unlock()
|
||||
if !fg {
|
||||
return
|
||||
return nil
|
||||
}
|
||||
|
||||
renderCh <- struct{}{}
|
||||
@ -100,10 +107,11 @@ func (u *UserInterface) Update() {
|
||||
break loop
|
||||
}
|
||||
}
|
||||
return
|
||||
return nil
|
||||
} else {
|
||||
u.t.Loop(ctx)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type UserInterface struct {
|
||||
@ -112,6 +120,7 @@ type UserInterface struct {
|
||||
|
||||
sizeChanged bool
|
||||
foreground bool
|
||||
errCh chan error
|
||||
|
||||
// Used for gomobile-build
|
||||
gbuildWidthPx int
|
||||
@ -221,17 +230,13 @@ func (u *UserInterface) Run(context driver.UIContext) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *UserInterface) RunWithoutMainLoop(context driver.UIContext) <-chan error {
|
||||
ch := make(chan error)
|
||||
func (u *UserInterface) RunWithoutMainLoop(context driver.UIContext) {
|
||||
go func() {
|
||||
defer close(ch)
|
||||
// title is ignored?
|
||||
if err := u.run(context, false); err != nil {
|
||||
ch <- err
|
||||
u.errCh <- err
|
||||
}
|
||||
}()
|
||||
|
||||
return ch
|
||||
}
|
||||
|
||||
func (u *UserInterface) run(context driver.UIContext, mainloop bool) (err error) {
|
||||
|
@ -36,9 +36,7 @@ import (
|
||||
var theState state
|
||||
|
||||
type state struct {
|
||||
game ebiten.Game
|
||||
|
||||
errorCh <-chan error
|
||||
started bool
|
||||
|
||||
// m is a mutex required for each function.
|
||||
// For example, on Android, Update can be called from a different thread:
|
||||
@ -47,18 +45,18 @@ type state struct {
|
||||
}
|
||||
|
||||
func (s *state) isRunning() bool {
|
||||
return s.game != nil && s.errorCh != nil
|
||||
return s.started
|
||||
}
|
||||
|
||||
func SetGame(game ebiten.Game) {
|
||||
theState.m.Lock()
|
||||
defer theState.m.Unlock()
|
||||
|
||||
if theState.game != nil {
|
||||
if theState.started {
|
||||
panic("ebitenmobileview: SetGame cannot be called twice or more")
|
||||
}
|
||||
theState.game = game
|
||||
theState.errorCh = ebiten.RunGameWithoutMainLoop(theState.game)
|
||||
ebiten.RunGameWithoutMainLoop(game)
|
||||
theState.started = true
|
||||
}
|
||||
|
||||
func Layout(viewWidth, viewHeight float64) {
|
||||
@ -75,21 +73,13 @@ func Update() error {
|
||||
|
||||
theState.m.Lock()
|
||||
defer theState.m.Unlock()
|
||||
|
||||
if !theState.isRunning() {
|
||||
if !theState.started {
|
||||
// start is not called yet, but as update can be called from another thread, it is OK. Just ignore
|
||||
// this.
|
||||
return nil
|
||||
}
|
||||
|
||||
select {
|
||||
case err := <-theState.errorCh:
|
||||
return err
|
||||
default:
|
||||
}
|
||||
|
||||
mobile.Get().Update()
|
||||
return nil
|
||||
return mobile.Get().Update()
|
||||
}
|
||||
|
||||
func Suspend() {
|
||||
|
4
run.go
4
run.go
@ -243,11 +243,11 @@ func runGame(game Game, scale float64) error {
|
||||
//
|
||||
// Ebiten users should NOT call RunGameWithoutMainLoop.
|
||||
// Instead, functions in github.com/hajimehoshi/ebiten/mobile package calls this.
|
||||
func RunGameWithoutMainLoop(game Game) <-chan error {
|
||||
func RunGameWithoutMainLoop(game Game) {
|
||||
game = &imageDumperGame{game: game}
|
||||
fixWindowPosition(WindowSize())
|
||||
theUIContext.set(game, 0)
|
||||
return uiDriver().RunWithoutMainLoop(theUIContext)
|
||||
uiDriver().RunWithoutMainLoop(theUIContext)
|
||||
}
|
||||
|
||||
// ScreenSizeInFullscreen is deprecated as of 1.11.0-alpha.
|
||||
|
Loading…
Reference in New Issue
Block a user