diff --git a/internal/app/ui.go b/internal/app/ui.go index d836dca..084ab32 100644 --- a/internal/app/ui.go +++ b/internal/app/ui.go @@ -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 diff --git a/internal/sim/world.go b/internal/sim/world.go index 35e6fcc..84e1f75 100644 --- a/internal/sim/world.go +++ b/internal/sim/world.go @@ -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}) + } } } } diff --git a/internal/wire/frame.go b/internal/wire/frame.go index c482a72..6db5ce3 100644 --- a/internal/wire/frame.go +++ b/internal/wire/frame.go @@ -155,4 +155,5 @@ func (d Delta) IsEmpty() bool { func init() { Register(func() Value { return new(Frame) }) + Register(func() Value { return new(Delta) }) }