Package gaiasky.event
Class EventManager
java.lang.Object
gaiasky.event.EventManager
- All Implemented Interfaces:
IObserver
Event manager that allows for subscription of observers to events (identified
by strings), and also for the creation of event objects by anyone. Events can also
be added to be processed with a delay.
-
Nested Class Summary
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
void
clearSubscriptions
(Event msg) Unregister all the listeners for the specified message code.void
Dispatches any telegrams with a timestamp that has expired.static long
Returns the current time in milliseconds.boolean
hasSubscriptors
(Event event) boolean
isSubscribedTo
(IObserver o, Event event) boolean
void
Event notification call.void
Register a new data-less event with the given source.void
Register a new event with the given source and with the given data.void
postDelayed
(Event event, Object source, long delayMs, EventManager.TimeFrame frame, Object... data) Register a new event with the given type, data, delay and time frame.void
postDelayed
(Event event, Object source, long delayMs, Object... data) Register a new delayed event with the given type, data, delay and the default time frame.static void
Register a new event to the default event manager instance with the given source and data.static void
publishDelayed
(Event event, Object source, long delayMs, Object... data) Register a new delayed event in the default manager with the given type, data, delay and the default time frame.void
removeAllSubscriptions
(IObserver... listeners) Unregister all the subscriptions of the given listeners.void
removeRadioSubscriptions
(com.badlogic.ashley.core.Entity entity) Remove all subscriptions ofEntityRadio
for the given entity.void
Register a listener for the specified message code.void
Subscribe the given observer to the given event types.void
unsubscribe
(IObserver listener, Event event) Unregister the specified listener for the specified message code.void
unsubscribe
(IObserver listener, Event... events)
-
Field Details
-
instance
Singleton pattern
-
-
Constructor Details
-
EventManager
public EventManager()
-
-
Method Details
-
subscribe
Subscribe the given observer to the given event types.- Parameters:
observer
- The observer to subscribe.events
- The event types to subscribe to.
-
subscribe
Register a listener for the specified message code. Messages without an explicit receiver are broadcast to all its registered listeners.- Parameters:
listener
- the listener to addmsg
- the message code
-
unsubscribe
-
unsubscribe
Unregister the specified listener for the specified message code.- Parameters:
listener
- The listener to remove.event
- The message code.
-
removeAllSubscriptions
Unregister all the subscriptions of the given listeners.- Parameters:
listeners
- The listeners to remove.
-
removeRadioSubscriptions
public void removeRadioSubscriptions(com.badlogic.ashley.core.Entity entity) Remove all subscriptions ofEntityRadio
for the given entity.- Parameters:
entity
- The entity.
-
clearSubscriptions
Unregister all the listeners for the specified message code.- Parameters:
msg
- The message code.
-
clearAllSubscriptions
public void clearAllSubscriptions() -
publish
Register a new event to the default event manager instance with the given source and data.- Parameters:
event
- The event.source
- The source object, if any.data
- The event data.
-
post
Register a new data-less event with the given source.- Parameters:
event
- The event.source
- The source object, if any.
-
post
Register a new event with the given source and with the given data.- Parameters:
event
- The event.source
- The source object, if any.data
- The event data.
-
publishDelayed
Register a new delayed event in the default manager with the given type, data, delay and the default time frame. The default time frame can be changed using the eventEvent.EVENT_TIME_FRAME_CMD
. The event will be passed along after the specified delay time [ms] in the given time frame has passed.- Parameters:
event
- The event.source
- The source object, if any.delayMs
- Milliseconds of delay in the given time frame.data
- The event data.
-
postDelayed
Register a new delayed event with the given type, data, delay and the default time frame. The default time frame can be changed using the eventEvent.EVENT_TIME_FRAME_CMD
. The event will be passed along after the specified delay time [ms] in the given time frame has passed.- Parameters:
event
- The event.source
- The source object, if any.delayMs
- Milliseconds of delay in the given time frame.data
- The event data.
-
postDelayed
public void postDelayed(Event event, Object source, long delayMs, EventManager.TimeFrame frame, Object... data) Register a new event with the given type, data, delay and time frame. The event will be passed along after the specified delay time [ms] in the given time frame has passed.- Parameters:
event
- The event.source
- The source object, if any.delayMs
- Milliseconds of delay in the given time frame.frame
- The time frame, either real time (user) or simulation time (simulation clock time).data
- The event data.
-
getCurrentTime
public static long getCurrentTime()Returns the current time in milliseconds. -
dispatchDelayedMessages
public void dispatchDelayedMessages()Dispatches any telegrams with a timestamp that has expired. Any dispatched telegrams are removed from the queue.This method must be called each time through the main loop.
-
hasSubscriptors
-
isSubscribedToAny
-
isSubscribedTo
-
notify
Description copied from interface:IObserver
Event notification call.
-