diff --git a/core/actions/Animation.cpp b/core/actions/Animation.cpp index 97e1f3b8..4f18f472 100644 --- a/core/actions/Animation.cpp +++ b/core/actions/Animation.cpp @@ -57,7 +57,7 @@ void easy2d::Animation::SetInterval(float interval) void easy2d::Animation::Add(Image * frame) { - WARN_IF(frame == nullptr, "Animation::Add failed, frame Is nullptr."); + E2D_WARNING_IF(frame == nullptr, "Animation::Add failed, frame Is nullptr."); if (frame) { frames_.push_back(frame); diff --git a/core/actions/Loop.cpp b/core/actions/Loop.cpp index 774a6328..8b3efe73 100644 --- a/core/actions/Loop.cpp +++ b/core/actions/Loop.cpp @@ -25,7 +25,7 @@ easy2d::Loop::Loop(Action * action, int times /* = -1 */) , times_(0) , total_times_(times) { - WARN_IF(action == nullptr, "Loop NULL pointer exception!"); + E2D_WARNING_IF(action == nullptr, "Loop NULL pointer exception!"); if (action) { diff --git a/core/e2daction.h b/core/e2daction.h index 7e943447..5f898b49 100644 --- a/core/e2daction.h +++ b/core/e2daction.h @@ -188,7 +188,7 @@ namespace easy2d // 获取该动作的倒转 virtual MoveTo * Reverse() const override { - WARN("Reverse() not supported in MoveTo"); + E2D_WARNING("Reverse() not supported in MoveTo"); return nullptr; } @@ -257,7 +257,7 @@ namespace easy2d // 获取该动作的倒转 virtual JumpTo * Reverse() const override { - WARN("Reverse() not supported in JumpTo"); + E2D_WARNING("Reverse() not supported in JumpTo"); return nullptr; } @@ -333,7 +333,7 @@ namespace easy2d // 获取该动作的倒转 virtual ScaleTo * Reverse() const override { - WARN("Reverse() not supported in ScaleTo"); + E2D_WARNING("Reverse() not supported in ScaleTo"); return nullptr; } @@ -396,7 +396,7 @@ namespace easy2d // 获取该动作的倒转 virtual OpacityTo * Reverse() const override { - WARN("Reverse() not supported in OpacityTo"); + E2D_WARNING("Reverse() not supported in OpacityTo"); return nullptr; } @@ -488,7 +488,7 @@ namespace easy2d // 获取该动作的倒转 virtual RotateTo * Reverse() const override { - WARN("Reverse() not supported in RotateTo"); + E2D_WARNING("Reverse() not supported in RotateTo"); return nullptr; } diff --git a/core/e2dmacros.h b/core/e2dmacros.h index 3be7ea86..91f3de95 100644 --- a/core/e2dmacros.h +++ b/core/e2dmacros.h @@ -94,24 +94,6 @@ #endif -#ifndef WARN -# if defined( DEBUG ) || defined( _DEBUG ) -# define WARN(message, ...) do { fwprintf(stderr, L"Warning: " _CRT_WIDE(#message) L"\n", __VA_ARGS__); } while(0) -# else -# 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) -# else -# define WARN_IF(expression, message, ...) ((void)0) -# endif -#endif - - #if _MSC_VER >= 1800 # define E2D_OP_EXPLICIT explicit #else @@ -144,3 +126,59 @@ #ifdef min # undef min #endif + + +#ifdef UNICODE +# define OutputDebugStringEx OutputDebugStringExW +#else +# define OutputDebugStringEx OutputDebugStringExA +#endif + + +#ifndef E2D_WARNING +# if defined( DEBUG ) || defined( _DEBUG ) +# define E2D_WARNING(msg, ...) do { OutputDebugStringExW(L"Warning: " _CRT_WIDE(#msg) L"\n", __VA_ARGS__); } while(0) +# else +# define E2D_WARNING(msg, ...) ((void)0) +# endif +#endif + + +#ifndef E2D_WARNING_IF +# if defined( DEBUG ) || defined( _DEBUG ) +# define E2D_WARNING_IF(exp, msg, ...) do { if (exp) { OutputDebugStringExW(L"Warning: " _CRT_WIDE(#msg) L"\n", __VA_ARGS__); } } while(0) +# else +# define E2D_WARNING_IF(exp, msg, ...) ((void)0) +# endif +#endif + + +void OutputDebugStringExW(LPCWSTR pszOutput, ...) +{ + va_list args = NULL; + va_start(args, pszOutput); + + size_t nLen = _vscwprintf(pszOutput, args) + 1; + const wchar_t* psBuffer = new wchar_t[nLen]; + _vsnwprintf_s(psBuffer, nLen, nLen, pszOutput, args); + + va_end(args); + + OutputDebugStringW(psBuffer); + delete [] psBuffer; +} + +void OutputDebugStringExA(LPCSTR pszOutput, ...) +{ + va_list args = NULL; + va_start(args, pszOutput); + + size_t nLen = _vscprintf(pszOutput, args) + 1; + const char* psBuffer = new char[nLen]; + _vsnprintf_s(psBuffer, nLen, nLen, pszOutput, args); + + va_end(args); + + OutputDebugStringA(psBuffer); + delete [] psBuffer; +} diff --git a/core/modules/Game.cpp b/core/modules/Game.cpp index 395ba91d..7e7f48fe 100644 --- a/core/modules/Game.cpp +++ b/core/modules/Game.cpp @@ -151,13 +151,13 @@ void easy2d::Game::EnterScene(Scene * scene, Transition * transition) { if (scene == nullptr) { - WARN("Next scene is null pointer!"); + E2D_WARNING("Next scene is null pointer!"); return; } if (next_scene_ != nullptr) { - WARN("Scene is transitioning..."); + E2D_WARNING("Scene is transitioning..."); return; } @@ -393,7 +393,7 @@ easy2d::Rect easy2d::Game::Locate(int width, int height) height = static_cast(rect.bottom - rect.top); // 当输入的窗口大小比分辨率大时,给出警告 - WARN_IF(max_width < width || max_height < height, "The window Is larger than screen!"); + E2D_WARNING_IF(max_width < width || max_height < height, "The window Is larger than screen!"); width = std::min(width, max_width); height = std::min(height, max_height); diff --git a/core/objects/Image.cpp b/core/objects/Image.cpp index c74191e7..ec15f313 100644 --- a/core/objects/Image.cpp +++ b/core/objects/Image.cpp @@ -69,7 +69,7 @@ bool easy2d::Image::Load(const Resource& res) { if (!Image::CacheBitmap(res)) { - WARN("Load Image from file failed!"); + E2D_WARNING("Load Image from file failed!"); return false; } @@ -79,14 +79,14 @@ bool easy2d::Image::Load(const Resource& res) bool easy2d::Image::Load(const String & file_name) { - WARN_IF(file_name.IsEmpty(), "Image Load failed! Invalid file name."); + E2D_WARNING_IF(file_name.IsEmpty(), "Image Load failed! Invalid file name."); if (file_name.IsEmpty()) return false; if (!Image::CacheBitmap(file_name)) { - WARN("Load Image from file failed!"); + E2D_WARNING("Load Image from file failed!"); return false; } diff --git a/core/objects/Node.cpp b/core/objects/Node.cpp index 40ff9820..11a6fed0 100644 --- a/core/objects/Node.cpp +++ b/core/objects/Node.cpp @@ -595,7 +595,7 @@ void easy2d::Node::SetBorderColor(const Color & color) void easy2d::Node::AddChild(Node * child, int order) { - WARN_IF(child == nullptr, "Node::AddChild NULL pointer exception."); + E2D_WARNING_IF(child == nullptr, "Node::AddChild NULL pointer exception."); if (child) { @@ -699,7 +699,7 @@ void easy2d::Node::RemoveFromParent() bool easy2d::Node::RemoveChild(Node * child) { - WARN_IF(child == nullptr, "Node::RemoveChildren NULL pointer exception."); + E2D_WARNING_IF(child == nullptr, "Node::RemoveChildren NULL pointer exception."); if (children_.empty()) { @@ -766,7 +766,7 @@ void easy2d::Node::RemoveAllChildren() void easy2d::Node::RunAction(Action * action) { - WARN_IF(action == nullptr, "Action NULL pointer exception!"); + E2D_WARNING_IF(action == nullptr, "Action NULL pointer exception!"); if (action) { @@ -1041,7 +1041,7 @@ void easy2d::Node::SetVisible(bool value) void easy2d::Node::SetName(const String& name) { - WARN_IF(name.IsEmpty(), "Invalid Node name."); + E2D_WARNING_IF(name.IsEmpty(), "Invalid Node name."); if (!name.IsEmpty() && name_ != name) { diff --git a/core/objects/Text.cpp b/core/objects/Text.cpp index da0f28ef..972f702f 100644 --- a/core/objects/Text.cpp +++ b/core/objects/Text.cpp @@ -396,7 +396,7 @@ void easy2d::Text::CreateLayout() if (text_format_ == nullptr) { - WARN("Text::CreateLayout failed! text_format_ NULL pointer exception."); + E2D_WARNING("Text::CreateLayout failed! text_format_ NULL pointer exception."); return; } diff --git a/core/tools/Music.cpp b/core/tools/Music.cpp index eee9ab45..229a587e 100644 --- a/core/tools/Music.cpp +++ b/core/tools/Music.cpp @@ -24,13 +24,13 @@ inline bool TraceError(wchar_t* prompt) { - WARN("Music error: %s failed!", prompt); + E2D_WARNING("Music error: %s failed!", prompt); return false; } inline bool TraceError(wchar_t* prompt, HRESULT hr) { - WARN("Music error: %s (%#X)", prompt, hr); + E2D_WARNING("Music error: %s (%#X)", prompt, hr); return false; } @@ -339,7 +339,7 @@ bool easy2d::Music::Load(const easy2d::String & file_path) File music_file; if (!music_file.Open(file_path)) { - WARN("Music::Load error: File not found."); + E2D_WARNING("Music::Load error: File not found."); return false; } @@ -400,13 +400,13 @@ bool easy2d::Music::Play(int loop_count) { if (!opened_) { - WARN("Music::Play Failed: Music must be opened first!"); + E2D_WARNING("Music::Play Failed: Music must be opened first!"); return false; } if (voice_ == nullptr) { - WARN("Music::Play Failed: IXAudio2SourceVoice Null pointer exception!"); + E2D_WARNING("Music::Play Failed: IXAudio2SourceVoice Null pointer exception!"); return false; } diff --git a/core/utils/String.cpp b/core/utils/String.cpp index 0c7db0d1..7e948caf 100644 --- a/core/utils/String.cpp +++ b/core/utils/String.cpp @@ -483,13 +483,8 @@ int easy2d::String::Find(const String & str, int offset) const { size_t index; if ((index = string_.find(str.string_, size_t(offset))) == std::wstring::npos) - { return -1; - } - else - { - return static_cast(index); - } + return static_cast(index); } void easy2d::String::Clear()