From: <eli...@us...> - 2008-10-02 07:34:33
|
Revision: 3133 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3133&view=rev Author: elias_naur Date: 2008-10-02 07:34:22 +0000 (Thu, 02 Oct 2008) Log Message: ----------- Added Display.getDesktopDisplayMode() Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2008-09-24 18:02:05 UTC (rev 3132) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2008-10-02 07:34:22 UTC (rev 3133) @@ -206,6 +206,17 @@ } /** + * Return the initial desktop display mode. + * + * @return The desktop display mode + */ + public static DisplayMode getDesktopDisplayMode() { + synchronized (GlobalLock.lock) { + return initial_mode; + } + } + + /** * Return the current display mode, as set by setDisplayMode(). * * @return The current display mode This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2008-10-02 08:10:57
|
Revision: 3134 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3134&view=rev Author: elias_naur Date: 2008-10-02 08:10:47 +0000 (Thu, 02 Oct 2008) Log Message: ----------- Properly handle non-fullscreen DisplayModes Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2008-10-02 07:34:22 UTC (rev 3133) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2008-10-02 08:10:47 UTC (rev 3134) @@ -211,9 +211,7 @@ * @return The desktop display mode */ public static DisplayMode getDesktopDisplayMode() { - synchronized (GlobalLock.lock) { - return initial_mode; - } + return initial_mode; } /** @@ -222,9 +220,7 @@ * @return The current display mode */ public static DisplayMode getDisplayMode() { - synchronized ( GlobalLock.lock ) { - return current_mode; - } + return current_mode; } /** @@ -239,17 +235,18 @@ * @throws LWJGLException if the display mode could not be set */ public static void setDisplayMode(DisplayMode mode) throws LWJGLException { - synchronized ( GlobalLock.lock ) { - if ( mode == null ) + synchronized (GlobalLock.lock) { + if (mode == null) throw new NullPointerException("mode must be non-null"); + boolean was_fullscreen = isFullscreen(); current_mode = mode; - if ( isCreated() ) { + if (isCreated()) { destroyWindow(); // If mode is not fullscreen capable, make sure we are in windowed mode - if ( !mode.isFullscreen() ) - resetFullscreen(); try { - if ( fullscreen ) + if (was_fullscreen && !isFullscreen()) + display_impl.resetDisplayMode(); + else if (isFullscreen()) switchDisplayMode(); createWindow(); makeCurrentAndSetSwapInterval(); @@ -264,13 +261,13 @@ } private static DisplayMode getEffectiveMode() { - return !fullscreen && parent != null ? new DisplayMode(parent.getWidth(), parent.getHeight()) : current_mode; + return !isFullscreen() && parent != null ? new DisplayMode(parent.getWidth(), parent.getHeight()) : current_mode; } private static int getWindowX() { - if ( !fullscreen && parent == null ) { + if (!isFullscreen() && parent == null) { // if no display location set, center window - if ( x == -1 ) { + if (x == -1) { return Math.max(0, (initial_mode.getWidth() - current_mode.getWidth()) / 2); } else { return x; @@ -281,7 +278,7 @@ } private static int getWindowY() { - if ( !fullscreen && parent == null ) { + if (!isFullscreen() && parent == null) { // if no display location set, center window if ( y == -1 ) { return Math.max(0, (initial_mode.getHeight() - current_mode.getHeight()) / 2); @@ -301,14 +298,14 @@ if ( window_created ) { return; } - Canvas tmp_parent = fullscreen ? null : parent; + Canvas tmp_parent = isFullscreen() ? null : parent; if ( tmp_parent != null && !tmp_parent.isDisplayable() ) // Only a best effort check, since the parent can turn undisplayable hereafter throw new LWJGLException("Parent.isDisplayable() must be true"); if ( tmp_parent != null ) { tmp_parent.addComponentListener(component_listener); } DisplayMode mode = getEffectiveMode(); - display_impl.createWindow(mode, fullscreen, tmp_parent, getWindowX(), getWindowY()); + display_impl.createWindow(mode, isFullscreen(), tmp_parent, getWindowX(), getWindowY()); window_created = true; setTitle(title); @@ -444,15 +441,6 @@ } } - private static void resetFullscreen() { - synchronized ( GlobalLock.lock ) { - if ( Display.fullscreen ) { - Display.fullscreen = false; - display_impl.resetDisplayMode(); - } - } - } - /** Return the last parent set with setParent(). */ public static Canvas getParent() { synchronized ( GlobalLock.lock ) { @@ -472,13 +460,13 @@ */ public static void setParent(Canvas parent) throws LWJGLException { synchronized ( GlobalLock.lock ) { - if ( Display.parent != parent ) { + if (Display.parent != parent) { Display.parent = parent; if ( !isCreated() ) return; destroyWindow(); try { - if ( fullscreen ) { + if (isFullscreen()) { switchDisplayMode(); } else { display_impl.resetDisplayMode(); @@ -509,13 +497,14 @@ */ public static void setFullscreen(boolean fullscreen) throws LWJGLException { synchronized ( GlobalLock.lock ) { - if ( Display.fullscreen != fullscreen ) { - Display.fullscreen = fullscreen; - if ( !isCreated() ) + boolean was_fullscreen = isFullscreen(); + Display.fullscreen = fullscreen; + if (was_fullscreen != isFullscreen()) { + if (!isCreated()) return; destroyWindow(); try { - if ( fullscreen ) { + if (isFullscreen()) { switchDisplayMode(); } else { display_impl.resetDisplayMode(); @@ -534,8 +523,8 @@ /** @return whether the Display is in fullscreen mode */ public static boolean isFullscreen() { - synchronized ( GlobalLock.lock ) { - return fullscreen; + synchronized (GlobalLock.lock) { + return fullscreen && current_mode.isFullscreen(); } } @@ -819,7 +808,7 @@ throw new NullPointerException("pixel_format cannot be null"); removeShutdownHook(); registerShutdownHook(); - if ( fullscreen ) + if (isFullscreen()) switchDisplayMode(); try { peer_info = display_impl.createPeerInfo(pixel_format); @@ -996,16 +985,12 @@ */ public static void setLocation(int new_x, int new_y) { synchronized ( GlobalLock.lock ) { - if ( fullscreen ) { - return; - } - // cache position x = new_x; y = new_y; // offset if already created - if ( isCreated() ) { + if (isCreated() && !isFullscreen()) { reshape(); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-12-01 15:13:10
|
Revision: 3258 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3258&view=rev Author: kappa1 Date: 2009-12-01 15:12:52 +0000 (Tue, 01 Dec 2009) Log Message: ----------- added the Display.setInitialBackground(r,g,b) method, this will allow you to select the initial background color of the lwjgl Display window. Useful to create more polished applications and smoother looking applets. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2009-12-01 11:39:48 UTC (rev 3257) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2009-12-01 15:12:52 UTC (rev 3258) @@ -116,6 +116,9 @@ private static boolean window_created = false; private static boolean parent_resized; + + /** Initial Background Color of Display */ + private static float r = 0, g = 0, b = 0; private static ComponentListener component_listener = new ComponentAdapter() { public void componentResized(ComponentEvent e) { @@ -861,6 +864,20 @@ } } } + + /** + * Set the initial color of the Display. This method is called before the Display is created and will set the + * background color to the one specified in this method. + * + * @param red - color value between 0 - 1 + * @param green - color value between 0 - 1 + * @param blue - color value between 0 - 1 + */ + public static void setInitialBackground(float red, float green, float blue) { + r = red; + g = green; + b = blue; + } private static void makeCurrentAndSetSwapInterval() throws LWJGLException { makeCurrent(); @@ -869,6 +886,8 @@ } private static void initContext() { + // set background clear color + GL11.glClearColor(r, g, b, 1.0f); // Clear window to avoid the desktop "showing through" GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); update(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sp...@us...> - 2010-04-03 19:03:55
|
Revision: 3308 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3308&view=rev Author: spasi Date: 2010-04-03 19:03:49 +0000 (Sat, 03 Apr 2010) Log Message: ----------- Moved processMessages call after swapBuffers in Display.update. Added option to not call processMessages during Display.update. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2010-04-03 13:32:35 UTC (rev 3307) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2010-04-03 19:03:49 UTC (rev 3308) @@ -116,7 +116,7 @@ private static boolean window_created = false; private static boolean parent_resized; - + /** Initial Background Color of Display */ private static float r = 0, g = 0, b = 0; @@ -648,17 +648,27 @@ } /** - * Update the window. This calls processMessages(), and if the window is visible - * clears the dirty flag and calls swapBuffers() and finally polls the input devices. + * Update the window. If the window is visible clears + * the dirty flag and calls swapBuffers() and finally + * polls the input devices. * - * @throws OpenGLException if an OpenGL error has occured since the last call to GL11.glGetError() */ public static void update() { + update(true); + } + + /** + * Update the window. If the window is visible clears + * the dirty flag and calls swapBuffers() and finally + * polls the input devices if processMessages is true. + * + * @param processMessages Poll input devices if true + */ + public static void update(boolean processMessages) { synchronized ( GlobalLock.lock ) { if ( !isCreated() ) throw new IllegalStateException("Display not created"); - processMessages(); // We paint only when the window is visible or dirty if ( display_impl.isVisible() || display_impl.isDirty() ) { try { @@ -667,13 +677,14 @@ throw new RuntimeException(e); } } - if ( swap_interval != 0 ) // Handle events again when vsync is enabled, to reduced input lag. - processMessages(); if ( parent_resized ) { reshape(); parent_resized = false; } + + if ( processMessages ) + processMessages(); } } @@ -866,11 +877,11 @@ } } } - + /** * Set the initial color of the Display. This method is called before the Display is created and will set the * background color to the one specified in this method. - * + * * @param red - color value between 0 - 1 * @param green - color value between 0 - 1 * @param blue - color value between 0 - 1 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2010-07-09 19:37:21
|
Revision: 3369 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3369&view=rev Author: kappa1 Date: 2010-07-09 19:37:14 +0000 (Fri, 09 Jul 2010) Log Message: ----------- Display sync modified to allow it to be interrupted. Thanks to bobjob for this, further thanks to MatthiasM for pointing out that the interrupt should not be swallowed. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2010-07-09 18:44:31 UTC (rev 3368) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2010-07-09 19:37:14 UTC (rev 3369) @@ -424,12 +424,13 @@ savedTimeLate = timeLate; } - while ( gapTo > timeNow + savedTimeLate ) { - try { + try { + while ( gapTo > timeNow + savedTimeLate ) { Thread.sleep(1); - } catch (InterruptedException e) { + timeNow = Sys.getTime(); } - timeNow = Sys.getTime(); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); } synchronized ( GlobalLock.lock ) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2010-11-11 21:25:27
|
Revision: 3455 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3455&view=rev Author: kappa1 Date: 2010-11-11 21:25:20 +0000 (Thu, 11 Nov 2010) Log Message: ----------- Changed initial alpha value of glClearColor from 1 to 0 which is set when Initialising the Display. This now matches expected OpenGL behaviour. Thanks to Ryanm for spotting this. If you use FBO's make sure your setting glClearColor properly. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2010-11-05 17:13:56 UTC (rev 3454) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2010-11-11 21:25:20 UTC (rev 3455) @@ -905,7 +905,7 @@ private static void initContext() { // set background clear color - glClearColor(r, g, b, 1.0f); + glClearColor(r, g, b, 0.0f); // Clear window to avoid the desktop "showing through" glClear(GL_COLOR_BUFFER_BIT); update(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sp...@us...> - 2011-05-31 14:40:53
|
Revision: 3539 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3539&view=rev Author: spasi Date: 2011-05-31 14:40:47 +0000 (Tue, 31 May 2011) Log Message: ----------- Update current DisplayMode when the Display's parent is resized. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2011-05-31 13:32:38 UTC (rev 3538) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2011-05-31 14:40:47 UTC (rev 3539) @@ -270,7 +270,7 @@ } private static DisplayMode getEffectiveMode() { - return !isFullscreen() && parent != null ? new DisplayMode(parent.getWidth(), parent.getHeight()) : current_mode; + return !isFullscreen() && parent != null ? (current_mode = new DisplayMode(parent.getWidth(), parent.getHeight())) : current_mode; } private static int getWindowX() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2011-07-13 19:29:21
|
Revision: 3584 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3584&view=rev Author: kappa1 Date: 2011-07-13 19:29:15 +0000 (Wed, 13 Jul 2011) Log Message: ----------- Updated JavaDoc for the new resizing api to clarify behaviour when running in fullscreen or with Display.setParent(). Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2011-07-13 12:44:25 UTC (rev 3583) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2011-07-13 19:29:15 UTC (rev 3584) @@ -1270,6 +1270,8 @@ /** * @return true if the Display window has been resized. * This value will be updated after a call to Display.update(). + * + * This will return false if running in fullscreen or with Display.setParent(Canvas parent) */ public static boolean wasResized() { return false; @@ -1278,6 +1280,10 @@ /** * @return this method will return the width of the Display window. * + * If running in fullscreen mode it will return the width of the current set DisplayMode. + * If running Display.setParent(Canvas parent) is being used, the width of the parent + * will be returned. + * * This value will be updated after a call to Display.update(). */ public static int getWidth() { @@ -1286,6 +1292,10 @@ /** * @return this method will return the height of the Display window. + * + * If running in fullscreen mode it will return the height of the current set DisplayMode. + * If running Display.setParent(Canvas parent) is being used, the height of the parent + * will be returned. * * This value will be updated after a call to Display.update(). */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ma...@us...> - 2011-10-11 19:25:01
|
Revision: 3658 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3658&view=rev Author: matzon Date: 2011-10-11 19:24:55 +0000 (Tue, 11 Oct 2011) Log Message: ----------- undoing r3539 to fix issue with fullscreen Revision Links: -------------- http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3539&view=rev Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2011-10-11 17:39:37 UTC (rev 3657) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2011-10-11 19:24:55 UTC (rev 3658) @@ -259,7 +259,7 @@ } private static DisplayMode getEffectiveMode() { - return !isFullscreen() && parent != null ? (current_mode = new DisplayMode(parent.getWidth(), parent.getHeight())) : current_mode; + return !isFullscreen() && parent != null ? new DisplayMode(parent.getWidth(), parent.getHeight()) : current_mode; } private static int getWindowX() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ma...@us...> - 2011-10-18 17:23:45
|
Revision: 3681 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3681&view=rev Author: matzon Date: 2011-10-18 17:23:39 +0000 (Tue, 18 Oct 2011) Log Message: ----------- make Display.destroy a NOP if it hasn't been created yet Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2011-10-17 07:45:46 UTC (rev 3680) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2011-10-18 17:23:39 UTC (rev 3681) @@ -1107,7 +1107,9 @@ * regardless of whether the Display was the current rendering context. */ public static void destroy() { - drawable.destroy(); + if(isCreated()) { + drawable.destroy(); + } } /* This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2012-02-29 23:18:43
|
Revision: 3746 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3746&view=rev Author: kappa1 Date: 2012-02-29 23:18:35 +0000 (Wed, 29 Feb 2012) Log Message: ----------- Implement a much more accurate Display.sync() method that auto adapts to the systems timer resolution and load. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2012-02-28 18:18:06 UTC (rev 3745) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2012-02-29 23:18:35 UTC (rev 3746) @@ -79,9 +79,15 @@ /** The current display mode, if created */ private static DisplayMode current_mode; - /** Timer for sync() */ - private static long timeThen; + /** time at last sync() */ + private static long lastTime; + /** Whether the sync() method has been initiated */ + private static boolean syncInitiated; + + /** adaptive time to yield instead of sleeping in sync()*/ + private static long adaptiveYieldTime = 1000*1000; + /** X coordinate of the window */ private static int x = -1; @@ -401,41 +407,84 @@ } } - private static long timeLate; - /** - * Best sync method that works reliably. - * + * An accurate sync method that adapts automatically + * to the system it runs on to provide reliable results. + * * @param fps The desired frame rate, in frames per second */ public static void sync(int fps) { - long timeNow; - long gapTo; - long savedTimeLate; - synchronized ( GlobalLock.lock ) { - gapTo = Sys.getTimerResolution() / fps + timeThen; - timeNow = Sys.getTime(); - savedTimeLate = timeLate; - } - + if (fps <= 0) return; + if (!syncInitiated) initiateSyncTimer(); + + long sleepTime = 1000000000 / fps; // nanoseconds to sleep this frame + // adaptiveYieldTime + remainder micro & nano seconds if smaller than sleepTime + long yieldTime = Math.min(sleepTime, adaptiveYieldTime + sleepTime % (1000*1000)); + long overSleep = 0; // time the sync goes over by + try { - while ( gapTo > timeNow + savedTimeLate ) { - Thread.sleep(1); - timeNow = Sys.getTime(); + while (true) { + long t = getTime() - lastTime; + + if (t < sleepTime - yieldTime) { + Thread.sleep(1); + } + else if (t < sleepTime) { + // burn the last few CPU cycles to ensure accuracy + Thread.yield(); + } + else { + overSleep = t - sleepTime; + break; // exit while loop + } } - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); + } catch (InterruptedException e) {} + + lastTime = getTime() - Math.min(overSleep, sleepTime); + + // auto tune the amount of time to yield + if (overSleep > adaptiveYieldTime) { + // increase by 500 microseconds (half a ms) + adaptiveYieldTime = Math.min(adaptiveYieldTime + 500*1000, sleepTime); } - - synchronized ( GlobalLock.lock ) { - if ( gapTo < timeNow ) - timeLate = timeNow - gapTo; - else - timeLate = 0; - - timeThen = timeNow; + else if (overSleep < adaptiveYieldTime - 1000*1000) { + // decrease by 5 microseconds + adaptiveYieldTime = Math.max(adaptiveYieldTime - 5*1000, 1000*1000); } } + + /** + * Get System Nano Time + * @return will return the current time in nano's + */ + private static long getTime() { + return (Sys.getTime() * 1000000000) / Sys.getTimerResolution(); + } + + /** + * On windows the sleep functions can be highly inaccurate by + * over 10ms making in unusable. However it can be forced to + * be a bit more accurate by running a separate sleeping daemon + * thread. + */ + private static void initiateSyncTimer() { + syncInitiated = true; + + if (!System.getProperty("os.name").startsWith("Win")) { + return; + } + + Thread timerAccuracyThread = new Thread(new Runnable() { + public void run() { + try { + Thread.sleep(Long.MAX_VALUE); + } catch (Exception e) {} + } + }); + + timerAccuracyThread.setDaemon(true); + timerAccuracyThread.start(); + } /** @return the title of the window */ public static String getTitle() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2012-03-01 22:34:40
|
Revision: 3747 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3747&view=rev Author: kappa1 Date: 2012-03-01 22:34:34 +0000 (Thu, 01 Mar 2012) Log Message: ----------- Tweak Display.sync() method a little to reduce the Thread.yield() time even further, now with a minimum of 0 yield time. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2012-02-29 23:18:35 UTC (rev 3746) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2012-03-01 22:34:34 UTC (rev 3747) @@ -86,7 +86,7 @@ private static boolean syncInitiated; /** adaptive time to yield instead of sleeping in sync()*/ - private static long adaptiveYieldTime = 1000*1000; + private static long adaptiveYieldTime; /** X coordinate of the window */ private static int x = -1; @@ -444,12 +444,12 @@ // auto tune the amount of time to yield if (overSleep > adaptiveYieldTime) { - // increase by 500 microseconds (half a ms) - adaptiveYieldTime = Math.min(adaptiveYieldTime + 500*1000, sleepTime); + // increase by 200 microseconds (1/5 a ms) + adaptiveYieldTime = Math.min(adaptiveYieldTime + 200*1000, sleepTime); } - else if (overSleep < adaptiveYieldTime - 1000*1000) { + else if (overSleep < adaptiveYieldTime - 200*1000) { // decrease by 5 microseconds - adaptiveYieldTime = Math.max(adaptiveYieldTime - 5*1000, 1000*1000); + adaptiveYieldTime = Math.max(adaptiveYieldTime - 2*1000, 0); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2012-03-18 16:25:29
|
Revision: 3752 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3752&view=rev Author: kappa1 Date: 2012-03-18 16:25:23 +0000 (Sun, 18 Mar 2012) Log Message: ----------- Fix the new accurate Display.sync() method to use less CPU on Mac. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2012-03-04 13:41:49 UTC (rev 3751) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2012-03-18 16:25:23 UTC (rev 3752) @@ -85,6 +85,9 @@ /** Whether the sync() method has been initiated */ private static boolean syncInitiated; + /** whether to disable adaptive yield time in sync() method */ + private static boolean adaptiveTimeDisabled; + /** adaptive time to yield instead of sleeping in sync()*/ private static long adaptiveYieldTime; @@ -419,7 +422,7 @@ long sleepTime = 1000000000 / fps; // nanoseconds to sleep this frame // adaptiveYieldTime + remainder micro & nano seconds if smaller than sleepTime - long yieldTime = Math.min(sleepTime, adaptiveYieldTime + sleepTime % (1000*1000)); + long yieldTime = adaptiveTimeDisabled ? 0 : Math.min(sleepTime, adaptiveYieldTime + sleepTime % (1000*1000)); long overSleep = 0; // time the sync goes over by try { @@ -442,15 +445,17 @@ lastTime = getTime() - Math.min(overSleep, sleepTime); - // auto tune the amount of time to yield - if (overSleep > adaptiveYieldTime) { - // increase by 200 microseconds (1/5 a ms) - adaptiveYieldTime = Math.min(adaptiveYieldTime + 200*1000, sleepTime); + if (!adaptiveTimeDisabled) { + // auto tune the amount of time to yield + if (overSleep > adaptiveYieldTime) { + // increase by 200 microseconds (1/5 a ms) + adaptiveYieldTime = Math.min(adaptiveYieldTime + 200*1000, sleepTime); + } + else if (overSleep < adaptiveYieldTime - 200*1000) { + // decrease by 5 microseconds + adaptiveYieldTime = Math.max(adaptiveYieldTime - 2*1000, 0); + } } - else if (overSleep < adaptiveYieldTime - 200*1000) { - // decrease by 5 microseconds - adaptiveYieldTime = Math.max(adaptiveYieldTime - 2*1000, 0); - } } /** @@ -462,28 +467,37 @@ } /** - * On windows the sleep functions can be highly inaccurate by - * over 10ms making in unusable. However it can be forced to - * be a bit more accurate by running a separate sleeping daemon - * thread. + * Initialise the sync(fps) method. */ private static void initiateSyncTimer() { syncInitiated = true; + lastTime = getTime(); - if (!System.getProperty("os.name").startsWith("Win")) { + String osName = System.getProperty("os.name"); + + if (osName.startsWith("Mac") || osName.startsWith("Darwin")) { + // disabled on mac as it uses too much cpu, besides + // Thread.sleep is pretty accurate on mac by default + adaptiveTimeDisabled = true; return; } - Thread timerAccuracyThread = new Thread(new Runnable() { - public void run() { - try { - Thread.sleep(Long.MAX_VALUE); - } catch (Exception e) {} - } - }); - - timerAccuracyThread.setDaemon(true); - timerAccuracyThread.start(); + if (osName.startsWith("Win")) { + // On windows the sleep functions can be highly inaccurate by + // over 10ms making in unusable. However it can be forced to + // be a bit more accurate by running a separate sleeping daemon + // thread. + Thread timerAccuracyThread = new Thread(new Runnable() { + public void run() { + try { + Thread.sleep(Long.MAX_VALUE); + } catch (Exception e) {} + } + }); + + timerAccuracyThread.setDaemon(true); + timerAccuracyThread.start(); + } } /** @return the title of the window */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2012-03-21 19:35:00
|
Revision: 3754 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3754&view=rev Author: kappa1 Date: 2012-03-21 19:34:51 +0000 (Wed, 21 Mar 2012) Log Message: ----------- Display.sync() fix excessive CPU using on windows Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2012-03-19 22:12:38 UTC (rev 3753) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2012-03-21 19:34:51 UTC (rev 3754) @@ -451,8 +451,12 @@ // increase by 200 microseconds (1/5 a ms) adaptiveYieldTime = Math.min(adaptiveYieldTime + 200*1000, sleepTime); } + else if (overSleep < adaptiveYieldTime - 2*1000*1000) { + // fast decrease by 50 microseconds for large under sleeps + adaptiveYieldTime = Math.max(adaptiveYieldTime - 50*1000, 0); + } else if (overSleep < adaptiveYieldTime - 200*1000) { - // decrease by 5 microseconds + // slower but finer decrease by 2 microseconds adaptiveYieldTime = Math.max(adaptiveYieldTime - 2*1000, 0); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2012-05-13 18:01:19
|
Revision: 3773 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3773&view=rev Author: kappa1 Date: 2012-05-13 18:01:12 +0000 (Sun, 13 May 2012) Log Message: ----------- Display.wasResized() should now work correctly when using Display.setParent() Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2012-05-13 13:50:52 UTC (rev 3772) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2012-05-13 18:01:12 UTC (rev 3773) @@ -656,6 +656,9 @@ if ( parent_resized ) { reshape(); parent_resized = false; + window_resized = true; + width = parent.getWidth(); + height = parent.getHeight(); } if ( processMessages ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2012-05-13 18:03:11
|
Revision: 3774 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3774&view=rev Author: kappa1 Date: 2012-05-13 18:03:05 +0000 (Sun, 13 May 2012) Log Message: ----------- Minor tweak to remove unused code Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2012-05-13 18:01:12 UTC (rev 3773) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2012-05-13 18:03:05 UTC (rev 3774) @@ -657,8 +657,6 @@ reshape(); parent_resized = false; window_resized = true; - width = parent.getWidth(); - height = parent.getHeight(); } if ( processMessages ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |