Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 41 additions & 43 deletions HierarchicalPathfinding/Include/Graph.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#ifndef __GRAPH_H__
#define __GRAPH_H__
#ifndef GRAPH_H
#define GRAPH_H

#include "DetourCommon.h"
#include "DetourAlloc.h"
#include <vector>
#include <map>
#include <cstring>


const int maxInternalPath = 256;
Expand All @@ -16,68 +17,66 @@ 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;

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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -143,4 +141,4 @@ typedef unsigned int dtPolyRef;
}
};

#endif // __GRAPH_H__
#endif // GRAPH_H