Skip to content

Commit

Permalink
fixed_typemap.hpp: reduce indirection
Browse files Browse the repository at this point in the history
Backported some changes from auto_typemap.hpp
Implemented methods init(), reset(), clear()
Disabled recreation support.
  • Loading branch information
Nekotekina committed Mar 1, 2021
1 parent 36981ad commit fb70f4c
Show file tree
Hide file tree
Showing 20 changed files with 218 additions and 170 deletions.
1 change: 0 additions & 1 deletion rpcs3/Emu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ target_include_directories(rpcs3_emu
# Utilities
target_sources(rpcs3_emu PRIVATE
../util/atomic.cpp
../util/fixed_typemap.cpp
../util/logs.cpp
../util/yaml.cpp
../util/cereal.cpp
Expand Down
4 changes: 2 additions & 2 deletions rpcs3/Emu/CPU/CPUThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ void cpu_thread::operator()()
}
}

while (!g_fxo->get<cpu_profiler>())
while (!g_fxo->is_init<cpu_profiler>())
{
if (Emu.IsStopped())
{
Expand Down Expand Up @@ -1151,7 +1151,7 @@ void cpu_thread::stop_all() noexcept

void cpu_thread::flush_profilers() noexcept
{
if (!g_fxo->get<cpu_profiler>())
if (!g_fxo->is_init<cpu_profiler>())
{
profiler.fatal("cpu_thread::flush_profilers() has been called incorrectly.");
return;
Expand Down
14 changes: 7 additions & 7 deletions rpcs3/Emu/Cell/Modules/cellMsgDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ struct msg_dlg_thread_info
thread_ctrl::wait_for(10'000);
}

if (auto manager = g_fxo->get<rsx::overlays::display_manager>())
if (auto manager = g_fxo->try_get<rsx::overlays::display_manager>())
{
if (auto dlg = manager->get<rsx::overlays::message_dialog>())
{
Expand Down Expand Up @@ -149,7 +149,7 @@ error_code open_msg_dialog(bool is_blocking, u32 type, vm::cptr<char> msgString,

const MsgDialogType _type{ type };

if (auto manager = g_fxo->get<rsx::overlays::display_manager>())
if (auto manager = g_fxo->try_get<rsx::overlays::display_manager>())
{
if (manager->get<rsx::overlays::message_dialog>())
{
Expand Down Expand Up @@ -433,7 +433,7 @@ error_code cellMsgDialogClose(f32 delay)

const u64 wait_until = get_guest_system_time() + static_cast<s64>(std::max<float>(delay, 0.0f) * 1000);

if (auto manager = g_fxo->get<rsx::overlays::display_manager>())
if (auto manager = g_fxo->try_get<rsx::overlays::display_manager>())
{
if (auto dlg = manager->get<rsx::overlays::message_dialog>())
{
Expand Down Expand Up @@ -463,7 +463,7 @@ error_code cellMsgDialogAbort()
{
cellSysutil.warning("cellMsgDialogAbort()");

if (auto manager = g_fxo->get<rsx::overlays::display_manager>())
if (auto manager = g_fxo->try_get<rsx::overlays::display_manager>())
{
if (auto dlg = manager->get<rsx::overlays::message_dialog>())
{
Expand Down Expand Up @@ -514,7 +514,7 @@ error_code cellMsgDialogProgressBarSetMsg(u32 progressBarIndex, vm::cptr<char> m
return CELL_MSGDIALOG_ERROR_PARAM;
}

if (auto manager = g_fxo->get<rsx::overlays::display_manager>())
if (auto manager = g_fxo->try_get<rsx::overlays::display_manager>())
{
if (auto dlg = manager->get<rsx::overlays::message_dialog>())
{
Expand Down Expand Up @@ -546,7 +546,7 @@ error_code cellMsgDialogProgressBarReset(u32 progressBarIndex)
{
cellSysutil.warning("cellMsgDialogProgressBarReset(progressBarIndex=%d)", progressBarIndex);

if (auto manager = g_fxo->get<rsx::overlays::display_manager>())
if (auto manager = g_fxo->try_get<rsx::overlays::display_manager>())
{
if (auto dlg = manager->get<rsx::overlays::message_dialog>())
{
Expand Down Expand Up @@ -578,7 +578,7 @@ error_code cellMsgDialogProgressBarInc(u32 progressBarIndex, u32 delta)
{
cellSysutil.warning("cellMsgDialogProgressBarInc(progressBarIndex=%d, delta=%d)", progressBarIndex, delta);

if (auto manager = g_fxo->get<rsx::overlays::display_manager>())
if (auto manager = g_fxo->try_get<rsx::overlays::display_manager>())
{
if (auto dlg = manager->get<rsx::overlays::message_dialog>())
{
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/Modules/cellOskDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ std::shared_ptr<OskDialogBase> _get_osk_dialog(bool create = false)
return nullptr;
}

if (auto manager = g_fxo->get<rsx::overlays::display_manager>())
if (auto manager = g_fxo->try_get<rsx::overlays::display_manager>())
{
std::shared_ptr<rsx::overlays::osk_dialog> dlg = std::make_shared<rsx::overlays::osk_dialog>();
osk->dlg = manager->add(dlg);
Expand Down
4 changes: 2 additions & 2 deletions rpcs3/Emu/IdManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,6 @@ class idm

#include "util/fixed_typemap.hpp"

extern stx::manual_fixed_typemap<void> g_fixed_typemap;
extern stx::manual_typemap<void, 0x20'00000, 128> g_fixed_typemap;

constexpr stx::manual_fixed_typemap<void>* g_fxo = &g_fixed_typemap;
constexpr auto* g_fxo = &g_fixed_typemap;
4 changes: 2 additions & 2 deletions rpcs3/Emu/Io/interception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ namespace input

pad::SetIntercepted(intercepted);

if (const auto handler = g_fxo->get<KeyboardHandlerBase>())
if (const auto handler = g_fxo->try_get<KeyboardHandlerBase>())
{
handler->SetIntercepted(intercepted);
}

if (const auto handler = g_fxo->get<MouseHandlerBase>())
if (const auto handler = g_fxo->try_get<MouseHandlerBase>())
{
handler->SetIntercepted(intercepted);
}
Expand Down
4 changes: 2 additions & 2 deletions rpcs3/Emu/Memory/vm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ namespace vm
// Notify rsx that range has become valid
// Note: This must be done *before* memory gets mapped while holding the vm lock, otherwise
// the RSX might try to invalidate memory that got unmapped and remapped
if (const auto rsxthr = g_fxo->get<rsx::thread>())
if (const auto rsxthr = g_fxo->try_get<rsx::thread>())
{
rsxthr->on_notify_memory_mapped(addr, size);
}
Expand Down Expand Up @@ -906,7 +906,7 @@ namespace vm
// Notify rsx to invalidate range
// Note: This must be done *before* memory gets unmapped while holding the vm lock, otherwise
// the RSX might try to call VirtualProtect on memory that is already unmapped
if (const auto rsxthr = g_fxo->get<rsx::thread>())
if (const auto rsxthr = g_fxo->get<rsx::thread>(); g_fxo->is_init<rsx::thread>())
{
rsxthr->on_notify_memory_unmapped(addr, size);
}
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/RSX/Overlays/overlay_message_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ namespace rsx
// Only update the screen at about 60fps since updating it everytime slows down the process
std::this_thread::sleep_for(16ms);

if (!g_fxo->get<display_manager>())
if (!g_fxo->is_init<display_manager>())
{
rsx_log.fatal("display_manager was improperly destroyed");
break;
Expand Down
4 changes: 2 additions & 2 deletions rpcs3/Emu/RSX/RSXThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ namespace rsx
void recover_fifo();
static void fifo_wake_delay(u64 div = 1);
u32 get_fifo_cmd() const;

std::string dump_regs() const override;
void cpu_wait(bs_t<cpu_flag> old) override;

Expand Down Expand Up @@ -974,7 +974,7 @@ namespace rsx

inline thread* get_current_renderer()
{
return g_fxo->get<rsx::thread>();
return g_fxo->try_get<rsx::thread>();
}

template<bool IsFullLock = false>
Expand Down
25 changes: 13 additions & 12 deletions rpcs3/Emu/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@

LOG_CHANNEL(sys_log, "SYS");

stx::manual_fixed_typemap<void> g_fixed_typemap;
// Preallocate 32 MiB
stx::manual_typemap<void, 0x20'00000, 128> g_fixed_typemap;

bool g_use_rtm = false;
u64 g_rtm_tx_limit1 = 0;
Expand Down Expand Up @@ -138,7 +139,7 @@ void Emulator::Init(bool add_only)

idm::init();
g_fxo->reset();
g_fxo->init<named_thread<progress_dialog_server>>();
g_fxo->need<named_thread<progress_dialog_server>>();

// Reset defaults, cache them
g_cfg.from_default();
Expand Down Expand Up @@ -569,7 +570,7 @@ bool Emulator::BootRsxCapture(const std::string& path)
g_cfg.video.disable_on_disk_shader_cache.set(true);

vm::init();
g_fxo->init();
g_fxo->init(false);

// PS3 'executable'
m_state = system_state::ready;
Expand Down Expand Up @@ -1095,7 +1096,7 @@ game_boot_result Emulator::Load(const std::string& title_id, bool add_only, bool
m_state = system_state::ready;
GetCallbacks().on_ready();
vm::init();
g_fxo->init();
g_fxo->init(false);
Run(false);
m_force_boot = false;

Expand Down Expand Up @@ -1591,7 +1592,7 @@ game_boot_result Emulator::Load(const std::string& title_id, bool add_only, bool
{
ConfigurePPUCache();

g_fxo->init();
g_fxo->init(false);
Emu.GetCallbacks().init_gs_render();
Emu.GetCallbacks().init_pad_handler(m_title_id);
Emu.GetCallbacks().init_kb_handler();
Expand All @@ -1618,7 +1619,7 @@ game_boot_result Emulator::Load(const std::string& title_id, bool add_only, bool
m_state = system_state::ready;
GetCallbacks().on_ready();
vm::init();
g_fxo->init();
g_fxo->init(false);
ppu_load_prx(ppu_prx, m_path);
}
else if (spu_exec.open(elf_file) == elf_error::ok)
Expand All @@ -1627,7 +1628,7 @@ game_boot_result Emulator::Load(const std::string& title_id, bool add_only, bool
m_state = system_state::ready;
GetCallbacks().on_ready();
vm::init();
g_fxo->init();
g_fxo->init(false);
spu_load_exec(spu_exec);
}
else
Expand Down Expand Up @@ -1706,7 +1707,7 @@ void Emulator::Run(bool start_playtime)
cpu.state.notify_one(cpu_flag::stop);
});

if (auto thr = g_fxo->get<named_thread<rsx::rsx_replay_thread>>())
if (auto thr = g_fxo->try_get<named_thread<rsx::rsx_replay_thread>>())
{
thr->state -= cpu_flag::stop;
thr->state.notify_one(cpu_flag::stop);
Expand Down Expand Up @@ -1747,7 +1748,7 @@ bool Emulator::Pause()
idm::select<named_thread<ppu_thread>>(on_select);
idm::select<named_thread<spu_thread>>(on_select);

if (auto rsx = g_fxo->get<rsx::thread>())
if (auto rsx = g_fxo->try_get<rsx::thread>())
{
rsx->state += cpu_flag::dbg_global_pause;
}
Expand Down Expand Up @@ -1820,7 +1821,7 @@ void Emulator::Resume()
idm::select<named_thread<ppu_thread>>(on_select);
idm::select<named_thread<spu_thread>>(on_select);

if (auto rsx = g_fxo->get<rsx::thread>())
if (auto rsx = g_fxo->try_get<rsx::thread>())
{
// TODO: notify?
rsx->state -= cpu_flag::dbg_global_pause;
Expand Down Expand Up @@ -1876,7 +1877,7 @@ void Emulator::Stop(bool restart)

GetCallbacks().on_stop();

if (auto rsx = g_fxo->get<rsx::thread>())
if (auto rsx = g_fxo->try_get<rsx::thread>())
{
// TODO: notify?
rsx->state += cpu_flag::exit;
Expand Down Expand Up @@ -1962,7 +1963,7 @@ bool Emulator::Quit(bool force_quit)
const auto on_exit = []()
{
// Deinitialize object manager to prevent any hanging objects at program exit
*g_fxo = {};
g_fxo->clear();
};
return GetCallbacks().try_to_quit(force_quit, on_exit);
}
Expand Down
3 changes: 0 additions & 3 deletions rpcs3/emucore.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,6 @@
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
</ClCompile>
<ClCompile Include="util\fixed_typemap.cpp">
<PrecompiledHeader>NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="..\Utilities\bin_patch.cpp">
<PrecompiledHeader>NotUsing</PrecompiledHeader>
</ClCompile>
Expand Down
3 changes: 0 additions & 3 deletions rpcs3/emucore.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -881,9 +881,6 @@
<ClCompile Include="util\cereal.cpp">
<Filter>Utilities</Filter>
</ClCompile>
<ClCompile Include="util\fixed_typemap.cpp">
<Filter>Utilities</Filter>
</ClCompile>
<ClCompile Include="util\cpu_stats.cpp">
<Filter>Utilities</Filter>
</ClCompile>
Expand Down
3 changes: 2 additions & 1 deletion rpcs3/rpcs3qt/cheat_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,8 @@ bool cheat_engine::is_addr_safe(const u32 offset)
if (Emu.IsStopped())
return false;

const auto ppum = g_fxo->get<ppu_module>();
const auto ppum = g_fxo->try_get<ppu_module>();

if (!ppum)
{
log_cheat.fatal("Failed to get ppu_module");
Expand Down
4 changes: 2 additions & 2 deletions rpcs3/rpcs3qt/debugger_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ void debugger_frame::keyPressEvent(QKeyEvent* event)
"\nKey R: Registers Editor for selected thread."
"\nKey N: Show next instruction the thread will execute after marked instruction, does nothing if target is not predictable."
"\nKey M: Show the Memory Viewer with initial address pointing to the marked instruction."
"\nKey I: Show RSX method detail."
"\nKey I: Show RSX method detail."
"\nKey F10: Perform single-stepping on instructions."
"\nKey F11: Perform step-over on instructions. (skip function calls)"
"\nKey F1: Show this help dialog."
Expand Down Expand Up @@ -431,7 +431,7 @@ cpu_thread* debugger_frame::get_cpu()
return m_rsx;
}

if (g_fxo->get<rsx::thread>() != m_rsx)
if (!g_fxo->is_init<rsx::thread>())
{
m_rsx = nullptr;
return m_rsx;
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/rpcs3qt/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ void main_window::DecryptSPRXLibraries()
// Always start with no KLIC
std::vector<u128> klics{u128{}};

if (const auto keys = g_fxo->get<loaded_npdrm_keys>())
if (const auto keys = g_fxo->try_get<loaded_npdrm_keys>())
{
// Second klic: get it from a running game
if (const u128 klic = keys->devKlic)
Expand Down
4 changes: 2 additions & 2 deletions rpcs3/rpcs3qt/rsx_debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,8 @@ void Buffer::showImage(const QImage& image)

void Buffer::ShowWindowed()
{
const auto render = rsx::get_current_renderer();
if (!render)
//const auto render = rsx::get_current_renderer();
if (!g_fxo->is_init<rsx::thread>())
return;

// TODO: Is there any better way to choose the color buffers
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/rpcs3qt/save_data_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
s32 save_data_dialog::ShowSaveDataList(std::vector<SaveDataEntry>& save_entries, s32 focused, u32 op, vm::ptr<CellSaveDataListSet> listSet)
{
// TODO: Install native shell as an Emu callback
if (auto manager = g_fxo->get<rsx::overlays::display_manager>())
if (auto manager = g_fxo->try_get<rsx::overlays::display_manager>())
{
auto result = manager->create<rsx::overlays::save_dialog>()->show(save_entries, focused, op, listSet);
if (result != rsx::overlays::user_interface::selection_code::error)
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/rpcs3qt/trophy_notification_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

s32 trophy_notification_helper::ShowTrophyNotification(const SceNpTrophyDetails& trophy, const std::vector<uchar>& trophy_icon_buffer)
{
if (auto manager = g_fxo->get<rsx::overlays::display_manager>())
if (auto manager = g_fxo->try_get<rsx::overlays::display_manager>())
{
// Allow adding more than one trophy notification. The notification class manages scheduling
auto popup = std::make_shared<rsx::overlays::trophy_notification>();
Expand Down
15 changes: 0 additions & 15 deletions rpcs3/util/fixed_typemap.cpp

This file was deleted.

0 comments on commit fb70f4c

Please sign in to comment.