mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-12 07:03:34 +00:00
working on code refactor
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/04 21:49:46 by maldavid #+# #+# */
|
||||
/* Updated: 2024/04/03 15:05:24 by maldavid ### ########.fr */
|
||||
/* Updated: 2024/04/21 20:39:33 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include <Core/Graphics.h>
|
||||
#include <Platform/Inputs.h>
|
||||
#include <Core/DriverLoader.h>
|
||||
#include <Core/ImagesRegistry.h>
|
||||
#include <Core/Fps.h>
|
||||
|
||||
namespace mlx
|
||||
@@ -59,11 +60,11 @@ namespace mlx
|
||||
|
||||
private:
|
||||
FpsManager m_fps;
|
||||
Input m_in;
|
||||
DriverLoader m_driver_loader;
|
||||
std::list<Texture> m_textures;
|
||||
ImageRegistry m_image_registry;
|
||||
std::vector<std::unique_ptr<GraphicsSupport>> m_graphics;
|
||||
std::function<int(void*)> f_loop_hook;
|
||||
std::unique_ptr<Input> p_in;
|
||||
void* p_param = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* application.inl :+: :+: :+: */
|
||||
/* Application.inl :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/04 21:49:46 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/02 14:56:27 by maldavid ### ########.fr */
|
||||
/* Updated: 2024/04/23 14:45:07 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -30,12 +30,9 @@
|
||||
Error("invalid image ptr (NULL)"); \
|
||||
retval; \
|
||||
} \
|
||||
else if(std::find_if(_textures.begin(), _textures.end(), [=](const Texture& texture) \
|
||||
{ \
|
||||
return &texture == img; \
|
||||
}) == _textures.end()) \
|
||||
else if(m_image_registry.Find(img)) \
|
||||
{ \
|
||||
Error(e_kind::error, "invalid image ptr"); \
|
||||
Error("invalid image ptr"); \
|
||||
retval; \
|
||||
} else {}
|
||||
|
||||
@@ -65,7 +62,7 @@ namespace mlx
|
||||
Warning("trying to add event hook for a window that is targeting an image and not a real window, this is not allowed (hook ignored)");
|
||||
return;
|
||||
}
|
||||
p_in->OnEvent(m_graphics[*static_cast<int*>(win)]->GetWindow()->GetID(), event, funct_ptr, param);
|
||||
m_in.OnEvent(m_graphics[*static_cast<int*>(win)]->GetWindow()->GetID(), event, funct_ptr, param);
|
||||
}
|
||||
|
||||
void Application::GetScreenSize(void* win, int* w, int* h) noexcept
|
||||
@@ -97,7 +94,7 @@ namespace mlx
|
||||
return nullptr;
|
||||
}
|
||||
m_graphics.emplace_back(std::make_unique<GraphicsSupport>(w, h, title, m_graphics.size()));
|
||||
p_in->RegisterWindow(m_graphics.back()->GetWindow());
|
||||
m_in.RegisterWindow(m_graphics.back()->GetWindow());
|
||||
}
|
||||
return static_cast<void*>(&m_graphics.back()->GetID());
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/02 14:49:49 by maldavid #+# #+# */
|
||||
/* Updated: 2024/03/27 21:16:11 by maldavid ### ########.fr */
|
||||
/* Updated: 2024/04/23 14:02:48 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -42,13 +42,14 @@ namespace mlx
|
||||
inline void LoadFont(const std::filesystem::path& filepath, float scale);
|
||||
inline void TryEraseTextureFromManager(NonOwningPtr<Texture> texture) noexcept;
|
||||
|
||||
inline bool HasWindow() const noexcept { return _has_window; }
|
||||
inline bool HasWindow() const noexcept { return m_has_window; }
|
||||
|
||||
inline Renderer& GetRenderer() { return *_renderer; }
|
||||
inline Renderer& GetRenderer() { return m_renderer; }
|
||||
|
||||
~GraphicsSupport();
|
||||
|
||||
private:
|
||||
Renderer m_renderer;
|
||||
PixelPutPipeline m_pixel_put_pipeline;
|
||||
|
||||
std::vector<NonOwningPtr<DrawableResource>> m_drawlist;
|
||||
@@ -59,7 +60,6 @@ namespace mlx
|
||||
glm::mat4 m_proj = glm::mat4(1.0);
|
||||
|
||||
std::shared_ptr<Window> p_window;
|
||||
std::unique_ptr<Renderer> p_renderer;
|
||||
|
||||
std::size_t m_width = 0;
|
||||
std::size_t m_height = 0;
|
||||
|
||||
@@ -1,27 +1,36 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ImagesManager.h :+: :+: :+: */
|
||||
/* ImagesRegistry.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/03 15:11:47 by maldavid #+# #+# */
|
||||
/* Updated: 2024/04/21 15:13:43 by maldavid ### ########.fr */
|
||||
/* Updated: 2024/04/21 20:31:00 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef __MLX_CORE_IMAGES_MANAGER__
|
||||
#define __MLX_CORE_IMAGES_MANAGER__
|
||||
#ifndef __MLX_CORE_IMAGES_REGISTRY__
|
||||
#define __MLX_CORE_IMAGES_REGISTRY__
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
class ImagesManager
|
||||
class ImageRegistry
|
||||
{
|
||||
public:
|
||||
ImageRegistry() = default;
|
||||
|
||||
inline void RegisterTexture(NonOwningPtr<class Texture> texture);
|
||||
inline void UnregisterTexture(NonOwningPtr<class Texture> texture);
|
||||
inline bool IsTextureKnown(NonOwningPtr<class Texture> texture);
|
||||
|
||||
~ImageRegistry() = default;
|
||||
|
||||
private:
|
||||
std::unordered_set<Texture*> m_textures_registry;
|
||||
std::unordered_set<NonOwningPtr<class Texture>> m_textures_registry;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Core/ImagesRegistry.inl>
|
||||
|
||||
#endif
|
||||
25
runtime/Includes/Core/ImagesRegistry.inl
git.filemode.normal_file
25
runtime/Includes/Core/ImagesRegistry.inl
git.filemode.normal_file
@@ -0,0 +1,25 @@
|
||||
// This file is a part of Akel
|
||||
// Authors : @kbz_8
|
||||
// Created : 21/04/2024
|
||||
// Updated : 21/04/2024
|
||||
|
||||
#pragma once
|
||||
#include <Core/ImagesRegistry.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
void ImageRegistry::RegisterTexture(NonOwningPtr<class Texture> texture)
|
||||
{
|
||||
m_textures_registry.insert(texture);
|
||||
}
|
||||
|
||||
void ImageRegistry::UnregisterTexture(NonOwningPtr<class Texture> texture)
|
||||
{
|
||||
m_textures_registry.erase(texture);
|
||||
}
|
||||
|
||||
bool ImageRegistry::IsTextureKnown(NonOwningPtr<class Texture> texture)
|
||||
{
|
||||
return m_textures_registry.find(texture) != m_textures_registry.end();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user