Java 类com.badlogic.gdx.assets.loaders.AssetLoader 实例源码

项目:Quilly-s-Castle    文件:Utils.java   
private static <T, P extends AssetLoaderParameters<T>> void loadAsset(String filePath, Class<T> type, AssetLoader<T, P> loader) {
if (filePath == null || filePath.trim().isEmpty()) {
    Gdx.app.debug(TAG, "Trying to load a " + type.getSimpleName() + " with empty filePath");
    return;
}

if (fileResolver.resolve(filePath).exists()) {
    assetManager.setLoader(type, loader);
    assetManager.load(filePath, type);

    assetManager.finishLoading();
    Gdx.app.debug(TAG, type.getSimpleName() + " loaded: " + filePath);
} else {
    Gdx.app.debug(TAG, type.getSimpleName() + " does not exist: " + filePath);
}
   }
项目:fabulae    文件:LoaderUtil.java   
public static <T, P extends AssetLoaderParameters<T>> void handleImports(
        AssetLoader<T, P> loader, P parameter,
        @SuppressWarnings("rawtypes") Array<AssetDescriptor> dependencies, FileHandle parentFile,
        Element root) throws IOException {
    Array<Element> imports = root.getChildrenByName(XMLUtil.XML_IMPORT);
    for (Element singleImport : imports) {
        String filename = singleImport.get(XMLUtil.XML_FILENAME);
        FileHandle file = parentFile.parent().child(filename);
        if (!file.exists()) {
            throw new GdxRuntimeException("Import " + file.path()
                    + " from import for " + parentFile.name()
                    + " does not exist.");
        }
        dependencies.addAll(loader.getDependencies(filename, file, parameter));
    }
}
项目:libgdxcn    文件:FlameMain.java   
public <T> T load (String resource, Class<T> type, AssetLoader loader, AssetLoaderParameters<T> params) {   
    String resolvedPath = new String(resource).replaceAll("\\\\", "/");
    boolean exist = assetManager.isLoaded(resolvedPath, type);
    T oldAsset = null;
    if(exist){
        oldAsset = assetManager.get(resolvedPath, type);
        for(int i=assetManager.getReferenceCount(resolvedPath); i > 0; --i)
            assetManager.unload(resolvedPath);
    }

    AssetLoader<T, AssetLoaderParameters<T>> currentLoader = assetManager.getLoader(type);
    if(loader != null)
        assetManager.setLoader(type, loader); 

    assetManager.load(resource, type, params);
    assetManager.finishLoading();
    T res = assetManager.get(resolvedPath);
    if(currentLoader != null)
        assetManager.setLoader(type, currentLoader);

    if(exist)
        EventManager.get().fire(EVT_ASSET_RELOADED, new Object[]{oldAsset, res});

    return res;
}
项目:CodeBase    文件:AssetManagerX.java   
private <T> String prefixFilename(Class<T> clazz, String filename) {
    AssetLoader loader = getLoader(clazz);
    if (loader instanceof AsynchronousAssetLoaderX) {
        AsynchronousAssetLoaderX loaderX = (AsynchronousAssetLoaderX) loader;
        return loaderX.getFilePrefix() + filename;
    }
    return filename;
}
项目:libgdxcn    文件:AssetManager.java   
/** 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;
}
项目:libgdxcn    文件:AssetManager.java   
/** Sets a new {@link AssetLoader} for the given type.
 * @param type the type of the asset
 * @param suffix the suffix the filename must have for this loader to be used or null to specify the default loader.
 * @param loader the loader */
