Пример #1
0
	void refresh_controllers()
	{
		for (s32 i = 0; i < MAX_GAMEPADS; i++)
		{
			if (haptics[i])
			{
				SDL_HapticClose(haptics[i]);
				haptics[i] = nullptr;
			}

			if (controllers[i])
			{
				SDL_GameControllerClose(controllers[i]);
				controllers[i] = nullptr;
			}
		}

		for (s32 i = 0; i < SDL_NumJoysticks(); i++)
		{
			if (SDL_IsGameController(i))
			{
				controllers[i] = SDL_GameControllerOpen(i);
				SDL_Joystick* joystick = SDL_GameControllerGetJoystick(controllers[i]);
				if (SDL_JoystickIsHaptic(joystick))
				{
					haptics[i] = SDL_HapticOpenFromJoystick(joystick);
					if (SDL_HapticRumbleInit(haptics[i])) // failed
					{
						SDL_HapticClose(haptics[i]);
						haptics[i] = nullptr;
					}
				}
			}
		}
	}
Пример #2
0
void
IN_Shutdown(void)
{
	Cmd_RemoveCommand("force_centerview");
	Cmd_RemoveCommand("+mlook");
	Cmd_RemoveCommand("-mlook");

	Com_Printf("Shutting down input.\n");

#if SDL_VERSION_ATLEAST(2, 0, 0)
	IN_Haptic_Shutdown();

	if (controller)
	{
		back_button_id = -1;
		SDL_GameControllerClose(controller);
		controller  = NULL;
	}

	if (joystick)
	{
		SDL_JoystickClose(joystick);
		joystick = NULL;
	}
#endif
}
Пример #3
0
SDLController::~SDLController()
{
    if (m_Ctrl)
    {
        SDL_GameControllerClose(m_Ctrl);
    }
}
GameControllerManager::~GameControllerManager()
{
  for(const auto& con : m_game_controllers)
  {
    SDL_GameControllerClose(con);
  }
}
Пример #5
0
void list_joysticks()
{
  int num_joysticks = SDL_NumJoysticks();
  if (num_joysticks == 0)
  {
    printf("No joysticks were found\n");
  }
  else
  {
    printf("Found %d joystick(s)\n\n", num_joysticks);
    for(int joy_idx = 0; joy_idx < num_joysticks; ++joy_idx)
    {
      SDL_Joystick* joy = SDL_JoystickOpen(joy_idx);
      if (!joy)
      {
        fprintf(stderr, "Unable to open joystick %d\n", joy_idx);
      }
      else
      {
        SDL_GameController* gamepad = SDL_GameControllerOpen(joy_idx);
        print_joystick_info(joy_idx, joy, gamepad);
        if (gamepad)
        {
          SDL_GameControllerClose(gamepad);
        }
        SDL_JoystickClose(joy);
      }
    }
  }
}
Пример #6
0
void GameController::close()
{
	if (sdl_device)
	{
		SDL_GameControllerClose(sdl_device);
		sdl_device = nullptr;
	}
}
Пример #7
0
void GameController::closeSDLDevice()
{
    if (controller && SDL_GameControllerGetAttached(controller))
    {
        SDL_GameControllerClose(controller);
        controller = 0;
    }
}
Пример #8
0
void GameController::disable() {
	Joystick::disable();

	if (_sdlController)
		SDL_GameControllerClose(_sdlController);

	_sdlController = 0;
}
Пример #9
0
inline void
SDLCloseGameControllers() {
    if(RumbleHandle) {
        SDL_HapticClose(RumbleHandle);
        RumbleHandle = 0;
    }

    SDL_GameControllerClose(GamePadHandle);
    GamePadHandle = 0;
}
Пример #10
0
void remove_controller(SDL_JoystickID id) {
    SDL_GameController* controller = get_controller(id);

    // If the device that was just removed is an existing controller in our
    // array
    if (controller) {
        // Close the controller
        SDL_GameControllerClose(controller);
        vacate_controller_array_slot(controller);
    }
}
Пример #11
0
Game::~Game(){
    SDL_GameControllerClose(this->gamePad);
    
    delete this->gWorld;
    
    SDL_DestroyRenderer(this->mainRenderer);
    SDL_DestroyWindow(this->mainWindow);
    this->mainWindow = NULL;
    
    SDL_Quit();
}
Пример #12
0
int main(int argc, char* argv[]) {
  init(argc, argv, 800, 600);
  init_controllers_and_audio();
  game = new StateManager();
  glutMainLoop();
  if (SDL_GameControllerGetAttached(controller)) {
    SDL_GameControllerClose(controller);
  }
  delete game;
  return EXIT_SUCCESS;
}
Пример #13
0
void OVR_SDL2_app::game_connect(int device, bool connected)
{
    controller.resize(device + 1);

    if (controller[device])
        SDL_GameControllerClose(controller[device]);

    if (connected)
        controller[device] = SDL_GameControllerOpen(device);
    else
        controller[device] = 0;
}
Пример #14
0
Joystick::~Joystick()
{
    auto l = sdl_events.lockSDL();
    sdl_events.removeCallback(&callback);
    if (controller) {
        SDL_GameControllerClose(controller);
    } else if (joystick) {
        SDL_JoystickClose(joystick);
    }
    joystick = nullptr;
    controller = nullptr;
}
Пример #15
0
int
main(int argc, char *argv[])
{
    const char *name;
    int i;
	int nController = 0;
    SDL_GameController *gamecontroller;

	SDL_SetHint( SDL_HINT_GAMECONTROLLERCONFIG, "341a3608000000000000504944564944,Aferglow PS3 Controller,a:b1,b:b2,y:b3,x:b0,start:b9,guide:b12,back:b8,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftshoulder:b4,rightshoulder:b5,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7" );
    /* Initialize SDL (Note: video is required to start event loop) */
    if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER ) < 0) {
        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
        exit(1);
    }

    /* Print information about the controller */
    for (i = 0; i < SDL_NumJoysticks(); ++i) {
		if ( SDL_IsGameController(i) )
		{
			nController++;
			name = SDL_GameControllerNameForIndex(i);
			printf("Game Controller %d: %s\n", i, name ? name : "Unknown Controller");
		}
    }
	printf("There are %d game controllers attached\n", nController);

    if (argv[1]) {
		int nreportederror = 0;
		SDL_Event event;
		gamecontroller = SDL_GameControllerOpen(atoi(argv[1]));
		while ( s_ForceQuit == SDL_FALSE ) {
			if (gamecontroller == NULL) {
				if ( nreportederror == 0 ) {
					printf("Couldn't open joystick %d: %s\n", atoi(argv[1]), SDL_GetError());
					nreportederror = 1;
				}
			} else {
				nreportederror = 0;
				WatchGameController(gamecontroller);
				SDL_GameControllerClose(gamecontroller);
			}
			
			gamecontroller = NULL;
			SDL_WaitEvent( &event );
			if ( event.type == SDL_JOYDEVICEADDED )
				gamecontroller = SDL_GameControllerOpen(atoi(argv[1]));
		}
	}
    SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER );

    return (0);
}
Пример #16
0
void SDL2EventHandler::inputTerminate()
{
    /* Close haptic devices and game controllers */
    if(getSDL2Context())
        for(Pair<uint8, SDL_GameController*> con :
            getSDL2Context()->controllers)
        {
            SDL_HapticClose(getSDL2Context()->haptics[con.first]);
            SDL_GameControllerClose(getSDL2Context()->controllers[con.first]);
        }
    SDL_QuitSubSystem(
        SDL_INIT_EVENTS | SDL_INIT_GAMECONTROLLER | SDL_INIT_HAPTIC);
}
Пример #17
0
internal void sdl_close_joysticks(struct sdl_event_context *ctx)
{
	unsigned int i;

	for (i = 0; i < MAX_CONTROLLERS; ++i) {
		if (ctx->players[i].controller) {
			if (ctx->players[i].rumble) {
				SDL_HapticClose(ctx->players[i].rumble);
			}
			SDL_GameControllerClose(ctx->players[i].controller);
		}
	}
}
Пример #18
0
void
DecafSDL::openInputDevices()
{
   mVpad0Config = nullptr;
   mVpad0Controller = nullptr;

   for (const auto &device : config::input::devices) {
      if (config::input::vpad0.compare(device.id) != 0) {
         continue;
      }

      if (device.type == config::input::Joystick) {
         auto numJoysticks = SDL_NumJoysticks();

         for (int i = 0; i < numJoysticks; ++i) {
            if (!SDL_IsGameController(i)) {
               continue;
            }

            auto controller = SDL_GameControllerOpen(i);

            if (!controller) {
               gCliLog->error("Failed to open game controller {}: {}", i, SDL_GetError());
               continue;
            }

            auto name = SDL_GameControllerName(controller);

            if (!device.device_name.empty() && device.device_name.compare(name) != 0) {
               SDL_GameControllerClose(controller);
               continue;
            }

            mVpad0Controller = controller;
            break;
         }

         if (!mVpad0Controller) {
            continue;
         }
      }

      mVpad0Config = &device;
      break;
   }

   if (!mVpad0Config) {
      gCliLog->warn("No input device found for gamepad (VPAD0)");
   }
}
Пример #19
0
void test_gamecontroller(int gamecontroller_idx)
{
  SDL_GameController* gamepad = SDL_GameControllerOpen(gamecontroller_idx);
  if (!gamepad)
  {
    printf("error: not a gamecontroller\n");
  }
  else
  {
    test_gamecontroller_events(gamepad);

    SDL_GameControllerClose(gamepad);
  }
}
Пример #20
0
bool Joystick::openGamepad(int deviceindex)
{
	if (!SDL_IsGameController(deviceindex))
		return false;

	if (isGamepad())
	{
		SDL_GameControllerClose(controller);
		controller = nullptr;
	}

	controller = SDL_GameControllerOpen(deviceindex);
	return isGamepad();
}
Пример #21
0
static void _StopMapping()
{
    _this->is_mapping = SDL_FALSE;
    _this->current_joystick_id = 0;
    if (_this->controller != NULL) {
        SDL_GameControllerClose(_this->controller);
        _this->controller = NULL;
    } else if (_this->joystick != NULL) {
        SDL_JoystickClose(_this->joystick);
        _this->joystick = NULL;
    }
    _ResetMappings();
    SDL_Log("Mapping finished\n");
}
Пример #22
0
	bool SDLGamepad::Disconnect (int id) {

		if (gameControllers.find (id) != gameControllers.end ()) {

			SDL_GameController *gameController = gameControllers[id];
			SDL_GameControllerClose (gameController);
			gameControllers.erase (id);

			return true;

		}

		return false;

	}
