diff --git a/data/uking_functions.csv b/data/uking_functions.csv index c724da38..7d17549e 100644 --- a/data/uking_functions.csv +++ b/data/uking_functions.csv @@ -91855,15 +91855,15 @@ 0x00000071011c020c,sub_71011C020C,92, 0x00000071011c0268,sub_71011C0268,8,_ZNK4sead10IDelegate1IPN4ksys4util14StrTreeMapNodeEE9isNoDummyEv 0x00000071011c0270,sub_71011C0270,8,_ZNK4sead10IDelegate1IPN4ksys4util14StrTreeMapNodeEE5cloneEPNS_4HeapE -0x00000071011c0278,sub_71011C0278,32, +0x00000071011c0278,sub_71011C0278,32,_GLOBAL__sub_I_actBaseProcJob.cpp 0x00000071011c0298,ActorJobLink::ctor,32,_ZN4ksys3act15BaseProcJobLinkC1EPNS0_8BaseProcEh -0x00000071011c02b8,ActorJobListsForPriority::getJobFromFront,52, -0x00000071011c02ec,ActorJobListsForPriority::getTotalNumberOfJobs,16, -0x00000071011c02fc,ActorJobLists::pushJob,236, -0x00000071011c03e8,ActorJobLists::eraseJob,72, -0x00000071011c0430,ActorJobLists::getJobWithTopPriority,332, -0x00000071011c057c,ActorJobLists::getNextJobWithTopPriority,848, -0x00000071011c08cc,ActorJobLists::getNextJob,140, +0x00000071011c02b8,ActorJobListsForPriority::getJobFromFront,52,_ZNK4ksys3act15BaseProcJobList5frontEv +0x00000071011c02ec,ActorJobListsForPriority::getTotalNumberOfJobs,16,_ZNK4ksys3act15BaseProcJobList4sizeEv +0x00000071011c02fc,ActorJobLists::pushJob,236,_ZN4ksys3act16BaseProcJobLists7pushJobERNS0_15BaseProcJobLinkE +0x00000071011c03e8,ActorJobLists::eraseJob,72,_ZN4ksys3act16BaseProcJobLists8eraseJobERNS0_15BaseProcJobLinkE +0x00000071011c0430,ActorJobLists::getJobWithTopPriority,332,_ZNK4ksys3act16BaseProcJobLists21getJobWithTopPriorityEv +0x00000071011c057c,ActorJobLists::getNextJobWithTopPriority,848,_ZNK4ksys3act16BaseProcJobLists25getNextJobWithTopPriorityEPNS0_15BaseProcJobLinkE +0x00000071011c08cc,ActorJobLists::getNextJob,140,_ZNK4ksys3act16BaseProcJobLists10getNextJobEPNS0_15BaseProcJobLinkE 0x00000071011c0958,sub_71011C0958,100,_ZN4ksys3act15BaseProcHeapMgr18SingletonDisposer_D2Ev 0x00000071011c09bc,sub_71011C09BC,108,_ZN4ksys3act15BaseProcHeapMgr18SingletonDisposer_D0Ev 0x00000071011c0a28,BaseProcMgr::Struct2::createInstance,152,_ZN4ksys3act15BaseProcHeapMgr14createInstanceEPN4sead4HeapE diff --git a/lib/sead b/lib/sead index f85c9358..a88c0975 160000 --- a/lib/sead +++ b/lib/sead @@ -1 +1 @@ -Subproject commit f85c9358c5f043bd5e6febecd5c31f55e7f5018e +Subproject commit a88c0975cef13aa1ace83d9a829df963da1594e3 diff --git a/src/KingSystem/ActorSystem/actBaseProcJob.cpp b/src/KingSystem/ActorSystem/actBaseProcJob.cpp index 2b3801fa..6e23eec2 100644 --- a/src/KingSystem/ActorSystem/actBaseProcJob.cpp +++ b/src/KingSystem/ActorSystem/actBaseProcJob.cpp @@ -1,9 +1,77 @@ #include "KingSystem/ActorSystem/actBaseProcJob.h" +#include "KingSystem/Utils/InitTimeInfo.h" namespace ksys::act { +static util::InitTimeInfo sInfo; + BaseProcJobLink::BaseProcJobLink(BaseProc* proc, u8 priority) : TListNode(proc), mPriority(priority), mNewPriority(priority), mPriority2(3), mNewPriority2(3) {} +sead::TListNode* BaseProcJobList::front() const { + for (const auto& list : lists) { + if (list.size() >= 1 && list.front()) + return list.front(); + } + return nullptr; +} + +sead::TListNode* BaseProcJobList::next(BaseProcJobLink* link) const { + if (auto* next = lists[link->getPriority2() >> 1].next(link)) + return next; + + for (int i = (link->getPriority2() >> 1) + 1; i < lists.size(); ++i) { + if (lists[i].size() >= 1 && lists[i].front()) + return lists[i].front(); + } + + return nullptr; +} + +int BaseProcJobList::size() const { + return lists[0].size() + lists[1].size(); +} + +void BaseProcJobLists::pushJob(BaseProcJobLink& link) { + if (link.isLinked()) + return; + + auto& list = mLists[link.getPriority()].lists[link.getPriority2() >> 1]; + if (link.getPriority2() % 2 == 0) + list.pushFront(&link); + else + list.pushBack(&link); +} + +void BaseProcJobLists::eraseJob(BaseProcJobLink& link) { + if (link.isLinked()) + link.erase(); +} + +sead::TListNode* BaseProcJobLists::getJobWithTopPriority() const { + for (const auto& list : mLists) { + if (auto* result = list.front()) + return result; + } + return nullptr; +} + +sead::TListNode* +BaseProcJobLists::getNextJobWithTopPriority(BaseProcJobLink* link) const { + if (auto* next = getNextJob(link)) + return next; + + for (u32 i = link->getPriority() + 1; i < u32(mLists.size()); ++i) { + if (auto* next = mLists[i].front()) + return next; + } + + return nullptr; +} + +sead::TListNode* BaseProcJobLists::getNextJob(BaseProcJobLink* link) const { + return mLists[link->getPriority()].next(link); +} + } // namespace ksys::act diff --git a/src/KingSystem/ActorSystem/actBaseProcJob.h b/src/KingSystem/ActorSystem/actBaseProcJob.h index be5a219d..e598442d 100644 --- a/src/KingSystem/ActorSystem/actBaseProcJob.h +++ b/src/KingSystem/ActorSystem/actBaseProcJob.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include "KingSystem/Utils/Types.h" @@ -50,4 +51,24 @@ private: }; KSYS_CHECK_SIZE_NX150(BaseProcJobLink, 0x28); +struct BaseProcJobList { + sead::TListNode* front() const; + sead::TListNode* next(BaseProcJobLink* link) const; + int size() const; + + sead::SafeArray, 2> lists; +}; + +class BaseProcJobLists { +public: + void pushJob(BaseProcJobLink& link); + void eraseJob(BaseProcJobLink& link); + sead::TListNode* getJobWithTopPriority() const; + sead::TListNode* getNextJobWithTopPriority(BaseProcJobLink* link) const; + sead::TListNode* getNextJob(BaseProcJobLink* link) const; + +private: + sead::SafeArray mLists; +}; + } // namespace ksys::act