diff --git a/core/Action/EAction.cpp b/core/Action/Action.cpp similarity index 64% rename from core/Action/EAction.cpp rename to core/Action/Action.cpp index 13ee312d..897a750f 100644 --- a/core/Action/EAction.cpp +++ b/core/Action/Action.cpp @@ -1,15 +1,13 @@ #include "..\eactions.h" -#include "..\Win\winbase.h" -e2d::EAction::EAction() : - m_bRunning(false), - m_bEnding(false), - m_bInit(false), - m_pTarget(nullptr), - m_pParentScene(nullptr) +e2d::EAction::EAction() + : m_bRunning(false) + , m_bEnding(false) + , m_bInit(false) + , m_pTarget(nullptr) + , m_pParentScene(nullptr) + , m_fLast(0) { - // 默认动作 15ms 运行一次 - setInterval(15); } e2d::EAction::~EAction() @@ -34,7 +32,7 @@ void e2d::EAction::start() void e2d::EAction::resume() { m_bRunning = true; - m_tLast = GetNow(); + m_fLast = ETime::getTotalTime(); } void e2d::EAction::pause() @@ -47,22 +45,11 @@ void e2d::EAction::stop() m_bEnding = true; } -void e2d::EAction::setInterval(LONGLONG milliSeconds) -{ - // 设置动作的时间间隔 - SetInterval(m_nAnimationInterval, milliSeconds); -} - void e2d::EAction::setTarget(ENode * node) { - if (m_pTarget) + if (!m_pTarget && node) { // 动作只能有一个目标 - return; - } - - if (node) - { m_pTarget = node; } } @@ -82,7 +69,7 @@ void e2d::EAction::_init() { m_bInit = true; // 记录当前时间 - m_tLast = GetNow(); + m_fLast = ETime::getTotalTime(); } void e2d::EAction::_update() @@ -97,10 +84,10 @@ void e2d::EAction::_reset() { m_bInit = false; m_bEnding = false; - m_tLast = GetNow(); + m_fLast = ETime::getTotalTime(); } void e2d::EAction::_resetTime() { - m_tLast = GetNow(); + m_fLast = ETime::getTotalTime(); } diff --git a/core/Action/EActionCallback.cpp b/core/Action/ActionCallback.cpp similarity index 100% rename from core/Action/EActionCallback.cpp rename to core/Action/ActionCallback.cpp diff --git a/core/Action/EActionDelay.cpp b/core/Action/ActionDelay.cpp similarity index 60% rename from core/Action/EActionDelay.cpp rename to core/Action/ActionDelay.cpp index 67254fa4..4d627473 100644 --- a/core/Action/EActionDelay.cpp +++ b/core/Action/ActionDelay.cpp @@ -1,14 +1,13 @@ #include "..\eactions.h" -#include "..\Win\winbase.h" e2d::EActionDelay::EActionDelay(float duration) { - setInterval(static_cast(duration * 1000)); + m_fDelayTime = max(duration, 0); } e2d::EActionDelay * e2d::EActionDelay::clone() const { - return new EActionDelay(static_cast(ToMilliseconds(m_nAnimationInterval.QuadPart)) / 1000.0f); + return new EActionDelay(m_fDelayTime); } void e2d::EActionDelay::_init() @@ -20,7 +19,7 @@ void e2d::EActionDelay::_update() { EAction::_update(); // 判断时间间隔是否足够 - if (IsIntervalFull(m_tLast, m_nAnimationInterval)) + if ((ETime::getTotalTime() - m_fLast) >= m_fDelayTime) { this->stop(); } diff --git a/core/Action/ActionGradual.cpp b/core/Action/ActionGradual.cpp new file mode 100644 index 00000000..c8c779b1 --- /dev/null +++ b/core/Action/ActionGradual.cpp @@ -0,0 +1,35 @@ +#include "..\eactions.h" + +e2d::EActionGradual::EActionGradual(float duration) + : m_fRateOfProgress(0) +{ + m_fDuration = max(duration, 0); +} + +void e2d::EActionGradual::_init() +{ + EAction::_init(); +} + +void e2d::EActionGradual::_update() +{ + // 判断时间间隔是否足够 + if (m_fDuration == 0) + { + m_fRateOfProgress = 1; + this->stop(); + return; + } + // 计算动画进度 + m_fRateOfProgress = min((ETime::getTotalTime() - m_fLast) / m_fDuration, 1); + // 判断动作是否结束 + if (m_fRateOfProgress >= 1) + { + this->stop(); + } +} + +void e2d::EActionGradual::_reset() +{ + EAction::_reset(); +} diff --git a/core/Action/EActionLoop.cpp b/core/Action/ActionLoop.cpp similarity index 100% rename from core/Action/EActionLoop.cpp rename to core/Action/ActionLoop.cpp diff --git a/core/Action/ActionMoveBy.cpp b/core/Action/ActionMoveBy.cpp new file mode 100644 index 00000000..e6813c83 --- /dev/null +++ b/core/Action/ActionMoveBy.cpp @@ -0,0 +1,49 @@ +#include "..\eactions.h" + + +e2d::EActionMoveBy::EActionMoveBy(float duration, EVector2 vector) : + EActionGradual(duration) +{ + m_MoveVec = vector; +} + +void e2d::EActionMoveBy::_init() +{ + EActionGradual::_init(); + if (m_pTarget) + { + m_BeginPos = m_pTarget->getPos(); + } +} + +void e2d::EActionMoveBy::_update() +{ + EActionGradual::_update(); + + if (m_pTarget == nullptr) + { + this->stop(); + return; + } + + // 移动节点 + m_pTarget->setPos( + m_BeginPos.x + m_MoveVec.x * m_fRateOfProgress, + m_BeginPos.y + m_MoveVec.y * m_fRateOfProgress + ); +} + +void e2d::EActionMoveBy::_reset() +{ + EActionGradual::_reset(); +} + +e2d::EActionMoveBy * e2d::EActionMoveBy::clone() const +{ + return new EActionMoveBy(m_fDuration, m_MoveVec); +} + +e2d::EActionMoveBy * e2d::EActionMoveBy::reverse() const +{ + return new EActionMoveBy(m_fDuration, EVector2(-m_MoveVec.x, -m_MoveVec.y)); +} \ No newline at end of file diff --git a/core/Action/EActionMoveTo.cpp b/core/Action/ActionMoveTo.cpp similarity index 77% rename from core/Action/EActionMoveTo.cpp rename to core/Action/ActionMoveTo.cpp index d9d1a723..b4728f9b 100644 --- a/core/Action/EActionMoveTo.cpp +++ b/core/Action/ActionMoveTo.cpp @@ -1,14 +1,14 @@ #include "..\eactions.h" e2d::EActionMoveTo::EActionMoveTo(float duration, EPoint pos) : - EActionMoveBy(duration, EVec()) + EActionMoveBy(duration, EVector2()) { m_EndPos = pos; } e2d::EActionMoveTo * e2d::EActionMoveTo::clone() const { - return new EActionMoveTo(m_fTotalDuration / 1000, m_EndPos); + return new EActionMoveTo(m_fDuration, m_EndPos); } void e2d::EActionMoveTo::_init() diff --git a/core/Action/EActionOpacityBy.cpp b/core/Action/ActionOpacityBy.cpp similarity index 61% rename from core/Action/EActionOpacityBy.cpp rename to core/Action/ActionOpacityBy.cpp index 32128251..a8023b54 100644 --- a/core/Action/EActionOpacityBy.cpp +++ b/core/Action/ActionOpacityBy.cpp @@ -18,25 +18,15 @@ void e2d::EActionOpacityBy::_init() void e2d::EActionOpacityBy::_update() { - EAction::_update(); + EActionGradual::_update(); if (m_pTarget == nullptr) { this->stop(); return; } - - while (EActionGradual::_isDelayEnough()) - { - // 设置节点透明度 - m_pTarget->setOpacity(m_nBeginVal + m_nVariation * m_fRateOfProgress); - // 判断动作是否结束 - if (_isEnd()) - { - this->stop(); - break; - } - } + // 设置节点透明度 + m_pTarget->setOpacity(m_nBeginVal + m_nVariation * m_fRateOfProgress); } void e2d::EActionOpacityBy::_reset() @@ -46,10 +36,10 @@ void e2d::EActionOpacityBy::_reset() e2d::EActionOpacityBy * e2d::EActionOpacityBy::clone() const { - return new EActionOpacityBy(m_fTotalDuration / 1000, m_nVariation); + return new EActionOpacityBy(m_fDuration, m_nVariation); } e2d::EActionOpacityBy * e2d::EActionOpacityBy::reverse() const { - return new EActionOpacityBy(m_fTotalDuration / 1000, -m_nVariation); + return new EActionOpacityBy(m_fDuration, -m_nVariation); } \ No newline at end of file diff --git a/core/Action/EActionOpacityTo.cpp b/core/Action/ActionOpacityTo.cpp similarity index 85% rename from core/Action/EActionOpacityTo.cpp rename to core/Action/ActionOpacityTo.cpp index 71ca0265..97b79acd 100644 --- a/core/Action/EActionOpacityTo.cpp +++ b/core/Action/ActionOpacityTo.cpp @@ -9,7 +9,7 @@ e2d::EActionOpacityTo::EActionOpacityTo(float duration, float opacity) : e2d::EActionOpacityTo * e2d::EActionOpacityTo::clone() const { - return new EActionOpacityTo(m_fTotalDuration / 1000, m_nEndVal); + return new EActionOpacityTo(m_fDuration, m_nEndVal); } void e2d::EActionOpacityTo::_init() diff --git a/core/Action/EActionRotateBy.cpp b/core/Action/ActionRotateBy.cpp similarity index 61% rename from core/Action/EActionRotateBy.cpp rename to core/Action/ActionRotateBy.cpp index b294a82f..d6346cc1 100644 --- a/core/Action/EActionRotateBy.cpp +++ b/core/Action/ActionRotateBy.cpp @@ -18,7 +18,7 @@ void e2d::EActionRotateBy::_init() void e2d::EActionRotateBy::_update() { - EAction::_update(); + EActionGradual::_update(); if (m_pTarget == nullptr) { @@ -26,17 +26,8 @@ void e2d::EActionRotateBy::_update() return; } - while (EActionGradual::_isDelayEnough()) - { - // 旋转节点 - m_pTarget->setRotation(m_nBeginVal + m_nVariation * m_fRateOfProgress); - // 判断动作是否结束 - if (_isEnd()) - { - this->stop(); - break; - } - } + // 旋转节点 + m_pTarget->setRotation(m_nBeginVal + m_nVariation * m_fRateOfProgress); } void e2d::EActionRotateBy::_reset() @@ -46,10 +37,10 @@ void e2d::EActionRotateBy::_reset() e2d::EActionRotateBy * e2d::EActionRotateBy::clone() const { - return new EActionRotateBy(m_fTotalDuration / 1000, m_nVariation); + return new EActionRotateBy(m_fDuration, m_nVariation); } e2d::EActionRotateBy * e2d::EActionRotateBy::reverse() const { - return new EActionRotateBy(m_fTotalDuration / 1000, -m_nVariation); + return new EActionRotateBy(m_fDuration, -m_nVariation); } \ No newline at end of file diff --git a/core/Action/EActionRotateTo.cpp b/core/Action/ActionRotateTo.cpp similarity index 85% rename from core/Action/EActionRotateTo.cpp rename to core/Action/ActionRotateTo.cpp index 49da2153..92059a83 100644 --- a/core/Action/EActionRotateTo.cpp +++ b/core/Action/ActionRotateTo.cpp @@ -9,7 +9,7 @@ e2d::EActionRotateTo::EActionRotateTo(float duration, float rotation) : e2d::EActionRotateTo * e2d::EActionRotateTo::clone() const { - return new EActionRotateTo(m_fTotalDuration / 1000, m_nEndVal); + return new EActionRotateTo(m_fDuration, m_nEndVal); } void e2d::EActionRotateTo::_init() diff --git a/core/Action/EActionScaleBy.cpp b/core/Action/ActionScaleBy.cpp similarity index 63% rename from core/Action/EActionScaleBy.cpp rename to core/Action/ActionScaleBy.cpp index 4d2194d4..1fe86644 100644 --- a/core/Action/EActionScaleBy.cpp +++ b/core/Action/ActionScaleBy.cpp @@ -27,7 +27,7 @@ void e2d::EActionScaleBy::_init() void e2d::EActionScaleBy::_update() { - EAction::_update(); + EActionGradual::_update(); if (m_pTarget == nullptr) { @@ -35,19 +35,10 @@ void e2d::EActionScaleBy::_update() return; } - while (EActionGradual::_isDelayEnough()) - { - // 缩放节点 - m_pTarget->setScale( - m_nBeginScaleX + m_nVariationX * m_fRateOfProgress, - m_nBeginScaleX + m_nVariationX * m_fRateOfProgress); - // 判断动作是否结束 - if (_isEnd()) - { - this->stop(); - break; - } - } + // 缩放节点 + m_pTarget->setScale( + m_nBeginScaleX + m_nVariationX * m_fRateOfProgress, + m_nBeginScaleX + m_nVariationX * m_fRateOfProgress); } void e2d::EActionScaleBy::_reset() @@ -57,10 +48,10 @@ void e2d::EActionScaleBy::_reset() e2d::EActionScaleBy * e2d::EActionScaleBy::clone() const { - return new EActionScaleBy(m_fTotalDuration / 1000, m_nVariationX, m_nVariationY); + return new EActionScaleBy(m_fDuration, m_nVariationX, m_nVariationY); } e2d::EActionScaleBy * e2d::EActionScaleBy::reverse() const { - return new EActionScaleBy(m_fTotalDuration / 1000, -m_nVariationX, -m_nVariationY); + return new EActionScaleBy(m_fDuration, -m_nVariationX, -m_nVariationY); } \ No newline at end of file diff --git a/core/Action/EActionScaleTo.cpp b/core/Action/ActionScaleTo.cpp similarity index 88% rename from core/Action/EActionScaleTo.cpp rename to core/Action/ActionScaleTo.cpp index f117e65e..cb1decd1 100644 --- a/core/Action/EActionScaleTo.cpp +++ b/core/Action/ActionScaleTo.cpp @@ -16,7 +16,7 @@ e2d::EActionScaleTo::EActionScaleTo(float duration, float scaleX, float scaleY) e2d::EActionScaleTo * e2d::EActionScaleTo::clone() const { - return new EActionScaleTo(m_fTotalDuration / 1000, m_nEndScaleX, m_nEndScaleY); + return new EActionScaleTo(m_fDuration, m_nEndScaleX, m_nEndScaleY); } void e2d::EActionScaleTo::_init() diff --git a/core/Action/EActionSequence.cpp b/core/Action/ActionSequence.cpp similarity index 99% rename from core/Action/EActionSequence.cpp rename to core/Action/ActionSequence.cpp index 7f18f148..5cce2b07 100644 --- a/core/Action/EActionSequence.cpp +++ b/core/Action/ActionSequence.cpp @@ -1,5 +1,4 @@ #include "..\eactions.h" -#include e2d::EActionSequence::EActionSequence() : m_nActionIndex(0) diff --git a/core/Action/EActionTwo.cpp b/core/Action/ActionTwo.cpp similarity index 100% rename from core/Action/EActionTwo.cpp rename to core/Action/ActionTwo.cpp diff --git a/core/Action/EActionTwoAtSameTime.cpp b/core/Action/ActionTwoAtSameTime.cpp similarity index 100% rename from core/Action/EActionTwoAtSameTime.cpp rename to core/Action/ActionTwoAtSameTime.cpp diff --git a/core/Action/EAnimation.cpp b/core/Action/Animation.cpp similarity index 66% rename from core/Action/EAnimation.cpp rename to core/Action/Animation.cpp index 42f752b3..0f06cbb1 100644 --- a/core/Action/EAnimation.cpp +++ b/core/Action/Animation.cpp @@ -1,18 +1,14 @@ #include "..\eactions.h" -#include "..\Win\winbase.h" -#include -e2d::EAnimation::EAnimation() : - m_nFrameIndex(0) +e2d::EAnimation::EAnimation() + : m_nFrameIndex(0) { - // 帧动画默认 0.1s 刷新一次 - setInterval(100); } -e2d::EAnimation::EAnimation(LONGLONG frameDelay) : - m_nFrameIndex(0) +e2d::EAnimation::EAnimation(float invertal) + : m_nFrameIndex(0) + , m_fInterval(invertal) { - setInterval(frameDelay); } e2d::EAnimation::~EAnimation() @@ -23,6 +19,11 @@ e2d::EAnimation::~EAnimation() } } +void e2d::EAnimation::setInterval(float interval) +{ + m_fInterval = max(interval, 0); +} + void e2d::EAnimation::_init() { EAction::_init(); @@ -39,11 +40,11 @@ void e2d::EAnimation::_update() } // 判断时间间隔是否足够 - while (IsIntervalFull(m_tLast, m_nAnimationInterval)) + while ((ETime::getTotalTime() - m_fLast) >= m_fInterval) { // 重新记录时间 - m_tLast.QuadPart += m_nAnimationInterval.QuadPart; - // 加载精灵帧 + m_fLast += m_fInterval; + // 加载关键帧 reinterpret_cast(m_pTarget)->loadFrom(m_vFrames[m_nFrameIndex]); m_nFrameIndex++; // 判断动作是否结束 @@ -61,7 +62,7 @@ void e2d::EAnimation::_reset() m_nFrameIndex = 0; } -void e2d::EAnimation::addFrame(ESpriteFrame * frame) +void e2d::EAnimation::addKeyframe(EKeyframe * frame) { if (frame) { @@ -72,10 +73,10 @@ void e2d::EAnimation::addFrame(ESpriteFrame * frame) e2d::EAnimation * e2d::EAnimation::clone() const { - auto a = new EAnimation(ToMilliseconds(m_nAnimationInterval.QuadPart)); + auto a = new EAnimation(m_fInterval); for (auto frame = m_vFrames.begin(); frame != m_vFrames.end(); frame++) { - a->addFrame((*frame)); + a->addKeyframe((*frame)); } return a; } diff --git a/core/Action/EActionGradual.cpp b/core/Action/EActionGradual.cpp deleted file mode 100644 index 029ad789..00000000 --- a/core/Action/EActionGradual.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include "..\eactions.h" -#include "..\Win\winbase.h" - -e2d::EActionGradual::EActionGradual(float duration) - : m_fRateOfProgress(0) - , m_fDuration(0) - , m_fTotalDuration(duration * 1000) -{ -} - -bool e2d::EActionGradual::_isEnd() const -{ - return m_fDuration >= m_fTotalDuration; -} - -void e2d::EActionGradual::_init() -{ - EAction::_init(); -} -#include -bool e2d::EActionGradual::_isDelayEnough() -{ - // 判断时间间隔是否足够 - if (m_fTotalDuration == 0) - { - m_fRateOfProgress = 1; - return true; - } - - if (IsIntervalFull(m_tLast, m_nAnimationInterval)) - { - // 重新记录时间 - m_tLast.QuadPart += m_nAnimationInterval.QuadPart; - m_fDuration += static_cast(ToMilliseconds(m_nAnimationInterval.QuadPart)); - std::cout << ToMilliseconds(m_nAnimationInterval.QuadPart) << std::endl; - // 计算动画进度 - m_fRateOfProgress = m_fDuration / m_fTotalDuration; - return true; - } - return false; -} - -void e2d::EActionGradual::_reset() -{ - EAction::_reset(); - m_fDuration = 0; -} diff --git a/core/Action/EActionMoveBy.cpp b/core/Action/EActionMoveBy.cpp deleted file mode 100644 index 75847083..00000000 --- a/core/Action/EActionMoveBy.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include "..\eactions.h" - - -e2d::EActionMoveBy::EActionMoveBy(float duration, EVec vector) : - EActionGradual(duration) -{ - m_MoveVec = vector; -} - -void e2d::EActionMoveBy::_init() -{ - EActionGradual::_init(); - if (m_pTarget) - { - m_BeginPos = m_pTarget->getPos(); - } -} - -void e2d::EActionMoveBy::_update() -{ - EAction::_update(); - - if (m_pTarget == nullptr) - { - this->stop(); - return; - } - - while (EActionGradual::_isDelayEnough()) - { - // 移动节点 - m_pTarget->setPos( - m_BeginPos.x + m_MoveVec.x * m_fRateOfProgress, - m_BeginPos.y + m_MoveVec.y * m_fRateOfProgress - ); - // 判断动作是否结束 - if (_isEnd()) - { - this->stop(); - break; - } - } -} - -void e2d::EActionMoveBy::_reset() -{ - EActionGradual::_reset(); -} - -e2d::EActionMoveBy * e2d::EActionMoveBy::clone() const -{ - return new EActionMoveBy(m_fTotalDuration / 1000, m_MoveVec); -} - -e2d::EActionMoveBy * e2d::EActionMoveBy::reverse() const -{ - return new EActionMoveBy(m_fTotalDuration / 1000, EVec(-m_MoveVec.x, -m_MoveVec.y)); -} \ No newline at end of file diff --git a/core/Base/EApp.cpp b/core/Base/EApp.cpp deleted file mode 100644 index d7984dd0..00000000 --- a/core/Base/EApp.cpp +++ /dev/null @@ -1,784 +0,0 @@ -#include "..\ebase.h" -#include "..\Win\winbase.h" -#include "..\emanagers.h" -#include "..\enodes.h" -#include "..\etransitions.h" -#include "..\etools.h" -#include -#include -#pragma comment (lib ,"imm32.lib") -#include -#pragma comment(lib, "winmm.lib") - - -// 唯一实例指针 -static e2d::EApp * s_pInstance = nullptr; -// 场景栈 -static std::stack s_SceneStack; -// 游戏开始时间 -static LARGE_INTEGER s_tStart; - - -e2d::EApp::EApp() - : m_bEnd(false) - , m_bPaused(false) - , m_bManualPaused(false) - , m_bShowConsole(false) - , m_nAnimationInterval() - , m_ClearColor(EColor::BLACK) - , m_pTransition(nullptr) - , m_pCurrentScene(nullptr) - , m_pNextScene(nullptr) -{ - CoInitialize(NULL); - - // 获取时钟频率 - LARGE_INTEGER tFreq; - QueryPerformanceFrequency(&tFreq); - // 默认帧率为 60 - m_nAnimationInterval.QuadPart = static_cast(1.0 / 60 * tFreq.QuadPart); -} - -e2d::EApp::~EApp() -{ - SafeReleaseInterface(&GetSolidColorBrush()); - SafeReleaseInterface(&GetRenderTarget()); - SafeReleaseInterface(&GetFactory()); - SafeReleaseInterface(&GetImagingFactory()); - SafeReleaseInterface(&GetDirectWriteFactory()); - CoUninitialize(); -} - -e2d::EApp * e2d::EApp::getInstance() -{ - if (!s_pInstance) - { - s_pInstance = new EApp(); - } - return s_pInstance; -} - -bool e2d::EApp::init(const EString &title, UINT32 width, UINT32 height, const EWindowStyle &wStyle /* = nullptr */) -{ - EApp * pApp = EApp::getInstance(); - HRESULT hr; - - // 保存窗口样式 - pApp->m_WindowStyle = wStyle; - // 保存窗口名称 - pApp->m_sTitle = title; - - // 注册窗口类 - WNDCLASSEX wcex = { sizeof(WNDCLASSEX) }; - wcex.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS; - wcex.lpfnWndProc = EApp::WndProc; - wcex.cbClsExtra = 0; - wcex.cbWndExtra = sizeof(LONG_PTR); - wcex.hInstance = HINST_THISCOMPONENT; - wcex.hbrBackground = (HBRUSH)(GetStockObject(BLACK_BRUSH)); - wcex.lpszMenuName = NULL; - wcex.hCursor = LoadCursor(NULL, IDI_APPLICATION); - wcex.lpszClassName = L"Easy2DApp"; - // 设置窗口是否有关闭按钮 - if (wStyle.m_bNoClose) - { - wcex.style |= CS_NOCLOSE; - } - // 设置程序图标 - if (wStyle.m_pIconID) - { - wcex.hIcon = (HICON)::LoadImage( - GetModuleHandle(NULL), - wStyle.m_pIconID, - IMAGE_ICON, - 0, - 0, - LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_DEFAULTSIZE); - } - - RegisterClassEx(&wcex); - - // 因为 CreateWindow 函数使用的是像素大小,获取系统的 DPI 以使它 - // 适应窗口缩放 - FLOAT dpiX, dpiY; - - // 工厂将返回当前的系统 DPI,这个值也将用来创建窗口 - GetFactory()->GetDesktopDpi(&dpiX, &dpiY); - - width = static_cast(ceil(width * dpiX / 96.f)); - height = static_cast(ceil(height * dpiY / 96.f)); - - // 获取屏幕分辨率 - UINT screenWidth = static_cast(GetSystemMetrics(SM_CXSCREEN)); - UINT screenHeight = static_cast(GetSystemMetrics(SM_CYSCREEN)); - // 当输入的窗口大小比分辨率大时,给出警告 - WARN_IF(screenWidth < width || screenHeight < height, "The window is larger than screen!"); - // 取最小值 - width = min(width, screenWidth); - height = min(height, screenHeight); - - // 创建窗口样式 - DWORD dwStyle = WS_OVERLAPPED | WS_SYSMENU; - if (!wStyle.m_bNoMiniSize) - { - dwStyle |= WS_MINIMIZEBOX; - } - // 创建窗口 - GetHWnd() = CreateWindow( - L"Easy2DApp", - title, - dwStyle, - 0, 0, width, height, - NULL, - NULL, - HINST_THISCOMPONENT, - NULL - ); - - hr = GetHWnd() ? S_OK : E_FAIL; - - if (SUCCEEDED(hr)) - { - // 禁用输入法 - EApp::setKeyboardLayoutEnable(false); - // 重设客户区大小 - EApp::setWindowSize(width, height); - } - else - { - UnregisterClass(L"Easy2DApp", HINST_THISCOMPONENT); - } - - if (FAILED(hr)) - { - MessageBox(nullptr, L"Initialize Failed!", L"Error", MB_OK); - } - - return SUCCEEDED(hr); -} - -int e2d::EApp::run() -{ - if (GetHWnd() == nullptr) - { - MessageBox(nullptr, L"Invalid window handle!", L"Error", MB_OK); - return -1; - } - - EApp * pApp = EApp::getInstance(); - // 进入第一个场景 - pApp->_enterNextScene(); - // 关闭控制台 - if (!pApp->m_bShowConsole) - { - showConsole(false); - } - // 显示窗口 - ShowWindow(GetHWnd(), SW_SHOWNORMAL); - UpdateWindow(GetHWnd()); - // 设置窗口置顶 - if (pApp->m_WindowStyle.m_bTopMost) - { - SetWindowPos(GetHWnd(), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); - } - - // 挂起时长 - LONG nWait = 0L; - // 时间间隔 - LONGLONG nInterval; - // 上一帧画面绘制时间 - LARGE_INTEGER tLast; - // 时钟频率 - LARGE_INTEGER tFreq; - - // 修改时间精度 - timeBeginPeriod(1); - // 获取时钟频率 - QueryPerformanceFrequency(&tFreq); - // 刷新当前时间 - QueryPerformanceCounter(&GetNow()); - // 记录开始时间 - s_tStart = GetNow(); - tLast = GetNow(); - // 窗口消息 - MSG msg; - - while (!pApp->m_bEnd) - { - // 处理窗口消息 - while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) - { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - - // 刷新当前时间 - QueryPerformanceCounter(&GetNow()); - // 计算时间间隔 - nInterval = GetNow().QuadPart - tLast.QuadPart; - // 判断间隔时间是否足够 - if (nInterval >= pApp->m_nAnimationInterval.QuadPart) - { - // 记录当前时间 - tLast.QuadPart += pApp->m_nAnimationInterval.QuadPart; - // 更新游戏内容 - pApp->_update(); - // 刷新游戏画面 - pApp->_render(); - } - else - { - // 计算挂起时长 - nWait = static_cast(ToMilliseconds(pApp->m_nAnimationInterval.QuadPart - nInterval) - 1LL); - // 挂起线程,释放 CPU 占用 - if (nWait > 1L) - { - Sleep(nWait); - } - } - } - - // 关闭控制台 - EApp::showConsole(false); - // 重置时间精度 - timeEndPeriod(1); - - return 0; -} - -void e2d::EApp::pause() -{ - EApp::getInstance()->m_bManualPaused = true; -} - -void e2d::EApp::resume() -{ - if (isPaused()) - { - EApp::getInstance()->m_bPaused = false; - EApp::getInstance()->m_bManualPaused = false; - EApp::getInstance()->_updateTime(); - } -} - -bool e2d::EApp::isPaused() -{ - return s_pInstance->m_bPaused || s_pInstance->m_bManualPaused; -} - -void e2d::EApp::quit() -{ - getInstance()->m_bEnd = true; // 这个变量将控制游戏是否结束 -} - -void e2d::EApp::showConsole(bool show /* = true */) -{ - static FILE * stdoutstream = nullptr; - static FILE * stdinstream = nullptr; - static FILE * stderrstream = nullptr; - - EApp::getInstance()->m_bShowConsole = show; - // 查找已存在的控制台句柄 - HWND hwnd = GetConsoleWindow(); - // 关闭控制台 - if (show) - { - if (hwnd) - { - ShowWindow(hwnd, SW_SHOWNORMAL); - } - else - { - // 显示一个新控制台 - if (AllocConsole()) - { - freopen_s(&stdoutstream, "CONOUT$", "w+t", stdout); - freopen_s(&stderrstream, "CONOUT$", "w+t", stderr); - freopen_s(&stdinstream, "CONIN$", "r+t", stdin); - } - else - { - MessageBox(nullptr, L"Alloc Console Failed!", L"Error", MB_OK); - } - } - } - else - { - if (hwnd) - { - if (stdoutstream) - { - fclose(stdoutstream); - fclose(stdinstream); - fclose(stderrstream); - - stdoutstream = stdinstream = stderrstream = nullptr; - } - FreeConsole(); - } - } -} - -bool e2d::EApp::onActivate() -{ - return false; -} - -bool e2d::EApp::onInactive() -{ - return false; -} - -bool e2d::EApp::onCloseWindow() -{ - return true; -} - -void e2d::EApp::_update() -{ - if (isPaused()) - { - return; - } - - // 正在切换场景时,执行场景切换动画 - if (m_pTransition) - { - m_pTransition->_update(); - if (m_pTransition->isEnding()) - { - m_pTransition->release(); - m_pTransition = nullptr; - // 进入下一场景 - _enterNextScene(); - // 刷新计时器 - _updateTime(); - } - return; - } - - // 下一场景指针不为空时,切换场景 - if (m_pNextScene) - { - // 进入下一场景 - _enterNextScene(); - } - - // 断言当前场景非空 - ASSERT(m_pCurrentScene != nullptr, "Current scene NULL pointer exception."); - - EObjectManager::__flush(); // 刷新内存池 - ETimerManager::TimerProc(); // 定时器管理器执行程序 - EActionManager::ActionProc(); // 动作管理器执行程序 -} - -void e2d::EApp::_render() -{ - HRESULT hr = S_OK; - - // 开始绘图 - GetRenderTarget()->BeginDraw(); - // 使用背景色清空屏幕 - GetRenderTarget()->Clear(D2D1::ColorF(m_ClearColor)); - // 绘制当前场景 - if (m_pCurrentScene) - { - m_pCurrentScene->_render(); - } - // 切换场景时,同时绘制两场景 - if (m_pTransition && m_pNextScene) - { - m_pNextScene->_render(); - } - // 终止绘图 - hr = GetRenderTarget()->EndDraw(); - - if (hr == D2DERR_RECREATE_TARGET) - { - // 如果 Direct3D 设备在执行过程中消失,将丢弃当前的设备相关资源 - // 并在下一次调用时重建资源 - hr = S_OK; - SafeReleaseInterface(&GetRenderTarget()); - } - - if (FAILED(hr)) - { - // 渲染时产生了未知的错误,退出游戏 - MessageBox(GetHWnd(), L"Game rendering failed!", L"Error", MB_OK); - this->quit(); - } -} - -void e2d::EApp::setWindowSize(UINT32 width, UINT32 height) -{ - // 获取屏幕分辨率 - int screenWidth = GetSystemMetrics(SM_CXSCREEN); - int screenHeight = GetSystemMetrics(SM_CYSCREEN); - // 获取窗口大小(包含菜单栏) - tagRECT rcWindow; - GetWindowRect(GetHWnd(), &rcWindow); - // 获取客户区大小 - tagRECT rcClient; - GetClientRect(GetHWnd(), &rcClient); - // 计算边框大小 - width += (rcWindow.right - rcWindow.left) - (rcClient.right - rcClient.left); - height += (rcWindow.bottom - rcWindow.top) - (rcClient.bottom - rcClient.top); - // 修改窗口大小,并设置窗口在屏幕居中 - MoveWindow(GetHWnd(), (screenWidth - width) / 2, (screenHeight - height) / 2, width, height, TRUE); -} - -void e2d::EApp::setWindowTitle(const EString &title) -{ - // 设置窗口标题 - SetWindowText(GetHWnd(), title); - // 保存当前标题,用于修改窗口大小时恢复标题 - getInstance()->m_sTitle = title; -} - -e2d::EString e2d::EApp::getTitle() -{ - return getInstance()->m_sTitle; -} - -float e2d::EApp::getWidth() -{ - return GetRenderTarget()->GetSize().width; -} - -float e2d::EApp::getHeight() -{ - return GetRenderTarget()->GetSize().height; -} - -e2d::ESize e2d::EApp::getSize() -{ - return ESize(GetRenderTarget()->GetSize().width, GetRenderTarget()->GetSize().height); -} - -void e2d::EApp::enterScene(EScene * scene, ETransition * transition /* = nullptr */, bool saveCurrentScene /* = true */) -{ - ASSERT(scene != nullptr, "Next scene NULL pointer exception!"); - scene->retain(); - // 保存下一场景的指针 - getInstance()->m_pNextScene = scene; - // 切换场景时,是否保存当前场景 - if (getInstance()->m_pCurrentScene) - { - getInstance()->m_pCurrentScene->m_bWillSave = saveCurrentScene; - } - // 设置切换场景动画 - if (transition) - { - getInstance()->m_pTransition = transition; - transition->retain(); - transition->_setTarget( - getInstance()->m_pCurrentScene, - getInstance()->m_pNextScene - ); - } -} - -void e2d::EApp::backScene(ETransition * transition /* = nullptr */) -{ - // 栈为空时,调用返回场景函数失败 - WARN_IF(s_SceneStack.size() == 0, "Scene stack now is empty!"); - if (s_SceneStack.size() == 0) return; - - // 从栈顶取出场景指针,作为下一场景 - getInstance()->m_pNextScene = s_SceneStack.top(); - s_SceneStack.pop(); - - // 返回上一场景时,不保存当前场景 - if (getInstance()->m_pCurrentScene) - { - getInstance()->m_pCurrentScene->m_bWillSave = false; - } - - // 设置切换场景动画 - if (transition) - { - getInstance()->m_pTransition = transition; - transition->retain(); - transition->_setTarget( - getInstance()->m_pCurrentScene, - getInstance()->m_pNextScene - ); - } -} - -void e2d::EApp::clearScene() -{ - // 清空场景栈 - while (s_SceneStack.size()) - { - auto temp = s_SceneStack.top(); - SafeRelease(&temp); - s_SceneStack.pop(); - } -} - -void e2d::EApp::setFPS(UINT32 fps) -{ - fps = min(max(fps, 30), 120); - - // 获取时钟频率 - LARGE_INTEGER tFreq; - QueryPerformanceFrequency(&tFreq); - EApp::getInstance()->m_nAnimationInterval.QuadPart = static_cast(1.0 / fps * tFreq.QuadPart); -} - -e2d::EScene * e2d::EApp::getCurrentScene() -{ - return getInstance()->m_pCurrentScene; -} - -void e2d::EApp::setAppName(const EString &appname) -{ - getInstance()->m_sAppName = appname; -} - -e2d::EString e2d::EApp::getAppName() -{ - if (getInstance()->m_sAppName.isEmpty()) - getInstance()->m_sAppName = getInstance()->m_sTitle; - return getInstance()->m_sAppName; -} - -void e2d::EApp::setBkColor(UINT32 color) -{ - getInstance()->m_ClearColor = color; -} - -void e2d::EApp::setKeyboardLayoutEnable(bool value) -{ - static HIMC hImc = NULL; - - if (value) - { - if (hImc != NULL) - { - ImmAssociateContext(GetHWnd(), hImc); - hImc = NULL; - } - } - else - { - if (hImc == NULL) - { - hImc = ImmAssociateContext(GetHWnd(), NULL); - } - } -} - -HWND e2d::EApp::getHWnd() -{ - return GetHWnd(); -} - -e2d::EWindowStyle e2d::EApp::getWindowStyle() -{ - return getInstance()->m_WindowStyle; -} - -LONGLONG e2d::EApp::getTotalDurationFromStart() -{ - return (s_tStart.QuadPart - GetNow().QuadPart) * 1000LL / GetFreq().QuadPart; -} - -void e2d::EApp::hideWindow() -{ - ShowWindow(GetHWnd(), SW_HIDE); -} - -void e2d::EApp::showWindow() -{ - ShowWindow(GetHWnd(), SW_SHOWNORMAL); -} - -void e2d::EApp::_enterNextScene() -{ - if (m_pNextScene == nullptr) - return; - - // 执行当前场景的 onCloseWindow 函数 - if (m_pCurrentScene) - { - m_pCurrentScene->onExit(); - - if (m_pCurrentScene->m_bWillSave) - { - // 若要保存当前场景,把它放入栈中 - s_SceneStack.push(m_pCurrentScene); - } - else - { - SafeRelease(&m_pCurrentScene); - } - } - - // 执行下一场景的 onEnter 函数 - m_pNextScene->onEnter(); - - m_pCurrentScene = m_pNextScene; // 切换场景 - m_pNextScene = nullptr; // 下一场景置空 -} - -void e2d::EApp::_updateTime() -{ - // 刷新当前时间 - QueryPerformanceCounter(&GetNow()); - // 重置动画和定时器 - EActionManager::_resetAllActions(); - ETimerManager::_resetAllTimers(); -} - -LRESULT e2d::EApp::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) -{ - if (s_pInstance == nullptr) - { - return DefWindowProc(hWnd, message, wParam, lParam); - } - else - { - LRESULT result = 0; - - switch (message) - { - // 处理鼠标消息 - case WM_LBUTTONUP: - case WM_LBUTTONDOWN: - case WM_LBUTTONDBLCLK: - case WM_MBUTTONUP: - case WM_MBUTTONDOWN: - case WM_MBUTTONDBLCLK: - case WM_RBUTTONUP: - case WM_RBUTTONDOWN: - case WM_RBUTTONDBLCLK: - case WM_MOUSEMOVE: - case WM_MOUSEWHEEL: - { - // 执行场景切换时屏蔽按键和鼠标消息 - if (!s_pInstance->m_pTransition && !s_pInstance->m_pNextScene) - { - EMsgManager::MouseProc(message, wParam, lParam); - } - } - result = 0; - break; - - // 处理按键消息 - case WM_KEYDOWN: - case WM_KEYUP: - { - // 执行场景切换时屏蔽按键和鼠标消息 - if (!s_pInstance->m_pTransition && !s_pInstance->m_pNextScene) - { - EMsgManager::KeyboardProc(message, wParam, lParam); - } - } - result = 0; - break; - - // 处理窗口大小变化消息 - case WM_SIZE: - { - UINT width = LOWORD(lParam); - UINT height = HIWORD(lParam); - // 如果程序接收到一个 WM_SIZE 消息,这个方法将调整渲染 - // 目标适当。它可能会调用失败,但是这里可以忽略有可能的 - // 错误,因为这个错误将在下一次调用 EndDraw 时产生 - GetRenderTarget()->Resize(D2D1::SizeU(width, height)); - } - break; - - // 处理分辨率变化消息 - case WM_DISPLAYCHANGE: - { - // 重绘客户区 - InvalidateRect(hWnd, NULL, FALSE); - } - result = 0; - break; - - // 重绘窗口 - case WM_PAINT: - { - s_pInstance->_render(); - ValidateRect(hWnd, NULL); - } - result = 0; - break; - - // 窗口激活消息 - case WM_ACTIVATE: - { - EScene * pCurrentScene = s_pInstance->getCurrentScene(); - - if (LOWORD(wParam) == WA_INACTIVE) - { - if (pCurrentScene && - pCurrentScene->onInactive() && - s_pInstance->onInactive()) - { - s_pInstance->m_bPaused = true; - } - } - else if (s_pInstance->m_bPaused) - { - if (pCurrentScene && - pCurrentScene->onActivate() && - s_pInstance->onActivate()) - { - s_pInstance->m_bPaused = false; - if (!s_pInstance->m_bManualPaused) - { - s_pInstance->_updateTime(); - } - } - } - } - result = 1; - break; - - // 窗口关闭消息 - case WM_CLOSE: - { - EScene * pCurrentScene = s_pInstance->getCurrentScene(); - - if (pCurrentScene) - { - if (pCurrentScene->onCloseWindow() && - s_pInstance->onCloseWindow()) - { - DestroyWindow(hWnd); - } - } - else - { - if (s_pInstance->onCloseWindow()) - { - DestroyWindow(hWnd); - } - } - } - result = 1; - break; - - // 窗口被销毁 - case WM_DESTROY: - { - // 退出程序 - s_pInstance->quit(); - // 发送退出消息 - PostQuitMessage(0); - } - result = 1; - break; - - default: - result = DefWindowProc(hWnd, message, wParam, lParam); - } - - return result; - } -} diff --git a/core/Base/Game.cpp b/core/Base/Game.cpp new file mode 100644 index 00000000..7ca5095d --- /dev/null +++ b/core/Base/Game.cpp @@ -0,0 +1,166 @@ +#include "..\ebase.h" +#include "..\emanagers.h" +#include "..\enodes.h" +#include "..\etransitions.h" +#include "..\etools.h" + + +// 控制游戏终止 +static bool s_bEndGame = false; +// 控制游戏暂停 +static bool s_bPaused = false; +// 是否进行过初始化 +static bool s_bInitialized = false; +// AppName +static e2d::EString s_sAppName; + + +bool e2d::EGame::init(LPCTSTR sTitle, UINT32 nWidth, UINT32 nHeight, LPCTSTR pIconID, bool bNoClose, bool bNoMiniSize, bool bTopMost) +{ + if (s_bInitialized) + { + WARN_IF(true, "The game has been initialized!"); + return false; + } + + // 初始化 COM 组件 + if (SUCCEEDED(CoInitialize(NULL))) + { + // 创建设备无关资源 + if (ERenderer::__createDeviceIndependentResources()) + { + // 初始化窗口 + if (EWindow::__init(sTitle, nWidth, nHeight, pIconID, bNoClose, bNoMiniSize, bTopMost)) + { + // 创建设备相关资源 + if (ERenderer::__createDeviceResources()) + { + // 重设 Client 大小 + EWindow::setSize(nWidth, nHeight); + // 设置默认 AppName + if (s_sAppName.isEmpty()) + s_sAppName = EWindow::getTitle(); + // 标志初始化成功 + s_bInitialized = true; + } + } + } + } + + return s_bInitialized; +} + +int e2d::EGame::run() +{ + if (!s_bInitialized) + { + ASSERT(false, "You must initialize EGame first!"); + return -1; + } + + // 初始化 DirectInput + EInput::__init(); + // 初始化计时操作 + ETime::__init(); + // 进入第一个场景 + ESceneManager::__enterNextScene(); + // 显示窗口 + EWindow::showWindow(); + // 刷新窗口内容 + ::UpdateWindow(EWindow::getHWnd()); + // 处理窗口消息 + EWindow::__poll(); + // 刷新时间信息 + ETime::__updateNow(); + ETime::__updateLast(); + + // 挂起时长 + int nWaitMS = 0; + + while (!s_bEndGame) + { + // 处理窗口消息 + EWindow::__poll(); + // 刷新时间信息 + ETime::__updateNow(); + + // 判断是否达到了刷新状态 + if (ETime::getDeltaTime() >= 17) + { + ETime::__updateLast(); + EGame::__update(); + } + else + { + // 挂起线程 + ETime::__sleep(); + } + } + + return 0; +} + +void e2d::EGame::pause() +{ + s_bPaused = true; +} + +void e2d::EGame::resume() +{ + if (isPaused()) + { + s_bPaused = false; + // 刷新当前时间 + ETime::__updateLast(); + // 重置动画和定时器 + EActionManager::__resetAllActions(); + ETimerManager::__resetAllTimers(); + } +} + +bool e2d::EGame::isPaused() +{ + return s_bPaused; +} + +void e2d::EGame::quit() +{ + s_bEndGame = true; // 这个变量将控制游戏是否结束 +} + +void e2d::EGame::uninit() +{ + // 重置窗口属性 + EWindow::__uninit(); + // 关闭输入 + EInput::__uninit(); + // 恢复计时操作 + ETime::__uninit(); + // 删除渲染相关资源 + ERenderer::__discardResources(); + + CoUninitialize(); +} + +void e2d::EGame::__update() +{ + EInput::__updateDeviceState(); // 获取用户输入 + + if (!s_bPaused) + { + ETimerManager::__update(); // 定时器管理器执行程序 + EActionManager::__update(); // 动作管理器执行程序 + ESceneManager::__update(); // 更新游戏内容 + ERenderer::__render(); // 渲染游戏画面 + } +} + +void e2d::EGame::setAppName(const EString &appname) +{ + s_sAppName = appname; +} + +e2d::EString e2d::EGame::getAppName() +{ + return s_sAppName; +} diff --git a/core/Base/Input.cpp b/core/Base/Input.cpp new file mode 100644 index 00000000..dd68bbd7 --- /dev/null +++ b/core/Base/Input.cpp @@ -0,0 +1,255 @@ +#include "..\ebase.h" + +#pragma comment(lib, "dinput8.lib") +#pragma comment(lib, "dxguid.lib") + +using namespace e2d; + +static IDirectInput8* s_pDirectInput = nullptr; // DirectInput 接口对象 +static IDirectInputDevice8* s_KeyboardDevice = nullptr; // 键盘设备接口 +static char s_KeyBuffer[256] = { 0 }; // 用于保存键盘按键信息缓冲区 +static char s_KeySecBuffer[256] = { 0 }; // 键盘消息二级缓冲区 + +static IDirectInputDevice8* s_MouseDevice = nullptr; // 鼠标设备接口 +static DIMOUSESTATE s_MouseState; // 鼠标信息存储结构体 +static DIMOUSESTATE s_MouseSecState; // 鼠标信息二级缓冲 +static POINT s_MousePosition; // 鼠标位置存储结构体 + + +void EInput::__uninit() +{ + if (s_KeyboardDevice) + s_KeyboardDevice->Unacquire(); + if (s_MouseDevice) + s_MouseDevice->Unacquire(); + + SafeReleaseInterface(&s_MouseDevice); + SafeReleaseInterface(&s_KeyboardDevice); + SafeReleaseInterface(&s_pDirectInput); +} + +HRESULT EInput::__init() +{ + ZeroMemory(s_KeyBuffer, sizeof(s_KeyBuffer)); + ZeroMemory(s_KeySecBuffer, sizeof(s_KeySecBuffer)); + ZeroMemory(&s_MouseState, sizeof(s_MouseState)); + ZeroMemory(&s_MouseSecState, sizeof(s_MouseSecState)); + + // 初始化接口对象 + HRESULT hr = DirectInput8Create( + HINST_THISCOMPONENT, + DIRECTINPUT_VERSION, + IID_IDirectInput8, + (void**)&s_pDirectInput, + NULL + ); + + if (SUCCEEDED(hr)) + { + // 初始化键盘设备 + hr = s_pDirectInput->CreateDevice( + GUID_SysKeyboard, + &s_KeyboardDevice, + NULL + ); + + if (SUCCEEDED(hr)) + { + s_KeyboardDevice->SetCooperativeLevel( + EWindow::getHWnd(), + DISCL_FOREGROUND | DISCL_NONEXCLUSIVE + ); + s_KeyboardDevice->SetDataFormat( + &c_dfDIKeyboard); + s_KeyboardDevice->Acquire(); + s_KeyboardDevice->Poll(); + } + else + { + MessageBox(nullptr, L"Keyboard not found. The game will now exit.", + L"Error", + MB_ICONERROR | MB_OK); + EGame::quit(); + return false; + } + } + + if (SUCCEEDED(hr)) + { + // 初始化鼠标设备 + hr = s_pDirectInput->CreateDevice(GUID_SysMouse, &s_MouseDevice, NULL); + + if (SUCCEEDED(hr)) + { + s_MouseDevice->SetCooperativeLevel(EWindow::getHWnd(), DISCL_FOREGROUND | DISCL_NONEXCLUSIVE); + s_MouseDevice->SetDataFormat(&c_dfDIMouse); + s_MouseDevice->Acquire(); + s_MouseDevice->Poll(); + } + else + { + MessageBox(nullptr, L"Mouse not found. The game will now exit.", + L"Error", + MB_ICONERROR | MB_OK); + EGame::quit(); + return false; + } + } + + return SUCCEEDED(hr); +} + +void EInput::__updateDeviceState() +{ + if (s_KeyboardDevice) + { + HRESULT hr = s_KeyboardDevice->Poll(); + if (FAILED(hr)) + { + hr = s_KeyboardDevice->Acquire(); + while (hr == DIERR_INPUTLOST) + hr = s_KeyboardDevice->Acquire(); + } + else + { + for (int i = 0; i < 256; i++) + s_KeySecBuffer[i] = s_KeyBuffer[i]; + + s_KeyboardDevice->GetDeviceState(sizeof(s_KeyBuffer), (void**)&s_KeyBuffer); + } + } + + if (s_MouseDevice) + { + HRESULT hr = s_MouseDevice->Poll(); + if (FAILED(hr)) + { + hr = s_MouseDevice->Acquire(); + while (hr == DIERR_INPUTLOST) + hr = s_MouseDevice->Acquire(); + } + else + { + s_MouseSecState = s_MouseState; + s_MouseDevice->GetDeviceState(sizeof(s_MouseState), (void**)&s_MouseState); + } + DIK_0; + } + + GetCursorPos(&s_MousePosition); + ScreenToClient(EWindow::getHWnd(), &s_MousePosition); +} + +bool EInput::isKeyDown(int nKeyCode) +{ + if (s_KeyBuffer[nKeyCode] & 0x80) + return true; + return false; +} + +bool EInput::isKeyPress(int nKeyCode) +{ + if ((s_KeyBuffer[nKeyCode] & 0x80) && !(s_KeySecBuffer[nKeyCode] & 0x80)) + return true; + return false; +} + +bool EInput::isKeyRelease(int nKeyCode) +{ + if (!(s_KeyBuffer[nKeyCode] & 0x80) && (s_KeySecBuffer[nKeyCode] & 0x80)) + return true; + return false; +} + +bool EInput::isMouseLButtonDown() +{ + if (s_MouseState.rgbButtons[0] & 0x80) + return true; + return false; +} + +bool EInput::isMouseRButtonDown() +{ + if (s_MouseState.rgbButtons[1] & 0x80) + return true; + return false; +} + +bool EInput::isMouseMButtonDown() +{ + if (s_MouseState.rgbButtons[2] & 0x80) + return true; + return false; +} + +bool EInput::isMouseLButtonPress() +{ + if ((s_MouseState.rgbButtons[0] & 0x80) && !(s_MouseSecState.rgbButtons[0] & 0x80)) + return true; + return false; +} + +bool EInput::isMouseRButtonPress() +{ + if ((s_MouseState.rgbButtons[1] & 0x80) && !(s_MouseSecState.rgbButtons[1] & 0x80)) + return true; + return false; +} + +bool EInput::isMouseMButtonPress() +{ + if ((s_MouseState.rgbButtons[2] & 0x80) && !(s_MouseSecState.rgbButtons[2] & 0x80)) + return true; + return false; +} + +bool EInput::isMouseLButtonRelease() +{ + if (!(s_MouseState.rgbButtons[0] & 0x80) && (s_MouseSecState.rgbButtons[0] & 0x80)) + return true; + return false; +} + +bool EInput::isMouseRButtonRelease() +{ + if (!(s_MouseState.rgbButtons[1] & 0x80) && (s_MouseSecState.rgbButtons[1] & 0x80)) + return true; + return false; +} + +bool EInput::isMouseMButtonRelease() +{ + if (!(s_MouseState.rgbButtons[2] & 0x80) && (s_MouseSecState.rgbButtons[2] & 0x80)) + return true; + return false; +} + +float EInput::getMouseX() +{ + return (float)s_MousePosition.x; +} + +float EInput::getMouseY() +{ + return (float)s_MousePosition.y; +} + +EPoint EInput::getMousePos() +{ + return EPoint((float)s_MousePosition.x, (float)s_MousePosition.y); +} + +float EInput::getMouseDeltaX() +{ + return (float)s_MouseState.lX; +} + +float EInput::getMouseDeltaY() +{ + return (float)s_MouseState.lY; +} + +float EInput::getMouseDeltaZ() +{ + return (float)s_MouseState.lZ; +} \ No newline at end of file diff --git a/core/Base/Renderer.cpp b/core/Base/Renderer.cpp new file mode 100644 index 00000000..5c3ce8e1 --- /dev/null +++ b/core/Base/Renderer.cpp @@ -0,0 +1,169 @@ +#include "..\ebase.h" +#include "..\emanagers.h" + +static ID2D1Factory * s_pDirect2dFactory = nullptr; +static ID2D1HwndRenderTarget * s_pRenderTarget = nullptr; +static ID2D1SolidColorBrush * s_pSolidBrush = nullptr; +static IWICImagingFactory * s_pIWICFactory = nullptr; +static IDWriteFactory * s_pDWriteFactory = nullptr; +static D2D1_COLOR_F s_nClearColor = D2D1::ColorF(D2D1::ColorF::Black); + + +bool e2d::ERenderer::__createDeviceIndependentResources() +{ + // 创建设备无关资源,它们的生命周期和程序的时长相同 + HRESULT hr = D2D1CreateFactory( + D2D1_FACTORY_TYPE_SINGLE_THREADED, + &s_pDirect2dFactory + ); + + ASSERT(SUCCEEDED(hr), "Create Device Independent Resources Failed!"); + + if (SUCCEEDED(hr)) + { + // 创建 WIC 绘图工厂,用于统一处理各种格式的图片 + hr = CoCreateInstance( + CLSID_WICImagingFactory, + NULL, + CLSCTX_INPROC_SERVER, + IID_IWICImagingFactory, + reinterpret_cast(&s_pIWICFactory) + ); + ASSERT(SUCCEEDED(hr), "Create WICImagingFactory Failed!"); + } + + if (SUCCEEDED(hr)) + { + // 创建 DirectWrite 工厂 + hr = DWriteCreateFactory( + DWRITE_FACTORY_TYPE_SHARED, + __uuidof(IDWriteFactory), + reinterpret_cast(&s_pDWriteFactory) + ); + ASSERT(SUCCEEDED(hr), "Create DirectWrite Factory Failed!"); + } + + return SUCCEEDED(hr); +} + +bool e2d::ERenderer::__createDeviceResources() +{ + HRESULT hr = S_OK; + + if (!s_pRenderTarget) + { + HWND hWnd = EWindow::getHWnd(); + + // 创建设备相关资源。这些资源应在 Direct3D 设备消失时重建, + // 比如当 isVisiable 被修改,等等 + RECT rc; + GetClientRect(hWnd, &rc); + + D2D1_SIZE_U size = D2D1::SizeU( + rc.right - rc.left, + rc.bottom - rc.top + ); + + // 创建一个 Direct2D 渲染目标 + hr = s_pDirect2dFactory->CreateHwndRenderTarget( + D2D1::RenderTargetProperties(), + D2D1::HwndRenderTargetProperties( + hWnd, + size), + &s_pRenderTarget + ); + + ASSERT(SUCCEEDED(hr), "Create Render Target Failed!"); + } + + if (SUCCEEDED(hr)) + { + // 创建画刷 + hr = s_pRenderTarget->CreateSolidColorBrush( + D2D1::ColorF(D2D1::ColorF::White), + &s_pSolidBrush + ); + ASSERT(SUCCEEDED(hr), "Create Solid Color Brush Failed!"); + } + return SUCCEEDED(hr); +} + +void e2d::ERenderer::__discardDeviceResources() +{ + SafeReleaseInterface(&s_pRenderTarget); + SafeReleaseInterface(&s_pSolidBrush); +} + +void e2d::ERenderer::__discardResources() +{ + SafeReleaseInterface(&s_pDirect2dFactory); + SafeReleaseInterface(&s_pRenderTarget); + SafeReleaseInterface(&s_pSolidBrush); + SafeReleaseInterface(&s_pIWICFactory); + SafeReleaseInterface(&s_pDWriteFactory); +} + +void e2d::ERenderer::__render() +{ + HRESULT hr = S_OK; + + // 创建设备相关资源 + ERenderer::__createDeviceResources(); + + // 开始渲染 + s_pRenderTarget->BeginDraw(); + // 使用背景色清空屏幕 + s_pRenderTarget->Clear(s_nClearColor); + + // 渲染场景 + ESceneManager::__render(); + + // 终止渲染 + hr = s_pRenderTarget->EndDraw(); + + if (hr == D2DERR_RECREATE_TARGET) + { + // 如果 Direct3D 设备在执行过程中消失,将丢弃当前的设备相关资源 + // 并在下一次调用时重建资源 + hr = S_OK; + ERenderer::__discardDeviceResources(); + } + + if (FAILED(hr)) + { + // 渲染时产生了未知的错误,退出游戏 + ASSERT(false, L"Renderer error!"); + EGame::quit(); + } +} + + +void e2d::ERenderer::setBackgroundColor(UINT32 color) +{ + s_nClearColor = D2D1::ColorF(color); +} + +ID2D1Factory * e2d::ERenderer::getID2D1Factory() +{ + return s_pDirect2dFactory; +} + +ID2D1HwndRenderTarget * e2d::ERenderer::getRenderTarget() +{ + return s_pRenderTarget; +} + +ID2D1SolidColorBrush * e2d::ERenderer::getSolidColorBrush() +{ + return s_pSolidBrush; +} + +IWICImagingFactory * e2d::ERenderer::getIWICImagingFactory() +{ + return s_pIWICFactory; +} + +IDWriteFactory * e2d::ERenderer::getIDWriteFactory() +{ + return s_pDWriteFactory; +} diff --git a/core/Base/Time.cpp b/core/Base/Time.cpp new file mode 100644 index 00000000..351932ec --- /dev/null +++ b/core/Base/Time.cpp @@ -0,0 +1,123 @@ +#include "..\ebase.h" + +// 上一帧与当前帧的时间间隔 +static int s_nInterval = 0; +// 游戏开始时长 +static float s_fTotalTime = 0; + + +float e2d::ETime::getTotalTime() +{ + return s_fTotalTime; +} + +int e2d::ETime::getDeltaTime() +{ + return s_nInterval; +} + + + +#if _MSC_VER > 1600 + +#include +#include +using namespace std::chrono; + + +// 游戏开始时间 +static steady_clock::time_point s_tStart; +// 当前时间 +static steady_clock::time_point s_tNow; +// 上一帧刷新时间 +static steady_clock::time_point s_tLast; + + +void e2d::ETime::__init() +{ + s_tStart = s_tLast = s_tNow = steady_clock::now(); +} + +void e2d::ETime::__uninit() +{ +} + +void e2d::ETime::__updateNow() +{ + s_tNow = steady_clock::now(); + s_fTotalTime = static_cast(duration_cast(s_tNow - s_tStart).count()) / 1000.0f; + s_nInterval = static_cast(duration_cast(s_tNow - s_tLast).count()); +} + +void e2d::ETime::__updateLast() +{ + s_tLast = s_tNow; +} + +void e2d::ETime::__sleep() +{ + // 计算挂起时长 + int nWaitMS = 16 - s_nInterval; + // 挂起线程,释放 CPU 占用 + if (nWaitMS > 1) + { + std::this_thread::sleep_for(milliseconds(nWaitMS)); + } +} + + +#else + + +#include +#pragma comment(lib, "winmm.lib") + +// 时钟频率 +static LARGE_INTEGER s_tFreq; +// 当前时间 +static LARGE_INTEGER s_tNow; +// 游戏开始时间 +static LARGE_INTEGER s_tStart; +// 上一帧画面绘制时间 +static LARGE_INTEGER s_tLast; + + + +void e2d::ETime::__init() +{ + ::timeBeginPeriod(1); // 修改时间精度 + ::QueryPerformanceFrequency(&s_tFreq); // 获取时钟频率 + ::QueryPerformanceCounter(&s_tNow); // 刷新当前时间 + s_tStart = s_tLast = s_tNow; +} + +void e2d::ETime::__uninit() +{ + ::timeEndPeriod(1); // 重置时间精度 +} + +void e2d::ETime::__updateNow() +{ + ::QueryPerformanceCounter(&s_tNow); + s_fTotalTime = static_cast(s_tNow.QuadPart - s_tStart.QuadPart) / s_tFreq.QuadPart; + s_nInterval = static_cast((s_tNow.QuadPart - s_tLast.QuadPart) * 1000LL / s_tFreq.QuadPart); +} + +void e2d::ETime::__updateLast() +{ + s_tLast = s_tNow; +} + +void e2d::ETime::__sleep() +{ + // 计算挂起时长 + int nWaitMS = 16 - s_nInterval; + // 挂起线程,释放 CPU 占用 + if (nWaitMS > 1) + { + ::Sleep(nWaitMS); + } +} + + +#endif // _MSC_VER > 1600 diff --git a/core/Base/Window.cpp b/core/Base/Window.cpp new file mode 100644 index 00000000..8506330b --- /dev/null +++ b/core/Base/Window.cpp @@ -0,0 +1,328 @@ +#include "..\ebase.h" +#include "..\emanagers.h" +#include +#pragma comment (lib ,"imm32.lib") + +// 窗口句柄 +static HWND s_HWnd = nullptr; +// 是否打开控制台 +static bool s_bShowConsole = false; + + +bool e2d::EWindow::__init(LPCTSTR sTitle, UINT32 nWidth, UINT32 nHeight, LPCTSTR pIconID /*= nullptr*/, bool bNoClose /*= false*/, bool bNoMiniSize /*= false*/, bool bTopMost /*= false*/) +{ + // 注册窗口类 + WNDCLASSEX wcex = { sizeof(WNDCLASSEX) }; + wcex.style = CS_HREDRAW | CS_VREDRAW; + wcex.lpfnWndProc = EWindow::WndProc; + wcex.cbClsExtra = 0; + wcex.cbWndExtra = sizeof(LONG_PTR); + wcex.hInstance = HINST_THISCOMPONENT; + wcex.hbrBackground = NULL; + wcex.lpszMenuName = NULL; + wcex.hCursor = LoadCursor(NULL, IDI_APPLICATION); + wcex.lpszClassName = L"Easy2DApp"; + // 设置窗口是否有关闭按钮 + if (bNoClose) + { + wcex.style |= CS_NOCLOSE; + } + // 设置程序图标 + if (pIconID) + { + wcex.hIcon = (HICON)::LoadImage( + GetModuleHandle(NULL), + pIconID, + IMAGE_ICON, + 0, + 0, + LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_DEFAULTSIZE); + } + + RegisterClassEx(&wcex); + + // 因为 CreateWindow 函数使用的是像素大小,获取系统的 DPI 以使它 + // 适应窗口缩放 + FLOAT dpiX, dpiY; + + // 工厂将返回当前的系统 DPI,这个值也将用来创建窗口 + ERenderer::getID2D1Factory()->GetDesktopDpi(&dpiX, &dpiY); + + nWidth = static_cast(ceil(nWidth * dpiX / 96.f)); + nHeight = static_cast(ceil(nHeight * dpiY / 96.f)); + + // 获取屏幕分辨率 + UINT screenWidth = static_cast(::GetSystemMetrics(SM_CXSCREEN)); + UINT screenHeight = static_cast(::GetSystemMetrics(SM_CYSCREEN)); + // 当输入的窗口大小比分辨率大时,给出警告 + WARN_IF(screenWidth < nWidth || screenHeight < nHeight, "The window is larger than screen!"); + // 取最小值 + nWidth = min(nWidth, screenWidth); + nHeight = min(nHeight, screenHeight); + + // 创建窗口样式 + DWORD dwStyle = WS_OVERLAPPED | WS_SYSMENU; + if (!bNoMiniSize) + { + dwStyle |= WS_MINIMIZEBOX; + } + // 创建窗口 + s_HWnd = CreateWindow( + L"Easy2DApp", + sTitle, + dwStyle, + 0, 0, nWidth, nHeight, + NULL, + NULL, + HINST_THISCOMPONENT, + NULL + ); + + HRESULT hr = s_HWnd ? S_OK : E_FAIL; + + if (SUCCEEDED(hr)) + { + // 禁用输入法 + EWindow::setTypewritingEnable(false); + // 设置窗口置顶 + if (bTopMost) + { + ::SetWindowPos(s_HWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); + } + // 查找是否存在控制台 + HWND hwnd = ::GetConsoleWindow(); + if (hwnd) + { + // 禁用控制台关闭按钮 + HMENU hmenu = ::GetSystemMenu(hwnd, FALSE); + ::RemoveMenu(hmenu, SC_CLOSE, MF_BYCOMMAND); + // 默认隐藏控制台 + if (!s_bShowConsole) + { + ::ShowWindow(hwnd, SW_HIDE); + } + } + } + else + { + UnregisterClass(L"Easy2DApp", HINST_THISCOMPONENT); + } + + if (FAILED(hr)) + { + MessageBox(nullptr, L"Create Window Failed!", L"Error", MB_OK); + } + + return SUCCEEDED(hr); +} + +void e2d::EWindow::__uninit() +{ + if (::GetConsoleWindow()) + { + ::FreeConsole(); + } +} + +void e2d::EWindow::__poll() +{ + static MSG msg; + + while (::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) + { + ::TranslateMessage(&msg); + ::DispatchMessage(&msg); + } +} + +float e2d::EWindow::getWidth() +{ + return ERenderer::getRenderTarget()->GetSize().width; +} + +float e2d::EWindow::getHeight() +{ + return ERenderer::getRenderTarget()->GetSize().height; +} + +e2d::ESize e2d::EWindow::getSize() +{ + D2D1_SIZE_F size = ERenderer::getRenderTarget()->GetSize(); + return ESize(size.width, size.height); +} + +HWND e2d::EWindow::getHWnd() +{ + return s_HWnd; +} + +void e2d::EWindow::setSize(UINT32 width, UINT32 height) +{ + // 获取屏幕分辨率 + int screenWidth = ::GetSystemMetrics(SM_CXSCREEN); + int screenHeight = ::GetSystemMetrics(SM_CYSCREEN); + // 获取窗口大小(包含菜单栏) + tagRECT rcWindow; + ::GetWindowRect(s_HWnd, &rcWindow); + // 获取客户区大小 + tagRECT rcClient; + ::GetClientRect(s_HWnd, &rcClient); + // 计算边框大小 + width += (rcWindow.right - rcWindow.left) - (rcClient.right - rcClient.left); + height += (rcWindow.bottom - rcWindow.top) - (rcClient.bottom - rcClient.top); + // 修改窗口大小,并设置窗口在屏幕居中 + ::MoveWindow(s_HWnd, (screenWidth - width) / 2, (screenHeight - height) / 2, width, height, TRUE); +} + +void e2d::EWindow::setTitle(const EString &title) +{ + // 设置窗口标题 + SetWindowText(s_HWnd, title); +} + +e2d::EString e2d::EWindow::getTitle() +{ + wchar_t wszTitle[MAX_PATH] = { 0 }; + ::GetWindowText(s_HWnd, wszTitle, MAX_PATH); + return wszTitle; +} + +void e2d::EWindow::showConsole(bool show /* = true */) +{ + s_bShowConsole = show; + // 查找已存在的控制台句柄 + HWND hwnd = ::GetConsoleWindow(); + // 关闭控制台 + if (show) + { + if (hwnd) + { + ::ShowWindow(hwnd, SW_SHOWNORMAL); + } + else + { + // 显示一个新控制台 + if (::AllocConsole()) + { + hwnd = ::GetConsoleWindow(); + // 重定向输入输出 + FILE * stdoutStream, * stdinStream, * stderrStream; + freopen_s(&stdoutStream, "conout$", "w+t", stdout); + freopen_s(&stdinStream, "conin$", "r+t", stdin); + freopen_s(&stderrStream, "conerr$", "w+t", stderr); + // 禁用控制台关闭按钮 + HMENU hmenu = ::GetSystemMenu(hwnd, FALSE); + ::RemoveMenu(hmenu, SC_CLOSE, MF_BYCOMMAND); + } + else + { + MessageBox(nullptr, L"Alloc Console Failed!", L"Error", MB_OK); + } + } + } + else + { + if (hwnd) + { + ::ShowWindow(hwnd, SW_HIDE); + } + } +} + +void e2d::EWindow::hideWindow() +{ + ::ShowWindow(s_HWnd, SW_HIDE); +} + +void e2d::EWindow::showWindow() +{ + ::ShowWindow(s_HWnd, SW_SHOWNORMAL); +} + +void e2d::EWindow::setTypewritingEnable(bool bEnable) +{ + static HIMC hImc = nullptr; + + if (bEnable) + { + if (hImc != nullptr) + { + ::ImmAssociateContext(EWindow::getHWnd(), hImc); + hImc = nullptr; + } + } + else + { + if (hImc == nullptr) + { + hImc = ::ImmAssociateContext(EWindow::getHWnd(), nullptr); + } + } +} + + +LRESULT e2d::EWindow::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + LRESULT result = 0; + + switch (message) + { + // 处理窗口大小变化消息 + case WM_SIZE: + { + UINT width = LOWORD(lParam); + UINT height = HIWORD(lParam); + // 如果程序接收到一个 WM_SIZE 消息,这个方法将调整渲染 + // 目标适当。它可能会调用失败,但是这里可以忽略有可能的 + // 错误,因为这个错误将在下一次调用 EndDraw 时产生 + ERenderer::getRenderTarget()->Resize(D2D1::SizeU(width, height)); + } + break; + + // 处理分辨率变化消息 + case WM_DISPLAYCHANGE: + { + // 重绘客户区 + InvalidateRect(hWnd, NULL, FALSE); + } + result = 0; + break; + + // 重绘窗口 + case WM_PAINT: + { + e2d::ERenderer::__render(); + ValidateRect(hWnd, NULL); + } + result = 0; + break; + + // 窗口关闭消息 + case WM_CLOSE: + { + e2d::EScene * pCurrentScene = e2d::ESceneManager::getCurrentScene(); + if (!pCurrentScene || pCurrentScene->onCloseWindow()) + { + e2d::EGame::quit(); + DestroyWindow(hWnd); + } + } + result = 0; + break; + + case WM_DESTROY: + { + PostQuitMessage(0); + } + result = 1; + break; + + default: + { + result = DefWindowProc(hWnd, message, wParam, lParam); + } + + } + + return result; +} \ No newline at end of file diff --git a/core/Common/ESpriteFrame.cpp b/core/Common/ESpriteFrame.cpp deleted file mode 100644 index 347fae78..00000000 --- a/core/Common/ESpriteFrame.cpp +++ /dev/null @@ -1,118 +0,0 @@ -#include "..\ecommon.h" - -e2d::ESpriteFrame::ESpriteFrame() - : m_fSourceClipX(0) - , m_fSourceClipY(0) - , m_fSourceClipWidth(0) - , m_fSourceClipHeight(0) - , m_pTexture(nullptr) -{ -} - -e2d::ESpriteFrame::ESpriteFrame(ETexture * texture) - : m_fSourceClipX(0) - , m_fSourceClipY(0) - , m_fSourceClipWidth(0) - , m_fSourceClipHeight(0) - , m_pTexture(nullptr) -{ - _setTexture(texture); -} - -e2d::ESpriteFrame::ESpriteFrame(const EString & imageFileName) - : m_fSourceClipX(0) - , m_fSourceClipY(0) - , m_fSourceClipWidth(0) - , m_fSourceClipHeight(0) - , m_pTexture(nullptr) -{ - _setTexture(new ETexture(imageFileName)); -} - -e2d::ESpriteFrame::ESpriteFrame(LPCTSTR resourceName, LPCTSTR resourceType) - : m_fSourceClipX(0) - , m_fSourceClipY(0) - , m_fSourceClipWidth(0) - , m_fSourceClipHeight(0) - , m_pTexture(nullptr) -{ - _setTexture(new ETexture(resourceName, resourceType)); -} - -e2d::ESpriteFrame::ESpriteFrame(ETexture * texture, float x, float y, float width, float height) - : m_fSourceClipX(0) - , m_fSourceClipY(0) - , m_fSourceClipWidth(0) - , m_fSourceClipHeight(0) - , m_pTexture(nullptr) -{ - _setTexture(texture); - _clipTexture(x, y, width, height); -} - -e2d::ESpriteFrame::ESpriteFrame(const EString & imageFileName, float x, float y, float width, float height) - : m_fSourceClipX(0) - , m_fSourceClipY(0) - , m_fSourceClipWidth(0) - , m_fSourceClipHeight(0) - , m_pTexture(nullptr) -{ - _setTexture(new ETexture(imageFileName)); - _clipTexture(x, y, width, height); -} - -e2d::ESpriteFrame::ESpriteFrame(LPCTSTR resourceName, LPCTSTR resourceType, float x, float y, float width, float height) - : m_fSourceClipX(0) - , m_fSourceClipY(0) - , m_fSourceClipWidth(0) - , m_fSourceClipHeight(0) - , m_pTexture(nullptr) -{ - _setTexture(new ETexture(resourceName, resourceType)); - _clipTexture(x, y, width, height); -} - -e2d::ESpriteFrame::~ESpriteFrame() -{ - SafeRelease(&m_pTexture); -} - -float e2d::ESpriteFrame::getWidth() const -{ - return m_fSourceClipWidth; -} - -float e2d::ESpriteFrame::getHeight() const -{ - return m_fSourceClipHeight; -} - -e2d::ETexture * e2d::ESpriteFrame::getTexture() const -{ - return m_pTexture; -} - -void e2d::ESpriteFrame::_setTexture(ETexture * texture) -{ - if (texture) - { - SafeRelease(&m_pTexture); - m_pTexture = texture; - m_pTexture->retain(); - m_fSourceClipX = 0; - m_fSourceClipY = 0; - m_fSourceClipWidth = texture->getSourceWidth(); - m_fSourceClipHeight = texture->getSourceHeight(); - } -} - -void e2d::ESpriteFrame::_clipTexture(float x, float y, float width, float height) -{ - if (m_pTexture) - { - m_fSourceClipX = min(max(x, 0), m_pTexture->getSourceWidth()); - m_fSourceClipY = min(max(y, 0), m_pTexture->getSourceHeight()); - m_fSourceClipWidth = min(max(width, 0), m_pTexture->getSourceWidth() - m_fSourceClipX); - m_fSourceClipHeight = min(max(height, 0), m_pTexture->getSourceHeight() - m_fSourceClipY); - } -} diff --git a/core/Common/EFont.cpp b/core/Common/Font.cpp similarity index 95% rename from core/Common/EFont.cpp rename to core/Common/Font.cpp index fe722cc7..49377def 100644 --- a/core/Common/EFont.cpp +++ b/core/Common/Font.cpp @@ -1,5 +1,4 @@ #include "..\enodes.h" -#include "..\Win\winbase.h" e2d::EFont::EFont() : m_pTextFormat(nullptr) @@ -84,7 +83,7 @@ void e2d::EFont::_initTextFormat() { SafeReleaseInterface(&m_pTextFormat); - HRESULT hr = GetDirectWriteFactory()->CreateTextFormat( + HRESULT hr = ERenderer::getIDWriteFactory()->CreateTextFormat( m_sFontFamily, NULL, DWRITE_FONT_WEIGHT(m_FontWeight), diff --git a/core/Common/ETexture.cpp b/core/Common/Image.cpp similarity index 78% rename from core/Common/ETexture.cpp rename to core/Common/Image.cpp index e8e94b37..d46bb6c3 100644 --- a/core/Common/ETexture.cpp +++ b/core/Common/Image.cpp @@ -1,5 +1,4 @@ #include "..\enodes.h" -#include "..\Win\winbase.h" #include @@ -25,51 +24,51 @@ static std::map s_mBitmapsFromFile; static std::map s_mBitmapsFromResource; -e2d::ETexture::ETexture() +e2d::EImage::EImage() : m_pBitmap(nullptr) { } -e2d::ETexture::ETexture(const EString & fileName) +e2d::EImage::EImage(LPCTSTR fileName) { this->loadFromFile(fileName); } -e2d::ETexture::ETexture(LPCTSTR resourceName, LPCTSTR resourceType) +e2d::EImage::EImage(LPCTSTR resourceName, LPCTSTR resourceType) { this->loadFromResource(resourceName, resourceType); } -e2d::ETexture::~ETexture() +e2d::EImage::~EImage() { } -void e2d::ETexture::loadFromFile(const EString & fileName) +void e2d::EImage::loadFromFile(const EString & fileName) { - WARN_IF(fileName.isEmpty(), "ETexture cannot load bitmap from NULL file name."); + WARN_IF(fileName.isEmpty(), "EImage cannot load bitmap from NULL file name."); if (fileName.isEmpty()) return; - if (!e2d::ETexture::preload(fileName)) + if (!e2d::EImage::preload(fileName)) { - WARN_IF(true, "Load ETexture from file failed!"); + WARN_IF(true, "Load EImage from file failed!"); return; } m_pBitmap = s_mBitmapsFromFile.at(fileName.hash()); } -void e2d::ETexture::loadFromResource(LPCTSTR resourceName, LPCTSTR resourceType) +void e2d::EImage::loadFromResource(LPCTSTR resourceName, LPCTSTR resourceType) { - WARN_IF(!resourceName || !resourceType, "ETexture cannot load bitmap from NULL resource."); + WARN_IF(!resourceName || !resourceType, "EImage cannot load bitmap from NULL resource."); if (!resourceName || !resourceType) return; - if (!e2d::ETexture::preload(resourceName, resourceType)) + if (!e2d::EImage::preload(resourceName, resourceType)) { - WARN_IF(true, "Load ETexture from resource failed!"); + WARN_IF(true, "Load EImage from resource failed!"); return; } @@ -81,7 +80,7 @@ void e2d::ETexture::loadFromResource(LPCTSTR resourceName, LPCTSTR resourceType) m_pBitmap = s_mBitmapsFromResource.at(key); } -float e2d::ETexture::getSourceWidth() const +float e2d::EImage::getSourceWidth() const { if (m_pBitmap) { @@ -93,7 +92,7 @@ float e2d::ETexture::getSourceWidth() const } } -float e2d::ETexture::getSourceHeight() const +float e2d::EImage::getSourceHeight() const { if (m_pBitmap) { @@ -105,7 +104,7 @@ float e2d::ETexture::getSourceHeight() const } } -e2d::ESize e2d::ETexture::getSourceSize() const +e2d::ESize e2d::EImage::getSourceSize() const { if (m_pBitmap) { @@ -117,7 +116,7 @@ e2d::ESize e2d::ETexture::getSourceSize() const } } -bool e2d::ETexture::preload(const EString & fileName) +bool e2d::EImage::preload(const EString & fileName) { if (s_mBitmapsFromFile.find(fileName.hash()) != s_mBitmapsFromFile.end()) { @@ -133,7 +132,7 @@ bool e2d::ETexture::preload(const EString & fileName) ID2D1Bitmap *pBitmap = nullptr; // 创建解码器 - hr = GetImagingFactory()->CreateDecoderFromFilename( + hr = ERenderer::getIWICImagingFactory()->CreateDecoderFromFilename( fileName, NULL, GENERIC_READ, @@ -151,7 +150,7 @@ bool e2d::ETexture::preload(const EString & fileName) { // 创建图片格式转换器 // (DXGI_FORMAT_B8G8R8A8_UNORM + D2D1_ALPHA_MODE_PREMULTIPLIED). - hr = GetImagingFactory()->CreateFormatConverter(&pConverter); + hr = ERenderer::getIWICImagingFactory()->CreateFormatConverter(&pConverter); } if (SUCCEEDED(hr)) { @@ -168,7 +167,7 @@ bool e2d::ETexture::preload(const EString & fileName) if (SUCCEEDED(hr)) { // 从 WIC 位图创建一个 Direct2D 位图 - hr = GetRenderTarget()->CreateBitmapFromWicBitmap( + hr = ERenderer::getRenderTarget()->CreateBitmapFromWicBitmap( pConverter, NULL, &pBitmap @@ -193,7 +192,7 @@ bool e2d::ETexture::preload(const EString & fileName) return SUCCEEDED(hr); } -bool e2d::ETexture::preload(LPCTSTR resourceName, LPCTSTR resourceType) +bool e2d::EImage::preload(LPCTSTR resourceName, LPCTSTR resourceType) { std::hash h; @@ -251,7 +250,7 @@ bool e2d::ETexture::preload(LPCTSTR resourceName, LPCTSTR resourceType) if (SUCCEEDED(hr)) { // 创建 WIC 流 - hr = GetImagingFactory()->CreateStream(&pStream); + hr = ERenderer::getIWICImagingFactory()->CreateStream(&pStream); } if (SUCCEEDED(hr)) @@ -266,7 +265,7 @@ bool e2d::ETexture::preload(LPCTSTR resourceName, LPCTSTR resourceType) if (SUCCEEDED(hr)) { // 创建流的解码器 - hr = GetImagingFactory()->CreateDecoderFromStream( + hr = ERenderer::getIWICImagingFactory()->CreateDecoderFromStream( pStream, NULL, WICDecodeMetadataCacheOnLoad, @@ -284,7 +283,7 @@ bool e2d::ETexture::preload(LPCTSTR resourceName, LPCTSTR resourceType) { // 创建图片格式转换器 // (DXGI_FORMAT_B8G8R8A8_UNORM + D2D1_ALPHA_MODE_PREMULTIPLIED). - hr = GetImagingFactory()->CreateFormatConverter(&pConverter); + hr = ERenderer::getIWICImagingFactory()->CreateFormatConverter(&pConverter); } if (SUCCEEDED(hr)) @@ -303,7 +302,7 @@ bool e2d::ETexture::preload(LPCTSTR resourceName, LPCTSTR resourceType) if (SUCCEEDED(hr)) { // 从 WIC 位图创建一个 Direct2D 位图 - hr = GetRenderTarget()->CreateBitmapFromWicBitmap( + hr = ERenderer::getRenderTarget()->CreateBitmapFromWicBitmap( pConverter, NULL, &pBitmap @@ -335,7 +334,7 @@ bool e2d::ETexture::preload(LPCTSTR resourceName, LPCTSTR resourceType) return SUCCEEDED(hr); } -void e2d::ETexture::clearCache() +void e2d::EImage::clearCache() { for (auto child = s_mBitmapsFromFile.begin(); child != s_mBitmapsFromFile.end(); child++) { @@ -349,7 +348,7 @@ void e2d::ETexture::clearCache() s_mBitmapsFromResource.clear(); } -ID2D1Bitmap * e2d::ETexture::_getBitmap() +ID2D1Bitmap * e2d::EImage::_getBitmap() { return m_pBitmap; } diff --git a/core/Common/Keyframe.cpp b/core/Common/Keyframe.cpp new file mode 100644 index 00000000..4f62950e --- /dev/null +++ b/core/Common/Keyframe.cpp @@ -0,0 +1,118 @@ +#include "..\ecommon.h" + +e2d::EKeyframe::EKeyframe() + : m_fSourceClipX(0) + , m_fSourceClipY(0) + , m_fSourceClipWidth(0) + , m_fSourceClipHeight(0) + , m_pImage(nullptr) +{ +} + +e2d::EKeyframe::EKeyframe(EImage * texture) + : m_fSourceClipX(0) + , m_fSourceClipY(0) + , m_fSourceClipWidth(0) + , m_fSourceClipHeight(0) + , m_pImage(nullptr) +{ + _setImage(texture); +} + +e2d::EKeyframe::EKeyframe(const EString & imageFileName) + : m_fSourceClipX(0) + , m_fSourceClipY(0) + , m_fSourceClipWidth(0) + , m_fSourceClipHeight(0) + , m_pImage(nullptr) +{ + _setImage(new EImage(imageFileName)); +} + +e2d::EKeyframe::EKeyframe(LPCTSTR resourceName, LPCTSTR resourceType) + : m_fSourceClipX(0) + , m_fSourceClipY(0) + , m_fSourceClipWidth(0) + , m_fSourceClipHeight(0) + , m_pImage(nullptr) +{ + _setImage(new EImage(resourceName, resourceType)); +} + +e2d::EKeyframe::EKeyframe(EImage * texture, float x, float y, float width, float height) + : m_fSourceClipX(0) + , m_fSourceClipY(0) + , m_fSourceClipWidth(0) + , m_fSourceClipHeight(0) + , m_pImage(nullptr) +{ + _setImage(texture); + _clipTexture(x, y, width, height); +} + +e2d::EKeyframe::EKeyframe(const EString & imageFileName, float x, float y, float width, float height) + : m_fSourceClipX(0) + , m_fSourceClipY(0) + , m_fSourceClipWidth(0) + , m_fSourceClipHeight(0) + , m_pImage(nullptr) +{ + _setImage(new EImage(imageFileName)); + _clipTexture(x, y, width, height); +} + +e2d::EKeyframe::EKeyframe(LPCTSTR resourceName, LPCTSTR resourceType, float x, float y, float width, float height) + : m_fSourceClipX(0) + , m_fSourceClipY(0) + , m_fSourceClipWidth(0) + , m_fSourceClipHeight(0) + , m_pImage(nullptr) +{ + _setImage(new EImage(resourceName, resourceType)); + _clipTexture(x, y, width, height); +} + +e2d::EKeyframe::~EKeyframe() +{ + SafeRelease(&m_pImage); +} + +float e2d::EKeyframe::getWidth() const +{ + return m_fSourceClipWidth; +} + +float e2d::EKeyframe::getHeight() const +{ + return m_fSourceClipHeight; +} + +e2d::EImage * e2d::EKeyframe::getImage() const +{ + return m_pImage; +} + +void e2d::EKeyframe::_setImage(EImage * texture) +{ + if (texture) + { + SafeRelease(&m_pImage); + m_pImage = texture; + m_pImage->retain(); + m_fSourceClipX = 0; + m_fSourceClipY = 0; + m_fSourceClipWidth = texture->getSourceWidth(); + m_fSourceClipHeight = texture->getSourceHeight(); + } +} + +void e2d::EKeyframe::_clipTexture(float x, float y, float width, float height) +{ + if (m_pImage) + { + m_fSourceClipX = min(max(x, 0), m_pImage->getSourceWidth()); + m_fSourceClipY = min(max(y, 0), m_pImage->getSourceHeight()); + m_fSourceClipWidth = min(max(width, 0), m_pImage->getSourceWidth() - m_fSourceClipX); + m_fSourceClipHeight = min(max(height, 0), m_pImage->getSourceHeight() - m_fSourceClipY); + } +} diff --git a/core/Common/EObject.cpp b/core/Common/Object.cpp similarity index 100% rename from core/Common/EObject.cpp rename to core/Common/Object.cpp diff --git a/core/Base/EScene.cpp b/core/Common/Scene.cpp similarity index 76% rename from core/Base/EScene.cpp rename to core/Common/Scene.cpp index 39ce17ef..737bc9a7 100644 --- a/core/Base/EScene.cpp +++ b/core/Common/Scene.cpp @@ -3,7 +3,6 @@ #include "..\emanagers.h" #include "..\etools.h" #include "..\eactions.h" -#include "..\Win\winbase.h" #include e2d::EScene::EScene() @@ -16,7 +15,7 @@ e2d::EScene::EScene() m_pRoot->_onEnter(); m_pRoot->_setParentScene(this); m_pRoot->setPivot(0, 0); - m_pRoot->_setSize(EApp::getWidth(), EApp::getHeight()); + m_pRoot->_setSize(EWindow::getWidth(), EWindow::getHeight()); } e2d::EScene::~EScene() @@ -24,43 +23,27 @@ e2d::EScene::~EScene() SafeRelease(&m_pRoot); } -void e2d::EScene::onEnter() -{ -} - -void e2d::EScene::onExit() -{ -} - -bool e2d::EScene::onActivate() -{ - return false; -} - -bool e2d::EScene::onInactive() -{ - return false; -} - -bool e2d::EScene::onCloseWindow() -{ - return true; -} - void e2d::EScene::_render() { - // 访问根节点 - m_pRoot->_update(); + m_pRoot->_render(); if (m_bGeometryVisiable) { // 恢复矩阵转换 - GetRenderTarget()->SetTransform(D2D1::Matrix3x2F::Identity()); + ERenderer::getRenderTarget()->SetTransform(D2D1::Matrix3x2F::Identity()); // 绘制所有几何图形 m_pRoot->_drawGeometry(); } } +void e2d::EScene::_update() +{ + // 执行 onUpdate 函数 + this->onUpdate(); + // 更新根节点 + m_pRoot->_update(); +} + void e2d::EScene::add(ENode * child, int order /* = 0 */) { m_pRoot->addChild(child, order); @@ -76,7 +59,7 @@ void e2d::EScene::remove(const EString &childName) return m_pRoot->removeChild(childName); } -std::vector& e2d::EScene::getChildren() +std::vector e2d::EScene::getChildren() { return m_pRoot->m_vChildren; } diff --git a/core/Common/EString.cpp b/core/Common/String.cpp similarity index 97% rename from core/Common/EString.cpp rename to core/Common/String.cpp index 55dff9c7..da8492ec 100644 --- a/core/Common/EString.cpp +++ b/core/Common/String.cpp @@ -22,7 +22,7 @@ EString::EString(const wchar_t *str) { if (str) { - _size = wcslen(str); + _size = static_cast(wcslen(str)); _string = new wchar_t[_size + 1]; wcscpy_s(_string, _size + 1, str); } @@ -80,7 +80,7 @@ EString &EString::operator=(const wchar_t *str) if (str) { delete[] _string; - _size = wcslen(str); + _size = static_cast(wcslen(str)); _string = new wchar_t[_size + 1]; wcscpy_s(_string, _size + 1, str); } @@ -214,7 +214,7 @@ EString &EString::operator+=(const wchar_t *str) { if (!str) return *this; - int d_size = wcslen(str); + int d_size = static_cast(wcslen(str)); if (d_size == 0) return *this; wchar_t *str_temp = new wchar_t[_size + d_size + 1]; @@ -326,7 +326,7 @@ std::wistream & e2d::operator>>(std::wistream &cin, EString &str) str._string = new wchar_t[limit_string_size]; cin >> std::setw(limit_string_size) >> str._string; - str._size = wcslen(str._string); + str._size = static_cast(wcslen(str._string)); return cin; } diff --git a/core/Event/PhysicsEvent.cpp b/core/Event/PhysicsEvent.cpp new file mode 100644 index 00000000..49802df3 --- /dev/null +++ b/core/Event/PhysicsEvent.cpp @@ -0,0 +1,20 @@ +#include "..\ecommon.h" + +e2d::EPhysicsEvent::INTERSECT_RELATION e2d::EPhysicsEvent::s_nRelation = e2d::EPhysicsEvent::UNKNOWN; +e2d::EGeometry * e2d::EPhysicsEvent::s_pActiveGeometry = nullptr; +e2d::EGeometry * e2d::EPhysicsEvent::s_pPassiveGeometry = nullptr; + +e2d::EPhysicsEvent::INTERSECT_RELATION e2d::EPhysicsEvent::getMsg() +{ + return EPhysicsEvent::s_nRelation; +} + +e2d::EGeometry * e2d::EPhysicsEvent::getActiveGeometry() +{ + return EPhysicsEvent::s_pActiveGeometry; +} + +e2d::EGeometry * e2d::EPhysicsEvent::getPassiveGeometry() +{ + return EPhysicsEvent::s_pPassiveGeometry; +} diff --git a/core/Geometry/ECircle.cpp b/core/Geometry/Circle.cpp similarity index 92% rename from core/Geometry/ECircle.cpp rename to core/Geometry/Circle.cpp index b6cc178f..ea014242 100644 --- a/core/Geometry/ECircle.cpp +++ b/core/Geometry/Circle.cpp @@ -1,6 +1,5 @@ #include "..\egeometry.h" #include "..\enodes.h" -#include "..\Win\winbase.h" e2d::ECircle::ECircle() : m_pD2dCircle(nullptr) @@ -35,7 +34,7 @@ void e2d::ECircle::_setCircle(EPoint center, float radius) { SafeReleaseInterface(&m_pD2dCircle); - GetFactory()->CreateEllipseGeometry( + ERenderer::getID2D1Factory()->CreateEllipseGeometry( D2D1::Ellipse( D2D1::Point2F( center.x, diff --git a/core/Geometry/EEllipse.cpp b/core/Geometry/Ellipse.cpp similarity index 92% rename from core/Geometry/EEllipse.cpp rename to core/Geometry/Ellipse.cpp index 264b600d..7e325ed1 100644 --- a/core/Geometry/EEllipse.cpp +++ b/core/Geometry/Ellipse.cpp @@ -1,6 +1,5 @@ #include "..\egeometry.h" #include "..\enodes.h" -#include "..\Win\winbase.h" e2d::EEllipse::EEllipse() : m_pD2dEllipse(nullptr) @@ -35,7 +34,7 @@ void e2d::EEllipse::_setEllipse(EPoint center, float radiusX, float radiusY) { SafeReleaseInterface(&m_pD2dEllipse); - GetFactory()->CreateEllipseGeometry( + ERenderer::getID2D1Factory()->CreateEllipseGeometry( D2D1::Ellipse( D2D1::Point2F( center.x, diff --git a/core/Geometry/EGeometry.cpp b/core/Geometry/Geometry.cpp similarity index 79% rename from core/Geometry/EGeometry.cpp rename to core/Geometry/Geometry.cpp index daaab97f..4ffb1c80 100644 --- a/core/Geometry/EGeometry.cpp +++ b/core/Geometry/Geometry.cpp @@ -1,7 +1,6 @@ #include "..\egeometry.h" #include "..\emanagers.h" #include "..\enodes.h" -#include "..\Win\winbase.h" e2d::EGeometry::EGeometry() : m_nCategoryBitmask(0) @@ -63,21 +62,20 @@ void e2d::EGeometry::_render() { if (m_pTransformedGeometry) { + ID2D1SolidColorBrush * pBrush = ERenderer::getSolidColorBrush(); // 创建画刷 - GetRenderTarget()->CreateSolidColorBrush( + ERenderer::getRenderTarget()->CreateSolidColorBrush( D2D1::ColorF( m_nColor, m_fOpacity), - &GetSolidColorBrush() + &pBrush ); // 绘制几何形状 - GetRenderTarget()->DrawGeometry(m_pTransformedGeometry, GetSolidColorBrush()); - // 释放临时资源 - SafeReleaseInterface(&GetSolidColorBrush()); + ERenderer::getRenderTarget()->DrawGeometry(m_pTransformedGeometry, pBrush); } } -e2d::EPhysicsMsg::INTERSECT_RELATION e2d::EGeometry::_intersectWith(EGeometry * pGeometry) +e2d::EPhysicsEvent::INTERSECT_RELATION e2d::EGeometry::_intersectWith(EGeometry * pGeometry) { if (m_pTransformedGeometry && pGeometry->m_pTransformedGeometry) { @@ -89,9 +87,9 @@ e2d::EPhysicsMsg::INTERSECT_RELATION e2d::EGeometry::_intersectWith(EGeometry * &relation ); - return EPhysicsMsg::INTERSECT_RELATION(relation); + return EPhysicsEvent::INTERSECT_RELATION(relation); } - return EPhysicsMsg::UNKNOWN; + return EPhysicsEvent::UNKNOWN; } void e2d::EGeometry::_transform() @@ -102,7 +100,7 @@ void e2d::EGeometry::_transform() SafeReleaseInterface(&m_pTransformedGeometry); // 根据父节点转换几何图形 - GetFactory()->CreateTransformedGeometry( + ERenderer::getID2D1Factory()->CreateTransformedGeometry( _getD2dGeometry(), m_pParentNode->m_MatriFinal, &m_pTransformedGeometry diff --git a/core/Geometry/ERectangle.cpp b/core/Geometry/Rectangle.cpp similarity index 92% rename from core/Geometry/ERectangle.cpp rename to core/Geometry/Rectangle.cpp index ef7143ab..01489e92 100644 --- a/core/Geometry/ERectangle.cpp +++ b/core/Geometry/Rectangle.cpp @@ -1,6 +1,5 @@ #include "..\egeometry.h" #include "..\enodes.h" -#include "..\Win\winbase.h" e2d::ERectangle::ERectangle() : m_pD2dRectangle(nullptr) @@ -33,7 +32,7 @@ void e2d::ERectangle::_setRect(float left, float top, float right, float bottom) { SafeReleaseInterface(&m_pD2dRectangle); - GetFactory()->CreateRectangleGeometry( + ERenderer::getID2D1Factory()->CreateRectangleGeometry( D2D1::RectF(left, top, right, bottom), &m_pD2dRectangle ); diff --git a/core/Listener/EListenerKeyboard.cpp b/core/Listener/EListenerKeyboard.cpp deleted file mode 100644 index 046ba683..00000000 --- a/core/Listener/EListenerKeyboard.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include "..\elisteners.h" -#include "..\emanagers.h" - -e2d::EListenerKeyboard::EListenerKeyboard() - : EListener() - , m_Callback(nullptr) -{ -} - -e2d::EListenerKeyboard::EListenerKeyboard(const EString & name) - : EListener(name) - , m_Callback(nullptr) -{ -} - -e2d::EListenerKeyboard::EListenerKeyboard(const KEY_LISTENER_CALLBACK & callback) - : EListener() - , m_Callback(callback) -{ -} - -e2d::EListenerKeyboard::EListenerKeyboard(const EString & name, const KEY_LISTENER_CALLBACK & callback) - : EListener(name) - , m_Callback(callback) -{ -} - -void e2d::EListenerKeyboard::_callOn() -{ - if (m_Callback) - { - m_Callback(); - } -} - -void e2d::EListenerKeyboard::setCallback(const KEY_LISTENER_CALLBACK & callback) -{ - m_Callback = callback; -} - -void e2d::EListenerKeyboard::bindWith(EScene * pParentScene) -{ - WARN_IF(m_pParentNode != nullptr, "A listener cannot bind with two object."); - - if (pParentScene) - { - EMsgManager::bindListener(this, pParentScene); - } -} - -void e2d::EListenerKeyboard::bindWith(ENode * pParentNode) -{ - WARN_IF(m_pParentNode != nullptr, "A listener cannot bind with two object."); - - if (pParentNode) - { - EMsgManager::bindListener(this, pParentNode); - } -} \ No newline at end of file diff --git a/core/Listener/EListenerKeyboardPress.cpp b/core/Listener/EListenerKeyboardPress.cpp deleted file mode 100644 index 096f0faa..00000000 --- a/core/Listener/EListenerKeyboardPress.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include "..\elisteners.h" - -e2d::EListenerKeyboardPress::EListenerKeyboardPress() - : EListenerKeyboard() -{ -} - -e2d::EListenerKeyboardPress::EListenerKeyboardPress(const EString & name) - : EListenerKeyboard(name) -{ -} - -e2d::EListenerKeyboardPress::EListenerKeyboardPress(const KEY_LISTENER_CALLBACK & callback) - : EListenerKeyboard(callback) -{ -} - -e2d::EListenerKeyboardPress::EListenerKeyboardPress(const EString & name, const KEY_LISTENER_CALLBACK & callback) - : EListenerKeyboard(name, callback) -{ -} - -void e2d::EListenerKeyboardPress::_callOn() -{ - if (EKeyboardMsg::getMsg() == EKeyboardMsg::KEY_DOWN) - { - if (m_Callback) - { - m_Callback(); - } - } -} diff --git a/core/Listener/EListenerMouse.cpp b/core/Listener/EListenerMouse.cpp deleted file mode 100644 index 12b1bb64..00000000 --- a/core/Listener/EListenerMouse.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include "..\elisteners.h" -#include "..\emanagers.h" - -e2d::EListenerMouse::EListenerMouse() - : EListener() - , m_Callback(nullptr) -{ -} - -e2d::EListenerMouse::EListenerMouse(const EString & name) - : EListener(name) - , m_Callback(nullptr) -{ -} - -e2d::EListenerMouse::EListenerMouse(const MOUSE_LISTENER_CALLBACK & callback) - : EListener() - , m_Callback(callback) -{ -} - -e2d::EListenerMouse::EListenerMouse(const EString & name, const MOUSE_LISTENER_CALLBACK & callback) - : EListener(name) - , m_Callback(callback) -{ -} - -void e2d::EListenerMouse::_callOn() -{ - if (m_Callback) - { - m_Callback(); - } -} - -void e2d::EListenerMouse::setCallback(const MOUSE_LISTENER_CALLBACK & callback) -{ - m_Callback = callback; -} - -void e2d::EListenerMouse::bindWith(EScene * pParentScene) -{ - WARN_IF(m_pParentNode != nullptr, "A listener cannot bind with two object."); - - if (pParentScene) - { - EMsgManager::bindListener(this, pParentScene); - } -} - -void e2d::EListenerMouse::bindWith(ENode * pParentNode) -{ - WARN_IF(m_pParentNode != nullptr, "A listener cannot bind with two object."); - - if (pParentNode != nullptr) - { - EMsgManager::bindListener(this, pParentNode); - } -} diff --git a/core/Listener/EListenerMouseClick.cpp b/core/Listener/EListenerMouseClick.cpp deleted file mode 100644 index dff2e8d0..00000000 --- a/core/Listener/EListenerMouseClick.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include "..\elisteners.h" - -e2d::EListenerMouseClick::EListenerMouseClick() - : EListenerMouse() - , m_bPressed(false) - , m_Callback(nullptr) -{ -} - -e2d::EListenerMouseClick::EListenerMouseClick(const EString & name) - : EListenerMouse(name) - , m_bPressed(false) - , m_Callback(nullptr) -{ -} - -e2d::EListenerMouseClick::EListenerMouseClick(const MOUSE_CLICK_LISTENER_CALLBACK & callback) - : EListenerMouse() - , m_Callback(callback) - , m_bPressed(false) -{ -} - -e2d::EListenerMouseClick::EListenerMouseClick(const EString & name, const MOUSE_CLICK_LISTENER_CALLBACK & callback) - : EListenerMouse(name) - , m_Callback(callback) - , m_bPressed(false) -{ -} - -void e2d::EListenerMouseClick::_callOn() -{ - if (EMouseMsg::getMsg() == EMouseMsg::LBUTTON_DOWN || - EMouseMsg::getMsg() == EMouseMsg::LBUTTON_DBLCLK) - { - m_bPressed = true; - } - else if (m_bPressed && EMouseMsg::getMsg() == EMouseMsg::LBUTTON_UP) - { - if (m_Callback) - { - m_Callback(EMouseMsg::getPos()); - } - m_bPressed = false; - } -} - -void e2d::EListenerMouseClick::setCallback(const MOUSE_CLICK_LISTENER_CALLBACK & callback) -{ - m_Callback = callback; -} diff --git a/core/Listener/EListenerMouseDoubleClick.cpp b/core/Listener/EListenerMouseDoubleClick.cpp deleted file mode 100644 index 045d5dfe..00000000 --- a/core/Listener/EListenerMouseDoubleClick.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include "..\elisteners.h" - -e2d::EListenerMouseDoubleClick::EListenerMouseDoubleClick() - : EListenerMouse() - , m_bPressed(false) - , m_Callback(nullptr) -{ -} - -e2d::EListenerMouseDoubleClick::EListenerMouseDoubleClick(const EString & name) - : EListenerMouse(name) - , m_bPressed(false) - , m_Callback(nullptr) -{ -} - -e2d::EListenerMouseDoubleClick::EListenerMouseDoubleClick(const MOUSE_DBLCLK_LISTENER_CALLBACK & callback) - : EListenerMouse() - , m_Callback(callback) - , m_bPressed(false) -{ -} - -e2d::EListenerMouseDoubleClick::EListenerMouseDoubleClick(const EString & name, const MOUSE_DBLCLK_LISTENER_CALLBACK & callback) - : EListenerMouse(name) - , m_Callback(callback) - , m_bPressed(false) -{ -} - -void e2d::EListenerMouseDoubleClick::_callOn() -{ - if (EMouseMsg::getMsg() == EMouseMsg::LBUTTON_DOWN) - { - m_bPressed = false; - } - else if (EMouseMsg::getMsg() == EMouseMsg::LBUTTON_DBLCLK) - { - m_bPressed = true; - } - else if (m_bPressed && EMouseMsg::getMsg() == EMouseMsg::LBUTTON_UP) - { - if (m_Callback) - { - m_Callback(EMouseMsg::getPos()); - } - m_bPressed = false; - } -} - -void e2d::EListenerMouseDoubleClick::setCallback(const MOUSE_DBLCLK_LISTENER_CALLBACK & callback) -{ - m_Callback = callback; -} diff --git a/core/Listener/EListenerMouseDrag.cpp b/core/Listener/EListenerMouseDrag.cpp deleted file mode 100644 index 1f2d1d99..00000000 --- a/core/Listener/EListenerMouseDrag.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include "..\elisteners.h" - -e2d::EListenerMouseDrag::EListenerMouseDrag() - : EListenerMouse() - , m_Callback(nullptr) -{ -} - -e2d::EListenerMouseDrag::EListenerMouseDrag(const EString & name) - : EListenerMouse(name) - , m_Callback(nullptr) -{ -} - -e2d::EListenerMouseDrag::EListenerMouseDrag(const MOUSE_DRAG_LISTENER_CALLBACK & callback) - : EListenerMouse() - , m_Callback(callback) -{ -} - -e2d::EListenerMouseDrag::EListenerMouseDrag(const EString & name, const MOUSE_DRAG_LISTENER_CALLBACK & callback) - : EListenerMouse(name) - , m_Callback(callback) -{ -} - -void e2d::EListenerMouseDrag::_callOn() -{ - if (EMouseMsg::getMsg() == EMouseMsg::LBUTTON_DOWN || - EMouseMsg::getMsg() == EMouseMsg::LBUTTON_DBLCLK) - { - m_Begin = EMouseMsg::getPos(); - } - else if (EMouseMsg::isLButtonDown() && EMouseMsg::getMsg() == EMouseMsg::MOVE) - { - if (m_Callback) - { - m_Callback(m_Begin, EMouseMsg::getPos()); - } - } -} - -void e2d::EListenerMouseDrag::setCallback(const MOUSE_DRAG_LISTENER_CALLBACK & callback) -{ - m_Callback = callback; -} diff --git a/core/Listener/EListenerMousePress.cpp b/core/Listener/EListenerMousePress.cpp deleted file mode 100644 index 9dbe6b94..00000000 --- a/core/Listener/EListenerMousePress.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include "..\elisteners.h" - -e2d::EListenerMousePress::EListenerMousePress() - : EListenerMouse() - , m_Callback(nullptr) -{ -} - -e2d::EListenerMousePress::EListenerMousePress(const EString & name) - : EListenerMouse(name) - , m_Callback(nullptr) -{ -} - -e2d::EListenerMousePress::EListenerMousePress(const MOUSE_PRESS_LISTENER_CALLBACK & callback) - : EListenerMouse() - , m_Callback(callback) -{ -} - -e2d::EListenerMousePress::EListenerMousePress(const EString & name, const MOUSE_PRESS_LISTENER_CALLBACK & callback) - : EListenerMouse(name) - , m_Callback(callback) -{ -} - -void e2d::EListenerMousePress::_callOn() -{ - if (EMouseMsg::getMsg() == EMouseMsg::LBUTTON_DOWN || - EMouseMsg::getMsg() == EMouseMsg::LBUTTON_DBLCLK) - { - if (m_Callback) - { - m_Callback(EMouseMsg::getPos()); - } - } -} - -void e2d::EListenerMousePress::setCallback(const MOUSE_PRESS_LISTENER_CALLBACK & callback) -{ - m_Callback = callback; -} diff --git a/core/Listener/EListener.cpp b/core/Listener/Listener.cpp similarity index 87% rename from core/Listener/EListener.cpp rename to core/Listener/Listener.cpp index 8d2ddb0f..8fc9881c 100644 --- a/core/Listener/EListener.cpp +++ b/core/Listener/Listener.cpp @@ -1,4 +1,5 @@ #include "..\elisteners.h" +#include "..\emanagers.h" #include "..\enodes.h" e2d::EListener::EListener() @@ -62,9 +63,9 @@ bool e2d::EListener::_isReady() const { if (m_bRunning && m_pParentNode) { - if (m_pParentNode->getParentScene() == EApp::getCurrentScene()) + if (m_pParentNode->getParentScene() == ESceneManager::getCurrentScene()) { - if (!EApp::isPaused() || m_bAlways) + if (!EGame::isPaused() || m_bAlways) return true; } } diff --git a/core/Listener/EListenerPhysics.cpp b/core/Listener/ListenerPhysics.cpp similarity index 82% rename from core/Listener/EListenerPhysics.cpp rename to core/Listener/ListenerPhysics.cpp index e69c1eb0..0617b72d 100644 --- a/core/Listener/EListenerPhysics.cpp +++ b/core/Listener/ListenerPhysics.cpp @@ -14,13 +14,13 @@ e2d::EListenerPhysics::EListenerPhysics(const EString & name) { } -e2d::EListenerPhysics::EListenerPhysics(const PHYSICS_LISTENER_CALLBACK & callback) +e2d::EListenerPhysics::EListenerPhysics(const PhysLsnrCallback & callback) : EListener() , m_Callback(callback) { } -e2d::EListenerPhysics::EListenerPhysics(const EString & name, const PHYSICS_LISTENER_CALLBACK & callback) +e2d::EListenerPhysics::EListenerPhysics(const EString & name, const PhysLsnrCallback & callback) : EListener(name) , m_Callback(callback) { @@ -34,7 +34,7 @@ void e2d::EListenerPhysics::_callOn() } } -void e2d::EListenerPhysics::setCallback(const PHYSICS_LISTENER_CALLBACK & callback) +void e2d::EListenerPhysics::setCallback(const PhysLsnrCallback & callback) { m_Callback = callback; } diff --git a/core/Listener/EListenerPhysicsCollision.cpp b/core/Listener/ListenerPhysicsCollision.cpp similarity index 70% rename from core/Listener/EListenerPhysicsCollision.cpp rename to core/Listener/ListenerPhysicsCollision.cpp index 808f81a0..d98dfa51 100644 --- a/core/Listener/EListenerPhysicsCollision.cpp +++ b/core/Listener/ListenerPhysicsCollision.cpp @@ -13,13 +13,13 @@ e2d::EListenerPhysicsCollision::EListenerPhysicsCollision(const EString & name) { } -e2d::EListenerPhysicsCollision::EListenerPhysicsCollision(const COLLISION_LISTENER_CALLBACK & callback) +e2d::EListenerPhysicsCollision::EListenerPhysicsCollision(const ClsLsnrCallback & callback) : EListenerPhysics() , m_Callback(callback) { } -e2d::EListenerPhysicsCollision::EListenerPhysicsCollision(const EString & name, const COLLISION_LISTENER_CALLBACK & callback) +e2d::EListenerPhysicsCollision::EListenerPhysicsCollision(const EString & name, const ClsLsnrCallback & callback) : EListenerPhysics(name) , m_Callback(callback) { @@ -27,9 +27,9 @@ e2d::EListenerPhysicsCollision::EListenerPhysicsCollision(const EString & name, void e2d::EListenerPhysicsCollision::_callOn() { - if (EPhysicsMsg::getMsg() == EPhysicsMsg::OVERLAP || - EPhysicsMsg::getMsg() == EPhysicsMsg::CONTAINS || - EPhysicsMsg::getMsg() == EPhysicsMsg::IS_CONTAINED) + if (EPhysicsEvent::getMsg() == EPhysicsEvent::OVERLAP || + EPhysicsEvent::getMsg() == EPhysicsEvent::CONTAINS || + EPhysicsEvent::getMsg() == EPhysicsEvent::IS_CONTAINED) { if (m_Callback) { diff --git a/core/Manager/EActionManager.cpp b/core/Manager/ActionManager.cpp similarity index 74% rename from core/Manager/EActionManager.cpp rename to core/Manager/ActionManager.cpp index 29d1fc84..b949824c 100644 --- a/core/Manager/EActionManager.cpp +++ b/core/Manager/ActionManager.cpp @@ -1,6 +1,5 @@ #include "..\emanagers.h" #include "..\eactions.h" -#include "..\Win\winbase.h" static std::vector s_vActions; @@ -17,7 +16,7 @@ void e2d::EActionManager::addAction(EAction * action) } } -void e2d::EActionManager::startAllActionsBindedWith(ENode * pTargetNode) +void e2d::EActionManager::resumeAllActionsBindedWith(ENode * pTargetNode) { if (pTargetNode) { @@ -30,7 +29,7 @@ void e2d::EActionManager::startAllActionsBindedWith(ENode * pTargetNode) } for (auto child = pTargetNode->getChildren().begin(); child != pTargetNode->getChildren().end(); child++) { - EActionManager::startAllActionsBindedWith((*child)); + EActionManager::resumeAllActionsBindedWith((*child)); } } } @@ -71,7 +70,7 @@ void e2d::EActionManager::stopAllActionsBindedWith(ENode * pTargetNode) } } -void e2d::EActionManager::_clearAllActionsBindedWith(ENode * pTargetNode) +void e2d::EActionManager::__clearAllActionsBindedWith(ENode * pTargetNode) { if (pTargetNode) { @@ -91,17 +90,17 @@ void e2d::EActionManager::_clearAllActionsBindedWith(ENode * pTargetNode) } } -void e2d::EActionManager::startAllActions() +void e2d::EActionManager::resumeAllActions() { - for (auto child = EApp::getCurrentScene()->getChildren().begin(); child != EApp::getCurrentScene()->getChildren().end(); child++) + for (auto child = ESceneManager::getCurrentScene()->getChildren().begin(); child != ESceneManager::getCurrentScene()->getChildren().end(); child++) { - EActionManager::startAllActionsBindedWith((*child)); + EActionManager::resumeAllActionsBindedWith((*child)); } } void e2d::EActionManager::pauseAllActions() { - for (auto child = EApp::getCurrentScene()->getChildren().begin(); child != EApp::getCurrentScene()->getChildren().end(); child++) + for (auto child = ESceneManager::getCurrentScene()->getChildren().begin(); child != ESceneManager::getCurrentScene()->getChildren().end(); child++) { EActionManager::pauseAllActionsBindedWith((*child)); } @@ -109,18 +108,13 @@ void e2d::EActionManager::pauseAllActions() void e2d::EActionManager::stopAllActions() { - for (auto child = EApp::getCurrentScene()->getChildren().begin(); child != EApp::getCurrentScene()->getChildren().end(); child++) + for (auto child = ESceneManager::getCurrentScene()->getChildren().begin(); child != ESceneManager::getCurrentScene()->getChildren().end(); child++) { EActionManager::stopAllActionsBindedWith((*child)); } } -void e2d::EActionManager::_clearManager() -{ - s_vActions.clear(); -} - -void e2d::EActionManager::_resetAllActions() +void e2d::EActionManager::__resetAllActions() { for (auto action = s_vActions.begin(); action != s_vActions.end(); action++) { @@ -128,7 +122,7 @@ void e2d::EActionManager::_resetAllActions() } } -void e2d::EActionManager::ActionProc() +void e2d::EActionManager::__update() { if (s_vActions.empty()) return; @@ -139,7 +133,7 @@ void e2d::EActionManager::ActionProc() auto &action = s_vActions[i]; // 获取动作运行状态 if (action->isRunning() || - (action->getTarget() && action->getTarget()->getParentScene() == EApp::getCurrentScene())) + (action->getTarget() && action->getTarget()->getParentScene() == ESceneManager::getCurrentScene())) { if (action->_isEnding()) { diff --git a/core/Manager/EMsgManager.cpp b/core/Manager/EMsgManager.cpp deleted file mode 100644 index a64e8265..00000000 --- a/core/Manager/EMsgManager.cpp +++ /dev/null @@ -1,331 +0,0 @@ -#include "..\emanagers.h" -#include "..\elisteners.h" -#include "..\enodes.h" -#include "..\Win\winbase.h" - - -// 鼠标消息监听器 -std::vector s_vMouseListeners; -// 按键消息监听器 -std::vector s_vKeyboardListeners; - - -void e2d::EMsgManager::MouseProc(UINT message, WPARAM wParam, LPARAM lParam) -{ - // 保存鼠标消息 - EMouseMsg::s_nMsg = message; - EMouseMsg::s_wParam = wParam; - EMouseMsg::s_lParam = lParam; - - if (s_vMouseListeners.empty()) return; - - // 执行鼠标消息监听函数 - size_t i = s_vMouseListeners.size(); - - do - { - auto mlistener = s_vMouseListeners[--i]; - - if (mlistener->_isReady()) - { - mlistener->_callOn(); - if (mlistener->m_bSwallow) - break; - } - } while (i != 0); -} - -void e2d::EMsgManager::KeyboardProc(UINT message, WPARAM wParam, LPARAM lParam) -{ - // 保存按键消息 - EKeyboardMsg::s_nMsg = message; - EKeyboardMsg::s_wParam = wParam; - EKeyboardMsg::s_lParam = lParam; - - if (s_vKeyboardListeners.empty()) return; - - // 执行按键消息监听函数 - size_t i = s_vKeyboardListeners.size(); - - do - { - auto klistener = s_vKeyboardListeners[--i]; - - if (klistener->_isReady()) - { - klistener->_callOn(); - if (klistener->m_bSwallow) - break; - } - } while (i != 0); -} - -void e2d::EMsgManager::bindListener(e2d::EListenerMouse * listener, EScene * pParentScene) -{ - EMsgManager::bindListener(listener, pParentScene->getRoot()); -} - -void e2d::EMsgManager::bindListener(EListenerKeyboard * listener, EScene * pParentScene) -{ - EMsgManager::bindListener(listener, pParentScene->getRoot()); -} - -void e2d::EMsgManager::bindListener(EListenerMouse * listener, ENode * pParentNode) -{ - WARN_IF(listener == nullptr, "EListenerMouse NULL pointer exception!"); - WARN_IF(pParentNode == nullptr, "Bind EListenerMouse with a NULL ENode pointer!"); - - if (listener && pParentNode) - { - ASSERT( - !listener->m_pParentNode, - "The listener is already binded, it cannot bind again!" - ); - - listener->start(); - listener->retain(); - listener->m_pParentNode = pParentNode; - s_vMouseListeners.push_back(listener); - } -} - -void e2d::EMsgManager::bindListener(EListenerKeyboard * listener, ENode * pParentNode) -{ - WARN_IF(listener == nullptr, "EListenerKeyboard NULL pointer exception!"); - WARN_IF(pParentNode == nullptr, "Bind EListenerKeyboard with a NULL ENode pointer!"); - - if (listener && pParentNode) - { - ASSERT( - !listener->m_pParentNode, - "The listener is already binded, it cannot bind again!" - ); - - listener->start(); - listener->retain(); - listener->m_pParentNode = pParentNode; - s_vKeyboardListeners.push_back(listener); - } -} - -void e2d::EMsgManager::startMouseListeners(const EString & name) -{ - for (auto l = s_vMouseListeners.begin(); l != s_vMouseListeners.end(); l++) - { - if ((*l)->getName() == name) - { - (*l)->start(); - } - } -} - -void e2d::EMsgManager::stopMouseListeners(const EString & name) -{ - for (auto l = s_vMouseListeners.begin(); l != s_vMouseListeners.end(); l++) - { - if ((*l)->getName() == name) - { - (*l)->stop(); - } - } -} - -void e2d::EMsgManager::delMouseListeners(const EString & name) -{ - // 删除鼠标消息监听器 - std::vector::iterator mIter; - for (mIter = s_vMouseListeners.begin(); mIter != s_vMouseListeners.end();) - { - if ((*mIter)->getName() == name) - { - SafeRelease(&(*mIter)); - mIter = s_vMouseListeners.erase(mIter); - } - else - { - mIter++; - } - } -} - -void e2d::EMsgManager::startKeyboardListeners(const EString & name) -{ - // 启动按键消息监听器 - for (auto l = s_vKeyboardListeners.begin(); l != s_vKeyboardListeners.end(); l++) - { - if ((*l)->getName() == name) - { - (*l)->start(); - } - } -} - -void e2d::EMsgManager::stopKeyboardListeners(const EString & name) -{ - // 停止按键消息监听器 - for (auto l = s_vKeyboardListeners.begin(); l != s_vKeyboardListeners.end(); l++) - { - if ((*l)->getName() == name) - { - (*l)->stop(); - } - } -} - -void e2d::EMsgManager::delKeyboardListeners(const EString & name) -{ - // 删除按键消息监听器 - std::vector::iterator kIter; - for (kIter = s_vKeyboardListeners.begin(); kIter != s_vKeyboardListeners.end();) - { - if ((*kIter)->getName() == name) - { - SafeRelease(&(*kIter)); - kIter = s_vKeyboardListeners.erase(kIter); - } - else - { - kIter++; - } - } -} - -void e2d::EMsgManager::startAllMouseListenersBindedWith(EScene * pParentScene) -{ - EMsgManager::startAllMouseListenersBindedWith(pParentScene->getRoot()); -} - -void e2d::EMsgManager::stopAllMouseListenersBindedWith(EScene * pParentScene) -{ - EMsgManager::stopAllMouseListenersBindedWith(pParentScene->getRoot()); -} - -void e2d::EMsgManager::startAllMouseListenersBindedWith(ENode * pParentNode) -{ - for (auto l = s_vMouseListeners.begin(); l != s_vMouseListeners.end(); l++) - { - if ((*l)->getParentNode() == pParentNode) - { - (*l)->start(); - } - } - for (auto child = pParentNode->getChildren().begin(); child != pParentNode->getChildren().end(); child++) - { - EMsgManager::startAllMouseListenersBindedWith((*child)); - } -} - -void e2d::EMsgManager::stopAllMouseListenersBindedWith(ENode * pParentNode) -{ - for (auto l = s_vMouseListeners.begin(); l != s_vMouseListeners.end(); l++) - { - if ((*l)->getParentNode() == pParentNode) - { - (*l)->stop(); - } - } - for (auto child = pParentNode->getChildren().begin(); child != pParentNode->getChildren().end(); child++) - { - EMsgManager::stopAllMouseListenersBindedWith((*child)); - } -} - -void e2d::EMsgManager::startAllKeyboardListenersBindedWith(EScene * pParentScene) -{ - EMsgManager::startAllKeyboardListenersBindedWith(pParentScene->getRoot()); -} - -void e2d::EMsgManager::stopAllKeyboardListenersBindedWith(EScene * pParentScene) -{ - EMsgManager::stopAllKeyboardListenersBindedWith(pParentScene->getRoot()); -} - -void e2d::EMsgManager::startAllKeyboardListenersBindedWith(ENode * pParentNode) -{ - for (auto l = s_vKeyboardListeners.begin(); l != s_vKeyboardListeners.end(); l++) - { - if ((*l)->getParentNode() == pParentNode) - { - (*l)->start(); - } - } - for (auto child = pParentNode->getChildren().begin(); child != pParentNode->getChildren().end(); child++) - { - EMsgManager::startAllKeyboardListenersBindedWith((*child)); - } -} - -void e2d::EMsgManager::stopAllKeyboardListenersBindedWith(ENode * pParentNode) -{ - for (auto l = s_vKeyboardListeners.begin(); l != s_vKeyboardListeners.end(); l++) - { - if ((*l)->getParentNode() == pParentNode) - { - (*l)->stop(); - } - } - for (auto child = pParentNode->getChildren().begin(); child != pParentNode->getChildren().end(); child++) - { - EMsgManager::stopAllKeyboardListenersBindedWith((*child)); - } -} - -void e2d::EMsgManager::_clearAllMouseListenersBindedWith(ENode * pParentNode) -{ - for (size_t i = 0; i < s_vMouseListeners.size();) - { - auto t = s_vMouseListeners[i]; - if (t->getParentNode() == pParentNode) - { - SafeRelease(&t); - s_vMouseListeners.erase(s_vMouseListeners.begin() + i); - } - else - { - i++; - } - } -} - -void e2d::EMsgManager::_clearAllKeyboardListenersBindedWith(ENode * pParentNode) -{ - for (size_t i = 0; i < s_vKeyboardListeners.size();) - { - auto t = s_vKeyboardListeners[i]; - if (t->getParentNode() == pParentNode) - { - SafeRelease(&t); - s_vKeyboardListeners.erase(s_vKeyboardListeners.begin() + i); - } - else - { - i++; - } - } -} - -void e2d::EMsgManager::_clearManager() -{ - s_vMouseListeners.clear(); - s_vKeyboardListeners.clear(); -} - -void e2d::EMsgManager::startAllMouseListeners() -{ - EMsgManager::startAllMouseListenersBindedWith(EApp::getCurrentScene()); -} - -void e2d::EMsgManager::stopAllMouseListeners() -{ - EMsgManager::stopAllMouseListenersBindedWith(EApp::getCurrentScene()); -} - -void e2d::EMsgManager::startAllKeyboardListeners() -{ - EMsgManager::startAllKeyboardListenersBindedWith(EApp::getCurrentScene()); -} - -void e2d::EMsgManager::stopAllKeyboardListeners() -{ - EMsgManager::stopAllKeyboardListenersBindedWith(EApp::getCurrentScene()); -} \ No newline at end of file diff --git a/core/Manager/EObjectManager.cpp b/core/Manager/ObjectManager.cpp similarity index 100% rename from core/Manager/EObjectManager.cpp rename to core/Manager/ObjectManager.cpp diff --git a/core/Manager/EPhysicsManager.cpp b/core/Manager/PhysicsManager.cpp similarity index 87% rename from core/Manager/EPhysicsManager.cpp rename to core/Manager/PhysicsManager.cpp index 044c6c38..dd8ce2ee 100644 --- a/core/Manager/EPhysicsManager.cpp +++ b/core/Manager/PhysicsManager.cpp @@ -11,18 +11,18 @@ std::vector s_vGeometries; void e2d::EPhysicsManager::PhysicsGeometryProc(EGeometry * pActiveGeometry) { - if (s_vListeners.empty() || s_vGeometries.empty() || EApp::isPaused()) + if (s_vListeners.empty() || s_vGeometries.empty() || EGame::isPaused()) return; // pActiveGeometry 为主动方 - EPhysicsMsg::s_pActiveGeometry = pActiveGeometry; + EPhysicsEvent::s_pActiveGeometry = pActiveGeometry; // 判断变化后的状态 for (UINT i = 0; i < s_vGeometries.size(); i++) { auto pPassiveGeometry = s_vGeometries[i]; // 不与其他场景的物体判断 if (!pPassiveGeometry->getParentNode() || - (pPassiveGeometry->getParentNode()->getParentScene() != EApp::getCurrentScene())) + (pPassiveGeometry->getParentNode()->getParentScene() != ESceneManager::getCurrentScene())) continue; if (pActiveGeometry != pPassiveGeometry) @@ -31,12 +31,12 @@ void e2d::EPhysicsManager::PhysicsGeometryProc(EGeometry * pActiveGeometry) if (pActiveGeometry->m_nCollisionBitmask & pPassiveGeometry->m_nCategoryBitmask) { // pPassiveGeometry 为被动方 - EPhysicsMsg::s_pPassiveGeometry = pPassiveGeometry; + EPhysicsEvent::s_pPassiveGeometry = pPassiveGeometry; // 获取两方的关系 - EPhysicsMsg::s_nRelation = pActiveGeometry->_intersectWith(pPassiveGeometry); + EPhysicsEvent::s_nRelation = pActiveGeometry->_intersectWith(pPassiveGeometry); // 如果关系不为未知或无交集,响应监听器 - if (EPhysicsMsg::s_nRelation != EPhysicsMsg::UNKNOWN && - EPhysicsMsg::s_nRelation != EPhysicsMsg::DISJOINT) + if (EPhysicsEvent::s_nRelation != EPhysicsEvent::UNKNOWN && + EPhysicsEvent::s_nRelation != EPhysicsEvent::DISJOINT) { // 执行监听器 PhysicsListenerProc(); @@ -194,12 +194,12 @@ void e2d::EPhysicsManager::stopAllListenersBindedWith(ENode * pParentNode) void e2d::EPhysicsManager::startAllListeners() { - EPhysicsManager::startAllListenersBindedWith(EApp::getCurrentScene()); + EPhysicsManager::startAllListenersBindedWith(ESceneManager::getCurrentScene()); } void e2d::EPhysicsManager::stopAllListeners() { - EPhysicsManager::stopAllListenersBindedWith(EApp::getCurrentScene()); + EPhysicsManager::stopAllListenersBindedWith(ESceneManager::getCurrentScene()); } void e2d::EPhysicsManager::_clearManager() diff --git a/core/Manager/SceneManager.cpp b/core/Manager/SceneManager.cpp new file mode 100644 index 00000000..2795e91f --- /dev/null +++ b/core/Manager/SceneManager.cpp @@ -0,0 +1,148 @@ +#include "..\emanagers.h" +#include "..\ebase.h" +#include "..\etransitions.h" +#include + +static e2d::EScene * s_pCurrentScene = nullptr; +static e2d::EScene * s_pNextScene = nullptr; +static e2d::ETransition * s_pTransition = nullptr; +static std::stack s_SceneStack; + +void e2d::ESceneManager::enterScene(EScene * scene, ETransition * transition /* = nullptr */, bool saveCurrentScene /* = true */) +{ + ASSERT(scene != nullptr, "Next scene NULL pointer exception!"); + scene->retain(); + + // 保存下一场景的指针 + s_pNextScene = scene; + + // 设置切换场景动画 + if (transition) + { + s_pTransition = transition; + transition->retain(); + transition->_setTarget( + s_pCurrentScene, + s_pNextScene + ); + } + + if (s_pCurrentScene) + { + s_pCurrentScene->m_bWillSave = saveCurrentScene; + } +} + +void e2d::ESceneManager::backScene(ETransition * transition /* = nullptr */) +{ + // 栈为空时,调用返回场景函数失败 + WARN_IF(s_SceneStack.size() == 0, "Scene stack now is empty!"); + if (s_SceneStack.size() == 0) return; + + // 从栈顶取出场景指针,作为下一场景 + s_pNextScene = s_SceneStack.top(); + s_SceneStack.pop(); + + // 返回上一场景时,不保存当前场景 + if (s_pCurrentScene) + { + s_pCurrentScene->m_bWillSave = false; + } + + // 设置切换场景动画 + if (transition) + { + s_pTransition = transition; + transition->retain(); + transition->_setTarget( + s_pCurrentScene, + s_pNextScene + ); + } +} + +void e2d::ESceneManager::clearScene() +{ + // 清空场景栈 + while (s_SceneStack.size()) + { + auto temp = s_SceneStack.top(); + SafeRelease(&temp); + s_SceneStack.pop(); + } +} + +e2d::EScene * e2d::ESceneManager::getCurrentScene() +{ + return s_pCurrentScene; +} + +void e2d::ESceneManager::__update() +{ + // 正在切换场景时,执行场景切换动画 + if (s_pTransition) + { + s_pTransition->_update(); + if (s_pTransition->isEnding()) + { + s_pTransition->release(); + s_pTransition = nullptr; + } + return; + } + + // 下一场景指针不为空时,切换场景 + if (s_pNextScene) + { + // 进入下一场景 + __enterNextScene(); + } + + // 断言当前场景非空 + ASSERT(s_pCurrentScene != nullptr, "Current scene NULL pointer exception."); + + // 更新场景内容 + s_pCurrentScene->_update(); +} + +void e2d::ESceneManager::__render() +{ + // 绘制当前场景 + if (s_pCurrentScene) + { + s_pCurrentScene->_render(); + } + // 切换场景时,同时绘制两场景 + if (s_pTransition && s_pNextScene) + { + s_pNextScene->_render(); + } +} + +void e2d::ESceneManager::__enterNextScene() +{ + if (s_pNextScene == nullptr) + return; + + // 执行当前场景的 onCloseWindow 函数 + if (s_pCurrentScene) + { + s_pCurrentScene->onExit(); + + if (s_pCurrentScene->m_bWillSave) + { + // 若要保存当前场景,把它放入栈中 + s_SceneStack.push(s_pCurrentScene); + } + else + { + SafeRelease(&s_pCurrentScene); + } + } + + // 执行下一场景的 onEnter 函数 + s_pNextScene->onEnter(); + + s_pCurrentScene = s_pNextScene; // 切换场景 + s_pNextScene = nullptr; // 下一场景置空 +} diff --git a/core/Manager/ETimerManager.cpp b/core/Manager/TimerManager.cpp similarity index 88% rename from core/Manager/ETimerManager.cpp rename to core/Manager/TimerManager.cpp index 8e02e440..2db90158 100644 --- a/core/Manager/ETimerManager.cpp +++ b/core/Manager/TimerManager.cpp @@ -1,12 +1,11 @@ #include "..\emanagers.h" #include "..\etools.h" #include "..\enodes.h" -#include "..\Win\winbase.h" static std::vector s_vTimers; -void e2d::ETimerManager::TimerProc() +void e2d::ETimerManager::__update() { if (s_vTimers.empty()) return; @@ -124,7 +123,7 @@ void e2d::ETimerManager::stopAllTimersBindedWith(ENode * pParentNode) } } -void e2d::ETimerManager::_clearAllTimersBindedWith(ENode * pParentNode) +void e2d::ETimerManager::__clearAllTimersBindedWith(ENode * pParentNode) { for (size_t i = 0; i < s_vTimers.size();) { @@ -141,25 +140,20 @@ void e2d::ETimerManager::_clearAllTimersBindedWith(ENode * pParentNode) } } -void e2d::ETimerManager::_clearManager() -{ - s_vTimers.clear(); -} - -void e2d::ETimerManager::_resetAllTimers() +void e2d::ETimerManager::__resetAllTimers() { for (auto timer = s_vTimers.begin(); timer != s_vTimers.end(); timer++) { - (*timer)->m_tLast = GetNow(); + (*timer)->m_fLast = ETime::getTotalTime(); } } void e2d::ETimerManager::startAllTimers() { - ETimerManager::startAllTimersBindedWith(EApp::getCurrentScene()); + ETimerManager::startAllTimersBindedWith(ESceneManager::getCurrentScene()); } void e2d::ETimerManager::stopAllTimers() { - ETimerManager::stopAllTimersBindedWith(EApp::getCurrentScene()); + ETimerManager::stopAllTimersBindedWith(ESceneManager::getCurrentScene()); } \ No newline at end of file diff --git a/core/Msg/EKeyboardMsg.cpp b/core/Msg/EKeyboardMsg.cpp deleted file mode 100644 index 821a9d2f..00000000 --- a/core/Msg/EKeyboardMsg.cpp +++ /dev/null @@ -1,56 +0,0 @@ -#include "..\ecommon.h" - -UINT e2d::EKeyboardMsg::s_nMsg = 0; -WPARAM e2d::EKeyboardMsg::s_wParam = 0; -LPARAM e2d::EKeyboardMsg::s_lParam = 0; - -e2d::EKeyboardMsg::KEYBOARD_MSG e2d::EKeyboardMsg::getMsg() -{ - return KEYBOARD_MSG(EKeyboardMsg::s_nMsg); -} - -e2d::EKeyboardMsg::KEY e2d::EKeyboardMsg::getKeyValue() -{ - return KEY(EKeyboardMsg::s_wParam); -} - -DWORD e2d::EKeyboardMsg::getCount() -{ - return (((DWORD)EKeyboardMsg::s_lParam) & 0x0000FFFF); -} - -bool e2d::EKeyboardMsg::isKeyDown(KEY key) -{ - if (::GetAsyncKeyState((int)key) & 0x8000) - { - return true; - } - return false; -} - -bool e2d::EKeyboardMsg::isCapitalLockOn() -{ - if (::GetKeyState(VK_CAPITAL) & 0x0001) - { - return true; - } - return false; -} - -bool e2d::EKeyboardMsg::isNumpadLockOn() -{ - if (::GetKeyState(VK_NUMLOCK) & 0x0001) - { - return true; - } - return false; -} - -bool e2d::EKeyboardMsg::isScrollLockOn() -{ - if (::GetKeyState(VK_SCROLL) & 0x0001) - { - return true; - } - return false; -} diff --git a/core/Msg/EMouseMsg.cpp b/core/Msg/EMouseMsg.cpp deleted file mode 100644 index 3c1ef61d..00000000 --- a/core/Msg/EMouseMsg.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include "..\ecommon.h" - -UINT e2d::EMouseMsg::s_nMsg = 0; -WPARAM e2d::EMouseMsg::s_wParam = 0; -LPARAM e2d::EMouseMsg::s_lParam = 0; - -DWORD e2d::EMouseMsg::getPosX() -{ - return LOWORD(EMouseMsg::s_lParam); -} - -DWORD e2d::EMouseMsg::getPosY() -{ - return HIWORD(EMouseMsg::s_lParam); -} - -e2d::EPoint e2d::EMouseMsg::getPos() -{ - return EPoint(LOWORD(EMouseMsg::s_lParam), HIWORD(EMouseMsg::s_lParam)); -} - -bool e2d::EMouseMsg::isLButtonDown() -{ - return GET_KEYSTATE_WPARAM(EMouseMsg::s_wParam) == MK_LBUTTON; -} - -bool e2d::EMouseMsg::isMButtonDown() -{ - return GET_KEYSTATE_WPARAM(EMouseMsg::s_wParam) == MK_MBUTTON; -} - -bool e2d::EMouseMsg::isRButtonDown() -{ - return GET_KEYSTATE_WPARAM(EMouseMsg::s_wParam) == MK_RBUTTON; -} - -bool e2d::EMouseMsg::isShiftDown() -{ - return GET_KEYSTATE_WPARAM(EMouseMsg::s_wParam) == MK_SHIFT; -} - -bool e2d::EMouseMsg::isCtrlDown() -{ - return GET_KEYSTATE_WPARAM(EMouseMsg::s_wParam) == MK_CONTROL; -} - -DWORD e2d::EMouseMsg::getWheelDelta() -{ - return GET_WHEEL_DELTA_WPARAM(EMouseMsg::s_wParam); -} - -e2d::EMouseMsg::MOUSE_MSG e2d::EMouseMsg::getMsg() -{ - return MOUSE_MSG(EMouseMsg::s_nMsg); -} diff --git a/core/Msg/EPhysicsMsg.cpp b/core/Msg/EPhysicsMsg.cpp deleted file mode 100644 index cfd7065b..00000000 --- a/core/Msg/EPhysicsMsg.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "..\ecommon.h" - -e2d::EPhysicsMsg::INTERSECT_RELATION e2d::EPhysicsMsg::s_nRelation = e2d::EPhysicsMsg::UNKNOWN; -e2d::EGeometry * e2d::EPhysicsMsg::s_pActiveGeometry = nullptr; -e2d::EGeometry * e2d::EPhysicsMsg::s_pPassiveGeometry = nullptr; - -e2d::EPhysicsMsg::INTERSECT_RELATION e2d::EPhysicsMsg::getMsg() -{ - return EPhysicsMsg::s_nRelation; -} - -e2d::EGeometry * e2d::EPhysicsMsg::getActiveGeometry() -{ - return EPhysicsMsg::s_pActiveGeometry; -} - -e2d::EGeometry * e2d::EPhysicsMsg::getPassiveGeometry() -{ - return EPhysicsMsg::s_pPassiveGeometry; -} diff --git a/core/Node/EButton.cpp b/core/Node/Button.cpp similarity index 76% rename from core/Node/EButton.cpp rename to core/Node/Button.cpp index 5d71292a..9807ca11 100644 --- a/core/Node/EButton.cpp +++ b/core/Node/Button.cpp @@ -1,10 +1,9 @@ #include "..\enodes.h" #include "..\elisteners.h" #include "..\emanagers.h" -#include "..\Win\winbase.h" e2d::EButton::EButton() - : m_Callback((const BUTTON_CLICK_CALLBACK &)nullptr) + : m_Callback((const BtnClkCallback &)nullptr) , m_eStatus(EButton::NORMAL) , m_bEnable(true) , m_bIsSelected(false) @@ -12,13 +11,11 @@ e2d::EButton::EButton() , m_pMouseover(nullptr) , m_pSelected(nullptr) , m_pDisabled(nullptr) - , m_pListener(nullptr) { - this->_init(); } -e2d::EButton::EButton(ENode * normal, const BUTTON_CLICK_CALLBACK & callback) - : m_Callback((const BUTTON_CLICK_CALLBACK &)nullptr) +e2d::EButton::EButton(ENode * normal, const BtnClkCallback & callback) + : m_Callback((const BtnClkCallback &)nullptr) , m_eStatus(EButton::NORMAL) , m_bEnable(true) , m_bIsSelected(false) @@ -26,15 +23,13 @@ e2d::EButton::EButton(ENode * normal, const BUTTON_CLICK_CALLBACK & callback) , m_pMouseover(nullptr) , m_pSelected(nullptr) , m_pDisabled(nullptr) - , m_pListener(nullptr) { - this->_init(); this->setNormal(normal); this->setCallback(callback); } -e2d::EButton::EButton(ENode * normal, ENode * selected, const BUTTON_CLICK_CALLBACK & callback) - : m_Callback((const BUTTON_CLICK_CALLBACK &)nullptr) +e2d::EButton::EButton(ENode * normal, ENode * selected, const BtnClkCallback & callback) + : m_Callback((const BtnClkCallback &)nullptr) , m_eStatus(EButton::NORMAL) , m_bEnable(true) , m_bIsSelected(false) @@ -42,16 +37,14 @@ e2d::EButton::EButton(ENode * normal, ENode * selected, const BUTTON_CLICK_CALLB , m_pMouseover(nullptr) , m_pSelected(nullptr) , m_pDisabled(nullptr) - , m_pListener(nullptr) { - this->_init(); this->setNormal(normal); this->setSelected(selected); this->setCallback(callback); } -e2d::EButton::EButton(ENode * normal, ENode * mouseover, ENode * selected, const BUTTON_CLICK_CALLBACK & callback) - : m_Callback((const BUTTON_CLICK_CALLBACK &)nullptr) +e2d::EButton::EButton(ENode * normal, ENode * mouseover, ENode * selected, const BtnClkCallback & callback) + : m_Callback((const BtnClkCallback &)nullptr) , m_eStatus(EButton::NORMAL) , m_bEnable(true) , m_bIsSelected(false) @@ -59,17 +52,15 @@ e2d::EButton::EButton(ENode * normal, ENode * mouseover, ENode * selected, const , m_pMouseover(nullptr) , m_pSelected(nullptr) , m_pDisabled(nullptr) - , m_pListener(nullptr) { - this->_init(); this->setNormal(normal); this->setMouseOver(mouseover); this->setSelected(selected); this->setCallback(callback); } -e2d::EButton::EButton(ENode * normal, ENode * mouseover, ENode * selected, ENode * disabled, const BUTTON_CLICK_CALLBACK & callback) - : m_Callback((const BUTTON_CLICK_CALLBACK &)nullptr) +e2d::EButton::EButton(ENode * normal, ENode * mouseover, ENode * selected, ENode * disabled, const BtnClkCallback & callback) + : m_Callback((const BtnClkCallback &)nullptr) , m_eStatus(EButton::NORMAL) , m_bEnable(true) , m_bIsSelected(false) @@ -77,9 +68,7 @@ e2d::EButton::EButton(ENode * normal, ENode * mouseover, ENode * selected, ENode , m_pMouseover(nullptr) , m_pSelected(nullptr) , m_pDisabled(nullptr) - , m_pListener(nullptr) { - this->_init(); this->setNormal(normal); this->setMouseOver(mouseover); this->setSelected(selected); @@ -179,13 +168,12 @@ void e2d::EButton::setEnable(bool bEnable) { m_bEnable = bEnable; _updateVisiable(); - _updateStatus(); } } -void e2d::EButton::setCallback(const BUTTON_CLICK_CALLBACK & callback) +void e2d::EButton::setCallback(const BtnClkCallback & callback) { - WARN_IF(m_pNormal == nullptr, "EButton cannot work without something to show. Please set its normal displayed."); + WARN_IF(m_pNormal == nullptr, "EButton cannot work without anything to show. Please set its normal displayed."); m_Callback = callback; } @@ -217,11 +205,52 @@ void e2d::EButton::setPivot(float pivotX, float pivotY) if (m_pDisabled) m_pDisabled->setPivot(pivotX, pivotY); } -void e2d::EButton::_init() +void e2d::EButton::onUpdate() { - m_pListener = new EListenerMouse(std::bind(&EButton::_updateStatus, this)); - m_pListener->setAlwaysWorking(true); - EMsgManager::bindListener(m_pListener, this); + if (m_bEnable && m_pNormal) + { + ENode * pMouseover = m_pMouseover ? m_pMouseover : m_pNormal; + ENode * pSelected = m_pSelected ? m_pSelected : m_pNormal; + + if (EInput::isMouseLButtonRelease()) + { + // 鼠标左键抬起时,判断鼠标坐标是否在按钮内部 + if (m_bIsSelected && + pSelected->isPointIn(EInput::getMousePos())) + { + _runCallback(); + } + // 标记 m_bIsSelected 为 false + m_bIsSelected = false; + } + + if (EInput::isMouseLButtonPress()) + { + if (pMouseover->isPointIn(EInput::getMousePos())) + { + // 鼠标左键按下,且位于按钮内时,标记 m_bIsSelected 为 true + m_bIsSelected = true; + _setStatus(EButton::SELECTED); + return; + } + } + + if (m_bIsSelected && EInput::isMouseLButtonDown()) + { + if (pSelected->isPointIn(EInput::getMousePos())) + { + _setStatus(EButton::SELECTED); + return; + } + } + else if (m_pNormal->isPointIn(EInput::getMousePos())) + { + _setStatus(EButton::MOUSEOVER); + return; + } + + _setStatus(EButton::NORMAL); + } } void e2d::EButton::_setStatus(STATUS status) @@ -233,12 +262,6 @@ void e2d::EButton::_setStatus(STATUS status) } } -void e2d::EButton::_updateTransform() -{ - ENode::_updateTransform(); - _updateStatus(); -} - void e2d::EButton::_updateVisiable() { if (m_pNormal) m_pNormal->setVisiable(false); @@ -274,54 +297,6 @@ void e2d::EButton::_updateVisiable() } } -void e2d::EButton::_updateStatus() -{ - if (m_bEnable && m_pNormal) - { - ENode * pMouseover = m_pMouseover ? m_pMouseover : m_pNormal; - ENode * pSelected = m_pSelected ? m_pSelected : m_pNormal; - - if (EMouseMsg::getMsg() == EMouseMsg::LBUTTON_UP) - { - // 鼠标左键抬起时,判断鼠标坐标是否在按钮内部 - if (m_bIsSelected && - pSelected->isPointIn(EMouseMsg::getPos())) - { - _runCallback(); - } - // 标记 m_bIsSelected 为 false - m_bIsSelected = false; - } - - if (EMouseMsg::getMsg() == EMouseMsg::LBUTTON_DOWN) - { - if (pMouseover->isPointIn(EMouseMsg::getPos())) - { - // 鼠标左键按下,且位于按钮内时,标记 m_bIsSelected 为 true - m_bIsSelected = true; - _setStatus(EButton::SELECTED); - return; - } - } - - if (m_bIsSelected && EMouseMsg::isLButtonDown()) - { - if (pSelected->isPointIn(EMouseMsg::getPos())) - { - _setStatus(EButton::SELECTED); - return; - } - } - else if (m_pNormal->isPointIn(EMouseMsg::getPos())) - { - _setStatus(EButton::MOUSEOVER); - return; - } - - _setStatus(EButton::NORMAL); - } -} - void e2d::EButton::_runCallback() { if (m_Callback) diff --git a/core/Node/EButtonToggle.cpp b/core/Node/ButtonToggle.cpp similarity index 96% rename from core/Node/EButtonToggle.cpp rename to core/Node/ButtonToggle.cpp index f2380637..50474df5 100644 --- a/core/Node/EButtonToggle.cpp +++ b/core/Node/ButtonToggle.cpp @@ -1,7 +1,6 @@ #include "..\enodes.h" #include "..\elisteners.h" #include "..\emanagers.h" -#include "..\Win\winbase.h" e2d::EButtonToggle::EButtonToggle() : EButton() @@ -17,7 +16,7 @@ e2d::EButtonToggle::EButtonToggle() { } -e2d::EButtonToggle::EButtonToggle(ENode * toggleOnNormal, ENode * toggleOffNormal, const BUTTON_CLICK_CALLBACK & callback) +e2d::EButtonToggle::EButtonToggle(ENode * toggleOnNormal, ENode * toggleOffNormal, const BtnClkCallback & callback) : EButton() , m_bToggle(true) , m_pNormalOn(nullptr) @@ -34,7 +33,7 @@ e2d::EButtonToggle::EButtonToggle(ENode * toggleOnNormal, ENode * toggleOffNorma this->setCallback(callback); } -e2d::EButtonToggle::EButtonToggle(ENode * toggleOnNormal, ENode * toggleOffNormal, ENode * toggleOnSelected, ENode * toggleOffSelected, const BUTTON_CLICK_CALLBACK & callback) +e2d::EButtonToggle::EButtonToggle(ENode * toggleOnNormal, ENode * toggleOffNormal, ENode * toggleOnSelected, ENode * toggleOffSelected, const BtnClkCallback & callback) : EButton() , m_bToggle(true) , m_pNormalOn(nullptr) @@ -53,7 +52,7 @@ e2d::EButtonToggle::EButtonToggle(ENode * toggleOnNormal, ENode * toggleOffNorma this->setCallback(callback); } -e2d::EButtonToggle::EButtonToggle(ENode * toggleOnNormal, ENode * toggleOffNormal, ENode * toggleOnMouseOver, ENode * toggleOffMouseOver, ENode * toggleOnSelected, ENode * toggleOffSelected, const BUTTON_CLICK_CALLBACK & callback) +e2d::EButtonToggle::EButtonToggle(ENode * toggleOnNormal, ENode * toggleOffNormal, ENode * toggleOnMouseOver, ENode * toggleOffMouseOver, ENode * toggleOnSelected, ENode * toggleOffSelected, const BtnClkCallback & callback) : EButton() , m_bToggle(true) , m_pNormalOn(nullptr) @@ -74,7 +73,7 @@ e2d::EButtonToggle::EButtonToggle(ENode * toggleOnNormal, ENode * toggleOffNorma this->setCallback(callback); } -e2d::EButtonToggle::EButtonToggle(ENode * toggleOnNormal, ENode * toggleOffNormal, ENode * toggleOnMouseOver, ENode * toggleOffMouseOver, ENode * toggleOnSelected, ENode * toggleOffSelected, ENode * toggleOnDisabled, ENode * toggleOffDisabled, const BUTTON_CLICK_CALLBACK & callback) +e2d::EButtonToggle::EButtonToggle(ENode * toggleOnNormal, ENode * toggleOffNormal, ENode * toggleOnMouseOver, ENode * toggleOffMouseOver, ENode * toggleOnSelected, ENode * toggleOffSelected, ENode * toggleOnDisabled, ENode * toggleOffDisabled, const BtnClkCallback & callback) : EButton() , m_bToggle(true) , m_pNormalOn(nullptr) diff --git a/core/Node/ESprite.cpp b/core/Node/ESprite.cpp deleted file mode 100644 index d2205ed3..00000000 --- a/core/Node/ESprite.cpp +++ /dev/null @@ -1,132 +0,0 @@ -#include "..\enodes.h" -#include "..\Win\winbase.h" - - -e2d::ESprite::ESprite() - : m_fSourceClipX(0) - , m_fSourceClipY(0) - , m_pTexture(nullptr) -{ -} - -e2d::ESprite::ESprite(ETexture * texture) - : m_fSourceClipX(0) - , m_fSourceClipY(0) - , m_pTexture(nullptr) -{ - loadFrom(texture); -} - -e2d::ESprite::ESprite(ESpriteFrame * spriteFrame) - : m_fSourceClipX(0) - , m_fSourceClipY(0) - , m_pTexture(nullptr) -{ - loadFrom(spriteFrame); -} - -e2d::ESprite::ESprite(const EString & imageFileName) - : m_fSourceClipX(0) - , m_fSourceClipY(0) - , m_pTexture(nullptr) -{ - loadFrom(imageFileName); -} - -e2d::ESprite::ESprite(const EString & imageFileName, float x, float y, float width, float height) - : m_fSourceClipX(0) - , m_fSourceClipY(0) - , m_pTexture(nullptr) -{ - loadFrom(imageFileName); - clip(x, y, width, height); -} - -e2d::ESprite::ESprite(LPCTSTR resourceName, LPCTSTR resourceType) - : m_fSourceClipX(0) - , m_fSourceClipY(0) - , m_pTexture(nullptr) -{ - loadFrom(resourceName, resourceType); -} - -e2d::ESprite::ESprite(LPCTSTR resourceName, LPCTSTR resourceType, float x, float y, float width, float height) - : m_fSourceClipX(0) - , m_fSourceClipY(0) - , m_pTexture(nullptr) -{ - loadFrom(resourceName, resourceType); - clip(x, y, width, height); -} - -e2d::ESprite::~ESprite() -{ - SafeRelease(&m_pTexture); -} - -void e2d::ESprite::loadFrom(ETexture * texture) -{ - if (texture) - { - SafeRelease(&m_pTexture); - m_pTexture = texture; - m_pTexture->retain(); - - m_fSourceClipX = m_fSourceClipY = 0; - ENode::_setWidth(m_pTexture->getSourceWidth()); - ENode::_setHeight(m_pTexture->getSourceHeight()); - } -} - -void e2d::ESprite::loadFrom(const EString & imageFileName) -{ - loadFrom(new ETexture(imageFileName)); -} - -void e2d::ESprite::loadFrom(LPCTSTR resourceName, LPCTSTR resourceType) -{ - loadFrom(new ETexture(resourceName, resourceType)); -} - -void e2d::ESprite::loadFrom(ETexture * texture, float x, float y, float width, float height) -{ - loadFrom(texture); - clip(x, y, width, height); -} - -void e2d::ESprite::loadFrom(ESpriteFrame * frame) -{ - if (frame) - { - loadFrom(frame->m_pTexture); - clip(frame->m_fSourceClipX, frame->m_fSourceClipY, frame->m_fSourceClipWidth, frame->m_fSourceClipHeight); - } -} - -void e2d::ESprite::clip(float x, float y, float width, float height) -{ - m_fSourceClipX = min(max(x, 0), m_pTexture->getSourceWidth()); - m_fSourceClipY = min(max(y, 0), m_pTexture->getSourceHeight()); - ENode::_setWidth(min(max(width, 0), m_pTexture->getSourceWidth() - m_fSourceClipX)); - ENode::_setHeight(min(max(height, 0), m_pTexture->getSourceHeight() - m_fSourceClipY)); -} - -void e2d::ESprite::_render() -{ - if (m_pTexture && m_pTexture->_getBitmap()) - { - // Draw bitmap - GetRenderTarget()->DrawBitmap( - m_pTexture->_getBitmap(), - D2D1::RectF(0, 0, getRealWidth(), getRealHeight()), - m_fDisplayOpacity, - D2D1_BITMAP_INTERPOLATION_MODE_LINEAR, - D2D1::RectF( - m_fSourceClipX, - m_fSourceClipY, - m_fSourceClipX + getRealWidth(), - m_fSourceClipY + getRealHeight() - ) - ); - } -} diff --git a/core/Node/EMenu.cpp b/core/Node/Menu.cpp similarity index 78% rename from core/Node/EMenu.cpp rename to core/Node/Menu.cpp index 5cbb58e7..b88fb004 100644 --- a/core/Node/EMenu.cpp +++ b/core/Node/Menu.cpp @@ -37,14 +37,7 @@ void e2d::EMenu::setEnable(bool enable) for (auto button = m_vButtons.begin(); button != m_vButtons.end(); button++) { - if (enable) - { - (*button)->m_pListener->start(); - } - else - { - (*button)->m_pListener->stop(); - } + (*button)->setEnable(enable); } } } @@ -55,15 +48,7 @@ void e2d::EMenu::addButton(EButton * button) { this->addChild(button); m_vButtons.push_back(button); - - if (m_bEnable) - { - button->m_pListener->start(); - } - else - { - button->m_pListener->stop(); - } + button->setEnable(m_bEnable); } } @@ -83,8 +68,8 @@ bool e2d::EMenu::removeButton(EButton * button) { if (m_vButtons[i] == button) { - // 移除按钮前,将它的监听器启用 - button->m_pListener->start(); + // 移除按钮前,将它启用 + button->setEnable(true); m_vButtons.erase(m_vButtons.begin() + i); return true; } diff --git a/core/Node/ENode.cpp b/core/Node/Node.cpp similarity index 93% rename from core/Node/ENode.cpp rename to core/Node/Node.cpp index 4ccf8e15..f816cf80 100644 --- a/core/Node/ENode.cpp +++ b/core/Node/Node.cpp @@ -3,7 +3,6 @@ #include "..\etools.h" #include "..\eactions.h" #include "..\egeometry.h" -#include "..\Win\winbase.h" #include // 默认中心点位置 @@ -61,10 +60,8 @@ e2d::ENode::ENode(const EString & name) e2d::ENode::~ENode() { - ETimerManager::_clearAllTimersBindedWith(this); - EMsgManager::_clearAllMouseListenersBindedWith(this); - EMsgManager::_clearAllKeyboardListenersBindedWith(this); - EActionManager::_clearAllActionsBindedWith(this); + ETimerManager::__clearAllTimersBindedWith(this); + EActionManager::__clearAllActionsBindedWith(this); EPhysicsManager::_clearAllListenersBindedWith(this); EPhysicsManager::_delGeometry(m_pGeometry); for (auto child = m_vChildren.begin(); child != m_vChildren.end(); child++) @@ -73,14 +70,6 @@ e2d::ENode::~ENode() } } -void e2d::ENode::onEnter() -{ -} - -void e2d::ENode::onExit() -{ -} - void e2d::ENode::_update() { if (!m_bVisiable) @@ -113,9 +102,8 @@ void e2d::ENode::_update() } } - GetRenderTarget()->SetTransform(m_MatriFinal); - // 渲染自身 - this->_render(); + // 执行 onUpdate 函数 + this->onUpdate(); // 访问剩余节点 for (; i < size; i++) @@ -123,14 +111,52 @@ void e2d::ENode::_update() } else { - GetRenderTarget()->SetTransform(m_MatriFinal); - // 渲染自身 - this->_render(); + // 执行 onUpdate 函数 + this->onUpdate(); } } void e2d::ENode::_render() { + if (!m_bVisiable) + { + return; + } + + if (!m_vChildren.empty()) + { + size_t size = m_vChildren.size(); + size_t i; + for (i = 0; i < size; i++) + { + auto child = m_vChildren[i]; + // 访问 Order 小于零的节点 + if (child->getOrder() < 0) + { + child->_render(); + } + else + { + break; + } + } + + // 转换渲染器的二维矩阵 + ERenderer::getRenderTarget()->SetTransform(m_MatriFinal); + // 渲染自身 + this->onRender(); + + // 访问剩余节点 + for (; i < size; i++) + m_vChildren[i]->_render(); + } + else + { + // 转换渲染器的二维矩阵 + ERenderer::getRenderTarget()->SetTransform(m_MatriFinal); + // 渲染自身 + this->onRender(); + } } void e2d::ENode::_drawGeometry() @@ -410,7 +436,7 @@ void e2d::ENode::movePos(float x, float y) this->setPos(m_Pos.x + x, m_Pos.y + y); } -void e2d::ENode::movePos(const EVec & v) +void e2d::ENode::movePos(const EVector2 & v) { this->movePos(v.x, v.y); } @@ -733,7 +759,7 @@ bool e2d::ENode::isPointIn(EPoint point) } // 为节点创建一个形状 ID2D1RectangleGeometry * rect; - GetFactory()->CreateRectangleGeometry( + ERenderer::getID2D1Factory()->CreateRectangleGeometry( D2D1::RectF(0, 0, getRealWidth(), getRealHeight()), &rect ); @@ -773,9 +799,9 @@ void e2d::ENode::stopAction(EAction * action) } } -void e2d::ENode::startAllActions() +void e2d::ENode::resumeAllActions() { - EActionManager::startAllActionsBindedWith(this); + EActionManager::resumeAllActionsBindedWith(this); } void e2d::ENode::pauseAllActions() diff --git a/core/Node/Sprite.cpp b/core/Node/Sprite.cpp new file mode 100644 index 00000000..07af97fa --- /dev/null +++ b/core/Node/Sprite.cpp @@ -0,0 +1,131 @@ +#include "..\enodes.h" + + +e2d::ESprite::ESprite() + : m_fSourceClipX(0) + , m_fSourceClipY(0) + , m_pImage(nullptr) +{ +} + +e2d::ESprite::ESprite(EImage * image) + : m_fSourceClipX(0) + , m_fSourceClipY(0) + , m_pImage(nullptr) +{ + loadFrom(image); +} + +e2d::ESprite::ESprite(EKeyframe * spriteFrame) + : m_fSourceClipX(0) + , m_fSourceClipY(0) + , m_pImage(nullptr) +{ + loadFrom(spriteFrame); +} + +e2d::ESprite::ESprite(LPCTSTR imageFileName) + : m_fSourceClipX(0) + , m_fSourceClipY(0) + , m_pImage(nullptr) +{ + loadFrom(imageFileName); +} + +e2d::ESprite::ESprite(LPCTSTR imageFileName, float x, float y, float width, float height) + : m_fSourceClipX(0) + , m_fSourceClipY(0) + , m_pImage(nullptr) +{ + loadFrom(imageFileName); + clip(x, y, width, height); +} + +e2d::ESprite::ESprite(LPCTSTR resourceName, LPCTSTR resourceType) + : m_fSourceClipX(0) + , m_fSourceClipY(0) + , m_pImage(nullptr) +{ + loadFrom(resourceName, resourceType); +} + +e2d::ESprite::ESprite(LPCTSTR resourceName, LPCTSTR resourceType, float x, float y, float width, float height) + : m_fSourceClipX(0) + , m_fSourceClipY(0) + , m_pImage(nullptr) +{ + loadFrom(resourceName, resourceType); + clip(x, y, width, height); +} + +e2d::ESprite::~ESprite() +{ + SafeRelease(&m_pImage); +} + +void e2d::ESprite::loadFrom(EImage * image) +{ + if (image) + { + SafeRelease(&m_pImage); + m_pImage = image; + m_pImage->retain(); + + m_fSourceClipX = m_fSourceClipY = 0; + ENode::_setWidth(m_pImage->getSourceWidth()); + ENode::_setHeight(m_pImage->getSourceHeight()); + } +} + +void e2d::ESprite::loadFrom(LPCTSTR imageFileName) +{ + loadFrom(new EImage(imageFileName)); +} + +void e2d::ESprite::loadFrom(LPCTSTR resourceName, LPCTSTR resourceType) +{ + loadFrom(new EImage(resourceName, resourceType)); +} + +void e2d::ESprite::loadFrom(EImage * image, float x, float y, float width, float height) +{ + loadFrom(image); + clip(x, y, width, height); +} + +void e2d::ESprite::loadFrom(EKeyframe * frame) +{ + if (frame) + { + loadFrom(frame->m_pImage); + clip(frame->m_fSourceClipX, frame->m_fSourceClipY, frame->m_fSourceClipWidth, frame->m_fSourceClipHeight); + } +} + +void e2d::ESprite::clip(float x, float y, float width, float height) +{ + m_fSourceClipX = min(max(x, 0), m_pImage->getSourceWidth()); + m_fSourceClipY = min(max(y, 0), m_pImage->getSourceHeight()); + ENode::_setWidth(min(max(width, 0), m_pImage->getSourceWidth() - m_fSourceClipX)); + ENode::_setHeight(min(max(height, 0), m_pImage->getSourceHeight() - m_fSourceClipY)); +} + +void e2d::ESprite::onRender() +{ + if (m_pImage && m_pImage->_getBitmap()) + { + // Draw bitmap + ERenderer::getRenderTarget()->DrawBitmap( + m_pImage->_getBitmap(), + D2D1::RectF(0, 0, getRealWidth(), getRealHeight()), + m_fDisplayOpacity, + D2D1_BITMAP_INTERPOLATION_MODE_LINEAR, + D2D1::RectF( + m_fSourceClipX, + m_fSourceClipY, + m_fSourceClipX + getRealWidth(), + m_fSourceClipY + getRealHeight() + ) + ); + } +} diff --git a/core/Node/EText.cpp b/core/Node/Text.cpp similarity index 91% rename from core/Node/EText.cpp rename to core/Node/Text.cpp index 20aee8b5..0be1f022 100644 --- a/core/Node/EText.cpp +++ b/core/Node/Text.cpp @@ -1,5 +1,4 @@ #include "..\enodes.h" -#include "..\Win\winbase.h" e2d::EText::EText() : m_bWordWrapping(false) @@ -99,10 +98,10 @@ void e2d::EText::setWordWrappingWidth(float wordWrapWidth) _initTextLayout(); } -void e2d::EText::_render() +void e2d::EText::onRender() { - GetSolidColorBrush()->SetColor(D2D1::ColorF(m_pFont->m_Color, m_fDisplayOpacity)); - GetRenderTarget()->DrawTextW( + ERenderer::getSolidColorBrush()->SetColor(D2D1::ColorF(m_pFont->m_Color, m_fDisplayOpacity)); + ERenderer::getRenderTarget()->DrawTextW( m_sText, UINT32(m_sText.length()), m_pFont->_getTextFormat(), @@ -112,7 +111,7 @@ void e2d::EText::_render() m_bWordWrapping ? m_fWordWrappingWidth : m_Size.width, getRealHeight() ), - GetSolidColorBrush() + ERenderer::getSolidColorBrush() ); } @@ -139,7 +138,7 @@ void e2d::EText::_initTextLayout() // 获取 TextLayout IDWriteTextLayout * pDWriteTextLayout = nullptr; - HRESULT hr = GetDirectWriteFactory()->CreateTextLayout( + HRESULT hr = ERenderer::getIDWriteFactory()->CreateTextLayout( m_sText, UINT32(m_sText.length()), m_pFont->_getTextFormat(), diff --git a/core/Tool/Data.cpp b/core/Tool/Data.cpp new file mode 100644 index 00000000..aff3cc38 --- /dev/null +++ b/core/Tool/Data.cpp @@ -0,0 +1,36 @@ +#include "..\etools.h" + + +void e2d::EData::saveInt(const EString & key, int value) +{ + ::WritePrivateProfileString(L"Default", key, EString::parse(value), EFile::getDefaultSavePath()); +} + +void e2d::EData::saveFloat(const EString & key, float value) +{ + ::WritePrivateProfileString(L"Default", key, EString::parse(value), EFile::getDefaultSavePath()); +} + +void e2d::EData::saveString(const EString & key, const EString & value) +{ + ::WritePrivateProfileString(L"Default", key, value, EFile::getDefaultSavePath()); +} + +int e2d::EData::getInt(const EString & key, int default) +{ + return ::GetPrivateProfileInt(L"Default", key, default, EFile::getDefaultSavePath()); +} + +float e2d::EData::getFloat(const EString & key, float default) +{ + wchar_t temp[32] = { 0 }; + ::GetPrivateProfileString(L"Default", key, EString::parse(default), temp, 31, EFile::getDefaultSavePath()); + return std::stof(temp); +} + +e2d::EString e2d::EData::getString(const EString & key, const EString & default) +{ + wchar_t temp[256] = { 0 }; + ::GetPrivateProfileString(L"Default", key, default, temp, 255, EFile::getDefaultSavePath()); + return temp; +} diff --git a/core/Tool/EMusicUtils.cpp b/core/Tool/EMusicUtils.cpp deleted file mode 100644 index 8ede66fb..00000000 --- a/core/Tool/EMusicUtils.cpp +++ /dev/null @@ -1,150 +0,0 @@ -#include "..\etools.h" -#include -#include "..\Win\MciPlayer.h" -#include - -typedef std::pair Music; -typedef std::map MusicList; - -static MusicList& getMciPlayerList() -{ - static MusicList s_List; - return s_List; -} - - -UINT e2d::EMusicUtils::playMusic(const EString & musicFilePath, int repeatTimes) -{ - UINT nRet = preloadMusic(musicFilePath); - - if (nRet) - { - getMciPlayerList()[nRet]->play(repeatTimes); - } - return nRet; -} - -UINT e2d::EMusicUtils::playMusic(const EString & musicResourceName, const EString & musicResourceType, const EString & musicExtension, int repeatTimes) -{ - UINT nRet = preloadMusic(musicResourceName, musicResourceType, musicExtension); - - if (nRet) - { - getMciPlayerList()[nRet]->play(repeatTimes); - } - return nRet; -} - -UINT e2d::EMusicUtils::preloadMusic(const EString & musicFilePath) -{ - if (musicFilePath.isEmpty()) - return 0; - - UINT nRet = musicFilePath.hash(); - - if (getMciPlayerList().end() != getMciPlayerList().find(nRet)) - return nRet; - - getMciPlayerList().insert(Music(nRet, new MciPlayer())); - MciPlayer * pPlayer = getMciPlayerList()[nRet]; - pPlayer->open(musicFilePath, nRet); - - if (nRet == pPlayer->getMusicID()) return nRet; - - delete pPlayer; - getMciPlayerList().erase(nRet); - return 0; -} - -UINT e2d::EMusicUtils::preloadMusic(const EString & musicResourceName, const EString & musicResourceType, const EString & musicExtension) -{ - if (musicResourceName.isEmpty() || musicResourceType.isEmpty()) - return 0; - - UINT nRet = musicResourceName.hash(); - - if (getMciPlayerList().end() != getMciPlayerList().find(nRet)) - return nRet; - - getMciPlayerList().insert(Music(nRet, new MciPlayer())); - MciPlayer * pPlayer = getMciPlayerList()[nRet]; - pPlayer->open(musicResourceName, musicResourceType, musicExtension, nRet); - - if (nRet == pPlayer->getMusicID()) return nRet; - - delete pPlayer; - getMciPlayerList().erase(nRet); - return 0; -} - -bool e2d::EMusicUtils::resumeMusic(UINT musicId) -{ - MusicList::iterator p = getMciPlayerList().find(musicId); - if (p != getMciPlayerList().end()) - { - p->second->resume(); - return true; - } - return false; -} - -bool e2d::EMusicUtils::resumeMusic(const EString & musicName) -{ - return resumeMusic(musicName.hash());; -} - -bool e2d::EMusicUtils::pauseMusic(UINT musicId) -{ - MusicList::iterator p = getMciPlayerList().find(musicId); - if (p != getMciPlayerList().end()) - { - p->second->pause(); - return true; - } - return false; -} - -bool e2d::EMusicUtils::pauseMusic(const EString & musicName) -{ - return pauseMusic(musicName.hash()); -} - -bool e2d::EMusicUtils::stopMusic(UINT musicId) -{ - MusicList::iterator p = getMciPlayerList().find(musicId); - if (p != getMciPlayerList().end()) - { - p->second->stop(); - return true; - } - return false; -} - -bool e2d::EMusicUtils::stopMusic(const EString & musicName) -{ - return stopMusic(musicName.hash());; -} - -void e2d::EMusicUtils::pauseAllMusics() -{ - for (auto iter = getMciPlayerList().begin(); iter != getMciPlayerList().end(); iter++) - { - (*iter).second->pause(); - } -} - -void e2d::EMusicUtils::resumeAllMusics() -{ - for (auto iter = getMciPlayerList().begin(); iter != getMciPlayerList().end(); iter++) - { - (*iter).second->resume(); - } -} - -void e2d::EMusicUtils::stopAllMusics() -{ - for (auto iter = getMciPlayerList().begin(); iter != getMciPlayerList().end(); iter++) - { - (*iter).second->stop(); - } -} diff --git a/core/Tool/EFileUtils.cpp b/core/Tool/File.cpp similarity index 54% rename from core/Tool/EFileUtils.cpp rename to core/Tool/File.cpp index 0e18e061..20b12bee 100644 --- a/core/Tool/EFileUtils.cpp +++ b/core/Tool/File.cpp @@ -1,5 +1,4 @@ #include "..\etools.h" -#include "..\Win\winbase.h" #include #include @@ -9,13 +8,9 @@ DEFINE_KNOWN_FOLDER(FOLDERID_LocalAppData, 0xF1B32785, 0x6FBA, 0x4FCF, 0x9D, 0x55, 0x7B, 0x8E, 0x7F, 0x15, 0x70, 0x91); -typedef HRESULT(WINAPI* pFunSHGetKnownFolderPath)( - const GUID& rfid, - DWORD dwFlags, - HANDLE hToken, - PWSTR *ppszPath); +typedef HRESULT(WINAPI* pFunSHGetKnownFolderPath)(const GUID& rfid, DWORD dwFlags, HANDLE hToken, PWSTR *ppszPath); -e2d::EString e2d::EFileUtils::getLocalAppDataPath() +e2d::EString e2d::EFile::getLocalAppDataPath() { // 获取 AppData\Local 文件夹的路径 PWSTR pszPath = NULL; @@ -32,14 +27,14 @@ e2d::EString e2d::EFileUtils::getLocalAppDataPath() return L""; } -e2d::EString e2d::EFileUtils::getTempPath() +e2d::EString e2d::EFile::getTempPath() { // 获取临时文件目录 wchar_t path[_MAX_PATH]; ::GetTempPath(_MAX_PATH, path); // 创建临时文件目录 - e2d::EString tempFilePath = path + e2d::EApp::getAppName(); + e2d::EString tempFilePath = path + e2d::EGame::getAppName(); if (_waccess(tempFilePath, 0) == -1) { _wmkdir(tempFilePath); @@ -47,12 +42,12 @@ e2d::EString e2d::EFileUtils::getTempPath() return tempFilePath; } -e2d::EString e2d::EFileUtils::getDefaultSavePath() +e2d::EString e2d::EFile::getDefaultSavePath() { - EString path = EFileUtils::getLocalAppDataPath(); + EString path = EFile::getLocalAppDataPath(); WARN_IF(path.isEmpty(), "Cannot get local AppData path!"); - path += L"\\" + EApp::getAppName(); + path += L"\\" + EGame::getAppName(); if (_waccess(path, 0) == -1) { @@ -64,45 +59,11 @@ e2d::EString e2d::EFileUtils::getDefaultSavePath() return path; } -void e2d::EFileUtils::saveInt(const EString & key, int value) -{ - ::WritePrivateProfileString(L"Default", key, EString::parse(value), getDefaultSavePath()); -} - -void e2d::EFileUtils::saveFloat(const EString & key, float value) -{ - ::WritePrivateProfileString(L"Default", key, EString::parse(value), getDefaultSavePath()); -} - -void e2d::EFileUtils::saveString(const EString & key, const EString & value) -{ - ::WritePrivateProfileString(L"Default", key, value, getDefaultSavePath()); -} - -int e2d::EFileUtils::getInt(const EString & key, int default) -{ - return ::GetPrivateProfileInt(L"Default", key, default, getDefaultSavePath()); -} - -float e2d::EFileUtils::getFloat(const EString & key, float default) -{ - wchar_t temp[32] = { 0 }; - ::GetPrivateProfileString(L"Default", key, EString::parse(default), temp, 31, getDefaultSavePath()); - return std::stof(temp); -} - -e2d::EString e2d::EFileUtils::getString(const EString & key, const EString & default) -{ - wchar_t temp[256] = { 0 }; - ::GetPrivateProfileString(L"Default", key, default, temp, 255, getDefaultSavePath()); - return temp; -} - -e2d::EString e2d::EFileUtils::getFileExtension(const EString & filePath) +e2d::EString e2d::EFile::getFileExtension(const EString & filePath) { EString fileExtension; // 找到文件名中的最后一个 '.' 的位置 - size_t pos = filePath.findLastOf(L'.'); + int pos = filePath.findLastOf(L'.'); // 判断 pos 是否是个有效位置 if (pos != -1) { @@ -115,13 +76,13 @@ e2d::EString e2d::EFileUtils::getFileExtension(const EString & filePath) return fileExtension; } -e2d::EString e2d::EFileUtils::getSaveFilePath(const EString & title, const EString & defExt) +e2d::EString e2d::EFile::getSaveFilePath(const EString & title, const EString & defExt) { // 弹出保存对话框 OPENFILENAME ofn = { 0 }; TCHAR strFilename[MAX_PATH] = { 0 }; // 用于接收文件名 ofn.lStructSize = sizeof(OPENFILENAME); // 结构体大小 - ofn.hwndOwner = GetHWnd(); // 窗口句柄 + ofn.hwndOwner = EWindow::getHWnd(); // 窗口句柄 ofn.lpstrFilter = L"所有文件\0*.*\0\0"; // 设置过滤 ofn.nFilterIndex = 1; // 过滤器索引 ofn.lpstrFile = strFilename; // 接收返回的文件路径和文件名 @@ -136,4 +97,4 @@ e2d::EString e2d::EFileUtils::getSaveFilePath(const EString & title, const EStri return strFilename; } return L""; -} +} \ No newline at end of file diff --git a/core/Win/MciPlayer.cpp b/core/Tool/Music.cpp similarity index 53% rename from core/Win/MciPlayer.cpp rename to core/Tool/Music.cpp index 59beac71..88e87fa1 100644 --- a/core/Win/MciPlayer.cpp +++ b/core/Tool/Music.cpp @@ -1,7 +1,6 @@ #include "..\etools.h" +#include #include -#include "winbase.h" -#include "MciPlayer.h" #pragma comment(lib , "winmm.lib") #define WIN_CLASS_NAME L"MciPlayerCallbackWnd" @@ -11,8 +10,36 @@ static HINSTANCE s_hInstance = nullptr; LRESULT WINAPI _MciPlayerProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); static bool ExtractResource(LPCTSTR strDstFile, LPCTSTR strResType, LPCTSTR strResName); +class MciPlayer +{ +public: + MciPlayer(); + ~MciPlayer(); -MciPlayer::MciPlayer() + void close(); + bool open(const e2d::EString & pFileName, UINT uId); + bool open(const e2d::EString & pResouceName, const e2d::EString & pResouceType, const e2d::EString & musicExtension, UINT uId); + void play(int repeatTimes); + void pause(); + void resume(); + void stop(); + void rewind(); + bool isPlaying(); + UINT getMusicID(); + +private: + friend LRESULT WINAPI _MciPlayerProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); + void _sendCommand(int nCommand, DWORD_PTR param1 = 0, DWORD_PTR parma2 = 0); + + MCIDEVICEID m_dev; + HWND m_wnd; + UINT m_nMusicID; + bool m_bPlaying; + int m_nRepeatTimes; +}; + + +MciPlayer::MciPlayer() : m_wnd(NULL) , m_dev(0L) , m_nMusicID(0) @@ -72,7 +99,7 @@ bool MciPlayer::open(const e2d::EString & pFileName, UINT uId) close(); MCI_OPEN_PARMS mciOpen = { 0 }; - mciOpen.lpstrDeviceType = (LPCTSTR)MCI_ALL_DEVICE_ID; + mciOpen.lpstrDeviceType = 0; mciOpen.lpstrElementName = pFileName; MCIERROR mciError; @@ -99,7 +126,7 @@ bool MciPlayer::open(const e2d::EString & pResouceName, const e2d::EString & pRe if (pResouceName.isEmpty() || pResouceType.isEmpty() || musicExtension.isEmpty()) return false; // 获取临时文件目录 - e2d::EString tempFileName = e2d::EFileUtils::getTempPath(); + e2d::EString tempFileName = e2d::EFile::getTempPath(); // 产生临时文件的文件名 tempFileName = tempFileName + L"\\" + uId + L"." + musicExtension; @@ -251,11 +278,11 @@ LRESULT WINAPI _MciPlayerProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) if (pPlayer->m_nRepeatTimes) { - mciSendCommand(lParam, MCI_SEEK, MCI_SEEK_TO_START, 0); + mciSendCommand(static_cast(lParam), MCI_SEEK, MCI_SEEK_TO_START, 0); MCI_PLAY_PARMS mciPlay = { 0 }; mciPlay.dwCallback = reinterpret_cast(hWnd); - mciSendCommand(lParam, MCI_PLAY, MCI_NOTIFY, reinterpret_cast(&mciPlay)); + mciSendCommand(static_cast(lParam), MCI_PLAY, MCI_NOTIFY, reinterpret_cast(&mciPlay)); } else { @@ -264,4 +291,153 @@ LRESULT WINAPI _MciPlayerProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) } } return DefWindowProc(hWnd, Msg, wParam, lParam); -} \ No newline at end of file +} + + + + +typedef std::pair MusicPair; +typedef std::map MusicList; + +static MusicList& getMciPlayerList() +{ + static MusicList s_List; + return s_List; +} + + +UINT e2d::EMusic::play(const EString & musicFilePath, int repeatTimes) +{ + UINT nRet = preload(musicFilePath); + + if (nRet) + { + getMciPlayerList()[nRet]->play(repeatTimes); + } + return nRet; +} + +UINT e2d::EMusic::play(const EString & musicResourceName, const EString & musicResourceType, const EString & musicExtension, int repeatTimes) +{ + UINT nRet = preload(musicResourceName, musicResourceType, musicExtension); + + if (nRet) + { + getMciPlayerList()[nRet]->play(repeatTimes); + } + return nRet; +} + +UINT e2d::EMusic::preload(const EString & musicFilePath) +{ + if (musicFilePath.isEmpty()) + return 0; + + UINT nRet = musicFilePath.hash(); + + if (getMciPlayerList().end() != getMciPlayerList().find(nRet)) + return nRet; + + getMciPlayerList().insert(MusicPair(nRet, new MciPlayer())); + MciPlayer * pPlayer = getMciPlayerList()[nRet]; + pPlayer->open(musicFilePath, nRet); + + if (nRet == pPlayer->getMusicID()) return nRet; + + delete pPlayer; + getMciPlayerList().erase(nRet); + return 0; +} + +UINT e2d::EMusic::preload(const EString & musicResourceName, const EString & musicResourceType, const EString & musicExtension) +{ + if (musicResourceName.isEmpty() || musicResourceType.isEmpty()) + return 0; + + UINT nRet = musicResourceName.hash(); + + if (getMciPlayerList().end() != getMciPlayerList().find(nRet)) + return nRet; + + getMciPlayerList().insert(MusicPair(nRet, new MciPlayer())); + MciPlayer * pPlayer = getMciPlayerList()[nRet]; + pPlayer->open(musicResourceName, musicResourceType, musicExtension, nRet); + + if (nRet == pPlayer->getMusicID()) return nRet; + + delete pPlayer; + getMciPlayerList().erase(nRet); + return 0; +} + +bool e2d::EMusic::resume(UINT musicId) +{ + MusicList::iterator p = getMciPlayerList().find(musicId); + if (p != getMciPlayerList().end()) + { + p->second->resume(); + return true; + } + return false; +} + +bool e2d::EMusic::resume(const EString & musicName) +{ + return resume(musicName.hash());; +} + +bool e2d::EMusic::pause(UINT musicId) +{ + MusicList::iterator p = getMciPlayerList().find(musicId); + if (p != getMciPlayerList().end()) + { + p->second->pause(); + return true; + } + return false; +} + +bool e2d::EMusic::pause(const EString & musicName) +{ + return pause(musicName.hash()); +} + +bool e2d::EMusic::stop(UINT musicId) +{ + MusicList::iterator p = getMciPlayerList().find(musicId); + if (p != getMciPlayerList().end()) + { + p->second->stop(); + return true; + } + return false; +} + +bool e2d::EMusic::stop(const EString & musicName) +{ + return stop(musicName.hash());; +} + +void e2d::EMusic::pauseAllMusics() +{ + for (auto iter = getMciPlayerList().begin(); iter != getMciPlayerList().end(); iter++) + { + (*iter).second->pause(); + } +} + +void e2d::EMusic::resumeAllMusics() +{ + for (auto iter = getMciPlayerList().begin(); iter != getMciPlayerList().end(); iter++) + { + (*iter).second->resume(); + } +} + +void e2d::EMusic::stopAllMusics() +{ + for (auto iter = getMciPlayerList().begin(); iter != getMciPlayerList().end(); iter++) + { + (*iter).second->stop(); + } +} diff --git a/core/Tool/ERandom.cpp b/core/Tool/Random.cpp similarity index 100% rename from core/Tool/ERandom.cpp rename to core/Tool/Random.cpp diff --git a/core/Tool/ETimer.cpp b/core/Tool/Timer.cpp similarity index 71% rename from core/Tool/ETimer.cpp rename to core/Tool/Timer.cpp index 2623f7d2..2367faf5 100644 --- a/core/Tool/ETimer.cpp +++ b/core/Tool/Timer.cpp @@ -1,25 +1,26 @@ #include "..\etools.h" #include "..\enodes.h" #include "..\emanagers.h" -#include "..\Win\winbase.h" e2d::ETimer::ETimer() : m_bRunning(false) , m_nRunTimes(0) , m_pParentNode(nullptr) , m_Callback(nullptr) - , m_nInterval() + , m_fInterval(0) + , m_fLast(0) , m_nRepeatTimes(-1) , m_bAtOnce(false) { } -e2d::ETimer::ETimer(const TIMER_CALLBACK & callback, int repeatTimes /* = -1 */, LONGLONG interval /* = 0 */, bool atOnce /* = false */) +e2d::ETimer::ETimer(const TimerCallback & callback, int repeatTimes /* = -1 */, float interval /* = 0 */, bool atOnce /* = false */) : m_bRunning(false) , m_nRunTimes(0) , m_pParentNode(nullptr) , m_Callback(nullptr) - , m_nInterval() + , m_fInterval(0) + , m_fLast(0) , m_nRepeatTimes(-1) , m_bAtOnce(false) { @@ -29,12 +30,13 @@ e2d::ETimer::ETimer(const TIMER_CALLBACK & callback, int repeatTimes /* = -1 */, m_bAtOnce = atOnce; } -e2d::ETimer::ETimer(const EString & name, const TIMER_CALLBACK & callback, int repeatTimes /* = -1 */, LONGLONG interval /* = 0 */, bool atOnce /* = false */) +e2d::ETimer::ETimer(const EString & name, const TimerCallback & callback, int repeatTimes /* = -1 */, float interval /* = 0 */, bool atOnce /* = false */) : m_bRunning(false) , m_nRunTimes(0) , m_pParentNode(nullptr) , m_Callback(nullptr) - , m_nInterval() + , m_fInterval(0) + , m_fLast(0) , m_nRepeatTimes(-1) , m_bAtOnce(false) { @@ -53,7 +55,7 @@ bool e2d::ETimer::isRunning() const void e2d::ETimer::start() { m_bRunning = true; - m_tLast = GetNow(); + m_fLast = ETime::getTotalTime(); } void e2d::ETimer::stop() @@ -76,12 +78,12 @@ void e2d::ETimer::setName(const EString & name) m_sName = name; } -void e2d::ETimer::setInterval(LONGLONG interval) +void e2d::ETimer::setInterval(float interval) { - SetInterval(m_nInterval, max(interval, 0)); + m_fInterval = max(interval, 0); } -void e2d::ETimer::setCallback(const TIMER_CALLBACK & callback) +void e2d::ETimer::setCallback(const TimerCallback & callback) { m_Callback = callback; } @@ -125,17 +127,17 @@ bool e2d::ETimer::_isReady() { if (m_bRunning && m_pParentNode && - m_pParentNode->getParentScene() == EApp::getCurrentScene()) + m_pParentNode->getParentScene() == ESceneManager::getCurrentScene()) { if (m_bAtOnce && m_nRunTimes == 0) return true; - if (m_nInterval.QuadPart == 0) + if (m_fInterval == 0) return true; - if (IsIntervalFull(m_tLast, m_nInterval)) + if ((ETime::getTotalTime() - m_fLast) >= m_fInterval) { - m_tLast.QuadPart += m_nInterval.QuadPart; + m_fLast += m_fInterval; return true; } } diff --git a/core/Transition/ETransition.cpp b/core/Transition/ETransition.cpp index d57bddaa..b666549a 100644 --- a/core/Transition/ETransition.cpp +++ b/core/Transition/ETransition.cpp @@ -1,15 +1,14 @@ +#include "..\ebase.h" #include "..\etransitions.h" -#include "..\Win\winbase.h" e2d::ETransition::ETransition(float duration) : m_bEnd(false) - , m_fTotalDuration(duration * 1000) - , m_fDuration(0) + , m_fLast(0) , m_fRateOfProgress(0) , m_pPrevScene(nullptr) , m_pNextScene(nullptr) { - SetInterval(m_nAnimationInterval, 15LL); + m_fDuration = max(duration, 0); } bool e2d::ETransition::isEnding() @@ -17,25 +16,17 @@ bool e2d::ETransition::isEnding() return m_bEnd; } -bool e2d::ETransition::_isDelayEnough() +void e2d::ETransition::_calcRateOfProgress() { // 判断时间间隔是否足够 - if (m_fTotalDuration == 0) + if (m_fDuration == 0) { m_fRateOfProgress = 1; - return true; + return; } - if (IsIntervalFull(m_tLast, m_nAnimationInterval)) - { - // 重新记录时间 - m_tLast.QuadPart += m_nAnimationInterval.QuadPart; - m_fDuration += static_cast(ToMilliseconds(m_nAnimationInterval.QuadPart)); - // 计算动画进度 - m_fRateOfProgress = m_fDuration / m_fTotalDuration; - return true; - } - return false; + // 计算动画进度 + m_fRateOfProgress = min((ETime::getTotalTime() - m_fLast) / m_fDuration, 1); } void e2d::ETransition::_stop() @@ -46,7 +37,7 @@ void e2d::ETransition::_stop() void e2d::ETransition::_setTarget(EScene * prev, EScene * next) { - m_tLast = GetNow(); + m_fLast = ETime::getTotalTime(); m_pPrevScene = prev; m_pNextScene = next; _init(); diff --git a/core/Transition/ETransitionEmerge.cpp b/core/Transition/ETransitionEmerge.cpp index 52b77cb2..1d05de2d 100644 --- a/core/Transition/ETransitionEmerge.cpp +++ b/core/Transition/ETransitionEmerge.cpp @@ -8,15 +8,14 @@ e2d::ETransitionEmerge::ETransitionEmerge(float duration) void e2d::ETransitionEmerge::_update() { - if (_isDelayEnough()) - { - if (m_pPrevScene) m_pPrevScene->getRoot()->setOpacity(1 - m_fRateOfProgress); - m_pNextScene->getRoot()->setOpacity(m_fRateOfProgress); + this->_calcRateOfProgress(); - if (m_fDuration >= m_fTotalDuration) - { - this->_stop(); - } + if (m_pPrevScene) m_pPrevScene->getRoot()->setOpacity(1 - m_fRateOfProgress); + m_pNextScene->getRoot()->setOpacity(m_fRateOfProgress); + + if (m_fRateOfProgress >= 1) + { + this->_stop(); } } diff --git a/core/Transition/ETransitionFade.cpp b/core/Transition/ETransitionFade.cpp index bbca7ddb..2b2ede10 100644 --- a/core/Transition/ETransitionFade.cpp +++ b/core/Transition/ETransitionFade.cpp @@ -3,34 +3,33 @@ e2d::ETransitionFade::ETransitionFade(float fadeOutDuration, float fadeInDuration) : ETransition(0) - , m_fFadeOutDuration(fadeOutDuration * 1000) - , m_fFadeInDuration(fadeInDuration * 1000) + , m_fFadeOutDuration(fadeOutDuration) + , m_fFadeInDuration(fadeInDuration) , m_bFadeOutTransioning(true) { - m_fTotalDuration = m_fFadeOutDuration; + m_fDuration = max(m_fFadeOutDuration, 0); } void e2d::ETransitionFade::_update() { - if (_isDelayEnough()) + this->_calcRateOfProgress(); + + if (m_bFadeOutTransioning) { - if (m_bFadeOutTransioning) + m_pPrevScene->getRoot()->setOpacity(1 - m_fRateOfProgress); + if (m_fRateOfProgress >= 1) { - m_pPrevScene->getRoot()->setOpacity(1 - m_fRateOfProgress); - if (m_fDuration >= m_fTotalDuration) - { - m_bFadeOutTransioning = false; - m_fTotalDuration = m_fFadeInDuration; - m_fDuration = 0; - } + m_bFadeOutTransioning = false; + m_fDuration = max(m_fFadeInDuration, 0); + m_fLast = ETime::getTotalTime(); } - else + } + else + { + m_pNextScene->getRoot()->setOpacity(m_fRateOfProgress); + if (m_fRateOfProgress >= 1) { - m_pNextScene->getRoot()->setOpacity(m_fRateOfProgress); - if (m_fDuration >= m_fTotalDuration) - { - this->_stop(); - } + this->_stop(); } } } @@ -45,7 +44,7 @@ void e2d::ETransitionFade::_init() else { m_bFadeOutTransioning = false; - m_fTotalDuration = m_fFadeInDuration; + m_fDuration = m_fFadeInDuration; } m_pNextScene->getRoot()->setOpacity(0); } diff --git a/core/Transition/ETransitionMove.cpp b/core/Transition/ETransitionMove.cpp index 77480756..b7e3a25a 100644 --- a/core/Transition/ETransitionMove.cpp +++ b/core/Transition/ETransitionMove.cpp @@ -9,15 +9,14 @@ e2d::ETransitionMove::ETransitionMove(float duration, MOVE_DIRECT direct) void e2d::ETransitionMove::_update() { - if (_isDelayEnough()) - { - if (m_pPrevScene) m_pPrevScene->getRoot()->setPos(m_Vec * m_fRateOfProgress); - m_pNextScene->getRoot()->setPos(m_NextPos + m_Vec * m_fRateOfProgress); + this->_calcRateOfProgress(); - if (m_fDuration >= m_fTotalDuration) - { - this->_stop(); - } + if (m_pPrevScene) m_pPrevScene->getRoot()->setPos(m_Vec * m_fRateOfProgress); + m_pNextScene->getRoot()->setPos(m_NextPos + m_Vec * m_fRateOfProgress); + + if (m_fRateOfProgress >= 1) + { + this->_stop(); } } @@ -25,23 +24,23 @@ void e2d::ETransitionMove::_init() { if (m_Direct == ETransitionMove::UP) { - m_Vec = EVec(0, -EApp::getHeight()); - m_NextPos = EPoint(0, EApp::getHeight()); + m_Vec = EVector2(0, -EWindow::getHeight()); + m_NextPos = EPoint(0, EWindow::getHeight()); } else if (m_Direct == ETransitionMove::DOWN) { - m_Vec = EVec(0, EApp::getHeight()); - m_NextPos = EPoint(0, -EApp::getHeight()); + m_Vec = EVector2(0, EWindow::getHeight()); + m_NextPos = EPoint(0, -EWindow::getHeight()); } else if (m_Direct == ETransitionMove::LEFT) { - m_Vec = EVec(-EApp::getWidth(), 0); - m_NextPos = EPoint(EApp::getWidth(), 0); + m_Vec = EVector2(-EWindow::getWidth(), 0); + m_NextPos = EPoint(EWindow::getWidth(), 0); } else if (m_Direct == ETransitionMove::RIGHT) { - m_Vec = EVec(EApp::getWidth(), 0); - m_NextPos = EPoint(-EApp::getWidth(), 0); + m_Vec = EVector2(EWindow::getWidth(), 0); + m_NextPos = EPoint(-EWindow::getWidth(), 0); } if (m_pPrevScene) m_pPrevScene->getRoot()->setPos(0, 0); diff --git a/core/Win/MciPlayer.h b/core/Win/MciPlayer.h deleted file mode 100644 index 9b8c45ff..00000000 --- a/core/Win/MciPlayer.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -class MciPlayer -{ -public: - MciPlayer(); - ~MciPlayer(); - - void close(); - bool open(const e2d::EString & pFileName, UINT uId); - bool open(const e2d::EString & pResouceName, const e2d::EString & pResouceType, const e2d::EString & musicExtension, UINT uId); - void play(int repeatTimes); - void pause(); - void resume(); - void stop(); - void rewind(); - bool isPlaying(); - UINT getMusicID(); - -private: - friend LRESULT WINAPI _MciPlayerProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); - void _sendCommand(int nCommand, DWORD_PTR param1 = 0, DWORD_PTR parma2 = 0); - - MCIDEVICEID m_dev; - HWND m_wnd; - UINT m_nMusicID; - bool m_bPlaying; - int m_nRepeatTimes; -}; diff --git a/core/Win/winbase.cpp b/core/Win/winbase.cpp deleted file mode 100644 index 297a8dc8..00000000 --- a/core/Win/winbase.cpp +++ /dev/null @@ -1,136 +0,0 @@ -#include "winbase.h" - - -static HWND s_HWnd = nullptr; -static ID2D1Factory * s_pDirect2dFactory = nullptr; -static ID2D1HwndRenderTarget * s_pRenderTarget = nullptr; -static ID2D1SolidColorBrush * s_pSolidBrush = nullptr; -static IWICImagingFactory * s_pIWICFactory = nullptr; -static IDWriteFactory * s_pDWriteFactory = nullptr; -static LARGE_INTEGER s_tNow; -static LARGE_INTEGER s_tFreq; - - -HWND &GetHWnd() -{ - return s_HWnd; -} - -ID2D1Factory * &GetFactory() -{ - if (!s_pDirect2dFactory) - { - // 创建设备无关资源,它们的生命周期和程序的时长相同 - HRESULT hr = S_OK; - - // 创建一个 Direct2D 工厂 - hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &s_pDirect2dFactory); - - ASSERT(SUCCEEDED(hr), "Create Device Independent Resources Failed!"); - } - return s_pDirect2dFactory; -} - -ID2D1HwndRenderTarget * &GetRenderTarget() -{ - if (!s_pRenderTarget) - { - // 创建设备相关资源。这些资源应在 Direct3D 设备消失时重建, - // 比如当 isVisiable 被修改,等等 - RECT rc; - GetClientRect(GetHWnd(), &rc); - - D2D1_SIZE_U size = D2D1::SizeU( - rc.right - rc.left, - rc.bottom - rc.top - ); - - // 创建一个 Direct2D 渲染目标 - HRESULT hr; - hr = GetFactory()->CreateHwndRenderTarget( - D2D1::RenderTargetProperties(), - D2D1::HwndRenderTargetProperties( - GetHWnd(), - size), - &s_pRenderTarget - ); - - ASSERT(SUCCEEDED(hr), "Create Render Target Failed! Maybe you should initalize EApp first."); - } - return s_pRenderTarget; -} - -IWICImagingFactory * &GetImagingFactory() -{ - if (!s_pIWICFactory) - { - // 创建 WIC 绘图工厂,用于统一处理各种格式的图片 - HRESULT hr = CoCreateInstance( - CLSID_WICImagingFactory, - NULL, - CLSCTX_INPROC_SERVER, - IID_IWICImagingFactory, - reinterpret_cast(&s_pIWICFactory) - ); - ASSERT(SUCCEEDED(hr), "Create WICImagingFactory Failed!"); - } - return s_pIWICFactory; -} - -IDWriteFactory * &GetDirectWriteFactory() -{ - if (!s_pDWriteFactory) - { - // 创建 DirectWrite 工厂 - HRESULT hr = DWriteCreateFactory( - DWRITE_FACTORY_TYPE_SHARED, - __uuidof(IDWriteFactory), - reinterpret_cast(&s_pDWriteFactory) - ); - ASSERT(SUCCEEDED(hr), "Create DirectWrite Factory Failed!"); - } - return s_pDWriteFactory; -} - -ID2D1SolidColorBrush * &GetSolidColorBrush() -{ - if (!s_pSolidBrush) - { - HRESULT hr; - hr = GetRenderTarget()->CreateSolidColorBrush( - D2D1::ColorF(D2D1::ColorF::White), - &s_pSolidBrush - ); - ASSERT(SUCCEEDED(hr), "Create Solid Color Brush Failed!"); - } - return s_pSolidBrush; -} - -LARGE_INTEGER &GetFreq() -{ - if (s_tFreq.QuadPart == 0) - { - QueryPerformanceFrequency(&s_tFreq); // 获取时钟频率 - } - return s_tFreq; -} - -LARGE_INTEGER &GetNow() -{ - return s_tNow; -} - -bool IsIntervalFull(const LARGE_INTEGER& tLast, const LARGE_INTEGER& tInterval) -{ - return (s_tNow.QuadPart - tLast.QuadPart) >= tInterval.QuadPart; -} - -LONGLONG ToMilliseconds(LONGLONG tLast) -{ - return tLast * 1000LL / GetFreq().QuadPart; -} - -void SetInterval(LARGE_INTEGER& nInterval, LONGLONG nIntervalMS) -{ - nInterval.QuadPart = static_cast(GetFreq().QuadPart * nIntervalMS / 1000.0); -} diff --git a/core/Win/winbase.h b/core/Win/winbase.h deleted file mode 100644 index a5c64452..00000000 --- a/core/Win/winbase.h +++ /dev/null @@ -1,45 +0,0 @@ -#pragma once -#include "..\emacros.h" - - -#ifndef HINST_THISCOMPONENT -EXTERN_C IMAGE_DOS_HEADER __ImageBase; -#define HINST_THISCOMPONENT ((HINSTANCE)&__ImageBase) -#endif - - -HWND &GetHWnd(); - -ID2D1Factory * &GetFactory(); - -ID2D1HwndRenderTarget * &GetRenderTarget(); - -ID2D1SolidColorBrush * &GetSolidColorBrush(); - -IWICImagingFactory * &GetImagingFactory(); - -IDWriteFactory * &GetDirectWriteFactory(); - -LARGE_INTEGER &GetFreq(); - -LARGE_INTEGER &GetNow(); - -bool IsIntervalFull(const LARGE_INTEGER& tLast, const LARGE_INTEGER& tInterval); - -LONGLONG ToMilliseconds(LONGLONG tLast); - -void SetInterval(LARGE_INTEGER& nInterval, LONGLONG nIntervalMS); - - -template -inline void SafeReleaseInterface( - Interface **ppInterfaceToRelease -) -{ - if (*ppInterfaceToRelease != nullptr) - { - (*ppInterfaceToRelease)->Release(); - - (*ppInterfaceToRelease) = nullptr; - } -} \ No newline at end of file diff --git a/core/eactions.h b/core/eactions.h index f00df0d1..82e98783 100644 --- a/core/eactions.h +++ b/core/eactions.h @@ -49,11 +49,6 @@ public: // 获取执行该动作的目标 virtual ENode * getTarget(); - // 设置动作每一帧的时间间隔 - virtual void setInterval( - LONGLONG milliSeconds - ); - // 设置动作执行目标 virtual void setTarget( ENode * node @@ -76,13 +71,12 @@ protected: virtual void _resetTime(); protected: - bool m_bRunning; - bool m_bEnding; - bool m_bInit; - ENode * m_pTarget; - EScene * m_pParentScene; - LARGE_INTEGER m_nAnimationInterval; - LARGE_INTEGER m_tLast; + bool m_bRunning; + bool m_bEnding; + bool m_bInit; + ENode * m_pTarget; + EScene *m_pParentScene; + float m_fLast; }; @@ -96,21 +90,17 @@ public: ); protected: - // 判断动作是否结束 - bool _isEnd() const; - - // 判断延时是否足够 - bool _isDelayEnough(); - // 初始化动画 virtual void _init() override; + // 更新动画 + virtual void _update() override; + // 重置动画 virtual void _reset() override; protected: float m_fDuration; - float m_fTotalDuration; float m_fRateOfProgress; }; @@ -122,7 +112,7 @@ public: // 创建相对位移动画 EActionMoveBy( float duration, /* 动画持续时长 */ - EVec vector /* 位移向量 */ + EVector2 vector /* 位移向量 */ ); // 获取该动画的拷贝对象 @@ -143,7 +133,7 @@ protected: protected: EPoint m_BeginPos; - EVec m_MoveVec; + EVector2 m_MoveVec; }; @@ -490,6 +480,9 @@ protected: // 重置动作 virtual void _reset() override; + +protected: + float m_fDelayTime; }; @@ -576,14 +569,19 @@ public: // 创建特定帧间隔的帧动画 EAnimation( - LONGLONG frameDelay /* 帧间隔(毫秒) */ + float interval /* 帧间隔(秒) */ ); virtual ~EAnimation(); - // 添加帧 - void addFrame( - ESpriteFrame * frame /* 添加帧 */ + // 添加关键帧 + void addKeyframe( + EKeyframe * frame /* 添加关键帧 */ + ); + + // 设置每一帧的时间间隔(秒) + void setInterval( + float interval ); // 获取该动画的拷贝对象 @@ -603,8 +601,9 @@ protected: virtual void _reset() override; protected: - UINT m_nFrameIndex; - std::vector m_vFrames; + float m_fInterval; + UINT m_nFrameIndex; + std::vector m_vFrames; }; diff --git a/core/easy2d.h b/core/easy2d.h index 4efe644d..94734ec8 100644 --- a/core/easy2d.h +++ b/core/easy2d.h @@ -1,7 +1,7 @@ /****************************************************** -* Easy2D Game Framework +* Easy2D Game Core * -* Website: http://www.easy2d.cn +* Website: https://www.easy2d.cn * Source Code: https://github.com/Nomango/Easy2D ******************************************************/ @@ -9,11 +9,11 @@ #pragma once #ifndef __cplusplus - #error Easy2D is only for C++ + #error 仅能在 C++ 环境下使用 Easy2D #endif #if _MSC_VER < 1600 - #error MSVC version is too low + #error Easy2D 不支持 Visual Studio 2010 以下版本 #endif diff --git a/core/ebase.h b/core/ebase.h index a682dad8..34c9ac78 100644 --- a/core/ebase.h +++ b/core/ebase.h @@ -8,29 +8,22 @@ namespace e2d { -class EScene; -class ENode; -class EObjectManager; -class EListenerMouse; -class EListenerKeyboard; -class EAction; -class ETransition; -class EApp +class EGame { public: - // 获取程序实例 - static EApp * getInstance(); - - // 初始化游戏界面 + // 初始化游戏 static bool init( - const EString &title, /* 窗口标题 */ - UINT32 width, /* 窗口宽度 */ - UINT32 height, /* 窗口高度 */ - const EWindowStyle &wStyle = nullptr /* 窗口样式 */ + LPCTSTR sTitle, /* 窗口标题 */ + UINT32 nWidth, /* 窗口宽度 */ + UINT32 nHeight, /* 窗口高度 */ + LPCTSTR pIconID = nullptr, /* 窗口图标 */ + bool bNoClose = false, /* 禁用关闭按钮 */ + bool bNoMiniSize = false, /* 禁用最小化按钮 */ + bool bTopMost = false /* 窗口置顶 */ ); - // 启动程序 + // 启动游戏 static int run(); // 暂停游戏 @@ -42,35 +35,32 @@ public: // 结束游戏 static void quit(); - // 切换场景 - static void enterScene( - EScene * scene, /* 下一个场景的指针 */ - ETransition * transition = nullptr, /* 场景切换动画 */ - bool saveCurrentScene = true /* 是否保存当前场景 */ - ); - - // 返回上一场景 - static void backScene( - ETransition * transition = nullptr /* 场景切换动画 */ - ); - - // 清空保存的所有场景 - static void clearScene(); - - // 隐藏窗口 - static void hideWindow(); - - // 显示窗口 - static void showWindow(); - - // 是否打开控制台 - static void showConsole( - bool show = true - ); + // 回收游戏资源 + static void uninit(); // 游戏是否暂停 static bool isPaused(); + // 获取 AppName + static EString getAppName(); + + // 设置 AppName + static void setAppName( + const EString &appname + ); + +private: + // 更新游戏内容 + static void __update(); +}; + + +// 控制窗口属性 +class EWindow +{ + friend EGame; + +public: // 获取窗口标题 static EString getTitle(); @@ -83,175 +73,209 @@ public: // 获取窗口大小 static ESize getSize(); - // 获取当前场景 - static EScene * getCurrentScene(); - // 获取窗口句柄 static HWND getHWnd(); - // 获取窗口样式 - static EWindowStyle getWindowStyle(); - - // 获取从游戏开始到当前经过的毫秒数 - static LONGLONG getTotalDurationFromStart(); - - // 获取 AppName - static EString getAppName(); - // 修改窗口大小 - static void setWindowSize( + static void setSize( UINT32 width, UINT32 height ); // 设置窗口标题 - static void setWindowTitle( + static void setTitle( const EString & title ); - // 设置 AppName - static void setAppName( - const EString &appname + // 打开/隐藏控制台 + static void showConsole( + bool show = true ); - // 修改窗口背景色 - static void setBkColor( + // 隐藏主窗口 + static void hideWindow(); + + // 显示主窗口 + static void showWindow(); + + // 是否允许响应输入法 + static void setTypewritingEnable( + bool bEnable + ); + +private: + // 初始化窗口 + static bool __init( + LPCTSTR sTitle, /* 窗口标题 */ + UINT32 nWidth, /* 窗口宽度 */ + UINT32 nHeight, /* 窗口高度 */ + LPCTSTR pIconID, /* 窗口图标 */ + bool bNoClose, /* 禁用关闭按钮 */ + bool bNoMiniSize, /* 禁用最小化按钮 */ + bool bTopMost /* 窗口置顶 */ + ); + + // 重置窗口属性 + static void __uninit(); + + // 处理窗口消息 + static void __poll(); + + // Win32 窗口消息回调程序 + static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); +}; + + +// 控制游戏时间 +class ETime +{ + friend EGame; + +public: + // 获取上一帧与当前帧的时间间隔(毫秒) + static int getDeltaTime(); + + // 获取游戏开始时长(秒) + static float getTotalTime(); + +private: + // 初始化计时操作 + static void __init(); + + // 重置计时操作 + static void __uninit(); + + // 更新当前时间 + static void __updateNow(); + + // 更新时间信息 + static void __updateLast(); + + // 挂起线程 + static void __sleep(); +}; + + +// 控制键盘和鼠标的输入 +class EInput +{ + friend EGame; + +public: + // 检测键盘某按键是否正被按下 + static bool isKeyDown( + int nKeyCode + ); + + // 检测键盘某按键是否被点击 + static bool isKeyPress( + int nKeyCode + ); + + // 检测键盘某按键是否正在松开 + static bool isKeyRelease( + int nKeyCode + ); + + // 检测鼠标左键是否正被按下 + static bool isMouseLButtonDown(); + + // 检测鼠标右键是否正被按下 + static bool isMouseRButtonDown(); + + // 检测鼠标中键是否正被按下 + static bool isMouseMButtonDown(); + + // 检测鼠标左键是否被点击 + static bool isMouseLButtonPress(); + + // 检测鼠标右键是否被点击 + static bool isMouseRButtonPress(); + + // 检测鼠标中键是否被点击 + static bool isMouseMButtonPress(); + + // 检测鼠标左键是否正在松开 + static bool isMouseLButtonRelease(); + + // 检测鼠标右键是否正在松开 + static bool isMouseRButtonRelease(); + + // 检测鼠标中键是否正在松开 + static bool isMouseMButtonRelease(); + + // 获得鼠标X轴坐标值 + static float getMouseX(); + + // 获得鼠标Y轴坐标值 + static float getMouseY(); + + // 获得鼠标坐标值 + static EPoint getMousePos(); + + // 获得鼠标X轴坐标增量 + static float getMouseDeltaX(); + + // 获得鼠标Y轴坐标增量 + static float getMouseDeltaY(); + + // 获得鼠标Z轴(鼠标滚轮)坐标增量 + static float getMouseDeltaZ(); + +private: + // 初始化 DirectInput 以及键盘鼠标设备 + static HRESULT __init(); + + // 获得输入信息 + static void __updateDeviceState(); + + // 卸载 DirectInput + static void __uninit(); +}; + + +// 渲染器 +class ERenderer +{ + friend EGame; + friend EWindow; + +public: + // 修改背景色 + static void setBackgroundColor( UINT32 color ); - // 设置程序是否响应输入法 - static void setKeyboardLayoutEnable( - bool value - ); + // 获取 ID2D1Factory 对象 + static ID2D1Factory * getID2D1Factory(); - // 预设画面帧数 - static void setFPS( - UINT32 fps - ); + // 获取 ID2D1HwndRenderTarget 对象 + static ID2D1HwndRenderTarget * getRenderTarget(); -public: - // 重写这个函数,它将在窗口激活时执行 - virtual bool onActivate(); + // 获取 ID2D1SolidColorBrush 对象 + static ID2D1SolidColorBrush * getSolidColorBrush(); - // 重写这个函数,它将在窗口非激活时执行 - virtual bool onInactive(); + // 获取 IWICImagingFactory 对象 + static IWICImagingFactory * getIWICImagingFactory(); - // 重写这个函数,它将在关闭窗口时执行 - virtual bool onCloseWindow(); + // 获取 IDWriteFactory 对象 + static IDWriteFactory * getIDWriteFactory(); private: - EApp(); + // 渲染游戏画面 + static void __render(); - virtual ~EApp(); + // 创建设备无关资源 + static bool __createDeviceIndependentResources(); - void _update(); + // 创建设备相关资源 + static bool __createDeviceResources(); - void _render(); + // 删除设备相关资源 + static void __discardDeviceResources(); - void _enterNextScene(); - - void _updateTime(); - - static LRESULT CALLBACK WndProc( - HWND hWnd, - UINT message, - WPARAM wParam, - LPARAM lParam - ); - -private: - bool m_bEnd; - bool m_bPaused; - bool m_bManualPaused; - bool m_bShowConsole; - EString m_sTitle; - EString m_sAppName; - UINT32 m_ClearColor; - LARGE_INTEGER m_nAnimationInterval; - EScene * m_pCurrentScene; - EScene * m_pNextScene; - EWindowStyle m_WindowStyle; - ETransition * m_pTransition; -}; - - -class EScene : - public EObject -{ - friend EApp; - -public: - EScene(); - - virtual ~EScene(); - - // 重写这个函数,它将在进入这个场景时自动执行 - virtual void onEnter(); - - // 重写这个函数,它将在离开这个场景时自动执行 - virtual void onExit(); - - // 重写这个函数,它将在窗口激活时执行 - virtual bool onActivate(); - - // 重写这个函数,它将在窗口非激活时执行 - virtual bool onInactive(); - - // 重写这个函数,它将在关闭窗口时执行 - virtual bool onCloseWindow(); - - // 添加子节点到场景 - void add( - ENode * child, - int zOrder = 0 - ); - - // 删除子节点 - bool remove( - ENode * child - ); - - // 删除相同名称的子节点 - void remove( - const EString &childName - ); - - // 获取所有子节点 - std::vector &getChildren(); - - // 获取子节点数量 - size_t getChildrenCount() const; - - // 根据名称获取子节点 - ENode * getChild( - const EString &childName - ); - - // 获取根节点 - ENode * getRoot() const; - - // 清空所有子成员 - void clearAllChildren(); - - // 执行动画 - void runAction( - EAction * action - ); - - // 开启几何图形的渲染 - void setGeometryVisiable( - bool visiable - ); - -protected: - // 渲染场景画面 - void _render(); - -protected: - bool m_bSortNeeded; - bool m_bWillSave; - bool m_bGeometryVisiable; - ENode * m_pRoot; + // 删除所有渲染相关资源 + static void __discardResources(); }; } \ No newline at end of file diff --git a/core/ecommon.h b/core/ecommon.h index a1d2e951..39844f6e 100644 --- a/core/ecommon.h +++ b/core/ecommon.h @@ -47,9 +47,6 @@ struct EPoint } }; -// 表示二维向量的结构体 -typedef EPoint EVec; - // 表示大小的结构体 struct ESize { @@ -89,46 +86,6 @@ struct ESize } }; -// 表示窗口样式的结构体 -struct EWindowStyle -{ - LPCTSTR m_pIconID; /* 程序图标 ID */ - bool m_bNoClose; /* 禁用关闭按钮 */ - bool m_bNoMiniSize; /* 禁用最小化按钮 */ - bool m_bTopMost; /* 窗口置顶 */ - - EWindowStyle() - { - m_pIconID = 0; - m_bNoClose = false; - m_bNoMiniSize = false; - m_bTopMost = false; - } - - EWindowStyle( - LPCTSTR pIconID - ) - { - m_pIconID = pIconID; - m_bNoClose = false; - m_bNoMiniSize = false; - m_bTopMost = false; - } - - EWindowStyle( - LPCTSTR pIconID, - bool bNoClose, - bool bNoMiniSize, - bool bTopMost - ) - { - m_pIconID = pIconID; - m_bNoClose = bNoClose; - m_bNoMiniSize = bNoMiniSize; - m_bTopMost = bTopMost; - } -}; - // 字符串 class EString { @@ -261,6 +218,32 @@ private: int _size; }; + +// 二维向量 +typedef EPoint EVector2; + +// 定时器回调函数(参数为该定时器被调用的次数,从 0 开始) +typedef std::function TimerCallback; + +// 按钮点击回调函数 +typedef std::function BtnClkCallback; + +// 物理世界消息监听器回调函数 +typedef std::function PhysLsnrCallback; + +// 碰撞消息监听器回调函数 +typedef PhysLsnrCallback ClsLsnrCallback; + +template +inline void SafeDelete(T** p) { if (*p) { delete *p; *p = nullptr; } } + +template +inline void SafeRelease(Obj** p) { if (*p) { (*p)->release(); *p = nullptr; } } + +template +inline void SafeReleaseInterface(Interface **pp) { if (*pp != nullptr) { (*pp)->Release(); (*pp) = nullptr; } } + + // 颜色 class EColor { @@ -268,143 +251,65 @@ public: enum COMMON_VALUE { ALICE_BLUE = 0xF0F8FF, - ANTIQUE_WHITE = 0xFAEBD7, AQUA = 0x00FFFF, - AQUAMARINE = 0x7FFFD4, AZURE = 0xF0FFFF, BEIGE = 0xF5F5DC, - BISQUE = 0xFFE4C4, BLACK = 0x000000, - BLANCHED_ALMOND = 0xFFEBCD, BLUE = 0x0000FF, BLUE_VIOLET = 0x8A2BE2, BROWN = 0xA52A2A, - BURLY_WOOD = 0xDEB887, - CADET_BLUE = 0x5F9EA0, - CHARTREUSE = 0x7FFF00, CHOCOLATE = 0xD2691E, - CORAL = 0xFF7F50, - CORNFLOWER_BLUE = 0x6495ED, - CORNSILK = 0xFFF8DC, - CRIMSON = 0xDC143C, CYAN = 0x00FFFF, DARK_BLUE = 0x00008B, DARK_CYAN = 0x008B8B, DARK_GOLDENROD = 0xB8860B, DARK_GRAY = 0xA9A9A9, DARK_GREEN = 0x006400, - DARK_KHAKI = 0xBDB76B, - DARK_MAGENTA = 0x8B008B, - DARK_OLIVE_GREEN = 0x556B2F, DARK_ORANGE = 0xFF8C00, - DARK_ORCHID = 0x9932CC, DARK_RED = 0x8B0000, - DARK_SALMON = 0xE9967A, DARK_SEA_GREEN = 0x8FBC8F, - DARK_SLATE_BLUE = 0x483D8B, - DARK_SLATE_GRAY = 0x2F4F4F, - DARK_TURQUOISE = 0x00CED1, DARK_VIOLET = 0x9400D3, DEEP_PINK = 0xFF1493, DEEP_SKY_BLUE = 0x00BFFF, - DIM_GRAY = 0x696969, - DODGER_BLUE = 0x1E90FF, - FIREBRICK = 0xB22222, - FLORAL_WHITE = 0xFFFAF0, FOREST_GREEN = 0x228B22, - FUCHSIA = 0xFF00FF, - GAINSCORO = 0xDCDCDC, - GHOST_WHITE = 0xF8F8FF, GOLD = 0xFFD700, GOLDENROD = 0xDAA520, GRAY = 0x808080, GREEN = 0x008000, GREEN_YELLOW = 0xADFF2F, - HONEYDEW = 0xF0FFF0, - HOT_PINK = 0xFF69B4, - INDIAN_RED = 0xCD5C5C, - INDIGO = 0x4B0082, - IVORY = 0xFFFFF0, - KHAKI = 0xF0E68C, - LAVENDER = 0xE6E6FA, - LAVENDER_BLUSH = 0xFFF0F5, - LAWN_GREEN = 0x7CFC00, - LEMON_CHIFFON = 0xFFFACD, LIGHT_BLUE = 0xADD8E6, - LIGHT_CORAL = 0xF08080, LIGHT_CYAN = 0xE0FFFF, LIGHT_GOLDENROD_YELLOW = 0xFAFAD2, LIGHT_GREEN = 0x90EE90, LIGHT_GRAY = 0xD3D3D3, LIGHT_PINK = 0xFFB6C1, - LIGHT_SALMON = 0xFFA07A, LIGHT_SEA_GREEN = 0x20B2AA, LIGHT_SKY_BLUE = 0x87CEFA, LIGHT_SLATE_GRAY = 0x778899, - LIGHT_STEEL_BLUE = 0xB0C4DE, LIGHT_YELLOW = 0xFFFFE0, - LIME = 0x00FF00, - LIME_GREEN = 0x32CD32, - LINEN = 0xFAF0E6, - MAGENTA = 0xFF00FF, - MAROON = 0x800000, - MEDIUM_AQUAMARINE = 0x66CDAA, MEDIUM_BLUE = 0x0000CD, - MEDIUM_ORCHID = 0xBA55D3, MEDIUM_PURPLE = 0x9370DB, MEDIUM_SEA_GREEN = 0x3CB371, - MEDIUM_SLATE_BLUE = 0x7B68EE, MEDIUM_SPRING_GREEN = 0x00FA9A, - MEDIUM_TURQUOISE = 0x48D1CC, MEDUIM_VIOLET_RED = 0xC71585, MIDNIGHT_BLUE = 0x191970, - MINT_CREAM = 0xF5FFFA, - MISTY_ROSE = 0xFFE4E1, - MOCCASIN = 0xFFE4B5, - NAVAJO_WHITE = 0xFFDEAD, - NAVY = 0x000080, - OLD_LACE = 0xFDF5E6, - OLIVE = 0x808000, - OLIVE_DRAB = 0x6B8E23, ORANGE = 0xFFA500, ORANGE_RED = 0xFF4500, - ORCHID = 0xDA70D6, - PALE_GOLDENROD = 0xEEE8AA, - PALE_GREEN = 0x98FB98, - PALE_TURQUOISE = 0xAFEEEE, - PALE_VIOLET_RED = 0xDB7093, - PAPAYA_WHIP = 0xFFEFD5, - PEACH_PUFF = 0xFFDAB9, - PERU = 0xCD853F, PINK = 0xFFC0CB, - PLUM = 0xDDA0DD, - POWDER_BLUE = 0xB0E0E6, PURPLE = 0x800080, RED = 0xFF0000, - ROSY_BROWN = 0xBC8F8F, - ROYAL_BLUE = 0x4169E1, - SADDLE_BROWN = 0x8B4513, - SALMON = 0xFA8072, - SANDY_BROWN = 0xF4A460, SEA_GREEN = 0x2E8B57, SEA_SHELL = 0xFFF5EE, - SIENNA = 0xA0522D, SILVER = 0xC0C0C0, SKY_BLUE = 0x87CEEB, - SLATE_BLUE = 0x6A5ACD, - SLATE_GRAY = 0x708090, SNOW = 0xFFFAFA, SPRING_GREEN = 0x00FF7F, - STEEL_BLUE = 0x4682B4, - TAN = 0xD2B48C, - TEAL = 0x008080, - THISTLE = 0xD8BFD8, TOMATO = 0xFF6347, - TURQUOISE = 0x40E0D0, VIOLET = 0xEE82EE, WHEAT = 0xF5DEB3, WHITE = 0xFFFFFF, WHITE_SMOKE = 0xF5F5F5, + WOOD = 0xDEB887, YELLOW = 0xFFFF00, YELLOW_GREEN = 0x9ACD32 }; @@ -437,136 +342,86 @@ public: }; -// 鼠标消息 -class EMouseMsg +// 键值集合 +class EKeyCode { public: - // 鼠标消息集合 - enum MOUSE_MSG + enum VALUE { - MOVE = 0x0200, // 鼠标移动 - LBUTTON_DOWN, // 鼠标左键按下 - LBUTTON_UP, // 鼠标左键抬起 - LBUTTON_DBLCLK, // 鼠标左键双击 - RBUTTON_DOWN, // 鼠标右键按下 - RBUTTON_UP, // 鼠标右键抬起 - RBUTTON_DBLCLK, // 鼠标右键双击 - MBUTTON_DOWN, // 鼠标中键按下 - MBUTTON_UP, // 鼠标中键抬起 - MBUTTON_DBLCLK, // 鼠标中键双击 - WHEEL // 滑动滚轮 + UP = 0xC8, + LEFT = 0xCB, + RIGHT = 0xCD, + DOWN = 0xD0, + ENTER = 0x1C, + SPACE = 0x39, + ESC = 0x01, + BACK = 0x0E, + TAB = 0x0F, + PAUSE = 0xC5, + Q = 0x10, + W = 0x11, + E = 0x12, + R = 0x13, + T = 0x14, + Y = 0x15, + U = 0x16, + I = 0x17, + O = 0x18, + P = 0x19, + A = 0x1E, + S = 0x1F, + D = 0x20, + F = 0x21, + G = 0x22, + H = 0x23, + J = 0x24, + K = 0x25, + L = 0x26, + Z = 0x2C, + X = 0x2D, + C = 0x2E, + V = 0x2F, + B = 0x30, + N = 0x31, + M = 0x32, + NUM1 = 0x02, + NUM2 = 0x03, + NUM3 = 0x04, + NUM4 = 0x05, + NUM5 = 0x06, + NUM6 = 0x07, + NUM7 = 0x08, + NUM8 = 0x09, + NUM9 = 0x0A, + NUM0 = 0x0B, + NUMPAD7 = 0x47, + NUMPAD8 = 0x48, + NUMPAD9 = 0x49, + NUMPAD4 = 0x4B, + NUMPAD5 = 0x4C, + NUMPAD6 = 0x4D, + NUMPAD1 = 0x4F, + NUMPAD2 = 0x50, + NUMPAD3 = 0x51, + NUMPAD0 = 0x52, + F1 = 0x3B, + F2 = 0x3C, + F3 = 0x3D, + F4 = 0x3E, + F5 = 0x3F, + F6 = 0x40, + F7 = 0x41, + F8 = 0x42, + F9 = 0x43, + F10 = 0x44 }; - - // 获取鼠标横坐标 - static DWORD getPosX(); - - // 获取鼠标纵坐标 - static DWORD getPosY(); - - // 获取鼠标坐标 - static EPoint getPos(); - - // 获取鼠标左键按下状态 - static bool isLButtonDown(); - - // 获取鼠标中键按下状态 - static bool isMButtonDown(); - - // 获取鼠标右键按下状态 - static bool isRButtonDown(); - - // 获取 Shift 按键状态 - static bool isShiftDown(); - - // 获取 Ctrl 按键状态 - static bool isCtrlDown(); - - // 获取鼠标滚轮值 - static DWORD getWheelDelta(); - - // 获取当前鼠标消息类型 - static MOUSE_MSG getMsg(); - -public: - static UINT s_nMsg; - static WPARAM s_wParam; - static LPARAM s_lParam; -}; - - -// 按键消息 -class EKeyboardMsg -{ -public: - // 按键消息类型集合 - enum KEYBOARD_MSG - { - KEY_DOWN = 0x0100, // 按下 - KEY_UP // 抬起 - }; - - // 按键键值集合 - enum KEY - { - A = 'A', B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, // 字母键值 - NUM0 = '0', NUM1, NUM2, NUM3, NUM4, NUM5, NUM6, NUM7, NUM8, NUM9, // 数字键值 - NUMPAD0 = 0x60, NUMPAD1, NUMPAD2, NUMPAD3, NUMPAD4, NUMPAD5, NUMPAD6, NUMPAD7, NUMPAD8, NUMPAD9, // 数字小键盘键值 - F1 = 0x70, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, // F键键值 - MULTIPLY, // 乘号键键值 - ADD, // 加号键键值 - SEPARATOR, // 分割键键值 - SUBTRACT, // 减号键键值 - DECIMAL, // 小数点键键值 - DIVIDE, // 除号键键值 - TAB = 0x09, // TAB 键键值 - ENTER = 0x0D, // 回车键键值 - SHIFT, CTRL, // SHIFT 键键值 - ESC = 0x1B, // ESCAPE 键键值 - SPACE = 0x20, // 空格键键值 - PAGE_UP, // PageUp 键键值 - PAGE_DOWN, // PageDown 键键值 - END, // End 键键值 - HOME, // Home 键键值 - LEFT, // 左键键值 - UP, // 上键键值 - RIGHT, // 右键键值 - DOWN // 下键键值 - }; - - // 获取按键消息类型 - static KEYBOARD_MSG getMsg(); - - // 获取键值 - static KEY getKeyValue(); - - // 获取按键消息的计数 - static DWORD getCount(); - - // 获取特定按键的状态 - static bool isKeyDown( - KEY key - ); - - // 获取大小写锁定状态 - static bool isCapitalLockOn(); - - // 获取数字小键盘锁定状态 - static bool isNumpadLockOn(); - - // 获取滑动锁定状态 - static bool isScrollLockOn(); - -public: - static UINT s_nMsg; - static WPARAM s_wParam; - static LPARAM s_lParam; }; class EGeometry; // 物理消息 -class EPhysicsMsg +class EPhysicsEvent { public: enum INTERSECT_RELATION @@ -694,27 +549,27 @@ protected: class ESprite; -class ETexture : +class EImage : public EObject { friend ESprite; public: - // 创建一个空的纹理 - ETexture(); + // 创建一个空的图片 + EImage(); // 从本地文件中读取资源 - ETexture( - const EString & fileName + EImage( + LPCTSTR fileName ); // 读取程序资源 - ETexture( + EImage( LPCTSTR resourceName, LPCTSTR resourceType ); - virtual ~ETexture(); + virtual ~EImage(); // 从本地文件中读取资源 void loadFromFile( @@ -758,42 +613,42 @@ protected: }; -class ESpriteFrame : +class EKeyframe : public EObject { friend ESprite; public: - // 创建空的精灵帧 - ESpriteFrame(); + // 创建空的关键帧 + EKeyframe(); - // 创建空的精灵帧 - ESpriteFrame( - ETexture * texture + // 创建空的关键帧 + EKeyframe( + EImage * texture ); - // 创建空的精灵帧 - ESpriteFrame( + // 创建空的关键帧 + EKeyframe( const EString & imageFileName ); - // 创建空的精灵帧 - ESpriteFrame( + // 创建空的关键帧 + EKeyframe( LPCTSTR resourceName, LPCTSTR resourceType ); - // 创建空的精灵帧 - ESpriteFrame( - ETexture * texture, + // 创建空的关键帧 + EKeyframe( + EImage * texture, float x, float y, float width, float height ); - // 创建空的精灵帧 - ESpriteFrame( + // 创建空的关键帧 + EKeyframe( const EString & imageFileName, float x, float y, @@ -801,8 +656,8 @@ public: float height ); - // 创建空的精灵帧 - ESpriteFrame( + // 创建空的关键帧 + EKeyframe( LPCTSTR resourceName, LPCTSTR resourceType, float x, @@ -811,7 +666,7 @@ public: float height ); - virtual ~ESpriteFrame(); + virtual ~EKeyframe(); // 获取宽度 float getWidth() const; @@ -819,16 +674,16 @@ public: // 获取高度 float getHeight() const; - // 获取纹理 - ETexture * getTexture() const; + // 获取图片 + EImage * getImage() const; protected: - // 获取纹理 - void _setTexture( - ETexture * texture + // 修改图片 + void _setImage( + EImage * texture ); - // 裁剪纹理 + // 裁剪图片 void _clipTexture( float x, float y, @@ -841,39 +696,98 @@ protected: float m_fSourceClipY; float m_fSourceClipWidth; float m_fSourceClipHeight; - ETexture * m_pTexture; + EImage * m_pImage; }; + +class ESceneManager; class ENode; +class EAction; -// 定时器回调函数(参数为该定时器被调用的次数,从 0 开始) -typedef std::function TIMER_CALLBACK; +// 场景 +class EScene : + public EObject +{ + friend ESceneManager; -// 按钮点击回调函数 -typedef std::function BUTTON_CLICK_CALLBACK; +public: + EScene(); -// 按键消息监听回调函数 -typedef std::function KEY_LISTENER_CALLBACK; + virtual ~EScene(); -// 鼠标消息监听回调函数 -typedef std::function MOUSE_LISTENER_CALLBACK; + // 重写这个函数,它将在进入这个场景时自动执行 + virtual void onEnter() {} -// 鼠标点击消息监听回调函数(参数为点击位置) -typedef std::function MOUSE_CLICK_LISTENER_CALLBACK; + // 重写这个函数,它将在离开这个场景时自动执行 + virtual void onExit() {} -// 鼠标按下消息监听回调函数(参数为按下位置) -typedef MOUSE_CLICK_LISTENER_CALLBACK MOUSE_PRESS_LISTENER_CALLBACK; + // 重写这个函数,它将在窗口激活时执行 + virtual bool onActivate() { return false; } -// 鼠标双击消息监听回调函数(参数为双击位置) -typedef MOUSE_CLICK_LISTENER_CALLBACK MOUSE_DBLCLK_LISTENER_CALLBACK; + // 重写这个函数,它将在窗口非激活时执行 + virtual bool onInactive() { return false; } -// 鼠标拖动消息监听回调函数(参数为拖动前位置和拖动后位置) -typedef std::function MOUSE_DRAG_LISTENER_CALLBACK; + // 重写这个函数,它将在关闭窗口时执行 + virtual bool onCloseWindow() { return true; } -// 物理世界消息监听器回调函数 -typedef std::function PHYSICS_LISTENER_CALLBACK; + // 重写这个函数,它将在每一帧画面刷新时执行 + virtual void onUpdate() {} -// 碰撞消息监听器回调函数 -typedef PHYSICS_LISTENER_CALLBACK COLLISION_LISTENER_CALLBACK; + // 添加子节点到场景 + void add( + ENode * child, + int zOrder = 0 + ); + + // 删除子节点 + bool remove( + ENode * child + ); + + // 删除相同名称的子节点 + void remove( + const EString &childName + ); + + // 获取所有子节点 + std::vector getChildren(); + + // 获取子节点数量 + size_t getChildrenCount() const; + + // 根据名称获取子节点 + ENode * getChild( + const EString &childName + ); + + // 获取根节点 + ENode * getRoot() const; + + // 清空所有子成员 + void clearAllChildren(); + + // 执行动画 + void runAction( + EAction * action + ); + + // 开启几何图形的渲染 + void setGeometryVisiable( + bool visiable + ); + +protected: + // 渲染场景画面 + void _render(); + + // 更新场景内容 + void _update(); + +protected: + bool m_bSortNeeded; + bool m_bWillSave; + bool m_bGeometryVisiable; + ENode * m_pRoot; +}; } \ No newline at end of file diff --git a/core/egeometry.h b/core/egeometry.h index 1b1934f6..6cbe436c 100644 --- a/core/egeometry.h +++ b/core/egeometry.h @@ -56,7 +56,7 @@ public: protected: // 判断两形状的交集关系 - virtual EPhysicsMsg::INTERSECT_RELATION _intersectWith( + virtual EPhysicsEvent::INTERSECT_RELATION _intersectWith( EGeometry * pGeometry ); diff --git a/core/elisteners.h b/core/elisteners.h index 998b3d09..140d6425 100644 --- a/core/elisteners.h +++ b/core/elisteners.h @@ -6,15 +6,12 @@ namespace e2d { class ENode; -class EMsgManager; class EPhysicsManager; // 监听器 class EListener : public EObject { - friend EMsgManager; - public: EListener(); @@ -78,265 +75,6 @@ protected: }; -// 鼠标消息监听器 -class EListenerMouse : - public EListener -{ - friend EMsgManager; - -public: - EListenerMouse(); - - EListenerMouse( - const EString &name - ); - - EListenerMouse( - const MOUSE_LISTENER_CALLBACK &callback - ); - - EListenerMouse( - const EString &name, - const MOUSE_LISTENER_CALLBACK &callback - ); - - // 设置监听器回调函数 - void setCallback( - const MOUSE_LISTENER_CALLBACK &callback - ); - - // 绑定监听器到场景 - virtual void bindWith( - EScene * pParentScene - ) override; - - // 绑定监听器到节点 - virtual void bindWith( - ENode * pParentNode - ) override; - -protected: - // 执行监听器回调函数 - virtual void _callOn() override; - -protected: - MOUSE_LISTENER_CALLBACK m_Callback; -}; - - -// 鼠标按下消息监听器 -class EListenerMousePress : - public EListenerMouse -{ -public: - EListenerMousePress(); - - EListenerMousePress( - const EString &name - ); - - EListenerMousePress( - const MOUSE_PRESS_LISTENER_CALLBACK &callback - ); - - EListenerMousePress( - const EString &name, - const MOUSE_PRESS_LISTENER_CALLBACK &callback - ); - - // 设置监听器回调函数 - void setCallback( - const MOUSE_PRESS_LISTENER_CALLBACK &callback - ); - -protected: - // 执行监听器回调函数 - virtual void _callOn() override; - -protected: - MOUSE_PRESS_LISTENER_CALLBACK m_Callback; -}; - - -// 鼠标点击消息监听器 -class EListenerMouseClick : - public EListenerMouse -{ -public: - EListenerMouseClick(); - - EListenerMouseClick( - const EString &name - ); - - EListenerMouseClick( - const MOUSE_CLICK_LISTENER_CALLBACK &callback - ); - - EListenerMouseClick( - const EString &name, - const MOUSE_CLICK_LISTENER_CALLBACK &callback - ); - - // 设置监听器回调函数 - void setCallback( - const MOUSE_CLICK_LISTENER_CALLBACK &callback - ); - -protected: - // 执行监听器回调函数 - virtual void _callOn() override; - -protected: - bool m_bPressed; - MOUSE_CLICK_LISTENER_CALLBACK m_Callback; -}; - - -// 鼠标点击消息监听器 -class EListenerMouseDoubleClick : - public EListenerMouse -{ -public: - EListenerMouseDoubleClick(); - - EListenerMouseDoubleClick( - const EString &name - ); - - EListenerMouseDoubleClick( - const MOUSE_DBLCLK_LISTENER_CALLBACK &callback - ); - - EListenerMouseDoubleClick( - const EString &name, - const MOUSE_DBLCLK_LISTENER_CALLBACK &callback - ); - - // 设置监听器回调函数 - void setCallback( - const MOUSE_DBLCLK_LISTENER_CALLBACK &callback - ); - -protected: - // 执行监听器回调函数 - virtual void _callOn() override; - -protected: - bool m_bPressed; - MOUSE_DBLCLK_LISTENER_CALLBACK m_Callback; -}; - - -// 鼠标拖动消息监听器 -class EListenerMouseDrag : - public EListenerMouse -{ -public: - EListenerMouseDrag(); - - EListenerMouseDrag( - const EString &name - ); - - EListenerMouseDrag( - const MOUSE_DRAG_LISTENER_CALLBACK &callback - ); - - EListenerMouseDrag( - const EString &name, - const MOUSE_DRAG_LISTENER_CALLBACK &callback - ); - - // 设置监听器回调函数 - void setCallback( - const MOUSE_DRAG_LISTENER_CALLBACK &callback - ); - -protected: - // 执行监听器回调函数 - virtual void _callOn() override; - -protected: - EPoint m_Begin; - MOUSE_DRAG_LISTENER_CALLBACK m_Callback; -}; - - -// 按键消息监听器 -class EListenerKeyboard : - public EListener -{ - friend EMsgManager; - -public: - EListenerKeyboard(); - - EListenerKeyboard( - const EString &name - ); - - EListenerKeyboard( - const KEY_LISTENER_CALLBACK &callback - ); - - EListenerKeyboard( - const EString &name, - const KEY_LISTENER_CALLBACK &callback - ); - - // 设置监听器回调函数 - void setCallback( - const KEY_LISTENER_CALLBACK &callback - ); - - // 绑定监听器到场景 - virtual void bindWith( - EScene * pParentScene - ) override; - - // 绑定监听器到节点 - virtual void bindWith( - ENode * pParentNode - ) override; - -protected: - // 执行监听器回调函数 - virtual void _callOn() override; - -protected: - KEY_LISTENER_CALLBACK m_Callback; -}; - - -// 按键按下消息监听 -class EListenerKeyboardPress : - public EListenerKeyboard -{ - friend EMsgManager; - -public: - EListenerKeyboardPress(); - - EListenerKeyboardPress( - const EString &name - ); - - EListenerKeyboardPress( - const KEY_LISTENER_CALLBACK &callback - ); - - EListenerKeyboardPress( - const EString &name, - const KEY_LISTENER_CALLBACK &callback - ); - -protected: - // 执行监听器回调函数 - virtual void _callOn() override; -}; - - // 物理世界消息监听器 class EListenerPhysics : public EListener @@ -351,17 +89,17 @@ public: ); EListenerPhysics( - const PHYSICS_LISTENER_CALLBACK &callback + const PhysLsnrCallback &callback ); EListenerPhysics( const EString &name, - const PHYSICS_LISTENER_CALLBACK &callback + const PhysLsnrCallback &callback ); // 设置监听器回调函数 void setCallback( - const PHYSICS_LISTENER_CALLBACK &callback + const PhysLsnrCallback &callback ); // 将监听器与场景绑定 @@ -379,7 +117,7 @@ protected: virtual void _callOn() override; protected: - PHYSICS_LISTENER_CALLBACK m_Callback; + PhysLsnrCallback m_Callback; }; @@ -395,12 +133,12 @@ public: ); EListenerPhysicsCollision( - const COLLISION_LISTENER_CALLBACK &callback + const ClsLsnrCallback &callback ); EListenerPhysicsCollision( const EString &name, - const COLLISION_LISTENER_CALLBACK &callback + const ClsLsnrCallback &callback ); protected: @@ -408,7 +146,7 @@ protected: virtual void _callOn() override; protected: - COLLISION_LISTENER_CALLBACK m_Callback; + ClsLsnrCallback m_Callback; }; } \ No newline at end of file diff --git a/core/emacros.h b/core/emacros.h index 168f4bdf..2dc81e93 100644 --- a/core/emacros.h +++ b/core/emacros.h @@ -24,6 +24,10 @@ #define WIN32_LEAN_AND_MEAN #endif +#ifndef DIRECTINPUT_VERSION +#define DIRECTINPUT_VERSION 0x0800 +#endif + // Windows Header Files: #include #include @@ -34,15 +38,22 @@ #include #include #include +#include #include #pragma comment(lib, "d2d1.lib") #pragma comment(lib, "dwrite.lib") #pragma comment(lib, "windowscodecs.lib") +#ifndef HINST_THISCOMPONENT +EXTERN_C IMAGE_DOS_HEADER __ImageBase; +#define HINST_THISCOMPONENT ((HINSTANCE)&__ImageBase) +#endif + + #ifndef ASSERT_IF #if defined( DEBUG ) || defined( _DEBUG ) -#define ASSERT(b, m) do {if (!(b)) { fprintf(stderr, "Assert: " #m "\n"); assert(b); }} while(0) + #define ASSERT(b, m) do {if (!(b)) { fprintf(stderr, "Assert: " #m "\n"); assert(b); }} while(0) #else #define ASSERT(b, m) ((void)0) #endif //DEBUG || _DEBUG @@ -50,18 +61,8 @@ #ifndef WARN_IF #if defined( DEBUG ) || defined( _DEBUG ) -#define WARN_IF(b, m) do {if (b) { fprintf(stderr, "Warning: " #m "\n"); }} while(0) + #define WARN_IF(b, m) do {if (b) { fprintf(stderr, "Warning: " #m "\n"); }} while(0) #else -#define WARN_IF(b, m) ((void)0) + #define WARN_IF(b, m) ((void)0) #endif //DEBUG || _DEBUG -#endif - - -#define DEPRECATED_ATTRIBUTE __declspec(deprecated) - - -template -inline void SafeDelete(T** p) { if (*p) { delete *p; *p = nullptr; } } - -template -inline void SafeRelease(T** p) { if (*p) { (*p)->release(); *p = nullptr; } } \ No newline at end of file +#endif \ No newline at end of file diff --git a/core/emanagers.h b/core/emanagers.h index c0c969e0..f42cbef1 100644 --- a/core/emanagers.h +++ b/core/emanagers.h @@ -5,21 +5,21 @@ namespace e2d { -class EApp; +class EGame; +class ERenderer; class EObject; class EScene; class ENode; class ETimer; class EAction; -class EListenerMouse; -class EListenerKeyboard; class EGeometry; +class ETransition; class EListenerPhysics; // 对象管理器 class EObjectManager { - friend EApp; + friend EGame; public: // 将一个节点放入内存池 @@ -36,154 +36,47 @@ private: }; -// 消息管理器 -class EMsgManager +// 场景管理器 +class ESceneManager { - friend EApp; - friend EScene; - friend ENode; + friend EGame; + friend ERenderer; public: - // 绑定鼠标消息监听器到场景 - static void bindListener( - EListenerMouse * listener, - EScene * pParentScene + // 切换场景 + static void enterScene( + EScene * scene, /* 下一个场景的指针 */ + ETransition * transition = nullptr, /* 场景切换动画 */ + bool saveCurrentScene = true /* 是否保存当前场景 */ ); - // 绑定鼠标消息监听器到节点 - static void bindListener( - EListenerMouse * listener, - ENode * pParentNode + // 返回上一场景 + static void backScene( + ETransition * transition = nullptr /* 场景切换动画 */ ); - // 启动具有相同名称的鼠标消息监听器 - static void startMouseListeners( - const EString &name - ); + // 清空保存的所有场景 + static void clearScene(); - // 停止具有相同名称的鼠标消息监听器 - static void stopMouseListeners( - const EString &name - ); - - // 删除具有相同名称的鼠标消息监听器 - static void delMouseListeners( - const EString &name - ); - - // 启动绑定在场景及其子节点上的所有鼠标消息监听器 - static void startAllMouseListenersBindedWith( - EScene * pParentScene - ); - - // 停止绑定在场景及其子节点上的所有鼠标消息监听器 - static void stopAllMouseListenersBindedWith( - EScene * pParentScene - ); - - // 启动绑定在节点上的所有鼠标消息监听器 - static void startAllMouseListenersBindedWith( - ENode * pParentNode - ); - - // 停止绑定在节点上的所有鼠标消息监听器 - static void stopAllMouseListenersBindedWith( - ENode * pParentNode - ); - - // 启动所有鼠标消息监听器 - static void startAllMouseListeners(); - - // 停止所有鼠标消息监听器 - static void stopAllMouseListeners(); - - // 绑定按键消息监听器到场景 - static void bindListener( - EListenerKeyboard * listener, - EScene * pParentScene - ); - - // 绑定按键消息监听器到节点 - static void bindListener( - EListenerKeyboard * listener, - ENode * pParentNode - ); - - // 启动名称相同的按键消息监听器 - static void startKeyboardListeners( - const EString &name - ); - - // 停止名称相同的按键消息监听器 - static void stopKeyboardListeners( - const EString &name - ); - - // 删除名称相同的按键消息监听器 - static void delKeyboardListeners( - const EString &name - ); - - // 启动绑定在场景及其子节点上的所有按键消息监听器 - static void startAllKeyboardListenersBindedWith( - EScene * pParentScene - ); - - // 停止绑定在场景及其子节点上的所有按键消息监听器 - static void stopAllKeyboardListenersBindedWith( - EScene * pParentScene - ); - - // 启动绑定在节点上的所有按键消息监听器 - static void startAllKeyboardListenersBindedWith( - ENode * pParentNode - ); - - // 停止绑定在节点上的所有按键消息监听器 - static void stopAllKeyboardListenersBindedWith( - ENode * pParentNode - ); - - // 启动所有按键消息监听器 - static void startAllKeyboardListeners(); - - // 停止所有按键消息监听器 - static void stopAllKeyboardListeners(); + // 获取当前场景 + static EScene * getCurrentScene(); private: - // 清除所有监听器 - static void _clearManager(); + // 更新场景内容 + static void __update(); - // 清除绑定在节点上的所有鼠标消息监听器 - static void _clearAllMouseListenersBindedWith( - ENode * pParentNode - ); + // 渲染场景画面 + static void __render(); - // 清除绑定在节点上的所有按键消息监听器 - static void _clearAllKeyboardListenersBindedWith( - ENode * pParentNode - ); - - // 鼠标消息程序 - static void MouseProc( - UINT message, - WPARAM wParam, - LPARAM lParam - ); - - // 按键消息程序 - static void KeyboardProc( - UINT message, - WPARAM wParam, - LPARAM lParam - ); + // 进入下一场景 + static void __enterNextScene(); }; // 定时器管理器 class ETimerManager { - friend EApp; + friend EGame; friend EScene; friend ENode; @@ -242,26 +135,23 @@ public: static void stopAllTimers(); private: - // 清空定时器管理器 - static void _clearManager(); + // 更新定时器 + static void __update(); // 清空绑定在节点上的所有定时器 - static void _clearAllTimersBindedWith( + static void __clearAllTimersBindedWith( ENode * pParentNode ); // 重置定时器状态 - static void _resetAllTimers(); - - // 定时器执行程序 - static void TimerProc(); + static void __resetAllTimers(); }; // 动作管理器 class EActionManager { - friend EApp; + friend EGame; friend EScene; friend ENode; @@ -272,7 +162,7 @@ public: ); // 继续绑定在节点上的所有动作 - static void startAllActionsBindedWith( + static void resumeAllActionsBindedWith( ENode * pTargetNode ); @@ -287,7 +177,7 @@ public: ); // 继续所有动作 - static void startAllActions(); + static void resumeAllActions(); // 暂停所有动作 static void pauseAllActions(); @@ -296,25 +186,22 @@ public: static void stopAllActions(); private: - // 清空动画管理器 - static void _clearManager(); + // 更新动画状态 + static void __update(); // 清空绑定在节点上的所有动作 - static void _clearAllActionsBindedWith( + static void __clearAllActionsBindedWith( ENode * pTargetNode ); // 重置所有动作状态 - static void _resetAllActions(); - - // 动作执行程序 - static void ActionProc(); + static void __resetAllActions(); }; class EPhysicsManager { - friend EApp; + friend EGame; friend EScene; friend ENode; friend EGeometry; diff --git a/core/enodes.h b/core/enodes.h index b4a73d99..8df00389 100644 --- a/core/enodes.h +++ b/core/enodes.h @@ -31,11 +31,17 @@ public: virtual ~ENode(); - // 重写这个函数,它将在节点进入场景时自动执行 - virtual void onEnter(); + // 节点进入场景时,这个函数将自动运行 + virtual void onEnter() {} - // 重写这个函数,它将在节点离开场景时自动执行 - virtual void onExit(); + // 节点离开场景时,这个函数将自动运行 + virtual void onExit() {} + + // 每一帧画面刷新时,这个函数将自动运行 + virtual void onUpdate() {} + + // 渲染节点时,这个函数将自动运行 + virtual void onRender() {} // 获取节点显示状态 virtual bool isVisiable() const; @@ -163,7 +169,7 @@ public: // 移动节点 virtual void movePos( - const EVec & v + const EVector2 & v ); // 设置节点绘图顺序 @@ -295,7 +301,7 @@ public: ); // 继续所有暂停动画 - virtual void startAllActions(); + virtual void resumeAllActions(); // 暂停所有动画 virtual void pauseAllActions(); @@ -411,22 +417,22 @@ public: // 从文理资源创建精灵 ESprite( - ETexture * texture + EImage * image ); - // 从精灵帧创建精灵 + // 从关键帧创建精灵 ESprite( - ESpriteFrame * spriteFrame + EKeyframe * spriteFrame ); // 从文件图片创建精灵 ESprite( - const EString & imageFileName + LPCTSTR imageFileName ); // 从文件图片创建精灵并裁剪 ESprite( - const EString & imageFileName, + LPCTSTR imageFileName, float x, float y, float width, @@ -451,37 +457,37 @@ public: virtual ~ESprite(); - // 加载精灵纹理 + // 加载精灵图片 void loadFrom( - ETexture * texture + EImage * texture ); - // 从本地文件加载纹理 + // 从本地文件加载图片 void loadFrom( - const EString & imageFileName + LPCTSTR imageFileName ); - // 从资源加载纹理 + // 从资源加载图片 void loadFrom( LPCTSTR resourceName, LPCTSTR resourceType ); - // 加载纹理并裁剪 + // 加载图片并裁剪 void loadFrom( - ETexture * texture, + EImage * image, float x, float y, float width, float height ); - // 从精灵帧加载资源 + // 从关键帧加载资源 void loadFrom( - ESpriteFrame * frame + EKeyframe * frame ); - // 裁剪纹理 + // 裁剪图片 void clip( float x, float y, @@ -489,14 +495,13 @@ public: float height ); -protected: // 渲染精灵 - virtual void _render() override; + virtual void onRender() override; protected: float m_fSourceClipX; float m_fSourceClipY; - ETexture * m_pTexture; + EImage * m_pImage; }; @@ -562,10 +567,10 @@ public: float wordWrapWidth ); -protected: // 渲染文字 - virtual void _render() override; + virtual void onRender() override; +protected: // 创建文字布局 void _initTextLayout(); @@ -589,14 +594,14 @@ public: // 创建按钮 EButton( ENode * normal, /* 普通状态 */ - const BUTTON_CLICK_CALLBACK & callback = nullptr + const BtnClkCallback & callback = nullptr ); // 创建按钮 EButton( ENode * normal, /* 普通状态 */ ENode * selected, /* 鼠标按下状态 */ - const BUTTON_CLICK_CALLBACK & callback = nullptr + const BtnClkCallback & callback = nullptr ); // 创建按钮 @@ -604,7 +609,7 @@ public: ENode * normal, /* 普通状态 */ ENode * mouseover, /* 鼠标移入状态 */ ENode * selected, /* 鼠标按下状态 */ - const BUTTON_CLICK_CALLBACK & callback = nullptr + const BtnClkCallback & callback = nullptr ); // 创建按钮 @@ -613,7 +618,7 @@ public: ENode * mouseover, /* 鼠标移入状态 */ ENode * selected, /* 鼠标移入状态 */ ENode * disabled, /* 按钮禁用状态 */ - const BUTTON_CLICK_CALLBACK & callback = nullptr + const BtnClkCallback & callback = nullptr ); // 获取按钮状态是启用还是禁用 @@ -646,7 +651,7 @@ public: // 设置回调函数 void setCallback( - const BUTTON_CLICK_CALLBACK & callback + const BtnClkCallback & callback ); // 设置中心点的横向位置 @@ -668,24 +673,18 @@ public: float pivotY ) override; + // 更新按钮状态 + virtual void onUpdate(); + protected: enum STATUS { NORMAL, MOUSEOVER, SELECTED }; - // 初始化按钮 - virtual void _init(); - // 设置按钮状态 virtual void _setStatus(STATUS status); - // 对自身进行二维矩阵变换 - virtual void _updateTransform() override; - // 刷新按钮显示 virtual void _updateVisiable(); - // 刷新按钮状态 - virtual void _updateStatus(); - // 执行按钮回调函数 virtual void _runCallback(); @@ -697,8 +696,7 @@ protected: ENode * m_pDisabled; bool m_bEnable; bool m_bIsSelected; - EListenerMouse * m_pListener; - BUTTON_CLICK_CALLBACK m_Callback; + BtnClkCallback m_Callback; }; @@ -713,7 +711,7 @@ public: EButtonToggle( ENode * toggleOnNormal, ENode * toggleOffNormal, - const BUTTON_CLICK_CALLBACK & callback = nullptr + const BtnClkCallback & callback = nullptr ); // 创建开关按钮 @@ -722,7 +720,7 @@ public: ENode * toggleOffNormal, ENode * toggleOnSelected, ENode * toggleOffSelected, - const BUTTON_CLICK_CALLBACK & callback = nullptr + const BtnClkCallback & callback = nullptr ); // 创建开关按钮 @@ -733,7 +731,7 @@ public: ENode * toggleOffMouseOver, ENode * toggleOnSelected, ENode * toggleOffSelected, - const BUTTON_CLICK_CALLBACK & callback = nullptr + const BtnClkCallback & callback = nullptr ); // 创建开关按钮 @@ -746,7 +744,7 @@ public: ENode * toggleOffSelected, ENode * toggleOnDisabled, ENode * toggleOffDisabled, - const BUTTON_CLICK_CALLBACK & callback = nullptr + const BtnClkCallback & callback = nullptr ); // 切换开关状态,并执行回调函数 diff --git a/core/etools.h b/core/etools.h index 4b862f8c..43d3ffda 100644 --- a/core/etools.h +++ b/core/etools.h @@ -8,6 +8,47 @@ namespace e2d class ETimerManager; class EAction; +// 随机数产生器 +class ERandom +{ +public: + // 取得整型范围内的一个随机数 + template + static inline T range(T min, T max) { return e2d::ERandom::randomInt(min, max); } + + // 取得浮点数范围内的一个随机数 + static inline float range(float min, float max) { return e2d::ERandom::randomReal(min, max); } + + // 取得浮点数范围内的一个随机数 + static inline double range(double min, double max) { return e2d::ERandom::randomReal(min, max); } + + // 取得浮点数范围内的一个随机数 + static inline long double range(long double min, long double max) { return e2d::ERandom::randomReal(min, max); } + + // 取得整型范围内的一个随机数 + template + static T randomInt( + T min, + T max) + { + std::uniform_int_distribution dist(min, max); + return dist(getEngine()); + } + + // 取得浮点数类型范围内的一个随机数 + template + static T randomReal( + T min, + T max) + { + std::uniform_real_distribution dist(min, max); + return dist(getEngine()); + } + + // 获取随机数产生器 + static std::default_random_engine &getEngine(); +}; + // 定时器 class ETimer : @@ -19,17 +60,17 @@ public: ETimer(); ETimer( - const TIMER_CALLBACK &callback, /* 定时器回调函数 */ + const TimerCallback &callback, /* 定时器回调函数 */ int repeatTimes = -1, /* 定时器执行次数 */ - LONGLONG interval = 0LL, /* 时间间隔(毫秒) */ + float interval = 0LL, /* 时间间隔(秒) */ bool atOnce = false /* 是否立即执行 */ ); ETimer( const EString &name, /* 定时器名称 */ - const TIMER_CALLBACK &callback, /* 定时器回调函数 */ + const TimerCallback &callback, /* 定时器回调函数 */ int repeatTimes = -1, /* 定时器执行次数 */ - LONGLONG interval = 0LL, /* 时间间隔(毫秒) */ + float interval = 0, /* 时间间隔(秒) */ bool atOnce = false /* 是否立即执行 */ ); @@ -53,14 +94,14 @@ public: const EString &name ); - // 设置定时器执行间隔 + // 设置定时器执行间隔(秒) void setInterval( - LONGLONG interval + float interval ); // 设置定时器回调函数 void setCallback( - const TIMER_CALLBACK & callback + const TimerCallback & callback ); // 设置定时器重复执行次数 @@ -96,14 +137,60 @@ protected: bool m_bAtOnce; int m_nRunTimes; int m_nRepeatTimes; + float m_fInterval; + float m_fLast; ENode * m_pParentNode; - TIMER_CALLBACK m_Callback; - LARGE_INTEGER m_nInterval; - LARGE_INTEGER m_tLast; + TimerCallback m_Callback; }; -class EFileUtils +// 数据管理工具 +class EData +{ +public: + // 保存 int 类型的值 + static void saveInt( + const EString & key, + int value + ); + + // 保存 float 类型的值 + static void saveFloat( + const EString & key, + float value + ); + + // 保存 字符串 类型的值 + static void saveString( + const EString & key, + const EString & value + ); + + // 获取 int 类型的值 + // (若不存在则返回 defaultValue 参数的值) + static int getInt( + const EString & key, + int defaultValue + ); + + // 获取 float 类型的值 + // (若不存在则返回 defaultValue 参数的值) + static float getFloat( + const EString & key, + float defaultValue + ); + + // 获取 字符串 类型的值 + // (若不存在则返回 defaultValue 参数的值) + static EString getString( + const EString & key, + const EString & defaultValue + ); +}; + + +// 文件管理工具 +class EFile { public: // 获取系统的 AppData Local 路径 @@ -115,110 +202,31 @@ public: // 获取默认的保存路径 static EString getDefaultSavePath(); - // 保存 int 型的值 - static void saveInt( - const EString & key, - int value - ); - - // 保存 float 型的值 - static void saveFloat( - const EString & key, - float value - ); - - // 保存 字符串 型的值(不要在 Unicode 字符集下保存中文字符) - static void saveString( - const EString & key, - const EString & value - ); - - // 获取 int 型的值(若不存在则返回 default 参数的值) - static int getInt( - const EString & key, - int default - ); - - // 获取 float 型的值(若不存在则返回 default 参数的值) - static float getFloat( - const EString & key, - float default - ); - - // 获取 字符串 型的值(若不存在则返回 default 参数的值) - static EString getString( - const EString & key, - const EString & default - ); - - // 得到文件扩展名(小写) + // 获取文件扩展名 static EString getFileExtension( const EString & filePath ); - /** - * 打开保存文件对话框,得到有效保存路径返回 true - * 参数:窗口标题,默认扩展名 - */ + // 打开保存文件对话框 static EString getSaveFilePath( - const EString & title = L"保存到", - const EString & defExt = L"" + const EString & title = L"保存到", /* 对话框标题 */ + const EString & defExt = L"" /* 默认扩展名 */ ); }; -class ERandom -{ -public: - // 取得整型范围内的一个随机数 - template - static inline T between(T min, T max) { return e2d::ERandom::randomInt(min, max); } - - // 取得浮点数范围内的一个随机数 - static inline float between(float min, float max) { return e2d::ERandom::randomReal(min, max); } - - // 取得浮点数范围内的一个随机数 - static inline double between(double min, double max) { return e2d::ERandom::randomReal(min, max); } - - // 取得浮点数范围内的一个随机数 - static inline long double between(long double min, long double max) { return e2d::ERandom::randomReal(min, max); } - - // 取得整型范围内的一个随机数 - template - static T randomInt( - T min, - T max) - { - std::uniform_int_distribution dist(min, max); - return dist(getEngine()); - } - - // 取得浮点数类型范围内的一个随机数 - template - static T randomReal( - T min, - T max) - { - std::uniform_real_distribution dist(min, max); - return dist(getEngine()); - } - - // 获取随机数产生器 - static std::default_random_engine &getEngine(); -}; - - -class EMusicUtils +// 音乐管理工具 +class EMusic { public: // 播放音乐 - static UINT playMusic( + static UINT play( const EString & musicFilePath, /* 音乐文件路径 */ int repeatTimes = 1 ); // 播放音乐 - static UINT playMusic( + static UINT play( const EString & musicResourceName, /* 资源名称 */ const EString & musicResourceType, /* 资源类别 */ const EString & musicExtension, /* 指定资源的扩展名 */ @@ -226,42 +234,42 @@ public: ); // 暂停音乐 - static bool pauseMusic( + static bool pause( UINT musicId ); // 暂停音乐 - static bool pauseMusic( + static bool pause( const EString& musicName ); // 继续播放音乐 - static bool resumeMusic( + static bool resume( UINT musicId ); // 继续播放音乐 - static bool resumeMusic( + static bool resume( const EString& musicName ); // 停止音乐 - static bool stopMusic( + static bool stop( UINT musicId ); // 停止音乐 - static bool stopMusic( + static bool stop( const EString& musicName ); // 预加载音乐 - static UINT preloadMusic( + static UINT preload( const EString & musicFilePath ); // 预加载音乐 - static UINT preloadMusic( + static UINT preload( const EString & musicResourceName, /* 资源名称 */ const EString & musicResourceType, /* 资源类别 */ const EString & musicExtension /* 指定资源的扩展名 */ diff --git a/core/etransitions.h b/core/etransitions.h index f3f24d15..52ed98d0 100644 --- a/core/etransitions.h +++ b/core/etransitions.h @@ -1,13 +1,16 @@ #pragma once -#include "ebase.h" +#include "ecommon.h" namespace e2d { + +class ESceneManager; + class ETransition : public EObject { - friend EApp; + friend ESceneManager; public: ETransition(float duration); @@ -16,17 +19,21 @@ public: bool isEnding(); protected: - // 更新动画 + // 更新场景动画 virtual void _update() = 0; + // 初始化场景动画 virtual void _init() = 0; + // 重置场景动画 virtual void _reset() = 0; - virtual bool _isDelayEnough(); - + // 停止场景动画 virtual void _stop(); + // 计算场景动画进度 + void _calcRateOfProgress(); + // 保存当前场景和下一场景的指针 void _setTarget( EScene * prev, @@ -35,13 +42,11 @@ protected: protected: bool m_bEnd; - float m_fTotalDuration; + float m_fLast; float m_fDuration; float m_fRateOfProgress; EScene * m_pPrevScene; EScene * m_pNextScene; - LARGE_INTEGER m_tLast; - LARGE_INTEGER m_nAnimationInterval; }; @@ -117,7 +122,7 @@ protected: protected: MOVE_DIRECT m_Direct; - EVec m_Vec; + EVector2 m_Vec; EPoint m_NextPos; }; diff --git a/prebuilt/vs2010/Easy2Ddw.lib b/prebuilt/vs2010/Easy2Ddw.lib deleted file mode 100644 index 8062f66c..00000000 Binary files a/prebuilt/vs2010/Easy2Ddw.lib and /dev/null differ diff --git a/prebuilt/vs2010/Easy2Dw.lib b/prebuilt/vs2010/Easy2Dw.lib deleted file mode 100644 index 87431162..00000000 Binary files a/prebuilt/vs2010/Easy2Dw.lib and /dev/null differ diff --git a/prebuilt/vs2017/Easy2Ddw.lib b/prebuilt/vs2017/Easy2Ddw.lib deleted file mode 100644 index 1813bcb7..00000000 Binary files a/prebuilt/vs2017/Easy2Ddw.lib and /dev/null differ diff --git a/prebuilt/vs2017/Easy2Dw.lib b/prebuilt/vs2017/Easy2Dw.lib deleted file mode 100644 index cb04b508..00000000 Binary files a/prebuilt/vs2017/Easy2Dw.lib and /dev/null differ diff --git a/project/vs2010/Easy2D.vcxproj b/project/vs2010/Easy2D.vcxproj index 8c3670bd..1f3e673b 100644 --- a/project/vs2010/Easy2D.vcxproj +++ b/project/vs2010/Easy2D.vcxproj @@ -94,72 +94,63 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - diff --git a/project/vs2010/Easy2D.vcxproj.filters b/project/vs2010/Easy2D.vcxproj.filters index a9adec6a..e144e4ef 100644 --- a/project/vs2010/Easy2D.vcxproj.filters +++ b/project/vs2010/Easy2D.vcxproj.filters @@ -1,275 +1,215 @@ 锘 - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hpp;hxx;hm;inl;inc;xsd - - - {d4a509dd-1bc0-4456-9554-d414de91b50c} - - - {3ff66c81-6040-4f84-a39a-d21b4bb54819} - - + {5be538cb-a432-4f84-9678-bbf408eca288} - - {6c760a81-9bc8-4fb0-a145-8e119b783365} + + {d4a509dd-1bc0-4456-9554-d414de91b50c} - - {7b102f67-5905-4c0e-8400-51c128da026a} - - - {c536c42c-283d-4a10-b19b-0699b4f1e051} - - - {17bdc67b-1801-4b69-b79b-ffcbbee8dae0} - - - {7454d212-5d2e-4b0b-865c-30fb02d2878c} - - - {c5f168c6-1403-486a-9cae-ab29495a723c} - - + {c907d829-e510-472c-bd47-cf4eab6f9266} - + + {62d6a1d4-f1ec-458a-aee0-377b16012bed} + + {508b39c8-a430-45c3-9405-364fbc281220} + + {c5f168c6-1403-486a-9cae-ab29495a723c} + + + {7b102f67-5905-4c0e-8400-51c128da026a} + + + {c536c42c-283d-4a10-b19b-0699b4f1e051} + + + {17bdc67b-1801-4b69-b79b-ffcbbee8dae0} + + + {6c760a81-9bc8-4fb0-a145-8e119b783365} + - - 澶存枃浠 - - - 澶存枃浠 - - - 澶存枃浠 - - - 澶存枃浠 - - - 澶存枃浠 - - - 澶存枃浠 - - - 澶存枃浠 - - - 澶存枃浠 - - - 澶存枃浠 - - - 澶存枃浠 - - - 澶存枃浠 - - - 婧愭枃浠禱Win - - - 婧愭枃浠禱Win - + + + + + + + + + + + - - 婧愭枃浠禱Base + + Action - - 婧愭枃浠禱Base + + Action - - 婧愭枃浠禱Msg + + Action - - 婧愭枃浠禱Msg + + Action - - 婧愭枃浠禱Msg + + Action - - 婧愭枃浠禱Action + + Action - - 婧愭枃浠禱Action + + Action - - 婧愭枃浠禱Action + + Action - - 婧愭枃浠禱Action + + Action - - 婧愭枃浠禱Action + + Action - - 婧愭枃浠禱Action + + Action - - 婧愭枃浠禱Action + + Action - - 婧愭枃浠禱Action + + Action - - 婧愭枃浠禱Action + + Action - - 婧愭枃浠禱Action + + Action - - 婧愭枃浠禱Action + + Action - - 婧愭枃浠禱Action + + Action - - 婧愭枃浠禱Action + + Base - - 婧愭枃浠禱Action + + Base - - 婧愭枃浠禱Action + + Base - - 婧愭枃浠禱Action + + Base - - 婧愭枃浠禱Action + + Base - - 婧愭枃浠禱Manager + + Common - - 婧愭枃浠禱Manager + + Common - - 婧愭枃浠禱Manager + + Common - - 婧愭枃浠禱Manager + + Common - - 婧愭枃浠禱Manager + + Common - - 婧愭枃浠禱Listener + + Common - - 婧愭枃浠禱Listener + + Geometry - - 婧愭枃浠禱Listener + + Geometry - - 婧愭枃浠禱Listener + + Geometry - - 婧愭枃浠禱Listener + + Geometry - - 婧愭枃浠禱Listener + + Event - - 婧愭枃浠禱Listener + + Listener - - 婧愭枃浠禱Listener + + Listener - - 婧愭枃浠禱Listener + + Listener - - 婧愭枃浠禱Listener + + Manager - - 婧愭枃浠禱Common + + Manager - - 婧愭枃浠禱Common + + Manager - - 婧愭枃浠禱Common + + Manager - - 婧愭枃浠禱Common + + Manager - - 婧愭枃浠禱Common + + Node - - 婧愭枃浠禱Geometry + + Node - - 婧愭枃浠禱Geometry + + Node - - 婧愭枃浠禱Geometry + + Node - - 婧愭枃浠禱Geometry + + Node - - 婧愭枃浠禱Win + + Node - - 婧愭枃浠禱Win + + Tool - - 婧愭枃浠禱Tool + + Tool - - 婧愭枃浠禱Tool + + Tool - - 婧愭枃浠禱Tool - - - 婧愭枃浠禱Tool - - - 婧愭枃浠禱Node - - - 婧愭枃浠禱Node - - - 婧愭枃浠禱Node - - - 婧愭枃浠禱Node - - - 婧愭枃浠禱Node - - - 婧愭枃浠禱Node + + Tool - 婧愭枃浠禱Transition + Transition - 婧愭枃浠禱Transition + Transition - 婧愭枃浠禱Transition + Transition - 婧愭枃浠禱Transition + Transition \ No newline at end of file diff --git a/project/vs2012/Easy2D.sln b/project/vs2012/Easy2D.sln new file mode 100644 index 00000000..cc69b66e --- /dev/null +++ b/project/vs2012/Easy2D.sln @@ -0,0 +1,20 @@ +锘 +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Easy2D", "Easy2D.vcxproj", "{722EA245-ADD5-4296-8C85-8FF42C0335D3}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {722EA245-ADD5-4296-8C85-8FF42C0335D3}.Debug|Win32.ActiveCfg = Debug|Win32 + {722EA245-ADD5-4296-8C85-8FF42C0335D3}.Debug|Win32.Build.0 = Debug|Win32 + {722EA245-ADD5-4296-8C85-8FF42C0335D3}.Release|Win32.ActiveCfg = Release|Win32 + {722EA245-ADD5-4296-8C85-8FF42C0335D3}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/project/vs2012/Easy2D.vcxproj b/project/vs2012/Easy2D.vcxproj new file mode 100644 index 00000000..324f8da0 --- /dev/null +++ b/project/vs2012/Easy2D.vcxproj @@ -0,0 +1,160 @@ +锘 + + + + Debug + Win32 + + + Release + Win32 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {722EA245-ADD5-4296-8C85-8FF42C0335D3} + Win32Proj + Easy2D + + + + StaticLibrary + true + v110 + Unicode + + + StaticLibrary + false + v110 + false + Unicode + + + + + + + + + + + + + $(SolutionDir)$(Platform)\ + $(Configuration)\$(Platform)\ + Easy2Ddw + + + $(SolutionDir)$(Platform)\ + $(Configuration)\$(Platform)\ + Easy2Dw + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + None + false + + + Windows + true + + + + + Level3 + + + MaxSpeed + + + true + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + None + + + Windows + true + true + true + + + + + + \ No newline at end of file diff --git a/project/vs2012/Easy2D.vcxproj.filters b/project/vs2012/Easy2D.vcxproj.filters new file mode 100644 index 00000000..c11d1034 --- /dev/null +++ b/project/vs2012/Easy2D.vcxproj.filters @@ -0,0 +1,215 @@ +锘 + + + + {01311827-b639-4313-a5b6-61cd22fe8920} + + + {e5c42dd3-2d56-4a95-8f88-45d059d58c21} + + + {08126b0c-d139-48f9-8559-3d9d9e3a5940} + + + {a00a6f30-ec6b-42be-93a2-c540466670a8} + + + {a8185fe2-5477-4293-97d6-d84f27d354bb} + + + {dfaa8954-50d7-49c5-8aa6-7232c6d5c557} + + + {9b2673ff-9077-4d74-b7ec-b435e5540b66} + + + {70412fec-4c60-425b-81c9-4547e5a1b78a} + + + {dacd05f1-3496-488b-af4d-b3ea7bce9515} + + + {337d5a0f-60fd-473a-83da-b2a3515affd9} + + + + + + + + + + + + + + + + + + Action + + + Action + + + Action + + + Action + + + Action + + + Action + + + Action + + + Action + + + Action + + + Action + + + Action + + + Action + + + Action + + + Action + + + Action + + + Action + + + Action + + + Base + + + Base + + + Base + + + Base + + + Base + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Event + + + Manager + + + Manager + + + Manager + + + Manager + + + Manager + + + Geometry + + + Geometry + + + Geometry + + + Geometry + + + Listener + + + Listener + + + Listener + + + Tool + + + Tool + + + Tool + + + Tool + + + Transition + + + Transition + + + Transition + + + Transition + + + Node + + + Node + + + Node + + + Node + + + Node + + + Node + + + \ No newline at end of file diff --git a/project/vs2013/Easy2D.sln b/project/vs2013/Easy2D.sln new file mode 100644 index 00000000..46fc71fb --- /dev/null +++ b/project/vs2013/Easy2D.sln @@ -0,0 +1,22 @@ +锘 +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.21005.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Easy2D", "Easy2D.vcxproj", "{91DBDFCC-4083-427C-AAAD-55715118DB26}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {91DBDFCC-4083-427C-AAAD-55715118DB26}.Debug|Win32.ActiveCfg = Debug|Win32 + {91DBDFCC-4083-427C-AAAD-55715118DB26}.Debug|Win32.Build.0 = Debug|Win32 + {91DBDFCC-4083-427C-AAAD-55715118DB26}.Release|Win32.ActiveCfg = Release|Win32 + {91DBDFCC-4083-427C-AAAD-55715118DB26}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/project/vs2013/Easy2D.vcxproj b/project/vs2013/Easy2D.vcxproj new file mode 100644 index 00000000..abf975a4 --- /dev/null +++ b/project/vs2013/Easy2D.vcxproj @@ -0,0 +1,160 @@ +锘 + + + + Debug + Win32 + + + Release + Win32 + + + + {91DBDFCC-4083-427C-AAAD-55715118DB26} + Win32Proj + Win32Project1 + + + + StaticLibrary + true + v120 + Unicode + + + StaticLibrary + false + v120 + false + Unicode + + + + + + + + + + + + + $(SolutionDir)$(Platform)\ + $(Configuration)\$(Platform)\ + Easy2Ddw + + + $(SolutionDir)$(Platform)\ + $(Configuration)\$(Platform)\ + Easy2Dw + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + None + false + + + Windows + true + + + + + Level3 + + + MaxSpeed + + + true + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + None + + + Windows + true + true + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/project/vs2013/Easy2D.vcxproj.filters b/project/vs2013/Easy2D.vcxproj.filters new file mode 100644 index 00000000..c11d1034 --- /dev/null +++ b/project/vs2013/Easy2D.vcxproj.filters @@ -0,0 +1,215 @@ +锘 + + + + {01311827-b639-4313-a5b6-61cd22fe8920} + + + {e5c42dd3-2d56-4a95-8f88-45d059d58c21} + + + {08126b0c-d139-48f9-8559-3d9d9e3a5940} + + + {a00a6f30-ec6b-42be-93a2-c540466670a8} + + + {a8185fe2-5477-4293-97d6-d84f27d354bb} + + + {dfaa8954-50d7-49c5-8aa6-7232c6d5c557} + + + {9b2673ff-9077-4d74-b7ec-b435e5540b66} + + + {70412fec-4c60-425b-81c9-4547e5a1b78a} + + + {dacd05f1-3496-488b-af4d-b3ea7bce9515} + + + {337d5a0f-60fd-473a-83da-b2a3515affd9} + + + + + + + + + + + + + + + + + + Action + + + Action + + + Action + + + Action + + + Action + + + Action + + + Action + + + Action + + + Action + + + Action + + + Action + + + Action + + + Action + + + Action + + + Action + + + Action + + + Action + + + Base + + + Base + + + Base + + + Base + + + Base + + + Common + + + Common + + + Common + + + Common + + + Common + + + Common + + + Event + + + Manager + + + Manager + + + Manager + + + Manager + + + Manager + + + Geometry + + + Geometry + + + Geometry + + + Geometry + + + Listener + + + Listener + + + Listener + + + Tool + + + Tool + + + Tool + + + Tool + + + Transition + + + Transition + + + Transition + + + Transition + + + Node + + + Node + + + Node + + + Node + + + Node + + + Node + + + \ No newline at end of file diff --git a/project/vs2017/Easy2D.sln b/project/vs2017/Easy2D.sln index c4734e48..9284ee79 100644 --- a/project/vs2017/Easy2D.sln +++ b/project/vs2017/Easy2D.sln @@ -7,13 +7,20 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Easy2D", "Easy2D.vcxproj", EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 Debug|x86 = Debug|x86 + Release|x64 = Release|x64 Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution + {FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}.Debug|x64.ActiveCfg = Debug|x64 + {FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}.Debug|x64.Build.0 = Debug|x64 + {FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}.Debug|x64.Deploy.0 = Debug|x64 {FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}.Debug|x86.ActiveCfg = Debug|Win32 {FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}.Debug|x86.Build.0 = Debug|Win32 {FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}.Debug|x86.Deploy.0 = Debug|Win32 + {FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}.Release|x64.ActiveCfg = Release|x64 + {FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}.Release|x64.Build.0 = Release|x64 {FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}.Release|x86.ActiveCfg = Release|Win32 {FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}.Release|x86.Build.0 = Release|Win32 EndGlobalSection diff --git a/project/vs2017/Easy2D.vcxproj b/project/vs2017/Easy2D.vcxproj index 06645478..7b5a6eb2 100644 --- a/project/vs2017/Easy2D.vcxproj +++ b/project/vs2017/Easy2D.vcxproj @@ -43,6 +43,7 @@ StaticLibrary true Unicode + v141 StaticLibrary @@ -189,68 +190,62 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - @@ -264,8 +259,6 @@ - - diff --git a/project/vs2017/Easy2D.vcxproj.filters b/project/vs2017/Easy2D.vcxproj.filters index bb60a7f1..aa812845 100644 --- a/project/vs2017/Easy2D.vcxproj.filters +++ b/project/vs2017/Easy2D.vcxproj.filters @@ -1,9 +1,6 @@ 锘 - - {2f0f3d30-bfc2-4aea-a170-258bbaacaa79} - {42d46a92-c043-4667-8c20-358319e5c313} @@ -31,202 +28,181 @@ {be5d9314-b00a-4f11-bd2a-1f720dc32407} - - {3c524aef-fb91-4f44-a3dc-bff34de229eb} + + {6d0b43af-2432-4221-b572-4bef331ae10e} - - Win - - - Base - - - Node - - - Base - - - Node - - - Node - - - Action - - - Action - - - Action - - - Action - - - Action - - - Action - - - Action - - - Action - - - Action - - - Action - - - Action - - - Action - - - Action - - - Tool - - - Tool - - - Action - - - Action - - - Action - Transition - - Action - - - Manager - - - Manager - - - Manager - - - Manager - - - Listener - - - Node - Transition Transition - - Tool - - - Tool - - - Geometry - - - Geometry - - - Geometry - - - Geometry - - - Manager - - - Listener - - - Listener - - - Listener - - - Listener - - - Listener - - - Listener - - - Listener - - - Listener - - - Common - - - Common - - - Common - - - Listener - - - Node - - - Node - - - Common - - - Win - Transition - - Msg + + Base - - Msg - - - Msg - - + Common + + Action + + + Action + + + Action + + + Action + + + Action + + + Action + + + Action + + + Action + + + Action + + + Action + + + Action + + + Action + + + Action + + + Action + + + Action + + + Action + + + Action + + + Common + + + Common + + + Common + + + Common + + + Common + + + Event + + + Geometry + + + Geometry + + + Geometry + + + Geometry + + + Listener + + + Listener + + + Listener + + + Manager + + + Manager + + + Manager + + + Manager + + + Node + + + Node + + + Node + + + Node + + + Node + + + Node + + + Tool + + + Tool + + + Base + + + Base + + + Manager + + + Base + + + Base + + + Tool + + + Tool + + + Tool + - - Win - @@ -238,8 +214,5 @@ - - Win - \ No newline at end of file