From 22d9e843fe07dd767b86c39c1a1d19be70f24498 Mon Sep 17 00:00:00 2001 From: Haibo Date: Tue, 8 Jan 2019 19:30:02 +0800 Subject: [PATCH] change: the name of smart pointers start with 'Sp' minor fixes minor fixes minor fixes minor fixes --- core/base/Action.hpp | 8 +-- core/base/ActionCombined.cpp | 18 +++---- core/base/ActionCombined.h | 24 ++++----- core/base/ActionManager.cpp | 6 +-- core/base/ActionManager.h | 4 +- core/base/ActionTween.cpp | 36 ++++++------- core/base/ActionTween.h | 48 ++++++++--------- core/base/Animation.cpp | 10 ++-- core/base/Animation.h | 12 ++--- core/base/Canvas.cpp | 14 ++--- core/base/Canvas.h | 28 +++++----- core/base/DebugNode.h | 2 +- core/base/Delay.cpp | 4 +- core/base/Delay.h | 4 +- core/base/EventDispatcher.cpp | 14 ++--- core/base/EventDispatcher.h | 4 +- core/base/EventListener.h | 6 +-- core/base/Factory.cpp | 46 ++++++++--------- core/base/Factory.h | 48 ++++++++--------- core/base/Frames.cpp | 6 +-- core/base/Frames.h | 8 +-- core/base/Game.cpp | 28 +++++----- core/base/Game.h | 24 ++++----- core/base/Geometry.cpp | 12 ++--- core/base/Geometry.h | 6 +-- core/base/GeometryNode.cpp | 4 +- core/base/GeometryNode.h | 8 +-- core/base/Image.cpp | 10 ++-- core/base/Image.h | 8 +-- core/base/Node.cpp | 18 +++---- core/base/Node.h | 14 ++--- core/base/Sprite.cpp | 6 +-- core/base/Sprite.h | 8 +-- core/base/Task.cpp | 2 +- core/base/Task.h | 26 +++++----- core/base/TaskManager.cpp | 8 +-- core/base/TaskManager.h | 4 +- core/base/Text.h | 4 +- core/base/TextRenderer.h | 2 +- core/base/Transition.cpp | 12 ++--- core/base/Transition.h | 32 ++++++------ core/base/d2dhelper.hpp | 42 +++++++-------- core/base/helper.hpp | 21 ++------ core/base/intrusive/List.hpp | 10 ++-- core/base/intrusive/SmartPointer.hpp | 2 +- core/base/modules.cpp | 3 ++ core/base/modules.h | 2 + core/base/render.cpp | 28 +++++----- core/base/render.h | 38 +++++++------- core/base/time.cpp | 77 +++++----------------------- core/base/time.h | 26 +++------- core/base/window.cpp | 2 +- core/ui/Menu.cpp | 8 +-- core/ui/Menu.h | 10 ++-- core/utils/Player.cpp | 4 +- core/utils/Player.h | 2 +- core/utils/Transcoder.cpp | 2 +- 57 files changed, 398 insertions(+), 465 deletions(-) diff --git a/core/base/Action.hpp b/core/base/Action.hpp index 7d1b43ec..78e7707c 100644 --- a/core/base/Action.hpp +++ b/core/base/Action.hpp @@ -30,13 +30,13 @@ namespace easy2d class Action : public Object - , protected intrusive::ListItem + , protected intrusive::ListItem { friend class ActionManager; friend class Loop; friend class Sequence; friend class Spawn; - friend class intrusive::List; + friend class intrusive::List; public: Action() : running_(false), done_(false), initialized_(false) {} @@ -56,10 +56,10 @@ namespace easy2d virtual void Stop() { if (!done_) { done_ = true; if (cb_) cb_(); } } // 获取动作的拷贝 - virtual spAction Clone() const = 0; + virtual SpAction Clone() const = 0; // 获取动作的倒转 - virtual spAction Reverse() const = 0; + virtual SpAction Reverse() const = 0; // 重置动作 virtual void Reset() diff --git a/core/base/ActionCombined.cpp b/core/base/ActionCombined.cpp index 8931f5e1..be3f3765 100644 --- a/core/base/ActionCombined.cpp +++ b/core/base/ActionCombined.cpp @@ -27,7 +27,7 @@ namespace easy2d // Loop //------------------------------------------------------- - Loop::Loop(spAction const& action, int times) + Loop::Loop(SpAction const& action, int times) : action_(action) , times_(0) , total_times_(times) @@ -41,7 +41,7 @@ namespace easy2d { } - spAction Loop::Clone() const + SpAction Loop::Clone() const { if (action_) { @@ -53,7 +53,7 @@ namespace easy2d } } - spAction Loop::Reverse() const + SpAction Loop::Reverse() const { if (action_) { @@ -172,7 +172,7 @@ namespace easy2d action_index_ = 0; } - void Sequence::Add(spAction const& action) + void Sequence::Add(SpAction const& action) { if (action) { @@ -188,7 +188,7 @@ namespace easy2d } } - spAction Sequence::Clone() const + SpAction Sequence::Clone() const { auto sequence = new (std::nothrow) Sequence(); if (sequence) @@ -204,7 +204,7 @@ namespace easy2d return sequence; } - spAction Sequence::Reverse() const + SpAction Sequence::Reverse() const { auto sequence = new (std::nothrow) Sequence(); if (sequence && !actions_.empty()) @@ -281,7 +281,7 @@ namespace easy2d } } - void Spawn::Add(spAction const& action) + void Spawn::Add(SpAction const& action) { if (action) { @@ -297,7 +297,7 @@ namespace easy2d } } - spAction Spawn::Clone() const + SpAction Spawn::Clone() const { auto spawn = new (std::nothrow) Spawn(); if (spawn) @@ -313,7 +313,7 @@ namespace easy2d return spawn; } - spAction Spawn::Reverse() const + SpAction Spawn::Reverse() const { auto spawn = new (std::nothrow) Spawn(); if (spawn && !actions_.empty()) diff --git a/core/base/ActionCombined.h b/core/base/ActionCombined.h index cc2661ba..d6133c03 100644 --- a/core/base/ActionCombined.h +++ b/core/base/ActionCombined.h @@ -29,17 +29,17 @@ namespace easy2d { public: explicit Loop( - spAction const& action, /* 执行循环的动作 */ + SpAction const& action, /* 执行循环的动作 */ int times = -1 /* 循环次数 */ ); virtual ~Loop(); // 获取该动作的拷贝对象 - virtual spAction Clone() const override; + virtual SpAction Clone() const override; // 获取该动作的倒转 - virtual spAction Reverse() const override; + virtual SpAction Reverse() const override; // 重置动作 virtual void Reset() override; @@ -54,7 +54,7 @@ namespace easy2d virtual void Update(Node* target, Duration const& dt) override; protected: - spAction action_; + SpAction action_; int times_; int total_times_; }; @@ -64,7 +64,7 @@ namespace easy2d class Sequence : public Action { - using Actions = std::vector; + using Actions = std::vector; public: Sequence(); @@ -77,7 +77,7 @@ namespace easy2d // 在结尾添加动作 void Add( - spAction const& action + SpAction const& action ); // 在结尾添加多个动作 @@ -86,10 +86,10 @@ namespace easy2d ); // 获取该动作的拷贝对象 - virtual spAction Clone() const override; + virtual SpAction Clone() const override; // 获取该动作的倒转 - virtual spAction Reverse() const override; + virtual SpAction Reverse() const override; // 重置动作 virtual void Reset() override; @@ -111,7 +111,7 @@ namespace easy2d class Spawn : public Action { - using Actions = std::vector; + using Actions = std::vector; public: Spawn(); @@ -124,7 +124,7 @@ namespace easy2d // 在结尾添加动作 void Add( - spAction const& action + SpAction const& action ); // 在结尾添加多个动作 @@ -133,10 +133,10 @@ namespace easy2d ); // 获取该动作的拷贝对象 - virtual spAction Clone() const override; + virtual SpAction Clone() const override; // 获取该动作的倒转 - virtual spAction Reverse() const; + virtual SpAction Reverse() const; // 重置动作 virtual void Reset() override; diff --git a/core/base/ActionManager.cpp b/core/base/ActionManager.cpp index b5681757..994127e6 100644 --- a/core/base/ActionManager.cpp +++ b/core/base/ActionManager.cpp @@ -28,7 +28,7 @@ namespace easy2d if (actions_.IsEmpty()) return; - spAction next; + SpAction next; for (auto action = actions_.First(); action; action = next) { next = action->NextItem(); @@ -41,14 +41,14 @@ namespace easy2d } } - void ActionManager::AddAction(spAction const& action) + void ActionManager::AddAction(SpAction const& action) { E2D_ASSERT(action && "AddAction failed, NULL pointer exception"); if (action) { action->Start(); - actions_.PushBack(Action::ItemType(action)); + actions_.PushBack(action); } } diff --git a/core/base/ActionManager.h b/core/base/ActionManager.h index 8ecb28a1..b2b7f480 100644 --- a/core/base/ActionManager.h +++ b/core/base/ActionManager.h @@ -25,12 +25,12 @@ namespace easy2d { class ActionManager { - using Actions = intrusive::List; + using Actions = intrusive::List; public: // 执行动作 void AddAction( - spAction const& action + SpAction const& action ); // 继续所有暂停动作 diff --git a/core/base/ActionTween.cpp b/core/base/ActionTween.cpp index ee751579..d7049a9f 100644 --- a/core/base/ActionTween.cpp +++ b/core/base/ActionTween.cpp @@ -235,12 +235,12 @@ namespace easy2d } } - spAction MoveBy::Clone() const + SpAction MoveBy::Clone() const { return new (std::nothrow) MoveBy(duration_, delta_pos_, ease_type_); } - spAction MoveBy::Reverse() const + SpAction MoveBy::Reverse() const { return new (std::nothrow) MoveBy(duration_, -delta_pos_, ease_type_); } @@ -251,7 +251,7 @@ namespace easy2d end_pos_ = pos; } - spAction MoveTo::Clone() const + SpAction MoveTo::Clone() const { return new (std::nothrow) MoveTo(duration_, end_pos_, ease_type_); } @@ -275,12 +275,12 @@ namespace easy2d { } - spAction JumpBy::Clone() const + SpAction JumpBy::Clone() const { return new (std::nothrow) JumpBy(duration_, delta_pos_, height_, jumps_, ease_type_); } - spAction JumpBy::Reverse() const + SpAction JumpBy::Reverse() const { return new (std::nothrow) JumpBy(duration_, -delta_pos_, height_, jumps_, ease_type_); } @@ -320,7 +320,7 @@ namespace easy2d { } - spAction JumpTo::Clone() const + SpAction JumpTo::Clone() const { return new (std::nothrow) JumpTo(duration_, end_pos_, height_, jumps_, ease_type_); } @@ -369,12 +369,12 @@ namespace easy2d } } - spAction ScaleBy::Clone() const + SpAction ScaleBy::Clone() const { return new (std::nothrow) ScaleBy(duration_, delta_x_, delta_y_, ease_type_); } - spAction ScaleBy::Reverse() const + SpAction ScaleBy::Reverse() const { return new (std::nothrow) ScaleBy(duration_, -delta_x_, -delta_y_, ease_type_); } @@ -393,7 +393,7 @@ namespace easy2d end_scale_y_ = scale_y; } - spAction ScaleTo::Clone() const + SpAction ScaleTo::Clone() const { return new (std::nothrow) ScaleTo(duration_, end_scale_x_, end_scale_y_, ease_type_); } @@ -434,12 +434,12 @@ namespace easy2d } } - spAction OpacityBy::Clone() const + SpAction OpacityBy::Clone() const { return new (std::nothrow) OpacityBy(duration_, delta_val_, ease_type_); } - spAction OpacityBy::Reverse() const + SpAction OpacityBy::Reverse() const { return new (std::nothrow) OpacityBy(duration_, -delta_val_, ease_type_); } @@ -450,7 +450,7 @@ namespace easy2d end_val_ = opacity; } - spAction OpacityTo::Clone() const + SpAction OpacityTo::Clone() const { return new (std::nothrow) OpacityTo(duration_, end_val_, ease_type_); } @@ -500,12 +500,12 @@ namespace easy2d } } - spAction RotateBy::Clone() const + SpAction RotateBy::Clone() const { return new (std::nothrow) RotateBy(duration_, delta_val_, ease_type_); } - spAction RotateBy::Reverse() const + SpAction RotateBy::Reverse() const { return new (std::nothrow) RotateBy(duration_, -delta_val_, ease_type_); } @@ -516,7 +516,7 @@ namespace easy2d end_val_ = rotation; } - spAction RotateTo::Clone() const + SpAction RotateTo::Clone() const { return new (std::nothrow) RotateTo(duration_, end_val_, ease_type_); } @@ -532,7 +532,7 @@ namespace easy2d // PathAction //------------------------------------------------------- - PathAction::PathAction(Duration const & duration, spGeometry const& geo, bool rotating, float start, float end, EaseFunc func) + PathAction::PathAction(Duration const & duration, SpGeometry const& geo, bool rotating, float start, float end, EaseFunc func) : Tween(duration, func) , start_(start) , end_(end) @@ -541,12 +541,12 @@ namespace easy2d { } - spAction PathAction::Clone() const + SpAction PathAction::Clone() const { return new PathAction(duration_, geo_, rotating_, start_, end_, ease_type_); } - spAction PathAction::Reverse() const + SpAction PathAction::Reverse() const { return new PathAction(duration_, geo_, rotating_, end_, start_, ease_type_); } diff --git a/core/base/ActionTween.h b/core/base/ActionTween.h index 5c9dba02..6f710c02 100644 --- a/core/base/ActionTween.h +++ b/core/base/ActionTween.h @@ -128,10 +128,10 @@ namespace easy2d ); // 获取该动作的拷贝对象 - virtual spAction Clone() const override; + virtual SpAction Clone() const override; // 获取该动作的倒转 - virtual spAction Reverse() const override; + virtual SpAction Reverse() const override; protected: virtual void Init(Node* target) override; @@ -157,10 +157,10 @@ namespace easy2d ); // 获取该动作的拷贝对象 - virtual spAction Clone() const override; + virtual SpAction Clone() const override; // 获取该动作的倒转 - virtual spAction Reverse() const override + virtual SpAction Reverse() const override { logs::Errorln("Reverse() not supported in MoveTo"); return nullptr; @@ -188,10 +188,10 @@ namespace easy2d ); // 获取该动作的拷贝对象 - virtual spAction Clone() const override; + virtual SpAction Clone() const override; // 获取该动作的倒转 - virtual spAction Reverse() const override; + virtual SpAction Reverse() const override; protected: virtual void Init(Node* target) override; @@ -221,10 +221,10 @@ namespace easy2d ); // 获取该动作的拷贝对象 - virtual spAction Clone() const override; + virtual SpAction Clone() const override; // 获取该动作的倒转 - virtual spAction Reverse() const override + virtual SpAction Reverse() const override { logs::Errorln("Reverse() not supported in JumpTo"); return nullptr; @@ -257,10 +257,10 @@ namespace easy2d ); // 获取该动作的拷贝对象 - virtual spAction Clone() const override; + virtual SpAction Clone() const override; // 获取该动作的倒转 - virtual spAction Reverse() const override; + virtual SpAction Reverse() const override; protected: virtual void Init(Node* target) override; @@ -294,10 +294,10 @@ namespace easy2d ); // 获取该动作的拷贝对象 - virtual spAction Clone() const override; + virtual SpAction Clone() const override; // 获取该动作的倒转 - virtual spAction Reverse() const override + virtual SpAction Reverse() const override { logs::Errorln("Reverse() not supported in ScaleTo"); return nullptr; @@ -324,10 +324,10 @@ namespace easy2d ); // 获取该动作的拷贝对象 - virtual spAction Clone() const override; + virtual SpAction Clone() const override; // 获取该动作的倒转 - virtual spAction Reverse() const override; + virtual SpAction Reverse() const override; protected: virtual void Init(Node* target) override; @@ -352,10 +352,10 @@ namespace easy2d ); // 获取该动作的拷贝对象 - virtual spAction Clone() const override; + virtual SpAction Clone() const override; // 获取该动作的倒转 - virtual spAction Reverse() const override + virtual SpAction Reverse() const override { logs::Errorln("Reverse() not supported in OpacityTo"); return nullptr; @@ -407,10 +407,10 @@ namespace easy2d ); // 获取该动作的拷贝对象 - virtual spAction Clone() const override; + virtual SpAction Clone() const override; // 获取该动作的倒转 - virtual spAction Reverse() const override; + virtual SpAction Reverse() const override; protected: virtual void Init(Node* target) override; @@ -435,10 +435,10 @@ namespace easy2d ); // 获取该动作的拷贝对象 - virtual spAction Clone() const override; + virtual SpAction Clone() const override; // 获取该动作的倒转 - virtual spAction Reverse() const override + virtual SpAction Reverse() const override { logs::Errorln("Reverse() not supported in RotateTo"); return nullptr; @@ -459,7 +459,7 @@ namespace easy2d public: explicit PathAction( Duration const& duration, /* 持续时长 */ - spGeometry const& geo, /* 几何图形 */ + SpGeometry const& geo, /* 几何图形 */ bool rotating = false, /* 沿路径切线方向旋转 */ float start = 0.f, /* 起点 */ float end = 1.f, /* 终点 */ @@ -467,10 +467,10 @@ namespace easy2d ); // 获取该动作的拷贝对象 - virtual spAction Clone() const override; + virtual SpAction Clone() const override; // 获取该动作的倒转 - virtual spAction Reverse() const override; + virtual SpAction Reverse() const override; protected: virtual void Init(Node* target) override; @@ -482,6 +482,6 @@ namespace easy2d float start_; float end_; Point start_pos_; - spGeometry geo_; + SpGeometry geo_; }; } diff --git a/core/base/Animation.cpp b/core/base/Animation.cpp index a006e473..257ebc97 100644 --- a/core/base/Animation.cpp +++ b/core/base/Animation.cpp @@ -31,7 +31,7 @@ namespace easy2d { } - Animation::Animation(spFrames const& animation) + Animation::Animation(SpFrames const& animation) : frame_index_(0) , frames_(nullptr) { @@ -42,12 +42,12 @@ namespace easy2d { } - spFrames Animation::GetAnimation() const + SpFrames Animation::GetAnimation() const { return frames_; } - void Animation::SetAnimation(spFrames const& animation) + void Animation::SetAnimation(SpFrames const& animation) { if (animation && animation != frames_) { @@ -106,7 +106,7 @@ namespace easy2d frame_index_ = 0; } - spAction Animation::Clone() const + SpAction Animation::Clone() const { if (frames_) { @@ -115,7 +115,7 @@ namespace easy2d return nullptr; } - spAction Animation::Reverse() const + SpAction Animation::Reverse() const { if (frames_) { diff --git a/core/base/Animation.h b/core/base/Animation.h index 7b19e297..2bfbd51c 100644 --- a/core/base/Animation.h +++ b/core/base/Animation.h @@ -31,24 +31,24 @@ namespace easy2d Animation(); explicit Animation( - spFrames const& animation + SpFrames const& animation ); virtual ~Animation(); // 获取动画 - spFrames GetAnimation() const; + SpFrames GetAnimation() const; // 设置动画 void SetAnimation( - spFrames const& animation + SpFrames const& animation ); // 获取该动作的拷贝对象 - virtual spAction Clone() const override; + virtual SpAction Clone() const override; // 获取该动作的倒转 - virtual spAction Reverse() const override; + virtual SpAction Reverse() const override; // 重置动作 virtual void Reset() override; @@ -63,6 +63,6 @@ namespace easy2d protected: size_t frame_index_; Duration delta_; - spFrames frames_; + SpFrames frames_; }; } diff --git a/core/base/Canvas.cpp b/core/base/Canvas.cpp index 24d6c542..3200f870 100644 --- a/core/base/Canvas.cpp +++ b/core/base/Canvas.cpp @@ -247,7 +247,7 @@ namespace easy2d cache_expired_ = true; } - void Canvas::DrawImage(spImage const & image, float opacity) + void Canvas::DrawImage(SpImage const & image, float opacity) { if (image && image->GetBitmap()) { @@ -267,7 +267,7 @@ namespace easy2d if (text.empty()) return; - cpTextFormat text_format; + CpTextFormat text_format; ThrowIfFailed( Factory::Instance()->CreateTextFormat( text_format, @@ -276,7 +276,7 @@ namespace easy2d ) ); - cpTextLayout text_layout; + CpTextLayout text_layout; Size layout_size; ThrowIfFailed( Factory::Instance()->CreateTextLayout( @@ -293,7 +293,7 @@ namespace easy2d ); } - void Canvas::DrawGeometry(spGeometry const & geo) + void Canvas::DrawGeometry(SpGeometry const & geo) { if (geo && geo->geo_) { @@ -371,7 +371,7 @@ namespace easy2d cache_expired_ = true; } - void Canvas::FillGeometry(spGeometry const & geo) + void Canvas::FillGeometry(SpGeometry const & geo) { if (geo && geo->geo_) { @@ -493,14 +493,14 @@ namespace easy2d cache_expired_ = true; } - spImage Canvas::ExportToImage() const + SpImage Canvas::ExportToImage() const { auto image = new Image(GetBitmap()); image->Crop(Rect(Point{}, this->GetSize())); return image; } - cpBitmap const& easy2d::Canvas::GetBitmap() const + CpBitmap const& easy2d::Canvas::GetBitmap() const { if (cache_expired_) { diff --git a/core/base/Canvas.h b/core/base/Canvas.h index b111b8ec..6fec91c7 100644 --- a/core/base/Canvas.h +++ b/core/base/Canvas.h @@ -85,7 +85,7 @@ namespace easy2d // 画图片 void DrawImage( - spImage const& image, + SpImage const& image, float opacity = 1.f ); @@ -97,7 +97,7 @@ namespace easy2d // 画几何图形边框 void DrawGeometry( - spGeometry const& geo + SpGeometry const& geo ); // 填充圆形 @@ -127,7 +127,7 @@ namespace easy2d // 填充几何图形 void FillGeometry( - spGeometry const& geo + SpGeometry const& geo ); // 开始绘制路径 @@ -216,26 +216,26 @@ namespace easy2d ); // 导出为图片 - spImage ExportToImage() const; + SpImage ExportToImage() const; virtual void OnRender() override; protected: - cpBitmap const& GetBitmap() const; + CpBitmap const& GetBitmap() const; protected: mutable bool cache_expired_; - mutable cpBitmap bitmap_cached_; + mutable CpBitmap bitmap_cached_; float stroke_width_; Font text_font_; TextStyle text_style_; - cpPathGeometry current_geometry_; - cpGeometrySink current_sink_; - cpStrokeStyle outline_join_style_; - cpSolidColorBrush fill_brush_; - cpSolidColorBrush stroke_brush_; - cpSolidColorBrush text_brush_; - cpTextRenderer text_renderer_; - cpBitmapRenderTarget render_target_; + CpPathGeometry current_geometry_; + CpGeometrySink current_sink_; + CpStrokeStyle outline_join_style_; + CpSolidColorBrush fill_brush_; + CpSolidColorBrush stroke_brush_; + CpSolidColorBrush text_brush_; + CpTextRenderer text_renderer_; + CpBitmapRenderTarget render_target_; }; } \ No newline at end of file diff --git a/core/base/DebugNode.h b/core/base/DebugNode.h index d63d48d9..dbd5c66d 100644 --- a/core/base/DebugNode.h +++ b/core/base/DebugNode.h @@ -44,7 +44,7 @@ namespace easy2d void OnUpdate(Duration const& dt) override; protected: - spText debug_text_; + SpText debug_text_; std::vector frame_time_; std::vector texts_; }; diff --git a/core/base/Delay.cpp b/core/base/Delay.cpp index 9bfb66a5..00c57fc7 100644 --- a/core/base/Delay.cpp +++ b/core/base/Delay.cpp @@ -51,12 +51,12 @@ namespace easy2d } } - spAction Delay::Clone() const + SpAction Delay::Clone() const { return new (std::nothrow) Delay(delay_); } - spAction Delay::Reverse() const + SpAction Delay::Reverse() const { return new (std::nothrow) Delay(delay_); } diff --git a/core/base/Delay.h b/core/base/Delay.h index 76d492da..f0f88d25 100644 --- a/core/base/Delay.h +++ b/core/base/Delay.h @@ -33,10 +33,10 @@ namespace easy2d ); // 获取该动作的拷贝对象 - virtual spAction Clone() const override; + virtual SpAction Clone() const override; // 获取该动作的倒转 - virtual spAction Reverse() const override; + virtual SpAction Reverse() const override; // 重置动作 virtual void Reset() override; diff --git a/core/base/EventDispatcher.cpp b/core/base/EventDispatcher.cpp index d93112bb..6e6d8ca4 100644 --- a/core/base/EventDispatcher.cpp +++ b/core/base/EventDispatcher.cpp @@ -28,7 +28,7 @@ namespace easy2d if (listeners_.IsEmpty()) return; - spEventListener next; + SpEventListener next; for (auto listener = listeners_.First(); listener; listener = next) { next = listener->NextItem(); @@ -40,22 +40,22 @@ namespace easy2d } } - void EventDispatcher::AddListener(spEventListener const & listener) + void EventDispatcher::AddListener(SpEventListener const & listener) { E2D_ASSERT(listener && "AddListener failed, NULL pointer exception"); if (listener) { - listeners_.PushBack(EventListener::ItemType(listener)); + listeners_.PushBack(listener); } } void EventDispatcher::AddListener(EventType type, EventCallback callback, std::wstring const& name) { - spEventListener listener = new EventListener(type, callback, name); + SpEventListener listener = new EventListener(type, callback, name); if (listener) { - listeners_.PushBack(EventListener::ItemType(listener)); + listeners_.PushBack(listener); } } @@ -83,7 +83,7 @@ namespace easy2d void EventDispatcher::RemoveListeners(std::wstring const & listener_name) { - spEventListener next; + SpEventListener next; for (auto listener = listeners_.First(); listener; listener = next) { next = listener->NextItem(); @@ -119,7 +119,7 @@ namespace easy2d void EventDispatcher::RemoveListeners(EventType type) { - spEventListener next; + SpEventListener next; for (auto listener = listeners_.First(); listener; listener = next) { next = listener->NextItem(); diff --git a/core/base/EventDispatcher.h b/core/base/EventDispatcher.h index 2e53f547..a6e9f350 100644 --- a/core/base/EventDispatcher.h +++ b/core/base/EventDispatcher.h @@ -25,12 +25,12 @@ namespace easy2d { class EventDispatcher { - using Listeners = intrusive::List; + using Listeners = intrusive::List; public: // 添加监听器 void AddListener( - spEventListener const& listener + SpEventListener const& listener ); // 添加监听器 diff --git a/core/base/EventListener.h b/core/base/EventListener.h index fbdc890a..6ed23703 100644 --- a/core/base/EventListener.h +++ b/core/base/EventListener.h @@ -32,10 +32,10 @@ namespace easy2d class EventListener : public Object - , protected intrusive::ListItem + , protected intrusive::ListItem { friend class EventDispatcher; - friend class intrusive::List; + friend class intrusive::List; public: EventListener( @@ -58,7 +58,7 @@ namespace easy2d protected: bool running_; - std::wstring name_; + std::wstring name_; EventType type_; EventCallback callback_; }; diff --git a/core/base/Factory.cpp b/core/base/Factory.cpp index 1a735f5b..242f7f6e 100644 --- a/core/base/Factory.cpp +++ b/core/base/Factory.cpp @@ -111,12 +111,12 @@ namespace easy2d return hr; } - HRESULT FactoryImpl::CreateHwndRenderTarget(cpHwndRenderTarget & hwnd_render_target, D2D1_RENDER_TARGET_PROPERTIES const & properties, D2D1_HWND_RENDER_TARGET_PROPERTIES const & hwnd_rt_properties) const + HRESULT FactoryImpl::CreateHwndRenderTarget(CpHwndRenderTarget & hwnd_render_target, D2D1_RENDER_TARGET_PROPERTIES const & properties, D2D1_HWND_RENDER_TARGET_PROPERTIES const & hwnd_rt_properties) const { if (!factory_) return E_UNEXPECTED; - cpHwndRenderTarget hwnd_render_target_tmp; + CpHwndRenderTarget hwnd_render_target_tmp; HRESULT hr = factory_->CreateHwndRenderTarget( properties, hwnd_rt_properties, @@ -129,15 +129,15 @@ namespace easy2d } HRESULT FactoryImpl::CreateTextRenderer( - cpTextRenderer& text_renderer, - cpRenderTarget const& render_target, - cpSolidColorBrush const& brush + CpTextRenderer& text_renderer, + CpRenderTarget const& render_target, + CpSolidColorBrush const& brush ) { if (!factory_) return E_UNEXPECTED; - cpTextRenderer text_renderer_tmp; + CpTextRenderer text_renderer_tmp; HRESULT hr = ITextRenderer::Create( &text_renderer_tmp, factory_.Get(), @@ -150,7 +150,7 @@ namespace easy2d return hr; } - HRESULT FactoryImpl::CreateBitmapFromFile(cpBitmap & bitmap, cpRenderTarget const & rt, std::wstring const & file_path) + HRESULT FactoryImpl::CreateBitmapFromFile(CpBitmap & bitmap, CpRenderTarget const & rt, std::wstring const & file_path) { if (imaging_factory_ == nullptr) { @@ -211,7 +211,7 @@ namespace easy2d return hr; } - HRESULT FactoryImpl::CreateBitmapFromResource(cpBitmap & bitmap, cpRenderTarget const & rt, Resource const & res) + HRESULT FactoryImpl::CreateBitmapFromResource(CpBitmap & bitmap, CpRenderTarget const & rt, Resource const & res) { if (imaging_factory_ == nullptr) { @@ -293,12 +293,12 @@ namespace easy2d return hr; } - HRESULT FactoryImpl::CreateRectangleGeometry(cpRectangleGeometry & geo, Rect const& rect) const + HRESULT FactoryImpl::CreateRectangleGeometry(CpRectangleGeometry & geo, Rect const& rect) const { if (!factory_) return E_UNEXPECTED; - cpRectangleGeometry rectangle; + CpRectangleGeometry rectangle; HRESULT hr = factory_->CreateRectangleGeometry( rect, &rectangle @@ -309,12 +309,12 @@ namespace easy2d return hr; } - HRESULT FactoryImpl::CreateRoundedRectangleGeometry(cpRoundedRectangleGeometry & geo, Rect const & rect, float radius_x, float radius_y) const + HRESULT FactoryImpl::CreateRoundedRectangleGeometry(CpRoundedRectangleGeometry & geo, Rect const & rect, float radius_x, float radius_y) const { if (!factory_) return E_UNEXPECTED; - cpRoundedRectangleGeometry rounded_rect; + CpRoundedRectangleGeometry rounded_rect; HRESULT hr = factory_->CreateRoundedRectangleGeometry( D2D1::RoundedRect( rect, @@ -329,12 +329,12 @@ namespace easy2d return hr; } - HRESULT FactoryImpl::CreateEllipseGeometry(cpEllipseGeometry & geo, Point const & center, float radius_x, float radius_y) const + HRESULT FactoryImpl::CreateEllipseGeometry(CpEllipseGeometry & geo, Point const & center, float radius_x, float radius_y) const { if (!factory_) return E_UNEXPECTED; - cpEllipseGeometry ellipse; + CpEllipseGeometry ellipse; HRESULT hr = factory_->CreateEllipseGeometry( D2D1::Ellipse( center, @@ -350,15 +350,15 @@ namespace easy2d } HRESULT FactoryImpl::CreateTransformedGeometry( - cpTransformedGeometry& transformed, + CpTransformedGeometry& transformed, Matrix const& matrix, - cpGeometry const& geo + CpGeometry const& geo ) const { if (!factory_) return E_UNEXPECTED; - cpTransformedGeometry transformed_tmp; + CpTransformedGeometry transformed_tmp; HRESULT hr = factory_->CreateTransformedGeometry( geo.Get(), matrix, @@ -372,7 +372,7 @@ namespace easy2d return hr; } - HRESULT FactoryImpl::CreatePathGeometry(cpPathGeometry & geometry) const + HRESULT FactoryImpl::CreatePathGeometry(CpPathGeometry & geometry) const { if (!factory_) return E_UNEXPECTED; @@ -380,12 +380,12 @@ namespace easy2d return factory_->CreatePathGeometry(&geometry); } - HRESULT FactoryImpl::CreateTextFormat(cpTextFormat & text_format, Font const & font, TextStyle const & text_style) const + HRESULT FactoryImpl::CreateTextFormat(CpTextFormat & text_format, Font const & font, TextStyle const & text_style) const { if (!write_factory_) return E_UNEXPECTED; - cpTextFormat text_format_tmp; + CpTextFormat text_format_tmp; HRESULT hr = write_factory_->CreateTextFormat( font.family.c_str(), nullptr, @@ -418,7 +418,7 @@ namespace easy2d return hr; } - HRESULT FactoryImpl::CreateTextLayout(cpTextLayout & text_layout, Size& layout_size, std::wstring const & text, cpTextFormat const& text_format, TextStyle const & text_style) const + HRESULT FactoryImpl::CreateTextLayout(CpTextLayout & text_layout, Size& layout_size, std::wstring const & text, CpTextFormat const& text_format, TextStyle const & text_style) const { if (!write_factory_) return E_UNEXPECTED; @@ -426,7 +426,7 @@ namespace easy2d text_layout = nullptr; HRESULT hr; - cpTextLayout text_layout_tmp; + CpTextLayout text_layout_tmp; UINT32 length = static_cast(text.length()); if (text_style.wrap) @@ -496,7 +496,7 @@ namespace easy2d return hr; } - cpStrokeStyle const& FactoryImpl::GetStrokeStyle(StrokeStyle stroke) const + CpStrokeStyle const& FactoryImpl::GetStrokeStyle(StrokeStyle stroke) const { switch (stroke) { diff --git a/core/base/Factory.h b/core/base/Factory.h index 52dc2d69..1edf1359 100644 --- a/core/base/Factory.h +++ b/core/base/Factory.h @@ -38,73 +38,73 @@ namespace easy2d HRESULT Init(bool debug); HRESULT CreateHwndRenderTarget( - cpHwndRenderTarget& hwnd_render_target, + CpHwndRenderTarget& hwnd_render_target, D2D1_RENDER_TARGET_PROPERTIES const& properties, D2D1_HWND_RENDER_TARGET_PROPERTIES const& hwnd_rt_properties ) const; HRESULT CreateTextRenderer( - cpTextRenderer& text_renderer, - cpRenderTarget const& render_target, - cpSolidColorBrush const& brush + CpTextRenderer& text_renderer, + CpRenderTarget const& render_target, + CpSolidColorBrush const& brush ); HRESULT CreateBitmapFromFile( - cpBitmap& bitmap, - cpRenderTarget const& rt, + CpBitmap& bitmap, + CpRenderTarget const& rt, std::wstring const& file_path ); HRESULT CreateBitmapFromResource( - cpBitmap& bitmap, - cpRenderTarget const& rt, + CpBitmap& bitmap, + CpRenderTarget const& rt, Resource const& res ); HRESULT CreateRectangleGeometry( - cpRectangleGeometry& geo, + CpRectangleGeometry& geo, Rect const& rect ) const; HRESULT CreateRoundedRectangleGeometry( - cpRoundedRectangleGeometry& geo, + CpRoundedRectangleGeometry& geo, Rect const& rect, float radius_x, float radius_y ) const; HRESULT CreateEllipseGeometry( - cpEllipseGeometry& geo, + CpEllipseGeometry& geo, Point const& center, float radius_x, float radius_y ) const; HRESULT CreateTransformedGeometry( - cpTransformedGeometry& transformed, + CpTransformedGeometry& transformed, Matrix const& matrix, - cpGeometry const& geo + CpGeometry const& geo ) const; HRESULT CreatePathGeometry( - cpPathGeometry& geometry + CpPathGeometry& geometry ) const; HRESULT CreateTextFormat( - cpTextFormat& text_format, + CpTextFormat& text_format, Font const& font, TextStyle const& text_style ) const; HRESULT CreateTextLayout( - cpTextLayout& text_layout, + CpTextLayout& text_layout, Size& layout_size, std::wstring const& text, - cpTextFormat const& text_format, + CpTextFormat const& text_format, TextStyle const& text_style ) const; - cpStrokeStyle const& GetStrokeStyle( + CpStrokeStyle const& GetStrokeStyle( StrokeStyle stroke ) const; @@ -114,12 +114,12 @@ namespace easy2d ~FactoryImpl(); protected: - cpFactory factory_; - cpImagingFactory imaging_factory_; - cpWriteFactory write_factory_; - cpStrokeStyle miter_stroke_style_; - cpStrokeStyle bevel_stroke_style_; - cpStrokeStyle round_stroke_style_; + CpFactory factory_; + CpImagingFactory imaging_factory_; + CpWriteFactory write_factory_; + CpStrokeStyle miter_stroke_style_; + CpStrokeStyle bevel_stroke_style_; + CpStrokeStyle round_stroke_style_; }; E2D_DECLARE_SINGLETON_TYPE(FactoryImpl, Factory); diff --git a/core/base/Frames.cpp b/core/base/Frames.cpp index 636231ec..7ef10b4e 100644 --- a/core/base/Frames.cpp +++ b/core/base/Frames.cpp @@ -55,7 +55,7 @@ namespace easy2d interval_ = interval; } - void Frames::Add(spImage const& frame) + void Frames::Add(SpImage const& frame) { E2D_ASSERT(frame && "Frames::Add failed, NULL pointer exception"); @@ -83,7 +83,7 @@ namespace easy2d return frames_; } - spFrames Frames::Clone() const + SpFrames Frames::Clone() const { auto animation = new (std::nothrow) Frames(interval_); if (animation) @@ -96,7 +96,7 @@ namespace easy2d return animation; } - spFrames Frames::Reverse() const + SpFrames Frames::Reverse() const { auto animation = new (std::nothrow) Frames(interval_); if (!frames_.empty()) diff --git a/core/base/Frames.h b/core/base/Frames.h index 766bc198..9108e824 100644 --- a/core/base/Frames.h +++ b/core/base/Frames.h @@ -28,7 +28,7 @@ namespace easy2d class Frames : public Object { - using Images = std::vector< spImage >; + using Images = std::vector< SpImage >; public: Frames(); @@ -50,7 +50,7 @@ namespace easy2d // 添加关键帧 void Add( - spImage const& frame /* 关键帧 */ + SpImage const& frame /* 关键帧 */ ); // 添加多个关键帧 @@ -70,10 +70,10 @@ namespace easy2d ); // 获取帧动画的拷贝对象 - spFrames Clone() const; + SpFrames Clone() const; // 获取帧动画的倒转 - spFrames Reverse() const; + SpFrames Reverse() const; protected: Duration interval_; diff --git a/core/base/Game.cpp b/core/base/Game.cpp index 402eab8a..df14693c 100644 --- a/core/base/Game.cpp +++ b/core/base/Game.cpp @@ -154,7 +154,7 @@ namespace easy2d Window::Instance()->Destroy(); } - void Game::EnterScene(spScene const & scene) + void Game::EnterScene(SpScene const & scene) { E2D_ASSERT(scene && "Game::EnterScene failed, NULL pointer exception"); @@ -164,7 +164,7 @@ namespace easy2d next_scene_ = scene; } - void Game::EnterScene(spScene const& scene, spTransition const& transition) + void Game::EnterScene(SpScene const& scene, SpTransition const& transition) { EnterScene(scene); @@ -179,7 +179,7 @@ namespace easy2d } } - spScene const& Game::GetCurrentScene() + SpScene const& Game::GetCurrentScene() { return curr_scene_; } @@ -199,26 +199,15 @@ namespace easy2d Input::Instance()->Update(); - if (curr_scene_) - curr_scene_->Update(dt); - - if (next_scene_) - next_scene_->Update(dt); - - if (debug_) - DebugNode::Instance()->Update(dt); - if (transition_) { transition_->Update(dt); if (transition_->IsDone()) transition_ = nullptr; - else - return; } - if (next_scene_) + if (next_scene_ && !transition_) { if (curr_scene_) { @@ -230,6 +219,15 @@ namespace easy2d curr_scene_ = next_scene_; next_scene_ = nullptr; } + + if (curr_scene_) + curr_scene_->Update(dt); + + if (next_scene_) + next_scene_->Update(dt); + + if (debug_) + DebugNode::Instance()->Update(dt); } void Game::Render(HWND hwnd) diff --git a/core/base/Game.h b/core/base/Game.h index 8ac0f898..bc3a05db 100644 --- a/core/base/Game.h +++ b/core/base/Game.h @@ -32,11 +32,11 @@ namespace easy2d struct Options { std::wstring title; // 标题 - int width; // 宽度 - int height; // 高度 - LPCWSTR icon; // 图标 - bool vsync; // 垂直同步 - bool debug; // 调试模式 + int width; // 宽度 + int height; // 高度 + LPCWSTR icon; // 图标 + bool vsync; // 垂直同步 + bool debug; // 调试模式 Options() : title(L"Easy2D Game") @@ -80,17 +80,17 @@ namespace easy2d // 切换场景 void EnterScene( - spScene const& scene /* 场景 */ + SpScene const& scene /* 场景 */ ); // 切换场景 void EnterScene( - spScene const& scene, /* 场景 */ - spTransition const& transition /* 场景动画 */ + SpScene const& scene, /* 场景 */ + SpTransition const& transition /* 场景动画 */ ); // 获取当前场景 - spScene const& GetCurrentScene(); + SpScene const& GetCurrentScene(); // 设置变速 void SetTimeScale(float scale); @@ -117,8 +117,8 @@ namespace easy2d bool debug_; bool active_; float time_scale_; - spScene curr_scene_; - spScene next_scene_; - spTransition transition_; + SpScene curr_scene_; + SpScene next_scene_; + SpTransition transition_; }; } diff --git a/core/base/Geometry.cpp b/core/base/Geometry.cpp index 26349a21..c8badf22 100644 --- a/core/base/Geometry.cpp +++ b/core/base/Geometry.cpp @@ -126,8 +126,8 @@ namespace easy2d void LineGeometry::SetLine(Point const & begin, Point const & end) { - cpPathGeometry path_geo; - cpGeometrySink path_sink; + CpPathGeometry path_geo; + CpGeometrySink path_sink; HRESULT hr = Factory::Instance()->CreatePathGeometry(path_geo); @@ -185,7 +185,7 @@ namespace easy2d void RectangleGeometry::SetRect(Rect const & rect) { - cpRectangleGeometry geo; + CpRectangleGeometry geo; if (SUCCEEDED(Factory::Instance()->CreateRectangleGeometry(geo, rect))) { geo_ = geo; @@ -224,7 +224,7 @@ namespace easy2d void CircleGeometry::SetCircle(Point const & center, float radius) { - cpEllipseGeometry geo; + CpEllipseGeometry geo; if (SUCCEEDED(Factory::Instance()->CreateEllipseGeometry(geo, center, radius, radius))) { geo_ = geo; @@ -265,7 +265,7 @@ namespace easy2d void EllipseGeometry::SetEllipse(Point const & center, float radius_x, float radius_y) { - cpEllipseGeometry geo; + CpEllipseGeometry geo; if (SUCCEEDED(Factory::Instance()->CreateEllipseGeometry(geo, center, radius_x, radius_y))) { geo_ = geo; @@ -414,7 +414,7 @@ namespace easy2d void RoundedRectGeometry::SetRoundedRect(Rect const & rect, float radius_x, float radius_y) { - cpRoundedRectangleGeometry geo; + CpRoundedRectangleGeometry geo; if (SUCCEEDED(Factory::Instance()->CreateRoundedRectangleGeometry(geo, rect, radius_x, radius_y))) { geo_ = geo; diff --git a/core/base/Geometry.h b/core/base/Geometry.h index 1e59dc2f..8dc33182 100644 --- a/core/base/Geometry.h +++ b/core/base/Geometry.h @@ -57,7 +57,7 @@ namespace easy2d float ComputeArea(); protected: - cpGeometry geo_; + CpGeometry geo_; }; @@ -254,8 +254,8 @@ namespace easy2d void ClearPath(); protected: - cpPathGeometry current_geometry_; - cpGeometrySink current_sink_; + CpPathGeometry current_geometry_; + CpGeometrySink current_sink_; }; diff --git a/core/base/GeometryNode.cpp b/core/base/GeometryNode.cpp index 86c29fb6..2528a347 100644 --- a/core/base/GeometryNode.cpp +++ b/core/base/GeometryNode.cpp @@ -31,7 +31,7 @@ namespace easy2d { } - GeometryNode::GeometryNode(spGeometry const& geometry) + GeometryNode::GeometryNode(SpGeometry const& geometry) : GeometryNode() { SetGeometry(geometry); @@ -41,7 +41,7 @@ namespace easy2d { } - void GeometryNode::SetGeometry(spGeometry const& geometry) + void GeometryNode::SetGeometry(SpGeometry const& geometry) { geometry_ = geometry; } diff --git a/core/base/GeometryNode.h b/core/base/GeometryNode.h index f584d7ad..583375ac 100644 --- a/core/base/GeometryNode.h +++ b/core/base/GeometryNode.h @@ -32,14 +32,14 @@ namespace easy2d GeometryNode(); GeometryNode( - spGeometry const& geometry + SpGeometry const& geometry ); virtual ~GeometryNode(); // 设置形状 void SetGeometry( - spGeometry const& geometry + SpGeometry const& geometry ); // 设置填充颜色 @@ -63,7 +63,7 @@ namespace easy2d ); // 获取形状 - spGeometry const& GetGeometry() const { return geometry_; } + SpGeometry const& GetGeometry() const { return geometry_; } // 获取填充颜色 Color GetFillColor() const { return fill_color_; } @@ -84,6 +84,6 @@ namespace easy2d Color stroke_color_; float stroke_width_; StrokeStyle outline_join_; - spGeometry geometry_; + SpGeometry geometry_; }; } diff --git a/core/base/Image.cpp b/core/base/Image.cpp index a6ca1b16..bf73fb75 100644 --- a/core/base/Image.cpp +++ b/core/base/Image.cpp @@ -58,7 +58,7 @@ namespace easy2d this->Crop(crop_rect); } - Image::Image(cpBitmap const & bitmap) + Image::Image(CpBitmap const & bitmap) : Image() { SetBitmap(bitmap); @@ -70,7 +70,7 @@ namespace easy2d bool Image::Load(Resource const& res) { - cpBitmap bitmap; + CpBitmap bitmap; HRESULT hr = Graphics::Instance()->CreateBitmapFromResource(bitmap, res); if (FAILED(hr)) { @@ -94,7 +94,7 @@ namespace easy2d // 默认搜索路径,所以需要通过 File::GetPath 获取完整路径 std::wstring image_file_path = image_file.GetPath(); - cpBitmap bitmap; + CpBitmap bitmap; HRESULT hr = Graphics::Instance()->CreateBitmapFromFile(bitmap, image_file_path); if (FAILED(hr)) { @@ -181,12 +181,12 @@ namespace easy2d return crop_rect_; } - cpBitmap const& Image::GetBitmap() const + CpBitmap const& Image::GetBitmap() const { return bitmap_; } - void Image::SetBitmap(cpBitmap const & bitmap) + void Image::SetBitmap(CpBitmap const & bitmap) { if (bitmap) { diff --git a/core/base/Image.h b/core/base/Image.h index ae8a196d..162ed9aa 100644 --- a/core/base/Image.h +++ b/core/base/Image.h @@ -50,7 +50,7 @@ namespace easy2d ); explicit Image( - cpBitmap const& bitmap + CpBitmap const& bitmap ); virtual ~Image(); @@ -100,15 +100,15 @@ namespace easy2d // 获取裁剪矩形 Rect const& GetCropRect() const; - cpBitmap const& GetBitmap() const; + CpBitmap const& GetBitmap() const; protected: void SetBitmap( - cpBitmap const& bitmap + CpBitmap const& bitmap ); protected: Rect crop_rect_; - cpBitmap bitmap_; + CpBitmap bitmap_; }; } diff --git a/core/base/Node.cpp b/core/base/Node.cpp index f6c816a9..8777c07c 100644 --- a/core/base/Node.cpp +++ b/core/base/Node.cpp @@ -62,7 +62,7 @@ namespace easy2d if (!children_.IsEmpty()) { - spNode next; + SpNode next; for (auto child = children_.First(); child; child = next) { next = child->NextItem(); @@ -118,7 +118,7 @@ namespace easy2d if (!visible_) return; - spNode prev; + SpNode prev; for (auto child = children_.Last(); child; child = prev) { prev = child->PrevItem(); @@ -255,7 +255,7 @@ namespace easy2d if (parent_) { - spNode me = this; + SpNode me = this; parent_->children_.Remove(me); @@ -272,7 +272,7 @@ namespace easy2d if (sibling) { - parent_->children_.InsertAfter(me, spNode(sibling)); + parent_->children_.InsertAfter(me, SpNode(sibling)); } else { @@ -444,7 +444,7 @@ namespace easy2d dirty_transform_ = true; } - void Node::AddChild(spNode const& child) + void Node::AddChild(SpNode const& child) { E2D_ASSERT(child && "Node::AddChild failed, NULL pointer exception"); @@ -461,7 +461,7 @@ namespace easy2d #endif // E2D_DEBUG - children_.PushBack(Node::ItemType(child)); + children_.PushBack(child); child->parent_ = this; child->SetScene(this->scene_); child->dirty_transform_ = true; @@ -498,7 +498,7 @@ namespace easy2d return children; } - spNode Node::GetChild(std::wstring const& name) const + SpNode Node::GetChild(std::wstring const& name) const { size_t hash_code = std::hash{}(name); @@ -525,7 +525,7 @@ namespace easy2d } } - bool Node::RemoveChild(spNode const& child) + bool Node::RemoveChild(SpNode const& child) { return RemoveChild(child.Get()); } @@ -541,7 +541,7 @@ namespace easy2d { child->parent_ = nullptr; if (child->scene_) child->SetScene(nullptr); - children_.Remove(spNode(child)); + children_.Remove(SpNode(child)); return true; } return false; diff --git a/core/base/Node.h b/core/base/Node.h index c4ebbb26..621066d4 100644 --- a/core/base/Node.h +++ b/core/base/Node.h @@ -37,15 +37,15 @@ namespace easy2d , public TaskManager , public ActionManager , public EventDispatcher - , protected intrusive::ListItem + , protected intrusive::ListItem { friend class Game; friend class Scene; friend class Transition; - friend class intrusive::List; + friend class intrusive::List; - using Nodes = std::vector; - using Children = intrusive::List; + using Nodes = std::vector; + using Children = intrusive::List; public: Node(); @@ -292,7 +292,7 @@ namespace easy2d // 添加子节点 void AddChild( - spNode const& child + SpNode const& child ); // 添加多个子节点 @@ -306,7 +306,7 @@ namespace easy2d ) const; // 获取名称相同的子节点 - spNode GetChild( + SpNode GetChild( std::wstring const& name ) const; @@ -315,7 +315,7 @@ namespace easy2d // 移除子节点 bool RemoveChild( - spNode const& child + SpNode const& child ); // 移除子节点 diff --git a/core/base/Sprite.cpp b/core/base/Sprite.cpp index 4f219978..ccbfd27d 100644 --- a/core/base/Sprite.cpp +++ b/core/base/Sprite.cpp @@ -28,7 +28,7 @@ namespace easy2d { } - Sprite::Sprite(spImage const& image) + Sprite::Sprite(SpImage const& image) : image_(nullptr) { Load(image); @@ -64,7 +64,7 @@ namespace easy2d { } - bool Sprite::Load(spImage const& image) + bool Sprite::Load(SpImage const& image) { if (image) { @@ -121,7 +121,7 @@ namespace easy2d ); } - spImage const& Sprite::GetImage() const + SpImage const& Sprite::GetImage() const { return image_; } diff --git a/core/base/Sprite.h b/core/base/Sprite.h index fdb4d0f9..32719745 100644 --- a/core/base/Sprite.h +++ b/core/base/Sprite.h @@ -32,7 +32,7 @@ namespace easy2d Sprite(); explicit Sprite( - spImage const& image + SpImage const& image ); explicit Sprite( @@ -67,7 +67,7 @@ namespace easy2d // 加载图片 bool Load( - spImage const& image + SpImage const& image ); // 将图片裁剪为矩形 @@ -76,12 +76,12 @@ namespace easy2d ); // 获取 Image 对象 - spImage const& GetImage() const; + SpImage const& GetImage() const; // 渲染精灵 virtual void OnRender() override; protected: - spImage image_; + SpImage image_; }; } diff --git a/core/base/Task.cpp b/core/base/Task.cpp index 58516343..db58744f 100644 --- a/core/base/Task.cpp +++ b/core/base/Task.cpp @@ -22,7 +22,7 @@ namespace easy2d { - Task::Task(const Callback & func, std::wstring const& name) + Task::Task(Callback const& func, std::wstring const& name) : Task(func, Duration{}, -1, name) { } diff --git a/core/base/Task.h b/core/base/Task.h index 1a77b31f..21992bae 100644 --- a/core/base/Task.h +++ b/core/base/Task.h @@ -31,23 +31,23 @@ namespace easy2d // 定时任务 class Task : public Object - , protected intrusive::ListItem + , protected intrusive::ListItem { friend class TaskManager; - friend class intrusive::List; + friend class intrusive::List; using Callback = std::function; public: explicit Task( - const Callback& func, /* 执行函数 */ + Callback const& func, /* 执行函数 */ std::wstring const& name = L"" /* 任务名称 */ ); explicit Task( - Callback const& func, /* 执行函数 */ - Duration const& delay, /* 时间间隔(秒) */ - int times = -1, /* 执行次数(设 -1 为永久执行) */ + Callback const& func, /* 执行函数 */ + Duration const& delay, /* 时间间隔(秒) */ + int times = -1, /* 执行次数(设 -1 为永久执行) */ std::wstring const& name = L"" /* 任务名称 */ ); @@ -69,12 +69,12 @@ namespace easy2d void Reset(); protected: - bool running_; - int run_times_; - int total_times_; - std::wstring name_; - Duration delay_; - Duration delta_; - Callback callback_; + bool running_; + int run_times_; + int total_times_; + std::wstring name_; + Duration delay_; + Duration delta_; + Callback callback_; }; } diff --git a/core/base/TaskManager.cpp b/core/base/TaskManager.cpp index 756f8c38..58dde7cf 100644 --- a/core/base/TaskManager.cpp +++ b/core/base/TaskManager.cpp @@ -28,7 +28,7 @@ namespace easy2d if (tasks_.IsEmpty()) return; - spTask next; + SpTask next; for (auto task = tasks_.First(); task; task = next) { next = task->NextItem(); @@ -41,14 +41,14 @@ namespace easy2d } } - void TaskManager::AddTask(spTask const& task) + void TaskManager::AddTask(SpTask const& task) { E2D_ASSERT(task && "AddTask failed, NULL pointer exception"); if (task) { task->Reset(); - tasks_.PushBack(Task::ItemType(task)); + tasks_.PushBack(task); } } @@ -85,7 +85,7 @@ namespace easy2d if (tasks_.IsEmpty()) return; - spTask next; + SpTask next; for (auto task = tasks_.First(); task; task = next) { next = task->NextItem(); diff --git a/core/base/TaskManager.h b/core/base/TaskManager.h index 95c35c78..856c4d46 100644 --- a/core/base/TaskManager.h +++ b/core/base/TaskManager.h @@ -25,12 +25,12 @@ namespace easy2d { class TaskManager { - using Tasks = intrusive::List; + using Tasks = intrusive::List; public: // 添加任务 void AddTask( - spTask const& task + SpTask const& task ); // 启动任务 diff --git a/core/base/Text.h b/core/base/Text.h index 686d47c8..4881969c 100644 --- a/core/base/Text.h +++ b/core/base/Text.h @@ -208,7 +208,7 @@ namespace easy2d std::wstring text_; Font font_; TextStyle style_; - cpTextFormat text_format_; - cpTextLayout text_layout_; + CpTextFormat text_format_; + CpTextLayout text_layout_; }; } \ No newline at end of file diff --git a/core/base/TextRenderer.h b/core/base/TextRenderer.h index 2c339cc2..da5560e6 100644 --- a/core/base/TextRenderer.h +++ b/core/base/TextRenderer.h @@ -123,4 +123,4 @@ namespace easy2d }; } -E2D_DECLARE_D2D_SMART_PTR(easy2d::ITextRenderer, cpTextRenderer); +E2D_DECLARE_D2D_SMART_PTR(easy2d::ITextRenderer, CpTextRenderer); diff --git a/core/base/Transition.cpp b/core/base/Transition.cpp index 4eca7abb..183b240d 100644 --- a/core/base/Transition.cpp +++ b/core/base/Transition.cpp @@ -55,7 +55,7 @@ namespace easy2d return done_; } - void Transition::Init(spScene const& prev, spScene const& next) + void Transition::Init(SpScene const& prev, SpScene const& next) { process_ = 0; delta_ = Duration{}; @@ -147,7 +147,7 @@ namespace easy2d { } - void BoxTransition::Init(spScene const& prev, spScene const& next) + void BoxTransition::Init(SpScene const& prev, SpScene const& next) { Transition::Init(prev, next); @@ -189,7 +189,7 @@ namespace easy2d { } - void EmergeTransition::Init(spScene const& prev, spScene const& next) + void EmergeTransition::Init(SpScene const& prev, SpScene const& next) { Transition::Init(prev, next); @@ -214,7 +214,7 @@ namespace easy2d { } - void FadeTransition::Init(spScene const& prev, spScene const& next) + void FadeTransition::Init(SpScene const& prev, SpScene const& next) { Transition::Init(prev, next); @@ -248,7 +248,7 @@ namespace easy2d { } - void MoveTransition::Init(spScene const& prev, spScene const& next) + void MoveTransition::Init(SpScene const& prev, SpScene const& next) { Transition::Init(prev, next); @@ -327,7 +327,7 @@ namespace easy2d { } - void RotationTransition::Init(spScene const& prev, spScene const& next) + void RotationTransition::Init(SpScene const& prev, SpScene const& next) { Transition::Init(prev, next); diff --git a/core/base/Transition.h b/core/base/Transition.h index a277aa43..4a90885c 100644 --- a/core/base/Transition.h +++ b/core/base/Transition.h @@ -43,8 +43,8 @@ namespace easy2d protected: virtual void Init( - spScene const& prev, - spScene const& next + SpScene const& prev, + SpScene const& next ); virtual void Update(Duration const& dt); @@ -61,10 +61,10 @@ namespace easy2d Duration duration_; Duration delta_; Size window_size_; - spScene out_scene_; - spScene in_scene_; - cpLayer out_layer_; - cpLayer in_layer_; + SpScene out_scene_; + SpScene in_scene_; + CpLayer out_layer_; + CpLayer in_layer_; LayerProperties out_layer_prop_; LayerProperties in_layer_prop_; }; @@ -84,8 +84,8 @@ namespace easy2d virtual void Update(Duration const& dt) override; virtual void Init( - spScene const& prev, - spScene const& next + SpScene const& prev, + SpScene const& next ) override; }; @@ -103,8 +103,8 @@ namespace easy2d virtual void Update(Duration const& dt) override; virtual void Init( - spScene const& prev, - spScene const& next + SpScene const& prev, + SpScene const& next ) override; }; @@ -122,8 +122,8 @@ namespace easy2d virtual void Update(Duration const& dt) override; virtual void Init( - spScene const& prev, - spScene const& next + SpScene const& prev, + SpScene const& next ) override; }; @@ -142,8 +142,8 @@ namespace easy2d virtual void Update(Duration const& dt) override; virtual void Init( - spScene const& prev, - spScene const& next + SpScene const& prev, + SpScene const& next ) override; virtual void Reset() override; @@ -169,8 +169,8 @@ namespace easy2d virtual void Update(Duration const& dt) override; virtual void Init( - spScene const& prev, - spScene const& next + SpScene const& prev, + SpScene const& next ) override; virtual void Reset() override; diff --git a/core/base/d2dhelper.hpp b/core/base/d2dhelper.hpp index b8459ed8..e7c45a5f 100644 --- a/core/base/d2dhelper.hpp +++ b/core/base/d2dhelper.hpp @@ -31,28 +31,30 @@ namespace easy2d { - E2D_DECLARE_D2D_SMART_PTR(ID2D1Factory, cpFactory); - E2D_DECLARE_D2D_SMART_PTR(IWICImagingFactory, cpImagingFactory); - E2D_DECLARE_D2D_SMART_PTR(IDWriteFactory, cpWriteFactory); - E2D_DECLARE_D2D_SMART_PTR(ID2D1SolidColorBrush, cpSolidColorBrush); - E2D_DECLARE_D2D_SMART_PTR(ID2D1RenderTarget, cpRenderTarget); - E2D_DECLARE_D2D_SMART_PTR(ID2D1HwndRenderTarget, cpHwndRenderTarget); - E2D_DECLARE_D2D_SMART_PTR(ID2D1BitmapRenderTarget, cpBitmapRenderTarget); - E2D_DECLARE_D2D_SMART_PTR(ID2D1StrokeStyle, cpStrokeStyle); + // "Cp" is a shorthand for "COM Pointer" - E2D_DECLARE_D2D_SMART_PTR(ID2D1Geometry, cpGeometry); - E2D_DECLARE_D2D_SMART_PTR(ID2D1RectangleGeometry, cpRectangleGeometry); - E2D_DECLARE_D2D_SMART_PTR(ID2D1RoundedRectangleGeometry, cpRoundedRectangleGeometry); - E2D_DECLARE_D2D_SMART_PTR(ID2D1EllipseGeometry, cpEllipseGeometry); - E2D_DECLARE_D2D_SMART_PTR(ID2D1GeometryGroup, cpGeometryGroup); - E2D_DECLARE_D2D_SMART_PTR(ID2D1PathGeometry, cpPathGeometry); - E2D_DECLARE_D2D_SMART_PTR(ID2D1TransformedGeometry, cpTransformedGeometry); - E2D_DECLARE_D2D_SMART_PTR(ID2D1GeometrySink, cpGeometrySink); + E2D_DECLARE_D2D_SMART_PTR(ID2D1Factory, CpFactory); + E2D_DECLARE_D2D_SMART_PTR(IWICImagingFactory, CpImagingFactory); + E2D_DECLARE_D2D_SMART_PTR(IDWriteFactory, CpWriteFactory); + E2D_DECLARE_D2D_SMART_PTR(ID2D1SolidColorBrush, CpSolidColorBrush); + E2D_DECLARE_D2D_SMART_PTR(ID2D1RenderTarget, CpRenderTarget); + E2D_DECLARE_D2D_SMART_PTR(ID2D1HwndRenderTarget, CpHwndRenderTarget); + E2D_DECLARE_D2D_SMART_PTR(ID2D1BitmapRenderTarget, CpBitmapRenderTarget); + E2D_DECLARE_D2D_SMART_PTR(ID2D1StrokeStyle, CpStrokeStyle); - E2D_DECLARE_D2D_SMART_PTR(ID2D1Layer, cpLayer); - E2D_DECLARE_D2D_SMART_PTR(ID2D1Bitmap, cpBitmap); - E2D_DECLARE_D2D_SMART_PTR(IDWriteTextFormat, cpTextFormat); - E2D_DECLARE_D2D_SMART_PTR(IDWriteTextLayout, cpTextLayout); + E2D_DECLARE_D2D_SMART_PTR(ID2D1Geometry, CpGeometry); + E2D_DECLARE_D2D_SMART_PTR(ID2D1RectangleGeometry, CpRectangleGeometry); + E2D_DECLARE_D2D_SMART_PTR(ID2D1RoundedRectangleGeometry, CpRoundedRectangleGeometry); + E2D_DECLARE_D2D_SMART_PTR(ID2D1EllipseGeometry, CpEllipseGeometry); + E2D_DECLARE_D2D_SMART_PTR(ID2D1GeometryGroup, CpGeometryGroup); + E2D_DECLARE_D2D_SMART_PTR(ID2D1PathGeometry, CpPathGeometry); + E2D_DECLARE_D2D_SMART_PTR(ID2D1TransformedGeometry, CpTransformedGeometry); + E2D_DECLARE_D2D_SMART_PTR(ID2D1GeometrySink, CpGeometrySink); + + E2D_DECLARE_D2D_SMART_PTR(ID2D1Layer, CpLayer); + E2D_DECLARE_D2D_SMART_PTR(ID2D1Bitmap, CpBitmap); + E2D_DECLARE_D2D_SMART_PTR(IDWriteTextFormat, CpTextFormat); + E2D_DECLARE_D2D_SMART_PTR(IDWriteTextLayout, CpTextLayout); inline void IntrusivePtrAddRef(IUnknown* ptr) { diff --git a/core/base/helper.hpp b/core/base/helper.hpp index 1957a47c..9c33a0a6 100644 --- a/core/base/helper.hpp +++ b/core/base/helper.hpp @@ -28,18 +28,20 @@ #ifndef E2D_DECLARE_SMART_PTR #define E2D_DECLARE_SMART_PTR(class_name)\ class class_name;\ - using sp##class_name = ::easy2d::intrusive::SmartPointer< class_name > + using Sp##class_name = ::easy2d::intrusive::SmartPointer< class_name > #define E2D_DECLARE_NS_SMART_PTR(ns_name, class_name)\ namespace ns_name\ {\ class class_name; \ - using sp##class_name = ::easy2d::intrusive::SmartPointer< class_name >;\ + using Sp##class_name = ::easy2d::intrusive::SmartPointer< class_name >;\ } #endif namespace easy2d { + // "Sp" is a shorthand for "Smart Pointer" + E2D_DECLARE_SMART_PTR(Image); E2D_DECLARE_SMART_PTR(Music); E2D_DECLARE_SMART_PTR(Task); @@ -97,19 +99,4 @@ namespace easy2d using Size = math::Vector2; using Rect = math::Rect; using Matrix = math::Matrix; - - template - inline Dest SafeCast(Src ptr) - { - if (!ptr) - return nullptr; - -#ifdef E2D_DEBUG - Dest cast = dynamic_cast(ptr); - E2D_ASSERT(cast); - return cast; -#else - return static_cast(ptr); -#endif - } } diff --git a/core/base/intrusive/List.hpp b/core/base/intrusive/List.hpp index 6e304710..28a9e11c 100644 --- a/core/base/intrusive/List.hpp +++ b/core/base/intrusive/List.hpp @@ -82,7 +82,7 @@ namespace easy2d bool IsEmpty() const { return !first_; } - void PushBack(T& child) + void PushBack(T const& child) { if (child->prev_) child->prev_->next_ = child->next_; @@ -106,7 +106,7 @@ namespace easy2d DEBUG_CHECK_LIST(this); } - void PushFront(T& child) + void PushFront(T const& child) { if (child->prev_) child->prev_->next_ = child->next_; @@ -130,7 +130,7 @@ namespace easy2d DEBUG_CHECK_LIST(this); } - void InsertBefore(T& child, T& before) + void InsertBefore(T const& child, T const& before) { if (child->prev_) child->prev_->next_ = child->next_; @@ -149,7 +149,7 @@ namespace easy2d DEBUG_CHECK_LIST(this); } - void InsertAfter(T& child, T& after) + void InsertAfter(T const& child, T const& after) { if (child->prev_) child->prev_->next_ = child->next_; @@ -168,7 +168,7 @@ namespace easy2d DEBUG_CHECK_LIST(this); } - void Remove(T& child) + void Remove(T const& child) { #ifdef E2D_DEBUG T tmp = first_; diff --git a/core/base/intrusive/SmartPointer.hpp b/core/base/intrusive/SmartPointer.hpp index 1e8eed16..2900fdb7 100644 --- a/core/base/intrusive/SmartPointer.hpp +++ b/core/base/intrusive/SmartPointer.hpp @@ -192,7 +192,7 @@ namespace easy2d } template - inline intrusive::SmartPointer make_intrusive(T* ptr) E2D_NOEXCEPT + inline intrusive::SmartPointer MakeSmart(T* ptr) E2D_NOEXCEPT { return intrusive::SmartPointer(ptr); } diff --git a/core/base/modules.cpp b/core/base/modules.cpp index bd053109..f3ffd4c9 100644 --- a/core/base/modules.cpp +++ b/core/base/modules.cpp @@ -32,6 +32,9 @@ namespace easy2d { PathFileExistsW = (PFN_PathFileExistsW) GetProcAddress(shlwapi, "PathFileExistsW"); + + SHCreateMemStream = (PFN_SHCreateMemStream) + GetProcAddress(shlwapi, "SHCreateMemStream"); } else { diff --git a/core/base/modules.h b/core/base/modules.h index c001b0cf..807069fb 100644 --- a/core/base/modules.h +++ b/core/base/modules.h @@ -37,11 +37,13 @@ namespace easy2d // Shlwapi functions typedef BOOL(WINAPI *PFN_PathFileExistsW)(LPCWSTR); + typedef IStream*(WINAPI *PFN_SHCreateMemStream)(const BYTE*, UINT); public: Shlwapi(); PFN_PathFileExistsW PathFileExistsW; + PFN_SHCreateMemStream SHCreateMemStream; }; diff --git a/core/base/render.cpp b/core/base/render.cpp index 591ec79c..9cd5fa3c 100644 --- a/core/base/render.cpp +++ b/core/base/render.cpp @@ -108,17 +108,17 @@ namespace easy2d bitmap_cache_.clear(); } - cpHwndRenderTarget const & GraphicsDevice::GetRenderTarget() const + CpHwndRenderTarget const & GraphicsDevice::GetRenderTarget() const { return render_target_; } - cpSolidColorBrush const & GraphicsDevice::GetSolidBrush() const + CpSolidColorBrush const & GraphicsDevice::GetSolidBrush() const { return solid_brush_; } - HRESULT GraphicsDevice::CreateLayer(cpLayer& layer) + HRESULT GraphicsDevice::CreateLayer(CpLayer& layer) { if (!render_target_) return E_UNEXPECTED; @@ -127,7 +127,7 @@ namespace easy2d return render_target_->CreateLayer(&layer); } - HRESULT GraphicsDevice::CreateSolidColorBrush(cpSolidColorBrush & brush) const + HRESULT GraphicsDevice::CreateSolidColorBrush(CpSolidColorBrush & brush) const { if (!render_target_) return E_UNEXPECTED; @@ -140,7 +140,7 @@ namespace easy2d } HRESULT GraphicsDevice::DrawGeometry( - cpGeometry const& geometry, + CpGeometry const& geometry, Color const& stroke_color, float stroke_width, StrokeStyle stroke @@ -167,7 +167,7 @@ namespace easy2d return S_OK; } - HRESULT GraphicsDevice::FillGeometry(cpGeometry const & geometry, const Color & fill_color) + HRESULT GraphicsDevice::FillGeometry(CpGeometry const & geometry, const Color & fill_color) { if (!solid_brush_ || !render_target_) @@ -187,7 +187,7 @@ namespace easy2d return S_OK; } - HRESULT GraphicsDevice::DrawImage(spImage const & image) + HRESULT GraphicsDevice::DrawImage(SpImage const & image) { if (!render_target_) return E_UNEXPECTED; @@ -212,7 +212,7 @@ namespace easy2d } HRESULT GraphicsDevice::DrawBitmap( - cpBitmap const& bitmap + CpBitmap const& bitmap ) { if (!render_target_) @@ -236,7 +236,7 @@ namespace easy2d return S_OK; } - HRESULT GraphicsDevice::DrawTextLayout(cpTextLayout const& text_layout) + HRESULT GraphicsDevice::DrawTextLayout(CpTextLayout const& text_layout) { if (!text_renderer_) return E_UNEXPECTED; @@ -277,7 +277,7 @@ namespace easy2d return S_OK; } - HRESULT GraphicsDevice::PushLayer(cpLayer const& layer, LayerProperties const& properties) + HRESULT GraphicsDevice::PushLayer(CpLayer const& layer, LayerProperties const& properties) { if (!render_target_ || !solid_brush_) @@ -324,7 +324,7 @@ namespace easy2d return S_OK; } - HRESULT GraphicsDevice::CreateBitmapFromFile(cpBitmap& bitmap, std::wstring const& file_path) + HRESULT GraphicsDevice::CreateBitmapFromFile(CpBitmap& bitmap, std::wstring const& file_path) { if (render_target_ == nullptr) { @@ -338,7 +338,7 @@ namespace easy2d return S_OK; } - cpBitmap bitmap_tmp; + CpBitmap bitmap_tmp; HRESULT hr = Factory::Instance()->CreateBitmapFromFile( bitmap, render_target_, @@ -353,7 +353,7 @@ namespace easy2d return hr; } - HRESULT GraphicsDevice::CreateBitmapFromResource(cpBitmap& bitmap, Resource const& res) + HRESULT GraphicsDevice::CreateBitmapFromResource(CpBitmap& bitmap, Resource const& res) { if (render_target_ == nullptr) { @@ -381,7 +381,7 @@ namespace easy2d return hr; } - HRESULT GraphicsDevice::CreateBitmapRenderTarget(cpBitmapRenderTarget & brt) + HRESULT GraphicsDevice::CreateBitmapRenderTarget(CpBitmapRenderTarget & brt) { if (!render_target_) return E_UNEXPECTED; diff --git a/core/base/render.h b/core/base/render.h index cb0ae486..6801a250 100644 --- a/core/base/render.h +++ b/core/base/render.h @@ -43,7 +43,7 @@ namespace easy2d int primitives; }; - using BitmapMap = std::unordered_map; + using BitmapMap = std::unordered_map; public: HRESULT Init(HWND hwnd, bool vsync, bool debug); @@ -78,25 +78,25 @@ namespace easy2d void DiscardResources(); HRESULT CreateLayer( - cpLayer& layer + CpLayer& layer ); HRESULT CreateSolidColorBrush( - cpSolidColorBrush& brush + CpSolidColorBrush& brush ) const; HRESULT CreateBitmapFromFile( - cpBitmap& bitmap, + CpBitmap& bitmap, std::wstring const& file_path ); HRESULT CreateBitmapFromResource( - cpBitmap& bitmap, + CpBitmap& bitmap, Resource const& res ); HRESULT CreateBitmapRenderTarget( - cpBitmapRenderTarget& brt + CpBitmapRenderTarget& brt ); HRESULT SetTransform( @@ -116,27 +116,27 @@ namespace easy2d ); HRESULT DrawGeometry( - cpGeometry const& geometry, + CpGeometry const& geometry, const Color& stroke_color, float stroke_width, StrokeStyle stroke = StrokeStyle::Miter ); HRESULT FillGeometry( - cpGeometry const& geometry, + CpGeometry const& geometry, const Color& fill_color ); HRESULT DrawImage( - spImage const& image + SpImage const& image ); HRESULT DrawBitmap( - cpBitmap const& bitmap + CpBitmap const& bitmap ); HRESULT DrawTextLayout( - cpTextLayout const& text_layout + CpTextLayout const& text_layout ); HRESULT PushClip( @@ -147,7 +147,7 @@ namespace easy2d HRESULT PopClip(); HRESULT PushLayer( - cpLayer const& layer, + CpLayer const& layer, LayerProperties const& properties ); @@ -164,9 +164,9 @@ namespace easy2d void ClearImageCache(); - cpHwndRenderTarget const& GetRenderTarget() const; + CpHwndRenderTarget const& GetRenderTarget() const; - cpSolidColorBrush const& GetSolidBrush() const; + CpSolidColorBrush const& GetSolidBrush() const; protected: GraphicsDevice(); @@ -182,11 +182,11 @@ namespace easy2d D2D1_COLOR_F clear_color_; TextAntialias text_antialias_; Status status_; - cpTextRenderer text_renderer_; - cpSolidColorBrush solid_brush_; - cpHwndRenderTarget render_target_; - cpTextFormat fps_text_format_; - cpTextLayout fps_text_layout_; + CpTextRenderer text_renderer_; + CpSolidColorBrush solid_brush_; + CpHwndRenderTarget render_target_; + CpTextFormat fps_text_format_; + CpTextLayout fps_text_layout_; BitmapMap bitmap_cache_; }; diff --git a/core/base/time.cpp b/core/base/time.cpp index beb109a0..95460250 100644 --- a/core/base/time.cpp +++ b/core/base/time.cpp @@ -35,7 +35,7 @@ namespace easy2d { } - TimePoint::TimePoint(long long dur) + TimePoint::TimePoint(long dur) : dur(dur) { } @@ -124,7 +124,7 @@ namespace easy2d { } - Duration::Duration(long long milliseconds) + Duration::Duration(long milliseconds) : milliseconds_(milliseconds) { } @@ -257,42 +257,32 @@ namespace easy2d const Duration easy2d::time::Duration::operator*(unsigned long long val) const { - return Duration(static_cast(milliseconds_ * val)); - } - - const Duration easy2d::time::Duration::operator/(unsigned long long val) const - { - return Duration(static_cast(milliseconds_ / val)); + return Duration(static_cast(milliseconds_ * val)); } const Duration Duration::operator*(float val) const { - return Duration(static_cast(milliseconds_ * val)); + return Duration(static_cast(milliseconds_ * val)); } const Duration Duration::operator/(float val) const { - return Duration(static_cast(milliseconds_ / val)); + return Duration(static_cast(milliseconds_ / val)); } const Duration Duration::operator*(double val) const { - return Duration(static_cast(milliseconds_ * val)); + return Duration(static_cast(milliseconds_ * val)); } const Duration Duration::operator*(long double val) const { - return Duration(static_cast(milliseconds_ * val)); + return Duration(static_cast(milliseconds_ * val)); } const Duration Duration::operator/(double val) const { - return Duration(static_cast(milliseconds_ / val)); - } - - const Duration Duration::operator/(long double val) const - { - return Duration(static_cast(milliseconds_ / val)); + return Duration(static_cast(milliseconds_ / val)); } Duration & Duration::operator+=(const Duration &other) @@ -315,55 +305,31 @@ namespace easy2d Duration & Duration::operator/=(int val) { - milliseconds_ = static_cast(milliseconds_ / val); - return (*this); - } - - Duration & easy2d::time::Duration::operator*=(unsigned long long val) - { - milliseconds_ = static_cast(milliseconds_ * val); - return (*this); - } - - Duration & easy2d::time::Duration::operator/=(unsigned long long val) - { - milliseconds_ = static_cast(milliseconds_ * val); + milliseconds_ = static_cast(milliseconds_ / val); return (*this); } Duration & Duration::operator*=(float val) { - milliseconds_ = static_cast(milliseconds_ * val); + milliseconds_ = static_cast(milliseconds_ * val); return (*this); } Duration & Duration::operator/=(float val) { - milliseconds_ = static_cast(milliseconds_ / val); + milliseconds_ = static_cast(milliseconds_ / val); return (*this); } Duration & Duration::operator*=(double val) { - milliseconds_ = static_cast(milliseconds_ * val); - return (*this); - } - - Duration & Duration::operator*=(long double val) - { - milliseconds_ = static_cast(milliseconds_ * val); + milliseconds_ = static_cast(milliseconds_ * val); return (*this); } Duration & Duration::operator/=(double val) { - milliseconds_ = static_cast(milliseconds_ / val); - return (*this); - } - - Duration & Duration::operator/=(long double val) - { - milliseconds_ = static_cast(milliseconds_ / val); + milliseconds_ = static_cast(milliseconds_ / val); return (*this); } @@ -372,21 +338,11 @@ namespace easy2d return dur * val; } - const Duration easy2d::time::operator*(unsigned long long val, const Duration & dur) - { - return dur / val; - } - const Duration easy2d::time::operator/(int val, const Duration & dur) { return dur / val; } - const Duration easy2d::time::operator/(unsigned long long val, const Duration & dur) - { - return dur * val; - } - const Duration easy2d::time::operator*(float val, const Duration & dur) { return dur * val; @@ -412,11 +368,6 @@ namespace easy2d return dur * val; } - const Duration easy2d::time::operator/(long double val, const Duration & dur) - { - return dur / val; - } - std::wostream & easy2d::time::operator<<(std::wostream & out, const Duration & dur) { return out << dur.ToString(); @@ -449,7 +400,7 @@ namespace easy2d const long long whole = (count.QuadPart / freq.QuadPart) * 1000LL; const long long part = (count.QuadPart % freq.QuadPart) * 1000LL / freq.QuadPart; - return TimePoint{ whole + part }; + return TimePoint{ static_cast(whole + part) }; } Duration easy2d::time::ParseDuration(const std::wstring & str) diff --git a/core/base/time.h b/core/base/time.h index fa7b0584..15dab658 100644 --- a/core/base/time.h +++ b/core/base/time.h @@ -20,7 +20,6 @@ #pragma once #include "macros.h" -#include namespace easy2d { @@ -45,11 +44,11 @@ namespace easy2d Duration(); explicit Duration( - long long milliseconds + long milliseconds ); // 转化为毫秒 - inline long long Milliseconds() const { return milliseconds_; } + inline long Milliseconds() const { return milliseconds_; } // 转化为秒 float Seconds() const; @@ -84,40 +83,31 @@ namespace easy2d const Duration operator * (double) const; const Duration operator * (long double) const; const Duration operator / (int) const; - const Duration operator / (unsigned long long) const; const Duration operator / (float) const; const Duration operator / (double) const; - const Duration operator / (long double) const; Duration& operator += (const Duration &); Duration& operator -= (const Duration &); Duration& operator *= (int); - Duration& operator *= (unsigned long long); Duration& operator *= (float); Duration& operator *= (double); - Duration& operator *= (long double); Duration& operator /= (int); - Duration& operator /= (unsigned long long); Duration& operator /= (float); Duration& operator /= (double); - Duration& operator /= (long double); friend const Duration operator* (int, const Duration &); - friend const Duration operator* (unsigned long long, const Duration &); friend const Duration operator* (float, const Duration &); friend const Duration operator* (double, const Duration &); friend const Duration operator* (long double, const Duration &); friend const Duration operator/ (int, const Duration &); - friend const Duration operator/ (unsigned long long, const Duration &); friend const Duration operator/ (float, const Duration &); friend const Duration operator/ (double, const Duration &); - friend const Duration operator/ (long double, const Duration &); friend std::wostream& operator<< (std::wostream &, const Duration &); friend std::wistream& operator>> (std::wistream &, Duration &); private: - long long milliseconds_; + long milliseconds_; }; extern const Duration Millisecond; // 毫秒 @@ -129,12 +119,12 @@ namespace easy2d // 时间 // // Usage: - // 获取当前时间: Time now = time::Now(); + // 获取当前时间: TimePoint now = time::Now(); // 时间操作: // 两时间相减, 得到一个 Duration 对象, 例如: - // Time t1 = time::Now(); + // TimePoint t1 = time::Now(); // ... // 做些什么 - // Time t2 = time::Now(); + // TimePoint t2 = time::Now(); // auto duration = t2 - t1; // 获取两时间相差的毫秒数: // int ms = duration.Milliseconds(); @@ -147,7 +137,7 @@ namespace easy2d TimePoint(); explicit TimePoint( - long long + long ); TimePoint( @@ -173,7 +163,7 @@ namespace easy2d TimePoint& operator = (TimePoint &&) E2D_NOEXCEPT; private: - long long dur; + long dur; }; // 获取当前时间 diff --git a/core/base/window.cpp b/core/base/window.cpp index 1b72aa34..ce494fec 100644 --- a/core/base/window.cpp +++ b/core/base/window.cpp @@ -55,7 +55,7 @@ namespace easy2d WNDCLASSEX wcex = { 0 }; wcex.cbSize = sizeof(WNDCLASSEX); wcex.lpszClassName = REGISTER_CLASS; - wcex.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS; + wcex.style = CS_HREDRAW | CS_VREDRAW /* | CS_DBLCLKS */; wcex.lpfnWndProc = proc; wcex.hIcon = nullptr; wcex.cbClsExtra = 0; diff --git a/core/ui/Menu.cpp b/core/ui/Menu.cpp index dabe52f6..fd1596c5 100644 --- a/core/ui/Menu.cpp +++ b/core/ui/Menu.cpp @@ -29,7 +29,7 @@ namespace easy2d { } - Menu::Menu(const std::vector& buttons) + Menu::Menu(const std::vector& buttons) : enabled_(true) { for (const auto& button : buttons) @@ -61,7 +61,7 @@ namespace easy2d } } - void Menu::AddButton(spButton const& button) + void Menu::AddButton(SpButton const& button) { if (button) { @@ -71,7 +71,7 @@ namespace easy2d } } - bool Menu::RemoveButton(spButton const& button) + bool Menu::RemoveButton(SpButton const& button) { if (buttons_.empty()) { @@ -94,7 +94,7 @@ namespace easy2d return false; } - const std::vector& Menu::GetAllButtons() const + const std::vector& Menu::GetAllButtons() const { return buttons_; } diff --git a/core/ui/Menu.h b/core/ui/Menu.h index edc097cf..8144ace4 100644 --- a/core/ui/Menu.h +++ b/core/ui/Menu.h @@ -33,7 +33,7 @@ namespace easy2d Menu(); explicit Menu( - const std::vector& buttons /* 按钮数组 */ + const std::vector& buttons /* 按钮数组 */ ); // 获取菜单是否禁用 @@ -49,20 +49,20 @@ namespace easy2d // 添加按钮 void AddButton( - spButton const& button + SpButton const& button ); // 移除按钮 bool RemoveButton( - spButton const& button + SpButton const& button ); // 获取所有按钮 - const std::vector& GetAllButtons() const; + const std::vector& GetAllButtons() const; private: bool enabled_; - std::vector buttons_; + std::vector buttons_; }; } } \ No newline at end of file diff --git a/core/utils/Player.cpp b/core/utils/Player.cpp index 9d749519..3743a6d5 100644 --- a/core/utils/Player.cpp +++ b/core/utils/Player.cpp @@ -38,7 +38,7 @@ namespace easy2d if (file_path.empty()) return false; - spMusic music = new (std::nothrow) Music(); + SpMusic music = new (std::nothrow) Music(); if (music) { @@ -117,7 +117,7 @@ namespace easy2d if (musics_cache_.end() != musics_cache_.find(hash_code)) return true; - spMusic music = new (std::nothrow) Music(); + SpMusic music = new (std::nothrow) Music(); if (music) { diff --git a/core/utils/Player.h b/core/utils/Player.h index f792d5a4..f218b255 100644 --- a/core/utils/Player.h +++ b/core/utils/Player.h @@ -29,7 +29,7 @@ namespace easy2d class Player : protected Noncopyable { - using MusicMap = std::unordered_map; + using MusicMap = std::unordered_map; public: Player(); diff --git a/core/utils/Transcoder.cpp b/core/utils/Transcoder.cpp index a56f16f2..e3f54b9c 100644 --- a/core/utils/Transcoder.cpp +++ b/core/utils/Transcoder.cpp @@ -79,7 +79,7 @@ namespace easy2d ResourceData buffer; if (!res.Load(&buffer)) { return false; } - stream = SHCreateMemStream( + stream = modules::Shlwapi{}.SHCreateMemStream( static_cast(buffer.buffer), static_cast(buffer.buffer_size) );