Search in sources :

Example 1 with AssetLoader

use of com.badlogic.gdx.assets.loaders.AssetLoader in project libgdx by libgdx.

the class AssetManager method load.

/** Adds the given asset to the loading queue of the AssetManager.
	 * @param fileName the file name (interpretation depends on {@link AssetLoader})
	 * @param type the type of the asset.
	 * @param parameter parameters for the AssetLoader. */
public synchronized <T> void load(String fileName, Class<T> type, AssetLoaderParameters<T> parameter) {
    AssetLoader loader = getLoader(type, fileName);
    if (loader == null)
        throw new GdxRuntimeException("No loader for type: " + ClassReflection.getSimpleName(type));
    // reset stats
    if (loadQueue.size == 0) {
        loaded = 0;
        toLoad = 0;
        peakTasks = 0;
    }
    // check preload queue
    for (int i = 0; i < loadQueue.size; i++) {
        AssetDescriptor desc = loadQueue.get(i);
        if (desc.fileName.equals(fileName) && !desc.type.equals(type))
            throw new GdxRuntimeException("Asset with name '" + fileName + "' already in preload queue, but has different type (expected: " + ClassReflection.getSimpleName(type) + ", found: " + ClassReflection.getSimpleName(desc.type) + ")");
    }
    // check task list
    for (int i = 0; i < tasks.size(); i++) {
        AssetDescriptor desc = tasks.get(i).assetDesc;
        if (desc.fileName.equals(fileName) && !desc.type.equals(type))
            throw new GdxRuntimeException("Asset with name '" + fileName + "' already in task list, but has different type (expected: " + ClassReflection.getSimpleName(type) + ", found: " + ClassReflection.getSimpleName(desc.type) + ")");
    }
    // check loaded assets
    Class otherType = assetTypes.get(fileName);
    if (otherType != null && !otherType.equals(type))
        throw new GdxRuntimeException("Asset with name '" + fileName + "' already loaded, but has different type (expected: " + ClassReflection.getSimpleName(type) + ", found: " + ClassReflection.getSimpleName(otherType) + ")");
    toLoad++;
    AssetDescriptor assetDesc = new AssetDescriptor(fileName, type, parameter);
    loadQueue.add(assetDesc);
    log.debug("Queued: " + assetDesc);
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) AssetLoader(com.badlogic.gdx.assets.loaders.AssetLoader)

Example 2 with AssetLoader

use of com.badlogic.gdx.assets.loaders.AssetLoader in project libgdx by libgdx.

the class AssetManager method getLoader.

/** Returns the loader for the given type and the specified filename. If no loader exists for the specific filename, the default
	 * loader for that type is returned.
	 * @param type The type of the loader to get
	 * @param fileName The filename of the asset to get a loader for, or null to get the default loader
	 * @return The loader capable of loading the type and filename, or null if none exists */
public <T> AssetLoader getLoader(final Class<T> type, final String fileName) {
    final ObjectMap<String, AssetLoader> loaders = this.loaders.get(type);
    if (loaders == null || loaders.size < 1)
        return null;
    if (fileName == null)
        return loaders.get("");
    AssetLoader result = null;
    int l = -1;
    for (ObjectMap.Entry<String, AssetLoader> entry : loaders.entries()) {
        if (entry.key.length() > l && fileName.endsWith(entry.key)) {
            result = entry.value;
            l = entry.key.length();
        }
    }
    return result;
}
Also used : AssetLoader(com.badlogic.gdx.assets.loaders.AssetLoader) ObjectMap(com.badlogic.gdx.utils.ObjectMap)

Example 3 with AssetLoader

use of com.badlogic.gdx.assets.loaders.AssetLoader in project libgdx by libgdx.

the class AssetManager method addTask.

/** Adds a {@link AssetLoadingTask} to the task stack for the given asset.
	 * @param assetDesc */
private void addTask(AssetDescriptor assetDesc) {
    AssetLoader loader = getLoader(assetDesc.type, assetDesc.fileName);
    if (loader == null)
        throw new GdxRuntimeException("No loader for type: " + ClassReflection.getSimpleName(assetDesc.type));
    tasks.push(new AssetLoadingTask(this, assetDesc, loader, executor));
    peakTasks++;
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) AssetLoader(com.badlogic.gdx.assets.loaders.AssetLoader)

Aggregations

AssetLoader (com.badlogic.gdx.assets.loaders.AssetLoader)3 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)2 ObjectMap (com.badlogic.gdx.utils.ObjectMap)1