#pragma once #include #include #include #include #include namespace extra2d { // ============================================================================ // 事件监听器 ID // ============================================================================ using ListenerId = uint64_t; // ============================================================================ // 事件分发器 // ============================================================================ class EventDispatcher { public: using EventCallback = std::function; EventDispatcher(); ~EventDispatcher() = default; // 添加监听器 ListenerId addListener(EventType type, EventCallback callback); // 移除监听器 void removeListener(ListenerId id); void removeAllListeners(EventType type); void removeAllListeners(); // 分发事件 void dispatch(Event &event); void dispatch(const Event &event); // 处理事件队列 void processQueue(class EventQueue &queue); // 统计 size_t getListenerCount(EventType type) const; size_t getTotalListenerCount() const; private: struct Listener { ListenerId id; EventType type; EventCallback callback; }; std::unordered_map> listeners_; ListenerId nextId_; }; } // namespace extra2d