intial work on creating a device interface
Some checks failed
Clang Format / clang-format (push) Has been cancelled

This commit is contained in:
georgemoralis 2024-08-09 15:44:49 +03:00
parent 2aab7e05ee
commit c14ec39de9
5 changed files with 65 additions and 0 deletions

View file

@ -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

View file

@ -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) {

View file

@ -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;
};

View 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

View 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