2018-05-08 20:03:29 +08:00
|
|
|
|
#include "..\e2daction.h"
|
|
|
|
|
|
|
|
|
|
|
|
e2d::Sequence::Sequence()
|
|
|
|
|
|
: _currIndex(0)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-10 17:02:18 +08:00
|
|
|
|
e2d::Sequence::Sequence(const std::vector<Action*>& actions)
|
2018-05-10 00:58:43 +08:00
|
|
|
|
: _currIndex(0)
|
|
|
|
|
|
{
|
|
|
|
|
|
this->add(actions);
|
2018-05-08 20:03:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
e2d::Sequence::~Sequence()
|
|
|
|
|
|
{
|
2018-08-12 14:30:28 +08:00
|
|
|
|
for (const auto& action : _actions)
|
2018-07-07 01:43:41 +08:00
|
|
|
|
{
|
2018-07-22 21:22:27 +08:00
|
|
|
|
GC::getInstance()->safeRelease(action);
|
2018-07-07 01:43:41 +08:00
|
|
|
|
}
|
2018-05-08 20:03:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::Sequence::_init()
|
|
|
|
|
|
{
|
|
|
|
|
|
Action::_init();
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
// <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
_actions[0]->_init();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::Sequence::_update()
|
|
|
|
|
|
{
|
|
|
|
|
|
Action::_update();
|
|
|
|
|
|
|
|
|
|
|
|
auto &action = _actions[_currIndex];
|
|
|
|
|
|
action->_update();
|
|
|
|
|
|
|
|
|
|
|
|
if (action->_isDone())
|
|
|
|
|
|
{
|
2018-05-14 22:51:40 +08:00
|
|
|
|
++_currIndex;
|
2018-05-08 20:03:29 +08:00
|
|
|
|
if (_currIndex == _actions.size())
|
|
|
|
|
|
{
|
|
|
|
|
|
this->stop();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
_actions[_currIndex]->_init();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::Sequence::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();
|
|
|
|
|
|
}
|
|
|
|
|
|
_currIndex = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::Sequence::_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::Sequence::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::Sequence::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::Sequence * e2d::Sequence::clone() const
|
|
|
|
|
|
{
|
2018-07-06 12:59:32 +08:00
|
|
|
|
auto sequence = new (e2d::autorelease) Sequence();
|
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)
|
|
|
|
|
|
{
|
|
|
|
|
|
sequence->add(action->clone());
|
|
|
|
|
|
}
|
2018-05-08 20:03:29 +08:00
|
|
|
|
}
|
2018-05-10 14:03:54 +08:00
|
|
|
|
return sequence;
|
2018-05-08 20:03:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
e2d::Sequence * e2d::Sequence::reverse() const
|
|
|
|
|
|
{
|
2018-07-06 12:59:32 +08:00
|
|
|
|
auto sequence = new (e2d::autorelease) Sequence();
|
2018-05-24 12:24:39 +08:00
|
|
|
|
if (sequence && !_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-05-14 00:36:01 +08:00
|
|
|
|
if (*iter)
|
|
|
|
|
|
{
|
2018-05-14 00:57:16 +08:00
|
|
|
|
newActions.push_back((*iter)->reverse());
|
2018-05-14 00:36:01 +08:00
|
|
|
|
}
|
2018-05-10 14:03:54 +08:00
|
|
|
|
}
|
2018-05-14 00:36:01 +08:00
|
|
|
|
sequence->add(newActions);
|
2018-05-08 20:03:29 +08:00
|
|
|
|
}
|
2018-05-10 14:03:54 +08:00
|
|
|
|
return sequence;
|
2018-05-08 20:03:29 +08:00
|
|
|
|
}
|