增加Exception类

This commit is contained in:
Nomango 2018-05-24 00:58:16 +08:00
parent dfd49588cd
commit 7499e1af7f
28 changed files with 285 additions and 197 deletions

View File

@ -1,4 +1,5 @@
#include "..\e2daction.h"
#include "..\e2dnode.h"
e2d::Animate::Animate()
: _frameIndex(0)

View File

@ -1,4 +1,5 @@
#include "..\e2daction.h"
#include "..\e2dnode.h"
e2d::JumpBy::JumpBy(double duration, const Vector & vec, double height, int jumps)
: FiniteTimeAction(duration)

View File

@ -1,4 +1,5 @@
#include "..\e2daction.h"
#include "..\e2dnode.h"
e2d::JumpTo::JumpTo(double duration, const Point & pos, double height, int jumps)
: JumpBy(duration, Point(), height, jumps)

View File

@ -1,4 +1,5 @@
#include "..\e2daction.h"
#include "..\e2dnode.h"
e2d::MoveBy::MoveBy(double duration, Vector vector)

View File

@ -1,4 +1,5 @@
#include "..\e2daction.h"
#include "..\e2dnode.h"
e2d::MoveTo::MoveTo(double duration, Point pos)
: MoveBy(duration, Vector())

View File

@ -1,4 +1,5 @@
#include "..\e2daction.h"
#include "..\e2dnode.h"
e2d::OpacityBy::OpacityBy(double duration, double opacity)

View File

@ -1,4 +1,5 @@
#include "..\e2daction.h"
#include "..\e2dnode.h"
e2d::OpacityTo::OpacityTo(double duration, double opacity)

View File

@ -1,4 +1,5 @@
#include "..\e2daction.h"
#include "..\e2dnode.h"
e2d::RotateBy::RotateBy(double duration, double rotation)

View File

@ -1,4 +1,5 @@
#include "..\e2daction.h"
#include "..\e2dnode.h"
e2d::RotateTo::RotateTo(double duration, double rotation)

View File

@ -1,4 +1,5 @@
#include "..\e2daction.h"
#include "..\e2dnode.h"
e2d::ScaleBy::ScaleBy(double duration, double scale)

View File

@ -1,4 +1,5 @@
#include "..\e2daction.h"
#include "..\e2dnode.h"
e2d::ScaleTo::ScaleTo(double duration, double scale)
: ScaleBy(duration, 0, 0)

View File

@ -5,7 +5,7 @@
// 控制游戏终止
static bool s_bEndGame = false;
static bool s_bEndGame = true;
// 控制游戏暂停
static bool s_bPaused = false;
// 是否进行过初始化
@ -127,6 +127,8 @@ int e2d::Game::start(bool autoRelease/* true */)
// 初始化计时
Time::__init();
s_bEndGame = false;
while (!s_bEndGame)
{
// 处理窗口消息
@ -154,6 +156,8 @@ int e2d::Game::start(bool autoRelease/* true */)
}
}
s_bEndGame = true;
if (autoRelease)
{
Game::destroy();
@ -178,12 +182,13 @@ void e2d::Game::resume()
void e2d::Game::reset()
{
// 刷新当前时间
if (s_bInitialized && !s_bEndGame)
{
Time::__reset();
// 重置动作和定时器
ActionManager::__resetAll();
Timer::__resetAll();
}
}
bool e2d::Game::isPaused()
{

View File

@ -4,13 +4,11 @@
typedef std::pair<UINT, UINT> HashPair;
// 监听器容器
static std::vector<e2d::Listener*> s_vListeners;
// 碰撞触发状态
static bool s_bCollisionEnable = false;
static e2d::Node * s_pActiveNode = nullptr;
static e2d::Node * s_pPassiveNode = nullptr;
static std::set<HashPair> s_sCollisionList;
static std::vector<e2d::Listener*> s_vListeners; // 监听器容器
static bool s_bCollisionEnable = false; // 碰撞触发状态
static e2d::Node * s_pActiveNode = nullptr; // 主动碰撞体
static e2d::Node * s_pPassiveNode = nullptr; // 被动碰撞体
static std::set<HashPair> s_sCollisionList; // 碰撞映射
void e2d::Collision::addName(const String & name1, const String & name2)

View File

@ -15,7 +15,7 @@ e2d::Scene::Scene()
}
else
{
// TODO: 抛出一个异常
throw Exception(L"场景根节点构造失败!");
}
}

