2018-05-08 20:03:29 +08:00
|
|
|
|
#include "..\e2daction.h"
|
|
|
|
|
|
|
|
|
|
|
|
e2d::Sequence::Sequence()
|
2018-09-04 22:42:34 +08:00
|
|
|
|
: action_index_(0)
|
2018-05-08 20:03:29 +08:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
e2d::Sequence::Sequence(const Actions& actions)
|
|
|
|
|
|
: action_index_(0)
|
2018-05-10 00:58:43 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
this->Add(actions);
|
2018-05-08 20:03:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
e2d::Sequence::~Sequence()
|
|
|
|
|
|
{
|
2018-09-07 00:28:54 +08:00
|
|
|
|
for (auto action : actions_)
|
2018-07-07 01:43:41 +08:00
|
|
|
|
{
|
2018-09-07 00:28:54 +08:00
|
|
|
|
SafeRelease(action);
|
2018-07-07 01:43:41 +08:00
|
|
|
|
}
|
2018-05-08 20:03:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Sequence::Init()
|
2018-05-08 20:03:29 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
Action::Init();
|
2018-05-08 20:03:29 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (target_)
|
2018-05-08 20:03:29 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
for (const auto& action : actions_)
|
2018-05-08 20:03:29 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
action->target_ = target_;
|
2018-05-08 20:03:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
// <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2018-09-04 22:42:34 +08:00
|
|
|
|
actions_[0]->Init();
|
2018-05-08 20:03:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Sequence::Update()
|
2018-05-08 20:03:29 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
Action::Update();
|
2018-05-08 20:03:29 +08:00
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
auto &action = actions_[action_index_];
|
|
|
|
|
|
action->Update();
|
2018-05-08 20:03:29 +08:00
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (action->IsDone())
|
2018-05-08 20:03:29 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
++action_index_;
|
|
|
|
|
|
if (action_index_ == actions_.size())
|
2018-05-08 20:03:29 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
this->Stop();
|
2018-05-08 20:03:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
actions_[action_index_]->Init();
|
2018-05-08 20:03:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Sequence::Reset()
|
2018-05-08 20:03:29 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
Action::Reset();
|
|
|
|
|
|
for (const auto& action : actions_)
|
2018-05-08 20:03:29 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
action->Reset();
|
2018-05-08 20:03:29 +08:00
|
|
|
|
}
|
2018-09-04 22:42:34 +08:00
|
|
|
|
action_index_ = 0;
|
2018-05-08 20:03:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Sequence::ResetTime()
|
2018-05-08 20:03:29 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
for (const auto& action : actions_)
|
2018-05-08 20:03:29 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
action->ResetTime();
|
2018-05-08 20:03:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Sequence::Add(Action * action)
|
2018-05-08 20:03:29 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (action)
|
|
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
actions_.push_back(action);
|
|
|
|
|
|
action->Retain();
|
2018-05-08 20:03:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Sequence::Add(const Actions& actions)
|
2018-05-10 00:58:43 +08:00
|
|
|
|
{
|
|
|
|
|
|
for (const auto &action : actions)
|
2018-05-08 20:03:29 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
this->Add(action);
|
2018-05-08 20:03:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
e2d::Sequence * e2d::Sequence::Clone() const
|
2018-05-08 20:03:29 +08:00
|
|
|
|
{
|
2018-09-07 00:28:54 +08:00
|
|
|
|
auto sequence = new Sequence();
|
2018-09-04 22:42:34 +08:00
|
|
|
|
for (const auto& action : actions_)
|
2018-05-08 20:03:29 +08:00
|
|
|
|
{
|
2018-05-10 14:03:54 +08:00
|
|
|
|
if (action)
|
|
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
sequence->Add(action->Clone());
|
2018-05-10 14:03:54 +08:00
|
|
|
|
}
|
2018-05-08 20:03:29 +08:00
|
|
|
|
}
|
2018-05-10 14:03:54 +08:00
|
|
|
|
return sequence;
|
2018-05-08 20:03:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
e2d::Sequence * e2d::Sequence::Reverse() const
|
2018-05-08 20:03:29 +08:00
|
|
|
|
{
|
2018-09-07 00:28:54 +08:00
|
|
|
|
auto sequence = new Sequence();
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (sequence && !actions_.empty())
|
2018-05-08 20:03:29 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +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-09-04 22:42:34 +08:00
|
|
|
|
newActions.push_back((*iter)->Reverse());
|
2018-05-10 14:03:54 +08:00
|
|
|
|
}
|
2018-09-04 22:42:34 +08:00
|
|
|
|
sequence->Add(newActions);
|
2018-05-08 20:03:29 +08:00
|
|
|
|
}
|
2018-05-10 14:03:54 +08:00
|
|
|
|
return sequence;
|
2018-05-08 20:03:29 +08:00
|
|
|
|
}
|