summaryrefslogtreecommitdiffhomepage
path: root/src/search-astar.hpp
blob: 61553f80c1b60c302e7e137ab5d66ee372cb5031 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#pragma once
#include "compat/safe-ptr.hpp"
#include "search-constants.hpp"
#include "search-pred.hpp"
#include "object-id.hpp"
#include <Corrade/Containers/Array.h>

namespace floormat::Search { struct cache; }

namespace floormat {

class world;
struct point;
struct path_search_result;

class astar
{
public:
    struct visited;
    using pred = Search::pred;

    astar();
    ~astar() noexcept;
    void reserve(size_t capacity);
    void clear();

    // todo add simple bresenham short-circuit
    path_search_result Dijkstra(world& w, point from, point to,
                                object_id own_id, uint32_t max_dist, Vector2ub own_size,
                                int debug = 0, const pred& p = Search::never_continue());

private:
    static constexpr auto initial_capacity = TILE_COUNT * 16 * Search::div_factor*Search::div_factor;

    void add_to_heap(uint32_t id);
    uint32_t pop_from_heap();

    safe_ptr<struct Search::cache> _cache;
    Array<visited> nodes;
    Array<uint32_t> Q;
    Array<point> temp_nodes;
};

} // namespace floormat