diff options
| author | Léo Lam <leo@leolam.fr> | 2021-02-04 18:56:20 +0100 |
|---|---|---|
| committer | Léo Lam <leo@leolam.fr> | 2021-02-07 15:45:09 +0100 |
| commit | 9c6bec732fa433121c7cbda227ed536af0a9cb91 (patch) | |
| tree | c4f0cca1357c28b289e253a837de247a5a8a3c7e /src | |
| parent | 85430d323270b83aff1e91837cd716733adce002 (diff) | |
ksys/evt: Match OrderParam "get T by name" getters
Diffstat (limited to 'src')
| -rw-r--r-- | src/KingSystem/Event/evtOrderParam.cpp | 22 | ||||
| -rw-r--r-- | src/KingSystem/Event/evtOrderParam.h | 44 |
2 files changed, 29 insertions, 37 deletions
diff --git a/src/KingSystem/Event/evtOrderParam.cpp b/src/KingSystem/Event/evtOrderParam.cpp index cbf71639..918fca06 100644 --- a/src/KingSystem/Event/evtOrderParam.cpp +++ b/src/KingSystem/Event/evtOrderParam.cpp @@ -91,18 +91,17 @@ void OrderParam::addParamActor(ksys::act::BaseProc& actor, sead::SafeString& nam } } } -// The three below have 1 pair of instructions swapped bool OrderParam::getIntByName(const sead::SafeString& name, u32** out_ptr) { - return tryGetPointerByName(name, (void**)out_ptr, nullptr, OrderParamType::INT); + return getPointerByName(name, out_ptr, nullptr, OrderParamType::INT); } bool OrderParam::getStringByName(const sead::SafeString& name, sead::SafeString** out_ptr) { - return tryGetPointerByName(name, (void**)out_ptr, nullptr, OrderParamType::STRING); + return getPointerByName(name, out_ptr, nullptr, OrderParamType::STRING); } bool OrderParam::getArrayByName(const sead::SafeString& name, void** out_ptr, u32* out_size) { - return tryGetPointerByName(name, out_ptr, out_size, OrderParamType::ARRAY); + return getPointerByName(name, out_ptr, out_size, OrderParamType::ARRAY); } // This one also does not match @@ -170,4 +169,17 @@ OrderParamEntry* OrderParam::tryAlloc(OrderParamType type, u32 size, sead::SafeS return nullptr; } -} // namespace ksys::evt
\ No newline at end of file +void* OrderParam::getPointerByName(const sead::SafeString& name, u32* out_size, + OrderParamType type) const { + const u32 hash = sead::HashCRC32::calcStringHash(name); + for (s32 i = 0; i < mEntries.size(); i++) { + if (mEntries[i].mHash == hash && mEntries[i].mType == type) { + if (out_size) + *out_size = mEntries[i].mSize; + return mEntries[i].mPointer; + } + } + return nullptr; +} + +} // namespace ksys::evt diff --git a/src/KingSystem/Event/evtOrderParam.h b/src/KingSystem/Event/evtOrderParam.h index 0fc07e74..11352a33 100644 --- a/src/KingSystem/Event/evtOrderParam.h +++ b/src/KingSystem/Event/evtOrderParam.h @@ -45,38 +45,18 @@ public: bool getArrayByName(const sead::SafeString& name, void** out_ptr, u32* out_size); private: - inline void* getPointerByName(const sead::SafeString& name, OrderParamType type) { - u32 hash = sead::HashCRC32::calcStringHash(name.cstr()); - s32 i; - for (i = 0; i < mEntries.size(); i++) { - if (mEntries[i].mHash == hash && mEntries[i].mType == type) { - return mEntries[i].mPointer; - } - } - return nullptr; - } - inline bool tryGetPointerByName(const sead::SafeString& name, void** out_ptr, u32* out_size, - OrderParamType type) { - u32 hash = sead::HashCRC32::calcStringHash(name.cstr()); - s32 i; - for (i = 0; i < mEntries.size(); i++) { - if (mEntries[i].mHash == hash && mEntries[i].mType == type) { - if (out_size) { - *out_size = mEntries[i].mSize; - } - return tryGetPointer(i, out_ptr); - } - } - return false; - } - inline bool tryGetPointer(s32 i, void** out_ptr) { - auto* ptr = mEntries[i].mPointer; - if (ptr) { - *out_ptr = ptr; // minor diff with scheduling - return true; - } - return false; + void* getPointerByName(const sead::SafeString& name, u32* out_size, OrderParamType type) const; + + template <typename T> + bool getPointerByName(const sead::SafeString& name, T** out_ptr, u32* out_size, + OrderParamType type) const { + auto* ptr = getPointerByName(name, out_size, type); + if (!ptr) + return false; + *out_ptr = static_cast<T*>(ptr); + return true; } + inline void clearEntry(OrderParamEntry* e) { e->mHash = 0; e->mSize = 0; @@ -89,4 +69,4 @@ private: u32 mEntryCount = 0; bool mInitialized = false; }; -} // namespace ksys::evt
\ No newline at end of file +} // namespace ksys::evt |
