change: WARN macros rename to E2D_WARNING & call OutputDebugString to output debug information.

This commit is contained in:
Nomango 2018-10-16 15:42:15 +08:00
parent 4ed453468d
commit 8b1137c131
10 changed files with 80 additions and 47 deletions

View File

@ -57,7 +57,7 @@ void easy2d::Animation::SetInterval(float interval)
void easy2d::Animation::Add(Image * frame) 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) if (frame)
{ {
frames_.push_back(frame); frames_.push_back(frame);

View File

@ -25,7 +25,7 @@ easy2d::Loop::Loop(Action * action, int times /* = -1 */)
, times_(0) , times_(0)
, total_times_(times) , total_times_(times)
{ {
WARN_IF(action == nullptr, "Loop NULL pointer exception!"); E2D_WARNING_IF(action == nullptr, "Loop NULL pointer exception!");
if (action) if (action)
{ {

View File

@ -188,7 +188,7 @@ namespace easy2d
// 获取该动作的倒转 // 获取该动作的倒转
virtual MoveTo * Reverse() const override virtual MoveTo * Reverse() const override
{ {
WARN("Reverse() not supported in MoveTo"); E2D_WARNING("Reverse() not supported in MoveTo");
return nullptr; return nullptr;
} }
@ -257,7 +257,7 @@ namespace easy2d
// 获取该动作的倒转 // 获取该动作的倒转
virtual JumpTo * Reverse() const override virtual JumpTo * Reverse() const override
{ {
WARN("Reverse() not supported in JumpTo"); E2D_WARNING("Reverse() not supported in JumpTo");
return nullptr; return nullptr;
} }
@ -333,7 +333,7 @@ namespace easy2d
// 获取该动作的倒转 // 获取该动作的倒转
virtual ScaleTo * Reverse() const override virtual ScaleTo * Reverse() const override
{ {
WARN("Reverse() not supported in ScaleTo"); E2D_WARNING("Reverse() not supported in ScaleTo");
return nullptr; return nullptr;
} }
@ -396,7 +396,7 @@ namespace easy2d
// 获取该动作的倒转 // 获取该动作的倒转
virtual OpacityTo * Reverse() const override virtual OpacityTo * Reverse() const override
{ {
WARN("Reverse() not supported in OpacityTo"); E2D_WARNING("Reverse() not supported in OpacityTo");
return nullptr; return nullptr;
} }
@ -488,7 +488,7 @@ namespace easy2d
// 获取该动作的倒转 // 获取该动作的倒转
virtual RotateTo * Reverse() const override virtual RotateTo * Reverse() const override
{ {
WARN("Reverse() not supported in RotateTo"); E2D_WARNING("Reverse() not supported in RotateTo");
return nullptr; return nullptr;
} }

View File

@ -94,24 +94,6 @@
#endif #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 #if _MSC_VER >= 1800
# define E2D_OP_EXPLICIT explicit # define E2D_OP_EXPLICIT explicit
#else #else
@ -144,3 +126,59 @@
#ifdef min #ifdef min
# undef min # undef min
#endif #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;
}

View File

@ -151,13 +151,13 @@ void easy2d::Game::EnterScene(Scene * scene, Transition * transition)
{ {
if (scene == nullptr) if (scene == nullptr)
{ {
WARN("Next scene is null pointer!"); E2D_WARNING("Next scene is null pointer!");
return; return;
} }
if (next_scene_ != nullptr) if (next_scene_ != nullptr)
{ {
WARN("Scene is transitioning..."); E2D_WARNING("Scene is transitioning...");
return; return;
} }
@ -393,7 +393,7 @@ easy2d::Rect easy2d::Game::Locate(int width, int height)
height = static_cast<int>(rect.bottom - rect.top); height = static_cast<int>(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); width = std::min(width, max_width);
height = std::min(height, max_height); height = std::min(height, max_height);

View File

@ -69,7 +69,7 @@ bool easy2d::Image::Load(const Resource& res)
{ {
if (!Image::CacheBitmap(res)) if (!Image::CacheBitmap(res))
{ {
WARN("Load Image from file failed!"); E2D_WARNING("Load Image from file failed!");
return false; return false;
} }
@ -79,14 +79,14 @@ bool easy2d::Image::Load(const Resource& res)
bool easy2d::Image::Load(const String & file_name) 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()) if (file_name.IsEmpty())
return false; return false;
if (!Image::CacheBitmap(file_name)) if (!Image::CacheBitmap(file_name))
{ {
WARN("Load Image from file failed!"); E2D_WARNING("Load Image from file failed!");
return false; return false;
} }

View File

@ -595,7 +595,7 @@ void easy2d::Node::SetBorderColor(const Color & color)
void easy2d::Node::AddChild(Node * child, int order) 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) if (child)
{ {
@ -699,7 +699,7 @@ void easy2d::Node::RemoveFromParent()
bool easy2d::Node::RemoveChild(Node * child) 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()) if (children_.empty())
{ {
@ -766,7 +766,7 @@ void easy2d::Node::RemoveAllChildren()
void easy2d::Node::RunAction(Action * action) 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) if (action)
{ {
@ -1041,7 +1041,7 @@ void easy2d::Node::SetVisible(bool value)
void easy2d::Node::SetName(const String& name) 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) if (!name.IsEmpty() && name_ != name)
{ {

View File

@ -396,7 +396,7 @@ void easy2d::Text::CreateLayout()
if (text_format_ == nullptr) if (text_format_ == nullptr)
{ {
WARN("Text::CreateLayout failed! text_format_ NULL pointer exception."); E2D_WARNING("Text::CreateLayout failed! text_format_ NULL pointer exception.");
return; return;
} }

View File

@ -24,13 +24,13 @@
inline bool TraceError(wchar_t* prompt) inline bool TraceError(wchar_t* prompt)
{ {
WARN("Music error: %s failed!", prompt); E2D_WARNING("Music error: %s failed!", prompt);
return false; return false;
} }
inline bool TraceError(wchar_t* prompt, HRESULT hr) 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; return false;
} }
@ -339,7 +339,7 @@ bool easy2d::Music::Load(const easy2d::String & file_path)
File music_file; File music_file;
if (!music_file.Open(file_path)) if (!music_file.Open(file_path))
{ {
WARN("Music::Load error: File not found."); E2D_WARNING("Music::Load error: File not found.");
return false; return false;
} }
@ -400,13 +400,13 @@ bool easy2d::Music::Play(int loop_count)
{ {
if (!opened_) if (!opened_)
{ {
WARN("Music::Play Failed: Music must be opened first!"); E2D_WARNING("Music::Play Failed: Music must be opened first!");
return false; return false;
} }
if (voice_ == nullptr) if (voice_ == nullptr)
{ {
WARN("Music::Play Failed: IXAudio2SourceVoice Null pointer exception!"); E2D_WARNING("Music::Play Failed: IXAudio2SourceVoice Null pointer exception!");
return false; return false;
} }

View File

@ -483,14 +483,9 @@ int easy2d::String::Find(const String & str, int offset) const
{ {
size_t index; size_t index;
if ((index = string_.find(str.string_, size_t(offset))) == std::wstring::npos) if ((index = string_.find(str.string_, size_t(offset))) == std::wstring::npos)
{
return -1; return -1;
}
else
{
return static_cast<int>(index); return static_cast<int>(index);
} }
}
void easy2d::String::Clear() void easy2d::String::Clear()
{ {