some optimization

minor

minor

minor

minor

minor

minor

minor

minor

minor

minor fixes
This commit is contained in:
Nomango 2019-05-03 15:27:18 +08:00 committed by Nomango
parent d76a4de248
commit 0742b0c02d
59 changed files with 450 additions and 364 deletions

View File

@ -36,7 +36,16 @@ namespace kiwano
{ {
} }
void Action::UpdateStep(NodePtr const& target, Duration dt) void Action::Init(NodePtr target)
{
}
void Action::Update(NodePtr target, Duration dt)
{
Complete(target);
}
void Action::UpdateStep(NodePtr target, Duration dt)
{ {
elapsed_ += dt; elapsed_ += dt;
@ -72,7 +81,7 @@ namespace kiwano
} }
} }
void Action::Complete(NodePtr const& target) void Action::Complete(NodePtr target)
{ {
if (cb_loop_done_) if (cb_loop_done_)
cb_loop_done_(); cb_loop_done_();
@ -90,7 +99,7 @@ namespace kiwano
++loops_done_; ++loops_done_;
} }
void Action::Restart(NodePtr const & target) void Action::Restart(NodePtr target)
{ {
status_ = Status::NotStarted; status_ = Status::NotStarted;
elapsed_ = 0; elapsed_ = 0;

View File

@ -95,20 +95,20 @@ namespace kiwano
inline Duration GetElapsed() const { return elapsed_; } inline Duration GetElapsed() const { return elapsed_; }
inline ActionCallback const& GetDoneCallback() const { return cb_done_; } inline ActionCallback GetDoneCallback() const { return cb_done_; }
inline ActionCallback const& GetLoopDoneCallback() const { return cb_loop_done_; } inline ActionCallback GetLoopDoneCallback() const { return cb_loop_done_; }
protected: protected:
virtual void Init(NodePtr const& target) {} virtual void Init(NodePtr target);
virtual void Update(NodePtr const& target, Duration dt) { Complete(target); } virtual void Update(NodePtr target, Duration dt);
void UpdateStep(NodePtr const& target, Duration dt); void UpdateStep(NodePtr target, Duration dt);
void Complete(NodePtr const& target); void Complete(NodePtr target);
void Restart(NodePtr const& target); void Restart(NodePtr target);
protected: protected:
Status status_; Status status_;

View File

@ -19,6 +19,7 @@
// THE SOFTWARE. // THE SOFTWARE.
#include "ActionGroup.h" #include "ActionGroup.h"
#include "Node.h"
#include "../base/logs.h" #include "../base/logs.h"
namespace kiwano namespace kiwano
@ -42,7 +43,7 @@ namespace kiwano
{ {
} }
void ActionGroup::Init(NodePtr const& target) void ActionGroup::Init(NodePtr target)
{ {
if (actions_.IsEmpty()) if (actions_.IsEmpty())
{ {
@ -63,7 +64,7 @@ namespace kiwano
} }
} }
void ActionGroup::Update(NodePtr const& target, Duration dt) void ActionGroup::Update(NodePtr target, Duration dt)
{ {
if (sequence_) if (sequence_)
{ {
@ -101,7 +102,7 @@ namespace kiwano
} }
} }
void ActionGroup::Add(ActionPtr const& action) void ActionGroup::Add(ActionPtr action)
{ {
if (action) if (action)
{ {

View File

@ -41,7 +41,7 @@ namespace kiwano
// 添加动作 // 添加动作
void Add( void Add(
ActionPtr const& action ActionPtr action
); );
// 添加多个动作 // 添加多个动作
@ -60,10 +60,10 @@ namespace kiwano
protected: protected:
// 初始化动作 // 初始化动作
void Init(NodePtr const& target) override; void Init(NodePtr target) override;
// 更新动作 // 更新动作
void Update(NodePtr const& target, Duration dt) override; void Update(NodePtr target, Duration dt) override;
protected: protected:
bool sequence_; bool sequence_;

View File

@ -46,9 +46,9 @@ namespace kiwano
inline ActionHelper& SetName(String const& name) { base->SetName(name); return (*this); } inline ActionHelper& SetName(String const& name) { base->SetName(name); return (*this); }
// 获取指针 // 获取指针
inline ActionPtr const& Get() const { return base; } inline ActionPtr Get() const { return base; }
inline ActionHelper(ActionPtr const& base) : base(base) {} inline ActionHelper(ActionPtr base) : base(base) {}
inline operator ActionPtr() const { return base; } inline operator ActionPtr() const { return base; }
@ -83,12 +83,14 @@ namespace kiwano
inline TweenHelper& SetName(String const& name) { base->SetName(name); return (*this); } inline TweenHelper& SetName(String const& name) { base->SetName(name); return (*this); }
// 获取指针 // 获取指针
inline ActionTweenPtr const& Get() const { return base; } inline ActionTweenPtr Get() const { return base; }
inline TweenHelper(ActionTweenPtr const& base) : base(base) {} inline TweenHelper(ActionTweenPtr base) : base(base) {}
inline operator ActionPtr() const { return base; } inline operator ActionPtr() const { return base; }
inline operator ActionTweenPtr() const { return base; }
protected: protected:
ActionTweenPtr base; ActionTweenPtr base;
}; };
@ -189,7 +191,7 @@ namespace kiwano
static inline TweenHelper static inline TweenHelper
Path( Path(
GeometryPtr const& geo, /* ¼¸ºÎͼÐÎ */ GeometryPtr geo, /* ¼¸ºÎͼÐÎ */
bool rotating = false, /* 沿路径切线方向旋转 */ bool rotating = false, /* 沿路径切线方向旋转 */
float start = 0.f, /* 起点 */ float start = 0.f, /* 起点 */
float end = 1.f) /* 终点 */ float end = 1.f) /* 终点 */
@ -198,7 +200,7 @@ namespace kiwano
} }
static inline TweenHelper static inline TweenHelper
Animation(FramesPtr const& frames) Animation(FramesPtr frames)
{ {
return TweenHelper(new kiwano::Animation(0, frames)); return TweenHelper(new kiwano::Animation(0, frames));
} }
@ -221,6 +223,9 @@ namespace kiwano
return ActionHelper(new kiwano::ActionGroup(actions, false)); return ActionHelper(new kiwano::ActionGroup(actions, false));
} }
#pragma warning(push)
#pragma warning(disable : 4996)
KGE_DEPRECATED("Tween::Sequence is deprecated, use Tween::Group instead") KGE_DEPRECATED("Tween::Sequence is deprecated, use Tween::Group instead")
static inline ActionHelper static inline ActionHelper
Sequence(Array<ActionPtr> const& actions) Sequence(Array<ActionPtr> const& actions)
@ -234,5 +239,7 @@ namespace kiwano
{ {
return ActionHelper(new kiwano::ActionGroup(actions, false)); return ActionHelper(new kiwano::ActionGroup(actions, false));
} }
#pragma warning(pop)
}; };
} }

View File

