From 6c686fb962d414c6f581044ce4477c0df94cdedc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Sat, 31 Oct 2020 15:23:18 +0100 Subject: [PATCH] ksys/gdt: Implement more TriggerParam copy functions --- data/uking_functions.csv | 58 +-- src/KingSystem/GameData/gdtTriggerParam.cpp | 423 +++++++++++++++++++- src/KingSystem/GameData/gdtTriggerParam.h | 20 +- 3 files changed, 450 insertions(+), 51 deletions(-) diff --git a/data/uking_functions.csv b/data/uking_functions.csv index c7be9c39..4df714d7 100644 --- a/data/uking_functions.csv +++ b/data/uking_functions.csv @@ -74471,29 +74471,29 @@ 0x0000007100de7fa8,TriggerParam::resetVec3fArray,284,_ZN4ksys3gdt12TriggerParam10resetVec3fEiib 0x0000007100de80c4,TriggerParam::resetVec4fArray,284,_ZN4ksys3gdt12TriggerParam10resetVec4fEiib 0x0000007100de81e0,_ZN4ksys3gdt12TriggerParam8resetS32ERKN4sead14SafeStringBaseIcEEib,0xEC,_ZN4ksys3gdt12TriggerParam8resetS32ERKN4sead14SafeStringBaseIcEEib -0x0000007100de82cc,TriggerParam::getArray158Flag,364, -0x0000007100de8438,TriggerParam::getHorseIntByKeyMaybe,360, -0x0000007100de85a0,sub_7100DE85A0,360, +0x0000007100de82cc,TriggerParam::getArray158Flag,364,_ZNK4ksys3gdt12TriggerParam15getBoolIfCopiedEPbRKN4sead14SafeStringBaseIcEEbb +0x0000007100de8438,TriggerParam::getHorseIntByKeyMaybe,360,_ZNK4ksys3gdt12TriggerParam14getS32IfCopiedEPiRKN4sead14SafeStringBaseIcEEbb +0x0000007100de85a0,sub_7100DE85A0,360,_ZNK4ksys3gdt12TriggerParam14getF32IfCopiedEPfRKN4sead14SafeStringBaseIcEEbb 0x0000007100de8708,sub_7100DE8708,268,_ZN4ksys3gdt12_GLOBAL__N_117addFlagCopyRecordIbEEvRN4sead8ObjArrayINS0_12TriggerParam14FlagCopyRecordEEEPNS0_4FlagIT_EEib 0x0000007100de8814,TriggerParam::copyAndInit,8556, -0x0000007100dea980,sub_7100DEA980,1124, -0x0000007100deade4,sub_7100DEADE4,1052, -0x0000007100deb200,sub_7100DEB200,1040, -0x0000007100deb610,sub_7100DEB610,1136, -0x0000007100deba80,sub_7100DEBA80,1136, -0x0000007100debef0,sub_7100DEBEF0,1136, -0x0000007100dec360,sub_7100DEC360,1040, -0x0000007100dec770,sub_7100DEC770,1040, -0x0000007100decb80,sub_7100DECB80,1040, -0x0000007100decf90,sub_7100DECF90,796, -0x0000007100ded2ac,sub_7100DED2AC,796, -0x0000007100ded5c8,sub_7100DED5C8,796, -0x0000007100ded8e4,sub_7100DED8E4,796, -0x0000007100dedc00,sub_7100DEDC00,796, -0x0000007100dedf1c,sub_7100DEDF1C,796, -0x0000007100dee238,sub_7100DEE238,796, -0x0000007100dee554,sub_7100DEE554,796, -0x0000007100dee870,sub_7100DEE870,796, +0x0000007100dea980,sub_7100DEA980,1124,_ZN4ksys3gdt9copyFlagsIbEEvRN4sead8PtrArrayINS0_8FlagBaseEEERKS5_RNS2_8ObjArrayINS0_12TriggerParam14FlagCopyRecordEEERNS2_9SafeArrayIiLi15EEEbbbb +0x0000007100deade4,sub_7100DEADE4,1052,_ZN4ksys3gdt9copyFlagsIiEEvRN4sead8PtrArrayINS0_8FlagBaseEEERKS5_RNS2_8ObjArrayINS0_12TriggerParam14FlagCopyRecordEEERNS2_9SafeArrayIiLi15EEEbbbb +0x0000007100deb200,sub_7100DEB200,1040,_ZN4ksys3gdt9copyFlagsIfEEvRN4sead8PtrArrayINS0_8FlagBaseEEERKS5_RNS2_8ObjArrayINS0_12TriggerParam14FlagCopyRecordEEERNS2_9SafeArrayIiLi15EEEbbbb +0x0000007100deb610,sub_7100DEB610,1136,_ZN4ksys3gdt9copyFlagsIN4sead15FixedSafeStringILi32EEEEEvRNS2_8PtrArrayINS0_8FlagBaseEEERKS7_RNS2_8ObjArrayINS0_12TriggerParam14FlagCopyRecordEEERNS2_9SafeArrayIiLi15EEEbbbb +0x0000007100deba80,sub_7100DEBA80,1136,_ZN4ksys3gdt9copyFlagsIN4sead15FixedSafeStringILi64EEEEEvRNS2_8PtrArrayINS0_8FlagBaseEEERKS7_RNS2_8ObjArrayINS0_12TriggerParam14FlagCopyRecordEEERNS2_9SafeArrayIiLi15EEEbbbb +0x0000007100debef0,sub_7100DEBEF0,1136,_ZN4ksys3gdt9copyFlagsIN4sead15FixedSafeStringILi256EEEEEvRNS2_8PtrArrayINS0_8FlagBaseEEERKS7_RNS2_8ObjArrayINS0_12TriggerParam14FlagCopyRecordEEERNS2_9SafeArrayIiLi15EEEbbbb +0x0000007100dec360,sub_7100DEC360,1040,_ZN4ksys3gdt9copyFlagsIN4sead7Vector2IfEEEEvRNS2_8PtrArrayINS0_8FlagBaseEEERKS7_RNS2_8ObjArrayINS0_12TriggerParam14FlagCopyRecordEEERNS2_9SafeArrayIiLi15EEEbbbb +0x0000007100dec770,sub_7100DEC770,1040,_ZN4ksys3gdt9copyFlagsIN4sead7Vector3IfEEEEvRNS2_8PtrArrayINS0_8FlagBaseEEERKS7_RNS2_8ObjArrayINS0_12TriggerParam14FlagCopyRecordEEERNS2_9SafeArrayIiLi15EEEbbbb +0x0000007100decb80,sub_7100DECB80,1040,_ZN4ksys3gdt9copyFlagsIN4sead7Vector4IfEEEEvRNS2_8PtrArrayINS0_8FlagBaseEEERKS7_RNS2_8ObjArrayINS0_12TriggerParam14FlagCopyRecordEEERNS2_9SafeArrayIiLi15EEEbbbb +0x0000007100decf90,sub_7100DECF90,796,_ZN4ksys3gdt14copyFlagArraysIbEEvRN4sead8PtrArrayINS3_INS0_8FlagBaseEEEEERKS6_RNS2_8ObjArrayINS0_12TriggerParam14FlagCopyRecordEEERNS2_9SafeArrayIiLi15EEEbbb +0x0000007100ded2ac,sub_7100DED2AC,796,_ZN4ksys3gdt14copyFlagArraysIiEEvRN4sead8PtrArrayINS3_INS0_8FlagBaseEEEEERKS6_RNS2_8ObjArrayINS0_12TriggerParam14FlagCopyRecordEEERNS2_9SafeArrayIiLi15EEEbbb +0x0000007100ded5c8,sub_7100DED5C8,796,_ZN4ksys3gdt14copyFlagArraysIfEEvRN4sead8PtrArrayINS3_INS0_8FlagBaseEEEEERKS6_RNS2_8ObjArrayINS0_12TriggerParam14FlagCopyRecordEEERNS2_9SafeArrayIiLi15EEEbbb +0x0000007100ded8e4,sub_7100DED8E4,796,_ZN4ksys3gdt14copyFlagArraysIN4sead15FixedSafeStringILi32EEEEEvRNS2_8PtrArrayINS5_INS0_8FlagBaseEEEEERKS8_RNS2_8ObjArrayINS0_12TriggerParam14FlagCopyRecordEEERNS2_9SafeArrayIiLi15EEEbbb +0x0000007100dedc00,sub_7100DEDC00,796,_ZN4ksys3gdt14copyFlagArraysIN4sead15FixedSafeStringILi64EEEEEvRNS2_8PtrArrayINS5_INS0_8FlagBaseEEEEERKS8_RNS2_8ObjArrayINS0_12TriggerParam14FlagCopyRecordEEERNS2_9SafeArrayIiLi15EEEbbb +0x0000007100dedf1c,sub_7100DEDF1C,796,_ZN4ksys3gdt14copyFlagArraysIN4sead15FixedSafeStringILi256EEEEEvRNS2_8PtrArrayINS5_INS0_8FlagBaseEEEEERKS8_RNS2_8ObjArrayINS0_12TriggerParam14FlagCopyRecordEEERNS2_9SafeArrayIiLi15EEEbbb +0x0000007100dee238,sub_7100DEE238,796,_ZN4ksys3gdt14copyFlagArraysIN4sead7Vector2IfEEEEvRNS2_8PtrArrayINS5_INS0_8FlagBaseEEEEERKS8_RNS2_8ObjArrayINS0_12TriggerParam14FlagCopyRecordEEERNS2_9SafeArrayIiLi15EEEbbb +0x0000007100dee554,sub_7100DEE554,796,_ZN4ksys3gdt14copyFlagArraysIN4sead7Vector3IfEEEEvRNS2_8PtrArrayINS5_INS0_8FlagBaseEEEEERKS8_RNS2_8ObjArrayINS0_12TriggerParam14FlagCopyRecordEEERNS2_9SafeArrayIiLi15EEEbbb +0x0000007100dee870,sub_7100DEE870,796,_ZN4ksys3gdt14copyFlagArraysIN4sead7Vector4IfEEEEvRNS2_8PtrArrayINS5_INS0_8FlagBaseEEEEERKS8_RNS2_8ObjArrayINS0_12TriggerParam14FlagCopyRecordEEERNS2_9SafeArrayIiLi15EEEbbb 0x0000007100deeb8c,TriggerParam::resetToInitialValues,2628,_ZN4ksys3gdt12TriggerParam28resetAllFlagsToInitialValuesEv 0x0000007100def5d0,shouldSkipReviveShopItem,868, 0x0000007100def934,TriggerParam::reset,3652, @@ -74763,14 +74763,14 @@ 0x0000007100df5d38,sub_7100DF5D38,272,_ZN4ksys3gdt9FlagProxyIN4sead7Vector4IfEEE8setValueES4_ 0x0000007100df5e48,sub_7100DF5E48,16,_ZNK4ksys3gdt9FlagProxyIN4sead7Vector4IfEEE12getDebugDataEv 0x0000007100df5e58,gdm::debugReportFlagChange,792,_ZN4ksys3gdt12_GLOBAL__N_124sendFlagChangePlayReportERKN4sead14SafeStringBaseIcEEPKNS0_8FlagBaseE -0x0000007100df6170,sub_7100DF6170,268, -0x0000007100df627c,sub_7100DF627C,268, -0x0000007100df6388,sub_7100DF6388,268, -0x0000007100df6494,sub_7100DF6494,268, -0x0000007100df65a0,sub_7100DF65A0,268, -0x0000007100df66ac,sub_7100DF66AC,268, -0x0000007100df67b8,sub_7100DF67B8,268, -0x0000007100df68c4,sub_7100DF68C4,268, +0x0000007100df6170,sub_7100DF6170,268,_ZN4ksys3gdt12_GLOBAL__N_117addFlagCopyRecordIiEEvRN4sead8ObjArrayINS0_12TriggerParam14FlagCopyRecordEEEPNS0_4FlagIT_EEib +0x0000007100df627c,sub_7100DF627C,268,_ZN4ksys3gdt12_GLOBAL__N_117addFlagCopyRecordIfEEvRN4sead8ObjArrayINS0_12TriggerParam14FlagCopyRecordEEEPNS0_4FlagIT_EEib +0x0000007100df6388,sub_7100DF6388,268,_ZN4ksys3gdt12_GLOBAL__N_117addFlagCopyRecordIN4sead15FixedSafeStringILi32EEEEEvRNS3_8ObjArrayINS0_12TriggerParam14FlagCopyRecordEEEPNS0_4FlagIT_EEib +0x0000007100df6494,sub_7100DF6494,268,_ZN4ksys3gdt12_GLOBAL__N_117addFlagCopyRecordIN4sead15FixedSafeStringILi64EEEEEvRNS3_8ObjArrayINS0_12TriggerParam14FlagCopyRecordEEEPNS0_4FlagIT_EEib +0x0000007100df65a0,sub_7100DF65A0,268,_ZN4ksys3gdt12_GLOBAL__N_117addFlagCopyRecordIN4sead15FixedSafeStringILi256EEEEEvRNS3_8ObjArrayINS0_12TriggerParam14FlagCopyRecordEEEPNS0_4FlagIT_EEib +0x0000007100df66ac,sub_7100DF66AC,268,_ZN4ksys3gdt12_GLOBAL__N_117addFlagCopyRecordIN4sead7Vector2IfEEEEvRNS3_8ObjArrayINS0_12TriggerParam14FlagCopyRecordEEEPNS0_4FlagIT_EEib +0x0000007100df67b8,sub_7100DF67B8,268,_ZN4ksys3gdt12_GLOBAL__N_117addFlagCopyRecordIN4sead7Vector3IfEEEEvRNS3_8ObjArrayINS0_12TriggerParam14FlagCopyRecordEEEPNS0_4FlagIT_EEib +0x0000007100df68c4,sub_7100DF68C4,268,_ZN4ksys3gdt12_GLOBAL__N_117addFlagCopyRecordIN4sead7Vector4IfEEEEvRNS3_8ObjArrayINS0_12TriggerParam14FlagCopyRecordEEEPNS0_4FlagIT_EEib 0x0000007100df69d0,sub_7100DF69D0,268,_GLOBAL__sub_I_gdtTriggerParam.cpp 0x0000007100df6adc,ResourceBgdata::ctor,136,_ZN4ksys3res8GameDataC1Ev 0x0000007100df6b64,ResourceBgdata::dtor,20,_ZN4ksys3res8GameDataD1Ev diff --git a/src/KingSystem/GameData/gdtTriggerParam.cpp b/src/KingSystem/GameData/gdtTriggerParam.cpp index aceeed8d..94c1888e 100644 --- a/src/KingSystem/GameData/gdtTriggerParam.cpp +++ b/src/KingSystem/GameData/gdtTriggerParam.cpp @@ -18,6 +18,7 @@ TriggerParam::TriggerParam() { cs.constructDefault(); mBitFlags.constructDefault(); mFlagChangeRecordIndices.fill(0); + mNumBoolFlagsPerCategory0.fill(0); mNumBoolFlagsPerCategory.fill(0); } @@ -431,10 +432,9 @@ void makeFlagProxies(sead::PtrArray& dest, const sead::PtrArray -[[gnu::noinline]] void addFlagCopyRecord(sead::ObjArray& records, - Flag* flag, s32 sub_index, bool find_existing_record) { +void addFlagCopyRecord(sead::ObjArray& records, Flag* flag, + s32 sub_index, bool find_existing_record) { if (records.isFull()) return; @@ -458,10 +458,152 @@ template record->name_hash = flag->getHash(); record->sub_index = sub_index; } - record->bit_flag.makeAllZero(); + record->bf.makeAllZero(); } } // namespace +/** + * @param dest Destination flag array + * @param src Source flag array + * @param records Copy records (only used if add_records is true) + * @param counts Boolean flag counts per category (only used if T = bool) + * @param record_copies Whether copies should be recorded + * @param ignore_temp_flags Whether temporary flags (i.e. flags that aren't saved) + * should be ignored + * @param find_existing_record See addFlagCopyRecord. + * @param is_array Whether the flag arrays are associated with an array-type flag (e.g. bool array) + */ +template +void copyFlags(sead::PtrArray& dest, const sead::PtrArray& src, + sead::ObjArray& records, + sead::SafeArray& counts, bool record_copies, bool ignore_temp_flags, + bool find_existing_record, bool is_array) { + // This function only handles two cases: + // + // 1. If both the source and destination have the same number of flags, we assume that + // both arrays store the same flags in the exact same order. + // + // 2. If the source has fewer flags than the destination, it is assumed that src is a subset of + // dest (i.e. every flag that is in src is also in dest) and src forms a subsequence of dest. + // Any flag in dest that isn't in src will be reset to its initial value. + + const auto update_records = [&](Flag* flag, const Flag* flag_src, s32 i) { + flag->setValue(flag_src->getValue()); + + s32 category, category_idx; + if constexpr (std::is_same()) { + category = flag->getCategory(); + category_idx = category - 1; + } + + if (record_copies) { + addFlagCopyRecord(records, flag, is_array ? i : -1, find_existing_record); + if constexpr (std::is_same()) { + if (category > 0) { + if (flag->getValue()) + ++counts[category_idx]; + else if (counts[category_idx] > 0) + --counts[category_idx]; + } + } + } else { + if constexpr (std::is_same()) { + if (category > 0 && flag->getValue()) + ++counts[category_idx]; + } + } + }; + + const auto dest_size = dest.size(); + const auto src_size = src.size(); + + if (dest_size == src_size) { + for (s32 i = 0; i < dest_size; ++i) { + if (!dest[i]) + continue; + if (ignore_temp_flags && !dest[i]->isSave()) + continue; + if (record_copies && dest[i]->isSave()) + continue; + + if (!src[i]) { + if (!dest[i]->isSave()) + dest[i]->resetToInitialValue(); + } else { + auto* flag = static_cast*>(dest[i]); + auto* flag_src = static_cast*>(src[i]); + update_records(flag, flag_src, i); + } + } + + } else if (src_size < dest_size) { + s32 j = 0; + for (s32 i = 0; i < dest_size; ++i) { + if (ignore_temp_flags && !dest[i]->isSave()) + continue; + if (record_copies && dest[i]->isSave()) + continue; + + if (j >= src_size || src[j]->getHash() != dest[i]->getHash()) { + if (!dest[i]->isSave()) + dest[i]->resetToInitialValue(); + } else if (src[j]->getHash() == dest[i]->getHash()) { + auto* flag = static_cast*>(dest[i]); + auto* flag_src = static_cast*>(src[j]); + update_records(flag, flag_src, i); + ++j; + } + } + } +} + +template +void copyFlagArrays(sead::PtrArray>& dest, + const sead::PtrArray>& src, + sead::ObjArray& records, + sead::SafeArray& counts, bool record_copies, bool ignore_temp_flags, + bool find_existing_record) { + const auto dest_size = dest.size(); + const auto src_size = src.size(); + + if (src_size == dest_size) { + for (s32 i = 0; i < dest_size; ++i) { + if (!src[i]) { + const auto n = dest[i]->size(); + if (!dest[i]->at(0)->isSave()) { + for (s32 j = 0; j < n; ++j) + dest[i]->at(j)->resetToInitialValue(); + } + } else { + copyFlags(*dest[i], *src[i], records, counts, record_copies, ignore_temp_flags, + find_existing_record, true); + } + } + + } else { + s32 j = 0; + for (s32 i = 0; i < dest_size; ++i) { + if (j >= src_size) { + const auto n = dest[i]->size(); + if (!dest[i]->at(0)->isSave()) { + for (s32 k = 0; k < n; ++k) + dest[i]->at(k)->resetToInitialValue(); + } + } else if (src[j]->at(0)->getHash() != dest[i]->at(0)->getHash()) { + const auto n = dest[i]->size(); + if (!dest[i]->at(0)->isSave()) { + for (s32 k = 0; k < n; ++k) + dest[i]->at(k)->resetToInitialValue(); + } + } else { + copyFlags(*dest[i], *src[j], records, counts, record_copies, ignore_temp_flags, + find_existing_record, true); + ++j; + } + } + } +} + void TriggerParam::copyFromGameDataRes(res::GameData* gdata, sead::Heap* heap) { if (!gdata) return; @@ -1448,20 +1590,74 @@ void TriggerParam::resetAllFlagsToInitialValues() { } } +bool TriggerParam::getBoolIfCopied(bool* value, const sead::SafeString& name, bool x, + bool y) const { + if (mCopiedBoolFlags.isEmpty()) + return false; + + const u32 hash = sead::HashCRC32::calcStringHash(name); + for (s32 i = 0; i < mCopiedBoolFlags.size(); ++i) { + if (mCopiedBoolFlags[i]->name_hash == hash) { + if (!mCopiedBoolFlags[i]->checkBitFlags(x, y)) + return false; + + *value = static_cast(mBoolFlags[getFlagIndex(mBoolFlags, hash)])->getValue(); + return true; + } + } + return false; +} + +bool TriggerParam::getS32IfCopied(s32* value, const sead::SafeString& name, bool x, bool y) const { + if (mCopiedS32Flags.isEmpty()) + return false; + + const u32 hash = sead::HashCRC32::calcStringHash(name); + for (s32 i = 0; i < mCopiedS32Flags.size(); ++i) { + if (mCopiedS32Flags[i]->name_hash == hash) { + if (!mCopiedS32Flags[i]->checkBitFlags(x, y)) + return false; + + *value = static_cast(mS32Flags[getFlagIndex(mS32Flags, hash)])->getValue(); + return true; + } + } + return false; +} + +bool TriggerParam::getF32IfCopied(f32* value, const sead::SafeString& name, bool x, bool y) const { + if (mCopiedF32Flags.isEmpty()) + return false; + + const u32 hash = sead::HashCRC32::calcStringHash(name); + for (s32 i = 0; i < mCopiedF32Flags.size(); ++i) { + if (mCopiedF32Flags[i]->name_hash == hash) { + if (!mCopiedF32Flags[i]->checkBitFlags(x, y)) + return false; + + *value = static_cast(mF32Flags[getFlagIndex(mF32Flags, hash)])->getValue(); + return true; + } + } + return false; +} + // FIXME: very incomplete -void TriggerParam::copyChangedFlags(TriggerParam& other, bool set_all_flags, bool y, bool z) { +void TriggerParam::copyChangedFlags(TriggerParam& other, bool set_all_flags, bool record_copies, + bool ignore_temp_flags) { if (!set_all_flags) { for (s32 i = 0; i < 3; ++i) { auto lock = sead::makeScopedLock(other.mCriticalSections[i].ref()); for (s32 j = 0; j < mFlagChangeRecordIndices[i]; ++i) { const FlagChangeRecord& record = mFlagChangeRecords[i].ref()[j]; + const auto idx = record.index; + const auto sub_idx = record.sub_index; switch (record.type) { case FlagType::Bool: { - auto* flag = static_cast(mBoolFlags[record.index]); - const bool find_existing = mBitFlags.ref().isOn(BitFlag::_7); - flag->setValue( - static_cast(other.mBoolFlags[record.index])->getValue()); + auto* flag = static_cast(mBoolFlags[idx]); + const bool find_existing = shouldFindExistingCopyRecord(); + flag->setValue(static_cast(other.mBoolFlags[idx])->getValue()); const auto category = flag->getCategory(); addFlagCopyRecord(mCopiedBoolFlags, flag, -1, find_existing); @@ -1473,15 +1669,75 @@ void TriggerParam::copyChangedFlags(TriggerParam& other, bool set_all_flags, boo } break; } + case FlagType::S32: { + auto* flag = static_cast(mS32Flags[idx]); + const bool find_existing = shouldFindExistingCopyRecord(); + flag->setValue(static_cast(other.mS32Flags[idx])->getValue()); + addFlagCopyRecord(mCopiedS32Flags, flag, -1, find_existing); + break; + } + case FlagType::F32: { + auto* flag = static_cast(mF32Flags[idx]); + const bool find_existing = shouldFindExistingCopyRecord(); + flag->setValue(static_cast(other.mF32Flags[idx])->getValue()); + addFlagCopyRecord(mCopiedF32Flags, flag, -1, find_existing); + break; + } + case FlagType::String: { + auto* flag = static_cast(mStringFlags[idx]); + const bool find_existing = shouldFindExistingCopyRecord(); + flag->setValue(static_cast(other.mStringFlags[idx])->getValue()); + addFlagCopyRecord(mCopiedStringFlags, flag, -1, find_existing); + break; + } + case FlagType::String64: { + auto* flag = static_cast(mString64Flags[idx]); + const bool find_existing = shouldFindExistingCopyRecord(); + flag->setValue( + static_cast(other.mString64Flags[idx])->getValue()); + addFlagCopyRecord(mCopiedString64Flags, flag, -1, find_existing); + break; + } + case FlagType::String256: { + auto* flag = static_cast(mString256Flags[idx]); + const bool find_existing = shouldFindExistingCopyRecord(); + flag->setValue( + static_cast(other.mString256Flags[idx])->getValue()); + addFlagCopyRecord(mCopiedString256Flags, flag, -1, find_existing); + break; + } + case FlagType::Vector2f: { + auto* flag = static_cast(mVector2fFlags[idx]); + const bool find_existing = shouldFindExistingCopyRecord(); + flag->setValue( + static_cast(other.mVector2fFlags[idx])->getValue()); + addFlagCopyRecord(mCopiedVector2fFlags, flag, -1, find_existing); + break; + } + case FlagType::Vector3f: { + auto* flag = static_cast(mVector3fFlags[idx]); + const bool find_existing = shouldFindExistingCopyRecord(); + flag->setValue( + static_cast(other.mVector3fFlags[idx])->getValue()); + addFlagCopyRecord(mCopiedVector3fFlags, flag, -1, find_existing); + break; + } + case FlagType::Vector4f: { + auto* flag = static_cast(mVector4fFlags[idx]); + const bool find_existing = shouldFindExistingCopyRecord(); + flag->setValue( + static_cast(other.mVector4fFlags[idx])->getValue()); + addFlagCopyRecord(mCopiedVector4fFlags, flag, -1, find_existing); + break; + } + case FlagType::BoolArray: { - auto* flag = - static_cast((*mBoolArrayFlags[record.index])[record.sub_index]); - const bool find_existing = mBitFlags.ref().isOn(BitFlag::_7); - flag->setValue(static_cast( - (*other.mBoolArrayFlags[record.index])[record.sub_index]) - ->getValue()); + auto* flag = static_cast((*mBoolArrayFlags[idx])[sub_idx]); + auto* flag2 = static_cast((*other.mBoolArrayFlags[idx])[sub_idx]); + const bool find_existing = shouldFindExistingCopyRecord(); + flag->setValue(flag2->getValue()); const auto category = flag->getCategory(); - addFlagCopyRecord(mCopiedBoolFlags, flag, record.sub_index, find_existing); + addFlagCopyRecord(mCopiedBoolFlags, flag, sub_idx, find_existing); if (category > 0) { if (flag->getValue()) @@ -1491,6 +1747,86 @@ void TriggerParam::copyChangedFlags(TriggerParam& other, bool set_all_flags, boo } break; } + case FlagType::S32Array: { + auto* flag = static_cast((*mS32ArrayFlags[idx])[record.sub_index]); + auto* flag2 = + static_cast((*other.mS32ArrayFlags[idx])[record.sub_index]); + const bool find_existing = shouldFindExistingCopyRecord(); + flag->setValue(flag2->getValue()); + addFlagCopyRecord(mCopiedS32Flags, flag, sub_idx, find_existing); + break; + } + case FlagType::F32Array: { + auto* flag = static_cast((*mF32ArrayFlags[idx])[record.sub_index]); + auto* flag2 = + static_cast((*other.mF32ArrayFlags[idx])[record.sub_index]); + const bool find_existing = shouldFindExistingCopyRecord(); + flag->setValue(flag2->getValue()); + addFlagCopyRecord(mCopiedF32Flags, flag, sub_idx, find_existing); + break; + } + case FlagType::StringArray: { + auto* flag = + static_cast((*mStringArrayFlags[idx])[record.sub_index]); + auto* flag2 = + static_cast((*other.mStringArrayFlags[idx])[record.sub_index]); + const bool find_existing = shouldFindExistingCopyRecord(); + flag->setValue(flag2->getValue()); + addFlagCopyRecord(mCopiedStringFlags, flag, sub_idx, find_existing); + break; + } + case FlagType::String64Array: { + auto* flag = + static_cast((*mString64ArrayFlags[idx])[record.sub_index]); + auto* flag2 = static_cast( + (*other.mString64ArrayFlags[idx])[record.sub_index]); + const bool find_existing = shouldFindExistingCopyRecord(); + flag->setValue(flag2->getValue()); + addFlagCopyRecord(mCopiedString64Flags, flag, sub_idx, find_existing); + break; + } + case FlagType::String256Array: { + auto* flag = + static_cast((*mString256ArrayFlags[idx])[record.sub_index]); + auto* flag2 = static_cast( + (*other.mString256ArrayFlags[idx])[record.sub_index]); + const bool find_existing = shouldFindExistingCopyRecord(); + flag->setValue(flag2->getValue()); + addFlagCopyRecord(mCopiedString256Flags, flag, sub_idx, find_existing); + break; + } + case FlagType::Vector2fArray: { + auto* flag = + static_cast((*mVector2fArrayFlags[idx])[record.sub_index]); + auto* flag2 = static_cast( + (*other.mVector2fArrayFlags[idx])[record.sub_index]); + const bool find_existing = shouldFindExistingCopyRecord(); + flag->setValue(flag2->getValue()); + addFlagCopyRecord(mCopiedVector2fFlags, flag, sub_idx, find_existing); + break; + } + case FlagType::Vector3fArray: { + auto* flag = + static_cast((*mVector3fArrayFlags[idx])[record.sub_index]); + auto* flag2 = static_cast( + (*other.mVector3fArrayFlags[idx])[record.sub_index]); + const bool find_existing = shouldFindExistingCopyRecord(); + flag->setValue(flag2->getValue()); + addFlagCopyRecord(mCopiedVector3fFlags, flag, sub_idx, find_existing); + break; + } + case FlagType::Vector4fArray: { + auto* flag = + static_cast((*mVector4fArrayFlags[idx])[record.sub_index]); + auto* flag2 = static_cast( + (*other.mVector4fArrayFlags[idx])[record.sub_index]); + const bool find_existing = shouldFindExistingCopyRecord(); + flag->setValue(flag2->getValue()); + addFlagCopyRecord(mCopiedVector4fFlags, flag, sub_idx, find_existing); + break; + } + case FlagType::Invalid: + break; } } @@ -1499,6 +1835,61 @@ void TriggerParam::copyChangedFlags(TriggerParam& other, bool set_all_flags, boo } return; } + + copyFlags(mBoolFlags, other.mBoolFlags, mCopiedBoolFlags, mNumBoolFlagsPerCategory0, + record_copies, ignore_temp_flags, shouldFindExistingCopyRecord(), false); + copyFlags(mS32Flags, other.mS32Flags, mCopiedS32Flags, mNumBoolFlagsPerCategory0, + record_copies, ignore_temp_flags, shouldFindExistingCopyRecord(), false); + copyFlags(mF32Flags, other.mF32Flags, mCopiedF32Flags, mNumBoolFlagsPerCategory0, + record_copies, ignore_temp_flags, shouldFindExistingCopyRecord(), false); + copyFlags>(mStringFlags, other.mStringFlags, mCopiedStringFlags, + mNumBoolFlagsPerCategory0, record_copies, + ignore_temp_flags, shouldFindExistingCopyRecord(), false); + copyFlags>(mString64Flags, other.mString64Flags, mCopiedString64Flags, + mNumBoolFlagsPerCategory0, record_copies, + ignore_temp_flags, shouldFindExistingCopyRecord(), false); + copyFlags>( + mString256Flags, other.mString256Flags, mCopiedString256Flags, mNumBoolFlagsPerCategory0, + record_copies, ignore_temp_flags, shouldFindExistingCopyRecord(), false); + copyFlags(mVector2fFlags, other.mVector2fFlags, mCopiedVector2fFlags, + mNumBoolFlagsPerCategory0, record_copies, ignore_temp_flags, + shouldFindExistingCopyRecord(), false); + copyFlags(mVector3fFlags, other.mVector3fFlags, mCopiedVector3fFlags, + mNumBoolFlagsPerCategory0, record_copies, ignore_temp_flags, + shouldFindExistingCopyRecord(), false); + copyFlags(mVector4fFlags, other.mVector4fFlags, mCopiedVector4fFlags, + mNumBoolFlagsPerCategory0, record_copies, ignore_temp_flags, + shouldFindExistingCopyRecord(), false); + + copyFlagArrays(mBoolArrayFlags, other.mBoolArrayFlags, mCopiedBoolFlags, + mNumBoolFlagsPerCategory0, record_copies, ignore_temp_flags, + shouldFindExistingCopyRecord()); + copyFlagArrays(mS32ArrayFlags, other.mS32ArrayFlags, mCopiedS32Flags, + mNumBoolFlagsPerCategory0, record_copies, ignore_temp_flags, + shouldFindExistingCopyRecord()); + copyFlagArrays(mF32ArrayFlags, other.mF32ArrayFlags, mCopiedF32Flags, + mNumBoolFlagsPerCategory0, record_copies, ignore_temp_flags, + shouldFindExistingCopyRecord()); + copyFlagArrays>( + mStringArrayFlags, other.mStringArrayFlags, mCopiedStringFlags, mNumBoolFlagsPerCategory0, + record_copies, ignore_temp_flags, shouldFindExistingCopyRecord()); + copyFlagArrays>(mString64ArrayFlags, other.mString64ArrayFlags, + mCopiedString64Flags, mNumBoolFlagsPerCategory0, + record_copies, ignore_temp_flags, + shouldFindExistingCopyRecord()); + copyFlagArrays>(mString256ArrayFlags, other.mString256ArrayFlags, + mCopiedString256Flags, mNumBoolFlagsPerCategory0, + record_copies, ignore_temp_flags, + shouldFindExistingCopyRecord()); + copyFlagArrays(mVector2fArrayFlags, other.mVector2fArrayFlags, + mCopiedVector2fFlags, mNumBoolFlagsPerCategory0, record_copies, + ignore_temp_flags, shouldFindExistingCopyRecord()); + copyFlagArrays(mVector3fArrayFlags, other.mVector3fArrayFlags, + mCopiedVector3fFlags, mNumBoolFlagsPerCategory0, record_copies, + ignore_temp_flags, shouldFindExistingCopyRecord()); + copyFlagArrays(mVector4fArrayFlags, other.mVector4fArrayFlags, + mCopiedVector4fFlags, mNumBoolFlagsPerCategory0, record_copies, + ignore_temp_flags, shouldFindExistingCopyRecord()); } s32 TriggerParam::getBoolIdx(u32 name) const { diff --git a/src/KingSystem/GameData/gdtTriggerParam.h b/src/KingSystem/GameData/gdtTriggerParam.h index c122e739..8bb88cd8 100644 --- a/src/KingSystem/GameData/gdtTriggerParam.h +++ b/src/KingSystem/GameData/gdtTriggerParam.h @@ -48,7 +48,12 @@ public: _8 = 8, }; - sead::TypedBitFlag bit_flag; + bool checkBitFlags(bool x, bool y) const { + return bf.isOn(BitFlag::_8) || !(bf.isOn(BitFlag::_4) || (bf.isOn(BitFlag::_1) && !x) || + (bf.isOn(BitFlag::_2) && !y)); + } + + sead::TypedBitFlag bf; s16 sub_index; u32 name_hash; }; @@ -429,11 +434,11 @@ public: FlagS32* getS32FlagByHash(u32 name_hash) const; void onResetBoolFlagForRadarMgr(FlagBase* flag, s32 sub_idx = -1); - bool getBoolIfChanged(bool* value, const sead::SafeString& name, bool x, bool y) const; - bool getS32IfChanged(s32* value, const sead::SafeString& name, bool x, bool y) const; - bool getF32IfChanged(f32* value, const sead::SafeString& name, bool x, bool y) const; + bool getBoolIfCopied(bool* value, const sead::SafeString& name, bool x, bool y) const; + bool getS32IfCopied(s32* value, const sead::SafeString& name, bool x, bool y) const; + bool getF32IfCopied(f32* value, const sead::SafeString& name, bool x, bool y) const; - void copyChangedFlags(TriggerParam& other, bool set_all_flags, bool y, bool z); + void copyChangedFlags(TriggerParam& other, bool set_all_flags, bool record_copies, bool ignore_temp_flags); private: enum class BitFlag : u8 { @@ -452,6 +457,8 @@ private: void recordFlagChange(const FlagBase* flag, s32 idx, s32 sub_idx = -1); + bool shouldFindExistingCopyRecord() const { return mBitFlags.ref().isOn(BitFlag::_7); } + u32 mResourceFlags = 0; sead::PtrArray mBoolFlags; @@ -491,7 +498,8 @@ private: sead::Heap* mHeap = nullptr; - std::array mFlagChangeRecordIndices; + std::array mFlagChangeRecordIndices; + sead::SafeArray mNumBoolFlagsPerCategory0; sead::SafeArray mNumBoolFlagsPerCategory; sead::SafeArray, 3> mCriticalSections{}; sead::StorageFor> mBitFlags;