From 1b75b5ef87fadac202e80e58acf33e0427a86d26 Mon Sep 17 00:00:00 2001 From: xxAtrain223 Date: Mon, 14 Jul 2025 21:31:14 -0500 Subject: [PATCH] Calculate Show Randomizer Checks/Regions before drawing each frame. Remove nodes after showing a region. --- .../randomizer/randomizer_logic_tracker.cpp | 50 +++++++++++++++++-- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/soh/soh/Enhancements/randomizer/randomizer_logic_tracker.cpp b/soh/soh/Enhancements/randomizer/randomizer_logic_tracker.cpp index b831691bb..17df0bf5d 100644 --- a/soh/soh/Enhancements/randomizer/randomizer_logic_tracker.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer_logic_tracker.cpp @@ -155,8 +155,18 @@ static void PopulateConnectionExpression(LogicTrackerNode::Connection& connectio connection.ExpressionTable.CombineAdult = combineAdult; } +RandomizerCheck showRandomizerCheck = RC_UNKNOWN_CHECK; + void LogicTrackerWindow::ShowRandomizerCheck(RandomizerCheck randomizerCheck) { - const auto& location = Rando::StaticData::GetLocation(randomizerCheck); + showRandomizerCheck = randomizerCheck; +} + +static void CalculateShowRandomizerCheck() { + if (showRandomizerCheck == RC_UNKNOWN_CHECK) { + return; + } + + const auto& location = Rando::StaticData::GetLocation(showRandomizerCheck); nodes.clear(); @@ -167,7 +177,7 @@ void LogicTrackerWindow::ShowRandomizerCheck(RandomizerCheck randomizerCheck) { for (int randomizerRegion = RR_NONE; randomizerRegion < RR_MAX; ++randomizerRegion) { const auto& region = areaTable[randomizerRegion]; for (const auto& locationAccess : region.locations) { - if (locationAccess.GetLocation() == randomizerCheck) { + if (locationAccess.GetLocation() == showRandomizerCheck) { LogicTrackerNode::Connection connection; connection.ParentName = "Region: " + region.regionName; connection.ParentRandomizerRegion = RandomizerRegion(randomizerRegion); @@ -189,19 +199,33 @@ void LogicTrackerWindow::ShowRandomizerCheck(RandomizerCheck randomizerCheck) { window->Show(); ImGui::SetWindowFocus(window->GetName().c_str()); expandNodeId = node.NodeId; + + showRandomizerCheck = RC_UNKNOWN_CHECK; } +RandomizerRegion showToRandomizerRegion = RR_NONE; +RandomizerRegion showFromRandomizerRegion = RR_NONE; + void LogicTrackerWindow::ShowRandomizerRegion(RandomizerRegion toRandomizerRegion, RandomizerRegion fromRandomizerRegion) { - const auto& region = RegionTable(toRandomizerRegion); + showToRandomizerRegion = toRandomizerRegion; + showFromRandomizerRegion = fromRandomizerRegion; +} + +static void CalculateShowRandomizerRegion() { + if (showToRandomizerRegion == RR_NONE) { + return; + } + + const auto& region = RegionTable(showToRandomizerRegion); LogicTrackerNode node; node.NodeName = "Region: " + region->regionName; node.NodeId = nodes.size(); - node.RandomizerRegion = toRandomizerRegion; + node.RandomizerRegion = showToRandomizerRegion; for (const auto& entrance : region->entrances) { - if (entrance->GetParentRegionKey() == fromRandomizerRegion) { + if (entrance->GetParentRegionKey() == showFromRandomizerRegion) { continue; } @@ -226,6 +250,9 @@ void LogicTrackerWindow::ShowRandomizerRegion(RandomizerRegion toRandomizerRegio window->Show(); ImGui::SetWindowFocus(window->GetName().c_str()); expandNodeId = node.NodeId; + + showToRandomizerRegion = RR_NONE; + showFromRandomizerRegion = RR_NONE; } static std::string ToString(const std::optional& value) { @@ -508,6 +535,8 @@ static std::string GetAvailableString(const LogicTrackerNode::Connection& connec return available; } +int clearNodesAfterNodeID = -1; + static void DrawNode(LogicTrackerNode& node) { ImGui::PushID(node.NodeId); @@ -549,6 +578,7 @@ static void DrawNode(LogicTrackerNode& node) { ImGui::SameLine(); if (ImGui::Button(ICON_FA_COGS)) { LogicTrackerWindow::ShowRandomizerRegion(connection.ParentRandomizerRegion, node.RandomizerRegion); + clearNodesAfterNodeID = node.NodeId; } if (ImGui::IsItemHovered()) { ImGui::SetTooltip("Show Region Logic"); @@ -568,6 +598,9 @@ static void DrawNode(LogicTrackerNode& node) { } void LogicTrackerWindow::DrawElement() { + CalculateShowRandomizerCheck(); + CalculateShowRandomizerRegion(); + if (expandNodeId != -1) { expandingNode = true; } @@ -580,6 +613,13 @@ void LogicTrackerWindow::DrawElement() { expandNodeId = -1; expandingNode = false; } + + if (clearNodesAfterNodeID != -1) { + while (nodes.back().NodeId > clearNodesAfterNodeID) { + nodes.pop_back(); + } + clearNodesAfterNodeID = -1; + } } void LogicTrackerWindow::InitElement() {