Tracker Debug Performance, Vanilla Save Fix (#4397)

* Improve check tracker performance.

* Fix vanilla saves getting randomizer quest assignment.
Fix trying to load blank data blocks from save file.
Prevent writing randomizer block, even if empty, when save type isn't rando.
This commit is contained in:
Malkierian 2024-10-12 23:38:07 -07:00 committed by GitHub
parent 64ee12c11f
commit 05962baf45
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 77 additions and 63 deletions

View File

@ -147,6 +147,15 @@ void UpdateInventoryChecks();
void UpdateOrdering(RandomizerCheckArea); void UpdateOrdering(RandomizerCheckArea);
int sectionId; int sectionId;
bool hideUnchecked = false;
bool hideScummed = false;
bool hideSeen = false;
bool hideSkipped = false;
bool hideSaved = false;
bool hideCollected = false;
bool showHidden = true;
bool mystery = false;
bool showLogicTooltip = false;
SceneID DungeonSceneLookupByArea(RandomizerCheckArea area) { SceneID DungeonSceneLookupByArea(RandomizerCheckArea area) {
switch (area) { switch (area) {
@ -883,8 +892,6 @@ void CheckTrackerWindow::DrawElement() {
return; return;
} }
RegionTable_Init();
ImGui::TableNextRow(0, headerHeight); ImGui::TableNextRow(0, headerHeight);
ImGui::TableNextColumn(); ImGui::TableNextColumn();
UIWidgets::EnhancementCheckbox( UIWidgets::EnhancementCheckbox(
@ -933,7 +940,7 @@ void CheckTrackerWindow::DrawElement() {
RainbowTick(); RainbowTick();
bool doDraw = false; bool doDraw = false;
bool thisAreaFullyChecked = false; bool thisAreaFullyChecked = false;
bool showHidden = CVarGetInteger(CVAR_TRACKER_CHECK("ShowHidden"), 0); bool mqSpoilers = CVarGetInteger(CVAR_TRACKER_CHECK("MQSpoilers"), 0);
bool hideIncomplete = CVarGetInteger(CVAR_TRACKER_CHECK("AreaIncomplete.Hide"), 0); bool hideIncomplete = CVarGetInteger(CVAR_TRACKER_CHECK("AreaIncomplete.Hide"), 0);
bool hideComplete = CVarGetInteger(CVAR_TRACKER_CHECK("AreaComplete.Hide"), 0); bool hideComplete = CVarGetInteger(CVAR_TRACKER_CHECK("AreaComplete.Hide"), 0);
bool collapseLogic; bool collapseLogic;
@ -1000,7 +1007,7 @@ void CheckTrackerWindow::DrawElement() {
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(extraColor.r / 255.0f, extraColor.g / 255.0f, ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(extraColor.r / 255.0f, extraColor.g / 255.0f,
extraColor.b / 255.0f, extraColor.a / 255.0f)); extraColor.b / 255.0f, extraColor.a / 255.0f));
isThisAreaSpoiled = IsAreaSpoiled(rcArea) || CVarGetInteger(CVAR_TRACKER_CHECK("MQSpoilers"), 0); isThisAreaSpoiled = IsAreaSpoiled(rcArea) || mqSpoilers;
if (isThisAreaSpoiled) { if (isThisAreaSpoiled) {
if (showVOrMQ && RandomizerCheckObjects::AreaIsDungeon(rcArea)) { if (showVOrMQ && RandomizerCheckObjects::AreaIsDungeon(rcArea)) {
@ -1380,65 +1387,64 @@ void DrawLocation(RandomizerCheck rc) {
Color_RGBA8 mainColor; Color_RGBA8 mainColor;
Color_RGBA8 extraColor; Color_RGBA8 extraColor;
std::string txt; std::string txt;
bool showHidden = CVarGetInteger(CVAR_TRACKER_CHECK("ShowHidden"), 0);
Rando::Location* loc = Rando::StaticData::GetLocation(rc); Rando::Location* loc = Rando::StaticData::GetLocation(rc);
Rando::ItemLocation* itemLoc = OTRGlobals::Instance->gRandoContext->GetItemLocation(rc); Rando::ItemLocation* itemLoc = OTRGlobals::Instance->gRandoContext->GetItemLocation(rc);
RandomizerCheckStatus status = itemLoc->GetCheckStatus(); RandomizerCheckStatus status = itemLoc->GetCheckStatus();
bool skipped = itemLoc->GetIsSkipped(); bool skipped = itemLoc->GetIsSkipped();
if (status == RCSHOW_COLLECTED) { if (status == RCSHOW_COLLECTED) {
if (!showHidden && CVarGetInteger(CVAR_TRACKER_CHECK("Collected.Hide"), 0)) { if (!showHidden && hideCollected) {
return; return;
} }
mainColor = mainColor =
!IsHeartPiece((GetItemID)Rando::StaticData::RetrieveItem(loc->GetVanillaItem()).GetItemID()) && !IS_RANDO !IsHeartPiece((GetItemID)Rando::StaticData::RetrieveItem(loc->GetVanillaItem()).GetItemID()) && !IS_RANDO
? CVarGetColor(CVAR_TRACKER_CHECK("Collected.ExtraColor"), Color_Collected_Extra_Default) ? Color_Collected_Extra_Default
: CVarGetColor(CVAR_TRACKER_CHECK("Collected.MainColor"), Color_Main_Default); : Color_Main_Default;
extraColor = CVarGetColor(CVAR_TRACKER_CHECK("Collected.ExtraColor"), Color_Collected_Extra_Default); extraColor = Color_Collected_Extra_Default;
} else if (status == RCSHOW_SAVED) { } else if (status == RCSHOW_SAVED) {
if (!showHidden && CVarGetInteger(CVAR_TRACKER_CHECK("Saved.Hide"), 0)) { if (!showHidden && hideSaved) {
return; return;
} }
mainColor = mainColor =
!IsHeartPiece((GetItemID)Rando::StaticData::RetrieveItem(loc->GetVanillaItem()).GetItemID()) && !IS_RANDO !IsHeartPiece((GetItemID)Rando::StaticData::RetrieveItem(loc->GetVanillaItem()).GetItemID()) && !IS_RANDO
? CVarGetColor(CVAR_TRACKER_CHECK("Saved.ExtraColor"), Color_Saved_Extra_Default) ? Color_Saved_Extra_Default
: CVarGetColor(CVAR_TRACKER_CHECK("Saved.MainColor"), Color_Main_Default); : Color_Main_Default;
extraColor = CVarGetColor(CVAR_TRACKER_CHECK("Saved.ExtraColor"), Color_Saved_Extra_Default); extraColor = Color_Saved_Extra_Default;
} else if (skipped) { } else if (skipped) {
if (!showHidden && CVarGetInteger(CVAR_TRACKER_CHECK("Skipped.Hide"), 0)) { if (!showHidden && hideSkipped) {
return; return;
} }
mainColor = mainColor =
!IsHeartPiece((GetItemID)Rando::StaticData::RetrieveItem(loc->GetVanillaItem()).GetItemID()) && !IS_RANDO !IsHeartPiece((GetItemID)Rando::StaticData::RetrieveItem(loc->GetVanillaItem()).GetItemID()) && !IS_RANDO
? CVarGetColor(CVAR_TRACKER_CHECK("Skipped.ExtraColor"), Color_Skipped_Extra_Default) ? Color_Skipped_Extra_Default
: CVarGetColor(CVAR_TRACKER_CHECK("Skipped.MainColor"), Color_Main_Default); : Color_Main_Default;
extraColor = CVarGetColor(CVAR_TRACKER_CHECK("Skipped.ExtraColor"), Color_Skipped_Extra_Default); extraColor = Color_Skipped_Extra_Default;
} else if (status == RCSHOW_SEEN || status == RCSHOW_IDENTIFIED) { } else if (status == RCSHOW_SEEN || status == RCSHOW_IDENTIFIED) {
if (!showHidden && CVarGetInteger(CVAR_TRACKER_CHECK("Seen.Hide"), 0)) { if (!showHidden && hideSeen) {
return; return;
} }
mainColor = mainColor =
!IsHeartPiece((GetItemID)Rando::StaticData::RetrieveItem(loc->GetVanillaItem()).GetItemID()) && !IS_RANDO !IsHeartPiece((GetItemID)Rando::StaticData::RetrieveItem(loc->GetVanillaItem()).GetItemID()) && !IS_RANDO
? CVarGetColor(CVAR_TRACKER_CHECK("Seen.ExtraColor"), Color_Seen_Extra_Default) ? Color_Seen_Extra_Default
: CVarGetColor(CVAR_TRACKER_CHECK("Seen.MainColor"), Color_Main_Default); : Color_Main_Default;
extraColor = CVarGetColor(CVAR_TRACKER_CHECK("Seen.ExtraColor"), Color_Seen_Extra_Default); extraColor = Color_Seen_Extra_Default;
} else if (status == RCSHOW_SCUMMED) { } else if (status == RCSHOW_SCUMMED) {
if (!showHidden && CVarGetInteger(CVAR_TRACKER_CHECK("Scummed.Hide"), 0)) { if (!showHidden && hideScummed) {
return; return;
} }
mainColor = mainColor =
!IsHeartPiece((GetItemID)Rando::StaticData::RetrieveItem(loc->GetVanillaItem()).GetItemID()) && !IS_RANDO !IsHeartPiece((GetItemID)Rando::StaticData::RetrieveItem(loc->GetVanillaItem()).GetItemID()) && !IS_RANDO
? CVarGetColor(CVAR_TRACKER_CHECK("Scummed.ExtraColor"), Color_Scummed_Extra_Default) ? Color_Scummed_Extra_Default
: CVarGetColor(CVAR_TRACKER_CHECK("Scummed.MainColor"), Color_Main_Default); : Color_Main_Default;
extraColor = CVarGetColor(CVAR_TRACKER_CHECK("Scummed.ExtraColor"), Color_Scummed_Extra_Default); extraColor = Color_Scummed_Extra_Default;
} else if (status == RCSHOW_UNCHECKED) { } else if (status == RCSHOW_UNCHECKED) {
if (!showHidden && CVarGetInteger(CVAR_TRACKER_CHECK("Unchecked.Hide"), 0)) { if (!showHidden && hideUnchecked) {
return; return;
} }
mainColor = mainColor =
!IsHeartPiece((GetItemID)Rando::StaticData::RetrieveItem(loc->GetVanillaItem()).GetItemID()) && !IS_RANDO !IsHeartPiece((GetItemID)Rando::StaticData::RetrieveItem(loc->GetVanillaItem()).GetItemID()) && !IS_RANDO
? CVarGetColor(CVAR_TRACKER_CHECK("Unchecked.ExtraColor"), Color_Unchecked_Extra_Default) ? Color_Unchecked_Extra_Default
: CVarGetColor(CVAR_TRACKER_CHECK("Unchecked.MainColor"), Color_Main_Default); : Color_Main_Default;
extraColor = CVarGetColor(CVAR_TRACKER_CHECK("Unchecked.ExtraColor"), Color_Unchecked_Extra_Default); extraColor = Color_Unchecked_Extra_Default;
} }
//Main Text //Main Text
@ -1481,8 +1487,6 @@ void DrawLocation(RandomizerCheck rc) {
//Draw the extra info //Draw the extra info
txt = ""; txt = "";
bool mystery = CVarGetInteger(CVAR_RANDOMIZER_ENHANCEMENT("MysteriousShuffle"), 0) && itemLoc->IsAddedToPool();
if (status != RCSHOW_UNCHECKED) { if (status != RCSHOW_UNCHECKED) {
switch (status) { switch (status) {
case RCSHOW_SAVED: case RCSHOW_SAVED:
@ -1503,16 +1507,16 @@ void DrawLocation(RandomizerCheck rc) {
case RCSHOW_IDENTIFIED: case RCSHOW_IDENTIFIED:
case RCSHOW_SEEN: case RCSHOW_SEEN:
if (IS_RANDO) { if (IS_RANDO) {
if (itemLoc->GetPlacedRandomizerGet() == RG_ICE_TRAP && !mystery) { if (itemLoc->GetPlacedRandomizerGet() == RG_ICE_TRAP && !mystery && !itemLoc->IsAddedToPool()) {
if (status == RCSHOW_IDENTIFIED) { if (status == RCSHOW_IDENTIFIED) {
txt = OTRGlobals::Instance->gRandoContext->overrides[rc].GetTrickName().GetForLanguage(gSaveContext.language); txt = OTRGlobals::Instance->gRandoContext->overrides[rc].GetTrickName().GetForLanguage(gSaveContext.language);
} else { } else {
txt = Rando::StaticData::RetrieveItem(OTRGlobals::Instance->gRandoContext->overrides[rc].LooksLike()).GetName().GetForLanguage(gSaveContext.language); txt = Rando::StaticData::RetrieveItem(OTRGlobals::Instance->gRandoContext->overrides[rc].LooksLike()).GetName().GetForLanguage(gSaveContext.language);
} }
} else if (!mystery) { } else if (!mystery && !itemLoc->IsAddedToPool()) {
txt = itemLoc->GetPlacedItem().GetName().GetForLanguage(gSaveContext.language); txt = itemLoc->GetPlacedItem().GetName().GetForLanguage(gSaveContext.language);
} }
if (IsVisibleInCheckTracker(rc) && status == RCSHOW_IDENTIFIED && !mystery) { if (IsVisibleInCheckTracker(rc) && status == RCSHOW_IDENTIFIED && !mystery && !itemLoc->IsAddedToPool()) {
txt += fmt::format(" - {}", OTRGlobals::Instance->gRandoContext->GetItemLocation(rc)->GetPrice()); txt += fmt::format(" - {}", OTRGlobals::Instance->gRandoContext->GetItemLocation(rc)->GetPrice());
} }
} else { } else {
@ -1538,7 +1542,7 @@ void DrawLocation(RandomizerCheck rc) {
ImGui::PopStyleColor(); ImGui::PopStyleColor();
} }
if (CVarGetInteger("gCheckTrackerOptionShowLogic", 0)) { if (showLogicTooltip) {
for (auto& locationInRegion : areaTable[itemLoc->GetParentRegionKey()].locations) { for (auto& locationInRegion : areaTable[itemLoc->GetParentRegionKey()].locations) {
if (locationInRegion.GetLocation() == rc) { if (locationInRegion.GetLocation() == rc) {
std::string conditionStr = locationInRegion.GetConditionStr(); std::string conditionStr = locationInRegion.GetConditionStr();
@ -1705,6 +1709,22 @@ void CheckTrackerSettingsWindow::DrawElement() {
} }
void CheckTrackerWindow::InitElement() { void CheckTrackerWindow::InitElement() {
SaveManager::Instance->AddInitFunction(InitTrackerData);
sectionId = SaveManager::Instance->AddSaveFunction("trackerData", 1, SaveFile, true, SECTION_PARENT_NONE);
SaveManager::Instance->AddLoadFunction("trackerData", 1, LoadFile);
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnLoadGame>(CheckTrackerLoadGame);
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnExitGame>([](uint32_t fileNum) {
Teardown();
});
// GameInteractor::Instance->RegisterGameHook<GameInteractor::OnItemReceive>(CheckTrackerItemReceive);
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnGameFrameUpdate>(CheckTrackerFrame);
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnTransitionEnd>(CheckTrackerTransition);
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnShopSlotChange>(CheckTrackerShopSlotChange);
// GameInteractor::Instance->RegisterGameHook<GameInteractor::OnSceneFlagSet>(CheckTrackerSceneFlagSet);
// GameInteractor::Instance->RegisterGameHook<GameInteractor::OnFlagSet>(CheckTrackerFlagSet);
}
void CheckTrackerWindow::UpdateElement() {
Color_Background = CVarGetColor(CVAR_TRACKER_CHECK("BgColor"), Color_Bg_Default); Color_Background = CVarGetColor(CVAR_TRACKER_CHECK("BgColor"), Color_Bg_Default);
Color_Area_Incomplete_Main = CVarGetColor(CVAR_TRACKER_CHECK("AreaIncomplete.MainColor"), Color_Main_Default); Color_Area_Incomplete_Main = CVarGetColor(CVAR_TRACKER_CHECK("AreaIncomplete.MainColor"), Color_Main_Default);
Color_Area_Incomplete_Extra = CVarGetColor(CVAR_TRACKER_CHECK("AreaIncomplete.ExtraColor"), Color_Area_Incomplete_Extra_Default); Color_Area_Incomplete_Extra = CVarGetColor(CVAR_TRACKER_CHECK("AreaIncomplete.ExtraColor"), Color_Area_Incomplete_Extra_Default);
@ -1724,23 +1744,17 @@ void CheckTrackerWindow::InitElement() {
Color_Scummed_Extra = CVarGetColor(CVAR_TRACKER_CHECK("Scummed.ExtraColor"), Color_Scummed_Extra_Default); Color_Scummed_Extra = CVarGetColor(CVAR_TRACKER_CHECK("Scummed.ExtraColor"), Color_Scummed_Extra_Default);
Color_Saved_Main = CVarGetColor(CVAR_TRACKER_CHECK("Saved.MainColor"), Color_Main_Default); Color_Saved_Main = CVarGetColor(CVAR_TRACKER_CHECK("Saved.MainColor"), Color_Main_Default);
Color_Saved_Extra = CVarGetColor(CVAR_TRACKER_CHECK("Saved.ExtraColor"), Color_Saved_Extra_Default); Color_Saved_Extra = CVarGetColor(CVAR_TRACKER_CHECK("Saved.ExtraColor"), Color_Saved_Extra_Default);
hideUnchecked = CVarGetInteger(CVAR_TRACKER_CHECK("Unchecked.Hide"), 0);
SaveManager::Instance->AddInitFunction(InitTrackerData); hideScummed = CVarGetInteger(CVAR_TRACKER_CHECK("Scummed.Hide"), 0);
sectionId = SaveManager::Instance->AddSaveFunction("trackerData", 1, SaveFile, true, SECTION_PARENT_NONE); hideSeen = CVarGetInteger(CVAR_TRACKER_CHECK("Seen.Hide"), 0);
SaveManager::Instance->AddLoadFunction("trackerData", 1, LoadFile); hideSkipped = CVarGetInteger(CVAR_TRACKER_CHECK("Skipped.Hide"), 0);
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnLoadGame>(CheckTrackerLoadGame); hideSaved = CVarGetInteger(CVAR_TRACKER_CHECK("Saved.Hide"), 0);
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnExitGame>([](uint32_t fileNum) { hideCollected = CVarGetInteger(CVAR_TRACKER_CHECK("Collected.Hide"), 0);
Teardown(); showHidden = CVarGetInteger(CVAR_TRACKER_CHECK("ShowHidden"), 0);
}); mystery = CVarGetInteger(CVAR_RANDOMIZER_ENHANCEMENT("MysteriousShuffle"), 0);
// GameInteractor::Instance->RegisterGameHook<GameInteractor::OnItemReceive>(CheckTrackerItemReceive); showLogicTooltip = CVarGetInteger("gCheckTrackerOptionShowLogic", 0);
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnGameFrameUpdate>(CheckTrackerFrame);
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnTransitionEnd>(CheckTrackerTransition);
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnShopSlotChange>(CheckTrackerShopSlotChange);
// GameInteractor::Instance->RegisterGameHook<GameInteractor::OnSceneFlagSet>(CheckTrackerSceneFlagSet);
// GameInteractor::Instance->RegisterGameHook<GameInteractor::OnFlagSet>(CheckTrackerFlagSet);
hideShopRightChecks = CVarGetInteger(CVAR_TRACKER_CHECK("HideRightShopChecks"), 1); hideShopRightChecks = CVarGetInteger(CVAR_TRACKER_CHECK("HideRightShopChecks"), 1);
alwaysShowGS = CVarGetInteger(CVAR_TRACKER_CHECK("AlwaysShowGSLocs"), 0); alwaysShowGS = CVarGetInteger(CVAR_TRACKER_CHECK("AlwaysShowGSLocs"), 0);
} }
} // namespace CheckTracker } // namespace CheckTracker

View File

@ -26,7 +26,7 @@ class CheckTrackerWindow : public Ship::GuiWindow {
protected: protected:
void InitElement() override; void InitElement() override;
void DrawElement() override; void DrawElement() override;
void UpdateElement() override {}; void UpdateElement() override;
}; };
//Converts an index into a Little Endian bitmask, as follows: //Converts an index into a Little Endian bitmask, as follows:

View File

@ -1160,17 +1160,14 @@ void SaveManager::SaveFileThreaded(int fileNum, SaveContext* saveContext, int se
for (auto& sectionHandlerPair : sectionSaveHandlers) { for (auto& sectionHandlerPair : sectionSaveHandlers) {
auto& saveFuncInfo = sectionHandlerPair.second; auto& saveFuncInfo = sectionHandlerPair.second;
// Don't call SaveFuncs for sections that aren't tied to game save // Don't call SaveFuncs for sections that aren't tied to game save
if (!saveFuncInfo.saveWithBase) { if (!saveFuncInfo.saveWithBase || (saveFuncInfo.name == "randomizer" && !IS_RANDO)) {
continue; continue;
} }
nlohmann::json& sectionBlock = saveBlock["sections"][saveFuncInfo.name]; nlohmann::json& sectionBlock = saveBlock["sections"][saveFuncInfo.name];
sectionBlock["version"] = sectionHandlerPair.second.version; sectionBlock["version"] = sectionHandlerPair.second.version;
// If any save file is loaded for medatata, or a spoiler log is loaded (not sure which at this point), there is still data in the "randomizer" section // If any save file is loaded for medatata, or a spoiler log is loaded (not sure which at this point), there is still data in the "randomizer" section
// This clears the randomizer data block if and only if the section being called is "randomizer" and the current save file is not a randomizer save file. // This clears the randomizer data block if and only if the section being called is "randomizer" and the current save file is not a randomizer save file.
if (sectionHandlerPair.second.name == "randomizer" && !IS_RANDO) {
sectionBlock["data"] = nlohmann::json::object();
continue;
}
currentJsonContext = &sectionBlock["data"]; currentJsonContext = &sectionBlock["data"];
sectionHandlerPair.second.func(saveContext, sectionID, true); sectionHandlerPair.second.func(saveContext, sectionID, true);
@ -1309,6 +1306,9 @@ void SaveManager::LoadFile(int fileNum) {
continue; continue;
} }
currentJsonContext = &block.value()["data"]; currentJsonContext = &block.value()["data"];
if (currentJsonContext->empty()) {
continue;
}
handler[sectionVersion](); handler[sectionVersion]();
} }
break; break;

View File

@ -250,12 +250,12 @@ void Sram_InitSave(FileChooseContext* fileChooseCtx) {
u8 currentQuest = fileChooseCtx->questType[fileChooseCtx->buttonIndex]; u8 currentQuest = fileChooseCtx->questType[fileChooseCtx->buttonIndex];
if (Randomizer_IsSeedGenerated() || Randomizer_IsPlandoLoaded()) { if (currentQuest == QUEST_RANDOMIZER && (Randomizer_IsSeedGenerated() || Randomizer_IsPlandoLoaded())) {
gSaveContext.questId = QUEST_RANDOMIZER; gSaveContext.questId = QUEST_RANDOMIZER;
Randomizer_InitSaveFile(); Randomizer_InitSaveFile();
} else if (currentQuest == QUEST_MASTER) { } else {
gSaveContext.questId = QUEST_MASTER; gSaveContext.questId = currentQuest;
} }
Save_SaveFile(); Save_SaveFile();