feat(mpsync): 实体位置广播(EntityMove)与客户端在线玩家显示;mesh 顶点池复用(性能与内存.md §2)

This commit is contained in:
NianGao Dev
2026-08-16 00:05:17 +08:00
parent e70314fb3f
commit 95c8d677ea
10 changed files with 146 additions and 21 deletions

View File

@@ -24,6 +24,8 @@ type Handler interface {
OnChunk(data []byte)
// OnBlockChange 方块变更。
OnBlockChange(m netproto.BlockChange)
// OnEntityMove 其他实体移动(多人同步.md §3)。
OnEntityMove(m netproto.EntityMove)
}
// Client TCP 客户端。
@@ -100,6 +102,10 @@ func (c *Client) dispatch(f netproto.Frame) {
if m, err := netproto.DecodeBlockChange(f.Payload); err == nil {
c.handler.OnBlockChange(m)
}
case netproto.MsgEntityMove:
if m, err := netproto.DecodeEntityMove(f.Payload); err == nil {
c.handler.OnEntityMove(m)
}
case netproto.MsgDisconnect:
c.Close()
}

View File

@@ -44,6 +44,7 @@ func newTestHandler() *testHandler {
func (h *testHandler) OnLogin(code uint8) { h.login <- code }
func (h *testHandler) OnChunk(data []byte) {}
func (h *testHandler) OnBlockChange(m netproto.BlockChange) { h.blocks <- m }
func (h *testHandler) OnEntityMove(m netproto.EntityMove) {}
// TestClientRoundtrip 客户端登录 → 发移动 → 收方块变更全链路(多人同步.md §2)。
func TestClientRoundtrip(t *testing.T) {