37
core/Custom/Exception.cpp Normal file
View File

@ -0,0 +1,37 @@
#include "..\e2dcustom.h"
e2d::Exception::Exception()
: _message()
{
}
e2d::Exception::Exception(String message)
: _message(message)
{
}
e2d::Exception::Exception(Exception const& other)
: _message(other._message)
{
}
e2d::Exception& e2d::Exception::operator=(Exception const& other)
{
if (this == &other)
{
return *this;
}
_message = other._message;
return *this;
}
e2d::Exception::~Exception()
{
}
e2d::String e2d::Exception::msg() const
{
return _message;
}

View File

@ -1,5 +1,6 @@
#include "..\e2dmanager.h"
#include "..\e2daction.h"
#include "..\e2dnode.h"
static std::vector<e2d::Action*> s_vActions;
static std::vector<e2d::Action*> s_vRunningActions;

View File

@ -596,13 +596,17 @@ void e2d::Node::addChild(Node * child, int order /* = 0 */)
if (child)
{
// TODO: 抛出一个异常
ASSERT(child->_parent == nullptr, "Node already added. It can't be added again!");
if (child->_parent != nullptr)
{
throw Exception(L"节点已有父节点, 不能再添加到其他节点!");
}
for (Node * parent = this; parent != nullptr; parent = parent->getParent())
{
// TODO: 抛出一个异常
ASSERT(child != parent, "A Node cannot be the child of his own children!");
if (child == parent)
{
throw Exception(L"一个节点不能同时是另一个节点的父节点和子节点!");
}
}
_children.push_back(child);

View File

@ -1,24 +1,26 @@
#pragma once
#include "e2dnode.h"
#include "e2dcommon.h"
#include "e2dbase.h"
namespace e2d
{
class ActionManager;
class Node;
class Loop;
class Sequence;
class Spawn;
class ActionManager;
// 基础动作
class Action :
public Object
{
friend ActionManager;
friend Loop;
friend Sequence;
friend Spawn;
friend class ActionManager;
friend class Loop;
friend class Sequence;
friend class Spawn;
public:
Action();

View File

@ -51,7 +51,7 @@ public:
// 窗口控制
class Window
{
friend Game;
friend class Game;
public:
// 鼠标指针样式
@ -147,7 +147,7 @@ private:
// 时间控制
class Time
{
friend Game;
friend class Game;
public:
// 获取上一帧与当前帧的时间间隔(秒)
@ -188,7 +188,7 @@ class Listener;
// 输入控制
class Input
{
friend Game;
friend class Game;
public:
// 鼠标键值
@ -375,8 +375,8 @@ private:
// 渲染器
class Renderer
{
friend Game;
friend Window;
friend class Game;
friend class Window;
public:
// 获取背景色
@ -437,8 +437,8 @@ private:
// 垃圾回收装置
class GC
{
friend Game;
friend Object;
friend class Game;
friend class Object;
public:
// 创建可自动回收内存的对象

View File

@ -13,8 +13,8 @@ class ColliderManager;
// 碰撞事件
class Collision
{
friend Game;
friend ColliderManager;
friend class Game;
friend class ColliderManager;
public:
// 添加可互相碰撞物体的名称
@ -123,8 +123,8 @@ private:
class Collider :
public Object
{
friend ColliderManager;
friend Node;
friend class ColliderManager;
friend class Node;
public:
// 碰撞体类别

View File

@ -227,8 +227,8 @@ public:
String operator+ (const wchar_t *);
// ÓÑÔªÔËËã·û
friend String operator+ (const char *, const String &);
friend String operator+ (const wchar_t*, const String &);
friend class String operator+ (const char *, const String &);
friend class String operator+ (const wchar_t*, const String &);
// ÀàÐÍת»»²Ù×÷·û
operator const wchar_t* () const;
@ -260,11 +260,11 @@ public:
// ÆäËûÔËËã·û
wchar_t& operator[] (int);
friend std::ostream& operator<< (std::ostream &, const String &);
friend std::wostream& operator<< (std::wostream &, const String &);
friend class std::ostream& operator<< (std::ostream &, const String &);
friend class std::wostream& operator<< (std::wostream &, const String &);
friend std::istream& operator>> (std::istream &, String &);
friend std::wistream& operator>> (std::wistream &, String &);
friend class std::istream& operator>> (std::istream &, String &);
friend class std::wistream& operator>> (std::wistream &, String &);
private:
std::wstring _str;
@ -571,8 +571,8 @@ class Transition;
class Scene :
public Object
{
friend SceneManager;
friend Transition;
friend class SceneManager;
friend class Transition;
public:
Scene();

View File

@ -4,6 +4,8 @@
namespace e2d
{
template<class Interface>
inline void SafeRelease(Interface*& p)
{
@ -14,6 +16,7 @@ namespace e2d
}
}
class Music;
// ÒôÔ´»Øµ÷
@ -156,4 +159,27 @@ namespace e2d
ID2D1SolidColorBrush* pBrush_;
};
// 异常
class Exception
{
public:
Exception() throw();
explicit Exception(String message) throw();
Exception(Exception const& other) throw();
virtual ~Exception() throw();
Exception& operator=(Exception const& other) throw();
// 获取异常信息
virtual String msg() const;
private:
String _message;
};
}

View File

@ -19,8 +19,8 @@ class Transition;
// 场景管理器
class SceneManager
{
friend Game;
friend Renderer;
friend class Game;
friend class Renderer;
public:
// 切换场景
@ -65,9 +65,9 @@ private:
// 动作管理器
class ActionManager
{
friend Game;
friend Node;
friend Action;
friend class Game;
friend class Node;
friend class Action;
public:
// 执行动作
@ -154,8 +154,8 @@ private:
// 碰撞体管理器
class ColliderManager
{
friend Node;
friend Collider;
friend class Node;
friend class Collider;
private:
// 更新碰撞体

View File

@ -13,10 +13,10 @@ class ColliderManager;
class Node :
public Object
{
friend Scene;
friend Collider;
friend Transition;
friend ColliderManager;
friend class Scene;
friend class Collider;
friend class Transition;
friend class ColliderManager;
public:
// 节点属性

View File

@ -52,7 +52,7 @@ private:
class Music :
public Object
{
friend Game;
friend class Game;
public:
Music();
@ -162,7 +162,7 @@ protected:
// 音乐播放器
class Player
{
friend Game;
friend class Game;
public:
// 预加载音乐资源
@ -258,7 +258,7 @@ private:
// 定时器
class Timer
{
friend Game;
friend class Game;
public:
// 启动定时器(每帧执行一次)
@ -324,8 +324,8 @@ class Collision;
class Listener
: public Object
{
friend Input;
friend Collision;
friend class Input;
friend class Collision;
public:
Listener();
@ -447,7 +447,7 @@ public:
// 路径工具
class Path
{
friend Game;
friend class Game;
public:
// 获取数据的默认保存路径

View File

@ -12,7 +12,7 @@ class SceneManager;
class Transition :
public Object
{
friend SceneManager;
friend class SceneManager;
public:
Transition(double duration);

View File

@ -236,6 +236,7 @@
<ClCompile Include="..\..\core\Common\Size.cpp" />
<ClCompile Include="..\..\core\Common\String.cpp" />
<ClCompile Include="..\..\core\Common\Image.cpp" />
<ClCompile Include="..\..\core\Custom\Exception.cpp" />
<ClCompile Include="..\..\core\Custom\TextRenderer.cpp" />
<ClCompile Include="..\..\core\Custom\VoiceCallback.cpp" />
<ClCompile Include="..\..\core\Manager\ActionManager.cpp" />

View File

@ -237,6 +237,9 @@
<ClCompile Include="..\..\core\Common\Rect.cpp">
<Filter>Common</Filter>
</ClCompile>
<ClCompile Include="..\..\core\Custom\Exception.cpp">
<Filter>Custom</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\core\easy2d.h" />