mirror of https://github.com/axmolengine/axmol.git
Merge pull request #5459 from dumganhar/develop
More const reference loves in EventDispatcher.
This commit is contained in:
commit
a6b89f1fcc
|
@ -35,7 +35,7 @@ EventListener::~EventListener()
|
||||||
CCLOGINFO("In the destructor of EventListener. %p", this);
|
CCLOGINFO("In the destructor of EventListener. %p", this);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EventListener::init(Type t, ListenerID listenerID, std::function<void(Event*)> callback)
|
bool EventListener::init(Type t, const ListenerID& listenerID, const std::function<void(Event*)>& callback)
|
||||||
{
|
{
|
||||||
_onEvent = callback;
|
_onEvent = callback;
|
||||||
_type = t;
|
_type = t;
|
||||||
|
|
|
@ -64,7 +64,7 @@ protected:
|
||||||
EventListener();
|
EventListener();
|
||||||
|
|
||||||
/** Initializes event with type and callback function */
|
/** Initializes event with type and callback function */
|
||||||
bool init(Type t, ListenerID listenerID, std::function<void(Event*)>callback);
|
bool init(Type t, const ListenerID& listenerID, const std::function<void(Event*)>& callback);
|
||||||
public:
|
public:
|
||||||
/** Destructor */
|
/** Destructor */
|
||||||
virtual ~EventListener();
|
virtual ~EventListener();
|
||||||
|
|
|
@ -39,7 +39,7 @@ EventListenerAcceleration::~EventListenerAcceleration()
|
||||||
CCLOGINFO("In the destructor of AccelerationEventListener. %p", this);
|
CCLOGINFO("In the destructor of AccelerationEventListener. %p", this);
|
||||||
}
|
}
|
||||||
|
|
||||||
EventListenerAcceleration* EventListenerAcceleration::create(std::function<void(Acceleration*, Event*)> callback)
|
EventListenerAcceleration* EventListenerAcceleration::create(const std::function<void(Acceleration*, Event*)>& callback)
|
||||||
{
|
{
|
||||||
EventListenerAcceleration* ret = new EventListenerAcceleration();
|
EventListenerAcceleration* ret = new EventListenerAcceleration();
|
||||||
if (ret && ret->init(callback))
|
if (ret && ret->init(callback))
|
||||||
|
@ -54,7 +54,7 @@ EventListenerAcceleration* EventListenerAcceleration::create(std::function<void(
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EventListenerAcceleration::init(std::function<void(Acceleration*, Event* event)> callback)
|
bool EventListenerAcceleration::init(const std::function<void(Acceleration*, Event* event)>& callback)
|
||||||
{
|
{
|
||||||
auto listener = [this](Event* event){
|
auto listener = [this](Event* event){
|
||||||
auto accEvent = static_cast<EventAcceleration*>(event);
|
auto accEvent = static_cast<EventAcceleration*>(event);
|
||||||
|
|
|
@ -35,7 +35,7 @@ class EventListenerAcceleration : public EventListener
|
||||||
public:
|
public:
|
||||||
static const std::string LISTENER_ID;
|
static const std::string LISTENER_ID;
|
||||||
|
|
||||||
static EventListenerAcceleration* create(std::function<void(Acceleration*, Event*)> callback);
|
static EventListenerAcceleration* create(const std::function<void(Acceleration*, Event*)>& callback);
|
||||||
virtual ~EventListenerAcceleration();
|
virtual ~EventListenerAcceleration();
|
||||||
|
|
||||||
/// Overrides
|
/// Overrides
|
||||||
|
@ -44,7 +44,7 @@ public:
|
||||||
private:
|
private:
|
||||||
EventListenerAcceleration();
|
EventListenerAcceleration();
|
||||||
|
|
||||||
bool init(std::function<void(Acceleration*, Event* event)> callback);
|
bool init(const std::function<void(Acceleration*, Event* event)>& callback);
|
||||||
std::function<void(Acceleration*, Event*)> onAccelerationEvent;
|
std::function<void(Acceleration*, Event*)> onAccelerationEvent;
|
||||||
|
|
||||||
friend class LuaEventListenerAcceleration;
|
friend class LuaEventListenerAcceleration;
|
||||||
|
|
|
@ -32,7 +32,7 @@ EventListenerCustom::EventListenerCustom()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
EventListenerCustom* EventListenerCustom::create(const std::string& eventName, std::function<void(EventCustom*)> callback)
|
EventListenerCustom* EventListenerCustom::create(const std::string& eventName, const std::function<void(EventCustom*)>& callback)
|
||||||
{
|
{
|
||||||
EventListenerCustom* ret = new EventListenerCustom();
|
EventListenerCustom* ret = new EventListenerCustom();
|
||||||
if (ret && ret->init(eventName, callback))
|
if (ret && ret->init(eventName, callback))
|
||||||
|
@ -46,7 +46,7 @@ EventListenerCustom* EventListenerCustom::create(const std::string& eventName, s
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EventListenerCustom::init(ListenerID listenerId, std::function<void(EventCustom*)>callback)
|
bool EventListenerCustom::init(const ListenerID& listenerId, const std::function<void(EventCustom*)>& callback)
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ public:
|
||||||
* @param eventType The type of the event.
|
* @param eventType The type of the event.
|
||||||
* @param callback The callback function when the specified event was emitted.
|
* @param callback The callback function when the specified event was emitted.
|
||||||
*/
|
*/
|
||||||
static EventListenerCustom* create(const std::string& eventName, std::function<void(EventCustom*)> callback);
|
static EventListenerCustom* create(const std::string& eventName, const std::function<void(EventCustom*)>& callback);
|
||||||
|
|
||||||
/// Overrides
|
/// Overrides
|
||||||
virtual bool checkAvailable() override;
|
virtual bool checkAvailable() override;
|
||||||
|
@ -67,7 +67,7 @@ protected:
|
||||||
EventListenerCustom();
|
EventListenerCustom();
|
||||||
|
|
||||||
/** Initializes event with type and callback function */
|
/** Initializes event with type and callback function */
|
||||||
bool init(ListenerID listenerId, std::function<void(EventCustom*)> callback);
|
bool init(const ListenerID& listenerId, const std::function<void(EventCustom*)>& callback);
|
||||||
|
|
||||||
std::function<void(EventCustom*)> _onCustomEvent;
|
std::function<void(EventCustom*)> _onCustomEvent;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue