Skip to content

Commit

Permalink
Emu: some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Megamouse committed Apr 9, 2021
1 parent 10bbb7f commit 43535bc
Show file tree
Hide file tree
Showing 149 changed files with 944 additions and 1,129 deletions.
1 change: 0 additions & 1 deletion rpcs3/Crypto/unself.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "stdafx.h"
#include "aes.h"
#include "sha1.h"
#include "utils.h"
#include "unself.h"
#include "Emu/VFS.h"
Expand Down
1 change: 0 additions & 1 deletion rpcs3/Emu/Cell/Modules/cellSaveData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "Utilities/StrUtil.h"
#include "Utilities/span.h"

#include <thread>
#include <mutex>
#include <algorithm>

Expand Down
17 changes: 1 addition & 16 deletions rpcs3/Emu/Cell/PPUThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "lv2/sys_prx.h"
#include "lv2/sys_overlay.h"
#include "lv2/sys_process.h"
#include "lv2/sys_memory.h"

#ifdef LLVM_AVAILABLE
#ifdef _MSC_VER
Expand All @@ -37,28 +36,14 @@
#pragma GCC diagnostic ignored "-Wmissing-noreturn"
#endif
#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Host.h"
#include "llvm/Object/ObjectFile.h"
#include "llvm/ADT/Triple.h"
#include "llvm/IR/LLVMContext.h"
//#include "llvm/IR/Dominators.h"
#include "llvm/IR/Verifier.h"
#include "llvm/IR/InstIterator.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/Scalar.h"
#include "llvm/Transforms/IPO.h"
#include "llvm/Transforms/Vectorize.h"
#ifdef _MSC_VER
#pragma warning(pop)
#else
Expand Down Expand Up @@ -3014,7 +2999,7 @@ bool ppu_initialize(const ppu_module& info, bool check_only)

// Create worker threads for compilation (TODO: how many threads)
{
u32 thread_count = Emu.GetMaxThreads();
u32 thread_count = Emulator::GetMaxThreads();

if (workload.size() < thread_count)
{
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/SPURecompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ void spu_cache::initialize()
g_progr_ptotal += ::size32(func_list);
progr.emplace("Building SPU cache...");

worker_count = Emu.GetMaxThreads();
worker_count = Emulator::GetMaxThreads();
}

named_thread_group workers("SPU Worker ", worker_count, [&]() -> uint
Expand Down
46 changes: 19 additions & 27 deletions rpcs3/Emu/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,14 @@

#include "Emu/Cell/ErrorCodes.h"
#include "Emu/Cell/PPUThread.h"
#include "Emu/Cell/PPUCallback.h"
#include "Emu/Cell/PPUOpcodes.h"
#include "Emu/Cell/PPUDisAsm.h"
#include "Emu/Cell/PPUAnalyser.h"
#include "Emu/Cell/SPUThread.h"
#include "Emu/Cell/RawSPUThread.h"
#include "Emu/RSX/RSXThread.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_prx.h"
#include "Emu/Cell/lv2/sys_overlay.h"
#include "Emu/Cell/lv2/sys_rsx.h"
#include "Emu/Cell/Modules/cellMsgDialog.h"

#include "Emu/title.h"
Expand All @@ -40,7 +35,6 @@
#include "util/cereal.hpp"

#include <thread>
#include <queue>
#include <fstream>
#include <memory>
#include <regex>
Expand Down Expand Up @@ -558,7 +552,7 @@ void Emulator::SetUsr(const std::string& user)
std::string Emulator::GetBackgroundPicturePath() const
{
// 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))
{
Expand Down Expand Up @@ -646,8 +640,8 @@ bool Emulator::BootRsxCapture(const std::string& path)
m_state = system_state::ready;
GetCallbacks().on_ready();

Emu.GetCallbacks().init_gs_render();
Emu.GetCallbacks().init_pad_handler("");
GetCallbacks().init_gs_render();
GetCallbacks().init_pad_handler("");

GetCallbacks().on_run(false);
m_state = system_state::running;
Expand All @@ -661,7 +655,7 @@ bool Emulator::BootRsxCapture(const std::string& path)

void Emulator::LimitCacheSize()
{
const std::string cache_location = Emulator::GetHdd1Dir() + "/caches";
const std::string cache_location = GetHdd1Dir() + "/caches";

if (!fs::is_dir(cache_location))
{
Expand Down Expand Up @@ -877,7 +871,7 @@ std::string Emulator::GetExeDir()
}
#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"))
{
Expand Down Expand Up @@ -1042,7 +1036,7 @@ game_boot_result Emulator::Load(const std::string& title_id, bool add_only, bool
if (fs::is_dir(m_path))
{
// 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())
{
Expand All @@ -1057,12 +1051,12 @@ game_boot_result Emulator::Load(const std::string& title_id, bool add_only, bool
}
else
{
m_sfo_dir = GetSfoDirFromGamePath(disc, GetUsr(), m_title_id);
m_sfo_dir = GetSfoDirFromGamePath(disc, m_title_id);
}
}
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"));
Expand Down Expand Up @@ -1268,15 +1262,15 @@ game_boot_result Emulator::Load(const std::string& title_id, bool add_only, bool
ensure(vm::falloc(0x10000, 0xf0000, vm::main));
}

if (Emu.IsStopped())
if (IsStopped())
{
return;
}

ppu_precompile(dir_queue, nullptr);

// Exit "process"
Emu.CallAfter([]
CallAfter([]
{
Emu.SetForceBoot(true);
Emu.Stop();
Expand Down Expand Up @@ -1336,11 +1330,9 @@ 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);
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);
return game_boot_result::wrong_disc_location;
}

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;
}

bdvd_dir = sfb_dir + "/";
Expand Down Expand Up @@ -1739,10 +1731,10 @@ game_boot_result Emulator::Load(const std::string& title_id, bool add_only, bool
ConfigurePPUCache();

g_fxo->init(false);
Emu.GetCallbacks().init_gs_render();
Emu.GetCallbacks().init_pad_handler(m_title_id);
Emu.GetCallbacks().init_kb_handler();
Emu.GetCallbacks().init_mouse_handler();
GetCallbacks().init_gs_render();
GetCallbacks().init_pad_handler(m_title_id);
GetCallbacks().init_kb_handler();
GetCallbacks().init_mouse_handler();
}
// Overlay (OVL) executable (only load it)
else if (vm::map(0x3000'0000, 0x1000'0000, 0x200); !ppu_load_overlay(ppu_exec, m_path).first)
Expand Down Expand Up @@ -2140,7 +2132,7 @@ std::string Emulator::GetFormattedTitle(double fps) const
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 hw_threads = utils::get_thread_count();
Expand Down Expand Up @@ -2239,7 +2231,7 @@ void Emulator::ConfigurePPUCache()

if (!m_title_id.empty() && m_cat != "1P")
{
_main.cache += Emu.GetTitleID();
_main.cache += GetTitleID();
_main.cache += '/';
}

Expand Down
10 changes: 5 additions & 5 deletions rpcs3/Emu/System.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class Emulator final

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 InstallPkg(const std::string& path);
static bool InstallPkg(const std::string& path);

#ifdef _WIN32
static std::string GetExeDir();
Expand All @@ -230,7 +230,7 @@ class Emulator final
static std::string GetHddDir();
static std::string GetHdd1Dir();
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 GetCustomConfigDir();
Expand Down Expand Up @@ -264,15 +264,15 @@ class Emulator final

std::string GetFormattedTitle(double fps) const;

u32 GetMaxThreads() const;
static u32 GetMaxThreads();

void ConfigureLogs();
static void ConfigureLogs();
void ConfigurePPUCache();

std::set<std::string> GetGameDirs() const;

private:
void LimitCacheSize();
static void LimitCacheSize();
};

extern Emulator Emu;
Expand Down
18 changes: 9 additions & 9 deletions rpcs3/Input/basic_keyboard_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void basic_keyboard_handler::Init(const u32 max_connect)
{
for (u32 i = 0; i < max_connect; i++)
{
Keyboard kb = Keyboard();
Keyboard kb;

kb.m_config.arrange = g_cfg.sys.keyboard_type;

Expand Down Expand Up @@ -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;
}

// !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)
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;
Expand Down Expand Up @@ -137,7 +137,7 @@ s32 basic_keyboard_handler::getUnmodifiedKey(QKeyEvent* keyEvent)
#ifdef _WIN32
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)
{
Expand Down
6 changes: 3 additions & 3 deletions rpcs3/Input/basic_keyboard_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
class basic_keyboard_handler final : public KeyboardHandlerBase, public QObject
{
public:
virtual void Init(const u32 max_connect) override;
void Init(const u32 max_connect) override;

explicit basic_keyboard_handler();

void SetTargetWindow(QWindow* target);
bool eventFilter(QObject* obj, QEvent* ev) override;
bool eventFilter(QObject* watched, QEvent* event) override;
void keyPressEvent(QKeyEvent* event);
void keyReleaseEvent(QKeyEvent* event);
s32 getUnmodifiedKey(QKeyEvent* event);
static s32 getUnmodifiedKey(QKeyEvent* event);
void LoadSettings();
private:
QWindow* m_target = nullptr;
Expand Down
14 changes: 7 additions & 7 deletions rpcs3/Input/basic_mouse_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,24 +82,24 @@ bool basic_mouse_handler::eventFilter(QObject* target, QEvent* ev)

void basic_mouse_handler::MouseButtonDown(QMouseEvent* event)
{
if (event->button() == Qt::LeftButton) MouseHandlerBase::Button(CELL_MOUSE_BUTTON_1, 1);
else if (event->button() == Qt::RightButton) MouseHandlerBase::Button(CELL_MOUSE_BUTTON_2, 1);
else if (event->button() == Qt::MiddleButton) MouseHandlerBase::Button(CELL_MOUSE_BUTTON_3, 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, true);
else if (event->button() == Qt::MiddleButton) MouseHandlerBase::Button(CELL_MOUSE_BUTTON_3, true);
}

void basic_mouse_handler::MouseButtonUp(QMouseEvent* event)
{
if (event->button() == Qt::LeftButton) MouseHandlerBase::Button(CELL_MOUSE_BUTTON_1, 0);
else if (event->button() == Qt::RightButton) MouseHandlerBase::Button(CELL_MOUSE_BUTTON_2, 0);
else if (event->button() == Qt::MiddleButton) MouseHandlerBase::Button(CELL_MOUSE_BUTTON_3, 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, false);
else if (event->button() == Qt::MiddleButton) MouseHandlerBase::Button(CELL_MOUSE_BUTTON_3, false);
}

void basic_mouse_handler::MouseScroll(QWheelEvent* event)
{
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))
return game_frame->get_mouse_lock_state();
Expand Down
4 changes: 2 additions & 2 deletions rpcs3/Input/basic_mouse_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class basic_mouse_handler final : public MouseHandlerBase, public QObject
{
public:
virtual void Init(const u32 max_connect) override;
void Init(const u32 max_connect) override;

basic_mouse_handler();

Expand All @@ -23,5 +23,5 @@ class basic_mouse_handler final : public MouseHandlerBase, public QObject
bool eventFilter(QObject* obj, QEvent* ev) override;
private:
QWindow* m_target = nullptr;
bool get_mouse_lock_state();
bool get_mouse_lock_state() const;
};
2 changes: 1 addition & 1 deletion rpcs3/Input/ds3_pad_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ ds3_pad_handler::~ds3_pad_handler()

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)
{
return 0;
Expand Down

0 comments on commit 43535bc

Please sign in to comment.