mirror of
https://github.com/zeldaret/botw
synced 2026-06-01 09:47:27 -04:00
ksys/act: Finish BaseProcUnit
This commit is contained in:
@@ -8,48 +8,118 @@
|
||||
|
||||
namespace ksys::act {
|
||||
|
||||
// NON_MATCHING: Equivalent but branches are off.
|
||||
bool BaseProcUnit::deleteProc(u32, BaseProcHandle* handle) {
|
||||
ActorLinkConstDataAccess accessor;
|
||||
|
||||
{
|
||||
const auto lock = sead::makeScopedLock(mCS);
|
||||
BaseProcHandle* current_handle = mHandle;
|
||||
if (current_handle == handle) {
|
||||
if (mProc)
|
||||
accessor.acquire(mProc);
|
||||
|
||||
if (mStatus == Status::_1 || mProc) {
|
||||
mHandle.compareExchange(handle, &BaseProcHandle::sDummyHandle);
|
||||
} else {
|
||||
mStatus = Status::Unused;
|
||||
mHandle = nullptr;
|
||||
}
|
||||
} else {
|
||||
sead::FixedSafeString<256> message;
|
||||
message.format("BaseProcUnit:(%p, %p), 呼び出し(%p)", this, current_handle, handle);
|
||||
util::PrintDebug(message);
|
||||
}
|
||||
}
|
||||
|
||||
if (accessor.hasProc())
|
||||
accessor.mProc->deleteLater(BaseProc::DeleteReason::_2);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BaseProcUnit::setProc(BaseProc* proc) {
|
||||
bool ret;
|
||||
static constexpr const char* sStateNames[] = {"Init", "Calc", "Sleep", "Delete"};
|
||||
|
||||
auto lock = sead::makeScopedLock(mCS);
|
||||
|
||||
if (mProc)
|
||||
mProc = nullptr;
|
||||
|
||||
if (mHandle == &BaseProcHandle::sDummyHandle)
|
||||
if (isParentHandleDefault())
|
||||
return false;
|
||||
|
||||
if (mHandle) {
|
||||
if (mFlags != 1) {
|
||||
sead::FixedSafeString<64> message;
|
||||
|
||||
if (proc)
|
||||
message.format("%s, %d, %d, %s, ( %p:%p )", proc->getName().cstr(), mFlags,
|
||||
proc->isInitialized(), sStateNames[u8(proc->getState())], this,
|
||||
mHandle.load());
|
||||
else
|
||||
message.format("なし, %d, ?, ?, ( %p:%p )", mFlags, this, mHandle.load());
|
||||
|
||||
util::PrintDebug(message);
|
||||
}
|
||||
mProc = proc;
|
||||
mFlags = 2;
|
||||
ret = true;
|
||||
} else {
|
||||
const auto print_info = [&] {
|
||||
sead::FixedSafeString<64> message;
|
||||
|
||||
if (proc)
|
||||
message.format("%s, %d, %d, %s, ( %p:%p )", proc->getName().cstr(), mFlags,
|
||||
if (proc) {
|
||||
message.format("%s, %d, %d, %s, ( %p:%p )", proc->getName().cstr(), u32(mStatus.load()),
|
||||
proc->isInitialized(), sStateNames[u8(proc->getState())], this,
|
||||
mHandle.load());
|
||||
else
|
||||
message.format("なし, %d, ?, ?, ( %p:%p )", mFlags, this, mHandle.load());
|
||||
|
||||
} else {
|
||||
message.format("なし, %d, ?, ?, ( %p:%p )", u32(mStatus.load()), this, mHandle.load());
|
||||
}
|
||||
util::PrintDebug(message);
|
||||
ret = false;
|
||||
};
|
||||
|
||||
if (!mHandle) {
|
||||
print_info();
|
||||
return false;
|
||||
}
|
||||
return ret;
|
||||
|
||||
if (mStatus != Status::_1)
|
||||
print_info();
|
||||
|
||||
mProc = proc;
|
||||
mStatus = Status::Ready;
|
||||
return true;
|
||||
}
|
||||
|
||||
void BaseProcUnit::reset() {
|
||||
auto* handle = getHandle();
|
||||
if (handle != &BaseProcHandle::sDummyHandle) {
|
||||
sead::FixedSafeString<256> message;
|
||||
message.format("BaseProcUnit:%p, %p", this, handle);
|
||||
util::PrintDebug(message);
|
||||
}
|
||||
mProc = nullptr;
|
||||
mStatus = Status::Unused;
|
||||
mHandle = nullptr;
|
||||
}
|
||||
|
||||
void BaseProcUnit::cleanUp(BaseProc* proc, bool set_status_5) {
|
||||
const auto lock = sead::makeScopedLock(mCS);
|
||||
|
||||
mProc = nullptr;
|
||||
|
||||
const auto print_info = [&] {
|
||||
sead::FixedSafeString<64> message;
|
||||
message.format("%d, ( %p:%p )", u32(mStatus.load()), this, mHandle.load());
|
||||
util::PrintDebug(message);
|
||||
};
|
||||
|
||||
if (isParentHandleDefault()) {
|
||||
reset();
|
||||
} else if (!mHandle) {
|
||||
print_info();
|
||||
} else {
|
||||
const auto status = mStatus.load();
|
||||
if (status == Status::Unused || (status > Status::_3 && status != Status::_5))
|
||||
print_info();
|
||||
mStatus = set_status_5 ? Status::_5 : Status::_3;
|
||||
}
|
||||
}
|
||||
|
||||
void BaseProcUnit::unlinkProc(BaseProc* proc) {
|
||||
const auto lock = sead::makeScopedLock(mCS);
|
||||
|
||||
if (mProc != proc && mProc != nullptr) {
|
||||
sead::FixedSafeString<256> message;
|
||||
message.format("BaseProcUnit:(%p:%p), BaseProc:(%s:%p), 残りBaseProc(%s:%p)", this,
|
||||
mHandle.load(), proc->getName().cstr(), proc, mProc->getName().cstr(),
|
||||
mProc);
|
||||
util::PrintDebug(message);
|
||||
}
|
||||
|
||||
reset();
|
||||
}
|
||||
|
||||
bool BaseProcUnit::isParentHandleDefault() const {
|
||||
|
||||
Reference in New Issue
Block a user