Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USB: Move to Qt (with *significant* refactoring) #7534

Merged
merged 10 commits into from
Dec 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions PCSX2_suite.sln
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "liblzma", "3rdparty\xz\libl
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fmt", "3rdparty\fmt\fmt.vcxproj", "{449AD25E-424A-4714-BABC-68706CDCC33B}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libsamplerate", "3rdparty\libsamplerate\libsamplerate.vcxproj", "{47AFDBEF-F15F-4BC0-B436-5BE443C3F80F}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libchdr", "3rdparty\libchdr\libchdr.vcxproj", "{A0D2B3AD-1F72-4EE3-8B5C-F2C358DA35F0}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "jpgd", "3rdparty\jpgd\jpgd.vcxproj", "{ED2F21FD-0A36-4A8F-9B90-E7D92A2ACB63}"
Expand Down Expand Up @@ -248,18 +246,6 @@ Global
{449AD25E-424A-4714-BABC-68706CDCC33B}.Release AVX2|x64.Build.0 = Release|x64
{449AD25E-424A-4714-BABC-68706CDCC33B}.Release|x64.ActiveCfg = Release|x64
{449AD25E-424A-4714-BABC-68706CDCC33B}.Release|x64.Build.0 = Release|x64
{47AFDBEF-F15F-4BC0-B436-5BE443C3F80F}.Debug AVX2|x64.ActiveCfg = Debug|x64
{47AFDBEF-F15F-4BC0-B436-5BE443C3F80F}.Debug AVX2|x64.Build.0 = Debug|x64
{47AFDBEF-F15F-4BC0-B436-5BE443C3F80F}.Debug|x64.ActiveCfg = Debug|x64
{47AFDBEF-F15F-4BC0-B436-5BE443C3F80F}.Debug|x64.Build.0 = Debug|x64
{47AFDBEF-F15F-4BC0-B436-5BE443C3F80F}.Devel AVX2|x64.ActiveCfg = Devel|x64
{47AFDBEF-F15F-4BC0-B436-5BE443C3F80F}.Devel AVX2|x64.Build.0 = Devel|x64
{47AFDBEF-F15F-4BC0-B436-5BE443C3F80F}.Devel|x64.ActiveCfg = Devel|x64
{47AFDBEF-F15F-4BC0-B436-5BE443C3F80F}.Devel|x64.Build.0 = Devel|x64
{47AFDBEF-F15F-4BC0-B436-5BE443C3F80F}.Release AVX2|x64.ActiveCfg = Release|x64
{47AFDBEF-F15F-4BC0-B436-5BE443C3F80F}.Release AVX2|x64.Build.0 = Release|x64
{47AFDBEF-F15F-4BC0-B436-5BE443C3F80F}.Release|x64.ActiveCfg = Release|x64
{47AFDBEF-F15F-4BC0-B436-5BE443C3F80F}.Release|x64.Build.0 = Release|x64
{A0D2B3AD-1F72-4EE3-8B5C-F2C358DA35F0}.Debug AVX2|x64.ActiveCfg = Debug|x64
{A0D2B3AD-1F72-4EE3-8B5C-F2C358DA35F0}.Debug AVX2|x64.Build.0 = Debug|x64
{A0D2B3AD-1F72-4EE3-8B5C-F2C358DA35F0}.Debug|x64.ActiveCfg = Debug|x64
Expand Down Expand Up @@ -434,7 +420,6 @@ Global
{27F17499-A372-4408-8AFA-4F9F4584FBD3} = {78EBE642-7A4D-4EA7-86BE-5639C6646C38}
{12728250-16EC-4DC6-94D7-E21DD88947F8} = {78EBE642-7A4D-4EA7-86BE-5639C6646C38}
{449AD25E-424A-4714-BABC-68706CDCC33B} = {78EBE642-7A4D-4EA7-86BE-5639C6646C38}
{47AFDBEF-F15F-4BC0-B436-5BE443C3F80F} = {78EBE642-7A4D-4EA7-86BE-5639C6646C38}
{A0D2B3AD-1F72-4EE3-8B5C-F2C358DA35F0} = {78EBE642-7A4D-4EA7-86BE-5639C6646C38}
{ED2F21FD-0A36-4A8F-9B90-E7D92A2ACB63} = {78EBE642-7A4D-4EA7-86BE-5639C6646C38}
{C0293B32-5ACF-40F0-AA6C-E6DA6F3BF33A} = {78EBE642-7A4D-4EA7-86BE-5639C6646C38}
Expand Down
1 change: 1 addition & 0 deletions common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ target_sources(common PRIVATE
HeterogeneousContainers.h
Image.h
LRUCache.h
HeapArray.h
HTTPDownloader.h
MemcpyFast.h
MemorySettingsInterface.h
Expand Down
118 changes: 118 additions & 0 deletions common/HeapArray.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2022 PCSX2 Dev Team
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with PCSX2.
* If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once
#include <algorithm>
#include <cassert>
#include <type_traits>

template <typename T, std::size_t SIZE>
class HeapArray
{
public:
using value_type = T;
using size_type = std::size_t;
using difference_type = std::ptrdiff_t;
using reference = T&;
using const_reference = const T&;
using pointer = T*;
using const_pointer = const T*;
using this_type = HeapArray<T, SIZE>;

HeapArray() { m_data = new T[SIZE]; }

HeapArray(const this_type& copy)
{
m_data = new T[SIZE];
std::copy(copy.cbegin(), copy.cend(), begin());
}

HeapArray(this_type&& move)
{
m_data = move.m_data;
move.m_data = nullptr;
}

~HeapArray() { delete[] m_data; }

size_type size() const { return SIZE; }
size_type capacity() const { return SIZE; }
bool empty() const { return false; }

pointer begin() { return m_data; }
pointer end() { return m_data + SIZE; }

const_pointer data() const { return m_data; }
pointer data() { return m_data; }

const_pointer cbegin() const { return m_data; }
const_pointer cend() const { return m_data + SIZE; }

const_reference operator[](size_type index) const
{
assert(index < SIZE);
return m_data[index];
}
reference operator[](size_type index)
{
assert(index < SIZE);
return m_data[index];
}

const_reference front() const { return m_data[0]; }
const_reference back() const { return m_data[SIZE - 1]; }
reference front() { return m_data[0]; }
reference back() { return m_data[SIZE - 1]; }

void fill(const_reference value) { std::fill(begin(), end(), value); }

void swap(this_type& move) { std::swap(m_data, move.m_data); }

this_type& operator=(const this_type& rhs)
{
std::copy(begin(), end(), rhs.cbegin());
return *this;
}

this_type& operator=(this_type&& move)
{
delete[] m_data;
m_data = move.m_data;
move.m_data = nullptr;
return *this;
}

#define RELATIONAL_OPERATOR(op) \
bool operator op(const this_type& rhs) const \
{ \
for (size_type i = 0; i < SIZE; i++) \
{ \
if (!(m_data[i] op rhs.m_data[i])) \
return false; \
} \
}

RELATIONAL_OPERATOR(==);
RELATIONAL_OPERATOR(!=);
RELATIONAL_OPERATOR(<);
RELATIONAL_OPERATOR(<=);
RELATIONAL_OPERATOR(>);
RELATIONAL_OPERATOR(>=);

#undef RELATIONAL_OPERATOR

private:
T* m_data;
};
38 changes: 38 additions & 0 deletions common/StringUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,25 @@ namespace StringUtil

return value;
}
template <typename T, std::enable_if_t<std::is_integral<T>::value, bool> = true>
inline std::optional<T> FromChars(const std::string_view& str, int base, std::string_view* endptr)
{
T value;

const char* ptr = str.data();
const char* end = ptr + str.length();
const std::from_chars_result result = std::from_chars(ptr, end, value, base);
if (result.ec != std::errc())
return std::nullopt;

if (endptr)
{
const size_t remaining_len = end - ptr - 1;
*endptr = (remaining_len > 0) ? std::string_view(result.ptr, remaining_len) : std::string_view();
}

return value;
}

