From a18ff4295d2842542ea8954cbc5f7c765479881d Mon Sep 17 00:00:00 2001 From: Nomango <569629550@qq.com> Date: Tue, 8 May 2018 11:37:11 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=86=E8=8A=82=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/Action/Action.cpp | 6 +- core/Action/ActionBase.cpp | 8 +-- core/Action/ActionFunc.cpp | 2 +- core/Action/ActionLoop.cpp | 2 +- core/Action/ActionSequence.cpp | 6 +- core/Action/ActionTwo.cpp | 10 +-- core/Action/Animation.cpp | 6 +- core/Common/Scene.cpp | 3 +- core/Manager/ActionManager.cpp | 4 +- core/Manager/ColliderManager.cpp | 42 ++++++------- core/Manager/InputManager.cpp | 42 ++++++------- core/Manager/SceneManager.cpp | 2 +- core/Node/Button.cpp | 10 +-- core/Node/ButtonToggle.cpp | 8 +-- core/Node/Menu.cpp | 2 +- core/Node/Node.cpp | 50 +-------------- core/Tool/Timer.cpp | 8 +-- core/Transition/TransitionBase.cpp | 2 +- core/e2daction.h | 45 +++++++++----- core/e2dcommon.h | 20 +----- core/e2dmanager.h | 4 +- core/e2dnode.h | 99 +++++++++++++----------------- core/e2dtool.h | 12 ++-- core/e2dtransition.h | 2 +- 24 files changed, 169 insertions(+), 226 deletions(-) diff --git a/core/Action/Action.cpp b/core/Action/Action.cpp index 85eca9d3..4e80bfc0 100644 --- a/core/Action/Action.cpp +++ b/core/Action/Action.cpp @@ -75,19 +75,19 @@ e2d::ActionLoop * e2d::Action::Loop(ActionBase * action, int times) return new (std::nothrow) ActionLoop(action, times); } -e2d::ActionFunc * e2d::Action::Func(Function func) +e2d::ActionFunc * e2d::Action::Func(const Function& func) { return new (std::nothrow) ActionFunc(func); } #ifdef HIGHER_THAN_VS2012 -e2d::ActionSequence * e2d::Action::Sequence(const InitList& vActions) +e2d::ActionSequence * e2d::Action::Sequence(const std::initializer_list& vActions) { return new (std::nothrow) ActionSequence(vActions); } -e2d::Animation * e2d::Action::Animation(double interval, const InitList& vFrames) +e2d::Animation * e2d::Action::Animation(double interval, const std::initializer_list& vFrames) { return new (std::nothrow) e2d::Animation(interval, vFrames); } diff --git a/core/Action/ActionBase.cpp b/core/Action/ActionBase.cpp index f4130116..b034d309 100644 --- a/core/Action/ActionBase.cpp +++ b/core/Action/ActionBase.cpp @@ -21,17 +21,17 @@ bool e2d::ActionBase::isRunning() return m_bRunning; } -bool e2d::ActionBase::_isEnding() +bool e2d::ActionBase::_isDone() { return m_bEnding; } -void e2d::ActionBase::setTarget(Node* pTarget) +void e2d::ActionBase::startWithTarget(Node* target) { - if (pTarget) + if (target) { m_bRunning = true; - m_pTarget = pTarget; + m_pTarget = target; this->reset(); } } diff --git a/core/Action/ActionFunc.cpp b/core/Action/ActionFunc.cpp index 91942a60..4bf391ae 100644 --- a/core/Action/ActionFunc.cpp +++ b/core/Action/ActionFunc.cpp @@ -1,6 +1,6 @@ #include "..\e2daction.h" -e2d::ActionFunc::ActionFunc(Function func) : +e2d::ActionFunc::ActionFunc(const Function& func) : m_Callback(func) { } diff --git a/core/Action/ActionLoop.cpp b/core/Action/ActionLoop.cpp index c87852c9..d2e768c3 100644 --- a/core/Action/ActionLoop.cpp +++ b/core/Action/ActionLoop.cpp @@ -38,7 +38,7 @@ void e2d::ActionLoop::_update() m_pAction->_update(); - if (m_pAction->_isEnding()) + if (m_pAction->_isDone()) { m_nTimes++; diff --git a/core/Action/ActionSequence.cpp b/core/Action/ActionSequence.cpp index 1b00d192..857f02a0 100644 --- a/core/Action/ActionSequence.cpp +++ b/core/Action/ActionSequence.cpp @@ -6,7 +6,7 @@ e2d::ActionSequence::ActionSequence() } #ifdef HIGHER_THAN_VS2012 -e2d::ActionSequence::ActionSequence(const InitList& vActions) +e2d::ActionSequence::ActionSequence(const std::initializer_list& vActions) : m_nActionIndex(0) { this->add(vActions); @@ -62,7 +62,7 @@ void e2d::ActionSequence::_update() auto &action = m_vActions[m_nActionIndex]; action->_update(); - if (action->_isEnding()) + if (action->_isDone()) { m_nActionIndex++; if (m_nActionIndex == m_vActions.size()) @@ -104,7 +104,7 @@ void e2d::ActionSequence::add(ActionBase * action) } #ifdef HIGHER_THAN_VS2012 -void e2d::ActionSequence::add(const InitList& vActions) +void e2d::ActionSequence::add(const std::initializer_list& vActions) { for (const auto &action : vActions) { diff --git a/core/Action/ActionTwo.cpp b/core/Action/ActionTwo.cpp index 99e6f457..a9b0b33a 100644 --- a/core/Action/ActionTwo.cpp +++ b/core/Action/ActionTwo.cpp @@ -45,11 +45,11 @@ void e2d::ActionTwo::_update() { ActionBase::_update(); - if (!m_pFirstAction->_isEnding()) + if (!m_pFirstAction->_isDone()) { m_pFirstAction->_update(); - if (!m_bAtSameTime && m_pFirstAction->_isEnding()) + if (!m_bAtSameTime && m_pFirstAction->_isDone()) { m_pSecondAction->_init(); } @@ -57,17 +57,17 @@ void e2d::ActionTwo::_update() if (m_bAtSameTime) { - if (!m_pSecondAction->_isEnding()) + if (!m_pSecondAction->_isDone()) { m_pSecondAction->_update(); } } - else if (m_pFirstAction->_isEnding()) + else if (m_pFirstAction->_isDone()) { m_pSecondAction->_update(); } - if (m_pFirstAction->_isEnding() && m_pSecondAction->_isEnding()) + if (m_pFirstAction->_isDone() && m_pSecondAction->_isDone()) { this->stop(); } diff --git a/core/Action/Animation.cpp b/core/Action/Animation.cpp index 6299ae2b..a5b1dbc8 100644 --- a/core/Action/Animation.cpp +++ b/core/Action/Animation.cpp @@ -14,14 +14,14 @@ e2d::Animation::Animation(double interval) #ifdef HIGHER_THAN_VS2012 -e2d::Animation::Animation(const InitList& vImages) +e2d::Animation::Animation(const std::initializer_list& vImages) : m_nFrameIndex(0) , m_fInterval(1) { this->add(vImages); } -e2d::Animation::Animation(double interval, const InitList& vImages) +e2d::Animation::Animation(double interval, const std::initializer_list& vImages) : m_nFrameIndex(0) , m_fInterval(interval) { @@ -128,7 +128,7 @@ void e2d::Animation::add(Image * frame) } #ifdef HIGHER_THAN_VS2012 -void e2d::Animation::add(const InitList& vImages) +void e2d::Animation::add(const std::initializer_list& vImages) { for (const auto &image : vImages) { diff --git a/core/Common/Scene.cpp b/core/Common/Scene.cpp index 87dc580b..8f55e223 100644 --- a/core/Common/Scene.cpp +++ b/core/Common/Scene.cpp @@ -10,7 +10,6 @@ e2d::Scene::Scene() , m_pRoot(new Node()) { m_pRoot->retain(); - m_pRoot->_onEnter(); m_pRoot->_setParentScene(this); } @@ -53,7 +52,7 @@ void e2d::Scene::add(Node * child, int order /* = 0 */) } #ifdef HIGHER_THAN_VS2012 -void e2d::Scene::add(const InitList& vNodes, int order) +void e2d::Scene::add(const std::initializer_list& vNodes, int order) { for (const auto &node : vNodes) { diff --git a/core/Manager/ActionManager.cpp b/core/Manager/ActionManager.cpp index 1741343d..121f964b 100644 --- a/core/Manager/ActionManager.cpp +++ b/core/Manager/ActionManager.cpp @@ -15,7 +15,7 @@ void e2d::ActionManager::__update() { auto action = s_vRunningActions[i]; // 获取动作运行状态 - if (action->_isEnding()) + if (action->_isDone()) { // 动作已经结束 action->release(); @@ -66,7 +66,7 @@ void e2d::ActionManager::__startAction(ActionBase * pAction, Node * pTargetNode) if (pAction) { - pAction->setTarget(pTargetNode); + pAction->startWithTarget(pTargetNode); pAction->retain(); s_vRunningActions.push_back(pAction); } diff --git a/core/Manager/ColliderManager.cpp b/core/Manager/ColliderManager.cpp index 2fef31e3..667d2800 100644 --- a/core/Manager/ColliderManager.cpp +++ b/core/Manager/ColliderManager.cpp @@ -8,7 +8,7 @@ class Listener { public: Listener( - e2d::Function func, + const e2d::Function& func, const e2d::String& name, bool paused ) @@ -59,17 +59,17 @@ void e2d::ColliderManager::__update() for (size_t i = 0; i < s_vListeners.size(); i++) { - auto pListener = s_vListeners[i]; + auto listener = s_vListeners[i]; // 清除已停止的监听器 - if (pListener->stopped) + if (listener->stopped) { - delete pListener; + delete listener; s_vListeners.erase(s_vListeners.begin() + i); } else { // 更新监听器 - pListener->update(); + listener->update(); ++i; } } @@ -133,7 +133,7 @@ void e2d::ColliderManager::__updateCollider(e2d::Collider * pActiveCollider) s_pPassiveNode = nullptr; } -void e2d::ColliderManager::add(Function func, const String& name, bool paused) +void e2d::ColliderManager::add(const Function& func, const String& name, bool paused) { auto listener = new Listener(func, name, paused); s_vListeners.push_back(listener); @@ -141,58 +141,58 @@ void e2d::ColliderManager::add(Function func, const String& name, bool paused) void e2d::ColliderManager::pause(const String& name) { - for (auto pListener : s_vListeners) + for (auto listener : s_vListeners) { - if (pListener->name == name) + if (listener->name == name) { - pListener->running = false; + listener->running = false; } } } void e2d::ColliderManager::resume(const String& name) { - for (auto pListener : s_vListeners) + for (auto listener : s_vListeners) { - if (pListener->name == name) + if (listener->name == name) { - pListener->running = true; + listener->running = true; } } } void e2d::ColliderManager::stop(const String& name) { - for (auto pListener : s_vListeners) + for (auto listener : s_vListeners) { - if (pListener->name == name) + if (listener->name == name) { - pListener->stopped = true; + listener->stopped = true; } } } void e2d::ColliderManager::pauseAll() { - for (auto pListener : s_vListeners) + for (auto listener : s_vListeners) { - pListener->running = false; + listener->running = false; } } void e2d::ColliderManager::resumeAll() { - for (auto pListener : s_vListeners) + for (auto listener : s_vListeners) { - pListener->running = true; + listener->running = true; } } void e2d::ColliderManager::stopAll() { - for (auto pListener : s_vListeners) + for (auto listener : s_vListeners) { - pListener->stopped = true; + listener->stopped = true; } } diff --git a/core/Manager/InputManager.cpp b/core/Manager/InputManager.cpp index 460d3299..79f35af1 100644 --- a/core/Manager/InputManager.cpp +++ b/core/Manager/InputManager.cpp @@ -6,7 +6,7 @@ class Listener { public: Listener( - e2d::Function func, + const e2d::Function& func, const e2d::String& name, bool paused ) @@ -37,7 +37,7 @@ public: static std::vector s_vListeners; -void e2d::InputManager::add(Function func, const String& name, bool paused) +void e2d::InputManager::add(const Function& func, const String& name, bool paused) { auto listener = new Listener(func, name, paused); s_vListeners.push_back(listener); @@ -45,58 +45,58 @@ void e2d::InputManager::add(Function func, const String& name, bool paused) void e2d::InputManager::pause(const String& name) { - for (auto pListener : s_vListeners) + for (auto listener : s_vListeners) { - if (pListener->name == name) + if (listener->name == name) { - pListener->running = false; + listener->running = false; } } } void e2d::InputManager::resume(const String& name) { - for (auto pListener : s_vListeners) + for (auto listener : s_vListeners) { - if (pListener->name == name) + if (listener->name == name) { - pListener->running = true; + listener->running = true; } } } void e2d::InputManager::stop(const String& name) { - for (auto pListener : s_vListeners) + for (auto listener : s_vListeners) { - if (pListener->name == name) + if (listener->name == name) { - pListener->stopped = true; + listener->stopped = true; } } } void e2d::InputManager::pauseAll() { - for (auto pListener : s_vListeners) + for (auto listener : s_vListeners) { - pListener->running = false; + listener->running = false; } } void e2d::InputManager::resumeAll() { - for (auto pListener : s_vListeners) + for (auto listener : s_vListeners) { - pListener->running = true; + listener->running = true; } } void e2d::InputManager::stopAll() { - for (auto pListener : s_vListeners) + for (auto listener : s_vListeners) { - pListener->stopped = true; + listener->stopped = true; } } @@ -107,17 +107,17 @@ void e2d::InputManager::__update() for (size_t i = 0; i < s_vListeners.size(); i++) { - auto pListener = s_vListeners[i]; + auto listener = s_vListeners[i]; // 清除已停止的监听器 - if (pListener->stopped) + if (listener->stopped) { - delete pListener; + delete listener; s_vListeners.erase(s_vListeners.begin() + i); } else { // 更新监听器 - pListener->update(); + listener->update(); ++i; } } diff --git a/core/Manager/SceneManager.cpp b/core/Manager/SceneManager.cpp index 07dc74ec..dba8ea67 100644 --- a/core/Manager/SceneManager.cpp +++ b/core/Manager/SceneManager.cpp @@ -102,7 +102,7 @@ void e2d::SceneManager::__update() // 更新场景动画 s_pTransition->_update(); - if (s_pTransition->isEnding()) + if (s_pTransition->isDone()) { s_pTransition->release(); s_pTransition = nullptr; diff --git a/core/Node/Button.cpp b/core/Node/Button.cpp index 36738bfa..c564b7ee 100644 --- a/core/Node/Button.cpp +++ b/core/Node/Button.cpp @@ -16,7 +16,7 @@ e2d::Button::Button() { } -e2d::Button::Button(Node * normal, Function func) +e2d::Button::Button(Node * normal, const Function& func) : m_Callback(nullptr) , m_eBtnState(ButtonState::NORMAL) , m_bEnable(true) @@ -30,7 +30,7 @@ e2d::Button::Button(Node * normal, Function func) this->setClickFunc(func); } -e2d::Button::Button(Node * normal, Node * selected, Function func) +e2d::Button::Button(Node * normal, Node * selected, const Function& func) : m_Callback(nullptr) , m_eBtnState(ButtonState::NORMAL) , m_bEnable(true) @@ -45,7 +45,7 @@ e2d::Button::Button(Node * normal, Node * selected, Function func) this->setClickFunc(func); } -e2d::Button::Button(Node * normal, Node * mouseover, Node * selected, Function func) +e2d::Button::Button(Node * normal, Node * mouseover, Node * selected, const Function& func) : m_Callback(nullptr) , m_eBtnState(ButtonState::NORMAL) , m_bEnable(true) @@ -61,7 +61,7 @@ e2d::Button::Button(Node * normal, Node * mouseover, Node * selected, Function f this->setClickFunc(func); } -e2d::Button::Button(Node * normal, Node * mouseover, Node * selected, Node * disabled, Function func) +e2d::Button::Button(Node * normal, Node * mouseover, Node * selected, Node * disabled, const Function& func) : m_Callback(nullptr) , m_eBtnState(ButtonState::NORMAL) , m_bEnable(true) @@ -170,7 +170,7 @@ void e2d::Button::setEnable(bool enable) } } -void e2d::Button::setClickFunc(Function func) +void e2d::Button::setClickFunc(const Function& func) { WARN_IF(m_pNormal == nullptr, "Button cannot work without anything to show. Please set its normal displayed."); diff --git a/core/Node/ButtonToggle.cpp b/core/Node/ButtonToggle.cpp index 94d741ef..f18f3433 100644 --- a/core/Node/ButtonToggle.cpp +++ b/core/Node/ButtonToggle.cpp @@ -14,7 +14,7 @@ e2d::ButtonToggle::ButtonToggle() { } -e2d::ButtonToggle::ButtonToggle(Node * toggleOnNormal, Node * toggleOffNormal, Function func) +e2d::ButtonToggle::ButtonToggle(Node * toggleOnNormal, Node * toggleOffNormal, const Function& func) : Button() , m_bState(true) , m_pNormalOn(nullptr) @@ -31,7 +31,7 @@ e2d::ButtonToggle::ButtonToggle(Node * toggleOnNormal, Node * toggleOffNormal, F this->setClickFunc(func); } -e2d::ButtonToggle::ButtonToggle(Node * toggleOnNormal, Node * toggleOffNormal, Node * toggleOnSelected, Node * toggleOffSelected, Function func) +e2d::ButtonToggle::ButtonToggle(Node * toggleOnNormal, Node * toggleOffNormal, Node * toggleOnSelected, Node * toggleOffSelected, const Function& func) : Button() , m_bState(true) , m_pNormalOn(nullptr) @@ -50,7 +50,7 @@ e2d::ButtonToggle::ButtonToggle(Node * toggleOnNormal, Node * toggleOffNormal, N this->setClickFunc(func); } -e2d::ButtonToggle::ButtonToggle(Node * toggleOnNormal, Node * toggleOffNormal, Node * toggleOnMouseOver, Node * toggleOffMouseOver, Node * toggleOnSelected, Node * toggleOffSelected, Function func) +e2d::ButtonToggle::ButtonToggle(Node * toggleOnNormal, Node * toggleOffNormal, Node * toggleOnMouseOver, Node * toggleOffMouseOver, Node * toggleOnSelected, Node * toggleOffSelected, const Function& func) : Button() , m_bState(true) , m_pNormalOn(nullptr) @@ -71,7 +71,7 @@ e2d::ButtonToggle::ButtonToggle(Node * toggleOnNormal, Node * toggleOffNormal, N this->setClickFunc(func); } -e2d::ButtonToggle::ButtonToggle(Node * toggleOnNormal, Node * toggleOffNormal, Node * toggleOnMouseOver, Node * toggleOffMouseOver, Node * toggleOnSelected, Node * toggleOffSelected, Node * toggleOnDisabled, Node * toggleOffDisabled, Function func) +e2d::ButtonToggle::ButtonToggle(Node * toggleOnNormal, Node * toggleOffNormal, Node * toggleOnMouseOver, Node * toggleOffMouseOver, Node * toggleOnSelected, Node * toggleOffSelected, Node * toggleOnDisabled, Node * toggleOffDisabled, const Function& func) : Button() , m_bState(true) , m_pNormalOn(nullptr) diff --git a/core/Node/Menu.cpp b/core/Node/Menu.cpp index 448c4a6e..c255e133 100644 --- a/core/Node/Menu.cpp +++ b/core/Node/Menu.cpp @@ -6,7 +6,7 @@ e2d::Menu::Menu() } #ifdef HIGHER_THAN_VS2012 -e2d::Menu::Menu(const InitList& vButtons) +e2d::Menu::Menu(const std::initializer_list& vButtons) : m_bEnable(true) { for (auto button : vButtons) diff --git a/core/Node/Node.cpp b/core/Node/Node.cpp index b69a27c4..8899c0c6 100644 --- a/core/Node/Node.cpp +++ b/core/Node/Node.cpp @@ -27,7 +27,6 @@ e2d::Node::Node() , m_MatriInitial(D2D1::Matrix3x2F::Identity()) , m_MatriFinal(D2D1::Matrix3x2F::Identity()) , m_bVisiable(true) - , m_bDisplayedInScene(false) , m_pCollider(nullptr) , m_pParent(nullptr) , m_pParentScene(nullptr) @@ -174,34 +173,6 @@ void e2d::Node::_drawCollider() } } -void e2d::Node::_onEnter() -{ - if (!this->m_bDisplayedInScene) - { - this->m_bDisplayedInScene = true; - this->onEnter(); - - for (auto child : m_vChildren) - { - child->_onEnter(); - } - } -} - -void e2d::Node::_onExit() -{ - if (this->m_bDisplayedInScene) - { - this->m_bDisplayedInScene = false; - this->onExit(); - - for (auto child : m_vChildren) - { - child->_onExit(); - } - } -} - void e2d::Node::_updateSelfTransform() { // 计算中心点坐标 @@ -627,7 +598,7 @@ void e2d::Node::addColliableName(const String& collliderName) } #ifdef HIGHER_THAN_VS2012 -void e2d::Node::addColliableName(const InitList& vCollliderName) +void e2d::Node::addColliableName(const std::initializer_list& vCollliderName) { for (const auto &name : vCollliderName) { @@ -668,11 +639,6 @@ void e2d::Node::addChild(Node * child, int order /* = 0 */) child->_setParentScene(this->m_pParentScene); } - if (this->m_bDisplayedInScene) - { - child->_onEnter(); - } - // 更新子节点透明度 child->_updateOpacity(); // 更新节点转换 @@ -683,7 +649,7 @@ void e2d::Node::addChild(Node * child, int order /* = 0 */) } #ifdef HIGHER_THAN_VS2012 -void e2d::Node::addChild(const InitList& vNodes, int order) +void e2d::Node::addChild(const std::initializer_list& vNodes, int order) { for (const auto &node : vNodes) { @@ -774,10 +740,6 @@ bool e2d::Node::removeChild(Node * child) { child->_setParentScene(nullptr); } - if (child->m_bDisplayedInScene) - { - child->_onExit(); - } child->release(); return true; @@ -811,10 +773,6 @@ void e2d::Node::removeChildren(const String& childName) { child->_setParentScene(nullptr); } - if (child->m_bDisplayedInScene) - { - child->_onExit(); - } child->release(); } } @@ -825,10 +783,6 @@ void e2d::Node::clearAllChildren() // 所有节点的引用计数减一 for (auto child : m_vChildren) { - if (child->m_bDisplayedInScene) - { - child->_onExit(); - } child->release(); } // 清空储存节点的容器 diff --git a/core/Tool/Timer.cpp b/core/Tool/Timer.cpp index 59e3bf54..9e64a809 100644 --- a/core/Tool/Timer.cpp +++ b/core/Tool/Timer.cpp @@ -5,7 +5,7 @@ class TimerInfo { public: TimerInfo( - e2d::Function func, + const e2d::Function& func, const e2d::String& name, double delay, int updateTimes, @@ -65,18 +65,18 @@ public: static std::vector s_vTimers; -void e2d::Timer::start(Function func, double delay, int updateTimes, bool paused, const String& name) +void e2d::Timer::start(const Function& func, double delay, int updateTimes, bool paused, const String& name) { auto timer = new TimerInfo(func, name, delay, updateTimes, paused); s_vTimers.push_back(timer); } -void e2d::Timer::start(Function func, const String& name) +void e2d::Timer::start(const Function& func, const String& name) { Timer::start(func, 0, -1, false, name); } -void e2d::Timer::startOnce(Function func, double timeOut) +void e2d::Timer::startOnce(const Function& func, double timeOut) { auto timer = new TimerInfo(func, L"", timeOut, 1, false); s_vTimers.push_back(timer); diff --git a/core/Transition/TransitionBase.cpp b/core/Transition/TransitionBase.cpp index 5664657c..74e81fe6 100644 --- a/core/Transition/TransitionBase.cpp +++ b/core/Transition/TransitionBase.cpp @@ -22,7 +22,7 @@ e2d::TransitionBase::~TransitionBase() SafeReleaseInterface(&m_pNextLayer); } -bool e2d::TransitionBase::isEnding() +bool e2d::TransitionBase::isDone() { return m_bEnd; } diff --git a/core/e2daction.h b/core/e2daction.h index 34f7f61e..cfd94d8f 100644 --- a/core/e2daction.h +++ b/core/e2daction.h @@ -120,19 +120,19 @@ public: // 创建执行函数对象的动作 static e2d::ActionFunc* Func( - Function func /* 函数对象 */ + const Function& func /* 函数对象 */ ); #ifdef HIGHER_THAN_VS2012 // 创建顺序动作 static e2d::ActionSequence* Sequence( - const InitList& vActions /* 动作数组 */ + const std::initializer_list& vActions /* 动作列表 */ ); // 创建特定帧间隔的帧动画 static e2d::Animation* Animation( - double interval, /* 帧间隔(秒) */ - const InitList& vFrames /* 关键帧数组 */ + double interval, /* 帧间隔(秒) */ + const std::initializer_list& vFrames /* 关键帧列表 */ ); #else // 创建顺序动作 @@ -171,8 +171,8 @@ public: virtual bool isRunning(); // 开始动作 - virtual void setTarget( - Node* pTarget /* 执行该动作的目标 */ + virtual void startWithTarget( + Node* target /* 执行该动作的目标 */ ); // 继续动作 @@ -215,7 +215,7 @@ protected: virtual void _update(); // 获取动作结束状态 - virtual bool _isEnding(); + virtual bool _isDone(); // 重置动画时间 virtual void _resetTime(); @@ -231,6 +231,7 @@ protected: }; +// 持续动作 class ActionGradual : public ActionBase { @@ -253,6 +254,7 @@ protected: }; +// 相对位移动画 class ActionMoveBy : public ActionGradual { @@ -282,6 +284,7 @@ protected: }; +// 位移动画 class ActionMoveTo : public ActionMoveBy { @@ -304,6 +307,7 @@ protected: }; +// 相对缩放动画 class ActionScaleBy : public ActionGradual { @@ -342,6 +346,7 @@ protected: }; +// 缩放动画 class ActionScaleTo : public ActionScaleBy { @@ -372,6 +377,7 @@ protected: }; +// 透明度相对渐变动画 class ActionOpacityBy : public ActionGradual { @@ -401,6 +407,7 @@ protected: }; +// 透明度渐变动画 class ActionOpacityTo : public ActionOpacityBy { @@ -423,6 +430,7 @@ protected: }; +// 淡入动画 class ActionFadeIn : public ActionOpacityTo { @@ -434,6 +442,7 @@ public: }; +// 淡出动画 class ActionFadeOut : public ActionOpacityTo { @@ -445,6 +454,7 @@ public: }; +// 相对旋转动作 class ActionRotateBy : public ActionGradual { @@ -474,6 +484,7 @@ protected: }; +// 旋转动作 class ActionRotateTo : public ActionRotateBy { @@ -496,6 +507,7 @@ protected: }; +// 组合动作 class ActionTwo : public ActionBase { @@ -540,6 +552,7 @@ protected: }; +// 顺序动作 class ActionSequence : public ActionBase { @@ -550,7 +563,7 @@ public: #ifdef HIGHER_THAN_VS2012 // 创建顺序动作 ActionSequence( - const InitList& vActions /* 动作数组 */ + const std::initializer_list& vActions /* 动作列表 */ ); #else // 创建顺序动作 @@ -571,7 +584,7 @@ public: #ifdef HIGHER_THAN_VS2012 // 在结尾添加多个动作 void add( - const InitList& vActions /* 动作数组 */ + const std::initializer_list& vActions /* 动作列表 */ ); #else // 在结尾添加多个动作 @@ -612,6 +625,7 @@ protected: }; +// 延时动作 class ActionDelay : public ActionBase { @@ -636,6 +650,7 @@ protected: }; +// 循环动作 class ActionLoop : public ActionBase { @@ -674,6 +689,7 @@ protected: }; +// 帧动画 class Animation : public ActionBase { @@ -689,13 +705,13 @@ public: #ifdef HIGHER_THAN_VS2012 // 创建帧动画 Animation( - const InitList& vImages /* 关键帧数组 */ + const std::initializer_list& vImages /* 关键帧列表 */ ); // 创建特定帧间隔的帧动画 Animation( - double interval, /* 帧间隔(秒) */ - const InitList& vImages /* 关键帧数组 */ + double interval, /* 帧间隔(秒) */ + const std::initializer_list& vImages /* 关键帧列表 */ ); #else // 创建帧动画 @@ -724,7 +740,7 @@ public: #ifdef HIGHER_THAN_VS2012 // 添加多个关键帧 void add( - const InitList& vImages /* 关键帧数组 */ + const std::initializer_list& vImages /* 关键帧列表 */ ); #else // 添加多个关键帧 @@ -766,13 +782,14 @@ protected: }; +// 回调动作 class ActionFunc : public ActionBase { public: // 创建执行函数对象的动作 ActionFunc( - Function func /* 函数对象 */ + const Function& func /* 函数对象 */ ); // 获取该动作的拷贝对象 diff --git a/core/e2dcommon.h b/core/e2dcommon.h index 6cf0c909..748835ef 100644 --- a/core/e2dcommon.h +++ b/core/e2dcommon.h @@ -11,15 +11,6 @@ namespace e2d { -#ifdef HIGHER_THAN_VS2012 - -// 初始化列表 -template -using InitList = std::initializer_list; - -#endif - - struct Size; // 表示坐标的结构体 @@ -561,12 +552,7 @@ public: ); template - Function( - Func func - ) - : m_func(func) - { - } + Function(Func func) : m_func(func) {} template Function( @@ -771,8 +757,8 @@ public: #ifdef HIGHER_THAN_VS2012 // 添加多个节点到场景 virtual void add( - const InitList& vNodes, /* 节点数组 */ - int order = 0 /* 渲染顺序 */ + const std::initializer_list& vNodes, /* 节点列表 */ + int order = 0 /* 渲染顺序 */ ); #endif diff --git a/core/e2dmanager.h b/core/e2dmanager.h index 8904a9c9..eb0d6c17 100644 --- a/core/e2dmanager.h +++ b/core/e2dmanager.h @@ -182,7 +182,7 @@ class InputManager public: // 添加输入监听 static void add( - Function func, /* 监听到用户输入时的执行函数 */ + const Function& func, /* 监听到用户输入时的执行函数 */ const String& name = L"", /* 监听器名称 */ bool paused = false /* 是否暂停 */ ); @@ -235,7 +235,7 @@ public: // 添加碰撞监听 static void add( - Function func, /* 监听到碰撞时的执行函数 */ + const Function& func, /* 监听到碰撞时的执行函数 */ const String& name = L"", /* 监听器名称 */ bool paused = false /* 是否暂停 */ ); diff --git a/core/e2dnode.h b/core/e2dnode.h index d4f79da0..39c8bcaa 100644 --- a/core/e2dnode.h +++ b/core/e2dnode.h @@ -23,12 +23,6 @@ public: virtual ~Node(); - // 进入场景时执行 - virtual void onEnter() {} - - // 离开场景时执行 - virtual void onExit() {} - // 更新节点 virtual void onUpdate() {} @@ -347,7 +341,7 @@ public: #ifdef HIGHER_THAN_VS2012 // 添加多个可碰撞节点的名称 virtual void addColliableName( - const InitList& vCollliderName /* 名称数组 */ + const std::initializer_list& vCollliderName /* 名称列表 */ ); #endif @@ -365,8 +359,8 @@ public: #ifdef HIGHER_THAN_VS2012 // 添加多个子节点 virtual void addChild( - const InitList& vNodes, /* 节点数组 */ - int order = 0 /* 渲染顺序 */ + const std::initializer_list& vNodes, /* 节点列表 */ + int order = 0 /* 渲染顺序 */ ); #endif @@ -433,12 +427,6 @@ protected: // 渲染图形 void _drawCollider(); - // 节点被添加到场景时的执行程序 - void _onEnter(); - - // 节点从场景中消失时的执行程序 - void _onExit(); - // 设置节点所在场景 void _setParentScene( Scene * scene @@ -472,7 +460,6 @@ protected: int m_nOrder; bool m_bVisiable; bool m_bAutoUpdate; - bool m_bDisplayedInScene; bool m_bSortChildrenNeeded; bool m_bTransformNeeded; bool m_bPositionFixed; @@ -764,32 +751,32 @@ public: // 创建按钮 Button( - Node * normal, /* 普通状态 */ - Function func = nullptr /* 按钮点击后的执行函数 */ + Node * normal, /* 普通状态 */ + const Function& func = nullptr /* 按钮点击后的执行函数 */ ); // 创建按钮 Button( - Node * normal, /* 普通状态 */ - Node * selected, /* 鼠标按下状态 */ - Function func = nullptr /* 按钮点击后的执行函数 */ + Node * normal, /* 普通状态 */ + Node * selected, /* 鼠标按下状态 */ + const Function& func = nullptr /* 按钮点击后的执行函数 */ ); // 创建按钮 Button( - Node * normal, /* 普通状态 */ - Node * mouseover, /* 鼠标移入状态 */ - Node * selected, /* 鼠标按下状态 */ - Function func = nullptr /* 按钮点击后的执行函数 */ + Node * normal, /* 普通状态 */ + Node * mouseover, /* 鼠标移入状态 */ + Node * selected, /* 鼠标按下状态 */ + const Function& func = nullptr /* 按钮点击后的执行函数 */ ); // 创建按钮 Button( - Node * normal, /* 普通状态 */ - Node * mouseover, /* 鼠标移入状态 */ - Node * selected, /* 鼠标移入状态 */ - Node * disabled, /* 按钮禁用状态 */ - Function func = nullptr /* 按钮点击后的执行函数 */ + Node * normal, /* 普通状态 */ + Node * mouseover, /* 鼠标移入状态 */ + Node * selected, /* 鼠标移入状态 */ + Node * disabled, /* 按钮禁用状态 */ + const Function& func = nullptr /* 按钮点击后的执行函数 */ ); // 获取按钮状态是启用还是禁用 @@ -822,7 +809,7 @@ public: // 设置按钮点击后的执行函数 void setClickFunc( - Function func + const Function& func ); // 更新按钮状态 @@ -862,42 +849,42 @@ public: // 创建开关按钮 ButtonToggle( - Node * onNormal, /* 按钮打开时,普通状态 */ - Node * offNormal, /* 按钮关闭时,普通状态 */ - Function func = nullptr /* 按钮点击后的执行函数 */ + Node * onNormal, /* 按钮打开时,普通状态 */ + Node * offNormal, /* 按钮关闭时,普通状态 */ + const Function& func = nullptr /* 按钮点击后的执行函数 */ ); // 创建开关按钮 ButtonToggle( - Node * onNormal, /* 按钮打开时,普通状态 */ - Node * offNormal, /* 按钮关闭时,普通状态 */ - Node * onSelected, /* 按钮打开时,鼠标按下状态 */ - Node * offSelected, /* 按钮关闭时,鼠标按下状态 */ - Function func = nullptr /* 按钮点击后的执行函数 */ + Node * onNormal, /* 按钮打开时,普通状态 */ + Node * offNormal, /* 按钮关闭时,普通状态 */ + Node * onSelected, /* 按钮打开时,鼠标按下状态 */ + Node * offSelected, /* 按钮关闭时,鼠标按下状态 */ + const Function& func = nullptr /* 按钮点击后的执行函数 */ ); // 创建开关按钮 ButtonToggle( - Node * onNormal, /* 按钮打开时,普通状态 */ - Node * offNormal, /* 按钮关闭时,普通状态 */ - Node * onMouseOver, /* 按钮打开时,鼠标移入状态 */ - Node * offMouseOver, /* 按钮关闭时,鼠标移入状态 */ - Node * onSelected, /* 按钮打开时,鼠标按下状态 */ - Node * offSelected, /* 按钮关闭时,鼠标按下状态 */ - Function func = nullptr /* 按钮点击后的执行函数 */ + Node * onNormal, /* 按钮打开时,普通状态 */ + Node * offNormal, /* 按钮关闭时,普通状态 */ + Node * onMouseOver, /* 按钮打开时,鼠标移入状态 */ + Node * offMouseOver, /* 按钮关闭时,鼠标移入状态 */ + Node * onSelected, /* 按钮打开时,鼠标按下状态 */ + Node * offSelected, /* 按钮关闭时,鼠标按下状态 */ + const Function& func = nullptr /* 按钮点击后的执行函数 */ ); // 创建开关按钮 ButtonToggle( - Node * onNormal, /* 按钮打开时,普通状态 */ - Node * offNormal, /* 按钮关闭时,普通状态 */ - Node * onMouseOver, /* 按钮打开时,鼠标移入状态 */ - Node * offMouseOver, /* 按钮关闭时,鼠标移入状态 */ - Node * onSelected, /* 按钮打开时,鼠标按下状态 */ - Node * offSelected, /* 按钮关闭时,鼠标按下状态 */ - Node * onDisabled, /* 按钮打开时,禁用状态 */ - Node * offDisabled, /* 按钮关闭时,禁用状态 */ - Function func = nullptr /* 按钮点击后的执行函数 */ + Node * onNormal, /* 按钮打开时,普通状态 */ + Node * offNormal, /* 按钮关闭时,普通状态 */ + Node * onMouseOver, /* 按钮打开时,鼠标移入状态 */ + Node * offMouseOver, /* 按钮关闭时,鼠标移入状态 */ + Node * onSelected, /* 按钮打开时,鼠标按下状态 */ + Node * offSelected, /* 按钮关闭时,鼠标按下状态 */ + Node * onDisabled, /* 按钮打开时,禁用状态 */ + Node * offDisabled, /* 按钮关闭时,禁用状态 */ + const Function& func = nullptr /* 按钮点击后的执行函数 */ ); // 获取开关状态(打开或关闭) @@ -978,7 +965,7 @@ public: #ifdef HIGHER_THAN_VS2012 // 创建菜单 Menu( - const InitList& vButtons /* 按钮数组 */ + const std::initializer_list& vButtons /* 按钮列表 */ ); #else // 创建菜单 diff --git a/core/e2dtool.h b/core/e2dtool.h index b41d86ba..4c44a546 100644 --- a/core/e2dtool.h +++ b/core/e2dtool.h @@ -162,16 +162,16 @@ class Timer friend Game; public: - // 启动定时器 + // 启动定时器(每帧执行一次) static void start( - Function func, /* 执行函数 */ - const String& name /* 定时器名称 */ + const Function& func, /* 执行函数 */ + const String& name = L"" /* 定时器名称 */ ); // 启动定时器 static void start( - Function func, /* 执行函数 */ - double delay = 0, /* 时间间隔(秒) */ + const Function& func, /* 执行函数 */ + double delay, /* 时间间隔(秒) */ int times = -1, /* 执行次数(设 -1 为永久执行) */ bool paused = false, /* 是否暂停 */ const String& name = L"" /* 定时器名称 */ @@ -179,7 +179,7 @@ public: // 启动仅执行一次的定时器 static void startOnce( - Function func, /* 执行的函数 */ + const Function& func, /* 执行的函数 */ double timeOut /* 等待的时长(秒) */ ); diff --git a/core/e2dtransition.h b/core/e2dtransition.h index e692ec28..1eac62a6 100644 --- a/core/e2dtransition.h +++ b/core/e2dtransition.h @@ -51,7 +51,7 @@ public: virtual ~TransitionBase(); // 场景切换动画是否结束 - bool isEnding(); + bool isDone(); // 销毁对象 virtual void destroy() override;