Magic_Game/core/Action/ActionSequence.cpp

156 lines
2.5 KiB
C++
Raw Normal View History

2018-04-21 21:24:46 +08:00
#include "..\e2daction.h"
2017-10-19 00:50:04 +08:00
2018-04-01 00:04:33 +08:00
e2d::ActionSequence::ActionSequence()
2018-05-08 17:40:36 +08:00
: _nActionIndex(0)
2017-10-19 00:50:04 +08:00
{
}
2018-04-24 20:22:41 +08:00
#ifdef HIGHER_THAN_VS2012
2018-05-08 11:37:11 +08:00
e2d::ActionSequence::ActionSequence(const std::initializer_list<ActionBase*>& vActions)
2018-05-08 17:40:36 +08:00
: _nActionIndex(0)
2017-10-19 00:50:04 +08:00
{
this->add(vActions);
2017-10-19 00:50:04 +08:00
}
2018-04-01 13:16:07 +08:00
#else
e2d::ActionSequence::ActionSequence(int number, ActionBase * action1, ...) :
2018-05-08 17:40:36 +08:00
_nActionIndex(0)
2018-04-01 13:16:07 +08:00
{
ActionBase ** ppAction = &action1;
2018-04-01 13:16:07 +08:00
while (number > 0)
{
WARN_IF((*ppAction) == nullptr, "ActionSequence NULL pointer exception!");
this->add(*ppAction);
ppAction++;
number--;
}
}
#endif
2017-10-19 00:50:04 +08:00
e2d::ActionSequence::~ActionSequence()
2017-10-19 00:50:04 +08:00
{
}
void e2d::ActionSequence::_init()
2017-10-19 00:50:04 +08:00
{
ActionBase::_init();
2017-10-19 00:50:04 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2018-05-08 17:40:36 +08:00
if (_pTarget)
2017-10-19 00:50:04 +08:00
{
2018-05-08 17:40:36 +08:00
for (auto action : _vActions)
{
2018-05-08 17:40:36 +08:00
action->_pTarget = _pTarget;
}
2017-10-19 00:50:04 +08:00
}
// <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2018-05-08 17:40:36 +08:00
_vActions[0]->_init();
2017-10-19 00:50:04 +08:00
}
void e2d::ActionSequence::destroy()
{
ActionBase::destroy();
2018-05-08 17:40:36 +08:00
for (auto action : _vActions)
{
SafeRelease(&action);
}
}
void e2d::ActionSequence::_update()
2017-10-19 00:50:04 +08:00
{
ActionBase::_update();
2017-11-03 12:51:01 +08:00
2018-05-08 17:40:36 +08:00
auto &action = _vActions[_nActionIndex];
action->_update();
2017-10-19 00:50:04 +08:00
2018-05-08 11:37:11 +08:00
if (action->_isDone())
2017-10-19 00:50:04 +08:00
{
2018-05-08 17:40:36 +08:00
_nActionIndex++;
if (_nActionIndex == _vActions.size())
2017-10-19 00:50:04 +08:00
{
this->stop();
}
else
{
2018-05-08 17:40:36 +08:00
_vActions[_nActionIndex]->_init();
2017-10-19 00:50:04 +08:00
}
}
}
void e2d::ActionSequence::reset()
2017-10-19 00:50:04 +08:00
{
ActionBase::reset();
2018-05-08 17:40:36 +08:00
for (auto action : _vActions)
2017-10-19 00:50:04 +08:00
{
2018-02-06 15:34:47 +08:00
action->reset();
2017-10-19 00:50:04 +08:00
}
2018-05-08 17:40:36 +08:00
_nActionIndex = 0;
2017-10-19 00:50:04 +08:00
}
void e2d::ActionSequence::_resetTime()
{
2018-05-08 17:40:36 +08:00
for (auto action : _vActions)
{
2018-02-03 22:04:43 +08:00
action->_resetTime();
}
}
void e2d::ActionSequence::add(ActionBase * action)
2017-10-19 00:50:04 +08:00
{
2017-11-03 22:14:07 +08:00
if (action)
{
2018-05-08 17:40:36 +08:00
_vActions.push_back(action);
2017-11-03 22:14:07 +08:00
action->retain();
}
2017-10-19 00:50:04 +08:00
}
2018-04-24 20:22:41 +08:00
#ifdef HIGHER_THAN_VS2012
2018-05-08 11:37:11 +08:00
void e2d::ActionSequence::add(const std::initializer_list<ActionBase*>& vActions)
{
for (const auto &action : vActions)
{
this->add(action);
}
}
2018-04-01 13:16:07 +08:00
#else
void e2d::ActionSequence::add(int number, ActionBase * action, ...)
2018-04-01 13:16:07 +08:00
{
ActionBase ** ppAction = &action;
2018-04-01 13:16:07 +08:00
while (number > 0)
{
WARN_IF((*ppAction) == nullptr, "ActionSequence NULL pointer exception!");
this->add(*ppAction);
ppAction++;
number--;
}
}
#endif
e2d::ActionSequence * e2d::ActionSequence::clone() const
2017-10-19 00:50:04 +08:00
{
auto a = new ActionSequence();
2018-05-08 17:40:36 +08:00
for (auto action : _vActions)
2017-10-19 00:50:04 +08:00
{
2018-03-06 09:56:17 +08:00
a->add(action->clone());
2017-10-19 00:50:04 +08:00
}
return a;
}
e2d::ActionSequence * e2d::ActionSequence::reverse(bool actionReverse) const
2017-10-19 00:50:04 +08:00
{
auto a = new ActionSequence();
2018-05-08 17:40:36 +08:00
for (auto action : _vActions)
2017-10-19 00:50:04 +08:00
{
if (actionReverse)
{
2018-03-06 09:56:17 +08:00
a->add(action->reverse());
2017-10-19 00:50:04 +08:00
}
else
{
2018-03-06 09:56:17 +08:00
a->add(action->clone());
2017-10-19 00:50:04 +08:00
}
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD><CBB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2018-05-08 17:40:36 +08:00
a->_vActions.reserve(_vActions.size());
2017-10-19 00:50:04 +08:00
return a;
}