Пример #1
0
  static void removeFromLayers(Shape shape) {
    if (!layerOf.containsKey(shape)) return;

    int oldLayer = layerOf.get(shape);
    layerContents.get(oldLayer).remove(shape);
    if (layerContents.get(oldLayer).isEmpty()) {
      layerContents.remove(oldLayer);
      layers.remove((Integer) oldLayer);
    }
    layerOf.remove(shape);
  }
Пример #2
0
  /**
   * Set the layer that a given shape will be displayed in. Since the shapes in this game are two
   * dimensional, it must be decided which will appear "on top" when two shapes overlap. The shape
   * in the higher layer will appear on top.
   *
   * <p>Setting a shape's layer will only affect how it is displayed; a shape's layer has no effect
   * on how it interacts with other shapes. (For example, two shapes can touch even if they are in
   * different layers. See {@link Shape#isTouching(Shape)}.)
   *
   * @param shape the shape whose layer is being set.
   * @param layer the layer into which this shape will be moved.
   */
  static void setLayer(Shape shape, int layer) {
    removeFromLayers(shape);

    // add new stuff
    if (!layerContents.containsKey(layer)) {
      layerContents.put(layer, new CopyOnWriteArrayList<Shape>());
      int insertionPoint = ~Collections.binarySearch(layers, layer);
      layers.add(insertionPoint, layer);
    }
    layerContents.get(layer).add(shape);
    layerOf.put(shape, layer);
  }
Пример #3
0
 static void removeCounter(Counter counter) {
   counters.remove(counter);
 }
Пример #4
0
 static void addCounter(Counter counter) {
   counters.add(counter);
 }
  public boolean execute() {
    if (CDState.getCycle() % period != 0) return false;

    MycoCast mycocast = (MycoCast) Network.get(0).getProtocol(mycocastPid);

    int bio = mycocast.countBiomass();
    int ext = mycocast.countExtending();
    int bra = mycocast.countBranching();
    int imm = mycocast.countImmobile();

    // Update vertices
    Set<MycoNode> activeNodes = new HashSet<MycoNode>();
    for (int i = 0; i < Network.size(); i++) {
      MycoNode n = (MycoNode) Network.get(i);
      activeNodes.add(n);
      HyphaData data = n.getHyphaData();
      // if (data.isBiomass()) { continue; }
      if (graph.containsVertex(n)) {
        graph.removeVertex(n);
      }
      if (!graph.containsVertex(n)) {
        graph.addVertex(n);
      }
    }
    Set<MycoNode> jungNodes = new HashSet<MycoNode>(graph.getVertices());
    jungNodes.removeAll(activeNodes);

    for (MycoNode n : jungNodes) {
      graph.removeVertex(n);
    }

    // Update edges
    for (int i = 0; i < Network.size(); i++) {
      MycoNode n = (MycoNode) Network.get(i);
      HyphaData data = n.getHyphaData();
      HyphaLink link = n.getHyphaLink();

      synchronized (graph) {

        // We now add in all links and tune out display in Visualizer
        java.util.List<MycoNode> neighbors = (java.util.List<MycoNode>) link.getNeighbors();

        //// Adding only links to hypha thins out links to biomass
        //    (java.util.List<MycoNode>) link.getHyphae();

        Collection<MycoNode> jungNeighbors = graph.getNeighbors(n);

        // Remove edges from Jung graph that are not in peersim graph
        for (MycoNode o : jungNeighbors) {
          if (!neighbors.contains(o)) {
            MycoEdge edge = graph.findEdge(n, o);
            while (edge != null) {
              graph.removeEdge(edge);
              edge = graph.findEdge(n, o);
            }
          }
        }

        // Add missing edges to Jung graph that are in peersim graph
        for (MycoNode o : neighbors) {
          if (graph.findEdge(n, o) == null) {
            MycoEdge edge = new MycoEdge();
            graph.addEdge(edge, n, o, EdgeType.DIRECTED);
          }
        }
      }

      // log.finest("VERTICES: " + graph.getVertices());
      // log.finest("EDGES: " + graph.getEdges());
    }

    for (ChangeListener cl : changeListeners) {
      cl.stateChanged(new ChangeEvent(graph));
    }
    if (walking) {
      try {
        Thread.sleep(walkDelay);
      } catch (InterruptedException e) {
      }
      stepBlocked = false;
    }

    try {
      while (stepBlocked && !noBlock) {
        synchronized (JungGraphObserver.class) {
          JungGraphObserver.class.wait();
        }
      }
    } catch (InterruptedException e) {
      stepBlocked = true;
    }
    stepBlocked = true;
    // System.out.println(graph.toString());
    return false;
  }