diff --git a/HierarchicalPathfinding/Include/Graph.h b/HierarchicalPathfinding/Include/Graph.h index e6cfa7b..7c505f7 100755 --- a/HierarchicalPathfinding/Include/Graph.h +++ b/HierarchicalPathfinding/Include/Graph.h @@ -1,10 +1,11 @@ -#ifndef __GRAPH_H__ -#define __GRAPH_H__ +#ifndef GRAPH_H +#define GRAPH_H #include "DetourCommon.h" #include "DetourAlloc.h" #include #include +#include const int maxInternalPath = 256; @@ -16,50 +17,49 @@ class Graph{ typedef unsigned int dtPolyRef; -public: - - struct IntraEdge - { - int startPosId; - int endPosId; - int nPath; - float cost; - dtPolyRef path[maxInternalPath]; - }; - - struct Edge - { - dtPolyRef targetNodeId; - int idPos; - int idPoly; - float pos[3]; - }; - - struct Node - { - dtPolyRef idNode; - dtPolyRef idParent; - - Edge *edges; - unsigned int numEdges; - - IntraEdge *intraEdges; - unsigned int numIntraEdges; - +public: + + struct IntraEdge + { + int startPosId; + int endPosId; + int nPath; + float cost; + dtPolyRef path[maxInternalPath]; + }; + + struct Edge + { + dtPolyRef targetNodeId; + int idPos; + int idPoly; + float pos[3]; + }; + + struct Node + { + dtPolyRef idNode; + dtPolyRef idParent; + + Edge *edges; + unsigned int numEdges; + + IntraEdge *intraEdges; + unsigned int numIntraEdges; + void InitEdge(int maxEdgesPerNode) { numEdges = 0; - edges = 0; edges = (Edge*)dtAlloc(sizeof(Edge)*maxEdgesPerNode, DT_ALLOC_PERM); memset(edges, 0, sizeof(Edge)*maxEdgesPerNode); - } - + } + void DestroyEdge() { dtFree(edges); numEdges = 0; - } - + } + void InitIntraEdge() { int maxIntraEdgesPerNode = numEdges * numEdges; @@ -67,17 +67,16 @@ typedef unsigned int dtPolyRef; if(maxIntraEdgesPerNode > 0) { numIntraEdges = 0; - intraEdges = 0; intraEdges = (IntraEdge*)dtAlloc(sizeof(IntraEdge)*maxIntraEdgesPerNode, DT_ALLOC_PERM); memset(intraEdges, 0, sizeof(IntraEdge)*maxIntraEdgesPerNode); } - } - + } + void DestroyIntraEdge() { dtFree(intraEdges); numIntraEdges = 0; - } + } }; Node* nodes; @@ -125,7 +124,6 @@ typedef unsigned int dtPolyRef; void Init(int numMaxNodes) { numNodes = 0; - nodes = 0; nodes = (Node*)dtAlloc(sizeof(Node)*numMaxNodes, DT_ALLOC_PERM); memset(nodes, 0, sizeof(Node)*numMaxNodes); } @@ -143,4 +141,4 @@ typedef unsigned int dtPolyRef; } }; -#endif // __GRAPH_H__ \ No newline at end of file +#endif // GRAPH_H