diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2024-12-20 14:33:43 -0500 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2024-12-20 14:33:43 -0500 |
commit | 3c49081df34fb1801063c0b538d12d4422fcf3f0 (patch) | |
tree | f4d267d953c97b0ee3e78730d8e36484abf7f096 /src/subway_map.cpp | |
parent | 5a7559e39d2cd8306a99adbc6d39e90716b14687 (diff) | |
download | lingo-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/subway_map.cpp')
-rw-r--r-- | src/subway_map.cpp | 61 |
1 files changed, 33 insertions, 28 deletions
diff --git a/src/subway_map.cpp b/src/subway_map.cpp index f896693..4ebc56a 100644 --- a/src/subway_map.cpp +++ b/src/subway_map.cpp | |||
@@ -16,28 +16,6 @@ constexpr int OWL_ACTUAL_SIZE = 32; | |||
16 | 16 | ||
17 | enum class ItemDrawType { kNone, kBox, kOwl }; | 17 | enum class ItemDrawType { kNone, kBox, kOwl }; |
18 | 18 | ||
19 | namespace { | ||
20 | |||
21 | std::optional<int> GetRealSubwayDoor(const SubwayItem subway_item) { | ||
22 | if (AP_IsSunwarpShuffle() && subway_item.sunwarp && | ||
23 | subway_item.sunwarp->type != SubwaySunwarpType::kFinal) { | ||
24 | int sunwarp_index = subway_item.sunwarp->dots - 1; | ||
25 | if (subway_item.sunwarp->type == SubwaySunwarpType::kExit) { | ||
26 | sunwarp_index += 6; | ||
27 | } | ||
28 | |||
29 | for (const auto &[start_index, mapping] : AP_GetSunwarpMapping()) { | ||
30 | if (start_index == sunwarp_index || mapping.exit_index == sunwarp_index) { | ||
31 | return GD_GetSunwarpDoors().at(mapping.dots - 1); | ||
32 | } | ||
33 | } | ||
34 | } | ||
35 | |||
36 | return subway_item.door; | ||
37 | } | ||
38 | |||
39 | } // namespace | ||
40 | |||
41 | SubwayMap::SubwayMap(wxWindow *parent) : wxPanel(parent, wxID_ANY) { | 19 | SubwayMap::SubwayMap(wxWindow *parent) : wxPanel(parent, wxID_ANY) { |
42 | SetBackgroundStyle(wxBG_STYLE_PAINT); | 20 | SetBackgroundStyle(wxBG_STYLE_PAINT); |
43 | 21 | ||
@@ -140,7 +118,7 @@ void SubwayMap::OnConnect() { | |||
140 | SubwaySunwarp final_sunwarp{.dots = 6, .type = SubwaySunwarpType::kFinal}; | 118 | SubwaySunwarp final_sunwarp{.dots = 6, .type = SubwaySunwarpType::kFinal}; |
141 | int final_sunwarp_item = GD_GetSubwayItemForSunwarp(final_sunwarp); | 119 | int final_sunwarp_item = GD_GetSubwayItemForSunwarp(final_sunwarp); |
142 | 120 | ||
143 | for (const auto &[index, mapping] : AP_GetSunwarpMapping()) { | 121 | for (const auto &[index, mapping] : sunwarp_mapping_) { |
144 | std::string tag = fmt::format("sunwarp{}", mapping.dots); | 122 | std::string tag = fmt::format("sunwarp{}", mapping.dots); |
145 | 123 | ||
146 | SubwaySunwarp fromWarp; | 124 | SubwaySunwarp fromWarp; |
@@ -197,15 +175,22 @@ void SubwayMap::OnConnect() { | |||
197 | } | 175 | } |
198 | 176 | ||
199 | void SubwayMap::UpdateIndicators() { | 177 | void SubwayMap::UpdateIndicators() { |
178 | if (AP_IsSunwarpShuffle()) { | ||
179 | sunwarp_mapping_ = AP_GetSunwarpMapping(); | ||
180 | } | ||
181 | |||
200 | if (AP_IsPaintingShuffle()) { | 182 | if (AP_IsPaintingShuffle()) { |
201 | for (const std::string &painting_id : AP_GetCheckedPaintings()) { | 183 | std::map<std::string, std::string> painting_mapping = |
184 | AP_GetPaintingMapping(); | ||
185 | std::set<std::string> remote_checked_paintings = AP_GetCheckedPaintings(); | ||
186 | |||
187 | for (const std::string &painting_id : remote_checked_paintings) { | ||
202 | if (!checked_paintings_.count(painting_id)) { | 188 | if (!checked_paintings_.count(painting_id)) { |
203 | checked_paintings_.insert(painting_id); | 189 | checked_paintings_.insert(painting_id); |
204 | 190 | ||
205 | if (AP_GetPaintingMapping().count(painting_id)) { | 191 | if (painting_mapping.count(painting_id)) { |
206 | std::optional<int> from_id = GD_GetSubwayItemForPainting(painting_id); | 192 | std::optional<int> from_id = GD_GetSubwayItemForPainting(painting_id); |
207 | std::optional<int> to_id = GD_GetSubwayItemForPainting( | 193 | std::optional<int> to_id = GD_GetSubwayItemForPainting(painting_mapping.at(painting_id)); |
208 | AP_GetPaintingMapping().at(painting_id)); | ||
209 | 194 | ||
210 | if (from_id && to_id) { | 195 | if (from_id && to_id) { |
211 | networks_.AddLink(*from_id, *to_id, false); | 196 | networks_.AddLink(*from_id, *to_id, false); |
@@ -600,6 +585,8 @@ void SubwayMap::Redraw() { | |||
600 | 585 | ||
601 | wxGCDC gcdc(dc); | 586 | wxGCDC gcdc(dc); |
602 | 587 | ||
588 | std::map<std::string, std::string> painting_mapping = AP_GetPaintingMapping(); | ||
589 | |||
603 | for (const SubwayItem &subway_item : GD_GetSubwayItems()) { | 590 | for (const SubwayItem &subway_item : GD_GetSubwayItems()) { |
604 | ItemDrawType draw_type = ItemDrawType::kNone; | 591 | ItemDrawType draw_type = ItemDrawType::kNone; |
605 | const wxBrush *brush_color = wxGREY_BRUSH; | 592 | const wxBrush *brush_color = wxGREY_BRUSH; |
@@ -641,7 +628,7 @@ void SubwayMap::Redraw() { | |||
641 | if (checked_paintings_.count(painting_id)) { | 628 | if (checked_paintings_.count(painting_id)) { |
642 | has_checked_painting = true; | 629 | has_checked_painting = true; |
643 | 630 | ||
644 | if (AP_GetPaintingMapping().count(painting_id)) { | 631 | if (painting_mapping.count(painting_id)) { |
645 | has_mapped_painting = true; | 632 | has_mapped_painting = true; |
646 | } else if (AP_IsPaintingMappedTo(painting_id)) { | 633 | } else if (AP_IsPaintingMappedTo(painting_id)) { |
647 | has_codomain_painting = true; | 634 | has_codomain_painting = true; |
@@ -803,6 +790,24 @@ void SubwayMap::SetZoom(double zoom, wxPoint static_point) { | |||
803 | zoom_slider_->SetValue((zoom - 1.0) / 0.25); | 790 | zoom_slider_->SetValue((zoom - 1.0) / 0.25); |
804 | } | 791 | } |
805 | 792 | ||
793 | std::optional<int> SubwayMap::GetRealSubwayDoor(const SubwayItem subway_item) { | ||
794 | if (AP_IsSunwarpShuffle() && subway_item.sunwarp && | ||
795 | subway_item.sunwarp->type != SubwaySunwarpType::kFinal) { | ||
796 | int sunwarp_index = subway_item.sunwarp->dots - 1; | ||
797 | if (subway_item.sunwarp->type == SubwaySunwarpType::kExit) { | ||
798 | sunwarp_index += 6; | ||
799 | } | ||
800 | |||
801 | for (const auto &[start_index, mapping] : sunwarp_mapping_) { | ||
802 | if (start_index == sunwarp_index || mapping.exit_index == sunwarp_index) { | ||
803 | return GD_GetSunwarpDoors().at(mapping.dots - 1); | ||
804 | } | ||
805 | } | ||
806 | } | ||
807 | |||
808 | return subway_item.door; | ||
809 | } | ||
810 | |||
806 | quadtree::Box<float> SubwayMap::GetItemBox::operator()(const int &id) const { | 811 | quadtree::Box<float> SubwayMap::GetItemBox::operator()(const int &id) const { |
807 | const SubwayItem &subway_item = GD_GetSubwayItem(id); | 812 | const SubwayItem &subway_item = GD_GetSubwayItem(id); |
808 | return {static_cast<float>(subway_item.x), static_cast<float>(subway_item.y), | 813 | return {static_cast<float>(subway_item.x), static_cast<float>(subway_item.y), |