File: GamePad.cpp

package info (click to toggle)
pcsx2 1.6.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 28,464 kB
  • sloc: cpp: 299,796; ansic: 23,973; lisp: 2,689; asm: 908; perl: 852; sh: 789; xml: 116; makefile: 60
file content (76 lines) | stat: -rw-r--r-- 2,165 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*  
 *  PCSX2 Dev Team
 *  Copyright (C) 2015
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

#include "GamePad.h"
#ifdef SDL_BUILD
#include "SDL/joystick.h"
#endif

std::vector<std::unique_ptr<GamePad>> s_vgamePad;

/**
 * Following static methods are just forwarders to their backend
 * This is where link between agnostic and specific code is done
 **/

/**
 * Find every interesting devices and create right structure for them(depend on backend)
 **/
void GamePad::EnumerateGamePads(std::vector<std::unique_ptr<GamePad>> &vgamePad)
{
#ifdef SDL_BUILD
    JoystickInfo::EnumerateJoysticks(vgamePad);
#endif
}

/**
 * Safely dispatch to the Rumble method above
 **/
void GamePad::DoRumble(unsigned type, unsigned pad)
{
    int index = uid_to_index(pad);
    if (index >= 0)
        s_vgamePad[index]->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(int pad)
{
    size_t uid = g_conf.get_joy_uid(pad);

    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. Or
    // user didn't select it. Fallback to 1st pad for
    // 1st player. And 2nd pad for 2nd player.
    if ((int)s_vgamePad.size() > pad)
        return pad;

    return -1;
}