Recast: properly calculate tile and poly bits during build

Tile bits should be 16, and polyBits 28 - tileBits. This is also the reason why the 'm_saltBits < 10' check no longer exists in the executable.
This commit is contained in:
Kawe Mazidjatari 2024-07-02 14:18:11 +02:00
parent 97204c20dc
commit 4ced95e2c1
3 changed files with 6 additions and 14 deletions

View File

@ -236,7 +236,7 @@ void Editor_TileMesh::handleSettings()
m_buildAll = !m_buildAll; m_buildAll = !m_buildAll;
imguiLabel("Tiling"); imguiLabel("Tiling");
imguiSlider("TileSize", &m_tileSize, 16.0f, 1024.0f, 16.0f); imguiSlider("TileSize", &m_tileSize, 8.0f, 1024.0f, 8.0f);
if (m_geom) if (m_geom)
{ {
@ -252,11 +252,11 @@ void Editor_TileMesh::handleSettings()
imguiValue(text); imguiValue(text);
snprintf(text, 64, "Tile Sizes %g x %g", tw*m_cellSize, th*m_cellSize); snprintf(text, 64, "Tile Sizes %g x %g", tw*m_cellSize, th*m_cellSize);
imguiValue(text); imguiValue(text);
// Max tiles and max polys affect how the tile IDs are caculated. // Max tiles and max polys affect how the tile IDs are calculated.
// There are 22 bits available for identifying a tile and a polygon. // There are 28 bits available for identifying a tile and a polygon.
int tileBits = rcMin((int)ilog2(nextPow2(tw*th)), 28); int tileBits = rcMin((int)ilog2(nextPow2(tw*th)), 16);
if (tileBits > 28) tileBits = 28; if (tileBits > 16) tileBits = 16;
int polyBits = 22 - tileBits; int polyBits = 28 - tileBits;
m_maxTiles = 1 << tileBits; m_maxTiles = 1 << tileBits;
m_maxPolysPerTile = 1 << polyBits; m_maxPolysPerTile = 1 << polyBits;
snprintf(text, 64, "Max Tiles %d", m_maxTiles); snprintf(text, 64, "Max Tiles %d", m_maxTiles);

View File

@ -257,10 +257,6 @@ dtStatus dtNavMesh::init(const dtNavMeshParams* params)
m_polyBits = dtIlog2(dtNextPow2((unsigned int)params->maxPolys)); m_polyBits = dtIlog2(dtNextPow2((unsigned int)params->maxPolys));
// Only allow 31 salt bits, since the salt mask is calculated using 32bit uint and it will overflow. // Only allow 31 salt bits, since the salt mask is calculated using 32bit uint and it will overflow.
m_saltBits = dtMin((unsigned int)31, 32 - m_tileBits - m_polyBits); m_saltBits = dtMin((unsigned int)31, 32 - m_tileBits - m_polyBits);
// NOTE[ AMOS ]: this check doesn't exist in R5!
if (m_saltBits < 10)
return DT_FAILURE | DT_INVALID_PARAM;
#endif #endif
return DT_SUCCESS; return DT_SUCCESS;

View File

@ -165,10 +165,6 @@ dtStatus dtTileCache::init(const dtTileCacheParams* params,
// Only allow 31 salt bits, since the salt mask is calculated using 32bit uint and it will overflow. // Only allow 31 salt bits, since the salt mask is calculated using 32bit uint and it will overflow.
m_saltBits = dtMin((unsigned int)31, 32 - m_tileBits); m_saltBits = dtMin((unsigned int)31, 32 - m_tileBits);
// NOTE[ AMOS ]: this check doesn't exist in dtNavMesh::init for R5, so it probably also doesn't exist here!
if (m_saltBits < 10)
return DT_FAILURE | DT_INVALID_PARAM;
return DT_SUCCESS; return DT_SUCCESS;
} }