diff options
| author | Léo Lam <leo@leolam.fr> | 2021-02-07 19:35:45 +0100 |
|---|---|---|
| committer | Léo Lam <leo@leolam.fr> | 2021-02-13 12:24:13 +0100 |
| commit | a1f5a6ed74cbe97e09ffd061640ca7fa30616422 (patch) | |
| tree | 086812da6c6de407906efff1bc948c1a029e82a5 /src/KingSystem/ActorSystem/actBaseProcJob.cpp | |
| parent | 255677ebe2da822b51b2c1608cb66a7855b6dd7d (diff) | |
ksys/act: Add BaseProcJob utilities
Diffstat (limited to 'src/KingSystem/ActorSystem/actBaseProcJob.cpp')
| -rw-r--r-- | src/KingSystem/ActorSystem/actBaseProcJob.cpp | 68 |
1 files changed, 68 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 |