public synchronized <T, P extends AssetLoaderParameters<T>> void setLoader (Class<T> type, String suffix,
    AssetLoader<T, P> loader) {
    if (type == null) throw new IllegalArgumentException("type cannot be null.");
    if (loader == null) throw new IllegalArgumentException("loader cannot be null.");
    log.debug("Loader set: " + ClassReflection.getSimpleName(type) + " -> " + ClassReflection.getSimpleName(loader.getClass()));
    ObjectMap<String, AssetLoader> loaders = this.loaders.get(type);
    if (loaders == null) this.loaders.put(type, loaders = new ObjectMap<String, AssetLoader>());
    loaders.put(suffix == null ? "" : suffix, loader);
}
项目:libgdxcn    文件:AssetLoadingTask.java   
public AssetLoadingTask (AssetManager manager, AssetDescriptor assetDesc, AssetLoader loader, AsyncExecutor threadPool) {
    this.manager = manager;
    this.assetDesc = assetDesc;
    this.loader = loader;
    this.executor = threadPool;
    startTime = manager.log.getLevel() == Logger.DEBUG ? TimeUtils.nanoTime() : 0;
}
项目:ingress-indonesia-dev    文件:AssetManager.java   
private void addTask(AssetDescriptor paramAssetDescriptor)
{
  AssetLoader localAssetLoader = (AssetLoader)this.loaders.get(paramAssetDescriptor.type);
  if (localAssetLoader == null)
    throw new GdxRuntimeException("No loader for type: " + paramAssetDescriptor.type.getSimpleName());
  this.tasks.push(new AssetLoadingTask(this, paramAssetDescriptor, localAssetLoader, this.threadPool));
}
项目:ingress-indonesia-dev    文件:AssetManager.java   
public <T, P extends AssetLoaderParameters<T>> void setLoader(Class<T> paramClass, AssetLoader<T, P> paramAssetLoader)
{
  if (paramClass == null)
    try
    {
      throw new IllegalArgumentException("type cannot be null.");
    }
    finally
    {
    }
  if (paramAssetLoader == null)
    throw new IllegalArgumentException("loader cannot be null.");
  this.log.debug("Loader set: " + paramClass.getSimpleName() + " -> " + paramAssetLoader.getClass().getSimpleName());
  this.loaders.put(paramClass, paramAssetLoader);
}
项目:ingress-indonesia-dev    文件:AssetLoadingTask.java   
public AssetLoadingTask(AssetManager paramAssetManager, AssetDescriptor paramAssetDescriptor, AssetLoader paramAssetLoader, ExecutorService paramExecutorService)
{
  this.manager = paramAssetManager;
  this.assetDesc = paramAssetDescriptor;
  this.loader = paramAssetLoader;
  this.threadPool = paramExecutorService;
  if (paramAssetManager.log.getLevel() == 3);
  for (long l = TimeUtils.nanoTime(); ; l = 0L)
  {
    this.startTime = l;
    return;
  }
}
项目:gdx-lml    文件:AssetService.java   
/** @param loader asset loader for the selected type. Will be registered in all managed {@link AssetManager}
 *            instances.
 * @param assetClass class of the loaded asset.
 * @see AssetManager#setLoader(Class, AssetLoader)
 * @param <Type> type of registered loader. */
public <Type> void registerLoader(final AssetLoader<Type, AssetLoaderParameters<Type>> loader,
        final Class<Type> assetClass) {
    assetManager.setLoader(assetClass, loader);
    eagerAssetManager.setLoader(assetClass, loader);
}
项目:sioncore    文件:Assets.java   
public AssetLoader<?, ?> getLoader(Class<?> type) {
    return manager.getLoader(type);
}
项目:libgdxcn    文件:AssetManager.java   
/** Returns the default loader for the given type
 * @param type The type of the loader to get
 * @return The loader capable of loading the type, or null if none exists */
public <T> AssetLoader getLoader (final Class<T> type) {
    return getLoader(type, null);
}
项目:libgdxcn    文件:AssetManager.java   
/** 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));
}
项目:libgdxcn    文件:AssetManager.java   
/** Sets a new {@link AssetLoader} for the given type.
 * @param type the type of the asset
 * @param loader the loader */
