Commit d5d43511 authored by James's avatar James
Browse files

Migrate LibRetro input factories to the LibRetro module

parent d01cde07
......@@ -2,9 +2,11 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/CMakeModules)
set(SRCS
citra_libretro.cpp libretro_window.cpp environment.cpp
input/input_factory.cpp
)
set(HEADERS
citra_libretro.h libretro_window.h environment.h)
citra_libretro.h libretro_window.h environment.h
input/input_factory.h)
create_directory_groups(${SRCS} ${HEADERS})
......
......@@ -20,12 +20,12 @@
#include "core/core.h"
#include "core/loader/loader.h"
#include "core/settings.h"
#include "input_common/libretro/libretro.h"
#include "input_common/main.h"
#include "video_core/video_core.h"
#include "video_core/renderer_opengl/renderer_opengl.h"
#include "citra_libretro.h"
#include "environment.h"
#include "citra_libretro/input/input_factory.h"
#include "citra_libretro/citra_libretro.h"
#include "citra_libretro/environment.h"
// TODO: Find a better place for this junk.
Log::Filter log_filter (Log::Level::Info);
......@@ -40,7 +40,7 @@ void retro_init() {
LOG_DEBUG(Frontend, "Initialising core...");
Log::SetFilter(&log_filter);
InputCommon::Init();
LibRetro::Input::Init();
}
void retro_deinit() {
......@@ -48,6 +48,8 @@ void retro_deinit() {
if (system_core.IsPoweredOn()) {
system_core.Shutdown();
}
LibRetro::Input::Shutdown();
}
unsigned retro_api_version() {
......
......@@ -8,7 +8,6 @@
#include "audio_core/libretro_sink.h"
#include "common/scm_rev.h"
#include "environment.h"
#include "input_common/libretro/libretro.h"
using namespace LibRetro;
......
......@@ -6,21 +6,22 @@
#include <memory>
#include <unordered_map>
#include <libretro.h>
#include "core/frontend/input.h"
#include "common/logging/log.h"
#include "common/math_util.h"
#include "input_common/libretro/libretro.h"
namespace InputCommon {
#include "citra_libretro/input/input_factory.h"
namespace LibRetro {
// TODO: Should this be outside of LibRetro's namespace?
namespace Input {
static retro_input_state_t input_state_cb;
class LibRetroButtonFactory;
class LibRetroAxisFactory;
class LibRetroButton final : public Input::ButtonDevice {
class LibRetroButton final : public ::Input::ButtonDevice {
public:
explicit LibRetroButton(int joystick_, int button_)
: joystick(joystick_), button(button_) {}
......@@ -35,7 +36,7 @@ private:
};
/// A button device factory that creates button devices from LibRetro joystick
class LibRetroButtonFactory final : public Input::Factory<Input::ButtonDevice> {
class LibRetroButtonFactory final : public ::Input::Factory<::Input::ButtonDevice> {
public:
/**
* Creates a button device from a joystick button
......@@ -43,7 +44,7 @@ public:
* - "joystick": the index of the joystick to bind
* - "button": the index of the button to bind
*/
std::unique_ptr<Input::ButtonDevice> Create(const Common::ParamPackage& params) override {
std::unique_ptr<::Input::ButtonDevice> Create(const Common::ParamPackage& params) override {
const int joystick_index = params.Get("joystick", 0);
const int button = params.Get("button", 0);
......@@ -52,7 +53,7 @@ public:
};
/// A axis device factory that creates axis devices from LibRetro joystick
class LibRetroAxis final : public Input::AnalogDevice {
class LibRetroAxis final : public ::Input::AnalogDevice {
public:
explicit LibRetroAxis(int joystick_, int button_)
: joystick(joystick_), button(button_) {}
......@@ -69,7 +70,7 @@ private:
};
/// A axis device factory that creates axis devices from SDL joystick
class LibRetroAxisFactory final : public Input::Factory<Input::AnalogDevice> {
class LibRetroAxisFactory final : public ::Input::Factory<::Input::AnalogDevice> {
public:
/**
* Creates a button device from a joystick button
......@@ -86,7 +87,7 @@ public:
* is greater than the threshold; "-" means the button is triggered when the axis value
* is smaller than the threshold
*/
std::unique_ptr<Input::AnalogDevice> Create(const Common::ParamPackage& params) override {
std::unique_ptr<::Input::AnalogDevice> Create(const Common::ParamPackage& params) override {
const int joystick_index = params.Get("joystick", 0);
const int button = params.Get("axis", 0);
......@@ -100,20 +101,20 @@ int16_t CheckButton(unsigned port, unsigned device,
}
void Init() {
using namespace Input;
using namespace ::Input;
RegisterFactory<ButtonDevice>("libretro", std::make_shared<LibRetroButtonFactory>());
RegisterFactory<AnalogDevice>("libretro", std::make_shared<LibRetroAxisFactory>());
}
void Shutdown() {
using namespace Input;
using namespace ::Input;
UnregisterFactory<ButtonDevice>("libretro");
UnregisterFactory<AnalogDevice>("libretro");
}
} // namespace Input
} // namespace LibRetro
} // namespace InputCommon
void retro_set_input_state(retro_input_state_t cb) {
InputCommon::LibRetro::input_state_cb = cb;
LibRetro::Input::input_state_cb = cb;
}
......@@ -6,9 +6,10 @@
#include "core/frontend/input.h"
namespace InputCommon {
namespace LibRetro {
namespace Input {
/// Function provided by Retroarch dynamically to poll input.
int16_t CheckButton(unsigned port, unsigned device,
unsigned index, unsigned id);
......@@ -19,5 +20,5 @@ void Init();
/// Unresisters LibRetro device factories and shut them down.
void Shutdown();
} // namespace Input
} // namespace LibRetro
} // namespace InputCommon
......@@ -7,10 +7,10 @@
#include "core/settings.h"
#include "core/3ds.h"
#include "common/logging/log.h"
#include "input_common/libretro/libretro.h"
#include "libretro.h"
#include "citra_libretro.h"
#include "environment.h"
#include "citra_libretro/input/input_factory.h"
#include "citra_libretro/citra_libretro.h"
#include "citra_libretro/environment.h"
/// LibRetro expects a "default" GL state.
void ResetGLState() {
......@@ -69,11 +69,11 @@ void EmuWindow_LibRetro::PollEvents() {
// TODO: Poll for right click
// TODO: Do we want to check other input devices?
bool state = static_cast<bool>(InputCommon::LibRetro::CheckButton(0, RETRO_DEVICE_POINTER,
bool state = static_cast<bool>(LibRetro::Input::CheckButton(0, RETRO_DEVICE_POINTER,
0, RETRO_DEVICE_ID_POINTER_PRESSED));
int x = (int) InputCommon::LibRetro::CheckButton(0, RETRO_DEVICE_POINTER,
int x = (int) LibRetro::Input::CheckButton(0, RETRO_DEVICE_POINTER,
0, RETRO_DEVICE_ID_POINTER_X);
int y = (int) InputCommon::LibRetro::CheckButton(0, RETRO_DEVICE_POINTER,
int y = (int) LibRetro::Input::CheckButton(0, RETRO_DEVICE_POINTER,
0, RETRO_DEVICE_ID_POINTER_Y);
if (state) {
......
......@@ -15,7 +15,6 @@ add_library(input_common STATIC
udp/udp.h
$<$<BOOL:${SDL2_FOUND}>:sdl/sdl.cpp sdl/sdl.h>
$<$<BOOL:${ENABLE_LIBRETRO}>:libretro/libretro.cpp libretro/libretro.h>
)
create_target_directory_groups(input_common)
......@@ -25,8 +24,3 @@ if(SDL2_FOUND)
target_link_libraries(input_common PRIVATE SDL2)
target_compile_definitions(input_common PRIVATE HAVE_SDL2)
endif()
if(ENABLE_LIBRETRO)
target_link_libraries(input_common PRIVATE libretro)
target_compile_definitions(input_common PRIVATE HAVE_LIBRETRO)
endif()
......@@ -13,9 +13,6 @@
#ifdef HAVE_SDL2
#include "input_common/sdl/sdl.h"
#endif
#ifdef HAVE_LIBRETRO
#include "input_common/libretro/libretro.h"
#endif
namespace InputCommon {
......@@ -38,9 +35,6 @@ void Init() {
#ifdef HAVE_SDL2
SDL::Init();
#endif
#ifdef HAVE_LIBRETRO
LibRetro::Init();
#endif
udp = CemuhookUDP::Init();
}
......@@ -62,9 +56,6 @@ void Shutdown() {
SDL::Shutdown();
poll_thread.join();
#endif
#ifdef HAVE_LIBRETRO
LibRetro::Shutdown();
#endif
}
Keyboard* GetKeyboard() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment