├── .gitignore ├── DebugUtils ├── Include │ ├── DebugDraw.h │ ├── DetourDebugDraw.h │ ├── RecastDebugDraw.h │ └── RecastDump.h └── Source │ ├── DebugDraw.cpp │ ├── DetourDebugDraw.cpp │ ├── RecastDebugDraw.cpp │ └── RecastDump.cpp ├── Detour ├── Include │ ├── DetourAlloc.h │ ├── DetourAssert.h │ ├── DetourCommon.h │ ├── DetourMath.h │ ├── DetourNavMesh.h │ ├── DetourNavMeshBuilder.h │ ├── DetourNavMeshQuery.h │ ├── DetourNode.h │ └── DetourStatus.h └── Source │ ├── DetourAlloc.cpp │ ├── DetourCommon.cpp │ ├── DetourNavMesh.cpp │ ├── DetourNavMeshBuilder.cpp │ ├── DetourNavMeshQuery.cpp │ └── DetourNode.cpp ├── DetourCrowd ├── Include │ ├── DetourCrowd.h │ ├── DetourLocalBoundary.h │ ├── DetourObstacleAvoidance.h │ ├── DetourPathCorridor.h │ ├── DetourPathQueue.h │ └── DetourProximityGrid.h └── Source │ ├── DetourCrowd.cpp │ ├── DetourLocalBoundary.cpp │ ├── DetourObstacleAvoidance.cpp │ ├── DetourPathCorridor.cpp │ ├── DetourPathQueue.cpp │ └── DetourProximityGrid.cpp ├── DetourTileCache ├── Include │ ├── DetourTileCache.h │ └── DetourTileCacheBuilder.h └── Source │ ├── DetourTileCache.cpp │ └── DetourTileCacheBuilder.cpp ├── Docs ├── Conceptual │ ├── license_c.txt │ └── mainpage_c.txt ├── DoxygenLayout.xml ├── Extern │ └── Recast_api.txt ├── Images │ └── recast_intro.png ├── Readme.txt ├── customdoxygen.css ├── footer.html └── header.html ├── Doxyfile ├── HierarchicalPathfinding ├── Include │ ├── Graph.h │ └── Navigation.h └── Source │ └── Navigation.cpp ├── License.txt ├── README.md ├── Recast ├── Include │ ├── Recast.h │ ├── RecastAlloc.h │ └── RecastAssert.h └── Source │ ├── Recast.cpp │ ├── RecastAlloc.cpp │ ├── RecastArea.cpp │ ├── RecastContour.cpp │ ├── RecastFilter.cpp │ ├── RecastLayers.cpp │ ├── RecastMesh.cpp │ ├── RecastMeshDetail.cpp │ ├── RecastRasterization.cpp │ └── RecastRegion.cpp └── RecastDemo ├── Contrib ├── fastlz │ ├── README.TXT │ ├── fastlz.c │ └── fastlz.h ├── metis │ ├── include │ │ ├── defs.h │ │ ├── macros.h │ │ ├── metis.h │ │ ├── proto.h │ │ ├── rename.h │ │ └── struct.h │ ├── lib │ │ ├── libmetis.a │ │ └── libmetis.lib │ └── source │ │ ├── CHANGES.v4 │ │ ├── CHANGES.v5 │ │ ├── GKlib │ │ └── trunk │ │ │ ├── GKlib.h │ │ │ ├── Makefile │ │ │ ├── b64.c │ │ │ ├── blas.c │ │ │ ├── dfkvkselect.c │ │ │ ├── dlmalloc.c │ │ │ ├── error.c │ │ │ ├── fs.c │ │ │ ├── getopt.c │ │ │ ├── gk_arch.h │ │ │ ├── gk_blas.h │ │ │ ├── gk_defs.h │ │ │ ├── gk_dlmalloc.h │ │ │ ├── gk_externs.h │ │ │ ├── gk_getopt.h │ │ │ ├── gk_macros.h │ │ │ ├── gk_memory.h │ │ │ ├── gk_proto.h │ │ │ ├── gk_sort.h │ │ │ ├── gk_struct.h │ │ │ ├── gk_types.h │ │ │ ├── htable.c │ │ │ ├── io.c │ │ │ ├── memory.c │ │ │ ├── omp.c │ │ │ ├── pdb.c │ │ │ ├── pqueue.c │ │ │ ├── seq.c │ │ │ ├── sort.c │ │ │ ├── string.c │ │ │ ├── test │ │ │ ├── Makefile │ │ │ ├── Makefile.in │ │ │ ├── gksort.c │ │ │ └── strings.c │ │ │ ├── timers.c │ │ │ ├── tokenizer.c │ │ │ └── util.c │ │ ├── INSTALL.v4 │ │ ├── INSTALL.v5 │ │ ├── LICENSE │ │ ├── Makefile │ │ ├── Makefile.help │ │ ├── Makefile.in │ │ ├── config │ │ ├── config.guess │ │ └── config.h │ │ ├── graphs │ │ ├── 4elt.graph │ │ ├── README │ │ ├── copter2.graph │ │ ├── metis.mesh │ │ └── test.mgraph │ │ ├── include │ │ └── metis.h │ │ ├── libmetis │ │ ├── Makefile │ │ ├── balance.c │ │ ├── bucketsort.c │ │ ├── ccgraph.c │ │ ├── checkgraph.c │ │ ├── cmetis.c │ │ ├── coarsen.c │ │ ├── compress.c │ │ ├── debug.c │ │ ├── defs.h │ │ ├── estmem.c │ │ ├── fm.c │ │ ├── fortran.c │ │ ├── frename.c │ │ ├── graph.c │ │ ├── initpart.c │ │ ├── kfmetis.c │ │ ├── kmetis.c │ │ ├── kvmetis.c │ │ ├── kwayfm.c │ │ ├── kwayrefine.c │ │ ├── kwayvolfm.c │ │ ├── kwayvolrefine.c │ │ ├── macros.h │ │ ├── match.c │ │ ├── mbalance.c │ │ ├── mbalance2.c │ │ ├── mcoarsen.c │ │ ├── memory.c │ │ ├── mesh.c │ │ ├── meshpart.c │ │ ├── metislib.h │ │ ├── mfm.c │ │ ├── mfm2.c │ │ ├── mincover.c │ │ ├── minitpart.c │ │ ├── minitpart2.c │ │ ├── mkmetis.c │ │ ├── mkwayfmh.c │ │ ├── mkwayrefine.c │ │ ├── mmatch.c │ │ ├── mmd.c │ │ ├── mpmetis.c │ │ ├── mrefine.c │ │ ├── mrefine2.c │ │ ├── mrkmetis.c │ │ ├── mutil.c │ │ ├── myqsort.c │ │ ├── ometis.c │ │ ├── parmetis.c │ │ ├── pmetis.c │ │ ├── pqueue.c │ │ ├── proto.h │ │ ├── refine.c │ │ ├── rename.h │ │ ├── rkmetis.c │ │ ├── separator.c │ │ ├── sfm.c │ │ ├── srefine.c │ │ ├── stat.c │ │ ├── stdheaders.h │ │ ├── streamio.c │ │ ├── struct.h │ │ ├── subdomains.c │ │ ├── timing.c │ │ └── util.c │ │ ├── programs │ │ ├── Makefile │ │ ├── cepic-rcb.c │ │ ├── cepic.c │ │ ├── cmdline_cmetis.c │ │ ├── cmdline_kfmetis.c │ │ ├── cmdline_pmetis.c │ │ ├── cmetis.c │ │ ├── defs.h │ │ ├── graphchk.c │ │ ├── io.c │ │ ├── kfmetis.c │ │ ├── kmetis.c │ │ ├── mesh2dual.c │ │ ├── mesh2nodal.c │ │ ├── metis.c │ │ ├── metisbin.h │ │ ├── mmetis.c │ │ ├── oemetis.c │ │ ├── onmetis.c │ │ ├── partdmesh.c │ │ ├── partnmesh.c │ │ ├── pmetis.c │ │ ├── proto.h │ │ ├── smbfactor.c │ │ └── struct.h │ │ ├── test │ │ ├── Makefile │ │ ├── mtest.c │ │ └── proto.h │ │ └── utils │ │ ├── int2idxtype.sh │ │ └── s+r.sh ├── stb_image.h └── stb_truetype.h ├── English.lproj ├── InfoPlist.strings └── MainMenu.xib ├── Icon.icns ├── Include ├── ChunkyTriMesh.h ├── ConvexVolumeTool.h ├── CrowdTool.h ├── Filelist.h ├── InputGeom.h ├── MeshLoaderObj.h ├── NavMeshTesterTool.h ├── NavmeshPruneTool.h ├── OffMeshConnectionTool.h ├── PerfTimer.h ├── SDLMain.h ├── Sample.h ├── SampleInterfaces.h ├── Sample_Debug.h ├── Sample_SoloMesh.h ├── Sample_TempObstacles.h ├── Sample_TileMesh.h ├── SlideShow.h ├── TestCase.h ├── ValueHistory.h ├── imgui.h └── imguiRenderGL.h ├── Info.plist ├── Source ├── ChunkyTriMesh.cpp ├── ConvexVolumeTool.cpp ├── CrowdTool.cpp ├── Filelist.cpp ├── InputGeom.cpp ├── MeshLoaderObj.cpp ├── NavMeshPruneTool.cpp ├── NavMeshTesterTool.cpp ├── OffMeshConnectionTool.cpp ├── PerfTimer.cpp ├── SDLMain.m ├── Sample.cpp ├── SampleInterfaces.cpp ├── Sample_Debug.cpp ├── Sample_SoloMesh.cpp ├── Sample_TempObstacles.cpp ├── Sample_TileMesh.cpp ├── SlideShow.cpp ├── TestCase.cpp ├── ValueHistory.cpp ├── imgui.cpp ├── imguiRenderGL.cpp └── main.cpp ├── premake4.lua └── screenshot.png /.gitignore: -------------------------------------------------------------------------------- 1 | ## Compiled source # 2 | *.com 3 | *.class 4 | *.dll 5 | *.exe 6 | *.ilk 7 | *.o 8 | *.pdb 9 | *.so 10 | 11 | ## Linux exes have no extension 12 | RecastDemo/Bin/RecastDemo 13 | 14 | # Build directory 15 | RecastDemo/Build 16 | 17 | # Ignore some meshes based on name 18 | RecastDemo/Bin/Meshes/_* 19 | 20 | ## Logs and databases # 21 | *.log 22 | *.sql 23 | *.sqlite 24 | 25 | ## OS generated files # 26 | .DS_Store 27 | .DS_Store? 28 | ._* 29 | .Spotlight-V100 30 | .Trashes 31 | ehthumbs.db 32 | Thumbs.db 33 | *.swp 34 | *.swo 35 | 36 | ## xcode specific 37 | *xcuserdata* 38 | 39 | ## SDL contrib 40 | RecastDemo/Contrib/SDL/* 41 | -------------------------------------------------------------------------------- /DebugUtils/Include/DetourDebugDraw.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2009-2010 Mikko Mononen memon@inside.org 3 | // 4 | // This software is provided 'as-is', without any express or implied 5 | // warranty. In no event will the authors be held liable for any damages 6 | // arising from the use of this software. 7 | // Permission is granted to anyone to use this software for any purpose, 8 | // including commercial applications, and to alter it and redistribute it 9 | // freely, subject to the following restrictions: 10 | // 1. The origin of this software must not be misrepresented; you must not 11 | // claim that you wrote the original software. If you use this software 12 | // in a product, an acknowledgment in the product documentation would be 13 | // appreciated but is not required. 14 | // 2. Altered source versions must be plainly marked as such, and must not be 15 | // misrepresented as being the original software. 16 | // 3. This notice may not be removed or altered from any source distribution. 17 | // 18 | 19 | #ifndef DETOURDEBUGDRAW_H 20 | #define DETOURDEBUGDRAW_H 21 | 22 | #include "DetourNavMesh.h" 23 | #include "DetourNavMeshQuery.h" 24 | #include "DetourTileCacheBuilder.h" 25 | #include "Graph.h" 26 | 27 | enum DrawNavMeshFlags 28 | { 29 | DU_DRAWNAVMESH_OFFMESHCONS = 0x01, 30 | DU_DRAWNAVMESH_CLOSEDLIST = 0x02, 31 | DU_DRAWNAVMESH_COLOR_TILES = 0x04, 32 | }; 33 | 34 | void duDebugDrawNavMesh(struct duDebugDraw* dd, const dtNavMesh& mesh, unsigned char flags); 35 | void duDebugDrawNavMeshWithClosedList(struct duDebugDraw* dd, const dtNavMesh& mesh, const dtNavMeshQuery& query, unsigned char flags); 36 | void duDebugDrawNavMeshNodes(struct duDebugDraw* dd, const dtNavMeshQuery& query); 37 | void duDebugDrawNavMeshBVTree(struct duDebugDraw* dd, const dtNavMesh& mesh); 38 | void duDebugDrawNavMeshPortals(struct duDebugDraw* dd, const dtNavMesh& mesh); 39 | void duDebugDrawNavMeshPolysWithFlags(struct duDebugDraw* dd, const dtNavMesh& mesh, const unsigned short polyFlags, const unsigned int col); 40 | void duDebugDrawNavMeshPoly(struct duDebugDraw* dd, const dtNavMesh& mesh, dtPolyRef ref, const unsigned int col); 41 | 42 | void duDebugDrawTileCacheLayerAreas(struct duDebugDraw* dd, const dtTileCacheLayer& layer, const float cs, const float ch); 43 | void duDebugDrawTileCacheLayerRegions(struct duDebugDraw* dd, const dtTileCacheLayer& layer, const float cs, const float ch); 44 | void duDebugDrawTileCacheContours(duDebugDraw* dd, const struct dtTileCacheContourSet& lcset, 45 | const float* orig, const float cs, const float ch); 46 | void duDebugDrawTileCachePolyMesh(duDebugDraw* dd, const struct dtTileCachePolyMesh& lmesh, 47 | const float* orig, const float cs, const float ch); 48 | 49 | 50 | #endif // DETOURDEBUGDRAW_H 51 | -------------------------------------------------------------------------------- /DebugUtils/Include/RecastDebugDraw.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2009-2010 Mikko Mononen memon@inside.org 3 | // 4 | // This software is provided 'as-is', without any express or implied 5 | // warranty. In no event will the authors be held liable for any damages 6 | // arising from the use of this software. 7 | // Permission is granted to anyone to use this software for any purpose, 8 | // including commercial applications, and to alter it and redistribute it 9 | // freely, subject to the following restrictions: 10 | // 1. The origin of this software must not be misrepresented; you must not 11 | // claim that you wrote the original software. If you use this software 12 | // in a product, an acknowledgment in the product documentation would be 13 | // appreciated but is not required. 14 | // 2. Altered source versions must be plainly marked as such, and must not be 15 | // misrepresented as being the original software. 16 | // 3. This notice may not be removed or altered from any source distribution. 17 | // 18 | 19 | #ifndef RECAST_DEBUGDRAW_H 20 | #define RECAST_DEBUGDRAW_H 21 | 22 | #include 23 | #include "DetourNavMesh.h" 24 | 25 | void duDebugDrawTriMesh(struct duDebugDraw* dd, const float* verts, int nverts, const int* tris, const float* normals, int ntris, const unsigned char* flags, const float texScale); 26 | void duDebugDrawTriMeshSlope(struct duDebugDraw* dd, const float* verts, int nverts, const int* tris, const float* normals, int ntris, const float walkableSlopeAngle, const float texScale); 27 | 28 | void duDebugDrawHeightfieldSolid(struct duDebugDraw* dd, const struct rcHeightfield& hf); 29 | void duDebugDrawHeightfieldWalkable(struct duDebugDraw* dd, const struct rcHeightfield& hf); 30 | 31 | void duDebugDrawCompactHeightfieldSolid(struct duDebugDraw* dd, const struct rcCompactHeightfield& chf); 32 | void duDebugDrawCompactHeightfieldRegions(struct duDebugDraw* dd, const struct rcCompactHeightfield& chf); 33 | void duDebugDrawCompactHeightfieldDistance(struct duDebugDraw* dd, const struct rcCompactHeightfield& chf); 34 | 35 | void duDebugDrawHeightfieldLayer(duDebugDraw* dd, const struct rcHeightfieldLayer& layer, const int idx); 36 | void duDebugDrawHeightfieldLayers(duDebugDraw* dd, const struct rcHeightfieldLayerSet& lset); 37 | void duDebugDrawHeightfieldLayersRegions(duDebugDraw* dd, const struct rcHeightfieldLayerSet& lset); 38 | 39 | void duDebugDrawLayerContours(duDebugDraw* dd, const struct rcLayerContourSet& lcset); 40 | void duDebugDrawLayerPolyMesh(duDebugDraw* dd, const struct rcLayerPolyMesh& lmesh); 41 | 42 | 43 | void duDebugDrawRegionConnections(struct duDebugDraw* dd, const struct rcContourSet& cset, const float alpha = 1.0f); 44 | void duDebugDrawRawContours(struct duDebugDraw* dd, const struct rcContourSet& cset, const float alpha = 1.0f); 45 | void duDebugDrawContours(struct duDebugDraw* dd, const struct rcContourSet& cset, const float alpha = 1.0f); 46 | void duDebugDrawPolyMesh(struct duDebugDraw* dd, const struct rcPolyMesh& mesh); 47 | void duDebugDrawPolyMeshDetail(struct duDebugDraw* dd, const struct rcPolyMeshDetail& dmesh); 48 | void duDebugDrawHierarchicalDivision(struct duDebugDraw* dd, const dtNavMesh& mesh, std::map clusteredNodes); 49 | 50 | #endif // RECAST_DEBUGDRAW_H 51 | -------------------------------------------------------------------------------- /DebugUtils/Include/RecastDump.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2009-2010 Mikko Mononen memon@inside.org 3 | // 4 | // This software is provided 'as-is', without any express or implied 5 | // warranty. In no event will the authors be held liable for any damages 6 | // arising from the use of this software. 7 | // Permission is granted to anyone to use this software for any purpose, 8 | // including commercial applications, and to alter it and redistribute it 9 | // freely, subject to the following restrictions: 10 | // 1. The origin of this software must not be misrepresented; you must not 11 | // claim that you wrote the original software. If you use this software 12 | // in a product, an acknowledgment in the product documentation would be 13 | // appreciated but is not required. 14 | // 2. Altered source versions must be plainly marked as such, and must not be 15 | // misrepresented as being the original software. 16 | // 3. This notice may not be removed or altered from any source distribution. 17 | // 18 | 19 | #ifndef RECAST_DUMP_H 20 | #define RECAST_DUMP_H 21 | 22 | struct duFileIO 23 | { 24 | virtual ~duFileIO() = 0; 25 | virtual bool isWriting() const = 0; 26 | virtual bool isReading() const = 0; 27 | virtual bool write(const void* ptr, const size_t size) = 0; 28 | virtual bool read(void* ptr, const size_t size) = 0; 29 | }; 30 | 31 | bool duDumpPolyMeshToObj(struct rcPolyMesh& pmesh, duFileIO* io); 32 | bool duDumpPolyMeshDetailToObj(struct rcPolyMeshDetail& dmesh, duFileIO* io); 33 | 34 | bool duDumpContourSet(struct rcContourSet& cset, duFileIO* io); 35 | bool duReadContourSet(struct rcContourSet& cset, duFileIO* io); 36 | 37 | bool duDumpCompactHeightfield(struct rcCompactHeightfield& chf, duFileIO* io); 38 | bool duReadCompactHeightfield(struct rcCompactHeightfield& chf, duFileIO* io); 39 | 40 | void duLogBuildTimes(rcContext& ctx, const int totalTileUsec); 41 | 42 | 43 | #endif // RECAST_DUMP_H 44 | -------------------------------------------------------------------------------- /Detour/Include/DetourAlloc.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2009-2010 Mikko Mononen memon@inside.org 3 | // 4 | // This software is provided 'as-is', without any express or implied 5 | // warranty. In no event will the authors be held liable for any damages 6 | // arising from the use of this software. 7 | // Permission is granted to anyone to use this software for any purpose, 8 | // including commercial applications, and to alter it and redistribute it 9 | // freely, subject to the following restrictions: 10 | // 1. The origin of this software must not be misrepresented; you must not 11 | // claim that you wrote the original software. If you use this software 12 | // in a product, an acknowledgment in the product documentation would be 13 | // appreciated but is not required. 14 | // 2. Altered source versions must be plainly marked as such, and must not be 15 | // misrepresented as being the original software. 16 | // 3. This notice may not be removed or altered from any source distribution. 17 | // 18 | 19 | #ifndef DETOURALLOCATOR_H 20 | #define DETOURALLOCATOR_H 21 | 22 | /// Provides hint values to the memory allocator on how long the 23 | /// memory is expected to be used. 24 | enum dtAllocHint 25 | { 26 | DT_ALLOC_PERM, ///< Memory persist after a function call. 27 | DT_ALLOC_TEMP ///< Memory used temporarily within a function. 28 | }; 29 | 30 | /// A memory allocation function. 31 | // @param[in] size The size, in bytes of memory, to allocate. 32 | // @param[in] rcAllocHint A hint to the allocator on how long the memory is expected to be in use. 33 | // @return A pointer to the beginning of the allocated memory block, or null if the allocation failed. 34 | /// @see dtAllocSetCustom 35 | typedef void* (dtAllocFunc)(int size, dtAllocHint hint); 36 | 37 | /// A memory deallocation function. 38 | /// @param[in] ptr A pointer to a memory block previously allocated using #dtAllocFunc. 39 | /// @see dtAllocSetCustom 40 | typedef void (dtFreeFunc)(void* ptr); 41 | 42 | /// Sets the base custom allocation functions to be used by Detour. 43 | /// @param[in] allocFunc The memory allocation function to be used by #dtAlloc 44 | /// @param[in] freeFunc The memory de-allocation function to be used by #dtFree 45 | void dtAllocSetCustom(dtAllocFunc *allocFunc, dtFreeFunc *freeFunc); 46 | 47 | /// Allocates a memory block. 48 | /// @param[in] size The size, in bytes of memory, to allocate. 49 | /// @param[in] hint A hint to the allocator on how long the memory is expected to be in use. 50 | /// @return A pointer to the beginning of the allocated memory block, or null if the allocation failed. 51 | /// @see dtFree 52 | void* dtAlloc(int size, dtAllocHint hint); 53 | 54 | /// Deallocates a memory block. 55 | /// @param[in] ptr A pointer to a memory block previously allocated using #dtAlloc. 56 | /// @see dtAlloc 57 | void dtFree(void* ptr); 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /Detour/Include/DetourAssert.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2009-2010 Mikko Mononen memon@inside.org 3 | // 4 | // This software is provided 'as-is', without any express or implied 5 | // warranty. In no event will the authors be held liable for any damages 6 | // arising from the use of this software. 7 | // Permission is granted to anyone to use this software for any purpose, 8 | // including commercial applications, and to alter it and redistribute it 9 | // freely, subject to the following restrictions: 10 | // 1. The origin of this software must not be misrepresented; you must not 11 | // claim that you wrote the original software. If you use this software 12 | // in a product, an acknowledgment in the product documentation would be 13 | // appreciated but is not required. 14 | // 2. Altered source versions must be plainly marked as such, and must not be 15 | // misrepresented as being the original software. 16 | // 3. This notice may not be removed or altered from any source distribution. 17 | // 18 | 19 | #ifndef DETOURASSERT_H 20 | #define DETOURASSERT_H 21 | 22 | // Note: This header file's only purpose is to include define assert. 23 | // Feel free to change the file and include your own implementation instead. 24 | 25 | #ifdef NDEBUG 26 | // From http://cnicholson.net/2009/02/stupid-c-tricks-adventures-in-assert/ 27 | # define dtAssert(x) do { (void)sizeof(x); } while((void)(__LINE__==-1),false) 28 | #else 29 | # include 30 | # define dtAssert assert 31 | #endif 32 | 33 | #endif // DETOURASSERT_H 34 | -------------------------------------------------------------------------------- /Detour/Include/DetourMath.h: -------------------------------------------------------------------------------- 1 | #ifndef DETOURMATH_H 2 | #define DETOURMATH_H 3 | 4 | /** 5 | @defgroup detour Detour 6 | 7 | Members in this module are wrappers around the standard math library 8 | 9 | */ 10 | 11 | #include 12 | 13 | #define dtMathFabs(x) fabs(x) 14 | #define dtMathSqrtf(x) sqrtf(x) 15 | #define dtMathFloorf(x) floorf(x) 16 | #define dtMathCeilf(x) ceilf(x) 17 | #define dtMathCosf(x) cosf(x) 18 | #define dtMathSinf(x) sinf(x) 19 | #define dtMathAtan2f(y, x) atan2f(y, x) 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /Detour/Include/DetourStatus.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2009-2010 Mikko Mononen memon@inside.org 3 | // 4 | // This software is provided 'as-is', without any express or implied 5 | // warranty. In no event will the authors be held liable for any damages 6 | // arising from the use of this software. 7 | // Permission is granted to anyone to use this software for any purpose, 8 | // including commercial applications, and to alter it and redistribute it 9 | // freely, subject to the following restrictions: 10 | // 1. The origin of this software must not be misrepresented; you must not 11 | // claim that you wrote the original software. If you use this software 12 | // in a product, an acknowledgment in the product documentation would be 13 | // appreciated but is not required. 14 | // 2. Altered source versions must be plainly marked as such, and must not be 15 | // misrepresented as being the original software. 16 | // 3. This notice may not be removed or altered from any source distribution. 17 | // 18 | 19 | #ifndef DETOURSTATUS_H 20 | #define DETOURSTATUS_H 21 | 22 | typedef unsigned int dtStatus; 23 | 24 | // High level status. 25 | static const unsigned int DT_FAILURE = 1u << 31; // Operation failed. 26 | static const unsigned int DT_SUCCESS = 1u << 30; // Operation succeed. 27 | static const unsigned int DT_IN_PROGRESS = 1u << 29; // Operation still in progress. 28 | 29 | // Detail information for status. 30 | static const unsigned int DT_STATUS_DETAIL_MASK = 0x0ffffff; 31 | static const unsigned int DT_WRONG_MAGIC = 1 << 0; // Input data is not recognized. 32 | static const unsigned int DT_WRONG_VERSION = 1 << 1; // Input data is in wrong version. 33 | static const unsigned int DT_OUT_OF_MEMORY = 1 << 2; // Operation ran out of memory. 34 | static const unsigned int DT_INVALID_PARAM = 1 << 3; // An input parameter was invalid. 35 | static const unsigned int DT_BUFFER_TOO_SMALL = 1 << 4; // Result buffer for the query was too small to store all results. 36 | static const unsigned int DT_OUT_OF_NODES = 1 << 5; // Query ran out of nodes during search. 37 | static const unsigned int DT_PARTIAL_RESULT = 1 << 6; // Query did not reach the end location, returning best guess. 38 | 39 | 40 | // Returns true of status is success. 41 | inline bool dtStatusSucceed(dtStatus status) 42 | { 43 | return (status & DT_SUCCESS) != 0; 44 | } 45 | 46 | // Returns true of status is failure. 47 | inline bool dtStatusFailed(dtStatus status) 48 | { 49 | return (status & DT_FAILURE) != 0; 50 | } 51 | 52 | // Returns true of status is in progress. 53 | inline bool dtStatusInProgress(dtStatus status) 54 | { 55 | return (status & DT_IN_PROGRESS) != 0; 56 | } 57 | 58 | // Returns true if specific detail is set. 59 | inline bool dtStatusDetail(dtStatus status, unsigned int detail) 60 | { 61 | return (status & detail) != 0; 62 | } 63 | 64 | #endif // DETOURSTATUS_H 65 | -------------------------------------------------------------------------------- /Detour/Source/DetourAlloc.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2009-2010 Mikko Mononen memon@inside.org 3 | // 4 | // This software is provided 'as-is', without any express or implied 5 | // warranty. In no event will the authors be held liable for any damages 6 | // arising from the use of this software. 7 | // Permission is granted to anyone to use this software for any purpose, 8 | // including commercial applications, and to alter it and redistribute it 9 | // freely, subject to the following restrictions: 10 | // 1. The origin of this software must not be misrepresented; you must not 11 | // claim that you wrote the original software. If you use this software 12 | // in a product, an acknowledgment in the product documentation would be 13 | // appreciated but is not required. 14 | // 2. Altered source versions must be plainly marked as such, and must not be 15 | // misrepresented as being the original software. 16 | // 3. This notice may not be removed or altered from any source distribution. 17 | // 18 | 19 | #include 20 | #include "DetourAlloc.h" 21 | 22 | static void *dtAllocDefault(int size, dtAllocHint) 23 | { 24 | return malloc(size); 25 | } 26 | 27 | static void dtFreeDefault(void *ptr) 28 | { 29 | free(ptr); 30 | } 31 | 32 | static dtAllocFunc* sAllocFunc = dtAllocDefault; 33 | static dtFreeFunc* sFreeFunc = dtFreeDefault; 34 | 35 | void dtAllocSetCustom(dtAllocFunc *allocFunc, dtFreeFunc *freeFunc) 36 | { 37 | sAllocFunc = allocFunc ? allocFunc : dtAllocDefault; 38 | sFreeFunc = freeFunc ? freeFunc : dtFreeDefault; 39 | } 40 | 41 | void* dtAlloc(int size, dtAllocHint hint) 42 | { 43 | return sAllocFunc(size, hint); 44 | } 45 | 46 | void dtFree(void* ptr) 47 | { 48 | if (ptr) 49 | sFreeFunc(ptr); 50 | } 51 | -------------------------------------------------------------------------------- /DetourCrowd/Include/DetourLocalBoundary.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2009-2010 Mikko Mononen memon@inside.org 3 | // 4 | // This software is provided 'as-is', without any express or implied 5 | // warranty. In no event will the authors be held liable for any damages 6 | // arising from the use of this software. 7 | // Permission is granted to anyone to use this software for any purpose, 8 | // including commercial applications, and to alter it and redistribute it 9 | // freely, subject to the following restrictions: 10 | // 1. The origin of this software must not be misrepresented; you must not 11 | // claim that you wrote the original software. If you use this software 12 | // in a product, an acknowledgment in the product documentation would be 13 | // appreciated but is not required. 14 | // 2. Altered source versions must be plainly marked as such, and must not be 15 | // misrepresented as being the original software. 16 | // 3. This notice may not be removed or altered from any source distribution. 17 | // 18 | 19 | #ifndef DETOURLOCALBOUNDARY_H 20 | #define DETOURLOCALBOUNDARY_H 21 | 22 | #include "DetourNavMeshQuery.h" 23 | 24 | 25 | class dtLocalBoundary 26 | { 27 | static const int MAX_LOCAL_SEGS = 8; 28 | static const int MAX_LOCAL_POLYS = 16; 29 | 30 | struct Segment 31 | { 32 | float s[6]; ///< Segment start/end 33 | float d; ///< Distance for pruning. 34 | }; 35 | 36 | float m_center[3]; 37 | Segment m_segs[MAX_LOCAL_SEGS]; 38 | int m_nsegs; 39 | 40 | dtPolyRef m_polys[MAX_LOCAL_POLYS]; 41 | int m_npolys; 42 | 43 | void addSegment(const float dist, const float* seg); 44 | 45 | public: 46 | dtLocalBoundary(); 47 | ~dtLocalBoundary(); 48 | 49 | void reset(); 50 | 51 | void update(dtPolyRef ref, const float* pos, const float collisionQueryRange, 52 | dtNavMeshQuery* navquery, const dtQueryFilter* filter); 53 | 54 | bool isValid(dtNavMeshQuery* navquery, const dtQueryFilter* filter); 55 | 56 | inline const float* getCenter() const { return m_center; } 57 | inline int getSegmentCount() const { return m_nsegs; } 58 | inline const float* getSegment(int i) const { return m_segs[i].s; } 59 | }; 60 | 61 | #endif // DETOURLOCALBOUNDARY_H 62 | -------------------------------------------------------------------------------- /DetourCrowd/Include/DetourPathQueue.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2009-2010 Mikko Mononen memon@inside.org 3 | // 4 | // This software is provided 'as-is', without any express or implied 5 | // warranty. In no event will the authors be held liable for any damages 6 | // arising from the use of this software. 7 | // Permission is granted to anyone to use this software for any purpose, 8 | // including commercial applications, and to alter it and redistribute it 9 | // freely, subject to the following restrictions: 10 | // 1. The origin of this software must not be misrepresented; you must not 11 | // claim that you wrote the original software. If you use this software 12 | // in a product, an acknowledgment in the product documentation would be 13 | // appreciated but is not required. 14 | // 2. Altered source versions must be plainly marked as such, and must not be 15 | // misrepresented as being the original software. 16 | // 3. This notice may not be removed or altered from any source distribution. 17 | // 18 | 19 | #ifndef DETOURPATHQUEUE_H 20 | #define DETOURPATHQUEUE_H 21 | 22 | #include "DetourNavMesh.h" 23 | #include "DetourNavMeshQuery.h" 24 | 25 | static const unsigned int DT_PATHQ_INVALID = 0; 26 | 27 | typedef unsigned int dtPathQueueRef; 28 | 29 | class dtPathQueue 30 | { 31 | struct PathQuery 32 | { 33 | dtPathQueueRef ref; 34 | /// Path find start and end location. 35 | float startPos[3], endPos[3]; 36 | dtPolyRef startRef, endRef; 37 | /// Result. 38 | dtPolyRef* path; 39 | int npath; 40 | /// State. 41 | dtStatus status; 42 | int keepAlive; 43 | const dtQueryFilter* filter; ///< TODO: This is potentially dangerous! 44 | }; 45 | 46 | static const int MAX_QUEUE = 8; 47 | PathQuery m_queue[MAX_QUEUE]; 48 | dtPathQueueRef m_nextHandle; 49 | int m_maxPathSize; 50 | int m_queueHead; 51 | dtNavMeshQuery* m_navquery; 52 | 53 | void purge(); 54 | 55 | public: 56 | dtPathQueue(); 57 | ~dtPathQueue(); 58 | 59 | bool init(const int maxPathSize, const int maxSearchNodeCount, dtNavMesh* nav); 60 | 61 | void update(const int maxIters); 62 | 63 | dtPathQueueRef request(dtPolyRef startRef, dtPolyRef endRef, 64 | const float* startPos, const float* endPos, 65 | const dtQueryFilter* filter); 66 | 67 | dtStatus getRequestStatus(dtPathQueueRef ref) const; 68 | 69 | dtStatus getPathResult(dtPathQueueRef ref, dtPolyRef* path, int* pathSize, const int maxPath); 70 | 71 | inline const dtNavMeshQuery* getNavQuery() const { return m_navquery; } 72 | 73 | }; 74 | 75 | #endif // DETOURPATHQUEUE_H 76 | -------------------------------------------------------------------------------- /DetourCrowd/Include/DetourProximityGrid.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2009-2010 Mikko Mononen memon@inside.org 3 | // 4 | // This software is provided 'as-is', without any express or implied 5 | // warranty. In no event will the authors be held liable for any damages 6 | // arising from the use of this software. 7 | // Permission is granted to anyone to use this software for any purpose, 8 | // including commercial applications, and to alter it and redistribute it 9 | // freely, subject to the following restrictions: 10 | // 1. The origin of this software must not be misrepresented; you must not 11 | // claim that you wrote the original software. If you use this software 12 | // in a product, an acknowledgment in the product documentation would be 13 | // appreciated but is not required. 14 | // 2. Altered source versions must be plainly marked as such, and must not be 15 | // misrepresented as being the original software. 16 | // 3. This notice may not be removed or altered from any source distribution. 17 | // 18 | 19 | #ifndef DETOURPROXIMITYGRID_H 20 | #define DETOURPROXIMITYGRID_H 21 | 22 | class dtProximityGrid 23 | { 24 | int m_maxItems; 25 | float m_cellSize; 26 | float m_invCellSize; 27 | 28 | struct Item 29 | { 30 | unsigned short id; 31 | short x,y; 32 | unsigned short next; 33 | }; 34 | Item* m_pool; 35 | int m_poolHead; 36 | int m_poolSize; 37 | 38 | unsigned short* m_buckets; 39 | int m_bucketsSize; 40 | 41 | int m_bounds[4]; 42 | 43 | public: 44 | dtProximityGrid(); 45 | ~dtProximityGrid(); 46 | 47 | bool init(const int maxItems, const float cellSize); 48 | 49 | void clear(); 50 | 51 | void addItem(const unsigned short id, 52 | const float minx, const float miny, 53 | const float maxx, const float maxy); 54 | 55 | int queryItems(const float minx, const float miny, 56 | const float maxx, const float maxy, 57 | unsigned short* ids, const int maxIds) const; 58 | 59 | int getItemCountAt(const int x, const int y) const; 60 | 61 | inline const int* getBounds() const { return m_bounds; } 62 | inline float getCellSize() const { return m_cellSize; } 63 | }; 64 | 65 | dtProximityGrid* dtAllocProximityGrid(); 66 | void dtFreeProximityGrid(dtProximityGrid* ptr); 67 | 68 | 69 | #endif // DETOURPROXIMITYGRID_H 70 | 71 | -------------------------------------------------------------------------------- /Docs/Conceptual/license_c.txt: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | @page License License 4 | 5 |
 6 | Copyright (c) 2009-2011 Mikko Mononen memon@inside.org
 7 | 
 8 | This software is provided 'as-is', without any express or implied
 9 | warranty.  In no event will the authors be held liable for any damages
