mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-27 03:02:49 +01:00
Close the observing channel
This commit is contained in:
parent
e2a8b07a94
commit
3e5d58ef85
@ -11,12 +11,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Rects struct {
|
type Rects struct {
|
||||||
rectTextureId graphics.RenderTargetId
|
rectTextureId graphics.RenderTargetId
|
||||||
rectTextureInited bool
|
rectTextureInited bool
|
||||||
offscreenId graphics.RenderTargetId
|
offscreenId graphics.RenderTargetId
|
||||||
offscreenInited bool
|
offscreenInited bool
|
||||||
rectBounds *graphics.Rect
|
rectBounds *graphics.Rect
|
||||||
rectColor *color.RGBA
|
rectColor *color.RGBA
|
||||||
screenSizeUpdatedCh chan ebiten.ScreenSizeUpdatedEvent
|
screenSizeUpdatedCh chan ebiten.ScreenSizeUpdatedEvent
|
||||||
screenWidth int
|
screenWidth int
|
||||||
screenHeight int
|
screenHeight int
|
||||||
@ -31,10 +31,10 @@ const (
|
|||||||
|
|
||||||
func New() *Rects {
|
func New() *Rects {
|
||||||
return &Rects{
|
return &Rects{
|
||||||
rectTextureInited: false,
|
rectTextureInited: false,
|
||||||
offscreenInited: false,
|
offscreenInited: false,
|
||||||
rectBounds: &graphics.Rect{},
|
rectBounds: &graphics.Rect{},
|
||||||
rectColor: &color.RGBA{},
|
rectColor: &color.RGBA{},
|
||||||
screenSizeUpdatedCh: make(chan ebiten.ScreenSizeUpdatedEvent),
|
screenSizeUpdatedCh: make(chan ebiten.ScreenSizeUpdatedEvent),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,9 +16,9 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Rotating struct {
|
type Rotating struct {
|
||||||
ebitenTextureId graphics.TextureId
|
ebitenTextureId graphics.TextureId
|
||||||
x int
|
x int
|
||||||
geometryMatrix matrix.Geometry
|
geometryMatrix matrix.Geometry
|
||||||
screenSizeUpdatedCh chan ebiten.ScreenSizeUpdatedEvent
|
screenSizeUpdatedCh chan ebiten.ScreenSizeUpdatedEvent
|
||||||
screenWidth int
|
screenWidth int
|
||||||
screenHeight int
|
screenHeight int
|
||||||
|
@ -64,8 +64,8 @@ func (sprite *Sprite) Update() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Sprites struct {
|
type Sprites struct {
|
||||||
ebitenTextureId graphics.TextureId
|
ebitenTextureId graphics.TextureId
|
||||||
sprites []*Sprite
|
sprites []*Sprite
|
||||||
screenSizeUpdatedCh chan ebiten.ScreenSizeUpdatedEvent
|
screenSizeUpdatedCh chan ebiten.ScreenSizeUpdatedEvent
|
||||||
screenWidth int
|
screenWidth int
|
||||||
screenHeight int
|
screenHeight int
|
||||||
|
@ -81,20 +81,26 @@ func main() {
|
|||||||
events:
|
events:
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case e := <-screenSizeUpdated:
|
case e, ok := <-inputStateUpdated:
|
||||||
type Handler interface {
|
if ok {
|
||||||
OnScreenSizeUpdated(e ebiten.ScreenSizeUpdatedEvent)
|
type Handler interface {
|
||||||
|
OnInputStateUpdated(ebiten.InputStateUpdatedEvent)
|
||||||
|
}
|
||||||
|
if game2, ok := game.(Handler); ok {
|
||||||
|
game2.OnInputStateUpdated(e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if game2, ok := game.(Handler); ok {
|
inputStateUpdated = ui.ObserveInputStateUpdated()
|
||||||
game2.OnScreenSizeUpdated(e)
|
case e, ok := <-screenSizeUpdated:
|
||||||
}
|
if ok {
|
||||||
case e := <-inputStateUpdated:
|
type Handler interface {
|
||||||
type Handler interface {
|
OnScreenSizeUpdated(e ebiten.ScreenSizeUpdatedEvent)
|
||||||
OnInputStateUpdated(ebiten.InputStateUpdatedEvent)
|
}
|
||||||
}
|
if game2, ok := game.(Handler); ok {
|
||||||
if game2, ok := game.(Handler); ok {
|
game2.OnScreenSizeUpdated(e)
|
||||||
game2.OnInputStateUpdated(e)
|
}
|
||||||
}
|
}
|
||||||
|
screenSizeUpdated = ui.ObserveScreenSizeUpdated()
|
||||||
default:
|
default:
|
||||||
break events
|
break events
|
||||||
}
|
}
|
||||||
|
@ -47,9 +47,9 @@ func New(screenWidth, screenHeight, screenScale int, title string) *UI {
|
|||||||
panic("UI can't be duplicated.")
|
panic("UI can't be duplicated.")
|
||||||
}
|
}
|
||||||
ui := &UI{
|
ui := &UI{
|
||||||
screenWidth: screenWidth,
|
screenWidth: screenWidth,
|
||||||
screenHeight: screenHeight,
|
screenHeight: screenHeight,
|
||||||
screenScale: screenScale,
|
screenScale: screenScale,
|
||||||
initialEventSent: false,
|
initialEventSent: false,
|
||||||
inputStateUpdatedChs: make(chan chan ebiten.InputStateUpdatedEvent),
|
inputStateUpdatedChs: make(chan chan ebiten.InputStateUpdatedEvent),
|
||||||
inputStateUpdatedNotified: make(chan ebiten.InputStateUpdatedEvent),
|
inputStateUpdatedNotified: make(chan ebiten.InputStateUpdatedEvent),
|
||||||
@ -90,13 +90,17 @@ func (ui *UI) chLoop() {
|
|||||||
case e := <-ui.inputStateUpdatedNotified:
|
case e := <-ui.inputStateUpdatedNotified:
|
||||||
for _, ch := range inputStateUpdated {
|
for _, ch := range inputStateUpdated {
|
||||||
ch <- e
|
ch <- e
|
||||||
|
close(ch)
|
||||||
}
|
}
|
||||||
|
inputStateUpdated = []chan ebiten.InputStateUpdatedEvent{}
|
||||||
case ch := <-ui.screenSizeUpdatedChs:
|
case ch := <-ui.screenSizeUpdatedChs:
|
||||||
screenSizeUpdated = append(screenSizeUpdated, ch)
|
screenSizeUpdated = append(screenSizeUpdated, ch)
|
||||||
case e := <-ui.screenSizeUpdatedNotified:
|
case e := <-ui.screenSizeUpdatedNotified:
|
||||||
for _, ch := range screenSizeUpdated {
|
for _, ch := range screenSizeUpdated {
|
||||||
ch <- e
|
ch <- e
|
||||||
|
close(ch)
|
||||||
}
|
}
|
||||||
|
screenSizeUpdated = []chan ebiten.ScreenSizeUpdatedEvent{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user