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/subway_map.cpp | 61 +++++++++++++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 28 deletions(-) (limited to 'src/subway_map.cpp') 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; enum class ItemDrawType { kNone, kBox, kOwl }; -namespace { - -std::optional GetRealSubwayDoor(const SubwayItem subway_item) { - if (AP_IsSunwarpShuffle() && subway_item.sunwarp && - subway_item.sunwarp->type != SubwaySunwarpType::kFinal) { - int sunwarp_index = subway_item.sunwarp->dots - 1; - if (subway_item.sunwarp->type == SubwaySunwarpType::kExit) { - sunwarp_index += 6; - } - - for (const auto &[start_index, mapping] : AP_GetSunwarpMapping()) { - if (start_index == sunwarp_index || mapping.exit_index == sunwarp_index) { - return GD_GetSunwarpDoors().at(mapping.dots - 1); - } - } - } - - return subway_item.door; -} - -} // namespace - SubwayMap::SubwayMap(wxWindow *parent) : wxPanel(parent, wxID_ANY) { SetBackgroundStyle(wxBG_STYLE_PAINT); @@ -140,7 +118,7 @@ void SubwayMap::OnConnect() { SubwaySunwarp final_sunwarp{.dots = 6, .type = SubwaySunwarpType::kFinal}; int final_sunwarp_item = GD_GetSubwayItemForSunwarp(final_sunwarp); - for (const auto &[index, mapping] : AP_GetSunwarpMapping()) { + for (const auto &[index, mapping] : sunwarp_mapping_) { std::string tag = fmt::format("sunwarp{}", mapping.dots); SubwaySunwarp fromWarp; @@ -197,15 +175,22 @@ void SubwayMap::OnConnect() { } void SubwayMap::UpdateIndicators() { + if (AP_IsSunwarpShuffle()) { + sunwarp_mapping_ = AP_GetSunwarpMapping(); + } + if (AP_IsPaintingShuffle()) { - for (const std::string &painting_id : AP_GetCheckedPaintings()) { + std::map painting_mapping = + AP_GetPaintingMapping(); + std::set remote_checked_paintings = AP_GetCheckedPaintings(); + + for (const std::string &painting_id : remote_checked_paintings) { if (!checked_paintings_.count(painting_id)) { checked_paintings_.insert(painting_id); - if (AP_GetPaintingMapping().count(painting_id)) { + if (painting_mapping.count(painting_id)) { std::optional from_id = GD_GetSubwayItemForPainting(painting_id); - std::optional to_id = GD_GetSubwayItemForPainting( - AP_GetPaintingMapping().at(painting_id)); + std::optional to_id = GD_GetSubwayItemForPainting(painting_mapping.at(painting_id)); if (from_id && to_id) { networks_.AddLink(*from_id, *to_id, false); @@ -600,6 +585,8 @@ void SubwayMap::Redraw() { wxGCDC gcdc(dc); + std::map painting_mapping = AP_GetPaintingMapping(); + for (const SubwayItem &subway_item : GD_GetSubwayItems()) { ItemDrawType draw_type = ItemDrawType::kNone; const wxBrush *brush_color = wxGREY_BRUSH; @@ -641,7 +628,7 @@ void SubwayMap::Redraw() { if (checked_paintings_.count(painting_id)) { has_checked_painting = true; - if (AP_GetPaintingMapping().count(painting_id)) { + if (painting_mapping.count(painting_id)) { has_mapped_painting = true; } else if (AP_IsPaintingMappedTo(painting_id)) { has_codomain_painting = true; @@ -803,6 +790,24 @@ void SubwayMap::SetZoom(double zoom, wxPoint static_point) { zoom_slider_->SetValue((zoom - 1.0) / 0.25); } +std::optional SubwayMap::GetRealSubwayDoor(const SubwayItem subway_item) { + if (AP_IsSunwarpShuffle() && subway_item.sunwarp && + subway_item.sunwarp->type != SubwaySunwarpType::kFinal) { + int sunwarp_index = subway_item.sunwarp->dots - 1; + if (subway_item.sunwarp->type == SubwaySunwarpType::kExit) { + sunwarp_index += 6; + } + + for (const auto &[start_index, mapping] : sunwarp_mapping_) { + if (start_index == sunwarp_index || mapping.exit_index == sunwarp_index) { + return GD_GetSunwarpDoors().at(mapping.dots - 1); + } + } + } + + return subway_item.door; +} + quadtree::Box SubwayMap::GetItemBox::operator()(const int &id) const { const SubwayItem &subway_item = GD_GetSubwayItem(id); return {static_cast(subway_item.x), static_cast(subway_item.y), -- cgit 1.4.1