template <typename T, std::enable_if_t<std::is_floating_point<T>::value, bool> = true>
inline std::optional<T> FromChars(const std::string_view& str)
Expand All @@ -100,6 +119,25 @@ namespace StringUtil

return value;
}
template <typename T, std::enable_if_t<std::is_floating_point<T>::value, bool> = true>
inline std::optional<T> FromChars(const std::string_view& str, std::string_view* endptr)
{
T value;

const char* ptr = str.data();
const char* end = ptr + str.length();
const fast_float::from_chars_result result = fast_float::from_chars(ptr, end, value);
if (result.ec != std::errc())
return std::nullopt;

if (endptr)
{
const size_t remaining_len = end - ptr - 1;
*endptr = (remaining_len > 0) ? std::string_view(result.ptr, remaining_len) : std::string_view();
}

return value;
}

/// Wrapper around std::to_chars
template <typename T, std::enable_if_t<std::is_integral<T>::value, bool> = true>
Expand Down
3 changes: 2 additions & 1 deletion common/common.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
<ClInclude Include="GL\StreamBuffer.h" />
<ClInclude Include="FileSystem.h" />
<ClInclude Include="HashCombine.h" />
<ClInclude Include="HeapArray.h" />
<ClInclude Include="HeterogeneousContainers.h" />
<ClInclude Include="Image.h" />
<ClInclude Include="LRUCache.h" />
Expand Down Expand Up @@ -241,4 +242,4 @@
<ImportGroup Label="ExtensionTargets">
<Import Project="$(VCTargetsPath)\BuildCustomizations\masm.targets" />
</ImportGroup>
</Project>
</Project>
5 changes: 4 additions & 1 deletion common/common.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,9 @@
<ClInclude Include="MemorySettingsInterface.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="HeapArray.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="Source Files">
Expand Down Expand Up @@ -529,4 +532,4 @@
<Filter>Source Files</Filter>
</MASM>
</ItemGroup>
</Project>
</Project>
6 changes: 5 additions & 1 deletion pcsx2-gsrunner/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ void Host::OnInputDeviceDisconnected(const std::string_view& identifier)
{
}

