From 3c49081df34fb1801063c0b538d12d4422fcf3f0 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Fri, 20 Dec 2024 14:33:43 -0500 Subject: 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. --- src/tracker_state.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'src/tracker_state.cpp') 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 { : options_(options) {} void Calculate() { + painting_mapping_ = AP_GetPaintingMapping(); + checked_paintings_ = AP_GetCheckedPaintings(); + sunwarp_mapping_ = AP_GetSunwarpMapping(); + std::list panel_boundary; std::list painting_boundary; std::list flood_boundary; @@ -231,12 +235,12 @@ class StateCalculator { reachable_changed = true; PaintingExit cur_painting = GD_GetPaintingExit(painting_id); - if (AP_GetPaintingMapping().count(cur_painting.internal_id) && - AP_GetCheckedPaintings().count(cur_painting.internal_id)) { + if (painting_mapping_.count(cur_painting.internal_id) && + checked_paintings_.count(cur_painting.internal_id)) { Exit painting_exit; PaintingExit target_painting = GD_GetPaintingExit(GD_GetPaintingByName( - AP_GetPaintingMapping().at(cur_painting.internal_id))); + painting_mapping_.at(cur_painting.internal_id))); painting_exit.source_room = cur_painting.room; painting_exit.destination_room = target_painting.room; painting_exit.type = EntranceType::kPainting; @@ -295,8 +299,8 @@ class StateCalculator { if (AP_IsSunwarpShuffle()) { for (int index : room_obj.sunwarps) { - if (AP_GetSunwarpMapping().count(index)) { - const SunwarpMapping& sm = AP_GetSunwarpMapping().at(index); + if (sunwarp_mapping_.count(index)) { + const SunwarpMapping& sm = sunwarp_mapping_.at(index); new_boundary.push_back( {.source_room = room_exit.destination_room, @@ -317,8 +321,7 @@ class StateCalculator { if (AP_IsPilgrimageEnabled()) { int pilgrimage_start_id = GD_GetRoomByName("Hub Room"); if (AP_IsSunwarpShuffle()) { - for (const auto& [start_index, mapping] : - AP_GetSunwarpMapping()) { + for (const auto& [start_index, mapping] : sunwarp_mapping_) { if (mapping.dots == 1) { pilgrimage_start_id = GD_GetRoomForSunwarp(start_index); } @@ -578,7 +581,7 @@ class StateCalculator { if (AP_IsSunwarpShuffle()) { pilgrimage_pairs = std::vector>(5); - for (const auto& [start_index, mapping] : AP_GetSunwarpMapping()) { + for (const auto& [start_index, mapping] : sunwarp_mapping_) { if (mapping.dots > 1) { std::get<1>(pilgrimage_pairs[mapping.dots - 2]) = start_index; } @@ -649,6 +652,10 @@ class StateCalculator { bool pilgrimage_doable_ = false; std::map> paths_; + + std::map painting_mapping_; + std::set checked_paintings_; + std::map sunwarp_mapping_; }; } // namespace -- cgit 1.4.1