Search in sources :

Example 26 with GdxRuntimeException

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

the class NetJavaSocketImpl method applyHints.

private void applyHints(SocketHints hints) {
    if (hints != null) {
        try {
            socket.setPerformancePreferences(hints.performancePrefConnectionTime, hints.performancePrefLatency, hints.performancePrefBandwidth);
            socket.setTrafficClass(hints.trafficClass);
            socket.setTcpNoDelay(hints.tcpNoDelay);
            socket.setKeepAlive(hints.keepAlive);
            socket.setSendBufferSize(hints.sendBufferSize);
            socket.setReceiveBufferSize(hints.receiveBufferSize);
            socket.setSoLinger(hints.linger, hints.lingerDuration);
            socket.setSoTimeout(hints.socketTimeout);
        } catch (Exception e) {
            throw new GdxRuntimeException("Error setting socket hints.", e);
        }
    }
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException)

Example 27 with GdxRuntimeException

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

the class Matrix3 method inv.

/** Inverts this matrix given that the determinant is != 0.
	 * @return This matrix for the purpose of chaining operations.
	 * @throws GdxRuntimeException if the matrix is singular (not invertible) */
public Matrix3 inv() {
    float det = det();
    if (det == 0)
        throw new GdxRuntimeException("Can't invert a singular matrix");
    float inv_det = 1.0f / det;
    float[] tmp = this.tmp, val = this.val;
    tmp[M00] = val[M11] * val[M22] - val[M21] * val[M12];
    tmp[M10] = val[M20] * val[M12] - val[M10] * val[M22];
    tmp[M20] = val[M10] * val[M21] - val[M20] * val[M11];
    tmp[M01] = val[M21] * val[M02] - val[M01] * val[M22];
    tmp[M11] = val[M00] * val[M22] - val[M20] * val[M02];
    tmp[M21] = val[M20] * val[M01] - val[M00] * val[M21];
    tmp[M02] = val[M01] * val[M12] - val[M11] * val[M02];
    tmp[M12] = val[M10] * val[M02] - val[M00] * val[M12];
    tmp[M22] = val[M00] * val[M11] - val[M10] * val[M01];
    val[M00] = inv_det * tmp[M00];
    val[M10] = inv_det * tmp[M10];
    val[M20] = inv_det * tmp[M20];
    val[M01] = inv_det * tmp[M01];
    val[M11] = inv_det * tmp[M11];
    val[M21] = inv_det * tmp[M21];
    val[M02] = inv_det * tmp[M02];
    val[M12] = inv_det * tmp[M12];
    val[M22] = inv_det * tmp[M22];
    return this;
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException)

Example 28 with GdxRuntimeException

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

the class MatrixJNITest method create.

@Override
public void create() {
    Matrix4 mat1 = new Matrix4();
    Matrix4 mat2 = new Matrix4();
    Matrix4 mat3 = new Matrix4();
    Vector3 vec = new Vector3(1, 2, 3);
    float[] fvec = { 1, 2, 3 };
    float[] fvecs = { 1, 2, 3, 0, 0, 1, 2, 3, 0, 0, 1, 2, 3, 0, 0 };
    mat1.setToRotation(0, 1, 0, 45);
    mat2.setToRotation(1, 0, 0, 45);
    vec.mul(mat1);
    Matrix4.mulVec(mat1.val, fvec);
    Matrix4.mulVec(mat1.val, fvecs, 0, 3, 5);
    check(vec, fvec);
    check(vec, fvecs, 3, 5);
    vec.prj(mat1);
    Matrix4.prj(mat1.val, fvec);
    Matrix4.prj(mat1.val, fvecs, 0, 3, 5);
    check(vec, fvec);
    check(vec, fvecs, 3, 5);
    vec.rot(mat1);
    Matrix4.rot(mat1.val, fvec);
    Matrix4.rot(mat1.val, fvecs, 0, 3, 5);
    check(vec, fvec);
    check(vec, fvecs, 3, 5);
    if (mat1.det() != Matrix4.det(mat1.val))
        throw new GdxRuntimeException("det doesn't work");
    mat2.set(mat1);
    mat1.inv();
    Matrix4.inv(mat2.val);
    check(mat1, mat2);
    mat3.set(mat1);
    mat1.mul(mat2);
    Matrix4.mul(mat3.val, mat2.val);
    check(mat1, mat3);
    bench();
    System.out.println("All tests passed.");
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) Vector3(com.badlogic.gdx.math.Vector3) Matrix4(com.badlogic.gdx.math.Matrix4)

Example 29 with GdxRuntimeException

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

the class MipMapTest method create.

