diff options
Diffstat (limited to 'modules/mono')
33 files changed, 540 insertions, 456 deletions
diff --git a/modules/mono/build_scripts/make_android_mono_config.py b/modules/mono/build_scripts/make_android_mono_config.py index 8cad204d7b..0afd939c57 100644 --- a/modules/mono/build_scripts/make_android_mono_config.py +++ b/modules/mono/build_scripts/make_android_mono_config.py @@ -24,7 +24,7 @@ def generate_compressed_config(config_src, output_dir): #ifdef ANDROID_ENABLED #include "core/io/compression.h" -#include "core/pool_vector.h" + namespace { @@ -36,9 +36,9 @@ static const unsigned char config_compressed_data[] = { %s }; } // namespace String get_godot_android_mono_config() { - PoolVector<uint8_t> data; + Vector<uint8_t> data; data.resize(config_uncompressed_size); - PoolVector<uint8_t>::Write w = data.write(); + uint8_t* w = data.ptrw(); Compression::decompress(w.ptr(), config_uncompressed_size, config_compressed_data, config_compressed_size, Compression::MODE_DEFLATE); String s; diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp index 9e19e5f8c4..15415d7655 100644 --- a/modules/mono/csharp_script.cpp +++ b/modules/mono/csharp_script.cpp @@ -31,6 +31,7 @@ #include "csharp_script.h" #include <mono/metadata/threads.h> +#include <stdint.h> #include "core/io/json.h" #include "core/os/file_access.h" @@ -161,13 +162,13 @@ void CSharpLanguage::finish() { #ifdef DEBUG_ENABLED for (Map<ObjectID, int>::Element *E = unsafe_object_references.front(); E; E = E->next()) { - const ObjectID &id = E->get(); + const ObjectID &id = E->key(); Object *obj = ObjectDB::get_instance(id); if (obj) { - ERR_PRINTS("Leaked unsafe reference to object: " + obj->get_class() + ":" + itos(id)); + ERR_PRINT("Leaked unsafe reference to object: " + obj->to_string()); } else { - ERR_PRINTS("Leaked unsafe reference to deleted object: " + itos(id)); + ERR_PRINT("Leaked unsafe reference to deleted object: " + itos(id)); } } #endif @@ -427,24 +428,24 @@ static String variant_type_to_managed_name(const String &p_var_type_name) { if (p_var_type_name == Variant::get_type_name(Variant::ARRAY)) return "Collections.Array"; - if (p_var_type_name == Variant::get_type_name(Variant::POOL_BYTE_ARRAY)) + if (p_var_type_name == Variant::get_type_name(Variant::PACKED_BYTE_ARRAY)) return "byte[]"; - if (p_var_type_name == Variant::get_type_name(Variant::POOL_INT_ARRAY)) + if (p_var_type_name == Variant::get_type_name(Variant::PACKED_INT_ARRAY)) return "int[]"; - if (p_var_type_name == Variant::get_type_name(Variant::POOL_REAL_ARRAY)) { + if (p_var_type_name == Variant::get_type_name(Variant::PACKED_REAL_ARRAY)) { #ifdef REAL_T_IS_DOUBLE return "double[]"; #else return "float[]"; #endif } - if (p_var_type_name == Variant::get_type_name(Variant::POOL_STRING_ARRAY)) + if (p_var_type_name == Variant::get_type_name(Variant::PACKED_STRING_ARRAY)) return "string[]"; - if (p_var_type_name == Variant::get_type_name(Variant::POOL_VECTOR2_ARRAY)) + if (p_var_type_name == Variant::get_type_name(Variant::PACKED_VECTOR2_ARRAY)) return "Vector2[]"; - if (p_var_type_name == Variant::get_type_name(Variant::POOL_VECTOR3_ARRAY)) + if (p_var_type_name == Variant::get_type_name(Variant::PACKED_VECTOR3_ARRAY)) return "Vector3[]"; - if (p_var_type_name == Variant::get_type_name(Variant::POOL_COLOR_ARRAY)) + if (p_var_type_name == Variant::get_type_name(Variant::PACKED_COLOR_ARRAY)) return "Color[]"; Variant::Type var_types[] = { @@ -472,7 +473,7 @@ static String variant_type_to_managed_name(const String &p_var_type_name) { return "object"; } -String CSharpLanguage::make_function(const String &, const String &p_name, const PoolStringArray &p_args) const { +String CSharpLanguage::make_function(const String &, const String &p_name, const PackedStringArray &p_args) const { // FIXME // - Due to Godot's API limitation this just appends the function to the end of the file // - Use fully qualified name if there is ambiguity @@ -490,7 +491,7 @@ String CSharpLanguage::make_function(const String &, const String &p_name, const return s; } #else -String CSharpLanguage::make_function(const String &, const String &, const PoolStringArray &) const { +String CSharpLanguage::make_function(const String &, const String &, const PackedStringArray &) const { return String(); } #endif @@ -853,7 +854,7 @@ void CSharpLanguage::reload_assemblies(bool p_soft_reload) { while (script->instances.front()) { Object *obj = script->instances.front()->get(); - obj->set_script(RefPtr()); // Remove script and existing script instances (placeholder are not removed before domain reload) + obj->set_script(REF()); // Remove script and existing script instances (placeholder are not removed before domain reload) } script->_clear(); @@ -876,7 +877,7 @@ void CSharpLanguage::reload_assemblies(bool p_soft_reload) { // Use a placeholder for now to avoid losing the state when saving a scene - obj->set_script(scr.get_ref_ptr()); + obj->set_script(scr); PlaceHolderScriptInstance *placeholder = scr->placeholder_instance_create(obj); obj->set_script_instance(placeholder); @@ -1002,7 +1003,7 @@ void CSharpLanguage::reload_assemblies(bool p_soft_reload) { CRASH_COND(si != NULL); #endif // Re-create script instance - obj->set_script(script.get_ref_ptr()); // will create the script instance as well + obj->set_script(script); // will create the script instance as well } } @@ -1080,7 +1081,7 @@ void CSharpLanguage::_load_scripts_metadata() { int err_line; Error json_err = JSON::parse(old_json, old_dict_var, err_str, err_line); if (json_err != OK) { - ERR_PRINTS("Failed to parse metadata file: '" + err_str + "' (" + String::num_int64(err_line) + ")."); + ERR_PRINT("Failed to parse metadata file: '" + err_str + "' (" + String::num_int64(err_line) + ")."); return; } @@ -1721,8 +1722,7 @@ bool CSharpInstance::has_method(const StringName &p_method) const { Variant CSharpInstance::call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error) { - if (!script.is_valid()) - ERR_FAIL_V(Variant()); + ERR_FAIL_COND_V(!script.is_valid(), Variant()); GD_MONO_SCOPE_THREAD_ATTACH; @@ -1980,67 +1980,44 @@ bool CSharpInstance::refcount_decremented() { return ref_dying; } -MultiplayerAPI::RPCMode CSharpInstance::_member_get_rpc_mode(IMonoClassMember *p_member) const { - - if (p_member->has_attribute(CACHED_CLASS(RemoteAttribute))) - return MultiplayerAPI::RPC_MODE_REMOTE; - if (p_member->has_attribute(CACHED_CLASS(MasterAttribute))) - return MultiplayerAPI::RPC_MODE_MASTER; - if (p_member->has_attribute(CACHED_CLASS(PuppetAttribute))) - return MultiplayerAPI::RPC_MODE_PUPPET; - if (p_member->has_attribute(CACHED_CLASS(SlaveAttribute))) - return MultiplayerAPI::RPC_MODE_PUPPET; - if (p_member->has_attribute(CACHED_CLASS(RemoteSyncAttribute))) - return MultiplayerAPI::RPC_MODE_REMOTESYNC; - if (p_member->has_attribute(CACHED_CLASS(SyncAttribute))) - return MultiplayerAPI::RPC_MODE_REMOTESYNC; - if (p_member->has_attribute(CACHED_CLASS(MasterSyncAttribute))) - return MultiplayerAPI::RPC_MODE_MASTERSYNC; - if (p_member->has_attribute(CACHED_CLASS(PuppetSyncAttribute))) - return MultiplayerAPI::RPC_MODE_PUPPETSYNC; +Vector<ScriptNetData> CSharpInstance::get_rpc_methods() const { + return script->get_rpc_methods(); +} - return MultiplayerAPI::RPC_MODE_DISABLED; +uint16_t CSharpInstance::get_rpc_method_id(const StringName &p_method) const { + return script->get_rpc_method_id(p_method); } -MultiplayerAPI::RPCMode CSharpInstance::get_rpc_mode(const StringName &p_method) const { +StringName CSharpInstance::get_rpc_method(const uint16_t p_rpc_method_id) const { + return script->get_rpc_method(p_rpc_method_id); +} - GD_MONO_SCOPE_THREAD_ATTACH; +MultiplayerAPI::RPCMode CSharpInstance::get_rpc_mode_by_id(const uint16_t p_rpc_method_id) const { + return script->get_rpc_mode_by_id(p_rpc_method_id); +} - GDMonoClass *top = script->script_class; +MultiplayerAPI::RPCMode CSharpInstance::get_rpc_mode(const StringName &p_method) const { + return script->get_rpc_mode(p_method); +} - while (top && top != script->native) { - GDMonoMethod *method = top->get_fetched_method_unknown_params(p_method); +Vector<ScriptNetData> CSharpInstance::get_rset_properties() const { + return script->get_rset_properties(); +} - if (method && !method->is_static()) - return _member_get_rpc_mode(method); +uint16_t CSharpInstance::get_rset_property_id(const StringName &p_variable) const { + return script->get_rset_property_id(p_variable); +} - top = top->get_parent_class(); - } +StringName CSharpInstance::get_rset_property(const uint16_t p_rset_member_id) const { + return script->get_rset_property(p_rset_member_id); +} - return MultiplayerAPI::RPC_MODE_DISABLED; +MultiplayerAPI::RPCMode CSharpInstance::get_rset_mode_by_id(const uint16_t p_rset_member_id) const { + return script->get_rset_mode_by_id(p_rset_member_id); } MultiplayerAPI::RPCMode CSharpInstance::get_rset_mode(const StringName &p_variable) const { - - GD_MONO_SCOPE_THREAD_ATTACH; - - GDMonoClass *top = script->script_class; - - while (top && top != script->native) { - GDMonoField *field = top->get_field(p_variable); - - if (field && !field->is_static()) - return _member_get_rpc_mode(field); - - GDMonoProperty *property = top->get_property(p_variable); - - if (property && !property->is_static()) - return _member_get_rpc_mode(property); - - top = top->get_parent_class(); - } - - return MultiplayerAPI::RPC_MODE_DISABLED; + return script->get_rset_mode(p_variable); } void CSharpInstance::notification(int p_notification) { @@ -2444,7 +2421,7 @@ bool CSharpScript::_update_exports() { if (tmp_native && !base_ref) { Node *node = Object::cast_to<Node>(tmp_native); if (node && node->is_inside_tree()) { - ERR_PRINTS("Temporary instance was added to the scene tree."); + ERR_PRINT("Temporary instance was added to the scene tree."); } else { memdelete(tmp_native); } @@ -2522,7 +2499,7 @@ bool CSharpScript::_get_signal(GDMonoClass *p_class, GDMonoClass *p_delegate, Ve arg.type = GDMonoMarshal::managed_to_variant_type(types[i]); if (arg.type == Variant::NIL) { - ERR_PRINTS("Unknown type of signal parameter: '" + arg.name + "' in '" + p_class->get_full_name() + "'."); + ERR_PRINT("Unknown type of signal parameter: '" + arg.name + "' in '" + p_class->get_full_name() + "'."); return false; } @@ -2552,7 +2529,7 @@ bool CSharpScript::_get_member_export(IMonoClassMember *p_member, bool p_inspect if (p_member->is_static()) { if (p_member->has_attribute(CACHED_CLASS(ExportAttribute))) - ERR_PRINTS("Cannot export member because it is static: '" + MEMBER_FULL_QUALIFIED_NAME(p_member) + "'."); + ERR_PRINT("Cannot export member because it is static: '" + MEMBER_FULL_QUALIFIED_NAME(p_member) + "'."); return false; } @@ -2575,12 +2552,12 @@ bool CSharpScript::_get_member_export(IMonoClassMember *p_member, bool p_inspect GDMonoProperty *property = static_cast<GDMonoProperty *>(p_member); if (!property->has_getter()) { if (exported) - ERR_PRINTS("Read-only property cannot be exported: '" + MEMBER_FULL_QUALIFIED_NAME(p_member) + "'."); + ERR_PRINT("Read-only property cannot be exported: '" + MEMBER_FULL_QUALIFIED_NAME(p_member) + "'."); return false; } if (!property->has_setter()) { if (exported) - ERR_PRINTS("Write-only property (without getter) cannot be exported: '" + MEMBER_FULL_QUALIFIED_NAME(p_member) + "'."); + ERR_PRINT("Write-only property (without getter) cannot be exported: '" + MEMBER_FULL_QUALIFIED_NAME(p_member) + "'."); return false; } } @@ -2599,7 +2576,7 @@ bool CSharpScript::_get_member_export(IMonoClassMember *p_member, bool p_inspect String hint_string; if (variant_type == Variant::NIL) { - ERR_PRINTS("Unknown exported member type: '" + MEMBER_FULL_QUALIFIED_NAME(p_member) + "'."); + ERR_PRINT("Unknown exported member type: '" + MEMBER_FULL_QUALIFIED_NAME(p_member) + "'."); return false; } @@ -2891,7 +2868,7 @@ bool CSharpScript::can_instance() const { "Compile", ProjectSettings::get_singleton()->globalize_path(get_path())); } else { - ERR_PRINTS("C# project could not be created; cannot add file: '" + get_path() + "'."); + ERR_PRINT("C# project could not be created; cannot add file: '" + get_path() + "'."); } } } @@ -3252,6 +3229,69 @@ Error CSharpScript::reload(bool p_keep_state) { _update_exports(); } + rpc_functions.clear(); + rpc_variables.clear(); + + GDMonoClass *top = script_class; + while (top && top != native) { + { + Vector<GDMonoMethod *> methods = top->get_all_methods(); + for (int i = 0; i < methods.size(); i++) { + if (!methods[i]->is_static()) { + MultiplayerAPI::RPCMode mode = _member_get_rpc_mode(methods[i]); + if (MultiplayerAPI::RPC_MODE_DISABLED != mode) { + ScriptNetData nd; + nd.name = methods[i]->get_name(); + nd.mode = mode; + if (-1 == rpc_functions.find(nd)) { + rpc_functions.push_back(nd); + } + } + } + } + } + + { + Vector<GDMonoField *> fields = top->get_all_fields(); + for (int i = 0; i < fields.size(); i++) { + if (!fields[i]->is_static()) { + MultiplayerAPI::RPCMode mode = _member_get_rpc_mode(fields[i]); + if (MultiplayerAPI::RPC_MODE_DISABLED != mode) { + ScriptNetData nd; + nd.name = fields[i]->get_name(); + nd.mode = mode; + if (-1 == rpc_variables.find(nd)) { + rpc_variables.push_back(nd); + } + } + } + } + } + + { + Vector<GDMonoProperty *> properties = top->get_all_properties(); + for (int i = 0; i < properties.size(); i++) { + if (!properties[i]->is_static()) { + MultiplayerAPI::RPCMode mode = _member_get_rpc_mode(properties[i]); + if (MultiplayerAPI::RPC_MODE_DISABLED != mode) { + ScriptNetData nd; + nd.name = properties[i]->get_name(); + nd.mode = mode; + if (-1 == rpc_variables.find(nd)) { + rpc_variables.push_back(nd); + } + } + } + } + } + + top = top->get_parent_class(); + } + + // Sort so we are 100% that they are always the same. + rpc_functions.sort_custom<SortNetData>(); + rpc_variables.sort_custom<SortNetData>(); + return OK; } @@ -3325,6 +3365,78 @@ int CSharpScript::get_member_line(const StringName &p_member) const { return -1; } +MultiplayerAPI::RPCMode CSharpScript::_member_get_rpc_mode(IMonoClassMember *p_member) const { + + if (p_member->has_attribute(CACHED_CLASS(RemoteAttribute))) + return MultiplayerAPI::RPC_MODE_REMOTE; + if (p_member->has_attribute(CACHED_CLASS(MasterAttribute))) + return MultiplayerAPI::RPC_MODE_MASTER; + if (p_member->has_attribute(CACHED_CLASS(PuppetAttribute))) + return MultiplayerAPI::RPC_MODE_PUPPET; + if (p_member->has_attribute(CACHED_CLASS(RemoteSyncAttribute))) + return MultiplayerAPI::RPC_MODE_REMOTESYNC; + if (p_member->has_attribute(CACHED_CLASS(MasterSyncAttribute))) + return MultiplayerAPI::RPC_MODE_MASTERSYNC; + if (p_member->has_attribute(CACHED_CLASS(PuppetSyncAttribute))) + return MultiplayerAPI::RPC_MODE_PUPPETSYNC; + + return MultiplayerAPI::RPC_MODE_DISABLED; +} + +Vector<ScriptNetData> CSharpScript::get_rpc_methods() const { + return rpc_functions; +} + +uint16_t CSharpScript::get_rpc_method_id(const StringName &p_method) const { + for (int i = 0; i < rpc_functions.size(); i++) { + if (rpc_functions[i].name == p_method) { + return i; + } + } + return UINT16_MAX; +} + +StringName CSharpScript::get_rpc_method(const uint16_t p_rpc_method_id) const { + ERR_FAIL_COND_V(p_rpc_method_id >= rpc_functions.size(), StringName()); + return rpc_functions[p_rpc_method_id].name; +} + +MultiplayerAPI::RPCMode CSharpScript::get_rpc_mode_by_id(const uint16_t p_rpc_method_id) const { + ERR_FAIL_COND_V(p_rpc_method_id >= rpc_functions.size(), MultiplayerAPI::RPC_MODE_DISABLED); + return rpc_functions[p_rpc_method_id].mode; +} + +MultiplayerAPI::RPCMode CSharpScript::get_rpc_mode(const StringName &p_method) const { + return get_rpc_mode_by_id(get_rpc_method_id(p_method)); +} + +Vector<ScriptNetData> CSharpScript::get_rset_properties() const { + return rpc_variables; +} + +uint16_t CSharpScript::get_rset_property_id(const StringName &p_variable) const { + for (int i = 0; i < rpc_variables.size(); i++) { + if (rpc_variables[i].name == p_variable) { + return i; + } + } + return UINT16_MAX; +} + +StringName CSharpScript::get_rset_property(const uint16_t p_rset_member_id) const { + ERR_FAIL_COND_V(p_rset_member_id >= rpc_variables.size(), StringName()); + return rpc_variables[p_rset_member_id].name; +} + +MultiplayerAPI::RPCMode CSharpScript::get_rset_mode_by_id(const uint16_t p_rset_member_id) const { + ERR_FAIL_COND_V(p_rset_member_id >= rpc_functions.size(), MultiplayerAPI::RPC_MODE_DISABLED); + return rpc_functions[p_rset_member_id].mode; +} + +MultiplayerAPI::RPCMode CSharpScript::get_rset_mode(const StringName &p_variable) const { + return get_rset_mode_by_id(get_rset_property_id(p_variable)); +} + Error CSharpScript::load_source_code(const String &p_path) { Error ferr = read_all_file_utf8(p_path, source); @@ -3437,7 +3549,7 @@ Error ResourceFormatSaverCSharpScript::save(const String &p_path, const RES &p_r "Compile", ProjectSettings::get_singleton()->globalize_path(p_path)); } else { - ERR_PRINTS("C# project could not be created; cannot add file: '" + p_path + "'."); + ERR_PRINT("C# project could not be created; cannot add file: '" + p_path + "'."); } } #endif diff --git a/modules/mono/csharp_script.h b/modules/mono/csharp_script.h index f244bc4119..8ee741b4d2 100644 --- a/modules/mono/csharp_script.h +++ b/modules/mono/csharp_script.h @@ -113,6 +113,9 @@ class CSharpScript : public Script { Map<StringName, Vector<Argument> > _signals; bool signals_invalidated; + Vector<ScriptNetData> rpc_functions; + Vector<ScriptNetData> rpc_variables; + #ifdef TOOLS_ENABLED List<PropertyInfo> exported_members_cache; // members_cache Map<StringName, Variant> exported_members_defval_cache; // member_default_values_cache @@ -146,6 +149,8 @@ class CSharpScript : public Script { static Ref<CSharpScript> create_for_managed_type(GDMonoClass *p_class, GDMonoClass *p_native); static void initialize_for_managed_type(Ref<CSharpScript> p_script, GDMonoClass *p_class, GDMonoClass *p_native); + MultiplayerAPI::RPCMode _member_get_rpc_mode(IMonoClassMember *p_member) const; + protected: static void _bind_methods(); @@ -187,6 +192,18 @@ public: virtual int get_member_line(const StringName &p_member) const; + virtual Vector<ScriptNetData> get_rpc_methods() const; + virtual uint16_t get_rpc_method_id(const StringName &p_method) const; + virtual StringName get_rpc_method(const uint16_t p_rpc_method_id) const; + virtual MultiplayerAPI::RPCMode get_rpc_mode_by_id(const uint16_t p_rpc_method_id) const; + virtual MultiplayerAPI::RPCMode get_rpc_mode(const StringName &p_method) const; + + virtual Vector<ScriptNetData> get_rset_properties() const; + virtual uint16_t get_rset_property_id(const StringName &p_variable) const; + virtual StringName get_rset_property(const uint16_t p_variable_id) const; + virtual MultiplayerAPI::RPCMode get_rset_mode_by_id(const uint16_t p_variable_id) const; + virtual MultiplayerAPI::RPCMode get_rset_mode(const StringName &p_variable) const; + #ifdef TOOLS_ENABLED virtual bool is_placeholder_fallback_enabled() const { return placeholder_fallback_enabled; } #endif @@ -232,8 +249,6 @@ class CSharpInstance : public ScriptInstance { void _call_multilevel(MonoObject *p_mono_object, const StringName &p_method, const Variant **p_args, int p_argcount); - MultiplayerAPI::RPCMode _member_get_rpc_mode(IMonoClassMember *p_member) const; - void get_properties_state_for_reloading(List<Pair<StringName, Variant> > &r_state); public: @@ -265,7 +280,16 @@ public: virtual void refcount_incremented(); virtual bool refcount_decremented(); + virtual Vector<ScriptNetData> get_rpc_methods() const; + virtual uint16_t get_rpc_method_id(const StringName &p_method) const; + virtual StringName get_rpc_method(const uint16_t p_rpc_method_id) const; + virtual MultiplayerAPI::RPCMode get_rpc_mode_by_id(const uint16_t p_rpc_method_id) const; virtual MultiplayerAPI::RPCMode get_rpc_mode(const StringName &p_method) const; + + virtual Vector<ScriptNetData> get_rset_properties() const; + virtual uint16_t get_rset_property_id(const StringName &p_variable) const; + virtual StringName get_rset_property(const uint16_t p_variable_id) const; + virtual MultiplayerAPI::RPCMode get_rset_mode_by_id(const uint16_t p_variable_id) const; virtual MultiplayerAPI::RPCMode get_rset_mode(const StringName &p_variable) const; virtual void notification(int p_notification); @@ -408,7 +432,7 @@ public: virtual bool has_named_classes() const; virtual bool supports_builtin_mode() const; /* TODO? */ virtual int find_function(const String &p_function, const String &p_code) const { return -1; } - virtual String make_function(const String &p_class, const String &p_name, const PoolStringArray &p_args) const; + virtual String make_function(const String &p_class, const String &p_name, const PackedStringArray &p_args) const; virtual String _get_indentation() const; /* TODO? */ virtual void auto_indent_code(String &p_code, int p_from_line, int p_to_line) const {} /* TODO */ virtual void add_global_constant(const StringName &p_variable, const Variant &p_value) {} diff --git a/modules/mono/doc_classes/@C#.xml b/modules/mono/doc_classes/@C#.xml index 826c106d7e..83a7fbf02c 100644 --- a/modules/mono/doc_classes/@C#.xml +++ b/modules/mono/doc_classes/@C#.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8" ?> -<class name="@C#" category="Core" version="3.2"> +<class name="@C#" version="4.0"> <brief_description> </brief_description> <description> diff --git a/modules/mono/doc_classes/CSharpScript.xml b/modules/mono/doc_classes/CSharpScript.xml index de2e246ea9..1eb3404f9e 100644 --- a/modules/mono/doc_classes/CSharpScript.xml +++ b/modules/mono/doc_classes/CSharpScript.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8" ?> -<class name="CSharpScript" inherits="Script" category="Core" version="3.2"> +<class name="CSharpScript" inherits="Script" version="4.0"> <brief_description> </brief_description> <description> @@ -8,7 +8,7 @@ </tutorials> <methods> <method name="new" qualifiers="vararg"> - <return type="Object"> + <return type="Variant"> </return> <description> </description> diff --git a/modules/mono/doc_classes/GodotSharp.xml b/modules/mono/doc_classes/GodotSharp.xml index 18556a84ba..19a08d2036 100644 --- a/modules/mono/doc_classes/GodotSharp.xml +++ b/modules/mono/doc_classes/GodotSharp.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8" ?> -<class name="GodotSharp" inherits="Object" category="Core" version="3.2"> +<class name="GodotSharp" inherits="Object" version="4.0"> <brief_description> </brief_description> <description> diff --git a/modules/mono/editor/GodotTools/GodotTools/BuildTab.cs b/modules/mono/editor/GodotTools/GodotTools/BuildTab.cs index 727581daab..f75fe239e3 100644 --- a/modules/mono/editor/GodotTools/GodotTools/BuildTab.cs +++ b/modules/mono/editor/GodotTools/GodotTools/BuildTab.cs @@ -41,7 +41,7 @@ namespace GodotTools public bool ErrorsVisible { get; set; } = true; public bool WarningsVisible { get; set; } = true; - public Texture IconTexture + public Texture2D IconTexture { get { diff --git a/modules/mono/editor/bindings_generator.cpp b/modules/mono/editor/bindings_generator.cpp index 9beadb1778..0724d72ce6 100644 --- a/modules/mono/editor/bindings_generator.cpp +++ b/modules/mono/editor/bindings_generator.cpp @@ -278,7 +278,7 @@ String BindingsGenerator::bbcode_to_xml(const String &p_bbcode, const TypeInterf Vector<String> link_target_parts = link_target.split("."); if (link_target_parts.size() <= 0 || link_target_parts.size() > 2) { - ERR_PRINTS("Invalid reference format: '" + tag + "'."); + ERR_PRINT("Invalid reference format: '" + tag + "'."); xml_output.append("<c>"); xml_output.append(tag); @@ -374,7 +374,7 @@ String BindingsGenerator::bbcode_to_xml(const String &p_bbcode, const TypeInterf xml_output.append(target_enum_itype.proxy_name); // Includes nesting class if any xml_output.append("\"/>"); } else { - ERR_PRINTS("Cannot resolve enum reference in documentation: '" + link_target + "'."); + ERR_PRINT("Cannot resolve enum reference in documentation: '" + link_target + "'."); xml_output.append("<c>"); xml_output.append(link_target); @@ -423,7 +423,7 @@ String BindingsGenerator::bbcode_to_xml(const String &p_bbcode, const TypeInterf xml_output.append(target_iconst->proxy_name); xml_output.append("\"/>"); } else { - ERR_PRINTS("Cannot resolve global constant reference in documentation: '" + link_target + "'."); + ERR_PRINT("Cannot resolve global constant reference in documentation: '" + link_target + "'."); xml_output.append("<c>"); xml_output.append(link_target); @@ -463,7 +463,7 @@ String BindingsGenerator::bbcode_to_xml(const String &p_bbcode, const TypeInterf xml_output.append(target_iconst->proxy_name); xml_output.append("\"/>"); } else { - ERR_PRINTS("Cannot resolve constant reference in documentation: '" + link_target + "'."); + ERR_PRINT("Cannot resolve constant reference in documentation: '" + link_target + "'."); xml_output.append("<c>"); xml_output.append(link_target); @@ -503,23 +503,23 @@ String BindingsGenerator::bbcode_to_xml(const String &p_bbcode, const TypeInterf xml_output.append("<c>"); xml_output.append(tag); xml_output.append("</c>"); - } else if (tag == "PoolByteArray") { + } else if (tag == "PackedByteArray") { xml_output.append("<see cref=\"byte\"/>"); - } else if (tag == "PoolIntArray") { + } else if (tag == "PackedIntArray") { xml_output.append("<see cref=\"int\"/>"); - } else if (tag == "PoolRealArray") { + } else if (tag == "PackedRealArray") { #ifdef REAL_T_IS_DOUBLE xml_output.append("<see cref=\"double\"/>"); #else xml_output.append("<see cref=\"float\"/>"); #endif - } else if (tag == "PoolStringArray") { + } else if (tag == "PackedStringArray") { xml_output.append("<see cref=\"string\"/>"); - } else if (tag == "PoolVector2Array") { + } else if (tag == "PackedVector2Array") { xml_output.append("<see cref=\"" BINDINGS_NAMESPACE ".Vector2\"/>"); - } else if (tag == "PoolVector3Array") { + } else if (tag == "PackedVector3Array") { xml_output.append("<see cref=\"" BINDINGS_NAMESPACE ".Vector3\"/>"); - } else if (tag == "PoolColorArray") { + } else if (tag == "PackedColorArray") { xml_output.append("<see cref=\"" BINDINGS_NAMESPACE ".Color\"/>"); } else { const TypeInterface *target_itype = _get_type_or_null(TypeReference(tag)); @@ -533,7 +533,7 @@ String BindingsGenerator::bbcode_to_xml(const String &p_bbcode, const TypeInterf xml_output.append(target_itype->proxy_name); xml_output.append("\"/>"); } else { - ERR_PRINTS("Cannot resolve type reference in documentation: '" + tag + "'."); + ERR_PRINT("Cannot resolve type reference in documentation: '" + tag + "'."); xml_output.append("<c>"); xml_output.append(tag); @@ -1207,7 +1207,7 @@ Error BindingsGenerator::_generate_cs_type(const TypeInterface &itype, const Str output.append(obj_types[itype.base_name].proxy_name); output.append("\n"); } else { - ERR_PRINTS("Base type '" + itype.base_name.operator String() + "' does not exist, for class '" + itype.name + "'."); + ERR_PRINT("Base type '" + itype.base_name.operator String() + "' does not exist, for class '" + itype.name + "'."); return ERR_INVALID_DATA; } } @@ -1646,7 +1646,7 @@ Error BindingsGenerator::_generate_cs_method(const BindingsGenerator::TypeInterf if (p_imethod.is_deprecated) { if (p_imethod.deprecation_message.empty()) - WARN_PRINTS("An empty deprecation message is discouraged. Method: '" + p_imethod.proxy_name + "'."); + WARN_PRINT("An empty deprecation message is discouraged. Method: '" + p_imethod.proxy_name + "'."); p_output.append(MEMBER_BEGIN "[Obsolete(\""); p_output.append(p_imethod.deprecation_message); @@ -2134,7 +2134,7 @@ const BindingsGenerator::TypeInterface *BindingsGenerator::_get_type_or_placehol if (found) return found; - ERR_PRINTS(String() + "Type not found. Creating placeholder: '" + p_typeref.cname.operator String() + "'."); + ERR_PRINT(String() + "Type not found. Creating placeholder: '" + p_typeref.cname.operator String() + "'."); const Map<StringName, TypeInterface>::Element *match = placeholder_types.find(p_typeref.cname); @@ -2358,9 +2358,9 @@ bool BindingsGenerator::_populate_object_type_interfaces() { // which could actually will return something different. // Let's put this to notify us if that ever happens. if (itype.cname != name_cache.type_Object || imethod.name != "free") { - WARN_PRINTS("Notification: New unexpected virtual non-overridable method found." - " We only expected Object.free, but found '" + - itype.name + "." + imethod.name + "'."); + WARN_PRINT("Notification: New unexpected virtual non-overridable method found." + " We only expected Object.free, but found '" + + itype.name + "." + imethod.name + "'."); } } else if (return_info.type == Variant::INT && return_info.usage & PROPERTY_USAGE_CLASS_IS_ENUM) { imethod.return_type.cname = return_info.class_name; @@ -2369,7 +2369,7 @@ bool BindingsGenerator::_populate_object_type_interfaces() { imethod.return_type.cname = return_info.class_name; if (!imethod.is_virtual && ClassDB::is_parent_class(return_info.class_name, name_cache.type_Reference) && return_info.hint != PROPERTY_HINT_RESOURCE_TYPE) { /* clang-format off */ - ERR_PRINTS("Return type is reference but hint is not '" _STR(PROPERTY_HINT_RESOURCE_TYPE) "'." + ERR_PRINT("Return type is reference but hint is not '" _STR(PROPERTY_HINT_RESOURCE_TYPE) "'." " Are you returning a reference type by pointer? Method: '" + itype.name + "." + imethod.name + "'."); /* clang-format on */ ERR_FAIL_V(false); @@ -2628,13 +2628,13 @@ bool BindingsGenerator::_arg_default_value_from_variant(const Variant &p_val, Ar r_iarg.default_argument = "null"; break; case Variant::ARRAY: - case Variant::POOL_BYTE_ARRAY: - case Variant::POOL_INT_ARRAY: - case Variant::POOL_REAL_ARRAY: - case Variant::POOL_STRING_ARRAY: - case Variant::POOL_VECTOR2_ARRAY: - case Variant::POOL_VECTOR3_ARRAY: - case Variant::POOL_COLOR_ARRAY: + case Variant::PACKED_BYTE_ARRAY: + case Variant::PACKED_INT_ARRAY: + case Variant::PACKED_REAL_ARRAY: + case Variant::PACKED_STRING_ARRAY: + case Variant::PACKED_VECTOR2_ARRAY: + case Variant::PACKED_VECTOR3_ARRAY: + case Variant::PACKED_COLOR_ARRAY: r_iarg.default_argument = "new %s {}"; r_iarg.def_param_mode = ArgumentInterface::NULLABLE_REF; break; @@ -2914,20 +2914,20 @@ void BindingsGenerator::_populate_builtin_type_interfaces() { #define INSERT_ARRAY(m_type, m_proxy_t) INSERT_ARRAY_FULL(m_type, m_type, m_proxy_t) - INSERT_ARRAY(PoolIntArray, int); - INSERT_ARRAY_FULL(PoolByteArray, PoolByteArray, byte); + INSERT_ARRAY(PackedIntArray, int); + INSERT_ARRAY_FULL(PackedByteArray, PackedByteArray, byte); #ifdef REAL_T_IS_DOUBLE - INSERT_ARRAY(PoolRealArray, double); + INSERT_ARRAY(PackedRealArray, double); #else - INSERT_ARRAY(PoolRealArray, float); + INSERT_ARRAY(PackedRealArray, float); #endif - INSERT_ARRAY(PoolStringArray, string); + INSERT_ARRAY(PackedStringArray, string); - INSERT_ARRAY(PoolColorArray, Color); - INSERT_ARRAY(PoolVector2Array, Vector2); - INSERT_ARRAY(PoolVector3Array, Vector3); + INSERT_ARRAY(PackedColorArray, Color); + INSERT_ARRAY(PackedVector2Array, Vector2); + INSERT_ARRAY(PackedVector3Array, Vector3); #undef INSERT_ARRAY @@ -3038,7 +3038,7 @@ void BindingsGenerator::_populate_global_constants() { // HARDCODED: The Error enum have the prefix 'ERR_' for everything except 'OK' and 'FAILED'. if (ienum.cname == name_cache.enum_Error) { if (prefix_length > 0) { // Just in case it ever changes - ERR_PRINTS("Prefix for enum '" _STR(Error) "' is not empty."); + ERR_PRINT("Prefix for enum '" _STR(Error) "' is not empty."); } prefix_length = 1; // 'ERR_' @@ -3133,7 +3133,7 @@ void BindingsGenerator::handle_cmdline_args(const List<String> &p_cmdline_args) glue_dir_path = path_elem->get(); elem = elem->next(); } else { - ERR_PRINTS(generate_all_glue_option + ": No output directory specified (expected path to '{GODOT_ROOT}/modules/mono/glue')."); + ERR_PRINT(generate_all_glue_option + ": No output directory specified (expected path to '{GODOT_ROOT}/modules/mono/glue')."); } --options_left; @@ -3144,7 +3144,7 @@ void BindingsGenerator::handle_cmdline_args(const List<String> &p_cmdline_args) cs_dir_path = path_elem->get(); elem = elem->next(); } else { - ERR_PRINTS(generate_cs_glue_option + ": No output directory specified."); + ERR_PRINT(generate_cs_glue_option + ": No output directory specified."); } --options_left; @@ -3155,7 +3155,7 @@ void BindingsGenerator::handle_cmdline_args(const List<String> &p_cmdline_args) cpp_dir_path = path_elem->get(); elem = elem->next(); } else { - ERR_PRINTS(generate_cpp_glue_option + ": No output directory specified."); + ERR_PRINT(generate_cpp_glue_option + ": No output directory specified."); } --options_left; @@ -3169,26 +3169,26 @@ void BindingsGenerator::handle_cmdline_args(const List<String> &p_cmdline_args) bindings_generator.set_log_print_enabled(true); if (!bindings_generator.initialized) { - ERR_PRINTS("Failed to initialize the bindings generator"); + ERR_PRINT("Failed to initialize the bindings generator"); ::exit(0); } if (glue_dir_path.length()) { if (bindings_generator.generate_glue(glue_dir_path) != OK) - ERR_PRINTS(generate_all_glue_option + ": Failed to generate the C++ glue."); + ERR_PRINT(generate_all_glue_option + ": Failed to generate the C++ glue."); if (bindings_generator.generate_cs_api(glue_dir_path.plus_file(API_SOLUTION_NAME)) != OK) - ERR_PRINTS(generate_all_glue_option + ": Failed to generate the C# API."); + ERR_PRINT(generate_all_glue_option + ": Failed to generate the C# API."); } if (cs_dir_path.length()) { if (bindings_generator.generate_cs_api(cs_dir_path) != OK) - ERR_PRINTS(generate_cs_glue_option + ": Failed to generate the C# API."); + ERR_PRINT(generate_cs_glue_option + ": Failed to generate the C# API."); } if (cpp_dir_path.length()) { if (bindings_generator.generate_glue(cpp_dir_path) != OK) - ERR_PRINTS(generate_cpp_glue_option + ": Failed to generate the C++ glue."); + ERR_PRINT(generate_cpp_glue_option + ": Failed to generate the C++ glue."); } // Exit once done diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/RPCAttributes.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/RPCAttributes.cs index 1bf6d5199a..8fc430b6bc 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/RPCAttributes.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/RPCAttributes.cs @@ -6,18 +6,12 @@ namespace Godot public class RemoteAttribute : Attribute {} [AttributeUsage(AttributeTargets.Method | AttributeTargets.Field | AttributeTargets.Property)] - public class SyncAttribute : Attribute {} - - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Field | AttributeTargets.Property)] public class MasterAttribute : Attribute {} [AttributeUsage(AttributeTargets.Method | AttributeTargets.Field | AttributeTargets.Property)] public class PuppetAttribute : Attribute {} [AttributeUsage(AttributeTargets.Method | AttributeTargets.Field | AttributeTargets.Property)] - public class SlaveAttribute : Attribute {} - - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Field | AttributeTargets.Property)] public class RemoteSyncAttribute : Attribute {} [AttributeUsage(AttributeTargets.Method | AttributeTargets.Field | AttributeTargets.Property)] diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs index d38589013e..baf470a0cc 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs @@ -93,11 +93,15 @@ namespace Godot } } - public Vector3 this[int columnIndex] + /// <summary> + /// Access whole columns in the form of Vector3. + /// </summary> + /// <param name="column">Which column vector.</param> + public Vector3 this[int column] { get { - switch (columnIndex) + switch (column) { case 0: return Column0; @@ -111,7 +115,7 @@ namespace Godot } set { - switch (columnIndex) + switch (column) { case 0: Column0 = value; @@ -128,50 +132,22 @@ namespace Godot } } - public real_t this[int columnIndex, int rowIndex] + /// <summary> + /// Access matrix elements in column-major order. + /// </summary> + /// <param name="column">Which column, the matrix horizontal position.</param> + /// <param name="row">Which row, the matrix vertical position.</param> + public real_t this[int column, int row] { get { - switch (columnIndex) - { - case 0: - return Column0[rowIndex]; - case 1: - return Column1[rowIndex]; - case 2: - return Column2[rowIndex]; - default: - throw new IndexOutOfRangeException(); - } + return this[column][row]; } set { - switch (columnIndex) - { - case 0: - { - var column0 = Column0; - column0[rowIndex] = value; - Column0 = column0; - return; - } - case 1: - { - var column1 = Column1; - column1[rowIndex] = value; - Column1 = column1; - return; - } - case 2: - { - var column2 = Column2; - column2[rowIndex] = value; - Column2 = column2; - return; - } - default: - throw new IndexOutOfRangeException(); - } + Vector3 columnVector = this[column]; + columnVector[row] = value; + this[column] = columnVector; } } @@ -290,12 +266,6 @@ namespace Godot this[index] = value; } - [Obsolete("GetAxis is deprecated. Use GetColumn instead.")] - public Vector3 GetAxis(int axis) - { - return new Vector3(this.Row0[axis], this.Row1[axis], this.Row2[axis]); - } - public int GetOrthogonalIndex() { var orth = this; diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs index 0462ef1125..1d1a49945f 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs @@ -318,9 +318,9 @@ namespace Godot return res; } - public int ToAbgr32() + public uint ToAbgr32() { - int c = (byte)Math.Round(a * 255); + uint c = (byte)Math.Round(a * 255); c <<= 8; c |= (byte)Math.Round(b * 255); c <<= 8; @@ -331,9 +331,9 @@ namespace Godot return c; } - public long ToAbgr64() + public ulong ToAbgr64() { - long c = (ushort)Math.Round(a * 65535); + ulong c = (ushort)Math.Round(a * 65535); c <<= 16; c |= (ushort)Math.Round(b * 65535); c <<= 16; @@ -344,9 +344,9 @@ namespace Godot return c; } - public int ToArgb32() + public uint ToArgb32() { - int c = (byte)Math.Round(a * 255); + uint c = (byte)Math.Round(a * 255); c <<= 8; c |= (byte)Math.Round(r * 255); c <<= 8; @@ -357,9 +357,9 @@ namespace Godot return c; } - public long ToArgb64() + public ulong ToArgb64() { - long c = (ushort)Math.Round(a * 65535); + ulong c = (ushort)Math.Round(a * 65535); c <<= 16; c |= (ushort)Math.Round(r * 65535); c <<= 16; @@ -370,9 +370,9 @@ namespace Godot return c; } - public int ToRgba32() + public uint ToRgba32() { - int c = (byte)Math.Round(r * 255); + uint c = (byte)Math.Round(r * 255); c <<= 8; c |= (byte)Math.Round(g * 255); c <<= 8; @@ -383,9 +383,9 @@ namespace Godot return c; } - public long ToRgba64() + public ulong ToRgba64() { - long c = (ushort)Math.Round(r * 65535); + ulong c = (ushort)Math.Round(r * 65535); c <<= 16; c |= (ushort)Math.Round(g * 65535); c <<= 16; @@ -419,7 +419,7 @@ namespace Godot this.a = a; } - public Color(int rgba) + public Color(uint rgba) { a = (rgba & 0xFF) / 255.0f; rgba >>= 8; @@ -430,7 +430,7 @@ namespace Godot r = (rgba & 0xFF) / 255.0f; } - public Color(long rgba) + public Color(ulong rgba) { a = (rgba & 0xFFFF) / 65535.0f; rgba >>= 16; diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Mathf.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Mathf.cs index ddfed180b5..4f7aa99df8 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Mathf.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Mathf.cs @@ -130,7 +130,7 @@ namespace Godot public static real_t InverseLerp(real_t from, real_t to, real_t weight) { - return (weight - from) / (to - from); + return (weight - from) / (to - from); } public static bool IsEqualApprox(real_t a, real_t b) @@ -151,12 +151,12 @@ namespace Godot public static bool IsInf(real_t s) { - return real_t.IsInfinity(s); + return real_t.IsInfinity(s); } public static bool IsNaN(real_t s) { - return real_t.IsNaN(s); + return real_t.IsNaN(s); } public static bool IsZeroApprox(real_t s) diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Quat.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Quat.cs index 6702634c51..bbc617ea6e 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Quat.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Quat.cs @@ -104,33 +104,6 @@ namespace Godot return this / Length; } - [Obsolete("Set is deprecated. Use the Quat(" + nameof(real_t) + ", " + nameof(real_t) + ", " + nameof(real_t) + ", " + nameof(real_t) + ") constructor instead.", error: true)] - public void Set(real_t x, real_t y, real_t z, real_t w) - { - this.x = x; - this.y = y; - this.z = z; - this.w = w; - } - - [Obsolete("Set is deprecated. Use the Quat(" + nameof(Quat) + ") constructor instead.", error: true)] - public void Set(Quat q) - { - this = q; - } - - [Obsolete("SetAxisAngle is deprecated. Use the Quat(" + nameof(Vector3) + ", " + nameof(real_t) + ") constructor instead.", error: true)] - public void SetAxisAngle(Vector3 axis, real_t angle) - { - this = new Quat(axis, angle); - } - - [Obsolete("SetEuler is deprecated. Use the Quat(" + nameof(Vector3) + ") constructor instead.", error: true)] - public void SetEuler(Vector3 eulerYXZ) - { - this = new Quat(eulerYXZ); - } - public Quat Slerp(Quat b, real_t t) { #if DEBUG diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs index b926037e5a..099eacd7dd 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs @@ -264,7 +264,8 @@ namespace Godot instanceIndex++; toIndex++; } - } else + } + else { while (true) { @@ -474,7 +475,7 @@ namespace Godot int source = 0; int target = 0; - while (instance[source] != 0 && text[target] != 0) + while (source < len && target < text.Length) { bool match; @@ -491,7 +492,7 @@ namespace Godot if (match) { source++; - if (instance[source] == 0) + if (source >= len) return true; } @@ -980,7 +981,7 @@ namespace Godot } // <summary> - // Convert the String (which is a character array) to PoolByteArray (which is an array of bytes). The conversion is speeded up in comparison to to_utf8() with the assumption that all the characters the String contains are only ASCII characters. + // Convert the String (which is a character array) to PackedByteArray (which is an array of bytes). The conversion is speeded up in comparison to to_utf8() with the assumption that all the characters the String contains are only ASCII characters. // </summary> public static byte[] ToAscii(this string instance) { @@ -1020,7 +1021,7 @@ namespace Godot } // <summary> - // Convert the String (which is an array of characters) to PoolByteArray (which is an array of bytes). The conversion is a bit slower than to_ascii(), but supports all UTF-8 characters. Therefore, you should prefer this function over to_ascii(). + // Convert the String (which is an array of characters) to PackedByteArray (which is an array of bytes). The conversion is a bit slower than to_ascii(), but supports all UTF-8 characters. Therefore, you should prefer this function over to_ascii(). // </summary> public static byte[] ToUTF8(this string instance) { diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform.cs index 0b84050f07..aa8815d1aa 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform.cs @@ -15,6 +15,76 @@ namespace Godot public Basis basis; public Vector3 origin; + /// <summary> + /// Access whole columns in the form of Vector3. The fourth column is the origin vector. + /// </summary> + /// <param name="column">Which column vector.</param> + public Vector3 this[int column] + { + get + { + switch (column) + { + case 0: + return basis.Column0; + case 1: + return basis.Column1; + case 2: + return basis.Column2; + case 3: + return origin; + default: + throw new IndexOutOfRangeException(); + } + } + set + { + switch (column) + { + case 0: + basis.Column0 = value; + return; + case 1: + basis.Column1 = value; + return; + case 2: + basis.Column2 = value; + return; + case 3: + origin = value; + return; + default: + throw new IndexOutOfRangeException(); + } + } + } + + /// <summary> + /// Access matrix elements in column-major order. The fourth column is the origin vector. + /// </summary> + /// <param name="column">Which column, the matrix horizontal position.</param> + /// <param name="row">Which row, the matrix vertical position.</param> + public real_t this[int column, int row] + { + get + { + if (column == 3) + { + return origin[row]; + } + return basis[column, row]; + } + set + { + if (column == 3) + { + origin[row] = value; + return; + } + basis[column, row] = value; + } + } + public Transform AffineInverse() { Basis basisInv = basis.Inverse(); diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs index 77ea3e5830..e72a44809a 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs @@ -54,11 +54,15 @@ namespace Godot } } - public Vector2 this[int rowIndex] + /// <summary> + /// Access whole columns in the form of Vector2. The third column is the origin vector. + /// </summary> + /// <param name="column">Which column vector.</param> + public Vector2 this[int column] { get { - switch (rowIndex) + switch (column) { case 0: return x; @@ -72,7 +76,7 @@ namespace Godot } set { - switch (rowIndex) + switch (column) { case 0: x = value; @@ -89,38 +93,22 @@ namespace Godot } } - public real_t this[int rowIndex, int columnIndex] + /// <summary> + /// Access matrix elements in column-major order. The third column is the origin vector. + /// </summary> + /// <param name="column">Which column, the matrix horizontal position.</param> + /// <param name="row">Which row, the matrix vertical position.</param> + public real_t this[int column, int row] { get { - switch (rowIndex) - { - case 0: - return x[columnIndex]; - case 1: - return y[columnIndex]; - case 2: - return origin[columnIndex]; - default: - throw new IndexOutOfRangeException(); - } + return this[column][row]; } set { - switch (rowIndex) - { - case 0: - x[columnIndex] = value; - return; - case 1: - y[columnIndex] = value; - return; - case 2: - origin[columnIndex] = value; - return; - default: - throw new IndexOutOfRangeException(); - } + Vector2 columnVector = this[column]; + columnVector[row] = value; + this[column] = columnVector; } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs index f92453f546..385bfed122 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs @@ -248,19 +248,6 @@ namespace Godot return new Vector2(Mathf.Round(x), Mathf.Round(y)); } - [Obsolete("Set is deprecated. Use the Vector2(" + nameof(real_t) + ", " + nameof(real_t) + ") constructor instead.", error: true)] - public void Set(real_t x, real_t y) - { - this.x = x; - this.y = y; - } - [Obsolete("Set is deprecated. Use the Vector2(" + nameof(Vector2) + ") constructor instead.", error: true)] - public void Set(Vector2 v) - { - x = v.x; - y = v.y; - } - public Vector2 Sign() { Vector2 v; diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs index fded34002d..390036c654 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs @@ -270,21 +270,6 @@ namespace Godot return new Basis(axis, phi).Xform(this); } - [Obsolete("Set is deprecated. Use the Vector3(" + nameof(real_t) + ", " + nameof(real_t) + ", " + nameof(real_t) + ") constructor instead.", error: true)] - public void Set(real_t x, real_t y, real_t z) - { - this.x = x; - this.y = y; - this.z = z; - } - [Obsolete("Set is deprecated. Use the Vector3(" + nameof(Vector3) + ") constructor instead.", error: true)] - public void Set(Vector3 v) - { - x = v.x; - y = v.y; - z = v.z; - } - public Vector3 Sign() { Vector3 v; diff --git a/modules/mono/glue/base_object_glue.cpp b/modules/mono/glue/base_object_glue.cpp index 02246b2f2f..8dfb5b7147 100644 --- a/modules/mono/glue/base_object_glue.cpp +++ b/modules/mono/glue/base_object_glue.cpp @@ -224,14 +224,9 @@ MonoString *godot_icall_Object_ToString(Object *p_ptr) { #ifdef DEBUG_ENABLED // Cannot happen in C#; would get an ObjectDisposedException instead. CRASH_COND(p_ptr == NULL); - - if (ScriptDebugger::get_singleton() && !Object::cast_to<Reference>(p_ptr)) { // Only if debugging! - // Cannot happen either in C#; the handle is nullified when the object is destroyed - CRASH_COND(!ObjectDB::instance_validate(p_ptr)); - } #endif - String result = "[" + p_ptr->get_class() + ":" + itos(p_ptr->get_instance_id()) + "]"; + String result = p_ptr->to_string(); return GDMonoMarshal::mono_string_from_godot(result); } diff --git a/modules/mono/glue/gd_glue.cpp b/modules/mono/glue/gd_glue.cpp index 9bea625450..a6273a60ac 100644 --- a/modules/mono/glue/gd_glue.cpp +++ b/modules/mono/glue/gd_glue.cpp @@ -44,9 +44,8 @@ MonoObject *godot_icall_GD_bytes2var(MonoArray *p_bytes, MonoBoolean p_allow_objects) { Variant ret; - PoolByteArray varr = GDMonoMarshal::mono_array_to_PoolByteArray(p_bytes); - PoolByteArray::Read r = varr.read(); - Error err = decode_variant(ret, r.ptr(), varr.size(), NULL, p_allow_objects); + PackedByteArray varr = GDMonoMarshal::mono_array_to_PackedByteArray(p_bytes); + Error err = decode_variant(ret, varr.ptr(), varr.size(), NULL, p_allow_objects); if (err != OK) { ret = RTR("Not enough bytes for decoding bytes, or invalid format."); } @@ -67,7 +66,7 @@ int godot_icall_GD_hash(MonoObject *p_var) { } MonoObject *godot_icall_GD_instance_from_id(uint64_t p_instance_id) { - return GDMonoUtils::unmanaged_get_managed(ObjectDB::get_instance(p_instance_id)); + return GDMonoUtils::unmanaged_get_managed(ObjectDB::get_instance(ObjectID(p_instance_id))); } void godot_icall_GD_print(MonoArray *p_what) { @@ -235,7 +234,7 @@ MonoObject *godot_icall_GD_str2var(MonoString *p_str) { Error err = VariantParser::parse(&ss, ret, errs, line); if (err != OK) { String err_str = "Parse error at line " + itos(line) + ": " + errs + "."; - ERR_PRINTS(err_str); + ERR_PRINT(err_str); ret = err_str; } @@ -247,28 +246,25 @@ MonoBoolean godot_icall_GD_type_exists(MonoString *p_type) { } void godot_icall_GD_pusherror(MonoString *p_str) { - ERR_PRINTS(GDMonoMarshal::mono_string_to_godot(p_str)); + ERR_PRINT(GDMonoMarshal::mono_string_to_godot(p_str)); } void godot_icall_GD_pushwarning(MonoString *p_str) { - WARN_PRINTS(GDMonoMarshal::mono_string_to_godot(p_str)); + WARN_PRINT(GDMonoMarshal::mono_string_to_godot(p_str)); } MonoArray *godot_icall_GD_var2bytes(MonoObject *p_var, MonoBoolean p_full_objects) { Variant var = GDMonoMarshal::mono_object_to_variant(p_var); - PoolByteArray barr; + PackedByteArray barr; int len; Error err = encode_variant(var, NULL, len, p_full_objects); ERR_FAIL_COND_V_MSG(err != OK, NULL, "Unexpected error encoding variable to bytes, likely unserializable type found (Object or RID)."); barr.resize(len); - { - PoolByteArray::Write w = barr.write(); - encode_variant(var, w.ptr(), len, p_full_objects); - } + encode_variant(var, barr.ptrw(), len, p_full_objects); - return GDMonoMarshal::PoolByteArray_to_mono_array(barr); + return GDMonoMarshal::PackedByteArray_to_mono_array(barr); } MonoString *godot_icall_GD_var2str(MonoObject *p_var) { diff --git a/modules/mono/mono_gd/gd_mono.cpp b/modules/mono/mono_gd/gd_mono.cpp index 60008f8fab..895393537f 100644 --- a/modules/mono/mono_gd/gd_mono.cpp +++ b/modules/mono/mono_gd/gd_mono.cpp @@ -621,7 +621,7 @@ bool GDMono::copy_prebuilt_api_assembly(ApiAssemblyInfo::Type p_api_type, const memdelete(da); if (err != OK) { - ERR_PRINTS("Failed to create destination directory for the API assemblies. Error: " + itos(err) + "."); + ERR_PRINT("Failed to create destination directory for the API assemblies. Error: " + itos(err) + "."); return false; } } @@ -630,15 +630,15 @@ bool GDMono::copy_prebuilt_api_assembly(ApiAssemblyInfo::Type p_api_type, const String xml_file = assembly_name + ".xml"; if (da->copy(src_dir.plus_file(xml_file), dst_dir.plus_file(xml_file)) != OK) - WARN_PRINTS("Failed to copy '" + xml_file + "'."); + WARN_PRINT("Failed to copy '" + xml_file + "'."); String pdb_file = assembly_name + ".pdb"; if (da->copy(src_dir.plus_file(pdb_file), dst_dir.plus_file(pdb_file)) != OK) - WARN_PRINTS("Failed to copy '" + pdb_file + "'."); + WARN_PRINT("Failed to copy '" + pdb_file + "'."); String assembly_file = assembly_name + ".dll"; if (da->copy(src_dir.plus_file(assembly_file), dst_dir.plus_file(assembly_file)) != OK) { - ERR_PRINTS("Failed to copy '" + assembly_file + "'."); + ERR_PRINT("Failed to copy '" + assembly_file + "'."); return false; } @@ -1115,7 +1115,7 @@ Error GDMono::finalize_and_unload_domain(MonoDomain *p_domain) { mono_domain_try_unload(p_domain, (MonoObject **)&exc); if (exc) { - ERR_PRINTS("Exception thrown when unloading domain '" + domain_name + "'."); + ERR_PRINT("Exception thrown when unloading domain '" + domain_name + "'."); GDMonoUtils::debug_print_unhandled_exception(exc); return FAILED; } diff --git a/modules/mono/mono_gd/gd_mono_android.cpp b/modules/mono/mono_gd/gd_mono_android.cpp index 27f394fae0..761368878f 100644 --- a/modules/mono/mono_gd/gd_mono_android.cpp +++ b/modules/mono/mono_gd/gd_mono_android.cpp @@ -315,7 +315,7 @@ MonoArray *_gd_mono_android_cert_store_lookup(MonoString *p_alias) { char *alias_utf8 = mono_string_to_utf8_checked(p_alias, &mono_error); if (!mono_error_ok(&mono_error)) { - ERR_PRINTS(String() + "Failed to convert MonoString* to UTF-8: '" + mono_error_get_message(&mono_error) + "'."); + ERR_PRINT(String() + "Failed to convert MonoString* to UTF-8: '" + mono_error_get_message(&mono_error) + "'."); mono_error_cleanup(&mono_error); return NULL; } diff --git a/modules/mono/mono_gd/gd_mono_cache.cpp b/modules/mono/mono_gd/gd_mono_cache.cpp index f1f6524cd2..0ad90a510e 100644 --- a/modules/mono/mono_gd/gd_mono_cache.cpp +++ b/modules/mono/mono_gd/gd_mono_cache.cpp @@ -136,10 +136,8 @@ void CachedData::clear_godot_api_cache() { class_SignalAttribute = NULL; class_ToolAttribute = NULL; class_RemoteAttribute = NULL; - class_SyncAttribute = NULL; class_MasterAttribute = NULL; class_PuppetAttribute = NULL; - class_SlaveAttribute = NULL; class_RemoteSyncAttribute = NULL; class_MasterSyncAttribute = NULL; class_PuppetSyncAttribute = NULL; @@ -254,10 +252,8 @@ void update_godot_api_cache() { CACHE_CLASS_AND_CHECK(SignalAttribute, GODOT_API_CLASS(SignalAttribute)); CACHE_CLASS_AND_CHECK(ToolAttribute, GODOT_API_CLASS(ToolAttribute)); CACHE_CLASS_AND_CHECK(RemoteAttribute, GODOT_API_CLASS(RemoteAttribute)); - CACHE_CLASS_AND_CHECK(SyncAttribute, GODOT_API_CLASS(SyncAttribute)); CACHE_CLASS_AND_CHECK(MasterAttribute, GODOT_API_CLASS(MasterAttribute)); CACHE_CLASS_AND_CHECK(PuppetAttribute, GODOT_API_CLASS(PuppetAttribute)); - CACHE_CLASS_AND_CHECK(SlaveAttribute, GODOT_API_CLASS(SlaveAttribute)); CACHE_CLASS_AND_CHECK(RemoteSyncAttribute, GODOT_API_CLASS(RemoteSyncAttribute)); CACHE_CLASS_AND_CHECK(MasterSyncAttribute, GODOT_API_CLASS(MasterSyncAttribute)); CACHE_CLASS_AND_CHECK(PuppetSyncAttribute, GODOT_API_CLASS(PuppetSyncAttribute)); diff --git a/modules/mono/mono_gd/gd_mono_cache.h b/modules/mono/mono_gd/gd_mono_cache.h index 1dc6b70479..0458e91240 100644 --- a/modules/mono/mono_gd/gd_mono_cache.h +++ b/modules/mono/mono_gd/gd_mono_cache.h @@ -106,13 +106,11 @@ struct CachedData { GDMonoClass *class_SignalAttribute; GDMonoClass *class_ToolAttribute; GDMonoClass *class_RemoteAttribute; - GDMonoClass *class_SyncAttribute; + GDMonoClass *class_MasterAttribute; + GDMonoClass *class_PuppetAttribute; GDMonoClass *class_RemoteSyncAttribute; GDMonoClass *class_MasterSyncAttribute; GDMonoClass *class_PuppetSyncAttribute; - GDMonoClass *class_MasterAttribute; - GDMonoClass *class_PuppetAttribute; - GDMonoClass *class_SlaveAttribute; GDMonoClass *class_GodotMethodAttribute; GDMonoField *field_GodotMethodAttribute_methodName; diff --git a/modules/mono/mono_gd/gd_mono_class.cpp b/modules/mono/mono_gd/gd_mono_class.cpp index 2132fd36f7..648f5f6c6b 100644 --- a/modules/mono/mono_gd/gd_mono_class.cpp +++ b/modules/mono/mono_gd/gd_mono_class.cpp @@ -166,8 +166,8 @@ void GDMonoClass::fetch_methods_with_godot_api_checks(GDMonoClass *p_native_base #ifdef DEBUG_ENABLED String fullname = method->get_ret_type_full_name() + " " + name + "(" + method->get_signature_desc(true) + ")"; - WARN_PRINTS("Method '" + fullname + "' is hidden by Godot API method. Should be '" + - method->get_full_name_no_class() + "'. In class '" + namespace_name + "." + class_name + "'."); + WARN_PRINT("Method '" + fullname + "' is hidden by Godot API method. Should be '" + + method->get_full_name_no_class() + "'. In class '" + namespace_name + "." + class_name + "'."); #endif continue; } @@ -185,8 +185,8 @@ void GDMonoClass::fetch_methods_with_godot_api_checks(GDMonoClass *p_native_base if (m && m->get_name() != name) { // found String fullname = m->get_ret_type_full_name() + " " + name + "(" + m->get_signature_desc(true) + ")"; - WARN_PRINTS("Method '" + fullname + "' should be '" + m->get_full_name_no_class() + - "'. In class '" + namespace_name + "." + class_name + "'."); + WARN_PRINT("Method '" + fullname + "' should be '" + m->get_full_name_no_class() + + "'. In class '" + namespace_name + "." + class_name + "'."); break; } diff --git a/modules/mono/mono_gd/gd_mono_field.cpp b/modules/mono/mono_gd/gd_mono_field.cpp index 3e0f9a3f15..21d78483ee 100644 --- a/modules/mono/mono_gd/gd_mono_field.cpp +++ b/modules/mono/mono_gd/gd_mono_field.cpp @@ -247,37 +247,37 @@ void GDMonoField::set_value_from_variant(MonoObject *p_object, const Variant &p_ } if (array_type->eklass == CACHED_CLASS_RAW(uint8_t)) { - SET_FROM_ARRAY(PoolByteArray); + SET_FROM_ARRAY(PackedByteArray); break; } if (array_type->eklass == CACHED_CLASS_RAW(int32_t)) { - SET_FROM_ARRAY(PoolIntArray); + SET_FROM_ARRAY(PackedIntArray); break; } if (array_type->eklass == REAL_T_MONOCLASS) { - SET_FROM_ARRAY(PoolRealArray); + SET_FROM_ARRAY(PackedRealArray); break; } if (array_type->eklass == CACHED_CLASS_RAW(String)) { - SET_FROM_ARRAY(PoolStringArray); + SET_FROM_ARRAY(PackedStringArray); break; } if (array_type->eklass == CACHED_CLASS_RAW(Vector2)) { - SET_FROM_ARRAY(PoolVector2Array); + SET_FROM_ARRAY(PackedVector2Array); break; } if (array_type->eklass == CACHED_CLASS_RAW(Vector3)) { - SET_FROM_ARRAY(PoolVector3Array); + SET_FROM_ARRAY(PackedVector3Array); break; } if (array_type->eklass == CACHED_CLASS_RAW(Color)) { - SET_FROM_ARRAY(PoolColorArray); + SET_FROM_ARRAY(PackedColorArray); break; } @@ -434,26 +434,26 @@ void GDMonoField::set_value_from_variant(MonoObject *p_object, const Variant &p_ MonoObject *managed = GDMonoUtils::create_managed_from(p_value.operator Array(), CACHED_CLASS(Array)); mono_field_set_value(p_object, mono_field, managed); } break; - case Variant::POOL_BYTE_ARRAY: { - SET_FROM_ARRAY(PoolByteArray); + case Variant::PACKED_BYTE_ARRAY: { + SET_FROM_ARRAY(PackedByteArray); } break; - case Variant::POOL_INT_ARRAY: { - SET_FROM_ARRAY(PoolIntArray); + case Variant::PACKED_INT_ARRAY: { + SET_FROM_ARRAY(PackedIntArray); } break; - case Variant::POOL_REAL_ARRAY: { - SET_FROM_ARRAY(PoolRealArray); + case Variant::PACKED_REAL_ARRAY: { + SET_FROM_ARRAY(PackedRealArray); } break; - case Variant::POOL_STRING_ARRAY: { - SET_FROM_ARRAY(PoolStringArray); + case Variant::PACKED_STRING_ARRAY: { + SET_FROM_ARRAY(PackedStringArray); } break; - case Variant::POOL_VECTOR2_ARRAY: { - SET_FROM_ARRAY(PoolVector2Array); + case Variant::PACKED_VECTOR2_ARRAY: { + SET_FROM_ARRAY(PackedVector2Array); } break; - case Variant::POOL_VECTOR3_ARRAY: { - SET_FROM_ARRAY(PoolVector3Array); + case Variant::PACKED_VECTOR3_ARRAY: { + SET_FROM_ARRAY(PackedVector3Array); } break; - case Variant::POOL_COLOR_ARRAY: { - SET_FROM_ARRAY(PoolColorArray); + case Variant::PACKED_COLOR_ARRAY: { + SET_FROM_ARRAY(PackedColorArray); } break; default: break; } @@ -512,7 +512,7 @@ void GDMonoField::set_value_from_variant(MonoObject *p_object, const Variant &p_ } break; default: { - ERR_PRINTS("Attempted to set the value of a field of unexpected type encoding: " + itos(type.type_encoding) + "."); + ERR_PRINT("Attempted to set the value of a field of unexpected type encoding: " + itos(type.type_encoding) + "."); } break; } diff --git a/modules/mono/mono_gd/gd_mono_internals.cpp b/modules/mono/mono_gd/gd_mono_internals.cpp index 75aa77c7b0..74ffa90cb3 100644 --- a/modules/mono/mono_gd/gd_mono_internals.cpp +++ b/modules/mono/mono_gd/gd_mono_internals.cpp @@ -107,7 +107,7 @@ void tie_managed_to_unmanaged(MonoObject *managed, Object *unmanaged) { ScriptInstance *si = CSharpInstance::create_for_managed_type(unmanaged, script.ptr(), gchandle); - unmanaged->set_script_and_instance(script.get_ref_ptr(), si); + unmanaged->set_script_and_instance(script, si); } void unhandled_exception(MonoException *p_exc) { diff --git a/modules/mono/mono_gd/gd_mono_log.cpp b/modules/mono/mono_gd/gd_mono_log.cpp index ad68a4d90e..76828a66e0 100644 --- a/modules/mono/mono_gd/gd_mono_log.cpp +++ b/modules/mono/mono_gd/gd_mono_log.cpp @@ -83,7 +83,7 @@ void GDMonoLog::mono_log_callback(const char *log_domain, const char *log_level, } if (fatal) { - ERR_PRINTS("Mono: FATAL ERROR, ABORTING! Logfile: '" + GDMonoLog::get_singleton()->log_file_path + "'."); + ERR_PRINT("Mono: FATAL ERROR, ABORTING! Logfile: '" + GDMonoLog::get_singleton()->log_file_path + "'."); // Make sure to flush before aborting f->flush(); f->close(); @@ -139,7 +139,7 @@ void GDMonoLog::initialize() { CharString log_level = OS::get_singleton()->get_environment("GODOT_MONO_LOG_LEVEL").utf8(); if (log_level.length() != 0 && get_log_level_id(log_level.get_data()) == -1) { - ERR_PRINTS(String() + "Mono: Ignoring invalid log level (GODOT_MONO_LOG_LEVEL): '" + log_level.get_data() + "'."); + ERR_PRINT(String() + "Mono: Ignoring invalid log level (GODOT_MONO_LOG_LEVEL): '" + log_level.get_data() + "'."); log_level = CharString(); } @@ -167,7 +167,7 @@ void GDMonoLog::initialize() { log_file = FileAccess::open(log_file_path, FileAccess::WRITE); if (!log_file) { - ERR_PRINTS("Mono: Cannot create log file at: " + log_file_path); + ERR_PRINT("Mono: Cannot create log file at: " + log_file_path); } } diff --git a/modules/mono/mono_gd/gd_mono_marshal.cpp b/modules/mono/mono_gd/gd_mono_marshal.cpp index b81c20348d..63890f6066 100644 --- a/modules/mono/mono_gd/gd_mono_marshal.cpp +++ b/modules/mono/mono_gd/gd_mono_marshal.cpp @@ -113,25 +113,25 @@ Variant::Type managed_to_variant_type(const ManagedType &p_type) { return Variant::ARRAY; if (array_type->eklass == CACHED_CLASS_RAW(uint8_t)) - return Variant::POOL_BYTE_ARRAY; + return Variant::PACKED_BYTE_ARRAY; if (array_type->eklass == CACHED_CLASS_RAW(int32_t)) - return Variant::POOL_INT_ARRAY; + return Variant::PACKED_INT_ARRAY; if (array_type->eklass == REAL_T_MONOCLASS) - return Variant::POOL_REAL_ARRAY; + return Variant::PACKED_REAL_ARRAY; if (array_type->eklass == CACHED_CLASS_RAW(String)) - return Variant::POOL_STRING_ARRAY; + return Variant::PACKED_STRING_ARRAY; if (array_type->eklass == CACHED_CLASS_RAW(Vector2)) - return Variant::POOL_VECTOR2_ARRAY; + return Variant::PACKED_VECTOR2_ARRAY; if (array_type->eklass == CACHED_CLASS_RAW(Vector3)) - return Variant::POOL_VECTOR3_ARRAY; + return Variant::PACKED_VECTOR3_ARRAY; if (array_type->eklass == CACHED_CLASS_RAW(Color)) - return Variant::POOL_COLOR_ARRAY; + return Variant::PACKED_COLOR_ARRAY; } break; case MONO_TYPE_CLASS: { @@ -277,7 +277,7 @@ String mono_to_utf8_string(MonoString *p_mono_string) { char *utf8 = mono_string_to_utf8_checked(p_mono_string, &error); if (!mono_error_ok(&error)) { - ERR_PRINTS(String() + "Failed to convert MonoString* to UTF-8: '" + mono_error_get_message(&error) + "'."); + ERR_PRINT(String() + "Failed to convert MonoString* to UTF-8: '" + mono_error_get_message(&error) + "'."); mono_error_cleanup(&error); return String(); } @@ -491,25 +491,25 @@ MonoObject *variant_to_mono_object(const Variant *p_var, const ManagedType &p_ty return (MonoObject *)Array_to_mono_array(p_var->operator Array()); if (array_type->eklass == CACHED_CLASS_RAW(uint8_t)) - return (MonoObject *)PoolByteArray_to_mono_array(p_var->operator PoolByteArray()); + return (MonoObject *)PackedByteArray_to_mono_array(p_var->operator PackedByteArray()); if (array_type->eklass == CACHED_CLASS_RAW(int32_t)) - return (MonoObject *)PoolIntArray_to_mono_array(p_var->operator PoolIntArray()); + return (MonoObject *)PackedIntArray_to_mono_array(p_var->operator PackedIntArray()); if (array_type->eklass == REAL_T_MONOCLASS) - return (MonoObject *)PoolRealArray_to_mono_array(p_var->operator PoolRealArray()); + return (MonoObject *)PackedRealArray_to_mono_array(p_var->operator PackedRealArray()); if (array_type->eklass == CACHED_CLASS_RAW(String)) - return (MonoObject *)PoolStringArray_to_mono_array(p_var->operator PoolStringArray()); + return (MonoObject *)PackedStringArray_to_mono_array(p_var->operator PackedStringArray()); if (array_type->eklass == CACHED_CLASS_RAW(Vector2)) - return (MonoObject *)PoolVector2Array_to_mono_array(p_var->operator PoolVector2Array()); + return (MonoObject *)PackedVector2Array_to_mono_array(p_var->operator PackedVector2Array()); if (array_type->eklass == CACHED_CLASS_RAW(Vector3)) - return (MonoObject *)PoolVector3Array_to_mono_array(p_var->operator PoolVector3Array()); + return (MonoObject *)PackedVector3Array_to_mono_array(p_var->operator PackedVector3Array()); if (array_type->eklass == CACHED_CLASS_RAW(Color)) - return (MonoObject *)PoolColorArray_to_mono_array(p_var->operator PoolColorArray()); + return (MonoObject *)PackedColorArray_to_mono_array(p_var->operator PackedColorArray()); ERR_FAIL_V_MSG(NULL, "Attempted to convert Variant to a managed array of unmarshallable element type."); } break; @@ -638,20 +638,20 @@ MonoObject *variant_to_mono_object(const Variant *p_var, const ManagedType &p_ty return GDMonoUtils::create_managed_from(p_var->operator Dictionary(), CACHED_CLASS(Dictionary)); case Variant::ARRAY: return GDMonoUtils::create_managed_from(p_var->operator Array(), CACHED_CLASS(Array)); - case Variant::POOL_BYTE_ARRAY: - return (MonoObject *)PoolByteArray_to_mono_array(p_var->operator PoolByteArray()); - case Variant::POOL_INT_ARRAY: - return (MonoObject *)PoolIntArray_to_mono_array(p_var->operator PoolIntArray()); - case Variant::POOL_REAL_ARRAY: - return (MonoObject *)PoolRealArray_to_mono_array(p_var->operator PoolRealArray()); - case Variant::POOL_STRING_ARRAY: - return (MonoObject *)PoolStringArray_to_mono_array(p_var->operator PoolStringArray()); - case Variant::POOL_VECTOR2_ARRAY: - return (MonoObject *)PoolVector2Array_to_mono_array(p_var->operator PoolVector2Array()); - case Variant::POOL_VECTOR3_ARRAY: - return (MonoObject *)PoolVector3Array_to_mono_array(p_var->operator PoolVector3Array()); - case Variant::POOL_COLOR_ARRAY: - return (MonoObject *)PoolColorArray_to_mono_array(p_var->operator PoolColorArray()); + case Variant::PACKED_BYTE_ARRAY: + return (MonoObject *)PackedByteArray_to_mono_array(p_var->operator PackedByteArray()); + case Variant::PACKED_INT_ARRAY: + return (MonoObject *)PackedIntArray_to_mono_array(p_var->operator PackedIntArray()); + case Variant::PACKED_REAL_ARRAY: + return (MonoObject *)PackedRealArray_to_mono_array(p_var->operator PackedRealArray()); + case Variant::PACKED_STRING_ARRAY: + return (MonoObject *)PackedStringArray_to_mono_array(p_var->operator PackedStringArray()); + case Variant::PACKED_VECTOR2_ARRAY: + return (MonoObject *)PackedVector2Array_to_mono_array(p_var->operator PackedVector2Array()); + case Variant::PACKED_VECTOR3_ARRAY: + return (MonoObject *)PackedVector3Array_to_mono_array(p_var->operator PackedVector3Array()); + case Variant::PACKED_COLOR_ARRAY: + return (MonoObject *)PackedColorArray_to_mono_array(p_var->operator PackedColorArray()); default: return NULL; } @@ -785,25 +785,25 @@ Variant mono_object_to_variant_impl(MonoObject *p_obj, const ManagedType &p_type return mono_array_to_Array((MonoArray *)p_obj); if (array_type->eklass == CACHED_CLASS_RAW(uint8_t)) - return mono_array_to_PoolByteArray((MonoArray *)p_obj); + return mono_array_to_PackedByteArray((MonoArray *)p_obj); if (array_type->eklass == CACHED_CLASS_RAW(int32_t)) - return mono_array_to_PoolIntArray((MonoArray *)p_obj); + return mono_array_to_PackedIntArray((MonoArray *)p_obj); if (array_type->eklass == REAL_T_MONOCLASS) - return mono_array_to_PoolRealArray((MonoArray *)p_obj); + return mono_array_to_PackedRealArray((MonoArray *)p_obj); if (array_type->eklass == CACHED_CLASS_RAW(String)) - return mono_array_to_PoolStringArray((MonoArray *)p_obj); + return mono_array_to_PackedStringArray((MonoArray *)p_obj); if (array_type->eklass == CACHED_CLASS_RAW(Vector2)) - return mono_array_to_PoolVector2Array((MonoArray *)p_obj); + return mono_array_to_PackedVector2Array((MonoArray *)p_obj); if (array_type->eklass == CACHED_CLASS_RAW(Vector3)) - return mono_array_to_PoolVector3Array((MonoArray *)p_obj); + return mono_array_to_PackedVector3Array((MonoArray *)p_obj); if (array_type->eklass == CACHED_CLASS_RAW(Color)) - return mono_array_to_PoolColorArray((MonoArray *)p_obj); + return mono_array_to_PackedColorArray((MonoArray *)p_obj); if (p_fail_with_err) { ERR_FAIL_V_MSG(Variant(), "Attempted to convert a managed array of unmarshallable element type to Variant."); @@ -987,8 +987,8 @@ Array mono_array_to_Array(MonoArray *p_array) { // TODO: Use memcpy where possible -MonoArray *PoolIntArray_to_mono_array(const PoolIntArray &p_array) { - PoolIntArray::Read r = p_array.read(); +MonoArray *PackedIntArray_to_mono_array(const PackedIntArray &p_array) { + const int *r = p_array.ptr(); MonoArray *ret = mono_array_new(mono_domain_get(), CACHED_CLASS_RAW(int32_t), p_array.size()); @@ -999,13 +999,13 @@ MonoArray *PoolIntArray_to_mono_array(const PoolIntArray &p_array) { return ret; } -PoolIntArray mono_array_to_PoolIntArray(MonoArray *p_array) { - PoolIntArray ret; +PackedIntArray mono_array_to_PackedIntArray(MonoArray *p_array) { + PackedIntArray ret; if (!p_array) return ret; int length = mono_array_length(p_array); ret.resize(length); - PoolIntArray::Write w = ret.write(); + int *w = ret.ptrw(); for (int i = 0; i < length; i++) { w[i] = mono_array_get(p_array, int32_t, i); @@ -1014,8 +1014,8 @@ PoolIntArray mono_array_to_PoolIntArray(MonoArray *p_array) { return ret; } -MonoArray *PoolByteArray_to_mono_array(const PoolByteArray &p_array) { - PoolByteArray::Read r = p_array.read(); +MonoArray *PackedByteArray_to_mono_array(const PackedByteArray &p_array) { + const uint8_t *r = p_array.ptr(); MonoArray *ret = mono_array_new(mono_domain_get(), CACHED_CLASS_RAW(uint8_t), p_array.size()); @@ -1026,13 +1026,13 @@ MonoArray *PoolByteArray_to_mono_array(const PoolByteArray &p_array) { return ret; } -PoolByteArray mono_array_to_PoolByteArray(MonoArray *p_array) { - PoolByteArray ret; +PackedByteArray mono_array_to_PackedByteArray(MonoArray *p_array) { + PackedByteArray ret; if (!p_array) return ret; int length = mono_array_length(p_array); ret.resize(length); - PoolByteArray::Write w = ret.write(); + uint8_t *w = ret.ptrw(); for (int i = 0; i < length; i++) { w[i] = mono_array_get(p_array, uint8_t, i); @@ -1041,8 +1041,8 @@ PoolByteArray mono_array_to_PoolByteArray(MonoArray *p_array) { return ret; } -MonoArray *PoolRealArray_to_mono_array(const PoolRealArray &p_array) { - PoolRealArray::Read r = p_array.read(); +MonoArray *PackedRealArray_to_mono_array(const PackedRealArray &p_array) { + const real_t *r = p_array.ptr(); MonoArray *ret = mono_array_new(mono_domain_get(), REAL_T_MONOCLASS, p_array.size()); @@ -1053,13 +1053,13 @@ MonoArray *PoolRealArray_to_mono_array(const PoolRealArray &p_array) { return ret; } -PoolRealArray mono_array_to_PoolRealArray(MonoArray *p_array) { - PoolRealArray ret; +PackedRealArray mono_array_to_PackedRealArray(MonoArray *p_array) { + PackedRealArray ret; if (!p_array) return ret; int length = mono_array_length(p_array); ret.resize(length); - PoolRealArray::Write w = ret.write(); + real_t *w = ret.ptrw(); for (int i = 0; i < length; i++) { w[i] = mono_array_get(p_array, real_t, i); @@ -1068,8 +1068,8 @@ PoolRealArray mono_array_to_PoolRealArray(MonoArray *p_array) { return ret; } -MonoArray *PoolStringArray_to_mono_array(const PoolStringArray &p_array) { - PoolStringArray::Read r = p_array.read(); +MonoArray *PackedStringArray_to_mono_array(const PackedStringArray &p_array) { + const String *r = p_array.ptr(); MonoArray *ret = mono_array_new(mono_domain_get(), CACHED_CLASS_RAW(String), p_array.size()); @@ -1081,13 +1081,13 @@ MonoArray *PoolStringArray_to_mono_array(const PoolStringArray &p_array) { return ret; } -PoolStringArray mono_array_to_PoolStringArray(MonoArray *p_array) { - PoolStringArray ret; +PackedStringArray mono_array_to_PackedStringArray(MonoArray *p_array) { + PackedStringArray ret; if (!p_array) return ret; int length = mono_array_length(p_array); ret.resize(length); - PoolStringArray::Write w = ret.write(); + String *w = ret.ptrw(); for (int i = 0; i < length; i++) { MonoString *elem = mono_array_get(p_array, MonoString *, i); @@ -1097,8 +1097,8 @@ PoolStringArray mono_array_to_PoolStringArray(MonoArray *p_array) { return ret; } -MonoArray *PoolColorArray_to_mono_array(const PoolColorArray &p_array) { - PoolColorArray::Read r = p_array.read(); +MonoArray *PackedColorArray_to_mono_array(const PackedColorArray &p_array) { + const Color *r = p_array.ptr(); MonoArray *ret = mono_array_new(mono_domain_get(), CACHED_CLASS_RAW(Color), p_array.size()); @@ -1110,13 +1110,13 @@ MonoArray *PoolColorArray_to_mono_array(const PoolColorArray &p_array) { return ret; } -PoolColorArray mono_array_to_PoolColorArray(MonoArray *p_array) { - PoolColorArray ret; +PackedColorArray mono_array_to_PackedColorArray(MonoArray *p_array) { + PackedColorArray ret; if (!p_array) return ret; int length = mono_array_length(p_array); ret.resize(length); - PoolColorArray::Write w = ret.write(); + Color *w = ret.ptrw(); for (int i = 0; i < length; i++) { w[i] = MARSHALLED_IN(Color, (M_Color *)mono_array_addr_with_size(p_array, sizeof(M_Color), i)); @@ -1125,8 +1125,8 @@ PoolColorArray mono_array_to_PoolColorArray(MonoArray *p_array) { return ret; } -MonoArray *PoolVector2Array_to_mono_array(const PoolVector2Array &p_array) { - PoolVector2Array::Read r = p_array.read(); +MonoArray *PackedVector2Array_to_mono_array(const PackedVector2Array &p_array) { + const Vector2 *r = p_array.ptr(); MonoArray *ret = mono_array_new(mono_domain_get(), CACHED_CLASS_RAW(Vector2), p_array.size()); @@ -1138,13 +1138,13 @@ MonoArray *PoolVector2Array_to_mono_array(const PoolVector2Array &p_array) { return ret; } -PoolVector2Array mono_array_to_PoolVector2Array(MonoArray *p_array) { - PoolVector2Array ret; +PackedVector2Array mono_array_to_PackedVector2Array(MonoArray *p_array) { + PackedVector2Array ret; if (!p_array) return ret; int length = mono_array_length(p_array); ret.resize(length); - PoolVector2Array::Write w = ret.write(); + Vector2 *w = ret.ptrw(); for (int i = 0; i < length; i++) { w[i] = MARSHALLED_IN(Vector2, (M_Vector2 *)mono_array_addr_with_size(p_array, sizeof(M_Vector2), i)); @@ -1153,8 +1153,8 @@ PoolVector2Array mono_array_to_PoolVector2Array(MonoArray *p_array) { return ret; } -MonoArray *PoolVector3Array_to_mono_array(const PoolVector3Array &p_array) { - PoolVector3Array::Read r = p_array.read(); +MonoArray *PackedVector3Array_to_mono_array(const PackedVector3Array &p_array) { + const Vector3 *r = p_array.ptr(); MonoArray *ret = mono_array_new(mono_domain_get(), CACHED_CLASS_RAW(Vector3), p_array.size()); @@ -1166,13 +1166,13 @@ MonoArray *PoolVector3Array_to_mono_array(const PoolVector3Array &p_array) { return ret; } -PoolVector3Array mono_array_to_PoolVector3Array(MonoArray *p_array) { - PoolVector3Array ret; +PackedVector3Array mono_array_to_PackedVector3Array(MonoArray *p_array) { + PackedVector3Array ret; if (!p_array) return ret; int length = mono_array_length(p_array); ret.resize(length); - PoolVector3Array::Write w = ret.write(); + Vector3 *w = ret.ptrw(); for (int i = 0; i < length; i++) { w[i] = MARSHALLED_IN(Vector3, (M_Vector3 *)mono_array_addr_with_size(p_array, sizeof(M_Vector3), i)); diff --git a/modules/mono/mono_gd/gd_mono_marshal.h b/modules/mono/mono_gd/gd_mono_marshal.h index e662e7814e..d3527109ff 100644 --- a/modules/mono/mono_gd/gd_mono_marshal.h +++ b/modules/mono/mono_gd/gd_mono_marshal.h @@ -127,40 +127,40 @@ String mono_object_to_variant_string(MonoObject *p_obj, MonoException **r_exc); MonoArray *Array_to_mono_array(const Array &p_array); Array mono_array_to_Array(MonoArray *p_array); -// PoolIntArray +// PackedIntArray -MonoArray *PoolIntArray_to_mono_array(const PoolIntArray &p_array); -PoolIntArray mono_array_to_PoolIntArray(MonoArray *p_array); +MonoArray *PackedIntArray_to_mono_array(const PackedIntArray &p_array); +PackedIntArray mono_array_to_PackedIntArray(MonoArray *p_array); -// PoolByteArray +// PackedByteArray -MonoArray *PoolByteArray_to_mono_array(const PoolByteArray &p_array); -PoolByteArray mono_array_to_PoolByteArray(MonoArray *p_array); +MonoArray *PackedByteArray_to_mono_array(const PackedByteArray &p_array); +PackedByteArray mono_array_to_PackedByteArray(MonoArray *p_array); -// PoolRealArray +// PackedRealArray -MonoArray *PoolRealArray_to_mono_array(const PoolRealArray &p_array); -PoolRealArray mono_array_to_PoolRealArray(MonoArray *p_array); +MonoArray *PackedRealArray_to_mono_array(const PackedRealArray &p_array); +PackedRealArray mono_array_to_PackedRealArray(MonoArray *p_array); -// PoolStringArray +// PackedStringArray -MonoArray *PoolStringArray_to_mono_array(const PoolStringArray &p_array); -PoolStringArray mono_array_to_PoolStringArray(MonoArray *p_array); +MonoArray *PackedStringArray_to_mono_array(const PackedStringArray &p_array); +PackedStringArray mono_array_to_PackedStringArray(MonoArray *p_array); -// PoolColorArray +// PackedColorArray -MonoArray *PoolColorArray_to_mono_array(const PoolColorArray &p_array); -PoolColorArray mono_array_to_PoolColorArray(MonoArray *p_array); +MonoArray *PackedColorArray_to_mono_array(const PackedColorArray &p_array); +PackedColorArray mono_array_to_PackedColorArray(MonoArray *p_array); -// PoolVector2Array +// PackedVector2Array -MonoArray *PoolVector2Array_to_mono_array(const PoolVector2Array &p_array); -PoolVector2Array mono_array_to_PoolVector2Array(MonoArray *p_array); +MonoArray *PackedVector2Array_to_mono_array(const PackedVector2Array &p_array); +PackedVector2Array mono_array_to_PackedVector2Array(MonoArray *p_array); -// PoolVector3Array +// PackedVector3Array -MonoArray *PoolVector3Array_to_mono_array(const PoolVector3Array &p_array); -PoolVector3Array mono_array_to_PoolVector3Array(MonoArray *p_array); +MonoArray *PackedVector3Array_to_mono_array(const PackedVector3Array &p_array); +PackedVector3Array mono_array_to_PackedVector3Array(MonoArray *p_array); // Structures diff --git a/modules/mono/mono_gd/gd_mono_utils.cpp b/modules/mono/mono_gd/gd_mono_utils.cpp index 4e7f590a69..05077a00c4 100644 --- a/modules/mono/mono_gd/gd_mono_utils.cpp +++ b/modules/mono/mono_gd/gd_mono_utils.cpp @@ -354,7 +354,7 @@ void debug_send_unhandled_exception_error(MonoException *p_exc) { if (!ScriptDebugger::get_singleton()) { #ifdef TOOLS_ENABLED if (Engine::get_singleton()->is_editor_hint()) { - ERR_PRINTS(GDMonoUtils::get_exception_name_and_message(p_exc)); + ERR_PRINT(GDMonoUtils::get_exception_name_and_message(p_exc)); } #endif return; @@ -431,7 +431,7 @@ void set_pending_exception(MonoException *p_exc) { } if (!mono_runtime_set_pending_exception(p_exc, false)) { - ERR_PRINTS("Exception thrown from managed code, but it could not be set as pending:"); + ERR_PRINT("Exception thrown from managed code, but it could not be set as pending:"); GDMonoUtils::debug_print_unhandled_exception(p_exc); } #endif diff --git a/modules/mono/signal_awaiter_utils.cpp b/modules/mono/signal_awaiter_utils.cpp index d3226762ea..b85d5f2fd9 100644 --- a/modules/mono/signal_awaiter_utils.cpp +++ b/modules/mono/signal_awaiter_utils.cpp @@ -68,7 +68,7 @@ Error connect_signal_awaiter(Object *p_source, const String &p_signal, Object *p Variant SignalAwaiterHandle::_signal_callback(const Variant **p_args, int p_argcount, Variant::CallError &r_error) { #ifdef DEBUG_ENABLED - ERR_FAIL_COND_V_MSG(conn_target_id && !ObjectDB::get_instance(conn_target_id), Variant(), + ERR_FAIL_COND_V_MSG(conn_target_id.is_valid() && !ObjectDB::get_instance(conn_target_id), Variant(), "Resumed after await, but class instance is gone."); #endif @@ -116,12 +116,7 @@ void SignalAwaiterHandle::_bind_methods() { } SignalAwaiterHandle::SignalAwaiterHandle(MonoObject *p_managed) : - MonoGCHandle(MonoGCHandle::new_strong_handle(p_managed), STRONG_HANDLE) { - -#ifdef DEBUG_ENABLED - conn_target_id = 0; -#endif -} + MonoGCHandle(MonoGCHandle::new_strong_handle(p_managed), STRONG_HANDLE) {} SignalAwaiterHandle::~SignalAwaiterHandle() { diff --git a/modules/mono/utils/string_utils.cpp b/modules/mono/utils/string_utils.cpp index 911ac5c4a3..49c4fb3f73 100644 --- a/modules/mono/utils/string_utils.cpp +++ b/modules/mono/utils/string_utils.cpp @@ -162,22 +162,22 @@ String escape_csharp_keyword(const String &p_name) { #endif Error read_all_file_utf8(const String &p_path, String &r_content) { - PoolVector<uint8_t> sourcef; + Vector<uint8_t> sourcef; Error err; FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err); ERR_FAIL_COND_V_MSG(err != OK, err, "Cannot open file '" + p_path + "'."); int len = f->get_len(); sourcef.resize(len + 1); - PoolVector<uint8_t>::Write w = sourcef.write(); - int r = f->get_buffer(w.ptr(), len); + uint8_t *w = sourcef.ptrw(); + int r = f->get_buffer(w, len); f->close(); memdelete(f); ERR_FAIL_COND_V(r != len, ERR_CANT_OPEN); w[len] = 0; String source; - if (source.parse_utf8((const char *)w.ptr())) { + if (source.parse_utf8((const char *)w)) { ERR_FAIL_V(ERR_INVALID_DATA); } |