Magic_Game/core/actions/Loop.cpp

98 lines
1.2 KiB
C++
Raw Normal View History

#include "..\e2daction.h"
#include "..\e2dmanager.h"
e2d::Loop::Loop(Action * action, int times /* = -1 */)
2018-09-04 22:42:34 +08:00
: action_(action)
, times_(0)
, total_times_(times)
{
2018-05-24 12:24:39 +08:00
WARN_IF(action == nullptr, "Loop NULL pointer exception!");
2018-05-10 14:03:54 +08:00
if (action)
{
2018-09-04 22:42:34 +08:00
action_ = action;
action_->Retain();
2018-05-10 14:03:54 +08:00
}
}
e2d::Loop::~Loop()
{
2018-09-04 22:42:34 +08:00
GC::GetInstance()->SafeRelease(action_);
}
2018-09-04 22:42:34 +08:00
e2d::Loop * e2d::Loop::Clone() const
{
2018-09-04 22:42:34 +08:00
if (action_)
2018-05-10 14:03:54 +08:00
{
2018-09-04 22:42:34 +08:00
return new (e2d::autorelease) Loop(action_->Clone());
2018-05-10 14:03:54 +08:00
}
else
{
return nullptr;
}
}
2018-09-04 22:42:34 +08:00
e2d::Loop * e2d::Loop::Reverse() const
2018-05-14 00:36:01 +08:00
{
2018-09-04 22:42:34 +08:00
if (action_)
2018-05-24 12:24:39 +08:00
{
2018-09-04 22:42:34 +08:00
return new (e2d::autorelease) Loop(action_->Clone());
2018-05-24 12:24:39 +08:00
}
else
{
return nullptr;
}
2018-05-14 00:36:01 +08:00
}
2018-09-04 22:42:34 +08:00
void e2d::Loop::Init()
{
2018-09-04 22:42:34 +08:00
Action::Init();
2018-05-10 14:03:54 +08:00
2018-09-04 22:42:34 +08:00
if (action_)
2018-05-10 14:03:54 +08:00
{
2018-09-04 22:42:34 +08:00
action_->target_ = target_;
action_->Init();
2018-05-10 14:03:54 +08:00
}
}
2018-09-04 22:42:34 +08:00
void e2d::Loop::Update()
{
2018-09-04 22:42:34 +08:00
Action::Update();
2018-09-04 22:42:34 +08:00
if (times_ == total_times_)
{
2018-09-04 22:42:34 +08:00
this->Stop();
return;
}
2018-09-04 22:42:34 +08:00
if (action_)
2018-05-10 14:03:54 +08:00
{
2018-09-04 22:42:34 +08:00
action_->Update();
2018-09-04 22:42:34 +08:00
if (action_->IsDone())
2018-05-10 14:03:54 +08:00
{
2018-09-04 22:42:34 +08:00
++times_;
2018-05-10 14:03:54 +08:00
2018-09-04 22:42:34 +08:00
Action::Reset();
action_->Reset();
2018-05-10 14:03:54 +08:00
}
}
else
{
2018-09-04 22:42:34 +08:00
this->Stop();
}
}
2018-09-04 22:42:34 +08:00
void e2d::Loop::Reset()
{
2018-09-04 22:42:34 +08:00
Action::Reset();
2018-09-04 22:42:34 +08:00
if (action_) action_->Reset();
times_ = 0;
}
2018-09-04 22:42:34 +08:00
void e2d::Loop::ResetTime()
{
2018-09-04 22:42:34 +08:00
if (action_) action_->ResetTime();
}