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.
input_system_ = xe::hid::InputSystem::Create(this);
input_system_ = xe::hid::InputSystem::Create(display_window_);
if (!input_system_) {
return X_STATUS_NOT_IMPLEMENTED;
}

View File

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

View File

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

View File

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

View File

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