Information and management about a registered event

It allows to retrieve static and dynamic information about an event. It also allows to register other time-related events with a fluent programming way.

Introduced properties

fun add_after(event: E, delay: Float, duration: nullable Float): EventInfo[E]

event_queue :: EventInfo :: add_after

Register an event that starts after the end of the current one.
fun add_before(event: E, delay: Float, duration: nullable Float): EventInfo[E]

event_queue :: EventInfo :: add_before

Register an event that finishes before the begin of current one.
fun add_sync(event: E, delay: Float, duration: nullable Float): EventInfo[E]

event_queue :: EventInfo :: add_sync

Register an event that starts with the current one.
fun completion: Float

event_queue :: EventInfo :: completion

Ratio of completion
protected fun completion=(completion: Float)

event_queue :: EventInfo :: completion=

Ratio of completion
fun dt: Float

event_queue :: EventInfo :: dt

Time since the last update (or the begin of the event if smaller)
protected fun dt=(dt: Float)

event_queue :: EventInfo :: dt=

Time since the last update (or the begin of the event if smaller)
fun duration: Float

event_queue :: EventInfo :: duration

Registered duration.
protected fun duration=(duration: Float)

event_queue :: EventInfo :: duration=

Registered duration.
fun event: E

event_queue :: EventInfo :: event

The registered event.
protected fun event=(event: E)

event_queue :: EventInfo :: event=

The registered event.
fun expire

event_queue :: EventInfo :: expire

Force the event to expire.
fun has_expired: Bool

event_queue :: EventInfo :: has_expired

Has the event expired?
protected fun has_expired=(has_expired: Bool)

event_queue :: EventInfo :: has_expired=

Has the event expired?
fun occurrences: Int

event_queue :: EventInfo :: occurrences

Number of times that an event was returned by update.
protected fun occurrences=(occurrences: Int)

event_queue :: EventInfo :: occurrences=

Number of times that an event was returned by update.
fun queue: EventQueue[E]

event_queue :: EventInfo :: queue

The associated event queue.
protected fun queue=(queue: EventQueue[E])

event_queue :: EventInfo :: queue=

The associated event queue.
fun start: Float

event_queue :: EventInfo :: start

Absolute start time for the registered event in the event queue time frame.
protected fun start=(start: Float)

event_queue :: EventInfo :: start=

Absolute start time for the registered event in the event queue time frame.
fun time: Float

event_queue :: EventInfo :: time

Time since the begin of the event, in units of time.
protected fun time=(time: Float)

event_queue :: EventInfo :: time=

Time since the begin of the event, in units of time.

Redefined properties

redef type SELF: EventInfo[E]

event_queue $ EventInfo :: SELF

Type of this instance, automatically specialized in every class
redef init init(event: E, queue: EventQueue[E], start: Float, duration: Float)

event_queue $ EventInfo :: init

redef fun to_s: String

event_queue $ EventInfo :: to_s

User readable representation of self.

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have self and other different values?
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have self and other the same value?
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
fun add_after(event: E, delay: Float, duration: nullable Float): EventInfo[E]

event_queue :: EventInfo :: add_after

Register an event that starts after the end of the current one.
fun add_before(event: E, delay: Float, duration: nullable Float): EventInfo[E]

event_queue :: EventInfo :: add_before

Register an event that finishes before the begin of current one.
fun add_sync(event: E, delay: Float, duration: nullable Float): EventInfo[E]

event_queue :: EventInfo :: add_sync

Register an event that starts with the current one.
protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by get_class to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
fun completion: Float

event_queue :: EventInfo :: completion

Ratio of completion
protected fun completion=(completion: Float)

event_queue :: EventInfo :: completion=

Ratio of completion
fun dt: Float

event_queue :: EventInfo :: dt

Time since the last update (or the begin of the event if smaller)
protected fun dt=(dt: Float)

event_queue :: EventInfo :: dt=

Time since the last update (or the begin of the event if smaller)
fun duration: Float

event_queue :: EventInfo :: duration

Registered duration.
protected fun duration=(duration: Float)

event_queue :: EventInfo :: duration=

Registered duration.
fun event: E

event_queue :: EventInfo :: event

The registered event.
protected fun event=(event: E)

event_queue :: EventInfo :: event=

The registered event.
fun expire

event_queue :: EventInfo :: expire

Force the event to expire.
fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun has_expired: Bool

event_queue :: EventInfo :: has_expired

Has the event expired?
protected fun has_expired=(has_expired: Bool)

event_queue :: EventInfo :: has_expired=

Has the event expired?
fun hash: Int

core :: Object :: hash

The hash code of the object.
init init

core :: Object :: init

fun inspect: String

core :: Object :: inspect

Developer readable representation of self.
protected fun inspect_head: String

core :: Object :: inspect_head

