From c15865e0f62a3af9508245554ed9d4000403e2e0 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 27 Jun 2013 16:41:10 +0200 Subject: Fix Window destroyNotify() -> QUIT --- src/jake2/render/opengl/GLDriver.java | 1 + src/jake2/render/opengl/JoglDummyDriver.java | 4 ++-- src/jake2/render/opengl/JoglES1Driver.java | 3 +-- src/jake2/render/opengl/JoglES2Driver.java | 3 +-- src/jake2/render/opengl/JoglGL2Driver.java | 3 +-- src/jake2/render/opengl/NEWTWin.java | 26 +++++++++++++++++++++----- 6 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/jake2/render/opengl/GLDriver.java b/src/jake2/render/opengl/GLDriver.java index d350811..7f86430 100644 --- a/src/jake2/render/opengl/GLDriver.java +++ b/src/jake2/render/opengl/GLDriver.java @@ -18,6 +18,7 @@ public interface GLDriver { void beginFrame(float camera_separation); + /** Performs swapBuffers(), ticks the fps counter and performs QUIT if requested. */ void endFrame(); void appActivate(boolean activate); diff --git a/src/jake2/render/opengl/JoglDummyDriver.java b/src/jake2/render/opengl/JoglDummyDriver.java index 73620b2..e962c37 100644 --- a/src/jake2/render/opengl/JoglDummyDriver.java +++ b/src/jake2/render/opengl/JoglDummyDriver.java @@ -102,9 +102,9 @@ public abstract class JoglDummyDriver extends DummyGL implements GLDriver { } public void endFrame() { - // newtWin.window.swapBuffers(); + newtWin.checkQuit(); + // newtWin.swapBuffers(); // deactivate(); - newtWin.fpsCounter.tickFPS(); } public void appActivate(boolean activate) { diff --git a/src/jake2/render/opengl/JoglES1Driver.java b/src/jake2/render/opengl/JoglES1Driver.java index f9a29f8..6f138cd 100644 --- a/src/jake2/render/opengl/JoglES1Driver.java +++ b/src/jake2/render/opengl/JoglES1Driver.java @@ -113,9 +113,8 @@ public abstract class JoglES1Driver extends JoglGL2ES1 implements GLDriver { } public void endFrame() { - newtWin.window.swapBuffers(); + newtWin.endFrame(); // deactivate(); - newtWin.fpsCounter.tickFPS(); } public void appActivate(boolean activate) { diff --git a/src/jake2/render/opengl/JoglES2Driver.java b/src/jake2/render/opengl/JoglES2Driver.java index 2548b62..08c95b9 100644 --- a/src/jake2/render/opengl/JoglES2Driver.java +++ b/src/jake2/render/opengl/JoglES2Driver.java @@ -118,9 +118,8 @@ public abstract class JoglES2Driver extends JoglGL2ES1 implements GLDriver { } public void endFrame() { - newtWin.window.swapBuffers(); + newtWin.endFrame(); // deactivate(); - newtWin.fpsCounter.tickFPS(); } public void appActivate(boolean activate) { diff --git a/src/jake2/render/opengl/JoglGL2Driver.java b/src/jake2/render/opengl/JoglGL2Driver.java index cad9c0a..0c95680 100644 --- a/src/jake2/render/opengl/JoglGL2Driver.java +++ b/src/jake2/render/opengl/JoglGL2Driver.java @@ -114,9 +114,8 @@ public abstract class JoglGL2Driver extends JoglGL2ES1 implements GLDriver { } public void endFrame() { - newtWin.window.swapBuffers(); + newtWin.endFrame(); // deactivate(); - newtWin.fpsCounter.tickFPS(); } public void appActivate(boolean activate) { diff --git a/src/jake2/render/opengl/NEWTWin.java b/src/jake2/render/opengl/NEWTWin.java index bc514ed..ff7b949 100644 --- a/src/jake2/render/opengl/NEWTWin.java +++ b/src/jake2/render/opengl/NEWTWin.java @@ -18,6 +18,7 @@ import jake2.sys.NEWTKBD; import java.util.List; import javax.media.nativewindow.CapabilitiesChooser; +import javax.media.nativewindow.WindowClosingProtocol.WindowClosingMode; import javax.media.nativewindow.util.Dimension; import javax.media.nativewindow.util.DimensionImmutable; import javax.media.nativewindow.util.SurfaceSize; @@ -39,6 +40,7 @@ public class NEWTWin { MonitorMode oldDisplayMode = null; volatile Screen screen = null; volatile GLWindow window = null; + volatile boolean shouldQuit = false; final FPSCounterImpl fpsCounter = new FPSCounterImpl(); public List getModeList() { @@ -119,14 +121,11 @@ public class NEWTWin { } } window = GLWindow.create(screen, caps); + window.setDefaultCloseOperation(WindowClosingMode.DO_NOTHING_ON_CLOSE); // we do handle QUIT on our own, no GLWindow.display() called. window.setCapabilitiesChooser(chooser); window.addWindowListener(new WindowAdapter() { public void windowDestroyNotify(WindowEvent e) { - if (!Globals.appletMode) { - if( null != window ) { // already in shutdown ? - Cbuf.ExecuteText(Defines.EXEC_APPEND, "quit"); - } - } + shouldQuit = !Globals.appletMode && null != window; // not applet and not already in shutdown ? } public void windowResized(WindowEvent e) { @@ -220,6 +219,23 @@ public class NEWTWin { } } + /** Performs {@link GLWindow#swapBuffers()}, ticks the fps counter and performs QUIT if requested. */ + public final void endFrame() { + window.swapBuffers(); + fpsCounter.tickFPS(); + if( shouldQuit ) { + deactivateGLContext(); + Cbuf.ExecuteText(Defines.EXEC_APPEND, "quit"); + } + } + /** Performs QUIT if requested. */ + public final void checkQuit() { + if( shouldQuit ) { + deactivateGLContext(); + Cbuf.ExecuteText(Defines.EXEC_APPEND, "quit"); + } + } + void shutdown() { shutdownImpl(true); } -- cgit v1.2.3