Search in sources :

Example 41 with Array

use of com.badlogic.gdx.utils.Array in project libgdx by libgdx.

the class MaxRectsPacker method pack.

public Array<Page> pack(Array<Rect> inputRects) {
    for (int i = 0, nn = inputRects.size; i < nn; i++) {
        Rect rect = inputRects.get(i);
        rect.width += settings.paddingX;
        rect.height += settings.paddingY;
    }
    if (settings.fast) {
        if (settings.rotation) {
            // Sort by longest side if rotation is enabled.
            sort.sort(inputRects, new Comparator<Rect>() {

                public int compare(Rect o1, Rect o2) {
                    int n1 = o1.width > o1.height ? o1.width : o1.height;
                    int n2 = o2.width > o2.height ? o2.width : o2.height;
                    return n2 - n1;
                }
            });
        } else {
            // Sort only by width (largest to smallest) if rotation is disabled.
            sort.sort(inputRects, new Comparator<Rect>() {

                public int compare(Rect o1, Rect o2) {
                    return o2.width - o1.width;
                }
            });
        }
    }
    Array<Page> pages = new Array();
    while (inputRects.size > 0) {
        Page result = packPage(inputRects);
        pages.add(result);
        inputRects = result.remainingRects;
    }
    return pages;
}
Also used : Array(com.badlogic.gdx.utils.Array) Rect(com.badlogic.gdx.tools.texturepacker.TexturePacker.Rect) Page(com.badlogic.gdx.tools.texturepacker.TexturePacker.Page)

Example 42 with Array

use of com.badlogic.gdx.utils.Array in project libgdx by libgdx.

the class ModelLoader method getDependencies.

@Override
public Array<AssetDescriptor> getDependencies(String fileName, FileHandle file, P parameters) {
    final Array<AssetDescriptor> deps = new Array();
    ModelData data = loadModelData(file, parameters);
    if (data == null)
        return deps;
    ObjectMap.Entry<String, ModelData> item = new ObjectMap.Entry<String, ModelData>();
    item.key = fileName;
    item.value = data;
    synchronized (items) {
        items.add(item);
    }
    TextureLoader.TextureParameter textureParameter = (parameters != null) ? parameters.textureParameter : defaultParameters.textureParameter;
    for (final ModelMaterial modelMaterial : data.materials) {
        if (modelMaterial.textures != null) {
            for (final ModelTexture modelTexture : modelMaterial.textures) deps.add(new AssetDescriptor(modelTexture.fileName, Texture.class, textureParameter));
        }
    }
    return deps;
}
Also used : Array(com.badlogic.gdx.utils.Array) ModelData(com.badlogic.gdx.graphics.g3d.model.data.ModelData) ObjectMap(com.badlogic.gdx.utils.ObjectMap) ModelMaterial(com.badlogic.gdx.graphics.g3d.model.data.ModelMaterial) AssetDescriptor(com.badlogic.gdx.assets.AssetDescriptor) ModelTexture(com.badlogic.gdx.graphics.g3d.model.data.ModelTexture)

Example 43 with Array

use of com.badlogic.gdx.utils.Array in project libgdx by libgdx.

the class ParticleEffectLoader method getDependencies.

@Override
public Array<AssetDescriptor> getDependencies(String fileName, FileHandle file, ParticleEffectParameter param) {
    Array<AssetDescriptor> deps = null;
    if (param != null && param.atlasFile != null) {
        deps = new Array();
        deps.add(new AssetDescriptor<TextureAtlas>(param.atlasFile, TextureAtlas.class));
    }
    return deps;
}
Also used : Array(com.badlogic.gdx.utils.Array) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) AssetDescriptor(com.badlogic.gdx.assets.AssetDescriptor)

Example 44 with Array

use of com.badlogic.gdx.utils.Array in project libgdx by libgdx.

the class TextureAtlasLoader method getDependencies.

@Override
public Array<AssetDescriptor> getDependencies(String fileName, FileHandle atlasFile, TextureAtlasParameter parameter) {
    FileHandle imgDir = atlasFile.parent();
    if (parameter != null)
        data = new TextureAtlasData(atlasFile, imgDir, parameter.flip);
    else {
        data = new TextureAtlasData(atlasFile, imgDir, false);
    }
    Array<AssetDescriptor> dependencies = new Array();
    for (Page page : data.getPages()) {
        TextureParameter params = new TextureParameter();
        params.format = page.format;
        params.genMipMaps = page.useMipMaps;
        params.minFilter = page.minFilter;
        params.magFilter = page.magFilter;
        dependencies.add(new AssetDescriptor(page.textureFile, Texture.class, params));
    }
    return dependencies;
}
Also used : Array(com.badlogic.gdx.utils.Array) TextureAtlasData(com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData) FileHandle(com.badlogic.gdx.files.FileHandle) Page(com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData.Page) TextureParameter(com.badlogic.gdx.assets.loaders.TextureLoader.TextureParameter) Texture(com.badlogic.gdx.graphics.Texture) AssetDescriptor(com.badlogic.gdx.assets.AssetDescriptor)

