Magic_Game/core/Action/Spawn.cpp

125 lines
1.7 KiB
C++
Raw Normal View History

#include "..\e2daction.h"
e2d::Spawn::Spawn()
{
}
e2d::Spawn::Spawn(const std::vector<Action*>& actions)
2018-05-10 00:58:43 +08:00
{
this->add(actions);
}
e2d::Spawn::~Spawn()
{
}
void e2d::Spawn::_init()
{
Action::_init();
if (_target)
{
for (auto action : _actions)
{
action->_target = _target;
action->_init();
}
}
}
void e2d::Spawn::onDestroy()
{
Action::onDestroy();
for (auto action : _actions)
{
2018-05-19 01:10:37 +08:00
GC::release(action);
}
}
void e2d::Spawn::_update()
{
Action::_update();
size_t doneNum = 0;
for (auto action : _actions)
{
if (action->_isDone())
{
2018-05-14 22:51:40 +08:00
++doneNum;
}
else
{
action->_update();
}
}
if (doneNum == _actions.size())
{
this->stop();
}
}
void e2d::Spawn::reset()
{
Action::reset();
for (auto action : _actions)
{
action->reset();
}
}
void e2d::Spawn::_resetTime()
{
for (auto action : _actions)
{
action->_resetTime();
}
}
void e2d::Spawn::add(Action * action)
{
if (action)
{
_actions.push_back(action);
action->retain();
}
}
void e2d::Spawn::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::Spawn * e2d::Spawn::clone() const
{
2018-05-19 01:10:37 +08:00
auto spawn = GC::create<Spawn>();
2018-05-10 14:03:54 +08:00
for (const auto& action : _actions)
{
2018-05-10 14:03:54 +08:00
if (action)
{
spawn->add(action->clone());
}
}
2018-05-10 14:03:54 +08:00
return spawn;
}
e2d::Spawn * e2d::Spawn::reverse() const
{
2018-05-19 01:10:37 +08:00
auto spawn = GC::create<Spawn>();
2018-05-24 12:24:39 +08:00
if (spawn && !_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-05-14 00:36:01 +08:00
if (*iter)
{
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
spawn->add(newActions);
}
2018-05-10 14:03:54 +08:00
return spawn;
}