about summary refs log tree commit diff stats
path: root/src/tracker_state.cpp
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2024-12-20 14:33:43 -0500
committerStar Rauchenberger <fefferburbia@gmail.com>2024-12-20 14:33:43 -0500
commit3c49081df34fb1801063c0b538d12d4422fcf3f0 (patch)
treef4d267d953c97b0ee3e78730d8e36484abf7f096 /src/tracker_state.cpp
parent5a7559e39d2cd8306a99adbc6d39e90716b14687 (diff)
downloadlingo-ap-tracker-3c49081df34fb1801063c0b538d12d4422fcf3f0.tar.gz
lingo-ap-tracker-3c49081df34fb1801063c0b538d12d4422fcf3f0.tar.bz2
lingo-ap-tracker-3c49081df34fb1801063c0b538d12d4422fcf3f0.zip
Fixed remaining thread unsafe APState/IPCState reads
Still would like to add some kind of wrapper object that TrackerState could use to read APState without locking, since it'll only ever be called from the thread that would do the mutating, but this is fine for now.
Diffstat (limited to 'src/tracker_state.cpp')
-rw-r--r--src/tracker_state.cpp23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/tracker_state.cpp b/src/tracker_state.cpp index 4a49fac..eee43e4 100644 --- a/src/tracker_state.cpp +++ b/src/tracker_state.cpp
@@ -192,6 +192,10 @@ class StateCalculator {
192 : options_(options) {} 192 : options_(options) {}
193 193
194 void Calculate() { 194 void Calculate() {
195 painting_mapping_ = AP_GetPaintingMapping();
196 checked_paintings_ = AP_GetCheckedPaintings();
197 sunwarp_mapping_ = AP_GetSunwarpMapping();
198
195 std::list<int> panel_boundary; 199 std::list<int> panel_boundary;
196 std::list<int> painting_boundary; 200 std::list<int> painting_boundary;
197 std::list<Exit> flood_boundary; 201 std::list<Exit> flood_boundary;
@@ -231,12 +235,12 @@ class StateCalculator {
231 reachable_changed = true; 235 reachable_changed = true;
232 236
233 PaintingExit cur_painting = GD_GetPaintingExit(painting_id); 237 PaintingExit cur_painting = GD_GetPaintingExit(painting_id);
234 if (AP_GetPaintingMapping().count(cur_painting.internal_id) && 238 if (painting_mapping_.count(cur_painting.internal_id) &&
235 AP_GetCheckedPaintings().count(cur_painting.internal_id)) { 239 checked_paintings_.count(cur_painting.internal_id)) {
236 Exit painting_exit; 240 Exit painting_exit;
237 PaintingExit target_painting = 241 PaintingExit target_painting =
238 GD_GetPaintingExit(GD_GetPaintingByName( 242 GD_GetPaintingExit(GD_GetPaintingByName(
239 AP_GetPaintingMapping().at(cur_painting.internal_id))); 243 painting_mapping_.at(cur_painting.internal_id)));
240 painting_exit.source_room = cur_painting.room; 244 painting_exit.source_room = cur_painting.room;
241 painting_exit.destination_room = target_painting.room; 245 painting_exit.destination_room = target_painting.room;
242 painting_exit.type = EntranceType::kPainting; 246 painting_exit.type = EntranceType::kPainting;
@@ -295,8 +299,8 @@ class StateCalculator {
295 299
296 if (AP_IsSunwarpShuffle()) { 300 if (AP_IsSunwarpShuffle()) {
297 for (int index : room_obj.sunwarps) { 301 for (int index : room_obj.sunwarps) {
298 if (AP_GetSunwarpMapping().count(index)) { 302 if (sunwarp_mapping_.count(index)) {
299 const SunwarpMapping& sm = AP_GetSunwarpMapping().at(index); 303 const SunwarpMapping& sm = sunwarp_mapping_.at(index);
300 304
301 new_boundary.push_back( 305 new_boundary.push_back(
302 {.source_room = room_exit.destination_room, 306 {.source_room = room_exit.destination_room,
@@ -317,8 +321,7 @@ class StateCalculator {
317 if (AP_IsPilgrimageEnabled()) { 321 if (AP_IsPilgrimageEnabled()) {
318 int pilgrimage_start_id = GD_GetRoomByName("Hub Room"); 322 int pilgrimage_start_id = GD_GetRoomByName("Hub Room");
319 if (AP_IsSunwarpShuffle()) { 323 if (AP_IsSunwarpShuffle()) {
320 for (const auto& [start_index, mapping] : 324 for (const auto& [start_index, mapping] : sunwarp_mapping_) {
321 AP_GetSunwarpMapping()) {
322 if (mapping.dots == 1) { 325 if (mapping.dots == 1) {
323 pilgrimage_start_id = GD_GetRoomForSunwarp(start_index); 326 pilgrimage_start_id = GD_GetRoomForSunwarp(start_index);
324 } 327 }
@@ -578,7 +581,7 @@ class StateCalculator {
578 if (AP_IsSunwarpShuffle()) { 581 if (AP_IsSunwarpShuffle()) {
579 pilgrimage_pairs = std::vector<std::tuple<int, int>>(5); 582 pilgrimage_pairs = std::vector<std::tuple<int, int>>(5);
580 583
581 for (const auto& [start_index, mapping] : AP_GetSunwarpMapping()) { 584 for (const auto& [start_index, mapping] : sunwarp_mapping_) {
582 if (mapping.dots > 1) { 585 if (mapping.dots > 1) {
583 std::get<1>(pilgrimage_pairs[mapping.dots - 2]) = start_index; 586 std::get<1>(pilgrimage_pairs[mapping.dots - 2]) = start_index;
584 } 587 }
@@ -649,6 +652,10 @@ class StateCalculator {
649 bool pilgrimage_doable_ = false; 652 bool pilgrimage_doable_ = false;
650 653
651 std::map<int, std::list<int>> paths_; 654 std::map<int, std::list<int>> paths_;
655
656 std::map<std::string, std::string> painting_mapping_;
657 std::set<std::string> checked_paintings_;
658 std::map<int, SunwarpMapping> sunwarp_mapping_;
652}; 659};
653 660
654} // namespace 661} // namespace