API Reference

A priority queue scheduler for use in game development.

See the queued turns time system: http://www.roguebasin.com/index.php?title=Time_Systems#Queued_turns

class turnq.Ticket(time: int, uid: int, value: T, insert_time: int)

Describes a scheduled object.

get_progress(current_time: int) float

Return the current progress of this Ticket as a float from 0 to 1.

get_time_left(current_time: int) int

Return the amount of time until this Ticket is triggered.

get_time_passed(current_time: int) int

Return the amount of time passed since this Ticket was initially scheduled.

insert_time: int

The time this ticket was inserted into the scheduler.

This can be used to get the delta time of this Ticket with time - insert_time or some equivalent.

time: int

The time this Ticket will be returned from the scheduler.

uid: int

A unique number which enforces FIFO ordering of tickets with the same time.

value: T

The scheduled object.

class turnq.TurnQueue(time: int = 0, next_uid: int = 0, heap: list[Ticket[T]] = <factory>)

Turned queue manager.

heap: list[Ticket[T]]

A min-heap queue of events maintained by Python’s heapq module.

next_uid: int = 0

Incrementing unique id used to enforce FIFO order on tickets.

peek() Ticket[T]

Return the next scheduled ticket without removing it.

IndexError will be raised if the heap is empty.

pop() Ticket[T]

Pop and return the next scheduled Ticket from the queue.

This will set TurnQueue.time to the tickets current time.

schedule(interval: int, value: T) Ticket[T]

Schedule value to be returned after internal time passes.

Returns the new Ticket associated with the scheduled value.

time: int = 0

The current tick. Always the time of the most recently popped ticket.