com.badlogic.gdx.utils.GdxRuntimeException Java Examples
The following examples show how to use
com.badlogic.gdx.utils.GdxRuntimeException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ShaderUtils.java From Mundus with Apache License 2.0 | 6 votes |
/** * Compiles and links shader. * * @param vertexShader * path to vertex shader * @param fragmentShader * path to fragment shader * * @return compiled shader program */ public static ShaderProgram compile(String vertexShader, String fragmentShader) { String vert; String frag; if (Gdx.app.getType() == Application.ApplicationType.WebGL) { vert = Gdx.files.internal(vertexShader).readString(); frag = Gdx.files.internal(fragmentShader).readString(); } else { vert = Gdx.files.classpath(vertexShader).readString(); frag = Gdx.files.classpath(fragmentShader).readString(); } ShaderProgram program = new ShaderProgram(vert, frag); if (!program.isCompiled()) { throw new GdxRuntimeException(program.getLog()); } return program; }
Example #2
Source File: Box2dSteeringTest.java From gdx-ai with Apache License 2.0 | 6 votes |
protected void setRandomNonOverlappingPosition (Box2dSteeringEntity character, Array<Box2dSteeringEntity> others, float minDistanceFromBoundary) { int maxTries = Math.max(100, others.size * others.size); SET_NEW_POS: while (--maxTries >= 0) { int x = MathUtils.random((int)container.stageWidth); int y = MathUtils.random((int)container.stageHeight); float angle = MathUtils.random(-MathUtils.PI, MathUtils.PI); character.body.setTransform(pixelsToMeters(x), pixelsToMeters(y), angle); for (int i = 0; i < others.size; i++) { Box2dSteeringEntity other = (Box2dSteeringEntity)others.get(i); if (character.getPosition().dst(other.getPosition()) <= character.getBoundingRadius() + other.getBoundingRadius() + minDistanceFromBoundary) continue SET_NEW_POS; } return; } throw new GdxRuntimeException("Probable infinite loop detected"); }
Example #3
Source File: HeadlessG3dModelLoader.java From gdx-proto with Apache License 2.0 | 6 votes |
public ModelData parseModel (FileHandle handle) { JsonValue json = reader.parse(handle); ModelData model = new ModelData(); JsonValue version = json.require("version"); model.version[0] = version.getShort(0); model.version[1] = version.getShort(1); if (model.version[0] != VERSION_HI || model.version[1] != VERSION_LO) throw new GdxRuntimeException("Model version not supported"); model.id = json.getString("id", ""); parseMeshes(model, json); //parseMaterials(model, json, handle.parent().path()); parseNodes(model, json); parseAnimations(model, json); return model; }
Example #4
Source File: Skin.java From gdx-skineditor with Apache License 2.0 | 6 votes |
public <T> T get(String name, Class<T> type) { if (name == null) throw new IllegalArgumentException("name cannot be null."); if (type == null) throw new IllegalArgumentException("type cannot be null."); if (type == Drawable.class) return (T) getDrawable(name); if (type == TextureRegion.class) return (T) getRegion(name); if (type == NinePatch.class) return (T) getPatch(name); if (type == Sprite.class) return (T) getSprite(name); ObjectMap<String, Object> typeResources = resources.get(type); if (typeResources == null) throw new GdxRuntimeException("No " + type.getName() + " registered with name: " + name); Object resource = typeResources.get(name); if (resource == null) throw new GdxRuntimeException("No " + type.getName() + " registered with name: " + name); return (T) resource; }
Example #5
Source File: COFD2.java From riiablo with Apache License 2.0 | 6 votes |
public static COFD2 loadFromStream(InputStream in) { try { int i = 0; Array<Entry> entries = new Array<>(1024); while (in.available() > 0) { Entry entry = new Entry(in); entries.add(entry); if (DEBUG_ENTRIES) Gdx.app.debug(TAG, i++ + ": " + entry.toString()); if (entry.header1 != -1 || entry.header2 != 0 || entry.header3 != -1) { Gdx.app.error(TAG, "Invalid entry headers: " + entry); } } return new COFD2(entries); } catch (Throwable t) { throw new GdxRuntimeException("Couldn't load D2 from stream.", t); } finally { StreamUtils.closeQuietly(in); } }
Example #6
Source File: VertexAttributeArray.java From libgdx-snippets with MIT License | 6 votes |
private int getTypeSize(int type) { switch (type) { case GL_BYTE: case GL_UNSIGNED_BYTE: return 1; case GL_SHORT: case GL_UNSIGNED_SHORT: return 2; case GL_INT: case GL_UNSIGNED_INT: case GL_FLOAT: return 4; default: throw new GdxRuntimeException("Unsupported vertex attribute type!"); } }
Example #7
Source File: SkinTextFont.java From beatoraja with GNU General Public License v3.0 | 6 votes |
@Override protected void prepareText(String text) { if(preparedFonts != null) { return; } if(font != null) { font.dispose(); font = null; } try { parameter.characters = text; font = generator.generateFont(parameter); layout = new GlyphLayout(font, ""); } catch (GdxRuntimeException e) { Logger.getGlobal().warning("Font準備失敗 : " + text + " - " + e.getMessage()); } }
Example #8
Source File: MG3dModelLoader.java From Mundus with Apache License 2.0 | 6 votes |
public ModelData parseModel(FileHandle handle) { JsonValue json = reader.parse(handle); ModelData model = new ModelData(); JsonValue version = json.require("version"); model.version[0] = version.getShort(0); model.version[1] = version.getShort(1); if (model.version[0] != VERSION_HI || model.version[1] != VERSION_LO) throw new GdxRuntimeException("Model version not supported"); model.id = json.getString("id", ""); parseMeshes(model, json); parseMaterials(model, json, handle.parent().path()); parseNodes(model, json); parseAnimations(model, json); return model; }
Example #9
Source File: ResumeVsJoinTest.java From gdx-ai with Apache License 2.0 | 6 votes |
protected void setRandomNonOverlappingPosition (SteeringActor character, Array<? extends SteeringActor> others, float minDistanceFromBoundary) { int maxTries = Math.max(100, others.size * others.size); SET_NEW_POS: while (--maxTries >= 0) { character.setPosition(MathUtils.random(stage.getWidth()), MathUtils.random(stage.getHeight()), Align.center); character.getPosition().set(character.getX(Align.center), character.getY(Align.center)); for (int i = 0; i < others.size; i++) { SteeringActor other = (SteeringActor)others.get(i); if (character.getPosition().dst(other.getPosition()) <= character.getBoundingRadius() + other.getBoundingRadius() + minDistanceFromBoundary) continue SET_NEW_POS; } return; } throw new GdxRuntimeException("Probable infinite loop detected"); }
Example #10
Source File: SpineRenderer.java From bladecoder-adventure-engine with Apache License 2.0 | 6 votes |
@Override public String[] getInternalAnimations(AnimationDesc anim) { try { retrieveSource(anim.source, ((SpineAnimationDesc) anim).atlas); } catch (GdxRuntimeException e) { sourceCache.remove(anim.source); Array<String> dependencies = EngineAssetManager.getInstance().getDependencies(getFileName(anim.source)); if (dependencies.size > 0) dependencies.removeIndex(dependencies.size - 1); return new String[0]; } Array<Animation> animations = ((SkeletonCacheEntry) sourceCache.get(anim.source)).skeleton.getData() .getAnimations(); String[] result = new String[animations.size]; for (int i = 0; i < animations.size; i++) { Animation a = animations.get(i); result[i] = a.getName(); } return result; }
Example #11
Source File: BehaviorTreeParser.java From gdx-ai with Apache License 2.0 | 6 votes |
@Override public void parse (char[] data, int offset, int length) { debug = btParser.debugLevel > BehaviorTreeParser.DEBUG_NONE; root = null; clear(); super.parse(data, offset, length); // Pop all task from the stack and check their minimum number of children popAndCheckMinChildren(0); Subtree<E> rootTree = subtrees.get(""); if (rootTree == null) throw new GdxRuntimeException("Missing root tree"); root = rootTree.rootTask; if (root == null) throw new GdxRuntimeException("The tree must have at least the root task"); clear(); }
Example #12
Source File: ImmutableArrayTests.java From ashley with Apache License 2.0 | 6 votes |
@Test public void forbiddenRemoval () { Array<Integer> array = new Array<Integer>(); ImmutableArray<Integer> immutable = new ImmutableArray<Integer>(array); for (int i = 0; i < 10; ++i) { array.add(i); } boolean thrown = false; try { immutable.iterator().remove(); } catch (GdxRuntimeException e) { thrown = true; } assertEquals(true, thrown); }
Example #13
Source File: MG3dModelLoader.java From Mundus with Apache License 2.0 | 6 votes |
private int parseType(String type) { if (type.equals("TRIANGLES")) { return GL20.GL_TRIANGLES; } else if (type.equals("LINES")) { return GL20.GL_LINES; } else if (type.equals("POINTS")) { return GL20.GL_POINTS; } else if (type.equals("TRIANGLE_STRIP")) { return GL20.GL_TRIANGLE_STRIP; } else if (type.equals("LINE_STRIP")) { return GL20.GL_LINE_STRIP; } else { throw new GdxRuntimeException("Unknown primitive type '" + type + "', should be one of triangle, trianglestrip, line, linestrip, lineloop or point"); } }
Example #14
Source File: MG3dModelLoader.java From Mundus with Apache License 2.0 | 5 votes |
private VertexAttribute[] parseAttributes(JsonValue attributes) { Array<VertexAttribute> vertexAttributes = new Array<VertexAttribute>(); int unit = 0; int blendWeightCount = 0; for (JsonValue value = attributes.child; value != null; value = value.next) { String attribute = value.asString(); String attr = (String) attribute; if (attr.equals("POSITION")) { vertexAttributes.add(VertexAttribute.Position()); } else if (attr.equals("NORMAL")) { vertexAttributes.add(VertexAttribute.Normal()); } else if (attr.equals("COLOR")) { vertexAttributes.add(VertexAttribute.ColorUnpacked()); } else if (attr.equals("COLORPACKED")) { vertexAttributes.add(VertexAttribute.ColorPacked()); } else if (attr.equals("TANGENT")) { vertexAttributes.add(VertexAttribute.Tangent()); } else if (attr.equals("BINORMAL")) { vertexAttributes.add(VertexAttribute.Binormal()); } else if (attr.startsWith("TEXCOORD")) { vertexAttributes.add(VertexAttribute.TexCoords(unit++)); } else if (attr.startsWith("BLENDWEIGHT")) { vertexAttributes.add(VertexAttribute.BoneWeight(blendWeightCount++)); } else { throw new GdxRuntimeException("Unknown vertex attribute '" + attr + "', should be one of position, normal, uv, tangent or binormal"); } } return vertexAttributes.toArray(VertexAttribute.class); }
Example #15
Source File: VisUI.java From vis-ui with Apache License 2.0 | 5 votes |
private static void checkBeforeLoad () { if (skin != null) throw new GdxRuntimeException("VisUI cannot be loaded twice"); if (skipGdxVersionCheck == false && Version.VERSION.equals(TARGET_GDX_VERSION) == false) { Gdx.app.log("VisUI", "Warning, using invalid libGDX version for VisUI " + VERSION + ".\n" + "You are using libGDX " + Version.VERSION + " but you need " + TARGET_GDX_VERSION + ". This may cause " + "unexpected problems and runtime exceptions."); } }
Example #16
Source File: SHA1.java From libgdx-snippets with MIT License | 5 votes |
@Override protected MessageDigest initialValue() { try { return MessageDigest.getInstance("SHA-1"); } catch (NoSuchAlgorithmException e) { throw new GdxRuntimeException(e); } }
Example #17
Source File: HeadlessModel.java From gdx-proto with Apache License 2.0 | 5 votes |
private Node loadNode (Node parent, ModelNode modelNode) { Node node = new Node(); node.id = modelNode.id; node.parent = parent; if (modelNode.translation != null) node.translation.set(modelNode.translation); if (modelNode.rotation != null) node.rotation.set(modelNode.rotation); if (modelNode.scale != null) node.scale.set(modelNode.scale); // FIXME create temporary maps for faster lookup? if (modelNode.parts != null) { for (ModelNodePart modelNodePart : modelNode.parts) { MeshPart meshPart = null; if (modelNodePart.meshPartId != null) { for (MeshPart part : meshParts) { if (modelNodePart.meshPartId.equals(part.id)) { meshPart = part; break; } } } if (meshPart == null) throw new GdxRuntimeException("Invalid node: " + node.id); NodePart nodePart = new NodePart(); nodePart.meshPart = meshPart; // nodePart.material = meshMaterial; node.parts.add(nodePart); if (modelNodePart.bones != null) nodePartBones.put(nodePart, modelNodePart.bones); } } if (modelNode.children != null) { for (ModelNode child : modelNode.children) { node.children.add(loadNode(node, child)); } } return node; }
Example #18
Source File: BufferUtils.java From riiablo with Apache License 2.0 | 5 votes |
public static String readString(InputStream in) { try { StringBuilder builder = new StringBuilder(64); for (int ch = in.read(); ch != 0; ch = in.read()) { builder.append((char) ch); } return builder.toString(); } catch (IOException t) { throw new GdxRuntimeException("Cannot read string.", t); } }
Example #19
Source File: DesktopMini2DxGame.java From mini2Dx with Apache License 2.0 | 5 votes |
static void initializeGlfw() { if (errorCallback == null) { Lwjgl3NativesLoader.load(); errorCallback = GLFWErrorCallback.createPrint(System.err); GLFW.glfwSetErrorCallback(errorCallback); GLFW.glfwInitHint(GLFW.GLFW_JOYSTICK_HAT_BUTTONS, GLFW.GLFW_FALSE); if (!GLFW.glfwInit()) { throw new GdxRuntimeException("Unable to initialize GLFW"); } } }
Example #20
Source File: Index.java From riiablo with Apache License 2.0 | 5 votes |
public static Index loadFromStream(InputStream in) { try { byte[] data = new byte[(INDEXES - 1) * Palette.COLORS]; IOUtils.readFully(in, data); return loadFromArray(null, data); } catch (Throwable t) { throw new GdxRuntimeException("Couldn't load palette from stream.", t); } finally { StreamUtils.closeQuietly(in); } }
Example #21
Source File: Fader.java From uracer-kotd with Apache License 2.0 | 5 votes |
/** Sets the duration of the effect, in milliseconds. */ @Override public void setDuration (long durationMs) { if (durationMs == 0) { throw new GdxRuntimeException("Invalid transition duration specified."); } duration = durationMs * 1000000; half = duration / 2; }
Example #22
Source File: MG3dModelLoader.java From Mundus with Apache License 2.0 | 5 votes |
private Vector2 readVector2(JsonValue vectorArray, float x, float y) { if (vectorArray == null) return new Vector2(x, y); else if (vectorArray.size == 2) return new Vector2(vectorArray.getFloat(0), vectorArray.getFloat(1)); else throw new GdxRuntimeException("Expected Vector2 values <> than two."); }
Example #23
Source File: HeadlessG3dModelLoader.java From gdx-proto with Apache License 2.0 | 5 votes |
private VertexAttribute[] parseAttributes (JsonValue attributes) { Array<VertexAttribute> vertexAttributes = new Array<VertexAttribute>(); int unit = 0; int blendWeightCount = 0; for (JsonValue value = attributes.child; value != null; value = value.next) { String attribute = value.asString(); String attr = (String)attribute; if (attr.equals("POSITION")) { vertexAttributes.add(VertexAttribute.Position()); } else if (attr.equals("NORMAL")) { vertexAttributes.add(VertexAttribute.Normal()); } else if (attr.equals("COLOR")) { vertexAttributes.add(VertexAttribute.ColorUnpacked()); } else if (attr.equals("COLORPACKED")) { vertexAttributes.add(VertexAttribute.Color()); } else if (attr.equals("TANGENT")) { vertexAttributes.add(VertexAttribute.Tangent()); } else if (attr.equals("BINORMAL")) { vertexAttributes.add(VertexAttribute.Binormal()); } else if (attr.startsWith("TEXCOORD")) { vertexAttributes.add(VertexAttribute.TexCoords(unit++)); } else if (attr.startsWith("BLENDWEIGHT")) { vertexAttributes.add(VertexAttribute.BoneWeight(blendWeightCount++)); } else { throw new GdxRuntimeException("Unknown vertex attribute '" + attr + "', should be one of position, normal, uv, tangent or binormal"); } } return vertexAttributes.toArray(VertexAttribute.class); }
Example #24
Source File: GLTFExporter.java From gdx-gltf with Apache License 2.0 | 5 votes |
/** multi scene export */ public void export(Array<SceneModel> scenes, SceneModel defaultScene, FileHandle file) { beginMultiScene(file); for(SceneModel scene : scenes){ GLTFScene glScene = obtainScene(); exportScene(glScene, scene); } root.scene = scenes.indexOf(defaultScene, true); if(root.scene < 0) throw new GdxRuntimeException("scene not found"); end(file); }
Example #25
Source File: ServerUpdate.java From gdx-proto with Apache License 2.0 | 5 votes |
public void applyUpdates() { if (processed) throw new GdxRuntimeException("serverUpdate already processed"); for (EntityUpdate entUpdate : entityUpdates) { Entity ent = Entity.getEntityById(entUpdate.getEntityId()); if (ent != null) { if (Main.inst.client.player == null && ent.id == Main.inst.client.playerId) { Main.inst.client.assignClientPlayerToId(ent.id); Log.debug("Entity matched player id, entity was assigned to player: " + ent.id); } ent.interpolator.handleUpdateFromServer(entUpdate, playerInputTick); } } processed = true; free(); }
Example #26
Source File: BlenderAssetManager.java From GdxDemo3D with Apache License 2.0 | 5 votes |
/** * Add a disposable asset to be held * * @param name Asset name * @param asset The asset * @param type Type of asset */ public void add(String name, T asset, Class<T> type) { if (!map.containsKey(type)) { map.put(type, new ObjectMap<String, T>()); } ObjectMap<String, T> innerMap = map.get(type); if (innerMap.containsKey(name)) { throw new GdxRuntimeException("Asset name is already used, try changing it: '" + name + "'"); } innerMap.put(name, asset); }
Example #27
Source File: GLTFMeshExporter.java From gdx-gltf with Apache License 2.0 | 5 votes |
public static Integer mapPrimitiveMode(int type){ switch(type){ case GL20.GL_POINTS: return 0; case GL20.GL_LINES: return 1; case GL20.GL_LINE_LOOP: return 2; case GL20.GL_LINE_STRIP: return 3; case GL20.GL_TRIANGLES: return null; // default not need to be set case GL20.GL_TRIANGLE_STRIP: return 5; case GL20.GL_TRIANGLE_FAN: return 6; } throw new GdxRuntimeException("unsupported primitive type " + type); }
Example #28
Source File: Skin.java From gdx-skineditor with Apache License 2.0 | 5 votes |
/** Returns a copy of the specified drawable. */ public Drawable newDrawable(Drawable drawable) { if (drawable instanceof TextureRegionDrawable) return new TextureRegionDrawable((TextureRegionDrawable) drawable); if (drawable instanceof NinePatchDrawable) return new NinePatchDrawable((NinePatchDrawable) drawable); if (drawable instanceof SpriteDrawable) return new SpriteDrawable((SpriteDrawable) drawable); throw new GdxRuntimeException("Unable to copy, unknown drawable type: " + drawable.getClass()); }
Example #29
Source File: Mini2DxOpenALMusic.java From mini2Dx with Apache License 2.0 | 5 votes |
public void play () { if (audio.noDevice) return; if (sourceID == -1) { sourceID = audio.obtainSource(true); if (sourceID == -1) return; audio.music.add(this); if (buffers == null) { buffers = BufferUtils.createIntBuffer(bufferCount); alGenBuffers(buffers); int errorCode = alGetError(); if (errorCode != AL_NO_ERROR) throw new GdxRuntimeException("Unable to allocate audio buffers. AL Error: " + errorCode); } alSourcei(sourceID, AL_LOOPING, AL_FALSE); setPan(pan, volume); boolean filled = false; // Check if there's anything to actually play. for (int i = 0; i < bufferCount; i++) { int bufferID = buffers.get(i); if (!fill(bufferID)) break; filled = true; alSourceQueueBuffers(sourceID, bufferID); } if (!filled && onCompletionListener != null) onCompletionListener.onCompletion(this); if (alGetError() != AL_NO_ERROR) { stop(); return; } } if (!isPlaying) { alSourcePlay(sourceID); isPlaying = true; } }
Example #30
Source File: TextureLoader.java From StS-DefaultModBase with MIT License | 5 votes |
/** * @param textureString - String path to the texture you want to load relative to resources, * Example: "theDefaultResources/images/ui/missing_texture.png" * @return <b>com.badlogic.gdx.graphics.Texture</b> - The texture from the path provided */ public static Texture getTexture(final String textureString) { if (textures.get(textureString) == null) { try { loadTexture(textureString); } catch (GdxRuntimeException e) { logger.error("Could not find texture: " + textureString); return getTexture("theDefaultResources/images/ui/missing_texture.png"); } } return textures.get(textureString); }