mirror of https://github.com/PCSX2/pcsx2.git
onepad: add an unique identifier
This commit is contained in:
parent
a50766384b
commit
3cff588eff
|
@ -35,3 +35,26 @@ void GamePad::DoRumble(unsigned type, unsigned pad)
|
|||
s_vgamePad[id]->Rumble(type, pad);
|
||||
}
|
||||
}
|
||||
|
||||
size_t GamePad::index_to_uid(int index)
|
||||
{
|
||||
if ((index >= 0) && (index < (int)s_vgamePad.size()))
|
||||
return s_vgamePad[index]->GetUniqueIdentifier();
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
int GamePad::uid_to_index(size_t uid)
|
||||
{
|
||||
for (int i = 0; i < (int)s_vgamePad.size(); ++i) {
|
||||
if (s_vgamePad[i]->GetUniqueIdentifier() == uid)
|
||||
return i;
|
||||
}
|
||||
|
||||
// Current uid wasn't found maybe the pad was unplugged
|
||||
// Fallback to the first pad which more friendly than nothing
|
||||
if (!s_vgamePad.empty())
|
||||
return 0;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -57,6 +57,11 @@ public:
|
|||
return m_deadzone;
|
||||
}
|
||||
|
||||
virtual size_t GetUniqueIdentifier() = 0;
|
||||
|
||||
static size_t index_to_uid(int index);
|
||||
static int uid_to_index(size_t uid);
|
||||
|
||||
bool IsProperlyInitialized()
|
||||
{
|
||||
return m_no_error;
|
||||
|
|
|
@ -151,6 +151,9 @@ JoystickInfo::JoystickInfo(int id)
|
|||
return;
|
||||
}
|
||||
|
||||
std::hash<std::string> hash_me;
|
||||
m_unique_id = hash_me(std::string(guid));
|
||||
|
||||
// Default haptic effect
|
||||
SDL_HapticEffect effects[NB_EFFECT];
|
||||
for (int i = 0; i < NB_EFFECT; i++) {
|
||||
|
@ -207,6 +210,11 @@ const char *JoystickInfo::GetName()
|
|||
return SDL_JoystickName(SDL_GameControllerGetJoystick(m_controller));
|
||||
}
|
||||
|
||||
size_t JoystickInfo::GetUniqueIdentifier()
|
||||
{
|
||||
return m_unique_id;
|
||||
}
|
||||
|
||||
bool JoystickInfo::TestForce(float strength = 0.60)
|
||||
{
|
||||
// This code just use standard rumble to check that SDL handles the pad correctly! --3kinox
|
||||
|
|
|
@ -52,8 +52,11 @@ public:
|
|||
|
||||
virtual void UpdateGamePadState();
|
||||
|
||||
virtual size_t GetUniqueIdentifier();
|
||||
|
||||
private:
|
||||
SDL_GameController *m_controller;
|
||||
SDL_Haptic *m_haptic;
|
||||
std::array<int, NB_EFFECT> m_effects_id;
|
||||
size_t m_unique_id;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue