Search in sources :

Example 66 with GdxRuntimeException

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

the class FileHandle method list.

/** Returns the paths to the children of this directory that satisfy the specified filter. Returns an empty list if this file
	 * handle represents a file and not a directory. On the desktop, an {@link FileType#Internal} handle to a directory on the
	 * classpath will return a zero length array.
	 * @param filter the {@link FileFilter} to filter files
	 * @throws GdxRuntimeException if this file is an {@link FileType#Classpath} file. */
public FileHandle[] list(FileFilter filter) {
    if (type == FileType.Classpath)
        throw new GdxRuntimeException("Cannot list a classpath directory: " + file);
    File file = file();
    String[] relativePaths = file.list();
    if (relativePaths == null)
        return new FileHandle[0];
    FileHandle[] handles = new FileHandle[relativePaths.length];
    int count = 0;
    for (int i = 0, n = relativePaths.length; i < n; i++) {
        String path = relativePaths[i];
        FileHandle child = child(path);
        if (!filter.accept(child.file()))
            continue;
        handles[count] = child;
        count++;
    }
    if (count < relativePaths.length) {
        FileHandle[] newHandles = new FileHandle[count];
        System.arraycopy(handles, 0, newHandles, 0, count);
        handles = newHandles;
    }
    return handles;
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) File(java.io.File)

Example 67 with GdxRuntimeException

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

the class Pixmap method dispose.

/** Releases all resources associated with this Pixmap. */
public void dispose() {
    if (disposed)
        throw new GdxRuntimeException("Pixmap already disposed!");
    pixmap.dispose();
    disposed = true;
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException)

Example 68 with GdxRuntimeException

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

the class Texture method load.

public void load(TextureData data) {
    if (this.data != null && data.isManaged() != this.data.isManaged())
        throw new GdxRuntimeException("New data must have the same managed status as the old data");
    this.data = data;
    if (!data.isPrepared())
        data.prepare();
    bind();
    uploadImageData(GL20.GL_TEXTURE_2D, data);
    setFilter(minFilter, magFilter);
    setWrap(uWrap, vWrap);
    Gdx.gl.glBindTexture(glTarget, 0);
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException)

Example 69 with GdxRuntimeException

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

the class Texture method reload.

/** Used internally to reload after context loss. Creates a new GL handle then calls {@link #load(TextureData)}. Use this only
	 * if you know what you do! */
@Override
protected void reload() {
    if (!isManaged())
        throw new GdxRuntimeException("Tried to reload unmanaged Texture");
    glHandle = Gdx.gl.glGenTexture();
    load(data);
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException)

Example 70 with GdxRuntimeException

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

the class Mesh method calculateRadiusSquared.

/** Calculates the squared radius of the bounding sphere around the specified center for the specified part.
	 * @param centerX The X coordinate of the center of the bounding sphere
	 * @param centerY The Y coordinate of the center of the bounding sphere
	 * @param centerZ The Z coordinate of the center of the bounding sphere
	 * @param offset the start index of the part.
	 * @param count the amount of indices the part contains.
	 * @return the squared radius of the bounding sphere. */
public float calculateRadiusSquared(final float centerX, final float centerY, final float centerZ, int offset, int count, final Matrix4 transform) {
    int numIndices = getNumIndices();
    if (offset < 0 || count < 1 || offset + count > numIndices)
        throw new GdxRuntimeException("Not enough indices");
    final FloatBuffer verts = vertices.getBuffer();
    final ShortBuffer index = indices.getBuffer();
    final VertexAttribute posAttrib = getVertexAttribute(Usage.Position);
    final int posoff = posAttrib.offset / 4;
    final int vertexSize = vertices.getAttributes().vertexSize / 4;
    final int end = offset + count;
    float result = 0;
    switch(posAttrib.numComponents) {
        case 1:
            for (int i = offset; i < end; i++) {
                final int idx = index.get(i) * vertexSize + posoff;
                tmpV.set(verts.get(idx), 0, 0);
                if (transform != null)
                    tmpV.mul(transform);
                final float r = tmpV.sub(centerX, centerY, centerZ).len2();
                if (r > result)
                    result = r;
            }
            break;
        case 2:
            for (int i = offset; i < end; i++) {
                final int idx = index.get(i) * vertexSize + posoff;
                tmpV.set(verts.get(idx), verts.get(idx + 1), 0);
                if (transform != null)
                    tmpV.mul(transform);
                final float r = tmpV.sub(centerX, centerY, centerZ).len2();
                if (r > result)
                    result = r;
            }
            break;
        case 3:
            for (int i = offset; i < end; i++) {
                final int idx = index.get(i) * vertexSize + posoff;
                tmpV.set(verts.get(idx), verts.get(idx + 1), verts.get(idx + 2));
                if (transform != null)
                    tmpV.mul(transform);
                final float r = tmpV.sub(centerX, centerY, centerZ).len2();
                if (r > result)
                    result = r;
            }
            break;
    }
    return result;
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) FloatBuffer(java.nio.FloatBuffer) ShortBuffer(java.nio.ShortBuffer)

Aggregations

GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)202 IOException (java.io.IOException)40 FileHandle (com.badlogic.gdx.files.FileHandle)14 Array (com.badlogic.gdx.utils.Array)13 Texture (com.badlogic.gdx.graphics.Texture)12 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)11 AtlasRegion (com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion)9 InputStream (java.io.InputStream)9 Pixmap (com.badlogic.gdx.graphics.Pixmap)8 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)8 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)7 AtlasSprite (com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasSprite)7 BufferedInputStream (java.io.BufferedInputStream)7 File (java.io.File)7 OutputStream (java.io.OutputStream)7 VertexAttribute (com.badlogic.gdx.graphics.VertexAttribute)6 LifecycleListener (com.badlogic.gdx.LifecycleListener)5 ByteBuffer (java.nio.ByteBuffer)5 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)4 NinePatch (com.badlogic.gdx.graphics.g2d.NinePatch)4