Example 45 with Array

use of com.badlogic.gdx.utils.Array in project libgdx by libgdx.

the class Texture method invalidateAllTextures.

/** Invalidate all managed textures. This is an internal method. Do not use it! */
public static void invalidateAllTextures(Application app) {
    Array<Texture> managedTextureArray = managedTextures.get(app);
    if (managedTextureArray == null)
        return;
    if (assetManager == null) {
        for (int i = 0; i < managedTextureArray.size; i++) {
            Texture texture = managedTextureArray.get(i);
            texture.reload();
        }
    } else {
        // first we have to make sure the AssetManager isn't loading anything anymore,
        // otherwise the ref counting trick below wouldn't work (when a texture is
        // currently on the task stack of the manager.)
        assetManager.finishLoading();
        // next we go through each texture and reload either directly or via the
        // asset manager.
        Array<Texture> textures = new Array<Texture>(managedTextureArray);
        for (Texture texture : textures) {
            String fileName = assetManager.getAssetFileName(texture);
            if (fileName == null) {
                texture.reload();
            } else {
                // get the ref count of the texture, then set it to 0 so we
                // can actually remove it from the assetmanager. Also set the
                // handle to zero, otherwise we might accidentially dispose
                // already reloaded textures.
                final int refCount = assetManager.getReferenceCount(fileName);
                assetManager.setReferenceCount(fileName, 0);
                texture.glHandle = 0;
                // create the parameters, passing the reference to the texture as
                // well as a callback that sets the ref count.
                TextureParameter params = new TextureParameter();
                params.textureData = texture.getTextureData();
                params.minFilter = texture.getMinFilter();
                params.magFilter = texture.getMagFilter();
                params.wrapU = texture.getUWrap();
                params.wrapV = texture.getVWrap();
                // not sure about this?
                params.genMipMaps = texture.data.useMipMaps();
                // special parameter which will ensure that the references stay the same.
                params.texture = texture;
                params.loadedCallback = new LoadedCallback() {

                    @Override
                    public void finishedLoading(AssetManager assetManager, String fileName, Class type) {
                        assetManager.setReferenceCount(fileName, refCount);
                    }
                };
                // unload the texture, create a new gl handle then reload it.
                assetManager.unload(fileName);
                texture.glHandle = Gdx.gl.glGenTexture();
                assetManager.load(fileName, Texture.class, params);
            }
        }
        managedTextureArray.clear();
        managedTextureArray.addAll(textures);
    }
}
Also used : Array(com.badlogic.gdx.utils.Array) LoadedCallback(com.badlogic.gdx.assets.AssetLoaderParameters.LoadedCallback) AssetManager(com.badlogic.gdx.assets.AssetManager) TextureParameter(com.badlogic.gdx.assets.loaders.TextureLoader.TextureParameter)

Aggregations

Array (com.badlogic.gdx.utils.Array)67 FileHandle (com.badlogic.gdx.files.FileHandle)18 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)16 AssetDescriptor (com.badlogic.gdx.assets.AssetDescriptor)9 Texture (com.badlogic.gdx.graphics.Texture)8 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)7 IntArray (com.badlogic.gdx.utils.IntArray)7 Element (com.badlogic.gdx.utils.XmlReader.Element)7 IOException (java.io.IOException)7 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)5 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)5 JsonValue (com.badlogic.gdx.utils.JsonValue)5 ObjectMap (com.badlogic.gdx.utils.ObjectMap)5 Color (com.badlogic.gdx.graphics.Color)4 ModelMaterial (com.badlogic.gdx.graphics.g3d.model.data.ModelMaterial)4 Page (com.badlogic.gdx.tools.texturepacker.TexturePacker.Page)4 Rect (com.badlogic.gdx.tools.texturepacker.TexturePacker.Rect)4 Json (com.badlogic.gdx.utils.Json)4 TextureParameter (com.badlogic.gdx.assets.loaders.TextureLoader.TextureParameter)3 GwtFileHandle (com.badlogic.gdx.backends.gwt.GwtFileHandle)3