mirror of
https://github.com/zeldaret/botw
synced 2026-06-05 11:17:48 -04:00
ksys/act: Add BaseProcJob utilities
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user