/** Called when the game loop has exited. */ protected void end () { synchronized (lifecycleListeners) { for (LifecycleListener listener : lifecycleListeners) { listener.pause(); listener.dispose(); } } listener.pause(); listener.dispose(); if (audio != null) { audio.dispose(); } glfwReleaseCallbacks(graphics.window); glfwTerminate(); if (forceExit) System.exit(-1); }
/** * @throws InitException If a fatal error occurs during initialization. */ public void start() throws InitException { DesktopGdxFileSystem gdxFileSystem = openResourceFileSystem(new File(".")); IWritableFileSystem outputFileSystem = new DesktopOutputFileSystem(FileType.Local, "save/"); final Launcher launcher = new Launcher(gdxFileSystem, outputFileSystem) { @Override public void create() { DesktopGraphicsUtil.setWindowIcon(gdxFileSystem); windowedSize = DesktopGraphicsUtil.limitInitialWindowSize(Gdx.graphics); super.create(); } @Override public void resize(int width, int height) { super.resize(width, height); if (!Gdx.graphics.isFullscreen()) { windowedSize = Dim.of(width, height); } } @Override protected void handleInput(INativeInput input) { super.handleInput(input); DesktopLauncher.this.handleInput(input); } }; NovelPrefsStore prefs = launcher.loadPreferences(); handleCommandlineOptions(prefs); Lwjgl3ApplicationConfiguration config = createConfig(launcher, prefs); Lwjgl3Application app = new Lwjgl3Application(launcher, config); app.addLifecycleListener(new LifecycleListener() { @Override public void resume() { LOG.info("App resume"); } @Override public void pause() { LOG.info("App pause"); } @Override public void dispose() { LOG.info("App dispose"); } }); }
/** 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); }
public void pause () { if (appPaused) return; appPaused = true; Array<LifecycleListener> listeners = app.lifecycleListeners; synchronized (listeners) { for (LifecycleListener listener : listeners) { listener.pause(); } } app.listener.pause(); }
final void willTerminate (UIApplication uiApp) { Gdx.app.debug("IOSApplication", "disposed"); graphics.makeCurrent(); Array<LifecycleListener> listeners = lifecycleListeners; synchronized (listeners) { for (LifecycleListener listener : listeners) { listener.pause(); } } listener.dispose(); Gdx.gl.glFlush(); }
public void stop () { EventQueue.invokeLater(new Runnable() { public void run () { if (!running) return; running = false; try { Display.destroy(); if (audio != null) audio.dispose(); } catch (Throwable ignored) { } Array<LifecycleListener> listeners = lifecycleListeners; synchronized (listeners) { for (LifecycleListener listener : listeners) { listener.pause(); listener.dispose(); } } listener.pause(); listener.dispose(); } }); }
public void stop () { if (!running) return; running = false; setGlobals(); Array<LifecycleListener> listeners = lifecycleListeners; // To allow destroying of OpenGL textures during disposal. if (canvas.isDisplayable()) { makeCurrent(); } else { error(logTag, "OpenGL context destroyed before application listener has had a chance to dispose of textures."); } synchronized (listeners) { for (LifecycleListener listener : listeners) { listener.pause(); listener.dispose(); } } listener.pause(); listener.dispose(); Gdx.app = null; Gdx.graphics = null; if (audio != null) { audio.dispose(); Gdx.audio = null; } if (files != null) Gdx.files = null; if (net != null) Gdx.net = null; stopped(); }
@Override public void removeLifecycleListener (LifecycleListener listener) { synchronized (lifecycleListeners) { lifecycleListeners.removeValue(listener, true); } }
public OculusImplementation() { VirtualReality.implementation = this; VirtualReality.head = new Head(); VirtualReality.body = new Body(); VirtualReality.renderer = new VirtualRealityRenderer(); OvrLibrary.INSTANCE.ovr_Initialize(); hmd = OvrLibrary.INSTANCE.ovrHmd_CreateDebug(0); VirtualReality.headMountedDisplay = new OculusHMD(hmd); Gdx.app.addLifecycleListener(new LifecycleListener() { @Override public void resume() { } @Override public void pause() { } @Override public void dispose() { OvrLibrary.INSTANCE.ovr_Shutdown(); } }); }
public void addLifecycleListener (LifecycleListener listener) { synchronized (lifecycleListeners) { lifecycleListeners.add(listener); } }
public void resume () { if (!appPaused) return; appPaused = false; Array<LifecycleListener> listeners = app.lifecycleListeners; synchronized (listeners) { for (LifecycleListener listener : listeners) { listener.resume(); } } app.listener.resume(); }
@Override public final void create() { splash = new SplashScreen(); this.setScreen(splash); loadGame(); Gdx.app.addLifecycleListener(new LifecycleListener() { @Override public void resume() { Gdx.app.log("LifecycleListener", "resume"); } @Override public void pause() { Gdx.app.log("LifecycleListener", "pause"); } @Override public void dispose() { Gdx.app.log("LifecycleListener", "dispose"); GameManagerFactory.getInstance().getSettings().dispose(); AudioManagerImpl.getInstance().dispose(); AssetManager.disposeAll(); } }); }
public CardboardImplementation(Activity activity) { VirtualReality.implementation = this; VirtualReality.head = new Head(); VirtualReality.body = new Body(); VirtualReality.renderer = new VirtualRealityRenderer(); headTracker = new HeadTracker(activity); headTracker.startTracking(); HeadMountedDisplay hmd = new HeadMountedDisplay(activity.getWindowManager().getDefaultDisplay()); VirtualReality.headMountedDisplay = new CardboardHMD(hmd); VirtualReality.distortionRenderer = new CardboardDistortionRenderer(hmd, new DistortionRenderer()); Gdx.app.addLifecycleListener(new LifecycleListener() { @Override public void resume() { } @Override public void pause() { } @Override public void dispose() { headTracker.stopTracking(); } }); }
private void init (ApplicationListener listener, AndroidApplicationConfiguration config, boolean isForView) { if (this.getVersion() < MINIMUM_SDK) { throw new GdxRuntimeException("LibGDX requires Android API Level " + MINIMUM_SDK + " or later."); } graphics = new CardBoardGraphics(this, config, config.resolutionStrategy == null ? new FillResolutionStrategy() : config.resolutionStrategy); input = AndroidInputFactory.newAndroidInput(this, this, graphics.view, config); audio = new AndroidAudio(this, config); this.getFilesDir(); // workaround for Android bug #10515463 files = new AndroidFiles(this.getAssets(), this.getFilesDir().getAbsolutePath()); net = new AndroidNet(this); this.listener = listener; this.handler = new Handler(); this.useImmersiveMode = config.useImmersiveMode; this.hideStatusBar = config.hideStatusBar; // Add a specialized audio lifecycle listener addLifecycleListener(new LifecycleListener() { @Override public void resume () { // No need to resume audio here } @Override public void pause () { audio.pause(); } @Override public void dispose () { audio.dispose(); } }); 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) { try { requestWindowFeature(Window.FEATURE_NO_TITLE); } catch (Exception ex) { log("AndroidApplication", "Content already displayed, cannot request FEATURE_NO_TITLE", ex); } getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); setContentView(graphics.getView(), createLayoutParams()); setCardboardView((CardboardView)graphics.getView()); } createWakeLock(config.useWakelock); hideStatusBar(this.hideStatusBar); useImmersiveMode(this.useImmersiveMode); if (this.useImmersiveMode && getVersion() >= Build.VERSION_CODES.KITKAT) { try { Class<?> vlistener = Class.forName("com.badlogic.gdx.backends.android.AndroidVisibilityListener"); Object o = vlistener.newInstance(); Method method = vlistener.getDeclaredMethod("createListener", AndroidApplicationBase.class); method.invoke(o, this); } catch (Exception e) { log("AndroidApplication", "Failed to create AndroidVisibilityListener", e); } } }
@Override public void addLifecycleListener (LifecycleListener listener) { synchronized (lifecycleListeners) { lifecycleListeners.add(listener); } }
@Override public SnapshotArray<LifecycleListener> getLifecycleListeners () { return lifecycleListeners; }
private void init(ApplicationListener listener, AndroidApplicationConfiguration config, boolean isForView) { if (this.getVersion() < MINIMUM_SDK) { throw new GdxRuntimeException("LibGDX requires Android API Level " + MINIMUM_SDK + " or later."); } graphics = new AndroidGraphics(this, config, config.resolutionStrategy == null ? new FillResolutionStrategy() : config.resolutionStrategy); input = AndroidInputFactory.newAndroidInput(this, this.getContext(), graphics.getView(), config); audio = new AndroidAudio(this.getContext(), config); this.getContext().getFilesDir(); // workaround for Android bug #10515463 files = new AndroidFiles(this.getContext().getAssets(), this.getContext().getFilesDir().getAbsolutePath()); net = new AndroidNet(this); this.listener = listener; this.handler = new Handler(); this.useImmersiveMode = config.useImmersiveMode; this.hideStatusBar = config.hideStatusBar; // Add a specialized audio lifecycle listener addLifecycleListener(new LifecycleListener() { @Override public void resume() { // No need to resume audio here } @Override public void pause() { audio.pause(); } @Override public void dispose() { audio.dispose(); } }); 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) { try { supportRequestWindowFeature(Window.FEATURE_NO_TITLE); } catch (Exception ex) { log("AndroidApplication", "Content already displayed, cannot request FEATURE_NO_TITLE", ex); } getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); setContentView(graphics.getView(), createLayoutParams()); } createWakeLock(config.useWakelock); hideStatusBar(this.hideStatusBar); useImmersiveMode(this.useImmersiveMode); if (this.useImmersiveMode && getVersion() >= Build.VERSION_CODES.KITKAT) { try { Class<?> vlistener = Class.forName("com.badlogic.gdx.backends.android.AndroidVisibilityListener"); Object o = vlistener.newInstance(); Method method = vlistener.getDeclaredMethod("createListener", AndroidApplicationBase.class); method.invoke(o, this); } catch (Exception e) { log("AndroidApplication", "Failed to create AndroidVisibilityListener", e); } } }
@Override public void addLifecycleListener(LifecycleListener listener) { synchronized (lifecycleListeners) { lifecycleListeners.add(listener); } }
@Override public void removeLifecycleListener(LifecycleListener listener) { synchronized (lifecycleListeners) { lifecycleListeners.removeValue(listener, true); } }
@Override public Array<LifecycleListener> getLifecycleListeners() { return lifecycleListeners; }
public void removeLifecycleListener (LifecycleListener listener) { synchronized (lifecycleListeners) { lifecycleListeners.removeValue(listener, true); } }
@Override public void addLifecycleListener(LifecycleListener listener) { // Doesn't have a lifecycle }
@Override public void removeLifecycleListener(LifecycleListener listener) { // Doesn't have a lifecycle }
@Override public void addLifecycleListener(LifecycleListener listener) { lifecycleListeners.add(listener); }
@Override public void removeLifecycleListener(LifecycleListener listener) { lifecycleListeners.remove(listener); }
@Override public void addLifecycleListener (LifecycleListener listener) { synchronized(lifecycleListeners) { lifecycleListeners.add(listener); } }