Example #1
0
  /**
   * Runs the main loop. Several number of world steps (according to worldStepsPerLoop property) is
   * taken, a friction coefficient is set up to all Actives and Passives, the VivaeObjects are
   * moved, if the visible output is turned on, the painting method is called and the thread sleeps
   * for a several (according to loopSleepTime property) milisecs.
   */
  @Override
  public void run() {
    //        while (true) {
    while (isRunning) {
      for (int i = 0; i < worldStepsPerLoop; i++) {
        world.step();
        //                if (stepsDone % 100 == 0) {
        //                    System.out.println("println = "+stepsDone);

        //                }
        if (capture) {
          if (stepsDone % 5 == 0) {
            String s = new PrintfFormat("%06d").sprintf(stepsDone);
            this.captureToSVG("step" + s + ".svg");
          }
        }
        stepsDone++;
      }
      if (stepsDone > totalStepsPerSimulation) isRunning = false;
      for (Active active : getActives()) {
        // active.setDamping(getFrictionOfSurface(active));  //speedup
        active.setDamping(
            (float) frictionBuffer.getFriction((int) active.getX(), (int) active.getY()));
      }
      for (Passive passive : getPassives()) {
        // passive.setDamping(getFrictionOfSurface(passive));  //speedup
        passive.setDamping(
            (float) frictionBuffer.getFriction((int) passive.getX(), (int) passive.getY()));
      }
      moveVivaes();

      if (isVisible && loopSleepTime > 0) {
        repaint();
        if (loopSleepTime > 0) {
          try {
            Thread.sleep(loopSleepTime);
          } catch (InterruptedException e) {
            e.printStackTrace();
          }
        }
      }
    }
  }