mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-13 04:22:05 +01:00
Split the event loop
This commit is contained in:
parent
3e5d58ef85
commit
5eb08941e0
@ -75,14 +75,14 @@ func New(screenWidth, screenHeight, screenScale int, title string) *UI {
|
|||||||
context)
|
context)
|
||||||
currentUI = ui
|
currentUI = ui
|
||||||
|
|
||||||
go ui.chLoop()
|
ui.eventLoop()
|
||||||
|
|
||||||
return ui
|
return ui
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ui *UI) chLoop() {
|
func (ui *UI) eventLoop() {
|
||||||
|
go func() {
|
||||||
inputStateUpdated := []chan ebiten.InputStateUpdatedEvent{}
|
inputStateUpdated := []chan ebiten.InputStateUpdatedEvent{}
|
||||||
screenSizeUpdated := []chan ebiten.ScreenSizeUpdatedEvent{}
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case ch := <-ui.inputStateUpdatedChs:
|
case ch := <-ui.inputStateUpdatedChs:
|
||||||
@ -92,7 +92,15 @@ func (ui *UI) chLoop() {
|
|||||||
ch <- e
|
ch <- e
|
||||||
close(ch)
|
close(ch)
|
||||||
}
|
}
|
||||||
inputStateUpdated = []chan ebiten.InputStateUpdatedEvent{}
|
inputStateUpdated = inputStateUpdated[0:0]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
screenSizeUpdated := []chan ebiten.ScreenSizeUpdatedEvent{}
|
||||||
|
for {
|
||||||
|
select {
|
||||||
case ch := <-ui.screenSizeUpdatedChs:
|
case ch := <-ui.screenSizeUpdatedChs:
|
||||||
screenSizeUpdated = append(screenSizeUpdated, ch)
|
screenSizeUpdated = append(screenSizeUpdated, ch)
|
||||||
case e := <-ui.screenSizeUpdatedNotified:
|
case e := <-ui.screenSizeUpdatedNotified:
|
||||||
@ -103,6 +111,7 @@ func (ui *UI) chLoop() {
|
|||||||
screenSizeUpdated = []chan ebiten.ScreenSizeUpdatedEvent{}
|
screenSizeUpdated = []chan ebiten.ScreenSizeUpdatedEvent{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ui *UI) PollEvents() {
|
func (ui *UI) PollEvents() {
|
||||||
|
Loading…
Reference in New Issue
Block a user