Пример #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;
    }
  }
Пример #2
0
  /** thread's run() method that does all the work in the right order */
  public void run() {
    try {
      if (log != null)
        log.println(
            "-------------------\ncartridge "
                + gwcfile.name
                + " started (openWIG r"
                + VERSION
                + ")\n-------------------");
      prepareState();

      if (doRestore) restoreGame();
      else newGame();

      loglevel = LOG_PROP;

      ui.debugMsg("Starting game...\n");
      ui.start();

      player.refreshLocation();
      cartridge.callEvent(doRestore ? "OnRestore" : "OnStart", null);
      ui.refresh();
      eventRunner.unpause();

      mainloop();
    } catch (IOException e) {
      ui.showError("Could not load cartridge: " + e.getMessage());
    } catch (Throwable t) {
      stacktrace(t);
    } finally {
      ui.end();
    }
  }
Пример #3
0
  /** invokes creation of clean new game environment */
  private void newGame() throws IOException {
    // starting game normally
    ui.debugMsg("Loading gwc...");
    if (gwcfile == null) throw new IOException("invalid cartridge file");

    ui.debugMsg("pre-setting properties...");
    player.rawset("CompletionCode", gwcfile.code);
    player.rawset("Name", gwcfile.member);

    ui.debugMsg("loading code...");
    byte[] lbc = gwcfile.getBytecode();

    ui.debugMsg("parsing...");
    LuaClosure closure =
        LuaPrototype.loadByteCode(new ByteArrayInputStream(lbc), state.getEnvironment());

    ui.debugMsg("calling...\n");
    state.call(closure, null, null, null);
    lbc = null;
    closure = null;
  }