(Jin Qing's Column, Nov., 2022)
dtLink
dtLink defines a link between 2 polygons. It is an internal data structure.
A dtLink is owned by its source polygon.
The links are used in findPath(), to search all the neighbor polygons, from the current best polygon.
findPath()
dtLink has 2 required fields:
If the link is a boundary link, which links to other tile, then it has more fields:
Links are not saved to navmesh file. They are created on navmesh loading in addTile().
addTile()
dtNavMesh::addTile() add a tile to the navmesh. A tile is a square block of the map.
dtNavMesh::addTile()
The main job of dtNavMesh::addTile() is to create links inside this tile and between this tile and other tiles. Actually a block indexed by (x, y) of constant size has many layers for multi-floor map. A dtMeshTile is actually a layer with an index of (x, y, layer).
dtMeshTile
5 steps to create all links:
connectIntLinks() iterates all the polygons in the tile and create links for them by the help of neighbors information of the polygons.
connectIntLinks()
baseOffMeshLinks() bases off-mesh connections to their starting polygons and connect connections inside the tile.
baseOffMeshLinks()
Off-mesh connection is between 2 points which are inside a tile or between 2 adjacent tiles.
For each off-mesh connection, there creates a specific polygon consisting of 2 vertices. See DT_POLYTYPE_OFFMESH_CONNECTION.
DT_POLYTYPE_OFFMESH_CONNECTION
baseOffMeshLinks() creates 2 links for each off-mesh connection:
The destinaton polygon of the off-mesh connection is skipped here.
connectExtOffMeshLinks() with the source and target tile be this tile.
connectExtOffMeshLinks()
connectExtOffMeshLinks() searches off-mesh connections that are from this tile to the target tile by checking the side direction of the connection.
It creates a link from off-mesh connection polygon to the target tile. For bidirectional connection, it also creates a link from the target polygon to the off-mesh connection polygon.
So for each off-mesh connection of this tile, 3 or 4 links are created by baseOffMeshLinks() and connectExtOffMeshLinks(), one on the source polygon, one on the destination polygon and 1/2 on the off-mesh connection polygon.
For each layer other than this layer in this tile:
Check 9 neighbor tiles' layers, and create links just like previous step:
By now, for every off-mesh connection of all the loaded tiles, 3/4 links are created.
Powered by: C++博客 Copyright © 金慶