From 6ab51bfb002af08da74a693f386c4154d2c4108a Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Mon, 6 Nov 2017 20:17:58 +0000 Subject: More support for cflags. --- src/common.hpp | 6 ++++-- src/path_finder.cpp | 9 +++------ src/world.cpp | 13 ++++++++----- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/common.hpp b/src/common.hpp index 0785a79..b7ce218 100644 --- a/src/common.hpp +++ b/src/common.hpp @@ -110,9 +110,11 @@ namespace world { // FIXME: iterators instead of returning std::lists std::list get_sectors(rectf_t rect); - std::list get_entities(rectf_t rect); + std::list get_entities(rectf_t rect, cflags_t cflags); std::list get_render_entities(rectf_t rect); + bool test_rect(rectf_t rect, cflags_t cflags); + void debug_point(sf::Vector2f point); }; @@ -154,7 +156,7 @@ namespace world { ~path_finder_t(); void setup_nodes(v2f_t src_, v2f_t dst_, cflags_t cflags_); - void eliminate_nodes(cmodel_t cmodel); + void eliminate_nodes(rectf_t rect); void find_r(tile_index_t index, float dist, float limit); bool find(void); void export_path(std::list *list); diff --git a/src/path_finder.cpp b/src/path_finder.cpp index 3d97df7..aeded09 100644 --- a/src/path_finder.cpp +++ b/src/path_finder.cpp @@ -42,16 +42,13 @@ void path_finder_t::setup_nodes(v2f_t src_, v2f_t dst_, cflags_t cflags_) nodes[i].dist = INFINITY; } -void path_finder_t::eliminate_nodes(cmodel_t cmodel) +void path_finder_t::eliminate_nodes(rectf_t bounds) { rect_t index_bounds; tile_index_t index; - if (!(cmodel.cflags & cflags)) - return; - - index_bounds[0] = tile_index_t(cmodel.bounds[0].floor()) - base; - index_bounds[1] = tile_index_t(cmodel.bounds[1].ceil()) - base; + index_bounds[0] = tile_index_t(bounds[0].floor()) - base; + index_bounds[1] = tile_index_t(bounds[1].ceil()) - base; for (index[1] = index_bounds[0][1]; index[1] <= index_bounds[1][1]; index[1]++) for (index[0] = index_bounds[0][0]; index[0] <= index_bounds[1][0]; index[0]++) { diff --git a/src/world.cpp b/src/world.cpp index d9789ad..ab3ef92 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -99,9 +99,9 @@ bool world_t::find_path(v2f_t src, v2f_t dst, cmodel_t *cmodel, entity_t *ignore bounds = rectf_t(src, dst).norm(); - for (entity_t *ent : get_entities(bounds)) + for (entity_t *ent : get_entities(bounds, cmodel->cflags)) if (ent != ignore) - finder.eliminate_nodes(ent->cmodel); + finder.eliminate_nodes(ent->cmodel.bounds); if (!finder.find()) return false; @@ -169,7 +169,7 @@ std::list world_t::get_sectors(rectf_t rect) return list; } -std::list world_t::get_entities(rectf_t rect) +std::list world_t::get_entities(rectf_t rect, cflags_t cflags) { static size_t cookie = 0; std::list list; @@ -181,10 +181,13 @@ std::list world_t::get_entities(rectf_t rect) if (ent->cookie == cookie) continue; - if (!(rect && ent->cmodel.bounds)) + ent->cookie = cookie; + + if (!(ent->cmodel.cflags & cflags)) continue; - ent->cookie = cookie; + if (!(rect && ent->cmodel.bounds)) + continue; list.push_back(ent); } -- cgit