Class SafePools

java.lang.Object
com.prineside.tdi2.utils.SafePools

public final class SafePools extends Object
Thread-safe version of GDX's Pools Why thread safe: - Some events (like LogEntryAdd) may be triggered on a different threads - Multiple gameStates can be simulated on a different threads at the same time
  • Method Details

    • getInstance

      public static SafePools getInstance()
    • create

      public <T> SafePools.Pool<T> create(int initial, int max, ObjectSupplier<T> provider)
      Returns:
      RegularPool or a simple instantiator depending on the Engine's config
    • get

      public <T> SafePools.Pool<T> get(Class<T> type, int max)
    • get

      public <T> SafePools.Pool<T> get(Class<T> type)
      Returns a new or existing pool for the specified type, stored in a Class to SafePools.Pool map. The max size of the pool used is 100.
    • set

      public <T> void set(Class<T> type, SafePools.Pool<T> pool)
      Sets an existing pool for the specified type, stored in a Class to SafePools.Pool map.
    • obtain

      public <T> T obtain(Class<T> type)
      Obtains an object from the pool.
    • free

      public void free(Object object)
      Frees an object from the pool.
    • freeAll

      public void freeAll(com.badlogic.gdx.utils.Array objects)
      Frees the specified objects from the pool. Null objects within the array are silently ignored. Objects don't need to be from the same pool.
    • freeAll

      public void freeAll(com.badlogic.gdx.utils.Array objects, boolean samePool)
      Frees the specified objects from the pool. Null objects within the array are silently ignored.
      Parameters:
      samePool - If true, objects don't need to be from the same pool but the pool must be looked up for each object.