public void run() {
        long lastTime = System.nanoTime(), lastTimer = System.currentTimeMillis();
        double delta = 0, ns = 1000000000D / 60D;
        int ticks = 0, frames = 0;

        init();

        while (running) {
            long now = System.nanoTime();
            delta += (now - lastTime) / ns;
            lastTime = now;
            boolean shouldRender = true;

            while (delta >= 1) {
                tick();
                ticks++;
                delta--;
                shouldRender = true;
            }

            if (shouldRender) {
                render();
                frames++;
            }

            if (System.currentTimeMillis() - lastTimer >= 1000) {
                lastTimer += 1000;
                System.out.println(ticks + " ticks, " + frames + " frames");
                ticks = 0;
                frames = 0;
            }
        }
    }