Update of /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28476/src/java/org/lwjgl
Modified Files:
Display.java Sys.java
Log Message:
Removed Sys.setTime(), Sys.getPlatform()
Changed Sys.getTime()
Added Display.sync()
Index: Display.java
===================================================================
RCS file: /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/Display.java,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -d -r1.44 -r1.45
--- Display.java 27 Mar 2004 15:05:22 -0000 1.44
+++ Display.java 5 May 2004 14:28:37 -0000 1.45
@@ -59,20 +59,9 @@
/** Whether or not the display has been requested to shutdown by the user */
private static boolean closeRequested = false;
-
- /*
- * Platforms. This will let you determine which platform you are running
- * on, which is handy to know for some GL context calls.
- */
-
- /** Windows platform */
- public static final int PLATFORM_WGL = 0;
-
- /** GLX (Linux/Unix) platform */
- public static final int PLATFORM_GLX = 1;
-
- /** MacOSX platform */
- public static final int PLATFORM_AGL = 2;
+
+ /** Timer for sync() */
+ private static long timeNow, timeThen;
static {
Sys.initialize();
@@ -178,16 +167,6 @@
}
/**
- * Returns the operating system windowing platform. This will be one of the
- * constants defined above. There is no "unknown" platform; a native library port
- * has to provide a unique platform number for this mechanism to work. If the LWJGL
- * is ported to, say, QNX, we will have a PLATFORM_QNX at the ready.
- *
- * @return the windowing system
- */
- public static native int getPlatform();
-
- /**
* Set the display configuration to the specified gamma, brightness and contrast.
* The configuration changes will be reset when resetDisplayMode is called.
*
@@ -250,5 +229,21 @@
* @return a String
*/
public static native String getVersion();
+
+ /**
+ * Synchronize the display to a capped frame rate.
+ * @param frameTime The desired frame time in seconds
+ */
+ public static void sync(float frameRate) {
+ timeNow = Sys.getTime();
+ System.out.println(Sys.getTimerResolution());
+ System.out.println(timeNow+" "+timeThen+" "+((float) (timeNow - timeThen) / (float) Sys.getTimerResolution()));
+ while (timeNow > timeThen && (float) (timeNow - timeThen) / (float) Sys.getTimerResolution() < frameRate) {
+ // This is a system-friendly way of allowing other stuff to use CPU if it wants to
+ Thread.yield();
+ timeNow = Sys.getTime();
+ }
+ timeThen = timeNow;
+ }
}
Index: Sys.java
===================================================================
RCS file: /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/Sys.java,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -d -r1.45 -r1.46
--- Sys.java 27 Mar 2004 15:05:22 -0000 1.45
+++ Sys.java 5 May 2004 14:28:38 -0000 1.46
@@ -81,7 +81,7 @@
/** The native library name */
private static String LIBRARY_NAME = "lwjgl";
- /** The platform being executed on */
+ /** The platform adapter class name */
private static String PLATFORM;
/**
@@ -131,13 +131,8 @@
throw new LinkageError("Version mismatch: jar version is '" + VERSION +
"', native libary version is '" + native_version + "'");
setDebug(DEBUG);
- setTime(0);
- // check platform name, and default to awt
- PLATFORM = System.getProperty("org.lwjgl.Sys.platform");
- if(PLATFORM == null) {
- PLATFORM = "org.lwjgl.SwingAdapter";
- }
+ PLATFORM = System.getProperty("org.lwjgl.Sys.platform", "org.lwjgl.SwingAdapter");
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
@@ -173,20 +168,14 @@
/**
* Gets the current value of the hires timer, in ticks. When the Sys class is first loaded
* the hires timer is reset to 0. If no hires timer is present then this method will always
- * return whatever value the timer was last set to.
+ * return 0.<p><strong>NOTEZ BIEN</strong> that the hires timer WILL wrap around.
*
- * @return the current hires time, in ticks.
- */
- public static native long getTime();
-
- /**
- * Sets the hires timer to a new time, specified in ticks.
- *
- * @param time The new time, in ticks
- * @see #getTime()
- * @see #getTimerResolution()
+ * @return the current hires time, in ticks (always >= 0)
*/
- public static native void setTime(long time);
+ public static long getTime() {
+ return ngetTime() & 0x7FFFFFFFFFFFFFFFL;
+ }
+ private static native long ngetTime();
/**
* Set the process priority in a system independent way. Because of the various
|