Search in sources :

Example 1 with OpenALAudio

use of com.badlogic.gdx.backends.lwjgl3.audio.OpenALAudio in project libgdx by libgdx.

the class Lwjgl3Application method loop.

private void loop() {
    Array<Lwjgl3Window> closedWindows = new Array<Lwjgl3Window>();
    while (running && windows.size > 0) {
        // FIXME put it on a separate thread
        if (audio instanceof OpenALAudio) {
            ((OpenALAudio) audio).update();
        }
        boolean haveWindowsRendered = false;
        closedWindows.clear();
        for (Lwjgl3Window window : windows) {
            window.makeCurrent();
            currentWindow = window;
            synchronized (lifecycleListeners) {
                haveWindowsRendered |= window.update();
            }
            if (window.shouldClose()) {
                closedWindows.add(window);
            }
        }
        GLFW.glfwPollEvents();
        boolean shouldRequestRendering;
        synchronized (runnables) {
            shouldRequestRendering = runnables.size > 0;
            executedRunnables.clear();
            executedRunnables.addAll(runnables);
            runnables.clear();
        }
        for (Runnable runnable : executedRunnables) {
            runnable.run();
        }
        if (shouldRequestRendering) {
            // in the following render.
            for (Lwjgl3Window window : windows) {
                if (!window.getGraphics().isContinuousRendering())
                    window.requestRendering();
            }
        }
        for (Lwjgl3Window closedWindow : closedWindows) {
            if (windows.size == 1) {
                // when there is only 1 window left, which is in the process of being disposed.
                for (int i = lifecycleListeners.size - 1; i >= 0; i--) {
                    LifecycleListener l = lifecycleListeners.get(i);
                    l.pause();
                    l.dispose();
                }
                lifecycleListeners.clear();
            }
            closedWindow.dispose();
            windows.removeValue(closedWindow, false);
        }
        if (!haveWindowsRendered) {
            // with continuous rendering disabled.
            try {
                Thread.sleep(1000 / config.idleFPS);
            } catch (InterruptedException e) {
            // ignore
            }
        }
    }
}
Also used : Array(com.badlogic.gdx.utils.Array) OpenALAudio(com.badlogic.gdx.backends.lwjgl3.audio.OpenALAudio) LifecycleListener(com.badlogic.gdx.LifecycleListener)

Aggregations

LifecycleListener (com.badlogic.gdx.LifecycleListener)1 OpenALAudio (com.badlogic.gdx.backends.lwjgl3.audio.OpenALAudio)1 Array (com.badlogic.gdx.utils.Array)1