Source: prepare/limiters/CountLimiter.js

prepare/limiters/CountLimiter.js

  1. /**
  2. * CountLimiter limits the number of items handled by a {@link PIXI.prepare.BasePrepare} to a specified
  3. * number of items per frame.
  4. *
  5. * @class
  6. * @memberof PIXI
  7. */
  8. export default class CountLimiter
  9. {
  10. /**
  11. * @param {number} maxItemsPerFrame - The maximum number of items that can be prepared each frame.
  12. */
  13. constructor(maxItemsPerFrame)
  14. {
  15. /**
  16. * The maximum number of items that can be prepared each frame.
  17. * @private
  18. */
  19. this.maxItemsPerFrame = maxItemsPerFrame;
  20. /**
  21. * The number of items that can be prepared in the current frame.
  22. * @type {number}
  23. * @private
  24. */
  25. this.itemsLeft = 0;
  26. }
  27. /**
  28. * Resets any counting properties to start fresh on a new frame.
  29. */
  30. beginFrame()
  31. {
  32. this.itemsLeft = this.maxItemsPerFrame;
  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 this.itemsLeft-- > 0;
  41. }
  42. }