From: <eli...@us...> - 2006-11-09 11:11:05
|
Revision: 2623 http://svn.sourceforge.net/java-game-lib/?rev=2623&view=rev Author: elias_naur Date: 2006-11-09 03:10:59 -0800 (Thu, 09 Nov 2006) Log Message: ----------- Don't use threads to repaint in test.applet.* tests Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/test/applet/OpenGL.java trunk/LWJGL/src/java/org/lwjgl/test/applet/Speed.java Modified: trunk/LWJGL/src/java/org/lwjgl/test/applet/OpenGL.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/applet/OpenGL.java 2006-11-09 11:03:55 UTC (rev 2622) +++ trunk/LWJGL/src/java/org/lwjgl/test/applet/OpenGL.java 2006-11-09 11:10:59 UTC (rev 2623) @@ -41,27 +41,19 @@ float angle = 0; public OpenGL() throws LWJGLException { - Thread t = new Thread() { - - public void run() { - while (true) { - if (isVisible()) - repaint(); - Display.sync(60); - } - } - }; - t.setDaemon(true); - t.start(); } - public void paintGL() { - GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); + public void initGL() { GL11.glMatrixMode(GL11.GL_PROJECTION_MATRIX); GL11.glLoadIdentity(); GL11.glOrtho(0, 640, 0, 480, 1, -1); GL11.glMatrixMode(GL11.GL_MODELVIEW_MATRIX); + setVSyncEnabled(true); + } + public void paintGL() { + GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); + GL11.glPushMatrix(); GL11.glTranslatef(320, 240, 0.0f); GL11.glRotatef(angle, 0, 0, 1.0f); @@ -77,6 +69,8 @@ try { swapBuffers(); + if (isVisible()) + repaint(); } catch (Exception e) {/*OK*/ } } Modified: trunk/LWJGL/src/java/org/lwjgl/test/applet/Speed.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/applet/Speed.java 2006-11-09 11:03:55 UTC (rev 2622) +++ trunk/LWJGL/src/java/org/lwjgl/test/applet/Speed.java 2006-11-09 11:10:59 UTC (rev 2623) @@ -37,37 +37,11 @@ public class Speed extends AWTGLCanvas implements Test { - float angle = 0; + private float angle = 0; + private long startTime = System.currentTimeMillis() + 5000; + private long fps = 0; public Speed() throws LWJGLException { - Thread t = new Thread() { - - public void run() { - long startTime = System.currentTimeMillis() + 5000; - long fps = 0; - - while (true) { - if (isVisible()) - repaint(); - try { - Thread.sleep(1); - } catch (InterruptedException inte) { - /* */ - } - if (startTime > System.currentTimeMillis()) { - fps++; - } else { - long timeUsed = 5000 + (startTime - System.currentTimeMillis()); - startTime = System.currentTimeMillis() + 5000; - System.out.println(fps + " frames in " + (float) (timeUsed / 1000f) + " seconds = " - + (fps / (timeUsed / 1000f))); - fps = 0; - } - } - } - }; - t.setDaemon(true); - t.start(); } public void paintGL() { @@ -92,8 +66,19 @@ try { swapBuffers(); + if (isVisible()) + repaint(); } catch (Exception e) {/*OK*/ } + if (startTime > System.currentTimeMillis()) { + fps++; + } else { + long timeUsed = 5000 + (startTime - System.currentTimeMillis()); + startTime = System.currentTimeMillis() + 5000; + System.out.println(fps + " frames in " + (float) (timeUsed / 1000f) + " seconds = " + + (fps / (timeUsed / 1000f))); + fps = 0; + } } public void start() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2007-11-09 05:11:33
|
Revision: 2918 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=2918&view=rev Author: elias_naur Date: 2007-11-08 21:11:29 -0800 (Thu, 08 Nov 2007) Log Message: ----------- Added a Thread.yield() to applets tests that repaint() last in paintGL() to help input responsiveness on linux. Thanks to Kappa for debugging and finding the workaround. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/test/applet/OpenGL.java trunk/LWJGL/src/java/org/lwjgl/test/applet/Speed.java Modified: trunk/LWJGL/src/java/org/lwjgl/test/applet/OpenGL.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/applet/OpenGL.java 2007-11-07 23:17:14 UTC (rev 2917) +++ trunk/LWJGL/src/java/org/lwjgl/test/applet/OpenGL.java 2007-11-09 05:11:29 UTC (rev 2918) @@ -121,8 +121,10 @@ } try { swapBuffers(); - if (isVisible()) + if (isVisible()) { + Thread.yield(); // Helps input responsiveness on linux repaint(); + } } catch (Exception e) {/*OK*/ } } Modified: trunk/LWJGL/src/java/org/lwjgl/test/applet/Speed.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/applet/Speed.java 2007-11-07 23:17:14 UTC (rev 2917) +++ trunk/LWJGL/src/java/org/lwjgl/test/applet/Speed.java 2007-11-09 05:11:29 UTC (rev 2918) @@ -66,8 +66,10 @@ try { swapBuffers(); - if (isVisible()) + if (isVisible()) { + Thread.yield(); // Helps input responsiveness on linux repaint(); + } } catch (Exception e) {/*OK*/ } if (startTime > System.currentTimeMillis()) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |