Class AssetPool<T extends Asset>

java.lang.Object
dev.prozilla.pine.common.asset.pool.AssetPool<T>
Type Parameters:
T - The type of assets in this pool
All Implemented Interfaces:
Destructible
Direct Known Subclasses:
AudioSourcePool, FontPool, ImagePool, TextAssetPool, TexturePool

public abstract class AssetPool<T extends Asset> extends Object implements Destructible
Base class for pools of assets. Pools manage asset loading efficiently by avoiding loading assets multiple times.
  • Field Details

  • Constructor Details

    • AssetPool

      public AssetPool()
  • Method Details

    • load

      protected T load(String path)
      Loads an asset from a path or retrieves it from the pool if it has already been loaded once.

      This method is protected because some subclasses may require additional parameters to load an asset.

      Parameters:
      path - The path of the asset
      Returns:
      The asset, or null if it failed to load.
    • prepareNext

      protected void prepareNext()
      Prepares this pool for the next asset.
    • createAsset

      protected abstract T createAsset(String path)
      Creates a new asset from a normalized path.
      Parameters:
      path - The normalized path
      Returns:
      The new asset, or null if the asset creation failed.
    • fail

      protected T fail(String path, String reason)
      Utility method for marking the asset creation as failed.
      Parameters:
      reason - The reason of the failure
      Returns:
      null
    • fail

      protected T fail(String path, String reason, Exception exception)
      Utility method for marking the asset creation as failed.
      Parameters:
      reason - The reason of the failure
      Returns:
      null
    • getAssets

      protected final Collection<T> getAssets()
      Returns the assets stored in this pool.
      Returns:
      The assets stored in this pool.
    • remove

      public boolean remove(T asset)
      Removes an asset from this pool.
      Parameters:
      asset - The asset to remove
      Returns:
      false if path does not match any asset in this pool.
    • remove

      protected boolean remove(String path)
      Removes an asset from this pool.
      Parameters:
      path - The path of the asset to remove
      Returns:
      false if path does not match any asset in this pool.
    • destroy

      public void destroy()
      Destroys all assets in this pool and removes them.
      Specified by:
      destroy in interface Destructible
    • count

      public int count()
      Returns the number of assets in this pool.
      Returns:
      The number of assets in this pool.
    • createKey

      protected String createKey(String path)
    • normalize

      protected String normalize(String path)
      Normalizes a path.
      Parameters:
      path - The path
      Returns:
      The normalized path.
    • printInfo

      public void printInfo()
    • printInfo

      public void printInfo(Logger logger)
    • addListener

      public final void addListener(AssetPoolEventType assetPoolEventType, EventListener<AssetPoolEvent<T>> listener)
    • removeListener

      public final void removeListener(AssetPoolEventType assetPoolEventType, EventListener<AssetPoolEvent<T>> listener)