diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cb09f3cd1..7eaf54708 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,6 +2,7 @@ include_directories(.) add_subdirectory(common) +add_subdirectory(input_common) add_subdirectory(core) add_subdirectory(video_core) if (ENABLE_GLFW) diff --git a/src/input_common/CMakeLists.txt b/src/input_common/CMakeLists.txt new file mode 100644 index 000000000..7061bb970 --- /dev/null +++ b/src/input_common/CMakeLists.txt @@ -0,0 +1,3 @@ +set(SRCS input_common.cpp) + +add_library(input_common STATIC ${SRCS}) diff --git a/src/input_common/controller_state.h b/src/input_common/controller_state.h new file mode 100644 index 000000000..533bd6c5d --- /dev/null +++ b/src/input_common/controller_state.h @@ -0,0 +1,36 @@ +// Copyright 2015 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include "common/common_types.h" + +namespace InputCommon { + + enum ControllerButtons { + A = 0, + B, + X, + Y, + L, + R, + ZL, + ZR, + START, + SELECT, + HOME, + DPAD_LEFT, + DPAD_RIGHT, + DPAD_UP, + DPAD_DOWN + }; + + struct ControllerState { + bool buttons[15]; + s16 circle_pad_x; + s16 circle_pad_y; + u16 touch_screen_x; + u16 touch_screen_y; + }; +} //namespace diff --git a/src/input_common/input_common.cpp b/src/input_common/input_common.cpp new file mode 100644 index 000000000..edbd572bd --- /dev/null +++ b/src/input_common/input_common.cpp @@ -0,0 +1,32 @@ +// Copyright 2015 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include "input_common/input_common.h" + +namespace InputCommon { + +ControllerBase::ControllerBase() { + device_name = "None"; + + //Make sure internal 3DS input is in a neutral state before continuing + for(int x = 0; x < 15; x++) { + controller_state.buttons[x] = false; + } + + controller_state.circle_pad_x = 0; + controller_state.circle_pad_y = 0; + controller_state.touch_screen_x = 0; + controller_state.touch_screen_y = 0; +} + +std::string ControllerBase::GetDeviceName() const { + return device_name; +} + +//Set to nullptr until initialized by a backend +ControllerBase* g_user_input = nullptr; + +} // namespace + + diff --git a/src/input_common/input_common.h b/src/input_common/input_common.h new file mode 100644 index 000000000..b6c7c6850 --- /dev/null +++ b/src/input_common/input_common.h @@ -0,0 +1,47 @@ +// Copyright 2015 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include "common/common_types.h" +#include "controller_state.h" +#include "core/hle/service/hid/hid.h" + +namespace InputCommon { + +class ControllerBase { +public: + ControllerBase(); + virtual ~ControllerBase(); + + ///Initializes input based on specific backends + virtual bool Init() = 0; + + ///Grabs a list of devices supported by the backend + virtual void DiscoverDevices() = 0; + + ///Grab and process input + virtual void Poll() = 0; + + ///Shuts down all backend related data + virtual void ShutDown() = 0; + + ///Returns internal name of currently selected device. Expose this to the UI + std::string GetDeviceName() const; + +private: + + ///Internal view this specific object will have of 3DS input states, NOT the same as Service::HID::PadState! + ControllerState controller_state; + + ///Internal name of currently selected device + std::string device_name; +}; + + +///InputCommon 'plugin' +extern ControllerBase* g_user_input; +} // namespace + +