Source: prepare/limiters/TimeLimiter.js

prepare/limiters/TimeLimiter.js

  1. /**
  2. * TimeLimiter limits the number of items handled by a {@link PIXI.BasePrepare} to a specified
  3. * number of milliseconds per frame.
  4. *
  5. * @class
  6. * @memberof PIXI
  7. */
  8. export default class TimeLimiter
  9. {
  10. /**
  11. * @param {number} maxMilliseconds - The maximum milliseconds that can be spent preparing items each frame.
  12. */
  13. constructor(maxMilliseconds)
  14. {
  15. /**
  16. * The maximum milliseconds that can be spent preparing items each frame.
  17. * @private
  18. */
  19. this.maxMilliseconds = maxMilliseconds;
  20. /**
  21. * The start time of the current frame.
  22. * @type {number}
  23. * @private
  24. */
  25. this.frameStart = 0;
  26. }
  27. /**
  28. * Resets any counting properties to start fresh on a new frame.
  29. */
  30. beginFrame()
  31. {
  32. this.frameStart = Date.now();
  33. }
  34. /**
  35. * Checks to see if another item can be uploaded. This should only be called once per item.
  36. * @return {boolean} If the item is allowed to be uploaded.
  37. */
  38. allowedToUpload()
  39. {
  40. return Date.now() - this.frameStart < this.maxMilliseconds;
  41. }
  42. }