Delegate Sys platform dependent methods into SysImplementation instances

This commit is contained in:
Elias Naur 2005-01-18 20:23:05 +00:00
parent 87ce7a85af
commit 66181d1486
14 changed files with 253 additions and 365 deletions

View File

@ -385,13 +385,14 @@
</javah>
<javah classpath="${lwjgl.bin}" destdir="${lwjgl.src.native}/win32" force="yes">
<class name="org.lwjgl.opengl.Win32Display" />
<class name="org.lwjgl.Win32SysImplementation" />
</javah>
<javah classpath="${lwjgl.bin}" destdir="${lwjgl.src.native}/macosx" force="yes">
<class name="org.lwjgl.opengl.MacOSXDisplay" />
</javah>
<!-- lwjgl -->
<javah classpath="${lwjgl.bin}" destdir="${lwjgl.src.headers}" force="yes">
<class name="org.lwjgl.Sys" />
<class name="org.lwjgl.DefaultSysImplementation" />
<class name="org.lwjgl.input.Cursor" />
<class name="org.lwjgl.input.Keyboard" />

View File

@ -1,64 +1,58 @@
/*
/*
* Copyright (c) 2002-2004 LWJGL Project
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'LWJGL' nor the names of
* its contributors may be used to endorse or promote products derived
* * Neither the name of 'LWJGL' nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.lwjgl;
import java.lang.reflect.Method;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
/**
* $Id$
* <p>
* A Swing adapter for using Swing to take care of things on platforms where we
* know Swing is present.
* <p><em>Note</em> To compile LWJGL applications with Excelsior JET that use JetPerfect
* and that have no dependencies on Swing, do not include this class in your
* JET project.
*
* @author cix_foo <cix_foo@users.sourceforge.net>
*
* @author elias_naur <elias_naur@users.sourceforge.net>
* @version $Revision$
*/
final class SwingAdapter implements PlatformAdapter {
/**
* Constructs a new SwingAdapter
*/
SwingAdapter() {
abstract class DefaultSysImplementation implements SysImplementation {
public native String getNativeLibraryVersion();
public native void setDebug(boolean debug);
public long getTimerResolution() {
return 1000;
}
public long getTime() {
return System.currentTimeMillis();
}
/**
* Spawn a "modal" dialog in the centre of the screen with a message in it
* and an OK button. This method blocks until the dialog is dismissed.
* @param title Title of alert
* @param message Message to show in alert
*/
public void alert(String title, String message) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
@ -66,13 +60,7 @@ final class SwingAdapter implements PlatformAdapter {
}
JOptionPane.showMessageDialog(null, message, title, JOptionPane.WARNING_MESSAGE);
}
/**
* Get the contents of the system clipboard. The system might not have a clipboard
* (particularly if it doesn't even have a keyboard) in which case we return null.
* Otherwise we return a String, which may be the empty string "".
* @return a String, or null if there is no system clipboard.
*/
public String getClipboard() {
try {
java.awt.datatransfer.Clipboard clipboard = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();

View File

@ -1,96 +1,65 @@
/*
/*
* Copyright (c) 2002-2004 LWJGL Project
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'LWJGL' nor the names of
* its contributors may be used to endorse or promote products derived
* * Neither the name of 'LWJGL' nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.lwjgl;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import java.io.IOException;
/**
* $Id$
*
* Linux system library.
* $Id$
*
* @author elias_naur <elias_naur@users.sourceforge.net>
* @version $Revision$
*/
class LinuxSysImplementation extends DefaultSysImplementation {
public boolean openURL(String url) {
// Linux may as well resort to pure Java hackery, as there's no Linux native way of doing it
// right anyway.
#include <sched.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <Carbon/Carbon.h>
#include "org_lwjgl_Sys.h"
#include "common_tools.h"
String[] browsers = {"mozilla", "opera", "konqueror", "nautilus", "galeon", "netscape"};
static long int hires_timer; // Hires timer current time
for (int i = 0; i < browsers.length; i ++) {
try {
Runtime.getRuntime().exec(new String[] { browsers[i], url });
return true;
} catch (IOException e) {
// Ignore
e.printStackTrace(System.err);
}
}
/*
* Class: org_lwjgl_Sys
* Method: getTimerResolution
* Signature: ()J
*/
JNIEXPORT jlong JNICALL Java_org_lwjgl_Sys_getTimerResolution
(JNIEnv * env, jclass clazz)
{
// Constant on MacOS
return 1000000;
}
static long queryTime(void) {
struct timeval tv;
if (gettimeofday(&tv, NULL) == -1) {
printfDebug("Could not read current time\n");
}
long result = tv.tv_sec * 1000000l + tv.tv_usec;
return result;
}
JNIEXPORT void JNICALL Java_org_lwjgl_Sys_setDebug(JNIEnv *env, jclass clazz, jboolean enabled) {
setDebugEnabled(enabled == JNI_TRUE ? true : false);
}
JNIEXPORT jlong JNICALL Java_org_lwjgl_Sys_ngetTime
(JNIEnv * env, jclass clazz)
{
hires_timer = queryTime();
return (jlong) hires_timer;
}
JNIEXPORT jstring JNICALL Java_org_lwjgl_Sys_getNativeLibraryVersion(JNIEnv *env, jclass clazz) {
return getVersionString(env);
}
JNIEXPORT void JNICALL Java_org_lwjgl_Sys_nAlert(JNIEnv * env, jclass clazz, jstring title, jstring message)
{
}
JNIEXPORT jstring JNICALL Java_org_lwjgl_Sys_nGetClipboard
(JNIEnv * env, jclass clazz)
{
return NULL;
// Seems to have failed
return false;
}
}

View File

@ -0,0 +1,55 @@
/*
* Copyright (c) 2002-2004 LWJGL Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'LWJGL' nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.lwjgl;
import java.lang.reflect.Method;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
/**
* $Id$
*
* @author elias_naur <elias_naur@users.sourceforge.net>
* @version $Revision$
*/
class MacOSXSysImplementation extends DefaultSysImplementation {
public boolean openURL(String url) {
try {
Class com_apple_eio_FileManager = Class.forName("com.apple.eio.FileManager");
Method openURL_method = com_apple_eio_FileManager.getMethod("openURL", new Class[]{String.class});
openURL_method.invoke(null, new Object[]{url});
return true;
} catch (Exception e) {
return false;
}
}
}

View File

@ -51,27 +51,54 @@ public final class Sys {
public static final String VERSION = "0.94";
/** The native library name */
private static String LIBRARY_NAME = "lwjgl";
private static final String LIBRARY_NAME = "lwjgl";
/** The platform adapter class name */
private static String PLATFORM;
private static final String PLATFORM;
/**
* Debug flag.
*/
public static final boolean DEBUG = Boolean.getBoolean("org.lwjgl.Sys.debug");
private static boolean initialized;
/**
* The implementation instance to delegate platform specific behavior to
*/
private final static SysImplementation implementation;
static {
initialize();
System.loadLibrary(LIBRARY_NAME);
implementation = createImplementation();
String native_version = implementation.getNativeLibraryVersion();
if (!native_version.equals(VERSION))
throw new LinkageError("Version mismatch: jar version is '" + VERSION +
"', native libary version is '" + native_version + "'");
implementation.setDebug(DEBUG);
PLATFORM = System.getProperty("org.lwjgl.Sys.platform", "org.lwjgl.SwingAdapter");
}
/**
* @return the name of the native library to load
*/
private static String getLibraryName() {
return LIBRARY_NAME;
private static SysImplementation createImplementation() {
String class_name;
String os_name = System.getProperty("os.name");
if (os_name.startsWith("Linux")) {
class_name = "org.lwjgl.LinuxSysImplementation";
} else if (os_name.startsWith("Windows")) {
class_name = "org.lwjgl.Win32SysImplementation";
} else if (os_name.startsWith("Mac")) {
class_name = "org.lwjgl.MacOSXSysImplementation";
} else
throw new IllegalStateException("The platform " + os_name + " is not supported");
try {
Class impl_class = Class.forName(class_name);
return (SysImplementation)impl_class.newInstance();
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
} catch (InstantiationException e) {
throw new RuntimeException(e);
}
}
/**
@ -91,39 +118,19 @@ public final class Sys {
}
/**
* Initialization.
* Initialization. This is just a dummy method to trigger the static constructor.
*/
public static void initialize() {
if (initialized)
return;
initialized = true;
System.loadLibrary(LIBRARY_NAME);
String native_version = getNativeLibraryVersion();
if (!native_version.equals(VERSION))
throw new LinkageError("Version mismatch: jar version is '" + VERSION +
"', native libary version is '" + native_version + "'");
setDebug(DEBUG);
PLATFORM = System.getProperty("org.lwjgl.Sys.platform", "org.lwjgl.SwingAdapter");
}
/**
* Return the version of the native library
*/
private static native String getNativeLibraryVersion();
/**
* Set the debug level of the native library
*/
private static native void setDebug(boolean debug);
/**
* Obtains the number of ticks that the hires timer does in a second.
*
* @return timer resolution in ticks per second or 0 if no timer is present.
*/
public static native long getTimerResolution();
public static long getTimerResolution() {
return implementation.getTimerResolution();
}
/**
* Gets the current value of the hires timer, in ticks. When the Sys class is first loaded
@ -133,9 +140,8 @@ public final class Sys {
* @return the current hires time, in ticks (always >= 0)
*/
public static long getTime() {
return ngetTime() & 0x7FFFFFFFFFFFFFFFL;
return implementation.getTime() & 0x7FFFFFFFFFFFFFFFL;
}
private static native long ngetTime();
/**
* Attempt to display a modal alert to the user. This method should be used
@ -165,23 +171,12 @@ public final class Sys {
if (message == null)
message = "";
String osName = System.getProperty("os.name");
if (osName.startsWith("Windows")) {
nAlert(title, message);
} else {
try {
PlatformAdapter adapter = (PlatformAdapter) Class.forName(PLATFORM).newInstance(); // This avoids a Jet error message
adapter.alert(title, message);
} catch (Exception e) {
Sys.log("Unable to display alert using: " + PLATFORM);
}
}
implementation.alert(title, message);
if (grabbed) {
Mouse.setGrabbed(true);
}
}
private static native void nAlert(String title, String message);
/**
* Open the system web browser and point it at the specified URL. It is recommended
* that this not be called whilst your game is running, but on application exit in
@ -212,7 +207,7 @@ public final class Sys {
return false;
}
} catch (Exception ue) {
return Display.getImplementation().openURL(url);
return implementation.openURL(url);
}
}
@ -225,15 +220,6 @@ public final class Sys {
* @return a String, or null if there is no system clipboard.
*/
public static String getClipboard() {
try {
PlatformAdapter adapter = (PlatformAdapter) Class.forName(PLATFORM).newInstance(); // This avoids a Jet error message
return adapter.getClipboard();
} catch (Throwable e) {
Sys.log("Unable to get clipboard contents: " + e);
// ignore exception and use native implementation
return nGetClipboard();
}
return implementation.getClipboard();
}
private static native String nGetClipboard();
}

View File

@ -31,30 +31,35 @@
*/
package org.lwjgl;
/**
* $Id$
*
* Interface for adapting to window environments.
* System class platform specific method interface
*
* @author cix_foo <cix_foo@users.sourceforge.net>
* @author elias_naur <elias_naur@users.sourceforge.net>
* @version $Revision$
*/
public interface PlatformAdapter {
interface SysImplementation {
/**
* Return the version of the native library
*/
public String getNativeLibraryVersion();
public void setDebug(boolean debug);
/**
* Spawn a "modal" dialog in the centre of the screen with a message in it
* and an OK button. This method blocks until the dialog is dismissed.
* @param title
* @param message
* Obtains the number of ticks that the hires timer does in a second.
*
* @return timer resolution in ticks per second or 0 if no timer is present.
*/
void alert(String title, String message);
public long getTimerResolution();
/**
* Get the contents of the system clipboard. The system might not have a clipboard
* (particularly if it doesn't even have a keyboard) in which case we return null.
* Otherwise we return a String, which may be the empty string "".
* @return a String, or null if there is no system clipboard.
*/
String getClipboard();
public long getTime();
public void alert(String title, String message);
boolean openURL(String url);
public String getClipboard();
}

View File

@ -0,0 +1,50 @@
/*
* Copyright (c) 2002-2004 LWJGL Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'LWJGL' nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.lwjgl;
/**
* $Id$
*
* @author elias_naur <elias_naur@users.sourceforge.net>
* @version $Revision$
*/
class Win32SysImplementation extends DefaultSysImplementation {
public native long getTimerResolution();
public native long getTime();
public native void alert(String title, String message);
public native boolean openURL(String url);
public native String getClipboard();
}

View File

@ -248,6 +248,4 @@ public interface DisplayImplementation {
public void bindTexImageToPbuffer(ByteBuffer handle, int buffer);
public void releaseTexImageFromPbuffer(ByteBuffer handle, int buffer);
boolean openURL(String url);
}

View File

@ -393,24 +393,4 @@ final class LinuxDisplay implements DisplayImplementation {
public void releaseTexImageFromPbuffer(ByteBuffer handle, int buffer) {
throw new UnsupportedOperationException();
}
public boolean openURL(String url) {
// Linux may as well resort to pure Java hackery, as there's no Linux native way of doing it
// right anyway.
String[] browsers = {"mozilla", "opera", "konqueror", "nautilus", "galeon", "netscape"};
for (int i = 0; i < browsers.length; i ++) {
try {
Runtime.getRuntime().exec(new String[] { browsers[i], url });
return true;
} catch (IOException e) {
// Ignore
e.printStackTrace(System.err);
}
}
// Seems to have failed
return false;
}
}

View File

@ -368,18 +368,6 @@ final class MacOSXDisplay implements DisplayImplementation {
return GL11.glGetString(GL11.GL_EXTENSIONS).indexOf("GL_APPLE_pixel_buffer") != -1 ? Pbuffer.PBUFFER_SUPPORTED : 0;
}
/* Use the com.apple.eio.FileManager Mac OS X extension to show the given URL */
public boolean openURL(String url) {
try {
Class com_apple_eio_FileManager = Class.forName("com.apple.eio.FileManager");
Method openURL_method = com_apple_eio_FileManager.getMethod("openURL", new Class[]{String.class});
openURL_method.invoke(null, new Object[]{url});
return true;
} catch (Exception e) {
return false;
}
}
/**
* This class captures com.apple.eawt.ApplicationEvents through reflection
* to enable compilation on other platforms than Mac OS X

View File

@ -126,11 +126,4 @@ final class Win32Display implements DisplayImplementation {
public native void setPbufferAttrib(ByteBuffer handle, int attrib, int value);
public native void bindTexImageToPbuffer(ByteBuffer handle, int buffer);
public native void releaseTexImageFromPbuffer(ByteBuffer handle, int buffer);
public boolean openURL(String url) {
nOpenURL(url);
return true;
}
private native void nOpenURL(String url);
}

View File

@ -45,6 +45,7 @@
#endif
#include "common_tools.h"
#include "org_lwjgl_DefaultSysImplementation.h"
static bool debug = false;
static const char* VERSION = "0.94";
@ -63,18 +64,20 @@ void putAttrib(attrib_list_t *list, int attrib) {
list->current_index++;
}
jstring getVersionString(JNIEnv *env) {
JNIEXPORT jstring JNICALL Java_org_lwjgl_DefaultSysImplementation_getNativeLibraryVersion
(JNIEnv *env, jobject ignored) {
return NewStringNative(env, VERSION);
}
JNIEXPORT void JNICALL Java_org_lwjgl_DefaultSysImplementation_setDebug
(JNIEnv *env, jobject ignored, jboolean enable) {
debug = enable == JNI_TRUE ? true : false;
}
bool isDebugEnabled(void) {
return debug;
}
void setDebugEnabled(bool enable) {
debug = enable;
}
void printfDebugJava(JNIEnv *env, const char *format, ...) {
#define BUFFER_SIZE 4000
static char buffer[BUFFER_SIZE];

View File

@ -1,120 +0,0 @@
/*
* Copyright (c) 2002-2004 LWJGL Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'LWJGL' nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* $Id$
*
* Linux system library.
*
* @author elias_naur <elias_naur@users.sourceforge.net>
* @version $Revision$
*/
#include <sys/time.h>
#include <sys/resource.h>
#include "org_lwjgl_Sys.h"
#include "common_tools.h"
static long int hires_timer; // Hires timer current time
/*
* Class: org_lwjgl_Sys
* Method: getTimerResolution
* Signature: ()J
*/
JNIEXPORT jlong JNICALL Java_org_lwjgl_Sys_getTimerResolution
(JNIEnv * env, jclass clazz)
{
// Constant on linux
return 1000000;
}
static long queryTime(JNIEnv *env) {
struct timeval tv;
if (gettimeofday(&tv, NULL) == -1) {
printfDebugJava(env, "Could not read current time");
}
long result = tv.tv_sec * 1000000l + tv.tv_usec;
return result;
}
JNIEXPORT void JNICALL Java_org_lwjgl_Sys_setDebug(JNIEnv *env, jclass clazz, jboolean enabled) {
setDebugEnabled(enabled == JNI_TRUE ? true : false);
}
/*
* Class: org_lwjgl_Sys
* Method: ngetTime
* Signature: ()J
*/
JNIEXPORT jlong JNICALL Java_org_lwjgl_Sys_ngetTime
(JNIEnv * env, jclass clazz)
{
hires_timer = queryTime(env);
return (jlong) hires_timer;
}
JNIEXPORT void JNICALL Java_org_lwjgl_Sys_nAlert(JNIEnv * env, jclass clazz, jstring title, jstring message)
{
char * eMessageText = GetStringNativeChars(env, message);
char * cTitleBarText = GetStringNativeChars(env, title);
printfDebugJava(env, "*** Alert ***%s\n%s\n", cTitleBarText, eMessageText);
free(eMessageText);
free(cTitleBarText);
}
JNIEXPORT jstring JNICALL Java_org_lwjgl_Sys_getNativeLibraryVersion(JNIEnv *env, jclass clazz) {
return getVersionString(env);
}
/*
* Class: org_lwjgl_Sys
* Method: openURL
* Signature: (Ljava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_Sys_nOpenURL
(JNIEnv * env, jclass clazz, jstring url)
{
char * urlString = GetStringNativeChars(env, url);
printf("*** Please visit %s\n", urlString);
free(urlString);
}
JNIEXPORT jstring JNICALL Java_org_lwjgl_Sys_nGetClipboard
(JNIEnv * env, jclass clazz)
{
return NULL;
}

View File

@ -53,28 +53,20 @@ unsigned __int64 hires_timer = 0; // Hires timer current time
* Method: getTimerResolution
* Signature: ()J
*/
JNIEXPORT jlong JNICALL Java_org_lwjgl_Sys_getTimerResolution
(JNIEnv * env, jclass clazz)
JNIEXPORT jlong JNICALL Java_org_lwjgl_Win32SysImplementation_getTimerResolution
(JNIEnv * env, jobject ignored)
{
QueryPerformanceFrequency((LARGE_INTEGER*) &hires_timer_freq);
return (jlong) hires_timer_freq;
}
JNIEXPORT void JNICALL Java_org_lwjgl_Sys_setDebug(JNIEnv *env, jclass clazz, jboolean enabled) {
setDebugEnabled(enabled == JNI_TRUE ? true : false);
}
JNIEXPORT jstring JNICALL Java_org_lwjgl_Sys_getNativeLibraryVersion(JNIEnv *env, jclass clazz) {
return getVersionString(env);
}
/*
* Class: org_lwjgl_Sys
* Method: ngetTime
* Signature: ()J
*/
JNIEXPORT jlong JNICALL Java_org_lwjgl_Sys_ngetTime
(JNIEnv * env, jclass clazz)
JNIEXPORT jlong JNICALL Java_org_lwjgl_Win32SysImplementation_getTime
(JNIEnv * env, jobject ignored)
{
QueryPerformanceCounter((LARGE_INTEGER*) &hires_timer);
return (jlong) hires_timer;
@ -85,8 +77,8 @@ JNIEXPORT jlong JNICALL Java_org_lwjgl_Sys_ngetTime
* Method: alert
* Signature: (Ljava/lang/String;Ljava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_Sys_nAlert
(JNIEnv * env, jclass clazz, jstring title, jstring message)
JNIEXPORT void JNICALL Java_org_lwjgl_Win32SysImplementation_alert
(JNIEnv * env, jobject ignored, jstring title, jstring message)
{
char * eMessageText = GetStringNativeChars(env, message);
char * cTitleBarText = GetStringNativeChars(env, title);
@ -103,8 +95,8 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Sys_nAlert
* Method: openURL
* Signature: (Ljava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_nOpenURL
(JNIEnv * env, jobject self, jstring url)
JNIEXPORT void JNICALL Java_org_lwjgl_Win32SysImplementation_openURL
(JNIEnv * env, jobject ignored, jstring url)
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
@ -169,8 +161,8 @@ const void * getClipboard(int type)
}
JNIEXPORT jstring JNICALL Java_org_lwjgl_Sys_nGetClipboard
(JNIEnv * env, jclass clazz)
JNIEXPORT jstring JNICALL Java_org_lwjgl_Win32SysImplementation_getClipboard
(JNIEnv * env, jobject ignored)
{
// Check to see if there's text available in the clipboard
BOOL textAvailable = IsClipboardFormatAvailable(CF_TEXT);