Keyboard Wiimote emulation cleanup, phase one

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4665 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
bztdlinux
2009-12-09 16:33:32 +00:00
parent 0fa1f968c7
commit 828bf052f0
3 changed files with 48 additions and 30 deletions

View File

@ -63,6 +63,13 @@ std::vector<InputCommon::CONTROLLER_INFO> joyinfo;
InputCommon::CONTROLLER_STATE_NEW PadState[4]; InputCommon::CONTROLLER_STATE_NEW PadState[4];
InputCommon::CONTROLLER_MAPPING_NEW PadMapping[4]; InputCommon::CONTROLLER_MAPPING_NEW PadMapping[4];
// Shake emulation
ShakeData::ShakeData() {
Shake = 0;
Roll = 0;
Pitch = 0;
}
// Keyboard input // Keyboard input
KeyboardWiimote g_Wiimote_kbd; KeyboardWiimote g_Wiimote_kbd;
KeyboardNunchuck g_NunchuckExt; KeyboardNunchuck g_NunchuckExt;

View File

@ -171,6 +171,15 @@ struct SIR
int Distance; int Distance;
}; };
class ShakeData
{
public:
ShakeData();
int Shake;
int Roll, Pitch;
};
// Keyboard input // Keyboard input
struct KeyboardWiimote struct KeyboardWiimote
{ {
@ -190,6 +199,7 @@ struct KeyboardWiimote
// Raw X and Y coordinate and processed X and Y coordinates // Raw X and Y coordinate and processed X and Y coordinates
SIR IR; SIR IR;
ShakeData shakeData;
}; };
extern KeyboardWiimote g_Wiimote_kbd; extern KeyboardWiimote g_Wiimote_kbd;
struct KeyboardNunchuck struct KeyboardNunchuck
@ -207,6 +217,7 @@ struct KeyboardNunchuck
SHAKE, SHAKE,
LAST_CONSTANT LAST_CONSTANT
}; };
ShakeData shakeData;
}; };
extern KeyboardNunchuck g_NunchuckExt; extern KeyboardNunchuck g_NunchuckExt;
struct KeyboardClassicController struct KeyboardClassicController

View File

