diff --git a/core/Action/ActionCallback.cpp b/core/Action/ActionCallback.cpp index 842c69f5..b64c02a0 100644 --- a/core/Action/ActionCallback.cpp +++ b/core/Action/ActionCallback.cpp @@ -1,6 +1,6 @@ #include "..\eactions.h" -e2d::ActionCallback::ActionCallback(const VoidFunction& callback) : +e2d::ActionCallback::ActionCallback(VoidFunction callback) : m_Callback(callback) { } diff --git a/core/Manager/SceneManager.cpp b/core/Manager/SceneManager.cpp index c2282b5c..3a224e21 100644 --- a/core/Manager/SceneManager.cpp +++ b/core/Manager/SceneManager.cpp @@ -152,15 +152,17 @@ void e2d::SceneManager::__render() bool e2d::SceneManager::__init() { - if (!s_pNextScene) + // 若游戏初始化时场景不为空,进入该场景 + if (s_pNextScene) { - s_pNextScene = new Scene(); - s_pNextScene->retain(); + s_pCurrentScene = s_pNextScene; + s_pCurrentScene->onEnter(); + s_pNextScene = nullptr; } - s_pCurrentScene = s_pNextScene; - s_pCurrentScene->onEnter(); - s_pNextScene = nullptr; + // 更新场景内容 + SceneManager::__update(); + return true; } diff --git a/core/Node/Button.cpp b/core/Node/Button.cpp index b94257b5..66da1a6e 100644 --- a/core/Node/Button.cpp +++ b/core/Node/Button.cpp @@ -5,7 +5,7 @@ e2d::Button::Button() - : m_Callback((const ButtonCallback &)nullptr) + : m_Callback(nullptr) , m_eBtnState(Button::NORMAL) , m_bEnable(true) , m_bIsSelected(false) @@ -16,8 +16,8 @@ e2d::Button::Button() { } -e2d::Button::Button(Node * normal, const ButtonCallback & callback) - : m_Callback((const ButtonCallback &)nullptr) +e2d::Button::Button(Node * normal, ButtonCallback callback) + : m_Callback(nullptr) , m_eBtnState(Button::NORMAL) , m_bEnable(true) , m_bIsSelected(false) @@ -30,8 +30,8 @@ e2d::Button::Button(Node * normal, const ButtonCallback & callback) this->setCallback(callback); } -e2d::Button::Button(Node * normal, Node * selected, const ButtonCallback & callback) - : m_Callback((const ButtonCallback &)nullptr) +e2d::Button::Button(Node * normal, Node * selected, ButtonCallback callback) + : m_Callback(nullptr) , m_eBtnState(Button::NORMAL) , m_bEnable(true) , m_bIsSelected(false) @@ -45,8 +45,8 @@ e2d::Button::Button(Node * normal, Node * selected, const ButtonCallback & callb this->setCallback(callback); } -e2d::Button::Button(Node * normal, Node * mouseover, Node * selected, const ButtonCallback & callback) - : m_Callback((const ButtonCallback &)nullptr) +e2d::Button::Button(Node * normal, Node * mouseover, Node * selected, ButtonCallback callback) + : m_Callback(nullptr) , m_eBtnState(Button::NORMAL) , m_bEnable(true) , m_bIsSelected(false) @@ -61,8 +61,8 @@ e2d::Button::Button(Node * normal, Node * mouseover, Node * selected, const Butt this->setCallback(callback); } -e2d::Button::Button(Node * normal, Node * mouseover, Node * selected, Node * disabled, const ButtonCallback & callback) - : m_Callback((const ButtonCallback &)nullptr) +e2d::Button::Button(Node * normal, Node * mouseover, Node * selected, Node * disabled, ButtonCallback callback) + : m_Callback(nullptr) , m_eBtnState(Button::NORMAL) , m_bEnable(true) , m_bIsSelected(false) @@ -170,7 +170,7 @@ void e2d::Button::setEnable(bool bEnable) } } -void e2d::Button::setCallback(const ButtonCallback & callback) +void e2d::Button::setCallback(ButtonCallback callback) { 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 5c2c2ca9..5b0723fa 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, const ButtonCallback & callback) +e2d::ButtonToggle::ButtonToggle(Node * toggleOnNormal, Node * toggleOffNormal, ButtonCallback callback) : Button() , m_bState(true) , m_pNormalOn(nullptr) @@ -31,7 +31,7 @@ e2d::ButtonToggle::ButtonToggle(Node * toggleOnNormal, Node * toggleOffNormal, c this->setCallback(callback); } -e2d::ButtonToggle::ButtonToggle(Node * toggleOnNormal, Node * toggleOffNormal, Node * toggleOnSelected, Node * toggleOffSelected, const ButtonCallback & callback) +e2d::ButtonToggle::ButtonToggle(Node * toggleOnNormal, Node * toggleOffNormal, Node * toggleOnSelected, Node * toggleOffSelected, ButtonCallback callback) : Button() , m_bState(true) , m_pNormalOn(nullptr) @@ -50,7 +50,7 @@ e2d::ButtonToggle::ButtonToggle(Node * toggleOnNormal, Node * toggleOffNormal, N this->setCallback(callback); } -e2d::ButtonToggle::ButtonToggle(Node * toggleOnNormal, Node * toggleOffNormal, Node * toggleOnMouseOver, Node * toggleOffMouseOver, Node * toggleOnSelected, Node * toggleOffSelected, const ButtonCallback & callback) +e2d::ButtonToggle::ButtonToggle(Node * toggleOnNormal, Node * toggleOffNormal, Node * toggleOnMouseOver, Node * toggleOffMouseOver, Node * toggleOnSelected, Node * toggleOffSelected, ButtonCallback callback) : Button() , m_bState(true) , m_pNormalOn(nullptr) @@ -71,7 +71,7 @@ e2d::ButtonToggle::ButtonToggle(Node * toggleOnNormal, Node * toggleOffNormal, N this->setCallback(callback); } -e2d::ButtonToggle::ButtonToggle(Node * toggleOnNormal, Node * toggleOffNormal, Node * toggleOnMouseOver, Node * toggleOffMouseOver, Node * toggleOnSelected, Node * toggleOffSelected, Node * toggleOnDisabled, Node * toggleOffDisabled, const ButtonCallback & callback) +e2d::ButtonToggle::ButtonToggle(Node * toggleOnNormal, Node * toggleOffNormal, Node * toggleOnMouseOver, Node * toggleOffMouseOver, Node * toggleOnSelected, Node * toggleOffSelected, Node * toggleOnDisabled, Node * toggleOffDisabled, ButtonCallback callback) : Button() , m_bState(true) , m_pNormalOn(nullptr) diff --git a/core/Tool/Timer.cpp b/core/Tool/Timer.cpp index d529ed19..2429bd70 100644 --- a/core/Tool/Timer.cpp +++ b/core/Tool/Timer.cpp @@ -11,12 +11,12 @@ e2d::Timer::Timer() , m_nUpdateTimes(-1) , m_bAtOnce(false) , m_bAutoRelease(false) - , m_bClear(false) + , m_bClear(true) { TimerManager::__add(this); } -e2d::Timer::Timer(const TimerCallback & callback, double interval /* = 0 */, int updateTimes /* = -1 */, bool atOnce /* = false */, bool autoRelease /* = false */) +e2d::Timer::Timer(TimerCallback callback, double interval /* = 0 */, int updateTimes /* = -1 */, bool atOnce /* = false */, bool autoRelease /* = false */) : m_bRunning(false) , m_nRunTimes(0) , m_Callback(nullptr) @@ -25,7 +25,7 @@ e2d::Timer::Timer(const TimerCallback & callback, double interval /* = 0 */, int , m_nUpdateTimes(-1) , m_bAtOnce(false) , m_bAutoRelease(false) - , m_bClear(false) + , m_bClear(true) { this->setCallback(callback); this->setUpdateTimes(updateTimes); @@ -35,7 +35,7 @@ e2d::Timer::Timer(const TimerCallback & callback, double interval /* = 0 */, int TimerManager::__add(this); } -e2d::Timer::Timer(const String & name, const TimerCallback & callback, double interval /* = 0 */, int updateTimes /* = -1 */, bool atOnce /* = false */, bool autoRelease /* = false */) +e2d::Timer::Timer(const String & name, TimerCallback callback, double interval /* = 0 */, int updateTimes /* = -1 */, bool atOnce /* = false */, bool autoRelease /* = false */) : m_bRunning(false) , m_nRunTimes(0) , m_Callback(nullptr) @@ -44,7 +44,7 @@ e2d::Timer::Timer(const String & name, const TimerCallback & callback, double in , m_nUpdateTimes(-1) , m_bAtOnce(false) , m_bAutoRelease(false) - , m_bClear(false) + , m_bClear(true) { this->setName(name); this->setCallback(callback); @@ -92,7 +92,7 @@ void e2d::Timer::setInterval(double interval) m_fInterval = max(interval, 0); } -void e2d::Timer::setCallback(const TimerCallback & callback) +void e2d::Timer::setCallback(TimerCallback callback) { m_Callback = callback; } diff --git a/core/eactions.h b/core/eactions.h index 24ec360b..a62b404c 100644 --- a/core/eactions.h +++ b/core/eactions.h @@ -553,7 +553,7 @@ class ActionCallback : public: // 创建执行回调函数的动作 ActionCallback( - const VoidFunction & callback /* 回调函数 */ + VoidFunction callback /* 回调函数 */ ); // 获取该动作的拷贝对象 diff --git a/core/enodes.h b/core/enodes.h index 3f7ae8cd..a933bb64 100644 --- a/core/enodes.h +++ b/core/enodes.h @@ -584,14 +584,14 @@ public: // 创建按钮 Button( Node * normal, /* 普通状态 */ - const ButtonCallback & callback = nullptr + ButtonCallback callback = nullptr ); // 创建按钮 Button( Node * normal, /* 普通状态 */ Node * selected, /* 鼠标按下状态 */ - const ButtonCallback & callback = nullptr + ButtonCallback callback = nullptr ); // 创建按钮 @@ -599,7 +599,7 @@ public: Node * normal, /* 普通状态 */ Node * mouseover, /* 鼠标移入状态 */ Node * selected, /* 鼠标按下状态 */ - const ButtonCallback & callback = nullptr + ButtonCallback callback = nullptr ); // 创建按钮 @@ -608,7 +608,7 @@ public: Node * mouseover, /* 鼠标移入状态 */ Node * selected, /* 鼠标移入状态 */ Node * disabled, /* 按钮禁用状态 */ - const ButtonCallback & callback = nullptr + ButtonCallback callback = nullptr ); // 获取按钮状态是启用还是禁用 @@ -641,7 +641,7 @@ public: // 设置回调函数 void setCallback( - const ButtonCallback & callback + ButtonCallback callback ); // 更新按钮状态 @@ -682,7 +682,7 @@ public: ButtonToggle( Node * onNormal, Node * offNormal, - const ButtonCallback & callback = nullptr + ButtonCallback callback = nullptr ); // 创建开关按钮 @@ -691,7 +691,7 @@ public: Node * offNormal, Node * onSelected, Node * offSelected, - const ButtonCallback & callback = nullptr + ButtonCallback callback = nullptr ); // 创建开关按钮 @@ -702,7 +702,7 @@ public: Node * offMouseOver, Node * onSelected, Node * offSelected, - const ButtonCallback & callback = nullptr + ButtonCallback callback = nullptr ); // 创建开关按钮 @@ -715,7 +715,7 @@ public: Node * offSelected, Node * onDisabled, Node * offDisabled, - const ButtonCallback & callback = nullptr + ButtonCallback callback = nullptr ); // 获取开关状态(打开或关闭) diff --git a/core/etools.h b/core/etools.h index 10f65d8e..44712b77 100644 --- a/core/etools.h +++ b/core/etools.h @@ -50,20 +50,20 @@ public: Timer(); Timer( - const TimerCallback &callback, /* 定时器回调函数 */ - double interval = 0, /* 时间间隔(秒) */ - int times = -1, /* 执行次数(设 -1 为永久执行) */ - bool atOnce = false, /* 是否立即执行 */ - bool autoRelease = false /* 自动清除 */ + TimerCallback callback, /* 定时器回调函数 */ + double interval = 0, /* 时间间隔(秒) */ + int times = -1, /* 执行次数(设 -1 为永久执行) */ + bool atOnce = false, /* 是否立即执行 */ + bool autoRelease = false /* 自动清除 */ ); Timer( - const String &name, /* 定时器名称 */ - const TimerCallback &callback = nullptr, /* 定时器回调函数 */ - double interval = 0, /* 时间间隔(秒) */ - int times = -1, /* 执行次数(设 -1 为永久执行) */ - bool atOnce = false, /* 是否立即执行 */ - bool autoRelease = false /* 自动清除 */ + const String &name, /* 定时器名称 */ + TimerCallback callback = nullptr, /* 定时器回调函数 */ + double interval = 0, /* 时间间隔(秒) */ + int times = -1, /* 执行次数(设 -1 为永久执行) */ + bool atOnce = false, /* 是否立即执行 */ + bool autoRelease = false /* 自动清除 */ ); // 启动定时器 @@ -99,7 +99,7 @@ public: // 设置定时器回调函数 void setCallback( - const TimerCallback & callback + TimerCallback callback ); // 设置定时器执行次数