From 1b141c877582c87f2ee6c797e97164945b020c03 Mon Sep 17 00:00:00 2001 From: nakeee Date: Fri, 23 Jan 2009 01:12:32 +0000 Subject: [PATCH] copy common sdl code to the input manager, next removing it from njoy* git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1987 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/Core/Src/InputManager.cpp | 79 ++++++++++++++++++++++++-- Source/Core/Core/Src/InputManager.h | 24 +++++++- Source/Core/Core/Src/PluginManager.cpp | 3 +- Source/PluginSpecs/PluginSpecs.h | 1 + 4 files changed, 99 insertions(+), 8 deletions(-) diff --git a/Source/Core/Core/Src/InputManager.cpp b/Source/Core/Core/Src/InputManager.cpp index 14ed63ee8c..e9fc976251 100644 --- a/Source/Core/Core/Src/InputManager.cpp +++ b/Source/Core/Core/Src/InputManager.cpp @@ -1,6 +1,22 @@ #include "InputManager.h" bool InputManager::Init() { + + if (! SDLInit()) + return false; + + ScanDevices(); + return true; +} + +bool InputManager::Shutdown() { + SDLShutdown(); + sdlInit = false; + + return true; +} + +bool InputManager::SDLInit() { #ifdef HAVE_SDL // Move also joystick opening code here. if (! sdlInit) { @@ -12,16 +28,67 @@ bool InputManager::Init() { sdlInit = true; } } + return sdlInit; #endif - + return true; } - -bool InputManager::Shutdown() { -#ifdef HAVE_SDL +void InputManager::SDLShutdown() { + for(int i = 0; i < numjoy; i++ ) { + if (SDL_JoystickOpened(m_joyinfo[i].ID)) + SDL_JoystickClose(m_joyinfo[i].joy); + } SDL_Quit(); - sdlInit = false; +} + +int InputManager::ScanDevices() { + + int res = SDLScanDevices(); + return res; +} + +int InputManager::SDLScanDevices() { +#if defined HAVE_SDL && HAVE_SDL + numjoy = SDL_NumJoysticks(); + + if(numjoy == 0) { + PanicAlert("No Joystick detected!\n"); + return 0; + } + + if(m_joyinfo) + delete [] m_joyinfo; + + m_joyinfo = new ControllerInfo[numjoy]; + +#ifdef _DEBUG + fprintf(pFile, "Scanning for devices\n"); + fprintf(pFile, "¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯\n"); #endif - return true; + for(int i = 0; i < numjoy; i++ ) { + m_joyinfo[i].joy = SDL_JoystickOpen(i); + m_joyinfo[i].ID = i; + m_joyinfo[i].NumAxes = SDL_JoystickNumAxes(m_joyinfo[i].joy); + m_joyinfo[i].NumButtons = SDL_JoystickNumButtons(m_joyinfo[i].joy); + m_joyinfo[i].NumBalls = SDL_JoystickNumBalls(m_joyinfo[i].joy); + m_joyinfo[i].NumHats = SDL_JoystickNumHats(m_joyinfo[i].joy); + m_joyinfo[i].Name = SDL_JoystickName(i); + + printf("ID: %d\n", i); + printf("Name: %s\n", m_joyinfo[i].Name); + printf("Buttons: %d\n", m_joyinfo[i].NumButtons); + printf("Axises: %d\n", m_joyinfo[i].NumAxes); + printf("Hats: %d\n", m_joyinfo[i].NumHats); + printf("Balls: %d\n\n", m_joyinfo[i].NumBalls); + + // Close if opened + if(SDL_JoystickOpened(i)) + SDL_JoystickClose(m_joyinfo[i].joy); + } + + return numjoy; +#else + return 0; +#endif } diff --git a/Source/Core/Core/Src/InputManager.h b/Source/Core/Core/Src/InputManager.h index 2a421d6990..88ec46dec4 100644 --- a/Source/Core/Core/Src/InputManager.h +++ b/Source/Core/Core/Src/InputManager.h @@ -4,6 +4,17 @@ #if defined HAVE_SDL && HAVE_SDL #include + + +struct ControllerInfo { // CONNECTED WINDOWS DEVICES INFO + int NumAxes; // Amount of Axes + int NumButtons; // Amount of Buttons + int NumBalls; // Amount of Balls + int NumHats; // Amount of Hats (POV) + const char *Name; // Joypad/stickname + int ID; // SDL joystick device ID + SDL_Joystick *joy; // SDL joystick device +}; #endif class InputManager { @@ -13,9 +24,20 @@ public: bool Shutdown(); InputManager(): sdlInit(false) {} - ~InputManager() {} + ~InputManager() { + if(m_joyinfo) + delete [] m_joyinfo; + } private: bool sdlInit; + int ScanDevices(); + + // sdl specific + bool SDLInit(); + void SDLShutdown(); + int SDLScanDevices(); + ControllerInfo *m_joyinfo; + int numjoy; }; #endif diff --git a/Source/Core/Core/Src/PluginManager.cpp b/Source/Core/Core/Src/PluginManager.cpp index c2d2284fa0..a004a763a8 100644 --- a/Source/Core/Core/Src/PluginManager.cpp +++ b/Source/Core/Core/Src/PluginManager.cpp @@ -36,8 +36,9 @@ CPluginManager::CPluginManager() : m_PluginGlobals->eventHandler = EventHandler::GetInstance(); m_PluginGlobals->config = (void *)&SConfig::GetInstance(); m_PluginGlobals->messageLogger = NULL; - m_InputManager = new InputManager(); + m_InputManager = new InputManager(); + m_PluginGlobals->inputManager = m_InputManager; } diff --git a/Source/PluginSpecs/PluginSpecs.h b/Source/PluginSpecs/PluginSpecs.h index c35acc4b9c..c66bc7180d 100644 --- a/Source/PluginSpecs/PluginSpecs.h +++ b/Source/PluginSpecs/PluginSpecs.h @@ -82,6 +82,7 @@ typedef struct void *eventHandler; void *config; void *messageLogger; + void *inputManager; } PLUGIN_GLOBALS; ///////////////////////////////