OnePad: Fix multi-gamepad support

Can change the number of gamepad with the constant GAMEPAD_NUMBER in the onepad.h file
This commit is contained in:
kust2708 2016-02-27 20:04:06 +01:00
parent 0b0e2a3f34
commit de5f7f70e2
10 changed files with 41 additions and 36 deletions

View File

@ -23,7 +23,7 @@
void KeyStatus::Init()
{
for (int pad = 0; pad < 2; pad++) {
for (int pad = 0; pad < GAMEPAD_NUMBER; pad++) {
m_button[pad] = 0xFFFF;
m_internal_button_kbd[pad] = 0xFFFF;
m_internal_button_joy[pad] = 0xFFFF;

View File

@ -35,18 +35,18 @@ typedef struct
class KeyStatus
{
private:
u16 m_button[2];
u16 m_internal_button_kbd[2];
u16 m_internal_button_joy[2];
u16 m_button[GAMEPAD_NUMBER];
u16 m_internal_button_kbd[GAMEPAD_NUMBER];
u16 m_internal_button_joy[GAMEPAD_NUMBER];
u8 m_button_pressure[2][MAX_KEYS];
u8 m_internal_button_pressure[2][MAX_KEYS];
u8 m_button_pressure[GAMEPAD_NUMBER][MAX_KEYS];
u8 m_internal_button_pressure[GAMEPAD_NUMBER][MAX_KEYS];
bool m_state_acces[2];
bool m_state_acces[GAMEPAD_NUMBER];
PADAnalog m_analog[2];
PADAnalog m_internal_analog_kbd[2];
PADAnalog m_internal_analog_joy[2];
PADAnalog m_analog[GAMEPAD_NUMBER];
PADAnalog m_internal_analog_kbd[GAMEPAD_NUMBER];
PADAnalog m_internal_analog_joy[GAMEPAD_NUMBER];
void analog_set(u32 pad, u32 index, u8 value);
bool analog_is_reversed(u32 pad, u32 index);

View File

@ -240,10 +240,10 @@ Dialog::Dialog() : wxFrame( NULL, // Parent
{
// Tabs panels
m_pan_tabs[i] = new opPanel(
m_tab_gamepad,
wxID_ANY,
wxDefaultPosition,
wxSize(DEFAULT_WIDTH, DEFAULT_HEIGHT)
m_tab_gamepad,
wxID_ANY,
wxDefaultPosition,
wxSize(DEFAULT_WIDTH, DEFAULT_HEIGHT)
);
// Add new page
// Define label
@ -258,14 +258,14 @@ Dialog::Dialog() : wxFrame( NULL, // Parent
for(int j=0; j<BUTTONS_LENGHT; ++j)
{
// Gamepad buttons
m_bt_gamepad[i][j] = new wxButton(
m_pan_tabs[i], // Parent
wxID_HIGHEST+j+1, // ID
_T("Undefined"), // Label
wxPoint(padding[j][2], padding[j][3]), // Position
wxSize(padding[j][0], padding[j][1]) // Size
);
// Gamepad buttons
m_bt_gamepad[i][j] = new wxButton(
m_pan_tabs[i], // Parent
wxID_HIGHEST+j+1, // ID
_T("Undefined"), // Label
wxPoint(padding[j][2], padding[j][3]), // Position
wxSize(padding[j][0], padding[j][1]) // Size
);
}
// Redefine others gui buttons label
m_bt_gamepad[i][JoyL_config]->SetLabel(_T("&Left Joystick Config"));

View File

@ -59,7 +59,6 @@ enum gui_buttons {
};
#define BUTTONS_LENGHT 32 // numbers of buttons on the gamepad
#define GAMEPAD_NUMBER 2 // numbers of gamepad
#define UPDATE_TIME 5
#define DEFAULT_WIDTH 1000
#define DEFAULT_HEIGHT 740

View File

@ -133,7 +133,7 @@ void SaveConfig()
fprintf(f, "joy_pad_map = %d\n", conf->joyid_map);
fprintf(f, "ff_intensity = %d\n", conf->get_ff_intensity());
for (int pad = 0; pad < 2; pad++)
for (int pad = 0; pad < GAMEPAD_NUMBER; pad++)
{
for (int key = 0; key < MAX_KEYS; key++)
{
@ -142,7 +142,7 @@ void SaveConfig()
}
map<u32,u32>::iterator it;
for (int pad = 0; pad < 2 ; pad++)
for (int pad = 0; pad < GAMEPAD_NUMBER ; pad++)
for (it = conf->keysym_map[pad].begin(); it != conf->keysym_map[pad].end(); ++it)
fprintf(f, "PAD %d:KEYSYM 0x%x = %d\n", pad, it->first, it->second);
@ -181,7 +181,7 @@ void LoadConfig()
if (fscanf(f, "ff_intensity = %d\n", &value) == 0) goto error;
conf->set_ff_intensity(value);
for (int pad = 0; pad < 2; pad++)
for (int pad = 0; pad < GAMEPAD_NUMBER; pad++)
{
for (int key = 0; key < MAX_KEYS; key++)
{

View File

@ -172,7 +172,7 @@ EXPORT_C_(void) PADupdate(int pad)
// Actually PADupdate is always call with pad == 0. So you need to update both
// pads -- Gregory
for (int cpad = 0; cpad < 2; cpad++) {
for (int cpad = 0; cpad < GAMEPAD_NUMBER; cpad++) {
// Poll keyboard/mouse event
key_status->keyboard_state_acces(cpad);
PollForX11KeyboardInput(cpad);

View File

@ -52,7 +52,7 @@ extern int button_to_key(int button_id);
extern int axis_to_key(int full_axis, int sign, int axis_id);
extern int hat_to_key(int dir, int axis_id);
extern int PadEnum[2][2];
//extern int PadEnum[2][2]; // never used
class PADconf
{
@ -71,14 +71,14 @@ class PADconf
u16 sixaxis_usb :1;
u16 sixaxis_pressure :1;
u16 _free : 7; // The 8 remaining bits are unused, do what you wish with them ;)
} pad_options[2]; // One for each pads
} pad_options[GAMEPAD_NUMBER]; // One for each pads
u32 packed_options; // Only first 8 bits of each 16 bits series are really used, rest is padding
};
u32 keys[2][MAX_KEYS];
u32 keys[GAMEPAD_NUMBER][MAX_KEYS];
u32 log;
u32 joyid_map;
map<u32,u32> keysym_map[2];
map<u32,u32> keysym_map[GAMEPAD_NUMBER];
PADconf() { init(); }
@ -87,8 +87,11 @@ class PADconf
log = packed_options = joyid_map = 0;
ff_intensity = 0x7FFF; // set it at max value by default
sensibility = 500;
for (int pad = 0; pad < 2 ; pad++)
for (int pad = 0; pad < GAMEPAD_NUMBER ; pad++)
{
keysym_map[pad].clear();
set_joyid((u32)pad, (u32)pad); // define id mapping for each gamepad
}
}
void set_joyid(u32 pad, u32 joy_id) {

View File

@ -260,7 +260,7 @@ LRESULT WINAPI PADwndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
case WM_KEYDOWN:
if (lParam & 0x40000000) return TRUE;
for (int pad = 0; pad < 2; ++pad)
for (int pad = 0; pad < GAMEPAD_NUMBER; ++pad)
{
for (int i = 0; i < MAX_KEYS; i++)
{
@ -277,7 +277,7 @@ LRESULT WINAPI PADwndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
break;
case WM_KEYUP:
for (int pad = 0; pad < 2; ++pad)
for (int pad = 0; pad < GAMEPAD_NUMBER; ++pad)
{
for (int i = 0; i < MAX_KEYS; i++)
{
@ -304,7 +304,7 @@ LRESULT WINAPI PADwndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
return GSwndProc(hWnd, msg, wParam, lParam);
}
for (int pad = 0; pad < 2; ++pad)
for (int pad = 0; pad < GAMEPAD_NUMBER; ++pad)
key_status->commit_status(pad);
return TRUE;

View File

@ -49,7 +49,8 @@ const u32 version = PS2E_PAD_VERSION;
const u32 revision = 1;
const u32 build = 2; // increase that with each version
int PadEnum[2][2] = {{0, 2}, {1, 3}};
// Useless variable ...
//int PadEnum[2][2] = {{0, 2}, {1, 3}};
u8 stdpar[2][20] = {
{0xff, 0x5a, 0xff, 0xff, 0x80, 0x80, 0x80, 0x80,

View File

@ -22,6 +22,8 @@
#ifndef __PAD_H__
#define __PAD_H__
#define GAMEPAD_NUMBER 2 // numbers of gamepad
#include <stdio.h>
#include <assert.h>
#include <queue>