2017-10-19 00:50:04 +08:00
|
|
|
|
#include "..\etools.h"
|
2017-10-19 12:48:58 +08:00
|
|
|
|
#include "..\eactions.h"
|
2017-10-19 00:50:04 +08:00
|
|
|
|
|
2017-10-19 12:48:58 +08:00
|
|
|
|
static e2d::EVector<e2d::EAction*> s_vActions;
|
2017-10-19 00:50:04 +08:00
|
|
|
|
|
2017-10-19 12:48:58 +08:00
|
|
|
|
|
|
|
|
|
|
void e2d::EActionManager::bindAction(EAction * action, ENode * pTargetNode)
|
2017-10-19 00:50:04 +08:00
|
|
|
|
{
|
2017-10-19 12:48:58 +08:00
|
|
|
|
ASSERT(
|
|
|
|
|
|
(!action->m_pTarget),
|
|
|
|
|
|
"The action is already running, it cannot running again!"
|
|
|
|
|
|
);
|
|
|
|
|
|
WARN_IF(action == nullptr, "EAction NULL pointer exception!");
|
|
|
|
|
|
WARN_IF(pTargetNode == nullptr, "EAction's target is NULL!");
|
|
|
|
|
|
|
|
|
|
|
|
if (action && pTargetNode)
|
|
|
|
|
|
{
|
|
|
|
|
|
action->start();
|
|
|
|
|
|
action->retain();
|
|
|
|
|
|
action->m_pTarget = pTargetNode;
|
|
|
|
|
|
s_vActions.push_back(action);
|
|
|
|
|
|
}
|
2017-10-19 00:50:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::EActionManager::startAllActionsBindedWith(EScene * pParentScene)
|
|
|
|
|
|
{
|
2017-10-19 12:48:58 +08:00
|
|
|
|
if (pParentScene)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (const auto &child : pParentScene->getChildren())
|
|
|
|
|
|
{
|
|
|
|
|
|
EActionManager::startAllActionsBindedWith(child);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-10-19 00:50:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::EActionManager::stopAllActionsBindedWith(EScene * pParentScene)
|
|
|
|
|
|
{
|
2017-10-19 12:48:58 +08:00
|
|
|
|
if (pParentScene)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (const auto &child : pParentScene->getChildren())
|
|
|
|
|
|
{
|
|
|
|
|
|
EActionManager::stopAllActionsBindedWith(child);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-10-19 00:50:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::EActionManager::clearAllActionsBindedWith(EScene * pParentScene)
|
|
|
|
|
|
{
|
2017-10-19 12:48:58 +08:00
|
|
|
|
if (pParentScene)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (const auto & child : pParentScene->getChildren())
|
|
|
|
|
|
{
|
|
|
|
|
|
ETimerManager::clearAllTimersBindedWith(child);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-10-19 00:50:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-19 12:48:58 +08:00
|
|
|
|
void e2d::EActionManager::startAllActionsBindedWith(ENode * pTargetNode)
|
2017-10-19 00:50:04 +08:00
|
|
|
|
{
|
2017-10-19 12:48:58 +08:00
|
|
|
|
if (pTargetNode)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (const auto &action : s_vActions)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (action->getTarget() == pTargetNode)
|
|
|
|
|
|
{
|
|
|
|
|
|
action->start();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
for (const auto &child : pTargetNode->getChildren())
|
|
|
|
|
|
{
|
|
|
|
|
|
EActionManager::startAllActionsBindedWith(child);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-10-19 00:50:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-19 12:48:58 +08:00
|
|
|
|
void e2d::EActionManager::stopAllActionsBindedWith(ENode * pTargetNode)
|
2017-10-19 00:50:04 +08:00
|
|
|
|
{
|
2017-10-19 12:48:58 +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-19 12:48:58 +08:00
|
|
|
|
void e2d::EActionManager::clearAllActionsBindedWith(ENode * pTargetNode)
|
2017-10-19 00:50:04 +08:00
|
|
|
|
{
|
2017-10-19 12:48:58 +08:00
|
|
|
|
if (pTargetNode)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (size_t i = 0; i < s_vActions.size();)
|
|
|
|
|
|
{
|
|
|
|
|
|
auto a = s_vActions[i];
|
|
|
|
|
|
if (a->getTarget() == pTargetNode)
|
|
|
|
|
|
{
|
|
|
|
|
|
a->autoRelease();
|
|
|
|
|
|
a->release();
|
|
|
|
|
|
s_vActions.erase(s_vActions.begin() + i);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
i++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
for (auto child : pTargetNode->getChildren())
|
|
|
|
|
|
{
|
|
|
|
|
|
ETimerManager::clearAllTimersBindedWith(child);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-10-19 00:50:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::EActionManager::startAllActions()
|
|
|
|
|
|
{
|
2017-10-19 12:48:58 +08:00
|
|
|
|
EActionManager::startAllActionsBindedWith(EApp::getCurrentScene());
|
2017-10-19 00:50:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::EActionManager::stopAllActions()
|
|
|
|
|
|
{
|
2017-10-19 12:48:58 +08:00
|
|
|
|
EActionManager::stopAllActionsBindedWith(EApp::getCurrentScene());
|
2017-10-19 00:50:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::EActionManager::clearAllActions()
|
|
|
|
|
|
{
|
2017-10-19 12:48:58 +08:00
|
|
|
|
EActionManager::clearAllActionsBindedWith(EApp::getCurrentScene());
|
2017-10-19 00:50:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::EActionManager::_waitAllActionsBindedWith(EScene * pParentScene)
|
|
|
|
|
|
{
|
2017-10-19 12:48:58 +08:00
|
|
|
|
if (pParentScene)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (const auto &child : pParentScene->getChildren())
|
|
|
|
|
|
{
|
|
|
|
|
|
EActionManager::_waitAllActionsBindedWith(child);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-10-19 00:50:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::EActionManager::_notifyAllActionsBindedWith(EScene * pParentScene)
|
|
|
|
|
|
{
|
2017-10-19 12:48:58 +08:00
|
|
|
|
if (pParentScene)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (const auto &child : pParentScene->getChildren())
|
|
|
|
|
|
{
|
|
|
|
|
|
EActionManager::_notifyAllActionsBindedWith(child);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-10-19 00:50:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-19 12:48:58 +08:00
|
|
|
|
void e2d::EActionManager::_waitAllActionsBindedWith(ENode * pTargetNode)
|
2017-10-19 00:50:04 +08:00
|
|
|
|
{
|
2017-10-19 12:48:58 +08:00
|
|
|
|
if (pTargetNode)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (const auto &action : s_vActions)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (action->getTarget() == pTargetNode)
|
|
|
|
|
|
{
|
|
|
|
|
|
action->_wait();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
for (const auto &child : pTargetNode->getChildren())
|
|
|
|
|
|
{
|
|
|
|
|
|
EActionManager::_waitAllActionsBindedWith(child);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-10-19 00:50:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-19 12:48:58 +08:00
|
|
|
|
void e2d::EActionManager::_notifyAllActionsBindedWith(ENode * pTargetNode)
|
2017-10-19 00:50:04 +08:00
|
|
|
|
{
|
2017-10-19 12:48:58 +08:00
|
|
|
|
if (pTargetNode)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (const auto &action : s_vActions)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (action->getTarget() == pTargetNode)
|
|
|
|
|
|
{
|
|
|
|
|
|
action->_notify();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
for (const auto &child : pTargetNode->getChildren())
|
|
|
|
|
|
{
|
|
|
|
|
|
EActionManager::_notifyAllActionsBindedWith(child);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-10-19 00:50:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::EActionManager::ActionProc()
|
|
|
|
|
|
{
|
2017-10-19 12:48:58 +08:00
|
|
|
|
if (s_vActions.empty())
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
EAction * action;
|
|
|
|
|
|
// ѭ<><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++)
|
|
|
|
|
|
{
|
|
|
|
|
|
action = s_vActions[i];
|
|
|
|
|
|
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
|
|
|
|
|
|
if (action->isRunning())
|
|
|
|
|
|
{
|
|
|
|
|
|
if (action->_isEnding())
|
|
|
|
|
|
{
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
action->autoRelease();
|
|
|
|
|
|
action->release();
|
|
|
|
|
|
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
|
|
|
|
}
|