@ -19,11 +19,12 @@
// THE SOFTWARE. // THE SOFTWARE.
#include "ActionManager.h" #include "ActionManager.h"
#include "Node.h"
#include "../base/logs.h" #include "../base/logs.h"
namespace kiwano namespace kiwano
{ {
void ActionManager::UpdateActions(NodePtr const& target, Duration dt) void ActionManager::UpdateActions(NodePtr target, Duration dt)
{ {
if (actions_.IsEmpty() || !target) if (actions_.IsEmpty() || !target)
return; return;
@ -41,7 +42,7 @@ namespace kiwano
} }
} }
ActionPtr ActionManager::AddAction(ActionPtr const& action) ActionPtr ActionManager::AddAction(ActionPtr action)
{ {
KGE_ASSERT(action && "AddAction failed, NULL pointer exception"); KGE_ASSERT(action && "AddAction failed, NULL pointer exception");

View File

@ -30,7 +30,7 @@ namespace kiwano
public: public:
// 添加动作 // 添加动作
ActionPtr AddAction( ActionPtr AddAction(
ActionPtr const& action ActionPtr action
); );
// 获取动作 // 获取动作
@ -51,7 +51,7 @@ namespace kiwano
Actions const& GetAllActions() const; Actions const& GetAllActions() const;
protected: protected:
void UpdateActions(NodePtr const& target, Duration dt); void UpdateActions(NodePtr target, Duration dt);
protected: protected:
Actions actions_; Actions actions_;

View File

@ -28,6 +28,13 @@ namespace kiwano
// Ease Functions // Ease Functions
//------------------------------------------------------- //-------------------------------------------------------
inline EaseFunc MakeEaseIn(float rate) { return std::bind(math::EaseIn, std::placeholders::_1, rate); }
inline EaseFunc MakeEaseOut(float rate) { return std::bind(math::EaseOut, std::placeholders::_1, rate); }
inline EaseFunc MakeEaseInOut(float rate) { return std::bind(math::EaseInOut, std::placeholders::_1, rate); }
inline EaseFunc MakeEaseElasticIn(float period) { return std::bind(math::EaseElasticIn, std::placeholders::_1, period); }
inline EaseFunc MakeEaseElasticOut(float period) { return std::bind(math::EaseElasticOut, std::placeholders::_1, period); }
inline EaseFunc MakeEaseElasticInOut(float period) { return std::bind(math::EaseElasticInOut, std::placeholders::_1, period); }
EaseFunc Ease::Linear = math::Linear; EaseFunc Ease::Linear = math::Linear;
EaseFunc Ease::EaseIn = MakeEaseIn(2.f); EaseFunc Ease::EaseIn = MakeEaseIn(2.f);
EaseFunc Ease::EaseOut = MakeEaseOut(2.f); EaseFunc Ease::EaseOut = MakeEaseOut(2.f);
@ -91,7 +98,7 @@ namespace kiwano
return dur_; return dur_;
} }
void ActionTween::Update(NodePtr const& target, Duration dt) void ActionTween::Update(NodePtr target, Duration dt)
{ {
float percent; float percent;
@ -135,7 +142,7 @@ namespace kiwano
delta_pos_ = vector; delta_pos_ = vector;
} }
void ActionMoveBy::Init(NodePtr const& target) void ActionMoveBy::Init(NodePtr target)
{ {
if (target) if (target)
{ {
@ -143,7 +150,7 @@ namespace kiwano
} }
} }
void ActionMoveBy::UpdateTween(NodePtr const& target, float percent) void ActionMoveBy::UpdateTween(NodePtr target, float percent)
{ {
Point diff = target->GetPosition() - prev_pos_; Point diff = target->GetPosition() - prev_pos_;
start_pos_ = start_pos_ + diff; start_pos_ = start_pos_ + diff;
@ -175,7 +182,7 @@ namespace kiwano
return new (std::nothrow) ActionMoveTo(dur_, end_pos_, ease_func_); return new (std::nothrow) ActionMoveTo(dur_, end_pos_, ease_func_);
} }
void ActionMoveTo::Init(NodePtr const& target) void ActionMoveTo::Init(NodePtr target)
{ {
ActionMoveBy::Init(target); ActionMoveBy::Init(target);
delta_pos_ = end_pos_ - start_pos_; delta_pos_ = end_pos_ - start_pos_;
@ -204,7 +211,7 @@ namespace kiwano
return new (std::nothrow) ActionJumpBy(dur_, -delta_pos_, height_, jumps_, ease_func_); return new (std::nothrow) ActionJumpBy(dur_, -delta_pos_, height_, jumps_, ease_func_);
} }
void ActionJumpBy::Init(NodePtr const& target) void ActionJumpBy::Init(NodePtr target)
{ {
if (target) if (target)
{ {
@ -212,7 +219,7 @@ namespace kiwano
} }
} }
void ActionJumpBy::UpdateTween(NodePtr const& target, float percent) void ActionJumpBy::UpdateTween(NodePtr target, float percent)
{ {
float frac = fmod(percent * jumps_, 1.f); float frac = fmod(percent * jumps_, 1.f);
float x = delta_pos_.x * percent; float x = delta_pos_.x * percent;
@ -239,7 +246,7 @@ namespace kiwano
return new (std::nothrow) ActionJumpTo(dur_, end_pos_, height_, jumps_, ease_func_); return new (std::nothrow) ActionJumpTo(dur_, end_pos_, height_, jumps_, ease_func_);
} }
void ActionJumpTo::Init(NodePtr const& target) void ActionJumpTo::Init(NodePtr target)
{ {
ActionJumpBy::Init(target); ActionJumpBy::Init(target);
delta_pos_ = end_pos_ - start_pos_; delta_pos_ = end_pos_ - start_pos_;
@ -264,7 +271,7 @@ namespace kiwano
delta_y_ = scale_y; delta_y_ = scale_y;
} }
void ActionScaleBy::Init(NodePtr const& target) void ActionScaleBy::Init(NodePtr target)
{ {
if (target) if (target)
{ {
@ -273,7 +280,7 @@ namespace kiwano
} }
} }
void ActionScaleBy::UpdateTween(NodePtr const& target, float percent) void ActionScaleBy::UpdateTween(NodePtr target, float percent)
{ {
target->SetScale(start_scale_x_ + delta_x_ * percent, start_scale_y_ + delta_y_ * percent); target->SetScale(start_scale_x_ + delta_x_ * percent, start_scale_y_ + delta_y_ * percent);
} }
@ -307,7 +314,7 @@ namespace kiwano
return new (std::nothrow) ActionScaleTo(dur_, end_scale_x_, end_scale_y_, ease_func_); return new (std::nothrow) ActionScaleTo(dur_, end_scale_x_, end_scale_y_, ease_func_);
} }
void ActionScaleTo::Init(NodePtr const& target) void ActionScaleTo::Init(NodePtr target)
{ {
ActionScaleBy::Init(target); ActionScaleBy::Init(target);
delta_x_ = end_scale_x_ - start_scale_x_; delta_x_ = end_scale_x_ - start_scale_x_;
@ -325,7 +332,7 @@ namespace kiwano
delta_val_ = opacity; delta_val_ = opacity;
} }
void ActionOpacityBy::Init(NodePtr const& target) void ActionOpacityBy::Init(NodePtr target)
{ {
if (target) if (target)
{ {
@ -333,7 +340,7 @@ namespace kiwano
} }
} }
void ActionOpacityBy::UpdateTween(NodePtr const& target, float percent) void ActionOpacityBy::UpdateTween(NodePtr target, float percent)
{ {
target->SetOpacity(start_val_ + delta_val_ * percent); target->SetOpacity(start_val_ + delta_val_ * percent);
} }
@ -359,7 +366,7 @@ namespace kiwano
return new (std::nothrow) ActionOpacityTo(dur_, end_val_, ease_func_); return new (std::nothrow) ActionOpacityTo(dur_, end_val_, ease_func_);
} }
void ActionOpacityTo::Init(NodePtr const& target) void ActionOpacityTo::Init(NodePtr target)
{ {
ActionOpacityBy::Init(target); ActionOpacityBy::Init(target);
delta_val_ = end_val_ - start_val_; delta_val_ = end_val_ - start_val_;
@ -386,7 +393,7 @@ namespace kiwano
{ {
} }
void ActionRotateBy::Init(NodePtr const& target) void ActionRotateBy::Init(NodePtr target)
{ {
if (target) if (target)
{ {
@ -394,7 +401,7 @@ namespace kiwano
} }
} }
void ActionRotateBy::UpdateTween(NodePtr const& target, float percent) void ActionRotateBy::UpdateTween(NodePtr target, float percent)
{ {
float rotation = start_val_ + delta_val_ * percent; float rotation = start_val_ + delta_val_ * percent;
if (rotation > 360.f) if (rotation > 360.f)
@ -424,7 +431,7 @@ namespace kiwano
return new (std::nothrow) ActionRotateTo(dur_, end_val_, ease_func_); return new (std::nothrow) ActionRotateTo(dur_, end_val_, ease_func_);
} }
void ActionRotateTo::Init(NodePtr const& target) void ActionRotateTo::Init(NodePtr target)
{ {
ActionRotateBy::Init(target); ActionRotateBy::Init(target);
delta_val_ = end_val_ - start_val_; delta_val_ = end_val_ - start_val_;
@ -435,7 +442,7 @@ namespace kiwano
// ActionPath // ActionPath
//------------------------------------------------------- //-------------------------------------------------------
ActionPath::ActionPath(Duration duration, GeometryPtr const& geo, bool rotating, float start, float end, EaseFunc func) ActionPath::ActionPath(Duration duration, GeometryPtr geo, bool rotating, float start, float end, EaseFunc func)
: ActionTween(duration, func) : ActionTween(duration, func)
, start_(start) , start_(start)
, end_(end) , end_(end)
@ -454,12 +461,12 @@ namespace kiwano
return new ActionPath(dur_, geo_, rotating_, end_, start_, ease_func_); return new ActionPath(dur_, geo_, rotating_, end_, start_, ease_func_);
} }
void ActionPath::Init(NodePtr const& target) void ActionPath::Init(NodePtr target)
{ {
start_pos_ = target->GetPosition(); start_pos_ = target->GetPosition();
} }
void ActionPath::UpdateTween(NodePtr const& target, float percent) void ActionPath::UpdateTween(NodePtr target, float percent)
{ {
float length = geo_->GetLength() * std::min(std::max((end_ - start_) * percent + start_, 0.f), 1.f); float length = geo_->GetLength() * std::min(std::max((end_ - start_) * percent + start_, 0.f), 1.f);

View File

@ -65,13 +65,6 @@ namespace kiwano
static KGE_API EaseFunc SineInOut; static KGE_API EaseFunc SineInOut;
}; };
inline EaseFunc MakeEaseIn(float rate) { return std::bind(math::EaseIn, std::placeholders::_1, rate); }
inline EaseFunc MakeEaseOut(float rate) { return std::bind(math::EaseOut, std::placeholders::_1, rate); }
inline EaseFunc MakeEaseInOut(float rate) { return std::bind(math::EaseInOut, std::placeholders::_1, rate); }
inline EaseFunc MakeEaseElasticIn(float period) { return std::bind(math::EaseElasticIn, std::placeholders::_1, period); }
inline EaseFunc MakeEaseElasticOut(float period) { return std::bind(math::EaseElasticOut, std::placeholders::_1, period); }
inline EaseFunc MakeEaseElasticInOut(float period) { return std::bind(math::EaseElasticInOut, std::placeholders::_1, period); }
// 补间动画 // 补间动画
class KGE_API ActionTween class KGE_API ActionTween
@ -97,9 +90,9 @@ namespace kiwano
void SetDuration(Duration duration); void SetDuration(Duration duration);
protected: protected:
void Update(NodePtr const& target, Duration dt) override; void Update(NodePtr target, Duration dt) override;
virtual void UpdateTween(NodePtr const& target, float percent) = 0; virtual void UpdateTween(NodePtr target, float percent) = 0;
protected: protected:
Duration dur_; Duration dur_;
@ -125,9 +118,9 @@ namespace kiwano
ActionPtr Reverse() const override; ActionPtr Reverse() const override;
protected: protected:
void Init(NodePtr const& target) override; void Init(NodePtr target) override;
void UpdateTween(NodePtr const& target, float percent) override; void UpdateTween(NodePtr target, float percent) override;
protected: protected:
Point start_pos_; Point start_pos_;
@ -158,7 +151,7 @@ namespace kiwano
} }
protected: protected:
void Init(NodePtr const& target) override; void Init(NodePtr target) override;
protected: protected:
Point end_pos_; Point end_pos_;
@ -185,9 +178,9 @@ namespace kiwano
ActionPtr Reverse() const override; ActionPtr Reverse() const override;
protected: protected:
void Init(NodePtr const& target) override; void Init(NodePtr target) override;
void UpdateTween(NodePtr const& target, float percent) override; void UpdateTween(NodePtr target, float percent) override;
protected: protected:
Point start_pos_; Point start_pos_;
@ -222,7 +215,7 @@ namespace kiwano
} }
protected: protected:
void Init(NodePtr const& target) override; void Init(NodePtr target) override;
protected: protected:
Point end_pos_; Point end_pos_;
@ -254,9 +247,9 @@ namespace kiwano
ActionPtr Reverse() const override; ActionPtr Reverse() const override;
protected: protected:
void Init(NodePtr const& target) override; void Init(NodePtr target) override;
void UpdateTween(NodePtr const& target, float percent) override; void UpdateTween(NodePtr target, float percent) override;
protected: protected:
float start_scale_x_; float start_scale_x_;
@ -295,7 +288,7 @@ namespace kiwano
} }
protected: protected:
void Init(NodePtr const& target) override; void Init(NodePtr target) override;
protected: protected:
float end_scale_x_; float end_scale_x_;
@ -321,9 +314,9 @@ namespace kiwano
ActionPtr Reverse() const override; ActionPtr Reverse() const override;
protected: protected:
void Init(NodePtr const& target) override; void Init(NodePtr target) override;
void UpdateTween(NodePtr const& target, float percent) override; void UpdateTween(NodePtr target, float percent) override;
protected: protected:
float start_val_; float start_val_;
@ -353,7 +346,7 @@ namespace kiwano
} }
protected: protected:
void Init(NodePtr const& target) override; void Init(NodePtr target) override;
protected: protected:
float end_val_; float end_val_;
@ -404,9 +397,9 @@ namespace kiwano
ActionPtr Reverse() const override; ActionPtr Reverse() const override;
protected: protected:
void Init(NodePtr const& target) override; void Init(NodePtr target) override;
void UpdateTween(NodePtr const& target, float percent) override; void UpdateTween(NodePtr target, float percent) override;
protected: protected:
float start_val_; float start_val_;
@ -436,7 +429,7 @@ namespace kiwano
} }
protected: protected:
void Init(NodePtr const& target) override; void Init(NodePtr target) override;
protected: protected:
float end_val_; float end_val_;
@ -450,7 +443,7 @@ namespace kiwano
public: public:
ActionPath( ActionPath(
Duration duration, /* 持续时长 */ Duration duration, /* 持续时长 */
GeometryPtr const& geo, /* ¼¸ºÎͼÐÎ */ GeometryPtr geo, /* ¼¸ºÎͼÐÎ */
bool rotating = false, /* 沿路径切线方向旋转 */ bool rotating = false, /* 沿路径切线方向旋转 */
float start = 0.f, /* 起点 */ float start = 0.f, /* 起点 */
float end = 1.f, /* 终点 */ float end = 1.f, /* 终点 */
@ -464,9 +457,9 @@ namespace kiwano
ActionPtr Reverse() const override; ActionPtr Reverse() const override;
protected: protected:
void Init(NodePtr const& target) override; void Init(NodePtr target) override;
void UpdateTween(NodePtr const& target, float percent) override; void UpdateTween(NodePtr target, float percent) override;
protected: protected:
bool rotating_; bool rotating_;

View File

@ -30,7 +30,7 @@ namespace kiwano
{ {
} }
Animation::Animation(Duration duration, FramesPtr const& animation, EaseFunc func) Animation::Animation(Duration duration, FramesPtr animation, EaseFunc func)
: ActionTween(duration, func) : ActionTween(duration, func)
, frames_(nullptr) , frames_(nullptr)
{ {
@ -46,12 +46,12 @@ namespace kiwano
return frames_; return frames_;
} }
void Animation::SetFrames(FramesPtr const& frames) void Animation::SetFrames(FramesPtr frames)
{ {
frames_ = frames; frames_ = frames;
} }
void Animation::Init(NodePtr const& target) void Animation::Init(NodePtr target)
{ {
if (!frames_ || frames_->GetFrames().empty()) if (!frames_ || frames_->GetFrames().empty())
{ {
@ -66,15 +66,15 @@ namespace kiwano
} }
} }
void Animation::UpdateTween(NodePtr const& target, float percent) void Animation::UpdateTween(NodePtr target, float percent)
{ {
auto sprite_target = dynamic_cast<Sprite*>(target.Get()); auto sprite_target = dynamic_cast<Sprite*>(target.Get());
KGE_ASSERT(sprite_target && "Animation only supports Sprites"); KGE_ASSERT(sprite_target && "Animation only supports Sprites");
const auto& frames = frames_->GetFrames(); const auto& frames = frames_->GetFrames();
int size = frames.size(); auto size = frames.size();
int index = std::min(static_cast<int>(math::Floor(size * percent)), size - 1); auto index = std::min(static_cast<size_t>(math::Floor(size * percent)), size - 1);
sprite_target->Load(frames[index]); sprite_target->Load(frames[index]);
} }

View File

@ -32,7 +32,7 @@ namespace kiwano
Animation( Animation(
Duration duration, /* 动画时长 */ Duration duration, /* 动画时长 */
FramesPtr const& frames, /* ÐòÁÐÖ¡ */ FramesPtr frames, /* ÐòÁÐÖ¡ */
EaseFunc func = nullptr /* 速度变化 */ EaseFunc func = nullptr /* 速度变化 */
); );
@ -43,7 +43,7 @@ namespace kiwano
// 设置动画 // 设置动画
void SetFrames( void SetFrames(
FramesPtr const& frames FramesPtr frames
); );
// 获取该动作的拷贝对象 // 获取该动作的拷贝对象
@ -53,9 +53,9 @@ namespace kiwano
ActionPtr Reverse() const override; ActionPtr Reverse() const override;
protected: protected:
void Init(NodePtr const& target) override; void Init(NodePtr target) override;
void UpdateTween(NodePtr const& target, float percent) override; void UpdateTween(NodePtr target, float percent) override;
protected: protected:
FramesPtr frames_; FramesPtr frames_;

View File

@ -249,7 +249,7 @@ namespace kiwano
cache_expired_ = true; cache_expired_ = true;
} }
void Canvas::DrawImage(ImagePtr const & image, float opacity) void Canvas::DrawImage(ImagePtr image, float opacity)
{ {
if (image && image->GetBitmap()) if (image && image->GetBitmap())
{ {
@ -297,7 +297,7 @@ namespace kiwano
); );
} }
void Canvas::DrawGeometry(GeometryPtr const & geo) void Canvas::DrawGeometry(GeometryPtr geo)
{ {
if (geo && geo->geo_) if (geo && geo->geo_)
{ {
@ -375,7 +375,7 @@ namespace kiwano
cache_expired_ = true; cache_expired_ = true;
} }
void Canvas::FillGeometry(GeometryPtr const & geo) void Canvas::FillGeometry(GeometryPtr geo)
{ {
if (geo && geo->geo_) if (geo && geo->geo_)
{ {

View File

@ -85,7 +85,7 @@ namespace kiwano
// 뺌暠튬 // 뺌暠튬
void DrawImage( void DrawImage(
ImagePtr const& image, ImagePtr image,
float opacity = 1.f float opacity = 1.f
); );
@ -97,7 +97,7 @@ namespace kiwano
// 뺌섯부暠近긋움 // 뺌섯부暠近긋움
void DrawGeometry( void DrawGeometry(
GeometryPtr const& geo GeometryPtr geo
); );
// 輕념途近 // 輕념途近
@ -127,7 +127,7 @@ namespace kiwano
// 輕념섯부暠近 // 輕념섯부暠近
void FillGeometry( void FillGeometry(
GeometryPtr const& geo GeometryPtr geo
); );
// 역迦삥齡쨌쓺 // 역迦삥齡쨌쓺

View File

@ -51,10 +51,11 @@ namespace kiwano
void DebugNode::OnRender() void DebugNode::OnRender()
{ {
Renderer::Instance().SetTransform(Matrix{});
Renderer::Instance().GetSolidColorBrush()->SetColor(D2D1::ColorF(0.0f, 0.0f, 0.0f, 0.5f)); Renderer::Instance().GetSolidColorBrush()->SetColor(D2D1::ColorF(0.0f, 0.0f, 0.0f, 0.5f));
Renderer::Instance().GetDeviceResources()->GetD2DDeviceContext()->FillRectangle( Renderer::Instance().GetDeviceResources()->GetD2DDeviceContext()->FillRectangle(
D2D1_RECT_F{ 10, 10, 30 + debug_text_->GetWidth(), 30 + debug_text_->GetHeight() }, D2D1_RECT_F{ 10, 10, 30 + debug_text_->GetLayoutSize().x, 30 + debug_text_->GetLayoutSize().y },
Renderer::Instance().GetSolidColorBrush() Renderer::Instance().GetSolidColorBrush()
); );
} }
@ -85,8 +86,6 @@ namespace kiwano
ss << "Memory: " << pmc.PrivateUsage / 1024 << "kb"; ss << "Memory: " << pmc.PrivateUsage / 1024 << "kb";
debug_text_->SetText(ss.str()); debug_text_->SetText(ss.str());
debug_text_->SetSize(debug_text_->GetLayoutSize());
} }
} }

View File

@ -37,7 +37,7 @@ namespace kiwano
{ {
} }
void Frames::Add(ImagePtr const& frame) void Frames::Add(ImagePtr frame)
{ {
KGE_ASSERT(frame && "Frames::Add failed, NULL pointer exception"); KGE_ASSERT(frame && "Frames::Add failed, NULL pointer exception");

View File

@ -38,7 +38,7 @@ namespace kiwano
// 添加关键帧 // 添加关键帧
void Add( void Add(
ImagePtr const& frame ImagePtr frame
); );
// 添加多个关键帧 // 添加多个关键帧

View File

@ -31,7 +31,7 @@ namespace kiwano
{ {
} }
GeometryNode::GeometryNode(GeometryPtr const& geometry) GeometryNode::GeometryNode(GeometryPtr geometry)
: GeometryNode() : GeometryNode()
{ {
SetGeometry(geometry); SetGeometry(geometry);
@ -41,7 +41,7 @@ namespace kiwano
{ {
} }
void GeometryNode::SetGeometry(GeometryPtr const& geometry) void GeometryNode::SetGeometry(GeometryPtr geometry)
{ {
geometry_ = geometry; geometry_ = geometry;
} }

View File

@ -32,14 +32,14 @@ namespace kiwano
GeometryNode(); GeometryNode();
GeometryNode( GeometryNode(
GeometryPtr const& geometry GeometryPtr geometry
); );
virtual ~GeometryNode(); virtual ~GeometryNode();
// ÉčÖĂĐÎ×´ // ÉčÖĂĐÎ×´
void SetGeometry( void SetGeometry(
GeometryPtr const& geometry GeometryPtr geometry
); );
// ÉčÖĂĚîłäŃŐÉŤ // ÉčÖĂĚîłäŃŐÉŤ
@ -63,7 +63,7 @@ namespace kiwano
); );
// ťńČĄĐÎ×´ // ťńČĄĐÎ×´
GeometryPtr const& GetGeometry() const { return geometry_; } GeometryPtr GetGeometry() const { return geometry_; }
// ťńČĄĚîłäŃŐÉŤ // ťńČĄĚîłäŃŐÉŤ
Color GetFillColor() const { return fill_color_; } Color GetFillColor() const { return fill_color_; }

View File

@ -58,9 +58,8 @@ namespace kiwano
void Node::Update(Duration dt) void Node::Update(Duration dt)
{ {
if (update_pausing_) if (!update_pausing_)
return; {
UpdateActions(this, dt); UpdateActions(this, dt);
UpdateTimers(dt); UpdateTimers(dt);
@ -68,6 +67,7 @@ namespace kiwano
cb_update_(dt); cb_update_(dt);
OnUpdate(dt); OnUpdate(dt);
}
if (!children_.IsEmpty()) if (!children_.IsEmpty())
{ {
@ -451,7 +451,7 @@ namespace kiwano
dirty_transform_ = true; dirty_transform_ = true;
} }
void Node::AddChild(NodePtr const& child) void Node::AddChild(NodePtr child)
{ {
KGE_ASSERT(child && "Node::AddChild failed, NULL pointer exception"); KGE_ASSERT(child && "Node::AddChild failed, NULL pointer exception");
@ -537,7 +537,7 @@ namespace kiwano
} }
} }
void Node::RemoveChild(NodePtr const& child) void Node::RemoveChild(NodePtr child)
{ {
RemoveChild(child.Get()); RemoveChild(child.Get());
} }

View File

@ -325,7 +325,7 @@ namespace kiwano
// 添加子节点 // 添加子节点
void AddChild( void AddChild(
NodePtr const& child NodePtr child
); );
// 添加多个子节点 // 添加多个子节点
@ -348,7 +348,7 @@ namespace kiwano
// 移除子节点 // 移除子节点
void RemoveChild( void RemoveChild(
NodePtr const& child NodePtr child
); );
// 移除子节点 // 移除子节点

View File

@ -30,6 +30,7 @@ namespace kiwano
{ {
scene_ = this; scene_ = this;
SetAnchor(0, 0);
SetSize(Renderer::Instance().GetOutputSize()); SetSize(Renderer::Instance().GetOutputSize());
} }

View File

@ -28,7 +28,7 @@ namespace kiwano
{ {
} }
Sprite::Sprite(ImagePtr const& image) Sprite::Sprite(ImagePtr image)
: image_(nullptr) : image_(nullptr)
{ {
Load(image); Load(image);
@ -51,7 +51,7 @@ namespace kiwano
{ {
} }
bool Sprite::Load(ImagePtr const& image) bool Sprite::Load(ImagePtr image)
{ {
if (image) if (image)
{ {
@ -90,7 +90,7 @@ namespace kiwano
); );
} }
ImagePtr const& Sprite::GetImage() const ImagePtr Sprite::GetImage() const
{ {
return image_; return image_;
} }

View File

@ -32,7 +32,7 @@ namespace kiwano
Sprite(); Sprite();
explicit Sprite( explicit Sprite(
ImagePtr const& image ImagePtr image
); );
explicit Sprite( explicit Sprite(
@ -53,7 +53,7 @@ namespace kiwano
// 加载图片 // 加载图片
bool Load( bool Load(
ImagePtr const& image ImagePtr image
); );
// 将图片裁剪为矩形 // 将图片裁剪为矩形
@ -62,7 +62,7 @@ namespace kiwano
); );
// 获取 Image 对象 // 获取 Image 对象
ImagePtr const& GetImage() const; ImagePtr GetImage() const;
// 渲染精灵 // 渲染精灵
void OnRender() override; void OnRender() override;

View File

@ -47,7 +47,7 @@ namespace kiwano
rotation == other.rotation; rotation == other.rotation;
} }
inline math::Matrix ToMatrix() const inline Matrix ToMatrix() const
{ {
// matrix multiplication is optimized by expression template // matrix multiplication is optimized by expression template
return Matrix::Scaling(scale) return Matrix::Scaling(scale)

View File

@ -55,7 +55,7 @@ namespace kiwano
return done_; return done_;
} }
void Transition::Init(ScenePtr const& prev, ScenePtr const& next) void Transition::Init(ScenePtr prev, ScenePtr next)
{ {
process_ = 0; process_ = 0;
delta_ = Duration{}; delta_ = Duration{};
@ -147,7 +147,7 @@ namespace kiwano
{ {
} }
void BoxTransition::Init(ScenePtr const& prev, ScenePtr const& next) void BoxTransition::Init(ScenePtr prev, ScenePtr next)
{ {
Transition::Init(prev, next); Transition::Init(prev, next);
@ -189,7 +189,7 @@ namespace kiwano
{ {
} }
void EmergeTransition::Init(ScenePtr const& prev, ScenePtr const& next) void EmergeTransition::Init(ScenePtr prev, ScenePtr next)
{ {
Transition::Init(prev, next); Transition::Init(prev, next);
@ -214,7 +214,7 @@ namespace kiwano
{ {
} }
void FadeTransition::Init(ScenePtr const& prev, ScenePtr const& next) void FadeTransition::Init(ScenePtr prev, ScenePtr next)
{ {
Transition::Init(prev, next); Transition::Init(prev, next);
@ -248,7 +248,7 @@ namespace kiwano
{ {
} }
void MoveTransition::Init(ScenePtr const& prev, ScenePtr const& next) void MoveTransition::Init(ScenePtr prev, ScenePtr next)
{ {
Transition::Init(prev, next); Transition::Init(prev, next);
@ -327,7 +327,7 @@ namespace kiwano
{ {
} }
void RotationTransition::Init(ScenePtr const& prev, ScenePtr const& next) void RotationTransition::Init(ScenePtr prev, ScenePtr next)
{ {
Transition::Init(prev, next); Transition::Init(prev, next);

View File

@ -43,8 +43,8 @@ namespace kiwano
protected: protected:
virtual void Init( virtual void Init(
ScenePtr const& prev, ScenePtr prev,
ScenePtr const& next ScenePtr next
); );
virtual void Update(Duration dt); virtual void Update(Duration dt);
@ -84,8 +84,8 @@ namespace kiwano
void Update(Duration dt) override; void Update(Duration dt) override;
virtual void Init( virtual void Init(
ScenePtr const& prev, ScenePtr prev,
ScenePtr const& next ScenePtr next
) override; ) override;
}; };
@ -103,8 +103,8 @@ namespace kiwano
void Update(Duration dt) override; void Update(Duration dt) override;
virtual void Init( virtual void Init(
ScenePtr const& prev, ScenePtr prev,
ScenePtr const& next ScenePtr next
) override; ) override;
}; };
@ -122,8 +122,8 @@ namespace kiwano
void Update(Duration dt) override; void Update(Duration dt) override;
virtual void Init( virtual void Init(
ScenePtr const& prev, ScenePtr prev,
ScenePtr const& next ScenePtr next
) override; ) override;
}; };
@ -142,8 +142,8 @@ namespace kiwano
void Update(Duration dt) override; void Update(Duration dt) override;
virtual void Init( virtual void Init(
ScenePtr const& prev, ScenePtr prev,
ScenePtr const& next ScenePtr next
) override; ) override;
void Reset() override; void Reset() override;
@ -169,8 +169,8 @@ namespace kiwano
void Update(Duration dt) override; void Update(Duration dt) override;
virtual void Init( virtual void Init(
ScenePtr const& prev, ScenePtr prev,
ScenePtr const& next ScenePtr next
) override; ) override;
void Reset() override; void Reset() override;

View File

@ -126,7 +126,7 @@ namespace kiwano
// 图层属性 // 图层属性
struct LayerProperties struct LayerProperties
{ {
math::Rect area; Rect area;
float opacity; float opacity;
}; };
} }

View File

@ -40,7 +40,7 @@ namespace kiwano
} }
} }
EventListenerPtr EventDispatcher::AddListener(EventListenerPtr const & listener) EventListenerPtr EventDispatcher::AddListener(EventListenerPtr listener)
{ {
KGE_ASSERT(listener && "AddListener failed, NULL pointer exception"); KGE_ASSERT(listener && "AddListener failed, NULL pointer exception");

View File

@ -30,7 +30,7 @@ namespace kiwano
public: public:
// 添加监听器 // 添加监听器
EventListenerPtr AddListener( EventListenerPtr AddListener(
EventListenerPtr const& listener EventListenerPtr listener
); );
// 添加监听器 // 添加监听器

View File

@ -38,7 +38,7 @@ namespace kiwano
}; };
template <typename _Ty> template <typename _Ty>
using SmartPtr = IntrusivePtr<_Ty, DefaultIntrusivePtrManager, true>; using SmartPtr = IntrusivePtr<_Ty, DefaultIntrusivePtrManager>;
} }

View File

@ -41,7 +41,7 @@ namespace kiwano
} }
} }
void TimerManager::AddTimer(TimerPtr const& timer) void TimerManager::AddTimer(TimerPtr timer)
{ {
KGE_ASSERT(timer && "AddTimer failed, NULL pointer exception"); KGE_ASSERT(timer && "AddTimer failed, NULL pointer exception");

View File

@ -30,7 +30,7 @@ namespace kiwano
public: public:
// 添加任务 // 添加任务
void AddTimer( void AddTimer(
TimerPtr const& timer TimerPtr timer
); );
// 启动任务 // 启动任务

View File

@ -67,7 +67,7 @@ namespace kiwano
return Duration(dur_ - other.dur_); return Duration(dur_ - other.dur_);
} }
Time Time::Now() KGE_NOEXCEPT Time Time::Now() noexcept
{ {
static LARGE_INTEGER freq = {}; static LARGE_INTEGER freq = {};
if (freq.QuadPart == 0LL) if (freq.QuadPart == 0LL)

View File

@ -177,7 +177,7 @@ namespace kiwano
// 获取当前时间 // 获取当前时间
// 由于该时间点基于系统启动时间开始计算, 所以无法格式化该时间, // 由于该时间点基于系统启动时间开始计算, 所以无法格式化该时间,
// 也无法获得该时间的 Unix 时间戳 // 也无法获得该时间的 Unix 时间戳
static Time Now() KGE_NOEXCEPT; static Time Now() noexcept;
private: private:
long dur_; long dur_;

View File

@ -25,14 +25,6 @@
namespace kiwano namespace kiwano
{ {
//
// Array
// Lightweight std::vector<>-like class
//
template<typename _Ty, typename _Alloc, typename _Manager>
class Array;
// //
// ArrayManager<> with memory operations // ArrayManager<> with memory operations
// //
@ -42,6 +34,7 @@ namespace kiwano
// //
// Array<> // Array<>
// Lightweight std::vector<>-like class
// //
template< template<
typename _Ty, typename _Ty,
@ -68,14 +61,14 @@ namespace kiwano
inline Array(size_type count, const _Ty& val) : Array() { assign(count, val); } inline Array(size_type count, const _Ty& val) : Array() { assign(count, val); }
inline Array(initializer_list list) : Array() { assign(list); } inline Array(initializer_list list) : Array() { assign(list); }
inline Array(const Array& src) : Array() { assign(src); } inline Array(const Array& src) : Array() { assign(src); }
inline Array(Array&& src) : Array() { swap(src); } inline Array(Array&& src) noexcept : Array() { swap(src); }
inline ~Array() { destroy(); } inline ~Array() { destroy(); }
template <typename _Iter> template <typename _Iter>
inline Array(_Iter first, _Iter last) : Array() { assign(first, last); } inline Array(_Iter first, _Iter last) : Array() { assign(first, last); }
inline Array& operator=(const Array& src) { if (&src != this) { resize(src.size_); manager::copy_data(begin(), src.cbegin(), size_); } return (*this); } inline Array& operator=(const Array& src) { if (&src != this) { resize(src.size_); manager::copy_data(begin(), src.cbegin(), size_); } return (*this); }
inline Array& operator=(Array&& src) { swap(src); return *this; } inline Array& operator=(Array&& src) noexcept { swap(src); return *this; }
inline Array& operator=(initializer_list list) { if (list.size()) { assign(list.begin(), list.end()); } else clear(); return (*this); } inline Array& operator=(initializer_list list) { if (list.size()) { assign(list.begin(), list.end()); } else clear(); return (*this); }
inline Array& assign(size_type count, const _Ty& val) { if (count > 0) { resize(count); manager::copy_data(begin(), count, val); } else clear(); return (*this); } inline Array& assign(size_type count, const _Ty& val) { if (count > 0) { resize(count); manager::copy_data(begin(), count, val); } else clear(); return (*this); }
@ -86,7 +79,7 @@ namespace kiwano
inline void assign(_Iter first, _Iter last) { auto diff = std::distance(first, last); resize((size_type)diff); auto data = begin(); while (first != last) (*data++) = (*first++); } inline void assign(_Iter first, _Iter last) { auto diff = std::distance(first, last); resize((size_type)diff); auto data = begin(); while (first != last) (*data++) = (*first++); }
inline void clear() { destroy(); size_ = capacity_ = 0; data_ = nullptr; } inline void clear() { destroy(); size_ = capacity_ = 0; data_ = nullptr; }
inline void swap(Array& rhs) { std::swap(size_, rhs.size_); std::swap(capacity_, rhs.capacity_); std::swap(data_, rhs.data_); } inline void swap(Array& rhs) noexcept { std::swap(size_, rhs.size_); std::swap(capacity_, rhs.capacity_); std::swap(data_, rhs.data_); }
inline void resize(size_type new_size) { resize(new_size, _Ty()); } inline void resize(size_type new_size) { resize(new_size, _Ty()); }
inline void resize(size_type new_size, const _Ty& v); inline void resize(size_type new_size, const _Ty& v);
@ -215,7 +208,7 @@ namespace kiwano
struct __ArrayManager<_Ty, _Alloc, false> struct __ArrayManager<_Ty, _Alloc, false>
{ {
using value_type = _Ty; using value_type = _Ty;
using size_type = int; using size_type = size_t;
using allocator_type = typename _Alloc; using allocator_type = typename _Alloc;
static inline void copy_data(value_type* dest, const value_type* src, size_type count) { if (src == dest) return; ::memcpy(dest, src, (size_t)count * sizeof(value_type)); } static inline void copy_data(value_type* dest, const value_type* src, size_type count) { if (src == dest) return; ::memcpy(dest, src, (size_t)count * sizeof(value_type)); }
@ -244,7 +237,7 @@ namespace kiwano
struct __ArrayManager<_Ty, _Alloc, true> struct __ArrayManager<_Ty, _Alloc, true>
{ {
using value_type = _Ty; using value_type = _Ty;
using size_type = int; using size_type = size_t;
using allocator_type = typename _Alloc; using allocator_type = typename _Alloc;
static inline void copy_data(value_type* dest, const value_type* src, size_type count) { if (src == dest) return; while (count--) (*dest++) = (*src++); } static inline void copy_data(value_type* dest, const value_type* src, size_type count) { if (src == dest) return; while (count--) (*dest++) = (*src++); }

View File

@ -39,7 +39,9 @@ namespace kiwano
}; };
// ComPtr<> is a smart pointer for COM // ComPtr<> is a smart pointer for COM
template <typename _Ty> template<
using ComPtr = IntrusivePtr<_Ty, ComPtrManager, ::std::is_base_of<IUnknown, _Ty>::value>; typename _Ty,
typename = typename std::enable_if<std::is_base_of<IUnknown, _Ty>::value, int>::type>
using ComPtr = IntrusivePtr<_Ty, ComPtrManager>;
} }

View File

@ -25,65 +25,55 @@
namespace kiwano namespace kiwano
{ {
template <typename _Ty, typename _Manager, bool _Enable>
class IntrusivePtr;
template <typename _Ty, typename _Manager> template <typename _Ty, typename _Manager>
class IntrusivePtr<_Ty, _Manager, false>; class IntrusivePtr
template <typename _Ty, typename _Manager>
using RealIntrusivePtr = IntrusivePtr<_Ty, _Manager, true>;
template <typename _Ty, typename _Manager>
class IntrusivePtr<_Ty, _Manager, true>
{ {
_Ty* ptr_{ nullptr }; _Ty* ptr_{ nullptr };
public: public:
using Type = _Ty; using Type = _Ty;
IntrusivePtr() KGE_NOEXCEPT {} IntrusivePtr() noexcept {}
IntrusivePtr(nullptr_t) KGE_NOEXCEPT {} IntrusivePtr(nullptr_t) noexcept {}
IntrusivePtr(Type* p) KGE_NOEXCEPT : ptr_(p) IntrusivePtr(Type* p) noexcept : ptr_(p)
{ {
typename _Manager::AddRef(ptr_); typename _Manager::AddRef(ptr_);
} }
IntrusivePtr(const IntrusivePtr& other) KGE_NOEXCEPT IntrusivePtr(const IntrusivePtr& other) noexcept
: ptr_(other.ptr_) : ptr_(other.ptr_)
{ {
typename _Manager::AddRef(ptr_); typename _Manager::AddRef(ptr_);
} }
template <typename _UTy> template <typename _UTy>
IntrusivePtr(const RealIntrusivePtr<_UTy, _Manager>& other) KGE_NOEXCEPT IntrusivePtr(const IntrusivePtr<_UTy, _Manager>& other) noexcept
: ptr_(other.Get()) : ptr_(other.Get())
{ {
typename _Manager::AddRef(ptr_); typename _Manager::AddRef(ptr_);
} }
IntrusivePtr(IntrusivePtr&& other) KGE_NOEXCEPT IntrusivePtr(IntrusivePtr&& other) noexcept
{ {
ptr_ = other.ptr_; ptr_ = other.ptr_;
other.ptr_ = nullptr; other.ptr_ = nullptr;
} }
~IntrusivePtr() KGE_NOEXCEPT ~IntrusivePtr() noexcept
{ {
typename _Manager::Release(ptr_); typename _Manager::Release(ptr_);
} }
inline Type* Get() const KGE_NOEXCEPT { return ptr_; } inline Type* Get() const noexcept { return ptr_; }
inline void Reset() KGE_NOEXCEPT inline void Reset() noexcept
{ {
IntrusivePtr{}.Swap(*this); IntrusivePtr{}.Swap(*this);
} }
inline void Swap(IntrusivePtr& other) KGE_NOEXCEPT inline void Swap(IntrusivePtr& other) noexcept
{ {
std::swap(ptr_, other.ptr_); std::swap(ptr_, other.ptr_);
} }
@ -106,18 +96,18 @@ namespace kiwano
return &ptr_; return &ptr_;
} }
inline operator bool() const KGE_NOEXCEPT { return ptr_ != nullptr; } inline operator bool() const noexcept { return ptr_ != nullptr; }
inline bool operator !() const KGE_NOEXCEPT { return ptr_ == 0; } inline bool operator !() const noexcept { return ptr_ == 0; }
inline IntrusivePtr& operator =(const IntrusivePtr& other) KGE_NOEXCEPT inline IntrusivePtr& operator =(const IntrusivePtr& other) noexcept
{ {
if (other.ptr_ != ptr_) if (other.ptr_ != ptr_)
IntrusivePtr(other).Swap(*this); IntrusivePtr(other).Swap(*this);
return *this; return *this;
} }
inline IntrusivePtr& operator =(IntrusivePtr&& other) KGE_NOEXCEPT inline IntrusivePtr& operator =(IntrusivePtr&& other) noexcept
{ {
typename _Manager::Release(ptr_); typename _Manager::Release(ptr_);
ptr_ = other.ptr_; ptr_ = other.ptr_;
@ -125,14 +115,14 @@ namespace kiwano
return *this; return *this;
} }
inline IntrusivePtr& operator =(Type* p) KGE_NOEXCEPT inline IntrusivePtr& operator =(Type* p) noexcept
{ {
if (p != ptr_) if (p != ptr_)
IntrusivePtr(p).Swap(*this); IntrusivePtr(p).Swap(*this);
return *this; return *this;
} }
inline IntrusivePtr& operator =(nullptr_t) KGE_NOEXCEPT inline IntrusivePtr& operator =(nullptr_t) noexcept
{ {
if (nullptr != ptr_) if (nullptr != ptr_)
IntrusivePtr{}.Swap(*this); IntrusivePtr{}.Swap(*this);
@ -141,67 +131,67 @@ namespace kiwano
}; };
template <class _Ty, class _UTy, class _Manager> template <class _Ty, class _UTy, class _Manager>
inline bool operator==(RealIntrusivePtr<_Ty, _Manager> const& lhs, RealIntrusivePtr<_UTy, _Manager> const& rhs) KGE_NOEXCEPT inline bool operator==(IntrusivePtr<_Ty, _Manager> const& lhs, IntrusivePtr<_UTy, _Manager> const& rhs) noexcept
{ {
return lhs.Get() == rhs.Get(); return lhs.Get() == rhs.Get();
} }
template <class _Ty, class _UTy, class _Manager> template <class _Ty, class _UTy, class _Manager>
inline bool operator!=(RealIntrusivePtr<_Ty, _Manager> const& lhs, RealIntrusivePtr<_UTy, _Manager> const& rhs) KGE_NOEXCEPT inline bool operator!=(IntrusivePtr<_Ty, _Manager> const& lhs, IntrusivePtr<_UTy, _Manager> const& rhs) noexcept
{ {
return lhs.Get() != rhs.Get(); return lhs.Get() != rhs.Get();
} }
template <class _Ty, class _UTy, class _Manager> template <class _Ty, class _UTy, class _Manager>
inline bool operator<(RealIntrusivePtr<_Ty, _Manager> const& lhs, RealIntrusivePtr<_UTy, _Manager> const& rhs) KGE_NOEXCEPT inline bool operator<(IntrusivePtr<_Ty, _Manager> const& lhs, IntrusivePtr<_UTy, _Manager> const& rhs) noexcept
{ {
return lhs.Get() < rhs.Get(); return lhs.Get() < rhs.Get();
} }
template <class _Ty, class _Manager> template <class _Ty, class _Manager>
inline bool operator==(RealIntrusivePtr<_Ty, _Manager> const& lhs, _Ty* rhs) KGE_NOEXCEPT inline bool operator==(IntrusivePtr<_Ty, _Manager> const& lhs, _Ty* rhs) noexcept
{ {
return lhs.Get() == rhs; return lhs.Get() == rhs;
} }
template <class _Ty, class _Manager> template <class _Ty, class _Manager>
inline bool operator!=(RealIntrusivePtr<_Ty, _Manager> const& lhs, _Ty* rhs) KGE_NOEXCEPT inline bool operator!=(IntrusivePtr<_Ty, _Manager> const& lhs, _Ty* rhs) noexcept
{ {
return lhs.Get() != rhs; return lhs.Get() != rhs;
} }
template <class _Ty, class _Manager> template <class _Ty, class _Manager>
inline bool operator==(_Ty* lhs, RealIntrusivePtr<_Ty, _Manager> const& rhs) KGE_NOEXCEPT inline bool operator==(_Ty* lhs, IntrusivePtr<_Ty, _Manager> const& rhs) noexcept
{ {
return lhs == rhs.Get(); return lhs == rhs.Get();
} }
template <class _Ty, class _Manager> template <class _Ty, class _Manager>
inline bool operator!=(_Ty* lhs, RealIntrusivePtr<_Ty, _Manager> const& rhs) KGE_NOEXCEPT inline bool operator!=(_Ty* lhs, IntrusivePtr<_Ty, _Manager> const& rhs) noexcept
{ {
return lhs != rhs.Get(); return lhs != rhs.Get();
} }
template <class _Ty, class _Manager> template <class _Ty, class _Manager>
inline bool operator==(RealIntrusivePtr<_Ty, _Manager> const& lhs, nullptr_t) KGE_NOEXCEPT inline bool operator==(IntrusivePtr<_Ty, _Manager> const& lhs, nullptr_t) noexcept
{ {
return !static_cast<bool>(lhs); return !static_cast<bool>(lhs);
} }
template <class _Ty, class _Manager> template <class _Ty, class _Manager>
inline bool operator!=(RealIntrusivePtr<_Ty, _Manager> const& lhs, nullptr_t) KGE_NOEXCEPT inline bool operator!=(IntrusivePtr<_Ty, _Manager> const& lhs, nullptr_t) noexcept
{ {
return static_cast<bool>(lhs); return static_cast<bool>(lhs);
} }
template <class _Ty, class _Manager> template <class _Ty, class _Manager>
inline bool operator==(nullptr_t, RealIntrusivePtr<_Ty, _Manager> const& rhs) KGE_NOEXCEPT inline bool operator==(nullptr_t, IntrusivePtr<_Ty, _Manager> const& rhs) noexcept
{ {
return !static_cast<bool>(rhs); return !static_cast<bool>(rhs);
} }
template <class _Ty, class _Manager> template <class _Ty, class _Manager>
inline bool operator!=(nullptr_t, RealIntrusivePtr<_Ty, _Manager> const& rhs) KGE_NOEXCEPT inline bool operator!=(nullptr_t, IntrusivePtr<_Ty, _Manager> const& rhs) noexcept
{ {
return static_cast<bool>(rhs); return static_cast<bool>(rhs);
} }
@ -209,7 +199,7 @@ namespace kiwano
// template class cannot specialize std::swap, // template class cannot specialize std::swap,
// so implement a swap function in kiwano namespace // so implement a swap function in kiwano namespace
template <class _Ty, class _Manager> template <class _Ty, class _Manager>
inline void swap(RealIntrusivePtr<_Ty, _Manager>& lhs, RealIntrusivePtr<_Ty, _Manager>& rhs) KGE_NOEXCEPT inline void swap(IntrusivePtr<_Ty, _Manager>& lhs, IntrusivePtr<_Ty, _Manager>& rhs) noexcept
{ {
lhs.Swap(rhs); lhs.Swap(rhs);
} }

View File

@ -363,7 +363,7 @@ namespace kiwano
{ {
using difference_type = std::ptrdiff_t; using difference_type = std::ptrdiff_t;
inline primitive_iterator(int it = 0) : it_(it) {} inline primitive_iterator(difference_type it = 0) : it_(it) {}
inline void set_begin() { it_ = 0; } inline void set_begin() { it_ = 0; }
inline void set_end() { it_ = 1; } inline void set_end() { it_ = 1; }
@ -392,7 +392,7 @@ namespace kiwano
inline bool operator>=(primitive_iterator const& other) const { return it_ >= other.it_; } inline bool operator>=(primitive_iterator const& other) const { return it_ >= other.it_; }
private: private:
int it_; difference_type it_;
}; };
template <typename _BasicJsonTy> template <typename _BasicJsonTy>

View File

@ -106,7 +106,7 @@ namespace kiwano
String(std::wstring const& str); String(std::wstring const& str);
String(String const& rhs); String(String const& rhs);
String(String const& rhs, size_type pos, size_type count = npos); String(String const& rhs, size_type pos, size_type count = npos);
String(String && rhs); String(String && rhs) noexcept;
~String(); ~String();
template <typename _Iter> template <typename _Iter>
@ -191,7 +191,7 @@ namespace kiwano
std::string to_string() const; std::string to_string() const;
std::wstring to_wstring() const; std::wstring to_wstring() const;
void swap(String& rhs); void swap(String& rhs) noexcept;
size_t hash() const; size_t hash() const;
public: public:
@ -245,7 +245,7 @@ namespace kiwano
inline String& operator=(const wchar_t* cstr) { if (const_str_ != cstr) String{ cstr }.swap(*this); return *this; } inline String& operator=(const wchar_t* cstr) { if (const_str_ != cstr) String{ cstr }.swap(*this); return *this; }
inline String& operator=(std::wstring const& str) { String{ str }.swap(*this); return *this; } inline String& operator=(std::wstring const& str) { String{ str }.swap(*this); return *this; }
inline String& operator=(String const& rhs) { if (this != &rhs) String{ rhs }.swap(*this); return *this; } inline String& operator=(String const& rhs) { if (this != &rhs) String{ rhs }.swap(*this); return *this; }
inline String& operator=(String && rhs) { if (this != &rhs) String{ rhs }.swap(*this); return *this; } inline String& operator=(String && rhs) noexcept { if (this != &rhs) String{ rhs }.swap(*this); return *this; }
public: public:
static const String::size_type npos = static_cast<size_type>(-1); static const String::size_type npos = static_cast<size_type>(-1);
@ -537,7 +537,7 @@ namespace kiwano
assign(rhs, pos, count); assign(rhs, pos, count);
} }
inline String::String(String && rhs) inline String::String(String && rhs) noexcept
: str_(rhs.str_) : str_(rhs.str_)
, size_(rhs.size_) , size_(rhs.size_)
, capacity_(rhs.capacity_) , capacity_(rhs.capacity_)
@ -1074,7 +1074,7 @@ namespace kiwano
size_ = capacity_ = 0; size_ = capacity_ = 0;
} }
inline void String::swap(String & rhs) inline void String::swap(String & rhs) noexcept
{ {
std::swap(const_str_, rhs.const_str_); std::swap(const_str_, rhs.const_str_);
std::swap(size_, rhs.size_); std::swap(size_, rhs.size_);

View File

@ -29,6 +29,43 @@ namespace kiwano
namespace __closure_detail namespace __closure_detail
{ {
//
// is_callable
//
namespace __callable_detail
{
template <typename _Ty, typename _Ret, typename... _Args>
struct helper
{
template <typename _Uty> static int test(...);
template <typename _Uty, _Ret(_Uty::*)(_Args...)> struct class_mem;
template <typename _Uty> static char test(class_mem<_Uty, &_Uty::operator()>*);
template <typename _Uty, _Ret(_Uty::*)(_Args...) const> struct class_const_mem;
template <typename _Uty> static char test(class_const_mem<_Uty, &_Uty::operator()>*);
template<
typename _Uty,
typename _Uret = typename std::decay<decltype(std::declval<_Uty>().operator()(std::declval<_Args>()...))>::type,
typename = typename std::enable_if<std::is_convertible<_Ret, _Uret>::value>::type>
static char test(int);
static constexpr bool value = sizeof(test<_Ty>(0)) == sizeof(char);
};
}
template<typename _Ty, typename _Ret, typename... _Args>
struct is_callable
: public std::bool_constant<__callable_detail::helper<_Ty, _Ret, _Args...>::value>
{
};
//
// Callable
//
template<typename _Ret, typename... _Args> template<typename _Ret, typename... _Args>
class Callable class Callable
{ {
@ -195,7 +232,15 @@ namespace kiwano
rhs.callable_ = nullptr; rhs.callable_ = nullptr;
} }
template <typename _Ty> Closure(_Ret(*func)(_Args...))
{
callable_ = __closure_detail::ProxyCallable<_Ret(*)(_Args...), _Ret, _Args...>::Make(std::move(func));
if (callable_) callable_->AddRef();
}
template<
typename _Ty,
typename = typename std::enable_if<__closure_detail::is_callable<_Ty, _Ret, _Args...>::value, int>::type>
Closure(_Ty val) Closure(_Ty val)
{ {
callable_ = __closure_detail::ProxyCallable<_Ty, _Ret, _Args...>::Make(std::move(val)); callable_ = __closure_detail::ProxyCallable<_Ty, _Ret, _Args...>::Make(std::move(val));
@ -204,7 +249,7 @@ namespace kiwano
template<typename _Ty, template<typename _Ty,
typename _Uty, typename _Uty,
typename std::enable_if<std::is_same<_Ty, _Uty>::value || std::is_base_of<_Ty, _Uty>::value, int>::type = 0> typename = typename std::enable_if<std::is_same<_Ty, _Uty>::value || std::is_base_of<_Ty, _Uty>::value, int>::type>
Closure(_Uty* ptr, _Ret(_Ty::* func)(_Args...)) Closure(_Uty* ptr, _Ret(_Ty::* func)(_Args...))
{ {
callable_ = __closure_detail::ProxyMemCallable<_Ty, _Ret, _Args...>::Make(ptr, func); callable_ = __closure_detail::ProxyMemCallable<_Ty, _Ret, _Args...>::Make(ptr, func);
@ -213,7 +258,7 @@ namespace kiwano
template<typename _Ty, template<typename _Ty,
typename _Uty, typename _Uty,
typename std::enable_if<std::is_same<_Ty, _Uty>::value || std::is_base_of<_Ty, _Uty>::value, int>::type = 0> typename = typename std::enable_if<std::is_same<_Ty, _Uty>::value || std::is_base_of<_Ty, _Uty>::value, int>::type>
Closure(_Uty* ptr, _Ret(_Ty::* func)(_Args...) const) Closure(_Uty* ptr, _Ret(_Ty::* func)(_Args...) const)
{ {
callable_ = __closure_detail::ProxyConstMemCallable<_Ty, _Ret, _Args...>::Make(ptr, func); callable_ = __closure_detail::ProxyConstMemCallable<_Ty, _Ret, _Args...>::Make(ptr, func);
@ -274,9 +319,9 @@ namespace kiwano
template<typename _Ty, template<typename _Ty,
typename _Uty, typename _Uty,
typename std::enable_if< typename = typename std::enable_if<
std::is_same<_Ty, _Uty>::value || std::is_base_of<_Ty, _Uty>::value, int std::is_same<_Ty, _Uty>::value || std::is_base_of<_Ty, _Uty>::value, int
>::type = 0, >::type,
typename _Ret, typename _Ret,
typename... _Args> typename... _Args>
inline Closure<_Ret(_Args...)> MakeClosure(_Uty* ptr, _Ret(_Ty::* func)(_Args...)) inline Closure<_Ret(_Args...)> MakeClosure(_Uty* ptr, _Ret(_Ty::* func)(_Args...))
@ -286,9 +331,9 @@ namespace kiwano
template<typename _Ty, template<typename _Ty,
typename _Uty, typename _Uty,
typename std::enable_if< typename = typename std::enable_if<
std::is_same<_Ty, _Uty>::value || std::is_base_of<_Ty, _Uty>::value, int std::is_same<_Ty, _Uty>::value || std::is_base_of<_Ty, _Uty>::value, int
>::type = 0, >::type,
typename _Ret, typename _Ret,
typename... _Args> typename... _Args>
inline Closure<_Ret(_Args...)> MakeClosure(_Uty* ptr, _Ret(_Ty::* func)(_Args...) const) inline Closure<_Ret(_Args...)> MakeClosure(_Uty* ptr, _Ret(_Ty::* func)(_Args...) const)

View File

@ -33,10 +33,11 @@
# define VS_2013 1800 # define VS_2013 1800
# define VS_2015 1900 # define VS_2015 1900
# define VS_2017 1900 # define VS_2017 1900
# define VS_2019 1920
#endif #endif
#if VS_VER < VS_2013 #if VS_VER < VS_2015
# error Kiwano only supports Visual Studio 2013 and above # error Kiwano only supports Visual Studio 2015 and above
#endif #endif
#ifndef WINVER #ifndef WINVER
@ -84,15 +85,6 @@
#endif #endif
#if VS_VER >= VS_2015
# define KGE_NOEXCEPT noexcept
# define KGE_CONSTEXPR constexpr
#else
# define KGE_NOEXCEPT throw()
# define KGE_CONSTEXPR const
#endif
#ifndef KGE_ASSERT #ifndef KGE_ASSERT
# ifdef KGE_DEBUG # ifdef KGE_DEBUG
# define KGE_ASSERT(EXPR) assert(EXPR) # define KGE_ASSERT(EXPR) assert(EXPR)

View File

@ -27,43 +27,49 @@ namespace kiwano
{ {
namespace math namespace math
{ {
struct Matrix template <typename _Ty, typename _Lty, typename _Rty>
struct MatrixMultiply;
template <typename _Ty>
struct MatrixT
{ {
using value_type = _Ty;
union union
{ {
struct struct
{ {
float m[6]; // m[3][2] _Ty m[6]; // m[3][2]
}; };
struct struct
{ {
float _Ty
_11, _12, _11, _12,
_21, _22, _21, _22,
_31, _32; _31, _32;
}; };
}; };
Matrix() MatrixT()
: _11(1.f), _12(0.f) : _11(1.f), _12(0.f)
, _21(0.f), _22(1.f) , _21(0.f), _22(1.f)
, _31(0.f), _32(0.f) , _31(0.f), _32(0.f)
{ {
} }
Matrix(float _11, float _12, float _21, float _22, float _31, float _32) MatrixT(value_type _11, value_type _12, value_type _21, value_type _22, value_type _31, value_type _32)
: _11(_11), _12(_12), _21(_21), _22(_22), _31(_31), _32(_32) : _11(_11), _12(_12), _21(_21), _22(_22), _31(_31), _32(_32)
{ {
} }
explicit Matrix(const float* p) explicit MatrixT(const value_type* p)
{ {
for (int i = 0; i < 6; i++) for (int i = 0; i < 6; i++)
m[i] = p[i]; m[i] = p[i];
} }
Matrix(Matrix const& other) MatrixT(MatrixT const& other)
: _11(other._11), _12(other._12) : _11(other._11), _12(other._12)
, _21(other._21), _22(other._22) , _21(other._21), _22(other._22)
, _31(other._31), _32(other._32) , _31(other._31), _32(other._32)
@ -71,7 +77,7 @@ namespace kiwano
} }
template <typename T> template <typename T>
Matrix(T const& other) MatrixT(T const& other)
{ {
for (int i = 0; i < 6; i++) for (int i = 0; i < 6; i++)
m[i] = other[i]; m[i] = other[i];
@ -92,17 +98,17 @@ namespace kiwano
); );
} }
Rect Transform(const Rect & rect) const RectT<value_type> Transform(const Rect & rect) const
{ {
Vec2 top_left = Transform(rect.GetLeftTop()); Vec2T<value_type> top_left = Transform(rect.GetLeftTop());
Vec2 top_right = Transform(rect.GetRightTop()); Vec2T<value_type> top_right = Transform(rect.GetRightTop());
Vec2 bottom_left = Transform(rect.GetLeftBottom()); Vec2T<value_type> bottom_left = Transform(rect.GetLeftBottom());
Vec2 bottom_right = Transform(rect.GetRightBottom()); Vec2T<value_type> bottom_right = Transform(rect.GetRightBottom());
float left = std::min(std::min(top_left.x, top_right.x), std::min(bottom_left.x, bottom_right.x)); value_type left = std::min(std::min(top_left.x, top_right.x), std::min(bottom_left.x, bottom_right.x));
float right = std::max(std::max(top_left.x, top_right.x), std::max(bottom_left.x, bottom_right.x)); value_type right = std::max(std::max(top_left.x, top_right.x), std::max(bottom_left.x, bottom_right.x));
float top = std::min(std::min(top_left.y, top_right.y), std::min(bottom_left.y, bottom_right.y)); value_type top = std::min(std::min(top_left.y, top_right.y), std::min(bottom_left.y, bottom_right.y));
float bottom = std::max(std::max(top_left.y, top_right.y), std::max(bottom_left.y, bottom_right.y)); value_type bottom = std::max(std::max(top_left.y, top_right.y), std::max(bottom_left.y, bottom_right.y));
return Rect{ left, top, (right - left), (bottom - top) }; return Rect{ left, top, (right - left), (bottom - top) };
} }
@ -113,20 +119,20 @@ namespace kiwano
_32 += _12 * v.x + _22 * v.y; _32 += _12 * v.x + _22 * v.y;
} }
inline float operator [](unsigned int index) const inline value_type operator [](unsigned int index) const
{ {
return m[index]; return m[index];
} }
template <typename T> template <typename _Lty, typename _Rty>
inline Matrix& operator =(T const& other) inline MatrixT& operator= (MatrixMultiply<value_type, _Lty, _Rty> const& other)
{ {
for (int i = 0; i < 6; i++) for (int i = 0; i < 6; i++)
m[i] = other[i]; m[i] = other[i];
return *this; return *this;
} }
inline float Determinant() const inline value_type Determinant() const
{ {
return (_11 * _22) - (_12 * _21); return (_11 * _22) - (_12 * _21);
} }
@ -143,27 +149,27 @@ namespace kiwano
return 0 != Determinant(); return 0 != Determinant();
} }
static inline Matrix Translation(const Vec2& v) static inline MatrixT Translation(const Vec2& v)
{ {
return Matrix( return MatrixT(
1.f, 0.f, 1.f, 0.f,
0.f, 1.f, 0.f, 1.f,
v.x, v.y v.x, v.y
); );
} }
static inline Matrix Translation( static inline MatrixT Translation(
float x, value_type x,
float y) value_type y)
{ {
return Translation(Vec2(x, y)); return Translation(Vec2(x, y));
} }
static inline Matrix Scaling( static inline MatrixT Scaling(
const Vec2& v, const Vec2& v,
const Vec2& center = Vec2()) const Vec2& center = Vec2())
{ {
return Matrix( return MatrixT(
v.x, 0.f, v.x, 0.f,
0.f, v.y, 0.f, v.y,
center.x - v.x * center.x, center.x - v.x * center.x,
@ -171,21 +177,21 @@ namespace kiwano
); );
} }
static inline Matrix Scaling( static inline MatrixT Scaling(
float x, value_type x,
float y, value_type y,
const Vec2& center = Vec2()) const Vec2& center = Vec2())
{ {
return Scaling(Vec2(x, y), center); return Scaling(Vec2(x, y), center);
} }
static inline Matrix Rotation( static inline MatrixT Rotation(
float angle, value_type angle,
const Vec2& center = Vec2()) const Vec2& center = Vec2())
{ {
float s = math::Sin(angle); value_type s = math::Sin(angle);
float c = math::Cos(angle); value_type c = math::Cos(angle);
return Matrix( return MatrixT(
c, s, c, s,
-s, c, -s, c,
center.x * (1 - c) + center.y * s, center.x * (1 - c) + center.y * s,
@ -193,25 +199,25 @@ namespace kiwano
); );
} }
static inline Matrix Skewing( static inline MatrixT Skewing(
float angle_x, value_type angle_x,
float angle_y, value_type angle_y,
const Vec2& center = Vec2()) const Vec2& center = Vec2())
{ {
float tx = math::Tan(angle_x); value_type tx = math::Tan(angle_x);
float ty = math::Tan(angle_y); value_type ty = math::Tan(angle_y);
return Matrix( return MatrixT(
1.f, -ty, 1.f, -ty,
-tx, 1.f, -tx, 1.f,
center.y * tx, center.x * ty center.y * tx, center.x * ty
); );
} }
static inline Matrix Invert(Matrix const& matrix) static inline MatrixT Invert(MatrixT const& matrix)
{ {
float det = 1.f / matrix.Determinant(); value_type det = 1.f / matrix.Determinant();
return Matrix( return MatrixT(
det * matrix._22, det * matrix._22,
-det * matrix._12, -det * matrix._12,
-det * matrix._21, -det * matrix._21,
@ -224,18 +230,18 @@ namespace kiwano
// Use template expression to optimize matrix multiply // Use template expression to optimize matrix multiply
template <typename L, typename R> template <typename _Ty, typename _Lty, typename _Rty>
struct MatrixMultiply struct MatrixMultiply
{ {
L const& lhs; _Lty const& lhs;
R const& rhs; _Rty const& rhs;
MatrixMultiply(L const& lhs, R const& rhs) MatrixMultiply(_Lty const& lhs, _Rty const& rhs)
: lhs(lhs) : lhs(lhs)
, rhs(rhs) , rhs(rhs)
{} {}
inline float operator [](unsigned int index) const inline _Ty operator [](unsigned int index) const
{ {
switch (index) switch (index)
{ {
@ -257,15 +263,25 @@ namespace kiwano
} }
}; };
inline MatrixMultiply<Matrix, Matrix> operator *(Matrix const& lhs, Matrix const& rhs) template <typename _Ty>
inline
MatrixMultiply<_Ty, MatrixT<_Ty>, MatrixT<_Ty>>
operator *(MatrixT<_Ty> const& lhs, MatrixT<_Ty> const& rhs)
{ {
return MatrixMultiply<Matrix, Matrix>(lhs, rhs); return MatrixMultiply<_Ty, MatrixT<_Ty>, MatrixT<_Ty>>(lhs, rhs);
} }
template <typename L, typename R> template <typename _Ty, typename _Lty, typename _Rty>
inline MatrixMultiply<MatrixMultiply<L, R>, Matrix> operator *(MatrixMultiply<L, R> const& lhs, Matrix const& rhs) inline
MatrixMultiply<_Ty, MatrixMultiply<_Ty, _Lty, _Rty>, MatrixT<_Ty>>
operator *(MatrixMultiply<_Ty, _Lty, _Rty> const& lhs, MatrixT<_Ty> const& rhs)
{ {
return MatrixMultiply<MatrixMultiply<L, R>, Matrix>(lhs, rhs); return MatrixMultiply<_Ty, MatrixMultiply<_Ty, _Lty, _Rty>, MatrixT<_Ty>>(lhs, rhs);
} }
} }
} }
namespace kiwano
{
using Matrix = kiwano::math::MatrixT<float>;
}

View File

@ -26,24 +26,29 @@ namespace kiwano
namespace math namespace math
{ {
// 矩形 // 矩形
struct Rect template <typename _Ty>
struct RectT
{ {
Vec2 origin; // ×óÉϽÇ×ø±ê public:
Vec2 size; // ¿í¶ÈºÍ¸ß¶È using value_type = _Ty;
Rect() {} Vec2T<value_type> origin; // ×óÉϽÇ×ø±ê
Vec2T<value_type> size; // ¿í¶ÈºÍ¸ß¶È
Rect( public:
float x, RectT() {}
float y,
float width, RectT(
float height value_type x,
value_type y,
value_type width,
value_type height
) )
: origin(x, y) : origin(x, y)
, size(width, height) , size(width, height)
{} {}
Rect( RectT(
const Vec2& pos, const Vec2& pos,
const Vec2& size const Vec2& size
) )
@ -51,26 +56,26 @@ namespace kiwano
, size(size.x, size.y) , size(size.x, size.y)
{} {}
Rect( RectT(
const Rect& other const RectT& other
) )
: origin(other.origin.x, other.origin.y) : origin(other.origin.x, other.origin.y)
, size(other.size.x, other.size.y) , size(other.size.x, other.size.y)
{} {}
Rect& operator= (const Rect& other) RectT& operator= (const RectT& other)
{ {
origin = other.origin; origin = other.origin;
size = other.size; size = other.size;
return *this; return *this;
} }
inline bool operator== (const Rect& rect) const inline bool operator== (const RectT& rect) const
{ {
return (origin == rect.origin) && (size == rect.size); return (origin == rect.origin) && (size == rect.size);
} }
inline void Set(float x, float y, float width, float height) { origin = Vec2{ x, y }; size = Vec2{ width, height }; } inline void Set(value_type x, value_type y, value_type width, value_type height) { origin = Vec2{ x, y }; size = Vec2{ width, height }; }
inline Vec2 GetCenter() const { return Vec2{ origin.x + size.x / 2, origin.y + size.y / 2 }; } inline Vec2 GetCenter() const { return Vec2{ origin.x + size.x / 2, origin.y + size.y / 2 }; }
@ -82,13 +87,13 @@ namespace kiwano
inline Vec2 GetLeftBottom() const { return Vec2{ GetLeft(), GetBottom() }; } inline Vec2 GetLeftBottom() const { return Vec2{ GetLeft(), GetBottom() }; }
inline float GetLeft() const { return origin.x; } inline value_type GetLeft() const { return origin.x; }
inline float GetTop() const { return origin.y; } inline value_type GetTop() const { return origin.y; }
inline float GetRight() const { return origin.x + size.x; } inline value_type GetRight() const { return origin.x + size.x; }
inline float GetBottom() const { return origin.y + size.y; } inline value_type GetBottom() const { return origin.y + size.y; }
inline bool IsEmpty() const { return origin.IsOrigin() && size.IsOrigin(); } inline bool IsEmpty() const { return origin.IsOrigin() && size.IsOrigin(); }
@ -100,7 +105,7 @@ namespace kiwano
} }
// 判断两矩形是否相交 // 判断两矩形是否相交
inline bool Intersects(const Rect& rect) const inline bool Intersects(const RectT& rect) const
{ {
return !((origin.x + size.x) < rect.origin.x || return !((origin.x + size.x) < rect.origin.x ||
(rect.origin.x + rect.size.x) < origin.x || (rect.origin.x + rect.size.x) < origin.x ||
@ -110,3 +115,8 @@ namespace kiwano
}; };
} }
} }
namespace kiwano
{
using Rect = kiwano::math::RectT<float>;
}

View File

@ -25,18 +25,21 @@ namespace kiwano
{ {
namespace math namespace math
{ {
struct Vec2 template <typename _Ty>
struct Vec2T
{ {
float x; using value_type = _Ty;
float y;
Vec2() : x(0.f), y(0.f) {} value_type x;
value_type y;
Vec2(float x, float y) : x(x), y(y) {} Vec2T() : x(0.f), y(0.f) {}
Vec2(const Vec2& other) : x(other.x), y(other.y) {} Vec2T(value_type x, value_type y) : x(x), y(y) {}
inline float Length() const Vec2T(const Vec2T& other) : x(other.x), y(other.y) {}
inline value_type Length() const
{ {
return math::Sqrt(x * x + y * y); return math::Sqrt(x * x + y * y);
} }
@ -46,46 +49,51 @@ namespace kiwano
return (x == 0) && (y == 0); return (x == 0) && (y == 0);
} }
inline void Set(float x, float y) inline void Set(value_type x, value_type y)
{ {
this->x = x; this->x = x;
this->y = y; this->y = y;
} }
inline const Vec2 operator + (const Vec2 & other) const inline const Vec2T operator + (const Vec2T & other) const
{ {
return Vec2(x + other.x, y + other.y); return Vec2T(x + other.x, y + other.y);
} }
inline const Vec2 operator - (const Vec2 & other) const inline const Vec2T operator - (const Vec2T & other) const
{ {
return Vec2(x - other.x, y - other.y); return Vec2T(x - other.x, y - other.y);
} }
inline const Vec2 operator * (float val) const inline const Vec2T operator * (value_type val) const
{ {
return Vec2(x * val, y * val); return Vec2T(x * val, y * val);
} }
inline const Vec2 operator / (float val) const inline const Vec2T operator / (value_type val) const
{ {
return Vec2(x / val, y / val); return Vec2T(x / val, y / val);
} }
inline const Vec2 operator - () const inline const Vec2T operator - () const
{ {
return Vec2(-x, -y); return Vec2T(-x, -y);
} }
inline bool operator== (const Vec2& other) const inline bool operator== (const Vec2T& other) const
{ {
return (x == other.x) && (y == other.y); return (x == other.x) && (y == other.y);
} }
inline bool operator!= (const Vec2& other) const inline bool operator!= (const Vec2T& other) const
{ {
return (x != other.x) || (y != other.y); return (x != other.x) || (y != other.y);
} }
}; };
} }
} }
namespace kiwano
{
using Vec2 = kiwano::math::Vec2T<float>;
}

View File

@ -28,8 +28,6 @@
namespace kiwano namespace kiwano
{ {
using namespace kiwano::math; using Point = Vec2;
using Size = Vec2;
typedef Vec2 Point;
typedef Vec2 Size;
} }

View File

@ -262,7 +262,7 @@ namespace kiwano
::curl_global_cleanup(); ::curl_global_cleanup();
} }
void HttpClient::Send(HttpRequestPtr const & request) void HttpClient::Send(HttpRequestPtr request)
{ {
if (!request) if (!request)
return; return;
@ -300,7 +300,7 @@ namespace kiwano
} }
} }
void HttpClient::Perform(HttpRequestPtr const & request, HttpResponsePtr const & response) void HttpClient::Perform(HttpRequestPtr request, HttpResponsePtr response)
{ {
bool ok = false; bool ok = false;
long response_code = 0; long response_code = 0;

View File

@ -34,7 +34,7 @@ namespace kiwano
public: public:
void Send( void Send(
HttpRequestPtr const& request HttpRequestPtr request
); );
inline void SetTimeoutForConnect(Duration timeout) inline void SetTimeoutForConnect(Duration timeout)
@ -78,8 +78,8 @@ namespace kiwano
void NetworkThread(); void NetworkThread();
void Perform( void Perform(
HttpRequestPtr const& request, HttpRequestPtr request,
HttpResponsePtr const& response HttpResponsePtr response
); );
void DispatchResponseCallback(); void DispatchResponseCallback();

View File

@ -28,14 +28,14 @@ namespace kiwano
: public Object : public Object
{ {
public: public:
inline HttpResponse(HttpRequestPtr const& request) inline HttpResponse(HttpRequestPtr request)
: request_(request) : request_(request)
, succeed_(false) , succeed_(false)
, response_code_(0) , response_code_(0)
{ {
} }
inline HttpRequestPtr const& GetRequest() const inline HttpRequestPtr GetRequest() const
{ {
return request_; return request_;
} }

View File

@ -187,7 +187,7 @@ namespace kiwano
} }
} }
void Application::EnterScene(ScenePtr const & scene) void Application::EnterScene(ScenePtr scene)
{ {
KGE_ASSERT(scene && "Application::EnterScene failed, NULL pointer exception"); KGE_ASSERT(scene && "Application::EnterScene failed, NULL pointer exception");
@ -197,7 +197,7 @@ namespace kiwano
next_scene_ = scene; next_scene_ = scene;
} }
void Application::EnterScene(ScenePtr const& scene, TransitionPtr const& transition) void Application::EnterScene(ScenePtr scene, TransitionPtr transition)
{ {
EnterScene(scene); EnterScene(scene);
@ -212,7 +212,7 @@ namespace kiwano
} }
} }
ScenePtr const& Application::GetCurrentScene() ScenePtr Application::GetCurrentScene()
{ {
return curr_scene_; return curr_scene_;
} }

View File

@ -105,17 +105,17 @@ namespace kiwano
// Çл»³¡¾° // Çл»³¡¾°
void EnterScene( void EnterScene(
ScenePtr const& scene /* 场景 */ ScenePtr scene /* 场景 */
); );
// Çл»³¡¾° // Çл»³¡¾°
void EnterScene( void EnterScene(
ScenePtr const& scene, /* 场景 */ ScenePtr scene, /* 场景 */
TransitionPtr const& transition /* 场景动画 */ TransitionPtr transition /* 场景动画 */
); );
// »ñÈ¡µ±Ç°³¡¾° // »ñÈ¡µ±Ç°³¡¾°
ScenePtr const& GetCurrentScene(); ScenePtr GetCurrentScene();
// »ñÈ¡Ö÷´°¿Ú // »ñÈ¡Ö÷´°¿Ú
inline Window* GetWindow() const { return main_window_; } inline Window* GetWindow() const { return main_window_; }

View File

@ -38,17 +38,17 @@ namespace kiwano
} }
} }
inline D2D1_POINT_2F const& ConvertToPoint2F(math::Vec2 const& point) inline D2D1_POINT_2F const& ConvertToPoint2F(Vec2 const& point)
{ {
return reinterpret_cast<D2D1_POINT_2F const&>(point); return reinterpret_cast<D2D1_POINT_2F const&>(point);
} }
inline D2D1_SIZE_F const& ConvertToSizeF(math::Vec2 const& size) inline D2D1_SIZE_F const& ConvertToSizeF(Vec2 const& size)
{ {
return reinterpret_cast<D2D1_SIZE_F const&>(size); return reinterpret_cast<D2D1_SIZE_F const&>(size);
} }
inline D2D1_RECT_F ConvertToRectF(math::Rect const& rect) inline D2D1_RECT_F ConvertToRectF(Rect const& rect)
{ {
return D2D1_RECT_F{ rect.origin.x, rect.origin.y, rect.origin.x + rect.size.x, rect.origin.y + rect.size.y }; return D2D1_RECT_F{ rect.origin.x, rect.origin.y, rect.origin.x + rect.size.x, rect.origin.y + rect.size.y };
} }
@ -58,7 +58,7 @@ namespace kiwano
return reinterpret_cast<D2D1_COLOR_F const&>(color); return reinterpret_cast<D2D1_COLOR_F const&>(color);
} }
inline D2D1_MATRIX_3X2_F const& ConvertToMatrix3x2F(math::Matrix const& matrix) inline D2D1_MATRIX_3X2_F const& ConvertToMatrix3x2F(Matrix const& matrix)
{ {
return reinterpret_cast<D2D1_MATRIX_3X2_F const&>(matrix); return reinterpret_cast<D2D1_MATRIX_3X2_F const&>(matrix);
} }

