src/joystick/SDL_joystick.c
branchSDL-1.2
changeset 5858 b406b7d61494
parent 5857 772a7dbfbccf
child 6047 54b2716f595d
equal deleted inserted replaced
5857:772a7dbfbccf 5858:b406b7d61494
    36 #define SDL_Unlock_EventThread()
    36 #define SDL_Unlock_EventThread()
    37 #endif
    37 #endif
    38 
    38 
    39 Uint8 SDL_numjoysticks = 0;
    39 Uint8 SDL_numjoysticks = 0;
    40 SDL_Joystick **SDL_joysticks = NULL;
    40 SDL_Joystick **SDL_joysticks = NULL;
    41 static SDL_Joystick *default_joystick = NULL;
       
    42 
    41 
    43 int SDL_JoystickInit(void)
    42 int SDL_JoystickInit(void)
    44 {
    43 {
    45 	int arraylen;
    44 	int arraylen;
    46 	int status;
    45 	int status;
    56 			SDL_memset(SDL_joysticks, 0, arraylen);
    55 			SDL_memset(SDL_joysticks, 0, arraylen);
    57 			SDL_numjoysticks = status;
    56 			SDL_numjoysticks = status;
    58 		}
    57 		}
    59 		status = 0;
    58 		status = 0;
    60 	}
    59 	}
    61 	default_joystick = NULL;
       
    62 	return(status);
    60 	return(status);
    63 }
    61 }
    64 
    62 
    65 /*
    63 /*
    66  * Count the number of joysticks attached to the system
    64  * Count the number of joysticks attached to the system
   197 static int ValidJoystick(SDL_Joystick **joystick)
   195 static int ValidJoystick(SDL_Joystick **joystick)
   198 {
   196 {
   199 	int valid;
   197 	int valid;
   200 
   198 
   201 	if ( *joystick == NULL ) {
   199 	if ( *joystick == NULL ) {
   202 		*joystick = default_joystick;
       
   203 	}
       
   204 	if ( *joystick == NULL ) {
       
   205 		SDL_SetError("Joystick hasn't been opened yet");
   200 		SDL_SetError("Joystick hasn't been opened yet");
   206 		valid = 0;
   201 		valid = 0;
   207 	} else {
   202 	} else {
   208 		valid = 1;
   203 		valid = 1;
   209 	}
   204 	}
   367 	}
   362 	}
   368 
   363 
   369 	/* Lock the event queue - prevent joystick polling */
   364 	/* Lock the event queue - prevent joystick polling */
   370 	SDL_Lock_EventThread();
   365 	SDL_Lock_EventThread();
   371 
   366 
   372 	if ( joystick == default_joystick ) {
       
   373 		default_joystick = NULL;
       
   374 	}
       
   375 	SDL_SYS_JoystickClose(joystick);
   367 	SDL_SYS_JoystickClose(joystick);
   376 
   368 
   377 	/* Remove joystick from list */
   369 	/* Remove joystick from list */
   378 	for ( i=0; SDL_joysticks[i]; ++i ) {
   370 	for ( i=0; SDL_joysticks[i]; ++i ) {
   379 		if ( joystick == SDL_joysticks[i] ) {
   371 		if ( joystick == SDL_joysticks[i] ) {