From dfaf6296a515273ec1697effbc4903e367956cb4 Mon Sep 17 00:00:00 2001 From: robojumper Date: Fri, 25 Oct 2024 15:15:10 +0200 Subject: [PATCH] Renames --- config/SOUE01/symbols.txt | 24 +++--- include/d/flag/baseflag_manager.h | 24 +++--- include/d/flag/dungeonflag_manager.h | 36 +++++++++ include/d/flag/flag_index.h | 37 ++++++++++ include/d/flag/itemflag_manager.h | 8 +- include/d/flag/storyflag_manager.h | 8 +- include/d/flag/unk_flag_stuff.h | 26 ------- src/d/flag/baseflag_manager.inc | 73 +++++++++---------- src/d/flag/dungeonflag_manager.inc | 46 ++---------- .../{unk_flag_stuff.inc => flag_index.inc} | 18 ++--- src/d/flag/flag_managers.cpp | 6 +- src/d/flag/flag_space.inc | 2 +- src/d/flag/itemflag_manager.inc | 12 +-- src/d/flag/sceneflag_manager.inc | 14 +--- src/d/flag/skipflag_manager.inc | 6 +- src/d/flag/storyflag_manager.inc | 18 ++--- 16 files changed, 181 insertions(+), 177 deletions(-) create mode 100644 include/d/flag/dungeonflag_manager.h create mode 100644 include/d/flag/flag_index.h delete mode 100644 include/d/flag/unk_flag_stuff.h rename src/d/flag/{unk_flag_stuff.inc => flag_index.inc} (66%) diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index d052772d..f889db3a 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -4129,21 +4129,21 @@ setAllToZero__9FlagSpaceFUsUs = .text:0x800BEE60; // type:function size:0x68 copyFromSaveFile2__9FlagSpaceFPCUsUsUs = .text:0x800BEED0; // type:function size:0x7C copyFromSaveFile__9FlagSpaceFPCUsUsUs = .text:0x800BEF50; // type:function size:0x20 filemanagerCheck__9FlagSpaceCFv = .text:0x800BEF70; // type:function size:0x20 -calculateMask__12UnkFlagStuffFl = .text:0x800BEF90; // type:function size:0x18 -doNothing__12UnkFlagStuffFUl = .text:0x800BEFB0; // type:function size:0x4 -__ct__12UnkFlagStuffFUsP17UnkFlagDefinition = .text:0x800BEFC0; // type:function size:0xC -prepareIndexShiftMask__12UnkFlagStuffFUsUlPUsPUcPUs = .text:0x800BEFD0; // type:function size:0x80 -maskForIdx__12UnkFlagStuffFUsUs = .text:0x800BF050; // type:function size:0x50 -getCounterOrFlag__12UnkFlagStuffFUsPCUsUl = .text:0x800BF0A0; // type:function size:0x68 -setCounterOrFlag__12UnkFlagStuffFUsPUsUlUl = .text:0x800BF110; // type:function size:0x9C -checkFlagValid__12UnkFlagStuffFUsUl = .text:0x800BF1B0; // type:function size:0x50 +calculateMask__9FlagIndexFl = .text:0x800BEF90; // type:function size:0x18 +doNothing__9FlagIndexFUl = .text:0x800BEFB0; // type:function size:0x4 +__ct__9FlagIndexFUsP14FlagDefinition = .text:0x800BEFC0; // type:function size:0xC +prepareIndexShiftMask__9FlagIndexFUsUlPUsPUcPUs = .text:0x800BEFD0; // type:function size:0x80 +maskForIdx__9FlagIndexFUsUs = .text:0x800BF050; // type:function size:0x50 +getCounterOrFlag__9FlagIndexFUsPCUsUl = .text:0x800BF0A0; // type:function size:0x68 +setCounterOrFlag__9FlagIndexFUsPUsUlUl = .text:0x800BF110; // type:function size:0x9C +checkFlagValid__9FlagIndexFUsUl = .text:0x800BF1B0; // type:function size:0x50 checkFlag__17BitwiseFlagHelperFUsUsPCUsUs = .text:0x800BF200; // type:function size:0x14 setFlag__17BitwiseFlagHelperFUsUsPUsUs = .text:0x800BF220; // type:function size:0x20 unsetFlag__17BitwiseFlagHelperFUsUsPUsUs = .text:0x800BF240; // type:function size:0x24 __ct__20ItemStoryManagerBaseFv = .text:0x800BF270; // type:function size:0x28 __dt__20ItemStoryManagerBaseFv = .text:0x800BF2A0; // type:function size:0x70 setFlagSizes__20ItemStoryManagerBaseFUsUs = .text:0x800BF310; // type:function size:0xC -setupUnkFlagStuff__20ItemStoryManagerBaseFP17UnkFlagDefinitionUs = .text:0x800BF320; // type:function size:0x60 +setupFlagIndex__20ItemStoryManagerBaseFP14FlagDefinitionUs = .text:0x800BF320; // type:function size:0x60 copyFlagsFromSave_Priv__20ItemStoryManagerBaseFv = .text:0x800BF380; // type:function size:0x58 init__20ItemStoryManagerBaseFv = .text:0x800BF3E0; // type:function size:0x88 setFlagszptr__20ItemStoryManagerBaseFv = .text:0x800BF470; // type:function size:0x4 @@ -4156,11 +4156,11 @@ setFlagOrCounterToValue__20ItemStoryManagerBaseFUsUs = .text:0x800BF5D0; // type getCounterOrFlag__20ItemStoryManagerBaseCFUs = .text:0x800BF5E0; // type:function size:0x4 getUncommittedValue__20ItemStoryManagerBaseFUs = .text:0x800BF5F0; // type:function size:0x4 unk3__20ItemStoryManagerBaseFUs = .text:0x800BF600; // type:function size:0x4 -FUN_800bf610__20ItemStoryManagerBaseFUs = .text:0x800BF610; // type:function size:0x18 +onFlagChange__20ItemStoryManagerBaseFUs = .text:0x800BF610; // type:function size:0x18 onDirty__20ItemStoryManagerBaseFv = .text:0x800BF630; // type:function size:0x4 -FUN_800bf640__20ItemStoryManagerBaseFUs = .text:0x800BF640; // type:function size:0x10 +getMaskForFlag__20ItemStoryManagerBaseFUs = .text:0x800BF640; // type:function size:0x10 doCommit_Priv__20ItemStoryManagerBaseFv = .text:0x800BF650; // type:function size:0x40 -FUN_800bf690__20ItemStoryManagerBaseFv = .text:0x800BF690; // type:function size:0x4 +postCommit__20ItemStoryManagerBaseFv = .text:0x800BF690; // type:function size:0x4 __ct__16StoryflagManagerFv = .text:0x800BF6A0; // type:function size:0x5C copyFlagsFromSave__16StoryflagManagerFv = .text:0x800BF700; // type:function size:0x3C setupUnkFlagsStuff__16StoryflagManagerFv = .text:0x800BF740; // type:function size:0x10 diff --git a/include/d/flag/baseflag_manager.h b/include/d/flag/baseflag_manager.h index 9d187957..42471bca 100644 --- a/include/d/flag/baseflag_manager.h +++ b/include/d/flag/baseflag_manager.h @@ -1,7 +1,7 @@ #ifndef D_FLAG_BASEFLAG_MANAGER_H #define D_FLAG_BASEFLAG_MANAGER_H -#include "d/flag/unk_flag_stuff.h" +#include "d/flag/flag_index.h" #include "d/flag/flag_space.h" class ItemStoryManagerBase { @@ -24,24 +24,26 @@ public: void init(); - void setFlagSizes(u16 flagSizeMaybe, u16 anotherFlagSizeMaybe); void copyFlagsFromSave_Priv(); - void setupUnkFlagStuff(UnkFlagDefinition *def, u16 count); + void setupFlagIndex(FlagDefinition *def, u16 count); void doCommit_Priv(); void setOrClearFlag(u16 flag, u16 value); u16 getFlag(u16 flag) const; - void FUN_800bf610(u16 flag); - u16 FUN_800bf640(u16 flag); - void FUN_800bf690(); + void onFlagChange(u16 flag); + u16 getMaskForFlag(u16 flag); + void postCommit(); u16 getUncommittedValue_Priv(u16 flag); protected: - /** 0x04 */ u16 flagSizeMaybe; - /** 0x06 */ u16 anotherSizeMaybe; - /** 0x08 */ FlagSpace *storyFlagsPtr; - /** 0x0C */ UnkFlagStuff *unkFlagsPtr; - /** 0x10 */ bool dirty; + + void setFlagSizes(u16 flagCount, u16 flagSizeBytes); + + /** 0x04 */ u16 mFlagCount; + /** 0x06 */ u16 mFlagSizeBytes; + /** 0x08 */ FlagSpace *mpFlagSpace; + /** 0x0C */ FlagIndex *mpFlagIndex; + /** 0x10 */ bool mDirty; }; #endif diff --git a/include/d/flag/dungeonflag_manager.h b/include/d/flag/dungeonflag_manager.h new file mode 100644 index 00000000..ec944532 --- /dev/null +++ b/include/d/flag/dungeonflag_manager.h @@ -0,0 +1,36 @@ +#ifndef D_FLAG_DUNGEONFLAG_MANAGER_H +#define D_FLAG_DUNGEONFLAG_MANAGER_H + +#include "d/flag/flag_index.h" +#include "d/flag/flag_space.h" +#include "toBeSorted/file_manager.h" + +class DungeonflagManager { +public: + bool mShouldCommit; + u16 mStageIndex; + FlagIndex *mpFlagIndex; + FlagSpace mFlagSpace; + + static u16 sDungeonFlags[8]; + + void copyFromSave(u32 flag); + void copyFromSave_Internal(u16 flagIndex); + void setCommitFlag(u16 flag); + DungeonflagManager(); + void init(); + void setToValue(u16 flag, u32 value); + void setFlag(u16 flag); + u16 getDungeonFlag(u16 flag); + bool doCommit(); + + /** inline shenanigans to get copyFromSave to match */ + static inline u16 *saveFilePtr(u16 flagIndex) { + u32 offset = (flagIndex & 0x1fff) * 8; + return FileManager::sInstance->getDungeonFlagsConst() + offset; + } + + static DungeonflagManager *sInstance; +}; + +#endif diff --git a/include/d/flag/flag_index.h b/include/d/flag/flag_index.h new file mode 100644 index 00000000..f4f98d34 --- /dev/null +++ b/include/d/flag/flag_index.h @@ -0,0 +1,37 @@ +#ifndef D_FLAG_FLAG_INDEX_H +#define D_FLAG_FLAG_INDEX_H + +#include "common.h" + +/** + * @brief Defines a single story or item flag. + */ +struct FlagDefinition { + u8 mIndex; + u8 mShiftMask; +}; + +/** + * @brief Helper class for packing and unpacking flag data. + * + * Some flag managers store their data in a packed format, where + * flags have a variable number of bits and can appear in varied + * locations within a halfword. + */ +class FlagIndex { + u16 mDefinitionsCount; + FlagDefinition *mpDefinitions; + +public: + u16 calculateMask(s32 shift); + void doNothing(u32 unused); + FlagIndex(u16 count, FlagDefinition *definitions); + void prepareIndexShiftMask(u16 counterIdx, u32 flagCount, u16 *pIndex, u8 *pShift, u16 *pMask); + u16 maskForIdx(u16 index, u16 flagCount); + u16 getCounterOrFlag(u16 counterIdx, const u16 *pData, u32 flagCount); + void setCounterOrFlag(u16 counterIdx, u16 *pData, u32 flagCount, u32 value); + + u32 checkFlagValid(u16 counterIdx, u32 flagCount); +}; + +#endif diff --git a/include/d/flag/itemflag_manager.h b/include/d/flag/itemflag_manager.h index fa55067c..d2507575 100644 --- a/include/d/flag/itemflag_manager.h +++ b/include/d/flag/itemflag_manager.h @@ -8,7 +8,7 @@ class ItemflagManager : public ItemStoryManagerBase { public: - FlagSpace itemFlags; + FlagSpace mItemFlags; ItemflagManager(); virtual ~ItemflagManager() {} @@ -16,14 +16,14 @@ public: bool commit(); /** 0x0C */ virtual void setFlagszptr() override { - storyFlagsPtr = &itemFlags; + mpFlagSpace = &mItemFlags; } /** 0x10 */ virtual void onDirty() override; /** 0x14 */ virtual void copyFlagsFromSave(); /** 0x18 */ virtual void setupUnkFlagsStuff(); /** 0x1C */ virtual void doCommit() { - u16 sz = flagSizeMaybe; - u16 *flags = storyFlagsPtr->getFlagPtrUnchecked(); + u16 sz = mFlagCount; + u16 *flags = mpFlagSpace->getFlagPtrUnchecked(); FileManager::sInstance->setItemFlags(flags, 0, sz); } /** 0x20 */ virtual void setFlag(u16 flag) { diff --git a/include/d/flag/storyflag_manager.h b/include/d/flag/storyflag_manager.h index d718823d..bdcaf0aa 100644 --- a/include/d/flag/storyflag_manager.h +++ b/include/d/flag/storyflag_manager.h @@ -10,19 +10,19 @@ public: virtual ~StoryflagManager() {} - FlagSpace storyFlags; + FlagSpace mStoryFlags; bool commit(); /** 0x0C */ virtual void setFlagszptr() override { - storyFlagsPtr = &storyFlags; + mpFlagSpace = &mStoryFlags; } /** 0x10 */ virtual void onDirty() override; /** 0x14 */ virtual void copyFlagsFromSave() override; /** 0x18 */ virtual void setupUnkFlagsStuff() override; /** 0x1C */ virtual void doCommit() override { - u16 sz = flagSizeMaybe; - u16 *flags = storyFlagsPtr->getFlagPtrUnchecked(); + u16 sz = mFlagCount; + u16 *flags = mpFlagSpace->getFlagPtrUnchecked(); FileManager::sInstance->setStoryFlags(flags, 0, sz); } /** 0x24 */ virtual void unsetFlag(u16 flag) override; diff --git a/include/d/flag/unk_flag_stuff.h b/include/d/flag/unk_flag_stuff.h deleted file mode 100644 index 9f0513f3..00000000 --- a/include/d/flag/unk_flag_stuff.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef UNK_FLAG_STUFF_H -#define UNK_FLAG_STUFF_H - -#include "common.h" - -struct UnkFlagDefinition { - u8 mIndex; - u8 mShiftMask; -}; - -class UnkFlagStuff { - u16 mDefinitionsCount; - UnkFlagDefinition *mpDefinitions; - -public: - u16 calculateMask(s32 shift); - void doNothing(u32 unused); - UnkFlagStuff(u16 count, UnkFlagDefinition *definitions); - void prepareIndexShiftMask(u16 counterIdx, u32 flagCount, u16 *pIndex, u8 *pShift, u16 *pMask); - u16 maskForIdx(u16 index, u16 flagSizeMaybe); - u16 getCounterOrFlag(u16 counterIdx, const u16 *pData, u32 flagCount); - void setCounterOrFlag(u16 counterIdx, u16 *pData, u32 flagCount, u32 value); - u32 checkFlagValid(u16 counterIdx, u32 flagCount); -}; - -#endif diff --git a/src/d/flag/baseflag_manager.inc b/src/d/flag/baseflag_manager.inc index 86b3e14e..9dd6c15c 100644 --- a/src/d/flag/baseflag_manager.inc +++ b/src/d/flag/baseflag_manager.inc @@ -1,37 +1,36 @@ #include "d/flag/baseflag_manager.h" -ItemStoryManagerBase::ItemStoryManagerBase(): flagSizeMaybe(0), anotherSizeMaybe(0), storyFlagsPtr(nullptr), unkFlagsPtr(nullptr), dirty(false) {} +ItemStoryManagerBase::ItemStoryManagerBase(): mFlagCount(0), mFlagSizeBytes(0), mpFlagSpace(nullptr), mpFlagIndex(nullptr), mDirty(false) {} ItemStoryManagerBase::~ItemStoryManagerBase() { - if (unkFlagsPtr != nullptr) { - delete unkFlagsPtr; + if (mpFlagIndex != nullptr) { + delete mpFlagIndex; } } -void ItemStoryManagerBase::setFlagSizes(u16 flagSizeMaybe, u16 anotherFlagSizeMaybe) { - this->flagSizeMaybe = flagSizeMaybe; - this->anotherSizeMaybe = anotherFlagSizeMaybe; +void ItemStoryManagerBase::setFlagSizes(u16 flagCount, u16 flagSizeBytes) { + mFlagCount = flagCount; + mFlagSizeBytes = flagSizeBytes; } /** 800bf320 */ -void ItemStoryManagerBase::setupUnkFlagStuff(UnkFlagDefinition *def, u16 count) { - UnkFlagStuff *stuff = new UnkFlagStuff(count, def); - this->unkFlagsPtr = stuff; +void ItemStoryManagerBase::setupFlagIndex(FlagDefinition *def, u16 count) { + mpFlagIndex = new FlagIndex(count, def); } /** 800bf380 */ void ItemStoryManagerBase::copyFlagsFromSave_Priv() { - FlagSpace *current = this->storyFlagsPtr; - const u16 *saved = this->getSaveFlagSpace(); - current->copyFromSaveFile(saved, 0, this->flagSizeMaybe); + FlagSpace *current = mpFlagSpace; + const u16 *saved = getSaveFlagSpace(); + current->copyFromSaveFile(saved, 0, mFlagCount); } /** 800bf3e0 */ void ItemStoryManagerBase::init() { - const u16 *space = this->getSaveFlagSpace(); - if (space == nullptr || this->unkFlagsPtr == nullptr) { - this->setFlagszptr(); - this->copyFlagsFromSave(); - this->setupUnkFlagsStuff(); + const u16 *space = getSaveFlagSpace(); + if (space == nullptr || mpFlagIndex == nullptr) { + setFlagszptr(); + copyFlagsFromSave(); + setupUnkFlagsStuff(); } } @@ -42,37 +41,37 @@ void ItemStoryManagerBase::setFlagszptr() { /** 800bf480 */ u16 ItemStoryManagerBase::getFlag(u16 flag) const { - const u16 *data = this->getSaveFlagSpace(); - return this->unkFlagsPtr->getCounterOrFlag(flag, data, this->flagSizeMaybe); + const u16 *data = getSaveFlagSpace(); + return mpFlagIndex->getCounterOrFlag(flag, data, mFlagCount); } /** 800bf4e0 */ u16 ItemStoryManagerBase::getUncommittedValue_Priv(u16 flag) { - u16 *data = this->storyFlagsPtr->getFlagPtrUnchecked(); - return this->unkFlagsPtr->getCounterOrFlag(flag, data, this->flagSizeMaybe); + u16 *data = mpFlagSpace->getFlagPtrUnchecked(); + return mpFlagIndex->getCounterOrFlag(flag, data, mFlagCount); } /** 800bf530 */ void ItemStoryManagerBase::setOrClearFlag(u16 flag, u16 value) { - FlagSpace *storyFlagsPtr = this->storyFlagsPtr; + FlagSpace *storyFlagsPtr = mpFlagSpace; u16 *pData = storyFlagsPtr->getFlagPtrChecked(); - this->unkFlagsPtr->setCounterOrFlag(flag, pData, storyFlagsPtr->mCount, value); - this->FUN_800bf610(flag); + mpFlagIndex->setCounterOrFlag(flag, pData, storyFlagsPtr->mCount, value); + onFlagChange(flag); } /** 800bf5b0 */ void ItemStoryManagerBase::setFlag(u16 flag) { - this->setOrClearFlag(flag, true); + setOrClearFlag(flag, true); } /** 800bf5c0 */ void ItemStoryManagerBase::unsetFlag(u16 flag) { - this->setOrClearFlag(flag, false); + setOrClearFlag(flag, false); } /** 800bf5d0 */ void ItemStoryManagerBase::setFlagOrCounterToValue(u16 flag, u16 value) { - this->setOrClearFlag(flag, value); + setOrClearFlag(flag, value); } /** 800bf5e0 */ @@ -82,18 +81,18 @@ u16 ItemStoryManagerBase::getCounterOrFlag(u16 flag) const { /** 800bf5f0 */ u16 ItemStoryManagerBase::getUncommittedValue(u16 flag) { - return this->getUncommittedValue_Priv(flag); + return getUncommittedValue_Priv(flag); } /** 800bf600 */ u16 ItemStoryManagerBase::unk3(u16 flag) { - return this->FUN_800bf640(flag); + return getMaskForFlag(flag); } /** 800bf610 */ -void ItemStoryManagerBase::FUN_800bf610(u16 flag) { - this->dirty = true; - this->onDirty(); +void ItemStoryManagerBase::onFlagChange(u16 flag) { + mDirty = true; + onDirty(); } /** 800bf630 */ @@ -102,17 +101,17 @@ void ItemStoryManagerBase::onDirty() { } /** 800bf640 */ -u16 ItemStoryManagerBase::FUN_800bf640(u16 flag) { - return this->unkFlagsPtr->maskForIdx(flag, this->flagSizeMaybe); +u16 ItemStoryManagerBase::getMaskForFlag(u16 flag) { + return mpFlagIndex->maskForIdx(flag, mFlagCount); } /** 800bf650 */ void ItemStoryManagerBase::doCommit_Priv() { - this->doCommit(); - this->dirty = false; + doCommit(); + mDirty = false; } /* 800bf690 */ -void ItemStoryManagerBase::FUN_800bf690() { +void ItemStoryManagerBase::postCommit() { } diff --git a/src/d/flag/dungeonflag_manager.inc b/src/d/flag/dungeonflag_manager.inc index 7b9e0f50..4af48f90 100644 --- a/src/d/flag/dungeonflag_manager.inc +++ b/src/d/flag/dungeonflag_manager.inc @@ -1,39 +1,9 @@ -#include "toBeSorted/file_manager.h" -#include "d/flag/flag_space.h" -#include "d/flag/unk_flag_stuff.h" +#include "d/flag/dungeonflag_manager.h" +#include "d/flag/flag_index.h" // TODO move -extern "C" UnkFlagDefinition DungeonflagManager__FLAG_DEFINITIONS[]; - -class DungeonflagManager { -public: - bool mShouldCommit; - u16 mStageIndex; - UnkFlagStuff *mFlagStuff; - FlagSpace mFlagSpace; - - static u16 sDungeonFlags[8]; - // static DungeonflagManager *sInstance; - - void copyFromSave(u32 flag); - void copyFromSave_Internal(u16 flagIndex); - void setCommitFlag(u16 flag); - DungeonflagManager(); - void init(); - void setToValue(u16 flag, u32 value); - void setFlag(u16 flag); - u16 getDungeonFlag(u16 flag); - bool doCommit(); - - /** inline shenanigans to get copyFromSave to match */ - static inline u16 *saveFilePtr(u16 flagIndex) { - u32 offset = (flagIndex & 0x1fff) * 8; - return FileManager::sInstance->getDungeonFlagsConst() + offset; - } - - static DungeonflagManager *sInstance; -}; +extern "C" FlagDefinition DungeonflagManager__FLAG_DEFINITIONS[]; /** 80575404 */ DungeonflagManager *DungeonflagManager::sInstance = nullptr; @@ -53,12 +23,12 @@ void DungeonflagManager::setCommitFlag(u16 flag) { /** 0x800bf940 */ DungeonflagManager::DungeonflagManager() - : mShouldCommit(false), mStageIndex(-1), mFlagStuff(nullptr), + : mShouldCommit(false), mStageIndex(-1), mpFlagIndex(nullptr), mFlagSpace(sDungeonFlags, ARRAY_LENGTH(sDungeonFlags)) {} /** 800bf980 */ void DungeonflagManager::init() { - mFlagStuff = new UnkFlagStuff(0x11, DungeonflagManager__FLAG_DEFINITIONS); + mpFlagIndex = new FlagIndex(0x11, DungeonflagManager__FLAG_DEFINITIONS); mShouldCommit = false; } @@ -71,21 +41,21 @@ void DungeonflagManager::copyFromSave(u32 flag) { /** 800bf9f0 */ void DungeonflagManager::setToValue(u16 flag, u32 value) { u16 *data = mFlagSpace.getFlagPtrChecked(); - mFlagStuff->setCounterOrFlag(flag, data, 8, value); + mpFlagIndex->setCounterOrFlag(flag, data, 8, value); setCommitFlag(flag); } /** 800bfa60 */ void DungeonflagManager::setFlag(u16 flag) { u16 *data = mFlagSpace.getFlagPtrChecked(); - mFlagStuff->setCounterOrFlag(flag, data, 8, 1); + mpFlagIndex->setCounterOrFlag(flag, data, 8, 1); setCommitFlag(flag); } /** 800fbac0 */ u16 DungeonflagManager::getDungeonFlag(u16 flag) { u16 *data = mFlagSpace.getFlagPtrUnchecked(); - return mFlagStuff->getCounterOrFlag(flag, data, 8); + return mpFlagIndex->getCounterOrFlag(flag, data, 8); } /** 800fbb10 */ diff --git a/src/d/flag/unk_flag_stuff.inc b/src/d/flag/flag_index.inc similarity index 66% rename from src/d/flag/unk_flag_stuff.inc rename to src/d/flag/flag_index.inc index 79289abe..b7dc5380 100644 --- a/src/d/flag/unk_flag_stuff.inc +++ b/src/d/flag/flag_index.inc @@ -1,30 +1,30 @@ -#include "d/flag/unk_flag_stuff.h" +#include "d/flag/flag_index.h" -u16 UnkFlagStuff::calculateMask(s32 shift) { +u16 FlagIndex::calculateMask(s32 shift) { return (2 << (shift & 0xF)) - 1; } -void UnkFlagStuff::doNothing(u32 unused) {} +void FlagIndex::doNothing(u32 unused) {} -UnkFlagStuff::UnkFlagStuff(u16 count, UnkFlagDefinition *definitions) { +FlagIndex::FlagIndex(u16 count, FlagDefinition *definitions) { this->mDefinitionsCount = count; this->mpDefinitions = definitions; } -void UnkFlagStuff::prepareIndexShiftMask(u16 counterIdx, u32 unused, u16 *indexPtr, u8 *shiftPtr, u16 *maskPtr) { +void FlagIndex::prepareIndexShiftMask(u16 counterIdx, u32 unused, u16 *indexPtr, u8 *shiftPtr, u16 *maskPtr) { doNothing(counterIdx); *indexPtr = mpDefinitions[counterIdx].mIndex; *shiftPtr = mpDefinitions[counterIdx].mShiftMask >> 4; *maskPtr = calculateMask(mpDefinitions[counterIdx].mShiftMask); } -u16 UnkFlagStuff::maskForIdx(u16 index, u16 flagSizeMaybe) { +u16 FlagIndex::maskForIdx(u16 index, u16 flagCount) { doNothing(index); return calculateMask(mpDefinitions[index].mShiftMask); } -u16 UnkFlagStuff::getCounterOrFlag(u16 counterIdx, const u16 *dataPtr, u32 param4) { +u16 FlagIndex::getCounterOrFlag(u16 counterIdx, const u16 *dataPtr, u32 param4) { u16 index = 0; u8 shift = 0; u16 mask = 0; @@ -32,7 +32,7 @@ u16 UnkFlagStuff::getCounterOrFlag(u16 counterIdx, const u16 *dataPtr, u32 param return mask & (dataPtr[index] >> shift); } -void UnkFlagStuff::setCounterOrFlag(u16 counterIdx, u16 *dataPtr, u32 flagCount, u32 value) { +void FlagIndex::setCounterOrFlag(u16 counterIdx, u16 *dataPtr, u32 flagCount, u32 value) { u16 index = 0; u8 shift = 0; u16 mask = 0; @@ -45,7 +45,7 @@ inline bool isLessThan(int a, int b) { return a <= b; } -u32 UnkFlagStuff::checkFlagValid(u16 counterIdx, u32 flagCount) { +u32 FlagIndex::checkFlagValid(u16 counterIdx, u32 flagCount) { if (mpDefinitions == nullptr) { return 0; } diff --git a/src/d/flag/flag_managers.cpp b/src/d/flag/flag_managers.cpp index 5a39ad65..acd6b3b9 100644 --- a/src/d/flag/flag_managers.cpp +++ b/src/d/flag/flag_managers.cpp @@ -11,21 +11,21 @@ #include "d/flag/enemyflag_manager.h" #include "d/flag/storyflag_manager.h" #include "d/flag/itemflag_manager.h" -// clang-format on +// actual managers #include "d/flag/sceneflag_manager.inc" #include "d/flag/committable_flag_manager.inc" #include "d/flag/tboxflag_manager.inc" #include "d/flag/enemyflag_manager.inc" #include "d/flag/flag_space.inc" -#include "d/flag/unk_flag_stuff.inc" +#include "d/flag/flag_index.inc" #include "d/flag/bitwise_flag_helper.inc" - #include "d/flag/baseflag_manager.inc" #include "d/flag/storyflag_manager.inc" #include "d/flag/itemflag_manager.inc" #include "d/flag/dungeonflag_manager.inc" #include "d/flag/skipflag_manager.inc" +// clang-format on static void postSetup(); diff --git a/src/d/flag/flag_space.inc b/src/d/flag/flag_space.inc index 298aac80..18e7c0ab 100644 --- a/src/d/flag/flag_space.inc +++ b/src/d/flag/flag_space.inc @@ -1,7 +1,7 @@ +#include "common.h" #include "d/flag/flag_managers.h" #include "d/flag/flag_space.h" #include "toBeSorted/file_manager.h" -#include "common.h" u16 *FlagSpace::getFlagPtrChecked() const { filemanagerCheck(); diff --git a/src/d/flag/itemflag_manager.inc b/src/d/flag/itemflag_manager.inc index 027a16a8..190d2fb1 100644 --- a/src/d/flag/itemflag_manager.inc +++ b/src/d/flag/itemflag_manager.inc @@ -4,25 +4,25 @@ u16 ItemflagManager::sFlags[0x40]; ItemflagManager *ItemflagManager::sInstance = nullptr; -ItemflagManager::ItemflagManager() : itemFlags(sFlags, 0x40) {} +ItemflagManager::ItemflagManager() : mItemFlags(sFlags, 0x40) {} void ItemflagManager::copyFlagsFromSave() { setFlagSizes(0x40, 0x80); - copyFlagsFromSave_Priv(); + ItemStoryManagerBase::copyFlagsFromSave_Priv(); } -extern "C" UnkFlagDefinition ItemflagManager__ITEMFLAG_DEFINITIONS[]; +extern "C" FlagDefinition ItemflagManager__ITEMFLAG_DEFINITIONS[]; void ItemflagManager::setupUnkFlagsStuff() { - setupUnkFlagStuff(ItemflagManager__ITEMFLAG_DEFINITIONS, 0x1FE); + setupFlagIndex(ItemflagManager__ITEMFLAG_DEFINITIONS, 0x1FE); } void ItemflagManager::onDirty() {} bool ItemflagManager::commit() { - if (dirty) { + if (mDirty) { doCommit_Priv(); - FUN_800bf690(); + postCommit(); return true; } return false; diff --git a/src/d/flag/sceneflag_manager.inc b/src/d/flag/sceneflag_manager.inc index c0536acf..16d51c7c 100644 --- a/src/d/flag/sceneflag_manager.inc +++ b/src/d/flag/sceneflag_manager.inc @@ -1,10 +1,7 @@ -#include "d/flag/sceneflag_manager.h" - #include "common.h" -#include "libc.h" +#include "d/flag/sceneflag_manager.h" #include "toBeSorted/file_manager.h" - SceneflagManager *SceneflagManager::sInstance = nullptr; u16 SceneflagManager::sTempFlags[] = {}; u16 SceneflagManager::sSceneFlags[8] = {}; @@ -20,14 +17,7 @@ SceneflagManager::SceneflagManager() mSceneIdx = 0xFFFF; mShouldCommit = 0; } -// SceneflagManager::SceneflagManager() -// { -// mSceneflags.init(sSceneFlags, ARRAY_LENGTH(sSceneFlags)); -// mTempflags.init(sTempFlags, ARRAY_LENGTH(sTempFlags)); -// mZoneflags.init(sZoneFlags, ARRAY_LENGTH(sZoneFlags)); -// mSceneIdx = 0xFFFF; -// mShouldCommit = 0; -// } + s32 SceneflagManager::isNotTempOrZoneFlag(u16 flag) { // return ((s32)flag - 0x80) < 0; return flag < 0x80; diff --git a/src/d/flag/skipflag_manager.inc b/src/d/flag/skipflag_manager.inc index b365aee3..c3bd8433 100644 --- a/src/d/flag/skipflag_manager.inc +++ b/src/d/flag/skipflag_manager.inc @@ -1,9 +1,9 @@ #include "common.h" -#include "d/flag/flag_managers.h" -#include "d/flag/skipflag_manager.h" #include "d/flag/bitwise_flag_helper.h" -#include "toBeSorted/file_manager.h" +#include "d/flag/flag_managers.h" #include "d/flag/flag_space.h" +#include "d/flag/skipflag_manager.h" +#include "toBeSorted/file_manager.h" // 0x80575408 SkipflagManager *SkipflagManager::sInstance = nullptr; diff --git a/src/d/flag/storyflag_manager.inc b/src/d/flag/storyflag_manager.inc index 3b45d4cc..74408dff 100644 --- a/src/d/flag/storyflag_manager.inc +++ b/src/d/flag/storyflag_manager.inc @@ -3,29 +3,25 @@ u16 StoryflagManager::sFlags[0x80]; StoryflagManager *StoryflagManager::sInstance = nullptr; -StoryflagManager::StoryflagManager() : storyFlags(sFlags, 0x80) { - -} +StoryflagManager::StoryflagManager() : mStoryFlags(sFlags, 0x80) {} void StoryflagManager::copyFlagsFromSave() { setFlagSizes(0x80, 0x100); - copyFlagsFromSave_Priv(); + ItemStoryManagerBase::copyFlagsFromSave_Priv(); } -extern "C" UnkFlagDefinition StoryflagManager__STORYFLAG_DEFINITIONS[]; +extern "C" FlagDefinition StoryflagManager__STORYFLAG_DEFINITIONS[]; void StoryflagManager::setupUnkFlagsStuff() { - setupUnkFlagStuff(StoryflagManager__STORYFLAG_DEFINITIONS, 0x4B1); + setupFlagIndex(StoryflagManager__STORYFLAG_DEFINITIONS, 0x4B1); } -void StoryflagManager::onDirty() { - -} +void StoryflagManager::onDirty() {} bool StoryflagManager::commit() { - if (dirty) { + if (mDirty) { doCommit_Priv(); - FUN_800bf690(); + postCommit(); return true; } return false;