List of usage examples for com.badlogic.gdx LifecycleListener dispose
public void dispose();
From source file:com.badlogic.gdx.backends.android.CardBoardGraphics.java
License:Apache License
@Override public void onNewFrame(HeadTransform arg0) { long time = System.nanoTime(); deltaTime = (time - lastFrameTime) / 1000000000.0f; lastFrameTime = time;/*from ww w . ja v a 2 s . c om*/ // After pause deltaTime can have somewhat huge value that destabilizes the mean, so let's cut it off if (!resume) { mean.addValue(deltaTime); } else { deltaTime = 0; } boolean lrunning = false; boolean lpause = false; boolean ldestroy = false; boolean lresume = false; synchronized (synch) { lrunning = running; lpause = pause; ldestroy = destroy; lresume = resume; if (resume) { resume = false; } if (pause) { pause = false; synch.notifyAll(); } if (destroy) { destroy = false; synch.notifyAll(); } } if (lresume) { Array<LifecycleListener> listeners = app.getLifecycleListeners(); synchronized (listeners) { for (LifecycleListener listener : listeners) { listener.resume(); } } app.getApplicationListener().resume(); Gdx.app.log(LOG_TAG, "resumed"); } if (lrunning) { synchronized (app.getRunnables()) { app.getExecutedRunnables().clear(); app.getExecutedRunnables().addAll(app.getRunnables()); app.getRunnables().clear(); } for (int i = 0; i < app.getExecutedRunnables().size; i++) { try { app.getExecutedRunnables().get(i).run(); } catch (Throwable t) { t.printStackTrace(); } } app.getInput().processEvents(); frameId++; app.getApplicationListener().render(); } if (lpause) { Array<LifecycleListener> listeners = app.getLifecycleListeners(); synchronized (listeners) { for (LifecycleListener listener : listeners) { listener.pause(); } } app.getApplicationListener().pause(); Gdx.app.log(LOG_TAG, "paused"); } if (ldestroy) { Array<LifecycleListener> listeners = app.getLifecycleListeners(); synchronized (listeners) { for (LifecycleListener listener : listeners) { listener.dispose(); } } app.getApplicationListener().dispose(); disposed = true; Gdx.app.log(LOG_TAG, "destroyed"); } if (time - frameStart > 1000000000) { fps = frames; frames = 0; frameStart = time; } frames++; if (!(app.getApplicationListener() instanceof CardBoardApplicationListener)) { throw new RuntimeException( "should implement com.badlogic.gdx.backends.android.CardBoardApplicationListener"); } if (!disposed) { ((CardBoardApplicationListener) app.getApplicationListener()).onNewFrame(arg0); } }
From source file:net.pevnostgames.lwjglserver.ServerApplication.java
License:Apache License
private void mainLoop() { listener.create();/*from w w w .j a v a2s. c o m*/ lastTime = System.nanoTime(); while (running) { boolean shouldRender = (System.nanoTime() - lastTime) / 1000000000.0f >= targetDelta; synchronized (runnables) { executedRunnables.clear(); executedRunnables.addAll(runnables); runnables.clear(); } for (int i = 0; i < executedRunnables.size; i++) { shouldRender = true; executedRunnables.get(i).run(); // calls out to random app code that could do anything ... } // If one of the runnables set running to false, for example after an exit(). if (!running) break; if (shouldRender) { long time = System.nanoTime(); deltaTime = (time - lastTime) / 1000000000.0f; lastTime = time; listener.render(); } } Array<LifecycleListener> listeners = lifecycleListeners; synchronized (listeners) { for (LifecycleListener listener : listeners) { listener.pause(); listener.dispose(); } } listener.pause(); listener.dispose(); }