2018-05-08 20:03:29 +08:00
|
|
|
#include "..\e2daction.h"
|
|
|
|
|
|
|
|
|
|
e2d::Spawn::Spawn()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-10 17:02:18 +08:00
|
|
|
e2d::Spawn::Spawn(const std::vector<Action*>& actions)
|
2018-05-10 00:58:43 +08:00
|
|
|
{
|
|
|
|
|
this->add(actions);
|
2018-05-08 20:03:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
e2d::Spawn::~Spawn()
|
|
|
|
|
{
|
2018-08-12 14:30:28 +08:00
|
|
|
for (const auto& action : _actions)
|
2018-07-07 01:43:41 +08:00
|
|
|
{
|
2018-08-23 16:37:44 +08:00
|
|
|
GC::instance()->safeRelease(action);
|
2018-07-07 01:43:41 +08:00
|
|
|
}
|
2018-05-08 20:03:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void e2d::Spawn::_init()
|
|
|
|
|
{
|
|
|
|
|
Action::_init();
|
|
|
|
|
|
|
|
|
|
if (_target)
|
|
|
|
|
{
|
2018-08-12 14:30:28 +08:00
|
|
|
for (const auto& action : _actions)
|
2018-05-08 20:03:29 +08:00
|
|
|
{
|
|
|
|
|
action->_target = _target;
|
|
|
|
|
action->_init();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void e2d::Spawn::_update()
|
|
|
|
|
{
|
|
|
|
|
Action::_update();
|
|
|
|
|
|
|
|
|
|
size_t doneNum = 0;
|
2018-08-12 14:30:28 +08:00
|
|
|
for (const auto& action : _actions)
|
2018-05-08 20:03:29 +08:00
|
|
|
{
|
|
|
|
|
if (action->_isDone())
|
|
|
|
|
{
|
2018-05-14 22:51:40 +08:00
|
|
|
++doneNum;
|
2018-05-08 20:03:29 +08:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
action->_update();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (doneNum == _actions.size())
|
|
|
|
|
{
|
|
|
|
|
this->stop();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void e2d::Spawn::reset()
|
|
|
|
|
{
|
|
|
|
|
Action::reset();
|
2018-08-12 14:30:28 +08:00
|
|
|
for (const auto& action : _actions)
|
2018-05-08 20:03:29 +08:00
|
|
|
{
|
|
|
|
|
action->reset();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void e2d::Spawn::_resetTime()
|
|
|
|
|
{
|
2018-08-12 14:30:28 +08:00
|
|
|
for (const auto& action : _actions)
|
2018-05-08 20:03:29 +08:00
|
|
|
{
|
|
|
|
|
action->_resetTime();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void e2d::Spawn::add(Action * action)
|
|
|
|
|
{
|
|
|
|
|
if (action)
|
|
|
|
|
{
|
|
|
|
|
_actions.push_back(action);
|
2018-07-22 21:22:27 +08:00
|
|
|
action->retain();
|
2018-05-08 20:03:29 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-10 17:02:18 +08:00
|
|
|
void e2d::Spawn::add(const std::vector<Action*>& actions)
|
2018-05-10 00:58:43 +08:00
|
|
|
{
|
|
|
|
|
for (const auto &action : actions)
|
2018-05-08 20:03:29 +08:00
|
|
|
{
|
2018-05-10 00:58:43 +08:00
|
|
|
this->add(action);
|
2018-05-08 20:03:29 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
e2d::Spawn * e2d::Spawn::clone() const
|
|
|
|
|
{
|
2018-07-06 12:59:32 +08:00
|
|
|
auto spawn = new (e2d::autorelease) Spawn();
|
2018-05-10 14:03:54 +08:00
|
|
|
for (const auto& action : _actions)
|
2018-05-08 20:03:29 +08:00
|
|
|
{
|
2018-05-10 14:03:54 +08:00
|
|
|
if (action)
|
|
|
|
|
{
|
|
|
|
|
spawn->add(action->clone());
|
|
|
|
|
}
|
2018-05-08 20:03:29 +08:00
|
|
|
}
|
2018-05-10 14:03:54 +08:00
|
|
|
return spawn;
|
2018-05-08 20:03:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
e2d::Spawn * e2d::Spawn::reverse() const
|
|
|
|
|
{
|
2018-07-06 12:59:32 +08:00
|
|
|
auto spawn = new (e2d::autorelease) Spawn();
|
2018-05-24 12:24:39 +08:00
|
|
|
if (spawn && !_actions.empty())
|
2018-05-08 20:03:29 +08:00
|
|
|
{
|
2018-05-14 00:36:01 +08:00
|
|
|
std::vector<Action*> newActions(_actions.size());
|
|
|
|
|
for (auto iter = _actions.crbegin(), iterCrend = _actions.crend(); iter != iterCrend; ++iter)
|
2018-05-10 14:03:54 +08:00
|
|
|
{
|
2018-08-12 20:19:47 +08:00
|
|
|
newActions.push_back((*iter)->reverse());
|
2018-05-10 14:03:54 +08:00
|
|
|
}
|
2018-05-14 00:36:01 +08:00
|
|
|
spawn->add(newActions);
|
2018-05-08 20:03:29 +08:00
|
|
|
}
|
2018-05-10 14:03:54 +08:00
|
|
|
return spawn;
|
2018-05-08 20:03:29 +08:00
|
|
|
}
|