mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 22:29:39 -06:00
Introduce the usage of unique_ptr into the InputCommon ControlEmu.h class. Allows for the automatic handling of resource deallocation.
This commit is contained in:
@ -8,55 +8,30 @@
|
||||
#include <X11/Xlib.h>
|
||||
#endif
|
||||
|
||||
ControllerEmu::~ControllerEmu()
|
||||
{
|
||||
for (ControlGroup* cg : groups)
|
||||
delete cg;
|
||||
}
|
||||
|
||||
ControllerEmu::ControlGroup::~ControlGroup()
|
||||
{
|
||||
for (Control* c : controls)
|
||||
delete c;
|
||||
|
||||
for (Setting* s : settings)
|
||||
delete s;
|
||||
}
|
||||
|
||||
ControllerEmu::Extension::~Extension()
|
||||
{
|
||||
for (ControllerEmu* ai : attachments)
|
||||
delete ai;
|
||||
}
|
||||
ControllerEmu::ControlGroup::Control::~Control()
|
||||
{
|
||||
delete control_ref;
|
||||
}
|
||||
|
||||
void ControllerEmu::UpdateReferences(ControllerInterface& devi)
|
||||
{
|
||||
for (ControlGroup* cg : groups)
|
||||
for (auto& ctrlGroup : groups)
|
||||
{
|
||||
for (ControlGroup::Control* control : cg->controls)
|
||||
devi.UpdateReference(control->control_ref, default_device);
|
||||
for (auto& control : ctrlGroup->controls)
|
||||
devi.UpdateReference(control->control_ref.get(), default_device);
|
||||
|
||||
// extension
|
||||
if (GROUP_TYPE_EXTENSION == cg->type)
|
||||
if (ctrlGroup->type == GROUP_TYPE_EXTENSION)
|
||||
{
|
||||
for (ControllerEmu* ai : ((Extension*)cg)->attachments)
|
||||
ai->UpdateReferences(devi);
|
||||
for (auto& attachment : ((Extension*)ctrlGroup.get())->attachments)
|
||||
attachment->UpdateReferences(devi);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ControllerEmu::UpdateDefaultDevice()
|
||||
{
|
||||
for (ControlGroup* cg : groups)
|
||||
for (auto& ctrlGroup : groups)
|
||||
{
|
||||
// extension
|
||||
if (GROUP_TYPE_EXTENSION == cg->type)
|
||||
if (ctrlGroup->type == GROUP_TYPE_EXTENSION)
|
||||
{
|
||||
for (ControllerEmu* ai : ((Extension*)cg)->attachments)
|
||||
for (auto& ai : ((Extension*)ctrlGroup.get())->attachments)
|
||||
{
|
||||
ai->default_device = default_device;
|
||||
ai->UpdateDefaultDevice();
|
||||
@ -70,13 +45,13 @@ void ControllerEmu::ControlGroup::LoadConfig(IniFile::Section *sec, const std::s
|
||||
std::string group(base + name); group += "/";
|
||||
|
||||
// settings
|
||||
for (Setting* s : settings)
|
||||
for (auto& s : settings)
|
||||
{
|
||||
sec->Get((group + s->name).c_str(), &s->value, s->default_value * 100);
|
||||
s->value /= 100;
|
||||
}
|
||||
|
||||
for (Control* c : controls)
|
||||
for (auto& c : controls)
|
||||
{
|
||||
// control expression
|
||||
sec->Get((group + c->name).c_str(), &c->control_ref->expression, "");
|
||||
@ -88,7 +63,7 @@ void ControllerEmu::ControlGroup::LoadConfig(IniFile::Section *sec, const std::s
|
||||
}
|
||||
|
||||
// extensions
|
||||
if (GROUP_TYPE_EXTENSION == type)
|
||||
if (type == GROUP_TYPE_EXTENSION)
|
||||
{
|
||||
Extension* const ext = ((Extension*)this);
|
||||
|
||||
@ -97,7 +72,7 @@ void ControllerEmu::ControlGroup::LoadConfig(IniFile::Section *sec, const std::s
|
||||
std::string extname;
|
||||
sec->Get((base + name).c_str(), &extname, "");
|
||||
|
||||
for (ControllerEmu* ai : ext->attachments)
|
||||
for (auto& ai : ext->attachments)
|
||||
{
|
||||
ai->default_device.FromString(defdev);
|
||||
ai->LoadConfig(sec, base + ai->GetName() + "/");
|
||||
@ -119,7 +94,7 @@ void ControllerEmu::LoadConfig(IniFile::Section *sec, const std::string& base)
|
||||
default_device.FromString(defdev);
|
||||
}
|
||||
|
||||
for (ControlGroup* cg : groups)
|
||||
for (auto& cg : groups)
|
||||
cg->LoadConfig(sec, defdev, base);
|
||||
}
|
||||
|
||||
@ -127,10 +102,10 @@ void ControllerEmu::ControlGroup::SaveConfig(IniFile::Section *sec, const std::s
|
||||
{
|
||||
std::string group(base + name); group += "/";
|
||||
|
||||
for (Setting* s : settings)
|
||||
for (auto& s : settings)
|
||||
sec->Set((group + s->name).c_str(), s->value*100.0f, s->default_value*100.0f);
|
||||
|
||||
for (Control* c : controls)
|
||||
for (auto& c : controls)
|
||||
{
|
||||
// control expression
|
||||
sec->Set((group + c->name).c_str(), c->control_ref->expression, "");
|
||||
@ -140,12 +115,12 @@ void ControllerEmu::ControlGroup::SaveConfig(IniFile::Section *sec, const std::s
|
||||
}
|
||||
|
||||
// extensions
|
||||
if (GROUP_TYPE_EXTENSION == type)
|
||||
if (type == GROUP_TYPE_EXTENSION)
|
||||
{
|
||||
Extension* const ext = ((Extension*)this);
|
||||
sec->Set((base + name).c_str(), ext->attachments[ext->switch_extension]->GetName(), "None");
|
||||
|
||||
for (ControllerEmu* ai : ext->attachments)
|
||||
for (auto& ai : ext->attachments)
|
||||
ai->SaveConfig(sec, base + ai->GetName() + "/");
|
||||
}
|
||||
}
|
||||
@ -156,58 +131,58 @@ void ControllerEmu::SaveConfig(IniFile::Section *sec, const std::string& base)
|
||||
if (base.empty())
|
||||
sec->Set((/*std::string(" ") +*/ base + "Device").c_str(), defdev, "");
|
||||
|
||||
for (ControlGroup* cg : groups)
|
||||
cg->SaveConfig(sec, defdev, base);
|
||||
for (auto& ctrlGroup : groups)
|
||||
ctrlGroup->SaveConfig(sec, defdev, base);
|
||||
}
|
||||
|
||||
ControllerEmu::AnalogStick::AnalogStick(const char* const _name) : ControlGroup(_name, GROUP_TYPE_STICK)
|
||||
{
|
||||
for (auto& named_direction : named_directions)
|
||||
controls.push_back(new Input(named_direction));
|
||||
controls.emplace_back(new Input(named_direction));
|
||||
|
||||
controls.push_back(new Input(_trans("Modifier")));
|
||||
controls.emplace_back(new Input(_trans("Modifier")));
|
||||
|
||||
settings.push_back(new Setting(_trans("Radius"), 0.7f, 0, 100));
|
||||
settings.push_back(new Setting(_trans("Dead Zone"), 0, 0, 50));
|
||||
settings.push_back(new Setting(_trans("Square Stick"), 0));
|
||||
settings.emplace_back(new Setting(_trans("Radius"), 0.7f, 0, 100));
|
||||
settings.emplace_back(new Setting(_trans("Dead Zone"), 0, 0, 50));
|
||||
settings.emplace_back(new Setting(_trans("Square Stick"), 0));
|
||||
|
||||
}
|
||||
|
||||
ControllerEmu::Buttons::Buttons(const char* const _name) : ControlGroup(_name, GROUP_TYPE_BUTTONS)
|
||||
{
|
||||
settings.push_back(new Setting(_trans("Threshold"), 0.5f));
|
||||
settings.emplace_back(new Setting(_trans("Threshold"), 0.5f));
|
||||
}
|
||||
|
||||
ControllerEmu::MixedTriggers::MixedTriggers(const char* const _name) : ControlGroup(_name, GROUP_TYPE_MIXED_TRIGGERS)
|
||||
{
|
||||
settings.push_back(new Setting(_trans("Threshold"), 0.9f));
|
||||
settings.emplace_back(new Setting(_trans("Threshold"), 0.9f));
|
||||
}
|
||||
|
||||
ControllerEmu::Triggers::Triggers(const char* const _name) : ControlGroup(_name, GROUP_TYPE_TRIGGERS)
|
||||
{
|
||||
settings.push_back(new Setting(_trans("Dead Zone"), 0, 0, 50));
|
||||
settings.emplace_back(new Setting(_trans("Dead Zone"), 0, 0, 50));
|
||||
}
|
||||
|
||||
ControllerEmu::Slider::Slider(const char* const _name) : ControlGroup(_name, GROUP_TYPE_SLIDER)
|
||||
{
|
||||
controls.push_back(new Input("Left"));
|
||||
controls.push_back(new Input("Right"));
|
||||
controls.emplace_back(new Input("Left"));
|
||||
controls.emplace_back(new Input("Right"));
|
||||
|
||||
settings.push_back(new Setting(_trans("Dead Zone"), 0, 0, 50));
|
||||
settings.emplace_back(new Setting(_trans("Dead Zone"), 0, 0, 50));
|
||||
}
|
||||
|
||||
ControllerEmu::Force::Force(const char* const _name) : ControlGroup(_name, GROUP_TYPE_FORCE)
|
||||
{
|
||||
memset(m_swing, 0, sizeof(m_swing));
|
||||
|
||||
controls.push_back(new Input(_trans("Up")));
|
||||
controls.push_back(new Input(_trans("Down")));
|
||||
controls.push_back(new Input(_trans("Left")));
|
||||
controls.push_back(new Input(_trans("Right")));
|
||||
controls.push_back(new Input(_trans("Forward")));
|
||||
controls.push_back(new Input(_trans("Backward")));
|
||||
controls.emplace_back(new Input(_trans("Up")));
|
||||
controls.emplace_back(new Input(_trans("Down")));
|
||||
controls.emplace_back(new Input(_trans("Left")));
|
||||
controls.emplace_back(new Input(_trans("Right")));
|
||||
controls.emplace_back(new Input(_trans("Forward")));
|
||||
controls.emplace_back(new Input(_trans("Backward")));
|
||||
|
||||
settings.push_back(new Setting(_trans("Dead Zone"), 0, 0, 50));
|
||||
settings.emplace_back(new Setting(_trans("Dead Zone"), 0, 0, 50));
|
||||
}
|
||||
|
||||
ControllerEmu::Tilt::Tilt(const char* const _name)
|
||||
@ -215,16 +190,16 @@ ControllerEmu::Tilt::Tilt(const char* const _name)
|
||||
{
|
||||
memset(m_tilt, 0, sizeof(m_tilt));
|
||||
|
||||
controls.push_back(new Input("Forward"));
|
||||
controls.push_back(new Input("Backward"));
|
||||
controls.push_back(new Input("Left"));
|
||||
controls.push_back(new Input("Right"));
|
||||
controls.emplace_back(new Input("Forward"));
|
||||
controls.emplace_back(new Input("Backward"));
|
||||
controls.emplace_back(new Input("Left"));
|
||||
controls.emplace_back(new Input("Right"));
|
||||
|
||||
controls.push_back(new Input(_trans("Modifier")));
|
||||
controls.emplace_back(new Input(_trans("Modifier")));
|
||||
|
||||
settings.push_back(new Setting(_trans("Dead Zone"), 0, 0, 50));
|
||||
settings.push_back(new Setting(_trans("Circle Stick"), 0));
|
||||
settings.push_back(new Setting(_trans("Angle"), 0.9f, 0, 180));
|
||||
settings.emplace_back(new Setting(_trans("Dead Zone"), 0, 0, 50));
|
||||
settings.emplace_back(new Setting(_trans("Circle Stick"), 0));
|
||||
settings.emplace_back(new Setting(_trans("Angle"), 0.9f, 0, 180));
|
||||
}
|
||||
|
||||
ControllerEmu::Cursor::Cursor(const char* const _name)
|
||||
@ -232,14 +207,14 @@ ControllerEmu::Cursor::Cursor(const char* const _name)
|
||||
, m_z(0)
|
||||
{
|
||||
for (auto& named_direction : named_directions)
|
||||
controls.push_back(new Input(named_direction));
|
||||
controls.push_back(new Input("Forward"));
|
||||
controls.push_back(new Input("Backward"));
|
||||
controls.push_back(new Input(_trans("Hide")));
|
||||
controls.emplace_back(new Input(named_direction));
|
||||
controls.emplace_back(new Input("Forward"));
|
||||
controls.emplace_back(new Input("Backward"));
|
||||
controls.emplace_back(new Input(_trans("Hide")));
|
||||
|
||||
settings.push_back(new Setting(_trans("Center"), 0.5f));
|
||||
settings.push_back(new Setting(_trans("Width"), 0.5f));
|
||||
settings.push_back(new Setting(_trans("Height"), 0.5f));
|
||||
settings.emplace_back(new Setting(_trans("Center"), 0.5f));
|
||||
settings.emplace_back(new Setting(_trans("Width"), 0.5f));
|
||||
settings.emplace_back(new Setting(_trans("Height"), 0.5f));
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user