joystick init fixes (John Fay)
git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@523 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
parent
20ecbd409c
commit
8fd086e068
@ -171,12 +171,7 @@ void FGAPIENTRY glutJoystickFunc( void (* callback)
|
|||||||
( unsigned int, int, int, int ),
|
( unsigned int, int, int, int ),
|
||||||
int pollInterval )
|
int pollInterval )
|
||||||
{
|
{
|
||||||
if( !fgState.JoysticksInitialised )
|
fgInitialiseJoysticks ();
|
||||||
{
|
|
||||||
fgJoystickInit( 0 );
|
|
||||||
fgJoystickInit( 1 );
|
|
||||||
fgState.JoysticksInitialised = GL_TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
SET_CALLBACK( Joystick );
|
SET_CALLBACK( Joystick );
|
||||||
fgStructure.Window->State.JoystickPollRate = pollInterval;
|
fgStructure.Window->State.JoystickPollRate = pollInterval;
|
||||||
|
@ -704,10 +704,16 @@ SFG_Menu* fgCreateMenu( FGCBMenu menuCallback );
|
|||||||
void fgDestroyMenu( SFG_Menu* menu );
|
void fgDestroyMenu( SFG_Menu* menu );
|
||||||
|
|
||||||
/* Joystick device management functions, defined in freeglut_joystick.c */
|
/* Joystick device management functions, defined in freeglut_joystick.c */
|
||||||
void fgJoystickInit( int ident );
|
int fgJoystickDetect( void );
|
||||||
|
void fgInitialiseJoysticks( void );
|
||||||
void fgJoystickClose( void );
|
void fgJoystickClose( void );
|
||||||
void fgJoystickPollWindow( SFG_Window* window );
|
void fgJoystickPollWindow( SFG_Window* window );
|
||||||
|
|
||||||
|
/* More joystick functions. Should these go into the API? */
|
||||||
|
int glutJoystickGetNumAxes( int ident );
|
||||||
|
int glutJoystickGetNumButtons( int ident );
|
||||||
|
int glutJoystickNotWorking( int ident );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Helper function to enumerate through all registered windows
|
* Helper function to enumerate through all registered windows
|
||||||
* and one to enumerate all of a window's subwindows...
|
* and one to enumerate all of a window's subwindows...
|
||||||
|
@ -450,7 +450,6 @@ static void fghJoystickAddHatElement ( SFG_Joystick* joy, CFDictionaryRef hat );
|
|||||||
* The static joystick structure pointer
|
* The static joystick structure pointer
|
||||||
*/
|
*/
|
||||||
#define MAX_NUM_JOYSTICKS 2
|
#define MAX_NUM_JOYSTICKS 2
|
||||||
static int fgNumberOfJoysticks = 0;
|
|
||||||
static SFG_Joystick *fgJoystick [ MAX_NUM_JOYSTICKS ];
|
static SFG_Joystick *fgJoystick [ MAX_NUM_JOYSTICKS ];
|
||||||
|
|
||||||
|
|
||||||
@ -1528,7 +1527,7 @@ static void fghJoystickOpen( SFG_Joystick* joy )
|
|||||||
/*
|
/*
|
||||||
* This function replaces the constructor method in the JS library.
|
* This function replaces the constructor method in the JS library.
|
||||||
*/
|
*/
|
||||||
void fgJoystickInit( int ident )
|
static void fghJoystickInit( int ident )
|
||||||
{
|
{
|
||||||
if( ident >= MAX_NUM_JOYSTICKS )
|
if( ident >= MAX_NUM_JOYSTICKS )
|
||||||
fgError( "Too large a joystick number: %d", ident );
|
fgError( "Too large a joystick number: %d", ident );
|
||||||
@ -1638,6 +1637,22 @@ void fgJoystickInit( int ident )
|
|||||||
fghJoystickOpen( fgJoystick[ ident ] );
|
fghJoystickOpen( fgJoystick[ ident ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Try initializing all the joysticks (well, both of them)
|
||||||
|
*/
|
||||||
|
void fgInitialiseJoysticks ( void )
|
||||||
|
{
|
||||||
|
/* Initialization courtesy of OpenGLUT -- do we want it? */
|
||||||
|
if( !fgState.JoysticksInitialised )
|
||||||
|
{
|
||||||
|
int ident ;
|
||||||
|
for ( ident = 0; ident < MAX_NUM_JOYSTICKS; ident++ )
|
||||||
|
fghJoystickInit( ident );
|
||||||
|
|
||||||
|
fgState.JoysticksInitialised = GL_TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -1722,12 +1737,38 @@ void fgJoystickPollWindow( SFG_Window* window )
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* PWO: These jsJoystick class methods have not been implemented.
|
* Implementation for glutDeviceGet(GLUT_HAS_JOYSTICK)
|
||||||
|
*/
|
||||||
|
int fgJoystickDetect( void )
|
||||||
|
{
|
||||||
|
int ident;
|
||||||
|
|
||||||
|
fgInitialiseJoysticks ();
|
||||||
|
|
||||||
|
if ( !fgJoystick )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if ( !fgState.JoysticksInitialised )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
for( ident=0; ident<MAX_NUM_JOYSTICKS; ident++ )
|
||||||
|
if( fgJoystick[ident] && !fgJoystick[ident]->error )
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Joystick information functions
|
||||||
*/
|
*/
|
||||||
int glutJoystickGetNumAxes( int ident )
|
int glutJoystickGetNumAxes( int ident )
|
||||||
{
|
{
|
||||||
return fgJoystick[ ident ]->num_axes;
|
return fgJoystick[ ident ]->num_axes;
|
||||||
}
|
}
|
||||||
|
int glutJoystickGetNumButtons( int ident )
|
||||||
|
{
|
||||||
|
return fgJoystick[ ident ]->num_buttons;
|
||||||
|
}
|
||||||
int glutJoystickNotWorking( int ident )
|
int glutJoystickNotWorking( int ident )
|
||||||
{
|
{
|
||||||
return fgJoystick[ ident ]->error;
|
return fgJoystick[ ident ]->error;
|
||||||
|
@ -528,13 +528,21 @@ int FGAPIENTRY glutDeviceGet( GLenum eWhat )
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
case GLUT_JOYSTICK_POLL_RATE:
|
|
||||||
case GLUT_HAS_JOYSTICK:
|
case GLUT_HAS_JOYSTICK:
|
||||||
|
return fgJoystickDetect ();
|
||||||
|
|
||||||
case GLUT_OWNS_JOYSTICK:
|
case GLUT_OWNS_JOYSTICK:
|
||||||
|
return fgState.JoysticksInitialised;
|
||||||
|
|
||||||
|
case GLUT_JOYSTICK_POLL_RATE:
|
||||||
|
return fgStructure.Window ? fgStructure.Window->State.JoystickPollRate : 0;
|
||||||
|
|
||||||
|
/* The following two are only for Joystick 0 but this is an improvement */
|
||||||
case GLUT_JOYSTICK_BUTTONS:
|
case GLUT_JOYSTICK_BUTTONS:
|
||||||
|
return glutJoystickGetNumButtons ( 0 );
|
||||||
|
|
||||||
case GLUT_JOYSTICK_AXES:
|
case GLUT_JOYSTICK_AXES:
|
||||||
/* XXX WARNING: THIS IS A BIG LIE! */
|
return glutJoystickGetNumAxes ( 0 );
|
||||||
return 0;
|
|
||||||
|
|
||||||
case GLUT_HAS_SPACEBALL:
|
case GLUT_HAS_SPACEBALL:
|
||||||
case GLUT_HAS_DIAL_AND_BUTTON_BOX:
|
case GLUT_HAS_DIAL_AND_BUTTON_BOX:
|
||||||
|
Reference in New Issue
Block a user