<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ### 3.2 實現AOI格子結構 將aoi模塊放在一個`core`模塊中 > mmo\_game/core/grid.go ```go package core import "sync" /* 一個地圖中的格子類 */ type Grid struct { GID int //格子ID MinX int //格子左邊界坐標 MaxX int //格子右邊界坐標 MinY int //格子上邊界坐標 MaxY int //格子下邊界坐標 playerIDs map[int]bool //當前格子內的玩家或者物體成員ID pIDLock sync.RWMutex //playerIDs的保護map的鎖 } //初始化一個格子 func NewGrid(gID, minX, maxX, minY, maxY int) *Grid { return &Grid{ GID:gID, MinX:minX, MaxX:maxX, MinY:minY, MaxY:maxY, playerIDs:make(map[int] bool), } } //向當前格子中添加一個玩家 func (g *Grid) Add(playerID int) { g.pIDLock.Lock() defer g.pIDLock.Unlock() g.playerIDs[playerID] = true } //從格子中刪除一個玩家 func (g *Grid) Remove(playerID int) { g.pIDLock.Lock() defer g.pIDLock.Unlock() delete(g.playerIDs, playerID) } //得到當前格子中所有的玩家 func (g *Grid) GetPlyerIDs() (playerIDs []int) { g.pIDLock.RLock() defer g.pIDLock.RUnlock() for k, _ := range g.playerIDs { playerIDs = append(playerIDs, k) } return } //打印信息方法 func (g *Grid) String() string { return fmt.Sprintf("Grid id: %d, minX:%d, maxX:%d, minY:%d, maxY:%d, playerIDs:%v", g.GID, g.MinX, g.MaxX, g.MinY, g.MaxY, g.playerIDs) ``` `Grid`這個格子類型,很好理解,分別有上下左右四個坐標,確定格子的領域范圍,還是有格子ID,其中`playerIDs`是一個map,表示當前格子中存在的玩家有哪些。這里提供了一個方法`GetPlyerIDs()`可以返回當前格子中所有玩家的ID切片。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看