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
Base class for pools of assets.
Pools manage asset loading efficiently by avoiding loading assets multiple times.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidaddListener(AssetPoolEventType assetPoolEventType, EventListener<AssetPoolEvent<T>> listener) intcount()Returns the number of assets in this pool.protected abstract TcreateAsset(String path) Creates a new asset from a normalized path.protected StringCreates a key for the current asset.voiddestroy()Destroys all assets in this pool and removes them.protected TUtility method for marking the asset creation as failed.protected TUtility method for marking the asset creation as failed.protected final Collection<T> Returns the assets stored in this pool.protected TLoads an asset from a path or retrieves it from the pool if it has already been loaded once.protected StringNormalizes a path.protected voidPrepares this pool for the next asset.voidvoidprotected booleanRemoves an asset from this pool.booleanRemoves an asset from this pool.final voidremoveListener(AssetPoolEventType assetPoolEventType, EventListener<AssetPoolEvent<T>> listener)
-
Field Details
-
eventDispatcher
-
-
Constructor Details
-
AssetPool
public AssetPool()
-
-
Method Details
-
load
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
nullif it failed to load.
-
prepareNext
protected void prepareNext()Prepares this pool for the next asset. -
createAsset
Creates a new asset from a normalized path.- Parameters:
path- The normalized path- Returns:
- The new asset, or
nullif the asset creation failed.
-
fail
Utility method for marking the asset creation as failed.- Parameters:
reason- The reason of the failure- Returns:
null
-
fail
Utility method for marking the asset creation as failed.- Parameters:
reason- The reason of the failure- Returns:
null
-
getAssets
Returns the assets stored in this pool.- Returns:
- The assets stored in this pool.
-
remove
Removes an asset from this pool.- Parameters:
asset- The asset to remove- Returns:
falseifpathdoes not match any asset in this pool.
-
remove
Removes an asset from this pool.- Parameters:
path- The path of the asset to remove- Returns:
falseifpathdoes not match any asset in this pool.
-
destroy
public void destroy()Destroys all assets in this pool and removes them.- Specified by:
destroyin interfaceDestructible
-
count
public int count()Returns the number of assets in this pool.- Returns:
- The number of assets in this pool.
-
createKey
Creates a key for the current asset.- Parameters:
path- The normalized path of the asset- Returns:
- The new key.
-
normalize
Normalizes a path.- Parameters:
path- The path- Returns:
- The normalized path.
-
printInfo
public void printInfo() -
printInfo
-
addListener
public final void addListener(AssetPoolEventType assetPoolEventType, EventListener<AssetPoolEvent<T>> listener) -
removeListener
public final void removeListener(AssetPoolEventType assetPoolEventType, EventListener<AssetPoolEvent<T>> listener)
-