Magic_Game/Easy2D/Manager/EActionManager.cpp

163 lines
3.0 KiB
C++
Raw Normal View History

2017-10-19 00:50:04 +08:00
#include "..\etools.h"
#include "..\eactions.h"
#include "..\Win\winbase.h"
2017-10-19 00:50:04 +08:00
static e2d::EVector<e2d::EAction*> s_vActions;
2017-10-19 00:50:04 +08:00
void e2d::EActionManager::addAction(EAction * action)
2017-10-19 00:50:04 +08:00
{
WARN_IF(action == nullptr, "EAction NULL pointer exception!");
if (action)
{
action->start();
action->retain();
s_vActions.push_back(action);
}
2017-10-19 00:50:04 +08:00
}
2017-10-21 19:09:31 +08:00
void e2d::EActionManager::startAllActionsBindedWith(ENode * pTargetNode)
2017-10-19 00:50:04 +08:00
{
2017-10-21 19:09:31 +08:00
if (pTargetNode)
{
2017-10-21 19:09:31 +08:00
for (const auto &action : s_vActions)
{
2017-10-21 19:09:31 +08:00
if (action->getTarget() == pTargetNode)
{
action->start();
}
}
2017-10-21 19:09:31 +08:00
for (const auto &child : pTargetNode->getChildren())
{
2017-10-21 19:09:31 +08:00
EActionManager::startAllActionsBindedWith(child);
}
}
2017-10-19 00:50:04 +08:00
}
2017-10-21 19:09:31 +08:00
void e2d::EActionManager::pauseAllActionsBindedWith(ENode * pTargetNode)
2017-10-19 00:50:04 +08:00
{
if (pTargetNode)
{
for (const auto &action : s_vActions)
{
if (action->getTarget() == pTargetNode)
{
2017-10-21 19:09:31 +08:00
action->pause();
}
}
for (const auto &child : pTargetNode->getChildren())
{
2017-10-21 19:09:31 +08:00
EActionManager::pauseAllActionsBindedWith(child);
}
}
2017-10-19 00:50:04 +08:00
}
void e2d::EActionManager::stopAllActionsBindedWith(ENode * pTargetNode)
2017-10-19 00:50:04 +08:00
{
if (pTargetNode)
{
for (const auto &action : s_vActions)
{
if (action->getTarget() == pTargetNode)
{
action->stop();
}
}
for (const auto &child : pTargetNode->getChildren())
{
EActionManager::stopAllActionsBindedWith(child);
}
}
2017-10-19 00:50:04 +08:00
}
2017-10-21 19:09:31 +08:00
void e2d::EActionManager::_clearAllActionsBindedWith(ENode * pTargetNode)
2017-10-19 00:50:04 +08:00
{
if (pTargetNode)
{
for (size_t i = 0; i < s_vActions.size();)
{
auto a = s_vActions[i];
if (a->getTarget() == pTargetNode)
{
2017-10-21 19:09:31 +08:00
SafeReleaseAndClear(&a);
s_vActions.erase(s_vActions.begin() + i);
}
else
{
i++;
}
}
}
2017-10-19 00:50:04 +08:00
}
void e2d::EActionManager::startAllActions()
{
2017-10-21 19:09:31 +08:00
for (auto child : EApp::getCurrentScene()->getChildren())
{
EActionManager::startAllActionsBindedWith(child);
}
2017-10-19 00:50:04 +08:00
}
2017-10-21 19:09:31 +08:00
void e2d::EActionManager::pauseAllActions()
2017-10-19 00:50:04 +08:00
{
2017-10-21 19:09:31 +08:00
for (auto child : EApp::getCurrentScene()->getChildren())
{
EActionManager::pauseAllActionsBindedWith(child);
}
2017-10-19 00:50:04 +08:00
}
2017-10-21 19:09:31 +08:00
void e2d::EActionManager::stopAllActions()
2017-10-19 00:50:04 +08:00
{
2017-10-21 19:09:31 +08:00
for (auto child : EApp::getCurrentScene()->getChildren())
{
EActionManager::stopAllActionsBindedWith(child);
}
2017-10-19 00:50:04 +08:00
}
void e2d::EActionManager::_clearManager()
2017-10-19 00:50:04 +08:00
{
s_vActions.clear();
2017-10-19 00:50:04 +08:00
}
void e2d::EActionManager::_resetAllActions()
2017-10-19 00:50:04 +08:00
{
for (const auto & action : s_vActions)
{
action->m_tLast = GetNow();
}
2017-10-19 00:50:04 +08:00
}
void e2d::EActionManager::ActionProc()
{
if (EApp::isPaused() || s_vActions.empty())
return;
// ѭ<><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>еĶ<D0B5><C4B6><EFBFBD>
for (size_t i = 0; i < s_vActions.size(); i++)
{
2017-10-21 19:09:31 +08:00
auto &action = s_vActions[i];
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
if (action->isRunning() ||
(action->getTarget() && action->getTarget()->getParentScene() == EApp::getCurrentScene()))
{
if (action->_isEnding())
{
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD>
2017-10-21 19:09:31 +08:00
SafeReleaseAndClear(&action);
s_vActions.erase(s_vActions.begin() + i);
}
else
{
// <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (!action->m_bInit)
{
action->_init();
}
// ִ<>ж<EFBFBD><D0B6><EFBFBD>
action->_callOn();
}
}
}
2017-10-19 00:50:04 +08:00
}