Example usage for com.badlogic.gdx.utils ArrayMap put

List of usage examples for com.badlogic.gdx.utils ArrayMap put

Introduction

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

Prototype

public void put(K key, V value) 

Source Link

Usage

From source file:com.algodal.gdxscreen.GdxGame.java

License:Apache License

private <T extends GdxScreen> void registerScreen(ArrayMap<String, GdxScreen> map, String name, String ref,
        Class<T> clazz) {/*from  ww w.j  a va  2 s.  c  om*/
    debug.assertEqual("method is called in initialize", currentState, State.Initializing);
    debug.assertNotNull(name + " ref is not null", ref);
    debug.assertNotNull(name + " class is not null", clazz);
    debug.assertStringNotEmpty(name + " ref is not empty", (ref = ref.trim())); //The trimmed down version of the string is used
    debug.assertContructorEmpty(name + " class has a empty constructor", clazz);

    //generate screen object
    T screen = debug.assertNoException("no allocation excepton", new Operation<T>() {
        @Override
        public T resultOf() throws Exception {
            return clazz.newInstance();
        }
    });
    screen.setGame(this); //This is a must.  Every screen must know their game.

    debug.assertNotNull(name + " is not null", screen);
    debug.assertFalse(name + " ref is unique", map.containsKey(ref)); //unique reference
    debug.assertFalse(name + " object is unique", map.containsValue(screen, false)); //unique screen: see GdxScreen equals(ObjectS) method

    //add new reference
    map.put(ref, screen);
}

From source file:com.mygdx.game.objects.Ragdoll.java

License:Apache License

/**
 * @param empties    Blender empties containing rigid body dimension data
 * @param armatureNodeId The name of the root skeleton/armature node
 *///from w  ww.  j a  v  a2s .co m
