From 3a9fd0f9b9cbc3dccd87a9838f016bd5b7f1344c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Tue, 23 Mar 2021 15:11:53 +0100 Subject: [PATCH] ksys: Split actAiParam.h to reduce compile times --- src/KingSystem/ActorSystem/CMakeLists.txt | 1 + .../ActorSystem/actAiActionBase.cpp | 2 + src/KingSystem/ActorSystem/actAiActionBase.h | 5 +- src/KingSystem/ActorSystem/actAiAi.cpp | 2 + src/KingSystem/ActorSystem/actAiClassDef.cpp | 1 + src/KingSystem/ActorSystem/actAiClassDef.h | 16 +-- src/KingSystem/ActorSystem/actAiInlineParam.h | 85 +++++++++++++++ src/KingSystem/ActorSystem/actAiParam.cpp | 19 ++++ src/KingSystem/ActorSystem/actAiParam.h | 103 ++++-------------- src/KingSystem/ActorSystem/actAiQuery.cpp | 1 + src/KingSystem/ActorSystem/actAiRoot.cpp | 1 + src/KingSystem/ActorSystem/actAiRoot.h | 1 + 12 files changed, 140 insertions(+), 97 deletions(-) create mode 100644 src/KingSystem/ActorSystem/actAiInlineParam.h diff --git a/src/KingSystem/ActorSystem/CMakeLists.txt b/src/KingSystem/ActorSystem/CMakeLists.txt index 2ca08b2c..78676af5 100644 --- a/src/KingSystem/ActorSystem/CMakeLists.txt +++ b/src/KingSystem/ActorSystem/CMakeLists.txt @@ -42,6 +42,7 @@ target_sources(uking PRIVATE actAiBehavior.h actAiClassDef.cpp actAiClassDef.h + actAiInlineParam.h actAiParam.cpp actAiParam.h actAiQuery.cpp diff --git a/src/KingSystem/ActorSystem/actAiActionBase.cpp b/src/KingSystem/ActorSystem/actAiActionBase.cpp index a3a5adcb..8f62ecd9 100644 --- a/src/KingSystem/ActorSystem/actAiActionBase.cpp +++ b/src/KingSystem/ActorSystem/actAiActionBase.cpp @@ -2,9 +2,11 @@ #include "KingSystem/ActorSystem/actActor.h" #include "KingSystem/ActorSystem/actActorParam.h" #include "KingSystem/ActorSystem/actAiAction.h" +#include "KingSystem/ActorSystem/actAiInlineParam.h" #include "KingSystem/ActorSystem/actAiRoot.h" #include "KingSystem/Resource/resResourceAIProgram.h" #include "KingSystem/Utils/InitTimeInfo.h" +#include "KingSystem/Utils/Thread/MessageTransceiverId.h" namespace ksys::act::ai { diff --git a/src/KingSystem/ActorSystem/actAiActionBase.h b/src/KingSystem/ActorSystem/actAiActionBase.h index 283e754f..d21ee008 100644 --- a/src/KingSystem/ActorSystem/actAiActionBase.h +++ b/src/KingSystem/ActorSystem/actAiActionBase.h @@ -2,14 +2,17 @@ #include #include +#include #include #include #include "KingSystem/ActorSystem/actAiParam.h" #include "KingSystem/Utils/Types.h" namespace ksys { +struct AIDefSet; class Message; -} +struct MesTransceiverId; +} // namespace ksys namespace ksys::res { class AIProgram; diff --git a/src/KingSystem/ActorSystem/actAiAi.cpp b/src/KingSystem/ActorSystem/actAiAi.cpp index aa013208..f689360b 100644 --- a/src/KingSystem/ActorSystem/actAiAi.cpp +++ b/src/KingSystem/ActorSystem/actAiAi.cpp @@ -3,6 +3,8 @@ #include "KingSystem/ActorSystem/actActorParam.h" #include "KingSystem/ActorSystem/actActorUtil.h" #include "KingSystem/ActorSystem/actAiAction.h" +#include "KingSystem/ActorSystem/actAiClassDef.h" +#include "KingSystem/ActorSystem/actAiInlineParam.h" #include "KingSystem/ActorSystem/actAiRoot.h" #include "KingSystem/ActorSystem/aiDummyAi.h" #include "KingSystem/Resource/resResourceAIProgram.h" diff --git a/src/KingSystem/ActorSystem/actAiClassDef.cpp b/src/KingSystem/ActorSystem/actAiClassDef.cpp index 873b0efa..378d2248 100644 --- a/src/KingSystem/ActorSystem/actAiClassDef.cpp +++ b/src/KingSystem/ActorSystem/actAiClassDef.cpp @@ -3,6 +3,7 @@ #include #include #include +#include "KingSystem/ActorSystem/actAiParam.h" #include "KingSystem/Resource/resLoadRequest.h" #include "KingSystem/Utils/Byaml/ByamlData.h" #include "KingSystem/Utils/Byaml/ByamlHashIter.h" diff --git a/src/KingSystem/ActorSystem/actAiClassDef.h b/src/KingSystem/ActorSystem/actAiClassDef.h index 2d5756b1..1b74f4f4 100644 --- a/src/KingSystem/ActorSystem/actAiClassDef.h +++ b/src/KingSystem/ActorSystem/actAiClassDef.h @@ -40,21 +40,7 @@ constexpr bool paramKindHasValue(AIDefInstParamKind kind) { constexpr s32 NumAIDefInstParamKinds = 4; -enum class AIDefParamType { - String = 0, - Int = 1, - Float = 2, - Vec3 = 3, - Bool = 4, - Tree = 5, - AITreeVariablePointer = 6, - UInt = 7, - BaseProcLink = 8, - MesTransceiverId = 9, - BaseProcHandle = 10, - Rail = 11, - Other = 12, -}; +enum class AIDefParamType; enum class CalcTiming { AIAfter = 0, diff --git a/src/KingSystem/ActorSystem/actAiInlineParam.h b/src/KingSystem/ActorSystem/actAiInlineParam.h new file mode 100644 index 00000000..06b38ba8 --- /dev/null +++ b/src/KingSystem/ActorSystem/actAiInlineParam.h @@ -0,0 +1,85 @@ +#pragma once + +#include +#include +#include + +#include "KingSystem/ActorSystem/actAiClassDef.h" +#include "KingSystem/ActorSystem/actBaseProcLink.h" +#include "KingSystem/Utils/Thread/MessageTransceiverId.h" +#include "KingSystem/Utils/Types.h" + +namespace ksys { + +class Rail; + +namespace act { +class Actor; +class BaseProc; +} // namespace act + +namespace act::ai { + +struct InlineParam { + union { + bool b; + int i; + u32 u; + float f; + const char* cstr; + void* ptr; + }; + BaseProcLink baseProcLink; + sead::Vector3f vec3; + MesTransceiverId mesTransceiverId; + AIDefParamType type; + const char* key; +}; +KSYS_CHECK_SIZE_NX150(InlineParam, 0x50); + +struct InlineParamPack { + InlineParamPack() = default; + + InlineParam& getParam(s32 idx) { + if (idx < 0) { + idx = count; + if (count > NumParamsMax - 1) + idx = 0; + else + count = idx + 1; + } + return params[idx]; + } + + s32 findIndex(const sead::SafeString& name, AIDefParamType type) const { + for (s32 i = 0; i < count; ++i) { + if (params[i].type == type && name == params[i].key) + return i; + } + return -1; + } + + void addString(const char* value, const sead::SafeString& key, s32 idx); + void addString(const sead::SafeString& value, const sead::SafeString& key, s32 idx) { + addString(value.cstr(), key, idx); + } + void addInt(s32 value, const sead::SafeString& key, s32 idx); + void addFloat(f32 value, const sead::SafeString& key, s32 idx); + void addVec3(const sead::Vector3f& value, const sead::SafeString& key, s32 idx); + void addBool(bool value, const sead::SafeString& key, s32 idx); + void addUInt(u32 value, const sead::SafeString& key, s32 idx); + void addActor(const BaseProcLink& value, const sead::SafeString& key, s32 idx); + void addMesTransceiverId(const MesTransceiverId& value, const sead::SafeString& key, s32 idx); + void addPointer(void* value, const sead::SafeString& key, AIDefParamType type, s32 idx); + void acquireActor(BaseProc* proc, const sead::SafeString& key, s32 idx); + void copyToParamPack(ParamPack& pack) const; + + static constexpr s32 NumParamsMax = 32; + InlineParam params[NumParamsMax]; + int count = 0; +}; +KSYS_CHECK_SIZE_NX150(InlineParamPack, 0xA08); + +} // namespace act::ai + +} // namespace ksys diff --git a/src/KingSystem/ActorSystem/actAiParam.cpp b/src/KingSystem/ActorSystem/actAiParam.cpp index c182fce4..5fdcd395 100644 --- a/src/KingSystem/ActorSystem/actAiParam.cpp +++ b/src/KingSystem/ActorSystem/actAiParam.cpp @@ -1,5 +1,8 @@ #include "KingSystem/ActorSystem/actAiParam.h" +#include #include "KingSystem/ActorSystem/actActor.h" +#include "KingSystem/ActorSystem/actAiClassDef.h" +#include "KingSystem/ActorSystem/actAiInlineParam.h" namespace ksys::act { class BaseProcHandle; @@ -58,6 +61,22 @@ ParamPack::~ParamPack() { } } +template +T* ParamPack::getVariable(const sead::SafeString& key, AIDefParamType type, bool a4) const { + const u32 hash = agl::utl::ParameterBase::calcHash(key); + auto* param = mParams; + if (!param) + return nullptr; + while (param->hash != hash || param->type != type) { + param = param->next; + if (!param) + return nullptr; + } + if (a4) + param->used = true; + return static_cast(param->data); +} + bool ParamPack::load(const Actor& actor, const ParamNameTypePairs& pairs, s32 count, sead::Heap* heap) { AIDef def; diff --git a/src/KingSystem/ActorSystem/actAiParam.h b/src/KingSystem/ActorSystem/actAiParam.h index abab0b05..5644b56c 100644 --- a/src/KingSystem/ActorSystem/actAiParam.h +++ b/src/KingSystem/ActorSystem/actAiParam.h @@ -1,26 +1,40 @@ #pragma once -#include #include #include -#include #include #include -#include "KingSystem/ActorSystem/actAiClassDef.h" -#include "KingSystem/ActorSystem/actBaseProcLink.h" -#include "KingSystem/Utils/Thread/MessageTransceiverId.h" #include "KingSystem/Utils/Types.h" namespace ksys { -class Rail; - namespace act { class Actor; class BaseProc; +class BaseProcLink; } // namespace act +struct AIDef; +class Rail; +enum class AIDefInstParamKind; + +enum class AIDefParamType { + String = 0, + Int = 1, + Float = 2, + Vec3 = 3, + Bool = 4, + Tree = 5, + AITreeVariablePointer = 6, + UInt = 7, + BaseProcLink = 8, + MesTransceiverId = 9, + BaseProcHandle = 10, + Rail = 11, + Other = 12, +}; + namespace act::ai { struct InlineParamPack; @@ -57,20 +71,7 @@ public: ~ParamPack(); template - T* getVariable(const sead::SafeString& key, AIDefParamType type, bool a4 = true) const { - const u32 hash = agl::utl::ParameterBase::calcHash(key); - auto* param = mParams; - if (!param) - return nullptr; - while (param->hash != hash || param->type != type) { - param = param->next; - if (!param) - return nullptr; - } - if (a4) - param->used = true; - return static_cast(param->data); - } + T* getVariable(const sead::SafeString& key, AIDefParamType type, bool a4 = true) const; template void setVariable(const sead::SafeString& key, AIDefParamType type, const T& val) const { @@ -112,66 +113,6 @@ private: Param* mParams = nullptr; }; -struct InlineParam { - union { - bool b; - int i; - u32 u; - float f; - const char* cstr; - void* ptr; - }; - BaseProcLink baseProcLink; - sead::Vector3f vec3; - MesTransceiverId mesTransceiverId; - AIDefParamType type; - const char* key; -}; -KSYS_CHECK_SIZE_NX150(InlineParam, 0x50); - -struct InlineParamPack { - InlineParamPack() = default; - - InlineParam& getParam(s32 idx) { - if (idx < 0) { - idx = count; - if (count > NumParamsMax - 1) - idx = 0; - else - count = idx + 1; - } - return params[idx]; - } - - s32 findIndex(const sead::SafeString& name, AIDefParamType type) const { - for (s32 i = 0; i < count; ++i) { - if (params[i].type == type && name == params[i].key) - return i; - } - return -1; - } - - void addString(const char* value, const sead::SafeString& key, s32 idx); - void addString(const sead::SafeString& value, const sead::SafeString& key, s32 idx) { - addString(value.cstr(), key, idx); - } - void addInt(s32 value, const sead::SafeString& key, s32 idx); - void addFloat(f32 value, const sead::SafeString& key, s32 idx); - void addVec3(const sead::Vector3f& value, const sead::SafeString& key, s32 idx); - void addBool(bool value, const sead::SafeString& key, s32 idx); - void addUInt(u32 value, const sead::SafeString& key, s32 idx); - void addActor(const BaseProcLink& value, const sead::SafeString& key, s32 idx); - void addMesTransceiverId(const MesTransceiverId& value, const sead::SafeString& key, s32 idx); - void addPointer(void* value, const sead::SafeString& key, AIDefParamType type, s32 idx); - void acquireActor(BaseProc* proc, const sead::SafeString& key, s32 idx); - void copyToParamPack(ParamPack& pack) const; - - static constexpr s32 NumParamsMax = 32; - InlineParam params[NumParamsMax]; - int count = 0; -}; -KSYS_CHECK_SIZE_NX150(InlineParamPack, 0xA08); - } // namespace act::ai } // namespace ksys diff --git a/src/KingSystem/ActorSystem/actAiQuery.cpp b/src/KingSystem/ActorSystem/actAiQuery.cpp index 5f2eb9bf..5a1a0ccc 100644 --- a/src/KingSystem/ActorSystem/actAiQuery.cpp +++ b/src/KingSystem/ActorSystem/actAiQuery.cpp @@ -1,6 +1,7 @@ #include "KingSystem/ActorSystem/actAiQuery.h" #include "KingSystem/ActorSystem/actActor.h" #include "KingSystem/ActorSystem/actActorParam.h" +#include "KingSystem/ActorSystem/actAiClassDef.h" #include "KingSystem/ActorSystem/actAiRoot.h" #include "KingSystem/Resource/resResourceAIProgram.h" diff --git a/src/KingSystem/ActorSystem/actAiRoot.cpp b/src/KingSystem/ActorSystem/actAiRoot.cpp index 85da4dff..0aa8f4ac 100644 --- a/src/KingSystem/ActorSystem/actAiRoot.cpp +++ b/src/KingSystem/ActorSystem/actAiRoot.cpp @@ -1,5 +1,6 @@ #include "KingSystem/ActorSystem/actAiRoot.h" #include "KingSystem/ActorSystem/actActor.h" +#include "KingSystem/ActorSystem/actAiClassDef.h" #include "KingSystem/Utils/InitTimeInfo.h" namespace ksys::act::ai { diff --git a/src/KingSystem/ActorSystem/actAiRoot.h b/src/KingSystem/ActorSystem/actAiRoot.h index dd5360c5..f57a7081 100644 --- a/src/KingSystem/ActorSystem/actAiRoot.h +++ b/src/KingSystem/ActorSystem/actAiRoot.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include "KingSystem/ActorSystem/actAiAction.h" #include "KingSystem/ActorSystem/actAiAi.h" #include "KingSystem/ActorSystem/actAiBehavior.h"