mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-08-04 08:22:32 +00:00
libMouse: adds mutexes
This commit is contained in:
parent
d1fdbd024a
commit
c70a4965c2
@ -1,23 +1,32 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
// Generated By moduleGenerator
|
||||
#include "mouse.h"
|
||||
|
||||
#include <common/singleton.h>
|
||||
#include <core/libraries/system/msgdialog_ui.h>
|
||||
#include <input/mouse.h>
|
||||
#include "common/elf_info.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "core/libraries/error_codes.h"
|
||||
#include "core/libraries/libs.h"
|
||||
#include "mouse.h"
|
||||
|
||||
#include <mutex>
|
||||
|
||||
using Common::ElfInfo;
|
||||
|
||||
namespace Libraries::Mouse {
|
||||
|
||||
static std::mutex g_mtx;
|
||||
|
||||
static bool g_initialized = false;
|
||||
static bool g_mouse1_open = false;
|
||||
static bool g_mouse2_open = false;
|
||||
|
||||
constexpr auto MOUSE1_HANDLE = 0xF1;
|
||||
constexpr auto MOUSE2_HANDLE = 0xF2;
|
||||
constexpr int32_t MOUSE1_HANDLE = 0x72617431; // rat1
|
||||
constexpr int32_t MOUSE2_HANDLE = 0x72617432; // rat2
|
||||
static_assert(MOUSE1_HANDLE > 0);
|
||||
static_assert(MOUSE2_HANDLE > 0);
|
||||
|
||||
constexpr auto ORBIS_MOUSE_OPEN_PARAM_NORMAL = 0x00;
|
||||
constexpr auto ORBIS_MOUSE_OPEN_PARAM_MERGED = 0x01;
|
||||
@ -27,6 +36,7 @@ int PS4_SYSV_ABI sceMouseClose(s32 handle) {
|
||||
if (!g_initialized) {
|
||||
return ORBIS_MOUSE_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
std::lock_guard lck{g_mtx};
|
||||
if (handle == MOUSE1_HANDLE && g_mouse1_open) {
|
||||
g_mouse1_open = false;
|
||||
return ORBIS_OK;
|
||||
@ -71,6 +81,7 @@ int PS4_SYSV_ABI sceMouseGetDeviceInfo() {
|
||||
|
||||
int PS4_SYSV_ABI sceMouseInit() {
|
||||
LOG_INFO(Lib_Mouse, "called");
|
||||
std::lock_guard lck{g_mtx};
|
||||
g_initialized = true;
|
||||
return ORBIS_OK;
|
||||
}
|
||||
@ -85,7 +96,13 @@ int PS4_SYSV_ABI sceMouseOpen(s32 userId, s32 type, s32 index, OrbisMouseOpenPar
|
||||
if (!g_initialized) {
|
||||
return ORBIS_MOUSE_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
bool merge = pParam != nullptr && (pParam->behaviorFlag & ORBIS_MOUSE_OPEN_PARAM_MERGED) != 0;
|
||||
if (type != 0) {
|
||||
return ORBIS_MOUSE_ERROR_INVALID_ARG;
|
||||
}
|
||||
std::lock_guard lck{g_mtx};
|
||||
|
||||
bool merge = ElfInfo::Instance().FirmwareVer() >= ElfInfo::FW_20 && pParam != nullptr &&
|
||||
(pParam->behaviorFlag & ORBIS_MOUSE_OPEN_PARAM_MERGED) != 0;
|
||||
|
||||
if (merge || index == 0) {
|
||||
if (g_mouse1_open) {
|
||||
@ -128,6 +145,8 @@ int PS4_SYSV_ABI sceMouseRead(s32 handle, OrbisMouseData* pData, s32 num) {
|
||||
return ORBIS_MOUSE_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
std::lock_guard lck{g_mtx};
|
||||
|
||||
auto* mouse = Common::Singleton<Input::GameMouse>::Instance();
|
||||
|
||||
if (handle == MOUSE1_HANDLE) {
|
||||
|
@ -16,13 +16,13 @@ struct OrbisMouseOpenParam {
|
||||
};
|
||||
|
||||
struct OrbisMouseData {
|
||||
u64 timestamp;
|
||||
bool connected;
|
||||
u32 buttons;
|
||||
s32 xAxis;
|
||||
s32 yAxis;
|
||||
s32 wheel;
|
||||
s32 tilt;
|
||||
u64 timestamp{};
|
||||
bool connected{};
|
||||
u32 buttons{};
|
||||
s32 xAxis{};
|
||||
s32 yAxis{};
|
||||
s32 wheel{};
|
||||
s32 tilt{};
|
||||
std::array<u8, 8> reserve{};
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user