public void run() { int currentTPS = 0; int currentFPS = 0; double fpsTimer = System.currentTimeMillis(); double then = System.nanoTime(); double now; double unprocessed = 0; init(); while (isRunning) { now = System.nanoTime(); unprocessed += (now - then) / NS_PER_TICK; then = now; while (unprocessed >= 1) { update(); currentTPS++; unprocessed--; } render(); currentFPS++; try { Thread.sleep(1); } catch (InterruptedException e) { } if (System.currentTimeMillis() - fpsTimer >= 1000) { System.out.printf("FPS: %d TPS %d%n", currentFPS, currentTPS); currentFPS = 0; currentTPS = 0; fpsTimer += 1000; } } frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING)); }
public void render() { frame.render(); }