public synchronized <T, P extends AssetLoaderParameters<T>> void setLoader (Class<T> type, AssetLoader<T, P> loader) {
    setLoader(type, null, loader);
}
项目:libgdxcn    文件:AssetLoadingTask.java   
private FileHandle resolve (AssetLoader loader, AssetDescriptor assetDesc) {
    if (assetDesc.file == null) assetDesc.file = loader.resolve(assetDesc.fileName);
    return assetDesc.file;
}
项目:ingress-indonesia-dev    文件:AssetManager.java   
public <T> void load(String paramString, Class<T> paramClass, AssetLoaderParameters<T> paramAssetLoaderParameters)
{
  try
  {
    if ((AssetLoader)this.loaders.get(paramClass) == null)
      throw new GdxRuntimeException("No loader for type: " + paramClass.getSimpleName());
  }
  finally
  {
  }
  int k;
  int i;
  if (this.loadQueue.size == 0)
  {
    this.loaded = 0;
    this.toLoad = 0;
    break label449;
    int j = this.loadQueue.size;
    k = 0;
    if (i < j)
    {
      AssetDescriptor localAssetDescriptor1 = (AssetDescriptor)this.loadQueue.get(i);
      if ((!localAssetDescriptor1.fileName.equals(paramString)) || (localAssetDescriptor1.type.equals(paramClass)))
        break label455;
      throw new GdxRuntimeException("Asset with name '" + paramString + "' already in preload queue, but has different type (expected: " + paramClass.getSimpleName() + ", found: " + localAssetDescriptor1.type.getSimpleName() + ")");
    }
  }
  while (true)
  {
    if (k < this.tasks.size())
    {
      AssetDescriptor localAssetDescriptor3 = ((AssetLoadingTask)this.tasks.get(k)).assetDesc;
      if ((localAssetDescriptor3.fileName.equals(paramString)) && (!localAssetDescriptor3.type.equals(paramClass)))
        throw new GdxRuntimeException("Asset with name '" + paramString + "' already in task list, but has different type (expected: " + paramClass.getSimpleName() + ", found: " + localAssetDescriptor3.type.getSimpleName() + ")");
    }
    else
    {
      Class localClass = (Class)this.assetTypes.get(paramString);
      if ((localClass != null) && (!localClass.equals(paramClass)))
        throw new GdxRuntimeException("Asset with name '" + paramString + "' already loaded, but has different type (expected: " + paramClass.getSimpleName() + ", found: " + localClass.getSimpleName() + ")");
      this.toLoad = (1 + this.toLoad);
      AssetDescriptor localAssetDescriptor2 = new AssetDescriptor(paramString, paramClass, paramAssetLoaderParameters);
      this.loadQueue.add(localAssetDescriptor2);
      this.log.debug("Queued: " + localAssetDescriptor2);
      return;
      label449: i = 0;
      break;
      label455: i++;
      break;
    }
    k++;
  }
}
项目:gdx-lml    文件:AssetService.java   
/** @param loader asset loader for the selected type. Will be registered in all managed {@link AssetManager}
 *            instances.
 * @param suffix allows to filter files.
 * @param assetClass class of the loaded asset.
 * @see AssetManager#setLoader(Class, String, AssetLoader)
 * @param <Type> type of registered loader. */
public <Type> void registerLoader(final AssetLoader<Type, AssetLoaderParameters<Type>> loader, final String suffix,
        final Class<Type> assetClass) {
    assetManager.setLoader(assetClass, suffix, loader);
    eagerAssetManager.setLoader(assetClass, suffix, loader);
}
项目:ead    文件:Assets.java   
/**
 * Sets a new {@link com.badlogic.gdx.assets.loaders.AssetLoader} for the
 * given type. This is needed for any object type that can be stored to and
 * loaded from a file (e.g. scene.json, game.json). Otherwise Assets does
 * not know how to load the file and convert it to an object of the model.
 * 
 * @param type
 *            the type of the asset
 * @param loader
 *            the loader
 */
public synchronized <T, P extends AssetLoaderParameters<T>> void setLoader(
        Class<T> type, AssetLoader<T, P> loader) {
    assetManager.setLoader(type, loader);
}