#include "ControllerEmu.h" #include "ControllerEmu/GCPad/GCPad.h" const char modifier[] = "Modifier"; // TODO: make this use iterators ControllerEmu::~ControllerEmu() { for ( unsigned int g = 0; gcontrols.size(); ++i ) devi.UpdateReference( groups[g]->controls[i]->control_ref ); } void ControllerEmu::UpdateDefaultDevice() { std::vector::const_iterator i = groups.begin(), e = groups.end(); for ( ; i!=e; ++i ) { std::vector::const_iterator ci = (*i)->controls.begin(), ce = (*i)->controls.end(); for ( ; ci!=ce; ++ci ) (*ci)->control_ref->device_qualifier = default_device; } } void ControllerEmu::LoadConfig( IniFile::Section& sec ) { const std::string default_dev = sec[ "Device" ]; default_device.FromString( default_dev ); std::vector::const_iterator i = groups.begin(), e = groups.end(); for ( ; i!=e; ++i ) { std::string group( (*i)->name ); group += "/"; // settings std::vector::const_iterator si = (*i)->settings.begin(), se = (*i)->settings.end(); for ( ; si!=se; ++si ) (*si)->value = sec.GetValue(group+(*si)->name, (*si)->default_value*100) / 100; // controls std::vector::const_iterator ci = (*i)->controls.begin(), ce = (*i)->controls.end(); for ( ; ci!=ce; ++ci ) { // control and dev qualifier (*ci)->control_ref->control_qualifier.name = sec[group + (*ci)->name]; (*ci)->control_ref->device_qualifier.FromString( sec.GetValue( group+(*ci)->name+"/Device", default_dev ) ); // range (*ci)->control_ref->range = sec.GetValue( group+(*ci)->name+"/Range", 100.0f ) / 100; // input mode if ( (*ci)->control_ref->is_input ) ((ControllerInterface::InputReference*)((*ci)->control_ref))->mode = sec.GetValue( group+(*ci)->name+"/Mode", 0 ); } } } void ControllerEmu::SaveConfig( IniFile::Section& sec ) { const std::string default_dev = default_device.ToString(); sec[ " Device" ] = default_dev; std::vector::const_iterator i = groups.begin(), e = groups.end(); for ( ; i!=e; ++i ) { std::string group( (*i)->name ); group += "/"; // settings std::vector::const_iterator si = (*i)->settings.begin(), se = (*i)->settings.end(); for ( ; si!=se; ++si ) sec.SetValue( group+(*si)->name, (*si)->value*100, (*si)->default_value*100 ); // controls std::vector::const_iterator ci = (*i)->controls.begin(), ce = (*i)->controls.end(); for ( ; ci!=ce; ++ci ) { // control and dev qualifier sec[group + (*ci)->name] = (*ci)->control_ref->control_qualifier.name; sec.SetValue( group+(*ci)->name+"/Device", (*ci)->control_ref->device_qualifier.ToString(), default_dev ); // range sec.SetValue( group+(*ci)->name+"/Range", (*ci)->control_ref->range*100, 100 ); // input mode if ( (*ci)->control_ref->is_input ) sec.SetValue( group+(*ci)->name+"/Mode", ((ControllerInterface::InputReference*)((*ci)->control_ref))->mode, (unsigned int)0 ); } } } ControllerEmu::AnalogStick::AnalogStick( const char* const _name ) : ControlGroup( _name, GROUP_TYPE_STICK ) { for ( unsigned int i = 0; i < 4; ++i ) controls.push_back( new Input( named_directions[i] ) ); controls.push_back( new Input( modifier ) ); settings.push_back( new Setting("Dead Zone", 0 ) ); settings.push_back( new Setting("Square Stick", 0 ) ); } ControllerEmu::Buttons::Buttons( const char* const _name ) : ControlGroup( _name, GROUP_TYPE_BUTTONS ) { settings.push_back( new Setting("Threshold", 0.5f ) ); } ControllerEmu::MixedTriggers::MixedTriggers( const char* const _name ) : ControlGroup( _name, GROUP_TYPE_MIXED_TRIGGERS ) { settings.push_back( new Setting("Threshold", 0.9f ) ); }