Skip to content

Commit

Permalink
fix issues with optional
Browse files Browse the repository at this point in the history
  • Loading branch information
dmwever committed Jan 23, 2025
1 parent 342efb9 commit 30a8baa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
15 changes: 8 additions & 7 deletions libopenage/pathfinding/cost_field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,25 @@ void CostField::set_costs(std::vector<cost_t> &&cells, const time::time_t &valid
}

bool CostField::stamp(size_t idx, cost_t cost, const time::time_t &stamped_at) {
if (this->cost_stamps.contains(idx)) return false;
if (this->cost_stamps[idx].has_value()) return false;

cost_t original_cost = this->get_cost(idx);
this->cost_stamps[idx].original_cost = original_cost;
this->cost_stamps[idx].stamp_time = stamped_at;
this->cost_stamps[idx]->original_cost = original_cost;
this->cost_stamps[idx]->stamp_time = stamped_at;

this->set_cost(idx, cost, stamped_at);
return true;
}

bool CostField::unstamp(size_t idx, const time::time_t &unstamped_at) {
if (!this->cost_stamps.contains(idx)) return false;
if (unstamped_at < this->cost_stamps[idx].stamp_time) return false;
if (!this->cost_stamps[idx].has_value()) return false;
if (unstamped_at < this->cost_stamps[idx]->stamp_time) return false;

cost_t original_cost = cost_stamps[idx].original_cost;
cost_t original_cost = cost_stamps[idx]->original_cost;

this->set_cost(idx, original_cost, unstamped_at);
return this->cost_stamps.erase(idx) != 0;
this->cost_stamps[idx].reset();
return true;
}

bool CostField::is_dirty(const time::time_t &time) const {
Expand Down
1 change: 1 addition & 0 deletions libopenage/pathfinding/cost_field.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <cstddef>
#include <vector>
#include <optional>

#include "pathfinding/types.h"
#include "time/time.h"
Expand Down

0 comments on commit 30a8baa

Please sign in to comment.