Example usage for com.badlogic.gdx.utils GdxRuntimeException GdxRuntimeException

List of usage examples for com.badlogic.gdx.utils GdxRuntimeException GdxRuntimeException

Introduction

In this page you can find the example usage for com.badlogic.gdx.utils GdxRuntimeException GdxRuntimeException.

Prototype

public GdxRuntimeException(Throwable t) 

Source Link

Usage

From source file:be.ac.ucl.lfsab1509.bouboule.game.level.LevelLoader.java

License:Open Source License

/**
 * Load the 'level' in the Element file.
 * Update the bonus option//  w w w  .  j  a v a  2s. c o m
 * 
 *    public void loadLevel(String level)
 */
public void loadLevel(final String level) {
    if (!timerListenerArray.isEmpty()) { // can be used to produce new obstacles
        for (TimerListener timerListener : timerListenerArray) {
            GlobalSettings.GAME.getTimer().removeTimerListener(timerListener);
        }
        timerListenerArray.clear();
    }

    file = root.getChildByName(level);
    if (file == null) {
        Gdx.app.log("Matth", "Level not found");
        throw new GdxRuntimeException("Level not found");
    }

    readLevelSettings(file);
}

From source file:chbachman.api.util.Array.java

License:Apache License

/**
 * Selects the nth-lowest element from the Array according to Comparator
 * ranking. This might partially sort the Array. The array must have a size
 * greater than 0, or a {@link com.badlogic.gdx.utils.GdxRuntimeException}
 * will be thrown.//from   w w w. java2 s  . c  o  m
 * 
 * @see Select
 * @param comparator
 *            used for comparison
 * @param kthLowest
 *            rank of desired object according to comparison, n is based on
 *            ordinal numbers, not array indices. for min value use 1, for
 *            max value use size of array, using 0 results in runtime
 *            exception.
 * @return the value of the Nth lowest ranked object.
 */
public T selectRanked(Comparator<T> comparator, int kthLowest) {
    if (kthLowest < 1) {
        throw new GdxRuntimeException("nth_lowest must be greater than 0, 1 = first, 2 = second...");
    }
    return Select.instance().select(items, comparator, kthLowest, size);
}

From source file:chbachman.api.util.Array.java

License:Apache License

/**
 * @see Array#selectRanked(java.util.Comparator, int)
 * @param comparator/*from w  ww.  j  a  va  2  s  .  com*/
 *            used for comparison
 * @param kthLowest
 *            rank of desired object according to comparison, n is based on
 *            ordinal numbers, not array indices. for min value use 1, for
 *            max value use size of array, using 0 results in runtime
 *            exception.
 * @return the index of the Nth lowest ranked object.
 */
public int selectRankedIndex(Comparator<T> comparator, int kthLowest) {
    if (kthLowest < 1) {
        throw new GdxRuntimeException("nth_lowest must be greater than 0, 1 = first, 2 = second...");
    }
    return Select.instance().selectIndex(items, comparator, kthLowest, size);
}

From source file:color.guard.GameplayScreen.java

License:Open Source License

