mirror of
https://github.com/zeldaret/botw
synced 2026-09-08 03:16:55 -04:00
Switch to subrepos
git subrepo clone https://github.com/open-ead/sead lib/sead subrepo: subdir: "lib/sead" merged: "1b66e825d" upstream: origin: "https://github.com/open-ead/sead" branch: "master" commit: "1b66e825d" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo" commit: "2f68596" git subrepo clone (merge) https://github.com/open-ead/nnheaders lib/NintendoSDK subrepo: subdir: "lib/NintendoSDK" merged: "9ee21399f" upstream: origin: "https://github.com/open-ead/nnheaders" branch: "master" commit: "9ee21399f" git-subrepo: version: "0.4.3" origin: "ssh://git@github.com/ingydotnet/git-subrepo" commit: "2f68596" git subrepo clone https://github.com/open-ead/agl lib/agl subrepo: subdir: "lib/agl" merged: "7c063271b" upstream: origin: "https://github.com/open-ead/agl" branch: "master" commit: "7c063271b" git-subrepo: version: "0.4.3" origin: "ssh://git@github.com/ingydotnet/git-subrepo" commit: "2f68596" git subrepo clone https://github.com/open-ead/EventFlow lib/EventFlow subrepo: subdir: "lib/EventFlow" merged: "c35d21b34" upstream: origin: "https://github.com/open-ead/EventFlow" branch: "master" commit: "c35d21b34" git-subrepo: version: "0.4.3" origin: "ssh://git@github.com/ingydotnet/git-subrepo" commit: "2f68596"
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
#include "framework/seadCalculateTask.h"
|
||||
|
||||
namespace sead
|
||||
{
|
||||
CalculateTask::CalculateTask(const TaskConstructArg& arg) : TaskBase(arg)
|
||||
{
|
||||
mCalcNode.bind(sead::Delegate<CalculateTask>{this, &CalculateTask::calc}, "CalculateTask");
|
||||
}
|
||||
|
||||
CalculateTask::CalculateTask(const TaskConstructArg& arg, const char* name) : TaskBase(arg, name)
|
||||
{
|
||||
mCalcNode.bind(sead::Delegate<CalculateTask>{this, &CalculateTask::calc}, name);
|
||||
}
|
||||
|
||||
CalculateTask::~CalculateTask() = default;
|
||||
} // namespace sead
|
||||
@@ -0,0 +1,38 @@
|
||||
#include <framework/seadFramework.h>
|
||||
#include <framework/seadMethodTreeMgr.h>
|
||||
#include <framework/seadTaskMgr.h>
|
||||
#include <heap/seadHeap.h>
|
||||
|
||||
namespace sead
|
||||
{
|
||||
Framework::CreateSystemTaskArg::CreateSystemTaskArg()
|
||||
: hostio_parameter(NULL), infloop_detection_span()
|
||||
{
|
||||
}
|
||||
|
||||
Framework::Framework()
|
||||
: mReserveReset(false), mResetParameter(NULL), mResetEvent(), mTaskMgr(NULL),
|
||||
mMethodTreeMgr(NULL), mMethodTreeMgrHeap(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
Framework::~Framework()
|
||||
{
|
||||
if (mTaskMgr != NULL)
|
||||
{
|
||||
mTaskMgr->finalize();
|
||||
delete mTaskMgr;
|
||||
mTaskMgr = NULL;
|
||||
}
|
||||
|
||||
if (mMethodTreeMgr != NULL)
|
||||
{
|
||||
delete mMethodTreeMgr;
|
||||
mMethodTreeMgr = NULL;
|
||||
}
|
||||
|
||||
if (mMethodTreeMgrHeap != NULL)
|
||||
mMethodTreeMgrHeap->destroy();
|
||||
}
|
||||
|
||||
} // namespace sead
|
||||
@@ -0,0 +1,101 @@
|
||||
#include <framework/seadMethodTree.h>
|
||||
#include <thread/seadCriticalSection.h>
|
||||
|
||||
namespace sead
|
||||
{
|
||||
void MethodTreeNode::pushBackChild(MethodTreeNode* node)
|
||||
{
|
||||
lock_();
|
||||
node->detachSubTree();
|
||||
node->mCriticalSection = mCriticalSection;
|
||||
if (node->child())
|
||||
{
|
||||
auto* parent = node->child()->value();
|
||||
if (parent)
|
||||
parent->attachMutexRec_(mCriticalSection);
|
||||
}
|
||||
TreeNode::pushBackChild(node);
|
||||
unlock_();
|
||||
}
|
||||
|
||||
void MethodTreeNode::pushFrontChild(MethodTreeNode* node)
|
||||
{
|
||||
lock_();
|
||||
node->detachSubTree();
|
||||
node->mCriticalSection = mCriticalSection;
|
||||
if (node->child())
|
||||
{
|
||||
auto* parent = node->child()->value();
|
||||
if (parent)
|
||||
parent->attachMutexRec_(mCriticalSection);
|
||||
}
|
||||
TreeNode::pushFrontChild(node);
|
||||
unlock_();
|
||||
}
|
||||
|
||||
void MethodTreeNode::attachMutexRec_(CriticalSection* m) const
|
||||
{
|
||||
const MethodTreeNode* node = this;
|
||||
|
||||
do
|
||||
{
|
||||
auto* child = node->child();
|
||||
node->mCriticalSection = m;
|
||||
if (child && child->value())
|
||||
child->value()->attachMutexRec_(m);
|
||||
} while (node->next() && (node = node->next()->value()));
|
||||
}
|
||||
|
||||
void MethodTreeNode::detachAll()
|
||||
{
|
||||
CriticalSection* cs = mCriticalSection;
|
||||
attachMutexRec_(NULL);
|
||||
mCriticalSection = cs;
|
||||
|
||||
lock_();
|
||||
TreeNode::detachAll();
|
||||
unlock_();
|
||||
|
||||
mCriticalSection = NULL;
|
||||
}
|
||||
|
||||
void MethodTreeNode::lock_()
|
||||
{
|
||||
if (mCriticalSection == NULL)
|
||||
return;
|
||||
|
||||
mCriticalSection->lock();
|
||||
}
|
||||
|
||||
void MethodTreeNode::unlock_()
|
||||
{
|
||||
if (mCriticalSection == NULL)
|
||||
return;
|
||||
|
||||
mCriticalSection->unlock();
|
||||
}
|
||||
|
||||
void MethodTreeNode::call()
|
||||
{
|
||||
lock_();
|
||||
callRec_();
|
||||
unlock_();
|
||||
}
|
||||
|
||||
void MethodTreeNode::callRec_()
|
||||
{
|
||||
if (!mPauseFlag.isOn(cPause_Self))
|
||||
(*mDelegateHolder.data())();
|
||||
|
||||
auto* node = child();
|
||||
if (node && !mPauseFlag.isOn(cPause_Child))
|
||||
{
|
||||
while (node)
|
||||
{
|
||||
node->value()->callRec_();
|
||||
node = node->value()->next();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sead
|
||||
@@ -0,0 +1,151 @@
|
||||
#include "framework/seadProcessMeterBar.h"
|
||||
#include "basis/seadRawPrint.h"
|
||||
#include "framework/seadProcessMeter.h"
|
||||
|
||||
namespace sead
|
||||
{
|
||||
ProcessMeterBarBase::ProcessMeterBarBase(ProcessMeterBarBase::Section* sections, s32 num_sections,
|
||||
const SafeString& name, const Color4f& color)
|
||||
: INamable(name), mColor(color)
|
||||
{
|
||||
mSectionList(0).setBuffer(num_sections, sections);
|
||||
_88(0) = 0;
|
||||
mSectionList(1).setBuffer(num_sections, sections + num_sections);
|
||||
_88(1) = 0;
|
||||
}
|
||||
|
||||
ProcessMeterBarBase::~ProcessMeterBarBase()
|
||||
{
|
||||
if (mParent)
|
||||
mParent->detachProcessMeterBar(this);
|
||||
}
|
||||
|
||||
void ProcessMeterBarBase::measureBegin()
|
||||
{
|
||||
if (mEnabled)
|
||||
measureBeginImpl_(TickTime(), mColor);
|
||||
}
|
||||
|
||||
void ProcessMeterBarBase::measureBegin(const TickTime& start_time)
|
||||
{
|
||||
if (mEnabled)
|
||||
measureBeginImpl_(start_time, mColor);
|
||||
}
|
||||
|
||||
void ProcessMeterBarBase::measureBegin(const Color4f& color)
|
||||
{
|
||||
if (mEnabled)
|
||||
measureBeginImpl_(TickTime(), color);
|
||||
}
|
||||
|
||||
void ProcessMeterBarBase::measureBegin(const TickTime& start_time, const Color4f& color)
|
||||
{
|
||||
if (mEnabled)
|
||||
measureBeginImpl_(start_time, color);
|
||||
}
|
||||
|
||||
void ProcessMeterBarBase::measureEnd()
|
||||
{
|
||||
if (mEnabled)
|
||||
measureEndImpl_(TickTime());
|
||||
}
|
||||
|
||||
void ProcessMeterBarBase::measureEnd(const TickTime& end_time)
|
||||
{
|
||||
if (mEnabled)
|
||||
measureEndImpl_(end_time);
|
||||
}
|
||||
|
||||
const ProcessMeterBarBase::Section* ProcessMeterBarBase::getLastFirstBegin() const
|
||||
{
|
||||
return mSectionList[1 - mActiveBufferIdx].get(0);
|
||||
}
|
||||
|
||||
TickSpan ProcessMeterBarBase::getLastTotalSpan() const
|
||||
{
|
||||
TickSpan total = 0;
|
||||
for (s32 i = 0; i < _88[1 - mActiveBufferIdx]; ++i)
|
||||
{
|
||||
if (mSectionList[1 - mActiveBufferIdx].get(i)->parent == -1)
|
||||
total += mSectionList[1 - mActiveBufferIdx].get(i)->span;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
void ProcessMeterBarBase::onEndFrame()
|
||||
{
|
||||
SEAD_ASSERT(mTopSection == -1);
|
||||
SEAD_ASSERT(mOverNum == 0);
|
||||
mActiveBufferIdx = 1 - mActiveBufferIdx;
|
||||
mTopSection = -1;
|
||||
mOverNum = 0;
|
||||
_88[mActiveBufferIdx] = 0;
|
||||
mEnabled = mParent != nullptr;
|
||||
}
|
||||
|
||||
void ProcessMeterBarBase::setParentProcessMeter(ProcessMeter* parent)
|
||||
{
|
||||
SEAD_ASSERT(mParent == nullptr || parent == nullptr);
|
||||
mParent = parent;
|
||||
}
|
||||
|
||||
void ProcessMeterBarBase::measureBeginImpl_(const TickTime& start_time, Color4f color)
|
||||
{
|
||||
addSection_(start_time, color, mTopSection);
|
||||
}
|
||||
|
||||
void ProcessMeterBarBase::measureEndImpl_(const TickTime& end_time)
|
||||
{
|
||||
TickTime new_time = end_time;
|
||||
mTicks[mActiveBufferIdx] = new_time;
|
||||
|
||||
if (mOverNum > 0)
|
||||
{
|
||||
--mOverNum;
|
||||
}
|
||||
else
|
||||
{
|
||||
TickTime t = getCurSection_(mTopSection)->time;
|
||||
if (new_time.diff(t).toS64() < 0)
|
||||
new_time = t;
|
||||
|
||||
SEAD_ASSERT_MSG(mTopSection >= 0, "Unmatching measureBegin / measureEnd.");
|
||||
endSection_(mTopSection, new_time);
|
||||
mTopSection = getCurSection_(mTopSection)->parent;
|
||||
}
|
||||
}
|
||||
|
||||
// NON_MATCHING: some stores are paired
|
||||
void ProcessMeterBarBase::addSection_(const TickTime& time, Color4f color, s32 parent)
|
||||
{
|
||||
if (_88[mActiveBufferIdx] >= mSectionList[0].getSize())
|
||||
{
|
||||
++mOverNum;
|
||||
}
|
||||
else
|
||||
{
|
||||
Section* sec = getCurSection_(_88[mActiveBufferIdx]);
|
||||
sec->time = time;
|
||||
sec->span = -1;
|
||||
sec->color = color;
|
||||
sec->parent = parent;
|
||||
|
||||
mTopSection = _88[mActiveBufferIdx];
|
||||
++_88[mActiveBufferIdx];
|
||||
}
|
||||
}
|
||||
|
||||
ProcessMeterBarBase::Section* ProcessMeterBarBase::getCurSection_(s32 idx)
|
||||
{
|
||||
SEAD_ASSERT(idx >= 0 && idx < mSectionList[0].getSize());
|
||||
return mSectionList[mActiveBufferIdx].get(idx);
|
||||
}
|
||||
|
||||
void ProcessMeterBarBase::endSection_(s32 idx, const TickTime& time)
|
||||
{
|
||||
SEAD_ASSERT(idx >= 0 && idx < mSectionList[0].getSize());
|
||||
Section* sec = getCurSection_(idx);
|
||||
SEAD_ASSERT(sec->span.toS64() == -1);
|
||||
sec->span = time.diff(sec->time);
|
||||
}
|
||||
} // namespace sead
|
||||
@@ -0,0 +1,150 @@
|
||||
#include <framework/seadFramework.h>
|
||||
#include <framework/seadMethodTreeMgr.h>
|
||||
#include <framework/seadTaskBase.h>
|
||||
#include <framework/seadTaskMgr.h>
|
||||
#include <prim/seadSafeString.h>
|
||||
#include <resource/seadResourceMgr.h>
|
||||
#include <thread/seadDelegateThread.h>
|
||||
|
||||
namespace sead
|
||||
{
|
||||
bool TaskMgr::changeTaskState_(TaskBase* task, TaskBase::State state)
|
||||
{
|
||||
mCriticalSection.lock();
|
||||
|
||||
if (task->mState != state)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case TaskBase::cPrepare:
|
||||
if (task->mState == TaskBase::cCreated)
|
||||
{
|
||||
task->mState = TaskBase::cPrepare;
|
||||
appendToList_(mPrepareList, task);
|
||||
|
||||
if (mPrepareThread == NULL || mPrepareThread->sendMessage(1, 1))
|
||||
{
|
||||
mCriticalSection.unlock();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case TaskBase::cPrepareDone:
|
||||
task->mState = TaskBase::cPrepareDone;
|
||||
task->mTaskListNode.erase();
|
||||
|
||||
mCriticalSection.unlock();
|
||||
return true;
|
||||
|
||||
case TaskBase::cRunning:
|
||||
task->mState = TaskBase::cRunning;
|
||||
task->mTaskListNode.erase();
|
||||
appendToList_(mActiveList, task);
|
||||
|
||||
if (ResourceMgr::instance() != NULL)
|
||||
ResourceMgr::instance()->postCreate();
|
||||
|
||||
task->enterCommon();
|
||||
|
||||
mCriticalSection.unlock();
|
||||
return true;
|
||||
|
||||
case TaskBase::cDying:
|
||||
task->mState = TaskBase::cDying;
|
||||
|
||||
mCriticalSection.unlock();
|
||||
return true;
|
||||
|
||||
case TaskBase::cDestroyable:
|
||||
if (task->mState == TaskBase::cRunning)
|
||||
{
|
||||
task->mState = TaskBase::cDestroyable;
|
||||
task->detachCalcImpl();
|
||||
task->detachDrawImpl();
|
||||
appendToList_(mDestroyableList, task);
|
||||
|
||||
mCriticalSection.unlock();
|
||||
return true;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case TaskBase::cDead:
|
||||
task->exit();
|
||||
task->mState = TaskBase::cDead;
|
||||
task->mTaskListNode.erase();
|
||||
|
||||
mCriticalSection.unlock();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
mCriticalSection.unlock();
|
||||
return false;
|
||||
}
|
||||
|
||||
void TaskMgr::destroyTaskSync(TaskBase* task)
|
||||
{
|
||||
if (mParentFramework->mMethodTreeMgr->mCS.tryLock())
|
||||
{
|
||||
doDestroyTask_(task);
|
||||
mParentFramework->mMethodTreeMgr->mCS.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
void TaskMgr::doDestroyTask_(TaskBase* task)
|
||||
{
|
||||
mCriticalSection.lock();
|
||||
|
||||
TreeNode* node = task->mChild;
|
||||
while (node != NULL)
|
||||
{
|
||||
doDestroyTask_(static_cast<TTreeNode<TaskBase*>*>(node)->mData);
|
||||
node = task->mChild;
|
||||
}
|
||||
|
||||
if (changeTaskState_(task, TaskBase::cDead))
|
||||
{
|
||||
task->detachAll();
|
||||
|
||||
HeapArray heapArray(task->mHeapArray);
|
||||
for (s32 i = 0; i < HeapMgr::sRootHeaps.mPtrNum; i++)
|
||||
{
|
||||
Heap* heap = heapArray.mHeaps[i];
|
||||
if (heap != NULL)
|
||||
heap->destroy();
|
||||
}
|
||||
}
|
||||
|
||||
mCriticalSection.unlock();
|
||||
}
|
||||
|
||||
void TaskMgr::finalize()
|
||||
{
|
||||
if (mPrepareThread != NULL)
|
||||
{
|
||||
mPrepareThread->quitAndDestroySingleThread(false);
|
||||
delete mPrepareThread;
|
||||
mPrepareThread = NULL;
|
||||
}
|
||||
|
||||
if (mRootTask != NULL)
|
||||
{
|
||||
destroyTaskSync(mRootTask);
|
||||
mRootTask = NULL;
|
||||
}
|
||||
|
||||
for (s32 i = 0; i < HeapMgr::sRootHeaps.mPtrNum; i++)
|
||||
{
|
||||
Heap* heap = mHeapArray.mHeaps[i];
|
||||
if (heap)
|
||||
{
|
||||
heap->destroy();
|
||||
mHeapArray.mHeaps[i] = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sead
|
||||
Reference in New Issue
Block a user