Skip to content

Commit 2a3d646

Browse files
committed
Pathfinding: Record history of cost changes in pathfinder
1 parent 4b51903 commit 2a3d646

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

@@ -52,6 +53,7 @@ void CostField::set_costs(std::vector<cost_t> &&cells, const time::time_t &valid
5253
<< "; expected: "
5354
<< this->cells.size());
5455

56+
this->cell_cost_history.set_insert_range(valid_until, this->cells.begin(), this->cells.end());
5557
this->cells = std::move(cells);
5658
this->valid_until = valid_until;
5759
}

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
/**
@@ -88,6 +91,7 @@ class CostField {
8891
* @param valid_until Time at which the cost value expires.
8992
*/
9093
inline void set_cost(size_t idx, cost_t cost, const time::time_t &valid_until) {
94+
this->cell_cost_history.set_insert(valid_until, idx, this->cells[idx]);
9195
this->cells[idx] = cost;
9296
this->valid_until = valid_until;
9397
}
@@ -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)