• 3.5 AOI格子添加删除操作

    3.5 AOI格子添加删除操作

    mmo_game/core/aoi.go

    1. //通过GID获取当前格子的全部playerID
    2. func (m *AOIManager) GetPidsByGid(gID int) (playerIDs []int) {
    3. playerIDs = m.grids[gID].GetPlyerIDs()
    4. return
    5. }
    6. //移除一个格子中的PlayerID
    7. func (m *AOIManager) RemovePidFromGrid(pID, gID int) {
    8. m.grids[gID].Remove(pID)
    9. }
    10. //添加一个PlayerID到一个格子中
    11. func (m *AOIManager) AddPidToGrid(pID, gID int) {
    12. m.grids[gID].Add(pID)
    13. }
    14. //通过横纵坐标添加一个Player到一个格子中
    15. func (m *AOIManager) AddToGridByPos(pID int, x, y float32) {
    16. gID := m.GetGidByPos(x, y)
    17. grid := m.grids[gID]
    18. grid.Add(pID)
    19. }
    20. //通过横纵坐标把一个Player从对应的格子中删除
    21. func (m *AOIManager) RemoveFromGridByPos(pID int, x, y float32) {
    22. gID := m.GetGidByPos(x, y)
    23. grid := m.grids[gID]
    24. grid.Remove(pID)
    25. }