You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

event-queue.js 906B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /**
  2. * -------------------------------------------
  3. * Magic AR Basketball
  4. * A demo game of the encantar.js WebAR engine
  5. * -------------------------------------------
  6. * @fileoverview Event queue
  7. * @author Alexandre Martins <alemartf(at)gmail.com> (https://github.com/alemart/encantar-js)
  8. */
  9. import { GameEvent } from './events.js';
  10. /**
  11. * Event queue
  12. */
  13. export class EventQueue
  14. {
  15. /**
  16. * Constructor
  17. */
  18. constructor()
  19. {
  20. this._events = /** @type {GameEvent[]} */ ( [] );
  21. }
  22. /**
  23. * Enqueue an event
  24. * @param {GameEvent} event
  25. * @returns {void}
  26. */
  27. enqueue(event)
  28. {
  29. this._events.push(event);
  30. }
  31. /**
  32. * Removes and returns the first event from the queue
  33. * If the queue is empty, null is returned instead
  34. * @returns {GameEvent|null}
  35. */
  36. dequeue()
  37. {
  38. return this._events.shift() || null;
  39. }
  40. }