mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-12 07:03:34 +00:00
fixing performance issue in text pipeline, working on event system
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/10 11:59:57 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/11 18:30:09 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/04/12 13:24:19 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -14,11 +14,13 @@
|
||||
#include <core/errors.h>
|
||||
#include <renderer/renderer.h>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
void TextData::init(std::vector<Vertex> vbo_data, std::vector<uint16_t> ibo_data)
|
||||
void TextData::init(std::string text, std::vector<Vertex> vbo_data, std::vector<uint16_t> ibo_data)
|
||||
{
|
||||
_text = std::move(text);
|
||||
_vbo.create(sizeof(Vertex) * vbo_data.size(), vbo_data.data());
|
||||
_ibo.create(sizeof(uint16_t) * ibo_data.size(), ibo_data.data());
|
||||
}
|
||||
@@ -46,7 +48,7 @@ namespace mlx
|
||||
{
|
||||
auto it = std::find_if(_cache.begin(), _cache.end(), [=](const std::pair<TextID, std::shared_ptr<TextData>>& v)
|
||||
{
|
||||
return v.second == text;
|
||||
return v.second->getText() == text->getText();
|
||||
});
|
||||
if(it != _cache.end())
|
||||
return it->first;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/10 11:52:30 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/11 12:28:08 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/04/12 11:38:57 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -31,9 +31,10 @@ namespace mlx
|
||||
public:
|
||||
TextData() = default;
|
||||
|
||||
void init(std::vector<Vertex> vbo_data, std::vector<uint16_t> ibo_data);
|
||||
void init(std::string text, std::vector<Vertex> vbo_data, std::vector<uint16_t> ibo_data);
|
||||
void bind(class Renderer& renderer) noexcept;
|
||||
inline uint32_t getIBOsize() noexcept { return _ibo.getSize(); }
|
||||
inline const std::string& getText() const { return _text; }
|
||||
void destroy() noexcept;
|
||||
|
||||
~TextData() = default;
|
||||
@@ -41,7 +42,7 @@ namespace mlx
|
||||
private:
|
||||
C_VBO _vbo;
|
||||
C_IBO _ibo;
|
||||
|
||||
std::string _text;
|
||||
};
|
||||
|
||||
class TextLibrary
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/06 16:41:13 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/11 23:27:45 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/04/12 13:21:42 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -23,7 +23,12 @@
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
TextDrawData::TextDrawData(std::string text, int _color, int _x, int _y, TextLibrary& library, std::array<stbtt_bakedchar, 96>& cdata) : x(_x), y(_y), color(_color)
|
||||
TextDrawData::TextDrawData(std::string _text, int _color, int _x, int _y) :
|
||||
x(_x), y(_y), color(_color),
|
||||
text(std::move(_text))
|
||||
{}
|
||||
|
||||
void TextDrawData::init(TextLibrary& library, std::array<stbtt_bakedchar, 96>& cdata) noexcept
|
||||
{
|
||||
std::vector<Vertex> vertexData;
|
||||
std::vector<uint16_t> indexData;
|
||||
@@ -53,9 +58,8 @@ namespace mlx
|
||||
indexData.emplace_back(index + 3);
|
||||
indexData.emplace_back(index + 0);
|
||||
}
|
||||
|
||||
std::shared_ptr<TextData> text_data = std::make_shared<TextData>();
|
||||
text_data->init(std::move(vertexData), std::move(indexData));
|
||||
text_data->init(text, std::move(vertexData), std::move(indexData));
|
||||
id = library.addTextToLibrary(text_data);
|
||||
}
|
||||
|
||||
@@ -78,7 +82,9 @@ namespace mlx
|
||||
|
||||
void TextPutPipeline::put(int x, int y, int color, std::string str)
|
||||
{
|
||||
_drawlist.emplace(std::move(str), color, x, y, _library, _cdata);
|
||||
auto res = _drawlist.emplace(std::move(str), color, x, y);
|
||||
if(res.second)
|
||||
const_cast<TextDrawData&>(*res.first).init(_library, _cdata);
|
||||
}
|
||||
|
||||
void TextPutPipeline::render()
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/06 16:24:11 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/11 18:36:53 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/04/12 13:25:33 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -29,9 +29,11 @@ namespace mlx
|
||||
int x;
|
||||
int y;
|
||||
int color;
|
||||
std::string text;
|
||||
|
||||
TextDrawData(std::string text, int _color, int _x, int _y, TextLibrary& library, std::array<stbtt_bakedchar, 96>& cdata);
|
||||
bool operator==(const TextDrawData& rhs) const { return id == rhs.id && x == rhs.x && y == rhs.y && color == rhs.color; }
|
||||
TextDrawData(std::string text, int _color, int _x, int _y);
|
||||
void init(TextLibrary& library, std::array<stbtt_bakedchar, 96>& cdata) noexcept;
|
||||
bool operator==(const TextDrawData& rhs) const { return text == rhs.text && x == rhs.x && y == rhs.y && color == rhs.color; }
|
||||
};
|
||||
}
|
||||
|
||||
@@ -40,9 +42,9 @@ namespace std
|
||||
template <>
|
||||
struct hash<mlx::TextDrawData>
|
||||
{
|
||||
size_t operator()(const mlx::TextDrawData& d) const noexcept
|
||||
std::size_t operator()(const mlx::TextDrawData& d) const noexcept
|
||||
{
|
||||
return std::hash<mlx::TextID>()(d.id) + std::hash<int>()(d.x) + std::hash<int>()(d.y) + std::hash<int>()(d.color);
|
||||
return std::hash<std::string>()(d.text) + std::hash<int>()(d.x) + std::hash<int>()(d.y) + std::hash<int>()(d.color);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/01 14:24:00 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/11 18:30:30 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/04/12 13:26:59 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace mlx
|
||||
{
|
||||
auto it = std::find_if(_cache.begin(), _cache.end(), [=](const std::pair<TextureID, std::shared_ptr<Texture>>& v)
|
||||
{
|
||||
return v.second == texture;
|
||||
return v.second.get() == texture.get();
|
||||
});
|
||||
if(it != _cache.end())
|
||||
return it->first;
|
||||
|
||||
Reference in New Issue
Block a user