mirror of
https://github.com/shadowfacts/lwjgl2-arm64.git
synced 2026-02-25 00:55:02 +01:00
Replaced debug libraries with runtime debug condition
This commit is contained in:
parent
cd2a1cc13f
commit
472b5337d4
|
|
@ -80,7 +80,7 @@ public final class Display {
|
|||
static {
|
||||
System.loadLibrary(Sys.getLibraryName());
|
||||
init();
|
||||
if (Sys.DEBUG) {
|
||||
if (Sys.atDebugLevel()) {
|
||||
System.out.println("Adapter: "+getAdapter()+" Version: "+getVersion());
|
||||
}
|
||||
}
|
||||
|
|
@ -120,7 +120,7 @@ public final class Display {
|
|||
DisplayMode[] filteredModes = new DisplayMode[modes.size()];
|
||||
modes.toArray(filteredModes);
|
||||
|
||||
if (Sys.DEBUG) {
|
||||
if (Sys.atDebugLevel()) {
|
||||
System.out.println("Removed " + (unfilteredModes.length - filteredModes.length) + " duplicate displaymodes");
|
||||
}
|
||||
|
||||
|
|
@ -239,7 +239,7 @@ public final class Display {
|
|||
gammaRamp.put(i, rampEntry);
|
||||
}
|
||||
setGammaRamp(gammaRamp);
|
||||
if (Sys.DEBUG) {
|
||||
if (Sys.atDebugLevel()) {
|
||||
System.out.println("Gamma set, gamma = " + gamma + ", brightness = " + brightness + ", contrast = " + contrast);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,6 +47,9 @@ import org.lwjgl.input.Mouse;
|
|||
* @version $Revision$
|
||||
*/
|
||||
public final class Sys {
|
||||
/** Debug level constants */
|
||||
public static final int DEBUG_DISABLED = 1;
|
||||
public static final int DEBUG_ENABLED = 2;
|
||||
|
||||
/** Low process priority. @see #setProcessPriority() */
|
||||
public static final int LOW_PRIORITY = -1;
|
||||
|
|
@ -78,38 +81,26 @@ public final class Sys {
|
|||
public static final int REALTIME_PRIORITY = 2;
|
||||
|
||||
/** The native library name */
|
||||
private static String LIBRARY_NAME;
|
||||
private static String LIBRARY_NAME = "lwjgl";
|
||||
|
||||
/**
|
||||
* Debug flag. This will tell you if you are using the debug version of
|
||||
* Debug level. This will tell you if you are using the debug version of
|
||||
* the library, and whether assertions are enabled or not.
|
||||
*/
|
||||
public static final boolean DEBUG;
|
||||
public static final int DEBUG;
|
||||
|
||||
/**
|
||||
* The ByteBuffer equivalent of the native NULL constant
|
||||
*/
|
||||
// public static final ByteBuffer NULL;
|
||||
|
||||
|
||||
private static boolean _debug;
|
||||
static {
|
||||
int _debug = DEBUG_DISABLED;
|
||||
try {
|
||||
assert false;
|
||||
LIBRARY_NAME = "lwjgl";
|
||||
_debug = false;
|
||||
} catch (AssertionError e) {
|
||||
// Assertions are enabled, so we'll use the debug version of the
|
||||
// library
|
||||
LIBRARY_NAME = "lwjgl_d";
|
||||
_debug = true;
|
||||
// Assertions are enabled, so we'll enabled debugging
|
||||
_debug = DEBUG_ENABLED;
|
||||
} finally {
|
||||
DEBUG = _debug;
|
||||
initialize();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return the name of the native library to load
|
||||
|
|
@ -124,11 +115,16 @@ public final class Sys {
|
|||
private Sys() {
|
||||
}
|
||||
|
||||
public static boolean atDebugLevel() {
|
||||
return DEBUG >= DEBUG_ENABLED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialization.
|
||||
*/
|
||||
private static void initialize() {
|
||||
System.loadLibrary(LIBRARY_NAME);
|
||||
setDebugLevel(DEBUG);
|
||||
setTime(0);
|
||||
|
||||
Runtime.getRuntime().addShutdownHook(new Thread() {
|
||||
|
|
@ -145,6 +141,11 @@ public final class Sys {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the debug level of the native library
|
||||
*/
|
||||
private static native void setDebugLevel(int level);
|
||||
|
||||
/**
|
||||
* Obtains the number of ticks that the hires timer does in a second.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -142,7 +142,7 @@ public abstract class BaseAL {
|
|||
private static String getPathFromJWS(String libname) {
|
||||
try {
|
||||
|
||||
if(Sys.DEBUG) {
|
||||
if(Sys.atDebugLevel()) {
|
||||
System.out.println("JWS Classloader looking for: " + libname);
|
||||
}
|
||||
|
||||
|
|
@ -154,7 +154,7 @@ public abstract class BaseAL {
|
|||
return (String) findLibrary.invoke(o, arguments);
|
||||
|
||||
} catch (Exception e) {
|
||||
if(Sys.DEBUG) {
|
||||
if(Sys.atDebugLevel()) {
|
||||
System.out.println("Failure locating OpenAL using classloader:");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -162,13 +162,13 @@ public abstract class GLCaps {
|
|||
}
|
||||
|
||||
private static void setExtensionFields(HashSet exts, HashMap field_map) {
|
||||
if(org.lwjgl.Sys.DEBUG) {
|
||||
if(org.lwjgl.Sys.atDebugLevel()) {
|
||||
System.out.println("Available extensions:");
|
||||
}
|
||||
Iterator it = exts.iterator();
|
||||
while (it.hasNext()) {
|
||||
String ext = (String)it.next();
|
||||
if(org.lwjgl.Sys.DEBUG) {
|
||||
if(org.lwjgl.Sys.atDebugLevel()) {
|
||||
System.out.println(ext);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,36 +10,32 @@
|
|||
#ifndef _CHECKALERROR_H_INCLUDED_
|
||||
#define _CHECKALERROR_H_INCLUDED_
|
||||
|
||||
#ifdef _DEBUG
|
||||
|
||||
#include <jni.h>
|
||||
#include "extal.h"
|
||||
#include "common_tools.h"
|
||||
|
||||
#define CHECK_AL_ERROR \
|
||||
{ \
|
||||
int err = alGetError(); \
|
||||
if (err != AL_NO_ERROR) { \
|
||||
jclass cls = env->FindClass("org/lwjgl/openal/OpenALException"); \
|
||||
env->ThrowNew(cls, (const char*) alGetString(err)); \
|
||||
env->DeleteLocalRef(cls); \
|
||||
if (ATDEBUGLEVEL()) { \
|
||||
int err = alGetError(); \
|
||||
if (err != AL_NO_ERROR) { \
|
||||
jclass cls = env->FindClass("org/lwjgl/openal/OpenALException"); \
|
||||
env->ThrowNew(cls, (const char*) alGetString(err)); \
|
||||
env->DeleteLocalRef(cls); \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
/* only available if deviceaddress is specified in method */
|
||||
#define CHECK_ALC_ERROR \
|
||||
{ \
|
||||
int err = alcGetError((ALCdevice*) deviceaddress); \
|
||||
if (err != AL_NO_ERROR) { \
|
||||
jclass cls = env->FindClass("org/lwjgl/openal/OpenALException"); \
|
||||
env->ThrowNew(cls, (const char*) alcGetString((ALCdevice*) deviceaddress, err)); \
|
||||
env->DeleteLocalRef(cls); \
|
||||
if (ATDEBUGLEVEL()) { \
|
||||
int err = alcGetError((ALCdevice*) deviceaddress); \
|
||||
if (err != AL_NO_ERROR) { \
|
||||
jclass cls = env->FindClass("org/lwjgl/openal/OpenALException"); \
|
||||
env->ThrowNew(cls, (const char*) alcGetString((ALCdevice*) deviceaddress, err)); \
|
||||
env->DeleteLocalRef(cls); \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#define CHECK_AL_ERROR
|
||||
#define CHECK_ALC_ERROR
|
||||
|
||||
#endif /* _DEBUG */
|
||||
|
||||
#endif /* _CHECKALERROR_H_INCLUDED_ */
|
||||
|
|
|
|||
|
|
@ -10,18 +10,19 @@
|
|||
#ifndef _CHECKGLERROR_H_INCLUDED_
|
||||
#define _CHECKGLERROR_H_INCLUDED_
|
||||
|
||||
#ifdef _DEBUG
|
||||
|
||||
#include <jni.h>
|
||||
#include "extgl.h"
|
||||
#include "common_tools.h"
|
||||
|
||||
#define CHECK_GL_ERROR \
|
||||
{ \
|
||||
int err = glGetError(); \
|
||||
if (err != GL_NO_ERROR) { \
|
||||
jclass cls = env->FindClass("org/lwjgl/opengl/OpenGLException"); \
|
||||
env->ThrowNew(cls, (const char *)gluErrorString(err)); \
|
||||
env->DeleteLocalRef(cls); \
|
||||
if (ATDEBUGLEVEL()) { \
|
||||
int err = glGetError(); \
|
||||
if (err != GL_NO_ERROR) { \
|
||||
jclass cls = env->FindClass("org/lwjgl/opengl/OpenGLException"); \
|
||||
env->ThrowNew(cls, (const char *)gluErrorString(err)); \
|
||||
env->DeleteLocalRef(cls); \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
|
|
@ -34,11 +35,4 @@
|
|||
} \
|
||||
} \
|
||||
|
||||
#else
|
||||
|
||||
#define CHECK_GL_ERROR
|
||||
#define CHECK_EXISTS(f)
|
||||
|
||||
#endif /* _DEBUG */
|
||||
|
||||
#endif /* _CHECKGLERROR_H_INCLUDED_ */
|
||||
|
|
|
|||
|
|
@ -39,6 +39,20 @@
|
|||
|
||||
#include "common_tools.h"
|
||||
|
||||
int debug_level = org_lwjgl_Sys_DEBUG_DISABLED;
|
||||
|
||||
void setDebugLevel(int level) {
|
||||
debug_level = level;
|
||||
}
|
||||
|
||||
int printfDebug(const char *format, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
int result = vprintf(format, ap);
|
||||
va_end(ap);
|
||||
return result;
|
||||
}
|
||||
|
||||
static void incListStart(event_queue_t *queue) {
|
||||
queue->list_start = (queue->list_start + 1)%EVENT_BUFFER_SIZE;
|
||||
}
|
||||
|
|
@ -51,9 +65,7 @@ void initEventQueue(event_queue_t *event_queue) {
|
|||
void putEventElement(event_queue_t *queue, unsigned char byte) {
|
||||
int next_index = (queue->list_end + 1)%EVENT_BUFFER_SIZE;
|
||||
if (next_index == queue->list_start) {
|
||||
#ifdef _DEBUG
|
||||
printf("Event buffer overflow!\n");
|
||||
#endif
|
||||
printfDebug("Event buffer overflow!\n");
|
||||
return;
|
||||
}
|
||||
queue->input_event_buffer[queue->list_end] = byte;
|
||||
|
|
|
|||
|
|
@ -41,9 +41,13 @@
|
|||
#define _COMMON_TOOLS_H
|
||||
|
||||
#include <jni.h>
|
||||
#include "org_lwjgl_Sys.h"
|
||||
|
||||
extern int debug_level;
|
||||
|
||||
// Must be x * max_event_size + 1
|
||||
#define EVENT_BUFFER_SIZE (25 * 4 + 1)
|
||||
#define ATDEBUGLEVEL() (debug_level >= org_lwjgl_Sys_DEBUG_ENABLED)
|
||||
|
||||
typedef struct {
|
||||
unsigned char input_event_buffer[EVENT_BUFFER_SIZE];
|
||||
|
|
@ -60,5 +64,7 @@ extern unsigned char *getOutputList(event_queue_t *queue);
|
|||
extern int getEventBufferSize(event_queue_t *event_queue);
|
||||
extern void throwException(JNIEnv *env, const char *msg);
|
||||
extern void throwOpenALException(JNIEnv * env, const char * err);
|
||||
extern void setDebugLevel(int level);
|
||||
extern int printfDebug(const char *format, ...);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -182,9 +182,7 @@ static void *NativeGetFunctionPointer(const char *function) {
|
|||
static void* GetFunctionPointer(const char* function) {
|
||||
void *p = NativeGetFunctionPointer(function);
|
||||
if (p == NULL) {
|
||||
#ifdef _DEBUG
|
||||
printf("Could not locate symbol %s\n", function);
|
||||
#endif
|
||||
printfDebug("Could not locate symbol %s\n", function);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
|
@ -195,15 +193,11 @@ static void* GetFunctionPointer(const char* function) {
|
|||
static bool LoadOpenAL(JNIEnv *env, jobjectArray oalPaths) {
|
||||
|
||||
jsize pathcount = env->GetArrayLength(oalPaths);
|
||||
#ifdef _DEBUG
|
||||
printf("Found %d OpenAL paths\n", (int)pathcount);
|
||||
#endif
|
||||
printfDebug("Found %d OpenAL paths\n", (int)pathcount);
|
||||
for(int i=0;i<pathcount;i++) {
|
||||
jstring path = (jstring) env->GetObjectArrayElement(oalPaths, i);
|
||||
const char *path_str = env->GetStringUTFChars(path, NULL);
|
||||
#ifdef _DEBUG
|
||||
printf("Testing '%s'\n", path_str);
|
||||
#endif
|
||||
printfDebug("Testing '%s'\n", path_str);
|
||||
#ifdef _WIN32
|
||||
handleOAL = LoadLibrary(path_str);
|
||||
#endif
|
||||
|
|
@ -214,9 +208,7 @@ static bool LoadOpenAL(JNIEnv *env, jobjectArray oalPaths) {
|
|||
handleOAL = NSAddImage(path_str, NSADDIMAGE_OPTION_RETURN_ON_ERROR);
|
||||
#endif
|
||||
if (handleOAL != NULL) {
|
||||
#ifdef _DEBUG
|
||||
printf("Found OpenAL at '%s'\n", path_str);
|
||||
#endif
|
||||
printfDebug("Found OpenAL at '%s'\n", path_str);
|
||||
return true;
|
||||
}
|
||||
env->ReleaseStringUTFChars(path, path_str);
|
||||
|
|
|
|||
|
|
@ -33,9 +33,10 @@ THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
*/
|
||||
|
||||
#include "extgl.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "extgl.h"
|
||||
#include "common_tools.h"
|
||||
|
||||
/* turn off the warning for the borland compiler*/
|
||||
#ifdef __BORLANDC__
|
||||
|
|
@ -1338,9 +1339,7 @@ static CFBundleRef loadBundle(const Str255 frameworkName)
|
|||
err = FindFolder (kSystemDomain, kFrameworksFolderType, false, &fileRefParam.ioVRefNum, &fileRefParam.ioDirID);
|
||||
if (noErr != err)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
printf("Could not find frameworks folder\n");
|
||||
#endif
|
||||
printfDebug("Could not find frameworks folder\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -1351,9 +1350,7 @@ static CFBundleRef loadBundle(const Str255 frameworkName)
|
|||
|
||||
if (noErr != err)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
printf("Could make FSref to frameworks folder\n");
|
||||
#endif
|
||||
printfDebug("Could make FSref to frameworks folder\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -1362,9 +1359,7 @@ static CFBundleRef loadBundle(const Str255 frameworkName)
|
|||
bundleURLOpenGL = CFURLCreateFromFSRef (kCFAllocatorDefault, &fileRef);
|
||||
if (!bundleURLOpenGL)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
printf("Could create framework URL\n");
|
||||
#endif
|
||||
printfDebug("Could create framework URL\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -1372,18 +1367,14 @@ static CFBundleRef loadBundle(const Str255 frameworkName)
|
|||
CFRelease (bundleURLOpenGL);
|
||||
if (bundle_ref == NULL)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
printf("Could not load framework\n");
|
||||
#endif
|
||||
printfDebug("Could not load framework\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// if the code was successfully loaded, look for our function.
|
||||
if (!CFBundleLoadExecutable(bundle_ref))
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
printf("Could not load MachO executable\n");
|
||||
#endif
|
||||
printfDebug("Could not load MachO executable\n");
|
||||
CFRelease(bundle_ref);
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -1412,9 +1403,7 @@ static void *extgl_GetProcAddress(char *name)
|
|||
{
|
||||
t = GetProcAddress(lib_glu_handle, name);
|
||||
if (t == NULL) {
|
||||
#ifdef _DEBUG
|
||||
printf("Could not locate symbol %s\n", name);
|
||||
#endif
|
||||
printfDebug("Could not locate symbol %s\n", name);
|
||||
extgl_error = true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1431,9 +1420,7 @@ static void *extgl_GetProcAddress(char *name)
|
|||
{
|
||||
t = dlsym(lib_glu_handle, name);
|
||||
if (t == NULL) {
|
||||
#ifdef _DEBUG
|
||||
printf("Could not locate symbol %s\n", name);
|
||||
#endif
|
||||
printfDebug("Could not locate symbol %s\n", name);
|
||||
extgl_error = true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1447,9 +1434,7 @@ static void *extgl_GetProcAddress(char *name)
|
|||
if (func_pointer == NULL) {
|
||||
func_pointer = CFBundleGetFunctionPointerForName(agl_bundle_ref, str);
|
||||
if (func_pointer == NULL) {
|
||||
#ifdef _DEBUG
|
||||
printf("Could not locate symbol %s\n", name);
|
||||
#endif
|
||||
printfDebug("Could not locate symbol %s\n", name);
|
||||
extgl_error = true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1464,9 +1449,7 @@ static bool QueryExtension(JNIEnv *env, jobject ext_set, const GLubyte*extension
|
|||
GLubyte *where, *terminator;
|
||||
|
||||
if (extensions == NULL) {
|
||||
#ifdef _DEBUG
|
||||
printf("NULL extension string\n");
|
||||
#endif
|
||||
printfDebug("NULL extension string\n");
|
||||
extgl_error = true;
|
||||
return false;
|
||||
}
|
||||
|
|
@ -3308,16 +3291,12 @@ bool extgl_Open()
|
|||
{
|
||||
lib_gl_handle = dlopen("libGL.so.1", RTLD_LAZY | RTLD_GLOBAL);
|
||||
if (lib_gl_handle == NULL) {
|
||||
#ifdef _DEBUG
|
||||
printf("Error loading libGL.so.1: %s\n", dlerror());
|
||||
#endif
|
||||
printfDebug("Error loading libGL.so.1: %s\n", dlerror());
|
||||
return false;
|
||||
}
|
||||
lib_glu_handle = dlopen("libGLU.so.1", RTLD_LAZY | RTLD_GLOBAL);
|
||||
if (lib_glu_handle == NULL) {
|
||||
#ifdef _DEBUG
|
||||
printf("Error loading libGLU.so.1: %s\n", dlerror());
|
||||
#endif
|
||||
printfDebug("Error loading libGLU.so.1: %s\n", dlerror());
|
||||
dlclose(lib_gl_handle);
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,10 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
/* Inaccessible static: _00024assertionsDisabled */
|
||||
#undef org_lwjgl_Sys_DEBUG_DISABLED
|
||||
#define org_lwjgl_Sys_DEBUG_DISABLED 1L
|
||||
#undef org_lwjgl_Sys_DEBUG_ENABLED
|
||||
#define org_lwjgl_Sys_DEBUG_ENABLED 2L
|
||||
#undef org_lwjgl_Sys_LOW_PRIORITY
|
||||
#define org_lwjgl_Sys_LOW_PRIORITY -1L
|
||||
#undef org_lwjgl_Sys_NORMAL_PRIORITY
|
||||
|
|
@ -18,8 +22,15 @@ extern "C" {
|
|||
#define org_lwjgl_Sys_REALTIME_PRIORITY 2L
|
||||
/* Inaccessible static: LIBRARY_NAME */
|
||||
/* Inaccessible static: DEBUG */
|
||||
/* Inaccessible static: _debug */
|
||||
/* Inaccessible static: class_00024org_00024lwjgl_00024Sys */
|
||||
/*
|
||||
* Class: org_lwjgl_Sys
|
||||
* Method: setDebugLevel
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_Sys_setDebugLevel
|
||||
(JNIEnv *, jclass, jint);
|
||||
|
||||
/*
|
||||
* Class: org_lwjgl_Sys
|
||||
* Method: getTimerResolution
|
||||
|
|
|
|||
|
|
@ -16,32 +16,22 @@ AC_PROG_LN_S
|
|||
AC_PROG_MAKE_SET
|
||||
|
||||
AC_PROG_CXX
|
||||
AC_ARG_ENABLE(debug,
|
||||
AC_HELP_STRING([--disable-debug], [Disable debug build]),
|
||||
[build_debug=$enableval], [build_debug=no])
|
||||
|
||||
if test $build_debug = yes; then
|
||||
DEBUG_FLAGS=-D_DEBUG
|
||||
else
|
||||
DEBUG_FLAGS=
|
||||
fi
|
||||
|
||||
AC_CANONICAL_HOST
|
||||
|
||||
case "$host_os" in
|
||||
darwin*) _BUILD_FLAGS="-D_AGL -fpascal-strings"
|
||||
LDFLAGS="-Xlinker -framework -Xlinker JavaVM -Xlinker -framework -Xlinker ApplicationServices -Xlinker -framework -Xlinker CoreServices -Xlinker -framework -Xlinker Carbon"
|
||||
NATIVE_BUILD_DIR=macosx
|
||||
CXXFLAGS="$CXXFLAGS $DEBUG_FLAGS -Wall $_BUILD_FLAGS"
|
||||
CFLAGS="$CFLAGS $DEBUG_FLAGS -Wall $_BUILD_FLAGS"
|
||||
CXXFLAGS="$CXXFLAGS -Wall $_BUILD_FLAGS"
|
||||
CFLAGS="$CFLAGS -Wall $_BUILD_FLAGS"
|
||||
;;
|
||||
bsdi* | linux* | solaris*) AC_PATH_XTRA
|
||||
AC_LIBTOOL_DLOPEN
|
||||
_BUILD_FLAGS="-pthread -D_X11 $X_CFLAGS"
|
||||
AC_CHECK_HEADERS([AL/altypes.h AL/alctypes.h],, AC_MSG_ERROR([OpenAL headers required]))
|
||||
NATIVE_BUILD_DIR=linux
|
||||
CXXFLAGS="$CXXFLAGS $DEBUG_FLAGS -Wall $_BUILD_FLAGS"
|
||||
CFLAGS="$CFLAGS $DEBUG_FLAGS -Wall $_BUILD_FLAGS"
|
||||
CXXFLAGS="$CXXFLAGS -Wall $_BUILD_FLAGS"
|
||||
CFLAGS="$CFLAGS -Wall $_BUILD_FLAGS"
|
||||
LIBS="$LIBS $X_LIBS"
|
||||
AC_CHECK_LIB(X11, XOpenDisplay,, AC_MSG_ERROR(X11 is required))
|
||||
AC_CHECK_LIB(Xext, main,, AC_MSG_ERROR(Xext is required))
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include <stdio.h>
|
||||
#include <dlfcn.h>
|
||||
#include "extxcursor.h"
|
||||
#include "common_tools.h"
|
||||
|
||||
static void * xcursor_handle = NULL;
|
||||
static const char *xcursor_lib_name = "libXcursor.so.1";
|
||||
|
|
@ -39,9 +40,7 @@ bool loadXcursor(void) {
|
|||
load_success = false;
|
||||
xcursor_handle = dlopen(xcursor_lib_name, RTLD_GLOBAL | RTLD_LAZY);
|
||||
if (xcursor_handle == NULL) {
|
||||
#ifdef _DEBUG
|
||||
printf("Could not load %s: %s\n", xcursor_lib_name, dlerror());
|
||||
#endif
|
||||
printfDebug("Could not load %s: %s\n", xcursor_lib_name, dlerror());
|
||||
return load_success;
|
||||
}
|
||||
loadFunctionPointers();
|
||||
|
|
|
|||
|
|
@ -61,20 +61,14 @@ static bool getVidModeExtensionVersion(Display *disp, int screen, int *major, in
|
|||
int event_base, error_base;
|
||||
|
||||
if (!XF86VidModeQueryExtension(disp, &event_base, &error_base)) {
|
||||
#ifdef _DEBUG
|
||||
printf("XF86VidMode extension not available\n");
|
||||
#endif
|
||||
printfDebug("XF86VidMode extension not available\n");
|
||||
return false;
|
||||
}
|
||||
if (!XF86VidModeQueryVersion(disp, major, minor)) {
|
||||
#ifdef _DEBUG
|
||||
printf("Could not determine XF86VidMode version\n");
|
||||
#endif
|
||||
printfDebug("Could not determine XF86VidMode version\n");
|
||||
return false;
|
||||
}
|
||||
#ifdef _DEBUG
|
||||
printf("XF86VidMode extension version %i.%i\n", *major, *minor);
|
||||
#endif
|
||||
printfDebug("XF86VidMode extension version %i.%i\n", *major, *minor);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -90,24 +84,17 @@ static bool setMode(Display *disp, int screen, int width, int height, bool lock_
|
|||
int num_modes, i;
|
||||
XF86VidModeModeInfo **avail_modes;
|
||||
if (!getDisplayModes(disp, screen, &num_modes, &avail_modes)) {
|
||||
#ifdef _DEBUG
|
||||
printf("Could not get display modes\n");
|
||||
#endif
|
||||
printfDebug("Could not get display modes\n");
|
||||
return false;
|
||||
}
|
||||
XF86VidModeLockModeSwitch(disp, screen, 0);
|
||||
for ( i = 0; i < num_modes; ++i ) {
|
||||
#ifdef _DEBUG
|
||||
printf("Mode %d: %dx%d\n", i, avail_modes[i]->hdisplay, avail_modes[i]->vdisplay);
|
||||
#endif
|
||||
printfDebug("Mode %d: %dx%d\n", i, avail_modes[i]->hdisplay, avail_modes[i]->vdisplay);
|
||||
if (avail_modes[i]->hdisplay == width && avail_modes[i]->vdisplay == height) {
|
||||
if (!XF86VidModeSwitchToMode(disp, screen, avail_modes[i])) {
|
||||
#ifdef _DEBUG
|
||||
printf("Could not switch mode\n");
|
||||
#endif
|
||||
printfDebug("Could not switch mode\n");
|
||||
break;
|
||||
}
|
||||
// XF86VidModeSetViewPort(disp, screen, 0, 0);
|
||||
if (lock_mode)
|
||||
XF86VidModeLockModeSwitch(disp, screen, 1);
|
||||
XFree(avail_modes);
|
||||
|
|
@ -131,15 +118,11 @@ static void freeSavedGammaRamps() {
|
|||
static int getGammaRampLength(Display *disp, int screen) {
|
||||
int minor_ver, major_ver, ramp_size;
|
||||
if (!getVidModeExtensionVersion(disp, screen, &major_ver, &minor_ver) || major_ver < 2) {
|
||||
#ifdef _DEBUG
|
||||
printf("XF86VidMode extension version >= 2 not found\n");
|
||||
#endif
|
||||
printfDebug("XF86VidMode extension version >= 2 not found\n");
|
||||
return 0;
|
||||
}
|
||||
if (XF86VidModeGetGammaRampSize(disp, screen, &ramp_size) == False) {
|
||||
#ifdef _DEBUG
|
||||
printf("XF86VidModeGetGammaRampSize call failed\n");
|
||||
#endif
|
||||
printfDebug("XF86VidModeGetGammaRampSize call failed\n");
|
||||
return 0;
|
||||
}
|
||||
return ramp_size;
|
||||
|
|
@ -153,24 +136,18 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Display_init
|
|||
int screen;
|
||||
Display *disp = XOpenDisplay(NULL);
|
||||
if (disp == NULL) {
|
||||
#ifdef _DEBUG
|
||||
printf("Could not open X connection\n");
|
||||
#endif
|
||||
printfDebug("Could not open X connection\n");
|
||||
return;
|
||||
}
|
||||
screen = DefaultScreen(disp);
|
||||
|
||||
if (!getDisplayModes(disp, screen, &num_modes, &avail_modes)) {
|
||||
#ifdef _DEBUG
|
||||
printf("Could not get display modes\n");
|
||||
#endif
|
||||
printfDebug("Could not get display modes\n");
|
||||
}
|
||||
saved_width = avail_modes[0]->hdisplay;
|
||||
saved_height = avail_modes[0]->vdisplay;
|
||||
int bpp = XDefaultDepth(disp, screen);
|
||||
#ifdef _DEBUG
|
||||
printf("Saved width, height %d, %d\n", saved_width, saved_height);
|
||||
#endif
|
||||
printfDebug("Saved width, height %d, %d\n", saved_width, saved_height);
|
||||
jclass jclass_DisplayMode = env->FindClass("org/lwjgl/DisplayMode");
|
||||
jmethodID ctor = env->GetMethodID(jclass_DisplayMode, "<init>", "(IIII)V");
|
||||
jobject newMode = env->NewObject(jclass_DisplayMode, ctor, saved_width, saved_height, bpp, 0);
|
||||
|
|
@ -218,9 +195,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Display_resetDisplayMode(JNIEnv * env, jcl
|
|||
Display *disp = XOpenDisplay(NULL);
|
||||
|
||||
if (disp == NULL) {
|
||||
#ifdef _DEBUG
|
||||
printf("Could not open X connection\n");
|
||||
#endif
|
||||
printfDebug("Could not open X connection\n");
|
||||
return;
|
||||
}
|
||||
screen = DefaultScreen(disp);
|
||||
|
|
@ -232,11 +207,6 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Display_resetDisplayMode(JNIEnv * env, jcl
|
|||
XCloseDisplay(disp);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_lwjgl_Display
|
||||
* Method: nGetAvailableDisplayModes
|
||||
* Signature: ()[Lorg/lwjgl/DisplayMode;
|
||||
*/
|
||||
JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_Display_nGetAvailableDisplayModes
|
||||
(JNIEnv * env, jclass clazz)
|
||||
{
|
||||
|
|
@ -246,9 +216,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_Display_nGetAvailableDisplayModes
|
|||
XF86VidModeModeInfo **avail_modes;
|
||||
|
||||
if (disp == NULL) {
|
||||
#ifdef _DEBUG
|
||||
printf("Could not open X connection\n");
|
||||
#endif
|
||||
printfDebug("Could not open X connection\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -256,9 +224,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_Display_nGetAvailableDisplayModes
|
|||
int bpp = XDefaultDepth(disp, screen);
|
||||
|
||||
if (!getDisplayModes(disp, screen, &num_modes, &avail_modes)) {
|
||||
#ifdef _DEBUG
|
||||
printf("Could not get display modes\n");
|
||||
#endif
|
||||
printfDebug("Could not get display modes\n");
|
||||
XCloseDisplay(disp);
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@
|
|||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
#include "org_lwjgl_Sys.h"
|
||||
#include "common_tools.h"
|
||||
|
||||
static long int hires_timer_freq; // Hires timer frequency
|
||||
static long int hires_timer_start; // Hires timer start
|
||||
|
|
@ -62,15 +63,17 @@ JNIEXPORT jlong JNICALL Java_org_lwjgl_Sys_getTimerResolution
|
|||
static long queryTime(void) {
|
||||
struct timeval tv;
|
||||
if (gettimeofday(&tv, NULL) == -1) {
|
||||
#ifdef _DEBUG
|
||||
printf("Could not read current time\n");
|
||||
#endif
|
||||
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_setDebugLevel(JNIEnv *env, jclass clazz, jint debug_level) {
|
||||
setDebugLevel(debug_level);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_lwjgl_Sys
|
||||
* Method: getTime
|
||||
|
|
@ -114,9 +117,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Sys_setProcessPriority
|
|||
// Reset scheduler to normal
|
||||
sched_pri.sched_priority = 0;
|
||||
if (sched_setscheduler(0, SCHED_OTHER, &sched_pri) != 0) {
|
||||
#ifdef _DEBUG
|
||||
printf("Could not set realtime priority\n");
|
||||
#endif
|
||||
printfDebug("Could not set realtime priority\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -126,16 +127,12 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Sys_setProcessPriority
|
|||
min_pri = sched_get_priority_min(SCHED_FIFO);
|
||||
max_pri = sched_get_priority_max(SCHED_FIFO);
|
||||
if (min_pri == -1 || max_pri == -1) {
|
||||
#ifdef _DEBUG
|
||||
printf("Failed to set realtime priority\n");
|
||||
#endif
|
||||
printfDebug("Failed to set realtime priority\n");
|
||||
return;
|
||||
}
|
||||
sched_pri.sched_priority = (max_pri + min_pri)/2;
|
||||
if (sched_setscheduler(0, SCHED_FIFO, &sched_pri) != 0) {
|
||||
#ifdef _DEBUG
|
||||
printf("Could not set realtime priority\n");
|
||||
#endif
|
||||
printfDebug("Could not set realtime priority\n");
|
||||
return;
|
||||
}
|
||||
return;
|
||||
|
|
@ -153,9 +150,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Sys_setProcessPriority
|
|||
}
|
||||
|
||||
if (setpriority(PRIO_PROCESS, 0, linux_priority) == -1) {
|
||||
#ifdef _DEBUG
|
||||
printf("Failed to set priority.\n");
|
||||
#endif
|
||||
printfDebug("Failed to set priority.\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -122,9 +122,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_initIDs
|
|||
static bool blankCursor(void) {
|
||||
unsigned int best_width, best_height;
|
||||
if (XQueryBestCursor(getCurrentDisplay(), getCurrentWindow(), 1, 1, &best_width, &best_height) == 0) {
|
||||
#ifdef _DEBUG
|
||||
printf("Could not query best cursor size\n");
|
||||
#endif
|
||||
printfDebug("Could not query best cursor size\n");
|
||||
return false;
|
||||
}
|
||||
Pixmap mask = XCreatePixmap(getCurrentDisplay(), getCurrentWindow(), best_width, best_height, 1);
|
||||
|
|
@ -201,14 +199,10 @@ static void doWarpPointer(void ) {
|
|||
event.xmotion.y > current_y - POINTER_WARP_BORDER &&
|
||||
event.xmotion.y < current_y + POINTER_WARP_BORDER)
|
||||
break;
|
||||
#ifdef _DEBUG
|
||||
printf("Skipped event searching for warp event %d, %d\n", event.xmotion.x, event.xmotion.y);
|
||||
#endif
|
||||
printfDebug("Skipped event searching for warp event %d, %d\n", event.xmotion.x, event.xmotion.y);
|
||||
}
|
||||
#ifdef _DEBUG
|
||||
if (i == WARP_RETRY)
|
||||
printf("Never got warp event\n");
|
||||
#endif
|
||||
printfDebug("Never got warp event\n");
|
||||
}
|
||||
|
||||
static void warpPointer(void) {
|
||||
|
|
|
|||
|
|
@ -161,9 +161,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Pbuffer_nMakeCurrent
|
|||
GLXPbuffer buffer = buffer_info->buffer;
|
||||
GLXContext context = buffer_info->context;
|
||||
if (glXMakeContextCurrent(getCurrentDisplay(), buffer, buffer, context) == False) {
|
||||
#ifdef _DEBUG
|
||||
printf("Could not make pbuffer current");
|
||||
#endif
|
||||
printfDebug("Could not make pbuffer current");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -208,9 +208,7 @@ static void createWindow(JNIEnv* env, Display *disp, int screen, XVisualInfo *vi
|
|||
}
|
||||
win = XCreateWindow(disp, root_win, x, y, width, height, 0, vis_info->depth, InputOutput, vis_info->visual, attribmask, &attribs);
|
||||
XFreeColormap(disp, cmap);
|
||||
#ifdef _DEBUG
|
||||
printf("Created window\n");
|
||||
#endif
|
||||
printfDebug("Created window\n");
|
||||
current_win = win;
|
||||
Java_org_lwjgl_opengl_Window_nSetTitle(env, NULL, title);
|
||||
XSizeHints * size_hints = XAllocSizeHints();
|
||||
|
|
@ -383,9 +381,8 @@ static bool initWindowGLX13(JNIEnv *env, Display *disp, int screen, jstring titl
|
|||
throwException(env, "Could not create visual info from FB config");
|
||||
return false;
|
||||
}
|
||||
#ifdef _DEBUG
|
||||
dumpVisualInfo(disp, vis_info);
|
||||
#endif
|
||||
if (ATDEBUGLEVEL())
|
||||
dumpVisualInfo(disp, vis_info);
|
||||
createWindow(env, disp, screen, vis_info, title, x, y, width, height, fscreen);
|
||||
glx_window = glXCreateWindow(disp, configs[0], getCurrentWindow(), NULL);
|
||||
makeCurrent();
|
||||
|
|
@ -400,9 +397,8 @@ static bool initWindowGLX(JNIEnv *env, Display *disp, int screen, jstring title,
|
|||
throwException(env, "Could not find a matching pixel format");
|
||||
return false;
|
||||
}
|
||||
#ifdef _DEBUG
|
||||
dumpVisualInfo(disp, vis_info);
|
||||
#endif
|
||||
if (ATDEBUGLEVEL())
|
||||
dumpVisualInfo(disp, vis_info);
|
||||
context = glXCreateContext(disp, vis_info, NULL, True);
|
||||
if (context == NULL) {
|
||||
XFree(vis_info);
|
||||
|
|
@ -467,10 +463,10 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nCreate
|
|||
throwException(env, "Could not init gl function pointers");
|
||||
return;
|
||||
}
|
||||
#ifdef _DEBUG
|
||||
const GLubyte * extensions = glGetString(GL_EXTENSIONS);
|
||||
printf("Supported extensions: %s\n", extensions);
|
||||
#endif
|
||||
if (ATDEBUGLEVEL()) {
|
||||
const GLubyte * extensions = glGetString(GL_EXTENSIONS);
|
||||
printf("Supported extensions: %s\n", extensions);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -123,9 +123,7 @@ static void searchDictionaryElement(CFDictionaryRef dict, CFStringRef key, hid_d
|
|||
static void addToDeviceQueue(hid_device_t *hid_dev, IOHIDElementCookie cookie, int index) {
|
||||
HRESULT result = (*hid_dev->device_queue)->addElement(hid_dev->device_queue, cookie, 0);
|
||||
if (result != S_OK) {
|
||||
#ifdef _DEBUG
|
||||
printf("Could not add cookie to queue\n");
|
||||
#endif
|
||||
printfDebug("Could not add cookie to queue\n");
|
||||
return;
|
||||
}
|
||||
CFDictionaryAddValue(hid_dev->cookie_map, cookie, (void *)index);
|
||||
|
|
@ -193,9 +191,7 @@ bool findDevice(hid_device_t *hid_dev, long device_usage_page, long device_usage
|
|||
CFDictionaryRef matching_dic = IOServiceMatching(kIOHIDDeviceKey);
|
||||
IOReturn err = IOServiceGetMatchingServices(kIOMasterPortDefault, matching_dic, &device_iterator);
|
||||
if (err != kIOReturnSuccess) {
|
||||
#ifdef _DEBUG
|
||||
printf("Could not find matching devices\n");
|
||||
#endif
|
||||
printfDebug("Could not find matching devices\n");
|
||||
return false;
|
||||
}
|
||||
while (!success && (hid_device = IOIteratorNext(device_iterator)) != NULL) {
|
||||
|
|
@ -205,11 +201,11 @@ bool findDevice(hid_device_t *hid_dev, long device_usage_page, long device_usage
|
|||
long usage_page;
|
||||
if (getDictLong(dev_props, CFSTR(kIOHIDPrimaryUsageKey), &usage) &&
|
||||
getDictLong(dev_props, CFSTR(kIOHIDPrimaryUsagePageKey), &usage_page)) {
|
||||
#ifdef _DEBUG
|
||||
printf("Considering device '");
|
||||
printProperty(dev_props, CFSTR(kIOHIDProductKey));
|
||||
printf("', usage page %ld usage %ld\n", usage_page, usage);
|
||||
#endif
|
||||
if (ATDEBUGLEVEL()) {
|
||||
printf("Considering device '");
|
||||
printProperty(dev_props, CFSTR(kIOHIDProductKey));
|
||||
printf("', usage page %ld usage %ld\n", usage_page, usage);
|
||||
}
|
||||
if (usage_page == device_usage_page && usage == device_usage) {
|
||||
success = initDevice(hid_dev, hid_device, dev_props, num_cookies, hid_cookies, buffer_size);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@
|
|||
#include <sys/resource.h>
|
||||
#include <Carbon/Carbon.h>
|
||||
#include "org_lwjgl_Sys.h"
|
||||
#include "common_tools.h"
|
||||
|
||||
long int hires_timer_freq; // Hires timer frequency
|
||||
long int hires_timer_start; // Hires timer start
|
||||
|
|
@ -63,15 +64,17 @@ JNIEXPORT jlong JNICALL Java_org_lwjgl_Sys_getTimerResolution
|
|||
static long queryTime(void) {
|
||||
struct timeval tv;
|
||||
if (gettimeofday(&tv, NULL) == -1) {
|
||||
#ifdef _DEBUG
|
||||
printf("Could not read current time\n");
|
||||
#endif
|
||||
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_setDebugLevel(JNIEnv *env, jclass clazz, jint debug_level) {
|
||||
setDebugLevel(debug_level);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_lwjgl_Sys
|
||||
* Method: getTime
|
||||
|
|
@ -107,9 +110,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Sys_setTime
|
|||
JNIEXPORT void JNICALL Java_org_lwjgl_Sys_setProcessPriority
|
||||
(JNIEnv * env, jclass clazz, jint priority)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
printf("Unsupported\n");
|
||||
#endif
|
||||
printfDebug("WARNING: setProcessPriority unsupported\n");
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -70,16 +70,12 @@ static bool handleMappedKey(unsigned char mapped_code, unsigned char state) {
|
|||
|
||||
static bool handleKey(UInt32 key_code, unsigned char state) {
|
||||
if (key_code >= KEYBOARD_SIZE) {
|
||||
#ifdef _DEBUG
|
||||
printf("Key code >= %d %x\n", KEYBOARD_SIZE, (unsigned int)key_code);
|
||||
#endif
|
||||
printfDebug("Key code >= %d %x\n", KEYBOARD_SIZE, (unsigned int)key_code);
|
||||
return false;
|
||||
}
|
||||
unsigned char mapped_code = key_map[key_code];
|
||||
if (mapped_code == 0) {
|
||||
#ifdef _DEBUG
|
||||
printf("unknown key code: %x\n", (unsigned int)key_code);
|
||||
#endif
|
||||
printfDebug("unknown key code: %x\n", (unsigned int)key_code);
|
||||
return false;
|
||||
}
|
||||
return handleMappedKey(mapped_code, state);
|
||||
|
|
@ -133,9 +129,7 @@ static bool handleTranslation(EventRef event, bool state) {
|
|||
KeyboardLayoutRef layout;
|
||||
OSStatus err = KLGetCurrentKeyboardLayout(&layout);
|
||||
if (err != noErr) {
|
||||
#ifdef _DEBUG
|
||||
printf("Could not get current keyboard layout\n");
|
||||
#endif
|
||||
printfDebug("Could not get current keyboard layout\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -149,9 +143,7 @@ static bool handleTranslation(EventRef event, bool state) {
|
|||
success = success && GetEventParameter(event, kEventParamKeyboardType, typeUInt32, NULL, sizeof(keyboardType), NULL, &keyboardType) == noErr;
|
||||
success = success && GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(modifierKeyState), NULL, &modifierKeyState) == noErr;
|
||||
if (!success) {
|
||||
#ifdef _DEBUG
|
||||
printf("Could not get event parameters for character translation\n");
|
||||
#endif
|
||||
printfDebug("Could not get event parameters for character translation\n");
|
||||
return false;
|
||||
}
|
||||
err = KLGetKeyboardLayoutProperty(layout, kKLuchrData, (const void **)&uchrHandle);
|
||||
|
|
@ -183,9 +175,7 @@ static bool handleTranslation(EventRef event, bool state) {
|
|||
if (state)
|
||||
return writeAsciiChars(count, ascii_buffer);
|
||||
} else {
|
||||
#ifdef _DEBUG
|
||||
printf("Could not translate key\n");
|
||||
#endif
|
||||
printfDebug("Could not translate key\n");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -196,9 +186,7 @@ static void doKeyDown(EventRef event) {
|
|||
UInt32 key_code;
|
||||
OSStatus err = GetEventParameter(event, kEventParamKeyCode, typeUInt32, NULL, sizeof(key_code), NULL, &key_code);
|
||||
if (err != noErr) {
|
||||
#ifdef _DEBUG
|
||||
printf("Could not get event key code\n");
|
||||
#endif
|
||||
printfDebug("Could not get event key code\n");
|
||||
return;
|
||||
}
|
||||
if (handleKey(key_code, 1) && !handleTranslation(event, true)) {
|
||||
|
|
@ -211,9 +199,7 @@ static void doKeyUp(EventRef event) {
|
|||
UInt32 key_code;
|
||||
OSStatus err = GetEventParameter(event, kEventParamKeyCode, typeUInt32, NULL, sizeof(key_code), NULL, &key_code);
|
||||
if (err != noErr) {
|
||||
#ifdef _DEBUG
|
||||
printf("Could not get event key code\n");
|
||||
#endif
|
||||
printfDebug("Could not get event key code\n");
|
||||
return;
|
||||
}
|
||||
if (handleKey(key_code, 0) && !handleTranslation(event, false)) {
|
||||
|
|
@ -236,9 +222,7 @@ static void doKeyModifier(EventRef event) {
|
|||
UInt32 modifier_bits;
|
||||
OSStatus err = GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(modifier_bits), NULL, &modifier_bits);
|
||||
if (err != noErr) {
|
||||
#ifdef _DEBUG
|
||||
printf("Could not get event key code\n");
|
||||
#endif
|
||||
printfDebug("Could not get event key code\n");
|
||||
return;
|
||||
}
|
||||
handleModifier(modifier_bits, controlKey, 0x1d);
|
||||
|
|
|
|||
|
|
@ -70,9 +70,7 @@ static bool created;
|
|||
|
||||
static void handleButton(unsigned char button_index, jbyte state) {
|
||||
if (button_index >= NUM_BUTTONS) {
|
||||
#ifdef _DEBUG
|
||||
printf("Button index %d out of range [0..%d]\n", button_index, NUM_BUTTONS);
|
||||
#endif
|
||||
printfDebug("Button index %d out of range [0..%d]\n", button_index, NUM_BUTTONS);
|
||||
return;
|
||||
}
|
||||
button_states[button_index] = state;
|
||||
|
|
@ -108,9 +106,7 @@ cont:
|
|||
}
|
||||
}
|
||||
}
|
||||
#ifdef _DEBUG
|
||||
printf("Recieved an unknown HID device event\n");
|
||||
#endif
|
||||
printfDebug("Recieved an unknown HID device event\n");
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
|
@ -124,9 +120,7 @@ static void handleButtonEvent(EventRef event, unsigned char state) {
|
|||
EventMouseButton button;
|
||||
OSStatus err = GetEventParameter(event, kEventParamMouseButton, typeMouseButton, NULL, sizeof(button), NULL, &button);
|
||||
if (err != noErr) {
|
||||
#ifdef _DEBUG
|
||||
printf("Could not get button parameter from event\n");
|
||||
#endif
|
||||
printfDebug("Could not get button parameter from event\n");
|
||||
return;
|
||||
}
|
||||
handleButton(button - 1, state);
|
||||
|
|
@ -136,9 +130,7 @@ static void handleMovedEvent(EventRef event) {
|
|||
HIPoint delta;
|
||||
OSStatus err = GetEventParameter(event, kEventParamMouseDelta, typeHIPoint, NULL, sizeof(delta), NULL, &delta);
|
||||
if (err != noErr) {
|
||||
#ifdef _DEBUG
|
||||
printf("Could not delta parameter from event\n");
|
||||
#endif
|
||||
printfDebug("Could not delta parameter from event\n");
|
||||
return;
|
||||
}
|
||||
last_dx += (int)delta.x;
|
||||
|
|
@ -149,9 +141,7 @@ static void handleWheelEvent(EventRef event) {
|
|||
long delta;
|
||||
OSStatus err = GetEventParameter(event, kEventParamMouseWheelDelta, typeLongInteger, NULL, sizeof(delta), NULL, &delta);
|
||||
if (err != noErr) {
|
||||
#ifdef _DEBUG
|
||||
printf("Could not delta parameter from event\n");
|
||||
#endif
|
||||
printfDebug("Could not delta parameter from event\n");
|
||||
return;
|
||||
}
|
||||
last_dz += (int)delta;
|
||||
|
|
|
|||
|
|
@ -45,8 +45,8 @@
|
|||
|
||||
#define WINDOWCLASSNAME "LWJGLWINDOW"
|
||||
|
||||
jobjectArray GetAvailableDisplayModesEx(JNIEnv * env);
|
||||
jobjectArray GetAvailableDisplayModes(JNIEnv * env);
|
||||
static jobjectArray GetAvailableDisplayModesEx(JNIEnv * env);
|
||||
static jobjectArray GetAvailableDisplayModes(JNIEnv * env);
|
||||
bool modeSet = false; // Whether we've done a display mode change
|
||||
WORD* originalGamma = new WORD[256 * 3]; // Original gamma settings
|
||||
WORD* currentGamma = new WORD[256 * 3]; // Current gamma settings
|
||||
|
|
@ -62,9 +62,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_Display_nGetAvailableDisplayModes
|
|||
{
|
||||
jobjectArray result = GetAvailableDisplayModesEx(env);
|
||||
if (result == NULL) {
|
||||
#ifdef _DEBUG
|
||||
printf("Extended display mode selection failed, using fallback\n");
|
||||
#endif
|
||||
printfDebug("Extended display mode selection failed, using fallback\n");
|
||||
result = GetAvailableDisplayModes(env);
|
||||
}
|
||||
return result;
|
||||
|
|
@ -73,7 +71,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_Display_nGetAvailableDisplayModes
|
|||
/**
|
||||
* Choose displaymodes using extended codepath (multiple displaydevices)
|
||||
*/
|
||||
jobjectArray GetAvailableDisplayModesEx(JNIEnv * env) {
|
||||
static jobjectArray GetAvailableDisplayModesEx(JNIEnv * env) {
|
||||
typedef BOOL (WINAPI * EnumDisplayDevicesAPROC)(IN LPCSTR lpDevice, IN DWORD iDevNum, OUT PDISPLAY_DEVICEA lpDisplayDevice, IN DWORD dwFlags);
|
||||
typedef BOOL (WINAPI * EnumDisplaySettingsExAPROC)(IN LPCSTR lpszDeviceName, IN DWORD iModeNum, OUT LPDEVMODEA lpDevMode, IN DWORD dwFlags);
|
||||
EnumDisplayDevicesAPROC EnumDisplayDevicesA;
|
||||
|
|
@ -81,9 +79,7 @@ jobjectArray GetAvailableDisplayModesEx(JNIEnv * env) {
|
|||
|
||||
HMODULE lib_handle = LoadLibrary("user32.dll");
|
||||
if (lib_handle == NULL) {
|
||||
#ifdef _DEBUG
|
||||
printf("Could not load user32.dll\n");
|
||||
#endif
|
||||
printfDebug("Could not load user32.dll\n");
|
||||
return NULL;
|
||||
}
|
||||
EnumDisplayDevicesA = (EnumDisplayDevicesAPROC)GetProcAddress(lib_handle, "EnumDisplayDevicesA");
|
||||
|
|
@ -105,25 +101,18 @@ jobjectArray GetAvailableDisplayModesEx(JNIEnv * env) {
|
|||
DevMode.dmSize = sizeof(DEVMODE);
|
||||
DisplayDevice.cb = sizeof(DISPLAY_DEVICE);
|
||||
|
||||
//enumerate all displays, and all of their displaymodes
|
||||
//enumerate all displays, and all of their displaymodes
|
||||
while(EnumDisplayDevicesA(NULL, i++, &DisplayDevice, 0) != 0) {
|
||||
#ifdef _DEBUG
|
||||
printf("Querying %s device\n", DisplayDevice.DeviceString);
|
||||
#endif
|
||||
printfDebug("Querying %s device\n", DisplayDevice.DeviceString);
|
||||
j = 0;
|
||||
while(EnumDisplaySettingsExA((const char *) DisplayDevice.DeviceName, j++, &DevMode, 0) != 0) {
|
||||
//#ifdef _DEBUG
|
||||
// printf("Checking setting #%d\n", j);
|
||||
//#endif
|
||||
if (DevMode.dmBitsPerPel > 8) {
|
||||
AvailableModes++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
printf("Found %d displaymodes\n", AvailableModes);
|
||||
#endif
|
||||
printfDebug("Found %d displaymodes\n", AvailableModes);
|
||||
|
||||
// now that we have the count create the classes, and add 'em all - we'll remove dups in Java
|
||||
// Allocate an array of DisplayModes big enough
|
||||
|
|
@ -154,7 +143,7 @@ jobjectArray GetAvailableDisplayModesEx(JNIEnv * env) {
|
|||
/**
|
||||
* Choose displaymodes using standard codepath (single displaydevice)
|
||||
*/
|
||||
jobjectArray GetAvailableDisplayModes(JNIEnv * env) {
|
||||
static jobjectArray GetAvailableDisplayModes(JNIEnv * env) {
|
||||
int i = 0, j = 0, n = 0;
|
||||
int AvailableModes = 0;
|
||||
|
||||
|
|
@ -171,9 +160,7 @@ jobjectArray GetAvailableDisplayModes(JNIEnv * env) {
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
printf("Found %d displaymodes\n", AvailableModes);
|
||||
#endif
|
||||
printfDebug("Found %d displaymodes\n", AvailableModes);
|
||||
|
||||
// now that we have the count create the classes, and add 'em all - we'll remove dups in Java
|
||||
// Allocate an array of DisplayModes big enough
|
||||
|
|
@ -243,16 +230,12 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Display_setDisplayMode
|
|||
|
||||
if (cdsret != DISP_CHANGE_SUCCESSFUL) {
|
||||
// Failed: so let's check to see if it's a wierd dual screen display
|
||||
#ifdef _DEBUG
|
||||
printf("Failed to set display mode... assuming dual monitors\n");
|
||||
#endif
|
||||
printfDebug("Failed to set display mode... assuming dual monitors\n");
|
||||
devmode.dmPelsWidth = width * 2;
|
||||
cdsret = ChangeDisplaySettings(&devmode, CDS_FULLSCREEN);
|
||||
|
||||
if (cdsret != DISP_CHANGE_SUCCESSFUL) {
|
||||
#ifdef _DEBUG
|
||||
printf("Failed to set display mode using dual monitors\n");
|
||||
#endif
|
||||
printfDebug("Failed to set display mode using dual monitors\n");
|
||||
throwException(env, "Failed to set display mode.");
|
||||
return;
|
||||
}
|
||||
|
|
@ -295,9 +278,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Display_resetDisplayMode
|
|||
HDC screenDC = GetDC(NULL);
|
||||
try {
|
||||
if (!SetDeviceGammaRamp(screenDC, originalGamma)) {
|
||||
#ifdef _DEBUG
|
||||
printf("Could not reset device gamma\n");
|
||||
#endif
|
||||
printfDebug("Could not reset device gamma\n");
|
||||
}
|
||||
} catch (...) {
|
||||
printf("Exception occurred in SetDeviceGammaRamp\n");
|
||||
|
|
@ -317,14 +298,12 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Display_resetDisplayMode
|
|||
/*
|
||||
* Temporarily reset display settings. This is called when the window is minimized.
|
||||
*/
|
||||
void tempResetDisplayMode() {
|
||||
static void tempResetDisplayMode() {
|
||||
// Return device gamma to normal
|
||||
HDC screenDC = GetDC(NULL);
|
||||
try {
|
||||
if (!SetDeviceGammaRamp(screenDC, originalGamma)) {
|
||||
#ifdef _DEBUG
|
||||
printf("Could not reset device gamma\n");
|
||||
#endif
|
||||
printfDebug("Could not reset device gamma\n");
|
||||
}
|
||||
} catch (...) {
|
||||
printf("Exception occurred in SetDeviceGammaRamp\n");
|
||||
|
|
@ -332,9 +311,7 @@ void tempResetDisplayMode() {
|
|||
ReleaseDC(NULL, screenDC);
|
||||
|
||||
if (modeSet) {
|
||||
#ifdef _DEBUG
|
||||
printf("Attempting to temporarily reset the display mode\n");
|
||||
#endif
|
||||
printfDebug("Attempting to temporarily reset the display mode\n");
|
||||
modeSet = false;
|
||||
// Under Win32, all we have to do is:
|
||||
ChangeDisplaySettings(NULL, 0);
|
||||
|
|
@ -344,14 +321,12 @@ void tempResetDisplayMode() {
|
|||
/*
|
||||
* Put display settings back to what they were when the window is maximized.
|
||||
*/
|
||||
void tempRestoreDisplayMode() {
|
||||
static void tempRestoreDisplayMode() {
|
||||
// Restore gamma
|
||||
HDC screenDC = GetDC(NULL);
|
||||
try {
|
||||
if (!SetDeviceGammaRamp(screenDC, currentGamma)) {
|
||||
#ifdef _DEBUG
|
||||
printf("Could not restore device gamma\n");
|
||||
#endif
|
||||
printfDebug("Could not restore device gamma\n");
|
||||
}
|
||||
} catch (...) {
|
||||
printf("Exception occurred in SetDeviceGammaRamp\n");
|
||||
|
|
@ -359,18 +334,13 @@ void tempRestoreDisplayMode() {
|
|||
ReleaseDC(NULL, screenDC);
|
||||
|
||||
if (!modeSet) {
|
||||
|
||||
#ifdef _DEBUG
|
||||
printf("Attempting to restore the display mode\n");
|
||||
#endif
|
||||
printfDebug("Attempting to restore the display mode\n");
|
||||
modeSet = true;
|
||||
LONG cdsret = ChangeDisplaySettings(&devmode, CDS_FULLSCREEN);
|
||||
|
||||
#ifdef _DEBUG
|
||||
if (cdsret != DISP_CHANGE_SUCCESSFUL) {
|
||||
printf("Failed to restore display mode\n");
|
||||
printfDebug("Failed to restore display mode\n");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -445,9 +415,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Display_init
|
|||
// Get the default gamma ramp
|
||||
try {
|
||||
if (GetDeviceGammaRamp(screenDC, originalGamma) == FALSE) {
|
||||
#ifdef _DEBUG
|
||||
printf("Failed to get initial device gamma\n");
|
||||
#endif
|
||||
printfDebug("Failed to get initial device gamma\n");
|
||||
}
|
||||
} catch (...) {
|
||||
printf("Exception occurred in GetDeviceGammaRamp\n");
|
||||
|
|
@ -457,34 +425,32 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Display_init
|
|||
|
||||
}
|
||||
|
||||
char * getDriver() {
|
||||
#define MY_BUFSIZE 256
|
||||
static char * getDriver() {
|
||||
#define MY_BUFSIZE 256
|
||||
|
||||
HKEY hKey;
|
||||
static TCHAR szAdapterKey[MY_BUFSIZE], szDriverValue[MY_BUFSIZE];
|
||||
DWORD dwBufLen = MY_BUFSIZE;
|
||||
LONG lRet;
|
||||
HKEY hKey;
|
||||
static TCHAR szAdapterKey[MY_BUFSIZE], szDriverValue[MY_BUFSIZE];
|
||||
DWORD dwBufLen = MY_BUFSIZE;
|
||||
LONG lRet;
|
||||
|
||||
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,
|
||||
TEXT("HARDWARE\\DeviceMap\\Video"),
|
||||
0,
|
||||
KEY_QUERY_VALUE,
|
||||
&hKey) != ERROR_SUCCESS) return NULL;
|
||||
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,
|
||||
TEXT("HARDWARE\\DeviceMap\\Video"),
|
||||
0,
|
||||
KEY_QUERY_VALUE,
|
||||
&hKey) != ERROR_SUCCESS) return NULL;
|
||||
|
||||
lRet = RegQueryValueEx(hKey,
|
||||
TEXT("\\Device\\Video0"),
|
||||
NULL,
|
||||
NULL,
|
||||
(LPBYTE)szAdapterKey,
|
||||
&dwBufLen);
|
||||
lRet = RegQueryValueEx(hKey,
|
||||
TEXT("\\Device\\Video0"),
|
||||
NULL,
|
||||
NULL,
|
||||
(LPBYTE)szAdapterKey,
|
||||
&dwBufLen);
|
||||
|
||||
RegCloseKey(hKey);
|
||||
RegCloseKey(hKey);
|
||||
|
||||
if(lRet != ERROR_SUCCESS) return NULL;
|
||||
if(lRet != ERROR_SUCCESS) return NULL;
|
||||
|
||||
#ifdef _DEBUG
|
||||
printf("Adapter key: %s\n", szAdapterKey);
|
||||
#endif
|
||||
printfDebug("Adapter key: %s\n", szAdapterKey);
|
||||
|
||||
// szAdapterKey now contains something like \Registry\Machine\System\CurrentControlSet\Control\Video\{B70DBD2A-90C4-41CF-A58E-F3BA69F1A6BC}\0000
|
||||
// We'll check for the first chunk:
|
||||
|
|
@ -493,9 +459,6 @@ char * getDriver() {
|
|||
|
||||
TCHAR szDriverKey[MY_BUFSIZE];
|
||||
strcpy(szDriverKey, &szAdapterKey[18]);
|
||||
//#ifdef _DEBUG
|
||||
// printf("Driver key: %s\n", szDriverKey);
|
||||
//#endif
|
||||
|
||||
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,
|
||||
TEXT(szDriverKey),
|
||||
|
|
@ -557,27 +520,17 @@ JNIEXPORT jstring JNICALL Java_org_lwjgl_Display_getVersion
|
|||
}
|
||||
strcat(driverDLL, driver);
|
||||
strcat(driverDLL, ".dll");
|
||||
//#ifdef _DEBUG
|
||||
// printf("Driver dll = %s\n", driverDLL);
|
||||
//#endif
|
||||
DWORD var = 0;
|
||||
DWORD dwInfoSize = GetFileVersionInfoSize(driverDLL, &var);
|
||||
LPVOID lpInfoBuff = new unsigned char[dwInfoSize];
|
||||
BOOL bRetval = GetFileVersionInfo(driverDLL, NULL, dwInfoSize, lpInfoBuff);
|
||||
if (bRetval == 0) {
|
||||
//#ifdef _DEBUG
|
||||
// printf("GetFileVersionInfo failed\n");
|
||||
//#endif
|
||||
} else {
|
||||
VS_FIXEDFILEINFO * fxdFileInfo;
|
||||
|
||||
UINT uiLen = 0;
|
||||
bRetval = VerQueryValue(lpInfoBuff, TEXT("\\"), (void **) &fxdFileInfo, &uiLen);
|
||||
if (bRetval == 0) {
|
||||
//#ifdef _DEBUG
|
||||
// printf("VerQueryValue failed\n");
|
||||
//#endif
|
||||
} else {
|
||||
if (bRetval != 0) {
|
||||
TCHAR version[256];
|
||||
TCHAR ms[10], ls[10];
|
||||
sprintf(ms, "%d.%d\0", fxdFileInfo->dwProductVersionMS >> 16, fxdFileInfo->dwProductVersionMS & 0xFFFF);
|
||||
|
|
@ -594,11 +547,3 @@ JNIEXPORT jstring JNICALL Java_org_lwjgl_Display_getVersion
|
|||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@
|
|||
|
||||
#include <windows.h>
|
||||
#include "org_lwjgl_Sys.h"
|
||||
#include "common_tools.h"
|
||||
|
||||
// Handle to the application's window
|
||||
extern HWND hwnd;
|
||||
|
|
@ -60,6 +61,10 @@ JNIEXPORT jlong JNICALL Java_org_lwjgl_Sys_getTimerResolution
|
|||
return hires_timer_freq;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_Sys_setDebugLevel(JNIEnv *env, jclass clazz, jint debug_level) {
|
||||
setDebugLevel(debug_level);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_lwjgl_Sys
|
||||
* Method: getTime
|
||||
|
|
@ -115,9 +120,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Sys_setProcessPriority
|
|||
}
|
||||
|
||||
if (!SetPriorityClass(me, win32priority)) {
|
||||
#ifdef _DEBUG
|
||||
printf("Failed to set priority class.\n");
|
||||
#endif
|
||||
printfDebug("Failed to set priority class.\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -134,9 +137,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Sys_alert
|
|||
const char * cTitleBarText = env->GetStringUTFChars(title, ©);
|
||||
MessageBox(hwnd, eMessageText, cTitleBarText, MB_OK | MB_TOPMOST);
|
||||
|
||||
#ifdef _DEBUG
|
||||
printf("*** Alert ***%s\n%s\n", cTitleBarText, eMessageText);
|
||||
#endif
|
||||
printfDebug("*** Alert ***%s\n%s\n", cTitleBarText, eMessageText);
|
||||
|
||||
env->ReleaseStringUTFChars(message, eMessageText);
|
||||
env->ReleaseStringUTFChars(title, cTitleBarText);
|
||||
|
|
@ -170,33 +171,31 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Sys_nOpenURL
|
|||
strncat(command, urlString, 200); // Prevent buffer overflow
|
||||
env->ReleaseStringUTFChars(url, urlString);
|
||||
|
||||
STARTUPINFO si;
|
||||
PROCESS_INFORMATION pi;
|
||||
STARTUPINFO si;
|
||||
PROCESS_INFORMATION pi;
|
||||
|
||||
ZeroMemory( &si, sizeof(si) );
|
||||
si.cb = sizeof(si);
|
||||
ZeroMemory( &pi, sizeof(pi) );
|
||||
ZeroMemory( &si, sizeof(si) );
|
||||
si.cb = sizeof(si);
|
||||
ZeroMemory( &pi, sizeof(pi) );
|
||||
|
||||
// Start the child process.
|
||||
if( !CreateProcess( NULL, // No module name (use command line).
|
||||
command, // Command line.
|
||||
NULL, // Process handle not inheritable.
|
||||
NULL, // Thread handle not inheritable.
|
||||
FALSE, // Set handle inheritance to FALSE.
|
||||
0, // No creation flags.
|
||||
NULL, // Use parent's environment block.
|
||||
NULL, // Use parent's starting directory.
|
||||
&si, // Pointer to STARTUPINFO structure.
|
||||
&pi ) // Pointer to PROCESS_INFORMATION structure.
|
||||
)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
printf("Failed to open URL %s\n", urlString);
|
||||
#endif
|
||||
}
|
||||
// Start the child process.
|
||||
if( !CreateProcess( NULL, // No module name (use command line).
|
||||
command, // Command line.
|
||||
NULL, // Process handle not inheritable.
|
||||
NULL, // Thread handle not inheritable.
|
||||
FALSE, // Set handle inheritance to FALSE.
|
||||
0, // No creation flags.
|
||||
NULL, // Use parent's environment block.
|
||||
NULL, // Use parent's starting directory.
|
||||
&si, // Pointer to STARTUPINFO structure.
|
||||
&pi ) // Pointer to PROCESS_INFORMATION structure.
|
||||
)
|
||||
{
|
||||
printfDebug("Failed to open URL %s\n", urlString);
|
||||
}
|
||||
|
||||
// Close process and thread handles.
|
||||
CloseHandle( pi.hProcess );
|
||||
CloseHandle( pi.hThread );
|
||||
// Close process and thread handles.
|
||||
CloseHandle( pi.hProcess );
|
||||
CloseHandle( pi.hThread );
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,15 +7,15 @@
|
|||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 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.
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'Light Weight Java Game Library' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
* 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
|
||||
|
|
@ -42,33 +42,33 @@
|
|||
#define WIN32_LEAN_AND_MEAN
|
||||
#include "org_lwjgl_input_Controller.h"
|
||||
#include <windows.h>
|
||||
#undef DIRECTINPUT_VERSION
|
||||
#undef DIRECTINPUT_VERSION
|
||||
#define DIRECTINPUT_VERSION 0x0500
|
||||
#include <dinput.h>
|
||||
#include "Window.h"
|
||||
#include "common_tools.h"
|
||||
|
||||
#define CONTROLLER_AXISMAX 1000 // Maxmimum range to which we'll gauge the swing
|
||||
#define CONTROLLER_AXISMIN -1000 // Minimum range to which we'll gauge the swing
|
||||
#define CONTROLLER_AXISMAX 1000 // Maxmimum range to which we'll gauge the swing
|
||||
#define CONTROLLER_AXISMIN -1000 // Minimum range to which we'll gauge the swing
|
||||
|
||||
extern HINSTANCE dll_handle;
|
||||
extern HWND hwnd;
|
||||
|
||||
static IDirectInput* cDI; // DI instance
|
||||
static IDirectInputDevice2* cDIDevice; // DI Device instance
|
||||
static DIJOYSTATE2 cJS; // State of Controller
|
||||
static IDirectInput* cDI; // DI instance
|
||||
static IDirectInputDevice2* cDIDevice; // DI Device instance
|
||||
static DIJOYSTATE2 cJS; // State of Controller
|
||||
|
||||
static int cButtoncount = 0; // Temporary buttoncount
|
||||
static bool cHasx; // Temporary xaxis check
|
||||
static bool cHasrx; // Temporary rotational xaxis check
|
||||
static bool cHasy; // Temporary yaxis check
|
||||
static bool cHasry; // Temporary rotational yaxis check
|
||||
static bool cHasz; // Temporary zaxis check
|
||||
static bool cHasrz; // Temporary rotational zaxis check
|
||||
static bool cHaspov; // Temporary pov check
|
||||
static bool cHasslider; // Temporary slider check
|
||||
static int cButtoncount = 0; // Temporary buttoncount
|
||||
static bool cHasx; // Temporary xaxis check
|
||||
static bool cHasrx; // Temporary rotational xaxis check
|
||||
static bool cHasy; // Temporary yaxis check
|
||||
static bool cHasry; // Temporary rotational yaxis check
|
||||
static bool cHasz; // Temporary zaxis check
|
||||
static bool cHasrz; // Temporary rotational zaxis check
|
||||
static bool cHaspov; // Temporary pov check
|
||||
static bool cHasslider; // Temporary slider check
|
||||
|
||||
static bool cCreate_success; // bool used to determine successfull creation
|
||||
static bool cCreate_success; // bool used to determine successfull creation
|
||||
static bool cFirstTimeInitialization = true; // boolean to determine first time initialization
|
||||
|
||||
// Cached fields of Controller.java
|
||||
|
|
@ -108,470 +108,431 @@ void SetControllerCapabilities(JNIEnv *env, jclass clsController);
|
|||
* Initializes any field ids
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_input_Controller_initIDs(JNIEnv * env, jclass clazz) {
|
||||
/* Cache fields in Controller */
|
||||
CacheControllerFields(env, clazz);
|
||||
/* Cache fields in Controller */
|
||||
CacheControllerFields(env, clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the Controller instance is to be created
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_input_Controller_nCreate(JNIEnv *env, jclass clazz) {
|
||||
// Create the DirectInput object.
|
||||
HRESULT hr;
|
||||
hr = DirectInputCreate(dll_handle, DIRECTINPUT_VERSION, &cDI, NULL);
|
||||
if (FAILED(hr)) {
|
||||
#if _DEBUG
|
||||
printf("DirectInputCreate failed\n");
|
||||
#endif
|
||||
ShutdownController();
|
||||
return;
|
||||
}
|
||||
// Create the DirectInput object.
|
||||
HRESULT hr;
|
||||
hr = DirectInputCreate(dll_handle, DIRECTINPUT_VERSION, &cDI, NULL);
|
||||
if (FAILED(hr)) {
|
||||
printfDebug("DirectInputCreate failed\n");
|
||||
ShutdownController();
|
||||
return;
|
||||
}
|
||||
|
||||
/* Find all Controllers */
|
||||
EnumerateControllers();
|
||||
if (!cCreate_success) {
|
||||
throwException(env, "Failed to enumerate.");
|
||||
ShutdownController();
|
||||
return;
|
||||
}
|
||||
/* Find all Controllers */
|
||||
EnumerateControllers();
|
||||
if (!cCreate_success) {
|
||||
throwException(env, "Failed to enumerate.");
|
||||
ShutdownController();
|
||||
return;
|
||||
}
|
||||
|
||||
/* check that we got at least 1 controller */
|
||||
if (cDIDevice == NULL) {
|
||||
throwException(env, "No devices found.");
|
||||
ShutdownController();
|
||||
return;
|
||||
}
|
||||
/* check that we got at least 1 controller */
|
||||
if (cDIDevice == NULL) {
|
||||
throwException(env, "No devices found.");
|
||||
ShutdownController();
|
||||
return;
|
||||
}
|
||||
|
||||
//check for first time initialization - need to detect capabilities
|
||||
if (cFirstTimeInitialization) {
|
||||
cFirstTimeInitialization = false;
|
||||
//check for first time initialization - need to detect capabilities
|
||||
if (cFirstTimeInitialization) {
|
||||
cFirstTimeInitialization = false;
|
||||
|
||||
/* Enumerate capabilities of Controller */
|
||||
EnumerateControllerCapabilities();
|
||||
if (!cCreate_success) {
|
||||
throwException(env, "Falied to enumerate capabilities.");
|
||||
ShutdownController();
|
||||
return;
|
||||
}
|
||||
|
||||
/* Enumerate capabilities of Controller */
|
||||
EnumerateControllerCapabilities();
|
||||
if (!cCreate_success) {
|
||||
throwException(env, "Falied to enumerate capabilities.");
|
||||
ShutdownController();
|
||||
return;
|
||||
}
|
||||
/* Do setup of Controller */
|
||||
SetupController();
|
||||
|
||||
/* Do setup of Controller */
|
||||
SetupController();
|
||||
/* Initialize any fields on the Controller */
|
||||
InitializeControllerFields(env, clazz);
|
||||
|
||||
/* Initialize any fields on the Controller */
|
||||
InitializeControllerFields(env, clazz);
|
||||
/* Set capabilities */
|
||||
SetControllerCapabilities(env, clazz);
|
||||
} else {
|
||||
if(cCreate_success) {
|
||||
/* Do setup of Controller */
|
||||
SetupController();
|
||||
|
||||
/* Initialize any fields on the Controller */
|
||||
InitializeControllerFields(env, clazz);
|
||||
}
|
||||
}
|
||||
|
||||
/* Set capabilities */
|
||||
SetControllerCapabilities(env, clazz);
|
||||
} else {
|
||||
if(cCreate_success) {
|
||||
/* Do setup of Controller */
|
||||
SetupController();
|
||||
|
||||
/* Initialize any fields on the Controller */
|
||||
InitializeControllerFields(env, clazz);
|
||||
}
|
||||
}
|
||||
|
||||
/* Aquire the Controller */
|
||||
hr = cDIDevice->Acquire();
|
||||
if(FAILED(hr)) {
|
||||
throwException(env, "Acquire failed");
|
||||
ShutdownController();
|
||||
return;
|
||||
}
|
||||
/* Aquire the Controller */
|
||||
hr = cDIDevice->Acquire();
|
||||
if(FAILED(hr)) {
|
||||
throwException(env, "Acquire failed");
|
||||
ShutdownController();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_lwjgl_input_Controller
|
||||
* Method: nDestroy
|
||||
* Class: org_lwjgl_input_Controller
|
||||
* Method: nDestroy
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_input_Controller_nDestroy(JNIEnv *env, jclass clazz) {
|
||||
ShutdownController();
|
||||
ShutdownController();
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_lwjgl_input_Controller
|
||||
* Method: nPoll
|
||||
* Class: org_lwjgl_input_Controller
|
||||
* Method: nPoll
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_input_Controller_nPoll(JNIEnv * env, jclass clazz) {
|
||||
HRESULT hRes;
|
||||
HRESULT hRes;
|
||||
|
||||
// poll the Controller to read the current state
|
||||
hRes = cDIDevice->Poll();
|
||||
if (FAILED(hRes)) {
|
||||
#if _DEBUG
|
||||
printf("Poll fail\n");
|
||||
#endif
|
||||
// poll the Controller to read the current state
|
||||
hRes = cDIDevice->Poll();
|
||||
if (FAILED(hRes)) {
|
||||
printfDebug("Poll fail\n");
|
||||
|
||||
//check if we need to reaquire
|
||||
if(hRes == DIERR_INPUTLOST || hRes == DIERR_NOTACQUIRED) {
|
||||
cDIDevice->Acquire();
|
||||
#if _DEBUG
|
||||
printf("DIERR_INPUTLOST, reaquiring input : cCreate_success=%d\n", cCreate_success);
|
||||
#endif
|
||||
}
|
||||
return;
|
||||
}
|
||||
//check if we need to reaquire
|
||||
if(hRes == DIERR_INPUTLOST || hRes == DIERR_NOTACQUIRED) {
|
||||
cDIDevice->Acquire();
|
||||
printfDebug("DIERR_INPUTLOST, reaquiring input : cCreate_success=%d\n", cCreate_success);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateControllerFields(env, clazz);
|
||||
UpdateControllerFields(env, clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shutdown DI
|
||||
*/
|
||||
static void ShutdownController() {
|
||||
// release device
|
||||
if (cDIDevice != NULL) {
|
||||
cDIDevice->Unacquire();
|
||||
cDIDevice->Release();
|
||||
cDIDevice = NULL;
|
||||
}
|
||||
// release device
|
||||
if (cDIDevice != NULL) {
|
||||
cDIDevice->Unacquire();
|
||||
cDIDevice->Release();
|
||||
cDIDevice = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enumerates the capabilities of the Controller attached to the system
|
||||
*/
|
||||
static void EnumerateControllerCapabilities() {
|
||||
HRESULT hr;
|
||||
hr = cDIDevice->EnumObjects(EnumControllerObjectsCallback, NULL, DIDFT_ALL);
|
||||
if FAILED(hr) {
|
||||
#if _DEBUG
|
||||
printf("EnumObjects failed\n");
|
||||
#endif
|
||||
cCreate_success = false;
|
||||
return;
|
||||
}
|
||||
cCreate_success = true;
|
||||
HRESULT hr;
|
||||
hr = cDIDevice->EnumObjects(EnumControllerObjectsCallback, NULL, DIDFT_ALL);
|
||||
if FAILED(hr) {
|
||||
printfDebug("EnumObjects failed\n");
|
||||
cCreate_success = false;
|
||||
return;
|
||||
}
|
||||
cCreate_success = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enumerates the Controllers attached to the system
|
||||
*/
|
||||
static void EnumerateControllers() {
|
||||
HRESULT hr;
|
||||
hr = cDI->EnumDevices(DIDEVTYPE_JOYSTICK, EnumControllerCallback, 0, DIEDFL_ATTACHEDONLY);
|
||||
if FAILED(hr) {
|
||||
#if _DEBUG
|
||||
printf("EnumDevices failed\n");
|
||||
#endif
|
||||
cCreate_success = false;
|
||||
return;
|
||||
}
|
||||
cCreate_success = true;
|
||||
HRESULT hr;
|
||||
hr = cDI->EnumDevices(DIDEVTYPE_JOYSTICK, EnumControllerCallback, 0, DIEDFL_ATTACHEDONLY);
|
||||
if FAILED(hr) {
|
||||
printfDebug("EnumDevices failed\n");
|
||||
cCreate_success = false;
|
||||
return;
|
||||
}
|
||||
cCreate_success = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback from EnumDevices. Called for each Controller attached to the system
|
||||
*/
|
||||
BOOL CALLBACK EnumControllerCallback(LPCDIDEVICEINSTANCE pdinst, LPVOID pvRef) {
|
||||
/* Add the Controller */
|
||||
CreateController(pdinst);
|
||||
/* Add the Controller */
|
||||
CreateController(pdinst);
|
||||
|
||||
/* just stop after 1st Controller */
|
||||
return DIENUM_STOP;
|
||||
/* just stop after 1st Controller */
|
||||
return DIENUM_STOP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback from EnumObjects. Called for each "object" on the Controller.
|
||||
*/
|
||||
BOOL CALLBACK EnumControllerObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef) {
|
||||
#if _DEBUG
|
||||
printf("found %s\n", lpddoi->tszName);
|
||||
#endif
|
||||
if(lpddoi->guidType == GUID_Button) {
|
||||
cButtoncount++;
|
||||
} else if(lpddoi->guidType == GUID_XAxis) {
|
||||
cHasx = true;
|
||||
} else if(lpddoi->guidType == GUID_YAxis) {
|
||||
cHasy = true;
|
||||
} else if(lpddoi->guidType == GUID_ZAxis){
|
||||
cHasz = true;
|
||||
} else if (lpddoi->guidType == GUID_POV){
|
||||
cHaspov = true;
|
||||
} else if (lpddoi->guidType == GUID_Slider){
|
||||
cHasslider = true;
|
||||
} else if (lpddoi->guidType == GUID_RxAxis) {
|
||||
cHasrx = true;
|
||||
} else if (lpddoi->guidType == GUID_RyAxis) {
|
||||
cHasry = true;
|
||||
} else if (lpddoi->guidType == GUID_RzAxis) {
|
||||
cHasrz = true;
|
||||
#if _DEBUG
|
||||
} else {
|
||||
printf("Unhandled object found: %s\n", lpddoi->tszName);
|
||||
#endif
|
||||
}
|
||||
return DIENUM_CONTINUE;
|
||||
printfDebug("found %s\n", lpddoi->tszName);
|
||||
if(lpddoi->guidType == GUID_Button) {
|
||||
cButtoncount++;
|
||||
} else if(lpddoi->guidType == GUID_XAxis) {
|
||||
cHasx = true;
|
||||
} else if(lpddoi->guidType == GUID_YAxis) {
|
||||
cHasy = true;
|
||||
} else if(lpddoi->guidType == GUID_ZAxis){
|
||||
cHasz = true;
|
||||
} else if (lpddoi->guidType == GUID_POV){
|
||||
cHaspov = true;
|
||||
} else if (lpddoi->guidType == GUID_Slider){
|
||||
cHasslider = true;
|
||||
} else if (lpddoi->guidType == GUID_RxAxis) {
|
||||
cHasrx = true;
|
||||
} else if (lpddoi->guidType == GUID_RyAxis) {
|
||||
cHasry = true;
|
||||
} else if (lpddoi->guidType == GUID_RzAxis) {
|
||||
cHasrz = true;
|
||||
} else {
|
||||
printfDebug("Unhandled object found: %s\n", lpddoi->tszName);
|
||||
}
|
||||
return DIENUM_CONTINUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the specified device as a Controller
|
||||
*/
|
||||
static void CreateController(LPCDIDEVICEINSTANCE lpddi) {
|
||||
HRESULT hr;
|
||||
hr = cDI->CreateDevice(lpddi->guidInstance, (LPDIRECTINPUTDEVICE*) &cDIDevice, NULL);
|
||||
if FAILED(hr) {
|
||||
#if _DEBUG
|
||||
printf("CreateDevice failed\n");
|
||||
#endif
|
||||
cCreate_success = false;
|
||||
return;
|
||||
}
|
||||
cCreate_success = true;
|
||||
HRESULT hr;
|
||||
hr = cDI->CreateDevice(lpddi->guidInstance, (LPDIRECTINPUTDEVICE*) &cDIDevice, NULL);
|
||||
if FAILED(hr) {
|
||||
printfDebug("CreateDevice failed\n");
|
||||
cCreate_success = false;
|
||||
return;
|
||||
}
|
||||
cCreate_success = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the Controller properties
|
||||
*/
|
||||
static void SetupController() {
|
||||
// set Controller data format
|
||||
if(cDIDevice->SetDataFormat(&c_dfDIJoystick2) != DI_OK) {
|
||||
#if _DEBUG
|
||||
printf("SetDataFormat failed\n");
|
||||
#endif
|
||||
cCreate_success = false;
|
||||
return;
|
||||
}
|
||||
// set Controller data format
|
||||
if(cDIDevice->SetDataFormat(&c_dfDIJoystick2) != DI_OK) {
|
||||
printfDebug("SetDataFormat failed\n");
|
||||
cCreate_success = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// set the cooperative level
|
||||
if(cDIDevice->SetCooperativeLevel(hwnd, DISCL_EXCLUSIVE | DISCL_FOREGROUND) != DI_OK) {
|
||||
#if _DEBUG
|
||||
printf("SetCooperativeLevel failed\n");
|
||||
#endif
|
||||
cCreate_success = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// set range to (-1000 ... +1000)
|
||||
// This lets us test against 0 to see which way the stick is pointed.
|
||||
DIPROPRANGE diprg;
|
||||
diprg.diph.dwSize = sizeof(diprg);
|
||||
diprg.diph.dwHeaderSize = sizeof(diprg.diph);
|
||||
diprg.diph.dwHow = DIPH_BYOFFSET;
|
||||
diprg.lMin = CONTROLLER_AXISMIN;
|
||||
diprg.lMax = CONTROLLER_AXISMAX;
|
||||
// set the cooperative level
|
||||
if(cDIDevice->SetCooperativeLevel(hwnd, DISCL_EXCLUSIVE | DISCL_FOREGROUND) != DI_OK) {
|
||||
printfDebug("SetCooperativeLevel failed\n");
|
||||
cCreate_success = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// set range to (-1000 ... +1000)
|
||||
// This lets us test against 0 to see which way the stick is pointed.
|
||||
DIPROPRANGE diprg;
|
||||
diprg.diph.dwSize = sizeof(diprg);
|
||||
diprg.diph.dwHeaderSize = sizeof(diprg.diph);
|
||||
diprg.diph.dwHow = DIPH_BYOFFSET;
|
||||
diprg.lMin = CONTROLLER_AXISMIN;
|
||||
diprg.lMax = CONTROLLER_AXISMAX;
|
||||
|
||||
// set X-axis
|
||||
if(cHasx) {
|
||||
diprg.diph.dwObj = DIJOFS_X;
|
||||
if(cDIDevice->SetProperty(DIPROP_RANGE, &diprg.diph) != DI_OK) {
|
||||
#if _DEBUG
|
||||
printf("SetProperty(DIJOFS_X) failed\n");
|
||||
#endif
|
||||
cCreate_success = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
// set X-axis
|
||||
if(cHasx) {
|
||||
diprg.diph.dwObj = DIJOFS_X;
|
||||
if(cDIDevice->SetProperty(DIPROP_RANGE, &diprg.diph) != DI_OK) {
|
||||
printfDebug("SetProperty(DIJOFS_X) failed\n");
|
||||
cCreate_success = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// set RX-axis
|
||||
if(cHasrx) {
|
||||
diprg.diph.dwObj = DIJOFS_RX;
|
||||
if(cDIDevice->SetProperty(DIPROP_RANGE, &diprg.diph) != DI_OK) {
|
||||
#if _DEBUG
|
||||
printf("SetProperty(DIJOFS_RX) failed\n");
|
||||
#endif
|
||||
cCreate_success = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
// set RX-axis
|
||||
if(cHasrx) {
|
||||
diprg.diph.dwObj = DIJOFS_RX;
|
||||
if(cDIDevice->SetProperty(DIPROP_RANGE, &diprg.diph) != DI_OK) {
|
||||
printfDebug("SetProperty(DIJOFS_RX) failed\n");
|
||||
cCreate_success = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// set Y-axis
|
||||
if(cHasy) {
|
||||
diprg.diph.dwObj = DIJOFS_Y;
|
||||
if(cDIDevice->SetProperty(DIPROP_RANGE, &diprg.diph) != DI_OK) {
|
||||
#if _DEBUG
|
||||
printf("SetProperty(DIJOFS_Y) failed\n");
|
||||
#endif
|
||||
cCreate_success = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
// set Y-axis
|
||||
if(cHasy) {
|
||||
diprg.diph.dwObj = DIJOFS_Y;
|
||||
if(cDIDevice->SetProperty(DIPROP_RANGE, &diprg.diph) != DI_OK) {
|
||||
printfDebug("SetProperty(DIJOFS_Y) failed\n");
|
||||
cCreate_success = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// set RY-axis
|
||||
if(cHasry) {
|
||||
diprg.diph.dwObj = DIJOFS_RY;
|
||||
if(cDIDevice->SetProperty(DIPROP_RANGE, &diprg.diph) != DI_OK) {
|
||||
#if _DEBUG
|
||||
printf("SetProperty(DIJOFS_RY) failed\n");
|
||||
#endif
|
||||
cCreate_success = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
// set RY-axis
|
||||
if(cHasry) {
|
||||
diprg.diph.dwObj = DIJOFS_RY;
|
||||
if(cDIDevice->SetProperty(DIPROP_RANGE, &diprg.diph) != DI_OK) {
|
||||
printfDebug("SetProperty(DIJOFS_RY) failed\n");
|
||||
cCreate_success = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// set Z-axis
|
||||
if(cHasz) {
|
||||
diprg.diph.dwObj = DIJOFS_Z;
|
||||
if(cDIDevice->SetProperty(DIPROP_RANGE, &diprg.diph) != DI_OK) {
|
||||
#if _DEBUG
|
||||
printf("SetProperty(DIJOFS_Z) failed\n");
|
||||
#endif
|
||||
cCreate_success = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
// set Z-axis
|
||||
if(cHasz) {
|
||||
diprg.diph.dwObj = DIJOFS_Z;
|
||||
if(cDIDevice->SetProperty(DIPROP_RANGE, &diprg.diph) != DI_OK) {
|
||||
printfDebug("SetProperty(DIJOFS_Z) failed\n");
|
||||
cCreate_success = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// set RZ-axis
|
||||
if(cHasrz) {
|
||||
diprg.diph.dwObj = DIJOFS_RZ;
|
||||
if(cDIDevice->SetProperty(DIPROP_RANGE, &diprg.diph) != DI_OK) {
|
||||
#if _DEBUG
|
||||
printf("SetProperty(DIJOFS_RZ) failed\n");
|
||||
#endif
|
||||
cCreate_success = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
// set RZ-axis
|
||||
if(cHasrz) {
|
||||
diprg.diph.dwObj = DIJOFS_RZ;
|
||||
if(cDIDevice->SetProperty(DIPROP_RANGE, &diprg.diph) != DI_OK) {
|
||||
printfDebug("SetProperty(DIJOFS_RZ) failed\n");
|
||||
cCreate_success = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Lastly slider
|
||||
// using z axis since we're running dx 5
|
||||
//
|
||||
if(cHasslider) {
|
||||
diprg.diph.dwObj = DIJOFS_Z;
|
||||
if(cDIDevice->SetProperty(DIPROP_RANGE, &diprg.diph) != DI_OK) {
|
||||
#if _DEBUG
|
||||
printf("SetProperty(DIJOFS_Z(SLIDER)) failed\n");
|
||||
#endif
|
||||
cCreate_success = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
cCreate_success = true;
|
||||
//
|
||||
// Lastly slider
|
||||
// using z axis since we're running dx 5
|
||||
//
|
||||
if(cHasslider) {
|
||||
diprg.diph.dwObj = DIJOFS_Z;
|
||||
if(cDIDevice->SetProperty(DIPROP_RANGE, &diprg.diph) != DI_OK) {
|
||||
printfDebug("SetProperty(DIJOFS_Z(SLIDER)) failed\n");
|
||||
cCreate_success = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
cCreate_success = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the fields on the Controller
|
||||
*/
|
||||
static void InitializeControllerFields(JNIEnv *env, jclass clsController) {
|
||||
//create buttons array
|
||||
jbooleanArray cButtonsArray = env->NewBooleanArray(cButtoncount);
|
||||
|
||||
//set buttons array
|
||||
env->SetStaticObjectField(clsController, fidCButtons, cButtonsArray);
|
||||
//create buttons array
|
||||
jbooleanArray cButtonsArray = env->NewBooleanArray(cButtoncount);
|
||||
|
||||
//set buttons array
|
||||
env->SetStaticObjectField(clsController, fidCButtons, cButtonsArray);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the fields on the Controller
|
||||
*/
|
||||
static void UpdateControllerFields(JNIEnv *env, jclass clsController) {
|
||||
HRESULT hRes;
|
||||
HRESULT hRes;
|
||||
|
||||
// get data from the Controller
|
||||
hRes = cDIDevice->GetDeviceState(sizeof(DIJOYSTATE2), &cJS);
|
||||
// get data from the Controller
|
||||
hRes = cDIDevice->GetDeviceState(sizeof(DIJOYSTATE2), &cJS);
|
||||
|
||||
if (hRes != DI_OK) {
|
||||
// did the read fail because we lost input for some reason?
|
||||
// if so, then attempt to reacquire.
|
||||
if(hRes == DIERR_INPUTLOST || hRes == DIERR_NOTACQUIRED) {
|
||||
cDIDevice->Acquire();
|
||||
#if _DEBUG
|
||||
printf("DIERR_INPUTLOST, reaquiring input : cCreate_success=%d\n", cCreate_success);
|
||||
#endif
|
||||
}
|
||||
#if _DEBUG
|
||||
printf("Error getting controller state: %d\n", hRes);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
if (hRes != DI_OK) {
|
||||
// did the read fail because we lost input for some reason?
|
||||
// if so, then attempt to reacquire.
|
||||
if(hRes == DIERR_INPUTLOST || hRes == DIERR_NOTACQUIRED) {
|
||||
cDIDevice->Acquire();
|
||||
printfDebug("DIERR_INPUTLOST, reaquiring input : cCreate_success=%d\n", cCreate_success);
|
||||
}
|
||||
printfDebug("Error getting controller state: %d\n", hRes);
|
||||
return;
|
||||
}
|
||||
|
||||
//axis's
|
||||
if(cHasx) {
|
||||
env->SetStaticIntField(clsController, fidCX, cJS.lX);
|
||||
}
|
||||
//axis's
|
||||
if(cHasx) {
|
||||
env->SetStaticIntField(clsController, fidCX, cJS.lX);
|
||||
}
|
||||
|
||||
if(cHasy) {
|
||||
env->SetStaticIntField(clsController, fidCY, cJS.lY);
|
||||
}
|
||||
if(cHasy) {
|
||||
env->SetStaticIntField(clsController, fidCY, cJS.lY);
|
||||
}
|
||||
|
||||
if(cHasz) {
|
||||
env->SetStaticIntField(clsController, fidCZ, cJS.lZ);
|
||||
}
|
||||
if(cHasz) {
|
||||
env->SetStaticIntField(clsController, fidCZ, cJS.lZ);
|
||||
}
|
||||
|
||||
//rotational axis
|
||||
if(cHasrx) {
|
||||
env->SetStaticIntField(clsController, fidCRX, cJS.lRx);
|
||||
}
|
||||
//rotational axis
|
||||
if(cHasrx) {
|
||||
env->SetStaticIntField(clsController, fidCRX, cJS.lRx);
|
||||
}
|
||||
|
||||
if(cHasry) {
|
||||
env->SetStaticIntField(clsController, fidCRY, cJS.lRy);
|
||||
}
|
||||
if(cHasry) {
|
||||
env->SetStaticIntField(clsController, fidCRY, cJS.lRy);
|
||||
}
|
||||
|
||||
if(cHasrz) {
|
||||
env->SetStaticIntField(clsController, fidCRZ, cJS.lRz);
|
||||
}
|
||||
if(cHasrz) {
|
||||
env->SetStaticIntField(clsController, fidCRZ, cJS.lRz);
|
||||
}
|
||||
|
||||
//buttons
|
||||
for (int i = 0; i < cButtoncount; i++) {
|
||||
if (cJS.rgbButtons[i] != 0) {
|
||||
cJS.rgbButtons[i] = 1;
|
||||
} else {
|
||||
cJS.rgbButtons[i] = 0;
|
||||
}
|
||||
}
|
||||
jbyteArray buttonsArray = (jbyteArray) env->GetStaticObjectField(clsController, fidCButtons);
|
||||
env->SetByteArrayRegion(buttonsArray, 0, cButtoncount, (jbyte *)cJS.rgbButtons);
|
||||
//buttons
|
||||
for (int i = 0; i < cButtoncount; i++) {
|
||||
if (cJS.rgbButtons[i] != 0) {
|
||||
cJS.rgbButtons[i] = 1;
|
||||
} else {
|
||||
cJS.rgbButtons[i] = 0;
|
||||
}
|
||||
}
|
||||
jbyteArray buttonsArray = (jbyteArray) env->GetStaticObjectField(clsController, fidCButtons);
|
||||
env->SetByteArrayRegion(buttonsArray, 0, cButtoncount, (jbyte *)cJS.rgbButtons);
|
||||
|
||||
//pov
|
||||
if(cHaspov) {
|
||||
env->SetStaticIntField(clsController, fidCPOV, cJS.rgdwPOV[0]);
|
||||
}
|
||||
//pov
|
||||
if(cHaspov) {
|
||||
env->SetStaticIntField(clsController, fidCPOV, cJS.rgdwPOV[0]);
|
||||
}
|
||||
|
||||
//slider
|
||||
if(cHasslider) {
|
||||
env->SetStaticIntField(clsController, fidCSlider, cJS.lZ);
|
||||
}
|
||||
//slider
|
||||
if(cHasslider) {
|
||||
env->SetStaticIntField(clsController, fidCSlider, cJS.lZ);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the capabilities of the Controller
|
||||
*/
|
||||
static void SetControllerCapabilities(JNIEnv *env, jclass clsController) {
|
||||
//set buttoncount
|
||||
env->SetStaticIntField(clsController, fidCButtonCount, cButtoncount);
|
||||
//set buttoncount
|
||||
env->SetStaticIntField(clsController, fidCButtonCount, cButtoncount);
|
||||
|
||||
//set axis
|
||||
env->SetStaticBooleanField(clsController, fidCHasXAxis, cHasx);
|
||||
env->SetStaticBooleanField(clsController, fidCHasYAxis, cHasy);
|
||||
env->SetStaticBooleanField(clsController, fidCHasZAxis, cHasz);
|
||||
//set axis
|
||||
env->SetStaticBooleanField(clsController, fidCHasXAxis, cHasx);
|
||||
env->SetStaticBooleanField(clsController, fidCHasYAxis, cHasy);
|
||||
env->SetStaticBooleanField(clsController, fidCHasZAxis, cHasz);
|
||||
|
||||
//set rotational axis
|
||||
env->SetStaticBooleanField(clsController, fidCHasRXAxis, cHasrx);
|
||||
env->SetStaticBooleanField(clsController, fidCHasRYAxis, cHasry);
|
||||
env->SetStaticBooleanField(clsController, fidCHasRZAxis, cHasrz);
|
||||
//set rotational axis
|
||||
env->SetStaticBooleanField(clsController, fidCHasRXAxis, cHasrx);
|
||||
env->SetStaticBooleanField(clsController, fidCHasRYAxis, cHasry);
|
||||
env->SetStaticBooleanField(clsController, fidCHasRZAxis, cHasrz);
|
||||
|
||||
//set pov
|
||||
env->SetStaticBooleanField(clsController, fidCHasPOV, cHaspov);
|
||||
//set pov
|
||||
env->SetStaticBooleanField(clsController, fidCHasPOV, cHaspov);
|
||||
|
||||
//set slider
|
||||
env->SetStaticBooleanField(clsController, fidCHasSlider, cHasslider);
|
||||
//set slider
|
||||
env->SetStaticBooleanField(clsController, fidCHasSlider, cHasslider);
|
||||
}
|
||||
|
||||
/**
|
||||
* Caches the field ids for quicker access
|
||||
*/
|
||||
static void CacheControllerFields(JNIEnv *env, jclass clsController) {
|
||||
fidCButtonCount = env->GetStaticFieldID(clsController, "buttonCount", "I");
|
||||
fidCHasXAxis = env->GetStaticFieldID(clsController, "hasXAxis", "Z");
|
||||
fidCHasRXAxis = env->GetStaticFieldID(clsController, "hasRXAxis", "Z");
|
||||
fidCHasYAxis = env->GetStaticFieldID(clsController, "hasYAxis", "Z");
|
||||
fidCHasRYAxis = env->GetStaticFieldID(clsController, "hasRYAxis", "Z");
|
||||
fidCHasZAxis = env->GetStaticFieldID(clsController, "hasZAxis", "Z");
|
||||
fidCHasRZAxis = env->GetStaticFieldID(clsController, "hasRZAxis", "Z");
|
||||
fidCHasPOV = env->GetStaticFieldID(clsController, "hasPOV", "Z");
|
||||
fidCHasSlider = env->GetStaticFieldID(clsController, "hasSlider", "Z");
|
||||
fidCButtons = env->GetStaticFieldID(clsController, "buttons", "[Z");
|
||||
fidCX = env->GetStaticFieldID(clsController, "x", "I");
|
||||
fidCRX = env->GetStaticFieldID(clsController, "rx", "I");
|
||||
fidCY = env->GetStaticFieldID(clsController, "y", "I");
|
||||
fidCRY = env->GetStaticFieldID(clsController, "ry", "I");
|
||||
fidCZ = env->GetStaticFieldID(clsController, "z", "I");
|
||||
fidCRZ = env->GetStaticFieldID(clsController, "rz", "I");
|
||||
fidCPOV = env->GetStaticFieldID(clsController, "pov", "I");
|
||||
fidCSlider = env->GetStaticFieldID(clsController, "slider", "I");
|
||||
fidCButtonCount = env->GetStaticFieldID(clsController, "buttonCount", "I");
|
||||
fidCHasXAxis = env->GetStaticFieldID(clsController, "hasXAxis", "Z");
|
||||
fidCHasRXAxis = env->GetStaticFieldID(clsController, "hasRXAxis", "Z");
|
||||
fidCHasYAxis = env->GetStaticFieldID(clsController, "hasYAxis", "Z");
|
||||
fidCHasRYAxis = env->GetStaticFieldID(clsController, "hasRYAxis", "Z");
|
||||
fidCHasZAxis = env->GetStaticFieldID(clsController, "hasZAxis", "Z");
|
||||
fidCHasRZAxis = env->GetStaticFieldID(clsController, "hasRZAxis", "Z");
|
||||
fidCHasPOV = env->GetStaticFieldID(clsController, "hasPOV", "Z");
|
||||
fidCHasSlider = env->GetStaticFieldID(clsController, "hasSlider", "Z");
|
||||
fidCButtons = env->GetStaticFieldID(clsController, "buttons", "[Z");
|
||||
fidCX = env->GetStaticFieldID(clsController, "x", "I");
|
||||
fidCRX = env->GetStaticFieldID(clsController, "rx", "I");
|
||||
fidCY = env->GetStaticFieldID(clsController, "y", "I");
|
||||
fidCRY = env->GetStaticFieldID(clsController, "ry", "I");
|
||||
fidCZ = env->GetStaticFieldID(clsController, "z", "I");
|
||||
fidCRZ = env->GetStaticFieldID(clsController, "rz", "I");
|
||||
fidCPOV = env->GetStaticFieldID(clsController, "pov", "I");
|
||||
fidCSlider = env->GetStaticFieldID(clsController, "slider", "I");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -110,9 +110,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nCreate
|
|||
|
||||
HRESULT ret = lpdiKeyboard->Acquire();
|
||||
if(FAILED(ret)) {
|
||||
#if _DEBUG
|
||||
printf("Failed to acquire keyboard\n");
|
||||
#endif
|
||||
printfDebug("Failed to acquire keyboard\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -200,11 +198,6 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_input_Keyboard_nRead
|
|||
|
||||
if (ret == DI_OK) {
|
||||
unsigned char * buf = readBuffer;
|
||||
//#ifdef _DEBUG
|
||||
// if (bufsize > 0) {
|
||||
// printf("Got %d keyboard events.\n", bufsize);
|
||||
// }
|
||||
//#endif
|
||||
for (unsigned int i = 0; i < bufsize; i ++) {
|
||||
num_events++;
|
||||
*buf++ = (unsigned char) rgdod[i].dwOfs;
|
||||
|
|
@ -252,33 +245,19 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_input_Keyboard_nRead
|
|||
}
|
||||
}
|
||||
} else if (ret == DI_BUFFEROVERFLOW) {
|
||||
#ifdef _DEBUG
|
||||
printf("Keyboard buffer overflowed\n");
|
||||
#endif
|
||||
printfDebug("Keyboard buffer overflowed\n");
|
||||
} else if (ret == DIERR_INPUTLOST) {
|
||||
#ifdef _DEBUG
|
||||
printf("Input lost\n");
|
||||
#endif
|
||||
printfDebug("Input lost\n");
|
||||
} else if (ret == DIERR_NOTACQUIRED) {
|
||||
#ifdef _DEBUG
|
||||
printf("not acquired\n");
|
||||
#endif
|
||||
printfDebug("not acquired\n");
|
||||
} else if (ret == DIERR_INVALIDPARAM) {
|
||||
#ifdef _DEBUG
|
||||
printf("invalid parameter\n");
|
||||
#endif
|
||||
printfDebug("invalid parameter\n");
|
||||
} else if (ret == DIERR_NOTBUFFERED) {
|
||||
#ifdef _DEBUG
|
||||
printf("not buffered\n");
|
||||
#endif
|
||||
printfDebug("not buffered\n");
|
||||
} else if (ret == DIERR_NOTINITIALIZED) {
|
||||
#ifdef _DEBUG
|
||||
printf("not inited\n");
|
||||
#endif
|
||||
printfDebug("not inited\n");
|
||||
} else {
|
||||
#ifdef _DEBUG
|
||||
printf("unknown keyboard error\n");
|
||||
#endif
|
||||
printfDebug("unknown keyboard error\n");
|
||||
}
|
||||
return num_events;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,15 +7,15 @@
|
|||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 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.
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'Light Weight Java Game Library' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
* 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
|
||||
|
|
@ -41,7 +41,7 @@
|
|||
#define WIN32_LEAN_AND_MEAN
|
||||
#include "org_lwjgl_input_Mouse.h"
|
||||
#include <windows.h>
|
||||
#undef DIRECTINPUT_VERSION
|
||||
#undef DIRECTINPUT_VERSION
|
||||
#define DIRECTINPUT_VERSION 0x0300
|
||||
#include "Window.h"
|
||||
#include "common_tools.h"
|
||||
|
|
@ -49,11 +49,11 @@
|
|||
|
||||
static BYTE readBuffer[EVENT_BUFFER_SIZE];
|
||||
|
||||
static LPDIRECTINPUTDEVICE mDIDevice; // DI Device instance
|
||||
static int mButtoncount = 0; // Temporary buttoncount
|
||||
static bool mHaswheel; // Temporary wheel check
|
||||
static LPDIRECTINPUTDEVICE mDIDevice; // DI Device instance
|
||||
static int mButtoncount = 0; // Temporary buttoncount
|
||||
static bool mHaswheel; // Temporary wheel check
|
||||
|
||||
static bool mCreate_success; // bool used to determine successfull creation
|
||||
static bool mCreate_success; // bool used to determine successfull creation
|
||||
static bool mFirstTimeInitialization = true; // boolean to determine first time initialization
|
||||
|
||||
// Cached fields of Mouse.java
|
||||
|
|
@ -90,8 +90,8 @@ static void getScreenClientRect(RECT* clientRect, RECT* windowRect)
|
|||
* Initializes any field ids
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_initIDs(JNIEnv * env, jclass clazz) {
|
||||
/* Cache fields in Mouse */
|
||||
CacheMouseFields(env, clazz);
|
||||
/* Cache fields in Mouse */
|
||||
CacheMouseFields(env, clazz);
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_lwjgl_input_Mouse_nHasWheel(JNIEnv *, jclass) {
|
||||
|
|
@ -129,15 +129,13 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nCreate(JNIEnv *env, jclass cl
|
|||
} else {
|
||||
if(mCreate_success) {
|
||||
/* Do setup of Mouse */
|
||||
SetupMouse();
|
||||
SetupMouse();
|
||||
}
|
||||
}
|
||||
/* Aquire the Mouse */
|
||||
hr = mDIDevice->Acquire();
|
||||
if(FAILED(hr)) {
|
||||
#if _DEBUG
|
||||
printf("Failed to acquire mouse\n");
|
||||
#endif
|
||||
printfDebug("Failed to acquire mouse\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -178,7 +176,7 @@ static int bufferButtons(int count, DIDEVICEOBJECTDATA *di_buffer) {
|
|||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_org_lwjgl_input_Mouse_nRead
|
||||
(JNIEnv * env, jclass clazz)
|
||||
(JNIEnv * env, jclass clazz)
|
||||
{
|
||||
|
||||
static DIDEVICEOBJECTDATA rgdod[EVENT_BUFFER_SIZE];
|
||||
|
|
@ -199,55 +197,41 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_input_Mouse_nRead
|
|||
if (ret == DI_OK) {
|
||||
return bufferButtons(bufsize, rgdod);
|
||||
} else if (ret == DI_BUFFEROVERFLOW) {
|
||||
#ifdef _DEBUG
|
||||
printf("Buffer overflowed\n");
|
||||
#endif
|
||||
printfDebug("Buffer overflowed\n");
|
||||
} else if (ret == DIERR_INPUTLOST) {
|
||||
#ifdef _DEBUG
|
||||
printf("Input lost\n");
|
||||
#endif
|
||||
printfDebug("Input lost\n");
|
||||
} else if (ret == DIERR_NOTACQUIRED) {
|
||||
#ifdef _DEBUG
|
||||
printf("not acquired\n");
|
||||
#endif
|
||||
printfDebug("not acquired\n");
|
||||
} else if (ret == DIERR_INVALIDPARAM) {
|
||||
#ifdef _DEBUG
|
||||
printf("invalid parameter\n");
|
||||
#endif
|
||||
printfDebug("invalid parameter\n");
|
||||
} else if (ret == DIERR_NOTBUFFERED) {
|
||||
#ifdef _DEBUG
|
||||
printf("not buffered\n");
|
||||
#endif
|
||||
printfDebug("not buffered\n");
|
||||
} else if (ret == DIERR_NOTINITIALIZED) {
|
||||
#ifdef _DEBUG
|
||||
printf("not inited\n");
|
||||
#endif
|
||||
printfDebug("not inited\n");
|
||||
} else {
|
||||
#ifdef _DEBUG
|
||||
printf("unknown keyboard error\n");
|
||||
#endif
|
||||
printfDebug("unknown keyboard error\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_lwjgl_input_Mouse
|
||||
* Method: nIsNativeCursorSupported
|
||||
* Class: org_lwjgl_input_Mouse
|
||||
* Method: nIsNativeCursorSupported
|
||||
* Signature: ()I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_lwjgl_input_Mouse_nGetNativeCursorCaps
|
||||
(JNIEnv *env, jclass clazz)
|
||||
(JNIEnv *env, jclass clazz)
|
||||
{
|
||||
return org_lwjgl_input_Mouse_CURSOR_ONE_BIT_TRANSPARENCY;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_lwjgl_input_Mouse
|
||||
* Method: nSetNativeCursor
|
||||
* Class: org_lwjgl_input_Mouse
|
||||
* Method: nSetNativeCursor
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nSetNativeCursor
|
||||
(JNIEnv *env, jclass clazz, jlong cursor_handle)
|
||||
(JNIEnv *env, jclass clazz, jlong cursor_handle)
|
||||
{
|
||||
if (mDIDevice == NULL)
|
||||
throwException(env, "null device!");
|
||||
|
|
@ -288,30 +272,30 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nSetNativeCursor
|
|||
}
|
||||
|
||||
/*
|
||||
* Class: org_lwjgl_input_Mouse
|
||||
* Method: nGetMaxCursorSize
|
||||
* Class: org_lwjgl_input_Mouse
|
||||
* Method: nGetMaxCursorSize
|
||||
* Signature: ()I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_lwjgl_input_Mouse_nGetMaxCursorSize
|
||||
(JNIEnv *env, jclass clazz)
|
||||
(JNIEnv *env, jclass clazz)
|
||||
{
|
||||
return GetSystemMetrics(SM_CXCURSOR);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_lwjgl_input_Mouse
|
||||
* Method: nGetMaxCursorSize
|
||||
* Class: org_lwjgl_input_Mouse
|
||||
* Method: nGetMaxCursorSize
|
||||
* Signature: ()I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_lwjgl_input_Mouse_nGetMinCursorSize
|
||||
(JNIEnv *env, jclass clazz)
|
||||
(JNIEnv *env, jclass clazz)
|
||||
{
|
||||
return GetSystemMetrics(SM_CXCURSOR);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_lwjgl_input_Mouse
|
||||
* Method: nDestroy
|
||||
* Class: org_lwjgl_input_Mouse
|
||||
* Method: nDestroy
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nDestroy(JNIEnv *env, jclass clazz) {
|
||||
|
|
@ -320,25 +304,25 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nDestroy(JNIEnv *env, jclass c
|
|||
}
|
||||
|
||||
/*
|
||||
* Class: org_lwjgl_input_Controller
|
||||
* Method: nPoll
|
||||
* Class: org_lwjgl_input_Controller
|
||||
* Method: nPoll
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nPoll(JNIEnv * env, jclass clazz) {
|
||||
mDIDevice->Acquire();
|
||||
UpdateMouseFields(env, clazz);
|
||||
mDIDevice->Acquire();
|
||||
UpdateMouseFields(env, clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shutdown DI
|
||||
*/
|
||||
void ShutdownMouse() {
|
||||
// release device
|
||||
if (mDIDevice != NULL) {
|
||||
mDIDevice->Unacquire();
|
||||
mDIDevice->Release();
|
||||
mDIDevice = NULL;
|
||||
}
|
||||
// release device
|
||||
if (mDIDevice != NULL) {
|
||||
mDIDevice->Unacquire();
|
||||
mDIDevice->Release();
|
||||
mDIDevice = NULL;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Enumerates the capabilities of the Mouse attached to the system
|
||||
|
|
@ -347,21 +331,17 @@ void EnumerateMouseCapabilities() {
|
|||
HRESULT hr;
|
||||
hr = mDIDevice->EnumObjects(EnumMouseObjectsCallback, NULL, DIDFT_ALL);
|
||||
if FAILED(hr) {
|
||||
#if _DEBUG
|
||||
printf("EnumObjects failed\n");
|
||||
#endif
|
||||
printfDebug("EnumObjects failed\n");
|
||||
mCreate_success = false;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//check for > 4 buttons - need to clamp since we're using dx 5
|
||||
if(mButtoncount > 4) {
|
||||
mButtoncount = 4;
|
||||
#ifdef _DEBUG
|
||||
printf("WARNING: Clamping to 4 mouse buttons\n");
|
||||
#endif
|
||||
printfDebug("WARNING: Clamping to 4 mouse buttons\n");
|
||||
}
|
||||
|
||||
|
||||
mCreate_success = true;
|
||||
}
|
||||
|
||||
|
|
@ -369,51 +349,43 @@ void EnumerateMouseCapabilities() {
|
|||
* Callback from EnumObjects. Called for each "object" on the Mouse.
|
||||
*/
|
||||
BOOL CALLBACK EnumMouseObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef) {
|
||||
#if _DEBUG
|
||||
printf("found %s\n", lpddoi->tszName);
|
||||
#endif
|
||||
if(lpddoi->guidType == GUID_Button) {
|
||||
mButtoncount++;
|
||||
} else if(lpddoi->guidType == GUID_XAxis) {
|
||||
} else if(lpddoi->guidType == GUID_YAxis) {
|
||||
} else if(lpddoi->guidType == GUID_ZAxis) {
|
||||
mHaswheel = true;
|
||||
#if _DEBUG
|
||||
} else {
|
||||
printf("Unhandled object found: %s\n", lpddoi->tszName);
|
||||
#endif
|
||||
}
|
||||
return DIENUM_CONTINUE;
|
||||
printfDebug("found %s\n", lpddoi->tszName);
|
||||
if(lpddoi->guidType == GUID_Button) {
|
||||
mButtoncount++;
|
||||
} else if(lpddoi->guidType == GUID_XAxis) {
|
||||
} else if(lpddoi->guidType == GUID_YAxis) {
|
||||
} else if(lpddoi->guidType == GUID_ZAxis) {
|
||||
mHaswheel = true;
|
||||
} else {
|
||||
printfDebug("Unhandled object found: %s\n", lpddoi->tszName);
|
||||
}
|
||||
return DIENUM_CONTINUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the specified device as a Mouse
|
||||
*/
|
||||
void CreateMouse() {
|
||||
HRESULT hr;
|
||||
hr = lpdi->CreateDevice(GUID_SysMouse, &mDIDevice, NULL);
|
||||
if FAILED(hr) {
|
||||
#if _DEBUG
|
||||
printf("CreateDevice failed\n");
|
||||
#endif
|
||||
mCreate_success = false;
|
||||
return;
|
||||
}
|
||||
mCreate_success = true;
|
||||
HRESULT hr;
|
||||
hr = lpdi->CreateDevice(GUID_SysMouse, &mDIDevice, NULL);
|
||||
if FAILED(hr) {
|
||||
printfDebug("CreateDevice failed\n");
|
||||
mCreate_success = false;
|
||||
return;
|
||||
}
|
||||
mCreate_success = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the Mouse properties
|
||||
*/
|
||||
void SetupMouse() {
|
||||
// set Mouse data format
|
||||
if(mDIDevice->SetDataFormat(&c_dfDIMouse) != DI_OK) {
|
||||
#if _DEBUG
|
||||
printf("SetDataFormat failed\n");
|
||||
#endif
|
||||
mCreate_success = false;
|
||||
return;
|
||||
}
|
||||
// set Mouse data format
|
||||
if(mDIDevice->SetDataFormat(&c_dfDIMouse) != DI_OK) {
|
||||
printfDebug("SetDataFormat failed\n");
|
||||
mCreate_success = false;
|
||||
return;
|
||||
}
|
||||
|
||||
DIPROPDWORD dipropdw;
|
||||
dipropdw.diph.dwSize = sizeof(DIPROPDWORD);
|
||||
|
|
@ -424,14 +396,12 @@ void SetupMouse() {
|
|||
mDIDevice->SetProperty(DIPROP_BUFFERSIZE, &dipropdw.diph);
|
||||
|
||||
// set the cooperative level
|
||||
if(mDIDevice->SetCooperativeLevel(hwnd, DISCL_EXCLUSIVE | DISCL_FOREGROUND) != DI_OK) {
|
||||
#if _DEBUG
|
||||
printf("SetCooperativeLevel failed\n");
|
||||
#endif
|
||||
mCreate_success = false;
|
||||
return;
|
||||
}
|
||||
mCreate_success = true;
|
||||
if(mDIDevice->SetCooperativeLevel(hwnd, DISCL_EXCLUSIVE | DISCL_FOREGROUND) != DI_OK) {
|
||||
printfDebug("SetCooperativeLevel failed\n");
|
||||
mCreate_success = false;
|
||||
return;
|
||||
}
|
||||
mCreate_success = true;
|
||||
}
|
||||
|
||||
static int cap(int val, int min, int max) {
|
||||
|
|
@ -471,8 +441,8 @@ static void getGDICursorDelta(int* return_dx, int* return_dy) {
|
|||
* Updates the fields on the Mouse
|
||||
*/
|
||||
static void UpdateMouseFields(JNIEnv *env, jclass clsMouse) {
|
||||
HRESULT hRes;
|
||||
DIMOUSESTATE diMouseState; // State of Mouse
|
||||
HRESULT hRes;
|
||||
DIMOUSESTATE diMouseState; // State of Mouse
|
||||
int dx, dy;
|
||||
|
||||
// get data from the Mouse
|
||||
|
|
@ -486,13 +456,8 @@ static void UpdateMouseFields(JNIEnv *env, jclass clsMouse) {
|
|||
// if so, then attempt to reacquire.
|
||||
if(hRes == DIERR_INPUTLOST || hRes == DIERR_NOTACQUIRED) {
|
||||
mDIDevice->Acquire();
|
||||
#if _DEBUG
|
||||
//printf("DIERR_INPUTLOST, reaquiring input : mCreate_success=%d\n", mCreate_success);
|
||||
#endif
|
||||
} else {
|
||||
#if _DEBUG
|
||||
printf("Error getting mouse state: %d\n", hRes);
|
||||
#endif
|
||||
printfDebug("Error getting mouse state: %d\n", hRes);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -523,8 +488,8 @@ static void UpdateMouseFields(JNIEnv *env, jclass clsMouse) {
|
|||
* Caches the field ids for quicker access
|
||||
*/
|
||||
void CacheMouseFields(JNIEnv* env, jclass clsMouse) {
|
||||
fidMButtons = env->GetStaticFieldID(clsMouse, "buttons", "[B");
|
||||
fidMDX = env->GetStaticFieldID(clsMouse, "dx", "I");
|
||||
fidMDY = env->GetStaticFieldID(clsMouse, "dy", "I");
|
||||
fidMDWheel = env->GetStaticFieldID(clsMouse, "dwheel", "I");
|
||||
fidMButtons = env->GetStaticFieldID(clsMouse, "buttons", "[B");
|
||||
fidMDX = env->GetStaticFieldID(clsMouse, "dx", "I");
|
||||
fidMDY = env->GetStaticFieldID(clsMouse, "dy", "I");
|
||||
fidMDWheel = env->GetStaticFieldID(clsMouse, "dwheel", "I");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,9 +97,7 @@ static int findPixelFormat(JNIEnv *env, unsigned int flags, int bpp, int alpha,
|
|||
return -1;
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
printf("Pixel format is %d\n", iPixelFormat);
|
||||
#endif
|
||||
printfDebug("Pixel format is %d\n", iPixelFormat);
|
||||
|
||||
// make that the pixel format of the device context
|
||||
if (SetPixelFormat(hdc, iPixelFormat, &pfd) == FALSE) {
|
||||
|
|
@ -161,22 +159,20 @@ static bool createDirectInput()
|
|||
// Create input
|
||||
HRESULT ret = DirectInputCreate(dll_handle, DIRECTINPUT_VERSION, &lpdi, NULL);
|
||||
if (ret != DI_OK && ret != DIERR_BETADIRECTINPUTVERSION ) {
|
||||
#ifdef _DEBUG
|
||||
printf("Failed to create directinput");
|
||||
printfDebug("Failed to create directinput");
|
||||
switch (ret) {
|
||||
case DIERR_INVALIDPARAM :
|
||||
printf(" - Invalid parameter\n");
|
||||
printfDebug(" - Invalid parameter\n");
|
||||
break;
|
||||
case DIERR_OLDDIRECTINPUTVERSION :
|
||||
printf(" - Old Version\n");
|
||||
printfDebug(" - Old Version\n");
|
||||
break;
|
||||
case DIERR_OUTOFMEMORY :
|
||||
printf(" - Out Of Memory\n");
|
||||
printfDebug(" - Out Of Memory\n");
|
||||
break;
|
||||
default:
|
||||
printf(" - Unknown failure\n");
|
||||
printfDebug(" - Unknown failure\n");
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
|
|
@ -190,31 +186,23 @@ static void closeWindow()
|
|||
{
|
||||
// Release DirectInput
|
||||
if (lpdi != NULL) {
|
||||
#ifdef _DEBUG
|
||||
printf("Destroying directinput\n");
|
||||
#endif
|
||||
printfDebug("Destroying directinput\n");
|
||||
lpdi->Release();
|
||||
lpdi = NULL;
|
||||
}
|
||||
|
||||
// Release device context
|
||||
if (hdc != NULL && hwnd != NULL) {
|
||||
#ifdef _DEBUG
|
||||
printf("Releasing DC\n");
|
||||
#endif
|
||||
printfDebug("Releasing DC\n");
|
||||
ReleaseDC(hwnd, hdc);
|
||||
}
|
||||
|
||||
// Close the window
|
||||
if (hwnd != NULL) {
|
||||
#ifdef _DEBUG
|
||||
printf("Destroy window\n");
|
||||
#endif
|
||||
printfDebug("Destroy window\n");
|
||||
// Vape the window
|
||||
DestroyWindow(hwnd);
|
||||
#ifdef _DEBUG
|
||||
printf("Destroyed window\n");
|
||||
#endif
|
||||
printfDebug("Destroyed window\n");
|
||||
hwnd = NULL;
|
||||
}
|
||||
}
|
||||
|
|
@ -324,14 +312,10 @@ static bool registerWindow()
|
|||
windowClass.lpszClassName = WINDOWCLASSNAME;
|
||||
|
||||
if (RegisterClass(&windowClass) == 0) {
|
||||
#ifdef _DEBUG
|
||||
printf("Failed to register window class\n");
|
||||
#endif
|
||||
printfDebug("Failed to register window class\n");
|
||||
return false;
|
||||
}
|
||||
#ifdef _DEBUG
|
||||
printf("Window registered\n");
|
||||
#endif
|
||||
printfDebug("Window registered\n");
|
||||
oneShotInitialised = true;
|
||||
}
|
||||
|
||||
|
|
@ -413,15 +397,11 @@ static bool createWindow(const char * title, int x, int y, int width, int height
|
|||
NULL);
|
||||
|
||||
if (hwnd == NULL) {
|
||||
#ifdef _DEBUG
|
||||
printf("Failed to create window\n");
|
||||
#endif
|
||||
printfDebug("Failed to create window\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
printf("Created window\n");
|
||||
#endif
|
||||
printfDebug("Created window\n");
|
||||
|
||||
ShowWindow(hwnd, SW_SHOW);
|
||||
UpdateWindow(hwnd);
|
||||
|
|
@ -578,9 +558,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nDestroy
|
|||
|
||||
// Delete the rendering context
|
||||
if (hglrc != NULL) {
|
||||
#ifdef _DEBUG
|
||||
printf("Delete GL context\n");
|
||||
#endif
|
||||
printfDebug("Deleting GL context\n");
|
||||
wglDeleteContext(hglrc);
|
||||
hglrc = NULL;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue