refactoring singleton class

This commit is contained in:
georgemoralis 2023-10-15 10:03:26 +03:00
parent 0f80805d69
commit 58721d84a0
12 changed files with 44 additions and 71 deletions

View File

@ -86,7 +86,7 @@ add_executable(shadps4
src/Core/PS4/HLE/Kernel/cpu_management.cpp src/Core/PS4/HLE/Kernel/cpu_management.cpp
src/Core/PS4/HLE/Kernel/cpu_management.h src/Core/PS4/HLE/Kernel/cpu_management.h
"src/Util/Singleton.h" "src/Util/Disassembler.cpp" "src/Util/Disassembler.h" "src/Core/PS4/Util/aerolib.h" "src/Core/PS4/Loader/SymbolsResolver.h" "src/Core/PS4/Loader/SymbolsResolver.cpp" "src/Core/PS4/HLE/Libs.cpp" "src/Core/PS4/HLE/Libs.h" "src/Core/PS4/HLE/LibC.cpp" "src/Core/PS4/HLE/LibC.h" "src/Lib/Timer.cpp" "src/Lib/Timer.h" "src/Core/PS4/HLE/LibKernel.cpp" "src/Core/PS4/HLE/LibKernel.h" "src/Core/PS4/HLE/LibSceGnmDriver.cpp" "src/Core/PS4/HLE/LibSceGnmDriver.h" "src/Core/PS4/HLE/Kernel/ThreadManagement.cpp" "src/Core/PS4/HLE/Kernel/ThreadManagement.h" "src/Core/PS4/HLE/ErrorCodes.h" "src/debug.h" "src/Core/PS4/HLE/Kernel/memory_management.cpp" "src/Core/PS4/HLE/Kernel/memory_management.h" "src/Core/PS4/GPU/gpu_memory.cpp" "src/Core/PS4/GPU/gpu_memory.h" "src/emulator.cpp" "src/emulator.h" "src/Core/PS4/HLE/Kernel/Objects/event_queue.h" "src/Core/PS4/HLE/Kernel/Objects/event_queue.cpp" "src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.cpp" "src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.h" "src/Core/PS4/HLE/Graphics/graphics_ctx.h" "src/vulkan_util.cpp" "src/vulkan_util.h" "src/Core/PS4/GPU/video_out_buffer.cpp" "src/Core/PS4/GPU/video_out_buffer.h" "src/Core/PS4/HLE/Graphics/graphics_render.cpp" "src/Core/PS4/HLE/Graphics/graphics_render.h" "src/Core/PS4/GPU/tile_manager.cpp" "src/Core/PS4/GPU/tile_manager.h" "src/version.h" "src/Emulator/HLE/Libraries/LibSystemService/system_service.cpp" "src/Emulator/HLE/Libraries/LibSystemService/system_service.h") "src/Util/Disassembler.cpp" "src/Util/Disassembler.h" "src/Core/PS4/Util/aerolib.h" "src/Core/PS4/Loader/SymbolsResolver.h" "src/Core/PS4/Loader/SymbolsResolver.cpp" "src/Core/PS4/HLE/Libs.cpp" "src/Core/PS4/HLE/Libs.h" "src/Core/PS4/HLE/LibC.cpp" "src/Core/PS4/HLE/LibC.h" "src/Lib/Timer.cpp" "src/Lib/Timer.h" "src/Core/PS4/HLE/LibKernel.cpp" "src/Core/PS4/HLE/LibKernel.h" "src/Core/PS4/HLE/LibSceGnmDriver.cpp" "src/Core/PS4/HLE/LibSceGnmDriver.h" "src/Core/PS4/HLE/Kernel/ThreadManagement.cpp" "src/Core/PS4/HLE/Kernel/ThreadManagement.h" "src/Core/PS4/HLE/ErrorCodes.h" "src/debug.h" "src/Core/PS4/HLE/Kernel/memory_management.cpp" "src/Core/PS4/HLE/Kernel/memory_management.h" "src/Core/PS4/GPU/gpu_memory.cpp" "src/Core/PS4/GPU/gpu_memory.h" "src/emulator.cpp" "src/emulator.h" "src/Core/PS4/HLE/Kernel/Objects/event_queue.h" "src/Core/PS4/HLE/Kernel/Objects/event_queue.cpp" "src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.cpp" "src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.h" "src/Core/PS4/HLE/Graphics/graphics_ctx.h" "src/vulkan_util.cpp" "src/vulkan_util.h" "src/Core/PS4/GPU/video_out_buffer.cpp" "src/Core/PS4/GPU/video_out_buffer.h" "src/Core/PS4/HLE/Graphics/graphics_render.cpp" "src/Core/PS4/HLE/Graphics/graphics_render.h" "src/Core/PS4/GPU/tile_manager.cpp" "src/Core/PS4/GPU/tile_manager.h" "src/version.h" "src/Emulator/HLE/Libraries/LibSystemService/system_service.cpp" "src/Emulator/HLE/Libraries/LibSystemService/system_service.h")
find_package(OpenGL REQUIRED) find_package(OpenGL REQUIRED)
target_link_libraries(shadps4 PUBLIC fmt mincore spdlog IMGUI SDL3-shared ${OPENGL_LIBRARY} vulkan-1 spirv-tools-opt spirv-tools) target_link_libraries(shadps4 PUBLIC fmt mincore spdlog IMGUI SDL3-shared ${OPENGL_LIBRARY} vulkan-1 spirv-tools-opt spirv-tools)

