From e8e7e512926a2bf9dfea22068f05a29a5ddcafd2 Mon Sep 17 00:00:00 2001 From: Malkierian Date: Tue, 23 Jul 2024 18:54:25 -0700 Subject: [PATCH] Change `inLogic` to static array. --- soh/soh/Enhancements/randomizer/item.cpp | 4 ++-- soh/soh/Enhancements/randomizer/logic.cpp | 14 ++++---------- soh/soh/Enhancements/randomizer/logic.h | 2 +- soh/soh/Enhancements/randomizer/randomizerTypes.h | 1 + 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/soh/soh/Enhancements/randomizer/item.cpp b/soh/soh/Enhancements/randomizer/item.cpp index 1c4bc10357d..e27fbeb1048 100644 --- a/soh/soh/Enhancements/randomizer/item.cpp +++ b/soh/soh/Enhancements/randomizer/item.cpp @@ -40,14 +40,14 @@ Item::Item(const RandomizerGet randomizerGet_, Text name_, const ItemType type_, void Item::ApplyEffect() const { auto ctx = Rando::Context::GetInstance(); ctx->ApplyItemEffect(StaticData::RetrieveItem(randomizerGet), false); - ctx->GetLogic()->SetInLogic(logicVar, false); + ctx->GetLogic()->SetInLogic(logicVar, true); ctx->GetLogic()->UpdateHelpers(); } void Item::UndoEffect() const { auto ctx = Rando::Context::GetInstance(); ctx->ApplyItemEffect(StaticData::RetrieveItem(randomizerGet), true); - ctx->GetLogic()->SetInLogic(logicVar, true); + ctx->GetLogic()->SetInLogic(logicVar, false); ctx->GetLogic()->UpdateHelpers(); } diff --git a/soh/soh/Enhancements/randomizer/logic.cpp b/soh/soh/Enhancements/randomizer/logic.cpp index 7432cbcc4d5..ea17fbd3748 100644 --- a/soh/soh/Enhancements/randomizer/logic.cpp +++ b/soh/soh/Enhancements/randomizer/logic.cpp @@ -768,22 +768,16 @@ namespace Rando { } bool Logic::GetInLogic(LogicVal logicVar) { - return std::find(inLogic.begin(), inLogic.end(), logicVar) != inLogic.end(); + return inLogic[logicVar]; } - void Logic::SetInLogic(LogicVal logicVar, bool remove) { - auto it = std::find(inLogic.begin(), inLogic.end(), logicVar); - if (it == inLogic.end() && !remove) { - inLogic.push_back(logicVar); - } - else if (it != inLogic.end() && remove) { - inLogic.erase(it); - } + void Logic::SetInLogic(LogicVal logicVar, bool value) { + inLogic[logicVar] = value; } void Logic::Reset() { - //SPDLOG_INFO("Logic reset."); ctx->NewSaveContext(); + memset(inLogic, false, sizeof(inLogic)); //Settings-dependent variables IsKeysanity = ctx->GetOption(RSK_KEYSANITY).Is(RO_DUNGEON_ITEM_LOC_ANYWHERE) || ctx->GetOption(RSK_KEYSANITY).Is(RO_DUNGEON_ITEM_LOC_ANYWHERE) || diff --git a/soh/soh/Enhancements/randomizer/logic.h b/soh/soh/Enhancements/randomizer/logic.h index 5d908b42a1d..304b92eabd3 100644 --- a/soh/soh/Enhancements/randomizer/logic.h +++ b/soh/soh/Enhancements/randomizer/logic.h @@ -435,6 +435,6 @@ class Logic { static bool IsMagicItem(RandomizerGet item); static bool IsMagicArrow(RandomizerGet item); std::shared_ptr ctx; - std::vector inLogic; + bool inLogic[LOGIC_MAX]; }; // class Logic } // namespace Rando \ No newline at end of file diff --git a/soh/soh/Enhancements/randomizer/randomizerTypes.h b/soh/soh/Enhancements/randomizer/randomizerTypes.h index a1a81d03f77..6162b3341d2 100644 --- a/soh/soh/Enhancements/randomizer/randomizerTypes.h +++ b/soh/soh/Enhancements/randomizer/randomizerTypes.h @@ -200,6 +200,7 @@ typedef enum { LOGIC_OCARINA_C_LEFT_BUTTON, LOGIC_OCARINA_C_RIGHT_BUTTON, LOGIC_TRIFORCE_PIECES, + LOGIC_MAX } LogicVal; typedef enum {