feat(mpsync): 实体位置广播(EntityMove)与客户端在线玩家显示;mesh 顶点池复用(性能与内存.md §2)
This commit is contained in:
@@ -317,3 +317,28 @@ func DecodeHandshake(b []byte) (Handshake, error) {
|
||||
m := Handshake{ProtocolVersion: int(r.Varint()), ClientID: r.Str()}
|
||||
return m, r.Err
|
||||
}
|
||||
|
||||
// EntityMove 实体移动(0x07,20Hz 广播,多人同步.md §3)。
|
||||
type EntityMove struct {
|
||||
EntityID uint32
|
||||
X, Y, Z float32
|
||||
Yaw float32
|
||||
}
|
||||
|
||||
// Encode 编码实体移动。
|
||||
func (m EntityMove) Encode() []byte {
|
||||
w := &Writer{}
|
||||
w.U32(m.EntityID)
|
||||
w.F32(m.X)
|
||||
w.F32(m.Y)
|
||||
w.F32(m.Z)
|
||||
w.F32(m.Yaw)
|
||||
return w.B
|
||||
}
|
||||
|
||||
// DecodeEntityMove 解码实体移动。
|
||||
func DecodeEntityMove(b []byte) (EntityMove, error) {
|
||||
r := NewReader(b)
|
||||
m := EntityMove{EntityID: r.U32(), X: r.F32(), Y: r.F32(), Z: r.F32(), Yaw: r.F32()}
|
||||
return m, r.Err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user