Compare commits

...

1 Commits

Author SHA1 Message Date
georgemoralis 1d8c2456dd intial work on creating a device interface 2024-08-09 15:44:49 +03:00
5 changed files with 65 additions and 0 deletions

View File

@ -511,6 +511,8 @@ set(VIDEO_CORE src/video_core/amdgpu/liverpool.cpp
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

@ -10,6 +10,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"
namespace Input {
@ -57,6 +58,7 @@ private:
u32 m_first_state = 0;
std::array<State, MAX_STATES> m_states;
std::array<StateInternal, MAX_STATES> m_private;
std::unique_ptr<InputDevices> m_device;
};
} // namespace Input

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