Merge pull request #604 from magcius/wip/emu-cleanup-2

Start cleaning up the input interface
This commit is contained in:
Lioncash
2014-07-15 12:11:17 -04:00
41 changed files with 765 additions and 1630 deletions
+16
View File
@@ -150,6 +150,7 @@ void SConfig::SaveSettings()
SaveCoreSettings(ini);
SaveMovieSettings(ini);
SaveDSPSettings(ini);
SaveInputSettings(ini);
SaveFifoPlayerSettings(ini);
ini.Save(File::GetUserPath(F_DOLPHINCONFIG_IDX));
@@ -329,6 +330,13 @@ void SConfig::SaveDSPSettings(IniFile& ini)
dsp->Set("CaptureLog", m_DSPCaptureLog);
}
void SConfig::SaveInputSettings(IniFile& ini)
{
IniFile::Section* input = ini.GetOrCreateSection("Input");
input->Set("BackgroundInput", m_BackgroundInput);
}
void SConfig::SaveFifoPlayerSettings(IniFile& ini)
{
IniFile::Section* fifoplayer = ini.GetOrCreateSection("FifoPlayer");
@@ -350,6 +358,7 @@ void SConfig::LoadSettings()
LoadCoreSettings(ini);
LoadMovieSettings(ini);
LoadDSPSettings(ini);
LoadInputSettings(ini);
LoadFifoPlayerSettings(ini);
m_SYSCONF = new SysConf();
@@ -556,6 +565,13 @@ void SConfig::LoadDSPSettings(IniFile& ini)
dsp->Get("CaptureLog", &m_DSPCaptureLog, false);
}
void SConfig::LoadInputSettings(IniFile& ini)
{
IniFile::Section* input = ini.GetOrCreateSection("Input");
input->Get("BackgroundInput", &m_BackgroundInput, false);
}
void SConfig::LoadFifoPlayerSettings(IniFile& ini)
{
IniFile::Section* fifoplayer = ini.GetOrCreateSection("FifoPlayer");
+5
View File
@@ -97,6 +97,9 @@ struct SConfig : NonCopyable
int m_Volume;
std::string sBackend;
// Input settings
bool m_BackgroundInput;
SysConf* m_SYSCONF;
// save settings
@@ -122,6 +125,7 @@ private:
void SaveGameListSettings(IniFile& ini);
void SaveCoreSettings(IniFile& ini);
void SaveDSPSettings(IniFile& ini);
void SaveInputSettings(IniFile& ini);
void SaveMovieSettings(IniFile& ini);
void SaveFifoPlayerSettings(IniFile& ini);
@@ -132,6 +136,7 @@ private:
void LoadGameListSettings(IniFile& ini);
void LoadCoreSettings(IniFile& ini);
void LoadDSPSettings(IniFile& ini);
void LoadInputSettings(IniFile& ini);
void LoadMovieSettings(IniFile& ini);
void LoadFifoPlayerSettings(IniFile& ini);
+1 -2
View File
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|x64">
@@ -357,7 +357,6 @@
<ClInclude Include="HW\WiimoteEmu\Attachment\Turntable.h" />
<ClInclude Include="HW\WiimoteEmu\Encryption.h" />
<ClInclude Include="HW\WiimoteEmu\MatrixMath.h" />
<ClInclude Include="HW\WiimoteEmu\UDPTLayer.h" />
<ClInclude Include="HW\WiimoteEmu\WiimoteEmu.h" />
<ClInclude Include="HW\WiimoteEmu\WiimoteHid.h" />
<ClInclude Include="HW\WiimoteReal\WiimoteReal.h" />
+1 -4
View File
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="ActionReplay">
@@ -1005,9 +1005,6 @@
<ClInclude Include="HW\WiimoteEmu\MatrixMath.h">
<Filter>HW %28Flipper/Hollywood%29\Wiimote\Emu</Filter>
</ClInclude>
<ClInclude Include="HW\WiimoteEmu\UDPTLayer.h">
<Filter>HW %28Flipper/Hollywood%29\Wiimote\Emu</Filter>
</ClInclude>
<ClInclude Include="HW\WiimoteEmu\WiimoteEmu.h">
<Filter>HW %28Flipper/Hollywood%29\Wiimote\Emu</Filter>
</ClInclude>
+24 -32
View File
@@ -79,7 +79,7 @@ GCPad::GCPad(const unsigned int index) : m_index(index)
// options
groups.emplace_back(m_options = new ControlGroup(_trans("Options")));
m_options->settings.emplace_back(new ControlGroup::Setting(_trans("Background Input"), false));
m_options->settings.emplace_back(new ControlGroup::BackgroundInputSetting(_trans("Background Input")));
}
std::string GCPad::GetName() const
@@ -89,34 +89,31 @@ std::string GCPad::GetName() const
void GCPad::GetInput(GCPadStatus* const pad)
{
// if window has focus or background input enabled
if (Host_RendererHasFocus() || m_options[0].settings[0]->value)
{
// buttons
m_buttons->GetState(&pad->button, button_bitmasks);
double x, y, triggers[2];
// set analog A/B analog to full or w/e, prolly not needed
if (pad->button & PAD_BUTTON_A) pad->analogA = 0xFF;
if (pad->button & PAD_BUTTON_B) pad->analogB = 0xFF;
// buttons
m_buttons->GetState(&pad->button, button_bitmasks);
// dpad
m_dpad->GetState(&pad->button, dpad_bitmasks);
// set analog A/B analog to full or w/e, prolly not needed
if (pad->button & PAD_BUTTON_A) pad->analogA = 0xFF;
if (pad->button & PAD_BUTTON_B) pad->analogB = 0xFF;
// sticks
m_main_stick->GetState(&pad->stickX, &pad->stickY, 0x80, 127);
m_c_stick->GetState(&pad->substickX, &pad->substickY, 0x80, 127);
// dpad
m_dpad->GetState(&pad->button, dpad_bitmasks);
// triggers
m_triggers->GetState(&pad->button, trigger_bitmasks, &pad->triggerLeft, 0xFF);
}
else
{
// center sticks
pad->stickX = 0x80;
pad->stickY = 0x80;
pad->substickX = 0x80;
pad->substickY = 0x80;
}
// sticks
m_main_stick->GetState(&x, &y);
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
m_triggers->GetState(&pad->button, trigger_bitmasks, triggers);
pad->triggerLeft = triggers[0] * 0xFF;
pad->triggerRight = triggers[1] * 0xFF;
}
void GCPad::SetMotor(const u8 on)
@@ -126,17 +123,12 @@ void GCPad::SetMotor(const u8 on)
if (state < 0.5)
force = -force;
// only rumble if window has focus or background input is enabled
if (Host_RendererHasFocus() || m_options[0].settings[0]->value)
m_rumble->controls[0]->control_ref->State(force);
else
m_rumble->controls[0]->control_ref->State(0);
m_rumble->controls[0]->control_ref->State(force);
}
void GCPad::SetOutput(const u8 on)
{
// only rumble if window has focus or background input is enabled
m_rumble->controls[0]->control_ref->State(on && (Host_RendererHasFocus() || m_options[0].settings[0]->value));
m_rumble->controls[0]->control_ref->State(on);
}
void GCPad::LoadDefaults(const ControllerInterface& ciface)
@@ -42,7 +42,7 @@ void Attachment::Reset()
}
void ControllerEmu::Extension::GetState(u8* const data, const bool focus)
void ControllerEmu::Extension::GetState(u8* const data)
{
((WiimoteEmu::Attachment*)attachments[active_extension].get())->GetState(data, focus);
((WiimoteEmu::Attachment*)attachments[active_extension].get())->GetState(data);
}
@@ -15,7 +15,7 @@ class Attachment : public ControllerEmu
public:
Attachment(const char* const _name, WiimoteEmu::ExtensionReg& _reg);
virtual void GetState(u8* const data, const bool focus = true) {}
virtual void GetState(u8* const data) {}
void Reset();
std::string GetName() const override;
@@ -80,7 +80,7 @@ Classic::Classic(WiimoteEmu::ExtensionReg& _reg) : Attachment(_trans("Classic"),
memcpy(&id, classic_id, sizeof(classic_id));
}
void Classic::GetState(u8* const data, const bool focus)
void Classic::GetState(u8* const data)
{
wm_classic_extension* const ccdata = (wm_classic_extension*)data;
ccdata->bt = 0;
@@ -89,41 +89,46 @@ void Classic::GetState(u8* const data, const bool focus)
// left stick
{
u8 x, y;
m_left_stick->GetState(&x, &y, 0x20, focus ? 0x1F /*0x15*/ : 0);
double x, y;
m_left_stick->GetState(&x, &y);
ccdata->lx = x;
ccdata->ly = y;
ccdata->lx = (x * 0x1F) + 0x20;
ccdata->ly = (y * 0x1F) + 0x20;
}
// right stick
{
u8 x, y;
m_right_stick->GetState(&x, &y, 0x10, focus ? 0x0F /*0x0C*/ : 0);
double x, y;
u8 x_, y_;
m_right_stick->GetState(&x, &y);
ccdata->rx1 = x;
ccdata->rx2 = x >> 1;
ccdata->rx3 = x >> 3;
ccdata->ry = y;
x_ = (x * 0x1F) + 0x20;
y_ = (y * 0x1F) + 0x20;
ccdata->rx1 = x_;
ccdata->rx2 = x_ >> 1;
ccdata->rx3 = x_ >> 3;
ccdata->ry = y_;
}
//triggers
{
u8 trigs[2];
m_triggers->GetState(&ccdata->bt, classic_trigger_bitmasks, trigs, focus ? 0x1F : 0);
double trigs[2] = { 0, 0 };
u8 lt, rt;
m_triggers->GetState(&ccdata->bt, classic_trigger_bitmasks, trigs);
ccdata->lt1 = trigs[0];
ccdata->lt2 = trigs[0] >> 3;
ccdata->rt = trigs[1];
lt = trigs[0] * 0x1F;
rt = trigs[1] * 0x1F;
ccdata->lt1 = lt;
ccdata->lt2 = lt >> 3;
ccdata->rt = rt;
}
if (focus)
{
// buttons
m_buttons->GetState(&ccdata->bt, classic_button_bitmasks);
// dpad
m_dpad->GetState(&ccdata->bt, classic_dpad_bitmasks);
}
// buttons
m_buttons->GetState(&ccdata->bt, classic_button_bitmasks);
// dpad
m_dpad->GetState(&ccdata->bt, classic_dpad_bitmasks);
// flip button bits
ccdata->bt ^= 0xFFFF;
@@ -13,7 +13,7 @@ class Classic : public Attachment
{
public:
Classic(WiimoteEmu::ExtensionReg& _reg);
void GetState(u8* const data, const bool focus) override;
void GetState(u8* const data) override;
enum
{
@@ -51,7 +51,7 @@ Drums::Drums(WiimoteEmu::ExtensionReg& _reg) : Attachment(_trans("Drums"), _reg)
memcpy(&id, drums_id, sizeof(drums_id));
}
void Drums::GetState(u8* const data, const bool focus)
void Drums::GetState(u8* const data)
{
wm_drums_extension* const ddata = (wm_drums_extension*)data;
ddata->bt = 0;
@@ -60,24 +60,21 @@ void Drums::GetState(u8* const data, const bool focus)
// stick
{
u8 x, y;
m_stick->GetState(&x, &y, 0x20, focus ? 0x1F /*0x15*/ : 0);
double x, y;
m_stick->GetState(&x, &y);
ddata->sx = x;
ddata->sy = y;
ddata->sx = (x * 0x1F) + 0x20;
ddata->sx = (y * 0x1F) + 0x20;
}
// TODO: softness maybe
data[2] = 0xFF;
data[3] = 0xFF;
if (focus)
{
// buttons
m_buttons->GetState(&ddata->bt, drum_button_bitmasks);
// pads
m_pads->GetState(&ddata->bt, drum_pad_bitmasks);
}
// buttons
m_buttons->GetState(&ddata->bt, drum_button_bitmasks);
// pads
m_pads->GetState(&ddata->bt, drum_pad_bitmasks);
// flip button bits
ddata->bt ^= 0xFFFF;
@@ -13,7 +13,7 @@ class Drums : public Attachment
{
public:
Drums(WiimoteEmu::ExtensionReg& _reg);
void GetState(u8* const data, const bool focus) override;
void GetState(u8* const data) override;
enum
{
@@ -64,7 +64,7 @@ Guitar::Guitar(WiimoteEmu::ExtensionReg& _reg) : Attachment(_trans("Guitar"), _r
memcpy(&id, guitar_id, sizeof(guitar_id));
}
void Guitar::GetState(u8* const data, const bool focus)
void Guitar::GetState(u8* const data)
{
wm_guitar_extension* const gdata = (wm_guitar_extension*)data;
gdata->bt = 0;
@@ -73,30 +73,27 @@ void Guitar::GetState(u8* const data, const bool focus)
// stick
{
u8 x, y;
m_stick->GetState(&x, &y, 0x20, focus ? 0x1F /*0x15*/ : 0);
double x, y;
m_stick->GetState(&x, &y);
gdata->sx = x;
gdata->sy = y;
gdata->sx = (x * 0x1F) + 0x20;
gdata->sy = (y * 0x1F) + 0x20;
}
// TODO: touch bar, probably not
gdata->tb = 0x0F; // not touched
// whammy bar
u8 whammy;
m_whammy->GetState(&whammy, 0x1F);
gdata->whammy = whammy;
double whammy;
m_whammy->GetState(&whammy);
gdata->whammy = whammy * 0x1F;
if (focus)
{
// buttons
m_buttons->GetState(&gdata->bt, guitar_button_bitmasks);
// frets
m_frets->GetState(&gdata->bt, guitar_fret_bitmasks);
// strum
m_strum->GetState(&gdata->bt, guitar_strum_bitmasks);
}
// buttons
m_buttons->GetState(&gdata->bt, guitar_button_bitmasks);
// frets
m_frets->GetState(&gdata->bt, guitar_fret_bitmasks);
// strum
m_strum->GetState(&gdata->bt, guitar_strum_bitmasks);
// flip button bits
gdata->bt ^= 0xFFFF;
@@ -13,7 +13,7 @@ class Guitar : public Attachment
{
public:
Guitar(WiimoteEmu::ExtensionReg& _reg);
void GetState(u8* const data, const bool focus) override;
void GetState(u8* const data) override;
enum
{
@@ -4,9 +4,6 @@
#include "Core/HW/WiimoteEmu/Attachment/Nunchuk.h"
#include "InputCommon/UDPWiimote.h"
#include "InputCommon/UDPWrapper.h"
namespace WiimoteEmu
{
@@ -31,8 +28,7 @@ static const u8 nunchuk_button_bitmasks[] =
Nunchuk::BUTTON_Z,
};
Nunchuk::Nunchuk(UDPWrapper *wrp, WiimoteEmu::ExtensionReg& _reg)
: Attachment(_trans("Nunchuk"), _reg) , m_udpWrap(wrp)
Nunchuk::Nunchuk(WiimoteEmu::ExtensionReg& _reg) : Attachment(_trans("Nunchuk"), _reg)
{
// buttons
groups.emplace_back(m_buttons = new Buttons("Buttons"));
@@ -64,23 +60,23 @@ Nunchuk::Nunchuk(UDPWrapper *wrp, WiimoteEmu::ExtensionReg& _reg)
memset(m_shake_step, 0, sizeof(m_shake_step));
}
void Nunchuk::GetState(u8* const data, const bool focus)
void Nunchuk::GetState(u8* const data)
{
wm_extension* const ncdata = (wm_extension*)data;
ncdata->bt = 0;
// stick
ControlState state[2];
m_stick->GetState(&state[0], &state[1], 0, 1);
double state[2];
m_stick->GetState(&state[0], &state[1]);
nu_cal &cal = *(nu_cal*)&reg.calibration;
nu_js cal_js[2];
cal_js[0] = *&cal.jx;
cal_js[1] = *&cal.jy;
cal_js[0] = cal.jx;
cal_js[1] = cal.jy;
for (int i = 0; i < 2; i++) {
ControlState &s = *&state[i];
nu_js c = *&cal_js[i];
double &s = state[i];
nu_js c = cal_js[i];
if (s < 0)
s = s * abs(c.min - c.center) + c.center;
else if (s > 0)
@@ -100,59 +96,21 @@ void Nunchuk::GetState(u8* const data, const bool focus)
ncdata->jx = cal.jx.center + 1;
}
if (!focus)
{
ncdata->jx = cal.jx.center;
ncdata->jy = cal.jy.center;
}
AccelData accel;
// tilt
EmulateTilt(&accel, m_tilt, focus);
EmulateTilt(&accel, m_tilt);
if (focus)
{
// swing
EmulateSwing(&accel, m_swing);
// shake
EmulateShake(&accel, m_shake, m_shake_step);
// buttons
m_buttons->GetState(&ncdata->bt, nunchuk_button_bitmasks);
}
// swing
EmulateSwing(&accel, m_swing);
// shake
EmulateShake(&accel, m_shake, m_shake_step);
// buttons
m_buttons->GetState(&ncdata->bt, nunchuk_button_bitmasks);
// flip the button bits :/
ncdata->bt ^= 0x03;
if (m_udpWrap->inst)
{
if (m_udpWrap->updNun)
{
u8 mask;
float x, y;
m_udpWrap->inst->getNunchuck(&x, &y, &mask);
// buttons
if (mask & UDPWM_NC)
ncdata->bt &= ~WiimoteEmu::Nunchuk::BUTTON_C;
if (mask & UDPWM_NZ)
ncdata->bt &= ~WiimoteEmu::Nunchuk::BUTTON_Z;
// stick
if (ncdata->jx == 0x80 && ncdata->jy == 0x80)
{
ncdata->jx = u8(0x80 + x*127);
ncdata->jy = u8(0x80 + y*127);
}
}
if (m_udpWrap->updNunAccel)
{
float x, y, z;
m_udpWrap->inst->getNunchuckAccel(&x, &y, &z);
accel.x = x;
accel.y = y;
accel.z = z;
}
}
FillRawAccelFromGForceData(*(wm_accel*)&ncdata->ax, *(accel_cal*)&reg.calibration, accel);
}
@@ -6,17 +6,15 @@
#include "Core/HW/WiimoteEmu/Attachment/Attachment.h"
class UDPWrapper;
namespace WiimoteEmu
{
class Nunchuk : public Attachment
{
public:
Nunchuk(UDPWrapper * wrp, WiimoteEmu::ExtensionReg& _reg);
Nunchuk(WiimoteEmu::ExtensionReg& _reg);
virtual void GetState(u8* const data, const bool focus) override;
virtual void GetState(u8* const data) override;
enum
{
@@ -36,8 +34,6 @@ private:
AnalogStick* m_stick;
u8 m_shake_step[3];
UDPWrapper* const m_udpWrap;
};
}
@@ -55,63 +55,68 @@ Turntable::Turntable(WiimoteEmu::ExtensionReg& _reg) : Attachment(_trans("Turnta
memcpy(&id, turntable_id, sizeof(turntable_id));
}
void Turntable::GetState(u8* const data, const bool focus)
void Turntable::GetState(u8* const data)
{
wm_turntable_extension* const ttdata = (wm_turntable_extension*)data;
ttdata->bt = 0;
// stick
{
u8 x, y;
m_stick->GetState(&x, &y, 0x20, focus ? 0x1F /*0x15*/ : 0);
double x, y;
m_stick->GetState(&x, &y);
ttdata->sx = x;
ttdata->sy = y;
ttdata->sx = (x * 0x1F) + 0x20;
ttdata->sy = (y * 0x1F) + 0x20;
}
// left table
{
s8 tt = 0;
m_left_table->GetState(&tt, focus ? 0x1F : 0);
double tt;
s8 tt_;
m_left_table->GetState(&tt);
ttdata->ltable1 = tt;
ttdata->ltable2 = tt >> 5;
tt_ = tt * 0x1F;
ttdata->ltable1 = tt_;
ttdata->ltable2 = tt_ >> 5;
}
// right table
{
s8 tt = 0;
m_right_table->GetState(&tt, focus ? 0x1F : 0);
double tt;
s8 tt_;
m_right_table->GetState(&tt);
ttdata->rtable1 = tt;
ttdata->rtable2 = tt >> 1;
ttdata->rtable3 = tt >> 3;
ttdata->rtable4 = tt >> 5;
tt_ = tt * 0x1F;
ttdata->rtable1 = tt_;
ttdata->rtable2 = tt_ >> 1;
ttdata->rtable3 = tt_ >> 3;
ttdata->rtable4 = tt_ >> 5;
}
// effect dial
{
u8 dial = 0;
m_effect_dial->GetState(&dial, focus ? 0xF : 0);
double dial;
u8 dial_;
m_effect_dial->GetState(&dial);
ttdata->dial1 = dial;
ttdata->dial2 = dial >> 3;
dial_ = dial * 0x0F;
ttdata->dial1 = dial_;
ttdata->dial2 = dial_ >> 3;
}
// crossfade slider
{
s8 cfs = 0;
m_crossfade->GetState(&cfs, focus ? 7 : 0);
cfs += 8;
double cfs;
m_crossfade->GetState(&cfs);
ttdata->slider = cfs;
ttdata->slider = (cfs * 0x07) + 0x08;
}
if (focus)
{
// buttons
m_buttons->GetState(&ttdata->bt, turntable_button_bitmasks);
}
// buttons
m_buttons->GetState(&ttdata->bt, turntable_button_bitmasks);
// flip button bits :/
ttdata->bt ^= (
@@ -13,7 +13,7 @@ class Turntable : public Attachment
{
public:
Turntable(WiimoteEmu::ExtensionReg& _reg);
void GetState(u8* const data, const bool focus) override;
void GetState(u8* const data) override;
enum
{
@@ -1,54 +0,0 @@
// Copyright 2013 Dolphin Emulator Project
// Licensed under GPLv2
// Refer to the license.txt file included.
//UDP Wiimote Translation Layer
#pragma once
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
#include "InputCommon/UDPWiimote.h"
namespace UDPTLayer
{
static void GetButtons(UDPWrapper * m , wm_core * butt)
{
if (!(m->inst)) return;
if (!(m->updButt)) return;
u32 mask = m->inst->getButtons();
*butt |= (mask & UDPWM_BA) ? WiimoteEmu::Wiimote::BUTTON_A : 0;
*butt |= (mask & UDPWM_BB) ? WiimoteEmu::Wiimote::BUTTON_B : 0;
*butt |= (mask & UDPWM_B1) ? WiimoteEmu::Wiimote::BUTTON_ONE : 0;
*butt |= (mask & UDPWM_B2) ? WiimoteEmu::Wiimote::BUTTON_TWO : 0;
*butt |= (mask & UDPWM_BP) ? WiimoteEmu::Wiimote::BUTTON_PLUS : 0;
*butt |= (mask & UDPWM_BM) ? WiimoteEmu::Wiimote::BUTTON_MINUS : 0;
*butt |= (mask & UDPWM_BH) ? WiimoteEmu::Wiimote::BUTTON_HOME : 0;
*butt |= (mask & UDPWM_BU) ? WiimoteEmu::Wiimote::PAD_UP : 0;
*butt |= (mask & UDPWM_BD) ? WiimoteEmu::Wiimote::PAD_DOWN : 0;
*butt |= (mask & UDPWM_BL) ? WiimoteEmu::Wiimote::PAD_LEFT : 0;
*butt |= (mask & UDPWM_BR) ? WiimoteEmu::Wiimote::PAD_RIGHT : 0;
}
static void GetAcceleration(UDPWrapper * m , WiimoteEmu::AccelData * const data)
{
if (!(m->inst)) return;
if (!(m->updAccel)) return;
float x, y, z;
m->inst->getAccel(&x, &y, &z);
data->x = x;
data->y = y;
data->z = z;
}
static void GetIR( UDPWrapper * m, float * x, float * y, float * z)
{
if (!(m->inst)) return;
if (!(m->updIR)) return;
if ((*x >= -0.999) && (*x <= 0.999) && (*y >= -0.999) && (*y <= 0.999)) return; //the received values are used ONLY when the normal pointer is offscreen
float _x, _y;
m->inst->getIR(&_x, &_y);
*x = _x * 2 - 1;
*y = -(_y * 2 - 1);
*z = 0;
}
}
+85 -109
View File
@@ -13,7 +13,6 @@
#include "Core/NetPlayClient.h"
#include "Core/HW/WiimoteEmu/MatrixMath.h"
#include "Core/HW/WiimoteEmu/UDPTLayer.h"
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
#include "Core/HW/WiimoteEmu/WiimoteHid.h"
#include "Core/HW/WiimoteEmu/Attachment/Classic.h"
@@ -119,11 +118,14 @@ void EmulateShake(AccelData* const accel
void EmulateTilt(AccelData* const accel
, ControllerEmu::Tilt* const tilt_group
, const bool focus, const bool sideways, const bool upright)
, const bool sideways, const bool upright)
{
float roll, pitch;
double roll, pitch;
// 180 degrees
tilt_group->GetState(&roll, &pitch, 0, focus ? PI : 0);
tilt_group->GetState(&roll, &pitch);
roll *= PI;
pitch *= PI;
unsigned int ud = 0, lr = 0, fb = 0;
@@ -145,7 +147,7 @@ void EmulateTilt(AccelData* const accel
if (!sideways && upright)
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)[fb] = sin(pitch)*sgn[fb];
}
@@ -156,8 +158,8 @@ void EmulateSwing(AccelData* const accel
, ControllerEmu::Force* const swing_group
, const bool sideways, const bool upright)
{
float swing[3];
swing_group->GetState(swing, 0, SWING_INTENSITY);
double swing[3];
swing_group->GetState(swing);
s8 g_dir[3] = {-1, -1, -1};
u8 axis_map[3];
@@ -175,7 +177,7 @@ void EmulateSwing(AccelData* const accel
g_dir[axis_map[0]] *= -1;
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[] =
@@ -266,9 +268,6 @@ Wiimote::Wiimote( const unsigned int index )
for (auto& named_button : named_buttons)
m_buttons->controls.emplace_back(new ControlGroup::Input( named_button));
// udp
groups.emplace_back(m_udp = new UDPWrapper(m_index, _trans("UDP Wiimote")));
// ir
groups.emplace_back(m_ir = new Cursor(_trans("IR")));
@@ -287,7 +286,7 @@ Wiimote::Wiimote( const unsigned int index )
// extension
groups.emplace_back(m_extension = new Extension(_trans("Extension")));
m_extension->attachments.emplace_back(new WiimoteEmu::None(m_reg_ext));
m_extension->attachments.emplace_back(new WiimoteEmu::Nunchuk(m_udp, m_reg_ext));
m_extension->attachments.emplace_back(new WiimoteEmu::Nunchuk(m_reg_ext));
m_extension->attachments.emplace_back(new WiimoteEmu::Classic(m_reg_ext));
m_extension->attachments.emplace_back(new WiimoteEmu::Guitar(m_reg_ext));
m_extension->attachments.emplace_back(new WiimoteEmu::Drums(m_reg_ext));
@@ -306,7 +305,7 @@ Wiimote::Wiimote( const unsigned int index )
// options
groups.emplace_back( m_options = new ControlGroup(_trans("Options")));
m_options->settings.emplace_back(new ControlGroup::Setting(_trans("Background Input"), false));
m_options->settings.emplace_back(new ControlGroup::BackgroundInputSetting(_trans("Background Input")));
m_options->settings.emplace_back(new ControlGroup::Setting(_trans("Sideways Wiimote"), false));
m_options->settings.emplace_back(new ControlGroup::Setting(_trans("Upright Wiimote"), false));
@@ -322,26 +321,17 @@ std::string Wiimote::GetName() const
return std::string("Wiimote") + char('1'+m_index);
}
// if windows is focused or background input is enabled
#define HAS_FOCUS (Host_RendererHasFocus() || (m_options->settings[0]->value != 0))
bool Wiimote::Step()
{
const bool has_focus = HAS_FOCUS;
// TODO: change this a bit
m_motion_plus_present = m_extension->settings[0]->value != 0;
// no rumble if no focus
if (false == has_focus)
m_rumble_on = false;
m_rumble->controls[0]->control_ref->State(m_rumble_on);
// when a movie is active, this button status update is disabled (moved), because movies only record data reports.
if (!(Movie::IsPlayingInput() || Movie::IsRecordingInput()) || NetPlay::IsNetPlayRunning())
{
UpdateButtonsStatus(has_focus);
UpdateButtonsStatus();
}
// check if there is a read data request
@@ -381,17 +371,13 @@ bool Wiimote::Step()
return false;
}
void Wiimote::UpdateButtonsStatus(bool has_focus)
void Wiimote::UpdateButtonsStatus()
{
// update buttons in status struct
m_status.buttons = 0;
if (has_focus)
{
const bool is_sideways = m_options->settings[1]->value != 0;
m_buttons->GetState(&m_status.buttons, button_bitmasks);
m_dpad->GetState(&m_status.buttons, is_sideways ? dpad_sideways_bitmasks : dpad_bitmasks);
UDPTLayer::GetButtons(m_udp, &m_status.buttons);
}
const bool is_sideways = m_options->settings[1]->value != 0;
m_buttons->GetState(&m_status.buttons, button_bitmasks);
m_dpad->GetState(&m_status.buttons, is_sideways ? dpad_sideways_bitmasks : dpad_bitmasks);
}
void Wiimote::GetCoreData(u8* const data)
@@ -399,7 +385,7 @@ void Wiimote::GetCoreData(u8* const data)
// when a movie is active, the button update happens here instead of Wiimote::Step, to avoid potential desync issues.
if (Movie::IsPlayingInput() || Movie::IsRecordingInput() || NetPlay::IsNetPlayRunning())
{
UpdateButtonsStatus(HAS_FOCUS);
UpdateButtonsStatus();
}
*(wm_core*)data |= m_status.buttons;
@@ -407,21 +393,16 @@ void Wiimote::GetCoreData(u8* const data)
void Wiimote::GetAccelData(u8* const data)
{
const bool has_focus = HAS_FOCUS;
const bool is_sideways = m_options->settings[1]->value != 0;
const bool is_upright = m_options->settings[2]->value != 0;
// ----TILT----
EmulateTilt(&m_accel, m_tilt, has_focus, is_sideways, is_upright);
EmulateTilt(&m_accel, m_tilt, is_sideways, is_upright);
// ----SWING----
// ----SHAKE----
if (has_focus)
{
EmulateSwing(&m_accel, m_swing, is_sideways, is_upright);
EmulateShake(&m_accel, m_shake, m_shake_step);
UDPTLayer::GetAcceleration(m_udp, &m_accel);
}
EmulateSwing(&m_accel, m_swing, is_sideways, is_upright);
EmulateShake(&m_accel, m_shake, m_shake_step);
FillRawAccelFromGForceData(*(wm_accel*)data, *(accel_cal*)&m_eeprom[0x16], m_accel);
}
@@ -435,94 +416,89 @@ inline void LowPassFilter(double & var, double newval, double period)
void Wiimote::GetIRData(u8* const data, bool use_accel)
{
const bool has_focus = HAS_FOCUS;
u16 x[4], y[4];
memset(x, 0xFF, sizeof(x));
if (has_focus)
{
float xx = 10000, yy = 0, zz = 0;
double nsin,ncos;
double xx = 10000, yy = 0, zz = 0;
double nsin,ncos;
if (use_accel)
if (use_accel)
{
double ax,az,len;
ax=m_accel.x;
az=m_accel.z;
len=sqrt(ax*ax+az*az);
if (len)
{
double ax,az,len;
ax=m_accel.x;
az=m_accel.z;
len=sqrt(ax*ax+az*az);
if (len)
{
ax/=len;
az/=len; //normalizing the vector
nsin=ax;
ncos=az;
}
else
{
nsin=0;
ncos=1;
}
// PanicAlert("%d %d %d\nx:%f\nz:%f\nsin:%f\ncos:%f",accel->x,accel->y,accel->z,ax,az,sin,cos);
// PanicAlert("%d %d %d\n%d %d %d\n%d %d %d",accel->x,accel->y,accel->z,calib->zero_g.x,calib->zero_g.y,calib->zero_g.z, calib->one_g.x,calib->one_g.y,calib->one_g.z);
ax/=len;
az/=len; //normalizing the vector
nsin=ax;
ncos=az;
}
else
{
nsin=0; //m_tilt stuff here (can't figure it out yet....)
nsin=0;
ncos=1;
}
// PanicAlert("%d %d %d\nx:%f\nz:%f\nsin:%f\ncos:%f",accel->x,accel->y,accel->z,ax,az,sin,cos);
// PanicAlert("%d %d %d\n%d %d %d\n%d %d %d",accel->x,accel->y,accel->z,calib->zero_g.x,calib->zero_g.y,calib->zero_g.z, calib->one_g.x,calib->one_g.y,calib->one_g.z);
}
else
{
nsin=0; //m_tilt stuff here (can't figure it out yet....)
ncos=1;
}
LowPassFilter(ir_sin,nsin,1.0f/60);
LowPassFilter(ir_cos,ncos,1.0f/60);
LowPassFilter(ir_sin,nsin,1.0f/60);
LowPassFilter(ir_cos,ncos,1.0f/60);
m_ir->GetState(&xx, &yy, &zz, true);
UDPTLayer::GetIR(m_udp, &xx, &yy, &zz);
m_ir->GetState(&xx, &yy, &zz, true);
Vertex v[4];
Vertex v[4];
static const int camWidth=1024;
static const int camHeight=768;
static const double bndup=-0.315447;
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 int camWidth=1024;
static const int camHeight=768;
static const double bndup=-0.315447;
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;
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.z=0;
}
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.z=0;
}
v[0].x-=(zz*0.5+1)*dist1;
v[1].x+=(zz*0.5+1)*dist1;
v[2].x-=(zz*0.5+1)*dist2;
v[3].x+=(zz*0.5+1)*dist2;
v[0].x-=(zz*0.5+1)*dist1;
v[1].x+=(zz*0.5+1)*dist1;
v[2].x-=(zz*0.5+1)*dist2;
v[3].x+=(zz*0.5+1)*dist2;
#define printmatrix(m) PanicAlert("%f %f %f %f\n%f %f %f %f\n%f %f %f %f\n%f %f %f %f\n",m[0][0],m[0][1],m[0][2],m[0][3],m[1][0],m[1][1],m[1][2],m[1][3],m[2][0],m[2][1],m[2][2],m[2][3],m[3][0],m[3][1],m[3][2],m[3][3])
Matrix rot,tot;
static Matrix scale;
MatrixScale(scale,1,camWidth/camHeight,1);
//MatrixIdentity(scale);
MatrixRotationByZ(rot,ir_sin,ir_cos);
//MatrixIdentity(rot);
MatrixMultiply(tot,scale,rot);
Matrix rot,tot;
static Matrix scale;
MatrixScale(scale,1,camWidth/camHeight,1);
//MatrixIdentity(scale);
MatrixRotationByZ(rot,ir_sin,ir_cos);
//MatrixIdentity(rot);
MatrixMultiply(tot,scale,rot);
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))
continue;
x[i] = (u16)lround((v[i].x+1)/2*(camWidth-1));
y[i] = (u16)lround((v[i].y+1)/2*(camHeight-1));
}
// PanicAlert("%f %f\n%f %f\n%f %f\n%f %f\n%d %d\n%d %d\n%d %d\n%d %d",
// v[0].x,v[0].y,v[1].x,v[1].y,v[2].x,v[2].y,v[3].x,v[3].y,
// x[0],y[0],x[1],y[1],x[2],y[2],x[3],y[38]);
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))
continue;
x[i] = (u16)lround((v[i].x+1)/2*(camWidth-1));
y[i] = (u16)lround((v[i].y+1)/2*(camHeight-1));
}
// PanicAlert("%f %f\n%f %f\n%f %f\n%f %f\n%d %d\n%d %d\n%d %d\n%d %d",
// v[0].x,v[0].y,v[1].x,v[1].y,v[2].x,v[2].y,v[3].x,v[3].y,
// x[0],y[0],x[1],y[1],x[2],y[2],x[3],y[38]);
// Fill report with valid data when full handshake was done
if (m_reg_ir.data[0x30])
// ir mode
@@ -582,7 +558,7 @@ void Wiimote::GetIRData(u8* const data, bool use_accel)
void Wiimote::GetExtData(u8* const data)
{
m_extension->GetState(data, HAS_FOCUS);
m_extension->GetState(data);
// i dont think anything accesses the extension data like this, but ill support it. Indeed, commercial games don't do this.
// i think it should be unencrpyted in the register, encrypted when read.
+2 -5
View File
@@ -12,7 +12,6 @@
#include "Core/HW/WiimoteEmu/Encryption.h"
#include "Core/HW/WiimoteEmu/WiimoteHid.h"
#include "InputCommon/ControllerEmu.h"
#include "InputCommon/UDPWrapper.h"
// Registry sizes
#define WIIMOTE_EEPROM_SIZE (16*1024)
@@ -78,7 +77,7 @@ void EmulateShake(AccelData* const accel_data
void EmulateTilt(AccelData* const accel
, ControllerEmu::Tilt* const tilt_group
, const bool focus, const bool sideways = false, const bool upright = false);
, const bool sideways = false, const bool upright = false);
void EmulateSwing(AccelData* const accel
, ControllerEmu::Force* const tilt_group
@@ -129,7 +128,7 @@ protected:
bool Step();
void HidOutputReport(const wm_report* const sr, const bool send_ack = true);
void HandleExtensionSwap();
void UpdateButtonsStatus(bool has_focus);
void UpdateButtonsStatus();
void GetCoreData(u8* const data);
void GetAccelData(u8* const data);
@@ -175,8 +174,6 @@ private:
double ir_sin, ir_cos; //for the low pass filter
UDPWrapper* m_udp;
bool m_rumble_on;
bool m_speaker_mute;
bool m_motion_plus_present;

Some files were not shown because too many files have changed in this diff Show More