void Host::SetRelativeMouseMode(bool enabled)
{
}

bool Host::AcquireHostDisplay(RenderAPI api, bool clear_state_on_fail)
{
const std::optional<WindowInfo> wi(GSRunner::GetPlatformWindowInfo());
Expand Down Expand Up @@ -772,4 +776,4 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
return DefWindowProcW(hwnd, msg, wParam, lParam);
}

#endif // _WIN32
#endif // _WIN32
2 changes: 2 additions & 0 deletions pcsx2-qt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ target_sources(pcsx2-qt PRIVATE
Settings/SettingsDialog.cpp
Settings/SettingsDialog.h
Settings/SettingsDialog.ui
Settings/USBBindingWidget_DrivingForce.ui
Settings/USBBindingWidget_GTForce.ui
Tools/InputRecording/NewInputRecordingDlg.cpp
Tools/InputRecording/NewInputRecordingDlg.h
Tools/InputRecording/NewInputRecordingDlg.ui
Expand Down
35 changes: 17 additions & 18 deletions pcsx2-qt/DisplayWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,31 +84,29 @@ std::optional<WindowInfo> DisplayWidget::getWindowInfo()
return ret;
}

void DisplayWidget::updateRelativeMode(bool master_enable)
void DisplayWidget::updateRelativeMode(bool enabled)
{
bool relative_mode = master_enable && InputManager::HasPointerAxisBinds();

#ifdef _WIN32
// prefer ClipCursor() over warping movement when we're using raw input
bool clip_cursor = relative_mode && false /*InputManager::IsUsingRawInput()*/;
if (m_relative_mouse_enabled == relative_mode && m_clip_mouse_enabled == clip_cursor)
bool clip_cursor = enabled && false /*InputManager::IsUsingRawInput()*/;
if (m_relative_mouse_enabled == enabled && m_clip_mouse_enabled == clip_cursor)
return;

DevCon.WriteLn("updateRelativeMode(): relative=%s, clip=%s", relative_mode ? "yes" : "no", clip_cursor ? "yes" : "no");
DevCon.WriteLn("updateRelativeMode(): relative=%s, clip=%s", enabled ? "yes" : "no", clip_cursor ? "yes" : "no");

if (!clip_cursor && m_clip_mouse_enabled)
{
m_clip_mouse_enabled = false;
ClipCursor(nullptr);
}
#else
if (m_relative_mouse_enabled == relative_mode)
if (m_relative_mouse_enabled == enabled)
return;

DevCon.WriteLn("updateRelativeMode(): relative=%s", relative_mode ? "yes" : "no");
DevCon.WriteLn("updateRelativeMode(): relative=%s", enabled ? "yes" : "no");
#endif

if (relative_mode)
if (enabled)
{
#ifdef _WIN32
m_relative_mouse_enabled = !clip_cursor;
Expand All @@ -129,21 +127,22 @@ void DisplayWidget::updateRelativeMode(bool master_enable)

}

void DisplayWidget::updateCursor(bool master_enable)
void DisplayWidget::updateCursor(bool hidden)
{
#ifdef _WIN32
const bool hide = master_enable && (m_should_hide_cursor || m_relative_mouse_enabled || m_clip_mouse_enabled);
#else
const bool hide = master_enable && (m_should_hide_cursor || m_relative_mouse_enabled);
#endif
if (m_cursor_hidden == hide)
if (m_cursor_hidden == hidden)
return;

m_cursor_hidden = hide;
if (hide)
m_cursor_hidden = hidden;
if (hidden)
{
DevCon.WriteLn("updateCursor(): Cursor is now hidden");
setCursor(Qt::BlankCursor);
}
else
{
DevCon.WriteLn("updateCursor(): Cursor is now shown");
unsetCursor();
}
}

void DisplayWidget::handleCloseEvent(QCloseEvent* event)
Expand Down
7 changes: 2 additions & 5 deletions pcsx2-qt/DisplayWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,13 @@ class DisplayWidget final : public QWidget

QPaintEngine* paintEngine() const override;

__fi void setShouldHideCursor(bool hide) { m_should_hide_cursor = hide; }

int scaledWindowWidth() const;
int scaledWindowHeight() const;

std::optional<WindowInfo> getWindowInfo();

void updateRelativeMode(bool master_enable);
void updateCursor(bool master_enable);
void updateRelativeMode(bool enabled);
void updateCursor(bool hidden);

void handleCloseEvent(QCloseEvent* event);

Expand All @@ -60,7 +58,6 @@ class DisplayWidget final : public QWidget
#ifdef _WIN32
bool m_clip_mouse_enabled = false;
#endif
bool m_should_hide_cursor = false;
bool m_cursor_hidden = false;

std::vector<int> m_keys_pressed_with_modifiers;
Expand Down
Loading