Fix bug where allocated paths were never returned
This commit is contained in:
@@ -213,7 +213,7 @@ void render(float dt, void *userData) {
|
||||
static PathNode *heap = NULL;
|
||||
if (!heap)
|
||||
heap = bzHeapCreate(PathNode, game->map.width * game->map.height);
|
||||
if (!ecs_has(ECS, game->entity, Path)) {
|
||||
if (!ecs_has(ECS, game->entity, Path) && IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
|
||||
Path path = {};
|
||||
const Position *start = ecs_get(ECS, game->entity, Position);
|
||||
findPath(&(PathfindingDesc) {
|
||||
@@ -227,7 +227,7 @@ void render(float dt, void *userData) {
|
||||
.outPath=&path,
|
||||
.pool=game->pools.pathData
|
||||
});
|
||||
if (path.paths && IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
|
||||
if (path.paths) {
|
||||
ecs_set_ptr(ECS, game->entity, Path, &path);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ bool findPath(const PathfindingDesc *desc) {
|
||||
.weight = gCost + toTargetCost,
|
||||
.gCost = gCost,
|
||||
.hCost = toTargetCost,
|
||||
.pos = (TilePosition) {x, y}
|
||||
.pos = curPos
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -57,7 +57,6 @@ void updatePos(ecs_iter_t *it) {
|
||||
for (i32 i = 0; i < it->count; i++) {
|
||||
Vector2 d = Vector2Subtract(target[i], pos[i]);
|
||||
if (Vector2LengthSqr(d) < 1) {
|
||||
bzLogInfo("Done");
|
||||
ecs_remove(ECS, it->entities[i], TargetPosition);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user