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;
}
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;
}
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;
}
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;
}
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);
}
}
Aggregations