Skip to content

Commit 8d216b9

Browse files
committed
Pathfinding: Record history of cost changes in pathfinder
1 parent e123e28 commit 8d216b9

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

libopenage/pathfinding/cost_field.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ namespace openage::path {
1414
CostField::CostField(size_t size) :
1515
size{size},
1616
valid_until{time::TIME_MIN},
17-
cells(this->size * this->size, COST_MIN) {
17+
cells(this->size * this->size, COST_MIN),
18+
cell_cost_history() {
1819
log::log(DBG << "Created cost field with size " << this->size << "x" << this->size);
1920
}
2021

@@ -54,6 +55,7 @@ void CostField::set_costs(std::vector<cost_t> &&cells, const time::time_t &valid
5455

5556
this->cells = std::move(cells);
5657
this->valid_until = valid_until;
58+
this->cell_cost_history.set_insert_range(valid_until, this->cells.begin(), this->cells.end());
5759
}
5860

5961
bool CostField::stamp(size_t idx, cost_t cost, const time::time_t &stamped_at) {

libopenage/pathfinding/cost_field.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <vector>
77
#include <optional>
88

9+
#include "curve/container/array.h"
910
#include "pathfinding/types.h"
1011
#include "time/time.h"
1112

@@ -15,6 +16,8 @@ namespace coord {
1516
struct tile_delta;
1617
} // namespace coord
1718

19+
const unsigned int CHUNK_SIZE = 100;
20+
1821
namespace path {
1922

2023
/**
@@ -90,6 +93,7 @@ class CostField {
9093
inline void set_cost(size_t idx, cost_t cost, const time::time_t &valid_until) {
9194
this->cells[idx] = cost;
9295
this->valid_until = valid_until;
96+
this->cell_cost_history.set_insert(valid_until, idx, this->cells[idx]);
9397
}
9498

9599
/**
@@ -162,6 +166,12 @@ class CostField {
162166
* Cost stamp vector.
163167
*/
164168
std::vector<std::optional<cost_stamp_t>> cost_stamps;
169+
170+
171+
/**
172+
* Array curve recording cell cost history,
173+
*/
174+
curve::Array<cost_t, CHUNK_SIZE> cell_cost_history;
165175
};
166176

167177
} // namespace path

0 commit comments

Comments
 (0)