summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLéo Lam <leo@leolam.fr>2021-02-07 19:35:45 +0100
committerLéo Lam <leo@leolam.fr>2021-02-13 12:24:13 +0100
commita1f5a6ed74cbe97e09ffd061640ca7fa30616422 (patch)
tree086812da6c6de407906efff1bc948c1a029e82a5
parent255677ebe2da822b51b2c1608cb66a7855b6dd7d (diff)
ksys/act: Add BaseProcJob utilities
-rw-r--r--data/uking_functions.csv16
m---------lib/sead0
-rw-r--r--src/KingSystem/ActorSystem/actBaseProcJob.cpp68
-rw-r--r--src/KingSystem/ActorSystem/actBaseProcJob.h21
4 files changed, 97 insertions, 8 deletions
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
-Subproject f85c9358c5f043bd5e6febecd5c31f55e7f5018
+Subproject a88c0975cef13aa1ace83d9a829df963da1594e
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<BaseProc*>* BaseProcJobList::front() const {
+ for (const auto& list : lists) {
+ if (list.size() >= 1 && list.front())
+ return list.front();
+ }
+ return nullptr;
+}
+
+sead::TListNode<BaseProc*>* 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<BaseProc*>* BaseProcJobLists::getJobWithTopPriority() const {
+ for (const auto& list : mLists) {
+ if (auto* result = list.front())
+ return result;
+ }
+ return nullptr;
+}
+
+sead::TListNode<BaseProc*>*
+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<BaseProc*>* 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 <container/seadSafeArray.h>
#include <container/seadTList.h>
#include "KingSystem/Utils/Types.h"
@@ -50,4 +51,24 @@ private:
};
KSYS_CHECK_SIZE_NX150(BaseProcJobLink, 0x28);
+struct BaseProcJobList {
+ sead::TListNode<BaseProc*>* front() const;
+ sead::TListNode<BaseProc*>* next(BaseProcJobLink* link) const;
+ int size() const;
+
+ sead::SafeArray<sead::TList<BaseProc*>, 2> lists;
+};
+
+class BaseProcJobLists {
+public:
+ void pushJob(BaseProcJobLink& link);
+ void eraseJob(BaseProcJobLink& link);
+ sead::TListNode<BaseProc*>* getJobWithTopPriority() const;
+ sead::TListNode<BaseProc*>* getNextJobWithTopPriority(BaseProcJobLink* link) const;
+ sead::TListNode<BaseProc*>* getNextJob(BaseProcJobLink* link) const;
+
+private:
+ sead::SafeArray<BaseProcJobList, 8> mLists;
+};
+
} // namespace ksys::act