mirror of
https://github.com/RPCS3/rpcs3.git
synced 2026-02-05 07:15:01 +01:00
Some checks are pending
Generate Translation Template / Generate Translation Template (push) Waiting to run
Build RPCS3 / RPCS3 Linux ${{ matrix.os }} ${{ matrix.compiler }} (/rpcs3/.ci/build-linux-aarch64.sh, gcc, rpcs3/rpcs3-ci-jammy-aarch64:1.7, ubuntu-24.04-arm) (push) Waiting to run
Build RPCS3 / RPCS3 Linux ${{ matrix.os }} ${{ matrix.compiler }} (/rpcs3/.ci/build-linux.sh, gcc, rpcs3/rpcs3-ci-jammy:1.7, ubuntu-24.04) (push) Waiting to run
Build RPCS3 / RPCS3 Linux ${{ matrix.os }} ${{ matrix.compiler }} (a1d35836e8d45bfc6f63c26f0a3e5d46ef622fe1, rpcs3/rpcs3-binaries-linux-arm64, /rpcs3/.ci/build-linux-aarch64.sh, clang, rpcs3/rpcs3-ci-jammy-aarch64:1.7, ubuntu-24.04-arm) (push) Waiting to run
Build RPCS3 / RPCS3 Linux ${{ matrix.os }} ${{ matrix.compiler }} (d812f1254a1157c80fd402f94446310560f54e5f, rpcs3/rpcs3-binaries-linux, /rpcs3/.ci/build-linux.sh, clang, rpcs3/rpcs3-ci-jammy:1.7, ubuntu-24.04) (push) Waiting to run
Build RPCS3 / RPCS3 Mac ${{ matrix.name }} (0, 51ae32f468089a8169aaf1567de355ff4a3e0842, rpcs3/rpcs3-binaries-mac, Intel) (push) Waiting to run
Build RPCS3 / RPCS3 Mac ${{ matrix.name }} (1, 8e21bdbc40711a3fccd18fbf17b742348b0f4281, rpcs3/rpcs3-binaries-mac-arm64, Apple Silicon) (push) Waiting to run
Build RPCS3 / RPCS3 Windows (push) Waiting to run
Build RPCS3 / RPCS3 Windows Clang ${{ matrix.arch }} (aarch64, clang, clangarm64, ARM64, windows-11-arm) (push) Waiting to run
Build RPCS3 / RPCS3 Windows Clang ${{ matrix.arch }} (x86_64, clang, clang64, X64, windows-2025) (push) Waiting to run
Build RPCS3 / RPCS3 FreeBSD (push) Waiting to run
174 lines
3.5 KiB
C++
174 lines
3.5 KiB
C++
#include "stdafx.h"
|
|
#include "MouseHandler.h"
|
|
#include "Emu/System.h"
|
|
#include "util/serialization.hpp"
|
|
|
|
#include <algorithm>
|
|
|
|
MouseHandlerBase::MouseHandlerBase(utils::serial* ar)
|
|
{
|
|
if (!ar)
|
|
{
|
|
return;
|
|
}
|
|
|
|
(*ar)(m_info.max_connect);
|
|
|
|
if (m_info.max_connect)
|
|
{
|
|
Emu.PostponeInitCode([this]()
|
|
{
|
|
Init(m_info.max_connect);
|
|
auto lk = init.init();
|
|
});
|
|
}
|
|
}
|
|
|
|
void MouseHandlerBase::save(utils::serial& ar)
|
|
{
|
|
const auto inited = init.access();
|
|
|
|
ar(inited ? m_info.max_connect : 0);
|
|
}
|
|
|
|
bool MouseHandlerBase::is_time_for_update(double elapsed_time_ms)
|
|
{
|
|
const steady_clock::time_point now = steady_clock::now();
|
|
const double elapsed_ms = (now - m_last_update).count() / 1'000'000.;
|
|
|
|
if (elapsed_ms > elapsed_time_ms)
|
|
{
|
|
m_last_update = now;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void MouseHandlerBase::Button(u32 index, u8 button, bool pressed)
|
|
{
|
|
std::lock_guard lock(mutex);
|
|
|
|
if (index < m_mice.size())
|
|
{
|
|
if (m_info.status[index] != CELL_MOUSE_STATUS_CONNECTED)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Mouse& mouse = m_mice[index];
|
|
MouseDataList& datalist = GetDataList(index);
|
|
|
|
if (datalist.size() > MOUSE_MAX_DATA_LIST_NUM)
|
|
{
|
|
datalist.pop_front();
|
|
}
|
|
|
|
if (pressed)
|
|
mouse.buttons |= button;
|
|
else
|
|
mouse.buttons &= ~button;
|
|
|
|
MouseData new_data{};
|
|
new_data.update = CELL_MOUSE_DATA_UPDATE;
|
|
new_data.buttons = mouse.buttons;
|
|
new_data.pixel_x = mouse.x_pos;
|
|
new_data.pixel_y = mouse.y_pos;
|
|
|
|
datalist.push_back(std::move(new_data));
|
|
}
|
|
}
|
|
|
|
void MouseHandlerBase::Scroll(u32 index, s8 x, s8 y)
|
|
{
|
|
std::lock_guard lock(mutex);
|
|
|
|
if (index < m_mice.size())
|
|
{
|
|
if (m_info.status[index] != CELL_MOUSE_STATUS_CONNECTED)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Mouse& mouse = m_mice[index];
|
|
MouseDataList& datalist = GetDataList(index);
|
|
|
|
if (datalist.size() > MOUSE_MAX_DATA_LIST_NUM)
|
|
{
|
|
datalist.pop_front();
|
|
}
|
|
|
|
MouseData new_data{};
|
|
new_data.update = CELL_MOUSE_DATA_UPDATE;
|
|
new_data.buttons = mouse.buttons;
|
|
new_data.wheel = y;
|
|
new_data.tilt = x;
|
|
new_data.pixel_x = mouse.x_pos;
|
|
new_data.pixel_y = mouse.y_pos;
|
|
|
|
datalist.push_back(std::move(new_data));
|
|
}
|
|
}
|
|
|
|
void MouseHandlerBase::Move(u32 index, s32 x_pos_new, s32 y_pos_new, s32 x_max, s32 y_max, bool is_relative, s32 x_delta, s32 y_delta)
|
|
{
|
|
std::lock_guard lock(mutex);
|
|
|
|
if (index < m_mice.size())
|
|
{
|
|
if (m_info.status[index] != CELL_MOUSE_STATUS_CONNECTED)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Mouse& mouse = m_mice[index];
|
|
MouseDataList& datalist = GetDataList(index);
|
|
|
|
if (datalist.size() > MOUSE_MAX_DATA_LIST_NUM)
|
|
{
|
|
datalist.pop_front();
|
|
}
|
|
|
|
MouseData new_data{};
|
|
new_data.update = CELL_MOUSE_DATA_UPDATE;
|
|
new_data.buttons = mouse.buttons;
|
|
|
|
if (!is_relative)
|
|
{
|
|
// The PS3 expects relative mouse movement, so we have to calculate it with the last absolute position.
|
|
x_delta = x_pos_new - mouse.x_pos;
|
|
y_delta = y_pos_new - mouse.y_pos;
|
|
}
|
|
|
|
new_data.x_axis = static_cast<s8>(std::clamp(x_delta, -127, 128));
|
|
new_data.y_axis = static_cast<s8>(std::clamp(y_delta, -127, 128));
|
|
new_data.pixel_x = x_pos_new;
|
|
new_data.pixel_y = y_pos_new;
|
|
|
|
mouse.x_max = x_max;
|
|
mouse.y_max = y_max;
|
|
mouse.x_pos = x_pos_new;
|
|
mouse.y_pos = y_pos_new;
|
|
|
|
//CellMouseRawData& rawdata = GetRawData(p);
|
|
//rawdata.data[rawdata.len % CELL_MOUSE_MAX_CODES] = 0; // (TODO)
|
|
//rawdata.len++;
|
|
|
|
datalist.push_back(std::move(new_data));
|
|
}
|
|
}
|
|
|
|
void MouseHandlerBase::SetIntercepted(bool intercepted)
|
|
{
|
|
std::lock_guard lock(mutex);
|
|
|
|
m_info.info = intercepted ? CELL_MOUSE_INFO_INTERCEPTED : 0;
|
|
|
|
if (intercepted)
|
|
{
|
|
for (Mouse& mouse : m_mice)
|
|
{
|
|
mouse = {};
|
|
}
|
|
}
|
|
}
|