summaryrefslogtreecommitdiff
path: root/src/path_finder.cpp
diff options
context:
space:
mode:
authorPaweł Redman <pawel.redman@gmail.com>2017-10-21 14:40:20 +0200
committerPaweł Redman <pawel.redman@gmail.com>2017-10-21 14:40:20 +0200
commitf08fb7293382dbaf240860119d128486ada62221 (patch)
treece9a85f47b3dacc98f75a9f73f1378d4c00ec915 /src/path_finder.cpp
parent42fece714e30b899208a90183a571452eb35811e (diff)
Improve short paths and do some refactoring.
Diffstat (limited to 'src/path_finder.cpp')
-rw-r--r--src/path_finder.cpp14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/path_finder.cpp b/src/path_finder.cpp
index ab300dc..8ca0ccc 100644
--- a/src/path_finder.cpp
+++ b/src/path_finder.cpp
@@ -78,10 +78,13 @@ void path_finder_t::find_r(tile_index_t index, float dist)
path.pop_back();
}
-void path_finder_t::find(void)
+bool path_finder_t::find(void)
{
tile_index_t start;
+ if ((src - dst).len() < 1.0f)
+ return true;
+
start = tile_index_at(src) - base;
nodes[start[1] * width + start[0]].accessible = false;
@@ -98,21 +101,18 @@ void path_finder_t::find(void)
find_r(next, v2f_t(offset).len());
}
+
+ return shortest_path.size() > 0;
}
-bool path_finder_t::export_path(std::list<v2f_t> *list)
+void path_finder_t::export_path(std::list<v2f_t> *list)
{
- if (!shortest_path.size())
- return false;
-
list->clear();
for (tile_index_t &index : shortest_path)
list->push_back(v2f_t(index + base) + tile_center);
list->push_back(dst);
-
- return true;
}
} // namespace world