Skip to content

Commit

Permalink
Minor edge case fix on Micropather core
Browse files Browse the repository at this point in the history
  • Loading branch information
selimanac committed Jul 13, 2024
1 parent ece7ac0 commit 59d9d94
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 11 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ or you can add stable versions from [releases](https://github.com/selimanac/defo

## Examples

New examples are on the way.
Hexagon example: https://github.com/selimanac/defold-astar-hex-example

Old examples: https://github.com/selimanac/defold-astar-examples

Expand All @@ -29,6 +29,11 @@ I'd love to hear about your projects! Please share your released projects that u

## Release Notes

### 1.1.1

- Minor edge case fix on Micropather core.
- Minor code refactoring.

### 1.1.0

This is a major release. Consider it a Beta version. New examples on the way.
Expand Down
2 changes: 2 additions & 0 deletions astar/include/pather.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ int WorldAt(int16_t x, int16_t y);
void SetToWorldAt(int16_t x, int16_t y, int value);
void NodeToXY(void *node, int16_t *x, int16_t *y);
void *XYToNode(size_t x, size_t y);
void PushNeighbors(StateCost *nodeCost, MPVector<StateCost> *neighbors,
int16_t *nx, int16_t *ny, unsigned int a, unsigned int b);

float LeastCostEstimate(void *nodeStart, void *nodeEnd); // extern
void AdjacentCost(void *node, MPVector<StateCost> *neighbors); // extern
Expand Down
2 changes: 2 additions & 0 deletions astar/src/micropather/micropather.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ int MicroPather::Solve(void *startNode, void *endNode, MP_VECTOR<void *> *path,
// Could add a bunch more with a little tracking.
pathCache->AddNoSolution(endNode, &startNode, 1);
}

pathNodePool.Clear();
return NO_SOLUTION;
}

Expand Down
38 changes: 28 additions & 10 deletions astar/src/pather.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,13 @@ int Passable(int16_t nx, int16_t ny) {
return -1;
}

void PushNeighbors(StateCost *nodeCost, MPVector<StateCost> *neighbors,
int16_t *nx, int16_t *ny, unsigned int a, unsigned int b) {
nodeCost->state = XYToNode(*nx, *ny);
nodeCost->cost = Costs[a].costs[b];
neighbors->push_back(*nodeCost);
}

void AdjacentCost(void *node, MPVector<StateCost> *neighbors) {
int16_t x, y, nx, ny, pass;
NodeToXY(node, &x, &y);
Expand Down Expand Up @@ -278,14 +285,21 @@ void AdjacentCost(void *node, MPVector<StateCost> *neighbors) {
if (XYToNode(nx, ny) == XYToNode(pathTo.x, pathTo.y) &&
getEntity && getNearEntities == false) {

nodeCost.state = XYToNode(nx, ny);
nodeCost.cost = Costs[a].costs[b];
neighbors->push_back(nodeCost);
PushNeighbors(&nodeCost, neighbors, &nx, &ny, a, b);
/*
// TODO :add push_back to method
nodeCost.state = XYToNode(nx, ny);
nodeCost.cost = Costs[a].costs[b];
neighbors->push_back(nodeCost);
*/
} else if (getNearEntities) {

nodeCost.state = XYToNode(nx, ny);
nodeCost.cost = Costs[a].costs[b];
neighbors->push_back(nodeCost);
PushNeighbors(&nodeCost, neighbors, &nx, &ny, a, b);
/*
// TODO :add push_back to method
nodeCost.state = XYToNode(nx, ny);
nodeCost.cost = Costs[a].costs[b];
neighbors->push_back(nodeCost);
*/
}
}
}
Expand All @@ -294,9 +308,13 @@ void AdjacentCost(void *node, MPVector<StateCost> *neighbors) {

if (pass == Costs[a].tile_id) {
if (WorldAt(nx, ny) >= 0) {
nodeCost.state = XYToNode(nx, ny);
nodeCost.cost = Costs[a].costs[b];
neighbors->push_back(nodeCost);

PushNeighbors(&nodeCost, neighbors, &nx, &ny, a, b);
/*
// TODO :add push_back to method
nodeCost.state = XYToNode(nx, ny);
nodeCost.cost = Costs[a].costs[b];
neighbors->push_back(nodeCost);*/
}
}
}
Expand Down

0 comments on commit 59d9d94

Please sign in to comment.