[Plib-cvs] plib/src/js README,NONE,1.1 jsBSD.cxx,NONE,1.1 jsLinux.cxx,NONE,1.1 jsLinuxOld.cxx,NONE,1
Brought to you by:
sjbaker
From: Steve B. <sj...@us...> - 2002-11-29 19:39:51
|
Update of /cvsroot/plib/plib/src/js In directory sc8-pr-cvs1:/tmp/cvs-serv26502/plib/src/js Modified Files: Makefile.am js.cxx js.h Added Files: README jsBSD.cxx jsLinux.cxx jsLinuxOld.cxx jsMacOS.cxx jsWindows.cxx Log Message: Major rework of JS library. Cleaned up OS type flags in conditional compilations. --- NEW FILE: README --- Joystick interfaces are horribly non-portable. Using conditional compilation on a line-by-line basis became FAR too complex after more than a couple of OS's were supported so now there is on standard interface header: js.h ...one set of common routines: js.cxx ...and a bunch of OS-specific code: jsLinux.cxx jsLinuxOld.cxx jsWindows.cxx jsBSD.cxx jsMacOS.cxx --- NEW FILE: jsBSD.cxx --- /* PLIB - A Suite of Portable Game Libraries Copyright (C) 1998,2002 Steve Baker This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA For further information visit http://plib.sourceforge.net [...104 lines suppressed...] if ( status != JS_RETURN_SIZE ) { perror ( fname ) ; setError () ; return ; } if ( buttons != NULL ) *buttons = ( js.b1 ? 1 : 0 ) | ( js.b2 ? 2 : 0 ) ; if ( axes != NULL ) { axes[0] = (float) js.x ; axes[1] = (float) js.y ; } } #endif --- NEW FILE: jsLinux.cxx --- /* PLIB - A Suite of Portable Game Libraries Copyright (C) 1998,2002 Steve Baker This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA For further information visit http://plib.sourceforge.net [...126 lines suppressed...] default: ulSetError ( UL_WARNING, "PLIB_JS: Unrecognised /dev/js return!?!" ) ; /* use the old values */ if ( buttons != NULL ) *buttons = tmp_buttons ; if ( axes != NULL ) memcpy ( axes, tmp_axes, sizeof(float) * num_axes ) ; return ; } if ( buttons != NULL ) *buttons = tmp_buttons ; } } #endif --- NEW FILE: jsLinuxOld.cxx --- /* PLIB - A Suite of Portable Game Libraries Copyright (C) 1998,2002 Steve Baker This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA For further information visit http://plib.sourceforge.net [...94 lines suppressed...] if ( status != JS_RETURN ) { perror ( fname ) ; setError () ; return ; } if ( buttons != NULL ) *buttons = js.buttons ; if ( axes != NULL ) { axes[0] = (float) js.x ; axes[1] = (float) js.y ; } } #endif --- NEW FILE: jsMacOS.cxx --- /* PLIB - A Suite of Portable Game Libraries Copyright (C) 1998,2002 Steve Baker This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA For further information visit http://plib.sourceforge.net [...159 lines suppressed...] err = ISpElement_GetSimpleState ( isp_elem [ i + isp_num_axis ], &state) ; ISP_CHECK_ERR(err) *buttons |= state << i ; } } if ( axes != NULL ) { for ( i = 0 ; i < num_axes ; i++ ) { err = ISpElement_GetSimpleState ( isp_elem [ i ], &state ) ; ISP_CHECK_ERR(err) axes [i] = (float) state ; } } } #endif --- NEW FILE: jsWindows.cxx --- /* PLIB - A Suite of Portable Game Libraries Copyright (C) 1998,2002 Steve Baker This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA For further information visit http://plib.sourceforge.net [...209 lines suppressed...] axes [ 7 ] = ( s < 0.0 ) ? -c/s : c/s ; } } case 6: axes[5] = (float) js . dwVpos ; case 5: axes[4] = (float) js . dwUpos ; case 4: axes[3] = (float) js . dwRpos ; case 3: axes[2] = (float) js . dwZpos ; case 2: axes[1] = (float) js . dwYpos ; case 1: axes[0] = (float) js . dwXpos ; break; default: ulSetError ( UL_WARNING, "PLIB_JS: Wrong num_axes. Joystick input is now invalid" ) ; } } } #endif Index: Makefile.am =================================================================== RCS file: /cvsroot/plib/plib/src/js/Makefile.am,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- Makefile.am 1 Sep 2002 00:29:28 -0000 1.7 +++ Makefile.am 29 Nov 2002 19:39:48 -0000 1.8 @@ -4,7 +4,8 @@ include_HEADERS = js.h -libplibjs_a_SOURCES = js.cxx +libplibjs_a_SOURCES = js.cxx jsLinux.cxx jsLinuxOld.cxx jsMacOS.cxx \ + jsWindows.cxx jsBSD.cxx INCLUDES = -I$(top_srcdir)/src/util Index: js.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/js/js.cxx,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- js.cxx 2 Sep 2002 06:05:43 -0000 1.2 +++ js.cxx 29 Nov 2002 19:39:48 -0000 1.3 @@ -24,4 +24,64 @@ void jsInit () {} +float jsJoystick::fudge_axis ( float value, int axis ) const +{ + if ( value < center[axis] ) + { + float xx = ( value - center[ axis ] ) / + ( center [ axis ] - min [ axis ] ) ; + + if ( xx < -saturate [ axis ] ) + return -1.0f ; + + if ( xx > -dead_band [ axis ] ) + return 0.0f ; + + xx = ( xx + dead_band [ axis ] ) / + ( saturate [ axis ] - dead_band [ axis ] ) ; + + return ( xx < -1.0f ) ? -1.0f : xx ; + } + else + { + float xx = ( value - center [ axis ] ) / + ( max [ axis ] - center [ axis ] ) ; + + if ( xx > saturate [ axis ] ) + return 1.0f ; + + if ( xx < dead_band [ axis ] ) + return 0.0f ; + + xx = ( xx - dead_band [ axis ] ) / + ( saturate [ axis ] - dead_band [ axis ] ) ; + + return ( xx > 1.0f ) ? 1.0f : xx ; + } +} + + +void jsJoystick::read ( int *buttons, float *axes ) +{ + if ( error ) + { + if ( buttons ) + *buttons = 0 ; + + if ( axes ) + for ( int i = 0 ; i < num_axes ; i++ ) + axes[i] = 0.0f ; + + return ; + } + + float raw_axes [ _JS_MAX_AXES ] ; + + rawRead ( buttons, raw_axes ) ; + + if ( axes ) + for ( int i = 0 ; i < num_axes ; i++ ) + axes[i] = fudge_axis ( raw_axes[i], i ) ; +} + Index: js.h =================================================================== RCS file: /cvsroot/plib/plib/src/js/js.h,v retrieving revision 1.26 retrieving revision 1.27 diff -u -d -r1.26 -r1.27 --- js.h 9 Sep 2002 22:27:53 -0000 1.26 +++ js.h 29 Nov 2002 19:39:48 -0000 1.27 @@ -30,121 +30,75 @@ #include <stdlib.h> #include <string.h> // -dw- for memcpy -#ifdef macintosh -# include <InputSprocket.h> -#endif - -/* - FreeBSD port - courtesy of Stephen Montgomery-Smith - <st...@ma...> - [...834 lines suppressed...] -# if defined(__FreeBSD__) || defined(__NetBSD__) - *buttons = ( js.b1 ? 1 : 0 ) | ( js.b2 ? 2 : 0 ) ; -# else - *buttons = js.buttons ; -# endif - - if ( axes != NULL ) - { - axes[0] = (float) js.x ; - axes[1] = (float) js.y ; - } -# endif -} - -#endif - -//lint -restore #endif |