From 6af90623faa172ed5621f3600df56b8418337c43 Mon Sep 17 00:00:00 2001 From: Nomango <569629550@qq.com> Date: Thu, 24 May 2018 12:24:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0SystemException=EF=BC=8C?= =?UTF-8?q?=E7=A7=BB=E9=99=A4ASSERT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/Action/Animate.cpp | 17 +---- core/Action/Animation.cpp | 30 ++++++++- core/Action/Loop.cpp | 11 +++- core/Action/Sequence.cpp | 2 +- core/Action/Spawn.cpp | 2 +- core/Base/Game.cpp | 94 ++++++++++++++++----------- core/Base/Renderer.cpp | 45 ++++++++----- core/Common/Image.cpp | 4 +- core/Common/Scene.cpp | 2 +- core/Custom/Exception.cpp | 10 +-- core/Custom/SystemException.cpp | 12 ++++ core/Manager/ActionManager.cpp | 22 +++++-- core/Manager/ColliderManager.cpp | 2 +- core/Manager/SceneManager.cpp | 7 +- core/Node/Node.cpp | 14 +--- core/Node/Text.cpp | 19 ++++-- core/Tool/Music.cpp | 24 +++---- core/Tool/Path.cpp | 4 +- core/Transition/Transition.cpp | 2 +- core/e2daction.h | 17 +++-- core/e2dbase.h | 2 +- core/e2dcustom.h | 14 +++- core/e2dmacros.h | 9 +-- project/vs2017/Easy2D.vcxproj | 1 + project/vs2017/Easy2D.vcxproj.filters | 3 + 25 files changed, 228 insertions(+), 141 deletions(-) create mode 100644 core/Custom/SystemException.cpp diff --git a/core/Action/Animate.cpp b/core/Action/Animate.cpp index 00eb8843..a369fb54 100644 --- a/core/Action/Animate.cpp +++ b/core/Action/Animate.cpp @@ -107,22 +107,7 @@ e2d::Animate * e2d::Animate::reverse() const { if (_animation) { - auto& oldFrames = _animation->getFrames(); - std::vector frames(oldFrames.size()); - - if (!oldFrames.empty()) - { - for (auto iter = oldFrames.crbegin(), iterCrend = oldFrames.crend(); iter != iterCrend; ++iter) - { - Image* frame = *iter; - if (frame) - { - frames.push_back(frame); - } - } - } - - auto animation = GC::create(_animation->getInterval(), frames); + auto animation = _animation->reverse(); if (animation) { return GC::create(animation); diff --git a/core/Action/Animation.cpp b/core/Action/Animation.cpp index 6bf1cb40..7debbf99 100644 --- a/core/Action/Animation.cpp +++ b/core/Action/Animation.cpp @@ -69,9 +69,35 @@ const std::vector& e2d::Animation::getFrames() const e2d::Animation * e2d::Animation::clone() const { auto animation = GC::create(_interval); - for (auto frame : _frames) + if (animation) { - animation->add(frame); + for (auto frame : _frames) + { + animation->add(frame); + } } return animation; } + +e2d::Animation * e2d::Animation::reverse() const +{ + auto& oldFrames = this->getFrames(); + std::vector frames(oldFrames.size()); + + if (!oldFrames.empty()) + { + for (auto iter = oldFrames.crbegin(), + iterCrend = oldFrames.crend(); + iter != iterCrend; + ++iter) + { + Image* frame = *iter; + if (frame) + { + frames.push_back(frame); + } + } + } + + return GC::create(this->getInterval(), frames); +} diff --git a/core/Action/Loop.cpp b/core/Action/Loop.cpp index 7c7219f7..27633c7c 100644 --- a/core/Action/Loop.cpp +++ b/core/Action/Loop.cpp @@ -6,7 +6,7 @@ e2d::Loop::Loop(Action * action, int times /* = -1 */) , _times(0) , _totalTimes(times) { - ASSERT(action, "Loop NULL pointer exception!"); + WARN_IF(action == nullptr, "Loop NULL pointer exception!"); if (action) { @@ -33,7 +33,14 @@ e2d::Loop * e2d::Loop::clone() const e2d::Loop * e2d::Loop::reverse() const { - return GC::create(_action); + if (_action) + { + return GC::create(_action->clone()); + } + else + { + return nullptr; + } } void e2d::Loop::_init() diff --git a/core/Action/Sequence.cpp b/core/Action/Sequence.cpp index f002e635..33aceab6 100644 --- a/core/Action/Sequence.cpp +++ b/core/Action/Sequence.cpp @@ -111,7 +111,7 @@ e2d::Sequence * e2d::Sequence::clone() const e2d::Sequence * e2d::Sequence::reverse() const { auto sequence = GC::create(); - if (!_actions.empty()) + if (sequence && !_actions.empty()) { std::vector newActions(_actions.size()); for (auto iter = _actions.crbegin(), iterCrend = _actions.crend(); iter != iterCrend; ++iter) diff --git a/core/Action/Spawn.cpp b/core/Action/Spawn.cpp index 64b9d3ab..79b28f6b 100644 --- a/core/Action/Spawn.cpp +++ b/core/Action/Spawn.cpp @@ -109,7 +109,7 @@ e2d::Spawn * e2d::Spawn::clone() const e2d::Spawn * e2d::Spawn::reverse() const { auto spawn = GC::create(); - if (!_actions.empty()) + if (spawn && !_actions.empty()) { std::vector newActions(_actions.size()); for (auto iter = _actions.crbegin(), iterCrend = _actions.crend(); iter != iterCrend; ++iter) diff --git a/core/Base/Game.cpp b/core/Base/Game.cpp index 07914e0a..9faf9e28 100644 --- a/core/Base/Game.cpp +++ b/core/Base/Game.cpp @@ -18,7 +18,7 @@ bool e2d::Game::init(const String& name, const String& mutexName) { if (s_bInitialized) { - WARN_IF(true, "The game has been initialized!"); + WARN("The game has been initialized!"); return false; } @@ -29,7 +29,7 @@ bool e2d::Game::init(const String& name, const String& mutexName) if (hMutex == nullptr) { - WARN_IF(true, "CreateMutex Failed!"); + WARN("CreateMutex Failed!"); } else if (::GetLastError() == ERROR_ALREADY_EXISTS) { @@ -44,39 +44,74 @@ bool e2d::Game::init(const String& name, const String& mutexName) // 初始化 COM 组件 CoInitialize(nullptr); - // 创建设备无关资源 - if (!Renderer::__createDeviceIndependentResources()) + bool bRendererDevIndResInit = false, + bWindowInit = false, + bRendererDevResInit = false, + bInputInit = false, + bMusicInit = false; + + auto DestroyResources = [&]() { - WARN_IF(true, "Renderer::__createDeviceIndependentResources Failed!"); - goto dev_ind_res_fail; + if (bRendererDevIndResInit) Renderer::__discardResources(); + if (bWindowInit) Window::__init(); + if (bRendererDevResInit) Renderer::__discardDeviceResources(); + if (bInputInit) Input::__uninit(); + if (bMusicInit) Music::__uninit(); + }; + + // 创建设备无关资源 + if (Renderer::__createDeviceIndependentResources()) + { + bRendererDevIndResInit = true; + } + else + { + DestroyResources(); + throw SystemException(L"渲染器设备无关资源创建失败"); } // 初始化窗口 - if (!Window::__init()) + if (Window::__init()) { - WARN_IF(true, "Window::__init Failed!"); - goto window_fail; + bWindowInit = true; + } + else + { + DestroyResources(); + throw SystemException(L"初始化窗口失败"); } // 创建设备相关资源 - if (!Renderer::__createDeviceResources()) + if (Renderer::__createDeviceResources()) { - WARN_IF(true, "Renderer::__createDeviceResources Failed!"); - goto dev_res_fail; + bRendererDevResInit = true; + } + else + { + DestroyResources(); + throw SystemException(L"渲染器设备相关资源创建失败"); } // 初始化 DirectInput - if (!Input::__init()) + if (Input::__init()) { - WARN_IF(true, "Input::__init Failed!"); - goto input_fail; + bInputInit = true; + } + else + { + DestroyResources(); + throw SystemException(L"初始化 DirectInput 失败"); } // 初始化播放器 - if (!Music::__init()) + if (Music::__init()) { - WARN_IF(true, "Music::__init Failed!"); - Music::__uninit(); + bMusicInit = true; + } + else + { + DestroyResources(); + throw SystemException(L"初始化 XAudio2 失败"); } // 保存游戏名称 @@ -85,35 +120,20 @@ bool e2d::Game::init(const String& name, const String& mutexName) // 初始化路径 if (!Path::__init()) { - WARN_IF(true, "Path::__init Failed!"); + WARN("Path::__init failed!"); } // 初始化成功 s_bInitialized = true; - goto succeeded; -input_fail: - Input::__uninit(); - -dev_res_fail: - Renderer::__discardDeviceResources(); - -window_fail: - Window::__init(); - -dev_ind_res_fail: - Renderer::__discardResources(); - -succeeded: return s_bInitialized; } -int e2d::Game::start(bool autoRelease/* true */) +void e2d::Game::start(bool autoRelease/* true */) { if (!s_bInitialized) { - ASSERT(false, "You must initialize Game first!"); - return -1; + throw Exception(L"开始游戏前未进行初始化"); } // 初始化场景管理器 @@ -162,8 +182,6 @@ int e2d::Game::start(bool autoRelease/* true */) { Game::destroy(); } - - return 0; } void e2d::Game::pause() diff --git a/core/Base/Renderer.cpp b/core/Base/Renderer.cpp index 9d4ac430..20ba0001 100644 --- a/core/Base/Renderer.cpp +++ b/core/Base/Renderer.cpp @@ -23,9 +23,11 @@ bool e2d::Renderer::__createDeviceIndependentResources() &s_pDirect2dFactory ); - ASSERT(SUCCEEDED(hr), "Create ID2D1Factory Failed!"); - - if (SUCCEEDED(hr)) + if (FAILED(hr)) + { + throw SystemException(L"Create ID2D1Factory failed"); + } + else { // 创建 WIC 绘图工厂,用于统一处理各种格式的图片 hr = CoCreateInstance( @@ -35,10 +37,13 @@ bool e2d::Renderer::__createDeviceIndependentResources() IID_IWICImagingFactory, reinterpret_cast(&s_pIWICFactory) ); - ASSERT(SUCCEEDED(hr), "Create IWICImagingFactory Failed!"); } - if (SUCCEEDED(hr)) + if (FAILED(hr)) + { + throw SystemException(L"Create IWICImagingFactory failed"); + } + else { // 创建 DirectWrite 工厂 hr = DWriteCreateFactory( @@ -46,17 +51,17 @@ bool e2d::Renderer::__createDeviceIndependentResources() __uuidof(IDWriteFactory), reinterpret_cast(&s_pDWriteFactory) ); - ASSERT(SUCCEEDED(hr), "Create IDWriteFactory Failed!"); } - if (SUCCEEDED(hr)) + if (FAILED(hr)) + { + throw SystemException(L"Create IDWriteFactory failed"); + } + else { // 工厂将返回当前的系统 DPI,这个值也将用来创建窗口 Renderer::getID2D1Factory()->GetDesktopDpi(&s_fDpiScaleX, &s_fDpiScaleY); - } - if (SUCCEEDED(hr)) - { // 创建文本格式化对象 hr = s_pDWriteFactory->CreateTextFormat( L"", @@ -105,19 +110,24 @@ bool e2d::Renderer::__createDeviceResources() &s_pRenderTarget ); - ASSERT(SUCCEEDED(hr), "Create ID2D1HwndRenderTarget Failed!"); - - if (SUCCEEDED(hr)) + if (FAILED(hr)) + { + throw SystemException(L"Create ID2D1HwndRenderTarget failed"); + } + else { // 创建画刷 hr = s_pRenderTarget->CreateSolidColorBrush( D2D1::ColorF(D2D1::ColorF::White), &s_pSolidBrush ); - ASSERT(SUCCEEDED(hr), "Create ID2D1SolidColorBrush Failed!"); } - if (SUCCEEDED(hr)) + if (FAILED(hr)) + { + throw SystemException(L"Create ID2D1SolidColorBrush failed"); + } + else { // 创建自定义的文字渲染器 s_pTextRenderer = new (std::nothrow) TextRenderer( @@ -165,7 +175,7 @@ void e2d::Renderer::__render() SceneManager::__render(); // 渲染 FPS - if (s_bShowFps) + if (s_bShowFps && s_pTextFormat) { static int s_nRenderTimes = 0; static double s_fLastRenderTime = 0; @@ -223,8 +233,7 @@ void e2d::Renderer::__render() if (FAILED(hr)) { - Window::error(L"Device loss recovery failed. Exiting game."); - Game::quit(); + throw SystemException(L"Device loss recovery failed"); } } diff --git a/core/Common/Image.cpp b/core/Common/Image.cpp index 0c101835..0cea0147 100644 --- a/core/Common/Image.cpp +++ b/core/Common/Image.cpp @@ -56,7 +56,7 @@ bool e2d::Image::open(const String& filePath) if (!Image::preload(filePath)) { - WARN_IF(true, "Load Image from file failed!"); + WARN("Load Image from file failed!"); return false; } @@ -68,7 +68,7 @@ bool e2d::Image::open(int resNameId, const String& resType) { if (!Image::preload(resNameId, resType)) { - WARN_IF(true, "Load Image from file failed!"); + WARN("Load Image from file failed!"); return false; } diff --git a/core/Common/Scene.cpp b/core/Common/Scene.cpp index 02f5d8ac..36b7f45f 100644 --- a/core/Common/Scene.cpp +++ b/core/Common/Scene.cpp @@ -15,7 +15,7 @@ e2d::Scene::Scene() } else { - throw Exception(L"场景根节点构造失败!"); + throw Exception(L"场景根节点构造失败"); } } diff --git a/core/Custom/Exception.cpp b/core/Custom/Exception.cpp index d3a579de..356cbe6a 100644 --- a/core/Custom/Exception.cpp +++ b/core/Custom/Exception.cpp @@ -1,22 +1,22 @@ #include "..\e2dcustom.h" -e2d::Exception::Exception() +e2d::Exception::Exception() throw() : _message() { } -e2d::Exception::Exception(String message) +e2d::Exception::Exception(const String& message) throw() : _message(message) { } -e2d::Exception::Exception(Exception const& other) +e2d::Exception::Exception(Exception const& other) throw() : _message(other._message) { } -e2d::Exception& e2d::Exception::operator=(Exception const& other) +e2d::Exception& e2d::Exception::operator=(Exception const& other) throw() { if (this == &other) { @@ -27,7 +27,7 @@ e2d::Exception& e2d::Exception::operator=(Exception const& other) return *this; } -e2d::Exception::~Exception() +e2d::Exception::~Exception() throw() { } diff --git a/core/Custom/SystemException.cpp b/core/Custom/SystemException.cpp new file mode 100644 index 00000000..fb3a7263 --- /dev/null +++ b/core/Custom/SystemException.cpp @@ -0,0 +1,12 @@ +#include "..\e2dcustom.h" + +e2d::SystemException::SystemException() throw() + : Exception(L"未知的系统异常") +{ +} + +e2d::SystemException::SystemException(const String& message) throw() + : Exception(message) +{ +} + diff --git a/core/Manager/ActionManager.cpp b/core/Manager/ActionManager.cpp index 550c88e6..b0d09b9e 100644 --- a/core/Manager/ActionManager.cpp +++ b/core/Manager/ActionManager.cpp @@ -103,13 +103,21 @@ void e2d::ActionManager::start(Action * action, Node * target, bool paused) if (action && target) { - auto iter = std::find(s_vRunningActions.begin(), s_vRunningActions.end(), action); - ASSERT(iter == s_vRunningActions.end(), "Action has begun!"); - - action->_startWithTarget(target); - action->retain(); - action->_running = !paused; - s_vRunningActions.push_back(action); + if (action->_target == nullptr) + { + auto iter = std::find(s_vRunningActions.begin(), s_vRunningActions.end(), action); + if (iter == s_vRunningActions.end()) + { + action->_startWithTarget(target); + action->retain(); + action->_running = !paused; + s_vRunningActions.push_back(action); + } + } + else + { + throw Exception(L"该 Action 已有执行目标"); + } } } diff --git a/core/Manager/ColliderManager.cpp b/core/Manager/ColliderManager.cpp index 9cda287d..25b7a4fd 100644 --- a/core/Manager/ColliderManager.cpp +++ b/core/Manager/ColliderManager.cpp @@ -56,7 +56,7 @@ void e2d::ColliderManager::__addCollider(Collider * pCollider) { if (pCollider->_parentNode) { - WARN_IF(true, "ColliderManager::__add Failed! The shape is already added."); + WARN("ColliderManager::__add Failed! The shape is already added."); return; } pCollider->retain(); diff --git a/core/Manager/SceneManager.cpp b/core/Manager/SceneManager.cpp index 2a2c2e02..1eb6f2f8 100644 --- a/core/Manager/SceneManager.cpp +++ b/core/Manager/SceneManager.cpp @@ -10,11 +10,14 @@ static std::stack s_SceneStack; void e2d::SceneManager::enter(Scene * scene, Transition * transition /* = nullptr */, bool saveCurrentScene /* = true */) { - ASSERT(scene, "Next scene NULL pointer exception!"); - scene->retain(); + if (scene == nullptr) + { + throw Exception(L"场景空指针异常"); + } // 保存下一场景的指针 s_pNextScene = scene; + s_pNextScene->retain(); // 设置切换场景动作 if (transition) diff --git a/core/Node/Node.cpp b/core/Node/Node.cpp index a90fab62..923a88d4 100644 --- a/core/Node/Node.cpp +++ b/core/Node/Node.cpp @@ -598,14 +598,14 @@ void e2d::Node::addChild(Node * child, int order /* = 0 */) { if (child->_parent != nullptr) { - throw Exception(L"节点已有父节点, 不能再添加到其他节点!"); + throw Exception(L"节点已有父节点, 不能再添加到其他节点"); } for (Node * parent = this; parent != nullptr; parent = parent->getParent()) { if (child == parent) { - throw Exception(L"一个节点不能同时是另一个节点的父节点和子节点!"); + throw Exception(L"一个节点不能同时是另一个节点的父节点和子节点"); } } @@ -769,15 +769,7 @@ void e2d::Node::clearAllChildren() void e2d::Node::runAction(Action * action) { - if (this != action->getTarget()) - { - ASSERT(action->getTarget() == nullptr, "The action has already got a target!"); - ActionManager::start(action, this, false); - } - else - { - action->reset(); - } + ActionManager::start(action, this, false); } void e2d::Node::resumeAction(const String& name) diff --git a/core/Node/Text.cpp b/core/Node/Text.cpp index 9ad86d95..4945dead 100644 --- a/core/Node/Text.cpp +++ b/core/Node/Text.cpp @@ -331,9 +331,13 @@ void e2d::Text::_createFormat() &_textFormat ); - ASSERT(SUCCEEDED(hr), "Create IDWriteTextFormat Failed!"); - - if (_textFormat) + if (FAILED(hr)) + { + WARN("Text::_createFormat error : Create IDWriteTextFormat failed!"); + _textFormat = nullptr; + return; + } + else { // 设置文字对齐方式 _textFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT(_style.alignment)); @@ -375,7 +379,7 @@ void e2d::Text::_createLayout() if (_textFormat == nullptr) { - WARN_IF(true, "Text::_createLayout failed! _textFormat NULL pointer exception."); + WARN("Text::_createLayout failed! _textFormat NULL pointer exception."); return; } @@ -420,7 +424,12 @@ void e2d::Text::_createLayout() } } - ASSERT(SUCCEEDED(hr), "Create IDWriteTextFormat Failed!"); + if (FAILED(hr)) + { + WARN("Text::_createLayout error : Create IDWriteTextLayout failed!"); + _textLayout = nullptr; + return; + } // 添加下划线和删除线 DWRITE_TEXT_RANGE range = { 0, length }; diff --git a/core/Tool/Music.cpp b/core/Tool/Music.cpp index 8bba4458..c0ababb6 100644 --- a/core/Tool/Music.cpp +++ b/core/Tool/Music.cpp @@ -10,13 +10,13 @@ inline bool TraceError(wchar_t* sPrompt) { - WARN_IF(true, "MusicInfo error: %s failed!", sPrompt); + WARN("MusicInfo error: %s failed!", sPrompt); return false; } inline bool TraceError(wchar_t* sPrompt, HRESULT hr) { - WARN_IF(true, "MusicInfo error: %s (%#X)", sPrompt, hr); + WARN("MusicInfo error: %s (%#X)", sPrompt, hr); return false; } @@ -75,19 +75,19 @@ bool e2d::Music::open(const e2d::String& filePath) { if (_opened) { - WARN_IF(true, "MusicInfo can be opened only once!"); + WARN("MusicInfo can be opened only once!"); return false; } if (filePath.isEmpty()) { - WARN_IF(true, "MusicInfo::open Invalid file name."); + WARN("MusicInfo::open Invalid file name."); return false; } if (!s_pXAudio2) { - WARN_IF(true, "IXAudio2 nullptr pointer error!"); + WARN("IXAudio2 nullptr pointer error!"); return false; } @@ -95,7 +95,7 @@ bool e2d::Music::open(const e2d::String& filePath) wchar_t pFilePath[MAX_PATH]; if (!_findMediaFileCch(pFilePath, MAX_PATH, filePath)) { - WARN_IF(true, "Failed to find media file: %s", pFilePath); + WARN("Failed to find media file: %s", pFilePath); return false; } @@ -152,13 +152,13 @@ bool e2d::Music::open(int resNameId, const e2d::String& resType) if (_opened) { - WARN_IF(true, "MusicInfo can be opened only once!"); + WARN("MusicInfo can be opened only once!"); return false; } if (!s_pXAudio2) { - WARN_IF(true, "IXAudio2 nullptr pointer error!"); + WARN("IXAudio2 nullptr pointer error!"); return false; } @@ -226,13 +226,13 @@ bool e2d::Music::play(int nLoopCount) { if (!_opened) { - WARN_IF(true, "MusicInfo::play Failed: MusicInfo must be opened first!"); + WARN("MusicInfo::play Failed: MusicInfo must be opened first!"); return false; } if (_voice == nullptr) { - WARN_IF(true, "MusicInfo::play Failed: IXAudio2SourceVoice Null pointer exception!"); + WARN("MusicInfo::play Failed: IXAudio2SourceVoice Null pointer exception!"); return false; } @@ -584,13 +584,13 @@ bool e2d::Music::__init() if (FAILED(hr = XAudio2Create(&s_pXAudio2, 0))) { - WARN_IF(true, "Failed to init XAudio2 engine"); + WARN("Failed to init XAudio2 engine"); return false; } if (FAILED(hr = s_pXAudio2->CreateMasteringVoice(&s_pMasteringVoice))) { - WARN_IF(true, "Failed creating mastering voice"); + WARN("Failed creating mastering voice"); e2d::SafeRelease(s_pXAudio2); return false; } diff --git a/core/Tool/Path.cpp b/core/Tool/Path.cpp index d05731aa..27cd8434 100644 --- a/core/Tool/Path.cpp +++ b/core/Tool/Path.cpp @@ -30,7 +30,7 @@ bool e2d::Path::__init() } else { - WARN_IF(true, "Cannot get local AppData path!"); + WARN("Cannot get local AppData path!"); } // 获取游戏名称 @@ -173,7 +173,7 @@ bool e2d::Path::createFolder(const String& dirPath) { if (dirPath.isEmpty()) { - WARN_IF(true, "Path::createFolder Failed: Invalid directory path!"); + WARN("Path::createFolder Failed: Invalid directory path!"); return false; } diff --git a/core/Transition/Transition.cpp b/core/Transition/Transition.cpp index bd3298af..c8e6059d 100644 --- a/core/Transition/Transition.cpp +++ b/core/Transition/Transition.cpp @@ -45,7 +45,7 @@ void e2d::Transition::_init(Scene * prev, Scene * next) if (FAILED(hr)) { - ASSERT(false, "Create layer failed!"); + throw SystemException(L"场景过渡动画图层创建失败"); } _last = Time::getTotalTime(); diff --git a/core/e2daction.h b/core/e2daction.h index 802ef953..df748ebb 100644 --- a/core/e2daction.h +++ b/core/e2daction.h @@ -164,7 +164,7 @@ public: // 获取该动作的倒转 virtual MoveTo * reverse() const override { - ASSERT(false, "reverse() not supported in MoveTo"); + WARN("reverse() not supported in MoveTo"); return nullptr; } @@ -229,7 +229,7 @@ public: // 获取该动作的倒转 virtual JumpTo * reverse() const override { - ASSERT(false, "reverse() not supported in JumpTo"); + WARN("reverse() not supported in JumpTo"); return nullptr; } @@ -301,7 +301,7 @@ public: // 获取该动作的倒转 virtual ScaleTo * reverse() const override { - ASSERT(false, "reverse() not supported in ScaleTo"); + WARN("reverse() not supported in ScaleTo"); return nullptr; } @@ -360,7 +360,7 @@ public: // 获取该动作的倒转 virtual OpacityTo * reverse() const override { - ASSERT(false, "reverse() not supported in OpacityTo"); + WARN("reverse() not supported in OpacityTo"); return nullptr; } @@ -448,7 +448,7 @@ public: // 获取该动作的倒转 virtual RotateTo * reverse() const override { - ASSERT(false, "reverse() not supported in RotateTo"); + WARN("reverse() not supported in RotateTo"); return nullptr; } @@ -707,8 +707,11 @@ public: double interval /* 帧间隔(秒) */ ); - // 获取动画的拷贝对象 - virtual Animation * clone() const; + // 获取帧动画的拷贝对象 + Animation * clone() const; + + // 获取帧动画的倒转 + Animation * reverse() const; // 销毁对象 virtual void onDestroy() override; diff --git a/core/e2dbase.h b/core/e2dbase.h index ce2bf3c2..3a841692 100644 --- a/core/e2dbase.h +++ b/core/e2dbase.h @@ -21,7 +21,7 @@ public: ); // 启动游戏 - static int start( + static void start( bool autoRelease = true /* 游戏结束时自动回收资源 */ ); diff --git a/core/e2dcustom.h b/core/e2dcustom.h index 717c6ff2..65353d8e 100644 --- a/core/e2dcustom.h +++ b/core/e2dcustom.h @@ -164,10 +164,9 @@ private: class Exception { public: - Exception() throw(); - explicit Exception(String message) throw(); + explicit Exception(const String& message) throw(); Exception(Exception const& other) throw(); @@ -182,4 +181,15 @@ private: String _message; }; + +// 系统异常 +class SystemException + : public Exception +{ +public: + SystemException() throw(); + + explicit SystemException(const String& message) throw(); +}; + } \ No newline at end of file diff --git a/core/e2dmacros.h b/core/e2dmacros.h index dedf4f03..98b9cc7e 100644 --- a/core/e2dmacros.h +++ b/core/e2dmacros.h @@ -61,17 +61,18 @@ EXTERN_C IMAGE_DOS_HEADER __ImageBase; #endif -#ifndef ASSERT +#ifndef WARN #if defined( DEBUG ) || defined( _DEBUG ) - #define ASSERT(expression, message, ...) do {if (!(expression)) { fwprintf(stderr, L"Assert: " _CRT_WIDE(#message) L"\n", __VA_ARGS__); abort(); }} while(0) +#define WARN(message, ...) do { fwprintf(stderr, L"Warning: " _CRT_WIDE(#message) L"\n", __VA_ARGS__); } while(0) #else - #define ASSERT(expression, message, ...) ((void)0) +#define WARN(message, ...) ((void)0) #endif #endif + #ifndef WARN_IF #if defined( DEBUG ) || defined( _DEBUG ) - #define WARN_IF(expression, message, ...) do {if (expression) { fwprintf(stderr, L"Warning: " _CRT_WIDE(#message) L"\n", __VA_ARGS__); }} while(0) + #define WARN_IF(expression, message, ...) do { if (expression) { fwprintf(stderr, L"Warning: " _CRT_WIDE(#message) L"\n", __VA_ARGS__); } } while(0) #else #define WARN_IF(expression, message, ...) ((void)0) #endif diff --git a/project/vs2017/Easy2D.vcxproj b/project/vs2017/Easy2D.vcxproj index d8e346ac..1e4938ba 100644 --- a/project/vs2017/Easy2D.vcxproj +++ b/project/vs2017/Easy2D.vcxproj @@ -237,6 +237,7 @@ + diff --git a/project/vs2017/Easy2D.vcxproj.filters b/project/vs2017/Easy2D.vcxproj.filters index 738c27b9..5ac3c2a8 100644 --- a/project/vs2017/Easy2D.vcxproj.filters +++ b/project/vs2017/Easy2D.vcxproj.filters @@ -240,6 +240,9 @@ Custom + + Custom +