Skip to content

Commit

Permalink
onepad: replace conf pointer by g_conf object
Browse files Browse the repository at this point in the history
  • Loading branch information
gregory38 committed May 3, 2017
1 parent db4f28f commit 7597b31
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 62 deletions.
2 changes: 1 addition & 1 deletion plugins/onepad/GamePad.cpp
Expand Up @@ -25,7 +25,7 @@ void GamePad::EnumerateGamePads(std::vector<std::unique_ptr<GamePad>> &vgamePad)
**/
void GamePad::DoRumble(unsigned type, unsigned pad)
{
int index = uid_to_index(conf->get_joy_uid(pad));
int index = uid_to_index(g_conf.get_joy_uid(pad));
if (index >= 0)
s_vgamePad[index]->Rumble(type, pad);
}
Expand Down
8 changes: 4 additions & 4 deletions plugins/onepad/KeyStatus.cpp
Expand Up @@ -133,19 +133,19 @@ bool KeyStatus::analog_is_reversed(u32 pad, u32 index)
switch (index) {
case PAD_L_RIGHT:
case PAD_L_LEFT:
return (conf->pad_options[pad].reverse_lx);
return (g_conf.pad_options[pad].reverse_lx);

case PAD_R_LEFT:
case PAD_R_RIGHT:
return (conf->pad_options[pad].reverse_rx);
return (g_conf.pad_options[pad].reverse_rx);

case PAD_L_UP:
case PAD_L_DOWN:
return (conf->pad_options[pad].reverse_ly);
return (g_conf.pad_options[pad].reverse_ly);

case PAD_R_DOWN:
case PAD_R_UP:
return (conf->pad_options[pad].reverse_ry);
return (g_conf.pad_options[pad].reverse_ry);

default:
return false;
Expand Down
16 changes: 8 additions & 8 deletions plugins/onepad/Linux/GamepadConfiguration.cpp
Expand Up @@ -176,7 +176,7 @@ void GamepadConfiguration::OnSliderReleased(wxCommandEvent &event)
int sl_id = sl_tmp->GetId(); // slider id
if (sl_id == m_sl_rumble_intensity->GetId()) { // if this is the rumble intensity slider
u32 intensity = m_sl_rumble_intensity->GetValue(); // get the new value
conf->set_ff_intensity(intensity); // and set the force feedback intensity value with it
g_conf.set_ff_intensity(intensity); // and set the force feedback intensity value with it
// get the rumble intensity
float strength = m_sl_rumble_intensity->GetValue();
/*
Expand All @@ -193,7 +193,7 @@ void GamepadConfiguration::OnSliderReleased(wxCommandEvent &event)
s_vgamePad[m_pad_id]->TestForce(strength / 0x7FFF);
} else if (sl_id == m_sl_joystick_sensibility->GetId()) {
u32 sensibility = m_sl_joystick_sensibility->GetValue(); // get the new value
conf->set_sensibility(sensibility); // and set the joystick sensibility
g_conf.set_sensibility(sensibility); // and set the joystick sensibility
}
}

Expand All @@ -205,7 +205,7 @@ void GamepadConfiguration::OnCheckboxChange(wxCommandEvent &event)
wxCheckBox *cb_tmp = (wxCheckBox *)event.GetEventObject(); // get the slider object
int cb_id = cb_tmp->GetId();
if (cb_id == m_cb_rumble->GetId()) {
conf->pad_options[m_pad_id].forcefeedback = (m_cb_rumble->GetValue()) ? (u32)1 : (u32)0;
g_conf.pad_options[m_pad_id].forcefeedback = (m_cb_rumble->GetValue()) ? (u32)1 : (u32)0;
if (m_cb_rumble->GetValue()) {
s_vgamePad[m_pad_id]->TestForce();
m_sl_rumble_intensity->Enable();
Expand All @@ -224,7 +224,7 @@ void GamepadConfiguration::OnChoiceChange(wxCommandEvent &event)
int id = choice_tmp->GetSelection();
if (id != wxNOT_FOUND) {
size_t uid = GamePad::index_to_uid(id);
conf->set_joy_uid(m_pad_id, uid);
g_conf.set_joy_uid(m_pad_id, uid);
}
}

Expand All @@ -235,16 +235,16 @@ void GamepadConfiguration::OnChoiceChange(wxCommandEvent &event)
// Set button values
void GamepadConfiguration::repopulate()
{
bool val = conf->pad_options[m_pad_id].forcefeedback;
bool val = g_conf.pad_options[m_pad_id].forcefeedback;
m_cb_rumble->SetValue(val);

int tmp = conf->get_ff_intensity();
int tmp = g_conf.get_ff_intensity();
m_sl_rumble_intensity->SetValue(tmp);

tmp = conf->get_sensibility();
tmp = g_conf.get_sensibility();
m_sl_joystick_sensibility->SetValue(tmp);

u32 joyid = GamePad::uid_to_index(conf->get_joy_uid(m_pad_id));
u32 joyid = GamePad::uid_to_index(g_conf.get_joy_uid(m_pad_id));
if (joyid < m_joy_map->GetCount() && !m_joy_map->IsEmpty())
m_joy_map->SetSelection(joyid);

Expand Down
24 changes: 12 additions & 12 deletions plugins/onepad/Linux/JoystickConfiguration.cpp
Expand Up @@ -178,24 +178,24 @@ void JoystickConfiguration::OnCheckboxChange(wxCommandEvent &event)
if (m_isForLeftJoystick) {
if (cb_id == m_cb_reverse_Ly->GetId()) {
val = m_cb_reverse_Ly->GetValue();
conf->pad_options[m_pad_id].reverse_ly = val;
g_conf.pad_options[m_pad_id].reverse_ly = val;
} else if (cb_id == m_cb_reverse_Lx->GetId()) {
val = m_cb_reverse_Lx->GetValue();
conf->pad_options[m_pad_id].reverse_lx = val;
g_conf.pad_options[m_pad_id].reverse_lx = val;
} else if (cb_id == m_cb_mouse_Ljoy->GetId()) {
val = m_cb_mouse_Ljoy->GetValue();
conf->pad_options[m_pad_id].mouse_l = val;
g_conf.pad_options[m_pad_id].mouse_l = val;
}
} else {
if (cb_id == m_cb_reverse_Ry->GetId()) {
val = m_cb_reverse_Ry->GetValue();
conf->pad_options[m_pad_id].reverse_ry = val;
g_conf.pad_options[m_pad_id].reverse_ry = val;
} else if (cb_id == m_cb_reverse_Rx->GetId()) {
val = m_cb_reverse_Rx->GetValue();
conf->pad_options[m_pad_id].reverse_rx = val;
g_conf.pad_options[m_pad_id].reverse_rx = val;
} else if (cb_id == m_cb_mouse_Rjoy->GetId()) {
val = m_cb_mouse_Rjoy->GetValue();
conf->pad_options[m_pad_id].mouse_r = val;
g_conf.pad_options[m_pad_id].mouse_r = val;
}
}
}
Expand Down Expand Up @@ -223,27 +223,27 @@ void JoystickConfiguration::repopulate()
{
bool val;
if (m_isForLeftJoystick) {
val = conf->pad_options[m_pad_id].reverse_lx;
val = g_conf.pad_options[m_pad_id].reverse_lx;
m_init_reverse_Lx = val;
m_cb_reverse_Lx->SetValue(val);

val = conf->pad_options[m_pad_id].reverse_ly;
val = g_conf.pad_options[m_pad_id].reverse_ly;
m_init_reverse_Ly = val;
m_cb_reverse_Ly->SetValue(val);

val = conf->pad_options[m_pad_id].mouse_l;
val = g_conf.pad_options[m_pad_id].mouse_l;
m_init_mouse_Ljoy = val;
m_cb_mouse_Ljoy->SetValue(val);
} else {
val = conf->pad_options[m_pad_id].reverse_rx;
val = g_conf.pad_options[m_pad_id].reverse_rx;
m_init_reverse_Rx = val;
m_cb_reverse_Rx->SetValue(val);

val = conf->pad_options[m_pad_id].reverse_ry;
val = g_conf.pad_options[m_pad_id].reverse_ry;
m_init_reverse_Ry = val;
m_cb_reverse_Ry->SetValue(val);

val = conf->pad_options[m_pad_id].mouse_r;
val = g_conf.pad_options[m_pad_id].mouse_r;
m_init_mouse_Rjoy = val;
m_cb_mouse_Rjoy->SetValue(val);
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/onepad/Linux/dialog.cpp
Expand Up @@ -432,7 +432,7 @@ void Dialog::clear_key(int pad, int key)
m_simulatedKeys[pad][key] = 0;

// erase gamepad entry (keysim map)
conf->keysym_map[pad].erase(keysim);
g_conf.keysym_map[pad].erase(keysim);
}


Expand All @@ -441,7 +441,7 @@ void Dialog::repopulate()
{
for (int gamepad_id = 0; gamepad_id < GAMEPAD_NUMBER; ++gamepad_id) {
// keyboard/mouse key
for (const auto &it : conf->keysym_map[gamepad_id]) {
for (const auto &it : g_conf.keysym_map[gamepad_id]) {
int keysym = it.first;
int key = it.second;

Expand Down
35 changes: 16 additions & 19 deletions plugins/onepad/Linux/ini.cpp
Expand Up @@ -89,18 +89,18 @@ void SaveConfig()
return;
}

fprintf(f, "log = %d\n", conf->log);
fprintf(f, "options = %d\n", conf->packed_options);
fprintf(f, "mouse_sensibility = %d\n", conf->get_sensibility());
fprintf(f, "ff_intensity = %d\n", conf->get_ff_intensity());
fprintf(f, "uid[0] = %zu\n", conf->get_joy_uid(0));
fprintf(f, "uid[1] = %zu\n", conf->get_joy_uid(1));
fprintf(f, "log = %d\n", g_conf.log);
fprintf(f, "options = %d\n", g_conf.packed_options);
fprintf(f, "mouse_sensibility = %d\n", g_conf.get_sensibility());
fprintf(f, "ff_intensity = %d\n", g_conf.get_ff_intensity());
fprintf(f, "uid[0] = %zu\n", g_conf.get_joy_uid(0));
fprintf(f, "uid[1] = %zu\n", g_conf.get_joy_uid(1));

for (int pad = 0; pad < GAMEPAD_NUMBER; pad++)
for (auto const &it : conf->keysym_map[pad])
for (auto const &it : g_conf.keysym_map[pad])
fprintf(f, "PAD %d:KEYSYM 0x%x = %d\n", pad, it.first, it.second);

for (auto const &it : conf->sdl2_mapping)
for (auto const &it : g_conf.sdl2_mapping)
fprintf(f, "SDL2 = %s\n", it.c_str());

fclose(f);
Expand All @@ -111,10 +111,7 @@ void LoadConfig()
FILE *f;
bool have_user_setting = false;

if (!conf)
conf = new PADconf;

conf->init();
g_conf.init();

const std::string iniFile(s_strIniPath + "OnePAD2.ini");
f = fopen(iniFile.c_str(), "r");
Expand All @@ -126,22 +123,22 @@ void LoadConfig()

u32 value;
if (fscanf(f, "log = %u\n", &value) == 1)
conf->log = value;
g_conf.log = value;

if (fscanf(f, "options = %u\n", &value) == 1)
conf->packed_options = value;
g_conf.packed_options = value;

if (fscanf(f, "mouse_sensibility = %u\n", &value) == 1)
conf->set_sensibility(value);
g_conf.set_sensibility(value);

if (fscanf(f, "ff_intensity = %u\n", &value) == 1)
conf->set_ff_intensity(value);
g_conf.set_ff_intensity(value);

size_t uid;
if (fscanf(f, "uid[0] = %zu\n", &uid) == 1)
conf->set_joy_uid(0, uid);
g_conf.set_joy_uid(0, uid);
if (fscanf(f, "uid[1] = %zu\n", &uid) == 1)
conf->set_joy_uid(1, uid);
g_conf.set_joy_uid(1, uid);

u32 pad;
u32 keysym;
Expand All @@ -154,7 +151,7 @@ void LoadConfig()

char sdl2[512];
while (fscanf(f, "SDL2 = %511[^\n]\n", sdl2) == 1)
conf->sdl2_mapping.push_back(std::string(sdl2));
g_conf.sdl2_mapping.push_back(std::string(sdl2));

if (!have_user_setting)
DefaultKeyboardValues();
Expand Down
2 changes: 1 addition & 1 deletion plugins/onepad/Linux/linux.cpp
Expand Up @@ -80,7 +80,7 @@ void _PADclose()

void PollForJoystickInput(int cpad)
{
int index = GamePad::uid_to_index(conf->get_joy_uid(cpad));
int index = GamePad::uid_to_index(g_conf.get_joy_uid(cpad));
if (index < 0)
return;

Expand Down
6 changes: 3 additions & 3 deletions plugins/onepad/SDL/joystick.cpp
Expand Up @@ -62,7 +62,7 @@ void JoystickInfo::EnumerateJoysticks(std::vector<std::unique_ptr<GamePad>> &vjo
g_bytes_unref(bytes);

// Add user mapping too
for (auto const &map : conf->sdl2_mapping)
for (auto const &map : g_conf.sdl2_mapping)
SDL_GameControllerAddMapping(map.c_str());
}
}
Expand All @@ -82,7 +82,7 @@ void JoystickInfo::Rumble(unsigned type, unsigned pad)
if (type >= m_effects_id.size())
return;

if (!(conf->pad_options[pad].forcefeedback))
if (!(g_conf.pad_options[pad].forcefeedback))
return;

if (m_haptic == nullptr)
Expand Down Expand Up @@ -167,7 +167,7 @@ JoystickInfo::JoystickInfo(int id)
direction.dir[0] = 18000;
effect.periodic.direction = direction;
effect.periodic.period = 10;
effect.periodic.magnitude = (Sint16)(conf->get_ff_intensity()); // Effect at maximum instensity
effect.periodic.magnitude = (Sint16)(g_conf.get_ff_intensity()); // Effect at maximum instensity
effect.periodic.offset = 0;
effect.periodic.phase = 18000;
effect.periodic.length = 125; // 125ms feels quite near to original
Expand Down
6 changes: 3 additions & 3 deletions plugins/onepad/controller.cpp
Expand Up @@ -24,15 +24,15 @@

__forceinline void set_keyboard_key(int pad, int keysym, int index)
{
conf->keysym_map[pad][keysym] = index;
g_conf.keysym_map[pad][keysym] = index;
}

__forceinline int get_keyboard_key(int pad, int keysym)
{
// You must use find instead of []
// [] will create an element if the key does not exist and return 0
map<u32, u32>::iterator it = conf->keysym_map[pad].find(keysym);
if (it != conf->keysym_map[pad].end())
map<u32, u32>::iterator it = g_conf.keysym_map[pad].find(keysym);
if (it != g_conf.keysym_map[pad].end())
return it->second;
else
return -1;
Expand Down
2 changes: 1 addition & 1 deletion plugins/onepad/controller.h
Expand Up @@ -118,4 +118,4 @@ class PADconf
return sensibility;
}
};
extern PADconf *conf;
extern PADconf g_conf;
8 changes: 4 additions & 4 deletions plugins/onepad/keyboard.cpp
Expand Up @@ -137,11 +137,11 @@ static void AnalyzeKeyEvent(keyEvent &evt)
// 1/ small move == no move. Cons : can not do small movement
// 2/ use a watchdog timer thread
// 3/ ??? idea welcome ;)
if (conf->pad_options[pad].mouse_l | conf->pad_options[pad].mouse_r) {
if (g_conf.pad_options[pad].mouse_l | g_conf.pad_options[pad].mouse_r) {
unsigned int pad_x;
unsigned int pad_y;
// Note when both PADOPTION_MOUSE_R and PADOPTION_MOUSE_L are set, take only the right one
if (conf->pad_options[pad].mouse_r) {
if (g_conf.pad_options[pad].mouse_r) {
pad_x = PAD_R_RIGHT;
pad_y = PAD_R_UP;
} else {
Expand All @@ -151,7 +151,7 @@ static void AnalyzeKeyEvent(keyEvent &evt)

unsigned x = evt.key & 0xFFFF;
unsigned int value = (s_previous_mouse_x > x) ? s_previous_mouse_x - x : x - s_previous_mouse_x;
value *= conf->get_sensibility();
value *= g_conf.get_sensibility();

if (x == 0)
g_key_status.press(pad, pad_x, -MAX_ANALOG_VALUE);
Expand All @@ -167,7 +167,7 @@ static void AnalyzeKeyEvent(keyEvent &evt)

unsigned y = evt.key >> 16;
value = (s_previous_mouse_y > y) ? s_previous_mouse_y - y : y - s_previous_mouse_y;
value *= conf->get_sensibility();
value *= g_conf.get_sensibility();

if (y == 0)
g_key_status.press(pad, pad_y, -MAX_ANALOG_VALUE);
Expand Down
5 changes: 1 addition & 4 deletions plugins/onepad/onepad.cpp
Expand Up @@ -36,7 +36,7 @@
#define snprintf sprintf_s
#endif

PADconf *conf;
PADconf g_conf;
static char libraryName[256];

keyEvent event;
Expand Down Expand Up @@ -173,9 +173,6 @@ EXPORT_C_(void)
PADshutdown()
{
CloseLogging();

delete conf;
conf = nullptr;
}

EXPORT_C_(s32)
Expand Down

0 comments on commit 7597b31

Please sign in to comment.