feat: People go walkies
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
typedef struct navSearchNodeState navSearchNodeState;
|
||||
struct navSearchNodeState{
|
||||
bool visited;
|
||||
U64 distance;
|
||||
F64 distance;
|
||||
U32 shortest;
|
||||
bool addedToUnvisited;
|
||||
};
|
||||
@@ -53,6 +53,12 @@ U32 getLowestState(U32 unfinishedIndexes[128], U32 unfinishedCount, navSearchSta
|
||||
|
||||
// Generate a path to follow between the start and end node.
|
||||
NavPath Nav_Path(NavMesh *mesh, U32 start, U32 end) {
|
||||
// This is a stupid fix, since it's easier to work backwards
|
||||
// to generate a path, I'm swapping the start / end, to generate
|
||||
// it backwards
|
||||
U32 tmp = end;
|
||||
end = start;
|
||||
start = tmp;
|
||||
navSearchState state = initState(start, mesh->nodeCount);
|
||||
U32 unfinishedCount = 1;
|
||||
U32 unfinishedIndexes[NAV_MAX_NODES] = {start};
|
||||
@@ -68,9 +74,9 @@ NavPath Nav_Path(NavMesh *mesh, U32 start, U32 end) {
|
||||
NavConnection *connection = &mesh->nodes[lowestNodeIndex].connections[connectionI];
|
||||
navSearchNodeState *testNode = &state.nodeStates[connection->NodeIndex];
|
||||
if(testNode->visited) {continue;}
|
||||
U32 distance = cast(U32) (state.nodeStates[lowestNodeIndex].distance + connection->Cost);
|
||||
distance += cast(U32) (mesh->nodes[end].pos.x - mesh->nodes[connection->NodeIndex].pos.x);
|
||||
distance += cast(U32) (mesh->nodes[end].pos.y - mesh->nodes[connection->NodeIndex].pos.y);
|
||||
F64 distance = cast(F64) (state.nodeStates[lowestNodeIndex].distance + connection->Cost);
|
||||
distance += cast(F64) Abs((mesh->nodes[end].pos.x - mesh->nodes[connection->NodeIndex].pos.x));
|
||||
distance += cast(F64) Abs((mesh->nodes[end].pos.y - mesh->nodes[connection->NodeIndex].pos.y));
|
||||
if(testNode->distance > distance) {
|
||||
testNode->distance = distance;
|
||||
testNode->shortest = lowestNodeIndex;
|
||||
|
||||
Reference in New Issue
Block a user