Magic_Game/core/Action/Sequence.cpp

156 lines
2.2 KiB
C++
Raw Normal View History

#include "..\e2daction.h"
e2d::Sequence::Sequence()
: _currIndex(0)
{
}
2018-05-10 00:58:43 +08:00
e2d::Sequence::Sequence(int number, Action * action, ...) :
_currIndex(0)
{
2018-05-10 00:58:43 +08:00
va_list args;
va_start(args, action);
2018-05-10 00:58:43 +08:00
this->add(action);
for (int i = 1; i < number; i++)
{
2018-05-10 00:58:43 +08:00
this->add(va_arg(args, Action*));
}
2018-05-10 00:58:43 +08:00
va_end(args);
}
#ifdef HIGHER_THAN_VS2012
e2d::Sequence::Sequence(const std::initializer_list<Action*>& actions)
: _currIndex(0)
{
this->add(actions);
}
#endif
e2d::Sequence::~Sequence()
{
}
void e2d::Sequence::_init()
{
Action::_init();
// <20><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (_target)
{
for (auto action : _actions)
{
action->_target = _target;
}
}
// <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
_actions[0]->_init();
}
void e2d::Sequence::onDestroy()
{
Action::onDestroy();
for (auto action : _actions)
{
SafeRelease(&action);
}
}
void e2d::Sequence::_update()
{
Action::_update();
auto &action = _actions[_currIndex];
action->_update();
if (action->_isDone())
{
_currIndex++;
if (_currIndex == _actions.size())
{
this->stop();
}
else
{
_actions[_currIndex]->_init();
}
}
}
void e2d::Sequence::reset()
{
Action::reset();
for (auto action : _actions)
{
action->reset();
}
_currIndex = 0;
}
void e2d::Sequence::_resetTime()
{
for (auto action : _actions)
{
action->_resetTime();
}
}
void e2d::Sequence::add(Action * action)
{
if (action)
{
_actions.push_back(action);
action->retain();
}
}
2018-05-10 00:58:43 +08:00
void e2d::Sequence::add(int number, Action * action, ...)
{
2018-05-10 00:58:43 +08:00
va_list args;
va_start(args, action);
this->add(action);
for (int i = 1; i < number; i++)
{
2018-05-10 00:58:43 +08:00
this->add(va_arg(args, Action*));
}
2018-05-10 00:58:43 +08:00
va_end(args);
}
2018-05-10 00:58:43 +08:00
#ifdef HIGHER_THAN_VS2012
void e2d::Sequence::add(const std::initializer_list<Action*>& actions)
{
for (const auto &action : actions)
{
2018-05-10 00:58:43 +08:00
this->add(action);
}
}
#endif
e2d::Sequence * e2d::Sequence::clone() const
{
2018-05-10 14:03:54 +08:00
auto sequence = new (std::nothrow) Sequence();
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
{
2018-05-10 14:03:54 +08:00
auto sequence = new (std::nothrow) Sequence();
for (const auto& action : _actions)
{
2018-05-10 14:03:54 +08:00
if (action)
{
sequence->add(action->reverse());
}
}
2018-05-10 14:03:54 +08:00
sequence->_actions.reserve(_actions.size());
return sequence;
}