Allow multiple event handlers for the same slot
This commit is contained in:
@@ -107,10 +107,11 @@ struct CompanyBalanceChanged {
|
|||||||
};
|
};
|
||||||
|
|
||||||
enum class Slot : uint8 {
|
enum class Slot : uint8 {
|
||||||
CONTROLLER = 10,
|
GOAL = 10,
|
||||||
GAME = 20,
|
CONTROLLER = 20,
|
||||||
CONTROLLER_POST = 30,
|
GAME = 30,
|
||||||
RECORDER = 40,
|
CONTROLLER_POST = 40,
|
||||||
|
RECORDER = 50,
|
||||||
};
|
};
|
||||||
|
|
||||||
class TypeDispatcherBase {
|
class TypeDispatcherBase {
|
||||||
@@ -128,11 +129,7 @@ public:
|
|||||||
virtual ~TypeDispatcher() {}
|
virtual ~TypeDispatcher() {}
|
||||||
|
|
||||||
void listen(Slot slot, Handler &handler) {
|
void listen(Slot slot, Handler &handler) {
|
||||||
auto p = this->handler_map.find(slot);
|
this->handler_map.insert(std::make_pair(slot, handler));
|
||||||
if (p != this->handler_map.end())
|
|
||||||
IConsolePrintF(CC_ERROR, "ERROR: Ignored duplicate handler for event %s slot %d", typeid(T).name(), (int)slot);
|
|
||||||
this->handler_map.insert(p, std::make_pair(slot, handler));
|
|
||||||
this->new_handlers = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void emit(const T &event) {
|
void emit(const T &event) {
|
||||||
@@ -149,7 +146,7 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::vector<Handler> handlers;
|
std::vector<Handler> handlers;
|
||||||
std::map<Slot, Handler> handler_map;
|
std::multimap<Slot, Handler> handler_map;
|
||||||
bool new_handlers = false;
|
bool new_handlers = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user