removing all singletons

This commit is contained in:
2024-09-20 17:29:42 +02:00
parent 8348f9ce7a
commit 1e2705ef06
10 changed files with 59 additions and 49 deletions

View File

@@ -8,7 +8,7 @@
namespace mlx
{
Application::Application() : m_fps(), m_in()
Application::Application() : p_mem_manager(std::make_unique<MemManager>()), p_sdl_manager(std::make_unique<SDLManager>()), m_fps(), m_in()
{
EventBus::RegisterListener({[](const EventBase& event)
{
@@ -16,8 +16,11 @@ namespace mlx
std::abort();
}, "__MlxApplication" });
#ifdef PROFILER
p_profiler = std::make_unique<Profiler>();
#endif
m_fps.Init();
SDLManager::Get().Init();
p_render_core = std::make_unique<RenderCore>();
}
@@ -89,6 +92,10 @@ namespace mlx
Application::~Application()
{
p_render_core.reset();
SDLManager::Get().Shutdown();
p_sdl_manager.reset();
#ifdef PROFILER
p_profiler.reset();
#endif
p_mem_manager.reset();
}
}

View File

@@ -4,6 +4,13 @@
namespace mlx
{
MemManager* MemManager::s_instance = nullptr;
MemManager::MemManager()
{
s_instance = this;
}
void* MemManager::Malloc(std::size_t size)
{
void* ptr = std::malloc(size);
@@ -49,5 +56,6 @@ namespace mlx
{
std::free(ptr);
});
s_instance = nullptr;
}
}

View File

@@ -4,6 +4,8 @@
namespace mlx
{
Profiler* Profiler::s_instance = nullptr;
void Profiler::BeginRuntimeSession()
{
std::lock_guard lock(m_mutex);
@@ -63,5 +65,6 @@ namespace mlx
if(!m_runtime_session_began)
return;
EndRuntimeSession();
s_instance = nullptr;
}
}

View File

@@ -26,9 +26,13 @@ namespace mlx
};
}
void SDLManager::Init() noexcept
SDLManager* SDLManager::s_instance = nullptr;
SDLManager::SDLManager()
{
MLX_PROFILE_FUNCTION();
s_instance = this;
m_drop_sdl_responsability = SDL_WasInit(SDL_INIT_VIDEO);
if(m_drop_sdl_responsability) // is case the mlx is running in a sandbox like MacroUnitTester where SDL is already init
return;
@@ -224,12 +228,13 @@ namespace mlx
return y;
}
void SDLManager::Shutdown() noexcept
SDLManager::~SDLManager()
{
if(m_drop_sdl_responsability)
return;
SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_EVENTS);
SDL_Quit();
s_instance = nullptr;
DebugLog("SDL Manager uninitialized");
}
}