send/receive frame deltas

master
Jordan Orelli 4 years ago
parent f512df73dd
commit 15f6b0acfb

@ -156,6 +156,22 @@ func (ui *UI) handleNotification(v wire.Value) bool {
ui.room.Entities = n.Entities
return true
case *wire.Delta:
if n.RoomSize != nil {
ui.room.Rect = *n.RoomSize
}
if len(n.Entities) > 0 {
for id, e := range n.Entities {
if e != nil {
ui.room.Entities[id] = *e
} else {
delete(ui.room.Entities, id)
}
}
}
return true
case *sim.ChatMessage:
ui.chatView.history = append(ui.chatView.history, *n)
return true

@ -291,7 +291,13 @@ func (w *world) tick(d time.Duration) {
r.lastFrame = frame
for _, p := range r.players {
p.send(wire.Response{Body: frame})
switch {
case p.fullSync:
p.send(wire.Response{Body: frame})
p.fullSync = false
case delta != nil:
p.send(wire.Response{Body: delta})
}
}
}
}

@ -155,4 +155,5 @@ func (d Delta) IsEmpty() bool {
func init() {
Register(func() Value { return new(Frame) })
Register(func() Value { return new(Delta) })
}

Loading…
Cancel
Save