diff options
| author | Léo Lam <leo@leolam.fr> | 2020-12-21 15:49:50 +0100 |
|---|---|---|
| committer | Léo Lam <leo@leolam.fr> | 2020-12-21 15:50:21 +0100 |
| commit | 258bfd057a3277dfba009a1db80bcd5e6404bdc5 (patch) | |
| tree | 7a61f3fac772ed5f3cb726151367b15e7c9299ac /src | |
| parent | 62014b715b65d207448bcf94cad2421ac4679087 (diff) | |
ksys/act: Give better names to ActionBase/Actions functions
And get rid of Ais::clone, which is unused.
Diffstat (limited to 'src')
| -rw-r--r-- | src/KingSystem/ActorSystem/actAiAction.cpp | 68 | ||||
| -rw-r--r-- | src/KingSystem/ActorSystem/actAiAction.h | 17 | ||||
| -rw-r--r-- | src/KingSystem/ActorSystem/actAiActionBase.h | 8 | ||||
| -rw-r--r-- | src/KingSystem/ActorSystem/actAiAi.cpp | 95 | ||||
| -rw-r--r-- | src/KingSystem/ActorSystem/actAiAi.h | 18 |
5 files changed, 94 insertions, 112 deletions
diff --git a/src/KingSystem/ActorSystem/actAiAction.cpp b/src/KingSystem/ActorSystem/actAiAction.cpp index 0f973f9f..0f87ac9f 100644 --- a/src/KingSystem/ActorSystem/actAiAction.cpp +++ b/src/KingSystem/ActorSystem/actAiAction.cpp @@ -21,16 +21,16 @@ Actions::~Actions() { } void Actions::finalize() { - for (s32 i = 0; i < classes.size(); ++i) { - if (classes[i]) { - delete classes[i]; - classes[i] = nullptr; + for (s32 i = 0; i < mClasses.size(); ++i) { + if (mClasses[i]) { + delete mClasses[i]; + mClasses[i] = nullptr; } } - predelete1_callbacks.freeBuffer(); - predelete2_callbacks.freeBuffer(); - classes.freeBuffer(); + mOnPreDeleteCbs.freeBuffer(); + mUpdateForPreDeleteCbs.freeBuffer(); + mClasses.freeBuffer(); } bool Actions::init(Actor* actor, sead::Heap* heap) { @@ -40,19 +40,19 @@ bool Actions::init(Actor* actor, sead::Heap* heap) { if (num_actions == 0) return true; - if (!classes.tryAllocBuffer(num_actions, heap)) + if (!mClasses.tryAllocBuffer(num_actions, heap)) return false; for (s32 i = 0; i < num_actions; ++i) - classes(i) = nullptr; - auto it_class = classes.begin(); - const auto it_class_end = classes.end(); + mClasses(i) = nullptr; + auto it_class = mClasses.begin(); + const auto it_class_end = mClasses.end(); Action::InitArg arg{}; arg.actor = actor; arg.def_idx = -1; arg.root_idx = -1; - s32 predelete1_callback_num = 0; - s32 predelete2_callback_num = 0; + s32 pre_delete_cb_num = 0; + s32 update_cb_num = 0; for (; it_class != it_class_end; ++it_class) { const char* name; if (it_class.getIndex() >= num_actions) { @@ -73,38 +73,38 @@ bool Actions::init(Actor* actor, sead::Heap* heap) { if (!*it_class) return false; - predelete2_callback_num += (*it_class)->m8(); - predelete1_callback_num += (*it_class)->m7(); + update_cb_num += (*it_class)->hasUpdateForPreDeleteCb(); + pre_delete_cb_num += (*it_class)->hasPreDeleteCb(); } // Allocate the callback lists. - if (predelete1_callback_num != 0) { - if (!predelete1_callbacks.tryAllocBuffer(predelete1_callback_num, heap)) + if (pre_delete_cb_num != 0) { + if (!mOnPreDeleteCbs.tryAllocBuffer(pre_delete_cb_num, heap)) return false; - for (s32 i = 0; i < predelete1_callback_num; ++i) - predelete1_callbacks(i) = nullptr; + for (s32 i = 0; i < pre_delete_cb_num; ++i) + mOnPreDeleteCbs(i) = nullptr; } - if (predelete2_callback_num != 0) { - if (!predelete2_callbacks.tryAllocBuffer(predelete2_callback_num, heap)) + if (update_cb_num != 0) { + if (!mUpdateForPreDeleteCbs.tryAllocBuffer(update_cb_num, heap)) return false; - for (s32 i = 0; i < predelete2_callback_num; ++i) - predelete2_callbacks(i) = nullptr; + for (s32 i = 0; i < update_cb_num; ++i) + mUpdateForPreDeleteCbs(i) = nullptr; } // Initialize each class. s32 idx_cb1 = 0, idx_cb2 = 0; - for (auto it = classes.begin(), end = classes.end(); it != end; ++it) { + for (auto it = mClasses.begin(), end = mClasses.end(); it != end; ++it) { if (!(*it)->init(heap, false)) return false; - if ((*it)->m8()) { - predelete2_callbacks[idx_cb2] = *it; + if ((*it)->hasUpdateForPreDeleteCb()) { + mUpdateForPreDeleteCbs[idx_cb2] = *it; ++idx_cb2; } - if ((*it)->m7()) { - predelete1_callbacks[idx_cb1] = *it; + if ((*it)->hasPreDeleteCb()) { + mOnPreDeleteCbs[idx_cb1] = *it; ++idx_cb1; } } @@ -130,19 +130,19 @@ Action* Actions::clone(const Action& action, sead::Heap* heap) { return clone; } -bool Actions::onActorPreDelete2() const { +bool Actions::updateForPreDelete() const { bool ok = true; - for (auto* action : predelete2_callbacks) { + for (auto* action : mUpdateForPreDeleteCbs) { if (action) - ok &= action->m18(); + ok &= action->updateForPreDelete(); } return ok; } -void Actions::onActorPreDelete1() const { - for (auto* action : predelete1_callbacks) { +void Actions::onPreDelete() const { + for (auto* action : mOnPreDeleteCbs) { if (action) - action->m19(); + action->onPreDelete(); } } diff --git a/src/KingSystem/ActorSystem/actAiAction.h b/src/KingSystem/ActorSystem/actAiAction.h index 9ffa28a5..634cb134 100644 --- a/src/KingSystem/ActorSystem/actAiAction.h +++ b/src/KingSystem/ActorSystem/actAiAction.h @@ -34,21 +34,22 @@ public: void finalize(); bool init(Actor* actor, sead::Heap* heap); - bool onActorPreDelete2() const; - void onActorPreDelete1() const; + bool updateForPreDelete() const; + void onPreDelete() const; + + const sead::Buffer<Action*>& getClasses() const { return mClasses; } static Action* clone(const Action& action, sead::Heap* heap); static ActionFactory* getFactory(const sead::SafeString& name); static void setFactories(int count, ActionFactory* factories); - sead::Buffer<Action*> classes; - // Non-owning buffer. - sead::Buffer<Action*> predelete1_callbacks; - // Non-owning buffer. - sead::Buffer<Action*> predelete2_callbacks; - private: static inline sead::Buffer<ActionFactory> sFactories; + sead::Buffer<Action*> mClasses; + // Non-owning buffer. + sead::Buffer<Action*> mOnPreDeleteCbs; + // Non-owning buffer. + sead::Buffer<Action*> mUpdateForPreDeleteCbs; }; } // namespace ksys::act::ai diff --git a/src/KingSystem/ActorSystem/actAiActionBase.h b/src/KingSystem/ActorSystem/actAiActionBase.h index 404771ba..a75280e4 100644 --- a/src/KingSystem/ActorSystem/actAiActionBase.h +++ b/src/KingSystem/ActorSystem/actAiActionBase.h @@ -71,8 +71,8 @@ public: virtual bool isFinished() const { return mFlags.isOn(Flag::Finished); } virtual bool isFlag4Set() const { return mFlags.isOn(Flag::_4); } - virtual bool m7() { return false; } - virtual bool m8() { return false; } + virtual bool hasPreDeleteCb() { return false; } + virtual bool hasUpdateForPreDeleteCb() { return false; } virtual void m9() {} virtual bool oneShot_() { return true; } virtual bool init_(sead::Heap* heap) { return true; } @@ -82,8 +82,8 @@ public: virtual void loadParams_() {} virtual bool m16() { return false; } virtual bool m17() { return false; } - virtual bool m18() { return true; } - virtual void m19() {} + virtual bool updateForPreDelete() { return true; } + virtual void onPreDelete() {} virtual void calc() {} virtual void getCurrentName(sead::BufferedSafeString* name, ActionBase* last) const; virtual void* m22() { return nullptr; } diff --git a/src/KingSystem/ActorSystem/actAiAi.cpp b/src/KingSystem/ActorSystem/actAiAi.cpp index 46e5bc90..f12391af 100644 --- a/src/KingSystem/ActorSystem/actAiAi.cpp +++ b/src/KingSystem/ActorSystem/actAiAi.cpp @@ -60,9 +60,9 @@ bool Ai::initChildren_(s32 num_children, const char** names, sead::Buffer<u16>& for (; it_ptr != it_ptr_end && it_idx != it_idx_end; ++it_ptr, ++it_idx) { if (*it_idx < effective_ai_count) - *it_ptr = root_ai->getAis().classes[*it_idx]; + *it_ptr = root_ai->getAis().getClasses()[*it_idx]; else - *it_ptr = root_ai->getActions().classes[*it_idx - effective_ai_count]; + *it_ptr = root_ai->getActions().getClasses()[*it_idx - effective_ai_count]; if (*it_ptr == nullptr) return false; @@ -113,16 +113,16 @@ Ais::~Ais() { } void Ais::finalize() { - for (s32 i = 0; i < classes.size(); ++i) { - if (classes[i]) { - delete classes[i]; - classes[i] = nullptr; + for (s32 i = 0; i < mClasses.size(); ++i) { + if (mClasses[i]) { + delete mClasses[i]; + mClasses[i] = nullptr; } } - predelete1_callbacks.freeBuffer(); - predelete2_callbacks.freeBuffer(); - classes.freeBuffer(); + mOnPreDeleteCbs.freeBuffer(); + mUpdateForPreDeleteCbs.freeBuffer(); + mClasses.freeBuffer(); } bool Ais::init(Actor* actor, sead::Heap* heap) { @@ -132,19 +132,19 @@ bool Ais::init(Actor* actor, sead::Heap* heap) { if (num_ais < 0) return false; - if (!classes.tryAllocBuffer(num_ais + 1, heap)) + if (!mClasses.tryAllocBuffer(num_ais + 1, heap)) return false; - for (s32 i = 0, n = classes.size(); i != n; ++i) - classes(i) = nullptr; - auto it_class = classes.begin(); - const auto it_class_end = classes.end(); + for (s32 i = 0, n = mClasses.size(); i != n; ++i) + mClasses(i) = nullptr; + auto it_class = mClasses.begin(); + const auto it_class_end = mClasses.end(); Ai::InitArg arg{}; arg.actor = actor; arg.def_idx = -1; arg.root_idx = -1; - s32 predelete1_callback_num = 0; - s32 predelete2_callback_num = 0; + s32 predelete_cb_num = 0; + s32 update_cb_num = 0; for (; it_class != it_class_end; ++it_class) { const char* name; if (it_class.getIndex() >= num_ais) { @@ -165,43 +165,43 @@ bool Ais::init(Actor* actor, sead::Heap* heap) { if (!*it_class) return false; - predelete2_callback_num += (*it_class)->m8(); - predelete1_callback_num += (*it_class)->m7(); + update_cb_num += (*it_class)->hasUpdateForPreDeleteCb(); + predelete_cb_num += (*it_class)->hasPreDeleteCb(); } // Allocate the callback lists. - if (predelete1_callback_num != 0) { - if (!predelete1_callbacks.tryAllocBuffer(predelete1_callback_num, heap)) + if (predelete_cb_num != 0) { + if (!mOnPreDeleteCbs.tryAllocBuffer(predelete_cb_num, heap)) return false; - for (s32 i = 0; i < predelete1_callback_num; ++i) - predelete1_callbacks(i) = nullptr; + for (s32 i = 0; i < predelete_cb_num; ++i) + mOnPreDeleteCbs(i) = nullptr; } - if (predelete2_callback_num != 0) { - if (!predelete2_callbacks.tryAllocBuffer(predelete2_callback_num, heap)) + if (update_cb_num != 0) { + if (!mUpdateForPreDeleteCbs.tryAllocBuffer(update_cb_num, heap)) return false; - for (s32 i = 0; i < predelete2_callback_num; ++i) - predelete2_callbacks(i) = nullptr; + for (s32 i = 0; i < update_cb_num; ++i) + mUpdateForPreDeleteCbs(i) = nullptr; } // Initialize each class. s32 idx_cb1 = 0, idx_cb2 = 0; - for (auto it = classes.begin(), end = classes.end(); it != end; ++it) { + for (auto it = mClasses.begin(), end = mClasses.end(); it != end; ++it) { if (!(*it)->init(heap, false)) return false; - if ((*it)->m8()) { - predelete2_callbacks[idx_cb2] = *it; + if ((*it)->hasUpdateForPreDeleteCb()) { + mUpdateForPreDeleteCbs[idx_cb2] = *it; ++idx_cb2; } - if ((*it)->m7()) { - predelete1_callbacks[idx_cb1] = *it; + if ((*it)->hasPreDeleteCb()) { + mOnPreDeleteCbs[idx_cb1] = *it; ++idx_cb1; } } - for (auto* ai : classes) { + for (auto* ai : mClasses) { if (!ai->gatherParamsFromChildren(heap)) return false; } @@ -209,38 +209,19 @@ bool Ais::init(Actor* actor, sead::Heap* heap) { return true; } -Ai* Ais::clone(const Ai& action, sead::Heap* heap) { - auto* factory = getFactory(action.getClassName()); - if (!factory) - return nullptr; - - Ai::InitArg arg; - arg.actor = action.getActor(); - arg.def_idx = action.getDefinitionIdx(); - auto* clone = factory->create_fn(arg, heap); - if (!clone) { - return nullptr; - } - if (!clone->init(heap, true)) { - delete clone; - return nullptr; - } - return clone; -} - -bool Ais::onActorPreDelete2() const { +bool Ais::updateForPreDelete() const { bool ok = true; - for (auto* action : predelete2_callbacks) { + for (auto* action : mUpdateForPreDeleteCbs) { if (action) - ok &= action->m18(); + ok &= action->updateForPreDelete(); } return ok; } -void Ais::onActorPreDelete1() const { - for (auto* action : predelete1_callbacks) { +void Ais::onPreDelete() const { + for (auto* action : mOnPreDeleteCbs) { if (action) - action->m19(); + action->onPreDelete(); } } diff --git a/src/KingSystem/ActorSystem/actAiAi.h b/src/KingSystem/ActorSystem/actAiAi.h index 06213208..75b1bc0c 100644 --- a/src/KingSystem/ActorSystem/actAiAi.h +++ b/src/KingSystem/ActorSystem/actAiAi.h @@ -62,21 +62,21 @@ public: void finalize(); bool init(Actor* actor, sead::Heap* heap); - bool onActorPreDelete2() const; - void onActorPreDelete1() const; + bool updateForPreDelete() const; + void onPreDelete() const; + + const sead::Buffer<Ai*>& getClasses() const { return mClasses; } - static Ai* clone(const Ai& ai, sead::Heap* heap); static AiFactory* getFactory(const sead::SafeString& name); static void setFactories(int count, AiFactory* factories); - sead::Buffer<Ai*> classes; - // Non-owning buffer. - sead::Buffer<Ai*> predelete1_callbacks; - // Non-owning buffer. - sead::Buffer<Ai*> predelete2_callbacks; - private: static inline sead::Buffer<AiFactory> sFactories; + sead::Buffer<Ai*> mClasses; + // Non-owning buffer. + sead::Buffer<Ai*> mOnPreDeleteCbs; + // Non-owning buffer. + sead::Buffer<Ai*> mUpdateForPreDeleteCbs; }; } // namespace ksys::act::ai |
