diff --git a/contrib/mmap/src/MapBuilder.cpp b/contrib/mmap/src/MapBuilder.cpp index 08c374541c6..436e8439162 100644 --- a/contrib/mmap/src/MapBuilder.cpp +++ b/contrib/mmap/src/MapBuilder.cpp @@ -120,33 +120,31 @@ bool IsModelArea(int area) } void filterLedgeSpans(const int walkableHeight, const int walkableClimbTransition, const int walkableClimbTerrain, - rcHeightfield& solid) + rcHeightfield& heightfield) { - const int w = solid.width; - const int h = solid.height; + const int w = heightfield.width; + const int h = heightfield.height; const int MAX_HEIGHT = 0xffff; - std::list nullSpans; - std::list steepSlopes; for (int y = 0; y < h; ++y) { for (int x = 0; x < w; ++x) { - for (rcSpan* s = solid.spans[x + y*w]; s; s = s->next) + for (rcSpan* span = heightfield.spans[x + y*w]; span; span = span->next) { // Skip non walkable spans. - if (s->area == RC_NULL_AREA) + if (span->area == RC_NULL_AREA) continue; - const int bot = (int)(s->smax); - const int top = s->next ? (int)(s->next->smin) : MAX_HEIGHT; + const int bot = (int)(span->smax); + const int top = span->next ? (int)(span->next->smin) : MAX_HEIGHT; // Find neighbours minimum height. - int minh = MAX_HEIGHT; + int minNeighborHeight = MAX_HEIGHT; // Min and max height of accessible neighbours. - int asmin = s->smax; - int asmax = s->smax; + int accessibleNeighborMinHeight = span->smax; + int accessibleNeighborMaxHeight = span->smax; bool hasAllNbTerrain = true; bool hasAllNbModel = true; @@ -157,35 +155,36 @@ void filterLedgeSpans(const int walkableHeight, const int walkableClimbTransitio // Skip neighbours which are out of bounds. if (dx < 0 || dy < 0 || dx >= w || dy >= h) { - //minh = rcMin(minh, -walkableClimbTerrain - bot); + //TODO: Figure out why this is commented out. + //minNeighborHeight = rcMin(minNeighborHeight , -walkableClimbTerrain - bot); continue; } // From minus infinity to the first span. - rcSpan* ns = solid.spans[dx + dy*w]; + rcSpan* neighborSpan = heightfield.spans[dx + dy*w]; int nbot = -walkableClimbTerrain; - int ntop = ns ? (int)ns->smin : MAX_HEIGHT; + int ntop = neighborSpan ? (int)neighborSpan->smin : MAX_HEIGHT; // Skip neighbour if the gap between the spans is too small. if (rcMin(top,ntop) - rcMax(bot,nbot) > walkableHeight) - minh = rcMin(minh, nbot - bot); + minNeighborHeight = rcMin(minNeighborHeight, nbot - bot); // Rest of the spans. - for (ns = solid.spans[dx + dy*w]; ns; ns = ns->next) + for (neighborSpan = heightfield.spans[dx + dy*w]; neighborSpan; neighborSpan = neighborSpan->next) { - if (ns->area == RC_NULL_AREA) + if (neighborSpan->area == RC_NULL_AREA) continue; - nbot = (int)ns->smax; - ntop = ns->next ? (int)ns->next->smin : MAX_HEIGHT; + nbot = (int)neighborSpan->smax; + ntop = neighborSpan->next ? (int)neighborSpan->next->smin : MAX_HEIGHT; // Skip neightbour if the gap between the spans is too small. if (rcMin(top,ntop) - rcMax(bot,nbot) > walkableHeight) { - minh = rcMin(minh, nbot - bot); + minNeighborHeight = rcMin(minNeighborHeight, nbot - bot); // Find min/max accessible neighbour height. if (rcAbs(nbot - bot) <= walkableClimbTerrain) { - if (nbot < asmin) asmin = nbot; - if (nbot > asmax) asmax = nbot; - if (!IsModelArea(ns->area)) + if (nbot < accessibleNeighborMinHeight) accessibleNeighborMinHeight = nbot; + if (nbot > accessibleNeighborMaxHeight) accessibleNeighborMaxHeight = nbot; + if (!IsModelArea(neighborSpan->area)) hasAllNbModel = false; else hasAllNbTerrain = false; @@ -196,31 +195,27 @@ void filterLedgeSpans(const int walkableHeight, const int walkableClimbTransitio // The current span is close to a ledge if the drop to any // neighbour span is less than the walkableClimb. - bool modelToTerrainTransition = (IsModelArea(s->area) && !hasAllNbModel) || (!IsModelArea(s->area) && !hasAllNbTerrain); + bool modelToTerrainTransition = (IsModelArea(span->area) && !hasAllNbModel) || (!IsModelArea(span->area) && !hasAllNbTerrain); int currentMaxClimb = walkableClimbTerrain; // Model -> Terrain or Terrain -> Model if (modelToTerrainTransition) currentMaxClimb = walkableClimbTransition; - if (minh < -currentMaxClimb) - nullSpans.push_front(s); + if (minNeighborHeight < -currentMaxClimb) + span->area = RC_NULL_AREA; // If the difference between all neighbours is too large, // we are at steep slope, mark the span as it - else if ((asmax - asmin) > currentMaxClimb) + else if ((accessibleNeighborMaxHeight - accessibleNeighborMinHeight) > currentMaxClimb) { if (modelToTerrainTransition) - nullSpans.push_front(s); + span->area = RC_NULL_AREA; else - steepSlopes.push_front(s); + span->area = AREA_STEEP_SLOPE; } } } } - for (std::list::iterator it = nullSpans.begin(); it != nullSpans.end(); ++it) - (*it)->area = RC_NULL_AREA; - for (std::list::iterator it = steepSlopes.begin(); it != steepSlopes.end(); ++it) - (*it)->area = AREA_STEEP_SLOPE; } void from_json(const json& j, rcConfig& config) @@ -373,8 +368,7 @@ namespace MMAP float bmin[3] = { 0, 0, 0 }; float bmax[3] = { 0, 0, 0 }; - float lmin[3] = { 0, 0, 0 }; - float lmax[3] = { 0, 0, 0 }; + MeshData meshData; // make sure we process maps which don't have tiles @@ -389,6 +383,9 @@ namespace MMAP // get the coord bounds of the model data if (meshData.solidVerts.size() && meshData.liquidVerts.size()) { + float lmin[3] = { 0, 0, 0 }; + float lmax[3] = { 0, 0, 0 }; + rcCalcBounds(meshData.solidVerts.getCArray(), meshData.solidVerts.size() / 3, bmin, bmax); rcCalcBounds(meshData.liquidVerts.getCArray(), meshData.liquidVerts.size() / 3, lmin, lmax); rcVmin(bmin, lmin); @@ -397,7 +394,7 @@ namespace MMAP else if (meshData.solidVerts.size()) rcCalcBounds(meshData.solidVerts.getCArray(), meshData.solidVerts.size() / 3, bmin, bmax); else - rcCalcBounds(meshData.liquidVerts.getCArray(), meshData.liquidVerts.size() / 3, lmin, lmax); + rcCalcBounds(meshData.liquidVerts.getCArray(), meshData.liquidVerts.size() / 3, bmin, bmax); // convert coord bounds to grid bounds maxX = 32 - bmin[0] / GRID_SIZE; @@ -711,7 +708,7 @@ namespace MMAP // - We are on a model (WMO...) // - Also we want to remove under-terrain triangles unsigned char* areas = new unsigned char[tTriCount]; - memset(areas, 0, tTriCount * sizeof(unsigned char)); + memset(areas, AREA_NONE, tTriCount * sizeof(unsigned char)); float norm[3]; const float playerClimbLimit = cosf(52.0f/180.0f*RC_PI); const float maxClimbLimitTerrain = cosf(75.0f/180.0f*RC_PI); @@ -756,7 +753,7 @@ namespace MMAP if (m_terrainBuilder->IsUnderMap(&verts[0]) && m_terrainBuilder->IsUnderMap(&verts[3]) && m_terrainBuilder->IsUnderMap(&verts[6])) { - areas[i] = 0; + areas[i] = AREA_NONE; continue; } } @@ -1275,7 +1272,7 @@ namespace MMAP return; } unsigned char* m_triareas = new unsigned char[tTriCount]; - memset(m_triareas, 0, tTriCount*sizeof(unsigned char)); + memset(m_triareas, AREA_NONE, tTriCount*sizeof(unsigned char)); rcMarkWalkableTriangles(m_rcContext, config.walkableSlopeAngle, tVerts, tVertCount, tTris, tTriCount, m_triareas); rcRasterizeTriangles(m_rcContext, tVerts, tVertCount, tTris, m_triareas, tTriCount, *tile.solid, config.walkableClimb); rcFilterLowHangingWalkableObstacles(m_rcContext, config.walkableClimb, *tile.solid);