mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 03:38:55 +01:00
buffered: Use RunGame for tests
This commit is contained in:
parent
16280e9a5a
commit
ab94cebd02
@ -34,6 +34,31 @@ func runOnMainThread(f func()) {
|
|||||||
<-ch
|
<-ch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var regularTermination = errors.New("regular termination")
|
||||||
|
|
||||||
|
type game struct {
|
||||||
|
m *testing.M
|
||||||
|
endCh chan struct{}
|
||||||
|
code int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *game) Update(*ebiten.Image) error {
|
||||||
|
select {
|
||||||
|
case f := <-mainCh:
|
||||||
|
f()
|
||||||
|
case <-g.endCh:
|
||||||
|
return regularTermination
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*game) Draw(*ebiten.Image) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*game) Layout(int, int) (int, int) {
|
||||||
|
return 320, 240
|
||||||
|
}
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
codeCh := make(chan int)
|
codeCh := make(chan int)
|
||||||
endCh := make(chan struct{})
|
endCh := make(chan struct{})
|
||||||
@ -44,16 +69,11 @@ func TestMain(m *testing.M) {
|
|||||||
close(codeCh)
|
close(codeCh)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
rt := errors.New("regular termination")
|
g := &game{
|
||||||
if err := ebiten.Run(func(*ebiten.Image) error {
|
m: m,
|
||||||
select {
|
endCh: endCh,
|
||||||
case f := <-mainCh:
|
|
||||||
f()
|
|
||||||
case <-endCh:
|
|
||||||
return rt
|
|
||||||
}
|
}
|
||||||
return nil
|
if err := ebiten.RunGame(g); err != nil && err != regularTermination {
|
||||||
}, 320, 240, 1, ""); err != nil && err != rt {
|
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user