diff --git a/projects/kiwano/kiwano.vcxproj b/projects/kiwano/kiwano.vcxproj index 48309922..194381e3 100644 --- a/projects/kiwano/kiwano.vcxproj +++ b/projects/kiwano/kiwano.vcxproj @@ -15,6 +15,7 @@ + diff --git a/projects/kiwano/kiwano.vcxproj.filters b/projects/kiwano/kiwano.vcxproj.filters index 10e905b5..5a06fc89 100644 --- a/projects/kiwano/kiwano.vcxproj.filters +++ b/projects/kiwano/kiwano.vcxproj.filters @@ -321,6 +321,9 @@ core + + core + diff --git a/src/kiwano/2d/action/Action.cpp b/src/kiwano/2d/action/Action.cpp index f5881b98..6dc75105 100644 --- a/src/kiwano/2d/action/Action.cpp +++ b/src/kiwano/2d/action/Action.cpp @@ -105,7 +105,7 @@ void Action::Restart(Actor* target) Init(target); } -ActionPtr Action::InnerClone(ActionPtr to) const +ActionPtr Action::DoClone(ActionPtr to) const { if (to) { diff --git a/src/kiwano/2d/action/Action.h b/src/kiwano/2d/action/Action.h index f90de19e..f8d79e4a 100644 --- a/src/kiwano/2d/action/Action.h +++ b/src/kiwano/2d/action/Action.h @@ -20,6 +20,7 @@ #pragma once #include +#include #include #include #include @@ -51,6 +52,7 @@ typedef IntrusiveList ActionList; /// @brief 动画 class KGE_API Action : public ObjectBase + , public Cloneable , protected IntrusiveListValue { friend class ActionManager; @@ -99,10 +101,6 @@ public: /// @brief 设置动画循环结束时的回调函数 void SetLoopDoneCallback(const DoneCallback& cb); - /// \~chinese - /// @brief 获取动画的拷贝 - virtual ActionPtr Clone() const = 0; - /// \~chinese /// @brief 获取动画的倒转 virtual ActionPtr Reverse() const = 0; @@ -184,7 +182,7 @@ protected: bool IsRemoveable() const; protected: - ActionPtr InnerClone(ActionPtr to) const; + ActionPtr DoClone(ActionPtr to) const; private: Status status_; diff --git a/src/kiwano/2d/action/ActionDelay.cpp b/src/kiwano/2d/action/ActionDelay.cpp index a8857156..3450ab6c 100644 --- a/src/kiwano/2d/action/ActionDelay.cpp +++ b/src/kiwano/2d/action/ActionDelay.cpp @@ -35,12 +35,12 @@ ActionDelayPtr ActionDelay::Create(Duration delay) ActionPtr ActionDelay::Clone() const { - return InnerClone(ActionDelay::Create(GetDelay())); + return DoClone(ActionDelay::Create(GetDelay())); } ActionPtr ActionDelay::Reverse() const { - return InnerClone(ActionDelay::Create(GetDelay())); + return DoClone(ActionDelay::Create(GetDelay())); } } // namespace kiwano diff --git a/src/kiwano/2d/action/ActionGroup.cpp b/src/kiwano/2d/action/ActionGroup.cpp index 7a0ebaca..520065c3 100644 --- a/src/kiwano/2d/action/ActionGroup.cpp +++ b/src/kiwano/2d/action/ActionGroup.cpp @@ -133,7 +133,7 @@ ActionPtr ActionGroup::Clone() const actions.push_back(action->Clone()); } } - return InnerClone(ActionGroup::Create(actions, sync_)); + return DoClone(ActionGroup::Create(actions, sync_)); } ActionPtr ActionGroup::Reverse() const @@ -146,7 +146,7 @@ ActionPtr ActionGroup::Reverse() const actions.push_back(action->Reverse()); } } - return InnerClone(ActionGroup::Create(actions, sync_)); + return DoClone(ActionGroup::Create(actions, sync_)); } } // namespace kiwano diff --git a/src/kiwano/2d/action/ActionTween.cpp b/src/kiwano/2d/action/ActionTween.cpp index aefec650..dc5849c2 100644 --- a/src/kiwano/2d/action/ActionTween.cpp +++ b/src/kiwano/2d/action/ActionTween.cpp @@ -129,15 +129,14 @@ void ActionTween::Update(Actor* target, Duration dt) UpdateTween(target, percent); } -ActionPtr ActionTween::InnerClone(ActionTweenPtr to) const +ActionPtr ActionTween::DoClone(ActionTweenPtr to) const { if (to) { - (void)Action::InnerClone(to); to->SetDuration(this->GetDuration()); to->SetEaseFunc(this->GetEaseFunc()); } - return to; + return Action::DoClone(to); } //------------------------------------------------------- @@ -178,12 +177,12 @@ void ActionMoveBy::UpdateTween(Actor* target, float percent) ActionPtr ActionMoveBy::Clone() const { - return InnerClone(ActionMoveBy::Create(GetDuration(), displacement_)); + return DoClone(ActionMoveBy::Create(GetDuration(), displacement_)); } ActionPtr ActionMoveBy::Reverse() const { - return InnerClone(ActionMoveBy::Create(GetDuration(), -displacement_)); + return DoClone(ActionMoveBy::Create(GetDuration(), -displacement_)); } ActionMoveToPtr ActionMoveTo::Create(Duration duration, const Point& distination) @@ -201,7 +200,7 @@ ActionMoveTo::ActionMoveTo() {} ActionPtr ActionMoveTo::Clone() const { - return InnerClone(ActionMoveTo::Create(GetDuration(), distination_)); + return DoClone(ActionMoveTo::Create(GetDuration(), distination_)); } void ActionMoveTo::Init(Actor* target) @@ -237,12 +236,12 @@ ActionJumpBy::ActionJumpBy() ActionPtr ActionJumpBy::Clone() const { - return InnerClone(ActionJumpBy::Create(GetDuration(), displacement_, height_, jump_count_)); + return DoClone(ActionJumpBy::Create(GetDuration(), displacement_, height_, jump_count_)); } ActionPtr ActionJumpBy::Reverse() const { - return InnerClone(ActionJumpBy::Create(GetDuration(), -displacement_, height_, jump_count_)); + return DoClone(ActionJumpBy::Create(GetDuration(), -displacement_, height_, jump_count_)); } void ActionJumpBy::Init(Actor* target) @@ -288,7 +287,7 @@ ActionJumpTo::ActionJumpTo() {} ActionPtr ActionJumpTo::Clone() const { - return InnerClone(ActionJumpTo::Create(GetDuration(), distination_, height_, jump_count_)); + return DoClone(ActionJumpTo::Create(GetDuration(), distination_, height_, jump_count_)); } void ActionJumpTo::Init(Actor* target) @@ -337,12 +336,12 @@ void ActionScaleBy::UpdateTween(Actor* target, float percent) ActionPtr ActionScaleBy::Clone() const { - return InnerClone(ActionScaleBy::Create(GetDuration(), delta_x_, delta_y_)); + return DoClone(ActionScaleBy::Create(GetDuration(), delta_x_, delta_y_)); } ActionPtr ActionScaleBy::Reverse() const { - return InnerClone(ActionScaleBy::Create(GetDuration(), -delta_x_, -delta_y_)); + return DoClone(ActionScaleBy::Create(GetDuration(), -delta_x_, -delta_y_)); } ActionScaleToPtr ActionScaleTo::Create(Duration duration, float scale_x, float scale_y) @@ -365,7 +364,7 @@ ActionScaleTo::ActionScaleTo() ActionPtr ActionScaleTo::Clone() const { - return InnerClone(ActionScaleTo::Create(GetDuration(), end_scale_x_, end_scale_y_)); + return DoClone(ActionScaleTo::Create(GetDuration(), end_scale_x_, end_scale_y_)); } void ActionScaleTo::Init(Actor* target) @@ -413,7 +412,7 @@ void ActionFadeTo::UpdateTween(Actor* target, float percent) ActionPtr ActionFadeTo::Clone() const { - return InnerClone(ActionFadeTo::Create(GetDuration(), end_val_)); + return DoClone(ActionFadeTo::Create(GetDuration(), end_val_)); } ActionFadeInPtr ActionFadeIn::Create(Duration duration) @@ -478,12 +477,12 @@ void ActionRotateBy::UpdateTween(Actor* target, float percent) ActionPtr ActionRotateBy::Clone() const { - return InnerClone(ActionRotateBy::Create(GetDuration(), delta_val_)); + return DoClone(ActionRotateBy::Create(GetDuration(), delta_val_)); } ActionPtr ActionRotateBy::Reverse() const { - return InnerClone(ActionRotateBy::Create(GetDuration(), -delta_val_)); + return DoClone(ActionRotateBy::Create(GetDuration(), -delta_val_)); } ActionRotateToPtr ActionRotateTo::Create(Duration duration, float rotation) @@ -504,7 +503,7 @@ ActionRotateTo::ActionRotateTo() ActionPtr ActionRotateTo::Clone() const { - return InnerClone(ActionRotateTo::Create(GetDuration(), end_val_)); + return DoClone(ActionRotateTo::Create(GetDuration(), end_val_)); } void ActionRotateTo::Init(Actor* target) @@ -532,7 +531,7 @@ ActionCustom::ActionCustom() {} ActionPtr ActionCustom::Clone() const { - return InnerClone(ActionCustom::Create(GetDuration(), tween_func_)); + return DoClone(ActionCustom::Create(GetDuration(), tween_func_)); } void ActionCustom::Init(Actor* target) diff --git a/src/kiwano/2d/action/ActionTween.h b/src/kiwano/2d/action/ActionTween.h index 8fb8e1a3..6f271cd9 100644 --- a/src/kiwano/2d/action/ActionTween.h +++ b/src/kiwano/2d/action/ActionTween.h @@ -119,7 +119,7 @@ protected: virtual void UpdateTween(Actor* target, float percent) = 0; - ActionPtr InnerClone(ActionTweenPtr to) const; + ActionPtr DoClone(ActionTweenPtr to) const; private: Duration dur_; diff --git a/src/kiwano/2d/action/ActionWalk.cpp b/src/kiwano/2d/action/ActionWalk.cpp index 38c3d2b5..c286e764 100644 --- a/src/kiwano/2d/action/ActionWalk.cpp +++ b/src/kiwano/2d/action/ActionWalk.cpp @@ -48,12 +48,12 @@ ActionWalk::ActionWalk() ActionPtr ActionWalk::Clone() const { - return InnerClone(ActionWalk::Create(GetDuration(), path_, rotating_, start_, end_)); + return DoClone(ActionWalk::Create(GetDuration(), path_, rotating_, start_, end_)); } ActionPtr ActionWalk::Reverse() const { - return InnerClone(ActionWalk::Create(GetDuration(), path_, rotating_, end_, start_)); + return DoClone(ActionWalk::Create(GetDuration(), path_, rotating_, end_, start_)); } void ActionWalk::Init(Actor* target) diff --git a/src/kiwano/2d/action/Animation.cpp b/src/kiwano/2d/action/Animation.cpp index afcd34d0..1abdaae1 100644 --- a/src/kiwano/2d/action/Animation.cpp +++ b/src/kiwano/2d/action/Animation.cpp @@ -89,7 +89,7 @@ ActionPtr Animation::Clone() const { if (frame_seq_) { - return InnerClone(Animation::Create(GetDuration(), frame_seq_)); + return DoClone(Animation::Create(GetDuration(), frame_seq_)); } return nullptr; } @@ -101,7 +101,7 @@ ActionPtr Animation::Reverse() const FrameSequencePtr frames = frame_seq_->Reverse(); if (frames) { - return InnerClone(Animation::Create(GetDuration(), frames)); + return DoClone(Animation::Create(GetDuration(), frames)); } } return nullptr; diff --git a/src/kiwano/core/Cloneable.h b/src/kiwano/core/Cloneable.h new file mode 100644 index 00000000..78f48c76 --- /dev/null +++ b/src/kiwano/core/Cloneable.h @@ -0,0 +1,42 @@ +// Copyright (c) 2016-2018 Kiwano - Nomango +// +// 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 +#include + +namespace kiwano +{ + +template +class Cloneable +{ +public: + virtual SmartPtr<_Ty> Clone() const = 0; + +protected: + Cloneable() = default; + +private: + Cloneable(const Cloneable&) = delete; + + Cloneable& operator=(const Cloneable&) = delete; +}; + +} // namespace kiwano