Use zip in kconfig to allow use of range-based for
This commit is contained in:
parent
6e4b63e098
commit
d959eeca8f
|
@ -72,6 +72,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "compiler-range_for.h"
|
#include "compiler-range_for.h"
|
||||||
|
#include "d_zip.h"
|
||||||
|
|
||||||
using std::min;
|
using std::min;
|
||||||
using std::max;
|
using std::max;
|
||||||
|
@ -738,19 +739,18 @@ static window_event_result kconfig_handler(window *wind,const d_event &event, kc
|
||||||
|
|
||||||
// Update save values...
|
// Update save values...
|
||||||
|
|
||||||
for (unsigned i=0; i < std::size(kc_keyboard); i++ )
|
for (auto &&[setting, kcm] : zip(PlayerCfg.KeySettings.Keyboard, kcm_keyboard))
|
||||||
PlayerCfg.KeySettings.Keyboard[i] = kcm_keyboard[i].value;
|
setting = kcm.value;
|
||||||
|
|
||||||
#if DXX_MAX_JOYSTICKS
|
#if DXX_MAX_JOYSTICKS
|
||||||
for (unsigned i=0; i < std::size(kc_joystick); i++ )
|
for (auto &&[setting, kcm] : zip(PlayerCfg.KeySettings.Joystick, kcm_joystick))
|
||||||
PlayerCfg.KeySettings.Joystick[i] = kcm_joystick[i].value;
|
setting = kcm.value;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (unsigned i=0; i < std::size(kc_mouse); i++ )
|
for (auto &&[setting, kcm] : zip(PlayerCfg.KeySettings.Mouse, kcm_mouse))
|
||||||
PlayerCfg.KeySettings.Mouse[i] = kcm_mouse[i].value;
|
setting = kcm.value;
|
||||||
|
for (auto &&[setting, kcm] : zip(PlayerCfg.KeySettingsRebirth, kcm_rebirth))
|
||||||
for (unsigned i=0; i < std::size(kc_rebirth); i++)
|
setting = kcm.value;
|
||||||
PlayerCfg.KeySettingsRebirth[i] = kcm_rebirth[i].value;
|
|
||||||
return window_event_result::ignored; // continue closing
|
return window_event_result::ignored; // continue closing
|
||||||
default:
|
default:
|
||||||
return window_event_result::ignored;
|
return window_event_result::ignored;
|
||||||
|
@ -1119,12 +1119,10 @@ void kconfig_read_controls(control_info &Controls, const d_event &event, int aut
|
||||||
const auto &&key = event_key_get_raw(event);
|
const auto &&key = event_key_get_raw(event);
|
||||||
if (key < 255)
|
if (key < 255)
|
||||||
{
|
{
|
||||||
for (uint_fast32_t i = 0; i < std::size(kc_keyboard); i++)
|
for (auto &&[kc, kcm] : zip(kc_keyboard, kcm_keyboard))
|
||||||
{
|
{
|
||||||
if (kcm_keyboard[i].value == key)
|
if (kcm.value == key)
|
||||||
{
|
input_button_matched(Controls, kc, event.type == EVENT_KEY_COMMAND);
|
||||||
input_button_matched(Controls, kc_keyboard[i], (event.type==EVENT_KEY_COMMAND));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!automap_flag && event.type == EVENT_KEY_COMMAND)
|
if (!automap_flag && event.type == EVENT_KEY_COMMAND)
|
||||||
for (uint_fast32_t i = 0, j = 0; i < 28; i += 3, j++)
|
for (uint_fast32_t i = 0, j = 0; i < 28; i += 3, j++)
|
||||||
|
@ -1145,12 +1143,10 @@ void kconfig_read_controls(control_info &Controls, const d_event &event, int aut
|
||||||
const auto &&button = event_joystick_get_button(event);
|
const auto &&button = event_joystick_get_button(event);
|
||||||
if (button < 255)
|
if (button < 255)
|
||||||
{
|
{
|
||||||
for (uint_fast32_t i = 0; i < std::size(kc_joystick); i++)
|
for (auto &&[kc, kcm] : zip(kc_joystick, kcm_joystick))
|
||||||
{
|
{
|
||||||
if (kc_joystick[i].type == BT_JOY_BUTTON && kcm_joystick[i].value == button)
|
if (kc.type == BT_JOY_BUTTON && kcm.value == button)
|
||||||
{
|
input_button_matched(Controls, kc, event.type == EVENT_JOYSTICK_BUTTON_DOWN);
|
||||||
input_button_matched(Controls, kc_joystick[i], (event.type==EVENT_JOYSTICK_BUTTON_DOWN));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!automap_flag && event.type == EVENT_JOYSTICK_BUTTON_DOWN)
|
if (!automap_flag && event.type == EVENT_JOYSTICK_BUTTON_DOWN)
|
||||||
for (uint_fast32_t i = 1, j = 0; i < 29; i += 3, j++)
|
for (uint_fast32_t i = 1, j = 0; i < 29; i += 3, j++)
|
||||||
|
@ -1171,12 +1167,10 @@ void kconfig_read_controls(control_info &Controls, const d_event &event, int aut
|
||||||
const auto &&button = event_mouse_get_button(event);
|
const auto &&button = event_mouse_get_button(event);
|
||||||
if (button < 255)
|
if (button < 255)
|
||||||
{
|
{
|
||||||
for (uint_fast32_t i = 0; i < std::size(kc_mouse); i++)
|
for (auto &&[kc, kcm] : zip(kc_mouse, kcm_mouse))
|
||||||
{
|
{
|
||||||
if (kc_mouse[i].type == BT_MOUSE_BUTTON && kcm_mouse[i].value == button)
|
if (kc.type == BT_MOUSE_BUTTON && kcm.value == button)
|
||||||
{
|
input_button_matched(Controls, kc, event.type == EVENT_MOUSE_BUTTON_DOWN);
|
||||||
input_button_matched(Controls, kc_mouse[i], (event.type==EVENT_MOUSE_BUTTON_DOWN));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!automap_flag && event.type == EVENT_MOUSE_BUTTON_DOWN)
|
if (!automap_flag && event.type == EVENT_MOUSE_BUTTON_DOWN)
|
||||||
for (uint_fast32_t i = 2, j = 0; i < 30; i += 3, j++)
|
for (uint_fast32_t i = 2, j = 0; i < 30; i += 3, j++)
|
||||||
|
@ -1418,35 +1412,35 @@ void reset_cruise(void)
|
||||||
|
|
||||||
void kc_set_controls()
|
void kc_set_controls()
|
||||||
{
|
{
|
||||||
for (unsigned i=0; i < std::size(kc_keyboard); i++ )
|
for (auto &&[setting, kcm] : zip(PlayerCfg.KeySettings.Keyboard, kcm_keyboard))
|
||||||
kcm_keyboard[i].oldvalue = kcm_keyboard[i].value = PlayerCfg.KeySettings.Keyboard[i];
|
kcm.oldvalue = kcm.value = setting;
|
||||||
|
|
||||||
#if DXX_MAX_JOYSTICKS
|
#if DXX_MAX_JOYSTICKS
|
||||||
for (unsigned i=0; i < std::size(kc_joystick); i++ )
|
for (auto &&[setting, kcm, kc] : zip(PlayerCfg.KeySettings.Joystick, kcm_joystick, kc_joystick))
|
||||||
{
|
{
|
||||||
uint8_t value = PlayerCfg.KeySettings.Joystick[i];
|
uint8_t value = setting;
|
||||||
if (kc_joystick[i].type == BT_INVERT )
|
if (kc.type == BT_INVERT)
|
||||||
{
|
{
|
||||||
if (value != 1)
|
if (value != 1)
|
||||||
value = 0;
|
value = 0;
|
||||||
PlayerCfg.KeySettings.Joystick[i] = value;
|
setting = value;
|
||||||
}
|
}
|
||||||
kcm_joystick[i].oldvalue = kcm_joystick[i].value = value;
|
kcm.oldvalue = kcm.value = value;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (unsigned i=0; i < std::size(kc_mouse); i++ )
|
for (auto &&[setting, kcm, kc] : zip(PlayerCfg.KeySettings.Mouse, kcm_mouse, kc_mouse))
|
||||||
{
|
{
|
||||||
uint8_t value = PlayerCfg.KeySettings.Mouse[i];
|
uint8_t value = setting;
|
||||||
if (kc_mouse[i].type == BT_INVERT )
|
if (kc.type == BT_INVERT)
|
||||||
{
|
{
|
||||||
if (value != 1)
|
if (value != 1)
|
||||||
value = 0;
|
value = 0;
|
||||||
PlayerCfg.KeySettings.Mouse[i] = value;
|
setting = value;
|
||||||
}
|
}
|
||||||
kcm_mouse[i].oldvalue = kcm_mouse[i].value = value;
|
kcm.oldvalue = kcm.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unsigned i=0; i < std::size(kc_rebirth); i++ )
|
for (auto &&[setting, kcm] : zip(PlayerCfg.KeySettingsRebirth, kcm_rebirth))
|
||||||
kcm_rebirth[i].oldvalue = kcm_rebirth[i].value = PlayerCfg.KeySettingsRebirth[i];
|
kcm.oldvalue = kcm.value = setting;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue