Example #1
0
  /** 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;
    }
  }
Example #2
0
 /** Gets a Location entity by its exact name. */
 public static Location getLocationByName(String locationName, Location parent) {
   LocationService locationService = Context.getLocationService();
   Location location = locationService.getLocation(locationName);
   if (location == null) {
     location = new Location();
     location.setName(locationName);
     location.setDescription(locationName);
     if (parent != null) {
       location.setParentLocation(parent);
     }
     locationService.saveLocation(location);
   }
   return location;
 }
Example #3
0
 /** 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();
   }
 }