Buildings as entities instead of map layer
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
#include <raymath.h>
|
||||
|
||||
static i32 dst(TilePosition a, TilePosition b) {
|
||||
static i32 dst(Vec2i a, Vec2i b) {
|
||||
//i32 dX = a.x - b.x;
|
||||
//i32 dY = a.y - b.y;
|
||||
//return dX * dX + dY * dY;
|
||||
@@ -126,9 +126,8 @@ bool pathfindAStar(const PathfindingDesc *desc) {
|
||||
BZ_ASSERT(desc->alloc);
|
||||
BzTileMap *map = desc->map;
|
||||
|
||||
TilePosition start = {0}, target = {0};
|
||||
bzTileMapPosToTile(map, desc->start, &start.x, &start.y);
|
||||
bzTileMapPosToTile(map, desc->target, &target.x, &target.y);
|
||||
Vec2i start = bzTileMapPosToTile(map, desc->start);
|
||||
Vec2i target = bzTileMapPosToTile(map, desc->target);
|
||||
BZ_ASSERT(start.x >= 0 && start.x < map->width);
|
||||
BZ_ASSERT(start.y >= 0 && start.y < map->height);
|
||||
|
||||
@@ -178,7 +177,7 @@ bool pathfindAStar(const PathfindingDesc *desc) {
|
||||
foundPath = true;
|
||||
break;
|
||||
}
|
||||
TilePosition pos = node.pos;
|
||||
Vec2i pos = node.pos;
|
||||
PathNodeRecord *nodeRecord = &closedSet[pos.y * map->width + pos.x];
|
||||
nodeRecord->visited = true;
|
||||
nodeRecord->open = false;
|
||||
@@ -199,7 +198,7 @@ bool pathfindAStar(const PathfindingDesc *desc) {
|
||||
if (curRecord->visited)
|
||||
continue;
|
||||
|
||||
TilePosition curPos = {x, y};
|
||||
Vec2i curPos = {x, y};
|
||||
i32 gCost = node.gCost + dst(node.pos, curPos);
|
||||
if (curRecord->open) {
|
||||
i32 nodeIdx = curRecord->nodeIdx;
|
||||
@@ -234,7 +233,7 @@ bool pathfindAStar(const PathfindingDesc *desc) {
|
||||
|
||||
i32 pathLen = 0;
|
||||
if (foundPath && desc->outPath) {
|
||||
TilePosition pos = target;
|
||||
Vec2i pos = target;
|
||||
Path *out = desc->outPath;
|
||||
out->curWaypoint = 0;
|
||||
BZ_ASSERT(desc->pool);
|
||||
@@ -282,8 +281,8 @@ static void heapSwap(Heap *heap, i32 left, i32 right) {
|
||||
heap->arr[left] = heap->arr[right];
|
||||
heap->arr[right] = tmp;
|
||||
|
||||
TilePosition leftPos = heap->arr[left].pos;
|
||||
TilePosition rightPos = heap->arr[right].pos;
|
||||
Vec2i leftPos = heap->arr[left].pos;
|
||||
Vec2i rightPos = heap->arr[right].pos;
|
||||
|
||||
i32 leftIdx = leftPos.y * heap->mapWidth + leftPos.x;
|
||||
i32 rightIdx = rightPos.y * heap->mapWidth + rightPos.x;
|
||||
@@ -339,7 +338,7 @@ static void heapPush(Heap *heap, PathNode node) {
|
||||
heap->arr[heap->size] = node;
|
||||
heap->size++;
|
||||
|
||||
TilePosition pos = node.pos;
|
||||
Vec2i pos = node.pos;
|
||||
PathNodeRecord *record = &heap->records[pos.y * heap->mapWidth + pos.x];
|
||||
record->nodeIdx = heap->size - 1;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user