feat(mpsync): 实体位置广播(EntityMove)与客户端在线玩家显示;mesh 顶点池复用(性能与内存.md §2)
This commit is contained in:
@@ -72,6 +72,24 @@ func (h *Hub) SetBlockWorld(x, y, z int32, s block.State) {
|
||||
h.BroadcastBlockChange(x, y, z, s.ID(), s.Meta())
|
||||
}
|
||||
|
||||
// BroadcastEntityMove 广播玩家移动给其他客户端(多人同步.md §3:20Hz 增量)。
|
||||
// from 为发送者(不回传给自己)。
|
||||
func (h *Hub) BroadcastEntityMove(from *netserver.Conn, entityID uint32, m netproto.PlayerMove) {
|
||||
msg := netproto.EntityMove{EntityID: entityID, X: m.X, Y: m.Y, Z: m.Z, Yaw: m.Yaw}
|
||||
payload := msg.Encode()
|
||||
h.mu.Lock()
|
||||
clients := make([]*netserver.Conn, 0, len(h.clients))
|
||||
for c := range h.clients {
|
||||
if c != from {
|
||||
clients = append(clients, c)
|
||||
}
|
||||
}
|
||||
h.mu.Unlock()
|
||||
for _, c := range clients {
|
||||
c.Send(netproto.Frame{MsgID: netproto.MsgEntityMove, Payload: payload})
|
||||
}
|
||||
}
|
||||
|
||||
// absi32 绝对值。
|
||||
func absi32(v int32) int32 {
|
||||
if v < 0 {
|
||||
|
||||
Reference in New Issue
Block a user