View File

@ -2,17 +2,17 @@
#include <xxhash/xxh3.h> #include <xxhash/xxh3.h>
#include "Util/Singleton.h" #include "Emulator/Util/singleton.h"
void* GPU::memoryCreateObj(u64 submit_id, HLE::Libs::Graphics::GraphicCtx* ctx, void* todo /*CommandBuffer?*/, u64 virtual_addr, u64 size, void* GPU::memoryCreateObj(u64 submit_id, HLE::Libs::Graphics::GraphicCtx* ctx, void* todo /*CommandBuffer?*/, u64 virtual_addr, u64 size,
const GPUObject& info) { const GPUObject& info) {
auto* gpumemory = Singleton<GPUMemory>::Instance(); auto* gpumemory = singleton<GPUMemory>::instance();
return gpumemory->memoryCreateObj(submit_id, ctx, nullptr, &virtual_addr, &size, 1, info); return gpumemory->memoryCreateObj(submit_id, ctx, nullptr, &virtual_addr, &size, 1, info);
} }
void GPU::memorySetAllocArea(u64 virtual_addr, u64 size) { void GPU::memorySetAllocArea(u64 virtual_addr, u64 size) {
auto* gpumemory = Singleton<GPUMemory>::Instance(); auto* gpumemory = singleton<GPUMemory>::instance();
Lib::LockMutexGuard lock(gpumemory->m_mutex); Lib::LockMutexGuard lock(gpumemory->m_mutex);
@ -59,7 +59,7 @@ bool GPU::vulkanAllocateMemory(HLE::Libs::Graphics::GraphicCtx* ctx, HLE::Libs::
} }
void GPU::flushGarlic(HLE::Libs::Graphics::GraphicCtx* ctx) { void GPU::flushGarlic(HLE::Libs::Graphics::GraphicCtx* ctx) {
auto* gpumemory = Singleton<GPUMemory>::Instance(); auto* gpumemory = singleton<GPUMemory>::instance();
gpumemory->flushAllHeaps(ctx); gpumemory->flushAllHeaps(ctx);
} }
@ -78,7 +78,7 @@ int GPU::GPUMemory::getHeapId(u64 virtual_addr, u64 size) {
void* GPU::GPUMemory::memoryCreateObj(u64 submit_id, HLE::Libs::Graphics::GraphicCtx* ctx, void* todo, const u64* virtual_addr, const u64* size, void* GPU::GPUMemory::memoryCreateObj(u64 submit_id, HLE::Libs::Graphics::GraphicCtx* ctx, void* todo, const u64* virtual_addr, const u64* size,
int virtual_addr_num, const GPUObject& info) { int virtual_addr_num, const GPUObject& info) {
auto* gpumemory = Singleton<GPUMemory>::Instance(); auto* gpumemory = singleton<GPUMemory>::instance();
Lib::LockMutexGuard lock(gpumemory->m_mutex); Lib::LockMutexGuard lock(gpumemory->m_mutex);

View File

@ -1,6 +1,6 @@
#include "tile_manager.h" #include "tile_manager.h"
#include "Lib/Threads.h" #include "Lib/Threads.h"
#include "Util/Singleton.h" #include "Emulator/Util/singleton.h"
namespace GPU { namespace GPU {
@ -143,7 +143,7 @@ void convertTileToLinear(void* dst, const void* src,u32 width, u32 height, bool
TileManager32 t; TileManager32 t;
t.Init(width, height, is_neo); t.Init(width, height, is_neo);
auto* g_TileManager = Singleton<TileManager>::Instance(); auto* g_TileManager = singleton<TileManager>::instance();
Lib::LockMutexGuard lock(g_TileManager->m_mutex); Lib::LockMutexGuard lock(g_TileManager->m_mutex);

View File

@ -1,12 +1,12 @@
#include "graphics_render.h" #include "graphics_render.h"
#include "Util/Singleton.h" #include "Emulator/Util/singleton.h"
#include "emulator.h" #include "emulator.h"
static thread_local GPU::CommandPool g_command_pool; static thread_local GPU::CommandPool g_command_pool;
void GPU::renderCreateCtx() { void GPU::renderCreateCtx() {
auto* render_ctx = Singleton<RenderCtx>::Instance(); auto* render_ctx = singleton<RenderCtx>::instance();
render_ctx->setGraphicCtx(Emu::getGraphicCtx()); render_ctx->setGraphicCtx(Emu::getGraphicCtx());
} }
@ -37,7 +37,7 @@ void GPU::CommandBuffer::freeBuffer() {
} }
void GPU::CommandBuffer::waitForFence() { void GPU::CommandBuffer::waitForFence() {
auto* render_ctx = Singleton<RenderCtx>::Instance(); auto* render_ctx = singleton<RenderCtx>::instance();
if (m_execute) { if (m_execute) {
auto* device = render_ctx->getGraphicCtx()->m_device; auto* device = render_ctx->getGraphicCtx()->m_device;
@ -89,7 +89,7 @@ void GPU::CommandBuffer::executeWithSemaphore() {
submit_info.signalSemaphoreCount = 1; submit_info.signalSemaphoreCount = 1;
submit_info.pSignalSemaphores = &m_pool->semaphores[m_index]; submit_info.pSignalSemaphores = &m_pool->semaphores[m_index];
auto* render_ctx = Singleton<RenderCtx>::Instance(); auto* render_ctx = singleton<RenderCtx>::instance();
const auto& queue = render_ctx->getGraphicCtx()->queues[m_queue]; const auto& queue = render_ctx->getGraphicCtx()->queues[m_queue];
if (queue.mutex != nullptr) { if (queue.mutex != nullptr) {
@ -124,7 +124,7 @@ void GPU::CommandBuffer::execute() {
submit_info.signalSemaphoreCount = 0; submit_info.signalSemaphoreCount = 0;
submit_info.pSignalSemaphores = nullptr; submit_info.pSignalSemaphores = nullptr;
auto* render_ctx = Singleton<RenderCtx>::Instance(); auto* render_ctx = singleton<RenderCtx>::instance();
const auto& queue = render_ctx->getGraphicCtx()->queues[m_queue]; const auto& queue = render_ctx->getGraphicCtx()->queues[m_queue];
if (queue.mutex != nullptr) { if (queue.mutex != nullptr) {
@ -145,7 +145,7 @@ void GPU::CommandBuffer::execute() {
} }
} }
void GPU::CommandPool::createPool(int id) { void GPU::CommandPool::createPool(int id) {
auto* render_ctx = Singleton<RenderCtx>::Instance(); auto* render_ctx = singleton<RenderCtx>::instance();
auto* ctx = render_ctx->getGraphicCtx(); auto* ctx = render_ctx->getGraphicCtx();
m_pool[id] = new HLE::Libs::Graphics::VulkanCommandPool; m_pool[id] = new HLE::Libs::Graphics::VulkanCommandPool;
@ -206,7 +206,7 @@ void GPU::CommandPool::createPool(int id) {
} }
void GPU::CommandPool::deleteAllPool() { void GPU::CommandPool::deleteAllPool() {
auto* render_ctx = Singleton<RenderCtx>::Instance(); auto* render_ctx = singleton<RenderCtx>::instance();
auto* ctx = render_ctx->getGraphicCtx(); auto* ctx = render_ctx->getGraphicCtx();
for (auto& pool : m_pool) { for (auto& pool : m_pool) {

View File

@ -15,7 +15,7 @@
#include <string> #include <string>
#include "Objects/video_out_ctx.h" #include "Objects/video_out_ctx.h"
#include "Util/Singleton.h" #include "Emulator/Util/singleton.h"
#include "emulator.h" #include "emulator.h"
#include "graphics_render.h" #include "graphics_render.h"
@ -24,12 +24,12 @@ namespace HLE::Libs::Graphics::VideoOut {
constexpr bool log_file_videoout = true; // disable it to disable logging constexpr bool log_file_videoout = true; // disable it to disable logging
void videoOutInit(u32 width, u32 height) { void videoOutInit(u32 width, u32 height) {
auto* videoOut = Singleton<HLE::Graphics::Objects::VideoOutCtx>::Instance(); auto* videoOut = singleton<HLE::Graphics::Objects::VideoOutCtx>::instance();
videoOut->Init(width, height); videoOut->Init(width, height);
} }
bool videoOutFlip(u32 micros) { bool videoOutFlip(u32 micros) {
auto* videoOut = Singleton<HLE::Graphics::Objects::VideoOutCtx>::Instance(); auto* videoOut = singleton<HLE::Graphics::Objects::VideoOutCtx>::instance();
return videoOut->getFlipQueue().flip(micros); return videoOut->getFlipQueue().flip(micros);
} }
@ -87,7 +87,7 @@ static void flip_delete_event_func(LibKernel::EventQueues::SceKernelEqueue eq, H
s32 PS4_SYSV_ABI sceVideoOutAddFlipEvent(LibKernel::EventQueues::SceKernelEqueue eq, s32 handle, void* udata) { s32 PS4_SYSV_ABI sceVideoOutAddFlipEvent(LibKernel::EventQueues::SceKernelEqueue eq, s32 handle, void* udata) {
PRINT_FUNCTION_NAME(); PRINT_FUNCTION_NAME();
auto* videoOut = Singleton<HLE::Graphics::Objects::VideoOutCtx>::Instance(); auto* videoOut = singleton<HLE::Graphics::Objects::VideoOutCtx>::instance();
auto* ctx = videoOut->getCtx(handle); auto* ctx = videoOut->getCtx(handle);
@ -122,7 +122,7 @@ s32 PS4_SYSV_ABI sceVideoOutAddFlipEvent(LibKernel::EventQueues::SceKernelEqueue
s32 PS4_SYSV_ABI sceVideoOutRegisterBuffers(s32 handle, s32 startIndex, void* const* addresses, s32 bufferNum, s32 PS4_SYSV_ABI sceVideoOutRegisterBuffers(s32 handle, s32 startIndex, void* const* addresses, s32 bufferNum,
const SceVideoOutBufferAttribute* attribute) { const SceVideoOutBufferAttribute* attribute) {
PRINT_FUNCTION_NAME(); PRINT_FUNCTION_NAME();
auto* videoOut = Singleton<HLE::Graphics::Objects::VideoOutCtx>::Instance(); auto* videoOut = singleton<HLE::Graphics::Objects::VideoOutCtx>::instance();
auto* ctx = videoOut->getCtx(handle); auto* ctx = videoOut->getCtx(handle);
if (handle == 1) { // main port if (handle == 1) { // main port
@ -215,19 +215,19 @@ s32 PS4_SYSV_ABI sceVideoOutRegisterBuffers(s32 handle, s32 startIndex, void* co
} }
s32 PS4_SYSV_ABI sceVideoOutSetFlipRate(s32 handle, s32 rate) { s32 PS4_SYSV_ABI sceVideoOutSetFlipRate(s32 handle, s32 rate) {
PRINT_FUNCTION_NAME(); PRINT_FUNCTION_NAME();
auto* videoOut = Singleton<HLE::Graphics::Objects::VideoOutCtx>::Instance(); auto* videoOut = singleton<HLE::Graphics::Objects::VideoOutCtx>::instance();
videoOut->getCtx(handle)->m_flip_rate = rate; videoOut->getCtx(handle)->m_flip_rate = rate;
return SCE_OK; return SCE_OK;
} }
s32 PS4_SYSV_ABI sceVideoOutIsFlipPending(s32 handle) { s32 PS4_SYSV_ABI sceVideoOutIsFlipPending(s32 handle) {
PRINT_FUNCTION_NAME(); PRINT_FUNCTION_NAME();
auto* videoOut = Singleton<HLE::Graphics::Objects::VideoOutCtx>::Instance(); auto* videoOut = singleton<HLE::Graphics::Objects::VideoOutCtx>::instance();
s32 pending = videoOut->getCtx(handle)->m_flip_status.flipPendingNum; s32 pending = videoOut->getCtx(handle)->m_flip_status.flipPendingNum;
return pending; return pending;
} }
s32 PS4_SYSV_ABI sceVideoOutSubmitFlip(s32 handle, s32 bufferIndex, s32 flipMode, s64 flipArg) { s32 PS4_SYSV_ABI sceVideoOutSubmitFlip(s32 handle, s32 bufferIndex, s32 flipMode, s64 flipArg) {
PRINT_FUNCTION_NAME(); PRINT_FUNCTION_NAME();
auto* videoOut = Singleton<HLE::Graphics::Objects::VideoOutCtx>::Instance(); auto* videoOut = singleton<HLE::Graphics::Objects::VideoOutCtx>::instance();
auto* ctx = videoOut->getCtx(handle); auto* ctx = videoOut->getCtx(handle);
if (flipMode != 1) { if (flipMode != 1) {
@ -254,7 +254,7 @@ s32 PS4_SYSV_ABI sceVideoOutSubmitFlip(s32 handle, s32 bufferIndex, s32 flipMode
} }
s32 PS4_SYSV_ABI sceVideoOutGetFlipStatus(s32 handle, SceVideoOutFlipStatus* status) { s32 PS4_SYSV_ABI sceVideoOutGetFlipStatus(s32 handle, SceVideoOutFlipStatus* status) {
PRINT_FUNCTION_NAME(); PRINT_FUNCTION_NAME();
auto* videoOut = Singleton<HLE::Graphics::Objects::VideoOutCtx>::Instance(); auto* videoOut = singleton<HLE::Graphics::Objects::VideoOutCtx>::instance();
auto* ctx = videoOut->getCtx(handle); auto* ctx = videoOut->getCtx(handle);
videoOut->getFlipQueue().getFlipStatus(ctx, status); videoOut->getFlipQueue().getFlipStatus(ctx, status);
@ -270,7 +270,7 @@ s32 PS4_SYSV_ABI sceVideoOutGetFlipStatus(s32 handle, SceVideoOutFlipStatus* sta
} }
s32 PS4_SYSV_ABI sceVideoOutGetResolutionStatus(s32 handle, SceVideoOutResolutionStatus* status) { s32 PS4_SYSV_ABI sceVideoOutGetResolutionStatus(s32 handle, SceVideoOutResolutionStatus* status) {
PRINT_FUNCTION_NAME(); PRINT_FUNCTION_NAME();
auto* videoOut = Singleton<HLE::Graphics::Objects::VideoOutCtx>::Instance(); auto* videoOut = singleton<HLE::Graphics::Objects::VideoOutCtx>::instance();
*status = videoOut->getCtx(handle)->m_resolution; *status = videoOut->getCtx(handle)->m_resolution;
return SCE_OK; return SCE_OK;
} }
@ -289,7 +289,7 @@ s32 PS4_SYSV_ABI sceVideoOutOpen(SceUserServiceUserId userId, s32 busType, s32 i
if (param != nullptr) { if (param != nullptr) {
BREAKPOINT(); BREAKPOINT();
} }
auto* videoOut = Singleton<HLE::Graphics::Objects::VideoOutCtx>::Instance(); auto* videoOut = singleton<HLE::Graphics::Objects::VideoOutCtx>::instance();
int handle = videoOut->Open(); int handle = videoOut->Open();
if (handle < 0) { if (handle < 0) {

View File

@ -8,7 +8,7 @@
#include <bit> #include <bit>
#include <magic_enum.hpp> #include <magic_enum.hpp>
#include "../../../../Util/Singleton.h" #include "Emulator/Util/singleton.h"
#include "../ErrorCodes.h" #include "../ErrorCodes.h"
#include "../Libs.h" #include "../Libs.h"
#include "Objects/physical_memory.h" #include "Objects/physical_memory.h"
@ -55,7 +55,7 @@ int PS4_SYSV_ABI sceKernelAllocateDirectMemory(s64 searchStart, s64 searchEnd, u
LOG_INFO_IF(log_file_memory, "memory_type = {}\n", magic_enum::enum_name(memtype.value())); LOG_INFO_IF(log_file_memory, "memory_type = {}\n", magic_enum::enum_name(memtype.value()));
u64 physical_addr = 0; u64 physical_addr = 0;
auto* physical_memory = Singleton<HLE::Kernel::Objects::PhysicalMemory>::Instance(); auto* physical_memory = singleton<HLE::Kernel::Objects::PhysicalMemory>::instance();
if (!physical_memory->Alloc(searchStart, searchEnd, len, alignment, &physical_addr, memoryType)) { if (!physical_memory->Alloc(searchStart, searchEnd, len, alignment, &physical_addr, memoryType)) {
LOG_TRACE_IF(log_file_memory, "sceKernelAllocateDirectMemory returned SCE_KERNEL_ERROR_EAGAIN can't allocate physical memory\n"); LOG_TRACE_IF(log_file_memory, "sceKernelAllocateDirectMemory returned SCE_KERNEL_ERROR_EAGAIN can't allocate physical memory\n");
return SCE_KERNEL_ERROR_EAGAIN; return SCE_KERNEL_ERROR_EAGAIN;
@ -115,7 +115,7 @@ int PS4_SYSV_ABI sceKernelMapDirectMemory(void** addr, u64 len, int prot, int fl
return SCE_KERNEL_ERROR_ENOMEM; return SCE_KERNEL_ERROR_ENOMEM;
} }
auto* physical_memory = Singleton<HLE::Kernel::Objects::PhysicalMemory>::Instance(); auto* physical_memory = singleton<HLE::Kernel::Objects::PhysicalMemory>::instance();
if (!physical_memory->Map(out_addr, directMemoryStart, len, prot, cpu_mode, gpu_mode)) { if (!physical_memory->Map(out_addr, directMemoryStart, len, prot, cpu_mode, gpu_mode)) {
BREAKPOINT(); BREAKPOINT();
} }

View File

@ -3,7 +3,7 @@
#include <Util/log.h> #include <Util/log.h>
#include <debug.h> #include <debug.h>
#include "../../../Util/Singleton.h" #include "Emulator/Util/singleton.h"
#include "../Loader/Elf.h" #include "../Loader/Elf.h"
#include "Kernel/Objects/physical_memory.h" #include "Kernel/Objects/physical_memory.h"
#include "Kernel/cpu_management.h" #include "Kernel/cpu_management.h"

View File

@ -3,7 +3,7 @@
#include <Core/PS4/HLE/ErrorCodes.h> #include <Core/PS4/HLE/ErrorCodes.h>
#include <Core/PS4/HLE/Libs.h> #include <Core/PS4/HLE/Libs.h>
#include "Util/Singleton.h" #include "Emulator/Util/singleton.h"
#include "controller.h" #include "controller.h"
#include <debug.h> #include <debug.h>
#include <Util/log.h> #include <Util/log.h>
@ -20,7 +20,7 @@ int PS4_SYSV_ABI scePadOpen(Emulator::HLE::Libraries::LibUserService::SceUserSer
} }
int PS4_SYSV_ABI scePadReadState(int32_t handle, ScePadData* pData) { int PS4_SYSV_ABI scePadReadState(int32_t handle, ScePadData* pData) {
auto* controller = Singleton<Emulator::Host::Controller::GameController>::Instance(); auto* controller = singleton<Emulator::Host::Controller::GameController>::instance();
int connectedCount = 0; int connectedCount = 0;
bool isConnected = false; bool isConnected = false;

View File

@ -1,27 +0,0 @@
#pragma once
#include <cstdlib>
#include <new>
template <class T>
class Singleton
{
public:
static T* Instance()
{
if (!m_instance)
{
m_instance = static_cast<T*>(std::malloc(sizeof(T)));
new (m_instance) T;
}
return m_instance;
}
protected:
Singleton();
~Singleton();
private:
static inline T* m_instance = nullptr;
};

View File

@ -2,7 +2,7 @@
#include <Core/PS4/HLE/Graphics/graphics_render.h> #include <Core/PS4/HLE/Graphics/graphics_render.h>
#include <Emulator/HLE/Libraries/LibPad/controller.h> #include <Emulator/HLE/Libraries/LibPad/controller.h>
#include <Util/Singleton.h> #include "Emulator/Util/singleton.h"
#include <vulkan_util.h> #include <vulkan_util.h>
#include "Core/PS4/HLE/Graphics/video_out.h" #include "Core/PS4/HLE/Graphics/video_out.h"
@ -14,14 +14,14 @@ namespace Emu {
bool m_emu_needs_exit = false; bool m_emu_needs_exit = false;
void emuInit(u32 width, u32 height) { void emuInit(u32 width, u32 height) {
auto* window_ctx = Singleton<Emu::WindowCtx>::Instance(); auto* window_ctx = singleton<Emu::WindowCtx>::instance();
window_ctx->m_graphic_ctx.screen_width = width; window_ctx->m_graphic_ctx.screen_width = width;
window_ctx->m_graphic_ctx.screen_height = height; window_ctx->m_graphic_ctx.screen_height = height;
} }
void checkAndWaitForGraphicsInit() { void checkAndWaitForGraphicsInit() {
auto* window_ctx = Singleton<Emu::WindowCtx>::Instance(); auto* window_ctx = singleton<Emu::WindowCtx>::instance();
Lib::LockMutexGuard lock(window_ctx->m_mutex); Lib::LockMutexGuard lock(window_ctx->m_mutex);
while (!window_ctx->m_is_graphic_initialized) { while (!window_ctx->m_is_graphic_initialized) {
@ -50,7 +50,7 @@ static void CreateSdlWindow(WindowCtx* ctx) {
SDL_SetWindowResizable(ctx->m_window, SDL_FALSE); // we don't support resizable atm SDL_SetWindowResizable(ctx->m_window, SDL_FALSE); // we don't support resizable atm
} }
void emuRun() { void emuRun() {
auto* window_ctx = Singleton<Emu::WindowCtx>::Instance(); auto* window_ctx = singleton<Emu::WindowCtx>::instance();
window_ctx->m_mutex.LockMutex(); window_ctx->m_mutex.LockMutex();
{ {
// init window and wait until init finishes // init window and wait until init finishes
@ -98,14 +98,14 @@ void emuRun() {
} }
HLE::Libs::Graphics::GraphicCtx* getGraphicCtx() { HLE::Libs::Graphics::GraphicCtx* getGraphicCtx() {
auto* window_ctx = Singleton<Emu::WindowCtx>::Instance(); auto* window_ctx = singleton<Emu::WindowCtx>::instance();
Lib::LockMutexGuard lock(window_ctx->m_mutex); Lib::LockMutexGuard lock(window_ctx->m_mutex);
return &window_ctx->m_graphic_ctx; return &window_ctx->m_graphic_ctx;
} }
void DrawBuffer(HLE::Libs::Graphics::VideoOutVulkanImage* image) { void DrawBuffer(HLE::Libs::Graphics::VideoOutVulkanImage* image) {
auto* window_ctx = Singleton<Emu::WindowCtx>::Instance(); auto* window_ctx = singleton<Emu::WindowCtx>::instance();
if (window_ctx->is_window_hidden) { if (window_ctx->is_window_hidden) {
SDL_ShowWindow(window_ctx->m_window); SDL_ShowWindow(window_ctx->m_window);
window_ctx->is_window_hidden = false; window_ctx->is_window_hidden = false;
@ -219,7 +219,7 @@ void keyboardEvent(SDL_Event* event) {
default: break; default: break;
} }
if (button != 0) { if (button != 0) {
auto* controller = Singleton<Emulator::Host::Controller::GameController>::Instance(); auto* controller = singleton<Emulator::Host::Controller::GameController>::instance();
controller->checKButton(0, button, event->type == SDL_EVENT_KEY_DOWN); controller->checKButton(0, button, event->type == SDL_EVENT_KEY_DOWN);
} }
} }

View File

@ -35,7 +35,7 @@
#include "Core/PS4/HLE/Libs.h" #include "Core/PS4/HLE/Libs.h"
#include "Core/PS4/Linker.h" #include "Core/PS4/Linker.h"
#include "Lib/Threads.h" #include "Lib/Threads.h"
#include "Util/Singleton.h" #include "Emulator/Util\singleton.h"
#include "discord.h" #include "discord.h"
// Main code // Main code
@ -54,12 +54,12 @@ int main(int argc, char* argv[]) {
const char* const path = argv[1]; // argument 1 is the path of self file to boot const char* const path = argv[1]; // argument 1 is the path of self file to boot
auto* linker = Singleton<Linker>::Instance(); auto* linker = singleton<Linker>::instance();
HLE::Libs::Init_HLE_Libs(linker->getHLESymbols()); HLE::Libs::Init_HLE_Libs(linker->getHLESymbols());
auto* module = linker->LoadModule(path); // load main executable auto* module = linker->LoadModule(path); // load main executable
Lib::Thread mainthread( Lib::Thread mainthread(
[](void*) { [](void*) {
auto* linker = Singleton<Linker>::Instance(); auto* linker = singleton<Linker>::instance();
linker->Execute(); linker->Execute();
}, },
nullptr); nullptr);

View File

@ -2,7 +2,7 @@
#include <Core/PS4/GPU/gpu_memory.h> #include <Core/PS4/GPU/gpu_memory.h>
#include <SDL_vulkan.h> #include <SDL_vulkan.h>
#include <Util/Singleton.h> #include <Emulator/Util/singleton.h>
#include <Util/log.h> #include <Util/log.h>
#include <debug.h> #include <debug.h>
#include <vulkan/vk_enum_string_helper.h> #include <vulkan/vk_enum_string_helper.h>
@ -80,7 +80,7 @@ void Graphics::Vulkan::vulkanCreate(Emu::WindowCtx* ctx) {
} }
Emu::VulkanSwapchain* Graphics::Vulkan::vulkanCreateSwapchain(HLE::Libs::Graphics::GraphicCtx* ctx, u32 image_count) { Emu::VulkanSwapchain* Graphics::Vulkan::vulkanCreateSwapchain(HLE::Libs::Graphics::GraphicCtx* ctx, u32 image_count) {
auto* window_ctx = Singleton<Emu::WindowCtx>::Instance(); auto* window_ctx = singleton<Emu::WindowCtx>::instance();
Lib::LockMutexGuard lock(window_ctx->m_mutex); Lib::LockMutexGuard lock(window_ctx->m_mutex);
auto* s = new Emu::VulkanSwapchain; auto* s = new Emu::VulkanSwapchain;