mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2024-12-26 17:37:03 +00:00
intial work on creating a device interface
Some checks failed
Clang Format / clang-format (push) Has been cancelled
Some checks failed
Clang Format / clang-format (push) Has been cancelled
This commit is contained in:
parent
2aab7e05ee
commit
c14ec39de9
|
@ -619,6 +619,8 @@ set(IMGUI src/imgui/imgui_config.h
|
|||
|
||||
set(INPUT src/input/controller.cpp
|
||||
src/input/controller.h
|
||||
src/input/devices/devices.h
|
||||
src/input/devices/sdl_keyboard.cpp
|
||||
)
|
||||
|
||||
set(EMULATOR src/emulator.cpp
|
||||
|
|
|
@ -11,6 +11,7 @@ namespace Input {
|
|||
GameController::GameController() {
|
||||
m_states_num = 0;
|
||||
m_last_state = State();
|
||||
m_device = std::make_unique<SDLKeyboard>();
|
||||
}
|
||||
|
||||
void GameController::ReadState(State* state, bool* isConnected, int* connectedCount) {
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include <mutex>
|
||||
#include "common/types.h"
|
||||
#include "devices/devices.h"
|
||||
|
||||
struct SDL_Gamepad;
|
||||
|
||||
|
@ -71,6 +72,7 @@ private:
|
|||
std::array<State, MAX_STATES> m_states;
|
||||
std::array<StateInternal, MAX_STATES> m_private;
|
||||
|
||||
std::unique_ptr<InputDevices> m_device;
|
||||
SDL_Gamepad* m_sdl_gamepad = nullptr;
|
||||
};
|
||||
|
||||
|
|
41
src/input/devices/devices.h
Normal file
41
src/input/devices/devices.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <unordered_map>
|
||||
#include <common/types.h>
|
||||
|
||||
namespace Input {
|
||||
|
||||
struct InputMappings {
|
||||
using Scancode = u32;
|
||||
using Container = std::unordered_map<Scancode, u32>;
|
||||
|
||||
u32 getMapping(Scancode scancode) const {
|
||||
auto it = container.find(scancode);
|
||||
return it != container.end() ? it->second : -1;
|
||||
}
|
||||
|
||||
void setMapping(Scancode scancode, u32 key) {
|
||||
container[scancode] = key;
|
||||
}
|
||||
|
||||
private:
|
||||
Container container;
|
||||
};
|
||||
|
||||
class InputDevices {
|
||||
|
||||
public:
|
||||
virtual ~InputDevices() = default;
|
||||
virtual InputMappings GetMappings() = 0;
|
||||
};
|
||||
|
||||
class SDLKeyboard : public InputDevices {
|
||||
public:
|
||||
virtual ~SDLKeyboard();
|
||||
virtual InputMappings GetMappings() override;
|
||||
};
|
||||
|
||||
} // namespace Input
|
19
src/input/devices/sdl_keyboard.cpp
Normal file
19
src/input/devices/sdl_keyboard.cpp
Normal file
|
@ -0,0 +1,19 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <SDL3/SDL_keycode.h>
|
||||
#include "core/libraries/pad/pad.h"
|
||||
#include "devices.h"
|
||||
|
||||
namespace Input {
|
||||
|
||||
SDLKeyboard::~SDLKeyboard() {}
|
||||
|
||||
InputMappings SDLKeyboard::GetMappings() {
|
||||
using Libraries::Pad::OrbisPadButtonDataOffset;
|
||||
InputMappings mappings;
|
||||
mappings.setMapping(SDLK_UP, OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_UP);
|
||||
// TODO the rest
|
||||
return mappings;
|
||||
}
|
||||
} // namespace Input
|
Loading…
Reference in a new issue