private void createRagdoll(Array<BlenderEmpty> empties, String armatureNodeId) {
    Node armature = modelInstance.getNode(armatureNodeId, true, true);

    // Load mass and shape half extent data from Blender json
    ArrayMap<String, Vector3> halfExtMap = new ArrayMap<String, Vector3>();
    ArrayMap<String, Float> massMap = new ArrayMap<String, Float>();

    for (BlenderEmpty empty : empties) {
        Vector3 halfExtents = new Vector3(empty.scale);
        halfExtents.x = Math.abs(halfExtents.x);
        halfExtents.y = Math.abs(halfExtents.y);
        halfExtents.z = Math.abs(halfExtents.z);
        halfExtMap.put(empty.name, halfExtents);

        float partMass = Float.parseFloat(empty.custom_properties.get("mass"));
        massMap.put(empty.name, super.mass * partMass);
    }

    ArrayMap<String, btCollisionShape> shapeMap = new ArrayMap<String, btCollisionShape>();
    ArrayMap<String, btRigidBody> bodyMap = new ArrayMap<String, btRigidBody>();

    // Create rigid bodies using the previously loaded mass and half extents.
    // Put them along with the shapes into maps.
    for (Iterator<ObjectMap.Entry<String, Vector3>> iterator = halfExtMap.iterator(); iterator.hasNext();) {
        ObjectMap.Entry<String, Vector3> entry = iterator.next();
        String partName = entry.key;
        Vector3 partHalfExt = entry.value;
        float partMass = massMap.get(partName);

        btCollisionShape partShape = new btBoxShape(partHalfExt);
        shapeMap.put(partName, partShape);

        InvisibleBody phyCmp = new InvisibleBody(partName, partShape, partMass, new Matrix4(),
                this.belongsToFlag, this.collidesWithFlag, false, true);
        phyCmp.constructionInfo.dispose();

        bodyMap.put(partName, phyCmp.body);
        this.addPart(phyCmp.body, armature.getChild(partName, true, true));
    }
    // Abdomen is the at the top of the armature hierarchy
    this.addPart(bodyMap.get("abdomen"), armature, new Vector3(0, halfExtMap.get("abdomen").y * 1.6f, 0));

    final Matrix4 localA = new Matrix4();
    final Matrix4 localB = new Matrix4();
    btHingeConstraint hingeC;
    btConeTwistConstraint coneC;
    btFixedConstraint fixedC;
    String a, b;

    // TODO: This part could probably be automated somehow...

    // Set the ragdollConstraints
    a = "abdomen";
    b = "chest";
    localA.setFromEulerAnglesRad(0, PI0_25, 0).trn(0, halfExtMap.get(a).y, 0);
    localB.setFromEulerAnglesRad(0, PI0_25, 0).trn(0, -halfExtMap.get(b).y, 0);
    this.constraints.add(hingeC = new btHingeConstraint(bodyMap.get(a), bodyMap.get(b), localA, localB));
    hingeC.setLimit(-PI0_25, PI0_5);

    a = "chest";
    b = "neck";
    localA.setFromEulerAnglesRad(0, 0, 0).trn(0, halfExtMap.get(a).y, 0);
    localB.setFromEulerAnglesRad(0, 0, 0).trn(0, -halfExtMap.get(b).y, 0);
    this.constraints.add(fixedC = new btFixedConstraint(bodyMap.get(a), bodyMap.get(b), localA, localB));

    a = "neck";
    b = "head";
    localA.setFromEulerAnglesRad(-PI0_5, 0, 0).trn(0, halfExtMap.get(a).y, 0);
    localB.setFromEulerAnglesRad(-PI0_5, 0, 0).trn(0, -halfExtMap.get(b).y, 0);
    this.constraints.add(coneC = new btConeTwistConstraint(bodyMap.get(a), bodyMap.get(b), localA, localB));
    coneC.setLimit(PI0_25, PI0_25, PI0_25);

    a = "abdomen";
    b = "left_thigh";
    localA.setFromEulerAnglesRad(0, PI, 0).scl(-1, 1, 1).trn(halfExtMap.get(a).x * 0.5f,
            -halfExtMap.get("abdomen").y, 0);
    localB.setFromEulerAnglesRad(0, 0, 0).scl(-1, 1, 1).trn(0, -halfExtMap.get(b).y, 0);
    this.constraints.add(coneC = new btConeTwistConstraint(bodyMap.get(a), bodyMap.get(b), localA, localB));
    coneC.setLimit(PI0_25, PI0_25, PI0_25);
    coneC.setDamping(10);

    a = "abdomen";
    b = "right_thigh";
    localA.setFromEulerAnglesRad(0, PI, 0).trn(-halfExtMap.get(a).x * 0.5f, -halfExtMap.get("abdomen").y, 0);
    localB.setFromEulerAnglesRad(0, 0, 0).trn(0, -halfExtMap.get(b).y, 0);
    this.constraints.add(coneC = new btConeTwistConstraint(bodyMap.get(a), bodyMap.get(b), localA, localB));
    coneC.setLimit(PI0_25, PI0_25, PI0_25);
    coneC.setDamping(10);

    a = "left_thigh";
    b = "left_shin";
    localA.setFromEulerAnglesRad(-PI0_5, 0, 0).trn(0, halfExtMap.get(a).y, 0);
    localB.setFromEulerAnglesRad(-PI0_5, 0, 0).trn(0, -halfExtMap.get(b).y, 0);
    this.constraints.add(hingeC = new btHingeConstraint(bodyMap.get(a), bodyMap.get(b), localA, localB));
    hingeC.setLimit(0, PI0_25 * 3);

    a = "right_thigh";
    b = "right_shin";
    localA.setFromEulerAnglesRad(-PI0_5, 0, 0).trn(0, halfExtMap.get(a).y, 0);
    localB.setFromEulerAnglesRad(-PI0_5, 0, 0).trn(0, -halfExtMap.get(b).y, 0);
    this.constraints.add(hingeC = new btHingeConstraint(bodyMap.get(a), bodyMap.get(b), localA, localB));
    hingeC.setLimit(0, PI0_25 * 3);

    // TODO: causes shoulder rotation
    a = "chest";
    b = "left_upper_arm";
    localA.setFromEulerAnglesRad(0, PI, 0).trn(halfExtMap.get(a).x + halfExtMap.get(b).x, halfExtMap.get(a).y,
            0);
    localB.setFromEulerAnglesRad(PI0_25, 0, 0).trn(0, -halfExtMap.get(b).y, 0);
    this.constraints.add(coneC = new btConeTwistConstraint(bodyMap.get(a), bodyMap.get(b), localA, localB));
    coneC.setLimit(PI0_5, PI0_5, 0);
    coneC.setDamping(10);

    // TODO: as above
    a = "chest";
    b = "right_upper_arm";
    localA.setFromEulerAnglesRad(0, PI, 0).trn(-halfExtMap.get(a).x - halfExtMap.get(b).x, halfExtMap.get(a).y,
            0);
    localB.setFromEulerAnglesRad(-PI0_25, 0, 0).trn(0, -halfExtMap.get("right_upper_arm").y, 0);
    this.constraints.add(coneC = new btConeTwistConstraint(bodyMap.get(a), bodyMap.get(b), localA, localB));
    coneC.setLimit(PI0_5, PI0_5, 0);
    coneC.setDamping(10);

    a = "left_upper_arm";
    b = "left_forearm";
    localA.setFromEulerAnglesRad(PI0_5, 0, 0).trn(0, halfExtMap.get(a).y, 0);
    localB.setFromEulerAnglesRad(PI0_5, 0, 0).trn(0, -halfExtMap.get(b).y, 0);
    this.constraints.add(hingeC = new btHingeConstraint(bodyMap.get(a), bodyMap.get(b), localA, localB));
    hingeC.setLimit(0, PI0_5);

    a = "right_upper_arm";
    b = "right_forearm";
    localA.setFromEulerAnglesRad(PI0_5, 0, 0).trn(0, halfExtMap.get(a).y, 0);
    localB.setFromEulerAnglesRad(PI0_5, 0, 0).trn(0, -halfExtMap.get(b).y, 0);
    this.constraints.add(hingeC = new btHingeConstraint(bodyMap.get(a), bodyMap.get(b), localA, localB));
    hingeC.setLimit(0, PI0_5);

}

