kraken: Fix errors from rebase and format files

master
german77 2021-10-15 19:07:47 +07:00 committed by Narr the Reg
parent 06a5ef5874
commit e0da5c1bbc
20 changed files with 83 additions and 53 deletions

@ -91,6 +91,7 @@ void EmulatedController::ReloadFromSettings() {
} }
void EmulatedController::ReloadInput() { void EmulatedController::ReloadInput() {
// If you load any device here add the equivalent to the UnloadInput() function
const auto player_index = NpadIdTypeToIndex(npad_id_type); const auto player_index = NpadIdTypeToIndex(npad_id_type);
const auto left_side = button_params[Settings::NativeButton::ZL]; const auto left_side = button_params[Settings::NativeButton::ZL];
const auto right_side = button_params[Settings::NativeButton::ZR]; const auto right_side = button_params[Settings::NativeButton::ZR];
@ -113,7 +114,7 @@ void EmulatedController::ReloadInput() {
battery_devices[0] = Input::CreateDevice<Input::InputDevice>(left_side); battery_devices[0] = Input::CreateDevice<Input::InputDevice>(left_side);
battery_devices[1] = Input::CreateDevice<Input::InputDevice>(right_side); battery_devices[1] = Input::CreateDevice<Input::InputDevice>(right_side);
button_params[Settings::NativeButton::ZL].Set("output",true); button_params[Settings::NativeButton::ZL].Set("output", true);
output_devices[0] = output_devices[0] =
Input::CreateDevice<Input::OutputDevice>(button_params[Settings::NativeButton::ZL]); Input::CreateDevice<Input::OutputDevice>(button_params[Settings::NativeButton::ZL]);
@ -179,6 +180,9 @@ void EmulatedController::UnloadInput() {
for (auto& battery : battery_devices) { for (auto& battery : battery_devices) {
battery.reset(); battery.reset();
} }
for (auto& output : output_devices) {
output.reset();
}
} }
void EmulatedController::EnableConfiguration() { void EmulatedController::EnableConfiguration() {

@ -8,7 +8,6 @@
#include "common/settings.h" #include "common/settings.h"
#include "core/core.h" #include "core/core.h"
#include "core/core_timing.h" #include "core/core_timing.h"
#include "core/frontend/input.h"
#include "core/hardware_properties.h" #include "core/hardware_properties.h"
#include "core/hle/ipc_helpers.h" #include "core/hle/ipc_helpers.h"
#include "core/hle/kernel/k_readable_event.h" #include "core/hle/kernel/k_readable_event.h"

@ -322,7 +322,8 @@ bool GCAdapter::GetGCEndpoint(libusb_device* device) {
return true; return true;
} }
Input::VibrationError GCAdapter::SetRumble(const PadIdentifier& identifier, const Input::VibrationStatus vibration) { Input::VibrationError GCAdapter::SetRumble(const PadIdentifier& identifier,
const Input::VibrationStatus vibration) {
const auto mean_amplitude = (vibration.low_amplitude + vibration.high_amplitude) * 0.5f; const auto mean_amplitude = (vibration.low_amplitude + vibration.high_amplitude) * 0.5f;
const auto processed_amplitude = const auto processed_amplitude =
static_cast<u8>((mean_amplitude + std::pow(mean_amplitude, 0.3f)) * 0.5f * 0x8); static_cast<u8>((mean_amplitude + std::pow(mean_amplitude, 0.3f)) * 0.5f * 0x8);

@ -25,7 +25,7 @@ public:
~GCAdapter(); ~GCAdapter();
Input::VibrationError SetRumble(const PadIdentifier& identifier, Input::VibrationError SetRumble(const PadIdentifier& identifier,
const Input::VibrationStatus vibration) override; const Input::VibrationStatus vibration) override;
/// Used for automapping features /// Used for automapping features
std::vector<Common::ParamPackage> GetInputDevices() const override; std::vector<Common::ParamPackage> GetInputDevices() const override;

@ -59,7 +59,7 @@ public:
u8 GetHatButtonId(const std::string direction_name) const override; u8 GetHatButtonId(const std::string direction_name) const override;
Input::VibrationError SetRumble(const PadIdentifier& identifier, Input::VibrationError SetRumble(const PadIdentifier& identifier,
const Input::VibrationStatus vibration) override; const Input::VibrationStatus vibration) override;
private: private:
void InitJoystick(int joystick_index); void InitJoystick(int joystick_index);

@ -251,8 +251,7 @@ private:
std::chrono::time_point<std::chrono::steady_clock> last_update; std::chrono::time_point<std::chrono::steady_clock> last_update;
}; };
std::unique_ptr<Input::InputDevice> StickFromButton::Create( std::unique_ptr<Input::InputDevice> StickFromButton::Create(const Common::ParamPackage& params) {
const Common::ParamPackage& params) {
const std::string null_engine = Common::ParamPackage{{"engine", "null"}}.Serialize(); const std::string null_engine = Common::ParamPackage{{"engine", "null"}}.Serialize();
auto up = Input::CreateDeviceFromString<Input::InputDevice>(params.Get("up", null_engine)); auto up = Input::CreateDeviceFromString<Input::InputDevice>(params.Get("up", null_engine));
auto down = Input::CreateDeviceFromString<Input::InputDevice>(params.Get("down", null_engine)); auto down = Input::CreateDeviceFromString<Input::InputDevice>(params.Get("down", null_engine));

@ -25,8 +25,7 @@ public:
* - "modifier": a serialized ParamPackage for creating a button device as the modifier * - "modifier": a serialized ParamPackage for creating a button device as the modifier
* - "modifier_scale": a float for the multiplier the modifier gives to the position * - "modifier_scale": a float for the multiplier the modifier gives to the position
*/ */
std::unique_ptr<Input::InputDevice> Create( std::unique_ptr<Input::InputDevice> Create(const Common::ParamPackage& params) override;
const Common::ParamPackage& params) override;
}; };
} // namespace InputCommon } // namespace InputCommon

@ -57,9 +57,7 @@ private:
const Input::AnalogProperties properties{0.0f, 1.0f, 0.5f, 0.0f, false}; const Input::AnalogProperties properties{0.0f, 1.0f, 0.5f, 0.0f, false};
}; };
std::unique_ptr<Input::InputDevice> TouchFromButton::Create(const Common::ParamPackage& params) {
std::unique_ptr<Input::InputDevice> TouchFromButton::Create(
const Common::ParamPackage& params) {
const std::string null_engine = Common::ParamPackage{{"engine", "null"}}.Serialize(); const std::string null_engine = Common::ParamPackage{{"engine", "null"}}.Serialize();
auto button = auto button =
Input::CreateDeviceFromString<Input::InputDevice>(params.Get("button", null_engine)); Input::CreateDeviceFromString<Input::InputDevice>(params.Get("button", null_engine));

@ -121,14 +121,16 @@ public:
} }
// Sets rumble to a controller // Sets rumble to a controller
virtual Input::VibrationError SetRumble([[maybe_unused]] const PadIdentifier& identifier, virtual Input::VibrationError SetRumble(
[[maybe_unused]] const Input::VibrationStatus vibration) { [[maybe_unused]] const PadIdentifier& identifier,
[[maybe_unused]] const Input::VibrationStatus vibration) {
return Input::VibrationError::NotSupported; return Input::VibrationError::NotSupported;
} }
// Sets polling mode to a controller // Sets polling mode to a controller
virtual Input::PollingError SetPollingMode([[maybe_unused]] const PadIdentifier& identifier, virtual Input::PollingError SetPollingMode(
[[maybe_unused]] const Input::PollingMode vibration) { [[maybe_unused]] const PadIdentifier& identifier,
[[maybe_unused]] const Input::PollingMode vibration) {
return Input::PollingError::NotSupported; return Input::PollingError::NotSupported;
} }

