Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #781 from RachelBryk/ControlState
Change ControlState typedef to double, and change all related floats/dou...
  • Loading branch information
dolphin-emu-bot committed Sep 3, 2014
2 parents db84a22 + 5adbc83 commit 6e2b873
Show file tree
Hide file tree
Showing 16 changed files with 99 additions and 97 deletions.
6 changes: 3 additions & 3 deletions Source/Core/Core/HW/GCPadEmu.cpp
Expand Up @@ -92,7 +92,7 @@ std::string GCPad::GetName() const

void GCPad::GetInput(GCPadStatus* const pad)
{
double x, y, triggers[2];
ControlState x, y, triggers[2];

// buttons
m_buttons->GetState(&pad->button, button_bitmasks);
Expand Down Expand Up @@ -121,8 +121,8 @@ void GCPad::GetInput(GCPadStatus* const pad)

void GCPad::SetMotor(const u8 on)
{
float state = static_cast<float>(on) / 255;
float force = abs(state - 0.5f) * 2;
ControlState state = static_cast<ControlState>(on) / 255;
ControlState force = abs(state - 0.5) * 2;
if (state < 0.5)
force = -force;

Expand Down
6 changes: 3 additions & 3 deletions Source/Core/Core/HW/WiimoteEmu/Attachment/Classic.cpp
Expand Up @@ -89,7 +89,7 @@ void Classic::GetState(u8* const data)

// left stick
{
double x, y;
ControlState x, y;
m_left_stick->GetState(&x, &y);

ccdata->lx = static_cast<u8>(Classic::LEFT_STICK_CENTER_X + (x * Classic::LEFT_STICK_RADIUS));
Expand All @@ -98,7 +98,7 @@ void Classic::GetState(u8* const data)

// right stick
{
double x, y;
ControlState x, y;
u8 x_, y_;
m_right_stick->GetState(&x, &y);

Expand All @@ -113,7 +113,7 @@ void Classic::GetState(u8* const data)

//triggers
{
double trigs[2] = { 0, 0 };
ControlState trigs[2] = { 0, 0 };
u8 lt, rt;
m_triggers->GetState(&ccdata->bt, classic_trigger_bitmasks, trigs);

Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/HW/WiimoteEmu/Attachment/Drums.cpp
Expand Up @@ -60,7 +60,7 @@ void Drums::GetState(u8* const data)

// stick
{
double x, y;
ControlState x, y;
m_stick->GetState(&x, &y);

ddata->sx = static_cast<u8>((x * 0x1F) + 0x20);
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/Core/HW/WiimoteEmu/Attachment/Guitar.cpp
Expand Up @@ -73,7 +73,7 @@ void Guitar::GetState(u8* const data)

// stick
{
double x, y;
ControlState x, y;
m_stick->GetState(&x, &y);

gdata->sx = static_cast<u8>((x * 0x1F) + 0x20);
Expand All @@ -84,7 +84,7 @@ void Guitar::GetState(u8* const data)
gdata->tb = 0x0F; // not touched

// whammy bar
double whammy;
ControlState whammy;
m_whammy->GetState(&whammy);
gdata->whammy = static_cast<u8>(whammy * 0x1F);

Expand Down
10 changes: 5 additions & 5 deletions Source/Core/Core/HW/WiimoteEmu/Attachment/Turntable.cpp
Expand Up @@ -62,7 +62,7 @@ void Turntable::GetState(u8* const data)

// stick
{
double x, y;
ControlState x, y;
m_stick->GetState(&x, &y);

ttdata->sx = static_cast<u8>((x * 0x1F) + 0x20);
Expand All @@ -71,7 +71,7 @@ void Turntable::GetState(u8* const data)

// left table
{
double tt;
ControlState tt;
s8 tt_;
m_left_table->GetState(&tt);

Expand All @@ -83,7 +83,7 @@ void Turntable::GetState(u8* const data)

// right table
{
double tt;
ControlState tt;
s8 tt_;
m_right_table->GetState(&tt);

Expand All @@ -97,7 +97,7 @@ void Turntable::GetState(u8* const data)

// effect dial
{
double dial;
ControlState dial;
u8 dial_;
m_effect_dial->GetState(&dial);

Expand All @@ -109,7 +109,7 @@ void Turntable::GetState(u8* const data)

// crossfade slider
{
double cfs;
ControlState cfs;
m_crossfade->GetState(&cfs);

ttdata->slider = static_cast<u8>((cfs * 0x07) + 0x08);
Expand Down
40 changes: 21 additions & 19 deletions Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp
Expand Up @@ -97,7 +97,7 @@ void EmulateShake(AccelData* const accel
auto const shake_step_max = 15;

// peak G-force
auto const shake_intensity = 3.f;
auto const shake_intensity = 3.0;

// shake is a bitfield of X,Y,Z shake button states
static const unsigned int btns[] = { 0x01, 0x02, 0x04 };
Expand All @@ -120,7 +120,7 @@ void EmulateTilt(AccelData* const accel
, ControllerEmu::Tilt* const tilt_group
, const bool sideways, const bool upright)
{
double roll, pitch;
ControlState roll, pitch;
// 180 degrees
tilt_group->GetState(&roll, &pitch);

Expand Down Expand Up @@ -152,13 +152,13 @@ void EmulateTilt(AccelData* const accel
(&accel->x)[fb] = sin(pitch)*sgn[fb];
}

#define SWING_INTENSITY 2.5f//-uncalibrated(aprox) 0x40-calibrated
#define SWING_INTENSITY 2.5//-uncalibrated(aprox) 0x40-calibrated

void EmulateSwing(AccelData* const accel
, ControllerEmu::Force* const swing_group
, const bool sideways, const bool upright)
{
double swing[3];
ControlState swing[3];
swing_group->GetState(swing);

s8 g_dir[3] = {-1, -1, -1};
Expand All @@ -176,7 +176,7 @@ void EmulateSwing(AccelData* const accel
if (!sideways && upright)
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] * SWING_INTENSITY;
}

Expand Down Expand Up @@ -406,7 +406,7 @@ void Wiimote::GetAccelData(u8* const data)

FillRawAccelFromGForceData(*(wm_accel*)data, *(accel_cal*)&m_eeprom[0x16], m_accel);
}
#define kCutoffFreq 5.0f
#define kCutoffFreq 5.0
inline void LowPassFilter(double & var, double newval, double period)
{
double RC=1.0/kCutoffFreq;
Expand All @@ -419,15 +419,15 @@ void Wiimote::GetIRData(u8* const data, bool use_accel)
u16 x[4], y[4];
memset(x, 0xFF, sizeof(x));

double xx = 10000, yy = 0, zz = 0;
ControlState xx = 10000, yy = 0, zz = 0;
double nsin,ncos;

if (use_accel)
{
double ax,az,len;
ax=m_accel.x;
az=m_accel.z;
len=sqrt(ax*ax+az*az);
ax = m_accel.x;
az = m_accel.z;
len = sqrt(ax*ax+az*az);
if (len)
{
ax/=len;
Expand All @@ -449,8 +449,8 @@ void Wiimote::GetIRData(u8* const data, bool use_accel)
ncos=1;
}

LowPassFilter(ir_sin,nsin,1.0f/60);
LowPassFilter(ir_cos,ncos,1.0f/60);
LowPassFilter(ir_sin,nsin,1.0/60);
LowPassFilter(ir_cos,ncos,1.0/60);

m_ir->GetState(&xx, &yy, &zz, true);

Expand All @@ -462,14 +462,16 @@ void Wiimote::GetIRData(u8* const data, bool use_accel)
static const double bnddown=0.85;
static const double bndleft=0.443364;
static const double bndright=-0.443364;
static const double dist1=100.f/camWidth; //this seems the optimal distance for zelda
static const double dist2=1.2f*dist1;
static const double dist1=100.0/camWidth; //this seems the optimal distance for zelda
static const double dist2=1.2*dist1;

for (auto& vtx : v)
{
vtx.x=xx*(bndright-bndleft)/2+(bndleft+bndright)/2;
if (m_sensor_bar_on_top) vtx.y=yy*(bndup-bnddown)/2+(bndup+bnddown)/2;
else vtx.y=yy*(bndup-bnddown)/2-(bndup+bnddown)/2;
vtx.x = xx * (bndright - bndleft) / 2 + (bndleft + bndright) / 2;
if (m_sensor_bar_on_top)
vtx.y = yy * (bndup - bnddown) / 2 + (bndup + bnddown) / 2;
else
vtx.y = yy * (bndup - bnddown) / 2 - (bndup + bnddown) / 2;
vtx.z=0;
}

Expand All @@ -487,7 +489,7 @@ void Wiimote::GetIRData(u8* const data, bool use_accel)
//MatrixIdentity(rot);
MatrixMultiply(tot,scale,rot);

for (int i=0; i<4; i++)
for (int i = 0; i < 4; i++)
{
MatrixTransformVertex(tot,v[i]);
if ((v[i].x<-1)||(v[i].x>1)||(v[i].y<-1)||(v[i].y>1))
Expand Down Expand Up @@ -535,7 +537,7 @@ void Wiimote::GetIRData(u8* const data, bool use_accel)
{
memset(data, 0xFF, 12);
wm_ir_extended* const irdata = (wm_ir_extended*)data;
for (unsigned int i=0; i<4; ++i)
for (unsigned int i = 0; i < 4; ++i)
if (x[i] < 1024 && y[i] < 768)
{
irdata[i].x = u8(x[i]);
Expand Down
30 changes: 15 additions & 15 deletions Source/Core/DolphinWX/InputConfigDiagBitmaps.cpp
Expand Up @@ -43,7 +43,7 @@ static void DrawCenteredRectangle(wxDC &dc, int x, int y, int w, int h)

#define COORD_VIS_SIZE 4

static void DrawCoordinate(wxDC &dc, double x, double y)
static void DrawCoordinate(wxDC &dc, ControlState x, ControlState y)
{
int xc = VIS_COORD(x);
int yc = VIS_COORD(y);
Expand All @@ -60,7 +60,7 @@ static void DrawControlGroupBox(wxDC &dc, ControlGroupBox *g)
{
// this is starting to be a mess combining all these in one case

double x = 0, y = 0, z = 0;
ControlState x = 0, y = 0, z = 0;

switch (g->control_group->type)
{
Expand Down Expand Up @@ -103,26 +103,26 @@ static void DrawControlGroupBox(wxDC &dc, ControlGroupBox *g)
dc.SetPen(LightGrayPen);

// polygon offset
float max
ControlState max
, diagonal
, box = 64
, d_of = box / 256.0
, x_of = box / 2.0;

if (g->control_group->name == "Main Stick")
{
max = (87.0f / 127.0f) * 100;
diagonal = (55.0f / 127.0f) * 100;
max = (87.0 / 127.0) * 100;
diagonal = (55.0 / 127.0) * 100;
}
else if (g->control_group->name == "C-Stick")
{
max = (74.0f / 127.0f) * 100;
diagonal = (46.0f / 127.0f) * 100;
max = (74.0 / 127.0) * 100;
diagonal = (46.0 / 127.0) * 100;
}
else
{
max = (82.0f / 127.0f) * 100;
diagonal = (58.0f / 127.0f) * 100;
max = (82.0 / 127.0) * 100;
diagonal = (58.0 / 127.0) * 100;
}

// polygon corners
Expand Down Expand Up @@ -153,7 +153,7 @@ static void DrawControlGroupBox(wxDC &dc, ControlGroupBox *g)

// raw dot
{
float xx, yy;
ControlState xx, yy;
xx = g->control_group->controls[3]->control_ref->State();
xx -= g->control_group->controls[2]->control_ref->State();
yy = g->control_group->controls[1]->control_ref->State();
Expand All @@ -177,9 +177,9 @@ static void DrawControlGroupBox(wxDC &dc, ControlGroupBox *g)
break;
case GROUP_TYPE_FORCE :
{
double raw_dot[3];
double adj_dot[3];
const float deadzone = g->control_group->settings[0]->value;
ControlState raw_dot[3];
ControlState adj_dot[3];
const ControlState deadzone = g->control_group->settings[0]->value;

// adjusted
((ControllerEmu::Force*)g->control_group)->GetState(adj_dot);
Expand Down Expand Up @@ -287,7 +287,7 @@ static void DrawControlGroupBox(wxDC &dc, ControlGroupBox *g)
dc.SetPen(*wxGREY_PEN);
ControlState deadzone = g->control_group->settings[0]->value;

double* const trigs = new double[trigger_count];
ControlState* const trigs = new ControlState[trigger_count];
((ControllerEmu::Triggers*)g->control_group)->GetState(trigs);

for (unsigned int n = 0; n < trigger_count; ++n)
Expand Down Expand Up @@ -363,7 +363,7 @@ static void DrawControlGroupBox(wxDC &dc, ControlGroupBox *g)
dc.SetBrush(*wxGREY_BRUSH);
dc.DrawRectangle(31 + state * 30, 0, 2, 14);

double adj_state;
ControlState adj_state;
((ControllerEmu::Slider*)g->control_group)->GetState(&adj_state);
if (state)
{
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/InputCommon/ControllerEmu.cpp
Expand Up @@ -104,7 +104,7 @@ void ControllerEmu::ControlGroup::SaveConfig(IniFile::Section *sec, const std::s
{
if (s->is_virtual)
continue;
sec->Set(group + s->name, s->value*100.0f, s->default_value*100.0f);
sec->Set(group + s->name, (float)s->value * 100.0f, (float)s->default_value * 100.0f);
}

for (auto& c : controls)
Expand All @@ -113,7 +113,7 @@ void ControllerEmu::ControlGroup::SaveConfig(IniFile::Section *sec, const std::s
sec->Set(group + c->name, c->control_ref->expression, "");

// range
sec->Set(group + c->name + "/Range", c->control_ref->range*100.0f, 100.0f);
sec->Set(group + c->name + "/Range", (float) (c->control_ref->range*100.0, 100.0));
}

// extensions
Expand Down

0 comments on commit 6e2b873

Please sign in to comment.