ksys/gdt: Implement TriggerParam::recordFlagChange

This commit is contained in:
Léo Lam 2020-10-25 11:07:45 +01:00
parent da2a57992c
commit c612f77fcd
No known key found for this signature in database
GPG Key ID: 0DF30F9081000741
4 changed files with 46 additions and 16 deletions

View File

@ -74414,7 +74414,7 @@
0x0000007100de1a20,TriggerParam::getS32Max,324,_ZNK4ksys3gdt12TriggerParam17getMaxValueForS32EPiRKN4sead14SafeStringBaseIcEE
0x0000007100de1b64,TriggerParam::setBoolByIndex,236,
0x0000007100de1c50,sub_7100DE1C50,260,
0x0000007100de1d54,TriggerParam::postSetFlagMaybe,360,
0x0000007100de1d54,TriggerParam::postSetFlagMaybe,360,_ZN4ksys3gdt12TriggerParam16recordFlagChangeEPKNS0_8FlagBaseEis
0x0000007100de1ebc,GameDataFlagBool::reportUpdate,1084,
0x0000007100de22f8,TriggerParam::setS32ByIdx,332,
0x0000007100de2444,sub_7100DE2444,1220,

Can't render this file because it is too large.

@ -1 +1 @@
Subproject commit 6881c8ed535464bf205ea9655b348c8553e1f956
Subproject commit e0f91577f3df97c41f4a91493dc06b208387963b

View File

@ -1,5 +1,6 @@
#include "KingSystem/GameData/gdtTriggerParam.h"
#include <algorithm>
#include <mc/seadCoreInfo.h>
#include "KingSystem/GameData/gdtFlagProxy.h"
#include "KingSystem/Resource/resResourceGameData.h"
#include "KingSystem/Utils/SafeDelete.h"
@ -7,10 +8,12 @@
namespace ksys::gdt {
TriggerParam::TriggerParam() {
mUnkArray.constructDefault();
mCriticalSections.constructDefault();
for (auto& buffer : mFlagChangeRecords)
buffer.constructDefault();
for (auto& cs : mCriticalSections)
cs.constructDefault();
mBitFlags.constructDefault();
mCounts.fill(0);
mFlagChangeRecordIndices.fill(0);
mNumBoolFlagsPerCategory.fill(0);
}
@ -459,8 +462,8 @@ void TriggerParam::copyAllFlags(const TriggerParam& src, sead::Heap* heap, bool
#undef COPY_ARRAY_
if (init_reset_data) {
for (auto& array : *mUnkArray.data())
array.allocBufferAssert(num_flags, heap);
for (auto& array : mFlagChangeRecords)
array.ref().allocBufferAssert(num_flags, heap);
initResetData(heap);
initRevivalRandomBools(heap);
}
@ -855,6 +858,25 @@ bool TriggerParam::getMaxValueForS32(s32* max, const sead::SafeString& name) con
return true;
}
void TriggerParam::recordFlagChange(const FlagBase* flag, s32 idx, s16 sub_idx) {
const auto core = sead::CoreInfo::getCurrentCoreId();
const u32 platform_core_id = sead::CoreInfo::getPlatformCoreId(core);
auto& buffer = mFlagChangeRecords[platform_core_id].ref();
if (buffer.size() < 1)
return;
auto lock = sead::makeScopedLock(mCriticalSections[platform_core_id].ref());
buffer[mFlagChangeRecordIndices[platform_core_id]].type.mValue = u8(flag->getType());
buffer[mFlagChangeRecordIndices[platform_core_id]].index = idx;
buffer[mFlagChangeRecordIndices[platform_core_id]].sub_index = sub_idx;
++mFlagChangeRecordIndices[platform_core_id];
if (flag->getType() == FlagType::Bool)
mBitFlags.ref().set(BitFlag::_8);
}
s32 TriggerParam::getBoolIdx(u32 name) const {
return getFlagIndex(mBoolFlags, name);
}

View File

@ -1,5 +1,6 @@
#pragma once
#include <array>
#include <basis/seadTypes.h>
#include <codec/seadHashCRC32.h>
#include <container/seadBuffer.h>
@ -26,6 +27,17 @@ public:
};
KSYS_CHECK_SIZE_NX150(ResetEntry, 0x8);
struct FlagChangeRecord {
sead::SizedEnum<FlagType::ValueType, u8> type;
sead::SizedEnum<ResetType, u8> reset_type;
/// If the flag that was modified was an array, this is the index of the modified element.
/// Otherwise, this is -1.
s16 sub_index;
/// Index of the flag that was modified.
s32 index;
};
KSYS_CHECK_SIZE_NX150(FlagChangeRecord, 0x8);
TriggerParam();
void copyFromGameDataRes(res::GameData* gdata, sead::Heap* heap);
@ -212,7 +224,7 @@ public:
private:
enum class BitFlag : u8 {
_8 = 8,
};
void allocCombinedFlagArrays(sead::Heap* heap);
@ -220,11 +232,7 @@ private:
void initResetData(sead::Heap* heap);
void initRevivalRandomBools(sead::Heap* heap);
sead::TypedBitFlag<BitFlag>& getBitFlags() { return *mBitFlags.data(); }
const sead::TypedBitFlag<BitFlag>& getBitFlags() const { return *mBitFlags.data(); }
sead::SafeArray<sead::CriticalSection, 3>& getCriticalSections() {
return *mCriticalSections.data();
}
void recordFlagChange(const FlagBase* flag, s32 idx, s16 sub_idx);
u32 mResourceFlags = 0;
@ -248,7 +256,7 @@ private:
sead::PtrArray<sead::PtrArray<FlagBase>> mVector3fArrayFlags;
sead::PtrArray<sead::PtrArray<FlagBase>> mVector4fArrayFlags;
sead::StorageFor<sead::SafeArray<sead::Buffer<ResetEntry>, 3>> mUnkArray{};
sead::SafeArray<sead::StorageFor<sead::Buffer<FlagChangeRecord>>, 3> mFlagChangeRecords{};
sead::ObjArray<FlagBase> mCombinedBoolFlags;
sead::ObjArray<FlagBase> mCombinedS32Flags;
@ -265,9 +273,9 @@ private:
sead::Heap* mHeap = nullptr;
sead::SafeArray<s32, 18> mCounts;
std::array<s32, 18> mFlagChangeRecordIndices;
sead::SafeArray<s32, 15> mNumBoolFlagsPerCategory;
sead::StorageFor<sead::SafeArray<sead::CriticalSection, 3>> mCriticalSections{};
sead::SafeArray<sead::StorageFor<sead::CriticalSection>, 3> mCriticalSections{};
sead::StorageFor<sead::TypedBitFlag<BitFlag>> mBitFlags;
};
KSYS_CHECK_SIZE_NX150(TriggerParam, 0x3f0);