Removing use of Emulator from hid/.

This commit is contained in:
Ben Vanik 2015-11-07 11:09:47 -08:00
parent e16fa28822
commit 2fdb00b4ed
5 changed files with 34 additions and 45 deletions

View File

@ -127,7 +127,7 @@ X_STATUS Emulator::Setup(ui::Window* display_window) {
}); });
// Initialize the HID. // Initialize the HID.
input_system_ = xe::hid::InputSystem::Create(this); input_system_ = xe::hid::InputSystem::Create(display_window_);
if (!input_system_) { if (!input_system_) {
return X_STATUS_NOT_IMPLEMENTED; return X_STATUS_NOT_IMPLEMENTED;
} }

View File

@ -9,8 +9,6 @@
#include "xenia/hid/input_system.h" #include "xenia/hid/input_system.h"
#include "xenia/cpu/processor.h"
#include "xenia/emulator.h"
#include "xenia/hid/hid_flags.h" #include "xenia/hid/hid_flags.h"
#include "xenia/hid/input_driver.h" #include "xenia/hid/input_driver.h"
#include "xenia/profiling.h" #include "xenia/profiling.h"
@ -19,13 +17,13 @@
#if XE_PLATFORM_WIN32 #if XE_PLATFORM_WIN32
#include "xenia/hid/winkey/winkey_hid.h" #include "xenia/hid/winkey/winkey_hid.h"
#include "xenia/hid/xinput/xinput_hid.h" #include "xenia/hid/xinput/xinput_hid.h"
#endif // WIN32 #endif // XE_PLATFORM_WIN32
namespace xe { namespace xe {
namespace hid { namespace hid {
std::unique_ptr<InputSystem> InputSystem::Create(Emulator* emulator) { std::unique_ptr<InputSystem> InputSystem::Create(xe::ui::Window* window) {
auto input_system = std::make_unique<InputSystem>(emulator); std::unique_ptr<InputSystem> input_system(new InputSystem(window));
if (FLAGS_hid.compare("nop") == 0) { if (FLAGS_hid.compare("nop") == 0) {
input_system->AddDriver(xe::hid::nop::Create(input_system.get())); input_system->AddDriver(xe::hid::nop::Create(input_system.get()));
@ -63,16 +61,11 @@ std::unique_ptr<InputSystem> InputSystem::Create(Emulator* emulator) {
return input_system; return input_system;
} }
InputSystem::InputSystem(Emulator* emulator) InputSystem::InputSystem(xe::ui::Window* window) : window_(window) {}
: emulator_(emulator), memory_(emulator->memory()) {}
InputSystem::~InputSystem() = default; InputSystem::~InputSystem() = default;
X_STATUS InputSystem::Setup() { X_STATUS InputSystem::Setup() { return X_STATUS_SUCCESS; }
processor_ = emulator_->processor();
return X_STATUS_SUCCESS;
}
void InputSystem::AddDriver(std::unique_ptr<InputDriver> driver) { void InputSystem::AddDriver(std::unique_ptr<InputDriver> driver) {
drivers_.push_back(std::move(driver)); drivers_.push_back(std::move(driver));

View File

@ -13,13 +13,13 @@
#include <memory> #include <memory>
#include <vector> #include <vector>
#include "xenia/cpu/processor.h"
#include "xenia/hid/input.h" #include "xenia/hid/input.h"
#include "xenia/memory.h"
#include "xenia/xbox.h" #include "xenia/xbox.h"
namespace xe { namespace xe {
class Emulator; namespace ui {
class Window;
} // namespace ui
} // namespace xe } // namespace xe
namespace xe { namespace xe {
@ -29,14 +29,11 @@ class InputDriver;
class InputSystem { class InputSystem {
public: public:
explicit InputSystem(Emulator* emulator);
~InputSystem(); ~InputSystem();
static std::unique_ptr<InputSystem> Create(Emulator* emulator); static std::unique_ptr<InputSystem> Create(xe::ui::Window* window);
Emulator* emulator() const { return emulator_; } xe::ui::Window* window() const { return window_; }
Memory* memory() const { return memory_; }
cpu::Processor* processor() const { return processor_; }
X_STATUS Setup(); X_STATUS Setup();
@ -50,9 +47,9 @@ class InputSystem {
X_INPUT_KEYSTROKE* out_keystroke); X_INPUT_KEYSTROKE* out_keystroke);
private: private:
Emulator* emulator_ = nullptr; explicit InputSystem(xe::ui::Window* window);
Memory* memory_ = nullptr;
cpu::Processor* processor_ = nullptr; xe::ui::Window* window_ = nullptr;
std::vector<std::unique_ptr<InputDriver>> drivers_; std::vector<std::unique_ptr<InputDriver>> drivers_;
}; };

View File

@ -9,6 +9,7 @@ project("xenia-hid-winkey")
links({ links({
"xenia-base", "xenia-base",
"xenia-hid", "xenia-hid",
"xenia-ui",
}) })
defines({ defines({
}) })

View File

@ -22,28 +22,26 @@ namespace winkey {
WinKeyInputDriver::WinKeyInputDriver(InputSystem* input_system) WinKeyInputDriver::WinKeyInputDriver(InputSystem* input_system)
: InputDriver(input_system), packet_number_(1) { : InputDriver(input_system), packet_number_(1) {
// Register a key listener. // Register a key listener.
input_system_->emulator()->display_window()->on_key_down.AddListener( input_system_->window()->on_key_down.AddListener([this](ui::KeyEvent* evt) {
[this](ui::KeyEvent* evt) { auto global_lock = global_critical_region_.Acquire();
auto global_lock = global_critical_region_.Acquire();
KeyEvent key; KeyEvent key;
key.vkey = evt->key_code(); key.vkey = evt->key_code();
key.transition = true; key.transition = true;
key.prev_state = evt->prev_state(); key.prev_state = evt->prev_state();
key.repeat_count = evt->repeat_count(); key.repeat_count = evt->repeat_count();
key_events_.push(key); key_events_.push(key);
}); });
input_system_->emulator()->display_window()->on_key_up.AddListener( input_system_->window()->on_key_up.AddListener([this](ui::KeyEvent* evt) {
[this](ui::KeyEvent* evt) { auto global_lock = global_critical_region_.Acquire();
auto global_lock = global_critical_region_.Acquire();
KeyEvent key; KeyEvent key;
key.vkey = evt->key_code(); key.vkey = evt->key_code();
key.transition = false; key.transition = false;
key.prev_state = evt->prev_state(); key.prev_state = evt->prev_state();
key.repeat_count = evt->repeat_count(); key.repeat_count = evt->repeat_count();
key_events_.push(key); key_events_.push(key);
}); });
} }
WinKeyInputDriver::~WinKeyInputDriver() = default; WinKeyInputDriver::~WinKeyInputDriver() = default;
@ -91,7 +89,7 @@ X_RESULT WinKeyInputDriver::GetState(uint32_t user_index,
int16_t thumb_rx = 0; int16_t thumb_rx = 0;
int16_t thumb_ry = 0; int16_t thumb_ry = 0;
if (input_system_->emulator()->display_window()->has_focus()) { if (input_system_->window()->has_focus()) {
if (IS_KEY_TOGGLED(VK_CAPITAL)) { if (IS_KEY_TOGGLED(VK_CAPITAL)) {
// dpad toggled // dpad toggled
if (IS_KEY_DOWN(0x41)) { if (IS_KEY_DOWN(0x41)) {