コード例 #1
0
ファイル: EventsTester.java プロジェクト: bennylut/azapi-test
  /**
   * this method maintains the dyanmic coloring, makes sure that entities are added and removed to
   * their current edges, and from a certain threshold, added to the dynamic coloring group.
   *
   * @param from
   * @param to
   * @param startPrecent
   * @param who
   * @param boundingQuery
   * @param endPrecent
   */
  private void maintainDynamicColoring(
      String from,
      String to,
      double startPrecent,
      Integer who,
      GroupBoundingQuery boundingQuery,
      double endPrecent) {
    String edge = from + " " + to;
    if (!graphData.getEdgeSet().contains(edge)) {
      String[] split = edge.split(" ");
      edge = split[1] + " " + split[0];
    }
    AZVisVertex sV = (AZVisVertex) graphData.getData(edge.split(" ")[0]);
    AZVisVertex tV = (AZVisVertex) graphData.getData(edge.split(" ")[1]);

    Edge temp = (Edge) boundingQuery.getById(edge + " dynamic");
    if (temp == null) {
      temp = new Edge(edge + " dynamic");
    }

    // what happens if start=0 and end=100 at the same time???
    if (startPrecent == 0) {
      String oldEdge = graphData.removeEdgeEntity(who.toString());
      Edge oldTemp = null;
      if (oldEdge != null) {
        //                String[] split = oldEdge.split(" ");
        //                oldEdge = split[0] + " " + split[1];
        oldTemp = (Edge) boundingQuery.getById(oldEdge + " dynamic");
      }

      if (oldTemp != null) {
        int numEdges = graphData.getEdgeEntities(oldEdge).size();
        if (numEdges <= THRESHOLD) {
          Object removed =
              boundingQuery.remove("DYNAMIC_COLORED", "EDGES", sV.getX(), sV.getY(), oldTemp);
        }
      }

      graphData.addEntityToEdge(edge, who.toString());
      int numEdges = graphData.getEdgeEntities(edge).size();
      if (numEdges == THRESHOLD + 1) {
        boundingQuery.addToGroup(
            "DYNAMIC_COLORED",
            "EDGES",
            sV.getX(),
            sV.getY(),
            Math.abs(sV.getX() - tV.getX()),
            Math.abs(sV.getY() - tV.getY()),
            temp);
      }
    }
  }
コード例 #2
0
ファイル: EventsTester.java プロジェクト: bennylut/azapi-test
  public void AddNewMovesFromTick(
      Tick tick, SimplePlayer player, GroupBoundingQuery boundingQuery) {

    Collection<SimulatorEvent> events = tick.getEvents();
    Set<String> edgeSet = graphData.getEdgeSet();
    BasicOperationsFrame frame = new BasicOperationsFrame();
    for (Object event : events) {
      if (event instanceof MoveEvent) {
        MoveEvent movee = (MoveEvent) event;
        Integer who = movee.getId();
        String from = movee.getFromNode();
        String to = movee.getToNode();
        double startPrecent = movee.getStartPrecent();
        double endPrecent = movee.getEndPrecent();
        Location startLocation = translateToLocation(from, to, startPrecent);
        Location endLocation = translateToLocation(from, to, endPrecent);
        frame.directedMove(who, startLocation, endLocation);
        maintainDynamicColoring(from, to, startPrecent, who, boundingQuery, endPrecent);
      }
      if (event instanceof ParkingEvent) {
        ParkingEvent parke = (ParkingEvent) event;
        ParkingLotEntity ple =
            (ParkingLotEntity) boundingQuery.getById("parking" + parke.getParkNodeId());
        if (ple != null && parke.getInOut() == ParkingEvent.InOut.IN) {
          ple.addToData(parke.getPrecentage(), parke.getCarType());
        }
      }
    }
    player.playNextFrame(frame);
  }