2018-09-20 08:28:05 +02:00
|
|
|
// Copyright 2018 Citra Emulator Project
|
2018-09-22 22:11:15 +02:00
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2018-09-20 08:28:05 +02:00
|
|
|
#include <atomic>
|
2018-09-22 22:11:15 +02:00
|
|
|
#include <memory>
|
2018-09-20 08:28:05 +02:00
|
|
|
#include <thread>
|
2023-05-03 17:24:10 +02:00
|
|
|
#include <unordered_map>
|
2022-12-08 12:27:25 +01:00
|
|
|
#include "common/settings.h"
|
2018-09-20 08:28:05 +02:00
|
|
|
#include "common/threadsafe_queue.h"
|
|
|
|
#include "input_common/sdl/sdl.h"
|
2018-09-22 22:11:15 +02:00
|
|
|
|
|
|
|
union SDL_Event;
|
2018-09-20 08:28:05 +02:00
|
|
|
using SDL_Joystick = struct _SDL_Joystick;
|
|
|
|
using SDL_JoystickID = s32;
|
2021-01-01 10:01:07 +01:00
|
|
|
using SDL_GameController = struct _SDL_GameController;
|
2018-09-22 22:11:15 +02:00
|
|
|
|
2018-09-20 08:28:05 +02:00
|
|
|
namespace InputCommon::SDL {
|
2018-09-22 22:11:15 +02:00
|
|
|
|
2018-09-20 08:28:05 +02:00
|
|
|
class SDLJoystick;
|
2021-01-01 10:01:07 +01:00
|
|
|
class SDLGameController;
|
2018-09-20 08:28:05 +02:00
|
|
|
class SDLButtonFactory;
|
|
|
|
class SDLAnalogFactory;
|
2021-09-09 05:04:46 +02:00
|
|
|
class SDLMotionFactory;
|
2018-09-22 22:11:15 +02:00
|
|
|
|
2018-09-20 08:28:05 +02:00
|
|
|
class SDLState : public State {
|
|
|
|
public:
|
|
|
|
/// Initializes and registers SDL device factories
|
|
|
|
SDLState();
|
2018-09-22 22:11:15 +02:00
|
|
|
|
Port various minor changes from yuzu PRs (#4725)
* common/thread: Remove unused functions
Many of these functions are carried over from Dolphin (where they aren't
used anymore). Given these have no use (and we really shouldn't be
screwing around with OS-specific thread scheduler handling from the
emulator, these can be removed.
The function for setting the thread name is left, however, since it can
have debugging utility usages.
* input_common/sdl: Use a type alias to shorten declaration of GetPollers
Just makes the definitions a little bit more tidy.
* input_common/sdl: Correct return values within implementations of GetPollers()
In both cases, we weren't actually returning anything, which is
undefined behavior.
* yuzu/debugger/graphics_surface: Fill in missing surface format listings
Fills in the missing surface types that were marked as unknown. The
order corresponds with the TextureFormat enum within
video_core/texture.h.
We also don't need to all of these strings as translatable (only the
first string, as it's an English word).
* yuzu/debugger/graphics_surface: Clean up connection overload deduction
We can utilize qOverload with the signal connections to make the
function deducing a little less ugly.
* yuzu/debugger/graphics_surface: Tidy up SaveSurface
- Use QStringLiteral where applicable.
- Use const where applicable
- Remove unnecessary precondition check (we already assert the pixbuf
being non null)
* yuzu/debugger/graphics_surface: Display error messages for file I/O errors
* core: Add missing override specifiers where applicable
Applies the override specifier where applicable. In the case of
destructors that are defaulted in their definition, they can
simply be removed.
This also removes the unnecessary inclusions being done in audin_u and
audrec_u, given their close proximity.
* kernel/thread: Make parameter of GetWaitObjectIndex() const qualified
The pointed to member is never actually modified, so it can be made
const.
* kernel/thread: Avoid sign conversion within GetCommandBufferAddress()
Previously this was performing a u64 + int sign conversion. When dealing
with addresses, we should generally be keeping the arithmetic in the
same signedness type.
This also gets rid of the static lifetime of the constant, as there's no
need to make a trivial type like this potentially live for the entire
duration of the program.
* kernel/codeset: Make CodeSet's memory data member a regular std::vector
The use of a shared_ptr is an implementation detail of the VMManager
itself when mapping memory. Because of that, we shouldn't require all
users of the CodeSet to have to allocate the shared_ptr ahead of time.
It's intended that CodeSet simply pass in the required direct data, and
that the memory manager takes care of it from that point on.
This means we just do the shared pointer allocation in a single place,
when loading modules, as opposed to in each loader.
* kernel/wait_object: Make ShouldWait() take thread members by pointer-to-const
Given this is intended as a querying function, it doesn't make sense to
allow the implementer to modify the state of the given thread.
2019-05-01 14:28:49 +02:00
|
|
|
/// Unregisters SDL device factories and shut them down.
|
2018-09-20 08:28:05 +02:00
|
|
|
~SDLState() override;
|
2018-09-22 22:11:15 +02:00
|
|
|
|
2018-09-20 08:28:05 +02:00
|
|
|
/// Handle SDL_Events for joysticks from SDL_PollEvent
|
|
|
|
void HandleGameControllerEvent(const SDL_Event& event);
|
2018-09-22 22:11:15 +02:00
|
|
|
|
2018-09-20 08:28:05 +02:00
|
|
|
std::shared_ptr<SDLJoystick> GetSDLJoystickBySDLID(SDL_JoystickID sdl_id);
|
|
|
|
std::shared_ptr<SDLJoystick> GetSDLJoystickByGUID(const std::string& guid, int port);
|
2018-09-22 22:11:15 +02:00
|
|
|
|
2021-01-01 10:01:07 +01:00
|
|
|
std::shared_ptr<SDLGameController> GetSDLGameControllerByGUID(const std::string& guid,
|
|
|
|
int port);
|
|
|
|
|
|
|
|
Common::ParamPackage GetSDLControllerButtonBindByGUID(const std::string& guid, int port,
|
|
|
|
Settings::NativeButton::Values button);
|
|
|
|
Common::ParamPackage GetSDLControllerAnalogBindByGUID(const std::string& guid, int port,
|
|
|
|
Settings::NativeAnalog::Values analog);
|
|
|
|
|
2018-09-20 08:28:05 +02:00
|
|
|
/// Get all DevicePoller that use the SDL backend for a specific device type
|
Port various minor changes from yuzu PRs (#4725)
* common/thread: Remove unused functions
Many of these functions are carried over from Dolphin (where they aren't
used anymore). Given these have no use (and we really shouldn't be
screwing around with OS-specific thread scheduler handling from the
emulator, these can be removed.
The function for setting the thread name is left, however, since it can
have debugging utility usages.
* input_common/sdl: Use a type alias to shorten declaration of GetPollers
Just makes the definitions a little bit more tidy.
* input_common/sdl: Correct return values within implementations of GetPollers()
In both cases, we weren't actually returning anything, which is
undefined behavior.
* yuzu/debugger/graphics_surface: Fill in missing surface format listings
Fills in the missing surface types that were marked as unknown. The
order corresponds with the TextureFormat enum within
video_core/texture.h.
We also don't need to all of these strings as translatable (only the
first string, as it's an English word).
* yuzu/debugger/graphics_surface: Clean up connection overload deduction
We can utilize qOverload with the signal connections to make the
function deducing a little less ugly.
* yuzu/debugger/graphics_surface: Tidy up SaveSurface
- Use QStringLiteral where applicable.
- Use const where applicable
- Remove unnecessary precondition check (we already assert the pixbuf
being non null)
* yuzu/debugger/graphics_surface: Display error messages for file I/O errors
* core: Add missing override specifiers where applicable
Applies the override specifier where applicable. In the case of
destructors that are defaulted in their definition, they can
simply be removed.
This also removes the unnecessary inclusions being done in audin_u and
audrec_u, given their close proximity.
* kernel/thread: Make parameter of GetWaitObjectIndex() const qualified
The pointed to member is never actually modified, so it can be made
const.
* kernel/thread: Avoid sign conversion within GetCommandBufferAddress()
Previously this was performing a u64 + int sign conversion. When dealing
with addresses, we should generally be keeping the arithmetic in the
same signedness type.
This also gets rid of the static lifetime of the constant, as there's no
need to make a trivial type like this potentially live for the entire
duration of the program.
* kernel/codeset: Make CodeSet's memory data member a regular std::vector
The use of a shared_ptr is an implementation detail of the VMManager
itself when mapping memory. Because of that, we shouldn't require all
users of the CodeSet to have to allocate the shared_ptr ahead of time.
It's intended that CodeSet simply pass in the required direct data, and
that the memory manager takes care of it from that point on.
This means we just do the shared pointer allocation in a single place,
when loading modules, as opposed to in each loader.
* kernel/wait_object: Make ShouldWait() take thread members by pointer-to-const
Given this is intended as a querying function, it doesn't make sense to
allow the implementer to modify the state of the given thread.
2019-05-01 14:28:49 +02:00
|
|
|
Pollers GetPollers(Polling::DeviceType type) override;
|
2018-09-22 22:11:15 +02:00
|
|
|
|
2018-09-20 08:28:05 +02:00
|
|
|
/// Used by the Pollers during config
|
|
|
|
std::atomic<bool> polling = false;
|
|
|
|
Common::SPSCQueue<SDL_Event> event_queue;
|
2018-09-22 22:11:15 +02:00
|
|
|
|
2018-09-20 08:28:05 +02:00
|
|
|
private:
|
|
|
|
void InitJoystick(int joystick_index);
|
|
|
|
void CloseJoystick(SDL_Joystick* sdl_joystick);
|
2018-09-22 22:11:15 +02:00
|
|
|
|
2021-01-01 10:01:07 +01:00
|
|
|
void InitGameController(int joystick_index);
|
|
|
|
void CloseGameController(SDL_GameController* sdl_controller);
|
|
|
|
|
2018-09-20 08:28:05 +02:00
|
|
|
/// Needs to be called before SDL_QuitSubSystem.
|
|
|
|
void CloseJoysticks();
|
2021-01-01 10:01:07 +01:00
|
|
|
void CloseGameControllers();
|
2018-09-20 08:28:05 +02:00
|
|
|
|
|
|
|
/// Map of GUID of a list of corresponding virtual Joysticks
|
|
|
|
std::unordered_map<std::string, std::vector<std::shared_ptr<SDLJoystick>>> joystick_map;
|
|
|
|
std::mutex joystick_map_mutex;
|
|
|
|
|
2021-01-01 10:01:07 +01:00
|
|
|
/// Map of GUID of a list of corresponding virtual Controllers
|
|
|
|
std::unordered_map<std::string, std::vector<std::shared_ptr<SDLGameController>>> controller_map;
|
|
|
|
std::mutex controller_map_mutex;
|
|
|
|
|
2018-09-20 08:28:05 +02:00
|
|
|
std::shared_ptr<SDLButtonFactory> button_factory;
|
|
|
|
std::shared_ptr<SDLAnalogFactory> analog_factory;
|
2021-09-09 05:04:46 +02:00
|
|
|
std::shared_ptr<SDLMotionFactory> motion_factory;
|
2018-09-20 08:28:05 +02:00
|
|
|
|
|
|
|
bool start_thread = false;
|
|
|
|
std::atomic<bool> initialized = false;
|
|
|
|
|
|
|
|
std::thread poll_thread;
|
|
|
|
};
|
|
|
|
} // namespace InputCommon::SDL
|