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);
|
||||
}
|
||||
|
||||
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;
|
||||
_type = t;
|
||||
|
|
|
@ -64,7 +64,7 @@ protected:
|
|||
EventListener();
|
||||
|
||||
/** 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:
|
||||
/** Destructor */
|
||||
virtual ~EventListener();
|
||||
|
|
|
@ -39,7 +39,7 @@ EventListenerAcceleration::~EventListenerAcceleration()
|
|||
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();
|
||||
if (ret && ret->init(callback))
|
||||
|
@ -54,7 +54,7 @@ EventListenerAcceleration* EventListenerAcceleration::create(std::function<void(
|
|||
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 accEvent = static_cast<EventAcceleration*>(event);
|
||||
|
|
|
@ -35,7 +35,7 @@ class EventListenerAcceleration : public EventListener
|
|||
public:
|
||||
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();
|
||||
|
||||
/// Overrides
|
||||
|
@ -44,7 +44,7 @@ public:
|
|||
private:
|
||||
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;
|
||||
|
||||
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();
|
||||
if (ret && ret->init(eventName, callback))
|
||||
|
@ -46,7 +46,7 @@ EventListenerCustom* EventListenerCustom::create(const std::string& eventName, s
|
|||
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;
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ public:
|
|||
* @param eventType The type of the event.
|
||||
* @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
|
||||
virtual bool checkAvailable() override;
|
||||
|
@ -67,7 +67,7 @@ protected:
|
|||
EventListenerCustom();
|
||||
|
||||
/** 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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue