Style normalizations to the joystick code.

git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@349 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
rkrolib 2003-11-15 16:39:46 +00:00
parent 2b78c976ea
commit 1fe1473fbb

View File

@ -34,7 +34,7 @@
* FreeBSD port by Stephen Montgomery-Smith <stephen@math.missouri.edu> * FreeBSD port by Stephen Montgomery-Smith <stephen@math.missouri.edu>
*/ */
#if defined(__FreeBSD__) || defined(__NetBSD__) #if defined( __FreeBSD__ ) || defined( __NetBSD__ )
#include <sys/param.h> #include <sys/param.h>
#endif #endif
@ -158,7 +158,7 @@ static SFG_Joystick* fgJoystick = NULL;
/* /*
* Read the raw joystick data * Read the raw joystick data
*/ */
static void fghJoystickRawRead ( SFG_Joystick* joy, int* buttons, float* axes ) static void fghJoystickRawRead( SFG_Joystick* joy, int* buttons, float* axes )
{ {
#ifdef WIN32 #ifdef WIN32
MMRESULT status; MMRESULT status;
@ -171,7 +171,7 @@ static void fghJoystickRawRead ( SFG_Joystick* joy, int* buttons, float* axes )
if( joy->error ) if( joy->error )
{ {
if( buttons ) if( buttons )
*buttons = 0 ; *buttons = 0;
if( axes ) if( axes )
for( i=0; i<joy->num_axes; i++ ) for( i=0; i<joy->num_axes; i++ )
@ -214,7 +214,7 @@ static void fghJoystickRawRead ( SFG_Joystick* joy, int* buttons, float* axes )
{ {
status = read( joy->fd, &joy->js, sizeof(struct js_event) ); status = read( joy->fd, &joy->js, sizeof(struct js_event) );
if( status != sizeof(struct js_event) ) if( status != sizeof( struct js_event ) )
{ {
if( errno == EAGAIN ) if( errno == EAGAIN )
{ {
@ -225,7 +225,7 @@ static void fghJoystickRawRead ( SFG_Joystick* joy, int* buttons, float* axes )
*buttons = joy->tmp_buttons; *buttons = joy->tmp_buttons;
if( axes ) if( axes )
memcpy( axes, joy->tmp_axes, memcpy( axes, joy->tmp_axes,
sizeof(float) * joy->num_axes ); sizeof( float ) * joy->num_axes );
return; return;
} }
@ -237,14 +237,14 @@ static void fghJoystickRawRead ( SFG_Joystick* joy, int* buttons, float* axes )
switch( joy->js.type & ~JS_EVENT_INIT ) switch( joy->js.type & ~JS_EVENT_INIT )
{ {
case JS_EVENT_BUTTON: case JS_EVENT_BUTTON:
if ( joy->js.value == 0 ) /* clear the flag */ if( joy->js.value == 0 ) /* clear the flag */
joy->tmp_buttons &= ~(1 << joy->js.number); joy->tmp_buttons &= ~( 1 << joy->js.number );
else else
joy->tmp_buttons |= (1 << joy->js.number); joy->tmp_buttons |= ( 1 << joy->js.number );
break; break;
case JS_EVENT_AXIS: case JS_EVENT_AXIS:
joy->tmp_axes[ joy->js.number ] = (float) joy->js.value; joy->tmp_axes[ joy->js.number ] = ( float )joy->js.value;
if( axes ) if( axes )
memcpy( axes, joy->tmp_axes, sizeof(float) * joy->num_axes ); memcpy( axes, joy->tmp_axes, sizeof(float) * joy->num_axes );
@ -266,8 +266,8 @@ static void fghJoystickRawRead ( SFG_Joystick* joy, int* buttons, float* axes )
} }
if( buttons ) if( buttons )
# if defined(__FreeBSD__) || defined(__NetBSD__) # if defined( __FreeBSD__ ) || defined( __NetBSD__ )
*buttons = (joy->js.b1 ? 1 : 0) | (joy->js.b2 ? 2 : 0); *buttons = ( joy->js.b1 ? 1 : 0 ) | ( joy->js.b2 ? 2 : 0 );
# else # else
*buttons = joy->js.buttons; *buttons = joy->js.buttons;
# endif # endif
@ -288,8 +288,8 @@ static float fghJoystickFudgeAxis( SFG_Joystick* joy, float value, int axis )
{ {
if( value < joy->center[ axis ] ) if( value < joy->center[ axis ] )
{ {
float xx = (value - joy->center[ axis ]) / (joy->center[ axis ] - float xx = ( value - joy->center[ axis ] ) / ( joy->center[ axis ] -
joy->min[ axis ]); joy->min[ axis ] );
if( xx < -joy->saturate[ axis ] ) if( xx < -joy->saturate[ axis ] )
return -1.0f; return -1.0f;
@ -297,24 +297,24 @@ static float fghJoystickFudgeAxis( SFG_Joystick* joy, float value, int axis )
if( xx > -joy->dead_band [ axis ] ) if( xx > -joy->dead_band [ axis ] )
return 0.0f; return 0.0f;
xx = (xx + joy->dead_band[ axis ]) / (joy->saturate[ axis ] - xx = ( xx + joy->dead_band[ axis ] ) / ( joy->saturate[ axis ] -
joy->dead_band[ axis ]); joy->dead_band[ axis ] );
return ( xx < -1.0f ) ? -1.0f : xx; return ( xx < -1.0f ) ? -1.0f : xx;
} }
else else
{ {
float xx = (value - joy->center [ axis ]) / (joy->max[ axis ] - float xx = ( value - joy->center [ axis ] ) / ( joy->max[ axis ] -
joy->center[ axis ]); joy->center[ axis ] );
if( xx > joy->saturate[ axis ] ) if( xx > joy->saturate[ axis ] )
return 1.0f ; return 1.0f;
if( xx < joy->dead_band[ axis ] ) if( xx < joy->dead_band[ axis ] )
return 0.0f ; return 0.0f;
xx = (xx - joy->dead_band[ axis ]) / (joy->saturate[ axis ] - xx = ( xx - joy->dead_band[ axis ] ) / ( joy->saturate[ axis ] -
joy->dead_band[ axis ]); joy->dead_band[ axis ] );
return ( xx > 1.0f ) ? 1.0f : xx; return ( xx > 1.0f ) ? 1.0f : xx;
} }
@ -357,13 +357,13 @@ static void fghJoystickOpen( SFG_Joystick* joy )
joy->js.dwFlags = JOY_RETURNALL; joy->js.dwFlags = JOY_RETURNALL;
joy->js.dwSize = sizeof( joy->js ); joy->js.dwSize = sizeof( joy->js );
memset( &jsCaps, 0, sizeof(jsCaps) ); memset( &jsCaps, 0, sizeof( jsCaps ) );
joy->error = joy->error =
(joyGetDevCaps( joy->js_id, &jsCaps, sizeof(jsCaps) ) != ( joyGetDevCaps( joy->js_id, &jsCaps, sizeof( jsCaps ) ) !=
JOYERR_NOERROR); JOYERR_NOERROR );
joy->num_axes = joy->num_axes =
(jsCaps.wNumAxes < _JS_MAX_AXES ) ? jsCaps.wNumAxes : _JS_MAX_AXES; ( jsCaps.wNumAxes < _JS_MAX_AXES ) ? jsCaps.wNumAxes : _JS_MAX_AXES;
/* /*
* WARNING - Fall through case clauses!! * WARNING - Fall through case clauses!!
@ -448,12 +448,12 @@ static void fghJoystickOpen( SFG_Joystick* joy )
fghJoystickRawRead(joy, buttons, axes ); fghJoystickRawRead(joy, buttons, axes );
joy->error = axes[ 0 ] < -1000000000.0f; joy->error = axes[ 0 ] < -1000000000.0f;
if( joy->error ) if( joy->error )
return ; return;
sprintf( joyfname, "%s/.joy%drc", getenv( "HOME" ), joy->id ); sprintf( joyfname, "%s/.joy%drc", getenv( "HOME" ), joy->id );
joyfile = fopen( joyfname, "r" ); joyfile = fopen( joyfname, "r" );
joy->error = (joyfile == NULL); joy->error =( joyfile == NULL );
if( joy->error ) if( joy->error )
return; return;
@ -464,12 +464,12 @@ static void fghJoystickOpen( SFG_Joystick* joy )
&joy->min[ 1 ], &joy->center[ 1 ], &joy->max[ 1 ] &joy->min[ 1 ], &joy->center[ 1 ], &joy->max[ 1 ]
); );
joy->error = (noargs != 7) || (in_no_axes != _JS_MAX_AXES); joy->error =( noargs != 7 ) || ( in_no_axes != _JS_MAX_AXES );
fclose( joyfile ); fclose( joyfile );
if( joy->error ) if( joy->error )
return; return;
for( i=0 ; i<_JS_MAX_AXES ; i++ ) for( i = 0; i < _JS_MAX_AXES; i++ )
{ {
joy->dead_band[ i ] = 0.0f; joy->dead_band[ i ] = 0.0f;
joy->saturate [ i ] = 1.0f; joy->saturate [ i ] = 1.0f;
@ -496,7 +496,7 @@ static void fghJoystickOpen( SFG_Joystick* joy )
* PWO: shouldn't be that done somehow wiser on the kernel level? * PWO: shouldn't be that done somehow wiser on the kernel level?
*/ */
# ifndef JS_NEW # ifndef JS_NEW
counter = 0 ; counter = 0;
do do
{ {
@ -511,7 +511,7 @@ static void fghJoystickOpen( SFG_Joystick* joy )
joy->error = TRUE; joy->error = TRUE;
# endif # endif
for( i=0 ; i<_JS_MAX_AXES ; i++ ) for( i = 0; i < _JS_MAX_AXES; i++ )
{ {
# ifdef JS_NEW # ifdef JS_NEW
joy->max [ i ] = 32767.0f; joy->max [ i ] = 32767.0f;
@ -533,10 +533,10 @@ static void fghJoystickOpen( SFG_Joystick* joy )
*/ */
void fgJoystickInit( int ident ) void fgJoystickInit( int ident )
{ {
if( fgJoystick != NULL ) if( fgJoystick )
fgError( "illegal attemp to initialize joystick device" ); fgError( "illegal attemp to initialize joystick device" );
fgJoystick = (SFG_Joystick *)calloc( sizeof(SFG_Joystick), 1 ); fgJoystick = ( SFG_Joystick * )calloc( sizeof( SFG_Joystick ), 1 );
#ifdef WIN32 #ifdef WIN32
switch( ident ) switch( ident )
@ -575,7 +575,7 @@ void fgJoystickInit( int ident )
*/ */
void fgJoystickClose( void ) void fgJoystickClose( void )
{ {
if( fgJoystick == NULL ) if( !fgJoystick )
fgError( "illegal attempt to deinitialize joystick device" ); fgError( "illegal attempt to deinitialize joystick device" );
#ifndef WIN32 #ifndef WIN32
@ -583,8 +583,8 @@ void fgJoystickClose( void )
close( fgJoystick->fd ); close( fgJoystick->fd );
#endif #endif
free ( fgJoystick ) ; free( fgJoystick );
fgJoystick = NULL ; /* show joystick has been deinitialized */ fgJoystick = NULL; /* show joystick has been deinitialized */
} }
/* /*
@ -596,7 +596,8 @@ void fgJoystickPollWindow( SFG_Window* window )
float axes[ _JS_MAX_AXES ]; float axes[ _JS_MAX_AXES ];
int buttons; int buttons;
freeglut_return_if_fail( fgJoystick != NULL && window != NULL ); freeglut_return_if_fail( fgJoystick );
freeglut_return_if_fail( window );
freeglut_return_if_fail( FETCH_WCB( *window, Joystick ) ); freeglut_return_if_fail( FETCH_WCB( *window, Joystick ) );
fghJoystickRead( fgJoystick, &buttons, axes ); fghJoystickRead( fgJoystick, &buttons, axes );