List of usage examples for com.badlogic.gdx.utils IntMap put
public V put(int key, V value)
From source file:com.dragome.gdx.graphics.webgl.DragomeGL20.java
License:Apache License
private int allocateUniformLocationId(final int program, final WebGLUniformLocation location) { IntMap<WebGLUniformLocation> progUniforms = uniforms.get(program); if (progUniforms == null) { progUniforms = new IntMap<WebGLUniformLocation>(); uniforms.put(program, progUniforms); }/* w ww. ja va2s. c om*/ // FIXME Check if uniform already stored. final int id = nextUniformId++; progUniforms.put(id, location); return id; }
From source file:com.kotcrab.vis.editor.serializer.cloner.IntMapCloner.java
License:Apache License
@Override protected IntMap cloneObject(IntMap original, IDeepCloner cloner, Map<Object, Object> clones) { IntMap map = new IntMap(original.size); for (Object object : original.entries()) { Entry entry = (Entry) object;/* ww w .j av a 2s . c o m*/ map.put(entry.key, cloner.deepClone(entry.value, clones)); } return map; }
From source file:com.kotcrab.vis.editor.serializer.json.IntMapJsonSerializer.java
License:Apache License
@Override public IntMap<T> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonArray jsonArray = json.getAsJsonArray(); IntMap<T> intMap = new IntMap<>(jsonArray.size()); for (JsonElement element : jsonArray) { JsonObject object = element.getAsJsonObject(); Entry<String, JsonElement> entry = object.entrySet().iterator().next(); int mapKey = Integer.parseInt(entry.getKey()); Class<?> mapObjectClass = GsonUtils.readClassProperty(object, context); intMap.put(mapKey, context.deserialize(entry.getValue(), mapObjectClass)); }/* w w w . j av a 2s . c o m*/ return intMap; }
From source file:com.kotcrab.vis.runtime.scene.IntMapJsonSerializer.java
License:Apache License
@Override public IntMap read(Json json, JsonValue jsonData, Class type) { IntMap intMap = new IntMap(); for (JsonValue entry = jsonData.child; entry != null; entry = entry.next) { intMap.put(Integer.parseInt(entry.name), json.readValue(entry.name, null, jsonData)); }/*from w ww .j ava2 s. c o m*/ return intMap; }
From source file:net.mgsx.game.examples.gpu.utils.ShaderProgramEx.java
License:Apache License
private int loadShader(int type, String source) { GL20 gl = Gdx.gl20;//from ww w . j a v a 2 s . com IntBuffer intbuf = BufferUtils.newIntBuffer(1); int shader = gl.glCreateShader(type); if (shader == 0) return -1; gl.glShaderSource(shader, source); gl.glCompileShader(shader); gl.glGetShaderiv(shader, GL20.GL_COMPILE_STATUS, intbuf); int compiled = intbuf.get(0); if (compiled == 0) { // gl.glGetShaderiv(shader, GL20.GL_INFO_LOG_LENGTH, intbuf); // int infoLogLength = intbuf.get(0); // if (infoLogLength > 1) { String infoLog = gl.glGetShaderInfoLog(shader); IntMap<String> typeString = new IntMap<String>(); typeString.put(GL20.GL_VERTEX_SHADER, "Vertex shader"); typeString.put(GL20.GL_FRAGMENT_SHADER, "Vertex shader"); typeString.put(GL_GEOMETRY_SHADER, "Geometry shader"); typeString.put(GL_TESS_CONTROL_SHADER, "Tess control shader"); typeString.put(GL_TESS_EVALUATION_SHADER, "Tess evaluation shader"); log += typeString.get(type) + "\n"; log += infoLog; // } return -1; } return shader; }
From source file:releasethekraken.LevelLoader.java
/** * Parses the level file and constructs a game world from it, and returns it. * Throws an exception if loading failed. * @return The newly loaded GameWorld/*www . jav a2 s. c o m*/ */ public GameWorld loadWorld() { Gdx.app.log("LevelLoader", "Loading level \"" + this.levelName + "\""); MapBodyManager mapBodyManager; GameWorld newWorld = new GameWorld(this.levelName); //Make a new TiledMap TiledMap map = new TmxMapLoader().load(this.levelName + ".tmx"); float unitScale = 16.0F; //16 pixels = 1 meter mapBodyManager = new MapBodyManager(newWorld.getPhysWorld(), unitScale, null, 2); mapBodyManager.createPhysics(map, "physics"); //Get the map properties MapProperties properties = map.getProperties(); //Load world properties newWorld.setName(properties.get("levelname", String.class)); newWorld.setPointsForKraken(Integer.parseInt(properties.get("krakenpoints", String.class))); newWorld.setWidth(properties.get("width", Integer.class) * 2); newWorld.setHeight(properties.get("height", Integer.class) * 2); newWorld.setTiledMap(map); newWorld.setTiledMapUnitScale(unitScale); newWorld.spawnWorldBoundaries(); //Load Entity Tile Data Gdx.app.log("LevelLoader", "Parsing entity tile data"); TiledMapTileSet entityTileSet = map.getTileSets().getTileSet("Entities"); Iterator<TiledMapTile> entityTileIterator = entityTileSet.iterator(); while (entityTileIterator.hasNext()) //Iterate through entity tiles { TiledMapTile tile = entityTileIterator.next(); String type = tile.getProperties().get("type", String.class); if (type == null) //Only check tiles that have a type set continue; //See if there is an entity class for a given name Class<? extends Entity> entityClass = ReleaseTheKraken.getEntityFromName(type); //If there is, register the ID if (entityClass != null) this.entityTileIDs.put(tile.getId(), entityClass); Gdx.app.log("LevelLoader", "Tile ID: " + tile.getId() + " type: " + type); } //If you thought that was complicated, wait until you see what's next: paths! //Load world paths Gdx.app.log("LevelLoader", "Parsing world paths"); MapLayer pathLayer = map.getLayers().get("paths"); //If the layer doesn't exist, throw an exception if (pathLayer == null) throw new NullPointerException("paths layer is null"); MapObjects pathObjects = pathLayer.getObjects(); Iterator<MapObject> pathObjIterator = pathObjects.iterator(); //Create an IntMap to map integer path IDs to paths IntMap<SeaCreaturePath> pathMap = new IntMap<SeaCreaturePath>(); //Create an IntMap to map integer path IDs to arrays of next path IDs IntMap<int[]> nextPathsMap = new IntMap<int[]>(); while (pathObjIterator.hasNext()) //Iterate over paths on the map { MapObject pathObject = pathObjIterator.next(); //Gdx.app.log("LevelLoader", "Parsing map object: " + pathObject); if (pathObject instanceof PolylineMapObject) //If the mapObject is of the correct type { PolylineMapObject polylineMapObject = (PolylineMapObject) pathObject; int pathID = polylineMapObject.getProperties().get("id", Integer.class); Gdx.app.log("LevelLoader", "Attempting to load path with ID: " + pathID); //Get and parse the list of next paths String nextPaths = polylineMapObject.getProperties().get("next", String.class); String[] nextPathIDs = nextPaths.split(","); //Make an array of next path integer IDs int[] nextPathIntIDs = new int[nextPathIDs.length]; //Parse the integer IDs from the string IDs for (int i = 0; i < nextPathIDs.length; i++) if (!nextPathIDs[i].equals("")) nextPathIntIDs[i] = Integer.parseInt(nextPathIDs[i]); //Create a new SeaCreaturePath object SeaCreaturePath seaCreaturePath = new SeaCreaturePath(pathID, null, null, polylineMapObject.getPolyline()); //Add the SeaCreaturePath object and its next paths to the IntMaps pathMap.put(pathID, seaCreaturePath); //Add the path to the IntMap so that it can be connected later nextPathsMap.put(pathID, nextPathIntIDs); //Add the next paths to the IntMap so that the paths can be connected later } } //Gdx.app.log("LevelLoader", "Done creating paths"); //Gdx.app.log("LevelLoader", "pathMap: " + pathMap); //Gdx.app.log("LevelLoader", "nextPathsMap: " + nextPathsMap); //Now that all of the SeaCreaturePaths are created, it's time to connect them SeaCreaturePath firstPath = null; //The first path, which will be the one added to the world Iterator<IntMap.Entry<SeaCreaturePath>> pathIterator = pathMap.iterator(); //Iterate over each path, connecting it to the other paths it should be connected to while (pathIterator.hasNext()) { IntMap.Entry<SeaCreaturePath> currentPathEntry = pathIterator.next(); int pathID = currentPathEntry.key; SeaCreaturePath currentPath = currentPathEntry.value; //Create the next paths list Array<SeaCreaturePath> nextPaths = new Array<SeaCreaturePath>(); //Get the array of next path IDs int[] nextPathIDs = nextPathsMap.get(pathID); //Connect the paths for (int i = 0; i < nextPathIDs.length; i++) { nextPaths.add(pathMap.get(nextPathIDs[i])); //Add the path to the list of next paths if (pathMap.get(nextPathIDs[i]) != null) pathMap.get(nextPathIDs[i]).setParent(currentPath); //Tell the next path that this current path is the parent //BUG: Each next path overwrites this, only the last "next path" gets to be the parent } currentPath.setNextPaths(nextPaths); //Set the next paths list for the path //Set the first path to the path that has a null parent if (currentPath.getParent() == null) firstPath = currentPath; //BUG: Only the last path that has a null parent becomes the first path. //This might not be a problem, as only one path should ever have a null parent. } newWorld.setFirstPath(firstPath); //Set the first path in the world //Done loading paths //Load world entities Gdx.app.log("LevelLoader", "Parsing world entities"); MapLayer entityLayer = map.getLayers().get("entities"); //If the layer doesn't exist, throw an exception if (entityLayer == null) throw new NullPointerException("entities layer is null"); MapObjects entityObjects = entityLayer.getObjects(); Iterator<MapObject> entityObjIterator = entityObjects.iterator(); while (entityObjIterator.hasNext()) //Iterate over entities on the map { MapObject entityObject = entityObjIterator.next(); //Gdx.app.log("LevelLoader", "Parsing map object: " + entityObject); if (entityObject instanceof TextureMapObject) //If the mapObject is of the correct type { //Get the entity class from the mapObject's tile ID int gid = ((TextureMapObject) entityObject).getProperties().get("gid", Integer.class); Class<? extends Entity> entityClass = this.entityTileIDs.get(gid); if (entityClass != null) { Gdx.app.log("LevelLoader", "Attempting to spawn " + entityClass.getSimpleName()); try { //Construct a new entity by finding the correct constructor from its class, and reflectively instantiating it. Magic! Constructor<? extends Entity> constructor = entityClass.getConstructor(GameWorld.class, TextureMapObject.class); Entity entity = constructor.newInstance(newWorld, entityObject); //newWorld.addEntity(entity); //Add the entity to the world //With Box2D, the entity should add itself to the world if (entity instanceof EntityPlayer) //Set the player if the entity is the player newWorld.setPlayer((EntityPlayer) entity); else if (entity instanceof EntityPirateBase) //Set the pirate base if the entity is the pirate base newWorld.setPirateBase((EntityPirateBase) entity); } catch (Exception e) { e.printStackTrace(); } } } } Gdx.app.log("LevelLoader", "Successfully loaded the world!"); Gdx.app.log("LevelLoader", newWorld.toString()); return newWorld; }