started = false;
    public void run() {        initSystem();        assertDisplayCreated();        initGame();        if (type == GameType.GRAPHICAL) {            timer = Timer.getTimer();        } else if (type == GameType.HEADLESS) {            timer = new NanoTimer();        }        // Configure frame rate        int preferredFPS = settings.getFramerate();        long preferredTicksPerFrame = -1;        long frameStartTick = -1;        long frames = 0;        long frameDurationTicks = -1;        if (preferredFPS >= 0) {            preferredTicksPerFrame = Math.round((float)timer.getResolution() / (float)preferredFPS);        }                // Main game loop        try {            float tpf;            started = true;            while ((!finished) && (!display.isClosing())) {                // Fixed framerate Start                if (preferredTicksPerFrame >= 0) {                    frameStartTick = timer.getTime();                }                                timer.update();                tpf = timer.getTimePerFrame();                                if (type == GameType.GRAPHICAL) {                    InputSystem.update();                }                update(tpf);                render(tpf);                display.getRenderer().displayBackBuffer();                                // Fixed framerate End                if (preferredTicksPerFrame >= 0) {                    frames++;                    frameDurationTicks = timer.getTime() - frameStartTick;                    while (frameDurationTicks < preferredTicksPerFrame) {                        long sleepTime = ((preferredTicksPerFrame - frameDurationTicks) * 1000) / timer.getResolution();                        try {                            Thread.sleep(sleepTime);                        } catch(InterruptedException exc) {                            LoggingSystem.getLogger().log(Level.SEVERE, "Interrupted while sleeping in fixed-framerate", exc);                        }                        frameDurationTicks = timer.getTime() - frameStartTick;                    }                    if (frames == Long.MAX_VALUE) frames = 0;                }                                Thread.yield();            }            started = false;        } catch(Throwable t) {            LoggingSystem.getLogger().log(Level.SEVERE, "Main game loop broken by uncaught exception", t);        }        cleanup();        quit();    }