2019-04-11 14:40:54 +08:00
|
|
|
|
// Copyright (c) 2016-2018 Kiwano - Nomango
|
2019-03-31 01:37:06 +08:00
|
|
|
|
//
|
|
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
|
// in the Software without restriction, including without limitation the rights
|
|
|
|
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
|
// furnished to do so, subject to the following conditions:
|
|
|
|
|
|
//
|
|
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
|
|
//
|
|
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
|
|
// THE SOFTWARE.
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
2019-12-23 18:05:08 +08:00
|
|
|
|
#include <kiwano/core/common.h>
|
|
|
|
|
|
#include <kiwano/core/time.h>
|
|
|
|
|
|
#include <kiwano/core/SmartPtr.hpp>
|
|
|
|
|
|
#include <kiwano/core/ObjectBase.h>
|
|
|
|
|
|
#include <kiwano/math/math.h>
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
2019-04-11 14:40:54 +08:00
|
|
|
|
namespace kiwano
|
2019-03-31 01:37:06 +08:00
|
|
|
|
{
|
2019-12-23 18:05:08 +08:00
|
|
|
|
class Actor;
|
2019-03-31 01:37:06 +08:00
|
|
|
|
class ActionManager;
|
|
|
|
|
|
|
2019-12-23 18:05:08 +08:00
|
|
|
|
KGE_DECLARE_SMART_PTR(Action);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* \~chinese
|
|
|
|
|
|
* \defgroup Actions <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* \addtogroup Actions
|
|
|
|
|
|
* @{
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD>
|
2019-04-11 14:40:54 +08:00
|
|
|
|
class KGE_API Action
|
2019-08-18 10:23:54 +08:00
|
|
|
|
: public ObjectBase
|
2019-10-30 23:12:18 +08:00
|
|
|
|
, protected IntrusiveListItem<ActionPtr>
|
2019-03-31 01:37:06 +08:00
|
|
|
|
{
|
|
|
|
|
|
friend class ActionManager;
|
|
|
|
|
|
friend class ActionGroup;
|
2019-10-30 23:12:18 +08:00
|
|
|
|
friend IntrusiveList<ActionPtr>;
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
|
|
|
|
|
public:
|
2019-12-23 18:05:08 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>Ļص<C4BB><D8B5><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
using DoneCallback = Function<void()>;
|
|
|
|
|
|
|
2019-03-31 01:37:06 +08:00
|
|
|
|
Action();
|
|
|
|
|
|
|
|
|
|
|
|
virtual ~Action();
|
|
|
|
|
|
|
2019-12-23 18:05:08 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2019-11-07 18:16:28 +08:00
|
|
|
|
void Resume();
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
2019-12-23 18:05:08 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD>
|
2019-11-07 18:16:28 +08:00
|
|
|
|
void Pause();
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
2019-12-23 18:05:08 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD>
|
2019-11-07 18:16:28 +08:00
|
|
|
|
void Stop();
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
2019-12-23 18:05:08 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD>ö<EFBFBD><C3B6><EFBFBD><EFBFBD><EFBFBD>ʱ
|
2019-11-07 18:16:28 +08:00
|
|
|
|
void SetDelay(Duration delay);
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
2019-12-23 18:05:08 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
/// @param loops ѭ<><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-1 Ϊ<><CEAA><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD>
|
2019-11-07 18:16:28 +08:00
|
|
|
|
void SetLoops(int loops);
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
2019-12-23 18:05:08 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>Ƴ<EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD>ɫ
|
2019-11-07 18:16:28 +08:00
|
|
|
|
void RemoveTargetWhenDone();
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
2019-12-23 18:05:08 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD>ö<EFBFBD><C3B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>Ļص<C4BB><D8B5><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
void SetDoneCallback(DoneCallback const& cb);
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
2019-12-23 18:05:08 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD>ö<EFBFBD><C3B6><EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>Ļص<C4BB><D8B5><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
void SetLoopDoneCallback(DoneCallback const& cb);
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
2019-12-23 18:05:08 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD>
|
2019-03-31 01:37:06 +08:00
|
|
|
|
virtual ActionPtr Clone() const = 0;
|
|
|
|
|
|
|
2019-12-23 18:05:08 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>ת
|
2019-03-31 01:37:06 +08:00
|
|
|
|
virtual ActionPtr Reverse() const = 0;
|
|
|
|
|
|
|
2019-12-23 18:05:08 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
|
2019-11-07 18:16:28 +08:00
|
|
|
|
bool IsRunning() const;
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
2019-12-23 18:05:08 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2019-11-07 18:16:28 +08:00
|
|
|
|
int GetLoops() const;
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
2019-12-23 18:05:08 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ
|
2019-11-07 18:16:28 +08:00
|
|
|
|
Duration GetDelay() const;
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
2019-12-23 18:05:08 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>Ļص<C4BB><D8B5><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
DoneCallback GetDoneCallback() const;
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
2019-12-23 18:05:08 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>Ļص<C4BB><D8B5><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
DoneCallback GetLoopDoneCallback() const;
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
|
|
|
|
|
protected:
|
2019-12-23 18:05:08 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
virtual void Init(Actor* target);
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
2019-12-23 18:05:08 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD>¶<EFBFBD><C2B6><EFBFBD>
|
|
|
|
|
|
virtual void Update(Actor* target, Duration dt);
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
2019-12-23 18:05:08 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ʱ<EFBFBD>䲽
|
|
|
|
|
|
void UpdateStep(Actor* target, Duration dt);
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
2019-12-23 18:05:08 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD>ɶ<EFBFBD><C9B6><EFBFBD>
|
|
|
|
|
|
void Complete(Actor* target);
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
2019-12-23 18:05:08 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD>¿<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
|
|
|
|
|
|
void Restart(Actor* target);
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
2019-12-23 18:05:08 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD>״̬
|
2019-11-07 18:16:28 +08:00
|
|
|
|
enum class Status
|
|
|
|
|
|
{
|
2019-12-23 18:05:08 +08:00
|
|
|
|
NotStarted, ///< δ<><CEB4>ʼ
|
|
|
|
|
|
Delayed, ///< <20>ȴ<EFBFBD><C8B4><EFBFBD>ʱ
|
|
|
|
|
|
Started, ///< <20>ѿ<EFBFBD>ʼ
|
|
|
|
|
|
Done, ///< <20>ѽ<EFBFBD><D1BD><EFBFBD>
|
|
|
|
|
|
Removeable ///< <20><><EFBFBD>Ƴ<EFBFBD>
|
2019-11-07 18:16:28 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2019-12-23 18:05:08 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>״̬
|
2019-11-07 18:16:28 +08:00
|
|
|
|
Status GetStatus() const;
|
|
|
|
|
|
|
2019-12-23 18:05:08 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
2019-11-07 18:16:28 +08:00
|
|
|
|
Duration GetElapsed() const;
|
|
|
|
|
|
|
2019-12-23 18:05:08 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD>ɵ<EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2019-11-07 18:16:28 +08:00
|
|
|
|
int GetLoopsDone() const;
|
|
|
|
|
|
|
2019-12-23 18:05:08 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2019-11-07 18:16:28 +08:00
|
|
|
|
void Done();
|
|
|
|
|
|
|
2019-12-23 18:05:08 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20>Ƿ<EFBFBD><C7B7>ѽ<EFBFBD><D1BD><EFBFBD>
|
2019-11-07 18:16:28 +08:00
|
|
|
|
bool IsDone() const;
|
|
|
|
|
|
|
2019-12-23 18:05:08 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>Ƴ<EFBFBD>
|
2019-11-07 18:16:28 +08:00
|
|
|
|
bool IsRemoveable() const;
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
2019-03-31 01:37:06 +08:00
|
|
|
|
Status status_;
|
|
|
|
|
|
bool running_;
|
|
|
|
|
|
bool detach_target_;
|
2019-09-29 22:23:13 +08:00
|
|
|
|
int loops_;
|
|
|
|
|
|
int loops_done_;
|
2019-03-31 01:37:06 +08:00
|
|
|
|
Duration delay_;
|
|
|
|
|
|
Duration elapsed_;
|
2019-12-23 18:05:08 +08:00
|
|
|
|
DoneCallback cb_done_;
|
|
|
|
|
|
DoneCallback cb_loop_done_;
|
2019-03-31 01:37:06 +08:00
|
|
|
|
};
|
2019-11-07 18:16:28 +08:00
|
|
|
|
|
2019-12-23 18:05:08 +08:00
|
|
|
|
/** @} */
|
|
|
|
|
|
|
2019-11-07 18:16:28 +08:00
|
|
|
|
|
|
|
|
|
|
inline void Action::Resume()
|
|
|
|
|
|
{
|
|
|
|
|
|
running_ = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void Action::Pause()
|
|
|
|
|
|
{
|
|
|
|
|
|
running_ = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void Action::Stop()
|
|
|
|
|
|
{
|
|
|
|
|
|
Done();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void Action::SetDelay(Duration delay)
|
|
|
|
|
|
{
|
|
|
|
|
|
delay_ = delay;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void Action::SetLoops(int loops)
|
|
|
|
|
|
{
|
|
|
|
|
|
loops_ = loops;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void Action::RemoveTargetWhenDone()
|
|
|
|
|
|
{
|
|
|
|
|
|
detach_target_ = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-23 18:05:08 +08:00
|
|
|
|
inline void Action::SetDoneCallback(DoneCallback const& cb)
|
2019-11-07 18:16:28 +08:00
|
|
|
|
{
|
|
|
|
|
|
cb_done_ = cb;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-23 18:05:08 +08:00
|
|
|
|
inline void Action::SetLoopDoneCallback(DoneCallback const& cb)
|
2019-11-07 18:16:28 +08:00
|
|
|
|
{
|
|
|
|
|
|
cb_loop_done_ = cb;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void Action::Done()
|
|
|
|
|
|
{
|
|
|
|
|
|
status_ = Status::Done;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline Action::Status Action::GetStatus() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return status_;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline bool Action::IsRunning() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return running_;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline bool Action::IsDone() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return status_ == Status::Done || status_ == Status::Removeable;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline bool Action::IsRemoveable() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return status_ == Status::Removeable;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline int Action::GetLoops() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return loops_;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline Duration Action::GetDelay() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return delay_;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline Duration Action::GetElapsed() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return elapsed_;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline int Action::GetLoopsDone() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return loops_done_;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-23 18:05:08 +08:00
|
|
|
|
inline Action::DoneCallback Action::GetDoneCallback() const
|
2019-11-07 18:16:28 +08:00
|
|
|
|
{
|
|
|
|
|
|
return cb_done_;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-23 18:05:08 +08:00
|
|
|
|
inline Action::DoneCallback Action::GetLoopDoneCallback() const
|
2019-11-07 18:16:28 +08:00
|
|
|
|
{
|
|
|
|
|
|
return cb_loop_done_;
|
|
|
|
|
|
}
|
2019-03-31 01:37:06 +08:00
|
|
|
|
}
|