diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/gdscript/gdscript.cpp | 10 | ||||
-rw-r--r-- | modules/gdscript/gdscript.h | 3 | ||||
-rw-r--r-- | modules/gdscript/gdscript_analyzer.cpp | 17 | ||||
-rw-r--r-- | modules/gridmap/doc_classes/GridMap.xml | 20 | ||||
-rw-r--r-- | modules/gridmap/grid_map.cpp | 39 | ||||
-rw-r--r-- | modules/gridmap/grid_map.h | 7 | ||||
-rw-r--r-- | modules/svg/image_loader_svg.cpp | 23 | ||||
-rw-r--r-- | modules/svg/image_loader_svg.h | 1 |
8 files changed, 37 insertions, 83 deletions
diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index 57a29cc81e..1fe1561559 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -1966,6 +1966,16 @@ void GDScriptLanguage::add_named_global_constant(const StringName &p_name, const named_globals[p_name] = p_value; } +Variant GDScriptLanguage::get_any_global_constant(const StringName &p_name) { + if (named_globals.has(p_name)) { + return named_globals[p_name]; + } + if (globals.has(p_name)) { + return _global_array[globals[p_name]]; + } + ERR_FAIL_V_MSG(Variant(), vformat("Could not find any global constant with name: %s.", p_name)); +} + void GDScriptLanguage::remove_named_global_constant(const StringName &p_name) { ERR_FAIL_COND(!named_globals.has(p_name)); named_globals.erase(p_name); diff --git a/modules/gdscript/gdscript.h b/modules/gdscript/gdscript.h index 332d18f720..39367e377b 100644 --- a/modules/gdscript/gdscript.h +++ b/modules/gdscript/gdscript.h @@ -455,6 +455,9 @@ public: _FORCE_INLINE_ Variant *get_global_array() { return _global_array; } _FORCE_INLINE_ const HashMap<StringName, int> &get_global_map() const { return globals; } _FORCE_INLINE_ const HashMap<StringName, Variant> &get_named_globals_map() const { return named_globals; } + // These two functions should be used when behavior needs to be consistent between in-editor and running the scene + bool has_any_global_constant(const StringName &p_name) { return named_globals.has(p_name) || globals.has(p_name); } + Variant get_any_global_constant(const StringName &p_name); _FORCE_INLINE_ static GDScriptLanguage *get_singleton() { return singleton; } diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp index 1a1c2193bf..0aea2b9c16 100644 --- a/modules/gdscript/gdscript_analyzer.cpp +++ b/modules/gdscript/gdscript_analyzer.cpp @@ -3403,8 +3403,8 @@ void GDScriptAnalyzer::reduce_identifier(GDScriptParser::IdentifierNode *p_ident } } } else if (ResourceLoader::get_resource_type(autoload.path) == "PackedScene") { - if (GDScriptLanguage::get_singleton()->get_named_globals_map().has(name)) { - Variant constant = GDScriptLanguage::get_singleton()->get_named_globals_map()[name]; + if (GDScriptLanguage::get_singleton()->has_any_global_constant(name)) { + Variant constant = GDScriptLanguage::get_singleton()->get_any_global_constant(name); Node *node = Object::cast_to<Node>(constant); if (node != nullptr) { Ref<GDScript> scr = node->get_script(); @@ -3426,17 +3426,8 @@ void GDScriptAnalyzer::reduce_identifier(GDScriptParser::IdentifierNode *p_ident } } - if (GDScriptLanguage::get_singleton()->get_global_map().has(name)) { - int idx = GDScriptLanguage::get_singleton()->get_global_map()[name]; - Variant constant = GDScriptLanguage::get_singleton()->get_global_array()[idx]; - p_identifier->set_datatype(type_from_variant(constant, p_identifier)); - p_identifier->is_constant = true; - p_identifier->reduced_value = constant; - return; - } - - if (GDScriptLanguage::get_singleton()->get_named_globals_map().has(name)) { - Variant constant = GDScriptLanguage::get_singleton()->get_named_globals_map()[name]; + if (GDScriptLanguage::get_singleton()->has_any_global_constant(name)) { + Variant constant = GDScriptLanguage::get_singleton()->get_any_global_constant(name); p_identifier->set_datatype(type_from_variant(constant, p_identifier)); p_identifier->is_constant = true; p_identifier->reduced_value = constant; diff --git a/modules/gridmap/doc_classes/GridMap.xml b/modules/gridmap/doc_classes/GridMap.xml index 686ba4dad6..e0fc4e2697 100644 --- a/modules/gridmap/doc_classes/GridMap.xml +++ b/modules/gridmap/doc_classes/GridMap.xml @@ -89,13 +89,6 @@ Returns an array of [Transform3D] and [Mesh] references corresponding to the non-empty cells in the grid. The transforms are specified in local space. </description> </method> - <method name="get_navigation_layer_value" qualifiers="const"> - <return type="bool" /> - <param index="0" name="layer_number" type="int" /> - <description> - Returns whether or not the specified layer of the [member navigation_layers] bitmask is enabled, given a [code]layer_number[/code] between 1 and 32. - </description> - </method> <method name="get_navigation_map" qualifiers="const"> <return type="RID" /> <description> @@ -179,14 +172,6 @@ Based on [code]value[/code], enables or disables the specified layer in the [member collision_mask], given a [code]layer_number[/code] between 1 and 32. </description> </method> - <method name="set_navigation_layer_value"> - <return type="void" /> - <param index="0" name="layer_number" type="int" /> - <param index="1" name="value" type="bool" /> - <description> - Based on [code]value[/code], enables or disables the specified layer in the [member navigation_layers] bitmask, given a [code]layer_number[/code] between 1 and 32. - </description> - </method> <method name="set_navigation_map"> <return type="void" /> <param index="0" name="navigation_map" type="RID" /> @@ -197,7 +182,7 @@ </methods> <members> <member name="bake_navigation" type="bool" setter="set_bake_navigation" getter="is_baking_navigation" default="false"> - If [code]true[/code], this GridMap bakes a navigation region. + If [code]true[/code], this GridMap creates a navigation region for each cell that uses a [member mesh_library] item with a navigation mesh. The created navigation region will use the navigation layers bitmask assigned to the [MeshLibrary]'s item. </member> <member name="cell_center_x" type="bool" setter="set_center_x" getter="get_center_x" default="true"> If [code]true[/code], grid items are centered on the X axis. @@ -232,9 +217,6 @@ <member name="mesh_library" type="MeshLibrary" setter="set_mesh_library" getter="get_mesh_library"> The assigned [MeshLibrary]. </member> - <member name="navigation_layers" type="int" setter="set_navigation_layers" getter="get_navigation_layers" default="1"> - A bitmask determining all navigation layers the GridMap generated navigation regions belong to. These navigation layers can be checked upon when requesting a path with [method NavigationServer3D.map_get_path]. - </member> <member name="physics_material" type="PhysicsMaterial" setter="set_physics_material" getter="get_physics_material"> Overrides the default friction and bounce physics properties for the whole [GridMap]. </member> diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp index d5db66d648..e396d77d86 100644 --- a/modules/gridmap/grid_map.cpp +++ b/modules/gridmap/grid_map.cpp @@ -256,33 +256,6 @@ RID GridMap::get_navigation_map() const { return RID(); } -void GridMap::set_navigation_layers(uint32_t p_navigation_layers) { - navigation_layers = p_navigation_layers; - _recreate_octant_data(); -} - -uint32_t GridMap::get_navigation_layers() const { - return navigation_layers; -} - -void GridMap::set_navigation_layer_value(int p_layer_number, bool p_value) { - ERR_FAIL_COND_MSG(p_layer_number < 1, "Navigation layer number must be between 1 and 32 inclusive."); - ERR_FAIL_COND_MSG(p_layer_number > 32, "Navigation layer number must be between 1 and 32 inclusive."); - uint32_t _navigation_layers = get_navigation_layers(); - if (p_value) { - _navigation_layers |= 1 << (p_layer_number - 1); - } else { - _navigation_layers &= ~(1 << (p_layer_number - 1)); - } - set_navigation_layers(_navigation_layers); -} - -bool GridMap::get_navigation_layer_value(int p_layer_number) const { - ERR_FAIL_COND_V_MSG(p_layer_number < 1, false, "Navigation layer number must be between 1 and 32 inclusive."); - ERR_FAIL_COND_V_MSG(p_layer_number > 32, false, "Navigation layer number must be between 1 and 32 inclusive."); - return get_navigation_layers() & (1 << (p_layer_number - 1)); -} - void GridMap::set_mesh_library(const Ref<MeshLibrary> &p_mesh_library) { if (!mesh_library.is_null()) { mesh_library->unregister_owner(this); @@ -663,11 +636,12 @@ bool GridMap::_octant_update(const OctantKey &p_key) { if (navigation_mesh.is_valid()) { Octant::NavigationCell nm; nm.xform = xform * mesh_library->get_item_navigation_mesh_transform(c.item); + nm.navigation_layers = mesh_library->get_item_navigation_layers(c.item); if (bake_navigation) { RID region = NavigationServer3D::get_singleton()->region_create(); NavigationServer3D::get_singleton()->region_set_owner_id(region, get_instance_id()); - NavigationServer3D::get_singleton()->region_set_navigation_layers(region, navigation_layers); + NavigationServer3D::get_singleton()->region_set_navigation_layers(region, nm.navigation_layers); NavigationServer3D::get_singleton()->region_set_navigation_mesh(region, navigation_mesh); NavigationServer3D::get_singleton()->region_set_transform(region, get_global_transform() * nm.xform); if (is_inside_tree()) { @@ -792,7 +766,7 @@ void GridMap::_octant_enter_world(const OctantKey &p_key) { if (navigation_mesh.is_valid()) { RID region = NavigationServer3D::get_singleton()->region_create(); NavigationServer3D::get_singleton()->region_set_owner_id(region, get_instance_id()); - NavigationServer3D::get_singleton()->region_set_navigation_layers(region, navigation_layers); + NavigationServer3D::get_singleton()->region_set_navigation_layers(region, F.value.navigation_layers); NavigationServer3D::get_singleton()->region_set_navigation_mesh(region, navigation_mesh); NavigationServer3D::get_singleton()->region_set_transform(region, get_global_transform() * F.value.xform); if (map_override.is_valid()) { @@ -1070,12 +1044,6 @@ void GridMap::_bind_methods() { ClassDB::bind_method(D_METHOD("set_navigation_map", "navigation_map"), &GridMap::set_navigation_map); ClassDB::bind_method(D_METHOD("get_navigation_map"), &GridMap::get_navigation_map); - ClassDB::bind_method(D_METHOD("set_navigation_layers", "layers"), &GridMap::set_navigation_layers); - ClassDB::bind_method(D_METHOD("get_navigation_layers"), &GridMap::get_navigation_layers); - - ClassDB::bind_method(D_METHOD("set_navigation_layer_value", "layer_number", "value"), &GridMap::set_navigation_layer_value); - ClassDB::bind_method(D_METHOD("get_navigation_layer_value", "layer_number"), &GridMap::get_navigation_layer_value); - ClassDB::bind_method(D_METHOD("set_mesh_library", "mesh_library"), &GridMap::set_mesh_library); ClassDB::bind_method(D_METHOD("get_mesh_library"), &GridMap::get_mesh_library); @@ -1135,7 +1103,6 @@ void GridMap::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "collision_priority"), "set_collision_priority", "get_collision_priority"); ADD_GROUP("Navigation", ""); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "bake_navigation"), "set_bake_navigation", "is_baking_navigation"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "navigation_layers", PROPERTY_HINT_LAYERS_3D_NAVIGATION), "set_navigation_layers", "get_navigation_layers"); BIND_CONSTANT(INVALID_CELL_ITEM); diff --git a/modules/gridmap/grid_map.h b/modules/gridmap/grid_map.h index 59d2936f2c..2a9f34bdda 100644 --- a/modules/gridmap/grid_map.h +++ b/modules/gridmap/grid_map.h @@ -99,6 +99,7 @@ class GridMap : public Node3D { RID region; Transform3D xform; RID navigation_mesh_debug_instance; + uint32_t navigation_layers = 1; }; struct MultimeshInstance { @@ -255,12 +256,6 @@ public: void set_navigation_map(RID p_navigation_map); RID get_navigation_map() const; - void set_navigation_layers(uint32_t p_navigation_layers); - uint32_t get_navigation_layers() const; - - void set_navigation_layer_value(int p_layer_number, bool p_value); - bool get_navigation_layer_value(int p_layer_number) const; - void set_mesh_library(const Ref<MeshLibrary> &p_mesh_library); Ref<MeshLibrary> get_mesh_library() const; diff --git a/modules/svg/image_loader_svg.cpp b/modules/svg/image_loader_svg.cpp index 2dba4916a0..b194e7cb3f 100644 --- a/modules/svg/image_loader_svg.cpp +++ b/modules/svg/image_loader_svg.cpp @@ -67,19 +67,12 @@ void ImageLoaderSVG::_replace_color_property(const HashMap<Color, Color> &p_colo } } -Error ImageLoaderSVG::create_image_from_string(Ref<Image> p_image, String p_string, float p_scale, bool p_upsample, const HashMap<Color, Color> &p_color_map) { +Error ImageLoaderSVG::create_image_from_utf8_buffer(Ref<Image> p_image, const PackedByteArray &p_buffer, float p_scale, bool p_upsample) { ERR_FAIL_COND_V_MSG(Math::is_zero_approx(p_scale), ERR_INVALID_PARAMETER, "ImageLoaderSVG: Can't load SVG with a scale of 0."); - if (p_color_map.size()) { - _replace_color_property(p_color_map, "stop-color=\"", p_string); - _replace_color_property(p_color_map, "fill=\"", p_string); - _replace_color_property(p_color_map, "stroke=\"", p_string); - } - std::unique_ptr<tvg::Picture> picture = tvg::Picture::gen(); - PackedByteArray bytes = p_string.to_utf8_buffer(); - tvg::Result result = picture->load((const char *)bytes.ptr(), bytes.size(), "svg", true); + tvg::Result result = picture->load((const char *)p_buffer.ptr(), p_buffer.size(), "svg", true); if (result != tvg::Result::Success) { return ERR_INVALID_DATA; } @@ -149,6 +142,18 @@ Error ImageLoaderSVG::create_image_from_string(Ref<Image> p_image, String p_stri return OK; } +Error ImageLoaderSVG::create_image_from_string(Ref<Image> p_image, String p_string, float p_scale, bool p_upsample, const HashMap<Color, Color> &p_color_map) { + if (p_color_map.size()) { + _replace_color_property(p_color_map, "stop-color=\"", p_string); + _replace_color_property(p_color_map, "fill=\"", p_string); + _replace_color_property(p_color_map, "stroke=\"", p_string); + } + + PackedByteArray bytes = p_string.to_utf8_buffer(); + + return create_image_from_utf8_buffer(p_image, bytes, p_scale, p_upsample); +} + void ImageLoaderSVG::get_recognized_extensions(List<String> *p_extensions) const { p_extensions->push_back("svg"); } diff --git a/modules/svg/image_loader_svg.h b/modules/svg/image_loader_svg.h index 84511f1708..d955a04f1e 100644 --- a/modules/svg/image_loader_svg.h +++ b/modules/svg/image_loader_svg.h @@ -41,6 +41,7 @@ class ImageLoaderSVG : public ImageFormatLoader { public: static void set_forced_color_map(const HashMap<Color, Color> &p_color_map); + Error create_image_from_utf8_buffer(Ref<Image> p_image, const PackedByteArray &p_buffer, float p_scale, bool p_upsample); Error create_image_from_string(Ref<Image> p_image, String p_string, float p_scale, bool p_upsample, const HashMap<Color, Color> &p_color_map); virtual Error load_image(Ref<Image> p_image, Ref<FileAccess> p_fileaccess, BitField<ImageFormatLoader::LoaderFlags> p_flags, float p_scale) override; |