remove path.count redundancy
This commit is contained in:
+4
-4
@@ -91,7 +91,7 @@ entity_set_move_target :: proc(
|
||||
return false
|
||||
}
|
||||
ew.path_index[i] = 1
|
||||
if ew.path[i].count <= 1 {
|
||||
if len(ew.path[i].tiles) <= 1 {
|
||||
ew.move_state[i] = .Idle
|
||||
} else {
|
||||
ew.move_state[i] = .Moving
|
||||
@@ -118,7 +118,7 @@ entity_update_movement :: proc(ew: ^Entity_World, dt: f32) {
|
||||
|
||||
p := &ew.path[i]
|
||||
|
||||
if ew.path_index[i] >= p.count {
|
||||
if ew.path_index[i] >= len(p.tiles) {
|
||||
ew.move_state[i] = .Idle
|
||||
continue
|
||||
}
|
||||
@@ -137,7 +137,7 @@ entity_update_movement :: proc(ew: ^Entity_World, dt: f32) {
|
||||
ew.visual_position[i] = goal
|
||||
ew.path_index[i] += 1
|
||||
|
||||
if ew.path_index[i] >= p.count {
|
||||
if ew.path_index[i] >= len(p.tiles) {
|
||||
ew.move_state[i] = .Idle
|
||||
}
|
||||
} else {
|
||||
@@ -147,7 +147,7 @@ entity_update_movement :: proc(ew: ^Entity_World, dt: f32) {
|
||||
ew.position[i] = next
|
||||
ew.path_index[i] += 1
|
||||
|
||||
if ew.path_index[i] >= p.count {
|
||||
if ew.path_index[i] >= len(p.tiles) {
|
||||
ew.move_state[i] = .Idle
|
||||
}
|
||||
|
||||
|
||||
@@ -2,14 +2,12 @@ package main
|
||||
|
||||
Path :: struct {
|
||||
tiles: [dynamic]Tile_Coord,
|
||||
count: int,
|
||||
}
|
||||
|
||||
max_path_int :: 1_000_000_000
|
||||
|
||||
path_clear :: proc(path: ^Path) {
|
||||
resize(&path.tiles, 0)
|
||||
path.count = 0
|
||||
}
|
||||
|
||||
pathfind_bfs :: proc(tilemap: ^Tilemap, start, goal: Tile_Coord, path: ^Path) -> bool {
|
||||
@@ -18,7 +16,6 @@ pathfind_bfs :: proc(tilemap: ^Tilemap, start, goal: Tile_Coord, path: ^Path) ->
|
||||
if start == goal {
|
||||
resize(&path.tiles, 1)
|
||||
path.tiles[0] = start
|
||||
path.count = 1
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -83,7 +80,6 @@ pathfind_astar :: proc(tm: ^Tilemap, start, goal: Tile_Coord, path: ^Path) -> bo
|
||||
if start == goal {
|
||||
resize(&path.tiles, 1)
|
||||
path.tiles[0] = start
|
||||
path.count = 1
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -198,7 +194,6 @@ path_reconstruct :: proc(
|
||||
}
|
||||
|
||||
resize(&path.tiles, rev_count)
|
||||
path.count = rev_count
|
||||
|
||||
for i in 0 ..< rev_count {
|
||||
path.tiles[i] = rev[rev_count - 1 - i]
|
||||
@@ -210,6 +205,5 @@ path_reconstruct :: proc(
|
||||
path_destroy :: proc(path: ^Path) {
|
||||
delete(path.tiles)
|
||||
path.tiles = nil
|
||||
path.count = 0
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user