From 3b5704ee222d154a987130fa94afbe6f2e8136b0 Mon Sep 17 00:00:00 2001 From: Nomango <569629550@qq.com> Date: Tue, 22 Jan 2019 21:58:01 +0800 Subject: [PATCH] add: ResLoader minor minor minor refactoring refactoring --- ResLoader.cpp | 45 ------- project/vs2013/Easy2D.vcxproj | 4 +- project/vs2013/Easy2D.vcxproj.filters | 8 +- project/vs2015/Easy2D.vcxproj | 4 +- project/vs2015/Easy2D.vcxproj.filters | 8 +- project/vs2017/Easy2D.vcxproj | 4 +- project/vs2017/Easy2D.vcxproj.filters | 8 +- src/core/Action.hpp | 8 +- src/core/ActionCombined.cpp | 26 ++-- src/core/ActionCombined.h | 32 ++--- src/core/ActionManager.cpp | 4 +- src/core/ActionManager.h | 4 +- src/core/ActionTween.cpp | 36 +++--- src/core/ActionTween.h | 58 ++++----- src/core/Animation.cpp | 10 +- src/core/Animation.h | 12 +- src/core/Canvas.cpp | 14 +-- src/core/Canvas.h | 28 ++--- src/core/DebugNode.h | 2 +- src/core/Delay.cpp | 4 +- src/core/Delay.h | 4 +- src/core/EventDispatcher.cpp | 10 +- src/core/EventDispatcher.h | 4 +- src/core/EventListener.h | 4 +- src/core/Factory.cpp | 74 ++++++------ src/core/Factory.h | 48 ++++---- src/core/Frames.cpp | 29 ++--- src/core/Frames.h | 20 ++- src/core/Game.cpp | 24 ++-- src/core/Game.h | 14 +-- src/core/Geometry.cpp | 12 +- src/core/Geometry.h | 6 +- src/core/GeometryNode.cpp | 4 +- src/core/GeometryNode.h | 8 +- src/core/Image.cpp | 22 ++-- src/core/Image.h | 8 +- src/core/Input.cpp | 4 +- src/core/Music.cpp | 19 ++- src/core/Node.cpp | 26 ++-- src/core/Node.h | 16 +-- src/core/Resource.cpp | 20 +-- src/core/Resource.h | 18 +-- src/core/Scene.cpp | 4 +- src/core/Sprite.cpp | 6 +- src/core/Sprite.h | 8 +- src/core/Task.h | 4 +- src/core/TaskManager.cpp | 6 +- src/core/TaskManager.h | 4 +- src/core/Text.cpp | 2 +- src/core/Text.h | 6 +- src/core/TextRenderer.h | 2 +- src/core/Transition.cpp | 12 +- src/core/Transition.h | 32 ++--- src/core/audio.cpp | 10 +- src/core/d2dhelper.hpp | 46 +++---- src/core/helper.hpp | 13 +- .../{SmartPointer.hpp => SmartPtr.hpp} | 58 ++++----- src/core/keys.hpp | 2 +- src/core/logs.cpp | 52 ++++---- src/core/logs.h | 14 +-- src/core/modules.cpp | 12 +- src/core/modules.h | 32 ++++- src/core/render.cpp | 32 ++--- src/core/render.h | 38 +++--- src/core/time.cpp | 6 +- src/core/window.cpp | 6 +- src/easy2d.h | 3 +- src/math/rand.h | 2 +- src/ui/Menu.cpp | 8 +- src/ui/Menu.h | 10 +- src/utils/File.cpp | 54 +-------- src/utils/File.h | 11 +- src/utils/Player.cpp | 2 +- src/utils/Player.h | 2 +- src/utils/ResLoader.cpp | 114 ++++++++++++++++++ ResLoader.h => src/utils/ResLoader.h | 34 ++++-- src/utils/Transcoder.cpp | 32 ++--- src/utils/string.cpp | 4 +- 78 files changed, 723 insertions(+), 673 deletions(-) delete mode 100644 ResLoader.cpp rename src/core/intrusive/{SmartPointer.hpp => SmartPtr.hpp} (66%) create mode 100644 src/utils/ResLoader.cpp rename ResLoader.h => src/utils/ResLoader.h (61%) diff --git a/ResLoader.cpp b/ResLoader.cpp deleted file mode 100644 index 1e34b2f0..00000000 --- a/ResLoader.cpp +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) 2016-2018 Easy2D - Nomango -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -#include "ResLoader.h" - -namespace easy2d -{ - /*void ResLoader::Add(String const & id, SpImage const & image) - { - res_.insert(std::make_pair(id, image.Get())); - } - - void ResLoader::Add(String const & id, SpFrames const & frames) - { - res_.insert(std::make_pair(id, frames.Get())); - } - - SpImage easy2d::ResLoader::GetImage(String const & id) - { - return Get(id); - }*/ - - /*SpFrames easy2d::ResLoader::GetFrames(String const & id) - { - return Get(id); - }*/ - -} \ No newline at end of file diff --git a/project/vs2013/Easy2D.vcxproj b/project/vs2013/Easy2D.vcxproj index b6658356..b364d231 100644 --- a/project/vs2013/Easy2D.vcxproj +++ b/project/vs2013/Easy2D.vcxproj @@ -44,7 +44,7 @@ - + @@ -84,6 +84,7 @@ + @@ -129,6 +130,7 @@ + diff --git a/project/vs2013/Easy2D.vcxproj.filters b/project/vs2013/Easy2D.vcxproj.filters index bdc83e0e..a14c5e46 100644 --- a/project/vs2013/Easy2D.vcxproj.filters +++ b/project/vs2013/Easy2D.vcxproj.filters @@ -128,7 +128,7 @@ core\intrusive - + core\intrusive @@ -200,6 +200,9 @@ math + + utils + @@ -348,5 +351,8 @@ core + + utils + \ No newline at end of file diff --git a/project/vs2015/Easy2D.vcxproj b/project/vs2015/Easy2D.vcxproj index fa65406a..413b0d2e 100644 --- a/project/vs2015/Easy2D.vcxproj +++ b/project/vs2015/Easy2D.vcxproj @@ -44,7 +44,7 @@ - + @@ -84,6 +84,7 @@ + @@ -129,6 +130,7 @@ + diff --git a/project/vs2015/Easy2D.vcxproj.filters b/project/vs2015/Easy2D.vcxproj.filters index bdc83e0e..a14c5e46 100644 --- a/project/vs2015/Easy2D.vcxproj.filters +++ b/project/vs2015/Easy2D.vcxproj.filters @@ -128,7 +128,7 @@ core\intrusive - + core\intrusive @@ -200,6 +200,9 @@ math + + utils + @@ -348,5 +351,8 @@ core + + utils + \ No newline at end of file diff --git a/project/vs2017/Easy2D.vcxproj b/project/vs2017/Easy2D.vcxproj index cfd59a42..3a9bee02 100644 --- a/project/vs2017/Easy2D.vcxproj +++ b/project/vs2017/Easy2D.vcxproj @@ -44,7 +44,7 @@ - + @@ -84,6 +84,7 @@ + @@ -129,6 +130,7 @@ + diff --git a/project/vs2017/Easy2D.vcxproj.filters b/project/vs2017/Easy2D.vcxproj.filters index bdc83e0e..a14c5e46 100644 --- a/project/vs2017/Easy2D.vcxproj.filters +++ b/project/vs2017/Easy2D.vcxproj.filters @@ -128,7 +128,7 @@ core\intrusive - + core\intrusive @@ -200,6 +200,9 @@ math + + utils + @@ -348,5 +351,8 @@ core + + utils + \ No newline at end of file diff --git a/src/core/Action.hpp b/src/core/Action.hpp index 78e7707c..81080623 100644 --- a/src/core/Action.hpp +++ b/src/core/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 ActionPtr Clone() const = 0; // 获取动作的倒转 - virtual SpAction Reverse() const = 0; + virtual ActionPtr Reverse() const = 0; // 重置动作 virtual void Reset() diff --git a/src/core/ActionCombined.cpp b/src/core/ActionCombined.cpp index 833dd00b..8a3d201e 100644 --- a/src/core/ActionCombined.cpp +++ b/src/core/ActionCombined.cpp @@ -27,7 +27,7 @@ namespace easy2d // Loop //------------------------------------------------------- - Loop::Loop(SpAction const& action, int times) + Loop::Loop(ActionPtr const& action, int times) : action_(action) , times_(0) , total_times_(times) @@ -41,7 +41,7 @@ namespace easy2d { } - SpAction Loop::Clone() const + ActionPtr Loop::Clone() const { if (action_) { @@ -53,7 +53,7 @@ namespace easy2d } } - SpAction Loop::Reverse() const + ActionPtr Loop::Reverse() const { if (action_) { @@ -125,7 +125,7 @@ namespace easy2d { } - Sequence::Sequence(Array const& actions) + Sequence::Sequence(Array const& actions) : action_index_(0) { this->Add(actions); @@ -172,7 +172,7 @@ namespace easy2d action_index_ = 0; } - void Sequence::Add(SpAction const& action) + void Sequence::Add(ActionPtr const& action) { if (action) { @@ -180,7 +180,7 @@ namespace easy2d } } - void Sequence::Add(Array const& actions) + void Sequence::Add(Array const& actions) { for (const auto &action : actions) { @@ -188,7 +188,7 @@ namespace easy2d } } - SpAction Sequence::Clone() const + ActionPtr Sequence::Clone() const { auto sequence = new (std::nothrow) Sequence(); if (sequence) @@ -204,7 +204,7 @@ namespace easy2d return sequence; } - SpAction Sequence::Reverse() const + ActionPtr Sequence::Reverse() const { auto sequence = new (std::nothrow) Sequence(); if (sequence && !actions_.empty()) @@ -227,7 +227,7 @@ namespace easy2d { } - Spawn::Spawn(Array const& actions) + Spawn::Spawn(Array const& actions) { this->Add(actions); } @@ -281,7 +281,7 @@ namespace easy2d } } - void Spawn::Add(SpAction const& action) + void Spawn::Add(ActionPtr const& action) { if (action) { @@ -289,7 +289,7 @@ namespace easy2d } } - void Spawn::Add(Array const& actions) + void Spawn::Add(Array const& actions) { for (const auto &action : actions) { @@ -297,7 +297,7 @@ namespace easy2d } } - SpAction Spawn::Clone() const + ActionPtr Spawn::Clone() const { auto spawn = new (std::nothrow) Spawn(); if (spawn) @@ -313,7 +313,7 @@ namespace easy2d return spawn; } - SpAction Spawn::Reverse() const + ActionPtr Spawn::Reverse() const { auto spawn = new (std::nothrow) Spawn(); if (spawn && !actions_.empty()) diff --git a/src/core/ActionCombined.h b/src/core/ActionCombined.h index b1e29177..eb4a94a2 100644 --- a/src/core/ActionCombined.h +++ b/src/core/ActionCombined.h @@ -29,17 +29,17 @@ namespace easy2d { public: explicit Loop( - SpAction const& action, /* 执行循环的动作 */ + ActionPtr const& action, /* 执行循环的动作 */ int times = -1 /* 循环次数 */ ); virtual ~Loop(); // 获取该动作的拷贝对象 - virtual SpAction Clone() const override; + virtual ActionPtr Clone() const override; // 获取该动作的倒转 - virtual SpAction Reverse() const override; + virtual ActionPtr 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_; + ActionPtr action_; int times_; int total_times_; }; @@ -68,26 +68,26 @@ namespace easy2d Sequence(); explicit Sequence( - Array const& actions /* 动作列表 */ + Array const& actions /* 动作列表 */ ); virtual ~Sequence(); // 在结尾添加动作 void Add( - SpAction const& action + ActionPtr const& action ); // 在结尾添加多个动作 void Add( - Array const& actions /* 动作列表 */ + Array const& actions /* 动作列表 */ ); // 获取该动作的拷贝对象 - virtual SpAction Clone() const override; + virtual ActionPtr Clone() const override; // 获取该动作的倒转 - virtual SpAction Reverse() const override; + virtual ActionPtr Reverse() const override; // 重置动作 virtual void Reset() override; @@ -101,7 +101,7 @@ namespace easy2d protected: UINT action_index_; - Array actions_; + Array actions_; }; @@ -113,26 +113,26 @@ namespace easy2d Spawn(); explicit Spawn( - Array const& actions /* 动作列表 */ + Array const& actions /* 动作列表 */ ); virtual ~Spawn(); // 在结尾添加动作 void Add( - SpAction const& action + ActionPtr const& action ); // 在结尾添加多个动作 void Add( - Array const& actions /* 动作列表 */ + Array const& actions /* 动作列表 */ ); // 获取该动作的拷贝对象 - virtual SpAction Clone() const override; + virtual ActionPtr Clone() const override; // 获取该动作的倒转 - virtual SpAction Reverse() const; + virtual ActionPtr Reverse() const; // 重置动作 virtual void Reset() override; @@ -145,6 +145,6 @@ namespace easy2d virtual void Update(Node* target, Duration const& dt) override; protected: - Array actions_; + Array actions_; }; } diff --git a/src/core/ActionManager.cpp b/src/core/ActionManager.cpp index 994127e6..d4a0fe60 100644 --- a/src/core/ActionManager.cpp +++ b/src/core/ActionManager.cpp @@ -28,7 +28,7 @@ namespace easy2d if (actions_.IsEmpty()) return; - SpAction next; + ActionPtr next; for (auto action = actions_.First(); action; action = next) { next = action->NextItem(); @@ -41,7 +41,7 @@ namespace easy2d } } - void ActionManager::AddAction(SpAction const& action) + void ActionManager::AddAction(ActionPtr const& action) { E2D_ASSERT(action && "AddAction failed, NULL pointer exception"); diff --git a/src/core/ActionManager.h b/src/core/ActionManager.h index b2b7f480..ea8ac98c 100644 --- a/src/core/ActionManager.h +++ b/src/core/ActionManager.h @@ -25,12 +25,12 @@ namespace easy2d { class ActionManager { - using Actions = intrusive::List; + using Actions = intrusive::List; public: // 执行动作 void AddAction( - SpAction const& action + ActionPtr const& action ); // 继续所有暂停动作 diff --git a/src/core/ActionTween.cpp b/src/core/ActionTween.cpp index d7049a9f..dd8ca3b6 100644 --- a/src/core/ActionTween.cpp +++ b/src/core/ActionTween.cpp @@ -235,12 +235,12 @@ namespace easy2d } } - SpAction MoveBy::Clone() const + ActionPtr MoveBy::Clone() const { return new (std::nothrow) MoveBy(duration_, delta_pos_, ease_type_); } - SpAction MoveBy::Reverse() const + ActionPtr 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 + ActionPtr MoveTo::Clone() const { return new (std::nothrow) MoveTo(duration_, end_pos_, ease_type_); } @@ -275,12 +275,12 @@ namespace easy2d { } - SpAction JumpBy::Clone() const + ActionPtr JumpBy::Clone() const { return new (std::nothrow) JumpBy(duration_, delta_pos_, height_, jumps_, ease_type_); } - SpAction JumpBy::Reverse() const + ActionPtr 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 + ActionPtr 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 + ActionPtr ScaleBy::Clone() const { return new (std::nothrow) ScaleBy(duration_, delta_x_, delta_y_, ease_type_); } - SpAction ScaleBy::Reverse() const + ActionPtr 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 + ActionPtr 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 + ActionPtr OpacityBy::Clone() const { return new (std::nothrow) OpacityBy(duration_, delta_val_, ease_type_); } - SpAction OpacityBy::Reverse() const + ActionPtr 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 + ActionPtr OpacityTo::Clone() const { return new (std::nothrow) OpacityTo(duration_, end_val_, ease_type_); } @@ -500,12 +500,12 @@ namespace easy2d } } - SpAction RotateBy::Clone() const + ActionPtr RotateBy::Clone() const { return new (std::nothrow) RotateBy(duration_, delta_val_, ease_type_); } - SpAction RotateBy::Reverse() const + ActionPtr 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 + ActionPtr 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, GeometryPtr 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 + ActionPtr PathAction::Clone() const { return new PathAction(duration_, geo_, rotating_, start_, end_, ease_type_); } - SpAction PathAction::Reverse() const + ActionPtr PathAction::Reverse() const { return new PathAction(duration_, geo_, rotating_, end_, start_, ease_type_); } diff --git a/src/core/ActionTween.h b/src/core/ActionTween.h index a7074fe0..4ee34629 100644 --- a/src/core/ActionTween.h +++ b/src/core/ActionTween.h @@ -128,10 +128,10 @@ namespace easy2d ); // 获取该动作的拷贝对象 - virtual SpAction Clone() const override; + virtual ActionPtr Clone() const override; // 获取该动作的倒转 - virtual SpAction Reverse() const override; + virtual ActionPtr Reverse() const override; protected: virtual void Init(Node* target) override; @@ -157,12 +157,12 @@ namespace easy2d ); // 获取该动作的拷贝对象 - virtual SpAction Clone() const override; + virtual ActionPtr Clone() const override; // 获取该动作的倒转 - virtual SpAction Reverse() const override + virtual ActionPtr Reverse() const override { - logs::Errorln("Reverse() not supported in MoveTo"); + logs::Errorln(L"Reverse() not supported in MoveTo"); return nullptr; } @@ -188,10 +188,10 @@ namespace easy2d ); // 获取该动作的拷贝对象 - virtual SpAction Clone() const override; + virtual ActionPtr Clone() const override; // 获取该动作的倒转 - virtual SpAction Reverse() const override; + virtual ActionPtr Reverse() const override; protected: virtual void Init(Node* target) override; @@ -221,12 +221,12 @@ namespace easy2d ); // 获取该动作的拷贝对象 - virtual SpAction Clone() const override; + virtual ActionPtr Clone() const override; // 获取该动作的倒转 - virtual SpAction Reverse() const override + virtual ActionPtr Reverse() const override { - logs::Errorln("Reverse() not supported in JumpTo"); + logs::Errorln(L"Reverse() not supported in JumpTo"); return nullptr; } @@ -257,10 +257,10 @@ namespace easy2d ); // 获取该动作的拷贝对象 - virtual SpAction Clone() const override; + virtual ActionPtr Clone() const override; // 获取该动作的倒转 - virtual SpAction Reverse() const override; + virtual ActionPtr Reverse() const override; protected: virtual void Init(Node* target) override; @@ -294,12 +294,12 @@ namespace easy2d ); // 获取该动作的拷贝对象 - virtual SpAction Clone() const override; + virtual ActionPtr Clone() const override; // 获取该动作的倒转 - virtual SpAction Reverse() const override + virtual ActionPtr Reverse() const override { - logs::Errorln("Reverse() not supported in ScaleTo"); + logs::Errorln(L"Reverse() not supported in ScaleTo"); return nullptr; } @@ -324,10 +324,10 @@ namespace easy2d ); // 获取该动作的拷贝对象 - virtual SpAction Clone() const override; + virtual ActionPtr Clone() const override; // 获取该动作的倒转 - virtual SpAction Reverse() const override; + virtual ActionPtr Reverse() const override; protected: virtual void Init(Node* target) override; @@ -352,12 +352,12 @@ namespace easy2d ); // 获取该动作的拷贝对象 - virtual SpAction Clone() const override; + virtual ActionPtr Clone() const override; // 获取该动作的倒转 - virtual SpAction Reverse() const override + virtual ActionPtr Reverse() const override { - logs::Errorln("Reverse() not supported in OpacityTo"); + logs::Errorln(L"Reverse() not supported in OpacityTo"); return nullptr; } @@ -407,10 +407,10 @@ namespace easy2d ); // 获取该动作的拷贝对象 - virtual SpAction Clone() const override; + virtual ActionPtr Clone() const override; // 获取该动作的倒转 - virtual SpAction Reverse() const override; + virtual ActionPtr Reverse() const override; protected: virtual void Init(Node* target) override; @@ -435,12 +435,12 @@ namespace easy2d ); // 获取该动作的拷贝对象 - virtual SpAction Clone() const override; + virtual ActionPtr Clone() const override; // 获取该动作的倒转 - virtual SpAction Reverse() const override + virtual ActionPtr Reverse() const override { - logs::Errorln("Reverse() not supported in RotateTo"); + logs::Errorln(L"Reverse() not supported in RotateTo"); return nullptr; } @@ -459,7 +459,7 @@ namespace easy2d public: explicit PathAction( Duration const& duration, /* 持续时长 */ - SpGeometry const& geo, /* 几何图形 */ + GeometryPtr 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 ActionPtr Clone() const override; // 获取该动作的倒转 - virtual SpAction Reverse() const override; + virtual ActionPtr 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_; + GeometryPtr geo_; }; } diff --git a/src/core/Animation.cpp b/src/core/Animation.cpp index 257ebc97..2223c633 100644 --- a/src/core/Animation.cpp +++ b/src/core/Animation.cpp @@ -31,7 +31,7 @@ namespace easy2d { } - Animation::Animation(SpFrames const& animation) + Animation::Animation(FramesPtr const& animation) : frame_index_(0) , frames_(nullptr) { @@ -42,12 +42,12 @@ namespace easy2d { } - SpFrames Animation::GetAnimation() const + FramesPtr Animation::GetAnimation() const { return frames_; } - void Animation::SetAnimation(SpFrames const& animation) + void Animation::SetAnimation(FramesPtr const& animation) { if (animation && animation != frames_) { @@ -106,7 +106,7 @@ namespace easy2d frame_index_ = 0; } - SpAction Animation::Clone() const + ActionPtr Animation::Clone() const { if (frames_) { @@ -115,7 +115,7 @@ namespace easy2d return nullptr; } - SpAction Animation::Reverse() const + ActionPtr Animation::Reverse() const { if (frames_) { diff --git a/src/core/Animation.h b/src/core/Animation.h index 2bfbd51c..a60afcfd 100644 --- a/src/core/Animation.h +++ b/src/core/Animation.h @@ -31,24 +31,24 @@ namespace easy2d Animation(); explicit Animation( - SpFrames const& animation + FramesPtr const& animation ); virtual ~Animation(); // 获取动画 - SpFrames GetAnimation() const; + FramesPtr GetAnimation() const; // 设置动画 void SetAnimation( - SpFrames const& animation + FramesPtr const& animation ); // 获取该动作的拷贝对象 - virtual SpAction Clone() const override; + virtual ActionPtr Clone() const override; // 获取该动作的倒转 - virtual SpAction Reverse() const override; + virtual ActionPtr Reverse() const override; // 重置动作 virtual void Reset() override; @@ -63,6 +63,6 @@ namespace easy2d protected: size_t frame_index_; Duration delta_; - SpFrames frames_; + FramesPtr frames_; }; } diff --git a/src/core/Canvas.cpp b/src/core/Canvas.cpp index 157c4738..af192cd0 100644 --- a/src/core/Canvas.cpp +++ b/src/core/Canvas.cpp @@ -247,7 +247,7 @@ namespace easy2d cache_expired_ = true; } - void Canvas::DrawImage(SpImage const & image, float opacity) + void Canvas::DrawImage(ImagePtr const & image, float opacity) { if (image && image->GetBitmap()) { @@ -267,7 +267,7 @@ namespace easy2d if (text.empty()) return; - CpTextFormat text_format; + D2DTextFormatPtr text_format; ThrowIfFailed( Factory::Instance()->CreateTextFormat( text_format, @@ -276,7 +276,7 @@ namespace easy2d ) ); - CpTextLayout text_layout; + D2DTextLayoutPtr text_layout; Size layout_size; ThrowIfFailed( Factory::Instance()->CreateTextLayout( @@ -293,7 +293,7 @@ namespace easy2d ); } - void Canvas::DrawGeometry(SpGeometry const & geo) + void Canvas::DrawGeometry(GeometryPtr const & geo) { if (geo && geo->geo_) { @@ -371,7 +371,7 @@ namespace easy2d cache_expired_ = true; } - void Canvas::FillGeometry(SpGeometry const & geo) + void Canvas::FillGeometry(GeometryPtr const & geo) { if (geo && geo->geo_) { @@ -493,14 +493,14 @@ namespace easy2d cache_expired_ = true; } - SpImage Canvas::ExportToImage() const + ImagePtr Canvas::ExportToImage() const { auto image = new Image(GetBitmap()); image->Crop(Rect(Point{}, this->GetSize())); return image; } - CpBitmap const& easy2d::Canvas::GetBitmap() const + D2DBitmapPtr const& easy2d::Canvas::GetBitmap() const { if (cache_expired_) { diff --git a/src/core/Canvas.h b/src/core/Canvas.h index ed75c80d..68735c41 100644 --- a/src/core/Canvas.h +++ b/src/core/Canvas.h @@ -85,7 +85,7 @@ namespace easy2d // 画图片 void DrawImage( - SpImage const& image, + ImagePtr const& image, float opacity = 1.f ); @@ -97,7 +97,7 @@ namespace easy2d // 画几何图形边框 void DrawGeometry( - SpGeometry const& geo + GeometryPtr const& geo ); // 填充圆形 @@ -127,7 +127,7 @@ namespace easy2d // 填充几何图形 void FillGeometry( - SpGeometry const& geo + GeometryPtr const& geo ); // 开始绘制路径 @@ -216,26 +216,26 @@ namespace easy2d ); // 导出为图片 - SpImage ExportToImage() const; + ImagePtr ExportToImage() const; virtual void OnRender() override; protected: - CpBitmap const& GetBitmap() const; + D2DBitmapPtr const& GetBitmap() const; protected: mutable bool cache_expired_; - mutable CpBitmap bitmap_cached_; + mutable D2DBitmapPtr 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_; + D2DPathGeometryPtr current_geometry_; + D2DGeometrySinkPtr current_sink_; + D2DStrokeStylePtr outline_join_style_; + D2DSolidColorBrushPtr fill_brush_; + D2DSolidColorBrushPtr stroke_brush_; + D2DSolidColorBrushPtr text_brush_; + D2DTextRendererPtr text_renderer_; + D2DBitmapRenderTargetPtr render_target_; }; } \ No newline at end of file diff --git a/src/core/DebugNode.h b/src/core/DebugNode.h index 9931e09d..7c419f65 100644 --- a/src/core/DebugNode.h +++ b/src/core/DebugNode.h @@ -44,7 +44,7 @@ namespace easy2d void OnUpdate(Duration const& dt) override; protected: - SpText debug_text_; + TextPtr debug_text_; Array frame_time_; Array texts_; }; diff --git a/src/core/Delay.cpp b/src/core/Delay.cpp index 00c57fc7..06393cc6 100644 --- a/src/core/Delay.cpp +++ b/src/core/Delay.cpp @@ -51,12 +51,12 @@ namespace easy2d } } - SpAction Delay::Clone() const + ActionPtr Delay::Clone() const { return new (std::nothrow) Delay(delay_); } - SpAction Delay::Reverse() const + ActionPtr Delay::Reverse() const { return new (std::nothrow) Delay(delay_); } diff --git a/src/core/Delay.h b/src/core/Delay.h index f0f88d25..8cb8ed7c 100644 --- a/src/core/Delay.h +++ b/src/core/Delay.h @@ -33,10 +33,10 @@ namespace easy2d ); // 获取该动作的拷贝对象 - virtual SpAction Clone() const override; + virtual ActionPtr Clone() const override; // 获取该动作的倒转 - virtual SpAction Reverse() const override; + virtual ActionPtr Reverse() const override; // 重置动作 virtual void Reset() override; diff --git a/src/core/EventDispatcher.cpp b/src/core/EventDispatcher.cpp index e2a36acc..a06e49e1 100644 --- a/src/core/EventDispatcher.cpp +++ b/src/core/EventDispatcher.cpp @@ -28,7 +28,7 @@ namespace easy2d if (listeners_.IsEmpty()) return; - SpEventListener next; + EventListenerPtr next; for (auto listener = listeners_.First(); listener; listener = next) { next = listener->NextItem(); @@ -40,7 +40,7 @@ namespace easy2d } } - void EventDispatcher::AddListener(SpEventListener const & listener) + void EventDispatcher::AddListener(EventListenerPtr const & listener) { E2D_ASSERT(listener && "AddListener failed, NULL pointer exception"); @@ -52,7 +52,7 @@ namespace easy2d void EventDispatcher::AddListener(EventType type, EventCallback callback, String const& name) { - SpEventListener listener = new EventListener(type, callback, name); + EventListenerPtr listener = new EventListener(type, callback, name); if (listener) { listeners_.PushBack(listener); @@ -83,7 +83,7 @@ namespace easy2d void EventDispatcher::RemoveListeners(String const & listener_name) { - SpEventListener next; + EventListenerPtr 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; + EventListenerPtr next; for (auto listener = listeners_.First(); listener; listener = next) { next = listener->NextItem(); diff --git a/src/core/EventDispatcher.h b/src/core/EventDispatcher.h index ee8befaa..ecf7615e 100644 --- a/src/core/EventDispatcher.h +++ b/src/core/EventDispatcher.h @@ -25,12 +25,12 @@ namespace easy2d { class EventDispatcher { - using Listeners = intrusive::List; + using Listeners = intrusive::List; public: // 添加监听器 void AddListener( - SpEventListener const& listener + EventListenerPtr const& listener ); // 添加监听器 diff --git a/src/core/EventListener.h b/src/core/EventListener.h index 94ecf7b9..c6bafcb6 100644 --- a/src/core/EventListener.h +++ b/src/core/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( diff --git a/src/core/Factory.cpp b/src/core/Factory.cpp index e8292eae..9953b011 100644 --- a/src/core/Factory.cpp +++ b/src/core/Factory.cpp @@ -31,16 +31,16 @@ namespace easy2d FactoryImpl::~FactoryImpl() { - E2D_LOG("Destroying device independent resources"); + E2D_LOG(L"Destroying device independent resources"); } HRESULT FactoryImpl::Init(bool debug) { - E2D_LOG("Creating device independent resources"); + E2D_LOG(L"Creating device independent resources"); D2D1_FACTORY_OPTIONS fact_options; fact_options.debugLevel = debug ? D2D1_DEBUG_LEVEL_INFORMATION : D2D1_DEBUG_LEVEL_NONE; - HRESULT hr = modules::DirectX().D2D1CreateFactory( + HRESULT hr = modules::DirectX::Get().D2D1CreateFactory( D2D1_FACTORY_TYPE_SINGLE_THREADED, __uuidof(ID2D1Factory), &fact_options, @@ -60,7 +60,7 @@ namespace easy2d if (SUCCEEDED(hr)) { - modules::DirectX().DWriteCreateFactory( + modules::DirectX::Get().DWriteCreateFactory( DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory), reinterpret_cast(&write_factory_) @@ -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(D2DHwndRenderTargetPtr & 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; + D2DHwndRenderTargetPtr 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 + D2DTextRendererPtr& text_renderer, + D2DRenderTargetPtr const& render_target, + D2DSolidColorBrushPtr const& brush ) { if (!factory_) return E_UNEXPECTED; - CpTextRenderer text_renderer_tmp; + D2DTextRendererPtr 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, String const & file_path) + HRESULT FactoryImpl::CreateBitmapFromFile(D2DBitmapPtr & bitmap, D2DRenderTargetPtr const & rt, String const & file_path) { if (imaging_factory_ == nullptr) { @@ -159,11 +159,11 @@ namespace easy2d using namespace intrusive; - SmartPointer decoder; - SmartPointer source; - SmartPointer stream; - SmartPointer converter; - SmartPointer bitmap_tmp; + SmartPtr decoder; + SmartPtr source; + SmartPtr stream; + SmartPtr converter; + SmartPtr bitmap_tmp; HRESULT hr = imaging_factory_->CreateDecoderFromFilename( file_path.c_str(), @@ -211,7 +211,7 @@ namespace easy2d return hr; } - HRESULT FactoryImpl::CreateBitmapFromResource(CpBitmap & bitmap, CpRenderTarget const & rt, Resource const & res) + HRESULT FactoryImpl::CreateBitmapFromResource(D2DBitmapPtr & bitmap, D2DRenderTargetPtr const & rt, Resource const & res) { if (imaging_factory_ == nullptr) { @@ -220,11 +220,11 @@ namespace easy2d using namespace intrusive; - SmartPointer decoder; - SmartPointer source; - SmartPointer stream; - SmartPointer converter; - SmartPointer bitmap_tmp; + SmartPtr decoder; + SmartPtr source; + SmartPtr stream; + SmartPtr converter; + SmartPtr bitmap_tmp; // 加载资源 LPVOID buffer; @@ -294,12 +294,12 @@ namespace easy2d return hr; } - HRESULT FactoryImpl::CreateRectangleGeometry(CpRectangleGeometry & geo, Rect const& rect) const + HRESULT FactoryImpl::CreateRectangleGeometry(D2DRectangleGeometryPtr & geo, Rect const& rect) const { if (!factory_) return E_UNEXPECTED; - CpRectangleGeometry rectangle; + D2DRectangleGeometryPtr rectangle; HRESULT hr = factory_->CreateRectangleGeometry( rect, &rectangle @@ -310,12 +310,12 @@ namespace easy2d return hr; } - HRESULT FactoryImpl::CreateRoundedRectangleGeometry(CpRoundedRectangleGeometry & geo, Rect const & rect, float radius_x, float radius_y) const + HRESULT FactoryImpl::CreateRoundedRectangleGeometry(D2DRoundedRectangleGeometryPtr & geo, Rect const & rect, float radius_x, float radius_y) const { if (!factory_) return E_UNEXPECTED; - CpRoundedRectangleGeometry rounded_rect; + D2DRoundedRectangleGeometryPtr rounded_rect; HRESULT hr = factory_->CreateRoundedRectangleGeometry( D2D1::RoundedRect( rect, @@ -330,12 +330,12 @@ namespace easy2d return hr; } - HRESULT FactoryImpl::CreateEllipseGeometry(CpEllipseGeometry & geo, Point const & center, float radius_x, float radius_y) const + HRESULT FactoryImpl::CreateEllipseGeometry(D2DEllipseGeometryPtr & geo, Point const & center, float radius_x, float radius_y) const { if (!factory_) return E_UNEXPECTED; - CpEllipseGeometry ellipse; + D2DEllipseGeometryPtr ellipse; HRESULT hr = factory_->CreateEllipseGeometry( D2D1::Ellipse( center, @@ -351,15 +351,15 @@ namespace easy2d } HRESULT FactoryImpl::CreateTransformedGeometry( - CpTransformedGeometry& transformed, + D2DTransformedGeometryPtr& transformed, Matrix const& matrix, - CpGeometry const& geo + D2DGeometryPtr const& geo ) const { if (!factory_) return E_UNEXPECTED; - CpTransformedGeometry transformed_tmp; + D2DTransformedGeometryPtr transformed_tmp; HRESULT hr = factory_->CreateTransformedGeometry( geo.Get(), matrix, @@ -373,7 +373,7 @@ namespace easy2d return hr; } - HRESULT FactoryImpl::CreatePathGeometry(CpPathGeometry & geometry) const + HRESULT FactoryImpl::CreatePathGeometry(D2DPathGeometryPtr & geometry) const { if (!factory_) return E_UNEXPECTED; @@ -381,12 +381,12 @@ namespace easy2d return factory_->CreatePathGeometry(&geometry); } - HRESULT FactoryImpl::CreateTextFormat(CpTextFormat & text_format, Font const & font, TextStyle const & text_style) const + HRESULT FactoryImpl::CreateTextFormat(D2DTextFormatPtr & text_format, Font const & font, TextStyle const & text_style) const { if (!write_factory_) return E_UNEXPECTED; - CpTextFormat text_format_tmp; + D2DTextFormatPtr text_format_tmp; HRESULT hr = write_factory_->CreateTextFormat( font.family.c_str(), nullptr, @@ -419,7 +419,7 @@ namespace easy2d return hr; } - HRESULT FactoryImpl::CreateTextLayout(CpTextLayout & text_layout, Size& layout_size, String const & text, CpTextFormat const& text_format, TextStyle const & text_style) const + HRESULT FactoryImpl::CreateTextLayout(D2DTextLayoutPtr & text_layout, Size& layout_size, String const & text, D2DTextFormatPtr const& text_format, TextStyle const & text_style) const { if (!write_factory_) return E_UNEXPECTED; @@ -427,7 +427,7 @@ namespace easy2d text_layout = nullptr; HRESULT hr; - CpTextLayout text_layout_tmp; + D2DTextLayoutPtr text_layout_tmp; UINT32 length = static_cast(text.length()); if (text_style.wrap) @@ -497,7 +497,7 @@ namespace easy2d return hr; } - CpStrokeStyle const& FactoryImpl::GetStrokeStyle(StrokeStyle stroke) const + D2DStrokeStylePtr const& FactoryImpl::GetStrokeStyle(StrokeStyle stroke) const { switch (stroke) { diff --git a/src/core/Factory.h b/src/core/Factory.h index c77de77b..922c3d4b 100644 --- a/src/core/Factory.h +++ b/src/core/Factory.h @@ -38,73 +38,73 @@ namespace easy2d HRESULT Init(bool debug); HRESULT CreateHwndRenderTarget( - CpHwndRenderTarget& hwnd_render_target, + D2DHwndRenderTargetPtr& 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 + D2DTextRendererPtr& text_renderer, + D2DRenderTargetPtr const& render_target, + D2DSolidColorBrushPtr const& brush ); HRESULT CreateBitmapFromFile( - CpBitmap& bitmap, - CpRenderTarget const& rt, + D2DBitmapPtr& bitmap, + D2DRenderTargetPtr const& rt, String const& file_path ); HRESULT CreateBitmapFromResource( - CpBitmap& bitmap, - CpRenderTarget const& rt, + D2DBitmapPtr& bitmap, + D2DRenderTargetPtr const& rt, Resource const& res ); HRESULT CreateRectangleGeometry( - CpRectangleGeometry& geo, + D2DRectangleGeometryPtr& geo, Rect const& rect ) const; HRESULT CreateRoundedRectangleGeometry( - CpRoundedRectangleGeometry& geo, + D2DRoundedRectangleGeometryPtr& geo, Rect const& rect, float radius_x, float radius_y ) const; HRESULT CreateEllipseGeometry( - CpEllipseGeometry& geo, + D2DEllipseGeometryPtr& geo, Point const& center, float radius_x, float radius_y ) const; HRESULT CreateTransformedGeometry( - CpTransformedGeometry& transformed, + D2DTransformedGeometryPtr& transformed, Matrix const& matrix, - CpGeometry const& geo + D2DGeometryPtr const& geo ) const; HRESULT CreatePathGeometry( - CpPathGeometry& geometry + D2DPathGeometryPtr& geometry ) const; HRESULT CreateTextFormat( - CpTextFormat& text_format, + D2DTextFormatPtr& text_format, Font const& font, TextStyle const& text_style ) const; HRESULT CreateTextLayout( - CpTextLayout& text_layout, + D2DTextLayoutPtr& text_layout, Size& layout_size, String const& text, - CpTextFormat const& text_format, + D2DTextFormatPtr const& text_format, TextStyle const& text_style ) const; - CpStrokeStyle const& GetStrokeStyle( + D2DStrokeStylePtr 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_; + D2DFactoryPtr factory_; + D2DImagingFactoryPtr imaging_factory_; + D2DWriteFactoryPtr write_factory_; + D2DStrokeStylePtr miter_stroke_style_; + D2DStrokeStylePtr bevel_stroke_style_; + D2DStrokeStylePtr round_stroke_style_; }; E2D_DECLARE_SINGLETON_TYPE(FactoryImpl, Factory); diff --git a/src/core/Frames.cpp b/src/core/Frames.cpp index 3d0d2f93..c57e0ed2 100644 --- a/src/core/Frames.cpp +++ b/src/core/Frames.cpp @@ -25,22 +25,17 @@ namespace easy2d { Frames::Frames() - : interval_(1) + : interval_(200) { } - Frames::Frames(Array const& frames) - : interval_(1) + Frames::Frames(Array const& frames) + : interval_(200) { this->Add(frames); } - Frames::Frames(Duration const& interval) - : interval_(interval) - { - } - - Frames::Frames(Duration const& interval, Array const& frames) + Frames::Frames(Duration const& interval, Array const& frames) : interval_(interval) { this->Add(frames); @@ -55,7 +50,7 @@ namespace easy2d interval_ = interval; } - void Frames::Add(SpImage const& frame) + void Frames::Add(ImagePtr const& frame) { E2D_ASSERT(frame && "Frames::Add failed, NULL pointer exception"); @@ -65,7 +60,7 @@ namespace easy2d } } - void Frames::Add(Array const& frames) + void Frames::Add(Array const& frames) { for (const auto &image : frames) { @@ -78,16 +73,17 @@ namespace easy2d return interval_; } - Array const& Frames::GetFrames() const + Array const& Frames::GetFrames() const { return frames_; } - SpFrames Frames::Clone() const + FramesPtr Frames::Clone() const { - auto animation = new (std::nothrow) Frames(interval_); + auto animation = new (std::nothrow) Frames; if (animation) { + animation->SetInterval(interval_); for (const auto& frame : frames_) { animation->Add(frame); @@ -96,11 +92,12 @@ namespace easy2d return animation; } - SpFrames Frames::Reverse() const + FramesPtr Frames::Reverse() const { - auto animation = new (std::nothrow) Frames(interval_); + auto animation = new (std::nothrow) Frames; if (!frames_.empty()) { + animation->SetInterval(interval_); for (auto iter = frames_.crbegin(), crend = frames_.crend(); iter != crend; ++iter) { if (*iter) diff --git a/src/core/Frames.h b/src/core/Frames.h index 446be900..128a4faa 100644 --- a/src/core/Frames.h +++ b/src/core/Frames.h @@ -32,35 +32,31 @@ namespace easy2d Frames(); explicit Frames( - Array const& frames /* 关键帧数组 */ - ); - - explicit Frames( - Duration const& interval /* 帧间隔 */ + Array const& frames /* 关键帧数组 */ ); explicit Frames( Duration const& interval, /* 帧间隔 */ - Array const& frames /* 关键帧数组 */ + Array const& frames /* 关键帧数组 */ ); virtual ~Frames(); // 添加关键帧 void Add( - SpImage const& frame + ImagePtr const& frame ); // 添加多个关键帧 void Add( - Array const& frames + Array const& frames ); // 获取帧间隔 Duration const& GetInterval() const; // 获取关键帧 - Array const& GetFrames() const; + Array const& GetFrames() const; // 设置每一帧的时间间隔 void SetInterval( @@ -68,13 +64,13 @@ namespace easy2d ); // 获取帧动画的拷贝对象 - SpFrames Clone() const; + FramesPtr Clone() const; // 获取帧动画的倒转 - SpFrames Reverse() const; + FramesPtr Reverse() const; protected: Duration interval_; - Array frames_; + Array frames_; }; } diff --git a/src/core/Game.cpp b/src/core/Game.cpp index eff1bad6..51e4a0b9 100644 --- a/src/core/Game.cpp +++ b/src/core/Game.cpp @@ -153,7 +153,7 @@ namespace easy2d Window::Instance()->Destroy(); } - void Game::EnterScene(SpScene const & scene) + void Game::EnterScene(ScenePtr const & scene) { E2D_ASSERT(scene && "Game::EnterScene failed, NULL pointer exception"); @@ -163,7 +163,7 @@ namespace easy2d next_scene_ = scene; } - void Game::EnterScene(SpScene const& scene, SpTransition const& transition) + void Game::EnterScene(ScenePtr const& scene, TransitionPtr const& transition) { EnterScene(scene); @@ -178,7 +178,7 @@ namespace easy2d } } - SpScene const& Game::GetCurrentScene() + ScenePtr const& Game::GetCurrentScene() { return curr_scene_; } @@ -337,7 +337,7 @@ namespace easy2d case WM_DISPLAYCHANGE: { - E2D_LOG("The display resolution has changed"); + E2D_LOG(L"The display resolution has changed"); ::InvalidateRect(hwnd, nullptr, FALSE); } @@ -345,7 +345,7 @@ namespace easy2d case WM_CLOSE: { - E2D_LOG("Received a message to close the window"); + E2D_LOG(L"Received a message to close the window"); SysEvent event(SysEvent::WindowClose); game->Dispatch(&event); @@ -360,7 +360,7 @@ namespace easy2d case WM_DESTROY: { - E2D_LOG("Window was destroyed"); + E2D_LOG(L"Window was destroyed"); game->OnExit(); ::PostQuitMessage(0); @@ -374,14 +374,14 @@ namespace easy2d { game->active_ = false; - E2D_LOG("Window minimized"); + E2D_LOG(L"Window minimized"); } else if (SIZE_RESTORED == wparam) { game->active_ = true; ::InvalidateRect(hwnd, nullptr, FALSE); - E2D_LOG("Window restored"); + E2D_LOG(L"Window restored"); } UINT width = LOWORD(lparam); @@ -399,14 +399,14 @@ namespace easy2d bool active = (LOWORD(wparam) != WA_INACTIVE); if (active) { - E2D_LOG("Window activated"); + E2D_LOG(L"Window activated"); SysEvent event(SysEvent::WindowActivate); game->Dispatch(&event); } else { - E2D_LOG("Window deactivated"); + E2D_LOG(L"Window deactivated"); SysEvent event(SysEvent::WindowDeavtivate); game->Dispatch(&event); @@ -416,13 +416,13 @@ namespace easy2d case WM_SETTEXT: { - E2D_LOG("Window title changed"); + E2D_LOG(L"Window title changed"); } break; case WM_SETICON: { - E2D_LOG("Window icon changed"); + E2D_LOG(L"Window icon changed"); } break; } diff --git a/src/core/Game.h b/src/core/Game.h index cd72e6cc..c84187d1 100644 --- a/src/core/Game.h +++ b/src/core/Game.h @@ -80,17 +80,17 @@ namespace easy2d // 切换场景 void EnterScene( - SpScene const& scene /* 场景 */ + ScenePtr const& scene /* 场景 */ ); // 切换场景 void EnterScene( - SpScene const& scene, /* 场景 */ - SpTransition const& transition /* 场景动画 */ + ScenePtr const& scene, /* 场景 */ + TransitionPtr const& transition /* 场景动画 */ ); // 获取当前场景 - SpScene const& GetCurrentScene(); + ScenePtr const& GetCurrentScene(); // 设置变速 void SetTimeScale(float scale); @@ -110,8 +110,8 @@ namespace easy2d bool debug_; bool active_; float time_scale_; - SpScene curr_scene_; - SpScene next_scene_; - SpTransition transition_; + ScenePtr curr_scene_; + ScenePtr next_scene_; + TransitionPtr transition_; }; } diff --git a/src/core/Geometry.cpp b/src/core/Geometry.cpp index 0e05a878..f69ca497 100644 --- a/src/core/Geometry.cpp +++ b/src/core/Geometry.cpp @@ -126,8 +126,8 @@ namespace easy2d void LineGeometry::SetLine(Point const & begin, Point const & end) { - CpPathGeometry path_geo; - CpGeometrySink path_sink; + D2DPathGeometryPtr path_geo; + D2DGeometrySinkPtr path_sink; HRESULT hr = Factory::Instance()->CreatePathGeometry(path_geo); @@ -185,7 +185,7 @@ namespace easy2d void RectangleGeometry::SetRect(Rect const & rect) { - CpRectangleGeometry geo; + D2DRectangleGeometryPtr 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; + D2DEllipseGeometryPtr 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; + D2DEllipseGeometryPtr 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; + D2DRoundedRectangleGeometryPtr geo; if (SUCCEEDED(Factory::Instance()->CreateRoundedRectangleGeometry(geo, rect, radius_x, radius_y))) { geo_ = geo; diff --git a/src/core/Geometry.h b/src/core/Geometry.h index 589f2ab9..a37e89c4 100644 --- a/src/core/Geometry.h +++ b/src/core/Geometry.h @@ -57,7 +57,7 @@ namespace easy2d float ComputeArea(); protected: - CpGeometry geo_; + D2DGeometryPtr geo_; }; @@ -254,8 +254,8 @@ namespace easy2d void ClearPath(); protected: - CpPathGeometry current_geometry_; - CpGeometrySink current_sink_; + D2DPathGeometryPtr current_geometry_; + D2DGeometrySinkPtr current_sink_; }; diff --git a/src/core/GeometryNode.cpp b/src/core/GeometryNode.cpp index 2528a347..9d77fc35 100644 --- a/src/core/GeometryNode.cpp +++ b/src/core/GeometryNode.cpp @@ -31,7 +31,7 @@ namespace easy2d { } - GeometryNode::GeometryNode(SpGeometry const& geometry) + GeometryNode::GeometryNode(GeometryPtr const& geometry) : GeometryNode() { SetGeometry(geometry); @@ -41,7 +41,7 @@ namespace easy2d { } - void GeometryNode::SetGeometry(SpGeometry const& geometry) + void GeometryNode::SetGeometry(GeometryPtr const& geometry) { geometry_ = geometry; } diff --git a/src/core/GeometryNode.h b/src/core/GeometryNode.h index 583375ac..557c6c6a 100644 --- a/src/core/GeometryNode.h +++ b/src/core/GeometryNode.h @@ -32,14 +32,14 @@ namespace easy2d GeometryNode(); GeometryNode( - SpGeometry const& geometry + GeometryPtr const& geometry ); virtual ~GeometryNode(); // 设置形状 void SetGeometry( - SpGeometry const& geometry + GeometryPtr const& geometry ); // 设置填充颜色 @@ -63,7 +63,7 @@ namespace easy2d ); // 获取形状 - SpGeometry const& GetGeometry() const { return geometry_; } + GeometryPtr 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_; + GeometryPtr geometry_; }; } diff --git a/src/core/Image.cpp b/src/core/Image.cpp index 5d197bb3..42441a18 100644 --- a/src/core/Image.cpp +++ b/src/core/Image.cpp @@ -45,7 +45,7 @@ namespace easy2d this->Crop(crop_rect); } - Image::Image(CpBitmap const & bitmap) + Image::Image(D2DBitmapPtr const & bitmap) : Image() { SetBitmap(bitmap); @@ -58,22 +58,16 @@ namespace easy2d bool Image::Load(Resource const& res) { HRESULT hr = S_OK; - CpBitmap bitmap; + D2DBitmapPtr bitmap; if (res.IsFile()) { - File image_file; - if (!image_file.Open(res.GetFileName())) + if (!File(res.GetFileName()).Exists()) { - logs::Warningln("Image file '%s' not found!", StringWideCharToMultiByte(res.GetFileName()).c_str()); + logs::Warningln(L"Image file '%s' not found!", res.GetFileName()); return false; } - - // 用户输入的路径不一定是完整路径,因为用户可能通过 File::AddSearchPath 添加 - // 默认搜索路径,所以需要通过 File::GetPath 获取完整路径 - String image_file_path = image_file.GetPath(); - - hr = Graphics::Instance()->CreateBitmapFromFile(bitmap, image_file_path); + hr = Graphics::Instance()->CreateBitmapFromFile(bitmap, res.GetFileName()); } else { @@ -82,7 +76,7 @@ namespace easy2d if (FAILED(hr)) { - logs::Errorln(hr, "Load image file failed!"); + logs::Errorln(hr, L"Load image file failed!"); return false; } @@ -165,12 +159,12 @@ namespace easy2d return crop_rect_; } - CpBitmap const& Image::GetBitmap() const + D2DBitmapPtr const& Image::GetBitmap() const { return bitmap_; } - void Image::SetBitmap(CpBitmap const & bitmap) + void Image::SetBitmap(D2DBitmapPtr const & bitmap) { if (bitmap) { diff --git a/src/core/Image.h b/src/core/Image.h index 38a515bf..cc97592c 100644 --- a/src/core/Image.h +++ b/src/core/Image.h @@ -41,7 +41,7 @@ namespace easy2d ); explicit Image( - CpBitmap const& bitmap + D2DBitmapPtr const& bitmap ); virtual ~Image(); @@ -86,15 +86,15 @@ namespace easy2d // 获取裁剪矩形 Rect const& GetCropRect() const; - CpBitmap const& GetBitmap() const; + D2DBitmapPtr const& GetBitmap() const; protected: void SetBitmap( - CpBitmap const& bitmap + D2DBitmapPtr const& bitmap ); protected: Rect crop_rect_; - CpBitmap bitmap_; + D2DBitmapPtr bitmap_; }; } diff --git a/src/core/Input.cpp b/src/core/Input.cpp index d6737900..7d5de0a8 100644 --- a/src/core/Input.cpp +++ b/src/core/Input.cpp @@ -35,12 +35,12 @@ namespace easy2d InputDevice::~InputDevice() { - E2D_LOG("Destroying input device"); + E2D_LOG(L"Destroying input device"); } HRESULT InputDevice::Init(HWND hwnd, float scale_x, float scale_y, bool debug) { - E2D_LOG("Initing input device"); + E2D_LOG(L"Initing input device"); hwnd_ = hwnd; scale_x_ = scale_x; diff --git a/src/core/Music.cpp b/src/core/Music.cpp index b0cb8361..c5ab23e1 100644 --- a/src/core/Music.cpp +++ b/src/core/Music.cpp @@ -60,17 +60,12 @@ namespace easy2d if (res.IsFile()) { - File music_file; - if (!music_file.Open(res.GetFileName())) + if (!File(res.GetFileName()).Exists()) { - logs::Warningln("Media file '%s' not found", StringWideCharToMultiByte(res.GetFileName()).c_str()); + logs::Warningln(L"Media file '%s' not found", res.GetFileName()); return false; } - - // 用户输入的路径不一定是完整路径,因为用户可能通过 File::AddSearchPath 添加 - // 默认搜索路径,所以需要通过 File::GetPath 获取完整路径 - String music_file_path = music_file.GetPath(); - HRESULT hr = transcoder.LoadMediaFile(music_file_path.c_str(), &wave_data_, &size_); + hr = transcoder.LoadMediaFile(res.GetFileName(), &wave_data_, &size_); } else { @@ -79,7 +74,7 @@ namespace easy2d if (FAILED(hr)) { - logs::Errorln(hr, "Load media file failed"); + logs::Errorln(hr, L"Load media file failed"); return false; } @@ -91,7 +86,7 @@ namespace easy2d delete[] wave_data_; wave_data_ = nullptr; } - logs::Errorln(hr, "Create source voice error"); + logs::Errorln(hr, L"Create source voice error"); return false; } @@ -103,7 +98,7 @@ namespace easy2d { if (!opened_) { - logs::Errorln("Music must be opened first!"); + logs::Errorln(L"Music must be opened first!"); return false; } @@ -120,7 +115,7 @@ namespace easy2d HRESULT hr = voice_.Play(wave_data_, size_, static_cast(loop_count)); if (FAILED(hr)) { - logs::Errorln(hr, "Submitting source buffer error"); + logs::Errorln(hr, L"Submitting source buffer error"); } playing_ = SUCCEEDED(hr); diff --git a/src/core/Node.cpp b/src/core/Node.cpp index a2d49279..3d2f5d18 100644 --- a/src/core/Node.cpp +++ b/src/core/Node.cpp @@ -62,7 +62,7 @@ namespace easy2d if (!children_.IsEmpty()) { - SpNode next; + NodePtr next; for (auto child = children_.First(); child; child = next) { next = child->NextItem(); @@ -118,7 +118,7 @@ namespace easy2d if (!visible_) return; - SpNode prev; + NodePtr prev; for (auto child = children_.Last(); child; child = prev) { prev = child->PrevItem(); @@ -255,7 +255,7 @@ namespace easy2d if (parent_) { - SpNode me = this; + NodePtr me = this; parent_->children_.Remove(me); @@ -272,7 +272,7 @@ namespace easy2d if (sibling) { - parent_->children_.InsertAfter(me, SpNode(sibling)); + parent_->children_.InsertAfter(me, NodePtr(sibling)); } else { @@ -444,7 +444,7 @@ namespace easy2d dirty_transform_ = true; } - void Node::AddChild(SpNode const& child) + void Node::AddChild(NodePtr const& child) { E2D_ASSERT(child && "Node::AddChild failed, NULL pointer exception"); @@ -453,11 +453,11 @@ namespace easy2d #ifdef E2D_DEBUG if (child->parent_) - logs::Errorln("The node to be added already has a parent"); + logs::Errorln(L"The node to be added already has a parent"); for (Node* parent = parent_; parent; parent = parent->parent_) if (parent == child) - logs::Errorln("A node cannot be its own parent"); + logs::Errorln(L"A node cannot be its own parent"); #endif // E2D_DEBUG @@ -470,7 +470,7 @@ namespace easy2d } } - void Node::AddChildren(Array const& children) + void Node::AddChildren(Array const& children) { for (const auto& node : children) { @@ -483,9 +483,9 @@ namespace easy2d return Rect(Point{}, size_); } - Array Node::GetChildren(String const& name) const + Array Node::GetChildren(String const& name) const { - Array children; + Array children; size_t hash_code = std::hash{}(name); for (Node* child = children_.First().Get(); child; child = child->NextItem().Get()) @@ -498,7 +498,7 @@ namespace easy2d return children; } - SpNode Node::GetChild(String const& name) const + NodePtr Node::GetChild(String 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(NodePtr 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(NodePtr(child)); return true; } return false; diff --git a/src/core/Node.h b/src/core/Node.h index 355c36a1..e29270f9 100644 --- a/src/core/Node.h +++ b/src/core/Node.h @@ -37,14 +37,14 @@ 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 Children = intrusive::List; + using Children = intrusive::List; public: Node(); @@ -291,21 +291,21 @@ namespace easy2d // 添加子节点 void AddChild( - SpNode const& child + NodePtr const& child ); // 添加多个子节点 void AddChildren( - Array const& children + Array const& children ); // 获取所有名称相同的子节点 - Array GetChildren( + Array GetChildren( String const& name ) const; // 获取名称相同的子节点 - SpNode GetChild( + NodePtr GetChild( String const& name ) const; @@ -314,7 +314,7 @@ namespace easy2d // 移除子节点 bool RemoveChild( - SpNode const& child + NodePtr const& child ); // 移除子节点 diff --git a/src/core/Resource.cpp b/src/core/Resource.cpp index 0e1cd56b..87d5d57e 100644 --- a/src/core/Resource.cpp +++ b/src/core/Resource.cpp @@ -23,12 +23,6 @@ namespace easy2d { - Resource::Resource(String const& file_name) - : type_(Type::File) - , file_name_(file_name) - { - } - Resource::Resource(LPCWSTR file_name) : type_(Type::File) , file_name_(file_name) @@ -42,14 +36,10 @@ namespace easy2d { } - Resource::~Resource() - { - } - size_t Resource::GetHashCode() const { if (type_ == Type::File) - return std::hash{}(file_name_); + return std::hash{}(file_name_); return std::hash{}(bin_name_); } @@ -64,28 +54,28 @@ namespace easy2d res_info = FindResourceW(nullptr, bin_name_, bin_type_); if (res_info == nullptr) { - logs::Errorln("FindResource"); + logs::Errorln(L"FindResource"); return false; } res_data = LoadResource(nullptr, res_info); if (res_data == nullptr) { - logs::Errorln("LoadResource"); + logs::Errorln(L"LoadResource"); return false; } buffer_size = SizeofResource(nullptr, res_info); if (buffer_size == 0) { - logs::Errorln("SizeofResource"); + logs::Errorln(L"SizeofResource"); return false; } buffer = LockResource(res_data); if (buffer == nullptr) { - logs::Errorln("LockResource"); + logs::Errorln(L"LockResource"); return false; } return true; diff --git a/src/core/Resource.h b/src/core/Resource.h index 8c8470e3..cb1f70e1 100644 --- a/src/core/Resource.h +++ b/src/core/Resource.h @@ -26,7 +26,7 @@ namespace easy2d { // 资源 // - // 资源可以是文件类型,也可以是保存在 exe 中的二进制文件 + // 资源可以是文件类型,也可以是保存在 exe 中的二进制资源 // 例如, 一份音频资源的类型为 L"WAVE", 名称标识符为 IDR_WAVE_1, // 那么可以这样指定该资源: Resource res(MAKEINTRESOURCE(IDR_WAVE_1), L"WAVE"); // @@ -38,25 +38,19 @@ namespace easy2d enum class Type { File, Binary }; Resource( - String const& file_name /* 文件路径 */ + LPCWSTR file_name /* 文件路径 */ ); Resource( - LPCWSTR file_name /* 文件路径 */ + LPCWSTR name, /* 资源名称 */ + LPCWSTR type /* 资源类型 */ ); - Resource( - LPCWSTR name, /* 资源名称 */ - LPCWSTR type /* 资源类型 */ - ); - - virtual ~Resource(); - inline bool IsFile() const { return type_ == Type::File; } inline Type GetType() const { return type_; } - inline String const& GetFileName() const { return file_name_; } + inline LPCWSTR GetFileName() const { return file_name_; } bool Load( LPVOID& buffer, @@ -71,7 +65,7 @@ namespace easy2d { struct { - String file_name_; + LPCWSTR file_name_; }; struct diff --git a/src/core/Scene.cpp b/src/core/Scene.cpp index d10a6610..b6e28d34 100644 --- a/src/core/Scene.cpp +++ b/src/core/Scene.cpp @@ -38,12 +38,12 @@ namespace easy2d void Scene::OnEnter() { - E2D_LOG("Scene entered"); + E2D_LOG(L"Scene entered"); } void Scene::OnExit() { - E2D_LOG("Scene exited"); + E2D_LOG(L"Scene exited"); } void Scene::OnDeactivate() diff --git a/src/core/Sprite.cpp b/src/core/Sprite.cpp index 425defdf..7e942e8c 100644 --- a/src/core/Sprite.cpp +++ b/src/core/Sprite.cpp @@ -28,7 +28,7 @@ namespace easy2d { } - Sprite::Sprite(SpImage const& image) + Sprite::Sprite(ImagePtr const& image) : image_(nullptr) { Load(image); @@ -51,7 +51,7 @@ namespace easy2d { } - bool Sprite::Load(SpImage const& image) + bool Sprite::Load(ImagePtr const& image) { if (image) { @@ -90,7 +90,7 @@ namespace easy2d ); } - SpImage const& Sprite::GetImage() const + ImagePtr const& Sprite::GetImage() const { return image_; } diff --git a/src/core/Sprite.h b/src/core/Sprite.h index 45dc2a14..e8f60dd0 100644 --- a/src/core/Sprite.h +++ b/src/core/Sprite.h @@ -32,7 +32,7 @@ namespace easy2d Sprite(); explicit Sprite( - SpImage const& image + ImagePtr const& image ); explicit Sprite( @@ -53,7 +53,7 @@ namespace easy2d // 加载图片 bool Load( - SpImage const& image + ImagePtr const& image ); // 将图片裁剪为矩形 @@ -62,12 +62,12 @@ namespace easy2d ); // 获取 Image 对象 - SpImage const& GetImage() const; + ImagePtr const& GetImage() const; // 渲染精灵 virtual void OnRender() override; protected: - SpImage image_; + ImagePtr image_; }; } diff --git a/src/core/Task.h b/src/core/Task.h index f3a55c9d..3bc8319e 100644 --- a/src/core/Task.h +++ b/src/core/Task.h @@ -31,10 +31,10 @@ 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; diff --git a/src/core/TaskManager.cpp b/src/core/TaskManager.cpp index 6dbb08c4..53f9ff8c 100644 --- a/src/core/TaskManager.cpp +++ b/src/core/TaskManager.cpp @@ -28,7 +28,7 @@ namespace easy2d if (tasks_.IsEmpty()) return; - SpTask next; + TaskPtr next; for (auto task = tasks_.First(); task; task = next) { next = task->NextItem(); @@ -41,7 +41,7 @@ namespace easy2d } } - void TaskManager::AddTask(SpTask const& task) + void TaskManager::AddTask(TaskPtr const& task) { E2D_ASSERT(task && "AddTask failed, NULL pointer exception"); @@ -85,7 +85,7 @@ namespace easy2d if (tasks_.IsEmpty()) return; - SpTask next; + TaskPtr next; for (auto task = tasks_.First(); task; task = next) { next = task->NextItem(); diff --git a/src/core/TaskManager.h b/src/core/TaskManager.h index 0080dc9b..5b36891b 100644 --- a/src/core/TaskManager.h +++ b/src/core/TaskManager.h @@ -25,12 +25,12 @@ namespace easy2d { class TaskManager { - using Tasks = intrusive::List; + using Tasks = intrusive::List; public: // 添加任务 void AddTask( - SpTask const& task + TaskPtr const& task ); // 启动任务 diff --git a/src/core/Text.cpp b/src/core/Text.cpp index bf656660..7524d491 100644 --- a/src/core/Text.cpp +++ b/src/core/Text.cpp @@ -235,7 +235,7 @@ namespace easy2d } } - void Text::SetLineSpacing(float line_spacing) + void Text::SetLineacingPtr(float line_spacing) { if (style_.line_spacing != line_spacing) { diff --git a/src/core/Text.h b/src/core/Text.h index a8b604d7..bc92bac5 100644 --- a/src/core/Text.h +++ b/src/core/Text.h @@ -150,7 +150,7 @@ namespace easy2d ); // 设置行间距(默认为 0) - void SetLineSpacing( + void SetLineacingPtr( float line_spacing ); @@ -208,7 +208,7 @@ namespace easy2d String text_; Font font_; TextStyle style_; - CpTextFormat text_format_; - CpTextLayout text_layout_; + D2DTextFormatPtr text_format_; + D2DTextLayoutPtr text_layout_; }; } \ No newline at end of file diff --git a/src/core/TextRenderer.h b/src/core/TextRenderer.h index da5560e6..e9b7cf86 100644 --- a/src/core/TextRenderer.h +++ b/src/core/TextRenderer.h @@ -123,4 +123,4 @@ namespace easy2d }; } -E2D_DECLARE_D2D_SMART_PTR(easy2d::ITextRenderer, CpTextRenderer); +E2D_DECLARE_D2D_SMART_PTR(easy2d::ITextRenderer, D2DTextRendererPtr); diff --git a/src/core/Transition.cpp b/src/core/Transition.cpp index 183b240d..72159694 100644 --- a/src/core/Transition.cpp +++ b/src/core/Transition.cpp @@ -55,7 +55,7 @@ namespace easy2d return done_; } - void Transition::Init(SpScene const& prev, SpScene const& next) + void Transition::Init(ScenePtr const& prev, ScenePtr const& next) { process_ = 0; delta_ = Duration{}; @@ -147,7 +147,7 @@ namespace easy2d { } - void BoxTransition::Init(SpScene const& prev, SpScene const& next) + void BoxTransition::Init(ScenePtr const& prev, ScenePtr const& next) { Transition::Init(prev, next); @@ -189,7 +189,7 @@ namespace easy2d { } - void EmergeTransition::Init(SpScene const& prev, SpScene const& next) + void EmergeTransition::Init(ScenePtr const& prev, ScenePtr const& next) { Transition::Init(prev, next); @@ -214,7 +214,7 @@ namespace easy2d { } - void FadeTransition::Init(SpScene const& prev, SpScene const& next) + void FadeTransition::Init(ScenePtr const& prev, ScenePtr const& next) { Transition::Init(prev, next); @@ -248,7 +248,7 @@ namespace easy2d { } - void MoveTransition::Init(SpScene const& prev, SpScene const& next) + void MoveTransition::Init(ScenePtr const& prev, ScenePtr const& next) { Transition::Init(prev, next); @@ -327,7 +327,7 @@ namespace easy2d { } - void RotationTransition::Init(SpScene const& prev, SpScene const& next) + void RotationTransition::Init(ScenePtr const& prev, ScenePtr const& next) { Transition::Init(prev, next); diff --git a/src/core/Transition.h b/src/core/Transition.h index 4a90885c..b6c57a38 100644 --- a/src/core/Transition.h +++ b/src/core/Transition.h @@ -43,8 +43,8 @@ namespace easy2d protected: virtual void Init( - SpScene const& prev, - SpScene const& next + ScenePtr const& prev, + ScenePtr 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_; + ScenePtr out_scene_; + ScenePtr in_scene_; + D2DLayerPtr out_layer_; + D2DLayerPtr 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 + ScenePtr const& prev, + ScenePtr 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 + ScenePtr const& prev, + ScenePtr 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 + ScenePtr const& prev, + ScenePtr 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 + ScenePtr const& prev, + ScenePtr 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 + ScenePtr const& prev, + ScenePtr const& next ) override; virtual void Reset() override; diff --git a/src/core/audio.cpp b/src/core/audio.cpp index 836d57b6..8318de84 100644 --- a/src/core/audio.cpp +++ b/src/core/audio.cpp @@ -167,7 +167,7 @@ namespace easy2d AudioDevice::~AudioDevice() { - E2D_LOG("Destroying audio device"); + E2D_LOG(L"Destroying audio device"); ClearVoiceCache(); @@ -179,18 +179,18 @@ namespace easy2d SafeRelease(x_audio2_); - modules::MediaFoundation().MFShutdown(); + modules::MediaFoundation::Get().MFShutdown(); } HRESULT AudioDevice::Init(bool debug) { - E2D_LOG("Initing audio device"); + E2D_LOG(L"Initing audio device"); - HRESULT hr = modules::MediaFoundation().MFStartup(MF_VERSION, MFSTARTUP_FULL); + HRESULT hr = modules::MediaFoundation::Get().MFStartup(MF_VERSION, MFSTARTUP_FULL); if (SUCCEEDED(hr)) { - hr = modules::XAudio2().XAudio2Create(&x_audio2_, 0, XAUDIO2_DEFAULT_PROCESSOR); + hr = modules::XAudio2::Get().XAudio2Create(&x_audio2_, 0, XAUDIO2_DEFAULT_PROCESSOR); } if (SUCCEEDED(hr)) diff --git a/src/core/d2dhelper.hpp b/src/core/d2dhelper.hpp index e7c45a5f..7af44ce0 100644 --- a/src/core/d2dhelper.hpp +++ b/src/core/d2dhelper.hpp @@ -19,42 +19,42 @@ // THE SOFTWARE. #pragma once -#include "intrusive/SmartPointer.hpp" +#include "intrusive/SmartPtr.hpp" #include #include #ifndef E2D_DECLARE_D2D_SMART_PTR #define E2D_DECLARE_D2D_SMART_PTR(class_name, sp_name)\ - using sp_name = ::easy2d::intrusive::SmartPointer< class_name > + using sp_name = ::easy2d::intrusive::SmartPtr< class_name > #endif namespace easy2d { - // "Cp" is a shorthand for "COM Pointer" + // "D2DPtr" is a shorthand for "COM Pointer" - 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(ID2D1Factory, D2DFactoryPtr); + E2D_DECLARE_D2D_SMART_PTR(IWICImagingFactory, D2DImagingFactoryPtr); + E2D_DECLARE_D2D_SMART_PTR(IDWriteFactory, D2DWriteFactoryPtr); + E2D_DECLARE_D2D_SMART_PTR(ID2D1SolidColorBrush, D2DSolidColorBrushPtr); + E2D_DECLARE_D2D_SMART_PTR(ID2D1RenderTarget, D2DRenderTargetPtr); + E2D_DECLARE_D2D_SMART_PTR(ID2D1HwndRenderTarget, D2DHwndRenderTargetPtr); + E2D_DECLARE_D2D_SMART_PTR(ID2D1BitmapRenderTarget, D2DBitmapRenderTargetPtr); + E2D_DECLARE_D2D_SMART_PTR(ID2D1StrokeStyle, D2DStrokeStylePtr); - 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(ID2D1Geometry, D2DGeometryPtr); + E2D_DECLARE_D2D_SMART_PTR(ID2D1RectangleGeometry, D2DRectangleGeometryPtr); + E2D_DECLARE_D2D_SMART_PTR(ID2D1RoundedRectangleGeometry, D2DRoundedRectangleGeometryPtr); + E2D_DECLARE_D2D_SMART_PTR(ID2D1EllipseGeometry, D2DEllipseGeometryPtr); + E2D_DECLARE_D2D_SMART_PTR(ID2D1GeometryGroup, D2DGeometryGroupPtr); + E2D_DECLARE_D2D_SMART_PTR(ID2D1PathGeometry, D2DPathGeometryPtr); + E2D_DECLARE_D2D_SMART_PTR(ID2D1TransformedGeometry, D2DTransformedGeometryPtr); + E2D_DECLARE_D2D_SMART_PTR(ID2D1GeometrySink, D2DGeometrySinkPtr); - 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(ID2D1Layer, D2DLayerPtr); + E2D_DECLARE_D2D_SMART_PTR(ID2D1Bitmap, D2DBitmapPtr); + E2D_DECLARE_D2D_SMART_PTR(IDWriteTextFormat, D2DTextFormatPtr); + E2D_DECLARE_D2D_SMART_PTR(IDWriteTextLayout, D2DTextLayoutPtr); inline void IntrusivePtrAddRef(IUnknown* ptr) { diff --git a/src/core/helper.hpp b/src/core/helper.hpp index 20be6f8c..bc7a20c2 100644 --- a/src/core/helper.hpp +++ b/src/core/helper.hpp @@ -20,7 +20,7 @@ #pragma once #include "RefCounter.hpp" -#include "intrusive/SmartPointer.hpp" +#include "intrusive/SmartPtr.hpp" #include "../math/vector.hpp" #include "../math/Rect.hpp" #include "../math/Matrix.hpp" @@ -34,13 +34,13 @@ #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 class_name##Ptr = ::easy2d::intrusive::SmartPtr< 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 class_name##Ptr = ::easy2d::intrusive::SmartPtr< class_name >;\ } #endif @@ -70,8 +70,9 @@ namespace easy2d namespace easy2d { - // "Sp" is a shorthand for "Smart Pointer" + // "Ptr" is a shorthand for "Smart Pointer" + E2D_DECLARE_SMART_PTR(Object); E2D_DECLARE_SMART_PTR(Image); E2D_DECLARE_SMART_PTR(Music); E2D_DECLARE_SMART_PTR(Task); @@ -140,9 +141,9 @@ namespace easy2d } template - inline intrusive::SmartPointer operator- (T* ptr) const + inline intrusive::SmartPtr operator- (T* ptr) const { - return intrusive::SmartPointer(ptr); + return intrusive::SmartPtr(ptr); } }; } diff --git a/src/core/intrusive/SmartPointer.hpp b/src/core/intrusive/SmartPtr.hpp similarity index 66% rename from src/core/intrusive/SmartPointer.hpp rename to src/core/intrusive/SmartPtr.hpp index 7ee3e0ac..b5ab02f0 100644 --- a/src/core/intrusive/SmartPointer.hpp +++ b/src/core/intrusive/SmartPtr.hpp @@ -27,47 +27,49 @@ namespace easy2d namespace intrusive { template - class SmartPointer + class SmartPtr { T* ptr_{ nullptr }; public: using Type = T; - SmartPointer() E2D_NOEXCEPT {} + SmartPtr() E2D_NOEXCEPT {} - SmartPointer(nullptr_t) E2D_NOEXCEPT {} + SmartPtr(nullptr_t) E2D_NOEXCEPT {} - SmartPointer(Type* p) E2D_NOEXCEPT : ptr_(p) + SmartPtr(Type* p) E2D_NOEXCEPT : ptr_(p) { IntrusivePtrAddRef(ptr_); } - SmartPointer(const SmartPointer& other) E2D_NOEXCEPT : ptr_(other.ptr_) + SmartPtr(const SmartPtr& other) E2D_NOEXCEPT + : ptr_(other.ptr_) { IntrusivePtrAddRef(ptr_); } template - SmartPointer(const SmartPointer& other) E2D_NOEXCEPT : ptr_(other.Get()) + SmartPtr(const SmartPtr& other) E2D_NOEXCEPT + : ptr_(other.Get()) { IntrusivePtrAddRef(ptr_); } - SmartPointer(SmartPointer&& other) E2D_NOEXCEPT + SmartPtr(SmartPtr&& other) E2D_NOEXCEPT { ptr_ = other.ptr_; other.ptr_ = nullptr; } - ~SmartPointer() E2D_NOEXCEPT + ~SmartPtr() E2D_NOEXCEPT { IntrusivePtrRelease(ptr_); } inline Type* Get() const E2D_NOEXCEPT { return ptr_; } - inline void Swap(SmartPointer& other) E2D_NOEXCEPT + inline void Swap(SmartPtr& other) E2D_NOEXCEPT { std::swap(ptr_, other.ptr_); } @@ -94,14 +96,14 @@ namespace easy2d inline bool operator !() const E2D_NOEXCEPT { return ptr_ == 0; } - inline SmartPointer& operator =(const SmartPointer& other) E2D_NOEXCEPT + inline SmartPtr& operator =(const SmartPtr& other) E2D_NOEXCEPT { if (other.ptr_ != ptr_) - SmartPointer(other).Swap(*this); + SmartPtr(other).Swap(*this); return *this; } - inline SmartPointer& operator =(SmartPointer&& other) E2D_NOEXCEPT + inline SmartPtr& operator =(SmartPtr&& other) E2D_NOEXCEPT { IntrusivePtrRelease(ptr_); ptr_ = other.ptr_; @@ -109,83 +111,83 @@ namespace easy2d return *this; } - inline SmartPointer& operator =(Type* p) E2D_NOEXCEPT + inline SmartPtr& operator =(Type* p) E2D_NOEXCEPT { if (p != ptr_) - SmartPointer(p).Swap(*this); + SmartPtr(p).Swap(*this); return *this; } - inline SmartPointer& operator =(nullptr_t) E2D_NOEXCEPT + inline SmartPtr& operator =(nullptr_t) E2D_NOEXCEPT { if (nullptr != ptr_) - SmartPointer{}.Swap(*this); + SmartPtr{}.Swap(*this); return *this; } }; template - inline bool operator==(SmartPointer const& lhs, SmartPointer const& rhs) E2D_NOEXCEPT + inline bool operator==(SmartPtr const& lhs, SmartPtr const& rhs) E2D_NOEXCEPT { return lhs.Get() == rhs.Get(); } template - inline bool operator!=(SmartPointer const& lhs, SmartPointer const& rhs) E2D_NOEXCEPT + inline bool operator!=(SmartPtr const& lhs, SmartPtr const& rhs) E2D_NOEXCEPT { return lhs.Get() != rhs.Get(); } template - inline bool operator<(SmartPointer const& lhs, SmartPointer const& rhs) E2D_NOEXCEPT + inline bool operator<(SmartPtr const& lhs, SmartPtr const& rhs) E2D_NOEXCEPT { return lhs.Get() < rhs.Get(); } template - inline bool operator==(SmartPointer const& lhs, T* rhs) E2D_NOEXCEPT + inline bool operator==(SmartPtr const& lhs, T* rhs) E2D_NOEXCEPT { return lhs.Get() == rhs; } template - inline bool operator!=(SmartPointer const& lhs, T* rhs) E2D_NOEXCEPT + inline bool operator!=(SmartPtr const& lhs, T* rhs) E2D_NOEXCEPT { return lhs.Get() != rhs; } template - inline bool operator==(T* lhs, SmartPointer const& rhs) E2D_NOEXCEPT + inline bool operator==(T* lhs, SmartPtr const& rhs) E2D_NOEXCEPT { return lhs == rhs.Get(); } template - inline bool operator!=(T* lhs, SmartPointer const& rhs) E2D_NOEXCEPT + inline bool operator!=(T* lhs, SmartPtr const& rhs) E2D_NOEXCEPT { return lhs != rhs.Get(); } template - inline bool operator==(SmartPointer const& lhs, nullptr_t) E2D_NOEXCEPT + inline bool operator==(SmartPtr const& lhs, nullptr_t) E2D_NOEXCEPT { return !static_cast(lhs); } template - inline bool operator!=(SmartPointer const& lhs, nullptr_t) E2D_NOEXCEPT + inline bool operator!=(SmartPtr const& lhs, nullptr_t) E2D_NOEXCEPT { return static_cast(lhs); } template - inline bool operator==(nullptr_t, SmartPointer const& rhs) E2D_NOEXCEPT + inline bool operator==(nullptr_t, SmartPtr const& rhs) E2D_NOEXCEPT { return !static_cast(rhs); } template - inline bool operator!=(nullptr_t, SmartPointer const& rhs) E2D_NOEXCEPT + inline bool operator!=(nullptr_t, SmartPtr const& rhs) E2D_NOEXCEPT { return static_cast(rhs); } @@ -194,7 +196,7 @@ namespace easy2d // template class cannot specialize std::swap, // so implement a swap function in easy2d namespace template - inline void swap(intrusive::SmartPointer& lhs, intrusive::SmartPointer& rhs) E2D_NOEXCEPT + inline void swap(intrusive::SmartPtr& lhs, intrusive::SmartPtr& rhs) E2D_NOEXCEPT { lhs.Swap(rhs); } diff --git a/src/core/keys.hpp b/src/core/keys.hpp index b5c90101..884543e9 100644 --- a/src/core/keys.hpp +++ b/src/core/keys.hpp @@ -32,7 +32,7 @@ namespace easy2d Right = VK_RIGHT, Down = VK_DOWN, Enter = VK_RETURN, - Space = VK_SPACE, + acePtr = VK_SPACE, Esc = VK_ESCAPE, Ctrl = VK_CONTROL, Shift = VK_SHIFT, diff --git a/src/core/logs.cpp b/src/core/logs.cpp index b147e25a..8bab3e2d 100644 --- a/src/core/logs.cpp +++ b/src/core/logs.cpp @@ -33,30 +33,30 @@ namespace easy2d { bool enabled = true; - void Out(std::ostream& stream, const char* output) + void Out(std::ostream& stream, const wchar_t* output) { stream << output; - ::OutputDebugStringA(output); + ::OutputDebugStringW(output); } - void OutPrefix(std::stringstream& ss) + void OutPrefix(std::wstringstream& ss) { std::time_t unix = ::time(NULL); struct tm tmbuf; localtime_s(&tmbuf, &unix); - ss << std::put_time(&tmbuf, "[easy2d] %H:%M:%S "); + ss << std::put_time(&tmbuf, L"[easy2d] %H:%M:%S "); } - void Output(std::ostream& stream, const char* prompt, const char* format, va_list args) + void Output(std::ostream& stream, const wchar_t* prompt, const wchar_t* format, va_list args) { if (!enabled) return; - size_t len = ::_vscprintf(format, args) + 1; - char* buffer = new char[len]; - ::_vsnprintf_s(buffer, len, len, format, args); + size_t len = ::_vscwprintf(format, args) + 1; + wchar_t* buffer = new wchar_t[len]; + ::_vsnwprintf_s(buffer, len, len, format, args); - std::stringstream ss; + std::wstringstream ss; OutPrefix(ss); ss << prompt << buffer; Out(stream, ss.str().c_str()); @@ -64,13 +64,13 @@ namespace easy2d delete[] buffer; } - void OutputLine(std::ostream& stream, const char* prompt, const char* format, va_list args) + void OutputLine(std::ostream& stream, const wchar_t* prompt, const wchar_t* format, va_list args) { if (!enabled) return; Output(stream, prompt, format, args); - Out(stream, "\r\n"); + Out(stream, L"\r\n"); } } @@ -84,74 +84,74 @@ namespace easy2d enabled = false; } - void Print(const char* format, ...) + void Print(const wchar_t* format, ...) { va_list args = nullptr; va_start(args, format); - Output(std::cout, "", format, args); + Output(std::cout, L"", format, args); va_end(args); } - void Println(const char* format, ...) + void Println(const wchar_t* format, ...) { va_list args = nullptr; va_start(args, format); - OutputLine(std::cout, "", format, args); + OutputLine(std::cout, L"", format, args); va_end(args); } - void Warning(const char* format, ...) + void Warning(const wchar_t* format, ...) { va_list args = nullptr; va_start(args, format); - Output(std::cerr, "Warning: ", format, args); + Output(std::cerr, L"Warning: ", format, args); va_end(args); } - void Warningln(const char* format, ...) + void Warningln(const wchar_t* format, ...) { va_list args = nullptr; va_start(args, format); - OutputLine(std::cerr, "Warning: ", format, args); + OutputLine(std::cerr, L"Warning: ", format, args); va_end(args); } - void Error(const char* format, ...) + void Error(const wchar_t* format, ...) { va_list args = nullptr; va_start(args, format); - Output(std::cerr, "Error: ", format, args); + Output(std::cerr, L"Error: ", format, args); va_end(args); } - void Errorln(const char* format, ...) + void Errorln(const wchar_t* format, ...) { va_list args = nullptr; va_start(args, format); - OutputLine(std::cerr, "Error: ", format, args); + OutputLine(std::cerr, L"Error: ", format, args); va_end(args); } void Errorln(HRESULT hr) { - Errorln("failure with HRESULT of %08X", hr); + Errorln(L"failure with HRESULT of %08X", hr); } - void Errorln(HRESULT hr, const char* output) + void Errorln(HRESULT hr, const wchar_t* output) { - Errorln("failure with HRESULT of %08X: %s", hr, output); + Errorln(L"failure with HRESULT of %08X: %s", hr, output); } } } diff --git a/src/core/logs.h b/src/core/logs.h index 1ebeae63..cf308571 100644 --- a/src/core/logs.h +++ b/src/core/logs.h @@ -37,21 +37,21 @@ namespace easy2d void Disable(); - void Print(const char* format, ...); + void Print(const wchar_t* format, ...); - void Println(const char* format, ...); + void Println(const wchar_t* format, ...); - void Warning(const char* format, ...); + void Warning(const wchar_t* format, ...); - void Warningln(const char* format, ...); + void Warningln(const wchar_t* format, ...); - void Error(const char* format, ...); + void Error(const wchar_t* format, ...); - void Errorln(const char* format, ...); + void Errorln(const wchar_t* format, ...); void Errorln(HRESULT hr); - void Errorln(HRESULT hr, const char* output); + void Errorln(HRESULT hr, const wchar_t* output); } inline void ThrowIfFailed(HRESULT hr) diff --git a/src/core/modules.cpp b/src/core/modules.cpp index f3ffd4c9..8c7d2cbb 100644 --- a/src/core/modules.cpp +++ b/src/core/modules.cpp @@ -38,7 +38,7 @@ namespace easy2d } else { - E2D_LOG("load shlapi.dll failed"); + E2D_LOG(L"load shlapi.dll failed"); } } @@ -52,7 +52,7 @@ namespace easy2d } else { - E2D_LOG("load d2d.dll failed"); + E2D_LOG(L"load d2d.dll failed"); } dwrite = LoadLibraryW(L"dwrite.dll"); @@ -63,7 +63,7 @@ namespace easy2d } else { - E2D_LOG("load dwrite.dll failed"); + E2D_LOG(L"load dwrite.dll failed"); } } @@ -89,7 +89,7 @@ namespace easy2d if (!xaudio2) { - E2D_LOG("load xaudio2.dll failed"); + E2D_LOG(L"load xaudio2.dll failed"); } } @@ -115,7 +115,7 @@ namespace easy2d } else { - E2D_LOG("load Mfplat.dll failed"); + E2D_LOG(L"load Mfplat.dll failed"); } mfreadwrite = LoadLibraryW(L"Mfreadwrite.dll"); @@ -129,7 +129,7 @@ namespace easy2d } else { - E2D_LOG("load Mfreadwrite.dll failed"); + E2D_LOG(L"load Mfreadwrite.dll failed"); } } } diff --git a/src/core/modules.h b/src/core/modules.h index 807069fb..0612d771 100644 --- a/src/core/modules.h +++ b/src/core/modules.h @@ -33,6 +33,8 @@ namespace easy2d { class Shlwapi { + Shlwapi(); + HMODULE shlwapi; // Shlwapi functions @@ -40,7 +42,11 @@ namespace easy2d typedef IStream*(WINAPI *PFN_SHCreateMemStream)(const BYTE*, UINT); public: - Shlwapi(); + static Shlwapi& Get() + { + static Shlwapi instance; + return instance; + } PFN_PathFileExistsW PathFileExistsW; PFN_SHCreateMemStream SHCreateMemStream; @@ -49,6 +55,8 @@ namespace easy2d class DirectX { + DirectX(); + HMODULE d2d; HMODULE dwrite; @@ -57,7 +65,11 @@ namespace easy2d typedef HRESULT(WINAPI *PFN_DWriteCreateFactory)(DWRITE_FACTORY_TYPE, const IID&, IUnknown **); public: - DirectX(); + static DirectX& Get() + { + static DirectX instance; + return instance; + } PFN_D2D1CreateFactory D2D1CreateFactory; PFN_DWriteCreateFactory DWriteCreateFactory; @@ -66,13 +78,19 @@ namespace easy2d class XAudio2 { + XAudio2(); + HMODULE xaudio2; // XAudio2 functions typedef HRESULT(WINAPI *PFN_XAudio2Create)(IXAudio2**, UINT32, XAUDIO2_PROCESSOR); public: - XAudio2(); + static XAudio2& Get() + { + static XAudio2 instance; + return instance; + } PFN_XAudio2Create XAudio2Create; }; @@ -80,6 +98,8 @@ namespace easy2d class MediaFoundation { + MediaFoundation(); + HMODULE mfplat; HMODULE mfreadwrite; @@ -93,7 +113,11 @@ namespace easy2d typedef HRESULT(WINAPI *PFN_MFCreateMFByteStreamOnStream)(IStream*, IMFByteStream**); public: - MediaFoundation(); + static MediaFoundation& Get() + { + static MediaFoundation instance; + return instance; + } PFN_MFStartup MFStartup; PFN_MFShutdown MFShutdown; diff --git a/src/core/render.cpp b/src/core/render.cpp index 36f5a95d..5f386bc7 100644 --- a/src/core/render.cpp +++ b/src/core/render.cpp @@ -41,14 +41,14 @@ namespace easy2d GraphicsDevice::~GraphicsDevice() { - E2D_LOG("Destroying graphics device"); + E2D_LOG(L"Destroying graphics device"); ClearImageCache(); } HRESULT GraphicsDevice::Init(HWND hwnd, bool vsync, bool debug) { - E2D_LOG("Initing graphics device"); + E2D_LOG(L"Initing graphics device"); vsync_enabled_ = vsync; debug_ = debug; @@ -108,17 +108,17 @@ namespace easy2d bitmap_cache_.clear(); } - CpHwndRenderTarget const & GraphicsDevice::GetRenderTarget() const + D2DHwndRenderTargetPtr const & GraphicsDevice::GetRenderTarget() const { return render_target_; } - CpSolidColorBrush const & GraphicsDevice::GetSolidBrush() const + D2DSolidColorBrushPtr const & GraphicsDevice::GetSolidBrush() const { return solid_brush_; } - HRESULT GraphicsDevice::CreateLayer(CpLayer& layer) + HRESULT GraphicsDevice::CreateLayer(D2DLayerPtr& 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(D2DSolidColorBrushPtr & brush) const { if (!render_target_) return E_UNEXPECTED; @@ -140,7 +140,7 @@ namespace easy2d } HRESULT GraphicsDevice::DrawGeometry( - CpGeometry const& geometry, + D2DGeometryPtr 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(D2DGeometryPtr 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(ImagePtr const & image) { if (!render_target_) return E_UNEXPECTED; @@ -212,7 +212,7 @@ namespace easy2d } HRESULT GraphicsDevice::DrawBitmap( - CpBitmap const& bitmap + D2DBitmapPtr const& bitmap ) { if (!render_target_) @@ -236,7 +236,7 @@ namespace easy2d return S_OK; } - HRESULT GraphicsDevice::DrawTextLayout(CpTextLayout const& text_layout) + HRESULT GraphicsDevice::DrawTextLayout(D2DTextLayoutPtr 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(D2DLayerPtr const& layer, LayerProperties const& properties) { if (!render_target_ || !solid_brush_) @@ -324,7 +324,7 @@ namespace easy2d return S_OK; } - HRESULT GraphicsDevice::CreateBitmapFromFile(CpBitmap& bitmap, String const& file_path) + HRESULT GraphicsDevice::CreateBitmapFromFile(D2DBitmapPtr& bitmap, String const& file_path) { if (render_target_ == nullptr) { @@ -338,7 +338,7 @@ namespace easy2d return S_OK; } - CpBitmap bitmap_tmp; + D2DBitmapPtr 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(D2DBitmapPtr& bitmap, Resource const& res) { if (render_target_ == nullptr) { @@ -381,7 +381,7 @@ namespace easy2d return hr; } - HRESULT GraphicsDevice::CreateBitmapRenderTarget(CpBitmapRenderTarget & brt) + HRESULT GraphicsDevice::CreateBitmapRenderTarget(D2DBitmapRenderTargetPtr & brt) { if (!render_target_) return E_UNEXPECTED; diff --git a/src/core/render.h b/src/core/render.h index de7bd336..bf884404 100644 --- a/src/core/render.h +++ b/src/core/render.h @@ -43,7 +43,7 @@ namespace easy2d int primitives; }; - using BitmapMap = UnorderedMap; + using BitmapMap = UnorderedMap; public: HRESULT Init(HWND hwnd, bool vsync, bool debug); @@ -78,25 +78,25 @@ namespace easy2d void DiscardResources(); HRESULT CreateLayer( - CpLayer& layer + D2DLayerPtr& layer ); HRESULT CreateSolidColorBrush( - CpSolidColorBrush& brush + D2DSolidColorBrushPtr& brush ) const; HRESULT CreateBitmapFromFile( - CpBitmap& bitmap, + D2DBitmapPtr& bitmap, String const& file_path ); HRESULT CreateBitmapFromResource( - CpBitmap& bitmap, + D2DBitmapPtr& bitmap, Resource const& res ); HRESULT CreateBitmapRenderTarget( - CpBitmapRenderTarget& brt + D2DBitmapRenderTargetPtr& brt ); HRESULT SetTransform( @@ -116,27 +116,27 @@ namespace easy2d ); HRESULT DrawGeometry( - CpGeometry const& geometry, + D2DGeometryPtr const& geometry, const Color& stroke_color, float stroke_width, StrokeStyle stroke = StrokeStyle::Miter ); HRESULT FillGeometry( - CpGeometry const& geometry, + D2DGeometryPtr const& geometry, const Color& fill_color ); HRESULT DrawImage( - SpImage const& image + ImagePtr const& image ); HRESULT DrawBitmap( - CpBitmap const& bitmap + D2DBitmapPtr const& bitmap ); HRESULT DrawTextLayout( - CpTextLayout const& text_layout + D2DTextLayoutPtr const& text_layout ); HRESULT PushClip( @@ -147,7 +147,7 @@ namespace easy2d HRESULT PopClip(); HRESULT PushLayer( - CpLayer const& layer, + D2DLayerPtr const& layer, LayerProperties const& properties ); @@ -164,9 +164,9 @@ namespace easy2d void ClearImageCache(); - CpHwndRenderTarget const& GetRenderTarget() const; + D2DHwndRenderTargetPtr const& GetRenderTarget() const; - CpSolidColorBrush const& GetSolidBrush() const; + D2DSolidColorBrushPtr 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_; + D2DTextRendererPtr text_renderer_; + D2DSolidColorBrushPtr solid_brush_; + D2DHwndRenderTargetPtr render_target_; + D2DTextFormatPtr fps_text_format_; + D2DTextLayoutPtr fps_text_layout_; BitmapMap bitmap_cache_; }; diff --git a/src/core/time.cpp b/src/core/time.cpp index 7babbe36..90a65df0 100644 --- a/src/core/time.cpp +++ b/src/core/time.cpp @@ -412,7 +412,7 @@ namespace easy2d if (!std::regex_match(str, duration_regex)) { - logs::Errorln("time::ParseDuration failed, invalid duration"); + logs::Errorln(L"time::ParseDuration failed, invalid duration"); return Duration(); } @@ -443,7 +443,7 @@ namespace easy2d if (num_str.empty() || num_str == L".") { - logs::Errorln("time::ParseDuration failed, invalid duration"); + logs::Errorln(L"time::ParseDuration failed, invalid duration"); return Duration(); } @@ -462,7 +462,7 @@ namespace easy2d if (unit_map.find(unit_str) == unit_map.end()) { - logs::Errorln("time::ParseDuration failed, invalid duration"); + logs::Errorln(L"time::ParseDuration failed, invalid duration"); return Duration(); } diff --git a/src/core/window.cpp b/src/core/window.cpp index 6f729f5c..6f1c356d 100644 --- a/src/core/window.cpp +++ b/src/core/window.cpp @@ -44,12 +44,12 @@ namespace easy2d WindowImpl::~WindowImpl() { - E2D_LOG("Destroying window"); + E2D_LOG(L"Destroying window"); } HRESULT WindowImpl::Init(String title, int width, int height, LPCWSTR icon, WNDPROC proc, bool debug) { - E2D_LOG("Creating window"); + E2D_LOG(L"Creating window"); HINSTANCE hinstance = GetModuleHandle(nullptr); WNDCLASSEX wcex = { 0 }; @@ -235,7 +235,7 @@ namespace easy2d height = static_cast(rect.bottom - rect.top); if (max_width < width || max_height < height) - logs::Warningln("The window is larger than screen!"); + logs::Warningln(L"The window is larger than screen!"); width = std::min(width, max_width); height = std::min(height, max_height); diff --git a/src/easy2d.h b/src/easy2d.h index be78367b..46aa2706 100644 --- a/src/easy2d.h +++ b/src/easy2d.h @@ -47,7 +47,7 @@ #include "core/noncopyable.hpp" #include "core/RefCounter.hpp" -#include "core/intrusive/SmartPointer.hpp" +#include "core/intrusive/SmartPtr.hpp" #include "core/intrusive/List.hpp" #include "core/Object.h" @@ -104,6 +104,7 @@ #include "utils/File.h" #include "utils/Player.h" #include "utils/Transcoder.h" +#include "utils/ResLoader.h" // diff --git a/src/math/rand.h b/src/math/rand.h index 201a3e49..1730fed4 100644 --- a/src/math/rand.h +++ b/src/math/rand.h @@ -89,7 +89,7 @@ namespace easy2d return RandomReal(min, max); } - inline double Range(double min, double max) + inline double Rand(double min, double max) { return RandomReal(min, max); } diff --git a/src/ui/Menu.cpp b/src/ui/Menu.cpp index 4c2ffeee..78e11b5e 100644 --- a/src/ui/Menu.cpp +++ b/src/ui/Menu.cpp @@ -29,7 +29,7 @@ namespace easy2d { } - Menu::Menu(Array const& buttons) + Menu::Menu(Array const& buttons) : enabled_(true) { for (const auto& button : buttons) @@ -61,7 +61,7 @@ namespace easy2d } } - void Menu::AddButton(SpButton const& button) + void Menu::AddButton(ButtonPtr const& button) { if (button) { @@ -71,7 +71,7 @@ namespace easy2d } } - bool Menu::RemoveButton(SpButton const& button) + bool Menu::RemoveButton(ButtonPtr const& button) { if (buttons_.empty()) { @@ -94,7 +94,7 @@ namespace easy2d return false; } - Array const& Menu::GetAllButtons() const + Array const& Menu::GetAllButtons() const { return buttons_; } diff --git a/src/ui/Menu.h b/src/ui/Menu.h index fe423f1d..fefd7828 100644 --- a/src/ui/Menu.h +++ b/src/ui/Menu.h @@ -33,7 +33,7 @@ namespace easy2d Menu(); explicit Menu( - Array const& buttons /* 按钮数组 */ + Array const& buttons /* 按钮数组 */ ); // 获取菜单是否禁用 @@ -49,20 +49,20 @@ namespace easy2d // 添加按钮 void AddButton( - SpButton const& button + ButtonPtr const& button ); // 移除按钮 bool RemoveButton( - SpButton const& button + ButtonPtr const& button ); // 获取所有按钮 - Array const& GetAllButtons() const; + Array const& GetAllButtons() const; private: bool enabled_; - Array buttons_; + Array buttons_; }; } } \ No newline at end of file diff --git a/src/utils/File.cpp b/src/utils/File.cpp index 6e28d6a0..03e63bbf 100644 --- a/src/utils/File.cpp +++ b/src/utils/File.cpp @@ -24,8 +24,6 @@ namespace easy2d { - std::list File::search_paths_; - File::File() : file_path_() { @@ -34,7 +32,6 @@ namespace easy2d File::File(String const& file_name) : file_path_(file_name) { - this->Open(file_name); } File::~File() @@ -46,35 +43,13 @@ namespace easy2d if (file_name.empty()) return false; - auto FindFile = [](String const& path) -> bool - { - if (modules::Shlwapi().PathFileExistsW(path.c_str())) - return true; - return false; - }; - - if (FindFile(file_name)) - { - file_path_ = file_name; - return true; - } - - for (const auto& path : search_paths_) - { - if (FindFile(path + file_name)) - { - file_path_ = path + file_name; - return true; - } - } - return false; + file_path_ = file_name; + return Exists(); } bool File::Exists() const { - if (modules::Shlwapi().PathFileExistsW(file_path_.c_str())) - return true; - return false; + return modules::Shlwapi::Get().PathFileExistsW(file_path_.c_str()); } String const& File::GetPath() const @@ -101,7 +76,7 @@ namespace easy2d return false; } - File File::Extract(Resource& res, String const& dest_file_name) + File File::Extract(Resource const& res, String const& dest_file_name) { File file; HANDLE file_handle = ::CreateFile( @@ -136,25 +111,4 @@ namespace easy2d return file; } - - void File::AddSearchPath(String const& path) - { - String tmp = path; - size_t pos = 0; - while ((pos = tmp.find(L"/", pos)) != String::npos) - { - tmp.replace(pos, 1, L"\\"); - pos++; - } - - if (tmp.at(tmp.length() - 1) != L'\\') - { - tmp.append(L"\\"); - } - auto iter = std::find(search_paths_.cbegin(), search_paths_.cend(), tmp); - if (iter == search_paths_.cend()) - { - search_paths_.push_front(tmp); - } - } } \ No newline at end of file diff --git a/src/utils/File.h b/src/utils/File.h index 93f20034..2931a08b 100644 --- a/src/utils/File.h +++ b/src/utils/File.h @@ -53,20 +53,13 @@ namespace easy2d // 获取文件扩展名 String GetExtension() const; - // 释放资源到临时文件目录 + // 释放二进制资源到临时文件目录 static File Extract( - Resource& res, /* 资源 */ + Resource const& res, /* 资源 */ String const& dest_file_name /* 目标文件名 */ ); - // 添加文件搜索路径 - static void AddSearchPath( - String const& path - ); - protected: String file_path_; - - static List search_paths_; }; } diff --git a/src/utils/Player.cpp b/src/utils/Player.cpp index 853be7c7..834d0d22 100644 --- a/src/utils/Player.cpp +++ b/src/utils/Player.cpp @@ -39,7 +39,7 @@ namespace easy2d if (musics_cache_.end() != musics_cache_.find(hash_code)) return true; - SpMusic music = new (std::nothrow) Music(); + MusicPtr music = new (std::nothrow) Music(); if (music) { diff --git a/src/utils/Player.h b/src/utils/Player.h index dee336e0..c94f16c7 100644 --- a/src/utils/Player.h +++ b/src/utils/Player.h @@ -29,7 +29,7 @@ namespace easy2d class Player : protected Noncopyable { - using MusicMap = Map; + using MusicMap = Map; public: Player(); diff --git a/src/utils/ResLoader.cpp b/src/utils/ResLoader.cpp new file mode 100644 index 00000000..7bbf8b50 --- /dev/null +++ b/src/utils/ResLoader.cpp @@ -0,0 +1,114 @@ +// Copyright (c) 2016-2018 Easy2D - Nomango +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#include "ResLoader.h" +#include "../core/Image.h" +#include "../core/Frames.h" +#include "../core/modules.h" + +namespace easy2d +{ + namespace + { + String Search(LPCWSTR file_name, List const& paths) + { + for (const auto& path : paths) + { + if (modules::Shlwapi::Get().PathFileExistsW((path + file_name).c_str())) + { + return path + file_name; + } + } + return file_name; + } + } + + void ResLoader::AddImage(String const& id, Resource const& image) + { + auto path = Search(image.GetFileName(), search_paths_); + res_.insert(std::make_pair(id, ImagePtr(new Image(path.c_str())))); + } + + void ResLoader::AddFrames(String const& id, Array const& images, Duration const& interval) + { + auto frames = FramesPtr(new Frames); + frames->SetInterval(interval); + + for (const auto& image : images) + { + auto path = Search(image.GetFileName(), search_paths_); + frames->Add(ImagePtr(new Image(path.c_str()))); + } + res_.insert(std::make_pair(id, frames)); + } + + void ResLoader::AddObj(String const& id, ObjectPtr const& obj) + { + res_.insert(std::make_pair(id, obj)); + } + + ImagePtr ResLoader::GetImage(String const & id) const + { + return Get(id); + } + + FramesPtr ResLoader::GetFrames(String const & id) const + { + return Get(id); + } + + ObjectPtr ResLoader::GetObj(String const & id) const + { + return Get(id); + } + + void ResLoader::Delete(String const & id) + { + res_.erase(id); + } + + void ResLoader::Destroy() + { + res_.clear(); + } + + void ResLoader::AddSearchPath(String const & path) + { + String tmp = path; + size_t pos = 0; + while ((pos = tmp.find(L"/", pos)) != String::npos) + { + tmp.replace(pos, 1, L"\\"); + pos++; + } + + if (tmp.at(tmp.length() - 1) != L'\\') + { + tmp.append(L"\\"); + } + + auto iter = std::find(search_paths_.cbegin(), search_paths_.cend(), tmp); + if (iter == search_paths_.cend()) + { + search_paths_.push_front(tmp); + } + } + +} \ No newline at end of file diff --git a/ResLoader.h b/src/utils/ResLoader.h similarity index 61% rename from ResLoader.h rename to src/utils/ResLoader.h index ee4455a2..bc354c07 100644 --- a/ResLoader.h +++ b/src/utils/ResLoader.h @@ -19,30 +19,46 @@ // THE SOFTWARE. #pragma once -#include "include-forwards.h" +#include "../core/include-forwards.h" +#include "../core/Resource.h" namespace easy2d { class ResLoader { public: - //void Add(String const& id, SpImage const& image); + void AddImage(String const& id, Resource const& image); - //void Add(String const& id, SpFrames const& frames); + void AddFrames(String const& id, Array const& images, Duration const& interval = 200); - //SpImage GetImage(String const& id); + void AddObj(String const& id, ObjectPtr const& obj); - //SpFrames GetFrames(String const& id); + ImagePtr GetImage(String const& id) const; + + FramesPtr GetFrames(String const& id) const; + + ObjectPtr GetObj(String const& id) const; + + void Delete(String const& id); + + void Destroy(); + + // 添加资源搜索路径 + void AddSearchPath( + String const& path + ); template - T Get(String const& id) const + auto Get(String const& id) const -> decltype(auto) { - if (res_.find(id) == res_.end()) + auto iter = res_.find(id); + if (iter == res_.end()) return T{}; - return static_cast(res_.at(id)); + return dynamic_cast((*iter).second.Get()); } protected: - UnorderedMap res_; + UnorderedMap res_; + List search_paths_; }; } diff --git a/src/utils/Transcoder.cpp b/src/utils/Transcoder.cpp index d4d59c4e..0566415a 100644 --- a/src/utils/Transcoder.cpp +++ b/src/utils/Transcoder.cpp @@ -51,9 +51,9 @@ namespace easy2d { HRESULT hr = S_OK; - SmartPointer reader; + SmartPtr reader; - hr = modules::MediaFoundation().MFCreateSourceReaderFromURL( + hr = modules::MediaFoundation::Get().MFCreateSourceReaderFromURL( file_path, nullptr, &reader @@ -72,33 +72,33 @@ namespace easy2d HRESULT hr = S_OK; HINSTANCE hinstance = GetModuleHandle(nullptr); - SmartPointer stream; - SmartPointer byte_stream; - SmartPointer reader; + SmartPtr stream; + SmartPtr byte_stream; + SmartPtr reader; LPVOID buffer; DWORD buffer_size; if (!res.Load(buffer, buffer_size)) { return false; } - stream = modules::Shlwapi{}.SHCreateMemStream( + stream = modules::Shlwapi::Get().SHCreateMemStream( static_cast(buffer), static_cast(buffer_size) ); if (stream == nullptr) { - logs::Errorln("SHCreateMemStream"); + logs::Errorln(L"SHCreateMemStream"); return E_OUTOFMEMORY; } if (SUCCEEDED(hr)) { - hr = modules::MediaFoundation().MFCreateMFByteStreamOnStream(stream.Get(), &byte_stream); + hr = modules::MediaFoundation::Get().MFCreateMFByteStreamOnStream(stream.Get(), &byte_stream); } if (SUCCEEDED(hr)) { - hr = modules::MediaFoundation().MFCreateSourceReaderFromByteStream( + hr = modules::MediaFoundation::Get().MFCreateSourceReaderFromByteStream( byte_stream.Get(), nullptr, &reader @@ -118,10 +118,10 @@ namespace easy2d HRESULT hr = S_OK; DWORD max_stream_size = 0; - SmartPointer partial_type; - SmartPointer uncompressed_type; + SmartPtr partial_type; + SmartPtr uncompressed_type; - hr = modules::MediaFoundation().MFCreateMediaType(&partial_type); + hr = modules::MediaFoundation::Get().MFCreateMediaType(&partial_type); if (SUCCEEDED(hr)) { @@ -165,7 +165,7 @@ namespace easy2d if (SUCCEEDED(hr)) { UINT32 size = 0; - hr = modules::MediaFoundation().MFCreateWaveFormatExFromMFMediaType( + hr = modules::MediaFoundation::Get().MFCreateWaveFormatExFromMFMediaType( uncompressed_type.Get(), &wave_format_, &size, @@ -199,12 +199,12 @@ namespace easy2d DWORD position = 0; BYTE* data = new (std::nothrow) BYTE[max_stream_size]; - SmartPointer sample; - SmartPointer buffer; + SmartPtr sample; + SmartPtr buffer; if (data == nullptr) { - logs::Errorln("Low memory"); + logs::Errorln(L"Low memory"); hr = E_OUTOFMEMORY; } else diff --git a/src/utils/string.cpp b/src/utils/string.cpp index 180f8130..9ea9cf6c 100644 --- a/src/utils/string.cpp +++ b/src/utils/string.cpp @@ -42,7 +42,7 @@ namespace easy2d } else { - logs::Errorln(HRESULT_FROM_WIN32(GetLastError()), "Wrong convert to WideChar code"); + logs::Errorln(HRESULT_FROM_WIN32(GetLastError()), L"Convert to WideChar code failed"); } } return ret; @@ -66,7 +66,7 @@ namespace easy2d } else { - logs::Errorln(HRESULT_FROM_WIN32(GetLastError()), ("Wrong convert to MultiByte code")); + logs::Errorln(HRESULT_FROM_WIN32(GetLastError()), L"Convert to MultiByte code failed"); } }