Magic_Game/core/Action/ActionSequence.cpp

120 lines
1.8 KiB
C++
Raw Normal View History

2017-10-19 00:50:04 +08:00
#include "..\eactions.h"
e2d::ActionSequence::ActionSequence() :
2017-10-19 00:50:04 +08:00
m_nActionIndex(0)
{
}
e2d::ActionSequence::ActionSequence(int number, Action * action1, ...) :
2017-10-19 00:50:04 +08:00
m_nActionIndex(0)
{
Action ** ppAction = &action1;
2017-10-19 00:50:04 +08:00
while (number > 0)
{
ASSERT((*ppAction) != nullptr, "ActionSequence NULL pointer exception!");
this->_add(*ppAction);
2017-11-03 22:14:07 +08:00
ppAction++;
2017-10-19 00:50:04 +08:00
number--;
}
}
e2d::ActionSequence::~ActionSequence()
2017-10-19 00:50:04 +08:00
{
2018-02-03 22:04:43 +08:00
for (auto action : m_vActions)
2017-10-19 00:50:04 +08:00
{
2018-02-03 22:04:43 +08:00
SafeRelease(&action);
2017-10-19 00:50:04 +08:00
}
}
void e2d::ActionSequence::_init()
2017-10-19 00:50:04 +08:00
{
Action::_init();
2017-10-19 00:50:04 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (m_pTarget)
2017-10-19 00:50:04 +08:00
{
2018-02-03 22:04:43 +08:00
for (auto action : m_vActions)
{
2018-02-06 15:34:47 +08:00
action->m_pTarget = m_pTarget;
}
2017-10-19 00:50:04 +08:00
}
// <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
m_vActions[0]->_init();
}
void e2d::ActionSequence::_update()
2017-10-19 00:50:04 +08:00
{
Action::_update();
2017-11-03 12:51:01 +08:00
2017-10-21 19:09:31 +08:00
auto &action = m_vActions[m_nActionIndex];
action->_update();
2017-10-19 00:50:04 +08:00
2017-10-21 19:09:31 +08:00
if (action->_isEnding())
2017-10-19 00:50:04 +08:00
{
m_nActionIndex++;
if (m_nActionIndex == m_vActions.size())
{
this->stop();
}
else
{
m_vActions[m_nActionIndex]->_init();
}
}
}
void e2d::ActionSequence::reset()
2017-10-19 00:50:04 +08:00
{
Action::reset();
2018-02-03 22:04:43 +08:00
for (auto action : m_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
}
m_nActionIndex = 0;
}
void e2d::ActionSequence::_resetTime()
{
2018-02-03 22:04:43 +08:00
for (auto action : m_vActions)
{
2018-02-03 22:04:43 +08:00
action->_resetTime();
}
}
void e2d::ActionSequence::_add(Action * action)
2017-10-19 00:50:04 +08:00
{
2017-11-03 22:14:07 +08:00
if (action)
{
m_vActions.push_back(action);
action->retain();
}
2017-10-19 00:50:04 +08:00
}
e2d::ActionSequence * e2d::ActionSequence::clone() const
2017-10-19 00:50:04 +08:00
{
auto a = new ActionSequence();
2018-02-03 22:04:43 +08:00
for (auto action : m_vActions)
2017-10-19 00:50:04 +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-02-03 22:04:43 +08:00
for (auto action : m_vActions)
2017-10-19 00:50:04 +08:00
{
if (actionReverse)
{
a->_add(action->reverse());
2017-10-19 00:50:04 +08:00
}
else
{
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>
a->m_vActions.reserve(m_vActions.size());
return a;
}