public static void estimateKeyDerivationTime() {
   // This is run in the background after startup. If we haven't recorded it before, do a key
   // derivation to see
   // how long it takes. This helps us produce better progress feedback, as on Windows we don't
   // currently have a
   // native Scrypt impl and the Java version is ~3 times slower, plus it depends a lot on CPU
   // speed.
   checkGuiThread();
   estimatedKeyDerivationTime = Main.instance.prefs.getExpectedKeyDerivationTime();
   if (estimatedKeyDerivationTime == null) {
     new Thread(
             () -> {
               log.info("Doing background test key derivation");
               KeyCrypterScrypt scrypt = new KeyCrypterScrypt(SCRYPT_PARAMETERS);
               long start = System.currentTimeMillis();
               scrypt.deriveKey("test password");
               long msec = System.currentTimeMillis() - start;
               log.info("Background test key derivation took {}msec", msec);
               Platform.runLater(
                   () -> {
                     estimatedKeyDerivationTime = Duration.ofMillis(msec);
                     Main.instance.prefs.setExpectedKeyDerivationTime(estimatedKeyDerivationTime);
                   });
             })
         .start();
   }
 }
Esempio n. 2
0
  /**
   * Defines the characteristics of a <i>TranslateTransition</i>. Each call results in ONE segment
   * of motion. When that segment is finished, it "chains" another call to <i>startMotion()</i>
   * (which is NOT recursion)! The initial call is made by the managing <i>Army</i> object;
   * subsequent calls are made through the "chaining" process described here.
   *
   * @param engageInCombat TODO
   */
  public void startMotion(boolean engageInCombat) {
    Army opposingArmy = armyAllegiance.getOpposingArmy();
    Actor opponent =
        opposingArmy.findNearestOpponent(
            this); // could legitimately return a null: 1) no one is visible 2) no Actors in
                   // opposing army

    Point2D newLocation;
    if (opponent != null) {
      System.out.printf(
          "ToMove:[%.1f:%.1f] Opponent:[%.1f:%.1f]\n",
          getAvatar().getTranslateX(),
          getAvatar().getTranslateY(),
          opponent.getAvatar().getTranslateX(),
          opponent.getAvatar().getTranslateX());
      double DISTANCE_FOR_BATTLE = 50.0;
      if (engageInCombat && distanceTo(opponent) < DISTANCE_FOR_BATTLE) {
        double h1, h2, h3, h4; // debug code
        h1 = this.getHealth();
        h2 = opponent.getHealth();

        combatRound(opponent);
        h3 = this.getHealth();
        h4 = opponent.getHealth();
        h4 = h4;
        if (this.getHealth() <= 0.0) {
          armyAllegiance.removeNowDeadActor(this);
        }
        if (opponent.getHealth() <= 0.0) {
          opponent.armyAllegiance.removeNowDeadActor(opponent);
        }
      } // end if (combat)
      newLocation = findNewLocation(opponent);
    } else // end if (test for null opponent)
    newLocation = meander(); // null opponent means we wander around close to our current location

    if (tt.getStatus()
        != Animation.Status.RUNNING) { // if NOT yet RUNNING, start . . . otherwise, do nothing.
      // tt.setToX(Math.random()*getAvatar().getScene().getWidth());
      // tt.setToY(Math.random()*getAvatar().getScene().getHeight());
      tt.setToX(validateCoordinate(newLocation).getX());
      tt.setToY(validateCoordinate(newLocation).getY());
      tt.setDuration(
          Duration.seconds(MAX_SPEED / (getSpeed() * (armyAllegiance.getSpeedControllerValue()))));
      tt.setOnFinished(event -> startMotion(true)); // NOT RECURSION!!!!
      tt
          .play(); // give assembled object to the render engine (of course, play() is an
                   // object-oriented method which has access to "this" inside, and it can use
                   // "this" to give to the render engine.
    }
  } // end startMotion()