diff --git a/core/e2dmacros.h b/core/e2dmacros.h index b30a6f6f..4de8cc47 100644 --- a/core/e2dmacros.h +++ b/core/e2dmacros.h @@ -81,6 +81,7 @@ #include #include #include +#include // Import Libraries #pragma comment(lib, "d2d1.lib") diff --git a/core/e2dtool.h b/core/e2dtool.h index 4e8f047c..948f831d 100644 --- a/core/e2dtool.h +++ b/core/e2dtool.h @@ -27,49 +27,6 @@ namespace easy2d { - // 随机数产生器 - class Random - { - public: - // 取得范围内的一个整型随机数 - template - static inline T Range(T min, T max) - { - return easy2d::Random::RandomInt(min, max); - } - - // 取得范围内的一个浮点数随机数 - static inline float Range(float min, float max) - { - return easy2d::Random::RandomReal(min, max); - } - - // 取得范围内的一个浮点数随机数 - static inline double Range(double min, double max) - { - return easy2d::Random::RandomReal(min, max); - } - - private: - template - static T RandomInt(T min, T max) - { - std::uniform_int_distribution dist(min, max); - return dist(Random::GetEngine()); - } - - template - static T RandomReal(T min, T max) - { - std::uniform_real_distribution dist(min, max); - return dist(Random::GetEngine()); - } - - // 获取随机数产生器 - static std::default_random_engine &GetEngine(); - }; - - // 音乐 class Music : public Ref diff --git a/core/e2dutil.h b/core/e2dutil.h index 7aa5ba09..3f4963b4 100644 --- a/core/e2dutil.h +++ b/core/e2dutil.h @@ -526,6 +526,49 @@ namespace easy2d }; + // 随机数产生器 + class Random + { + public: + // 取得范围内的一个整型随机数 + template + static inline T Range(T min, T max) + { + return easy2d::Random::RandomInt(min, max); + } + + // 取得范围内的一个浮点数随机数 + static inline float Range(float min, float max) + { + return easy2d::Random::RandomReal(min, max); + } + + // 取得范围内的一个浮点数随机数 + static inline double Range(double min, double max) + { + return easy2d::Random::RandomReal(min, max); + } + + private: + template + static T RandomInt(T min, T max) + { + std::uniform_int_distribution dist(min, max); + return dist(Random::GetEngine()); + } + + template + static T RandomReal(T min, T max) + { + std::uniform_real_distribution dist(min, max); + return dist(Random::GetEngine()); + } + + // 获取随机数产生器 + static std::default_random_engine &GetEngine(); + }; + + // 引用计数对象 class Ref { @@ -558,45 +601,6 @@ namespace easy2d } } - // 运行时异常 - class RuntimeError - { - public: - RuntimeError() E2D_NOEXCEPT - : message_(nullptr) - { - } - - explicit RuntimeError(char const* const message) E2D_NOEXCEPT - : message_(message) - { - } - - RuntimeError(RuntimeError const& other) E2D_NOEXCEPT - : message_(other.message_) - { - } - - RuntimeError& operator=(RuntimeError const& other) E2D_NOEXCEPT - { - if (this == &other) - { - return *this; - } - - message_ = other.message_; - return *this; - } - - virtual char const* Message() const - { - return message_ ? message_ : "Unknown runtime exception"; - } - - private: - char const* message_; - }; - inline void ThrowIfFailed(HRESULT hr) { @@ -605,7 +609,7 @@ namespace easy2d // 在此处设置断点以捕获系统异常. static char s_str[64] = {}; sprintf_s(s_str, "Failure with HRESULT of %08X", static_cast(hr)); - throw RuntimeError(s_str); + throw std::runtime_error(s_str); } } diff --git a/core/modules/Game.cpp b/core/modules/Game.cpp index f47c4068..e3820319 100644 --- a/core/modules/Game.cpp +++ b/core/modules/Game.cpp @@ -51,7 +51,7 @@ easy2d::Game::Game() { if (instance) { - throw RuntimeError("同时只能存在一个游戏实例"); + throw std::runtime_error("同时只能存在一个游戏实例"); } instance = this; @@ -317,7 +317,7 @@ void easy2d::Game::Init() if (hwnd_ == nullptr) { ::UnregisterClass(REGISTER_CLASS, hinstance); - throw RuntimeError("Create window failed"); + throw std::runtime_error("Create window failed"); return; } diff --git a/core/objects/Node.cpp b/core/objects/Node.cpp index 7ad699c0..05e84cf4 100644 --- a/core/objects/Node.cpp +++ b/core/objects/Node.cpp @@ -606,14 +606,14 @@ void easy2d::Node::AddChild(Node * child, int order) { if (child->parent_ != nullptr) { - throw RuntimeError("节点已有父节点, 不能再添加到其他节点"); + throw std::runtime_error("节点已有父节点, 不能再添加到其他节点"); } for (Node * parent = this; parent != nullptr; parent = parent->GetParent()) { if (child == parent) { - throw RuntimeError("一个节点不能同时是另一个节点的父节点和子节点"); + throw std::runtime_error("一个节点不能同时是另一个节点的父节点和子节点"); } } @@ -787,7 +787,7 @@ void easy2d::Node::RunAction(Action * action) } else { - throw RuntimeError("该 Action 已有执行目标"); + throw std::runtime_error("该 Action 已有执行目标"); } } } diff --git a/core/utils/Random.cpp b/core/utils/Random.cpp index 035dce8b..f6aab299 100644 --- a/core/utils/Random.cpp +++ b/core/utils/Random.cpp @@ -18,7 +18,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#include "..\e2dtool.h" +#include "..\e2dutil.h" std::default_random_engine &easy2d::Random::GetEngine() {