Magic_Game/core/Action/Sequence.cpp

119 lines
1.8 KiB
C++
Raw Normal View History

#include "..\e2daction.h"
e2d::Sequence::Sequence()
: _currIndex(0)
{
}
e2d::Sequence::Sequence(const std::vector<Action*>& actions)
2018-05-10 00:58:43 +08:00
: _currIndex(0)
{
this->add(actions);
}
e2d::Sequence::~Sequence()
{
2018-08-12 14:30:28 +08:00
for (const auto& action : _actions)
2018-07-07 01:43:41 +08:00
{
GC::getInstance()->safeRelease(action);
2018-07-07 01:43:41 +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)
{
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;
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)
{
action->reset();
}
_currIndex = 0;
}
void e2d::Sequence::_resetTime()
{
2018-08-12 14:30:28 +08:00
for (const auto& action : _actions)
{
action->_resetTime();
}
}
void e2d::Sequence::add(Action * action)
{
if (action)
{
_actions.push_back(action);
2018-07-22 21:22:27 +08:00
action->retain();
}
}
void e2d::Sequence::add(const std::vector<Action*>& actions)
2018-05-10 00:58:43 +08:00
{
for (const auto &action : actions)
{
2018-05-10 00:58:43 +08:00
this->add(action);
}
}
e2d::Sequence * e2d::Sequence::clone() const
{
auto sequence = new (e2d::autorelease) Sequence();
2018-05-10 14:03:54 +08:00
for (const auto& action : _actions)
{
2018-05-10 14:03:54 +08:00
if (action)
{
sequence->add(action->clone());
}
}
2018-05-10 14:03:54 +08:00
return sequence;
}
e2d::Sequence * e2d::Sequence::reverse() const
{
auto sequence = new (e2d::autorelease) Sequence();
2018-05-24 12:24:39 +08:00
if (sequence && !_actions.empty())
{
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
sequence->add(newActions);
}
2018-05-10 14:03:54 +08:00
return sequence;
}