@Override
public void create() {
    camera = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    camera.position.set(0, 1.5f, 1.5f);
    camera.lookAt(0, 0, 0);
    camera.update();
    controller = new PerspectiveCamController(camera);
    mesh = new Mesh(true, 4, 4, new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE));
    mesh.setVertices(new float[] { -1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, -1, 1, 0, -1, 0, -1, 0, 0 });
    mesh.setIndices(new short[] { 0, 1, 2, 3 });
    shader = new ShaderProgram(Gdx.files.internal("data/shaders/flattex-vert.glsl").readString(), Gdx.files.internal("data/shaders/flattex-frag.glsl").readString());
    if (!shader.isCompiled())
        throw new GdxRuntimeException("shader error: " + shader.getLog());
    textureHW = new Texture(Gdx.files.internal("data/badlogic.jpg"), Format.RGB565, true);
    MipMapGenerator.setUseHardwareMipMap(false);
    textureSW = new Texture(Gdx.files.internal("data/badlogic.jpg"), Format.RGB565, true);
    currTexture = textureHW;
    createUI();
    multiplexer = new InputMultiplexer();
    Gdx.input.setInputProcessor(multiplexer);
    multiplexer.addProcessor(ui);
    multiplexer.addProcessor(controller);
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) PerspectiveCamController(com.badlogic.gdx.tests.utils.PerspectiveCamController) InputMultiplexer(com.badlogic.gdx.InputMultiplexer) ShaderProgram(com.badlogic.gdx.graphics.glutils.ShaderProgram) VertexAttribute(com.badlogic.gdx.graphics.VertexAttribute) Mesh(com.badlogic.gdx.graphics.Mesh) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) Texture(com.badlogic.gdx.graphics.Texture)

Example 30 with GdxRuntimeException

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

the class LwjglApplication method mainLoop.

void mainLoop() {
    SnapshotArray<LifecycleListener> lifecycleListeners = this.lifecycleListeners;
    try {
        graphics.setupDisplay();
    } catch (LWJGLException e) {
        throw new GdxRuntimeException(e);
    }
    listener.create();
    graphics.resize = true;
    int lastWidth = graphics.getWidth();
    int lastHeight = graphics.getHeight();
    graphics.lastTime = System.nanoTime();
    boolean wasActive = true;
    while (running) {
        Display.processMessages();
        if (Display.isCloseRequested())
            exit();
        boolean isActive = Display.isActive();
        if (wasActive && !isActive) {
            // if it's just recently minimized from active state
            wasActive = false;
            synchronized (lifecycleListeners) {
                LifecycleListener[] listeners = lifecycleListeners.begin();
                for (int i = 0, n = lifecycleListeners.size; i < n; ++i) listeners[i].pause();
                lifecycleListeners.end();
            }
            listener.pause();
        }
        if (!wasActive && isActive) {
            // if it's just recently focused from minimized state
            wasActive = true;
            synchronized (lifecycleListeners) {
                LifecycleListener[] listeners = lifecycleListeners.begin();
                for (int i = 0, n = lifecycleListeners.size; i < n; ++i) listeners[i].resume();
                lifecycleListeners.end();
            }
            listener.resume();
        }
        boolean shouldRender = false;
        if (graphics.canvas != null) {
            int width = graphics.canvas.getWidth();
            int height = graphics.canvas.getHeight();
            if (lastWidth != width || lastHeight != height) {
                lastWidth = width;
                lastHeight = height;
                Gdx.gl.glViewport(0, 0, lastWidth, lastHeight);
                listener.resize(lastWidth, lastHeight);
                shouldRender = true;
            }
        } else {
            graphics.config.x = Display.getX();
            graphics.config.y = Display.getY();
            if (graphics.resize || Display.wasResized() || (int) (Display.getWidth() * Display.getPixelScaleFactor()) != graphics.config.width || (int) (Display.getHeight() * Display.getPixelScaleFactor()) != graphics.config.height) {
                graphics.resize = false;
                graphics.config.width = (int) (Display.getWidth() * Display.getPixelScaleFactor());
                graphics.config.height = (int) (Display.getHeight() * Display.getPixelScaleFactor());
                Gdx.gl.glViewport(0, 0, graphics.config.width, graphics.config.height);
                if (listener != null)
                    listener.resize(graphics.config.width, graphics.config.height);
                graphics.requestRendering();
            }
        }
        if (executeRunnables())
            shouldRender = true;
        // If one of the runnables set running to false, for example after an exit().
        if (!running)
            break;
        input.update();
        shouldRender |= graphics.shouldRender();
        input.processEvents();
        if (audio != null)
            audio.update();
        if (!isActive && graphics.config.backgroundFPS == -1)
            shouldRender = false;
        int frameRate = isActive ? graphics.config.foregroundFPS : graphics.config.backgroundFPS;
        if (shouldRender) {
            graphics.updateTime();
            graphics.frameId++;
            listener.render();
            Display.update(false);
        } else {
            // Sleeps to avoid wasting CPU in an empty loop.
            if (frameRate == -1)
                frameRate = 10;
            if (frameRate == 0)
                frameRate = graphics.config.backgroundFPS;
            if (frameRate == 0)
                frameRate = 30;
        }
        if (frameRate > 0)
            Display.sync(frameRate);
    }
    synchronized (lifecycleListeners) {
        LifecycleListener[] listeners = lifecycleListeners.begin();
        for (int i = 0, n = lifecycleListeners.size; i < n; ++i) {
            listeners[i].pause();
            listeners[i].dispose();
        }
        lifecycleListeners.end();
    }
    listener.pause();
    listener.dispose();
    Display.destroy();
    if (audio != null)
        audio.dispose();
    if (graphics.config.forceExit)
        System.exit(-1);
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) LifecycleListener(com.badlogic.gdx.LifecycleListener) LWJGLException(org.lwjgl.LWJGLException)

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