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 void
addListener
(AssetPoolEventType assetPoolEventType, EventListener<AssetPoolEvent<T>> listener) int
count()
Returns the number of assets in this pool.protected abstract T
createAsset
(String path) Creates a new asset from a normalized path.protected String
void
destroy()
Destroys all assets in this pool and removes them.protected T
Utility method for marking the asset creation as failed.protected T
Utility method for marking the asset creation as failed.protected final Collection
<T> Returns the assets stored in this pool.protected T
Loads an asset from a path or retrieves it from the pool if it has already been loaded once.protected String
Normalizes a path.protected void
Prepares this pool for the next asset.void
void
protected boolean
Removes an asset from this pool.boolean
Removes an asset from this pool.final void
removeListener
(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
null
if 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
null
if 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:
false
ifpath
does not match any asset in this pool.
-
remove
Removes an asset from this pool.- Parameters:
path
- The path of the asset to remove- Returns:
false
ifpath
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 interfaceDestructible
-
count
public int count()Returns the number of assets in this pool.- Returns:
- The number of assets in this pool.
-
createKey
-
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)
-