MCPcopy Create free account
hub / github.com/axmolengine/axmol / dtBuildTileCacheContours

Function dtBuildTileCacheContours

3rdparty/recast/DetourTileCacheBuilder.cpp:748–838  ·  view source on GitHub ↗

TODO: move this somewhere else, once the layer meshing is done.

Source from the content-addressed store, hash-verified

746
747// TODO: move this somewhere else, once the layer meshing is done.
748dtStatus dtBuildTileCacheContours(dtTileCacheAlloc* alloc,
749 dtTileCacheLayer& layer,
750 const int walkableClimb, const float maxError,
751 dtTileCacheContourSet& lcset)
752{
753 dtAssert(alloc);
754
755 const int w = (int)layer.header->width;
756 const int h = (int)layer.header->height;
757
758 lcset.nconts = layer.regCount;
759 lcset.conts = (dtTileCacheContour*)alloc->alloc(sizeof(dtTileCacheContour)*lcset.nconts);
760 if (!lcset.conts)
761 return DT_FAILURE | DT_OUT_OF_MEMORY;
762 memset(lcset.conts, 0, sizeof(dtTileCacheContour)*lcset.nconts);
763
764 // Allocate temp buffer for contour tracing.
765 const int maxTempVerts = (w+h)*2 * 2; // Twice around the layer.
766
767 dtFixedArray<unsigned char> tempVerts(alloc, maxTempVerts*4);
768 if (!tempVerts)
769 return DT_FAILURE | DT_OUT_OF_MEMORY;
770
771 dtFixedArray<unsigned short> tempPoly(alloc, maxTempVerts);
772 if (!tempPoly)
773 return DT_FAILURE | DT_OUT_OF_MEMORY;
774
775 dtTempContour temp(tempVerts, maxTempVerts, tempPoly, maxTempVerts);
776
777 // Find contours.
778 for (int y = 0; y < h; ++y)
779 {
780 for (int x = 0; x < w; ++x)
781 {
782 const int idx = x+y*w;
783 const unsigned char ri = layer.regs[idx];
784 if (ri == 0xff)
785 continue;
786
787 dtTileCacheContour& cont = lcset.conts[ri];
788
789 if (cont.nverts > 0)
790 continue;
791
792 cont.reg = ri;
793 cont.area = layer.areas[idx];
794
795 if (!walkContour(layer, x, y, temp))
796 {
797 // Too complex contour.
798 // Note: If you hit here ofte, try increasing 'maxTempVerts'.
799 return DT_FAILURE | DT_BUFFER_TOO_SMALL;
800 }
801
802 simplifyContour(temp, maxError);
803
804 // Store contour.
805 cont.nverts = temp.nverts;

Callers 1

buildNavMeshTileMethod · 0.85

Calls 4

walkContourFunction · 0.85
simplifyContourFunction · 0.85
getCornerHeightFunction · 0.85
allocMethod · 0.45

Tested by

no test coverage detected