diff options
| author | Jordan Woyak <jordan.woyak@gmail.com> | 2010-04-24 00:44:10 +0000 |
|---|---|---|
| committer | Jordan Woyak <jordan.woyak@gmail.com> | 2010-04-24 00:44:10 +0000 |
| commit | 23689387e1f00bf045daa44df5c733950cdfb5d2 (patch) | |
| tree | eee9dbd66cdc19e8309791e1bff89a9560d99395 /Source/Plugins/InputPluginCommon | |
| parent | 1d8db5ce3f44cf637a88a6521680e2a336ff8f7c (diff) | |
More improvements to new wiimote plugin: Added emulated Drums/Guitar extensions. Wiimote rumble now handled for every output report. Fixed some mem leaks. Hopefully fixed a floating point exception in Linux, thanks to glennrics.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5403 8ced0084-cf51-0410-be5f-012b33b47a6e
Diffstat (limited to 'Source/Plugins/InputPluginCommon')
5 files changed, 120 insertions, 59 deletions
diff --git a/Source/Plugins/InputPluginCommon/Src/Config.cpp b/Source/Plugins/InputPluginCommon/Src/Config.cpp index f8278225fa..417867c175 100644 --- a/Source/Plugins/InputPluginCommon/Src/Config.cpp +++ b/Source/Plugins/InputPluginCommon/Src/Config.cpp @@ -48,7 +48,7 @@ void Plugin::SaveConfig() (*i)->SaveConfig( inifile[ (*i)->GetName() ] ); // dont need to save empty values - inifile.Clean(); + //inifile.Clean(); std::ofstream file; file.open( (std::string(File::GetUserPath(D_CONFIG_IDX)) + ini_name + ".ini" ).c_str() ); diff --git a/Source/Plugins/InputPluginCommon/Src/ConfigDiag.cpp b/Source/Plugins/InputPluginCommon/Src/ConfigDiag.cpp index 72738c9164..afa521d8d8 100644 --- a/Source/Plugins/InputPluginCommon/Src/ConfigDiag.cpp +++ b/Source/Plugins/InputPluginCommon/Src/ConfigDiag.cpp @@ -714,24 +714,36 @@ ControlGroupBox::ControlGroupBox( ControllerEmu::ControlGroup* const group, wxWi } break; case GROUP_TYPE_MIXED_TRIGGERS : + case GROUP_TYPE_TRIGGERS : { - wxBitmap bitmap(64+12+1, int(6*group->controls.size())+1); + int height = (int)(6 * group->controls.size()); + int width = 64+12+1; + if (GROUP_TYPE_TRIGGERS == group->type) + { + height *= 2; + width = 64; + } + wxBitmap bitmap(width, height+1); wxMemoryDC dc; dc.SelectObject(bitmap); dc.Clear(); dc.SelectObject(wxNullBitmap); static_bitmap = new wxStaticBitmap( parent, -1, bitmap, wxDefaultPosition, wxDefaultSize, wxBITMAP_TYPE_BMP ); - PadSettingChoice* threshold_cbox = new PadSettingChoice( parent, group->settings[0] ); - _connect_macro_( threshold_cbox, GamepadPage::AdjustSetting, wxEVT_COMMAND_CHOICE_SELECTED, eventsink ); - - options.push_back( threshold_cbox ); - - wxBoxSizer* const szr = new wxBoxSizer( wxHORIZONTAL ); - szr->Add( new wxStaticText( parent, -1, wxString::FromAscii( group->settings[0]->name ) ), 0, wxCENTER|wxRIGHT, 5 ); - szr->Add( threshold_cbox, 0, wxRIGHT, 5 ); + std::vector<ControllerEmu::ControlGroup::Setting*>::const_iterator + i = group->settings.begin(), + e = group->settings.end(); + for ( ; i!=e; ++i ) + { + PadSettingChoice* cbox = new PadSettingChoice( parent, *i ); + _connect_macro_( cbox, GamepadPage::AdjustSetting, wxEVT_COMMAND_CHOICE_SELECTED, eventsink ); + options.push_back( cbox ); + wxBoxSizer* const szr = new wxBoxSizer( wxHORIZONTAL ); + szr->Add( new wxStaticText( parent, -1, wxString::FromAscii( (*i)->name ) ), 0, wxCENTER|wxRIGHT, 5 ); + szr->Add( cbox, 0, wxRIGHT, 5 ); + Add( szr, 0, wxALL|wxCENTER, 5 ); + } - Add( szr, 0, wxALL|wxCENTER, 5 ); Add( static_bitmap, 0, wxALL|wxCENTER, 5 ); } break; diff --git a/Source/Plugins/InputPluginCommon/Src/ConfigDiagBitmaps.cpp b/Source/Plugins/InputPluginCommon/Src/ConfigDiagBitmaps.cpp index 04061098e8..0cb19ef610 100644 --- a/Source/Plugins/InputPluginCommon/Src/ConfigDiagBitmaps.cpp +++ b/Source/Plugins/InputPluginCommon/Src/ConfigDiagBitmaps.cpp @@ -79,9 +79,9 @@ void ConfigDialog::UpdateBitmaps(wxTimerEvent& WXUNUSED(event)) else dc.DrawRectangle( 16, 16, 32, 32 ); - // deadzone circle if ( GROUP_TYPE_CURSOR != (*g)->control_group->type ) { + // deadzone circle dc.SetBrush(*wxLIGHT_GREY_BRUSH); dc.DrawCircle( 32, 32, ((*g)->control_group)->settings[0]->value * 32 ); @@ -166,7 +166,52 @@ void ConfigDialog::UpdateBitmaps(wxTimerEvent& WXUNUSED(event)) (*g)->static_bitmap->SetBitmap( bitmap ); } break; + case GROUP_TYPE_TRIGGERS : + { + const unsigned int trigger_count = ((unsigned int)((*g)->control_group->controls.size())); + // setup + wxBitmap bitmap( 64, 12*trigger_count+1); + wxMemoryDC dc; + dc.SelectObject(bitmap); + dc.Clear(); + + // draw the shit + dc.SetPen(*wxGREY_PEN); + ControlState deadzone = (*g)->control_group->settings[0]->value; + + unsigned int* const trigs = new unsigned int[trigger_count]; + ((ControllerEmu::Triggers*)(*g)->control_group)->GetState( trigs, 64 ); + + for ( unsigned int n = 0; n < trigger_count; ++n ) + { + ControlState trig_r = (*g)->control_group->controls[n]->control_ref->State(); + + dc.SetBrush(*wxGREY_BRUSH); + dc.DrawRectangle(0, n*12, trig_r*64, 14); + + dc.SetBrush(*wxRED_BRUSH); + dc.DrawRectangle(0, n*12, trigs[n], 14); + } + + delete[] trigs; + // deadzone box + dc.SetPen(*wxLIGHT_GREY_PEN); + dc.SetBrush(*wxTRANSPARENT_BRUSH); + dc.DrawRectangle(0, 0, deadzone*64, trigger_count*14); + + // box outline + // Windows XP color + dc.SetPen(wxPen(_T("#7f9db9"))); + dc.DrawRectangle(0, 0, bitmap.GetWidth(), bitmap.GetHeight()); + + // done drawing + dc.SelectObject(wxNullBitmap); + + // set the shit + (*g)->static_bitmap->SetBitmap( bitmap ); + } + break; case GROUP_TYPE_MIXED_TRIGGERS : { const unsigned int trigger_count = ((unsigned int)((*g)->control_group->controls.size() / 2)); @@ -194,6 +239,9 @@ void ConfigDialog::UpdateBitmaps(wxTimerEvent& WXUNUSED(event)) dc.DrawRectangle(trig_a*64, n*12, 64+20, 14); dc.DrawRectangle(64, n*12, 32, 14); } + + // threshold box + dc.SetPen(*wxLIGHT_GREY_PEN); dc.SetBrush(*wxTRANSPARENT_BRUSH); dc.DrawRectangle(thresh*64, 0, 128, trigger_count*14); diff --git a/Source/Plugins/InputPluginCommon/Src/ControllerEmu.cpp b/Source/Plugins/InputPluginCommon/Src/ControllerEmu.cpp index 70aa0998cb..b15607e5cc 100644 --- a/Source/Plugins/InputPluginCommon/Src/ControllerEmu.cpp +++ b/Source/Plugins/InputPluginCommon/Src/ControllerEmu.cpp @@ -4,11 +4,9 @@ #include <X11/Xlib.h> #endif -const char modifier[] = "Modifier"; - - ControllerEmu::~ControllerEmu() { + // control groups std::vector<ControlGroup*>::const_iterator i = groups.begin(), e = groups.end(); @@ -18,12 +16,14 @@ ControllerEmu::~ControllerEmu() ControllerEmu::ControlGroup::~ControlGroup() { + // controls std::vector<Control*>::const_iterator ci = controls.begin(), ce = controls.end(); for ( ; ci!=ce; ++ci ) delete *ci; + // settings std::vector<Setting*>::const_iterator si = settings.begin(), se = settings.end(); @@ -31,6 +31,20 @@ ControllerEmu::ControlGroup::~ControlGroup() delete *si; } +ControllerEmu::Extension::~Extension() +{ + // attachments + std::vector<ControllerEmu*>::const_iterator + ai = attachments.begin(), + ae = attachments.end(); + for ( ; ai!=ae; ++ai ) + delete *ai; +} +ControllerEmu::ControlGroup::Control::~Control() +{ + delete control_ref; +} + void ControllerEmu::UpdateReferences( ControllerInterface& devi ) { std::vector<ControlGroup*>::const_iterator @@ -170,7 +184,7 @@ void ControllerEmu::ControlGroup::SaveConfig( IniFile::Section& sec, const std:: for ( ; ci!=ce; ++ci ) { // control and dev qualifier - sec[group + (*ci)->name] = (*ci)->control_ref->control_qualifier.name; + sec.Set( group+(*ci)->name, (*ci)->control_ref->control_qualifier.name ); sec.Set( group+(*ci)->name+"/Device", (*ci)->control_ref->device_qualifier.ToString(), defdev ); // range @@ -200,7 +214,7 @@ void ControllerEmu::SaveConfig( IniFile::Section& sec, const std::string& base ) { const std::string defdev = default_device.ToString(); if ( base.empty() ) - sec[ std::string(" ") + base + "Device" ] = defdev; + sec.Set( std::string(" ") + base + "Device", defdev ); std::vector<ControlGroup*>::const_iterator i = groups.begin(), e = groups.end(); @@ -213,7 +227,7 @@ ControllerEmu::AnalogStick::AnalogStick( const char* const _name ) : ControlGrou for ( unsigned int i = 0; i < 4; ++i ) controls.push_back( new Input( named_directions[i] ) ); - controls.push_back( new Input( modifier ) ); + controls.push_back( new Input( "Modifier" ) ); settings.push_back( new Setting("Dead Zone", 0, 1, 50 ) ); settings.push_back( new Setting("Square Stick", 0 ) ); @@ -230,6 +244,11 @@ ControllerEmu::MixedTriggers::MixedTriggers( const char* const _name ) : Control settings.push_back( new Setting("Threshold", 0.9f ) ); } +ControllerEmu::Triggers::Triggers( const char* const _name ) : ControlGroup( _name, GROUP_TYPE_TRIGGERS ) +{ + settings.push_back( new Setting("Dead Zone", 0, 1, 50 ) ); +} + ControllerEmu::Force::Force( const char* const _name ) : ControlGroup( _name, GROUP_TYPE_FORCE ) { controls.push_back( new Input( "X-" ) ); @@ -255,7 +274,7 @@ ControllerEmu::Tilt::Tilt( const char* const _name ) : ControlGroup( _name, GROU controls.push_back( new Input( "Left" ) ); controls.push_back( new Input( "Right" ) ); - controls.push_back( new Input( modifier ) ); + controls.push_back( new Input( "Modifier" ) ); settings.push_back( new Setting("Dead Zone", 0, 1, 50 ) ); settings.push_back( new Setting("Circle Stick", 0 ) ); @@ -275,31 +294,6 @@ ControllerEmu::Cursor::Cursor( const char* const _name, const SWiimoteInitialize } -//void GetMousePos(float& x, float& y, const SWiimoteInitialize* const wiimote_initialize) -//{ -//#ifdef _WIN32 -// // Get the cursor position for the entire screen -// POINT point; -// GetCursorPos(&point); -// // Get the cursor position relative to the upper left corner of the rendering window -// ScreenToClient(wiimote_initialize->hWnd, &point); -// -// // Get the size of the rendering window. (In my case Rect.top and Rect.left was zero.) -// RECT Rect; -// GetClientRect(wiimote_initialize->hWnd, &Rect); -// // Width and height is the size of the rendering window -// float WinWidth = (float)(Rect.right - Rect.left); -// float WinHeight = (float)(Rect.bottom - Rect.top); -// float XOffset = 0, YOffset = 0; -// float PictureWidth = WinWidth, PictureHeight = WinHeight; -//#endif -// -// x = ((float)point.x - XOffset) / PictureWidth; -// y = ((float)point.y - YOffset) / PictureHeight; -// x *=2; x-=1; -// y *=2; y-=1; -//} - void GetMousePos(float& x, float& y, const SWiimoteInitialize* const wiimote_initialize) { unsigned int win_width = 2, win_height = 2; diff --git a/Source/Plugins/InputPluginCommon/Src/ControllerEmu.h b/Source/Plugins/InputPluginCommon/Src/ControllerEmu.h index 13b6b27d6c..eb779f1ae7 100644 --- a/Source/Plugins/InputPluginCommon/Src/ControllerEmu.h +++ b/Source/Plugins/InputPluginCommon/Src/ControllerEmu.h @@ -28,6 +28,7 @@ enum GROUP_TYPE_EXTENSION, GROUP_TYPE_TILT, GROUP_TYPE_CURSOR, + GROUP_TYPE_TRIGGERS, }; const char * const named_directions[] = @@ -55,9 +56,7 @@ public: : control_ref(_ref), name(_name){} public: - - //virtual std::string GetName() const = 0; - + virtual ~Control(); ControllerInterface::ControlReference* const control_ref; const char * const name; @@ -105,7 +104,6 @@ public: void LoadConfig( IniFile::Section& sec, const std::string& defdev = "", const std::string& base = "" ); void SaveConfig( IniFile::Section& sec, const std::string& defdev = "", const std::string& base = "" ); - //const unsigned int type; const char* const name; const unsigned int type; @@ -147,7 +145,7 @@ public: ControlState ang_cos = cos(ang); // the amt a full square stick would have at current angle - ControlState square_full = std::min( 1/abs(ang_sin), 1/abs(ang_cos) ); + ControlState square_full = std::min( ang_sin ? 1/abs(ang_sin) : 2, ang_cos ? 1/abs(ang_cos) : 2 ); // the amt a full stick would have that was ( user setting squareness) at current angle // i think this is more like a pointed circle rather than a rounded square like it should be @@ -217,6 +215,23 @@ public: }; + class Triggers : public ControlGroup + { + public: + + template <typename S> + void GetState( S* analog, const unsigned int range ) + { + const unsigned int trig_count = ((unsigned int) (controls.size())); + const ControlState deadzone = settings[0]->value; + 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 ); + } + + Triggers( const char* const _name ); + + }; + class Force : public ControlGroup { public: @@ -259,7 +274,7 @@ public: ControlState ang_cos = cos(ang); // the amt a full square stick would have at current angle - ControlState square_full = std::min( 1/abs(ang_sin), 1/abs(ang_cos) ); + ControlState square_full = std::min( ang_sin ? 1/abs(ang_sin) : 2, ang_cos ? 1/abs(ang_cos) : 2 ); // the amt a full stick would have that was ( user setting circular ) at current angle // i think this is more like a pointed circle rather than a rounded square like it should be @@ -292,12 +307,6 @@ public: template <typename C> void GetState( C* const x, C* const y, C* const forward, const bool adjusted = false ) { - // this is flawed when GetState() isn't called at regular intervals - //const ControlState zz = controls[4]->control_ref->State(); - //if (z < zz) - // z = std::min( z + 0.01f, zz ); - //else - // z = std::max( z - 0.01f, zz ); const ControlState z = controls[4]->control_ref->State(); // hide @@ -335,7 +344,6 @@ public: } private: - //ControlState z; const SWiimoteInitialize* const wiimote_initialize; }; @@ -347,6 +355,7 @@ public: : ControlGroup( _name, GROUP_TYPE_EXTENSION ) , switch_extension(0) , active_extension(0) {} + ~Extension(); void GetState( u8* const data, const bool focus = true ); @@ -368,8 +377,6 @@ public: std::vector< ControlGroup* > groups; - ControlGroup* options; - ControllerInterface::DeviceQualifier default_device; }; |
