diff options
Diffstat (limited to 'modules')
65 files changed, 1128 insertions, 3164 deletions
diff --git a/modules/bmp/image_loader_bmp.cpp b/modules/bmp/image_loader_bmp.cpp index 171895ed24..bd8342e1aa 100644 --- a/modules/bmp/image_loader_bmp.cpp +++ b/modules/bmp/image_loader_bmp.cpp @@ -91,11 +91,13 @@ Error ImageLoaderBMP::convert_to_image(Ref<Image> p_image, // the data width in case of 8/4/1 bit images const uint32_t w = bits_per_pixel >= 24 ? width : width_bytes; const uint8_t *line = p_buffer + (line_width * (height - 1)); + const uint8_t *end_buffer = p_buffer + p_header.bmp_file_header.bmp_file_size - p_header.bmp_file_header.bmp_file_offset; for (uint64_t i = 0; i < height; i++) { const uint8_t *line_ptr = line; for (unsigned int j = 0; j < w; j++) { + ERR_FAIL_COND_V(line_ptr >= end_buffer, ERR_FILE_CORRUPT); switch (bits_per_pixel) { case 1: { uint8_t color_index = *line_ptr; diff --git a/modules/bullet/bullet_physics_server.cpp b/modules/bullet/bullet_physics_server.cpp index 3054debaec..bb2db49c87 100644 --- a/modules/bullet/bullet_physics_server.cpp +++ b/modules/bullet/bullet_physics_server.cpp @@ -903,7 +903,7 @@ RID BulletPhysicsServer3D::soft_body_get_space(RID p_body) const { return space->get_self(); } -void BulletPhysicsServer3D::soft_body_set_mesh(RID p_body, const REF &p_mesh) { +void BulletPhysicsServer3D::soft_body_set_mesh(RID p_body, RID p_mesh) { SoftBodyBullet *body = soft_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); @@ -1404,8 +1404,8 @@ void BulletPhysicsServer3D::free(RID p_rid) { ShapeBullet *shape = shape_owner.get_or_null(p_rid); // Notify the shape is configured - for (Map<ShapeOwnerBullet *, int>::Element *element = shape->get_owners().front(); element; element = element->next()) { - static_cast<ShapeOwnerBullet *>(element->key())->remove_shape_full(shape); + for (const KeyValue<ShapeOwnerBullet *, int> &element : shape->get_owners()) { + static_cast<ShapeOwnerBullet *>(element.key)->remove_shape_full(shape); } shape_owner.free(p_rid); diff --git a/modules/bullet/bullet_physics_server.h b/modules/bullet/bullet_physics_server.h index 7f0934e679..7c146de0c3 100644 --- a/modules/bullet/bullet_physics_server.h +++ b/modules/bullet/bullet_physics_server.h @@ -265,7 +265,7 @@ public: virtual void soft_body_set_space(RID p_body, RID p_space) override; virtual RID soft_body_get_space(RID p_body) const override; - virtual void soft_body_set_mesh(RID p_body, const REF &p_mesh) override; + virtual void soft_body_set_mesh(RID p_body, RID p_mesh) override; virtual AABB soft_body_get_bounds(RID p_body) const override; diff --git a/modules/bullet/shape_bullet.cpp b/modules/bullet/shape_bullet.cpp index 88ffb9ec67..ec039ba842 100644 --- a/modules/bullet/shape_bullet.cpp +++ b/modules/bullet/shape_bullet.cpp @@ -63,8 +63,8 @@ btCollisionShape *ShapeBullet::prepare(btCollisionShape *p_btShape) const { } void ShapeBullet::notifyShapeChanged() { - for (Map<ShapeOwnerBullet *, int>::Element *E = owners.front(); E; E = E->next()) { - ShapeOwnerBullet *owner = static_cast<ShapeOwnerBullet *>(E->key()); + for (const KeyValue<ShapeOwnerBullet *, int> &E : owners) { + ShapeOwnerBullet *owner = static_cast<ShapeOwnerBullet *>(E.key); owner->shape_changed(owner->find_shape(this)); } } diff --git a/modules/bullet/soft_body_bullet.cpp b/modules/bullet/soft_body_bullet.cpp index bbbb0e7851..94b7e0ce38 100644 --- a/modules/bullet/soft_body_bullet.cpp +++ b/modules/bullet/soft_body_bullet.cpp @@ -32,9 +32,10 @@ #include "bullet_types_converter.h" #include "bullet_utilities.h" -#include "scene/3d/soft_body_3d.h" #include "space_bullet.h" +#include "servers/rendering_server.h" + SoftBodyBullet::SoftBodyBullet() : CollisionObjectBullet(CollisionObjectBullet::TYPE_SOFT_BODY) {} @@ -105,24 +106,26 @@ void SoftBodyBullet::update_rendering_server(RenderingServerHandler *p_rendering p_rendering_server_handler->set_aabb(aabb); } -void SoftBodyBullet::set_soft_mesh(const Ref<Mesh> &p_mesh) { - if (p_mesh.is_null()) { - soft_mesh.unref(); - } else { - soft_mesh = p_mesh; - } +void SoftBodyBullet::set_soft_mesh(RID p_mesh) { + destroy_soft_body(); + + soft_mesh = p_mesh; if (soft_mesh.is_null()) { - destroy_soft_body(); return; } - Array arrays = soft_mesh->surface_get_arrays(0); - ERR_FAIL_COND(!(soft_mesh->surface_get_format(0) & RS::ARRAY_FORMAT_INDEX)); - set_trimesh_body_shape(arrays[RS::ARRAY_INDEX], arrays[RS::ARRAY_VERTEX]); + Array arrays = RenderingServer::get_singleton()->mesh_surface_get_arrays(soft_mesh, 0); + + bool success = set_trimesh_body_shape(arrays[RS::ARRAY_INDEX], arrays[RS::ARRAY_VERTEX]); + if (!success) { + destroy_soft_body(); + } } void SoftBodyBullet::destroy_soft_body() { + soft_mesh = RID(); + if (!bt_soft_body) { return; } @@ -289,9 +292,9 @@ void SoftBodyBullet::set_drag_coefficient(real_t p_val) { } } -void SoftBodyBullet::set_trimesh_body_shape(Vector<int> p_indices, Vector<Vector3> p_vertices) { - /// Assert the current soft body is destroyed - destroy_soft_body(); +bool SoftBodyBullet::set_trimesh_body_shape(Vector<int> p_indices, Vector<Vector3> p_vertices) { + ERR_FAIL_COND_V(p_indices.is_empty(), false); + ERR_FAIL_COND_V(p_vertices.is_empty(), false); /// Parse visual server indices to physical indices. /// Merge all overlapping vertices and create a map of physical vertices to visual server @@ -363,6 +366,8 @@ void SoftBodyBullet::set_trimesh_body_shape(Vector<int> p_indices, Vector<Vector bt_soft_body = btSoftBodyHelpers::CreateFromTriMesh(fake_world_info, &bt_vertices[0], &bt_triangles[0], triangles_size, false); setup_soft_body(); } + + return true; } void SoftBodyBullet::setup_soft_body() { diff --git a/modules/bullet/soft_body_bullet.h b/modules/bullet/soft_body_bullet.h index 63708b57a7..84da56ae69 100644 --- a/modules/bullet/soft_body_bullet.h +++ b/modules/bullet/soft_body_bullet.h @@ -32,7 +32,6 @@ #define SOFT_BODY_BULLET_H #include "collision_object_bullet.h" -#include "scene/resources/material.h" // TODO remove this please #ifdef None /// This is required to remove the macro None defined by x11 compiler because this word "None" is used internally by Bullet @@ -42,7 +41,6 @@ #include "BulletSoftBody/btSoftBodyHelpers.h" #include "collision_object_bullet.h" -#include "scene/resources/mesh.h" #include "servers/physics_server_3d.h" #ifdef x11_None @@ -64,7 +62,7 @@ private: btSoftBody::Material *mat0 = nullptr; // This is just a copy of pointer managed by btSoftBody bool isScratched = false; - Ref<Mesh> soft_mesh; + RID soft_mesh; int simulation_precision = 5; real_t total_mass = 1.; @@ -100,7 +98,7 @@ public: void update_rendering_server(RenderingServerHandler *p_rendering_server_handler); - void set_soft_mesh(const Ref<Mesh> &p_mesh); + void set_soft_mesh(RID p_mesh); void destroy_soft_body(); // Special function. This function has bad performance @@ -139,7 +137,7 @@ public: _FORCE_INLINE_ real_t get_drag_coefficient() const { return drag_coefficient; } private: - void set_trimesh_body_shape(Vector<int> p_indices, Vector<Vector3> p_vertices); + bool set_trimesh_body_shape(Vector<int> p_indices, Vector<Vector3> p_vertices); void setup_soft_body(); void pin_node(int p_node_index); diff --git a/modules/csg/csg.cpp b/modules/csg/csg.cpp index 229e1e2724..53694035dc 100644 --- a/modules/csg/csg.cpp +++ b/modules/csg/csg.cpp @@ -258,8 +258,8 @@ void CSGBrush::build_from_faces(const Vector<Vector3> &p_vertices, const Vector< } materials.resize(material_map.size()); - for (Map<Ref<Material>, int>::Element *E = material_map.front(); E; E = E->next()) { - materials.write[E->get()] = E->key(); + for (const KeyValue<Ref<Material>, int> &E : material_map) { + materials.write[E.value] = E.key; } _regen_face_aabbs(); @@ -457,8 +457,8 @@ void CSGBrushOperation::merge_brushes(Operation p_operation, const CSGBrush &p_b // Update the list of materials. r_merged_brush.materials.resize(mesh_merge.materials.size()); - for (const Map<Ref<Material>, int>::Element *E = mesh_merge.materials.front(); E; E = E->next()) { - r_merged_brush.materials.write[E->get()] = E->key(); + for (const KeyValue<Ref<Material>, int> &E : mesh_merge.materials) { + r_merged_brush.materials.write[E.value] = E.key; } } diff --git a/modules/enet/enet_multiplayer_peer.cpp b/modules/enet/enet_multiplayer_peer.cpp index 52eb46f070..2cfae60ad2 100644 --- a/modules/enet/enet_multiplayer_peer.cpp +++ b/modules/enet/enet_multiplayer_peer.cpp @@ -444,7 +444,7 @@ Error ENetMultiplayerPeer::put_packet(const uint8_t *p_buffer, int p_buffer_size packet_flags = ENET_PACKET_FLAG_UNSEQUENCED; channel = SYSCH_UNRELIABLE; } break; - case Multiplayer::TRANSFER_MODE_ORDERED: { + case Multiplayer::TRANSFER_MODE_UNRELIABLE_ORDERED: { packet_flags = 0; channel = SYSCH_UNRELIABLE; } break; diff --git a/modules/fbx/data/fbx_skeleton.cpp b/modules/fbx/data/fbx_skeleton.cpp index 1ac4922acf..3dc163964c 100644 --- a/modules/fbx/data/fbx_skeleton.cpp +++ b/modules/fbx/data/fbx_skeleton.cpp @@ -98,9 +98,9 @@ void FBXSkeleton::init_skeleton(const ImportState &state) { ERR_FAIL_COND_MSG(skeleton->get_bone_count() != bone_count, "Not all bones got added, is the file corrupted?"); - for (Map<int, Ref<FBXBone>>::Element *bone_element = bone_map.front(); bone_element; bone_element = bone_element->next()) { - const Ref<FBXBone> bone = bone_element->value(); - int bone_index = bone_element->key(); + for (const KeyValue<int, Ref<FBXBone>> &bone_element : bone_map) { + const Ref<FBXBone> bone = bone_element.value; + int bone_index = bone_element.key; print_verbose("working on bone: " + itos(bone_index) + " bone name:" + bone->bone_name); skeleton->set_bone_rest(bone->godot_bone_id, get_unscaled_transform(bone->node->pivot_transform->LocalTransform, state.scale)); diff --git a/modules/fbx/editor_scene_importer_fbx.cpp b/modules/fbx/editor_scene_importer_fbx.cpp index e3f36ef3e3..e0663ab49d 100644 --- a/modules/fbx/editor_scene_importer_fbx.cpp +++ b/modules/fbx/editor_scene_importer_fbx.cpp @@ -567,8 +567,8 @@ Node3D *EditorSceneImporterFBX::_generate_scene( // this means that the nodes from maya kLocators will be preserved as bones // in the same rig without having to match this across skeletons and merge by detection // we can just merge and undo any parent transforms - for (Map<uint64_t, Ref<FBXBone>>::Element *bone_element = state.fbx_bone_map.front(); bone_element; bone_element = bone_element->next()) { - Ref<FBXBone> bone = bone_element->value(); + for (KeyValue<uint64_t, Ref<FBXBone>> &bone_element : state.fbx_bone_map) { + Ref<FBXBone> bone = bone_element.value; Ref<FBXSkeleton> fbx_skeleton_inst; uint64_t armature_id = bone->armature_id; @@ -609,8 +609,8 @@ Node3D *EditorSceneImporterFBX::_generate_scene( } // setup skeleton instances if required :) - for (Map<uint64_t, Ref<FBXSkeleton>>::Element *skeleton_node = state.skeleton_map.front(); skeleton_node; skeleton_node = skeleton_node->next()) { - Ref<FBXSkeleton> &skeleton = skeleton_node->value(); + for (KeyValue<uint64_t, Ref<FBXSkeleton>> &skeleton_node : state.skeleton_map) { + Ref<FBXSkeleton> &skeleton = skeleton_node.value; skeleton->init_skeleton(state); ERR_CONTINUE_MSG(skeleton->fbx_node.is_null(), "invalid fbx target map, missing skeleton"); @@ -699,9 +699,9 @@ Node3D *EditorSceneImporterFBX::_generate_scene( } } - for (Map<uint64_t, Ref<FBXMeshData>>::Element *mesh_data = state.renderer_mesh_data.front(); mesh_data; mesh_data = mesh_data->next()) { - const uint64_t mesh_id = mesh_data->key(); - Ref<FBXMeshData> mesh = mesh_data->value(); + for (KeyValue<uint64_t, Ref<FBXMeshData>> &mesh_data : state.renderer_mesh_data) { + const uint64_t mesh_id = mesh_data.key; + Ref<FBXMeshData> mesh = mesh_data.value; const FBXDocParser::MeshGeometry *mesh_geometry = p_document->GetObject(mesh_id)->Get<FBXDocParser::MeshGeometry>(); @@ -765,9 +765,9 @@ Node3D *EditorSceneImporterFBX::_generate_scene( } // mesh data iteration for populating skeleton mapping - for (Map<uint64_t, Ref<FBXMeshData>>::Element *mesh_data = state.renderer_mesh_data.front(); mesh_data; mesh_data = mesh_data->next()) { - Ref<FBXMeshData> mesh = mesh_data->value(); - const uint64_t mesh_id = mesh_data->key(); + for (KeyValue<uint64_t, Ref<FBXMeshData>> &mesh_data : state.renderer_mesh_data) { + Ref<FBXMeshData> mesh = mesh_data.value; + const uint64_t mesh_id = mesh_data.key; EditorSceneImporterMeshNode3D *mesh_instance = mesh->godot_mesh_instance; const int mesh_weights = mesh->max_weight_count; Ref<FBXSkeleton> skeleton; @@ -1004,13 +1004,13 @@ Node3D *EditorSceneImporterFBX::_generate_scene( // target id, [ track name, [time index, vector] ] //std::map<uint64_t, std::map<StringName, FBXTrack > > AnimCurveNodes; - for (Map<uint64_t, Map<StringName, FBXTrack>>::Element *track = AnimCurveNodes.front(); track; track = track->next()) { + for (KeyValue<uint64_t, Map<StringName, FBXTrack>> &track : AnimCurveNodes) { // 5 tracks // current track index // track count is 5 // track count is 5. // next track id is 5. - const uint64_t target_id = track->key(); + const uint64_t target_id = track.key; int track_idx = animation->add_track(Animation::TYPE_TRANSFORM3D); // animation->track_set_path(track_idx, node_path); @@ -1072,7 +1072,7 @@ Node3D *EditorSceneImporterFBX::_generate_scene( const FBXDocParser::Model *model = target_node->fbx_model; const FBXDocParser::PropertyTable *props = dynamic_cast<const FBXDocParser::PropertyTable *>(model); - Map<StringName, FBXTrack> &track_data = track->value(); + Map<StringName, FBXTrack> &track_data = track.value; FBXTrack &translation_keys = track_data[StringName("T")]; FBXTrack &rotation_keys = track_data[StringName("R")]; FBXTrack &scale_keys = track_data[StringName("S")]; @@ -1259,15 +1259,15 @@ Node3D *EditorSceneImporterFBX::_generate_scene( state.fbx_target_map.clear(); state.fbx_node_list.clear(); - for (Map<uint64_t, Ref<FBXBone>>::Element *element = state.fbx_bone_map.front(); element; element = element->next()) { - Ref<FBXBone> bone = element->value(); + for (KeyValue<uint64_t, Ref<FBXBone>> &element : state.fbx_bone_map) { + Ref<FBXBone> bone = element.value; bone->parent_bone.unref(); bone->node.unref(); bone->fbx_skeleton.unref(); } - for (Map<uint64_t, Ref<FBXSkeleton>>::Element *element = state.skeleton_map.front(); element; element = element->next()) { - Ref<FBXSkeleton> skel = element->value(); + for (KeyValue<uint64_t, Ref<FBXSkeleton>> &element : state.skeleton_map) { + Ref<FBXSkeleton> skel = element.value; skel->fbx_node.unref(); skel->skeleton_bones.clear(); } diff --git a/modules/fbx/tools/validation_tools.h b/modules/fbx/tools/validation_tools.h index 906a721045..12d644ee94 100644 --- a/modules/fbx/tools/validation_tools.h +++ b/modules/fbx/tools/validation_tools.h @@ -53,9 +53,9 @@ protected: String csv_header = "file_path, error message, extra data\n"; massive_log_file += csv_header; - for (Map<String, LocalVector<String>>::Element *element = validation_entries.front(); element; element = element->next()) { - for (unsigned int x = 0; x < element->value().size(); x++) { - const String &line_entry = element->key() + ", " + element->value()[x].c_escape() + "\n"; + for (const KeyValue<String, LocalVector<String>> &element : validation_entries) { + for (unsigned int x = 0; x < element.value.size(); x++) { + const String &line_entry = element.key + ", " + element.value[x].c_escape() + "\n"; massive_log_file += line_entry; } } diff --git a/modules/gdnative/SCsub b/modules/gdnative/SCsub index 94bda04d12..f7f21a433e 100644 --- a/modules/gdnative/SCsub +++ b/modules/gdnative/SCsub @@ -18,7 +18,6 @@ Export("env_gdnative") SConscript("pluginscript/SCsub") SConscript("videodecoder/SCsub") -SConscript("text/SCsub") import gdnative_builders diff --git a/modules/gdnative/gdnative_api.json b/modules/gdnative/gdnative_api.json index 627883886c..cf1c7dc01f 100644 --- a/modules/gdnative/gdnative_api.json +++ b/modules/gdnative/gdnative_api.json @@ -5103,489 +5103,6 @@ ] } ] - }, - { - "name": "text", - "type": "TEXT", - "version": { - "major": 1, - "minor": 0 - }, - "next": null, - "api": [ - { - "name": "godot_text_register_interface", - "return_type": "void", - "arguments": [ - [ - "const godot_text_interface_gdnative *", - "p_interface" - ], - [ - "const godot_string *", - "p_name" - ], - [ - "uint32_t", - "p_features" - ] - ] - }, - { - "name": "godot_glyph_new", - "return_type": "void", - "arguments": [ - [ - "godot_glyph *", - "r_dest" - ] - ] - }, - { - "name": "godot_glyph_get_range", - "return_type": "godot_vector2i", - "arguments": [ - [ - "const godot_glyph *", - "p_self" - ] - ] - }, - { - "name": "godot_glyph_set_range", - "return_type": "void", - "arguments": [ - [ - "godot_glyph *", - "p_self" - ], - [ - "const godot_vector2i *", - "p_range" - ] - ] - }, - { - "name": "godot_glyph_get_count", - "return_type": "godot_int", - "arguments": [ - [ - "const godot_glyph *", - "p_self" - ] - ] - }, - { - "name": "godot_glyph_set_count", - "return_type": "void", - "arguments": [ - [ - "godot_glyph *", - "p_self" - ], - [ - "godot_int", - "p_count" - ] - ] - }, - { - "name": "godot_glyph_get_repeat", - "return_type": "godot_int", - "arguments": [ - [ - "const godot_glyph *", - "p_self" - ] - ] - }, - { - "name": "godot_glyph_set_repeat", - "return_type": "void", - "arguments": [ - [ - "godot_glyph *", - "p_self" - ], - [ - "godot_int", - "p_repeat" - ] - ] - }, - { - "name": "godot_glyph_get_flags", - "return_type": "godot_int", - "arguments": [ - [ - "const godot_glyph *", - "p_self" - ] - ] - }, - { - "name": "godot_glyph_set_flags", - "return_type": "void", - "arguments": [ - [ - "godot_glyph *", - "p_self" - ], - [ - "godot_int", - "p_flags" - ] - ] - }, - { - "name": "godot_glyph_get_offset", - "return_type": "godot_vector2", - "arguments": [ - [ - "const godot_glyph *", - "p_self" - ] - ] - }, - { - "name": "godot_glyph_set_offset", - "return_type": "void", - "arguments": [ - [ - "godot_glyph *", - "p_self" - ], - [ - "const godot_vector2 *", - "p_offset" - ] - ] - }, - { - "name": "godot_glyph_get_advance", - "return_type": "godot_real_t", - "arguments": [ - [ - "const godot_glyph *", - "p_self" - ] - ] - }, - { - "name": "godot_glyph_set_advance", - "return_type": "void", - "arguments": [ - [ - "godot_glyph *", - "p_self" - ], - [ - "godot_real_t", - "p_advance" - ] - ] - }, - { - "name": "godot_glyph_get_font", - "return_type": "godot_rid", - "arguments": [ - [ - "const godot_glyph *", - "p_self" - ] - ] - }, - { - "name": "godot_glyph_set_font", - "return_type": "void", - "arguments": [ - [ - "godot_glyph *", - "p_self" - ], - [ - "godot_rid *", - "p_font" - ] - ] - }, - { - "name": "godot_glyph_get_font_size", - "return_type": "godot_int", - "arguments": [ - [ - "const godot_glyph *", - "p_self" - ] - ] - }, - { - "name": "godot_glyph_set_font_size", - "return_type": "void", - "arguments": [ - [ - "godot_glyph *", - "p_self" - ], - [ - "godot_int", - "p_size" - ] - ] - }, - { - "name": "godot_glyph_get_index", - "return_type": "godot_int", - "arguments": [ - [ - "const godot_glyph *", - "p_self" - ] - ] - }, - { - "name": "godot_glyph_set_index", - "return_type": "void", - "arguments": [ - [ - "godot_glyph *", - "p_self" - ], - [ - "godot_int", - "p_index" - ] - ] - }, - { - "name": "godot_packed_glyph_array_new", - "return_type": "void", - "arguments": [ - [ - "godot_packed_glyph_array *", - "r_dest" - ] - ] - }, - { - "name": "godot_packed_glyph_array_new_copy", - "return_type": "void", - "arguments": [ - [ - "godot_packed_glyph_array *", - "r_dest" - ], - [ - "const godot_packed_glyph_array *", - "p_src" - ] - ] - }, - { - "name": "godot_packed_glyph_array_is_empty", - "return_type": "godot_bool", - "arguments": [ - [ - "const godot_packed_glyph_array *", - "p_self" - ] - ] - }, - { - "name": "godot_packed_glyph_array_append", - "return_type": "void", - "arguments": [ - [ - "godot_packed_glyph_array *", - "p_self" - ], - [ - "const godot_glyph *", - "p_data" - ] - ] - }, - { - "name": "godot_packed_glyph_array_append_array", - "return_type": "void", - "arguments": [ - [ - "godot_packed_glyph_array *", - "p_self" - ], - [ - "const godot_packed_glyph_array *", - "p_array" - ] - ] - }, - { - "name": "godot_packed_glyph_array_insert", - "return_type": "godot_error", - "arguments": [ - [ - "godot_packed_glyph_array *", - "p_self" - ], - [ - "const godot_int", - "p_idx" - ], - [ - "const godot_glyph *", - "p_data" - ] - ] - }, - { - "name": "godot_packed_glyph_array_has", - "return_type": "godot_bool", - "arguments": [ - [ - "godot_packed_glyph_array *", - "p_self" - ], - [ - "const godot_glyph *", - "p_value" - ] - ] - }, - { - "name": "godot_packed_glyph_array_sort", - "return_type": "void", - "arguments": [ - [ - "godot_packed_glyph_array *", - "p_self" - ] - ] - }, - { - "name": "godot_packed_glyph_array_reverse", - "return_type": "void", - "arguments": [ - [ - "godot_packed_glyph_array *", - "p_self" - ] - ] - }, - { - "name": "godot_packed_glyph_array_push_back", - "return_type": "void", - "arguments": [ - [ - "godot_packed_glyph_array *", - "p_self" - ], - [ - "const godot_glyph *", - "p_data" - ] - ] - }, - { - "name": "godot_packed_glyph_array_remove", - "return_type": "void", - "arguments": [ - [ - "godot_packed_glyph_array *", - "p_self" - ], - [ - "const godot_int", - "p_idx" - ] - ] - }, - { - "name": "godot_packed_glyph_array_resize", - "return_type": "void", - "arguments": [ - [ - "godot_packed_glyph_array *", - "p_self" - ], - [ - "const godot_int", - "p_size" - ] - ] - }, - { - "name": "godot_packed_glyph_array_ptr", - "return_type": "const godot_glyph *", - "arguments": [ - [ - "const godot_packed_glyph_array *", - "p_self" - ] - ] - }, - { - "name": "godot_packed_glyph_array_ptrw", - "return_type": "godot_glyph *", - "arguments": [ - [ - "godot_packed_glyph_array *", - "p_self" - ] - ] - }, - { - "name": "godot_packed_glyph_array_set", - "return_type": "void", - "arguments": [ - [ - "godot_packed_glyph_array *", - "p_self" - ], - [ - "const godot_int", - "p_idx" - ], - [ - "const godot_glyph *", - "p_data" - ] - ] - }, - { - "name": "godot_packed_glyph_array_get", - "return_type": "godot_glyph", - "arguments": [ - [ - "const godot_packed_glyph_array *", - "p_self" - ], - [ - "const godot_int", - "p_idx" - ] - ] - }, - { - "name": "godot_packed_glyph_array_size", - "return_type": "godot_int", - "arguments": [ - [ - "const godot_packed_glyph_array *", - "p_self" - ] - ] - }, - { - "name": "godot_packed_glyph_array_destroy", - "return_type": "void", - "arguments": [ - [ - "godot_packed_glyph_array *", - "p_self" - ] - ] - } - ] } ] } diff --git a/modules/gdnative/gdnative_builders.py b/modules/gdnative/gdnative_builders.py index 4986b173cf..6c96e23426 100644 --- a/modules/gdnative/gdnative_builders.py +++ b/modules/gdnative/gdnative_builders.py @@ -22,7 +22,6 @@ def _build_gdnative_api_struct_header(api): "#include <nativescript/godot_nativescript.h>", "#include <pluginscript/godot_pluginscript.h>", "#include <videodecoder/godot_videodecoder.h>", - "#include <text/godot_text.h>", "", "#ifdef __cplusplus", 'extern "C" {', diff --git a/modules/gdnative/gdnative_library_editor_plugin.cpp b/modules/gdnative/gdnative_library_editor_plugin.cpp index f965bcd014..9dad13a615 100644 --- a/modules/gdnative/gdnative_library_editor_plugin.cpp +++ b/modules/gdnative/gdnative_library_editor_plugin.cpp @@ -38,9 +38,9 @@ void GDNativeLibraryEditor::edit(Ref<GDNativeLibrary> p_library) { library = p_library; Ref<ConfigFile> config = p_library->get_config_file(); - for (Map<String, NativePlatformConfig>::Element *E = platforms.front(); E; E = E->next()) { - for (List<String>::Element *it = E->value().entries.front(); it; it = it->next()) { - String target = E->key() + "." + it->get(); + for (KeyValue<String, NativePlatformConfig> &E : platforms) { + for (List<String>::Element *it = E.value.entries.front(); it; it = it->next()) { + String target = E.key + "." + it->get(); TargetConfig ecfg; ecfg.library = config->get_value("entry", target, ""); ecfg.dependencies = config->get_value("dependencies", target, Array()); @@ -245,9 +245,9 @@ void GDNativeLibraryEditor::_translate_to_config_file() { config->erase_section("entry"); config->erase_section("dependencies"); - for (Map<String, NativePlatformConfig>::Element *E = platforms.front(); E; E = E->next()) { - for (List<String>::Element *it = E->value().entries.front(); it; it = it->next()) { - String target = E->key() + "." + it->get(); + for (KeyValue<String, NativePlatformConfig> &E : platforms) { + for (List<String>::Element *it = E.value.entries.front(); it; it = it->next()) { + String target = E.key + "." + it->get(); if (entry_configs[target].library.is_empty() && entry_configs[target].dependencies.is_empty()) { continue; } @@ -341,9 +341,9 @@ GDNativeLibraryEditor::GDNativeLibraryEditor() { filter_list->set_hide_on_checkable_item_selection(false); int idx = 0; - for (Map<String, NativePlatformConfig>::Element *E = platforms.front(); E; E = E->next()) { - filter_list->add_check_item(E->get().name, idx); - filter_list->set_item_metadata(idx, E->key()); + for (const KeyValue<String, NativePlatformConfig> &E : platforms) { + filter_list->add_check_item(E.value.name, idx); + filter_list->set_item_metadata(idx, E.key); filter_list->set_item_checked(idx, true); idx += 1; } diff --git a/modules/gdnative/include/nativescript/godot_nativescript.h b/modules/gdnative/include/nativescript/godot_nativescript.h index 09eac2492f..5390d30c9f 100644 --- a/modules/gdnative/include/nativescript/godot_nativescript.h +++ b/modules/gdnative/include/nativescript/godot_nativescript.h @@ -39,7 +39,7 @@ extern "C" { typedef enum { GODOT_METHOD_RPC_MODE_DISABLED, - GODOT_METHOD_RPC_MODE_ANY, + GODOT_METHOD_RPC_MODE_ANY_PEER, GODOT_METHOD_RPC_MODE_AUTHORITY, } godot_nativescript_method_rpc_mode; diff --git a/modules/gdnative/include/text/godot_text.h b/modules/gdnative/include/text/godot_text.h deleted file mode 100644 index 940cfd11f8..0000000000 --- a/modules/gdnative/include/text/godot_text.h +++ /dev/null @@ -1,283 +0,0 @@ -/*************************************************************************/ -/* godot_text.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef GODOT_NATIVETEXT_H -#define GODOT_NATIVETEXT_H - -#include <gdnative/gdnative.h> - -#ifdef __cplusplus -extern "C" { -#endif - -#define GODOT_TEXT_API_MAJOR 1 -#define GODOT_TEXT_API_MINOR 0 - -#define GODOT_GLYPH_SIZE 40 - -#ifndef GODOT_TEXT_API_GODOT_GLYPH_TYPE_DEFINED -#define GODOT_TEXT_API_GODOT_GLYPH_TYPE_DEFINED -typedef struct { - uint8_t _dont_touch_that[GODOT_GLYPH_SIZE]; -} godot_glyph; -#endif - -#define GODOT_PACKED_GLYPH_ARRAY_SIZE (2 * sizeof(void *)) - -#ifndef GODOT_TEXT_API_GODOT_PACKED_GLYPH_ARRAY_TYPE_DEFINED -#define GODOT_TEXT_API_GODOT_PACKED_GLYPH_ARRAY_TYPE_DEFINED -typedef struct { - uint8_t _dont_touch_that[GODOT_PACKED_GLYPH_ARRAY_SIZE]; -} godot_packed_glyph_array; -#endif - -typedef struct { - godot_gdnative_api_version version; - - void *(*constructor)(godot_object *); - void (*destructor)(void *); - - godot_string (*get_name)(const void *); - godot_bool (*has_feature)(const void *, godot_int); - - void (*free)(void *, godot_rid *); - bool (*has)(void *, godot_rid *); - - bool (*load_support_data)(void *, const godot_string *); - godot_string (*get_support_data_filename)(const void *); - godot_string (*get_support_data_info)(const void *); - bool (*save_support_data)(void *, const godot_string *); - - bool (*is_locale_right_to_left)(void *, const godot_string *); - int32_t (*name_to_tag)(const void *, const godot_string *); - godot_string (*tag_to_name)(const void *, int32_t); - - godot_rid (*create_font)(void *); - void (*font_set_data)(void *, godot_rid *, const godot_packed_byte_array *); - void (*font_set_data_ptr)(void *, godot_rid *, const uint8_t *, size_t); - void (*font_set_antialiased)(void *, godot_rid *, bool); - bool (*font_is_antialiased)(const void *, godot_rid *); - void (*font_set_multichannel_signed_distance_field)(void *, godot_rid *, bool); - bool (*font_is_multichannel_signed_distance_field)(const void *, godot_rid *); - void (*font_set_msdf_pixel_range)(void *, godot_rid *, godot_int); - godot_int (*font_get_msdf_pixel_range)(const void *, godot_rid *); - void (*font_set_msdf_size)(void *, godot_rid *, godot_int); - godot_int (*font_get_msdf_size)(const void *, godot_rid *); - void (*font_set_fixed_size)(void *, godot_rid *, godot_int); - godot_int (*font_get_fixed_size)(const void *, godot_rid *); - void (*font_set_force_autohinter)(void *, godot_rid *, bool); - bool (*font_is_force_autohinter)(const void *, godot_rid *); - void (*font_set_hinting)(void *, godot_rid *, godot_int); - godot_int (*font_get_hinting)(const void *, godot_rid *); - void (*font_set_variation_coordinates)(void *, godot_rid *, const godot_dictionary *); - godot_dictionary (*font_get_variation_coordinates)(const void *, godot_rid *); - void (*font_set_oversampling)(void *, godot_rid *, godot_real_t); - godot_real_t (*font_get_oversampling)(const void *, godot_rid *); - godot_array (*font_get_size_cache_list)(const void *, godot_rid *); - void (*font_clear_size_cache)(void *, godot_rid *); - void (*font_remove_size_cache)(void *, godot_rid *, const godot_vector2i *); - void (*font_set_ascent)(void *, godot_rid *, godot_int, godot_real_t); - godot_real_t (*font_get_ascent)(const void *, godot_rid *, godot_int); - void (*font_set_descent)(void *, godot_rid *, godot_int, godot_real_t); - godot_real_t (*font_get_descent)(const void *, godot_rid *, godot_int); - void (*font_set_underline_position)(void *, godot_rid *, godot_int, godot_real_t); - godot_real_t (*font_get_underline_position)(const void *, godot_rid *, godot_int); - void (*font_set_underline_thickness)(void *, godot_rid *, godot_int, godot_real_t); - godot_real_t (*font_get_underline_thickness)(const void *, godot_rid *, godot_int); - void (*font_set_scale)(void *, godot_rid *, godot_int, godot_real_t); - godot_real_t (*font_get_scale)(const void *, godot_rid *, godot_int); - void (*font_set_spacing)(void *, godot_rid *, godot_int, godot_int, godot_int); - godot_int (*font_get_spacing)(const void *, godot_rid *, godot_int, godot_int); - godot_int (*font_get_texture_count)(const void *, godot_rid *, const godot_vector2i *); - void (*font_clear_textures)(void *, godot_rid *, const godot_vector2i *); - void (*font_remove_texture)(void *, godot_rid *, const godot_vector2i *, godot_int); - void (*font_set_texture_image)(void *, godot_rid *, const godot_vector2i *, godot_int, const godot_object *); - godot_object *(*font_get_texture_image)(const void *, godot_rid *, const godot_vector2i *, godot_int); - void (*font_set_texture_offsets)(void *, godot_rid *, const godot_vector2i *, godot_int, const godot_packed_int32_array *); - godot_packed_int32_array (*font_get_texture_offsets)(const void *, godot_rid *, const godot_vector2i *, godot_int); - godot_array (*font_get_glyph_list)(const void *, godot_rid *, const godot_vector2i *); - void (*font_clear_glyphs)(void *, godot_rid *, const godot_vector2i *); - void (*font_remove_glyph)(void *, godot_rid *, const godot_vector2i *, int32_t); - godot_vector2 (*font_get_glyph_advance)(const void *, godot_rid *, godot_int, int32_t); - void (*font_set_glyph_advance)(void *, godot_rid *, godot_int, int32_t, const godot_vector2 *); - godot_vector2 (*font_get_glyph_offset)(const void *, godot_rid *, const godot_vector2i *, int32_t); - void (*font_set_glyph_offset)(void *, godot_rid *, const godot_vector2i *, int32_t, const godot_vector2 *); - godot_vector2 (*font_get_glyph_size)(const void *, godot_rid *, const godot_vector2i *, int32_t); - void (*font_set_glyph_size)(void *, godot_rid *, const godot_vector2i *, int32_t, const godot_vector2 *); - godot_rect2 (*font_get_glyph_uv_rect)(const void *, godot_rid *, const godot_vector2i *, int32_t); - void (*font_set_glyph_uv_rect)(void *, godot_rid *, const godot_vector2i *, int32_t, const godot_rect2 *); - godot_int (*font_get_glyph_texture_idx)(const void *, godot_rid *, const godot_vector2i *, int32_t); - void (*font_set_glyph_texture_idx)(void *, godot_rid *, const godot_vector2i *, int32_t, godot_int); - bool (*font_get_glyph_contours)(const void *, godot_rid *, godot_int, int32_t, godot_packed_vector3_array *, godot_packed_int32_array *, bool *); - godot_array (*font_get_kerning_list)(const void *, godot_rid *, godot_int); - void (*font_clear_kerning_map)(void *, godot_rid *, godot_int); - void (*font_remove_kerning)(void *, godot_rid *, godot_int, const godot_vector2i *); - void (*font_set_kerning)(void *, godot_rid *, godot_int, const godot_vector2i *, const godot_vector2 *); - godot_vector2 (*font_get_kerning)(const void *, godot_rid *, godot_int, const godot_vector2i *); - int32_t (*font_get_glyph_index)(const void *, godot_rid *, godot_int, char32_t, char32_t); - bool (*font_has_char)(const void *, godot_rid *, char32_t); - godot_string (*font_get_supported_chars)(const void *, godot_rid *); - void (*font_render_range)(void *, godot_rid *, const godot_vector2i *, char32_t, char32_t); - void (*font_render_glyph)(void *, godot_rid *, const godot_vector2i *, int32_t); - void (*font_draw_glyph)(const void *, godot_rid *, godot_rid *, godot_int, const godot_vector2 *, int32_t, const godot_color *); - void (*font_draw_glyph_outline)(const void *, godot_rid *, godot_rid *, godot_int, godot_int, const godot_vector2 *, int32_t, const godot_color *); - bool (*font_is_language_supported)(const void *, godot_rid *, const godot_string *); - void (*font_set_language_support_override)(void *, godot_rid *, const godot_string *, bool); - bool (*font_get_language_support_override)(const void *, godot_rid *, const godot_string *); - void (*font_remove_language_support_override)(void *, godot_rid *, const godot_string *); - godot_packed_string_array (*font_get_language_support_overrides)(const void *, godot_rid *); - bool (*font_is_script_supported)(const void *, godot_rid *, const godot_string *); - void (*font_set_script_support_override)(void *, godot_rid *, const godot_string *, bool); - bool (*font_get_script_support_override)(const void *, godot_rid *, const godot_string *); - void (*font_remove_script_support_override)(void *, godot_rid *, const godot_string *); - godot_packed_string_array (*font_get_script_support_overrides)(const void *, godot_rid *); - godot_dictionary (*font_supported_feature_list)(const void *, godot_rid *); - godot_dictionary (*font_supported_variation_list)(const void *, godot_rid *); - godot_real_t (*font_get_global_oversampling)(const void *); - void (*font_set_global_oversampling)(void *, godot_real_t); - - godot_rid (*create_shaped_text)(void *, godot_int, godot_int); - void (*shaped_text_clear)(void *, godot_rid *); - void (*shaped_text_set_direction)(void *, godot_rid *, godot_int); - godot_int (*shaped_text_get_direction)(void *, godot_rid *); - void (*shaped_text_set_bidi_override)(void *, godot_rid *, const godot_packed_vector2i_array *); - void (*shaped_text_set_orientation)(void *, godot_rid *, godot_int); - godot_int (*shaped_text_get_orientation)(void *, godot_rid *); - void (*shaped_text_set_preserve_invalid)(void *, godot_rid *, bool); - bool (*shaped_text_get_preserve_invalid)(void *, godot_rid *); - void (*shaped_text_set_preserve_control)(void *, godot_rid *, bool); - bool (*shaped_text_get_preserve_control)(void *, godot_rid *); - bool (*shaped_text_add_string)(void *, godot_rid *, const godot_string *, const godot_rid **, int, const godot_dictionary *, const godot_string *); - bool (*shaped_text_add_object)(void *, godot_rid *, const godot_variant *, const godot_vector2 *, godot_int, godot_int); - bool (*shaped_text_resize_object)(void *, godot_rid *, const godot_variant *, const godot_vector2 *, godot_int); - godot_rid (*shaped_text_substr)(void *, godot_rid *, godot_int, godot_int); - godot_rid (*shaped_text_get_parent)(void *, godot_rid *); - godot_real_t (*shaped_text_fit_to_width)(void *, godot_rid *, godot_real_t, uint8_t); - godot_real_t (*shaped_text_tab_align)(void *, godot_rid *, godot_packed_float32_array *); - bool (*shaped_text_shape)(void *, godot_rid *); - bool (*shaped_text_update_breaks)(void *, godot_rid *); - bool (*shaped_text_update_justification_ops)(void *, godot_rid *); - void (*shaped_text_overrun_trim_to_width)(void *, godot_rid *, godot_real_t, uint8_t); - bool (*shaped_text_is_ready)(void *, godot_rid *); - godot_packed_glyph_array (*shaped_text_get_glyphs)(void *, godot_rid *); - godot_vector2i (*shaped_text_get_range)(void *, godot_rid *); - godot_packed_glyph_array (*shaped_text_sort_logical)(void *, godot_rid *); - godot_packed_vector2i_array (*shaped_text_get_line_breaks_adv)(void *, godot_rid *, godot_packed_float32_array *, int, bool, uint8_t); - godot_packed_vector2i_array (*shaped_text_get_line_breaks)(void *, godot_rid *, godot_real_t, int, uint8_t); - godot_packed_vector2i_array (*shaped_text_get_word_breaks)(void *, godot_rid *, int); - godot_array (*shaped_text_get_objects)(void *, godot_rid *); - godot_rect2 (*shaped_text_get_object_rect)(void *, godot_rid *, const godot_variant *); - godot_vector2 (*shaped_text_get_size)(void *, godot_rid *); - godot_real_t (*shaped_text_get_ascent)(void *, godot_rid *); - godot_real_t (*shaped_text_get_descent)(void *, godot_rid *); - godot_real_t (*shaped_text_get_width)(void *, godot_rid *); - godot_real_t (*shaped_text_get_underline_position)(void *, godot_rid *); - godot_real_t (*shaped_text_get_underline_thickness)(void *, godot_rid *); - - godot_string (*format_number)(void *, const godot_string *, const godot_string *); - godot_string (*parse_number)(void *, const godot_string *, const godot_string *); - godot_string (*percent_sign)(void *, const godot_string *); -} godot_text_interface_gdnative; - -void GDAPI godot_text_register_interface(const godot_text_interface_gdnative *p_interface, const godot_string *p_name, uint32_t p_features); - -// Glyph - -void GDAPI godot_glyph_new(godot_glyph *r_dest); - -godot_vector2i GDAPI godot_glyph_get_range(const godot_glyph *p_self); -void GDAPI godot_glyph_set_range(godot_glyph *p_self, const godot_vector2i *p_range); - -godot_int GDAPI godot_glyph_get_count(const godot_glyph *p_self); -void GDAPI godot_glyph_set_count(godot_glyph *p_self, godot_int p_count); - -godot_int GDAPI godot_glyph_get_repeat(const godot_glyph *p_self); -void GDAPI godot_glyph_set_repeat(godot_glyph *p_self, godot_int p_repeat); - -godot_int GDAPI godot_glyph_get_flags(const godot_glyph *p_self); -void GDAPI godot_glyph_set_flags(godot_glyph *p_self, godot_int p_flags); - -godot_vector2 GDAPI godot_glyph_get_offset(const godot_glyph *p_self); -void GDAPI godot_glyph_set_offset(godot_glyph *p_self, const godot_vector2 *p_offset); - -godot_real_t GDAPI godot_glyph_get_advance(const godot_glyph *p_self); -void GDAPI godot_glyph_set_advance(godot_glyph *p_self, godot_real_t p_advance); - -godot_rid GDAPI godot_glyph_get_font(const godot_glyph *p_self); -void GDAPI godot_glyph_set_font(godot_glyph *p_self, godot_rid *p_font); - -godot_int GDAPI godot_glyph_get_font_size(const godot_glyph *p_self); -void GDAPI godot_glyph_set_font_size(godot_glyph *p_self, godot_int p_size); - -godot_int GDAPI godot_glyph_get_index(const godot_glyph *p_self); -void GDAPI godot_glyph_set_index(godot_glyph *p_self, godot_int p_index); - -// GlyphArray - -void GDAPI godot_packed_glyph_array_new(godot_packed_glyph_array *r_dest); -void GDAPI godot_packed_glyph_array_new_copy(godot_packed_glyph_array *r_dest, const godot_packed_glyph_array *p_src); - -const godot_glyph GDAPI *godot_packed_glyph_array_ptr(const godot_packed_glyph_array *p_self); -godot_glyph GDAPI *godot_packed_glyph_array_ptrw(godot_packed_glyph_array *p_self); - -void GDAPI godot_packed_glyph_array_append(godot_packed_glyph_array *p_self, const godot_glyph *p_data); - -void GDAPI godot_packed_glyph_array_append_array(godot_packed_glyph_array *p_self, const godot_packed_glyph_array *p_array); - -godot_error GDAPI godot_packed_glyph_array_insert(godot_packed_glyph_array *p_self, const godot_int p_idx, const godot_glyph *p_data); - -godot_bool GDAPI godot_packed_glyph_array_has(godot_packed_glyph_array *p_self, const godot_glyph *p_value); - -void GDAPI godot_packed_glyph_array_sort(godot_packed_glyph_array *p_self); - -void GDAPI godot_packed_glyph_array_reverse(godot_packed_glyph_array *p_self); - -void GDAPI godot_packed_glyph_array_push_back(godot_packed_glyph_array *p_self, const godot_glyph *p_data); - -void GDAPI godot_packed_glyph_array_remove(godot_packed_glyph_array *p_self, godot_int p_idx); - -void GDAPI godot_packed_glyph_array_resize(godot_packed_glyph_array *p_self, godot_int p_size); - -void GDAPI godot_packed_glyph_array_set(godot_packed_glyph_array *p_self, godot_int p_idx, const godot_glyph *p_data); -godot_glyph GDAPI godot_packed_glyph_array_get(const godot_packed_glyph_array *p_self, godot_int p_idx); - -godot_int GDAPI godot_packed_glyph_array_size(const godot_packed_glyph_array *p_self); - -godot_bool GDAPI godot_packed_glyph_array_is_empty(const godot_packed_glyph_array *p_self); - -void GDAPI godot_packed_glyph_array_destroy(godot_packed_glyph_array *p_self); - -// Grapheme - -#ifdef __cplusplus -} -#endif - -#endif /* !GODOT_NATIVETEXT_H */ diff --git a/modules/gdnative/nativescript/api_generator.cpp b/modules/gdnative/nativescript/api_generator.cpp index 2d9b45cb07..598f7c7ad0 100644 --- a/modules/gdnative/nativescript/api_generator.cpp +++ b/modules/gdnative/nativescript/api_generator.cpp @@ -223,8 +223,8 @@ List<ClassAPI> generate_c_api_classes() { enum_api_map[enum_name] = enum_api; } } - for (const Map<StringName, EnumAPI>::Element *E = enum_api_map.front(); E; E = E->next()) { - global_constants_api.enums.push_back(E->get()); + for (const KeyValue<StringName, EnumAPI> &E : enum_api_map) { + global_constants_api.enums.push_back(E.value); } global_constants_api.constants.sort_custom<ConstantAPIComparator>(); api.push_back(global_constants_api); diff --git a/modules/gdnative/nativescript/nativescript.cpp b/modules/gdnative/nativescript/nativescript.cpp index 92ba9bd452..fb46bafb3c 100644 --- a/modules/gdnative/nativescript/nativescript.cpp +++ b/modules/gdnative/nativescript/nativescript.cpp @@ -360,8 +360,8 @@ void NativeScript::get_script_signal_list(List<MethodInfo> *r_signals) const { Set<MethodInfo> signals_; while (script_data) { - for (Map<StringName, NativeScriptDesc::Signal>::Element *S = script_data->signals_.front(); S; S = S->next()) { - signals_.insert(S->get().signal); + for (const KeyValue<StringName, NativeScriptDesc::Signal> &S : script_data->signals_) { + signals_.insert(S.value.signal); } script_data = script_data->base_data; @@ -401,8 +401,8 @@ void NativeScript::get_script_method_list(List<MethodInfo> *p_list) const { Set<MethodInfo> methods; while (script_data) { - for (Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.front(); E; E = E->next()) { - methods.insert(E->get().info); + for (const KeyValue<StringName, NativeScriptDesc::Method> &E : script_data->methods) { + methods.insert(E.value.info); } script_data = script_data->base_data; @@ -857,9 +857,9 @@ NativeScriptLanguage *NativeScriptLanguage::singleton; void NativeScriptLanguage::_unload_stuff(bool p_reload) { Map<String, Ref<GDNative>> erase_and_unload; - for (Map<String, Map<StringName, NativeScriptDesc>>::Element *L = library_classes.front(); L; L = L->next()) { - String lib_path = L->key(); - Map<StringName, NativeScriptDesc> classes = L->get(); + for (KeyValue<String, Map<StringName, NativeScriptDesc>> &L : library_classes) { + String lib_path = L.key; + Map<StringName, NativeScriptDesc> classes = L.value; if (p_reload) { Map<String, Ref<GDNative>>::Element *E = library_gdnatives.find(lib_path); @@ -890,9 +890,9 @@ void NativeScriptLanguage::_unload_stuff(bool p_reload) { gdn = E->get(); } - for (Map<StringName, NativeScriptDesc>::Element *C = classes.front(); C; C = C->next()) { + for (KeyValue<StringName, NativeScriptDesc> &C : classes) { // free property stuff first - for (OrderedHashMap<StringName, NativeScriptDesc::Property>::Element P = C->get().properties.front(); P; P = P.next()) { + for (OrderedHashMap<StringName, NativeScriptDesc::Property>::Element P = C.value.properties.front(); P; P = P.next()) { if (P.get().getter.free_func) { P.get().getter.free_func(P.get().getter.method_data); } @@ -903,28 +903,28 @@ void NativeScriptLanguage::_unload_stuff(bool p_reload) { } // free method stuff - for (Map<StringName, NativeScriptDesc::Method>::Element *M = C->get().methods.front(); M; M = M->next()) { - if (M->get().method.free_func) { - M->get().method.free_func(M->get().method.method_data); + for (const KeyValue<StringName, NativeScriptDesc::Method> &M : C.value.methods) { + if (M.value.method.free_func) { + M.value.method.free_func(M.value.method.method_data); } } // free constructor/destructor - if (C->get().create_func.free_func) { - C->get().create_func.free_func(C->get().create_func.method_data); + if (C.value.create_func.free_func) { + C.value.create_func.free_func(C.value.create_func.method_data); } - if (C->get().destroy_func.free_func) { - C->get().destroy_func.free_func(C->get().destroy_func.method_data); + if (C.value.destroy_func.free_func) { + C.value.destroy_func.free_func(C.value.destroy_func.method_data); } } erase_and_unload.insert(lib_path, gdn); } - for (Map<String, Ref<GDNative>>::Element *E = erase_and_unload.front(); E; E = E->next()) { - String lib_path = E->key(); - Ref<GDNative> gdn = E->get(); + for (KeyValue<String, Ref<GDNative>> &E : erase_and_unload) { + String lib_path = E.key; + Ref<GDNative> gdn = E.value; library_classes.erase(lib_path); @@ -957,8 +957,8 @@ NativeScriptLanguage::NativeScriptLanguage() { } NativeScriptLanguage::~NativeScriptLanguage() { - for (Map<String, Ref<GDNative>>::Element *L = NSL->library_gdnatives.front(); L; L = L->next()) { - Ref<GDNative> lib = L->get(); + for (KeyValue<String, Ref<GDNative>> &L : NSL->library_gdnatives) { + Ref<GDNative> lib = L.value; // only shut down valid libs, duh! if (lib.is_valid()) { // If it's a singleton-library then the gdnative module @@ -1157,15 +1157,15 @@ int NativeScriptLanguage::profiling_get_accumulated_data(ProfilingInfo *p_info_a int current = 0; - for (Map<StringName, ProfileData>::Element *d = profile_data.front(); d; d = d->next()) { + for (const KeyValue<StringName, ProfileData> &d : profile_data) { if (current >= p_info_max) { break; } - p_info_arr[current].call_count = d->get().call_count; - p_info_arr[current].self_time = d->get().self_time; - p_info_arr[current].total_time = d->get().total_time; - p_info_arr[current].signature = d->get().signature; + p_info_arr[current].call_count = d.value.call_count; + p_info_arr[current].self_time = d.value.self_time; + p_info_arr[current].total_time = d.value.total_time; + p_info_arr[current].signature = d.value.signature; current++; } @@ -1181,16 +1181,16 @@ int NativeScriptLanguage::profiling_get_frame_data(ProfilingInfo *p_info_arr, in int current = 0; - for (Map<StringName, ProfileData>::Element *d = profile_data.front(); d; d = d->next()) { + for (const KeyValue<StringName, ProfileData> &d : profile_data) { if (current >= p_info_max) { break; } - if (d->get().last_frame_call_count) { - p_info_arr[current].call_count = d->get().last_frame_call_count; - p_info_arr[current].self_time = d->get().last_frame_self_time; - p_info_arr[current].total_time = d->get().last_frame_total_time; - p_info_arr[current].signature = d->get().signature; + if (d.value.last_frame_call_count) { + p_info_arr[current].call_count = d.value.last_frame_call_count; + p_info_arr[current].self_time = d.value.last_frame_self_time; + p_info_arr[current].total_time = d.value.last_frame_total_time; + p_info_arr[current].signature = d.value.signature; current++; } } @@ -1503,9 +1503,9 @@ void NativeScriptLanguage::unregister_script(NativeScript *script) { if (L) { Map<StringName, NativeScriptDesc> classes = L->get(); - for (Map<StringName, NativeScriptDesc>::Element *C = classes.front(); C; C = C->next()) { + for (KeyValue<StringName, NativeScriptDesc> &C : classes) { // free property stuff first - for (OrderedHashMap<StringName, NativeScriptDesc::Property>::Element P = C->get().properties.front(); P; P = P.next()) { + for (OrderedHashMap<StringName, NativeScriptDesc::Property>::Element P = C.value.properties.front(); P; P = P.next()) { if (P.get().getter.free_func) { P.get().getter.free_func(P.get().getter.method_data); } @@ -1516,19 +1516,19 @@ void NativeScriptLanguage::unregister_script(NativeScript *script) { } // free method stuff - for (Map<StringName, NativeScriptDesc::Method>::Element *M = C->get().methods.front(); M; M = M->next()) { - if (M->get().method.free_func) { - M->get().method.free_func(M->get().method.method_data); + for (const KeyValue<StringName, NativeScriptDesc::Method> &M : C.value.methods) { + if (M.value.method.free_func) { + M.value.method.free_func(M.value.method.method_data); } } // free constructor/destructor - if (C->get().create_func.free_func) { - C->get().create_func.free_func(C->get().create_func.method_data); + if (C.value.create_func.free_func) { + C.value.create_func.free_func(C.value.create_func.method_data); } - if (C->get().destroy_func.free_func) { - C->get().destroy_func.free_func(C->get().destroy_func.method_data); + if (C.value.destroy_func.free_func) { + C.value.destroy_func.free_func(C.value.destroy_func.method_data); } } @@ -1548,14 +1548,14 @@ void NativeScriptLanguage::unregister_script(NativeScript *script) { void NativeScriptLanguage::call_libraries_cb(const StringName &name) { // library_gdnatives is modified only from the main thread, so it's safe not to use mutex here - for (Map<String, Ref<GDNative>>::Element *L = library_gdnatives.front(); L; L = L->next()) { - if (L->get().is_null()) { + for (KeyValue<String, Ref<GDNative>> &L : library_gdnatives) { + if (L.value.is_null()) { continue; } - if (L->get()->is_initialized()) { + if (L.value->is_initialized()) { void *proc_ptr; - Error err = L->get()->get_symbol(L->get()->get_library()->get_symbol_prefix() + name, proc_ptr); + Error err = L.value->get_symbol(L.value->get_library()->get_symbol_prefix() + name, proc_ptr); if (!err) { ((void (*)())proc_ptr)(); @@ -1584,13 +1584,13 @@ void NativeScriptLanguage::frame() { { MutexLock lock(mutex); - for (Map<StringName, ProfileData>::Element *d = profile_data.front(); d; d = d->next()) { - d->get().last_frame_call_count = d->get().frame_call_count; - d->get().last_frame_self_time = d->get().frame_self_time; - d->get().last_frame_total_time = d->get().frame_total_time; - d->get().frame_call_count = 0; - d->get().frame_self_time = 0; - d->get().frame_total_time = 0; + for (KeyValue<StringName, ProfileData> &d : profile_data) { + d.value.last_frame_call_count = d.value.frame_call_count; + d.value.last_frame_self_time = d.value.frame_self_time; + d.value.last_frame_total_time = d.value.frame_total_time; + d.value.frame_call_count = 0; + d.value.frame_self_time = 0; + d.value.frame_total_time = 0; } } #endif @@ -1651,8 +1651,8 @@ void NativeReloadNode::_notification(int p_what) { MutexLock lock(NSL->mutex); NSL->_unload_stuff(true); - for (Map<String, Ref<GDNative>>::Element *L = NSL->library_gdnatives.front(); L; L = L->next()) { - Ref<GDNative> gdn = L->get(); + for (KeyValue<String, Ref<GDNative>> &L : NSL->library_gdnatives) { + Ref<GDNative> gdn = L.value; if (gdn.is_null()) { continue; @@ -1685,8 +1685,8 @@ void NativeReloadNode::_notification(int p_what) { MutexLock lock(NSL->mutex); Set<StringName> libs_to_remove; - for (Map<String, Ref<GDNative>>::Element *L = NSL->library_gdnatives.front(); L; L = L->next()) { - Ref<GDNative> gdn = L->get(); + for (KeyValue<String, Ref<GDNative>> &L : NSL->library_gdnatives) { + Ref<GDNative> gdn = L.value; if (gdn.is_null()) { continue; @@ -1703,24 +1703,24 @@ void NativeReloadNode::_notification(int p_what) { } if (!gdn->initialize()) { - libs_to_remove.insert(L->key()); + libs_to_remove.insert(L.key); continue; } - NSL->library_classes.insert(L->key(), Map<StringName, NativeScriptDesc>()); + NSL->library_classes.insert(L.key, Map<StringName, NativeScriptDesc>()); // here the library registers all the classes and stuff. void *proc_ptr; Error err = gdn->get_symbol(gdn->get_library()->get_symbol_prefix() + "nativescript_init", proc_ptr); if (err != OK) { - ERR_PRINT(String("No godot_nativescript_init in \"" + L->key() + "\" found").utf8().get_data()); + ERR_PRINT(String("No godot_nativescript_init in \"" + L.key + "\" found").utf8().get_data()); } else { - ((void (*)(void *))proc_ptr)((void *)&L->key()); + ((void (*)(void *))proc_ptr)((void *)&L.key); } - for (Map<String, Set<NativeScript *>>::Element *U = NSL->library_script_users.front(); U; U = U->next()) { - for (Set<NativeScript *>::Element *S = U->get().front(); S; S = S->next()) { + for (KeyValue<String, Set<NativeScript *>> &U : NSL->library_script_users) { + for (Set<NativeScript *>::Element *S = U.value.front(); S; S = S->next()) { NativeScript *script = S->get(); if (script->placeholders.size() == 0) { diff --git a/modules/gdnative/text/SCsub b/modules/gdnative/text/SCsub deleted file mode 100644 index 0b2db3b504..0000000000 --- a/modules/gdnative/text/SCsub +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env python - -Import("env") -Import("env_gdnative") - -env_gdnative.add_source_files(env.modules_sources, "*.cpp") diff --git a/modules/gdnative/text/config.py b/modules/gdnative/text/config.py deleted file mode 100644 index d22f9454ed..0000000000 --- a/modules/gdnative/text/config.py +++ /dev/null @@ -1,6 +0,0 @@ -def can_build(env, platform): - return True - - -def configure(env): - pass diff --git a/modules/gdnative/text/register_types.cpp b/modules/gdnative/text/register_types.cpp deleted file mode 100644 index 67385d2fbf..0000000000 --- a/modules/gdnative/text/register_types.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/*************************************************************************/ -/* register_types.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "register_types.h" -#include "text_server_gdnative.h" - -void register_text_server_gdn_types() {} - -void unregister_text_server_gdn_types() {} diff --git a/modules/gdnative/text/register_types.h b/modules/gdnative/text/register_types.h deleted file mode 100644 index cd4f2a3089..0000000000 --- a/modules/gdnative/text/register_types.h +++ /dev/null @@ -1,37 +0,0 @@ -/*************************************************************************/ -/* register_types.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef TEXT_REGISTER_TYPES_H -#define TEXT_REGISTER_TYPES_H - -void register_text_server_gdn_types(); -void unregister_text_server_gdn_types(); - -#endif // TEXT_REGISTER_TYPES_H diff --git a/modules/gdnative/text/text_server_gdnative.cpp b/modules/gdnative/text/text_server_gdnative.cpp deleted file mode 100644 index 39db8ae636..0000000000 --- a/modules/gdnative/text/text_server_gdnative.cpp +++ /dev/null @@ -1,1086 +0,0 @@ -/*************************************************************************/ -/* text_server_gdnative.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "text_server_gdnative.h" - -bool TextServerGDNative::has_feature(Feature p_feature) { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->has_feature(data, (godot_int)p_feature); -} - -String TextServerGDNative::get_name() const { - ERR_FAIL_COND_V(interface == nullptr, String()); - godot_string result = interface->get_name(data); - String name = *(String *)&result; - godot_string_destroy(&result); - return name; -} - -void TextServerGDNative::free(RID p_rid) { - ERR_FAIL_COND(interface == nullptr); - interface->free(data, (godot_rid *)&p_rid); -} - -bool TextServerGDNative::has(RID p_rid) { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->has(data, (godot_rid *)&p_rid); -} - -bool TextServerGDNative::load_support_data(const String &p_filename) { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->load_support_data(data, (godot_string *)&p_filename); -} - -#ifdef TOOLS_ENABLED - -String TextServerGDNative::get_support_data_filename() { - ERR_FAIL_COND_V(interface == nullptr, String()); - godot_string result = interface->get_support_data_filename(data); - String name = *(String *)&result; - godot_string_destroy(&result); - return name; -} - -String TextServerGDNative::get_support_data_info() { - ERR_FAIL_COND_V(interface == nullptr, String()); - godot_string result = interface->get_support_data_info(data); - String info = *(String *)&result; - godot_string_destroy(&result); - return info; -} - -bool TextServerGDNative::save_support_data(const String &p_filename) { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->save_support_data(data, (godot_string *)&p_filename); -} - -#endif - -bool TextServerGDNative::is_locale_right_to_left(const String &p_locale) { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->is_locale_right_to_left(data, (godot_string *)&p_locale); -} - -int32_t TextServerGDNative::name_to_tag(const String &p_name) const { - ERR_FAIL_COND_V(interface == nullptr, 0); - return interface->name_to_tag(data, (godot_string *)&p_name); -} - -String TextServerGDNative::tag_to_name(int32_t p_tag) const { - ERR_FAIL_COND_V(interface == nullptr, String()); - godot_string result = interface->tag_to_name(data, p_tag); - String name = *(String *)&result; - godot_string_destroy(&result); - return name; -} - -/*************************************************************************/ -/* Font */ -/*************************************************************************/ - -RID TextServerGDNative::create_font() { - ERR_FAIL_COND_V(interface == nullptr, RID()); - godot_rid result = interface->create_font(data); - RID rid = *(RID *)&result; - return rid; -} - -void TextServerGDNative::font_set_data(RID p_font_rid, const PackedByteArray &p_data) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_data(data, (godot_rid *)&p_font_rid, (const godot_packed_byte_array *)&p_data); -} - -void TextServerGDNative::font_set_data_ptr(RID p_font_rid, const uint8_t *p_data_ptr, size_t p_data_size) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_data_ptr(data, (godot_rid *)&p_font_rid, p_data_ptr, p_data_size); -} - -void TextServerGDNative::font_set_antialiased(RID p_font_rid, bool p_antialiased) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_antialiased(data, (godot_rid *)&p_font_rid, p_antialiased); -} - -bool TextServerGDNative::font_is_antialiased(RID p_font_rid) const { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->font_is_antialiased(data, (godot_rid *)&p_font_rid); -} - -void TextServerGDNative::font_set_multichannel_signed_distance_field(RID p_font_rid, bool p_msdf) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_multichannel_signed_distance_field(data, (godot_rid *)&p_font_rid, p_msdf); -} - -bool TextServerGDNative::font_is_multichannel_signed_distance_field(RID p_font_rid) const { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->font_is_multichannel_signed_distance_field(data, (godot_rid *)&p_font_rid); -} - -void TextServerGDNative::font_set_msdf_pixel_range(RID p_font_rid, int p_msdf_pixel_range) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_msdf_pixel_range(data, (godot_rid *)&p_font_rid, p_msdf_pixel_range); -} - -int TextServerGDNative::font_get_msdf_pixel_range(RID p_font_rid) const { - ERR_FAIL_COND_V(interface == nullptr, 0); - return interface->font_get_msdf_pixel_range(data, (godot_rid *)&p_font_rid); -} - -void TextServerGDNative::font_set_msdf_size(RID p_font_rid, int p_msdf_size) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_msdf_size(data, (godot_rid *)&p_font_rid, p_msdf_size); -} - -int TextServerGDNative::font_get_msdf_size(RID p_font_rid) const { - ERR_FAIL_COND_V(interface == nullptr, 0); - return interface->font_get_msdf_size(data, (godot_rid *)&p_font_rid); -} - -void TextServerGDNative::font_set_fixed_size(RID p_font_rid, int p_fixed_size) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_fixed_size(data, (godot_rid *)&p_font_rid, p_fixed_size); -} - -int TextServerGDNative::font_get_fixed_size(RID p_font_rid) const { - ERR_FAIL_COND_V(interface == nullptr, 0); - return interface->font_get_fixed_size(data, (godot_rid *)&p_font_rid); -} - -void TextServerGDNative::font_set_force_autohinter(RID p_font_rid, bool p_force_autohinter) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_force_autohinter(data, (godot_rid *)&p_font_rid, p_force_autohinter); -} - -bool TextServerGDNative::font_is_force_autohinter(RID p_font_rid) const { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->font_is_force_autohinter(data, (godot_rid *)&p_font_rid); -} - -void TextServerGDNative::font_set_hinting(RID p_font_rid, TextServer::Hinting p_hinting) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_hinting(data, (godot_rid *)&p_font_rid, (godot_int)p_hinting); -} - -TextServer::Hinting TextServerGDNative::font_get_hinting(RID p_font_rid) const { - ERR_FAIL_COND_V(interface == nullptr, TextServer::HINTING_NONE); - return (TextServer::Hinting)interface->font_get_hinting(data, (godot_rid *)&p_font_rid); -} - -void TextServerGDNative::font_set_variation_coordinates(RID p_font_rid, const Dictionary &p_variation_coordinates) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_variation_coordinates(data, (godot_rid *)&p_font_rid, (const godot_dictionary *)&p_variation_coordinates); -} - -Dictionary TextServerGDNative::font_get_variation_coordinates(RID p_font_rid) const { - ERR_FAIL_COND_V(interface == nullptr, Dictionary()); - godot_dictionary result = interface->font_get_variation_coordinates(data, (godot_rid *)&p_font_rid); - Dictionary dict = *(Dictionary *)&result; - godot_dictionary_destroy(&result); - return dict; -} - -void TextServerGDNative::font_set_oversampling(RID p_font_rid, real_t p_oversampling) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_oversampling(data, (godot_rid *)&p_font_rid, p_oversampling); -} - -real_t TextServerGDNative::font_get_oversampling(RID p_font_rid) const { - ERR_FAIL_COND_V(interface == nullptr, 0.0f); - return interface->font_get_oversampling(data, (godot_rid *)&p_font_rid); -} - -Array TextServerGDNative::font_get_size_cache_list(RID p_font_rid) const { - ERR_FAIL_COND_V(interface == nullptr, Array()); - godot_array result = interface->font_get_size_cache_list(data, (godot_rid *)&p_font_rid); - Array list = *(Array *)&result; - godot_array_destroy(&result); - return list; -} - -void TextServerGDNative::font_clear_size_cache(RID p_font_rid) { - ERR_FAIL_COND(interface == nullptr); - interface->font_clear_size_cache(data, (godot_rid *)&p_font_rid); -} - -void TextServerGDNative::font_remove_size_cache(RID p_font_rid, const Vector2i &p_size) { - ERR_FAIL_COND(interface == nullptr); - interface->font_remove_size_cache(data, (godot_rid *)&p_font_rid, (const godot_vector2i *)&p_size); -} - -void TextServerGDNative::font_set_ascent(RID p_font_rid, int p_size, real_t p_ascent) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_ascent(data, (godot_rid *)&p_font_rid, p_size, p_ascent); -} - -real_t TextServerGDNative::font_get_ascent(RID p_font_rid, int p_size) const { - ERR_FAIL_COND_V(interface == nullptr, 0.0f); - return interface->font_get_ascent(data, (godot_rid *)&p_font_rid, p_size); -} - -void TextServerGDNative::font_set_descent(RID p_font_rid, int p_size, real_t p_descent) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_descent(data, (godot_rid *)&p_font_rid, p_size, p_descent); -} - -real_t TextServerGDNative::font_get_descent(RID p_font_rid, int p_size) const { - ERR_FAIL_COND_V(interface == nullptr, 0.0f); - return interface->font_get_descent(data, (godot_rid *)&p_font_rid, p_size); -} - -void TextServerGDNative::font_set_underline_position(RID p_font_rid, int p_size, real_t p_underline_position) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_underline_position(data, (godot_rid *)&p_font_rid, p_size, p_underline_position); -} - -real_t TextServerGDNative::font_get_underline_position(RID p_font_rid, int p_size) const { - ERR_FAIL_COND_V(interface == nullptr, 0.0f); - return interface->font_get_underline_position(data, (godot_rid *)&p_font_rid, p_size); -} - -void TextServerGDNative::font_set_underline_thickness(RID p_font_rid, int p_size, real_t p_underline_thickness) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_underline_thickness(data, (godot_rid *)&p_font_rid, p_size, p_underline_thickness); -} - -real_t TextServerGDNative::font_get_underline_thickness(RID p_font_rid, int p_size) const { - ERR_FAIL_COND_V(interface == nullptr, 0.0f); - return interface->font_get_underline_thickness(data, (godot_rid *)&p_font_rid, p_size); -} - -void TextServerGDNative::font_set_scale(RID p_font_rid, int p_size, real_t p_scale) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_scale(data, (godot_rid *)&p_font_rid, p_size, p_scale); -} - -real_t TextServerGDNative::font_get_scale(RID p_font_rid, int p_size) const { - ERR_FAIL_COND_V(interface == nullptr, 0.0f); - return interface->font_get_scale(data, (godot_rid *)&p_font_rid, p_size); -} - -void TextServerGDNative::font_set_spacing(RID p_font_rid, int p_size, TextServer::SpacingType p_spacing, int p_value) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_spacing(data, (godot_rid *)&p_font_rid, p_size, (godot_int)p_spacing, p_value); -} - -int TextServerGDNative::font_get_spacing(RID p_font_rid, int p_size, TextServer::SpacingType p_spacing) const { - ERR_FAIL_COND_V(interface == nullptr, 0); - return interface->font_get_spacing(data, (godot_rid *)&p_font_rid, p_size, (godot_int)p_spacing); -} - -int TextServerGDNative::font_get_texture_count(RID p_font_rid, const Vector2i &p_size) const { - ERR_FAIL_COND_V(interface == nullptr, -1); - return interface->font_get_texture_count(data, (godot_rid *)&p_font_rid, (const godot_vector2i *)&p_size); -} - -void TextServerGDNative::font_clear_textures(RID p_font_rid, const Vector2i &p_size) { - ERR_FAIL_COND(interface == nullptr); - interface->font_clear_textures(data, (godot_rid *)&p_font_rid, (const godot_vector2i *)&p_size); -} - -void TextServerGDNative::font_remove_texture(RID p_font_rid, const Vector2i &p_size, int p_texture_index) { - ERR_FAIL_COND(interface == nullptr); - interface->font_remove_texture(data, (godot_rid *)&p_font_rid, (const godot_vector2i *)&p_size, p_texture_index); -} - -void TextServerGDNative::font_set_texture_image(RID p_font_rid, const Vector2i &p_size, int p_texture_index, const Ref<Image> &p_image) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_texture_image(data, (godot_rid *)&p_font_rid, (const godot_vector2i *)&p_size, p_texture_index, (const godot_object *)p_image.ptr()); -} - -Ref<Image> TextServerGDNative::font_get_texture_image(RID p_font_rid, const Vector2i &p_size, int p_texture_index) const { - ERR_FAIL_COND_V(interface == nullptr, Ref<Image>()); - godot_object *result = interface->font_get_texture_image(data, (godot_rid *)&p_font_rid, (const godot_vector2i *)&p_size, p_texture_index); - return Ref<Image>((Image *)result); -} - -void TextServerGDNative::font_set_texture_offsets(RID p_font_rid, const Vector2i &p_size, int p_texture_index, const PackedInt32Array &p_offset) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_texture_offsets(data, (godot_rid *)&p_font_rid, (const godot_vector2i *)&p_size, p_texture_index, (const godot_packed_int32_array *)&p_offset); -} - -PackedInt32Array TextServerGDNative::font_get_texture_offsets(RID p_font_rid, const Vector2i &p_size, int p_texture_index) const { - ERR_FAIL_COND_V(interface == nullptr, PackedInt32Array()); - godot_packed_int32_array result = interface->font_get_texture_offsets(data, (godot_rid *)&p_font_rid, (const godot_vector2i *)&p_size, p_texture_index); - PackedInt32Array offset = *(PackedInt32Array *)&result; - godot_packed_int32_array_destroy(&result); - return offset; -} - -Array TextServerGDNative::font_get_glyph_list(RID p_font_rid, const Vector2i &p_size) const { - ERR_FAIL_COND_V(interface == nullptr, Array()); - godot_array result = interface->font_get_glyph_list(data, (godot_rid *)&p_font_rid, (const godot_vector2i *)&p_size); - Array list = *(Array *)&result; - godot_array_destroy(&result); - return list; -} - -void TextServerGDNative::font_clear_glyphs(RID p_font_rid, const Vector2i &p_size) { - ERR_FAIL_COND(interface == nullptr); - interface->font_clear_glyphs(data, (godot_rid *)&p_font_rid, (const godot_vector2i *)&p_size); -} - -void TextServerGDNative::font_remove_glyph(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph) { - ERR_FAIL_COND(interface == nullptr); - interface->font_remove_glyph(data, (godot_rid *)&p_font_rid, (const godot_vector2i *)&p_size, p_glyph); -} - -Vector2 TextServerGDNative::font_get_glyph_advance(RID p_font_rid, int p_size, int32_t p_glyph) const { - ERR_FAIL_COND_V(interface == nullptr, Vector2()); - godot_vector2 result = interface->font_get_glyph_advance(data, (godot_rid *)&p_font_rid, p_size, p_glyph); - Vector2 adv = *(Vector2 *)&result; - return adv; -} - -void TextServerGDNative::font_set_glyph_advance(RID p_font_rid, int p_size, int32_t p_glyph, const Vector2 &p_advance) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_glyph_advance(data, (godot_rid *)&p_font_rid, p_size, p_glyph, (const godot_vector2 *)&p_advance); -} - -Vector2 TextServerGDNative::font_get_glyph_offset(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph) const { - ERR_FAIL_COND_V(interface == nullptr, Vector2()); - godot_vector2 result = interface->font_get_glyph_offset(data, (godot_rid *)&p_font_rid, (const godot_vector2i *)&p_size, p_glyph); - Vector2 off = *(Vector2 *)&result; - return off; -} - -void TextServerGDNative::font_set_glyph_offset(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph, const Vector2 &p_offset) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_glyph_offset(data, (godot_rid *)&p_font_rid, (const godot_vector2i *)&p_size, p_glyph, (const godot_vector2 *)&p_offset); -} - -Vector2 TextServerGDNative::font_get_glyph_size(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph) const { - ERR_FAIL_COND_V(interface == nullptr, Vector2()); - godot_vector2 result = interface->font_get_glyph_size(data, (godot_rid *)&p_font_rid, (const godot_vector2i *)&p_size, p_glyph); - Vector2 sz = *(Vector2 *)&result; - return sz; -} - -void TextServerGDNative::font_set_glyph_size(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph, const Vector2 &p_gl_size) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_glyph_size(data, (godot_rid *)&p_font_rid, (const godot_vector2i *)&p_size, p_glyph, (const godot_vector2 *)&p_gl_size); -} - -Rect2 TextServerGDNative::font_get_glyph_uv_rect(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph) const { - ERR_FAIL_COND_V(interface == nullptr, Rect2()); - godot_rect2 result = interface->font_get_glyph_uv_rect(data, (godot_rid *)&p_font_rid, (const godot_vector2i *)&p_size, p_glyph); - Rect2 uv = *(Rect2 *)&result; - return uv; -} - -void TextServerGDNative::font_set_glyph_uv_rect(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph, const Rect2 &p_uv_rect) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_glyph_uv_rect(data, (godot_rid *)&p_font_rid, (const godot_vector2i *)&p_size, p_glyph, (const godot_rect2 *)&p_uv_rect); -} - -int TextServerGDNative::font_get_glyph_texture_idx(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph) const { - ERR_FAIL_COND_V(interface == nullptr, -1); - return interface->font_get_glyph_texture_idx(data, (godot_rid *)&p_font_rid, (const godot_vector2i *)&p_size, p_glyph); -} - -void TextServerGDNative::font_set_glyph_texture_idx(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph, int p_texture_idx) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_glyph_texture_idx(data, (godot_rid *)&p_font_rid, (const godot_vector2i *)&p_size, p_glyph, p_texture_idx); -} - -bool TextServerGDNative::font_get_glyph_contours(RID p_font_rid, int p_size, int32_t p_index, Vector<Vector3> &r_points, Vector<int32_t> &r_contours, bool &r_orientation) const { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->font_get_glyph_contours(data, (godot_rid *)&p_font_rid, p_size, p_index, (godot_packed_vector3_array *)&r_points, (godot_packed_int32_array *)&r_contours, &r_orientation); -} - -Array TextServerGDNative::font_get_kerning_list(RID p_font_rid, int p_size) const { - ERR_FAIL_COND_V(interface == nullptr, Array()); - godot_array result = interface->font_get_kerning_list(data, (godot_rid *)&p_font_rid, p_size); - Array list = *(Array *)&result; - godot_array_destroy(&result); - return list; -} - -void TextServerGDNative::font_clear_kerning_map(RID p_font_rid, int p_size) { - ERR_FAIL_COND(interface == nullptr); - interface->font_clear_kerning_map(data, (godot_rid *)&p_font_rid, p_size); -} - -void TextServerGDNative::font_remove_kerning(RID p_font_rid, int p_size, const Vector2i &p_glyph_pair) { - ERR_FAIL_COND(interface == nullptr); - interface->font_remove_kerning(data, (godot_rid *)&p_font_rid, p_size, (const godot_vector2i *)&p_glyph_pair); -} - -void TextServerGDNative::font_set_kerning(RID p_font_rid, int p_size, const Vector2i &p_glyph_pair, const Vector2 &p_kerning) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_kerning(data, (godot_rid *)&p_font_rid, p_size, (const godot_vector2i *)&p_glyph_pair, (const godot_vector2 *)&p_kerning); -} - -Vector2 TextServerGDNative::font_get_kerning(RID p_font_rid, int p_size, const Vector2i &p_glyph_pair) const { - ERR_FAIL_COND_V(interface == nullptr, Vector2()); - godot_vector2 result = interface->font_get_kerning(data, (godot_rid *)&p_font_rid, p_size, (const godot_vector2i *)&p_glyph_pair); - Vector2 kern = *(Vector2 *)&result; - return kern; -} - -int32_t TextServerGDNative::font_get_glyph_index(RID p_font_rid, int p_size, char32_t p_char, char32_t p_variation_selector) const { - ERR_FAIL_COND_V(interface == nullptr, 0); - return interface->font_get_glyph_index(data, (godot_rid *)&p_font_rid, p_size, p_char, p_variation_selector); -} - -bool TextServerGDNative::font_has_char(RID p_font_rid, char32_t p_char) const { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->font_has_char(data, (godot_rid *)&p_font_rid, p_char); -} - -String TextServerGDNative::font_get_supported_chars(RID p_font_rid) const { - ERR_FAIL_COND_V(interface == nullptr, String()); - godot_string result = interface->font_get_supported_chars(data, (godot_rid *)&p_font_rid); - String chars = *(String *)&result; - godot_string_destroy(&result); - return chars; -} - -void TextServerGDNative::font_render_range(RID p_font_rid, const Vector2i &p_size, char32_t p_start, char32_t p_end) { - ERR_FAIL_COND(interface == nullptr); - interface->font_render_range(data, (godot_rid *)&p_font_rid, (const godot_vector2i *)&p_size, p_start, p_end); -} - -void TextServerGDNative::font_render_glyph(RID p_font_rid, const Vector2i &p_size, int32_t p_index) { - ERR_FAIL_COND(interface == nullptr); - interface->font_render_glyph(data, (godot_rid *)&p_font_rid, (const godot_vector2i *)&p_size, p_index); -} - -void TextServerGDNative::font_draw_glyph(RID p_font_rid, RID p_canvas, int p_size, const Vector2 &p_pos, int32_t p_index, const Color &p_color) const { - ERR_FAIL_COND(interface == nullptr); - interface->font_draw_glyph(data, (godot_rid *)&p_font_rid, (godot_rid *)&p_canvas, p_size, (const godot_vector2 *)&p_pos, p_index, (const godot_color *)&p_color); -} - -void TextServerGDNative::font_draw_glyph_outline(RID p_font_rid, RID p_canvas, int p_size, int p_outline_size, const Vector2 &p_pos, int32_t p_index, const Color &p_color) const { - ERR_FAIL_COND(interface == nullptr); - interface->font_draw_glyph_outline(data, (godot_rid *)&p_font_rid, (godot_rid *)&p_canvas, p_size, p_outline_size, (const godot_vector2 *)&p_pos, p_index, (const godot_color *)&p_color); -} - -bool TextServerGDNative::font_is_language_supported(RID p_font_rid, const String &p_language) const { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->font_is_language_supported(data, (godot_rid *)&p_font_rid, (const godot_string *)&p_language); -} - -void TextServerGDNative::font_set_language_support_override(RID p_font_rid, const String &p_language, bool p_supported) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_language_support_override(data, (godot_rid *)&p_font_rid, (const godot_string *)&p_language, p_supported); -} - -bool TextServerGDNative::font_get_language_support_override(RID p_font_rid, const String &p_language) { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->font_get_language_support_override(data, (godot_rid *)&p_font_rid, (const godot_string *)&p_language); -} - -void TextServerGDNative::font_remove_language_support_override(RID p_font_rid, const String &p_language) { - ERR_FAIL_COND(interface == nullptr); - interface->font_remove_language_support_override(data, (godot_rid *)&p_font_rid, (const godot_string *)&p_language); -} - -Vector<String> TextServerGDNative::font_get_language_support_overrides(RID p_font_rid) { - ERR_FAIL_COND_V(interface == nullptr, PackedStringArray()); - godot_packed_string_array result = interface->font_get_language_support_overrides(data, (godot_rid *)&p_font_rid); - PackedStringArray list = *(PackedStringArray *)&result; - godot_packed_string_array_destroy(&result); - return list; -} - -bool TextServerGDNative::font_is_script_supported(RID p_font_rid, const String &p_script) const { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->font_is_script_supported(data, (godot_rid *)&p_font_rid, (const godot_string *)&p_script); -} - -void TextServerGDNative::font_set_script_support_override(RID p_font_rid, const String &p_script, bool p_supported) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_script_support_override(data, (godot_rid *)&p_font_rid, (const godot_string *)&p_script, p_supported); -} - -bool TextServerGDNative::font_get_script_support_override(RID p_font_rid, const String &p_script) { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->font_get_script_support_override(data, (godot_rid *)&p_font_rid, (const godot_string *)&p_script); -} - -void TextServerGDNative::font_remove_script_support_override(RID p_font_rid, const String &p_script) { - ERR_FAIL_COND(interface == nullptr); - interface->font_remove_script_support_override(data, (godot_rid *)&p_font_rid, (const godot_string *)&p_script); -} - -Vector<String> TextServerGDNative::font_get_script_support_overrides(RID p_font_rid) { - ERR_FAIL_COND_V(interface == nullptr, PackedStringArray()); - godot_packed_string_array result = interface->font_get_script_support_overrides(data, (godot_rid *)&p_font_rid); - PackedStringArray list = *(PackedStringArray *)&result; - godot_packed_string_array_destroy(&result); - return list; -} - -Dictionary TextServerGDNative::font_supported_feature_list(RID p_font_rid) const { - ERR_FAIL_COND_V(interface == nullptr, Dictionary()); - godot_dictionary result = interface->font_supported_feature_list(data, (godot_rid *)&p_font_rid); - Dictionary dict = *(Dictionary *)&result; - godot_dictionary_destroy(&result); - return dict; -} - -Dictionary TextServerGDNative::font_supported_variation_list(RID p_font_rid) const { - ERR_FAIL_COND_V(interface == nullptr, Dictionary()); - godot_dictionary result = interface->font_supported_variation_list(data, (godot_rid *)&p_font_rid); - Dictionary dict = *(Dictionary *)&result; - godot_dictionary_destroy(&result); - return dict; -} - -real_t TextServerGDNative::font_get_global_oversampling() const { - ERR_FAIL_COND_V(interface == nullptr, 0.0f); - return interface->font_get_global_oversampling(data); -} - -void TextServerGDNative::font_set_global_oversampling(real_t p_oversampling) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_global_oversampling(data, p_oversampling); -} - -/*************************************************************************/ -/* Shaped text buffer interface */ -/*************************************************************************/ - -RID TextServerGDNative::create_shaped_text(TextServer::Direction p_direction, TextServer::Orientation p_orientation) { - ERR_FAIL_COND_V(interface == nullptr, RID()); - godot_rid result = interface->create_shaped_text(data, (godot_int)p_direction, (godot_int)p_orientation); - RID rid = *(RID *)&result; - return rid; -} - -void TextServerGDNative::shaped_text_clear(RID p_shaped) { - ERR_FAIL_COND(interface == nullptr); - interface->shaped_text_clear(data, (godot_rid *)&p_shaped); -} - -void TextServerGDNative::shaped_text_set_direction(RID p_shaped, TextServer::Direction p_direction) { - ERR_FAIL_COND(interface == nullptr); - interface->shaped_text_set_direction(data, (godot_rid *)&p_shaped, (godot_int)p_direction); -} - -TextServer::Direction TextServerGDNative::shaped_text_get_direction(RID p_shaped) const { - ERR_FAIL_COND_V(interface == nullptr, TextServer::DIRECTION_LTR); - return (TextServer::Direction)interface->shaped_text_get_direction(data, (godot_rid *)&p_shaped); -} - -void TextServerGDNative::shaped_text_set_orientation(RID p_shaped, TextServer::Orientation p_orientation) { - ERR_FAIL_COND(interface == nullptr); - interface->shaped_text_set_orientation(data, (godot_rid *)&p_shaped, (godot_int)p_orientation); -} - -TextServer::Orientation TextServerGDNative::shaped_text_get_orientation(RID p_shaped) const { - ERR_FAIL_COND_V(interface == nullptr, TextServer::ORIENTATION_HORIZONTAL); - return (TextServer::Orientation)interface->shaped_text_get_orientation(data, (godot_rid *)&p_shaped); -} - -void TextServerGDNative::shaped_text_set_bidi_override(RID p_shaped, const Vector<Vector2i> &p_override) { - ERR_FAIL_COND(interface == nullptr); - interface->shaped_text_set_bidi_override(data, (godot_rid *)&p_shaped, (const godot_packed_vector2i_array *)&p_override); -} - -void TextServerGDNative::shaped_text_set_preserve_invalid(RID p_shaped, bool p_enabled) { - ERR_FAIL_COND(interface == nullptr); - interface->shaped_text_set_preserve_invalid(data, (godot_rid *)&p_shaped, p_enabled); -} - -bool TextServerGDNative::shaped_text_get_preserve_invalid(RID p_shaped) const { - ERR_FAIL_COND_V(interface == nullptr, false); - return (TextServer::Orientation)interface->shaped_text_get_preserve_invalid(data, (godot_rid *)&p_shaped); -} - -void TextServerGDNative::shaped_text_set_preserve_control(RID p_shaped, bool p_enabled) { - ERR_FAIL_COND(interface == nullptr); - interface->shaped_text_set_preserve_control(data, (godot_rid *)&p_shaped, p_enabled); -} - -bool TextServerGDNative::shaped_text_get_preserve_control(RID p_shaped) const { - ERR_FAIL_COND_V(interface == nullptr, false); - return (TextServer::Orientation)interface->shaped_text_get_preserve_control(data, (godot_rid *)&p_shaped); -} - -bool TextServerGDNative::shaped_text_add_string(RID p_shaped, const String &p_text, const Vector<RID> &p_fonts, int p_size, const Dictionary &p_opentype_features, const String &p_language) { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->shaped_text_add_string(data, (godot_rid *)&p_shaped, (const godot_string *)&p_text, (const godot_rid **)p_fonts.ptr(), p_size, (const godot_dictionary *)&p_opentype_features, (const godot_string *)&p_language); -} - -bool TextServerGDNative::shaped_text_add_object(RID p_shaped, Variant p_key, const Size2 &p_size, InlineAlign p_inline_align, int p_length) { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->shaped_text_add_object(data, (godot_rid *)&p_shaped, (const godot_variant *)&p_key, (const godot_vector2 *)&p_size, (godot_int)p_inline_align, p_length); -} - -bool TextServerGDNative::shaped_text_resize_object(RID p_shaped, Variant p_key, const Size2 &p_size, InlineAlign p_inline_align) { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->shaped_text_resize_object(data, (godot_rid *)&p_shaped, (const godot_variant *)&p_key, (const godot_vector2 *)&p_size, (godot_int)p_inline_align); -} - -RID TextServerGDNative::shaped_text_substr(RID p_shaped, int p_start, int p_length) const { - ERR_FAIL_COND_V(interface == nullptr, RID()); - godot_rid result = interface->shaped_text_substr(data, (godot_rid *)&p_shaped, (godot_int)p_start, (godot_int)p_length); - RID rid = *(RID *)&result; - return rid; -} - -RID TextServerGDNative::shaped_text_get_parent(RID p_shaped) const { - ERR_FAIL_COND_V(interface == nullptr, RID()); - godot_rid result = interface->shaped_text_get_parent(data, (godot_rid *)&p_shaped); - RID rid = *(RID *)&result; - return rid; -} - -real_t TextServerGDNative::shaped_text_fit_to_width(RID p_shaped, real_t p_width, uint8_t p_jst_flags) { - ERR_FAIL_COND_V(interface == nullptr, 0.f); - return interface->shaped_text_fit_to_width(data, (godot_rid *)&p_shaped, p_width, p_jst_flags); -} - -real_t TextServerGDNative::shaped_text_tab_align(RID p_shaped, const Vector<real_t> &p_tab_stops) { - ERR_FAIL_COND_V(interface == nullptr, 0.f); - return interface->shaped_text_tab_align(data, (godot_rid *)&p_shaped, (godot_packed_float32_array *)&p_tab_stops); -} - -bool TextServerGDNative::shaped_text_shape(RID p_shaped) { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->shaped_text_shape(data, (godot_rid *)&p_shaped); -} - -bool TextServerGDNative::shaped_text_update_breaks(RID p_shaped) { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->shaped_text_update_breaks(data, (godot_rid *)&p_shaped); -} - -bool TextServerGDNative::shaped_text_update_justification_ops(RID p_shaped) { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->shaped_text_update_justification_ops(data, (godot_rid *)&p_shaped); -} - -void TextServerGDNative::shaped_text_overrun_trim_to_width(RID p_shaped_line, real_t p_width, uint8_t p_trim_flags) { - ERR_FAIL_COND(interface == nullptr); - interface->shaped_text_overrun_trim_to_width(data, (godot_rid *)&p_shaped_line, p_width, p_trim_flags); -}; - -bool TextServerGDNative::shaped_text_is_ready(RID p_shaped) const { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->shaped_text_is_ready(data, (godot_rid *)&p_shaped); -} - -Vector<TextServer::Glyph> TextServerGDNative::shaped_text_get_glyphs(RID p_shaped) const { - ERR_FAIL_COND_V(interface == nullptr, Vector<TextServer::Glyph>()); - godot_packed_glyph_array result = interface->shaped_text_get_glyphs(data, (godot_rid *)&p_shaped); - Vector<TextServer::Glyph> glyphs = *(Vector<TextServer::Glyph> *)&result; - godot_packed_glyph_array_destroy(&result); - return glyphs; -} - -Vector2i TextServerGDNative::shaped_text_get_range(RID p_shaped) const { - ERR_FAIL_COND_V(interface == nullptr, Vector2i()); - godot_vector2i result = interface->shaped_text_get_range(data, (godot_rid *)&p_shaped); - Vector2i range = *(Vector2i *)&result; - return range; -} - -Vector<TextServer::Glyph> TextServerGDNative::shaped_text_sort_logical(RID p_shaped) { - ERR_FAIL_COND_V(interface == nullptr, Vector<TextServer::Glyph>()); - godot_packed_glyph_array result = interface->shaped_text_sort_logical(data, (godot_rid *)&p_shaped); - Vector<TextServer::Glyph> glyphs = *(Vector<TextServer::Glyph> *)&result; - godot_packed_glyph_array_destroy(&result); - return glyphs; -} - -Vector<Vector2i> TextServerGDNative::shaped_text_get_line_breaks_adv(RID p_shaped, const Vector<real_t> &p_width, int p_start, bool p_once, uint8_t p_break_flags) const { - ERR_FAIL_COND_V(interface == nullptr, Vector<Vector2i>()); - if (interface->shaped_text_get_line_breaks_adv != nullptr) { - godot_packed_vector2i_array result = interface->shaped_text_get_line_breaks_adv(data, (godot_rid *)&p_shaped, (godot_packed_float32_array *)&p_width, p_start, p_once, p_break_flags); - Vector<Vector2i> breaks = *(Vector<Vector2i> *)&result; - godot_packed_vector2i_array_destroy(&result); - return breaks; - } else { - return TextServer::shaped_text_get_line_breaks_adv(p_shaped, p_width, p_break_flags); - } -} - -Vector<Vector2i> TextServerGDNative::shaped_text_get_line_breaks(RID p_shaped, real_t p_width, int p_start, uint8_t p_break_flags) const { - ERR_FAIL_COND_V(interface == nullptr, Vector<Vector2i>()); - if (interface->shaped_text_get_line_breaks != nullptr) { - godot_packed_vector2i_array result = interface->shaped_text_get_line_breaks(data, (godot_rid *)&p_shaped, p_width, p_start, p_break_flags); - Vector<Vector2i> breaks = *(Vector<Vector2i> *)&result; - godot_packed_vector2i_array_destroy(&result); - return breaks; - } else { - return TextServer::shaped_text_get_line_breaks(p_shaped, p_width, p_break_flags); - } -} - -Vector<Vector2i> TextServerGDNative::shaped_text_get_word_breaks(RID p_shaped, int p_grapheme_flags) const { - ERR_FAIL_COND_V(interface == nullptr, Vector<Vector2i>()); - if (interface->shaped_text_get_word_breaks != nullptr) { - godot_packed_vector2i_array result = interface->shaped_text_get_word_breaks(data, (godot_rid *)&p_shaped, p_grapheme_flags); - Vector<Vector2i> breaks = *(Vector<Vector2i> *)&result; - godot_packed_vector2i_array_destroy(&result); - return breaks; - } else { - return TextServer::shaped_text_get_word_breaks(p_shaped, p_grapheme_flags); - } -} - -Array TextServerGDNative::shaped_text_get_objects(RID p_shaped) const { - ERR_FAIL_COND_V(interface == nullptr, Array()); - godot_array result = interface->shaped_text_get_objects(data, (godot_rid *)&p_shaped); - Array rect = *(Array *)&result; - return rect; -} - -Rect2 TextServerGDNative::shaped_text_get_object_rect(RID p_shaped, Variant p_key) const { - ERR_FAIL_COND_V(interface == nullptr, Rect2()); - godot_rect2 result = interface->shaped_text_get_object_rect(data, (godot_rid *)&p_shaped, (const godot_variant *)&p_key); - Rect2 rect = *(Rect2 *)&result; - return rect; -} - -Size2 TextServerGDNative::shaped_text_get_size(RID p_shaped) const { - ERR_FAIL_COND_V(interface == nullptr, Size2()); - godot_vector2 result = interface->shaped_text_get_size(data, (godot_rid *)&p_shaped); - Size2 size = *(Size2 *)&result; - return size; -} - -real_t TextServerGDNative::shaped_text_get_ascent(RID p_shaped) const { - ERR_FAIL_COND_V(interface == nullptr, 0.f); - return interface->shaped_text_get_ascent(data, (godot_rid *)&p_shaped); -} - -real_t TextServerGDNative::shaped_text_get_descent(RID p_shaped) const { - ERR_FAIL_COND_V(interface == nullptr, 0.f); - return interface->shaped_text_get_descent(data, (godot_rid *)&p_shaped); -} - -real_t TextServerGDNative::shaped_text_get_width(RID p_shaped) const { - ERR_FAIL_COND_V(interface == nullptr, 0.f); - return interface->shaped_text_get_width(data, (godot_rid *)&p_shaped); -} - -real_t TextServerGDNative::shaped_text_get_underline_position(RID p_shaped) const { - ERR_FAIL_COND_V(interface == nullptr, 0.f); - return interface->shaped_text_get_underline_position(data, (godot_rid *)&p_shaped); -} - -real_t TextServerGDNative::shaped_text_get_underline_thickness(RID p_shaped) const { - ERR_FAIL_COND_V(interface == nullptr, 0.f); - return interface->shaped_text_get_underline_thickness(data, (godot_rid *)&p_shaped); -} - -String TextServerGDNative::format_number(const String &p_string, const String &p_language) const { - ERR_FAIL_COND_V(interface == nullptr, String()); - godot_string result = interface->format_number(data, (const godot_string *)&p_string, (const godot_string *)&p_language); - if (interface->format_number == nullptr) { - return p_string; - } - String ret = *(String *)&result; - godot_string_destroy(&result); - return ret; -} - -String TextServerGDNative::parse_number(const String &p_string, const String &p_language) const { - ERR_FAIL_COND_V(interface == nullptr, String()); - if (interface->parse_number == nullptr) { - return p_string; - } - godot_string result = interface->parse_number(data, (const godot_string *)&p_string, (const godot_string *)&p_language); - String ret = *(String *)&result; - godot_string_destroy(&result); - return ret; -} - -String TextServerGDNative::percent_sign(const String &p_language) const { - ERR_FAIL_COND_V(interface == nullptr, String()); - if (interface->percent_sign == nullptr) { - return "%"; - } - godot_string result = interface->percent_sign(data, (const godot_string *)&p_language); - String ret = *(String *)&result; - godot_string_destroy(&result); - return ret; -} - -TextServer *TextServerGDNative::create_func(Error &r_error, void *p_user_data) { - const godot_text_interface_gdnative *interface = (const godot_text_interface_gdnative *)p_user_data; - r_error = OK; - - TextServerGDNative *server = memnew(TextServerGDNative()); - server->interface = interface; - server->data = interface->constructor((godot_object *)server); - - return server; -} - -TextServerGDNative::TextServerGDNative() { - data = nullptr; - interface = nullptr; -} - -TextServerGDNative::~TextServerGDNative() { - if (interface != nullptr) { - interface->destructor(data); - data = nullptr; - interface = nullptr; - } -} - -/*************************************************************************/ -/* GDNative functions */ -/*************************************************************************/ - -#ifdef __cplusplus -extern "C" { -#endif - -static_assert(sizeof(godot_glyph) == sizeof(TextServer::Glyph), "Glyph size mismatch"); -static_assert(sizeof(godot_packed_glyph_array) == sizeof(Vector<TextServer::Glyph>), "Vector<Glyph> size mismatch"); - -void GDAPI godot_text_register_interface(const godot_text_interface_gdnative *p_interface, const godot_string *p_name, uint32_t p_features) { - ERR_FAIL_COND(p_interface->version.major != 1); - String name = *(String *)p_name; - TextServerManager::register_create_function(name + "(GDNative)", p_features, TextServerGDNative::create_func, (void *)p_interface); -} - -// Glyph - -void GDAPI godot_glyph_new(godot_glyph *r_dest) { - TextServer::Glyph *dest = (TextServer::Glyph *)r_dest; - *dest = TextServer::Glyph(); -} - -godot_vector2i GDAPI godot_glyph_get_range(const godot_glyph *p_self) { - godot_vector2i dest; - Vector2i *d = (Vector2i *)&dest; - const TextServer::Glyph *self = (const TextServer::Glyph *)p_self; - d->x = self->start; - d->y = self->end; - return dest; -} - -void GDAPI godot_glyph_set_range(godot_glyph *p_self, const godot_vector2i *p_range) { - TextServer::Glyph *self = (TextServer::Glyph *)p_self; - const Vector2i *range = (const Vector2i *)p_range; - self->start = range->x; - self->end = range->y; -} - -godot_int GDAPI godot_glyph_get_count(const godot_glyph *p_self) { - const TextServer::Glyph *self = (const TextServer::Glyph *)p_self; - return self->count; -} - -void GDAPI godot_glyph_set_count(godot_glyph *p_self, godot_int p_count) { - TextServer::Glyph *self = (TextServer::Glyph *)p_self; - self->count = p_count; -} - -godot_int GDAPI godot_glyph_get_repeat(const godot_glyph *p_self) { - const TextServer::Glyph *self = (const TextServer::Glyph *)p_self; - return self->repeat; -} - -void GDAPI godot_glyph_set_repeat(godot_glyph *p_self, godot_int p_repeat) { - TextServer::Glyph *self = (TextServer::Glyph *)p_self; - self->repeat = p_repeat; -} - -godot_int GDAPI godot_glyph_get_flags(const godot_glyph *p_self) { - const TextServer::Glyph *self = (const TextServer::Glyph *)p_self; - return self->flags; -} - -void GDAPI godot_glyph_set_flags(godot_glyph *p_self, godot_int p_flags) { - TextServer::Glyph *self = (TextServer::Glyph *)p_self; - self->flags = p_flags; -} - -godot_vector2 GDAPI godot_glyph_get_offset(const godot_glyph *p_self) { - godot_vector2 dest; - Vector2 *d = (Vector2 *)&dest; - const TextServer::Glyph *self = (const TextServer::Glyph *)p_self; - d->x = self->x_off; - d->y = self->y_off; - return dest; -} - -void GDAPI godot_glyph_set_offset(godot_glyph *p_self, const godot_vector2 *p_offset) { - TextServer::Glyph *self = (TextServer::Glyph *)p_self; - const Vector2 *offset = (const Vector2 *)p_offset; - self->x_off = offset->x; - self->y_off = offset->y; -} - -godot_real_t GDAPI godot_glyph_get_advance(const godot_glyph *p_self) { - const TextServer::Glyph *self = (const TextServer::Glyph *)p_self; - return self->advance; -} - -void GDAPI godot_glyph_set_advance(godot_glyph *p_self, godot_real_t p_advance) { - TextServer::Glyph *self = (TextServer::Glyph *)p_self; - self->advance = p_advance; -} - -godot_rid GDAPI godot_glyph_get_font(const godot_glyph *p_self) { - godot_rid dest; - RID *d = (RID *)&dest; - const TextServer::Glyph *self = (const TextServer::Glyph *)p_self; - *d = self->font_rid; - return dest; -} - -void GDAPI godot_glyph_set_font(godot_glyph *p_self, godot_rid *p_font) { - TextServer::Glyph *self = (TextServer::Glyph *)p_self; - const RID *font = (const RID *)p_font; - self->font_rid = *font; -} - -godot_int GDAPI godot_glyph_get_font_size(const godot_glyph *p_self) { - const TextServer::Glyph *self = (const TextServer::Glyph *)p_self; - return self->font_size; -} - -void GDAPI godot_glyph_set_font_size(godot_glyph *p_self, godot_int p_size) { - TextServer::Glyph *self = (TextServer::Glyph *)p_self; - self->font_size = p_size; -} - -godot_int GDAPI godot_glyph_get_index(const godot_glyph *p_self) { - const TextServer::Glyph *self = (const TextServer::Glyph *)p_self; - return self->index; -} - -void GDAPI godot_glyph_set_index(godot_glyph *p_self, godot_int p_index) { - TextServer::Glyph *self = (TextServer::Glyph *)p_self; - self->index = p_index; -} - -// GlyphArray - -void GDAPI godot_packed_glyph_array_new(godot_packed_glyph_array *r_dest) { - Vector<TextServer::Glyph> *dest = (Vector<TextServer::Glyph> *)r_dest; - memnew_placement(dest, Vector<TextServer::Glyph>); -} - -void GDAPI godot_packed_glyph_array_new_copy(godot_packed_glyph_array *r_dest, const godot_packed_glyph_array *p_src) { - Vector<TextServer::Glyph> *dest = (Vector<TextServer::Glyph> *)r_dest; - const Vector<TextServer::Glyph> *src = (const Vector<TextServer::Glyph> *)p_src; - memnew_placement(dest, Vector<TextServer::Glyph>(*src)); -} - -const godot_glyph GDAPI *godot_packed_glyph_array_ptr(const godot_packed_glyph_array *p_self) { - const Vector<TextServer::Glyph> *self = (const Vector<TextServer::Glyph> *)p_self; - return (const godot_glyph *)self->ptr(); -} - -godot_glyph GDAPI *godot_packed_glyph_array_ptrw(godot_packed_glyph_array *p_self) { - Vector<TextServer::Glyph> *self = (Vector<TextServer::Glyph> *)p_self; - return (godot_glyph *)self->ptrw(); -} - -void GDAPI godot_packed_glyph_array_append(godot_packed_glyph_array *p_self, const godot_glyph *p_data) { - Vector<TextServer::Glyph> *self = (Vector<TextServer::Glyph> *)p_self; - TextServer::Glyph &s = *(TextServer::Glyph *)p_data; - self->push_back(s); -} - -void GDAPI godot_packed_glyph_array_append_array(godot_packed_glyph_array *p_self, const godot_packed_glyph_array *p_array) { - Vector<TextServer::Glyph> *self = (Vector<TextServer::Glyph> *)p_self; - Vector<TextServer::Glyph> *array = (Vector<TextServer::Glyph> *)p_array; - self->append_array(*array); -} - -godot_error GDAPI godot_packed_glyph_array_insert(godot_packed_glyph_array *p_self, const godot_int p_idx, const godot_glyph *p_data) { - Vector<TextServer::Glyph> *self = (Vector<TextServer::Glyph> *)p_self; - TextServer::Glyph &s = *(TextServer::Glyph *)p_data; - return (godot_error)self->insert(p_idx, s); -} - -godot_bool GDAPI godot_packed_glyph_array_has(godot_packed_glyph_array *p_self, const godot_glyph *p_value) { - Vector<TextServer::Glyph> *self = (Vector<TextServer::Glyph> *)p_self; - TextServer::Glyph &v = *(TextServer::Glyph *)p_value; - return (godot_bool)self->has(v); -} - -void GDAPI godot_packed_glyph_array_sort(godot_packed_glyph_array *p_self) { - Vector<TextServer::Glyph> *self = (Vector<TextServer::Glyph> *)p_self; - self->sort(); -} - -void GDAPI godot_packed_glyph_array_reverse(godot_packed_glyph_array *p_self) { - Vector<TextServer::Glyph> *self = (Vector<TextServer::Glyph> *)p_self; - self->reverse(); -} - -void GDAPI godot_packed_glyph_array_push_back(godot_packed_glyph_array *p_self, const godot_glyph *p_data) { - Vector<TextServer::Glyph> *self = (Vector<TextServer::Glyph> *)p_self; - TextServer::Glyph &s = *(TextServer::Glyph *)p_data; - self->push_back(s); -} - -void GDAPI godot_packed_glyph_array_remove(godot_packed_glyph_array *p_self, const godot_int p_idx) { - Vector<TextServer::Glyph> *self = (Vector<TextServer::Glyph> *)p_self; - self->remove(p_idx); -} - -void GDAPI godot_packed_glyph_array_resize(godot_packed_glyph_array *p_self, const godot_int p_size) { - Vector<TextServer::Glyph> *self = (Vector<TextServer::Glyph> *)p_self; - self->resize(p_size); -} - -void GDAPI godot_packed_glyph_array_set(godot_packed_glyph_array *p_self, const godot_int p_idx, const godot_glyph *p_data) { - Vector<TextServer::Glyph> *self = (Vector<TextServer::Glyph> *)p_self; - TextServer::Glyph &s = *(TextServer::Glyph *)p_data; - self->set(p_idx, s); -} - -godot_glyph GDAPI godot_packed_glyph_array_get(const godot_packed_glyph_array *p_self, const godot_int p_idx) { - const Vector<TextServer::Glyph> *self = (const Vector<TextServer::Glyph> *)p_self; - godot_glyph v; - TextServer::Glyph *s = (TextServer::Glyph *)&v; - *s = self->get(p_idx); - return v; -} - -godot_int GDAPI godot_packed_glyph_array_size(const godot_packed_glyph_array *p_self) { - const Vector<TextServer::Glyph> *self = (const Vector<TextServer::Glyph> *)p_self; - return self->size(); -} - -godot_bool GDAPI godot_packed_glyph_array_is_empty(const godot_packed_glyph_array *p_self) { - const Vector<TextServer::Glyph> *self = (const Vector<TextServer::Glyph> *)p_self; - return self->is_empty(); -} - -void GDAPI godot_packed_glyph_array_destroy(godot_packed_glyph_array *p_self) { - ((Vector<TextServer::Glyph> *)p_self)->~Vector(); -} - -#ifdef __cplusplus -} -#endif diff --git a/modules/gdnative/text/text_server_gdnative.h b/modules/gdnative/text/text_server_gdnative.h deleted file mode 100644 index f081637e23..0000000000 --- a/modules/gdnative/text/text_server_gdnative.h +++ /dev/null @@ -1,254 +0,0 @@ -/*************************************************************************/ -/* text_server_gdnative.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef TEXT_SERVER_GDNATIVE_H -#define TEXT_SERVER_GDNATIVE_H - -#include "modules/gdnative/gdnative.h" - -#include "servers/text_server.h" - -class TextServerGDNative : public TextServer { - GDCLASS(TextServerGDNative, TextServer); - - const godot_text_interface_gdnative *interface = nullptr; - void *data = nullptr; - -protected: - static void _bind_methods(){}; - -public: - virtual bool has_feature(Feature p_feature) override; - virtual String get_name() const override; - - virtual void free(RID p_rid) override; - virtual bool has(RID p_rid) override; - virtual bool load_support_data(const String &p_filename) override; - -#ifdef TOOLS_ENABLED - virtual String get_support_data_filename() override; - virtual String get_support_data_info() override; - virtual bool save_support_data(const String &p_filename) override; -#endif - - virtual bool is_locale_right_to_left(const String &p_locale) override; - - virtual int32_t name_to_tag(const String &p_name) const override; - virtual String tag_to_name(int32_t p_tag) const override; - - /* Font interface */ - virtual RID create_font() override; - - virtual void font_set_data(RID p_font_rid, const PackedByteArray &p_data) override; - virtual void font_set_data_ptr(RID p_font_rid, const uint8_t *p_data_ptr, size_t p_data_size) override; - - virtual void font_set_antialiased(RID p_font_rid, bool p_antialiased) override; - virtual bool font_is_antialiased(RID p_font_rid) const override; - - virtual void font_set_multichannel_signed_distance_field(RID p_font_rid, bool p_msdf) override; - virtual bool font_is_multichannel_signed_distance_field(RID p_font_rid) const override; - - virtual void font_set_msdf_pixel_range(RID p_font_rid, int p_msdf_pixel_range) override; - virtual int font_get_msdf_pixel_range(RID p_font_rid) const override; - - virtual void font_set_msdf_size(RID p_font_rid, int p_msdf_size) override; - virtual int font_get_msdf_size(RID p_font_rid) const override; - - virtual void font_set_fixed_size(RID p_font_rid, int p_fixed_size) override; - virtual int font_get_fixed_size(RID p_font_rid) const override; - - virtual void font_set_force_autohinter(RID p_font_rid, bool p_force_autohinter) override; - virtual bool font_is_force_autohinter(RID p_font_rid) const override; - - virtual void font_set_hinting(RID p_font_rid, TextServer::Hinting p_hinting) override; - virtual TextServer::Hinting font_get_hinting(RID p_font_rid) const override; - - virtual void font_set_variation_coordinates(RID p_font_rid, const Dictionary &p_variation_coordinates) override; - virtual Dictionary font_get_variation_coordinates(RID p_font_rid) const override; - - virtual void font_set_oversampling(RID p_font_rid, real_t p_oversampling) override; - virtual real_t font_get_oversampling(RID p_font_rid) const override; - - virtual Array font_get_size_cache_list(RID p_font_rid) const override; - virtual void font_clear_size_cache(RID p_font_rid) override; - virtual void font_remove_size_cache(RID p_font_rid, const Vector2i &p_size) override; - - virtual void font_set_ascent(RID p_font_rid, int p_size, real_t p_ascent) override; - virtual real_t font_get_ascent(RID p_font_rid, int p_size) const override; - - virtual void font_set_descent(RID p_font_rid, int p_size, real_t p_descent) override; - virtual real_t font_get_descent(RID p_font_rid, int p_size) const override; - - virtual void font_set_underline_position(RID p_font_rid, int p_size, real_t p_underline_position) override; - virtual real_t font_get_underline_position(RID p_font_rid, int p_size) const override; - - virtual void font_set_underline_thickness(RID p_font_rid, int p_size, real_t p_underline_thickness) override; - virtual real_t font_get_underline_thickness(RID p_font_rid, int p_size) const override; - - virtual void font_set_scale(RID p_font_rid, int p_size, real_t p_scale) override; - virtual real_t font_get_scale(RID p_font_rid, int p_size) const override; - - virtual void font_set_spacing(RID p_font_rid, int p_size, SpacingType p_spacing, int p_value) override; - virtual int font_get_spacing(RID p_font_rid, int p_size, SpacingType p_spacing) const override; - - virtual int font_get_texture_count(RID p_font_rid, const Vector2i &p_size) const override; - virtual void font_clear_textures(RID p_font_rid, const Vector2i &p_size) override; - virtual void font_remove_texture(RID p_font_rid, const Vector2i &p_size, int p_texture_index) override; - - virtual void font_set_texture_image(RID p_font_rid, const Vector2i &p_size, int p_texture_index, const Ref<Image> &p_image) override; - virtual Ref<Image> font_get_texture_image(RID p_font_rid, const Vector2i &p_size, int p_texture_index) const override; - - virtual void font_set_texture_offsets(RID p_font_rid, const Vector2i &p_size, int p_texture_index, const PackedInt32Array &p_offset) override; - virtual PackedInt32Array font_get_texture_offsets(RID p_font_rid, const Vector2i &p_size, int p_texture_index) const override; - - virtual Array font_get_glyph_list(RID p_font_rid, const Vector2i &p_size) const override; - virtual void font_clear_glyphs(RID p_font_rid, const Vector2i &p_size) override; - virtual void font_remove_glyph(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph) override; - - virtual Vector2 font_get_glyph_advance(RID p_font_rid, int p_size, int32_t p_glyph) const override; - virtual void font_set_glyph_advance(RID p_font_rid, int p_size, int32_t p_glyph, const Vector2 &p_advance) override; - - virtual Vector2 font_get_glyph_offset(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph) const override; - virtual void font_set_glyph_offset(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph, const Vector2 &p_offset) override; - - virtual Vector2 font_get_glyph_size(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph) const override; - virtual void font_set_glyph_size(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph, const Vector2 &p_gl_size) override; - - virtual Rect2 font_get_glyph_uv_rect(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph) const override; - virtual void font_set_glyph_uv_rect(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph, const Rect2 &p_uv_rect) override; - - virtual int font_get_glyph_texture_idx(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph) const override; - virtual void font_set_glyph_texture_idx(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph, int p_texture_idx) override; - - virtual bool font_get_glyph_contours(RID p_font, int p_size, int32_t p_index, Vector<Vector3> &r_points, Vector<int32_t> &r_contours, bool &r_orientation) const override; - - virtual Array font_get_kerning_list(RID p_font_rid, int p_size) const override; - virtual void font_clear_kerning_map(RID p_font_rid, int p_size) override; - virtual void font_remove_kerning(RID p_font_rid, int p_size, const Vector2i &p_glyph_pair) override; - - virtual void font_set_kerning(RID p_font_rid, int p_size, const Vector2i &p_glyph_pair, const Vector2 &p_kerning) override; - virtual Vector2 font_get_kerning(RID p_font_rid, int p_size, const Vector2i &p_glyph_pair) const override; - - virtual int32_t font_get_glyph_index(RID p_font_rid, int p_size, char32_t p_char, char32_t p_variation_selector = 0) const override; - - virtual bool font_has_char(RID p_font_rid, char32_t p_char) const override; - virtual String font_get_supported_chars(RID p_font_rid) const override; - - virtual void font_render_range(RID p_font, const Vector2i &p_size, char32_t p_start, char32_t p_end) override; - virtual void font_render_glyph(RID p_font_rid, const Vector2i &p_size, int32_t p_index) override; - - virtual void font_draw_glyph(RID p_font, RID p_canvas, int p_size, const Vector2 &p_pos, int32_t p_index, const Color &p_color = Color(1, 1, 1)) const override; - virtual void font_draw_glyph_outline(RID p_font, RID p_canvas, int p_size, int p_outline_size, const Vector2 &p_pos, int32_t p_index, const Color &p_color = Color(1, 1, 1)) const override; - - virtual bool font_is_language_supported(RID p_font_rid, const String &p_language) const override; - virtual void font_set_language_support_override(RID p_font_rid, const String &p_language, bool p_supported) override; - virtual bool font_get_language_support_override(RID p_font_rid, const String &p_language) override; - virtual void font_remove_language_support_override(RID p_font_rid, const String &p_language) override; - virtual Vector<String> font_get_language_support_overrides(RID p_font_rid) override; - - virtual bool font_is_script_supported(RID p_font_rid, const String &p_script) const override; - virtual void font_set_script_support_override(RID p_font_rid, const String &p_script, bool p_supported) override; - virtual bool font_get_script_support_override(RID p_font_rid, const String &p_script) override; - virtual void font_remove_script_support_override(RID p_font_rid, const String &p_script) override; - virtual Vector<String> font_get_script_support_overrides(RID p_font_rid) override; - - virtual Dictionary font_supported_feature_list(RID p_font_rid) const override; - virtual Dictionary font_supported_variation_list(RID p_font_rid) const override; - - virtual real_t font_get_global_oversampling() const override; - virtual void font_set_global_oversampling(real_t p_oversampling) override; - - /* Shaped text buffer interface */ - - virtual RID create_shaped_text(Direction p_direction = DIRECTION_AUTO, Orientation p_orientation = ORIENTATION_HORIZONTAL) override; - - virtual void shaped_text_clear(RID p_shaped) override; - - virtual void shaped_text_set_direction(RID p_shaped, Direction p_direction = DIRECTION_AUTO) override; - virtual Direction shaped_text_get_direction(RID p_shaped) const override; - - virtual void shaped_text_set_bidi_override(RID p_shaped, const Vector<Vector2i> &p_override) override; - - virtual void shaped_text_set_orientation(RID p_shaped, Orientation p_orientation = ORIENTATION_HORIZONTAL) override; - virtual Orientation shaped_text_get_orientation(RID p_shaped) const override; - - virtual void shaped_text_set_preserve_invalid(RID p_shaped, bool p_enabled) override; - virtual bool shaped_text_get_preserve_invalid(RID p_shaped) const override; - - virtual void shaped_text_set_preserve_control(RID p_shaped, bool p_enabled) override; - virtual bool shaped_text_get_preserve_control(RID p_shaped) const override; - - virtual bool shaped_text_add_string(RID p_shaped, const String &p_text, const Vector<RID> &p_fonts, int p_size, const Dictionary &p_opentype_features = Dictionary(), const String &p_language = "") override; - virtual bool shaped_text_add_object(RID p_shaped, Variant p_key, const Size2 &p_size, InlineAlign p_inline_align = INLINE_ALIGN_CENTER, int p_length = 1) override; - virtual bool shaped_text_resize_object(RID p_shaped, Variant p_key, const Size2 &p_size, InlineAlign p_inline_align = INLINE_ALIGN_CENTER) override; - - virtual RID shaped_text_substr(RID p_shaped, int p_start, int p_length) const override; - virtual RID shaped_text_get_parent(RID p_shaped) const override; - - virtual real_t shaped_text_fit_to_width(RID p_shaped, real_t p_width, uint8_t /*JustificationFlag*/ p_jst_flags = JUSTIFICATION_WORD_BOUND | JUSTIFICATION_KASHIDA) override; - virtual real_t shaped_text_tab_align(RID p_shaped, const Vector<real_t> &p_tab_stops) override; - - virtual bool shaped_text_shape(RID p_shaped) override; - virtual bool shaped_text_update_breaks(RID p_shaped) override; - virtual bool shaped_text_update_justification_ops(RID p_shaped) override; - - virtual void shaped_text_overrun_trim_to_width(RID p_shaped, real_t p_width, uint8_t p_trim_flags) override; - - virtual bool shaped_text_is_ready(RID p_shaped) const override; - - virtual Vector<Glyph> shaped_text_get_glyphs(RID p_shaped) const override; - - virtual Vector2i shaped_text_get_range(RID p_shaped) const override; - - virtual Vector<Glyph> shaped_text_sort_logical(RID p_shaped) override; - virtual Vector<Vector2i> shaped_text_get_line_breaks_adv(RID p_shaped, const Vector<real_t> &p_width, int p_start = 0, bool p_once = true, uint8_t /*TextBreakFlag*/ p_break_flags = BREAK_MANDATORY | BREAK_WORD_BOUND) const override; - virtual Vector<Vector2i> shaped_text_get_line_breaks(RID p_shaped, real_t p_width, int p_start = 0, uint8_t p_break_flags = BREAK_MANDATORY | BREAK_WORD_BOUND) const override; - virtual Vector<Vector2i> shaped_text_get_word_breaks(RID p_shaped, int p_grapheme_flags = GRAPHEME_IS_SPACE | GRAPHEME_IS_PUNCTUATION) const override; - virtual Array shaped_text_get_objects(RID p_shaped) const override; - virtual Rect2 shaped_text_get_object_rect(RID p_shaped, Variant p_key) const override; - - virtual Size2 shaped_text_get_size(RID p_shaped) const override; - virtual real_t shaped_text_get_ascent(RID p_shaped) const override; - virtual real_t shaped_text_get_descent(RID p_shaped) const override; - virtual real_t shaped_text_get_width(RID p_shaped) const override; - virtual real_t shaped_text_get_underline_position(RID p_shaped) const override; - virtual real_t shaped_text_get_underline_thickness(RID p_shaped) const override; - - virtual String format_number(const String &p_string, const String &p_language = "") const override; - virtual String parse_number(const String &p_string, const String &p_language = "") const override; - virtual String percent_sign(const String &p_language = "") const override; - - static TextServer *create_func(Error &r_error, void *p_user_data); - - TextServerGDNative(); - ~TextServerGDNative(); -}; - -#endif // TEXT_SERVER_GDNATIVE_H diff --git a/modules/gdscript/doc_classes/@GDScript.xml b/modules/gdscript/doc_classes/@GDScript.xml index 51b3452a3a..631ee4d895 100644 --- a/modules/gdscript/doc_classes/@GDScript.xml +++ b/modules/gdscript/doc_classes/@GDScript.xml @@ -176,7 +176,8 @@ <method name="range" qualifiers="vararg"> <return type="Array" /> <description> - Returns an array with the given range. Range can be 1 argument N (0 to N-1), two arguments (initial, final-1) or three arguments (initial, final-1, increment). + Returns an array with the given range. Range can be 1 argument [code]N[/code] (0 to [code]N[/code] - 1), two arguments ([code]initial[/code], [code]final - 1[/code]) or three arguments ([code]initial[/code], [code]final - 1[/code], [code]increment[/code]). Returns an empty array if the range isn't valid (e.g. [code]range(2, 5, -1)[/code] or [code]range(5, 5, 1)[/code]). + Returns an array with the given range. [code]range()[/code] can have 1 argument N ([code]0[/code] to [code]N - 1[/code]), two arguments ([code]initial[/code], [code]final - 1[/code]) or three arguments ([code]initial[/code], [code]final - 1[/code], [code]increment[/code]). [code]increment[/code] can be negative. If [code]increment[/code] is negative, [code]final - 1[/code] will become [code]final + 1[/code]. Also, the initial value must be greater than the final value for the loop to run. [codeblock] print(range(4)) print(range(2, 5)) @@ -188,6 +189,20 @@ [2, 3, 4] [0, 2, 4] [/codeblock] + To iterate over an [Array] backwards, use: + [codeblock] + var array = [3, 6, 9] + var i := array.size() - 1 + while i >= 0: + print(array[i]) + i -= 1 + [/codeblock] + Output: + [codeblock] + 9 + 6 + 3 + [/codeblock] </description> </method> <method name="str" qualifiers="vararg"> diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index bc8801b8b9..2bae838543 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -122,8 +122,8 @@ GDScriptInstance *GDScript::_create_instance(const Variant **p_args, int p_argco instance->owner_id = p_owner->get_instance_id(); #ifdef DEBUG_ENABLED //needed for hot reloading - for (Map<StringName, MemberInfo>::Element *E = member_indices.front(); E; E = E->next()) { - instance->member_indices_cache[E->key()] = E->get().index; + for (const KeyValue<StringName, MemberInfo> &E : member_indices) { + instance->member_indices_cache[E.key] = E.value.index; } #endif instance->owner->set_script_instance(instance); @@ -253,10 +253,10 @@ void GDScript::_placeholder_erased(PlaceHolderScriptInstance *p_placeholder) { void GDScript::_get_script_method_list(List<MethodInfo> *r_list, bool p_include_base) const { const GDScript *current = this; while (current) { - for (const Map<StringName, GDScriptFunction *>::Element *E = current->member_functions.front(); E; E = E->next()) { - GDScriptFunction *func = E->get(); + for (const KeyValue<StringName, GDScriptFunction *> &E : current->member_functions) { + GDScriptFunction *func = E.value; MethodInfo mi; - mi.name = E->key(); + mi.name = E.key; for (int i = 0; i < func->get_argument_count(); i++) { PropertyInfo arginfo = func->get_argument_type(i); #ifdef TOOLS_ENABLED @@ -286,11 +286,11 @@ void GDScript::_get_script_property_list(List<PropertyInfo> *r_list, bool p_incl while (sptr) { Vector<_GDScriptMemberSort> msort; - for (Map<StringName, PropertyInfo>::Element *E = sptr->member_info.front(); E; E = E->next()) { + for (const KeyValue<StringName, PropertyInfo> &E : sptr->member_info) { _GDScriptMemberSort ms; - ERR_CONTINUE(!sptr->member_indices.has(E->key())); - ms.index = sptr->member_indices[E->key()].index; - ms.name = E->key(); + ERR_CONTINUE(!sptr->member_indices.has(E.key)); + ms.index = sptr->member_indices[E.key].index; + ms.name = E.key; msort.push_back(ms); } @@ -412,8 +412,8 @@ void GDScript::_update_exports_values(Map<StringName, Variant> &values, List<Pro base_cache->_update_exports_values(values, propnames); } - for (Map<StringName, Variant>::Element *E = member_default_values_cache.front(); E; E = E->next()) { - values[E->key()] = E->get(); + for (const KeyValue<StringName, Variant> &E : member_default_values_cache) { + values[E.key] = E.value; } for (const PropertyInfo &E : members_cache) { @@ -471,9 +471,9 @@ void GDScript::_update_doc() { doc.description = doc_description; doc.tutorials = doc_tutorials; - for (Map<String, DocData::EnumDoc>::Element *E = doc_enums.front(); E; E = E->next()) { - if (E->value().description != "") { - doc.enums[E->key()] = E->value().description; + for (const KeyValue<String, DocData::EnumDoc> &E : doc_enums) { + if (E.value.description != "") { + doc.enums[E.key] = E.value.description; } } @@ -552,29 +552,29 @@ void GDScript::_update_doc() { doc.signals.push_back(signal_doc); } - for (Map<StringName, Variant>::Element *E = constants.front(); E; E = E->next()) { - if (subclasses.has(E->key())) { + for (const KeyValue<StringName, Variant> &E : constants) { + if (subclasses.has(E.key)) { continue; } // Enums. bool is_enum = false; - if (E->value().get_type() == Variant::DICTIONARY) { - if (doc_enums.has(E->key())) { + if (E.value.get_type() == Variant::DICTIONARY) { + if (doc_enums.has(E.key)) { is_enum = true; - for (int i = 0; i < doc_enums[E->key()].values.size(); i++) { - doc_enums[E->key()].values.write[i].enumeration = E->key(); - doc.constants.push_back(doc_enums[E->key()].values[i]); + for (int i = 0; i < doc_enums[E.key].values.size(); i++) { + doc_enums[E.key].values.write[i].enumeration = E.key; + doc.constants.push_back(doc_enums[E.key].values[i]); } } } if (!is_enum && doc_enums.has("@unnamed_enums")) { for (int i = 0; i < doc_enums["@unnamed_enums"].values.size(); i++) { - if (E->key() == doc_enums["@unnamed_enums"].values[i].name) { + if (E.key == doc_enums["@unnamed_enums"].values[i].name) { is_enum = true; DocData::ConstantDoc constant_doc; constant_doc.enumeration = "@unnamed_enums"; - DocData::constant_doc_from_variant(constant_doc, E->key(), E->value(), doc_enums["@unnamed_enums"].values[i].description); + DocData::constant_doc_from_variant(constant_doc, E.key, E.value, doc_enums["@unnamed_enums"].values[i].description); doc.constants.push_back(constant_doc); break; } @@ -583,16 +583,16 @@ void GDScript::_update_doc() { if (!is_enum) { DocData::ConstantDoc constant_doc; String doc_description; - if (doc_constants.has(E->key())) { - doc_description = doc_constants[E->key()]; + if (doc_constants.has(E.key)) { + doc_description = doc_constants[E.key]; } - DocData::constant_doc_from_variant(constant_doc, E->key(), E->value(), doc_description); + DocData::constant_doc_from_variant(constant_doc, E.key, E.value, doc_description); doc.constants.push_back(constant_doc); } } - for (Map<StringName, Ref<GDScript>>::Element *E = subclasses.front(); E; E = E->next()) { - E->get()->_update_doc(); + for (KeyValue<StringName, Ref<GDScript>> &E : subclasses) { + E.value->_update_doc(); } _add_doc(doc); @@ -784,8 +784,8 @@ void GDScript::update_exports() { void GDScript::_set_subclass_path(Ref<GDScript> &p_sc, const String &p_path) { p_sc->path = p_path; - for (Map<StringName, Ref<GDScript>>::Element *E = p_sc->subclasses.front(); E; E = E->next()) { - _set_subclass_path(E->get(), p_path); + for (KeyValue<StringName, Ref<GDScript>> &E : p_sc->subclasses) { + _set_subclass_path(E.value, p_path); } } @@ -886,8 +886,8 @@ Error GDScript::reload(bool p_keep_state) { valid = true; - for (Map<StringName, Ref<GDScript>>::Element *E = subclasses.front(); E; E = E->next()) { - _set_subclass_path(E->get(), path); + for (KeyValue<StringName, Ref<GDScript>> &E : subclasses) { + _set_subclass_path(E.value, path); } _init_rpc_methods_properties(); @@ -901,8 +901,8 @@ ScriptLanguage *GDScript::get_language() const { void GDScript::get_constants(Map<StringName, Variant> *p_constants) { if (p_constants) { - for (Map<StringName, Variant>::Element *E = constants.front(); E; E = E->next()) { - (*p_constants)[E->key()] = E->value(); + for (const KeyValue<StringName, Variant> &E : constants) { + (*p_constants)[E.key] = E.value; } } } @@ -1032,9 +1032,9 @@ const Map<StringName, GDScriptFunction *> &GDScript::debug_get_member_functions( } StringName GDScript::debug_get_member_by_index(int p_idx) const { - for (const Map<StringName, MemberInfo>::Element *E = member_indices.front(); E; E = E->next()) { - if (E->get().index == p_idx) { - return E->key(); + for (const KeyValue<StringName, MemberInfo> &E : member_indices) { + if (E.value.index == p_idx) { + return E.key; } } @@ -1079,12 +1079,12 @@ bool GDScript::has_script_signal(const StringName &p_signal) const { } void GDScript::_get_script_signal_list(List<MethodInfo> *r_list, bool p_include_base) const { - for (const Map<StringName, Vector<StringName>>::Element *E = _signals.front(); E; E = E->next()) { + for (const KeyValue<StringName, Vector<StringName>> &E : _signals) { MethodInfo mi; - mi.name = E->key(); - for (int i = 0; i < E->get().size(); i++) { + mi.name = E.key; + for (int i = 0; i < E.value.size(); i++) { PropertyInfo arg; - arg.name = E->get()[i]; + arg.name = E.value[i]; mi.arguments.push_back(arg); } r_list->push_back(mi); @@ -1142,11 +1142,11 @@ void GDScript::_save_orphaned_subclasses() { }; Vector<ClassRefWithName> weak_subclasses; // collect subclasses ObjectID and name - for (Map<StringName, Ref<GDScript>>::Element *E = subclasses.front(); E; E = E->next()) { - E->get()->_owner = nullptr; //bye, you are no longer owned cause I died + for (KeyValue<StringName, Ref<GDScript>> &E : subclasses) { + E.value->_owner = nullptr; //bye, you are no longer owned cause I died ClassRefWithName subclass; - subclass.id = E->get()->get_instance_id(); - subclass.fully_qualified_name = E->get()->fully_qualified_name; + subclass.id = E.value->get_instance_id(); + subclass.fully_qualified_name = E.value->fully_qualified_name; weak_subclasses.push_back(subclass); } @@ -1178,10 +1178,10 @@ void GDScript::_init_rpc_methods_properties() { Map<StringName, Ref<GDScript>>::Element *sub_E = subclasses.front(); while (cscript) { // RPC Methods - for (Map<StringName, GDScriptFunction *>::Element *E = cscript->member_functions.front(); E; E = E->next()) { - Multiplayer::RPCConfig config = E->get()->get_rpc_config(); + for (KeyValue<StringName, GDScriptFunction *> &E : cscript->member_functions) { + Multiplayer::RPCConfig config = E.value->get_rpc_config(); if (config.rpc_mode != Multiplayer::RPC_MODE_DISABLED) { - config.name = E->get()->get_name(); + config.name = E.value->get_name(); if (rpc_functions.find(config) == -1) { rpc_functions.push_back(config); } @@ -1215,8 +1215,8 @@ GDScript::~GDScript() { } } - for (Map<StringName, GDScriptFunction *>::Element *E = member_functions.front(); E; E = E->next()) { - memdelete(E->get()); + for (const KeyValue<StringName, GDScriptFunction *> &E : member_functions) { + memdelete(E.value); } if (GDScriptCache::singleton) { // Cache may have been already destroyed at engine shutdown. @@ -1442,11 +1442,11 @@ void GDScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const //instance a fake script for editing the values Vector<_GDScriptMemberSort> msort; - for (Map<StringName, PropertyInfo>::Element *F = sptr->member_info.front(); F; F = F->next()) { + for (const KeyValue<StringName, PropertyInfo> &F : sptr->member_info) { _GDScriptMemberSort ms; - ERR_CONTINUE(!sptr->member_indices.has(F->key())); - ms.index = sptr->member_indices[F->key()].index; - ms.name = F->key(); + ERR_CONTINUE(!sptr->member_indices.has(F.key)); + ms.index = sptr->member_indices[F.key].index; + ms.name = F.key; msort.push_back(ms); } @@ -1467,11 +1467,11 @@ void GDScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const void GDScriptInstance::get_method_list(List<MethodInfo> *p_list) const { const GDScript *sptr = script.ptr(); while (sptr) { - for (Map<StringName, GDScriptFunction *>::Element *E = sptr->member_functions.front(); E; E = E->next()) { + for (const KeyValue<StringName, GDScriptFunction *> &E : sptr->member_functions) { MethodInfo mi; - mi.name = E->key(); + mi.name = E.key; mi.flags |= METHOD_FLAG_FROM_SCRIPT; - for (int i = 0; i < E->get()->get_argument_count(); i++) { + for (int i = 0; i < E.value->get_argument_count(); i++) { mi.arguments.push_back(PropertyInfo(Variant::NIL, "arg" + itos(i))); } p_list->push_back(mi); @@ -1569,10 +1569,10 @@ void GDScriptInstance::reload_members() { new_members.resize(script->member_indices.size()); //pass the values to the new indices - for (Map<StringName, GDScript::MemberInfo>::Element *E = script->member_indices.front(); E; E = E->next()) { - if (member_indices_cache.has(E->key())) { - Variant value = members[member_indices_cache[E->key()]]; - new_members.write[E->get().index] = value; + for (KeyValue<StringName, GDScript::MemberInfo> &E : script->member_indices) { + if (member_indices_cache.has(E.key)) { + Variant value = members[member_indices_cache[E.key]]; + new_members.write[E.value.index] = value; } } @@ -1581,8 +1581,8 @@ void GDScriptInstance::reload_members() { //pass the values to the new indices member_indices_cache.clear(); - for (Map<StringName, GDScript::MemberInfo>::Element *E = script->member_indices.front(); E; E = E->next()) { - member_indices_cache[E->key()] = E->get().index; + for (const KeyValue<StringName, GDScript::MemberInfo> &E : script->member_indices) { + member_indices_cache[E.key] = E.value.index; } #endif @@ -1890,21 +1890,21 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_so #endif - for (Map<ObjectID, List<Pair<StringName, Variant>>>::Element *F = script->pending_reload_state.front(); F; F = F->next()) { - map[F->key()] = F->get(); //pending to reload, use this one instead + for (const KeyValue<ObjectID, List<Pair<StringName, Variant>>> &F : script->pending_reload_state) { + map[F.key] = F.value; //pending to reload, use this one instead } } } - for (Map<Ref<GDScript>, Map<ObjectID, List<Pair<StringName, Variant>>>>::Element *E = to_reload.front(); E; E = E->next()) { - Ref<GDScript> scr = E->key(); + for (KeyValue<Ref<GDScript>, Map<ObjectID, List<Pair<StringName, Variant>>>> &E : to_reload) { + Ref<GDScript> scr = E.key; scr->reload(p_soft_reload); //restore state if saved - for (Map<ObjectID, List<Pair<StringName, Variant>>>::Element *F = E->get().front(); F; F = F->next()) { - List<Pair<StringName, Variant>> &saved_state = F->get(); + for (KeyValue<ObjectID, List<Pair<StringName, Variant>>> &F : E.value) { + List<Pair<StringName, Variant>> &saved_state = F.value; - Object *obj = ObjectDB::get_instance(F->key()); + Object *obj = ObjectDB::get_instance(F.key); if (!obj) { continue; } @@ -2210,15 +2210,15 @@ GDScriptLanguage::~GDScriptLanguage() { // is not the same as before). script->reference(); - for (Map<StringName, GDScriptFunction *>::Element *E = script->member_functions.front(); E; E = E->next()) { - GDScriptFunction *func = E->get(); + for (KeyValue<StringName, GDScriptFunction *> &E : script->member_functions) { + GDScriptFunction *func = E.value; for (int i = 0; i < func->argument_types.size(); i++) { func->argument_types.write[i].script_type_ref = Ref<Script>(); } func->return_type.script_type_ref = Ref<Script>(); } - for (Map<StringName, GDScript::MemberInfo>::Element *E = script->member_indices.front(); E; E = E->next()) { - E->get().data_type.script_type_ref = Ref<Script>(); + for (KeyValue<StringName, GDScript::MemberInfo> &E : script->member_indices) { + E.value.data_type.script_type_ref = Ref<Script>(); } s = s->next(); diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp index 032e08f5a0..c35af9ca5b 100644 --- a/modules/gdscript/gdscript_analyzer.cpp +++ b/modules/gdscript/gdscript_analyzer.cpp @@ -2270,10 +2270,10 @@ void GDScriptAnalyzer::reduce_call(GDScriptParser::CallNode *p_call, bool is_awa if (get_function_signature(p_call, base_type, p_call->function_name, return_type, par_types, default_arg_count, is_static, is_vararg)) { // If the function require typed arrays we must make literals be typed. - for (Map<int, GDScriptParser::ArrayNode *>::Element *E = arrays.front(); E; E = E->next()) { - int index = E->key(); + for (const KeyValue<int, GDScriptParser::ArrayNode *> &E : arrays) { + int index = E.key; if (index < par_types.size() && par_types[index].has_container_element_type()) { - update_array_literal_element_type(par_types[index], E->get()); + update_array_literal_element_type(par_types[index], E.value); } } validate_call_arg(par_types, default_arg_count, is_vararg, p_call); diff --git a/modules/gdscript/gdscript_byte_codegen.cpp b/modules/gdscript/gdscript_byte_codegen.cpp index 1127488db8..b8300cd872 100644 --- a/modules/gdscript/gdscript_byte_codegen.cpp +++ b/modules/gdscript/gdscript_byte_codegen.cpp @@ -209,8 +209,8 @@ GDScriptFunction *GDScriptByteCodeGenerator::write_end() { if (name_map.size()) { function->global_names.resize(name_map.size()); function->_global_names_ptr = &function->global_names[0]; - for (Map<StringName, int>::Element *E = name_map.front(); E; E = E->next()) { - function->global_names.write[E->get()] = E->key(); + for (const KeyValue<StringName, int> &E : name_map) { + function->global_names.write[E.value] = E.key; } function->_global_names_count = function->global_names.size(); @@ -241,8 +241,8 @@ GDScriptFunction *GDScriptByteCodeGenerator::write_end() { function->operator_funcs.resize(operator_func_map.size()); function->_operator_funcs_count = function->operator_funcs.size(); function->_operator_funcs_ptr = function->operator_funcs.ptr(); - for (const Map<Variant::ValidatedOperatorEvaluator, int>::Element *E = operator_func_map.front(); E; E = E->next()) { - function->operator_funcs.write[E->get()] = E->key(); + for (const KeyValue<Variant::ValidatedOperatorEvaluator, int> &E : operator_func_map) { + function->operator_funcs.write[E.value] = E.key; } } else { function->_operator_funcs_count = 0; @@ -253,8 +253,8 @@ GDScriptFunction *GDScriptByteCodeGenerator::write_end() { function->setters.resize(setters_map.size()); function->_setters_count = function->setters.size(); function->_setters_ptr = function->setters.ptr(); - for (const Map<Variant::ValidatedSetter, int>::Element *E = setters_map.front(); E; E = E->next()) { - function->setters.write[E->get()] = E->key(); + for (const KeyValue<Variant::ValidatedSetter, int> &E : setters_map) { + function->setters.write[E.value] = E.key; } } else { function->_setters_count = 0; @@ -265,8 +265,8 @@ GDScriptFunction *GDScriptByteCodeGenerator::write_end() { function->getters.resize(getters_map.size()); function->_getters_count = function->getters.size(); function->_getters_ptr = function->getters.ptr(); - for (const Map<Variant::ValidatedGetter, int>::Element *E = getters_map.front(); E; E = E->next()) { - function->getters.write[E->get()] = E->key(); + for (const KeyValue<Variant::ValidatedGetter, int> &E : getters_map) { + function->getters.write[E.value] = E.key; } } else { function->_getters_count = 0; @@ -277,8 +277,8 @@ GDScriptFunction *GDScriptByteCodeGenerator::write_end() { function->keyed_setters.resize(keyed_setters_map.size()); function->_keyed_setters_count = function->keyed_setters.size(); function->_keyed_setters_ptr = function->keyed_setters.ptr(); - for (const Map<Variant::ValidatedKeyedSetter, int>::Element *E = keyed_setters_map.front(); E; E = E->next()) { - function->keyed_setters.write[E->get()] = E->key(); + for (const KeyValue<Variant::ValidatedKeyedSetter, int> &E : keyed_setters_map) { + function->keyed_setters.write[E.value] = E.key; } } else { function->_keyed_setters_count = 0; @@ -289,8 +289,8 @@ GDScriptFunction *GDScriptByteCodeGenerator::write_end() { function->keyed_getters.resize(keyed_getters_map.size()); function->_keyed_getters_count = function->keyed_getters.size(); function->_keyed_getters_ptr = function->keyed_getters.ptr(); - for (const Map<Variant::ValidatedKeyedGetter, int>::Element *E = keyed_getters_map.front(); E; E = E->next()) { - function->keyed_getters.write[E->get()] = E->key(); + for (const KeyValue<Variant::ValidatedKeyedGetter, int> &E : keyed_getters_map) { + function->keyed_getters.write[E.value] = E.key; } } else { function->_keyed_getters_count = 0; @@ -301,8 +301,8 @@ GDScriptFunction *GDScriptByteCodeGenerator::write_end() { function->indexed_setters.resize(indexed_setters_map.size()); function->_indexed_setters_count = function->indexed_setters.size(); function->_indexed_setters_ptr = function->indexed_setters.ptr(); - for (const Map<Variant::ValidatedIndexedSetter, int>::Element *E = indexed_setters_map.front(); E; E = E->next()) { - function->indexed_setters.write[E->get()] = E->key(); + for (const KeyValue<Variant::ValidatedIndexedSetter, int> &E : indexed_setters_map) { + function->indexed_setters.write[E.value] = E.key; } } else { function->_indexed_setters_count = 0; @@ -313,8 +313,8 @@ GDScriptFunction *GDScriptByteCodeGenerator::write_end() { function->indexed_getters.resize(indexed_getters_map.size()); function->_indexed_getters_count = function->indexed_getters.size(); function->_indexed_getters_ptr = function->indexed_getters.ptr(); - for (const Map<Variant::ValidatedIndexedGetter, int>::Element *E = indexed_getters_map.front(); E; E = E->next()) { - function->indexed_getters.write[E->get()] = E->key(); + for (const KeyValue<Variant::ValidatedIndexedGetter, int> &E : indexed_getters_map) { + function->indexed_getters.write[E.value] = E.key; } } else { function->_indexed_getters_count = 0; @@ -325,8 +325,8 @@ GDScriptFunction *GDScriptByteCodeGenerator::write_end() { function->builtin_methods.resize(builtin_method_map.size()); function->_builtin_methods_ptr = function->builtin_methods.ptr(); function->_builtin_methods_count = builtin_method_map.size(); - for (const Map<Variant::ValidatedBuiltInMethod, int>::Element *E = builtin_method_map.front(); E; E = E->next()) { - function->builtin_methods.write[E->get()] = E->key(); + for (const KeyValue<Variant::ValidatedBuiltInMethod, int> &E : builtin_method_map) { + function->builtin_methods.write[E.value] = E.key; } } else { function->_builtin_methods_ptr = nullptr; @@ -337,8 +337,8 @@ GDScriptFunction *GDScriptByteCodeGenerator::write_end() { function->constructors.resize(constructors_map.size()); function->_constructors_ptr = function->constructors.ptr(); function->_constructors_count = constructors_map.size(); - for (const Map<Variant::ValidatedConstructor, int>::Element *E = constructors_map.front(); E; E = E->next()) { - function->constructors.write[E->get()] = E->key(); + for (const KeyValue<Variant::ValidatedConstructor, int> &E : constructors_map) { + function->constructors.write[E.value] = E.key; } } else { function->_constructors_ptr = nullptr; @@ -349,8 +349,8 @@ GDScriptFunction *GDScriptByteCodeGenerator::write_end() { function->utilities.resize(utilities_map.size()); function->_utilities_ptr = function->utilities.ptr(); function->_utilities_count = utilities_map.size(); - for (const Map<Variant::ValidatedUtilityFunction, int>::Element *E = utilities_map.front(); E; E = E->next()) { - function->utilities.write[E->get()] = E->key(); + for (const KeyValue<Variant::ValidatedUtilityFunction, int> &E : utilities_map) { + function->utilities.write[E.value] = E.key; } } else { function->_utilities_ptr = nullptr; @@ -361,8 +361,8 @@ GDScriptFunction *GDScriptByteCodeGenerator::write_end() { function->gds_utilities.resize(gds_utilities_map.size()); function->_gds_utilities_ptr = function->gds_utilities.ptr(); function->_gds_utilities_count = gds_utilities_map.size(); - for (const Map<GDScriptUtilityFunctions::FunctionPtr, int>::Element *E = gds_utilities_map.front(); E; E = E->next()) { - function->gds_utilities.write[E->get()] = E->key(); + for (const KeyValue<GDScriptUtilityFunctions::FunctionPtr, int> &E : gds_utilities_map) { + function->gds_utilities.write[E.value] = E.key; } } else { function->_gds_utilities_ptr = nullptr; @@ -373,8 +373,8 @@ GDScriptFunction *GDScriptByteCodeGenerator::write_end() { function->methods.resize(method_bind_map.size()); function->_methods_ptr = function->methods.ptrw(); function->_methods_count = method_bind_map.size(); - for (const Map<MethodBind *, int>::Element *E = method_bind_map.front(); E; E = E->next()) { - function->methods.write[E->get()] = E->key(); + for (const KeyValue<MethodBind *, int> &E : method_bind_map) { + function->methods.write[E.value] = E.key; } } else { function->_methods_ptr = nullptr; @@ -385,8 +385,8 @@ GDScriptFunction *GDScriptByteCodeGenerator::write_end() { function->lambdas.resize(lambdas_map.size()); function->_lambdas_ptr = function->lambdas.ptrw(); function->_lambdas_count = lambdas_map.size(); - for (const Map<GDScriptFunction *, int>::Element *E = lambdas_map.front(); E; E = E->next()) { - function->lambdas.write[E->get()] = E->key(); + for (const KeyValue<GDScriptFunction *, int> &E : lambdas_map) { + function->lambdas.write[E.value] = E.key; } } else { function->_lambdas_ptr = nullptr; diff --git a/modules/gdscript/gdscript_byte_codegen.h b/modules/gdscript/gdscript_byte_codegen.h index dcc11ebdce..fbbf5802fd 100644 --- a/modules/gdscript/gdscript_byte_codegen.h +++ b/modules/gdscript/gdscript_byte_codegen.h @@ -153,12 +153,12 @@ class GDScriptByteCodeGenerator : public GDScriptCodeGenerator { #endif locals.resize(current_locals); if (debug_stack) { - for (Map<StringName, int>::Element *E = block_identifiers.front(); E; E = E->next()) { + for (const KeyValue<StringName, int> &E : block_identifiers) { GDScriptFunction::StackDebug sd; sd.added = false; - sd.identifier = E->key(); + sd.identifier = E.key; sd.line = current_line; - sd.pos = E->get(); + sd.pos = E.value; stack_debug.push_back(sd); } block_identifiers = block_identifier_stack.back()->get(); diff --git a/modules/gdscript/gdscript_compiler.cpp b/modules/gdscript/gdscript_compiler.cpp index 947224e93e..2c02291795 100644 --- a/modules/gdscript/gdscript_compiler.cpp +++ b/modules/gdscript/gdscript_compiler.cpp @@ -2193,8 +2193,8 @@ Error GDScriptCompiler::_parse_class_level(GDScript *p_script, const GDScriptPar p_script->_base = nullptr; p_script->members.clear(); p_script->constants.clear(); - for (Map<StringName, GDScriptFunction *>::Element *E = p_script->member_functions.front(); E; E = E->next()) { - memdelete(E->get()); + for (const KeyValue<StringName, GDScriptFunction *> &E : p_script->member_functions) { + memdelete(E.value); } p_script->member_functions.clear(); p_script->member_indices.clear(); @@ -2519,8 +2519,8 @@ Error GDScriptCompiler::_parse_class_blocks(GDScript *p_script, const GDScriptPa instance->owner = E->get(); //needed for hot reloading - for (Map<StringName, GDScript::MemberInfo>::Element *F = p_script->member_indices.front(); F; F = F->next()) { - instance->member_indices_cache[F->key()] = F->get().index; + for (const KeyValue<StringName, GDScript::MemberInfo> &F : p_script->member_indices) { + instance->member_indices_cache[F.key] = F.value.index; } instance->owner->set_script_instance(instance); diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp index 044ac4b661..83805f626a 100644 --- a/modules/gdscript/gdscript_editor.cpp +++ b/modules/gdscript/gdscript_editor.cpp @@ -173,8 +173,8 @@ bool GDScriptLanguage::validate(const String &p_script, const String &p_path, Li get_function_names_recursively(cl, "", funcs); - for (Map<int, String>::Element *E = funcs.front(); E; E = E->next()) { - r_functions->push_back(E->get() + ":" + itos(E->key())); + for (const KeyValue<int, String> &E : funcs) { + r_functions->push_back(E.value + ":" + itos(E.key)); } } @@ -344,9 +344,9 @@ void GDScriptLanguage::debug_get_stack_level_members(int p_level, List<String> * const Map<StringName, GDScript::MemberInfo> &mi = script->debug_get_member_indices(); - for (const Map<StringName, GDScript::MemberInfo>::Element *E = mi.front(); E; E = E->next()) { - p_members->push_back(E->key()); - p_values->push_back(instance->debug_get_member_by_index(E->get().index)); + for (const KeyValue<StringName, GDScript::MemberInfo> &E : mi) { + p_members->push_back(E.key); + p_values->push_back(instance->debug_get_member_by_index(E.value.index)); } } @@ -370,14 +370,14 @@ void GDScriptLanguage::debug_get_globals(List<String> *p_globals, List<Variant> List<Pair<String, Variant>> cinfo; get_public_constants(&cinfo); - for (const Map<StringName, int>::Element *E = name_idx.front(); E; E = E->next()) { - if (ClassDB::class_exists(E->key()) || Engine::get_singleton()->has_singleton(E->key())) { + for (const KeyValue<StringName, int> &E : name_idx) { + if (ClassDB::class_exists(E.key) || Engine::get_singleton()->has_singleton(E.key)) { continue; } bool is_script_constant = false; for (List<Pair<String, Variant>>::Element *CE = cinfo.front(); CE; CE = CE->next()) { - if (CE->get().first == E->key()) { + if (CE->get().first == E.key) { is_script_constant = true; break; } @@ -386,7 +386,7 @@ void GDScriptLanguage::debug_get_globals(List<String> *p_globals, List<Variant> continue; } - const Variant &var = globals[E->value()]; + const Variant &var = globals[E.value]; if (Object *obj = var) { if (Object::cast_to<GDScriptNativeClass>(obj)) { continue; @@ -395,7 +395,7 @@ void GDScriptLanguage::debug_get_globals(List<String> *p_globals, List<Variant> bool skip = false; for (int i = 0; i < CoreConstants::get_global_constant_count(); i++) { - if (E->key() == CoreConstants::get_global_constant_name(i)) { + if (E.key == CoreConstants::get_global_constant_name(i)) { skip = true; break; } @@ -404,7 +404,7 @@ void GDScriptLanguage::debug_get_globals(List<String> *p_globals, List<Variant> continue; } - p_globals->push_back(E->key()); + p_globals->push_back(E.key); p_values->push_back(var); } } @@ -875,8 +875,8 @@ static void _find_identifiers_in_base(const GDScriptCompletionIdentifier &p_base } Map<StringName, Variant> constants; scr->get_constants(&constants); - for (Map<StringName, Variant>::Element *E = constants.front(); E; E = E->next()) { - ScriptCodeCompletionOption option(E->key().operator String(), ScriptCodeCompletionOption::KIND_CONSTANT); + for (const KeyValue<StringName, Variant> &E : constants) { + ScriptCodeCompletionOption option(E.key.operator String(), ScriptCodeCompletionOption::KIND_CONSTANT); r_result.insert(option.display, option); } @@ -1099,12 +1099,12 @@ static void _find_identifiers(GDScriptParser::CompletionContext &p_context, bool } // Native classes and global constants. - for (const Map<StringName, int>::Element *E = GDScriptLanguage::get_singleton()->get_global_map().front(); E; E = E->next()) { + for (const KeyValue<StringName, int> &E : GDScriptLanguage::get_singleton()->get_global_map()) { ScriptCodeCompletionOption option; - if (ClassDB::class_exists(E->key()) || Engine::get_singleton()->has_singleton(E->key())) { - option = ScriptCodeCompletionOption(E->key().operator String(), ScriptCodeCompletionOption::KIND_CLASS); + if (ClassDB::class_exists(E.key) || Engine::get_singleton()->has_singleton(E.key)) { + option = ScriptCodeCompletionOption(E.key.operator String(), ScriptCodeCompletionOption::KIND_CLASS); } else { - option = ScriptCodeCompletionOption(E->key().operator String(), ScriptCodeCompletionOption::KIND_CONSTANT); + option = ScriptCodeCompletionOption(E.key.operator String(), ScriptCodeCompletionOption::KIND_CONSTANT); } r_result.insert(option.display, option); } @@ -2680,8 +2680,8 @@ static void _find_call_arguments(GDScriptParser::CompletionContext &p_context, c } break; } - for (Map<String, ScriptCodeCompletionOption>::Element *E = options.front(); E; E = E->next()) { - r_options->push_back(E->get()); + for (const KeyValue<String, ScriptCodeCompletionOption> &E : options) { + r_options->push_back(E.value); } return OK; diff --git a/modules/gdscript/gdscript_function.cpp b/modules/gdscript/gdscript_function.cpp index 876c508689..a3f0c7dfef 100644 --- a/modules/gdscript/gdscript_function.cpp +++ b/modules/gdscript/gdscript_function.cpp @@ -120,11 +120,11 @@ void GDScriptFunction::debug_get_stack_member_state(int p_line, List<Pair<String } List<_GDFKCS> stackpositions; - for (Map<StringName, _GDFKC>::Element *E = sdmap.front(); E; E = E->next()) { + for (const KeyValue<StringName, _GDFKC> &E : sdmap) { _GDFKCS spp; - spp.id = E->key(); - spp.order = E->get().order; - spp.pos = E->get().pos.back()->get(); + spp.id = E.key; + spp.order = E.value.order; + spp.pos = E.value.pos.back()->get(); stackpositions.push_back(spp); } diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index 025accf4ba..63817e970a 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -582,9 +582,9 @@ void GDScriptParser::parse_program() { parse_class_body(true); #ifdef TOOLS_ENABLED - for (Map<int, GDScriptTokenizer::CommentData>::Element *E = tokenizer.get_comments().front(); E; E = E->next()) { - if (E->get().new_line && E->get().comment.begins_with("##")) { - class_doc_line = MIN(class_doc_line, E->key()); + for (const KeyValue<int, GDScriptTokenizer::CommentData> &E : tokenizer.get_comments()) { + if (E.value.new_line && E.value.comment.begins_with("##")) { + class_doc_line = MIN(class_doc_line, E.key); } } if (has_comment(class_doc_line)) { @@ -3481,22 +3481,22 @@ bool GDScriptParser::network_annotations(const AnnotationNode *p_annotation, Nod } for (int i = last; i >= 0; i--) { String mode = p_annotation->resolved_arguments[i].operator String(); - if (mode == "any") { - rpc_config.rpc_mode = Multiplayer::RPC_MODE_ANY; - } else if (mode == "auth") { + if (mode == "any_peer") { + rpc_config.rpc_mode = Multiplayer::RPC_MODE_ANY_PEER; + } else if (mode == "authority") { rpc_config.rpc_mode = Multiplayer::RPC_MODE_AUTHORITY; - } else if (mode == "sync") { + } else if (mode == "call_local") { rpc_config.sync = true; - } else if (mode == "nosync") { + } else if (mode == "call_remote") { rpc_config.sync = false; } else if (mode == "reliable") { rpc_config.transfer_mode = Multiplayer::TRANSFER_MODE_RELIABLE; } else if (mode == "unreliable") { rpc_config.transfer_mode = Multiplayer::TRANSFER_MODE_UNRELIABLE; - } else if (mode == "ordered") { - rpc_config.transfer_mode = Multiplayer::TRANSFER_MODE_ORDERED; + } else if (mode == "unreliable_ordered") { + rpc_config.transfer_mode = Multiplayer::TRANSFER_MODE_UNRELIABLE_ORDERED; } else { - push_error(R"(Invalid RPC argument. Must be one of: 'sync'/'nosync' (local calls), 'any'/'auth' (permission), 'reliable'/'unreliable'/'ordered' (transfer mode).)", p_annotation); + push_error(R"(Invalid RPC argument. Must be one of: 'call_local'/'no_call_local' (local calls), 'any_peer'/'authority' (permission), 'reliable'/'unreliable'/'unreliable_ordered' (transfer mode).)", p_annotation); } } } diff --git a/modules/gdscript/gdscript_utility_functions.cpp b/modules/gdscript/gdscript_utility_functions.cpp index 62531473c3..f1b0079536 100644 --- a/modules/gdscript/gdscript_utility_functions.cpp +++ b/modules/gdscript/gdscript_utility_functions.cpp @@ -317,9 +317,9 @@ struct GDScriptUtilityFunctionsDefinitions { d["@subpath"] = cp; d["@path"] = p->get_path(); - for (Map<StringName, GDScript::MemberInfo>::Element *E = base->member_indices.front(); E; E = E->next()) { - if (!d.has(E->key())) { - d[E->key()] = ins->members[E->get().index]; + for (const KeyValue<StringName, GDScript::MemberInfo> &E : base->member_indices) { + if (!d.has(E.key)) { + d[E.key] = ins->members[E.value.index]; } } *r_ret = d; @@ -396,9 +396,9 @@ struct GDScriptUtilityFunctionsDefinitions { GDScriptInstance *ins = static_cast<GDScriptInstance *>(static_cast<Object *>(*r_ret)->get_script_instance()); Ref<GDScript> gd_ref = ins->get_script(); - for (Map<StringName, GDScript::MemberInfo>::Element *E = gd_ref->member_indices.front(); E; E = E->next()) { - if (d.has(E->key())) { - ins->members.write[E->get().index] = d[E->key()]; + for (KeyValue<StringName, GDScript::MemberInfo> &E : gd_ref->member_indices) { + if (d.has(E.key)) { + ins->members.write[E.value.index] = d[E.key]; } } } diff --git a/modules/gdscript/gdscript_vm.cpp b/modules/gdscript/gdscript_vm.cpp index 6186d0edee..c89cf2f25c 100644 --- a/modules/gdscript/gdscript_vm.cpp +++ b/modules/gdscript/gdscript_vm.cpp @@ -531,8 +531,8 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a memnew_placement(&stack[ADDR_STACK_CLASS], Variant(script)); - for (const Map<int, Variant::Type>::Element *E = temporary_slots.front(); E; E = E->next()) { - type_init_function_table[E->get()](&stack[E->key()]); + for (const KeyValue<int, Variant::Type> &E : temporary_slots) { + type_init_function_table[E.value](&stack[E.key]); } String err_text; diff --git a/modules/gdscript/language_server/gdscript_extend_parser.cpp b/modules/gdscript/language_server/gdscript_extend_parser.cpp index d106b3b541..730e554476 100644 --- a/modules/gdscript/language_server/gdscript_extend_parser.cpp +++ b/modules/gdscript/language_server/gdscript_extend_parser.cpp @@ -491,7 +491,7 @@ String ExtendGDScriptParser::get_text_for_completion(const lsp::Position &p_curs return longthing; } -String ExtendGDScriptParser::get_text_for_lookup_symbol(const lsp::Position &p_cursor, const String &p_symbol, bool p_func_requred) const { +String ExtendGDScriptParser::get_text_for_lookup_symbol(const lsp::Position &p_cursor, const String &p_symbol, bool p_func_required) const { String longthing; int len = lines.size(); for (int i = 0; i < len; i++) { @@ -513,7 +513,7 @@ String ExtendGDScriptParser::get_text_for_lookup_symbol(const lsp::Position &p_c longthing += first_part; longthing += String::chr(0xFFFF); //not unicode, represents the cursor - if (p_func_requred) { + if (p_func_required) { longthing += "("; // tell the parser this is a function call } longthing += last_part; @@ -532,6 +532,9 @@ String ExtendGDScriptParser::get_text_for_lookup_symbol(const lsp::Position &p_c String ExtendGDScriptParser::get_identifier_under_position(const lsp::Position &p_position, Vector2i &p_offset) const { ERR_FAIL_INDEX_V(p_position.line, lines.size(), ""); String line = lines[p_position.line]; + if (line.is_empty()) { + return ""; + } ERR_FAIL_INDEX_V(p_position.character, line.size(), ""); int start_pos = p_position.character; diff --git a/modules/gdscript/language_server/gdscript_extend_parser.h b/modules/gdscript/language_server/gdscript_extend_parser.h index 28b9b3c82a..5d7b16765b 100644 --- a/modules/gdscript/language_server/gdscript_extend_parser.h +++ b/modules/gdscript/language_server/gdscript_extend_parser.h @@ -85,7 +85,7 @@ public: Error get_left_function_call(const lsp::Position &p_position, lsp::Position &r_func_pos, int &r_arg_index) const; String get_text_for_completion(const lsp::Position &p_cursor) const; - String get_text_for_lookup_symbol(const lsp::Position &p_cursor, const String &p_symbol = "", bool p_func_requred = false) const; + String get_text_for_lookup_symbol(const lsp::Position &p_cursor, const String &p_symbol = "", bool p_func_required = false) const; String get_identifier_under_position(const lsp::Position &p_position, Vector2i &p_offset) const; String get_uri() const; diff --git a/modules/gdscript/language_server/gdscript_language_protocol.cpp b/modules/gdscript/language_server/gdscript_language_protocol.cpp index bd5a9f01b2..5cf1e0fc5f 100644 --- a/modules/gdscript/language_server/gdscript_language_protocol.cpp +++ b/modules/gdscript/language_server/gdscript_language_protocol.cpp @@ -212,11 +212,11 @@ void GDScriptLanguageProtocol::initialized(const Variant &p_params) { lsp::GodotCapabilities capabilities; DocTools *doc = EditorHelp::get_doc_data(); - for (Map<String, DocData::ClassDoc>::Element *E = doc->class_list.front(); E; E = E->next()) { + for (const KeyValue<String, DocData::ClassDoc> &E : doc->class_list) { lsp::GodotNativeClassInfo gdclass; - gdclass.name = E->get().name; - gdclass.class_doc = &(E->get()); - if (ClassDB::ClassInfo *ptr = ClassDB::classes.getptr(StringName(E->get().name))) { + gdclass.name = E.value.name; + gdclass.class_doc = &(E.value); + if (ClassDB::ClassInfo *ptr = ClassDB::classes.getptr(StringName(E.value.name))) { gdclass.class_info = ptr; } capabilities.native_classes.push_back(gdclass); diff --git a/modules/gdscript/language_server/gdscript_text_document.cpp b/modules/gdscript/language_server/gdscript_text_document.cpp index 03b1e3fa44..92ce71f395 100644 --- a/modules/gdscript/language_server/gdscript_text_document.cpp +++ b/modules/gdscript/language_server/gdscript_text_document.cpp @@ -217,8 +217,8 @@ Array GDScriptTextDocument::completion(const Dictionary &p_params) { } else if (GDScriptLanguageProtocol::get_singleton()->is_smart_resolve_enabled()) { arr = native_member_completions.duplicate(); - for (Map<String, ExtendGDScriptParser *>::Element *E = GDScriptLanguageProtocol::get_singleton()->get_workspace()->scripts.front(); E; E = E->next()) { - ExtendGDScriptParser *script = E->get(); + for (KeyValue<String, ExtendGDScriptParser *> &E : GDScriptLanguageProtocol::get_singleton()->get_workspace()->scripts) { + ExtendGDScriptParser *script = E.value; const Array &items = script->get_member_completions(); const int start_size = arr.size(); @@ -428,6 +428,9 @@ GDScriptTextDocument::~GDScriptTextDocument() { void GDScriptTextDocument::sync_script_content(const String &p_path, const String &p_content) { String path = GDScriptLanguageProtocol::get_singleton()->get_workspace()->get_file_path(p_path); + if (!path.begins_with("res://")) { + return; + } GDScriptLanguageProtocol::get_singleton()->get_workspace()->parse_script(path, p_content); EditorFileSystem::get_singleton()->update_file(path); diff --git a/modules/gdscript/language_server/gdscript_workspace.cpp b/modules/gdscript/language_server/gdscript_workspace.cpp index f4b55cac02..371e3de419 100644 --- a/modules/gdscript/language_server/gdscript_workspace.cpp +++ b/modules/gdscript/language_server/gdscript_workspace.cpp @@ -261,9 +261,9 @@ Array GDScriptWorkspace::symbol(const Dictionary &p_params) { String query = p_params["query"]; Array arr; if (!query.is_empty()) { - for (Map<String, ExtendGDScriptParser *>::Element *E = scripts.front(); E; E = E->next()) { + for (const KeyValue<String, ExtendGDScriptParser *> &E : scripts) { Vector<lsp::DocumentedSymbolInformation> script_symbols; - E->get()->get_symbols().symbol_tree_as_list(E->key(), script_symbols); + E.value->get_symbols().symbol_tree_as_list(E.key, script_symbols); for (int i = 0; i < script_symbols.size(); ++i) { if (query.is_subsequence_ofi(script_symbols[i].name)) { lsp::DocumentedSymbolInformation symbol = script_symbols[i]; @@ -282,10 +282,10 @@ Error GDScriptWorkspace::initialize() { } DocTools *doc = EditorHelp::get_doc_data(); - for (Map<String, DocData::ClassDoc>::Element *E = doc->class_list.front(); E; E = E->next()) { - const DocData::ClassDoc &class_data = E->value(); + for (const KeyValue<String, DocData::ClassDoc> &E : doc->class_list) { + const DocData::ClassDoc &class_data = E.value; lsp::DocumentSymbol class_symbol; - String class_name = E->key(); + String class_name = E.key; class_symbol.name = class_name; class_symbol.native_class = class_name; class_symbol.kind = lsp::SymbolKind::Class; @@ -393,19 +393,19 @@ Error GDScriptWorkspace::initialize() { reload_all_workspace_scripts(); if (GDScriptLanguageProtocol::get_singleton()->is_smart_resolve_enabled()) { - for (Map<StringName, lsp::DocumentSymbol>::Element *E = native_symbols.front(); E; E = E->next()) { + for (const KeyValue<StringName, lsp::DocumentSymbol> &E : native_symbols) { ClassMembers members; - const lsp::DocumentSymbol &class_symbol = E->get(); + const lsp::DocumentSymbol &class_symbol = E.value; for (int i = 0; i < class_symbol.children.size(); i++) { const lsp::DocumentSymbol &symbol = class_symbol.children[i]; members.set(symbol.name, &symbol); } - native_members.set(E->key(), members); + native_members.set(E.key, members); } // cache member completions - for (Map<String, ExtendGDScriptParser *>::Element *S = scripts.front(); S; S = S->next()) { - S->get()->get_member_completions(); + for (const KeyValue<String, ExtendGDScriptParser *> &S : scripts) { + S.value->get_member_completions(); } } @@ -685,8 +685,8 @@ void GDScriptWorkspace::resolve_related_symbols(const lsp::TextDocumentPositionP class_ptr = native_members.next(class_ptr); } - for (Map<String, ExtendGDScriptParser *>::Element *E = scripts.front(); E; E = E->next()) { - const ExtendGDScriptParser *script = E->get(); + for (const KeyValue<String, ExtendGDScriptParser *> &E : scripts) { + const ExtendGDScriptParser *script = E.value; const ClassMembers &members = script->get_members(); if (const lsp::DocumentSymbol *const *symbol = members.getptr(symbol_identifier)) { r_list.push_back(*symbol); @@ -786,12 +786,12 @@ GDScriptWorkspace::GDScriptWorkspace() { GDScriptWorkspace::~GDScriptWorkspace() { Set<String> cached_parsers; - for (Map<String, ExtendGDScriptParser *>::Element *E = parse_results.front(); E; E = E->next()) { - cached_parsers.insert(E->key()); + for (const KeyValue<String, ExtendGDScriptParser *> &E : parse_results) { + cached_parsers.insert(E.key); } - for (Map<String, ExtendGDScriptParser *>::Element *E = scripts.front(); E; E = E->next()) { - cached_parsers.insert(E->key()); + for (const KeyValue<String, ExtendGDScriptParser *> &E : scripts) { + cached_parsers.insert(E.key); } for (Set<String>::Element *E = cached_parsers.front(); E; E = E->next()) { diff --git a/modules/gdscript/language_server/lsp.hpp b/modules/gdscript/language_server/lsp.hpp index 662382d279..3710a84a28 100644 --- a/modules/gdscript/language_server/lsp.hpp +++ b/modules/gdscript/language_server/lsp.hpp @@ -277,15 +277,15 @@ struct WorkspaceEdit { Dictionary dict; Dictionary out_changes; - for (Map<String, Vector<TextEdit>>::Element *E = changes.front(); E; E = E->next()) { + for (const KeyValue<String, Vector<TextEdit>> &E : changes) { Array edits; - for (int i = 0; i < E->get().size(); ++i) { + for (int i = 0; i < E.value.size(); ++i) { Dictionary text_edit; - text_edit["range"] = E->get()[i].range.to_json(); - text_edit["newText"] = E->get()[i].newText; + text_edit["range"] = E.value[i].range.to_json(); + text_edit["newText"] = E.value[i].newText; edits.push_back(text_edit); } - out_changes[E->key()] = edits; + out_changes[E.key] = edits; } dict["changes"] = out_changes; diff --git a/modules/gdscript/tests/test_gdscript.cpp b/modules/gdscript/tests/test_gdscript.cpp index e54f055f2b..80eabc1596 100644 --- a/modules/gdscript/tests/test_gdscript.cpp +++ b/modules/gdscript/tests/test_gdscript.cpp @@ -172,8 +172,8 @@ static void test_compiler(const String &p_code, const String &p_script_path, con return; } - for (const Map<StringName, GDScriptFunction *>::Element *E = script->get_member_functions().front(); E; E = E->next()) { - const GDScriptFunction *func = E->value(); + for (const KeyValue<StringName, GDScriptFunction *> &E : script->get_member_functions()) { + const GDScriptFunction *func = E.value; String signature = "Disassembling " + func->get_name().operator String() + "("; for (int i = 0; i < func->get_argument_count(); i++) { diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp index 5f2e8d4ba6..3f1f218e78 100644 --- a/modules/gltf/gltf_document.cpp +++ b/modules/gltf/gltf_document.cpp @@ -4673,8 +4673,8 @@ Error GLTFDocument::_serialize_animations(Ref<GLTFState> state) { Array channels; Array samplers; - for (Map<int, GLTFAnimation::Track>::Element *track_i = gltf_animation->get_tracks().front(); track_i; track_i = track_i->next()) { - GLTFAnimation::Track track = track_i->get(); + for (KeyValue<int, GLTFAnimation::Track> &track_i : gltf_animation->get_tracks()) { + GLTFAnimation::Track track = track_i.value; if (track.position_track.times.size()) { Dictionary t; t["sampler"] = samplers.size(); @@ -4690,7 +4690,7 @@ Error GLTFDocument::_serialize_animations(Ref<GLTFState> state) { Dictionary target; target["path"] = "translation"; - target["node"] = track_i->key(); + target["node"] = track_i.key; t["target"] = target; channels.push_back(t); @@ -4710,7 +4710,7 @@ Error GLTFDocument::_serialize_animations(Ref<GLTFState> state) { Dictionary target; target["path"] = "rotation"; - target["node"] = track_i->key(); + target["node"] = track_i.key; t["target"] = target; channels.push_back(t); @@ -4730,7 +4730,7 @@ Error GLTFDocument::_serialize_animations(Ref<GLTFState> state) { Dictionary target; target["path"] = "scale"; - target["node"] = track_i->key(); + target["node"] = track_i.key; t["target"] = target; channels.push_back(t); @@ -4809,7 +4809,7 @@ Error GLTFDocument::_serialize_animations(Ref<GLTFState> state) { Dictionary target; target["path"] = "weights"; - target["node"] = track_i->key(); + target["node"] = track_i.key; t["target"] = target; channels.push_back(t); @@ -5800,16 +5800,16 @@ void GLTFDocument::_import_animation(Ref<GLTFState> state, AnimationPlayer *ap, float length = 0.0; - for (Map<int, GLTFAnimation::Track>::Element *track_i = anim->get_tracks().front(); track_i; track_i = track_i->next()) { - const GLTFAnimation::Track &track = track_i->get(); + for (const KeyValue<int, GLTFAnimation::Track> &track_i : anim->get_tracks()) { + const GLTFAnimation::Track &track = track_i.value; //need to find the path: for skeletons, weight tracks will affect the mesh NodePath node_path; //for skeletons, transform tracks always affect bones NodePath transform_node_path; - GLTFNodeIndex node_index = track_i->key(); + GLTFNodeIndex node_index = track_i.key; - const Ref<GLTFNode> gltf_node = state->nodes[track_i->key()]; + const Ref<GLTFNode> gltf_node = state->nodes[track_i.key]; Node *root = ap->get_parent(); ERR_FAIL_COND(root == nullptr); @@ -5861,15 +5861,15 @@ void GLTFDocument::_import_animation(Ref<GLTFState> state, AnimationPlayer *ap, Vector3 base_scale = Vector3(1, 1, 1); if (!track.rotation_track.values.size()) { - base_rot = state->nodes[track_i->key()]->rotation.normalized(); + base_rot = state->nodes[track_i.key]->rotation.normalized(); } if (!track.position_track.values.size()) { - base_pos = state->nodes[track_i->key()]->position; + base_pos = state->nodes[track_i.key]->position; } if (!track.scale_track.values.size()) { - base_scale = state->nodes[track_i->key()]->scale; + base_scale = state->nodes[track_i.key]->scale; } bool last = false; @@ -6322,9 +6322,9 @@ void GLTFDocument::_convert_animation(Ref<GLTFState> state, AnimationPlayer *ap, const Vector<String> node_suffix = String(orig_track_path).split(":position"); const NodePath path = node_suffix[0]; const Node *node = ap->get_parent()->get_node_or_null(path); - for (Map<GLTFNodeIndex, Node *>::Element *position_scene_node_i = state->scene_nodes.front(); position_scene_node_i; position_scene_node_i = position_scene_node_i->next()) { - if (position_scene_node_i->get() == node) { - GLTFNodeIndex node_index = position_scene_node_i->key(); + for (const KeyValue<GLTFNodeIndex, Node *> &position_scene_node_i : state->scene_nodes) { + if (position_scene_node_i.value == node) { + GLTFNodeIndex node_index = position_scene_node_i.key; Map<int, GLTFAnimation::Track>::Element *position_track_i = gltf_animation->get_tracks().find(node_index); GLTFAnimation::Track track; if (position_track_i) { @@ -6338,9 +6338,9 @@ void GLTFDocument::_convert_animation(Ref<GLTFState> state, AnimationPlayer *ap, const Vector<String> node_suffix = String(orig_track_path).split(":rotation_degrees"); const NodePath path = node_suffix[0]; const Node *node = ap->get_parent()->get_node_or_null(path); - for (Map<GLTFNodeIndex, Node *>::Element *rotation_degree_scene_node_i = state->scene_nodes.front(); rotation_degree_scene_node_i; rotation_degree_scene_node_i = rotation_degree_scene_node_i->next()) { - if (rotation_degree_scene_node_i->get() == node) { - GLTFNodeIndex node_index = rotation_degree_scene_node_i->key(); + for (const KeyValue<GLTFNodeIndex, Node *> &rotation_degree_scene_node_i : state->scene_nodes) { + if (rotation_degree_scene_node_i.value == node) { + GLTFNodeIndex node_index = rotation_degree_scene_node_i.key; Map<int, GLTFAnimation::Track>::Element *rotation_degree_track_i = gltf_animation->get_tracks().find(node_index); GLTFAnimation::Track track; if (rotation_degree_track_i) { @@ -6354,9 +6354,9 @@ void GLTFDocument::_convert_animation(Ref<GLTFState> state, AnimationPlayer *ap, const Vector<String> node_suffix = String(orig_track_path).split(":scale"); const NodePath path = node_suffix[0]; const Node *node = ap->get_parent()->get_node_or_null(path); - for (Map<GLTFNodeIndex, Node *>::Element *scale_scene_node_i = state->scene_nodes.front(); scale_scene_node_i; scale_scene_node_i = scale_scene_node_i->next()) { - if (scale_scene_node_i->get() == node) { - GLTFNodeIndex node_index = scale_scene_node_i->key(); + for (const KeyValue<GLTFNodeIndex, Node *> &scale_scene_node_i : state->scene_nodes) { + if (scale_scene_node_i.value == node) { + GLTFNodeIndex node_index = scale_scene_node_i.key; Map<int, GLTFAnimation::Track>::Element *scale_track_i = gltf_animation->get_tracks().find(node_index); GLTFAnimation::Track track; if (scale_track_i) { @@ -6370,11 +6370,11 @@ void GLTFDocument::_convert_animation(Ref<GLTFState> state, AnimationPlayer *ap, const Vector<String> node_suffix = String(orig_track_path).split(":transform"); const NodePath path = node_suffix[0]; const Node *node = ap->get_parent()->get_node_or_null(path); - for (Map<GLTFNodeIndex, Node *>::Element *transform_track_i = state->scene_nodes.front(); transform_track_i; transform_track_i = transform_track_i->next()) { - if (transform_track_i->get() == node) { + for (const KeyValue<GLTFNodeIndex, Node *> &transform_track_i : state->scene_nodes) { + if (transform_track_i.value == node) { GLTFAnimation::Track track; - track = _convert_animation_track(state, track, animation, Transform3D(), track_i, transform_track_i->key()); - gltf_animation->get_tracks().insert(transform_track_i->key(), track); + track = _convert_animation_track(state, track, animation, Transform3D(), track_i, transform_track_i.key); + gltf_animation->get_tracks().insert(transform_track_i.key, track); } } } else if (String(orig_track_path).find(":blend_shapes/") != -1) { @@ -6386,9 +6386,9 @@ void GLTFDocument::_convert_animation(Ref<GLTFState> state, AnimationPlayer *ap, Ref<Mesh> mesh = mi->get_mesh(); ERR_CONTINUE(mesh.is_null()); int32_t mesh_index = -1; - for (Map<GLTFNodeIndex, Node *>::Element *mesh_track_i = state->scene_nodes.front(); mesh_track_i; mesh_track_i = mesh_track_i->next()) { - if (mesh_track_i->get() == node) { - mesh_index = mesh_track_i->key(); + for (const KeyValue<GLTFNodeIndex, Node *> &mesh_track_i : state->scene_nodes) { + if (mesh_track_i.value == node) { + mesh_index = mesh_track_i.key; } } ERR_CONTINUE(mesh_index == -1); @@ -6469,9 +6469,9 @@ void GLTFDocument::_convert_animation(Ref<GLTFState> state, AnimationPlayer *ap, for (int32_t node_i = 0; node_i < ap->get_parent()->get_child_count(); node_i++) { const Node *child = ap->get_parent()->get_child(node_i); const Node *node = child->get_node_or_null(orig_track_path); - for (Map<GLTFNodeIndex, Node *>::Element *scene_node_i = state->scene_nodes.front(); scene_node_i; scene_node_i = scene_node_i->next()) { - if (scene_node_i->get() == node) { - GLTFNodeIndex node_index = scene_node_i->key(); + for (const KeyValue<GLTFNodeIndex, Node *> &scene_node_i : state->scene_nodes) { + if (scene_node_i.value == node) { + GLTFNodeIndex node_index = scene_node_i.key; Map<int, GLTFAnimation::Track>::Element *node_track_i = gltf_animation->get_tracks().find(node_index); GLTFAnimation::Track track; if (node_track_i) { diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp index 116c0e00f9..c9d8f2b42b 100644 --- a/modules/gridmap/grid_map.cpp +++ b/modules/gridmap/grid_map.cpp @@ -420,8 +420,8 @@ bool GridMap::_octant_update(const OctantKey &p_key) { } //erase navigation - for (Map<IndexKey, Octant::NavMesh>::Element *E = g.navmesh_ids.front(); E; E = E->next()) { - NavigationServer3D::get_singleton()->free(E->get().region); + for (const KeyValue<IndexKey, Octant::NavMesh> &E : g.navmesh_ids) { + NavigationServer3D::get_singleton()->free(E.value.region); } g.navmesh_ids.clear(); @@ -512,15 +512,15 @@ bool GridMap::_octant_update(const OctantKey &p_key) { //update multimeshes, only if not baked if (baked_meshes.size() == 0) { - for (Map<int, List<Pair<Transform3D, IndexKey>>>::Element *E = multimesh_items.front(); E; E = E->next()) { + for (const KeyValue<int, List<Pair<Transform3D, IndexKey>>> &E : multimesh_items) { Octant::MultimeshInstance mmi; RID mm = RS::get_singleton()->multimesh_create(); - RS::get_singleton()->multimesh_allocate_data(mm, E->get().size(), RS::MULTIMESH_TRANSFORM_3D); - RS::get_singleton()->multimesh_set_mesh(mm, mesh_library->get_item_mesh(E->key())->get_rid()); + RS::get_singleton()->multimesh_allocate_data(mm, E.value.size(), RS::MULTIMESH_TRANSFORM_3D); + RS::get_singleton()->multimesh_set_mesh(mm, mesh_library->get_item_mesh(E.key)->get_rid()); int idx = 0; - for (const Pair<Transform3D, IndexKey> &F : E->get()) { + for (const Pair<Transform3D, IndexKey> &F : E.value) { RS::get_singleton()->multimesh_instance_set_transform(mm, idx, F.first); #ifdef TOOLS_ENABLED @@ -567,9 +567,9 @@ bool GridMap::_octant_update(const OctantKey &p_key) { } void GridMap::_reset_physic_bodies_collision_filters() { - for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) { - PhysicsServer3D::get_singleton()->body_set_collision_layer(E->get()->static_body, collision_layer); - PhysicsServer3D::get_singleton()->body_set_collision_mask(E->get()->static_body, collision_mask); + for (const KeyValue<OctantKey, Octant *> &E : octant_map) { + PhysicsServer3D::get_singleton()->body_set_collision_layer(E.value->static_body, collision_layer); + PhysicsServer3D::get_singleton()->body_set_collision_mask(E.value->static_body, collision_mask); } } @@ -590,17 +590,17 @@ void GridMap::_octant_enter_world(const OctantKey &p_key) { } if (bake_navigation && mesh_library.is_valid()) { - for (Map<IndexKey, Octant::NavMesh>::Element *F = g.navmesh_ids.front(); F; F = F->next()) { - if (cell_map.has(F->key()) && F->get().region.is_valid() == false) { - Ref<NavigationMesh> nm = mesh_library->get_item_navmesh(cell_map[F->key()].item); + for (KeyValue<IndexKey, Octant::NavMesh> &F : g.navmesh_ids) { + if (cell_map.has(F.key) && F.value.region.is_valid() == false) { + Ref<NavigationMesh> nm = mesh_library->get_item_navmesh(cell_map[F.key].item); if (nm.is_valid()) { RID region = NavigationServer3D::get_singleton()->region_create(); NavigationServer3D::get_singleton()->region_set_layers(region, navigation_layers); NavigationServer3D::get_singleton()->region_set_navmesh(region, nm); - NavigationServer3D::get_singleton()->region_set_transform(region, get_global_transform() * F->get().xform); + NavigationServer3D::get_singleton()->region_set_transform(region, get_global_transform() * F.value.xform); NavigationServer3D::get_singleton()->region_set_map(region, get_world_3d()->get_navigation_map()); - F->get().region = region; + F.value.region = region; } } } @@ -621,10 +621,10 @@ void GridMap::_octant_exit_world(const OctantKey &p_key) { RS::get_singleton()->instance_set_scenario(g.multimesh_instances[i].instance, RID()); } - for (Map<IndexKey, Octant::NavMesh>::Element *F = g.navmesh_ids.front(); F; F = F->next()) { - if (F->get().region.is_valid()) { - NavigationServer3D::get_singleton()->free(F->get().region); - F->get().region = RID(); + for (KeyValue<IndexKey, Octant::NavMesh> &F : g.navmesh_ids) { + if (F.value.region.is_valid()) { + NavigationServer3D::get_singleton()->free(F.value.region); + F.value.region = RID(); } } } @@ -643,8 +643,8 @@ void GridMap::_octant_clean_up(const OctantKey &p_key) { PhysicsServer3D::get_singleton()->free(g.static_body); // Erase navigation - for (Map<IndexKey, Octant::NavMesh>::Element *E = g.navmesh_ids.front(); E; E = E->next()) { - NavigationServer3D::get_singleton()->free(E->get().region); + for (const KeyValue<IndexKey, Octant::NavMesh> &E : g.navmesh_ids) { + NavigationServer3D::get_singleton()->free(E.value.region); } g.navmesh_ids.clear(); @@ -662,8 +662,8 @@ void GridMap::_notification(int p_what) { case NOTIFICATION_ENTER_WORLD: { last_transform = get_global_transform(); - for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) { - _octant_enter_world(E->key()); + for (const KeyValue<OctantKey, Octant *> &E : octant_map) { + _octant_enter_world(E.key); } for (int i = 0; i < baked_meshes.size(); i++) { @@ -678,8 +678,8 @@ void GridMap::_notification(int p_what) { break; } //update run - for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) { - _octant_transform(E->key()); + for (const KeyValue<OctantKey, Octant *> &E : octant_map) { + _octant_transform(E.key); } last_transform = new_xform; @@ -689,8 +689,8 @@ void GridMap::_notification(int p_what) { } } break; case NOTIFICATION_EXIT_WORLD: { - for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) { - _octant_exit_world(E->key()); + for (const KeyValue<OctantKey, Octant *> &E : octant_map) { + _octant_exit_world(E.key); } //_queue_octants_dirty(MAP_DIRTY_INSTANCES|MAP_DIRTY_TRANSFORMS); @@ -712,8 +712,8 @@ void GridMap::_update_visibility() { return; } - for (Map<OctantKey, Octant *>::Element *e = octant_map.front(); e; e = e->next()) { - Octant *octant = e->value(); + for (KeyValue<OctantKey, Octant *> &e : octant_map) { + Octant *octant = e.value; for (int i = 0; i < octant->multimesh_instances.size(); i++) { const Octant::MultimeshInstance &mi = octant->multimesh_instances[i]; RS::get_singleton()->instance_set_visible(mi.instance, is_visible_in_tree()); @@ -738,20 +738,20 @@ void GridMap::_recreate_octant_data() { recreating_octants = true; Map<IndexKey, Cell> cell_copy = cell_map; _clear_internal(); - for (Map<IndexKey, Cell>::Element *E = cell_copy.front(); E; E = E->next()) { - set_cell_item(Vector3i(E->key()), E->get().item, E->get().rot); + for (const KeyValue<IndexKey, Cell> &E : cell_copy) { + set_cell_item(Vector3i(E.key), E.value.item, E.value.rot); } recreating_octants = false; } void GridMap::_clear_internal() { - for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) { + for (const KeyValue<OctantKey, Octant *> &E : octant_map) { if (is_inside_world()) { - _octant_exit_world(E->key()); + _octant_exit_world(E.key); } - _octant_clean_up(E->key()); - memdelete(E->get()); + _octant_clean_up(E.key); + memdelete(E.value); } octant_map.clear(); @@ -773,9 +773,9 @@ void GridMap::_update_octants_callback() { } List<OctantKey> to_delete; - for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) { - if (_octant_update(E->key())) { - to_delete.push_back(E->key()); + for (const KeyValue<OctantKey, Octant *> &E : octant_map) { + if (_octant_update(E.key)) { + to_delete.push_back(E.key); } } @@ -883,8 +883,8 @@ void GridMap::set_clip(bool p_enabled, bool p_clip_above, int p_floor, Vector3:: clip_above = p_clip_above; //make it all update - for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) { - Octant *g = E->get(); + for (KeyValue<OctantKey, Octant *> &E : octant_map) { + Octant *g = E.value; g->dirty = true; } awaiting_update = true; @@ -904,8 +904,8 @@ Array GridMap::get_used_cells() const { Array a; a.resize(cell_map.size()); int i = 0; - for (Map<IndexKey, Cell>::Element *E = cell_map.front(); E; E = E->next()) { - Vector3 p(E->key().x, E->key().y, E->key().z); + for (const KeyValue<IndexKey, Cell> &E : cell_map) { + Vector3 p(E.key.x, E.key.y, E.key.z); a[i++] = p; } @@ -920,8 +920,8 @@ Array GridMap::get_meshes() { Vector3 ofs = _get_offset(); Array meshes; - for (Map<IndexKey, Cell>::Element *E = cell_map.front(); E; E = E->next()) { - int id = E->get().item; + for (KeyValue<IndexKey, Cell> &E : cell_map) { + int id = E.value.item; if (!mesh_library->has_item(id)) { continue; } @@ -930,13 +930,13 @@ Array GridMap::get_meshes() { continue; } - IndexKey ik = E->key(); + IndexKey ik = E.key; Vector3 cellpos = Vector3(ik.x, ik.y, ik.z); Transform3D xform; - xform.basis.set_orthogonal_index(E->get().rot); + xform.basis.set_orthogonal_index(E.value.rot); xform.set_origin(cellpos * cell_size + ofs); xform.basis.scale(Vector3(cell_scale, cell_scale, cell_scale)); @@ -972,10 +972,10 @@ void GridMap::make_baked_meshes(bool p_gen_lightmap_uv, float p_lightmap_uv_texe //generate Map<OctantKey, Map<Ref<Material>, Ref<SurfaceTool>>> surface_map; - for (Map<IndexKey, Cell>::Element *E = cell_map.front(); E; E = E->next()) { - IndexKey key = E->key(); + for (KeyValue<IndexKey, Cell> &E : cell_map) { + IndexKey key = E.key; - int item = E->get().item; + int item = E.value.item; if (!mesh_library->has_item(item)) { continue; } @@ -990,7 +990,7 @@ void GridMap::make_baked_meshes(bool p_gen_lightmap_uv, float p_lightmap_uv_texe Transform3D xform; - xform.basis.set_orthogonal_index(E->get().rot); + xform.basis.set_orthogonal_index(E.value.rot); xform.set_origin(cellpos * cell_size + ofs); xform.basis.scale(Vector3(cell_scale, cell_scale, cell_scale)); @@ -1023,11 +1023,11 @@ void GridMap::make_baked_meshes(bool p_gen_lightmap_uv, float p_lightmap_uv_texe } } - for (Map<OctantKey, Map<Ref<Material>, Ref<SurfaceTool>>>::Element *E = surface_map.front(); E; E = E->next()) { + for (KeyValue<OctantKey, Map<Ref<Material>, Ref<SurfaceTool>>> &E : surface_map) { Ref<ArrayMesh> mesh; mesh.instantiate(); - for (Map<Ref<Material>, Ref<SurfaceTool>>::Element *F = E->get().front(); F; F = F->next()) { - F->get()->commit(mesh); + for (KeyValue<Ref<Material>, Ref<SurfaceTool>> &F : E.value) { + F.value->commit(mesh); } BakedMesh bm; diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp index af7c54dd5b..247eee4280 100644 --- a/modules/mono/csharp_script.cpp +++ b/modules/mono/csharp_script.cpp @@ -3511,8 +3511,8 @@ int CSharpScript::get_member_line(const StringName &p_member) const { } Multiplayer::RPCMode CSharpScript::_member_get_rpc_mode(IMonoClassMember *p_member) const { - if (p_member->has_attribute(CACHED_CLASS(AnyAttribute))) { - return Multiplayer::RPC_MODE_ANY; + if (p_member->has_attribute(CACHED_CLASS(AnyPeerAttribute))) { + return Multiplayer::RPC_MODE_ANY_PEER; } if (p_member->has_attribute(CACHED_CLASS(AuthorityAttribute))) { return Multiplayer::RPC_MODE_AUTHORITY; diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/RPCAttributes.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/RPCAttributes.cs index 1da91ea867..b8b9bc660c 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/RPCAttributes.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/RPCAttributes.cs @@ -3,7 +3,7 @@ using System; namespace Godot { [AttributeUsage(AttributeTargets.Method)] - public class AnyAttribute : Attribute { } + public class AnyPeerAttribute : Attribute { } [AttributeUsage(AttributeTargets.Method)] public class AuthorityAttribute : Attribute { } diff --git a/modules/mono/mono_gd/gd_mono_cache.cpp b/modules/mono/mono_gd/gd_mono_cache.cpp index 34e845a589..2bf55493e0 100644 --- a/modules/mono/mono_gd/gd_mono_cache.cpp +++ b/modules/mono/mono_gd/gd_mono_cache.cpp @@ -140,7 +140,7 @@ void CachedData::clear_godot_api_cache() { field_ExportAttribute_hintString = nullptr; class_SignalAttribute = nullptr; class_ToolAttribute = nullptr; - class_AnyAttribute = nullptr; + class_AnyPeerAttribute = nullptr; class_AuthorityAttribute = nullptr; class_GodotMethodAttribute = nullptr; field_GodotMethodAttribute_methodName = nullptr; @@ -265,7 +265,7 @@ void update_godot_api_cache() { CACHE_FIELD_AND_CHECK(ExportAttribute, hintString, CACHED_CLASS(ExportAttribute)->get_field("hintString")); CACHE_CLASS_AND_CHECK(SignalAttribute, GODOT_API_CLASS(SignalAttribute)); CACHE_CLASS_AND_CHECK(ToolAttribute, GODOT_API_CLASS(ToolAttribute)); - CACHE_CLASS_AND_CHECK(AnyAttribute, GODOT_API_CLASS(AnyAttribute)); + CACHE_CLASS_AND_CHECK(AnyPeerAttribute, GODOT_API_CLASS(AnyPeerAttribute)); CACHE_CLASS_AND_CHECK(AuthorityAttribute, GODOT_API_CLASS(AuthorityAttribute)); CACHE_CLASS_AND_CHECK(GodotMethodAttribute, GODOT_API_CLASS(GodotMethodAttribute)); CACHE_FIELD_AND_CHECK(GodotMethodAttribute, methodName, CACHED_CLASS(GodotMethodAttribute)->get_field("methodName")); diff --git a/modules/mono/mono_gd/gd_mono_cache.h b/modules/mono/mono_gd/gd_mono_cache.h index e60a4d5279..4b4688b4d9 100644 --- a/modules/mono/mono_gd/gd_mono_cache.h +++ b/modules/mono/mono_gd/gd_mono_cache.h @@ -111,7 +111,7 @@ struct CachedData { GDMonoField *field_ExportAttribute_hintString; GDMonoClass *class_SignalAttribute; GDMonoClass *class_ToolAttribute; - GDMonoClass *class_AnyAttribute; + GDMonoClass *class_AnyPeerAttribute; GDMonoClass *class_AuthorityAttribute; GDMonoClass *class_GodotMethodAttribute; GDMonoField *field_GodotMethodAttribute_methodName; diff --git a/modules/navigation/nav_map.cpp b/modules/navigation/nav_map.cpp index 962bf79150..0c8f0ed8c9 100644 --- a/modules/navigation/nav_map.cpp +++ b/modules/navigation/nav_map.cpp @@ -613,17 +613,17 @@ void NavMap::sync() { } Vector<gd::Edge::Connection> free_edges; - for (Map<gd::EdgeKey, Vector<gd::Edge::Connection>>::Element *E = connections.front(); E; E = E->next()) { - if (E->get().size() == 2) { + for (KeyValue<gd::EdgeKey, Vector<gd::Edge::Connection>> &E : connections) { + if (E.value.size() == 2) { // Connect edge that are shared in different polygons. - gd::Edge::Connection &c1 = E->get().write[0]; - gd::Edge::Connection &c2 = E->get().write[1]; + gd::Edge::Connection &c1 = E.value.write[0]; + gd::Edge::Connection &c2 = E.value.write[1]; c1.polygon->edges[c1.edge].connections.push_back(c2); c2.polygon->edges[c2.edge].connections.push_back(c1); // Note: The pathway_start/end are full for those connection and do not need to be modified. } else { - CRASH_COND_MSG(E->get().size() != 1, vformat("Number of connection != 1. Found: %d", E->get().size())); - free_edges.push_back(E->get()[0]); + CRASH_COND_MSG(E.value.size() != 1, vformat("Number of connection != 1. Found: %d", E.value.size())); + free_edges.push_back(E.value[0]); } } diff --git a/modules/text_server_adv/config.py b/modules/text_server_adv/config.py index d22f9454ed..8c8df9b05e 100644 --- a/modules/text_server_adv/config.py +++ b/modules/text_server_adv/config.py @@ -4,3 +4,13 @@ def can_build(env, platform): def configure(env): pass + + +def get_doc_classes(): + return [ + "TextServerAdvanced", + ] + + +def get_doc_path(): + return "doc_classes" diff --git a/modules/text_server_adv/doc_classes/TextServerAdvanced.xml b/modules/text_server_adv/doc_classes/TextServerAdvanced.xml new file mode 100644 index 0000000000..eff4aa5fae --- /dev/null +++ b/modules/text_server_adv/doc_classes/TextServerAdvanced.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="TextServerAdvanced" inherits="TextServer" version="4.0"> + <brief_description> + Text Server using HarfBuzz, ICU and SIL Graphite to support BiDi, complex text layouts and contextual OpenType features. + </brief_description> + <description> + </description> + <tutorials> + </tutorials> +</class> diff --git a/modules/text_server_adv/register_types.cpp b/modules/text_server_adv/register_types.cpp index abefa83b9b..b711d1561f 100644 --- a/modules/text_server_adv/register_types.cpp +++ b/modules/text_server_adv/register_types.cpp @@ -33,7 +33,12 @@ #include "text_server_adv.h" void preregister_text_server_adv_types() { - TextServerAdvanced::register_server(); + GDREGISTER_CLASS(TextServerAdvanced); + if (TextServerManager::get_singleton()) { + Ref<TextServerAdvanced> ts; + ts.instantiate(); + TextServerManager::get_singleton()->add_interface(ts); + } } void register_text_server_adv_types() { diff --git a/modules/text_server_adv/text_server_adv.cpp b/modules/text_server_adv/text_server_adv.cpp index acc447018d..f5d159040f 100644 --- a/modules/text_server_adv/text_server_adv.cpp +++ b/modules/text_server_adv/text_server_adv.cpp @@ -322,7 +322,7 @@ _FORCE_INLINE_ bool is_underscore(char32_t p_char) { String TextServerAdvanced::interface_name = "ICU / HarfBuzz / Graphite"; uint32_t TextServerAdvanced::interface_features = FEATURE_BIDI_LAYOUT | FEATURE_VERTICAL_LAYOUT | FEATURE_SHAPING | FEATURE_KASHIDA_JUSTIFICATION | FEATURE_BREAK_ITERATORS | FEATURE_USE_SUPPORT_DATA | FEATURE_FONT_VARIABLE; -bool TextServerAdvanced::has_feature(Feature p_feature) { +bool TextServerAdvanced::has_feature(Feature p_feature) const { return (interface_features & p_feature) == p_feature; } @@ -330,6 +330,10 @@ String TextServerAdvanced::get_name() const { return interface_name; } +uint32_t TextServerAdvanced::get_features() const { + return interface_features; +} + void TextServerAdvanced::free(RID p_rid) { _THREAD_SAFE_METHOD_ if (font_owner.owns(p_rid)) { @@ -394,9 +398,23 @@ bool TextServerAdvanced::load_support_data(const String &p_filename) { return true; } -#ifdef TOOLS_ENABLED +String TextServerAdvanced::get_support_data_filename() const { +#ifdef ICU_STATIC_DATA + return _MKSTR(ICU_DATA_NAME); +#else + return String(); +#endif +} -bool TextServerAdvanced::save_support_data(const String &p_filename) { +String TextServerAdvanced::get_support_data_info() const { +#ifdef ICU_STATIC_DATA + return String("ICU break iteration data (") + _MKSTR(ICU_DATA_NAME) + String(")."); +#else + return String(); +#endif +} + +bool TextServerAdvanced::save_support_data(const String &p_filename) const { _THREAD_SAFE_METHOD_ #ifdef ICU_STATIC_DATA @@ -415,9 +433,7 @@ bool TextServerAdvanced::save_support_data(const String &p_filename) { #endif } -#endif - -bool TextServerAdvanced::is_locale_right_to_left(const String &p_locale) { +bool TextServerAdvanced::is_locale_right_to_left(const String &p_locale) const { String l = p_locale.get_slicec('_', 0); if ((l == "ar") || (l == "dv") || (l == "he") || (l == "fa") || (l == "ff") || (l == "ku") || (l == "ur")) { return true; @@ -1142,7 +1158,7 @@ _FORCE_INLINE_ bool TextServerAdvanced::_ensure_glyph(FontDataAdvanced *p_font_d int error = FT_Load_Glyph(fd->face, p_glyph, flags); if (error) { fd->glyph_map[p_glyph] = FontGlyph(); - ERR_FAIL_V_MSG(false, "FreeType: Failed to load glyph."); + return false; } if (!outline) { @@ -1236,7 +1252,7 @@ _FORCE_INLINE_ bool TextServerAdvanced::_ensure_cache_for_size(FontDataAdvanced fd->oversampling = 1.0f; fd->size.x = p_font_data->msdf_source_size; } else if (p_font_data->oversampling <= 0.0f) { - fd->oversampling = TS->font_get_global_oversampling(); + fd->oversampling = font_get_global_oversampling(); } else { fd->oversampling = p_font_data->oversampling; } @@ -1244,13 +1260,13 @@ _FORCE_INLINE_ bool TextServerAdvanced::_ensure_cache_for_size(FontDataAdvanced if (FT_HAS_COLOR(fd->face) && fd->face->num_fixed_sizes > 0) { int best_match = 0; int diff = ABS(fd->size.x - ((int64_t)fd->face->available_sizes[0].width)); - fd->scale = real_t(fd->size.x * fd->oversampling) / fd->face->available_sizes[0].width; + fd->scale = float(fd->size.x * fd->oversampling) / fd->face->available_sizes[0].width; for (int i = 1; i < fd->face->num_fixed_sizes; i++) { int ndiff = ABS(fd->size.x - ((int64_t)fd->face->available_sizes[i].width)); if (ndiff < diff) { best_match = i; diff = ndiff; - fd->scale = real_t(fd->size.x * fd->oversampling) / fd->face->available_sizes[i].width; + fd->scale = float(fd->size.x * fd->oversampling) / fd->face->available_sizes[i].width; } } FT_Select_Size(fd->face, best_match); @@ -1585,8 +1601,8 @@ _FORCE_INLINE_ bool TextServerAdvanced::_ensure_cache_for_size(FontDataAdvanced } _FORCE_INLINE_ void TextServerAdvanced::_font_clear_cache(FontDataAdvanced *p_font_data) { - for (const Map<Vector2i, FontDataForSizeAdvanced *>::Element *E = p_font_data->cache.front(); E; E = E->next()) { - memdelete(E->get()); + for (const KeyValue<Vector2i, FontDataForSizeAdvanced *> &E : p_font_data->cache) { + memdelete(E.value); } p_font_data->cache.clear(); p_font_data->face_init = false; @@ -1786,7 +1802,7 @@ Dictionary TextServerAdvanced::font_get_variation_coordinates(RID p_font_rid) co return fd->variation_coordinates; } -void TextServerAdvanced::font_set_oversampling(RID p_font_rid, real_t p_oversampling) { +void TextServerAdvanced::font_set_oversampling(RID p_font_rid, float p_oversampling) { FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); @@ -1797,7 +1813,7 @@ void TextServerAdvanced::font_set_oversampling(RID p_font_rid, real_t p_oversamp } } -real_t TextServerAdvanced::font_get_oversampling(RID p_font_rid) const { +float TextServerAdvanced::font_get_oversampling(RID p_font_rid) const { FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, 0.f); @@ -1822,8 +1838,8 @@ void TextServerAdvanced::font_clear_size_cache(RID p_font_rid) { ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); - for (const Map<Vector2i, FontDataForSizeAdvanced *>::Element *E = fd->cache.front(); E; E = E->next()) { - memdelete(E->get()); + for (const KeyValue<Vector2i, FontDataForSizeAdvanced *> &E : fd->cache) { + memdelete(E.value); } fd->cache.clear(); } @@ -1839,7 +1855,7 @@ void TextServerAdvanced::font_remove_size_cache(RID p_font_rid, const Vector2i & } } -void TextServerAdvanced::font_set_ascent(RID p_font_rid, int p_size, real_t p_ascent) { +void TextServerAdvanced::font_set_ascent(RID p_font_rid, int p_size, float p_ascent) { FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); @@ -1850,7 +1866,7 @@ void TextServerAdvanced::font_set_ascent(RID p_font_rid, int p_size, real_t p_as fd->cache[size]->ascent = p_ascent; } -real_t TextServerAdvanced::font_get_ascent(RID p_font_rid, int p_size) const { +float TextServerAdvanced::font_get_ascent(RID p_font_rid, int p_size) const { FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, 0.f); @@ -1860,13 +1876,13 @@ real_t TextServerAdvanced::font_get_ascent(RID p_font_rid, int p_size) const { ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), 0.f); if (fd->msdf) { - return fd->cache[size]->ascent * (real_t)p_size / (real_t)fd->msdf_source_size; + return fd->cache[size]->ascent * (float)p_size / (float)fd->msdf_source_size; } else { return fd->cache[size]->ascent; } } -void TextServerAdvanced::font_set_descent(RID p_font_rid, int p_size, real_t p_descent) { +void TextServerAdvanced::font_set_descent(RID p_font_rid, int p_size, float p_descent) { FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); @@ -1876,7 +1892,7 @@ void TextServerAdvanced::font_set_descent(RID p_font_rid, int p_size, real_t p_d fd->cache[size]->descent = p_descent; } -real_t TextServerAdvanced::font_get_descent(RID p_font_rid, int p_size) const { +float TextServerAdvanced::font_get_descent(RID p_font_rid, int p_size) const { FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, 0.f); @@ -1886,13 +1902,13 @@ real_t TextServerAdvanced::font_get_descent(RID p_font_rid, int p_size) const { ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), 0.f); if (fd->msdf) { - return fd->cache[size]->descent * (real_t)p_size / (real_t)fd->msdf_source_size; + return fd->cache[size]->descent * (float)p_size / (float)fd->msdf_source_size; } else { return fd->cache[size]->descent; } } -void TextServerAdvanced::font_set_underline_position(RID p_font_rid, int p_size, real_t p_underline_position) { +void TextServerAdvanced::font_set_underline_position(RID p_font_rid, int p_size, float p_underline_position) { FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); @@ -1903,7 +1919,7 @@ void TextServerAdvanced::font_set_underline_position(RID p_font_rid, int p_size, fd->cache[size]->underline_position = p_underline_position; } -real_t TextServerAdvanced::font_get_underline_position(RID p_font_rid, int p_size) const { +float TextServerAdvanced::font_get_underline_position(RID p_font_rid, int p_size) const { FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, 0.f); @@ -1913,13 +1929,13 @@ real_t TextServerAdvanced::font_get_underline_position(RID p_font_rid, int p_siz ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), 0.f); if (fd->msdf) { - return fd->cache[size]->underline_position * (real_t)p_size / (real_t)fd->msdf_source_size; + return fd->cache[size]->underline_position * (float)p_size / (float)fd->msdf_source_size; } else { return fd->cache[size]->underline_position; } } -void TextServerAdvanced::font_set_underline_thickness(RID p_font_rid, int p_size, real_t p_underline_thickness) { +void TextServerAdvanced::font_set_underline_thickness(RID p_font_rid, int p_size, float p_underline_thickness) { FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); @@ -1930,7 +1946,7 @@ void TextServerAdvanced::font_set_underline_thickness(RID p_font_rid, int p_size fd->cache[size]->underline_thickness = p_underline_thickness; } -real_t TextServerAdvanced::font_get_underline_thickness(RID p_font_rid, int p_size) const { +float TextServerAdvanced::font_get_underline_thickness(RID p_font_rid, int p_size) const { FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, 0.f); @@ -1940,13 +1956,13 @@ real_t TextServerAdvanced::font_get_underline_thickness(RID p_font_rid, int p_si ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), 0.f); if (fd->msdf) { - return fd->cache[size]->underline_thickness * (real_t)p_size / (real_t)fd->msdf_source_size; + return fd->cache[size]->underline_thickness * (float)p_size / (float)fd->msdf_source_size; } else { return fd->cache[size]->underline_thickness; } } -void TextServerAdvanced::font_set_scale(RID p_font_rid, int p_size, real_t p_scale) { +void TextServerAdvanced::font_set_scale(RID p_font_rid, int p_size, float p_scale) { FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); @@ -1957,7 +1973,7 @@ void TextServerAdvanced::font_set_scale(RID p_font_rid, int p_size, real_t p_sca fd->cache[size]->scale = p_scale; } -real_t TextServerAdvanced::font_get_scale(RID p_font_rid, int p_size) const { +float TextServerAdvanced::font_get_scale(RID p_font_rid, int p_size) const { FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, 0.f); @@ -1967,7 +1983,7 @@ real_t TextServerAdvanced::font_get_scale(RID p_font_rid, int p_size) const { ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), 0.f); if (fd->msdf) { - return fd->cache[size]->scale * (real_t)p_size / (real_t)fd->msdf_source_size; + return fd->cache[size]->scale * (float)p_size / (float)fd->msdf_source_size; } else { return fd->cache[size]->scale / fd->cache[size]->oversampling; } @@ -2006,14 +2022,14 @@ int TextServerAdvanced::font_get_spacing(RID p_font_rid, int p_size, TextServer: switch (p_spacing) { case TextServer::SPACING_GLYPH: { if (fd->msdf) { - return fd->cache[size]->spacing_glyph * (real_t)p_size / (real_t)fd->msdf_source_size; + return fd->cache[size]->spacing_glyph * (float)p_size / (float)fd->msdf_source_size; } else { return fd->cache[size]->spacing_glyph; } } break; case TextServer::SPACING_SPACE: { if (fd->msdf) { - return fd->cache[size]->spacing_space * (real_t)p_size / (real_t)fd->msdf_source_size; + return fd->cache[size]->spacing_space * (float)p_size / (float)fd->msdf_source_size; } else { return fd->cache[size]->spacing_space; } @@ -2182,7 +2198,7 @@ Vector2 TextServerAdvanced::font_get_glyph_advance(RID p_font_rid, int p_size, i const HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map; if (fd->msdf) { - return gl[p_glyph].advance * (real_t)p_size / (real_t)fd->msdf_source_size; + return gl[p_glyph].advance * (float)p_size / (float)fd->msdf_source_size; } else { return gl[p_glyph].advance; } @@ -2218,7 +2234,7 @@ Vector2 TextServerAdvanced::font_get_glyph_offset(RID p_font_rid, const Vector2i const HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map; if (fd->msdf) { - return gl[p_glyph].rect.position * (real_t)p_size.x / (real_t)fd->msdf_source_size; + return gl[p_glyph].rect.position * (float)p_size.x / (float)fd->msdf_source_size; } else { return gl[p_glyph].rect.position; } @@ -2254,7 +2270,7 @@ Vector2 TextServerAdvanced::font_get_glyph_size(RID p_font_rid, const Vector2i & const HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map; if (fd->msdf) { - return gl[p_glyph].rect.size * (real_t)p_size.x / (real_t)fd->msdf_source_size; + return gl[p_glyph].rect.size * (float)p_size.x / (float)fd->msdf_source_size; } else { return gl[p_glyph].rect.size; } @@ -2337,38 +2353,46 @@ void TextServerAdvanced::font_set_glyph_texture_idx(RID p_font_rid, const Vector gl[p_glyph].found = true; } -bool TextServerAdvanced::font_get_glyph_contours(RID p_font_rid, int p_size, int32_t p_index, Vector<Vector3> &r_points, Vector<int32_t> &r_contours, bool &r_orientation) const { +Dictionary TextServerAdvanced::font_get_glyph_contours(RID p_font_rid, int p_size, int32_t p_index) const { FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, false); + ERR_FAIL_COND_V(!fd, Dictionary()); MutexLock lock(fd->mutex); Vector2i size = _get_size(fd, p_size); - ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), false); + ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), Dictionary()); + Vector<Vector3> points; + Vector<int32_t> contours; + bool orientation; #ifdef MODULE_FREETYPE_ENABLED int error = FT_Load_Glyph(fd->cache[size]->face, p_index, FT_LOAD_NO_BITMAP | (fd->force_autohinter ? FT_LOAD_FORCE_AUTOHINT : 0)); - ERR_FAIL_COND_V(error, false); + ERR_FAIL_COND_V(error, Dictionary()); - r_points.clear(); - r_contours.clear(); + points.clear(); + contours.clear(); - real_t h = fd->cache[size]->ascent; - real_t scale = (1.0 / 64.0) / fd->cache[size]->oversampling * fd->cache[size]->scale; + float h = fd->cache[size]->ascent; + float scale = (1.0 / 64.0) / fd->cache[size]->oversampling * fd->cache[size]->scale; if (fd->msdf) { - scale = scale * (real_t)p_size / (real_t)fd->msdf_source_size; + scale = scale * (float)p_size / (float)fd->msdf_source_size; } for (short i = 0; i < fd->cache[size]->face->glyph->outline.n_points; i++) { - r_points.push_back(Vector3(fd->cache[size]->face->glyph->outline.points[i].x * scale, h - fd->cache[size]->face->glyph->outline.points[i].y * scale, FT_CURVE_TAG(fd->cache[size]->face->glyph->outline.tags[i]))); + points.push_back(Vector3(fd->cache[size]->face->glyph->outline.points[i].x * scale, h - fd->cache[size]->face->glyph->outline.points[i].y * scale, FT_CURVE_TAG(fd->cache[size]->face->glyph->outline.tags[i]))); } for (short i = 0; i < fd->cache[size]->face->glyph->outline.n_contours; i++) { - r_contours.push_back(fd->cache[size]->face->glyph->outline.contours[i]); + contours.push_back(fd->cache[size]->face->glyph->outline.contours[i]); } - r_orientation = (FT_Outline_Get_Orientation(&fd->cache[size]->face->glyph->outline) == FT_ORIENTATION_FILL_RIGHT); + orientation = (FT_Outline_Get_Orientation(&fd->cache[size]->face->glyph->outline) == FT_ORIENTATION_FILL_RIGHT); #else - return false; + return Dictionary(); #endif - return true; + + Dictionary out; + out["points"] = points; + out["contours"] = contours; + out["orientation"] = orientation; + return out; } Array TextServerAdvanced::font_get_kerning_list(RID p_font_rid, int p_size) const { @@ -2433,7 +2457,7 @@ Vector2 TextServerAdvanced::font_get_kerning(RID p_font_rid, int p_size, const V if (kern.has(p_glyph_pair)) { if (fd->msdf) { - return kern[p_glyph_pair] * (real_t)p_size / (real_t)fd->msdf_source_size; + return kern[p_glyph_pair] * (float)p_size / (float)fd->msdf_source_size; } else { return kern[p_glyph_pair]; } @@ -2443,7 +2467,7 @@ Vector2 TextServerAdvanced::font_get_kerning(RID p_font_rid, int p_size, const V FT_Vector delta; FT_Get_Kerning(fd->cache[size]->face, p_glyph_pair.x, p_glyph_pair.y, FT_KERNING_DEFAULT, &delta); if (fd->msdf) { - return Vector2(delta.x, delta.y) * (real_t)p_size / (real_t)fd->msdf_source_size; + return Vector2(delta.x, delta.y) * (float)p_size / (float)fd->msdf_source_size; } else { return Vector2(delta.x, delta.y); } @@ -2582,8 +2606,8 @@ void TextServerAdvanced::font_draw_glyph(RID p_font_rid, RID p_canvas, int p_siz RID texture = fd->cache[size]->textures[gl.texture_idx].texture->get_rid(); if (fd->msdf) { Point2 cpos = p_pos; - cpos += gl.rect.position * (real_t)p_size / (real_t)fd->msdf_source_size; - Size2 csize = gl.rect.size * (real_t)p_size / (real_t)fd->msdf_source_size; + cpos += gl.rect.position * (float)p_size / (float)fd->msdf_source_size; + Size2 csize = gl.rect.size * (float)p_size / (float)fd->msdf_source_size; RenderingServer::get_singleton()->canvas_item_add_msdf_texture_rect_region(p_canvas, Rect2(cpos, csize), texture, gl.uv_rect, modulate, 0, fd->msdf_range); } else { Point2i cpos = p_pos; @@ -2622,8 +2646,8 @@ void TextServerAdvanced::font_draw_glyph_outline(RID p_font_rid, RID p_canvas, i RID texture = fd->cache[size]->textures[gl.texture_idx].texture->get_rid(); if (fd->msdf) { Point2 cpos = p_pos; - cpos += gl.rect.position * (real_t)p_size / (real_t)fd->msdf_source_size; - Size2 csize = gl.rect.size * (real_t)p_size / (real_t)fd->msdf_source_size; + cpos += gl.rect.position * (float)p_size / (float)fd->msdf_source_size; + Size2 csize = gl.rect.size * (float)p_size / (float)fd->msdf_source_size; RenderingServer::get_singleton()->canvas_item_add_msdf_texture_rect_region(p_canvas, Rect2(cpos, csize), texture, gl.uv_rect, modulate, p_outline_size * 2, fd->msdf_range); } else { Point2i cpos = p_pos; @@ -2678,8 +2702,8 @@ Vector<String> TextServerAdvanced::font_get_language_support_overrides(RID p_fon MutexLock lock(fd->mutex); Vector<String> out; - for (const Map<String, bool>::Element *E = fd->language_support_overrides.front(); E; E = E->next()) { - out.push_back(E->key()); + for (const KeyValue<String, bool> &E : fd->language_support_overrides) { + out.push_back(E.key); } return out; } @@ -2694,7 +2718,7 @@ bool TextServerAdvanced::font_is_script_supported(RID p_font_rid, const String & } else { Vector2i size = _get_size(fd, 16); ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), false); - return fd->supported_scripts.has(TS->name_to_tag(p_script)); + return fd->supported_scripts.has(hb_tag_from_string(p_script.ascii().get_data(), -1)); } } @@ -2754,11 +2778,11 @@ Dictionary TextServerAdvanced::font_supported_variation_list(RID p_font_rid) con return fd->supported_varaitions; } -real_t TextServerAdvanced::font_get_global_oversampling() const { +float TextServerAdvanced::font_get_global_oversampling() const { return oversampling; } -void TextServerAdvanced::font_set_global_oversampling(real_t p_oversampling) { +void TextServerAdvanced::font_set_global_oversampling(float p_oversampling) { _THREAD_SAFE_METHOD_ if (oversampling != p_oversampling) { oversampling = p_oversampling; @@ -2839,9 +2863,9 @@ void TextServerAdvanced::invalidate(TextServerAdvanced::ShapedTextDataAdvanced * void TextServerAdvanced::full_copy(ShapedTextDataAdvanced *p_shaped) { ShapedTextDataAdvanced *parent = shaped_owner.get_or_null(p_shaped->parent); - for (Map<Variant, ShapedTextData::EmbeddedObject>::Element *E = parent->objects.front(); E; E = E->next()) { - if (E->get().pos >= p_shaped->start && E->get().pos < p_shaped->end) { - p_shaped->objects[E->key()] = E->get(); + for (const KeyValue<Variant, ShapedTextData::EmbeddedObject> &E : parent->objects) { + if (E.value.pos >= p_shaped->start && E.value.pos < p_shaped->end) { + p_shaped->objects[E.key] = E.value; } } @@ -2904,7 +2928,7 @@ TextServer::Direction TextServerAdvanced::shaped_text_get_direction(RID p_shaped return sd->direction; } -void TextServerAdvanced::shaped_text_set_bidi_override(RID p_shaped, const Vector<Vector2i> &p_override) { +void TextServerAdvanced::shaped_text_set_bidi_override(RID p_shaped, const Array &p_override) { ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND(!sd); @@ -2912,7 +2936,10 @@ void TextServerAdvanced::shaped_text_set_bidi_override(RID p_shaped, const Vecto if (sd->parent != RID()) { full_copy(sd); } - sd->bidi_override = p_override; + sd->bidi_override.clear(); + for (int i = 0; i < p_override.size(); i++) { + sd->bidi_override.push_back(p_override[i]); + } invalidate(sd); } @@ -3065,9 +3092,9 @@ bool TextServerAdvanced::shaped_text_resize_object(RID p_shaped, Variant p_key, Glyph gl = sd->glyphs[i]; Variant key; if (gl.count == 1) { - for (Map<Variant, ShapedTextData::EmbeddedObject>::Element *E = sd->objects.front(); E; E = E->next()) { - if (E->get().pos == gl.start) { - key = E->key(); + for (const KeyValue<Variant, ShapedTextData::EmbeddedObject> &E : sd->objects) { + if (E.value.pos == gl.start) { + key = E.key; break; } } @@ -3096,8 +3123,7 @@ bool TextServerAdvanced::shaped_text_resize_object(RID p_shaped, Variant p_key, } else if (sd->preserve_invalid || (sd->preserve_control && is_control(gl.index))) { // Glyph not found, replace with hex code box. if (sd->orientation == ORIENTATION_HORIZONTAL) { - sd->ascent = MAX(sd->ascent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).y * 0.75f)); - sd->descent = MAX(sd->descent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).y * 0.25f)); + sd->ascent = MAX(sd->ascent, get_hex_code_box_size(gl.font_size, gl.index).y); } else { sd->ascent = MAX(sd->ascent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).x * 0.5f)); sd->descent = MAX(sd->descent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).x * 0.5f)); @@ -3108,66 +3134,66 @@ bool TextServerAdvanced::shaped_text_resize_object(RID p_shaped, Variant p_key, } // Align embedded objects to baseline. - real_t full_ascent = sd->ascent; - real_t full_descent = sd->descent; - for (Map<Variant, ShapedTextData::EmbeddedObject>::Element *E = sd->objects.front(); E; E = E->next()) { - if ((E->get().pos >= sd->start) && (E->get().pos < sd->end)) { + float full_ascent = sd->ascent; + float full_descent = sd->descent; + for (KeyValue<Variant, ShapedTextData::EmbeddedObject> &E : sd->objects) { + if ((E.value.pos >= sd->start) && (E.value.pos < sd->end)) { if (sd->orientation == ORIENTATION_HORIZONTAL) { - switch (E->get().inline_align & INLINE_ALIGN_TEXT_MASK) { + switch (E.value.inline_align & INLINE_ALIGN_TEXT_MASK) { case INLINE_ALIGN_TO_TOP: { - E->get().rect.position.y = -sd->ascent; + E.value.rect.position.y = -sd->ascent; } break; case INLINE_ALIGN_TO_CENTER: { - E->get().rect.position.y = (-sd->ascent + sd->descent) / 2; + E.value.rect.position.y = (-sd->ascent + sd->descent) / 2; } break; case INLINE_ALIGN_TO_BASELINE: { - E->get().rect.position.y = 0; + E.value.rect.position.y = 0; } break; case INLINE_ALIGN_TO_BOTTOM: { - E->get().rect.position.y = sd->descent; + E.value.rect.position.y = sd->descent; } break; } - switch (E->get().inline_align & INLINE_ALIGN_IMAGE_MASK) { + switch (E.value.inline_align & INLINE_ALIGN_IMAGE_MASK) { case INLINE_ALIGN_BOTTOM_TO: { - E->get().rect.position.y -= E->get().rect.size.y; + E.value.rect.position.y -= E.value.rect.size.y; } break; case INLINE_ALIGN_CENTER_TO: { - E->get().rect.position.y -= E->get().rect.size.y / 2; + E.value.rect.position.y -= E.value.rect.size.y / 2; } break; case INLINE_ALIGN_TOP_TO: { //NOP } break; } - full_ascent = MAX(full_ascent, -E->get().rect.position.y); - full_descent = MAX(full_descent, E->get().rect.position.y + E->get().rect.size.y); + full_ascent = MAX(full_ascent, -E.value.rect.position.y); + full_descent = MAX(full_descent, E.value.rect.position.y + E.value.rect.size.y); } else { - switch (E->get().inline_align & INLINE_ALIGN_TEXT_MASK) { + switch (E.value.inline_align & INLINE_ALIGN_TEXT_MASK) { case INLINE_ALIGN_TO_TOP: { - E->get().rect.position.x = -sd->ascent; + E.value.rect.position.x = -sd->ascent; } break; case INLINE_ALIGN_TO_CENTER: { - E->get().rect.position.x = (-sd->ascent + sd->descent) / 2; + E.value.rect.position.x = (-sd->ascent + sd->descent) / 2; } break; case INLINE_ALIGN_TO_BASELINE: { - E->get().rect.position.x = 0; + E.value.rect.position.x = 0; } break; case INLINE_ALIGN_TO_BOTTOM: { - E->get().rect.position.x = sd->descent; + E.value.rect.position.x = sd->descent; } break; } - switch (E->get().inline_align & INLINE_ALIGN_IMAGE_MASK) { + switch (E.value.inline_align & INLINE_ALIGN_IMAGE_MASK) { case INLINE_ALIGN_BOTTOM_TO: { - E->get().rect.position.x -= E->get().rect.size.x; + E.value.rect.position.x -= E.value.rect.size.x; } break; case INLINE_ALIGN_CENTER_TO: { - E->get().rect.position.x -= E->get().rect.size.x / 2; + E.value.rect.position.x -= E.value.rect.size.x / 2; } break; case INLINE_ALIGN_TOP_TO: { //NOP } break; } - full_ascent = MAX(full_ascent, -E->get().rect.position.x); - full_descent = MAX(full_descent, E->get().rect.position.x + E->get().rect.size.x); + full_ascent = MAX(full_ascent, -E.value.rect.position.x); + full_descent = MAX(full_descent, E.value.rect.position.x + E.value.rect.size.x); } } } @@ -3254,11 +3280,11 @@ RID TextServerAdvanced::shaped_text_substr(RID p_shaped, int p_start, int p_leng Variant key; bool find_embedded = false; if (gl.count == 1) { - for (Map<Variant, ShapedTextData::EmbeddedObject>::Element *E = sd->objects.front(); E; E = E->next()) { - if (E->get().pos == gl.start) { + for (const KeyValue<Variant, ShapedTextData::EmbeddedObject> &E : sd->objects) { + if (E.value.pos == gl.start) { find_embedded = true; - key = E->key(); - new_sd->objects[key] = E->get(); + key = E.key; + new_sd->objects[key] = E.value; break; } } @@ -3283,8 +3309,7 @@ RID TextServerAdvanced::shaped_text_substr(RID p_shaped, int p_start, int p_leng } else if (new_sd->preserve_invalid || (new_sd->preserve_control && is_control(gl.index))) { // Glyph not found, replace with hex code box. if (new_sd->orientation == ORIENTATION_HORIZONTAL) { - new_sd->ascent = MAX(new_sd->ascent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).y * 0.75f)); - new_sd->descent = MAX(new_sd->descent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).y * 0.25f)); + new_sd->ascent = MAX(new_sd->ascent, get_hex_code_box_size(gl.font_size, gl.index).y); } else { new_sd->ascent = MAX(new_sd->ascent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).x * 0.5f)); new_sd->descent = MAX(new_sd->descent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).x * 0.5f)); @@ -3299,66 +3324,66 @@ RID TextServerAdvanced::shaped_text_substr(RID p_shaped, int p_start, int p_leng } // Align embedded objects to baseline. - real_t full_ascent = new_sd->ascent; - real_t full_descent = new_sd->descent; - for (Map<Variant, ShapedTextData::EmbeddedObject>::Element *E = new_sd->objects.front(); E; E = E->next()) { - if ((E->get().pos >= new_sd->start) && (E->get().pos < new_sd->end)) { + float full_ascent = new_sd->ascent; + float full_descent = new_sd->descent; + for (KeyValue<Variant, ShapedTextData::EmbeddedObject> &E : new_sd->objects) { + if ((E.value.pos >= new_sd->start) && (E.value.pos < new_sd->end)) { if (sd->orientation == ORIENTATION_HORIZONTAL) { - switch (E->get().inline_align & INLINE_ALIGN_TEXT_MASK) { + switch (E.value.inline_align & INLINE_ALIGN_TEXT_MASK) { case INLINE_ALIGN_TO_TOP: { - E->get().rect.position.y = -new_sd->ascent; + E.value.rect.position.y = -new_sd->ascent; } break; case INLINE_ALIGN_TO_CENTER: { - E->get().rect.position.y = (-new_sd->ascent + new_sd->descent) / 2; + E.value.rect.position.y = (-new_sd->ascent + new_sd->descent) / 2; } break; case INLINE_ALIGN_TO_BASELINE: { - E->get().rect.position.y = 0; + E.value.rect.position.y = 0; } break; case INLINE_ALIGN_TO_BOTTOM: { - E->get().rect.position.y = new_sd->descent; + E.value.rect.position.y = new_sd->descent; } break; } - switch (E->get().inline_align & INLINE_ALIGN_IMAGE_MASK) { + switch (E.value.inline_align & INLINE_ALIGN_IMAGE_MASK) { case INLINE_ALIGN_BOTTOM_TO: { - E->get().rect.position.y -= E->get().rect.size.y; + E.value.rect.position.y -= E.value.rect.size.y; } break; case INLINE_ALIGN_CENTER_TO: { - E->get().rect.position.y -= E->get().rect.size.y / 2; + E.value.rect.position.y -= E.value.rect.size.y / 2; } break; case INLINE_ALIGN_TOP_TO: { //NOP } break; } - full_ascent = MAX(full_ascent, -E->get().rect.position.y); - full_descent = MAX(full_descent, E->get().rect.position.y + E->get().rect.size.y); + full_ascent = MAX(full_ascent, -E.value.rect.position.y); + full_descent = MAX(full_descent, E.value.rect.position.y + E.value.rect.size.y); } else { - switch (E->get().inline_align & INLINE_ALIGN_TEXT_MASK) { + switch (E.value.inline_align & INLINE_ALIGN_TEXT_MASK) { case INLINE_ALIGN_TO_TOP: { - E->get().rect.position.x = -new_sd->ascent; + E.value.rect.position.x = -new_sd->ascent; } break; case INLINE_ALIGN_TO_CENTER: { - E->get().rect.position.x = (-new_sd->ascent + new_sd->descent) / 2; + E.value.rect.position.x = (-new_sd->ascent + new_sd->descent) / 2; } break; case INLINE_ALIGN_TO_BASELINE: { - E->get().rect.position.x = 0; + E.value.rect.position.x = 0; } break; case INLINE_ALIGN_TO_BOTTOM: { - E->get().rect.position.x = new_sd->descent; + E.value.rect.position.x = new_sd->descent; } break; } - switch (E->get().inline_align & INLINE_ALIGN_IMAGE_MASK) { + switch (E.value.inline_align & INLINE_ALIGN_IMAGE_MASK) { case INLINE_ALIGN_BOTTOM_TO: { - E->get().rect.position.x -= E->get().rect.size.x; + E.value.rect.position.x -= E.value.rect.size.x; } break; case INLINE_ALIGN_CENTER_TO: { - E->get().rect.position.x -= E->get().rect.size.x / 2; + E.value.rect.position.x -= E.value.rect.size.x / 2; } break; case INLINE_ALIGN_TOP_TO: { //NOP } break; } - full_ascent = MAX(full_ascent, -E->get().rect.position.x); - full_descent = MAX(full_descent, E->get().rect.position.x + E->get().rect.size.x); + full_ascent = MAX(full_ascent, -E.value.rect.position.x); + full_descent = MAX(full_descent, E.value.rect.position.x + E.value.rect.size.x); } } } @@ -3378,7 +3403,7 @@ RID TextServerAdvanced::shaped_text_get_parent(RID p_shaped) const { return sd->parent; } -real_t TextServerAdvanced::shaped_text_fit_to_width(RID p_shaped, real_t p_width, uint8_t /*JustificationFlag*/ p_jst_flags) { +float TextServerAdvanced::shaped_text_fit_to_width(RID p_shaped, float p_width, uint16_t /*JustificationFlag*/ p_jst_flags) { ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, 0.f); @@ -3419,7 +3444,7 @@ real_t TextServerAdvanced::shaped_text_fit_to_width(RID p_shaped, real_t p_width } } - real_t justification_width; + float justification_width; if ((p_jst_flags & JUSTIFICATION_CONSTRAIN_ELLIPSIS) == JUSTIFICATION_CONSTRAIN_ELLIPSIS) { if (sd->overrun_trim_data.trim_pos >= 0) { start_pos = sd->overrun_trim_data.trim_pos; @@ -3459,7 +3484,7 @@ real_t TextServerAdvanced::shaped_text_fit_to_width(RID p_shaped, real_t p_width } if ((elongation_count > 0) && ((p_jst_flags & JUSTIFICATION_KASHIDA) == JUSTIFICATION_KASHIDA)) { - real_t delta_width_per_kashida = (p_width - justification_width) / elongation_count; + float delta_width_per_kashida = (p_width - justification_width) / elongation_count; for (int i = start_pos; i <= end_pos; i++) { Glyph &gl = sd->glyphs.write[i]; if (gl.count > 0) { @@ -3474,15 +3499,15 @@ real_t TextServerAdvanced::shaped_text_fit_to_width(RID p_shaped, real_t p_width } } } - real_t adv_remain = 0; + float adv_remain = 0; if ((space_count > 0) && ((p_jst_flags & JUSTIFICATION_WORD_BOUND) == JUSTIFICATION_WORD_BOUND)) { - real_t delta_width_per_space = (p_width - justification_width) / space_count; + float delta_width_per_space = (p_width - justification_width) / space_count; for (int i = start_pos; i <= end_pos; i++) { Glyph &gl = sd->glyphs.write[i]; if (gl.count > 0) { if ((gl.flags & GRAPHEME_IS_SPACE) == GRAPHEME_IS_SPACE) { - real_t old_adv = gl.advance; - real_t new_advance; + float old_adv = gl.advance; + float new_advance; if ((gl.flags & GRAPHEME_IS_VIRTUAL) == GRAPHEME_IS_VIRTUAL) { new_advance = MAX(gl.advance + delta_width_per_space, 0.f); } else { @@ -3514,7 +3539,7 @@ real_t TextServerAdvanced::shaped_text_fit_to_width(RID p_shaped, real_t p_width return sd->width; } -real_t TextServerAdvanced::shaped_text_tab_align(RID p_shaped, const Vector<real_t> &p_tab_stops) { +float TextServerAdvanced::shaped_text_tab_align(RID p_shaped, const PackedFloat32Array &p_tab_stops) { ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, 0.f); @@ -3527,7 +3552,7 @@ real_t TextServerAdvanced::shaped_text_tab_align(RID p_shaped, const Vector<real } int tab_index = 0; - real_t off = 0.f; + float off = 0.f; int start, end, delta; if (sd->para_direction == DIRECTION_LTR) { @@ -3544,7 +3569,7 @@ real_t TextServerAdvanced::shaped_text_tab_align(RID p_shaped, const Vector<real for (int i = start; i != end; i += delta) { if ((gl[i].flags & GRAPHEME_IS_TAB) == GRAPHEME_IS_TAB) { - real_t tab_off = 0.f; + float tab_off = 0.f; while (tab_off <= off) { tab_off += p_tab_stops[tab_index]; tab_index++; @@ -3552,7 +3577,7 @@ real_t TextServerAdvanced::shaped_text_tab_align(RID p_shaped, const Vector<real tab_index = 0; } } - real_t old_adv = gl[i].advance; + float old_adv = gl[i].advance; gl[i].advance = tab_off - off; sd->width += gl[i].advance - old_adv; off = 0; @@ -3564,7 +3589,7 @@ real_t TextServerAdvanced::shaped_text_tab_align(RID p_shaped, const Vector<real return 0.f; } -void TextServerAdvanced::shaped_text_overrun_trim_to_width(RID p_shaped_line, real_t p_width, uint8_t p_trim_flags) { +void TextServerAdvanced::shaped_text_overrun_trim_to_width(RID p_shaped_line, float p_width, uint16_t p_trim_flags) { ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped_line); ERR_FAIL_COND_MSG(!sd, "ShapedTextDataAdvanced invalid."); @@ -3607,7 +3632,7 @@ void TextServerAdvanced::shaped_text_overrun_trim_to_width(RID p_shaped_line, re } int ell_min_characters = 6; - real_t width = sd->width; + float width = sd->width; bool is_rtl = sd->direction == DIRECTION_RTL || (sd->direction == DIRECTION_AUTO && sd->para_direction == DIRECTION_RTL); @@ -3663,7 +3688,7 @@ void TextServerAdvanced::shaped_text_overrun_trim_to_width(RID p_shaped_line, re if (add_ellipsis && (ellipsis_pos > 0 || enforce_ellipsis)) { // Insert an additional space when cutting word bound for aesthetics. if (cut_per_word && (ellipsis_pos > 0)) { - TextServer::Glyph gl; + Glyph gl; gl.count = 1; gl.advance = whitespace_adv.x; gl.index = whitespace_gl_idx; @@ -3674,7 +3699,7 @@ void TextServerAdvanced::shaped_text_overrun_trim_to_width(RID p_shaped_line, re sd->overrun_trim_data.ellipsis_glyph_buf.append(gl); } // Add ellipsis dots. - TextServer::Glyph gl; + Glyph gl; gl.count = 1; gl.repeat = 3; gl.advance = dot_adv.x; @@ -3691,12 +3716,36 @@ void TextServerAdvanced::shaped_text_overrun_trim_to_width(RID p_shaped_line, re } } -TextServer::TrimData TextServerAdvanced::shaped_text_get_trim_data(RID p_shaped) const { +int TextServerAdvanced::shaped_text_get_trim_pos(RID p_shaped) const { + ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); + ERR_FAIL_COND_V_MSG(!sd, -1, "ShapedTextDataAdvanced invalid."); + + MutexLock lock(sd->mutex); + return sd->overrun_trim_data.trim_pos; +} + +int TextServerAdvanced::shaped_text_get_ellipsis_pos(RID p_shaped) const { ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); - ERR_FAIL_COND_V_MSG(!sd, TrimData(), "ShapedTextDataAdvanced invalid."); + ERR_FAIL_COND_V_MSG(!sd, -1, "ShapedTextDataAdvanced invalid."); MutexLock lock(sd->mutex); - return sd->overrun_trim_data; + return sd->overrun_trim_data.ellipsis_pos; +} + +const Glyph *TextServerAdvanced::shaped_text_get_ellipsis_glyphs(RID p_shaped) const { + ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); + ERR_FAIL_COND_V_MSG(!sd, nullptr, "ShapedTextDataAdvanced invalid."); + + MutexLock lock(sd->mutex); + return sd->overrun_trim_data.ellipsis_glyph_buf.ptr(); +} + +int TextServerAdvanced::shaped_text_get_ellipsis_glyph_count(RID p_shaped) const { + ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); + ERR_FAIL_COND_V_MSG(!sd, 0, "ShapedTextDataAdvanced invalid."); + + MutexLock lock(sd->mutex); + return sd->overrun_trim_data.ellipsis_glyph_buf.size(); } bool TextServerAdvanced::shaped_text_update_breaks(RID p_shaped) { @@ -3783,7 +3832,7 @@ bool TextServerAdvanced::shaped_text_update_breaks(RID p_shaped) { if (is_whitespace(c)) { sd_glyphs[i].flags |= GRAPHEME_IS_BREAK_SOFT; } else { - TextServer::Glyph gl; + Glyph gl; gl.start = sd_glyphs[i].start; gl.end = sd_glyphs[i].end; gl.count = 1; @@ -3964,7 +4013,7 @@ bool TextServerAdvanced::shaped_text_update_justification_ops(RID p_shaped) { sd->glyphs.write[i].flags |= GRAPHEME_IS_ELONGATION; } else { if (sd->glyphs[i].font_rid != RID()) { - TextServer::Glyph gl = _shape_single_glyph(sd, 0x0640, HB_SCRIPT_ARABIC, HB_DIRECTION_RTL, sd->glyphs[i].font_rid, sd->glyphs[i].font_size); + Glyph gl = _shape_single_glyph(sd, 0x0640, HB_SCRIPT_ARABIC, HB_DIRECTION_RTL, sd->glyphs[i].font_rid, sd->glyphs[i].font_size); if ((gl.flags & GRAPHEME_IS_VALID) == GRAPHEME_IS_VALID) { gl.start = sd->glyphs[i].start; gl.end = sd->glyphs[i].end; @@ -3982,7 +4031,7 @@ bool TextServerAdvanced::shaped_text_update_justification_ops(RID p_shaped) { } } } else if (!is_whitespace(c)) { - TextServer::Glyph gl; + Glyph gl; gl.start = sd->glyphs[i].start; gl.end = sd->glyphs[i].end; gl.count = 1; @@ -4007,9 +4056,9 @@ bool TextServerAdvanced::shaped_text_update_justification_ops(RID p_shaped) { return sd->justification_ops_valid; } -TextServer::Glyph TextServerAdvanced::_shape_single_glyph(ShapedTextDataAdvanced *p_sd, char32_t p_char, hb_script_t p_script, hb_direction_t p_direction, RID p_font, int p_font_size) { +Glyph TextServerAdvanced::_shape_single_glyph(ShapedTextDataAdvanced *p_sd, char32_t p_char, hb_script_t p_script, hb_direction_t p_direction, RID p_font, int p_font_size) { hb_font_t *hb_font = _font_get_hb_handle(p_font, p_font_size); - ERR_FAIL_COND_V(hb_font == nullptr, TextServer::Glyph()); + ERR_FAIL_COND_V(hb_font == nullptr, Glyph()); hb_buffer_clear_contents(p_sd->hb_buffer); hb_buffer_set_direction(p_sd->hb_buffer, p_direction); @@ -4024,7 +4073,7 @@ TextServer::Glyph TextServerAdvanced::_shape_single_glyph(ShapedTextDataAdvanced hb_glyph_position_t *glyph_pos = hb_buffer_get_glyph_positions(p_sd->hb_buffer, &glyph_count); // Process glyphs. - TextServer::Glyph gl; + Glyph gl; if (p_direction == HB_DIRECTION_RTL || p_direction == HB_DIRECTION_BTT) { gl.flags |= TextServer::GRAPHEME_IS_RTL; @@ -4034,7 +4083,7 @@ TextServer::Glyph TextServerAdvanced::_shape_single_glyph(ShapedTextDataAdvanced gl.font_size = p_font_size; if (glyph_count > 0) { - real_t scale = font_get_scale(p_font, p_font_size); + float scale = font_get_scale(p_font, p_font_size); if (p_sd->orientation == ORIENTATION_HORIZONTAL) { gl.advance = Math::round(glyph_pos[0].x_advance / (64.0 / scale)); } else { @@ -4059,7 +4108,7 @@ void TextServerAdvanced::_shape_run(ShapedTextDataAdvanced *p_sd, int32_t p_star // Add fallback glyphs. for (int i = p_start; i < p_end; i++) { if (p_sd->preserve_invalid || (p_sd->preserve_control && is_control(p_sd->text[i]))) { - TextServer::Glyph gl; + Glyph gl; gl.start = i; gl.end = i + 1; gl.count = 1; @@ -4071,8 +4120,7 @@ void TextServerAdvanced::_shape_run(ShapedTextDataAdvanced *p_sd, int32_t p_star } if (p_sd->orientation == ORIENTATION_HORIZONTAL) { gl.advance = get_hex_code_box_size(fs, gl.index).x; - p_sd->ascent = MAX(p_sd->ascent, Math::round(get_hex_code_box_size(fs, gl.index).y * 0.75f)); - p_sd->descent = MAX(p_sd->descent, Math::round(get_hex_code_box_size(fs, gl.index).y * 0.25f)); + p_sd->ascent = MAX(p_sd->ascent, get_hex_code_box_size(fs, gl.index).y); } else { gl.advance = get_hex_code_box_size(fs, gl.index).y; p_sd->ascent = MAX(p_sd->ascent, Math::round(get_hex_code_box_size(fs, gl.index).x * 0.5f)); @@ -4126,7 +4174,7 @@ void TextServerAdvanced::_shape_run(ShapedTextDataAdvanced *p_sd, int32_t p_star // Process glyphs. if (glyph_count > 0) { - TextServer::Glyph *w = (TextServer::Glyph *)memalloc(glyph_count * sizeof(TextServer::Glyph)); + Glyph *w = (Glyph *)memalloc(glyph_count * sizeof(Glyph)); int end = (p_direction == HB_DIRECTION_RTL || p_direction == HB_DIRECTION_BTT) ? p_end : 0; uint32_t last_cluster_id = UINT32_MAX; @@ -4155,8 +4203,8 @@ void TextServerAdvanced::_shape_run(ShapedTextDataAdvanced *p_sd, int32_t p_star last_cluster_id = glyph_info[i].cluster; - TextServer::Glyph &gl = w[i]; - gl = TextServer::Glyph(); + Glyph &gl = w[i]; + gl = Glyph(); gl.start = glyph_info[i].cluster; gl.end = end; @@ -4171,7 +4219,7 @@ void TextServerAdvanced::_shape_run(ShapedTextDataAdvanced *p_sd, int32_t p_star gl.index = glyph_info[i].codepoint; if (gl.index != 0) { - real_t scale = font_get_scale(f, fs); + float scale = font_get_scale(f, fs); if (p_sd->orientation == ORIENTATION_HORIZONTAL) { gl.advance = Math::round(glyph_pos[i].x_advance / (64.0 / scale)); } else { @@ -4411,65 +4459,65 @@ bool TextServerAdvanced::shaped_text_shape(RID p_shaped) { } // Align embedded objects to baseline. - real_t full_ascent = sd->ascent; - real_t full_descent = sd->descent; - for (Map<Variant, ShapedTextData::EmbeddedObject>::Element *E = sd->objects.front(); E; E = E->next()) { + float full_ascent = sd->ascent; + float full_descent = sd->descent; + for (KeyValue<Variant, ShapedTextData::EmbeddedObject> &E : sd->objects) { if (sd->orientation == ORIENTATION_HORIZONTAL) { - switch (E->get().inline_align & INLINE_ALIGN_TEXT_MASK) { + switch (E.value.inline_align & INLINE_ALIGN_TEXT_MASK) { case INLINE_ALIGN_TO_TOP: { - E->get().rect.position.y = -sd->ascent; + E.value.rect.position.y = -sd->ascent; } break; case INLINE_ALIGN_TO_CENTER: { - E->get().rect.position.y = (-sd->ascent + sd->descent) / 2; + E.value.rect.position.y = (-sd->ascent + sd->descent) / 2; } break; case INLINE_ALIGN_TO_BASELINE: { - E->get().rect.position.y = 0; + E.value.rect.position.y = 0; } break; case INLINE_ALIGN_TO_BOTTOM: { - E->get().rect.position.y = sd->descent; + E.value.rect.position.y = sd->descent; } break; } - switch (E->get().inline_align & INLINE_ALIGN_IMAGE_MASK) { + switch (E.value.inline_align & INLINE_ALIGN_IMAGE_MASK) { case INLINE_ALIGN_BOTTOM_TO: { - E->get().rect.position.y -= E->get().rect.size.y; + E.value.rect.position.y -= E.value.rect.size.y; } break; case INLINE_ALIGN_CENTER_TO: { - E->get().rect.position.y -= E->get().rect.size.y / 2; + E.value.rect.position.y -= E.value.rect.size.y / 2; } break; case INLINE_ALIGN_TOP_TO: { //NOP } break; } - full_ascent = MAX(full_ascent, -E->get().rect.position.y); - full_descent = MAX(full_descent, E->get().rect.position.y + E->get().rect.size.y); + full_ascent = MAX(full_ascent, -E.value.rect.position.y); + full_descent = MAX(full_descent, E.value.rect.position.y + E.value.rect.size.y); } else { - switch (E->get().inline_align & INLINE_ALIGN_TEXT_MASK) { + switch (E.value.inline_align & INLINE_ALIGN_TEXT_MASK) { case INLINE_ALIGN_TO_TOP: { - E->get().rect.position.x = -sd->ascent; + E.value.rect.position.x = -sd->ascent; } break; case INLINE_ALIGN_TO_CENTER: { - E->get().rect.position.x = (-sd->ascent + sd->descent) / 2; + E.value.rect.position.x = (-sd->ascent + sd->descent) / 2; } break; case INLINE_ALIGN_TO_BASELINE: { - E->get().rect.position.x = 0; + E.value.rect.position.x = 0; } break; case INLINE_ALIGN_TO_BOTTOM: { - E->get().rect.position.x = sd->descent; + E.value.rect.position.x = sd->descent; } break; } - switch (E->get().inline_align & INLINE_ALIGN_IMAGE_MASK) { + switch (E.value.inline_align & INLINE_ALIGN_IMAGE_MASK) { case INLINE_ALIGN_BOTTOM_TO: { - E->get().rect.position.x -= E->get().rect.size.x; + E.value.rect.position.x -= E.value.rect.size.x; } break; case INLINE_ALIGN_CENTER_TO: { - E->get().rect.position.x -= E->get().rect.size.x / 2; + E.value.rect.position.x -= E.value.rect.size.x / 2; } break; case INLINE_ALIGN_TOP_TO: { //NOP } break; } - full_ascent = MAX(full_ascent, -E->get().rect.position.x); - full_descent = MAX(full_descent, E->get().rect.position.x + E->get().rect.size.x); + full_ascent = MAX(full_ascent, -E.value.rect.position.x); + full_descent = MAX(full_descent, E.value.rect.position.x + E.value.rect.size.x); } } sd->ascent = full_ascent; @@ -4486,28 +4534,31 @@ bool TextServerAdvanced::shaped_text_is_ready(RID p_shaped) const { return sd->valid; } -Vector<TextServer::Glyph> TextServerAdvanced::shaped_text_get_glyphs(RID p_shaped) const { +const Glyph *TextServerAdvanced::shaped_text_get_glyphs(RID p_shaped) const { const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); - ERR_FAIL_COND_V(!sd, Vector<TextServer::Glyph>()); + ERR_FAIL_COND_V(!sd, nullptr); MutexLock lock(sd->mutex); if (!sd->valid) { const_cast<TextServerAdvanced *>(this)->shaped_text_shape(p_shaped); } - return sd->glyphs; + return sd->glyphs.ptr(); } -Vector2i TextServerAdvanced::shaped_text_get_range(RID p_shaped) const { +int TextServerAdvanced::shaped_text_get_glyph_count(RID p_shaped) const { const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); - ERR_FAIL_COND_V(!sd, Vector2i()); + ERR_FAIL_COND_V(!sd, 0); MutexLock lock(sd->mutex); - return Vector2(sd->start, sd->end); + if (!sd->valid) { + const_cast<TextServerAdvanced *>(this)->shaped_text_shape(p_shaped); + } + return sd->glyphs.size(); } -Vector<TextServer::Glyph> TextServerAdvanced::shaped_text_sort_logical(RID p_shaped) { +const Glyph *TextServerAdvanced::shaped_text_sort_logical(RID p_shaped) { ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); - ERR_FAIL_COND_V(!sd, Vector<TextServer::Glyph>()); + ERR_FAIL_COND_V(!sd, nullptr); MutexLock lock(sd->mutex); if (!sd->valid) { @@ -4516,11 +4567,19 @@ Vector<TextServer::Glyph> TextServerAdvanced::shaped_text_sort_logical(RID p_sha if (!sd->sort_valid) { sd->glyphs_logical = sd->glyphs; - sd->glyphs_logical.sort_custom<TextServer::GlyphCompare>(); + sd->glyphs_logical.sort_custom<GlyphCompare>(); sd->sort_valid = true; } - return sd->glyphs_logical; + return sd->glyphs_logical.ptr(); +} + +Vector2i TextServerAdvanced::shaped_text_get_range(RID p_shaped) const { + const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); + ERR_FAIL_COND_V(!sd, Vector2i()); + + MutexLock lock(sd->mutex); + return Vector2(sd->start, sd->end); } Array TextServerAdvanced::shaped_text_get_objects(RID p_shaped) const { @@ -4529,8 +4588,8 @@ Array TextServerAdvanced::shaped_text_get_objects(RID p_shaped) const { ERR_FAIL_COND_V(!sd, ret); MutexLock lock(sd->mutex); - for (const Map<Variant, ShapedTextData::EmbeddedObject>::Element *E = sd->objects.front(); E; E = E->next()) { - ret.push_back(E->key()); + for (const KeyValue<Variant, ShapedTextData::EmbeddedObject> &E : sd->objects) { + ret.push_back(E.key); } return ret; @@ -4563,7 +4622,7 @@ Size2 TextServerAdvanced::shaped_text_get_size(RID p_shaped) const { } } -real_t TextServerAdvanced::shaped_text_get_ascent(RID p_shaped) const { +float TextServerAdvanced::shaped_text_get_ascent(RID p_shaped) const { const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, 0.f); @@ -4574,7 +4633,7 @@ real_t TextServerAdvanced::shaped_text_get_ascent(RID p_shaped) const { return sd->ascent; } -real_t TextServerAdvanced::shaped_text_get_descent(RID p_shaped) const { +float TextServerAdvanced::shaped_text_get_descent(RID p_shaped) const { const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, 0.f); @@ -4585,7 +4644,7 @@ real_t TextServerAdvanced::shaped_text_get_descent(RID p_shaped) const { return sd->descent; } -real_t TextServerAdvanced::shaped_text_get_width(RID p_shaped) const { +float TextServerAdvanced::shaped_text_get_width(RID p_shaped) const { const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, 0.f); @@ -4596,7 +4655,7 @@ real_t TextServerAdvanced::shaped_text_get_width(RID p_shaped) const { return (sd->text_trimmed ? sd->width_trimmed : sd->width); } -real_t TextServerAdvanced::shaped_text_get_underline_position(RID p_shaped) const { +float TextServerAdvanced::shaped_text_get_underline_position(RID p_shaped) const { const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, 0.f); @@ -4608,7 +4667,7 @@ real_t TextServerAdvanced::shaped_text_get_underline_position(RID p_shaped) cons return sd->upos; } -real_t TextServerAdvanced::shaped_text_get_underline_thickness(RID p_shaped) const { +float TextServerAdvanced::shaped_text_get_underline_thickness(RID p_shaped) const { const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, 0.f); @@ -4752,15 +4811,6 @@ String TextServerAdvanced::percent_sign(const String &p_language) const { return "%"; } -TextServer *TextServerAdvanced::create_func(Error &r_error, void *p_user_data) { - r_error = OK; - return memnew(TextServerAdvanced()); -} - -void TextServerAdvanced::register_server() { - TextServerManager::register_create_function(interface_name, interface_features, create_func, nullptr); -} - TextServerAdvanced::TextServerAdvanced() { _insert_num_systems_lang(); _insert_feature_sets(); diff --git a/modules/text_server_adv/text_server_adv.h b/modules/text_server_adv/text_server_adv.h index fc0e7a09a7..1feeada76d 100644 --- a/modules/text_server_adv/text_server_adv.h +++ b/modules/text_server_adv/text_server_adv.h @@ -115,12 +115,12 @@ class TextServerAdvanced : public TextServer { }; struct FontDataForSizeAdvanced { - real_t ascent = 0.f; - real_t descent = 0.f; - real_t underline_position = 0.f; - real_t underline_thickness = 0.f; - real_t scale = 1.f; - real_t oversampling = 1.f; + float ascent = 0.f; + float descent = 0.f; + float underline_position = 0.f; + float underline_thickness = 0.f; + float scale = 1.f; + float oversampling = 1.f; int spacing_glyph = 0; int spacing_space = 0; @@ -161,7 +161,7 @@ class TextServerAdvanced : public TextServer { bool force_autohinter = false; TextServer::Hinting hinting = TextServer::HINTING_LIGHT; Dictionary variation_coordinates; - real_t oversampling = 0.f; + float oversampling = 0.f; Map<Vector2i, FontDataForSizeAdvanced *> cache; @@ -245,14 +245,14 @@ class TextServerAdvanced : public TextServer { // Common data. - real_t oversampling = 1.f; + float oversampling = 1.f; mutable RID_PtrOwner<FontDataAdvanced> font_owner; mutable RID_PtrOwner<ShapedTextDataAdvanced> shaped_owner; int _convert_pos(const ShapedTextDataAdvanced *p_sd, int p_pos) const; int _convert_pos_inv(const ShapedTextDataAdvanced *p_sd, int p_pos) const; void _shape_run(ShapedTextDataAdvanced *p_sd, int32_t p_start, int32_t p_end, hb_script_t p_script, hb_direction_t p_direction, Vector<RID> p_fonts, int p_span, int p_fb_index); - TextServer::Glyph _shape_single_glyph(ShapedTextDataAdvanced *p_sd, char32_t p_char, hb_script_t p_script, hb_direction_t p_direction, RID p_font, int p_font_size); + Glyph _shape_single_glyph(ShapedTextDataAdvanced *p_sd, char32_t p_char, hb_script_t p_script, hb_direction_t p_direction, RID p_font, int p_font_size); // HarfBuzz bitmap font interface. @@ -284,20 +284,19 @@ protected: void invalidate(ShapedTextDataAdvanced *p_shaped); public: - virtual bool has_feature(Feature p_feature) override; + virtual bool has_feature(Feature p_feature) const override; virtual String get_name() const override; + virtual uint32_t get_features() const override; virtual void free(RID p_rid) override; virtual bool has(RID p_rid) override; virtual bool load_support_data(const String &p_filename) override; -#ifdef TOOLS_ENABLED - virtual String get_support_data_filename() override { return _MKSTR(ICU_DATA_NAME); }; - virtual String get_support_data_info() override { return String("ICU break iteration data (") + _MKSTR(ICU_DATA_NAME) + String(")."); }; - virtual bool save_support_data(const String &p_filename) override; -#endif + virtual String get_support_data_filename() const override; + virtual String get_support_data_info() const override; + virtual bool save_support_data(const String &p_filename) const override; - virtual bool is_locale_right_to_left(const String &p_locale) override; + virtual bool is_locale_right_to_left(const String &p_locale) const override; virtual int32_t name_to_tag(const String &p_name) const override; virtual String tag_to_name(int32_t p_tag) const override; @@ -332,8 +331,8 @@ public: virtual void font_set_variation_coordinates(RID p_font_rid, const Dictionary &p_variation_coordinates) override; virtual Dictionary font_get_variation_coordinates(RID p_font_rid) const override; - virtual void font_set_oversampling(RID p_font_rid, real_t p_oversampling) override; - virtual real_t font_get_oversampling(RID p_font_rid) const override; + virtual void font_set_oversampling(RID p_font_rid, float p_oversampling) override; + virtual float font_get_oversampling(RID p_font_rid) const override; virtual Array font_get_size_cache_list(RID p_font_rid) const override; virtual void font_clear_size_cache(RID p_font_rid) override; @@ -341,20 +340,20 @@ public: hb_font_t *_font_get_hb_handle(RID p_font, int p_font_size) const; - virtual void font_set_ascent(RID p_font_rid, int p_size, real_t p_ascent) override; - virtual real_t font_get_ascent(RID p_font_rid, int p_size) const override; + virtual void font_set_ascent(RID p_font_rid, int p_size, float p_ascent) override; + virtual float font_get_ascent(RID p_font_rid, int p_size) const override; - virtual void font_set_descent(RID p_font_rid, int p_size, real_t p_descent) override; - virtual real_t font_get_descent(RID p_font_rid, int p_size) const override; + virtual void font_set_descent(RID p_font_rid, int p_size, float p_descent) override; + virtual float font_get_descent(RID p_font_rid, int p_size) const override; - virtual void font_set_underline_position(RID p_font_rid, int p_size, real_t p_underline_position) override; - virtual real_t font_get_underline_position(RID p_font_rid, int p_size) const override; + virtual void font_set_underline_position(RID p_font_rid, int p_size, float p_underline_position) override; + virtual float font_get_underline_position(RID p_font_rid, int p_size) const override; - virtual void font_set_underline_thickness(RID p_font_rid, int p_size, real_t p_underline_thickness) override; - virtual real_t font_get_underline_thickness(RID p_font_rid, int p_size) const override; + virtual void font_set_underline_thickness(RID p_font_rid, int p_size, float p_underline_thickness) override; + virtual float font_get_underline_thickness(RID p_font_rid, int p_size) const override; - virtual void font_set_scale(RID p_font_rid, int p_size, real_t p_scale) override; - virtual real_t font_get_scale(RID p_font_rid, int p_size) const override; + virtual void font_set_scale(RID p_font_rid, int p_size, float p_scale) override; + virtual float font_get_scale(RID p_font_rid, int p_size) const override; virtual void font_set_spacing(RID p_font_rid, int p_size, SpacingType p_spacing, int p_value) override; virtual int font_get_spacing(RID p_font_rid, int p_size, SpacingType p_spacing) const override; @@ -388,7 +387,7 @@ public: virtual int font_get_glyph_texture_idx(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph) const override; virtual void font_set_glyph_texture_idx(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph, int p_texture_idx) override; - virtual bool font_get_glyph_contours(RID p_font, int p_size, int32_t p_index, Vector<Vector3> &r_points, Vector<int32_t> &r_contours, bool &r_orientation) const override; + virtual Dictionary font_get_glyph_contours(RID p_font, int p_size, int32_t p_index) const override; virtual Array font_get_kerning_list(RID p_font_rid, int p_size) const override; virtual void font_clear_kerning_map(RID p_font_rid, int p_size) override; @@ -423,8 +422,8 @@ public: virtual Dictionary font_supported_feature_list(RID p_font_rid) const override; virtual Dictionary font_supported_variation_list(RID p_font_rid) const override; - virtual real_t font_get_global_oversampling() const override; - virtual void font_set_global_oversampling(real_t p_oversampling) override; + virtual float font_get_global_oversampling() const override; + virtual void font_set_global_oversampling(float p_oversampling) override; /* Shaped text buffer interface */ @@ -435,7 +434,7 @@ public: virtual void shaped_text_set_direction(RID p_shaped, Direction p_direction = DIRECTION_AUTO) override; virtual Direction shaped_text_get_direction(RID p_shaped) const override; - virtual void shaped_text_set_bidi_override(RID p_shaped, const Vector<Vector2i> &p_override) override; + virtual void shaped_text_set_bidi_override(RID p_shaped, const Array &p_override) override; virtual void shaped_text_set_orientation(RID p_shaped, Orientation p_orientation = ORIENTATION_HORIZONTAL) override; virtual Orientation shaped_text_get_orientation(RID p_shaped) const override; @@ -453,41 +452,42 @@ public: virtual RID shaped_text_substr(RID p_shaped, int p_start, int p_length) const override; virtual RID shaped_text_get_parent(RID p_shaped) const override; - virtual real_t shaped_text_fit_to_width(RID p_shaped, real_t p_width, uint8_t /*JustificationFlag*/ p_jst_flags = JUSTIFICATION_WORD_BOUND | JUSTIFICATION_KASHIDA) override; - virtual real_t shaped_text_tab_align(RID p_shaped, const Vector<real_t> &p_tab_stops) override; + virtual float shaped_text_fit_to_width(RID p_shaped, float p_width, uint16_t /*JustificationFlag*/ p_jst_flags = JUSTIFICATION_WORD_BOUND | JUSTIFICATION_KASHIDA) override; + virtual float shaped_text_tab_align(RID p_shaped, const PackedFloat32Array &p_tab_stops) override; virtual bool shaped_text_shape(RID p_shaped) override; virtual bool shaped_text_update_breaks(RID p_shaped) override; virtual bool shaped_text_update_justification_ops(RID p_shaped) override; - virtual void shaped_text_overrun_trim_to_width(RID p_shaped, real_t p_width, uint8_t p_trim_flags) override; - virtual TrimData shaped_text_get_trim_data(RID p_shaped) const override; + virtual int shaped_text_get_trim_pos(RID p_shaped) const override; + virtual int shaped_text_get_ellipsis_pos(RID p_shaped) const override; + virtual const Glyph *shaped_text_get_ellipsis_glyphs(RID p_shaped) const override; + virtual int shaped_text_get_ellipsis_glyph_count(RID p_shaped) const override; + + virtual void shaped_text_overrun_trim_to_width(RID p_shaped, float p_width, uint16_t p_trim_flags) override; virtual bool shaped_text_is_ready(RID p_shaped) const override; - virtual Vector<Glyph> shaped_text_get_glyphs(RID p_shaped) const override; + virtual const Glyph *shaped_text_get_glyphs(RID p_shaped) const override; + virtual const Glyph *shaped_text_sort_logical(RID p_shaped) override; + virtual int shaped_text_get_glyph_count(RID p_shaped) const override; virtual Vector2i shaped_text_get_range(RID p_shaped) const override; - virtual Vector<Glyph> shaped_text_sort_logical(RID p_shaped) override; - virtual Array shaped_text_get_objects(RID p_shaped) const override; virtual Rect2 shaped_text_get_object_rect(RID p_shaped, Variant p_key) const override; virtual Size2 shaped_text_get_size(RID p_shaped) const override; - virtual real_t shaped_text_get_ascent(RID p_shaped) const override; - virtual real_t shaped_text_get_descent(RID p_shaped) const override; - virtual real_t shaped_text_get_width(RID p_shaped) const override; - virtual real_t shaped_text_get_underline_position(RID p_shaped) const override; - virtual real_t shaped_text_get_underline_thickness(RID p_shaped) const override; + virtual float shaped_text_get_ascent(RID p_shaped) const override; + virtual float shaped_text_get_descent(RID p_shaped) const override; + virtual float shaped_text_get_width(RID p_shaped) const override; + virtual float shaped_text_get_underline_position(RID p_shaped) const override; + virtual float shaped_text_get_underline_thickness(RID p_shaped) const override; virtual String format_number(const String &p_string, const String &p_language = "") const override; virtual String parse_number(const String &p_string, const String &p_language = "") const override; virtual String percent_sign(const String &p_language = "") const override; - static TextServer *create_func(Error &r_error, void *p_user_data); - static void register_server(); - TextServerAdvanced(); ~TextServerAdvanced(); }; diff --git a/modules/text_server_fb/config.py b/modules/text_server_fb/config.py index 7a73080ae9..275c2b4d53 100644 --- a/modules/text_server_fb/config.py +++ b/modules/text_server_fb/config.py @@ -9,3 +9,13 @@ def configure(env): def is_enabled(): # The module is disabled by default. Use module_text_server_fb_enabled=yes to enable it. return False + + +def get_doc_classes(): + return [ + "TextServerFallback", + ] + + +def get_doc_path(): + return "doc_classes" diff --git a/modules/text_server_fb/doc_classes/TextServerFallback.xml b/modules/text_server_fb/doc_classes/TextServerFallback.xml new file mode 100644 index 0000000000..8aadf2b882 --- /dev/null +++ b/modules/text_server_fb/doc_classes/TextServerFallback.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="TextServerFallback" inherits="TextServer" version="4.0"> + <brief_description> + Fallback implementation of the Text Server, without BiDi and complex text layout support. + </brief_description> + <description> + </description> + <tutorials> + </tutorials> +</class> diff --git a/modules/text_server_fb/register_types.cpp b/modules/text_server_fb/register_types.cpp index 87cbd2ac2c..0b59040ce8 100644 --- a/modules/text_server_fb/register_types.cpp +++ b/modules/text_server_fb/register_types.cpp @@ -33,7 +33,12 @@ #include "text_server_fb.h" void preregister_text_server_fb_types() { - TextServerFallback::register_server(); + GDREGISTER_CLASS(TextServerFallback); + if (TextServerManager::get_singleton()) { + Ref<TextServerFallback> ts; + ts.instantiate(); + TextServerManager::get_singleton()->add_interface(ts); + } } void register_text_server_fb_types() { diff --git a/modules/text_server_fb/text_server_fb.cpp b/modules/text_server_fb/text_server_fb.cpp index b1ce85d505..3d868d7be3 100644 --- a/modules/text_server_fb/text_server_fb.cpp +++ b/modules/text_server_fb/text_server_fb.cpp @@ -69,7 +69,7 @@ _FORCE_INLINE_ bool is_underscore(char32_t p_char) { String TextServerFallback::interface_name = "Fallback"; uint32_t TextServerFallback::interface_features = 0; // Nothing is supported. -bool TextServerFallback::has_feature(Feature p_feature) { +bool TextServerFallback::has_feature(Feature p_feature) const { return (interface_features & p_feature) == p_feature; } @@ -77,6 +77,10 @@ String TextServerFallback::get_name() const { return interface_name; } +uint32_t TextServerFallback::get_features() const { + return interface_features; +} + void TextServerFallback::free(RID p_rid) { _THREAD_SAFE_METHOD_ if (font_owner.owns(p_rid)) { @@ -99,15 +103,11 @@ bool TextServerFallback::load_support_data(const String &p_filename) { return false; // No extra data used. } -#ifdef TOOLS_ENABLED - -bool TextServerFallback::save_support_data(const String &p_filename) { +bool TextServerFallback::save_support_data(const String &p_filename) const { return false; // No extra data used. } -#endif - -bool TextServerFallback::is_locale_right_to_left(const String &p_locale) { +bool TextServerFallback::is_locale_right_to_left(const String &p_locale) const { return false; // No RTL support. } @@ -420,7 +420,7 @@ _FORCE_INLINE_ TextServerFallback::FontGlyph TextServerFallback::rasterize_msdf( FontTexture &tex = p_data->textures.write[tex_pos.index]; edgeColoringSimple(shape, 3.0); // Max. angle. - msdfgen::Bitmap<real_t, 4> image(w, h); // Texture size. + msdfgen::Bitmap<float, 4> image(w, h); // Texture size. //msdfgen::generateMTSDF(image, shape, p_pixel_range, 1.0, msdfgen::Vector2(-bounds.l, -bounds.b)); // Range, scale, translation. DistancePixelConversion distancePixelConversion(p_pixel_range); @@ -620,7 +620,7 @@ _FORCE_INLINE_ bool TextServerFallback::_ensure_glyph(FontDataFallback *p_font_d int error = FT_Load_Glyph(fd->face, glyph_index, flags); if (error) { fd->glyph_map[p_glyph] = FontGlyph(); - ERR_FAIL_V_MSG(false, "FreeType: Failed to load glyph."); + return false; } if (!outline) { @@ -714,7 +714,7 @@ _FORCE_INLINE_ bool TextServerFallback::_ensure_cache_for_size(FontDataFallback fd->oversampling = 1.0f; fd->size.x = p_font_data->msdf_source_size; } else if (p_font_data->oversampling <= 0.0f) { - fd->oversampling = TS->font_get_global_oversampling(); + fd->oversampling = font_get_global_oversampling(); } else { fd->oversampling = p_font_data->oversampling; } @@ -722,13 +722,13 @@ _FORCE_INLINE_ bool TextServerFallback::_ensure_cache_for_size(FontDataFallback if (FT_HAS_COLOR(fd->face) && fd->face->num_fixed_sizes > 0) { int best_match = 0; int diff = ABS(fd->size.x - ((int64_t)fd->face->available_sizes[0].width)); - fd->scale = real_t(fd->size.x * fd->oversampling) / fd->face->available_sizes[0].width; + fd->scale = float(fd->size.x * fd->oversampling) / fd->face->available_sizes[0].width; for (int i = 1; i < fd->face->num_fixed_sizes; i++) { int ndiff = ABS(fd->size.x - ((int64_t)fd->face->available_sizes[i].width)); if (ndiff < diff) { best_match = i; diff = ndiff; - fd->scale = real_t(fd->size.x * fd->oversampling) / fd->face->available_sizes[i].width; + fd->scale = float(fd->size.x * fd->oversampling) / fd->face->available_sizes[i].width; } } FT_Select_Size(fd->face, best_match); @@ -769,7 +769,7 @@ _FORCE_INLINE_ bool TextServerFallback::_ensure_cache_for_size(FontDataFallback for (FT_UInt i = 0; i < amaster->num_axis; i++) { // Reset to default. int32_t var_tag = amaster->axis[i].tag; - real_t var_value = (double)amaster->axis[i].def / 65536.f; + float var_value = (double)amaster->axis[i].def / 65536.f; coords.write[i] = amaster->axis[i].def; if (p_font_data->variation_coordinates.has(var_tag)) { @@ -795,8 +795,8 @@ _FORCE_INLINE_ bool TextServerFallback::_ensure_cache_for_size(FontDataFallback } _FORCE_INLINE_ void TextServerFallback::_font_clear_cache(FontDataFallback *p_font_data) { - for (const Map<Vector2i, FontDataForSizeFallback *>::Element *E = p_font_data->cache.front(); E; E = E->next()) { - memdelete(E->get()); + for (const KeyValue<Vector2i, FontDataForSizeFallback *> &E : p_font_data->cache) { + memdelete(E.value); } p_font_data->cache.clear(); @@ -983,7 +983,7 @@ Dictionary TextServerFallback::font_get_variation_coordinates(RID p_font_rid) co return fd->variation_coordinates; } -void TextServerFallback::font_set_oversampling(RID p_font_rid, real_t p_oversampling) { +void TextServerFallback::font_set_oversampling(RID p_font_rid, float p_oversampling) { FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); @@ -994,7 +994,7 @@ void TextServerFallback::font_set_oversampling(RID p_font_rid, real_t p_oversamp } } -real_t TextServerFallback::font_get_oversampling(RID p_font_rid) const { +float TextServerFallback::font_get_oversampling(RID p_font_rid) const { FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, 0.f); @@ -1008,8 +1008,8 @@ Array TextServerFallback::font_get_size_cache_list(RID p_font_rid) const { MutexLock lock(fd->mutex); Array ret; - for (const Map<Vector2i, FontDataForSizeFallback *>::Element *E = fd->cache.front(); E; E = E->next()) { - ret.push_back(E->key()); + for (const KeyValue<Vector2i, FontDataForSizeFallback *> &E : fd->cache) { + ret.push_back(E.key); } return ret; } @@ -1019,8 +1019,8 @@ void TextServerFallback::font_clear_size_cache(RID p_font_rid) { ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); - for (const Map<Vector2i, FontDataForSizeFallback *>::Element *E = fd->cache.front(); E; E = E->next()) { - memdelete(E->get()); + for (const KeyValue<Vector2i, FontDataForSizeFallback *> &E : fd->cache) { + memdelete(E.value); } fd->cache.clear(); } @@ -1036,7 +1036,7 @@ void TextServerFallback::font_remove_size_cache(RID p_font_rid, const Vector2i & } } -void TextServerFallback::font_set_ascent(RID p_font_rid, int p_size, real_t p_ascent) { +void TextServerFallback::font_set_ascent(RID p_font_rid, int p_size, float p_ascent) { FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); @@ -1047,7 +1047,7 @@ void TextServerFallback::font_set_ascent(RID p_font_rid, int p_size, real_t p_as fd->cache[size]->ascent = p_ascent; } -real_t TextServerFallback::font_get_ascent(RID p_font_rid, int p_size) const { +float TextServerFallback::font_get_ascent(RID p_font_rid, int p_size) const { FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, 0.f); @@ -1057,13 +1057,13 @@ real_t TextServerFallback::font_get_ascent(RID p_font_rid, int p_size) const { ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), 0.f); if (fd->msdf) { - return fd->cache[size]->ascent * (real_t)p_size / (real_t)fd->msdf_source_size; + return fd->cache[size]->ascent * (float)p_size / (float)fd->msdf_source_size; } else { return fd->cache[size]->ascent; } } -void TextServerFallback::font_set_descent(RID p_font_rid, int p_size, real_t p_descent) { +void TextServerFallback::font_set_descent(RID p_font_rid, int p_size, float p_descent) { FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); @@ -1073,7 +1073,7 @@ void TextServerFallback::font_set_descent(RID p_font_rid, int p_size, real_t p_d fd->cache[size]->descent = p_descent; } -real_t TextServerFallback::font_get_descent(RID p_font_rid, int p_size) const { +float TextServerFallback::font_get_descent(RID p_font_rid, int p_size) const { FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, 0.f); @@ -1083,13 +1083,13 @@ real_t TextServerFallback::font_get_descent(RID p_font_rid, int p_size) const { ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), 0.f); if (fd->msdf) { - return fd->cache[size]->descent * (real_t)p_size / (real_t)fd->msdf_source_size; + return fd->cache[size]->descent * (float)p_size / (float)fd->msdf_source_size; } else { return fd->cache[size]->descent; } } -void TextServerFallback::font_set_underline_position(RID p_font_rid, int p_size, real_t p_underline_position) { +void TextServerFallback::font_set_underline_position(RID p_font_rid, int p_size, float p_underline_position) { FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); @@ -1100,7 +1100,7 @@ void TextServerFallback::font_set_underline_position(RID p_font_rid, int p_size, fd->cache[size]->underline_position = p_underline_position; } -real_t TextServerFallback::font_get_underline_position(RID p_font_rid, int p_size) const { +float TextServerFallback::font_get_underline_position(RID p_font_rid, int p_size) const { FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, 0.f); @@ -1110,13 +1110,13 @@ real_t TextServerFallback::font_get_underline_position(RID p_font_rid, int p_siz ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), 0.f); if (fd->msdf) { - return fd->cache[size]->underline_position * (real_t)p_size / (real_t)fd->msdf_source_size; + return fd->cache[size]->underline_position * (float)p_size / (float)fd->msdf_source_size; } else { return fd->cache[size]->underline_position; } } -void TextServerFallback::font_set_underline_thickness(RID p_font_rid, int p_size, real_t p_underline_thickness) { +void TextServerFallback::font_set_underline_thickness(RID p_font_rid, int p_size, float p_underline_thickness) { FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); @@ -1127,7 +1127,7 @@ void TextServerFallback::font_set_underline_thickness(RID p_font_rid, int p_size fd->cache[size]->underline_thickness = p_underline_thickness; } -real_t TextServerFallback::font_get_underline_thickness(RID p_font_rid, int p_size) const { +float TextServerFallback::font_get_underline_thickness(RID p_font_rid, int p_size) const { FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, 0.f); @@ -1137,13 +1137,13 @@ real_t TextServerFallback::font_get_underline_thickness(RID p_font_rid, int p_si ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), 0.f); if (fd->msdf) { - return fd->cache[size]->underline_thickness * (real_t)p_size / (real_t)fd->msdf_source_size; + return fd->cache[size]->underline_thickness * (float)p_size / (float)fd->msdf_source_size; } else { return fd->cache[size]->underline_thickness; } } -void TextServerFallback::font_set_scale(RID p_font_rid, int p_size, real_t p_scale) { +void TextServerFallback::font_set_scale(RID p_font_rid, int p_size, float p_scale) { FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); @@ -1154,7 +1154,7 @@ void TextServerFallback::font_set_scale(RID p_font_rid, int p_size, real_t p_sca fd->cache[size]->scale = p_scale; } -real_t TextServerFallback::font_get_scale(RID p_font_rid, int p_size) const { +float TextServerFallback::font_get_scale(RID p_font_rid, int p_size) const { FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, 0.f); @@ -1164,7 +1164,7 @@ real_t TextServerFallback::font_get_scale(RID p_font_rid, int p_size) const { ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), 0.f); if (fd->msdf) { - return fd->cache[size]->scale * (real_t)p_size / (real_t)fd->msdf_source_size; + return fd->cache[size]->scale * (float)p_size / (float)fd->msdf_source_size; } else { return fd->cache[size]->scale / fd->cache[size]->oversampling; } @@ -1203,14 +1203,14 @@ int TextServerFallback::font_get_spacing(RID p_font_rid, int p_size, TextServer: switch (p_spacing) { case TextServer::SPACING_GLYPH: { if (fd->msdf) { - return fd->cache[size]->spacing_glyph * (real_t)p_size / (real_t)fd->msdf_source_size; + return fd->cache[size]->spacing_glyph * (float)p_size / (float)fd->msdf_source_size; } else { return fd->cache[size]->spacing_glyph; } } break; case TextServer::SPACING_SPACE: { if (fd->msdf) { - return fd->cache[size]->spacing_space * (real_t)p_size / (real_t)fd->msdf_source_size; + return fd->cache[size]->spacing_space * (float)p_size / (float)fd->msdf_source_size; } else { return fd->cache[size]->spacing_space; } @@ -1379,7 +1379,7 @@ Vector2 TextServerFallback::font_get_glyph_advance(RID p_font_rid, int p_size, i const HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map; if (fd->msdf) { - return gl[p_glyph].advance * (real_t)p_size / (real_t)fd->msdf_source_size; + return gl[p_glyph].advance * (float)p_size / (float)fd->msdf_source_size; } else { return gl[p_glyph].advance; } @@ -1415,7 +1415,7 @@ Vector2 TextServerFallback::font_get_glyph_offset(RID p_font_rid, const Vector2i const HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map; if (fd->msdf) { - return gl[p_glyph].rect.position * (real_t)p_size.x / (real_t)fd->msdf_source_size; + return gl[p_glyph].rect.position * (float)p_size.x / (float)fd->msdf_source_size; } else { return gl[p_glyph].rect.position; } @@ -1451,7 +1451,7 @@ Vector2 TextServerFallback::font_get_glyph_size(RID p_font_rid, const Vector2i & const HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map; if (fd->msdf) { - return gl[p_glyph].rect.size * (real_t)p_size.x / (real_t)fd->msdf_source_size; + return gl[p_glyph].rect.size * (float)p_size.x / (float)fd->msdf_source_size; } else { return gl[p_glyph].rect.size; } @@ -1534,38 +1534,46 @@ void TextServerFallback::font_set_glyph_texture_idx(RID p_font_rid, const Vector gl[p_glyph].found = true; } -bool TextServerFallback::font_get_glyph_contours(RID p_font_rid, int p_size, int32_t p_index, Vector<Vector3> &r_points, Vector<int32_t> &r_contours, bool &r_orientation) const { +Dictionary TextServerFallback::font_get_glyph_contours(RID p_font_rid, int p_size, int32_t p_index) const { FontDataFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, false); + ERR_FAIL_COND_V(!fd, Dictionary()); MutexLock lock(fd->mutex); Vector2i size = _get_size(fd, p_size); - ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), false); + ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), Dictionary()); + Vector<Vector3> points; + Vector<int32_t> contours; + bool orientation; #ifdef MODULE_FREETYPE_ENABLED int error = FT_Load_Glyph(fd->cache[size]->face, FT_Get_Char_Index(fd->cache[size]->face, p_index), FT_LOAD_NO_BITMAP | (fd->force_autohinter ? FT_LOAD_FORCE_AUTOHINT : 0)); - ERR_FAIL_COND_V(error, false); + ERR_FAIL_COND_V(error, Dictionary()); - r_points.clear(); - r_contours.clear(); + points.clear(); + contours.clear(); - real_t h = fd->cache[size]->ascent; - real_t scale = (1.0 / 64.0) / fd->cache[size]->oversampling * fd->cache[size]->scale; + float h = fd->cache[size]->ascent; + float scale = (1.0 / 64.0) / fd->cache[size]->oversampling * fd->cache[size]->scale; if (fd->msdf) { - scale = scale * (real_t)p_size / (real_t)fd->msdf_source_size; + scale = scale * (float)p_size / (float)fd->msdf_source_size; } for (short i = 0; i < fd->cache[size]->face->glyph->outline.n_points; i++) { - r_points.push_back(Vector3(fd->cache[size]->face->glyph->outline.points[i].x * scale, h - fd->cache[size]->face->glyph->outline.points[i].y * scale, FT_CURVE_TAG(fd->cache[size]->face->glyph->outline.tags[i]))); + points.push_back(Vector3(fd->cache[size]->face->glyph->outline.points[i].x * scale, h - fd->cache[size]->face->glyph->outline.points[i].y * scale, FT_CURVE_TAG(fd->cache[size]->face->glyph->outline.tags[i]))); } for (short i = 0; i < fd->cache[size]->face->glyph->outline.n_contours; i++) { - r_contours.push_back(fd->cache[size]->face->glyph->outline.contours[i]); + contours.push_back(fd->cache[size]->face->glyph->outline.contours[i]); } - r_orientation = (FT_Outline_Get_Orientation(&fd->cache[size]->face->glyph->outline) == FT_ORIENTATION_FILL_RIGHT); + orientation = (FT_Outline_Get_Orientation(&fd->cache[size]->face->glyph->outline) == FT_ORIENTATION_FILL_RIGHT); #else - return false; + return Dictionary(); #endif - return true; + + Dictionary out; + out["points"] = points; + out["contours"] = contours; + out["orientation"] = orientation; + return out; } Array TextServerFallback::font_get_kerning_list(RID p_font_rid, int p_size) const { @@ -1578,8 +1586,8 @@ Array TextServerFallback::font_get_kerning_list(RID p_font_rid, int p_size) cons ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), Array()); Array ret; - for (const Map<Vector2i, Vector2>::Element *E = fd->cache[size]->kerning_map.front(); E; E = E->next()) { - ret.push_back(E->key()); + for (const KeyValue<Vector2i, Vector2> &E : fd->cache[size]->kerning_map) { + ret.push_back(E.key); } return ret; } @@ -1630,7 +1638,7 @@ Vector2 TextServerFallback::font_get_kerning(RID p_font_rid, int p_size, const V if (kern.has(p_glyph_pair)) { if (fd->msdf) { - return kern[p_glyph_pair] * (real_t)p_size / (real_t)fd->msdf_source_size; + return kern[p_glyph_pair] * (float)p_size / (float)fd->msdf_source_size; } else { return kern[p_glyph_pair]; } @@ -1642,7 +1650,7 @@ Vector2 TextServerFallback::font_get_kerning(RID p_font_rid, int p_size, const V int32_t glyph_b = FT_Get_Char_Index(fd->cache[size]->face, p_glyph_pair.y); FT_Get_Kerning(fd->cache[size]->face, glyph_a, glyph_b, FT_KERNING_DEFAULT, &delta); if (fd->msdf) { - return Vector2(delta.x, delta.y) * (real_t)p_size / (real_t)fd->msdf_source_size; + return Vector2(delta.x, delta.y) * (float)p_size / (float)fd->msdf_source_size; } else { return Vector2(delta.x, delta.y); } @@ -1756,8 +1764,8 @@ void TextServerFallback::font_draw_glyph(RID p_font_rid, RID p_canvas, int p_siz RID texture = fd->cache[size]->textures[gl.texture_idx].texture->get_rid(); if (fd->msdf) { Point2 cpos = p_pos; - cpos += gl.rect.position * (real_t)p_size / (real_t)fd->msdf_source_size; - Size2 csize = gl.rect.size * (real_t)p_size / (real_t)fd->msdf_source_size; + cpos += gl.rect.position * (float)p_size / (float)fd->msdf_source_size; + Size2 csize = gl.rect.size * (float)p_size / (float)fd->msdf_source_size; RenderingServer::get_singleton()->canvas_item_add_msdf_texture_rect_region(p_canvas, Rect2(cpos, csize), texture, gl.uv_rect, modulate, 0, fd->msdf_range); } else { Point2i cpos = p_pos; @@ -1796,8 +1804,8 @@ void TextServerFallback::font_draw_glyph_outline(RID p_font_rid, RID p_canvas, i RID texture = fd->cache[size]->textures[gl.texture_idx].texture->get_rid(); if (fd->msdf) { Point2 cpos = p_pos; - cpos += gl.rect.position * (real_t)p_size / (real_t)fd->msdf_source_size; - Size2 csize = gl.rect.size * (real_t)p_size / (real_t)fd->msdf_source_size; + cpos += gl.rect.position * (float)p_size / (float)fd->msdf_source_size; + Size2 csize = gl.rect.size * (float)p_size / (float)fd->msdf_source_size; RenderingServer::get_singleton()->canvas_item_add_msdf_texture_rect_region(p_canvas, Rect2(cpos, csize), texture, gl.uv_rect, modulate, p_outline_size * 2, fd->msdf_range); } else { Point2i cpos = p_pos; @@ -1852,8 +1860,8 @@ Vector<String> TextServerFallback::font_get_language_support_overrides(RID p_fon MutexLock lock(fd->mutex); Vector<String> out; - for (const Map<String, bool>::Element *E = fd->language_support_overrides.front(); E; E = E->next()) { - out.push_back(E->key()); + for (const KeyValue<String, bool> &E : fd->language_support_overrides) { + out.push_back(E.key); } return out; } @@ -1902,8 +1910,8 @@ Vector<String> TextServerFallback::font_get_script_support_overrides(RID p_font_ MutexLock lock(fd->mutex); Vector<String> out; - for (const Map<String, bool>::Element *E = fd->script_support_overrides.front(); E; E = E->next()) { - out.push_back(E->key()); + for (const KeyValue<String, bool> &E : fd->script_support_overrides) { + out.push_back(E.key); } return out; } @@ -1922,11 +1930,11 @@ Dictionary TextServerFallback::font_supported_variation_list(RID p_font_rid) con return fd->supported_varaitions; } -real_t TextServerFallback::font_get_global_oversampling() const { +float TextServerFallback::font_get_global_oversampling() const { return oversampling; } -void TextServerFallback::font_set_global_oversampling(real_t p_oversampling) { +void TextServerFallback::font_set_global_oversampling(float p_oversampling) { _THREAD_SAFE_METHOD_ if (oversampling != p_oversampling) { oversampling = p_oversampling; @@ -1971,9 +1979,9 @@ void TextServerFallback::invalidate(ShapedTextData *p_shaped) { void TextServerFallback::full_copy(ShapedTextData *p_shaped) { ShapedTextData *parent = shaped_owner.get_or_null(p_shaped->parent); - for (Map<Variant, ShapedTextData::EmbeddedObject>::Element *E = parent->objects.front(); E; E = E->next()) { - if (E->get().pos >= p_shaped->start && E->get().pos < p_shaped->end) { - p_shaped->objects[E->key()] = E->get(); + for (const KeyValue<Variant, ShapedTextData::EmbeddedObject> &E : parent->objects) { + if (E.value.pos >= p_shaped->start && E.value.pos < p_shaped->end) { + p_shaped->objects[E.key] = E.value; } } @@ -2037,7 +2045,7 @@ void TextServerFallback::shaped_text_set_orientation(RID p_shaped, TextServer::O } } -void TextServerFallback::shaped_text_set_bidi_override(RID p_shaped, const Vector<Vector2i> &p_override) { +void TextServerFallback::shaped_text_set_bidi_override(RID p_shaped, const Array &p_override) { // No BiDi support, ignore. } @@ -2192,9 +2200,9 @@ bool TextServerFallback::shaped_text_resize_object(RID p_shaped, Variant p_key, Glyph gl = sd->glyphs[i]; Variant key; if (gl.count == 1) { - for (Map<Variant, ShapedTextData::EmbeddedObject>::Element *E = sd->objects.front(); E; E = E->next()) { - if (E->get().pos == gl.start) { - key = E->key(); + for (const KeyValue<Variant, ShapedTextData::EmbeddedObject> &E : sd->objects) { + if (E.value.pos == gl.start) { + key = E.key; break; } } @@ -2223,8 +2231,7 @@ bool TextServerFallback::shaped_text_resize_object(RID p_shaped, Variant p_key, } else if (sd->preserve_invalid || (sd->preserve_control && is_control(gl.index))) { // Glyph not found, replace with hex code box. if (sd->orientation == ORIENTATION_HORIZONTAL) { - sd->ascent = MAX(sd->ascent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).y * 0.75f)); - sd->descent = MAX(sd->descent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).y * 0.25f)); + sd->ascent = MAX(sd->ascent, get_hex_code_box_size(gl.font_size, gl.index).y); } else { sd->ascent = MAX(sd->ascent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).x * 0.5f)); sd->descent = MAX(sd->descent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).x * 0.5f)); @@ -2235,66 +2242,66 @@ bool TextServerFallback::shaped_text_resize_object(RID p_shaped, Variant p_key, } // Align embedded objects to baseline. - real_t full_ascent = sd->ascent; - real_t full_descent = sd->descent; - for (Map<Variant, ShapedTextData::EmbeddedObject>::Element *E = sd->objects.front(); E; E = E->next()) { - if ((E->get().pos >= sd->start) && (E->get().pos < sd->end)) { + float full_ascent = sd->ascent; + float full_descent = sd->descent; + for (KeyValue<Variant, ShapedTextData::EmbeddedObject> &E : sd->objects) { + if ((E.value.pos >= sd->start) && (E.value.pos < sd->end)) { if (sd->orientation == ORIENTATION_HORIZONTAL) { - switch (E->get().inline_align & INLINE_ALIGN_TEXT_MASK) { + switch (E.value.inline_align & INLINE_ALIGN_TEXT_MASK) { case INLINE_ALIGN_TO_TOP: { - E->get().rect.position.y = -sd->ascent; + E.value.rect.position.y = -sd->ascent; } break; case INLINE_ALIGN_TO_CENTER: { - E->get().rect.position.y = (-sd->ascent + sd->descent) / 2; + E.value.rect.position.y = (-sd->ascent + sd->descent) / 2; } break; case INLINE_ALIGN_TO_BASELINE: { - E->get().rect.position.y = 0; + E.value.rect.position.y = 0; } break; case INLINE_ALIGN_TO_BOTTOM: { - E->get().rect.position.y = sd->descent; + E.value.rect.position.y = sd->descent; } break; } - switch (E->get().inline_align & INLINE_ALIGN_IMAGE_MASK) { + switch (E.value.inline_align & INLINE_ALIGN_IMAGE_MASK) { case INLINE_ALIGN_BOTTOM_TO: { - E->get().rect.position.y -= E->get().rect.size.y; + E.value.rect.position.y -= E.value.rect.size.y; } break; case INLINE_ALIGN_CENTER_TO: { - E->get().rect.position.y -= E->get().rect.size.y / 2; + E.value.rect.position.y -= E.value.rect.size.y / 2; } break; case INLINE_ALIGN_TOP_TO: { //NOP } break; } - full_ascent = MAX(full_ascent, -E->get().rect.position.y); - full_descent = MAX(full_descent, E->get().rect.position.y + E->get().rect.size.y); + full_ascent = MAX(full_ascent, -E.value.rect.position.y); + full_descent = MAX(full_descent, E.value.rect.position.y + E.value.rect.size.y); } else { - switch (E->get().inline_align & INLINE_ALIGN_TEXT_MASK) { + switch (E.value.inline_align & INLINE_ALIGN_TEXT_MASK) { case INLINE_ALIGN_TO_TOP: { - E->get().rect.position.x = -sd->ascent; + E.value.rect.position.x = -sd->ascent; } break; case INLINE_ALIGN_TO_CENTER: { - E->get().rect.position.x = (-sd->ascent + sd->descent) / 2; + E.value.rect.position.x = (-sd->ascent + sd->descent) / 2; } break; case INLINE_ALIGN_TO_BASELINE: { - E->get().rect.position.x = 0; + E.value.rect.position.x = 0; } break; case INLINE_ALIGN_TO_BOTTOM: { - E->get().rect.position.x = sd->descent; + E.value.rect.position.x = sd->descent; } break; } - switch (E->get().inline_align & INLINE_ALIGN_IMAGE_MASK) { + switch (E.value.inline_align & INLINE_ALIGN_IMAGE_MASK) { case INLINE_ALIGN_BOTTOM_TO: { - E->get().rect.position.x -= E->get().rect.size.x; + E.value.rect.position.x -= E.value.rect.size.x; } break; case INLINE_ALIGN_CENTER_TO: { - E->get().rect.position.x -= E->get().rect.size.x / 2; + E.value.rect.position.x -= E.value.rect.size.x / 2; } break; case INLINE_ALIGN_TOP_TO: { //NOP } break; } - full_ascent = MAX(full_ascent, -E->get().rect.position.x); - full_descent = MAX(full_descent, E->get().rect.position.x + E->get().rect.size.x); + full_ascent = MAX(full_ascent, -E.value.rect.position.x); + full_descent = MAX(full_descent, E.value.rect.position.x + E.value.rect.size.x); } } } @@ -2344,11 +2351,11 @@ RID TextServerFallback::shaped_text_substr(RID p_shaped, int p_start, int p_leng Variant key; bool find_embedded = false; if (gl.count == 1) { - for (Map<Variant, ShapedTextData::EmbeddedObject>::Element *E = sd->objects.front(); E; E = E->next()) { - if (E->get().pos == gl.start) { + for (const KeyValue<Variant, ShapedTextData::EmbeddedObject> &E : sd->objects) { + if (E.value.pos == gl.start) { find_embedded = true; - key = E->key(); - new_sd->objects[key] = E->get(); + key = E.key; + new_sd->objects[key] = E.value; break; } } @@ -2373,8 +2380,7 @@ RID TextServerFallback::shaped_text_substr(RID p_shaped, int p_start, int p_leng } else if (new_sd->preserve_invalid || (new_sd->preserve_control && is_control(gl.index))) { // Glyph not found, replace with hex code box. if (new_sd->orientation == ORIENTATION_HORIZONTAL) { - new_sd->ascent = MAX(new_sd->ascent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).y * 0.75f)); - new_sd->descent = MAX(new_sd->descent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).y * 0.25f)); + new_sd->ascent = MAX(new_sd->ascent, get_hex_code_box_size(gl.font_size, gl.index).y); } else { new_sd->ascent = MAX(new_sd->ascent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).x * 0.5f)); new_sd->descent = MAX(new_sd->descent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).x * 0.5f)); @@ -2387,66 +2393,66 @@ RID TextServerFallback::shaped_text_substr(RID p_shaped, int p_start, int p_leng } // Align embedded objects to baseline. - real_t full_ascent = new_sd->ascent; - real_t full_descent = new_sd->descent; - for (Map<Variant, ShapedTextData::EmbeddedObject>::Element *E = new_sd->objects.front(); E; E = E->next()) { - if ((E->get().pos >= new_sd->start) && (E->get().pos < new_sd->end)) { + float full_ascent = new_sd->ascent; + float full_descent = new_sd->descent; + for (KeyValue<Variant, ShapedTextData::EmbeddedObject> &E : new_sd->objects) { + if ((E.value.pos >= new_sd->start) && (E.value.pos < new_sd->end)) { if (sd->orientation == ORIENTATION_HORIZONTAL) { - switch (E->get().inline_align & INLINE_ALIGN_TEXT_MASK) { + switch (E.value.inline_align & INLINE_ALIGN_TEXT_MASK) { case INLINE_ALIGN_TO_TOP: { - E->get().rect.position.y = -new_sd->ascent; + E.value.rect.position.y = -new_sd->ascent; } break; case INLINE_ALIGN_TO_CENTER: { - E->get().rect.position.y = (-new_sd->ascent + new_sd->descent) / 2; + E.value.rect.position.y = (-new_sd->ascent + new_sd->descent) / 2; } break; case INLINE_ALIGN_TO_BASELINE: { - E->get().rect.position.y = 0; + E.value.rect.position.y = 0; } break; case INLINE_ALIGN_TO_BOTTOM: { - E->get().rect.position.y = new_sd->descent; + E.value.rect.position.y = new_sd->descent; } break; } - switch (E->get().inline_align & INLINE_ALIGN_IMAGE_MASK) { + switch (E.value.inline_align & INLINE_ALIGN_IMAGE_MASK) { case INLINE_ALIGN_BOTTOM_TO: { - E->get().rect.position.y -= E->get().rect.size.y; + E.value.rect.position.y -= E.value.rect.size.y; } break; case INLINE_ALIGN_CENTER_TO: { - E->get().rect.position.y -= E->get().rect.size.y / 2; + E.value.rect.position.y -= E.value.rect.size.y / 2; } break; case INLINE_ALIGN_TOP_TO: { //NOP } break; } - full_ascent = MAX(full_ascent, -E->get().rect.position.y); - full_descent = MAX(full_descent, E->get().rect.position.y + E->get().rect.size.y); + full_ascent = MAX(full_ascent, -E.value.rect.position.y); + full_descent = MAX(full_descent, E.value.rect.position.y + E.value.rect.size.y); } else { - switch (E->get().inline_align & INLINE_ALIGN_TEXT_MASK) { + switch (E.value.inline_align & INLINE_ALIGN_TEXT_MASK) { case INLINE_ALIGN_TO_TOP: { - E->get().rect.position.x = -new_sd->ascent; + E.value.rect.position.x = -new_sd->ascent; } break; case INLINE_ALIGN_TO_CENTER: { - E->get().rect.position.x = (-new_sd->ascent + new_sd->descent) / 2; + E.value.rect.position.x = (-new_sd->ascent + new_sd->descent) / 2; } break; case INLINE_ALIGN_TO_BASELINE: { - E->get().rect.position.x = 0; + E.value.rect.position.x = 0; } break; case INLINE_ALIGN_TO_BOTTOM: { - E->get().rect.position.x = new_sd->descent; + E.value.rect.position.x = new_sd->descent; } break; } - switch (E->get().inline_align & INLINE_ALIGN_IMAGE_MASK) { + switch (E.value.inline_align & INLINE_ALIGN_IMAGE_MASK) { case INLINE_ALIGN_BOTTOM_TO: { - E->get().rect.position.x -= E->get().rect.size.x; + E.value.rect.position.x -= E.value.rect.size.x; } break; case INLINE_ALIGN_CENTER_TO: { - E->get().rect.position.x -= E->get().rect.size.x / 2; + E.value.rect.position.x -= E.value.rect.size.x / 2; } break; case INLINE_ALIGN_TOP_TO: { //NOP } break; } - full_ascent = MAX(full_ascent, -E->get().rect.position.x); - full_descent = MAX(full_descent, E->get().rect.position.x + E->get().rect.size.x); + full_ascent = MAX(full_ascent, -E.value.rect.position.x); + full_descent = MAX(full_descent, E.value.rect.position.x + E.value.rect.size.x); } } } @@ -2466,7 +2472,7 @@ RID TextServerFallback::shaped_text_get_parent(RID p_shaped) const { return sd->parent; } -real_t TextServerFallback::shaped_text_fit_to_width(RID p_shaped, real_t p_width, uint8_t /*JustificationFlag*/ p_jst_flags) { +float TextServerFallback::shaped_text_fit_to_width(RID p_shaped, float p_width, uint16_t /*JustificationFlag*/ p_jst_flags) { ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, 0.f); @@ -2530,12 +2536,12 @@ real_t TextServerFallback::shaped_text_fit_to_width(RID p_shaped, real_t p_width } if ((space_count > 0) && ((p_jst_flags & JUSTIFICATION_WORD_BOUND) == JUSTIFICATION_WORD_BOUND)) { - real_t delta_width_per_space = (p_width - sd->width) / space_count; + float delta_width_per_space = (p_width - sd->width) / space_count; for (int i = start_pos; i <= end_pos; i++) { Glyph &gl = sd->glyphs.write[i]; if (gl.count > 0) { if ((gl.flags & GRAPHEME_IS_SPACE) == GRAPHEME_IS_SPACE) { - real_t old_adv = gl.advance; + float old_adv = gl.advance; gl.advance = MAX(gl.advance + delta_width_per_space, Math::round(0.1 * gl.font_size)); sd->width += (gl.advance - old_adv); } @@ -2546,7 +2552,7 @@ real_t TextServerFallback::shaped_text_fit_to_width(RID p_shaped, real_t p_width return sd->width; } -real_t TextServerFallback::shaped_text_tab_align(RID p_shaped, const Vector<real_t> &p_tab_stops) { +float TextServerFallback::shaped_text_tab_align(RID p_shaped, const PackedFloat32Array &p_tab_stops) { ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, 0.f); @@ -2559,7 +2565,7 @@ real_t TextServerFallback::shaped_text_tab_align(RID p_shaped, const Vector<real } int tab_index = 0; - real_t off = 0.f; + float off = 0.f; int start, end, delta; if (sd->para_direction == DIRECTION_LTR) { @@ -2576,7 +2582,7 @@ real_t TextServerFallback::shaped_text_tab_align(RID p_shaped, const Vector<real for (int i = start; i != end; i += delta) { if ((gl[i].flags & GRAPHEME_IS_TAB) == GRAPHEME_IS_TAB) { - real_t tab_off = 0.f; + float tab_off = 0.f; while (tab_off <= off) { tab_off += p_tab_stops[tab_index]; tab_index++; @@ -2584,7 +2590,7 @@ real_t TextServerFallback::shaped_text_tab_align(RID p_shaped, const Vector<real tab_index = 0; } } - real_t old_adv = gl[i].advance; + float old_adv = gl[i].advance; gl[i].advance = tab_off - off; sd->width += gl[i].advance - old_adv; off = 0; @@ -2653,7 +2659,7 @@ bool TextServerFallback::shaped_text_update_justification_ops(RID p_shaped) { return true; } -void TextServerFallback::shaped_text_overrun_trim_to_width(RID p_shaped_line, real_t p_width, uint8_t p_trim_flags) { +void TextServerFallback::shaped_text_overrun_trim_to_width(RID p_shaped_line, float p_width, uint16_t p_trim_flags) { ShapedTextData *sd = shaped_owner.get_or_null(p_shaped_line); ERR_FAIL_COND_MSG(!sd, "ShapedTextDataFallback invalid."); @@ -2696,7 +2702,7 @@ void TextServerFallback::shaped_text_overrun_trim_to_width(RID p_shaped_line, re } int ell_min_characters = 6; - real_t width = sd->width; + float width = sd->width; int trim_pos = 0; int ellipsis_pos = (enforce_ellipsis) ? 0 : -1; @@ -2742,7 +2748,7 @@ void TextServerFallback::shaped_text_overrun_trim_to_width(RID p_shaped_line, re if (add_ellipsis && (ellipsis_pos > 0 || enforce_ellipsis)) { // Insert an additional space when cutting word bound for aesthetics. if (cut_per_word && (ellipsis_pos > 0)) { - TextServer::Glyph gl; + Glyph gl; gl.count = 1; gl.advance = whitespace_adv.x; gl.index = whitespace_gl_idx; @@ -2753,7 +2759,7 @@ void TextServerFallback::shaped_text_overrun_trim_to_width(RID p_shaped_line, re sd->overrun_trim_data.ellipsis_glyph_buf.append(gl); } // Add ellipsis dots. - TextServer::Glyph gl; + Glyph gl; gl.count = 1; gl.repeat = 3; gl.advance = dot_adv.x; @@ -2770,12 +2776,36 @@ void TextServerFallback::shaped_text_overrun_trim_to_width(RID p_shaped_line, re } } -TextServer::TrimData TextServerFallback::shaped_text_get_trim_data(RID p_shaped) const { +int TextServerFallback::shaped_text_get_trim_pos(RID p_shaped) const { + ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); + ERR_FAIL_COND_V_MSG(!sd, -1, "ShapedTextData invalid."); + + MutexLock lock(sd->mutex); + return sd->overrun_trim_data.trim_pos; +} + +int TextServerFallback::shaped_text_get_ellipsis_pos(RID p_shaped) const { + ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); + ERR_FAIL_COND_V_MSG(!sd, -1, "ShapedTextData invalid."); + + MutexLock lock(sd->mutex); + return sd->overrun_trim_data.ellipsis_pos; +} + +const Glyph *TextServerFallback::shaped_text_get_ellipsis_glyphs(RID p_shaped) const { + ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); + ERR_FAIL_COND_V_MSG(!sd, nullptr, "ShapedTextData invalid."); + + MutexLock lock(sd->mutex); + return sd->overrun_trim_data.ellipsis_glyph_buf.ptr(); +} + +int TextServerFallback::shaped_text_get_ellipsis_glyph_count(RID p_shaped) const { ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); - ERR_FAIL_COND_V_MSG(!sd, TrimData(), "ShapedTextDataFallback invalid."); + ERR_FAIL_COND_V_MSG(!sd, 0, "ShapedTextData invalid."); MutexLock lock(sd->mutex); - return sd->overrun_trim_data; + return sd->overrun_trim_data.ellipsis_glyph_buf.size(); } bool TextServerFallback::shaped_text_shape(RID p_shaped) { @@ -2890,8 +2920,7 @@ bool TextServerFallback::shaped_text_shape(RID p_shaped) { // Glyph not found, replace with hex code box. if (sd->orientation == ORIENTATION_HORIZONTAL) { gl.advance = get_hex_code_box_size(gl.font_size, gl.index).x; - sd->ascent = MAX(sd->ascent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).y * 0.75f)); - sd->descent = MAX(sd->descent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).y * 0.25f)); + sd->ascent = MAX(sd->ascent, get_hex_code_box_size(gl.font_size, gl.index).y); } else { gl.advance = get_hex_code_box_size(gl.font_size, gl.index).y; sd->ascent = MAX(sd->ascent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).x * 0.5f)); @@ -2905,65 +2934,65 @@ bool TextServerFallback::shaped_text_shape(RID p_shaped) { } // Align embedded objects to baseline. - real_t full_ascent = sd->ascent; - real_t full_descent = sd->descent; - for (Map<Variant, ShapedTextData::EmbeddedObject>::Element *E = sd->objects.front(); E; E = E->next()) { + float full_ascent = sd->ascent; + float full_descent = sd->descent; + for (KeyValue<Variant, ShapedTextData::EmbeddedObject> &E : sd->objects) { if (sd->orientation == ORIENTATION_HORIZONTAL) { - switch (E->get().inline_align & INLINE_ALIGN_TEXT_MASK) { + switch (E.value.inline_align & INLINE_ALIGN_TEXT_MASK) { case INLINE_ALIGN_TO_TOP: { - E->get().rect.position.y = -sd->ascent; + E.value.rect.position.y = -sd->ascent; } break; case INLINE_ALIGN_TO_CENTER: { - E->get().rect.position.y = (-sd->ascent + sd->descent) / 2; + E.value.rect.position.y = (-sd->ascent + sd->descent) / 2; } break; case INLINE_ALIGN_TO_BASELINE: { - E->get().rect.position.y = 0; + E.value.rect.position.y = 0; } break; case INLINE_ALIGN_TO_BOTTOM: { - E->get().rect.position.y = sd->descent; + E.value.rect.position.y = sd->descent; } break; } - switch (E->get().inline_align & INLINE_ALIGN_IMAGE_MASK) { + switch (E.value.inline_align & INLINE_ALIGN_IMAGE_MASK) { case INLINE_ALIGN_BOTTOM_TO: { - E->get().rect.position.y -= E->get().rect.size.y; + E.value.rect.position.y -= E.value.rect.size.y; } break; case INLINE_ALIGN_CENTER_TO: { - E->get().rect.position.y -= E->get().rect.size.y / 2; + E.value.rect.position.y -= E.value.rect.size.y / 2; } break; case INLINE_ALIGN_TOP_TO: { //NOP } break; } - full_ascent = MAX(full_ascent, -E->get().rect.position.y); - full_descent = MAX(full_descent, E->get().rect.position.y + E->get().rect.size.y); + full_ascent = MAX(full_ascent, -E.value.rect.position.y); + full_descent = MAX(full_descent, E.value.rect.position.y + E.value.rect.size.y); } else { - switch (E->get().inline_align & INLINE_ALIGN_TEXT_MASK) { + switch (E.value.inline_align & INLINE_ALIGN_TEXT_MASK) { case INLINE_ALIGN_TO_TOP: { - E->get().rect.position.x = -sd->ascent; + E.value.rect.position.x = -sd->ascent; } break; case INLINE_ALIGN_TO_CENTER: { - E->get().rect.position.x = (-sd->ascent + sd->descent) / 2; + E.value.rect.position.x = (-sd->ascent + sd->descent) / 2; } break; case INLINE_ALIGN_TO_BASELINE: { - E->get().rect.position.x = 0; + E.value.rect.position.x = 0; } break; case INLINE_ALIGN_TO_BOTTOM: { - E->get().rect.position.x = sd->descent; + E.value.rect.position.x = sd->descent; } break; } - switch (E->get().inline_align & INLINE_ALIGN_IMAGE_MASK) { + switch (E.value.inline_align & INLINE_ALIGN_IMAGE_MASK) { case INLINE_ALIGN_BOTTOM_TO: { - E->get().rect.position.x -= E->get().rect.size.x; + E.value.rect.position.x -= E.value.rect.size.x; } break; case INLINE_ALIGN_CENTER_TO: { - E->get().rect.position.x -= E->get().rect.size.x / 2; + E.value.rect.position.x -= E.value.rect.size.x / 2; } break; case INLINE_ALIGN_TOP_TO: { //NOP } break; } - full_ascent = MAX(full_ascent, -E->get().rect.position.x); - full_descent = MAX(full_descent, E->get().rect.position.x + E->get().rect.size.x); + full_ascent = MAX(full_ascent, -E.value.rect.position.x); + full_descent = MAX(full_descent, E.value.rect.position.x + E.value.rect.size.x); } } sd->ascent = full_ascent; @@ -2980,35 +3009,46 @@ bool TextServerFallback::shaped_text_is_ready(RID p_shaped) const { return sd->valid; } -Vector<TextServer::Glyph> TextServerFallback::shaped_text_get_glyphs(RID p_shaped) const { +const Glyph *TextServerFallback::shaped_text_get_glyphs(RID p_shaped) const { const ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); - ERR_FAIL_COND_V(!sd, Vector<TextServer::Glyph>()); + ERR_FAIL_COND_V(!sd, nullptr); MutexLock lock(sd->mutex); if (!sd->valid) { const_cast<TextServerFallback *>(this)->shaped_text_shape(p_shaped); } - return sd->glyphs; + return sd->glyphs.ptr(); } -Vector2i TextServerFallback::shaped_text_get_range(RID p_shaped) const { +int TextServerFallback::shaped_text_get_glyph_count(RID p_shaped) const { const ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); - ERR_FAIL_COND_V(!sd, Vector2i()); + ERR_FAIL_COND_V(!sd, 0); MutexLock lock(sd->mutex); - return Vector2(sd->start, sd->end); + if (!sd->valid) { + const_cast<TextServerFallback *>(this)->shaped_text_shape(p_shaped); + } + return sd->glyphs.size(); } -Vector<TextServer::Glyph> TextServerFallback::shaped_text_sort_logical(RID p_shaped) { +const Glyph *TextServerFallback::shaped_text_sort_logical(RID p_shaped) { const ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); - ERR_FAIL_COND_V(!sd, Vector<TextServer::Glyph>()); + ERR_FAIL_COND_V(!sd, nullptr); MutexLock lock(sd->mutex); if (!sd->valid) { const_cast<TextServerFallback *>(this)->shaped_text_shape(p_shaped); } - return sd->glyphs; // Already in the logical order, return as is. + return sd->glyphs.ptr(); // Already in the logical order, return as is. +} + +Vector2i TextServerFallback::shaped_text_get_range(RID p_shaped) const { + const ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); + ERR_FAIL_COND_V(!sd, Vector2i()); + + MutexLock lock(sd->mutex); + return Vector2(sd->start, sd->end); } Array TextServerFallback::shaped_text_get_objects(RID p_shaped) const { @@ -3017,8 +3057,8 @@ Array TextServerFallback::shaped_text_get_objects(RID p_shaped) const { ERR_FAIL_COND_V(!sd, ret); MutexLock lock(sd->mutex); - for (const Map<Variant, ShapedTextData::EmbeddedObject>::Element *E = sd->objects.front(); E; E = E->next()) { - ret.push_back(E->key()); + for (const KeyValue<Variant, ShapedTextData::EmbeddedObject> &E : sd->objects) { + ret.push_back(E.key); } return ret; @@ -3051,7 +3091,7 @@ Size2 TextServerFallback::shaped_text_get_size(RID p_shaped) const { } } -real_t TextServerFallback::shaped_text_get_ascent(RID p_shaped) const { +float TextServerFallback::shaped_text_get_ascent(RID p_shaped) const { const ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, 0.f); @@ -3062,7 +3102,7 @@ real_t TextServerFallback::shaped_text_get_ascent(RID p_shaped) const { return sd->ascent; } -real_t TextServerFallback::shaped_text_get_descent(RID p_shaped) const { +float TextServerFallback::shaped_text_get_descent(RID p_shaped) const { const ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, 0.f); @@ -3073,7 +3113,7 @@ real_t TextServerFallback::shaped_text_get_descent(RID p_shaped) const { return sd->descent; } -real_t TextServerFallback::shaped_text_get_width(RID p_shaped) const { +float TextServerFallback::shaped_text_get_width(RID p_shaped) const { const ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, 0.f); @@ -3084,7 +3124,7 @@ real_t TextServerFallback::shaped_text_get_width(RID p_shaped) const { return sd->width; } -real_t TextServerFallback::shaped_text_get_underline_position(RID p_shaped) const { +float TextServerFallback::shaped_text_get_underline_position(RID p_shaped) const { const ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, 0.f); @@ -3096,7 +3136,7 @@ real_t TextServerFallback::shaped_text_get_underline_position(RID p_shaped) cons return sd->upos; } -real_t TextServerFallback::shaped_text_get_underline_thickness(RID p_shaped) const { +float TextServerFallback::shaped_text_get_underline_thickness(RID p_shaped) const { const ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, 0.f); @@ -3108,15 +3148,6 @@ real_t TextServerFallback::shaped_text_get_underline_thickness(RID p_shaped) con return sd->uthk; } -TextServer *TextServerFallback::create_func(Error &r_error, void *p_user_data) { - r_error = OK; - return memnew(TextServerFallback()); -} - -void TextServerFallback::register_server() { - TextServerManager::register_create_function(interface_name, interface_features, create_func, nullptr); -} - TextServerFallback::TextServerFallback(){}; TextServerFallback::~TextServerFallback() { diff --git a/modules/text_server_fb/text_server_fb.h b/modules/text_server_fb/text_server_fb.h index fde75e7135..992ce5018f 100644 --- a/modules/text_server_fb/text_server_fb.h +++ b/modules/text_server_fb/text_server_fb.h @@ -93,12 +93,12 @@ class TextServerFallback : public TextServer { }; struct FontDataForSizeFallback { - real_t ascent = 0.f; - real_t descent = 0.f; - real_t underline_position = 0.f; - real_t underline_thickness = 0.f; - real_t scale = 1.f; - real_t oversampling = 1.f; + float ascent = 0.f; + float descent = 0.f; + float underline_position = 0.f; + float underline_thickness = 0.f; + float scale = 1.f; + float oversampling = 1.f; int spacing_glyph = 0; int spacing_space = 0; @@ -134,7 +134,7 @@ class TextServerFallback : public TextServer { bool force_autohinter = false; TextServer::Hinting hinting = TextServer::HINTING_LIGHT; Dictionary variation_coordinates; - real_t oversampling = 0.f; + float oversampling = 0.f; Map<Vector2i, FontDataForSizeFallback *> cache; @@ -194,7 +194,7 @@ class TextServerFallback : public TextServer { // Common data. - real_t oversampling = 1.f; + float oversampling = 1.f; mutable RID_PtrOwner<FontDataFallback> font_owner; mutable RID_PtrOwner<ShapedTextData> shaped_owner; @@ -205,20 +205,19 @@ protected: void invalidate(ShapedTextData *p_shaped); public: - virtual bool has_feature(Feature p_feature) override; + virtual bool has_feature(Feature p_feature) const override; virtual String get_name() const override; + virtual uint32_t get_features() const override; virtual void free(RID p_rid) override; virtual bool has(RID p_rid) override; virtual bool load_support_data(const String &p_filename) override; -#ifdef TOOLS_ENABLED - virtual String get_support_data_filename() override { return ""; }; - virtual String get_support_data_info() override { return "Not supported"; }; - virtual bool save_support_data(const String &p_filename) override; -#endif + virtual String get_support_data_filename() const override { return ""; }; + virtual String get_support_data_info() const override { return "Not supported"; }; + virtual bool save_support_data(const String &p_filename) const override; - virtual bool is_locale_right_to_left(const String &p_locale) override; + virtual bool is_locale_right_to_left(const String &p_locale) const override; virtual int32_t name_to_tag(const String &p_name) const override; virtual String tag_to_name(int32_t p_tag) const override; @@ -253,27 +252,27 @@ public: virtual void font_set_variation_coordinates(RID p_font_rid, const Dictionary &p_variation_coordinates) override; virtual Dictionary font_get_variation_coordinates(RID p_font_rid) const override; - virtual void font_set_oversampling(RID p_font_rid, real_t p_oversampling) override; - virtual real_t font_get_oversampling(RID p_font_rid) const override; + virtual void font_set_oversampling(RID p_font_rid, float p_oversampling) override; + virtual float font_get_oversampling(RID p_font_rid) const override; virtual Array font_get_size_cache_list(RID p_font_rid) const override; virtual void font_clear_size_cache(RID p_font_rid) override; virtual void font_remove_size_cache(RID p_font_rid, const Vector2i &p_size) override; - virtual void font_set_ascent(RID p_font_rid, int p_size, real_t p_ascent) override; - virtual real_t font_get_ascent(RID p_font_rid, int p_size) const override; + virtual void font_set_ascent(RID p_font_rid, int p_size, float p_ascent) override; + virtual float font_get_ascent(RID p_font_rid, int p_size) const override; - virtual void font_set_descent(RID p_font_rid, int p_size, real_t p_descent) override; - virtual real_t font_get_descent(RID p_font_rid, int p_size) const override; + virtual void font_set_descent(RID p_font_rid, int p_size, float p_descent) override; + virtual float font_get_descent(RID p_font_rid, int p_size) const override; - virtual void font_set_underline_position(RID p_font_rid, int p_size, real_t p_underline_position) override; - virtual real_t font_get_underline_position(RID p_font_rid, int p_size) const override; + virtual void font_set_underline_position(RID p_font_rid, int p_size, float p_underline_position) override; + virtual float font_get_underline_position(RID p_font_rid, int p_size) const override; - virtual void font_set_underline_thickness(RID p_font_rid, int p_size, real_t p_underline_thickness) override; - virtual real_t font_get_underline_thickness(RID p_font_rid, int p_size) const override; + virtual void font_set_underline_thickness(RID p_font_rid, int p_size, float p_underline_thickness) override; + virtual float font_get_underline_thickness(RID p_font_rid, int p_size) const override; - virtual void font_set_scale(RID p_font_rid, int p_size, real_t p_scale) override; - virtual real_t font_get_scale(RID p_font_rid, int p_size) const override; + virtual void font_set_scale(RID p_font_rid, int p_size, float p_scale) override; + virtual float font_get_scale(RID p_font_rid, int p_size) const override; virtual void font_set_spacing(RID p_font_rid, int p_size, SpacingType p_spacing, int p_value) override; virtual int font_get_spacing(RID p_font_rid, int p_size, SpacingType p_spacing) const override; @@ -307,7 +306,7 @@ public: virtual int font_get_glyph_texture_idx(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph) const override; virtual void font_set_glyph_texture_idx(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph, int p_texture_idx) override; - virtual bool font_get_glyph_contours(RID p_font, int p_size, int32_t p_index, Vector<Vector3> &r_points, Vector<int32_t> &r_contours, bool &r_orientation) const override; + virtual Dictionary font_get_glyph_contours(RID p_font, int p_size, int32_t p_index) const override; virtual Array font_get_kerning_list(RID p_font_rid, int p_size) const override; virtual void font_clear_kerning_map(RID p_font_rid, int p_size) override; @@ -342,8 +341,8 @@ public: virtual Dictionary font_supported_feature_list(RID p_font_rid) const override; virtual Dictionary font_supported_variation_list(RID p_font_rid) const override; - virtual real_t font_get_global_oversampling() const override; - virtual void font_set_global_oversampling(real_t p_oversampling) override; + virtual float font_get_global_oversampling() const override; + virtual void font_set_global_oversampling(float p_oversampling) override; /* Shaped text buffer interface */ @@ -354,7 +353,7 @@ public: virtual void shaped_text_set_direction(RID p_shaped, Direction p_direction = DIRECTION_AUTO) override; virtual Direction shaped_text_get_direction(RID p_shaped) const override; - virtual void shaped_text_set_bidi_override(RID p_shaped, const Vector<Vector2i> &p_override) override; + virtual void shaped_text_set_bidi_override(RID p_shaped, const Array &p_override) override; virtual void shaped_text_set_orientation(RID p_shaped, Orientation p_orientation = ORIENTATION_HORIZONTAL) override; virtual Orientation shaped_text_get_orientation(RID p_shaped) const override; @@ -372,36 +371,37 @@ public: virtual RID shaped_text_substr(RID p_shaped, int p_start, int p_length) const override; virtual RID shaped_text_get_parent(RID p_shaped) const override; - virtual real_t shaped_text_fit_to_width(RID p_shaped, real_t p_width, uint8_t /*JustificationFlag*/ p_jst_flags = JUSTIFICATION_WORD_BOUND | JUSTIFICATION_KASHIDA) override; - virtual real_t shaped_text_tab_align(RID p_shaped, const Vector<real_t> &p_tab_stops) override; + virtual float shaped_text_fit_to_width(RID p_shaped, float p_width, uint16_t /*JustificationFlag*/ p_jst_flags = JUSTIFICATION_WORD_BOUND | JUSTIFICATION_KASHIDA) override; + virtual float shaped_text_tab_align(RID p_shaped, const PackedFloat32Array &p_tab_stops) override; virtual bool shaped_text_shape(RID p_shaped) override; virtual bool shaped_text_update_breaks(RID p_shaped) override; virtual bool shaped_text_update_justification_ops(RID p_shaped) override; - virtual void shaped_text_overrun_trim_to_width(RID p_shaped, real_t p_width, uint8_t p_trim_flags) override; - virtual TrimData shaped_text_get_trim_data(RID p_shaped) const override; + virtual int shaped_text_get_trim_pos(RID p_shaped) const override; + virtual int shaped_text_get_ellipsis_pos(RID p_shaped) const override; + virtual const Glyph *shaped_text_get_ellipsis_glyphs(RID p_shaped) const override; + virtual int shaped_text_get_ellipsis_glyph_count(RID p_shaped) const override; + + virtual void shaped_text_overrun_trim_to_width(RID p_shaped, float p_width, uint16_t p_trim_flags) override; virtual bool shaped_text_is_ready(RID p_shaped) const override; - virtual Vector<Glyph> shaped_text_get_glyphs(RID p_shaped) const override; + virtual const Glyph *shaped_text_get_glyphs(RID p_shaped) const override; + virtual const Glyph *shaped_text_sort_logical(RID p_shaped) override; + virtual int shaped_text_get_glyph_count(RID p_shaped) const override; virtual Vector2i shaped_text_get_range(RID p_shaped) const override; - virtual Vector<Glyph> shaped_text_sort_logical(RID p_shaped) override; - virtual Array shaped_text_get_objects(RID p_shaped) const override; virtual Rect2 shaped_text_get_object_rect(RID p_shaped, Variant p_key) const override; virtual Size2 shaped_text_get_size(RID p_shaped) const override; - virtual real_t shaped_text_get_ascent(RID p_shaped) const override; - virtual real_t shaped_text_get_descent(RID p_shaped) const override; - virtual real_t shaped_text_get_width(RID p_shaped) const override; - virtual real_t shaped_text_get_underline_position(RID p_shaped) const override; - virtual real_t shaped_text_get_underline_thickness(RID p_shaped) const override; - - static TextServer *create_func(Error &r_error, void *p_user_data); - static void register_server(); + virtual float shaped_text_get_ascent(RID p_shaped) const override; + virtual float shaped_text_get_descent(RID p_shaped) const override; + virtual float shaped_text_get_width(RID p_shaped) const override; + virtual float shaped_text_get_underline_position(RID p_shaped) const override; + virtual float shaped_text_get_underline_thickness(RID p_shaped) const override; TextServerFallback(); ~TextServerFallback(); diff --git a/modules/visual_script/visual_script.cpp b/modules/visual_script/visual_script.cpp index 4d5f3420b8..54d310e636 100644 --- a/modules/visual_script/visual_script.cpp +++ b/modules/visual_script/visual_script.cpp @@ -702,8 +702,8 @@ void VisualScript::rename_custom_signal(const StringName &p_name, const StringNa } void VisualScript::get_custom_signal_list(List<StringName> *r_custom_signals) const { - for (const Map<StringName, Vector<Argument>>::Element *E = custom_signals.front(); E; E = E->next()) { - r_custom_signals->push_back(E->key()); + for (const KeyValue<StringName, Vector<Argument>> &E : custom_signals) { + r_custom_signals->push_back(E.key); } r_custom_signals->sort_custom<StringName::AlphCompare>(); @@ -848,13 +848,13 @@ bool VisualScript::has_script_signal(const StringName &p_signal) const { } void VisualScript::get_script_signal_list(List<MethodInfo> *r_signals) const { - for (const Map<StringName, Vector<Argument>>::Element *E = custom_signals.front(); E; E = E->next()) { + for (const KeyValue<StringName, Vector<Argument>> &E : custom_signals) { MethodInfo mi; - mi.name = E->key(); - for (int i = 0; i < E->get().size(); i++) { + mi.name = E.key; + for (int i = 0; i < E.value.size(); i++) { PropertyInfo arg; - arg.type = E->get()[i].type; - arg.name = E->get()[i].name; + arg.type = E.value[i].type; + arg.name = E.value[i].name; mi.arguments.push_back(arg); } @@ -1056,13 +1056,13 @@ Dictionary VisualScript::_get_data() const { d["variables"] = vars; Array sigs; - for (const Map<StringName, Vector<Argument>>::Element *E = custom_signals.front(); E; E = E->next()) { + for (const KeyValue<StringName, Vector<Argument>> &E : custom_signals) { Dictionary cs; - cs["name"] = E->key(); + cs["name"] = E.key; Array args; - for (int i = 0; i < E->get().size(); i++) { - args.push_back(E->get()[i].name); - args.push_back(E->get()[i].type); + for (int i = 0; i < E.value.size(); i++) { + args.push_back(E.value[i].name); + args.push_back(E.value[i].type); } cs["arguments"] = args; @@ -2093,8 +2093,8 @@ VisualScriptInstance::~VisualScriptInstance() { script->instances.erase(owner); } - for (Map<int, VisualScriptNodeInstance *>::Element *E = instances.front(); E; E = E->next()) { - memdelete(E->get()); + for (const KeyValue<int, VisualScriptNodeInstance *> &E : instances) { + memdelete(E.value); } } @@ -2516,8 +2516,8 @@ Ref<VisualScriptNode> VisualScriptLanguage::create_node_from_name(const String & } void VisualScriptLanguage::get_registered_node_names(List<String> *r_names) { - for (Map<String, VisualScriptNodeRegisterFunc>::Element *E = register_funcs.front(); E; E = E->next()) { - r_names->push_back(E->key()); + for (const KeyValue<String, VisualScriptNodeRegisterFunc> &E : register_funcs) { + r_names->push_back(E.key); } } diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index 0a6bcedf31..8cb701ea20 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -3632,17 +3632,17 @@ void VisualScriptEditor::_notification(int p_what) { node_colors["constants"] = Color(0.94, 0.18, 0.49); } - for (Map<StringName, Color>::Element *E = node_colors.front(); E; E = E->next()) { + for (const KeyValue<StringName, Color> &E : node_colors) { const Ref<StyleBoxFlat> sb = tm->get_stylebox(SNAME("frame"), SNAME("GraphNode")); if (!sb.is_null()) { Ref<StyleBoxFlat> frame_style = sb->duplicate(); // Adjust the border color to be close to the GraphNode's background color. // This keeps the node's title area from being too distracting. - Color color = dark_theme ? E->get().darkened(0.75) : E->get().lightened(0.75); + Color color = dark_theme ? E.value.darkened(0.75) : E.value.lightened(0.75); color.a = 0.9; frame_style->set_border_color(color); - node_styles[E->key()] = frame_style; + node_styles[E.key] = frame_style; } } @@ -3813,15 +3813,15 @@ void VisualScriptEditor::_menu_option(int p_what) { } } - for (Map<int, Ref<VisualScriptNode>>::Element *E = clipboard->nodes.front(); E; E = E->next()) { - Ref<VisualScriptNode> node = E->get()->duplicate(); + for (KeyValue<int, Ref<VisualScriptNode>> &E : clipboard->nodes) { + Ref<VisualScriptNode> node = E.value->duplicate(); int new_id = idc++; to_select.insert(new_id); - remap[E->key()] = new_id; + remap[E.key] = new_id; - Vector2 paste_pos = clipboard->nodes_positions[E->key()]; + Vector2 paste_pos = clipboard->nodes_positions[E.key]; while (existing_positions.has(paste_pos.snapped(Vector2(2, 2)))) { paste_pos += Vector2(20, 20) * EDSCALE; @@ -3906,16 +3906,16 @@ void VisualScriptEditor::_menu_option(int p_what) { // the user wants to connect the nodes. int top_nd = -1; Vector2 top; - for (Map<int, Ref<VisualScriptNode>>::Element *E = nodes.front(); E; E = E->next()) { - Ref<VisualScriptNode> nd = script->get_node(E->key()); + for (const KeyValue<int, Ref<VisualScriptNode>> &E : nodes) { + Ref<VisualScriptNode> nd = script->get_node(E.key); if (nd.is_valid() && nd->has_input_sequence_port()) { if (top_nd < 0) { - top_nd = E->key(); + top_nd = E.key; top = script->get_node_position(top_nd); } - Vector2 pos = script->get_node_position(E->key()); + Vector2 pos = script->get_node_position(E.key); if (top.y > pos.y) { - top_nd = E->key(); + top_nd = E.key; top = pos; } } diff --git a/modules/webrtc/webrtc_multiplayer_peer.cpp b/modules/webrtc/webrtc_multiplayer_peer.cpp index 48117f05f2..133bd71ddb 100644 --- a/modules/webrtc/webrtc_multiplayer_peer.cpp +++ b/modules/webrtc/webrtc_multiplayer_peer.cpp @@ -63,8 +63,8 @@ void WebRTCMultiplayerPeer::poll() { List<int> remove; List<int> add; - for (Map<int, Ref<ConnectedPeer>>::Element *E = peer_map.front(); E; E = E->next()) { - Ref<ConnectedPeer> peer = E->get(); + for (KeyValue<int, Ref<ConnectedPeer>> &E : peer_map) { + Ref<ConnectedPeer> peer = E.value; peer->connection->poll(); // Check peer state switch (peer->connection->get_connection_state()) { @@ -77,7 +77,7 @@ void WebRTCMultiplayerPeer::poll() { break; default: // Peer is closed or in error state. Got to next peer. - remove.push_back(E->key()); + remove.push_back(E.key); continue; } // Check channels state @@ -92,7 +92,7 @@ void WebRTCMultiplayerPeer::poll() { continue; default: // Channel was closed or in error state, remove peer id. - remove.push_back(E->key()); + remove.push_back(E.key); } // We got a closed channel break out, the peer will be removed. break; @@ -100,7 +100,7 @@ void WebRTCMultiplayerPeer::poll() { // This peer has newly connected, and all channels are now open. if (ready == peer->channels.size() && !peer->connected) { peer->connected = true; - add.push_back(E->key()); + add.push_back(E.key); } } // Remove disconnected peers @@ -125,9 +125,9 @@ void WebRTCMultiplayerPeer::poll() { emit_signal(SNAME("peer_connected"), TARGET_PEER_SERVER); emit_signal(SNAME("connection_succeeded")); // Notify of all previously connected peers - for (Map<int, Ref<ConnectedPeer>>::Element *F = peer_map.front(); F; F = F->next()) { - if (F->key() != 1 && F->get()->connected) { - emit_signal(SNAME("peer_connected"), F->key()); + for (const KeyValue<int, Ref<ConnectedPeer>> &F : peer_map) { + if (F.key != 1 && F.value->connected) { + emit_signal(SNAME("peer_connected"), F.key); } } break; // Because we already notified of all newly added peers. @@ -189,7 +189,7 @@ Error WebRTCMultiplayerPeer::initialize(int p_self_id, bool p_server_compat, Arr cfg["ordered"] = true; switch (mode) { - case Multiplayer::TRANSFER_MODE_ORDERED: + case Multiplayer::TRANSFER_MODE_UNRELIABLE_ORDERED: cfg["maxPacketLifetime"] = 1; break; case Multiplayer::TRANSFER_MODE_UNRELIABLE: @@ -244,10 +244,10 @@ Dictionary WebRTCMultiplayerPeer::get_peer(int p_peer_id) { Dictionary WebRTCMultiplayerPeer::get_peers() { Dictionary out; - for (Map<int, Ref<ConnectedPeer>>::Element *E = peer_map.front(); E; E = E->next()) { + for (const KeyValue<int, Ref<ConnectedPeer>> &E : peer_map) { Dictionary d; - _peer_to_dict(E->get(), d); - out[E->key()] = d; + _peer_to_dict(E.value, d); + out[E.key] = d; } return out; } @@ -334,7 +334,7 @@ Error WebRTCMultiplayerPeer::put_packet(const uint8_t *p_buffer, int p_buffer_si case Multiplayer::TRANSFER_MODE_RELIABLE: ch = CH_RELIABLE; break; - case Multiplayer::TRANSFER_MODE_ORDERED: + case Multiplayer::TRANSFER_MODE_UNRELIABLE_ORDERED: ch = CH_ORDERED; break; case Multiplayer::TRANSFER_MODE_UNRELIABLE: @@ -358,15 +358,15 @@ Error WebRTCMultiplayerPeer::put_packet(const uint8_t *p_buffer, int p_buffer_si } else { int exclude = -target_peer; - for (Map<int, Ref<ConnectedPeer>>::Element *F = peer_map.front(); F; F = F->next()) { + for (KeyValue<int, Ref<ConnectedPeer>> &F : peer_map) { // Exclude packet. If target_peer == 0 then don't exclude any packets - if (target_peer != 0 && F->key() == exclude) { + if (target_peer != 0 && F.key == exclude) { continue; } - ERR_CONTINUE_MSG(F->value()->channels.size() <= ch, vformat("Unable to send packet on channel %d, max channels: %d", ch, E->value()->channels.size())); - ERR_CONTINUE(F->value()->channels[ch].is_null()); - F->value()->channels[ch]->put_packet(p_buffer, p_buffer_size); + ERR_CONTINUE_MSG(F.value->channels.size() <= ch, vformat("Unable to send packet on channel %d, max channels: %d", ch, E->value()->channels.size())); + ERR_CONTINUE(F.value->channels[ch].is_null()); + F.value->channels[ch]->put_packet(p_buffer, p_buffer_size); } } return OK; @@ -377,8 +377,8 @@ int WebRTCMultiplayerPeer::get_available_packet_count() const { return 0; // To be sure next call to get_packet works if size > 0 . } int size = 0; - for (Map<int, Ref<ConnectedPeer>>::Element *E = peer_map.front(); E; E = E->next()) { - for (const Ref<WebRTCDataChannel> &F : E->get()->channels) { + for (const KeyValue<int, Ref<ConnectedPeer>> &E : peer_map) { + for (const Ref<WebRTCDataChannel> &F : E.value->channels) { size += F->get_available_packet_count(); } } diff --git a/modules/websocket/websocket_multiplayer_peer.cpp b/modules/websocket/websocket_multiplayer_peer.cpp index 3a27855a5e..e54bfbca12 100644 --- a/modules/websocket/websocket_multiplayer_peer.cpp +++ b/modules/websocket/websocket_multiplayer_peer.cpp @@ -148,8 +148,8 @@ void WebSocketMultiplayerPeer::_send_add(int32_t p_peer_id) { // Then send the server peer (which will trigger connection_succeded in client) _send_sys(get_peer(p_peer_id), SYS_ADD, 1); - for (Map<int, Ref<WebSocketPeer>>::Element *E = _peer_map.front(); E; E = E->next()) { - int32_t id = E->key(); + for (const KeyValue<int, Ref<WebSocketPeer>> &E : _peer_map) { + int32_t id = E.key; if (p_peer_id == id) { continue; // Skip the newly added peer (already confirmed) } @@ -162,8 +162,8 @@ void WebSocketMultiplayerPeer::_send_add(int32_t p_peer_id) { } void WebSocketMultiplayerPeer::_send_del(int32_t p_peer_id) { - for (Map<int, Ref<WebSocketPeer>>::Element *E = _peer_map.front(); E; E = E->next()) { - int32_t id = E->key(); + for (const KeyValue<int, Ref<WebSocketPeer>> &E : _peer_map) { + int32_t id = E.key; if (p_peer_id != id) { _send_sys(get_peer(id), SYS_DEL, p_peer_id); } @@ -186,17 +186,17 @@ Error WebSocketMultiplayerPeer::_server_relay(int32_t p_from, int32_t p_to, cons return OK; // Will not send to self } else if (p_to == 0) { - for (Map<int, Ref<WebSocketPeer>>::Element *E = _peer_map.front(); E; E = E->next()) { - if (E->key() != p_from) { - E->get()->put_packet(p_buffer, p_buffer_size); + for (KeyValue<int, Ref<WebSocketPeer>> &E : _peer_map) { + if (E.key != p_from) { + E.value->put_packet(p_buffer, p_buffer_size); } } return OK; // Sent to all but sender } else if (p_to < 0) { - for (Map<int, Ref<WebSocketPeer>>::Element *E = _peer_map.front(); E; E = E->next()) { - if (E->key() != p_from && E->key() != -p_to) { - E->get()->put_packet(p_buffer, p_buffer_size); + for (KeyValue<int, Ref<WebSocketPeer>> &E : _peer_map) { + if (E.key != p_from && E.key != -p_to) { + E.value->put_packet(p_buffer, p_buffer_size); } } return OK; // Sent to all but sender and excluded diff --git a/modules/websocket/wsl_server.cpp b/modules/websocket/wsl_server.cpp index 7402bbb46e..514b2d055f 100644 --- a/modules/websocket/wsl_server.cpp +++ b/modules/websocket/wsl_server.cpp @@ -182,12 +182,12 @@ Error WSLServer::listen(int p_port, const Vector<String> p_protocols, bool gd_mp void WSLServer::poll() { List<int> remove_ids; - for (Map<int, Ref<WebSocketPeer>>::Element *E = _peer_map.front(); E; E = E->next()) { - Ref<WSLPeer> peer = (WSLPeer *)E->get().ptr(); + for (const KeyValue<int, Ref<WebSocketPeer>> &E : _peer_map) { + Ref<WSLPeer> peer = (WSLPeer *)E.value.ptr(); peer->poll(); if (!peer->is_connected_to_host()) { - _on_disconnect(E->key(), peer->close_code != -1); - remove_ids.push_back(E->key()); + _on_disconnect(E.key, peer->close_code != -1); + remove_ids.push_back(E.key); } } for (int &E : remove_ids) { @@ -265,8 +265,8 @@ int WSLServer::get_max_packet_size() const { void WSLServer::stop() { _server->stop(); - for (Map<int, Ref<WebSocketPeer>>::Element *E = _peer_map.front(); E; E = E->next()) { - Ref<WSLPeer> peer = (WSLPeer *)E->get().ptr(); + for (const KeyValue<int, Ref<WebSocketPeer>> &E : _peer_map) { + Ref<WSLPeer> peer = (WSLPeer *)E.value.ptr(); peer->close_now(); } _pending.clear(); |