mirror of https://github.com/snes9xgit/snes9x.git
range-based for loops + simplify joynum assignment
This commit is contained in:
parent
cdbf783fc4
commit
e1685b05eb
|
@ -209,41 +209,36 @@ int Snes9xConfig::load_defaults()
|
|||
|
||||
void Snes9xConfig::joystick_register_centers()
|
||||
{
|
||||
for (auto it=joysticks.begin(); it != joysticks.end(); it++)
|
||||
it->second->register_centers();
|
||||
for (auto &j : joysticks)
|
||||
j.second->register_centers();
|
||||
}
|
||||
|
||||
void Snes9xConfig::flush_joysticks()
|
||||
{
|
||||
for (auto it=joysticks.begin(); it != joysticks.end(); it++)
|
||||
it->second->flush();
|
||||
for (auto &j : joysticks)
|
||||
j.second->flush();
|
||||
}
|
||||
|
||||
void Snes9xConfig::set_joystick_mode(int mode)
|
||||
{
|
||||
for (auto it=joysticks.begin(); it != joysticks.end(); it++)
|
||||
it->second->mode = mode;
|
||||
for (auto &j : joysticks)
|
||||
j.second->mode = mode;
|
||||
}
|
||||
|
||||
|
||||
bool Snes9xConfig::joystick_add(int sdl_device_index)
|
||||
{
|
||||
// Find lowest unused joynum for new joystick
|
||||
std::array<bool, NUM_JOYPADS> joynums;
|
||||
int joynum = -1;
|
||||
for (auto it = joysticks.begin(); it != joysticks.end(); it++)
|
||||
for (auto &j : joysticks)
|
||||
{
|
||||
joynums[it->second->joynum] = true;
|
||||
joynums[j.second->joynum] = true;
|
||||
}
|
||||
for (unsigned int i=0; i< NUM_JOYPADS; i++)
|
||||
{
|
||||
if (!joynums[i])
|
||||
{
|
||||
joynum = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (joynum == -1)
|
||||
|
||||
// New joystick always gets the lowest available joynum
|
||||
int joynum(0);
|
||||
for (; joynum < NUM_JOYPADS && joynums[joynum]; ++joynum);
|
||||
|
||||
if (joynum == NUM_JOYPADS)
|
||||
{
|
||||
printf("Joystick slots are full, cannot add joystick (device index %d)\n", sdl_device_index);
|
||||
return false;
|
||||
|
|
|
@ -467,11 +467,11 @@ void S9xProcessEvents(bool8 block)
|
|||
if (S9xGrabJoysticks())
|
||||
{
|
||||
JoyDevice::poll_joystick_events();
|
||||
for (auto it = gui_config->joysticks.begin(); it != gui_config->joysticks.end(); it++)
|
||||
for (auto &j : gui_config->joysticks)
|
||||
{
|
||||
while (it->second->get_event(&event))
|
||||
while (j.second->get_event(&event))
|
||||
{
|
||||
binding = Binding(it->second->joynum, event.parameter, 0);
|
||||
binding = Binding(j.second->joynum, event.parameter, 0);
|
||||
S9xReportButton(binding.hex(), event.state == JOY_PRESSED ? 1 : 0);
|
||||
gui_config->screensaver_needs_reset = true;
|
||||
}
|
||||
|
|
|
@ -51,15 +51,15 @@ gboolean poll_joystick(gpointer data)
|
|||
int focus;
|
||||
|
||||
JoyDevice::poll_joystick_events();
|
||||
for (auto it = window->config->joysticks.begin(); it != window->config->joysticks.end(); it++)
|
||||
for (auto &j : window->config->joysticks)
|
||||
{
|
||||
while (it->second->get_event(&event))
|
||||
while (j.second->get_event(&event))
|
||||
{
|
||||
if (event.state == JOY_PRESSED)
|
||||
{
|
||||
if ((focus = window->get_focused_binding()) >= 0)
|
||||
{
|
||||
binding = Binding(it->second->joynum,
|
||||
binding = Binding(j.second->joynum,
|
||||
event.parameter,
|
||||
window->config->joystick_threshold);
|
||||
|
||||
|
|
Loading…
Reference in New Issue