@@ -29,7 +29,7 @@ namespace path {
2929 * Cost field in the flow-field pathfinding algorithm.
3030 */
3131
32- template <size_t N >
32+ template <size_t SECTOR_SIDE_LENGTH >
3333class CostField {
3434public:
3535 /* *
@@ -106,15 +106,15 @@ class CostField {
106106 *
107107 * @return Cost field values.
108108 */
109- const std::array<cost_t , N * N > &get_costs () const ;
109+ const std::array<cost_t , SECTOR_SIDE_LENGTH * SECTOR_SIDE_LENGTH > &get_costs () const ;
110110
111111 /* *
112112 * Set the cost field values.
113113 *
114114 * @param cells Cost field values.
115115 * @param valid_until Time at which the cost value expires.
116116 */
117- void set_costs (std::array<cost_t , N * N > &&cells, const time::time_t &changed);
117+ void set_costs (std::array<cost_t , SECTOR_SIDE_LENGTH * SECTOR_SIDE_LENGTH > &&cells, const time::time_t &changed);
118118
119119 /* *
120120 * Stamp a cost field cell at a given time.
@@ -152,7 +152,7 @@ class CostField {
152152 void clear_dirty ();
153153
154154
155- const curve::Array<cost_t , N > &get_cost_history () const ;
155+ const curve::Array<cost_t , SECTOR_SIDE_LENGTH > &get_cost_history () const ;
156156
157157private:
158158 /* *
@@ -163,65 +163,65 @@ class CostField {
163163 /* *
164164 * Cost field values.
165165 */
166- std::array<cost_t , N * N > cells;
166+ std::array<cost_t , SECTOR_SIDE_LENGTH * SECTOR_SIDE_LENGTH > cells;
167167
168168 /* *
169169 * Cost stamp vector.
170170 */
171- std::array<std::optional<cost_stamp_t >, N * N > cost_stamps;
171+ std::array<std::optional<cost_stamp_t >, SECTOR_SIDE_LENGTH * SECTOR_SIDE_LENGTH > cost_stamps;
172172
173173
174174 /* *
175175 * Array curve recording cell cost history,
176176 */
177- curve::Array<cost_t , N * N > cell_cost_history;
177+ curve::Array<cost_t , SECTOR_SIDE_LENGTH * SECTOR_SIDE_LENGTH > cell_cost_history;
178178};
179179
180- template <size_t N >
181- CostField<N >::CostField(const std::shared_ptr<event::EventLoop> &loop, size_t id) :
180+ template <size_t SECTOR_SIDE_LENGTH >
181+ CostField<SECTOR_SIDE_LENGTH >::CostField(const std::shared_ptr<event::EventLoop> &loop, size_t id) :
182182 valid_until{time::TIME_MIN},
183183 cell_cost_history (loop, id) {
184184 cells.fill (COST_MIN);
185- log::log (DBG << " Created cost field with size " << N << " x" << N );
185+ log::log (DBG << " Created cost field with size " << SECTOR_SIDE_LENGTH << " x" << SECTOR_SIDE_LENGTH );
186186}
187187
188- template <size_t N >
189- constexpr size_t CostField<N >::get_size() const {
190- return N ;
188+ template <size_t SECTOR_SIDE_LENGTH >
189+ constexpr size_t CostField<SECTOR_SIDE_LENGTH >::get_size() const {
190+ return SECTOR_SIDE_LENGTH ;
191191}
192192
193- template <size_t N >
194- cost_t CostField<N >::get_cost(const coord::tile_delta &pos) const {
195- return this ->cells .at (pos.ne + pos.se * N );
193+ template <size_t SECTOR_SIDE_LENGTH >
194+ cost_t CostField<SECTOR_SIDE_LENGTH >::get_cost(const coord::tile_delta &pos) const {
195+ return this ->cells .at (pos.ne + pos.se * SECTOR_SIDE_LENGTH );
196196}
197197
198- template <size_t N >
199- cost_t CostField<N >::get_cost(size_t x, size_t y) const {
200- return this ->cells .at (x + y * N );
198+ template <size_t SECTOR_SIDE_LENGTH >
199+ cost_t CostField<SECTOR_SIDE_LENGTH >::get_cost(size_t x, size_t y) const {
200+ return this ->cells .at (x + y * SECTOR_SIDE_LENGTH );
201201}
202202
203- template <size_t N >
204- cost_t CostField<N >::get_cost(size_t idx) const {
203+ template <size_t SECTOR_SIDE_LENGTH >
204+ cost_t CostField<SECTOR_SIDE_LENGTH >::get_cost(size_t idx) const {
205205 return this ->cells .at (idx);
206206}
207207
208- template <size_t N >
209- void CostField<N >::set_cost(const coord::tile_delta &pos, cost_t cost, const time::time_t &valid_until) {
210- this ->set_cost (pos.ne + pos.se * N , cost, valid_until);
208+ template <size_t SECTOR_SIDE_LENGTH >
209+ void CostField<SECTOR_SIDE_LENGTH >::set_cost(const coord::tile_delta &pos, cost_t cost, const time::time_t &valid_until) {
210+ this ->set_cost (pos.ne + pos.se * SECTOR_SIDE_LENGTH , cost, valid_until);
211211}
212212
213- template <size_t N >
214- void CostField<N >::set_cost(size_t x, size_t y, cost_t cost, const time::time_t &valid_until) {
215- this ->set_cost (x + y * N , cost, valid_until);
213+ template <size_t SECTOR_SIDE_LENGTH >
214+ void CostField<SECTOR_SIDE_LENGTH >::set_cost(size_t x, size_t y, cost_t cost, const time::time_t &valid_until) {
215+ this ->set_cost (x + y * SECTOR_SIDE_LENGTH , cost, valid_until);
216216}
217217
218- template <size_t N >
219- const std::array<cost_t , N * N > &CostField<N >::get_costs() const {
218+ template <size_t SECTOR_SIDE_LENGTH >
219+ const std::array<cost_t , SECTOR_SIDE_LENGTH * SECTOR_SIDE_LENGTH > &CostField<SECTOR_SIDE_LENGTH >::get_costs() const {
220220 return this ->cells ;
221221}
222222
223- template <size_t N >
224- void CostField<N >::set_costs(std::array<cost_t , N * N > &&cells, const time::time_t &valid_until) {
223+ template <size_t SECTOR_SIDE_LENGTH >
224+ void CostField<SECTOR_SIDE_LENGTH >::set_costs(std::array<cost_t , SECTOR_SIDE_LENGTH * SECTOR_SIDE_LENGTH > &&cells, const time::time_t &valid_until) {
225225 ENSURE (cells.size () == this ->cells .size (),
226226 " cells vector has wrong size: " << cells.size ()
227227 << " ; expected: "
@@ -232,8 +232,8 @@ void CostField<N>::set_costs(std::array<cost_t, N * N> &&cells, const time::time
232232 this ->cell_cost_history .set_insert_range (valid_until, this ->cells .begin (), this ->cells .end ());
233233}
234234
235- template <size_t N >
236- bool CostField<N >::stamp(size_t idx, cost_t cost, const time::time_t &stamped_at) {
235+ template <size_t SECTOR_SIDE_LENGTH >
236+ bool CostField<SECTOR_SIDE_LENGTH >::stamp(size_t idx, cost_t cost, const time::time_t &stamped_at) {
237237 if (this ->cost_stamps [idx].has_value ()) {
238238 return false ;
239239 }
@@ -247,8 +247,8 @@ bool CostField<N>::stamp(size_t idx, cost_t cost, const time::time_t &stamped_at
247247 return true ;
248248}
249249
250- template <size_t N >
251- bool CostField<N >::unstamp(size_t idx, const time::time_t &unstamped_at) {
250+ template <size_t SECTOR_SIDE_LENGTH >
251+ bool CostField<SECTOR_SIDE_LENGTH >::unstamp(size_t idx, const time::time_t &unstamped_at) {
252252 if (not this ->cost_stamps [idx].has_value () or unstamped_at < this ->cost_stamps [idx]->stamp_time ) {
253253 return false ;
254254 }
@@ -259,18 +259,18 @@ bool CostField<N>::unstamp(size_t idx, const time::time_t &unstamped_at) {
259259 return true ;
260260}
261261
262- template <size_t N >
263- bool CostField<N >::is_dirty(const time::time_t &time) const {
262+ template <size_t SECTOR_SIDE_LENGTH >
263+ bool CostField<SECTOR_SIDE_LENGTH >::is_dirty(const time::time_t &time) const {
264264 return time >= this ->valid_until ;
265265}
266266
267- template <size_t N >
268- void CostField<N >::clear_dirty() {
267+ template <size_t SECTOR_SIDE_LENGTH >
268+ void CostField<SECTOR_SIDE_LENGTH >::clear_dirty() {
269269 this ->valid_until = time::TIME_MAX;
270270}
271271
272- template <size_t N >
273- const curve::Array<cost_t , N > &CostField<N >::get_cost_history() const {
272+ template <size_t SECTOR_SIDE_LENGTH >
273+ const curve::Array<cost_t , SECTOR_SIDE_LENGTH > &CostField<SECTOR_SIDE_LENGTH >::get_cost_history() const {
274274 return this ->cell_cost_history ;
275275};
276276
0 commit comments