10 | arising from the use of this software.
11 | 
12 | Permission is granted to anyone to use this software for any purpose,
13 | including commercial applications, and to alter it and redistribute it
14 | freely, subject to the following restrictions:
15 | 
16 | 1. The origin of this software must not be misrepresented; you must not
17 |    claim that you wrote the original software. If you use this software
18 |    in a product, an acknowledgment in the product documentation would be
19 |    appreciated but is not required.
20 | 
21 | 2. Altered source versions must be plainly marked as such, and must not be
22 |    misrepresented as being the original software.
23 | 
24 | 3. This notice may not be removed or altered from any source distribution.
25 | 
26 | 27 | */ -------------------------------------------------------------------------------- /Docs/Conceptual/mainpage_c.txt: -------------------------------------------------------------------------------- 1 | /// @mainpage Recast Navigation 2 | /// 3 | /// @note A documentation effort is currently underway. 4 | /// This documentation is in a draft state until the effort is complete. 5 | /// 6 | /// @section intro_recast Recast 7 | /// 8 | /// Recast is state of the art navigation mesh construction toolset for 9 | /// games. 10 | /// 11 | /// - It is automatic, which means that you can throw any level 12 | /// geometry at it and you will get robust mesh out. 13 | /// - It is fast which means swift turnaround times for level 14 | /// designers. 15 | /// - It is open source so it comes with full source and you can 16 | /// customize it to your hearts content. 17 | /// 18 | /// The Library is free for commercial use and open source under the 19 | /// ZLib License. 20 | /// 21 | /// Please use the latest version from the 22 | /// SVN. 23 | /// 24 | /// @image html recast_intro.png 25 | /// 26 | /// The Recast process starts with constructing a voxel mold from a level 27 | /// geometry and then casting a navigation mesh over it. The process 28 | /// consists of three steps, building the voxel mold, partitioning the 29 | /// mold into simple regions, peeling off the regions as simple polygons. 30 | /// 31 | /// -# The voxel mold is build from the input triangle mesh by 32 | /// rasterizing the triangles into a multi-layer heightfield. Some 33 | /// simple filters are then applied to the mold to prune out locations 34 | /// where the character would not be able to move. 35 | /// -# The walkable areas described by the mold are divided into simple 36 | /// overlayed 2D regions. The resulting regions have only one 37 | /// non-overlapping contour, which simplifies the final step of the 38 | /// process tremendously. 39 | /// -# The navigation polygons are peeled off from the regions by first 40 | /// tracing the boundaries and then simplifying them. The resulting 41 | /// polygons are finally converted to convex polygons which makes them 42 | /// perfect for pathfinding and spatial reasoning about the level. 43 | /// 44 | /// @section intro_detour Detour 45 | /// 46 | /// Recast is accompanied by Detour, a path-finding and spatial reasoning 47 | /// toolkit. You can use any navigation mesh with Detour, but of course 48 | /// the data generated by Recast fits perfectly. 49 | /// 50 | /// Detour offers a simple static navigation mesh that is suitable for 51 | /// many simple cases, as well as a tiled navigation mesh that allows you 52 | /// to add and remove pieces of the mesh. The tiled mesh allows you to 53 | /// create systems where you stream new navigation data in and out as 54 | /// the player progresses the level, or regenerate tiles as the 55 | /// world changes. 56 | /// 57 | /// You can discuss and give feedback for Recast and Detour in the 58 | /// 59 | /// discussion group. 60 | /// -------------------------------------------------------------------------------- /Docs/Images/recast_intro.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/educharlie/HNA-Algorithm/388e185b8ea4e5bd82c77cb7358b38bca61661d7/Docs/Images/recast_intro.png -------------------------------------------------------------------------------- /Docs/Readme.txt: -------------------------------------------------------------------------------- 1 | This directory contains source for the documentation. It is also the 2 | build target for doxygen output. 3 | 4 | Directory Layout 5 | 6 | . (Docs root) 7 | 8 | High level content and format files. (E.g. css, header, footer.) 9 | 10 | ./Conceptual 11 | 12 | Conceptual (non-api) documentation such as overviews, how-to's, etc. 13 | The main index page content is also in this directory. 14 | 15 | ./Extern 16 | 17 | API documentation that is located outside the source files. 18 | 19 | When the API documentation gets too big or complex for the header 20 | and source files, it goes in this directory. 21 | 22 | ./Images 23 | 24 | Images related to the documentation. 25 | 26 | Miscellany 27 | 28 | One of the requirements for the API documentation is that it 29 | has the minimum possible impact on the declarations in the 30 | header files. So, in general, the header file declarations only 31 | contain summary documentation. The detail documentation 32 | is placed as follows: 33 | 34 | 1. If an element is defined in a cpp file, then place 35 | the detail documentation in the source file. 36 | 2. If an element does not have an associated cpp file, then 37 | place the detail documentation at the end of the header file. 38 | 3. If there is a lot of detail documentation cluttering up 39 | the end of a header file, then the content is moved to 40 | a separate file in the Extern directory. 41 | 42 | 43 | -------------------------------------------------------------------------------- /Docs/footer.html: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Docs/header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | $title 6 | 7 | 8 | $treeview 9 | $search 10 | $mathjax 11 | 12 | 13 |
14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 29 | 30 | 31 | 32 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 |
24 |
$projectname 25 |  $projectnumber 26 |
27 |
$projectbrief
28 |
33 |
$projectbrief
34 |
$searchbox
45 |
46 | 47 | -------------------------------------------------------------------------------- /HierarchicalPathfinding/Include/Graph.h: -------------------------------------------------------------------------------- 1 | #ifndef __GRAPH_H__ 2 | #define __GRAPH_H__ 3 | 4 | #include "DetourCommon.h" 5 | #include "DetourAlloc.h" 6 | #include 7 | #include 8 | 9 | 10 | const int maxInternalPath = 256; 11 | const int maxNodes = 2048; 12 | 13 | static const float H_SCALE = 0.999f; 14 | 15 | class Graph{ 16 | 17 | typedef unsigned int dtPolyRef; 18 | 19 | public: 20 | 21 | struct IntraEdge 22 | { 23 | int startPosId; 24 | int endPosId; 25 | int nPath; 26 | float cost; 27 | dtPolyRef path[maxInternalPath]; 28 | }; 29 | 30 | struct Edge 31 | { 32 | dtPolyRef targetNodeId; 33 | int idPos; 34 | int idPoly; 35 | float pos[3]; 36 | }; 37 | 38 | struct Node 39 | { 40 | dtPolyRef idNode; 41 | dtPolyRef idParent; 42 | 43 | Edge *edges; 44 | unsigned int numEdges; 45 | 46 | IntraEdge *intraEdges; 47 | unsigned int numIntraEdges; 48 | 49 | void InitEdge(int maxEdgesPerNode) 50 | { 51 | numEdges = 0; 52 | edges = 0; 53 | edges = (Edge*)dtAlloc(sizeof(Edge)*maxEdgesPerNode, DT_ALLOC_PERM); 54 | memset(edges, 0, sizeof(Edge)*maxEdgesPerNode); 55 | } 56 | 57 | void DestroyEdge() 58 | { 59 | dtFree(edges); 60 | numEdges = 0; 61 | } 62 | 63 | void InitIntraEdge() 64 | { 65 | int maxIntraEdgesPerNode = numEdges * numEdges; 66 | 67 | if(maxIntraEdgesPerNode > 0) 68 | { 69 | numIntraEdges = 0; 70 | intraEdges = 0; 71 | intraEdges = (IntraEdge*)dtAlloc(sizeof(IntraEdge)*maxIntraEdgesPerNode, DT_ALLOC_PERM); 72 | memset(intraEdges, 0, sizeof(IntraEdge)*maxIntraEdgesPerNode); 73 | } 74 | } 75 | 76 | void DestroyIntraEdge() 77 | { 78 | dtFree(intraEdges); 79 | numIntraEdges = 0; 80 | } 81 | }; 82 | 83 | Node* nodes; 84 | int numNodes; 85 | 86 | void AddEdge(dtPolyRef sourceIdNode, dtPolyRef targetIdNode, float* pos, int idPos, int idPoly) 87 | { 88 | Node *node = &nodes[sourceIdNode]; 89 | Edge *edge = 0; 90 | 91 | edge = &node->edges[node->numEdges++]; 92 | edge->targetNodeId = targetIdNode; 93 | edge->idPos = idPos; 94 | edge->idPoly = idPoly; 95 | dtVcopy(edge->pos, pos); 96 | } 97 | 98 | void AddNode(int nodeId) 99 | { 100 | Node *node = 0; 101 | node = &nodes[numNodes++]; 102 | node->idNode = nodeId; 103 | } 104 | 105 | void AddIntraEdge(dtPolyRef clusterId, int startPosId, int endPosId, float cost, dtPolyRef* path, int nPath) 106 | { 107 | Node *node = &nodes[clusterId]; 108 | IntraEdge *intraEdge = 0; 109 | 110 | intraEdge = &node->intraEdges[node->numIntraEdges++]; 111 | 112 | intraEdge->startPosId = startPosId; 113 | intraEdge->endPosId = endPosId; 114 | intraEdge->cost = cost; 115 | intraEdge->nPath = nPath; 116 | memcpy(intraEdge->path, path, sizeof(dtPolyRef)*nPath); 117 | } 118 | 119 | void AddParent(dtPolyRef nodeId, dtPolyRef idParent) 120 | { 121 | Node *node = &nodes[nodeId]; 122 | node->idParent = idParent; 123 | } 124 | 125 | void Init(int numMaxNodes) 126 | { 127 | numNodes = 0; 128 | nodes = 0; 129 | nodes = (Node*)dtAlloc(sizeof(Node)*numMaxNodes, DT_ALLOC_PERM); 130 | memset(nodes, 0, sizeof(Node)*numMaxNodes); 131 | } 132 | 133 | void InitEdge(int nodeId, int maxEdges) 134 | { 135 | Node *node = &nodes[nodeId]; 136 | node->InitEdge(maxEdges); 137 | } 138 | 139 | void Destroy() 140 | { 141 | dtFree(nodes); 142 | numNodes = 0; 143 | } 144 | }; 145 | 146 | #endif // __GRAPH_H__ -------------------------------------------------------------------------------- /HierarchicalPathfinding/Include/Navigation.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Graph.h" 3 | #include "DetourNavMesh.h" 4 | #include "Recast.h" 5 | #include "DetourStatus.h" 6 | #include "DetourNavMeshQuery.h" 7 | #include "DetourNode.h" 8 | #include "DetourAssert.h" 9 | #include "RecastAssert.h" 10 | #include 11 | 12 | extern "C" { 13 | #include "metis.h" 14 | } 15 | 16 | typedef int idxtype; 17 | 18 | class Navigation 19 | { 20 | 21 | public: 22 | 23 | void createHierarchicalGraph(int p_levels,int p_level,int p_mergedPolys,rcContext* ctx, const dtMeshTile* ptile, const dtNavMesh* pm_navMesh, const dtNavMeshQuery* pm_navQuery, std::map &nodesInCluster); 24 | 25 | dtStatus findPathNav(rcContext* ctx, dtPolyRef startRef, dtPolyRef endRef, const float* startPos, const float* endPos, const dtQueryFilter* filter, dtPolyRef* path, int &pathCount, const int maxPath); 26 | 27 | private: 28 | static const int MAX_POLYS = 256; 29 | const dtMeshTile* tile; 30 | const dtNavMesh* m_navMesh; 31 | const dtNavMeshQuery* m_navQuery; 32 | int numParts; 33 | dtPolyRef refBase; 34 | 35 | int levels; 36 | int level; 37 | int maxPolyInNode; 38 | 39 | class dtNodePool* m_nodePool; ///< Pointer to node pool. 40 | class dtNodeQueue* m_openList; ///< Pointer to open list queue. 41 | 42 | Graph mainGraph; 43 | Graph currentGraph; 44 | Graph parentGraph; 45 | 46 | int numTotalEdges; 47 | int numLevel; 48 | 49 | std::map nodeCluster; 50 | std::multimap clusterNode; 51 | 52 | Graph *graphs; 53 | int numGraphs; 54 | 55 | void mergeNodes(); 56 | void buildHierarchy(); 57 | void buildNodes(); 58 | void buildEdges(); 59 | 60 | void init(); 61 | 62 | dtStatus findHierarchicalPath(dtPolyRef startRef, dtPolyRef endRef, int startIdPos, int endIdPos, const float* startPos, const float* endPos, dtPolyRef* tempPathNodes,int* tempPathPolys, int *nTempPath, const int maxPath); 63 | float findPathLocal(dtPolyRef startRef, dtPolyRef endRef,int startIdPos, int endIdPos, const float* startPos, const float* endPos, dtPolyRef* path, int &pathCount, const int maxPath, std::vector subGraphNodes); 64 | float findPath(dtPolyRef startRef, dtPolyRef endRef, const float* startPos, const float* endPos, dtPolyRef* path, int &pathCount, const int maxPath); 65 | 66 | Graph::Node * getNode(dtPolyRef ref, int l); 67 | void getPath(int fromPosId, int toPosId, Graph::Node *node, int l, dtPolyRef* tempPath, int &nTempPath); 68 | void setGraph(); 69 | float getCost(const Graph::Node *node, int startPosId, int endPosId, const float * startPos, const float * endPos); 70 | 71 | void linkStartToGraph(Graph::Node *node, dtPolyRef ref, const float *pos, int startIdPos); 72 | void linkEndToGraph(Graph::Node *node, dtPolyRef ref, const float *pos, int startIdPos); 73 | 74 | void checkPartition(int* part, const int numNodes, const int numParts); 75 | void explorePartition(int idNode, int* newPart, int* part); 76 | }; 77 | 78 | -------------------------------------------------------------------------------- /License.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 Mikko Mononen memon@inside.org 2 | 3 | This software is provided 'as-is', without any express or implied 4 | warranty. In no event will the authors be held liable for any damages 5 | arising from the use of this software. 6 | 7 | Permission is granted to anyone to use this software for any purpose, 8 | including commercial applications, and to alter it and redistribute it 9 | freely, subject to the following restrictions: 10 | 11 | 1. The origin of this software must not be misrepresented; you must not 12 | claim that you wrote the original software. If you use this software 13 | in a product, an acknowledgment in the product documentation would be 14 | appreciated but is not required. 15 | 2. Altered source versions must be plainly marked as such, and must not be 16 | misrepresented as being the original software. 17 | 3. This notice may not be removed or altered from any source distribution. 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # HPA-NavMesh 2 | Hierarchical Pathfinding for Navigation Meshes (HNA*) 3 | 4 | Path finding is a common problem in computer games. Most videogames require to simulate thousands or millions of agents who interact and navigate in a 3D world showing capabilities such as chasing, seeking or intercepting other agents. A new hierarchical path finding solution is proposed for large environments. Thus, a navigation mesh as abstract data structure is used in order to divide the 3D world. Then, a hierarchy of graphs is built to perform faster path finding calculations than a common A*. The benefits of this new approach are demonstrated on large world models. 5 | -------------------------------------------------------------------------------- /Recast/Include/RecastAssert.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2009-2010 Mikko Mononen memon@inside.org 3 | // 4 | // This software is provided 'as-is', without any express or implied 5 | // warranty. In no event will the authors be held liable for any damages 6 | // arising from the use of this software. 7 | // Permission is granted to anyone to use this software for any purpose, 8 | // including commercial applications, and to alter it and redistribute it 9 | // freely, subject to the following restrictions: 10 | // 1. The origin of this software must not be misrepresented; you must not 11 | // claim that you wrote the original software. If you use this software 12 | // in a product, an acknowledgment in the product documentation would be 13 | // appreciated but is not required. 14 | // 2. Altered source versions must be plainly marked as such, and must not be 15 | // misrepresented as being the original software. 16 | // 3. This notice may not be removed or altered from any source distribution. 17 | // 18 | 19 | #ifndef RECASTASSERT_H 20 | #define RECASTASSERT_H 21 | 22 | // Note: This header file's only purpose is to include define assert. 23 | // Feel free to change the file and include your own implementation instead. 24 | 25 | #ifdef NDEBUG 26 | // From http://cnicholson.net/2009/02/stupid-c-tricks-adventures-in-assert/ 27 | # define rcAssert(x) do { (void)sizeof(x); } while((void)(__LINE__==-1),false) 28 | #else 29 | # include 30 | # define rcAssert assert 31 | #endif 32 | 33 | #endif // RECASTASSERT_H 34 | -------------------------------------------------------------------------------- /Recast/Source/RecastAlloc.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2009-2010 Mikko Mononen memon@inside.org 3 | // 4 | // This software is provided 'as-is', without any express or implied 5 | // warranty. In no event will the authors be held liable for any damages 6 | // arising from the use of this software. 7 | // Permission is granted to anyone to use this software for any purpose, 8 | // including commercial applications, and to alter it and redistribute it 9 | // freely, subject to the following restrictions: 10 | // 1. The origin of this software must not be misrepresented; you must not 11 | // claim that you wrote the original software. If you use this software 12 | // in a product, an acknowledgment in the product documentation would be 13 | // appreciated but is not required. 14 | // 2. Altered source versions must be plainly marked as such, and must not be 15 | // misrepresented as being the original software. 16 | // 3. This notice may not be removed or altered from any source distribution. 17 | // 18 | 19 | #include 20 | #include 21 | #include "RecastAlloc.h" 22 | 23 | static void *rcAllocDefault(int size, rcAllocHint) 24 | { 25 | return malloc(size); 26 | } 27 | 28 | static void rcFreeDefault(void *ptr) 29 | { 30 | free(ptr); 31 | } 32 | 33 | static rcAllocFunc* sRecastAllocFunc = rcAllocDefault; 34 | static rcFreeFunc* sRecastFreeFunc = rcFreeDefault; 35 | 36 | /// @see rcAlloc, rcFree 37 | void rcAllocSetCustom(rcAllocFunc *allocFunc, rcFreeFunc *freeFunc) 38 | { 39 | sRecastAllocFunc = allocFunc ? allocFunc : rcAllocDefault; 40 | sRecastFreeFunc = freeFunc ? freeFunc : rcFreeDefault; 41 | } 42 | 43 | /// @see rcAllocSetCustom 44 | void* rcAlloc(int size, rcAllocHint hint) 45 | { 46 | return sRecastAllocFunc(size, hint); 47 | } 48 | 49 | /// @par 50 | /// 51 | /// @warning This function leaves the value of @p ptr unchanged. So it still 52 | /// points to the same (now invalid) location, and not to null. 53 | /// 54 | /// @see rcAllocSetCustom 55 | void rcFree(void* ptr) 56 | { 57 | if (ptr) 58 | sRecastFreeFunc(ptr); 59 | } 60 | 61 | /// @class rcIntArray 62 | /// 63 | /// While it is possible to pre-allocate a specific array size during 64 | /// construction or by using the #resize method, certain methods will 65 | /// automatically resize the array as needed. 66 | /// 67 | /// @warning The array memory is not initialized to zero when the size is 68 | /// manually set during construction or when using #resize. 69 | 70 | /// @par 71 | /// 72 | /// Using this method ensures the array is at least large enough to hold 73 | /// the specified number of elements. This can improve performance by 74 | /// avoiding auto-resizing during use. 75 | void rcIntArray::resize(int n) 76 | { 77 | if (n > m_cap) 78 | { 79 | if (!m_cap) m_cap = n; 80 | while (m_cap < n) m_cap *= 2; 81 | int* newData = (int*)rcAlloc(m_cap*sizeof(int), RC_ALLOC_TEMP); 82 | if (m_size && newData) memcpy(newData, m_data, m_size*sizeof(int)); 83 | rcFree(m_data); 84 | m_data = newData; 85 | } 86 | m_size = n; 87 | } 88 | 89 | -------------------------------------------------------------------------------- /RecastDemo/Contrib/fastlz/README.TXT: -------------------------------------------------------------------------------- 1 | FastLZ - lightning-fast lossless compression library 2 | 3 | Author: Ariya Hidayat 4 | Official website: http://www.fastlz.org 5 | 6 | FastLZ is distributed using the MIT license, see file LICENSE 7 | for details. 8 | 9 | FastLZ consists of two files: fastlz.h and fastlz.c. Just add these 10 | files to your project in order to use FastLZ. For information on 11 | compression and decompression routines, see fastlz.h. 12 | 13 | A simple file compressor called 6pack is included as an example 14 | on how to use FastLZ. The corresponding decompressor is 6unpack. 15 | 16 | To compile using GCC: 17 | 18 | gcc -o 6pack 6pack.c fastlz.c 19 | gcc -o 6unpack 6unpack.c fastlz.c 20 | 21 | To compile using MinGW: 22 | 23 | mingw32-gcc -o 6pack 6pack.c fastlz.c 24 | mingw32-gcc -o 6unpack 6unpack.c fastlz.c 25 | 26 | To compile using Microsoft Visual C++: 27 | 28 | cl 6pack.c fastlz.c 29 | cl 6unpack.c fastlz.c 30 | 31 | To compile using Borland C++: 32 | 33 | bcc32 6pack.c fastlz.c 34 | bcc32 6unpack.c fastlz.c 35 | 36 | To compile using OpenWatcom C/C++: 37 | 38 | cl386 6pack.c fastlz.c 39 | cl386 6unpack.c fastlz.c 40 | 41 | To compile using Intel C++ compiler for Windows: 42 | 43 | icl 6pack.c fastlz.c 44 | icl 6unpack.c fastlz.c 45 | 46 | To compile using Intel C++ compiler for Linux: 47 | 48 | icc -o 6pack 6pack.c fastlz.c 49 | icc -o 6unpack 6unpack.c fastlz.c 50 | 51 | To compile 6pack using LCC-Win32: 52 | 53 | lc 6pack.c fastlz.c 54 | lc 6unpack.c fastlz.c 55 | 56 | To compile 6pack using Pelles C: 57 | 58 | pocc 6pack.c 59 | pocc 6unpack.c 60 | pocc fastlz.c 61 | polink 6pack.obj fastlz.obj 62 | polink 6unpack.obj fastlz.obj 63 | 64 | For speed optimization, always use proper compile flags for optimization options. 65 | Typical compiler flags are given below: 66 | 67 | * GCC (pre 4.2): -march=pentium -O3 -fomit-frame-pointer -mtune=pentium 68 | * GCC 4.2 or later: -march=pentium -O3 -fomit-frame-pointer -mtune=generic 69 | * Digital Mars C/C++: -o+all -5 70 | * Intel C++ (Windows): /O3 /Qipo 71 | * Intel C++ (Linux): -O2 -march=pentium -mtune=pentium 72 | * Borland C++: -O2 -5 73 | * LCC-Win32: -O 74 | * Pelles C: /O2 75 | 76 | -------------------------------------------------------------------------------- /RecastDemo/Contrib/fastlz/fastlz.h: -------------------------------------------------------------------------------- 1 | /* 2 | FastLZ - lightning-fast lossless compression library 3 | 4 | Copyright (C) 2007 Ariya Hidayat (ariya@kde.org) 5 | Copyright (C) 2006 Ariya Hidayat (ariya@kde.org) 6 | Copyright (C) 2005 Ariya Hidayat (ariya@kde.org) 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in 16 | all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | THE SOFTWARE. 25 | */ 26 | 27 | #ifndef FASTLZ_H 28 | #define FASTLZ_H 29 | 30 | #define FASTLZ_VERSION 0x000100 31 | 32 | #define FASTLZ_VERSION_MAJOR 0 33 | #define FASTLZ_VERSION_MINOR 0 34 | #define FASTLZ_VERSION_REVISION 0 35 | 36 | #define FASTLZ_VERSION_STRING "0.1.0" 37 | 38 | #if defined (__cplusplus) 39 | extern "C" { 40 | #endif 41 | 42 | /** 43 | Compress a block of data in the input buffer and returns the size of 44 | compressed block. The size of input buffer is specified by length. The 45 | minimum input buffer size is 16. 46 | 47 | The output buffer must be at least 5% larger than the input buffer 48 | and can not be smaller than 66 bytes. 49 | 50 | If the input is not compressible, the return value might be larger than 51 | length (input buffer size). 52 | 53 | The input buffer and the output buffer can not overlap. 54 | */ 55 | 56 | int fastlz_compress(const void* input, int length, void* output); 57 | 58 | /** 59 | Decompress a block of compressed data and returns the size of the 60 | decompressed block. If error occurs, e.g. the compressed data is 61 | corrupted or the output buffer is not large enough, then 0 (zero) 62 | will be returned instead. 63 | 64 | The input buffer and the output buffer can not overlap. 65 | 66 | Decompression is memory safe and guaranteed not to write the output buffer 67 | more than what is specified in maxout. 68 | */ 69 | 70 | int fastlz_decompress(const void* input, int length, void* output, int maxout); 71 | 72 | /** 73 | Compress a block of data in the input buffer and returns the size of 74 | compressed block. The size of input buffer is specified by length. The 75 | minimum input buffer size is 16. 76 | 77 | The output buffer must be at least 5% larger than the input buffer 78 | and can not be smaller than 66 bytes. 79 | 80 | If the input is not compressible, the return value might be larger than 81 | length (input buffer size). 82 | 83 | The input buffer and the output buffer can not overlap. 84 | 85 | Compression level can be specified in parameter level. At the moment, 86 | only level 1 and level 2 are supported. 87 | Level 1 is the fastest compression and generally useful for short data. 88 | Level 2 is slightly slower but it gives better compression ratio. 89 | 90 | Note that the compressed data, regardless of the level, can always be 91 | decompressed using the function fastlz_decompress above. 92 | */ 93 | 94 | int fastlz_compress_level(int level, const void* input, int length, void* output); 95 | 96 | #if defined (__cplusplus) 97 | } 98 | #endif 99 | 100 | #endif /* FASTLZ_H */ 101 | -------------------------------------------------------------------------------- /RecastDemo/Contrib/metis/include/metis.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997, Regents of the University of Minnesota 3 | * 4 | * metis.h 5 | * 6 | * This file includes all necessary header files 7 | * 8 | * Started 8/27/94 9 | * George 10 | * 11 | * $Id: metis.h,v 1.1 1998/11/27 17:59:21 karypis Exp $ 12 | */ 13 | 14 | 15 | #include 16 | #ifdef __STDC__ 17 | #include 18 | #else 19 | #include 20 | #endif 21 | //#include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #ifdef DMALLOC 29 | #include 30 | #endif 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | -------------------------------------------------------------------------------- /RecastDemo/Contrib/metis/lib/libmetis.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/educharlie/HNA-Algorithm/388e185b8ea4e5bd82c77cb7358b38bca61661d7/RecastDemo/Contrib/metis/lib/libmetis.a -------------------------------------------------------------------------------- /RecastDemo/Contrib/metis/lib/libmetis.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/educharlie/HNA-Algorithm/388e185b8ea4e5bd82c77cb7358b38bca61661d7/RecastDemo/Contrib/metis/lib/libmetis.lib -------------------------------------------------------------------------------- /RecastDemo/Contrib/metis/source/CHANGES.v5: -------------------------------------------------------------------------------- 1 | 2 | metis-5.0pre2 3 | ------------------------------------------------------------------------ 4 | r1437 | karypis | 2007-04-07 23:16:16 -0500 (Sat, 07 Apr 2007) | 3 lines 5 | 6 | - Added installation instructions and change-logs. 7 | - Tested 32bit & 64bit on 64bit architectures and passed tests. 8 | - Tested 32bit on 32bit architectures and passed tests. 9 | - strtoidx() addition for portable input file parsing 10 | - Restructured the internal memory allocation schemes for graph and 11 | refinement data. This should enhance portability and make the code 12 | easier to maintain. 13 | - Fixed some bad memory allocation calls (i.e., sizeof(x)/sizeof(idxtype). 14 | However, there are tons of those and need to be corrected once and for 15 | all by eliminating workspace and the associated mallocs. 16 | - Added mprint/mscanf family of functions for portable formated I/O 17 | of the idxtype datatype. The specifier for this datatype is %D. 18 | All library routines use this function for printing. 19 | The implementation of these routines is not very efficient, but 20 | that should do for now (in principle these routines should not be 21 | used unless debugging). 22 | - Incorporated GKlib into METIS, which replaced many of its internal 23 | functions. GKlib's malloc interface will enable graceful and clean 24 | aborts (i.e., free all internally allocated memory) on fatal errors. 25 | This will probably be available in the next pre-release. 26 | - Fixed the problems associated with metis.h that were identified by 27 | David (flyspray Issue #9). 28 | 29 | -------------------------------------------------------------------------------- /RecastDemo/Contrib/metis/source/GKlib/trunk/GKlib.h: -------------------------------------------------------------------------------- 1 | /* 2 | * GKlib.h 3 | * 4 | * George's library of most frequently used routines 5 | * 6 | * $Id: GKlib.h 1430 2007-04-07 17:53:07Z karypis $ 7 | * 8 | */ 9 | 10 | #ifndef _GKLIB_H_ 11 | #define _GKLIB_H_ 1 12 | 13 | #define GKMSPACE 14 | 15 | #if defined(_MSC_VER) 16 | #define __MSC__ 17 | #endif 18 | #if defined(__ICC) 19 | #define __ICC__ 20 | #endif 21 | 22 | 23 | #include /*!< This should be here, prior to the includes */ 24 | 25 | 26 | /************************************************************************* 27 | * Header file inclusion section 28 | **************************************************************************/ 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | #if defined(__WITHPCRE__) 46 | #include 47 | #else 48 | #include 49 | #endif 50 | 51 | 52 | #if defined(__OPENMP__) 53 | #include 54 | #endif 55 | 56 | 57 | 58 | 59 | #include 60 | #include 61 | #include 62 | #include 63 | #include 64 | #include 65 | #include 66 | 67 | #include 68 | #include 69 | #include 70 | 71 | #include 72 | 73 | #endif /* GKlib.h */ 74 | 75 | 76 | -------------------------------------------------------------------------------- /RecastDemo/Contrib/metis/source/GKlib/trunk/b64.c: -------------------------------------------------------------------------------- 1 | /*! 2 | \file b64.c 3 | \brief This file contains some simple 8bit-to-6bit encoding/deconding routines 4 | 5 | Most of these routines are outdated and should be converted using glibc's equivalent 6 | routines. 7 | 8 | \date Started 2/22/05 9 | \author George 10 | \version\verbatim $Id: b64.c 1421 2007-04-06 14:37:41Z karypis $ \endverbatim 11 | */ 12 | 13 | 14 | #include 15 | 16 | #define B64OFFSET 48 /* This is the '0' number */ 17 | 18 | 19 | 20 | /****************************************************************************** 21 | * Encode 3 '8-bit' binary bytes as 4 '6-bit' characters 22 | *******************************************************************************/ 23 | void encodeblock(unsigned char *in, unsigned char *out) 24 | { 25 | out[0] = (in[0] >> 2); 26 | out[1] = (((in[0] & 0x03) << 4) | (in[1] >> 4)); 27 | out[2] = (((in[1] & 0x0f) << 2) | (in[2] >> 6)); 28 | out[3] = (in[2] & 0x3f); 29 | 30 | out[0] += B64OFFSET; 31 | out[1] += B64OFFSET; 32 | out[2] += B64OFFSET; 33 | out[3] += B64OFFSET; 34 | 35 | // printf("%c %c %c %c %2x %2x %2x %2x %2x %2x %2x\n", out[0], out[1], out[2], out[3], out[0], out[1], out[2], out[3], in[0], in[1], in[2]); 36 | } 37 | 38 | /****************************************************************************** 39 | * Decode 4 '6-bit' characters into 3 '8-bit' binary bytes 40 | *******************************************************************************/ 41 | void decodeblock(unsigned char *in, unsigned char *out) 42 | { 43 | in[0] -= B64OFFSET; 44 | in[1] -= B64OFFSET; 45 | in[2] -= B64OFFSET; 46 | in[3] -= B64OFFSET; 47 | 48 | out[0] = (in[0] << 2 | in[1] >> 4); 49 | out[1] = (in[1] << 4 | in[2] >> 2); 50 | out[2] = (in[2] << 6 | in[3]); 51 | } 52 | 53 | 54 | /****************************************************************************** 55 | * This function encodes an input array of bytes into a base64 encoding. Memory 56 | * for the output array is assumed to have been allocated by the calling program 57 | * and be sufficiently large. The output string is NULL terminated. 58 | *******************************************************************************/ 59 | void GKEncodeBase64(int nbytes, unsigned char *inbuffer, unsigned char *outbuffer) 60 | { 61 | int i, j; 62 | 63 | if (nbytes%3 != 0) 64 | gk_errexit(SIGERR, "GKEncodeBase64: Input buffer size should be a multiple of 3! (%d)\n", nbytes); 65 | 66 | for (j=0, i=0; i 12 | 13 | /* Byte-wise swap two items of size SIZE. */ 14 | #define QSSWAP(a, b, stmp) do { stmp = (a); (a) = (b); (b) = stmp; } while (0) 15 | 16 | 17 | /****************************************************************************** 18 | * This function puts the 'topk' largest values in the beginning of the array 19 | *******************************************************************************/ 20 | int gk_dfkvkselect(int n, int topk, gk_fkv_t *cand) 21 | { 22 | int i, j, lo, hi, mid; 23 | gk_fkv_t pivot, stmp; 24 | 25 | if (n <= topk) 26 | return n; /* return if the array has fewer elements than we want */ 27 | 28 | for (lo=0, hi=n-1; hi-lo > 2;) { 29 | mid = lo + ((hi-lo) >> 1); 30 | 31 | /* select the pivot */ 32 | if (cand[mid].key > cand[lo].key) 33 | QSSWAP(cand[mid], cand[lo], stmp); 34 | if (cand[hi].key > cand[mid].key) 35 | QSSWAP(cand[mid], cand[hi], stmp); 36 | else 37 | goto jump_over; 38 | if (cand[mid].key > cand[lo].key) 39 | QSSWAP(cand[mid], cand[lo], stmp); 40 | 41 | jump_over:; 42 | pivot = cand[mid]; 43 | 44 | /* Here's the famous ``collapse the walls'' section of quicksort. */ 45 | for (i=lo+1, j=hi-1; i<=j;) { 46 | for (; cand[i].key > pivot.key; i++); 47 | for (; pivot.key > cand[j].key; j--); 48 | 49 | if (i < j) { 50 | QSSWAP (cand[i], cand[j], stmp); 51 | i++; 52 | j--; 53 | } 54 | else if (i == j) { 55 | i++; 56 | j--; 57 | } 58 | } 59 | 60 | if (i > topk) 61 | hi = i; 62 | else if (i < topk) 63 | lo = i; 64 | else 65 | break; 66 | } 67 | 68 | if (hi-lo == 2) { 69 | if (cand[lo].key < cand[lo+1].key) 70 | QSSWAP(cand[lo], cand[lo+1], stmp); 71 | } 72 | 73 | /* 74 | if (cand[lo].key < cand[hi].key) 75 | printf("Hmm Error: %d %d %d %f %f\n", i, lo, hi, cand[lo].key, cand[hi].key); 76 | 77 | 78 | for (i=topk; i cand[j].key) 81 | printf("Hmm Error: %d %d %f %f %d %d\n", i, j, cand[i].key, cand[j].key, lo, hi); 82 | } 83 | */ 84 | 85 | return topk; 86 | } 87 | -------------------------------------------------------------------------------- /RecastDemo/Contrib/metis/source/GKlib/trunk/gk_arch.h: -------------------------------------------------------------------------------- 1 | /*! 2 | \file gk_arch.h 3 | \brief This file contains various architecture-specific declerations 4 | 5 | \date Started 3/27/2007 6 | \author George 7 | \version\verbatim $Id: gk_arch.h 1430 2007-04-07 17:53:07Z karypis $ \endverbatim 8 | */ 9 | 10 | #ifndef _GK_ARCH_H_ 11 | #define _GK_ARCH_H_ 12 | 13 | /************************************************************************* 14 | * Architecture-specific differences in header files 15 | **************************************************************************/ 16 | #ifdef LINUX 17 | #if !defined(__USE_XOPEN) 18 | #define __USE_XOPEN 19 | #endif 20 | #if !defined(_XOPEN_SOURCE) 21 | #define _XOPEN_SOURCE 600 22 | #endif 23 | #if !defined(__USE_XOPEN2K) 24 | #define __USE_XOPEN2K 25 | #endif 26 | #include 27 | #endif 28 | 29 | 30 | #ifdef __MSC__ 31 | #include 32 | #else 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #endif 39 | 40 | 41 | 42 | /************************************************************************* 43 | * Architecture-specific modifications 44 | **************************************************************************/ 45 | #ifdef WIN32 46 | #define __thread __declspec( thread ) 47 | 48 | typedef __int32 int32_t; 49 | typedef __int64 int64_t; 50 | typedef unsigned __int32 uint32_t; 51 | typedef unsigned __int64 uint64_t; 52 | #endif 53 | 54 | 55 | #ifdef SUNOS 56 | #define __thread 57 | #endif 58 | 59 | 60 | #ifdef DARWIN 61 | #define __thread 62 | #endif 63 | 64 | 65 | #ifdef __MSC__ 66 | #define rint(x) ((int)((x)+0.5)) /* MSC does not have rint() function */ 67 | #endif 68 | 69 | 70 | #ifdef __GNUC__ 71 | #if !defined(strdup) 72 | extern char* strdup (const char *); 73 | #endif 74 | #endif 75 | 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /RecastDemo/Contrib/metis/source/GKlib/trunk/gk_defs.h: -------------------------------------------------------------------------------- 1 | /*! 2 | \file gk_defs.h 3 | \brief This file contains various constants definitions 4 | 5 | \date Started 3/27/2007 6 | \author George 7 | \version\verbatim $Id: gk_defs.h 1277 2007-03-27 21:17:33Z karypis $ \endverbatim 8 | */ 9 | 10 | #ifndef _GK_DEFS_H_ 11 | #define _GK_DEFS_H_ 12 | 13 | 14 | #define LTERM (void **) 0 /* List terminator for GKfree() */ 15 | 16 | #define HTABLE_EMPTY -1 17 | #define HTABLE_DELETED -2 18 | #define HTABLE_FIRST 1 19 | #define HTABLE_NEXT 2 20 | 21 | /* pdb corruption bit switches */ 22 | #define CRP_ALTLOCS 1 23 | #define CRP_MISSINGCA 2 24 | #define CRP_MISSINGBB 4 25 | #define CRP_MULTICHAIN 8 26 | #define CRP_MULTICA 16 27 | #define CRP_MULTIBB 32 28 | 29 | #define MAXLINELEN 300000 30 | 31 | /* custom signals */ 32 | #define SIGMEM SIGABRT 33 | #define SIGERR SIGABRT 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /RecastDemo/Contrib/metis/source/GKlib/trunk/gk_externs.h: -------------------------------------------------------------------------------- 1 | /*! 2 | \file gk_externs.h 3 | \brief This file contains definitions of external variables created by GKlib 4 | 5 | \date Started 3/27/2007 6 | \author George 7 | \version\verbatim $Id: gk_externs.h 1277 2007-03-27 21:17:33Z karypis $ \endverbatim 8 | */ 9 | 10 | #ifndef _GK_EXTERNS_H_ 11 | #define _GK_EXTERNS_H_ 12 | 13 | 14 | /************************************************************************* 15 | * Extern variable definition. Hopefully, the __thread makes them thread-safe. 16 | **************************************************************************/ 17 | #ifndef _GK_ERROR_C_ 18 | extern __thread jmp_buf gk_return_to_entry; /* declared in error.c */ 19 | #endif 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /RecastDemo/Contrib/metis/source/GKlib/trunk/gk_getopt.h: -------------------------------------------------------------------------------- 1 | /*! 2 | \file gk_getopt.h 3 | \brief This file contains GNU's externs/structs/prototypes 4 | 5 | \date Started 3/27/2007 6 | \author George 7 | \version\verbatim $Id: gk_getopt.h 1277 2007-03-27 21:17:33Z karypis $ \endverbatim 8 | */ 9 | 10 | #ifndef _GK_GETOPT_H_ 11 | #define _GK_GETOPT_H_ 12 | 13 | 14 | /* Externals from getopt.c */ 15 | extern char *gk_optarg; 16 | extern int gk_optind; 17 | extern int gk_opterr; 18 | extern int gk_optopt; 19 | 20 | 21 | /*! \brief The structure that stores the information about the command-line options 22 | 23 | This structure describes a single long option name for the sake of 24 | gk_getopt_long(). The argument long_options must be an array 25 | of these structures, one for each long option. Terminate the array with 26 | an element containing all zeros. 27 | */ 28 | struct gk_option { 29 | const char *name; /*!< This field is the name of the option. */ 30 | int has_arg; /*!< This field says whether the option takes an argument. 31 | It is an integer, and there are three legitimate values: 32 | no_argument, required_argument and optional_argument. 33 | 34 | \todo Need to better define/use the constants for this member 35 | variable. 36 | */ 37 | int *flag; /*!< See the discussion on ::gk_option#val */ 38 | int val; /*!< These fields control how to report or act on the option 39 | when it occurs. 40 | 41 | If flag is a null pointer, then the val is a value which 42 | identifies this option. Often these values are chosen 43 | to uniquely identify particular long options. 44 | 45 | If flag is not a null pointer, it should be the address 46 | of an int variable which is the flag for this option. 47 | The value in val is the value to store in the flag to 48 | indicate that the option was seen. */ 49 | }; 50 | 51 | /* Names for the values of the `has_arg' field of `struct gk_option'. */ 52 | #define no_argument 0 53 | #define required_argument 1 54 | #define optional_argument 2 55 | 56 | 57 | /* Function prototypes */ 58 | extern int gk_getopt(int __argc, char **__argv, const char *__shortopts); 59 | extern int gk_getopt_long(int __argc, char *const *__argv, const char *__shortopts, 60 | const struct gk_option *__longopts, int *__longind); 61 | extern int gk_getopt_long_only (int __argc, char *const *__argv, 62 | const char *__shortopts, const struct gk_option *__longopts, int *__longind); 63 | 64 | 65 | 66 | #endif 67 | 68 | -------------------------------------------------------------------------------- /RecastDemo/Contrib/metis/source/GKlib/trunk/gk_memory.h: -------------------------------------------------------------------------------- 1 | /*! 2 | \file gk_memory.h 3 | \brief This file contains GKlib's code generators for memory allocation routines 4 | 5 | \date Started 3/29/07 6 | \author George 7 | \version\verbatim $Id: gk_memory.h 1432 2007-04-07 20:06:19Z karypis $ \endverbatim 8 | */ 9 | 10 | #ifndef _GK_MEMORY_H_ 11 | #define _GK_MEMORY_H_ 12 | 13 | 14 | /*************************************************************************/ 15 | /*! The macro for gk_?malloc()-class of routines */ 16 | /**************************************************************************/ 17 | #define GK_XMALLOC(NAME, TYPE)\ 18 | TYPE *NAME(size_t n, char *msg)\ 19 | { return (TYPE *)gk_malloc(sizeof(TYPE)*n, msg); } 20 | 21 | #define GK_XMALLOC_PROTO(NAME, TYPE)\ 22 | TYPE *NAME(size_t n, char *msg); 23 | 24 | 25 | /*************************************************************************/ 26 | /*! The macro for gk_?realloc()-class of routines */ 27 | /**************************************************************************/ 28 | #define GK_XREALLOC(NAME, TYPE)\ 29 | TYPE *NAME(TYPE *ptr, size_t n, char *msg)\ 30 | { return (TYPE *)gk_realloc((void *)ptr, sizeof(TYPE)*n, msg); } 31 | 32 | #define GK_XREALLOC_PROTO(NAME, TYPE)\ 33 | TYPE *NAME(TYPE *ptr, size_t n, char *msg); 34 | 35 | 36 | /*************************************************************************/ 37 | /*! The macro for gk_?smalloc()-class of routines */ 38 | /**************************************************************************/ 39 | #define GK_XSMALLOC(NAME, TYPE, SET)\ 40 | TYPE *NAME(size_t n, TYPE ival, char *msg)\ 41 | { return SET(n, ival, (TYPE *)gk_malloc(sizeof(TYPE)*n, msg)); } 42 | 43 | #define GK_XSMALLOC_PROTO(NAME, TYPE)\ 44 | TYPE *NAME(size_t n, TYPE ival, char *msg); 45 | 46 | 47 | 48 | 49 | /*************************************************************************/ 50 | /*! The macro for gk_?AllocMatrix()-class of routines */ 51 | /**************************************************************************/ 52 | #define GK_ALLOCMATRIX(NAME, TYPE, ROWALLOC)\ 53 | TYPE **NAME(size_t ndim1, size_t ndim2, TYPE value, char *errmsg)\ 54 | {\ 55 | gk_loop_t i;\ 56 | TYPE **matrix;\ 57 | \ 58 | matrix = (TYPE **)gk_malloc(ndim1*sizeof(TYPE *), errmsg);\ 59 | for (i=0; i 14 | 15 | /************************************************************************* 16 | * This function opens a file 17 | **************************************************************************/ 18 | FILE *gk_fopen(char *fname, char *mode, const char *msg) 19 | { 20 | FILE *fp; 21 | char errmsg[8192]; 22 | 23 | fp = fopen(fname, mode); 24 | if (fp != NULL) 25 | return fp; 26 | 27 | sprintf(errmsg,"file: %s, mode: %s, [%s]", fname, mode, msg); 28 | perror(errmsg); 29 | errexit("Failed on gk_fopen()\n"); 30 | 31 | return NULL; 32 | } 33 | 34 | 35 | /************************************************************************* 36 | * This function closes a file 37 | **************************************************************************/ 38 | void gk_fclose(FILE *fp) 39 | { 40 | fclose(fp); 41 | } 42 | 43 | 44 | 45 | /************************************************************************* 46 | * This function is the GKlib implementation of glibc's getline() 47 | * function. 48 | **************************************************************************/ 49 | gk_loop_t gk_getline(char **lineptr, size_t *n, FILE *stream) 50 | { 51 | size_t i; 52 | int ch; 53 | 54 | if (feof(stream)) 55 | return -1; 56 | 57 | /* Initial memory allocation if *lineptr is NULL */ 58 | if (*lineptr == NULL || *n == 0) { 59 | *n = 1024; 60 | *lineptr = gk_malloc((*n)*sizeof(char), "gk_getline: lineptr"); 61 | } 62 | 63 | /* get into the main loop */ 64 | for (i = 0; (ch = getc(stream)) != EOF; i++) { 65 | (*lineptr)[i] = (char)ch; 66 | 67 | /* reallocate memory if reached at the end of the buffer. The +2 is for '\0' */ 68 | if (i+2 == *n) { 69 | *n = 2* (*n); 70 | *lineptr = gk_realloc(*lineptr, (*n)*sizeof(char), "gk_getline: lineptr"); 71 | } 72 | 73 | if (ch == '\n') 74 | break; 75 | } 76 | (*lineptr)[i+1] = '\0'; 77 | 78 | return i; 79 | } 80 | 81 | -------------------------------------------------------------------------------- /RecastDemo/Contrib/metis/source/GKlib/trunk/omp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997, Regents of the University of Minnesota 3 | * 4 | * omp.c 5 | * 6 | * This file contains "fake" implementations of OpenMP's runtime libraries 7 | * 8 | */ 9 | 10 | #include 11 | 12 | #if !defined(__OPENMP__) 13 | void omp_set_num_threads(int num_threads) { return; } 14 | int omp_get_num_threads(void) { return 1; } 15 | int omp_get_max_threads(void) { return 1; } 16 | int omp_get_thread_num(void) { return 1; } 17 | int omp_get_num_procs(void) { return 1; } 18 | int omp_in_parallel(void) { return 0; } 19 | void omp_set_dynamic(int num_threads) { return; } 20 | int omp_get_dynamic(void) { return 0; } 21 | void omp_set_nested(int nested) { return; } 22 | int omp_get_nested(void) { return 0; } 23 | #endif 24 | 25 | 26 | -------------------------------------------------------------------------------- /RecastDemo/Contrib/metis/source/GKlib/trunk/test/Makefile: -------------------------------------------------------------------------------- 1 | include Makefile.in 2 | 3 | STRINGSOBJS = $(PRGBUILDDIR)/strings$(OBJEXT) 4 | GKSORTOBJS = $(PRGBUILDDIR)/gksort$(OBJEXT) 5 | 6 | HEADERS = $(wildcard $(GKLIBINCDIR)/*.h) 7 | 8 | 9 | default: $(BUILDDIR)/strings$(EXEEXT) $(BUILDDIR)/gksort$(EXEEXT) 10 | 11 | 12 | $(BUILDDIR)/strings$(EXEEXT): $(STRINGSOBJS) $(GKLIBBUILDDIR)/libGKlib.a 13 | $(LD) $(LDOPTIONS) $(EXEOUTPUTFILE) $(STRINGSOBJS) $(LIBSDIR) $(LIBS) ; $(MERGEMANIFEST) 14 | chmod 744 $@ 15 | 16 | $(BUILDDIR)/gksort$(EXEEXT): $(GKSORTOBJS) $(GKLIBBUILDDIR)/libGKlib.a 17 | $(LD) $(LDOPTIONS) $(EXEOUTPUTFILE) $(GKSORTOBJS) $(LIBSDIR) $(LIBS) ; $(MERGEMANIFEST) 18 | chmod 744 $@ 19 | 20 | 21 | clean: 22 | rm -rf $(PRGBUILDDIR) 23 | 24 | realclean: 25 | rm -rf $(PRGBUILDDIR) ;\ 26 | rm -rf $(BUILDDIR) ; 27 | 28 | 29 | $(STRINGSOBJS) : $(HEADERS) Makefile.in Makefile $(GKLIBBUILDDIR)/libGKlib.a 30 | 31 | 32 | $(PRGBUILDDIR)/%$(OBJEXT) : %.c 33 | $(CC) $(CFLAGS) $(SOURCEFILE) $(OUTPUTFILE) 34 | 35 | -------------------------------------------------------------------------------- /RecastDemo/Contrib/metis/source/GKlib/trunk/test/strings.c: -------------------------------------------------------------------------------- 1 | /*! 2 | \file strings.c 3 | \brief Testing module for the string functions in GKlib 4 | 5 | \date Started 3/5/2007 6 | \author George 7 | \version\verbatim $Id: strings.c 1413 2007-04-05 02:43:48Z karypis $ \endverbatim 8 | */ 9 | 10 | #include 11 | 12 | 13 | /*************************************************************************/ 14 | /*! Testing module for gk_strstr_replace() */ 15 | /*************************************************************************/ 16 | void test_strstr_replace() 17 | { 18 | char *new_str; 19 | int rc; 20 | 21 | rc = gk_strstr_replace("This is a simple string", "s", "S", "", &new_str); 22 | printf("%d, %s.\n", rc, new_str); 23 | gk_free((void **)&new_str, LTERM); 24 | 25 | 26 | rc = gk_strstr_replace("This is a simple string", "s", "S", "g", &new_str); 27 | printf("%d, %s.\n", rc, new_str); 28 | gk_free((void **)&new_str, LTERM); 29 | 30 | 31 | rc = gk_strstr_replace("This is a simple SS & ss string", "s", "T", "g", &new_str); 32 | printf("%d, %s.\n", rc, new_str); 33 | gk_free((void **)&new_str, LTERM); 34 | 35 | 36 | rc = gk_strstr_replace("This is a simple SS & ss string", "s", "T", "ig", &new_str); 37 | printf("%d, %s.\n", rc, new_str); 38 | gk_free((void **)&new_str, LTERM); 39 | 40 | rc = gk_strstr_replace("This is a simple SS & ss string", "\\b\\w(\\w+)\\w\\b", "$1", "ig", &new_str); 41 | printf("%d, %s.\n", rc, new_str); 42 | gk_free((void **)&new_str, LTERM); 43 | 44 | rc = gk_strstr_replace("This is a simple SS & ss string", "\\b\\w+\\b", "word", "ig", &new_str); 45 | printf("%d, %s.\n", rc, new_str); 46 | gk_free((void **)&new_str, LTERM); 47 | 48 | rc = gk_strstr_replace("http://www.cs.umn.edu/This-is-something-T12323?pp=20&page=4", 49 | "(http://www\\.cs\\.umn\\.edu/)(.*)-T(\\d+)", "$1$2-P$3", "g", &new_str); 50 | printf("%d, %s.\n", rc, new_str); 51 | gk_free((void **)&new_str, LTERM); 52 | 53 | rc = gk_strstr_replace("http://www.cs.umn.edu/This-is-something-T12323?pp=20&page=4", 54 | "(\\d+)", "number:$1", "ig", &new_str); 55 | printf("%d, %s.\n", rc, new_str); 56 | gk_free((void **)&new_str, LTERM); 57 | 58 | 59 | rc = gk_strstr_replace("http://www.cs.umn.edu/This-is-something-T12323?pp=20&page=4", 60 | "(http://www\\.cs\\.umn\\.edu/)", "[$1]", "g", &new_str); 61 | printf("%d, %s.\n", rc, new_str); 62 | gk_free((void **)&new_str, LTERM); 63 | 64 | 65 | 66 | } 67 | 68 | 69 | 70 | int main() 71 | { 72 | test_strstr_replace(); 73 | 74 | /* 75 | { 76 | int i; 77 | for (i=0; i<1000; i++) 78 | printf("%d\n", RandomInRange(3)); 79 | } 80 | */ 81 | } 82 | 83 | -------------------------------------------------------------------------------- /RecastDemo/Contrib/metis/source/GKlib/trunk/timers.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997, Regents of the University of Minnesota 3 | * 4 | * time.c 5 | * 6 | * This file contains various functions that do with time 7 | * 8 | * $Id: timers.c 934 2007-02-21 18:31:42Z karypis $ 9 | * 10 | */ 11 | 12 | #include 13 | 14 | 15 | 16 | 17 | /************************************************************************* 18 | * This function returns the CPU seconds 19 | **************************************************************************/ 20 | gk_wclock_t gk_WClockSeconds(void) 21 | { 22 | return time(NULL); 23 | } 24 | 25 | 26 | /************************************************************************* 27 | * This function returns the CPU seconds 28 | **************************************************************************/ 29 | double gk_CPUSeconds(void) 30 | { 31 | #ifdef __OPENMP__ 32 | return omp_get_wtime(); 33 | #else 34 | #ifdef WIN32 35 | return((double) clock()/CLOCKS_PER_SEC); 36 | #else 37 | struct rusage r; 38 | 39 | getrusage(RUSAGE_SELF, &r); 40 | return ((r.ru_utime.tv_sec + r.ru_stime.tv_sec) + 1.0e-6*(r.ru_utime.tv_usec + r.ru_stime.tv_usec)); 41 | #endif 42 | #endif 43 | } 44 | 45 | -------------------------------------------------------------------------------- /RecastDemo/Contrib/metis/source/GKlib/trunk/tokenizer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * tokenizer.c 3 | * 4 | * This file contains various routines for splitting an input string into 5 | * tokens and returning them in form of a list. The goal is to mimic 6 | * perl's split function 7 | * 8 | * Started 11/23/04 9 | * George 10 | * 11 | * $Id: tokenizer.c 1414 2007-04-05 02:52:46Z karypis $ 12 | * 13 | */ 14 | 15 | #include 16 | 17 | 18 | /************************************************************************ 19 | * This function tokenizes a string based on the user-supplied delimiters 20 | * list. The resulting tokens are returned into an array of strings. 21 | *************************************************************************/ 22 | void gk_strtokenize(char *str, char *delim, gk_Tokens_t *tokens) 23 | { 24 | int i, ntoks, slen; 25 | 26 | tokens->strbuf = gk_strdup(str); 27 | 28 | slen = strlen(str); 29 | str = tokens->strbuf; 30 | 31 | /* Scan once to determine the number of tokens */ 32 | for (ntoks=0, i=0; intoks = ntoks; 49 | tokens->list = (char **)gk_malloc(ntoks*sizeof(char *), "strtokenize: tokens->list"); 50 | 51 | 52 | /* Scan a second time to mark and link the tokens */ 53 | for (ntoks=0, i=0; ilist[ntoks++] = str+i; 62 | 63 | /* Consume all the consecutive characters from the token */ 64 | while (ilist, &tokens->strbuf, LTERM); 76 | } 77 | 78 | -------------------------------------------------------------------------------- /RecastDemo/Contrib/metis/source/GKlib/trunk/util.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997, Regents of the University of Minnesota 3 | * 4 | * util.c 5 | * 6 | * This file contains utility functions 7 | * 8 | * $Id: util.c 1421 2007-04-06 14:37:41Z karypis $ 9 | * 10 | */ 11 | 12 | #include 13 | 14 | 15 | 16 | /************************************************************************* 17 | * This file randomly permutes the contents of an array. 18 | * flag == 0, don't initialize perm 19 | * flag == 1, set p[i] = i 20 | **************************************************************************/ 21 | void gk_RandomPermute(size_t n, int *p, int flag) 22 | { 23 | gk_idx_t i, u, v; 24 | int tmp; 25 | 26 | if (flag == 1) { 27 | for (i=0; i 1; i++, a = a>>1); 75 | return i-1; 76 | } 77 | 78 | 79 | /************************************************************************* 80 | * This function checks if the argument is a power of 2 81 | **************************************************************************/ 82 | int gk_ispow2(int a) 83 | { 84 | return (a == (1< directory where is 12 | the name of the system on which your are building METIS. 13 | 14 | ***Important*** 15 | Make sure that you look at include/metis.h and change any of the 16 | parameters based on your target system and desired built. 17 | 18 | make clean 19 | Removes all object files that were generated as part of the build process 20 | but it will leave the built libraries and stand-alone programs intact. 21 | 22 | make realclean 23 | Removes both object files as well as libraries and stand-alone programs. 24 | 25 | 26 | The build system detects Linux, cygwin, SunOS, & Darwin systems. In the case 27 | of cygwin, it actually builds a MS Windows set of libraries and executables 28 | using Visual Studio 2005, using the command-line interface to the VC++ compiler 29 | (make sure that 'cl' is on the path). 30 | 31 | On any other system, the Makefiles default to using the cc compiler. If you 32 | want to build METIS using another compiler you can do that by setting the 'CC' 33 | variable on the command line. For example, 'make "CC=icc" all' will build 34 | METIS using the icc (intel's) compiler. 35 | 36 | In addition to 'CC' you can also set the following variables that are used by 37 | the build system: 38 | OPTFLAGS Specifies optimization parameters (e.g., -O3) 39 | CFLAGS Specifies compiler-specific arguments. If you decide to specify 40 | this, make sure that you also provide -DUNIX as one of the 41 | options (e.g., "CFLAGS=-DUNIX -Wall"). 42 | LD Specifies the linker. Defaults to CC. 43 | LDOPTIONS Specifies any options to be passed to the linker. 44 | 45 | Finally, the Makefiles understand the following variables, which are used for 46 | now only for development purposes: 47 | useopenmp=1 Specifies if OpenMP will be used. 48 | usegdb=1 Specifies that everything will be build with -g option. 49 | withdebug=1 Turns on internal error and assertion checking. 50 | ------------------------------------------------------------------------------- 51 | -------------------------------------------------------------------------------- /RecastDemo/Contrib/metis/source/config/config.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef CONFIG_H 3 | #define CONFIG_H 1 4 | 5 | /**************************************************************************** 6 | * A set of defines that can be modified by the user 7 | *****************************************************************************/ 8 | /*-------------------------------------------------------------------------- 9 | Specifies the width of the elementary data type that will hold information 10 | about vertices and their adjacency lists. 11 | 12 | Possible values: 13 | 32 : Use 32 bit signed integers 14 | 64 : Use 64 bit signed integers 15 | 16 | A width of 64 should be specified if the number of vertices or the total 17 | number of edges in the graph exceed the limits of a 32 bit signed integer 18 | i.e., 2^31-1. 19 | Proper use of 64 bit integers requires that the c99 standard datatypes 20 | int32_t and int64_t are supported by the compiler. 21 | GCC does provides these definitions in stdint.h, but it may require some 22 | modifications on other architectures. 23 | --------------------------------------------------------------------------*/ 24 | #define IDXTYPEWIDTH 32 25 | 26 | 27 | /*-------------------------------------------------------------------------- 28 | Specifies if the __thread storage directive is available by the compiler 29 | to indicate thread local storage. This storage directive is available in 30 | most systems using gcc compiler but it may not be available in other 31 | systems. 32 | 33 | Possible values: 34 | 0 : Not available and do not use thread local storage 35 | 1 : It is available and the __thread modifier will be used 36 | --------------------------------------------------------------------------*/ 37 | #define HAVE_THREADLOCALSTORAGE 0 38 | 39 | 40 | 41 | 42 | /**************************************************************************** 43 | * Do not change anything bellow this point 44 | *****************************************************************************/ 45 | /* Uniform defines for various compilers */ 46 | #if defined(_MSC_VER) 47 | #define COMPILER_MSC 48 | #endif 49 | #if defined(__ICC) 50 | #define COMPILER_ICC 51 | #endif 52 | #if defined(__GNUC__) 53 | #define COMPILER_GCC 54 | #endif 55 | 56 | 57 | #if defined(COMPILER_GCC) 58 | #include 59 | #endif 60 | 61 | 62 | #if defined(COMPILER_MSC) 63 | #include 64 | #define __thread __declspec( thread ) 65 | 66 | typedef __int32 int32_t; 67 | typedef __int64 int64_t; 68 | typedef unsigned __int32 uint32_t; 69 | typedef unsigned __int64 uint64_t; 70 | #endif 71 | 72 | 73 | #if defined(UNIX) 74 | #include 75 | #include 76 | #include 77 | #endif 78 | 79 | #if defined(ENABLE_OPENMP) 80 | #include 81 | #endif 82 | 83 | 84 | #endif /* CONFIG_H */ 85 | -------------------------------------------------------------------------------- /RecastDemo/Contrib/metis/source/graphs/README: -------------------------------------------------------------------------------- 1 | 2 | This file contains some test graphs and meshes 3 | 4 | 4elt.graph 5 | copter2.graph 6 | mdual.graph 7 | These are small to medium size graphs corresponding to 2D and 3D 8 | finite element mesh 9 | 10 | test.mgraph 11 | This is a very small graph with two vertex weights (multi-constraint) 12 | 13 | metis.mesh 14 | This is a small 2D mesh (It is a triangulation of 'METIS') 15 | 16 | 17 | You can use them to test the various partitioning, and ordering routines. 18 | For example try something like 19 | 20 | ../build/ARCH/kmetis 4elt.graph 40 21 | ../build/ARCH/onmetis 4elt.graph 22 | ../build/ARCH/pmetis test.mgraph 2 23 | ../build/ARCH/kmetis test.mgraph 2 24 | ../build/ARCH/kmetis test.mgraph 5 25 | ../build/ARCH/partnmesh metis.mesh 10 26 | ../build/ARCH/partdmesh metis.mesh 10 27 | ../build/ARCH/mesh2dual metis.mesh 28 | ../build/ARCH/kmetis metis.mesh.dgraph 10 29 | 30 | and so on... 31 | 32 | 33 | You can also use the 'mtest' program that tests the various partitioning 34 | routines. Here is how the correct output of 'mtest 4elt.graph' should 35 | look like. 36 | 37 | prompt%: mtest 4elt.graph 38 | ********************************************************************** 39 | METIS 4.0 Copyright 1998, Regents of the University of Minnesota 40 | 41 | Graph Information --------------------------------------------------- 42 | Name: 4elt.graph, #Vertices: 15606, #Edges: 45878 43 | 44 | Testing METIS_PartGraphRecursive ------------------------------------ 45 | [1:ok][2:ok][3:ok][4:ok][5:ok][6:ok] 46 | 47 | Testing METIS_WPartGraphRecursive ----------------------------------- 48 | [1:ok][2:ok][3:ok][4:ok][5:ok][6:ok] 49 | 50 | Testing METIS_PartGraphKway ----------------------------------------- 51 | [1:ok][2:ok][3:ok][4:ok][5:ok][6:ok][7:ok][8:ok] 52 | 53 | Testing METIS_WPartGraphKway ---------------------------------------- 54 | [1:ok][2:ok][3:ok][4:ok][5:ok][6:ok][7:ok][8:ok] 55 | 56 | Testing METIS_PartGraphVKway ---------------------------------------- 57 | [1:ok][2:ok][3:ok][4:ok][5:ok][6:ok][7:ok] 58 | 59 | Testing METIS_WPartGraphVKway --------------------------------------- 60 | [1:ok][2:ok][3:ok][4:ok][5:ok][6:ok][7:ok] 61 | 62 | Testing METIS_mCPartGraphRecursive ---------------------------------- 63 | [1:ok][2:ok][3:ok][4:ok][5:ok][6:ok][7:ok][8:ok][9:ok][10:ok] 64 | [11:ok][12:ok] 65 | 66 | Testing METIS_mCPartGraphKway --------------------------------------- 67 | [1:ok][2:ok][3:ok][4:ok][5:ok][6:ok][7:ok][8:ok][9:ok][10:ok] 68 | [11:ok][12:ok][13:ok][14:ok] 69 | 70 | Testing METIS_EdgeND ------------------------------------------------ 71 | [1:ok][2:ok][3:ok] 72 | 73 | Testing METIS_NodeND ------------------------------------------------ 74 | [1:ok][2:ok][3:ok][4:ok][5:ok][6:ok][7:ok][8:ok][9:ok][10:ok] 75 | [11:ok][12:ok][13:ok] 76 | 77 | Testing METIS_NodeWND ----------------------------------------------- 78 | [1:ok][2:ok][3:ok][4:ok][5:ok][6:ok] 79 | 80 | --------------------------------------------------------------------- 81 | Testing completed. 82 | ********************************************************************** 83 | 84 | 85 | -------------------------------------------------------------------------------- /RecastDemo/Contrib/metis/source/libmetis/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.in 2 | 3 | CURBUILDDIR = $(LIBBUILDDIR) 4 | 5 | OBJS = $(patsubst %.c, $(CURBUILDDIR)/%$(OBJEXT), $(wildcard *.c)) 6 | HEADERS = $(wildcard *.h) $(TOPDIR)/include/metis.h $(wildcard $(GKLIBINCDIR)/*.h) 7 | 8 | GKLIBOBJS = $(wildcard $(GKLIBBUILDDIR)/*$(OBJEXT)) 9 | 10 | $(BUILDDIR)/libmetis$(LIBEXT): $(OBJS) $(GKLIBOBJS) 11 | $(AR) $(OBJS) $(GKLIBOBJS) 12 | $(RANLIB) 13 | 14 | clean: 15 | rm -f $(OBJS) 16 | 17 | realclean: 18 | rm -f $(OBJS) ; rm -f $(BUILDDIR)/libmetis$(LIBEXT) 19 | 20 | dist: 21 | mkdir $(TOPDIR)/../$(PKGNAME) ;\ 22 | cp -r $(TOPDIR)/* $(TOPDIR)/../$(PKGNAME) ;\ 23 | tar -C $(TOPDIR)/../ --exclude=.svn -czf $(TOPDIR)/$(PKGNAME).tar.gz $(PKGNAME);\ 24 | rm -rf $(TOPDIR)/../$(PKGNAME) 25 | 26 | $(OBJS) : $(HEADERS) ../Makefile.in Makefile 27 | 28 | 29 | $(CURBUILDDIR)/%$(OBJEXT) : %.c 30 | $(CC) $(CFLAGS) $(SOURCEFILE) $(OUTPUTFILE) 31 | -------------------------------------------------------------------------------- /RecastDemo/Contrib/metis/source/libmetis/bucketsort.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997, Regents of the University of Minnesota 3 | * 4 | * bucketsort.c 5 | * 6 | * This file contains code that implement a variety of counting sorting 7 | * algorithms 8 | * 9 | * Started 7/25/97 10 | * George 11 | * 12 | */ 13 | 14 | #include 15 | 16 | 17 | 18 | /************************************************************************* 19 | * This function uses simple counting sort to return a permutation array 20 | * corresponding to the sorted order. The keys are agk_fsumed to start from 21 | * 0 and they are positive. This sorting is used during matching. 22 | **************************************************************************/ 23 | void BucketSortKeysInc(idxtype n, idxtype max, idxtype *keys, idxtype *tperm, idxtype *perm) 24 | { 25 | idxtype i, ii; 26 | idxtype *counts; 27 | 28 | counts = idxsmalloc(max+2, 0, "BucketSortKeysInc: counts"); 29 | 30 | for (i=0; i 14 | 15 | 16 | 17 | /************************************************************************* 18 | * This function checks if a graph is valid 19 | **************************************************************************/ 20 | idxtype CheckGraph(GraphType *graph) 21 | { 22 | idxtype i, j, k, l; 23 | idxtype nvtxs, ncon, err=0; 24 | idxtype minedge, maxedge, minewgt, maxewgt; 25 | float minvwgt[MAXNCON], maxvwgt[MAXNCON]; 26 | idxtype *xadj, *adjncy, *adjwgt, *htable; 27 | float *nvwgt, ntvwgts[MAXNCON]; 28 | 29 | nvtxs = graph->nvtxs; 30 | ncon = graph->ncon; 31 | xadj = graph->xadj; 32 | nvwgt = graph->nvwgt; 33 | adjncy = graph->adjncy; 34 | adjwgt = graph->adjwgt; 35 | 36 | htable = idxsmalloc(nvtxs, 0, "htable"); 37 | 38 | if (ncon > 1) { 39 | for (j=0; j 1) { 50 | for (j=0; j maxvwgt[j]) ? nvwgt[i*ncon+j] : maxvwgt[j]; 54 | } 55 | } 56 | 57 | for (j=xadj[i]; j maxedge) ? k : maxedge; 62 | minewgt = (adjwgt[j] < minewgt) ? adjwgt[j] : minewgt; 63 | maxewgt = (adjwgt[j] > maxewgt) ? adjwgt[j] : maxewgt; 64 | 65 | if (i == k) { 66 | mprintf("Vertex %D contains a self-loop (i.e., diagonal entry in the matrix)!\n", i); 67 | err++; 68 | } 69 | else { 70 | for (l=xadj[k]; l 1) { 100 | for (j=0; j 0.0001) { 102 | mprintf("Normalized vwgts don't sum to one. Weight %D = %.8f.\n", j, ntvwgts[j]); 103 | err++; 104 | } 105 | } 106 | } 107 | 108 | /* 109 | mprintf("errs: %D, adjncy: [%D %D], adjwgt: [%D %D]\n", 110 | err, minedge, maxedge, minewgt, maxewgt); 111 | if (ncon > 1) { 112 | for (j=0; j 0) { 119 | mprintf("A total of %D errors exist in the input file. Correct them, and run again!\n", err); 120 | } 121 | 122 | gk_free((void **)&htable, LTERM); 123 | return (err == 0 ? 1 : 0); 124 | } 125 | 126 | -------------------------------------------------------------------------------- /RecastDemo/Contrib/metis/source/libmetis/coarsen.c: -------------------------------------------------------------------------------- 1 | /* 2 | * coarsen.c 3 | * 4 | * This file contains the driving routines for the coarsening process 5 | * 6 | * Started 7/23/97 7 | * George 8 | * 9 | */ 10 | 11 | #include 12 | 13 | 14 | /************************************************************************* 15 | * This function takes a graph and creates a sequence of coarser graphs 16 | **************************************************************************/ 17 | GraphType *Coarsen2Way(CtrlType *ctrl, GraphType *graph) 18 | { 19 | idxtype clevel; 20 | GraphType *cgraph; 21 | 22 | IFSET(ctrl->dbglvl, DBG_TIME, gk_startcputimer(ctrl->CoarsenTmr)); 23 | 24 | cgraph = graph; 25 | 26 | /* The following is ahack to allow the multiple bisections to go through with correct 27 | coarsening */ 28 | if (ctrl->CType > 20) { 29 | clevel = 1; 30 | ctrl->CType -= 20; 31 | } 32 | else 33 | clevel = 0; 34 | 35 | do { 36 | IFSET(ctrl->dbglvl, DBG_COARSEN, mprintf("%6D %7D %7D [%D] [%D %D]\n", 37 | cgraph->nvtxs, cgraph->nedges/2, idxsum(cgraph->nvtxs, cgraph->adjwgtsum, 1)/2, 38 | ctrl->CoarsenTo, ctrl->maxvwgt, 39 | (cgraph->vwgt ? idxsum(cgraph->nvtxs, cgraph->vwgt, 1) : cgraph->nvtxs))); 40 | 41 | if (cgraph->adjwgt) { 42 | switch (ctrl->CType) { 43 | case MTYPE_RM: 44 | Match_RM(ctrl, cgraph); 45 | break; 46 | case MTYPE_HEM: 47 | if (clevel < 1 || cgraph->nedges == 0) 48 | Match_RM(ctrl, cgraph); 49 | else 50 | Match_HEM(ctrl, cgraph); 51 | break; 52 | case MTYPE_SHEM: 53 | if (clevel < 1 || cgraph->nedges == 0) 54 | Match_RM(ctrl, cgraph); 55 | else 56 | Match_SHEM(ctrl, cgraph); 57 | break; 58 | case MTYPE_SHEMKWAY: 59 | if (cgraph->nedges == 0) 60 | Match_RM(ctrl, cgraph); 61 | else 62 | Match_SHEM(ctrl, cgraph); 63 | break; 64 | default: 65 | errexit("Unknown CType: %d\n", ctrl->CType); 66 | } 67 | } 68 | else { 69 | Match_RM_NVW(ctrl, cgraph); 70 | } 71 | 72 | cgraph = cgraph->coarser; 73 | clevel++; 74 | 75 | } while (cgraph->nvtxs > ctrl->CoarsenTo && cgraph->nvtxs < COARSEN_FRACTION2*cgraph->finer->nvtxs && cgraph->nedges > cgraph->nvtxs/2); 76 | 77 | IFSET(ctrl->dbglvl, DBG_COARSEN, mprintf("%6D %7D %7D [%D] [%D %D]\n", 78 | cgraph->nvtxs, cgraph->nedges/2, idxsum(cgraph->nvtxs, cgraph->adjwgtsum, 1)/2, 79 | ctrl->CoarsenTo, ctrl->maxvwgt, 80 | (cgraph->vwgt ? idxsum(cgraph->nvtxs, cgraph->vwgt, 1) : cgraph->nvtxs))); 81 | 82 | IFSET(ctrl->dbglvl, DBG_TIME, gk_stopcputimer(ctrl->CoarsenTmr)); 83 | 84 | return cgraph; 85 | } 86 | 87 | -------------------------------------------------------------------------------- /RecastDemo/Contrib/metis/source/libmetis/macros.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997, Regents of the University of Minnesota 3 | * 4 | * macros.h 5 | * 6 | * This file contains macros used in multilevel 7 | * 8 | * Started 9/25/94 9 | * George 10 | * 11 | * $Id: macros.h,v 1.6 2003/04/30 12:42:05 karypis Exp $ 12 | * 13 | */ 14 | 15 | 16 | /************************************************************************* 17 | * The following macro returns a random number in the specified range 18 | **************************************************************************/ 19 | #define AND(a, b) ((a) < 0 ? ((-(a))&(b)) : ((a)&(b))) 20 | #define OR(a, b) ((a) < 0 ? -((-(a))|(b)) : ((a)|(b))) 21 | #define XOR(a, b) ((a) < 0 ? -((-(a))^(b)) : ((a)^(b))) 22 | 23 | #define idxcopy(n, a, b) (idxtype *)memcpy((void *)(b), (void *)(a), sizeof(idxtype)*(n)) 24 | 25 | #define HASHFCT(key, size) ((key)%(size)) 26 | 27 | 28 | /************************************************************************* 29 | * Datatype related macros 30 | **************************************************************************/ 31 | #define idxtype_abs(x) ((x) > 0 ? (x) : -(x)) 32 | 33 | 34 | 35 | 36 | 37 | /************************************************************************* 38 | * These macros insert and remove nodes from the boundary list 39 | **************************************************************************/ 40 | #define BNDInsert(nbnd, bndind, bndptr, vtx) \ 41 | do { \ 42 | ASSERT(bndptr[vtx] == -1); \ 43 | bndind[nbnd] = vtx; \ 44 | bndptr[vtx] = nbnd++;\ 45 | } while(0) 46 | 47 | #define BNDDelete(nbnd, bndind, bndptr, vtx) \ 48 | do { \ 49 | ASSERT(bndptr[vtx] != -1); \ 50 | bndind[bndptr[vtx]] = bndind[--nbnd]; \ 51 | bndptr[bndind[nbnd]] = bndptr[vtx]; \ 52 | bndptr[vtx] = -1; \ 53 | } while(0) 54 | 55 | 56 | -------------------------------------------------------------------------------- /RecastDemo/Contrib/metis/source/libmetis/mcoarsen.c: -------------------------------------------------------------------------------- 1 | /* 2 | * mcoarsen.c 3 | * 4 | * This file contains the driving routines for the coarsening process 5 | * 6 | * Started 7/23/97 7 | * George 8 | * 9 | * $Id: mcoarsen.c,v 1.3 2003/07/31 15:52:47 karypis Exp $ 10 | * 11 | */ 12 | 13 | #include 14 | 15 | 16 | /************************************************************************* 17 | * This function takes a graph and creates a sequence of coarser graphs 18 | **************************************************************************/ 19 | GraphType *MCCoarsen2Way(CtrlType *ctrl, GraphType *graph) 20 | { 21 | idxtype i, clevel; 22 | GraphType *cgraph; 23 | 24 | IFSET(ctrl->dbglvl, DBG_TIME, gk_startcputimer(ctrl->CoarsenTmr)); 25 | 26 | cgraph = graph; 27 | 28 | clevel = 0; 29 | do { 30 | if (ctrl->dbglvl&DBG_COARSEN) { 31 | mprintf("%6D %7D %10D [%D] [%6.4f", cgraph->nvtxs, cgraph->nedges, 32 | idxsum(cgraph->nvtxs, cgraph->adjwgtsum, 1), ctrl->CoarsenTo, ctrl->nmaxvwgt); 33 | for (i=0; incon; i++) 34 | mprintf(" %5.3f", gk_fsum(cgraph->nvtxs, cgraph->nvwgt+i, cgraph->ncon)); 35 | mprintf("]\n"); 36 | } 37 | 38 | if (cgraph->nedges == 0) { 39 | MCMatch_RM(ctrl, cgraph); 40 | } 41 | else { 42 | switch (ctrl->CType) { 43 | case MTYPE_RM: 44 | MCMatch_RM(ctrl, cgraph); 45 | break; 46 | case MTYPE_HEM: 47 | if (clevel < 1) 48 | MCMatch_RM(ctrl, cgraph); 49 | else 50 | MCMatch_HEM(ctrl, cgraph); 51 | break; 52 | case MTYPE_SHEM: 53 | if (clevel < 1) 54 | MCMatch_RM(ctrl, cgraph); 55 | else 56 | MCMatch_SHEM(ctrl, cgraph); 57 | break; 58 | case MTYPE_SHEMKWAY: 59 | MCMatch_SHEM(ctrl, cgraph); 60 | break; 61 | case MTYPE_SHEBM_ONENORM: 62 | MCMatch_SHEBM(ctrl, cgraph, 1); 63 | break; 64 | case MTYPE_SHEBM_INFNORM: 65 | MCMatch_SHEBM(ctrl, cgraph, -1); 66 | break; 67 | case MTYPE_SBHEM_ONENORM: 68 | MCMatch_SBHEM(ctrl, cgraph, 1); 69 | break; 70 | case MTYPE_SBHEM_INFNORM: 71 | MCMatch_SBHEM(ctrl, cgraph, -1); 72 | break; 73 | default: 74 | errexit("Unknown CType: %d\n", ctrl->CType); 75 | } 76 | } 77 | 78 | cgraph = cgraph->coarser; 79 | clevel++; 80 | 81 | } while (cgraph->nvtxs > ctrl->CoarsenTo && cgraph->nvtxs < COARSEN_FRACTION2*cgraph->finer->nvtxs && cgraph->nedges > cgraph->nvtxs/2); 82 | 83 | if (ctrl->dbglvl&DBG_COARSEN) { 84 | mprintf("%6D %7D %10D [%D] [%6.4f", cgraph->nvtxs, cgraph->nedges, 85 | idxsum(cgraph->nvtxs, cgraph->adjwgtsum, 1), ctrl->CoarsenTo, ctrl->nmaxvwgt); 86 | for (i=0; incon; i++) 87 | mprintf(" %5.3f", gk_fsum(cgraph->nvtxs, cgraph->nvwgt+i, cgraph->ncon)); 88 | mprintf("]\n"); 89 | } 90 | 91 | 92 | IFSET(ctrl->dbglvl, DBG_TIME, gk_stopcputimer(ctrl->CoarsenTmr)); 93 | 94 | return cgraph; 95 | } 96 | 97 | -------------------------------------------------------------------------------- /RecastDemo/Contrib/metis/source/libmetis/metislib.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997, Regents of the University of Minnesota 3 | * 4 | * metis.h 5 | * 6 | * This file includes all necessary header files 7 | * 8 | * Started 8/27/94 9 | * George 10 | * 11 | * $Id: metislib.h,v 1.1 2002/08/10 06:29:31 karypis Exp $ 12 | */ 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #if defined(ENABLE_OPENMP) 29 | #include 30 | #endif 31 | 32 | 33 | #include 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | 42 | #if defined(COMPILER_MSC) 43 | #define rint(x) ((idxtype)((x)+0.5)) /* MSC does not have rint() function */ 44 | #endif 45 | 46 | 47 | #if defined(COMPILER_GCC) 48 | extern char* strdup (const char *); 49 | #endif 50 | 51 | -------------------------------------------------------------------------------- /RecastDemo/Contrib/metis/source/libmetis/mrefine2.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997, Regents of the University of Minnesota 3 | * 4 | * mrefine2.c 5 | * 6 | * This file contains the driving routines for multilevel refinement 7 | * 8 | * Started 7/24/97 9 | * George 10 | * 11 | * $Id: mrefine2.c,v 1.2 2002/08/10 06:29:33 karypis Exp $ 12 | */ 13 | 14 | #include 15 | 16 | 17 | /************************************************************************* 18 | * This function is the entry point of refinement 19 | **************************************************************************/ 20 | void MocRefine2Way2(CtrlType *ctrl, GraphType *orggraph, GraphType *graph, float *tpwgts, 21 | float *ubvec) 22 | { 23 | 24 | IFSET(ctrl->dbglvl, DBG_TIME, gk_startcputimer(ctrl->UncoarsenTmr)); 25 | 26 | /* Compute the parameters of the coarsest graph */ 27 | MocCompute2WayPartitionParams(ctrl, graph); 28 | 29 | for (;;) { 30 | ASSERT(CheckBnd(graph)); 31 | 32 | IFSET(ctrl->dbglvl, DBG_TIME, gk_startcputimer(ctrl->RefTmr)); 33 | switch (ctrl->RType) { 34 | case RTYPE_FM: 35 | MocBalance2Way2(ctrl, graph, tpwgts, ubvec); 36 | MocFM_2WayEdgeRefine2(ctrl, graph, tpwgts, ubvec, 8); 37 | break; 38 | default: 39 | errexit("Unknown refinement type: %d\n", ctrl->RType); 40 | } 41 | IFSET(ctrl->dbglvl, DBG_TIME, gk_stopcputimer(ctrl->RefTmr)); 42 | 43 | if (graph == orggraph) 44 | break; 45 | 46 | graph = graph->finer; 47 | IFSET(ctrl->dbglvl, DBG_TIME, gk_startcputimer(ctrl->ProjectTmr)); 48 | MocProject2WayPartition(ctrl, graph); 49 | IFSET(ctrl->dbglvl, DBG_TIME, gk_stopcputimer(ctrl->ProjectTmr)); 50 | } 51 | 52 | IFSET(ctrl->dbglvl, DBG_TIME, gk_stopcputimer(ctrl->UncoarsenTmr)); 53 | } 54 | 55 | 56 | -------------------------------------------------------------------------------- /RecastDemo/Contrib/metis/source/libmetis/mrkmetis.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997, Regents of the University of Minnesota 3 | * 4 | * mrkmetis.c 5 | * 6 | * This file contains the top level routines for the multilevel k-way partitioning 7 | * algorithm KMETIS. 8 | * 9 | * Started 7/28/97 10 | * George 11 | * 12 | * $Id: mrkmetis.c,v 1.2 2003/04/04 23:25:10 karypis Exp $ 13 | * 14 | */ 15 | 16 | #include 17 | 18 | 19 | 20 | /************************************************************************* 21 | * This function is the entry point for KWMETIS 22 | **************************************************************************/ 23 | void METIS_mCRefineGraphKway(idxtype *nvtxs, idxtype *ncon, idxtype *xadj, idxtype *adjncy, 24 | idxtype *vwgt, idxtype *adjwgt, idxtype *wgtflag, idxtype *numflag, 25 | idxtype *nparts, float *rubvec, idxtype *options, idxtype *edgecut, 26 | idxtype *part) 27 | { 28 | idxtype i, j; 29 | GraphType graph; 30 | CtrlType ctrl; 31 | 32 | if (*numflag == 1) 33 | Change2CNumbering(*nvtxs, xadj, adjncy); 34 | 35 | SetUpGraph(&graph, OP_KMETIS, *nvtxs, *ncon, xadj, adjncy, vwgt, adjwgt, *wgtflag); 36 | 37 | if (options[0] == 0) { /* Use the default parameters */ 38 | ctrl.CType = McKMETIS_CTYPE; 39 | ctrl.IType = McKMETIS_ITYPE; 40 | ctrl.RType = McKMETIS_RTYPE; 41 | ctrl.dbglvl = McKMETIS_DBGLVL; 42 | } 43 | else { 44 | ctrl.CType = options[OPTION_CTYPE]; 45 | ctrl.IType = options[OPTION_ITYPE]; 46 | ctrl.RType = options[OPTION_RTYPE]; 47 | ctrl.dbglvl = options[OPTION_DBGLVL]; 48 | } 49 | ctrl.optype = OP_KMETIS; 50 | ctrl.CoarsenTo = amax((*nvtxs)/(20*gk_log2(*nparts)), 30*(*nparts)); 51 | ctrl.nmaxvwgt = 0.0; /* GK-MOD: Ensure that no coarsening will take place */ 52 | 53 | InitRandom(-1); 54 | 55 | AllocateWorkSpace(&ctrl, &graph, *nparts); 56 | 57 | IFSET(ctrl.dbglvl, DBG_TIME, InitTimers(&ctrl)); 58 | IFSET(ctrl.dbglvl, DBG_TIME, gk_startcputimer(ctrl.TotalTmr)); 59 | 60 | *edgecut = MCMlevelKWayRefinement(&ctrl, &graph, *nparts, part, rubvec); 61 | 62 | IFSET(ctrl.dbglvl, DBG_TIME, gk_stopcputimer(ctrl.TotalTmr)); 63 | IFSET(ctrl.dbglvl, DBG_TIME, PrintTimers(&ctrl)); 64 | 65 | FreeWorkSpace(&ctrl, &graph); 66 | 67 | if (*numflag == 1) 68 | Change2FNumbering(*nvtxs, xadj, adjncy, part); 69 | } 70 | 71 | 72 | /************************************************************************* 73 | * This function takes a graph and produces a bisection of it 74 | **************************************************************************/ 75 | idxtype MCMlevelKWayRefinement(CtrlType *ctrl, GraphType *graph, idxtype nparts, idxtype *part, 76 | float *rubvec) 77 | { 78 | idxtype i, j, nvtxs; 79 | GraphType *cgraph; 80 | idxtype options[10], edgecut; 81 | 82 | cgraph = MCCoarsen2Way(ctrl, graph); 83 | 84 | IFSET(ctrl->dbglvl, DBG_TIME, gk_startcputimer(ctrl->InitPartTmr)); 85 | MocAllocateKWayPartitionMemory(ctrl, cgraph, nparts); 86 | 87 | if (cgraph->nvtxs != graph->nvtxs) 88 | errexit("GK-MOD Failed: %d %d\n", cgraph->nvtxs, graph->nvtxs); 89 | 90 | for (i=0; invtxs; i++) 91 | cgraph->where[graph->cmap[i]] = part[i]; 92 | 93 | MocRefineKWayHorizontal(ctrl, graph, cgraph, nparts, rubvec); 94 | 95 | idxcopy(graph->nvtxs, graph->where, part); 96 | 97 | FreeGraph(graph, 0); 98 | 99 | return graph->mincut; 100 | 101 | } 102 | 103 | -------------------------------------------------------------------------------- /RecastDemo/Contrib/metis/source/libmetis/mutil.c: -------------------------------------------------------------------------------- 1 | /* 2 | * mutil.c 3 | * 4 | * This file contains various utility functions for the MOC portion of the 5 | * code 6 | * 7 | * Started 2/15/98 8 | * George 9 | * 10 | * $Id: mutil.c,v 1.2 2002/08/10 06:29:33 karypis Exp $ 11 | * 12 | */ 13 | 14 | #include 15 | 16 | 17 | /************************************************************************* 18 | * This function checks if the vertex weights of two vertices are below 19 | * a given set of values 20 | **************************************************************************/ 21 | idxtype AreAllVwgtsBelow(idxtype ncon, float alpha, float *vwgt1, float beta, float *vwgt2, float limit) 22 | { 23 | idxtype i; 24 | 25 | for (i=0; i limit) 27 | return 0; 28 | 29 | return 1; 30 | } 31 | 32 | 33 | /************************************************************************* 34 | * This function checks if the vertex weights of two vertices are below 35 | * a given set of values 36 | **************************************************************************/ 37 | idxtype AreAnyVwgtsBelow(idxtype ncon, float alpha, float *vwgt1, float beta, float *vwgt2, float limit) 38 | { 39 | idxtype i; 40 | 41 | for (i=0; i max) 79 | max = npwgts[j*ncon+i]; 80 | } 81 | if (max*nparts > lb) 82 | lb = max*nparts; 83 | } 84 | 85 | return lb; 86 | } 87 | 88 | /************************************************************************* 89 | * This function checks if the vertex weights of two vertices are below 90 | * a given set of values 91 | **************************************************************************/ 92 | idxtype AreAllBelow(idxtype ncon, float *v1, float *v2) 93 | { 94 | idxtype i; 95 | 96 | for (i=0; i v2[i]) 98 | return 0; 99 | 100 | return 1; 101 | } 102 | -------------------------------------------------------------------------------- /RecastDemo/Contrib/metis/source/libmetis/myqsort.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997, Regents of the University of Minnesota 3 | * 4 | * myqsort.c 5 | * 6 | * This file contains a fast idxtype increasing qsort algorithm. 7 | * Addopted from TeX 8 | * 9 | * Started 10/18/96 10 | * George 11 | * 12 | * $Id: myqsort.c,v 1.2 2002/08/10 06:29:33 karypis Exp $ 13 | */ 14 | 15 | #include /* only for type declarations */ 16 | 17 | 18 | 19 | 20 | /************************************************************************* 21 | * Entry point of idxtype increasing sort 22 | **************************************************************************/ 23 | void iidxsort(size_t n, idxtype *base) 24 | { 25 | #define idxtype_lt(a, b) ((*a) < (*b)) 26 | GKQSORT(idxtype, base, n, idxtype_lt); 27 | } 28 | 29 | 30 | /************************************************************************* 31 | * Entry point of KeyVal increasing sort, ONLY key part 32 | **************************************************************************/ 33 | void ikeysort(size_t n, KeyValueType *base) 34 | { 35 | #define keyvalue_lt(a, b) ((a)->key < (b)->key) 36 | GKQSORT(KeyValueType, base, n, keyvalue_lt); 37 | } 38 | 39 | 40 | 41 | /************************************************************************* 42 | * Entry point of KeyVal increasing sort, BOTH key and val part 43 | **************************************************************************/ 44 | void ikeyvalsort(size_t n, KeyValueType *base) 45 | { 46 | #define keyvalueboth_lt(a, b) ((a)->key < (b)->key || ((a)->key == (b)->key && (a)->val < (b)->val)) 47 | GKQSORT(KeyValueType, base, n, keyvalueboth_lt); 48 | } 49 | 50 | 51 | /************************************************************************* 52 | * Entry point of DKeyValueType increasing sort based on keys 53 | **************************************************************************/ 54 | void idkeysort(size_t n, DKeyValueType *base) 55 | { 56 | #define dkeyvalue_lt(a, b) ((a)->key < (b)->key) 57 | GKQSORT(DKeyValueType, base, n, dkeyvalue_lt); 58 | } 59 | -------------------------------------------------------------------------------- /RecastDemo/Contrib/metis/source/libmetis/stdheaders.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997, Regents of the University of Minnesota 3 | * 4 | * stdheaders.h 5 | * 6 | * This file includes all necessary header files 7 | * 8 | * Started 8/27/94 9 | * George 10 | * 11 | * $Id: stdheaders.h,v 1.2 2003/07/25 14:31:45 karypis Exp $ 12 | */ 13 | 14 | 15 | #include 16 | #ifdef __STDC__ 17 | #include 18 | #else 19 | #include 20 | #endif 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | -------------------------------------------------------------------------------- /RecastDemo/Contrib/metis/source/libmetis/timing.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997, Regents of the University of Minnesota 3 | * 4 | * timing.c 5 | * 6 | * This file contains routines that deal with timing Metis 7 | * 8 | * Started 7/24/97 9 | * George 10 | * 11 | * $Id: timing.c,v 1.2 2002/08/10 06:29:34 karypis Exp $ 12 | * 13 | */ 14 | 15 | #include 16 | 17 | 18 | /************************************************************************* 19 | * This function clears the timers 20 | **************************************************************************/ 21 | void InitTimers(CtrlType *ctrl) 22 | { 23 | gk_clearcputimer(ctrl->TotalTmr); 24 | gk_clearcputimer(ctrl->InitPartTmr); 25 | gk_clearcputimer(ctrl->MatchTmr); 26 | gk_clearcputimer(ctrl->ContractTmr); 27 | gk_clearcputimer(ctrl->CoarsenTmr); 28 | gk_clearcputimer(ctrl->UncoarsenTmr); 29 | gk_clearcputimer(ctrl->RefTmr); 30 | gk_clearcputimer(ctrl->ProjectTmr); 31 | gk_clearcputimer(ctrl->SplitTmr); 32 | gk_clearcputimer(ctrl->SepTmr); 33 | gk_clearcputimer(ctrl->AuxTmr1); 34 | gk_clearcputimer(ctrl->AuxTmr2); 35 | gk_clearcputimer(ctrl->AuxTmr3); 36 | gk_clearcputimer(ctrl->AuxTmr4); 37 | gk_clearcputimer(ctrl->AuxTmr5); 38 | gk_clearcputimer(ctrl->AuxTmr6); 39 | } 40 | 41 | 42 | 43 | /************************************************************************* 44 | * This function prints the various timers 45 | **************************************************************************/ 46 | void PrintTimers(CtrlType *ctrl) 47 | { 48 | mprintf("\nTiming Information -------------------------------------------------"); 49 | mprintf("\n Multilevel: \t\t %7.3f", gk_getcputimer(ctrl->TotalTmr)); 50 | mprintf("\n Coarsening: \t\t %7.3f", gk_getcputimer(ctrl->CoarsenTmr)); 51 | mprintf("\n Matching: \t\t\t %7.3f", gk_getcputimer(ctrl->MatchTmr)); 52 | mprintf("\n Contract: \t\t\t %7.3f", gk_getcputimer(ctrl->ContractTmr)); 53 | mprintf("\n Initial Partition: \t %7.3f", gk_getcputimer(ctrl->InitPartTmr)); 54 | mprintf("\n Construct Separator: \t %7.3f", gk_getcputimer(ctrl->SepTmr)); 55 | mprintf("\n Uncoarsening: \t\t %7.3f", gk_getcputimer(ctrl->UncoarsenTmr)); 56 | mprintf("\n Refinement: \t\t\t %7.3f", gk_getcputimer(ctrl->RefTmr)); 57 | mprintf("\n Projection: \t\t\t %7.3f", gk_getcputimer(ctrl->ProjectTmr)); 58 | mprintf("\n Splitting: \t\t %7.3f", gk_getcputimer(ctrl->SplitTmr)); 59 | mprintf("\n AUX1: \t\t %7.3f", gk_getcputimer(ctrl->AuxTmr1)); 60 | mprintf("\n AUX2: \t\t %7.3f", gk_getcputimer(ctrl->AuxTmr2)); 61 | mprintf("\n AUX3: \t\t %7.3f", gk_getcputimer(ctrl->AuxTmr3)); 62 | mprintf("\n********************************************************************\n"); 63 | } 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /RecastDemo/Contrib/metis/source/libmetis/util.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997, Regents of the University of Minnesota 3 | * 4 | * util.c 5 | * 6 | * This function contains various utility routines 7 | * 8 | * Started 9/28/95 9 | * George 10 | * 11 | * $Id: util.c,v 1.4 2003/04/13 04:45:12 karypis Exp $ 12 | */ 13 | 14 | #include 15 | 16 | 17 | 18 | 19 | /************************************************************************* 20 | * The following are utility functions defined for idxtype using GKlib's 21 | * function generating macros 22 | **************************************************************************/ 23 | GK_XMALLOC(idxmalloc, idxtype) 24 | GK_XREALLOC(idxrealloc, idxtype) 25 | GK_XSMALLOC(idxsmalloc, idxtype, idxset) 26 | GK_SET(idxset, idxtype) 27 | GK_ARGMAX(idxargmax, idxtype) 28 | GK_ARGMIN(idxargmin, idxtype) 29 | GK_SUM(idxsum, idxtype, idxtype) 30 | GK_AXPY(idxaxpy, idxtype) 31 | 32 | 33 | 34 | 35 | /************************************************************************* 36 | * These functions return the index of the maximum element in a vector 37 | **************************************************************************/ 38 | idxtype idxargmax_strd(size_t n, idxtype *x, idxtype incx) 39 | { 40 | size_t i, max=0; 41 | 42 | n *= incx; 43 | for (i=incx; i x[max] ? i : max); 45 | 46 | return max/incx; 47 | } 48 | 49 | 50 | 51 | 52 | /************************************************************************* 53 | * These functions return the index of the almost maximum element in a vector 54 | **************************************************************************/ 55 | idxtype famax2(size_t n, float *x) 56 | { 57 | size_t i, max1, max2; 58 | 59 | if (x[0] > x[1]) { 60 | max1 = 0; 61 | max2 = 1; 62 | } 63 | else { 64 | max1 = 1; 65 | max2 = 0; 66 | } 67 | 68 | for (i=2; i x[max1]) { 70 | max2 = max1; 71 | max1 = i; 72 | } 73 | else if (x[i] > x[max2]) 74 | max2 = i; 75 | } 76 | 77 | return max2; 78 | } 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | /************************************************************************* 87 | * This file randomly permutes the contents of an array. 88 | * flag == 0, don't initialize perm 89 | * flag == 1, set p[i] = i 90 | **************************************************************************/ 91 | void RandomPermute(size_t n, idxtype *p, idxtype flag) 92 | { 93 | size_t i, u, v; 94 | idxtype tmp; 95 | 96 | if (flag == 1) { 97 | for (i=0; i 17 | 18 | 19 | 20 | /************************************************************************* 21 | * Let the game begin 22 | **************************************************************************/ 23 | int main(int argc, char *argv[]) 24 | { 25 | idxtype i, options[10], nnodes, nclean, naclean, ndirty, maxdepth; 26 | idxtype *part, *sflag; 27 | float lbvec[MAXNCON]; 28 | GraphType graph; 29 | idxtype numflag = 0, wgtflag = 0, edgecut; 30 | ParamType params; 31 | void *cinfo; 32 | double TOTALTmr, METISTmr, IOTmr; 33 | 34 | parse_cmdline(¶ms, argc, argv); 35 | 36 | if (params.nparts < 2) { 37 | mprintf("The number of partitions should be greater than 1!\n"); 38 | exit(0); 39 | } 40 | 41 | gk_clearcputimer(TOTALTmr); 42 | gk_clearcputimer(METISTmr); 43 | gk_clearcputimer(IOTmr); 44 | 45 | gk_startcputimer(TOTALTmr); 46 | gk_startcputimer(IOTmr); 47 | ReadGraph(&graph, params.filename, &wgtflag); 48 | if (graph.nvtxs <= 0) { 49 | mprintf("Empty graph. Nothing to do.\n"); 50 | exit(0); 51 | } 52 | ReadCoordinates(&graph, params.xyzfilename); 53 | gk_stopcputimer(IOTmr); 54 | 55 | mprintf("**********************************************************************\n"); 56 | mprintf("%s", METISTITLE); 57 | mprintf("Graph Information ---------------------------------------------------\n"); 58 | mprintf(" Name: %s, #Vertices: %D, #Edges: %D, #Parts: %D\n", params.filename, graph.nvtxs, graph.nedges/2, params.nparts); 59 | if (graph.ncon > 1) 60 | mprintf(" Balancing Constraints: %D\n", graph.ncon); 61 | mprintf("\nRecursive Partitioning... -------------------------------------------\n"); 62 | 63 | part = idxmalloc(graph.nvtxs, "main: part"); 64 | sflag = idxsmalloc(graph.nvtxs, 1, "main: sflag"); 65 | options[0] = 0; 66 | 67 | gk_startcputimer(METISTmr); 68 | cinfo = METIS_PartGraphForContact(&graph.nvtxs, graph.xadj, graph.adjncy, graph.coords, sflag, 69 | &numflag, &(params.nparts), options, &edgecut, part); 70 | 71 | METIS_UpdateContactInfo(cinfo, &graph.nvtxs, graph.coords, sflag); 72 | gk_stopcputimer(METISTmr); 73 | 74 | ComputePartitionBalance(&graph, params.nparts, part, lbvec); 75 | 76 | graph.vwgt = idxsmalloc(graph.nvtxs, 1, "main: graph->vwgt"); 77 | 78 | mprintf(" %D-way Edge-Cut: %7D, Volume: %7D, Balance: ", params.nparts, edgecut, 79 | ComputeVolume(&graph, part)); 80 | for (i=0; i 16 | 17 | 18 | 19 | /************************************************************************* 20 | * Let the game begin 21 | **************************************************************************/ 22 | int main(int argc, char *argv[]) 23 | { 24 | GraphType graph; 25 | char filename[256]; 26 | idxtype wgtflag; 27 | 28 | if (argc != 2) { 29 | mprintf("Usage: %s \n", argv[0]); 30 | exit(0); 31 | } 32 | 33 | strcpy(filename, argv[1]); 34 | 35 | ReadGraph(&graph, filename, &wgtflag); 36 | if (graph.nvtxs == 0) { 37 | mprintf("Empty graph!\n"); 38 | exit(0); 39 | } 40 | 41 | mprintf("**********************************************************************\n"); 42 | mprintf("%s", METISTITLE); 43 | mprintf("Graph Information ---------------------------------------------------\n"); 44 | mprintf(" Name: %s, #Vertices: %D, #Edges: %D\n\n", filename, graph.nvtxs, graph.nedges/2); 45 | mprintf("Checking Graph... ---------------------------------------------------\n"); 46 | 47 | if (CheckGraph(&graph)) 48 | mprintf(" The format of the graph is correct!\n"); 49 | else 50 | mprintf(" The format of the graph is incorrect!\n"); 51 | 52 | mprintf("\n**********************************************************************\n"); 53 | 54 | 55 | gk_free((void **)&graph.xadj, &graph.adjncy, &graph.vwgt, &graph.adjwgt, LTERM); 56 | } 57 | 58 | 59 | -------------------------------------------------------------------------------- /RecastDemo/Contrib/metis/source/programs/kfmetis.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997, Regents of the University of Minnesota 3 | * 4 | * kfmetis.c 5 | * 6 | * This file contains the driving routine for partitioning for 7 | * sub-domain direct factorization. 8 | * 9 | * Started 8/11/02 10 | * George 11 | * 12 | * $Id: kfmetis.c,v 1.2 2002/08/13 16:40:14 karypis Exp $ 13 | * 14 | */ 15 | 16 | #include 17 | 18 | 19 | 20 | /************************************************************************* 21 | * Let the game begin 22 | **************************************************************************/ 23 | int main(int argc, char *argv[]) 24 | { 25 | idxtype i, options[10]; 26 | idxtype *part; 27 | float lbvec[MAXNCON]; 28 | GraphType graph; 29 | idxtype numflag = 0, wgtflag = 0, edgecut; 30 | ParamType params; 31 | double TOTALTmr, METISTmr, IOTmr; 32 | 33 | 34 | parse_cmdline(¶ms, argc, argv); 35 | 36 | 37 | if (params.nparts < 2) { 38 | mprintf("The number of partitions should be greater than 1!\n"); 39 | exit(0); 40 | } 41 | 42 | gk_clearcputimer(TOTALTmr); 43 | gk_clearcputimer(METISTmr); 44 | gk_clearcputimer(IOTmr); 45 | 46 | gk_startcputimer(TOTALTmr); 47 | gk_startcputimer(IOTmr); 48 | ReadGraph(&graph, params.filename, &wgtflag); 49 | if (graph.nvtxs <= 0) { 50 | mprintf("Empty graph. Nothing to do.\n"); 51 | exit(0); 52 | } 53 | gk_stopcputimer(IOTmr); 54 | 55 | mprintf("**********************************************************************\n"); 56 | mprintf("%s", METISTITLE); 57 | mprintf("Graph Information ---------------------------------------------------\n"); 58 | mprintf(" Name: %s, #Vertices: %D, #Edges: %D, #Parts: %D\n", params.filename, graph.nvtxs, graph.nedges/2, params.nparts); 59 | if (graph.ncon > 1) 60 | mprintf(" Balancing Constraints: %D\n", graph.ncon); 61 | mprintf("\nRecursive Partitioning... -------------------------------------------\n"); 62 | 63 | part = idxmalloc(graph.nvtxs, "main: part"); 64 | options[0] = 0; 65 | 66 | gk_startcputimer(METISTmr); 67 | METIS_PartFillGraph(&graph.nvtxs, graph.xadj, graph.adjncy, graph.vwgt, graph.adjwgt, 68 | &wgtflag, &numflag, &(params.nparts), options, &edgecut, part); 69 | 70 | gk_stopcputimer(METISTmr); 71 | 72 | ComputePartitionBalance(&graph, params.nparts, part, lbvec); 73 | 74 | mprintf(" %D-way Edge-Cut: %7D, Balance: ", params.nparts, edgecut); 75 | for (i=0; i 16 | 17 | 18 | 19 | /************************************************************************* 20 | * Let the game begin 21 | **************************************************************************/ 22 | int main(int argc, char *argv[]) 23 | { 24 | idxtype i, nparts, options[10]; 25 | idxtype *part; 26 | float rubvec[MAXNCON], lbvec[MAXNCON]; 27 | GraphType graph; 28 | char filename[256]; 29 | idxtype numflag = 0, wgtflag = 0, edgecut; 30 | double TOTALTmr, METISTmr, IOTmr; 31 | 32 | if (argc != 3) { 33 | mprintf("Usage: %s \n",argv[0]); 34 | exit(0); 35 | } 36 | 37 | strcpy(filename, argv[1]); 38 | nparts = atoi(argv[2]); 39 | 40 | if (nparts < 2) { 41 | mprintf("The number of partitions should be greater than 1!\n"); 42 | exit(0); 43 | } 44 | 45 | gk_clearcputimer(TOTALTmr); 46 | gk_clearcputimer(METISTmr); 47 | gk_clearcputimer(IOTmr); 48 | 49 | gk_startcputimer(TOTALTmr); 50 | gk_startcputimer(IOTmr); 51 | ReadGraph(&graph, filename, &wgtflag); 52 | 53 | /* The following is for debuging empty graphs... 54 | graph.nedges = 0; 55 | idxset(graph.nvtxs+1, 0, graph.xadj); 56 | */ 57 | 58 | if (graph.nvtxs <= 0) { 59 | mprintf("Empty graph. Nothing to do.\n"); 60 | exit(0); 61 | } 62 | gk_stopcputimer(IOTmr); 63 | 64 | mprintf("**********************************************************************\n"); 65 | mprintf("%s", METISTITLE); 66 | mprintf("Graph Information ---------------------------------------------------\n"); 67 | mprintf(" Name: %s, #Vertices: %D, #Edges: %D, #Parts: %D\n", filename, graph.nvtxs, graph.nedges/2, nparts); 68 | if (graph.ncon > 1) 69 | mprintf(" Balancing Constraints: %D\n", graph.ncon); 70 | mprintf("\nK-way Partitioning... -----------------------------------------------\n"); 71 | 72 | part = idxmalloc(graph.nvtxs, "main: part"); 73 | options[0] = 0; 74 | 75 | gk_startcputimer(METISTmr); 76 | if (graph.ncon == 1) { 77 | METIS_PartGraphKway(&graph.nvtxs, graph.xadj, graph.adjncy, graph.vwgt, graph.adjwgt, 78 | &wgtflag, &numflag, &nparts, options, &edgecut, part); 79 | } 80 | else { 81 | for (i=0; i 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | 25 | #if defined(ENABLE_OPENMP) 26 | #include 27 | #endif 28 | 29 | 30 | #include 31 | #include "../libmetis/defs.h" 32 | #include "../libmetis/struct.h" 33 | #include "../libmetis/rename.h" 34 | #include "../libmetis/macros.h" 35 | #include "../libmetis/proto.h" 36 | #include "defs.h" 37 | #include "struct.h" 38 | #include "proto.h" 39 | 40 | 41 | #if defined(COMPILER_MSC) 42 | #define rint(x) ((idxtype)((x)+0.5)) /* MSC does not have rint() function */ 43 | #endif 44 | 45 | 46 | #if defined(COMPILER_GCC) 47 | extern char* strdup (const char *); 48 | #endif 49 | 50 | -------------------------------------------------------------------------------- /RecastDemo/Contrib/metis/source/programs/oemetis.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997, Regents of the University of Minnesota 3 | * 4 | * oemetis.c 5 | * 6 | * This file contains the driving routine for multilevel method 7 | * 8 | * Started 8/28/94 9 | * George 10 | * 11 | * $Id: oemetis.c,v 1.2 2002/08/10 06:02:53 karypis Exp $ 12 | * 13 | */ 14 | 15 | #include 16 | 17 | 18 | 19 | /************************************************************************* 20 | * Let the game begin 21 | **************************************************************************/ 22 | int main(int argc, char *argv[]) 23 | { 24 | idxtype i, options[10]; 25 | idxtype *perm, *iperm; 26 | GraphType graph; 27 | char filename[256]; 28 | idxtype numflag = 0, wgtflag; 29 | double TOTALTmr, METISTmr, IOTmr, SMBTmr; 30 | 31 | 32 | if (argc != 2) { 33 | mprintf("Usage: %s \n",argv[0]); 34 | exit(0); 35 | } 36 | 37 | strcpy(filename, argv[1]); 38 | 39 | gk_clearcputimer(TOTALTmr); 40 | gk_clearcputimer(METISTmr); 41 | gk_clearcputimer(IOTmr); 42 | gk_clearcputimer(SMBTmr); 43 | 44 | gk_startcputimer(TOTALTmr); 45 | gk_startcputimer(IOTmr); 46 | ReadGraph(&graph, filename, &wgtflag); 47 | if (graph.nvtxs <= 0) { 48 | mprintf("Empty graph. Nothing to do.\n"); 49 | exit(0); 50 | } 51 | if (graph.ncon != 1) { 52 | mprintf("Ordering can only be applied to graphs with one constraint.\n"); 53 | exit(0); 54 | } 55 | gk_stopcputimer(IOTmr); 56 | 57 | /* Ordering does not use weights! */ 58 | gk_free((void **)&graph.vwgt, &graph.adjwgt, LTERM); 59 | 60 | mprintf("**********************************************************************\n"); 61 | mprintf("%s", METISTITLE); 62 | mprintf("Graph Information ---------------------------------------------------\n"); 63 | mprintf(" Name: %s, #Vertices: %D, #Edges: %D\n\n", filename, graph.nvtxs, graph.nedges/2); 64 | mprintf("Edge-Based Ordering... ----------------------------------------------\n"); 65 | 66 | perm = idxmalloc(graph.nvtxs, "main: perm"); 67 | iperm = idxmalloc(graph.nvtxs, "main: iperm"); 68 | options[0] = 0; 69 | 70 | gk_startcputimer(METISTmr); 71 | METIS_EdgeND(&graph.nvtxs, graph.xadj, graph.adjncy, &numflag, options, perm, iperm); 72 | gk_stopcputimer(METISTmr); 73 | 74 | gk_startcputimer(IOTmr); 75 | WritePermutation(filename, iperm, graph.nvtxs); 76 | gk_stopcputimer(IOTmr); 77 | 78 | gk_startcputimer(SMBTmr); 79 | ComputeFillIn(&graph, iperm); 80 | gk_stopcputimer(SMBTmr); 81 | 82 | gk_stopcputimer(TOTALTmr); 83 | 84 | mprintf("\nTiming Information --------------------------------------------------\n"); 85 | mprintf(" I/O: \t %7.3f\n", gk_getcputimer(IOTmr)); 86 | mprintf(" Ordering: \t %7.3f (OEMETIS time)\n", gk_getcputimer(METISTmr)); 87 | mprintf(" Symbolic Factorization: \t %7.3f\n", gk_getcputimer(SMBTmr)); 88 | mprintf(" Total: \t %7.3f\n", gk_getcputimer(TOTALTmr)); 89 | mprintf("**********************************************************************\n"); 90 | 91 | 92 | gk_free((void **)&graph.xadj, &graph.adjncy, &perm, &iperm, LTERM); 93 | } 94 | 95 | 96 | -------------------------------------------------------------------------------- /RecastDemo/Contrib/metis/source/programs/onmetis.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997, Regents of the University of Minnesota 3 | * 4 | * onmetis.c 5 | * 6 | * This file contains the driving routine for multilevel method 7 | * 8 | * Started 8/28/94 9 | * George 10 | * 11 | * $Id: onmetis.c,v 1.2 2002/08/10 06:02:53 karypis Exp $ 12 | * 13 | */ 14 | 15 | #include 16 | 17 | 18 | 19 | /************************************************************************* 20 | * Let the game begin 21 | **************************************************************************/ 22 | int main(int argc, char *argv[]) 23 | { 24 | idxtype i, options[10]; 25 | idxtype *perm, *iperm; 26 | GraphType graph; 27 | char filename[256]; 28 | idxtype numflag = 0, wgtflag; 29 | double TOTALTmr, METISTmr, IOTmr, SMBTmr; 30 | 31 | 32 | if (argc != 2) { 33 | mprintf("Usage: %s \n",argv[0]); 34 | exit(0); 35 | } 36 | 37 | strcpy(filename, argv[1]); 38 | 39 | gk_clearcputimer(TOTALTmr); 40 | gk_clearcputimer(METISTmr); 41 | gk_clearcputimer(IOTmr); 42 | gk_clearcputimer(SMBTmr); 43 | 44 | gk_startcputimer(TOTALTmr); 45 | gk_startcputimer(IOTmr); 46 | ReadGraph(&graph, filename, &wgtflag); 47 | if (graph.nvtxs <= 0) { 48 | mprintf("Empty graph. Nothing to do.\n"); 49 | exit(0); 50 | } 51 | if (graph.ncon != 1) { 52 | mprintf("Ordering can only be applied to graphs with one constraint.\n"); 53 | exit(0); 54 | } 55 | gk_stopcputimer(IOTmr); 56 | 57 | /* Ordering does not use weights! */ 58 | gk_free((void **)&graph.vwgt, &graph.adjwgt, LTERM); 59 | 60 | mprintf("**********************************************************************\n"); 61 | mprintf("%s", METISTITLE); 62 | mprintf("Graph Information ---------------------------------------------------\n"); 63 | mprintf(" Name: %s, #Vertices: %D, #Edges: %D\n\n", filename, graph.nvtxs, graph.nedges/2); 64 | mprintf("Node-Based Ordering... ----------------------------------------------\n"); 65 | 66 | perm = idxmalloc(graph.nvtxs, "main: perm"); 67 | iperm = idxmalloc(graph.nvtxs, "main: iperm"); 68 | options[0] = 0; 69 | 70 | gk_startcputimer(METISTmr); 71 | METIS_NodeND(&graph.nvtxs, graph.xadj, graph.adjncy, &numflag, options, perm, iperm); 72 | gk_stopcputimer(METISTmr); 73 | 74 | gk_startcputimer(IOTmr); 75 | WritePermutation(filename, iperm, graph.nvtxs); 76 | gk_stopcputimer(IOTmr); 77 | 78 | gk_startcputimer(SMBTmr); 79 | ComputeFillIn(&graph, iperm); 80 | gk_stopcputimer(SMBTmr); 81 | 82 | gk_stopcputimer(TOTALTmr); 83 | 84 | mprintf("\nTiming Information --------------------------------------------------\n"); 85 | mprintf(" I/O: \t %7.3f\n", gk_getcputimer(IOTmr)); 86 | mprintf(" Ordering: \t %7.3f (ONMETIS time)\n", gk_getcputimer(METISTmr)); 87 | mprintf(" Symbolic Factorization: \t %7.3f\n", gk_getcputimer(SMBTmr)); 88 | mprintf(" Total: \t %7.3f\n", gk_getcputimer(TOTALTmr)); 89 | mprintf("**********************************************************************\n"); 90 | 91 | 92 | gk_free((void **)&graph.xadj, &graph.adjncy, &perm, &iperm, LTERM); 93 | } 94 | 95 | 96 | -------------------------------------------------------------------------------- /RecastDemo/Contrib/metis/source/programs/partnmesh.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997, Regents of the University of Minnesota 3 | * 4 | * partnmesh.c 5 | * 6 | * This file reads in the element node connectivity array of a mesh and 7 | * partitions both the elements and the nodes using KMETIS on the dual graph. 8 | * 9 | * Started 9/29/97 10 | * George 11 | * 12 | * $Id: partnmesh.c,v 1.2 2002/08/10 06:02:54 karypis Exp $ 13 | * 14 | */ 15 | 16 | #include 17 | 18 | 19 | 20 | /************************************************************************* 21 | * Let the game begin 22 | **************************************************************************/ 23 | int main(int argc, char *argv[]) 24 | { 25 | idxtype i, j, ne, nn, etype, mtype, numflag=0, nparts, edgecut; 26 | idxtype *elmnts, *epart, *npart, *metype, *weights; 27 | double IOTmr, DUALTmr; 28 | char etypestr[5][5] = {"TRI", "TET", "HEX", "QUAD", "LINE"}; 29 | GraphType graph; 30 | 31 | if (argc != 3) { 32 | mprintf("Usage: %s \n",argv[0]); 33 | exit(0); 34 | } 35 | 36 | 37 | 38 | nparts = atoi(argv[2]); 39 | if (nparts < 2) { 40 | mprintf("nparts must be greater than one.\n"); 41 | exit(0); 42 | } 43 | 44 | gk_clearcputimer(IOTmr); 45 | gk_clearcputimer(DUALTmr); 46 | 47 | mtype=MeshType(argv[1]); 48 | ne=MixedElements(argv[1]); 49 | metype = idxmalloc(ne, "main: metype"); 50 | weights = idxmalloc(ne, "main: weights"); 51 | 52 | gk_startcputimer(IOTmr); 53 | 54 | if(mtype==1) 55 | elmnts = ReadMesh(argv[1], &ne, &nn, &etype); 56 | else if(mtype==3) 57 | elmnts = ReadMeshWgt(argv[1], &ne, &nn, &etype, weights); 58 | else if(mtype==0) 59 | elmnts = ReadMixedMesh(argv[1], &ne, &nn, metype); 60 | else 61 | elmnts = ReadMixedMeshWgt(argv[1], &ne, &nn, metype, weights); 62 | 63 | gk_stopcputimer(IOTmr); 64 | 65 | epart = idxmalloc(ne, "main: epart"); 66 | npart = idxmalloc(nn, "main: npart"); 67 | 68 | mprintf("**********************************************************************\n"); 69 | mprintf("%s", METISTITLE); 70 | mprintf("Mesh Information ----------------------------------------------------\n"); 71 | if (mtype==1) 72 | mprintf(" Name: %s, #Elements: %D, #Nodes: %D, Etype: %s\n\n", argv[1], ne, nn, etypestr[etype-1]); 73 | else 74 | mprintf(" Name: %s, #Elements: %D, #Nodes: %D, Etype: %s\n\n", argv[1], ne, nn, "Mixed"); 75 | mprintf("Partitioning Nodal Graph... -----------------------------------------\n"); 76 | 77 | 78 | gk_startcputimer(DUALTmr); 79 | 80 | if (mtype==1 || mtype==3) 81 | METIS_PartMeshNodal(&ne, &nn, elmnts, &etype, &numflag, &nparts, &edgecut, epart, npart); 82 | else 83 | METIS_PartMixedMeshNodal(&ne, &nn, elmnts, metype, &numflag, &nparts, &edgecut, epart, npart); 84 | 85 | gk_stopcputimer(DUALTmr); 86 | 87 | mprintf(" %D-way Edge-Cut: %7D, Balance: %5.2f\n", nparts, edgecut, ComputeElementBalance(ne, nparts, epart)); 88 | 89 | gk_startcputimer(IOTmr); 90 | WriteMeshPartition(argv[1], nparts, ne, epart, nn, npart); 91 | gk_stopcputimer(IOTmr); 92 | 93 | 94 | mprintf("\nTiming Information --------------------------------------------------\n"); 95 | mprintf(" I/O: \t\t %7.3f\n", gk_getcputimer(IOTmr)); 96 | mprintf(" Partitioning: \t\t %7.3f\n", gk_getcputimer(DUALTmr)); 97 | mprintf("**********************************************************************\n"); 98 | 99 | /* 100 | graph.nvtxs = ne; 101 | graph.xadj = idxmalloc(ne+1, "xadj"); 102 | graph.vwgt = idxsmalloc(ne, 1, "vwgt"); 103 | graph.adjncy = idxmalloc(10*ne, "adjncy"); 104 | graph.adjwgt = idxsmalloc(10*ne, 1, "adjncy"); 105 | 106 | METIS_MeshToDual(&ne, &nn, elmnts, &etype, &numflag, graph.xadj, graph.adjncy); 107 | 108 | ComputePartitionInfo(&graph, nparts, epart); 109 | 110 | gk_free((void **)&graph.xadj, &graph.adjncy, &graph.vwgt, &graph.adjwgt, LTERM); 111 | */ 112 | 113 | gk_free((void **)&elmnts, &epart, &npart, &metype, &weights, LTERM); 114 | 115 | } 116 | 117 | 118 | -------------------------------------------------------------------------------- /RecastDemo/Contrib/metis/source/programs/pmetis.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997, Regents of the University of Minnesota 3 | * 4 | * pmetis.c 5 | * 6 | * This file contains the driving routine for multilevel method 7 | * 8 | * Started 8/28/94 9 | * George 10 | * 11 | * $Id: pmetis.c,v 1.3 2002/08/10 06:57:51 karypis Exp $ 12 | * 13 | */ 14 | 15 | #include 16 | 17 | 18 | 19 | /************************************************************************* 20 | * Let the game begin 21 | **************************************************************************/ 22 | int main(int argc, char *argv[]) 23 | { 24 | idxtype i, options[10]; 25 | idxtype *part; 26 | float lbvec[MAXNCON]; 27 | GraphType graph; 28 | idxtype numflag = 0, wgtflag = 0, edgecut; 29 | ParamType params; 30 | double TOTALTmr, METISTmr, IOTmr; 31 | 32 | 33 | parse_cmdline(¶ms, argc, argv); 34 | 35 | 36 | if (params.nparts < 2) { 37 | mprintf("The number of partitions should be greater than 1!\n"); 38 | exit(0); 39 | } 40 | 41 | gk_clearcputimer(TOTALTmr); 42 | gk_clearcputimer(METISTmr); 43 | gk_clearcputimer(IOTmr); 44 | 45 | gk_startcputimer(TOTALTmr); 46 | gk_startcputimer(IOTmr); 47 | ReadGraph(&graph, params.filename, &wgtflag); 48 | if (graph.nvtxs <= 0) { 49 | mprintf("Empty graph. Nothing to do.\n"); 50 | exit(0); 51 | } 52 | gk_stopcputimer(IOTmr); 53 | 54 | mprintf("**********************************************************************\n"); 55 | mprintf("%s", METISTITLE); 56 | mprintf("Graph Information ---------------------------------------------------\n"); 57 | mprintf(" Name: %s, #Vertices: %D, #Edges: %D, #Parts: %D\n", params.filename, graph.nvtxs, graph.nedges/2, params.nparts); 58 | if (graph.ncon > 1) 59 | mprintf(" Balancing Constraints: %D\n", graph.ncon); 60 | mprintf("\nRecursive Partitioning... -------------------------------------------\n"); 61 | 62 | part = idxmalloc(graph.nvtxs, "main: part"); 63 | options[0] = 0; 64 | options[0] = 1; 65 | options[OPTION_CTYPE] = params.mtype; 66 | options[OPTION_ITYPE] = params.itype; 67 | options[OPTION_RTYPE] = params.rtype; 68 | options[OPTION_DBGLVL] = params.dbglvl; 69 | 70 | gk_startcputimer(METISTmr); 71 | if (graph.ncon == 1) { 72 | METIS_PartGraphRecursive(&graph.nvtxs, graph.xadj, graph.adjncy, graph.vwgt, graph.adjwgt, 73 | &wgtflag, &numflag, &(params.nparts), options, &edgecut, part); 74 | } 75 | else { 76 | METIS_mCPartGraphRecursive(&graph.nvtxs, &graph.ncon, graph.xadj, graph.adjncy, graph.vwgt, 77 | graph.adjwgt, &wgtflag, &numflag, &(params.nparts), options, &edgecut, part); 78 | } 79 | 80 | gk_stopcputimer(METISTmr); 81 | 82 | ComputePartitionBalance(&graph, params.nparts, part, lbvec); 83 | 84 | mprintf(" %D-way Edge-Cut: %7D, Balance: ", params.nparts, edgecut); 85 | for (i=0; i $file.tmp 6 | mv $file.tmp $file 7 | cat $file | sed 's/(int /(idxtype /g' > $file.tmp 8 | mv $file.tmp $file 9 | cat $file | sed 's/^int /idxtype /g' > $file.tmp 10 | mv $file.tmp $file 11 | done 12 | 13 | -------------------------------------------------------------------------------- /RecastDemo/Contrib/metis/source/utils/s+r.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo "Replacing $1 with $2" 4 | 5 | for file in *.[c,h] 6 | do 7 | cat $file | sed 's/$1/$2/g' > $file.tmp 8 | mv $file.tmp $file 9 | done 10 | 11 | -------------------------------------------------------------------------------- /RecastDemo/English.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/educharlie/HNA-Algorithm/388e185b8ea4e5bd82c77cb7358b38bca61661d7/RecastDemo/English.lproj/InfoPlist.strings -------------------------------------------------------------------------------- /RecastDemo/Icon.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/educharlie/HNA-Algorithm/388e185b8ea4e5bd82c77cb7358b38bca61661d7/RecastDemo/Icon.icns -------------------------------------------------------------------------------- /RecastDemo/Include/ChunkyTriMesh.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2009-2010 Mikko Mononen memon@inside.org 3 | // 4 | // This software is provided 'as-is', without any express or implied 5 | // warranty. In no event will the authors be held liable for any damages 6 | // arising from the use of this software. 7 | // Permission is granted to anyone to use this software for any purpose, 8 | // including commercial applications, and to alter it and redistribute it 9 | // freely, subject to the following restrictions: 10 | // 1. The origin of this software must not be misrepresented; you must not 11 | // claim that you wrote the original software. If you use this software 12 | // in a product, an acknowledgment in the product documentation would be 13 | // appreciated but is not required. 14 | // 2. Altered source versions must be plainly marked as such, and must not be 15 | // misrepresented as being the original software. 16 | // 3. This notice may not be removed or altered from any source distribution. 17 | // 18 | 19 | #ifndef CHUNKYTRIMESH_H 20 | #define CHUNKYTRIMESH_H 21 | 22 | struct rcChunkyTriMeshNode 23 | { 24 | float bmin[2], bmax[2]; 25 | int i, n; 26 | }; 27 | 28 | struct rcChunkyTriMesh 29 | { 30 | inline rcChunkyTriMesh() : nodes(0), tris(0) {}; 31 | inline ~rcChunkyTriMesh() { delete [] nodes; delete [] tris; } 32 | 33 | rcChunkyTriMeshNode* nodes; 34 | int nnodes; 35 | int* tris; 36 | int ntris; 37 | int maxTrisPerChunk; 38 | }; 39 | 40 | /// Creates partitioned triangle mesh (AABB tree), 41 | /// where each node contains at max trisPerChunk triangles. 42 | bool rcCreateChunkyTriMesh(const float* verts, const int* tris, int ntris, 43 | int trisPerChunk, rcChunkyTriMesh* cm); 44 | 45 | /// Returns the chunk indices which overlap the input rectable. 46 | int rcGetChunksOverlappingRect(const rcChunkyTriMesh* cm, float bmin[2], float bmax[2], int* ids, const int maxIds); 47 | 48 | /// Returns the chunk indices which overlap the input segment. 49 | int rcGetChunksOverlappingSegment(const rcChunkyTriMesh* cm, float p[2], float q[2], int* ids, const int maxIds); 50 | 51 | 52 | #endif // CHUNKYTRIMESH_H 53 | -------------------------------------------------------------------------------- /RecastDemo/Include/ConvexVolumeTool.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2009-2010 Mikko Mononen memon@inside.org 3 | // 4 | // This software is provided 'as-is', without any express or implied 5 | // warranty. In no event will the authors be held liable for any damages 6 | // arising from the use of this software. 7 | // Permission is granted to anyone to use this software for any purpose, 8 | // including commercial applications, and to alter it and redistribute it 9 | // freely, subject to the following restrictions: 10 | // 1. The origin of this software must not be misrepresented; you must not 11 | // claim that you wrote the original software. If you use this software 12 | // in a product, an acknowledgment in the product documentation would be 13 | // appreciated but is not required. 14 | // 2. Altered source versions must be plainly marked as such, and must not be 15 | // misrepresented as being the original software. 16 | // 3. This notice may not be removed or altered from any source distribution. 17 | // 18 | 19 | #ifndef CONVEXVOLUMETOOL_H 20 | #define CONVEXVOLUMETOOL_H 21 | 22 | #include "Sample.h" 23 | 24 | // Tool to create convex volumess for InputGeom 25 | 26 | class ConvexVolumeTool : public SampleTool 27 | { 28 | Sample* m_sample; 29 | int m_areaType; 30 | float m_polyOffset; 31 | float m_boxHeight; 32 | float m_boxDescent; 33 | 34 | static const int MAX_PTS = 12; 35 | float m_pts[MAX_PTS*3]; 36 | int m_npts; 37 | int m_hull[MAX_PTS]; 38 | int m_nhull; 39 | 40 | public: 41 | ConvexVolumeTool(); 42 | ~ConvexVolumeTool(); 43 | 44 | virtual int type() { return TOOL_CONVEX_VOLUME; } 45 | virtual void init(Sample* sample); 46 | virtual void reset(); 47 | virtual void handleMenu(); 48 | virtual void handleClick(const float* s, const float* p, bool shift); 49 | virtual void handleToggle(); 50 | virtual void handleStep(); 51 | virtual void handleUpdate(const float dt); 52 | virtual void handleRender(); 53 | virtual void handleRenderOverlay(double* proj, double* model, int* view); 54 | }; 55 | 56 | #endif // CONVEXVOLUMETOOL_H 57 | -------------------------------------------------------------------------------- /RecastDemo/Include/Filelist.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2009-2010 Mikko Mononen memon@inside.org 3 | // 4 | // This software is provided 'as-is', without any express or implied 5 | // warranty. In no event will the authors be held liable for any damages 6 | // arising from the use of this software. 7 | // Permission is granted to anyone to use this software for any purpose, 8 | // including commercial applications, and to alter it and redistribute it 9 | // freely, subject to the following restrictions: 10 | // 1. The origin of this software must not be misrepresented; you must not 11 | // claim that you wrote the original software. If you use this software 12 | // in a product, an acknowledgment in the product documentation would be 13 | // appreciated but is not required. 14 | // 2. Altered source versions must be plainly marked as such, and must not be 15 | // misrepresented as being the original software. 16 | // 3. This notice may not be removed or altered from any source distribution. 17 | // 18 | 19 | #ifndef FILELIST_H 20 | #define FILELIST_H 21 | 22 | struct FileList 23 | { 24 | static const int MAX_FILES = 256; 25 | 26 | FileList(); 27 | ~FileList(); 28 | 29 | char* files[MAX_FILES]; 30 | int size; 31 | }; 32 | 33 | void scanDirectory(const char* path, const char* ext, FileList& list); 34 | 35 | #endif // FILELIST_H 36 | -------------------------------------------------------------------------------- /RecastDemo/Include/MeshLoaderObj.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2009-2010 Mikko Mononen memon@inside.org 3 | // 4 | // This software is provided 'as-is', without any express or implied 5 | // warranty. In no event will the authors be held liable for any damages 6 | // arising from the use of this software. 7 | // Permission is granted to anyone to use this software for any purpose, 8 | // including commercial applications, and to alter it and redistribute it 9 | // freely, subject to the following restrictions: 10 | // 1. The origin of this software must not be misrepresented; you must not 11 | // claim that you wrote the original software. If you use this software 12 | // in a product, an acknowledgment in the product documentation would be 13 | // appreciated but is not required. 14 | // 2. Altered source versions must be plainly marked as such, and must not be 15 | // misrepresented as being the original software. 16 | // 3. This notice may not be removed or altered from any source distribution. 17 | // 18 | 19 | #ifndef MESHLOADER_OBJ 20 | #define MESHLOADER_OBJ 21 | 22 | class rcMeshLoaderObj 23 | { 24 | public: 25 | rcMeshLoaderObj(); 26 | ~rcMeshLoaderObj(); 27 | 28 | bool load(const char* fileName); 29 | 30 | inline const float* getVerts() const { return m_verts; } 31 | inline const float* getNormals() const { return m_normals; } 32 | inline const int* getTris() const { return m_tris; } 33 | inline int getVertCount() const { return m_vertCount; } 34 | inline int getTriCount() const { return m_triCount; } 35 | inline const char* getFileName() const { return m_filename; } 36 | 37 | private: 38 | 39 | void addVertex(float x, float y, float z, int& cap); 40 | void addTriangle(int a, int b, int c, int& cap); 41 | 42 | char m_filename[260]; 43 | float m_scale; 44 | float* m_verts; 45 | int* m_tris; 46 | float* m_normals; 47 | int m_vertCount; 48 | int m_triCount; 49 | }; 50 | 51 | #endif // MESHLOADER_OBJ 52 | -------------------------------------------------------------------------------- /RecastDemo/Include/NavMeshTesterTool.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2009-2010 Mikko Mononen memon@inside.org 3 | // 4 | // This software is provided 'as-is', without any express or implied 5 | // warranty. In no event will the authors be held liable for any damages 6 | // arising from the use of this software. 7 | // Permission is granted to anyone to use this software for any purpose, 8 | // including commercial applications, and to alter it and redistribute it 9 | // freely, subject to the following restrictions: 10 | // 1. The origin of this software must not be misrepresented; you must not 11 | // claim that you wrote the original software. If you use this software 12 | // in a product, an acknowledgment in the product documentation would be 13 | // appreciated but is not required. 14 | // 2. Altered source versions must be plainly marked as such, and must not be 15 | // misrepresented as being the original software. 16 | // 3. This notice may not be removed or altered from any source distribution. 17 | // 18 | 19 | #ifndef NAVMESHTESTERTOOL_H 20 | #define NAVMESHTESTERTOOL_H 21 | 22 | #include "Sample.h" 23 | #include "DetourNavMesh.h" 24 | #include "DetourNavMeshQuery.h" 25 | 26 | class NavMeshTesterTool : public SampleTool 27 | { 28 | Sample* m_sample; 29 | 30 | dtNavMesh* m_navMesh; 31 | dtNavMeshQuery* m_navQuery; 32 | Navigation nav; 33 | 34 | dtQueryFilter m_filter; 35 | 36 | dtStatus m_pathFindStatus; 37 | 38 | enum ToolMode 39 | { 40 | TOOLMODE_PATHFIND_FOLLOW, 41 | TOOLMODE_PATHFIND_STRAIGHT, 42 | TOOLMODE_PATHFIND_SLICED, 43 | TOOLMODE_RAYCAST, 44 | TOOLMODE_DISTANCE_TO_WALL, 45 | TOOLMODE_FIND_POLYS_IN_CIRCLE, 46 | TOOLMODE_FIND_POLYS_IN_SHAPE, 47 | TOOLMODE_FIND_LOCAL_NEIGHBOURHOOD, 48 | }; 49 | 50 | ToolMode m_toolMode; 51 | 52 | int m_straightPathOptions; 53 | 54 | static const int MAX_POLYS = 256; 55 | static const int MAX_SMOOTH = 2048; 56 | 57 | dtPolyRef m_startRef; 58 | dtPolyRef m_endRef; 59 | dtPolyRef m_polys[MAX_POLYS]; 60 | dtPolyRef m_parent[MAX_POLYS]; 61 | int m_npolys; 62 | float m_straightPath[MAX_POLYS*3]; 63 | unsigned char m_straightPathFlags[MAX_POLYS]; 64 | dtPolyRef m_straightPathPolys[MAX_POLYS]; 65 | int m_nstraightPath; 66 | float m_polyPickExt[3]; 67 | float m_smoothPath[MAX_SMOOTH*3]; 68 | int m_nsmoothPath; 69 | float m_queryPoly[4*3]; 70 | 71 | static const int MAX_RAND_POINTS = 64; 72 | float m_randPoints[MAX_RAND_POINTS*3]; 73 | int m_nrandPoints; 74 | bool m_randPointsInCircle; 75 | 76 | float m_spos[3]; 77 | float m_epos[3]; 78 | float m_hitPos[3]; 79 | float m_hitNormal[3]; 80 | bool m_hitResult; 81 | float m_distanceToWall; 82 | float m_neighbourhoodRadius; 83 | float m_randomRadius; 84 | bool m_sposSet; 85 | bool m_eposSet; 86 | 87 | int m_pathIterNum; 88 | dtPolyRef m_pathIterPolys[MAX_POLYS]; 89 | int m_pathIterPolyCount; 90 | float m_prevIterPos[3], m_iterPos[3], m_steerPos[3], m_targetPos[3]; 91 | 92 | static const int MAX_STEER_POINTS = 10; 93 | float m_steerPoints[MAX_STEER_POINTS*3]; 94 | int m_steerPointCount; 95 | 96 | public: 97 | NavMeshTesterTool(); 98 | ~NavMeshTesterTool(); 99 | 100 | virtual int type() { return TOOL_NAVMESH_TESTER; } 101 | virtual void init(Sample* sample); 102 | virtual void reset(); 103 | virtual void handleMenu(); 104 | virtual void handleClick(const float* s, const float* p, bool shift); 105 | virtual void handleToggle(); 106 | virtual void handleStep(); 107 | virtual void handleUpdate(const float dt); 108 | virtual void handleRender(); 109 | virtual void handleRenderOverlay(double* proj, double* model, int* view); 110 | 111 | void recalc(); 112 | void drawAgent(const float* pos, float r, float h, float c, const unsigned int col); 113 | }; 114 | 115 | #endif // NAVMESHTESTERTOOL_H -------------------------------------------------------------------------------- /RecastDemo/Include/NavmeshPruneTool.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2009-2010 Mikko Mononen memon@inside.org 3 | // 4 | // This software is provided 'as-is', without any express or implied 5 | // warranty. In no event will the authors be held liable for any damages 6 | // arising from the use of this software. 7 | // Permission is granted to anyone to use this software for any purpose, 8 | // including commercial applications, and to alter it and redistribute it 9 | // freely, subject to the following restrictions: 10 | // 1. The origin of this software must not be misrepresented; you must not 11 | // claim that you wrote the original software. If you use this software 12 | // in a product, an acknowledgment in the product documentation would be 13 | // appreciated but is not required. 14 | // 2. Altered source versions must be plainly marked as such, and must not be 15 | // misrepresented as being the original software. 16 | // 3. This notice may not be removed or altered from any source distribution. 17 | // 18 | 19 | #ifndef NAVMESHPRUNETOOL_H 20 | #define NAVMESHPRUNETOOL_H 21 | 22 | #include "Sample.h" 23 | 24 | // Prune navmesh to accessible locations from a point. 25 | 26 | class NavMeshPruneTool : public SampleTool 27 | { 28 | Sample* m_sample; 29 | 30 | class NavmeshFlags* m_flags; 31 | 32 | float m_hitPos[3]; 33 | bool m_hitPosSet; 34 | 35 | public: 36 | NavMeshPruneTool(); 37 | ~NavMeshPruneTool(); 38 | 39 | virtual int type() { return TOOL_NAVMESH_PRUNE; } 40 | virtual void init(Sample* sample); 41 | virtual void reset(); 42 | virtual void handleMenu(); 43 | virtual void handleClick(const float* s, const float* p, bool shift); 44 | virtual void handleToggle(); 45 | virtual void handleStep(); 46 | virtual void handleUpdate(const float dt); 47 | virtual void handleRender(); 48 | virtual void handleRenderOverlay(double* proj, double* model, int* view); 49 | }; 50 | 51 | #endif // NAVMESHPRUNETOOL_H 52 | -------------------------------------------------------------------------------- /RecastDemo/Include/OffMeshConnectionTool.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2009-2010 Mikko Mononen memon@inside.org 3 | // 4 | // This software is provided 'as-is', without any express or implied 5 | // warranty. In no event will the authors be held liable for any damages 6 | // arising from the use of this software. 7 | // Permission is granted to anyone to use this software for any purpose, 8 | // including commercial applications, and to alter it and redistribute it 9 | // freely, subject to the following restrictions: 10 | // 1. The origin of this software must not be misrepresented; you must not 11 | // claim that you wrote the original software. If you use this software 12 | // in a product, an acknowledgment in the product documentation would be 13 | // appreciated but is not required. 14 | // 2. Altered source versions must be plainly marked as such, and must not be 15 | // misrepresented as being the original software. 16 | // 3. This notice may not be removed or altered from any source distribution. 17 | // 18 | 19 | #ifndef OFFMESHCONNECTIONTOOL_H 20 | #define OFFMESHCONNECTIONTOOL_H 21 | 22 | #include "Sample.h" 23 | 24 | // Tool to create off-mesh connection for InputGeom 25 | 26 | class OffMeshConnectionTool : public SampleTool 27 | { 28 | Sample* m_sample; 29 | float m_hitPos[3]; 30 | bool m_hitPosSet; 31 | bool m_bidir; 32 | unsigned char m_oldFlags; 33 | 34 | public: 35 | OffMeshConnectionTool(); 36 | ~OffMeshConnectionTool(); 37 | 38 | virtual int type() { return TOOL_OFFMESH_CONNECTION; } 39 | virtual void init(Sample* sample); 40 | virtual void reset(); 41 | virtual void handleMenu(); 42 | virtual void handleClick(const float* s, const float* p, bool shift); 43 | virtual void handleToggle(); 44 | virtual void handleStep(); 45 | virtual void handleUpdate(const float dt); 46 | virtual void handleRender(); 47 | virtual void handleRenderOverlay(double* proj, double* model, int* view); 48 | }; 49 | 50 | #endif // OFFMESHCONNECTIONTOOL_H 51 | -------------------------------------------------------------------------------- /RecastDemo/Include/PerfTimer.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2009-2010 Mikko Mononen memon@inside.org 3 | // 4 | // This software is provided 'as-is', without any express or implied 5 | // warranty. In no event will the authors be held liable for any damages 6 | // arising from the use of this software. 7 | // Permission is granted to anyone to use this software for any purpose, 8 | // including commercial applications, and to alter it and redistribute it 9 | // freely, subject to the following restrictions: 10 | // 1. The origin of this software must not be misrepresented; you must not 11 | // claim that you wrote the original software. If you use this software 12 | // in a product, an acknowledgment in the product documentation would be 13 | // appreciated but is not required. 14 | // 2. Altered source versions must be plainly marked as such, and must not be 15 | // misrepresented as being the original software. 16 | // 3. This notice may not be removed or altered from any source distribution. 17 | // 18 | 19 | #ifndef PERFTIMER_H 20 | #define PERFTIMER_H 21 | 22 | #ifdef __GNUC__ 23 | #include 24 | typedef int64_t TimeVal; 25 | #else 26 | typedef __int64 TimeVal; 27 | #endif 28 | 29 | TimeVal getPerfTime(); 30 | int getPerfDeltaTimeUsec(const TimeVal start, const TimeVal end); 31 | 32 | #endif // PERFTIMER_H -------------------------------------------------------------------------------- /RecastDemo/Include/SDLMain.h: -------------------------------------------------------------------------------- 1 | /* SDLMain.m - main entry point for our Cocoa-ized SDL app 2 | Initial Version: Darrell Walisser 3 | Non-NIB-Code & other changes: Max Horn 4 | 5 | Feel free to customize this file to suit your needs 6 | */ 7 | 8 | #import 9 | 10 | @interface SDLMain : NSObject 11 | @end 12 | -------------------------------------------------------------------------------- /RecastDemo/Include/SampleInterfaces.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2009-2010 Mikko Mononen memon@inside.org 3 | // 4 | // This software is provided 'as-is', without any express or implied 5 | // warranty. In no event will the authors be held liable for any damages 6 | // arising from the use of this software. 7 | // Permission is granted to anyone to use this software for any purpose, 8 | // including commercial applications, and to alter it and redistribute it 9 | // freely, subject to the following restrictions: 10 | // 1. The origin of this software must not be misrepresented; you must not 11 | // claim that you wrote the original software. If you use this software 12 | // in a product, an acknowledgment in the product documentation would be 13 | // appreciated but is not required. 14 | // 2. Altered source versions must be plainly marked as such, and must not be 15 | // misrepresented as being the original software. 16 | // 3. This notice may not be removed or altered from any source distribution. 17 | // 18 | 19 | #ifndef SAMPLEINTERFACES_H 20 | #define SAMPLEINTERFACES_H 21 | 22 | #include "DebugDraw.h" 23 | #include "Recast.h" 24 | #include "RecastDump.h" 25 | #include "PerfTimer.h" 26 | 27 | // These are example implementations of various interfaces used in Recast and Detour. 28 | 29 | /// Recast build context. 30 | class BuildContext : public rcContext 31 | { 32 | TimeVal m_startTime[RC_MAX_TIMERS]; 33 | int m_accTime[RC_MAX_TIMERS]; 34 | 35 | static const int MAX_MESSAGES = 1000; 36 | const char* m_messages[MAX_MESSAGES]; 37 | int m_messageCount; 38 | static const int TEXT_POOL_SIZE = 8000; 39 | char m_textPool[TEXT_POOL_SIZE]; 40 | int m_textPoolSize; 41 | 42 | public: 43 | BuildContext(); 44 | virtual ~BuildContext(); 45 | 46 | /// Dumps the log to stdout. 47 | void dumpLog(const char* format, ...); 48 | /// Returns number of log messages. 49 | int getLogCount() const; 50 | /// Returns log message text. 51 | const char* getLogText(const int i) const; 52 | 53 | protected: 54 | /// Virtual functions for custom implementations. 55 | ///@{ 56 | virtual void doResetLog(); 57 | virtual void doLog(const rcLogCategory /*category*/, const char* /*msg*/, const int /*len*/); 58 | virtual void doResetTimers(); 59 | virtual void doStartTimer(const rcTimerLabel /*label*/); 60 | virtual void doStopTimer(const rcTimerLabel /*label*/); 61 | virtual int doGetAccumulatedTime(const rcTimerLabel /*label*/) const; 62 | ///@} 63 | }; 64 | 65 | /// OpenGL debug draw implementation. 66 | class DebugDrawGL : public duDebugDraw 67 | { 68 | public: 69 | virtual void depthMask(bool state); 70 | virtual void texture(bool state); 71 | virtual void begin(duDebugDrawPrimitives prim, float size = 1.0f); 72 | virtual void vertex(const float* pos, unsigned int color); 73 | virtual void vertex(const float x, const float y, const float z, unsigned int color); 74 | virtual void vertex(const float* pos, unsigned int color, const float* uv); 75 | virtual void vertex(const float x, const float y, const float z, unsigned int color, const float u, const float v); 76 | virtual void end(); 77 | }; 78 | 79 | /// stdio file implementation. 80 | class FileIO : public duFileIO 81 | { 82 | FILE* m_fp; 83 | int m_mode; 84 | public: 85 | FileIO(); 86 | virtual ~FileIO(); 87 | bool openForWrite(const char* path); 88 | bool openForRead(const char* path); 89 | virtual bool isWriting() const; 90 | virtual bool isReading() const; 91 | virtual bool write(const void* ptr, const size_t size); 92 | virtual bool read(void* ptr, const size_t size); 93 | }; 94 | 95 | #endif // SAMPLEINTERFACES_H 96 | 97 | -------------------------------------------------------------------------------- /RecastDemo/Include/Sample_Debug.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2009-2010 Mikko Mononen memon@inside.org 3 | // 4 | // This software is provided 'as-is', without any express or implied 5 | // warranty. In no event will the authors be held liable for any damages 6 | // arising from the use of this software. 7 | // Permission is granted to anyone to use this software for any purpose, 8 | // including commercial applications, and to alter it and redistribute it 9 | // freely, subject to the following restrictions: 10 | // 1. The origin of this software must not be misrepresented; you must not 11 | // claim that you wrote the original software. If you use this software 12 | // in a product, an acknowledgment in the product documentation would be 13 | // appreciated but is not required. 14 | // 2. Altered source versions must be plainly marked as such, and must not be 15 | // misrepresented as being the original software. 16 | // 3. This notice may not be removed or altered from any source distribution. 17 | // 18 | 19 | #ifndef RECASTSAMPLEDEBUG_H 20 | #define RECASTSAMPLEDEBUG_H 21 | 22 | #include "Sample.h" 23 | #include "DetourNavMesh.h" 24 | #include "Recast.h" 25 | 26 | /// Sample used for random debugging. 27 | class Sample_Debug : public Sample 28 | { 29 | protected: 30 | rcCompactHeightfield* m_chf; 31 | rcContourSet* m_cset; 32 | rcPolyMesh* m_pmesh; 33 | 34 | float m_ext[3]; 35 | float m_center[3]; 36 | float m_bmin[3], m_bmax[3]; 37 | dtPolyRef m_ref; 38 | 39 | public: 40 | Sample_Debug(); 41 | virtual ~Sample_Debug(); 42 | 43 | virtual void handleSettings(); 44 | virtual void handleTools(); 45 | virtual void handleDebugMode(); 46 | virtual void handleClick(const float* s, const float* p, bool shift); 47 | virtual void handleToggle(); 48 | virtual void handleRender(); 49 | virtual void handleRenderOverlay(double* proj, double* model, int* view); 50 | virtual void handleMeshChanged(class InputGeom* geom); 51 | virtual bool handleBuild(); 52 | 53 | virtual const float* getBoundsMin(); 54 | virtual const float* getBoundsMax(); 55 | }; 56 | 57 | 58 | #endif // RECASTSAMPLE_H 59 | -------------------------------------------------------------------------------- /RecastDemo/Include/Sample_SoloMesh.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2009-2010 Mikko Mononen memon@inside.org 3 | // 4 | // This software is provided 'as-is', without any express or implied 5 | // warranty. In no event will the authors be held liable for any damages 6 | // arising from the use of this software. 7 | // Permission is granted to anyone to use this software for any purpose, 8 | // including commercial applications, and to alter it and redistribute it 9 | // freely, subject to the following restrictions: 10 | // 1. The origin of this software must not be misrepresented; you must not 11 | // claim that you wrote the original software. If you use this software 12 | // in a product, an acknowledgment in the product documentation would be 13 | // appreciated but is not required. 14 | // 2. Altered source versions must be plainly marked as such, and must not be 15 | // misrepresented as being the original software. 16 | // 3. This notice may not be removed or altered from any source distribution. 17 | // 18 | 19 | #ifndef RECASTSAMPLESOLOMESH_H 20 | #define RECASTSAMPLESOLOMESH_H 21 | 22 | #include "Sample.h" 23 | #include "DetourNavMesh.h" 24 | #include "Recast.h" 25 | 26 | 27 | 28 | class Sample_SoloMesh : public Sample 29 | { 30 | protected: 31 | bool m_keepInterResults; 32 | float m_totalBuildTimeMs; 33 | 34 | unsigned char* m_triareas; 35 | rcHeightfield* m_solid; 36 | rcCompactHeightfield* m_chf; 37 | rcContourSet* m_cset; 38 | rcPolyMesh* m_pmesh; 39 | rcConfig m_cfg; 40 | rcPolyMeshDetail* m_dmesh; 41 | std::map nodeCluster; 42 | 43 | 44 | enum DrawMode 45 | { 46 | DRAWMODE_NAVMESH, 47 | DRAWMODE_NAVMESH_TRANS, 48 | DRAWMODE_NAVMESH_BVTREE, 49 | DRAWMODE_NAVMESH_NODES, 50 | DRAWMODE_NAVMESH_INVIS, 51 | DRAWMODE_MESH, 52 | DRAWMODE_VOXELS, 53 | DRAWMODE_VOXELS_WALKABLE, 54 | DRAWMODE_COMPACT, 55 | DRAWMODE_COMPACT_DISTANCE, 56 | DRAWMODE_COMPACT_REGIONS, 57 | DRAWMODE_REGION_CONNECTIONS, 58 | DRAWMODE_RAW_CONTOURS, 59 | DRAWMODE_BOTH_CONTOURS, 60 | DRAWMODE_CONTOURS, 61 | DRAWMODE_POLYMESH, 62 | DRAWMODE_POLYMESH_DETAIL, 63 | DRAWMODE_HIERARCHICAL, 64 | MAX_DRAWMODE 65 | }; 66 | 67 | DrawMode m_drawMode; 68 | 69 | void cleanup(); 70 | 71 | public: 72 | Sample_SoloMesh(); 73 | virtual ~Sample_SoloMesh(); 74 | 75 | virtual void handleSettings(); 76 | virtual void handleHierarchySettings(); 77 | virtual void handleTools(); 78 | virtual void handleDebugMode(); 79 | 80 | virtual void handleRender(); 81 | virtual void handleRenderOverlay(double* proj, double* model, int* view); 82 | virtual void handleMeshChanged(class InputGeom* geom); 83 | virtual bool handleBuild(); 84 | 85 | virtual bool handleHierarchy(); 86 | 87 | 88 | }; 89 | 90 | 91 | #endif // RECASTSAMPLESOLOMESHSIMPLE_H 92 | -------------------------------------------------------------------------------- /RecastDemo/Include/Sample_TempObstacles.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2009-2010 Mikko Mononen memon@inside.org 3 | // 4 | // This software is provided 'as-is', without any express or implied 5 | // warranty. In no event will the authors be held liable for any damages 6 | // arising from the use of this software. 7 | // Permission is granted to anyone to use this software for any purpose, 8 | // including commercial applications, and to alter it and redistribute it 9 | // freely, subject to the following restrictions: 10 | // 1. The origin of this software must not be misrepresented; you must not 11 | // claim that you wrote the original software. If you use this software 12 | // in a product, an acknowledgment in the product documentation would be 13 | // appreciated but is not required. 14 | // 2. Altered source versions must be plainly marked as such, and must not be 15 | // misrepresented as being the original software. 16 | // 3. This notice may not be removed or altered from any source distribution. 17 | // 18 | 19 | #ifndef RECASTSAMPLETEMPOBSTACLE_H 20 | #define RECASTSAMPLETEMPOBSTACLE_H 21 | 22 | #include "Sample.h" 23 | #include "DetourNavMesh.h" 24 | #include "Recast.h" 25 | #include "ChunkyTriMesh.h" 26 | 27 | 28 | class Sample_TempObstacles : public Sample 29 | { 30 | protected: 31 | bool m_keepInterResults; 32 | 33 | struct LinearAllocator* m_talloc; 34 | struct FastLZCompressor* m_tcomp; 35 | struct MeshProcess* m_tmproc; 36 | 37 | class dtTileCache* m_tileCache; 38 | 39 | float m_cacheBuildTimeMs; 40 | int m_cacheCompressedSize; 41 | int m_cacheRawSize; 42 | int m_cacheLayerCount; 43 | int m_cacheBuildMemUsage; 44 | 45 | enum DrawMode 46 | { 47 | DRAWMODE_NAVMESH, 48 | DRAWMODE_NAVMESH_TRANS, 49 | DRAWMODE_NAVMESH_BVTREE, 50 | DRAWMODE_NAVMESH_NODES, 51 | DRAWMODE_NAVMESH_PORTALS, 52 | DRAWMODE_NAVMESH_INVIS, 53 | DRAWMODE_MESH, 54 | DRAWMODE_CACHE_BOUNDS, 55 | MAX_DRAWMODE 56 | }; 57 | 58 | DrawMode m_drawMode; 59 | 60 | int m_maxTiles; 61 | int m_maxPolysPerTile; 62 | float m_tileSize; 63 | 64 | public: 65 | Sample_TempObstacles(); 66 | virtual ~Sample_TempObstacles(); 67 | 68 | virtual void handleSettings(); 69 | virtual void handleTools(); 70 | virtual void handleDebugMode(); 71 | virtual void handleRender(); 72 | virtual void handleRenderOverlay(double* proj, double* model, int* view); 73 | virtual void handleMeshChanged(class InputGeom* geom); 74 | virtual bool handleBuild(); 75 | virtual void handleUpdate(const float dt); 76 | 77 | void getTilePos(const float* pos, int& tx, int& ty); 78 | 79 | void renderCachedTile(const int tx, const int ty, const int type); 80 | void renderCachedTileOverlay(const int tx, const int ty, double* proj, double* model, int* view); 81 | 82 | void addTempObstacle(const float* pos); 83 | void removeTempObstacle(const float* sp, const float* sq); 84 | void clearAllTempObstacles(); 85 | }; 86 | 87 | 88 | #endif // RECASTSAMPLETEMPOBSTACLE_H 89 | -------------------------------------------------------------------------------- /RecastDemo/Include/Sample_TileMesh.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2009-2010 Mikko Mononen memon@inside.org 3 | // 4 | // This software is provided 'as-is', without any express or implied 5 | // warranty. In no event will the authors be held liable for any damages 6 | // arising from the use of this software. 7 | // Permission is granted to anyone to use this software for any purpose, 8 | // including commercial applications, and to alter it and redistribute it 9 | // freely, subject to the following restrictions: 10 | // 1. The origin of this software must not be misrepresented; you must not 11 | // claim that you wrote the original software. If you use this software 12 | // in a product, an acknowledgment in the product documentation would be 13 | // appreciated but is not required. 14 | // 2. Altered source versions must be plainly marked as such, and must not be 15 | // misrepresented as being the original software. 16 | // 3. This notice may not be removed or altered from any source distribution. 17 | // 18 | 19 | #ifndef RECASTSAMPLETILEMESH_H 20 | #define RECASTSAMPLETILEMESH_H 21 | 22 | #include "Sample.h" 23 | #include "DetourNavMesh.h" 24 | #include "Recast.h" 25 | #include "ChunkyTriMesh.h" 26 | 27 | class Sample_TileMesh : public Sample 28 | { 29 | protected: 30 | bool m_keepInterResults; 31 | bool m_buildAll; 32 | float m_totalBuildTimeMs; 33 | 34 | unsigned char* m_triareas; 35 | rcHeightfield* m_solid; 36 | rcCompactHeightfield* m_chf; 37 | rcContourSet* m_cset; 38 | rcPolyMesh* m_pmesh; 39 | rcPolyMeshDetail* m_dmesh; 40 | rcConfig m_cfg; 41 | 42 | enum DrawMode 43 | { 44 | DRAWMODE_NAVMESH, 45 | DRAWMODE_NAVMESH_TRANS, 46 | DRAWMODE_NAVMESH_BVTREE, 47 | DRAWMODE_NAVMESH_NODES, 48 | DRAWMODE_NAVMESH_PORTALS, 49 | DRAWMODE_NAVMESH_INVIS, 50 | DRAWMODE_MESH, 51 | DRAWMODE_VOXELS, 52 | DRAWMODE_VOXELS_WALKABLE, 53 | DRAWMODE_COMPACT, 54 | DRAWMODE_COMPACT_DISTANCE, 55 | DRAWMODE_COMPACT_REGIONS, 56 | DRAWMODE_REGION_CONNECTIONS, 57 | DRAWMODE_RAW_CONTOURS, 58 | DRAWMODE_BOTH_CONTOURS, 59 | DRAWMODE_CONTOURS, 60 | DRAWMODE_POLYMESH, 61 | DRAWMODE_POLYMESH_DETAIL, 62 | MAX_DRAWMODE 63 | }; 64 | 65 | DrawMode m_drawMode; 66 | 67 | int m_maxTiles; 68 | int m_maxPolysPerTile; 69 | float m_tileSize; 70 | 71 | unsigned int m_tileCol; 72 | float m_tileBmin[3]; 73 | float m_tileBmax[3]; 74 | float m_tileBuildTime; 75 | float m_tileMemUsage; 76 | int m_tileTriCount; 77 | 78 | unsigned char* buildTileMesh(const int tx, const int ty, const float* bmin, const float* bmax, int& dataSize); 79 | 80 | void cleanup(); 81 | 82 | void saveAll(const char* path, const dtNavMesh* mesh); 83 | dtNavMesh* loadAll(const char* path); 84 | 85 | public: 86 | Sample_TileMesh(); 87 | virtual ~Sample_TileMesh(); 88 | 89 | virtual void handleSettings(); 90 | virtual void handleTools(); 91 | virtual void handleDebugMode(); 92 | virtual void handleRender(); 93 | virtual void handleRenderOverlay(double* proj, double* model, int* view); 94 | virtual void handleMeshChanged(class InputGeom* geom); 95 | virtual bool handleBuild(); 96 | 97 | void getTilePos(const float* pos, int& tx, int& ty); 98 | 99 | void buildTile(const float* pos); 100 | void removeTile(const float* pos); 101 | void buildAllTiles(); 102 | void removeAllTiles(); 103 | }; 104 | 105 | 106 | #endif // RECASTSAMPLETILEMESH_H 107 | -------------------------------------------------------------------------------- /RecastDemo/Include/SlideShow.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2009-2010 Mikko Mononen memon@inside.org 3 | // 4 | // This software is provided 'as-is', without any express or implied 5 | // warranty. In no event will the authors be held liable for any damages 6 | // arising from the use of this software. 7 | // Permission is granted to anyone to use this software for any purpose, 8 | // including commercial applications, and to alter it and redistribute it 9 | // freely, subject to the following restrictions: 10 | // 1. The origin of this software must not be misrepresented; you must not 11 | // claim that you wrote the original software. If you use this software 12 | // in a product, an acknowledgment in the product documentation would be 13 | // appreciated but is not required. 14 | // 2. Altered source versions must be plainly marked as such, and must not be 15 | // misrepresented as being the original software. 16 | // 3. This notice may not be removed or altered from any source distribution. 17 | // 18 | 19 | #ifndef SLIDESHOW_H 20 | #define SLIDESHOW_H 21 | 22 | #include "Filelist.h" 23 | 24 | class SlideShow 25 | { 26 | FileList m_files; 27 | char m_path[256]; 28 | 29 | int m_width; 30 | int m_height; 31 | unsigned int m_texId; 32 | 33 | void purgeImage(); 34 | bool loadImage(const char* path); 35 | 36 | bool m_showSlides; 37 | bool m_showCurSlide; 38 | float m_slideAlpha; 39 | int m_curSlide; 40 | int m_nextSlide; 41 | 42 | public: 43 | SlideShow(); 44 | ~SlideShow(); 45 | 46 | bool init(const char* path); 47 | void nextSlide(); 48 | void prevSlide(); 49 | void setSlide(int n); 50 | void updateAndDraw(float dt, const float w, const float h); 51 | }; 52 | 53 | #endif // SLIDESHOW_H 54 | -------------------------------------------------------------------------------- /RecastDemo/Include/TestCase.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2009-2010 Mikko Mononen memon@inside.org 3 | // 4 | // This software is provided 'as-is', without any express or implied 5 | // warranty. In no event will the authors be held liable for any damages 6 | // arising from the use of this software. 7 | // Permission is granted to anyone to use this software for any purpose, 8 | // including commercial applications, and to alter it and redistribute it 9 | // freely, subject to the following restrictions: 10 | // 1. The origin of this software must not be misrepresented; you must not 11 | // claim that you wrote the original software. If you use this software 12 | // in a product, an acknowledgment in the product documentation would be 13 | // appreciated but is not required. 14 | // 2. Altered source versions must be plainly marked as such, and must not be 15 | // misrepresented as being the original software. 16 | // 3. This notice may not be removed or altered from any source distribution. 17 | // 18 | 19 | #ifndef TESTCASE_H 20 | #define TESTCASE_H 21 | 22 | #include "DetourNavMesh.h" 23 | 24 | class TestCase 25 | { 26 | enum TestType 27 | { 28 | TEST_PATHFIND, 29 | TEST_RAYCAST, 30 | }; 31 | 32 | struct Test 33 | { 34 | Test() : straight(0), nstraight(0), polys(0), npolys(0) {}; 35 | ~Test() 36 | { 37 | delete [] straight; 38 | delete [] polys; 39 | } 40 | 41 | TestType type; 42 | float spos[3], epos[3]; 43 | float nspos[3], nepos[3]; 44 | float radius; 45 | int includeFlags, excludeFlags; 46 | bool expand; 47 | 48 | float* straight; 49 | int nstraight; 50 | dtPolyRef* polys; 51 | int npolys; 52 | 53 | int findNearestPolyTime; 54 | int findPathTime; 55 | int findStraightPathTime; 56 | 57 | Test* next; 58 | }; 59 | 60 | char m_sampleName[256]; 61 | char m_geomFileName[256]; 62 | Test* m_tests; 63 | 64 | void resetTimes(); 65 | 66 | public: 67 | TestCase(); 68 | ~TestCase(); 69 | 70 | bool load(const char* filePath); 71 | 72 | inline const char* getSampleName() const { return m_sampleName; } 73 | inline const char* getGeomFileName() const { return m_geomFileName; } 74 | 75 | void doTests(class dtNavMesh* navmesh, class dtNavMeshQuery* navquery); 76 | 77 | void handleRender(); 78 | bool handleRenderOverlay(double* proj, double* model, int* view); 79 | }; 80 | 81 | #endif // TESTCASE_H -------------------------------------------------------------------------------- /RecastDemo/Include/ValueHistory.h: -------------------------------------------------------------------------------- 1 | #ifndef VALUEHISTORY_H 2 | #define VALUEHISTORY_H 3 | 4 | class ValueHistory 5 | { 6 | static const int MAX_HISTORY = 256; 7 | float m_samples[MAX_HISTORY]; 8 | int m_hsamples; 9 | public: 10 | ValueHistory(); 11 | ~ValueHistory(); 12 | 13 | inline void addSample(const float val) 14 | { 15 | m_hsamples = (m_hsamples+MAX_HISTORY-1) % MAX_HISTORY; 16 | m_samples[m_hsamples] = val; 17 | } 18 | 19 | inline int getSampleCount() const 20 | { 21 | return MAX_HISTORY; 22 | } 23 | 24 | inline float getSample(const int i) const 25 | { 26 | return m_samples[(m_hsamples+i) % MAX_HISTORY]; 27 | } 28 | 29 | float getSampleMin() const; 30 | float getSampleMax() const; 31 | float getAverage() const; 32 | }; 33 | 34 | struct GraphParams 35 | { 36 | void setRect(int ix, int iy, int iw, int ih, int ipad); 37 | void setValueRange(float ivmin, float ivmax, int indiv, const char* iunits); 38 | 39 | int x, y, w, h, pad; 40 | float vmin, vmax; 41 | int ndiv; 42 | char units[16]; 43 | }; 44 | 45 | void drawGraphBackground(const GraphParams* p); 46 | 47 | void drawGraph(const GraphParams* p, const ValueHistory* graph, 48 | int idx, const char* label, const unsigned int col); 49 | 50 | 51 | #endif // VALUEHISTORY_H -------------------------------------------------------------------------------- /RecastDemo/Include/imgui.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2009-2010 Mikko Mononen memon@inside.org 3 | // 4 | // This software is provided 'as-is', without any express or implied 5 | // warranty. In no event will the authors be held liable for any damages 6 | // arising from the use of this software. 7 | // Permission is granted to anyone to use this software for any purpose, 8 | // including commercial applications, and to alter it and redistribute it 9 | // freely, subject to the following restrictions: 10 | // 1. The origin of this software must not be misrepresented; you must not 11 | // claim that you wrote the original software. If you use this software 12 | // in a product, an acknowledgment in the product documentation would be 13 | // appreciated but is not required. 14 | // 2. Altered source versions must be plainly marked as such, and must not be 15 | // misrepresented as being the original software. 16 | // 3. This notice may not be removed or altered from any source distribution. 17 | // 18 | 19 | #ifndef IMGUI_H 20 | #define IMGUI_H 21 | 22 | enum imguiMouseButton 23 | { 24 | IMGUI_MBUT_LEFT = 0x01, 25 | IMGUI_MBUT_RIGHT = 0x02, 26 | }; 27 | 28 | enum imguiTextAlign 29 | { 30 | IMGUI_ALIGN_LEFT, 31 | IMGUI_ALIGN_CENTER, 32 | IMGUI_ALIGN_RIGHT, 33 | }; 34 | 35 | inline unsigned int imguiRGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a=255) 36 | { 37 | return (r) | (g << 8) | (b << 16) | (a << 24); 38 | } 39 | 40 | void imguiBeginFrame(int mx, int my, unsigned char mbut, int scroll); 41 | void imguiEndFrame(); 42 | 43 | bool imguiBeginScrollArea(const char* name, int x, int y, int w, int h, int* scroll); 44 | void imguiEndScrollArea(); 45 | 46 | void imguiIndent(); 47 | void imguiUnindent(); 48 | void imguiSeparator(); 49 | void imguiSeparatorLine(); 50 | 51 | bool imguiButton(const char* text, bool enabled = true); 52 | bool imguiItem(const char* text, bool enabled = true); 53 | bool imguiCheck(const char* text, bool checked, bool enabled = true); 54 | bool imguiCollapse(const char* text, const char* subtext, bool checked, bool enabled = true); 55 | void imguiLabel(const char* text); 56 | void imguiValue(const char* text); 57 | bool imguiSlider(const char* text, float* val, float vmin, float vmax, float vinc, bool enabled = true); 58 | 59 | void imguiDrawText(int x, int y, int align, const char* text, unsigned int color); 60 | void imguiDrawLine(float x0, float y0, float x1, float y1, float r, unsigned int color); 61 | void imguiDrawRoundedRect(float x, float y, float w, float h, float r, unsigned int color); 62 | void imguiDrawRect(float x, float y, float w, float h, unsigned int color); 63 | 64 | // Pull render interface. 65 | enum imguiGfxCmdType 66 | { 67 | IMGUI_GFXCMD_RECT, 68 | IMGUI_GFXCMD_TRIANGLE, 69 | IMGUI_GFXCMD_LINE, 70 | IMGUI_GFXCMD_TEXT, 71 | IMGUI_GFXCMD_SCISSOR, 72 | }; 73 | 74 | struct imguiGfxRect 75 | { 76 | short x,y,w,h,r; 77 | }; 78 | 79 | struct imguiGfxText 80 | { 81 | short x,y,align; 82 | const char* text; 83 | }; 84 | 85 | struct imguiGfxLine 86 | { 87 | short x0,y0,x1,y1,r; 88 | }; 89 | 90 | struct imguiGfxCmd 91 | { 92 | char type; 93 | char flags; 94 | char pad[2]; 95 | unsigned int col; 96 | union 97 | { 98 | imguiGfxLine line; 99 | imguiGfxRect rect; 100 | imguiGfxText text; 101 | }; 102 | }; 103 | 104 | const imguiGfxCmd* imguiGetRenderQueue(); 105 | int imguiGetRenderQueueSize(); 106 | 107 | 108 | #endif // IMGUI_H 109 | -------------------------------------------------------------------------------- /RecastDemo/Include/imguiRenderGL.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2009-2010 Mikko Mononen memon@inside.org 3 | // 4 | // This software is provided 'as-is', without any express or implied 5 | // warranty. In no event will the authors be held liable for any damages 6 | // arising from the use of this software. 7 | // Permission is granted to anyone to use this software for any purpose, 8 | // including commercial applications, and to alter it and redistribute it 9 | // freely, subject to the following restrictions: 10 | // 1. The origin of this software must not be misrepresented; you must not 11 | // claim that you wrote the original software. If you use this software 12 | // in a product, an acknowledgment in the product documentation would be 13 | // appreciated but is not required. 14 | // 2. Altered source versions must be plainly marked as such, and must not be 15 | // misrepresented as being the original software. 16 | // 3. This notice may not be removed or altered from any source distribution. 17 | // 18 | 19 | #ifndef IMGUI_RENDER_GL_H 20 | #define IMGUI_RENDER_GL_H 21 | 22 | bool imguiRenderGLInit(const char* fontpath); 23 | void imguiRenderGLDestroy(); 24 | void imguiRenderGLDraw(); 25 | 26 | #endif // IMGUI_RENDER_GL_H -------------------------------------------------------------------------------- /RecastDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | Icon.icns 11 | CFBundleIdentifier 12 | com.yourcompany.${PRODUCT_NAME:identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1.0 23 | NSMainNibFile 24 | MainMenu 25 | NSPrincipalClass 26 | NSApplication 27 | 28 | 29 | -------------------------------------------------------------------------------- /RecastDemo/Source/Filelist.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2009-2010 Mikko Mononen memon@inside.org 3 | // 4 | // This software is provided 'as-is', without any express or implied 5 | // warranty. In no event will the authors be held liable for any damages 6 | // arising from the use of this software. 7 | // Permission is granted to anyone to use this software for any purpose, 8 | // including commercial applications, and to alter it and redistribute it 9 | // freely, subject to the following restrictions: 10 | // 1. The origin of this software must not be misrepresented; you must not 11 | // claim that you wrote the original software. If you use this software 12 | // in a product, an acknowledgment in the product documentation would be 13 | // appreciated but is not required. 14 | // 2. Altered source versions must be plainly marked as such, and must not be 15 | // misrepresented as being the original software. 16 | // 3. This notice may not be removed or altered from any source distribution. 17 | // 18 | 19 | #include "Filelist.h" 20 | #include 21 | #include 22 | #include 23 | #ifdef WIN32 24 | # include 25 | #else 26 | # include 27 | #endif 28 | 29 | static void fileListAdd(FileList& list, const char* path) 30 | { 31 | if (list.size >= FileList::MAX_FILES) 32 | return; 33 | int n = strlen(path); 34 | list.files[list.size] = new char[n+1]; 35 | strcpy(list.files[list.size], path); 36 | list.size++; 37 | } 38 | 39 | static void fileListClear(FileList& list) 40 | { 41 | for (int i = 0; i < list.size; ++i) 42 | delete [] list.files[i]; 43 | list.size = 0; 44 | } 45 | 46 | FileList::FileList() : size(0) 47 | { 48 | memset(files, 0, sizeof(char*)*MAX_FILES); 49 | } 50 | 51 | FileList::~FileList() 52 | { 53 | fileListClear(*this); 54 | } 55 | 56 | static int cmp(const void* a, const void* b) 57 | { 58 | return strcmp(*(const char**)a, *(const char**)b); 59 | } 60 | 61 | void scanDirectory(const char* path, const char* ext, FileList& list) 62 | { 63 | fileListClear(list); 64 | 65 | #ifdef WIN32 66 | _finddata_t dir; 67 | char pathWithExt[260]; 68 | long fh; 69 | strcpy(pathWithExt, path); 70 | strcat(pathWithExt, "/*"); 71 | strcat(pathWithExt, ext); 72 | fh = _findfirst(pathWithExt, &dir); 73 | if (fh == -1L) 74 | return; 75 | do 76 | { 77 | fileListAdd(list, dir.name); 78 | } 79 | while (_findnext(fh, &dir) == 0); 80 | _findclose(fh); 81 | #else 82 | dirent* current = 0; 83 | DIR* dp = opendir(path); 84 | if (!dp) 85 | return; 86 | 87 | while ((current = readdir(dp)) != 0) 88 | { 89 | int len = strlen(current->d_name); 90 | if (len > 4 && strncmp(current->d_name+len-4, ext, 4) == 0) 91 | { 92 | fileListAdd(list, current->d_name); 93 | } 94 | } 95 | closedir(dp); 96 | #endif 97 | 98 | if (list.size > 1) 99 | qsort(list.files, list.size, sizeof(char*), cmp); 100 | } 101 | -------------------------------------------------------------------------------- /RecastDemo/Source/PerfTimer.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2009-2010 Mikko Mononen memon@inside.org 3 | // 4 | // This software is provided 'as-is', without any express or implied 5 | // warranty. In no event will the authors be held liable for any damages 6 | // arising from the use of this software. 7 | // Permission is granted to anyone to use this software for any purpose, 8 | // including commercial applications, and to alter it and redistribute it 9 | // freely, subject to the following restrictions: 10 | // 1. The origin of this software must not be misrepresented; you must not 11 | // claim that you wrote the original software. If you use this software 12 | // in a product, an acknowledgment in the product documentation would be 13 | // appreciated but is not required. 14 | // 2. Altered source versions must be plainly marked as such, and must not be 15 | // misrepresented as being the original software. 16 | // 3. This notice may not be removed or altered from any source distribution. 17 | // 18 | 19 | #include "PerfTimer.h" 20 | 21 | #if defined(WIN32) 22 | 23 | // Win32 24 | #include 25 | 26 | TimeVal getPerfTime() 27 | { 28 | __int64 count; 29 | QueryPerformanceCounter((LARGE_INTEGER*)&count); 30 | return count; 31 | } 32 | 33 | int getPerfDeltaTimeUsec(const TimeVal start, const TimeVal end) 34 | { 35 | static __int64 freq = 0; 36 | if (freq == 0) 37 | QueryPerformanceFrequency((LARGE_INTEGER*)&freq); 38 | __int64 elapsed = end - start; 39 | return (int)(elapsed*1000000 / freq); 40 | } 41 | 42 | #else 43 | 44 | // Linux, BSD, OSX 45 | 46 | #include 47 | 48 | TimeVal getPerfTime() 49 | { 50 | timeval now; 51 | gettimeofday(&now, 0); 52 | return (TimeVal)now.tv_sec*1000000L + (TimeVal)now.tv_usec; 53 | } 54 | 55 | int getPerfDeltaTimeUsec(const TimeVal start, const TimeVal end) 56 | { 57 | return (int)(end - start); 58 | } 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /RecastDemo/Source/ValueHistory.cpp: -------------------------------------------------------------------------------- 1 | #include "ValueHistory.h" 2 | #include "imgui.h" 3 | #include 4 | #include 5 | 6 | #ifdef WIN32 7 | # define snprintf _snprintf 8 | #endif 9 | 10 | ValueHistory::ValueHistory() : 11 | m_hsamples(0) 12 | { 13 | for (int i = 0; i < MAX_HISTORY; ++i) 14 | m_samples[i] = 0; 15 | } 16 | 17 | ValueHistory::~ValueHistory() 18 | { 19 | } 20 | 21 | float ValueHistory::getSampleMin() const 22 | { 23 | float val = m_samples[0]; 24 | for (int i = 1; i < MAX_HISTORY; ++i) 25 | if (m_samples[i] < val) 26 | val = m_samples[i]; 27 | return val; 28 | } 29 | 30 | float ValueHistory::getSampleMax() const 31 | { 32 | float val = m_samples[0]; 33 | for (int i = 1; i < MAX_HISTORY; ++i) 34 | if (m_samples[i] > val) 35 | val = m_samples[i]; 36 | return val; 37 | } 38 | 39 | float ValueHistory::getAverage() const 40 | { 41 | float val = 0; 42 | for (int i = 0; i < MAX_HISTORY; ++i) 43 | val += m_samples[i]; 44 | return val/(float)MAX_HISTORY; 45 | } 46 | 47 | void GraphParams::setRect(int ix, int iy, int iw, int ih, int ipad) 48 | { 49 | x = ix; 50 | y = iy; 51 | w = iw; 52 | h = ih; 53 | pad = ipad; 54 | } 55 | 56 | void GraphParams::setValueRange(float ivmin, float ivmax, int indiv, const char* iunits) 57 | { 58 | vmin = ivmin; 59 | vmax = ivmax; 60 | ndiv = indiv; 61 | strcpy(units, iunits); 62 | } 63 | 64 | void drawGraphBackground(const GraphParams* p) 65 | { 66 | // BG 67 | imguiDrawRoundedRect((float)p->x, (float)p->y, (float)p->w, (float)p->h, (float)p->pad, imguiRGBA(64,64,64,128)); 68 | 69 | const float sy = (p->h-p->pad*2) / (p->vmax-p->vmin); 70 | const float oy = p->y+p->pad-p->vmin*sy; 71 | 72 | char text[64]; 73 | 74 | // Divider Lines 75 | for (int i = 0; i <= p->ndiv; ++i) 76 | { 77 | const float u = (float)i/(float)p->ndiv; 78 | const float v = p->vmin + (p->vmax-p->vmin)*u; 79 | snprintf(text, 64, "%.2f %s", v, p->units); 80 | const float fy = oy + v*sy; 81 | imguiDrawText(p->x + p->w - p->pad, (int)fy-4, IMGUI_ALIGN_RIGHT, text, imguiRGBA(0,0,0,255)); 82 | imguiDrawLine((float)p->x + (float)p->pad, fy, (float)p->x + (float)p->w - (float)p->pad - 50, fy, 1.0f, imguiRGBA(0,0,0,64)); 83 | } 84 | } 85 | 86 | void drawGraph(const GraphParams* p, const ValueHistory* graph, 87 | int idx, const char* label, const unsigned int col) 88 | { 89 | const float sx = (p->w - p->pad*2) / (float)graph->getSampleCount(); 90 | const float sy = (p->h - p->pad*2) / (p->vmax - p->vmin); 91 | const float ox = (float)p->x + (float)p->pad; 92 | const float oy = (float)p->y + (float)p->pad - p->vmin*sy; 93 | 94 | // Values 95 | float px=0, py=0; 96 | for (int i = 0; i < graph->getSampleCount()-1; ++i) 97 | { 98 | const float x = ox + i*sx; 99 | const float y = oy + graph->getSample(i)*sy; 100 | if (i > 0) 101 | imguiDrawLine(px,py, x,y, 2.0f, col); 102 | px = x; 103 | py = y; 104 | } 105 | 106 | // Label 107 | const int size = 15; 108 | const int spacing = 10; 109 | int ix = p->x + p->w + 5; 110 | int iy = p->y + p->h - (idx+1)*(size+spacing); 111 | 112 | imguiDrawRoundedRect((float)ix, (float)iy, (float)size, (float)size, 2.0f, col); 113 | 114 | char text[64]; 115 | snprintf(text, 64, "%.2f %s", graph->getAverage(), p->units); 116 | imguiDrawText(ix+size+5, iy+3, IMGUI_ALIGN_LEFT, label, imguiRGBA(255,255,255,192)); 117 | imguiDrawText(ix+size+150, iy+3, IMGUI_ALIGN_RIGHT, text, imguiRGBA(255,255,255,128)); 118 | } 119 | 120 | -------------------------------------------------------------------------------- /RecastDemo/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/educharlie/HNA-Algorithm/388e185b8ea4e5bd82c77cb7358b38bca61661d7/RecastDemo/screenshot.png --------------------------------------------------------------------------------