mirror of
https://github.com/giongto35/cloud-game.git
synced 2026-07-22 09:37:09 +00:00
Remove channel polling for input
This commit is contained in:
parent
5b20cfb694
commit
4b98bc84e1
3 changed files with 21 additions and 20 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
2
ws.go
2
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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue