Search in sources :

Example 76 with GdxRuntimeException

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

the class VertexBufferObject method setBuffer.

/** Low level method to reset the buffer and attributes to the specified values. Use with care!
	 * @param data
	 * @param ownsBuffer
	 * @param value */
protected void setBuffer(Buffer data, boolean ownsBuffer, VertexAttributes value) {
    if (isBound)
        throw new GdxRuntimeException("Cannot change attributes while VBO is bound");
    if (this.ownsBuffer && byteBuffer != null)
        BufferUtils.disposeUnsafeByteBuffer(byteBuffer);
    attributes = value;
    if (data instanceof ByteBuffer)
        byteBuffer = (ByteBuffer) data;
    else
        throw new GdxRuntimeException("Only ByteBuffer is currently supported");
    this.ownsBuffer = ownsBuffer;
    final int l = byteBuffer.limit();
    byteBuffer.limit(byteBuffer.capacity());
    buffer = byteBuffer.asFloatBuffer();
    byteBuffer.limit(l);
    buffer.limit(l / 4);
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) ByteBuffer(java.nio.ByteBuffer)

Example 77 with GdxRuntimeException

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

the class AtlasTmxMapLoader method loadAsync.

@Override
public void loadAsync(AssetManager manager, String fileName, FileHandle tmxFile, AtlasTiledMapLoaderParameters parameter) {
    map = null;
    if (parameter != null) {
        convertObjectToTileSpace = parameter.convertObjectToTileSpace;
        flipY = parameter.flipY;
    } else {
        convertObjectToTileSpace = false;
        flipY = true;
    }
    try {
        map = loadMap(root, tmxFile, new AtlasResolver.AssetManagerAtlasResolver(manager));
    } catch (Exception e) {
        throw new GdxRuntimeException("Couldn't load tilemap '" + fileName + "'", e);
    }
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) IOException(java.io.IOException)

Example 78 with GdxRuntimeException

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

the class FilesTest method create.

@Override
public void create() {
    font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
    batch = new SpriteBatch();
    if (Gdx.files.isExternalStorageAvailable()) {
        message += "External storage available\n";
        message += "External storage path: " + Gdx.files.getExternalStoragePath() + "\n";
        try {
            InputStream in = Gdx.files.internal("data/cube.obj").read();
            StreamUtils.closeQuietly(in);
            message += "Open internal success\n";
        } catch (Throwable e) {
            message += "Couldn't open internal data/cube.obj\n" + e.getMessage() + "\n";
        }
        BufferedWriter out = null;
        try {
            out = new BufferedWriter(new OutputStreamWriter(Gdx.files.external("test.txt").write(false)));
            out.write("test");
            message += "Write external success\n";
        } catch (GdxRuntimeException ex) {
            message += "Couldn't open externalstorage/test.txt\n";
        } catch (IOException e) {
            message += "Couldn't write externalstorage/test.txt\n";
        } finally {
            StreamUtils.closeQuietly(out);
        }
        try {
            InputStream in = Gdx.files.external("test.txt").read();
            StreamUtils.closeQuietly(in);
            message += "Open external success\n";
        } catch (Throwable e) {
            message += "Couldn't open internal externalstorage/test.txt\n" + e.getMessage() + "\n";
        }
        BufferedReader in = null;
        try {
            in = new BufferedReader(new InputStreamReader(Gdx.files.external("test.txt").read()));
            if (!in.readLine().equals("test"))
                message += "Read result wrong\n";
            else
                message += "Read external success\n";
        } catch (GdxRuntimeException ex) {
            message += "Couldn't open externalstorage/test.txt\n";
        } catch (IOException e) {
            message += "Couldn't read externalstorage/test.txt\n";
        } finally {
            StreamUtils.closeQuietly(in);
        }
        if (!Gdx.files.external("test.txt").delete())
            message += "Couldn't delete externalstorage/test.txt";
    } else {
        message += "External storage not available";
    }
    if (Gdx.files.isLocalStorageAvailable()) {
        message += "Local storage available\n";
        message += "Local storage path: " + Gdx.files.getLocalStoragePath() + "\n";
        BufferedWriter out = null;
        try {
            out = new BufferedWriter(new OutputStreamWriter(Gdx.files.local("test.txt").write(false)));
            out.write("test");
            message += "Write local success\n";
        } catch (GdxRuntimeException ex) {
            message += "Couldn't open localstorage/test.txt\n";
        } catch (IOException e) {
            message += "Couldn't write localstorage/test.txt\n";
        } finally {
            StreamUtils.closeQuietly(out);
        }
        try {
            InputStream in = Gdx.files.local("test.txt").read();
            StreamUtils.closeQuietly(in);
            message += "Open local success\n";
        } catch (Throwable e) {
            message += "Couldn't open localstorage/test.txt\n" + e.getMessage() + "\n";
        }
        BufferedReader in = null;
        try {
            in = new BufferedReader(new InputStreamReader(Gdx.files.local("test.txt").read()));
            if (!in.readLine().equals("test"))
                message += "Read result wrong\n";
            else
                message += "Read local success\n";
        } catch (GdxRuntimeException ex) {
            message += "Couldn't open localstorage/test.txt\n";
        } catch (IOException e) {
            message += "Couldn't read localstorage/test.txt\n";
        } finally {
            StreamUtils.closeQuietly(in);
        }
        try {
            byte[] testBytes = Gdx.files.local("test.txt").readBytes();
            if (Arrays.equals("test".getBytes(), testBytes))
                message += "Read into byte array success\n";
            else
                fail();
        } catch (Throwable e) {
            message += "Couldn't read localstorage/test.txt\n" + e.getMessage() + "\n";
        }
        if (!Gdx.files.local("test.txt").delete())
            message += "Couldn't delete localstorage/test.txt";
    }
    try {
        testClasspath();
        testInternal();
        testExternal();
        testAbsolute();
        testLocal();
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) BufferedWriter(java.io.BufferedWriter)

Example 79 with GdxRuntimeException

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

the class CollectionsTest method invoke.

private void invoke(String methodName, Object object, Object... args) {
    try {
        Method theMethod = null;
        for (Method method : ClassReflection.getMethods(object.getClass())) {
            if (methodName.equals(method.getName()) && method.getParameterTypes().length == args.length) {
                theMethod = method;
                break;
            }
        }
        theMethod.invoke(object, args);
    } catch (Throwable ex) {
        throw new GdxRuntimeException(ex);
    }
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) Method(com.badlogic.gdx.utils.reflect.Method)

Example 80 with GdxRuntimeException

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

the class Affine2Test method create.

@Override
public void create() {
    Vector2 trn = new Vector2(30, 50);
    float rot = 35;
    float cos = (float) Math.cos(MathUtils.degreesToRadians * rot);
    float sin = (float) Math.sin(MathUtils.degreesToRadians * rot);
    Vector2 scl = new Vector2(0.42f, 1.19f);
    Vector2 shear = new Vector2(0.35f, 0.71f);
    Matrix3 mat1 = new Matrix3();
    Matrix3 mat2 = new Matrix3();
    Affine2 afn1 = new Affine2();
    Affine2 afn2 = new Affine2();
    // check setter - identity
    checkEqual(mat1, new float[] { 1, 0, 0, 0, 1, 0, 0, 0, 1 });
    checkEqual(mat1, mat2.idt());
    checkEqual(mat1, afn1);
    checkEqual(mat1, afn1.idt());
    // check setter - translation
    mat1.setToTranslation(trn);
    checkEqual(mat1, new float[] { 1, 0, 0, 0, 1, 0, trn.x, trn.y, 1 });
    afn1.setToTranslation(trn);
    checkEqual(mat1, afn1);
    // check setter - scale
    mat1.setToScaling(scl);
    checkEqual(mat1, new float[] { scl.x, 0, 0, 0, scl.y, 0, 0, 0, 1 });
    afn1.setToScaling(scl);
    checkEqual(mat1, afn1);
    // check setter - rotation
    mat1.setToRotation(rot);
    checkEqual(mat1, new float[] { cos, sin, 0, -sin, cos, 0, 0, 0, 1 });
    afn1.setToRotation(rot);
    checkEqual(mat1, afn1);
    mat1.setToRotationRad(MathUtils.degreesToRadians * rot);
    checkEqual(mat1, afn1);
    afn1.setToRotationRad(MathUtils.degreesToRadians * rot);
    checkEqual(mat1, afn1);
    // check setter - shearing
    afn1.setToShearing(shear);
    checkEqual(mat1.set(afn1), new float[] { 1, shear.y, 0, shear.x, 1, 0, 0, 0, 1 });
    // check setter - translation x rotation x scale
    afn1.setToTrnRotScl(trn, rot, scl);
    afn2.setToTrnRotRadScl(trn, MathUtils.degreesToRadians * rot, scl);
    checkEqual(afn1, afn2);
    afn2.setToTranslation(trn).rotate(rot).scale(scl);
    checkEqual(afn1, afn2);
    // check setter - translation x scale
    afn1.setToTrnRotScl(trn, 0, scl);
    afn2.setToTrnScl(trn, scl);
    checkEqual(afn1, afn2);
    // check post-multiplication
    mat1.idt().scale(scl).rotate(rot).translate(trn).mul(mat2.set(afn2.setToShearing(shear)));
    afn1.idt().scale(scl).rotate(rot).translate(trn).shear(shear);
    checkEqual(mat1, afn1);
    afn1.idt().mul(afn2.setToScaling(scl)).mul(afn2.setToRotation(rot)).mul(afn2.setToTranslation(trn)).mul(afn2.setToShearing(shear));
    checkEqual(mat1, afn1);
    // check pre-multiplication
    afn1.idt().preShear(shear).preTranslate(trn).preRotate(rot).preScale(scl);
    checkEqual(mat1, afn1);
    afn1.idt().preMul(afn2.setToShearing(shear)).preMul(afn2.setToTranslation(trn)).preMul(afn2.setToRotation(rot)).preMul(afn2.setToScaling(scl));
    checkEqual(mat1, afn1);
    mat1.set(afn2.setToShearing(shear)).trn(trn).mulLeft(mat2.setToRotation(rot)).mulLeft(mat2.setToScaling(scl));
    checkEqual(mat1, afn1);
    // check determinant and inverse
    checkEqual(mat1.det(), afn1.det());
    check(afn1.det() == (afn1.m00 * afn1.m11 - afn1.m01 * afn1.m10));
    mat1.inv();
    afn2.set(afn1).inv();
    checkEqual(mat1, afn2);
    checkEqual(afn1.det(), 1 / afn2.det());
    // check for exception when trying to invert singular matrices
    boolean didThrow = false;
    afn1.setToShearing(1, 1);
    try {
        afn1.inv();
    } catch (GdxRuntimeException e) {
        didThrow = true;
    }
    check(didThrow);
    System.out.println("All tests passed.");
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) Affine2(com.badlogic.gdx.math.Affine2) Vector2(com.badlogic.gdx.math.Vector2) Matrix3(com.badlogic.gdx.math.Matrix3)

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