mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-26 02:42:02 +01:00
Close the observing channel
This commit is contained in:
parent
e2a8b07a94
commit
3e5d58ef85
@ -81,20 +81,26 @@ func main() {
|
||||
events:
|
||||
for {
|
||||
select {
|
||||
case e := <-screenSizeUpdated:
|
||||
type Handler interface {
|
||||
OnScreenSizeUpdated(e ebiten.ScreenSizeUpdatedEvent)
|
||||
}
|
||||
if game2, ok := game.(Handler); ok {
|
||||
game2.OnScreenSizeUpdated(e)
|
||||
}
|
||||
case e := <-inputStateUpdated:
|
||||
case e, ok := <-inputStateUpdated:
|
||||
if ok {
|
||||
type Handler interface {
|
||||
OnInputStateUpdated(ebiten.InputStateUpdatedEvent)
|
||||
}
|
||||
if game2, ok := game.(Handler); ok {
|
||||
game2.OnInputStateUpdated(e)
|
||||
}
|
||||
}
|
||||
inputStateUpdated = ui.ObserveInputStateUpdated()
|
||||
case e, ok := <-screenSizeUpdated:
|
||||
if ok {
|
||||
type Handler interface {
|
||||
OnScreenSizeUpdated(e ebiten.ScreenSizeUpdatedEvent)
|
||||
}
|
||||
if game2, ok := game.(Handler); ok {
|
||||
game2.OnScreenSizeUpdated(e)
|
||||
}
|
||||
}
|
||||
screenSizeUpdated = ui.ObserveScreenSizeUpdated()
|
||||
default:
|
||||
break events
|
||||
}
|
||||
|
@ -90,13 +90,17 @@ func (ui *UI) chLoop() {
|
||||
case e := <-ui.inputStateUpdatedNotified:
|
||||
for _, ch := range inputStateUpdated {
|
||||
ch <- e
|
||||
close(ch)
|
||||
}
|
||||
inputStateUpdated = []chan ebiten.InputStateUpdatedEvent{}
|
||||
case ch := <-ui.screenSizeUpdatedChs:
|
||||
screenSizeUpdated = append(screenSizeUpdated, ch)
|
||||
case e := <-ui.screenSizeUpdatedNotified:
|
||||
for _, ch := range screenSizeUpdated {
|
||||
ch <- e
|
||||
close(ch)
|
||||
}
|
||||
screenSizeUpdated = []chan ebiten.ScreenSizeUpdatedEvent{}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user