mirror of
https://github.com/edubart/otclient.git
synced 2025-12-26 09:47:11 +01:00
merge total remake
This commit is contained in:
38
src/framework/core/eventdispatcher.h
Normal file
38
src/framework/core/eventdispatcher.h
Normal file
@@ -0,0 +1,38 @@
|
||||
#ifndef EVENTDISPATCHER_H
|
||||
#define EVENTDISPATCHER_H
|
||||
|
||||
#include <global.h>
|
||||
|
||||
struct ScheduledEvent {
|
||||
ScheduledEvent(int ticks, const SimpleCallback& callback) : ticks(ticks), callback(callback) { }
|
||||
bool operator<(const ScheduledEvent& other) const { return ticks > other.ticks; }
|
||||
int ticks;
|
||||
SimpleCallback callback;
|
||||
};
|
||||
|
||||
class EventDispatcher
|
||||
{
|
||||
public:
|
||||
/// Initialize dispatcher
|
||||
void init();
|
||||
|
||||
/// Cleanup scheduled events
|
||||
void terminate();
|
||||
|
||||
/// Execute scheduled events
|
||||
void poll();
|
||||
|
||||
/// Add an event
|
||||
void addEvent(const SimpleCallback& callback, bool pushFront = false);
|
||||
|
||||
/// Schedule an event
|
||||
void scheduleEvent(const SimpleCallback& callback, int delay);
|
||||
|
||||
private:
|
||||
std::list<SimpleCallback> m_eventList;
|
||||
std::priority_queue<ScheduledEvent> m_scheduledEventList;
|
||||
};
|
||||
|
||||
extern EventDispatcher g_dispatcher;
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user