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;
        }
    }
main loop - periodically copy location data into Lua and evaluate zone positions
main/src/main/java/cgeo/geocaching/wherigo/openwig/Engine.java