mirror of
https://github.com/giongto35/cloud-game.git
synced 2026-07-22 09:37:09 +00:00
guard input channel
This commit is contained in:
parent
4baff5dce6
commit
31ec2d6e4c
3 changed files with 16 additions and 9 deletions
|
|
@ -84,7 +84,7 @@ L:
|
|||
//case input := <-d.inputChannel:
|
||||
//d.UpdateInput(input)
|
||||
case <-d.Done:
|
||||
log.Println("Closed Director")
|
||||
log.Println("Closing Director")
|
||||
break L
|
||||
default:
|
||||
}
|
||||
|
|
@ -92,6 +92,7 @@ L:
|
|||
d.Step()
|
||||
}
|
||||
d.SetView(nil)
|
||||
log.Println("Closed Director")
|
||||
}
|
||||
|
||||
func (d *Director) PlayGame(path string) {
|
||||
|
|
|
|||
|
|
@ -86,7 +86,10 @@ func NewGameView(console *nes.Console, title, saveFile string, imageChannel chan
|
|||
// ListenToInputChannel listen from input channel streamm, which is exposed to WebRTC session
|
||||
func (view *GameView) ListenToInputChannel() {
|
||||
for {
|
||||
keysInBinary := <-view.inputChannel
|
||||
keysInBinary, ok := <-view.inputChannel
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
for i := 0; i < NumKeys*2; i++ {
|
||||
b := ((keysInBinary & 1) == 1)
|
||||
view.keyPressed[i] = (view.keyPressed[i] && b) || b
|
||||
|
|
|
|||
|
|
@ -125,7 +125,11 @@ func (r *Room) startWebRTCSession(peerconnection *webrtc.WebRTC, playerIndex int
|
|||
|
||||
// encode frame
|
||||
if peerconnection.IsConnected() {
|
||||
input := <-peerconnection.InputChannel
|
||||
input, ok := <-peerconnection.InputChannel
|
||||
if !ok {
|
||||
continue
|
||||
// might return here
|
||||
}
|
||||
// the first 8 bits belong to player 1
|
||||
// the next 8 belongs to player 2 ...
|
||||
// We standardize and put it to inputChannel (16 bits)
|
||||
|
|
@ -169,13 +173,12 @@ func (r *Room) removeSession(w *webrtc.WebRTC) {
|
|||
|
||||
func (r *Room) Close() {
|
||||
log.Println("Closing room", r)
|
||||
r.director.Done <- struct{}{}
|
||||
close(r.Done)
|
||||
// Not close fan input channel here, close in writer
|
||||
//close(r.inputChannel)
|
||||
// Close fan output channel
|
||||
close(r.imageChannel)
|
||||
close(r.audioChannel)
|
||||
close(r.director.Done)
|
||||
close(r.inputChannel)
|
||||
// Close here is a bit wrong because this read channel
|
||||
//close(r.imageChannel)
|
||||
//close(r.audioChannel)
|
||||
}
|
||||
|
||||
func (r *Room) SaveGame() error {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue