예제 #1
0
파일: Engine.java 프로젝트: Eway/whereigo
  /** main loop - periodically copy location data into Lua and evaluate zone positions */
  private void mainloop() {
    try {
      while (!end) {
        try {
          if (gps.getLatitude() != player.position.latitude
              || gps.getLongitude() != player.position.longitude
              || gps.getAltitude() != player.position.altitude) {
            player.refreshLocation();
          }
          cartridge.tick();
        } catch (Exception e) {
          stacktrace(e);
        }

        try {
          Thread.sleep(1000);
        } catch (InterruptedException e) {
        }
      }
      if (log != null) log.close();
    } catch (Throwable t) {
      ui.end();
      stacktrace(t);
    } finally {
      instance = null;
      state = null;
      if (eventRunner != null) eventRunner.kill();
      eventRunner = null;
    }
  }
예제 #2
0
파일: Engine.java 프로젝트: Eway/whereigo
 /** tries to log the specified message, if verbosity is higher than its level */
 public static void log(String s, int level) {
   if (instance == null || instance.log == null) return;
   if (level < instance.loglevel) return;
   synchronized (instance.log) {
     Calendar now = Calendar.getInstance();
     instance.log.print(now.get(Calendar.HOUR_OF_DAY));
     instance.log.print(':');
     instance.log.print(now.get(Calendar.MINUTE));
     instance.log.print(':');
     instance.log.print(now.get(Calendar.SECOND));
     instance.log.print('|');
     instance.log.print((int) (gps.getLatitude() * 10000 + 0.5) / 10000.0);
     instance.log.print('|');
     instance.log.print((int) (gps.getLongitude() * 10000 + 0.5) / 10000.0);
     instance.log.print('|');
     instance.log.print(gps.getAltitude());
     instance.log.print('|');
     instance.log.print(gps.getPrecision());
     instance.log.print("|:: ");
     instance.log.println(s);
     instance.log.flush();
   }
 }