Removed Sys.setTime(), Sys.getPlatform()

Changed Sys.getTime()
Added Display.sync()
This commit is contained in:
Caspian Rychlik-Prince 2004-05-05 14:28:40 +00:00
parent 3bb53392f6
commit b697fb3ecf
20 changed files with 102 additions and 261 deletions

View file

@ -59,20 +59,9 @@ public final class Display {
/** 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();
@ -177,16 +166,6 @@ public final class Display {
return mode.freq;
}
/**
* 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 @@ public final class Display {
* @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;
}
}

View file

@ -81,7 +81,7 @@ public final class Sys {
/** 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 @@ public final class Sys {
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 @@ public final class Sys {
/**
* 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.
* @return the current hires time, in ticks (always >= 0)
*/
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()
*/
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

View file

@ -109,18 +109,9 @@ public class Game {
finished = true;
} else if (Window.isActive()) {
// The window is in the foreground, so we should play the game
long timeThen = Sys.getTime();
logic();
render();
// Stabilise the framerate if we haven't got vsync
if (!Window.isVSyncEnabled()) {
long timeNow = Sys.getTime();
while ((float) (timeNow - timeThen) / (float) Sys.getTimerResolution() < FRAMETIME) {
// This is a system-friendly way of allowing other stuff to use CPU if it wants to
Thread.yield();
timeNow = Sys.getTime();
}
}
org.lwjgl.Display.sync(FRAMETIME);
} else {
// The window is not in the foreground, so we can allow other stuff to run and
// infrequently update

View file

@ -36,9 +36,8 @@ import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.IntBuffer;
import org.lwjgl.Display;
import org.lwjgl.Sys;
import org.lwjgl.LWJGLException;
import org.lwjgl.Sys;
/**
* $Id$
@ -108,28 +107,25 @@ public class Cursor {
// Win32 or X and do accordingly. This hasn't been implemented on Mac, but we
// might want to split it into a X/Win/Mac cursor if it gets too cluttered
switch(Display.getPlatform()) {
case Display.PLATFORM_GLX:
// create our cursor elements
cursors = new CursorElement[1];
cursors[0] = new CursorElement();
cursors[0].cursorHandle = nCreateCursor(width, height, xHotspot, yHotspot, numImages, images_copy, images_copy.position(), delays, delays != null ? delays.position() : -1);
break;
case Display.PLATFORM_WGL:
// create our cursor elements
cursors = new CursorElement[numImages];
for(int i=0; i<numImages; i++) {
cursors[i] = new CursorElement();
cursors[i].cursorHandle = nCreateCursor(width, height, xHotspot, yHotspot, 1, images_copy, images_copy.position(), null, 0);
cursors[i].delay = (delays != null) ? delays.get(i) : 0;
cursors[i].timeout = System.currentTimeMillis();
// offset to next image
images_copy.position(width*height*(i+1));
}
break;
case Display.PLATFORM_AGL:
break;
String osName = System.getProperty("os.name", "");
if (osName.startsWith("Win")) {
// create our cursor elements
cursors = new CursorElement[numImages];
for(int i=0; i<numImages; i++) {
cursors[i] = new CursorElement();
cursors[i].cursorHandle = nCreateCursor(width, height, xHotspot, yHotspot, 1, images_copy, images_copy.position(), null, 0);
cursors[i].delay = (delays != null) ? delays.get(i) : 0;
cursors[i].timeout = System.currentTimeMillis();
// offset to next image
images_copy.position(width*height*(i+1));
}
} else if (osName.startsWith("Lin")) {
// create our cursor elements
cursors = new CursorElement[1];
cursors[0] = new CursorElement();
cursors[0].cursorHandle = nCreateCursor(width, height, xHotspot, yHotspot, numImages, images_copy, images_copy.position(), delays, delays != null ? delays.position() : -1);
} else {
}
}

View file

@ -38,10 +38,9 @@ import java.util.HashMap;
import java.util.Map;
import org.lwjgl.BufferUtils;
import org.lwjgl.Display;
import org.lwjgl.LWJGLException;
import org.lwjgl.Sys;
import org.lwjgl.opengl.Window;
import org.lwjgl.LWJGLException;
/**
* $Id$
@ -568,7 +567,7 @@ public class Mouse {
* shouldn't be called otherwise
*/
public static void updateCursor() {
if (Display.getPlatform() == Display.PLATFORM_WGL && currentCursor != null && currentCursor.hasTimedOut()) {
if (System.getProperty("os.name").startsWith("Win") && currentCursor != null && currentCursor.hasTimedOut()) {
currentCursor.nextCursor();
try {
setNativeCursor(currentCursor);

View file

@ -35,9 +35,8 @@ import java.io.File;
import java.lang.reflect.Method;
import java.util.StringTokenizer;
import org.lwjgl.Display;
import org.lwjgl.Sys;
import org.lwjgl.LWJGLException;
import org.lwjgl.Sys;
/**
* $Id$
@ -141,18 +140,15 @@ public abstract class AL {
String seperator = System.getProperty("path.separator");
String jwsLibname;
switch (Display.getPlatform()) {
case Display.PLATFORM_WGL:
jwsLibname = "lwjglaudio";
break;
case Display.PLATFORM_GLX:
jwsLibname = "openal";
break;
case Display.PLATFORM_AGL:
jwsLibname = "openal";
break;
default:
throw new LWJGLException("Unknown platform");
String osName = System.getProperty("os.name");
if (osName.startsWith("Win")) {
jwsLibname = "lwjglaudio";
} else if (osName.startsWith("Lin")) {
jwsLibname = "openal";
} else if (osName.startsWith("Mac")) {
jwsLibname = "openal";
} else {
throw new LWJGLException("Unknown platform: "+osName);
}
String jwsPath = getPathFromJWS(jwsLibname);

View file

@ -510,23 +510,6 @@ public final class Window {
*/
private static native void nUpdate();
/**
* Determines to the best of the platform's ability whether monitor vysnc is enabled on
* this window. The failsafe assumption is that when vsync cannot be determined, this
* method returns false, and you should rely on using a hires timer to throttle your
* framerate rather than relying on monitor sync (even if monitor sync is actually working).
* Therefore you can guarantee that if we return true from this method that we're pretty
* certain vsync is enabled.
* @return boolean
*/
public static boolean isVSyncEnabled() {
if (!isCreated())
throw new IllegalStateException("Cannot determine vsync state of uncreated window");
return nIsVSyncEnabled();
}
private static native boolean nIsVSyncEnabled();
/**
* Enable or disable vertical monitor synchronization. This call is a best-attempt at changing
* the vertical refresh synchronization of the monitor, and is not guaranteed to be successful.

View file

@ -67,7 +67,6 @@ public class DisplayTest {
System.out.println("==== Test Current ====");
System.out.println("Info about current:");
System.out.println("Platform: " + getNameForPlatform());
System.out.println("Graphics card: " + Display.getAdapter() + ", version: " + Display.getVersion());
System.out.println("Resolution: " +
Display.getWidth() + "x" +
@ -228,24 +227,6 @@ public class DisplayTest {
}
}
/**
* Returns a String representation of the platform
*
* @return String representation of the platform
*/
private String getNameForPlatform() {
switch (Display.getPlatform()) {
case Display.PLATFORM_WGL:
return "WGL";
case Display.PLATFORM_GLX:
return "GLX";
case Display.PLATFORM_AGL:
return "AGL";
default:
return "Unknown platform";
}
}
/**
* Tests the Sys class, and serves as basic usage test
*

View file

@ -148,7 +148,6 @@ public final class Game {
*/
private static void init()
throws Exception {
Sys.setTime(0);
Sys.setProcessPriority(Sys.HIGH_PRIORITY);
System.out.println("Timer resolution: " + Sys.getTimerResolution());
System.out.println("Number of texture units: " + Util.glGetInteger(GL13.GL_MAX_TEXTURE_UNITS));

View file

@ -196,8 +196,7 @@ public final class VBOIndexTest {
* Initialize
*/
private static void init() throws Exception {
Sys.setTime(0);
Sys.setProcessPriority(Sys.HIGH_PRIORITY);
System.out.println("Timer resolution: " + Sys.getTimerResolution());
// Go into orthographic projection mode.
GL11.glMatrixMode(GL11.GL_PROJECTION);

View file

@ -176,8 +176,6 @@ public final class VBOTest {
* Initialize
*/
private static void init() throws Exception {
Sys.setTime(0);
Sys.setProcessPriority(Sys.HIGH_PRIORITY);
System.out.println("Timer resolution: " + Sys.getTimerResolution());
// Go into orthographic projection mode.
GL11.glMatrixMode(GL11.GL_PROJECTION);