From 32cbf96184ac828310c53b8000d28111082a887e Mon Sep 17 00:00:00 2001 From: robojumper Date: Fri, 14 Mar 2025 03:13:15 +0100 Subject: [PATCH] Link dowsing_target, eggException, d_lyt_meter_drink (#128) * Link dowsing_target, eggException * d_lyt_meter_drink OK (thanks Zeldex!) * More sensible DowsingTarget flag code * Attempt explaining TList inline --- configure.py | 6 ++--- include/egg/core/eggVideo.h | 2 +- include/egg/util/eggException.h | 2 +- include/nw4r/lyt/lyt_types.h | 2 +- include/toBeSorted/tlist.h | 15 +++++++++++ src/d/lyt/meter/d_lyt_meter_drink.cpp | 36 +++++++++++++-------------- src/egg/util/eggException.cpp | 11 ++++---- src/toBeSorted/dowsing_target.cpp | 22 ++++++---------- 8 files changed, 53 insertions(+), 43 deletions(-) diff --git a/configure.py b/configure.py index e3e08fae..d9a7592f 100644 --- a/configure.py +++ b/configure.py @@ -362,7 +362,7 @@ config.libs = [ Object(Matching, "toBeSorted/arc_managers/oarc_manager.cpp"), Object(Matching, "toBeSorted/arc_managers/layout_arc_manager.cpp"), Object(NonMatching, "toBeSorted/attention.cpp"), - Object(NonMatching, "toBeSorted/dowsing_target.cpp"), + Object(Matching, "toBeSorted/dowsing_target.cpp"), Object(NonMatching, "toBeSorted/time_area_mgr.cpp"), Object(NonMatching, "toBeSorted/nand_request_thread.cpp"), Object(Matching, "toBeSorted/save_file.cpp"), @@ -385,7 +385,7 @@ config.libs = [ Object(NonMatching, "d/lyt/meter/d_lyt_meter_a_btn.cpp"), Object(NonMatching, "d/lyt/meter/d_lyt_meter_z_btn.cpp"), Object(NonMatching, "d/lyt/meter/d_lyt_meter_key.cpp"), - Object(NonMatching, "d/lyt/meter/d_lyt_meter_drink.cpp"), + Object(Matching, "d/lyt/meter/d_lyt_meter_drink.cpp"), Object(NonMatching, "d/lyt/meter/d_lyt_meter_remocon_bg.cpp"), Object(NonMatching, "d/lyt/meter/d_lyt_meter_nunchaku_bg.cpp"), Object(NonMatching, "d/lyt/meter/d_lyt_meter_nun_stk.cpp"), @@ -906,7 +906,7 @@ config.libs = [ EGGLib( "util", [ - Object(NonMatching, "egg/util/eggException.cpp"), + Object(Matching, "egg/util/eggException.cpp"), ], ), # { diff --git a/include/egg/core/eggVideo.h b/include/egg/core/eggVideo.h index c9cf571a..d4de25ba 100644 --- a/include/egg/core/eggVideo.h +++ b/include/egg/core/eggVideo.h @@ -30,7 +30,7 @@ public: static u32 getTickPerVRetrace(); static const GXRenderModeObj *getStandardRenderModeObj(const RenderModeObjSet *); - GXRenderModeObj *getCurrentOrFallbackRenderModeObj() const { + const GXRenderModeObj *getCurrentOrFallbackRenderModeObj() const { if (pRenderMode == nullptr) { return &lbl_8055FC64; } diff --git a/include/egg/util/eggException.h b/include/egg/util/eggException.h index 228d52ba..6a2cc957 100644 --- a/include/egg/util/eggException.h +++ b/include/egg/util/eggException.h @@ -21,7 +21,7 @@ public: static Exception *sException; - volatile static nw4r::db::ConsoleHandle sConsoleHandle; + static nw4r::db::ConsoleHandle sConsoleHandle; static void *sMapFileWorks; static u32 sMapFileNumMax; static u32 sCurrentMapFileNum; diff --git a/include/nw4r/lyt/lyt_types.h b/include/nw4r/lyt/lyt_types.h index d810d2c9..047638e2 100644 --- a/include/nw4r/lyt/lyt_types.h +++ b/include/nw4r/lyt/lyt_types.h @@ -27,7 +27,7 @@ struct BitGXNums { template inline bool TestBit(T bits, int index) { T mask = 1 << index; - return bits & mask; + return (bits & mask) != 0; } template inline void SetBit(T *bits, int pos, bool val) { diff --git a/include/toBeSorted/tlist.h b/include/toBeSorted/tlist.h index 3fae072e..64a841b4 100644 --- a/include/toBeSorted/tlist.h +++ b/include/toBeSorted/tlist.h @@ -78,6 +78,21 @@ public: } } + /** + * Returns an iterator representing the position of pT in this + * list. If pT is not in the list, the result is the end iterator. + * + * This is typically used to check if an object is contained in a + * list of this type. + */ + Iterator GetPosition(T *pT) { + if (pT->mLink.mpNext == nullptr || pT->mLink.mpPrev == nullptr) { + return GetEndIter(); + } else { + return Iterator(pT); + } + } + Iterator GetEndIter() { return Iterator(GetPtrFromNode(&mStartEnd)); } diff --git a/src/d/lyt/meter/d_lyt_meter_drink.cpp b/src/d/lyt/meter/d_lyt_meter_drink.cpp index 7d2e914f..a935ee46 100644 --- a/src/d/lyt/meter/d_lyt_meter_drink.cpp +++ b/src/d/lyt/meter/d_lyt_meter_drink.cpp @@ -406,6 +406,15 @@ bool dLytMeterDrink_c::build(d2d::ResAccIf_c *resAcc) { return true; } +bool dLytMeterDrink_c::remove() { + for (int i = 0; i < 20; i++) { + mAnmGroups[i].unbind(); + mAnmGroups[i].afterUnbind(); + } + + return true; +} + bool dLytMeterDrink_c::execute() { mStateMgr.executeState(); @@ -420,29 +429,11 @@ bool dLytMeterDrink_c::execute() { return true; } -bool dLytMeterDrink_c::remove() { - for (int i = 0; i < 20; i++) { - mAnmGroups[i].unbind(); - mAnmGroups[i].afterUnbind(); - } - - return true; -} - bool dLytMeterDrink_c::draw() { mLyt.addToDrawList(); return true; } -int dLytMeterDrink_c::getPartForDrinkType(dLytMeterDrinkParts_c::DrinkType_e ty) const { - for (int i = 0; i < 3; i++) { - if (ty == mParts[i].mDrinkType) { - return i; - } - } - return 3; -} - bool dLytMeterDrink_c::fn_800E5C40(int i) { if ((i == 0 || i == 3) && (FileManager::GetInstance()->getStaminaPotionTimer() != 0 || FileManager::GetInstance()->getStaminaPotionPlusTimer() != 0)) { @@ -462,6 +453,15 @@ bool dLytMeterDrink_c::fn_800E5C40(int i) { return false; } +int dLytMeterDrink_c::getPartForDrinkType(dLytMeterDrinkParts_c::DrinkType_e ty) const { + for (int i = 0; i < 3; i++) { + if (ty == mParts[i].mDrinkType) { + return i; + } + } + return 3; +} + void dLytMeterDrink_c::executeInternal() { bool bHasNotSoonExpiringDrink = false; bool bHasSoonExpiringDrink = false; diff --git a/src/egg/util/eggException.cpp b/src/egg/util/eggException.cpp index 6bf4e2e7..b02caae4 100644 --- a/src/egg/util/eggException.cpp +++ b/src/egg/util/eggException.cpp @@ -13,7 +13,7 @@ namespace EGG { Exception *Exception::sException; -volatile nw4r::db::ConsoleHandle Exception::sConsoleHandle; +nw4r::db::ConsoleHandle Exception::sConsoleHandle; void *Exception::sMapFileWorks; u32 Exception::sMapFileNumMax; u32 Exception::sCurrentMapFileNum; @@ -179,16 +179,17 @@ Exception::Exception(u16 width, u16 height, u16 attr, EGG::Heap *heap, int mapFi return; } - GXRenderModeObj *o = EGG::BaseSystem::getVideo()->getCurrentOrFallbackRenderModeObj(); - nw4r::db::Exception_SetConsole(sConsoleHandle, o); + const GXRenderModeObj *o = EGG::BaseSystem::getVideo()->getCurrentOrFallbackRenderModeObj(); + // Fakematch? Everything before Exception_SetConsole matches if it's volatile, but things after + // it break + nw4r::db::Exception_SetConsole(*(nw4r::db::ConsoleHandle *volatile)&sConsoleHandle, o); nw4r::db::Console_SetPosition(sConsoleHandle, 0, 30); nw4r::db::Console_SetVisible(sConsoleHandle, false); sMapFileNumMax = mapFileNum; - size_t size = mapFileNum * 0x14; sCurrentMapFileNum = 0; - sMapFileWorks = Heap::alloc(size, 4, heap); + sMapFileWorks = Heap::alloc(mapFileNum * 0x14, 4, heap); SetCallbackArgs(nullptr); } diff --git a/src/toBeSorted/dowsing_target.cpp b/src/toBeSorted/dowsing_target.cpp index 6b2d40ad..879447c3 100644 --- a/src/toBeSorted/dowsing_target.cpp +++ b/src/toBeSorted/dowsing_target.cpp @@ -136,9 +136,12 @@ bool DowsingTarget::hasDowsingInSlot(int slot) { } else if (slot == 2) { return hasCrystalBallDowsing() || hasPumpkinDowsing() || hasNewPlantSpeciesDowsing() || hasKikwiDowsing() || hasKeyPieceDowsing() || hasDesertNodeDowsing() || hasPartyWheelDowsing(); - } else if (StoryflagManager::sInstance->getCounterOrFlag(DOWSING_TARGET_STORY_FLAGS[slot])) { - // TODO small instruction shuffle - return true; + } else { + u16 flag = DOWSING_TARGET_STORY_FLAGS[slot]; + flag = StoryflagManager::sInstance->getCounterOrFlag(flag); + if (flag != 0) { + return true; + } } return false; @@ -199,22 +202,13 @@ void DowsingTarget::init() {} void DowsingTarget::execute() {} -// Not sure what this is -inline static TListNode *getNode(u8 slot, DowsingTarget *t) { - if (t->mLink.mpNext == nullptr || t->mLink.mpPrev == nullptr) { - return &DOWSING_LISTS[slot].mStartEnd; - } else { - return &t->mLink; - } -} - static bool insertDowsingTarget(DowsingTarget *target) { u8 slot = target->getSlot(); if (slot == DowsingTarget::SLOT_NONE) { return false; } - if (getNode(slot, target) != &DOWSING_LISTS[slot].mStartEnd) { + if (DOWSING_LISTS[slot].GetPosition(target) != DOWSING_LISTS[slot].GetEndIter()) { return false; } DOWSING_LISTS[slot].insert(target); @@ -227,7 +221,7 @@ static bool removeDowsingTarget(DowsingTarget *target) { return false; } - if (getNode(slot, target) != &DOWSING_LISTS[slot].mStartEnd) { + if (DOWSING_LISTS[slot].GetPosition(target) != DOWSING_LISTS[slot].GetEndIter()) { DOWSING_LISTS[slot].remove(target); return true; }