Skip to content

Commit 772dd4a

Browse files
dmweverjere8184
authored andcommitted
fix issues with optional
1 parent f37e8b5 commit 772dd4a

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

libopenage/pathfinding/cost_field.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,24 +57,25 @@ void CostField::set_costs(std::vector<cost_t> &&cells, const time::time_t &valid
5757
}
5858

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

6262
cost_t original_cost = this->get_cost(idx);
63-
this->cost_stamps[idx].original_cost = original_cost;
64-
this->cost_stamps[idx].stamp_time = stamped_at;
63+
this->cost_stamps[idx]->original_cost = original_cost;
64+
this->cost_stamps[idx]->stamp_time = stamped_at;
6565

6666
this->set_cost(idx, cost, stamped_at);
6767
return true;
6868
}
6969

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

74-
cost_t original_cost = cost_stamps[idx].original_cost;
74+
cost_t original_cost = cost_stamps[idx]->original_cost;
7575

7676
this->set_cost(idx, original_cost, unstamped_at);
77-
return this->cost_stamps.erase(idx) != 0;
77+
this->cost_stamps[idx].reset();
78+
return true;
7879
}
7980

8081
bool CostField::is_dirty(const time::time_t &time) const {

libopenage/pathfinding/cost_field.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <cstddef>
66
#include <vector>
7+
#include <optional>
78

89
#include "pathfinding/types.h"
910
#include "time/time.h"

0 commit comments

Comments
 (0)