@ -430,21 +430,19 @@ Y |. .|| Z
*/ */
// Global declarations for FillReportAcc: These variables are global void StartShake(ShakeData &shakeData) {
// For the shake function, Wiimote: wm = 0, Nunchuck: wm = 1 shakeData.Shake = 1;
int Shake[] = {0, 0}; }
int Roll = 0, Pitch = 0;
// Single shake of all three directions // Single shake step of all three directions
void SingleShake(int &_x, int &_y, int &_z, int wm) void SingleShake(int &_x, int &_y, int &_z, ShakeData &shakeData)
{ {
#ifdef _WIN32 // if (shakeData.Shake == 0)
if (Shake[wm] == 0) // {
{ // if((wm == 0 && IsKey(g_Wiimote_kbd.SHAKE)) || (wm == 1 && IsKey(g_NunchuckExt.SHAKE)))
if((wm == 0 && IsKey(g_Wiimote_kbd.SHAKE)) || (wm == 1 && IsKey(g_NunchuckExt.SHAKE))) // Shake[wm] = 1;
Shake[wm] = 1; // }
} switch(shakeData.Shake)
switch(Shake[wm])
{ {
case 1: case 1:
case 3: case 3:
@ -474,11 +472,10 @@ void SingleShake(int &_x, int &_y, int &_z, int wm)
_z = 0x80; _z = 0x80;
break; break;
default: default:
Shake[wm] = -1; shakeData.Shake = -1;
break; break;
} }
Shake[wm]++; shakeData.Shake++;
#endif
//if (Shake[wm] != 0) DEBUG_LOG(WIIMOTE, "Shake: %i - 0x%02x, 0x%02x, 0x%02x", Shake[wm], _x, _y, _z); //if (Shake[wm] != 0) DEBUG_LOG(WIIMOTE, "Shake: %i - 0x%02x, 0x%02x, 0x%02x", Shake[wm], _x, _y, _z);
} }
@ -614,16 +611,16 @@ void Tilt(int &_x, int &_y, int &_z)
// Select input method and return the x, y, x values // Select input method and return the x, y, x values
if (g_Config.Tilt.Type == g_Config.Tilt.KEYBOARD) if (g_Config.Tilt.Type == g_Config.Tilt.KEYBOARD)
TiltWiimoteKeyboard(Roll, Pitch); TiltWiimoteKeyboard(g_Wiimote_kbd.shakeData.Roll, g_Wiimote_kbd.shakeData.Pitch);
else if (g_Config.Tilt.Type == g_Config.Tilt.TRIGGER || g_Config.Tilt.Type == g_Config.Tilt.ANALOG1 || g_Config.Tilt.Type == g_Config.Tilt.ANALOG2) else if (g_Config.Tilt.Type == g_Config.Tilt.TRIGGER || g_Config.Tilt.Type == g_Config.Tilt.ANALOG1 || g_Config.Tilt.Type == g_Config.Tilt.ANALOG2)
TiltWiimoteGamepad(Roll, Pitch); TiltWiimoteGamepad(g_Wiimote_kbd.shakeData.Roll, g_Wiimote_kbd.shakeData.Pitch);
// Adjust angles, it's only needed if both roll and pitch is used together // Adjust angles, it's only needed if both roll and pitch is used together
if (g_Config.Tilt.Range.Roll != 0 && g_Config.Tilt.Range.Pitch != 0) if (g_Config.Tilt.Range.Roll != 0 && g_Config.Tilt.Range.Pitch != 0)
AdjustAngles(Roll, Pitch); AdjustAngles(g_Wiimote_kbd.shakeData.Roll, g_Wiimote_kbd.shakeData.Pitch);
// Calculate the accelerometer value from this tilt angle // Calculate the accelerometer value from this tilt angle
PitchDegreeToAccelerometer(Roll, Pitch, _x, _y, _z); PitchDegreeToAccelerometer(g_Wiimote_kbd.shakeData.Roll, g_Wiimote_kbd.shakeData.Pitch, _x, _y, _z);
//DEBUG_LOG(WIIMOTE, "Roll:%i, Pitch:%i, _x:%u, _y:%u, _z:%u", Roll, Pitch, _x, _y, _z); //DEBUG_LOG(WIIMOTE, "Roll:%i, Pitch:%i, _x:%u, _y:%u, _z:%u", Roll, Pitch, _x, _y, _z);
} }
@ -657,15 +654,17 @@ void FillReportAcc(wm_accel& _acc)
// Check that Dolphin is in focus // Check that Dolphin is in focus
if (IsFocus()) if (IsFocus())
{ {
// Shake the Wiimote // Check for shake button
SingleShake(acc_x, acc_y, acc_z, 0); if(IsKey(g_Wiimote_kbd.SHAKE)) StartShake(g_Wiimote_kbd.shakeData);
// Step the shake simulation one step
SingleShake(acc_x, acc_y, acc_z, g_Wiimote_kbd.shakeData);
// Tilt Wiimote, allow the shake function to interrupt it // Tilt Wiimote, allow the shake function to interrupt it
if (Shake[0] == 0) Tilt(acc_x, acc_y, acc_z); if (g_Wiimote_kbd.shakeData.Shake == 0) Tilt(acc_x, acc_y, acc_z);
// Boundary check // Boundary check
if (acc_x > 0xFF) acc_x = 0xFF; if (acc_x > 0xFF) acc_x = 0xFF;
else if (_acc.x < 0x00) acc_x = 0x00; else if (acc_x < 0x00) acc_x = 0x00;
if (acc_y > 0xFF) acc_y = 0xFF; if (acc_y > 0xFF) acc_y = 0xFF;
else if (acc_y < 0x00) acc_y = 0x00; else if (acc_y < 0x00) acc_y = 0x00;
if (acc_z > 0xFF) acc_z = 0xFF; if (acc_z > 0xFF) acc_z = 0xFF;
@ -812,8 +811,8 @@ void FillReportIR(wm_ir_extended& _ir0, wm_ir_extended& _ir1)
int x0 = 1023 - g_Config.iIRLeft - g_Config.iIRWidth * MouseX - SENSOR_BAR_WIDTH / 2; int x0 = 1023 - g_Config.iIRLeft - g_Config.iIRWidth * MouseX - SENSOR_BAR_WIDTH / 2;
int x1 = x0 + SENSOR_BAR_WIDTH; int x1 = x0 + SENSOR_BAR_WIDTH;
RotateIRDot(Roll, x0, y0); RotateIRDot(g_Wiimote_kbd.shakeData.Roll, x0, y0);
RotateIRDot(Roll, x1, y1); RotateIRDot(g_Wiimote_kbd.shakeData.Roll, x1, y1);
// Converted to IR data // Converted to IR data
_ir0.x = x0 & 0xff; _ir0.xHi = x0 >> 8; _ir0.x = x0 & 0xff; _ir0.xHi = x0 >> 8;
@ -889,8 +888,8 @@ void FillReportIRBasic(wm_ir_basic& _ir0, wm_ir_basic& _ir1)
int x1 = 1023 - g_Config.iIRLeft - g_Config.iIRWidth * MouseX - SENSOR_BAR_WIDTH / 2; int x1 = 1023 - g_Config.iIRLeft - g_Config.iIRWidth * MouseX - SENSOR_BAR_WIDTH / 2;
int x2 = x1 + SENSOR_BAR_WIDTH; int x2 = x1 + SENSOR_BAR_WIDTH;
RotateIRDot(Roll, x1, y1); RotateIRDot(g_Wiimote_kbd.shakeData.Roll, x1, y1);
RotateIRDot(Roll, x2, y2); RotateIRDot(g_Wiimote_kbd.shakeData.Roll, x2, y2);
/* As with the extented report we settle with emulating two out of four /* As with the extented report we settle with emulating two out of four
possible objects the only difference is that we don't report any size of possible objects the only difference is that we don't report any size of
@ -967,8 +966,9 @@ void FillReportExtension(wm_extension& _ext)
int ext_ay = g_nu.cal_zero.y; int ext_ay = g_nu.cal_zero.y;
int ext_az = g_nu.cal_zero.z + g_nu.cal_g.z; int ext_az = g_nu.cal_zero.z + g_nu.cal_g.z;
// Shake the Wiimote if(IsKey(g_NunchuckExt.SHAKE)) StartShake(g_NunchuckExt.shakeData);
SingleShake(ext_ax, ext_ay, ext_az, 1); // Shake the Nunchuk one frame
SingleShake(ext_ax, ext_ay, ext_az, g_NunchuckExt.shakeData);
_ext.ax = ext_ax; _ext.ax = ext_ax;
_ext.ay = ext_ay; _ext.ay = ext_ay;