Skip to content

Commit

Permalink
w
Browse files Browse the repository at this point in the history
  • Loading branch information
sthalik committed Mar 24, 2024
1 parent edf5b8a commit a59e434
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/search-astar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace floormat {

class world;
struct point;
class path_search_result;
struct path_search_result;

class astar
{
Expand Down
2 changes: 1 addition & 1 deletion src/search-node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct path_search_result::pair

struct path_search_result::node
{
friend class path_search_result;
friend struct path_search_result;
friend struct test_app;

node() noexcept;
Expand Down
23 changes: 22 additions & 1 deletion src/search-result.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ namespace floormat {

namespace {

constexpr size_t min_length = TILE_MAX_DIM*2;
constexpr auto min_length = TILE_MAX_DIM*2;

void simplify_path(const std::vector<point>& src, std::vector<path_search_result::pair>& dest)
{
dest.clear();
fm_assert(!src.empty());

}

} // namespace

Expand Down Expand Up @@ -77,6 +84,19 @@ bool path_search_result::is_found() const { return _found; }
void path_search_result::set_found(bool value) { _found = value; }
uint32_t path_search_result::distance() const { return _distance; }
void path_search_result::set_distance(uint32_t dist) { _distance = dist; }
bool path_search_result::is_simplified() const { /*fm_assert(!_node->vec.empty());*/ return !_node->vec_.empty(); }
auto path_search_result::simplified() -> ArrayView<const pair>
{
if (!_node->vec_.empty())
return { _node->vec_.data(), _node->vec_.size() };
else
{
//fm_assert(!_node->vec.empty());
simplify_path(_node->vec, _node->vec_);
fm_assert(!_node->vec_.empty());
return { _node->vec_.data(), _node->vec_.size() };
}
}

auto path_search_result::data() const -> const point* { return _node->vec.data(); }
path_search_result::operator bool() const { return !_node->vec.empty(); }
Expand All @@ -93,6 +113,7 @@ const point& path_search_result::operator[](size_t index) const
fm_debug_assert(index < _node->vec.size());
return data()[index];
}

vector_wrapper<point, vector_wrapper_repr::ref> path_search_result::raw_path() { fm_assert(_node); return {_node->vec}; }
ArrayView<const point> path_search_result::path() const { fm_assert(_node); return {_node->vec.data(), _node->vec.size()}; }

Expand Down
23 changes: 11 additions & 12 deletions src/search-result.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma once
#include "compat/defs.hpp"
#include "compat/vector-wrapper-fwd.hpp"
#include "src/global-coords.hpp"
#include <Corrade/Containers/Pointer.h>
Expand All @@ -8,20 +7,12 @@ namespace floormat {

struct point;

class path_search_result final
struct path_search_result final
{
friend struct test_app;
struct pair;
struct node;

Pointer<node> _node;
float _time = 0;
uint32_t _cost = 0, _distance = (uint32_t)-1;
bool _found : 1 = false;

static Pointer<node> _pool; // NOLINT(*-avoid-non-const-global-variables)

public:
const point* data() const;
const point& operator[](size_t index) const;
size_t size() const;
Expand All @@ -34,10 +25,10 @@ class path_search_result final
uint32_t distance() const;
void set_distance(uint32_t dist);
bool is_simplified() const;
const pair& simplified();
ArrayView<const pair> simplified();

vector_wrapper<point, vector_wrapper_repr::ref> raw_path();
vector_wrapper<point, vector_wrapper_repr::ref> raw_simplified_path();
vector_wrapper<pair, vector_wrapper_repr::ref> raw_simplified_path();
ArrayView<const point> path() const;
explicit operator ArrayView<const point>() const;
explicit operator bool() const;
Expand All @@ -48,6 +39,14 @@ class path_search_result final
path_search_result(path_search_result&&) noexcept;
path_search_result& operator=(path_search_result&&) noexcept;
~path_search_result() noexcept;

private:
Pointer<node> _node;
float _time = 0;
uint32_t _cost = 0, _distance = (uint32_t)-1;
bool _found : 1 = false;

static Pointer<node> _pool; // NOLINT(*-avoid-non-const-global-variables)
};

} // namespace floormat

0 comments on commit a59e434

Please sign in to comment.