Пример #23
0
void Input_Shutdown(void)
{
	int i;

	for(i = 0; i < iNumControllers; i++)
	{
		// Function originally used here is obsolete. Just do a silly check here instead for safety.
		if(cController[i].sJoystick)
			SDL_JoystickClose(cController[i].sJoystick);
		else if(cController[i].sGameController)
			SDL_GameControllerClose(cController[i].sGameController);
	}

	Input_DeactivateMouse();
}
Пример #24
0
void GarbageCollect(photon_input &input){
    for(auto controller : input.open_controllers){
        if(controller == input.controller){
            input.controller = nullptr;
        }
        SDL_GameControllerClose(controller);
    }
    for(auto joystick : input.open_joysticks){
        if(joystick == input.joystick){
            input.joystick = nullptr;
        }
        SDL_JoystickClose(joystick);
    }
    PrintToLog("INFO: Input System garbage collection complete.");
}
void
GameControllerManager::on_controller_removed(int instance_id)
{
  for(auto& controller : m_game_controllers)
  {
    auto joy = SDL_GameControllerGetJoystick(controller);
    SDL_JoystickID id = SDL_JoystickInstanceID(joy);
    if (id == instance_id)
    {
      SDL_GameControllerClose(controller);
      controller = nullptr;
    }
  }

  m_game_controllers.erase(std::remove(m_game_controllers.begin(), m_game_controllers.end(), nullptr),
                           m_game_controllers.end());
}
Пример #26
0
void Joystick::close()
{
	if (haptic)
		SDL_HapticClose(haptic);

	if (controller)
		SDL_GameControllerClose(controller);

	if (joyhandle)
		SDL_JoystickClose(joyhandle);

	joyhandle = nullptr;
	controller = nullptr;
	haptic = nullptr;
	instanceid = -1;
	vibration = Vibration();
}
Пример #27
0
bool Joystick::deviceRemoved(const SDL_Event *event)
{
    if (event->type == SDL_CONTROLLERDEVICEREMOVED
            && ControllerMatchEvent(event->cdevice)) {
        SDL_GameControllerClose(controller);
        controller = nullptr;
        device_attached = false;
        qCDebug(phxInput) << "Controller removed";
        return true;
    } else if(JoystickMatchEvent(event->jdevice)) {
        SDL_JoystickClose(joystick);
        joystick = nullptr;
        device_attached = false;
        qCDebug(phxInput) << "Joystick removed";
        return true;
    }
    return false;
}
Пример #28
0
XInputController::~XInputController() {
  ConfigManager::Unbind(&m_LeftThumbDeadZone);
  ConfigManager::Unbind(&m_RightThumbDeadZone);
  ConfigManager::Unbind(&m_LeftThumbSaturationPoint);
  ConfigManager::Unbind(&m_RightThumbSaturationPoint);
  ConfigManager::Unbind(&m_TriggerDeadZone);
  ConfigManager::Unbind(&m_TriggerSaturationPoint);

  ConfigManager::Unbind(&m_LeftThumbBoolThreshold);
  ConfigManager::Unbind(&m_RightThumbBoolThreshold);
  ConfigManager::Unbind(&m_LeftTriggerBoolThreshold);
  ConfigManager::Unbind(&m_RightTriggerBoolThreshold);

#if BUILD_SDL
  if (m_Controller) {
    SDL_GameControllerClose(m_Controller);
  }
#endif
}
Пример #29
0
/*
 * Quit the controller subsystem
 */
void
SDL_GameControllerQuit(void)
{
    ControllerMapping_t *pControllerMap;
    while (SDL_gamecontrollers) {
        SDL_gamecontrollers->ref_count = 1;
        SDL_GameControllerClose(SDL_gamecontrollers);
    }

    while (s_pSupportedControllers) {
        pControllerMap = s_pSupportedControllers;
        s_pSupportedControllers = s_pSupportedControllers->next;
        SDL_free(pControllerMap->name);
        SDL_free(pControllerMap->mapping);
        SDL_free(pControllerMap);
    }

    SDL_DelEventWatch(SDL_GameControllerEventWatcher, NULL);

}
Пример #30
0
		void SDLUtilityTool::DestroyInputHandler()
		{
			int returnValue = 0;

			// wait on the thread
			g_assert(m_inputHandler.IsActive());
			m_inputHandler.Deactivate();
			g_assert(m_inputThread != nullptr);
			SDL_WaitThread(m_inputThread, &returnValue);
			LogSDLError();
			

			// cleanup the game controller
			g_assert(m_inputController != nullptr);
			SDL_GameControllerClose(m_inputController);
			LogSDLError();
			m_inputController = nullptr;
			m_inputHandler.m_gameController = nullptr;
			
		}