remove: easy2d::RuntimeError class

This commit is contained in:
Haibo 2018-10-28 23:35:07 +08:00 committed by Nomango
parent 380bde7932
commit def0d9ede2
6 changed files with 51 additions and 89 deletions

View File

@ -81,6 +81,7 @@
#include <sstream>
#include <functional>
#include <algorithm>
#include <stdexcept>
// Import Libraries
#pragma comment(lib, "d2d1.lib")

View File

@ -27,49 +27,6 @@
namespace easy2d
{
// 随机数产生器
class Random
{
public:
// 取得范围内的一个整型随机数
template<typename T>
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<typename T>
static T RandomInt(T min, T max)
{
std::uniform_int_distribution<T> dist(min, max);
return dist(Random::GetEngine());
}
template<typename T>
static T RandomReal(T min, T max)
{
std::uniform_real_distribution<T> dist(min, max);
return dist(Random::GetEngine());
}
// 获取随机数产生器
static std::default_random_engine &GetEngine();
};
// 稜있
class Music
: public Ref

View File

@ -526,6 +526,49 @@ namespace easy2d
};
// 随机数产生器
class Random
{
public:
// 取得范围内的一个整型随机数
template<typename T>
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<typename T>
static T RandomInt(T min, T max)
{
std::uniform_int_distribution<T> dist(min, max);
return dist(Random::GetEngine());
}
template<typename T>
static T RandomReal(T min, T max)
{
std::uniform_real_distribution<T> 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<unsigned int>(hr));
throw RuntimeError(s_str);
throw std::runtime_error(s_str);
}
}

View File

@ -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;
}

View File

@ -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 已有执行目标");
}
}
}

View File

@ -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()
{