From source file:com.mygdx.game.pathfinding.NavMeshGraph.java

License:Apache License

/**
 * Map the isolated edges for each triangle which does not have all three edges connected to other triangles.
 *
 * @param connectionMap//from   www . j a va  2  s. c  o  m
 * @return
 */
private static ArrayMap<Triangle, Array<Edge>> createIsolatedEdgesMap(
        ArrayMap<Triangle, Array<Edge>> connectionMap) {

    ArrayMap<Triangle, Array<Edge>> disconnectionMap = new ArrayMap<Triangle, Array<Edge>>();

    for (int i = 0; i < connectionMap.size; i++) {
        Triangle tri = connectionMap.getKeyAt(i);
        Array<Edge> connectedEdges = connectionMap.getValueAt(i);

        Array<Edge> disconnectedEdges = new Array<Edge>();
        disconnectionMap.put(tri, disconnectedEdges);

        if (connectedEdges.size < 3) {
            // This triangle does not have all edges connected to other triangles
            boolean ab = true;
            boolean bc = true;
            boolean ca = true;
            for (Edge edge : connectedEdges) {
                if (edge.rightVertex == tri.a && edge.leftVertex == tri.b)
                    ab = false;
                else if (edge.rightVertex == tri.b && edge.leftVertex == tri.c)
                    bc = false;
                else if (edge.rightVertex == tri.c && edge.leftVertex == tri.a)
                    ca = false;
            }
            if (ab)
                disconnectedEdges.add(new Edge(tri, null, tri.a, tri.b));
            if (bc)
                disconnectedEdges.add(new Edge(tri, null, tri.b, tri.c));
            if (ca)
                disconnectedEdges.add(new Edge(tri, null, tri.c, tri.a));
        }
        int totalEdges = (connectedEdges.size + disconnectedEdges.size);
        if (totalEdges != 3) {
            Gdx.app.debug(TAG, "Wrong number of edges (" + totalEdges + ") in triangle " + tri.getIndex());
        }
    }
    return disconnectionMap;
}

From source file:com.mygdx.game.pathfinding.NavMeshGraph.java

License:Apache License

/**
 * Creates a map over each triangle and its Edge connections to other triangles. Each edge must follow the
 * vertex winding order of the triangle associated with it. Since all triangles are assumed to have the same
 * winding order, this means if two triangles connect, each must have its own edge connection data, where the
 * edge follows the same winding order as the triangle which owns the edge data.
 *
 * @param indexConnections//from  w ww  .j a  v  a  2 s . c  om
 * @param triangles
 * @param vertexVectors
 * @return
 */
private static ArrayMap<Triangle, Array<Edge>> createSharedEdgesMap(Array<IndexConnection> indexConnections,
        Array<Triangle> triangles, Vector3[] vertexVectors) {

    ArrayMap<Triangle, Array<Edge>> connectionMap = new ArrayMap<Triangle, Array<Edge>>();
    connectionMap.ordered = true;

    for (Triangle tri : triangles) {
        connectionMap.put(tri, new Array<Edge>());
    }

    for (IndexConnection i : indexConnections) {
        Triangle fromNode = triangles.get(i.fromTriIndex);
        Triangle toNode = triangles.get(i.toTriIndex);
        Vector3 edgeVertexA = vertexVectors[i.edgeVertexIndex1];
        Vector3 edgeVertexB = vertexVectors[i.edgeVertexIndex2];

        Edge edge = new Edge(fromNode, toNode, edgeVertexA, edgeVertexB);
        connectionMap.get(fromNode).add(edge);
        fromNode.connections.add(edge);
    }
    return connectionMap;
}

From source file:com.vlaaad.dice.game.objects.Obstacle.java

License:Open Source License