@Override
public void show() {
    guiRandom = new RNG(new Lathe32RNG(0x1337BEEFFEEDL));
    Gdx.gl.glDisable(GL20.GL_BLEND);//  w  w w. ja v  a2 s . co  m
    viewport = new PixelPerfectViewport(Scaling.fill, visualWidth, visualHeight);
    //viewport = new ScreenViewport();
    //tempVector3 = new Vector3();
    viewport.getCamera().update();
    //prevCameraPosition = viewport.getCamera().position.cpy();
    nextCameraPosition = viewport.getCamera().position.cpy();
    atlas = new TextureAtlas("Iso_Mini.atlas");
    palettes = new Texture("palettes.png");
    tempSB = new StringBuilder(16);

    font = new BitmapFont(Gdx.files.internal("NanoOKExtended.fnt"), atlas.findRegion("NanoOKExtended"));
    //font.getData().setScale(2f);
    font.setColor(1f / 255f, 1f, 1f, 1f);
    //displayString = state.world.mapGen.atlas.getAt(0);
    String s, r;
    terrains = new TextureAtlas.AtlasRegion[WorldState.terrains.length << 2];
    for (int i = 0; i < terrains.length >> 2; i++) {
        terrains[i * 4] = atlas.findRegion(WorldState.terrains[i] + "_Huge_face0", 0);
        terrains[i * 4 + 1] = atlas.findRegion(WorldState.terrains[i] + "_Huge_face1", 0);
        terrains[i * 4 + 2] = atlas.findRegion(WorldState.terrains[i] + "_Huge_face2", 0);
        terrains[i * 4 + 3] = atlas.findRegion(WorldState.terrains[i] + "_Huge_face3", 0);
    }
    ;
    int pieceCount = PieceKind.kinds.size(), facilityCount = PieceKind.facilities.size(),
            totalCount = pieceCount + facilityCount << 2;
    PieceKind p;
    standing = new Animation[totalCount];
    acting0 = new Animation[totalCount];
    acting1 = new Animation[totalCount];
    dying = new Animation[totalCount];
    receiving0 = new Animation[totalCount];
    receiving1 = new Animation[totalCount];
    for (int i = 0; i < pieceCount; i++) {
        p = PieceKind.kinds.getAt(i);
        s = p.visual + "_Large_face";
        standing[i << 2] = new Animation<>(0.10f, atlas.createSprites(s + 0), Animation.PlayMode.LOOP);
        standing[i << 2 | 1] = new Animation<>(0.10f, atlas.createSprites(s + 1), Animation.PlayMode.LOOP);
        standing[i << 2 | 2] = new Animation<>(0.10f, atlas.createSprites(s + 2), Animation.PlayMode.LOOP);
        standing[i << 2 | 3] = new Animation<>(0.10f, atlas.createSprites(s + 3), Animation.PlayMode.LOOP);
        s = p.visual + "_Large_face";
        if ((p.weapons & 2) != 0) {
            acting0[i << 2] = new Animation<>(0.10f, atlas.createSprites(s + 0 + "_attack_0"));
            acting0[i << 2 | 1] = new Animation<>(0.10f, atlas.createSprites(s + 1 + "_attack_0"));
            acting0[i << 2 | 2] = new Animation<>(0.10f, atlas.createSprites(s + 2 + "_attack_0"));
            acting0[i << 2 | 3] = new Animation<>(0.10f, atlas.createSprites(s + 3 + "_attack_0"));
            r = p.show[0] + "_face";
            receiving0[i << 2] = new Animation<>(0.10f,
                    atlas.createSprites(r + 0 + "_strength_" + p.shownStrengths[0]));
            receiving0[i << 2 | 1] = new Animation<>(0.10f,
                    atlas.createSprites(r + 1 + "_strength_" + p.shownStrengths[0]));
            receiving0[i << 2 | 2] = new Animation<>(0.10f,
                    atlas.createSprites(r + 2 + "_strength_" + p.shownStrengths[0]));
            receiving0[i << 2 | 3] = new Animation<>(0.10f,
                    atlas.createSprites(r + 3 + "_strength_" + p.shownStrengths[0]));
        }
        if ((p.weapons & 1) != 0) {
            acting1[i << 2] = new Animation<>(0.10f, atlas.createSprites(s + 0 + "_attack_1"));
            acting1[i << 2 | 1] = new Animation<>(0.10f, atlas.createSprites(s + 1 + "_attack_1"));
            acting1[i << 2 | 2] = new Animation<>(0.10f, atlas.createSprites(s + 2 + "_attack_1"));
            acting1[i << 2 | 3] = new Animation<>(0.10f, atlas.createSprites(s + 3 + "_attack_1"));
            r = p.show[1] + "_face";
            receiving1[i << 2] = new Animation<>(0.10f,
                    atlas.createSprites(r + 0 + "_strength_" + p.shownStrengths[1]));
            receiving1[i << 2 | 1] = new Animation<>(0.10f,
                    atlas.createSprites(r + 1 + "_strength_" + p.shownStrengths[1]));
            receiving1[i << 2 | 2] = new Animation<>(0.10f,
                    atlas.createSprites(r + 2 + "_strength_" + p.shownStrengths[1]));
            receiving1[i << 2 | 3] = new Animation<>(0.10f,
                    atlas.createSprites(r + 3 + "_strength_" + p.shownStrengths[1]));
        }
        dying[i << 2] = new Animation<>(0.10f, atlas.createSprites(s + 0 + "_death"));
        dying[i << 2 | 1] = new Animation<>(0.10f, atlas.createSprites(s + 1 + "_death"));
        dying[i << 2 | 2] = new Animation<>(0.10f, atlas.createSprites(s + 2 + "_death"));
        dying[i << 2 | 3] = new Animation<>(0.10f, atlas.createSprites(s + 3 + "_death"));
    }
    for (int i = 0; i < facilityCount; i++) {
        p = PieceKind.facilities.getAt(i);
        s = p.visual + "_Large_face";
        standing[pieceCount + i << 2] = new Animation<>(0.10f, atlas.createSprites(s + 0),
                Animation.PlayMode.LOOP);
        standing[pieceCount + i << 2 | 1] = new Animation<>(0.10f, atlas.createSprites(s + 1),
                Animation.PlayMode.LOOP);
        standing[pieceCount + i << 2 | 2] = new Animation<>(0.10f, atlas.createSprites(s + 2),
                Animation.PlayMode.LOOP);
        standing[pieceCount + i << 2 | 3] = new Animation<>(0.10f, atlas.createSprites(s + 3),
                Animation.PlayMode.LOOP);
        s = p.visual + "_Large_face";
        dying[pieceCount + i << 2] = new Animation<>(0.10f, atlas.createSprites(s + 0 + "_death"));
        dying[pieceCount + i << 2 | 1] = new Animation<>(0.10f, atlas.createSprites(s + 1 + "_death"));
        dying[pieceCount + i << 2 | 2] = new Animation<>(0.10f, atlas.createSprites(s + 2 + "_death"));
        dying[pieceCount + i << 2 | 3] = new Animation<>(0.10f, atlas.createSprites(s + 3 + "_death"));
    }
    glp = new GLProfiler(Gdx.graphics);
    glp.enable();
    state.world.startBattle(state.world.factions);
    state.world.battle.resistanceMaps();
    final Coord playerPos = state.world.battle.pieces.firstKey();
    targetCell = playerPos;
    playerPiece = state.world.battle.pieces.getAt(0);
    dijkstra = new DijkstraMap(ArrayTools.fill('.', mapWidth, mapHeight), DijkstraMap.Measurement.MANHATTAN,
            new StatefulRNG(new Lathe32RNG(123456789, 987654321)));
    dijkstra.initializeCost(state.world.battle.resistances[playerPiece.pieceKind.mobility]);
    viewport.getCamera().position.set(32 * (playerPos.y - playerPos.x) + 9f,
            16 * (playerPos.y + playerPos.x) + 13f, 0f);
    viewport.getCamera().update();
    //prevCameraPosition = viewport.getCamera().position.cpy();
    nextCameraPosition = viewport.getCamera().position.cpy();

    //fog = new Noise.Layered3D(SeededNoise.instance, 2, 0.015);

    /*pieces = new int[mapWidth][mapHeight];
    int[] tempOrdering = new int[pieceCount];
    for (int x = mapWidth - 1; x >= 0; x--) {
    CELL_WISE:
    for (int y = mapHeight - 1; y >= 0; y--) {
        if(guiRandom.next(4) == 0) {
            guiRandom.randomOrdering(pieceCount, tempOrdering);
            for (int i = 0; i < pieceCount; i++) {
                if(PieceKind.kinds.getAt(tempOrdering[i]).mobilities[map[x][y]] < 6)
                {
                    pieces[x][y] = tempOrdering[i] << 2 | guiRandom.next(2);
                    continue CELL_WISE;
                }
            }
        }
        pieces[x][y] = -1;
    }
    }
    */
    String vertex = "attribute vec4 a_position;\n" + "attribute vec4 a_color;\n"
            + "attribute vec2 a_texCoord0;\n" + "uniform mat4 u_projTrans;\n" + "varying vec4 v_color;\n"
            + "varying vec2 v_texCoords;\n" + "void main()\n" + "{\n" + "v_color = "
            + ShaderProgram.COLOR_ATTRIBUTE + ";\n" + "v_color.a = v_color.a * (255.0/254.0);\n" + //* (256.0/255.0)
            "v_texCoords = " + ShaderProgram.TEXCOORD_ATTRIBUTE + "0;\n" + "gl_Position = u_projTrans * "
            + ShaderProgram.POSITION_ATTRIBUTE + ";\n" + "}\n";
    String fragment = "#ifdef GL_ES\n" + "#define LOWP lowp\n" + "precision mediump float;\n" + "#else\n"
            + "#define LOWP\n" + "#endif\n" + "varying LOWP vec4 v_color;\n" + "varying vec2 v_texCoords;\n"
            + "uniform sampler2D u_texture;\n" + "uniform sampler2D u_texPalette;\n" + "void main()\n" + "{\n"
            + "vec4 color = texture2D(u_texture, v_texCoords);\n"
            + "vec2 index = vec2(color.r * 255.0 / 255.5, v_color.r);\n"
            + "gl_FragColor = vec4(texture2D(u_texPalette, index).rgb, color.a);\n" + "}\n";
    //        String fragment =
    //                "#ifdef GL_ES\n" +
    //                "#define LOWP lowp\n" +
    //                "precision mediump float;\n" +
    //                "#else\n" +
    //                "#define LOWP\n" +
    //                "#endif\n" +
    //                "varying LOWP vec4 v_color;\n" +
    //                "varying vec2 v_texCoords;\n" +
    //                "uniform sampler2D u_texture;\n" +
    //                "uniform sampler2D u_texPalette;\n" +
    //                "// The MIT License\n" +
    //                "// Copyright  2013 Inigo Quilez\n" +
    //                "// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n" +
    //                "// Gradient Noise 3D             : https://www.shadertoy.com/view/Xsl3Dl\n" +
    //                "//===============================================================================================\n" +
    //                "vec3 hash( vec3 p ) // replace this by something better\n" +
    //                "{\n" +
    //                "    p = vec3( dot(p,vec3(127.1,311.7, 74.7)),\n" +
    //                "        dot(p,vec3(269.5,183.3,246.1)),\n" +
    //                "        dot(p,vec3(113.5,271.9,124.6)));\n" +
    //                "    return -1.0 + 2.0*fract(sin(p)*43758.5453123);\n" +
    //                "}\n" +
    //                "float noise(vec3 p)\n" +
    //                "{\n" +
    //                "    vec3 i = floor(p);\n" +
    //                "    vec3 f = fract(p);\n" +
    //                "    vec3 u = f*f*(3.0-2.0*f);\n" +
    //                "    return " +
    //                        "   mix( mix( mix( dot( hash( i + vec3(0.0,0.0,0.0) ), f - vec3(0.0,0.0,0.0) ), \n" +
    //                "                          dot( hash( i + vec3(1.0,0.0,0.0) ), f - vec3(1.0,0.0,0.0) ), u.x),\n" +
    //                "                     mix( dot( hash( i + vec3(0.0,1.0,0.0) ), f - vec3(0.0,1.0,0.0) ), \n" +
    //                "                          dot( hash( i + vec3(1.0,1.0,0.0) ), f - vec3(1.0,1.0,0.0) ), u.x), u.y),\n" +
    //                "                mix( mix( dot( hash( i + vec3(0.0,0.0,1.0) ), f - vec3(0.0,0.0,1.0) ), \n" +
    //                "                          dot( hash( i + vec3(1.0,0.0,1.0) ), f - vec3(1.0,0.0,1.0) ), u.x),\n" +
    //                "                     mix( dot( hash( i + vec3(0.0,1.0,1.0) ), f - vec3(0.0,1.0,1.0) ), \n" +
    //                "                          dot( hash( i + vec3(1.0,1.0,1.0) ), f - vec3(1.0,1.0,1.0) ), u.x), u.y), u.z)" +
    //                        ";\n" +
    //                "}\n" +
    //                "const mat3 m = mat3( 0.00,  0.80,  0.60,\n" +
    //                "                    -0.80,  0.36, -0.48,\n" +
    //                "                    -0.60, -0.48,  0.64 );\n"+
    //                "// End of MIT-licensed code\n"+
    //                //Jim Hejl and Richard Burgess-Dawson's tone mapping formula
    //                "vec3 tone(vec3 texColor, LOWP float change)\n" +
    //                "{\n" +
    //                "vec3 x = clamp((texColor * 0.666) - 0.004, 0.0, 100.0);\n" +
    //                "return mix(texColor, (x*(6.2*x+.5))/(x*(6.2*x+1.7)+0.06), change);\n" +
    //                "}\n" +
    //                "void main()\n" +
    //                "{\n" +
    //                "vec4 color = texture2D(u_texture, v_texCoords);\n" +
    //                "vec2 index = vec2(color.r * 255.0 / 255.5, v_color.r);\n" +
    //                "vec3 q = vec3(0.01125 * gl_FragCoord.xy, v_color.g * 2.75);\n" +
    ////                "float f = 0.5000*noise( q ); q = m*q*2.01;\n" +
    ////                "f      += 0.3125*noise( q ); q = m*q*2.02;\n" +
    ////                "f      += 0.1875*noise( q );\n" +
    ////                "f      += 0.0625*noise( q ); q = m*q*2.01;\n" +
    //                "gl_FragColor = vec4(tone(texture2D(u_texPalette, index).rgb, 0.65 - noise(q) * 0.75), color.a);\n" +
    //                "}\n";
    indexShader = new ShaderProgram(vertex, fragment);
    if (!indexShader.isCompiled())
        throw new GdxRuntimeException("Error compiling shader: " + indexShader.getLog());

    map = ArrayTools.copy(state.world.worldMap);
    for (int x = 0; x < mapWidth; x++) {
        for (int y = 0; y < mapHeight; y++) {
            map[x][y] = map[x][y] * 4 + guiRandom.next(2);
        }
    }
    batch = new SpriteBatch();
    proc = new InputAdapter() {
        @Override
        public boolean touchUp(int screenX, int screenY, int pointer, int button) {
            if (inputMode == INPUT_LOCKED)
                return false;
            inputMode = INPUT_LOCKED;

            nextCameraPosition.set(screenX, screenY, 0);
            viewport.unproject(nextCameraPosition);
            //32 * y - 32 * x, 16 * y + 16 * x
            /*
            nx = 32 * y - 32 * x
            ny = 16 * y + 16 * x
            nx + 2ny = 64y
            nx - 2ny = -64x  
            */
            targetCell = Coord.get(
                    MathUtils.round((nextCameraPosition.x - nextCameraPosition.y * 2f + 32f) / -64f),
                    MathUtils.round((nextCameraPosition.x + nextCameraPosition.y * 2f - 96f) / 64f));
            dijkstra.clearGoals();
            dijkstra.findPath(playerPiece.pieceKind.stats[PieceKind.MOV], 20,
                    state.world.battle.pieces.keySet(), null, state.world.battle.pieces.firstKey(), targetCell);
            return true;
        }

        @Override
        public boolean keyDown(int keycode) {
            if (inputMode == INPUT_LOCKED)
                return false;
            switch (keycode) {
            case Input.Keys.RIGHT:
                lastArrow = Direction.LEFT;
                break;
            case Input.Keys.LEFT:
                lastArrow = Direction.RIGHT;
                break;
            case Input.Keys.UP:
                lastArrow = Direction.DOWN;
                break;
            case Input.Keys.DOWN:
                lastArrow = Direction.UP;
                break;
            //default: lastArrow = Direction.NONE;
            default:
                return false;
            }
            targetCell = playerPos.translate(lastArrow);
            dijkstra.clearGoals();
            dijkstra.findPath(playerPiece.pieceKind.stats[PieceKind.MOV], 20,
                    state.world.battle.pieces.keySet(), null, state.world.battle.pieces.firstKey(), targetCell);
            inputMode = INPUT_LOCKED;
            return true;
        }
    };
    Gdx.input.setInputProcessor(proc);
}

From source file:com.algodal.gdxscreen.utils.GdxDebug.java

License:Apache License

public void assertTrue(String tag, boolean condition) {
    if (debug()) {
        if (!condition)
            throw new GdxRuntimeException("failed: " + tag);
    }//  w  w w. j ava2  s .c om
}

From source file:com.algodal.gdxscreen.utils.GdxDebug.java

License:Apache License

public void assertFalse(String tag, boolean condition) {
    if (debug())//from   ww w .j av a  2s . co m
        if (condition)
            throw new GdxRuntimeException("failed: " + tag);
}

From source file:com.algodal.gdxscreen.utils.GdxDebug.java

License:Apache License

public void assertNotNull(String tag, Object object) {
    if (debug())/*from   ww w  .  ja  va2 s.co  m*/
        if (object == null)
            throw new GdxRuntimeException("failed: " + tag);
}

From source file:com.algodal.gdxscreen.utils.GdxDebug.java

License:Apache License

public void assertContructorEmpty(String tag, Class<?> clazz) {
    if (debug()) {
        Constructor[] cstrs = ClassReflection.getConstructors(clazz);
        for (Constructor cstr : cstrs) {
            if (cstr.getParameterTypes().length == 0)
                return;
        }//  w w  w.  ja v a2s .  com
        throw new GdxRuntimeException("failed: " + tag);
    }
}

From source file:com.algodal.gdxscreen.utils.GdxDebug.java

License:Apache License

public <T> T assertNoException(String tag, Operation<T> operation) throws GdxRuntimeException {
    try {//  w w  w  .  j a v a2  s  . com
        return operation.resultOf();
    } catch (Exception e) {
        if (debug())
            throw new GdxRuntimeException("failed with exception: " + tag + ", " + e.getMessage());
        else
            throw new GdxRuntimeException(e);
    }
}

From source file:com.algodal.gdxscreen.utils.GdxDebug.java

License:Apache License

public void assertStringNotEmpty(String tag, String string) {
    if (debug())//from w w w .j  a va 2  s.c  o m
        if ("".equals(string))
            throw new GdxRuntimeException("failed: " + tag);
}