diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-09-11 04:18:11 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-09-11 14:20:10 +0200 |
commit | be8ab17542bea5d783166f320cf3ed02b7b88b20 (patch) | |
tree | 5bf6fae735faa69b84a87384cb48336e9cfa9fe6 /src | |
parent | 1af31374db91b0fd6091b27d4c199edaee989612 (diff) |
wip
Diffstat (limited to 'src')
-rw-r--r-- | src/path-search.cpp | 18 | ||||
-rw-r--r-- | src/path-search.hpp | 5 |
2 files changed, 13 insertions, 10 deletions
diff --git a/src/path-search.cpp b/src/path-search.cpp index 5558fa19..79ba5fa8 100644 --- a/src/path-search.cpp +++ b/src/path-search.cpp @@ -79,12 +79,11 @@ bool search::sample_rtree(world& w, global_coords coord, Vector2b offset, Vector return sample_rtree(w, coord, Vector2(center), Vector2(size), own_id); } -auto search::make_neighbor_tile_bbox(global_coords coord, Vector2ub own_size, rotation r) -> bbox +auto search::make_neighbor_tile_bbox(Vector2i coord, Vector2ub own_size, rotation r) -> bbox { constexpr auto full_tile = Vector2ui(iTILE_SIZE2*3/4); - constexpr auto tx = iTILE_SIZE2.x()*2u, ty = iTILE_SIZE2.y()*2u; + constexpr auto tx = full_tile.x()*2u, ty = full_tile.y()*2u; - fm_assert(Vector2i(own_size).product() != 0); const auto s = Math::max(Vector2ui(own_size), full_tile); const auto sx = s[0], sy = s[1]; @@ -93,14 +92,14 @@ auto search::make_neighbor_tile_bbox(global_coords coord, Vector2ub own_size, ro switch (r) { - case rotation::N: off = { 0, -1}; size = {sx, ty}; break; case rotation::E: off = { 1, 0}; size = {tx, sy}; break; - case rotation::S: off = { 0, 1}; size = {tx, sy}; break; - case rotation::W: off = {-1, 0}; size = {sx, ty}; break; + case rotation::N: off = { 0, -1}; size = {sx, ty}; break; + case rotation::S: off = { 0, 1}; size = {sx, ty}; break; + case rotation::W: off = {-1, 0}; size = {tx, sy}; break; default: fm_abort("wrong 4-way rotation enum value '%d", (int)r); } - auto center1 = Vector2i(coord.local()) * iTILE_SIZE2; + auto center1 = coord * iTILE_SIZE2; auto center2 = center1 + off*iTILE_SIZE2; auto center = (center1 + center2)/2; @@ -129,12 +128,15 @@ Optional<search_result> search::operator()(world& w, object_id own_id, Optional<search_result> search::operator()(world& w, const object& obj, global_coords to, Vector2b to_offset) { + constexpr auto full_tile = Vector2ub(iTILE_SIZE2*3/4); + auto size = Math::max(obj.bbox_size, full_tile); + // todo fixme // if bbox_offset is added to obj's offset, then all coordinates in the paths are shifted by bbox_offset. // maybe add handling to subtract bbox_offset from the returned path. // for that it needs to be passed into callees separately. fm_assert(obj.bbox_offset.isZero()); - return operator()(w, obj.id, obj.coord, obj.offset, obj.bbox_size, to, to_offset); + return operator()(w, obj.id, obj.coord, obj.offset, size, to, to_offset); } } // namespace floormat diff --git a/src/path-search.hpp b/src/path-search.hpp index 39fde1e4..f044a381 100644 --- a/src/path-search.hpp +++ b/src/path-search.hpp @@ -69,7 +69,6 @@ class search final }; struct obj_position { Vector2 center, size; }; - struct bbox { Vector2 min, max; }; chunk_cache cache; Array<global_coords> output; @@ -80,6 +79,8 @@ class search final void ensure_allocated(chunk_coords a, chunk_coords b); public: + struct bbox { Vector2 min, max; }; + // todo remember to check from.z() == to.z() // todo add simple bresenham short-circuit Optional<search_result> operator()(world& w, object_id own_id, global_coords from, Vector2b from_offset, Vector2ub size, global_coords to, Vector2b to_offset); @@ -89,7 +90,7 @@ public: static bool sample_rtree(world& w, chunk_coords_ ch0, Vector2 center, Vector2 size, object_id own_id); static bool sample_rtree(world& w, global_coords coord, Vector2b offset, Vector2ub size, object_id own_id); - static bbox make_neighbor_tile_bbox(global_coords coord, Vector2ub own_size, rotation r); + static bbox make_neighbor_tile_bbox(Vector2i coord, Vector2ub own_size, rotation r); static neighbors get_walkable_neighbor_tiles(world& w, global_coords pos, Vector2 size, object_id own_id); }; |