add compile-time configurations

minor fixes
This commit is contained in:
Nomango 2019-02-07 21:31:30 +08:00 committed by Nomango
parent 1f751d654f
commit d3f8c7afef
18 changed files with 114 additions and 71 deletions

View File

@ -12,6 +12,7 @@
<ClInclude Include="..\..\src\core\Canvas.h" />
<ClInclude Include="..\..\src\core\closure.hpp" />
<ClInclude Include="..\..\src\core\Color.h" />
<ClInclude Include="..\..\src\core\config.h" />
<ClInclude Include="..\..\src\core\d2dhelper.hpp" />
<ClInclude Include="..\..\src\core\DebugNode.h" />
<ClInclude Include="..\..\src\core\Delay.h" />
@ -182,22 +183,18 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>$(ProjectDir)$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)$(Configuration)\</IntDir>
<TargetName>easy2dd</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<IntDir>$(ProjectDir)$(Configuration)\</IntDir>
<OutDir>$(ProjectDir)$(Configuration)\</OutDir>
<TargetName>easy2dd</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>$(ProjectDir)$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)$(Configuration)\</IntDir>
<TargetName>easy2d</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<IntDir>$(ProjectDir)$(Configuration)\</IntDir>
<OutDir>$(ProjectDir)$(Configuration)\</OutDir>
<TargetName>easy2d</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>

View File

@ -220,6 +220,9 @@
<ClInclude Include="..\..\src\core\Array.h">
<Filter>core</Filter>
</ClInclude>
<ClInclude Include="..\..\src\core\config.h">
<Filter>core</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\src\core\Animation.cpp">

View File

@ -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;
}

View File

@ -59,7 +59,7 @@ namespace easy2d
{
if (!::AllocConsole())
{
logs::Warningln(L"AllocConsole failed");
E2D_WARNING_LOG(L"AllocConsole failed");
}
else
{

View File

@ -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;
}

View File

@ -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<UINT32>(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);

View File

@ -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

View File

@ -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;

19
src/core/config.h Normal file
View File

@ -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__)

View File

@ -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 <ctime>
#include <iomanip>
@ -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);
}
}
}

View File

@ -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");
}
}

View File

@ -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 <windows.h>
@ -87,6 +75,14 @@
#include <vector>
#include <algorithm>
// 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)

View File

@ -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();
}

View File

@ -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)

View File

@ -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
//

View File

@ -42,3 +42,8 @@ namespace easy2d
}
}
}
namespace easy2d
{
using namespace math::constants;
}

View File

@ -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

View File

@ -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");
}
}