@ -597,7 +597,7 @@ public:
explicit OutputFromIdentifier(PadIdentifier identifier_, InputEngine* input_engine_) explicit OutputFromIdentifier(PadIdentifier identifier_, InputEngine* input_engine_)
: identifier(identifier_), input_engine(input_engine_) {} : identifier(identifier_), input_engine(input_engine_) {}
virtual void SetLED( Input::LedStatus led_status) { virtual void SetLED(Input::LedStatus led_status) {
input_engine->SetLeds(identifier, led_status); input_engine->SetLeds(identifier, led_status);
} }
@ -847,8 +847,7 @@ std::unique_ptr<Input::InputDevice> InputFactory::CreateMotionDevice(Common::Par
InputFactory::InputFactory(std::shared_ptr<InputEngine> input_engine_) InputFactory::InputFactory(std::shared_ptr<InputEngine> input_engine_)
: input_engine(std::move(input_engine_)) {} : input_engine(std::move(input_engine_)) {}
std::unique_ptr<Input::InputDevice> InputFactory::Create( std::unique_ptr<Input::InputDevice> InputFactory::Create(const Common::ParamPackage& params) {
const Common::ParamPackage& params) {
if (params.Has("button") && params.Has("axis")) { if (params.Has("button") && params.Has("axis")) {
return CreateTriggerDevice(params); return CreateTriggerDevice(params);
} }
@ -883,8 +882,7 @@ std::unique_ptr<Input::InputDevice> InputFactory::Create(
OutputFactory::OutputFactory(std::shared_ptr<InputEngine> input_engine_) OutputFactory::OutputFactory(std::shared_ptr<InputEngine> input_engine_)
: input_engine(std::move(input_engine_)) {} : input_engine(std::move(input_engine_)) {}
std::unique_ptr<Input::OutputDevice> OutputFactory::Create( std::unique_ptr<Input::OutputDevice> OutputFactory::Create(const Common::ParamPackage& params) {
const Common::ParamPackage& params) {
const PadIdentifier identifier = { const PadIdentifier identifier = {
.guid = Common::UUID{params.Get("guid", "")}, .guid = Common::UUID{params.Get("guid", "")},
.port = static_cast<std::size_t>(params.Get("port", 0)), .port = static_cast<std::size_t>(params.Get("port", 0)),

@ -29,8 +29,7 @@ public:
* @param - "pad": slot of the connected controller * @param - "pad": slot of the connected controller
* @return an unique ouput device with the parameters specified * @return an unique ouput device with the parameters specified
*/ */
std::unique_ptr<Input::OutputDevice> Create( std::unique_ptr<Input::OutputDevice> Create(const Common::ParamPackage& params) override;
const Common::ParamPackage& params) override;
private: private:
std::shared_ptr<InputEngine> input_engine; std::shared_ptr<InputEngine> input_engine;
@ -41,8 +40,8 @@ public:
explicit InputFactory(std::shared_ptr<InputEngine> input_engine_); explicit InputFactory(std::shared_ptr<InputEngine> input_engine_);
/** /**
* Creates an input device from the parameters given. Identifies the type of input to be returned * Creates an input device from the parameters given. Identifies the type of input to be
* if it contains the following parameters: * returned if it contains the following parameters:
* - button: Contains "button" or "code" * - button: Contains "button" or "code"
* - hat_button: Contains "hat" * - hat_button: Contains "hat"
* - analog: Contains "axis" * - analog: Contains "axis"
@ -65,8 +64,7 @@ public:
* @param - "battery": Only used as a placeholder to set the input type * @param - "battery": Only used as a placeholder to set the input type
* @return an unique input device with the parameters specified * @return an unique input device with the parameters specified
*/ */
std::unique_ptr<Input::InputDevice> Create( std::unique_ptr<Input::InputDevice> Create(const Common::ParamPackage& params) override;
const Common::ParamPackage& params) override;
private: private:
/** /**

@ -48,8 +48,10 @@ struct InputSubsystem::Impl {
gcadapter->SetMappingCallback(mapping_callback); gcadapter->SetMappingCallback(mapping_callback);
gcadapter_input_factory = std::make_shared<InputFactory>(gcadapter); gcadapter_input_factory = std::make_shared<InputFactory>(gcadapter);
gcadapter_output_factory = std::make_shared<OutputFactory>(gcadapter); gcadapter_output_factory = std::make_shared<OutputFactory>(gcadapter);
Input::RegisterFactory<Input::InputDevice>(gcadapter->GetEngineName(), gcadapter_input_factory); Input::RegisterFactory<Input::InputDevice>(gcadapter->GetEngineName(),
Input::RegisterFactory<Input::OutputDevice>(gcadapter->GetEngineName(), gcadapter_output_factory); gcadapter_input_factory);
Input::RegisterFactory<Input::OutputDevice>(gcadapter->GetEngineName(),
gcadapter_output_factory);
udp_client = std::make_shared<CemuhookUDP::UDPClient>("cemuhookudp"); udp_client = std::make_shared<CemuhookUDP::UDPClient>("cemuhookudp");
udp_client->SetMappingCallback(mapping_callback); udp_client->SetMappingCallback(mapping_callback);

@ -106,7 +106,6 @@ private:
Core::Frontend::ControllerParameters parameters; Core::Frontend::ControllerParameters parameters;
InputCommon::InputSubsystem* input_subsystem; InputCommon::InputSubsystem* input_subsystem;
Core::System& system;
std::unique_ptr<InputProfiles> input_profiles; std::unique_ptr<InputProfiles> input_profiles;

@ -74,7 +74,7 @@ ConfigureDialog::ConfigureDialog(QWidget* parent, HotkeyRegistry& registry,
hotkeys_tab->Populate(registry); hotkeys_tab->Populate(registry);
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
input_tab->Initialize(input_subsystem); input_tab->Initialize(input_subsystem, system_);
general_tab->SetResetCallback([&] { this->close(); }); general_tab->SetResetCallback([&] { this->close(); });

@ -146,10 +146,11 @@ void ConfigureInput::Initialize(InputCommon::InputSubsystem* input_subsystem, Co
advanced = new ConfigureInputAdvanced(this); advanced = new ConfigureInputAdvanced(this);
ui->tabAdvanced->setLayout(new QHBoxLayout(ui->tabAdvanced)); ui->tabAdvanced->setLayout(new QHBoxLayout(ui->tabAdvanced));
ui->tabAdvanced->layout()->addWidget(advanced); ui->tabAdvanced->layout()->addWidget(advanced);
connect(advanced, &ConfigureInputAdvanced::CallDebugControllerDialog, [this, input_subsystem] { connect(advanced, &ConfigureInputAdvanced::CallDebugControllerDialog,
CallConfigureDialog<ConfigureDebugController>(*this, input_subsystem, profiles.get(), [this, input_subsystem, &system] {
system); CallConfigureDialog<ConfigureDebugController>(*this, input_subsystem,
}); profiles.get(), system);
});
connect(advanced, &ConfigureInputAdvanced::CallMouseConfigDialog, [this, input_subsystem] { connect(advanced, &ConfigureInputAdvanced::CallMouseConfigDialog, [this, input_subsystem] {
CallConfigureDialog<ConfigureMouseAdvanced>(*this, input_subsystem); CallConfigureDialog<ConfigureMouseAdvanced>(*this, input_subsystem);
}); });

@ -19,15 +19,11 @@ PlayerControlPreview::PlayerControlPreview(QWidget* parent) : QFrame(parent) {
} }
PlayerControlPreview::~PlayerControlPreview() { PlayerControlPreview::~PlayerControlPreview() {
if (is_controller_set) { UnloadController();
controller->DeleteCallback(callback_key);
}
}; };
void PlayerControlPreview::SetController(Core::HID::EmulatedController* controller_) { void PlayerControlPreview::SetController(Core::HID::EmulatedController* controller_) {
if (is_controller_set) { UnloadController();
controller->DeleteCallback(callback_key);
}
is_controller_set = true; is_controller_set = true;
controller = controller_; controller = controller_;
Core::HID::ControllerUpdateCallback engine_callback{ Core::HID::ControllerUpdateCallback engine_callback{
@ -36,14 +32,21 @@ void PlayerControlPreview::SetController(Core::HID::EmulatedController* controll
ControllerUpdate(Core::HID::ControllerTriggerType::All); ControllerUpdate(Core::HID::ControllerTriggerType::All);
} }
void PlayerControlPreview::BeginMappingButton(std::size_t index) { void PlayerControlPreview::UnloadController() {
button_mapping_index = index; if (is_controller_set) {
controller->DeleteCallback(callback_key);
is_controller_set = false;
}
}
void PlayerControlPreview::BeginMappingButton(std::size_t button_id) {
button_mapping_index = button_id;
mapping_active = true; mapping_active = true;
} }
void PlayerControlPreview::BeginMappingAnalog(std::size_t index) { void PlayerControlPreview::BeginMappingAnalog(std::size_t stick_id) {
button_mapping_index = Settings::NativeButton::LStick + index; button_mapping_index = Settings::NativeButton::LStick + stick_id;
analog_mapping_index = index; analog_mapping_index = stick_id;
mapping_active = true; mapping_active = true;
} }

@ -25,11 +25,25 @@ public:
explicit PlayerControlPreview(QWidget* parent); explicit PlayerControlPreview(QWidget* parent);
~PlayerControlPreview() override; ~PlayerControlPreview() override;
// Sets the emulated controller to be displayed
void SetController(Core::HID::EmulatedController* controller); void SetController(Core::HID::EmulatedController* controller);
// Disables events from the emulated controller
void UnloadController();
// Starts blinking animation at the button specified
void BeginMappingButton(std::size_t button_id); void BeginMappingButton(std::size_t button_id);
void BeginMappingAnalog(std::size_t button_id);
// Starts moving animation at the stick specified
void BeginMappingAnalog(std::size_t stick_id);
// Stops any ongoing animation
void EndMapping(); void EndMapping();
// Handles emulated controller events
void ControllerUpdate(Core::HID::ControllerTriggerType type); void ControllerUpdate(Core::HID::ControllerTriggerType type);
// Updates input on sheduled interval
void UpdateInput(); void UpdateInput();
protected: protected:

@ -10,7 +10,8 @@
#include "yuzu/configuration/configure_input_player_widget.h" #include "yuzu/configuration/configure_input_player_widget.h"
#include "yuzu/debugger/controller.h" #include "yuzu/debugger/controller.h"
ControllerDialog::ControllerDialog(QWidget* parent) : QWidget(parent, Qt::Dialog) { ControllerDialog::ControllerDialog(Core::System& system, QWidget* parent)
: QWidget(parent, Qt::Dialog) {
setObjectName(QStringLiteral("Controller")); setObjectName(QStringLiteral("Controller"));
setWindowTitle(tr("Controller P1")); setWindowTitle(tr("Controller P1"));
resize(500, 350); resize(500, 350);
@ -20,7 +21,7 @@ ControllerDialog::ControllerDialog(QWidget* parent) : QWidget(parent, Qt::Dialog
Qt::WindowMaximizeButtonHint); Qt::WindowMaximizeButtonHint);
widget = new PlayerControlPreview(this); widget = new PlayerControlPreview(this);
widget->SetController(Core::System::GetInstance().HIDCore().GetEmulatedController( widget->SetController(system.HIDCore().GetEmulatedController(
Core::HID::NpadIdType::Player1)); Core::HID::NpadIdType::Player1));
QLayout* layout = new QVBoxLayout(this); QLayout* layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0); layout->setContentsMargins(0, 0, 0, 0);
@ -45,6 +46,10 @@ QAction* ControllerDialog::toggleViewAction() {
return toggle_view_action; return toggle_view_action;
} }
void ControllerDialog::UnloadController() {
widget->UnloadController();
}
void ControllerDialog::showEvent(QShowEvent* ev) { void ControllerDialog::showEvent(QShowEvent* ev) {
if (toggle_view_action) { if (toggle_view_action) {
toggle_view_action->setChecked(isVisible()); toggle_view_action->setChecked(isVisible());

@ -11,6 +11,10 @@ class QHideEvent;
class QShowEvent; class QShowEvent;
class PlayerControlPreview; class PlayerControlPreview;
namespace Core {
class System;
}
namespace InputCommon { namespace InputCommon {
class InputSubsystem; class InputSubsystem;
} }
@ -19,11 +23,14 @@ class ControllerDialog : public QWidget {
Q_OBJECT Q_OBJECT
public: public:
explicit ControllerDialog(QWidget* parent = nullptr); explicit ControllerDialog(Core::System& system, QWidget* parent = nullptr);
/// Returns a QAction that can be used to toggle visibility of this dialog. /// Returns a QAction that can be used to toggle visibility of this dialog.
QAction* toggleViewAction(); QAction* toggleViewAction();
// Disables events from the emulated controller
void UnloadController();
protected: protected:
void showEvent(QShowEvent* ev) override; void showEvent(QShowEvent* ev) override;
void hideEvent(QHideEvent* ev) override; void hideEvent(QHideEvent* ev) override;

@ -228,7 +228,7 @@ GMainWindow::GMainWindow()
ConnectMenuEvents(); ConnectMenuEvents();
ConnectWidgetEvents(); ConnectWidgetEvents();
Core::System::GetInstance().HIDCore().ReloadInputDevices(); system->HIDCore().ReloadInputDevices();
const auto branch_name = std::string(Common::g_scm_branch); const auto branch_name = std::string(Common::g_scm_branch);
const auto description = std::string(Common::g_scm_desc); const auto description = std::string(Common::g_scm_desc);
@ -924,7 +924,7 @@ void GMainWindow::InitializeDebugWidgets() {
waitTreeWidget->hide(); waitTreeWidget->hide();
debug_menu->addAction(waitTreeWidget->toggleViewAction()); debug_menu->addAction(waitTreeWidget->toggleViewAction());
controller_dialog = new ControllerDialog(this); controller_dialog = new ControllerDialog(*system, this);
controller_dialog->hide(); controller_dialog->hide();
debug_menu->addAction(controller_dialog->toggleViewAction()); debug_menu->addAction(controller_dialog->toggleViewAction());
@ -3372,7 +3372,8 @@ void GMainWindow::closeEvent(QCloseEvent* event) {
UpdateUISettings(); UpdateUISettings();
game_list->SaveInterfaceLayout(); game_list->SaveInterfaceLayout();
hotkey_registry.SaveHotkeys(); hotkey_registry.SaveHotkeys();
Core::System::GetInstance().HIDCore().UnloadInputDevices(); controller_dialog->UnloadController();
system->HIDCore().UnloadInputDevices();
// Shutdown session if the emu thread is active... // Shutdown session if the emu thread is active...
if (emu_thread != nullptr) { if (emu_thread != nullptr) {