From be2a7d51571ea888b934c1ca92312a48a304aadb Mon Sep 17 00:00:00 2001 From: Kbz-8 Date: Mon, 25 Mar 2024 16:18:24 +0100 Subject: [PATCH] fixing new gcc warning in GPU allocator, fixing #55 --- example/main.c | 14 +++++++++----- src/renderer/core/memory.h | 6 +++--- src/renderer/texts/text.cpp | 5 +++-- src/renderer/texts/text.h | 6 ++++-- src/renderer/texts/text_descriptor.cpp | 4 ++-- src/renderer/texts/text_library.cpp | 13 +++++-------- src/renderer/texts/text_library.h | 4 +--- 7 files changed, 27 insertions(+), 25 deletions(-) diff --git a/example/main.c b/example/main.c index e6a42c9..baa9faf 100644 --- a/example/main.c +++ b/example/main.c @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/04 17:55:21 by maldavid #+# #+# */ -/* Updated: 2024/03/14 20:01:01 by maldavid ### ########.fr */ +/* Updated: 2024/03/25 16:16:07 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,7 +23,7 @@ typedef struct void* img; } mlx_t; -void* img = NULL; +//void* img = NULL; int update(void* param) { @@ -32,13 +32,13 @@ int update(void* param) if(i == 200) mlx_clear_window(mlx->mlx, mlx->win); - +/* if(img) mlx_destroy_image(mlx->mlx,img); img = mlx_new_image(mlx->mlx, 800, 800); mlx_set_image_pixel(mlx->mlx, img, 4, 4, 0xFF00FF00); mlx_put_image_to_window(mlx->mlx, mlx->win, img, 0, 0); - +*/ if(i >= 250) mlx_set_font_scale(mlx->mlx, mlx->win, "default", 16.f); else @@ -157,7 +157,11 @@ int main(void) mlx_put_image_to_window(mlx.mlx, mlx.win, mlx.logo_png, 10, 190); mlx.img = create_image(&mlx); - + + + mlx_string_put(mlx.mlx, mlx.win, 0, 10, 0xFFFFFF00, "fps:"); + mlx_string_put(mlx.mlx, mlx.win, 0, 20, 0xFFFFFFFF, "fps:"); + mlx_set_font_scale(mlx.mlx, mlx.win, "font.ttf", 16.f); mlx_string_put(mlx.mlx, mlx.win, 20, 20, 0xFF0020FF, "that text will disappear"); diff --git a/src/renderer/core/memory.h b/src/renderer/core/memory.h index 077fd1b..46cd13f 100644 --- a/src/renderer/core/memory.h +++ b/src/renderer/core/memory.h @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/10/20 02:13:03 by maldavid #+# #+# */ -/* Updated: 2024/01/03 15:25:56 by maldavid ### ########.fr */ +/* Updated: 2024/03/25 16:01:06 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -44,8 +44,8 @@ namespace mlx private: VmaAllocator _allocator; - std::uint32_t _active_buffers_allocations = 0; - std::uint32_t _active_images_allocations = 0; + std::int32_t _active_buffers_allocations = 0; + std::int32_t _active_images_allocations = 0; }; } diff --git a/src/renderer/texts/text.cpp b/src/renderer/texts/text.cpp index dbbd264..a7696dd 100644 --- a/src/renderer/texts/text.cpp +++ b/src/renderer/texts/text.cpp @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/11 00:11:56 by maldavid #+# #+# */ -/* Updated: 2024/02/25 09:01:46 by maldavid ### ########.fr */ +/* Updated: 2024/03/25 16:13:08 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,12 +16,13 @@ namespace mlx { - void Text::init(std::string text, FontID font, std::vector vbo_data, std::vector ibo_data) + void Text::init(std::string text, FontID font, std::uint32_t color, std::vector vbo_data, std::vector ibo_data) { MLX_PROFILE_FUNCTION(); if(_is_init) return; _text = std::move(text); + _color = color; _font = font; #ifdef DEBUG std::string debug_name = _text; diff --git a/src/renderer/texts/text.h b/src/renderer/texts/text.h index 88c588f..fd244fd 100644 --- a/src/renderer/texts/text.h +++ b/src/renderer/texts/text.h @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/11 00:09:04 by maldavid #+# #+# */ -/* Updated: 2024/02/25 09:00:26 by maldavid ### ########.fr */ +/* Updated: 2024/03/25 16:16:48 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,12 +27,13 @@ namespace mlx public: Text() = default; - void init(std::string text, FontID font, std::vector vbo_data, std::vector ibo_data); + void init(std::string text, FontID font, std::uint32_t color, std::vector vbo_data, std::vector ibo_data); void bind(class Renderer& renderer) noexcept; inline FontID getFontInUse() const noexcept { return _font; } void updateVertexData(int frame, std::vector vbo_data); inline std::uint32_t getIBOsize() noexcept { return _ibo.getSize(); } inline const std::string& getText() const { return _text; } + inline std::uint32_t getColor() const noexcept { return _color; } void destroy() noexcept; ~Text(); @@ -41,6 +42,7 @@ namespace mlx std::array _vbo; C_IBO _ibo; std::string _text; + std::uint32_t _color; FontID _font = nullfont; bool _is_init = false; }; diff --git a/src/renderer/texts/text_descriptor.cpp b/src/renderer/texts/text_descriptor.cpp index 752e736..f5d7f14 100644 --- a/src/renderer/texts/text_descriptor.cpp +++ b/src/renderer/texts/text_descriptor.cpp @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/11 00:23:11 by maldavid #+# #+# */ -/* Updated: 2024/02/25 07:58:21 by maldavid ### ########.fr */ +/* Updated: 2024/03/25 16:13:48 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -76,7 +76,7 @@ namespace mlx } } std::shared_ptr text_data = std::make_shared(); - text_data->init(_text, font, std::move(vertexData), std::move(indexData)); + text_data->init(_text, font, color, std::move(vertexData), std::move(indexData)); id = TextLibrary::get().addTextToLibrary(text_data); #ifdef DEBUG diff --git a/src/renderer/texts/text_library.cpp b/src/renderer/texts/text_library.cpp index a7d34cf..652356c 100644 --- a/src/renderer/texts/text_library.cpp +++ b/src/renderer/texts/text_library.cpp @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/04/10 11:59:57 by maldavid #+# #+# */ -/* Updated: 2024/03/14 17:31:55 by maldavid ### ########.fr */ +/* Updated: 2024/03/25 16:17:06 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,7 +22,7 @@ namespace mlx std::shared_ptr TextLibrary::getTextData(TextID id) { MLX_PROFILE_FUNCTION(); - if(!_cache.count(id) || std::find(_invalid_ids.begin(), _invalid_ids.end(), id) != _invalid_ids.end()) + if(!_cache.count(id)) core::error::report(e_kind::fatal_error, "Text Library : wrong text ID '%d'", id); return _cache[id]; } @@ -32,7 +32,7 @@ namespace mlx MLX_PROFILE_FUNCTION(); auto it = std::find_if(_cache.begin(), _cache.end(), [&](const std::pair>& v) { - return v.second->getText() == text->getText() && std::find(_invalid_ids.begin(), _invalid_ids.end(), v.first) == _invalid_ids.end(); + return v.second->getText() == text->getText() && v.second->getColor() == text->getColor(); }); if(it != _cache.end()) return it->first; @@ -44,23 +44,20 @@ namespace mlx void TextLibrary::removeTextFromLibrary(TextID id) { MLX_PROFILE_FUNCTION(); - if(!_cache.count(id) || std::find(_invalid_ids.begin(), _invalid_ids.end(), id) != _invalid_ids.end()) + if(!_cache.count(id)) { core::error::report(e_kind::warning, "Text Library : trying to remove a text with an unkown or invalid ID '%d'", id); return; } _cache[id]->destroy(); - _invalid_ids.push_back(id); + _cache.erase(id); } void TextLibrary::clearLibrary() { MLX_PROFILE_FUNCTION(); for(auto& [id, text] : _cache) - { text->destroy(); - _invalid_ids.push_back(id); - } _cache.clear(); } } diff --git a/src/renderer/texts/text_library.h b/src/renderer/texts/text_library.h index d7dab98..2b9345b 100644 --- a/src/renderer/texts/text_library.h +++ b/src/renderer/texts/text_library.h @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/04/10 11:52:30 by maldavid #+# #+# */ -/* Updated: 2024/01/16 08:54:15 by maldavid ### ########.fr */ +/* Updated: 2024/03/25 16:04:47 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,7 +17,6 @@ #include #include #include -#include #include #include #include @@ -46,7 +45,6 @@ namespace mlx private: std::unordered_map> _cache; - std::vector _invalid_ids; TextID _current_id = 1; }; }