summaryrefslogtreecommitdiff
path: root/src/KingSystem/ActorSystem
diff options
context:
space:
mode:
authorLéo Lam <leo@leolam.fr>2021-04-23 00:30:30 +0200
committerLéo Lam <leo@leolam.fr>2021-04-23 12:53:04 +0200
commit201d2ff06fd9ee9a1aac0ce914b23effae9c8f22 (patch)
treef9ff0055a38c0ec094410e7f738d6f68a4e4dfe2 /src/KingSystem/ActorSystem
parent52196c4b75f84444bca3b9c19302146235bf8f6a (diff)
ksys/act: Finish implementing ActorParamMgr
Diffstat (limited to 'src/KingSystem/ActorSystem')
-rw-r--r--src/KingSystem/ActorSystem/actASSetting.cpp2
-rw-r--r--src/KingSystem/ActorSystem/actASSetting.h2
-rw-r--r--src/KingSystem/ActorSystem/actActorParam.h6
-rw-r--r--src/KingSystem/ActorSystem/actActorParamMgr.cpp144
-rw-r--r--src/KingSystem/ActorSystem/actActorParamMgr.h8
5 files changed, 152 insertions, 10 deletions
diff --git a/src/KingSystem/ActorSystem/actASSetting.cpp b/src/KingSystem/ActorSystem/actASSetting.cpp
index 7c3d82e2..2b020cfe 100644
--- a/src/KingSystem/ActorSystem/actASSetting.cpp
+++ b/src/KingSystem/ActorSystem/actASSetting.cpp
@@ -8,7 +8,7 @@ SEAD_SINGLETON_DISPOSER_IMPL(ASSetting)
ASSetting::~ASSetting() = default;
-void ASSetting::init(const sead::SafeString& config_path) {
+void ASSetting::init(const sead::SafeString& config_path, sead::Heap* heap) {
res::LoadRequest req;
req.mRequester = "ASSetting";
req._22 = true;
diff --git a/src/KingSystem/ActorSystem/actASSetting.h b/src/KingSystem/ActorSystem/actASSetting.h
index 399ad201..8c97c85a 100644
--- a/src/KingSystem/ActorSystem/actASSetting.h
+++ b/src/KingSystem/ActorSystem/actASSetting.h
@@ -15,7 +15,7 @@ class ASSetting {
virtual ~ASSetting();
public:
- void init(const sead::SafeString& config_path);
+ void init(const sead::SafeString& config_path, sead::Heap* heap);
res::ASParamParser* getBoneParams(const sead::SafeString& key) const;
private:
diff --git a/src/KingSystem/ActorSystem/actActorParam.h b/src/KingSystem/ActorSystem/actActorParam.h
index 70b399d5..2d395965 100644
--- a/src/KingSystem/ActorSystem/actActorParam.h
+++ b/src/KingSystem/ActorSystem/actActorParam.h
@@ -16,7 +16,7 @@ namespace ksys {
namespace res {
class AIProgram;
class AISchedule;
-class AnimationInfo;
+class AnimInfo;
class ASList;
class AttClientList;
class Awareness;
@@ -107,7 +107,7 @@ public:
res::BoneControl* mBoneControl;
res::LifeCondition* mLifeCondition;
res::UMii* mUMii;
- res::AnimationInfo* mAnimationInfo;
+ res::AnimInfo* mAnimationInfo;
};
sead::SafeArray<void*, 25> mArray;
};
@@ -144,7 +144,7 @@ private:
void setEventSignal();
void waitForEvent();
bool isSignalSet() const;
- void updateResource(const char* name, const char* data, const char* data1);
+ int updateResource(const char* data, const char* data1, const char* data2);
res::Handle* allocHandle();
void freeLastHandle();
diff --git a/src/KingSystem/ActorSystem/actActorParamMgr.cpp b/src/KingSystem/ActorSystem/actActorParamMgr.cpp
index cf595074..9409ea15 100644
--- a/src/KingSystem/ActorSystem/actActorParamMgr.cpp
+++ b/src/KingSystem/ActorSystem/actActorParamMgr.cpp
@@ -2,6 +2,7 @@
#include <prim/seadScopedLock.h>
#include "KingSystem/ActorSystem/actASSetting.h"
#include "KingSystem/ActorSystem/actActorParam.h"
+#include "KingSystem/Resource/resEntryFactory.h"
#include "KingSystem/Resource/resLoadRequest.h"
#include "KingSystem/Resource/resResourceAIProgram.h"
#include "KingSystem/Resource/resResourceAISchedule.h"
@@ -32,6 +33,7 @@
#include "KingSystem/Resource/resSystem.h"
#include "KingSystem/Resource/resTempResourceLoader.h"
#include "KingSystem/Utils/Debug.h"
+#include "KingSystem/Utils/HeapUtil.h"
#include "KingSystem/Utils/ParamIO.h"
namespace ksys::act {
@@ -43,6 +45,108 @@ using User = res::ActorLink::User;
ActorParamMgr::ActorParamMgr() = default;
+void ActorParamMgr::init(sead::Heap* heap, sead::Heap* debug_heap) {
+ mTempHeap = util::DualHeap::create(0x300000, "TmpActorParamMgr", heap, debug_heap,
+ sizeof(void*), sead::Heap::cHeapDirection_Forward, false);
+ mTempHeap->enableLock(true);
+ mDebugHeap = debug_heap;
+
+ mParams = new (mTempHeap) ActorParam[NumParams];
+
+ res::registerEntryFactory(new (mTempHeap) res::EntryFactory<res::ActorLink>(1.0, 0x1000),
+ "bxml");
+ res::registerEntryFactory(new (mTempHeap) res::EntryFactory<res::GParamList>(
+ 1.0, res::GParamList::getResourceFactoryFallbackSize() + 0x800),
+ "bgparamlist");
+ res::registerEntryFactory(new (mTempHeap) res::EntryFactory<res::ModelList>(2.0), "bmodellist");
+ res::registerEntryFactory(new (mTempHeap) res::EntryFactory<res::ASList>(0.0, 0x80000),
+ "baslist");
+ res::registerEntryFactory(new (mTempHeap) res::EntryFactory<res::AIProgram>(1.0, 0x300000),
+ "baiprog");
+ res::registerEntryFactory(new (mTempHeap) res::EntryFactory<res::Physics>(6.0), "bphysics");
+ res::registerEntryFactory(new (mTempHeap) res::EntryFactory<res::Chemical>(0.0, 0x2000),
+ "bchemical");
+ res::registerEntryFactory(new (mTempHeap) res::EntryFactory<res::AS>(0.0, 0x80000), "bas");
+ res::registerEntryFactory(new (mTempHeap) res::EntryFactory<res::AttClientList>(1.0, 0x2000),
+ "batcllist");
+ res::registerEntryFactory(new (mTempHeap) res::EntryFactory<res::AttClient>(1.0, 0x2000),
+ "batcl");
+ res::registerEntryFactory(new (mTempHeap) res::EntryFactory<res::AISchedule>(1.0, 0x800),
+ "baischedule");
+ res::registerEntryFactory(new (mTempHeap) res::EntryFactory<res::DamageParam>(1.0, 0x20000),
+ "bdmgparam");
+ res::registerEntryFactory(
+ new (mTempHeap) res::EntryFactory<res::RagdollConfigList>(1.0, 0x2000), "brgconfiglist");
+ res::registerEntryFactory(new (mTempHeap) res::EntryFactory<res::RagdollConfig>(1.0, 0x20000),
+ "brgconfig");
+ res::registerEntryFactory(
+ new (mTempHeap) res::EntryFactory<res::RagdollBlendWeight>(1.0, 0x20000), "brgbw");
+ res::registerEntryFactory(new (mTempHeap) res::EntryFactory<res::Awareness>, "bawareness");
+ res::registerEntryFactory(new (mTempHeap) res::EntryFactory<res::Drop>(1.0, 0x5000), "bdrop");
+ res::registerEntryFactory(new (mTempHeap) res::EntryFactory<res::Shop>(1.0, 0x20000), "bshop");
+ res::registerEntryFactory(new (mTempHeap) res::EntryFactory<res::Recipe>(1.0, 0x20000),
+ "brecipe");
+ res::registerEntryFactory(new (mTempHeap) res::EntryFactory<res::Lod>(1.0, 0x20000), "blod");
+ res::registerEntryFactory(new (mTempHeap) res::EntryFactory<res::BoneControl>(1.0, 0x40000),
+ "bbonectrl");
+ res::registerEntryFactory(new (mTempHeap) res::EntryFactory<res::LifeCondition>(1.0, 0x20000),
+ "blifecondition");
+ res::registerEntryFactory(new (mTempHeap) res::EntryFactory<res::UMii>, "bumii");
+ res::registerEntryFactory(new (mTempHeap) res::EntryFactory<res::AnimInfo>(1.5), "baniminfo");
+ res::registerEntryFactory(new (mTempHeap) res::EntryFactory<sead::DirectResource>, "byaml");
+
+ {
+ using ResType = ActorParam::ResourceType;
+ res::LoadRequest req;
+ req.mRequester = "tapActorParamMgr";
+
+ getDummyResHandle(ResType::AIProgram).load("Actor/AIProgram/Dummy.baiprog", &req);
+ getDummyResHandle(ResType::ASList).load("Actor/ASList/Dummy.baslist", &req);
+ getDummyResHandle(ResType::AttClientList).load("Actor/AttClientList/Dummy.batcllist", &req);
+ getDummyResHandle(ResType::ModelList).load("Actor/ModelList/Dummy.bmodellist", &req);
+ getDummyResHandle(ResType::Physics).load("Actor/Physics/Dummy.bphysics", &req);
+ getDummyResHandle(ResType::Chemical).load("Actor/Chemical/Dummy.bchemical", &req);
+ getDummyResHandle(ResType::AISchedule).load("Actor/AISchedule/Dummy.baischedule", &req);
+ getDummyResHandle(ResType::EventFlow).load("EventFlow/Dummy.bfevfl", &req);
+ getDummyResHandle(ResType::AS).load("Actor/AS/Dummy.bas", &req);
+ getDummyResHandle(ResType::AttClient).load("Actor/AttClient/Dummy.batcl", &req);
+ getDummyResHandle(ResType::DamageParam).load("Actor/DamageParam/Dummy.bdmgparam", &req);
+ getDummyResHandle(ResType::RagdollConfigList)
+ .load("Actor/RagdollConfigList/Dummy.brgconfiglist", &req);
+ getDummyResHandle(ResType::RagdollConfig).load("Actor/RagdollConfig/Dummy.brgconfig", &req);
+ getDummyResHandle(ResType::RagdollBlendWeight)
+ .load("Actor/RagdollBlendWeight/Dummy.brgbw", &req);
+ getDummyResHandle(ResType::Awareness).load("Actor/Awareness/Dummy.bawareness", &req);
+ getDummyResHandle(ResType::DropTable).load("Actor/DropTable/Dummy.bdrop", &req);
+ getDummyResHandle(ResType::ShopData).load("Actor/ShopData/Dummy.bshop", &req);
+ getDummyResHandle(ResType::Recipe).load("Actor/Recipe/Dummy.brecipe", &req);
+ getDummyResHandle(ResType::Lod).load("Actor/LOD/Dummy.blod", &req);
+ getDummyResHandle(ResType::BoneControl).load("Actor/BoneControl/Dummy.bbonectrl", &req);
+ getDummyResHandle(ResType::LifeCondition)
+ .load("Actor/LifeCondition/Dummy.blifecondition", &req);
+ getDummyResHandle(ResType::UMii).load("Actor/UMii/Dummy.bumii", &req);
+ getDummyResHandle(ResType::AnimationInfo).load("Actor/AnimationInfo/Dummy.baniminfo", &req);
+
+ auto* dummy_gparam_factory = new (mTempHeap) res::EntryFactory<res::DummyGParamList>(
+ 1.0, res::GParamList::getResourceFactoryFallbackSize() + 0x1400);
+ req.mEntryFactory = dummy_gparam_factory;
+ getDummyResHandle(ResType::GParamList)
+ .load("Actor/GeneralParamList/Dummy.bgparamlist", &req);
+ if (dummy_gparam_factory)
+ delete dummy_gparam_factory;
+
+ auto* modellist = static_cast<res::ModelList*>(
+ getDummyResHandle(ResType::ModelList).getResourceUnchecked());
+ modellist->markAsDummy();
+ }
+
+ res::registerEntryFactory(new (mTempHeap) res::EntryFactory<res::ASSetting>(0.0, 0x80000),
+ "bassetting");
+ ASSetting::createInstance(mTempHeap);
+ ASSetting::instance()->init("Actor/ASSetting.bassetting", mTempHeap);
+ ActorParam::resetDummyResources();
+}
+
ActorParamMgr::~ActorParamMgr() {
ASSetting::deleteInstance();
}
@@ -93,7 +197,7 @@ ActorParam* ActorParamMgr::loadParam(const char* actor_name, res::Handle* pack_h
ActorParam* param = allocParam(actor_name, &allocated_new);
if (allocated_new) {
- loadFiles(param, mTmpActorParamMgrHeap, pack_handle, x, load_req_c);
+ loadFiles(param, mTempHeap, pack_handle, x, load_req_c);
param->setEventSignal();
} else {
param->waitForEvent();
@@ -157,7 +261,7 @@ ActorParam* ActorParamMgr::loadParamAsync(const char* actor_name, res::Handle* p
return param;
param->deleteResHandles();
- param->allocResHandles(mTmpActorParamMgrHeap, 0, ActorParam::NumResourceTypes + 1);
+ param->allocResHandles(mTempHeap, 0, ActorParam::NumResourceTypes + 1);
param->mActiveBufferIdx = 0;
loadFileAsync<res::ActorLink>(param, Type::ActorLink, "Actor/ActorLink", "xml",
@@ -385,7 +489,7 @@ void ActorParamMgr::loadExtraResAsync(ActorParam* param, res::Handle* pack_handl
const auto num_att = atcllist ? atcllist->getClients().size() : 0;
const auto num_rg = rgconfiglist ? rgconfiglist->getImpulseParams().size() : 0;
- param->allocResHandles(mTmpActorParamMgrHeap, 1, num_as + num_att + num_rg);
+ param->allocResHandles(mTempHeap, 1, num_as + num_att + num_rg);
param->mActiveBufferIdx = 1;
if (aslist) {
@@ -779,6 +883,40 @@ T* ActorParamMgr::loadFile(ActorParam* param, ActorParam::ResourceType type, con
return res;
}
+void ActorParamMgr::syncData(char* data) {
+ auto lock = sead::makeScopedLock(mCS);
+
+ char* data1 = data;
+ while (*data1++ != ' ')
+ continue;
+ data1[-1] = 0;
+
+ while (*data1++ != '[')
+ continue;
+
+ char* data2 = data1;
+ while (*data2++ != ']')
+ continue;
+ data2[-1] = 0;
+
+ for (int i = 0; i < NumParams; ++i) {
+ auto& param = mParams[i];
+ if (param.getActorName().isEmpty())
+ continue;
+
+ param.waitForEvent();
+ const int ret = param.updateResource(data, data1, data2);
+ if (ret == 0)
+ return;
+ if (ret == 1) {
+ sead::FixedSafeString<64> message;
+ message.format("[UpdateResource]%s", data);
+ log(message.cstr());
+ return;
+ }
+ }
+}
+
res::GParamList* ActorParamMgr::getDummyGParamList() const {
return static_cast<res::GParamList*>(
mDummyResources[u32(ActorParam::ResourceType::GParamList)].getResourceUnchecked());
diff --git a/src/KingSystem/ActorSystem/actActorParamMgr.h b/src/KingSystem/ActorSystem/actActorParamMgr.h
index c39c4709..3704dce3 100644
--- a/src/KingSystem/ActorSystem/actActorParamMgr.h
+++ b/src/KingSystem/ActorSystem/actActorParamMgr.h
@@ -34,7 +34,7 @@ public:
DebugMessage& getDebugMessage() { return mDebugMessage; }
sead::Heap* getDebugHeap() const { return mDebugHeap; }
- sead::Heap* getTmpActorParamMgrHeap() const { return mTmpActorParamMgrHeap; }
+ sead::Heap* getTmpActorParamMgrHeap() const { return mTempHeap; }
bool checkPath(const sead::SafeString& path) const;
@@ -95,6 +95,10 @@ private:
void allocExtraResHandles(ActorParam* param, sead::Heap* heap) const;
+ res::Handle& getDummyResHandle(ActorParam::ResourceType type) {
+ return mDummyResources[int(type)];
+ }
+
static constexpr s32 NumParams = 0x400;
sead::TypedBitFlag<Flag> mFlags{};
@@ -103,7 +107,7 @@ private:
void* _e0 = nullptr;
void* _e8 = nullptr;
sead::Heap* mDebugHeap = nullptr;
- sead::Heap* mTmpActorParamMgrHeap = nullptr;
+ sead::Heap* mTempHeap = nullptr;
sead::SafeArray<res::Handle, ActorParam::NumResourceTypes> mDummyResources;
mutable sead::CriticalSection mCS;
};