Only sync fonts cache with system's font when it's actually necessary (like clicking 'select system font' or current system font selected isn't in cache).

This reduces startup time for me (500 system fonts) by 100-130 ms.
This commit is contained in:
UnknownShadow200 2019-11-19 22:45:35 +11:00
parent 259bc1b3bb
commit f75e4b7f18
2 changed files with 22 additions and 5 deletions

View File

@ -879,6 +879,17 @@ static void* FT_ReallocWrapper(FT_Memory memory, long cur_size, long new_size, v
return Mem_Realloc(block, new_size, 1, "Freetype data"); return Mem_Realloc(block, new_size, 1, "Freetype data");
} }
static cc_bool updatedSysFonts;
/* Updates fonts list cache with system's list of fonts */
/* This should be avoided due to overhead potential */
static void SysFonts_Update(void) {
if (updatedSysFonts) return;
updatedSysFonts = true;
Platform_LoadSysFonts();
if (font_list_changed) EntryList_Save(&font_list);
}
#define FONT_CACHE_FILE "fontscache.txt" #define FONT_CACHE_FILE "fontscache.txt"
static void SysFonts_Init(void) { static void SysFonts_Init(void) {
static const String cachePath = String_FromConst(FONT_CACHE_FILE); static const String cachePath = String_FromConst(FONT_CACHE_FILE);
@ -896,8 +907,7 @@ static void SysFonts_Init(void) {
} }
EntryList_Init(&font_list, FONT_CACHE_FILE, '='); EntryList_Init(&font_list, FONT_CACHE_FILE, '=');
Platform_LoadSysFonts(); if (!font_list.entries.count) SysFonts_Update();
if (font_list_changed) EntryList_Save(&font_list);
} }
static void SysFonts_Add(const String* path, FT_Face face, int index, char type, const char* defStyle) { static void SysFonts_Add(const String* path, FT_Face face, int index, char type, const char* defStyle) {
@ -979,6 +989,7 @@ void Font_GetNames(StringsBuffer* buffer) {
String entry, name, path; String entry, name, path;
int i; int i;
if (!font_list.entries.count) SysFonts_Init(); if (!font_list.entries.count) SysFonts_Init();
SysFonts_Update();
for (i = 0; i < font_list.entries.count; i++) { for (i = 0; i < font_list.entries.count; i++) {
entry = StringsBuffer_UNSAFE_Get(&font_list.entries, i); entry = StringsBuffer_UNSAFE_Get(&font_list.entries, i);
@ -999,7 +1010,7 @@ static String Font_LookupOf(const String* fontName, const char type) {
return EntryList_UNSAFE_Get(&font_list, &name); return EntryList_UNSAFE_Get(&font_list, &name);
} }
String Font_Lookup(const String* fontName, int style) { static String Font_DoLookup(const String* fontName, int style) {
String path; String path;
if (!font_list.entries.count) SysFonts_Init(); if (!font_list.entries.count) SysFonts_Init();
path = String_Empty; path = String_Empty;
@ -1010,6 +1021,14 @@ String Font_Lookup(const String* fontName, int style) {
return path.length ? path : Font_LookupOf(fontName, 'R'); return path.length ? path : Font_LookupOf(fontName, 'R');
} }
String Font_Lookup(const String* fontName, int style) {
String path = Font_DoLookup(fontName, style);
if (path.length) return path;
SysFonts_Update();
return Font_DoLookup(fontName, style);
}
#define TEXT_CEIL(x) (((x) + 63) >> 6) #define TEXT_CEIL(x) (((x) + 63) >> 6)
cc_result Font_Make(struct FontDesc* desc, const String* fontName, int size, int style) { cc_result Font_Make(struct FontDesc* desc, const String* fontName, int size, int style) {
struct SysFont* font; struct SysFont* font;

View File

@ -1523,8 +1523,6 @@ void HandleDefineModel(cc_uint8* data) {
if (model != null) model.ReadRotationPacket(reader); if (model != null) model.ReadRotationPacket(reader);
break; break;
} }
int total = packetSizes[(byte)Opcode.CpeDefineModel];
reader.Skip(total - (reader.index - start));
} }
#endif #endif
static void BlockDefs_Reset(void) { static void BlockDefs_Reset(void) {