コード例 #1
0
ファイル: joystick.c プロジェクト: ifilex/SRC
/* install_joystick:
 *  Initialises the joystick module.
 */
int install_joystick(int type)
{
   int c;

   if (_joystick_installed)
      return 0;

   clear_joystick_vars();

   allegro_error[0] = 0;

   /* search table for a specific driver */
   for (c=0; _joystick_driver_list[c].driver; c++) { 
      if (_joystick_driver_list[c].driver_id == type) {
	 joystick_driver = _joystick_driver_list[c].driver;
	 joy_type = type;
	 if (joystick_driver->init() != 0) {
	    if (!allegro_error[0])
	       sprintf(allegro_error, get_config_text("%s not found"), joystick_driver->name);
	    joystick_driver = NULL; 
	    joy_type = JOY_TYPE_NONE;
	    return -1;
	 }
	 break;
      }
   }

   /* autodetect driver */
   if (!joystick_driver) {
      if (!joy_loading) {
	 if (load_joystick_data(NULL) == 0)
	    return 0;
      }

      for (c=0; _joystick_driver_list[c].driver; c++) {
	 if (_joystick_driver_list[c].autodetect) {
	    joystick_driver = _joystick_driver_list[c].driver;
	    joy_type = _joystick_driver_list[c].driver_id;
	    if (_joystick_driver_list[c].driver->init() == 0)
	       break;
	 }
      }
   }

   for (c=0; c<num_joysticks; c++)
      update_calib(c);

   poll_joystick();

   _add_exit_func(remove_joystick);
   _joystick_installed = TRUE;

   return 0;
}
コード例 #2
0
	void InputDeviceSingleton::InitializeJoystick()
	{
		static bool firstCall = true;
		
		// make sure that we only install the joystick driver once
		// because this routine may incorrectly be called multiple times
		if (firstCall)
		{
			/*
			 * check to see if the joysticks have previously been calibrated
			 *
			 * if the joysticks were not calibrated, then we go through a
			 * calibration sequence and then save the calibration data to a file.
			 *
			 * if the calibration file exists, we then try to load the data.
			 * if the loading of the data fails, then we disable the joystick.
			 */
			bool previouslyCalibrated = false;
			
			FILE* fp = fopen("joysettings.dat", "rb"); 
			
			if (fp) 
			{
				fclose(fp); 
				if (0 != load_joystick_data("joysettings.dat"))
				{
					LogWarning("Joystick Data File was found, but it could not be loaded! Possibly has been corrupted!");
				}
				else
				{
					previouslyCalibrated = true;
					joystickAvailable_ = true;
				}
			}
			
			if (!previouslyCalibrated)
			{
				// try to install the joystick driver
				if (0 != install_joystick(JOY_TYPE_AUTODETECT))
				{
					LogFatal("Could not install Allegro Joystick driver!");
				}
				
				// calibrate the joysticks
				BeginJoystickCalibration();
			}
			
			// first-time-only initialize has finished
			firstCall = false;
		}
	}