boolean results -> Exceptions

This commit is contained in:
Elias Naur 2003-09-30 10:52:05 +00:00
parent 42e8f13cbe
commit dd72b04c90
9 changed files with 77 additions and 79 deletions

View File

@ -171,9 +171,7 @@ public class Controller {
return; return;
} }
if (!nCreate()) { nCreate();
throw new Exception("The controller could not be created.");
}
created = true; created = true;
} }
@ -248,10 +246,8 @@ public class Controller {
/** /**
* Native method to create the controller * Native method to create the controller
*
* @return true if the controller was created
*/ */
private static native boolean nCreate(); private static native void nCreate() throws Exception;
/** /**
* Native method the destroy the controller * Native method the destroy the controller

View File

@ -286,17 +286,14 @@ public class Keyboard {
initialize(); initialize();
if (created) if (created)
return; return;
if (!nCreate()) nCreate();
throw new Exception("The keyboard could not be created.");
created = true; created = true;
} }
/** /**
* Native method to create the keyboard * Native method to create the keyboard
*
* @return true if the keyboard was created
*/ */
private static native boolean nCreate(); private static native void nCreate() throws Exception;
/** /**
* @return true if the keyboard has been created * @return true if the keyboard has been created
@ -359,27 +356,26 @@ public class Keyboard {
/** /**
* Enable keyboard translation. Must be called after the keyboard is created, * Enable keyboard translation. Must be called after the keyboard is created,
* and keyboard buffering must be enabled. * and keyboard buffering must be enabled.
* @return false if translation cannot be enabled; true if it can
*/ */
public static boolean enableTranslation() { public static void enableTranslation() throws Exception {
assert created : "The keyboard has not been created."; assert created : "The keyboard has not been created.";
assert readBuffer != null : "Keyboard buffering has not been enabled."; assert readBuffer != null : "Keyboard buffering has not been enabled.";
translationEnabled = nEnableTranslation(); nEnableTranslation();
return translationEnabled; translationEnabled = true;
} }
/** /**
* Native method to enable the translation buffer * Native method to enable the translation buffer
*/ */
private static native boolean nEnableTranslation(); private static native void nEnableTranslation() throws Exception;
/** /**
* Enable keyboard buffering. Must be called after the keyboard is created. * Enable keyboard buffering. Must be called after the keyboard is created.
* @return the size of the keyboard buffer in events, or 0 if no buffering * @return the size of the keyboard buffer in events, or 0 if no buffering
* can be enabled for any reason * can be enabled for any reason
*/ */
public static int enableBuffer() { public static int enableBuffer() throws Exception {
assert created : "The keyboard has not been created."; assert created : "The keyboard has not been created.";
int buf_len = nEnableBuffer(); int buf_len = nEnableBuffer();
if (readBuffer != null) if (readBuffer != null)
@ -392,7 +388,7 @@ public class Keyboard {
* @return the size of the buffer allocated, in events (1 event is 2 bytes), * @return the size of the buffer allocated, in events (1 event is 2 bytes),
* or 0 if no buffer can be allocated * or 0 if no buffer can be allocated
*/ */
private static native int nEnableBuffer(); private static native int nEnableBuffer() throws Exception;
/** /**
* Checks to see if a key is down. * Checks to see if a key is down.

View File

@ -146,7 +146,7 @@ public class Mouse {
} }
/** Native method to set the native cursor */ /** Native method to set the native cursor */
private static native void nSetNativeCursor(int handle); private static native void nSetNativeCursor(int handle) throws Exception;
/** /**
* Gets the minimum size of a native cursor. Can only be called if * Gets the minimum size of a native cursor. Can only be called if
@ -210,9 +210,7 @@ public class Mouse {
if (created) { if (created) {
return; return;
} }
if (!nCreate()) { nCreate();
throw new Exception("The mouse could not be created.");
}
created = true; created = true;
currentCursor = null; currentCursor = null;
@ -225,7 +223,7 @@ public class Mouse {
* *
* @return true if the mouse was created * @return true if the mouse was created
*/ */
private static native boolean nCreate(); private static native void nCreate();
/** /**
* @return true if the mouse has been created * @return true if the mouse has been created

View File

@ -107,6 +107,8 @@ public class KeyboardTest {
private void createKeyboard() { private void createKeyboard() {
try { try {
Keyboard.create(); Keyboard.create();
Keyboard.enableBuffer();
Keyboard.enableTranslation();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
System.exit(-1); System.exit(-1);
@ -114,8 +116,6 @@ public class KeyboardTest {
} }
private void wiggleKeyboard() { private void wiggleKeyboard() {
Keyboard.enableBuffer();
Keyboard.enableTranslation();
while (!Window.isCloseRequested()) { while (!Window.isCloseRequested()) {
Window.update(); Window.update();

View File

@ -11,9 +11,13 @@ extern "C" {
/* Inaccessible static: created */ /* Inaccessible static: created */
/* Inaccessible static: buttons */ /* Inaccessible static: buttons */
/* Inaccessible static: x */ /* Inaccessible static: x */
/* Inaccessible static: rx */
/* Inaccessible static: y */ /* Inaccessible static: y */
/* Inaccessible static: ry */
/* Inaccessible static: z */ /* Inaccessible static: z */
/* Inaccessible static: rz */
/* Inaccessible static: pov */ /* Inaccessible static: pov */
/* Inaccessible static: slider */
#undef org_lwjgl_input_Controller_POV_CENTER #undef org_lwjgl_input_Controller_POV_CENTER
#define org_lwjgl_input_Controller_POV_CENTER -1L #define org_lwjgl_input_Controller_POV_CENTER -1L
#undef org_lwjgl_input_Controller_POV_NORTH #undef org_lwjgl_input_Controller_POV_NORTH
@ -25,8 +29,17 @@ extern "C" {
#undef org_lwjgl_input_Controller_POV_WEST #undef org_lwjgl_input_Controller_POV_WEST
#define org_lwjgl_input_Controller_POV_WEST 9000L #define org_lwjgl_input_Controller_POV_WEST 9000L
/* Inaccessible static: buttonCount */ /* Inaccessible static: buttonCount */
/* Inaccessible static: hasXAxis */
/* Inaccessible static: hasRXAxis */
/* Inaccessible static: hasYAxis */
/* Inaccessible static: hasRYAxis */
/* Inaccessible static: hasZAxis */ /* Inaccessible static: hasZAxis */
/* Inaccessible static: hasRZAxis */
/* Inaccessible static: hasPOV */ /* Inaccessible static: hasPOV */
/* Inaccessible static: hasSlider */
/* Inaccessible static: buttonName */
/* Inaccessible static: buttonMap */
/* Inaccessible static: initialized */
/* Inaccessible static: class_00024org_00024lwjgl_00024input_00024Controller */ /* Inaccessible static: class_00024org_00024lwjgl_00024input_00024Controller */
/* /*
* Class: org_lwjgl_input_Controller * Class: org_lwjgl_input_Controller
@ -39,9 +52,9 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Controller_nPoll
/* /*
* Class: org_lwjgl_input_Controller * Class: org_lwjgl_input_Controller
* Method: nCreate * Method: nCreate
* Signature: ()Z * Signature: ()V
*/ */
JNIEXPORT jboolean JNICALL Java_org_lwjgl_input_Controller_nCreate JNIEXPORT void JNICALL Java_org_lwjgl_input_Controller_nCreate
(JNIEnv *, jclass); (JNIEnv *, jclass);
/* /*

View File

@ -276,8 +276,8 @@ extern "C" {
/* Inaccessible static: character */ /* Inaccessible static: character */
/* Inaccessible static: key */ /* Inaccessible static: key */
/* Inaccessible static: state */ /* Inaccessible static: state */
/* Inaccessible static: class_000240 */ /* Inaccessible static: initialized */
/* Inaccessible static: class_000241 */ /* Inaccessible static: class_00024org_00024lwjgl_00024input_00024Keyboard */
/* /*
* Class: org_lwjgl_input_Keyboard * Class: org_lwjgl_input_Keyboard
* Method: initIDs * Method: initIDs
@ -289,9 +289,9 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_initIDs
/* /*
* Class: org_lwjgl_input_Keyboard * Class: org_lwjgl_input_Keyboard
* Method: nCreate * Method: nCreate
* Signature: ()Z * Signature: ()V
*/ */
JNIEXPORT jboolean JNICALL Java_org_lwjgl_input_Keyboard_nCreate JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nCreate
(JNIEnv *, jclass); (JNIEnv *, jclass);
/* /*
@ -321,9 +321,9 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_input_Keyboard_nRead
/* /*
* Class: org_lwjgl_input_Keyboard * Class: org_lwjgl_input_Keyboard
* Method: nEnableTranslation * Method: nEnableTranslation
* Signature: ()Z * Signature: ()V
*/ */
JNIEXPORT jboolean JNICALL Java_org_lwjgl_input_Keyboard_nEnableTranslation JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nEnableTranslation
(JNIEnv *, jclass); (JNIEnv *, jclass);
/* /*

View File

@ -24,6 +24,7 @@ extern "C" {
/* Inaccessible static: currentCursor */ /* Inaccessible static: currentCursor */
/* Inaccessible static: buttonName */ /* Inaccessible static: buttonName */
/* Inaccessible static: buttonMap */ /* Inaccessible static: buttonMap */
/* Inaccessible static: initialized */
/* Inaccessible static: class_00024org_00024lwjgl_00024input_00024Mouse */ /* Inaccessible static: class_00024org_00024lwjgl_00024input_00024Mouse */
/* /*
* Class: org_lwjgl_input_Mouse * Class: org_lwjgl_input_Mouse
@ -68,9 +69,9 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_initIDs
/* /*
* Class: org_lwjgl_input_Mouse * Class: org_lwjgl_input_Mouse
* Method: nCreate * Method: nCreate
* Signature: ()Z * Signature: ()V
*/ */
JNIEXPORT jboolean JNICALL Java_org_lwjgl_input_Mouse_nCreate JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nCreate
(JNIEnv *, jclass); (JNIEnv *, jclass);
/* /*

View File

@ -39,11 +39,11 @@
* @version $Revision$ * @version $Revision$
*/ */
#include <Carbon/Carbon.h>
#include <assert.h>
#include "org_lwjgl_input_Keyboard.h" #include "org_lwjgl_input_Keyboard.h"
KeyMap keyMap; #define KEYBOARD_BUFFER_SIZE 50
#define KEYBOARD_SIZE 256
#define KEY_EVENT_BACKLOG 40
/* /*
* Class: org_lwjgl_input_Keyboard * Class: org_lwjgl_input_Keyboard
@ -53,32 +53,16 @@ KeyMap keyMap;
JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_initIDs JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_initIDs
(JNIEnv * env, jclass clazz) (JNIEnv * env, jclass clazz)
{ {
// Get a global class instance, just to be sure
static jobject globalClassLock = NULL;
if (globalClassLock == NULL) {
globalClassLock = env->NewGlobalRef(clazz);
}
//fid_readBuffer = env->GetStaticFieldID(clazz, "readBuffer", "Ljava/nio/ByteBuffer;");
//fid_readBufferAddress = env->GetStaticFieldID(clazz, "readBufferAddress", "I");
} }
/* /*
* Class: org_lwjgl_input_Keyboard * Class: org_lwjgl_input_Keyboard
* Method: nCreate * Method: nCreate
* Signature: ()Z * Signature: ()Z
*/ */
JNIEXPORT jboolean JNICALL Java_org_lwjgl_input_Keyboard_nCreate JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nCreate
(JNIEnv * env, jclass clazz) (JNIEnv * env, jclass clazz)
{ {
#ifdef _DEBUG
printf("Creating OSX Carbon keyboard interface\n");
#endif
return JNI_TRUE;
} }
/* /*
@ -89,24 +73,16 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_input_Keyboard_nCreate
JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nDestroy JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nDestroy
(JNIEnv * env, jclass clazz) (JNIEnv * env, jclass clazz)
{ {
// no specific methodology for doing this in OSX input system
#ifdef _DEBUG
printf("Destroying OSX Carbon keyboard interface\n");
#endif
} }
/* /*
* Class: org_lwjgl_input_Keyboard * Class: org_lwjgl_input_Keyboard
* Method: nPoll * Method: nPoll
* Signature: (I)V * Signature: (I)V
*/ */
JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nPoll JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nPoll
(JNIEnv * env, jclass clazz, jint buf) (JNIEnv * env, jclass clazz, jobject buffer)
{ {
// get the keymap from the operating system's carbon layer
//
GetKeys( keyMap );
} }
/* /*
@ -114,10 +90,18 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nPoll
* Method: nRead * Method: nRead
* Signature: (I)V * Signature: (I)V
*/ */
JNIEXPORT jint JNICALL Java_org_lwjgl_input_Keyboard_nRead JNIEXPORT int JNICALL Java_org_lwjgl_input_Keyboard_nRead
(JNIEnv * env, jclass clazz, jint keys) (JNIEnv * env, jclass clazz)
{
/*
* Class: org_lwjgl_input_Keyboard
* Method: nEnableTranslation
* Signature: ()I
*/
JNIEXPORT jboolean JNICALL Java_org_lwjgl_input_Keyboard_nEnableTranslation
(JNIEnv *env, jclass clazz)
{ {
return 0;
} }
/* /*
@ -128,7 +112,14 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_input_Keyboard_nRead
JNIEXPORT jint JNICALL Java_org_lwjgl_input_Keyboard_nEnableBuffer JNIEXPORT jint JNICALL Java_org_lwjgl_input_Keyboard_nEnableBuffer
(JNIEnv * env, jclass clazz) (JNIEnv * env, jclass clazz)
{ {
printf("Buffered input is currently not available\n"); }
return JNI_FALSE; /*
* Class: org_lwjgl_input_Keyboard
* Method: nisStateKeySet
* Signature: (I)I
*/
JNIEXPORT jint JNICALL Java_org_lwjgl_input_Keyboard_nisStateKeySet(JNIEnv *env, jclass clazz, jint key)
{
return org_lwjgl_input_Keyboard_STATE_UNKNOWN;
} }

View File

@ -73,24 +73,22 @@ static void setWindowTitle(JNIEnv *env, jstring title_obj) {
} }
static pascal OSStatus doQuit(EventHandlerCallRef next_handler, EventRef event, void *user_data) { static pascal OSStatus doQuit(EventHandlerCallRef next_handler, EventRef event, void *user_data) {
printf("Close requested\n");
close_requested = true; close_requested = true;
return noErr; return noErr;
} }
static void registerEventHandlers(JNIEnv *env) { static void registerEventHandlers(JNIEnv *env) {
EventTypeSpec event_type; EventTypeSpec event_types[2];
OSStatus err; OSStatus err;
EventHandlerUPP handler_upp = NewEventHandlerUPP(doQuit); EventHandlerUPP handler_upp = NewEventHandlerUPP(doQuit);
event_type.eventClass = kEventClassWindow; event_types[0].eventClass = kEventClassWindow;
event_type.eventKind = kEventWindowClose; event_types[0].eventKind = kEventWindowClose;
err = InstallWindowEventHandler(win_ref, handler_upp, 1, &event_type, NULL, NULL); err = InstallWindowEventHandler(win_ref, handler_upp, 1, event_types, NULL, NULL);
DisposeEventHandlerUPP(handler_upp);
if (noErr != err) { if (noErr != err) {
DisposeEventHandlerUPP(handler_upp);
throwException(env, "Could not register window event handler"); throwException(env, "Could not register window event handler");
return; return;
} }
DisposeEventHandlerUPP(handler_upp);
} }
static void destroy(void) { static void destroy(void) {
@ -125,7 +123,6 @@ static bool createContext(JNIEnv *env, jint bpp, jint alpha, jint depth, jint st
throwException(env, "Could not create context"); throwException(env, "Could not create context");
return false; return false;
} }
//if (aglSetFullScreen(context, 800, 600, 85, 0) == GL_FALSE) {
if (aglSetDrawable(context, drawable) == GL_FALSE) { if (aglSetDrawable(context, drawable) == GL_FALSE) {
aglDestroyContext(context); aglDestroyContext(context);
throwException(env, "Could not attach context"); throwException(env, "Could not attach context");
@ -180,15 +177,21 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nCreate(JNIEnv *env, jclass
throwException(env, "Could not load gl function pointers"); throwException(env, "Could not load gl function pointers");
return; return;
} }
TransitionWindow(win_ref, kWindowZoomTransitionEffect, kWindowShowTransitionAction, NULL); ShowWindow(win_ref);
SelectWindow(win_ref); SelectWindow(win_ref);
} }
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_update JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_update
(JNIEnv *env, jclass clazz) (JNIEnv *env, jclass clazz)
{ {
RunApplicationEventLoop();
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_swapBuffers(JNIEnv * env, jclass clazz)
{
aglSwapBuffers(context); aglSwapBuffers(context);
} }
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nDestroy JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nDestroy
(JNIEnv *env, jclass clazz) (JNIEnv *env, jclass clazz)