committed by
Narr the Reg
11 changed files with 95 additions and 614 deletions
-
4src/input_common/CMakeLists.txt
-
35src/input_common/drivers/keyboard.cpp
-
29src/input_common/drivers/keyboard.h
-
121src/input_common/keyboard.cpp
-
263src/input_common/main.cpp
-
89src/input_common/main.h
-
62src/yuzu/bootmanager.cpp
-
2src/yuzu/bootmanager.h
-
83src/yuzu/configuration/configure_input_player.cpp
-
3src/yuzu/debugger/controller.cpp
-
18src/yuzu/main.cpp
@ -0,0 +1,35 @@ |
|||||
|
// Copyright 2021 yuzu Emulator Project
|
||||
|
// Licensed under GPLv2 or any later version
|
||||
|
// Refer to the license.txt file included
|
||||
|
|
||||
|
#include "common/param_package.h"
|
||||
|
#include "input_common/drivers/keyboard.h"
|
||||
|
|
||||
|
namespace InputCommon { |
||||
|
|
||||
|
Keyboard::Keyboard(const std::string& input_engine_) : InputEngine(input_engine_) { |
||||
|
PreSetController(identifier); |
||||
|
} |
||||
|
|
||||
|
void Keyboard::PressKey(int key_code) { |
||||
|
SetButton(identifier, key_code, true); |
||||
|
} |
||||
|
|
||||
|
void Keyboard::ReleaseKey(int key_code) { |
||||
|
SetButton(identifier, key_code, false); |
||||
|
} |
||||
|
|
||||
|
void Keyboard::ReleaseAllKeys() { |
||||
|
ResetButtonState(); |
||||
|
} |
||||
|
|
||||
|
std::vector<Common::ParamPackage> Keyboard::GetInputDevices() const { |
||||
|
std::vector<Common::ParamPackage> devices; |
||||
|
devices.emplace_back(Common::ParamPackage{ |
||||
|
{"engine", "keyboard"}, |
||||
|
{"display", "Keyboard Only"}, |
||||
|
}); |
||||
|
return devices; |
||||
|
} |
||||
|
|
||||
|
} // namespace InputCommon
|
||||
@ -1,121 +0,0 @@ |
|||||
// Copyright 2017 Citra Emulator Project
|
|
||||
// Licensed under GPLv2 or any later version
|
|
||||
// Refer to the license.txt file included.
|
|
||||
|
|
||||
#include <atomic>
|
|
||||
#include <list>
|
|
||||
#include <mutex>
|
|
||||
#include <utility>
|
|
||||
#include "input_common/keyboard.h"
|
|
||||
|
|
||||
namespace InputCommon { |
|
||||
|
|
||||
class KeyButton final : public Input::ButtonDevice { |
|
||||
public: |
|
||||
explicit KeyButton(std::shared_ptr<KeyButtonList> key_button_list_, bool toggle_) |
|
||||
: key_button_list(std::move(key_button_list_)), toggle(toggle_) {} |
|
||||
|
|
||||
~KeyButton() override; |
|
||||
|
|
||||
bool GetStatus() const override { |
|
||||
if (toggle) { |
|
||||
return toggled_status.load(std::memory_order_relaxed); |
|
||||
} |
|
||||
return status.load(); |
|
||||
} |
|
||||
|
|
||||
void ToggleButton() { |
|
||||
if (lock) { |
|
||||
return; |
|
||||
} |
|
||||
lock = true; |
|
||||
const bool old_toggle_status = toggled_status.load(); |
|
||||
toggled_status.store(!old_toggle_status); |
|
||||
} |
|
||||
|
|
||||
void UnlockButton() { |
|
||||
lock = false; |
|
||||
} |
|
||||
|
|
||||
friend class KeyButtonList; |
|
||||
|
|
||||
private: |
|
||||
std::shared_ptr<KeyButtonList> key_button_list; |
|
||||
std::atomic<bool> status{false}; |
|
||||
std::atomic<bool> toggled_status{false}; |
|
||||
bool lock{false}; |
|
||||
const bool toggle; |
|
||||
}; |
|
||||
|
|
||||
struct KeyButtonPair { |
|
||||
int key_code; |
|
||||
KeyButton* key_button; |
|
||||
}; |
|
||||
|
|
||||
class KeyButtonList { |
|
||||
public: |
|
||||
void AddKeyButton(int key_code, KeyButton* key_button) { |
|
||||
std::lock_guard guard{mutex}; |
|
||||
list.push_back(KeyButtonPair{key_code, key_button}); |
|
||||
} |
|
||||
|
|
||||
void RemoveKeyButton(const KeyButton* key_button) { |
|
||||
std::lock_guard guard{mutex}; |
|
||||
list.remove_if( |
|
||||
[key_button](const KeyButtonPair& pair) { return pair.key_button == key_button; }); |
|
||||
} |
|
||||
|
|
||||
void ChangeKeyStatus(int key_code, bool pressed) { |
|
||||
std::lock_guard guard{mutex}; |
|
||||
for (const KeyButtonPair& pair : list) { |
|
||||
if (pair.key_code == key_code) { |
|
||||
pair.key_button->status.store(pressed); |
|
||||
if (pressed) { |
|
||||
pair.key_button->ToggleButton(); |
|
||||
} else { |
|
||||
pair.key_button->UnlockButton(); |
|
||||
} |
|
||||
pair.key_button->TriggerOnChange(); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
void ChangeAllKeyStatus(bool pressed) { |
|
||||
std::lock_guard guard{mutex}; |
|
||||
for (const KeyButtonPair& pair : list) { |
|
||||
pair.key_button->status.store(pressed); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
private: |
|
||||
std::mutex mutex; |
|
||||
std::list<KeyButtonPair> list; |
|
||||
}; |
|
||||
|
|
||||
Keyboard::Keyboard() : key_button_list{std::make_shared<KeyButtonList>()} {} |
|
||||
|
|
||||
KeyButton::~KeyButton() { |
|
||||
key_button_list->RemoveKeyButton(this); |
|
||||
} |
|
||||
|
|
||||
std::unique_ptr<Input::ButtonDevice> Keyboard::Create(const Common::ParamPackage& params) { |
|
||||
const int key_code = params.Get("code", 0); |
|
||||
const bool toggle = params.Get("toggle", false); |
|
||||
std::unique_ptr<KeyButton> button = std::make_unique<KeyButton>(key_button_list, toggle); |
|
||||
key_button_list->AddKeyButton(key_code, button.get()); |
|
||||
return button; |
|
||||
} |
|
||||
|
|
||||
void Keyboard::PressKey(int key_code) { |
|
||||
key_button_list->ChangeKeyStatus(key_code, true); |
|
||||
} |
|
||||
|
|
||||
void Keyboard::ReleaseKey(int key_code) { |
|
||||
key_button_list->ChangeKeyStatus(key_code, false); |
|
||||
} |
|
||||
|
|
||||
void Keyboard::ReleaseAllKeys() { |
|
||||
key_button_list->ChangeAllKeyStatus(false); |
|
||||
} |
|
||||
|
|
||||
} // namespace InputCommon
|
|
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue