Emu: some cleanup

This commit is contained in:
Megamouse 2021-04-07 23:05:18 +02:00
parent a3e8a61547
commit 03b76b4606
149 changed files with 957 additions and 1139 deletions

View file

@ -1,6 +1,5 @@
#include "stdafx.h" #include "stdafx.h"
#include "aes.h" #include "aes.h"
#include "sha1.h"
#include "utils.h" #include "utils.h"
#include "unself.h" #include "unself.h"
#include "Emu/VFS.h" #include "Emu/VFS.h"

View file

@ -16,7 +16,6 @@
#include "Utilities/StrUtil.h" #include "Utilities/StrUtil.h"
#include "Utilities/span.h" #include "Utilities/span.h"
#include <thread>
#include <mutex> #include <mutex>
#include <algorithm> #include <algorithm>

View file

@ -21,7 +21,6 @@
#include "lv2/sys_prx.h" #include "lv2/sys_prx.h"
#include "lv2/sys_overlay.h" #include "lv2/sys_overlay.h"
#include "lv2/sys_process.h" #include "lv2/sys_process.h"
#include "lv2/sys_memory.h"
#ifdef LLVM_AVAILABLE #ifdef LLVM_AVAILABLE
#ifdef _MSC_VER #ifdef _MSC_VER
@ -37,28 +36,14 @@
#pragma GCC diagnostic ignored "-Wmissing-noreturn" #pragma GCC diagnostic ignored "-Wmissing-noreturn"
#endif #endif
#include "llvm/Support/FormattedStream.h" #include "llvm/Support/FormattedStream.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Host.h" #include "llvm/Support/Host.h"
#include "llvm/Object/ObjectFile.h" #include "llvm/Object/ObjectFile.h"
#include "llvm/ADT/Triple.h" #include "llvm/ADT/Triple.h"
#include "llvm/IR/LLVMContext.h"
//#include "llvm/IR/Dominators.h"
#include "llvm/IR/Verifier.h" #include "llvm/IR/Verifier.h"
#include "llvm/IR/InstIterator.h" #include "llvm/IR/InstIterator.h"
#include "llvm/IR/LegacyPassManager.h" #include "llvm/IR/LegacyPassManager.h"
//#include "llvm/IR/Module.h"
//#include "llvm/IR/Function.h"
//#include "llvm/Analysis/Passes.h"
//#include "llvm/Analysis/BasicAliasAnalysis.h"
//#include "llvm/Analysis/TargetTransformInfo.h"
//#include "llvm/Analysis/MemoryDependenceAnalysis.h"
//#include "llvm/Analysis/LoopInfo.h"
//#include "llvm/Analysis/ScalarEvolution.h"
#include "llvm/Analysis/Lint.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h" #include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Scalar.h" #include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/IPO.h"
#include "llvm/Transforms/Vectorize.h"
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(pop) #pragma warning(pop)
#else #else
@ -3014,7 +2999,7 @@ bool ppu_initialize(const ppu_module& info, bool check_only)
// Create worker threads for compilation (TODO: how many threads) // Create worker threads for compilation (TODO: how many threads)
{ {
u32 thread_count = Emu.GetMaxThreads(); u32 thread_count = Emulator::GetMaxThreads();
if (workload.size() < thread_count) if (workload.size() < thread_count)
{ {

View file

@ -425,7 +425,7 @@ void spu_cache::initialize()
g_progr_ptotal += ::size32(func_list); g_progr_ptotal += ::size32(func_list);
progr.emplace("Building SPU cache..."); progr.emplace("Building SPU cache...");
worker_count = Emu.GetMaxThreads(); worker_count = Emulator::GetMaxThreads();
} }
named_thread_group workers("SPU Worker ", worker_count, [&]() -> uint named_thread_group workers("SPU Worker ", worker_count, [&]() -> uint

View file

@ -7,19 +7,14 @@
#include "Emu/Cell/ErrorCodes.h" #include "Emu/Cell/ErrorCodes.h"
#include "Emu/Cell/PPUThread.h" #include "Emu/Cell/PPUThread.h"
#include "Emu/Cell/PPUCallback.h"
#include "Emu/Cell/PPUOpcodes.h"
#include "Emu/Cell/PPUDisAsm.h" #include "Emu/Cell/PPUDisAsm.h"
#include "Emu/Cell/PPUAnalyser.h" #include "Emu/Cell/PPUAnalyser.h"
#include "Emu/Cell/SPUThread.h" #include "Emu/Cell/SPUThread.h"
#include "Emu/Cell/RawSPUThread.h"
#include "Emu/RSX/RSXThread.h" #include "Emu/RSX/RSXThread.h"
#include "Emu/Cell/lv2/sys_process.h" #include "Emu/Cell/lv2/sys_process.h"
#include "Emu/Cell/lv2/sys_memory.h"
#include "Emu/Cell/lv2/sys_sync.h" #include "Emu/Cell/lv2/sys_sync.h"
#include "Emu/Cell/lv2/sys_prx.h" #include "Emu/Cell/lv2/sys_prx.h"
#include "Emu/Cell/lv2/sys_overlay.h" #include "Emu/Cell/lv2/sys_overlay.h"
#include "Emu/Cell/lv2/sys_rsx.h"
#include "Emu/Cell/Modules/cellMsgDialog.h" #include "Emu/Cell/Modules/cellMsgDialog.h"
#include "Emu/title.h" #include "Emu/title.h"
@ -40,7 +35,6 @@
#include "util/cereal.hpp" #include "util/cereal.hpp"
#include <thread> #include <thread>
#include <queue>
#include <fstream> #include <fstream>
#include <memory> #include <memory>
#include <regex> #include <regex>
@ -558,7 +552,7 @@ void Emulator::SetUsr(const std::string& user)
std::string Emulator::GetBackgroundPicturePath() const std::string Emulator::GetBackgroundPicturePath() const
{ {
// Try to find a custom icon first // Try to find a custom icon first
std::string path = fs::get_config_dir() + "/Icons/game_icons/" + Emu.GetTitleID() + "/PIC1.PNG"; std::string path = fs::get_config_dir() + "/Icons/game_icons/" + GetTitleID() + "/PIC1.PNG";
if (fs::is_file(path)) if (fs::is_file(path))
{ {
@ -646,8 +640,8 @@ bool Emulator::BootRsxCapture(const std::string& path)
m_state = system_state::ready; m_state = system_state::ready;
GetCallbacks().on_ready(); GetCallbacks().on_ready();
Emu.GetCallbacks().init_gs_render(); GetCallbacks().init_gs_render();
Emu.GetCallbacks().init_pad_handler(""); GetCallbacks().init_pad_handler("");
GetCallbacks().on_run(false); GetCallbacks().on_run(false);
m_state = system_state::running; m_state = system_state::running;
@ -661,7 +655,7 @@ bool Emulator::BootRsxCapture(const std::string& path)
void Emulator::LimitCacheSize() void Emulator::LimitCacheSize()
{ {
const std::string cache_location = Emulator::GetHdd1Dir() + "/caches"; const std::string cache_location = GetHdd1Dir() + "/caches";
if (!fs::is_dir(cache_location)) if (!fs::is_dir(cache_location))
{ {
@ -877,7 +871,7 @@ std::string Emulator::GetExeDir()
} }
#endif #endif
std::string Emulator::GetSfoDirFromGamePath(const std::string& game_path, const std::string& user, const std::string& title_id) std::string Emulator::GetSfoDirFromGamePath(const std::string& game_path, const std::string& title_id)
{ {
if (fs::is_file(game_path + "/PS3_DISC.SFB")) if (fs::is_file(game_path + "/PS3_DISC.SFB"))
{ {
@ -1042,7 +1036,7 @@ game_boot_result Emulator::Load(const std::string& title_id, bool add_only, bool
if (fs::is_dir(m_path)) if (fs::is_dir(m_path))
{ {
// Special case (directory scan) // Special case (directory scan)
m_sfo_dir = GetSfoDirFromGamePath(m_path, GetUsr(), m_title_id); m_sfo_dir = GetSfoDirFromGamePath(m_path, m_title_id);
} }
else if (!disc.empty()) else if (!disc.empty())
{ {
@ -1057,12 +1051,12 @@ game_boot_result Emulator::Load(const std::string& title_id, bool add_only, bool
} }
else else
{ {
m_sfo_dir = GetSfoDirFromGamePath(disc, GetUsr(), m_title_id); m_sfo_dir = GetSfoDirFromGamePath(disc, m_title_id);
} }
} }
else else
{ {
m_sfo_dir = GetSfoDirFromGamePath(elf_dir + "/../", GetUsr(), m_title_id); m_sfo_dir = GetSfoDirFromGamePath(elf_dir + "/../", m_title_id);
} }
_psf = psf::load_object(fs::file(m_sfo_dir + "/PARAM.SFO")); _psf = psf::load_object(fs::file(m_sfo_dir + "/PARAM.SFO"));
@ -1268,7 +1262,7 @@ game_boot_result Emulator::Load(const std::string& title_id, bool add_only, bool
ensure(vm::falloc(0x10000, 0xf0000, vm::main)); ensure(vm::falloc(0x10000, 0xf0000, vm::main));
} }
if (Emu.IsStopped()) if (IsStopped())
{ {
return; return;
} }
@ -1276,7 +1270,7 @@ game_boot_result Emulator::Load(const std::string& title_id, bool add_only, bool
ppu_precompile(dir_queue, nullptr); ppu_precompile(dir_queue, nullptr);
// Exit "process" // Exit "process"
Emu.CallAfter([] CallAfter([]
{ {
Emu.SetForceBoot(true); Emu.SetForceBoot(true);
Emu.Stop(); Emu.Stop();
@ -1336,12 +1330,10 @@ game_boot_result Emulator::Load(const std::string& title_id, bool add_only, bool
sys_log.success("Disc game %s moved to special location /dev_hdd0/disc/", m_title_id); sys_log.success("Disc game %s moved to special location /dev_hdd0/disc/", m_title_id);
return m_path = hdd0_disc + m_path.substr(hdd0_game.size()), Load(m_title_id, add_only, force_global_config); return m_path = hdd0_disc + m_path.substr(hdd0_game.size()), Load(m_title_id, add_only, force_global_config);
} }
else
{
sys_log.error("Failed to move disc game %s to /dev_hdd0/disc/ (%s)", m_title_id, fs::g_tls_error); sys_log.error("Failed to move disc game %s to /dev_hdd0/disc/ (%s)", m_title_id, fs::g_tls_error);
return game_boot_result::wrong_disc_location; return game_boot_result::wrong_disc_location;
} }
}
bdvd_dir = sfb_dir + "/"; bdvd_dir = sfb_dir + "/";
@ -1739,10 +1731,10 @@ game_boot_result Emulator::Load(const std::string& title_id, bool add_only, bool
ConfigurePPUCache(); ConfigurePPUCache();
g_fxo->init(false); g_fxo->init(false);
Emu.GetCallbacks().init_gs_render(); GetCallbacks().init_gs_render();
Emu.GetCallbacks().init_pad_handler(m_title_id); GetCallbacks().init_pad_handler(m_title_id);
Emu.GetCallbacks().init_kb_handler(); GetCallbacks().init_kb_handler();
Emu.GetCallbacks().init_mouse_handler(); GetCallbacks().init_mouse_handler();
} }
// Overlay (OVL) executable (only load it) // Overlay (OVL) executable (only load it)
else if (vm::map(0x3000'0000, 0x1000'0000, 0x200); !ppu_load_overlay(ppu_exec, m_path).first) else if (vm::map(0x3000'0000, 0x1000'0000, 0x200); !ppu_load_overlay(ppu_exec, m_path).first)
@ -2140,7 +2132,7 @@ std::string Emulator::GetFormattedTitle(double fps) const
return rpcs3::get_formatted_title(title_data); return rpcs3::get_formatted_title(title_data);
} }
u32 Emulator::GetMaxThreads() const u32 Emulator::GetMaxThreads()
{ {
const u32 max_threads = static_cast<u32>(g_cfg.core.llvm_threads); const u32 max_threads = static_cast<u32>(g_cfg.core.llvm_threads);
const u32 hw_threads = utils::get_thread_count(); const u32 hw_threads = utils::get_thread_count();
@ -2239,7 +2231,7 @@ void Emulator::ConfigurePPUCache()
if (!m_title_id.empty() && m_cat != "1P") if (!m_title_id.empty() && m_cat != "1P")
{ {
_main.cache += Emu.GetTitleID(); _main.cache += GetTitleID();
_main.cache += '/'; _main.cache += '/';
} }

View file

@ -220,7 +220,7 @@ public:
game_boot_result BootGame(const std::string& path, const std::string& title_id = "", bool direct = false, bool add_only = false, bool force_global_config = false); game_boot_result BootGame(const std::string& path, const std::string& title_id = "", bool direct = false, bool add_only = false, bool force_global_config = false);
bool BootRsxCapture(const std::string& path); bool BootRsxCapture(const std::string& path);
bool InstallPkg(const std::string& path); static bool InstallPkg(const std::string& path);
#ifdef _WIN32 #ifdef _WIN32
static std::string GetExeDir(); static std::string GetExeDir();
@ -230,7 +230,7 @@ public:
static std::string GetHddDir(); static std::string GetHddDir();
static std::string GetHdd1Dir(); static std::string GetHdd1Dir();
static std::string GetCacheDir(); static std::string GetCacheDir();
static std::string GetSfoDirFromGamePath(const std::string& game_path, const std::string& user, const std::string& title_id = ""); static std::string GetSfoDirFromGamePath(const std::string& game_path, const std::string& title_id = "");
static std::string GetRapFilePath(const std::string& rap); static std::string GetRapFilePath(const std::string& rap);
static std::string GetCustomConfigDir(); static std::string GetCustomConfigDir();
@ -264,15 +264,15 @@ public:
std::string GetFormattedTitle(double fps) const; std::string GetFormattedTitle(double fps) const;
u32 GetMaxThreads() const; static u32 GetMaxThreads();
void ConfigureLogs(); static void ConfigureLogs();
void ConfigurePPUCache(); void ConfigurePPUCache();
std::set<std::string> GetGameDirs() const; std::set<std::string> GetGameDirs() const;
private: private:
void LimitCacheSize(); static void LimitCacheSize();
}; };
extern Emulator Emu; extern Emulator Emu;

View file

@ -15,7 +15,7 @@ void basic_keyboard_handler::Init(const u32 max_connect)
{ {
for (u32 i = 0; i < max_connect; i++) for (u32 i = 0; i < max_connect; i++)
{ {
Keyboard kb = Keyboard(); Keyboard kb;
kb.m_config.arrange = g_cfg.sys.keyboard_type; kb.m_config.arrange = g_cfg.sys.keyboard_type;
@ -51,24 +51,24 @@ void basic_keyboard_handler::SetTargetWindow(QWindow* target)
} }
} }
bool basic_keyboard_handler::eventFilter(QObject* target, QEvent* ev) bool basic_keyboard_handler::eventFilter(QObject* watched, QEvent* event)
{ {
if (!ev || input::g_intercepted) if (!event || input::g_intercepted)
{ {
return false; return false;
} }
// !m_target is for future proofing when gsrender isn't automatically initialized on load. // !m_target is for future proofing when gsrender isn't automatically initialized on load.
// !m_target->isVisible() is a hack since currently a guiless application will STILL inititialize a gsrender (providing a valid target) // !m_target->isVisible() is a hack since currently a guiless application will STILL inititialize a gsrender (providing a valid target)
if (!m_target || !m_target->isVisible() || target == m_target) if (!m_target || !m_target->isVisible() || watched == m_target)
{ {
if (ev->type() == QEvent::KeyPress) if (event->type() == QEvent::KeyPress)
{ {
keyPressEvent(static_cast<QKeyEvent*>(ev)); keyPressEvent(static_cast<QKeyEvent*>(event));
} }
else if (ev->type() == QEvent::KeyRelease) else if (event->type() == QEvent::KeyRelease)
{ {
keyReleaseEvent(static_cast<QKeyEvent*>(ev)); keyReleaseEvent(static_cast<QKeyEvent*>(event));
} }
} }
return false; return false;
@ -137,7 +137,7 @@ s32 basic_keyboard_handler::getUnmodifiedKey(QKeyEvent* keyEvent)
#ifdef _WIN32 #ifdef _WIN32
if (keyEvent->modifiers() != Qt::NoModifier && !keyEvent->text().isEmpty()) if (keyEvent->modifiers() != Qt::NoModifier && !keyEvent->text().isEmpty())
{ {
u32 mapped_key = (u32)MapVirtualKeyA((UINT)keyEvent->nativeVirtualKey(), MAPVK_VK_TO_CHAR); u32 mapped_key = static_cast<u32>(MapVirtualKeyA(static_cast<UINT>(keyEvent->nativeVirtualKey()), MAPVK_VK_TO_CHAR));
if (raw_key != mapped_key) if (raw_key != mapped_key)
{ {

View file

@ -9,15 +9,15 @@
class basic_keyboard_handler final : public KeyboardHandlerBase, public QObject class basic_keyboard_handler final : public KeyboardHandlerBase, public QObject
{ {
public: public:
virtual void Init(const u32 max_connect) override; void Init(const u32 max_connect) override;
explicit basic_keyboard_handler(); explicit basic_keyboard_handler();
void SetTargetWindow(QWindow* target); void SetTargetWindow(QWindow* target);
bool eventFilter(QObject* obj, QEvent* ev) override; bool eventFilter(QObject* watched, QEvent* event) override;
void keyPressEvent(QKeyEvent* event); void keyPressEvent(QKeyEvent* event);
void keyReleaseEvent(QKeyEvent* event); void keyReleaseEvent(QKeyEvent* event);
s32 getUnmodifiedKey(QKeyEvent* event); static s32 getUnmodifiedKey(QKeyEvent* event);
void LoadSettings(); void LoadSettings();
private: private:
QWindow* m_target = nullptr; QWindow* m_target = nullptr;

View file

@ -82,16 +82,16 @@ bool basic_mouse_handler::eventFilter(QObject* target, QEvent* ev)
void basic_mouse_handler::MouseButtonDown(QMouseEvent* event) void basic_mouse_handler::MouseButtonDown(QMouseEvent* event)
{ {
if (event->button() == Qt::LeftButton) MouseHandlerBase::Button(CELL_MOUSE_BUTTON_1, 1); if (event->button() == Qt::LeftButton) MouseHandlerBase::Button(CELL_MOUSE_BUTTON_1, true);
else if (event->button() == Qt::RightButton) MouseHandlerBase::Button(CELL_MOUSE_BUTTON_2, 1); else if (event->button() == Qt::RightButton) MouseHandlerBase::Button(CELL_MOUSE_BUTTON_2, true);
else if (event->button() == Qt::MiddleButton) MouseHandlerBase::Button(CELL_MOUSE_BUTTON_3, 1); else if (event->button() == Qt::MiddleButton) MouseHandlerBase::Button(CELL_MOUSE_BUTTON_3, true);
} }
void basic_mouse_handler::MouseButtonUp(QMouseEvent* event) void basic_mouse_handler::MouseButtonUp(QMouseEvent* event)
{ {
if (event->button() == Qt::LeftButton) MouseHandlerBase::Button(CELL_MOUSE_BUTTON_1, 0); if (event->button() == Qt::LeftButton) MouseHandlerBase::Button(CELL_MOUSE_BUTTON_1, false);
else if (event->button() == Qt::RightButton) MouseHandlerBase::Button(CELL_MOUSE_BUTTON_2, 0); else if (event->button() == Qt::RightButton) MouseHandlerBase::Button(CELL_MOUSE_BUTTON_2, false);
else if (event->button() == Qt::MiddleButton) MouseHandlerBase::Button(CELL_MOUSE_BUTTON_3, 0); else if (event->button() == Qt::MiddleButton) MouseHandlerBase::Button(CELL_MOUSE_BUTTON_3, false);
} }
void basic_mouse_handler::MouseScroll(QWheelEvent* event) void basic_mouse_handler::MouseScroll(QWheelEvent* event)
@ -99,7 +99,7 @@ void basic_mouse_handler::MouseScroll(QWheelEvent* event)
MouseHandlerBase::Scroll(event->angleDelta().y()); MouseHandlerBase::Scroll(event->angleDelta().y());
} }
bool basic_mouse_handler::get_mouse_lock_state() bool basic_mouse_handler::get_mouse_lock_state() const
{ {
if (auto game_frame = dynamic_cast<gs_frame*>(m_target)) if (auto game_frame = dynamic_cast<gs_frame*>(m_target))
return game_frame->get_mouse_lock_state(); return game_frame->get_mouse_lock_state();

View file

@ -10,7 +10,7 @@
class basic_mouse_handler final : public MouseHandlerBase, public QObject class basic_mouse_handler final : public MouseHandlerBase, public QObject
{ {
public: public:
virtual void Init(const u32 max_connect) override; void Init(const u32 max_connect) override;
basic_mouse_handler(); basic_mouse_handler();
@ -23,5 +23,5 @@ public:
bool eventFilter(QObject* obj, QEvent* ev) override; bool eventFilter(QObject* obj, QEvent* ev) override;
private: private:
QWindow* m_target = nullptr; QWindow* m_target = nullptr;
bool get_mouse_lock_state(); bool get_mouse_lock_state() const;
}; };

View file

@ -109,7 +109,7 @@ ds3_pad_handler::~ds3_pad_handler()
u32 ds3_pad_handler::get_battery_level(const std::string& padId) u32 ds3_pad_handler::get_battery_level(const std::string& padId)
{ {
std::shared_ptr<ds3_device> device = get_hid_device(padId); const std::shared_ptr<ds3_device> device = get_hid_device(padId);
if (!device || !device->hidDevice) if (!device || !device->hidDevice)
{ {
return 0; return 0;

View file

@ -186,7 +186,7 @@ void ds4_pad_handler::init_config(pad_config* cfg, const std::string& name)
u32 ds4_pad_handler::get_battery_level(const std::string& padId) u32 ds4_pad_handler::get_battery_level(const std::string& padId)
{ {
std::shared_ptr<DS4Device> device = get_hid_device(padId); const std::shared_ptr<DS4Device> device = get_hid_device(padId);
if (device == nullptr || device->hidDevice == nullptr) if (device == nullptr || device->hidDevice == nullptr)
{ {
return 0; return 0;
@ -266,7 +266,7 @@ std::unordered_map<u64, u16> ds4_pad_handler::get_button_values(const std::share
keyBuffer[DS4KeyCodes::RSYPos] = Clamp0To255((127.5f - buf[4]) * 2.0f); keyBuffer[DS4KeyCodes::RSYPos] = Clamp0To255((127.5f - buf[4]) * 2.0f);
// bleh, dpad in buffer is stored in a different state // bleh, dpad in buffer is stored in a different state
u8 dpadState = buf[5] & 0xf; const u8 dpadState = buf[5] & 0xf;
switch (dpadState) switch (dpadState)
{ {
case 0x08: // none pressed case 0x08: // none pressed
@ -366,7 +366,7 @@ pad_preview_values ds4_pad_handler::get_preview_values(const std::unordered_map<
}; };
} }
bool ds4_pad_handler::GetCalibrationData(DS4Device* ds4Dev) bool ds4_pad_handler::GetCalibrationData(DS4Device* ds4Dev) const
{ {
if (!ds4Dev || !ds4Dev->hidDevice) if (!ds4Dev || !ds4Dev->hidDevice)
{ {
@ -601,7 +601,7 @@ int ds4_pad_handler::send_output_report(DS4Device* device)
if (!device || !device->hidDevice) if (!device || !device->hidDevice)
return -2; return -2;
auto config = device->config; const auto config = device->config;
if (config == nullptr) if (config == nullptr)
return -2; // hid_write and hid_write_control return -1 on error return -2; // hid_write and hid_write_control return -1 on error
@ -682,7 +682,7 @@ ds4_pad_handler::DataStatus ds4_pad_handler::get_data(DS4Device* device)
return DataStatus::NoNewData; return DataStatus::NoNewData;
} }
int offset = 0; int offset;
// check report and set offset // check report and set offset
if (device->bt_controller && buf[0] == 0x11 && res == 78) if (device->bt_controller && buf[0] == 0x11 && res == 78)
{ {

View file

@ -1,7 +1,6 @@
#pragma once #pragma once
#include "hid_pad_handler.h" #include "hid_pad_handler.h"
#include "Utilities/CRC.h"
#include <unordered_map> #include <unordered_map>
@ -63,7 +62,7 @@ public:
private: private:
// This function gets us usuable buffer from the rawbuffer of padData // This function gets us usuable buffer from the rawbuffer of padData
bool GetCalibrationData(DS4Device* ds4Device); bool GetCalibrationData(DS4Device* ds4Device) const;
// Copies data into padData if status is NewData, otherwise buffer is untouched // Copies data into padData if status is NewData, otherwise buffer is untouched
DataStatus get_data(DS4Device* ds4Device) override; DataStatus get_data(DS4Device* ds4Device) override;

View file

@ -398,7 +398,7 @@ dualsense_pad_handler::DataStatus dualsense_pad_handler::get_data(DualSenseDevic
return DataStatus::NewData; return DataStatus::NewData;
} }
bool dualsense_pad_handler::get_calibration_data(DualSenseDevice* dualsense_device) bool dualsense_pad_handler::get_calibration_data(DualSenseDevice* dualsense_device) const
{ {
if (!dualsense_device || !dualsense_device->hidDevice) if (!dualsense_device || !dualsense_device->hidDevice)
{ {
@ -899,7 +899,7 @@ int dualsense_pad_handler::send_output_report(DualSenseDevice* device)
if (!device || !device->hidDevice) if (!device || !device->hidDevice)
return -2; return -2;
auto config = device->config; const auto config = device->config;
if (config == nullptr) if (config == nullptr)
return -2; // hid_write and hid_write_control return -1 on error return -2; // hid_write and hid_write_control return -1 on error
@ -976,7 +976,7 @@ int dualsense_pad_handler::send_output_report(DualSenseDevice* device)
report.report_id = 0x31; // report id for bluetooth report.report_id = 0x31; // report id for bluetooth
report.seq_tag = seq_tag; report.seq_tag = seq_tag;
report.tag = 0x10; // magic number report.tag = 0x10; // magic number
report.common = std::move(common); report.common = common;
const u8 btHdr = 0xA2; const u8 btHdr = 0xA2;
const u32 crcHdr = CRCPP::CRC::Calculate(&btHdr, 1, crcTable); const u32 crcHdr = CRCPP::CRC::Calculate(&btHdr, 1, crcTable);
@ -993,7 +993,7 @@ int dualsense_pad_handler::send_output_report(DualSenseDevice* device)
{ {
output_report_usb report{}; output_report_usb report{};
report.report_id = 0x02; // report id for usb report.report_id = 0x02; // report id for usb
report.common = std::move(common); report.common = common;
return hid_write(device->hidDevice, &report.report_id, DUALSENSE_USB_REPORT_SIZE); return hid_write(device->hidDevice, &report.report_id, DUALSENSE_USB_REPORT_SIZE);
} }
@ -1040,7 +1040,7 @@ void dualsense_pad_handler::apply_pad_data(const std::shared_ptr<PadDevice>& dev
// Turn lightbar on and off in an interval. I wanted to do an automatic pulse, but I haven't found out how to do that yet. // Turn lightbar on and off in an interval. I wanted to do an automatic pulse, but I haven't found out how to do that yet.
if (dualsense_dev->led_delay_on > 0) if (dualsense_dev->led_delay_on > 0)
{ {
if (steady_clock::time_point now = steady_clock::now(); (now - dualsense_dev->last_lightbar_time) > 500ms) if (const steady_clock::time_point now = steady_clock::now(); (now - dualsense_dev->last_lightbar_time) > 500ms)
{ {
dualsense_dev->lightbar_on = !dualsense_dev->lightbar_on; dualsense_dev->lightbar_on = !dualsense_dev->lightbar_on;
dualsense_dev->last_lightbar_time = now; dualsense_dev->last_lightbar_time = now;
@ -1138,7 +1138,7 @@ void dualsense_pad_handler::SetPadData(const std::string& padId, u32 largeMotor,
u32 dualsense_pad_handler::get_battery_level(const std::string& padId) u32 dualsense_pad_handler::get_battery_level(const std::string& padId)
{ {
std::shared_ptr<DualSenseDevice> device = get_hid_device(padId); const std::shared_ptr<DualSenseDevice> device = get_hid_device(padId);
if (device == nullptr || device->hidDevice == nullptr) if (device == nullptr || device->hidDevice == nullptr)
{ {
return 0; return 0;

View file

@ -1,7 +1,6 @@
#pragma once #pragma once
#include "hid_pad_handler.h" #include "hid_pad_handler.h"
#include "Utilities/CRC.h"
#include <unordered_map> #include <unordered_map>
@ -75,9 +74,9 @@ public:
void init_config(pad_config* cfg, const std::string& name) override; void init_config(pad_config* cfg, const std::string& name) override;
private: private:
bool get_calibration_data(DualSenseDevice* dualsense_device); bool get_calibration_data(DualSenseDevice* dualsense_device) const;
DataStatus get_data(DualSenseDevice* dualsenseDevice) override; DataStatus get_data(DualSenseDevice* device) override;
void check_add_device(hid_device* hidDevice, std::string_view path, std::wstring_view wide_serial) override; void check_add_device(hid_device* hidDevice, std::string_view path, std::wstring_view wide_serial) override;
int send_output_report(DualSenseDevice* device) override; int send_output_report(DualSenseDevice* device) override;

View file

@ -204,7 +204,7 @@ std::shared_ptr<PadDevice> hid_pad_handler<Device>::get_device(const std::string
} }
template <class Device> template <class Device>
u32 hid_pad_handler<Device>::get_battery_color(u8 battery_level, int brightness) const u32 hid_pad_handler<Device>::get_battery_color(u8 battery_level, int brightness)
{ {
static const std::array<u32, 12> battery_level_clr = {0xff00, 0xff33, 0xff66, 0xff99, 0xffcc, 0xffff, 0xccff, 0x99ff, 0x66ff, 0x33ff, 0x00ff, 0x00ff}; static const std::array<u32, 12> battery_level_clr = {0xff00, 0xff33, 0xff66, 0xff99, 0xffcc, 0xffff, 0xccff, 0x99ff, 0x66ff, 0x33ff, 0x00ff, 0x00ff};

View file

@ -82,7 +82,7 @@ protected:
virtual int send_output_report(Device* device) = 0; virtual int send_output_report(Device* device) = 0;
virtual DataStatus get_data(Device* device) = 0; virtual DataStatus get_data(Device* device) = 0;
inline s16 apply_calibration(s32 rawValue, const CalibData& calibData) static s16 apply_calibration(s32 rawValue, const CalibData& calibData)
{ {
const s32 biased = rawValue - calibData.bias; const s32 biased = rawValue - calibData.bias;
const s32 quot = calibData.sens_numer / calibData.sens_denom; const s32 quot = calibData.sens_numer / calibData.sens_denom;
@ -92,17 +92,17 @@ protected:
return static_cast<s16>(std::clamp<s32>(output, INT16_MIN, INT16_MAX)); return static_cast<s16>(std::clamp<s32>(output, INT16_MIN, INT16_MAX));
} }
inline s16 read_s16(const void* buf) static s16 read_s16(const void* buf)
{ {
return *reinterpret_cast<const s16*>(buf); return *static_cast<const s16*>(buf);
} }
inline u32 read_u32(const void* buf) static u32 read_u32(const void* buf)
{ {
return *reinterpret_cast<const u32*>(buf); return *static_cast<const u32*>(buf);
} }
u32 get_battery_color(u8 battery_level, int brightness) const; static u32 get_battery_color(u8 battery_level, int brightness);
private: private:
std::shared_ptr<PadDevice> get_device(const std::string& device) override; std::shared_ptr<PadDevice> get_device(const std::string& device) override;

View file

@ -78,7 +78,7 @@ void keyboard_pad_handler::Key(const u32 code, bool pressed, u16 value)
value = Clamp0To255(value); value = Clamp0To255(value);
for (auto pad : bindings) for (const auto& pad : m_bindings)
{ {
for (Button& button : pad->m_buttons) for (Button& button : pad->m_buttons)
{ {
@ -316,7 +316,7 @@ void keyboard_pad_handler::mouseReleaseEvent(QMouseEvent* event)
event->ignore(); event->ignore();
} }
bool keyboard_pad_handler::get_mouse_lock_state() bool keyboard_pad_handler::get_mouse_lock_state() const
{ {
if (auto game_frame = dynamic_cast<gs_frame*>(m_target)) if (auto game_frame = dynamic_cast<gs_frame*>(m_target))
return game_frame->get_mouse_lock_state(); return game_frame->get_mouse_lock_state();
@ -388,7 +388,7 @@ void keyboard_pad_handler::mouseMoveEvent(QMouseEvent* event)
const double a = m_deadzone_x; const double a = m_deadzone_x;
const double b = m_deadzone_y; const double b = m_deadzone_y;
const double m = double(movement_y) / double(movement_x); const double m = static_cast<double>(movement_y) / static_cast<double>(movement_x);
deadzone_x = a * b / std::sqrt(std::pow(a, 2) * std::pow(m, 2) + std::pow(b, 2)); deadzone_x = a * b / std::sqrt(std::pow(a, 2) * std::pow(m, 2) + std::pow(b, 2));
deadzone_y = std::abs(m * deadzone_x); deadzone_y = std::abs(m * deadzone_x);
@ -473,14 +473,14 @@ std::vector<std::string> keyboard_pad_handler::ListDevices()
return list_devices; return list_devices;
} }
std::string keyboard_pad_handler::GetMouseName(const QMouseEvent* event) std::string keyboard_pad_handler::GetMouseName(const QMouseEvent* event) const
{ {
return GetMouseName(event->button()); return GetMouseName(event->button());
} }
std::string keyboard_pad_handler::GetMouseName(u32 button) std::string keyboard_pad_handler::GetMouseName(u32 button) const
{ {
if (auto it = mouse_list.find(button); it != mouse_list.end()) if (const auto it = mouse_list.find(button); it != mouse_list.cend())
return it->second; return it->second;
return "FAIL"; return "FAIL";
} }
@ -550,7 +550,7 @@ QStringList keyboard_pad_handler::GetKeyNames(const QKeyEvent* keyEvent)
std::string keyboard_pad_handler::GetKeyName(const QKeyEvent* keyEvent) std::string keyboard_pad_handler::GetKeyName(const QKeyEvent* keyEvent)
{ {
// Handle special cases first // Handle special cases first
if (const std::string name = native_scan_code_to_string(keyEvent->nativeScanCode()); !name.empty()) if (std::string name = native_scan_code_to_string(keyEvent->nativeScanCode()); !name.empty())
{ {
return name; return name;
} }
@ -602,7 +602,7 @@ u32 keyboard_pad_handler::GetKeyCode(const QString& keyName)
else if (keyName == "Meta") else if (keyName == "Meta")
return Qt::Key_Meta; return Qt::Key_Meta;
QKeySequence seq(keyName); const QKeySequence seq(keyName);
u32 key_code = 0; u32 key_code = 0;
if (seq.count() == 1) if (seq.count() == 1)
@ -660,7 +660,7 @@ bool keyboard_pad_handler::bindPadToDevice(std::shared_ptr<Pad> pad, const std::
if (device != pad::keyboard_device_name) if (device != pad::keyboard_device_name)
return false; return false;
const int index = static_cast<int>(bindings.size()); const int index = static_cast<int>(m_bindings.size());
m_pad_configs[index].load(); m_pad_configs[index].load();
pad_config* p_profile = &m_pad_configs[index]; pad_config* p_profile = &m_pad_configs[index];
if (p_profile == nullptr) if (p_profile == nullptr)
@ -742,7 +742,7 @@ bool keyboard_pad_handler::bindPadToDevice(std::shared_ptr<Pad> pad, const std::
pad->m_vibrateMotors.emplace_back(true, 0); pad->m_vibrateMotors.emplace_back(true, 0);
pad->m_vibrateMotors.emplace_back(false, 0); pad->m_vibrateMotors.emplace_back(false, 0);
bindings.push_back(pad); m_bindings.push_back(pad);
return true; return true;
} }
@ -806,12 +806,12 @@ void keyboard_pad_handler::ThreadProc()
return (v0 <= v1) ? std::ceil(res) : std::floor(res); return (v0 <= v1) ? std::ceil(res) : std::floor(res);
}; };
for (uint i = 0; i < bindings.size(); i++) for (uint i = 0; i < m_bindings.size(); i++)
{ {
if (last_connection_status[i] == false) if (last_connection_status[i] == false)
{ {
bindings[i]->m_port_status |= CELL_PAD_STATUS_CONNECTED; m_bindings[i]->m_port_status |= CELL_PAD_STATUS_CONNECTED;
bindings[i]->m_port_status |= CELL_PAD_STATUS_ASSIGN_CHANGES; m_bindings[i]->m_port_status |= CELL_PAD_STATUS_ASSIGN_CHANGES;
last_connection_status[i] = true; last_connection_status[i] = true;
connected_devices++; connected_devices++;
} }
@ -819,25 +819,25 @@ void keyboard_pad_handler::ThreadProc()
{ {
if (update_sticks) if (update_sticks)
{ {
for (int j = 0; j < static_cast<int>(bindings[i]->m_sticks.size()); j++) for (int j = 0; j < static_cast<int>(m_bindings[i]->m_sticks.size()); j++)
{ {
const f32 stick_lerp_factor = (j < 2) ? m_l_stick_lerp_factor : m_r_stick_lerp_factor; const f32 stick_lerp_factor = (j < 2) ? m_l_stick_lerp_factor : m_r_stick_lerp_factor;
// we already applied the following values on keypress if we used factor 1 // we already applied the following values on keypress if we used factor 1
if (stick_lerp_factor < 1.0f) if (stick_lerp_factor < 1.0f)
{ {
const f32 v0 = static_cast<f32>(bindings[i]->m_sticks[j].m_value); const f32 v0 = static_cast<f32>(m_bindings[i]->m_sticks[j].m_value);
const f32 v1 = static_cast<f32>(m_stick_val[j]); const f32 v1 = static_cast<f32>(m_stick_val[j]);
const f32 res = get_lerped(v0, v1, stick_lerp_factor); const f32 res = get_lerped(v0, v1, stick_lerp_factor);
bindings[i]->m_sticks[j].m_value = static_cast<u16>(res); m_bindings[i]->m_sticks[j].m_value = static_cast<u16>(res);
} }
} }
} }
if (update_buttons) if (update_buttons)
{ {
for (auto& button : bindings[i]->m_buttons) for (auto& button : m_bindings[i]->m_buttons)
{ {
if (button.m_analog) if (button.m_analog)
{ {

View file

@ -80,21 +80,21 @@ public:
void mouseMoveEvent(QMouseEvent* event); void mouseMoveEvent(QMouseEvent* event);
void mouseWheelEvent(QWheelEvent* event); void mouseWheelEvent(QWheelEvent* event);
bool eventFilter(QObject* obj, QEvent* ev) override; bool eventFilter(QObject* target, QEvent* ev) override;
void init_config(pad_config* cfg, const std::string& name) override; void init_config(pad_config* cfg, const std::string& name) override;
std::vector<std::string> ListDevices() override; std::vector<std::string> ListDevices() override;
void get_next_button_press(const std::string& /*padId*/, const pad_callback& /*callback*/, const pad_fail_callback& /*fail_callback*/, bool /*get_blacklist*/ = false, const std::vector<std::string>& /*buttons*/ = {}) override {}; void get_next_button_press(const std::string& /*padId*/, const pad_callback& /*callback*/, const pad_fail_callback& /*fail_callback*/, bool /*get_blacklist*/ = false, const std::vector<std::string>& /*buttons*/ = {}) override {}
bool bindPadToDevice(std::shared_ptr<Pad> pad, const std::string& device) override; bool bindPadToDevice(std::shared_ptr<Pad> pad, const std::string& device) override;
void ThreadProc() override; void ThreadProc() override;
std::string GetMouseName(const QMouseEvent* event); std::string GetMouseName(const QMouseEvent* event) const;
std::string GetMouseName(u32 button); std::string GetMouseName(u32 button) const;
QStringList GetKeyNames(const QKeyEvent* keyEvent); static QStringList GetKeyNames(const QKeyEvent* keyEvent);
std::string GetKeyName(const QKeyEvent* keyEvent); static std::string GetKeyName(const QKeyEvent* keyEvent);
std::string GetKeyName(const u32& keyCode); static std::string GetKeyName(const u32& keyCode);
u32 GetKeyCode(const std::string& keyName); static u32 GetKeyCode(const std::string& keyName);
u32 GetKeyCode(const QString& keyName); static u32 GetKeyCode(const QString& keyName);
static int native_scan_code_from_string(const std::string& key); static int native_scan_code_from_string(const std::string& key);
static std::string native_scan_code_to_string(int native_scan_code); static std::string native_scan_code_to_string(int native_scan_code);
@ -105,9 +105,9 @@ protected:
private: private:
QWindow* m_target = nullptr; QWindow* m_target = nullptr;
bool m_mouse_move_used = false; bool m_mouse_move_used = false;
bool get_mouse_lock_state(); bool get_mouse_lock_state() const;
std::vector<std::shared_ptr<Pad>> bindings; std::vector<std::shared_ptr<Pad>> m_bindings;
// Button Movements // Button Movements
steady_clock::time_point m_button_time; steady_clock::time_point m_button_time;

View file

@ -26,10 +26,6 @@ mm_joystick_handler::mm_joystick_handler() : PadHandlerBase(pad_handler::mm)
m_thumb_threshold = thumb_max / 2; m_thumb_threshold = thumb_max / 2;
} }
mm_joystick_handler::~mm_joystick_handler()
{
}
void mm_joystick_handler::init_config(pad_config* cfg, const std::string& name) void mm_joystick_handler::init_config(pad_config* cfg, const std::string& name)
{ {
if (!cfg) return; if (!cfg) return;
@ -82,8 +78,8 @@ bool mm_joystick_handler::Init()
return true; return true;
m_devices.clear(); m_devices.clear();
u32 supported_joysticks = joyGetNumDevs();
const u32 supported_joysticks = joyGetNumDevs();
if (supported_joysticks <= 0) if (supported_joysticks <= 0)
{ {
input_log.error("mmjoy: Driver doesn't support Joysticks"); input_log.error("mmjoy: Driver doesn't support Joysticks");
@ -113,7 +109,7 @@ std::vector<std::string> mm_joystick_handler::ListDevices()
if (!Init()) if (!Init())
return devices; return devices;
for (auto dev : m_devices) for (const auto& dev : m_devices)
{ {
devices.emplace_back(dev.second.device_name); devices.emplace_back(dev.second.device_name);
} }
@ -129,7 +125,7 @@ std::array<u32, PadHandlerBase::button::button_count> mm_joystick_handler::get_m
if (!joy_device) if (!joy_device)
return mapping; return mapping;
auto find_key = [=](const cfg::string& name) auto find_key = [this](const cfg::string& name)
{ {
long key = FindKeyCode(button_list, name, false); long key = FindKeyCode(button_list, name, false);
if (key < 0) if (key < 0)
@ -191,7 +187,7 @@ void mm_joystick_handler::get_next_button_press(const std::string& padId, const
return; return;
} }
static std::string cur_pad = ""; static std::string cur_pad;
static int id = -1; static int id = -1;
if (cur_pad != padId) if (cur_pad != padId)
@ -213,7 +209,7 @@ void mm_joystick_handler::get_next_button_press(const std::string& padId, const
js_info.dwFlags = JOY_RETURNALL; js_info.dwFlags = JOY_RETURNALL;
joyGetDevCaps(id, &js_caps, sizeof(js_caps)); joyGetDevCaps(id, &js_caps, sizeof(js_caps));
MMRESULT status = joyGetPosEx(id, &js_info); const MMRESULT status = joyGetPosEx(id, &js_info);
switch (status) switch (status)
{ {
@ -299,7 +295,7 @@ void mm_joystick_handler::get_next_button_press(const std::string& padId, const
return; return;
} }
auto find_key = [=](const std::string& name) auto find_key = [this](const std::string& name)
{ {
long key = FindKeyCodeByString(axis_list, name, false); long key = FindKeyCodeByString(axis_list, name, false);
if (key < 0) if (key < 0)
@ -339,7 +335,7 @@ std::unordered_map<u64, u16> mm_joystick_handler::GetButtonValues(const JOYINFOE
{ {
std::unordered_map<u64, u16> button_values; std::unordered_map<u64, u16> button_values;
for (auto entry : button_list) for (const auto& entry : button_list)
{ {
button_values.emplace(entry.first, js_info.dwButtons & entry.first ? 255 : 0); button_values.emplace(entry.first, js_info.dwButtons & entry.first ? 255 : 0);
} }
@ -371,19 +367,19 @@ std::unordered_map<u64, u16> mm_joystick_handler::GetButtonValues(const JOYINFOE
} }
}; };
float rad = static_cast<float>(js_info.dwPOV / 100 * acos(-1) / 180); const float rad = static_cast<float>(js_info.dwPOV / 100 * acos(-1) / 180);
emplacePOVs(cosf(rad) * 255.0f, JOY_POVBACKWARD, JOY_POVFORWARD); emplacePOVs(cosf(rad) * 255.0f, JOY_POVBACKWARD, JOY_POVFORWARD);
emplacePOVs(sinf(rad) * 255.0f, JOY_POVLEFT, JOY_POVRIGHT); emplacePOVs(sinf(rad) * 255.0f, JOY_POVLEFT, JOY_POVRIGHT);
} }
} }
else if (js_caps.wCaps & JOYCAPS_POV4DIR) else if (js_caps.wCaps & JOYCAPS_POV4DIR)
{ {
int val = static_cast<int>(js_info.dwPOV); const int val = static_cast<int>(js_info.dwPOV);
auto emplacePOV = [&button_values, &val](int pov) auto emplacePOV = [&button_values, &val](int pov)
{ {
int cw = pov + 4500, ccw = pov - 4500; const int cw = pov + 4500, ccw = pov - 4500;
bool pressed = (val == pov) || (val == cw) || (ccw < 0 ? val == 36000 - std::abs(ccw) : val == ccw); const bool pressed = (val == pov) || (val == cw) || (ccw < 0 ? val == 36000 - std::abs(ccw) : val == ccw);
button_values.emplace(pov, pressed ? 255 : 0); button_values.emplace(pov, pressed ? 255 : 0);
}; };
@ -396,7 +392,7 @@ std::unordered_map<u64, u16> mm_joystick_handler::GetButtonValues(const JOYINFOE
auto add_axis_value = [&](DWORD axis, UINT min, UINT max, u64 pos, u64 neg) auto add_axis_value = [&](DWORD axis, UINT min, UINT max, u64 pos, u64 neg)
{ {
float val = ScaledInput2(axis, min, max); const float val = ScaledInput2(axis, min, max);
if (val < 0) if (val < 0)
{ {
button_values.emplace(pos, 0); button_values.emplace(pos, 0);
@ -437,7 +433,7 @@ std::unordered_map<u64, u16> mm_joystick_handler::get_button_values(const std::s
int mm_joystick_handler::GetIDByName(const std::string& name) int mm_joystick_handler::GetIDByName(const std::string& name)
{ {
for (auto dev : m_devices) for (const auto& dev : m_devices)
{ {
if (dev.second.device_name == name) if (dev.second.device_name == name)
return dev.first; return dev.first;
@ -445,7 +441,7 @@ int mm_joystick_handler::GetIDByName(const std::string& name)
return -1; return -1;
} }
bool mm_joystick_handler::GetMMJOYDevice(int index, MMJOYDevice* dev) bool mm_joystick_handler::GetMMJOYDevice(int index, MMJOYDevice* dev) const
{ {
if (!dev) if (!dev)
return false; return false;
@ -478,7 +474,7 @@ std::shared_ptr<PadDevice> mm_joystick_handler::get_device(const std::string& de
if (!Init()) if (!Init())
return nullptr; return nullptr;
int id = GetIDByName(device); const int id = GetIDByName(device);
if (id < 0) if (id < 0)
return nullptr; return nullptr;

View file

@ -110,7 +110,6 @@ class mm_joystick_handler final : public PadHandlerBase
public: public:
mm_joystick_handler(); mm_joystick_handler();
~mm_joystick_handler();
bool Init() override; bool Init() override;
@ -121,7 +120,7 @@ public:
private: private:
std::unordered_map<u64, u16> GetButtonValues(const JOYINFOEX& js_info, const JOYCAPS& js_caps); std::unordered_map<u64, u16> GetButtonValues(const JOYINFOEX& js_info, const JOYCAPS& js_caps);
int GetIDByName(const std::string& name); int GetIDByName(const std::string& name);
bool GetMMJOYDevice(int index, MMJOYDevice* dev); bool GetMMJOYDevice(int index, MMJOYDevice* dev) const;
bool is_init = false; bool is_init = false;

View file

@ -140,7 +140,7 @@ void pad_thread::Init()
cur_pad_handler = std::make_shared<evdev_joystick_handler>(); cur_pad_handler = std::make_shared<evdev_joystick_handler>();
break; break;
#endif #endif
default: case pad_handler::null:
break; break;
} }
handlers.emplace(handler_type, cur_pad_handler); handlers.emplace(handler_type, cur_pad_handler);

View file

@ -49,11 +49,6 @@ namespace input
{ {
switch (type) switch (type)
{ {
default:
case product_type::playstation_3_controller:
{
return product_info{ type, vendor_id::sony_corp, product_id::playstation_3_controller, 0x0 };
}
case product_type::dance_dance_revolution_mat: case product_type::dance_dance_revolution_mat:
{ {
return product_info{ type, vendor_id::konami_de, product_id::dance_dance_revolution_mat, 0x000000FF }; return product_info{ type, vendor_id::konami_de, product_id::dance_dance_revolution_mat, 0x000000FF };
@ -86,6 +81,11 @@ namespace input
{ {
return product_info{ type, vendor_id::sony_cea, product_id::rock_revolution_drum_kit, 0x000000FB }; return product_info{ type, vendor_id::sony_cea, product_id::rock_revolution_drum_kit, 0x000000FB };
} }
case product_type::playstation_3_controller:
default: // GCC doesn't like it when there is no return value if if all enum values are covered
{
return product_info{ type, vendor_id::sony_corp, product_id::playstation_3_controller, 0x0 };
}
} }
} }

View file

@ -188,7 +188,7 @@ int xinput_pad_handler::GetDeviceNumber(const std::string& padId)
if (pos == umax) if (pos == umax)
return -1; return -1;
int device_number = std::stoul(padId.substr(pos + 12)) - 1; // Controllers 1-n in GUI const int device_number = std::stoul(padId.substr(pos + 12)) - 1; // Controllers 1-n in GUI
if (device_number >= XUSER_MAX_COUNT) if (device_number >= XUSER_MAX_COUNT)
return -1; return -1;
@ -242,7 +242,7 @@ xinput_pad_handler::PadButtonValues xinput_pad_handler::get_button_values_base(c
values[XInputKeyCodes::RSYPos] = ry > 0 ? ry : 0; values[XInputKeyCodes::RSYPos] = ry > 0 ? ry : 0;
// Buttons // Buttons
WORD buttons = state.Gamepad.wButtons; const WORD buttons = state.Gamepad.wButtons;
// A, B, X, Y // A, B, X, Y
values[XInputKeyCodes::A] = buttons & XINPUT_GAMEPAD_A ? 255 : 0; values[XInputKeyCodes::A] = buttons & XINPUT_GAMEPAD_A ? 255 : 0;
@ -518,16 +518,16 @@ void xinput_pad_handler::apply_pad_data(const std::shared_ptr<PadDevice>& device
if (!dev || !pad) if (!dev || !pad)
return; return;
auto padnum = dev->deviceNumber; const auto padnum = dev->deviceNumber;
auto profile = dev->config; const auto profile = dev->config;
// The left motor is the low-frequency rumble motor. The right motor is the high-frequency rumble motor. // The left motor is the low-frequency rumble motor. The right motor is the high-frequency rumble motor.
// The two motors are not the same, and they create different vibration effects. Values range between 0 to 65535. // The two motors are not the same, and they create different vibration effects. Values range between 0 to 65535.
usz idx_l = profile->switch_vibration_motors ? 1 : 0; const usz idx_l = profile->switch_vibration_motors ? 1 : 0;
usz idx_s = profile->switch_vibration_motors ? 0 : 1; const usz idx_s = profile->switch_vibration_motors ? 0 : 1;
u16 speed_large = profile->enable_vibration_motor_large ? pad->m_vibrateMotors[idx_l].m_value : static_cast<u16>(vibration_min); const u16 speed_large = profile->enable_vibration_motor_large ? pad->m_vibrateMotors[idx_l].m_value : static_cast<u16>(vibration_min);
u16 speed_small = profile->enable_vibration_motor_small ? pad->m_vibrateMotors[idx_s].m_value : static_cast<u16>(vibration_min); const u16 speed_small = profile->enable_vibration_motor_small ? pad->m_vibrateMotors[idx_s].m_value : static_cast<u16>(vibration_min);
dev->newVibrateData |= dev->largeVibrate != speed_large || dev->smallVibrate != speed_small; dev->newVibrateData |= dev->largeVibrate != speed_large || dev->smallVibrate != speed_small;

View file

@ -10,7 +10,6 @@
#include <Windows.h> #include <Windows.h>
#include <Xinput.h> #include <Xinput.h>
#include <chrono> #include <chrono>
#include <optional>
// ScpToolkit defined structure for pressure sensitive button query // ScpToolkit defined structure for pressure sensitive button query
struct SCP_EXTN struct SCP_EXTN
@ -100,8 +99,8 @@ class xinput_pad_handler final : public PadHandlerBase
steady_clock::time_point last_vibration; steady_clock::time_point last_vibration;
bool is_scp_device{ false }; bool is_scp_device{ false };
DWORD state{ ERROR_NOT_CONNECTED }; // holds internal controller state change DWORD state{ ERROR_NOT_CONNECTED }; // holds internal controller state change
SCP_EXTN state_scp{ 0 }; SCP_EXTN state_scp{};
XINPUT_STATE state_base{ 0 }; XINPUT_STATE state_base{};
}; };
public: public:
@ -124,8 +123,8 @@ private:
private: private:
int GetDeviceNumber(const std::string& padId); int GetDeviceNumber(const std::string& padId);
PadButtonValues get_button_values_base(const XINPUT_STATE& state); static PadButtonValues get_button_values_base(const XINPUT_STATE& state);
PadButtonValues get_button_values_scp(const SCP_EXTN& state); static PadButtonValues get_button_values_scp(const SCP_EXTN& state);
bool is_init{ false }; bool is_init{ false };
HMODULE library{ nullptr }; HMODULE library{ nullptr };

View file

@ -32,7 +32,7 @@ bool headless_application::Init()
return true; return true;
} }
void headless_application::InitializeConnects() void headless_application::InitializeConnects() const
{ {
qRegisterMetaType<std::function<void()>>("std::function<void()>"); qRegisterMetaType<std::function<void()>>("std::function<void()>");
connect(this, &headless_application::RequestCallAfter, this, &headless_application::HandleCallAfter); connect(this, &headless_application::RequestCallAfter, this, &headless_application::HandleCallAfter);
@ -58,14 +58,14 @@ void headless_application::InitializeCallbacks()
return false; return false;
}; };
callbacks.call_after = [=, this](std::function<void()> func) callbacks.call_after = [this](std::function<void()> func)
{ {
RequestCallAfter(std::move(func)); RequestCallAfter(std::move(func));
}; };
callbacks.init_gs_render = []() callbacks.init_gs_render = []()
{ {
switch (video_renderer type = g_cfg.video.renderer) switch (const video_renderer type = g_cfg.video.renderer)
{ {
case video_renderer::null: case video_renderer::null:
{ {
@ -78,6 +78,7 @@ void headless_application::InitializeCallbacks()
#endif #endif
{ {
fmt::throw_exception("Headless mode can only be used with the %s video renderer. Current renderer: %s", video_renderer::null, type); fmt::throw_exception("Headless mode can only be used with the %s video renderer. Current renderer: %s", video_renderer::null, type);
[[fallthrough]];
} }
default: default:
{ {

View file

@ -21,16 +21,16 @@ public:
private: private:
void InitializeCallbacks(); void InitializeCallbacks();
void InitializeConnects(); void InitializeConnects() const;
QThread* get_thread() override QThread* get_thread() override
{ {
return thread(); return thread();
}; }
Q_SIGNALS: Q_SIGNALS:
void RequestCallAfter(const std::function<void()>& func); void RequestCallAfter(std::function<void()> func);
private Q_SLOTS: private Q_SLOTS:
void HandleCallAfter(const std::function<void()>& func); static void HandleCallAfter(const std::function<void()>& func);
}; };

View file

@ -137,12 +137,11 @@ LOG_CHANNEL(q_debug, "QDEBUG");
show_report(text); show_report(text);
std::exit(0); std::exit(0);
} }
else
{
#ifdef _WIN32 #ifdef _WIN32
wchar_t buffer[32767]; wchar_t buffer[32767];
GetModuleFileNameW(nullptr, buffer, sizeof(buffer) / 2); GetModuleFileNameW(nullptr, buffer, sizeof(buffer) / 2);
std::wstring arg(text.cbegin(), text.cend()); // ignore unicode for now const std::wstring arg(text.cbegin(), text.cend()); // ignore unicode for now
_wspawnl(_P_WAIT, buffer, buffer, L"--error", arg.c_str(), nullptr); _wspawnl(_P_WAIT, buffer, buffer, L"--error", arg.c_str(), nullptr);
#else #else
pid_t pid; pid_t pid;
@ -176,8 +175,6 @@ LOG_CHANNEL(q_debug, "QDEBUG");
std::fprintf(stderr, "posix_spawn() failed: %d\n", ret); std::fprintf(stderr, "posix_spawn() failed: %d\n", ret);
} }
#endif #endif
std::abort();
}
} }
std::abort(); std::abort();
@ -339,7 +336,7 @@ QCoreApplication* createApplication(int& argc, char* argv[])
void log_q_debug(QtMsgType type, const QMessageLogContext& context, const QString& msg) void log_q_debug(QtMsgType type, const QMessageLogContext& context, const QString& msg)
{ {
Q_UNUSED(context); Q_UNUSED(context)
switch (type) switch (type)
{ {
@ -402,8 +399,7 @@ int main(int argc, char** argv)
{ {
report_fatal_error("Another instance of RPCS3 is running. Close it or kill its process, if necessary."); report_fatal_error("Another instance of RPCS3 is running. Close it or kill its process, if necessary.");
} }
else
{
report_fatal_error("Cannot create RPCS3.log (access denied)." report_fatal_error("Cannot create RPCS3.log (access denied)."
#ifdef _WIN32 #ifdef _WIN32
"\nNote that RPCS3 cannot be installed in Program Files or similar directories with limited permissions." "\nNote that RPCS3 cannot be installed in Program Files or similar directories with limited permissions."
@ -412,20 +408,14 @@ int main(int argc, char** argv)
#endif #endif
); );
} }
}
else
{
report_fatal_error(fmt::format("Cannot create RPCS3.log (error %s)", fs::g_tls_error));
}
return 1; report_fatal_error(fmt::format("Cannot create RPCS3.log (error %s)", fs::g_tls_error));
} }
#ifdef _WIN32 #ifdef _WIN32
if (!SetProcessWorkingSetSize(GetCurrentProcess(), 0x80000000, 0xC0000000)) // 2-3 GiB if (!SetProcessWorkingSetSize(GetCurrentProcess(), 0x80000000, 0xC0000000)) // 2-3 GiB
{ {
report_fatal_error("Not enough memory for RPCS3 process."); report_fatal_error("Not enough memory for RPCS3 process.");
return 2;
} }
#endif #endif
@ -444,7 +434,6 @@ int main(int argc, char** argv)
if (!fs::statfs(fs::get_cache_dir(), stats) || stats.avail_free < 128 * 1024 * 1024) if (!fs::statfs(fs::get_cache_dir(), stats) || stats.avail_free < 128 * 1024 * 1024)
{ {
report_fatal_error(fmt::format("Not enough free space (%f KB)", stats.avail_free / 1000000.)); report_fatal_error(fmt::format("Not enough free space (%f KB)", stats.avail_free / 1000000.));
return 1;
} }
// Limit log size to ~25% of free space // Limit log size to ~25% of free space
@ -613,7 +602,7 @@ int main(int argc, char** argv)
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, hhdr); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, hhdr);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, +[](const char* ptr, usz, usz size, void* json) -> usz curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, +[](const char* ptr, usz, usz size, void* json) -> usz
{ {
reinterpret_cast<QByteArray*>(json)->append(ptr, size); static_cast<QByteArray*>(json)->append(ptr, size);
return size; return size;
}); });
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buf); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buf);
@ -760,7 +749,6 @@ int main(int argc, char** argv)
if (Emulator::CheckUsr(active_user) == 0) if (Emulator::CheckUsr(active_user) == 0)
{ {
report_fatal_error(fmt::format("Failed to set user ID '%s'.\nThe user ID must consist of 8 digits and cannot be 00000000.", active_user)); report_fatal_error(fmt::format("Failed to set user ID '%s'.\nThe user ID must consist of 8 digits and cannot be 00000000.", active_user));
return 1;
} }
} }
@ -799,7 +787,6 @@ int main(int argc, char** argv)
{ {
// Should be unreachable // Should be unreachable
report_fatal_error("RPCS3 initialization failed!"); report_fatal_error("RPCS3 initialization failed!");
return 1;
} }
#ifdef _WIN32 #ifdef _WIN32
@ -816,16 +803,13 @@ int main(int argc, char** argv)
} }
#endif #endif
std::string config_override_path;
if (parser.isSet(arg_config)) if (parser.isSet(arg_config))
{ {
config_override_path = parser.value(config_option).toStdString(); const std::string config_override_path = parser.value(config_option).toStdString();
if (!fs::is_file(config_override_path)) if (!fs::is_file(config_override_path))
{ {
report_fatal_error(fmt::format("No config file found: %s", config_override_path)); report_fatal_error(fmt::format("No config file found: %s", config_override_path));
return 1;
} }
Emu.SetConfigOverride(config_override_path); Emu.SetConfigOverride(config_override_path);
@ -839,7 +823,6 @@ int main(int argc, char** argv)
if (s_no_gui) if (s_no_gui)
{ {
report_fatal_error("Cannot perform installation in no-gui mode!"); report_fatal_error("Cannot perform installation in no-gui mode!");
return 1;
} }
if (gui_app->m_main_window) if (gui_app->m_main_window)
@ -860,13 +843,11 @@ int main(int argc, char** argv)
else else
{ {
report_fatal_error("Cannot perform installation. No main window found!"); report_fatal_error("Cannot perform installation. No main window found!");
return 1;
} }
} }
else else
{ {
report_fatal_error("Cannot perform installation in headless mode!"); report_fatal_error("Cannot perform installation in headless mode!");
return 1;
} }
} }
@ -880,24 +861,24 @@ int main(int argc, char** argv)
sys_log.notice("Booting application from command line: %s", args.at(0).toStdString()); sys_log.notice("Booting application from command line: %s", args.at(0).toStdString());
// Propagate command line arguments // Propagate command line arguments
std::vector<std::string> argv; std::vector<std::string> rpcs3_argv;
if (args.length() > 1) if (args.length() > 1)
{ {
argv.emplace_back(); rpcs3_argv.emplace_back();
for (int i = 1; i < args.length(); i++) for (int i = 1; i < args.length(); i++)
{ {
const std::string arg = args[i].toStdString(); const std::string arg = args[i].toStdString();
argv.emplace_back(arg); rpcs3_argv.emplace_back(arg);
sys_log.notice("Optional command line argument %d: %s", i, arg); sys_log.notice("Optional command line argument %d: %s", i, arg);
} }
} }
// Postpone startup to main event loop // Postpone startup to main event loop
Emu.CallAfter([config_override_path, path = sstr(QFileInfo(args.at(0)).absoluteFilePath()), argv = std::move(argv)]() mutable Emu.CallAfter([path = sstr(QFileInfo(args.at(0)).absoluteFilePath()), rpcs3_argv = std::move(rpcs3_argv)]() mutable
{ {
Emu.argv = std::move(argv); Emu.argv = std::move(rpcs3_argv);
Emu.SetForceBoot(true); Emu.SetForceBoot(true);
if (const game_boot_result error = Emu.BootGame(path, ""); error != game_boot_result::no_errors) if (const game_boot_result error = Emu.BootGame(path, ""); error != game_boot_result::no_errors)
@ -946,6 +927,7 @@ extern "C"
size--; size--;
continue; continue;
} }
default: break;
} }
break; break;

View file

@ -2,7 +2,6 @@
#include "util/types.hpp" #include "util/types.hpp"
#include "util/logs.hpp" #include "util/logs.hpp"
#include "util/atomic.hpp"
#include "Input/pad_thread.h" #include "Input/pad_thread.h"
#include "Emu/System.h" #include "Emu/System.h"
@ -48,7 +47,7 @@ EmuCallbacks main_application::CreateCallbacks()
callbacks.init_kb_handler = [this]() callbacks.init_kb_handler = [this]()
{ {
switch (keyboard_handler type = g_cfg.io.keyboard) switch (g_cfg.io.keyboard.get())
{ {
case keyboard_handler::null: case keyboard_handler::null:
{ {
@ -62,13 +61,12 @@ EmuCallbacks main_application::CreateCallbacks()
ret->SetTargetWindow(m_game_window); ret->SetTargetWindow(m_game_window);
break; break;
} }
default: fmt::throw_exception("Invalid keyboard handler: %s", type);
} }
}; };
callbacks.init_mouse_handler = [this]() callbacks.init_mouse_handler = [this]()
{ {
switch (mouse_handler type = g_cfg.io.mouse) switch (g_cfg.io.mouse.get())
{ {
case mouse_handler::null: case mouse_handler::null:
{ {
@ -90,7 +88,6 @@ EmuCallbacks main_application::CreateCallbacks()
ret->SetTargetWindow(m_game_window); ret->SetTargetWindow(m_game_window);
break; break;
} }
default: fmt::throw_exception("Invalid mouse handler: %s", type);
} }
}; };
@ -102,7 +99,7 @@ EmuCallbacks main_application::CreateCallbacks()
callbacks.get_audio = []() -> std::shared_ptr<AudioBackend> callbacks.get_audio = []() -> std::shared_ptr<AudioBackend>
{ {
std::shared_ptr<AudioBackend> result; std::shared_ptr<AudioBackend> result;
switch (audio_renderer type = g_cfg.audio.renderer) switch (g_cfg.audio.renderer.get())
{ {
case audio_renderer::null: result = std::make_shared<NullAudioBackend>(); break; case audio_renderer::null: result = std::make_shared<NullAudioBackend>(); break;
#ifdef _WIN32 #ifdef _WIN32
@ -119,7 +116,6 @@ EmuCallbacks main_application::CreateCallbacks()
#ifdef HAVE_FAUDIO #ifdef HAVE_FAUDIO
case audio_renderer::faudio: result = std::make_shared<FAudioBackend>(); break; case audio_renderer::faudio: result = std::make_shared<FAudioBackend>(); break;
#endif #endif
default: fmt::throw_exception("Invalid audio renderer: %s", type);
} }
if (!result->Initialized()) if (!result->Initialized())

View file

@ -12,7 +12,7 @@ public:
static void InitializeEmulator(const std::string& user, bool show_gui); static void InitializeEmulator(const std::string& user, bool show_gui);
void SetActiveUser(std::string user) void SetActiveUser(const std::string& user)
{ {
m_active_user = user; m_active_user = user;
} }

View file

@ -1,7 +1,6 @@
#ifdef WITH_DISCORD_RPC #ifdef WITH_DISCORD_RPC
#include "_discord_utils.h" #include "_discord_utils.h"
#include "discord_rpc.h" #include "discord_rpc.h"
#include "discord_register.h"
#include <string> #include <string>
#include <ctime> #include <ctime>
@ -11,7 +10,7 @@ namespace discord
void initialize(const std::string& application_id) void initialize(const std::string& application_id)
{ {
DiscordEventHandlers handlers = {}; DiscordEventHandlers handlers = {};
Discord_Initialize(application_id.c_str(), &handlers, 1, NULL); Discord_Initialize(application_id.c_str(), &handlers, 1, nullptr);
} }
void shutdown() void shutdown()
@ -29,7 +28,7 @@ namespace discord
if (reset_timer) if (reset_timer)
{ {
discordPresence.startTimestamp = std::time(0); discordPresence.startTimestamp = std::time(nullptr);
} }
Discord_UpdatePresence(&discordPresence); Discord_UpdatePresence(&discordPresence);

View file

@ -71,12 +71,12 @@ auto_pause_settings_dialog::auto_pause_settings_dialog(QWidget *parent) : QDialo
} }
// Copied some from AutoPause. // Copied some from AutoPause.
void auto_pause_settings_dialog::LoadEntries(void) void auto_pause_settings_dialog::LoadEntries()
{ {
m_entries.clear(); m_entries.clear();
m_entries.reserve(16); m_entries.reserve(16);
fs::file list(fs::get_config_dir() + "pause.bin"); const fs::file list(fs::get_config_dir() + "pause.bin");
if (list) if (list)
{ {
@ -99,7 +99,7 @@ void auto_pause_settings_dialog::LoadEntries(void)
// Copied some from AutoPause. // Copied some from AutoPause.
// Tip: This one doesn't check for the file is being read or not. // Tip: This one doesn't check for the file is being read or not.
// This would always use a 0xFFFFFFFF as end of the pause.bin // This would always use a 0xFFFFFFFF as end of the pause.bin
void auto_pause_settings_dialog::SaveEntries(void) void auto_pause_settings_dialog::SaveEntries()
{ {
fs::file list(fs::get_config_dir() + "pause.bin", fs::rewrite); fs::file list(fs::get_config_dir() + "pause.bin", fs::rewrite);
//System calls ID and Function calls ID are all u32 iirc. //System calls ID and Function calls ID are all u32 iirc.
@ -115,7 +115,7 @@ void auto_pause_settings_dialog::SaveEntries(void)
list.write(&num, sizeof(u32)); list.write(&num, sizeof(u32));
} }
void auto_pause_settings_dialog::UpdateList(void) void auto_pause_settings_dialog::UpdateList()
{ {
const int entries_size = static_cast<int>(m_entries.size()); const int entries_size = static_cast<int>(m_entries.size());
m_pause_list->clearContents(); m_pause_list->clearContents();
@ -179,7 +179,7 @@ void auto_pause_settings_dialog::ShowContextMenu(const QPoint &pos)
{ {
m_entries.emplace_back(0xFFFFFFFF); m_entries.emplace_back(0xFFFFFFFF);
UpdateList(); UpdateList();
int idx = static_cast<int>(m_entries.size()) - 1; const int idx = static_cast<int>(m_entries.size()) - 1;
m_pause_list->selectRow(idx); m_pause_list->selectRow(idx);
OnEntryConfig(idx, true); OnEntryConfig(idx, true);
}); });
@ -257,7 +257,7 @@ AutoPauseConfigDialog::AutoPauseConfigDialog(QWidget* parent, auto_pause_setting
void AutoPauseConfigDialog::OnOk() void AutoPauseConfigDialog::OnOk()
{ {
bool ok; bool ok;
ullong value = m_id->text().toULongLong(&ok, 16); const ullong value = m_id->text().toULongLong(&ok, 16);
m_entry = value; m_entry = value;
*m_presult = m_entry; *m_presult = m_entry;
@ -274,7 +274,7 @@ void AutoPauseConfigDialog::OnCancel()
close(); close();
} }
void AutoPauseConfigDialog::OnUpdateValue() void AutoPauseConfigDialog::OnUpdateValue() const
{ {
bool ok; bool ok;
const ullong value = m_id->text().toULongLong(&ok, 16); const ullong value = m_id->text().toULongLong(&ok, 16);

View file

@ -24,9 +24,9 @@ class auto_pause_settings_dialog : public QDialog
public: public:
explicit auto_pause_settings_dialog(QWidget* parent); explicit auto_pause_settings_dialog(QWidget* parent);
void UpdateList(void); void UpdateList();
void LoadEntries(void); void LoadEntries();
void SaveEntries(void); void SaveEntries();
public Q_SLOTS: public Q_SLOTS:
void OnRemove(); void OnRemove();
@ -52,5 +52,5 @@ public:
private Q_SLOTS: private Q_SLOTS:
void OnOk(); void OnOk();
void OnCancel(); void OnCancel();
void OnUpdateValue(); void OnUpdateValue() const;
}; };

View file

@ -2,14 +2,6 @@
extern void ppu_breakpoint(u32 loc, bool is_adding); extern void ppu_breakpoint(u32 loc, bool is_adding);
breakpoint_handler::breakpoint_handler()
{
}
breakpoint_handler::~breakpoint_handler()
{
}
bool breakpoint_handler::HasBreakpoint(u32 loc) const bool breakpoint_handler::HasBreakpoint(u32 loc) const
{ {
return m_breakpoints.contains(loc); return m_breakpoints.contains(loc);

View file

@ -17,8 +17,8 @@ class breakpoint_handler
{ {
public: public:
breakpoint_handler(); breakpoint_handler() = default;
~breakpoint_handler(); ~breakpoint_handler() = default;
/** /**
* Returns true iff breakpoint exists at loc. * Returns true iff breakpoint exists at loc.

View file

@ -2,7 +2,6 @@
#include "breakpoint_handler.h" #include "breakpoint_handler.h"
#include "Emu/CPU/CPUDisAsm.h" #include "Emu/CPU/CPUDisAsm.h"
#include "Emu/Cell/SPUThread.h"
#include "Emu/Cell/PPUThread.h" #include "Emu/Cell/PPUThread.h"
#include <QMenu> #include <QMenu>
@ -39,7 +38,7 @@ void breakpoint_list::ClearBreakpoints()
while (count()) while (count())
{ {
auto* currentItem = takeItem(0); auto* currentItem = takeItem(0);
u32 loc = currentItem->data(Qt::UserRole).value<u32>(); const u32 loc = currentItem->data(Qt::UserRole).value<u32>();
m_breakpoint_handler->RemoveBreakpoint(loc); m_breakpoint_handler->RemoveBreakpoint(loc);
delete currentItem; delete currentItem;
} }

View file

@ -3,7 +3,6 @@
#include "util/types.hpp" #include "util/types.hpp"
#include <QListWidget> #include <QListWidget>
#include <memory>
class CPUDisAsm; class CPUDisAsm;
class cpu_thread; class cpu_thread;
@ -17,7 +16,7 @@ public:
breakpoint_list(QWidget* parent, breakpoint_handler* handler); breakpoint_list(QWidget* parent, breakpoint_handler* handler);
void UpdateCPUData(cpu_thread* cpu, CPUDisAsm* disasm); void UpdateCPUData(cpu_thread* cpu, CPUDisAsm* disasm);
void ClearBreakpoints(); void ClearBreakpoints();
void AddBreakpoint(u32 addr); void AddBreakpoint(u32 pc);
void RemoveBreakpoint(u32 addr); void RemoveBreakpoint(u32 addr);
QColor m_text_color_bp; QColor m_text_color_bp;
@ -25,7 +24,7 @@ public:
Q_SIGNALS: Q_SIGNALS:
void RequestShowAddress(u32 addr, bool select_addr = true, bool force = false); void RequestShowAddress(u32 addr, bool select_addr = true, bool force = false);
public Q_SLOTS: public Q_SLOTS:
void HandleBreakpointRequest(u32 addr); void HandleBreakpointRequest(u32 loc);
private Q_SLOTS: private Q_SLOTS:
void OnBreakpointListDoubleClicked(); void OnBreakpointListDoubleClicked();
void OnBreakpointListRightClicked(const QPoint &pos); void OnBreakpointListRightClicked(const QPoint &pos);
@ -34,6 +33,6 @@ private:
breakpoint_handler* m_breakpoint_handler; breakpoint_handler* m_breakpoint_handler;
QMenu* m_context_menu = nullptr; QMenu* m_context_menu = nullptr;
QAction* m_delete_action; QAction* m_delete_action;
cpu_thread* m_cpu; cpu_thread* m_cpu = nullptr;
CPUDisAsm* m_disasm; CPUDisAsm* m_disasm = nullptr;
}; };

View file

@ -14,7 +14,7 @@ call_stack_list::call_stack_list(QWidget* parent) : QListWidget(parent)
connect(this, &QListWidget::itemDoubleClicked, this, &call_stack_list::OnCallStackListDoubleClicked); connect(this, &QListWidget::itemDoubleClicked, this, &call_stack_list::OnCallStackListDoubleClicked);
} }
void call_stack_list::HandleUpdate(std::vector<std::pair<u32, u32>> call_stack) void call_stack_list::HandleUpdate(const std::vector<std::pair<u32, u32>>& call_stack)
{ {
clear(); clear();

View file

@ -13,12 +13,12 @@ class call_stack_list : public QListWidget
Q_OBJECT Q_OBJECT
public: public:
call_stack_list(QWidget* parent); explicit call_stack_list(QWidget* parent);
Q_SIGNALS: Q_SIGNALS:
void RequestShowAddress(u32 addr, bool select_addr = true, bool force = false); void RequestShowAddress(u32 addr, bool select_addr = true, bool force = false);
public Q_SLOTS: public Q_SLOTS:
void HandleUpdate(std::vector<std::pair<u32, u32>> call_stack); void HandleUpdate(const std::vector<std::pair<u32, u32>>& call_stack);
private Q_SLOTS: private Q_SLOTS:
void OnCallStackListDoubleClicked(); void OnCallStackListDoubleClicked();
}; };

View file

@ -17,7 +17,7 @@ enum Category
Others, Others,
}; };
namespace category namespace cat
{ {
const QString cat_app_music = "AM"; const QString cat_app_music = "AM";
const QString cat_app_photo = "AP"; const QString cat_app_photo = "AP";

View file

@ -16,8 +16,8 @@ LOG_CHANNEL(gui_log, "GUI");
constexpr auto qstr = QString::fromStdString; constexpr auto qstr = QString::fromStdString;
inline std::string sstr(const QString& _in) { return _in.toStdString(); } inline std::string sstr(const QString& _in) { return _in.toStdString(); }
cg_disasm_window::cg_disasm_window(std::shared_ptr<gui_settings> xSettings) cg_disasm_window::cg_disasm_window(std::shared_ptr<gui_settings> gui_settings)
: m_gui_settings(xSettings) : m_gui_settings(std::move(gui_settings))
{ {
setWindowTitle(tr("Cg Disasm")); setWindowTitle(tr("Cg Disasm"));
setObjectName("cg_disasm"); setObjectName("cg_disasm");
@ -107,7 +107,7 @@ void cg_disasm_window::ShowContextMenu(const QPoint &pos)
menu.exec(origin); menu.exec(origin);
} }
void cg_disasm_window::ShowDisasm() void cg_disasm_window::ShowDisasm() const
{ {
if (QFileInfo(m_path_last).isFile()) if (QFileInfo(m_path_last).isFile())
{ {

View file

@ -19,7 +19,7 @@ private Q_SLOTS:
void ShowContextMenu(const QPoint &pos); void ShowContextMenu(const QPoint &pos);
private: private:
void ShowDisasm(); void ShowDisasm() const;
bool IsValidFile(const QMimeData& md, bool save = false); bool IsValidFile(const QMimeData& md, bool save = false);
QString m_path_last; QString m_path_last;

View file

@ -9,7 +9,6 @@
#include "cheat_manager.h" #include "cheat_manager.h"
#include "Emu/System.h" #include "Emu/System.h"
#include "Emu/system_config.h"
#include "Emu/Memory/vm.h" #include "Emu/Memory/vm.h"
#include "Emu/CPU/CPUThread.h" #include "Emu/CPU/CPUThread.h"
@ -88,8 +87,6 @@ cheat_engine::cheat_engine()
for (const auto& yml_offset : yml_cheat.second) for (const auto& yml_offset : yml_cheat.second)
{ {
std::string error;
const u32 offset = get_yaml_node_value<u32>(yml_offset.first, error); const u32 offset = get_yaml_node_value<u32>(yml_offset.first, error);
if (!error.empty()) if (!error.empty())
{ {
@ -179,12 +176,9 @@ std::string cheat_engine::export_cheats_to_str() const
return cheats_str; return cheats_str;
} }
bool cheat_engine::exist(const std::string& name, const u32 offset) const bool cheat_engine::exist(const std::string& game, const u32 offset) const
{ {
if (cheats.count(name) && cheats.at(name).count(offset)) return cheats.contains(game) && cheats.at(game).contains(offset);
return true;
return false;
} }
void cheat_engine::add(const std::string& game, const std::string& description, const cheat_type type, const u32 offset, const std::string& red_script) void cheat_engine::add(const std::string& game, const std::string& description, const cheat_type type, const u32 offset, const std::string& red_script)
@ -246,7 +240,7 @@ bool cheat_engine::resolve_script(u32& final_offset, const u32 offset, const std
num_string += red_script[index]; num_string += red_script[index];
} }
u32 num_value = std::stoul(num_string); const u32 num_value = std::stoul(num_string);
do_operation(cur_op, final_offset, num_value); do_operation(cur_op, final_offset, num_value);
} }
else else
@ -288,7 +282,7 @@ bool cheat_engine::resolve_script(u32& final_offset, const u32 offset, const std
// Tries to get value at resolved address // Tries to get value at resolved address
bool success; bool success;
u32 res_value = get_value<u32>(res_addr, success); const u32 res_value = get_value<u32>(res_addr, success);
if (!success) if (!success)
return false; return false;
@ -482,8 +476,6 @@ bool cheat_engine::is_addr_safe(const u32 offset)
u32 cheat_engine::reverse_lookup(const u32 addr, const u32 max_offset, const u32 max_depth, const u32 cur_depth) u32 cheat_engine::reverse_lookup(const u32 addr, const u32 max_offset, const u32 max_depth, const u32 cur_depth)
{ {
u32 result;
for (u32 index = 0; index <= max_offset; index += 4) for (u32 index = 0; index <= max_offset; index += 4)
{ {
std::vector<u32> ptrs = search(addr - index, {}); std::vector<u32> ptrs = search(addr - index, {});
@ -501,7 +493,7 @@ u32 cheat_engine::reverse_lookup(const u32 addr, const u32 max_offset, const u32
{ {
for (const auto& ptr : ptrs) for (const auto& ptr : ptrs)
{ {
result = reverse_lookup(ptr, max_offset, max_depth, cur_depth + 1); const u32 result = reverse_lookup(ptr, max_offset, max_depth, cur_depth + 1);
if (result) if (result)
return result; return result;
} }
@ -683,7 +675,7 @@ cheat_manager_dialog::cheat_manager_dialog(QWidget* parent)
connect(tbl_cheats, &QTableWidget::customContextMenuRequested, [this](const QPoint& loc) connect(tbl_cheats, &QTableWidget::customContextMenuRequested, [this](const QPoint& loc)
{ {
QPoint globalPos = tbl_cheats->mapToGlobal(loc); const QPoint globalPos = tbl_cheats->mapToGlobal(loc);
QMenu* menu = new QMenu(); QMenu* menu = new QMenu();
QAction* delete_cheats = new QAction(tr("Delete"), menu); QAction* delete_cheats = new QAction(tr("Delete"), menu);
QAction* import_cheats = new QAction(tr("Import Cheats")); QAction* import_cheats = new QAction(tr("Import Cheats"));
@ -855,9 +847,8 @@ cheat_manager_dialog::cheat_manager_dialog(QWidget* parent)
const u32 offset = offsets_found[current_row]; const u32 offset = offsets_found[current_row];
const cheat_type type = static_cast<cheat_type>(cbx_cheat_search_type->currentIndex()); const cheat_type type = static_cast<cheat_type>(cbx_cheat_search_type->currentIndex());
const std::string name = Emu.GetTitle();
connect(add_to_cheat_list, &QAction::triggered, [name, offset, type, this]() connect(add_to_cheat_list, &QAction::triggered, [name = Emu.GetTitle(), offset, type, this]()
{ {
if (g_cheat.exist(name, offset)) if (g_cheat.exist(name, offset))
{ {
@ -1073,9 +1064,7 @@ QString cheat_manager_dialog::get_localized_cheat_type(cheat_type type)
case cheat_type::signed_16_cheat: return tr("Signed 16 bits"); case cheat_type::signed_16_cheat: return tr("Signed 16 bits");
case cheat_type::signed_32_cheat: return tr("Signed 32 bits"); case cheat_type::signed_32_cheat: return tr("Signed 32 bits");
case cheat_type::signed_64_cheat: return tr("Signed 64 bits"); case cheat_type::signed_64_cheat: return tr("Signed 64 bits");
case cheat_type::max: case cheat_type::max: break;
default:
break;
} }
std::string type_formatted; std::string type_formatted;
fmt::append(type_formatted, "%s", type); fmt::append(type_formatted, "%s", type);

View file

@ -43,7 +43,6 @@ public:
static bool is_addr_safe(const u32 offset); static bool is_addr_safe(const u32 offset);
static u32 reverse_lookup(const u32 addr, const u32 max_offset, const u32 max_depth, const u32 cur_depth = 0); static u32 reverse_lookup(const u32 addr, const u32 max_offset, const u32 max_depth, const u32 cur_depth = 0);
public:
std::map<std::string, std::map<u32, cheat_info>> cheats; std::map<std::string, std::map<u32, cheat_info>> cheats;
private: private:

View file

@ -1,5 +1,3 @@
#include <QStringList>
#include "config_adapter.h" #include "config_adapter.h"
#include "Emu/system_config.h" #include "Emu/system_config.h"
@ -24,12 +22,12 @@ namespace cfg_adapter
fmt::throw_exception("Node not found: %s", name); fmt::throw_exception("Node not found: %s", name);
} }
static cfg::_base& get_cfg(cfg::_base& root, cfg_location::const_iterator begin, cfg_location::const_iterator end) static cfg::_base& get_cfg(cfg::_base& root, const cfg_location::const_iterator begin, const cfg_location::const_iterator end)
{ {
return begin == end ? root : get_cfg(get_cfg(root, *begin), begin + 1, end); return begin == end ? root : get_cfg(get_cfg(root, *begin), begin + 1, end);
} }
YAML::Node get_node(const YAML::Node& node, cfg_location::const_iterator begin, cfg_location::const_iterator end) YAML::Node get_node(const YAML::Node& node, const cfg_location::const_iterator begin, const cfg_location::const_iterator end)
{ {
if (begin == end) if (begin == end)
{ {
@ -45,28 +43,24 @@ namespace cfg_adapter
return get_node(node[*begin], begin + 1, end); // TODO return get_node(node[*begin], begin + 1, end); // TODO
} }
YAML::Node get_node(const YAML::Node& node, cfg_location loc) YAML::Node get_node(const YAML::Node& node, const cfg_location& location)
{ {
return get_node(node, loc.cbegin(), loc.cend()); return get_node(node, location.cbegin(), location.cend());
} }
QStringList get_options(cfg_location location) QStringList get_options(const cfg_location& location)
{ {
QStringList values; QStringList values;
auto begin = location.cbegin(); for (const auto& v : cfg_adapter::get_cfg(g_cfg, location.cbegin(), location.cend()).to_list())
auto end = location.cend();
for (const auto& v : cfg_adapter::get_cfg(g_cfg, begin, end).to_list())
{ {
values.append(QString::fromStdString(v)); values.append(QString::fromStdString(v));
} }
return values; return values;
} }
static bool get_is_dynamic(cfg_location location) static bool get_is_dynamic(const cfg_location& location)
{ {
auto begin = location.cbegin(); return cfg_adapter::get_cfg(g_cfg, location.cbegin(), location.cend()).get_is_dynamic();
auto end = location.cend();
return cfg_adapter::get_cfg(g_cfg, begin, end).get_is_dynamic();
} }
bool get_is_dynamic(emu_settings_type type) bool get_is_dynamic(emu_settings_type type)

View file

@ -8,13 +8,13 @@
// Helper methods to interact with YAML and the config settings. // Helper methods to interact with YAML and the config settings.
namespace cfg_adapter namespace cfg_adapter
{ {
YAML::Node get_node(const YAML::Node& node, cfg_location::const_iterator begin, cfg_location::const_iterator end); YAML::Node get_node(const YAML::Node& node, const cfg_location::const_iterator begin, const cfg_location::const_iterator end);
/** Syntactic sugar to get a setting at a given config location. */ /** Syntactic sugar to get a setting at a given config location. */
YAML::Node get_node(const YAML::Node& node, cfg_location loc); YAML::Node get_node(const YAML::Node& node, const cfg_location& location);
/** Returns possible options for values for some particular setting.*/ /** Returns possible options for values for some particular setting.*/
QStringList get_options(cfg_location location); QStringList get_options(const cfg_location& location);
/** Returns dynamic property for some particular setting.*/ /** Returns dynamic property for some particular setting.*/
bool get_is_dynamic(emu_settings_type type); bool get_is_dynamic(emu_settings_type type);

View file

@ -23,7 +23,7 @@ curl_handle::~curl_handle()
curl_easy_cleanup(m_curl); curl_easy_cleanup(m_curl);
} }
CURL* curl_handle::get_curl() CURL* curl_handle::get_curl() const
{ {
return m_curl; return m_curl;
} }

View file

@ -13,12 +13,12 @@ private:
CURL* m_curl = nullptr; CURL* m_curl = nullptr;
public: public:
curl_handle(QObject* parent = nullptr); explicit curl_handle(QObject* parent = nullptr);
~curl_handle(); ~curl_handle();
CURL* get_curl(); CURL* get_curl() const;
operator CURL*() operator CURL*() const
{ {
return get_curl(); return get_curl();
} }

View file

@ -10,7 +10,7 @@ private:
public: public:
using QTableWidgetItem::setData; using QTableWidgetItem::setData;
custom_table_widget_item(){} custom_table_widget_item() = default;
custom_table_widget_item(const std::string& text, int sort_role = Qt::DisplayRole, const QVariant& sort_value = 0); custom_table_widget_item(const std::string& text, int sort_role = Qt::DisplayRole, const QVariant& sort_value = 0);
custom_table_widget_item(const QString& text, int sort_role = Qt::DisplayRole, const QVariant& sort_value = 0); custom_table_widget_item(const QString& text, int sort_role = Qt::DisplayRole, const QVariant& sort_value = 0);

View file

@ -26,7 +26,6 @@
#include <QApplication> #include <QApplication>
#include <QFontDatabase> #include <QFontDatabase>
#include <QCompleter> #include <QCompleter>
#include <QMenu>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QTimer> #include <QTimer>
#include <QCheckBox> #include <QCheckBox>
@ -40,8 +39,9 @@ constexpr auto s_pause_flags = cpu_flag::dbg_pause + cpu_flag::dbg_global_pause;
extern atomic_t<bool> g_debugger_pause_all_threads_on_bp; extern atomic_t<bool> g_debugger_pause_all_threads_on_bp;
debugger_frame::debugger_frame(std::shared_ptr<gui_settings> settings, QWidget *parent) debugger_frame::debugger_frame(std::shared_ptr<gui_settings> gui_settings, QWidget *parent)
: custom_dock_widget(tr("Debugger"), parent), xgui_settings(settings) : custom_dock_widget(tr("Debugger"), parent)
, m_gui_settings(std::move(gui_settings))
{ {
setContentsMargins(0, 0, 0, 0); setContentsMargins(0, 0, 0, 0);
@ -61,7 +61,7 @@ debugger_frame::debugger_frame(std::shared_ptr<gui_settings> settings, QWidget *
m_breakpoint_handler = new breakpoint_handler(); m_breakpoint_handler = new breakpoint_handler();
m_breakpoint_list = new breakpoint_list(this, m_breakpoint_handler); m_breakpoint_list = new breakpoint_list(this, m_breakpoint_handler);
m_debugger_list = new debugger_list(this, settings, m_breakpoint_handler); m_debugger_list = new debugger_list(this, m_gui_settings, m_breakpoint_handler);
m_debugger_list->installEventFilter(this); m_debugger_list->installEventFilter(this);
m_call_stack_list = new call_stack_list(this); m_call_stack_list = new call_stack_list(this);
@ -181,8 +181,8 @@ debugger_frame::debugger_frame(std::shared_ptr<gui_settings> settings, QWidget *
m_choice_units->clearFocus(); m_choice_units->clearFocus();
}); });
connect(m_choice_units, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this, &debugger_frame::UpdateUI); connect(m_choice_units, QOverload<int>::of(&QComboBox::activated), this, &debugger_frame::UpdateUI);
connect(m_choice_units, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &debugger_frame::OnSelectUnit); connect(m_choice_units, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &debugger_frame::OnSelectUnit);
connect(this, &QDockWidget::visibilityChanged, this, &debugger_frame::EnableUpdateTimer); connect(this, &QDockWidget::visibilityChanged, this, &debugger_frame::EnableUpdateTimer);
connect(m_debugger_list, &debugger_list::BreakpointRequested, m_breakpoint_list, &breakpoint_list::HandleBreakpointRequest); connect(m_debugger_list, &debugger_list::BreakpointRequested, m_breakpoint_list, &breakpoint_list::HandleBreakpointRequest);
@ -195,28 +195,28 @@ debugger_frame::debugger_frame(std::shared_ptr<gui_settings> settings, QWidget *
UpdateUnitList(); UpdateUnitList();
} }
void debugger_frame::SaveSettings() void debugger_frame::SaveSettings() const
{ {
xgui_settings->SetValue(gui::d_splitterState, m_splitter->saveState()); m_gui_settings->SetValue(gui::d_splitterState, m_splitter->saveState());
} }
void debugger_frame::ChangeColors() void debugger_frame::ChangeColors() const
{ {
if (m_debugger_list) if (m_debugger_list)
{ {
m_debugger_list->m_color_bp = m_breakpoint_list->m_color_bp = gui::utils::get_label_color("debugger_frame_breakpoint", QPalette::Window); m_debugger_list->m_color_bp = m_breakpoint_list->m_color_bp = gui::utils::get_label_color("debugger_frame_breakpoint", QPalette::Window);
m_debugger_list->m_color_pc = gui::utils::get_label_color("debugger_frame_pc", QPalette::Window); m_debugger_list->m_color_pc = gui::utils::get_label_color("debugger_frame_pc", QPalette::Window);
m_debugger_list->m_text_color_bp = m_breakpoint_list->m_text_color_bp = gui::utils::get_label_color("debugger_frame_breakpoint");; m_debugger_list->m_text_color_bp = m_breakpoint_list->m_text_color_bp = gui::utils::get_label_color("debugger_frame_breakpoint");
m_debugger_list->m_text_color_pc = gui::utils::get_label_color("debugger_frame_pc");; m_debugger_list->m_text_color_pc = gui::utils::get_label_color("debugger_frame_pc");
} }
} }
bool debugger_frame::eventFilter(QObject* object, QEvent* ev) bool debugger_frame::eventFilter(QObject* object, QEvent* event)
{ {
// There's no overlap between keys so returning true wouldn't matter. // There's no overlap between keys so returning true wouldn't matter.
if (object == m_debugger_list && ev->type() == QEvent::KeyPress) if (object == m_debugger_list && event->type() == QEvent::KeyPress)
{ {
keyPressEvent(static_cast<QKeyEvent*>(ev)); keyPressEvent(static_cast<QKeyEvent*>(event));
} }
return false; return false;
} }
@ -230,7 +230,7 @@ void debugger_frame::closeEvent(QCloseEvent *event)
void debugger_frame::showEvent(QShowEvent * event) void debugger_frame::showEvent(QShowEvent * event)
{ {
// resize splitter widgets // resize splitter widgets
if (!m_splitter->restoreState(xgui_settings->GetValue(gui::d_splitterState).toByteArray())) if (!m_splitter->restoreState(m_gui_settings->GetValue(gui::d_splitterState).toByteArray()))
{ {
const int width_right = width() / 3; const int width_right = width() / 3;
const int width_left = width() - width_right; const int width_left = width() - width_right;
@ -243,7 +243,7 @@ void debugger_frame::showEvent(QShowEvent * event)
void debugger_frame::hideEvent(QHideEvent * event) void debugger_frame::hideEvent(QHideEvent * event)
{ {
// save splitter state or it will resume its initial state on next show // save splitter state or it will resume its initial state on next show
xgui_settings->SetValue(gui::d_splitterState, m_splitter->saveState()); m_gui_settings->SetValue(gui::d_splitterState, m_splitter->saveState());
QDockWidget::hideEvent(event); QDockWidget::hideEvent(event);
} }
@ -280,7 +280,7 @@ void debugger_frame::keyPressEvent(QKeyEvent* event)
} }
const auto cpu = get_cpu(); const auto cpu = get_cpu();
int i = m_debugger_list->currentRow(); const int row = m_debugger_list->currentRow();
switch (event->key()) switch (event->key())
{ {
@ -320,6 +320,7 @@ void debugger_frame::keyPressEvent(QKeyEvent* event)
dlg->exec(); dlg->exec();
return; return;
} }
default: break;
} }
if (!cpu) if (!cpu)
@ -328,7 +329,7 @@ void debugger_frame::keyPressEvent(QKeyEvent* event)
} }
const u32 address_limits = (cpu->id_type() == 2 ? 0x3fffc : ~3); const u32 address_limits = (cpu->id_type() == 2 ? 0x3fffc : ~3);
const u32 pc = (i >= 0 ? m_debugger_list->m_pc + i * 4 : cpu->get_pc()) & address_limits; const u32 pc = (row >= 0 ? m_debugger_list->m_pc + row * 4 : cpu->get_pc()) & address_limits;
const auto modifiers = QApplication::keyboardModifiers(); const auto modifiers = QApplication::keyboardModifiers();
@ -346,6 +347,7 @@ void debugger_frame::keyPressEvent(QKeyEvent* event)
open_breakpoints_settings(); open_breakpoints_settings();
return; return;
} }
default: break;
} }
} }
else else
@ -386,9 +388,9 @@ void debugger_frame::keyPressEvent(QKeyEvent* event)
max = 0; max = 0;
} }
auto spu = static_cast<spu_thread*>(cpu); const auto spu = static_cast<spu_thread*>(cpu);
auto ptr = reinterpret_cast<const mfc_cmd_dump*>(vm::g_stat_addr + spu->vm_offset()); const auto ptr = reinterpret_cast<const mfc_cmd_dump*>(vm::g_stat_addr + spu->vm_offset());
std::string ret; std::string ret;
@ -497,8 +499,8 @@ void debugger_frame::keyPressEvent(QKeyEvent* event)
default: break; default: break;
} }
if (auto pos = std::basic_string_view<u32>(res.data(), 2).find_last_not_of(UINT32_MAX); pos != umax) if (const size_t pos = std::basic_string_view<u32>(res.data(), 2).find_last_not_of(UINT32_MAX); pos != umax)
m_debugger_list->ShowAddress(res[pos] - std::max(i, 0) * 4, true, true); m_debugger_list->ShowAddress(res[pos] - std::max(row, 0) * 4, true, true);
return; return;
} }
@ -518,6 +520,7 @@ void debugger_frame::keyPressEvent(QKeyEvent* event)
DoStep(false); DoStep(false);
return; return;
} }
default: break;
} }
} }
} }
@ -670,7 +673,7 @@ void debugger_frame::UpdateUnitList()
{ {
if (emu_state == system_state::stopped) return; if (emu_state == system_state::stopped) return;
QVariant var_cpu = QVariant::fromValue<std::pair<cpu_thread*, u32>>(std::make_pair(&cpu, id)); const QVariant var_cpu = QVariant::fromValue<std::pair<cpu_thread*, u32>>(std::make_pair(&cpu, id));
m_choice_units->addItem(qstr(id >> 24 == 0x55 ? "RSX[0x55555555]" : cpu.get_name()), var_cpu); m_choice_units->addItem(qstr(id >> 24 == 0x55 ? "RSX[0x55555555]" : cpu.get_name()), var_cpu);
if (!reselected && old_cpu == var_cpu) if (!reselected && old_cpu == var_cpu)
@ -689,7 +692,7 @@ void debugger_frame::UpdateUnitList()
idm::select<named_thread<ppu_thread>>(on_select); idm::select<named_thread<ppu_thread>>(on_select);
idm::select<named_thread<spu_thread>>(on_select); idm::select<named_thread<spu_thread>>(on_select);
if (auto render = g_fxo->try_get<rsx::thread>(); emu_state != system_state::stopped && render && render->ctrl) if (const auto render = g_fxo->try_get<rsx::thread>(); emu_state != system_state::stopped && render && render->ctrl)
{ {
on_select(render->id, *render); on_select(render->id, *render);
} }
@ -800,7 +803,7 @@ void debugger_frame::OnSelectUnit()
void debugger_frame::DoUpdate() void debugger_frame::DoUpdate()
{ {
// Check if we need to disable a step over bp // Check if we need to disable a step over bp
if (auto cpu0 = get_cpu(); cpu0 && m_last_step_over_breakpoint != umax && cpu0->get_pc() == m_last_step_over_breakpoint) if (const auto cpu0 = get_cpu(); cpu0 && m_last_step_over_breakpoint != umax && cpu0->get_pc() == m_last_step_over_breakpoint)
{ {
m_breakpoint_handler->RemoveBreakpoint(m_last_step_over_breakpoint); m_breakpoint_handler->RemoveBreakpoint(m_last_step_over_breakpoint);
m_last_step_over_breakpoint = -1; m_last_step_over_breakpoint = -1;
@ -821,9 +824,7 @@ void debugger_frame::WritePanels()
return; return;
} }
int loc; int loc = m_misc_state->verticalScrollBar()->value();
loc = m_misc_state->verticalScrollBar()->value();
m_misc_state->clear(); m_misc_state->clear();
m_misc_state->setText(qstr(cpu->dump_misc())); m_misc_state->setText(qstr(cpu->dump_misc()));
m_misc_state->verticalScrollBar()->setValue(loc); m_misc_state->verticalScrollBar()->setValue(loc);
@ -852,7 +853,7 @@ void debugger_frame::ShowGotoAddressDialog()
expression_input->setFont(m_mono); expression_input->setFont(m_mono);
expression_input->setMaxLength(18); expression_input->setMaxLength(18);
if (auto thread = get_cpu(); !thread || thread->id_type() != 2) if (const auto thread = get_cpu(); !thread || thread->id_type() != 2)
{ {
expression_input->setValidator(new QRegExpValidator(QRegExp("^(0[xX])?0*[a-fA-F0-9]{0,8}$"))); expression_input->setValidator(new QRegExpValidator(QRegExp("^(0[xX])?0*[a-fA-F0-9]{0,8}$")));
} }
@ -907,11 +908,11 @@ u64 debugger_frame::EvaluateExpression(const QString& expression)
const u64 res = static_cast<u64>(fixed_expression.toULong(&ok, 16)); const u64 res = static_cast<u64>(fixed_expression.toULong(&ok, 16));
if (ok) return res; if (ok) return res;
if (auto thread = get_cpu()) return thread->get_pc(); if (const auto thread = get_cpu()) return thread->get_pc();
return 0; return 0;
} }
void debugger_frame::ClearBreakpoints() void debugger_frame::ClearBreakpoints() const
{ {
m_breakpoint_list->ClearBreakpoints(); m_breakpoint_list->ClearBreakpoints();
} }
@ -936,14 +937,14 @@ void debugger_frame::DoStep(bool step_over)
{ {
bool should_step_over = step_over && cpu->id_type() == 1; bool should_step_over = step_over && cpu->id_type() == 1;
if (auto _state = +cpu->state; _state & s_pause_flags && _state & cpu_flag::wait && !(_state & cpu_flag::dbg_step)) if (const auto _state = +cpu->state; _state & s_pause_flags && _state & cpu_flag::wait && !(_state & cpu_flag::dbg_step))
{ {
if (should_step_over) if (should_step_over)
{ {
u32 current_instruction_pc = cpu->get_pc(); const u32 current_instruction_pc = cpu->get_pc();
// Set breakpoint on next instruction // Set breakpoint on next instruction
u32 next_instruction_pc = current_instruction_pc + 4; const u32 next_instruction_pc = current_instruction_pc + 4;
m_breakpoint_handler->AddBreakpoint(next_instruction_pc); m_breakpoint_handler->AddBreakpoint(next_instruction_pc);
// Undefine previous step over breakpoint if it hasnt been already // Undefine previous step over breakpoint if it hasnt been already
@ -977,7 +978,7 @@ void debugger_frame::DoStep(bool step_over)
UpdateUI(); UpdateUI();
} }
void debugger_frame::EnableUpdateTimer(bool enable) void debugger_frame::EnableUpdateTimer(bool enable) const
{ {
enable ? m_update->start(50) : m_update->stop(); enable ? m_update->start(50) : m_update->stop();
} }

View file

@ -69,17 +69,17 @@ class debugger_frame : public custom_dock_widget
instruction_editor_dialog* m_inst_editor = nullptr; instruction_editor_dialog* m_inst_editor = nullptr;
register_editor_dialog* m_reg_editor = nullptr; register_editor_dialog* m_reg_editor = nullptr;
std::shared_ptr<gui_settings> xgui_settings; std::shared_ptr<gui_settings> m_gui_settings;
cpu_thread* get_cpu(); cpu_thread* get_cpu();
std::function<cpu_thread*()> make_check_cpu(cpu_thread* cpu); std::function<cpu_thread*()> make_check_cpu(cpu_thread* cpu);
void open_breakpoints_settings(); void open_breakpoints_settings();
public: public:
explicit debugger_frame(std::shared_ptr<gui_settings> settings, QWidget *parent = 0); explicit debugger_frame(std::shared_ptr<gui_settings> settings, QWidget *parent = nullptr);
void SaveSettings(); void SaveSettings() const;
void ChangeColors(); void ChangeColors() const;
void UpdateUI(); void UpdateUI();
void UpdateUnitList(); void UpdateUnitList();
@ -89,7 +89,7 @@ public:
void EnableButtons(bool enable); void EnableButtons(bool enable);
void ShowGotoAddressDialog(); void ShowGotoAddressDialog();
u64 EvaluateExpression(const QString& expression); u64 EvaluateExpression(const QString& expression);
void ClearBreakpoints(); // Fallthrough method into breakpoint_list. void ClearBreakpoints() const; // Fallthrough method into breakpoint_list.
void ClearCallStack(); void ClearCallStack();
/** Needed so key press events work when other objects are selected in debugger_frame. */ /** Needed so key press events work when other objects are selected in debugger_frame. */
@ -103,7 +103,7 @@ protected:
Q_SIGNALS: Q_SIGNALS:
void DebugFrameClosed(); void DebugFrameClosed();
void CallStackUpdateRequested(std::vector<std::pair<u32, u32>> call_stack); void CallStackUpdateRequested(const std::vector<std::pair<u32, u32>>& call_stack);
public Q_SLOTS: public Q_SLOTS:
void DoStep(bool step_over = false); void DoStep(bool step_over = false);
@ -111,7 +111,7 @@ public Q_SLOTS:
private Q_SLOTS: private Q_SLOTS:
void OnSelectUnit(); void OnSelectUnit();
void ShowPC(); void ShowPC();
void EnableUpdateTimer(bool state); void EnableUpdateTimer(bool enable) const;
}; };
Q_DECLARE_METATYPE(u32) Q_DECLARE_METATYPE(u32)

View file

@ -19,9 +19,9 @@
constexpr auto qstr = QString::fromStdString; constexpr auto qstr = QString::fromStdString;
debugger_list::debugger_list(QWidget* parent, std::shared_ptr<gui_settings> settings, breakpoint_handler* handler) debugger_list::debugger_list(QWidget* parent, std::shared_ptr<gui_settings> gui_settings, breakpoint_handler* handler)
: QListWidget(parent) : QListWidget(parent)
, m_gui_settings(settings) , m_gui_settings(std::move(gui_settings))
, m_breakpoint_handler(handler) , m_breakpoint_handler(handler)
{ {
setWindowTitle(tr("ASM")); setWindowTitle(tr("ASM"));
@ -189,7 +189,6 @@ void debugger_list::keyPressEvent(QKeyEvent* event)
} }
return; return;
} }
default: break; default: break;
} }
} }
@ -281,7 +280,7 @@ void debugger_list::wheelEvent(QWheelEvent* event)
void debugger_list::resizeEvent(QResizeEvent* event) void debugger_list::resizeEvent(QResizeEvent* event)
{ {
Q_UNUSED(event); Q_UNUSED(event)
if (count() < 1 || visualItemRect(item(0)).height() < 1) if (count() < 1 || visualItemRect(item(0)).height() < 1)
{ {

View file

@ -50,7 +50,7 @@ private:
breakpoint_handler* m_breakpoint_handler; breakpoint_handler* m_breakpoint_handler;
cpu_thread* m_cpu = nullptr; cpu_thread* m_cpu = nullptr;
CPUDisAsm* m_disasm; CPUDisAsm* m_disasm = nullptr;
QDialog* m_cmd_detail = nullptr; QDialog* m_cmd_detail = nullptr;
QLabel* m_detail_label = nullptr; QLabel* m_detail_label = nullptr;
}; };

View file

@ -12,7 +12,7 @@ LOG_CHANNEL(network_log, "NETWORK");
usz curl_write_cb_compat(char* ptr, usz /*size*/, usz nmemb, void* userdata) usz curl_write_cb_compat(char* ptr, usz /*size*/, usz nmemb, void* userdata)
{ {
downloader* download = reinterpret_cast<downloader*>(userdata); downloader* download = static_cast<downloader*>(userdata);
return download->update_buffer(ptr, nmemb); return download->update_buffer(ptr, nmemb);
} }
@ -32,7 +32,7 @@ downloader::~downloader()
} }
} }
void downloader::start(const std::string& url, bool follow_location, bool show_progress_dialog, const QString& progress_dialog_title, bool keep_progress_dialog_open, int exptected_size) void downloader::start(const std::string& url, bool follow_location, bool show_progress_dialog, const QString& progress_dialog_title, bool keep_progress_dialog_open, int expected_size)
{ {
if (m_thread) if (m_thread)
{ {
@ -91,7 +91,7 @@ void downloader::start(const std::string& url, bool follow_location, bool show_p
if (show_progress_dialog) if (show_progress_dialog)
{ {
const int maximum = exptected_size > 0 ? exptected_size : 100; const int maximum = expected_size > 0 ? expected_size : 100;
if (m_progress_dialog) if (m_progress_dialog)
{ {
@ -121,7 +121,7 @@ void downloader::start(const std::string& url, bool follow_location, bool show_p
m_thread->start(); m_thread->start();
} }
void downloader::update_progress_dialog(const QString& title) void downloader::update_progress_dialog(const QString& title) const
{ {
if (m_progress_dialog) if (m_progress_dialog)
{ {
@ -191,7 +191,7 @@ usz downloader::update_buffer(char* data, usz size)
return size; return size;
} }
void downloader::handle_buffer_update(int size, int max) void downloader::handle_buffer_update(int size, int max) const
{ {
if (m_curl_abort) if (m_curl_abort)
{ {

View file

@ -17,7 +17,7 @@ public:
void start(const std::string& url, bool follow_location, bool show_progress_dialog, const QString& progress_dialog_title = "", bool keep_progress_dialog_open = false, int expected_size = -1); void start(const std::string& url, bool follow_location, bool show_progress_dialog, const QString& progress_dialog_title = "", bool keep_progress_dialog_open = false, int expected_size = -1);
usz update_buffer(char* data, usz size); usz update_buffer(char* data, usz size);
void update_progress_dialog(const QString& title); void update_progress_dialog(const QString& title) const;
void close_progress_dialog(); void close_progress_dialog();
progress_dialog* get_progress_dialog() const; progress_dialog* get_progress_dialog() const;
@ -25,7 +25,7 @@ public:
static std::string get_hash(const char* data, usz size, bool lower_case); static std::string get_hash(const char* data, usz size, bool lower_case);
private Q_SLOTS: private Q_SLOTS:
void handle_buffer_update(int size, int max); void handle_buffer_update(int size, int max) const;
Q_SIGNALS: Q_SIGNALS:
void signal_download_error(const QString& error); void signal_download_error(const QString& error);

View file

@ -67,10 +67,6 @@ emu_settings::emu_settings()
{ {
} }
emu_settings::~emu_settings()
{
}
bool emu_settings::Init() bool emu_settings::Init()
{ {
m_render_creator = new render_creator(this); m_render_creator = new render_creator(this);
@ -265,7 +261,7 @@ bool emu_settings::ValidateSettings(bool cleanup)
return is_clean; return is_clean;
} }
void emu_settings::SaveSettings() void emu_settings::SaveSettings() const
{ {
YAML::Emitter out; YAML::Emitter out;
emit_data(out, m_current_settings); emit_data(out, m_current_settings);
@ -342,7 +338,7 @@ void emu_settings::EnhanceComboBox(QComboBox* combobox, emu_settings_type type,
} }
// Since the QComboBox has localised strings, we can't just findText / findData, so we need to manually iterate through it to find our index // Since the QComboBox has localised strings, we can't just findText / findData, so we need to manually iterate through it to find our index
auto find_index = [&](const QString& value) const auto find_index = [&](const QString& value)
{ {
for (int i = 0; i < combobox->count(); i++) for (int i = 0; i < combobox->count(); i++)
{ {
@ -359,7 +355,7 @@ void emu_settings::EnhanceComboBox(QComboBox* combobox, emu_settings_type type,
const std::string selected = GetSetting(type); const std::string selected = GetSetting(type);
const QString selected_q = qstr(selected); const QString selected_q = qstr(selected);
int index = -1; int index;
if (is_ranged) if (is_ranged)
{ {
@ -389,7 +385,7 @@ void emu_settings::EnhanceComboBox(QComboBox* combobox, emu_settings_type type,
combobox->setCurrentIndex(index); combobox->setCurrentIndex(index);
connect(combobox, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [=, this](int index) connect(combobox, QOverload<int>::of(&QComboBox::currentIndexChanged), combobox, [this, is_ranged, combobox, type](int index)
{ {
if (is_ranged) if (is_ranged)
{ {
@ -765,14 +761,14 @@ void emu_settings::SaveSelectedLibraries(const std::vector<std::string>& libs)
m_current_settings["Core"]["Libraries Control"] = libs; m_current_settings["Core"]["Libraries Control"] = libs;
} }
QStringList emu_settings::GetSettingOptions(emu_settings_type type) const QStringList emu_settings::GetSettingOptions(emu_settings_type type)
{ {
return cfg_adapter::get_options(const_cast<cfg_location&&>(settings_location[type])); return cfg_adapter::get_options(const_cast<cfg_location&&>(settings_location[type]));
} }
std::string emu_settings::GetSettingDefault(emu_settings_type type) const std::string emu_settings::GetSettingDefault(emu_settings_type type) const
{ {
if (auto node = cfg_adapter::get_node(m_default_settings, settings_location[type]); node && node.IsScalar()) if (const auto node = cfg_adapter::get_node(m_default_settings, settings_location[type]); node && node.IsScalar())
{ {
return node.Scalar(); return node.Scalar();
} }
@ -783,7 +779,7 @@ std::string emu_settings::GetSettingDefault(emu_settings_type type) const
std::string emu_settings::GetSetting(emu_settings_type type) const std::string emu_settings::GetSetting(emu_settings_type type) const
{ {
if (auto node = cfg_adapter::get_node(m_current_settings, settings_location[type]); node && node.IsScalar()) if (const auto node = cfg_adapter::get_node(m_current_settings, settings_location[type]); node && node.IsScalar())
{ {
return node.Scalar(); return node.Scalar();
} }
@ -792,7 +788,7 @@ std::string emu_settings::GetSetting(emu_settings_type type) const
return ""; return "";
} }
void emu_settings::SetSetting(emu_settings_type type, const std::string& val) void emu_settings::SetSetting(emu_settings_type type, const std::string& val) const
{ {
cfg_adapter::get_node(m_current_settings, settings_location[type]) = val; cfg_adapter::get_node(m_current_settings, settings_location[type]) = val;
} }

View file

@ -32,7 +32,6 @@ public:
* Settings are only written when SaveSettings is called. * Settings are only written when SaveSettings is called.
*/ */
emu_settings(); emu_settings();
~emu_settings();
bool Init(); bool Init();
@ -49,10 +48,10 @@ public:
void EnhanceSlider(QSlider* slider, emu_settings_type type); void EnhanceSlider(QSlider* slider, emu_settings_type type);
/** Connects an integer spin box with the target settings type*/ /** Connects an integer spin box with the target settings type*/
void EnhanceSpinBox(QSpinBox* slider, emu_settings_type type, const QString& prefix = "", const QString& suffix = ""); void EnhanceSpinBox(QSpinBox* spinbox, emu_settings_type type, const QString& prefix = "", const QString& suffix = "");
/** Connects a double spin box with the target settings type*/ /** Connects a double spin box with the target settings type*/
void EnhanceDoubleSpinBox(QDoubleSpinBox* slider, emu_settings_type type, const QString& prefix = "", const QString& suffix = ""); void EnhanceDoubleSpinBox(QDoubleSpinBox* spinbox, emu_settings_type type, const QString& prefix = "", const QString& suffix = "");
/** Connects a line edit with the target settings type*/ /** Connects a line edit with the target settings type*/
void EnhanceLineEdit(QLineEdit* edit, emu_settings_type type); void EnhanceLineEdit(QLineEdit* edit, emu_settings_type type);
@ -64,7 +63,7 @@ public:
void SaveSelectedLibraries(const std::vector<std::string>& libs); void SaveSelectedLibraries(const std::vector<std::string>& libs);
/** Returns the valid options for a given setting.*/ /** Returns the valid options for a given setting.*/
QStringList GetSettingOptions(emu_settings_type type) const; static QStringList GetSettingOptions(emu_settings_type type);
/** Returns the default value of the setting type.*/ /** Returns the default value of the setting type.*/
std::string GetSettingDefault(emu_settings_type type) const; std::string GetSettingDefault(emu_settings_type type) const;
@ -73,7 +72,7 @@ public:
std::string GetSetting(emu_settings_type type) const; std::string GetSetting(emu_settings_type type) const;
/** Sets the setting type to a given value.*/ /** Sets the setting type to a given value.*/
void SetSetting(emu_settings_type type, const std::string& val); void SetSetting(emu_settings_type type, const std::string& val) const;
/** Gets all the renderer info for gpu settings.*/ /** Gets all the renderer info for gpu settings.*/
render_creator* m_render_creator = nullptr; render_creator* m_render_creator = nullptr;
@ -95,7 +94,7 @@ public:
public Q_SLOTS: public Q_SLOTS:
/** Writes the unsaved settings to file. Used in settings dialog on accept.*/ /** Writes the unsaved settings to file. Used in settings dialog on accept.*/
void SaveSettings(); void SaveSettings() const;
private: private:
YAML::Node m_default_settings; // The default settings as a YAML node. YAML::Node m_default_settings; // The default settings as a YAML node.
YAML::Node m_current_settings; // The current settings as a YAML node. YAML::Node m_current_settings; // The current settings as a YAML node.

View file

@ -9,5 +9,5 @@ class fatal_error_dialog : public QMessageBox
Q_OBJECT Q_OBJECT
public: public:
fatal_error_dialog(std::string_view text); explicit fatal_error_dialog(std::string_view text);
}; };

View file

@ -54,16 +54,15 @@ int find_dialog::count_all()
return 0; return 0;
} }
QTextCursor old_cursor = m_text_edit->textCursor(); const QTextCursor old_cursor = m_text_edit->textCursor();
m_text_edit->moveCursor(QTextCursor::Start); m_text_edit->moveCursor(QTextCursor::Start);
int old_line_index = -1; int old_line_index = -1;
int new_line_index = 0;
while (m_text_edit->find(m_find_bar->text())) while (m_text_edit->find(m_find_bar->text()))
{ {
m_count_total++; m_count_total++;
new_line_index = m_text_edit->textCursor().blockNumber(); const int new_line_index = m_text_edit->textCursor().blockNumber();
if (new_line_index != old_line_index) if (new_line_index != old_line_index)
{ {
@ -111,7 +110,7 @@ void find_dialog::find_previous()
m_text_edit->find(m_find_bar->text(), QTextDocument::FindBackward); m_text_edit->find(m_find_bar->text(), QTextDocument::FindBackward);
} }
void find_dialog::show_count() void find_dialog::show_count() const
{ {
m_label_count_lines->setText(tr("Counted in lines: %0").arg(m_count_lines)); m_label_count_lines->setText(tr("Counted in lines: %0").arg(m_count_lines));
m_label_count_total->setText(tr("Counted in total: %0").arg(m_count_total)); m_label_count_total->setText(tr("Counted in total: %0").arg(m_count_total));

View file

@ -31,5 +31,5 @@ private Q_SLOTS:
void find_last(); void find_last();
void find_next(); void find_next();
void find_previous(); void find_previous();
void show_count(); void show_count() const;
}; };

View file

@ -16,9 +16,9 @@ LOG_CHANNEL(compat_log, "Compat");
constexpr auto qstr = QString::fromStdString; constexpr auto qstr = QString::fromStdString;
inline std::string sstr(const QString& _in) { return _in.toStdString(); } inline std::string sstr(const QString& _in) { return _in.toStdString(); }
game_compatibility::game_compatibility(std::shared_ptr<gui_settings> settings, QWidget* parent) game_compatibility::game_compatibility(std::shared_ptr<gui_settings> gui_settings, QWidget* parent)
: QObject(parent) : QObject(parent)
, m_gui_settings(settings) , m_gui_settings(std::move(gui_settings))
{ {
m_filepath = m_gui_settings->GetSettingsDir() + "/compat_database.dat"; m_filepath = m_gui_settings->GetSettingsDir() + "/compat_database.dat";
m_downloader = new downloader(parent); m_downloader = new downloader(parent);
@ -33,12 +33,12 @@ void game_compatibility::handle_download_error(const QString& error)
Q_EMIT DownloadError(error); Q_EMIT DownloadError(error);
} }
void game_compatibility::handle_download_finished(const QByteArray& data) void game_compatibility::handle_download_finished(const QByteArray& content)
{ {
compat_log.notice("Database download finished"); compat_log.notice("Database download finished");
// Create new map from database and write database to file if database was valid // Create new map from database and write database to file if database was valid
if (ReadJSON(QJsonDocument::fromJson(data).object(), true)) if (ReadJSON(QJsonDocument::fromJson(content).object(), true))
{ {
// We have a new database in map, therefore refresh gamelist to new state // We have a new database in map, therefore refresh gamelist to new state
Q_EMIT DownloadFinished(); Q_EMIT DownloadFinished();
@ -57,7 +57,7 @@ void game_compatibility::handle_download_finished(const QByteArray& data)
return; return;
} }
file.write(data); file.write(content);
file.close(); file.close();
compat_log.success("Wrote database to file: %s", sstr(m_filepath)); compat_log.success("Wrote database to file: %s", sstr(m_filepath));
@ -206,13 +206,13 @@ void game_compatibility::RequestCompatibility(bool online)
return; return;
} }
const QByteArray data = file.readAll(); const QByteArray content = file.readAll();
file.close(); file.close();
compat_log.notice("Finished reading database from file: %s", sstr(m_filepath)); compat_log.notice("Finished reading database from file: %s", sstr(m_filepath));
// Create new map from database // Create new map from database
ReadJSON(QJsonDocument::fromJson(data).object(), online); ReadJSON(QJsonDocument::fromJson(content).object(), online);
return; return;
} }
@ -240,7 +240,7 @@ compat::status game_compatibility::GetCompatibility(const std::string& title_id)
return Status_Data.at("NoResult"); return Status_Data.at("NoResult");
} }
compat::status game_compatibility::GetStatusData(const QString& status) compat::status game_compatibility::GetStatusData(const QString& status) const
{ {
return Status_Data.at(status); return Status_Data.at(status);
} }
@ -249,18 +249,18 @@ compat::package_info game_compatibility::GetPkgInfo(const QString& pkg_path, gam
{ {
compat::package_info info; compat::package_info info;
package_reader reader(pkg_path.toStdString()); const package_reader reader(pkg_path.toStdString());
if (!reader.is_valid()) if (!reader.is_valid())
{ {
info.is_valid = false; info.is_valid = false;
return info; return info;
} }
psf::registry psf = reader.get_psf(); const psf::registry psf = reader.get_psf();
// TODO: localization of title and changelog // TODO: localization of title and changelog
std::string title_key = "TITLE"; const std::string title_key = "TITLE";
std::string changelog_key = "paramhip"; const std::string changelog_key = "paramhip";
info.path = pkg_path; info.path = pkg_path;
info.title = qstr(std::string(psf::get_string(psf, title_key))); // Let's read this from the psf first info.title = qstr(std::string(psf::get_string(psf, title_key))); // Let's read this from the psf first

View file

@ -37,13 +37,13 @@ namespace compat
std::string get_changelog(const std::string& type) const std::string get_changelog(const std::string& type) const
{ {
if (auto it = std::find_if(changelogs.begin(), changelogs.end(), [type](const pkg_changelog& cl) { return cl.type == type; }); if (const auto it = std::find_if(changelogs.cbegin(), changelogs.cend(), [type](const pkg_changelog& cl) { return cl.type == type; });
it != changelogs.end()) it != changelogs.cend())
{ {
return it->content; return it->content;
} }
if (auto it = std::find_if(changelogs.begin(), changelogs.end(), [](const pkg_changelog& cl) { return cl.type == "paramhip"; }); if (const auto it = std::find_if(changelogs.cbegin(), changelogs.cend(), [](const pkg_changelog& cl) { return cl.type == "paramhip"; });
it != changelogs.end()) it != changelogs.cend())
{ {
return it->content; return it->content;
} }
@ -52,12 +52,12 @@ namespace compat
std::string get_title(const std::string& type) const std::string get_title(const std::string& type) const
{ {
if (auto it = std::find_if(titles.begin(), titles.end(), [type](const pkg_title& t) { return t.type == type; }); if (const auto it = std::find_if(titles.cbegin(), titles.cend(), [type](const pkg_title& t) { return t.type == type; });
it != titles.end()) it != titles.cend())
{ {
return it->title; return it->title;
} }
if (auto it = std::find_if(titles.begin(), titles.end(), [](const pkg_title& t) { return t.type == "TITLE"; }); if (const auto it = std::find_if(titles.cbegin(), titles.cend(), [](const pkg_title& t) { return t.type == "TITLE"; });
it != titles.end()) it != titles.end())
{ {
return it->title; return it->title;
@ -80,7 +80,7 @@ namespace compat
/** Represents the json object that contains an app's information and some additional info that is used in the GUI */ /** Represents the json object that contains an app's information and some additional info that is used in the GUI */
struct status struct status
{ {
int index; int index = 0;
QString date; QString date;
QString color; QString color;
QString text; QString text;
@ -149,7 +149,7 @@ public:
compat::status GetCompatibility(const std::string& title_id); compat::status GetCompatibility(const std::string& title_id);
/** Returns the data for the requested status */ /** Returns the data for the requested status */
compat::status GetStatusData(const QString& status); compat::status GetStatusData(const QString& status) const;
/** Returns package information like title, version, changelog etc. */ /** Returns package information like title, version, changelog etc. */
static compat::package_info GetPkgInfo(const QString& pkg_path, game_compatibility* compat); static compat::package_info GetPkgInfo(const QString& pkg_path, game_compatibility* compat);
@ -161,13 +161,13 @@ Q_SIGNALS:
private Q_SLOTS: private Q_SLOTS:
void handle_download_error(const QString& error); void handle_download_error(const QString& error);
void handle_download_finished(const QByteArray& data); void handle_download_finished(const QByteArray& content);
}; };
class compat_pixmap : public QPixmap class compat_pixmap : public QPixmap
{ {
public: public:
compat_pixmap(const QColor& color, qreal pixel_ratio) : QPixmap(16 * pixel_ratio, 16 * pixel_ratio) compat_pixmap(const QColor& color, qreal pixel_ratio) : QPixmap(pixel_ratio * 16, pixel_ratio * 16)
{ {
fill(Qt::transparent); fill(Qt::transparent);

View file

@ -24,7 +24,6 @@
#include "Input/pad_thread.h" #include "Input/pad_thread.h"
#include <algorithm> #include <algorithm>
#include <iterator>
#include <memory> #include <memory>
#include <set> #include <set>
#include <regex> #include <regex>
@ -37,7 +36,6 @@
#include <QMessageBox> #include <QMessageBox>
#include <QScrollBar> #include <QScrollBar>
#include <QInputDialog> #include <QInputDialog>
#include <QToolTip>
#include <QApplication> #include <QApplication>
#include <QClipboard> #include <QClipboard>
#include <QFileDialog> #include <QFileDialog>
@ -49,9 +47,9 @@ inline std::string sstr(const QString& _in) { return _in.toStdString(); }
game_list_frame::game_list_frame(std::shared_ptr<gui_settings> gui_settings, std::shared_ptr<emu_settings> emu_settings, std::shared_ptr<persistent_settings> persistent_settings, QWidget* parent) game_list_frame::game_list_frame(std::shared_ptr<gui_settings> gui_settings, std::shared_ptr<emu_settings> emu_settings, std::shared_ptr<persistent_settings> persistent_settings, QWidget* parent)
: custom_dock_widget(tr("Game List"), parent) : custom_dock_widget(tr("Game List"), parent)
, m_gui_settings(gui_settings) , m_gui_settings(std::move(gui_settings))
, m_emu_settings(emu_settings) , m_emu_settings(std::move(emu_settings))
, m_persistent_settings(persistent_settings) , m_persistent_settings(std::move(persistent_settings))
{ {
m_icon_size = gui::gl_icon_size_min; // ensure a valid size m_icon_size = gui::gl_icon_size_min; // ensure a valid size
m_is_list_layout = m_gui_settings->GetValue(gui::gl_listMode).toBool(); m_is_list_layout = m_gui_settings->GetValue(gui::gl_listMode).toBool();
@ -239,7 +237,7 @@ game_list_frame::~game_list_frame()
SaveSettings(); SaveSettings();
} }
void game_list_frame::FixNarrowColumns() void game_list_frame::FixNarrowColumns() const
{ {
qApp->processEvents(); qApp->processEvents();
@ -258,7 +256,7 @@ void game_list_frame::FixNarrowColumns()
} }
} }
void game_list_frame::ResizeColumnsToContents(int spacing) void game_list_frame::ResizeColumnsToContents(int spacing) const
{ {
if (!m_game_list) if (!m_game_list)
{ {
@ -316,11 +314,11 @@ bool game_list_frame::IsEntryVisible(const game_info& game)
}; };
const QString serial = qstr(game->info.serial); const QString serial = qstr(game->info.serial);
bool is_visible = m_show_hidden || !m_hidden_list.contains(serial); const bool is_visible = m_show_hidden || !m_hidden_list.contains(serial);
return is_visible && matches_category() && SearchMatchesApp(qstr(game->info.name), serial); return is_visible && matches_category() && SearchMatchesApp(qstr(game->info.name), serial);
} }
void game_list_frame::SortGameList() void game_list_frame::SortGameList() const
{ {
// Back-up old header sizes to handle unwanted column resize in case of zero search results // Back-up old header sizes to handle unwanted column resize in case of zero search results
QList<int> column_widths; QList<int> column_widths;
@ -387,14 +385,14 @@ void game_list_frame::SortGameList()
m_game_list->resizeColumnToContents(gui::column_count - 1); m_game_list->resizeColumnToContents(gui::column_count - 1);
} }
QString game_list_frame::GetLastPlayedBySerial(const QString& serial) QString game_list_frame::GetLastPlayedBySerial(const QString& serial) const
{ {
return m_persistent_settings->GetLastPlayed(serial); return m_persistent_settings->GetLastPlayed(serial);
} }
std::string game_list_frame::GetCacheDirBySerial(const std::string& serial) std::string game_list_frame::GetCacheDirBySerial(const std::string& serial)
{ {
return Emu.GetCacheDir() + serial; return Emulator::GetCacheDir() + serial;
} }
std::string game_list_frame::GetDataDirBySerial(const std::string& serial) std::string game_list_frame::GetDataDirBySerial(const std::string& serial)
@ -414,7 +412,7 @@ void game_list_frame::Refresh(const bool from_drive, const bool scroll_after)
m_notes.clear(); m_notes.clear();
const std::string _hdd = Emulator::GetHddDir(); const std::string _hdd = Emulator::GetHddDir();
const std::string cat_unknown = sstr(category::cat_unknown); const std::string cat_unknown = sstr(cat::cat_unknown);
const std::string cat_unknown_localized = sstr(localized.category.unknown); const std::string cat_unknown_localized = sstr(localized.category.unknown);
std::vector<std::string> path_list; std::vector<std::string> path_list;
@ -476,9 +474,7 @@ void game_list_frame::Refresh(const bool from_drive, const bool scroll_after)
auto get_games = []() -> YAML::Node auto get_games = []() -> YAML::Node
{ {
fs::file games(fs::get_config_dir() + "/games.yml", fs::read + fs::create); if (const fs::file games = fs::file(fs::get_config_dir() + "/games.yml", fs::read + fs::create))
if (games)
{ {
auto [result, error] = yaml_load(games.to_string()); auto [result, error] = yaml_load(games.to_string());
@ -490,12 +486,8 @@ void game_list_frame::Refresh(const bool from_drive, const bool scroll_after)
return result; return result;
} }
else
{
game_list_log.error("Failed to load games.yml, check permissions.");
return {};
}
game_list_log.error("Failed to load games.yml, check permissions.");
return {}; return {};
}; };
@ -549,7 +541,7 @@ void game_list_frame::Refresh(const bool from_drive, const bool scroll_after)
const Localized thread_localized; const Localized thread_localized;
{ {
const std::string sfo_dir = Emulator::GetSfoDirFromGamePath(dir, Emu.GetUsr()); const std::string sfo_dir = Emulator::GetSfoDirFromGamePath(dir);
const psf::registry psf = psf::load_object(fs::file(sfo_dir + "/PARAM.SFO")); const psf::registry psf = psf::load_object(fs::file(sfo_dir + "/PARAM.SFO"));
@ -696,7 +688,7 @@ void game_list_frame::Refresh(const bool from_drive, const bool scroll_after)
for (auto&& g : games.pop_all()) for (auto&& g : games.pop_all())
{ {
m_game_data.push_back(std::move(g)); m_game_data.push_back(g);
} }
// Try to update the app version for disc games if there is a patch // Try to update the app version for disc games if there is a patch
@ -1090,9 +1082,9 @@ void game_list_frame::ShowContextMenu(const QPoint &pos)
if (action != icon_action::remove) if (action != icon_action::remove)
{ {
if (QFile file(icon_path); !file.copy(icon_path, game_icon_path)) if (!QFile::copy(icon_path, game_icon_path))
{ {
game_list_log.error("Could not import image '%s' to '%s'. %s", sstr(icon_path), sstr(game_icon_path), sstr(file.errorString())); game_list_log.error("Could not import image '%s' to '%s'.", sstr(icon_path), sstr(game_icon_path));
QMessageBox::warning(this, tr("Warning!"), tr("Failed to import the new image!")); QMessageBox::warning(this, tr("Warning!"), tr("Failed to import the new image!"));
} }
else else
@ -1315,11 +1307,11 @@ void game_list_frame::ShowContextMenu(const QPoint &pos)
// Disable options depending on software category // Disable options depending on software category
const QString category = qstr(current_game.category); const QString category = qstr(current_game.category);
if (category == cat_disc_game) if (category == cat::cat_disc_game)
{ {
remove_game->setEnabled(false); remove_game->setEnabled(false);
} }
else if (category != cat_hdd_game) else if (category != cat::cat_hdd_game)
{ {
check_compat->setEnabled(false); check_compat->setEnabled(false);
} }
@ -1342,7 +1334,7 @@ bool game_list_frame::CreatePPUCache(const game_info& game)
return true; return true;
} }
bool game_list_frame::RemoveCustomConfiguration(const std::string& title_id, game_info game, bool is_interactive) bool game_list_frame::RemoveCustomConfiguration(const std::string& title_id, const game_info& game, bool is_interactive)
{ {
const std::string config_path_new = Emulator::GetCustomConfigPath(title_id); const std::string config_path_new = Emulator::GetCustomConfigPath(title_id);
const std::string config_path_old = Emulator::GetCustomConfigPath(title_id, true); const std::string config_path_old = Emulator::GetCustomConfigPath(title_id, true);
@ -1384,7 +1376,7 @@ bool game_list_frame::RemoveCustomConfiguration(const std::string& title_id, gam
return result; return result;
} }
bool game_list_frame::RemoveCustomPadConfiguration(const std::string& title_id, game_info game, bool is_interactive) bool game_list_frame::RemoveCustomPadConfiguration(const std::string& title_id, const game_info& game, bool is_interactive)
{ {
const std::string config_dir = Emulator::GetCustomInputConfigDir(title_id); const std::string config_dir = Emulator::GetCustomInputConfigDir(title_id);
@ -1411,7 +1403,8 @@ bool game_list_frame::RemoveCustomPadConfiguration(const std::string& title_id,
game_list_log.notice("Removed pad configuration directory: %s", config_dir); game_list_log.notice("Removed pad configuration directory: %s", config_dir);
return true; return true;
} }
else if (is_interactive)
if (is_interactive)
{ {
QMessageBox::warning(this, tr("Warning!"), tr("Failed to completely remove pad configuration directory!")); QMessageBox::warning(this, tr("Warning!"), tr("Failed to completely remove pad configuration directory!"));
game_list_log.fatal("Failed to completely remove pad configuration directory: %s\nError: %s", config_dir, fs::g_tls_error); game_list_log.fatal("Failed to completely remove pad configuration directory: %s\nError: %s", config_dir, fs::g_tls_error);
@ -1803,7 +1796,7 @@ void game_list_frame::BatchRemoveShaderCaches()
QApplication::beep(); QApplication::beep();
} }
QPixmap game_list_frame::PaintedPixmap(QPixmap icon, bool paint_config_icon, bool paint_pad_config_icon, const QColor& compatibility_color) QPixmap game_list_frame::PaintedPixmap(const QPixmap& icon, bool paint_config_icon, bool paint_pad_config_icon, const QColor& compatibility_color) const
{ {
const qreal device_pixel_ratio = devicePixelRatioF(); const qreal device_pixel_ratio = devicePixelRatioF();
QSize canvas_size(320, 176); QSize canvas_size(320, 176);
@ -1900,7 +1893,7 @@ QPixmap game_list_frame::PaintedPixmap(QPixmap icon, bool paint_config_icon, boo
return canvas.scaled(m_icon_size * device_pixel_ratio, Qt::KeepAspectRatio, Qt::TransformationMode::SmoothTransformation); return canvas.scaled(m_icon_size * device_pixel_ratio, Qt::KeepAspectRatio, Qt::TransformationMode::SmoothTransformation);
} }
void game_list_frame::ShowCustomConfigIcon(game_info game) void game_list_frame::ShowCustomConfigIcon(const game_info& game)
{ {
if (!game) if (!game)
{ {
@ -1911,7 +1904,7 @@ void game_list_frame::ShowCustomConfigIcon(game_info game)
const bool has_custom_config = game->hasCustomConfig; const bool has_custom_config = game->hasCustomConfig;
const bool has_custom_pad_config = game->hasCustomPadConfig; const bool has_custom_pad_config = game->hasCustomPadConfig;
for (auto other_game : m_game_data) for (const auto& other_game : m_game_data)
{ {
if (other_game->info.serial == serial) if (other_game->info.serial == serial)
{ {
@ -2001,7 +1994,7 @@ bool game_list_frame::eventFilter(QObject *object, QEvent *event)
if (wheel_event->modifiers() & Qt::ControlModifier) if (wheel_event->modifiers() & Qt::ControlModifier)
{ {
QPoint num_steps = wheel_event->angleDelta() / 8 / 15; // http://doc.qt.io/qt-5/qwheelevent.html#pixelDelta const QPoint num_steps = wheel_event->angleDelta() / 8 / 15; // http://doc.qt.io/qt-5/qwheelevent.html#pixelDelta
const int value = num_steps.y(); const int value = num_steps.y();
Q_EMIT RequestIconSizeChange(value); Q_EMIT RequestIconSizeChange(value);
return true; return true;
@ -2038,7 +2031,7 @@ bool game_list_frame::eventFilter(QObject *object, QEvent *event)
if (!item || !item->isSelected()) if (!item || !item->isSelected())
return false; return false;
game_info gameinfo = GetGameInfoFromItem(item); const game_info gameinfo = GetGameInfoFromItem(item);
if (!gameinfo) if (!gameinfo)
return false; return false;
@ -2061,7 +2054,7 @@ void game_list_frame::PopulateGameList()
{ {
int selected_row = -1; int selected_row = -1;
std::string selected_item = CurrentSelectionPath(); const std::string selected_item = CurrentSelectionPath();
m_game_list->clearSelection(); m_game_list->clearSelection();
m_game_list->clearContents(); m_game_list->clearContents();
@ -2115,7 +2108,7 @@ void game_list_frame::PopulateGameList()
} }
// Move Support (http://www.psdevwiki.com/ps3/PARAM.SFO#ATTRIBUTE) // Move Support (http://www.psdevwiki.com/ps3/PARAM.SFO#ATTRIBUTE)
bool supports_move = game->info.attr & 0x800000; const bool supports_move = game->info.attr & 0x800000;
// Compatibility // Compatibility
custom_table_widget_item* compat_item = new custom_table_widget_item; custom_table_widget_item* compat_item = new custom_table_widget_item;
@ -2316,8 +2309,7 @@ std::string game_list_frame::CurrentSelectionPath()
if (var.canConvert<game_info>()) if (var.canConvert<game_info>())
{ {
auto game = var.value<game_info>(); if (const game_info game = var.value<game_info>())
if (game)
{ {
selection = game->info.path + game->info.icon_path; selection = game->info.path + game->info.icon_path;
} }
@ -2359,7 +2351,7 @@ std::string game_list_frame::GetStringFromU32(const u32& key, const std::map<u32
return sstr(string.join(", ")); return sstr(string.join(", "));
} }
game_info game_list_frame::GetGameInfoByMode(const QTableWidgetItem* item) game_info game_list_frame::GetGameInfoByMode(const QTableWidgetItem* item) const
{ {
if (!item) if (!item)
{ {
@ -2390,7 +2382,7 @@ game_info game_list_frame::GetGameInfoFromItem(const QTableWidgetItem* item)
return var.value<game_info>(); return var.value<game_info>();
} }
QColor game_list_frame::getGridCompatibilityColor(const QString& string) QColor game_list_frame::getGridCompatibilityColor(const QString& string) const
{ {
if (m_draw_compat_status_to_grid && !m_is_list_layout) if (m_draw_compat_status_to_grid && !m_is_list_layout)
{ {

View file

@ -44,10 +44,10 @@ public:
~game_list_frame(); ~game_list_frame();
/** Fix columns with width smaller than the minimal section size */ /** Fix columns with width smaller than the minimal section size */
void FixNarrowColumns(); void FixNarrowColumns() const;
/** Resizes the columns to their contents and adds a small spacing */ /** Resizes the columns to their contents and adds a small spacing */
void ResizeColumnsToContents(int spacing = 20); void ResizeColumnsToContents(int spacing = 20) const;
/** Refresh the gamelist with/without loading game data from files. Public so that main frame can refresh after vfs or install */ /** Refresh the gamelist with/without loading game data from files. Public so that main frame can refresh after vfs or install */
void Refresh(const bool from_drive = false, const bool scroll_after = true); void Refresh(const bool from_drive = false, const bool scroll_after = true);
@ -69,7 +69,7 @@ public:
void SetShowHidden(bool show); void SetShowHidden(bool show);
game_compatibility* GetGameCompatibility() const { return m_game_compat; }; game_compatibility* GetGameCompatibility() const { return m_game_compat; }
QList<game_info> GetGameInfo() const; QList<game_info> GetGameInfo() const;
@ -105,30 +105,30 @@ protected:
void resizeEvent(QResizeEvent *event) override; void resizeEvent(QResizeEvent *event) override;
bool eventFilter(QObject *object, QEvent *event) override; bool eventFilter(QObject *object, QEvent *event) override;
private: private:
QPixmap PaintedPixmap(QPixmap icon, bool paint_config_icon = false, bool paint_pad_config_icon = false, const QColor& color = QColor()); QPixmap PaintedPixmap(const QPixmap& icon, bool paint_config_icon = false, bool paint_pad_config_icon = false, const QColor& color = QColor()) const;
QColor getGridCompatibilityColor(const QString& string); QColor getGridCompatibilityColor(const QString& string) const;
void ShowCustomConfigIcon(game_info game); void ShowCustomConfigIcon(const game_info& game);
void PopulateGameList(); void PopulateGameList();
void PopulateGameGrid(int maxCols, const QSize& image_size, const QColor& image_color); void PopulateGameGrid(int maxCols, const QSize& image_size, const QColor& image_color);
bool IsEntryVisible(const game_info& game); bool IsEntryVisible(const game_info& game);
void SortGameList(); void SortGameList() const;
bool SearchMatchesApp(const QString& name, const QString& serial) const; bool SearchMatchesApp(const QString& name, const QString& serial) const;
bool RemoveCustomConfiguration(const std::string& title_id, game_info game = nullptr, bool is_interactive = false); bool RemoveCustomConfiguration(const std::string& title_id, const game_info& game = nullptr, bool is_interactive = false);
bool RemoveCustomPadConfiguration(const std::string& title_id, game_info game = nullptr, bool is_interactive = false); bool RemoveCustomPadConfiguration(const std::string& title_id, const game_info& game = nullptr, bool is_interactive = false);
bool RemoveShadersCache(const std::string& base_dir, bool is_interactive = false); bool RemoveShadersCache(const std::string& base_dir, bool is_interactive = false);
bool RemovePPUCache(const std::string& base_dir, bool is_interactive = false); bool RemovePPUCache(const std::string& base_dir, bool is_interactive = false);
bool RemoveSPUCache(const std::string& base_dir, bool is_interactive = false); bool RemoveSPUCache(const std::string& base_dir, bool is_interactive = false);
bool CreatePPUCache(const game_info& game); static bool CreatePPUCache(const game_info& game);
QString GetLastPlayedBySerial(const QString& serial); QString GetLastPlayedBySerial(const QString& serial) const;
std::string GetCacheDirBySerial(const std::string& serial); static std::string GetCacheDirBySerial(const std::string& serial);
std::string GetDataDirBySerial(const std::string& serial); static std::string GetDataDirBySerial(const std::string& serial);
std::string CurrentSelectionPath(); std::string CurrentSelectionPath();
std::string GetStringFromU32(const u32& key, const std::map<u32, QString>& map, bool combined = false); static std::string GetStringFromU32(const u32& key, const std::map<u32, QString>& map, bool combined = false);
game_info GetGameInfoByMode(const QTableWidgetItem* item); game_info GetGameInfoByMode(const QTableWidgetItem* item) const;
game_info GetGameInfoFromItem(const QTableWidgetItem* item); static game_info GetGameInfoFromItem(const QTableWidgetItem* item);
// Which widget we are displaying depends on if we are in grid or list mode. // Which widget we are displaying depends on if we are in grid or list mode.
QMainWindow* m_game_dock = nullptr; QMainWindow* m_game_dock = nullptr;

View file

@ -5,8 +5,13 @@
#include <QHeaderView> #include <QHeaderView>
#include <QScrollBar> #include <QScrollBar>
game_list_grid::game_list_grid(const QSize& icon_size, const QColor& icon_color, const qreal& margin_factor, const qreal& text_factor, const bool& showText) game_list_grid::game_list_grid(const QSize& icon_size, QColor icon_color, const qreal& margin_factor, const qreal& text_factor, const bool& showText)
: game_list(), m_icon_size(icon_size), m_icon_color(icon_color), m_margin_factor(margin_factor), m_text_factor(text_factor), m_text_enabled(showText) : game_list()
, m_icon_size(icon_size)
, m_icon_color(std::move(icon_color))
, m_margin_factor(margin_factor)
, m_text_factor(text_factor)
, m_text_enabled(showText)
{ {
setObjectName("game_grid"); setObjectName("game_grid");
@ -35,16 +40,12 @@ game_list_grid::game_list_grid(const QSize& icon_size, const QColor& icon_color,
setShowGrid(false); setShowGrid(false);
} }
game_list_grid::~game_list_grid()
{
}
void game_list_grid::enableText(const bool& enabled) void game_list_grid::enableText(const bool& enabled)
{ {
m_text_enabled = enabled; m_text_enabled = enabled;
} }
void game_list_grid::setIconSize(const QSize& size) void game_list_grid::setIconSize(const QSize& size) const
{ {
if (m_text_enabled) if (m_text_enabled)
{ {
@ -72,7 +73,7 @@ void game_list_grid::addItem(const QPixmap& img, const QString& name, const int&
} }
// define offset for raw image placement // define offset for raw image placement
QPoint offset = QPoint(m_icon_size.width() * m_margin_factor, m_icon_size.height() * m_margin_factor); const QPoint offset = QPoint(m_icon_size.width() * m_margin_factor, m_icon_size.height() * m_margin_factor);
// create empty canvas for expanded image // create empty canvas for expanded image
QImage exp_img = QImage((exp_size * device_pixel_ratio).toSize(), QImage::Format_ARGB32); QImage exp_img = QImage((exp_size * device_pixel_ratio).toSize(), QImage::Format_ARGB32);
@ -103,7 +104,7 @@ void game_list_grid::addItem(const QPixmap& img, const QString& name, const int&
setItem(row, col, item); setItem(row, col, item);
} }
qreal game_list_grid::getMarginFactor() qreal game_list_grid::getMarginFactor() const
{ {
return m_margin_factor; return m_margin_factor;
} }

View file

@ -15,14 +15,13 @@ class game_list_grid : public game_list
bool m_text_enabled = true; bool m_text_enabled = true;
public: public:
explicit game_list_grid(const QSize& icon_size, const QColor& icon_color, const qreal& margin_factor, const qreal& text_factor, const bool& showText); explicit game_list_grid(const QSize& icon_size, QColor icon_color, const qreal& margin_factor, const qreal& text_factor, const bool& showText);
~game_list_grid();
void enableText(const bool& enabled); void enableText(const bool& enabled);
void setIconSize(const QSize& size); void setIconSize(const QSize& size) const;
void addItem(const QPixmap& img, const QString& name, const int& row, const int& col); void addItem(const QPixmap& img, const QString& name, const int& row, const int& col);
qreal getMarginFactor(); qreal getMarginFactor() const;
private: private:
game_list_grid_delegate* grid_item_delegate; game_list_grid_delegate* grid_item_delegate;

View file

@ -5,13 +5,9 @@ game_list_grid_delegate::game_list_grid_delegate(const QSize& size, const qreal&
{ {
} }
game_list_grid_delegate::~game_list_grid_delegate()
{
}
void game_list_grid_delegate::initStyleOption(QStyleOptionViewItem * option, const QModelIndex & index) const void game_list_grid_delegate::initStyleOption(QStyleOptionViewItem * option, const QModelIndex & index) const
{ {
Q_UNUSED(index); Q_UNUSED(index)
// Remove the focus frame around selected items // Remove the focus frame around selected items
option->state &= ~QStyle::State_HasFocus; option->state &= ~QStyle::State_HasFocus;
@ -22,13 +18,13 @@ void game_list_grid_delegate::initStyleOption(QStyleOptionViewItem * option, con
void game_list_grid_delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const void game_list_grid_delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{ {
QRect r = option.rect; const QRect r = option.rect;
painter->setRenderHints(QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform); painter->setRenderHints(QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform);
painter->eraseRect(r); painter->eraseRect(r);
// Get title and image // Get title and image
QPixmap image = qvariant_cast<QPixmap>(index.data(Qt::DecorationRole)); const QPixmap image = qvariant_cast<QPixmap>(index.data(Qt::DecorationRole));
const QString title = index.data(Qt::DisplayRole).toString(); const QString title = index.data(Qt::DisplayRole).toString();
// Paint from our stylesheet // Paint from our stylesheet
@ -60,8 +56,8 @@ void game_list_grid_delegate::paint(QPainter *painter, const QStyleOptionViewIte
QSize game_list_grid_delegate::sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const QSize game_list_grid_delegate::sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const
{ {
Q_UNUSED(option); Q_UNUSED(option)
Q_UNUSED(index); Q_UNUSED(index)
return m_size; return m_size;
} }

View file

@ -6,13 +6,12 @@
class game_list_grid_delegate : public QStyledItemDelegate class game_list_grid_delegate : public QStyledItemDelegate
{ {
public: public:
game_list_grid_delegate(const QSize& imageSize, const qreal& margin_factor, const qreal& margin_ratio, QObject *parent = 0); game_list_grid_delegate(const QSize& imageSize, const qreal& margin_factor, const qreal& margin_ratio, QObject *parent = nullptr);
virtual void initStyleOption(QStyleOptionViewItem *option, const QModelIndex &index) const override; void initStyleOption(QStyleOptionViewItem *option, const QModelIndex &index) const override;
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const override; QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const override;
void setItemSize(const QSize& size); void setItemSize(const QSize& size);
virtual ~game_list_grid_delegate();
private: private:
QSize m_size; QSize m_size;
qreal m_margin_factor; qreal m_margin_factor;

View file

@ -5,8 +5,8 @@
#include <QOpenGLContext> #include <QOpenGLContext>
#include <QOffscreenSurface> #include <QOffscreenSurface>
gl_gs_frame::gl_gs_frame(QScreen* screen, const QRect& geometry, const QIcon& appIcon, const std::shared_ptr<gui_settings>& gui_settings) gl_gs_frame::gl_gs_frame(QScreen* screen, const QRect& geometry, const QIcon& appIcon, std::shared_ptr<gui_settings> gui_settings)
: gs_frame(screen, geometry, appIcon, gui_settings) : gs_frame(screen, geometry, appIcon, std::move(gui_settings))
{ {
setSurfaceType(QSurface::OpenGLSurface); setSurfaceType(QSurface::OpenGLSurface);

View file

@ -1,7 +1,5 @@
#pragma once #pragma once
#include "util/types.hpp"
#include "gs_frame.h" #include "gs_frame.h"
#include <memory> #include <memory>
@ -20,10 +18,10 @@ private:
GLContext *m_primary_context = nullptr; GLContext *m_primary_context = nullptr;
public: public:
explicit gl_gs_frame(QScreen* screen, const QRect& geometry, const QIcon& appIcon, const std::shared_ptr<gui_settings>& gui_settings); explicit gl_gs_frame(QScreen* screen, const QRect& geometry, const QIcon& appIcon, std::shared_ptr<gui_settings> gui_settings);
draw_context_t make_context() override; draw_context_t make_context() override;
void set_current(draw_context_t context) override; void set_current(draw_context_t ctx) override;
void delete_context(draw_context_t context) override; void delete_context(draw_context_t ctx) override;
void flip(draw_context_t context, bool skip_frame=false) override; void flip(draw_context_t context, bool skip_frame=false) override;
}; };

View file

@ -38,7 +38,6 @@
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
#include <QWinTHumbnailToolbar>
#include <QWinTHumbnailToolbutton> #include <QWinTHumbnailToolbutton>
#elif HAVE_QTDBUS #elif HAVE_QTDBUS
#include <QtDBus/QDBusMessage> #include <QtDBus/QDBusMessage>
@ -52,18 +51,18 @@ extern atomic_t<bool> g_user_asked_for_frame_capture;
constexpr auto qstr = QString::fromStdString; constexpr auto qstr = QString::fromStdString;
gs_frame::gs_frame(QScreen* screen, const QRect& geometry, const QIcon& appIcon, const std::shared_ptr<gui_settings>& gui_settings) gs_frame::gs_frame(QScreen* screen, const QRect& geometry, const QIcon& appIcon, std::shared_ptr<gui_settings> gui_settings)
: QWindow() : QWindow()
, m_initial_geometry(geometry) , m_initial_geometry(geometry)
, m_gui_settings(gui_settings) , m_gui_settings(std::move(gui_settings))
{ {
m_disable_mouse = gui_settings->GetValue(gui::gs_disableMouse).toBool(); m_disable_mouse = m_gui_settings->GetValue(gui::gs_disableMouse).toBool();
m_disable_kb_hotkeys = gui_settings->GetValue(gui::gs_disableKbHotkeys).toBool(); m_disable_kb_hotkeys = m_gui_settings->GetValue(gui::gs_disableKbHotkeys).toBool();
m_show_mouse_in_fullscreen = gui_settings->GetValue(gui::gs_showMouseFs).toBool(); m_show_mouse_in_fullscreen = m_gui_settings->GetValue(gui::gs_showMouseFs).toBool();
m_hide_mouse_after_idletime = gui_settings->GetValue(gui::gs_hideMouseIdle).toBool(); m_hide_mouse_after_idletime = m_gui_settings->GetValue(gui::gs_hideMouseIdle).toBool();
m_hide_mouse_idletime = gui_settings->GetValue(gui::gs_hideMouseIdleTime).toUInt(); m_hide_mouse_idletime = m_gui_settings->GetValue(gui::gs_hideMouseIdleTime).toUInt();
m_window_title = qstr(Emu.GetFormattedTitle(0)); m_window_title = Emu.GetFormattedTitle(0);
if (!appIcon.isNull()) if (!appIcon.isNull())
{ {
@ -80,7 +79,7 @@ gs_frame::gs_frame(QScreen* screen, const QRect& geometry, const QIcon& appIcon,
setMinimumHeight(90); setMinimumHeight(90);
setScreen(screen); setScreen(screen);
setGeometry(geometry); setGeometry(geometry);
setTitle(m_window_title); setTitle(qstr(m_window_title));
setVisibility(Hidden); setVisibility(Hidden);
create(); create();
@ -131,7 +130,7 @@ gs_frame::~gs_frame()
void gs_frame::paintEvent(QPaintEvent *event) void gs_frame::paintEvent(QPaintEvent *event)
{ {
Q_UNUSED(event); Q_UNUSED(event)
} }
void gs_frame::showEvent(QShowEvent *event) void gs_frame::showEvent(QShowEvent *event)
@ -379,21 +378,21 @@ draw_context_t gs_frame::make_context()
return nullptr; return nullptr;
} }
void gs_frame::set_current(draw_context_t ctx) void gs_frame::set_current(draw_context_t context)
{ {
Q_UNUSED(ctx); Q_UNUSED(context)
} }
void gs_frame::delete_context(draw_context_t ctx) void gs_frame::delete_context(draw_context_t context)
{ {
Q_UNUSED(ctx); Q_UNUSED(context)
} }
int gs_frame::client_width() int gs_frame::client_width()
{ {
#ifdef _WIN32 #ifdef _WIN32
RECT rect; RECT rect;
if (GetClientRect(HWND(winId()), &rect)) if (GetClientRect(reinterpret_cast<HWND>(winId()), &rect))
{ {
return rect.right - rect.left; return rect.right - rect.left;
} }
@ -405,7 +404,7 @@ int gs_frame::client_height()
{ {
#ifdef _WIN32 #ifdef _WIN32
RECT rect; RECT rect;
if (GetClientRect(HWND(winId()), &rect)) if (GetClientRect(reinterpret_cast<HWND>(winId()), &rect))
{ {
return rect.bottom - rect.top; return rect.bottom - rect.top;
} }
@ -429,7 +428,7 @@ void gs_frame::flip(draw_context_t, bool /*skip_frame*/)
if (fps_t.GetElapsedTimeInSec() >= 0.5) if (fps_t.GetElapsedTimeInSec() >= 0.5)
{ {
const QString new_title = qstr(Emu.GetFormattedTitle(m_frames / fps_t.GetElapsedTimeInSec())); std::string new_title = Emu.GetFormattedTitle(m_frames / fps_t.GetElapsedTimeInSec());
if (new_title != m_window_title) if (new_title != m_window_title)
{ {
@ -437,7 +436,7 @@ void gs_frame::flip(draw_context_t, bool /*skip_frame*/)
Emu.CallAfter([this, title = std::move(new_title)]() Emu.CallAfter([this, title = std::move(new_title)]()
{ {
setTitle(title); setTitle(qstr(title));
}); });
} }
@ -446,10 +445,10 @@ void gs_frame::flip(draw_context_t, bool /*skip_frame*/)
} }
} }
void gs_frame::take_screenshot(const std::vector<u8> sshot_data, const u32 sshot_width, const u32 sshot_height, bool is_bgra) void gs_frame::take_screenshot(std::vector<u8> data, const u32 sshot_width, const u32 sshot_height, bool is_bgra)
{ {
std::thread( std::thread(
[sshot_width, sshot_height, is_bgra](const std::vector<u8> sshot_data) [sshot_width, sshot_height, is_bgra](std::vector<u8> sshot_data)
{ {
screenshot_log.notice("Taking screenshot (%dx%d)", sshot_width, sshot_height); screenshot_log.notice("Taking screenshot (%dx%d)", sshot_width, sshot_height);
@ -513,10 +512,10 @@ void gs_frame::take_screenshot(const std::vector<u8> sshot_data, const u32 sshot
const QDateTime date_time = QDateTime::currentDateTime(); const QDateTime date_time = QDateTime::currentDateTime();
const std::string creation_time = date_time.toString("yyyy:MM:dd hh:mm:ss").toStdString(); const std::string creation_time = date_time.toString("yyyy:MM:dd hh:mm:ss").toStdString();
const std::string title_id = Emu.GetTitleID();
const std::string photo_title = manager.get_photo_title(); const std::string photo_title = manager.get_photo_title();
const std::string game_title = manager.get_game_title(); const std::string game_title = manager.get_game_title();
const std::string game_comment = manager.get_game_comment(); const std::string game_comment = manager.get_game_comment();
const std::string& title_id = Emu.GetTitleID();
// Write tEXt chunk // Write tEXt chunk
text[num_text].compression = PNG_TEXT_COMPRESSION_NONE; text[num_text].compression = PNG_TEXT_COMPRESSION_NONE;
@ -553,7 +552,7 @@ void gs_frame::take_screenshot(const std::vector<u8> sshot_data, const u32 sshot
const auto write_png = [&]() const auto write_png = [&]()
{ {
scoped_png_ptrs ptrs; const scoped_png_ptrs ptrs;
png_set_IHDR(ptrs.write_ptr, ptrs.info_ptr, sshot_width, sshot_height, 8, PNG_COLOR_TYPE_RGBA, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); png_set_IHDR(ptrs.write_ptr, ptrs.info_ptr, sshot_width, sshot_height, 8, PNG_COLOR_TYPE_RGBA, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
png_set_text(ptrs.write_ptr, ptrs.info_ptr, text, 6); png_set_text(ptrs.write_ptr, ptrs.info_ptr, text, 6);
png_set_rows(ptrs.write_ptr, ptrs.info_ptr, &rows[0]); png_set_rows(ptrs.write_ptr, ptrs.info_ptr, &rows[0]);
@ -648,7 +647,7 @@ void gs_frame::take_screenshot(const std::vector<u8> sshot_data, const u32 sshot
return; return;
}, },
std::move(sshot_data)) std::move(data))
.detach(); .detach();
} }

View file

@ -39,7 +39,7 @@ private:
QTimer m_mousehide_timer; QTimer m_mousehide_timer;
u64 m_frames = 0; u64 m_frames = 0;
QString m_window_title; std::string m_window_title;
atomic_t<bool> m_show_mouse = true; atomic_t<bool> m_show_mouse = true;
bool m_disable_mouse = false; bool m_disable_mouse = false;
bool m_disable_kb_hotkeys = false; bool m_disable_kb_hotkeys = false;
@ -50,7 +50,7 @@ private:
bool m_flip_showed_frame = false; bool m_flip_showed_frame = false;
public: public:
explicit gs_frame(QScreen* screen, const QRect& geometry, const QIcon& appIcon, const std::shared_ptr<gui_settings>& gui_settings); explicit gs_frame(QScreen* screen, const QRect& geometry, const QIcon& appIcon, std::shared_ptr<gui_settings> gui_settings);
~gs_frame(); ~gs_frame();
draw_context_t make_context() override; draw_context_t make_context() override;
@ -70,11 +70,11 @@ public:
*/ */
bool get_mouse_lock_state(); bool get_mouse_lock_state();
void take_screenshot(const std::vector<u8> sshot_data, const u32 sshot_width, const u32 sshot_height, bool is_bgra) override; void take_screenshot(std::vector<u8> data, const u32 sshot_width, const u32 sshot_height, bool is_bgra) override;
protected: protected:
virtual void paintEvent(QPaintEvent *event); virtual void paintEvent(QPaintEvent *event);
virtual void showEvent(QShowEvent *event) override; void showEvent(QShowEvent *event) override;
void keyPressEvent(QKeyEvent *keyEvent) override; void keyPressEvent(QKeyEvent *keyEvent) override;

View file

@ -266,9 +266,9 @@ std::unique_ptr<gs_frame> gui_application::get_gs_frame()
const auto frame_geometry = gui::utils::create_centered_window_geometry(screen, source_geometry, w, h); const auto frame_geometry = gui::utils::create_centered_window_geometry(screen, source_geometry, w, h);
const auto app_icon = m_main_window ? m_main_window->GetAppIcon() : gui::utils::get_app_icon_from_path(Emu.GetBoot(), Emu.GetTitleID()); const auto app_icon = m_main_window ? m_main_window->GetAppIcon() : gui::utils::get_app_icon_from_path(Emu.GetBoot(), Emu.GetTitleID());
gs_frame* frame; gs_frame* frame = nullptr;
switch (video_renderer type = g_cfg.video.renderer) switch (g_cfg.video.renderer.get())
{ {
case video_renderer::opengl: case video_renderer::opengl:
{ {
@ -281,7 +281,6 @@ std::unique_ptr<gs_frame> gui_application::get_gs_frame()
frame = new gs_frame(screen, frame_geometry, app_icon, m_gui_settings); frame = new gs_frame(screen, frame_geometry, app_icon, m_gui_settings);
break; break;
} }
default: fmt::throw_exception("Invalid video renderer: %s", type);
} }
m_game_window = frame; m_game_window = frame;
@ -322,7 +321,7 @@ void gui_application::InitializeCallbacks()
callbacks.init_gs_render = []() callbacks.init_gs_render = []()
{ {
switch (video_renderer type = g_cfg.video.renderer) switch (g_cfg.video.renderer.get())
{ {
case video_renderer::null: case video_renderer::null:
{ {
@ -341,10 +340,6 @@ void gui_application::InitializeCallbacks()
break; break;
} }
#endif #endif
default:
{
fmt::throw_exception("Invalid video renderer: %s", type);
}
} }
}; };
@ -565,7 +560,7 @@ void gui_application::OnEmuSettingsChange()
} }
} }
Emu.ConfigureLogs(); Emulator::ConfigureLogs();
audio::configure_audio(); audio::configure_audio();
rsx::overlays::reset_performance_overlay(); rsx::overlays::reset_performance_overlay();
} }

View file

@ -58,7 +58,7 @@ private:
void SwitchTranslator(QTranslator& translator, const QString& filename, const QString& language_code); void SwitchTranslator(QTranslator& translator, const QString& filename, const QString& language_code);
void LoadLanguage(const QString& language_code); void LoadLanguage(const QString& language_code);
QStringList GetAvailableLanguageCodes(); static QStringList GetAvailableLanguageCodes();
void InitializeCallbacks(); void InitializeCallbacks();
void InitializeConnects(); void InitializeConnects();
@ -84,7 +84,7 @@ private:
private Q_SLOTS: private Q_SLOTS:
void OnChangeStyleSheetRequest(); void OnChangeStyleSheetRequest();
void OnEmuSettingsChange(); static void OnEmuSettingsChange();
Q_SIGNALS: Q_SIGNALS:
void OnEmulatorRun(bool start_playtime); void OnEmulatorRun(bool start_playtime);
@ -96,5 +96,5 @@ Q_SIGNALS:
void RequestCallAfter(const std::function<void()>& func); void RequestCallAfter(const std::function<void()>& func);
private Q_SLOTS: private Q_SLOTS:
void HandleCallAfter(const std::function<void()>& func); static void HandleCallAfter(const std::function<void()>& func);
}; };

View file

@ -54,7 +54,7 @@ bool gui_settings::ChangeToConfig(const QString& config_name)
return true; return true;
} }
void gui_settings::Reset(bool remove_meta) void gui_settings::Reset(bool remove_meta) const
{ {
if (remove_meta) if (remove_meta)
{ {
@ -68,25 +68,25 @@ void gui_settings::Reset(bool remove_meta)
} }
} }
QStringList gui_settings::GetGameListCategoryFilters() QStringList gui_settings::GetGameListCategoryFilters() const
{ {
QStringList filterList; QStringList filterList;
if (GetCategoryVisibility(Category::HDD_Game)) filterList.append(category::cat_hdd_game); if (GetCategoryVisibility(Category::HDD_Game)) filterList.append(cat::cat_hdd_game);
if (GetCategoryVisibility(Category::Disc_Game)) filterList.append(category::cat_disc_game); if (GetCategoryVisibility(Category::Disc_Game)) filterList.append(cat::cat_disc_game);
if (GetCategoryVisibility(Category::PS1_Game)) filterList.append(category::cat_ps1_game); if (GetCategoryVisibility(Category::PS1_Game)) filterList.append(cat::cat_ps1_game);
if (GetCategoryVisibility(Category::PS2_Game)) filterList.append(category::ps2_games); if (GetCategoryVisibility(Category::PS2_Game)) filterList.append(cat::ps2_games);
if (GetCategoryVisibility(Category::PSP_Game)) filterList.append(category::psp_games); if (GetCategoryVisibility(Category::PSP_Game)) filterList.append(cat::psp_games);
if (GetCategoryVisibility(Category::Home)) filterList.append(category::cat_home); if (GetCategoryVisibility(Category::Home)) filterList.append(cat::cat_home);
if (GetCategoryVisibility(Category::Media)) filterList.append(category::media); if (GetCategoryVisibility(Category::Media)) filterList.append(cat::media);
if (GetCategoryVisibility(Category::Data)) filterList.append(category::data); if (GetCategoryVisibility(Category::Data)) filterList.append(cat::data);
if (GetCategoryVisibility(Category::Unknown_Cat)) filterList.append(category::cat_unknown); if (GetCategoryVisibility(Category::Unknown_Cat)) filterList.append(cat::cat_unknown);
if (GetCategoryVisibility(Category::Others)) filterList.append(category::others); if (GetCategoryVisibility(Category::Others)) filterList.append(cat::others);
return filterList; return filterList;
} }
bool gui_settings::GetCategoryVisibility(int cat) bool gui_settings::GetCategoryVisibility(int cat) const
{ {
gui_save value; gui_save value;
@ -120,7 +120,7 @@ bool gui_settings::GetCategoryVisibility(int cat)
return GetValue(value).toBool(); return GetValue(value).toBool();
} }
void gui_settings::SetCategoryVisibility(int cat, const bool& val) void gui_settings::SetCategoryVisibility(int cat, const bool& val) const
{ {
gui_save value; gui_save value;
@ -211,7 +211,6 @@ bool gui_settings::GetBootConfirmation(QWidget* parent, const gui_save& gui_save
{ {
QString title = tr("Close Running Game?"); QString title = tr("Close Running Game?");
QString message = tr("Performing this action will close the current game.\nDo you really want to continue?\n\nAny unsaved progress will be lost!\n"); QString message = tr("Performing this action will close the current game.\nDo you really want to continue?\n\nAny unsaved progress will be lost!\n");
auto icon = QMessageBox::Question;
if (gui_save_entry == gui::ib_confirm_boot) if (gui_save_entry == gui::ib_confirm_boot)
{ {
@ -225,7 +224,7 @@ bool gui_settings::GetBootConfirmation(QWidget* parent, const gui_save& gui_save
int result = QMessageBox::Yes; int result = QMessageBox::Yes;
ShowBox(icon, title, message, gui_save_entry, &result, parent); ShowBox(QMessageBox::Question, title, message, gui_save_entry, &result, parent);
if (result != QMessageBox::Yes) if (result != QMessageBox::Yes)
{ {
@ -236,12 +235,12 @@ bool gui_settings::GetBootConfirmation(QWidget* parent, const gui_save& gui_save
return true; return true;
} }
void gui_settings::SetGamelistColVisibility(int col, bool val) void gui_settings::SetGamelistColVisibility(int col, bool val) const
{ {
SetValue(GetGuiSaveForColumn(col), val); SetValue(GetGuiSaveForColumn(col), val);
} }
void gui_settings::SetCustomColor(int col, const QColor& val) void gui_settings::SetCustomColor(int col, const QColor& val) const
{ {
SetValue(gui_save(gui::meta, "CustomColor" + QString::number(col), gui::gl_icon_color), val); SetValue(gui_save(gui::meta, "CustomColor" + QString::number(col), gui::gl_icon_color), val);
} }
@ -253,22 +252,22 @@ void gui_settings::SaveCurrentConfig(const QString& config_name)
ChangeToConfig(config_name); ChangeToConfig(config_name);
} }
logs::level gui_settings::GetLogLevel() logs::level gui_settings::GetLogLevel() const
{ {
return logs::level{GetValue(gui::l_level).toUInt()}; return logs::level{GetValue(gui::l_level).toUInt()};
} }
bool gui_settings::GetGamelistColVisibility(int col) bool gui_settings::GetGamelistColVisibility(int col) const
{ {
return GetValue(GetGuiSaveForColumn(col)).toBool(); return GetValue(GetGuiSaveForColumn(col)).toBool();
} }
QColor gui_settings::GetCustomColor(int col) QColor gui_settings::GetCustomColor(int col) const
{ {
return GetValue(gui_save(gui::meta, "CustomColor" + QString::number(col), gui::gl_icon_color)).value<QColor>(); return GetValue(gui_save(gui::meta, "CustomColor" + QString::number(col), gui::gl_icon_color)).value<QColor>();
} }
QStringList gui_settings::GetConfigEntries() QStringList gui_settings::GetConfigEntries() const
{ {
const QStringList name_filter = QStringList("*.ini"); const QStringList name_filter = QStringList("*.ini");
const QFileInfoList entries = m_settings_dir.entryInfoList(name_filter, QDir::Files); const QFileInfoList entries = m_settings_dir.entryInfoList(name_filter, QDir::Files);
@ -284,7 +283,7 @@ QStringList gui_settings::GetConfigEntries()
} }
// Save the name of the used config to the default settings file // Save the name of the used config to the default settings file
void gui_settings::SaveConfigNameToDefault(const QString& config_name) void gui_settings::SaveConfigNameToDefault(const QString& config_name) const
{ {
if (m_current_name == gui::Settings) if (m_current_name == gui::Settings)
{ {
@ -300,7 +299,7 @@ void gui_settings::SaveConfigNameToDefault(const QString& config_name)
} }
} }
void gui_settings::BackupSettingsToTarget(const QString& config_name) void gui_settings::BackupSettingsToTarget(const QString& config_name) const
{ {
QSettings target(ComputeSettingsDir() + config_name + ".ini", QSettings::Format::IniFormat); QSettings target(ComputeSettingsDir() + config_name + ".ini", QSettings::Format::IniFormat);
@ -315,7 +314,7 @@ void gui_settings::BackupSettingsToTarget(const QString& config_name)
target.sync(); target.sync();
} }
QStringList gui_settings::GetStylesheetEntries() QStringList gui_settings::GetStylesheetEntries() const
{ {
const QStringList name_filter = QStringList("*.qss"); const QStringList name_filter = QStringList("*.qss");
QStringList res = gui::utils::get_dir_entries(m_settings_dir, name_filter); QStringList res = gui::utils::get_dir_entries(m_settings_dir, name_filter);

View file

@ -70,9 +70,10 @@ namespace gui
case column_compat: case column_compat:
return "column_compat"; return "column_compat";
case column_count: case column_count:
default:
return ""; return "";
} }
fmt::throw_exception("get_game_list_column_name: Invalid column");
} }
const QSize gl_icon_size_min = QSize(40, 22); const QSize gl_icon_size_min = QSize(40, 22);
@ -84,8 +85,8 @@ namespace gui
inline int get_Index(const QSize& current) inline int get_Index(const QSize& current)
{ {
int size_delta = gl_icon_size_max.width() - gl_icon_size_min.width(); const int size_delta = gl_icon_size_max.width() - gl_icon_size_min.width();
int current_delta = current.width() - gl_icon_size_min.width(); const int current_delta = current.width() - gl_icon_size_min.width();
return gl_max_slider_pos * current_delta / size_delta; return gl_max_slider_pos * current_delta / size_delta;
} }
@ -248,28 +249,28 @@ public:
/** Changes the settings file to the destination preset*/ /** Changes the settings file to the destination preset*/
bool ChangeToConfig(const QString& config_name); bool ChangeToConfig(const QString& config_name);
bool GetCategoryVisibility(int cat); bool GetCategoryVisibility(int cat) const;
void ShowConfirmationBox(const QString& title, const QString& text, const gui_save& entry, int* result, QWidget* parent); void ShowConfirmationBox(const QString& title, const QString& text, const gui_save& entry, int* result, QWidget* parent);
void ShowInfoBox(const QString& title, const QString& text, const gui_save& entry, QWidget* parent); void ShowInfoBox(const QString& title, const QString& text, const gui_save& entry, QWidget* parent);
bool GetBootConfirmation(QWidget* parent, const gui_save& gui_save_entry = gui_save()); bool GetBootConfirmation(QWidget* parent, const gui_save& gui_save_entry = gui_save());
logs::level GetLogLevel(); logs::level GetLogLevel() const;
bool GetGamelistColVisibility(int col); bool GetGamelistColVisibility(int col) const;
QColor GetCustomColor(int col); QColor GetCustomColor(int col) const;
QStringList GetConfigEntries(); QStringList GetConfigEntries() const;
QStringList GetStylesheetEntries(); QStringList GetStylesheetEntries() const;
QStringList GetGameListCategoryFilters(); QStringList GetGameListCategoryFilters() const;
public Q_SLOTS: public Q_SLOTS:
void Reset(bool remove_meta = false); void Reset(bool remove_meta = false) const;
/** Sets the visibility of the chosen category. */ /** Sets the visibility of the chosen category. */
void SetCategoryVisibility(int cat, const bool& val); void SetCategoryVisibility(int cat, const bool& val) const;
void SetGamelistColVisibility(int col, bool val); void SetGamelistColVisibility(int col, bool val) const;
void SetCustomColor(int col, const QColor& val); void SetCustomColor(int col, const QColor& val) const;
void SaveCurrentConfig(const QString& config_name); void SaveCurrentConfig(const QString& config_name);
@ -277,9 +278,7 @@ public Q_SLOTS:
static gui_save GetGuiSaveForColumn(int col); static gui_save GetGuiSaveForColumn(int col);
private: private:
void SaveConfigNameToDefault(const QString& config_name); void SaveConfigNameToDefault(const QString& config_name) const;
void BackupSettingsToTarget(const QString& config_name); void BackupSettingsToTarget(const QString& config_name) const;
void ShowBox(QMessageBox::Icon icon, const QString& title, const QString& text, const gui_save& entry, int* result, QWidget* parent, bool always_on_top); void ShowBox(QMessageBox::Icon icon, const QString& title, const QString& text, const gui_save& entry, int* result, QWidget* parent, bool always_on_top);
QString m_current_name;
}; };

View file

@ -41,14 +41,14 @@ input_dialog::~input_dialog()
{ {
} }
void input_dialog::set_clear_button_enabled(bool enabled) void input_dialog::set_clear_button_enabled(bool enabled) const
{ {
m_input->setClearButtonEnabled(enabled); m_input->setClearButtonEnabled(enabled);
} }
void input_dialog::set_input_font(const QFont& font, bool fix_width, char sample) void input_dialog::set_input_font(const QFont& font, bool fix_width, char sample) const
{ {
if (int max = m_input->maxLength(); max > 0 && fix_width && std::isprint(static_cast<uchar>(sample))) if (const int max = m_input->maxLength(); max > 0 && fix_width && std::isprint(static_cast<uchar>(sample)))
{ {
const QString str = qstr(std::string(static_cast<usz>(max), sample)); const QString str = qstr(std::string(static_cast<usz>(max), sample));
m_input->setFixedWidth(gui::utils::get_label_width(str, &font)); m_input->setFixedWidth(gui::utils::get_label_width(str, &font));
@ -57,12 +57,12 @@ void input_dialog::set_input_font(const QFont& font, bool fix_width, char sample
m_input->setFont(font); m_input->setFont(font);
} }
void input_dialog::set_validator(const QValidator* validator) void input_dialog::set_validator(const QValidator* validator) const
{ {
m_input->setValidator(validator); m_input->setValidator(validator);
} }
void input_dialog::set_button_enabled(QDialogButtonBox::StandardButton id, bool enabled) void input_dialog::set_button_enabled(QDialogButtonBox::StandardButton id, bool enabled) const
{ {
if (QPushButton* button = m_button_box->button(id)) if (QPushButton* button = m_button_box->button(id))
{ {
@ -70,7 +70,7 @@ void input_dialog::set_button_enabled(QDialogButtonBox::StandardButton id, bool
} }
} }
void input_dialog::set_label_text(const QString& text) void input_dialog::set_label_text(const QString& text) const
{ {
m_label->setText(text); m_label->setText(text);
} }

View file

@ -15,11 +15,11 @@ public:
input_dialog(int max_length, const QString& text, const QString& title, const QString& label, const QString& placeholder, QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); input_dialog(int max_length, const QString& text, const QString& title, const QString& label, const QString& placeholder, QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
~input_dialog(); ~input_dialog();
void set_label_text(const QString& text); void set_label_text(const QString& text) const;
void set_validator(const QValidator* validator); void set_validator(const QValidator* validator) const;
void set_clear_button_enabled(bool enable); void set_clear_button_enabled(bool enable) const;
void set_input_font(const QFont& font, bool fix_width, char sample = '\0'); void set_input_font(const QFont& font, bool fix_width, char sample = '\0') const;
void set_button_enabled(QDialogButtonBox::StandardButton id, bool enabled); void set_button_enabled(QDialogButtonBox::StandardButton id, bool enabled) const;
QString get_input_text() const; QString get_input_text() const;
private: private:

View file

@ -26,7 +26,7 @@ instruction_editor_dialog::instruction_editor_dialog(QWidget *parent, u32 _pc, C
const auto cpu = m_get_cpu(); const auto cpu = m_get_cpu();
m_cpu_offset = cpu && cpu->id_type() == 2 ? static_cast<spu_thread&>(*cpu).ls : vm::g_sudo_addr; m_cpu_offset = cpu && cpu->id_type() == 2 ? static_cast<spu_thread&>(*cpu).ls : vm::g_sudo_addr;
QString instruction = qstr(fmt::format("%08x", *reinterpret_cast<be_t<u32>*>(m_cpu_offset + m_pc))); const QString instruction = qstr(fmt::format("%08x", *reinterpret_cast<be_t<u32>*>(m_cpu_offset + m_pc)));
QVBoxLayout* vbox_panel(new QVBoxLayout()); QVBoxLayout* vbox_panel(new QVBoxLayout());
QHBoxLayout* hbox_panel(new QHBoxLayout()); QHBoxLayout* hbox_panel(new QHBoxLayout());
@ -72,7 +72,7 @@ instruction_editor_dialog::instruction_editor_dialog(QWidget *parent, u32 _pc, C
setLayout(vbox_panel); setLayout(vbox_panel);
// Events // Events
connect(button_ok, &QAbstractButton::clicked, [=, this]() connect(button_ok, &QAbstractButton::clicked, [this]()
{ {
const auto cpu = m_get_cpu(); const auto cpu = m_get_cpu();
@ -83,13 +83,14 @@ instruction_editor_dialog::instruction_editor_dialog(QWidget *parent, u32 _pc, C
} }
bool ok; bool ok;
ulong opcode = m_instr->text().toULong(&ok, 16); const ulong opcode = m_instr->text().toULong(&ok, 16);
if (!ok || opcode > UINT32_MAX) if (!ok || opcode > UINT32_MAX)
{ {
QMessageBox::critical(this, tr("Error"), tr("Failed to parse PPU instruction.")); QMessageBox::critical(this, tr("Error"), tr("Failed to parse PPU instruction."));
return; return;
} }
else if (cpu->id_type() == 1)
if (cpu->id_type() == 1)
{ {
if (!ppu_patch(m_pc, static_cast<u32>(opcode))) if (!ppu_patch(m_pc, static_cast<u32>(opcode)))
{ {
@ -111,11 +112,11 @@ instruction_editor_dialog::instruction_editor_dialog(QWidget *parent, u32 _pc, C
updatePreview(); updatePreview();
} }
void instruction_editor_dialog::updatePreview() void instruction_editor_dialog::updatePreview() const
{ {
bool ok; bool ok;
ulong opcode = m_instr->text().toULong(&ok, 16); ulong opcode = m_instr->text().toULong(&ok, 16);
Q_UNUSED(opcode); Q_UNUSED(opcode)
if (ok) if (ok)
{ {

View file

@ -25,5 +25,5 @@ private:
public: public:
instruction_editor_dialog(QWidget *parent, u32 _pc, CPUDisAsm* _disasm, std::function<cpu_thread*()> func); instruction_editor_dialog(QWidget *parent, u32 _pc, CPUDisAsm* _disasm, std::function<cpu_thread*()> func);
void updatePreview(); void updatePreview() const;
}; };

View file

@ -9,7 +9,6 @@
#include "Emu/IdManager.h" #include "Emu/IdManager.h"
#include "Emu/Cell/PPUThread.h" #include "Emu/Cell/PPUThread.h"
#include "Emu/Cell/SPUThread.h" #include "Emu/Cell/SPUThread.h"
#include "Emu/Cell/RawSPUThread.h"
#include "Emu/Cell/lv2/sys_lwmutex.h" #include "Emu/Cell/lv2/sys_lwmutex.h"
#include "Emu/Cell/lv2/sys_lwcond.h" #include "Emu/Cell/lv2/sys_lwcond.h"
#include "Emu/Cell/lv2/sys_mutex.h" #include "Emu/Cell/lv2/sys_mutex.h"
@ -304,7 +303,7 @@ void kernel_explorer::Update()
idm::select<lv2_obj>([&](u32 id, lv2_obj& obj) idm::select<lv2_obj>([&](u32 id, lv2_obj& obj)
{ {
auto node = find_node(m_tree, id >> 24); const auto node = find_node(m_tree, id >> 24);
if (!node) if (!node)
{ {
return; return;
@ -705,7 +704,7 @@ void kernel_explorer::Update()
} }
} }
} }
while (0); while (false);
idm::select<lv2_fs_object>([&](u32 id, lv2_fs_object& fo) idm::select<lv2_fs_object>([&](u32 id, lv2_fs_object& fo)
{ {
@ -726,7 +725,7 @@ void kernel_explorer::Update()
continue; continue;
} }
switch (int type = node->data(0, kernel_item_role::type_role).toInt()) switch (const int type = node->data(0, kernel_item_role::type_role).toInt())
{ {
case kernel_item_type::leaf: case kernel_item_type::leaf:
{ {

View file

@ -26,7 +26,7 @@ class kernel_explorer : public QDialog
}; };
public: public:
kernel_explorer(QWidget* parent); explicit kernel_explorer(QWidget* parent);
private: private:
QTreeWidget* m_tree; QTreeWidget* m_tree;

View file

@ -1,9 +1,5 @@
#include "localized.h" #include "localized.h"
Localized::Localized()
{
}
QString Localized::GetVerboseTimeByMs(quint64 elapsed_ms, bool show_days) const QString Localized::GetVerboseTimeByMs(quint64 elapsed_ms, bool show_days) const
{ {
const quint64 elapsed_seconds = (elapsed_ms / 1000) + ((elapsed_ms % 1000) > 0 ? 1 : 0); const quint64 elapsed_seconds = (elapsed_ms / 1000) + ((elapsed_ms % 1000) > 0 ? 1 : 0);
@ -18,40 +14,34 @@ QString Localized::GetVerboseTimeByMs(quint64 elapsed_ms, bool show_days) const
const quint64 minutes = (elapsed_seconds % 3600) / 60; const quint64 minutes = (elapsed_seconds % 3600) / 60;
const quint64 seconds = (elapsed_seconds % 3600) % 60; const quint64 seconds = (elapsed_seconds % 3600) % 60;
const QString str_days = tr("%Ln day(s)", "", days); QString str_days = tr("%Ln day(s)", "", days);
const QString str_hours = tr("%Ln hour(s)", "", hours); QString str_hours = tr("%Ln hour(s)", "", hours);
const QString str_minutes = tr("%Ln minute(s)", "", minutes); QString str_minutes = tr("%Ln minute(s)", "", minutes);
const QString str_seconds = tr("%Ln second(s)", "", seconds); QString str_seconds = tr("%Ln second(s)", "", seconds);
if (days != 0) if (days != 0)
{ {
if (hours == 0) if (hours == 0)
return str_days; return str_days;
else
return tr("%0 and %1", "Days and hours").arg(str_days).arg(str_hours); return tr("%0 and %1", "Days and hours").arg(str_days).arg(str_hours);
} }
else
{
if (hours != 0) if (hours != 0)
{ {
if (minutes == 0) if (minutes == 0)
return str_hours; return str_hours;
else
return tr("%0 and %1", "Hours and minutes").arg(str_hours).arg(str_minutes); return tr("%0 and %1", "Hours and minutes").arg(str_hours).arg(str_minutes);
} }
else
{
if (minutes != 0) if (minutes != 0)
{ {
if (seconds != 0) if (seconds != 0)
return tr("%0 and %1", "Minutes and seconds").arg(str_minutes).arg(str_seconds); return tr("%0 and %1", "Minutes and seconds").arg(str_minutes).arg(str_seconds);
else
return str_minutes; return str_minutes;
} }
else
{
return str_seconds; return str_seconds;
}
}
}
} }

View file

@ -9,15 +9,12 @@
typedef std::map<const QString, const QString> localized_cat; typedef std::map<const QString, const QString> localized_cat;
using namespace category;
class Localized : public QObject class Localized : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
Localized() {}
Localized();
QString GetVerboseTimeByMs(quint64 elapsed_ms, bool show_days = false) const; QString GetVerboseTimeByMs(quint64 elapsed_ms, bool show_days = false) const;
@ -63,31 +60,31 @@ public:
const localized_cat cat_boot = const localized_cat cat_boot =
{ {
{ cat_app_music, app_music }, // media { cat::cat_app_music, app_music }, // media
{ cat_app_photo, app_photo }, // media { cat::cat_app_photo, app_photo }, // media
{ cat_app_tv , app_tv }, // media { cat::cat_app_tv , app_tv }, // media
{ cat_app_video, app_video }, // media { cat::cat_app_video, app_video }, // media
{ cat_bc_video , bc_video }, // media { cat::cat_bc_video , bc_video }, // media
{ cat_web_tv , web_tv }, // media { cat::cat_web_tv , web_tv }, // media
{ cat_home , home }, // home { cat::cat_home , home }, // home
{ cat_network , network }, // other { cat::cat_network , network }, // other
{ cat_store_fe , store_fe }, // other { cat::cat_store_fe , store_fe }, // other
{ cat_disc_game, disc_game }, // disc_game { cat::cat_disc_game, disc_game }, // disc_game
{ cat_hdd_game , hdd_game }, // hdd_game { cat::cat_hdd_game , hdd_game }, // hdd_game
{ cat_ps2_game , ps2_game }, // ps2_games { cat::cat_ps2_game , ps2_game }, // ps2_games
{ cat_ps2_inst , ps2_inst }, // ps2_games { cat::cat_ps2_inst , ps2_inst }, // ps2_games
{ cat_ps1_game , ps1_game }, // ps1_game { cat::cat_ps1_game , ps1_game }, // ps1_game
{ cat_psp_game , psp_game }, // psp_games { cat::cat_psp_game , psp_game }, // psp_games
{ cat_psp_mini , psp_mini }, // psp_games { cat::cat_psp_mini , psp_mini }, // psp_games
{ cat_psp_rema , psp_rema }, // psp_games { cat::cat_psp_rema , psp_rema }, // psp_games
}; };
const localized_cat cat_data = const localized_cat cat_data =
{ {
{ cat_ps3_data, ps3_data }, // data { cat::cat_ps3_data, ps3_data }, // data
{ cat_ps2_data, ps2_data }, // data { cat::cat_ps2_data, ps2_data }, // data
{ cat_ps3_save, ps3_save }, // data { cat::cat_ps3_save, ps3_save }, // data
{ cat_psp_save, psp_save } // data { cat::cat_psp_save, psp_save } // data
}; };
} category; } category;

View file

@ -17,8 +17,6 @@
#include <deque> #include <deque>
#include <mutex> #include <mutex>
#include "util/sysinfo.hpp"
extern fs::file g_tty; extern fs::file g_tty;
extern atomic_t<s64> g_tty_size; extern atomic_t<s64> g_tty_size;
extern std::array<std::deque<std::string>, 16> g_tty_input; extern std::array<std::deque<std::string>, 16> g_tty_input;
@ -55,7 +53,7 @@ struct gui_listener : logs::listener
void log(u64 stamp, const logs::message& msg, const std::string& prefix, const std::string& text) override void log(u64 stamp, const logs::message& msg, const std::string& prefix, const std::string& text) override
{ {
Q_UNUSED(stamp); Q_UNUSED(stamp)
if (msg.sev <= enabled) if (msg.sev <= enabled)
{ {
@ -164,7 +162,7 @@ log_frame::log_frame(std::shared_ptr<gui_settings> guiSettings, QWidget *parent)
timer->start(10); timer->start(10);
} }
void log_frame::SetLogLevel(logs::level lev) void log_frame::SetLogLevel(logs::level lev) const
{ {
switch (lev) switch (lev)
{ {
@ -204,12 +202,10 @@ void log_frame::SetLogLevel(logs::level lev)
m_trace_act->trigger(); m_trace_act->trigger();
break; break;
} }
default:
m_warning_act->trigger();
} }
} }
void log_frame::SetTTYLogging(bool val) void log_frame::SetTTYLogging(bool val) const
{ {
m_tty_act->setChecked(val); m_tty_act->setChecked(val);
} }
@ -450,6 +446,7 @@ void log_frame::RepaintTextColors()
QTextCursor tty_cursor = m_tty->textCursor(); QTextCursor tty_cursor = m_tty->textCursor();
QTextCharFormat text_format = tty_cursor.charFormat(); QTextCharFormat text_format = tty_cursor.charFormat();
text_format.setForeground(gui::utils::get_label_color("tty_text")); text_format.setForeground(gui::utils::get_label_color("tty_text"));
tty_cursor.setCharFormat(text_format);
m_tty->setTextCursor(tty_cursor); m_tty->setTextCursor(tty_cursor);
// Repaint log with new colors // Repaint log with new colors
@ -601,7 +598,6 @@ void log_frame::UpdateUI()
case logs::level::warning: text = QStringLiteral("W "); break; case logs::level::warning: text = QStringLiteral("W "); break;
case logs::level::notice: text = QStringLiteral("! "); break; case logs::level::notice: text = QStringLiteral("! "); break;
case logs::level::trace: text = QStringLiteral("T "); break; case logs::level::trace: text = QStringLiteral("T "); break;
default: continue;
} }
// Print UTF-8 text. // Print UTF-8 text.

View file

@ -37,8 +37,8 @@ protected:
private Q_SLOTS: private Q_SLOTS:
void UpdateUI(); void UpdateUI();
private: private:
void SetLogLevel(logs::level lev); void SetLogLevel(logs::level lev) const;
void SetTTYLogging(bool val); void SetTTYLogging(bool val) const;
void CreateAndConnectActions(); void CreateAndConnectActions();

View file

@ -22,8 +22,8 @@ inline std::string sstr(const QString& _in)
return _in.toStdString(); return _in.toStdString();
} }
log_viewer::log_viewer(std::shared_ptr<gui_settings> settings) log_viewer::log_viewer(std::shared_ptr<gui_settings> gui_settings)
: m_gui_settings(settings) : m_gui_settings(std::move(gui_settings))
{ {
setWindowTitle(tr("Log Viewer")); setWindowTitle(tr("Log Viewer"));
setObjectName("log_viewer"); setObjectName("log_viewer");
@ -95,7 +95,7 @@ void log_viewer::show_context_menu(const QPoint& pos)
menu.exec(origin); menu.exec(origin);
} }
void log_viewer::show_log() void log_viewer::show_log() const
{ {
if (m_path_last.isEmpty()) if (m_path_last.isEmpty())
{ {

View file

@ -17,7 +17,7 @@ private Q_SLOTS:
void show_context_menu(const QPoint& pos); void show_context_menu(const QPoint& pos);
private: private:
void show_log(); void show_log() const;
bool is_valid_file(const QMimeData& md, bool save = false); bool is_valid_file(const QMimeData& md, bool save = false);
std::shared_ptr<gui_settings> m_gui_settings; std::shared_ptr<gui_settings> m_gui_settings;

View file

@ -66,9 +66,9 @@ inline std::string sstr(const QString& _in) { return _in.toStdString(); }
main_window::main_window(std::shared_ptr<gui_settings> gui_settings, std::shared_ptr<emu_settings> emu_settings, std::shared_ptr<persistent_settings> persistent_settings, QWidget *parent) main_window::main_window(std::shared_ptr<gui_settings> gui_settings, std::shared_ptr<emu_settings> emu_settings, std::shared_ptr<persistent_settings> persistent_settings, QWidget *parent)
: QMainWindow(parent) : QMainWindow(parent)
, ui(new Ui::main_window) , ui(new Ui::main_window)
, m_gui_settings(gui_settings) , m_gui_settings(std::move(gui_settings))
, m_emu_settings(emu_settings) , m_emu_settings(std::move(emu_settings))
, m_persistent_settings(persistent_settings) , m_persistent_settings(std::move(persistent_settings))
{ {
Q_INIT_RESOURCE(resources); Q_INIT_RESOURCE(resources);
@ -248,7 +248,7 @@ QString main_window::GetCurrentTitle()
} }
// returns appIcon // returns appIcon
QIcon main_window::GetAppIcon() QIcon main_window::GetAppIcon() const
{ {
return m_app_icon; return m_app_icon;
} }
@ -349,11 +349,13 @@ void main_window::show_boot_error(game_boot_result status)
case game_boot_result::file_creation_error: case game_boot_result::file_creation_error:
message = tr("The emulator could not create files required for booting."); message = tr("The emulator could not create files required for booting.");
break; break;
case game_boot_result::unsupported_disc_type:
message = tr("This disc type is not supported yet.");
break;
case game_boot_result::firmware_missing: // Handled elsewhere case game_boot_result::firmware_missing: // Handled elsewhere
case game_boot_result::no_errors: case game_boot_result::no_errors:
return; return;
case game_boot_result::generic_error: case game_boot_result::generic_error:
default:
message = tr("Unknown error."); message = tr("Unknown error.");
break; break;
} }
@ -517,7 +519,7 @@ bool main_window::InstallRapFile(const QString& path, const std::string& filenam
// Copy file atomically with thread/process-safe error checking for file size // Copy file atomically with thread/process-safe error checking for file size
fs::pending_file to(Emulator::GetHddDir() + "/home/" + Emu.GetUsr() + "/exdata/" + filename.substr(0, filename.find_last_of('.')) + ".rap"); fs::pending_file to(Emulator::GetHddDir() + "/home/" + Emu.GetUsr() + "/exdata/" + filename.substr(0, filename.find_last_of('.')) + ".rap");
fs::file from(sstr(path)); const fs::file from(sstr(path));
if (!to.file || !from) if (!to.file || !from)
{ {
@ -736,8 +738,10 @@ void main_window::HandlePackageInstallation(QStringList file_paths)
}); });
// Wait for the completion // Wait for the completion
while (std::this_thread::sleep_for(5ms), worker <= thread_state::aborting) while (worker <= thread_state::aborting)
{ {
std::this_thread::sleep_for(5ms);
if (pdlg.wasCanceled()) if (pdlg.wasCanceled())
{ {
cancelled = true; cancelled = true;
@ -802,14 +806,14 @@ void main_window::HandlePackageInstallation(QStringList file_paths)
void main_window::ExtractMSELF() void main_window::ExtractMSELF()
{ {
const QString path_last_mself = m_gui_settings->GetValue(gui::fd_ext_mself).toString(); const QString path_last_mself = m_gui_settings->GetValue(gui::fd_ext_mself).toString();
QString file_path = QFileDialog::getOpenFileName(this, tr("Select MSELF To extract"), path_last_mself, tr("All mself files (*.mself);;All files (*.*)")); const QString file_path = QFileDialog::getOpenFileName(this, tr("Select MSELF To extract"), path_last_mself, tr("All mself files (*.mself);;All files (*.*)"));
if (file_path.isEmpty()) if (file_path.isEmpty())
{ {
return; return;
} }
QString dir = QFileDialog::getExistingDirectory(this, tr("Extraction Directory"), QString{}, QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); const QString dir = QFileDialog::getExistingDirectory(this, tr("Extraction Directory"), QString{}, QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
if (!dir.isEmpty()) if (!dir.isEmpty())
{ {
@ -848,14 +852,14 @@ void main_window::InstallPup(QString file_path)
void main_window::ExtractPup() void main_window::ExtractPup()
{ {
const QString path_last_pup = m_gui_settings->GetValue(gui::fd_install_pup).toString(); const QString path_last_pup = m_gui_settings->GetValue(gui::fd_install_pup).toString();
QString file_path = QFileDialog::getOpenFileName(this, tr("Select PS3UPDAT.PUP To extract"), path_last_pup, tr("PS3 update file (PS3UPDAT.PUP);;All pup files (*.pup);;All files (*.*)")); const QString file_path = QFileDialog::getOpenFileName(this, tr("Select PS3UPDAT.PUP To extract"), path_last_pup, tr("PS3 update file (PS3UPDAT.PUP);;All pup files (*.pup);;All files (*.*)"));
if (file_path.isEmpty()) if (file_path.isEmpty())
{ {
return; return;
} }
QString dir = QFileDialog::getExistingDirectory(this, tr("Extraction Directory"), QString{}, QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); const QString dir = QFileDialog::getExistingDirectory(this, tr("Extraction Directory"), QString{}, QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
if (!dir.isEmpty()) if (!dir.isEmpty())
{ {
@ -881,7 +885,7 @@ void main_window::ExtractTar()
return; return;
} }
QString dir = QFileDialog::getExistingDirectory(this, tr("Extraction Directory"), QString{}, QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); const QString dir = QFileDialog::getExistingDirectory(this, tr("Extraction Directory"), QString{}, QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
if (dir.isEmpty()) if (dir.isEmpty())
{ {
@ -925,7 +929,7 @@ void main_window::ExtractTar()
} }
} }
void main_window::HandlePupInstallation(QString file_path, QString dir_path) void main_window::HandlePupInstallation(const QString& file_path, const QString& dir_path)
{ {
const auto critical = [this](QString str) const auto critical = [this](QString str)
{ {
@ -986,7 +990,7 @@ void main_window::HandlePupInstallation(QString file_path, QString dir_path)
} }
case pup_error::header_file_count: case pup_error::header_file_count:
case pup_error::file_entries: case pup_error::file_entries:
default: case pup_error::stream:
{ {
std::string error = "Error while installing firmware: PUP file is invalid."; std::string error = "Error while installing firmware: PUP file is invalid.";
@ -1046,7 +1050,7 @@ void main_window::HandlePupInstallation(QString file_path, QString dir_path)
auto update_filenames = update_files.get_filenames(); auto update_filenames = update_files.get_filenames();
update_filenames.erase(std::remove_if( update_filenames.erase(std::remove_if(
update_filenames.begin(), update_filenames.end(), [](std::string s) { return s.find("dev_flash_") == umax; }), update_filenames.begin(), update_filenames.end(), [](const std::string& s) { return s.find("dev_flash_") == umax; }),
update_filenames.end()); update_filenames.end());
if (update_filenames.empty()) if (update_filenames.empty())
@ -1344,7 +1348,7 @@ void main_window::DecryptSPRXLibraries()
/** Needed so that when a backup occurs of window state in gui_settings, the state is current. /** Needed so that when a backup occurs of window state in gui_settings, the state is current.
* Also, so that on close, the window state is preserved. * Also, so that on close, the window state is preserved.
*/ */
void main_window::SaveWindowState() void main_window::SaveWindowState() const
{ {
// Save gui settings // Save gui settings
m_gui_settings->SetValue(gui::mw_geometry, saveGeometry()); m_gui_settings->SetValue(gui::mw_geometry, saveGeometry());
@ -1455,7 +1459,7 @@ void main_window::RepaintToolBarIcons()
ui->mw_searchbar->setFixedWidth(tool_bar_height * 5); ui->mw_searchbar->setFixedWidth(tool_bar_height * 5);
} }
void main_window::OnEmuRun(bool /*start_playtime*/) void main_window::OnEmuRun(bool /*start_playtime*/) const
{ {
const QString title = GetCurrentTitle(); const QString title = GetCurrentTitle();
const QString restart_tooltip = tr("Restart %0").arg(title); const QString restart_tooltip = tr("Restart %0").arg(title);
@ -1480,7 +1484,7 @@ void main_window::OnEmuRun(bool /*start_playtime*/)
EnableMenus(true); EnableMenus(true);
} }
void main_window::OnEmuResume() void main_window::OnEmuResume() const
{ {
const QString title = GetCurrentTitle(); const QString title = GetCurrentTitle();
const QString restart_tooltip = tr("Restart %0").arg(title); const QString restart_tooltip = tr("Restart %0").arg(title);
@ -1501,7 +1505,7 @@ void main_window::OnEmuResume()
ui->toolbar_stop->setToolTip(stop_tooltip); ui->toolbar_stop->setToolTip(stop_tooltip);
} }
void main_window::OnEmuPause() void main_window::OnEmuPause() const
{ {
const QString title = GetCurrentTitle(); const QString title = GetCurrentTitle();
const QString resume_tooltip = tr("Resume %0").arg(title); const QString resume_tooltip = tr("Resume %0").arg(title);
@ -1579,7 +1583,7 @@ void main_window::OnEmuStop()
} }
} }
void main_window::OnEmuReady() void main_window::OnEmuReady() const
{ {
const QString title = GetCurrentTitle(); const QString title = GetCurrentTitle();
const QString play_tooltip = Emu.IsReady() ? tr("Play %0").arg(title) : tr("Resume %0").arg(title); const QString play_tooltip = Emu.IsReady() ? tr("Play %0").arg(title) : tr("Resume %0").arg(title);
@ -1600,7 +1604,7 @@ void main_window::OnEmuReady()
ui->actionManage_Users->setEnabled(false); ui->actionManage_Users->setEnabled(false);
} }
void main_window::EnableMenus(bool enabled) void main_window::EnableMenus(bool enabled) const
{ {
// Thumbnail Buttons // Thumbnail Buttons
#ifdef _WIN32 #ifdef _WIN32
@ -1660,9 +1664,9 @@ void main_window::BootRecentAction(const QAction* act)
if (contains_path) if (contains_path)
{ {
// clear menu of actions // clear menu of actions
for (auto act : m_recent_game_acts) for (auto action : m_recent_game_acts)
{ {
ui->bootRecentMenu->removeAction(act); ui->bootRecentMenu->removeAction(action);
} }
// remove action from list // remove action from list
@ -1751,9 +1755,9 @@ void main_window::AddRecentAction(const q_string_pair& entry)
} }
// clear menu of actions // clear menu of actions
for (auto act : m_recent_game_acts) for (auto action : m_recent_game_acts)
{ {
ui->bootRecentMenu->removeAction(act); ui->bootRecentMenu->removeAction(action);
} }
// If path already exists, remove it in order to get it to beginning. Also remove duplicates. // If path already exists, remove it in order to get it to beginning. Also remove duplicates.
@ -1856,7 +1860,7 @@ void main_window::RetranslateUI(const QStringList& language_codes, const QString
} }
} }
void main_window::ShowTitleBars(bool show) void main_window::ShowTitleBars(bool show) const
{ {
m_game_list_frame->SetTitleBarVisible(show); m_game_list_frame->SetTitleBarVisible(show);
m_debugger_frame->SetTitleBarVisible(show); m_debugger_frame->SetTitleBarVisible(show);
@ -2193,16 +2197,16 @@ void main_window::CreateConnects()
int id = 0; int id = 0;
const bool checked = act->isChecked(); const bool checked = act->isChecked();
if (act == ui->showCatHDDGameAct) categories += category::cat_hdd_game, id = Category::HDD_Game; if (act == ui->showCatHDDGameAct) { categories += cat::cat_hdd_game; id = Category::HDD_Game; }
else if (act == ui->showCatDiscGameAct) categories += category::cat_disc_game, id = Category::Disc_Game; else if (act == ui->showCatDiscGameAct) { categories += cat::cat_disc_game; id = Category::Disc_Game; }
else if (act == ui->showCatPS1GamesAct) categories += category::cat_ps1_game, id = Category::PS1_Game; else if (act == ui->showCatPS1GamesAct) { categories += cat::cat_ps1_game; id = Category::PS1_Game; }
else if (act == ui->showCatPS2GamesAct) categories += category::ps2_games, id = Category::PS2_Game; else if (act == ui->showCatPS2GamesAct) { categories += cat::ps2_games; id = Category::PS2_Game; }
else if (act == ui->showCatPSPGamesAct) categories += category::psp_games, id = Category::PSP_Game; else if (act == ui->showCatPSPGamesAct) { categories += cat::psp_games; id = Category::PSP_Game; }
else if (act == ui->showCatHomeAct) categories += category::cat_home, id = Category::Home; else if (act == ui->showCatHomeAct) { categories += cat::cat_home; id = Category::Home; }
else if (act == ui->showCatAudioVideoAct) categories += category::media, id = Category::Media; else if (act == ui->showCatAudioVideoAct) { categories += cat::media; id = Category::Media; }
else if (act == ui->showCatGameDataAct) categories += category::data, id = Category::Data; else if (act == ui->showCatGameDataAct) { categories += cat::data; id = Category::Data; }
else if (act == ui->showCatUnknownAct) categories += category::cat_unknown, id = Category::Unknown_Cat; else if (act == ui->showCatUnknownAct) { categories += cat::cat_unknown; id = Category::Unknown_Cat; }
else if (act == ui->showCatOtherAct) categories += category::others, id = Category::Others; else if (act == ui->showCatOtherAct) { categories += cat::others; id = Category::Others; }
else gui_log.warning("categoryVisibleActGroup: category action not found"); else gui_log.warning("categoryVisibleActGroup: category action not found");
if (!categories.isEmpty()) if (!categories.isEmpty())
@ -2399,7 +2403,7 @@ void main_window::CreateDockWindows()
ui->toolbar_start->setIcon(m_icon_play); ui->toolbar_start->setIcon(m_icon_play);
} }
else if (const auto path = Emu.GetBoot(); !path.empty()) // Restartable games else if (const auto& path = Emu.GetBoot(); !path.empty()) // Restartable games
{ {
tooltip = tr("Restart %0").arg(GetCurrentTitle()); tooltip = tr("Restart %0").arg(GetCurrentTitle());
@ -2543,7 +2547,7 @@ void main_window::ConfigureGuiFromSettings(bool configure_all)
} }
} }
void main_window::SetIconSizeActions(int idx) void main_window::SetIconSizeActions(int idx) const
{ {
static const int threshold_tiny = gui::get_Index((gui::gl_icon_size_small + gui::gl_icon_size_min) / 2); static const int threshold_tiny = gui::get_Index((gui::gl_icon_size_small + gui::gl_icon_size_min) / 2);
static const int threshold_small = gui::get_Index((gui::gl_icon_size_medium + gui::gl_icon_size_small) / 2); static const int threshold_small = gui::get_Index((gui::gl_icon_size_medium + gui::gl_icon_size_small) / 2);
@ -2575,7 +2579,7 @@ void main_window::RemoveDiskCache()
void main_window::RemoveFirmwareCache() void main_window::RemoveFirmwareCache()
{ {
const std::string cache_dir = Emu.GetCacheDir(); const std::string cache_dir = Emulator::GetCacheDir();
if (!fs::is_dir(cache_dir)) if (!fs::is_dir(cache_dir))
return; return;
@ -2711,11 +2715,11 @@ void main_window::AddGamesFromDir(const QString& path)
QDirIterator dir_iter(path, QDir::Dirs | QDir::NoDotAndDotDot); QDirIterator dir_iter(path, QDir::Dirs | QDir::NoDotAndDotDot);
while (dir_iter.hasNext()) while (dir_iter.hasNext())
{ {
const std::string path = sstr(dir_iter.next()); const std::string dir_path = sstr(dir_iter.next());
if (const auto error = Emu.BootGame(path, "", false, true); error == game_boot_result::no_errors) if (const auto error = Emu.BootGame(dir_path, "", false, true); error == game_boot_result::no_errors)
{ {
gui_log.notice("Returned from game addition by drag and drop: %s", path); gui_log.notice("Returned from game addition by drag and drop: %s", dir_path);
} }
} }
} }
@ -2723,7 +2727,7 @@ void main_window::AddGamesFromDir(const QString& path)
/** /**
Check data for valid file types and cache their paths if necessary Check data for valid file types and cache their paths if necessary
@param md = data containing file urls @param md = data containing file urls
@param savePaths = flag for path caching @param drop_paths = flag for path caching
@returns validity of file type @returns validity of file type
*/ */
main_window::drop_type main_window::IsValidFile(const QMimeData& md, QStringList* drop_paths) main_window::drop_type main_window::IsValidFile(const QMimeData& md, QStringList* drop_paths)
@ -2882,11 +2886,6 @@ void main_window::dropEvent(QDropEvent* event)
BootRsxCapture(sstr(drop_paths.first())); BootRsxCapture(sstr(drop_paths.first()));
break; break;
} }
default:
{
gui_log.warning("Invalid dropType in gamelist dropEvent");
break;
}
} }
} }

View file

@ -80,13 +80,13 @@ class main_window : public QMainWindow
}; };
public: public:
explicit main_window(std::shared_ptr<gui_settings> gui_settings, std::shared_ptr<emu_settings> emu_settings, std::shared_ptr<persistent_settings> persistent_settings, QWidget *parent = 0); explicit main_window(std::shared_ptr<gui_settings> gui_settings, std::shared_ptr<emu_settings> emu_settings, std::shared_ptr<persistent_settings> persistent_settings, QWidget *parent = nullptr);
~main_window(); ~main_window();
bool Init(bool with_cli_boot); bool Init(bool with_cli_boot);
QIcon GetAppIcon(); QIcon GetAppIcon() const;
bool OnMissingFw(); bool OnMissingFw();
void InstallPackages(QStringList file_paths = QStringList()); void InstallPackages(QStringList file_paths = QStringList());
void InstallPup(QString filePath = ""); void InstallPup(QString file_path = "");
Q_SIGNALS: Q_SIGNALS:
void RequestLanguageChange(const QString& language); void RequestLanguageChange(const QString& language);
@ -96,10 +96,10 @@ Q_SIGNALS:
public Q_SLOTS: public Q_SLOTS:
void OnEmuStop(); void OnEmuStop();
void OnEmuRun(bool start_playtime); void OnEmuRun(bool start_playtime) const;
void OnEmuResume(); void OnEmuResume() const;
void OnEmuPause(); void OnEmuPause() const;
void OnEmuReady(); void OnEmuReady() const;
void RepaintGui(); void RepaintGui();
void RetranslateUI(const QStringList& language_codes, const QString& language); void RetranslateUI(const QStringList& language_codes, const QString& language);
@ -111,11 +111,11 @@ private Q_SLOTS:
void BootGame(); void BootGame();
void BootRsxCapture(std::string path = ""); void BootRsxCapture(std::string path = "");
void DecryptSPRXLibraries(); void DecryptSPRXLibraries();
void show_boot_error(game_boot_result result); static void show_boot_error(game_boot_result status);
void SaveWindowState(); void SaveWindowState() const;
void ConfigureGuiFromSettings(bool configure_all = false); void ConfigureGuiFromSettings(bool configure_all = false);
void SetIconSizeActions(int idx); void SetIconSizeActions(int idx) const;
void ResizeIcons(int index); void ResizeIcons(int index);
void RemoveDiskCache(); void RemoveDiskCache();
@ -137,21 +137,21 @@ private:
void CreateActions(); void CreateActions();
void CreateConnects(); void CreateConnects();
void CreateDockWindows(); void CreateDockWindows();
void EnableMenus(bool enabled); void EnableMenus(bool enabled) const;
void ShowTitleBars(bool show); void ShowTitleBars(bool show) const;
static bool InstallRapFile(const QString& path, const std::string& filename); static bool InstallRapFile(const QString& path, const std::string& filename);
void HandlePackageInstallation(QStringList file_paths); void HandlePackageInstallation(QStringList file_paths);
void HandlePupInstallation(QString file_path, QString dir_path = ""); void HandlePupInstallation(const QString& file_path, const QString& dir_path = "");
void ExtractPup(); void ExtractPup();
void ExtractTar(); void ExtractTar();
void ExtractMSELF(); void ExtractMSELF();
drop_type IsValidFile(const QMimeData& md, QStringList* drop_paths = nullptr); static drop_type IsValidFile(const QMimeData& md, QStringList* drop_paths = nullptr);
void AddGamesFromDir(const QString& path); static void AddGamesFromDir(const QString& path);
QAction* CreateRecentAction(const q_string_pair& entry, const uint& sc_idx); QAction* CreateRecentAction(const q_string_pair& entry, const uint& sc_idx);
void BootRecentAction(const QAction* act); void BootRecentAction(const QAction* act);
@ -159,7 +159,7 @@ private:
void UpdateLanguageActions(const QStringList& language_codes, const QString& language); void UpdateLanguageActions(const QStringList& language_codes, const QString& language);
QString GetCurrentTitle(); static QString GetCurrentTitle();
q_pair_list m_rg_entries; q_pair_list m_rg_entries;
QList<QAction*> m_recent_game_acts; QList<QAction*> m_recent_game_acts;

View file

@ -132,10 +132,10 @@ void memory_string_searcher::OnSearch()
wstr += part; wstr += part;
} }
if (usz pos = wstr.find_first_not_of(hex_chars); pos != umax) if (const usz pos = wstr.find_first_not_of(hex_chars); pos != umax)
{ {
gui_log.error("String '%s' cannot be interpreted as hexadecimal byte string due to unknown character '%s'." gui_log.error("String '%s' cannot be interpreted as hexadecimal byte string due to unknown character '%s'.",
, m_addr_line->text().toStdString(), std::string_view{&wstr[pos], 1}); m_addr_line->text().toStdString(), std::string_view{&wstr[pos], 1});
return; return;
} }
@ -196,7 +196,7 @@ void memory_string_searcher::OnSearch()
vm::reader_lock rlock; vm::reader_lock rlock;
named_thread_group workers("String Searcher "sv, max_threads, [&]() const named_thread_group workers("String Searcher "sv, max_threads, [&]()
{ {
u32 local_found = 0; u32 local_found = 0;

View file

@ -10,12 +10,12 @@ class memory_string_searcher : public QDialog
{ {
Q_OBJECT Q_OBJECT
QLineEdit* m_addr_line; QLineEdit* m_addr_line = nullptr;
QCheckBox* m_chkbox_case_insensitive = nullptr; QCheckBox* m_chkbox_case_insensitive = nullptr;
QComboBox* m_cbox_input_mode = nullptr; QComboBox* m_cbox_input_mode = nullptr;
public: public:
memory_string_searcher(QWidget* parent); explicit memory_string_searcher(QWidget* parent);
private Q_SLOTS: private Q_SLOTS:
void OnSearch(); void OnSearch();

View file

@ -55,7 +55,7 @@ memory_viewer_panel::memory_viewer_panel(QWidget* parent, u32 addr, std::functio
setObjectName("memory_viewer"); setObjectName("memory_viewer");
m_colcount = 4; m_colcount = 4;
m_rowcount = 16; m_rowcount = 16;
int pSize = 10; const int pSize = 10;
// Font // Font
QFont mono = QFontDatabase::systemFont(QFontDatabase::FixedFont); QFont mono = QFontDatabase::systemFont(QFontDatabase::FixedFont);
@ -93,7 +93,7 @@ memory_viewer_panel::memory_viewer_panel(QWidget* parent, u32 addr, std::functio
{ {
public: public:
words_spin_box(QWidget* parent = nullptr) : QSpinBox(parent) {} words_spin_box(QWidget* parent = nullptr) : QSpinBox(parent) {}
~words_spin_box() override {}; ~words_spin_box() override {}
private: private:
int valueFromText(const QString &text) const override int valueFromText(const QString &text) const override
@ -142,7 +142,7 @@ memory_viewer_panel::memory_viewer_panel(QWidget* parent, u32 addr, std::functio
// Tools: Raw Image Preview Options // Tools: Raw Image Preview Options
QGroupBox* tools_img = new QGroupBox(tr("Raw Image Preview Options")); QGroupBox* tools_img = new QGroupBox(tr("Raw Image Preview Options"));
QHBoxLayout* hbox_tools_img = new QHBoxLayout();; QHBoxLayout* hbox_tools_img = new QHBoxLayout();
// Tools: Raw Image Preview Options : Size // Tools: Raw Image Preview Options : Size
QGroupBox* tools_img_size = new QGroupBox(tr("Size")); QGroupBox* tools_img_size = new QGroupBox(tr("Size"));
@ -300,13 +300,13 @@ memory_viewer_panel::~memory_viewer_panel()
void memory_viewer_panel::wheelEvent(QWheelEvent *event) void memory_viewer_panel::wheelEvent(QWheelEvent *event)
{ {
// Set some scrollspeed modifiers: // Set some scrollspeed modifiers:
u32 stepSize = 1; u32 step_size = 1;
if (event->modifiers().testFlag(Qt::ControlModifier)) if (event->modifiers().testFlag(Qt::ControlModifier))
stepSize *= m_rowcount; step_size *= m_rowcount;
QPoint numSteps = event->angleDelta() / 8 / 15; // http://doc.qt.io/qt-5/qwheelevent.html#pixelDelta const QPoint num_steps = event->angleDelta() / 8 / 15; // http://doc.qt.io/qt-5/qwheelevent.html#pixelDelta
scroll(stepSize * (0 - numSteps.y())); scroll(step_size * (0 - num_steps.y()));
} }
void memory_viewer_panel::scroll(s32 steps) void memory_viewer_panel::scroll(s32 steps)
@ -345,7 +345,7 @@ void memory_viewer_panel::resizeEvent(QResizeEvent *event)
} }
} }
std::string memory_viewer_panel::getHeaderAtAddr(u32 addr) std::string memory_viewer_panel::getHeaderAtAddr(u32 addr) const
{ {
if (m_type == thread_type::spu) return {}; if (m_type == thread_type::spu) return {};
@ -356,7 +356,7 @@ std::string memory_viewer_panel::getHeaderAtAddr(u32 addr)
{ {
std::shared_ptr<named_thread<spu_thread>> spu; std::shared_ptr<named_thread<spu_thread>> spu;
if (u32 raw_spu_index = (spu_boundary - RAW_SPU_BASE_ADDR) / SPU_LS_SIZE; raw_spu_index < 5) if (const u32 raw_spu_index = (spu_boundary - RAW_SPU_BASE_ADDR) / SPU_LS_SIZE; raw_spu_index < 5)
{ {
spu = idm::get<named_thread<spu_thread>>(spu_thread::find_raw_spu(raw_spu_index)); spu = idm::get<named_thread<spu_thread>>(spu_thread::find_raw_spu(raw_spu_index));
@ -365,7 +365,7 @@ std::string memory_viewer_panel::getHeaderAtAddr(u32 addr)
spu.reset(); spu.reset();
} }
} }
else if (u32 spu_index = (spu_boundary - SPU_FAKE_BASE_ADDR) / SPU_LS_SIZE; spu_index < spu_thread::id_count) else if (const u32 spu_index = (spu_boundary - SPU_FAKE_BASE_ADDR) / SPU_LS_SIZE; spu_index < spu_thread::id_count)
{ {
spu = idm::get<named_thread<spu_thread>>(spu_thread::id_base | spu_index); spu = idm::get<named_thread<spu_thread>>(spu_thread::id_base | spu_index);
@ -384,7 +384,7 @@ std::string memory_viewer_panel::getHeaderAtAddr(u32 addr)
return {}; return {};
} }
void* memory_viewer_panel::to_ptr(u32 addr, u32 size) void* memory_viewer_panel::to_ptr(u32 addr, u32 size) const
{ {
if (m_type >= thread_type::spu && !m_get_cpu()) if (m_type >= thread_type::spu && !m_get_cpu())
{ {
@ -436,7 +436,8 @@ void* memory_viewer_panel::to_ptr(u32 addr, u32 size)
final_addr = 0; final_addr = 0;
break; break;
} }
else if (!final_addr)
if (!final_addr)
{ {
// First time, save starting address for later checks // First time, save starting address for later checks
final_addr = temp; final_addr = temp;
@ -456,7 +457,6 @@ void* memory_viewer_panel::to_ptr(u32 addr, u32 size)
break; break;
} }
default: break;
} }
return nullptr; return nullptr;
@ -534,11 +534,11 @@ void memory_viewer_panel::ShowMemory()
t_mem_hex_str += " "; t_mem_hex_str += " ";
} }
u32 addr = (m_addr + (row - spu_passed) * m_colcount * 4 + col * 4) & m_addr_mask; const u32 addr = (m_addr + (row - spu_passed) * m_colcount * 4 + col * 4) & m_addr_mask;
if (auto ptr = this->to_ptr(addr)) if (const auto ptr = this->to_ptr(addr))
{ {
const be_t<u32> rmem = *reinterpret_cast<be_t<u32>*>(ptr); const be_t<u32> rmem = *static_cast<be_t<u32>*>(ptr);
t_mem_hex_str += qstr(fmt::format("%02x %02x %02x %02x", t_mem_hex_str += qstr(fmt::format("%02x %02x %02x %02x",
static_cast<u8>(rmem >> 24), static_cast<u8>(rmem >> 24),
static_cast<u8>(rmem >> 16), static_cast<u8>(rmem >> 16),
@ -582,10 +582,14 @@ void memory_viewer_panel::SetPC(const uint pc)
m_addr = pc; m_addr = pc;
} }
void memory_viewer_panel::ShowImage(QWidget* parent, u32 addr, color_format format, u32 width, u32 height, bool flipv) void memory_viewer_panel::ShowImage(QWidget* parent, u32 addr, color_format format, u32 width, u32 height, bool flipv) const
{ {
// If exceeds 32-bits it is invalid as well, UINT32_MAX always fails checks // If exceeds 32-bits it is invalid as well, UINT32_MAX always fails checks
const u32 memsize = static_cast<u32>(std::min<u64>(4ull * width * height, UINT32_MAX)); const u32 memsize = static_cast<u32>(std::min<u64>(4ull * width * height, UINT32_MAX));
if (memsize == 0)
{
return;
}
std::shared_lock rlock(vm::g_mutex); std::shared_lock rlock(vm::g_mutex);
@ -671,7 +675,7 @@ void memory_viewer_panel::ShowImage(QWidget* parent, u32 addr, color_format form
rlock.unlock(); rlock.unlock();
// Flip vertically // Flip vertically
if (flipv && height > 1) if (flipv && height > 1 && memsize > 1)
{ {
const u32 pitch = width * 4; const u32 pitch = width * 4;
for (u32 y = 0; y < height / 2; y++) for (u32 y = 0; y < height / 2; y++)
@ -687,7 +691,7 @@ void memory_viewer_panel::ShowImage(QWidget* parent, u32 addr, color_format form
} }
} }
QImage image(convertedBuffer, width, height, QImage::Format_ARGB32, [](void* buffer){ delete[] static_cast<u8*>(buffer); }, convertedBuffer); const QImage image(convertedBuffer, width, height, QImage::Format_ARGB32, [](void* buffer){ delete[] static_cast<u8*>(buffer); }, convertedBuffer);
if (image.isNull()) return; if (image.isNull()) return;
QLabel* canvas = new QLabel(); QLabel* canvas = new QLabel();

View file

@ -70,14 +70,14 @@ private:
const std::shared_ptr<utils::shm> m_spu_shm; const std::shared_ptr<utils::shm> m_spu_shm;
const u32 m_addr_mask; const u32 m_addr_mask;
std::string getHeaderAtAddr(u32 addr); std::string getHeaderAtAddr(u32 addr) const;
void scroll(s32 steps); void scroll(s32 steps);
void* to_ptr(u32 addr, u32 size = 1); void* to_ptr(u32 addr, u32 size = 1) const;
void SetPC(const uint pc); void SetPC(const uint pc);
virtual void ShowMemory(); virtual void ShowMemory();
void ShowImage(QWidget* parent, u32 addr, color_format format, u32 sizex, u32 sizey, bool flipv); void ShowImage(QWidget* parent, u32 addr, color_format format, u32 width, u32 height, bool flipv) const;
}; };
// Lifetime management with IDM // Lifetime management with IDM

View file

@ -24,9 +24,9 @@ void microphone_creator::refresh_list()
m_microphone_list.clear(); m_microphone_list.clear();
m_microphone_list.append(get_none()); m_microphone_list.append(get_none());
if (alcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT") == AL_TRUE) if (alcIsExtensionPresent(nullptr, "ALC_ENUMERATION_EXT") == AL_TRUE)
{ {
if (const char* devices = alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER); devices != nullptr) if (const char* devices = alcGetString(nullptr, ALC_CAPTURE_DEVICE_SPECIFIER); devices != nullptr)
{ {
while (*devices != 0) while (*devices != 0)
{ {
@ -38,19 +38,19 @@ void microphone_creator::refresh_list()
else else
{ {
// Without enumeration we can only use one device // Without enumeration we can only use one device
if (const char* device = alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER); device != nullptr) if (const char* device = alcGetString(nullptr, ALC_DEFAULT_DEVICE_SPECIFIER); device != nullptr)
{ {
m_microphone_list.append(qstr(device)); m_microphone_list.append(qstr(device));
} }
} }
} }
QStringList microphone_creator::get_microphone_list() QStringList microphone_creator::get_microphone_list() const
{ {
return m_microphone_list; return m_microphone_list;
} }
std::array<std::string, 4> microphone_creator::get_selection_list() std::array<std::string, 4> microphone_creator::get_selection_list() const
{ {
return m_sel_list; return m_sel_list;
} }
@ -62,8 +62,7 @@ std::string microphone_creator::set_device(u32 num, const QString& text)
else else
m_sel_list[num - 1] = text.toStdString(); m_sel_list[num - 1] = text.toStdString();
const std::string final_list = m_sel_list[0] + "@@@" + m_sel_list[1] + "@@@" + m_sel_list[2] + "@@@" + m_sel_list[3] + "@@@"; return m_sel_list[0] + "@@@" + m_sel_list[1] + "@@@" + m_sel_list[2] + "@@@" + m_sel_list[3] + "@@@";
return final_list;
} }
void microphone_creator::parse_devices(const std::string& list) void microphone_creator::parse_devices(const std::string& list)

View file

@ -19,8 +19,8 @@ public:
std::string set_device(u32 num, const QString& text); std::string set_device(u32 num, const QString& text);
void parse_devices(const std::string& list); void parse_devices(const std::string& list);
void refresh_list(); void refresh_list();
QStringList get_microphone_list(); QStringList get_microphone_list() const;
std::array<std::string, 4> get_selection_list(); std::array<std::string, 4> get_selection_list() const;
private: private:
QStringList m_microphone_list; QStringList m_microphone_list;

View file

@ -6,7 +6,6 @@
#include <QFormLayout> #include <QFormLayout>
#ifdef _WIN32 #ifdef _WIN32
#include <QWinTHumbnailToolbar>
#include <QWinTHumbnailToolbutton> #include <QWinTHumbnailToolbutton>
#elif HAVE_QTDBUS #elif HAVE_QTDBUS
#include <QtDBus/QDBusMessage> #include <QtDBus/QDBusMessage>
@ -35,7 +34,7 @@ void msg_dialog_frame::Create(const std::string& msg, const std::string& title)
layout->setFormAlignment(Qt::AlignHCenter); layout->setFormAlignment(Qt::AlignHCenter);
layout->addRow(m_text); layout->addRow(m_text);
auto l_AddGauge = [=, this](QProgressBar* &bar, QLabel* &text) auto l_AddGauge = [this, layout](QProgressBar* &bar, QLabel* &text)
{ {
text = new QLabel("", m_dialog); text = new QLabel("", m_dialog);
bar = new QProgressBar(m_dialog); bar = new QProgressBar(m_dialog);
@ -169,8 +168,6 @@ void msg_dialog_frame::Close(bool success)
} }
} }
msg_dialog_frame::msg_dialog_frame() {}
msg_dialog_frame::~msg_dialog_frame() msg_dialog_frame::~msg_dialog_frame()
{ {
#ifdef _WIN32 #ifdef _WIN32

View file

@ -36,16 +36,16 @@ private:
int m_gauge_max = 0; int m_gauge_max = 0;
public: public:
msg_dialog_frame(); msg_dialog_frame() = default;
~msg_dialog_frame(); ~msg_dialog_frame();
virtual void Create(const std::string& msg, const std::string& title = "") override; void Create(const std::string& msg, const std::string& title = "") override;
virtual void Close(bool success) override; void Close(bool success) override;
virtual void SetMsg(const std::string& msg) override; void SetMsg(const std::string& msg) override;
virtual void ProgressBarSetMsg(u32 progressBarIndex, const std::string& msg) override; void ProgressBarSetMsg(u32 progressBarIndex, const std::string& msg) override;
virtual void ProgressBarReset(u32 progressBarIndex) override; void ProgressBarReset(u32 progressBarIndex) override;
virtual void ProgressBarInc(u32 progressBarIndex, u32 delta) override; void ProgressBarInc(u32 progressBarIndex, u32 delta) override;
virtual void ProgressBarSetValue(u32 progressBarIndex, u32 value) override; void ProgressBarSetValue(u32 progressBarIndex, u32 value) override;
virtual void ProgressBarSetLimit(u32 index, u32 limit) override; void ProgressBarSetLimit(u32 index, u32 limit) override;
#ifdef HAVE_QTDBUS #ifdef HAVE_QTDBUS
private: private:
void UpdateProgress(int progress, bool disable = false); void UpdateProgress(int progress, bool disable = false);

View file

@ -14,10 +14,6 @@
constexpr auto qstr = QString::fromStdString; constexpr auto qstr = QString::fromStdString;
osk_dialog_frame::osk_dialog_frame()
{
}
osk_dialog_frame::~osk_dialog_frame() osk_dialog_frame::~osk_dialog_frame()
{ {
if (m_dialog) if (m_dialog)
@ -48,8 +44,8 @@ void osk_dialog_frame::Create(const std::string& title, const std::u16string& me
QLabel* message_label = new QLabel(QString::fromStdU16String(message)); QLabel* message_label = new QLabel(QString::fromStdU16String(message));
// Text Input Counter // Text Input Counter
const QString text = QString::fromStdU16String(std::u16string(init_text)); const QString input_text = QString::fromStdU16String(std::u16string(init_text));
QLabel* input_count_label = new QLabel(QString("%1/%2").arg(text.length()).arg(charlimit)); QLabel* input_count_label = new QLabel(QString("%1/%2").arg(input_text.length()).arg(charlimit));
// Button Layout // Button Layout
QDialogButtonBox* button_box = new QDialogButtonBox(QDialogButtonBox::Ok); QDialogButtonBox* button_box = new QDialogButtonBox(QDialogButtonBox::Ok);
@ -64,7 +60,7 @@ void osk_dialog_frame::Create(const std::string& title, const std::u16string& me
QLineEdit* input = new QLineEdit(m_dialog); QLineEdit* input = new QLineEdit(m_dialog);
input->setFixedWidth(lineEditWidth()); input->setFixedWidth(lineEditWidth());
input->setMaxLength(charlimit); input->setMaxLength(charlimit);
input->setText(text); input->setText(input_text);
input->setFocus(); input->setFocus();
if (prohibit_flags & CELL_OSKDIALOG_NO_SPACE) if (prohibit_flags & CELL_OSKDIALOG_NO_SPACE)
@ -72,7 +68,7 @@ void osk_dialog_frame::Create(const std::string& title, const std::u16string& me
input->setValidator(new QRegExpValidator(QRegExp("^\\S*$"), this)); input->setValidator(new QRegExpValidator(QRegExp("^\\S*$"), this));
} }
connect(input, &QLineEdit::textChanged, [=, this](const QString& text) connect(input, &QLineEdit::textChanged, input_count_label, [input_count_label, charlimit, this](const QString& text)
{ {
input_count_label->setText(QString("%1/%2").arg(text.length()).arg(charlimit)); input_count_label->setText(QString("%1/%2").arg(text.length()).arg(charlimit));
SetOskText(text); SetOskText(text);
@ -86,10 +82,10 @@ void osk_dialog_frame::Create(const std::string& title, const std::u16string& me
{ {
QTextEdit* input = new QTextEdit(m_dialog); QTextEdit* input = new QTextEdit(m_dialog);
input->setFixedWidth(lineEditWidth()); input->setFixedWidth(lineEditWidth());
input->setText(text); input->setText(input_text);
input->setFocus(); input->setFocus();
input->moveCursor(QTextCursor::End); input->moveCursor(QTextCursor::End);
m_text_old = text; m_text_old = input_text;
connect(input, &QTextEdit::textChanged, [=, this]() connect(input, &QTextEdit::textChanged, [=, this]()
{ {

View file

@ -14,10 +14,10 @@ class osk_dialog_frame : public QObject, public OskDialogBase
Q_OBJECT Q_OBJECT
public: public:
osk_dialog_frame(); osk_dialog_frame() = default;
~osk_dialog_frame(); ~osk_dialog_frame();
virtual void Create(const std::string& title, const std::u16string& message, char16_t* init_text, u32 charlimit, u32 prohibit_flags, u32 panel_flag, u32 first_view_panel) override; void Create(const std::string& title, const std::u16string& message, char16_t* init_text, u32 charlimit, u32 prohibit_flags, u32 panel_flag, u32 first_view_panel) override;
virtual void Close(bool accepted) override; void Close(bool accepted) override;
private: private:
void SetOskText(const QString& text); void SetOskText(const QString& text);

Some files were not shown because too many files have changed in this diff Show more