View File

@ -227,7 +227,7 @@ namespace kiwano
return S_OK; return S_OK;
} }
HRESULT Renderer::DrawImage(ImagePtr const & image, Rect const& dest_rect) HRESULT Renderer::DrawImage(ImagePtr image, Rect const& dest_rect)
{ {
if (!device_context_) if (!device_context_)
return E_UNEXPECTED; return E_UNEXPECTED;

View File

@ -66,7 +66,7 @@ namespace kiwano
); );
HRESULT DrawImage( HRESULT DrawImage(
ImagePtr const& image, ImagePtr image,
Rect const& dest_rect Rect const& dest_rect
); );

View File

@ -79,6 +79,11 @@ namespace kiwano
pressed_callback_ = func; pressed_callback_ = func;
} }
void Button::SetReleasedCallback(const Callback& func)
{
released_callback_ = func;
}
void Button::SetMouseOverCallback(const Callback & func) void Button::SetMouseOverCallback(const Callback & func)
{ {
mouse_over_callback_ = func; mouse_over_callback_ = func;
@ -130,6 +135,9 @@ namespace kiwano
{ {
SetStatus(Status::Hover); SetStatus(Status::Hover);
if (released_callback_)
released_callback_();
if (click_callback_) if (click_callback_)
click_callback_(); click_callback_();
} }

View File

@ -27,16 +27,16 @@ namespace kiwano
class KGE_API Button class KGE_API Button
: public Sprite : public Sprite
{ {
public:
using Callback = Closure<void()>; using Callback = Closure<void()>;
public:
Button(); Button();
explicit Button( explicit Button(
Callback const& click /* 按钮点击回调函数 */ Callback const& click /* 按钮点击回调函数 */
); );
explicit Button( Button(
Callback const& click, /* 按钮点击回调函数 */ Callback const& click, /* 按钮点击回调函数 */
Callback const& pressed, /* 按钮按下回调函数 */ Callback const& pressed, /* 按钮按下回调函数 */
Callback const& mouse_over, /* 按钮移入回调函数 */ Callback const& mouse_over, /* 按钮移入回调函数 */
@ -63,6 +63,11 @@ namespace kiwano
const Callback& func const Callback& func
); );
// 设置按钮被抬起时的回调函数
void SetReleasedCallback(
const Callback& func
);
// 设置鼠标移入按钮时的回调函数 // 设置鼠标移入按钮时的回调函数
void SetMouseOverCallback( void SetMouseOverCallback(
const Callback& func const Callback& func
@ -88,6 +93,7 @@ namespace kiwano
Status status_; Status status_;
Callback click_callback_; Callback click_callback_;
Callback pressed_callback_; Callback pressed_callback_;
Callback released_callback_;
Callback mouse_over_callback_; Callback mouse_over_callback_;
Callback mouse_out_callback_; Callback mouse_out_callback_;
}; };

View File

@ -41,7 +41,7 @@ namespace kiwano
return enabled_; return enabled_;
} }
int Menu::GetButtonCount() const size_t Menu::GetButtonCount() const
{ {
return buttons_.size(); return buttons_.size();
} }
@ -59,7 +59,7 @@ namespace kiwano
} }
} }
void Menu::AddButton(ButtonPtr const& button) void Menu::AddButton(ButtonPtr button)
{ {
if (button) if (button)
{ {
@ -69,7 +69,7 @@ namespace kiwano
} }
} }
bool Menu::RemoveButton(ButtonPtr const& button) bool Menu::RemoveButton(ButtonPtr button)
{ {
if (buttons_.empty()) if (buttons_.empty())
{ {

View File

@ -38,7 +38,7 @@ namespace kiwano
bool IsEnable() const; bool IsEnable() const;
// 获取菜单中的按钮数量 // 获取菜单中的按钮数量
int GetButtonCount() const; size_t GetButtonCount() const;
// 设置菜单启用或禁用 // 设置菜单启用或禁用
void SetEnabled( void SetEnabled(
@ -47,12 +47,12 @@ namespace kiwano
// 添加按钮 // 添加按钮
void AddButton( void AddButton(
ButtonPtr const& button ButtonPtr button
); );
// 移除按钮 // 移除按钮
bool RemoveButton( bool RemoveButton(
ButtonPtr const& button ButtonPtr button
); );
// 获取所有按钮 // 获取所有按钮

View File

@ -58,7 +58,7 @@ namespace kiwano
return false; return false;
} }
bool ResLoader::AddImage(String const & id, ImagePtr const & image) bool ResLoader::AddImage(String const & id, ImagePtr image)
{ {
if (image) if (image)
{ {
@ -68,7 +68,7 @@ namespace kiwano
return false; return false;
} }
int ResLoader::AddFrames(String const& id, Array<Resource> const& images) size_t ResLoader::AddFrames(String const& id, Array<Resource> const& images)
{ {
if (images.empty()) if (images.empty())
return 0; return 0;
@ -100,7 +100,7 @@ namespace kiwano
return 0; return 0;
} }
int ResLoader::AddFrames(String const& id, Array<ImagePtr> const& images) size_t ResLoader::AddFrames(String const& id, Array<ImagePtr> const& images)
{ {
if (images.empty()) if (images.empty())
return 0; return 0;
@ -114,7 +114,7 @@ namespace kiwano
return 0; return 0;
} }
int ResLoader::AddFrames(String const & id, Resource const & image, int cols, int rows) size_t ResLoader::AddFrames(String const & id, Resource const & image, int cols, int rows)
{ {
if (cols <= 0 || rows <= 0) if (cols <= 0 || rows <= 0)
return 0; return 0;
@ -153,7 +153,7 @@ namespace kiwano
return 0; return 0;
} }
int ResLoader::AddFrames(String const & id, Resource const & image, Array<Rect> const & crop_rects) size_t ResLoader::AddFrames(String const & id, Resource const & image, Array<Rect> const & crop_rects)
{ {
ImagePtr raw = new (std::nothrow) Image; ImagePtr raw = new (std::nothrow) Image;
if (!raw || !raw->Load(LocateRes(image, search_paths_))) if (!raw || !raw->Load(LocateRes(image, search_paths_)))
@ -181,7 +181,7 @@ namespace kiwano
return 0; return 0;
} }
bool ResLoader::AddFrames(String const & id, FramesPtr const & frames) bool ResLoader::AddFrames(String const & id, FramesPtr frames)
{ {
if (frames) if (frames)
{ {
@ -191,7 +191,7 @@ namespace kiwano
return false; return false;
} }
bool ResLoader::AddObj(String const& id, ObjectPtr const& obj) bool ResLoader::AddObj(String const& id, ObjectPtr obj)
{ {
if (obj) if (obj)
{ {

View File

@ -33,27 +33,27 @@ namespace kiwano
bool AddImage(String const& id, Resource const& image); bool AddImage(String const& id, Resource const& image);
// 添加图片 // 添加图片
bool AddImage(String const& id, ImagePtr const& image); bool AddImage(String const& id, ImagePtr image);
// 添加帧集合 // 添加帧集合
int AddFrames(String const& id, Array<Resource> const& images); size_t AddFrames(String const& id, Array<Resource> const& images);
// 添加帧集合 // 添加帧集合
int AddFrames(String const& id, Array<ImagePtr> const& images); size_t AddFrames(String const& id, Array<ImagePtr> const& images);
// 添加帧集合 // 添加帧集合
// 按行列数裁剪图片 // 按行列数裁剪图片
int AddFrames(String const& id, Resource const& image, int cols, int rows = 1); size_t AddFrames(String const& id, Resource const& image, int cols, int rows = 1);
// 添加帧集合 // 添加帧集合
// 按指定裁剪矩形裁剪图片 // 按指定裁剪矩形裁剪图片
int AddFrames(String const& id, Resource const& image, Array<Rect> const& crop_rects); size_t AddFrames(String const& id, Resource const& image, Array<Rect> const& crop_rects);
// 添加帧集合 // 添加帧集合
bool AddFrames(String const& id, FramesPtr const& frames); bool AddFrames(String const& id, FramesPtr frames);
// 添加对象 // 添加对象
bool AddObj(String const& id, ObjectPtr const& obj); bool AddObj(String const& id, ObjectPtr obj);
ImagePtr GetImage(String const& id) const; ImagePtr GetImage(String const& id) const;