@Override
public ArrayMap<Object, SubView> createSubViews(Player viewer, PlayerColors colors) {
    ArrayMap<Object, SubView> result = new ArrayMap<Object, SubView>();
    result.put(this, new ImageSubView("obstacle/" + worldObjectName));
    return result;
}

From source file:com.vlaaad.dice.game.objects.StepDetector.java

License:Open Source License

@Override
public ArrayMap<Object, SubView> createSubViews(Player viewer, PlayerColors colors) {
    ArrayMap<Object, SubView> result = new ArrayMap<Object, SubView>();
    result.put(this, new StepDetectorSubView(this));
    return result;
}

From source file:com.vlaaad.dice.game.objects.WorldObject.java

License:Open Source License

public ArrayMap<Object, SubView> createSubViews(Player viewer, PlayerColors colors) {
    ArrayMap<Object, SubView> result = new ArrayMap<Object, SubView>();
    result.put(this, new ImageSubView(worldObjectName));
    return result;
}

From source file:de.tomgrill.gdxfacebook.core.utils.Utils.java

License:Apache License

public static ArrayMap<String, String> parseQuery(String query) throws UnsupportedEncodingException {
    ArrayMap<String, String> params = new ArrayMap<String, String>();
    for (String param : query.split("&")) {
        String[] pair = param.split("=");
        String key = URLDecoder.decode(pair[0], "UTF-8");
        String value = URLDecoder.decode(pair[1], "UTF-8");
        params.put(key, value);
    }//from   w  w  w .  j ava  2s  .  co m

    return params;
}

From source file:mobi.shad.s3lib.gfx.effect.BobsMulti.java

License:Apache License

/**
 * Create map of class value/*from  w w  w  . ja va2  s  .  c  o  m*/
 *
 * @param values
 */
@Override
public void getValues(final ArrayMap<String, String> values) {

    values.put("texture", textureFileName);

    values.put("size", String.valueOf(size));

    values.put("count", String.valueOf(count));

    values.put("countSteps", String.valueOf(countSteps));
    values.put("amplitudeAdd", String.valueOf(amplitudeAdd));
    values.put("amplitudeAdd2", String.valueOf(amplitudeAdd2));
    values.put("multiplerAdd", String.valueOf(multiplerAdd));
    values.put("stepAdd", String.valueOf(stepAdd));
    values.put("speedAdd", String.valueOf(speedAdd));

    values.put("speed1", String.valueOf(speed));
    values.put("step1", String.valueOf(step));
    values.put("amplitudeX1", String.valueOf(amplitudeX));
    values.put("amplitudeY1", String.valueOf(amplitudeY));
    values.put("multiplierX1", String.valueOf(multiplierX));
    values.put("multiplierY1", String.valueOf(multiplierY));

    values.put("speed2", String.valueOf(speed2));
    values.put("step2", String.valueOf(step2));
    values.put("amplitudeX2", String.valueOf(amplitudeX2));
    values.put("amplitudeY2", String.valueOf(amplitudeY2));
    values.put("multiplierX2", String.valueOf(multiplierX2));
    values.put("multiplierY2", String.valueOf(multiplierY2));

    values.put("speed3", String.valueOf(speed3));
    values.put("step3", String.valueOf(step3));
    values.put("amplitudeX3", String.valueOf(amplitudeX3));
    values.put("amplitudeY3", String.valueOf(amplitudeY3));
    values.put("multiplierX3", String.valueOf(multiplierX3));
    values.put("multiplierY3", String.valueOf(multiplierY3));
}

From source file:mobi.shad.s3lib.gfx.effect.Copper.java

License:Apache License

/**
 * Create map of class value//  w  ww .j a va2s  .co  m
 *
 * @param values
 */
@Override
public void getValues(ArrayMap<String, String> values) {

    values.put("count", String.valueOf(count));
    values.put("size", String.valueOf(copperSize));
    values.put("positionY", String.valueOf(positionY));

    values.put("speed1", String.valueOf(copperSpeed));
    values.put("step1", String.valueOf(copperStep));
    values.put("amplitude1", String.valueOf(copperAmplitude));
    values.put("multiplier1", String.valueOf(copperMultipler));

    values.put("speed2", String.valueOf(copperSpeed2));
    values.put("step2", String.valueOf(copperStep2));
    values.put("amplitude2", String.valueOf(copperAmplitude2));
    values.put("multiplier2", String.valueOf(copperMultipler2));

    values.put("colorMode", String.valueOf(mode));

    values.put("outSideColor", colorOutSide.toString());
    values.put("inSideColor", colorInSide.toString());
    values.put("inSide2Color", colorInSide2.toString());
    values.put("outSide2Color", colorOutSide2.toString());
}