Skip to content

Commit

Permalink
only send a board if something changed
Browse files Browse the repository at this point in the history
  • Loading branch information
terrbear committed Sep 12, 2021
1 parent 345f03b commit 3ad1ef0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 4 additions & 2 deletions internal/rpc/board.go
Expand Up @@ -28,8 +28,10 @@ func (b *Board) Diff(other *Board) *Board {
return b
}

diff := Board{
Winner: b.Winner,
diff := Board{}

if other.Winner != nil {
diff.Winner = other.Winner
}

for i, t := range b.Tiles {
Expand Down
8 changes: 5 additions & 3 deletions server/main.go
Expand Up @@ -189,9 +189,11 @@ func play(w http.ResponseWriter, r *http.Request) {
changes := board.Diff(oldBoard)
oldBoard = board

err = c.WriteMessage(websocket.BinaryMessage, game.serializedBoard(changes))
if err != nil {
log.Println("write:", err)
if len(changes.Tiles) > 0 || changes.Winner != nil {
err = c.WriteMessage(websocket.BinaryMessage, game.serializedBoard(changes))
if err != nil {
log.Println("write:", err)
}
}
}
}
Expand Down

0 comments on commit 3ad1ef0

Please sign in to comment.