Magic_Game/core/Manager/ActionManager.cpp

224 lines
4.0 KiB
C++
Raw Normal View History

2018-04-21 21:24:46 +08:00
#include "..\e2dmanager.h"
#include "..\e2daction.h"
2017-10-19 00:50:04 +08:00
static std::vector<e2d::Action*> s_vActions;
static std::vector<e2d::Action*> s_vRunningActions;
2017-10-19 00:50:04 +08:00
2018-03-06 09:56:17 +08:00
void e2d::ActionManager::__update()
{
if (s_vRunningActions.empty() || Game::isPaused())
return;
// ѭ<><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>еĶ<D0B5><C4B6><EFBFBD>
2018-05-14 22:51:40 +08:00
for (size_t i = 0; i < s_vRunningActions.size(); ++i)
2018-03-06 09:56:17 +08:00
{
auto action = s_vRunningActions[i];
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
2018-05-08 11:37:11 +08:00
if (action->_isDone())
2018-03-06 09:56:17 +08:00
{
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD>
action->release();
action->_target = nullptr;
s_vRunningActions.erase(s_vRunningActions.begin() + i);
}
else
{
if (action->isRunning())
2018-03-06 09:56:17 +08:00
{
// ִ<>ж<EFBFBD><D0B6><EFBFBD>
action->_update();
}
}
}
}
void e2d::ActionManager::__add(Action * action)
2018-03-06 09:56:17 +08:00
{
2018-05-08 17:40:36 +08:00
if (action)
2018-03-06 09:56:17 +08:00
{
2018-05-08 17:40:36 +08:00
s_vActions.push_back(action);
2018-03-06 09:56:17 +08:00
}
}
void e2d::ActionManager::__remove(Action * action)
2018-03-06 09:56:17 +08:00
{
2018-05-21 23:04:58 +08:00
auto iter = std::find(s_vActions.begin(), s_vActions.end(), action);
if (iter != s_vActions.end())
2018-03-06 09:56:17 +08:00
{
2018-05-21 23:04:58 +08:00
s_vActions.erase(iter);
2018-03-06 09:56:17 +08:00
}
}
2018-05-08 17:40:36 +08:00
void e2d::ActionManager::__resumeAllBindedWith(Node * target)
2017-10-19 00:50:04 +08:00
{
2018-05-08 17:40:36 +08:00
if (target)
{
2018-04-24 20:22:41 +08:00
for (auto action : s_vRunningActions)
{
2018-05-08 17:40:36 +08:00
if (action->getTarget() == target)
2017-10-21 19:09:31 +08:00
{
2018-02-06 15:34:47 +08:00
action->resume();
2017-10-21 19:09:31 +08:00
}
}
}
2017-10-19 00:50:04 +08:00
}
2018-05-08 17:40:36 +08:00
void e2d::ActionManager::__pauseAllBindedWith(Node * target)
2017-10-19 00:50:04 +08:00
{
2018-05-08 17:40:36 +08:00
if (target)
{
2018-04-24 20:22:41 +08:00
for (auto action : s_vRunningActions)
{
2018-05-08 17:40:36 +08:00
if (action->getTarget() == target)
{
2018-02-03 22:04:43 +08:00
action->pause();
}
}
}
2017-10-19 00:50:04 +08:00
}
2018-05-08 17:40:36 +08:00
void e2d::ActionManager::__stopAllBindedWith(Node * target)
2017-10-19 00:50:04 +08:00
{
2018-05-08 17:40:36 +08:00
if (target)
{
2018-04-24 20:22:41 +08:00
for (auto action : s_vRunningActions)
{
2018-05-08 17:40:36 +08:00
if (action->getTarget() == target)
{
2018-02-03 22:04:43 +08:00
action->stop();
}
}
2018-03-06 09:56:17 +08:00
}
}
void e2d::ActionManager::start(Action * action, Node * target, bool paused)
2018-05-08 17:40:36 +08:00
{
WARN_IF(action == nullptr, "Action NULL pointer exception!");
2018-05-08 17:40:36 +08:00
WARN_IF(target == nullptr, "Target node NULL pointer exception!");
if (action && target)
{
2018-05-21 23:04:58 +08:00
auto iter = std::find(s_vRunningActions.begin(), s_vRunningActions.end(), action);
ASSERT(iter == s_vRunningActions.end(), "Action has begun!");
2018-05-08 17:40:36 +08:00
action->_startWithTarget(target);
action->retain();
action->_running = !paused;
2018-05-08 17:40:36 +08:00
s_vRunningActions.push_back(action);
}
}
void e2d::ActionManager::resume(const String& strActionName)
2018-03-06 09:56:17 +08:00
{
2018-04-24 20:22:41 +08:00
for (auto action : s_vRunningActions)
2018-03-06 09:56:17 +08:00
{
if (action->getName() == strActionName)
{
action->resume();
}
}
}
void e2d::ActionManager::pause(const String& strActionName)
2018-03-06 09:56:17 +08:00
{
2018-04-24 20:22:41 +08:00
for (auto action : s_vRunningActions)
2018-03-06 09:56:17 +08:00
{
if (action->getName() == strActionName)
{
2018-03-06 09:56:17 +08:00
action->pause();
}
}
}
void e2d::ActionManager::stop(const String& strActionName)
2018-03-06 09:56:17 +08:00
{
2018-04-24 20:22:41 +08:00
for (auto action : s_vRunningActions)
2018-03-06 09:56:17 +08:00
{
if (action->getName() == strActionName)
{
action->stop();
}
}
2017-10-19 00:50:04 +08:00
}
2018-05-08 17:40:36 +08:00
void e2d::ActionManager::__clearAllBindedWith(Node * target)
2017-10-19 00:50:04 +08:00
{
2018-05-08 17:40:36 +08:00
if (target)
{
2018-03-06 09:56:17 +08:00
for (size_t i = 0; i < s_vRunningActions.size();)
{
2018-03-06 09:56:17 +08:00
auto a = s_vRunningActions[i];
2018-05-08 17:40:36 +08:00
if (a->getTarget() == target)
{
2018-05-19 01:10:37 +08:00
GC::release(a);
2018-03-06 09:56:17 +08:00
s_vRunningActions.erase(s_vRunningActions.begin() + i);
}
else
{
2018-05-14 22:51:40 +08:00
++i;
}
}
}
2017-10-19 00:50:04 +08:00
}
void e2d::ActionManager::__uninit()
{
2018-04-24 20:22:41 +08:00
for (auto action : s_vRunningActions)
{
2018-05-19 01:10:37 +08:00
GC::release(action);
}
s_vActions.clear();
s_vRunningActions.clear();
}
void e2d::ActionManager::resumeAll()
2017-10-19 00:50:04 +08:00
{
2018-04-24 20:22:41 +08:00
for (auto child : SceneManager::getCurrentScene()->getRoot()->getAllChildren())
2017-10-21 19:09:31 +08:00
{
ActionManager::__resumeAllBindedWith(child);
2017-10-21 19:09:31 +08:00
}
2017-10-19 00:50:04 +08:00
}
void e2d::ActionManager::pauseAll()
2017-10-19 00:50:04 +08:00
{
2018-04-24 20:22:41 +08:00
for (auto child : SceneManager::getCurrentScene()->getRoot()->getAllChildren())
2017-10-21 19:09:31 +08:00
{
ActionManager::__pauseAllBindedWith(child);
2017-10-21 19:09:31 +08:00
}
2017-10-19 00:50:04 +08:00
}
void e2d::ActionManager::stopAll()
2017-10-19 00:50:04 +08:00
{
2018-04-24 20:22:41 +08:00
for (auto child : SceneManager::getCurrentScene()->getRoot()->getAllChildren())
2017-10-21 19:09:31 +08:00
{
ActionManager::__stopAllBindedWith(child);
2017-10-21 19:09:31 +08:00
}
2017-10-19 00:50:04 +08:00
}
std::vector<e2d::Action*> e2d::ActionManager::get(const String& strActionName)
2017-10-19 00:50:04 +08:00
{
2018-05-10 00:58:43 +08:00
std::vector<Action*> actions;
2018-04-24 20:22:41 +08:00
for (auto action : s_vActions)
{
2018-03-06 09:56:17 +08:00
if (action->getName() == strActionName)
{
2018-05-10 00:58:43 +08:00
actions.push_back(action);
2018-03-06 09:56:17 +08:00
}
}
2018-05-10 00:58:43 +08:00
return std::move(actions);
2017-10-19 00:50:04 +08:00
}
2018-05-10 14:16:36 +08:00
const std::vector<e2d::Action*>& e2d::ActionManager::getAll()
2017-10-19 00:50:04 +08:00
{
2018-03-06 09:56:17 +08:00
return s_vActions;
}
2018-04-24 09:02:06 +08:00
void e2d::ActionManager::__resetAll()
2018-03-06 09:56:17 +08:00
{
2018-04-24 20:22:41 +08:00
for (auto action : s_vRunningActions)
{
2018-03-06 09:56:17 +08:00
action->_resetTime();
}
2017-10-19 00:50:04 +08:00
}