diff --git a/project/Easy2D/Easy2D.vcxproj b/project/Easy2D/Easy2D.vcxproj index 50697a0b..b41ebb48 100644 --- a/project/Easy2D/Easy2D.vcxproj +++ b/project/Easy2D/Easy2D.vcxproj @@ -12,6 +12,7 @@ + @@ -182,22 +183,18 @@ $(ProjectDir)$(Configuration)\ $(ProjectDir)$(Configuration)\ - easy2dd $(ProjectDir)$(Configuration)\ $(ProjectDir)$(Configuration)\ - easy2dd $(ProjectDir)$(Configuration)\ $(ProjectDir)$(Configuration)\ - easy2d $(ProjectDir)$(Configuration)\ $(ProjectDir)$(Configuration)\ - easy2d diff --git a/project/Easy2D/Easy2D.vcxproj.filters b/project/Easy2D/Easy2D.vcxproj.filters index 31e88199..4b16cae8 100644 --- a/project/Easy2D/Easy2D.vcxproj.filters +++ b/project/Easy2D/Easy2D.vcxproj.filters @@ -220,6 +220,9 @@ core + + core + diff --git a/src/core/ActionTween.h b/src/core/ActionTween.h index 26c64a07..5a543534 100644 --- a/src/core/ActionTween.h +++ b/src/core/ActionTween.h @@ -158,7 +158,7 @@ namespace easy2d // 获取该动作的倒转 virtual ActionPtr Reverse() const override { - logs::Errorln(L"Reverse() not supported in MoveTo"); + E2D_ERROR_LOG(L"Reverse() not supported in MoveTo"); return nullptr; } @@ -222,7 +222,7 @@ namespace easy2d // 获取该动作的倒转 virtual ActionPtr Reverse() const override { - logs::Errorln(L"Reverse() not supported in JumpTo"); + E2D_ERROR_LOG(L"Reverse() not supported in JumpTo"); return nullptr; } @@ -295,7 +295,7 @@ namespace easy2d // 获取该动作的倒转 virtual ActionPtr Reverse() const override { - logs::Errorln(L"Reverse() not supported in ScaleTo"); + E2D_ERROR_LOG(L"Reverse() not supported in ScaleTo"); return nullptr; } @@ -353,7 +353,7 @@ namespace easy2d // 获取该动作的倒转 virtual ActionPtr Reverse() const override { - logs::Errorln(L"Reverse() not supported in OpacityTo"); + E2D_ERROR_LOG(L"Reverse() not supported in OpacityTo"); return nullptr; } @@ -436,7 +436,7 @@ namespace easy2d // 获取该动作的倒转 virtual ActionPtr Reverse() const override { - logs::Errorln(L"Reverse() not supported in RotateTo"); + E2D_ERROR_LOG(L"Reverse() not supported in RotateTo"); return nullptr; } diff --git a/src/core/Application.cpp b/src/core/Application.cpp index fd01c85a..725aaacc 100644 --- a/src/core/Application.cpp +++ b/src/core/Application.cpp @@ -59,7 +59,7 @@ namespace easy2d { if (!::AllocConsole()) { - logs::Warningln(L"AllocConsole failed"); + E2D_WARNING_LOG(L"AllocConsole failed"); } else { diff --git a/src/core/Image.cpp b/src/core/Image.cpp index 059acde3..43c1c1f6 100644 --- a/src/core/Image.cpp +++ b/src/core/Image.cpp @@ -64,7 +64,7 @@ namespace easy2d { if (!File(res.GetFileName()).Exists()) { - logs::Warningln(L"Image file '%s' not found!", res.GetFileName()); + E2D_WARNING_LOG(L"Image file '%s' not found!", res.GetFileName()); return false; } hr = RenderSystem::Instance()->CreateBitmapFromFile(bitmap, res.GetFileName()); @@ -76,7 +76,7 @@ namespace easy2d if (FAILED(hr)) { - logs::Errorln(hr, L"Load image file failed!"); + E2D_ERROR_HR_LOG(hr, L"Load image file failed!"); return false; } diff --git a/src/core/Music.cpp b/src/core/Music.cpp index c5ab23e1..899eba80 100644 --- a/src/core/Music.cpp +++ b/src/core/Music.cpp @@ -62,7 +62,7 @@ namespace easy2d { if (!File(res.GetFileName()).Exists()) { - logs::Warningln(L"Media file '%s' not found", res.GetFileName()); + E2D_WARNING_LOG(L"Media file '%s' not found", res.GetFileName()); return false; } hr = transcoder.LoadMediaFile(res.GetFileName(), &wave_data_, &size_); @@ -74,7 +74,7 @@ namespace easy2d if (FAILED(hr)) { - logs::Errorln(hr, L"Load media file failed"); + E2D_ERROR_HR_LOG(hr, L"Load media file failed"); return false; } @@ -86,7 +86,7 @@ namespace easy2d delete[] wave_data_; wave_data_ = nullptr; } - logs::Errorln(hr, L"Create source voice error"); + E2D_ERROR_HR_LOG(hr, L"Create source voice error"); return false; } @@ -98,7 +98,7 @@ namespace easy2d { if (!opened_) { - logs::Errorln(L"Music must be opened first!"); + E2D_ERROR_LOG(L"Music must be opened first!"); return false; } @@ -115,7 +115,7 @@ namespace easy2d HRESULT hr = voice_.Play(wave_data_, size_, static_cast(loop_count)); if (FAILED(hr)) { - logs::Errorln(hr, L"Submitting source buffer error"); + E2D_ERROR_HR_LOG(hr, L"Submitting source buffer error"); } playing_ = SUCCEEDED(hr); diff --git a/src/core/Node.cpp b/src/core/Node.cpp index b35a6236..abc73200 100644 --- a/src/core/Node.cpp +++ b/src/core/Node.cpp @@ -265,9 +265,6 @@ namespace easy2d void Node::SetZOrder(int zorder) { - if (z_order_ == zorder) - return; - z_order_ = zorder; if (parent_) @@ -285,12 +282,13 @@ namespace easy2d { if (sibling->GetZOrder() <= zorder) break; + sibling = sibling->PrevItem().Get(); } } if (sibling) { - parent_->children_.InsertAfter(me, NodePtr(sibling)); + parent_->children_.InsertAfter(me, sibling); } else { @@ -471,11 +469,11 @@ namespace easy2d #ifdef E2D_DEBUG if (child->parent_) - logs::Errorln(L"The node to be added already has a parent"); + E2D_ERROR_LOG(L"The node to be added already has a parent"); for (Node* parent = parent_; parent; parent = parent->parent_) if (parent == child) - logs::Errorln(L"A node cannot be its own parent"); + E2D_ERROR_LOG(L"A node cannot be its own parent"); #endif // E2D_DEBUG diff --git a/src/core/Resource.cpp b/src/core/Resource.cpp index 87d5d57e..94576315 100644 --- a/src/core/Resource.cpp +++ b/src/core/Resource.cpp @@ -54,28 +54,28 @@ namespace easy2d res_info = FindResourceW(nullptr, bin_name_, bin_type_); if (res_info == nullptr) { - logs::Errorln(L"FindResource"); + E2D_ERROR_LOG(L"FindResource failed"); return false; } res_data = LoadResource(nullptr, res_info); if (res_data == nullptr) { - logs::Errorln(L"LoadResource"); + E2D_ERROR_LOG(L"LoadResource failed"); return false; } buffer_size = SizeofResource(nullptr, res_info); if (buffer_size == 0) { - logs::Errorln(L"SizeofResource"); + E2D_ERROR_LOG(L"SizeofResource failed"); return false; } buffer = LockResource(res_data); if (buffer == nullptr) { - logs::Errorln(L"LockResource"); + E2D_ERROR_LOG(L"LockResource failed"); return false; } return true; diff --git a/src/core/config.h b/src/core/config.h new file mode 100644 index 00000000..e22ca3b4 --- /dev/null +++ b/src/core/config.h @@ -0,0 +1,19 @@ +//----------------------------------------------------------------------------- +// Compile-time options for Easy2D +//----------------------------------------------------------------------------- + +#pragma once + +//---- Define assertion handler. Defaults to calling assert() +//#define E2D_ASSERT(EXPR) MyAssert(EXPR) +//#define E2D_ASSERT(EXPR) __noop // Disable asserts + +//---- Don't implement log functions +//#define E2D_DISABLE_LOG_FUNCTIONS + +//---- Define debug-output handler. Defaults to calling easy2d::logs::Messageln()/Warningln()/Errorln() +//#define E2D_LOG(FORMAT, ...) wprintf(FORMAT L"\n", __VA_ARGS__) +//#define E2D_WARNING_LOG(FORMAT, ...) wprintf(FORMAT L"\n", __VA_ARGS__) +//#define E2D_ERROR_LOG(FORMAT, ...) wprintf(FORMAT L"\n", __VA_ARGS__) +//#define E2D_ERROR_HR_LOG(HR, FORMAT, ...) E2D_ERROR_LOG(L"Failure with HRESULT of %08X " FORMAT L"\n", HR, __VA_ARGS__) + diff --git a/src/core/logs.cpp b/src/core/logs.cpp index ada96ec5..4ed74389 100644 --- a/src/core/logs.cpp +++ b/src/core/logs.cpp @@ -18,7 +18,6 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#pragma once #include "logs.h" #include #include @@ -120,12 +119,12 @@ namespace easy2d } } - void easy2d::logs::Enable() + void Enable() { enabled = true; } - void easy2d::logs::Disable() + void Disable() { enabled = false; } @@ -209,15 +208,5 @@ namespace easy2d va_end(args); } - - void Errorln(HRESULT hr) - { - Errorln(L"failure with HRESULT of %08X", hr); - } - - void Errorln(HRESULT hr, const wchar_t* output) - { - Errorln(L"failure with HRESULT of %08X: %s", hr, output); - } } } diff --git a/src/core/logs.h b/src/core/logs.h index c555180f..06b0fb61 100644 --- a/src/core/logs.h +++ b/src/core/logs.h @@ -21,14 +21,46 @@ #pragma once #include "macros.h" +#ifdef E2D_DISABLE_LOG_FUNCTIONS + +#ifndef E2D_LOG +# define E2D_LOG __noop +#endif + +#ifndef E2D_WARNING_LOG +# define E2D_WARNING_LOG __noop +#endif + +#ifndef E2D_ERROR_LOG +# define E2D_ERROR_LOG __noop +#endif + +#ifndef E2D_ERROR_HR_LOG +# define E2D_ERROR_HR_LOG __noop +#endif + +#else //! E2D_DISABLE_LOG_FUNCTIONS + #ifndef E2D_LOG # ifdef E2D_DEBUG -# define E2D_LOG(format, ...) easy2d::logs::Messageln((format), __VA_ARGS__) +# define E2D_LOG(FORMAT, ...) easy2d::logs::Messageln((FORMAT), __VA_ARGS__) # else # define E2D_LOG __noop # endif #endif +#ifndef E2D_WARNING_LOG +# define E2D_WARNING_LOG(FORMAT, ...) easy2d::logs::Warningln((FORMAT), __VA_ARGS__) +#endif + +#ifndef E2D_ERROR_LOG +# define E2D_ERROR_LOG(FORMAT, ...) easy2d::logs::Errorln((FORMAT), __VA_ARGS__) +#endif + +#ifndef E2D_ERROR_HR_LOG +# define E2D_ERROR_HR_LOG(HR, FORMAT, ...) E2D_ERROR_LOG(L"Failure with HRESULT of %08X " FORMAT, HR, __VA_ARGS__) +#endif + namespace easy2d { namespace logs @@ -52,17 +84,19 @@ namespace easy2d void Error(const wchar_t* format, ...); void Errorln(const wchar_t* format, ...); - - void Errorln(HRESULT hr); - - void Errorln(HRESULT hr, const wchar_t* output); } +} +#endif //! E2D_DISABLE_LOG_FUNCTIONS + + +namespace easy2d +{ inline void ThrowIfFailed(HRESULT hr) { if (FAILED(hr)) { - logs::Errorln(hr); + E2D_ERROR_LOG(L"Fatal error with HRESULT of %08X", hr); throw std::runtime_error("Fatal error"); } } diff --git a/src/core/macros.h b/src/core/macros.h index 0b30f46b..426cdc49 100644 --- a/src/core/macros.h +++ b/src/core/macros.h @@ -64,18 +64,6 @@ # define NOMINMAX #endif -#ifndef INITGUID -# define INITGUID -#endif - -#if defined(DEBUG) || defined(_DEBUG) -# ifndef E2D_DEBUG -# define E2D_DEBUG -# endif -#else -# undef E2D_DEBUG -#endif - // Windows Header Files #include @@ -87,6 +75,14 @@ #include #include +// Compile-time Config Header File +#include "config.h" + + +#if defined(DEBUG) || defined(_DEBUG) +# define E2D_DEBUG +#endif + #if VS_VER >= VS_2015 # define E2D_NOEXCEPT noexcept @@ -99,12 +95,10 @@ #ifndef E2D_ASSERT # ifdef E2D_DEBUG -# define E2D_ASSERT(expr) assert(expr) +# define E2D_ASSERT(EXPR) assert(EXPR) # else # define E2D_ASSERT __noop # endif #endif -#ifndef E2D_NOT_USED -# define E2D_NOT_USED(var) ((void)var); -#endif +#define E2D_NOT_USED(VAR) ((void)VAR) diff --git a/src/core/time.cpp b/src/core/time.cpp index 47c859ff..fd634356 100644 --- a/src/core/time.cpp +++ b/src/core/time.cpp @@ -384,7 +384,7 @@ namespace easy2d if (!std::regex_match(str, duration_regex)) { - logs::Errorln(L"time::ParseDuration failed, invalid duration"); + E2D_ERROR_LOG(L"time::ParseDuration failed, invalid duration"); return Duration(); } @@ -415,7 +415,7 @@ namespace easy2d if (num_str.empty() || num_str == L".") { - logs::Errorln(L"time::ParseDuration failed, invalid duration"); + E2D_ERROR_LOG(L"time::ParseDuration failed, invalid duration"); return Duration(); } @@ -434,7 +434,7 @@ namespace easy2d if (unit_map.find(unit_str) == unit_map.end()) { - logs::Errorln(L"time::ParseDuration failed, invalid duration"); + E2D_ERROR_LOG(L"time::ParseDuration failed, invalid duration"); return Duration(); } diff --git a/src/core/window.cpp b/src/core/window.cpp index b02d8f7d..c2a4d209 100644 --- a/src/core/window.cpp +++ b/src/core/window.cpp @@ -393,7 +393,7 @@ namespace easy2d mode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; if (::ChangeDisplaySettingsExW(device_name, &mode, NULL, CDS_FULLSCREEN, NULL) != DISP_CHANGE_SUCCESSFUL) - logs::Errorln(L"ChangeDisplaySettings failed"); + E2D_ERROR_LOG(L"ChangeDisplaySettings failed"); } void RestoreResolution(WCHAR* device_name) diff --git a/src/easy2d.h b/src/easy2d.h index 35a16c20..769e825b 100644 --- a/src/easy2d.h +++ b/src/easy2d.h @@ -19,7 +19,7 @@ // THE SOFTWARE. // // Website: https://www.easy2d.cn -// Source Code: https://github.com/Nomango/Easy2D +// Source Code: https://github.com/easy2d/easy2d // diff --git a/src/math/constants.hpp b/src/math/constants.hpp index f14761ba..b7570545 100644 --- a/src/math/constants.hpp +++ b/src/math/constants.hpp @@ -42,3 +42,8 @@ namespace easy2d } } } + +namespace easy2d +{ + using namespace math::constants; +} diff --git a/src/utils/Transcoder.cpp b/src/utils/Transcoder.cpp index 27929cd4..678a6aac 100644 --- a/src/utils/Transcoder.cpp +++ b/src/utils/Transcoder.cpp @@ -18,6 +18,10 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +#ifndef INITGUID +# define INITGUID // MFAudioFormat_PCM, MF_MT_MAJOR_TYPE, MF_MT_SUBTYPE, MFMediaType_Audio +#endif + #include "Transcoder.h" #include "../core/d2dhelper.hpp" #include "../core/modules.h" @@ -84,7 +88,7 @@ namespace easy2d if (stream == nullptr) { - logs::Errorln(L"SHCreateMemStream"); + E2D_ERROR_LOG(L"SHCreateMemStream failed"); return E_OUTOFMEMORY; } @@ -201,7 +205,7 @@ namespace easy2d if (data == nullptr) { - logs::Errorln(L"Low memory"); + E2D_ERROR_LOG(L"Low memory"); hr = E_OUTOFMEMORY; } else diff --git a/src/utils/string.cpp b/src/utils/string.cpp index 9ea9cf6c..87529b6d 100644 --- a/src/utils/string.cpp +++ b/src/utils/string.cpp @@ -42,7 +42,7 @@ namespace easy2d } else { - logs::Errorln(HRESULT_FROM_WIN32(GetLastError()), L"Convert to WideChar code failed"); + E2D_ERROR_HR_LOG(HRESULT_FROM_WIN32(GetLastError()), L"Convert to WideChar code failed"); } } return ret; @@ -66,7 +66,7 @@ namespace easy2d } else { - logs::Errorln(HRESULT_FROM_WIN32(GetLastError()), L"Convert to MultiByte code failed"); + E2D_ERROR_HR_LOG(HRESULT_FROM_WIN32(GetLastError()), L"Convert to MultiByte code failed"); } }