-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathsector.h
129 lines (109 loc) · 3.05 KB
/
sector.h
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// Copyright 2024-2025 the openage authors. See copying.md for legal info.
#pragma once
#include <cstddef>
#include <memory>
#include <vector>
#include "coord/chunk.h"
#include "pathfinding/portal.h"
#include "pathfinding/types.h"
namespace openage::path {
class CostField;
class Portal;
/**
* Sector in a grid for flow field pathfinding.
*
* Sectors consist of a cost field and a list of portals connecting them to adjacent
* sectors.
*/
class Sector {
public:
/**
* Create a new sector with a specified ID and an uninitialized cost field.
*
* @param id ID of the sector. Should be unique per grid.
* @param position Position of the sector in the grid.
* @param field_size Size of the cost field.
*/
Sector(sector_id_t id,
const coord::chunk &position,
size_t field_size);
/**
* Create a new sector with a specified ID and an existing cost field.
*
* @param id ID of the sector. Should be unique per grid.
* @param position Position of the sector in the grid.
* @param cost_field Cost field of the sector.
*/
Sector(sector_id_t id,
const coord::chunk &position,
const std::shared_ptr<CostField> &cost_field);
/**
* Get the ID of this sector.
*
* IDs are unique per grid.
*
* @return ID of the sector.
*/
const sector_id_t &get_id() const;
/**
* Get the position of this sector in the grid.
*
* @return Position of the sector (absolute on the grid).
*/
const coord::chunk &get_position() const;
/**
* Get the cost field of this sector.
*
* @return Cost field of this sector.
*/
const std::shared_ptr<CostField> &get_cost_field() const;
/**
* Get the portals connecting this sector to other sectors.
*
* @return Outgoing portals of this sector.
*/
const std::vector<std::shared_ptr<Portal>> &get_portals() const;
/**
* Add a portal to another sector.
*
* @param portal Portal to another sector.
*/
void add_portal(const std::shared_ptr<Portal> &portal);
/**
* Find portals connecting this sector to another sector.
*
* @param other Sector to which the portals should connect.
* @param direction Direction from this sector to \p other sector.
* @param next_id ID of the next portal to be created. Should be unique per grid.
*
* @return Portals connecting this sector to \p other sector.
*/
std::vector<std::shared_ptr<Portal>> find_portals(const std::shared_ptr<Sector> &other,
PortalDirection direction,
portal_id_t next_id) const;
/**
* Connect all portals that are mutually reachable.
*
* This method should be called after all sectors and portals have
* been created and initialized.
*/
void connect_exits();
private:
/**
* ID of the sector.
*/
sector_id_t id;
/**
* Position of the sector (absolute on the grid).
*/
coord::chunk position;
/**
* Cost field of the sector.
*/
std::shared_ptr<CostField> cost_field;
/**
* Portals of the sector.
*/
std::vector<std::shared_ptr<Portal>> portals;
};
} // namespace openage::path