diff --git a/RecastDemo/Include/Sample_TileMesh.h b/RecastDemo/Include/Sample_TileMesh.h index b432335c..c8d530d6 100644 --- a/RecastDemo/Include/Sample_TileMesh.h +++ b/RecastDemo/Include/Sample_TileMesh.h @@ -25,7 +25,7 @@ class Sample_TileMesh : public Sample { -protected: +private: bool m_buildAll = true; float m_totalBuildTimeMs = 0.0f; @@ -63,6 +63,7 @@ protected: int m_maxTiles = 0; int m_maxPolysPerTile = 0; + /// In cells float m_tileSize = 32.0f; unsigned int m_tileColor = duRGBA(0, 0, 0, 32); @@ -85,6 +86,7 @@ public: Sample_TileMesh(const Sample_TileMesh&&) = delete; Sample_TileMesh& operator=(const Sample_TileMesh&&) = delete; + // Sample methods void handleSettings() override; void handleTools() override; void handleDebugMode() override; @@ -94,7 +96,7 @@ public: bool handleBuild() override; void collectSettings(BuildSettings& settings) override; - void getTilePos(const float* pos, int& tileX, int& tileY) const; + void getTilePos(const float* pos, int& outTileX, int& outTileY) const; void buildTile(const float* pos); void removeTile(const float* pos); diff --git a/RecastDemo/Source/Sample_TileMesh.cpp b/RecastDemo/Source/Sample_TileMesh.cpp index a8455ee6..785edc81 100644 --- a/RecastDemo/Source/Sample_TileMesh.cpp +++ b/RecastDemo/Source/Sample_TileMesh.cpp @@ -18,7 +18,6 @@ #include "Sample_TileMesh.h" -#include "SDL.h" #include "SDL_opengl.h" #include @@ -161,7 +160,8 @@ public: GLdouble x, y, z; if (m_hitPosSet && gluProject(m_hitPos[0], m_hitPos[1], m_hitPos[2], model, proj, view, &x, &y, &z)) { - int tx = 0, ty = 0; + int tx = 0; + int ty = 0; m_sample->getTilePos(m_hitPos, tx, ty); char text[32]; snprintf(text, 32, "(%d,%d)", tx, ty); @@ -169,10 +169,9 @@ public: } // Tool help - const int h = view[3]; imguiDrawText( 280, - h - 40, + view[3] - 40, IMGUI_ALIGN_LEFT, "LMB: Rebuild hit tile. Shift+LMB: Clear hit tile.", imguiRGBA(255, 255, 255, 192)); @@ -691,7 +690,7 @@ void Sample_TileMesh::buildTile(const float* pos) m_buildContext->dumpLog("Build Tile (%d,%d):", tileX, tileY); } -void Sample_TileMesh::getTilePos(const float* pos, int& tileX, int& tileY) const +void Sample_TileMesh::getTilePos(const float* pos, int& outTileX, int& outTileY) const { if (!m_inputGeometry) { @@ -700,9 +699,9 @@ void Sample_TileMesh::getTilePos(const float* pos, int& tileX, int& tileY) const const float* navMeshBoundsMin = m_inputGeometry->getNavMeshBoundsMin(); - const float ts = m_tileSize * m_cellSize; - tileX = static_cast((pos[0] - navMeshBoundsMin[0]) / ts); - tileY = static_cast((pos[2] - navMeshBoundsMin[2]) / ts); + const float tileSize = m_tileSize * m_cellSize; + outTileX = static_cast((pos[0] - navMeshBoundsMin[0]) / tileSize); + outTileY = static_cast((pos[2] - navMeshBoundsMin[2]) / tileSize); } void Sample_TileMesh::removeTile(const float* pos) @@ -798,7 +797,11 @@ void Sample_TileMesh::buildAllTiles() void Sample_TileMesh::removeAllTiles() const { - if (!m_inputGeometry || !m_navMesh) + if (m_inputGeometry == nullptr) + { + return; + } + if (m_navMesh == nullptr) { return; } @@ -812,11 +815,11 @@ void Sample_TileMesh::removeAllTiles() const const int tileWidth = (gridWidth + tileSize - 1) / tileSize; const int tileHeight = (gridHeight + tileSize - 1) / tileSize; - for (int y = 0; y < tileHeight; ++y) + for (int tileY = 0; tileY < tileHeight; ++tileY) { - for (int x = 0; x < tileWidth; ++x) + for (int tileX = 0; tileX < tileWidth; ++tileX) { - m_navMesh->removeTile(m_navMesh->getTileRefAt(x, y, 0), 0, 0); + m_navMesh->removeTile(m_navMesh->getTileRefAt(tileX, tileY, 0), 0, 0); } } } @@ -937,14 +940,15 @@ unsigned char* Sample_TileMesh::buildTileMesh( return 0; } - float tbmin[2]; - float tbmax[2]; - tbmin[0] = m_config.bmin[0]; - tbmin[1] = m_config.bmin[2]; - tbmax[0] = m_config.bmax[0]; - tbmax[1] = m_config.bmax[2]; + float tileBoundsMin[2]; + float tileBoundsMax[2]; + tileBoundsMin[0] = m_config.bmin[0]; + tileBoundsMin[1] = m_config.bmin[2]; + tileBoundsMax[0] = m_config.bmax[0]; + tileBoundsMax[1] = m_config.bmax[2]; int overlappingChunkIndexes[512]; // TODO: Make grow when returning too many items. - const int numOverlappingChunks = chunkyMesh->GetChunksOverlappingRect(tbmin, tbmax, overlappingChunkIndexes, 512); + const int numOverlappingChunks = + chunkyMesh->GetChunksOverlappingRect(tileBoundsMin, tileBoundsMax, overlappingChunkIndexes, 512); if (!numOverlappingChunks) { return 0;