diff --git a/Easy2D/Action/Action.cpp b/Easy2D/Action/Action.cpp index 81f1b4ac..1d3de0cb 100644 --- a/Easy2D/Action/Action.cpp +++ b/Easy2D/Action/Action.cpp @@ -3,7 +3,8 @@ Action::Action() : m_bRunning(true), - m_bStop(false), + m_bWaiting(false), + m_bEnding(false), m_pTargetSprite(nullptr), m_pParentScene(nullptr) { @@ -17,7 +18,12 @@ Action::~Action() bool Action::isRunning() { - return m_bRunning; + return m_bRunning && !m_bWaiting; +} + +bool Action::isEnding() +{ + return m_bEnding; } void Action::start() @@ -37,7 +43,16 @@ void Action::pause() void Action::stop() { - m_bStop = true; + m_bEnding = true; +} +void Action::wait() +{ + m_bWaiting = true; +} + +void Action::notify() +{ + m_bWaiting = false; } void Action::setInterval(UINT ms) @@ -55,3 +70,8 @@ Action * Action::reverse() const assert(0); return nullptr; } + +void Action::_reset() +{ + m_bEnding = false; +} diff --git a/Easy2D/Action/ActionCallback.cpp b/Easy2D/Action/ActionCallback.cpp index ddd45803..fc6f8373 100644 --- a/Easy2D/Action/ActionCallback.cpp +++ b/Easy2D/Action/ActionCallback.cpp @@ -18,15 +18,13 @@ void ActionCallback::_init() { } -bool ActionCallback::_exec(LARGE_INTEGER nNow) +void ActionCallback::_exec(LARGE_INTEGER nNow) { - if (!m_bStop) - { - m_Callback(); - } - return true; + m_Callback(); + this->stop(); } void ActionCallback::_reset() { + Action::_reset(); } diff --git a/Easy2D/Action/ActionDelay.cpp b/Easy2D/Action/ActionDelay.cpp index 219af36b..70f63746 100644 --- a/Easy2D/Action/ActionDelay.cpp +++ b/Easy2D/Action/ActionDelay.cpp @@ -20,21 +20,18 @@ void ActionDelay::_init() QueryPerformanceCounter(&m_nLast); } -bool ActionDelay::_exec(LARGE_INTEGER nNow) +void ActionDelay::_exec(LARGE_INTEGER nNow) { - if (m_bStop) return true; - if (!m_bRunning) return false; - // 判断时间间隔是否足够 if (nNow.QuadPart - m_nLast.QuadPart > m_nAnimationInterval.QuadPart) { - return true; + this->stop(); } - return false; } void ActionDelay::_reset() { + Action::_reset(); // 重新记录当前时间 QueryPerformanceCounter(&m_nLast); } diff --git a/Easy2D/Action/ActionFrames.cpp b/Easy2D/Action/ActionFrames.cpp index 5b2a561f..87653f70 100644 --- a/Easy2D/Action/ActionFrames.cpp +++ b/Easy2D/Action/ActionFrames.cpp @@ -27,11 +27,8 @@ void ActionFrames::_init() QueryPerformanceCounter(&m_nLast); } -bool ActionFrames::_exec(LARGE_INTEGER nNow) +void ActionFrames::_exec(LARGE_INTEGER nNow) { - if (m_bStop) return true; - if (!m_bRunning) return false; - // 判断时间间隔是否足够 while (nNow.QuadPart - m_nLast.QuadPart > m_nAnimationInterval.QuadPart) { @@ -42,14 +39,14 @@ bool ActionFrames::_exec(LARGE_INTEGER nNow) // 判断动作是否结束 if (m_nFrameIndex == m_vFrames.size()) { - return true; + this->stop(); } } - return false; } void ActionFrames::_reset() { + Action::_reset(); m_nFrameIndex = 0; } diff --git a/Easy2D/Action/ActionMoveBy.cpp b/Easy2D/Action/ActionMoveBy.cpp index 3231d8de..dc48f1b8 100644 --- a/Easy2D/Action/ActionMoveBy.cpp +++ b/Easy2D/Action/ActionMoveBy.cpp @@ -16,12 +16,9 @@ void ActionMoveBy::_init() m_BeginPos = m_pTargetSprite->getPos(); } -bool ActionMoveBy::_exec(LARGE_INTEGER nNow) +void ActionMoveBy::_exec(LARGE_INTEGER nNow) { - if (m_bStop) return true; - if (!m_bRunning) return false; - - while (Animation::_exec(nNow)) + if (Animation::_isDelayEnough(nNow)) { // 计算移动位置 float scale = float(m_nDuration) / m_nTotalDuration; @@ -31,10 +28,9 @@ bool ActionMoveBy::_exec(LARGE_INTEGER nNow) // 判断动作是否结束 if (_isEnd()) { - return true; + this->stop(); } } - return false; } void ActionMoveBy::_reset() diff --git a/Easy2D/Action/ActionNeverStop.cpp b/Easy2D/Action/ActionNeverStop.cpp index b42fd5ba..6da217c1 100644 --- a/Easy2D/Action/ActionNeverStop.cpp +++ b/Easy2D/Action/ActionNeverStop.cpp @@ -22,20 +22,17 @@ void ActionNeverStop::_init() m_Action->_init(); } -bool ActionNeverStop::_exec(LARGE_INTEGER nNow) +void ActionNeverStop::_exec(LARGE_INTEGER nNow) { - if (m_bStop) return true; - if (!m_bRunning) return false; + m_Action->_exec(nNow); - if (m_Action->_exec(nNow)) + if (m_Action->isEnding()) { m_Action->_reset(); } - // 永不结束 - return false; } void ActionNeverStop::_reset() { - m_Action->_reset(); + Action::_reset(); } diff --git a/Easy2D/Action/ActionOpacityBy.cpp b/Easy2D/Action/ActionOpacityBy.cpp index 47c4a83c..216cfe80 100644 --- a/Easy2D/Action/ActionOpacityBy.cpp +++ b/Easy2D/Action/ActionOpacityBy.cpp @@ -16,12 +16,9 @@ void ActionOpacityBy::_init() m_nBeginVal = m_pTargetSprite->getOpacity(); } -bool ActionOpacityBy::_exec(LARGE_INTEGER nNow) +void ActionOpacityBy::_exec(LARGE_INTEGER nNow) { - if (m_bStop) return true; - if (!m_bRunning) return false; - - while (Animation::_exec(nNow)) + if (Animation::_isDelayEnough(nNow)) { // 计算移动位置 float scale = float(m_nDuration) / m_nTotalDuration; @@ -30,10 +27,9 @@ bool ActionOpacityBy::_exec(LARGE_INTEGER nNow) // 判断动作是否结束 if (_isEnd()) { - return true; + this->stop(); } } - return false; } void ActionOpacityBy::_reset() diff --git a/Easy2D/Action/ActionScaleBy.cpp b/Easy2D/Action/ActionScaleBy.cpp index d02338dd..18a4b380 100644 --- a/Easy2D/Action/ActionScaleBy.cpp +++ b/Easy2D/Action/ActionScaleBy.cpp @@ -18,12 +18,9 @@ void ActionScaleBy::_init() m_nBeginScaleY = m_pTargetSprite->getScaleY(); } -bool ActionScaleBy::_exec(LARGE_INTEGER nNow) +void ActionScaleBy::_exec(LARGE_INTEGER nNow) { - if (m_bStop) return true; - if (!m_bRunning) return false; - - while (Animation::_exec(nNow)) + if (Animation::_isDelayEnough(nNow)) { // 计算移动位置 float scale = float(m_nDuration) / m_nTotalDuration; @@ -32,10 +29,9 @@ bool ActionScaleBy::_exec(LARGE_INTEGER nNow) // 判断动作是否结束 if (_isEnd()) { - return true; + this->stop(); } } - return false; } void ActionScaleBy::_reset() diff --git a/Easy2D/Action/ActionSequence.cpp b/Easy2D/Action/ActionSequence.cpp index 86169530..71fe65c3 100644 --- a/Easy2D/Action/ActionSequence.cpp +++ b/Easy2D/Action/ActionSequence.cpp @@ -38,28 +38,27 @@ void ActionSequence::_init() m_vActions[0]->_init(); } -bool ActionSequence::_exec(LARGE_INTEGER nNow) +void ActionSequence::_exec(LARGE_INTEGER nNow) { - if (m_bStop) return true; - if (!m_bRunning) return false; + m_vActions[m_nActionIndex]->_exec(nNow); - if (m_vActions[m_nActionIndex]->_exec(nNow)) + if (m_vActions[m_nActionIndex]->isEnding()) { m_nActionIndex++; if (m_nActionIndex == m_vActions.size()) { - return true; + this->stop(); } else { m_vActions[m_nActionIndex]->_init(); } } - return false; } void ActionSequence::_reset() { + Action::_reset(); for (auto action : m_vActions) { action->_reset(); diff --git a/Easy2D/Action/ActionTwo.cpp b/Easy2D/Action/ActionTwo.cpp index 863e77e0..5472aaae 100644 --- a/Easy2D/Action/ActionTwo.cpp +++ b/Easy2D/Action/ActionTwo.cpp @@ -2,8 +2,7 @@ ActionTwo::ActionTwo(Action * actionFirst, Action * actionSecond) : m_FirstAction(actionFirst), - m_SecondAction(actionSecond), - m_bFirstFinished(false) + m_SecondAction(actionSecond) { m_FirstAction->retain(); m_SecondAction->retain(); @@ -40,32 +39,33 @@ void ActionTwo::_init() m_FirstAction->_init(); } -bool ActionTwo::_exec(LARGE_INTEGER nNow) +void ActionTwo::_exec(LARGE_INTEGER nNow) { - if (m_bStop) return true; - if (!m_bRunning) return false; - - if (!m_bFirstFinished) + if (!m_FirstAction->isEnding()) { - if (m_FirstAction->_exec(nNow)) + m_FirstAction->_exec(nNow); + if (m_FirstAction->isEnding()) { // 返回 true 表示第一个动作已经结束 m_SecondAction->_init(); - m_bFirstFinished = true; } } - else if (m_SecondAction->_exec(nNow)) + else if (!m_SecondAction->isEnding()) { - return true; + m_SecondAction->_exec(nNow); + } + else + { + this->stop(); } - return false; } void ActionTwo::_reset() { + Action::_reset(); + m_FirstAction->_reset(); m_SecondAction->_reset(); m_FirstAction->_init(); - m_bFirstFinished = false; } diff --git a/Easy2D/Action/Animation.cpp b/Easy2D/Action/Animation.cpp index cea441e0..69c01e48 100644 --- a/Easy2D/Action/Animation.cpp +++ b/Easy2D/Action/Animation.cpp @@ -21,7 +21,7 @@ void Animation::_init() QueryPerformanceCounter(&m_nLast); } -bool Animation::_exec(LARGE_INTEGER nNow) +bool Animation::_isDelayEnough(LARGE_INTEGER nNow) { // 判断时间间隔是否足够 if (nNow.QuadPart - m_nLast.QuadPart > m_nAnimationInterval.QuadPart) @@ -36,6 +36,7 @@ bool Animation::_exec(LARGE_INTEGER nNow) void Animation::_reset() { + Action::_reset(); m_nDuration = 0; // 重新记录当前时间 QueryPerformanceCounter(&m_nLast); diff --git a/Easy2D/Base/App.cpp b/Easy2D/Base/App.cpp index 197c1eb6..f208ac8f 100644 --- a/Easy2D/Base/App.cpp +++ b/Easy2D/Base/App.cpp @@ -16,6 +16,7 @@ static int originY = 0; App::App() : m_pCurrentScene(nullptr), m_pNextScene(nullptr), + m_pLoadingScene(nullptr), m_bRunning(false), m_nWindowMode(0), m_bSaveScene(true) @@ -302,10 +303,10 @@ void App::_enterNextScene() // 若要保存当前场景,把它放入栈中 m_SceneStack.push(m_pCurrentScene); // 暂停当前场景上运行的所有定时器 - Timer::stopAllSceneTimers(m_pCurrentScene); - MouseMsg::stopAllSceneListeners(m_pCurrentScene); - KeyMsg::stopAllSceneListeners(m_pCurrentScene); - ActionManager::pauseAllSceneActions(m_pCurrentScene); + Timer::waitAllSceneTimers(m_pCurrentScene); + MouseMsg::waitAllSceneListeners(m_pCurrentScene); + KeyMsg::waitAllSceneListeners(m_pCurrentScene); + ActionManager::waitAllSceneActions(m_pCurrentScene); } else { @@ -324,10 +325,10 @@ void App::_enterNextScene() if (bBackScene) { // 返回上一场景时,恢复场景上的定时器 - Timer::startAllSceneTimers(m_pCurrentScene); - MouseMsg::startAllSceneListeners(m_pCurrentScene); - KeyMsg::startAllSceneListeners(m_pCurrentScene); - ActionManager::startAllSceneActions(m_pCurrentScene); + Timer::notifyAllSceneTimers(m_pCurrentScene); + MouseMsg::notifyAllSceneListeners(m_pCurrentScene); + KeyMsg::notifyAllSceneListeners(m_pCurrentScene); + ActionManager::notifyAllSceneActions(m_pCurrentScene); } else { @@ -358,14 +359,12 @@ void App::reset() Scene * App::getCurrentScene() { // 获取当前场景的指针 - if (s_pInstance->m_pCurrentScene) - { - return s_pInstance->m_pCurrentScene; - } - else - { - return s_pInstance->m_pNextScene; - } + return s_pInstance->m_pCurrentScene; +} + +Scene * App::getLoadingScene() +{ + return s_pInstance->m_pLoadingScene; } void App::setFPS(DWORD fps) diff --git a/Easy2D/Base/Scene.cpp b/Easy2D/Base/Scene.cpp index f16b175b..da816e06 100644 --- a/Easy2D/Base/Scene.cpp +++ b/Easy2D/Base/Scene.cpp @@ -3,6 +3,7 @@ Scene::Scene() { + App::get()->m_pLoadingScene = this; } Scene::~Scene() diff --git a/Easy2D/Msg/KeyMsg.cpp b/Easy2D/Msg/KeyMsg.cpp index 9a8f1db6..f21b55e1 100644 --- a/Easy2D/Msg/KeyMsg.cpp +++ b/Easy2D/Msg/KeyMsg.cpp @@ -84,7 +84,8 @@ KeyMsg::KeyMsg(TString name, const KEY_CALLBACK & callback) : m_sName(name), m_callback(callback), m_pParentScene(nullptr), - m_bRunning(true) + m_bRunning(true), + m_bWaiting(false) { } @@ -107,6 +108,16 @@ void KeyMsg::stop() m_bRunning = false; } +void KeyMsg::wait() +{ + m_bWaiting = true; +} + +void KeyMsg::notify() +{ + m_bWaiting = false; +} + void KeyMsg::__exec() { if (_kbhit()) // 检测有无按键消息 @@ -115,7 +126,7 @@ void KeyMsg::__exec() for (auto l : s_vListeners) // 分发该消息 { - if (l->m_bRunning) + if (!l->m_bWaiting && l->m_bRunning) { l->onKbHit(key); // 执行按键回调函数 } @@ -128,7 +139,7 @@ void KeyMsg::addListener(TString name, const KEY_CALLBACK & callback) // 创建新的监听对象 auto listener = new KeyMsg(name, callback); // 绑定在场景上 - listener->m_pParentScene = App::getCurrentScene(); + listener->m_pParentScene = App::getLoadingScene(); // 添加新的按键回调函数 s_vListeners.push_back(listener); } @@ -138,7 +149,7 @@ void KeyMsg::startListener(TString name) // 查找名称相同的监听器 for (auto l : s_vListeners) { - if (l->m_sName == name && l->m_pParentScene == App::getCurrentScene()) + if (l->m_sName == name) { l->start(); } @@ -150,7 +161,7 @@ void KeyMsg::stopListener(TString name) // 查找名称相同的监听器 for (auto l : s_vListeners) { - if (l->m_sName == name && l->m_pParentScene == App::getCurrentScene()) + if (l->m_sName == name) { l->stop(); } @@ -165,7 +176,7 @@ void KeyMsg::delListener(TString name) for (iter = s_vListeners.begin(); iter != s_vListeners.end();) { // 查找相同名称的监听器 - if ((*iter)->m_sName == name && (*iter)->m_pParentScene == App::getCurrentScene()) + if ((*iter)->m_sName == name) { // 删除该定时器 delete (*iter); @@ -178,24 +189,24 @@ void KeyMsg::delListener(TString name) } } -void KeyMsg::startAllSceneListeners(Scene * scene) +void KeyMsg::notifyAllSceneListeners(Scene * scene) { for (auto l : s_vListeners) { if (l->m_pParentScene == scene) { - l->start(); + l->notify(); } } } -void KeyMsg::stopAllSceneListeners(Scene * scene) +void KeyMsg::waitAllSceneListeners(Scene * scene) { for (auto l : s_vListeners) { if (l->m_pParentScene == scene) { - l->stop(); + l->wait(); } } } diff --git a/Easy2D/Msg/MouseMsg.cpp b/Easy2D/Msg/MouseMsg.cpp index 14b5d693..58caf147 100644 --- a/Easy2D/Msg/MouseMsg.cpp +++ b/Easy2D/Msg/MouseMsg.cpp @@ -19,7 +19,7 @@ void MouseMsg::__exec() // 执行鼠标监听回调函数 for (auto l : s_vListeners) // 循环遍历所有的鼠标监听 { - if (l->m_bRunning) + if (!l->m_bWaiting && l->m_bRunning) { l->onMouseMsg(); // 执行回调函数 } @@ -30,7 +30,8 @@ void MouseMsg::__exec() MouseMsg::MouseMsg() : m_callback([]() {}), m_pParentScene(nullptr), - m_bRunning(true) + m_bRunning(true), + m_bWaiting(false) { } @@ -38,7 +39,8 @@ MouseMsg::MouseMsg(TString name, const MOUSE_CALLBACK & callback) : m_sName(name), m_callback(callback), m_pParentScene(nullptr), - m_bRunning(true) + m_bRunning(true), + m_bWaiting(false) { } @@ -56,7 +58,7 @@ void MouseMsg::addListener(TString name, const MOUSE_CALLBACK & callback) // 创建新的监听对象 auto listener = new MouseMsg(name, callback); // 绑定在场景上 - listener->m_pParentScene = App::getCurrentScene(); + listener->m_pParentScene = App::getLoadingScene(); // 添加新的按键回调函数 s_vListeners.push_back(listener); } @@ -66,7 +68,7 @@ void MouseMsg::startListener(TString name) // 查找名称相同的监听器 for (auto l : s_vListeners) { - if (l->m_sName == name && l->m_pParentScene == App::getCurrentScene()) + if (l->m_sName == name) { l->start(); } @@ -78,7 +80,7 @@ void MouseMsg::stopListener(TString name) // 查找名称相同的监听器 for (auto l : s_vListeners) { - if (l->m_sName == name && l->m_pParentScene == App::getCurrentScene()) + if (l->m_sName == name) { l->stop(); } @@ -93,7 +95,7 @@ void MouseMsg::delListener(TString name) for (iter = s_vListeners.begin(); iter != s_vListeners.end();) { // 查找相同名称的监听器 - if ((*iter)->m_sName == name && (*iter)->m_pParentScene == App::getCurrentScene()) + if ((*iter)->m_sName == name) { // 删除该定时器 delete (*iter); @@ -116,6 +118,16 @@ void MouseMsg::stop() m_bRunning = false; } +void MouseMsg::wait() +{ + m_bWaiting = true; +} + +void MouseMsg::notify() +{ + m_bWaiting = false; +} + void MouseMsg::clearAllListeners() { // 删除所有监听器 @@ -127,24 +139,24 @@ void MouseMsg::clearAllListeners() s_vListeners.clear(); } -void MouseMsg::startAllSceneListeners(Scene * scene) +void MouseMsg::notifyAllSceneListeners(Scene * scene) { for (auto l : s_vListeners) { if (l->m_pParentScene == scene) { - l->start(); + l->notify(); } } } -void MouseMsg::stopAllSceneListeners(Scene * scene) +void MouseMsg::waitAllSceneListeners(Scene * scene) { for (auto l : s_vListeners) { if (l->m_pParentScene == scene) { - l->stop(); + l->wait(); } } } diff --git a/Easy2D/Tool/ActionManager.cpp b/Easy2D/Tool/ActionManager.cpp index 7c2c015e..44b4e0cd 100644 --- a/Easy2D/Tool/ActionManager.cpp +++ b/Easy2D/Tool/ActionManager.cpp @@ -11,12 +11,18 @@ void ActionManager::__exec() // 循环遍历所有正在运行的动作 for (size_t i = 0; i < s_vActions.size(); i++) { - auto a = s_vActions[i]; - if (a->isRunning() && a->_exec(nNow)) + if (s_vActions[i]->isRunning()) { - // _exec 返回 true 时说明动作已经结束 - a->release(); - s_vActions.erase(s_vActions.begin() + i); + if (s_vActions[i]->isEnding()) + { + // 动作已经结束 + s_vActions[i]->release(); + s_vActions.erase(s_vActions.begin() + i); + } + else + { + s_vActions[i]->_exec(nNow); + } } } } @@ -31,30 +37,30 @@ void ActionManager::addAction(Action * action) assert(a != action); } #endif - action->m_pParentScene = App::getCurrentScene(); + action->m_pParentScene = App::getLoadingScene(); action->_init(); s_vActions.push_back(action); } } -void ActionManager::startAllSceneActions(Scene * scene) +void ActionManager::notifyAllSceneActions(Scene * scene) { for (auto action : s_vActions) { if (action->m_pParentScene == scene) { - action->start(); + action->notify(); } } } -void ActionManager::pauseAllSceneActions(Scene * scene) +void ActionManager::waitAllSceneActions(Scene * scene) { for (auto action : s_vActions) { if (action->m_pParentScene == scene) { - action->pause(); + action->wait(); } } } diff --git a/Easy2D/Tool/Timer.cpp b/Easy2D/Tool/Timer.cpp index f1d77df8..16ea3c60 100644 --- a/Easy2D/Tool/Timer.cpp +++ b/Easy2D/Tool/Timer.cpp @@ -6,6 +6,7 @@ static std::vector s_vTimers; Timer::Timer(TString name, UINT ms, const TIMER_CALLBACK & callback) : m_sName(name), m_bRunning(false), + m_bWaiting(false), m_callback(callback), m_pParentScene(nullptr) { @@ -19,19 +20,29 @@ Timer::~Timer() void Timer::start() { // 标志该定时器正在运行 - this->m_bRunning = true; + m_bRunning = true; // 记录当前时间 QueryPerformanceCounter(&m_nLast); } void Timer::stop() { - this->m_bRunning = false; // 标志该定时器已停止 + m_bRunning = false; // 标志该定时器已停止 +} + +void Timer::wait() +{ + m_bWaiting = true; +} + +void Timer::notify() +{ + m_bWaiting = false; } bool Timer::isRunning() { - return m_bRunning; // 获取该定时器的运行状态 + return m_bRunning && !m_bWaiting; // 获取该定时器的运行状态 } void Timer::setInterval(UINT ms) @@ -78,7 +89,7 @@ void Timer::__exec() for (auto timer : s_vTimers) { // 若定时器未运行,跳过这个定时器 - if (!timer->m_bRunning) + if (!timer->isRunning()) { continue; } @@ -98,7 +109,7 @@ void Timer::addTimer(Timer * timer) // 启动定时器 timer->start(); // 绑定在场景上 - timer->m_pParentScene = App::getCurrentScene(); + timer->m_pParentScene = App::getLoadingScene(); // 将该定时器放入容器 s_vTimers.push_back(timer); } @@ -169,24 +180,24 @@ void Timer::clearAllTimers() s_vTimers.clear(); } -void Timer::startAllSceneTimers(Scene * scene) +void Timer::notifyAllSceneTimers(Scene * scene) { for (auto t : s_vTimers) { if (t->m_pParentScene == scene) { - t->start(); + t->notify(); } } } -void Timer::stopAllSceneTimers(Scene * scene) +void Timer::waitAllSceneTimers(Scene * scene) { for (auto t : s_vTimers) { if (t->m_pParentScene == scene) { - t->stop(); + t->wait(); } } } diff --git a/Easy2D/easy2d.h b/Easy2D/easy2d.h index 4881df52..8df250d9 100644 --- a/Easy2D/easy2d.h +++ b/Easy2D/easy2d.h @@ -112,6 +112,7 @@ namespace easy2d class App { + friend Scene; public: App(); ~App(); @@ -176,12 +177,15 @@ public: static void reset(); // 获取当前场景 static Scene * getCurrentScene(); + // 获取正处于加载中的场景 + static Scene * getLoadingScene(); protected: TString m_sTitle; TString m_sAppName; Scene* m_pCurrentScene; Scene* m_pNextScene; + Scene* m_pLoadingScene; std::stack m_SceneStack; LARGE_INTEGER m_nAnimationInterval; CSize m_Size; @@ -283,6 +287,10 @@ public: void start(); // 停止监听 void stop(); + // 进入等待状态 + void wait(); + // 唤醒 + void notify(); // 左键是否按下 static bool isLButtonDown(); @@ -312,9 +320,9 @@ public: // 删除所有鼠标消息监听 static void clearAllListeners(); // 启动绑定在场景上的所有监听器 - static void startAllSceneListeners(Scene* scene); + static void notifyAllSceneListeners(Scene* scene); // 停止绑定在场景上的所有监听器 - static void stopAllSceneListeners(Scene* scene); + static void waitAllSceneListeners(Scene* scene); // 清除绑定在场景上的所有监听器 static void clearAllSceneListeners(Scene* scene); @@ -323,6 +331,7 @@ private: protected: bool m_bRunning; + bool m_bWaiting; TString m_sName; MOUSE_CALLBACK m_callback; Scene * m_pParentScene; @@ -345,6 +354,10 @@ public: void start(); // 停止监听 void stop(); + // 进入等待状态 + void wait(); + // 唤醒 + void notify(); // 判断键是否被按下,按下返回true static bool isKeyDown(VK_KEY key); @@ -357,9 +370,9 @@ public: // 删除按键监听 static void KeyMsg::delListener(TString name); // 启动绑定在场景上的所有监听器 - static void startAllSceneListeners(Scene* scene); + static void notifyAllSceneListeners(Scene* scene); // 停止绑定在场景上的所有监听器 - static void stopAllSceneListeners(Scene* scene); + static void waitAllSceneListeners(Scene* scene); // 停止绑定在场景上的所有定时器 static void clearAllSceneListeners(Scene* scene); // 删除所有按键监听 @@ -382,6 +395,7 @@ private: protected: bool m_bRunning; + bool m_bWaiting; TString m_sName; KEY_CALLBACK m_callback; Scene * m_pParentScene; @@ -1060,18 +1074,33 @@ public: Action(); virtual ~Action(); - bool isRunning(); - void start(); - void resume(); - void pause(); - void stop(); - void setInterval(UINT ms); + // 获取动作运行状态 + virtual bool isRunning(); + // 获取动作结束状态 + virtual bool isEnding(); + // 继续动作 + virtual void start(); + // 继续动作 + virtual void resume(); + // 暂停动作 + virtual void pause(); + // 停止动作 + virtual void stop(); + // 进入等待状态 + virtual void wait(); + // 唤醒 + virtual void notify(); + // 设置动作每一帧时间间隔 + virtual void setInterval(UINT ms); + // 获取一个新的拷贝动作 virtual Action * copy() const = 0; + // 获取一个新的逆向动作 virtual Action * reverse() const; protected: bool m_bRunning; - bool m_bStop; + bool m_bWaiting; + bool m_bEnding; Sprite * m_pTargetSprite; Scene * m_pParentScene; UINT m_nMilliSeconds; @@ -1080,8 +1109,8 @@ protected: protected: virtual void _init() = 0; - virtual bool _exec(LARGE_INTEGER nNow) = 0; - virtual void _reset() = 0; + virtual void _exec(LARGE_INTEGER nNow) = 0; + virtual void _reset(); }; class Animation : @@ -1097,8 +1126,8 @@ protected: protected: bool _isEnd() const; + bool _isDelayEnough(LARGE_INTEGER nNow); virtual void _init() override; - virtual bool _exec(LARGE_INTEGER nNow) override; virtual void _reset() override; }; @@ -1118,7 +1147,7 @@ protected: protected: virtual void _init() override; - virtual bool _exec(LARGE_INTEGER nNow) override; + virtual void _exec(LARGE_INTEGER nNow) override; virtual void _reset() override; }; @@ -1157,7 +1186,7 @@ protected: protected: virtual void _init() override; - virtual bool _exec(LARGE_INTEGER nNow) override; + virtual void _exec(LARGE_INTEGER nNow) override; virtual void _reset() override; }; @@ -1195,7 +1224,7 @@ protected: protected: virtual void _init() override; - virtual bool _exec(LARGE_INTEGER nNow) override; + virtual void _exec(LARGE_INTEGER nNow) override; virtual void _reset() override; }; @@ -1243,11 +1272,10 @@ public: protected: Action * m_FirstAction; Action * m_SecondAction; - bool m_bFirstFinished; protected: virtual void _init() override; - virtual bool _exec(LARGE_INTEGER nNow) override; + virtual void _exec(LARGE_INTEGER nNow) override; virtual void _reset() override; }; @@ -1269,7 +1297,7 @@ protected: protected: virtual void _init() override; - virtual bool _exec(LARGE_INTEGER nNow) override; + virtual void _exec(LARGE_INTEGER nNow) override; virtual void _reset() override; }; @@ -1284,7 +1312,7 @@ public: protected: virtual void _init() override; - virtual bool _exec(LARGE_INTEGER nNow) override; + virtual void _exec(LARGE_INTEGER nNow) override; virtual void _reset() override; }; @@ -1302,7 +1330,7 @@ protected: protected: virtual void _init() override; - virtual bool _exec(LARGE_INTEGER nNow) override; + virtual void _exec(LARGE_INTEGER nNow) override; virtual void _reset() override; }; @@ -1324,7 +1352,7 @@ protected: protected: virtual void _init() override; - virtual bool _exec(LARGE_INTEGER nNow) override; + virtual void _exec(LARGE_INTEGER nNow) override; virtual void _reset() override; }; @@ -1342,7 +1370,7 @@ protected: protected: virtual void _init() override; - virtual bool _exec(LARGE_INTEGER nNow) override; + virtual void _exec(LARGE_INTEGER nNow) override; virtual void _reset() override; }; @@ -1430,6 +1458,10 @@ public: void start(); // 停止定时器 void stop(); + // 进入等待状态 + void wait(); + // 唤醒 + void notify(); // 定时器是否正在运行 bool isRunning(); // 设置间隔时间 @@ -1457,14 +1489,15 @@ public: static void clearAllTimers(); // 继续绑定在场景上的所有定时器 - static void startAllSceneTimers(Scene* scene); + static void notifyAllSceneTimers(Scene* scene); // 停止绑定在场景上的所有定时器 - static void stopAllSceneTimers(Scene* scene); + static void waitAllSceneTimers(Scene* scene); // 清除绑定在场景上的所有定时器 static void clearAllSceneTimers(Scene* scene); protected: bool m_bRunning; + bool m_bWaiting; TString m_sName; TIMER_CALLBACK m_callback; LARGE_INTEGER m_nLast; @@ -1511,9 +1544,9 @@ public: static void clearAllActions(); // 继续绑定在场景上的动作 - static void startAllSceneActions(Scene* scene); + static void notifyAllSceneActions(Scene* scene); // 暂停绑定在场景上的动作 - static void pauseAllSceneActions(Scene* scene); + static void waitAllSceneActions(Scene* scene); // 停止绑定在场景上的动作 static void stopAllSceneActions(Scene* scene);