mirror of
https://github.com/citra-emu/citra.git
synced 2024-11-30 07:20:05 +00:00
Starting on scripted_input, rough Input::Factory to set the provide the Input::ButtonDevices.
This commit is contained in:
parent
9f6868ad9b
commit
1eb6af61fd
@ -7,6 +7,7 @@ add_subdirectory(video_core)
|
|||||||
add_subdirectory(audio_core)
|
add_subdirectory(audio_core)
|
||||||
add_subdirectory(network)
|
add_subdirectory(network)
|
||||||
add_subdirectory(input_common)
|
add_subdirectory(input_common)
|
||||||
|
add_subdirectory(scripted_input)
|
||||||
add_subdirectory(tests)
|
add_subdirectory(tests)
|
||||||
if (ENABLE_SDL2)
|
if (ENABLE_SDL2)
|
||||||
add_subdirectory(citra)
|
add_subdirectory(citra)
|
||||||
|
@ -16,7 +16,7 @@ set(HEADERS
|
|||||||
create_directory_groups(${SRCS} ${HEADERS})
|
create_directory_groups(${SRCS} ${HEADERS})
|
||||||
|
|
||||||
add_executable(citra ${SRCS} ${HEADERS})
|
add_executable(citra ${SRCS} ${HEADERS})
|
||||||
target_link_libraries(citra PRIVATE common core input_common network)
|
target_link_libraries(citra PRIVATE common core input_common network scripted_input)
|
||||||
target_link_libraries(citra PRIVATE inih glad)
|
target_link_libraries(citra PRIVATE inih glad)
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
target_link_libraries(citra PRIVATE getopt)
|
target_link_libraries(citra PRIVATE getopt)
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include "core/settings.h"
|
#include "core/settings.h"
|
||||||
#include "input_common/keyboard.h"
|
#include "input_common/keyboard.h"
|
||||||
#include "input_common/main.h"
|
#include "input_common/main.h"
|
||||||
|
#include "scripted_input/scripted_input.h"
|
||||||
#include "network/network.h"
|
#include "network/network.h"
|
||||||
|
|
||||||
void EmuWindow_SDL2::OnMouseMotion(s32 x, s32 y) {
|
void EmuWindow_SDL2::OnMouseMotion(s32 x, s32 y) {
|
||||||
@ -59,6 +60,7 @@ void EmuWindow_SDL2::OnResize() {
|
|||||||
|
|
||||||
EmuWindow_SDL2::EmuWindow_SDL2() {
|
EmuWindow_SDL2::EmuWindow_SDL2() {
|
||||||
InputCommon::Init();
|
InputCommon::Init();
|
||||||
|
ScriptedInput::Init();
|
||||||
Network::Init();
|
Network::Init();
|
||||||
|
|
||||||
motion_emu = std::make_unique<Motion::MotionEmu>(*this);
|
motion_emu = std::make_unique<Motion::MotionEmu>(*this);
|
||||||
|
14
src/scripted_input/CMakeLists.txt
Normal file
14
src/scripted_input/CMakeLists.txt
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
set(SRCS
|
||||||
|
scripted_input.cpp
|
||||||
|
scripted_buttons.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
set(HEADERS
|
||||||
|
scripted_input.h
|
||||||
|
scripted_buttons.h
|
||||||
|
)
|
||||||
|
|
||||||
|
create_directory_groups(${SRCS} ${HEADERS})
|
||||||
|
|
||||||
|
add_library(scripted_input STATIC ${SRCS} ${HEADERS})
|
||||||
|
target_link_libraries(scripted_input PUBLIC common core)
|
68
src/scripted_input/scripted_buttons.cpp
Normal file
68
src/scripted_input/scripted_buttons.cpp
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
// Copyright 2017 Citra Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include "scripted_input/scripted_buttons.h"
|
||||||
|
|
||||||
|
std::string button_name_to_index[] = {
|
||||||
|
"a",
|
||||||
|
"b",
|
||||||
|
"x",
|
||||||
|
"y",
|
||||||
|
"up",
|
||||||
|
"down",
|
||||||
|
"left",
|
||||||
|
"right",
|
||||||
|
"l",
|
||||||
|
"r",
|
||||||
|
"start",
|
||||||
|
"select",
|
||||||
|
"zl",
|
||||||
|
"zr",
|
||||||
|
"home"
|
||||||
|
};
|
||||||
|
|
||||||
|
int IndexOfButton(const std::string& button) {
|
||||||
|
for (int i = 0; i < 15; i++) {
|
||||||
|
if (button_name_to_index[i] == button) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: Log an error
|
||||||
|
return -1; //home
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace ScriptedInput {
|
||||||
|
|
||||||
|
class ScriptedButton final : public Input::ButtonDevice {
|
||||||
|
bool GetStatus() const override {
|
||||||
|
return status.load();
|
||||||
|
}
|
||||||
|
|
||||||
|
friend class ScriptedButtons;
|
||||||
|
private:
|
||||||
|
std::atomic<bool> status{false};
|
||||||
|
};
|
||||||
|
|
||||||
|
class ScriptedButtonList {
|
||||||
|
//TODO: Do i need to memset(0) buttons?
|
||||||
|
public:
|
||||||
|
ScriptedButton* buttons[15];
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
ScriptedButtons::ScriptedButtons() : scripted_button_list{std::make_shared<ScriptedButtonList>()} {}
|
||||||
|
|
||||||
|
std::unique_ptr<Input::ButtonDevice> ScriptedButtons::Create(const Common::ParamPackage& params) {
|
||||||
|
auto button_str = params.Get("button", "");
|
||||||
|
|
||||||
|
std::unique_ptr<ScriptedButton> button = std::make_unique<ScriptedButton>();
|
||||||
|
int index = IndexOfButton(button_str);
|
||||||
|
if (index >= 0) {
|
||||||
|
scripted_button_list.get()->buttons[index] = button.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::move(button);
|
||||||
|
}
|
||||||
|
}
|
32
src/scripted_input/scripted_buttons.h
Normal file
32
src/scripted_input/scripted_buttons.h
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
// Copyright 2017 Citra Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
#include <memory>
|
||||||
|
#include "core/frontend/input.h"
|
||||||
|
|
||||||
|
namespace ScriptedInput {
|
||||||
|
|
||||||
|
class ScriptedButtonList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A button device factory that returns inputs from a script file
|
||||||
|
*/
|
||||||
|
class ScriptedButtons final : public Input::Factory<Input::ButtonDevice> {
|
||||||
|
public:
|
||||||
|
ScriptedButtons();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a button device
|
||||||
|
* @param params unused
|
||||||
|
*/
|
||||||
|
std::unique_ptr<Input::ButtonDevice> Create(const Common::ParamPackage& params) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::shared_ptr<ScriptedButtonList> scripted_button_list;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace InputCommon
|
28
src/scripted_input/scripted_input.cpp
Normal file
28
src/scripted_input/scripted_input.cpp
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
// Copyright 2017 Citra Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include "scripted_input/scripted_buttons.h"
|
||||||
|
#include "scripted_input/scripted_input.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace ScriptedInput {
|
||||||
|
|
||||||
|
static std::shared_ptr<ScriptedButtons> scripted_buttons;
|
||||||
|
//TODO: static std::shared_ptr<ScriptedAnalog> scripted_analog;
|
||||||
|
|
||||||
|
void Init() {
|
||||||
|
scripted_buttons = std::make_shared<ScriptedInput::ScriptedButtons>();
|
||||||
|
Input::RegisterFactory<Input::ButtonDevice>("scripted", scripted_buttons);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Shutdown() {
|
||||||
|
Input::UnregisterFactory<Input::ButtonDevice>("scripted");
|
||||||
|
}
|
||||||
|
|
||||||
|
ScriptedButtons* GetScriptedButtons() {
|
||||||
|
return scripted_buttons.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace ScriptedInput
|
21
src/scripted_input/scripted_input.h
Normal file
21
src/scripted_input/scripted_input.h
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
// Copyright 2017 Citra Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace ScriptedInput {
|
||||||
|
|
||||||
|
/// Initializes and registers all built-in input device factories.
|
||||||
|
void Init();
|
||||||
|
|
||||||
|
/// Unresisters all build-in input device factories and shut them down.
|
||||||
|
void Shutdown();
|
||||||
|
|
||||||
|
class ScriptedButtons;
|
||||||
|
|
||||||
|
ScriptedButtons* GetScriptedButtons();
|
||||||
|
|
||||||
|
} // namespace InputCommon
|
Loading…
Reference in New Issue
Block a user