mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-03-12 22:56:52 +01:00
ControllerEmu: Change the GetState interface to remove range/base
Do the scaling in the code that interprets the results. This also removes the templatization of things and changes the interface to always take a double. This does add a bit more code to the users of GetState, especially when having to deal with focus management, but this will be cleaned up very soon, as focus and focus-related options will be centralized inside the input platforms themselves, rather than spread out across all the input plugins.
This commit is contained in:
parent
0d11081a3b
commit
a6dc3c47a9
@ -92,6 +92,8 @@ void GCPad::GetInput(GCPadStatus* const pad)
|
|||||||
// if window has focus or background input enabled
|
// if window has focus or background input enabled
|
||||||
if (Host_RendererHasFocus() || m_options[0].settings[0]->value)
|
if (Host_RendererHasFocus() || m_options[0].settings[0]->value)
|
||||||
{
|
{
|
||||||
|
double x, y, triggers[2];
|
||||||
|
|
||||||
// buttons
|
// buttons
|
||||||
m_buttons->GetState(&pad->button, button_bitmasks);
|
m_buttons->GetState(&pad->button, button_bitmasks);
|
||||||
|
|
||||||
@ -103,11 +105,18 @@ void GCPad::GetInput(GCPadStatus* const pad)
|
|||||||
m_dpad->GetState(&pad->button, dpad_bitmasks);
|
m_dpad->GetState(&pad->button, dpad_bitmasks);
|
||||||
|
|
||||||
// sticks
|
// sticks
|
||||||
m_main_stick->GetState(&pad->stickX, &pad->stickY, 0x80, 127);
|
m_main_stick->GetState(&x, &y);
|
||||||
m_c_stick->GetState(&pad->substickX, &pad->substickY, 0x80, 127);
|
pad->stickX = 0x7F + (x * 0x80);
|
||||||
|
pad->stickY = 0x7F + (y * 0x80);
|
||||||
|
|
||||||
|
m_c_stick->GetState(&x, &y);
|
||||||
|
pad->substickX = 0x7F + (x * 0x80);
|
||||||
|
pad->substickY = 0x7F + (y * 0x80);
|
||||||
|
|
||||||
// triggers
|
// triggers
|
||||||
m_triggers->GetState(&pad->button, trigger_bitmasks, &pad->triggerLeft, 0xFF);
|
m_triggers->GetState(&pad->button, trigger_bitmasks, triggers);
|
||||||
|
pad->triggerLeft = triggers[0] * 0xFF;
|
||||||
|
pad->triggerRight = triggers[1] * 0xFF;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -89,32 +89,56 @@ void Classic::GetState(u8* const data, const bool focus)
|
|||||||
|
|
||||||
// left stick
|
// left stick
|
||||||
{
|
{
|
||||||
u8 x, y;
|
double x, y;
|
||||||
m_left_stick->GetState(&x, &y, 0x20, focus ? 0x1F /*0x15*/ : 0);
|
if (focus)
|
||||||
|
{
|
||||||
|
m_left_stick->GetState(&x, &y);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
x = 0.0;
|
||||||
|
y = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
ccdata->lx = x;
|
ccdata->lx = (x * 0x1F) + 0x20;
|
||||||
ccdata->ly = y;
|
ccdata->ly = (y * 0x1F) + 0x20;
|
||||||
}
|
}
|
||||||
|
|
||||||
// right stick
|
// right stick
|
||||||
{
|
{
|
||||||
u8 x, y;
|
double x, y;
|
||||||
m_right_stick->GetState(&x, &y, 0x10, focus ? 0x0F /*0x0C*/ : 0);
|
u8 x_, y_;
|
||||||
|
if (focus)
|
||||||
|
{
|
||||||
|
m_right_stick->GetState(&x, &y);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
x = 0.0;
|
||||||
|
y = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
ccdata->rx1 = x;
|
x_ = (x * 0x1F) + 0x20;
|
||||||
ccdata->rx2 = x >> 1;
|
y_ = (y * 0x1F) + 0x20;
|
||||||
ccdata->rx3 = x >> 3;
|
|
||||||
ccdata->ry = y;
|
ccdata->rx1 = x_;
|
||||||
|
ccdata->rx2 = x_ >> 1;
|
||||||
|
ccdata->rx3 = x_ >> 3;
|
||||||
|
ccdata->ry = y_;
|
||||||
}
|
}
|
||||||
|
|
||||||
//triggers
|
//triggers
|
||||||
{
|
{
|
||||||
u8 trigs[2];
|
double trigs[2] = { 0, 0 };
|
||||||
m_triggers->GetState(&ccdata->bt, classic_trigger_bitmasks, trigs, focus ? 0x1F : 0);
|
u8 lt, rt;
|
||||||
|
m_triggers->GetState(&ccdata->bt, classic_trigger_bitmasks, trigs);
|
||||||
|
|
||||||
ccdata->lt1 = trigs[0];
|
lt = trigs[0] * 0x1F;
|
||||||
ccdata->lt2 = trigs[0] >> 3;
|
rt = trigs[1] * 0x1F;
|
||||||
ccdata->rt = trigs[1];
|
|
||||||
|
ccdata->lt1 = lt;
|
||||||
|
ccdata->lt2 = lt >> 3;
|
||||||
|
ccdata->rt = rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (focus)
|
if (focus)
|
||||||
|
@ -60,11 +60,19 @@ void Drums::GetState(u8* const data, const bool focus)
|
|||||||
|
|
||||||
// stick
|
// stick
|
||||||
{
|
{
|
||||||
u8 x, y;
|
double x, y;
|
||||||
m_stick->GetState(&x, &y, 0x20, focus ? 0x1F /*0x15*/ : 0);
|
if (focus)
|
||||||
|
{
|
||||||
|
m_stick->GetState(&x, &y);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
x = 0.0;
|
||||||
|
y = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
ddata->sx = x;
|
ddata->sx = (x * 0x1F) + 0x20;
|
||||||
ddata->sy = y;
|
ddata->sx = (y * 0x1F) + 0x20;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: softness maybe
|
// TODO: softness maybe
|
||||||
|
@ -73,20 +73,28 @@ void Guitar::GetState(u8* const data, const bool focus)
|
|||||||
|
|
||||||
// stick
|
// stick
|
||||||
{
|
{
|
||||||
u8 x, y;
|
double x, y;
|
||||||
m_stick->GetState(&x, &y, 0x20, focus ? 0x1F /*0x15*/ : 0);
|
if (focus)
|
||||||
|
{
|
||||||
|
m_stick->GetState(&x, &y);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
x = 0;
|
||||||
|
y = 0;
|
||||||
|
}
|
||||||
|
|
||||||
gdata->sx = x;
|
gdata->sx = (x * 0x1F) + 0x20;
|
||||||
gdata->sy = y;
|
gdata->sy = (y * 0x1F) + 0x20;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: touch bar, probably not
|
// TODO: touch bar, probably not
|
||||||
gdata->tb = 0x0F; // not touched
|
gdata->tb = 0x0F; // not touched
|
||||||
|
|
||||||
// whammy bar
|
// whammy bar
|
||||||
u8 whammy;
|
double whammy;
|
||||||
m_whammy->GetState(&whammy, 0x1F);
|
m_whammy->GetState(&whammy);
|
||||||
gdata->whammy = whammy;
|
gdata->whammy = whammy * 0x1F;
|
||||||
|
|
||||||
if (focus)
|
if (focus)
|
||||||
{
|
{
|
||||||
|
@ -66,8 +66,8 @@ void Nunchuk::GetState(u8* const data, const bool focus)
|
|||||||
ncdata->bt = 0;
|
ncdata->bt = 0;
|
||||||
|
|
||||||
// stick
|
// stick
|
||||||
ControlState state[2];
|
double state[2];
|
||||||
m_stick->GetState(&state[0], &state[1], 0, 1);
|
m_stick->GetState(&state[0], &state[1]);
|
||||||
|
|
||||||
nu_cal &cal = *(nu_cal*)®.calibration;
|
nu_cal &cal = *(nu_cal*)®.calibration;
|
||||||
nu_js cal_js[2];
|
nu_js cal_js[2];
|
||||||
@ -75,7 +75,7 @@ void Nunchuk::GetState(u8* const data, const bool focus)
|
|||||||
cal_js[1] = cal.jy;
|
cal_js[1] = cal.jy;
|
||||||
|
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
ControlState &s = state[i];
|
double &s = state[i];
|
||||||
nu_js c = cal_js[i];
|
nu_js c = cal_js[i];
|
||||||
if (s < 0)
|
if (s < 0)
|
||||||
s = s * abs(c.min - c.center) + c.center;
|
s = s * abs(c.min - c.center) + c.center;
|
||||||
|
@ -62,49 +62,93 @@ void Turntable::GetState(u8* const data, const bool focus)
|
|||||||
|
|
||||||
// stick
|
// stick
|
||||||
{
|
{
|
||||||
u8 x, y;
|
double x, y;
|
||||||
m_stick->GetState(&x, &y, 0x20, focus ? 0x1F /*0x15*/ : 0);
|
if (focus)
|
||||||
|
{
|
||||||
|
m_stick->GetState(&x, &y);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
x = 0.0;
|
||||||
|
y = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
ttdata->sx = x;
|
ttdata->sx = (x * 0x1F) + 0x20;
|
||||||
ttdata->sy = y;
|
ttdata->sy = (y * 0x1F) + 0x20;
|
||||||
}
|
}
|
||||||
|
|
||||||
// left table
|
// left table
|
||||||
{
|
{
|
||||||
s8 tt = 0;
|
double tt;
|
||||||
m_left_table->GetState(&tt, focus ? 0x1F : 0);
|
s8 tt_;
|
||||||
|
if (focus)
|
||||||
|
{
|
||||||
|
m_left_table->GetState(&tt);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tt = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
ttdata->ltable1 = tt;
|
tt_ = tt * 0x1F;
|
||||||
ttdata->ltable2 = tt >> 5;
|
|
||||||
|
ttdata->ltable1 = tt_;
|
||||||
|
ttdata->ltable2 = tt_ >> 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
// right table
|
// right table
|
||||||
{
|
{
|
||||||
s8 tt = 0;
|
double tt;
|
||||||
m_right_table->GetState(&tt, focus ? 0x1F : 0);
|
s8 tt_;
|
||||||
|
if (focus)
|
||||||
|
{
|
||||||
|
m_right_table->GetState(&tt);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tt = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
ttdata->rtable1 = tt;
|
tt_ = tt * 0x1F;
|
||||||
ttdata->rtable2 = tt >> 1;
|
|
||||||
ttdata->rtable3 = tt >> 3;
|
ttdata->rtable1 = tt_;
|
||||||
ttdata->rtable4 = tt >> 5;
|
ttdata->rtable2 = tt_ >> 1;
|
||||||
|
ttdata->rtable3 = tt_ >> 3;
|
||||||
|
ttdata->rtable4 = tt_ >> 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
// effect dial
|
// effect dial
|
||||||
{
|
{
|
||||||
u8 dial = 0;
|
double dial;
|
||||||
m_effect_dial->GetState(&dial, focus ? 0xF : 0);
|
u8 dial_;
|
||||||
|
if (focus)
|
||||||
|
{
|
||||||
|
m_effect_dial->GetState(&dial);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dial = 0;
|
||||||
|
}
|
||||||
|
|
||||||
ttdata->dial1 = dial;
|
dial_ = dial * 0x0F;
|
||||||
ttdata->dial2 = dial >> 3;
|
|
||||||
|
ttdata->dial1 = dial_;
|
||||||
|
ttdata->dial2 = dial_ >> 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
// crossfade slider
|
// crossfade slider
|
||||||
{
|
{
|
||||||
s8 cfs = 0;
|
double cfs;
|
||||||
m_crossfade->GetState(&cfs, focus ? 7 : 0);
|
if (focus)
|
||||||
cfs += 8;
|
{
|
||||||
|
m_crossfade->GetState(&cfs);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cfs = 0;
|
||||||
|
}
|
||||||
|
|
||||||
ttdata->slider = cfs;
|
ttdata->slider = (cfs * 0x07) + 0x08;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (focus)
|
if (focus)
|
||||||
|
@ -120,9 +120,20 @@ void EmulateTilt(AccelData* const accel
|
|||||||
, ControllerEmu::Tilt* const tilt_group
|
, ControllerEmu::Tilt* const tilt_group
|
||||||
, const bool focus, const bool sideways, const bool upright)
|
, const bool focus, const bool sideways, const bool upright)
|
||||||
{
|
{
|
||||||
float roll, pitch;
|
double roll, pitch;
|
||||||
// 180 degrees
|
// 180 degrees
|
||||||
tilt_group->GetState(&roll, &pitch, 0, focus ? PI : 0);
|
if (focus)
|
||||||
|
{
|
||||||
|
tilt_group->GetState(&roll, &pitch);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
roll = 0.0;
|
||||||
|
pitch = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
roll *= PI;
|
||||||
|
pitch *= PI;
|
||||||
|
|
||||||
unsigned int ud = 0, lr = 0, fb = 0;
|
unsigned int ud = 0, lr = 0, fb = 0;
|
||||||
|
|
||||||
@ -144,7 +155,7 @@ void EmulateTilt(AccelData* const accel
|
|||||||
if (!sideways && upright)
|
if (!sideways && upright)
|
||||||
sgn[ud] *= -1;
|
sgn[ud] *= -1;
|
||||||
|
|
||||||
(&accel->x)[ud] = (sin((PI / 2) - std::max(fabsf(roll), fabsf(pitch))))*sgn[ud];
|
(&accel->x)[ud] = (sin((PI / 2) - std::max(fabs(roll), fabs(pitch))))*sgn[ud];
|
||||||
(&accel->x)[lr] = -sin(roll)*sgn[lr];
|
(&accel->x)[lr] = -sin(roll)*sgn[lr];
|
||||||
(&accel->x)[fb] = sin(pitch)*sgn[fb];
|
(&accel->x)[fb] = sin(pitch)*sgn[fb];
|
||||||
}
|
}
|
||||||
@ -155,8 +166,8 @@ void EmulateSwing(AccelData* const accel
|
|||||||
, ControllerEmu::Force* const swing_group
|
, ControllerEmu::Force* const swing_group
|
||||||
, const bool sideways, const bool upright)
|
, const bool sideways, const bool upright)
|
||||||
{
|
{
|
||||||
float swing[3];
|
double swing[3];
|
||||||
swing_group->GetState(swing, 0, SWING_INTENSITY);
|
swing_group->GetState(swing);
|
||||||
|
|
||||||
s8 g_dir[3] = {-1, -1, -1};
|
s8 g_dir[3] = {-1, -1, -1};
|
||||||
u8 axis_map[3];
|
u8 axis_map[3];
|
||||||
@ -174,7 +185,7 @@ void EmulateSwing(AccelData* const accel
|
|||||||
g_dir[axis_map[0]] *= -1;
|
g_dir[axis_map[0]] *= -1;
|
||||||
|
|
||||||
for (unsigned int i=0; i<3; ++i)
|
for (unsigned int i=0; i<3; ++i)
|
||||||
(&accel->x)[axis_map[i]] += swing[i] * g_dir[i];
|
(&accel->x)[axis_map[i]] += swing[i] * g_dir[i] * SWING_INTENSITY;
|
||||||
}
|
}
|
||||||
|
|
||||||
const u16 button_bitmasks[] =
|
const u16 button_bitmasks[] =
|
||||||
@ -436,7 +447,7 @@ void Wiimote::GetIRData(u8* const data, bool use_accel)
|
|||||||
|
|
||||||
if (has_focus)
|
if (has_focus)
|
||||||
{
|
{
|
||||||
float xx = 10000, yy = 0, zz = 0;
|
double xx = 10000, yy = 0, zz = 0;
|
||||||
double nsin,ncos;
|
double nsin,ncos;
|
||||||
|
|
||||||
if (use_accel)
|
if (use_accel)
|
||||||
|
@ -60,15 +60,15 @@ static void DrawControlGroupBox(wxDC &dc, ControlGroupBox *g)
|
|||||||
{
|
{
|
||||||
// this is starting to be a mess combining all these in one case
|
// this is starting to be a mess combining all these in one case
|
||||||
|
|
||||||
float x = 0, y = 0, z = 0;
|
double x = 0, y = 0, z = 0;
|
||||||
|
|
||||||
switch (g->control_group->type)
|
switch (g->control_group->type)
|
||||||
{
|
{
|
||||||
case GROUP_TYPE_STICK :
|
case GROUP_TYPE_STICK :
|
||||||
((ControllerEmu::AnalogStick*)g->control_group)->GetState(&x, &y, 0, 1);
|
((ControllerEmu::AnalogStick*)g->control_group)->GetState(&x, &y);
|
||||||
break;
|
break;
|
||||||
case GROUP_TYPE_TILT :
|
case GROUP_TYPE_TILT :
|
||||||
((ControllerEmu::Tilt*)g->control_group)->GetState(&x, &y, 0, 1);
|
((ControllerEmu::Tilt*)g->control_group)->GetState(&x, &y);
|
||||||
break;
|
break;
|
||||||
case GROUP_TYPE_CURSOR :
|
case GROUP_TYPE_CURSOR :
|
||||||
((ControllerEmu::Cursor*)g->control_group)->GetState(&x, &y, &z);
|
((ControllerEmu::Cursor*)g->control_group)->GetState(&x, &y, &z);
|
||||||
@ -177,12 +177,12 @@ static void DrawControlGroupBox(wxDC &dc, ControlGroupBox *g)
|
|||||||
break;
|
break;
|
||||||
case GROUP_TYPE_FORCE :
|
case GROUP_TYPE_FORCE :
|
||||||
{
|
{
|
||||||
float raw_dot[3];
|
double raw_dot[3];
|
||||||
float adj_dot[3];
|
double adj_dot[3];
|
||||||
const float deadzone = g->control_group->settings[0]->value;
|
const float deadzone = g->control_group->settings[0]->value;
|
||||||
|
|
||||||
// adjusted
|
// adjusted
|
||||||
((ControllerEmu::Force*)g->control_group)->GetState(adj_dot, 0, 1);
|
((ControllerEmu::Force*)g->control_group)->GetState(adj_dot);
|
||||||
|
|
||||||
// raw
|
// raw
|
||||||
for (unsigned int i=0; i<3; ++i)
|
for (unsigned int i=0; i<3; ++i)
|
||||||
@ -287,8 +287,8 @@ static void DrawControlGroupBox(wxDC &dc, ControlGroupBox *g)
|
|||||||
dc.SetPen(*wxGREY_PEN);
|
dc.SetPen(*wxGREY_PEN);
|
||||||
ControlState deadzone = g->control_group->settings[0]->value;
|
ControlState deadzone = g->control_group->settings[0]->value;
|
||||||
|
|
||||||
unsigned int* const trigs = new unsigned int[trigger_count];
|
double* const trigs = new double[trigger_count];
|
||||||
((ControllerEmu::Triggers*)g->control_group)->GetState(trigs, 64);
|
((ControllerEmu::Triggers*)g->control_group)->GetState(trigs);
|
||||||
|
|
||||||
for (unsigned int n = 0; n < trigger_count; ++n)
|
for (unsigned int n = 0; n < trigger_count; ++n)
|
||||||
{
|
{
|
||||||
@ -305,7 +305,7 @@ static void DrawControlGroupBox(wxDC &dc, ControlGroupBox *g)
|
|||||||
|
|
||||||
// deadzone affected
|
// deadzone affected
|
||||||
dc.SetBrush(*wxRED_BRUSH);
|
dc.SetBrush(*wxRED_BRUSH);
|
||||||
dc.DrawRectangle(0, n*12, trigs[n], 14);
|
dc.DrawRectangle(0, n*12, trigs[n]*64, 14);
|
||||||
|
|
||||||
// text
|
// text
|
||||||
dc.DrawText(StrToWxStr(g->control_group->controls[n]->name), 3, n*12 + 1);
|
dc.DrawText(StrToWxStr(g->control_group->controls[n]->name), 3, n*12 + 1);
|
||||||
@ -363,12 +363,13 @@ static void DrawControlGroupBox(wxDC &dc, ControlGroupBox *g)
|
|||||||
dc.SetBrush(*wxGREY_BRUSH);
|
dc.SetBrush(*wxGREY_BRUSH);
|
||||||
dc.DrawRectangle(31 + state * 30, 0, 2, 14);
|
dc.DrawRectangle(31 + state * 30, 0, 2, 14);
|
||||||
|
|
||||||
((ControllerEmu::Slider*)g->control_group)->GetState(&state, 1);
|
double adj_state;
|
||||||
|
((ControllerEmu::Slider*)g->control_group)->GetState(&adj_state);
|
||||||
if (state)
|
if (state)
|
||||||
{
|
{
|
||||||
dc.SetPen(*wxRED_PEN);
|
dc.SetPen(*wxRED_PEN);
|
||||||
dc.SetBrush(*wxRED_BRUSH);
|
dc.SetBrush(*wxRED_BRUSH);
|
||||||
dc.DrawRectangle(31 + state * 30, 0, 2, 14);
|
dc.DrawRectangle(31 + adj_state * 30, 0, 2, 14);
|
||||||
}
|
}
|
||||||
|
|
||||||
// deadzone box
|
// deadzone box
|
||||||
|
@ -121,8 +121,7 @@ public:
|
|||||||
public:
|
public:
|
||||||
AnalogStick(const char* const _name);
|
AnalogStick(const char* const _name);
|
||||||
|
|
||||||
template <typename C>
|
void GetState(double* const x, double* const y)
|
||||||
void GetState(C* const x, C* const y, const unsigned int base, const unsigned int range)
|
|
||||||
{
|
{
|
||||||
ControlState yy = controls[0]->control_ref->State() - controls[1]->control_ref->State();
|
ControlState yy = controls[0]->control_ref->State() - controls[1]->control_ref->State();
|
||||||
ControlState xx = controls[3]->control_ref->State() - controls[2]->control_ref->State();
|
ControlState xx = controls[3]->control_ref->State() - controls[2]->control_ref->State();
|
||||||
@ -152,8 +151,8 @@ public:
|
|||||||
yy = std::max(-1.0f, std::min(1.0f, ang_sin * dist));
|
yy = std::max(-1.0f, std::min(1.0f, ang_sin * dist));
|
||||||
xx = std::max(-1.0f, std::min(1.0f, ang_cos * dist));
|
xx = std::max(-1.0f, std::min(1.0f, ang_cos * dist));
|
||||||
|
|
||||||
*y = C(yy * range + base);
|
*y = yy;
|
||||||
*x = C(xx * range + base);
|
*x = xx;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -181,20 +180,19 @@ public:
|
|||||||
public:
|
public:
|
||||||
MixedTriggers(const std::string& _name);
|
MixedTriggers(const std::string& _name);
|
||||||
|
|
||||||
template <typename C, typename S>
|
void GetState(u16 *const digital, const u16* bitmasks, double* analog)
|
||||||
void GetState(C* const digital, const C* bitmasks, S* analog, const unsigned int range)
|
|
||||||
{
|
{
|
||||||
const unsigned int trig_count = ((unsigned int) (controls.size() / 2));
|
const unsigned int trig_count = ((unsigned int) (controls.size() / 2));
|
||||||
for (unsigned int i=0; i<trig_count; ++i,++bitmasks,++analog)
|
for (unsigned int i=0; i<trig_count; ++i,++bitmasks,++analog)
|
||||||
{
|
{
|
||||||
if (controls[i]->control_ref->State() > settings[0]->value) //threshold
|
if (controls[i]->control_ref->State() > settings[0]->value) //threshold
|
||||||
{
|
{
|
||||||
*analog = range;
|
*analog = 1.0;
|
||||||
*digital |= *bitmasks;
|
*digital |= *bitmasks;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
*analog = S(controls[i+trig_count]->control_ref->State() * range);
|
*analog = controls[i+trig_count]->control_ref->State();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -205,13 +203,12 @@ public:
|
|||||||
public:
|
public:
|
||||||
Triggers(const std::string& _name);
|
Triggers(const std::string& _name);
|
||||||
|
|
||||||
template <typename S>
|
void GetState(double* analog)
|
||||||
void GetState(S* analog, const unsigned int range)
|
|
||||||
{
|
{
|
||||||
const unsigned int trig_count = ((unsigned int) (controls.size()));
|
const unsigned int trig_count = ((unsigned int) (controls.size()));
|
||||||
const ControlState deadzone = settings[0]->value;
|
const ControlState deadzone = settings[0]->value;
|
||||||
for (unsigned int i=0; i<trig_count; ++i,++analog)
|
for (unsigned int i=0; i<trig_count; ++i,++analog)
|
||||||
*analog = S(std::max(controls[i]->control_ref->State() - deadzone, 0.0f) / (1 - deadzone) * range);
|
*analog = std::max(controls[i]->control_ref->State() - deadzone, 0.0f) / (1 - deadzone);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -220,14 +217,13 @@ public:
|
|||||||
public:
|
public:
|
||||||
Slider(const std::string& _name);
|
Slider(const std::string& _name);
|
||||||
|
|
||||||
template <typename S>
|
void GetState(double* const slider)
|
||||||
void GetState(S* const slider, const unsigned int range, const unsigned int base = 0)
|
|
||||||
{
|
{
|
||||||
const float deadzone = settings[0]->value;
|
const float deadzone = settings[0]->value;
|
||||||
const float state = controls[1]->control_ref->State() - controls[0]->control_ref->State();
|
const float state = controls[1]->control_ref->State() - controls[0]->control_ref->State();
|
||||||
|
|
||||||
if (fabsf(state) > deadzone)
|
if (fabsf(state) > deadzone)
|
||||||
*slider = (S)((state - (deadzone * sign(state))) / (1 - deadzone) * range + base);
|
*slider = (state - (deadzone * sign(state))) / (1 - deadzone);
|
||||||
else
|
else
|
||||||
*slider = 0;
|
*slider = 0;
|
||||||
}
|
}
|
||||||
@ -238,8 +234,7 @@ public:
|
|||||||
public:
|
public:
|
||||||
Force(const std::string& _name);
|
Force(const std::string& _name);
|
||||||
|
|
||||||
template <typename C, typename R>
|
void GetState(double* axis)
|
||||||
void GetState(C* axis, const u8 base, const R range)
|
|
||||||
{
|
{
|
||||||
const float deadzone = settings[0]->value;
|
const float deadzone = settings[0]->value;
|
||||||
for (unsigned int i=0; i<6; i+=2)
|
for (unsigned int i=0; i<6; i+=2)
|
||||||
@ -250,7 +245,7 @@ public:
|
|||||||
tmpf = ((state - (deadzone * sign(state))) / (1 - deadzone));
|
tmpf = ((state - (deadzone * sign(state))) / (1 - deadzone));
|
||||||
|
|
||||||
float &ax = m_swing[i >> 1];
|
float &ax = m_swing[i >> 1];
|
||||||
*axis++ = (C)((tmpf - ax) * range + base);
|
*axis++ = (tmpf - ax);
|
||||||
ax = tmpf;
|
ax = tmpf;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -264,8 +259,7 @@ public:
|
|||||||
public:
|
public:
|
||||||
Tilt(const std::string& _name);
|
Tilt(const std::string& _name);
|
||||||
|
|
||||||
template <typename C, typename R>
|
void GetState(double* const x, double* const y, const bool step = true)
|
||||||
void GetState(C* const x, C* const y, const unsigned int base, const R range, const bool step = true)
|
|
||||||
{
|
{
|
||||||
// this is all a mess
|
// this is all a mess
|
||||||
|
|
||||||
@ -324,8 +318,8 @@ public:
|
|||||||
m_tilt[1] = std::max(m_tilt[1] - 0.1f, yy);
|
m_tilt[1] = std::max(m_tilt[1] - 0.1f, yy);
|
||||||
}
|
}
|
||||||
|
|
||||||
*y = C(m_tilt[1] * angle * range + base);
|
*y = m_tilt[1] * angle;
|
||||||
*x = C(m_tilt[0] * angle * range + base);
|
*x = m_tilt[0] * angle;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -337,8 +331,7 @@ public:
|
|||||||
public:
|
public:
|
||||||
Cursor(const std::string& _name);
|
Cursor(const std::string& _name);
|
||||||
|
|
||||||
template <typename C>
|
void GetState(double* const x, double* const y, double* const z, const bool adjusted = false)
|
||||||
void GetState(C* const x, C* const y, C* const z, const bool adjusted = false)
|
|
||||||
{
|
{
|
||||||
const float zz = controls[4]->control_ref->State() - controls[5]->control_ref->State();
|
const float zz = controls[4]->control_ref->State() - controls[5]->control_ref->State();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user