summaryrefslogtreecommitdiff
path: root/src/KingSystem/ActorSystem
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 /src/KingSystem/ActorSystem
parent255677ebe2da822b51b2c1608cb66a7855b6dd7d (diff)
ksys/act: Add BaseProcJob utilities
Diffstat (limited to 'src/KingSystem/ActorSystem')
-rw-r--r--src/KingSystem/ActorSystem/actBaseProcJob.cpp68
-rw-r--r--src/KingSystem/ActorSystem/actBaseProcJob.h21
2 files changed, 89 insertions, 0 deletions
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