Class InstanceRecycler<I extends Instance>

java.lang.Object
dev.engine_room.flywheel.lib.visual.util.InstanceRecycler<I>
Type Parameters:
I - The type of instance to recycle.

public final class InstanceRecycler<I extends Instance> extends Object
A utility for recycling instances.
If the exact number of instances you need each frame is unknown, you can use this to manage a pool of instances that will be dynamically created, deleted, or re-used as necessary.
  • Constructor Details

    • InstanceRecycler

      public InstanceRecycler(Supplier<I> factory)
  • Method Details

    • resetCount

      public void resetCount()
      Reset the count of instances.
      Call this at before your first call to get() each frame.
    • get

      public I get()
      Get the next instance in the pool, creating a new one if necessary.
      The returned instance may not be in its default state.
      Returns:
      The next instance in the pool.
    • discardExtra

      public void discardExtra()
      Delete any instances that were not used this frame.
      Call this after your last call to get() each frame.
    • delete

      public void delete()