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
This commit is contained in:
parent
8a87001778
commit
1b141c8775
|
@ -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
|
||||
}
|
||||
|
|
|
@ -4,6 +4,17 @@
|
|||
|
||||
#if defined HAVE_SDL && HAVE_SDL
|
||||
#include <SDL.h>
|
||||
|
||||
|
||||
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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -82,6 +82,7 @@ typedef struct
|
|||
void *eventHandler;
|
||||
void *config;
|
||||
void *messageLogger;
|
||||
void *inputManager;
|
||||
} PLUGIN_GLOBALS;
|
||||
///////////////////////////////
|
||||
|
||||
|
|
Loading…
Reference in New Issue