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

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

Introduction

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

Prototype

public K getKeyAt(int index) 

Source Link

Usage

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  w  w w.ja v  a 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:de.tomgrill.gdxfacebook.iosmoe.IOSMOEGDXFacebook.java

License:Apache License

@Override
public void graph(Request request, GDXFacebookCallback<JsonResult> callback) {
    if (!(request instanceof AbstractRequest)) {
        callback.onError(new GDXFacebookError("Request is not an AbstractRequest!"));
        return;// w  ww. j  a v a2s  .c o m
    }

    NSMutableDictionary converted = NSMutableDictionary.dictionary();
    ArrayMap<String, String> fields = ((AbstractRequest) request).getFields();
    for (int i = 0, size = fields.size; i < size; i++) {
        converted.put(fields.getKeyAt(i), fields.getValueAt(i));
    }

    FBSDKGraphRequest graphRequest = FBSDKGraphRequest.alloc().initWithGraphPathParameters(request.getNode(),
            converted);
    graphRequest.startWithCompletionHandler(new FBSDKGraphRequest.Block_startWithCompletionHandler() {
        @Override
        public void call_startWithCompletionHandler(FBSDKGraphRequestConnection connection,
                @Mapped(ObjCObjectMapper.class) Object result, NSError error) {
            if (error == null) {
                Gdx.app.debug("Graph request ", "success!");
                NSData nsData = NSJSONSerialization.dataWithJSONObjectOptionsError(result,
                        NSJSONReadingOptions.MutableContainers, (Ptr<NSError>) error);
                NSString alloc = NSString.alloc();
                NSString nsString = alloc.initWithDataEncoding(nsData, Enums.NSUTF8StringEncoding);
                callback.onSuccess(new JsonResult(nsString.toString()));
            } else {
                Gdx.app.debug("Error graph", error.localizedDescription());
                callback.onError(new GDXFacebookError(error.localizedDescription()));
            }
        }
    });
}