Working on save-load system and UI
This commit is contained in:
1 parent
901142385d
commit
d7db0faea3
29 files changed
+708
-180
No files matched your search
@@ -12,6 +12,15 @@
|
||||
|
||||
namespace ZL {
|
||||
|
||||
struct GlyphAtlasData {
|
||||
std::unordered_map<uint32_t, GlyphInfo> glyphs;
|
||||
std::shared_ptr<Texture> atlasTexture;
|
||||
size_t atlasWidth = 0;
|
||||
size_t atlasHeight = 0;
|
||||
float lineHeight = 32.f;
|
||||
};
|
||||
static std::unordered_map<std::string, GlyphAtlasData> s_glyphAtlasCache;
|
||||
|
||||
// Decode one UTF-8 codepoint from str at byte position i; advances i past the sequence.
|
||||
static uint32_t nextUtf8Codepoint(const std::string& str, size_t& i)
|
||||
{
|
||||
@@ -71,6 +80,18 @@ void TextRenderer::ClearCache()
|
||||
|
||||
bool TextRenderer::loadGlyphs(const std::string& ttfPath, int pixelSize, const std::string& zipfilename)
|
||||
{
|
||||
std::string cacheKey = ttfPath + "|" + zipfilename + "|" + std::to_string(pixelSize);
|
||||
auto cacheIt = s_glyphAtlasCache.find(cacheKey);
|
||||
if (cacheIt != s_glyphAtlasCache.end()) {
|
||||
const GlyphAtlasData& cached = cacheIt->second;
|
||||
glyphs = cached.glyphs;
|
||||
atlasTexture = cached.atlasTexture;
|
||||
atlasWidth = cached.atlasWidth;
|
||||
atlasHeight = cached.atlasHeight;
|
||||
lineHeight = cached.lineHeight;
|
||||
return true;
|
||||
}
|
||||
|
||||
// 1. Загружаем сырые данные из ZIP
|
||||
std::vector<char> fontData;
|
||||
try {
|
||||
@@ -312,10 +333,18 @@ bool TextRenderer::loadGlyphs(const std::string& ttfPath, int pixelSize, const s
|
||||
FT_Done_Face(face);
|
||||
FT_Done_FreeType(ft);
|
||||
|
||||
// После FT_Done_Face данные из fontData больше не нужны,
|
||||
// После FT_Done_Face данные из fontData больше не нужны,
|
||||
// вектор сам очистится при выходе из функции.
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
GlyphAtlasData& entry = s_glyphAtlasCache[cacheKey];
|
||||
entry.glyphs = glyphs;
|
||||
entry.atlasTexture = atlasTexture;
|
||||
entry.atlasWidth = atlasWidth;
|
||||
entry.atlasHeight = atlasHeight;
|
||||
entry.lineHeight = lineHeight;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -528,7 +528,8 @@ namespace ZL
|
||||
|
||||
void TextureManager::Unload(const std::string& fileName, const std::string& zipFile)
|
||||
{
|
||||
textureMap.erase(MakeKey(fileName, zipFile));
|
||||
//For now, we should keep all textures in memory, to make game load faster after restart
|
||||
//textureMap.erase(MakeKey(fileName, zipFile));
|
||||
}
|
||||
|
||||
void TextureManager::UnloadAll()
|
||||
|
||||
Reference in new issue
Block a user