You can subscribe to this list here.
2002 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(134) |
Sep
(52) |
Oct
(13) |
Nov
(342) |
Dec
(163) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2003 |
Jan
(44) |
Feb
(62) |
Mar
(158) |
Apr
(38) |
May
(70) |
Jun
(58) |
Jul
(104) |
Aug
(207) |
Sep
(83) |
Oct
(122) |
Nov
(23) |
Dec
(49) |
2004 |
Jan
(119) |
Feb
(132) |
Mar
(192) |
Apr
(140) |
May
(77) |
Jun
(74) |
Jul
(201) |
Aug
(63) |
Sep
(102) |
Oct
(70) |
Nov
(173) |
Dec
(78) |
2005 |
Jan
(174) |
Feb
(197) |
Mar
(105) |
Apr
(59) |
May
(77) |
Jun
(43) |
Jul
(21) |
Aug
(18) |
Sep
(47) |
Oct
(37) |
Nov
(74) |
Dec
(50) |
2006 |
Jan
(44) |
Feb
(19) |
Mar
(32) |
Apr
(24) |
May
(31) |
Jun
(55) |
Jul
(138) |
Aug
(28) |
Sep
(12) |
Oct
(41) |
Nov
(58) |
Dec
(24) |
2007 |
Jan
(28) |
Feb
(14) |
Mar
(10) |
Apr
(68) |
May
(30) |
Jun
(26) |
Jul
(18) |
Aug
(63) |
Sep
(19) |
Oct
(29) |
Nov
(20) |
Dec
(10) |
2008 |
Jan
(38) |
Feb
(7) |
Mar
(37) |
Apr
(120) |
May
(41) |
Jun
(36) |
Jul
(39) |
Aug
(24) |
Sep
(28) |
Oct
(30) |
Nov
(36) |
Dec
(75) |
2009 |
Jan
(46) |
Feb
(22) |
Mar
(50) |
Apr
(70) |
May
(134) |
Jun
(105) |
Jul
(75) |
Aug
(34) |
Sep
(38) |
Oct
(34) |
Nov
(19) |
Dec
(20) |
2010 |
Jan
(11) |
Feb
(20) |
Mar
(65) |
Apr
(83) |
May
(104) |
Jun
(73) |
Jul
(78) |
Aug
(57) |
Sep
(43) |
Oct
(35) |
Nov
(9) |
Dec
(4) |
2011 |
Jan
(21) |
Feb
(11) |
Mar
(18) |
Apr
(10) |
May
(18) |
Jun
(15) |
Jul
(48) |
Aug
(25) |
Sep
(17) |
Oct
(45) |
Nov
(15) |
Dec
(12) |
2012 |
Jan
(21) |
Feb
(9) |
Mar
(12) |
Apr
(9) |
May
(9) |
Jun
(5) |
Jul
(1) |
Aug
(10) |
Sep
(12) |
Oct
(1) |
Nov
(28) |
Dec
(5) |
2013 |
Jan
(4) |
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2014 |
Jan
|
Feb
(1) |
Mar
(1) |
Apr
|
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
2015 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
(2) |
Nov
|
Dec
|
2016 |
Jan
(2) |
Feb
(1) |
Mar
(1) |
Apr
(1) |
May
(2) |
Jun
|
Jul
(1) |
Aug
(2) |
Sep
|
Oct
|
Nov
(1) |
Dec
|
2017 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
S | M | T | W | T | F | S |
---|---|---|---|---|---|---|
|
|
|
|
1
|
2
|
3
(7) |
4
|
5
|
6
(2) |
7
(2) |
8
|
9
|
10
(3) |
11
|
12
(6) |
13
|
14
|
15
(5) |
16
(6) |
17
(1) |
18
(2) |
19
|
20
(1) |
21
|
22
(1) |
23
(3) |
24
|
25
|
26
(5) |
27
(3) |
28
(2) |
29
|
30
(6) |
|
From: <eli...@us...> - 2006-06-30 23:37:18
|
Revision: 2401 Author: elias_naur Date: 2006-06-30 16:37:12 -0700 (Fri, 30 Jun 2006) ViewCVS: http://svn.sourceforge.net/java-game-lib/?rev=2401&view=rev Log Message: ----------- Fixed KeyboardTest Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/test/input/KeyboardTest.java Modified: trunk/LWJGL/src/java/org/lwjgl/test/input/KeyboardTest.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/input/KeyboardTest.java 2006-06-30 23:05:28 UTC (rev 2400) +++ trunk/LWJGL/src/java/org/lwjgl/test/input/KeyboardTest.java 2006-06-30 23:37:12 UTC (rev 2401) @@ -54,10 +54,6 @@ /** Display mode selected */ private DisplayMode displayMode; - private boolean bufferedKeyboard; - private boolean translatedKeyboard; - private int bufferSize; - /** Creates a new instance of MouseTest */ public KeyboardTest() { } @@ -110,7 +106,6 @@ private void initializeOpenGL() { GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); - GLU.gluOrtho2D(0.0f, 640f, 0f, 480f); } public void executeTest() { @@ -158,24 +153,23 @@ if (Keyboard.getEventKey() == Keyboard.KEY_ESCAPE) { return; } + } + if (Keyboard.isKeyDown(Keyboard.KEY_RIGHT)) { + position.x += 1; + } - if (Keyboard.isKeyDown(Keyboard.KEY_RIGHT)) { - position.x += 1; - } + if (Keyboard.isKeyDown(Keyboard.KEY_LEFT)) { + position.x -= 1; + } - if (Keyboard.isKeyDown(Keyboard.KEY_LEFT)) { - position.x -= 1; - } + if (Keyboard.isKeyDown(Keyboard.KEY_UP)) { + position.y += 1; + } - if (Keyboard.isKeyDown(Keyboard.KEY_UP)) { - position.y += 1; - } - - if (Keyboard.isKeyDown(Keyboard.KEY_DOWN)) { - position.y -= 1; - } - + if (Keyboard.isKeyDown(Keyboard.KEY_DOWN)) { + position.y -= 1; } + if (count > 0) { System.out.println(); } @@ -207,7 +201,6 @@ GL11.glBegin(GL11.GL_POLYGON); { float color = 1.0f; - int buttonDown = 0; GL11.glColor3f(color, color, color); GL11.glVertex2f(position.x + 0.0f, position.y + 0.0f); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2006-06-30 23:05:35
|
Revision: 2400 Author: elias_naur Date: 2006-06-30 16:05:28 -0700 (Fri, 30 Jun 2006) ViewCVS: http://svn.sourceforge.net/java-game-lib/?rev=2400&view=rev Log Message: ----------- Reverted the widening of Keyboard.getEventCharacter Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/input/Keyboard.java Modified: trunk/LWJGL/src/java/org/lwjgl/input/Keyboard.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/input/Keyboard.java 2006-06-30 19:28:00 UTC (rev 2399) +++ trunk/LWJGL/src/java/org/lwjgl/input/Keyboard.java 2006-06-30 23:05:28 UTC (rev 2400) @@ -243,7 +243,7 @@ /** * The key events from the last read: a sequence of pairs of key number, * followed by state. The state is followed by - * a 4 byte java int representing the translated character. + * a 4 byte code point representing the translated character. */ private static IntBuffer readBuffer; @@ -442,8 +442,8 @@ /** * @return The character from the current event */ - public static int getEventCharacter() { - return eventCharacter; + public static char getEventCharacter() { + return (char)eventCharacter; } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2006-06-30 19:28:08
|
Revision: 2399 Author: elias_naur Date: 2006-06-30 12:28:00 -0700 (Fri, 30 Jun 2006) ViewCVS: http://svn.sourceforge.net/java-game-lib/?rev=2399&view=rev Log Message: ----------- Linux: native code cleanup Modified Paths: -------------- trunk/LWJGL/src/native/linux/org_lwjgl_input_Keyboard.c trunk/LWJGL/src/native/linux/org_lwjgl_opengl_Display.c Modified: trunk/LWJGL/src/native/linux/org_lwjgl_input_Keyboard.c =================================================================== --- trunk/LWJGL/src/native/linux/org_lwjgl_input_Keyboard.c 2006-06-30 19:08:20 UTC (rev 2398) +++ trunk/LWJGL/src/native/linux/org_lwjgl_input_Keyboard.c 2006-06-30 19:28:00 UTC (rev 2399) @@ -53,7 +53,6 @@ #include "org_lwjgl_opengl_LinuxDisplay.h" #define KEYBOARD_BUFFER_SIZE 50 -#define KEY_EVENT_BACKLOG 40 static jbyte key_buf[org_lwjgl_input_Keyboard_KEYBOARD_SIZE]; static int numlock_mask; Modified: trunk/LWJGL/src/native/linux/org_lwjgl_opengl_Display.c =================================================================== --- trunk/LWJGL/src/native/linux/org_lwjgl_opengl_Display.c 2006-06-30 19:08:20 UTC (rev 2398) +++ trunk/LWJGL/src/native/linux/org_lwjgl_opengl_Display.c 2006-06-30 19:28:00 UTC (rev 2399) @@ -242,7 +242,7 @@ } } -void handleMessages(JNIEnv *env, jint extension, jint window_mode, jobject saved_gamma, jobject current_gamma, jobject saved_mode, jobject current_mode) { +static void handleMessages(JNIEnv *env, jint extension, jint window_mode, jobject saved_gamma, jobject current_gamma, jobject saved_mode, jobject current_mode) { XEvent event; while (XPending(getDisplay()) > 0) { XNextEvent(getDisplay(), &event); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2006-06-30 19:08:26
|
Revision: 2398 Author: elias_naur Date: 2006-06-30 12:08:20 -0700 (Fri, 30 Jun 2006) ViewCVS: http://svn.sourceforge.net/java-game-lib/?rev=2398&view=rev Log Message: ----------- Windows: Fixed Display.setIcon memory leak Modified Paths: -------------- trunk/LWJGL/src/native/win32/org_lwjgl_opengl_Display.c Modified: trunk/LWJGL/src/native/win32/org_lwjgl_opengl_Display.c =================================================================== --- trunk/LWJGL/src/native/win32/org_lwjgl_opengl_Display.c 2006-06-30 18:56:37 UTC (rev 2397) +++ trunk/LWJGL/src/native/win32/org_lwjgl_opengl_Display.c 2006-06-30 19:08:20 UTC (rev 2398) @@ -49,6 +49,8 @@ #include "org_lwjgl_opengl_Win32Display.h" #include "context.h" +static HICON small_icon = NULL; +static HICON large_icon = NULL; static HWND display_hwnd = NULL; // Handle to the window static HDC display_hdc = NULL; // Device context static bool isFullScreen = false; // Whether we're fullscreen or not @@ -110,6 +112,20 @@ inAppActivate = false; } +static void freeLargeIcon() { + if (large_icon != NULL) { + DestroyIcon(large_icon); + large_icon = NULL; + } +} + +static void freeSmallIcon() { + if (small_icon != NULL) { + DestroyIcon(small_icon); + small_icon = NULL; + } +} + JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Win32Display_didMaximize (JNIEnv *env, jobject self) { jboolean result = did_maximize ? JNI_TRUE : JNI_FALSE; @@ -278,6 +294,8 @@ closeWindow(&display_hwnd, &display_hdc); if (isFullScreen) ClipCursor(NULL); + freeLargeIcon(); + freeSmallIcon(); } JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_switchDisplayMode(JNIEnv *env, jobject self, jobject mode) { @@ -461,10 +479,11 @@ { int *imgData = (int *)(*env)->GetDirectBufferAddress(env, iconBuffer); - HICON newIcon = createWindowIcon(env, imgData, 16, 16); + freeSmallIcon(); + small_icon = createWindowIcon(env, imgData, 16, 16); if (newIcon != NULL) { if (display_hwnd != NULL) { - SendMessage(display_hwnd, WM_SETICON, ICON_SMALL, (LPARAM) (newIcon)); + SendMessage(display_hwnd, WM_SETICON, ICON_SMALL, (LPARAM) (small_icon)); return 0; } @@ -478,10 +497,11 @@ { int *imgData = (int *)(*env)->GetDirectBufferAddress(env, iconBuffer); - HICON newIcon = createWindowIcon(env, imgData, 32, 32); + freeLargeIcon(); + large_icon = createWindowIcon(env, imgData, 32, 32); if (newIcon != NULL) { if (display_hwnd != NULL) { - SendMessage(display_hwnd, WM_SETICON, ICON_BIG, (LPARAM) (newIcon)); + SendMessage(display_hwnd, WM_SETICON, ICON_BIG, (LPARAM) (large_icon)); return 0; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2006-06-30 18:56:49
|
Revision: 2397 Author: elias_naur Date: 2006-06-30 11:56:37 -0700 (Fri, 30 Jun 2006) ViewCVS: http://svn.sourceforge.net/java-game-lib/?rev=2397&view=rev Log Message: ----------- Linux: Fixed Display.setIcon memory leak. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/DisplayImplementation.java trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java trunk/LWJGL/src/native/linux/org_lwjgl_opengl_Display.c Added Paths: ----------- trunk/LWJGL/src/java/org/lwjgl/test/applet/ Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/DisplayImplementation.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/DisplayImplementation.java 2006-06-30 16:47:46 UTC (rev 2396) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/DisplayImplementation.java 2006-06-30 18:56:37 UTC (rev 2397) @@ -242,5 +242,5 @@ * @param icons Array of icons in RGBA mode * @return number of icons used. */ - public int setIcon(ByteBuffer[] icons); + public int setIcon(ByteBuffer[] icons); } Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java 2006-06-30 16:47:46 UTC (rev 2396) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java 2006-06-30 18:56:37 UTC (rev 2397) @@ -692,7 +692,28 @@ throw new UnsupportedOperationException(); } + private static void convertIcon(ByteBuffer icon, int width, int height) { + int x = 0; + int y = 5; + byte r,g,b,a; + int depth = 4; + + for (y = 0; y < height; y++) { + for (x = 0; x < width; x++) { + r = icon.get((x*4)+(y*width*4)); + g = icon.get((x*4)+(y*width*4)+1); + b = icon.get((x*4)+(y*width*4)+2); + a = icon.get((x*4)+(y*width*4)+3); + + icon.put((x*depth)+(y*width*depth), b); // blue + icon.put((x*depth)+(y*width*depth)+1, g); // green + icon.put((x*depth)+(y*width*depth)+2, r); + icon.put((x*depth)+(y*width*depth)+3, a); + } + } + } + /** * Sets one or more icons for the Display. * <ul> @@ -700,23 +721,36 @@ * <li>Linux (and similar platforms) expect one 32x32 icon.</li> * <li>Mac OS X should be supplied one 128x128 icon</li> * </ul> - * The implementation will use the supplied ByteBuffers with image data in RGBA and perform any conversions nescesarry for the specific platform. + * The implementation will use the supplied ByteBuffers with image data in RGBA and perform any conversions necessary for the specific platform. * * @param icons Array of icons in RGBA mode * @return number of icons used. */ public int setIcon(ByteBuffer[] icons) { - for (int i=0;i<icons.length;i++) { - int size = icons[i].limit() / 4; - - if (((int) Math.sqrt(size)) == 32) { - nSetWindowIcon(icons[i]); - return 1; + lockAWT(); + try { + incDisplay(); + try { + for (int i=0;i<icons.length;i++) { + int size = icons[i].limit() / 4; + int dimension = (int)Math.sqrt(size); + if (dimension == 32) { + convertIcon(icons[i], dimension, dimension); + nSetWindowIcon(icons[i], icons[i].capacity(), dimension, dimension); + return 1; + } + } + return 0; + } finally { + decDisplay(); } + } catch (LWJGLException e) { + LWJGLUtil.log("Failed to set display icon: " + e); + return 0; + } finally { + unlockAWT(); } - - return 0; } - private static native int nSetWindowIcon(ByteBuffer icon); + private static native void nSetWindowIcon(ByteBuffer icon, int icons_size, int width, int height); } Modified: trunk/LWJGL/src/native/linux/org_lwjgl_opengl_Display.c =================================================================== --- trunk/LWJGL/src/native/linux/org_lwjgl_opengl_Display.c 2006-06-30 16:47:46 UTC (rev 2396) +++ trunk/LWJGL/src/native/linux/org_lwjgl_opengl_Display.c 2006-06-30 18:56:37 UTC (rev 2397) @@ -74,6 +74,7 @@ static Colormap cmap; static Window current_win; static int current_depth; +static Pixmap current_icon_pixmap; static Visual *current_visual; @@ -316,6 +317,13 @@ free(title); } +static void freeIconPixmap() { + if (current_icon_pixmap != 0) { + XFreePixmap(getDisplay(), current_icon_pixmap); + current_icon_pixmap = 0; + } +} + static void destroyWindow(JNIEnv *env) { if (glx_window != None) { lwjgl_glXDestroyWindow(getDisplay(), glx_window); @@ -323,6 +331,7 @@ } XDestroyWindow(getDisplay(), current_win); XFreeColormap(getDisplay(), cmap); + freeIconPixmap(); setRepeatMode(env, AutoRepeatModeDefault); } @@ -513,61 +522,53 @@ jawt.Unlock(env); } -static int setIcon(char *data,int width,int height) { +static void setIcon(JNIEnv *env, char *data, int icon_size, int width,int height) { XWMHints* win_hints; - int x = 0; - int y = 5; - char r,g,b,a; - - int depth = 4; - - for (y=0;y<height;y++) { - for (x=0;x<width;x++) { - r = data[(x*4)+(y*width*4)]; - g = data[(x*4)+(y*width*4)+1]; - b = data[(x*4)+(y*width*4)+2]; - a = data[(x*4)+(y*width*4)+3]; - - data[(x*depth)+(y*width*depth)] = b; // blue - data[(x*depth)+(y*width*depth)+1] = g; // green - data[(x*depth)+(y*width*depth)+2] = r; - data[(x*depth)+(y*width*depth)+3] = a; - } + freeIconPixmap(); + current_icon_pixmap = XCreatePixmap(getDisplay(), getCurrentWindow(), width, height, current_depth); + /* We need to copy the image data since XDestroyImage will also free its data buffer, which can't be allowed + * since the data buffer is managed by the jvm (it's the storage for the direct ByteBuffer) + */ + char *icon_copy = (char *)malloc(sizeof(*icon_copy)*icon_size); + + if (icon_copy == NULL) { + throwException(env, "malloc failed"); + return; } + memcpy(icon_copy, data, icon_size); + XImage *image = XCreateImage(getDisplay(), current_visual, current_depth, ZPixmap, 0, icon_copy, width, height, 32, 0); + if (image == NULL) { + freeIconPixmap(); + free(icon_copy); + throwException(env, "XCreateImage failed"); + return; + } - Pixmap icon_pixmap = XCreatePixmap(getDisplay(), getCurrentWindow(), width, height, current_depth); + GC gc = XCreateGC(getDisplay(), current_icon_pixmap, 0, NULL); + XPutImage(getDisplay(), current_icon_pixmap, gc, image, 0, 0, 0, 0, width, height); + XFreeGC(getDisplay(), gc); + XDestroyImage(image); + // We won't free icon_copy because it is freed by XDestroyImage - XImage *image = XCreateImage(getDisplay(), current_visual, current_depth, ZPixmap, 0, data, width, height, 32, 0); - - GC gc = XCreateGC(getDisplay(), icon_pixmap, 0, NULL); - - XPutImage(getDisplay(), icon_pixmap, gc, image, 0, 0, 0, 0, width, height); - win_hints = XAllocWMHints(); - if (!win_hints) { - return -1; + if (win_hints == NULL) { + throwException(env, "XAllocWMHints failed"); + return; } - win_hints->flags = IconPixmapHint; - win_hints->icon_pixmap = icon_pixmap; + win_hints->flags = IconPixmapHint; + win_hints->icon_pixmap = current_icon_pixmap; XSetWMHints(getDisplay(), getCurrentWindow(), win_hints); XFree(win_hints); XFlush(getDisplay()); - - return 0; } -JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nSetWindowIcon - (JNIEnv *env, jclass clazz, jobject iconBuffer) +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nSetWindowIcon + (JNIEnv *env, jclass clazz, jobject iconBuffer, jint icon_size, jint width, jint height) { char *imgData = (char *)(*env)->GetDirectBufferAddress(env, iconBuffer); - if (setIcon(imgData,32,32) == 0) - { - return 1; - } - - return 0; + setIcon(env, imgData, icon_size, width, height); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2006-06-30 16:48:17
|
Revision: 2396 Author: elias_naur Date: 2006-06-30 09:47:46 -0700 (Fri, 30 Jun 2006) ViewCVS: http://svn.sourceforge.net/java-game-lib/?rev=2396&view=rev Log Message: ----------- Linux: Made the native destructor my_fini static Modified Paths: -------------- trunk/LWJGL/src/native/linux/org_lwjgl_opengl_Display.c Modified: trunk/LWJGL/src/native/linux/org_lwjgl_opengl_Display.c =================================================================== --- trunk/LWJGL/src/native/linux/org_lwjgl_opengl_Display.c 2006-06-28 21:16:14 UTC (rev 2395) +++ trunk/LWJGL/src/native/linux/org_lwjgl_opengl_Display.c 2006-06-30 16:47:46 UTC (rev 2396) @@ -167,7 +167,7 @@ XCloseDisplay(disp); } -void __attribute__ ((destructor)) my_fini(void) { +static void __attribute__ ((destructor)) my_fini(void) { setRepeatMode(NULL, AutoRepeatModeDefault); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2006-06-28 21:16:41
|
Revision: 2395 Author: elias_naur Date: 2006-06-28 14:16:14 -0700 (Wed, 28 Jun 2006) ViewCVS: http://svn.sourceforge.net/java-game-lib/?rev=2395&view=rev Log Message: ----------- Windows: replace loadLibrary("jawt") with Toolkit.getDefaultToolkit() which is better and avoids classloader issues with multiple loaded natives. Additionally, getDefaultToolkit is not a privileged action, while loadLibrary is. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/Win32CanvasImplementation.java Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/Win32CanvasImplementation.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/Win32CanvasImplementation.java 2006-06-28 06:02:00 UTC (rev 2394) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/Win32CanvasImplementation.java 2006-06-28 21:16:14 UTC (rev 2395) @@ -33,6 +33,7 @@ import java.awt.GraphicsConfiguration; import java.awt.GraphicsDevice; +import java.awt.Toolkit; import java.security.PrivilegedAction; import java.security.AccessController; @@ -46,12 +47,8 @@ */ final class Win32CanvasImplementation implements AWTCanvasImplementation { static { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - System.loadLibrary("jawt"); - return null; - } - }); + // Make sure the awt stuff is properly initialised (the jawt library in particular) + Toolkit.getDefaultToolkit(); } public PeerInfo createPeerInfo(AWTGLCanvas canvas, PixelFormat pixel_format) throws LWJGLException { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2006-06-28 06:02:06
|
Revision: 2394 Author: elias_naur Date: 2006-06-27 23:02:00 -0700 (Tue, 27 Jun 2006) ViewCVS: http://svn.sourceforge.net/java-game-lib/?rev=2394&view=rev Log Message: ----------- Windows: Added missing doPrivileged around loadLibrary("jawt") Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/Win32CanvasImplementation.java Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/Win32CanvasImplementation.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/Win32CanvasImplementation.java 2006-06-27 15:41:53 UTC (rev 2393) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/Win32CanvasImplementation.java 2006-06-28 06:02:00 UTC (rev 2394) @@ -33,6 +33,8 @@ import java.awt.GraphicsConfiguration; import java.awt.GraphicsDevice; +import java.security.PrivilegedAction; +import java.security.AccessController; import org.lwjgl.LWJGLException; @@ -44,7 +46,12 @@ */ final class Win32CanvasImplementation implements AWTCanvasImplementation { static { - System.loadLibrary("jawt"); + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + System.loadLibrary("jawt"); + return null; + } + }); } public PeerInfo createPeerInfo(AWTGLCanvas canvas, PixelFormat pixel_format) throws LWJGLException { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2006-06-27 15:42:25
|
Revision: 2393 Author: elias_naur Date: 2006-06-27 08:41:53 -0700 (Tue, 27 Jun 2006) ViewCVS: http://svn.sourceforge.net/java-game-lib/?rev=2393&view=rev Log Message: ----------- Added an applet test (lwjgl from applets doesn't work yet). Modified Paths: -------------- trunk/LWJGL/build.xml Added Paths: ----------- trunk/LWJGL/applet/ trunk/LWJGL/applet/applet.html trunk/LWJGL/applet/lwjglkeystore Added: trunk/LWJGL/applet/applet.html =================================================================== --- trunk/LWJGL/applet/applet.html (rev 0) +++ trunk/LWJGL/applet/applet.html 2006-06-27 15:41:53 UTC (rev 2393) @@ -0,0 +1,5 @@ +<html> +<body> +<applet code="org.lwjgl.test.applet.LWJGLApplet" archive="lwjgl_applet.jar,lwjgl.jar" width="640" height="480"></applet> +</body> +</html> Added: trunk/LWJGL/applet/lwjglkeystore =================================================================== (Binary files differ) Property changes on: trunk/LWJGL/applet/lwjglkeystore ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Modified: trunk/LWJGL/build.xml =================================================================== --- trunk/LWJGL/build.xml 2006-06-27 12:57:04 UTC (rev 2392) +++ trunk/LWJGL/build.xml 2006-06-27 15:41:53 UTC (rev 2393) @@ -75,6 +75,12 @@ <include name="org/lwjgl/devil/**"/> </fileset> + <!-- Files to include in the lwjgl_applet.jar file --> + <fileset id="lwjgl_applet.fileset" dir="${lwjgl.bin}"> + <exclude name="**.*"/> + <include name="org/lwjgl/test/applet/**"/> + </fileset> + <!-- Files to make Javadoc from --> <fileset id="lwjgl.javadoc.fileset" dir="${lwjgl.src}"> <include name="**/*.java" /> @@ -334,8 +340,18 @@ <jar destfile="${lwjgl.temp}/jar/lwjgl_devil.jar" taskname="lwjgl_devil.jar"> <fileset refid="lwjgl_devil.fileset" /> </jar> + </target> + <target name="applet" depends="jars"> + <!-- Create lwjgl_applet.jar --> + <jar destfile="applet/lwjgl_applet.jar" taskname="lwjgl_applet.jar"> + <fileset refid="lwjgl_applet.fileset" /> + </jar> + <copy file="${lwjgl.lib}/lwjgl.jar" todir="applet"/> + <signjar jar="applet/lwjgl.jar" alias="lwjgl" keystore="applet/lwjglkeystore" storepass="123456"/> + </target> + <!-- Distributes files --> <target name="-distribute"> <delete> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2006-06-27 12:57:09
|
Revision: 2392 Author: elias_naur Date: 2006-06-27 05:57:04 -0700 (Tue, 27 Jun 2006) ViewCVS: http://svn.sourceforge.net/java-game-lib/?rev=2392&view=rev Log Message: ----------- Mac OS X: Made KeyboardEventQueue handle widened char types Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/KeyboardEventQueue.java Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/KeyboardEventQueue.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/KeyboardEventQueue.java 2006-06-27 11:11:37 UTC (rev 2391) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/KeyboardEventQueue.java 2006-06-27 12:57:04 UTC (rev 2392) @@ -257,7 +257,7 @@ key_down_buffer.position(old_position); } - private synchronized void handleKey(int key_code_mapped, byte state, char character) { + private synchronized void handleKey(int key_code_mapped, byte state, int character) { if ( character == KeyEvent.CHAR_UNDEFINED ) character = Keyboard.CHAR_NONE; /* Ignore repeating presses */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2006-06-27 11:11:52
|
Revision: 2391 Author: elias_naur Date: 2006-06-27 04:11:37 -0700 (Tue, 27 Jun 2006) ViewCVS: http://svn.sourceforge.net/java-game-lib/?rev=2391&view=rev Log Message: ----------- Windows: Generalize getMin/MaxCursorSize to one native GetSystemMetrics Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/Win32Display.java trunk/LWJGL/src/native/win32/org_lwjgl_input_Cursor.c trunk/LWJGL/src/native/win32/org_lwjgl_opengl_Display.c Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/Win32Display.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/Win32Display.java 2006-06-26 14:28:52 UTC (rev 2390) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/Win32Display.java 2006-06-27 11:11:37 UTC (rev 2391) @@ -85,6 +85,8 @@ private final static int SC_CONTEXTHELP = 0xF180; private final static int SC_SEPARATOR = 0xF00F; + private final static int SM_CXCURSOR = 13; + private static Win32DisplayPeerInfo peer_info; private static WindowsKeyboard keyboard; @@ -221,9 +223,16 @@ public native void setNativeCursor(Object handle) throws LWJGLException; - public native int getMinCursorSize(); - public native int getMaxCursorSize(); + public int getMinCursorSize() { + return getSystemMetrics(SM_CXCURSOR); + } + public int getMaxCursorSize() { + return getSystemMetrics(SM_CXCURSOR); + } + + public native int getSystemMetrics(int index); + private static native long getDllInstance(); private static native long getHwnd(); Modified: trunk/LWJGL/src/native/win32/org_lwjgl_input_Cursor.c =================================================================== --- trunk/LWJGL/src/native/win32/org_lwjgl_input_Cursor.c 2006-06-26 14:28:52 UTC (rev 2390) +++ trunk/LWJGL/src/native/win32/org_lwjgl_input_Cursor.c 2006-06-27 11:11:37 UTC (rev 2391) @@ -44,19 +44,6 @@ #include "org_lwjgl_opengl_Win32Display.h" #include "common_tools.h" -JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Win32Display_getMaxCursorSize -(JNIEnv *env, jobject self) -{ - return GetSystemMetrics(SM_CXCURSOR); -} - -JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Win32Display_getMinCursorSize -(JNIEnv *env, jobject self) -{ - return GetSystemMetrics(SM_CXCURSOR); -} - - JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_Win32Display_nCreateCursor (JNIEnv *env, jobject self, jint width, jint height, jint x_hotspot, jint y_hotspot, jint num_images, jobject image_buffer, jint images_offset, jobject delay_buffer, jint delays_offset) { Modified: trunk/LWJGL/src/native/win32/org_lwjgl_opengl_Display.c =================================================================== --- trunk/LWJGL/src/native/win32/org_lwjgl_opengl_Display.c 2006-06-26 14:28:52 UTC (rev 2390) +++ trunk/LWJGL/src/native/win32/org_lwjgl_opengl_Display.c 2006-06-27 11:11:37 UTC (rev 2391) @@ -548,3 +548,8 @@ GetClientRect(hwnd, &clientRect); return (clientRect.bottom - clientRect.top) - 1 - y; } + +JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Win32Display_getSystemMetrics(JNIEnv *env, jclass unused, jint index) { + return GetSystemMetrics(index); +} + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2006-06-26 14:28:59
|
Revision: 2390 Author: elias_naur Date: 2006-06-26 07:28:52 -0700 (Mon, 26 Jun 2006) ViewCVS: http://svn.sourceforge.net/java-game-lib/?rev=2390&view=rev Log Message: ----------- Windows: Moved isUndecorated from global to local variable Modified Paths: -------------- trunk/LWJGL/src/native/win32/org_lwjgl_opengl_Display.c Modified: trunk/LWJGL/src/native/win32/org_lwjgl_opengl_Display.c =================================================================== --- trunk/LWJGL/src/native/win32/org_lwjgl_opengl_Display.c 2006-06-26 14:24:45 UTC (rev 2389) +++ trunk/LWJGL/src/native/win32/org_lwjgl_opengl_Display.c 2006-06-26 14:28:52 UTC (rev 2390) @@ -54,7 +54,6 @@ static bool isFullScreen = false; // Whether we're fullscreen or not static bool isMinimized = false; // Whether we're minimized or not static bool isFocused = false; // whether we're focused or not -static bool isUndecorated = false; // Whether we're undecorated or not static bool did_maximize = false; // A flag to tell when a window // has recovered from minimized @@ -248,6 +247,7 @@ int width = (*env)->GetIntField(env, mode, fid_width); int height = (*env)->GetIntField(env, mode, fid_height); BOOL result; + bool isUndecorated; // Whether we're undecorated or not static bool oneShotInitialised = false; if (!oneShotInitialised) { if (!registerWindow(lwjglWindowProc, WINDOWCLASSNAME)) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2006-06-26 14:25:18
|
Revision: 2389 Author: elias_naur Date: 2006-06-26 07:24:45 -0700 (Mon, 26 Jun 2006) ViewCVS: http://svn.sourceforge.net/java-game-lib/?rev=2389&view=rev Log Message: ----------- Windows: Moved is_dirty from native to java Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/Win32Display.java trunk/LWJGL/src/native/win32/org_lwjgl_opengl_Display.c Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/Win32Display.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/Win32Display.java 2006-06-26 14:13:57 UTC (rev 2388) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/Win32Display.java 2006-06-26 14:24:45 UTC (rev 2389) @@ -62,6 +62,7 @@ private final static int WM_QUIT = 0x0012; private final static int WM_SYSCOMMAND = 0x0112; + private final static int WM_PAINT = 0x000F; private final static int SC_SIZE = 0xF000; private final static int SC_MOVE = 0xF010; @@ -90,9 +91,11 @@ private static WindowsMouse mouse; private static boolean close_requested; + private static boolean is_dirty; public void createWindow(DisplayMode mode, boolean fullscreen, int x, int y) throws LWJGLException { close_requested = false; + is_dirty = false; nCreateWindow(mode, fullscreen, x, y); peer_info.initDC(); } @@ -136,14 +139,22 @@ private native String nGetVersion(String driver); public native DisplayMode init() throws LWJGLException; public native void setTitle(String title); + public boolean isCloseRequested() { boolean saved = close_requested; close_requested = false; return saved; } + public native boolean isVisible(); public native boolean isActive(); - public native boolean isDirty(); + + public boolean isDirty() { + boolean saved = is_dirty; + is_dirty = false; + return saved; + } + public PeerInfo createPeerInfo(PixelFormat pixel_format) throws LWJGLException { peer_info = new Win32DisplayPeerInfo(pixel_format); return peer_info; @@ -381,6 +392,9 @@ break; } return false; + case WM_PAINT: + is_dirty = true; + return false; default: return false; } Modified: trunk/LWJGL/src/native/win32/org_lwjgl_opengl_Display.c =================================================================== --- trunk/LWJGL/src/native/win32/org_lwjgl_opengl_Display.c 2006-06-26 14:13:57 UTC (rev 2388) +++ trunk/LWJGL/src/native/win32/org_lwjgl_opengl_Display.c 2006-06-26 14:24:45 UTC (rev 2389) @@ -54,7 +54,6 @@ static bool isFullScreen = false; // Whether we're fullscreen or not static bool isMinimized = false; // Whether we're minimized or not static bool isFocused = false; // whether we're focused or not -static bool isDirty = false; // Whether we're dirty or not static bool isUndecorated = false; // Whether we're undecorated or not static bool did_maximize = false; // A flag to tell when a window // has recovered from minimized @@ -156,10 +155,6 @@ break; } break; - case WM_PAINT: - { - isDirty = true; - } } env = (JNIEnv *)(LONG_PTR)GetWindowLongPtr(hWnd, GWLP_USERDATA); @@ -232,14 +227,6 @@ handleMessages(env); } - -JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Win32Display_isDirty - (JNIEnv *env, jobject self) { - bool result = isDirty; - isDirty = false; - return result ? JNI_TRUE : JNI_FALSE; -} - JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Win32Display_isVisible (JNIEnv *env, jobject self) { return isMinimized ? JNI_FALSE : JNI_TRUE; @@ -272,7 +259,6 @@ isMinimized = false; isFocused = false; - isDirty = true; isFullScreen = fullscreen == JNI_TRUE; isUndecorated = getBooleanProperty(env, "org.lwjgl.opengl.Window.undecorated"); display_hwnd = createWindow(WINDOWCLASSNAME, x, y, width, height, isFullScreen, isUndecorated); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2006-06-26 14:23:39
|
Revision: 2388 Author: elias_naur Date: 2006-06-26 07:13:57 -0700 (Mon, 26 Jun 2006) ViewCVS: http://svn.sourceforge.net/java-game-lib/?rev=2388&view=rev Log Message: ----------- Widened Keyboard.getEventCharacter() return type from char to int to accomodate 32 bit characters. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/input/Keyboard.java Modified: trunk/LWJGL/src/java/org/lwjgl/input/Keyboard.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/input/Keyboard.java 2006-06-26 14:05:42 UTC (rev 2387) +++ trunk/LWJGL/src/java/org/lwjgl/input/Keyboard.java 2006-06-26 14:13:57 UTC (rev 2388) @@ -59,7 +59,7 @@ * The special character meaning that no * character was translated for the event. */ - public static final char CHAR_NONE = '\0'; + public static final int CHAR_NONE = '\0'; /** * The special keycode meaning that only the @@ -243,12 +243,12 @@ /** * The key events from the last read: a sequence of pairs of key number, * followed by state. The state is followed by - * a 2 byte java char representing the translated character. + * a 4 byte java int representing the translated character. */ private static IntBuffer readBuffer; /** The current keyboard character being examined */ - private static char eventCharacter; + private static int eventCharacter; /** The current keyboard event key being examined */ private static int eventKey; @@ -425,8 +425,7 @@ if (readBuffer.hasRemaining()) { eventKey = readBuffer.get() & 0xFF; eventState = readBuffer.get() != 0; - int eventCharacterInt = readBuffer.get() & 0xFFFF; - eventCharacter = (char)eventCharacterInt; + eventCharacter = readBuffer.get(); return true; } else { return false; @@ -443,7 +442,7 @@ /** * @return The character from the current event */ - public static char getEventCharacter() { + public static int getEventCharacter() { return eventCharacter; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2006-06-26 14:05:52
|
Revision: 2387 Author: elias_naur Date: 2006-06-26 07:05:42 -0700 (Mon, 26 Jun 2006) ViewCVS: http://svn.sourceforge.net/java-game-lib/?rev=2387&view=rev Log Message: ----------- Windows: moved closerequested from native to java Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/Win32Display.java trunk/LWJGL/src/native/win32/org_lwjgl_opengl_Display.c Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/Win32Display.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/Win32Display.java 2006-06-26 13:50:48 UTC (rev 2386) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/Win32Display.java 2006-06-26 14:05:42 UTC (rev 2387) @@ -60,12 +60,39 @@ private final static int WM_MBUTTONDBLCLK = 0x0209; private final static int WM_MOUSEWHEEL = 0x020A; + private final static int WM_QUIT = 0x0012; + private final static int WM_SYSCOMMAND = 0x0112; + + private final static int SC_SIZE = 0xF000; + private final static int SC_MOVE = 0xF010; + private final static int SC_MINIMIZE = 0xF020; + private final static int SC_MAXIMIZE = 0xF030; + private final static int SC_NEXTWINDOW = 0xF040; + private final static int SC_PREVWINDOW = 0xF050; + private final static int SC_CLOSE = 0xF060; + private final static int SC_VSCROLL = 0xF070; + private final static int SC_HSCROLL = 0xF080; + private final static int SC_MOUSEMENU = 0xF090; + private final static int SC_KEYMENU = 0xF100; + private final static int SC_ARRANGE = 0xF110; + private final static int SC_RESTORE = 0xF120; + private final static int SC_TASKLIST = 0xF130; + private final static int SC_SCREENSAVE = 0xF140; + private final static int SC_HOTKEY = 0xF150; + private final static int SC_DEFAULT = 0xF160; + private final static int SC_MONITORPOWER = 0xF170; + private final static int SC_CONTEXTHELP = 0xF180; + private final static int SC_SEPARATOR = 0xF00F; + private static Win32DisplayPeerInfo peer_info; private static WindowsKeyboard keyboard; private static WindowsMouse mouse; + private static boolean close_requested; + public void createWindow(DisplayMode mode, boolean fullscreen, int x, int y) throws LWJGLException { + close_requested = false; nCreateWindow(mode, fullscreen, x, y); peer_info.initDC(); } @@ -109,7 +136,11 @@ private native String nGetVersion(String driver); public native DisplayMode init() throws LWJGLException; public native void setTitle(String title); - public native boolean isCloseRequested(); + public boolean isCloseRequested() { + boolean saved = close_requested; + close_requested = false; + return saved; + } public native boolean isVisible(); public native boolean isActive(); public native boolean isDirty(); @@ -333,6 +364,23 @@ case WM_MBUTTONUP: handleMouseButton(2, 0); return true; + case WM_QUIT: + close_requested = true; + return true; + case WM_SYSCOMMAND: + switch ((int)wParam) { + case SC_KEYMENU: + case SC_MOUSEMENU: + case SC_SCREENSAVE: + case SC_MONITORPOWER: + return true; + case SC_CLOSE: + close_requested = true; + return true; + default: + break; + } + return false; default: return false; } Modified: trunk/LWJGL/src/native/win32/org_lwjgl_opengl_Display.c =================================================================== --- trunk/LWJGL/src/native/win32/org_lwjgl_opengl_Display.c 2006-06-26 13:50:48 UTC (rev 2386) +++ trunk/LWJGL/src/native/win32/org_lwjgl_opengl_Display.c 2006-06-26 14:05:42 UTC (rev 2387) @@ -59,8 +59,6 @@ static bool did_maximize = false; // A flag to tell when a window // has recovered from minimized -static bool closerequested; - #define WINDOWCLASSNAME "LWJGL" bool getCurrentFullscreen() { @@ -136,24 +134,6 @@ setupCursorClipping(); switch (msg) { // disable screen saver and monitor power down messages which wreak havoc - case WM_SYSCOMMAND: - { - switch (wParam) { - case SC_KEYMENU: - case SC_MOUSEMENU: - // Ignore system menu retrieval - case SC_SCREENSAVE: - case SC_MONITORPOWER: - return 0L; - break; - case SC_CLOSE: - closerequested = true; - //don't continue processing this command since this - //would shutdown the window, which the application might not want to - return 0L; - } - } - break; case WM_ACTIVATE: switch (wParam) { case WA_ACTIVE: @@ -176,11 +156,6 @@ break; } break; - case WM_QUIT: - { - closerequested = true; - return 0L; - } case WM_PAINT: { isDirty = true; @@ -270,13 +245,6 @@ return isMinimized ? JNI_FALSE : JNI_TRUE; } -JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Win32Display_isCloseRequested - (JNIEnv *env, jobject self) { - bool saved = closerequested; - closerequested = false; - return saved; -} - JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Win32Display_isActive (JNIEnv *env, jobject self) { return isFocused; @@ -302,7 +270,6 @@ oneShotInitialised = true; } - closerequested = false; isMinimized = false; isFocused = false; isDirty = true; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2006-06-26 13:52:08
|
Revision: 2386 Author: elias_naur Date: 2006-06-26 06:50:48 -0700 (Mon, 26 Jun 2006) ViewCVS: http://svn.sourceforge.net/java-game-lib/?rev=2386&view=rev Log Message: ----------- Windows: LWJGL didn't work well with jinput, but compatibility could be greatly improved if LWJGL used DirectInput 8 (like jinput). This can't be done unconditionally, since we need the DX3 support for older versions of windows. So, I've moved most Mouse and Keyboard stuff from native to java side and generalized DirectInput access through an abstract base class, with two concrete subclasses, one for dx3 and one for dx8. Modified Paths: -------------- trunk/LWJGL/build.xml trunk/LWJGL/platform_build/win32_ms_cmdline/build.bat trunk/LWJGL/src/java/org/lwjgl/BufferUtils.java trunk/LWJGL/src/java/org/lwjgl/input/Keyboard.java trunk/LWJGL/src/java/org/lwjgl/input/Mouse.java trunk/LWJGL/src/java/org/lwjgl/opengl/DisplayImplementation.java trunk/LWJGL/src/java/org/lwjgl/opengl/EventQueue.java trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXDisplay.java trunk/LWJGL/src/java/org/lwjgl/opengl/Win32Display.java trunk/LWJGL/src/native/common/common_tools.c trunk/LWJGL/src/native/common/common_tools.h trunk/LWJGL/src/native/win32/LWJGL.c trunk/LWJGL/src/native/win32/Window.h trunk/LWJGL/src/native/win32/org_lwjgl_opengl_Display.c Added Paths: ----------- trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInput.java trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInput3.java trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInput8.java trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInputDevice.java trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInputDevice3.java trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInputDevice8.java trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInputDeviceObjectCallback.java trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsKeyboard.java trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsMouse.java trunk/LWJGL/src/native/win32/dinputhelper.c trunk/LWJGL/src/native/win32/dinputhelper.h trunk/LWJGL/src/native/win32/org_lwjgl_opengl_WindowsDirectInput3.c trunk/LWJGL/src/native/win32/org_lwjgl_opengl_WindowsDirectInput8.c trunk/LWJGL/src/native/win32/org_lwjgl_opengl_WindowsDirectInputDevice3.c trunk/LWJGL/src/native/win32/org_lwjgl_opengl_WindowsDirectInputDevice8.c trunk/LWJGL/src/native/win32/org_lwjgl_opengl_WindowsKeyboard.c Removed Paths: ------------- trunk/LWJGL/src/native/win32/org_lwjgl_input_Keyboard.c trunk/LWJGL/src/native/win32/org_lwjgl_input_Mouse.c Modified: trunk/LWJGL/build.xml =================================================================== --- trunk/LWJGL/build.xml 2006-06-23 16:45:21 UTC (rev 2385) +++ trunk/LWJGL/build.xml 2006-06-26 13:50:48 UTC (rev 2386) @@ -420,6 +420,11 @@ </javah> <javah classpath="${lwjgl.bin}" destdir="${lwjgl.src.native}/win32" force="yes"> + <class name="org.lwjgl.opengl.WindowsKeyboard" /> + <class name="org.lwjgl.opengl.WindowsDirectInput8" /> + <class name="org.lwjgl.opengl.WindowsDirectInputDevice8" /> + <class name="org.lwjgl.opengl.WindowsDirectInput3" /> + <class name="org.lwjgl.opengl.WindowsDirectInputDevice3" /> <class name="org.lwjgl.opengl.Win32PbufferPeerInfo" /> <class name="org.lwjgl.opengl.Win32Display" /> <class name="org.lwjgl.opengl.Win32Registry" /> Modified: trunk/LWJGL/platform_build/win32_ms_cmdline/build.bat =================================================================== --- trunk/LWJGL/platform_build/win32_ms_cmdline/build.bat 2006-06-23 16:45:21 UTC (rev 2385) +++ trunk/LWJGL/platform_build/win32_ms_cmdline/build.bat 2006-06-26 13:50:48 UTC (rev 2386) @@ -9,7 +9,7 @@ set COPTIONS=/Wp64 /I"%CHOME%\include" /I"%PLTSDKHOME%\include" /I"%DXSDK_DIR%\include" /I"%JAVA_HOME%\include" /I"%JAVA_HOME%\include\win32" /I"%ALHOME%\include" /I"..\..\src\native\common" /Ox /Ob2 /Oi /Ot /Oy /FD /EHsc /MT /Gy /W2 /nologo /c /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_USRDLL" /D "LWJGL_EXPORTS" /D "_WINDLL" set LINKEROPTS=/link /LIBPATH:"%JAVA_HOME%\lib" /LIBPATH:"%ALHOME%\libs" /LIBPATH:"%DXSDK_DIR%\Lib\x86" /LIBPATH:"%PLTSDKHOME%\Lib" /LIBPATH:"%CHOME%\Lib" /SUBSYSTEM:WINDOWS /OPT:REF /OPT:ICF /MACHINE:X86 /NOLOGO /DLL /DELAYLOAD:jawt.dll -set LIBS=Kernel32.lib dinput.lib dxguid.lib OpenGL32.Lib Version.lib user32.lib Gdi32.lib Advapi32.lib jawt.lib delayimp.lib winmm.lib +set LIBS=Kernel32.lib ole32.lib dinput.lib dxguid.lib OpenGL32.Lib Version.lib user32.lib Gdi32.lib Advapi32.lib jawt.lib delayimp.lib winmm.lib for %%x in (..\..\src\native\win32\*.c) do cl %COPTIONS% %%x for %%x in (..\..\src\native\common\*.c) do cl %COPTIONS% %%x Modified: trunk/LWJGL/src/java/org/lwjgl/BufferUtils.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/BufferUtils.java 2006-06-23 16:45:21 UTC (rev 2385) +++ trunk/LWJGL/src/java/org/lwjgl/BufferUtils.java 2006-06-26 13:50:48 UTC (rev 2386) @@ -71,6 +71,16 @@ } /** + * Construct a direct native-order charbuffer with the specified number + * of elements. + * @param size The size, in chars + * @return an CharBuffer + */ + public static CharBuffer createCharBuffer(int size) { + return createByteBuffer(size << 1).asCharBuffer(); + } + + /** * Construct a direct native-order intbuffer with the specified number * of elements. * @param size The size, in ints @@ -81,10 +91,10 @@ } /** - * Construct a direct native-order intbuffer with the specified number + * Construct a direct native-order longbuffer with the specified number * of elements. - * @param size The size, in ints - * @return an IntBuffer + * @param size The size, in longs + * @return an LongBuffer */ public static LongBuffer createLongBuffer(int size) { return createByteBuffer(size << 3).asLongBuffer(); Modified: trunk/LWJGL/src/java/org/lwjgl/input/Keyboard.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/input/Keyboard.java 2006-06-23 16:45:21 UTC (rev 2385) +++ trunk/LWJGL/src/java/org/lwjgl/input/Keyboard.java 2006-06-26 13:50:48 UTC (rev 2386) @@ -348,7 +348,7 @@ private static void read() { readBuffer.compact(); - int numEvents = Display.getImplementation().readKeyboard(readBuffer, readBuffer.position()); + int numEvents = Display.getImplementation().readKeyboard(readBuffer); readBuffer.position(readBuffer.position() + numEvents*EVENT_SIZE); readBuffer.flip(); } Modified: trunk/LWJGL/src/java/org/lwjgl/input/Mouse.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/input/Mouse.java 2006-06-23 16:45:21 UTC (rev 2385) +++ trunk/LWJGL/src/java/org/lwjgl/input/Mouse.java 2006-06-26 13:50:48 UTC (rev 2386) @@ -306,7 +306,7 @@ private static void read() { readBuffer.compact(); - int numEvents = Display.getImplementation().readMouse(readBuffer, readBuffer.position()); + int numEvents = Display.getImplementation().readMouse(readBuffer); readBuffer.position(readBuffer.position() + numEvents * EVENT_SIZE); readBuffer.flip(); } Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/DisplayImplementation.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/DisplayImplementation.java 2006-06-23 16:45:21 UTC (rev 2385) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/DisplayImplementation.java 2006-06-26 13:50:48 UTC (rev 2386) @@ -153,9 +153,8 @@ * * @return the total number of events read. */ - int readMouse(IntBuffer buffer, int buffer_position); + int readMouse(IntBuffer buffer); - void grabMouse(boolean grab); /** @@ -201,7 +200,7 @@ * Method to read the keyboard buffer * @return the total number of events read. */ - int readKeyboard(IntBuffer buffer, int buffer_position); + int readKeyboard(IntBuffer buffer); // int isStateKeySet(int key); Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/EventQueue.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/EventQueue.java 2006-06-23 16:45:21 UTC (rev 2385) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/EventQueue.java 2006-06-26 13:50:48 UTC (rev 2386) @@ -40,7 +40,7 @@ import java.nio.ByteBuffer; import java.nio.IntBuffer; -abstract class EventQueue { +class EventQueue { private static final int QUEUE_SIZE = 200; Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java 2006-06-23 16:45:21 UTC (rev 2385) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java 2006-06-26 13:50:48 UTC (rev 2386) @@ -513,10 +513,10 @@ } private static native void nPollMouse(IntBuffer coord_buffer, ByteBuffer buttons); - public int readMouse(IntBuffer buffer, int buffer_position) { + public int readMouse(IntBuffer buffer) { update(); lockAWT(); - int count = nReadMouse(buffer, buffer_position); + int count = nReadMouse(buffer, buffer.position()); unlockAWT(); return count; } @@ -616,10 +616,10 @@ } private static native void nPollKeyboard(ByteBuffer keyDownBuffer); - public int readKeyboard(IntBuffer buffer, int buffer_position) { + public int readKeyboard(IntBuffer buffer) { update(); lockAWT(); - int count = nReadKeyboard(buffer, buffer_position); + int count = nReadKeyboard(buffer, buffer.position()); unlockAWT(); return count; } Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXDisplay.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXDisplay.java 2006-06-23 16:45:21 UTC (rev 2385) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXDisplay.java 2006-06-26 13:50:48 UTC (rev 2386) @@ -321,8 +321,7 @@ mouse_queue.poll(coord_buffer, buttons_buffer); } - public int readMouse(IntBuffer buffer, int buffer_position) { - assert buffer_position == buffer.position(); + public int readMouse(IntBuffer buffer) { return mouse_queue.copyEvents(buffer); } @@ -408,8 +407,7 @@ keyboard_queue.poll(keyDownBuffer); } - public int readKeyboard(IntBuffer buffer, int buffer_position) { - assert buffer_position == buffer.position(); + public int readKeyboard(IntBuffer buffer) { return keyboard_queue.copyEvents(buffer); } Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/Win32Display.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/Win32Display.java 2006-06-23 16:45:21 UTC (rev 2385) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/Win32Display.java 2006-06-26 13:50:48 UTC (rev 2386) @@ -48,9 +48,23 @@ final class Win32Display implements DisplayImplementation { private final static int GAMMA_LENGTH = 256; + private final static int WM_MOUSEMOVE = 0x0200; + private final static int WM_LBUTTONDOWN = 0x0201; + private final static int WM_LBUTTONUP = 0x0202; + private final static int WM_LBUTTONDBLCLK = 0x0203; + private final static int WM_RBUTTONDOWN = 0x0204; + private final static int WM_RBUTTONUP = 0x0205; + private final static int WM_RBUTTONDBLCLK = 0x0206; + private final static int WM_MBUTTONDOWN = 0x0207; + private final static int WM_MBUTTONUP = 0x0208; + private final static int WM_MBUTTONDBLCLK = 0x0209; + private final static int WM_MOUSEWHEEL = 0x020A; private static Win32DisplayPeerInfo peer_info; + private static WindowsKeyboard keyboard; + private static WindowsMouse mouse; + public void createWindow(DisplayMode mode, boolean fullscreen, int x, int y) throws LWJGLException { nCreateWindow(mode, fullscreen, x, y); peer_info.initDC(); @@ -126,47 +140,70 @@ public native DisplayMode[] getAvailableDisplayModes() throws LWJGLException; /* Mouse */ - public native boolean hasWheel(); - public native int getButtonCount(); - public native void createMouse() throws LWJGLException; - public native void destroyMouse(); + public boolean hasWheel() { + return mouse.hasWheel(); + } + + public int getButtonCount() { + return mouse.getButtonCount(); + } + + public void createMouse() throws LWJGLException { + mouse = new WindowsMouse(createDirectInput(), getHwnd()); + } + + public void destroyMouse() { + mouse.destroy(); + mouse = null; + } + public void pollMouse(IntBuffer coord_buffer, ByteBuffer buttons) { update(); - nPollMouse(coord_buffer, buttons); + mouse.poll(coord_buffer, buttons); } - private native void nPollMouse(IntBuffer coord_buffer, ByteBuffer buttons); - public int readMouse(IntBuffer buffer, int buffer_position) { + public int readMouse(IntBuffer buffer) { update(); - return nReadMouse(buffer, buffer_position); + return mouse.read(buffer); } - private native int nReadMouse(IntBuffer buffer, int buffer_position); - public native void grabMouse(boolean grab); + public void grabMouse(boolean grab) { + mouse.grab(grab); + } + public int getNativeCursorCapabilities() { return Cursor.CURSOR_ONE_BIT_TRANSPARENCY; } public native void setCursorPosition(int x, int y); + public native void setNativeCursor(Object handle) throws LWJGLException; + public native int getMinCursorSize(); public native int getMaxCursorSize(); + private static native long getDllInstance(); + private static native long getHwnd(); + /* Keyboard */ - public native void createKeyboard() throws LWJGLException; - public native void destroyKeyboard(); + public void createKeyboard() throws LWJGLException { + keyboard = new WindowsKeyboard(createDirectInput(), getHwnd()); + } + + public void destroyKeyboard() { + keyboard.destroy(); + keyboard = null; + } public void pollKeyboard(ByteBuffer keyDownBuffer) { update(); - nPollKeyboard(keyDownBuffer); + keyboard.poll(keyDownBuffer); } - private native void nPollKeyboard(ByteBuffer keyDownBuffer); - public int readKeyboard(IntBuffer buffer, int buffer_position) { + public int readKeyboard(IntBuffer buffer) { update(); - return nReadKeyboard(buffer, buffer_position); + return keyboard.read(buffer); } - private native int nReadKeyboard(IntBuffer buffer, int buffer_position); // public native int isStateKeySet(int key); @@ -249,4 +286,64 @@ private static native int nSetWindowIcon16(IntBuffer icon); private static native int nSetWindowIcon32(IntBuffer icon); + + private static void handleMouseButton(int button, int state) { + if (mouse != null) + mouse.handleMouseButton(button, state); + } + + private static void handleMouseMoved(int x, int y) { + if (mouse != null) + mouse.handleMouseMoved(x, y); + } + + private static void handleMouseScrolled(int amount) { + if (mouse != null) + mouse.handleMouseScrolled(amount); + } + + private static native int transformY(long hwnd, int y); + + private static boolean handleMessage(long hwnd, int msg, long wParam, long lParam) { + switch (msg) { + case WM_MOUSEMOVE: + int xPos = (int)(short)(lParam & 0xFFFF); + int yPos = transformY(getHwnd(), (int)(short)((lParam >> 16) & 0xFFFF)); + handleMouseMoved(xPos, yPos); + return true; + case WM_MOUSEWHEEL: + int dwheel = (int)(short)((wParam >> 16) & 0xFFFF); + handleMouseScrolled(dwheel); + return true; + case WM_LBUTTONDOWN: + handleMouseButton(0, 1); + return true; + case WM_LBUTTONUP: + handleMouseButton(0, 0); + return true; + case WM_RBUTTONDOWN: + handleMouseButton(1, 1); + return true; + case WM_RBUTTONUP: + handleMouseButton(1, 0); + return true; + case WM_MBUTTONDOWN: + handleMouseButton(2, 1); + return true; + case WM_MBUTTONUP: + handleMouseButton(2, 0); + return true; + default: + return false; + } + } + + private static WindowsDirectInput createDirectInput() throws LWJGLException { + try { + return new WindowsDirectInput8(getDllInstance()); + } catch (LWJGLException e) { + LWJGLUtil.log("Failed to create DirectInput 8 interface, falling back to DirectInput 3"); + return new WindowsDirectInput3(getDllInstance()); + } + } } Added: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInput.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInput.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInput.java 2006-06-26 13:50:48 UTC (rev 2386) @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.opengl; + +/** + * This is the DirectInput base class + * @author elias_naur + */ + +import org.lwjgl.LWJGLException; + +abstract class WindowsDirectInput { + public final static int KEYBOARD_TYPE = 1; + public final static int MOUSE_TYPE = 2; + + /* DirectInput constants */ + public final static int DI_OK = 0x00000000; + public final static int DI_NOEFFECT = 0x00000001; + public final static int DI_PROPNOEFFECT = 0x00000001; + + public final static int DI_DOWNLOADSKIPPED = 0x00000003; + public final static int DI_EFFECTRESTARTED = 0x00000004; + public final static int DI_TRUNCATED = 0x00000008; + public final static int DI_SETTINGSNOTSAVED = 0x0000000B; + public final static int DI_TRUNCATEDANDRESTARTED = 0x0000000C; + + public final static int DI_BUFFEROVERFLOW = 0x00000001; + public final static int DIERR_INPUTLOST = 0x8007001E; + public final static int DIERR_NOTACQUIRED = 0x8007001C; + public final static int DIERR_OTHERAPPHASPRIO = 0x80070005; + + private final long di_interface; + + public WindowsDirectInput(long hinst) throws LWJGLException { + di_interface = createDirectInput(hinst); + } + protected abstract long createDirectInput(long hinst) throws LWJGLException; + + public WindowsDirectInputDevice createDevice(int type) throws LWJGLException { + return createDevice(di_interface, type); + } + protected abstract WindowsDirectInputDevice createDevice(long di_interface, int type) throws LWJGLException; + + public void release() { + release(di_interface); + } + protected abstract void release(long di_interface); +} Property changes on: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInput.java ___________________________________________________________________ Name: svn:executable + * Added: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInput3.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInput3.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInput3.java 2006-06-26 13:50:48 UTC (rev 2386) @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.opengl; + +/** + * This is the DirectInput3 interface + * @author elias_naur + */ + +import org.lwjgl.LWJGLException; + +final class WindowsDirectInput3 extends WindowsDirectInput { + /* Re-define device types to get them included in the native headers */ + public final static int KEYBOARD_TYPE = WindowsDirectInput.KEYBOARD_TYPE; + public final static int MOUSE_TYPE = WindowsDirectInput.MOUSE_TYPE; + + public WindowsDirectInput3(long hinst) throws LWJGLException { + super(hinst); + } + + protected native long createDirectInput(long hinst) throws LWJGLException; + + protected WindowsDirectInputDevice createDevice(long di_interface, int type) throws LWJGLException { + long device = nCreateDevice(di_interface, type); + return new WindowsDirectInputDevice3(device); + } + private static native long nCreateDevice(long di_interface, int type) throws LWJGLException; + + protected native void release(long di_interface); +} Property changes on: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInput3.java ___________________________________________________________________ Name: svn:executable + * Added: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInput8.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInput8.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInput8.java 2006-06-26 13:50:48 UTC (rev 2386) @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.opengl; + +/** + * This is the DirectInput8 interface + * @author elias_naur + */ + +import org.lwjgl.LWJGLException; + +final class WindowsDirectInput8 extends WindowsDirectInput { + /* Re-define device types to get them included in the native headers */ + public final static int KEYBOARD_TYPE = WindowsDirectInput.KEYBOARD_TYPE; + public final static int MOUSE_TYPE = WindowsDirectInput.MOUSE_TYPE; + + public WindowsDirectInput8(long hinst) throws LWJGLException { + super(hinst); + } + + protected native long createDirectInput(long hinst) throws LWJGLException; + + protected WindowsDirectInputDevice createDevice(long di_interface, int type) throws LWJGLException { + long device = nCreateDevice(di_interface, type); + return new WindowsDirectInputDevice8(device); + } + private static native long nCreateDevice(long di_interface, int type) throws LWJGLException; + + protected native void release(long di_interface); +} Property changes on: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInput8.java ___________________________________________________________________ Name: svn:executable + * Added: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInputDevice.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInputDevice.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInputDevice.java 2006-06-26 13:50:48 UTC (rev 2386) @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.opengl; + +/** + * This is the DirectInputDevice interface + * @author elias_naur + */ + +import java.nio.ByteBuffer; +import java.nio.IntBuffer; +import org.lwjgl.LWJGLException; +import org.lwjgl.BufferUtils; + +abstract class WindowsDirectInputDevice { + public final static int DISCL_EXCLUSIVE = 0x00000001; + public final static int DISCL_NONEXCLUSIVE = 0x00000002; + public final static int DISCL_FOREGROUND = 0x00000004; + public final static int DISCL_BACKGROUND = 0x00000008; + public final static int DISCL_NOWINKEY = 0x00000010; + + public final static int GUID_XAxis = 1; + public final static int GUID_YAxis = 2; + public final static int GUID_ZAxis = 3; + public final static int GUID_Button = 4; + public final static int GUID_Unknown = 5; + + private final long di_device; + private ByteBuffer event_buffer; + + public WindowsDirectInputDevice(long di_device) { + this.di_device = di_device; + } + + public void release() { + release(di_device); + } + protected abstract void release(long di_device); + + public int poll() { + return poll(di_device); + } + protected abstract int poll(long di_device); + + public void setDataFormat(int type) throws LWJGLException { + int ret = setDataFormat(di_device, type); + if (ret != WindowsDirectInput.DI_OK) + throw new LWJGLException("Failed to set data format (" + ret + ")"); + } + protected abstract int setDataFormat(long di_device, int type); + + public void setCooperateLevel(long hwnd, int flags) throws LWJGLException { + int ret = setCooperativeLevel(di_device, hwnd, flags); + if (ret != WindowsDirectInput.DI_OK) + throw new LWJGLException("Failed to set cooperative level (" + ret + ")"); + } + protected abstract int setCooperativeLevel(long di_device, long hwnd, int flags); + + public int acquire() { + return acquire(di_device); + } + protected abstract int acquire(long di_device); + + public void setBufferSize(int buffer_size) throws LWJGLException { + int ret = setBufferSize(di_device, buffer_size); + if (ret != WindowsDirectInput.DI_OK) + throw new LWJGLException("Failed to set buffer size (" + ret + ")"); + int event_buffer_size = getEventSize()*buffer_size; + event_buffer = BufferUtils.createByteBuffer(event_buffer_size); + } + protected abstract int setBufferSize(long di_device, int buffer_size); + + public int getDeviceData(IntBuffer buffer) { + int events_remaining = buffer.remaining()/2; + if (event_buffer == null || events_remaining > event_buffer.remaining()/getEventSize()) + event_buffer = BufferUtils.createByteBuffer(events_remaining*getEventSize()); + return getDeviceData(di_device, event_buffer, event_buffer.capacity(), buffer, buffer.position(), buffer.remaining()); + } + protected abstract int getDeviceData(long di_device, ByteBuffer event_buffer, int event_buffer_size, IntBuffer buffer, int position, int size); + + /** + * Device data is returned in tuples of the form <dwOfs, dwData>. + * buffer position() is moved accordingly to number of events. + */ + public int getDeviceState(ByteBuffer buffer) { + return getDeviceState(di_device, buffer, buffer.position(), buffer.remaining()); + } + protected abstract int getDeviceState(long di_device, ByteBuffer buffer, int position, int size); + + public void unacquire() { + unacquire(di_device); + } + protected abstract int unacquire(long di_device); + + public int enumObjects(WindowsDirectInputDeviceObjectCallback enumerator) { + return enumObjects(di_device, enumerator); + } + protected abstract int enumObjects(long di_device, WindowsDirectInputDeviceObjectCallback enumerator); + + protected abstract int getEventSize(); +} Property changes on: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInputDevice.java ___________________________________________________________________ Name: svn:executable + * Added: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInputDevice3.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInputDevice3.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInputDevice3.java 2006-06-26 13:50:48 UTC (rev 2386) @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.opengl; + +/** + * This is the DirectInputDevice3 interface + * @author elias_naur + */ + +import java.nio.ByteBuffer; +import java.nio.IntBuffer; +import org.lwjgl.LWJGLException; + +final class WindowsDirectInputDevice3 extends WindowsDirectInputDevice { + /** Re-declare to get the constants into the native headers */ + public final static int GUID_XAxis = WindowsDirectInputDevice.GUID_XAxis; + public final static int GUID_YAxis = WindowsDirectInputDevice.GUID_YAxis; + public final static int GUID_ZAxis = WindowsDirectInputDevice.GUID_ZAxis; + public final static int GUID_Button = WindowsDirectInputDevice.GUID_Button; + public final static int GUID_Unknown = WindowsDirectInputDevice.GUID_Unknown; + + public WindowsDirectInputDevice3(long di_device) { + super(di_device); + } + + protected native int setDataFormat(long di_device, int type); + + protected native int setCooperativeLevel(long di_device, long hwnd, int flags); + + protected native int acquire(long di_device); + + protected native int getDeviceState(long di_device, ByteBuffer buffer, int position, int size); + + protected native int getDeviceData(long di_device, ByteBuffer event_buffer, int event_buffer_size, IntBuffer buffer, int position, int size); + + protected native int unacquire(long di_device); + + protected int poll(long di_device) { + return WindowsDirectInput.DI_OK; + } + + protected native int setBufferSize(long di_device, int buffer_size); + protected native int getEventSize(); + + protected native void release(long di_device); + + protected native int enumObjects(long di_device, WindowsDirectInputDeviceObjectCallback enumerator); +} Property changes on: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInputDevice3.java ___________________________________________________________________ Name: svn:executable + * Added: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInputDevice8.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInputDevice8.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInputDevice8.java 2006-06-26 13:50:48 UTC (rev 2386) @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.opengl; + +/** + * This is the DirectInputDevice3 interface + * @author elias_naur + */ + +import java.nio.ByteBuffer; +import java.nio.IntBuffer; +import org.lwjgl.LWJGLException; + +final class WindowsDirectInputDevice8 extends WindowsDirectInputDevice { + /** Re-declare to get the constants into the native headers */ + public final static int GUID_XAxis = WindowsDirectInputDevice.GUID_XAxis; + public final static int GUID_YAxis = WindowsDirectInputDevice.GUID_YAxis; + public final static int GUID_ZAxis = WindowsDirectInputDevice.GUID_ZAxis; + public final static int GUID_Button = WindowsDirectInputDevice.GUID_Button; + public final static int GUID_Unknown = WindowsDirectInputDevice.GUID_Unknown; + + public WindowsDirectInputDevice8(long di_device) { + super(di_device); + } + + protected native int setDataFormat(long di_device, int type); + + protected native int setCooperativeLevel(long di_device, long hwnd, int flags); + + protected native int acquire(long di_device); + + protected native int getDeviceState(long di_device, ByteBuffer buffer, int position, int size); + + protected native int getDeviceData(long di_device, ByteBuffer event_buffer, int event_buffer_size, IntBuffer buffer, int position, int size); + + protected native int unacquire(long di_device); + + protected native int poll(long di_device); + + protected native int setBufferSize(long di_device, int buffer_size); + protected native int getEventSize(); + + protected native void release(long di_device); + + protected native int enumObjects(long di_device, WindowsDirectInputDeviceObjectCallback enumerator); +} Property changes on: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInputDevice8.java ___________________________________________________________________ Name: svn:executable + * Added: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInputDeviceObjectCallback.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInputDeviceObjectCallback.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInputDeviceObjectCallback.java 2006-06-26 13:50:48 UTC (rev 2386) @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.opengl; + +/** + * This is the DirectInputDevice callback interface + * @author elias_naur + */ + +interface WindowsDirectInputDeviceObjectCallback { + public boolean nextObject(int type, String name); +} Property changes on: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInputDeviceObjectCallback.java ___________________________________________________________________ Name: svn:executable + * Copied: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsKeyboard.java (from rev 2382, trunk/LWJGL/src/java/org/lwjgl/opengl/Win32Display.java) =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsKeyboard.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsKeyboard.java 2006-06-26 13:50:48 UTC (rev 2386) @@ -0,0 +1,178 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.opengl; + +/** + * This is the Windows implementation of the Keyboard. + * @author elias_naur + */ + +import java.nio.ByteBuffer; +import java.nio.IntBuffer; +import java.nio.CharBuffer; + +import org.lwjgl.LWJGLException; +import org.lwjgl.LWJGLUtil; +import org.lwjgl.BufferUtils; + +final class WindowsKeyboard { + private final static int BUFFER_SIZE = 50; + + private final WindowsDirectInput dinput; + private final WindowsDirectInputDevice keyboard; + private final IntBuffer temp_data_buffer; + private final ByteBuffer keyboard_state; + private final CharBuffer unicode_buffer; + + public WindowsKeyboard(WindowsDirectInput dinput, long hwnd) throws LWJGLException { + this.dinput = dinput; + try { + keyboard = dinput.createDevice(WindowsDirectInput.KEYBOARD_TYPE); + try { + keyboard.setCooperateLevel(hwnd, WindowsDirectInputDevice.DISCL_NONEXCLUSIVE | WindowsDirectInputDevice.DISCL_FOREGROUND); + keyboard.setDataFormat(WindowsDirectInput.KEYBOARD_TYPE); + keyboard.setBufferSize(BUFFER_SIZE); + } catch (LWJGLException e) { + keyboard.release(); + throw e; + } + } catch (LWJGLException e) { + dinput.release(); + throw e; + } + keyboard.acquire(); + temp_data_buffer = BufferUtils.createIntBuffer(BUFFER_SIZE*2); + keyboard_state = BufferUtils.createByteBuffer(256); + unicode_buffer = BufferUtils.createCharBuffer(BUFFER_SIZE); + } + + public void destroy() { + keyboard.unacquire(); + keyboard.release(); + dinput.release(); + } + + public void poll(ByteBuffer keyDownBuffer) { + int ret = keyboard.acquire(); + if (ret != WindowsDirectInput.DI_OK && ret != WindowsDirectInput.DI_NOEFFECT) + return; + keyboard.poll(); + ret = keyboard.getDeviceState(keyDownBuffer); + switch (ret) { + case WindowsDirectInput.DI_OK: + break; + case WindowsDirectInput.DI_BUFFEROVERFLOW: + LWJGLUtil.log("Keyboard buffer overflow"); + break; + case WindowsDirectInput.DIERR_INPUTLOST: + break; + case WindowsDirectInput.DIERR_NOTACQUIRED: + break; + default: + LWJGLUtil.log("Failed to poll keyboard (0x" + Integer.toHexString(ret) + ")"); + break; + } + } + + private int translateData(IntBuffer src, IntBuffer dst) { + int dst_index = dst.position(); + int num_events = 0; + while (dst_index < dst.limit() && src.hasRemaining()) { + num_events++; + int dwOfs = src.get(); + dst.put(dst_index++, dwOfs); + int dwData = src.get(); + dst.put(dst_index++, dwData); + boolean key_down = (dwData & 0x80) != 0; + if (key_down) { + int virt_key = MapVirtualKey(dwOfs, 1); + if (virt_key != 0 && GetKeyboardState(keyboard_state) != 0) { + // Mark key down in the scan code + dwOfs = dwOfs & 0x7fff; + unicode_buffer.clear(); + int num_chars = ToUnicode(virt_key, + dwOfs, + keyboard_state, + unicode_buffer, + unicode_buffer.capacity(), 0); + if (num_chars > 0) { + int current_char = 0; + do { + if (current_char >= 1) { + num_events++; + dst.put(dst_index++, 0); + dst.put(dst_index++, 0); + } + int char_int = ((int)unicode_buffer.get()) & 0xFFFF; + dst.put(dst_index++, char_int); + current_char++; + } while (dst_index < dst.limit() && current_char < num_chars); + } else { + dst.put(dst_index++, 0); + } + } else { + dst.put(dst_index++, 0); + } + } else + dst.put(dst_index++, 0); + } + return num_events; + } + private static native int MapVirtualKey(int uCode, int uMapType); + private static native int ToUnicode(int wVirtKey, int wScanCode, ByteBuffer lpKeyState, CharBuffer pwszBuff, int cchBuff, int flags); + private static native int GetKeyboardState(ByteBuffer lpKeyState); + + public int read(IntBuffer buffer) { + int ret = keyboard.acquire(); + if (ret != WindowsDirectInput.DI_OK && ret != WindowsDirectInput.DI_NOEFFECT) + return 0; + keyboard.poll(); + temp_data_buffer.clear(); + ret = keyboard.getDeviceData(temp_data_buffer); + switch (ret) { + case WindowsDirectInput.DI_OK: + break; + case WindowsDirectInput.DI_BUFFEROVERFLOW: + LWJGLUtil.log("Keyboard buffer overflow"); + break; + case WindowsDirectInput.DIERR_INPUTLOST: + break; + case WindowsDirectInput.DIERR_NOTACQUIRED: + break; + default: + LWJGLUtil.log("Failed to read keyboard (0x" + Integer.toHexString(ret) + ")"); + break; + } + temp_data_buffer.flip(); + return translateData(temp_data_buffer, buffer); + } +} Added: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsMouse.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsMouse.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsMouse.java 2006-06-26 13:50:48 UTC (rev 2386) @@ -0,0 +1,341 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.opengl; + +/** + * This is the Windows implementation of the Mouse. + * @author elias_naur + */ + +import java.nio.ByteBuffer; +import java.nio.IntBuffer; +import java.nio.CharBuffer; + +import org.lwjgl.LWJGLException; +import org.lwjgl.LWJGLUtil; +import org.lwjgl.BufferUtils; + +final class WindowsMouse { + private final static int BUFFER_SIZE = 50; + private final static int BUTTON_STATES_SIZE = 7; + private final static int MOUSE_EVENT_SIZE = 5; + + private final static int DIMOFS_X = 0; + private final static int DIMOFS_Y = 4; + private final static int DIMOFS_Z = 8; + private final static int DIMOFS_BUTTON0 = 12; + private final static int DIMOFS_BUTTON1 = 13; + private final static int DIMOFS_BUTTON2 = 14; + private final static int DIMOFS_BUTTON3 = 15; + + private final long hwnd; + private final WindowsDirectInput dinput; + private final WindowsDirectInputDevice mouse; + + private final int mouse_button_count; + private final boolean has_wheel; + + private final EventQueue event_queue = new EventQueue(MOUSE_EVENT_SIZE); + /* Buffer to hold a DIMOUSESTATE */ + private final ByteBuffer mouse_state; + private final IntBuffer temp_data_buffer; + + private final int[] mouse_event = new int[MOUSE_EVENT_SIZE]; + + private boolean mouse_grabbed; + private byte[] win32_message_button_states = new byte[BUTTON_STATES_SIZE]; + private int accum_dwheel; + private int last_x; + private int last_y; + + public WindowsMouse(WindowsDirectInput dinput, long hwnd) throws LWJGLException { + this.hwnd = hwnd; + this.dinput = dinput; + try { + mouse = dinput.createDevice(WindowsDirectInput.MOUSE_TYPE); + try { + mouse.setDataFormat(WindowsDirectInput.MOUSE_TYPE); + mouse.setBufferSize(BUFFER_SIZE); + if (!acquireNonExclusive()) + throw new LWJGLException("Failed to acquire mouse non-exclusive"); + } catch (LWJGLException e) { + mouse.release(); + throw e; + } + } catch (LWJGLException e) { + dinput.release(); + throw e; + } + MouseEnumerator enumerator = new MouseEnumerator(); + mouse.enumObjects(enumerator); + this.mouse_button_count = Math.min(enumerator.getButtonCount(), 4); + this.has_wheel = enumerator.hasWheel(); + mouse_state = BufferUtils.createByteBuffer(3*4 + 4); + temp_data_buffer = BufferUtils.createIntBuffer(BUFFER_SIZE*2); + } + + public boolean hasWheel() { + return has_wheel; + } + + public int getButtonCount() { + return mouse_button_count; + } + + private boolean acquire(int flags) { + try { + mouse.setCooperateLevel(hwnd, flags); + mouse.acquire(); + return true; + } catch (LWJGLException e) { + LWJGLUtil.log("Failed to acquire mouse: " + e); + return false; + } + } + + private boolean acquireNonExclusive() { + return acquire(WindowsDirectInputDevice.DISCL_NONEXCLUSIVE | WindowsDirectInputDevice.DISCL_FOREGROUND) || + acquire(WindowsDirectInputDevice.DISCL_NONEXCLUSIVE | WindowsDirectInputDevice.DISCL_BACKGROUND); + } + + public void destroy() { + mouse.unacquire(); + mouse.release(); + dinput.release(); + } + + public void poll(IntBuffer coord_buffer, ByteBuffer buttons) { + int ret = mouse.acquire(); + if (ret != WindowsDirectInput.DI_OK && ret != WindowsDirectInput.DI_NOEFFECT) + return; + mouse.poll(); + for (int i = 0; i < coord_buffer.remaining(); i++) + coord_buffer.put(coord_buffer.position() + i, 0); + mouse_state.clear(); + ret = mouse.getDeviceState(mouse_state); + int mouse_state_lx = mouse_state.getInt(); + int mouse_state_ly = mouse_state.getInt(); + int mouse_state_lz = mouse_state.getInt(); + int num_buttons = mouse_button_count; + if (mouse_grabbed || ret == WindowsDirectInput.DI_OK) { + if (ret != WindowsDirectInput.DI_OK) { + LWJGLUtil.log("Error getting mouse state: (0x" + Integer.toHexString(ret) + ")"); + return; + } + + coord_buffer.put(coord_buffer.position() + 2, mouse_state_lz); + if (num_buttons > buttons.remaining()) + num_buttons = buttons.remaining(); + for (int j = 0; j < num_buttons; j++) { + byte button_state = (mouse_state.get() & 0x80) != 0 ? (byte)1 : (byte)0; + buttons.put(buttons.position() + j, button_state); + // track the button state in the windows message buffer state array + // to get accurate button information when releasing a grab + win32_message_button_states[j] = button_state; + } + } else { + coord_buffer.put(coord_buffer.position() + 2, accum_dwheel); + if (num_buttons > win32_message_button_states.length) + num_buttons = win32_message_button_states.length; + for (int j = 0; j < num_buttons; j++) { + buttons.put(buttons.position() + j, win32_message_button_states[j]); + } + } + accum_dwheel = 0; + if (mouse_grabbed) { + coord_buffer.put(coord_buffer.position() + 0, mouse_state_lx); + coord_buffer.put(coord_buffer.position() + 1, -mouse_state_ly); + } else { + coord_buffer.put(coord_buffer.position() + 0, last_x); + coord_buffer.put(coord_buffer.position() + 1, last_y); + } + } + + private boolean putMouseEventWithCoords(int button, int state, int coord1, int coord2, int dz) { + mouse_event[0] = button; + mouse_event[1] = state; + mouse_event[2] = coord1; + mouse_event[3] = coord2; + mouse_event[4] = dz; + return event_queue.putEvent(mouse_event); + } + + private boolean putMouseEvent(int button, int state, int dz) { + if (mouse_grabbed) + return putMouseEventWithCoords(button, state, 0, 0, dz); + else + return putMouseEventWithCoords(button, state, last_x, last_y, dz); + } + + private void copyDXEvents(IntBuffer buffer) { + int buffer_index = 0; + int dx = 0, dy = 0, dwheel = 0; + int button_state; + int i; + while (buffer.hasRemaining()) { + int dwOfs = buffer.get(); + int dwData = buffer.get(); + button_state = (dwData & 0x80) != 0 ? 1 : 0; + switch (dwOfs) { + case DIMOFS_BUTTON0: + putMouseEventWithCoords(0, button_state, dx, -dy, dwheel); + dx = dy = dwheel = 0; + break; + case DIMOFS_BUTTON1: + putMouseEventWithCoords(1, button_state, dx, -dy, dwheel); + dx = dy = dwheel = 0; + break; + case DIMOFS_BUTTON2: + putMouseEventWithCoords(2, button_state, dx, -dy, dwheel); + dx = dy = dwheel = 0; + break; + case DIMOFS_BUTTON3: + putMouseEventWithCoords(3, button_state, dx, -dy, dwheel); + dx = dy = dwheel = 0; + break; + case DIMOFS_X: + dx += dwData; + break; + case DIMOFS_Y: + dy += dwData; + break; + case DIMOFS_Z: + dwheel += dwData; + break; + } + } + if (dx != 0 || dy != 0 || dwheel != 0) + putMouseEventWithCoords(-1, 0, dx, -dy, dwheel); + } + + private void readDXBuffer() { + int ret = mouse.acquire(); + if (ret != WindowsDirectInput.DI_OK && ret != WindowsDirectInput.DI_NOEFFECT) + return; + mouse.poll(); + temp_data_buffer.clear(); + ret = mouse.getDeviceData(temp_data_buffer); + + if (ret == WindowsDirectInput.DI_OK) { + if (mouse_grabbed) { + temp_data_buffer.flip(); + copyDXEvents(temp_data_buffer); + } + } else if (ret == WindowsDirectInput.DI_BUFFEROVERFLOW) { + LWJGLUtil.log("Mouse buffer overflowed"); + } else if (ret == WindowsDirectInput.DIERR_INPUTLOST) { + LWJGLUtil.log("Mouse input lost"); + } else if (ret == WindowsDirectInput.DIERR_NOTACQUIRED) { + LWJGLUtil.log("Mouse not acquired"); + } else { + LWJGLUtil.log("unknown mouse error (" + Integer.toHexString(ret) + ")"); + } + } + + public int read(IntBuffer buffer) { + readDXBuffer(); + return event_queue.copyEvents(buffer); + } + + public void grab(boolean grab) { + if(grab) { + if (!mouse_grabbed) { + // flush DX event buffer + readDXBuffer(); + mouse_grabbed = true; + mouse.unacquire(); + if (!acquire(WindowsDirectInputDevice.DISCL_EXCLUSIVE | WindowsDirectInputDevice.DISCL_FOREGROUND)) + LWJGLUtil.log("Failed to reset cooperative mode"); + } + } else { + if (mouse_grabbed) { + mouse_grabbed = false; + mouse.unacquire(); + acquireNonExclusive(); + } + } + event_queue.clearEvents(); + } + + public void handleMouseScrolled(int event_dwheel) { + accum_dwheel += event_dwheel; + putMouseEvent(-1, 0, event_dwheel); + } + + public void handleMouseMoved(int x, int y) { + int dx; + int dy; + dx = x - last_x; + dy = y - last_y; + last_x = x; + last_y = y; + if (mouse_grabbed) { + putMouseEventWithCoords(-1, 0, dx, dy, 0); + } else { + putMouseEventWithCoords(-1, 0, x, y, 0); + } + } + + public void handleMouseButton(int button, int state) { + putMouseEvent(button, state, 0); + if (button < BUTTON_STATES_SIZE) + win32_message_button_states[button] = state != 0 ? (byte)1 : (byte)0; + } + + private static class MouseEnumerator implements WindowsDirectInputDeviceObjectCallback { + private int button_count; + private boolean has_wheel; + + public int getButtonCount() { + return button_count; + } + + public boolean hasWheel() { + return has_wheel; + } + + public boolean nextObject(int type, String name) { + LWJGLUtil.log("Found mouse object: " + name); + switch (type) { + case WindowsDirectInputDevice.GUID_ZAxis: + has_wheel = true; + break; + case WindowsDirectInputDevice.GUID_Button: + button_count++; + break; + default: + break; + } + return true; + } + } +} Property changes on: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsMouse.java ___________________________________________________________________ Name: svn:executable + * Modified: trunk/LWJGL/src/native/common/common_tools.c =================================================================== --- trunk/LWJGL/src/native/common/common_tools.c 2006-06-23 16:45:21 UTC (rev 2385) +++ trunk/LWJGL/src/native/common/common_tools.c 2006-06-26 13:50:48 UTC (rev 2386) @@ -97,12 +97,16 @@ jclass org_lwjgl_LWJGLUtil_class; jmethodID log_method; va_list ap; - if (isDebugEnabled()) { + if (isDebugEnabled() && !(*env)->ExceptionOccurred(env)) { va_start(ap, format);... [truncated message content] |
From: <eli...@us...> - 2006-06-23 16:45:57
|
Revision: 2385 Author: elias_naur Date: 2006-06-23 09:45:21 -0700 (Fri, 23 Jun 2006) ViewCVS: http://svn.sourceforge.net/java-game-lib/?rev=2385&view=rev Log Message: ----------- Windows: Cleanup of native input code Modified Paths: -------------- trunk/LWJGL/src/native/win32/org_lwjgl_input_Keyboard.c trunk/LWJGL/src/native/win32/org_lwjgl_input_Mouse.c Modified: trunk/LWJGL/src/native/win32/org_lwjgl_input_Keyboard.c =================================================================== --- trunk/LWJGL/src/native/win32/org_lwjgl_input_Keyboard.c 2006-06-23 08:16:27 UTC (rev 2384) +++ trunk/LWJGL/src/native/win32/org_lwjgl_input_Keyboard.c 2006-06-23 16:45:21 UTC (rev 2385) @@ -69,34 +69,28 @@ return; } - // Check to see if we're already initialized - if (lpdiKeyboard != NULL) { - throwException(env, "Keyboard already created."); - return; - } - // Create a keyboard device - if (IDirectInput_CreateDevice(lpdi, &GUID_SysKeyboard, &lpdiKeyboard, NULL) != DI_OK) { + if (IDirectInput_CreateDevice(lpdi, &GUID_SysKeyboard, &lpdiKeyboard, NULL) != DI_OK) { throwException(env, "Failed to create keyboard."); return; } - if (IDirectInputDevice_SetCooperativeLevel(lpdiKeyboard, getCurrentHWND(), DISCL_NONEXCLUSIVE | DISCL_FOREGROUND) != DI_OK) { + if (IDirectInputDevice_SetCooperativeLevel(lpdiKeyboard, getCurrentHWND(), DISCL_NONEXCLUSIVE | DISCL_FOREGROUND) != DI_OK) { throwException(env, "Failed to set keyboard cooperation mode."); return; } // Tell 'em wot format to be in (the default "you are a mouse and keyboard" format) - IDirectInputDevice_SetDataFormat(lpdiKeyboard, &c_dfDIKeyboard); + IDirectInputDevice_SetDataFormat(lpdiKeyboard, &c_dfDIKeyboard); dipropdw.diph.dwSize = sizeof(DIPROPDWORD); dipropdw.diph.dwHeaderSize = sizeof(DIPROPHEADER); dipropdw.diph.dwObj = 0; dipropdw.diph.dwHow = DIPH_DEVICE; dipropdw.dwData = KEYBOARD_BUFFER_SIZE; - IDirectInputDevice_SetProperty(lpdiKeyboard, DIPROP_BUFFERSIZE, &dipropdw.diph); + IDirectInputDevice_SetProperty(lpdiKeyboard, DIPROP_BUFFERSIZE, &dipropdw.diph); - ret = IDirectInputDevice_Acquire(lpdiKeyboard); + ret = IDirectInputDevice_Acquire(lpdiKeyboard); if(FAILED(ret)) { printfDebugJava(env, "Failed to acquire keyboard"); } @@ -120,14 +114,14 @@ { // Release keyboard if (lpdiKeyboard != NULL) { - IDirectInputDevice_Unacquire(lpdiKeyboard); - IDirectInputDevice_Release(lpdiKeyboard); + IDirectInputDevice_Unacquire(lpdiKeyboard); + IDirectInputDevice_Release(lpdiKeyboard); lpdiKeyboard = NULL; } // Release DirectInput if (lpdi != NULL) { printfDebugJava(env, "Destroying directinput"); - IDirectInput_Release(lpdi); + IDirectInput_Release(lpdi); lpdi = NULL; } } @@ -140,50 +134,32 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_nPollKeyboard (JNIEnv * env, jobject self, jobject buffer) { - HRESULT ret; - void *keyboardBuffer; - jlong buffer_size; - do { - ret = IDirectInputDevice_Acquire(lpdiKeyboard); - if (ret == DIERR_INPUTLOST) { - printf("Input lost\n"); - return; - } else if (ret == DIERR_NOTACQUIRED) { - printf("not acquired\n"); - return; - } else if (ret == DIERR_INVALIDPARAM) { - printf("invalid parameter\n"); - return; - } else if (ret == DIERR_NOTBUFFERED) { - printf("not buffered\n"); - return; - } else if (ret == DIERR_NOTINITIALIZED) { - printf("not inited\n"); - return; - } else if (ret != DI_OK && ret != S_FALSE) { - //printf("unknown keyboard error\n"); - return; - } - } while (ret != DI_OK && ret != S_FALSE); + void *keyboardBuffer; + jlong buffer_size; + HRESULT ret = IDirectInputDevice_Acquire(lpdiKeyboard); + if (ret != DI_OK && ret != S_FALSE) { +// printfDebugJava(env, "Failed to acquire keyboard (%x)\n", ret); + return; + } - keyboardBuffer = (void *)(*env)->GetDirectBufferAddress(env, buffer); - buffer_size = (*env)->GetDirectBufferCapacity(env, buffer); - IDirectInputDevice_GetDeviceState(lpdiKeyboard, (DWORD)buffer_size, keyboardBuffer); + keyboardBuffer = (void *)(*env)->GetDirectBufferAddress(env, buffer); + buffer_size = (*env)->GetDirectBufferCapacity(env, buffer); + IDirectInputDevice_GetDeviceState(lpdiKeyboard, (DWORD)buffer_size, keyboardBuffer); } JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Win32Display_nReadKeyboard (JNIEnv * env, jobject self, jobject buffer_obj, jint buffer_position) { - UINT scan_code; - UINT virt_key; - bool key_down; - jint * buf; - jint ch_int; - int buffer_size; - int index = 0; - int event_size = 3; - DWORD current_di_event = 0; - DIDEVICEOBJECTDATA rgdod[KEYBOARD_BUFFER_SIZE]; + UINT scan_code; + UINT virt_key; + bool key_down; + jint * buf; + jint ch_int; + int buffer_size; + int index = 0; + int event_size = 3; + DWORD current_di_event = 0; + DIDEVICEOBJECTDATA rgdod[KEYBOARD_BUFFER_SIZE]; wchar_t transBufUnicode[KEYBOARD_BUFFER_SIZE]; WORD transBufAscii[KEYBOARD_BUFFER_SIZE]; @@ -194,42 +170,42 @@ int num_chars; int num_events = 0; - ret = IDirectInputDevice_Acquire(lpdiKeyboard); + ret = IDirectInputDevice_Acquire(lpdiKeyboard); if (ret != DI_OK && ret != S_FALSE) return 0; - ret = IDirectInputDevice_GetDeviceData(lpdiKeyboard, - sizeof(DIDEVICEOBJECTDATA), - rgdod, - &num_di_events, - 0); + ret = IDirectInputDevice_GetDeviceData(lpdiKeyboard, + sizeof(DIDEVICEOBJECTDATA), + rgdod, + &num_di_events, + 0); if (ret == DI_OK) { - buf = buffer_position + (jint *)(*env)->GetDirectBufferAddress(env, buffer_obj); - buffer_size = ((int)(*env)->GetDirectBufferCapacity(env, buffer_obj))/sizeof(jint) - buffer_position; + buf = buffer_position + (jint *)(*env)->GetDirectBufferAddress(env, buffer_obj); + buffer_size = ((int)(*env)->GetDirectBufferCapacity(env, buffer_obj))/sizeof(jint) - buffer_position; while (index + event_size <= buffer_size && current_di_event < num_di_events) { num_events++; buf[index++] = (unsigned char) rgdod[current_di_event].dwOfs; buf[index++] = (unsigned char) rgdod[current_di_event].dwData; - key_down = (rgdod[current_di_event].dwData & 0x80) != 0; + key_down = (rgdod[current_di_event].dwData & 0x80) != 0; if (key_down) { - scan_code = rgdod[current_di_event].dwOfs; - virt_key = MapVirtualKey(scan_code, 1); + scan_code = rgdod[current_di_event].dwOfs; + virt_key = MapVirtualKey(scan_code, 1); if (virt_key != 0 && GetKeyboardState(state)) { // Mark key down in the scan code scan_code = scan_code & 0x7fff; if (useUnicode) { num_chars = ToUnicode(virt_key, - scan_code, - state, - transBufUnicode, - KEYBOARD_BUFFER_SIZE, 0); + scan_code, + state, + transBufUnicode, + KEYBOARD_BUFFER_SIZE, 0); } else { num_chars = ToAscii(virt_key, - scan_code, - state, - transBufAscii, - 0); + scan_code, + state, + transBufAscii, + 0); } if (num_chars > 0) { int current_char = 0; Modified: trunk/LWJGL/src/native/win32/org_lwjgl_input_Mouse.c =================================================================== --- trunk/LWJGL/src/native/win32/org_lwjgl_input_Mouse.c 2006-06-23 08:16:27 UTC (rev 2384) +++ trunk/LWJGL/src/native/win32/org_lwjgl_input_Mouse.c 2006-06-23 16:45:21 UTC (rev 2385) @@ -127,7 +127,7 @@ */ static bool CreateMouse(JNIEnv *env) { HRESULT hr; - hr = IDirectInput_CreateDevice(lpdi, &GUID_SysMouse, &mDIDevice, NULL); + hr = IDirectInput_CreateDevice(lpdi, &GUID_SysMouse, &mDIDevice, NULL); if FAILED(hr) { throwException(env, "CreateDevice failed"); return false; @@ -447,15 +447,6 @@ return DIENUM_CONTINUE; } -static int cap(int val, int min, int max) { - if (val < min) - return min; - else if (val > max) - return max; - else - return val; -} - /** * Updates the fields on the Mouse */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ma...@us...> - 2006-06-23 08:16:33
|
Revision: 2384 Author: matzon Date: 2006-06-23 01:16:27 -0700 (Fri, 23 Jun 2006) ViewCVS: http://svn.sourceforge.net/java-game-lib/?rev=2384&view=rev Log Message: ----------- fixed offset/length to use buffer properties Modified Paths: -------------- trunk/LWJGL/src/native/common/fmod3/org_lwjgl_fmod3_FMusic.c trunk/LWJGL/src/native/common/fmod3/org_lwjgl_fmod3_FSound.c Modified: trunk/LWJGL/src/native/common/fmod3/org_lwjgl_fmod3_FMusic.c =================================================================== --- trunk/LWJGL/src/native/common/fmod3/org_lwjgl_fmod3_FMusic.c 2006-06-23 08:14:49 UTC (rev 2383) +++ trunk/LWJGL/src/native/common/fmod3/org_lwjgl_fmod3_FMusic.c 2006-06-23 08:16:27 UTC (rev 2384) @@ -57,15 +57,15 @@ * Method: nFMUSIC_LoadSongEx * Signature: (Ljava/nio/ByteBuffer;IIILjava/nio/IntBuffer;I)J */ -JNIEXPORT jlong JNICALL Java_org_lwjgl_fmod3_FMusic_nFMUSIC_1LoadSongEx__Ljava_nio_ByteBuffer_2IIIILjava_nio_IntBuffer_2II - (JNIEnv *env, jclass clazz, jobject data, jint dataOffset, jint offset, jint length, jint mode, jobject sampleList, jint sampleListOffset, jint samplelistnum){ +JNIEXPORT jlong JNICALL Java_org_lwjgl_fmod3_FMusic_nFMUSIC_1LoadSongEx__Ljava_nio_ByteBuffer_2IIILjava_nio_IntBuffer_2II + (JNIEnv *env, jclass clazz, jobject data, jint offset, jint length, jint mode, jobject sampleList, jint sampleListOffset, jint samplelistnum){ int *sampleData = NULL; - const char *songData = dataOffset + (char *) (*env)->GetDirectBufferAddress(env, data); + const char *songData = offset + (char *) (*env)->GetDirectBufferAddress(env, data); if(sampleList != NULL) { sampleData = sampleListOffset + (int *) (*env)->GetDirectBufferAddress(env, sampleList); } - return (jlong) fmod_instance->FMUSIC_LoadSongEx(songData, offset, length, mode, sampleData, samplelistnum); + return (jlong) fmod_instance->FMUSIC_LoadSongEx(songData, 0, length, mode, sampleData, samplelistnum); } /* Modified: trunk/LWJGL/src/native/common/fmod3/org_lwjgl_fmod3_FSound.c =================================================================== --- trunk/LWJGL/src/native/common/fmod3/org_lwjgl_fmod3_FSound.c 2006-06-23 08:14:49 UTC (rev 2383) +++ trunk/LWJGL/src/native/common/fmod3/org_lwjgl_fmod3_FSound.c 2006-06-23 08:16:27 UTC (rev 2384) @@ -438,9 +438,9 @@ * Method: nFSOUND_Sample_Load * Signature: (ILjava/nio/ByteBuffer;IIII)J */ -JNIEXPORT jlong JNICALL Java_org_lwjgl_fmod3_FSound_nFSOUND_1Sample_1Load__ILjava_nio_ByteBuffer_2IIII(JNIEnv * env, jclass clazz, jint index, jobject data, jint dataOffset, jint inputmode, jint offset, jint length) { - const char * nData = dataOffset + (const char *) (*env)->GetDirectBufferAddress(env, data); - return (long) fmod_instance->FSOUND_Sample_Load(index, nData, inputmode, offset, length); +JNIEXPORT jlong JNICALL Java_org_lwjgl_fmod3_FSound_nFSOUND_1Sample_1Load__ILjava_nio_ByteBuffer_2III(JNIEnv * env, jclass clazz, jint index, jobject data, jint inputmode, jint offset, jint length) { + const char * nData = offset + (const char *) (*env)->GetDirectBufferAddress(env, data); + return (long) fmod_instance->FSOUND_Sample_Load(index, nData, inputmode, 0, length); } /* @@ -969,9 +969,9 @@ * Method: nFSOUND_Stream_Open * Signature: (Ljava/nio/ByteBuffer;IIII)J */ -JNIEXPORT jlong JNICALL Java_org_lwjgl_fmod3_FSound_nFSOUND_1Stream_1Open__Ljava_nio_ByteBuffer_2IIII(JNIEnv * env, jclass clazz, jobject data, jint dataOffset, jint mode, jint offset, jint length) { - const char *streamData = dataOffset + (char *) (*env)->GetDirectBufferAddress(env, data); - return (jlong) fmod_instance->FSOUND_Stream_Open(streamData, mode, offset, length); +JNIEXPORT jlong JNICALL Java_org_lwjgl_fmod3_FSound_nFSOUND_1Stream_1Open__Ljava_nio_ByteBuffer_2III(JNIEnv * env, jclass clazz, jobject data, jint mode, jint offset, jint length) { + const char *streamData = offset + (char *) (*env)->GetDirectBufferAddress(env, data); + return (jlong) fmod_instance->FSOUND_Stream_Open(streamData, mode, 0, length); } /* This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ma...@us...> - 2006-06-23 08:15:10
|
Revision: 2383 Author: matzon Date: 2006-06-23 01:14:49 -0700 (Fri, 23 Jun 2006) ViewCVS: http://svn.sourceforge.net/java-game-lib/?rev=2383&view=rev Log Message: ----------- fixed offset/length to use buffer properties keep reference to buffers until free'd added FMUSIC_LoadSongEx test Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/fmod3/FMusic.java trunk/LWJGL/src/java/org/lwjgl/fmod3/FMusicModule.java trunk/LWJGL/src/java/org/lwjgl/fmod3/FSound.java trunk/LWJGL/src/java/org/lwjgl/fmod3/FSoundSample.java trunk/LWJGL/src/java/org/lwjgl/fmod3/FSoundStream.java trunk/LWJGL/src/java/org/lwjgl/test/fmod3/DSPTest.java trunk/LWJGL/src/java/org/lwjgl/test/fmod3/MusicPlayer.java trunk/LWJGL/src/java/org/lwjgl/test/fmod3/StreamPlayer.java trunk/LWJGL/src/java/org/lwjgl/test/fmod3/StreamPlayerMemory.java trunk/LWJGL/src/java/org/lwjgl/test/fmod3/SyncTest.java Added Paths: ----------- trunk/LWJGL/src/java/org/lwjgl/test/fmod3/MusicPlayerMemory.java Modified: trunk/LWJGL/src/java/org/lwjgl/fmod3/FMusic.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/fmod3/FMusic.java 2006-06-22 10:42:45 UTC (rev 2382) +++ trunk/LWJGL/src/java/org/lwjgl/fmod3/FMusic.java 2006-06-23 08:14:49 UTC (rev 2383) @@ -84,7 +84,7 @@ public static FMusicModule FMUSIC_LoadSong(String name) { long result = nFMUSIC_LoadSong(name); if(result != FMUSIC_TYPE_NONE) { - return new FMusicModule(result); + return new FMusicModule(result, null); } return null; } @@ -110,16 +110,14 @@ * </p> * * @param data containing song to load. On PlayStation 2 data must be 16 byte aligned if loading from memory - * @param offset Optional. 0 by default. If > 0, this value is used to specify an offset in a file, so fmod will seek before opening - * @param length Optional. 0 by default. If > 0, this value is used to specify the length of a memory block when using FSOUND_LOADMEMORY, or it is the length of a file or file segment if the offset parameter is used. On PlayStation 2 this must be 16 byte aligned for memory loading * @param mode Mode for opening song. With module files, only FSOUND_LOADMEMORY, FSOUND_NONBLOCKING, FSOUND_LOOP_NORMAL, or FSOUND_LOOP_OFF are supported. For FSB files, FSOUND_2D, FSOUND_HW3D, FSOUND_FORCEMONO also work * @param sampleList Optional. Buffer of sample indicies to load. Leave as Null if you want all samples to be loaded (default behaviour). See Remarks for more on this * @return On success, a FMusicModule instance is returned. On failure, Null is returned */ - public static FMusicModule FMUSIC_LoadSongEx(ByteBuffer data, int offset, int length, int mode, IntBuffer sampleList) { - long result = nFMUSIC_LoadSongEx(data, data.position(), offset, length, mode, (sampleList != null) ? sampleList : null, (sampleList != null) ? sampleList.position() : 0, (sampleList != null) ? sampleList.remaining() : 0); + public static FMusicModule FMUSIC_LoadSongEx(ByteBuffer data, int mode, IntBuffer sampleList) { + long result = nFMUSIC_LoadSongEx(data, data.position(), data.remaining(), mode, (sampleList != null) ? sampleList : null, (sampleList != null) ? sampleList.position() : 0, (sampleList != null) ? sampleList.remaining() : 0); if(result != FMUSIC_TYPE_NONE) { - return new FMusicModule(result); + return new FMusicModule(result, data); } return null; } @@ -137,11 +135,11 @@ long result = nFMUSIC_LoadSongEx(name, offset, length, mode, (sampleList != null) ? sampleList : null, (sampleList != null) ? sampleList.position() : 0, (sampleList != null) ? sampleList.remaining() : 0); if(result != FMUSIC_TYPE_NONE) { - return new FMusicModule(result); + return new FMusicModule(result, null); } return null; } - private static native long nFMUSIC_LoadSongEx(ByteBuffer data, int dataOffset, int offset, int length, int mode, IntBuffer sampleList, int bufferOffset, int remaining); + private static native long nFMUSIC_LoadSongEx(ByteBuffer data, int offset, int length, int mode, IntBuffer sampleList, int bufferOffset, int remaining); private static native long nFMUSIC_LoadSongEx(String name, int offset, int length, int mode, IntBuffer sampleList, int bufferOffset, int remaining); /** @@ -165,6 +163,7 @@ FMOD.registerCallback(FMOD.FMUSIC_ORDERCALLBACK, module.moduleHandle, null, null); FMOD.registerCallback(FMOD.FMUSIC_ROWCALLBACK, module.moduleHandle, null, null); FMOD.registerCallback(FMOD.FMUSIC_ZXXCALLBACK, module.moduleHandle, null, null); + module.release(); return nFMUSIC_FreeSong(module.moduleHandle); } private static native boolean nFMUSIC_FreeSong(long module); @@ -335,6 +334,7 @@ * @return On success, true is returned. On failure, false is returned */ public static boolean FMUSIC_SetUserData(FMusicModule module, ByteBuffer userdata) { + module.userData = userdata; return nFMUSIC_SetUserData(module.moduleHandle, userdata, userdata.position()); } private static native boolean nFMUSIC_SetUserData(long module, ByteBuffer userdata, int offset); @@ -551,7 +551,7 @@ public static FSoundSample FMUSIC_GetSample(FMusicModule module, int sampno) { long result = nFMUSIC_GetSample(module.moduleHandle, sampno); if(result != 0) { - return new FSoundSample(result); + return new FSoundSample(result, null); } return null; } Modified: trunk/LWJGL/src/java/org/lwjgl/fmod3/FMusicModule.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/fmod3/FMusicModule.java 2006-06-22 10:42:45 UTC (rev 2382) +++ trunk/LWJGL/src/java/org/lwjgl/fmod3/FMusicModule.java 2006-06-23 08:14:49 UTC (rev 2383) @@ -31,6 +31,9 @@ */ package org.lwjgl.fmod3; +import java.nio.Buffer; +import java.nio.ByteBuffer; + /** * This class is a representation of a Module in FMod. * <br> @@ -42,12 +45,27 @@ /** Handle to module */ long moduleHandle; + /** Handle to buffer containing module data */ + Buffer moduleData; + + /** Handle to buffer containing user data */ + Buffer userData; + /** * Creates a new FMusicModule * * @param moduleHandle */ - FMusicModule(long moduleHandle) { - this.moduleHandle = moduleHandle; + FMusicModule(long moduleHandle, Buffer moduleData) { + this.moduleHandle = moduleHandle; + this.moduleData = moduleData; } + + /** + * Releases the reference to any data contained + */ + void release() { + this.moduleData = null; + this.userData = null; + } } Modified: trunk/LWJGL/src/java/org/lwjgl/fmod3/FSound.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/fmod3/FSound.java 2006-06-22 10:42:45 UTC (rev 2382) +++ trunk/LWJGL/src/java/org/lwjgl/fmod3/FSound.java 2006-06-23 08:14:49 UTC (rev 2383) @@ -877,7 +877,7 @@ */ public static FSoundSample FSOUND_Sample_Alloc(int index, int length, int mode, int deffreq, int defvol, int defpan, int defpri) { long result = nFSOUND_Sample_Alloc(index, length, mode, deffreq, defvol, defpan, defpri); - return (result != 0) ? new FSoundSample(result) : null; + return (result != 0) ? new FSoundSample(result, null) : null; } private static native long nFSOUND_Sample_Alloc(int index, int length, int mode, int deffreq, int defvol, int defpan, int defpri); @@ -886,6 +886,7 @@ * @param sample sample definition to be freed */ public static void FSOUND_Sample_Free(FSoundSample sample) { + sample.release(); nFSOUND_Sample_Free(sample.sampleHandle); } private static native void nFSOUND_Sample_Free(long sample); @@ -902,7 +903,7 @@ */ public static FSoundSample FSOUND_Sample_Get(int sampno) { long result = nFSOUND_Sample_Get(sampno); - return (result != 0) ? new FSoundSample(result) : null; + return (result != 0) ? new FSoundSample(result, null) : null; } private static native long nFSOUND_Sample_Get(int sampno); @@ -1056,14 +1057,12 @@ * FSOUND_UNMANAGED - Dont have this sample managed within fsounds sample management system * @param data ByteBuffer of memory image to load. * @param inputmode Description of the data format, OR in the bits defined in FSOUND_MODES to describe the data being loaded. - * @param offset Optional. 0 by default. If > 0, this value is used to specify an offset in a file, so fmod will seek before opening. length must also be specified if this value is used. - * @param length Optional. 0 by default. If > 0, this value is used to specify the length of a memory block when using FSOUND_LOADMEMORY, or it is the length of a file or file segment if the offset parameter is used. On PlayStation 2 this must be 16 byte aligned for memory loading. * @return On success, a sample is returned. On failure, NULL is returned. */ - public static FSoundSample FSOUND_Sample_Load(int index, ByteBuffer data, int inputmode, int offset, int length) { - long result = nFSOUND_Sample_Load(index, data, data.position(), inputmode, offset, length); + public static FSoundSample FSOUND_Sample_Load(int index, ByteBuffer data, int inputmode) { + long result = nFSOUND_Sample_Load(index, data, inputmode, data.position(), data.remaining()); if(result != 0) { - return new FSoundSample(result); + return new FSoundSample(result, data); } return null; } @@ -1083,11 +1082,11 @@ public static FSoundSample FSOUND_Sample_Load(int index, String name, int inputmode, int offset, int length) { long result = nFSOUND_Sample_Load(index, name, inputmode, offset, length); if(result != 0) { - return new FSoundSample(result); + return new FSoundSample(result, null); } return null; } - private static native long nFSOUND_Sample_Load(int index, ByteBuffer data, int dataOffset, int inputmode, int offset, int length); + private static native long nFSOUND_Sample_Load(int index, ByteBuffer data, int inputmode, int offset, int length); private static native long nFSOUND_Sample_Load(int index, String name, int inputmode, int offset, int length); /** @@ -1693,7 +1692,7 @@ public static FSoundSample FSOUND_GetCurrentSample(int channel) { long result = nFSOUND_GetCurrentSample(channel); if(result != 0) { - return new FSoundSample(result); + return new FSoundSample(result, null); } return null; } @@ -2088,7 +2087,7 @@ public static FSoundStream FSOUND_Stream_Open(String name, int mode, int offset, int length) { long result = nFSOUND_Stream_Open(name, mode, offset, length); if(result != 0) { - return new FSoundStream(result); + return new FSoundStream(result, null); } return null; } @@ -2098,18 +2097,16 @@ * @param data data when FSOUND_LOADMEMORY is used. * @param mode Simple description of how to play the file. For all formats except raw PCM, * FSOUND_LOOP*, FSOUND_HW3D, FSOUND_HW2D, FSOUND_2D, FSOUND_LOADMEMORY, FSOUND_LOADRAW, FSOUND_MPEGACCURATE, FSOUND_NONBLOCKING flags are the only ones supported. - * @param offset Optional. 0 by default. If > 0, this value is used to specify an offset in a file, so fmod will seek before opening. length must also be specified if this value is used. - * @param length Optional. 0 by default. If > 0, this value is used to specify the length of a memory block when using FSOUND_LOADMEMORY, or it is the length of a file or file segment if the offset parameter is used. On PlayStation 2 this must be 16 byte aligned for memory loading. * @return On success, a reference to an opened stream is returned. On failure, NULL is returned. */ - public static FSoundStream FSOUND_Stream_Open(ByteBuffer data, int mode, int offset, int length) { - long result = nFSOUND_Stream_Open(data, data.position(), mode, offset, length); + public static FSoundStream FSOUND_Stream_Open(ByteBuffer data, int mode) { + long result = nFSOUND_Stream_Open(data, mode, data.position(), data.remaining()); if(result != 0) { - return new FSoundStream(result); + return new FSoundStream(result, data); } return null; } - private static native long nFSOUND_Stream_Open(ByteBuffer data, int dataOffset, int mode, int offset, int length); + private static native long nFSOUND_Stream_Open(ByteBuffer data, int mode, int offset, int length); private static native long nFSOUND_Stream_Open(String name, int mode, int offset, int length); /** @@ -2170,6 +2167,7 @@ * @return On success, TRUE is returned. On failure, FALSE is returned. */ public static boolean FSOUND_Stream_Close(FSoundStream stream) { + stream.release(); return nFSOUND_Stream_Close(stream.streamHandle); } private static native boolean nFSOUND_Stream_Close(long streamhandle); @@ -2243,7 +2241,7 @@ FSoundStream stream = null; long result = nFSOUND_Stream_Create(lenbytes, mode, samplerate); if(result != 0) { - stream = new FSoundStream(result); + stream = new FSoundStream(result, null); FMOD.registerCallback(FMOD.FSOUND_STREAMCALLBACK, stream.streamHandle, stream, callbackHandler); } return stream; @@ -2414,7 +2412,7 @@ public static FSoundSample FSOUND_Stream_GetSample(FSoundStream stream) { long result = nFSOUND_Stream_GetSample(stream.streamHandle); if(result != 0) { - return new FSoundSample(result); + return new FSoundSample(result, null); } return null; } Modified: trunk/LWJGL/src/java/org/lwjgl/fmod3/FSoundSample.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/fmod3/FSoundSample.java 2006-06-22 10:42:45 UTC (rev 2382) +++ trunk/LWJGL/src/java/org/lwjgl/fmod3/FSoundSample.java 2006-06-23 08:14:49 UTC (rev 2383) @@ -31,6 +31,8 @@ */ package org.lwjgl.fmod3; +import java.nio.Buffer; + /** * This class is a representation of a Sound Sample in FMod. * <br> @@ -42,12 +44,23 @@ /** Handle to sample */ long sampleHandle; + /** Handle to buffer containing sample data */ + Buffer sampleData; + /** * Creates a new FSoundSample * * @param sampleHandle handle to sample */ - FSoundSample(long sampleHandle) { - this.sampleHandle = sampleHandle; + FSoundSample(long sampleHandle, Buffer sampleData) { + this.sampleHandle = sampleHandle; + this.sampleData = sampleData; } + + /** + * Releases the reference to any data contained + */ + void release() { + this.sampleData = null; + } } Modified: trunk/LWJGL/src/java/org/lwjgl/fmod3/FSoundStream.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/fmod3/FSoundStream.java 2006-06-22 10:42:45 UTC (rev 2382) +++ trunk/LWJGL/src/java/org/lwjgl/fmod3/FSoundStream.java 2006-06-23 08:14:49 UTC (rev 2383) @@ -31,6 +31,8 @@ */ package org.lwjgl.fmod3; +import java.nio.Buffer; + /** * This class is a representation of a Sound stream in FMod. * <br> @@ -42,12 +44,23 @@ /** Handle to stream */ long streamHandle; + /** Handle to buffer containing sample data */ + Buffer streamData; + /** * Creates a new FSoundStream * * @param streamHandle handle to stream */ - FSoundStream(long streamHandle) { + FSoundStream(long streamHandle, Buffer streamData) { this.streamHandle = streamHandle; + this.streamData = streamData; } + + /** + * Releases the reference to any data contained + */ + void release() { + this.streamData = null; + } } Modified: trunk/LWJGL/src/java/org/lwjgl/test/fmod3/DSPTest.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/fmod3/DSPTest.java 2006-06-22 10:42:45 UTC (rev 2382) +++ trunk/LWJGL/src/java/org/lwjgl/test/fmod3/DSPTest.java 2006-06-23 08:14:49 UTC (rev 2383) @@ -60,7 +60,7 @@ System.out.println("Usage:\n DSPTest <file>"); // default to phero.mp3 - args = new String[] { "res\\phero.mp3"}; + args = new String[] { "res" + File.separator + "phero.mp3"}; System.out.println("Using default: " + args[0]); } Modified: trunk/LWJGL/src/java/org/lwjgl/test/fmod3/MusicPlayer.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/fmod3/MusicPlayer.java 2006-06-22 10:42:45 UTC (rev 2382) +++ trunk/LWJGL/src/java/org/lwjgl/test/fmod3/MusicPlayer.java 2006-06-23 08:14:49 UTC (rev 2383) @@ -53,7 +53,7 @@ System.out.println("Usage:\n MusicPlayer <file>"); // default to Missing_you.mod - args = new String[] { "res\\Missing_you.mod"}; + args = new String[] { "res" + File.separator + "Missing_you.mod"}; System.out.println("Using default: " + args[0]); } Added: trunk/LWJGL/src/java/org/lwjgl/test/fmod3/MusicPlayerMemory.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/fmod3/MusicPlayerMemory.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/test/fmod3/MusicPlayerMemory.java 2006-06-23 08:14:49 UTC (rev 2383) @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.test.fmod3; + +import java.io.BufferedInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +import org.lwjgl.fmod3.FMOD; +import org.lwjgl.fmod3.FMODException; +import org.lwjgl.fmod3.FMusic; +import org.lwjgl.fmod3.FMusicModule; +import org.lwjgl.fmod3.FSound; + +/** + * <br> + * @author Brian Matzon <br...@ma...> + * @version $Revision: 2286 $ + * $Id: MusicPlayer.java 2286 2006-03-23 19:32:21Z matzon $ + */ +public class MusicPlayerMemory { + + public static void main(String[] args) { + if (args.length < 1) { + System.out.println("Usage:\n MusicPlayer <file>"); + + // default to Missing_you.mod + args = new String[] { "res" + File.separator + "Missing_you.mod"}; + System.out.println("Using default: " + args[0]); + } + + File file = new File(args[0]); + if (!file.exists()) { + System.out.println("No such file: " + args[0]); + System.exit(0); + } + + try { + FMOD.create(); + } catch (FMODException fmode) { + fmode.printStackTrace(); + System.exit(0); + } + + System.out.println("Initializing FMOD"); + if (!FSound.FSOUND_Init(44100, 32, 0)) { + System.out.println("Failed to initialize FMOD"); + return; + } + + System.out.println("Loading " + args[0]); + + // using name (path) + ByteBuffer data = getData(args[0]); + FMusicModule module = FMusic.FMUSIC_LoadSongEx(data, FSound.FSOUND_LOADMEMORY, null); + + if (module != null) { + System.out.println("Loaded. Playing module of type: " + FMusic.FMUSIC_GetType(module)); + FMusic.FMUSIC_PlaySong(module); + + System.out.println("Press enter to stop playing"); + try { + System.in.read(); + } catch (IOException ioe) { + } + FMusic.FMUSIC_StopSong(module); + + System.out.println("Done playing. Cleaning up"); + FMusic.FMUSIC_FreeSong(module); + } else { + System.out.println("Unable to play: " + args[0]); + System.out.println("Error: " + FMOD.FMOD_ErrorString(FSound.FSOUND_GetError())); + } + + FSound.FSOUND_Close(); + FMOD.destroy(); + System.exit(0); + } + + /** + * Reads the file into a ByteBuffer + * + * @param filename Name of file to load + * @return ByteBuffer containing file data + */ + static protected ByteBuffer getData(String filename) { + ByteBuffer buffer = null; + + System.out.println("Attempting to load: " + filename); + + try { + BufferedInputStream bis = new BufferedInputStream(StreamPlayerMemory.class.getClassLoader() + .getResourceAsStream(filename)); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + + int bufferLength = 4096; + byte[] readBuffer = new byte[bufferLength]; + int read = -1; + + while ((read = bis.read(readBuffer, 0, bufferLength)) != -1) { + baos.write(readBuffer, 0, read); + } + + //done reading, close + bis.close(); + + // place it in a buffer + buffer = ByteBuffer.allocateDirect(baos.size()); + buffer.order(ByteOrder.nativeOrder()); + buffer.put(baos.toByteArray()); + buffer.flip(); + System.out.println("loaded " + buffer.remaining() + " bytes"); + } catch (Exception ioe) { + ioe.printStackTrace(); + } + return buffer; + } +} \ No newline at end of file Modified: trunk/LWJGL/src/java/org/lwjgl/test/fmod3/StreamPlayer.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/fmod3/StreamPlayer.java 2006-06-22 10:42:45 UTC (rev 2382) +++ trunk/LWJGL/src/java/org/lwjgl/test/fmod3/StreamPlayer.java 2006-06-23 08:14:49 UTC (rev 2383) @@ -52,7 +52,7 @@ System.out.println("Usage:\n StreamPlayer <file>"); // default to phero.mp3 - args = new String[] { "res\\phero.mp3"}; + args = new String[] { "res" + File.separator + "phero.mp3"}; System.out.println("Using default: " + args[0]); } Modified: trunk/LWJGL/src/java/org/lwjgl/test/fmod3/StreamPlayerMemory.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/fmod3/StreamPlayerMemory.java 2006-06-22 10:42:45 UTC (rev 2382) +++ trunk/LWJGL/src/java/org/lwjgl/test/fmod3/StreamPlayerMemory.java 2006-06-23 08:14:49 UTC (rev 2383) @@ -33,6 +33,7 @@ import java.io.BufferedInputStream; import java.io.ByteArrayOutputStream; +import java.io.File; import java.nio.ByteBuffer; import java.nio.ByteOrder; @@ -54,7 +55,7 @@ System.out.println("Usage:\n StreamPlayerMemory <file>"); // default to phero.mp3 - args = new String[] { "phero2.ogg"}; + args = new String[] { "res" + File.separator + "phero2.ogg"}; System.out.println("Using default: " + args[0]); } @@ -73,7 +74,7 @@ } ByteBuffer data = getData(args[0]); - FSoundStream stream = FSound.FSOUND_Stream_Open(data, FSound.FSOUND_LOADMEMORY, 0, data.capacity()); + FSoundStream stream = FSound.FSOUND_Stream_Open(data, FSound.FSOUND_LOADMEMORY); if (stream != null) { FSound.FSOUND_Stream_Play(0, stream); Modified: trunk/LWJGL/src/java/org/lwjgl/test/fmod3/SyncTest.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/fmod3/SyncTest.java 2006-06-22 10:42:45 UTC (rev 2382) +++ trunk/LWJGL/src/java/org/lwjgl/test/fmod3/SyncTest.java 2006-06-23 08:14:49 UTC (rev 2383) @@ -101,7 +101,7 @@ System.out.println("Usage:\n SyncTest <file>"); // default to Missing_you.mod - args = new String[] { "res\\Missing_you.mod"}; + args = new String[] { "res" + File.separator + "Missing_you.mod"}; System.out.println("Using default: " + args[0]); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2006-06-22 11:43:35
|
Revision: 2382 Author: elias_naur Date: 2006-06-22 03:42:45 -0700 (Thu, 22 Jun 2006) ViewCVS: http://svn.sourceforge.net/java-game-lib/?rev=2382&view=rev Log Message: ----------- Mac OS X: Fix ctrl-click right button handling Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/MouseEventQueue.java Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/MouseEventQueue.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/MouseEventQueue.java 2006-06-20 14:09:27 UTC (rev 2381) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/MouseEventQueue.java 2006-06-22 10:42:45 UTC (rev 2382) @@ -69,6 +69,9 @@ private int last_x; private int last_y; + /** Saved control key state for ctrl-click right button emulation */ + private boolean saved_control_state; + /** Event scratch array */ private final int[] event = new int[EVENT_SIZE]; @@ -156,6 +159,17 @@ } private void handleButton(MouseEvent e) { + byte state; + switch (e.getID()) { + case MouseEvent.MOUSE_PRESSED: + state = 1; + break; + case MouseEvent.MOUSE_RELEASED: + state = 0; + break; + default: + throw new IllegalArgumentException("Not a valid event ID: " + e.getID()); + } byte button; switch (e.getButton()) { case MouseEvent.NOBUTTON: @@ -163,31 +177,27 @@ return; case MouseEvent.BUTTON1: // Emulate right click if ctrl is down - if (!e.isControlDown()) + if (state == 1) + saved_control_state = e.isControlDown(); + if (saved_control_state) { + if (buttons[1] == state) + return; // ignore + button = (byte)1; + } else { button = (byte)0; - else - button = (byte)1; + } break; case MouseEvent.BUTTON2: button = (byte)2; break; case MouseEvent.BUTTON3: + if (buttons[1] == state) + return; // ignore button = (byte)1; break; default: throw new IllegalArgumentException("Not a valid button: " + e.getButton()); } - byte state; - switch (e.getID()) { - case MouseEvent.MOUSE_PRESSED: - state = 1; - break; - case MouseEvent.MOUSE_RELEASED: - state = 0; - break; - default: - throw new IllegalArgumentException("Not a valid event ID: " + e.getID()); - } setButton(button, state); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2006-06-20 14:09:54
|
Revision: 2381 Author: elias_naur Date: 2006-06-20 07:09:27 -0700 (Tue, 20 Jun 2006) ViewCVS: http://svn.sourceforge.net/java-game-lib/?rev=2381&view=rev Log Message: ----------- Windows: Display.getVersion should return null when getAdapter() is null Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/Win32Display.java Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/Win32Display.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/Win32Display.java 2006-06-18 09:08:55 UTC (rev 2380) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/Win32Display.java 2006-06-20 14:09:27 UTC (rev 2381) @@ -86,7 +86,11 @@ } public String getVersion() { - return nGetVersion(getAdapter()); + String driver = getAdapter(); + if (driver != null) + return nGetVersion(driver); + else + return null; } private native String nGetVersion(String driver); public native DisplayMode init() throws LWJGLException; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2006-06-18 09:09:23
|
Revision: 2380 Author: elias_naur Date: 2006-06-18 02:08:55 -0700 (Sun, 18 Jun 2006) ViewCVS: http://svn.sourceforge.net/java-game-lib/?rev=2380&view=rev Log Message: ----------- Windows: Make sure the DirectInput even buffer is properly flushed before switching to grabbed state. Modified Paths: -------------- trunk/LWJGL/src/native/win32/org_lwjgl_input_Mouse.c Modified: trunk/LWJGL/src/native/win32/org_lwjgl_input_Mouse.c =================================================================== --- trunk/LWJGL/src/native/win32/org_lwjgl_input_Mouse.c 2006-06-18 08:51:03 UTC (rev 2379) +++ trunk/LWJGL/src/native/win32/org_lwjgl_input_Mouse.c 2006-06-18 09:08:55 UTC (rev 2380) @@ -324,7 +324,7 @@ { jint* buffer_ptr = (jint *)(*env)->GetDirectBufferAddress(env, buffer_obj) + buffer_position; int buffer_size = ((*env)->GetDirectBufferCapacity(env, buffer_obj))/sizeof(jint) - buffer_position; - readDXBuffer(env); + readDXBuffer(env); return copyEvents(&event_queue, buffer_ptr, buffer_size); } @@ -393,6 +393,8 @@ HRESULT di_res; if(grab) { if (!mouse_grabbed) { + // flush DX event buffer + readDXBuffer(env); mouse_grabbed = true; IDirectInputDevice_Unacquire(mDIDevice); if (!acquireMouse(DISCL_EXCLUSIVE | DISCL_FOREGROUND)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2006-06-18 08:51:12
|
Revision: 2379 Author: elias_naur Date: 2006-06-18 01:51:03 -0700 (Sun, 18 Jun 2006) ViewCVS: http://svn.sourceforge.net/java-game-lib/?rev=2379&view=rev Log Message: ----------- Windows: Fixed spurious mouse button events after a Mouse.setGrabbed(true) Modified Paths: -------------- trunk/LWJGL/src/native/win32/org_lwjgl_input_Mouse.c Modified: trunk/LWJGL/src/native/win32/org_lwjgl_input_Mouse.c =================================================================== --- trunk/LWJGL/src/native/win32/org_lwjgl_input_Mouse.c 2006-06-17 23:46:59 UTC (rev 2378) +++ trunk/LWJGL/src/native/win32/org_lwjgl_input_Mouse.c 2006-06-18 08:51:03 UTC (rev 2379) @@ -247,10 +247,10 @@ static void copyDXEvents(int num_di_events, DIDEVICEOBJECTDATA *di_buffer) { int buffer_index = 0; int dx = 0, dy = 0, dwheel = 0; - int button_state; - int i; - for (i = 0; i < num_di_events; i++) { - button_state = (di_buffer[i].dwData & 0x80) != 0 ? 1 : 0; + int button_state; + int i; + for (i = 0; i < num_di_events; i++) { + button_state = (di_buffer[i].dwData & 0x80) != 0 ? 1 : 0; switch (di_buffer[i].dwOfs) { case DIMOFS_BUTTON0: putMouseEventWithCoords(0, button_state, dx, -dy, dwheel); @@ -300,7 +300,8 @@ 0); if (ret == DI_OK) { - copyDXEvents(num_di_events, rgdod); + if (mouse_grabbed) + copyDXEvents(num_di_events, rgdod); } else if (ret == DI_BUFFEROVERFLOW) { printfDebugJava(env, "Buffer overflowed"); } else if (ret == DIERR_INPUTLOST) { @@ -314,7 +315,7 @@ } else if (ret == DIERR_NOTINITIALIZED) { printfDebugJava(env, "not inited"); } else { - printfDebugJava(env, "unknown keyboard error"); + printfDebugJava(env, "unknown mouse error (%d)", ret); } } @@ -323,9 +324,7 @@ { jint* buffer_ptr = (jint *)(*env)->GetDirectBufferAddress(env, buffer_obj) + buffer_position; int buffer_size = ((*env)->GetDirectBufferCapacity(env, buffer_obj))/sizeof(jint) - buffer_position; - if (mouse_grabbed) { readDXBuffer(env); - } return copyEvents(&event_queue, buffer_ptr, buffer_size); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2006-06-17 23:47:27
|
Revision: 2378 Author: elias_naur Date: 2006-06-17 16:46:59 -0700 (Sat, 17 Jun 2006) ViewCVS: http://svn.sourceforge.net/java-game-lib/?rev=2378&view=rev Log Message: ----------- Windows: Fix Windows sometimes marking LWJGL apps as "not responding" Modified Paths: -------------- trunk/LWJGL/src/native/win32/org_lwjgl_opengl_Display.c Modified: trunk/LWJGL/src/native/win32/org_lwjgl_opengl_Display.c =================================================================== --- trunk/LWJGL/src/native/win32/org_lwjgl_opengl_Display.c 2006-06-16 13:30:27 UTC (rev 2377) +++ trunk/LWJGL/src/native/win32/org_lwjgl_opengl_Display.c 2006-06-17 23:46:59 UTC (rev 2378) @@ -248,13 +248,21 @@ if (display_hwnd != NULL) { while (PeekMessage( &msg, // message information - display_hwnd, // handle to window + NULL, // handle to window 0, // first message 0, // last message PM_REMOVE // removal options )) { - DispatchMessage(&msg); + /* + * It would be better to filter messages + * to display_hwnd by specifying that to + * PeekMessage instead of this check. However, + * Windows will then mark LWJGL apps as "not + * responding". + */ + if (msg.hwnd == display_hwnd) + DispatchMessage(&msg); } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2006-06-16 13:30:32
|
Revision: 2377 Author: elias_naur Date: 2006-06-16 06:30:27 -0700 (Fri, 16 Jun 2006) ViewCVS: http://svn.sourceforge.net/java-game-lib/?rev=2377&view=rev Log Message: ----------- Added missing static methods to Quaternion for consistency. Cleaned up handling of src == dest aliasing Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/util/vector/Quaternion.java Modified: trunk/LWJGL/src/java/org/lwjgl/util/vector/Quaternion.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/vector/Quaternion.java 2006-06-16 12:44:53 UTC (rev 2376) +++ trunk/LWJGL/src/java/org/lwjgl/util/vector/Quaternion.java 2006-06-16 13:30:27 UTC (rev 2377) @@ -43,16 +43,16 @@ import java.nio.FloatBuffer; public class Quaternion extends Vector implements ReadableVector4f { - private static final long serialVersionUID = 1L; - private float x, y, z, w; + public float x, y, z, w; /** - * C'tor + * C'tor. The quaternion will be initialized to the identity. */ public Quaternion() { super(); + setIdentity(); } /** @@ -124,6 +124,27 @@ } /** + * Set this quaternion to the multiplication identity. + * @return this + */ + public Quaternion setIdentity() { + return setIdentity(this); + } + + /** + * Set the given quaternion to the multiplication identity. + * @param q The quaternion + * @return q + */ + public static Quaternion setIdentity(Quaternion q) { + q.x = 0; + q.y = 0; + q.z = 0; + q.w = 1; + return q; + } + + /** * @return the length squared of the quaternion */ public float lengthSquared() { @@ -131,25 +152,39 @@ } /** - * Normalise this vector and place the result in another vector. + * Normalise the source quaternion and place the result in another quaternion. * + * @param src + * The source quaternion * @param dest - * The destination vector, or null if a new vector is to be + * The destination quaternion, or null if a new quaternion is to be * created - * @return the normalised vector + * @return The normalised quaternion */ - public Quaternion normalise(Quaternion dest) { - float l = length(); + public static Quaternion normalise(Quaternion src, Quaternion dest) { + float inv_l = 1f/src.length(); if (dest == null) - dest = new Quaternion(x / l, y / l, z / l, w / l); - else - dest.set(x / l, y / l, z / l, w / l); + dest = new Quaternion(); + dest.set(src.x * inv_l, src.y * inv_l, src.z * inv_l, src.w * inv_l); + return dest; } /** + * Normalise this quaternion and place the result in another quaternion. + * + * @param dest + * The destination quaternion, or null if a new quaternion is to be + * created + * @return the normalised quaternion + */ + public Quaternion normalise(Quaternion dest) { + return normalise(this, dest); + } + + /** * The dot product of two quaternions * * @param left @@ -171,13 +206,26 @@ * quaternion */ public Quaternion negate(Quaternion dest) { + return negate(this, dest); + } + + /** + * Calculate the conjugate of this quaternion and put it into the given one + * + * @param src + * The source quaternion + * @param dest + * The quaternion which should be set to the conjugate of this + * quaternion + */ + public static Quaternion negate(Quaternion src, Quaternion dest) { if (dest == null) dest = new Quaternion(); - dest.x = -x; - dest.y = -y; - dest.z = -z; - dest.w = w; + dest.x = -src.x; + dest.y = -src.y; + dest.z = -src.z; + dest.w = src.w; return dest; } @@ -186,11 +234,7 @@ * Calculate the conjugate of this quaternion */ public Vector negate() { - x = -x; - y = -y; - z = -z; - - return this; + return negate(this, this); } /* (non-Javadoc) @@ -210,12 +254,25 @@ * @see org.lwjgl.vector.Vector#scale(float) */ public Vector scale(float scale) { - x *= scale; - y *= scale; - z *= scale; - w *= scale; - return this; + return scale(scale, this, this); } + + /** + * Scale the source quaternion by scale and put the result in the destination + * @param scale The amount to scale by + * @param src The source quaternion + * @param dest The destination quaternion, or null if a new quaternion is to be created + * @return The scaled quaternion + */ + public static Quaternion scale(float scale, Quaternion src, Quaternion dest) { + if (dest == null) + dest = new Quaternion(); + dest.x = src.x * scale; + dest.y = src.y * scale; + dest.z = src.z * scale; + dest.w = src.w * scale; + return dest; + } /* (non-Javadoc) * @see org.lwjgl.util.vector.ReadableVector#store(java.nio.FloatBuffer) @@ -314,21 +371,14 @@ public static Quaternion mul(Quaternion left, Quaternion right, Quaternion dest) { if (dest == null) - return new Quaternion(left.x * right.w + left.w * right.x + left.y - * right.z - left.z * right.y, left.y * right.w + left.w - * right.y + left.z * right.x - left.x * right.z, left.z - * right.w + left.w * right.z + left.x * right.y - left.y - * right.x, left.w * right.w - left.x * right.x - left.y - * right.y - left.z * right.z); - else { - dest.set(left.x * right.w + left.w * right.x + left.y * right.z - - left.z * right.y, left.y * right.w + left.w * right.y - + left.z * right.x - left.x * right.z, left.z * right.w - + left.w * right.z + left.x * right.y - left.y * right.x, - left.w * right.w - left.x * right.x - left.y * right.y - - left.z * right.z); - return dest; - } + dest = new Quaternion(); + dest.set(left.x * right.w + left.w * right.x + left.y * right.z + - left.z * right.y, left.y * right.w + left.w * right.y + + left.z * right.x - left.x * right.z, left.z * right.w + + left.w * right.z + left.x * right.y - left.y * right.x, + left.w * right.w - left.x * right.x - left.y * right.y + - left.z * right.z); + return dest; } /** @@ -349,29 +399,19 @@ n = (n == 0.0 ? n : 1 / n); // store on stack once for aliasing-safty if (dest == null) - return new Quaternion((left.x * right.w - left.w * right.x - left.y - * right.z + left.z * right.y) + dest = new Quaternion(); + dest + .set((left.x * right.w - left.w * right.x - left.y + * right.z + left.z * right.y) * n, (left.y * right.w - left.w * right.y - left.z - * right.x + left.x * right.z) + * right.x + left.x * right.z) * n, (left.z * right.w - left.w * right.z - left.x - * right.y + left.y * right.x) + * right.y + left.y * right.x) * n, (left.w * right.w + left.x * right.x + left.y - * right.y + left.z * right.z) + * right.y + left.z * right.z) * n); - else { - dest - .set((left.x * right.w - left.w * right.x - left.y - * right.z + left.z * right.y) - * n, (left.y * right.w - left.w * right.y - left.z - * right.x + left.x * right.z) - * n, (left.z * right.w - left.w * right.z - left.x - * right.y + left.y * right.x) - * n, (left.w * right.w + left.x * right.x + left.y - * right.y + left.z * right.z) - * n); - return dest; - } + return dest; } /** @@ -399,29 +439,58 @@ * passed matrix. * * @param m1 - * the matrix4f + * The matrix + * @return this */ - public final void setFromMatrix(Matrix4f m1) { - setFromMat(m1.m00, m1.m01, m1.m02, m1.m10, m1.m11, m1.m12, m1.m20, - m1.m21, m1.m22); + public final Quaternion setFromMatrix(Matrix4f m) { + return setFromMatrix(m, this); } /** + * Sets the value of the source quaternion using the rotational component of the + * passed matrix. + * + * @param m + * The source matrix + * @param q + * The destination quaternion, or null if a new quaternion is to be created + * @return + */ + public final static Quaternion setFromMatrix(Matrix4f m, Quaternion q) { + return q.setFromMat(m.m00, m.m01, m.m02, m.m10, m.m11, m.m12, m.m20, + m.m21, m.m22); + } + + /** * Sets the value of this quaternion using the rotational component of the * passed matrix. * - * @param m1 - * the matrix3f + * @param m + * The source matrix */ - public final void setFromMatrix(Matrix3f m1) { - setFromMat(m1.m00, m1.m01, m1.m02, m1.m10, m1.m11, m1.m12, m1.m20, - m1.m21, m1.m22); + public final Quaternion setFromMatrix(Matrix3f m) { + return setFromMatrix(m, this); } /** + * Sets the value of the source quaternion using the rotational component of the + * passed matrix. + * + * @param m + * The source matrix + * @param q + * The destination quaternion, or null if a new quaternion is to be created + * @return + */ + public static final Quaternion setFromMatrix(Matrix3f m, Quaternion q) { + return q.setFromMat(m.m00, m.m01, m.m02, m.m10, m.m11, m.m12, m.m20, + m.m21, m.m22); + } + + /** * Private method to perform the matrix-to-quaternion conversion */ - private void setFromMat(float m00, float m01, float m02, float m10, + private Quaternion setFromMat(float m00, float m01, float m02, float m10, float m11, float m12, float m20, float m21, float m22) { float s; @@ -458,6 +527,6 @@ w = (m10 - m01) * s; } } + return this; } - -} \ No newline at end of file +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |