use of com.badlogic.gdx.LifecycleListener in project libgdx by libgdx.
the class LwjglApplication method mainLoop.
void mainLoop() {
SnapshotArray<LifecycleListener> lifecycleListeners = this.lifecycleListeners;
try {
graphics.setupDisplay();
} catch (LWJGLException e) {
throw new GdxRuntimeException(e);
}
listener.create();
graphics.resize = true;
int lastWidth = graphics.getWidth();
int lastHeight = graphics.getHeight();
graphics.lastTime = System.nanoTime();
boolean wasActive = true;
while (running) {
Display.processMessages();
if (Display.isCloseRequested())
exit();
boolean isActive = Display.isActive();
if (wasActive && !isActive) {
// if it's just recently minimized from active state
wasActive = false;
synchronized (lifecycleListeners) {
LifecycleListener[] listeners = lifecycleListeners.begin();
for (int i = 0, n = lifecycleListeners.size; i < n; ++i) listeners[i].pause();
lifecycleListeners.end();
}
listener.pause();
}
if (!wasActive && isActive) {
// if it's just recently focused from minimized state
wasActive = true;
synchronized (lifecycleListeners) {
LifecycleListener[] listeners = lifecycleListeners.begin();
for (int i = 0, n = lifecycleListeners.size; i < n; ++i) listeners[i].resume();
lifecycleListeners.end();
}
listener.resume();
}
boolean shouldRender = false;
if (graphics.canvas != null) {
int width = graphics.canvas.getWidth();
int height = graphics.canvas.getHeight();
if (lastWidth != width || lastHeight != height) {
lastWidth = width;
lastHeight = height;
Gdx.gl.glViewport(0, 0, lastWidth, lastHeight);
listener.resize(lastWidth, lastHeight);
shouldRender = true;
}
} else {
graphics.config.x = Display.getX();
graphics.config.y = Display.getY();
if (graphics.resize || Display.wasResized() || (int) (Display.getWidth() * Display.getPixelScaleFactor()) != graphics.config.width || (int) (Display.getHeight() * Display.getPixelScaleFactor()) != graphics.config.height) {
graphics.resize = false;
graphics.config.width = (int) (Display.getWidth() * Display.getPixelScaleFactor());
graphics.config.height = (int) (Display.getHeight() * Display.getPixelScaleFactor());
Gdx.gl.glViewport(0, 0, graphics.config.width, graphics.config.height);
if (listener != null)
listener.resize(graphics.config.width, graphics.config.height);
graphics.requestRendering();
}
}
if (executeRunnables())
shouldRender = true;
// If one of the runnables set running to false, for example after an exit().
if (!running)
break;
input.update();
shouldRender |= graphics.shouldRender();
input.processEvents();
if (audio != null)
audio.update();
if (!isActive && graphics.config.backgroundFPS == -1)
shouldRender = false;
int frameRate = isActive ? graphics.config.foregroundFPS : graphics.config.backgroundFPS;
if (shouldRender) {
graphics.updateTime();
graphics.frameId++;
listener.render();
Display.update(false);
} else {
// Sleeps to avoid wasting CPU in an empty loop.
if (frameRate == -1)
frameRate = 10;
if (frameRate == 0)
frameRate = graphics.config.backgroundFPS;
if (frameRate == 0)
frameRate = 30;
}
if (frameRate > 0)
Display.sync(frameRate);
}
synchronized (lifecycleListeners) {
LifecycleListener[] listeners = lifecycleListeners.begin();
for (int i = 0, n = lifecycleListeners.size; i < n; ++i) {
listeners[i].pause();
listeners[i].dispose();
}
lifecycleListeners.end();
}
listener.pause();
listener.dispose();
Display.destroy();
if (audio != null)
audio.dispose();
if (graphics.config.forceExit)
System.exit(-1);
}
use of com.badlogic.gdx.LifecycleListener in project libgdx by libgdx.
the class Lwjgl3Application method cleanupWindows.
private void cleanupWindows() {
synchronized (lifecycleListeners) {
for (LifecycleListener lifecycleListener : lifecycleListeners) {
lifecycleListener.pause();
lifecycleListener.dispose();
}
}
for (Lwjgl3Window window : windows) {
window.dispose();
}
windows.clear();
}
use of com.badlogic.gdx.LifecycleListener in project libgdx by libgdx.
the class JglfwApplication method end.
/** Called when the game loop has exited. */
protected void end() {
synchronized (lifecycleListeners) {
for (LifecycleListener listener : lifecycleListeners) {
listener.pause();
listener.dispose();
}
}
listener.pause();
listener.dispose();
glfwTerminate();
if (forceExit)
System.exit(-1);
}
use of com.badlogic.gdx.LifecycleListener in project libgdx by libgdx.
the class AndroidDaydream method init.
private void init(ApplicationListener listener, AndroidApplicationConfiguration config, boolean isForView) {
setApplicationLogger(new AndroidApplicationLogger());
graphics = new AndroidGraphics(this, config, config.resolutionStrategy == null ? new FillResolutionStrategy() : config.resolutionStrategy);
input = AndroidInputFactory.newAndroidInput(this, this, graphics.view, config);
audio = new AndroidAudio(this, config);
// workaround for Android bug #10515463
this.getFilesDir();
files = new AndroidFiles(this.getAssets(), this.getFilesDir().getAbsolutePath());
net = new AndroidNet(this);
this.listener = listener;
this.handler = new Handler();
this.clipboard = new AndroidClipboard(this);
// Add a specialized audio lifecycle listener
addLifecycleListener(new LifecycleListener() {
@Override
public void resume() {
audio.resume();
}
@Override
public void pause() {
audio.pause();
}
@Override
public void dispose() {
audio.dispose();
audio = null;
}
});
Gdx.app = this;
Gdx.input = this.getInput();
Gdx.audio = this.getAudio();
Gdx.files = this.getFiles();
Gdx.graphics = this.getGraphics();
Gdx.net = this.getNet();
if (!isForView) {
setFullscreen(true);
setContentView(graphics.getView(), createLayoutParams());
}
createWakeLock(config.useWakelock);
hideStatusBar(config);
}
use of com.badlogic.gdx.LifecycleListener in project libgdx by libgdx.
the class IOSGraphics method resume.
public void resume() {
if (!appPaused)
return;
appPaused = false;
Array<LifecycleListener> listeners = app.lifecycleListeners;
synchronized (listeners) {
for (LifecycleListener listener : listeners) {
listener.resume();
}
}
app.listener.resume();
}
Aggregations