Refactoring Input

This commit is contained in:
Hajime Hoshi 2013-06-27 02:10:56 +09:00
parent ef6d643438
commit b0de4acaf4

View File

@ -153,8 +153,7 @@ func main() {
ch := currentUI.glutInputEventCh ch := currentUI.glutInputEventCh
var inputState ebiten.InputState var inputState ebiten.InputState
for { for {
select { event := <-ch
case event := <-ch:
switch event.State { switch event.State {
case GlutInputEventStateUp: case GlutInputEventStateUp:
inputState.IsTapped = false inputState.IsTapped = false
@ -165,9 +164,6 @@ func main() {
inputState.X = event.X inputState.X = event.X
inputState.Y = event.Y inputState.Y = event.Y
} }
default:
// do nothing
}
input <- inputState input <- inputState
} }
}() }()
@ -182,11 +178,13 @@ func main() {
go func() { go func() {
frameTime := time.Duration(int64(time.Second) / int64(game.Fps())) frameTime := time.Duration(int64(time.Second) / int64(game.Fps()))
update := time.Tick(frameTime) update := time.Tick(frameTime)
inputState := ebiten.InputState{}
for { for {
select { select {
case inputState = <-input:
case <-update: case <-update:
inputState := <-input
game.Update(inputState) game.Update(inputState)
inputState = ebiten.InputState{}
case gameDraw := <-draw: case gameDraw := <-draw:
ch := make(chan interface{}) ch := make(chan interface{})
s := &SyncDrawable{game, ch} s := &SyncDrawable{game, ch}