mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-11 14:43:34 +00:00
removing all singletons
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
#include <Core/Graphics.h>
|
||||
#include <Platform/Inputs.h>
|
||||
#include <Core/ImagesRegistry.h>
|
||||
#include <Core/SDLManager.h>
|
||||
#include <Core/Memory.h>
|
||||
#include <Core/Fps.h>
|
||||
|
||||
namespace mlx
|
||||
@@ -47,12 +49,17 @@ namespace mlx
|
||||
~Application();
|
||||
|
||||
private:
|
||||
std::unique_ptr<MemManager> p_mem_manager; // Putting ptr here to initialise them before inputs, even if it f*cks the padding
|
||||
std::unique_ptr<SDLManager> p_sdl_manager;
|
||||
FpsManager m_fps;
|
||||
Inputs m_in;
|
||||
ImageRegistry m_image_registry;
|
||||
std::vector<std::unique_ptr<GraphicsSupport>> m_graphics;
|
||||
std::function<int(Handle)> f_loop_hook;
|
||||
std::unique_ptr<RenderCore> p_render_core;
|
||||
#ifdef PROFILER
|
||||
std::unique_ptr<Profiler> p_profiler;
|
||||
#endif
|
||||
Handle p_param = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -3,21 +3,23 @@
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
class MemManager : public Singleton<MemManager>
|
||||
class MemManager
|
||||
{
|
||||
friend class Singleton<MemManager>;
|
||||
|
||||
public:
|
||||
MemManager();
|
||||
|
||||
static void* Malloc(std::size_t size);
|
||||
static void* Calloc(std::size_t n, std::size_t size);
|
||||
static void* Realloc(void* ptr, std::size_t size);
|
||||
static void Free(void* ptr);
|
||||
|
||||
private:
|
||||
MemManager() = default;
|
||||
inline static bool IsInit() noexcept { return s_instance != nullptr; }
|
||||
inline static MemManager& Get() noexcept { return *s_instance; }
|
||||
|
||||
~MemManager();
|
||||
|
||||
private:
|
||||
static MemManager* s_instance;
|
||||
inline static std::list<void*> s_blocks;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
#ifndef __MLX_PROFILER__
|
||||
#define __MLX_PROFILER__
|
||||
|
||||
#include <Utils/Singleton.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
using FloatingPointMilliseconds = std::chrono::duration<double, std::milli>;
|
||||
@@ -14,20 +12,21 @@ namespace mlx
|
||||
std::thread::id thread_id;
|
||||
};
|
||||
|
||||
class Profiler : public Singleton<Profiler>
|
||||
class Profiler
|
||||
{
|
||||
friend class Singleton<Profiler>;
|
||||
|
||||
public:
|
||||
Profiler(const Profiler&) = delete;
|
||||
Profiler(Profiler&&) = delete;
|
||||
Profiler() { BeginRuntimeSession(); s_instance = this; }
|
||||
|
||||
void AppendProfileData(ProfileResult&& result);
|
||||
|
||||
private:
|
||||
Profiler() { BeginRuntimeSession(); }
|
||||
inline static bool IsInit() noexcept { return s_instance != nullptr; }
|
||||
inline static Profiler& Get() noexcept { return *s_instance; }
|
||||
|
||||
~Profiler();
|
||||
|
||||
private:
|
||||
void BeginRuntimeSession();
|
||||
void WriteProfile(const ProfileResult& result);
|
||||
void EndRuntimeSession();
|
||||
@@ -44,6 +43,8 @@ namespace mlx
|
||||
}
|
||||
|
||||
private:
|
||||
static Profiler* s_instance;
|
||||
|
||||
std::unordered_map<std::string, std::pair<std::size_t, ProfileResult>> m_profile_data;
|
||||
std::ofstream m_output_stream;
|
||||
std::mutex m_mutex;
|
||||
|
||||
@@ -5,13 +5,10 @@
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
class SDLManager : public Singleton<SDLManager>
|
||||
class SDLManager
|
||||
{
|
||||
friend class Singleton<SDLManager>;
|
||||
|
||||
public:
|
||||
void Init() noexcept;
|
||||
void Shutdown() noexcept;
|
||||
SDLManager();
|
||||
|
||||
Handle CreateWindow(const std::string& title, std::size_t w, std::size_t h, bool hidden);
|
||||
void DestroyWindow(Handle window) noexcept;
|
||||
@@ -30,18 +27,17 @@ namespace mlx
|
||||
std::int32_t GetXRel() const noexcept;
|
||||
std::int32_t GetYRel() const noexcept;
|
||||
|
||||
private:
|
||||
SDLManager() = default;
|
||||
~SDLManager() = default;
|
||||
inline static bool IsInit() noexcept { return s_instance != nullptr; }
|
||||
inline static SDLManager& Get() noexcept { return *s_instance; }
|
||||
|
||||
~SDLManager();
|
||||
|
||||
private:
|
||||
static SDLManager* s_instance;
|
||||
|
||||
std::unordered_set<Handle> m_windows_registry;
|
||||
func::function<void(mlx_event_type, int, int, void*)> f_callback;
|
||||
void* p_callback_data = nullptr;
|
||||
std::int32_t m_x;
|
||||
std::int32_t m_y;
|
||||
std::int32_t m_rel_x;
|
||||
std::int32_t m_rel_y;
|
||||
bool m_drop_sdl_responsability = false;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -93,6 +93,7 @@
|
||||
#include <Core/EventBus.h>
|
||||
#include <Core/Profiler.h>
|
||||
#include <Utils/NonOwningPtr.h>
|
||||
#include <Utils/NonCopyable.h>
|
||||
|
||||
using Handle = void*;
|
||||
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
#ifndef __MLX_SINGLETON__
|
||||
#define __MLX_SINGLETON__
|
||||
|
||||
#include <Utils/NonCopyable.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
template <typename T>
|
||||
class Singleton : public NonCopyable
|
||||
{
|
||||
public:
|
||||
inline static T& Get()
|
||||
{
|
||||
static T instance;
|
||||
return instance;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif // __MLX_SINGLETON__
|
||||
Reference in New Issue
Block a user