UpdatePos Broadcast player position update (广播玩家位置移动)
(x float32, y float32, z float32, v float32)
| 175 | // UpdatePos Broadcast player position update |
| 176 | // (广播玩家位置移动) |
| 177 | func (p *Player) UpdatePos(x float32, y float32, z float32, v float32) { |
| 178 | |
| 179 | // Trigger visibility change and addition business |
| 180 | // Calculate the old grid gID |
| 181 | // 触发消失视野和添加视野业务 |
| 182 | // 计算旧格子gID |
| 183 | oldGID := WorldMgrObj.AoiMgr.GetGIDByPos(p.X, p.Z) |
| 184 | // Calculate the new grid gID |
| 185 | // 计算新格子gID |
| 186 | newGID := WorldMgrObj.AoiMgr.GetGIDByPos(x, z) |
| 187 | |
| 188 | // Update the player's position information |
| 189 | // 更新玩家的位置信息 |
| 190 | p.X = x |
| 191 | p.Y = y |
| 192 | p.Z = z |
| 193 | p.V = v |
| 194 | |
| 195 | if oldGID != newGID { |
| 196 | // Trigger grid switch |
| 197 | // Remove pID from the old aoi grid |
| 198 | // 触发gird切换 |
| 199 | // 把pID从就的aoi格子中删除 |
| 200 | WorldMgrObj.AoiMgr.RemovePIDFromGrID(int(p.PID), oldGID) |
| 201 | |
| 202 | // 把pID添加到新的aoi格子中去 |
| 203 | // Add pID to the new aoi grid |
| 204 | WorldMgrObj.AoiMgr.AddPIDToGrID(int(p.PID), newGID) |
| 205 | |
| 206 | _ = p.OnExchangeAoiGrID(oldGID, newGID) |
| 207 | } |
| 208 | |
| 209 | // Assemble protobuf data, send position to surrounding players |
| 210 | // 组装protobuf协议,发送位置给周围玩家 |
| 211 | msg := &pb.BroadCast{ |
| 212 | PID: p.PID, |
| 213 | Tp: 4, //Tp:4 Coordinates information after movement(移动之后的坐标信息) |
| 214 | Data: &pb.BroadCast_P{ |
| 215 | P: &pb.Position{ |
| 216 | X: p.X, |
| 217 | Y: p.Y, |
| 218 | Z: p.Z, |
| 219 | V: p.V, |
| 220 | }, |
| 221 | }, |
| 222 | } |
| 223 | |
| 224 | // Get all players around the current player |
| 225 | // (获取当前玩家周边全部玩家) |
| 226 | players := p.GetSurroundingPlayers() |
| 227 | |
| 228 | // Send MsgID:200 message to each player's client, updating position after movement |
| 229 | // (向周边的每个玩家发送MsgID:200消息,移动位置更新消息) |
| 230 | for _, player := range players { |
| 231 | player.SendMsg(200, msg) |
| 232 | } |
| 233 | } |
| 234 |
no test coverage detected