diff --git a/ui/director.go b/ui/director.go index e3c2fc58..bf397741 100644 --- a/ui/director.go +++ b/ui/director.go @@ -44,9 +44,9 @@ func (d *Director) SetView(view *GameView) { d.timestamp = float64(time.Now().Nanosecond()) / float64(time.Second) } -func (d *Director) UpdateInput(input int) { - d.view.UpdateInput(input) -} +//func (d *Director) UpdateInput(input int) { +//d.view.UpdateInput(input) +//} func (d *Director) Step() { timestamp := float64(time.Now().Nanosecond()) / float64(time.Second) @@ -69,11 +69,11 @@ func (d *Director) Run() { L: for range c { // quit game - + // TODO: Anyway not using select because it will slow down select { // if there is event from close channel => the game is ended - case input := <-d.inputChannel: - d.UpdateInput(input) + //case input := <-d.inputChannel: + //d.UpdateInput(input) case <-d.Done: break L default: diff --git a/ui/gameview.go b/ui/gameview.go index 1f829413..3185441e 100644 --- a/ui/gameview.go +++ b/ui/gameview.go @@ -54,29 +54,30 @@ func NewGameView(console *nes.Console, title, hash string, imageChannel chan *im inputChannel: inputChannel, } + go gameview.ListenToInputChannel() return gameview } // ListenToInputChannel listen from input channel streamm, which is exposed to WebRTC session -func (view *GameView) UpdateInput(keysInBinary int) { - for i := 0; i < NumKeys*2; i++ { - b := ((keysInBinary & 1) == 1) - view.keyPressed[i] = (view.keyPressed[i] && b) || b - keysInBinary = keysInBinary >> 1 - } -} - -// ListenToInputChannel listen from input channel streamm, which is exposed to WebRTC session -//func (view *GameView) ListenToInputChannel() { -//for { -//keysInBinary := <-view.inputChannel +//func (view *GameView) UpdateInput(keysInBinary int) { //for i := 0; i < NumKeys*2; i++ { //b := ((keysInBinary & 1) == 1) //view.keyPressed[i] = (view.keyPressed[i] && b) || b //keysInBinary = keysInBinary >> 1 //} //} -//} + +// ListenToInputChannel listen from input channel streamm, which is exposed to WebRTC session +func (view *GameView) ListenToInputChannel() { + for { + keysInBinary := <-view.inputChannel + for i := 0; i < NumKeys*2; i++ { + b := ((keysInBinary & 1) == 1) + view.keyPressed[i] = (view.keyPressed[i] && b) || b + keysInBinary = keysInBinary >> 1 + } + } +} // Enter enter the game view. func (view *GameView) Enter() { diff --git a/ws.go b/ws.go index 187846d5..13e66a12 100644 --- a/ws.go +++ b/ws.go @@ -117,7 +117,7 @@ func (c *Client) heartbeat() { func (c *Client) listen() { for { - log.Println("Waiting for message ...") + //log.Println("Waiting for message ...") _, rawMsg, err := c.conn.ReadMessage() if err != nil { log.Println("[!] read:", err)