Return "CLASSNAME:#OBJECTID".
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if self and other are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is self the same as other in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if self and other have the same dynamic type.
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun occurrences: Int

event_queue :: EventInfo :: occurrences

Number of times that an event was returned by update.
protected fun occurrences=(occurrences: Int)

event_queue :: EventInfo :: occurrences=

Number of times that an event was returned by update.
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
fun queue: EventQueue[E]

event_queue :: EventInfo :: queue

The associated event queue.
protected fun queue=(queue: EventQueue[E])

event_queue :: EventInfo :: queue=

The associated event queue.
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
fun start: Float

event_queue :: EventInfo :: start

Absolute start time for the registered event in the event queue time frame.
protected fun start=(start: Float)

event_queue :: EventInfo :: start=

Absolute start time for the registered event in the event queue time frame.
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
fun time: Float

event_queue :: EventInfo :: time

Time since the begin of the event, in units of time.
protected fun time=(time: Float)

event_queue :: EventInfo :: time=

Time since the begin of the event, in units of time.
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
package_diagram event_queue::EventInfo EventInfo core::Object Object event_queue::EventInfo->core::Object

Parents

interface Object

core :: Object

The root of the class hierarchy.

Class definitions

event_queue $ EventInfo
# Information and management about a registered event
#
# It allows to retrieve static and dynamic information about an event.
# It also allows to register other time-related events with a fluent programming way.
class EventInfo[E]
	# The registered event.
	var event: E

	# The associated event queue.
	#
	# It is used internally for fluent programming.
	var queue: EventQueue[E]

	# Absolute start time for the registered event in the event queue time frame.
	var start: Float

	# Registered duration.
	#
	# Events with a 0.0 duration are called *instant events*.
	var duration: Float

	# Time since the begin of the event, in units of time.
	var time: Float = nan

	# Time since the last update (or the begin of the event if smaller)
	#
	# Note that if the event has expired during the last time lapse,
	# then `dt` also counts the *expired* time between the expiration time
	# and the update time.
	var dt: Float = nan

	# Ratio of completion
	#
	# Usually between 0.0 and 1.
	# It might be > 1.0 if the event has expired during the last time lapse.
	var completion = 0.0

	# Number of times that an event was returned by `update`.
	#
	# If the event just started during the last update, 1 is returned.
	#
	# If the event was not returned by `update` yet, 0 is returned.
	var occurrences = 0

	# Has the event expired?
	#
	# Such an event will be not present in the next `update`.
	#
	# Note that an event can be `has_expired` and have `occurrences == 0` if it
	# is entirely included in the last time lapse.
	# It is especially the case for instant events.
	var has_expired = false

	## Fluent methods

	# Register an event that starts after the end of the current one.
	#
	# `delay` indicates the time between the end of the current event and the begin of the new one.
	# Use 0.0 if both events should be contiguous and not overlap.
	#
	# Returns the new event information that can be used in fluent programming.
	fun add_after(event: E, delay: Float, duration: nullable Float): EventInfo[E]
	do
		return queue.add_at(event, start + self.duration + delay, duration)
	end

	# Register an event that starts with the current one.
	#
	# `delay` indicates the time between the begin of the current event and the begin of the new one.
	# Use 0.0 if both events should start at the same time and overlaps.
	#
	# Returns the new event information that can be used in fluent programming.
	fun add_sync(event: E, delay: Float, duration: nullable Float): EventInfo[E]
	do
		return queue.add_at(event, start + delay, duration)
	end

	# Register an event that finishes before the begin of current one.
	#
	# `delay` indicates the time between the end of the new event and the begin of the current one.
	# Use 0.0 if both event should be contiguous and not overlap.
	#
	# Returns the new event information that can be used in fluent programming.
	fun add_before(event: E, delay: Float, duration: nullable Float): EventInfo[E]
	do
		duration = duration or else 0.0
		return queue.add_at(event, start - delay - duration, duration)
	end

	# Update attributes. Is called by `EventQueue::update`
	private fun update(queue_time, queue_dt: Float)
	do
		time = queue_time - start
		if time >= duration then expire
		dt = queue_dt.min(time)
		completion = time / duration
		occurrences += 1
	end

	# Force the event to expire.
	#
	# The event can be active of not.
	#
	# ~~~
	# var eq = new EventQueue[String]
	# var e1 = eq.add("active", 0.0, 10.0)
	# var e2 = eq.add("not active", 2.0, 10.0)
	# var es = eq.update(1.0)
	# assert es == [e1]
	# e1.expire
	# e2.expire
	# es = eq.update(2.0)
	# assert es.is_empty
	# ~~~
	#
	# Note that when an event is forced to expire,
	# it will not appears in the next `update`.
	fun expire do has_expired = true

	redef fun to_s do return "{event or else "null"}@{start}+{duration}"
end
lib/event_queue/event_queue.nit:257,1--377,3