summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/config/project_settings.cpp171
-rw-r--r--core/config/project_settings.h14
-rw-r--r--core/core_bind.cpp31
-rw-r--r--core/core_bind.h7
-rw-r--r--core/core_constants.cpp83
-rw-r--r--core/crypto/crypto.cpp39
-rw-r--r--core/crypto/crypto.h34
-rw-r--r--core/debugger/script_debugger.cpp4
-rw-r--r--core/debugger/script_debugger.h1
-rw-r--r--core/doc_data.cpp12
-rw-r--r--core/doc_data.h2
-rw-r--r--core/error/error_macros.cpp4
-rw-r--r--core/error/error_macros.h48
-rw-r--r--core/extension/extension_api_dump.cpp18
-rw-r--r--core/extension/gdextension_interface.cpp90
-rw-r--r--core/extension/gdextension_interface.h22
-rw-r--r--core/input/input.cpp43
-rw-r--r--core/input/input.h6
-rw-r--r--core/input/input_builders.py2
-rw-r--r--core/input/input_event.cpp127
-rw-r--r--core/input/input_event.h8
-rw-r--r--core/io/dtls_server.cpp2
-rw-r--r--core/io/dtls_server.h2
-rw-r--r--core/io/file_access.cpp12
-rw-r--r--core/io/file_access.h4
-rw-r--r--core/io/http_client.cpp2
-rw-r--r--core/io/http_client.h3
-rw-r--r--core/io/http_client_tcp.cpp33
-rw-r--r--core/io/http_client_tcp.h7
-rw-r--r--core/io/image.cpp46
-rw-r--r--core/io/image.h18
-rw-r--r--core/io/image_loader.cpp4
-rw-r--r--core/io/image_loader.h2
-rw-r--r--core/io/json.cpp33
-rw-r--r--core/io/json.h9
-rw-r--r--core/io/marshalls.h2
-rw-r--r--core/io/packet_peer_dtls.cpp2
-rw-r--r--core/io/packet_peer_dtls.h2
-rw-r--r--core/io/resource.cpp43
-rw-r--r--core/io/resource.h2
-rw-r--r--core/io/resource_format_binary.cpp97
-rw-r--r--core/io/resource_format_binary.h5
-rw-r--r--core/io/resource_loader.cpp27
-rw-r--r--core/io/resource_loader.h4
-rw-r--r--core/io/resource_saver.cpp7
-rw-r--r--core/io/resource_saver.h1
-rw-r--r--core/io/stream_peer_tls.cpp20
-rw-r--r--core/io/stream_peer_tls.h11
-rw-r--r--core/io/xml_parser.cpp10
-rw-r--r--core/io/xml_parser.h4
-rw-r--r--core/math/a_star.cpp50
-rw-r--r--core/math/a_star.h2
-rw-r--r--core/math/a_star_grid_2d.cpp16
-rw-r--r--core/math/a_star_grid_2d.h2
-rw-r--r--core/math/basis.cpp25
-rw-r--r--core/math/basis.h4
-rw-r--r--core/math/bvh.h10
-rw-r--r--core/math/bvh_abb.h2
-rw-r--r--core/math/bvh_split.inc8
-rw-r--r--core/math/color.cpp2
-rw-r--r--core/math/delaunay_3d.h12
-rw-r--r--core/math/expression.cpp9
-rw-r--r--core/math/face3.cpp40
-rw-r--r--core/math/face3.h5
-rw-r--r--core/math/geometry_2d.cpp35
-rw-r--r--core/math/geometry_2d.h1
-rw-r--r--core/math/geometry_3d.cpp173
-rw-r--r--core/math/geometry_3d.h2
-rw-r--r--core/math/plane.h2
-rw-r--r--core/math/transform_2d.cpp45
-rw-r--r--core/math/transform_2d.h1
-rw-r--r--core/math/triangle_mesh.cpp196
-rw-r--r--core/math/triangle_mesh.h2
-rw-r--r--core/object/make_virtuals.py4
-rw-r--r--core/object/object.cpp6
-rw-r--r--core/object/object.h29
-rw-r--r--core/object/script_language.cpp86
-rw-r--r--core/object/script_language.h10
-rw-r--r--core/object/script_language_extension.h1
-rw-r--r--core/object/undo_redo.cpp3
-rw-r--r--core/object/worker_thread_pool.cpp12
-rw-r--r--core/os/keyboard.cpp122
-rw-r--r--core/os/keyboard.h94
-rw-r--r--core/os/mutex.h5
-rw-r--r--core/os/os.cpp26
-rw-r--r--core/os/os.h13
-rw-r--r--core/os/rw_lock.h38
-rw-r--r--core/os/semaphore.h29
-rw-r--r--core/register_core_types.cpp1
-rw-r--r--core/string/ustring.cpp20
-rw-r--r--core/string/ustring.h1
-rw-r--r--core/templates/local_vector.h64
-rw-r--r--core/variant/array.cpp147
-rw-r--r--core/variant/array.h11
-rw-r--r--core/variant/container_type_validate.h11
-rw-r--r--core/variant/dictionary.cpp10
-rw-r--r--core/variant/dictionary.h2
-rw-r--r--core/variant/typed_array.h42
-rw-r--r--core/variant/variant.cpp40
-rw-r--r--core/variant/variant.h2
-rw-r--r--core/variant/variant_call.cpp21
-rw-r--r--core/variant/variant_internal.h19
-rw-r--r--core/variant/variant_parser.cpp148
-rw-r--r--core/variant/variant_setget.cpp29
-rw-r--r--core/variant/variant_utility.cpp7
105 files changed, 1531 insertions, 1346 deletions
diff --git a/core/config/project_settings.cpp b/core/config/project_settings.cpp
index 264883ffa8..6a1d802453 100644
--- a/core/config/project_settings.cpp
+++ b/core/config/project_settings.cpp
@@ -33,6 +33,7 @@
#include "core/core_bind.h" // For Compression enum.
#include "core/core_string_names.h"
#include "core/input/input_map.h"
+#include "core/io/config_file.h"
#include "core/io/dir_access.h"
#include "core/io/file_access.h"
#include "core/io/file_access_network.h"
@@ -293,31 +294,26 @@ bool ProjectSettings::_set(const StringName &p_name, const Variant &p_value) {
return true;
}
- if (!disable_feature_overrides) {
+ { // Feature overrides.
int dot = p_name.operator String().find(".");
if (dot != -1) {
Vector<String> s = p_name.operator String().split(".");
- bool override_valid = false;
for (int i = 1; i < s.size(); i++) {
String feature = s[i].strip_edges();
- if (OS::get_singleton()->has_feature(feature) || custom_features.has(feature)) {
- override_valid = true;
- break;
+ Pair<StringName, StringName> fo(feature, p_name);
+
+ if (!feature_overrides.has(s[0])) {
+ feature_overrides[s[0]] = LocalVector<Pair<StringName, StringName>>();
}
- }
- if (override_valid) {
- feature_overrides[s[0]] = p_name;
+ feature_overrides[s[0]].push_back(fo);
}
}
}
if (props.has(p_name)) {
- if (!props[p_name].overridden) {
- props[p_name].variant = p_value;
- }
-
+ props[p_name].variant = p_value;
} else {
props[p_name] = VariantContainer(p_value, last_order++);
}
@@ -342,16 +338,35 @@ bool ProjectSettings::_set(const StringName &p_name, const Variant &p_value) {
bool ProjectSettings::_get(const StringName &p_name, Variant &r_ret) const {
_THREAD_SAFE_METHOD_
+ if (!props.has(p_name)) {
+ WARN_PRINT("Property not found: " + String(p_name));
+ return false;
+ }
+ r_ret = props[p_name].variant;
+ return true;
+}
+
+Variant ProjectSettings::get_setting_with_override(const StringName &p_name) const {
+ _THREAD_SAFE_METHOD_
+
StringName name = p_name;
- if (!disable_feature_overrides && feature_overrides.has(name)) {
- name = feature_overrides[name];
+ if (feature_overrides.has(name)) {
+ const LocalVector<Pair<StringName, StringName>> &overrides = feature_overrides[name];
+ for (uint32_t i = 0; i < overrides.size(); i++) {
+ if (OS::get_singleton()->has_feature(overrides[i].first)) { // Custom features are checked in OS.has_feature() already. No need to check twice.
+ if (props.has(overrides[i].second)) {
+ name = overrides[i].second;
+ break;
+ }
+ }
+ }
}
+
if (!props.has(name)) {
WARN_PRINT("Property not found: " + String(name));
- return false;
+ return Variant();
}
- r_ret = props[name].variant;
- return true;
+ return props[name].variant;
}
struct _VCSort {
@@ -1056,23 +1071,6 @@ Variant _GLOBAL_DEF(const PropertyInfo &p_info, const Variant &p_default, bool p
return ret;
}
-Vector<String> ProjectSettings::get_optimizer_presets() const {
- List<PropertyInfo> pi;
- ProjectSettings::get_singleton()->get_property_list(&pi);
- Vector<String> names;
-
- for (const PropertyInfo &E : pi) {
- if (!E.name.begins_with("optimizer_presets/")) {
- continue;
- }
- names.push_back(E.name.get_slicec('/', 1));
- }
-
- names.sort();
-
- return names;
-}
-
void ProjectSettings::_add_property_info_bind(const Dictionary &p_info) {
ERR_FAIL_COND(!p_info.has("name"));
ERR_FAIL_COND(!p_info.has("type"));
@@ -1103,10 +1101,6 @@ const HashMap<StringName, PropertyInfo> &ProjectSettings::get_custom_property_in
return custom_prop_info;
}
-void ProjectSettings::set_disable_feature_overrides(bool p_disable) {
- disable_feature_overrides = p_disable;
-}
-
bool ProjectSettings::is_using_datapack() const {
return using_datapack;
}
@@ -1142,6 +1136,33 @@ Variant ProjectSettings::get_setting(const String &p_setting, const Variant &p_d
}
}
+Array ProjectSettings::get_global_class_list() {
+ Array script_classes;
+
+ Ref<ConfigFile> cf;
+ cf.instantiate();
+ if (cf->load(get_global_class_list_path()) == OK) {
+ script_classes = cf->get_value("", "list", Array());
+ } else {
+#ifndef TOOLS_ENABLED
+ // Script classes can't be recreated in exported project, so print an error.
+ ERR_PRINT("Could not load global script cache.");
+#endif
+ }
+ return script_classes;
+}
+
+String ProjectSettings::get_global_class_list_path() const {
+ return get_project_data_path().path_join("global_script_class_cache.cfg");
+}
+
+void ProjectSettings::store_global_class_list(const Array &p_classes) {
+ Ref<ConfigFile> cf;
+ cf.instantiate();
+ cf->set_value("", "list", p_classes);
+ cf->save(get_global_class_list_path());
+}
+
bool ProjectSettings::has_custom_feature(const String &p_feature) const {
return custom_features.has(p_feature);
}
@@ -1173,6 +1194,7 @@ void ProjectSettings::_bind_methods() {
ClassDB::bind_method(D_METHOD("has_setting", "name"), &ProjectSettings::has_setting);
ClassDB::bind_method(D_METHOD("set_setting", "name", "value"), &ProjectSettings::set_setting);
ClassDB::bind_method(D_METHOD("get_setting", "name", "default_value"), &ProjectSettings::get_setting, DEFVAL(Variant()));
+ ClassDB::bind_method(D_METHOD("get_setting_with_override", "name"), &ProjectSettings::get_setting_with_override);
ClassDB::bind_method(D_METHOD("set_order", "name", "position"), &ProjectSettings::set_order);
ClassDB::bind_method(D_METHOD("get_order", "name"), &ProjectSettings::get_order);
ClassDB::bind_method(D_METHOD("set_initial_value", "name", "value"), &ProjectSettings::set_initial_value);
@@ -1218,12 +1240,9 @@ ProjectSettings::ProjectSettings() {
singleton = this;
GLOBAL_DEF_BASIC("application/config/name", "");
- GLOBAL_DEF_BASIC("application/config/name_localized", Dictionary());
- custom_prop_info["application/config/name_localized"] = PropertyInfo(Variant::DICTIONARY, "application/config/name_localized", PROPERTY_HINT_LOCALIZABLE_STRING);
- GLOBAL_DEF_BASIC("application/config/description", "");
- custom_prop_info["application/config/description"] = PropertyInfo(Variant::STRING, "application/config/description", PROPERTY_HINT_MULTILINE_TEXT);
- GLOBAL_DEF_BASIC("application/run/main_scene", "");
- custom_prop_info["application/run/main_scene"] = PropertyInfo(Variant::STRING, "application/run/main_scene", PROPERTY_HINT_FILE, "*.tscn,*.scn,*.res");
+ GLOBAL_DEF_BASIC(PropertyInfo(Variant::DICTIONARY, "application/config/name_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary());
+ GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "application/config/description", PROPERTY_HINT_MULTILINE_TEXT), "");
+ GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "application/run/main_scene", PROPERTY_HINT_FILE, "*.tscn,*.scn,*.res"), "");
GLOBAL_DEF("application/run/disable_stdout", false);
GLOBAL_DEF("application/run/disable_stderr", false);
GLOBAL_DEF_RST("application/config/use_hidden_project_data_directory", true);
@@ -1235,22 +1254,15 @@ ProjectSettings::ProjectSettings() {
// - Have a 16:9 aspect ratio,
// - Have both dimensions divisible by 8 to better play along with video recording,
// - Be displayable correctly in windowed mode on a 1366×768 display (tested on Windows 10 with default settings).
- GLOBAL_DEF_BASIC("display/window/size/viewport_width", 1152);
- custom_prop_info["display/window/size/viewport_width"] = PropertyInfo(Variant::INT, "display/window/size/viewport_width", PROPERTY_HINT_RANGE, "0,7680,1,or_greater"); // 8K resolution
+ GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "display/window/size/viewport_width", PROPERTY_HINT_RANGE, "0,7680,1,or_greater"), 1152); // 8K resolution
+ GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "display/window/size/viewport_height", PROPERTY_HINT_RANGE, "0,4320,1,or_greater"), 648); // 8K resolution
- GLOBAL_DEF_BASIC("display/window/size/viewport_height", 648);
- custom_prop_info["display/window/size/viewport_height"] = PropertyInfo(Variant::INT, "display/window/size/viewport_height", PROPERTY_HINT_RANGE, "0,4320,1,or_greater"); // 8K resolution
-
- GLOBAL_DEF_BASIC("display/window/size/mode", 0);
- custom_prop_info["display/window/size/mode"] = PropertyInfo(Variant::INT, "display/window/size/mode", PROPERTY_HINT_ENUM, "Windowed,Minimized,Maximized,Fullscreen,Exclusive Fullscreen");
+ GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "display/window/size/mode", PROPERTY_HINT_ENUM, "Windowed,Minimized,Maximized,Fullscreen,Exclusive Fullscreen"), 0);
// Keep the enum values in sync with the `DisplayServer::SCREEN_` enum.
- GLOBAL_DEF_BASIC("display/window/size/initial_screen", -2);
- String screen_hints = "Primary Monitor:-2"; // Note: Main Window Monitor:-1 is not used for the main window, skip it.
- for (int i = 0; i < 64; i++) {
- screen_hints += ",Monitor " + itos(i + 1) + ":" + itos(i);
- }
- custom_prop_info["display/window/size/initial_screen"] = PropertyInfo(Variant::INT, "display/window/size/initial_screen", PROPERTY_HINT_ENUM, screen_hints);
+ GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "display/window/size/initial_position_type", PROPERTY_HINT_ENUM, "Absolute,Primary Screen Center,Other Screen Center"), 1);
+ GLOBAL_DEF_BASIC(PropertyInfo(Variant::VECTOR2I, "display/window/size/initial_position"), Vector2i());
+ GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "display/window/size/initial_screen", PROPERTY_HINT_RANGE, "0,64,1,or_greater"), 0);
GLOBAL_DEF_BASIC("display/window/size/resizable", true);
GLOBAL_DEF_BASIC("display/window/size/borderless", false);
@@ -1259,20 +1271,15 @@ ProjectSettings::ProjectSettings() {
GLOBAL_DEF("display/window/size/extend_to_title", false);
GLOBAL_DEF("display/window/size/no_focus", false);
- GLOBAL_DEF("display/window/size/window_width_override", 0);
- custom_prop_info["display/window/size/window_width_override"] = PropertyInfo(Variant::INT, "display/window/size/window_width_override", PROPERTY_HINT_RANGE, "0,7680,1,or_greater"); // 8K resolution
- GLOBAL_DEF("display/window/size/window_height_override", 0);
- custom_prop_info["display/window/size/window_height_override"] = PropertyInfo(Variant::INT, "display/window/size/window_height_override", PROPERTY_HINT_RANGE, "0,4320,1,or_greater"); // 8K resolution
+ GLOBAL_DEF(PropertyInfo(Variant::INT, "display/window/size/window_width_override", PROPERTY_HINT_RANGE, "0,7680,1,or_greater"), 0); // 8K resolution
+ GLOBAL_DEF(PropertyInfo(Variant::INT, "display/window/size/window_height_override", PROPERTY_HINT_RANGE, "0,4320,1,or_greater"), 0); // 8K resolution
GLOBAL_DEF("display/window/energy_saving/keep_screen_on", true);
GLOBAL_DEF("display/window/energy_saving/keep_screen_on.editor", false);
- GLOBAL_DEF_BASIC("audio/buses/default_bus_layout", "res://default_bus_layout.tres");
- custom_prop_info["audio/buses/default_bus_layout"] = PropertyInfo(Variant::STRING, "audio/buses/default_bus_layout", PROPERTY_HINT_FILE, "*.tres");
- GLOBAL_DEF_RST("audio/general/2d_panning_strength", 0.5f);
- custom_prop_info["audio/general/2d_panning_strength"] = PropertyInfo(Variant::FLOAT, "audio/general/2d_panning_strength", PROPERTY_HINT_RANGE, "0,2,0.01");
- GLOBAL_DEF_RST("audio/general/3d_panning_strength", 0.5f);
- custom_prop_info["audio/general/3d_panning_strength"] = PropertyInfo(Variant::FLOAT, "audio/general/3d_panning_strength", PROPERTY_HINT_RANGE, "0,2,0.01");
+ GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "audio/buses/default_bus_layout", PROPERTY_HINT_FILE, "*.tres"), "res://default_bus_layout.tres");
+ GLOBAL_DEF_RST(PropertyInfo(Variant::FLOAT, "audio/general/2d_panning_strength", PROPERTY_HINT_RANGE, "0,2,0.01"), 0.5f);
+ GLOBAL_DEF_RST(PropertyInfo(Variant::FLOAT, "audio/general/3d_panning_strength", PROPERTY_HINT_RANGE, "0,2,0.01"), 0.5f);
PackedStringArray extensions;
extensions.push_back("gd");
@@ -1283,11 +1290,13 @@ ProjectSettings::ProjectSettings() {
GLOBAL_DEF("editor/run/main_run_args", "");
- GLOBAL_DEF("editor/script/search_in_file_extensions", extensions);
- custom_prop_info["editor/script/search_in_file_extensions"] = PropertyInfo(Variant::PACKED_STRING_ARRAY, "editor/script/search_in_file_extensions");
+ GLOBAL_DEF(PropertyInfo(Variant::PACKED_STRING_ARRAY, "editor/script/search_in_file_extensions"), extensions);
+
+ GLOBAL_DEF(PropertyInfo(Variant::STRING, "editor/script/templates_search_path", PROPERTY_HINT_DIR), "res://script_templates");
- GLOBAL_DEF("editor/script/templates_search_path", "res://script_templates");
- custom_prop_info["editor/script/templates_search_path"] = PropertyInfo(Variant::STRING, "editor/script/templates_search_path", PROPERTY_HINT_DIR);
+ // For correct doc generation.
+ GLOBAL_DEF("editor/naming/default_signal_callback_name", "_on_{node_name}_{signal_name}");
+ GLOBAL_DEF("editor/naming/default_signal_callback_to_self_name", "_on_{signal_name}");
_add_builtin_input_map();
@@ -1299,21 +1308,13 @@ ProjectSettings::ProjectSettings() {
GLOBAL_DEF("physics/2d/run_on_separate_thread", false);
GLOBAL_DEF("physics/3d/run_on_separate_thread", false);
- GLOBAL_DEF("debug/settings/profiler/max_functions", 16384);
- custom_prop_info["debug/settings/profiler/max_functions"] = PropertyInfo(Variant::INT, "debug/settings/profiler/max_functions", PROPERTY_HINT_RANGE, "128,65535,1");
-
- GLOBAL_DEF("compression/formats/zstd/long_distance_matching", Compression::zstd_long_distance_matching);
- custom_prop_info["compression/formats/zstd/long_distance_matching"] = PropertyInfo(Variant::BOOL, "compression/formats/zstd/long_distance_matching");
- GLOBAL_DEF("compression/formats/zstd/compression_level", Compression::zstd_level);
- custom_prop_info["compression/formats/zstd/compression_level"] = PropertyInfo(Variant::INT, "compression/formats/zstd/compression_level", PROPERTY_HINT_RANGE, "1,22,1");
- GLOBAL_DEF("compression/formats/zstd/window_log_size", Compression::zstd_window_log_size);
- custom_prop_info["compression/formats/zstd/window_log_size"] = PropertyInfo(Variant::INT, "compression/formats/zstd/window_log_size", PROPERTY_HINT_RANGE, "10,30,1");
-
- GLOBAL_DEF("compression/formats/zlib/compression_level", Compression::zlib_level);
- custom_prop_info["compression/formats/zlib/compression_level"] = PropertyInfo(Variant::INT, "compression/formats/zlib/compression_level", PROPERTY_HINT_RANGE, "-1,9,1");
+ GLOBAL_DEF(PropertyInfo(Variant::INT, "debug/settings/profiler/max_functions", PROPERTY_HINT_RANGE, "128,65535,1"), 16384);
- GLOBAL_DEF("compression/formats/gzip/compression_level", Compression::gzip_level);
- custom_prop_info["compression/formats/gzip/compression_level"] = PropertyInfo(Variant::INT, "compression/formats/gzip/compression_level", PROPERTY_HINT_RANGE, "-1,9,1");
+ GLOBAL_DEF(PropertyInfo(Variant::BOOL, "compression/formats/zstd/long_distance_matching"), Compression::zstd_long_distance_matching);
+ GLOBAL_DEF(PropertyInfo(Variant::INT, "compression/formats/zstd/compression_level", PROPERTY_HINT_RANGE, "1,22,1"), Compression::zstd_level);
+ GLOBAL_DEF(PropertyInfo(Variant::INT, "compression/formats/zstd/window_log_size", PROPERTY_HINT_RANGE, "10,30,1"), Compression::zstd_window_log_size);
+ GLOBAL_DEF(PropertyInfo(Variant::INT, "compression/formats/zlib/compression_level", PROPERTY_HINT_RANGE, "-1,9,1"), Compression::zlib_level);
+ GLOBAL_DEF(PropertyInfo(Variant::INT, "compression/formats/gzip/compression_level", PROPERTY_HINT_RANGE, "-1,9,1"), Compression::gzip_level);
GLOBAL_DEF("debug/settings/crash_handler/message",
String("Please include this when reporting the bug to the project developer."));
diff --git a/core/config/project_settings.h b/core/config/project_settings.h
index 2aca1e7691..70f697741f 100644
--- a/core/config/project_settings.h
+++ b/core/config/project_settings.h
@@ -34,6 +34,7 @@
#include "core/object/class_db.h"
#include "core/os/thread_safe.h"
#include "core/templates/hash_map.h"
+#include "core/templates/local_vector.h"
#include "core/templates/rb_set.h"
class ProjectSettings : public Object {
@@ -69,7 +70,6 @@ protected:
Variant variant;
Variant initial;
bool hide_from_editor = false;
- bool overridden = false;
bool restart_if_changed = false;
#ifdef DEBUG_METHODS_ENABLED
bool ignore_value_in_docs = false;
@@ -91,12 +91,11 @@ protected:
RBMap<StringName, VariantContainer> props; // NOTE: Key order is used e.g. in the save_custom method.
String resource_path;
HashMap<StringName, PropertyInfo> custom_prop_info;
- bool disable_feature_overrides = false;
bool using_datapack = false;
List<String> input_presets;
HashSet<String> custom_features;
- HashMap<StringName, StringName> feature_overrides;
+ HashMap<StringName, LocalVector<Pair<StringName, StringName>>> feature_overrides;
HashMap<StringName, AutoloadInfo> autoloads;
@@ -142,6 +141,9 @@ public:
void set_setting(const String &p_setting, const Variant &p_value);
Variant get_setting(const String &p_setting, const Variant &p_default_value = Variant()) const;
+ Array get_global_class_list();
+ void store_global_class_list(const Array &p_classes);
+ String get_global_class_list_path() const;
bool has_setting(String p_var) const;
String localize_path(const String &p_path) const;
@@ -177,11 +179,9 @@ public:
const HashMap<StringName, PropertyInfo> &get_custom_property_info() const;
uint64_t get_last_saved_time() { return last_save_time; }
- Vector<String> get_optimizer_presets() const;
-
List<String> get_input_presets() const { return input_presets; }
- void set_disable_feature_overrides(bool p_disable);
+ Variant get_setting_with_override(const StringName &p_name) const;
bool is_using_datapack() const;
@@ -205,7 +205,7 @@ Variant _GLOBAL_DEF(const PropertyInfo &p_info, const Variant &p_default, bool p
#define GLOBAL_DEF_RST(m_var, m_value) _GLOBAL_DEF(m_var, m_value, true)
#define GLOBAL_DEF_NOVAL(m_var, m_value) _GLOBAL_DEF(m_var, m_value, false, true)
#define GLOBAL_DEF_RST_NOVAL(m_var, m_value) _GLOBAL_DEF(m_var, m_value, true, true)
-#define GLOBAL_GET(m_var) ProjectSettings::get_singleton()->get(m_var)
+#define GLOBAL_GET(m_var) ProjectSettings::get_singleton()->get_setting_with_override(m_var)
#define GLOBAL_DEF_BASIC(m_var, m_value) _GLOBAL_DEF(m_var, m_value, false, false, true)
#define GLOBAL_DEF_RST_BASIC(m_var, m_value) _GLOBAL_DEF(m_var, m_value, true, false, true)
diff --git a/core/core_bind.cpp b/core/core_bind.cpp
index ab433bd8f1..c752bdd057 100644
--- a/core/core_bind.cpp
+++ b/core/core_bind.cpp
@@ -322,8 +322,12 @@ String OS::get_environment(const String &p_var) const {
return ::OS::get_singleton()->get_environment(p_var);
}
-bool OS::set_environment(const String &p_var, const String &p_value) const {
- return ::OS::get_singleton()->set_environment(p_var, p_value);
+void OS::set_environment(const String &p_var, const String &p_value) const {
+ ::OS::get_singleton()->set_environment(p_var, p_value);
+}
+
+void OS::unset_environment(const String &p_var) const {
+ ::OS::get_singleton()->unset_environment(p_var);
}
String OS::get_name() const {
@@ -548,9 +552,10 @@ void OS::_bind_methods() {
ClassDB::bind_method(D_METHOD("is_process_running", "pid"), &OS::is_process_running);
ClassDB::bind_method(D_METHOD("get_process_id"), &OS::get_process_id);
+ ClassDB::bind_method(D_METHOD("has_environment", "variable"), &OS::has_environment);
ClassDB::bind_method(D_METHOD("get_environment", "variable"), &OS::get_environment);
ClassDB::bind_method(D_METHOD("set_environment", "variable", "value"), &OS::set_environment);
- ClassDB::bind_method(D_METHOD("has_environment", "variable"), &OS::has_environment);
+ ClassDB::bind_method(D_METHOD("unset_environment", "variable"), &OS::unset_environment);
ClassDB::bind_method(D_METHOD("get_name"), &OS::get_name);
ClassDB::bind_method(D_METHOD("get_distribution_name"), &OS::get_distribution_name);
@@ -712,7 +717,7 @@ TypedArray<PackedVector2Array> Geometry2D::decompose_polygon_in_convex(const Vec
TypedArray<PackedVector2Array> Geometry2D::merge_polygons(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b) {
Vector<Vector<Point2>> polys = ::Geometry2D::merge_polygons(p_polygon_a, p_polygon_b);
- Array ret;
+ TypedArray<PackedVector2Array> ret;
for (int i = 0; i < polys.size(); ++i) {
ret.push_back(polys[i]);
@@ -734,7 +739,7 @@ TypedArray<PackedVector2Array> Geometry2D::clip_polygons(const Vector<Vector2> &
TypedArray<PackedVector2Array> Geometry2D::intersect_polygons(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b) {
Vector<Vector<Point2>> polys = ::Geometry2D::intersect_polygons(p_polygon_a, p_polygon_b);
- Array ret;
+ TypedArray<PackedVector2Array> ret;
for (int i = 0; i < polys.size(); ++i) {
ret.push_back(polys[i]);
@@ -745,7 +750,7 @@ TypedArray<PackedVector2Array> Geometry2D::intersect_polygons(const Vector<Vecto
TypedArray<PackedVector2Array> Geometry2D::exclude_polygons(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b) {
Vector<Vector<Point2>> polys = ::Geometry2D::exclude_polygons(p_polygon_a, p_polygon_b);
- Array ret;
+ TypedArray<PackedVector2Array> ret;
for (int i = 0; i < polys.size(); ++i) {
ret.push_back(polys[i]);
@@ -756,7 +761,7 @@ TypedArray<PackedVector2Array> Geometry2D::exclude_polygons(const Vector<Vector2
TypedArray<PackedVector2Array> Geometry2D::clip_polyline_with_polygon(const Vector<Vector2> &p_polyline, const Vector<Vector2> &p_polygon) {
Vector<Vector<Point2>> polys = ::Geometry2D::clip_polyline_with_polygon(p_polyline, p_polygon);
- Array ret;
+ TypedArray<PackedVector2Array> ret;
for (int i = 0; i < polys.size(); ++i) {
ret.push_back(polys[i]);
@@ -767,7 +772,7 @@ TypedArray<PackedVector2Array> Geometry2D::clip_polyline_with_polygon(const Vect
TypedArray<PackedVector2Array> Geometry2D::intersect_polyline_with_polygon(const Vector<Vector2> &p_polyline, const Vector<Vector2> &p_polygon) {
Vector<Vector<Point2>> polys = ::Geometry2D::intersect_polyline_with_polygon(p_polyline, p_polygon);
- Array ret;
+ TypedArray<PackedVector2Array> ret;
for (int i = 0; i < polys.size(); ++i) {
ret.push_back(polys[i]);
@@ -778,7 +783,7 @@ TypedArray<PackedVector2Array> Geometry2D::intersect_polyline_with_polygon(const
TypedArray<PackedVector2Array> Geometry2D::offset_polygon(const Vector<Vector2> &p_polygon, real_t p_delta, PolyJoinType p_join_type) {
Vector<Vector<Point2>> polys = ::Geometry2D::offset_polygon(p_polygon, p_delta, ::Geometry2D::PolyJoinType(p_join_type));
- Array ret;
+ TypedArray<PackedVector2Array> ret;
for (int i = 0; i < polys.size(); ++i) {
ret.push_back(polys[i]);
@@ -789,7 +794,7 @@ TypedArray<PackedVector2Array> Geometry2D::offset_polygon(const Vector<Vector2>
TypedArray<PackedVector2Array> Geometry2D::offset_polyline(const Vector<Vector2> &p_polygon, real_t p_delta, PolyJoinType p_join_type, PolyEndType p_end_type) {
Vector<Vector<Point2>> polys = ::Geometry2D::offset_polyline(p_polygon, p_delta, ::Geometry2D::PolyJoinType(p_join_type), ::Geometry2D::PolyEndType(p_end_type));
- Array ret;
+ TypedArray<PackedVector2Array> ret;
for (int i = 0; i < polys.size(); ++i) {
ret.push_back(polys[i]);
@@ -1100,8 +1105,8 @@ void Semaphore::wait() {
semaphore.wait();
}
-Error Semaphore::try_wait() {
- return semaphore.try_wait() ? OK : ERR_BUSY;
+bool Semaphore::try_wait() {
+ return semaphore.try_wait();
}
void Semaphore::post() {
@@ -1120,7 +1125,7 @@ void Mutex::lock() {
mutex.lock();
}
-Error Mutex::try_lock() {
+bool Mutex::try_lock() {
return mutex.try_lock();
}
diff --git a/core/core_bind.h b/core/core_bind.h
index 7ef346d1c4..8852463234 100644
--- a/core/core_bind.h
+++ b/core/core_bind.h
@@ -162,7 +162,8 @@ public:
bool has_environment(const String &p_var) const;
String get_environment(const String &p_var) const;
- bool set_environment(const String &p_var, const String &p_value) const;
+ void set_environment(const String &p_var, const String &p_value) const;
+ void unset_environment(const String &p_var) const;
String get_name() const;
String get_distribution_name() const;
@@ -360,7 +361,7 @@ class Mutex : public RefCounted {
public:
void lock();
- Error try_lock();
+ bool try_lock();
void unlock();
};
@@ -372,7 +373,7 @@ class Semaphore : public RefCounted {
public:
void wait();
- Error try_wait();
+ bool try_wait();
void post();
};
diff --git a/core/core_constants.cpp b/core/core_constants.cpp
index edb72f73cb..b1f56539e5 100644
--- a/core/core_constants.cpp
+++ b/core/core_constants.cpp
@@ -274,14 +274,9 @@ void register_global_constants() {
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, KP_7);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, KP_8);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, KP_9);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, SUPER_L);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, SUPER_R);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, MENU);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, HYPER_L);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, HYPER_R);
+ BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, HYPER);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, HELP);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, DIRECTION_L);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, DIRECTION_R);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, BACK);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, FORWARD);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, STOP);
@@ -289,11 +284,6 @@ void register_global_constants() {
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, VOLUMEDOWN);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, VOLUMEMUTE);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, VOLUMEUP);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, BASSBOOST);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, BASSUP);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, BASSDOWN);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, TREBLEUP);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, TREBLEDOWN);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, MEDIAPLAY);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, MEDIASTOP);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, MEDIAPREVIOUS);
@@ -392,72 +382,12 @@ void register_global_constants() {
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, BAR);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, BRACERIGHT);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ASCIITILDE);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, NOBREAKSPACE);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, EXCLAMDOWN);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, CENT);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, STERLING);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, CURRENCY);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, YEN);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, BROKENBAR);
BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, SECTION);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, DIAERESIS);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, COPYRIGHT);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ORDFEMININE);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, GUILLEMOTLEFT);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, NOTSIGN);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, HYPHEN);
- BIND_CORE_ENUM_CLASS_CONSTANT_CUSTOM(Key, KEY_REGISTERED, KEY_REGISTERED);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, MACRON);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, DEGREE);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, PLUSMINUS);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, TWOSUPERIOR);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, THREESUPERIOR);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ACUTE);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, MU);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, PARAGRAPH);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, PERIODCENTERED);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, CEDILLA);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ONESUPERIOR);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, MASCULINE);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, GUILLEMOTRIGHT);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ONEQUARTER);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ONEHALF);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, THREEQUARTERS);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, QUESTIONDOWN);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, AGRAVE);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, AACUTE);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ACIRCUMFLEX);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ATILDE);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ADIAERESIS);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ARING);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, AE);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, CCEDILLA);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, EGRAVE);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, EACUTE);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ECIRCUMFLEX);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, EDIAERESIS);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, IGRAVE);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, IACUTE);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ICIRCUMFLEX);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, IDIAERESIS);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ETH);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, NTILDE);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, OGRAVE);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, OACUTE);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, OCIRCUMFLEX);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, OTILDE);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ODIAERESIS);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, MULTIPLY);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, OOBLIQUE);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, UGRAVE);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, UACUTE);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, UCIRCUMFLEX);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, UDIAERESIS);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, YACUTE);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, THORN);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, SSHARP);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, DIVISION);
- BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, YDIAERESIS);
+ BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, GLOBE);
+ BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, KEYBOARD);
+ BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, JIS_EISU);
+ BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, JIS_KANA);
BIND_CORE_BITFIELD_CLASS_FLAG_CUSTOM(KeyModifierMask, KEY_CODE_MASK, CODE_MASK);
BIND_CORE_BITFIELD_CLASS_FLAG_CUSTOM(KeyModifierMask, KEY_MODIFIER_MASK, MODIFIER_MASK);
@@ -656,7 +586,8 @@ void register_global_constants() {
BIND_CORE_BITFIELD_FLAG(PROPERTY_USAGE_CLASS_IS_ENUM);
BIND_CORE_BITFIELD_FLAG(PROPERTY_USAGE_NIL_IS_VARIANT);
BIND_CORE_BITFIELD_FLAG(PROPERTY_USAGE_ARRAY);
- BIND_CORE_BITFIELD_FLAG(PROPERTY_USAGE_DO_NOT_SHARE_ON_DUPLICATE);
+ BIND_CORE_BITFIELD_FLAG(PROPERTY_USAGE_ALWAYS_DUPLICATE);
+ BIND_CORE_BITFIELD_FLAG(PROPERTY_USAGE_NEVER_DUPLICATE);
BIND_CORE_BITFIELD_FLAG(PROPERTY_USAGE_HIGH_END_GFX);
BIND_CORE_BITFIELD_FLAG(PROPERTY_USAGE_NODE_PATH_FROM_SCENE_ROOT);
BIND_CORE_BITFIELD_FLAG(PROPERTY_USAGE_RESOURCE_NOT_PERSISTENT);
diff --git a/core/crypto/crypto.cpp b/core/crypto/crypto.cpp
index cbb18a277f..939c1c298f 100644
--- a/core/crypto/crypto.cpp
+++ b/core/crypto/crypto.cpp
@@ -65,6 +65,45 @@ void X509Certificate::_bind_methods() {
ClassDB::bind_method(D_METHOD("load", "path"), &X509Certificate::load);
}
+/// TLSOptions
+
+Ref<TLSOptions> TLSOptions::client(Ref<X509Certificate> p_trusted_chain, const String &p_common_name_override) {
+ Ref<TLSOptions> opts;
+ opts.instantiate();
+ opts->trusted_ca_chain = p_trusted_chain;
+ opts->common_name = p_common_name_override;
+ opts->verify_mode = TLS_VERIFY_FULL;
+ return opts;
+}
+
+Ref<TLSOptions> TLSOptions::client_unsafe(Ref<X509Certificate> p_trusted_chain) {
+ Ref<TLSOptions> opts;
+ opts.instantiate();
+ opts->trusted_ca_chain = p_trusted_chain;
+ if (p_trusted_chain.is_null()) {
+ opts->verify_mode = TLS_VERIFY_NONE;
+ } else {
+ opts->verify_mode = TLS_VERIFY_CERT;
+ }
+ return opts;
+}
+
+Ref<TLSOptions> TLSOptions::server(Ref<CryptoKey> p_own_key, Ref<X509Certificate> p_own_certificate) {
+ Ref<TLSOptions> opts;
+ opts.instantiate();
+ opts->server_mode = true;
+ opts->own_certificate = p_own_certificate;
+ opts->private_key = p_own_key;
+ opts->verify_mode = TLS_VERIFY_NONE;
+ return opts;
+}
+
+void TLSOptions::_bind_methods() {
+ ClassDB::bind_static_method("TLSOptions", D_METHOD("client", "trusted_chain", "common_name_override"), &TLSOptions::client, DEFVAL(Ref<X509Certificate>()), DEFVAL(String()));
+ ClassDB::bind_static_method("TLSOptions", D_METHOD("client_unsafe", "trusted_chain"), &TLSOptions::client_unsafe, DEFVAL(Ref<X509Certificate>()));
+ ClassDB::bind_static_method("TLSOptions", D_METHOD("server", "key", "certificate"), &TLSOptions::server);
+}
+
/// HMACContext
void HMACContext::_bind_methods() {
diff --git a/core/crypto/crypto.h b/core/crypto/crypto.h
index 981f67883c..999fe076d6 100644
--- a/core/crypto/crypto.h
+++ b/core/crypto/crypto.h
@@ -67,6 +67,40 @@ public:
virtual Error save(String p_path) = 0;
};
+class TLSOptions : public RefCounted {
+ GDCLASS(TLSOptions, RefCounted);
+
+public:
+ enum TLSVerifyMode {
+ TLS_VERIFY_NONE = 0,
+ TLS_VERIFY_CERT = 1,
+ TLS_VERIFY_FULL = 2,
+ };
+
+private:
+ bool server_mode = false;
+ String common_name;
+ TLSVerifyMode verify_mode = TLS_VERIFY_FULL;
+ Ref<X509Certificate> trusted_ca_chain;
+ Ref<X509Certificate> own_certificate;
+ Ref<CryptoKey> private_key;
+
+protected:
+ static void _bind_methods();
+
+public:
+ static Ref<TLSOptions> client(Ref<X509Certificate> p_trusted_chain = Ref<X509Certificate>(), const String &p_common_name_override = String());
+ static Ref<TLSOptions> client_unsafe(Ref<X509Certificate> p_trusted_chain);
+ static Ref<TLSOptions> server(Ref<CryptoKey> p_own_key, Ref<X509Certificate> p_own_certificate);
+
+ TLSVerifyMode get_verify_mode() const { return verify_mode; }
+ String get_common_name() const { return common_name; }
+ Ref<X509Certificate> get_trusted_ca_chain() const { return trusted_ca_chain; }
+ Ref<X509Certificate> get_own_certificate() const { return own_certificate; }
+ Ref<CryptoKey> get_private_key() const { return private_key; }
+ bool is_server() const { return server_mode; }
+};
+
class HMACContext : public RefCounted {
GDCLASS(HMACContext, RefCounted);
diff --git a/core/debugger/script_debugger.cpp b/core/debugger/script_debugger.cpp
index 8af1573bff..32725b76c1 100644
--- a/core/debugger/script_debugger.cpp
+++ b/core/debugger/script_debugger.cpp
@@ -73,10 +73,6 @@ bool ScriptDebugger::is_breakpoint(int p_line, const StringName &p_source) const
return breakpoints[p_line].has(p_source);
}
-bool ScriptDebugger::is_breakpoint_line(int p_line) const {
- return breakpoints.has(p_line);
-}
-
String ScriptDebugger::breakpoint_find_source(const String &p_source) const {
return p_source;
}
diff --git a/core/debugger/script_debugger.h b/core/debugger/script_debugger.h
index c7aa90027b..edce089179 100644
--- a/core/debugger/script_debugger.h
+++ b/core/debugger/script_debugger.h
@@ -64,7 +64,6 @@ public:
void insert_breakpoint(int p_line, const StringName &p_source);
void remove_breakpoint(int p_line, const StringName &p_source);
bool is_breakpoint(int p_line, const StringName &p_source) const;
- bool is_breakpoint_line(int p_line) const;
void clear_breakpoints();
const HashMap<int, HashSet<StringName>> &get_breakpoints() const { return breakpoints; }
diff --git a/core/doc_data.cpp b/core/doc_data.cpp
index f90dbe1423..5e09e560d5 100644
--- a/core/doc_data.cpp
+++ b/core/doc_data.cpp
@@ -30,6 +30,14 @@
#include "doc_data.h"
+String DocData::get_default_value_string(const Variant &p_value) {
+ if (p_value.get_type() == Variant::ARRAY) {
+ return Variant(Array(p_value, 0, StringName(), Variant())).get_construct_string().replace("\n", " ");
+ } else {
+ return p_value.get_construct_string().replace("\n", " ");
+ }
+}
+
void DocData::return_doc_from_retinfo(DocData::MethodDoc &p_method, const PropertyInfo &p_retinfo) {
if (p_retinfo.type == Variant::INT && p_retinfo.hint == PROPERTY_HINT_INT_IS_POINTER) {
p_method.return_type = p_retinfo.hint_string;
@@ -105,7 +113,7 @@ void DocData::property_doc_from_scriptmemberinfo(DocData::PropertyDoc &p_propert
p_property.getter = p_memberinfo.getter;
if (p_memberinfo.has_default_value && p_memberinfo.default_value.get_type() != Variant::OBJECT) {
- p_property.default_value = p_memberinfo.default_value.get_construct_string().replace("\n", "");
+ p_property.default_value = get_default_value_string(p_memberinfo.default_value);
}
p_property.overridden = false;
@@ -148,7 +156,7 @@ void DocData::method_doc_from_methodinfo(DocData::MethodDoc &p_method, const Met
int default_arg_index = i - (p_methodinfo.arguments.size() - p_methodinfo.default_arguments.size());
if (default_arg_index >= 0) {
Variant default_arg = p_methodinfo.default_arguments[default_arg_index];
- argument.default_value = default_arg.get_construct_string().replace("\n", "");
+ argument.default_value = get_default_value_string(default_arg);
}
p_method.arguments.push_back(argument);
}
diff --git a/core/doc_data.h b/core/doc_data.h
index 1cf4e4f206..c503a4e0d6 100644
--- a/core/doc_data.h
+++ b/core/doc_data.h
@@ -516,6 +516,8 @@ public:
}
};
+ static String get_default_value_string(const Variant &p_value);
+
static void return_doc_from_retinfo(DocData::MethodDoc &p_method, const PropertyInfo &p_retinfo);
static void argument_doc_from_arginfo(DocData::ArgumentDoc &p_argument, const PropertyInfo &p_arginfo);
static void property_doc_from_scriptmemberinfo(DocData::PropertyDoc &p_property, const ScriptMemberInfo &p_memberinfo);
diff --git a/core/error/error_macros.cpp b/core/error/error_macros.cpp
index ddfee3fc5d..8376c0aaf8 100644
--- a/core/error/error_macros.cpp
+++ b/core/error/error_macros.cpp
@@ -118,11 +118,11 @@ void _err_print_error(const char *p_function, const char *p_file, int p_line, co
void _err_print_index_error(const char *p_function, const char *p_file, int p_line, int64_t p_index, int64_t p_size, const char *p_index_str, const char *p_size_str, const char *p_message, bool p_editor_notify, bool p_fatal) {
String fstr(p_fatal ? "FATAL: " : "");
String err(fstr + "Index " + p_index_str + " = " + itos(p_index) + " is out of bounds (" + p_size_str + " = " + itos(p_size) + ").");
- _err_print_error(p_function, p_file, p_line, err.utf8().get_data(), p_message);
+ _err_print_error(p_function, p_file, p_line, err.utf8().get_data(), p_message, p_editor_notify, ERR_HANDLER_ERROR);
}
void _err_print_index_error(const char *p_function, const char *p_file, int p_line, int64_t p_index, int64_t p_size, const char *p_index_str, const char *p_size_str, const String &p_message, bool p_editor_notify, bool p_fatal) {
- _err_print_index_error(p_function, p_file, p_line, p_index, p_size, p_index_str, p_size_str, p_message.utf8().get_data(), p_fatal);
+ _err_print_index_error(p_function, p_file, p_line, p_index, p_size, p_index_str, p_size_str, p_message.utf8().get_data(), p_editor_notify, p_fatal);
}
void _err_flush_stdout() {
diff --git a/core/error/error_macros.h b/core/error/error_macros.h
index 63a2d22416..65804b7796 100644
--- a/core/error/error_macros.h
+++ b/core/error/error_macros.h
@@ -189,12 +189,12 @@ void _err_flush_stdout();
* Ensures an integer index `m_index` is less than `m_size` and greater than or equal to 0.
* If not, the application crashes.
*/
-#define CRASH_BAD_INDEX(m_index, m_size) \
- if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
- _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), "", true); \
- _err_flush_stdout(); \
- GENERATE_TRAP(); \
- } else \
+#define CRASH_BAD_INDEX(m_index, m_size) \
+ if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
+ _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), "", false, true); \
+ _err_flush_stdout(); \
+ GENERATE_TRAP(); \
+ } else \
((void)0)
/**
@@ -204,12 +204,12 @@ void _err_flush_stdout();
* Ensures an integer index `m_index` is less than `m_size` and greater than or equal to 0.
* If not, prints `m_msg` and the application crashes.
*/
-#define CRASH_BAD_INDEX_MSG(m_index, m_size, m_msg) \
- if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
- _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), m_msg, true); \
- _err_flush_stdout(); \
- GENERATE_TRAP(); \
- } else \
+#define CRASH_BAD_INDEX_MSG(m_index, m_size, m_msg) \
+ if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
+ _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), m_msg, false, true); \
+ _err_flush_stdout(); \
+ GENERATE_TRAP(); \
+ } else \
((void)0)
// Unsigned integer index out of bounds error macros.
@@ -292,12 +292,12 @@ void _err_flush_stdout();
* Ensures an unsigned integer index `m_index` is less than `m_size`.
* If not, the application crashes.
*/
-#define CRASH_BAD_UNSIGNED_INDEX(m_index, m_size) \
- if (unlikely((m_index) >= (m_size))) { \
- _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), "", true); \
- _err_flush_stdout(); \
- GENERATE_TRAP(); \
- } else \
+#define CRASH_BAD_UNSIGNED_INDEX(m_index, m_size) \
+ if (unlikely((m_index) >= (m_size))) { \
+ _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), "", false, true); \
+ _err_flush_stdout(); \
+ GENERATE_TRAP(); \
+ } else \
((void)0)
/**
@@ -307,12 +307,12 @@ void _err_flush_stdout();
* Ensures an unsigned integer index `m_index` is less than `m_size`.
* If not, prints `m_msg` and the application crashes.
*/
-#define CRASH_BAD_UNSIGNED_INDEX_MSG(m_index, m_size, m_msg) \
- if (unlikely((m_index) >= (m_size))) { \
- _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), m_msg, true); \
- _err_flush_stdout(); \
- GENERATE_TRAP(); \
- } else \
+#define CRASH_BAD_UNSIGNED_INDEX_MSG(m_index, m_size, m_msg) \
+ if (unlikely((m_index) >= (m_size))) { \
+ _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), m_msg, false, true); \
+ _err_flush_stdout(); \
+ GENERATE_TRAP(); \
+ } else \
((void)0)
// Null reference error macros.
diff --git a/core/extension/extension_api_dump.cpp b/core/extension/extension_api_dump.cpp
index 312064a36c..e26ead6d8c 100644
--- a/core/extension/extension_api_dump.cpp
+++ b/core/extension/extension_api_dump.cpp
@@ -82,6 +82,11 @@ static String get_property_info_type_name(const PropertyInfo &p_info) {
return get_builtin_or_variant_type_name(p_info.type);
}
+static String get_type_meta_name(const GodotTypeInfo::Metadata metadata) {
+ static const char *argmeta[11] = { "none", "int8", "int16", "int32", "int64", "uint8", "uint16", "uint32", "uint64", "float", "double" };
+ return argmeta[metadata];
+}
+
Dictionary GDExtensionAPIDump::generate_extension_api() {
Dictionary api_dump;
@@ -458,6 +463,7 @@ Dictionary GDExtensionAPIDump::generate_extension_api() {
// Global enums and constants.
Array constants;
HashMap<String, List<Pair<String, int64_t>>> enum_list;
+ HashMap<String, bool> enum_is_bitfield;
for (int i = 0; i < CoreConstants::get_global_constant_count(); i++) {
int64_t value = CoreConstants::get_global_constant_value(i);
@@ -466,6 +472,7 @@ Dictionary GDExtensionAPIDump::generate_extension_api() {
bool bitfield = CoreConstants::is_global_constant_bitfield(i);
if (!enum_name.is_empty()) {
enum_list[enum_name].push_back(Pair<String, int64_t>(name, value));
+ enum_is_bitfield[enum_name] = bitfield;
} else {
Dictionary d;
d["name"] = name;
@@ -481,6 +488,7 @@ Dictionary GDExtensionAPIDump::generate_extension_api() {
for (const KeyValue<String, List<Pair<String, int64_t>>> &E : enum_list) {
Dictionary d1;
d1["name"] = E.key;
+ d1["is_bitfield"] = enum_is_bitfield[E.key];
Array values;
for (const Pair<String, int64_t> &F : E.value) {
Dictionary d2;
@@ -837,6 +845,10 @@ Dictionary GDExtensionAPIDump::generate_extension_api() {
d3["type"] = get_property_info_type_name(pinfo);
+ if (mi.get_argument_meta(i) > 0) {
+ d3["meta"] = get_type_meta_name((GodotTypeInfo::Metadata)mi.get_argument_meta(i));
+ }
+
if (i == -1) {
d2["return_value"] = d3;
} else {
@@ -881,8 +893,7 @@ Dictionary GDExtensionAPIDump::generate_extension_api() {
d3["type"] = get_property_info_type_name(pinfo);
if (method->get_argument_meta(i) > 0) {
- static const char *argmeta[11] = { "none", "int8", "int16", "int32", "int64", "uint8", "uint16", "uint32", "uint64", "float", "double" };
- d3["meta"] = argmeta[method->get_argument_meta(i)];
+ d3["meta"] = get_type_meta_name(method->get_argument_meta(i));
}
if (i >= 0 && i >= (method->get_argument_count() - default_args.size())) {
@@ -926,6 +937,9 @@ Dictionary GDExtensionAPIDump::generate_extension_api() {
Dictionary d3;
d3["name"] = F.arguments[i].name;
d3["type"] = get_property_info_type_name(F.arguments[i]);
+ if (F.get_argument_meta(i) > 0) {
+ d3["meta"] = get_type_meta_name((GodotTypeInfo::Metadata)F.get_argument_meta(i));
+ }
arguments.push_back(d3);
}
if (arguments.size()) {
diff --git a/core/extension/gdextension_interface.cpp b/core/extension/gdextension_interface.cpp
index bd4fa61bd5..3bea013fab 100644
--- a/core/extension/gdextension_interface.cpp
+++ b/core/extension/gdextension_interface.cpp
@@ -31,8 +31,11 @@
#include "gdextension_interface.h"
#include "core/config/engine.h"
+#include "core/io/file_access.h"
+#include "core/io/xml_parser.h"
#include "core/object/class_db.h"
#include "core/object/script_language_extension.h"
+#include "core/object/worker_thread_pool.h"
#include "core/os/memory.h"
#include "core/variant/variant.h"
#include "core/version.h"
@@ -678,6 +681,59 @@ static const char32_t *gdextension_string_operator_index_const(GDExtensionConstS
return &self->ptr()[p_index];
}
+static void gdextension_string_operator_plus_eq_string(GDExtensionStringPtr p_self, GDExtensionConstStringPtr p_b) {
+ String *self = (String *)p_self;
+ const String *b = (const String *)p_b;
+ *self += *b;
+}
+
+static void gdextension_string_operator_plus_eq_char(GDExtensionStringPtr p_self, char32_t p_b) {
+ String *self = (String *)p_self;
+ *self += p_b;
+}
+
+static void gdextension_string_operator_plus_eq_cstr(GDExtensionStringPtr p_self, const char *p_b) {
+ String *self = (String *)p_self;
+ *self += p_b;
+}
+
+static void gdextension_string_operator_plus_eq_wcstr(GDExtensionStringPtr p_self, const wchar_t *p_b) {
+ String *self = (String *)p_self;
+ *self += p_b;
+}
+
+static void gdextension_string_operator_plus_eq_c32str(GDExtensionStringPtr p_self, const char32_t *p_b) {
+ String *self = (String *)p_self;
+ *self += p_b;
+}
+
+static GDExtensionInt gdextension_xml_parser_open_buffer(GDExtensionObjectPtr p_instance, const uint8_t *p_buffer, size_t p_size) {
+ XMLParser *xml = (XMLParser *)p_instance;
+ return (GDExtensionInt)xml->_open_buffer(p_buffer, p_size);
+}
+
+static void gdextension_file_access_store_buffer(GDExtensionObjectPtr p_instance, const uint8_t *p_src, uint64_t p_length) {
+ FileAccess *fa = (FileAccess *)p_instance;
+ fa->store_buffer(p_src, p_length);
+}
+
+static uint64_t gdextension_file_access_get_buffer(GDExtensionConstObjectPtr p_instance, uint8_t *p_dst, uint64_t p_length) {
+ const FileAccess *fa = (FileAccess *)p_instance;
+ return fa->get_buffer(p_dst, p_length);
+}
+
+static int64_t gdextension_worker_thread_pool_add_native_group_task(GDExtensionObjectPtr p_instance, void (*p_func)(void *, uint32_t), void *p_userdata, int p_elements, int p_tasks, GDExtensionBool p_high_priority, GDExtensionConstStringPtr p_description) {
+ WorkerThreadPool *p = (WorkerThreadPool *)p_instance;
+ const String *description = (const String *)p_description;
+ return (int64_t)p->add_native_group_task(p_func, p_userdata, p_elements, p_tasks, static_cast<bool>(p_high_priority), *description);
+}
+
+static int64_t gdextension_worker_thread_pool_add_native_task(GDExtensionObjectPtr p_instance, void (*p_func)(void *), void *p_userdata, GDExtensionBool p_high_priority, GDExtensionConstStringPtr p_description) {
+ WorkerThreadPool *p = (WorkerThreadPool *)p_instance;
+ const String *description = (const String *)p_description;
+ return (int64_t)p->add_native_task(p_func, p_userdata, static_cast<bool>(p_high_priority), *description);
+}
+
/* Packed array functions */
static uint8_t *gdextension_packed_byte_array_operator_index(GDExtensionTypePtr p_self, GDExtensionInt p_index) {
@@ -800,6 +856,19 @@ static GDExtensionVariantPtr gdextension_array_operator_index_const(GDExtensionC
return (GDExtensionVariantPtr)&self->operator[](p_index);
}
+void gdextension_array_ref(GDExtensionTypePtr p_self, GDExtensionConstTypePtr p_from) {
+ Array *self = (Array *)p_self;
+ const Array *from = (const Array *)p_from;
+ self->_ref(*from);
+}
+
+void gdextension_array_set_typed(GDExtensionTypePtr p_self, uint32_t p_type, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstVariantPtr p_script) {
+ Array *self = reinterpret_cast<Array *>(p_self);
+ const StringName *class_name = reinterpret_cast<const StringName *>(p_class_name);
+ const Variant *script = reinterpret_cast<const Variant *>(p_script);
+ self->set_typed(p_type, *class_name, *script);
+}
+
/* Dictionary functions */
static GDExtensionVariantPtr gdextension_dictionary_operator_index(GDExtensionTypePtr p_self, GDExtensionConstVariantPtr p_key) {
@@ -1025,6 +1094,25 @@ void gdextension_setup_interface(GDExtensionInterface *p_interface) {
gde_interface.string_to_wide_chars = gdextension_string_to_wide_chars;
gde_interface.string_operator_index = gdextension_string_operator_index;
gde_interface.string_operator_index_const = gdextension_string_operator_index_const;
+ gde_interface.string_operator_plus_eq_string = gdextension_string_operator_plus_eq_string;
+ gde_interface.string_operator_plus_eq_char = gdextension_string_operator_plus_eq_char;
+ gde_interface.string_operator_plus_eq_cstr = gdextension_string_operator_plus_eq_cstr;
+ gde_interface.string_operator_plus_eq_wcstr = gdextension_string_operator_plus_eq_wcstr;
+ gde_interface.string_operator_plus_eq_c32str = gdextension_string_operator_plus_eq_c32str;
+
+ /* XMLParser extra utilities */
+
+ gde_interface.xml_parser_open_buffer = gdextension_xml_parser_open_buffer;
+
+ /* FileAccess extra utilities */
+
+ gde_interface.file_access_store_buffer = gdextension_file_access_store_buffer;
+ gde_interface.file_access_get_buffer = gdextension_file_access_get_buffer;
+
+ /* WorkerThreadPool extra utilities */
+
+ gde_interface.worker_thread_pool_add_native_group_task = gdextension_worker_thread_pool_add_native_group_task;
+ gde_interface.worker_thread_pool_add_native_task = gdextension_worker_thread_pool_add_native_task;
/* Packed array functions */
@@ -1054,6 +1142,8 @@ void gdextension_setup_interface(GDExtensionInterface *p_interface) {
gde_interface.array_operator_index = gdextension_array_operator_index;
gde_interface.array_operator_index_const = gdextension_array_operator_index_const;
+ gde_interface.array_ref = gdextension_array_ref;
+ gde_interface.array_set_typed = gdextension_array_set_typed;
/* Dictionary functions */
diff --git a/core/extension/gdextension_interface.h b/core/extension/gdextension_interface.h
index 190298ee8a..876a09beff 100644
--- a/core/extension/gdextension_interface.h
+++ b/core/extension/gdextension_interface.h
@@ -503,6 +503,26 @@ typedef struct {
char32_t *(*string_operator_index)(GDExtensionStringPtr p_self, GDExtensionInt p_index);
const char32_t *(*string_operator_index_const)(GDExtensionConstStringPtr p_self, GDExtensionInt p_index);
+ void (*string_operator_plus_eq_string)(GDExtensionStringPtr p_self, GDExtensionConstStringPtr p_b);
+ void (*string_operator_plus_eq_char)(GDExtensionStringPtr p_self, char32_t p_b);
+ void (*string_operator_plus_eq_cstr)(GDExtensionStringPtr p_self, const char *p_b);
+ void (*string_operator_plus_eq_wcstr)(GDExtensionStringPtr p_self, const wchar_t *p_b);
+ void (*string_operator_plus_eq_c32str)(GDExtensionStringPtr p_self, const char32_t *p_b);
+
+ /* XMLParser extra utilities */
+
+ GDExtensionInt (*xml_parser_open_buffer)(GDExtensionObjectPtr p_instance, const uint8_t *p_buffer, size_t p_size);
+
+ /* FileAccess extra utilities */
+
+ void (*file_access_store_buffer)(GDExtensionObjectPtr p_instance, const uint8_t *p_src, uint64_t p_length);
+ uint64_t (*file_access_get_buffer)(GDExtensionConstObjectPtr p_instance, uint8_t *p_dst, uint64_t p_length);
+
+ /* WorkerThreadPool extra utilities */
+
+ int64_t (*worker_thread_pool_add_native_group_task)(GDExtensionObjectPtr p_instance, void (*p_func)(void *, uint32_t), void *p_userdata, int p_elements, int p_tasks, GDExtensionBool p_high_priority, GDExtensionConstStringPtr p_description);
+ int64_t (*worker_thread_pool_add_native_task)(GDExtensionObjectPtr p_instance, void (*p_func)(void *), void *p_userdata, GDExtensionBool p_high_priority, GDExtensionConstStringPtr p_description);
+
/* Packed array functions */
uint8_t *(*packed_byte_array_operator_index)(GDExtensionTypePtr p_self, GDExtensionInt p_index); // p_self should be a PackedByteArray
@@ -531,6 +551,8 @@ typedef struct {
GDExtensionVariantPtr (*array_operator_index)(GDExtensionTypePtr p_self, GDExtensionInt p_index); // p_self should be an Array ptr
GDExtensionVariantPtr (*array_operator_index_const)(GDExtensionConstTypePtr p_self, GDExtensionInt p_index); // p_self should be an Array ptr
+ void (*array_ref)(GDExtensionTypePtr p_self, GDExtensionConstTypePtr p_from); // p_self should be an Array ptr
+ void (*array_set_typed)(GDExtensionTypePtr p_self, uint32_t p_type, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstVariantPtr p_script); // p_self should be an Array ptr
/* Dictionary functions */
diff --git a/core/input/input.cpp b/core/input/input.cpp
index 0afa004515..aa89facdd7 100644
--- a/core/input/input.cpp
+++ b/core/input/input.cpp
@@ -93,6 +93,7 @@ void Input::_bind_methods() {
ClassDB::bind_method(D_METHOD("is_anything_pressed"), &Input::is_anything_pressed);
ClassDB::bind_method(D_METHOD("is_key_pressed", "keycode"), &Input::is_key_pressed);
ClassDB::bind_method(D_METHOD("is_physical_key_pressed", "keycode"), &Input::is_physical_key_pressed);
+ ClassDB::bind_method(D_METHOD("is_key_label_pressed", "keycode"), &Input::is_key_label_pressed);
ClassDB::bind_method(D_METHOD("is_mouse_button_pressed", "button"), &Input::is_mouse_button_pressed);
ClassDB::bind_method(D_METHOD("is_joy_button_pressed", "device", "button"), &Input::is_joy_button_pressed);
ClassDB::bind_method(D_METHOD("is_action_pressed", "action", "exact_match"), &Input::is_action_pressed, DEFVAL(false));
@@ -250,6 +251,11 @@ bool Input::is_physical_key_pressed(Key p_keycode) const {
return physical_keys_pressed.has(p_keycode);
}
+bool Input::is_key_label_pressed(Key p_keycode) const {
+ _THREAD_SAFE_METHOD_
+ return key_label_pressed.has(p_keycode);
+}
+
bool Input::is_mouse_button_pressed(MouseButton p_button) const {
_THREAD_SAFE_METHOD_
return mouse_button_mask.has_flag(mouse_button_to_mask(p_button));
@@ -343,8 +349,8 @@ float Input::get_axis(const StringName &p_negative_action, const StringName &p_p
Vector2 Input::get_vector(const StringName &p_negative_x, const StringName &p_positive_x, const StringName &p_negative_y, const StringName &p_positive_y, float p_deadzone) const {
Vector2 vector = Vector2(
- get_action_raw_strength(p_positive_x) - get_action_raw_strength(p_negative_x),
- get_action_raw_strength(p_positive_y) - get_action_raw_strength(p_negative_y));
+ get_action_strength(p_positive_x) - get_action_strength(p_negative_x),
+ get_action_strength(p_positive_y) - get_action_strength(p_negative_y));
if (p_deadzone < 0.0f) {
// If the deadzone isn't specified, get it from the average of the actions.
@@ -499,6 +505,13 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em
physical_keys_pressed.erase(k->get_physical_keycode());
}
}
+ if (k.is_valid() && !k->is_echo() && k->get_key_label() != Key::NONE) {
+ if (k->is_pressed()) {
+ key_label_pressed.insert(k->get_key_label());
+ } else {
+ key_label_pressed.erase(k->get_key_label());
+ }
+ }
Ref<InputEventMouseButton> mb = p_event;
@@ -878,6 +891,31 @@ void Input::parse_input_event(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null());
+#ifdef DEBUG_ENABLED
+ uint64_t curr_frame = Engine::get_singleton()->get_process_frames();
+ if (curr_frame != last_parsed_frame) {
+ frame_parsed_events.clear();
+ last_parsed_frame = curr_frame;
+ frame_parsed_events.insert(p_event);
+ } else if (frame_parsed_events.has(p_event)) {
+ // It would be technically safe to send the same event in cases such as:
+ // - After an explicit flush.
+ // - In platforms using buffering when agile flushing is enabled, after one of the mid-frame flushes.
+ // - If platform doesn't use buffering and event accumulation is disabled.
+ // - If platform doesn't use buffering and the event type is not accumulable.
+ // However, it wouldn't be reasonable to ask users to remember the full ruleset and be aware at all times
+ // of the possibilites of the target platform, project settings and engine internals, which may change
+ // without prior notice.
+ // Therefore, the guideline is, "don't send the same event object more than once per frame".
+ WARN_PRINT_ONCE(
+ "An input event object is being parsed more than once in the same frame, which is unsafe.\n"
+ "If you are generating events in a script, you have to instantiate a new event instead of sending the same one more than once, unless the original one was sent on an earlier frame.\n"
+ "You can call duplicate() on the event to get a new instance with identical values.");
+ } else {
+ frame_parsed_events.insert(p_event);
+ }
+#endif
+
if (use_accumulated_input) {
if (buffered_events.is_empty() || !buffered_events.back()->get()->accumulate(p_event)) {
buffered_events.push_back(p_event);
@@ -919,6 +957,7 @@ void Input::release_pressed_events() {
keys_pressed.clear();
physical_keys_pressed.clear();
+ key_label_pressed.clear();
joy_buttons_pressed.clear();
_joy_axis.clear();
diff --git a/core/input/input.h b/core/input/input.h
index 0915588700..c254650ef8 100644
--- a/core/input/input.h
+++ b/core/input/input.h
@@ -84,6 +84,7 @@ public:
private:
BitField<MouseButtonMask> mouse_button_mask;
+ RBSet<Key> key_label_pressed;
RBSet<Key> physical_keys_pressed;
RBSet<Key> keys_pressed;
RBSet<JoyButton> joy_buttons_pressed;
@@ -222,6 +223,10 @@ private:
void _parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_emulated);
List<Ref<InputEvent>> buffered_events;
+#ifdef DEBUG_ENABLED
+ HashSet<Ref<InputEvent>> frame_parsed_events;
+ uint64_t last_parsed_frame = UINT64_MAX;
+#endif
friend class DisplayServer;
@@ -247,6 +252,7 @@ public:
bool is_anything_pressed() const;
bool is_key_pressed(Key p_keycode) const;
bool is_physical_key_pressed(Key p_keycode) const;
+ bool is_key_label_pressed(Key p_keycode) const;
bool is_mouse_button_pressed(MouseButton p_button) const;
bool is_joy_button_pressed(int p_device, JoyButton p_button) const;
bool is_action_pressed(const StringName &p_action, bool p_exact = false) const;
diff --git a/core/input/input_builders.py b/core/input/input_builders.py
index a7729c9af2..76e199e0ff 100644
--- a/core/input/input_builders.py
+++ b/core/input/input_builders.py
@@ -45,7 +45,7 @@ def make_default_controller_mappings(target, source, env):
platform_mappings[current_platform][guid] = line
platform_variables = {
- "Linux": "#if X11_ENABLED",
+ "Linux": "#if LINUXBSD_ENABLED",
"Windows": "#ifdef WINDOWS_ENABLED",
"Mac OS X": "#ifdef MACOS_ENABLED",
"Android": "#if defined(__ANDROID__)",
diff --git a/core/input/input_event.cpp b/core/input/input_event.cpp
index 0dd7fdc19b..5a9ec74184 100644
--- a/core/input/input_event.cpp
+++ b/core/input/input_event.cpp
@@ -285,6 +285,8 @@ void InputEventWithModifiers::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_meta_pressed", "pressed"), &InputEventWithModifiers::set_meta_pressed);
ClassDB::bind_method(D_METHOD("is_meta_pressed"), &InputEventWithModifiers::is_meta_pressed);
+ ClassDB::bind_method(D_METHOD("get_modifiers_mask"), &InputEventWithModifiers::get_modifiers_mask);
+
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "command_or_control_autoremap"), "set_command_or_control_autoremap", "is_command_or_control_autoremap");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "alt_pressed"), "set_alt_pressed", "is_alt_pressed");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shift_pressed"), "set_shift_pressed", "is_shift_pressed");
@@ -328,6 +330,15 @@ Key InputEventKey::get_keycode() const {
return keycode;
}
+void InputEventKey::set_key_label(Key p_key_label) {
+ key_label = p_key_label;
+ emit_changed();
+}
+
+Key InputEventKey::get_key_label() const {
+ return key_label;
+}
+
void InputEventKey::set_physical_keycode(Key p_keycode) {
physical_keycode = p_keycode;
emit_changed();
@@ -363,13 +374,72 @@ Key InputEventKey::get_physical_keycode_with_modifiers() const {
return physical_keycode | (int64_t)get_modifiers_mask();
}
+Key InputEventKey::get_key_label_with_modifiers() const {
+ return key_label | get_modifiers_mask();
+}
+
+String InputEventKey::as_text_physical_keycode() const {
+ String kc;
+
+ if (physical_keycode != Key::NONE) {
+ kc = keycode_get_string(physical_keycode);
+ } else {
+ kc = "(" + RTR("Unset") + ")";
+ }
+
+ if (kc.is_empty()) {
+ return kc;
+ }
+
+ String mods_text = InputEventWithModifiers::as_text();
+ return mods_text.is_empty() ? kc : mods_text + "+" + kc;
+}
+
+String InputEventKey::as_text_keycode() const {
+ String kc;
+
+ if (keycode != Key::NONE) {
+ kc = keycode_get_string(keycode);
+ } else {
+ kc = "(" + RTR("Unset") + ")";
+ }
+
+ if (kc.is_empty()) {
+ return kc;
+ }
+
+ String mods_text = InputEventWithModifiers::as_text();
+ return mods_text.is_empty() ? kc : mods_text + "+" + kc;
+}
+
+String InputEventKey::as_text_key_label() const {
+ String kc;
+
+ if (key_label != Key::NONE) {
+ kc = keycode_get_string(key_label);
+ } else {
+ kc = "(" + RTR("Unset") + ")";
+ }
+
+ if (kc.is_empty()) {
+ return kc;
+ }
+
+ String mods_text = InputEventWithModifiers::as_text();
+ return mods_text.is_empty() ? kc : mods_text + "+" + kc;
+}
+
String InputEventKey::as_text() const {
String kc;
- if (keycode == Key::NONE) {
+ if (keycode == Key::NONE && physical_keycode == Key::NONE && key_label != Key::NONE) {
+ kc = keycode_get_string(key_label) + " (Unicode)";
+ } else if (keycode != Key::NONE) {
+ kc = keycode_get_string(keycode);
+ } else if (physical_keycode != Key::NONE) {
kc = keycode_get_string(physical_keycode) + " (" + RTR("Physical") + ")";
} else {
- kc = keycode_get_string(keycode);
+ kc = "(" + RTR("Unset") + ")";
}
if (kc.is_empty()) {
@@ -386,11 +456,16 @@ String InputEventKey::to_string() {
String kc = "";
String physical = "false";
- if (keycode == Key::NONE) {
+
+ if (keycode == Key::NONE && physical_keycode == Key::NONE && unicode != 0) {
+ kc = "U+" + String::num_uint64(unicode, 16) + " (" + String::chr(unicode) + ")";
+ } else if (keycode != Key::NONE) {
+ kc = itos((int64_t)keycode) + " (" + keycode_get_string(keycode) + ")";
+ } else if (physical_keycode != Key::NONE) {
kc = itos((int64_t)physical_keycode) + " (" + keycode_get_string(physical_keycode) + ")";
physical = "true";
} else {
- kc = itos((int64_t)keycode) + " (" + keycode_get_string(keycode) + ")";
+ kc = "(" + RTR("Unset") + ")";
}
String mods = InputEventWithModifiers::as_text();
@@ -435,11 +510,16 @@ bool InputEventKey::action_match(const Ref<InputEvent> &p_event, bool p_exact_ma
}
bool match;
- if (keycode != Key::NONE) {
+ if (keycode == Key::NONE && physical_keycode == Key::NONE && key_label != Key::NONE) {
+ match = key_label == key->key_label;
+ } else if (keycode != Key::NONE) {
match = keycode == key->keycode;
+ } else if (physical_keycode != Key::NONE) {
+ match = physical_keycode == key->physical_keycode;
} else {
- match = get_physical_keycode() == key->get_physical_keycode();
+ match = false;
}
+
Key action_mask = (Key)(int64_t)get_modifiers_mask();
Key key_mask = (Key)(int64_t)key->get_modifiers_mask();
if (key->is_pressed()) {
@@ -470,12 +550,17 @@ bool InputEventKey::is_match(const Ref<InputEvent> &p_event, bool p_exact_match)
return false;
}
- if (keycode == Key::NONE) {
- return physical_keycode == key->physical_keycode &&
+ if (keycode == Key::NONE && physical_keycode == Key::NONE && key_label != Key::NONE) {
+ return (key_label == key->key_label) &&
(!p_exact_match || get_modifiers_mask() == key->get_modifiers_mask());
- } else {
- return keycode == key->keycode &&
+ } else if (keycode != Key::NONE) {
+ return (keycode == key->keycode) &&
(!p_exact_match || get_modifiers_mask() == key->get_modifiers_mask());
+ } else if (physical_keycode != Key::NONE) {
+ return (physical_keycode == key->physical_keycode) &&
+ (!p_exact_match || get_modifiers_mask() == key->get_modifiers_mask());
+ } else {
+ return false;
}
}
@@ -488,6 +573,9 @@ void InputEventKey::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_physical_keycode", "physical_keycode"), &InputEventKey::set_physical_keycode);
ClassDB::bind_method(D_METHOD("get_physical_keycode"), &InputEventKey::get_physical_keycode);
+ ClassDB::bind_method(D_METHOD("set_key_label", "key_label"), &InputEventKey::set_key_label);
+ ClassDB::bind_method(D_METHOD("get_key_label"), &InputEventKey::get_key_label);
+
ClassDB::bind_method(D_METHOD("set_unicode", "unicode"), &InputEventKey::set_unicode);
ClassDB::bind_method(D_METHOD("get_unicode"), &InputEventKey::get_unicode);
@@ -495,10 +583,16 @@ void InputEventKey::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_keycode_with_modifiers"), &InputEventKey::get_keycode_with_modifiers);
ClassDB::bind_method(D_METHOD("get_physical_keycode_with_modifiers"), &InputEventKey::get_physical_keycode_with_modifiers);
+ ClassDB::bind_method(D_METHOD("get_key_label_with_modifiers"), &InputEventKey::get_key_label_with_modifiers);
+
+ ClassDB::bind_method(D_METHOD("as_text_keycode"), &InputEventKey::as_text_keycode);
+ ClassDB::bind_method(D_METHOD("as_text_physical_keycode"), &InputEventKey::as_text_physical_keycode);
+ ClassDB::bind_method(D_METHOD("as_text_key_label"), &InputEventKey::as_text_key_label);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
ADD_PROPERTY(PropertyInfo(Variant::INT, "keycode"), "set_keycode", "get_keycode");
ADD_PROPERTY(PropertyInfo(Variant::INT, "physical_keycode"), "set_physical_keycode", "get_physical_keycode");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "key_label"), "set_key_label", "get_key_label");
ADD_PROPERTY(PropertyInfo(Variant::INT, "unicode"), "set_unicode", "get_unicode");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "echo"), "set_echo", "is_echo");
}
@@ -1405,7 +1499,18 @@ bool InputEventAction::action_match(const Ref<InputEvent> &p_event, bool p_exact
}
String InputEventAction::as_text() const {
- return vformat(RTR("Input Action %s was %s"), action, pressed ? "pressed" : "released");
+ const List<Ref<InputEvent>> *events = InputMap::get_singleton()->action_get_events(action);
+ if (!events) {
+ return String();
+ }
+
+ for (const Ref<InputEvent> &E : *events) {
+ if (E.is_valid()) {
+ return E->as_text();
+ }
+ }
+
+ return String();
}
String InputEventAction::to_string() {
diff --git a/core/input/input_event.h b/core/input/input_event.h
index 2d7a72e327..797761b208 100644
--- a/core/input/input_event.h
+++ b/core/input/input_event.h
@@ -153,6 +153,7 @@ class InputEventKey : public InputEventWithModifiers {
Key keycode = Key::NONE; // Key enum, without modifier masks.
Key physical_keycode = Key::NONE;
+ Key key_label = Key::NONE;
uint32_t unicode = 0; ///unicode
bool echo = false; /// true if this is an echo key
@@ -170,6 +171,9 @@ public:
void set_physical_keycode(Key p_keycode);
Key get_physical_keycode() const;
+ void set_key_label(Key p_key_label);
+ Key get_key_label() const;
+
void set_unicode(char32_t p_unicode);
char32_t get_unicode() const;
@@ -178,12 +182,16 @@ public:
Key get_keycode_with_modifiers() const;
Key get_physical_keycode_with_modifiers() const;
+ Key get_key_label_with_modifiers() const;
virtual bool action_match(const Ref<InputEvent> &p_event, bool p_exact_match, float p_deadzone, bool *r_pressed, float *r_strength, float *r_raw_strength) const override;
virtual bool is_match(const Ref<InputEvent> &p_event, bool p_exact_match = true) const override;
virtual bool is_action_type() const override { return true; }
+ virtual String as_text_physical_keycode() const;
+ virtual String as_text_keycode() const;
+ virtual String as_text_key_label() const;
virtual String as_text() const override;
virtual String to_string() override;
diff --git a/core/io/dtls_server.cpp b/core/io/dtls_server.cpp
index c542e394a1..07d62d3a8d 100644
--- a/core/io/dtls_server.cpp
+++ b/core/io/dtls_server.cpp
@@ -48,6 +48,6 @@ bool DTLSServer::is_available() {
}
void DTLSServer::_bind_methods() {
- ClassDB::bind_method(D_METHOD("setup", "key", "certificate", "chain"), &DTLSServer::setup, DEFVAL(Ref<X509Certificate>()));
+ ClassDB::bind_method(D_METHOD("setup", "server_options"), &DTLSServer::setup);
ClassDB::bind_method(D_METHOD("take_connection", "udp_peer"), &DTLSServer::take_connection);
}
diff --git a/core/io/dtls_server.h b/core/io/dtls_server.h
index e749e6968b..f3fbde3c15 100644
--- a/core/io/dtls_server.h
+++ b/core/io/dtls_server.h
@@ -47,7 +47,7 @@ public:
static bool is_available();
static DTLSServer *create();
- virtual Error setup(Ref<CryptoKey> p_key, Ref<X509Certificate> p_cert, Ref<X509Certificate> p_ca_chain = Ref<X509Certificate>()) = 0;
+ virtual Error setup(Ref<TLSOptions> p_options) = 0;
virtual void stop() = 0;
virtual Ref<PacketPeerDTLS> take_connection(Ref<PacketPeerUDP> p_peer) = 0;
diff --git a/core/io/file_access.cpp b/core/io/file_access.cpp
index 77d1bdcc5c..cacbcb28a4 100644
--- a/core/io/file_access.cpp
+++ b/core/io/file_access.cpp
@@ -292,7 +292,7 @@ real_t FileAccess::get_real() const {
Variant FileAccess::get_var(bool p_allow_objects) const {
uint32_t len = get_32();
- Vector<uint8_t> buff = _get_buffer(len);
+ Vector<uint8_t> buff = get_buffer(len);
ERR_FAIL_COND_V((uint32_t)buff.size() != len, Variant());
const uint8_t *r = buff.ptr();
@@ -469,7 +469,7 @@ uint64_t FileAccess::get_buffer(uint8_t *p_dst, uint64_t p_length) const {
return i;
}
-Vector<uint8_t> FileAccess::_get_buffer(int64_t p_length) const {
+Vector<uint8_t> FileAccess::get_buffer(int64_t p_length) const {
Vector<uint8_t> data;
ERR_FAIL_COND_V_MSG(p_length < 0, data, "Length of buffer cannot be smaller than 0.");
@@ -663,7 +663,7 @@ void FileAccess::store_buffer(const uint8_t *p_src, uint64_t p_length) {
}
}
-void FileAccess::_store_buffer(const Vector<uint8_t> &p_buffer) {
+void FileAccess::store_buffer(const Vector<uint8_t> &p_buffer) {
uint64_t len = p_buffer.size();
if (len == 0) {
return;
@@ -687,7 +687,7 @@ void FileAccess::store_var(const Variant &p_var, bool p_full_objects) {
ERR_FAIL_COND_MSG(err != OK, "Error when trying to encode Variant.");
store_32(len);
- _store_buffer(buff);
+ store_buffer(buff);
}
Vector<uint8_t> FileAccess::get_file_as_bytes(const String &p_path, Error *r_error) {
@@ -829,7 +829,7 @@ void FileAccess::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_float"), &FileAccess::get_float);
ClassDB::bind_method(D_METHOD("get_double"), &FileAccess::get_double);
ClassDB::bind_method(D_METHOD("get_real"), &FileAccess::get_real);
- ClassDB::bind_method(D_METHOD("get_buffer", "length"), &FileAccess::_get_buffer);
+ ClassDB::bind_method(D_METHOD("get_buffer", "length"), (Vector<uint8_t>(FileAccess::*)(int64_t) const) & FileAccess::get_buffer);
ClassDB::bind_method(D_METHOD("get_line"), &FileAccess::get_line);
ClassDB::bind_method(D_METHOD("get_csv_line", "delim"), &FileAccess::get_csv_line, DEFVAL(","));
ClassDB::bind_method(D_METHOD("get_as_text", "skip_cr"), &FileAccess::get_as_text, DEFVAL(false));
@@ -847,7 +847,7 @@ void FileAccess::_bind_methods() {
ClassDB::bind_method(D_METHOD("store_float", "value"), &FileAccess::store_float);
ClassDB::bind_method(D_METHOD("store_double", "value"), &FileAccess::store_double);
ClassDB::bind_method(D_METHOD("store_real", "value"), &FileAccess::store_real);
- ClassDB::bind_method(D_METHOD("store_buffer", "buffer"), &FileAccess::_store_buffer);
+ ClassDB::bind_method(D_METHOD("store_buffer", "buffer"), (void(FileAccess::*)(const Vector<uint8_t> &)) & FileAccess::store_buffer);
ClassDB::bind_method(D_METHOD("store_line", "line"), &FileAccess::store_line);
ClassDB::bind_method(D_METHOD("store_csv_line", "values", "delim"), &FileAccess::store_csv_line, DEFVAL(","));
ClassDB::bind_method(D_METHOD("store_string", "string"), &FileAccess::store_string);
diff --git a/core/io/file_access.h b/core/io/file_access.h
index 3116ed521f..3e51ba11ed 100644
--- a/core/io/file_access.h
+++ b/core/io/file_access.h
@@ -127,7 +127,7 @@ public:
Variant get_var(bool p_allow_objects = false) const;
virtual uint64_t get_buffer(uint8_t *p_dst, uint64_t p_length) const; ///< get an array of bytes
- Vector<uint8_t> _get_buffer(int64_t p_length) const;
+ Vector<uint8_t> get_buffer(int64_t p_length) const;
virtual String get_line() const;
virtual String get_token() const;
virtual Vector<String> get_csv_line(const String &p_delim = ",") const;
@@ -162,7 +162,7 @@ public:
virtual String get_pascal_string();
virtual void store_buffer(const uint8_t *p_src, uint64_t p_length); ///< store an array of bytes
- void _store_buffer(const Vector<uint8_t> &p_buffer);
+ void store_buffer(const Vector<uint8_t> &p_buffer);
void store_var(const Variant &p_var, bool p_full_objects = false);
diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp
index 829abdc614..190edbfb82 100644
--- a/core/io/http_client.cpp
+++ b/core/io/http_client.cpp
@@ -138,7 +138,7 @@ PackedStringArray HTTPClient::_get_response_headers() {
}
void HTTPClient::_bind_methods() {
- ClassDB::bind_method(D_METHOD("connect_to_host", "host", "port", "use_tls", "verify_host"), &HTTPClient::connect_to_host, DEFVAL(-1), DEFVAL(false), DEFVAL(true));
+ ClassDB::bind_method(D_METHOD("connect_to_host", "host", "port", "tls_options"), &HTTPClient::connect_to_host, DEFVAL(-1), DEFVAL(Ref<TLSOptions>()));
ClassDB::bind_method(D_METHOD("set_connection", "connection"), &HTTPClient::set_connection);
ClassDB::bind_method(D_METHOD("get_connection"), &HTTPClient::get_connection);
ClassDB::bind_method(D_METHOD("request_raw", "method", "url", "headers", "body"), &HTTPClient::_request_raw);
diff --git a/core/io/http_client.h b/core/io/http_client.h
index 853ea7f472..9e018182e3 100644
--- a/core/io/http_client.h
+++ b/core/io/http_client.h
@@ -31,6 +31,7 @@
#ifndef HTTP_CLIENT_H
#define HTTP_CLIENT_H
+#include "core/crypto/crypto.h"
#include "core/io/ip.h"
#include "core/io/stream_peer.h"
#include "core/io/stream_peer_tcp.h"
@@ -168,7 +169,7 @@ public:
Error verify_headers(const Vector<String> &p_headers);
virtual Error request(Method p_method, const String &p_url, const Vector<String> &p_headers, const uint8_t *p_body, int p_body_size) = 0;
- virtual Error connect_to_host(const String &p_host, int p_port = -1, bool p_tls = false, bool p_verify_host = true) = 0;
+ virtual Error connect_to_host(const String &p_host, int p_port = -1, Ref<TLSOptions> p_tls_options = Ref<TLSOptions>()) = 0;
virtual void set_connection(const Ref<StreamPeer> &p_connection) = 0;
virtual Ref<StreamPeer> get_connection() const = 0;
diff --git a/core/io/http_client_tcp.cpp b/core/io/http_client_tcp.cpp
index 5cdb13fa06..3788fa501e 100644
--- a/core/io/http_client_tcp.cpp
+++ b/core/io/http_client_tcp.cpp
@@ -39,29 +39,31 @@ HTTPClient *HTTPClientTCP::_create_func() {
return memnew(HTTPClientTCP);
}
-Error HTTPClientTCP::connect_to_host(const String &p_host, int p_port, bool p_tls, bool p_verify_host) {
+Error HTTPClientTCP::connect_to_host(const String &p_host, int p_port, Ref<TLSOptions> p_options) {
close();
conn_port = p_port;
conn_host = p_host;
+ tls_options = p_options;
ip_candidates.clear();
- tls = p_tls;
- tls_verify_host = p_verify_host;
-
String host_lower = conn_host.to_lower();
if (host_lower.begins_with("http://")) {
conn_host = conn_host.substr(7, conn_host.length() - 7);
+ tls_options.unref();
} else if (host_lower.begins_with("https://")) {
- tls = true;
+ if (tls_options.is_null()) {
+ tls_options = TLSOptions::client();
+ }
conn_host = conn_host.substr(8, conn_host.length() - 8);
}
+ ERR_FAIL_COND_V(tls_options.is_valid() && tls_options->is_server(), ERR_INVALID_PARAMETER);
ERR_FAIL_COND_V(conn_host.length() < HOST_MIN_LEN, ERR_INVALID_PARAMETER);
if (conn_port < 0) {
- if (tls) {
+ if (tls_options.is_valid()) {
conn_port = PORT_HTTPS;
} else {
conn_port = PORT_HTTP;
@@ -70,11 +72,11 @@ Error HTTPClientTCP::connect_to_host(const String &p_host, int p_port, bool p_tl
connection = tcp_connection;
- if (tls && https_proxy_port != -1) {
+ if (tls_options.is_valid() && https_proxy_port != -1) {
proxy_client.instantiate(); // Needs proxy negotiation.
server_host = https_proxy_host;
server_port = https_proxy_port;
- } else if (!tls && http_proxy_port != -1) {
+ } else if (tls_options.is_null() && http_proxy_port != -1) {
server_host = http_proxy_host;
server_port = http_proxy_port;
} else {
@@ -107,7 +109,7 @@ Error HTTPClientTCP::connect_to_host(const String &p_host, int p_port, bool p_tl
void HTTPClientTCP::set_connection(const Ref<StreamPeer> &p_connection) {
ERR_FAIL_COND_MSG(p_connection.is_null(), "Connection is not a reference to a valid StreamPeer object.");
- if (tls) {
+ if (tls_options.is_valid()) {
ERR_FAIL_NULL_MSG(Object::cast_to<StreamPeerTLS>(p_connection.ptr()),
"Connection is not a reference to a valid StreamPeerTLS object.");
}
@@ -156,7 +158,7 @@ Error HTTPClientTCP::request(Method p_method, const String &p_url, const Vector<
}
String uri = p_url;
- if (!tls && http_proxy_port != -1) {
+ if (tls_options.is_null() && http_proxy_port != -1) {
uri = vformat("http://%s:%d%s", conn_host, conn_port, p_url);
}
@@ -181,7 +183,7 @@ Error HTTPClientTCP::request(Method p_method, const String &p_url, const Vector<
}
}
if (add_host) {
- if ((tls && conn_port == PORT_HTTPS) || (!tls && conn_port == PORT_HTTP)) {
+ if ((tls_options.is_valid() && conn_port == PORT_HTTPS) || (tls_options.is_null() && conn_port == PORT_HTTP)) {
// Don't append the standard ports.
request += "Host: " + conn_host + "\r\n";
} else {
@@ -316,7 +318,7 @@ Error HTTPClientTCP::poll() {
return OK;
} break;
case StreamPeerTCP::STATUS_CONNECTED: {
- if (tls && proxy_client.is_valid()) {
+ if (tls_options.is_valid() && proxy_client.is_valid()) {
Error err = proxy_client->poll();
if (err == ERR_UNCONFIGURED) {
proxy_client->set_connection(tcp_connection);
@@ -357,13 +359,12 @@ Error HTTPClientTCP::poll() {
return ERR_CANT_CONNECT;
} break;
}
- } else if (tls) {
+ } else if (tls_options.is_valid()) {
Ref<StreamPeerTLS> tls_conn;
if (!handshaking) {
// Connect the StreamPeerTLS and start handshaking.
tls_conn = Ref<StreamPeerTLS>(StreamPeerTLS::create());
- tls_conn->set_blocking_handshake_enabled(false);
- Error err = tls_conn->connect_to_stream(tcp_connection, tls_verify_host, conn_host);
+ Error err = tls_conn->connect_to_stream(tcp_connection, conn_host, tls_options);
if (err != OK) {
close();
status = STATUS_TLS_HANDSHAKE_ERROR;
@@ -421,7 +422,7 @@ Error HTTPClientTCP::poll() {
case STATUS_BODY:
case STATUS_CONNECTED: {
// Check if we are still connected.
- if (tls) {
+ if (tls_options.is_valid()) {
Ref<StreamPeerTLS> tmp = connection;
tmp->poll();
if (tmp->get_status() != StreamPeerTLS::STATUS_CONNECTED) {
diff --git a/core/io/http_client_tcp.h b/core/io/http_client_tcp.h
index 97ac2d76a7..6060c975bc 100644
--- a/core/io/http_client_tcp.h
+++ b/core/io/http_client_tcp.h
@@ -33,6 +33,8 @@
#include "http_client.h"
+#include "core/crypto/crypto.h"
+
class HTTPClientTCP : public HTTPClient {
private:
Status status = STATUS_DISCONNECTED;
@@ -46,11 +48,10 @@ private:
String http_proxy_host;
int https_proxy_port = -1; // Proxy server for https requests.
String https_proxy_host;
- bool tls = false;
- bool tls_verify_host = false;
bool blocking = false;
bool handshaking = false;
bool head_request = false;
+ Ref<TLSOptions> tls_options;
Vector<uint8_t> response_str;
@@ -79,7 +80,7 @@ public:
Error request(Method p_method, const String &p_url, const Vector<String> &p_headers, const uint8_t *p_body, int p_body_size) override;
- Error connect_to_host(const String &p_host, int p_port = -1, bool p_tls = false, bool p_verify_host = true) override;
+ Error connect_to_host(const String &p_host, int p_port = -1, Ref<TLSOptions> p_tls_options = Ref<TLSOptions>()) override;
void set_connection(const Ref<StreamPeer> &p_connection) override;
Ref<StreamPeer> get_connection() const override;
void close() override;
diff --git a/core/io/image.cpp b/core/io/image.cpp
index 9408a9c103..736a3ec82e 100644
--- a/core/io/image.cpp
+++ b/core/io/image.cpp
@@ -78,6 +78,10 @@ const char *Image::format_names[Image::FORMAT_MAX] = {
"ETC2_RGB8A1",
"ETC2_RA_AS_RG",
"FORMAT_DXT5_RA_AS_RG",
+ "ASTC_4x4",
+ "ASTC_4x4_HDR",
+ "ASTC_8x8",
+ "ASTC_8x8_HDR",
};
SavePNGFunc Image::save_png_func = nullptr;
@@ -2187,16 +2191,16 @@ void Image::initialize_data(int p_width, int p_height, bool p_use_mipmaps, Forma
int size = _get_dst_image_size(p_width, p_height, p_format, mm, p_use_mipmaps ? -1 : 0);
if (unlikely(p_data.size() != size)) {
- String description_mipmaps;
+ String description_mipmaps = get_format_name(p_format) + " ";
if (p_use_mipmaps) {
const int num_mipmaps = get_image_required_mipmaps(p_width, p_height, p_format);
if (num_mipmaps != 1) {
- description_mipmaps = vformat("with %d mipmaps", num_mipmaps);
+ description_mipmaps += vformat("with %d mipmaps", num_mipmaps);
} else {
- description_mipmaps = "with 1 mipmap";
+ description_mipmaps += "with 1 mipmap";
}
} else {
- description_mipmaps = "without mipmaps";
+ description_mipmaps += "without mipmaps";
}
const String description = vformat("%dx%dx%d (%s)", p_width, p_height, get_format_pixel_size(p_format), description_mipmaps);
ERR_FAIL_MSG(vformat("Expected Image data size of %s = %d bytes, got %d bytes instead.", description, size, p_data.size()));
@@ -2618,35 +2622,35 @@ Error Image::decompress() {
return OK;
}
-Error Image::compress(CompressMode p_mode, CompressSource p_source, float p_lossy_quality, ASTCFormat p_astc_format) {
+Error Image::compress(CompressMode p_mode, CompressSource p_source, ASTCFormat p_astc_format) {
ERR_FAIL_INDEX_V_MSG(p_mode, COMPRESS_MAX, ERR_INVALID_PARAMETER, "Invalid compress mode.");
ERR_FAIL_INDEX_V_MSG(p_source, COMPRESS_SOURCE_MAX, ERR_INVALID_PARAMETER, "Invalid compress source.");
- return compress_from_channels(p_mode, detect_used_channels(p_source), p_lossy_quality, p_astc_format);
+ return compress_from_channels(p_mode, detect_used_channels(p_source), p_astc_format);
}
-Error Image::compress_from_channels(CompressMode p_mode, UsedChannels p_channels, float p_lossy_quality, ASTCFormat p_astc_format) {
+Error Image::compress_from_channels(CompressMode p_mode, UsedChannels p_channels, ASTCFormat p_astc_format) {
ERR_FAIL_COND_V(data.is_empty(), ERR_INVALID_DATA);
switch (p_mode) {
case COMPRESS_S3TC: {
ERR_FAIL_COND_V(!_image_compress_bc_func, ERR_UNAVAILABLE);
- _image_compress_bc_func(this, p_lossy_quality, p_channels);
+ _image_compress_bc_func(this, p_channels);
} break;
case COMPRESS_ETC: {
ERR_FAIL_COND_V(!_image_compress_etc1_func, ERR_UNAVAILABLE);
- _image_compress_etc1_func(this, p_lossy_quality);
+ _image_compress_etc1_func(this);
} break;
case COMPRESS_ETC2: {
ERR_FAIL_COND_V(!_image_compress_etc2_func, ERR_UNAVAILABLE);
- _image_compress_etc2_func(this, p_lossy_quality, p_channels);
+ _image_compress_etc2_func(this, p_channels);
} break;
case COMPRESS_BPTC: {
ERR_FAIL_COND_V(!_image_compress_bptc_func, ERR_UNAVAILABLE);
- _image_compress_bptc_func(this, p_lossy_quality, p_channels);
+ _image_compress_bptc_func(this, p_channels);
} break;
case COMPRESS_ASTC: {
ERR_FAIL_COND_V(!_image_compress_bptc_func, ERR_UNAVAILABLE);
- _image_compress_astc_func(this, p_lossy_quality, p_astc_format);
+ _image_compress_astc_func(this, p_astc_format);
} break;
case COMPRESS_MAX: {
ERR_FAIL_V(ERR_INVALID_PARAMETER);
@@ -3000,11 +3004,11 @@ ImageMemLoadFunc Image::_webp_mem_loader_func = nullptr;
ImageMemLoadFunc Image::_tga_mem_loader_func = nullptr;
ImageMemLoadFunc Image::_bmp_mem_loader_func = nullptr;
-void (*Image::_image_compress_bc_func)(Image *, float, Image::UsedChannels) = nullptr;
-void (*Image::_image_compress_bptc_func)(Image *, float, Image::UsedChannels) = nullptr;
-void (*Image::_image_compress_etc1_func)(Image *, float) = nullptr;
-void (*Image::_image_compress_etc2_func)(Image *, float, Image::UsedChannels) = nullptr;
-void (*Image::_image_compress_astc_func)(Image *, float, Image::ASTCFormat) = nullptr;
+void (*Image::_image_compress_bc_func)(Image *, Image::UsedChannels) = nullptr;
+void (*Image::_image_compress_bptc_func)(Image *, Image::UsedChannels) = nullptr;
+void (*Image::_image_compress_etc1_func)(Image *) = nullptr;
+void (*Image::_image_compress_etc2_func)(Image *, Image::UsedChannels) = nullptr;
+void (*Image::_image_compress_astc_func)(Image *, Image::ASTCFormat) = nullptr;
void (*Image::_image_decompress_bc)(Image *) = nullptr;
void (*Image::_image_decompress_bptc)(Image *) = nullptr;
void (*Image::_image_decompress_etc1)(Image *) = nullptr;
@@ -3426,8 +3430,8 @@ void Image::_bind_methods() {
ClassDB::bind_method(D_METHOD("is_invisible"), &Image::is_invisible);
ClassDB::bind_method(D_METHOD("detect_used_channels", "source"), &Image::detect_used_channels, DEFVAL(COMPRESS_SOURCE_GENERIC));
- ClassDB::bind_method(D_METHOD("compress", "mode", "source", "lossy_quality", "astc_format"), &Image::compress, DEFVAL(COMPRESS_SOURCE_GENERIC), DEFVAL(0.7), DEFVAL(ASTC_FORMAT_4x4));
- ClassDB::bind_method(D_METHOD("compress_from_channels", "mode", "channels", "lossy_quality", "astc_format"), &Image::compress_from_channels, DEFVAL(0.7), DEFVAL(ASTC_FORMAT_4x4));
+ ClassDB::bind_method(D_METHOD("compress", "mode", "source", "astc_format"), &Image::compress, DEFVAL(COMPRESS_SOURCE_GENERIC), DEFVAL(ASTC_FORMAT_4x4));
+ ClassDB::bind_method(D_METHOD("compress_from_channels", "mode", "channels", "astc_format"), &Image::compress_from_channels, DEFVAL(ASTC_FORMAT_4x4));
ClassDB::bind_method(D_METHOD("decompress"), &Image::decompress);
ClassDB::bind_method(D_METHOD("is_compressed"), &Image::is_compressed);
@@ -3547,11 +3551,11 @@ void Image::_bind_methods() {
BIND_ENUM_CONSTANT(ASTC_FORMAT_8x8);
}
-void Image::set_compress_bc_func(void (*p_compress_func)(Image *, float, UsedChannels)) {
+void Image::set_compress_bc_func(void (*p_compress_func)(Image *, UsedChannels)) {
_image_compress_bc_func = p_compress_func;
}
-void Image::set_compress_bptc_func(void (*p_compress_func)(Image *, float, UsedChannels)) {
+void Image::set_compress_bptc_func(void (*p_compress_func)(Image *, UsedChannels)) {
_image_compress_bptc_func = p_compress_func;
}
diff --git a/core/io/image.h b/core/io/image.h
index 29ceb9478f..8e353a8bb7 100644
--- a/core/io/image.h
+++ b/core/io/image.h
@@ -149,11 +149,11 @@ public:
static ImageMemLoadFunc _tga_mem_loader_func;
static ImageMemLoadFunc _bmp_mem_loader_func;
- static void (*_image_compress_bc_func)(Image *, float, UsedChannels p_channels);
- static void (*_image_compress_bptc_func)(Image *, float p_lossy_quality, UsedChannels p_channels);
- static void (*_image_compress_etc1_func)(Image *, float);
- static void (*_image_compress_etc2_func)(Image *, float, UsedChannels p_channels);
- static void (*_image_compress_astc_func)(Image *, float, ASTCFormat p_format);
+ static void (*_image_compress_bc_func)(Image *, UsedChannels p_channels);
+ static void (*_image_compress_bptc_func)(Image *, UsedChannels p_channels);
+ static void (*_image_compress_etc1_func)(Image *);
+ static void (*_image_compress_etc2_func)(Image *, UsedChannels p_channels);
+ static void (*_image_compress_astc_func)(Image *, ASTCFormat p_format);
static void (*_image_decompress_bc)(Image *);
static void (*_image_decompress_bptc)(Image *);
@@ -368,8 +368,8 @@ public:
COMPRESS_SOURCE_MAX,
};
- Error compress(CompressMode p_mode, CompressSource p_source = COMPRESS_SOURCE_GENERIC, float p_lossy_quality = 0.7, ASTCFormat p_astc_format = ASTC_FORMAT_4x4);
- Error compress_from_channels(CompressMode p_mode, UsedChannels p_channels, float p_lossy_quality = 0.7, ASTCFormat p_astc_format = ASTC_FORMAT_4x4);
+ Error compress(CompressMode p_mode, CompressSource p_source = COMPRESS_SOURCE_GENERIC, ASTCFormat p_astc_format = ASTC_FORMAT_4x4);
+ Error compress_from_channels(CompressMode p_mode, UsedChannels p_channels, ASTCFormat p_astc_format = ASTC_FORMAT_4x4);
Error decompress();
bool is_compressed() const;
@@ -391,8 +391,8 @@ public:
Rect2i get_used_rect() const;
Ref<Image> get_region(const Rect2i &p_area) const;
- static void set_compress_bc_func(void (*p_compress_func)(Image *, float, UsedChannels));
- static void set_compress_bptc_func(void (*p_compress_func)(Image *, float, UsedChannels));
+ static void set_compress_bc_func(void (*p_compress_func)(Image *, UsedChannels));
+ static void set_compress_bptc_func(void (*p_compress_func)(Image *, UsedChannels));
static String get_format_name(Format p_format);
Error load_png_from_buffer(const Vector<uint8_t> &p_array);
diff --git a/core/io/image_loader.cpp b/core/io/image_loader.cpp
index 17fb199811..c6452f1033 100644
--- a/core/io/image_loader.cpp
+++ b/core/io/image_loader.cpp
@@ -135,10 +135,6 @@ void ImageLoader::remove_image_format_loader(Ref<ImageFormatLoader> p_loader) {
loader.erase(p_loader);
}
-const Vector<Ref<ImageFormatLoader>> &ImageLoader::get_image_format_loaders() {
- return loader;
-}
-
void ImageLoader::cleanup() {
while (loader.size()) {
remove_image_format_loader(loader[0]);
diff --git a/core/io/image_loader.h b/core/io/image_loader.h
index 1473f24186..ac51f13376 100644
--- a/core/io/image_loader.h
+++ b/core/io/image_loader.h
@@ -98,8 +98,6 @@ public:
static void add_image_format_loader(Ref<ImageFormatLoader> p_loader);
static void remove_image_format_loader(Ref<ImageFormatLoader> p_loader);
- static const Vector<Ref<ImageFormatLoader>> &get_image_format_loaders();
-
static void cleanup();
};
diff --git a/core/io/json.cpp b/core/io/json.cpp
index ca29534c35..448e39b2c3 100644
--- a/core/io/json.cpp
+++ b/core/io/json.cpp
@@ -30,6 +30,7 @@
#include "json.h"
+#include "core/config/engine.h"
#include "core/string/print_string.h"
const char *JSON::tk_name[TK_MAX] = {
@@ -506,6 +507,7 @@ Error JSON::_parse_object(Dictionary &object, const char32_t *p_str, int &index,
void JSON::set_data(const Variant &p_data) {
data = p_data;
+ text.clear();
}
Error JSON::_parse_string(const String &p_json, Variant &r_ret, String &r_err_str, int &r_err_line) {
@@ -539,14 +541,21 @@ Error JSON::_parse_string(const String &p_json, Variant &r_ret, String &r_err_st
return err;
}
-Error JSON::parse(const String &p_json_string) {
+Error JSON::parse(const String &p_json_string, bool p_keep_text) {
Error err = _parse_string(p_json_string, data, err_str, err_line);
if (err == Error::OK) {
err_line = 0;
}
+ if (p_keep_text) {
+ text = p_json_string;
+ }
return err;
}
+String JSON::get_parsed_text() const {
+ return text;
+}
+
String JSON::stringify(const Variant &p_var, const String &p_indent, bool p_sort_keys, bool p_full_precision) {
Ref<JSON> jason;
jason.instantiate();
@@ -565,10 +574,11 @@ Variant JSON::parse_string(const String &p_json_string) {
void JSON::_bind_methods() {
ClassDB::bind_static_method("JSON", D_METHOD("stringify", "data", "indent", "sort_keys", "full_precision"), &JSON::stringify, DEFVAL(""), DEFVAL(true), DEFVAL(false));
ClassDB::bind_static_method("JSON", D_METHOD("parse_string", "json_string"), &JSON::parse_string);
- ClassDB::bind_method(D_METHOD("parse", "json_string"), &JSON::parse);
+ ClassDB::bind_method(D_METHOD("parse", "json_text", "keep_text"), &JSON::parse, DEFVAL(false));
ClassDB::bind_method(D_METHOD("get_data"), &JSON::get_data);
ClassDB::bind_method(D_METHOD("set_data", "data"), &JSON::set_data);
+ ClassDB::bind_method(D_METHOD("get_parsed_text"), &JSON::get_parsed_text);
ClassDB::bind_method(D_METHOD("get_error_line"), &JSON::get_error_line);
ClassDB::bind_method(D_METHOD("get_error_message"), &JSON::get_error_message);
@@ -592,13 +602,20 @@ Ref<Resource> ResourceFormatLoaderJSON::load(const String &p_path, const String
Ref<JSON> json;
json.instantiate();
- Error err = json->parse(FileAccess::get_file_as_string(p_path));
+ Error err = json->parse(FileAccess::get_file_as_string(p_path), Engine::get_singleton()->is_editor_hint());
if (err != OK) {
- if (r_error) {
- *r_error = err;
+ String err_text = "Error parsing JSON file at '" + p_path + "', on line " + itos(json->get_error_line()) + ": " + json->get_error_message();
+
+ if (Engine::get_singleton()->is_editor_hint()) {
+ // If running on editor, still allow opening the JSON so the code editor can edit it.
+ WARN_PRINT(err_text);
+ } else {
+ if (r_error) {
+ *r_error = err;
+ }
+ ERR_PRINT(err_text);
+ return Ref<Resource>();
}
- ERR_PRINT("Error parsing JSON file at '" + p_path + "', on line " + itos(json->get_error_line()) + ": " + json->get_error_message());
- return Ref<Resource>();
}
if (r_error) {
@@ -628,7 +645,7 @@ Error ResourceFormatSaverJSON::save(const Ref<Resource> &p_resource, const Strin
Ref<JSON> json = p_resource;
ERR_FAIL_COND_V(json.is_null(), ERR_INVALID_PARAMETER);
- String source = JSON::stringify(json->get_data(), "\t", false, true);
+ String source = json->get_parsed_text().is_empty() ? JSON::stringify(json->get_data(), "\t", false, true) : json->get_parsed_text();
Error err;
Ref<FileAccess> file = FileAccess::open(p_path, FileAccess::WRITE, &err);
diff --git a/core/io/json.h b/core/io/json.h
index d66a4e24a3..a21cc542fd 100644
--- a/core/io/json.h
+++ b/core/io/json.h
@@ -36,8 +36,8 @@
#include "core/io/resource_saver.h"
#include "core/variant/variant.h"
-class JSON : public RefCounted {
- GDCLASS(JSON, RefCounted);
+class JSON : public Resource {
+ GDCLASS(JSON, Resource);
enum TokenType {
TK_CURLY_BRACKET_OPEN,
@@ -65,6 +65,7 @@ class JSON : public RefCounted {
Variant value;
};
+ String text;
Variant data;
String err_str;
int err_line = 0;
@@ -83,7 +84,9 @@ protected:
static void _bind_methods();
public:
- Error parse(const String &p_json_string);
+ Error parse(const String &p_json_string, bool p_keep_text = false);
+ String get_parsed_text() const;
+
static String stringify(const Variant &p_var, const String &p_indent = "", bool p_sort_keys = true, bool p_full_precision = false);
static Variant parse_string(const String &p_json_string);
diff --git a/core/io/marshalls.h b/core/io/marshalls.h
index 5e760c7565..6f015ac386 100644
--- a/core/io/marshalls.h
+++ b/core/io/marshalls.h
@@ -44,7 +44,7 @@ typedef uint32_t uintr_t;
#endif
/**
- * Miscellaneous helpers for marshalling data types, and encoding
+ * Miscellaneous helpers for marshaling data types, and encoding
* in an endian independent way
*/
diff --git a/core/io/packet_peer_dtls.cpp b/core/io/packet_peer_dtls.cpp
index c0998f10bc..18bef3ff3c 100644
--- a/core/io/packet_peer_dtls.cpp
+++ b/core/io/packet_peer_dtls.cpp
@@ -48,7 +48,7 @@ bool PacketPeerDTLS::is_available() {
void PacketPeerDTLS::_bind_methods() {
ClassDB::bind_method(D_METHOD("poll"), &PacketPeerDTLS::poll);
- ClassDB::bind_method(D_METHOD("connect_to_peer", "packet_peer", "validate_certs", "for_hostname", "valid_certificate"), &PacketPeerDTLS::connect_to_peer, DEFVAL(true), DEFVAL(String()), DEFVAL(Ref<X509Certificate>()));
+ ClassDB::bind_method(D_METHOD("connect_to_peer", "packet_peer", "hostname", "client_options"), &PacketPeerDTLS::connect_to_peer, DEFVAL(Ref<TLSOptions>()));
ClassDB::bind_method(D_METHOD("get_status"), &PacketPeerDTLS::get_status);
ClassDB::bind_method(D_METHOD("disconnect_from_peer"), &PacketPeerDTLS::disconnect_from_peer);
diff --git a/core/io/packet_peer_dtls.h b/core/io/packet_peer_dtls.h
index 5ba1faed7c..3990a851f7 100644
--- a/core/io/packet_peer_dtls.h
+++ b/core/io/packet_peer_dtls.h
@@ -53,7 +53,7 @@ public:
};
virtual void poll() = 0;
- virtual Error connect_to_peer(Ref<PacketPeerUDP> p_base, bool p_validate_certs = true, const String &p_for_hostname = String(), Ref<X509Certificate> p_ca_certs = Ref<X509Certificate>()) = 0;
+ virtual Error connect_to_peer(Ref<PacketPeerUDP> p_base, const String &p_hostname, Ref<TLSOptions> p_options = Ref<TLSOptions>()) = 0;
virtual void disconnect_from_peer() = 0;
virtual Status get_status() const = 0;
diff --git a/core/io/resource.cpp b/core/io/resource.cpp
index 2d6f09725f..4abcbffb61 100644
--- a/core/io/resource.cpp
+++ b/core/io/resource.cpp
@@ -260,15 +260,35 @@ Ref<Resource> Resource::duplicate(bool p_subresources) const {
}
Variant p = get(E.name);
- if ((p.get_type() == Variant::DICTIONARY || p.get_type() == Variant::ARRAY)) {
- r->set(E.name, p.duplicate(p_subresources));
- } else if (p.get_type() == Variant::OBJECT && (p_subresources || (E.usage & PROPERTY_USAGE_DO_NOT_SHARE_ON_DUPLICATE))) {
- Ref<Resource> sr = p;
- if (sr.is_valid()) {
- r->set(E.name, sr->duplicate(p_subresources));
+ switch (p.get_type()) {
+ case Variant::Type::DICTIONARY:
+ case Variant::Type::ARRAY:
+ case Variant::Type::PACKED_BYTE_ARRAY:
+ case Variant::Type::PACKED_COLOR_ARRAY:
+ case Variant::Type::PACKED_INT32_ARRAY:
+ case Variant::Type::PACKED_INT64_ARRAY:
+ case Variant::Type::PACKED_FLOAT32_ARRAY:
+ case Variant::Type::PACKED_FLOAT64_ARRAY:
+ case Variant::Type::PACKED_STRING_ARRAY:
+ case Variant::Type::PACKED_VECTOR2_ARRAY:
+ case Variant::Type::PACKED_VECTOR3_ARRAY: {
+ r->set(E.name, p.duplicate(p_subresources));
+ } break;
+
+ case Variant::Type::OBJECT: {
+ if (!(E.usage & PROPERTY_USAGE_NEVER_DUPLICATE) && (p_subresources || (E.usage & PROPERTY_USAGE_ALWAYS_DUPLICATE))) {
+ Ref<Resource> sr = p;
+ if (sr.is_valid()) {
+ r->set(E.name, sr->duplicate(p_subresources));
+ }
+ } else {
+ r->set(E.name, p);
+ }
+ } break;
+
+ default: {
+ r->set(E.name, p);
}
- } else {
- r->set(E.name, p);
}
}
@@ -385,10 +405,6 @@ void Resource::set_as_translation_remapped(bool p_remapped) {
ResourceCache::lock.unlock();
}
-bool Resource::is_translation_remapped() const {
- return remapped_list.in_list();
-}
-
#ifdef TOOLS_ENABLED
//helps keep IDs same number when loading/saving scenes. -1 clears ID and it Returns -1 when no id stored
void Resource::set_id_for_path(const String &p_path, const String &p_id) {
@@ -481,9 +497,6 @@ void ResourceCache::clear() {
resources.clear();
}
-void ResourceCache::reload_externals() {
-}
-
bool ResourceCache::has(const String &p_path) {
lock.lock();
diff --git a/core/io/resource.h b/core/io/resource.h
index 22ce5cef43..5135664f36 100644
--- a/core/io/resource.h
+++ b/core/io/resource.h
@@ -136,7 +136,6 @@ public:
#endif
void set_as_translation_remapped(bool p_remapped);
- bool is_translation_remapped() const;
virtual RID get_rid() const; // some resources may offer conversion to RID
@@ -164,7 +163,6 @@ class ResourceCache {
friend void register_core_types();
public:
- static void reload_externals();
static bool has(const String &p_path);
static Ref<Resource> get_ref(const String &p_path);
static void get_cached_resources(List<Ref<Resource>> *p_resources);
diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp
index 45e1301930..c0463de427 100644
--- a/core/io/resource_format_binary.cpp
+++ b/core/io/resource_format_binary.cpp
@@ -91,7 +91,8 @@ enum {
// Version 2: added 64 bits support for float and int.
// Version 3: changed nodepath encoding.
// Version 4: new string ID for ext/subresources, breaks forward compat.
- FORMAT_VERSION = 4,
+ // Version 5: Ability to store script class in the header.
+ FORMAT_VERSION = 5,
FORMAT_VERSION_CAN_RENAME_DEPS = 1,
FORMAT_VERSION_NO_NODEPATH_PROPERTY = 3,
};
@@ -661,10 +662,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) {
return OK; //never reach anyway
}
-void ResourceLoaderBinary::set_local_path(const String &p_local_path) {
- res_path = p_local_path;
-}
-
Ref<Resource> ResourceLoaderBinary::get_resource() {
return resource;
}
@@ -1013,6 +1010,10 @@ void ResourceLoaderBinary::open(Ref<FileAccess> p_f, bool p_no_resources, bool p
uid = ResourceUID::INVALID_ID;
}
+ if (flags & ResourceFormatSaverBinaryInstance::FORMAT_FLAG_HAS_SCRIPT_CLASS) {
+ script_class = get_unicode_string();
+ }
+
for (int i = 0; i < ResourceFormatSaverBinaryInstance::RESERVED_FIELDS; i++) {
f->get_32(); //skip a few reserved fields
}
@@ -1117,6 +1118,57 @@ String ResourceLoaderBinary::recognize(Ref<FileAccess> p_f) {
return get_unicode_string();
}
+String ResourceLoaderBinary::recognize_script_class(Ref<FileAccess> p_f) {
+ error = OK;
+
+ f = p_f;
+ uint8_t header[4];
+ f->get_buffer(header, 4);
+ if (header[0] == 'R' && header[1] == 'S' && header[2] == 'C' && header[3] == 'C') {
+ // Compressed.
+ Ref<FileAccessCompressed> fac;
+ fac.instantiate();
+ error = fac->open_after_magic(f);
+ if (error != OK) {
+ f.unref();
+ return "";
+ }
+ f = fac;
+
+ } else if (header[0] != 'R' || header[1] != 'S' || header[2] != 'R' || header[3] != 'C') {
+ // Not normal.
+ error = ERR_FILE_UNRECOGNIZED;
+ f.unref();
+ return "";
+ }
+
+ bool big_endian = f->get_32();
+ f->get_32(); // use_real64
+
+ f->set_big_endian(big_endian != 0); //read big endian if saved as big endian
+
+ uint32_t ver_major = f->get_32();
+ f->get_32(); // ver_minor
+ uint32_t ver_fmt = f->get_32();
+
+ if (ver_fmt > FORMAT_VERSION || ver_major > VERSION_MAJOR) {
+ f.unref();
+ return "";
+ }
+
+ get_unicode_string(); // type
+
+ f->get_64(); // Metadata offset
+ uint32_t flags = f->get_32();
+ f->get_64(); // UID
+
+ if (flags & ResourceFormatSaverBinaryInstance::FORMAT_FLAG_HAS_SCRIPT_CLASS) {
+ return get_unicode_string();
+ } else {
+ return String();
+ }
+}
+
Ref<Resource> ResourceFormatLoaderBinary::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) {
if (r_error) {
*r_error = ERR_FILE_CANT_OPEN;
@@ -1299,6 +1351,9 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons
fw->store_32(flags);
fw->store_64(uid_data);
+ if (flags & ResourceFormatSaverBinaryInstance::FORMAT_FLAG_HAS_SCRIPT_CLASS) {
+ save_ustring(fw, get_ustring(f));
+ }
for (int i = 0; i < ResourceFormatSaverBinaryInstance::RESERVED_FIELDS; i++) {
fw->store_32(0); // reserved
@@ -1420,6 +1475,18 @@ String ResourceFormatLoaderBinary::get_resource_type(const String &p_path) const
return ClassDB::get_compatibility_remapped_class(r);
}
+String ResourceFormatLoaderBinary::get_resource_script_class(const String &p_path) const {
+ Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ);
+ if (f.is_null()) {
+ return ""; //could not read
+ }
+
+ ResourceLoaderBinary loader;
+ loader.local_path = ProjectSettings::get_singleton()->localize_path(p_path);
+ loader.res_path = loader.local_path;
+ return loader.recognize_script_class(f);
+}
+
ResourceUID::ID ResourceFormatLoaderBinary::get_resource_uid(const String &p_path) const {
String ext = p_path.get_extension().to_lower();
if (!ClassDB::is_resource_extension(ext)) {
@@ -2037,15 +2104,31 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const Ref<Re
save_unicode_string(f, _resource_get_class(p_resource));
f->store_64(0); //offset to import metadata
+
+ String script_class;
{
uint32_t format_flags = FORMAT_FLAG_NAMED_SCENE_IDS | FORMAT_FLAG_UIDS;
#ifdef REAL_T_IS_DOUBLE
format_flags |= FORMAT_FLAG_REAL_T_IS_DOUBLE;
#endif
+ if (!p_resource->is_class("PackedScene")) {
+ Ref<Script> s = p_resource->get_script();
+ if (s.is_valid()) {
+ script_class = s->get_global_name();
+ if (!script_class.is_empty()) {
+ format_flags |= ResourceFormatSaverBinaryInstance::FORMAT_FLAG_HAS_SCRIPT_CLASS;
+ }
+ }
+ }
+
f->store_32(format_flags);
}
ResourceUID::ID uid = ResourceSaver::get_resource_id_for_path(p_path, true);
f->store_64(uid);
+ if (!script_class.is_empty()) {
+ save_unicode_string(f, script_class);
+ }
+
for (int i = 0; i < ResourceFormatSaverBinaryInstance::RESERVED_FIELDS; i++) {
f->store_32(0); // reserved
}
@@ -2298,6 +2381,10 @@ Error ResourceFormatSaverBinaryInstance::set_uid(const String &p_path, ResourceU
fw->store_32(flags);
fw->store_64(p_uid);
+ if (flags & ResourceFormatSaverBinaryInstance::FORMAT_FLAG_HAS_SCRIPT_CLASS) {
+ save_ustring(fw, get_ustring(f));
+ }
+
//rest of file
uint8_t b = f->get_8();
while (!f->eof_reached()) {
diff --git a/core/io/resource_format_binary.h b/core/io/resource_format_binary.h
index 2e8988005f..add7cdf297 100644
--- a/core/io/resource_format_binary.h
+++ b/core/io/resource_format_binary.h
@@ -65,6 +65,7 @@ class ResourceLoaderBinary {
bool using_named_scene_ids = false;
bool using_uids = false;
+ String script_class;
bool use_sub_threads = false;
float *progress = nullptr;
Vector<ExtResource> external_resources;
@@ -92,7 +93,6 @@ class ResourceLoaderBinary {
HashMap<String, Ref<Resource>> dependency_cache;
public:
- void set_local_path(const String &p_local_path);
Ref<Resource> get_resource();
Error load();
void set_translation_remapped(bool p_remapped);
@@ -100,6 +100,7 @@ public:
void set_remaps(const HashMap<String, String> &p_remaps) { remaps = p_remaps; }
void open(Ref<FileAccess> p_f, bool p_no_resources = false, bool p_keep_uuid_paths = false);
String recognize(Ref<FileAccess> p_f);
+ String recognize_script_class(Ref<FileAccess> p_f);
void get_dependencies(Ref<FileAccess> p_f, List<String> *p_dependencies, bool p_add_types);
void get_classes_used(Ref<FileAccess> p_f, HashSet<StringName> *p_classes);
@@ -113,6 +114,7 @@ public:
virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const;
+ virtual String get_resource_script_class(const String &p_path) const;
virtual void get_classes_used(const String &p_path, HashSet<StringName> *r_classes);
virtual ResourceUID::ID get_resource_uid(const String &p_path) const;
virtual void get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types = false);
@@ -165,6 +167,7 @@ public:
FORMAT_FLAG_NAMED_SCENE_IDS = 1,
FORMAT_FLAG_UIDS = 2,
FORMAT_FLAG_REAL_T_IS_DOUBLE = 4,
+ FORMAT_FLAG_HAS_SCRIPT_CLASS = 8,
// Amount of reserved 32-bit fields in resource header
RESERVED_FIELDS = 11
diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp
index 946c31cf0d..7447119ab7 100644
--- a/core/io/resource_loader.cpp
+++ b/core/io/resource_loader.cpp
@@ -99,6 +99,12 @@ String ResourceFormatLoader::get_resource_type(const String &p_path) const {
return ret;
}
+String ResourceFormatLoader::get_resource_script_class(const String &p_path) const {
+ String ret;
+ GDVIRTUAL_CALL(_get_resource_script_class, p_path, ret);
+ return ret;
+}
+
ResourceUID::ID ResourceFormatLoader::get_resource_uid(const String &p_path) const {
int64_t uid = ResourceUID::INVALID_ID;
GDVIRTUAL_CALL(_get_resource_uid, p_path, uid);
@@ -184,6 +190,7 @@ void ResourceFormatLoader::_bind_methods() {
GDVIRTUAL_BIND(_recognize_path, "path", "type");
GDVIRTUAL_BIND(_handles_type, "type");
GDVIRTUAL_BIND(_get_resource_type, "path");
+ GDVIRTUAL_BIND(_get_resource_script_class, "path");
GDVIRTUAL_BIND(_get_resource_uid, "path");
GDVIRTUAL_BIND(_get_dependencies, "path", "add_types");
GDVIRTUAL_BIND(_rename_dependencies, "path", "renames");
@@ -764,6 +771,19 @@ String ResourceLoader::get_resource_type(const String &p_path) {
return "";
}
+String ResourceLoader::get_resource_script_class(const String &p_path) {
+ String local_path = _validate_local_path(p_path);
+
+ for (int i = 0; i < loader_count; i++) {
+ String result = loader[i]->get_resource_script_class(local_path);
+ if (!result.is_empty()) {
+ return result;
+ }
+ }
+
+ return "";
+}
+
ResourceUID::ID ResourceLoader::get_resource_uid(const String &p_path) {
String local_path = _validate_local_path(p_path);
@@ -1011,13 +1031,6 @@ bool ResourceLoader::add_custom_resource_format_loader(String script_path) {
return true;
}
-void ResourceLoader::remove_custom_resource_format_loader(String script_path) {
- Ref<ResourceFormatLoader> custom_loader = _find_custom_resource_format_loader(script_path);
- if (custom_loader.is_valid()) {
- remove_resource_format_loader(custom_loader);
- }
-}
-
void ResourceLoader::set_create_missing_resources_if_class_unavailable(bool p_enable) {
create_missing_resources_if_class_unavailable = p_enable;
}
diff --git a/core/io/resource_loader.h b/core/io/resource_loader.h
index 41ba0dc6e6..eb8155e046 100644
--- a/core/io/resource_loader.h
+++ b/core/io/resource_loader.h
@@ -54,6 +54,7 @@ protected:
GDVIRTUAL2RC(bool, _recognize_path, String, StringName)
GDVIRTUAL1RC(bool, _handles_type, StringName)
GDVIRTUAL1RC(String, _get_resource_type, String)
+ GDVIRTUAL1RC(String, _get_resource_script_class, String)
GDVIRTUAL1RC(ResourceUID::ID, _get_resource_uid, String)
GDVIRTUAL2RC(Vector<String>, _get_dependencies, String, bool)
GDVIRTUAL1RC(Vector<String>, _get_classes_used, String)
@@ -71,6 +72,7 @@ public:
virtual bool handles_type(const String &p_type) const;
virtual void get_classes_used(const String &p_path, HashSet<StringName> *r_classes);
virtual String get_resource_type(const String &p_path) const;
+ virtual String get_resource_script_class(const String &p_path) const;
virtual ResourceUID::ID get_resource_uid(const String &p_path) const;
virtual void get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types = false);
virtual Error rename_dependencies(const String &p_path, const HashMap<String, String> &p_map);
@@ -175,6 +177,7 @@ public:
static void remove_resource_format_loader(Ref<ResourceFormatLoader> p_format_loader);
static void get_classes_used(const String &p_path, HashSet<StringName> *r_classes);
static String get_resource_type(const String &p_path);
+ static String get_resource_script_class(const String &p_path);
static ResourceUID::ID get_resource_uid(const String &p_path);
static void get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types = false);
static Error rename_dependencies(const String &p_path, const HashMap<String, String> &p_map);
@@ -225,7 +228,6 @@ public:
static ResourceLoaderImport import;
static bool add_custom_resource_format_loader(String script_path);
- static void remove_custom_resource_format_loader(String script_path);
static void add_custom_loaders();
static void remove_custom_loaders();
diff --git a/core/io/resource_saver.cpp b/core/io/resource_saver.cpp
index 9809b9a48f..b8201cc6b9 100644
--- a/core/io/resource_saver.cpp
+++ b/core/io/resource_saver.cpp
@@ -250,13 +250,6 @@ bool ResourceSaver::add_custom_resource_format_saver(String script_path) {
return true;
}
-void ResourceSaver::remove_custom_resource_format_saver(String script_path) {
- Ref<ResourceFormatSaver> custom_saver = _find_custom_resource_format_saver(script_path);
- if (custom_saver.is_valid()) {
- remove_resource_format_saver(custom_saver);
- }
-}
-
void ResourceSaver::add_custom_savers() {
// Custom resource savers exploits global class names
diff --git a/core/io/resource_saver.h b/core/io/resource_saver.h
index 2043947963..9e88b2086b 100644
--- a/core/io/resource_saver.h
+++ b/core/io/resource_saver.h
@@ -101,7 +101,6 @@ public:
static void set_get_resource_id_for_path(ResourceSaverGetResourceIDForPath p_callback);
static bool add_custom_resource_format_saver(String script_path);
- static void remove_custom_resource_format_saver(String script_path);
static void add_custom_savers();
static void remove_custom_savers();
};
diff --git a/core/io/stream_peer_tls.cpp b/core/io/stream_peer_tls.cpp
index 71fadd1d30..69877974e6 100644
--- a/core/io/stream_peer_tls.cpp
+++ b/core/io/stream_peer_tls.cpp
@@ -41,31 +41,17 @@ StreamPeerTLS *StreamPeerTLS::create() {
return nullptr;
}
-bool StreamPeerTLS::available = false;
-
bool StreamPeerTLS::is_available() {
- return available;
-}
-
-void StreamPeerTLS::set_blocking_handshake_enabled(bool p_enabled) {
- blocking_handshake = p_enabled;
-}
-
-bool StreamPeerTLS::is_blocking_handshake_enabled() const {
- return blocking_handshake;
+ return _create != nullptr;
}
void StreamPeerTLS::_bind_methods() {
ClassDB::bind_method(D_METHOD("poll"), &StreamPeerTLS::poll);
- ClassDB::bind_method(D_METHOD("accept_stream", "stream", "private_key", "certificate", "chain"), &StreamPeerTLS::accept_stream, DEFVAL(Ref<X509Certificate>()));
- ClassDB::bind_method(D_METHOD("connect_to_stream", "stream", "validate_certs", "for_hostname", "valid_certificate"), &StreamPeerTLS::connect_to_stream, DEFVAL(false), DEFVAL(String()), DEFVAL(Ref<X509Certificate>()));
+ ClassDB::bind_method(D_METHOD("accept_stream", "stream", "server_options"), &StreamPeerTLS::accept_stream);
+ ClassDB::bind_method(D_METHOD("connect_to_stream", "stream", "common_name", "client_options"), &StreamPeerTLS::connect_to_stream, DEFVAL(Ref<TLSOptions>()));
ClassDB::bind_method(D_METHOD("get_status"), &StreamPeerTLS::get_status);
ClassDB::bind_method(D_METHOD("get_stream"), &StreamPeerTLS::get_stream);
ClassDB::bind_method(D_METHOD("disconnect_from_stream"), &StreamPeerTLS::disconnect_from_stream);
- ClassDB::bind_method(D_METHOD("set_blocking_handshake_enabled", "enabled"), &StreamPeerTLS::set_blocking_handshake_enabled);
- ClassDB::bind_method(D_METHOD("is_blocking_handshake_enabled"), &StreamPeerTLS::is_blocking_handshake_enabled);
-
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "blocking_handshake"), "set_blocking_handshake_enabled", "is_blocking_handshake_enabled");
BIND_ENUM_CONSTANT(STATUS_DISCONNECTED);
BIND_ENUM_CONSTANT(STATUS_HANDSHAKING);
diff --git a/core/io/stream_peer_tls.h b/core/io/stream_peer_tls.h
index 6666107ad8..5894abb7a4 100644
--- a/core/io/stream_peer_tls.h
+++ b/core/io/stream_peer_tls.h
@@ -41,10 +41,6 @@ protected:
static StreamPeerTLS *(*_create)();
static void _bind_methods();
- static bool available;
-
- bool blocking_handshake = true;
-
public:
enum Status {
STATUS_DISCONNECTED,
@@ -54,12 +50,9 @@ public:
STATUS_ERROR_HOSTNAME_MISMATCH
};
- void set_blocking_handshake_enabled(bool p_enabled);
- bool is_blocking_handshake_enabled() const;
-
virtual void poll() = 0;
- virtual Error accept_stream(Ref<StreamPeer> p_base, Ref<CryptoKey> p_key, Ref<X509Certificate> p_cert, Ref<X509Certificate> p_ca_chain = Ref<X509Certificate>()) = 0;
- virtual Error connect_to_stream(Ref<StreamPeer> p_base, bool p_validate_certs = false, const String &p_for_hostname = String(), Ref<X509Certificate> p_valid_cert = Ref<X509Certificate>()) = 0;
+ virtual Error accept_stream(Ref<StreamPeer> p_base, Ref<TLSOptions> p_options) = 0;
+ virtual Error connect_to_stream(Ref<StreamPeer> p_base, const String &p_common_name, Ref<TLSOptions> p_options) = 0;
virtual Status get_status() const = 0;
virtual Ref<StreamPeer> get_stream() const = 0;
diff --git a/core/io/xml_parser.cpp b/core/io/xml_parser.cpp
index 09836419be..5c0a017bfc 100644
--- a/core/io/xml_parser.cpp
+++ b/core/io/xml_parser.cpp
@@ -354,10 +354,10 @@ void XMLParser::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_node_offset"), &XMLParser::get_node_offset);
ClassDB::bind_method(D_METHOD("get_attribute_count"), &XMLParser::get_attribute_count);
ClassDB::bind_method(D_METHOD("get_attribute_name", "idx"), &XMLParser::get_attribute_name);
- ClassDB::bind_method(D_METHOD("get_attribute_value", "idx"), (String(XMLParser::*)(int) const) & XMLParser::get_attribute_value);
+ ClassDB::bind_method(D_METHOD("get_attribute_value", "idx"), &XMLParser::get_attribute_value);
ClassDB::bind_method(D_METHOD("has_attribute", "name"), &XMLParser::has_attribute);
- ClassDB::bind_method(D_METHOD("get_named_attribute_value", "name"), (String(XMLParser::*)(const String &) const) & XMLParser::get_attribute_value);
- ClassDB::bind_method(D_METHOD("get_named_attribute_value_safe", "name"), &XMLParser::get_attribute_value_safe);
+ ClassDB::bind_method(D_METHOD("get_named_attribute_value", "name"), &XMLParser::get_named_attribute_value);
+ ClassDB::bind_method(D_METHOD("get_named_attribute_value_safe", "name"), &XMLParser::get_named_attribute_value_safe);
ClassDB::bind_method(D_METHOD("is_empty"), &XMLParser::is_empty);
ClassDB::bind_method(D_METHOD("get_current_line"), &XMLParser::get_current_line);
ClassDB::bind_method(D_METHOD("skip_section"), &XMLParser::skip_section);
@@ -422,7 +422,7 @@ bool XMLParser::has_attribute(const String &p_name) const {
return false;
}
-String XMLParser::get_attribute_value(const String &p_name) const {
+String XMLParser::get_named_attribute_value(const String &p_name) const {
int idx = -1;
for (int i = 0; i < attributes.size(); i++) {
if (attributes[i].name == p_name) {
@@ -436,7 +436,7 @@ String XMLParser::get_attribute_value(const String &p_name) const {
return attributes[idx].value;
}
-String XMLParser::get_attribute_value_safe(const String &p_name) const {
+String XMLParser::get_named_attribute_value_safe(const String &p_name) const {
int idx = -1;
for (int i = 0; i < attributes.size(); i++) {
if (attributes[i].name == p_name) {
diff --git a/core/io/xml_parser.h b/core/io/xml_parser.h
index b4ae5c93b6..b96478c7a5 100644
--- a/core/io/xml_parser.h
+++ b/core/io/xml_parser.h
@@ -109,8 +109,8 @@ public:
String get_attribute_name(int p_idx) const;
String get_attribute_value(int p_idx) const;
bool has_attribute(const String &p_name) const;
- String get_attribute_value(const String &p_name) const;
- String get_attribute_value_safe(const String &p_name) const; // do not print error if doesn't exist
+ String get_named_attribute_value(const String &p_name) const;
+ String get_named_attribute_value_safe(const String &p_name) const; // do not print error if doesn't exist
bool is_empty() const;
int get_current_line() const;
diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp
index a54804c5dc..f0f160940d 100644
--- a/core/math/a_star.cpp
+++ b/core/math/a_star.cpp
@@ -106,11 +106,11 @@ void AStar3D::remove_point(int64_t p_id) {
bool p_exists = points.lookup(p_id, p);
ERR_FAIL_COND_MSG(!p_exists, vformat("Can't remove point. Point with id: %d doesn't exist.", p_id));
- for (OAHashMap<int64_t, Point *>::Iterator it = p->neighbours.iter(); it.valid; it = p->neighbours.next_iter(it)) {
+ for (OAHashMap<int64_t, Point *>::Iterator it = p->neighbors.iter(); it.valid; it = p->neighbors.next_iter(it)) {
Segment s(p_id, (*it.key));
segments.erase(s);
- (*it.value)->neighbours.remove(p->id);
+ (*it.value)->neighbors.remove(p->id);
(*it.value)->unlinked_neighbours.remove(p->id);
}
@@ -118,7 +118,7 @@ void AStar3D::remove_point(int64_t p_id) {
Segment s(p_id, (*it.key));
segments.erase(s);
- (*it.value)->neighbours.remove(p->id);
+ (*it.value)->neighbors.remove(p->id);
(*it.value)->unlinked_neighbours.remove(p->id);
}
@@ -138,10 +138,10 @@ void AStar3D::connect_points(int64_t p_id, int64_t p_with_id, bool bidirectional
bool to_exists = points.lookup(p_with_id, b);
ERR_FAIL_COND_MSG(!to_exists, vformat("Can't connect points. Point with id: %d doesn't exist.", p_with_id));
- a->neighbours.set(b->id, b);
+ a->neighbors.set(b->id, b);
if (bidirectional) {
- b->neighbours.set(a->id, a);
+ b->neighbors.set(a->id, a);
} else {
b->unlinked_neighbours.set(a->id, a);
}
@@ -155,7 +155,7 @@ void AStar3D::connect_points(int64_t p_id, int64_t p_with_id, bool bidirectional
if (element) {
s.direction |= element->direction;
if (s.direction == Segment::BIDIRECTIONAL) {
- // Both are neighbours of each other now
+ // Both are neighbors of each other now
a->unlinked_neighbours.remove(b->id);
b->unlinked_neighbours.remove(a->id);
}
@@ -183,9 +183,9 @@ void AStar3D::disconnect_points(int64_t p_id, int64_t p_with_id, bool bidirectio
// Erase the directions to be removed
s.direction = (element->direction & ~remove_direction);
- a->neighbours.remove(b->id);
+ a->neighbors.remove(b->id);
if (bidirectional) {
- b->neighbours.remove(a->id);
+ b->neighbors.remove(a->id);
if (element->direction != Segment::BIDIRECTIONAL) {
a->unlinked_neighbours.remove(b->id);
b->unlinked_neighbours.remove(a->id);
@@ -226,7 +226,7 @@ Vector<int64_t> AStar3D::get_point_connections(int64_t p_id) {
Vector<int64_t> point_list;
- for (OAHashMap<int64_t, Point *>::Iterator it = p->neighbours.iter(); it.valid; it = p->neighbours.next_iter(it)) {
+ for (OAHashMap<int64_t, Point *>::Iterator it = p->neighbors.iter(); it.valid; it = p->neighbors.next_iter(it)) {
point_list.push_back((*it.key));
}
@@ -327,7 +327,7 @@ bool AStar3D::_solve(Point *begin_point, Point *end_point) {
bool found_route = false;
- Vector<Point *> open_list;
+ LocalVector<Point *> open_list;
SortArray<Point *, SortPoints> sorter;
begin_point->g_score = 0;
@@ -335,19 +335,19 @@ bool AStar3D::_solve(Point *begin_point, Point *end_point) {
open_list.push_back(begin_point);
while (!open_list.is_empty()) {
- Point *p = open_list[0]; // The currently processed point
+ Point *p = open_list[0]; // The currently processed point.
if (p == end_point) {
found_route = true;
break;
}
- sorter.pop_heap(0, open_list.size(), open_list.ptrw()); // Remove the current point from the open list
+ sorter.pop_heap(0, open_list.size(), open_list.ptr()); // Remove the current point from the open list.
open_list.remove_at(open_list.size() - 1);
- p->closed_pass = pass; // Mark the point as closed
+ p->closed_pass = pass; // Mark the point as closed.
- for (OAHashMap<int64_t, Point *>::Iterator it = p->neighbours.iter(); it.valid; it = p->neighbours.next_iter(it)) {
- Point *e = *(it.value); // The neighbour point
+ for (OAHashMap<int64_t, Point *>::Iterator it = p->neighbors.iter(); it.valid; it = p->neighbors.next_iter(it)) {
+ Point *e = *(it.value); // The neighbor point.
if (!e->enabled || e->closed_pass == pass) {
continue;
@@ -370,9 +370,9 @@ bool AStar3D::_solve(Point *begin_point, Point *end_point) {
e->f_score = e->g_score + _estimate_cost(e->id, end_point->id);
if (new_point) { // The position of the new points is already known.
- sorter.push_heap(0, open_list.size() - 1, 0, e, open_list.ptrw());
+ sorter.push_heap(0, open_list.size() - 1, 0, e, open_list.ptr());
} else {
- sorter.push_heap(0, open_list.find(e), 0, e, open_list.ptrw());
+ sorter.push_heap(0, open_list.find(e), 0, e, open_list.ptr());
}
}
}
@@ -794,7 +794,7 @@ bool AStar2D::_solve(AStar3D::Point *begin_point, AStar3D::Point *end_point) {
bool found_route = false;
- Vector<AStar3D::Point *> open_list;
+ LocalVector<AStar3D::Point *> open_list;
SortArray<AStar3D::Point *, AStar3D::SortPoints> sorter;
begin_point->g_score = 0;
@@ -802,19 +802,19 @@ bool AStar2D::_solve(AStar3D::Point *begin_point, AStar3D::Point *end_point) {
open_list.push_back(begin_point);
while (!open_list.is_empty()) {
- AStar3D::Point *p = open_list[0]; // The currently processed point
+ AStar3D::Point *p = open_list[0]; // The currently processed point.
if (p == end_point) {
found_route = true;
break;
}
- sorter.pop_heap(0, open_list.size(), open_list.ptrw()); // Remove the current point from the open list
+ sorter.pop_heap(0, open_list.size(), open_list.ptr()); // Remove the current point from the open list.
open_list.remove_at(open_list.size() - 1);
- p->closed_pass = astar.pass; // Mark the point as closed
+ p->closed_pass = astar.pass; // Mark the point as closed.
- for (OAHashMap<int64_t, AStar3D::Point *>::Iterator it = p->neighbours.iter(); it.valid; it = p->neighbours.next_iter(it)) {
- AStar3D::Point *e = *(it.value); // The neighbour point
+ for (OAHashMap<int64_t, AStar3D::Point *>::Iterator it = p->neighbors.iter(); it.valid; it = p->neighbors.next_iter(it)) {
+ AStar3D::Point *e = *(it.value); // The neighbor point.
if (!e->enabled || e->closed_pass == astar.pass) {
continue;
@@ -837,9 +837,9 @@ bool AStar2D::_solve(AStar3D::Point *begin_point, AStar3D::Point *end_point) {
e->f_score = e->g_score + _estimate_cost(e->id, end_point->id);
if (new_point) { // The position of the new points is already known.
- sorter.push_heap(0, open_list.size() - 1, 0, e, open_list.ptrw());
+ sorter.push_heap(0, open_list.size() - 1, 0, e, open_list.ptr());
} else {
- sorter.push_heap(0, open_list.find(e), 0, e, open_list.ptrw());
+ sorter.push_heap(0, open_list.find(e), 0, e, open_list.ptr());
}
}
}
diff --git a/core/math/a_star.h b/core/math/a_star.h
index a475e4f2fc..fc4bb09f03 100644
--- a/core/math/a_star.h
+++ b/core/math/a_star.h
@@ -52,7 +52,7 @@ class AStar3D : public RefCounted {
real_t weight_scale = 0;
bool enabled = false;
- OAHashMap<int64_t, Point *> neighbours = 4u;
+ OAHashMap<int64_t, Point *> neighbors = 4u;
OAHashMap<int64_t, Point *> unlinked_neighbours = 4u;
// Used for pathfinding.
diff --git a/core/math/a_star_grid_2d.cpp b/core/math/a_star_grid_2d.cpp
index 30d50073d7..139dc3afb1 100644
--- a/core/math/a_star_grid_2d.cpp
+++ b/core/math/a_star_grid_2d.cpp
@@ -265,7 +265,7 @@ AStarGrid2D::Point *AStarGrid2D::_jump(Point *p_from, Point *p_to) {
return nullptr;
}
-void AStarGrid2D::_get_nbors(Point *p_point, List<Point *> &r_nbors) {
+void AStarGrid2D::_get_nbors(Point *p_point, LocalVector<Point *> &r_nbors) {
bool ts0 = false, td0 = false,
ts1 = false, td1 = false,
ts2 = false, td2 = false,
@@ -378,7 +378,7 @@ bool AStarGrid2D::_solve(Point *p_begin_point, Point *p_end_point) {
bool found_route = false;
- Vector<Point *> open_list;
+ LocalVector<Point *> open_list;
SortArray<Point *, SortPoints> sorter;
p_begin_point->g_score = 0;
@@ -394,14 +394,14 @@ bool AStarGrid2D::_solve(Point *p_begin_point, Point *p_end_point) {
break;
}
- sorter.pop_heap(0, open_list.size(), open_list.ptrw()); // Remove the current point from the open list.
+ sorter.pop_heap(0, open_list.size(), open_list.ptr()); // Remove the current point from the open list.
open_list.remove_at(open_list.size() - 1);
p->closed_pass = pass; // Mark the point as closed.
- List<Point *> nbors;
+ LocalVector<Point *> nbors;
_get_nbors(p, nbors);
- for (List<Point *>::Element *E = nbors.front(); E; E = E->next()) {
- Point *e = E->get(); // The neighbour point.
+
+ for (Point *e : nbors) {
real_t weight_scale = 1.0;
if (jumping_enabled) {
@@ -433,9 +433,9 @@ bool AStarGrid2D::_solve(Point *p_begin_point, Point *p_end_point) {
e->f_score = e->g_score + _estimate_cost(e->id, p_end_point->id);
if (new_point) { // The position of the new points is already known.
- sorter.push_heap(0, open_list.size() - 1, 0, e, open_list.ptrw());
+ sorter.push_heap(0, open_list.size() - 1, 0, e, open_list.ptr());
} else {
- sorter.push_heap(0, open_list.find(e), 0, e, open_list.ptrw());
+ sorter.push_heap(0, open_list.find(e), 0, e, open_list.ptr());
}
}
}
diff --git a/core/math/a_star_grid_2d.h b/core/math/a_star_grid_2d.h
index 6b9012a5e3..e4e62ec360 100644
--- a/core/math/a_star_grid_2d.h
+++ b/core/math/a_star_grid_2d.h
@@ -124,7 +124,7 @@ private: // Internal routines.
return &points[p_y][p_x];
}
- void _get_nbors(Point *p_point, List<Point *> &r_nbors);
+ void _get_nbors(Point *p_point, LocalVector<Point *> &r_nbors);
Point *_jump(Point *p_from, Point *p_to);
bool _solve(Point *p_begin_point, Point *p_end_point);
diff --git a/core/math/basis.cpp b/core/math/basis.cpp
index 39e383fb49..234a4ddb79 100644
--- a/core/math/basis.cpp
+++ b/core/math/basis.cpp
@@ -36,23 +36,6 @@
#define cofac(row1, col1, row2, col2) \
(rows[row1][col1] * rows[row2][col2] - rows[row1][col2] * rows[row2][col1])
-void Basis::from_z(const Vector3 &p_z) {
- if (Math::abs(p_z.z) > (real_t)Math_SQRT12) {
- // choose p in y-z plane
- real_t a = p_z[1] * p_z[1] + p_z[2] * p_z[2];
- real_t k = 1.0f / Math::sqrt(a);
- rows[0] = Vector3(0, -p_z[2] * k, p_z[1] * k);
- rows[1] = Vector3(a * k, -p_z[0] * rows[0][2], p_z[0] * rows[0][1]);
- } else {
- // choose p in x-y plane
- real_t a = p_z.x * p_z.x + p_z.y * p_z.y;
- real_t k = 1.0f / Math::sqrt(a);
- rows[0] = Vector3(-p_z.y * k, p_z.x * k, 0);
- rows[1] = Vector3(-p_z.z * rows[0].y, p_z.z * rows[0].x, a * k);
- }
- rows[2] = p_z;
-}
-
void Basis::invert() {
real_t co[3] = {
cofac(1, 1, 2, 2), cofac(1, 2, 2, 0), cofac(1, 0, 2, 1)
@@ -271,14 +254,6 @@ float Basis::get_uniform_scale() const {
return (rows[0].length() + rows[1].length() + rows[2].length()) / 3.0f;
}
-void Basis::make_scale_uniform() {
- float l = (rows[0].length() + rows[1].length() + rows[2].length()) / 3.0f;
- for (int i = 0; i < 3; i++) {
- rows[i].normalize();
- rows[i] *= l;
- }
-}
-
Basis Basis::scaled_local(const Vector3 &p_scale) const {
return (*this) * Basis::from_scale(p_scale);
}
diff --git a/core/math/basis.h b/core/math/basis.h
index b3197dbc84..bbc1d40469 100644
--- a/core/math/basis.h
+++ b/core/math/basis.h
@@ -56,8 +56,6 @@ struct _NO_DISCARD_ Basis {
_FORCE_INLINE_ real_t determinant() const;
- void from_z(const Vector3 &p_z);
-
void rotate(const Vector3 &p_axis, real_t p_angle);
Basis rotated(const Vector3 &p_axis, real_t p_angle) const;
@@ -101,8 +99,6 @@ struct _NO_DISCARD_ Basis {
void scale_orthogonal(const Vector3 &p_scale);
Basis scaled_orthogonal(const Vector3 &p_scale) const;
-
- void make_scale_uniform();
float get_uniform_scale() const;
Vector3 get_scale() const;
diff --git a/core/math/bvh.h b/core/math/bvh.h
index 9de704834b..ea8289607e 100644
--- a/core/math/bvh.h
+++ b/core/math/bvh.h
@@ -444,9 +444,7 @@ private:
params.result_array = nullptr;
params.subindex_array = nullptr;
- for (unsigned int n = 0; n < changed_items.size(); n++) {
- const BVHHandle &h = changed_items[n];
-
+ for (const BVHHandle &h : changed_items) {
// use the expanded aabb for pairing
const BOUNDS &expanded_aabb = tree._pairs[h.id()].expanded_aabb;
BVHABB_CLASS abb;
@@ -465,9 +463,7 @@ private:
params.result_count_overall = 0; // might not be needed
tree.cull_aabb(params, false);
- for (unsigned int i = 0; i < tree._cull_hits.size(); i++) {
- uint32_t ref_id = tree._cull_hits[i];
-
+ for (const uint32_t ref_id : tree._cull_hits) {
// don't collide against ourself
if (ref_id == changed_item_ref_id) {
continue;
@@ -784,7 +780,7 @@ private:
if (p_thread_safe) {
_mutex = p_mutex;
- if (_mutex->try_lock() != OK) {
+ if (!_mutex->try_lock()) {
WARN_PRINT("Info : multithread BVH access detected (benign)");
_mutex->lock();
}
diff --git a/core/math/bvh_abb.h b/core/math/bvh_abb.h
index 32b011bd3b..fb0207e0bd 100644
--- a/core/math/bvh_abb.h
+++ b/core/math/bvh_abb.h
@@ -87,7 +87,7 @@ struct BVH_ABB {
return -neg_max - min;
}
- POINT calculate_centre() const {
+ POINT calculate_center() const {
return POINT((calculate_size() * 0.5) + min);
}
diff --git a/core/math/bvh_split.inc b/core/math/bvh_split.inc
index 180bbfb511..875abedb70 100644
--- a/core/math/bvh_split.inc
+++ b/core/math/bvh_split.inc
@@ -25,7 +25,7 @@ void _split_leaf_sort_groups_simple(int &num_a, int &num_b, uint16_t *group_a, u
return;
}
- POINT centre = full_bound.calculate_centre();
+ POINT center = full_bound.calculate_center();
POINT size = full_bound.calculate_size();
int order[POINT::AXIS_COUNT];
@@ -43,7 +43,7 @@ void _split_leaf_sort_groups_simple(int &num_a, int &num_b, uint16_t *group_a, u
for (int a = 0; a < num_a; a++) {
uint32_t ind = group_a[a];
- if (temp_bounds[ind].min.coord[split_axis] > centre.coord[split_axis]) {
+ if (temp_bounds[ind].min.coord[split_axis] > center.coord[split_axis]) {
// add to b
group_b[num_b++] = ind;
@@ -75,7 +75,7 @@ void _split_leaf_sort_groups_simple(int &num_a, int &num_b, uint16_t *group_a, u
for (int a = 0; a < num_a; a++) {
uint32_t ind = group_a[a];
- if (temp_bounds[ind].min.coord[split_axis] > centre.coord[split_axis]) {
+ if (temp_bounds[ind].min.coord[split_axis] > center.coord[split_axis]) {
count++;
}
}
@@ -100,7 +100,7 @@ void _split_leaf_sort_groups_simple(int &num_a, int &num_b, uint16_t *group_a, u
for (int a = 0; a < num_a; a++) {
uint32_t ind = group_a[a];
- if (temp_bounds[ind].min.coord[split_axis] > centre.coord[split_axis]) {
+ if (temp_bounds[ind].min.coord[split_axis] > center.coord[split_axis]) {
// add to b
group_b[num_b++] = ind;
diff --git a/core/math/color.cpp b/core/math/color.cpp
index 5bae8d25d6..3e5fa7b402 100644
--- a/core/math/color.cpp
+++ b/core/math/color.cpp
@@ -194,7 +194,7 @@ void Color::set_hsv(float p_h, float p_s, float p_v, float p_alpha) {
a = p_alpha;
if (p_s == 0.0f) {
- // Achromatic (grey)
+ // Achromatic (gray)
r = g = b = p_v;
return;
}
diff --git a/core/math/delaunay_3d.h b/core/math/delaunay_3d.h
index 8ca38d571a..55923e0133 100644
--- a/core/math/delaunay_3d.h
+++ b/core/math/delaunay_3d.h
@@ -313,20 +313,20 @@ public:
//remove simplex and continue
simplex_list.erase(simplex->SE);
- for (uint32_t k = 0; k < simplex->grid_positions.size(); k++) {
- Vector3i p = simplex->grid_positions[k].pos;
- acceleration_grid[p.x][p.y][p.z].erase(simplex->grid_positions[k].E);
+ for (const GridPos &gp : simplex->grid_positions) {
+ Vector3i p = gp.pos;
+ acceleration_grid[p.x][p.y][p.z].erase(gp.E);
}
memdelete(simplex);
}
E = N;
}
- for (uint32_t j = 0; j < triangles.size(); j++) {
- if (triangles[j].bad) {
+ for (const Triangle &triangle : triangles) {
+ if (triangle.bad) {
continue;
}
- Simplex *new_simplex = memnew(Simplex(triangles[j].triangle[0], triangles[j].triangle[1], triangles[j].triangle[2], i));
+ Simplex *new_simplex = memnew(Simplex(triangle.triangle[0], triangle.triangle[1], triangle.triangle[2], i));
circum_sphere_compute(points, new_simplex);
new_simplex->SE = simplex_list.push_back(new_simplex);
{
diff --git a/core/math/expression.cpp b/core/math/expression.cpp
index da52bb9465..d1ec987d56 100644
--- a/core/math/expression.cpp
+++ b/core/math/expression.cpp
@@ -434,14 +434,13 @@ Error Expression::_get_token(Token &r_token) {
}
return OK;
- } else if (is_ascii_char(cchar) || is_underscore(cchar)) {
- String id;
- bool first = true;
+ } else if (is_unicode_identifier_start(cchar)) {
+ String id = String::chr(cchar);
+ cchar = GET_CHAR();
- while (is_ascii_char(cchar) || is_underscore(cchar) || (!first && is_digit(cchar))) {
+ while (is_unicode_identifier_continue(cchar)) {
id += String::chr(cchar);
cchar = GET_CHAR();
- first = false;
}
str_ofs--; //go back one
diff --git a/core/math/face3.cpp b/core/math/face3.cpp
index e53bbf872b..1dff0ee4a6 100644
--- a/core/math/face3.cpp
+++ b/core/math/face3.cpp
@@ -120,36 +120,6 @@ bool Face3::is_degenerate() const {
return (normal.length_squared() < (real_t)CMP_EPSILON2);
}
-Face3::Side Face3::get_side_of(const Face3 &p_face, ClockDirection p_clock_dir) const {
- int over = 0, under = 0;
-
- Plane plane = get_plane(p_clock_dir);
-
- for (int i = 0; i < 3; i++) {
- const Vector3 &v = p_face.vertex[i];
-
- if (plane.has_point(v)) { //coplanar, don't bother
- continue;
- }
-
- if (plane.is_point_over(v)) {
- over++;
- } else {
- under++;
- }
- }
-
- if (over > 0 && under == 0) {
- return SIDE_OVER;
- } else if (under > 0 && over == 0) {
- return SIDE_UNDER;
- } else if (under == 0 && over == 0) {
- return SIDE_COPLANAR;
- } else {
- return SIDE_SPANNING;
- }
-}
-
Vector3 Face3::get_random_point_inside() const {
real_t a = Math::random(0.0, 1.0);
real_t b = Math::random(0.0, 1.0);
@@ -164,20 +134,10 @@ Plane Face3::get_plane(ClockDirection p_dir) const {
return Plane(vertex[0], vertex[1], vertex[2], p_dir);
}
-Vector3 Face3::get_median_point() const {
- return (vertex[0] + vertex[1] + vertex[2]) / 3.0f;
-}
-
real_t Face3::get_area() const {
return vec3_cross(vertex[0] - vertex[1], vertex[0] - vertex[2]).length() * 0.5f;
}
-ClockDirection Face3::get_clock_dir() const {
- Vector3 normal = vec3_cross(vertex[0] - vertex[1], vertex[0] - vertex[2]);
- //printf("normal is %g,%g,%g x %g,%g,%g- wtfu is %g\n",tofloat(normal.x),tofloat(normal.y),tofloat(normal.z),tofloat(vertex[0].x),tofloat(vertex[0].y),tofloat(vertex[0].z),tofloat( normal.dot( vertex[0] ) ) );
- return (normal.dot(vertex[0]) >= 0) ? CLOCKWISE : COUNTERCLOCKWISE;
-}
-
bool Face3::intersects_aabb(const AABB &p_aabb) const {
/** TEST PLANE **/
if (!p_aabb.intersects_plane(get_plane())) {
diff --git a/core/math/face3.h b/core/math/face3.h
index 3d87de03dc..3dd47d0226 100644
--- a/core/math/face3.h
+++ b/core/math/face3.h
@@ -57,19 +57,14 @@ struct _NO_DISCARD_ Face3 {
Plane get_plane(ClockDirection p_dir = CLOCKWISE) const;
Vector3 get_random_point_inside() const;
- Side get_side_of(const Face3 &p_face, ClockDirection p_clock_dir = CLOCKWISE) const;
-
bool is_degenerate() const;
real_t get_area() const;
- Vector3 get_median_point() const;
Vector3 get_closest_point_to(const Vector3 &p_point) const;
bool intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *p_intersection = nullptr) const;
bool intersects_segment(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *p_intersection = nullptr) const;
- ClockDirection get_clock_dir() const; ///< todo, test if this is returning the proper clockwisity
-
void get_support(const Vector3 &p_normal, const Transform3D &p_transform, Vector3 *p_vertices, int *p_count, int p_max) const;
void project_range(const Vector3 &p_normal, const Transform3D &p_transform, real_t &r_min, real_t &r_max) const;
diff --git a/core/math/geometry_2d.cpp b/core/math/geometry_2d.cpp
index a0b76d31cb..74cb92539a 100644
--- a/core/math/geometry_2d.cpp
+++ b/core/math/geometry_2d.cpp
@@ -320,41 +320,6 @@ Vector<Vector<Point2>> Geometry2D::_polypath_offset(const Vector<Point2> &p_poly
return polypaths;
}
-Vector<Point2i> Geometry2D::pack_rects(const Vector<Size2i> &p_sizes, const Size2i &p_atlas_size) {
- Vector<stbrp_node> nodes;
- nodes.resize(p_atlas_size.width);
-
- stbrp_context context;
- stbrp_init_target(&context, p_atlas_size.width, p_atlas_size.height, nodes.ptrw(), p_atlas_size.width);
-
- Vector<stbrp_rect> rects;
- rects.resize(p_sizes.size());
-
- for (int i = 0; i < p_sizes.size(); i++) {
- rects.write[i].id = 0;
- rects.write[i].w = p_sizes[i].width;
- rects.write[i].h = p_sizes[i].height;
- rects.write[i].x = 0;
- rects.write[i].y = 0;
- rects.write[i].was_packed = 0;
- }
-
- int res = stbrp_pack_rects(&context, rects.ptrw(), rects.size());
- if (res == 0) { //pack failed
- return Vector<Point2i>();
- }
-
- Vector<Point2i> ret;
- ret.resize(p_sizes.size());
-
- for (int i = 0; i < p_sizes.size(); i++) {
- Point2i r(rects[i].x, rects[i].y);
- ret.write[i] = r;
- }
-
- return ret;
-}
-
Vector<Vector3i> Geometry2D::partial_pack_rects(const Vector<Vector2i> &p_sizes, const Size2i &p_atlas_size) {
Vector<stbrp_node> nodes;
nodes.resize(p_atlas_size.width);
diff --git a/core/math/geometry_2d.h b/core/math/geometry_2d.h
index b55aecf85e..0e5702e0af 100644
--- a/core/math/geometry_2d.h
+++ b/core/math/geometry_2d.h
@@ -464,7 +464,6 @@ public:
static Vector<Vector<Vector2>> decompose_polygon_in_convex(Vector<Point2> polygon);
static void make_atlas(const Vector<Size2i> &p_rects, Vector<Point2i> &r_result, Size2i &r_size);
- static Vector<Point2i> pack_rects(const Vector<Size2i> &p_sizes, const Size2i &p_atlas_size);
static Vector<Vector3i> partial_pack_rects(const Vector<Vector2i> &p_sizes, const Size2i &p_atlas_size);
private:
diff --git a/core/math/geometry_3d.cpp b/core/math/geometry_3d.cpp
index 3ac78e0709..590483bf20 100644
--- a/core/math/geometry_3d.cpp
+++ b/core/math/geometry_3d.cpp
@@ -141,21 +141,19 @@ real_t Geometry3D::get_closest_distance_between_segments(const Vector3 &p_p0, co
void Geometry3D::MeshData::optimize_vertices() {
HashMap<int, int> vtx_remap;
- for (uint32_t i = 0; i < faces.size(); i++) {
- for (uint32_t j = 0; j < faces[i].indices.size(); j++) {
- int idx = faces[i].indices[j];
- if (!vtx_remap.has(idx)) {
+ for (MeshData::Face &face : faces) {
+ for (int &index : face.indices) {
+ if (!vtx_remap.has(index)) {
int ni = vtx_remap.size();
- vtx_remap[idx] = ni;
+ vtx_remap[index] = ni;
}
-
- faces[i].indices[j] = vtx_remap[idx];
+ index = vtx_remap[index];
}
}
- for (uint32_t i = 0; i < edges.size(); i++) {
- int a = edges[i].vertex_a;
- int b = edges[i].vertex_b;
+ for (MeshData::Edge &edge : edges) {
+ int a = edge.vertex_a;
+ int b = edge.vertex_b;
if (!vtx_remap.has(a)) {
int ni = vtx_remap.size();
@@ -166,8 +164,8 @@ void Geometry3D::MeshData::optimize_vertices() {
vtx_remap[b] = ni;
}
- edges[i].vertex_a = vtx_remap[a];
- edges[i].vertex_b = vtx_remap[b];
+ edge.vertex_a = vtx_remap[a];
+ edge.vertex_b = vtx_remap[b];
}
LocalVector<Vector3> new_vertices;
@@ -198,149 +196,6 @@ struct _FaceClassify {
_FaceClassify() {}
};
-static bool _connect_faces(_FaceClassify *p_faces, int len, int p_group) {
- // Connect faces, error will occur if an edge is shared between more than 2 faces.
- // Clear connections.
-
- bool error = false;
-
- for (int i = 0; i < len; i++) {
- for (int j = 0; j < 3; j++) {
- p_faces[i].links[j].clear();
- }
- }
-
- for (int i = 0; i < len; i++) {
- if (p_faces[i].group != p_group) {
- continue;
- }
- for (int j = i + 1; j < len; j++) {
- if (p_faces[j].group != p_group) {
- continue;
- }
-
- for (int k = 0; k < 3; k++) {
- Vector3 vi1 = p_faces[i].face.vertex[k];
- Vector3 vi2 = p_faces[i].face.vertex[(k + 1) % 3];
-
- for (int l = 0; l < 3; l++) {
- Vector3 vj2 = p_faces[j].face.vertex[l];
- Vector3 vj1 = p_faces[j].face.vertex[(l + 1) % 3];
-
- if (vi1.distance_to(vj1) < 0.00001f &&
- vi2.distance_to(vj2) < 0.00001f) {
- if (p_faces[i].links[k].face != -1) {
- ERR_PRINT("already linked\n");
- error = true;
- break;
- }
- if (p_faces[j].links[l].face != -1) {
- ERR_PRINT("already linked\n");
- error = true;
- break;
- }
-
- p_faces[i].links[k].face = j;
- p_faces[i].links[k].edge = l;
- p_faces[j].links[l].face = i;
- p_faces[j].links[l].edge = k;
- }
- }
- if (error) {
- break;
- }
- }
- if (error) {
- break;
- }
- }
- if (error) {
- break;
- }
- }
-
- for (int i = 0; i < len; i++) {
- p_faces[i].valid = true;
- for (int j = 0; j < 3; j++) {
- if (p_faces[i].links[j].face == -1) {
- p_faces[i].valid = false;
- }
- }
- }
- return error;
-}
-
-static bool _group_face(_FaceClassify *p_faces, int len, int p_index, int p_group) {
- if (p_faces[p_index].group >= 0) {
- return false;
- }
-
- p_faces[p_index].group = p_group;
-
- for (int i = 0; i < 3; i++) {
- ERR_FAIL_INDEX_V(p_faces[p_index].links[i].face, len, true);
- _group_face(p_faces, len, p_faces[p_index].links[i].face, p_group);
- }
-
- return true;
-}
-
-Vector<Vector<Face3>> Geometry3D::separate_objects(Vector<Face3> p_array) {
- Vector<Vector<Face3>> objects;
-
- int len = p_array.size();
-
- const Face3 *arrayptr = p_array.ptr();
-
- Vector<_FaceClassify> fc;
-
- fc.resize(len);
-
- _FaceClassify *_fcptr = fc.ptrw();
-
- for (int i = 0; i < len; i++) {
- _fcptr[i].face = arrayptr[i];
- }
-
- bool error = _connect_faces(_fcptr, len, -1);
-
- ERR_FAIL_COND_V_MSG(error, Vector<Vector<Face3>>(), "Invalid geometry.");
-
- // Group connected faces in separate objects.
-
- int group = 0;
- for (int i = 0; i < len; i++) {
- if (!_fcptr[i].valid) {
- continue;
- }
- if (_group_face(_fcptr, len, i, group)) {
- group++;
- }
- }
-
- // Group connected faces in separate objects.
-
- for (int i = 0; i < len; i++) {
- _fcptr[i].face = arrayptr[i];
- }
-
- if (group >= 0) {
- objects.resize(group);
- Vector<Face3> *group_faces = objects.ptrw();
-
- for (int i = 0; i < len; i++) {
- if (!_fcptr[i].valid) {
- continue;
- }
- if (_fcptr[i].group >= 0 && _fcptr[i].group < group) {
- group_faces[_fcptr[i].group].push_back(_fcptr[i].face);
- }
- }
- }
-
- return objects;
-}
-
/*** GEOMETRY WRAPPER ***/
enum _CellFlags {
@@ -748,7 +603,7 @@ Geometry3D::MeshData Geometry3D::build_convex_mesh(const Vector<Plane> &p_planes
Vector3 right = p.normal.cross(ref).normalized();
Vector3 up = p.normal.cross(right).normalized();
- Vector3 center = p.center();
+ Vector3 center = p.get_center();
// make a quad clockwise
LocalVector<Vector3> vertices = {
@@ -816,10 +671,10 @@ Geometry3D::MeshData Geometry3D::build_convex_mesh(const Vector<Plane> &p_planes
MeshData::Face face;
// Add face indices.
- for (uint32_t j = 0; j < vertices.size(); j++) {
+ for (const Vector3 &vertex : vertices) {
int idx = -1;
for (uint32_t k = 0; k < mesh.vertices.size(); k++) {
- if (mesh.vertices[k].distance_to(vertices[j]) < 0.001f) {
+ if (mesh.vertices[k].distance_to(vertex) < 0.001f) {
idx = k;
break;
}
@@ -827,7 +682,7 @@ Geometry3D::MeshData Geometry3D::build_convex_mesh(const Vector<Plane> &p_planes
if (idx == -1) {
idx = mesh.vertices.size();
- mesh.vertices.push_back(vertices[j]);
+ mesh.vertices.push_back(vertex);
}
face.indices.push_back(idx);
diff --git a/core/math/geometry_3d.h b/core/math/geometry_3d.h
index 6759db5766..99c554fe05 100644
--- a/core/math/geometry_3d.h
+++ b/core/math/geometry_3d.h
@@ -532,8 +532,6 @@ public:
return clipped;
}
- static Vector<Vector<Face3>> separate_objects(Vector<Face3> p_array);
-
// Create a "wrap" that encloses the given geometry.
static Vector<Face3> wrap_geometry(Vector<Face3> p_array, real_t *p_error = nullptr);
diff --git a/core/math/plane.h b/core/math/plane.h
index 3bc7c54b9d..8159f25342 100644
--- a/core/math/plane.h
+++ b/core/math/plane.h
@@ -47,7 +47,7 @@ struct _NO_DISCARD_ Plane {
/* Plane-Point operations */
- _FORCE_INLINE_ Vector3 center() const { return normal * d; }
+ _FORCE_INLINE_ Vector3 get_center() const { return normal * d; }
Vector3 get_any_perpendicular_normal() const;
_FORCE_INLINE_ bool is_point_over(const Vector3 &p_point) const; ///< Point is over plane
diff --git a/core/math/transform_2d.cpp b/core/math/transform_2d.cpp
index 6a7ee32230..96010b4096 100644
--- a/core/math/transform_2d.cpp
+++ b/core/math/transform_2d.cpp
@@ -221,12 +221,6 @@ Transform2D Transform2D::operator*(const Transform2D &p_transform) const {
return t;
}
-Transform2D Transform2D::basis_scaled(const Size2 &p_scale) const {
- Transform2D copy = *this;
- copy.scale_basis(p_scale);
- return copy;
-}
-
Transform2D Transform2D::scaled(const Size2 &p_scale) const {
// Equivalent to left multiplication
Transform2D copy = *this;
@@ -269,39 +263,12 @@ real_t Transform2D::basis_determinant() const {
return columns[0].x * columns[1].y - columns[0].y * columns[1].x;
}
-Transform2D Transform2D::interpolate_with(const Transform2D &p_transform, const real_t p_c) const {
- //extract parameters
- Vector2 p1 = get_origin();
- Vector2 p2 = p_transform.get_origin();
-
- real_t r1 = get_rotation();
- real_t r2 = p_transform.get_rotation();
-
- Size2 s1 = get_scale();
- Size2 s2 = p_transform.get_scale();
-
- //slerp rotation
- Vector2 v1(Math::cos(r1), Math::sin(r1));
- Vector2 v2(Math::cos(r2), Math::sin(r2));
-
- real_t dot = v1.dot(v2);
-
- dot = CLAMP(dot, (real_t)-1.0, (real_t)1.0);
-
- Vector2 v;
-
- if (dot > 0.9995f) {
- v = v1.lerp(v2, p_c).normalized(); //linearly interpolate to avoid numerical precision issues
- } else {
- real_t angle = p_c * Math::acos(dot);
- Vector2 v3 = (v2 - v1 * dot).normalized();
- v = v1 * Math::cos(angle) + v3 * Math::sin(angle);
- }
-
- //construct matrix
- Transform2D res(v.angle(), p1.lerp(p2, p_c));
- res.scale_basis(s1.lerp(s2, p_c));
- return res;
+Transform2D Transform2D::interpolate_with(const Transform2D &p_transform, const real_t p_weight) const {
+ return Transform2D(
+ Math::lerp_angle(get_rotation(), p_transform.get_rotation(), p_weight),
+ get_scale().lerp(p_transform.get_scale(), p_weight),
+ Math::lerp_angle(get_skew(), p_transform.get_skew(), p_weight),
+ get_origin().lerp(p_transform.get_origin(), p_weight));
}
void Transform2D::operator*=(const real_t p_val) {
diff --git a/core/math/transform_2d.h b/core/math/transform_2d.h
index 2a0917c63f..4a17a9db37 100644
--- a/core/math/transform_2d.h
+++ b/core/math/transform_2d.h
@@ -85,7 +85,6 @@ struct _NO_DISCARD_ Transform2D {
_FORCE_INLINE_ const Vector2 &get_origin() const { return columns[2]; }
_FORCE_INLINE_ void set_origin(const Vector2 &p_origin) { columns[2] = p_origin; }
- Transform2D basis_scaled(const Size2 &p_scale) const;
Transform2D scaled(const Size2 &p_scale) const;
Transform2D scaled_local(const Size2 &p_scale) const;
Transform2D translated(const Vector2 &p_offset) const;
diff --git a/core/math/triangle_mesh.cpp b/core/math/triangle_mesh.cpp
index 4b6921d38b..0da1b8c7ad 100644
--- a/core/math/triangle_mesh.cpp
+++ b/core/math/triangle_mesh.cpp
@@ -182,90 +182,6 @@ void TriangleMesh::create(const Vector<Vector3> &p_faces, const Vector<int32_t>
valid = true;
}
-Vector3 TriangleMesh::get_area_normal(const AABB &p_aabb) const {
- uint32_t *stack = (uint32_t *)alloca(sizeof(int) * max_depth);
-
- enum {
- TEST_AABB_BIT = 0,
- VISIT_LEFT_BIT = 1,
- VISIT_RIGHT_BIT = 2,
- VISIT_DONE_BIT = 3,
- VISITED_BIT_SHIFT = 29,
- NODE_IDX_MASK = (1 << VISITED_BIT_SHIFT) - 1,
- VISITED_BIT_MASK = ~NODE_IDX_MASK,
-
- };
-
- int n_count = 0;
- Vector3 n;
-
- int level = 0;
-
- const Triangle *triangleptr = triangles.ptr();
- // const Vector3 *verticesr = vertices.ptr();
- const BVH *bvhptr = bvh.ptr();
-
- int pos = bvh.size() - 1;
-
- stack[0] = pos;
- while (true) {
- uint32_t node = stack[level] & NODE_IDX_MASK;
- const BVH &b = bvhptr[node];
- bool done = false;
-
- switch (stack[level] >> VISITED_BIT_SHIFT) {
- case TEST_AABB_BIT: {
- if (!b.aabb.intersects(p_aabb)) {
- stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node;
- } else {
- if (b.face_index >= 0) {
- const Triangle &s = triangleptr[b.face_index];
- n += s.normal;
- n_count++;
-
- stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node;
-
- } else {
- stack[level] = (VISIT_LEFT_BIT << VISITED_BIT_SHIFT) | node;
- }
- }
- continue;
- }
- case VISIT_LEFT_BIT: {
- stack[level] = (VISIT_RIGHT_BIT << VISITED_BIT_SHIFT) | node;
- level++;
- stack[level] = b.left | TEST_AABB_BIT;
- continue;
- }
- case VISIT_RIGHT_BIT: {
- stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node;
- level++;
- stack[level] = b.right | TEST_AABB_BIT;
- continue;
- }
- case VISIT_DONE_BIT: {
- if (level == 0) {
- done = true;
- break;
- } else {
- level--;
- }
- continue;
- }
- }
-
- if (done) {
- break;
- }
- }
-
- if (n_count > 0) {
- n /= n_count;
- }
-
- return n;
-}
-
bool TriangleMesh::intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_point, Vector3 &r_normal, int32_t *r_surf_index) const {
uint32_t *stack = (uint32_t *)alloca(sizeof(int) * max_depth);
@@ -468,118 +384,6 @@ bool TriangleMesh::intersect_ray(const Vector3 &p_begin, const Vector3 &p_dir, V
return inters;
}
-bool TriangleMesh::intersect_convex_shape(const Plane *p_planes, int p_plane_count, const Vector3 *p_points, int p_point_count) const {
- uint32_t *stack = (uint32_t *)alloca(sizeof(int) * max_depth);
-
- //p_fully_inside = true;
-
- enum {
- TEST_AABB_BIT = 0,
- VISIT_LEFT_BIT = 1,
- VISIT_RIGHT_BIT = 2,
- VISIT_DONE_BIT = 3,
- VISITED_BIT_SHIFT = 29,
- NODE_IDX_MASK = (1 << VISITED_BIT_SHIFT) - 1,
- VISITED_BIT_MASK = ~NODE_IDX_MASK,
-
- };
-
- int level = 0;
-
- const Triangle *triangleptr = triangles.ptr();
- const Vector3 *vertexptr = vertices.ptr();
- const BVH *bvhptr = bvh.ptr();
-
- int pos = bvh.size() - 1;
-
- stack[0] = pos;
- while (true) {
- uint32_t node = stack[level] & NODE_IDX_MASK;
- const BVH &b = bvhptr[node];
- bool done = false;
-
- switch (stack[level] >> VISITED_BIT_SHIFT) {
- case TEST_AABB_BIT: {
- if (!b.aabb.intersects_convex_shape(p_planes, p_plane_count, p_points, p_point_count)) {
- stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node;
- } else {
- if (b.face_index >= 0) {
- const Triangle &s = triangleptr[b.face_index];
-
- for (int j = 0; j < 3; ++j) {
- const Vector3 &point = vertexptr[s.indices[j]];
- const Vector3 &next_point = vertexptr[s.indices[(j + 1) % 3]];
- Vector3 res;
- bool over = true;
- for (int i = 0; i < p_plane_count; i++) {
- const Plane &p = p_planes[i];
-
- if (p.intersects_segment(point, next_point, &res)) {
- bool inisde = true;
- for (int k = 0; k < p_plane_count; k++) {
- if (k == i) {
- continue;
- }
- const Plane &pp = p_planes[k];
- if (pp.is_point_over(res)) {
- inisde = false;
- break;
- }
- }
- if (inisde) {
- return true;
- }
- }
-
- if (p.is_point_over(point)) {
- over = false;
- break;
- }
- }
- if (over) {
- return true;
- }
- }
-
- stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node;
-
- } else {
- stack[level] = (VISIT_LEFT_BIT << VISITED_BIT_SHIFT) | node;
- }
- }
- continue;
- }
- case VISIT_LEFT_BIT: {
- stack[level] = (VISIT_RIGHT_BIT << VISITED_BIT_SHIFT) | node;
- level++;
- stack[level] = b.left | TEST_AABB_BIT;
- continue;
- }
- case VISIT_RIGHT_BIT: {
- stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node;
- level++;
- stack[level] = b.right | TEST_AABB_BIT;
- continue;
- }
- case VISIT_DONE_BIT: {
- if (level == 0) {
- done = true;
- break;
- } else {
- level--;
- }
- continue;
- }
- }
-
- if (done) {
- break;
- }
- }
-
- return false;
-}
-
bool TriangleMesh::inside_convex_shape(const Plane *p_planes, int p_plane_count, const Vector3 *p_points, int p_point_count, Vector3 p_scale) const {
uint32_t *stack = (uint32_t *)alloca(sizeof(int) * max_depth);
diff --git a/core/math/triangle_mesh.h b/core/math/triangle_mesh.h
index 728fd600d5..24fc12dda9 100644
--- a/core/math/triangle_mesh.h
+++ b/core/math/triangle_mesh.h
@@ -84,9 +84,7 @@ public:
bool is_valid() const;
bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_point, Vector3 &r_normal, int32_t *r_surf_index = nullptr) const;
bool intersect_ray(const Vector3 &p_begin, const Vector3 &p_dir, Vector3 &r_point, Vector3 &r_normal, int32_t *r_surf_index = nullptr) const;
- bool intersect_convex_shape(const Plane *p_planes, int p_plane_count, const Vector3 *p_points, int p_point_count) const;
bool inside_convex_shape(const Plane *p_planes, int p_plane_count, const Vector3 *p_points, int p_point_count, Vector3 p_scale = Vector3(1, 1, 1)) const;
- Vector3 get_area_normal(const AABB &p_aabb) const;
Vector<Face3> get_faces() const;
const Vector<Triangle> &get_triangles() const { return triangles; }
diff --git a/core/object/make_virtuals.py b/core/object/make_virtuals.py
index 0ee95835a6..18f27ae4a4 100644
--- a/core/object/make_virtuals.py
+++ b/core/object/make_virtuals.py
@@ -72,6 +72,7 @@ def generate_version(argcount, const=False, returns=False):
s = s.replace("$RVOID", "(void)r_ret;") # If required, may lead to uninitialized errors
s = s.replace("$CALLPTRRETDEF", "PtrToArg<m_ret>::EncodeT ret;")
method_info += "\tmethod_info.return_val = GetTypeInfo<m_ret>::get_class_info();\\\n"
+ method_info += "\tmethod_info.return_val_metadata = GetTypeInfo<m_ret>::METADATA;\\\n"
else:
s = s.replace("$RET", "")
s = s.replace("$RVOID", "")
@@ -113,6 +114,9 @@ def generate_version(argcount, const=False, returns=False):
)
callptrargsptr += "&argval" + str(i + 1)
method_info += "\tmethod_info.arguments.push_back(GetTypeInfo<m_type" + str(i + 1) + ">::get_class_info());\\\n"
+ method_info += (
+ "\tmethod_info.arguments_metadata.push_back(GetTypeInfo<m_type" + str(i + 1) + ">::METADATA);\\\n"
+ )
if argcount:
callsiargs += "};\\\n"
diff --git a/core/object/object.cpp b/core/object/object.cpp
index 2cb56dfe6c..57aa1339ec 100644
--- a/core/object/object.cpp
+++ b/core/object/object.cpp
@@ -499,7 +499,7 @@ void Object::get_property_list(List<PropertyInfo> *p_list, bool p_reversed) cons
_get_property_listv(p_list, p_reversed);
if (!is_class("Script")) { // can still be set, but this is for user-friendliness
- p_list->push_back(PropertyInfo(Variant::OBJECT, "script", PROPERTY_HINT_RESOURCE_TYPE, "Script", PROPERTY_USAGE_DEFAULT));
+ p_list->push_back(PropertyInfo(Variant::OBJECT, "script", PROPERTY_HINT_RESOURCE_TYPE, "Script", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_NEVER_DUPLICATE));
}
if (script_instance && !p_reversed) {
@@ -1549,7 +1549,9 @@ void Object::_bind_methods() {
#define BIND_OBJ_CORE_METHOD(m_method) \
::ClassDB::add_virtual_method(get_class_static(), m_method, true, Vector<String>(), true);
- BIND_OBJ_CORE_METHOD(MethodInfo("_notification", PropertyInfo(Variant::INT, "what")));
+ MethodInfo notification_mi("_notification", PropertyInfo(Variant::INT, "what"));
+ notification_mi.arguments_metadata.push_back(GodotTypeInfo::Metadata::METADATA_INT_IS_INT32);
+ BIND_OBJ_CORE_METHOD(notification_mi);
BIND_OBJ_CORE_METHOD(MethodInfo(Variant::BOOL, "_set", PropertyInfo(Variant::STRING_NAME, "property"), PropertyInfo(Variant::NIL, "value")));
#ifdef TOOLS_ENABLED
MethodInfo miget("_get", PropertyInfo(Variant::STRING_NAME, "property"));
diff --git a/core/object/object.h b/core/object/object.h
index f78c7c34fd..5ec69a371b 100644
--- a/core/object/object.h
+++ b/core/object/object.h
@@ -109,15 +109,16 @@ enum PropertyUsageFlags {
PROPERTY_USAGE_CLASS_IS_ENUM = 1 << 16,
PROPERTY_USAGE_NIL_IS_VARIANT = 1 << 17,
PROPERTY_USAGE_ARRAY = 1 << 18, // Used in the inspector to group properties as elements of an array.
- PROPERTY_USAGE_DO_NOT_SHARE_ON_DUPLICATE = 1 << 19, // If the object is duplicated also this property will be duplicated.
- PROPERTY_USAGE_HIGH_END_GFX = 1 << 20,
- PROPERTY_USAGE_NODE_PATH_FROM_SCENE_ROOT = 1 << 21,
- PROPERTY_USAGE_RESOURCE_NOT_PERSISTENT = 1 << 22,
- PROPERTY_USAGE_KEYING_INCREMENTS = 1 << 23, // Used in inspector to increment property when keyed in animation player.
- PROPERTY_USAGE_DEFERRED_SET_RESOURCE = 1 << 24, // when loading, the resource for this property can be set at the end of loading.
- PROPERTY_USAGE_EDITOR_INSTANTIATE_OBJECT = 1 << 25, // For Object properties, instantiate them when creating in editor.
- PROPERTY_USAGE_EDITOR_BASIC_SETTING = 1 << 26, //for project or editor settings, show when basic settings are selected.
- PROPERTY_USAGE_READ_ONLY = 1 << 27, // Mark a property as read-only in the inspector.
+ PROPERTY_USAGE_ALWAYS_DUPLICATE = 1 << 19, // When duplicating a resource, always duplicate, even with subresource duplication disabled.
+ PROPERTY_USAGE_NEVER_DUPLICATE = 1 << 20, // When duplicating a resource, never duplicate, even with subresource duplication enabled.
+ PROPERTY_USAGE_HIGH_END_GFX = 1 << 21,
+ PROPERTY_USAGE_NODE_PATH_FROM_SCENE_ROOT = 1 << 22,
+ PROPERTY_USAGE_RESOURCE_NOT_PERSISTENT = 1 << 23,
+ PROPERTY_USAGE_KEYING_INCREMENTS = 1 << 24, // Used in inspector to increment property when keyed in animation player.
+ PROPERTY_USAGE_DEFERRED_SET_RESOURCE = 1 << 25, // when loading, the resource for this property can be set at the end of loading.
+ PROPERTY_USAGE_EDITOR_INSTANTIATE_OBJECT = 1 << 26, // For Object properties, instantiate them when creating in editor.
+ PROPERTY_USAGE_EDITOR_BASIC_SETTING = 1 << 27, //for project or editor settings, show when basic settings are selected.
+ PROPERTY_USAGE_READ_ONLY = 1 << 28, // Mark a property as read-only in the inspector.
PROPERTY_USAGE_DEFAULT = PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_EDITOR,
PROPERTY_USAGE_NO_EDITOR = PROPERTY_USAGE_STORAGE,
@@ -222,6 +223,16 @@ struct MethodInfo {
int id = 0;
List<PropertyInfo> arguments;
Vector<Variant> default_arguments;
+ int return_val_metadata = 0;
+ Vector<int> arguments_metadata;
+
+ int get_argument_meta(int p_arg) const {
+ ERR_FAIL_COND_V(p_arg < -1 || p_arg > arguments.size(), 0);
+ if (p_arg == -1) {
+ return return_val_metadata;
+ }
+ return arguments_metadata.size() > p_arg ? arguments_metadata[p_arg] : 0;
+ }
inline bool operator==(const MethodInfo &p_method) const { return id == p_method.id; }
inline bool operator<(const MethodInfo &p_method) const { return id == p_method.id ? (name < p_method.name) : (id < p_method.id); }
diff --git a/core/object/script_language.cpp b/core/object/script_language.cpp
index 7be3a6c688..61f5cfc22a 100644
--- a/core/object/script_language.cpp
+++ b/core/object/script_language.cpp
@@ -186,6 +186,7 @@ void ScriptServer::unregister_language(const ScriptLanguage *p_language) {
void ScriptServer::init_languages() {
{ // Load global classes.
global_classes_clear();
+#ifndef DISABLE_DEPRECATED
if (ProjectSettings::get_singleton()->has_setting("_global_script_classes")) {
Array script_classes = GLOBAL_GET("_global_script_classes");
@@ -196,6 +197,17 @@ void ScriptServer::init_languages() {
}
add_global_class(c["class"], c["base"], c["language"], c["path"]);
}
+ ProjectSettings::get_singleton()->clear("_global_script_classes");
+ }
+#endif
+
+ Array script_classes = ProjectSettings::get_singleton()->get_global_class_list();
+ for (int i = 0; i < script_classes.size(); i++) {
+ Dictionary c = script_classes[i];
+ if (!c.has("class") || !c.has("language") || !c.has("path") || !c.has("base")) {
+ continue;
+ }
+ add_global_class(c["class"], c["base"], c["language"], c["path"]);
}
}
@@ -233,9 +245,12 @@ void ScriptServer::thread_exit() {
}
HashMap<StringName, ScriptServer::GlobalScriptClass> ScriptServer::global_classes;
+HashMap<StringName, Vector<StringName>> ScriptServer::inheriters_cache;
+bool ScriptServer::inheriters_cache_dirty = true;
void ScriptServer::global_classes_clear() {
global_classes.clear();
+ inheriters_cache.clear();
}
void ScriptServer::add_global_class(const StringName &p_class, const StringName &p_base, const StringName &p_language, const String &p_path) {
@@ -245,10 +260,47 @@ void ScriptServer::add_global_class(const StringName &p_class, const StringName
g.path = p_path;
g.base = p_base;
global_classes[p_class] = g;
+ inheriters_cache_dirty = true;
}
void ScriptServer::remove_global_class(const StringName &p_class) {
global_classes.erase(p_class);
+ inheriters_cache_dirty = true;
+}
+
+void ScriptServer::get_inheriters_list(const StringName &p_base_type, List<StringName> *r_classes) {
+ if (inheriters_cache_dirty) {
+ inheriters_cache.clear();
+ for (const KeyValue<StringName, GlobalScriptClass> &K : global_classes) {
+ if (!inheriters_cache.has(K.value.base)) {
+ inheriters_cache[K.value.base] = Vector<StringName>();
+ }
+ inheriters_cache[K.value.base].push_back(K.key);
+ }
+ for (KeyValue<StringName, Vector<StringName>> &K : inheriters_cache) {
+ K.value.sort_custom<StringName::AlphCompare>();
+ }
+ inheriters_cache_dirty = false;
+ }
+
+ if (!inheriters_cache.has(p_base_type)) {
+ return;
+ }
+
+ const Vector<StringName> &v = inheriters_cache[p_base_type];
+ for (int i = 0; i < v.size(); i++) {
+ r_classes->push_back(v[i]);
+ }
+}
+
+void ScriptServer::remove_global_class_by_path(const String &p_path) {
+ for (const KeyValue<StringName, GlobalScriptClass> &kv : global_classes) {
+ if (kv.value.path == p_path) {
+ global_classes.erase(kv.key);
+ inheriters_cache_dirty = true;
+ return;
+ }
+ }
}
bool ScriptServer::is_global_class(const StringName &p_class) {
@@ -291,6 +343,17 @@ void ScriptServer::get_global_class_list(List<StringName> *r_global_classes) {
}
void ScriptServer::save_global_classes() {
+ Dictionary class_icons;
+
+ Array script_classes = ProjectSettings::get_singleton()->get_global_class_list();
+ for (int i = 0; i < script_classes.size(); i++) {
+ Dictionary d = script_classes[i];
+ if (!d.has("name") || !d.has("icon")) {
+ continue;
+ }
+ class_icons[d["name"]] = d["icon"];
+ }
+
List<StringName> gc;
get_global_class_list(&gc);
Array gcarr;
@@ -300,25 +363,18 @@ void ScriptServer::save_global_classes() {
d["language"] = global_classes[E].language;
d["path"] = global_classes[E].path;
d["base"] = global_classes[E].base;
+ d["icon"] = class_icons.get(E, "");
gcarr.push_back(d);
}
+ ProjectSettings::get_singleton()->store_global_class_list(gcarr);
+}
- Array old;
- if (ProjectSettings::get_singleton()->has_setting("_global_script_classes")) {
- old = GLOBAL_GET("_global_script_classes");
- }
- if ((!old.is_empty() || gcarr.is_empty()) && gcarr.hash() == old.hash()) {
- return;
- }
+bool ScriptServer::has_global_classes() {
+ return !global_classes.is_empty();
+}
- if (gcarr.is_empty()) {
- if (ProjectSettings::get_singleton()->has_setting("_global_script_classes")) {
- ProjectSettings::get_singleton()->clear("_global_script_classes");
- }
- } else {
- ProjectSettings::get_singleton()->set("_global_script_classes", gcarr);
- }
- ProjectSettings::get_singleton()->save();
+String ScriptServer::get_global_class_cache_file_path() {
+ return ProjectSettings::get_singleton()->get_global_class_list_path();
}
////////////////////
diff --git a/core/object/script_language.h b/core/object/script_language.h
index ff678bcd25..b1393c7196 100644
--- a/core/object/script_language.h
+++ b/core/object/script_language.h
@@ -56,10 +56,12 @@ class ScriptServer {
struct GlobalScriptClass {
StringName language;
String path;
- String base;
+ StringName base;
};
static HashMap<StringName, GlobalScriptClass> global_classes;
+ static HashMap<StringName, Vector<StringName>> inheriters_cache;
+ static bool inheriters_cache_dirty;
public:
static ScriptEditRequestFunction edit_request_func;
@@ -80,13 +82,17 @@ public:
static void global_classes_clear();
static void add_global_class(const StringName &p_class, const StringName &p_base, const StringName &p_language, const String &p_path);
static void remove_global_class(const StringName &p_class);
+ static void remove_global_class_by_path(const String &p_path);
static bool is_global_class(const StringName &p_class);
static StringName get_global_class_language(const StringName &p_class);
static String get_global_class_path(const String &p_class);
static StringName get_global_class_base(const String &p_class);
static StringName get_global_class_native_base(const String &p_class);
static void get_global_class_list(List<StringName> *r_global_classes);
+ static void get_inheriters_list(const StringName &p_base_type, List<StringName> *r_classes);
static void save_global_classes();
+ static bool has_global_classes();
+ static String get_global_class_cache_file_path();
static void init_languages();
static void finish_languages();
@@ -119,7 +125,7 @@ public:
virtual bool can_instantiate() const = 0;
virtual Ref<Script> get_base_script() const = 0; //for script inheritance
-
+ virtual StringName get_global_name() const = 0;
virtual bool inherits_script(const Ref<Script> &p_script) const = 0;
virtual StringName get_instance_base_type() const = 0; // this may not work in all scripts, will return empty if so
diff --git a/core/object/script_language_extension.h b/core/object/script_language_extension.h
index 912f2218c4..8e162a1b0f 100644
--- a/core/object/script_language_extension.h
+++ b/core/object/script_language_extension.h
@@ -53,6 +53,7 @@ protected:
public:
EXBIND0RC(bool, can_instantiate)
EXBIND0RC(Ref<Script>, get_base_script)
+ EXBIND0RC(StringName, get_global_name)
EXBIND1RC(bool, inherits_script, const Ref<Script> &)
EXBIND0RC(StringName, get_instance_base_type)
diff --git a/core/object/undo_redo.cpp b/core/object/undo_redo.cpp
index e84933eb69..077929351e 100644
--- a/core/object/undo_redo.cpp
+++ b/core/object/undo_redo.cpp
@@ -99,8 +99,7 @@ void UndoRedo::create_action(const String &p_name, MergeMode p_mode) {
}
}
- for (unsigned int i = 0; i < to_remove.size(); i++) {
- List<Operation>::Element *E = to_remove[i];
+ for (List<Operation>::Element *E : to_remove) {
// Delete all object references
E->get().delete_reference();
E->erase();
diff --git a/core/object/worker_thread_pool.cpp b/core/object/worker_thread_pool.cpp
index fc907b2301..721c8d0a10 100644
--- a/core/object/worker_thread_pool.cpp
+++ b/core/object/worker_thread_pool.cpp
@@ -377,11 +377,11 @@ void WorkerThreadPool::wait_for_group_task_completion(GroupID p_group) {
Group *group = *groupp;
if (group->low_priority_native_tasks.size() > 0) {
- for (uint32_t i = 0; i < group->low_priority_native_tasks.size(); i++) {
- group->low_priority_native_tasks[i]->low_priority_thread->wait_to_finish();
- native_thread_allocator.free(group->low_priority_native_tasks[i]->low_priority_thread);
+ for (Task *task : group->low_priority_native_tasks) {
+ task->low_priority_thread->wait_to_finish();
+ native_thread_allocator.free(task->low_priority_thread);
task_mutex.lock();
- task_allocator.free(group->low_priority_native_tasks[i]);
+ task_allocator.free(task);
task_mutex.unlock();
}
@@ -449,8 +449,8 @@ void WorkerThreadPool::finish() {
task_available_semaphore.post();
}
- for (uint32_t i = 0; i < threads.size(); i++) {
- threads[i].thread.wait_to_finish();
+ for (ThreadData &data : threads) {
+ data.thread.wait_to_finish();
}
threads.clear();
diff --git a/core/os/keyboard.cpp b/core/os/keyboard.cpp
index e0231b818f..25a4b320cd 100644
--- a/core/os/keyboard.cpp
+++ b/core/os/keyboard.cpp
@@ -63,12 +63,15 @@ static const _KeyCodeText _keycodes[] = {
{Key::CTRL ,"Ctrl"},
#if defined(MACOS_ENABLED)
{Key::META ,"Command"},
+ {Key::CMD_OR_CTRL ,"Command"},
{Key::ALT ,"Option"},
#elif defined(WINDOWS_ENABLED)
{Key::META ,"Windows"},
+ {Key::CMD_OR_CTRL ,"Ctrl"},
{Key::ALT ,"Alt"},
#else
{Key::META ,"Meta"},
+ {Key::CMD_OR_CTRL ,"Ctrl"},
{Key::ALT ,"Alt"},
#endif
{Key::CAPSLOCK ,"CapsLock"},
@@ -124,14 +127,9 @@ static const _KeyCodeText _keycodes[] = {
{Key::KP_7 ,"Kp 7"},
{Key::KP_8 ,"Kp 8"},
{Key::KP_9 ,"Kp 9"},
- {Key::SUPER_L ,"Super L"},
- {Key::SUPER_R ,"Super R"},
{Key::MENU ,"Menu"},
- {Key::HYPER_L ,"Hyper L"},
- {Key::HYPER_R ,"Hyper R"},
+ {Key::HYPER ,"Hyper"},
{Key::HELP ,"Help"},
- {Key::DIRECTION_L ,"Direction L"},
- {Key::DIRECTION_R ,"Direction R"},
{Key::BACK ,"Back"},
{Key::FORWARD ,"Forward"},
{Key::STOP ,"Stop"},
@@ -139,11 +137,6 @@ static const _KeyCodeText _keycodes[] = {
{Key::VOLUMEDOWN ,"VolumeDown"},
{Key::VOLUMEMUTE ,"VolumeMute"},
{Key::VOLUMEUP ,"VolumeUp"},
- {Key::BASSBOOST ,"BassBoost"},
- {Key::BASSUP ,"BassUp"},
- {Key::BASSDOWN ,"BassDown"},
- {Key::TREBLEUP ,"TrebleUp"},
- {Key::TREBLEDOWN ,"TrebleDown"},
{Key::MEDIAPLAY ,"MediaPlay"},
{Key::MEDIASTOP ,"MediaStop"},
{Key::MEDIAPREVIOUS ,"MediaPrevious"},
@@ -171,6 +164,10 @@ static const _KeyCodeText _keycodes[] = {
{Key::LAUNCHD ,"LaunchD"},
{Key::LAUNCHE ,"LaunchE"},
{Key::LAUNCHF ,"LaunchF"},
+ {Key::GLOBE ,"Globe"},
+ {Key::KEYBOARD ,"On-screen keyboard"},
+ {Key::JIS_EISU ,"JIS Eisu"},
+ {Key::JIS_KANA ,"JIS Kana"},
{Key::UNKNOWN ,"Unknown"},
{Key::SPACE ,"Space"},
{Key::EXCLAM ,"Exclam"},
@@ -241,72 +238,6 @@ static const _KeyCodeText _keycodes[] = {
{Key::BAR ,"Bar"},
{Key::BRACERIGHT ,"BraceRight"},
{Key::ASCIITILDE ,"AsciiTilde"},
- {Key::NOBREAKSPACE ,"NoBreakSpace"},
- {Key::EXCLAMDOWN ,"ExclamDown"},
- {Key::CENT ,"Cent"},
- {Key::STERLING ,"Sterling"},
- {Key::CURRENCY ,"Currency"},
- {Key::YEN ,"Yen"},
- {Key::BROKENBAR ,"BrokenBar"},
- {Key::SECTION ,"Section"},
- {Key::DIAERESIS ,"Diaeresis"},
- {Key::COPYRIGHT ,"Copyright"},
- {Key::ORDFEMININE ,"Ordfeminine"},
- {Key::GUILLEMOTLEFT ,"GuillemotLeft"},
- {Key::NOTSIGN ,"NotSign"},
- {Key::HYPHEN ,"Hyphen"},
- {Key::KEY_REGISTERED ,"Registered"},
- {Key::MACRON ,"Macron"},
- {Key::DEGREE ,"Degree"},
- {Key::PLUSMINUS ,"PlusMinus"},
- {Key::TWOSUPERIOR ,"TwoSuperior"},
- {Key::THREESUPERIOR ,"ThreeSuperior"},
- {Key::ACUTE ,"Acute"},
- {Key::MU ,"Mu"},
- {Key::PARAGRAPH ,"Paragraph"},
- {Key::PERIODCENTERED ,"PeriodCentered"},
- {Key::CEDILLA ,"Cedilla"},
- {Key::ONESUPERIOR ,"OneSuperior"},
- {Key::MASCULINE ,"Masculine"},
- {Key::GUILLEMOTRIGHT ,"GuillemotRight"},
- {Key::ONEQUARTER ,"OneQuarter"},
- {Key::ONEHALF ,"OneHalf"},
- {Key::THREEQUARTERS ,"ThreeQuarters"},
- {Key::QUESTIONDOWN ,"QuestionDown"},
- {Key::AGRAVE ,"Agrave"},
- {Key::AACUTE ,"Aacute"},
- {Key::ACIRCUMFLEX ,"AcircumFlex"},
- {Key::ATILDE ,"Atilde"},
- {Key::ADIAERESIS ,"Adiaeresis"},
- {Key::ARING ,"Aring"},
- {Key::AE ,"Ae"},
- {Key::CCEDILLA ,"Ccedilla"},
- {Key::EGRAVE ,"Egrave"},
- {Key::EACUTE ,"Eacute"},
- {Key::ECIRCUMFLEX ,"Ecircumflex"},
- {Key::EDIAERESIS ,"Ediaeresis"},
- {Key::IGRAVE ,"Igrave"},
- {Key::IACUTE ,"Iacute"},
- {Key::ICIRCUMFLEX ,"Icircumflex"},
- {Key::IDIAERESIS ,"Idiaeresis"},
- {Key::ETH ,"Eth"},
- {Key::NTILDE ,"Ntilde"},
- {Key::OGRAVE ,"Ograve"},
- {Key::OACUTE ,"Oacute"},
- {Key::OCIRCUMFLEX ,"Ocircumflex"},
- {Key::OTILDE ,"Otilde"},
- {Key::ODIAERESIS ,"Odiaeresis"},
- {Key::MULTIPLY ,"Multiply"},
- {Key::OOBLIQUE ,"Ooblique"},
- {Key::UGRAVE ,"Ugrave"},
- {Key::UACUTE ,"Uacute"},
- {Key::UCIRCUMFLEX ,"Ucircumflex"},
- {Key::UDIAERESIS ,"Udiaeresis"},
- {Key::YACUTE ,"Yacute"},
- {Key::THORN ,"Thorn"},
- {Key::SSHARP ,"Ssharp"},
- {Key::DIVISION ,"Division"},
- {Key::YDIAERESIS ,"Ydiaeresis"},
{Key::NONE ,nullptr}
/* clang-format on */
};
@@ -375,14 +306,9 @@ bool keycode_has_unicode(Key p_keycode) {
case Key::F33:
case Key::F34:
case Key::F35:
- case Key::SUPER_L:
- case Key::SUPER_R:
case Key::MENU:
- case Key::HYPER_L:
- case Key::HYPER_R:
+ case Key::HYPER:
case Key::HELP:
- case Key::DIRECTION_L:
- case Key::DIRECTION_R:
case Key::BACK:
case Key::FORWARD:
case Key::STOP:
@@ -390,11 +316,6 @@ bool keycode_has_unicode(Key p_keycode) {
case Key::VOLUMEDOWN:
case Key::VOLUMEMUTE:
case Key::VOLUMEUP:
- case Key::BASSBOOST:
- case Key::BASSUP:
- case Key::BASSDOWN:
- case Key::TREBLEUP:
- case Key::TREBLEDOWN:
case Key::MEDIAPLAY:
case Key::MEDIASTOP:
case Key::MEDIAPREVIOUS:
@@ -423,6 +344,10 @@ bool keycode_has_unicode(Key p_keycode) {
case Key::LAUNCHD:
case Key::LAUNCHE:
case Key::LAUNCHF:
+ case Key::GLOBE:
+ case Key::KEYBOARD:
+ case Key::JIS_EISU:
+ case Key::JIS_KANA:
return false;
default: {
}
@@ -519,3 +444,24 @@ int keycode_get_value_by_index(int p_index) {
const char *keycode_get_name_by_index(int p_index) {
return _keycodes[p_index].text;
}
+
+char32_t fix_unicode(char32_t p_char) {
+ if (p_char >= 0x20 && p_char != 0x7F) {
+ return p_char;
+ }
+ return 0;
+}
+
+Key fix_keycode(char32_t p_char, Key p_key) {
+ if (p_char >= 0x20 && p_char <= 0x7E) {
+ return (Key)String::char_uppercase(p_char);
+ }
+ return p_key;
+}
+
+Key fix_key_label(char32_t p_char, Key p_key) {
+ if (p_char >= 0x20 && p_char != 0x7F) {
+ return (Key)String::char_uppercase(p_char);
+ }
+ return p_key;
+}
diff --git a/core/os/keyboard.h b/core/os/keyboard.h
index 389baee915..84017e89a6 100644
--- a/core/os/keyboard.h
+++ b/core/os/keyboard.h
@@ -65,6 +65,11 @@ enum class Key {
SHIFT = SPECIAL | 0x15,
CTRL = SPECIAL | 0x16,
META = SPECIAL | 0x17,
+#if defined(MACOS_ENABLED)
+ CMD_OR_CTRL = META,
+#else
+ CMD_OR_CTRL = CTRL,
+#endif
ALT = SPECIAL | 0x18,
CAPSLOCK = SPECIAL | 0x19,
NUMLOCK = SPECIAL | 0x1A,
@@ -119,14 +124,9 @@ enum class Key {
KP_7 = SPECIAL | 0x8D,
KP_8 = SPECIAL | 0x8E,
KP_9 = SPECIAL | 0x8F,
- SUPER_L = SPECIAL | 0x40,
- SUPER_R = SPECIAL | 0x41,
MENU = SPECIAL | 0x42,
- HYPER_L = SPECIAL | 0x43,
- HYPER_R = SPECIAL | 0x44,
+ HYPER = SPECIAL | 0x43,
HELP = SPECIAL | 0x45,
- DIRECTION_L = SPECIAL | 0x46,
- DIRECTION_R = SPECIAL | 0x47,
BACK = SPECIAL | 0x48,
FORWARD = SPECIAL | 0x49,
STOP = SPECIAL | 0x4A,
@@ -134,11 +134,6 @@ enum class Key {
VOLUMEDOWN = SPECIAL | 0x4C,
VOLUMEMUTE = SPECIAL | 0x4D,
VOLUMEUP = SPECIAL | 0x4E,
- BASSBOOST = SPECIAL | 0x4F,
- BASSUP = SPECIAL | 0x50,
- BASSDOWN = SPECIAL | 0x51,
- TREBLEUP = SPECIAL | 0x52,
- TREBLEDOWN = SPECIAL | 0x53,
MEDIAPLAY = SPECIAL | 0x54,
MEDIASTOP = SPECIAL | 0x55,
MEDIAPREVIOUS = SPECIAL | 0x56,
@@ -168,7 +163,12 @@ enum class Key {
LAUNCHE = SPECIAL | 0x6E,
LAUNCHF = SPECIAL | 0x6F,
- UNKNOWN = SPECIAL | 0xFFFFFF,
+ GLOBE = SPECIAL | 0x70,
+ KEYBOARD = SPECIAL | 0x71,
+ JIS_EISU = SPECIAL | 0x72,
+ JIS_KANA = SPECIAL | 0x73,
+
+ UNKNOWN = SPECIAL | 0x7FFFFF,
/* PRINTABLE LATIN 1 CODES */
@@ -241,74 +241,8 @@ enum class Key {
BAR = 0x007C,
BRACERIGHT = 0x007D,
ASCIITILDE = 0x007E,
- NOBREAKSPACE = 0x00A0,
- EXCLAMDOWN = 0x00A1,
- CENT = 0x00A2,
- STERLING = 0x00A3,
- CURRENCY = 0x00A4,
YEN = 0x00A5,
- BROKENBAR = 0x00A6,
SECTION = 0x00A7,
- DIAERESIS = 0x00A8,
- COPYRIGHT = 0x00A9,
- ORDFEMININE = 0x00AA,
- GUILLEMOTLEFT = 0x00AB,
- NOTSIGN = 0x00AC,
- HYPHEN = 0x00AD,
- KEY_REGISTERED = 0x00AE, // "REGISTERED" is a reserved word on Windows.
- MACRON = 0x00AF,
- DEGREE = 0x00B0,
- PLUSMINUS = 0x00B1,
- TWOSUPERIOR = 0x00B2,
- THREESUPERIOR = 0x00B3,
- ACUTE = 0x00B4,
- MU = 0x00B5,
- PARAGRAPH = 0x00B6,
- PERIODCENTERED = 0x00B7,
- CEDILLA = 0x00B8,
- ONESUPERIOR = 0x00B9,
- MASCULINE = 0x00BA,
- GUILLEMOTRIGHT = 0x00BB,
- ONEQUARTER = 0x00BC,
- ONEHALF = 0x00BD,
- THREEQUARTERS = 0x00BE,
- QUESTIONDOWN = 0x00BF,
- AGRAVE = 0x00C0,
- AACUTE = 0x00C1,
- ACIRCUMFLEX = 0x00C2,
- ATILDE = 0x00C3,
- ADIAERESIS = 0x00C4,
- ARING = 0x00C5,
- AE = 0x00C6,
- CCEDILLA = 0x00C7,
- EGRAVE = 0x00C8,
- EACUTE = 0x00C9,
- ECIRCUMFLEX = 0x00CA,
- EDIAERESIS = 0x00CB,
- IGRAVE = 0x00CC,
- IACUTE = 0x00CD,
- ICIRCUMFLEX = 0x00CE,
- IDIAERESIS = 0x00CF,
- ETH = 0x00D0,
- NTILDE = 0x00D1,
- OGRAVE = 0x00D2,
- OACUTE = 0x00D3,
- OCIRCUMFLEX = 0x00D4,
- OTILDE = 0x00D5,
- ODIAERESIS = 0x00D6,
- MULTIPLY = 0x00D7,
- OOBLIQUE = 0x00D8,
- UGRAVE = 0x00D9,
- UACUTE = 0x00DA,
- UCIRCUMFLEX = 0x00DB,
- UDIAERESIS = 0x00DC,
- YACUTE = 0x00DD,
- THORN = 0x00DE,
- SSHARP = 0x00DF,
-
- DIVISION = 0x00F7,
- YDIAERESIS = 0x00FF,
- END_LATIN1 = 0x0100,
};
enum class KeyModifierMask {
@@ -402,4 +336,8 @@ int keycode_get_count();
int keycode_get_value_by_index(int p_index);
const char *keycode_get_name_by_index(int p_index);
+char32_t fix_unicode(char32_t p_char);
+Key fix_keycode(char32_t p_char, Key p_key);
+Key fix_key_label(char32_t p_char, Key p_key);
+
#endif // KEYBOARD_H
diff --git a/core/os/mutex.h b/core/os/mutex.h
index c91917a9a1..ceedcb235a 100644
--- a/core/os/mutex.h
+++ b/core/os/mutex.h
@@ -31,7 +31,6 @@
#ifndef MUTEX_H
#define MUTEX_H
-#include "core/error/error_list.h"
#include "core/typedefs.h"
#include <mutex>
@@ -49,8 +48,8 @@ public:
mutex.unlock();
}
- _ALWAYS_INLINE_ Error try_lock() const {
- return mutex.try_lock() ? OK : ERR_BUSY;
+ _ALWAYS_INLINE_ bool try_lock() const {
+ return mutex.try_lock();
}
};
diff --git a/core/os/os.cpp b/core/os/os.cpp
index c6fa8d307b..ef7d860d19 100644
--- a/core/os/os.cpp
+++ b/core/os/os.cpp
@@ -203,16 +203,26 @@ uint64_t OS::get_embedded_pck_offset() const {
}
// Helper function to ensure that a dir name/path will be valid on the OS
-String OS::get_safe_dir_name(const String &p_dir_name, bool p_allow_dir_separator) const {
+String OS::get_safe_dir_name(const String &p_dir_name, bool p_allow_paths) const {
+ String safe_dir_name = p_dir_name;
Vector<String> invalid_chars = String(": * ? \" < > |").split(" ");
- if (p_allow_dir_separator) {
+ if (p_allow_paths) {
// Dir separators are allowed, but disallow ".." to avoid going up the filesystem
invalid_chars.push_back("..");
+ safe_dir_name = safe_dir_name.replace("\\", "/").strip_edges();
} else {
invalid_chars.push_back("/");
+ invalid_chars.push_back("\\");
+ safe_dir_name = safe_dir_name.strip_edges();
+
+ // These directory names are invalid.
+ if (safe_dir_name == ".") {
+ safe_dir_name = "dot";
+ } else if (safe_dir_name == "..") {
+ safe_dir_name = "twodots";
+ }
}
- String safe_dir_name = p_dir_name.replace("\\", "/").strip_edges();
for (int i = 0; i < invalid_chars.size(); i++) {
safe_dir_name = safe_dir_name.replace(invalid_chars[i], "-");
}
@@ -543,6 +553,16 @@ void OS::add_frame_delay(bool p_can_draw) {
}
}
+OS::PreferredTextureFormat OS::get_preferred_texture_format() const {
+#if defined(__arm__) || defined(__aarch64__) || defined(_M_ARM) || defined(_M_ARM64)
+ return PREFERRED_TEXTURE_FORMAT_ETC2_ASTC; // By rule, ARM hardware uses ETC texture compression.
+#elif defined(__x86_64__) || defined(_M_X64) || defined(i386) || defined(__i386__) || defined(__i386) || defined(_M_IX86)
+ return PREFERRED_TEXTURE_FORMAT_S3TC_BPTC; // By rule, X86 hardware prefers S3TC and derivatives.
+#else
+ return PREFERRED_TEXTURE_FORMAT_S3TC_BPTC; // Override in platform if needed.
+#endif
+}
+
OS::OS() {
singleton = this;
diff --git a/core/os/os.h b/core/os/os.h
index b80efa47b7..d77890d89d 100644
--- a/core/os/os.h
+++ b/core/os/os.h
@@ -167,7 +167,8 @@ public:
virtual bool has_environment(const String &p_var) const = 0;
virtual String get_environment(const String &p_var) const = 0;
- virtual bool set_environment(const String &p_var, const String &p_value) const = 0;
+ virtual void set_environment(const String &p_var, const String &p_value) const = 0;
+ virtual void unset_environment(const String &p_var) const = 0;
virtual String get_name() const = 0;
virtual String get_distribution_name() const = 0;
@@ -237,7 +238,7 @@ public:
virtual uint64_t get_embedded_pck_offset() const;
- String get_safe_dir_name(const String &p_dir_name, bool p_allow_dir_separator = false) const;
+ String get_safe_dir_name(const String &p_dir_name, bool p_allow_paths = false) const;
virtual String get_godot_dir_name() const;
virtual String get_data_path() const;
@@ -289,6 +290,14 @@ public:
virtual Vector<String> get_granted_permissions() const { return Vector<String>(); }
virtual void process_and_drop_events() {}
+
+ enum PreferredTextureFormat {
+ PREFERRED_TEXTURE_FORMAT_S3TC_BPTC,
+ PREFERRED_TEXTURE_FORMAT_ETC2_ASTC
+ };
+
+ virtual PreferredTextureFormat get_preferred_texture_format() const;
+
OS();
virtual ~OS();
};
diff --git a/core/os/rw_lock.h b/core/os/rw_lock.h
index e290b7c00b..a232fcb1ce 100644
--- a/core/os/rw_lock.h
+++ b/core/os/rw_lock.h
@@ -31,7 +31,7 @@
#ifndef RW_LOCK_H
#define RW_LOCK_H
-#include "core/error/error_list.h"
+#include "core/typedefs.h"
#include <shared_mutex>
@@ -39,34 +39,34 @@ class RWLock {
mutable std::shared_timed_mutex mutex;
public:
- // Lock the rwlock, block if locked by someone else
- void read_lock() const {
+ // Lock the RWLock, block if locked by someone else.
+ _ALWAYS_INLINE_ void read_lock() const {
mutex.lock_shared();
}
- // Unlock the rwlock, let other threads continue
- void read_unlock() const {
+ // Unlock the RWLock, let other threads continue.
+ _ALWAYS_INLINE_ void read_unlock() const {
mutex.unlock_shared();
}
- // Attempt to lock the rwlock, OK on success, ERR_BUSY means it can't lock.
- Error read_try_lock() const {
- return mutex.try_lock_shared() ? OK : ERR_BUSY;
+ // Attempt to lock the RWLock for reading. True on success, false means it can't lock.
+ _ALWAYS_INLINE_ bool read_try_lock() const {
+ return mutex.try_lock_shared();
}
- // Lock the rwlock, block if locked by someone else
- void write_lock() {
+ // Lock the RWLock, block if locked by someone else.
+ _ALWAYS_INLINE_ void write_lock() {
mutex.lock();
}
- // Unlock the rwlock, let other thwrites continue
- void write_unlock() {
+ // Unlock the RWLock, let other threads continue.
+ _ALWAYS_INLINE_ void write_unlock() {
mutex.unlock();
}
- // Attempt to lock the rwlock, OK on success, ERR_BUSY means it can't lock.
- Error write_try_lock() {
- return mutex.try_lock() ? OK : ERR_BUSY;
+ // Attempt to lock the RWLock for writing. True on success, false means it can't lock.
+ _ALWAYS_INLINE_ bool write_try_lock() {
+ return mutex.try_lock();
}
};
@@ -74,11 +74,11 @@ class RWLockRead {
const RWLock &lock;
public:
- RWLockRead(const RWLock &p_lock) :
+ _ALWAYS_INLINE_ RWLockRead(const RWLock &p_lock) :
lock(p_lock) {
lock.read_lock();
}
- ~RWLockRead() {
+ _ALWAYS_INLINE_ ~RWLockRead() {
lock.read_unlock();
}
};
@@ -87,11 +87,11 @@ class RWLockWrite {
RWLock &lock;
public:
- RWLockWrite(RWLock &p_lock) :
+ _ALWAYS_INLINE_ RWLockWrite(RWLock &p_lock) :
lock(p_lock) {
lock.write_lock();
}
- ~RWLockWrite() {
+ _ALWAYS_INLINE_ ~RWLockWrite() {
lock.write_unlock();
}
};
diff --git a/core/os/semaphore.h b/core/os/semaphore.h
index 6a290f21c6..a992a4587d 100644
--- a/core/os/semaphore.h
+++ b/core/os/semaphore.h
@@ -39,32 +39,33 @@
class Semaphore {
private:
- mutable std::mutex mutex_;
- mutable std::condition_variable condition_;
- mutable unsigned long count_ = 0; // Initialized as locked.
+ mutable std::mutex mutex;
+ mutable std::condition_variable condition;
+ mutable uint32_t count = 0; // Initialized as locked.
public:
_ALWAYS_INLINE_ void post() const {
- std::lock_guard<decltype(mutex_)> lock(mutex_);
- ++count_;
- condition_.notify_one();
+ std::lock_guard lock(mutex);
+ count++;
+ condition.notify_one();
}
_ALWAYS_INLINE_ void wait() const {
- std::unique_lock<decltype(mutex_)> lock(mutex_);
- while (!count_) { // Handle spurious wake-ups.
- condition_.wait(lock);
+ std::unique_lock lock(mutex);
+ while (!count) { // Handle spurious wake-ups.
+ condition.wait(lock);
}
- --count_;
+ count--;
}
_ALWAYS_INLINE_ bool try_wait() const {
- std::lock_guard<decltype(mutex_)> lock(mutex_);
- if (count_) {
- --count_;
+ std::lock_guard lock(mutex);
+ if (count) {
+ count--;
return true;
+ } else {
+ return false;
}
- return false;
}
};
diff --git a/core/register_core_types.cpp b/core/register_core_types.cpp
index 700174bdae..a374e7c009 100644
--- a/core/register_core_types.cpp
+++ b/core/register_core_types.cpp
@@ -209,6 +209,7 @@ void register_core_types() {
GDREGISTER_CLASS(AESContext);
ClassDB::register_custom_instance_class<X509Certificate>();
ClassDB::register_custom_instance_class<CryptoKey>();
+ GDREGISTER_ABSTRACT_CLASS(TLSOptions);
ClassDB::register_custom_instance_class<HMACContext>();
ClassDB::register_custom_instance_class<Crypto>();
ClassDB::register_custom_instance_class<StreamPeerTLS>();
diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp
index 9e468f7075..b34d9f3271 100644
--- a/core/string/ustring.cpp
+++ b/core/string/ustring.cpp
@@ -4342,6 +4342,9 @@ bool String::is_valid_html_color() const {
return Color::html_is_valid(*this);
}
+// Changes made to the set of invalid filename characters must also be reflected in the String documentation for is_valid_filename.
+static const char *invalid_filename_characters = ": / \\ ? * \" | % < >";
+
bool String::is_valid_filename() const {
String stripped = strip_edges();
if (*this != stripped) {
@@ -4352,7 +4355,22 @@ bool String::is_valid_filename() const {
return false;
}
- return !(find(":") != -1 || find("/") != -1 || find("\\") != -1 || find("?") != -1 || find("*") != -1 || find("\"") != -1 || find("|") != -1 || find("%") != -1 || find("<") != -1 || find(">") != -1);
+ Vector<String> chars = String(invalid_filename_characters).split(" ");
+ for (const String &ch : chars) {
+ if (contains(ch)) {
+ return false;
+ }
+ }
+ return true;
+}
+
+String String::validate_filename() const {
+ Vector<String> chars = String(invalid_filename_characters).split(" ");
+ String name = strip_edges();
+ for (int i = 0; i < chars.size(); i++) {
+ name = name.replace(chars[i], "_");
+ }
+ return name;
}
bool String::is_valid_ip_address() const {
diff --git a/core/string/ustring.h b/core/string/ustring.h
index 6338f1d3cd..1582504c57 100644
--- a/core/string/ustring.h
+++ b/core/string/ustring.h
@@ -433,6 +433,7 @@ public:
static const String invalid_node_name_characters;
String validate_node_name() const;
String validate_identifier() const;
+ String validate_filename() const;
bool is_valid_identifier() const;
bool is_valid_int() const;
diff --git a/core/templates/local_vector.h b/core/templates/local_vector.h
index 55761bb604..5311a94987 100644
--- a/core/templates/local_vector.h
+++ b/core/templates/local_vector.h
@@ -169,6 +169,70 @@ public:
return data[p_index];
}
+ struct Iterator {
+ _FORCE_INLINE_ T &operator*() const {
+ return *elem_ptr;
+ }
+ _FORCE_INLINE_ T *operator->() const { return elem_ptr; }
+ _FORCE_INLINE_ Iterator &operator++() {
+ elem_ptr++;
+ return *this;
+ }
+ _FORCE_INLINE_ Iterator &operator--() {
+ elem_ptr--;
+ return *this;
+ }
+
+ _FORCE_INLINE_ bool operator==(const Iterator &b) const { return elem_ptr == b.elem_ptr; }
+ _FORCE_INLINE_ bool operator!=(const Iterator &b) const { return elem_ptr != b.elem_ptr; }
+
+ Iterator(T *p_ptr) { elem_ptr = p_ptr; }
+ Iterator() {}
+ Iterator(const Iterator &p_it) { elem_ptr = p_it.elem_ptr; }
+
+ private:
+ T *elem_ptr = nullptr;
+ };
+
+ struct ConstIterator {
+ _FORCE_INLINE_ const T &operator*() const {
+ return *elem_ptr;
+ }
+ _FORCE_INLINE_ const T *operator->() const { return elem_ptr; }
+ _FORCE_INLINE_ ConstIterator &operator++() {
+ elem_ptr++;
+ return *this;
+ }
+ _FORCE_INLINE_ ConstIterator &operator--() {
+ elem_ptr--;
+ return *this;
+ }
+
+ _FORCE_INLINE_ bool operator==(const ConstIterator &b) const { return elem_ptr == b.elem_ptr; }
+ _FORCE_INLINE_ bool operator!=(const ConstIterator &b) const { return elem_ptr != b.elem_ptr; }
+
+ ConstIterator(const T *p_ptr) { elem_ptr = p_ptr; }
+ ConstIterator() {}
+ ConstIterator(const ConstIterator &p_it) { elem_ptr = p_it.elem_ptr; }
+
+ private:
+ const T *elem_ptr = nullptr;
+ };
+
+ _FORCE_INLINE_ Iterator begin() {
+ return Iterator(data);
+ }
+ _FORCE_INLINE_ Iterator end() {
+ return Iterator(data + size());
+ }
+
+ _FORCE_INLINE_ ConstIterator begin() const {
+ return ConstIterator(ptr());
+ }
+ _FORCE_INLINE_ ConstIterator end() const {
+ return ConstIterator(ptr() + size());
+ }
+
void insert(U p_pos, T p_val) {
ERR_FAIL_UNSIGNED_INDEX(p_pos, count + 1);
if (p_pos == count) {
diff --git a/core/variant/array.cpp b/core/variant/array.cpp
index f8af78f3c1..d3c5ca801f 100644
--- a/core/variant/array.cpp
+++ b/core/variant/array.cpp
@@ -64,7 +64,7 @@ void Array::_ref(const Array &p_from) const {
_unref();
- _p = p_from._p;
+ _p = _fp;
}
void Array::_unref() const {
@@ -191,62 +191,73 @@ uint32_t Array::recursive_hash(int recursion_count) const {
return hash_fmix32(h);
}
-bool Array::_assign(const Array &p_array) {
- bool can_convert = p_array._p->typed.type == Variant::NIL;
- can_convert |= _p->typed.type == Variant::STRING && p_array._p->typed.type == Variant::STRING_NAME;
- can_convert |= _p->typed.type == Variant::STRING_NAME && p_array._p->typed.type == Variant::STRING;
+void Array::operator=(const Array &p_array) {
+ if (this == &p_array) {
+ return;
+ }
+ _ref(p_array);
+}
+
+void Array::assign(const Array &p_array) {
+ const ContainerTypeValidate &typed = _p->typed;
+ const ContainerTypeValidate &source_typed = p_array._p->typed;
- if (_p->typed.type != Variant::OBJECT && _p->typed.type == p_array._p->typed.type) {
- //same type or untyped, just reference, should be fine
- _ref(p_array);
- } else if (_p->typed.type == Variant::NIL) { //from typed to untyped, must copy, but this is cheap anyway
+ if (typed == source_typed || typed.type == Variant::NIL || (source_typed.type == Variant::OBJECT && typed.can_reference(source_typed))) {
+ // from same to same or
+ // from anything to variants or
+ // from subclasses to base classes
_p->array = p_array._p->array;
- } else if (can_convert) { //from untyped to typed, must try to check if they are all valid
- if (_p->typed.type == Variant::OBJECT) {
- //for objects, it needs full validation, either can be converted or fail
- for (int i = 0; i < p_array._p->array.size(); i++) {
- const Variant &element = p_array._p->array[i];
- if (element.get_type() != Variant::OBJECT || !_p->typed.validate_object(element, "assign")) {
- return false;
- }
- }
- _p->array = p_array._p->array; //then just copy, which is cheap anyway
+ return;
+ }
- } else {
- //for non objects, we need to check if there is a valid conversion, which needs to happen one by one, so this is the worst case.
- Vector<Variant> new_array;
- new_array.resize(p_array._p->array.size());
- for (int i = 0; i < p_array._p->array.size(); i++) {
- Variant src_val = p_array._p->array[i];
- if (src_val.get_type() == _p->typed.type) {
- new_array.write[i] = src_val;
- } else if (Variant::can_convert_strict(src_val.get_type(), _p->typed.type)) {
- Variant *ptr = &src_val;
- Callable::CallError ce;
- Variant::construct(_p->typed.type, new_array.write[i], (const Variant **)&ptr, 1, ce);
- if (ce.error != Callable::CallError::CALL_OK) {
- ERR_FAIL_V_MSG(false, "Unable to convert array index " + itos(i) + " from '" + Variant::get_type_name(src_val.get_type()) + "' to '" + Variant::get_type_name(_p->typed.type) + "'.");
- }
- } else {
- ERR_FAIL_V_MSG(false, "Unable to convert array index " + itos(i) + " from '" + Variant::get_type_name(src_val.get_type()) + "' to '" + Variant::get_type_name(_p->typed.type) + "'.");
- }
+ const Variant *source = p_array._p->array.ptr();
+ int size = p_array._p->array.size();
+
+ if ((source_typed.type == Variant::NIL && typed.type == Variant::OBJECT) || (source_typed.type == Variant::OBJECT && source_typed.can_reference(typed))) {
+ // from variants to objects or
+ // from base classes to subclasses
+ for (int i = 0; i < size; i++) {
+ const Variant &element = source[i];
+ if (element.get_type() != Variant::NIL && (element.get_type() != Variant::OBJECT || !typed.validate_object(element, "assign"))) {
+ ERR_FAIL_MSG(vformat(R"(Unable to convert array index %i from "%s" to "%s".)", i, Variant::get_type_name(element.get_type()), Variant::get_type_name(typed.type)));
}
+ }
+ _p->array = p_array._p->array;
+ return;
+ }
- _p->array = new_array;
+ Vector<Variant> array;
+ array.resize(size);
+ Variant *data = array.ptrw();
+
+ if (source_typed.type == Variant::NIL && typed.type != Variant::OBJECT) {
+ // from variants to primitives
+ for (int i = 0; i < size; i++) {
+ const Variant *value = source + i;
+ if (value->get_type() == typed.type) {
+ data[i] = *value;
+ continue;
+ }
+ if (!Variant::can_convert_strict(value->get_type(), typed.type)) {
+ ERR_FAIL_MSG("Unable to convert array index " + itos(i) + " from '" + Variant::get_type_name(value->get_type()) + "' to '" + Variant::get_type_name(typed.type) + "'.");
+ }
+ Callable::CallError ce;
+ Variant::construct(typed.type, data[i], &value, 1, ce);
+ ERR_FAIL_COND_MSG(ce.error, vformat(R"(Unable to convert array index %i from "%s" to "%s".)", i, Variant::get_type_name(value->get_type()), Variant::get_type_name(typed.type)));
+ }
+ } else if (Variant::can_convert_strict(source_typed.type, typed.type)) {
+ // from primitives to different convertable primitives
+ for (int i = 0; i < size; i++) {
+ const Variant *value = source + i;
+ Callable::CallError ce;
+ Variant::construct(typed.type, data[i], &value, 1, ce);
+ ERR_FAIL_COND_MSG(ce.error, vformat(R"(Unable to convert array index %i from "%s" to "%s".)", i, Variant::get_type_name(value->get_type()), Variant::get_type_name(typed.type)));
}
- } else if (_p->typed.can_reference(p_array._p->typed)) { //same type or compatible
- _ref(p_array);
} else {
- ERR_FAIL_V_MSG(false, "Assignment of arrays of incompatible types.");
+ ERR_FAIL_MSG(vformat(R"(Cannot assign contents of "Array[%s]" to "Array[%s]".)", Variant::get_type_name(source_typed.type), Variant::get_type_name(typed.type)));
}
- return true;
-}
-void Array::operator=(const Array &p_array) {
- if (this == &p_array) {
- return;
- }
- _ref(p_array);
+ _p->array = array;
}
void Array::push_back(const Variant &p_value) {
@@ -269,7 +280,15 @@ void Array::append_array(const Array &p_array) {
Error Array::resize(int p_new_size) {
ERR_FAIL_COND_V_MSG(_p->read_only, ERR_LOCKED, "Array is in read-only state.");
- return _p->array.resize(p_new_size);
+ Variant::Type &variant_type = _p->typed.type;
+ int old_size = _p->array.size();
+ Error err = _p->array.resize_zeroed(p_new_size);
+ if (!err && variant_type != Variant::NIL && variant_type != Variant::OBJECT) {
+ for (int i = old_size; i < p_new_size; i++) {
+ VariantInternal::initialize(&_p->array.write[i], variant_type);
+ }
+ }
+ return err;
}
Error Array::insert(int p_pos, const Variant &p_value) {
@@ -403,24 +422,22 @@ Array Array::duplicate(bool p_deep) const {
Array Array::recursive_duplicate(bool p_deep, int recursion_count) const {
Array new_arr;
+ new_arr._p->typed = _p->typed;
if (recursion_count > MAX_RECURSION) {
ERR_PRINT("Max recursion reached");
return new_arr;
}
- int element_count = size();
- new_arr.resize(element_count);
- new_arr._p->typed = _p->typed;
if (p_deep) {
recursion_count++;
+ int element_count = size();
+ new_arr.resize(element_count);
for (int i = 0; i < element_count; i++) {
new_arr[i] = get(i).recursive_duplicate(true, recursion_count);
}
} else {
- for (int i = 0; i < element_count; i++) {
- new_arr[i] = get(i);
- }
+ new_arr._p->array = _p->array;
}
return new_arr;
@@ -737,11 +754,7 @@ Array::Array(const Array &p_from, uint32_t p_type, const StringName &p_class_nam
_p = memnew(ArrayPrivate);
_p->refcount.init();
set_typed(p_type, p_class_name, p_script);
- _assign(p_from);
-}
-
-bool Array::typed_assign(const Array &p_other) {
- return _assign(p_other);
+ assign(p_from);
}
void Array::set_typed(uint32_t p_type, const StringName &p_class_name, const Variant &p_script) {
@@ -763,6 +776,10 @@ bool Array::is_typed() const {
return _p->typed.type != Variant::NIL;
}
+bool Array::is_same_typed(const Array &p_other) const {
+ return _p->typed == p_other._p->typed;
+}
+
uint32_t Array::get_typed_builtin() const {
return _p->typed.type;
}
@@ -775,15 +792,9 @@ Variant Array::get_typed_script() const {
return _p->typed.script;
}
-void Array::set_read_only(bool p_enable) {
- if (p_enable == bool(_p->read_only != nullptr)) {
- return;
- }
- if (p_enable) {
+void Array::make_read_only() {
+ if (_p->read_only == nullptr) {
_p->read_only = memnew(Variant);
- } else {
- memdelete(_p->read_only);
- _p->read_only = nullptr;
}
}
diff --git a/core/variant/array.h b/core/variant/array.h
index 3728c22fe0..4ef8ba8ce7 100644
--- a/core/variant/array.h
+++ b/core/variant/array.h
@@ -43,13 +43,11 @@ class Callable;
class Array {
mutable ArrayPrivate *_p;
- void _ref(const Array &p_from) const;
void _unref() const;
-protected:
- bool _assign(const Array &p_array);
-
public:
+ void _ref(const Array &p_from) const;
+
Variant &operator[](int p_idx);
const Variant &operator[](int p_idx) const;
@@ -68,6 +66,7 @@ public:
uint32_t recursive_hash(int recursion_count) const;
void operator=(const Array &p_array);
+ void assign(const Array &p_array);
void push_back(const Variant &p_value);
_FORCE_INLINE_ void append(const Variant &p_value) { push_back(p_value); } //for python compatibility
void append_array(const Array &p_array);
@@ -120,14 +119,14 @@ public:
const void *id() const;
- bool typed_assign(const Array &p_other);
void set_typed(uint32_t p_type, const StringName &p_class_name, const Variant &p_script);
bool is_typed() const;
+ bool is_same_typed(const Array &p_other) const;
uint32_t get_typed_builtin() const;
StringName get_typed_class_name() const;
Variant get_typed_script() const;
- void set_read_only(bool p_enable);
+ void make_read_only();
bool is_read_only() const;
Array(const Array &p_base, uint32_t p_type, const StringName &p_class_name, const Variant &p_script);
diff --git a/core/variant/container_type_validate.h b/core/variant/container_type_validate.h
index 377be03bdf..796b66dc77 100644
--- a/core/variant/container_type_validate.h
+++ b/core/variant/container_type_validate.h
@@ -74,8 +74,15 @@ struct ContainerTypeValidate {
return true;
}
+ _FORCE_INLINE_ bool operator==(const ContainerTypeValidate &p_type) const {
+ return type == p_type.type && class_name == p_type.class_name && script == p_type.script;
+ }
+ _FORCE_INLINE_ bool operator!=(const ContainerTypeValidate &p_type) const {
+ return type != p_type.type || class_name != p_type.class_name || script != p_type.script;
+ }
+
// Coerces String and StringName into each other when needed.
- _FORCE_INLINE_ bool validate(Variant &inout_variant, const char *p_operation = "use") {
+ _FORCE_INLINE_ bool validate(Variant &inout_variant, const char *p_operation = "use") const {
if (type == Variant::NIL) {
return true;
}
@@ -102,7 +109,7 @@ struct ContainerTypeValidate {
return validate_object(inout_variant, p_operation);
}
- _FORCE_INLINE_ bool validate_object(const Variant &p_variant, const char *p_operation = "use") {
+ _FORCE_INLINE_ bool validate_object(const Variant &p_variant, const char *p_operation = "use") const {
ERR_FAIL_COND_V(p_variant.get_type() != Variant::OBJECT, false);
#ifdef DEBUG_ENABLED
diff --git a/core/variant/dictionary.cpp b/core/variant/dictionary.cpp
index f87064a0d1..0429508cc5 100644
--- a/core/variant/dictionary.cpp
+++ b/core/variant/dictionary.cpp
@@ -333,15 +333,9 @@ Dictionary Dictionary::duplicate(bool p_deep) const {
return recursive_duplicate(p_deep, 0);
}
-void Dictionary::set_read_only(bool p_enable) {
- if (p_enable == bool(_p->read_only != nullptr)) {
- return;
- }
- if (p_enable) {
+void Dictionary::make_read_only() {
+ if (_p->read_only == nullptr) {
_p->read_only = memnew(Variant);
- } else {
- memdelete(_p->read_only);
- _p->read_only = nullptr;
}
}
bool Dictionary::is_read_only() const {
diff --git a/core/variant/dictionary.h b/core/variant/dictionary.h
index e6d8ebe25b..8935d35ed9 100644
--- a/core/variant/dictionary.h
+++ b/core/variant/dictionary.h
@@ -86,7 +86,7 @@ public:
Dictionary duplicate(bool p_deep = false) const;
Dictionary recursive_duplicate(bool p_deep, int recursion_count) const;
- void set_read_only(bool p_enable);
+ void make_read_only();
bool is_read_only() const;
const void *id() const;
diff --git a/core/variant/typed_array.h b/core/variant/typed_array.h
index 5aeabbacf8..03e557819b 100644
--- a/core/variant/typed_array.h
+++ b/core/variant/typed_array.h
@@ -40,14 +40,9 @@
template <class T>
class TypedArray : public Array {
public:
- template <class U>
- _FORCE_INLINE_ void operator=(const TypedArray<U> &p_array) {
- static_assert(__is_base_of(T, U));
- _assign(p_array);
- }
-
_FORCE_INLINE_ void operator=(const Array &p_array) {
- _assign(p_array);
+ ERR_FAIL_COND_MSG(!is_same_typed(p_array), "Cannot assign an array with a different element type.");
+ _ref(p_array);
}
_FORCE_INLINE_ TypedArray(const Variant &p_variant) :
Array(Array(p_variant), Variant::OBJECT, T::get_class_static(), Variant()) {
@@ -62,22 +57,23 @@ public:
//specialization for the rest of variant types
-#define MAKE_TYPED_ARRAY(m_type, m_variant_type) \
- template <> \
- class TypedArray<m_type> : public Array { \
- public: \
- _FORCE_INLINE_ void operator=(const Array &p_array) { \
- _assign(p_array); \
- } \
- _FORCE_INLINE_ TypedArray(const Variant &p_variant) : \
- Array(Array(p_variant), m_variant_type, StringName(), Variant()) { \
- } \
- _FORCE_INLINE_ TypedArray(const Array &p_array) : \
- Array(p_array, m_variant_type, StringName(), Variant()) { \
- } \
- _FORCE_INLINE_ TypedArray() { \
- set_typed(m_variant_type, StringName(), Variant()); \
- } \
+#define MAKE_TYPED_ARRAY(m_type, m_variant_type) \
+ template <> \
+ class TypedArray<m_type> : public Array { \
+ public: \
+ _FORCE_INLINE_ void operator=(const Array &p_array) { \
+ ERR_FAIL_COND_MSG(!is_same_typed(p_array), "Cannot assign an array with a different element type."); \
+ _ref(p_array); \
+ } \
+ _FORCE_INLINE_ TypedArray(const Variant &p_variant) : \
+ Array(Array(p_variant), m_variant_type, StringName(), Variant()) { \
+ } \
+ _FORCE_INLINE_ TypedArray(const Array &p_array) : \
+ Array(p_array, m_variant_type, StringName(), Variant()) { \
+ } \
+ _FORCE_INLINE_ TypedArray() { \
+ set_typed(m_variant_type, StringName(), Variant()); \
+ } \
};
MAKE_TYPED_ARRAY(bool, Variant::BOOL)
diff --git a/core/variant/variant.cpp b/core/variant/variant.cpp
index ca42738b05..672b030806 100644
--- a/core/variant/variant.cpp
+++ b/core/variant/variant.cpp
@@ -3492,6 +3492,46 @@ bool Variant::hash_compare(const Variant &p_variant, int recursion_count) const
}
}
+bool Variant::identity_compare(const Variant &p_variant) const {
+ if (type != p_variant.type) {
+ return false;
+ }
+
+ switch (type) {
+ case OBJECT: {
+ return _get_obj().obj == p_variant._get_obj().obj;
+ } break;
+
+ case DICTIONARY: {
+ const Dictionary &l = *(reinterpret_cast<const Dictionary *>(_data._mem));
+ const Dictionary &r = *(reinterpret_cast<const Dictionary *>(p_variant._data._mem));
+ return l.id() == r.id();
+ } break;
+
+ case ARRAY: {
+ const Array &l = *(reinterpret_cast<const Array *>(_data._mem));
+ const Array &r = *(reinterpret_cast<const Array *>(p_variant._data._mem));
+ return l.id() == r.id();
+ } break;
+
+ case PACKED_BYTE_ARRAY:
+ case PACKED_INT32_ARRAY:
+ case PACKED_INT64_ARRAY:
+ case PACKED_FLOAT32_ARRAY:
+ case PACKED_FLOAT64_ARRAY:
+ case PACKED_STRING_ARRAY:
+ case PACKED_VECTOR2_ARRAY:
+ case PACKED_VECTOR3_ARRAY:
+ case PACKED_COLOR_ARRAY: {
+ return _data.packed_array == p_variant._data.packed_array;
+ } break;
+
+ default: {
+ return hash_compare(p_variant);
+ }
+ }
+}
+
bool StringLikeVariantComparator::compare(const Variant &p_lhs, const Variant &p_rhs) {
if (p_lhs.hash_compare(p_rhs)) {
return true;
diff --git a/core/variant/variant.h b/core/variant/variant.h
index fff59c43a6..b2f31a6d57 100644
--- a/core/variant/variant.h
+++ b/core/variant/variant.h
@@ -655,6 +655,7 @@ public:
static bool has_indexing(Variant::Type p_type);
static Variant::Type get_indexed_element_type(Variant::Type p_type);
+ static uint32_t get_indexed_element_usage(Variant::Type p_type);
typedef void (*ValidatedIndexedSetter)(Variant *base, int64_t index, const Variant *value, bool *oob);
typedef void (*ValidatedIndexedGetter)(const Variant *base, int64_t index, Variant *value, bool *oob);
@@ -747,6 +748,7 @@ public:
uint32_t recursive_hash(int recursion_count) const;
bool hash_compare(const Variant &p_variant, int recursion_count = 0) const;
+ bool identity_compare(const Variant &p_variant) const;
bool booleanize() const;
String stringify(int recursion_count = 0) const;
String to_json_string() const;
diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp
index 05fb62ff12..0c0c8f657a 100644
--- a/core/variant/variant_call.cpp
+++ b/core/variant/variant_call.cpp
@@ -1695,6 +1695,7 @@ static void _register_variant_builtin_methods() {
bind_string_method(json_escape, sarray(), varray());
bind_string_method(validate_node_name, sarray(), varray());
+ bind_string_method(validate_filename, sarray(), varray());
bind_string_method(is_valid_identifier, sarray(), varray());
bind_string_method(is_valid_int, sarray(), varray());
@@ -1923,7 +1924,7 @@ static void _register_variant_builtin_methods() {
/* Plane */
bind_method(Plane, normalized, sarray(), varray());
- bind_method(Plane, center, sarray(), varray());
+ bind_method(Plane, get_center, sarray(), varray());
bind_method(Plane, is_equal_approx, sarray("to_plane"), varray());
bind_method(Plane, is_finite, sarray(), varray());
bind_method(Plane, is_point_over, sarray("point"), varray());
@@ -2135,7 +2136,7 @@ static void _register_variant_builtin_methods() {
bind_static_method(Projection, create_depth_correction, sarray("flip_y"), varray());
bind_static_method(Projection, create_light_atlas_rect, sarray("rect"), varray());
bind_static_method(Projection, create_perspective, sarray("fovy", "aspect", "z_near", "z_far", "flip_fov"), varray(false));
- bind_static_method(Projection, create_perspective_hmd, sarray("fovy", "aspect", "z_near", "z_far", "flip_fov", "eye", "intraocular_dist", " convergence_dist"), varray());
+ bind_static_method(Projection, create_perspective_hmd, sarray("fovy", "aspect", "z_near", "z_far", "flip_fov", "eye", "intraocular_dist", "convergence_dist"), varray());
bind_static_method(Projection, create_for_hmd, sarray("eye", "aspect", "intraocular_dist", "display_width", "display_to_lens", "oversample", "z_near", "z_far"), varray());
bind_static_method(Projection, create_orthogonal, sarray("left", "right", "bottom", "top", "z_near", "z_far"), varray());
bind_static_method(Projection, create_orthogonal_aspect, sarray("size", "aspect", "z_near", "z_far", "flip_fov"), varray(false));
@@ -2179,6 +2180,8 @@ static void _register_variant_builtin_methods() {
bind_method(Dictionary, values, sarray(), varray());
bind_method(Dictionary, duplicate, sarray("deep"), varray(false));
bind_method(Dictionary, get, sarray("key", "default"), varray(Variant()));
+ bind_method(Dictionary, make_read_only, sarray(), varray());
+ bind_method(Dictionary, is_read_only, sarray(), varray());
/* Array */
@@ -2186,6 +2189,7 @@ static void _register_variant_builtin_methods() {
bind_method(Array, is_empty, sarray(), varray());
bind_method(Array, clear, sarray(), varray());
bind_method(Array, hash, sarray(), varray());
+ bind_method(Array, assign, sarray("array"), varray());
bind_method(Array, push_back, sarray("value"), varray());
bind_method(Array, push_front, sarray("value"), varray());
bind_method(Array, append, sarray("value"), varray());
@@ -2220,13 +2224,12 @@ static void _register_variant_builtin_methods() {
bind_method(Array, all, sarray("method"), varray());
bind_method(Array, max, sarray(), varray());
bind_method(Array, min, sarray(), varray());
- bind_method(Array, typed_assign, sarray("array"), varray());
- bind_method(Array, set_typed, sarray("type", "class_name", "script"), varray());
bind_method(Array, is_typed, sarray(), varray());
+ bind_method(Array, is_same_typed, sarray("array"), varray());
bind_method(Array, get_typed_builtin, sarray(), varray());
bind_method(Array, get_typed_class_name, sarray(), varray());
bind_method(Array, get_typed_script, sarray(), varray());
- bind_method(Array, set_read_only, sarray("enable"), varray());
+ bind_method(Array, make_read_only, sarray(), varray());
bind_method(Array, is_read_only, sarray(), varray());
/* Byte Array */
@@ -2400,7 +2403,7 @@ static void _register_variant_builtin_methods() {
bind_method(PackedStringArray, remove_at, sarray("index"), varray());
bind_method(PackedStringArray, insert, sarray("at_index", "value"), varray());
bind_method(PackedStringArray, fill, sarray("value"), varray());
- bind_method(PackedStringArray, resize, sarray("new_size"), varray());
+ bind_methodv(PackedStringArray, resize, &PackedStringArray::resize_zeroed, sarray("new_size"), varray());
bind_method(PackedStringArray, clear, sarray(), varray());
bind_method(PackedStringArray, has, sarray("value"), varray());
bind_method(PackedStringArray, reverse, sarray(), varray());
@@ -2424,7 +2427,7 @@ static void _register_variant_builtin_methods() {
bind_method(PackedVector2Array, remove_at, sarray("index"), varray());
bind_method(PackedVector2Array, insert, sarray("at_index", "value"), varray());
bind_method(PackedVector2Array, fill, sarray("value"), varray());
- bind_method(PackedVector2Array, resize, sarray("new_size"), varray());
+ bind_methodv(PackedVector2Array, resize, &PackedVector2Array::resize_zeroed, sarray("new_size"), varray());
bind_method(PackedVector2Array, clear, sarray(), varray());
bind_method(PackedVector2Array, has, sarray("value"), varray());
bind_method(PackedVector2Array, reverse, sarray(), varray());
@@ -2448,7 +2451,7 @@ static void _register_variant_builtin_methods() {
bind_method(PackedVector3Array, remove_at, sarray("index"), varray());
bind_method(PackedVector3Array, insert, sarray("at_index", "value"), varray());
bind_method(PackedVector3Array, fill, sarray("value"), varray());
- bind_method(PackedVector3Array, resize, sarray("new_size"), varray());
+ bind_methodv(PackedVector3Array, resize, &PackedVector3Array::resize_zeroed, sarray("new_size"), varray());
bind_method(PackedVector3Array, clear, sarray(), varray());
bind_method(PackedVector3Array, has, sarray("value"), varray());
bind_method(PackedVector3Array, reverse, sarray(), varray());
@@ -2472,7 +2475,7 @@ static void _register_variant_builtin_methods() {
bind_method(PackedColorArray, remove_at, sarray("index"), varray());
bind_method(PackedColorArray, insert, sarray("at_index", "value"), varray());
bind_method(PackedColorArray, fill, sarray("value"), varray());
- bind_method(PackedColorArray, resize, sarray("new_size"), varray());
+ bind_methodv(PackedColorArray, resize, &PackedColorArray::resize_zeroed, sarray("new_size"), varray());
bind_method(PackedColorArray, clear, sarray(), varray());
bind_method(PackedColorArray, has, sarray("value"), varray());
bind_method(PackedColorArray, reverse, sarray(), varray());
diff --git a/core/variant/variant_internal.h b/core/variant/variant_internal.h
index 21e1d21342..0d55ee4ae2 100644
--- a/core/variant/variant_internal.h
+++ b/core/variant/variant_internal.h
@@ -58,7 +58,13 @@ public:
init_basis(v);
break;
case Variant::TRANSFORM3D:
- init_transform(v);
+ init_transform3d(v);
+ break;
+ case Variant::PROJECTION:
+ init_projection(v);
+ break;
+ case Variant::COLOR:
+ init_color(v);
break;
case Variant::STRING_NAME:
init_string_name(v);
@@ -209,13 +215,12 @@ public:
// Should be in the same order as Variant::Type for consistency.
// Those primitive and vector types don't need an `init_` method:
- // Nil, bool, float, Vector2/i, Rect2/i, Vector3/i, Plane, Quat, Color, RID.
+ // Nil, bool, float, Vector2/i, Rect2/i, Vector3/i, Plane, Quat, RID.
// Object is a special case, handled via `object_assign_null`.
_FORCE_INLINE_ static void init_string(Variant *v) {
memnew_placement(v->_data._mem, String);
v->type = Variant::STRING;
}
-
_FORCE_INLINE_ static void init_transform2d(Variant *v) {
v->_data._transform2d = (Transform2D *)Variant::Pools::_bucket_small.alloc();
memnew_placement(v->_data._transform2d, Transform2D);
@@ -231,7 +236,7 @@ public:
memnew_placement(v->_data._basis, Basis);
v->type = Variant::BASIS;
}
- _FORCE_INLINE_ static void init_transform(Variant *v) {
+ _FORCE_INLINE_ static void init_transform3d(Variant *v) {
v->_data._transform3d = (Transform3D *)Variant::Pools::_bucket_medium.alloc();
memnew_placement(v->_data._transform3d, Transform3D);
v->type = Variant::TRANSFORM3D;
@@ -241,6 +246,10 @@ public:
memnew_placement(v->_data._projection, Projection);
v->type = Variant::PROJECTION;
}
+ _FORCE_INLINE_ static void init_color(Variant *v) {
+ memnew_placement(v->_data._mem, Color);
+ v->type = Variant::COLOR;
+ }
_FORCE_INLINE_ static void init_string_name(Variant *v) {
memnew_placement(v->_data._mem, StringName);
v->type = Variant::STRING_NAME;
@@ -1191,7 +1200,7 @@ struct VariantInitializer<Basis> {
template <>
struct VariantInitializer<Transform3D> {
- static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_transform(v); }
+ static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_transform3d(v); }
};
template <>
struct VariantInitializer<Projection> {
diff --git a/core/variant/variant_parser.cpp b/core/variant/variant_parser.cpp
index 87874deb8d..a40fcfbd47 100644
--- a/core/variant/variant_parser.cpp
+++ b/core/variant/variant_parser.cpp
@@ -910,7 +910,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
bool at_key = true;
String key;
- Token token2;
bool need_comma = false;
while (true) {
@@ -920,18 +919,18 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
}
if (at_key) {
- Error err = get_token(p_stream, token2, line, r_err_str);
+ Error err = get_token(p_stream, token, line, r_err_str);
if (err != OK) {
return err;
}
- if (token2.type == TK_PARENTHESIS_CLOSE) {
+ if (token.type == TK_PARENTHESIS_CLOSE) {
value = ref.is_valid() ? Variant(ref) : Variant(obj);
return OK;
}
if (need_comma) {
- if (token2.type != TK_COMMA) {
+ if (token.type != TK_COMMA) {
r_err_str = "Expected '}' or ','";
return ERR_PARSE_ERROR;
} else {
@@ -940,31 +939,31 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
}
}
- if (token2.type != TK_STRING) {
+ if (token.type != TK_STRING) {
r_err_str = "Expected property name as string";
return ERR_PARSE_ERROR;
}
- key = token2.value;
+ key = token.value;
- err = get_token(p_stream, token2, line, r_err_str);
+ err = get_token(p_stream, token, line, r_err_str);
if (err != OK) {
return err;
}
- if (token2.type != TK_COLON) {
+ if (token.type != TK_COLON) {
r_err_str = "Expected ':'";
return ERR_PARSE_ERROR;
}
at_key = false;
} else {
- Error err = get_token(p_stream, token2, line, r_err_str);
+ Error err = get_token(p_stream, token, line, r_err_str);
if (err != OK) {
return err;
}
Variant v;
- err = parse_value(token2, v, p_stream, line, r_err_str, p_res_parser);
+ err = parse_value(token, v, p_stream, line, r_err_str, p_res_parser);
if (err) {
return err;
}
@@ -1026,6 +1025,89 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
return ERR_PARSE_ERROR;
}
}
+ } else if (id == "Array") {
+ Error err = OK;
+
+ get_token(p_stream, token, line, r_err_str);
+ if (token.type != TK_BRACKET_OPEN) {
+ r_err_str = "Expected '['";
+ return ERR_PARSE_ERROR;
+ }
+
+ get_token(p_stream, token, line, r_err_str);
+ if (token.type != TK_IDENTIFIER) {
+ r_err_str = "Expected type identifier";
+ return ERR_PARSE_ERROR;
+ }
+
+ static HashMap<StringName, Variant::Type> builtin_types;
+ if (builtin_types.is_empty()) {
+ for (int i = 1; i < Variant::VARIANT_MAX; i++) {
+ builtin_types[Variant::get_type_name((Variant::Type)i)] = (Variant::Type)i;
+ }
+ }
+
+ Array array = Array();
+ bool got_bracket_token = false;
+ if (builtin_types.has(token.value)) {
+ array.set_typed(builtin_types.get(token.value), StringName(), Variant());
+ } else if (token.value == "Resource" || token.value == "SubResource" || token.value == "ExtResource") {
+ Variant resource;
+ err = parse_value(token, resource, p_stream, line, r_err_str, p_res_parser);
+ if (err) {
+ if (token.value == "Resource" && err == ERR_PARSE_ERROR && r_err_str == "Expected '('" && token.type == TK_BRACKET_CLOSE) {
+ err = OK;
+ r_err_str = String();
+ array.set_typed(Variant::OBJECT, token.value, Variant());
+ got_bracket_token = true;
+ } else {
+ return err;
+ }
+ } else {
+ Ref<Script> script = resource;
+ if (script.is_valid() && script->is_valid()) {
+ array.set_typed(Variant::OBJECT, script->get_instance_base_type(), script);
+ }
+ }
+ } else if (ClassDB::class_exists(token.value)) {
+ array.set_typed(Variant::OBJECT, token.value, Variant());
+ }
+
+ if (!got_bracket_token) {
+ get_token(p_stream, token, line, r_err_str);
+ if (token.type != TK_BRACKET_CLOSE) {
+ r_err_str = "Expected ']'";
+ return ERR_PARSE_ERROR;
+ }
+ }
+
+ get_token(p_stream, token, line, r_err_str);
+ if (token.type != TK_PARENTHESIS_OPEN) {
+ r_err_str = "Expected '('";
+ return ERR_PARSE_ERROR;
+ }
+
+ get_token(p_stream, token, line, r_err_str);
+ if (token.type != TK_BRACKET_OPEN) {
+ r_err_str = "Expected '['";
+ return ERR_PARSE_ERROR;
+ }
+
+ Array values;
+ err = _parse_array(values, p_stream, line, r_err_str, p_res_parser);
+ if (err) {
+ return err;
+ }
+
+ get_token(p_stream, token, line, r_err_str);
+ if (token.type != TK_PARENTHESIS_CLOSE) {
+ r_err_str = "Expected ')'";
+ return ERR_PARSE_ERROR;
+ }
+
+ array.assign(values);
+
+ value = array;
} else if (id == "PackedByteArray" || id == "PoolByteArray" || id == "ByteArray") {
Vector<uint8_t> args;
Error err = _parse_construct<uint8_t>(p_stream, args, line, r_err_str);
@@ -1843,6 +1925,38 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
} break;
case Variant::ARRAY: {
+ Array array = p_variant;
+ if (array.get_typed_builtin() != Variant::NIL) {
+ p_store_string_func(p_store_string_ud, "Array[");
+
+ Variant::Type builtin_type = (Variant::Type)array.get_typed_builtin();
+ StringName class_name = array.get_typed_class_name();
+ Ref<Script> script = array.get_typed_script();
+
+ if (script.is_valid()) {
+ String resource_text = String();
+ if (p_encode_res_func) {
+ resource_text = p_encode_res_func(p_encode_res_ud, script);
+ }
+ if (resource_text.is_empty() && script->get_path().is_resource_file()) {
+ resource_text = "Resource(\"" + script->get_path() + "\")";
+ }
+
+ if (!resource_text.is_empty()) {
+ p_store_string_func(p_store_string_ud, resource_text);
+ } else {
+ ERR_PRINT("Failed to encode a path to a custom script for an array type.");
+ p_store_string_func(p_store_string_ud, class_name);
+ }
+ } else if (class_name != StringName()) {
+ p_store_string_func(p_store_string_ud, class_name);
+ } else {
+ p_store_string_func(p_store_string_ud, Variant::get_type_name(builtin_type));
+ }
+
+ p_store_string_func(p_store_string_ud, "](");
+ }
+
if (recursion_count > MAX_RECURSION) {
ERR_PRINT("Max recursion reached");
p_store_string_func(p_store_string_ud, "[]");
@@ -1850,7 +1964,6 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
recursion_count++;
p_store_string_func(p_store_string_ud, "[");
- Array array = p_variant;
int len = array.size();
for (int i = 0; i < len; i++) {
if (i > 0) {
@@ -1862,11 +1975,14 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
p_store_string_func(p_store_string_ud, "]");
}
+ if (array.get_typed_builtin() != Variant::NIL) {
+ p_store_string_func(p_store_string_ud, ")");
+ }
+
} break;
case Variant::PACKED_BYTE_ARRAY: {
p_store_string_func(p_store_string_ud, "PackedByteArray(");
- String s;
Vector<uint8_t> data = p_variant;
int len = data.size();
const uint8_t *ptr = data.ptr();
@@ -1954,15 +2070,11 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
int len = data.size();
const String *ptr = data.ptr();
- String s;
- //write_string("\n");
-
for (int i = 0; i < len; i++) {
if (i > 0) {
p_store_string_func(p_store_string_ud, ", ");
}
- String str = ptr[i];
- p_store_string_func(p_store_string_ud, "\"" + str.c_escape() + "\"");
+ p_store_string_func(p_store_string_ud, "\"" + ptr[i].c_escape() + "\"");
}
p_store_string_func(p_store_string_ud, ")");
@@ -2010,9 +2122,9 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
if (i > 0) {
p_store_string_func(p_store_string_ud, ", ");
}
-
p_store_string_func(p_store_string_ud, rtos_fix(ptr[i].r) + ", " + rtos_fix(ptr[i].g) + ", " + rtos_fix(ptr[i].b) + ", " + rtos_fix(ptr[i].a));
}
+
p_store_string_func(p_store_string_ud, ")");
} break;
diff --git a/core/variant/variant_setget.cpp b/core/variant/variant_setget.cpp
index b8d4495702..30fb5d0e9f 100644
--- a/core/variant/variant_setget.cpp
+++ b/core/variant/variant_setget.cpp
@@ -151,8 +151,8 @@ void unregister_named_setters_getters() {
bool Variant::has_member(Variant::Type p_type, const StringName &p_member) {
ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, false);
- for (uint32_t i = 0; i < variant_setters_getters_names[p_type].size(); i++) {
- if (variant_setters_getters_names[p_type][i] == p_member) {
+ for (const StringName &member : variant_setters_getters_names[p_type]) {
+ if (member == p_member) {
return true;
}
}
@@ -172,8 +172,8 @@ Variant::Type Variant::get_member_type(Variant::Type p_type, const StringName &p
}
void Variant::get_member_list(Variant::Type p_type, List<StringName> *r_members) {
- for (uint32_t i = 0; i < variant_setters_getters_names[p_type].size(); i++) {
- r_members->push_back(variant_setters_getters_names[p_type][i]);
+ for (const StringName &member : variant_setters_getters_names[p_type]) {
+ r_members->push_back(member);
}
}
@@ -389,6 +389,7 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const {
v.write[index] = PtrToArg<m_elem_type>::convert(member); \
} \
static Variant::Type get_index_type() { return GetTypeInfo<m_elem_type>::VARIANT_TYPE; } \
+ static uint32_t get_index_usage() { return GetTypeInfo<m_elem_type>::get_class_info().usage; } \
static uint64_t get_indexed_size(const Variant *base) { return VariantGetInternalPtr<m_base_type>::get_ptr(base)->size(); } \
};
@@ -460,6 +461,7 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const {
v.write[index] = PtrToArg<m_elem_type>::convert(member); \
} \
static Variant::Type get_index_type() { return GetTypeInfo<m_elem_type>::VARIANT_TYPE; } \
+ static uint32_t get_index_usage() { return GetTypeInfo<m_elem_type>::get_class_info().usage; } \
static uint64_t get_indexed_size(const Variant *base) { return VariantGetInternalPtr<m_base_type>::get_ptr(base)->size(); } \
};
@@ -515,6 +517,7 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const {
v[index] = PtrToArg<m_elem_type>::convert(member); \
} \
static Variant::Type get_index_type() { return GetTypeInfo<m_elem_type>::VARIANT_TYPE; } \
+ static uint32_t get_index_usage() { return GetTypeInfo<m_elem_type>::get_class_info().usage; } \
static uint64_t get_indexed_size(const Variant *base) { return m_max; } \
};
@@ -564,6 +567,7 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const {
v m_accessor[index] = PtrToArg<m_elem_type>::convert(member); \
} \
static Variant::Type get_index_type() { return GetTypeInfo<m_elem_type>::VARIANT_TYPE; } \
+ static uint32_t get_index_usage() { return GetTypeInfo<m_elem_type>::get_class_info().usage; } \
static uint64_t get_indexed_size(const Variant *base) { return m_max; } \
};
@@ -613,6 +617,7 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const {
v.m_set(index, PtrToArg<m_elem_type>::convert(member)); \
} \
static Variant::Type get_index_type() { return GetTypeInfo<m_elem_type>::VARIANT_TYPE; } \
+ static uint32_t get_index_usage() { return GetTypeInfo<m_elem_type>::get_class_info().usage; } \
static uint64_t get_indexed_size(const Variant *base) { return m_max; } \
};
@@ -683,6 +688,7 @@ struct VariantIndexedSetGet_Array {
v.set(index, PtrToArg<Variant>::convert(member));
}
static Variant::Type get_index_type() { return Variant::NIL; }
+ static uint32_t get_index_usage() { return PROPERTY_USAGE_NIL_IS_VARIANT; }
static uint64_t get_indexed_size(const Variant *base) { return 0; }
};
@@ -768,6 +774,7 @@ struct VariantIndexedSetGet_String {
}
}
static Variant::Type get_index_type() { return Variant::STRING; }
+ static uint32_t get_index_usage() { return PROPERTY_USAGE_DEFAULT; }
static uint64_t get_indexed_size(const Variant *base) { return VariantInternal::get_string(base)->length(); }
};
@@ -812,6 +819,7 @@ struct VariantIndexedSetGet_String {
v[index] = PtrToArg<Variant>::convert(member); \
} \
static Variant::Type get_index_type() { return Variant::NIL; } \
+ static uint32_t get_index_usage() { return PROPERTY_USAGE_DEFAULT; } \
static uint64_t get_indexed_size(const Variant *base) { return VariantGetInternalPtr<m_base_type>::get_ptr(base)->size(); } \
};
@@ -852,7 +860,8 @@ struct VariantIndexedSetterGetterInfo {
uint64_t (*get_indexed_size)(const Variant *base) = nullptr;
- Variant::Type index_type;
+ Variant::Type index_type = Variant::NIL;
+ uint32_t index_usage = PROPERTY_USAGE_DEFAULT;
bool valid = false;
};
@@ -872,6 +881,7 @@ static void register_indexed_member(Variant::Type p_type) {
sgi.ptr_getter = T::ptr_get;
sgi.index_type = T::get_index_type();
+ sgi.index_usage = T::get_index_usage();
sgi.get_indexed_size = T::get_indexed_size;
sgi.valid = true;
@@ -920,6 +930,11 @@ Variant::Type Variant::get_indexed_element_type(Variant::Type p_type) {
return variant_indexed_setters_getters[p_type].index_type;
}
+uint32_t Variant::get_indexed_element_usage(Variant::Type p_type) {
+ ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, PROPERTY_USAGE_DEFAULT);
+ return variant_indexed_setters_getters[p_type].index_usage;
+}
+
Variant::ValidatedIndexedSetter Variant::get_member_validated_indexed_setter(Variant::Type p_type) {
ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, nullptr);
return variant_indexed_setters_getters[p_type].validated_setter;
@@ -1253,7 +1268,7 @@ bool Variant::iter_init(Variant &r_iter, bool &valid) const {
return _data._int > 0;
} break;
case FLOAT: {
- r_iter = 0;
+ r_iter = 0.0;
return _data._float > 0.0;
} break;
case VECTOR2: {
@@ -1457,7 +1472,7 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const {
return true;
} break;
case FLOAT: {
- int64_t idx = r_iter;
+ double idx = r_iter;
idx++;
if (idx >= _data._float) {
return false;
diff --git a/core/variant/variant_utility.cpp b/core/variant/variant_utility.cpp
index fe7150bca9..042ebe368a 100644
--- a/core/variant/variant_utility.cpp
+++ b/core/variant/variant_utility.cpp
@@ -1007,9 +1007,14 @@ struct VariantUtilityFunctions {
static inline uint64_t rid_allocate_id() {
return RID_AllocBase::_gen_id();
}
+
static inline RID rid_from_int64(uint64_t p_base) {
return RID::from_uint64(p_base);
}
+
+ static inline bool is_same(const Variant &p_a, const Variant &p_b) {
+ return p_a.identity_compare(p_b);
+ }
};
#ifdef DEBUG_METHODS_ENABLED
@@ -1601,6 +1606,8 @@ void Variant::_register_variant_utility_functions() {
FUNCBINDR(rid_allocate_id, Vector<String>(), Variant::UTILITY_FUNC_TYPE_GENERAL);
FUNCBINDR(rid_from_int64, sarray("base"), Variant::UTILITY_FUNC_TYPE_GENERAL);
+
+ FUNCBINDR(is_same, sarray("a", "b"), Variant::UTILITY_FUNC_TYPE_GENERAL);
}
void Variant::_unregister_variant_utility_functions() {