void mainLoop() { Array<LifecycleListener> lifecycleListeners = this.lifecycleListeners; listener.create(); boolean wasActive = true; // unlike LwjglApplication, a headless application will eat up CPU in this while loop // it is up to the implementation to call Thread.sleep as necessary while (running) { executeRunnables(); listener.render(); // If one of the runnables set running to false, for example after an exit(). if (!running) break; } synchronized (lifecycleListeners) { for (LifecycleListener listener : lifecycleListeners) { listener.pause(); listener.dispose(); } } listener.pause(); listener.dispose(); }
void mainLoop() { graphics.update(); if (Gdx.graphics.getWidth() != lastWidth || Gdx.graphics.getHeight() != lastHeight) { GwtApplication.this.listener.resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); lastWidth = graphics.getWidth(); lastHeight = graphics.getHeight(); Gdx.gl.glViewport(0, 0, lastWidth, lastHeight); } runnablesHelper.addAll(runnables); runnables.clear(); for (int i = 0; i < runnablesHelper.size; i++) { runnablesHelper.get(i).run(); } runnablesHelper.clear(); graphics.frameId++; listener.render(); input.reset(); }
void mainLoop() { try { graphics.setupDisplay(); } catch (LWJGLException e) { throw new GdxRuntimeException(e); } listener.create(); listener.resize(graphics.getWidth(), graphics.getHeight()); graphics.resize = false; int lastWidth = graphics.getWidth(); int lastHeight = graphics.getHeight(); graphics.lastTime = System.nanoTime(); while (running) { Display.processMessages(); if (Display.isCloseRequested()) { exit(); } boolean shouldRender = false; synchronized (runnables) { executedRunnables.clear(); executedRunnables.addAll(runnables); runnables.clear(); for (int i = 0; i < executedRunnables.size(); i++) { shouldRender = true; try { executedRunnables.get(i).run(); } catch (Throwable t) { t.printStackTrace(); } } } input.update(); shouldRender |= graphics.shouldRender(); 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() || Display.getWidth() != graphics.config.width || Display.getHeight() != graphics.config.height) { graphics.resize = false; Gdx.gl.glViewport(0, 0, Display.getWidth(), Display.getHeight()); graphics.config.width = Display.getWidth(); graphics.config.height = Display.getHeight(); if (listener != null) listener.resize(Display.getWidth(), Display.getHeight()); graphics.requestRendering(); } } input.processEvents(); audio.update(); if (shouldRender) { graphics.updateTime(); listener.render(); Display.update(); if (graphics.vsync && graphics.config.useCPUSynch) { Display.sync(60); } } else { // Effectively sleeps for a little while so we don't spend all available // cpu power in an essentially empty loop. Display.sync(60); } } listener.pause(); listener.dispose(); Display.destroy(); audio.dispose(); if (graphics.config.forceExit) System.exit(-1); }
void render(long time) { graphics.frameStart(time); listener.render(); glfwSwapBuffers(graphics.window); }