示例#1
0
  // take outcoming connections from node and build connections array
  private void buildNodeConnections() {
    List<List<Integer>> inboundList =
        new ArrayList<List<Integer>>(); // list of inbound connections for each node
    List<List<NodeConnectionSocket>> sockets =
        new ArrayList<List<NodeConnectionSocket>>(); // list of sockets for each node

    List<NodeConnection> connectionList =
        new ArrayList<NodeConnection>(); // list of node connections

    // filling up lists
    for (int i = 0; i < this.nodes.length; i++) {
      inboundList.add(new ArrayList<Integer>());
      sockets.add(new ArrayList<NodeConnectionSocket>());
    }

    int[] outArray;
    for (int i = 0; i < this.nodes.length; i++) {
      outArray = nodes[i].getOutboundConnections();
      for (int k = 0; k < outArray.length; k++) {
        inboundList.get(outArray[k]).add(i);

        // because of going from bottom to the top
        // it is checked whether current out id is higher, then current node id
        if (outArray[k] > i) {
          int connId = connectionList.size();

          // TODO: add socket position calculation here
          NodeConnectionSocket currNodeSocket =
              new NodeConnectionSocket(0, 0, 0, connId, outArray[k]);
          NodeConnectionSocket endNodeSocket = new NodeConnectionSocket(0, 0, 0, connId, i);

          Vector3f startPos = nodes[i].getPosV().addV(currNodeSocket.getPosV());
          Vector3f endPos = nodes[outArray[k]].getPosV().addV(endNodeSocket.getPosV());

          NodeConnection currConnection = new NodeConnection(i, outArray[k], connId);
          currConnection.setLine(startPos, endPos);

          connectionList.add(currConnection);

          sockets.get(i).add(currNodeSocket);
          sockets.get(outArray[k]).add(endNodeSocket);
        }
      }
    }

    for (int i = 0; i < this.nodes.length; i++) {
      nodes[i].setInboundConnections(inboundList.get(i));
      nodes[i].setSockets(sockets.get(i).toArray(new NodeConnectionSocket[sockets.get(i).size()]));
    }

    this.connections = connectionList.toArray(new NodeConnection[connectionList.size()]);
  }