-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathcost_field.h
141 lines (119 loc) · 2.97 KB
/
cost_field.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
130
131
132
133
134
135
136
137
138
139
140
141
// Copyright 2024-2025 the openage authors. See copying.md for legal info.
#pragma once
#include <cstddef>
#include <vector>
#include "pathfinding/types.h"
#include "time/time.h"
namespace openage {
namespace coord {
struct tile_delta;
} // namespace coord
namespace path {
/**
* Cost field in the flow-field pathfinding algorithm.
*/
class CostField {
public:
/**
* Create a square cost field with a specified size.
*
* @param size Side length of the field.
*/
CostField(size_t size);
/**
* Get the size of the cost field.
*
* @return Size of the cost field.
*/
size_t get_size() const;
/**
* Get the cost at a specified position.
*
* @param pos Coordinates of the cell (relative to field origin).
* @return Cost at the specified position.
*/
cost_t get_cost(const coord::tile_delta &pos) const;
/**
* Get the cost at a specified position.
*
* @param x X-coordinate of the cell.
* @param y Y-coordinate of the cell.
* @return Cost at the specified position.
*/
cost_t get_cost(size_t x, size_t y) const;
/**
* Get the cost at a specified position.
*
* @param idx Index of the cell.
* @return Cost at the specified position.
*/
cost_t get_cost(size_t idx) const;
/**
* Set the cost at a specified position.
*
* @param pos Coordinates of the cell (relative to field origin).
* @param cost Cost to set.
* @param valid_until Time at which the cost value expires.
*/
void set_cost(const coord::tile_delta &pos, cost_t cost, const time::time_t &valid_until);
/**
* Set the cost at a specified position.
*
* @param x X-coordinate of the cell.
* @param y Y-coordinate of the cell.
* @param cost Cost to set.
* @param valid_until Time at which the cost value expires.
*/
void set_cost(size_t x, size_t y, cost_t cost, const time::time_t &valid_until);
/**
* Set the cost at a specified position.
*
* @param idx Index of the cell.
* @param cost Cost to set.
* @param valid_until Time at which the cost value expires.
*/
inline void set_cost(size_t idx, cost_t cost, const time::time_t &valid_until) {
this->cells[idx] = cost;
this->valid_until = valid_until;
}
/**
* Get the cost field values.
*
* @return Cost field values.
*/
const std::vector<cost_t> &get_costs() const;
/**
* Set the cost field values.
*
* @param cells Cost field values.
* @param valid_until Time at which the cost value expires.
*/
void set_costs(std::vector<cost_t> &&cells, const time::time_t &changed);
/**
* Check if the cost field is dirty at the specified time.
*
* @param time Time of access to the cost field.
*
* @return Whether the cost field is dirty.
*/
bool is_dirty(const time::time_t &time) const;
/**
* Clear the dirty flag.
*/
void clear_dirty();
private:
/**
* Side length of the field.
*/
size_t size;
/**
* Time the cost field expires.
*/
time::time_t valid_until;
/**
* Cost field values.
*/
std::vector<cost_t> cells;
};
} // namespace path
} // namespace openage