Use new HashMap implementation in the TextServer, and Font.

This commit is contained in:
bruvzg 2022-05-08 21:03:20 +03:00
parent edda6ee9f8
commit 6783d55ce4
No known key found for this signature in database
GPG key ID: 7960FCF39844EC38
5 changed files with 25 additions and 24 deletions

View file

@ -2769,7 +2769,7 @@ Vector2 TextServerAdvanced::font_get_kerning(const RID &p_font_rid, int64_t p_si
ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), Vector2());
const Map<Vector2i, Vector2> &kern = fd->cache[size]->kerning_map;
const HashMap<Vector2i, Vector2, VariantHasher, VariantComparator> &kern = fd->cache[size]->kerning_map;
if (kern.has(p_glyph_pair)) {
if (fd->msdf) {
@ -2827,7 +2827,7 @@ bool TextServerAdvanced::font_has_char(const RID &p_font_rid, int64_t p_char) co
if (fd->cache.is_empty()) {
ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, fd->msdf ? Vector2i(fd->msdf_source_size, 0) : Vector2i(16, 0)), false);
}
FontDataForSizeAdvanced *at_size = fd->cache.front()->get();
FontDataForSizeAdvanced *at_size = fd->cache.begin()->value;
#ifdef MODULE_FREETYPE_ENABLED
if (at_size && at_size->face) {
@ -2845,7 +2845,7 @@ String TextServerAdvanced::font_get_supported_chars(const RID &p_font_rid) const
if (fd->cache.is_empty()) {
ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, fd->msdf ? Vector2i(fd->msdf_source_size, 0) : Vector2i(16, 0)), String());
}
FontDataForSizeAdvanced *at_size = fd->cache.front()->get();
FontDataForSizeAdvanced *at_size = fd->cache.begin()->value;
String chars;
#ifdef MODULE_FREETYPE_ENABLED
@ -4575,7 +4575,7 @@ bool TextServerAdvanced::shaped_text_update_justification_ops(const RID &p_shape
Glyph *sd_glyphs = sd->glyphs.ptrw();
int sd_size = sd->glyphs.size();
if (sd->jstops.size() > 0) {
if (!sd->jstops.is_empty()) {
for (int i = 0; i < sd_size; i++) {
if (sd_glyphs[i].count > 0) {
char32_t c = sd->text[sd_glyphs[i].start - sd->start];

View file

@ -67,7 +67,6 @@
#include <godot_cpp/classes/ref.hpp>
#include <godot_cpp/templates/hash_map.hpp>
#include <godot_cpp/templates/map.hpp>
#include <godot_cpp/templates/rid_owner.hpp>
#include <godot_cpp/templates/set.hpp>
#include <godot_cpp/templates/thread_work_pool.hpp>
@ -78,6 +77,7 @@ using namespace godot;
#else
// Headers for building as built-in module.
#include "core/templates/hash_map.h"
#include "core/templates/rid_owner.h"
#include "core/templates/thread_work_pool.h"
#include "scene/resources/texture.h"
@ -133,8 +133,8 @@ class TextServerAdvanced : public TextServerExtension {
};
Vector<NumSystemData> num_systems;
Map<StringName, int32_t> feature_sets;
Map<int32_t, StringName> feature_sets_inv;
HashMap<StringName, int32_t> feature_sets;
HashMap<int32_t, StringName> feature_sets_inv;
void _insert_num_systems_lang();
void _insert_feature_sets();
@ -191,7 +191,7 @@ class TextServerAdvanced : public TextServerExtension {
Vector<FontTexture> textures;
HashMap<int32_t, FontGlyph> glyph_map;
Map<Vector2i, Vector2> kerning_map;
HashMap<Vector2i, Vector2, VariantHasher, VariantComparator> kerning_map;
hb_font_t *hb_handle = nullptr;
@ -233,7 +233,7 @@ class TextServerAdvanced : public TextServerExtension {
String font_name;
String style_name;
Map<Vector2i, FontDataForSizeAdvanced *> cache;
HashMap<Vector2i, FontDataForSizeAdvanced *, VariantHasher, VariantComparator> cache;
bool face_init = false;
Set<uint32_t> supported_scripts;
@ -242,8 +242,8 @@ class TextServerAdvanced : public TextServerExtension {
Dictionary feature_overrides;
// Language/script support override.
Map<String, bool> language_support_overrides;
Map<String, bool> script_support_overrides;
HashMap<String, bool> language_support_overrides;
HashMap<String, bool> script_support_overrides;
PackedByteArray data;
const uint8_t *data_ptr;
@ -334,7 +334,7 @@ class TextServerAdvanced : public TextServerExtension {
InlineAlignment inline_align = INLINE_ALIGNMENT_CENTER;
Rect2 rect;
};
Map<Variant, EmbeddedObject> objects;
HashMap<Variant, EmbeddedObject, VariantHasher, VariantComparator> objects;
/* Shaped data */
TextServer::Direction para_direction = DIRECTION_LTR; // Detected text direction.

View file

@ -1917,7 +1917,7 @@ Vector2 TextServerFallback::font_get_kerning(const RID &p_font_rid, int64_t p_si
ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), Vector2());
const Map<Vector2i, Vector2> &kern = fd->cache[size]->kerning_map;
const HashMap<Vector2i, Vector2, VariantHasher, VariantComparator> &kern = fd->cache[size]->kerning_map;
if (kern.has(p_glyph_pair)) {
if (fd->msdf) {
@ -1957,7 +1957,7 @@ bool TextServerFallback::font_has_char(const RID &p_font_rid, int64_t p_char) co
if (fd->cache.is_empty()) {
ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, fd->msdf ? Vector2i(fd->msdf_source_size, 0) : Vector2i(16, 0)), false);
}
FontDataForSizeFallback *at_size = fd->cache.front()->get();
FontDataForSizeFallback *at_size = fd->cache.begin()->value;
#ifdef MODULE_FREETYPE_ENABLED
if (at_size && at_size->face) {
@ -1975,7 +1975,7 @@ String TextServerFallback::font_get_supported_chars(const RID &p_font_rid) const
if (fd->cache.is_empty()) {
ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, fd->msdf ? Vector2i(fd->msdf_source_size, 0) : Vector2i(16, 0)), String());
}
FontDataForSizeFallback *at_size = fd->cache.front()->get();
FontDataForSizeFallback *at_size = fd->cache.begin()->value;
String chars;
#ifdef MODULE_FREETYPE_ENABLED

View file

@ -67,7 +67,6 @@
#include <godot_cpp/classes/ref.hpp>
#include <godot_cpp/templates/hash_map.hpp>
#include <godot_cpp/templates/map.hpp>
#include <godot_cpp/templates/rid_owner.hpp>
#include <godot_cpp/templates/set.hpp>
#include <godot_cpp/templates/thread_work_pool.hpp>
@ -80,6 +79,7 @@ using namespace godot;
#include "servers/text/text_server_extension.h"
#include "core/templates/hash_map.h"
#include "core/templates/rid_owner.h"
#include "core/templates/thread_work_pool.h"
#include "scene/resources/texture.h"
@ -106,8 +106,8 @@ class TextServerFallback : public TextServerExtension {
GDCLASS(TextServerFallback, TextServerExtension);
_THREAD_SAFE_CLASS_
Map<StringName, int32_t> feature_sets;
Map<int32_t, StringName> feature_sets_inv;
HashMap<StringName, int32_t> feature_sets;
HashMap<int32_t, StringName> feature_sets_inv;
void _insert_feature_sets();
_FORCE_INLINE_ void _insert_feature(const StringName &p_name, int32_t p_tag);
@ -159,7 +159,7 @@ class TextServerFallback : public TextServerExtension {
Vector<FontTexture> textures;
HashMap<int32_t, FontGlyph> glyph_map;
Map<Vector2i, Vector2> kerning_map;
HashMap<Vector2i, Vector2, VariantHasher, VariantComparator> kerning_map;
#ifdef MODULE_FREETYPE_ENABLED
FT_Face face = nullptr;
@ -196,15 +196,15 @@ class TextServerFallback : public TextServerExtension {
String font_name;
String style_name;
Map<Vector2i, FontDataForSizeFallback *> cache;
HashMap<Vector2i, FontDataForSizeFallback *, VariantHasher, VariantComparator> cache;
bool face_init = false;
Dictionary supported_varaitions;
Dictionary feature_overrides;
// Language/script support override.
Map<String, bool> language_support_overrides;
Map<String, bool> script_support_overrides;
HashMap<String, bool> language_support_overrides;
HashMap<String, bool> script_support_overrides;
PackedByteArray data;
const uint8_t *data_ptr;
@ -294,7 +294,7 @@ class TextServerFallback : public TextServerExtension {
InlineAlignment inline_align = INLINE_ALIGNMENT_CENTER;
Rect2 rect;
};
Map<Variant, EmbeddedObject> objects;
HashMap<Variant, EmbeddedObject, VariantHasher, VariantComparator> objects;
/* Shaped data */
TextServer::Direction para_direction = DIRECTION_LTR; // Detected text direction.

View file

@ -33,6 +33,7 @@
#include "core/io/image_loader.h"
#include "core/io/resource_loader.h"
#include "core/string/translation.h"
#include "core/templates/hash_map.h"
#include "core/templates/hashfuncs.h"
#include "scene/resources/text_line.h"
#include "scene/resources/text_paragraph.h"
@ -963,7 +964,7 @@ Error FontData::load_bitmap_font(const String &p_path) {
int delimiter = line.find(" ");
String type = line.substr(0, delimiter);
int pos = delimiter + 1;
Map<String, String> keys;
HashMap<String, String> keys;
while (pos < line.size() && line[pos] == ' ') {
pos++;