Skip to content

Commit

Permalink
Pathfinding: Record history of cost changes in pathfinder
Browse files Browse the repository at this point in the history
  • Loading branch information
jere8184 committed Jan 26, 2025
1 parent e123e28 commit df2f0ab
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion libopenage/pathfinding/cost_field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ namespace openage::path {
CostField::CostField(size_t size) :
size{size},
valid_until{time::TIME_MIN},
cells(this->size * this->size, COST_MIN) {
cells(this->size * this->size, COST_MIN),
cell_cost_history() {
log::log(DBG << "Created cost field with size " << this->size << "x" << this->size);
}

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

this->cell_cost_history.set_insert_range(valid_until, this->cells.begin(), this->cells.end());
this->cells = std::move(cells);
this->valid_until = valid_until;
}
Expand Down
10 changes: 10 additions & 0 deletions libopenage/pathfinding/cost_field.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <vector>
#include <optional>

#include "curve/container/array.h"
#include "pathfinding/types.h"
#include "time/time.h"

Expand All @@ -15,6 +16,8 @@ namespace coord {
struct tile_delta;
} // namespace coord

const unsigned int CHUNK_SIZE = 100;

namespace path {

/**
Expand Down Expand Up @@ -88,6 +91,7 @@ class CostField {
* @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->cell_cost_history.set_insert(valid_until, idx, this->cells[idx]);
this->cells[idx] = cost;
this->valid_until = valid_until;
}
Expand Down Expand Up @@ -162,6 +166,12 @@ class CostField {
* Cost stamp vector.
*/
std::vector<std::optional<cost_stamp_t>> cost_stamps;


/**
* Array curve recording cell cost history,
*/
curve::Array<cost_t, CHUNK_SIZE> cell_cost_history;
};

} // namespace path
Expand Down

0 comments on commit df2f0ab

Please sign in to comment.