diff options
| author | Star Rauchenberger <fefferburbia@gmail.com> | 2023-05-05 16:35:09 -0400 |
|---|---|---|
| committer | Star Rauchenberger <fefferburbia@gmail.com> | 2023-05-05 16:35:09 -0400 |
| commit | d7212d755dca7f4fd99cf4b775cd0d372d7bcbb2 (patch) | |
| tree | a4ca0258eda334c4aa68073355b9f4ccd8a7bdef /src/tracker_state.cpp | |
| parent | 017df1397ace9ab8c3f152362d07871dcb6858be (diff) | |
| download | lingo-ap-tracker-d7212d755dca7f4fd99cf4b775cd0d372d7bcbb2.tar.gz lingo-ap-tracker-d7212d755dca7f4fd99cf4b775cd0d372d7bcbb2.tar.bz2 lingo-ap-tracker-d7212d755dca7f4fd99cf4b775cd0d372d7bcbb2.zip | |
Refactored away singletons
(Except TrackerConfig, for now at least)
Diffstat (limited to 'src/tracker_state.cpp')
| -rw-r--r-- | src/tracker_state.cpp | 48 |
1 files changed, 28 insertions, 20 deletions
| diff --git a/src/tracker_state.cpp b/src/tracker_state.cpp index 858ec3e..37a7da8 100644 --- a/src/tracker_state.cpp +++ b/src/tracker_state.cpp | |||
| @@ -1,16 +1,29 @@ | |||
| 1 | #include "tracker_state.h" | 1 | #include "tracker_state.h" |
| 2 | 2 | ||
| 3 | #include <list> | 3 | #include <list> |
| 4 | #include <map> | ||
| 4 | #include <set> | 5 | #include <set> |
| 6 | #include <tuple> | ||
| 5 | 7 | ||
| 6 | #include "ap_state.h" | 8 | #include "ap_state.h" |
| 7 | #include "game_data.h" | 9 | #include "game_data.h" |
| 8 | 10 | ||
| 11 | namespace { | ||
| 12 | |||
| 13 | struct TrackerState { | ||
| 14 | std::map<std::tuple<int, int>, bool> reachability; | ||
| 15 | }; | ||
| 16 | |||
| 17 | TrackerState& GetState() { | ||
| 18 | static TrackerState* instance = new TrackerState(); | ||
| 19 | return *instance; | ||
| 20 | } | ||
| 21 | |||
| 9 | bool IsDoorReachable_Helper(int door_id, const std::set<int>& reachable_rooms); | 22 | bool IsDoorReachable_Helper(int door_id, const std::set<int>& reachable_rooms); |
| 10 | 23 | ||
| 11 | bool IsPanelReachable_Helper(int panel_id, | 24 | bool IsPanelReachable_Helper(int panel_id, |
| 12 | const std::set<int>& reachable_rooms) { | 25 | const std::set<int>& reachable_rooms) { |
| 13 | const Panel& panel_obj = GetGameData().GetPanel(panel_id); | 26 | const Panel& panel_obj = GD_GetPanel(panel_id); |
| 14 | 27 | ||
| 15 | if (!reachable_rooms.count(panel_obj.room)) { | 28 | if (!reachable_rooms.count(panel_obj.room)) { |
| 16 | return false; | 29 | return false; |
| @@ -19,7 +32,7 @@ bool IsPanelReachable_Helper(int panel_id, | |||
| 19 | if (panel_obj.name == "THE MASTER") { | 32 | if (panel_obj.name == "THE MASTER") { |
| 20 | int achievements_accessible = 0; | 33 | int achievements_accessible = 0; |
| 21 | 34 | ||
| 22 | for (int achieve_id : GetGameData().GetAchievementPanels()) { | 35 | for (int achieve_id : GD_GetAchievementPanels()) { |
| 23 | if (IsPanelReachable_Helper(achieve_id, reachable_rooms)) { | 36 | if (IsPanelReachable_Helper(achieve_id, reachable_rooms)) { |
| 24 | achievements_accessible++; | 37 | achievements_accessible++; |
| 25 | 38 | ||
| @@ -56,7 +69,7 @@ bool IsPanelReachable_Helper(int panel_id, | |||
| 56 | } | 69 | } |
| 57 | 70 | ||
| 58 | bool IsDoorReachable_Helper(int door_id, const std::set<int>& reachable_rooms) { | 71 | bool IsDoorReachable_Helper(int door_id, const std::set<int>& reachable_rooms) { |
| 59 | const Door& door_obj = GetGameData().GetDoor(door_id); | 72 | const Door& door_obj = GD_GetDoor(door_id); |
| 60 | 73 | ||
| 61 | if (AP_GetDoorShuffleMode() == kNO_DOORS || door_obj.skip_item) { | 74 | if (AP_GetDoorShuffleMode() == kNO_DOORS || door_obj.skip_item) { |
| 62 | if (!reachable_rooms.count(door_obj.room)) { | 75 | if (!reachable_rooms.count(door_obj.room)) { |
| @@ -89,14 +102,15 @@ bool IsDoorReachable_Helper(int door_id, const std::set<int>& reachable_rooms) { | |||
| 89 | } | 102 | } |
| 90 | } | 103 | } |
| 91 | 104 | ||
| 92 | void TrackerState::CalculateState() { | 105 | } // namespace |
| 93 | reachability_.clear(); | 106 | |
| 107 | void RecalculateReachability() { | ||
| 108 | GetState().reachability.clear(); | ||
| 94 | 109 | ||
| 95 | std::set<int> reachable_rooms; | 110 | std::set<int> reachable_rooms; |
| 96 | 111 | ||
| 97 | std::list<Exit> flood_boundary; | 112 | std::list<Exit> flood_boundary; |
| 98 | flood_boundary.push_back( | 113 | flood_boundary.push_back({.destination_room = GD_GetRoomByName("Menu")}); |
| 99 | {.destination_room = GetGameData().GetRoomByName("Menu")}); | ||
| 100 | 114 | ||
| 101 | bool reachable_changed = true; | 115 | bool reachable_changed = true; |
| 102 | while (reachable_changed) { | 116 | while (reachable_changed) { |
| @@ -123,8 +137,7 @@ void TrackerState::CalculateState() { | |||
| 123 | reachable_rooms.insert(room_exit.destination_room); | 137 | reachable_rooms.insert(room_exit.destination_room); |
| 124 | reachable_changed = true; | 138 | reachable_changed = true; |
| 125 | 139 | ||
| 126 | const Room& room_obj = | 140 | const Room& room_obj = GD_GetRoom(room_exit.destination_room); |
| 127 | GetGameData().GetRoom(room_exit.destination_room); | ||
| 128 | for (const Exit& out_edge : room_obj.exits) { | 141 | for (const Exit& out_edge : room_obj.exits) { |
| 129 | if (!out_edge.painting || !AP_IsPaintingShuffle()) { | 142 | if (!out_edge.painting || !AP_IsPaintingShuffle()) { |
| 130 | new_boundary.push_back(out_edge); | 143 | new_boundary.push_back(out_edge); |
| @@ -135,7 +148,7 @@ void TrackerState::CalculateState() { | |||
| 135 | for (const PaintingExit& out_edge : room_obj.paintings) { | 148 | for (const PaintingExit& out_edge : room_obj.paintings) { |
| 136 | if (AP_GetPaintingMapping().count(out_edge.id)) { | 149 | if (AP_GetPaintingMapping().count(out_edge.id)) { |
| 137 | Exit painting_exit; | 150 | Exit painting_exit; |
| 138 | painting_exit.destination_room = GetGameData().GetRoomForPainting( | 151 | painting_exit.destination_room = GD_GetRoomForPainting( |
| 139 | AP_GetPaintingMapping().at(out_edge.id)); | 152 | AP_GetPaintingMapping().at(out_edge.id)); |
| 140 | painting_exit.door = out_edge.door; | 153 | painting_exit.door = out_edge.door; |
| 141 | 154 | ||
| @@ -149,7 +162,7 @@ void TrackerState::CalculateState() { | |||
| 149 | flood_boundary = new_boundary; | 162 | flood_boundary = new_boundary; |
| 150 | } | 163 | } |
| 151 | 164 | ||
| 152 | for (const MapArea& map_area : GetGameData().GetMapAreas()) { | 165 | for (const MapArea& map_area : GD_GetMapAreas()) { |
| 153 | for (int section_id = 0; section_id < map_area.locations.size(); | 166 | for (int section_id = 0; section_id < map_area.locations.size(); |
| 154 | section_id++) { | 167 | section_id++) { |
| 155 | const Location& location_section = map_area.locations.at(section_id); | 168 | const Location& location_section = map_area.locations.at(section_id); |
| @@ -160,22 +173,17 @@ void TrackerState::CalculateState() { | |||
| 160 | } | 173 | } |
| 161 | } | 174 | } |
| 162 | 175 | ||
| 163 | reachability_[{map_area.id, section_id}] = reachable; | 176 | GetState().reachability[{map_area.id, section_id}] = reachable; |
| 164 | } | 177 | } |
| 165 | } | 178 | } |
| 166 | } | 179 | } |
| 167 | 180 | ||
| 168 | bool TrackerState::IsLocationReachable(int area_id, int section_id) { | 181 | bool IsLocationReachable(int area_id, int section_id) { |
| 169 | std::tuple<int, int> key = {area_id, section_id}; | 182 | std::tuple<int, int> key = {area_id, section_id}; |
| 170 | 183 | ||
| 171 | if (reachability_.count(key)) { | 184 | if (GetState().reachability.count(key)) { |
| 172 | return reachability_.at(key); | 185 | return GetState().reachability.at(key); |
| 173 | } else { | 186 | } else { |
| 174 | return false; | 187 | return false; |
| 175 | } | 188 | } |
| 176 | } | 189 | } |
| 177 | |||
| 178 | TrackerState& GetTrackerState() { | ||
| 179 | static TrackerState* instance = new TrackerState(); | ||
| 180 | return *instance; | ||
| 181 | } | ||
