diff options
Diffstat (limited to 'modules')
149 files changed, 1830 insertions, 980 deletions
diff --git a/modules/csg/csg_shape.cpp b/modules/csg/csg_shape.cpp index 6294790132..3932c2377f 100644 --- a/modules/csg/csg_shape.cpp +++ b/modules/csg/csg_shape.cpp @@ -1852,13 +1852,13 @@ CSGBrush *CSGPolygon3D::_build_brush() { base_xform = path->get_global_transform(); } - Vector3 current_point = curve->interpolate_baked(0); - Vector3 next_point = curve->interpolate_baked(extrusion_step); + Vector3 current_point = curve->sample_baked(0); + Vector3 next_point = curve->sample_baked(extrusion_step); Vector3 current_up = Vector3(0, 1, 0); Vector3 direction = next_point - current_point; if (path_joined) { - Vector3 last_point = curve->interpolate_baked(curve->get_baked_length()); + Vector3 last_point = curve->sample_baked(curve->get_baked_length()); direction = next_point - last_point; } @@ -1869,7 +1869,7 @@ CSGBrush *CSGPolygon3D::_build_brush() { case PATH_ROTATION_PATH: break; case PATH_ROTATION_PATH_FOLLOW: - current_up = curve->interpolate_baked_up_vector(0); + current_up = curve->sample_baked_up_vector(0); break; } @@ -1931,9 +1931,9 @@ CSGBrush *CSGPolygon3D::_build_brush() { } } - Vector3 previous_point = curve->interpolate_baked(previous_offset); - Vector3 current_point = curve->interpolate_baked(current_offset); - Vector3 next_point = curve->interpolate_baked(next_offset); + Vector3 previous_point = curve->sample_baked(previous_offset); + Vector3 current_point = curve->sample_baked(current_offset); + Vector3 next_point = curve->sample_baked(next_offset); Vector3 current_up = Vector3(0, 1, 0); Vector3 direction = next_point - previous_point; Vector3 current_dir = (current_point - previous_point).normalized(); @@ -1956,7 +1956,7 @@ CSGBrush *CSGPolygon3D::_build_brush() { case PATH_ROTATION_PATH: break; case PATH_ROTATION_PATH_FOLLOW: - current_up = curve->interpolate_baked_up_vector(current_offset); + current_up = curve->sample_baked_up_vector(current_offset); break; } diff --git a/modules/denoise/config.py b/modules/denoise/config.py index 350839651a..20a5e1da2f 100644 --- a/modules/denoise/config.py +++ b/modules/denoise/config.py @@ -2,7 +2,7 @@ def can_build(env, platform): # Thirdparty dependency OpenImage Denoise includes oneDNN library # and the version we use only supports x86_64. # It's also only relevant for tools build and desktop platforms, - # as doing lightmap generation and denoising on Android or HTML5 + # as doing lightmap generation and denoising on Android or Web # would be a bit far-fetched. desktop_platforms = ["linuxbsd", "macos", "windows"] return env["tools"] and platform in desktop_platforms and env["arch"] == "x86_64" diff --git a/modules/freetype/SCsub b/modules/freetype/SCsub index 8efcd72fb6..2680479acc 100644 --- a/modules/freetype/SCsub +++ b/modules/freetype/SCsub @@ -99,7 +99,7 @@ if env["builtin_freetype"]: sfnt = thirdparty_dir + "src/sfnt/sfnt.c" # Must be done after all CPPDEFINES are being set so we can copy them. - if env["platform"] == "javascript": + if env["platform"] == "web": # Forcibly undefine this macro so SIMD is not used in this file, # since currently unsupported in WASM tmp_env = env_freetype.Clone() diff --git a/modules/gdscript/editor/gdscript_highlighter.cpp b/modules/gdscript/editor/gdscript_highlighter.cpp index b9560ea69b..afb59b486c 100644 --- a/modules/gdscript/editor/gdscript_highlighter.cpp +++ b/modules/gdscript/editor/gdscript_highlighter.cpp @@ -45,10 +45,11 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l int previous_column = 0; bool prev_is_char = false; - bool prev_is_number = false; + bool prev_is_digit = false; bool prev_is_binary_op = false; bool in_keyword = false; bool in_word = false; + bool in_number = false; bool in_function_name = false; bool in_lambda = false; bool in_variable_declaration = false; @@ -94,7 +95,7 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l color = font_color; bool is_char = !is_symbol(str[j]); bool is_a_symbol = is_symbol(str[j]); - bool is_number = is_digit(str[j]); + bool is_a_digit = is_digit(str[j]); bool is_binary_op = false; /* color regions */ @@ -233,58 +234,80 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l in_region = -1; prev_is_char = false; - prev_is_number = false; + prev_is_digit = false; + prev_is_binary_op = false; continue; } } } + // A bit of a hack, but couldn't come up with anything better. + if (j > 0 && (str[j] == '&' || str[j] == '^' || str[j] == '%' || str[j] == '+' || str[j] == '-' || str[j] == '~' || str[j] == '.')) { + if (!keywords.has(previous_text)) { + if (previous_text == "PI" || previous_text == "TAU" || previous_text == "INF" || previous_text == "NAN") { + is_binary_op = true; + } else { + int k = j - 1; + while (k > 0 && is_whitespace(str[k])) { + k--; + } + if (!is_symbol(str[k]) || str[k] == '"' || str[k] == '\'' || str[k] == ')' || str[k] == ']' || str[k] == '}') { + is_binary_op = true; + } + } + } + } + + if (!is_char) { + in_keyword = false; + } + // allow ABCDEF in hex notation - if (is_hex_notation && (is_hex_digit(str[j]) || is_number)) { - is_number = true; + if (is_hex_notation && (is_hex_digit(str[j]) || is_a_digit)) { + is_a_digit = true; } else { is_hex_notation = false; } // disallow anything not a 0 or 1 in binary notation - if (is_bin_notation && (is_binary_digit(str[j]))) { - is_number = true; - } else if (is_bin_notation) { - is_bin_notation = false; - is_number = false; - } else { + if (is_bin_notation && !is_binary_digit(str[j])) { + is_a_digit = false; is_bin_notation = false; } - // check for dot or underscore or 'x' for hex notation in floating point number or 'e' for scientific notation - if ((str[j] == '.' || str[j] == 'x' || str[j] == 'b' || str[j] == '_' || str[j] == 'e') && !in_word && prev_is_number && !is_number) { - is_number = true; - is_a_symbol = false; - is_char = false; + if (!in_number && !in_word && is_a_digit) { + in_number = true; + } - if (str[j] == 'x' && str[j - 1] == '0') { - is_hex_notation = true; - } else if (str[j] == 'b' && str[j - 1] == '0') { + // Special cases for numbers + if (in_number && !is_a_digit) { + if (str[j] == 'b' && str[j - 1] == '0') { is_bin_notation = true; + } else if (str[j] == 'x' && str[j - 1] == '0') { + is_hex_notation = true; + } else if (!((str[j] == '-' || str[j] == '+') && str[j - 1] == 'e' && !prev_is_digit) && + !(str[j] == '_' && (prev_is_digit || str[j - 1] == 'b' || str[j - 1] == 'x' || str[j - 1] == '.')) && + !((str[j] == 'e' || str[j] == '.') && (prev_is_digit || str[j - 1] == '_')) && + !((str[j] == '-' || str[j] == '+' || str[j] == '~') && !prev_is_binary_op && str[j - 1] != 'e')) { + /* 1st row of condition: '+' or '-' after scientific notation; + 2nd row of condition: '_' as a numeric separator; + 3rd row of condition: Scientific notation 'e' and floating points; + 4th row of condition: Multiple unary operators. */ + in_number = false; } + } else if ((str[j] == '-' || str[j] == '+' || str[j] == '~' || (str[j] == '.' && str[j + 1] != '.' && (j == 0 || (j > 0 && str[j - 1] != '.')))) && !is_binary_op) { + // Start a number from unary mathematical operators and floating points, except for '..' + in_number = true; } - if (!in_word && (is_ascii_char(str[j]) || is_underscore(str[j])) && !is_number) { + if (!in_word && (is_ascii_char(str[j]) || is_underscore(str[j])) && !in_number) { in_word = true; } - if ((in_keyword || in_word) && !is_hex_notation) { - is_number = false; - } - if (is_a_symbol && str[j] != '.' && in_word) { in_word = false; } - if (!is_char) { - in_keyword = false; - } - if (!in_keyword && is_char && !prev_is_char) { int to = j; while (to < line_length && !is_symbol(str[to])) { @@ -293,7 +316,22 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l String word = str.substr(j, to - j); Color col = Color(); - if (keywords.has(word)) { + if (global_functions.has(word)) { + // "assert" and "preload" are reserved, so highlight even if not followed by a bracket. + if (word == "assert" || word == "preload") { + col = global_function_color; + } else { + // For other global functions, check if followed by bracket. + int k = to; + while (k < line_length && is_whitespace(str[k])) { + k++; + } + + if (str[k] == '(') { + col = global_function_color; + } + } + } else if (keywords.has(word)) { col = keywords[word]; } else if (member_keywords.has(word)) { col = member_keywords[word]; @@ -302,12 +340,13 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l if (col != Color()) { for (int k = j - 1; k >= 0; k--) { if (str[k] == '.') { - col = Color(); // keyword & member indexing not allowed + col = Color(); // keyword, member & global func indexing not allowed break; } else if (str[k] > 32) { break; } } + if (col != Color()) { in_keyword = true; keyword_color = col; @@ -349,7 +388,7 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l } } - if (!in_function_name && !in_member_variable && !in_keyword && !is_number && in_word) { + if (!in_function_name && !in_member_variable && !in_keyword && !in_number && in_word) { int k = j; while (k > 0 && !is_symbol(str[k]) && !is_whitespace(str[k])) { k--; @@ -397,22 +436,6 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l in_member_variable = false; } - if (j > 0 && (str[j] == '&' || str[j] == '^' || str[j] == '%' || str[j] == '+' || str[j] == '-' || str[j] == '~')) { - int k = j - 1; - while (k > 0 && is_whitespace(str[k])) { - k--; - } - if (!is_symbol(str[k]) || str[k] == '"' || str[k] == '\'' || str[k] == ')' || str[k] == ']' || str[k] == '}') { - is_binary_op = true; - } - } - - // Highlight '+' and '-' like numbers when unary - if ((str[j] == '+' || str[j] == '-' || str[j] == '~') && !is_binary_op) { - is_number = true; - is_a_symbol = false; - } - // Keep symbol color for binary '&&'. In the case of '&&&' use StringName color for the last ampersand if (!in_string_name && in_region == -1 && str[j] == '&' && !is_binary_op) { if (j >= 2 && str[j - 1] == '&' && str[j - 2] != '&' && prev_is_binary_op) { @@ -473,12 +496,12 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l } else { color = function_color; } + } else if (in_number) { + next_type = NUMBER; + color = number_color; } else if (is_a_symbol) { next_type = SYMBOL; color = symbol_color; - } else if (is_number) { - next_type = NUMBER; - color = number_color; } else if (expect_type) { next_type = TYPE; color = type_color; @@ -510,7 +533,7 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l } prev_is_char = is_char; - prev_is_number = is_number; + prev_is_digit = is_a_digit; prev_is_binary_op = is_binary_op; if (color != prev_color) { @@ -535,6 +558,7 @@ PackedStringArray GDScriptSyntaxHighlighter::_get_supported_languages() const { void GDScriptSyntaxHighlighter::_update_cache() { keywords.clear(); member_keywords.clear(); + global_functions.clear(); color_regions.clear(); color_region_cache.clear(); @@ -591,6 +615,17 @@ void GDScriptSyntaxHighlighter::_update_cache() { } } + /* Global functions. */ + List<StringName> global_function_list; + GDScriptUtilityFunctions::get_function_list(&global_function_list); + Variant::get_utility_function_list(&global_function_list); + // "assert" and "preload" are not utility functions, but are global nonetheless, so insert them. + global_functions.insert(SNAME("assert")); + global_functions.insert(SNAME("preload")); + for (const StringName &E : global_function_list) { + global_functions.insert(E); + } + /* Comments */ const Color comment_color = EDITOR_GET("text_editor/theme/highlighting/comment_color"); List<String> comments; @@ -643,12 +678,14 @@ void GDScriptSyntaxHighlighter::_update_cache() { if (godot_2_theme || EditorSettings::get_singleton()->is_dark_theme()) { function_definition_color = Color(0.4, 0.9, 1.0); + global_function_color = Color(0.64, 0.64, 0.96); node_path_color = Color(0.72, 0.77, 0.49); node_ref_color = Color(0.39, 0.76, 0.35); annotation_color = Color(1.0, 0.7, 0.45); string_name_color = Color(1.0, 0.76, 0.65); } else { function_definition_color = Color(0, 0.6, 0.6); + global_function_color = Color(0.36, 0.18, 0.72); node_path_color = Color(0.18, 0.55, 0); node_ref_color = Color(0.0, 0.5, 0); annotation_color = Color(0.8, 0.37, 0); @@ -656,6 +693,7 @@ void GDScriptSyntaxHighlighter::_update_cache() { } EDITOR_DEF("text_editor/theme/highlighting/gdscript/function_definition_color", function_definition_color); + EDITOR_DEF("text_editor/theme/highlighting/gdscript/global_function_color", global_function_color); EDITOR_DEF("text_editor/theme/highlighting/gdscript/node_path_color", node_path_color); EDITOR_DEF("text_editor/theme/highlighting/gdscript/node_reference_color", node_ref_color); EDITOR_DEF("text_editor/theme/highlighting/gdscript/annotation_color", annotation_color); @@ -666,6 +704,10 @@ void GDScriptSyntaxHighlighter::_update_cache() { function_definition_color, true); EditorSettings::get_singleton()->set_initial_value( + "text_editor/theme/highlighting/gdscript/global_function_color", + global_function_color, + true); + EditorSettings::get_singleton()->set_initial_value( "text_editor/theme/highlighting/gdscript/node_path_color", node_path_color, true); @@ -684,6 +726,7 @@ void GDScriptSyntaxHighlighter::_update_cache() { } function_definition_color = EDITOR_GET("text_editor/theme/highlighting/gdscript/function_definition_color"); + global_function_color = EDITOR_GET("text_editor/theme/highlighting/gdscript/global_function_color"); node_path_color = EDITOR_GET("text_editor/theme/highlighting/gdscript/node_path_color"); node_ref_color = EDITOR_GET("text_editor/theme/highlighting/gdscript/node_reference_color"); annotation_color = EDITOR_GET("text_editor/theme/highlighting/gdscript/annotation_color"); diff --git a/modules/gdscript/editor/gdscript_highlighter.h b/modules/gdscript/editor/gdscript_highlighter.h index f434d03a31..60b5b092d4 100644 --- a/modules/gdscript/editor/gdscript_highlighter.h +++ b/modules/gdscript/editor/gdscript_highlighter.h @@ -49,6 +49,7 @@ private: HashMap<StringName, Color> keywords; HashMap<StringName, Color> member_keywords; + HashSet<StringName> global_functions; enum Type { NONE, @@ -67,10 +68,11 @@ private: TYPE, }; - // colours + // Colors. Color font_color; Color symbol_color; Color function_color; + Color global_function_color; Color function_definition_color; Color built_in_type_color; Color number_color; diff --git a/modules/gdscript/editor/gdscript_translation_parser_plugin.cpp b/modules/gdscript/editor/gdscript_translation_parser_plugin.cpp index 9b540b16f2..518d4bcb62 100644 --- a/modules/gdscript/editor/gdscript_translation_parser_plugin.cpp +++ b/modules/gdscript/editor/gdscript_translation_parser_plugin.cpp @@ -41,7 +41,7 @@ Error GDScriptEditorTranslationParserPlugin::parse_file(const String &p_path, Ve // Extract all translatable strings using the parsed tree from GDSriptParser. // The strategy is to find all ExpressionNode and AssignmentNode from the tree and extract strings if relevant, i.e // Search strings in ExpressionNode -> CallNode -> tr(), set_text(), set_placeholder() etc. - // Search strings in AssignmentNode -> text = "__", hint_tooltip = "__" etc. + // Search strings in AssignmentNode -> text = "__", tooltip_text = "__" etc. Error err; Ref<Resource> loaded_res = ResourceLoader::load(p_path, "", ResourceFormatLoader::CACHE_MODE_REUSE, &err); @@ -221,7 +221,7 @@ void GDScriptEditorTranslationParserPlugin::_assess_assignment(GDScriptParser::A } if (assignment_patterns.has(assignee_name) && p_assignment->assigned_value->type == GDScriptParser::Node::LITERAL) { - // If the assignment is towards one of the extract patterns (text, hint_tooltip etc.), and the value is a string literal, we collect the string. + // If the assignment is towards one of the extract patterns (text, tooltip_text etc.), and the value is a string literal, we collect the string. ids->push_back(static_cast<GDScriptParser::LiteralNode *>(p_assignment->assigned_value)->value); } else if (assignee_name == fd_filters && p_assignment->assigned_value->type == GDScriptParser::Node::CALL) { // FileDialog.filters accepts assignment in the form of PackedStringArray. For example, @@ -330,10 +330,10 @@ void GDScriptEditorTranslationParserPlugin::_extract_fd_literals(GDScriptParser: GDScriptEditorTranslationParserPlugin::GDScriptEditorTranslationParserPlugin() { assignment_patterns.insert("text"); assignment_patterns.insert("placeholder_text"); - assignment_patterns.insert("hint_tooltip"); + assignment_patterns.insert("tooltip_text"); first_arg_patterns.insert("set_text"); - first_arg_patterns.insert("set_tooltip"); + first_arg_patterns.insert("set_tooltip_text"); first_arg_patterns.insert("set_placeholder"); first_arg_patterns.insert("add_tab"); first_arg_patterns.insert("add_check_item"); diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index cf2d6ae9f8..10babad378 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -683,7 +683,7 @@ bool GDScript::_update_exports(bool *r_err, bool p_recursive_call, PlaceHolderSc if (base.is_empty() || base.is_relative_path()) { ERR_PRINT(("Could not resolve relative path for parent class: " + path).utf8().get_data()); } else { - path = base.get_base_dir().plus_file(path); + path = base.get_base_dir().path_join(path); } } } else if (c->extends.size() != 0) { @@ -2204,7 +2204,7 @@ String GDScriptLanguage::get_global_class_name(const String &p_path, String *r_b if (c->icon_path.is_empty() || c->icon_path.is_absolute_path()) { *r_icon_path = c->icon_path; } else if (c->icon_path.is_relative_path()) { - *r_icon_path = p_path.get_base_dir().plus_file(c->icon_path).simplify_path(); + *r_icon_path = p_path.get_base_dir().path_join(c->icon_path).simplify_path(); } } if (r_base_type) { @@ -2232,7 +2232,7 @@ String GDScriptLanguage::get_global_class_name(const String &p_path, String *r_b } String subpath = subclass->extends_path; if (subpath.is_relative_path()) { - subpath = path.get_base_dir().plus_file(subpath).simplify_path(); + subpath = path.get_base_dir().path_join(subpath).simplify_path(); } if (OK != subparser.parse(subsource, subpath, false)) { diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp index a07d4855f3..e37ac1dc3b 100644 --- a/modules/gdscript/gdscript_analyzer.cpp +++ b/modules/gdscript/gdscript_analyzer.cpp @@ -260,7 +260,7 @@ Error GDScriptAnalyzer::resolve_inheritance(GDScriptParser::ClassNode *p_class, if (!p_class->extends_path.is_empty()) { if (p_class->extends_path.is_relative_path()) { - p_class->extends_path = class_type.script_path.get_base_dir().plus_file(p_class->extends_path).simplify_path(); + p_class->extends_path = class_type.script_path.get_base_dir().path_join(p_class->extends_path).simplify_path(); } Ref<GDScriptParserRef> parser = get_parser_for(p_class->extends_path); if (parser.is_null()) { @@ -2726,6 +2726,7 @@ void GDScriptAnalyzer::reduce_identifier_from_base(GDScriptParser::IdentifierNod result.builtin_type = Variant::INT; result.native_type = base.native_type; result.enum_type = base.enum_type; + result.enum_values = base.enum_values; p_identifier->set_datatype(result); return; } else { @@ -3185,7 +3186,7 @@ void GDScriptAnalyzer::reduce_preload(GDScriptParser::PreloadNode *p_preload) { p_preload->resolved_path = p_preload->path->reduced_value; // TODO: Save this as script dependency. if (p_preload->resolved_path.is_relative_path()) { - p_preload->resolved_path = parser->script_path.get_base_dir().plus_file(p_preload->resolved_path); + p_preload->resolved_path = parser->script_path.get_base_dir().path_join(p_preload->resolved_path); } p_preload->resolved_path = p_preload->resolved_path.simplify_path(); if (!FileAccess::exists(p_preload->resolved_path)) { diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp index c18412bc63..4c908166df 100644 --- a/modules/gdscript/gdscript_editor.cpp +++ b/modules/gdscript/gdscript_editor.cpp @@ -2031,8 +2031,13 @@ static bool _guess_identifier_type(GDScriptParser::CompletionContext &p_context, r_type.type.kind = GDScriptParser::DataType::NATIVE; r_type.type.native_type = p_identifier; r_type.type.is_constant = true; - r_type.type.is_meta_type = !Engine::get_singleton()->has_singleton(p_identifier); - r_type.value = Variant(); + if (Engine::get_singleton()->has_singleton(p_identifier)) { + r_type.type.is_meta_type = false; + r_type.value = Engine::get_singleton()->get_singleton_object(p_identifier); + } else { + r_type.type.is_meta_type = true; + r_type.value = Variant(); + } } return false; diff --git a/modules/gdscript/language_server/gdscript_workspace.cpp b/modules/gdscript/language_server/gdscript_workspace.cpp index 44b60369ab..16461b0a6c 100644 --- a/modules/gdscript/language_server/gdscript_workspace.cpp +++ b/modules/gdscript/language_server/gdscript_workspace.cpp @@ -228,9 +228,9 @@ void GDScriptWorkspace::list_script_files(const String &p_root_dir, List<String> String file_name = dir->get_next(); while (file_name.length()) { if (dir->current_is_dir() && file_name != "." && file_name != ".." && file_name != "./") { - list_script_files(p_root_dir.plus_file(file_name), r_files); + list_script_files(p_root_dir.path_join(file_name), r_files); } else if (file_name.ends_with(".gd")) { - String script_file = p_root_dir.plus_file(file_name); + String script_file = p_root_dir.path_join(file_name); r_files.push_back(script_file); } file_name = dir->get_next(); @@ -499,9 +499,9 @@ Error GDScriptWorkspace::parse_local_script(const String &p_path) { } String GDScriptWorkspace::get_file_path(const String &p_uri) const { - String path = p_uri; - path = path.uri_decode(); - path = path.replacen(root_uri + "/", "res://"); + String path = p_uri.uri_decode(); + String base_uri = root_uri.uri_decode(); + path = path.replacen(base_uri + "/", "res://"); return path; } diff --git a/modules/gdscript/register_types.cpp b/modules/gdscript/register_types.cpp index 059ca703ab..19a8b59c6f 100644 --- a/modules/gdscript/register_types.cpp +++ b/modules/gdscript/register_types.cpp @@ -88,6 +88,8 @@ public: // TODO: Re-add compiled GDScript on export. return; } + + virtual String _get_name() const override { return "GDScript"; } }; static void _editor_init() { diff --git a/modules/gdscript/tests/gdscript_test_runner.cpp b/modules/gdscript/tests/gdscript_test_runner.cpp index e3b956369d..6c346acb7e 100644 --- a/modules/gdscript/tests/gdscript_test_runner.cpp +++ b/modules/gdscript/tests/gdscript_test_runner.cpp @@ -247,7 +247,7 @@ bool GDScriptTestRunner::make_tests_for_dir(const String &p_dir) { next = dir->get_next(); continue; } - if (!make_tests_for_dir(current_dir.plus_file(next))) { + if (!make_tests_for_dir(current_dir.path_join(next))) { return false; } } else { @@ -255,7 +255,7 @@ bool GDScriptTestRunner::make_tests_for_dir(const String &p_dir) { #ifndef DEBUG_ENABLED // On release builds, skip tests marked as debug only. Error open_err = OK; - Ref<FileAccess> script_file(FileAccess::open(current_dir.plus_file(next), FileAccess::READ, &open_err)); + Ref<FileAccess> script_file(FileAccess::open(current_dir.path_join(next), FileAccess::READ, &open_err)); if (open_err != OK) { ERR_PRINT(vformat(R"(Couldn't open test file "%s".)", next)); next = dir->get_next(); @@ -272,7 +272,7 @@ bool GDScriptTestRunner::make_tests_for_dir(const String &p_dir) { if (!is_generating && !dir->file_exists(out_file)) { ERR_FAIL_V_MSG(false, "Could not find output file for " + next); } - GDScriptTest test(current_dir.plus_file(next), current_dir.plus_file(out_file), source_dir); + GDScriptTest test(current_dir.path_join(next), current_dir.path_join(out_file), source_dir); tests.push_back(test); } } diff --git a/modules/gdscript/tests/scripts/analyzer/features/property_inline.out b/modules/gdscript/tests/scripts/analyzer/features/property_inline.out index 5482592e90..63e59398ae 100644 --- a/modules/gdscript/tests/scripts/analyzer/features/property_inline.out +++ b/modules/gdscript/tests/scripts/analyzer/features/property_inline.out @@ -1,5 +1,5 @@ GDTEST_OK -null +<null> 0 1 2 diff --git a/modules/gdscript/tests/scripts/parser/features/function_many_parameters.out b/modules/gdscript/tests/scripts/parser/features/function_many_parameters.out index 3a979227d4..80df7a3d4c 100644 --- a/modules/gdscript/tests/scripts/parser/features/function_many_parameters.out +++ b/modules/gdscript/tests/scripts/parser/features/function_many_parameters.out @@ -1,2 +1,2 @@ GDTEST_OK -123456789101112131415161718192212223242526272829303132333435363738394041424344454647falsetruenull +123456789101112131415161718192212223242526272829303132333435363738394041424344454647falsetrue<null> diff --git a/modules/gdscript/tests/scripts/parser/features/str_preserves_case.out b/modules/gdscript/tests/scripts/parser/features/str_preserves_case.out index abba38e87c..867f45f0ac 100644 --- a/modules/gdscript/tests/scripts/parser/features/str_preserves_case.out +++ b/modules/gdscript/tests/scripts/parser/features/str_preserves_case.out @@ -1,4 +1,4 @@ GDTEST_OK -null +<null> true false diff --git a/modules/gltf/doc_classes/GLTFCamera.xml b/modules/gltf/doc_classes/GLTFCamera.xml index b90abd105d..49efaa1564 100644 --- a/modules/gltf/doc_classes/GLTFCamera.xml +++ b/modules/gltf/doc_classes/GLTFCamera.xml @@ -10,6 +10,34 @@ <link title="GLTF camera detailed specification">https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#reference-camera</link> <link title="GLTF camera spec and example file">https://github.com/KhronosGroup/glTF-Tutorials/blob/master/gltfTutorial/gltfTutorial_015_SimpleCameras.md</link> </tutorials> + <methods> + <method name="from_dictionary" qualifiers="static"> + <return type="GLTFCamera" /> + <param index="0" name="dictionary" type="Dictionary" /> + <description> + Creates a new GLTFCamera instance by parsing the given [Dictionary]. + </description> + </method> + <method name="from_node" qualifiers="static"> + <return type="GLTFCamera" /> + <param index="0" name="camera_node" type="Camera3D" /> + <description> + Create a new GLTFCamera instance from the given Godot [Camera3D] node. + </description> + </method> + <method name="to_dictionary" qualifiers="const"> + <return type="Dictionary" /> + <description> + Serializes this GLTFCamera instance into a [Dictionary]. + </description> + </method> + <method name="to_node" qualifiers="const"> + <return type="Camera3D" /> + <description> + Converts this GLTFCamera instance into a Godot [Camera3D] node. + </description> + </method> + </methods> <members> <member name="depth_far" type="float" setter="set_depth_far" getter="get_depth_far" default="4000.0"> The distance to the far culling boundary for this camera relative to its local Z axis, in meters. This maps to GLTF's [code]zfar[/code] property. diff --git a/modules/gltf/doc_classes/GLTFLight.xml b/modules/gltf/doc_classes/GLTFLight.xml index db2dfb487a..7fd59e14bc 100644 --- a/modules/gltf/doc_classes/GLTFLight.xml +++ b/modules/gltf/doc_classes/GLTFLight.xml @@ -9,6 +9,34 @@ <tutorials> <link title="KHR_lights_punctual GLTF extension spec">https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_lights_punctual</link> </tutorials> + <methods> + <method name="from_dictionary" qualifiers="static"> + <return type="GLTFLight" /> + <param index="0" name="dictionary" type="Dictionary" /> + <description> + Creates a new GLTFLight instance by parsing the given [Dictionary]. + </description> + </method> + <method name="from_node" qualifiers="static"> + <return type="GLTFLight" /> + <param index="0" name="light_node" type="Light3D" /> + <description> + Create a new GLTFLight instance from the given Godot [Light3D] node. + </description> + </method> + <method name="to_dictionary" qualifiers="const"> + <return type="Dictionary" /> + <description> + Serializes this GLTFLight instance into a [Dictionary]. + </description> + </method> + <method name="to_node" qualifiers="const"> + <return type="Light3D" /> + <description> + Converts this GLTFLight instance into a Godot [Light3D] node. + </description> + </method> + </methods> <members> <member name="color" type="Color" setter="set_color" getter="get_color" default="Color(1, 1, 1, 1)"> The [Color] of the light. Defaults to white. A black color causes the light to have no effect. diff --git a/modules/gltf/editor/editor_scene_importer_blend.cpp b/modules/gltf/editor/editor_scene_importer_blend.cpp index 8002c185c7..ab52761e17 100644 --- a/modules/gltf/editor/editor_scene_importer_blend.cpp +++ b/modules/gltf/editor/editor_scene_importer_blend.cpp @@ -64,7 +64,7 @@ Node *EditorSceneFormatImporterBlend::import_scene(const String &p_path, uint32_ // Escape paths to be valid Python strings to embed in the script. const String source_global = ProjectSettings::get_singleton()->globalize_path(p_path).c_escape(); - const String sink = ProjectSettings::get_singleton()->get_imported_files_path().plus_file( + const String sink = ProjectSettings::get_singleton()->get_imported_files_path().path_join( vformat("%s-%s.gltf", p_path.get_file().get_basename(), p_path.md5_text())); const String sink_global = ProjectSettings::get_singleton()->globalize_path(sink).c_escape(); @@ -193,9 +193,9 @@ Node *EditorSceneFormatImporterBlend::import_scene(const String &p_path, uint32_ String blender_path = EDITOR_GET("filesystem/import/blender/blender3_path"); #ifdef WINDOWS_ENABLED - blender_path = blender_path.plus_file("blender.exe"); + blender_path = blender_path.path_join("blender.exe"); #else - blender_path = blender_path.plus_file("blender"); + blender_path = blender_path.path_join("blender"); #endif List<String> args; @@ -287,14 +287,14 @@ void EditorSceneFormatImporterBlend::get_import_options(const String &p_path, Li static bool _test_blender_path(const String &p_path, String *r_err = nullptr) { String path = p_path; #ifdef WINDOWS_ENABLED - path = path.plus_file("blender.exe"); + path = path.path_join("blender.exe"); #else - path = path.plus_file("blender"); + path = path.path_join("blender"); #endif #if defined(MACOS_ENABLED) if (!FileAccess::exists(path)) { - path = path.plus_file("Blender"); + path = path.path_join("Blender"); } #endif @@ -451,7 +451,7 @@ bool EditorFileSystemImportFormatSupportQueryBlend::query() { configure_blender_dialog->set_ok_button_text(TTR("Confirm Path")); configure_blender_dialog->set_cancel_button_text(TTR("Disable '.blend' Import")); - configure_blender_dialog->get_cancel_button()->set_tooltip(TTR("Disables Blender '.blend' files import for this project. Can be re-enabled in Project Settings.")); + configure_blender_dialog->get_cancel_button()->set_tooltip_text(TTR("Disables Blender '.blend' files import for this project. Can be re-enabled in Project Settings.")); configure_blender_dialog->connect("confirmed", callable_mp(this, &EditorFileSystemImportFormatSupportQueryBlend::_path_confirmed)); browse_dialog = memnew(EditorFileDialog); @@ -485,7 +485,7 @@ bool EditorFileSystemImportFormatSupportQueryBlend::query() { bool found = false; for (const String &path : mdfind_paths) { - found = _autodetect_path(path.plus_file("Contents/MacOS")); + found = _autodetect_path(path.path_join("Contents/MacOS")); if (found) { break; } diff --git a/modules/gltf/editor/editor_scene_importer_fbx.cpp b/modules/gltf/editor/editor_scene_importer_fbx.cpp index faad2d315d..017a44cccf 100644 --- a/modules/gltf/editor/editor_scene_importer_fbx.cpp +++ b/modules/gltf/editor/editor_scene_importer_fbx.cpp @@ -57,7 +57,7 @@ Node *EditorSceneFormatImporterFBX::import_scene(const String &p_path, uint32_t // enclosed in double quotes by OS::execute(), so we only need to escape those. // `c_escape_multiline()` seems to do this (escapes `\` and `"` only). const String source_global = ProjectSettings::get_singleton()->globalize_path(p_path).c_escape_multiline(); - const String sink = ProjectSettings::get_singleton()->get_imported_files_path().plus_file( + const String sink = ProjectSettings::get_singleton()->get_imported_files_path().path_join( vformat("%s-%s.glb", p_path.get_file().get_basename(), p_path.md5_text())); const String sink_global = ProjectSettings::get_singleton()->globalize_path(sink).c_escape_multiline(); diff --git a/modules/gltf/extensions/gltf_light.cpp b/modules/gltf/extensions/gltf_light.cpp index af21a4e804..ab5a15c671 100644 --- a/modules/gltf/extensions/gltf_light.cpp +++ b/modules/gltf/extensions/gltf_light.cpp @@ -31,6 +31,12 @@ #include "gltf_light.h" void GLTFLight::_bind_methods() { + ClassDB::bind_static_method("GLTFLight", D_METHOD("from_node", "light_node"), &GLTFLight::from_node); + ClassDB::bind_method(D_METHOD("to_node"), &GLTFLight::to_node); + + ClassDB::bind_static_method("GLTFLight", D_METHOD("from_dictionary", "dictionary"), &GLTFLight::from_dictionary); + ClassDB::bind_method(D_METHOD("to_dictionary"), &GLTFLight::to_dictionary); + ClassDB::bind_method(D_METHOD("get_color"), &GLTFLight::get_color); ClassDB::bind_method(D_METHOD("set_color", "color"), &GLTFLight::set_color); ClassDB::bind_method(D_METHOD("get_intensity"), &GLTFLight::get_intensity); @@ -99,3 +105,116 @@ float GLTFLight::get_outer_cone_angle() { void GLTFLight::set_outer_cone_angle(float p_outer_cone_angle) { outer_cone_angle = p_outer_cone_angle; } + +Ref<GLTFLight> GLTFLight::from_node(const Light3D *p_light) { + Ref<GLTFLight> l; + l.instantiate(); + l->color = p_light->get_color(); + if (cast_to<DirectionalLight3D>(p_light)) { + l->light_type = "directional"; + const DirectionalLight3D *light = cast_to<const DirectionalLight3D>(p_light); + l->intensity = light->get_param(DirectionalLight3D::PARAM_ENERGY); + l->range = FLT_MAX; // Range for directional lights is infinite in Godot. + } else if (cast_to<const OmniLight3D>(p_light)) { + l->light_type = "point"; + const OmniLight3D *light = cast_to<const OmniLight3D>(p_light); + l->range = light->get_param(OmniLight3D::PARAM_RANGE); + l->intensity = light->get_param(OmniLight3D::PARAM_ENERGY); + } else if (cast_to<const SpotLight3D>(p_light)) { + l->light_type = "spot"; + const SpotLight3D *light = cast_to<const SpotLight3D>(p_light); + l->range = light->get_param(SpotLight3D::PARAM_RANGE); + l->intensity = light->get_param(SpotLight3D::PARAM_ENERGY); + l->outer_cone_angle = Math::deg_to_rad(light->get_param(SpotLight3D::PARAM_SPOT_ANGLE)); + // This equation is the inverse of the import equation (which has a desmos link). + float angle_ratio = 1 - (0.2 / (0.1 + light->get_param(SpotLight3D::PARAM_SPOT_ATTENUATION))); + angle_ratio = MAX(0, angle_ratio); + l->inner_cone_angle = l->outer_cone_angle * angle_ratio; + } + return l; +} + +Light3D *GLTFLight::to_node() const { + if (light_type == "directional") { + DirectionalLight3D *light = memnew(DirectionalLight3D); + light->set_param(Light3D::PARAM_ENERGY, intensity); + light->set_color(color); + return light; + } + const float range = CLAMP(this->range, 0, 4096); + if (light_type == "point") { + OmniLight3D *light = memnew(OmniLight3D); + light->set_param(OmniLight3D::PARAM_ENERGY, intensity); + light->set_param(OmniLight3D::PARAM_RANGE, range); + light->set_color(color); + return light; + } + if (light_type == "spot") { + SpotLight3D *light = memnew(SpotLight3D); + light->set_param(SpotLight3D::PARAM_ENERGY, intensity); + light->set_param(SpotLight3D::PARAM_RANGE, range); + light->set_param(SpotLight3D::PARAM_SPOT_ANGLE, Math::rad_to_deg(outer_cone_angle)); + light->set_color(color); + // Line of best fit derived from guessing, see https://www.desmos.com/calculator/biiflubp8b + // The points in desmos are not exact, except for (1, infinity). + float angle_ratio = inner_cone_angle / outer_cone_angle; + float angle_attenuation = 0.2 / (1 - angle_ratio) - 0.1; + light->set_param(SpotLight3D::PARAM_SPOT_ATTENUATION, angle_attenuation); + return light; + } + return memnew(Light3D); +} + +Ref<GLTFLight> GLTFLight::from_dictionary(const Dictionary p_dictionary) { + ERR_FAIL_COND_V_MSG(!p_dictionary.has("type"), Ref<GLTFLight>(), "Failed to parse GLTF light, missing required field 'type'."); + Ref<GLTFLight> light; + light.instantiate(); + const String &type = p_dictionary["type"]; + light->light_type = type; + + if (p_dictionary.has("color")) { + const Array &arr = p_dictionary["color"]; + if (arr.size() == 3) { + light->color = Color(arr[0], arr[1], arr[2]).linear_to_srgb(); + } else { + ERR_PRINT("Error parsing GLTF light: The color must have exactly 3 numbers."); + } + } + if (p_dictionary.has("intensity")) { + light->intensity = p_dictionary["intensity"]; + } + if (p_dictionary.has("range")) { + light->range = p_dictionary["range"]; + } + if (type == "spot") { + const Dictionary &spot = p_dictionary["spot"]; + light->inner_cone_angle = spot["innerConeAngle"]; + light->outer_cone_angle = spot["outerConeAngle"]; + if (light->inner_cone_angle >= light->outer_cone_angle) { + ERR_PRINT("Error parsing GLTF light: The inner angle must be smaller than the outer angle."); + } + } else if (type != "point" && type != "directional") { + ERR_PRINT("Error parsing GLTF light: Light type '" + type + "' is unknown."); + } + return light; +} + +Dictionary GLTFLight::to_dictionary() const { + Dictionary d; + Array color_array; + color_array.resize(3); + color_array[0] = color.r; + color_array[1] = color.g; + color_array[2] = color.b; + d["color"] = color_array; + d["type"] = light_type; + if (light_type == "spot") { + Dictionary spot_dict; + spot_dict["innerConeAngle"] = inner_cone_angle; + spot_dict["outerConeAngle"] = outer_cone_angle; + d["spot"] = spot_dict; + } + d["intensity"] = intensity; + d["range"] = range; + return d; +} diff --git a/modules/gltf/extensions/gltf_light.h b/modules/gltf/extensions/gltf_light.h index f0765a1bbc..04980e144c 100644 --- a/modules/gltf/extensions/gltf_light.h +++ b/modules/gltf/extensions/gltf_light.h @@ -70,6 +70,12 @@ public: float get_outer_cone_angle(); void set_outer_cone_angle(float p_outer_cone_angle); + + static Ref<GLTFLight> from_node(const Light3D *p_light); + Light3D *to_node() const; + + static Ref<GLTFLight> from_dictionary(const Dictionary p_dictionary); + Dictionary to_dictionary() const; }; #endif // GLTF_LIGHT_H diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp index 87ba1d9869..0ed212e21f 100644 --- a/modules/gltf/gltf_document.cpp +++ b/modules/gltf/gltf_document.cpp @@ -786,7 +786,7 @@ Error GLTFDocument::_parse_buffers(Ref<GLTFState> state, const String &p_base_pa } else { // Relative path to an external image file. ERR_FAIL_COND_V(p_base_path.is_empty(), ERR_INVALID_PARAMETER); uri = uri.uri_decode(); - uri = p_base_path.plus_file(uri).replace("\\", "/"); // Fix for Windows. + uri = p_base_path.path_join(uri).replace("\\", "/"); // Fix for Windows. buffer_data = FileAccess::get_file_as_array(uri); ERR_FAIL_COND_V_MSG(buffer.size() == 0, ERR_PARSE_ERROR, "glTF: Couldn't load binary file as an array: " + uri); } @@ -3039,8 +3039,8 @@ Error GLTFDocument::_serialize_images(Ref<GLTFState> state, const String &p_path if (!da->dir_exists(new_texture_dir)) { da->make_dir(new_texture_dir); } - image->save_png(new_texture_dir.plus_file(name)); - d["uri"] = texture_dir.plus_file(name).uri_encode(); + image->save_png(new_texture_dir.path_join(name)); + d["uri"] = texture_dir.path_join(name).uri_encode(); } images.push_back(d); } @@ -3118,7 +3118,7 @@ Error GLTFDocument::_parse_images(Ref<GLTFState> state, const String &p_base_pat } else { // Relative path to an external image file. ERR_FAIL_COND_V(p_base_path.is_empty(), ERR_INVALID_PARAMETER); uri = uri.uri_decode(); - uri = p_base_path.plus_file(uri).replace("\\", "/"); // Fix for Windows. + uri = p_base_path.path_join(uri).replace("\\", "/"); // Fix for Windows. // ResourceLoader will rely on the file extension to use the relevant loader. // The spec says that if mimeType is defined, it should take precedence (e.g. // there could be a `.png` image which is actually JPEG), but there's no easy @@ -4534,28 +4534,7 @@ Error GLTFDocument::_serialize_lights(Ref<GLTFState> state) { } Array lights; for (GLTFLightIndex i = 0; i < state->lights.size(); i++) { - Dictionary d; - Ref<GLTFLight> light = state->lights[i]; - Array color; - color.resize(3); - color[0] = light->color.r; - color[1] = light->color.g; - color[2] = light->color.b; - d["color"] = color; - d["type"] = light->light_type; - if (light->light_type == "spot") { - Dictionary s; - float inner_cone_angle = light->inner_cone_angle; - s["innerConeAngle"] = inner_cone_angle; - float outer_cone_angle = light->outer_cone_angle; - s["outerConeAngle"] = outer_cone_angle; - d["spot"] = s; - } - float intensity = light->intensity; - d["intensity"] = intensity; - float range = light->range; - d["range"] = range; - lights.push_back(d); + lights.push_back(state->lights[i]->to_dictionary()); } Dictionary extensions; @@ -4577,27 +4556,7 @@ Error GLTFDocument::_serialize_cameras(Ref<GLTFState> state) { Array cameras; cameras.resize(state->cameras.size()); for (GLTFCameraIndex i = 0; i < state->cameras.size(); i++) { - Dictionary d; - - Ref<GLTFCamera> camera = state->cameras[i]; - - if (camera->get_perspective()) { - Dictionary persp; - persp["yfov"] = camera->get_fov(); - persp["zfar"] = camera->get_depth_far(); - persp["znear"] = camera->get_depth_near(); - d["perspective"] = persp; - d["type"] = "perspective"; - } else { - Dictionary ortho; - ortho["ymag"] = camera->get_size_mag(); - ortho["xmag"] = camera->get_size_mag(); - ortho["zfar"] = camera->get_depth_far(); - ortho["znear"] = camera->get_depth_near(); - d["orthographic"] = ortho; - d["type"] = "orthographic"; - } - cameras[i] = d; + cameras[i] = state->cameras[i]->to_dictionary(); } if (!state->cameras.size()) { @@ -4627,35 +4586,10 @@ Error GLTFDocument::_parse_lights(Ref<GLTFState> state) { const Array &lights = lights_punctual["lights"]; for (GLTFLightIndex light_i = 0; light_i < lights.size(); light_i++) { - const Dictionary &d = lights[light_i]; - - Ref<GLTFLight> light; - light.instantiate(); - ERR_FAIL_COND_V(!d.has("type"), ERR_PARSE_ERROR); - const String &type = d["type"]; - light->light_type = type; - - if (d.has("color")) { - const Array &arr = d["color"]; - ERR_FAIL_COND_V(arr.size() != 3, ERR_PARSE_ERROR); - const Color c = Color(arr[0], arr[1], arr[2]).linear_to_srgb(); - light->color = c; - } - if (d.has("intensity")) { - light->intensity = d["intensity"]; + Ref<GLTFLight> light = GLTFLight::from_dictionary(lights[light_i]); + if (light.is_null()) { + return Error::ERR_PARSE_ERROR; } - if (d.has("range")) { - light->range = d["range"]; - } - if (type == "spot") { - const Dictionary &spot = d["spot"]; - light->inner_cone_angle = spot["innerConeAngle"]; - light->outer_cone_angle = spot["outerConeAngle"]; - ERR_CONTINUE_MSG(light->inner_cone_angle >= light->outer_cone_angle, "The inner angle must be smaller than the outer angle."); - } else if (type != "point" && type != "directional") { - ERR_CONTINUE_MSG(true, "Light type is unknown."); - } - state->lights.push_back(light); } @@ -4672,35 +4606,7 @@ Error GLTFDocument::_parse_cameras(Ref<GLTFState> state) { const Array cameras = state->json["cameras"]; for (GLTFCameraIndex i = 0; i < cameras.size(); i++) { - const Dictionary &d = cameras[i]; - - Ref<GLTFCamera> camera; - camera.instantiate(); - ERR_FAIL_COND_V(!d.has("type"), ERR_PARSE_ERROR); - const String &type = d["type"]; - if (type == "perspective") { - camera->set_perspective(true); - if (d.has("perspective")) { - const Dictionary &persp = d["perspective"]; - camera->set_fov(persp["yfov"]); - if (persp.has("zfar")) { - camera->set_depth_far(persp["zfar"]); - } - camera->set_depth_near(persp["znear"]); - } - } else if (type == "orthographic") { - camera->set_perspective(false); - if (d.has("orthographic")) { - const Dictionary &ortho = d["orthographic"]; - camera->set_size_mag(ortho["ymag"]); - camera->set_depth_far(ortho["zfar"]); - camera->set_depth_near(ortho["znear"]); - } - } else { - ERR_FAIL_V_MSG(ERR_PARSE_ERROR, "Camera3D should be in 'orthographic' or 'perspective'"); - } - - state->cameras.push_back(camera); + state->cameras.push_back(GLTFCamera::from_dictionary(cameras[i])); } print_verbose("glTF: Total cameras: " + itos(state->cameras.size())); @@ -5148,45 +5054,7 @@ Node3D *GLTFDocument::_generate_light(Ref<GLTFState> state, const GLTFNodeIndex print_verbose("glTF: Creating light for: " + gltf_node->get_name()); Ref<GLTFLight> l = state->lights[gltf_node->light]; - - float intensity = l->intensity; - if (intensity > 10) { - // GLTF spec has the default around 1, but Blender defaults lights to 100. - // The only sane way to handle this is to check where it came from and - // handle it accordingly. If it's over 10, it probably came from Blender. - intensity /= 100; - } - - if (l->light_type == "directional") { - DirectionalLight3D *light = memnew(DirectionalLight3D); - light->set_param(Light3D::PARAM_ENERGY, intensity); - light->set_color(l->color); - return light; - } - - const float range = CLAMP(l->range, 0, 4096); - if (l->light_type == "point") { - OmniLight3D *light = memnew(OmniLight3D); - light->set_param(OmniLight3D::PARAM_ENERGY, intensity); - light->set_param(OmniLight3D::PARAM_RANGE, range); - light->set_color(l->color); - return light; - } - if (l->light_type == "spot") { - SpotLight3D *light = memnew(SpotLight3D); - light->set_param(SpotLight3D::PARAM_ENERGY, intensity); - light->set_param(SpotLight3D::PARAM_RANGE, range); - light->set_param(SpotLight3D::PARAM_SPOT_ANGLE, Math::rad_to_deg(l->outer_cone_angle)); - light->set_color(l->color); - - // Line of best fit derived from guessing, see https://www.desmos.com/calculator/biiflubp8b - // The points in desmos are not exact, except for (1, infinity). - float angle_ratio = l->inner_cone_angle / l->outer_cone_angle; - float angle_attenuation = 0.2 / (1 - angle_ratio) - 0.1; - light->set_param(SpotLight3D::PARAM_SPOT_ATTENUATION, angle_attenuation); - return light; - } - return memnew(Node3D); + return l->to_node(); } Camera3D *GLTFDocument::_generate_camera(Ref<GLTFState> state, const GLTFNodeIndex node_index) { @@ -5194,32 +5062,16 @@ Camera3D *GLTFDocument::_generate_camera(Ref<GLTFState> state, const GLTFNodeInd ERR_FAIL_INDEX_V(gltf_node->camera, state->cameras.size(), nullptr); - Camera3D *camera = memnew(Camera3D); print_verbose("glTF: Creating camera for: " + gltf_node->get_name()); Ref<GLTFCamera> c = state->cameras[gltf_node->camera]; - camera->set_projection(c->get_perspective() ? Camera3D::PROJECTION_PERSPECTIVE : Camera3D::PROJECTION_ORTHOGONAL); - // GLTF spec (yfov) is in radians, Godot's camera (fov) is in degrees. - camera->set_fov(Math::rad_to_deg(c->get_fov())); - // GLTF spec (xmag and ymag) is a radius in meters, Godot's camera (size) is a diameter in meters. - camera->set_size(c->get_size_mag() * 2.0f); - camera->set_near(c->get_depth_near()); - camera->set_far(c->get_depth_far()); - return camera; + return c->to_node(); } GLTFCameraIndex GLTFDocument::_convert_camera(Ref<GLTFState> state, Camera3D *p_camera) { print_verbose("glTF: Converting camera: " + p_camera->get_name()); - Ref<GLTFCamera> c; - c.instantiate(); - c->set_perspective(p_camera->get_projection() == Camera3D::ProjectionType::PROJECTION_PERSPECTIVE); - // GLTF spec (yfov) is in radians, Godot's camera (fov) is in degrees. - c->set_fov(Math::deg_to_rad(p_camera->get_fov())); - // GLTF spec (xmag and ymag) is a radius in meters, Godot's camera (size) is a diameter in meters. - c->set_size_mag(p_camera->get_size() * 0.5f); - c->set_depth_far(p_camera->get_far()); - c->set_depth_near(p_camera->get_near()); + Ref<GLTFCamera> c = GLTFCamera::from_node(p_camera); GLTFCameraIndex camera_index = state->cameras.size(); state->cameras.push_back(c); return camera_index; @@ -5228,31 +5080,7 @@ GLTFCameraIndex GLTFDocument::_convert_camera(Ref<GLTFState> state, Camera3D *p_ GLTFLightIndex GLTFDocument::_convert_light(Ref<GLTFState> state, Light3D *p_light) { print_verbose("glTF: Converting light: " + p_light->get_name()); - Ref<GLTFLight> l; - l.instantiate(); - l->color = p_light->get_color(); - if (cast_to<DirectionalLight3D>(p_light)) { - l->light_type = "directional"; - DirectionalLight3D *light = cast_to<DirectionalLight3D>(p_light); - l->intensity = light->get_param(DirectionalLight3D::PARAM_ENERGY); - l->range = FLT_MAX; // Range for directional lights is infinite in Godot. - } else if (cast_to<OmniLight3D>(p_light)) { - l->light_type = "point"; - OmniLight3D *light = cast_to<OmniLight3D>(p_light); - l->range = light->get_param(OmniLight3D::PARAM_RANGE); - l->intensity = light->get_param(OmniLight3D::PARAM_ENERGY); - } else if (cast_to<SpotLight3D>(p_light)) { - l->light_type = "spot"; - SpotLight3D *light = cast_to<SpotLight3D>(p_light); - l->range = light->get_param(SpotLight3D::PARAM_RANGE); - l->intensity = light->get_param(SpotLight3D::PARAM_ENERGY); - l->outer_cone_angle = Math::deg_to_rad(light->get_param(SpotLight3D::PARAM_SPOT_ANGLE)); - - // This equation is the inverse of the import equation (which has a desmos link). - float angle_ratio = 1 - (0.2 / (0.1 + light->get_param(SpotLight3D::PARAM_SPOT_ATTENUATION))); - angle_ratio = MAX(0, angle_ratio); - l->inner_cone_angle = l->outer_cone_angle * angle_ratio; - } + Ref<GLTFLight> l = GLTFLight::from_node(p_light); GLTFLightIndex light_index = state->lights.size(); state->lights.push_back(l); diff --git a/modules/gltf/structures/gltf_camera.cpp b/modules/gltf/structures/gltf_camera.cpp index c492913ea7..5069f39c4b 100644 --- a/modules/gltf/structures/gltf_camera.cpp +++ b/modules/gltf/structures/gltf_camera.cpp @@ -31,6 +31,12 @@ #include "gltf_camera.h" void GLTFCamera::_bind_methods() { + ClassDB::bind_static_method("GLTFCamera", D_METHOD("from_node", "camera_node"), &GLTFCamera::from_node); + ClassDB::bind_method(D_METHOD("to_node"), &GLTFCamera::to_node); + + ClassDB::bind_static_method("GLTFCamera", D_METHOD("from_dictionary", "dictionary"), &GLTFCamera::from_dictionary); + ClassDB::bind_method(D_METHOD("to_dictionary"), &GLTFCamera::to_dictionary); + ClassDB::bind_method(D_METHOD("get_perspective"), &GLTFCamera::get_perspective); ClassDB::bind_method(D_METHOD("set_perspective", "perspective"), &GLTFCamera::set_perspective); ClassDB::bind_method(D_METHOD("get_fov"), &GLTFCamera::get_fov); @@ -48,3 +54,78 @@ void GLTFCamera::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "depth_far"), "set_depth_far", "get_depth_far"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "depth_near"), "set_depth_near", "get_depth_near"); } + +Ref<GLTFCamera> GLTFCamera::from_node(const Camera3D *p_camera) { + Ref<GLTFCamera> c; + c.instantiate(); + c->set_perspective(p_camera->get_projection() == Camera3D::ProjectionType::PROJECTION_PERSPECTIVE); + // GLTF spec (yfov) is in radians, Godot's camera (fov) is in degrees. + c->set_fov(Math::deg_to_rad(p_camera->get_fov())); + // GLTF spec (xmag and ymag) is a radius in meters, Godot's camera (size) is a diameter in meters. + c->set_size_mag(p_camera->get_size() * 0.5f); + c->set_depth_far(p_camera->get_far()); + c->set_depth_near(p_camera->get_near()); + return c; +} + +Camera3D *GLTFCamera::to_node() const { + Camera3D *camera = memnew(Camera3D); + camera->set_projection(perspective ? Camera3D::PROJECTION_PERSPECTIVE : Camera3D::PROJECTION_ORTHOGONAL); + // GLTF spec (yfov) is in radians, Godot's camera (fov) is in degrees. + camera->set_fov(Math::rad_to_deg(fov)); + // GLTF spec (xmag and ymag) is a radius in meters, Godot's camera (size) is a diameter in meters. + camera->set_size(size_mag * 2.0f); + camera->set_near(depth_near); + camera->set_far(depth_far); + return camera; +} + +Ref<GLTFCamera> GLTFCamera::from_dictionary(const Dictionary p_dictionary) { + ERR_FAIL_COND_V_MSG(!p_dictionary.has("type"), Ref<GLTFCamera>(), "Failed to parse GLTF camera, missing required field 'type'."); + Ref<GLTFCamera> camera; + camera.instantiate(); + const String &type = p_dictionary["type"]; + if (type == "perspective") { + camera->set_perspective(true); + if (p_dictionary.has("perspective")) { + const Dictionary &persp = p_dictionary["perspective"]; + camera->set_fov(persp["yfov"]); + if (persp.has("zfar")) { + camera->set_depth_far(persp["zfar"]); + } + camera->set_depth_near(persp["znear"]); + } + } else if (type == "orthographic") { + camera->set_perspective(false); + if (p_dictionary.has("orthographic")) { + const Dictionary &ortho = p_dictionary["orthographic"]; + camera->set_size_mag(ortho["ymag"]); + camera->set_depth_far(ortho["zfar"]); + camera->set_depth_near(ortho["znear"]); + } + } else { + ERR_PRINT("Error parsing GLTF camera: Camera type '" + type + "' is unknown, should be perspective or orthographic."); + } + return camera; +} + +Dictionary GLTFCamera::to_dictionary() const { + Dictionary d; + if (perspective) { + Dictionary persp; + persp["yfov"] = fov; + persp["zfar"] = depth_far; + persp["znear"] = depth_near; + d["perspective"] = persp; + d["type"] = "perspective"; + } else { + Dictionary ortho; + ortho["ymag"] = size_mag; + ortho["xmag"] = size_mag; + ortho["zfar"] = depth_far; + ortho["znear"] = depth_near; + d["orthographic"] = ortho; + d["type"] = "orthographic"; + } + return d; +} diff --git a/modules/gltf/structures/gltf_camera.h b/modules/gltf/structures/gltf_camera.h index 8e528c063f..50ae10e17a 100644 --- a/modules/gltf/structures/gltf_camera.h +++ b/modules/gltf/structures/gltf_camera.h @@ -63,6 +63,12 @@ public: void set_depth_far(real_t p_val) { depth_far = p_val; } real_t get_depth_near() const { return depth_near; } void set_depth_near(real_t p_val) { depth_near = p_val; } + + static Ref<GLTFCamera> from_node(const Camera3D *p_light); + Camera3D *to_node() const; + + static Ref<GLTFCamera> from_dictionary(const Dictionary p_dictionary); + Dictionary to_dictionary() const; }; #endif // GLTF_CAMERA_H diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp index f207d4a741..8486e2c58b 100644 --- a/modules/gridmap/grid_map.cpp +++ b/modules/gridmap/grid_map.cpp @@ -638,7 +638,9 @@ bool GridMap::_octant_update(const OctantKey &p_key) { NavigationServer3D::get_singleton()->region_set_navigation_layers(region, navigation_layers); NavigationServer3D::get_singleton()->region_set_navmesh(region, navmesh); NavigationServer3D::get_singleton()->region_set_transform(region, get_global_transform() * nm.xform); - NavigationServer3D::get_singleton()->region_set_map(region, get_world_3d()->get_navigation_map()); + if (is_inside_tree()) { + NavigationServer3D::get_singleton()->region_set_map(region, get_world_3d()->get_navigation_map()); + } nm.region = region; // add navigation debugmesh visual instances if debug is enabled @@ -661,6 +663,12 @@ bool GridMap::_octant_update(const OctantKey &p_key) { } } +#ifdef DEBUG_ENABLED + if (bake_navigation) { + _update_octant_navigation_debug_edge_connections_mesh(p_key); + } +#endif // DEBUG_ENABLED + //update multimeshes, only if not baked if (baked_meshes.size() == 0) { for (const KeyValue<int, List<Pair<Transform3D, IndexKey>>> &E : multimesh_items) { @@ -755,6 +763,19 @@ void GridMap::_octant_enter_world(const OctantKey &p_key) { } } } + +#ifdef DEBUG_ENABLED + if (bake_navigation) { + if (!g.navigation_debug_edge_connections_instance.is_valid()) { + g.navigation_debug_edge_connections_instance = RenderingServer::get_singleton()->instance_create(); + } + if (!g.navigation_debug_edge_connections_mesh.is_valid()) { + g.navigation_debug_edge_connections_mesh = Ref<ArrayMesh>(memnew(ArrayMesh)); + } + + _update_octant_navigation_debug_edge_connections_mesh(p_key); + } +#endif // DEBUG_ENABLED } } @@ -782,6 +803,18 @@ void GridMap::_octant_exit_world(const OctantKey &p_key) { F.value.navmesh_debug_instance = RID(); } } + +#ifdef DEBUG_ENABLED + if (bake_navigation) { + if (g.navigation_debug_edge_connections_instance.is_valid()) { + RenderingServer::get_singleton()->free(g.navigation_debug_edge_connections_instance); + g.navigation_debug_edge_connections_instance = RID(); + } + if (g.navigation_debug_edge_connections_mesh.is_valid()) { + RenderingServer::get_singleton()->free(g.navigation_debug_edge_connections_mesh->get_rid()); + } + } +#endif // DEBUG_ENABLED } void GridMap::_octant_clean_up(const OctantKey &p_key) { @@ -808,6 +841,18 @@ void GridMap::_octant_clean_up(const OctantKey &p_key) { } g.navmesh_ids.clear(); +#ifdef DEBUG_ENABLED + if (bake_navigation) { + if (g.navigation_debug_edge_connections_instance.is_valid()) { + RenderingServer::get_singleton()->free(g.navigation_debug_edge_connections_instance); + g.navigation_debug_edge_connections_instance = RID(); + } + if (g.navigation_debug_edge_connections_mesh.is_valid()) { + RenderingServer::get_singleton()->free(g.navigation_debug_edge_connections_mesh->get_rid()); + } + } +#endif // DEBUG_ENABLED + //erase multimeshes for (int i = 0; i < g.multimesh_instances.size(); i++) { @@ -832,6 +877,14 @@ void GridMap::_notification(int p_what) { } } break; +#ifdef DEBUG_ENABLED + case NOTIFICATION_ENTER_TREE: { + if (bake_navigation && NavigationServer3D::get_singleton()->get_debug_enabled()) { + _update_navigation_debug_edge_connections(); + } + } break; +#endif // DEBUG_ENABLED + case NOTIFICATION_TRANSFORM_CHANGED: { Transform3D new_xform = get_global_transform(); if (new_xform == last_transform) { @@ -1231,12 +1284,136 @@ RID GridMap::get_bake_mesh_instance(int p_idx) { GridMap::GridMap() { set_notify_transform(true); +#ifdef DEBUG_ENABLED + NavigationServer3D::get_singleton_mut()->connect("map_changed", callable_mp(this, &GridMap::_navigation_map_changed)); + NavigationServer3D::get_singleton_mut()->connect("navigation_debug_changed", callable_mp(this, &GridMap::_update_navigation_debug_edge_connections)); +#endif // DEBUG_ENABLED +} + +#ifdef DEBUG_ENABLED +void GridMap::_update_navigation_debug_edge_connections() { + if (bake_navigation) { + for (const KeyValue<OctantKey, Octant *> &E : octant_map) { + _update_octant_navigation_debug_edge_connections_mesh(E.key); + } + } } +void GridMap::_navigation_map_changed(RID p_map) { + if (bake_navigation && is_inside_tree() && p_map == get_world_3d()->get_navigation_map()) { + _update_navigation_debug_edge_connections(); + } +} +#endif // DEBUG_ENABLED + GridMap::~GridMap() { if (!mesh_library.is_null()) { mesh_library->unregister_owner(this); } clear(); +#ifdef DEBUG_ENABLED + NavigationServer3D::get_singleton_mut()->disconnect("map_changed", callable_mp(this, &GridMap::_navigation_map_changed)); + NavigationServer3D::get_singleton_mut()->disconnect("navigation_debug_changed", callable_mp(this, &GridMap::_update_navigation_debug_edge_connections)); +#endif // DEBUG_ENABLED +} + +#ifdef DEBUG_ENABLED +void GridMap::_update_octant_navigation_debug_edge_connections_mesh(const OctantKey &p_key) { + ERR_FAIL_COND(!octant_map.has(p_key)); + Octant &g = *octant_map[p_key]; + + if (!NavigationServer3D::get_singleton()->get_debug_enabled()) { + if (g.navigation_debug_edge_connections_instance.is_valid()) { + RS::get_singleton()->instance_set_visible(g.navigation_debug_edge_connections_instance, false); + } + return; + } + + if (!is_inside_tree()) { + return; + } + + if (!bake_navigation) { + if (g.navigation_debug_edge_connections_instance.is_valid()) { + RS::get_singleton()->instance_set_visible(g.navigation_debug_edge_connections_instance, false); + } + return; + } + + if (!g.navigation_debug_edge_connections_instance.is_valid()) { + g.navigation_debug_edge_connections_instance = RenderingServer::get_singleton()->instance_create(); + } + + if (!g.navigation_debug_edge_connections_mesh.is_valid()) { + g.navigation_debug_edge_connections_mesh = Ref<ArrayMesh>(memnew(ArrayMesh)); + } + + g.navigation_debug_edge_connections_mesh->clear_surfaces(); + + float edge_connection_margin = NavigationServer3D::get_singleton()->map_get_edge_connection_margin(get_world_3d()->get_navigation_map()); + float half_edge_connection_margin = edge_connection_margin * 0.5; + + Vector<Vector3> vertex_array; + + for (KeyValue<IndexKey, Octant::NavMesh> &F : g.navmesh_ids) { + if (cell_map.has(F.key) && F.value.region.is_valid()) { + int connections_count = NavigationServer3D::get_singleton()->region_get_connections_count(F.value.region); + if (connections_count == 0) { + continue; + } + + for (int i = 0; i < connections_count; i++) { + Vector3 connection_pathway_start = NavigationServer3D::get_singleton()->region_get_connection_pathway_start(F.value.region, i); + Vector3 connection_pathway_end = NavigationServer3D::get_singleton()->region_get_connection_pathway_end(F.value.region, i); + + Vector3 direction_start_end = connection_pathway_start.direction_to(connection_pathway_end); + Vector3 direction_end_start = connection_pathway_end.direction_to(connection_pathway_start); + + Vector3 start_right_dir = direction_start_end.cross(Vector3(0, 1, 0)); + Vector3 start_left_dir = -start_right_dir; + + Vector3 end_right_dir = direction_end_start.cross(Vector3(0, 1, 0)); + Vector3 end_left_dir = -end_right_dir; + + Vector3 left_start_pos = connection_pathway_start + (start_left_dir * half_edge_connection_margin); + Vector3 right_start_pos = connection_pathway_start + (start_right_dir * half_edge_connection_margin); + Vector3 left_end_pos = connection_pathway_end + (end_right_dir * half_edge_connection_margin); + Vector3 right_end_pos = connection_pathway_end + (end_left_dir * half_edge_connection_margin); + + vertex_array.push_back(right_end_pos); + vertex_array.push_back(left_start_pos); + vertex_array.push_back(right_start_pos); + + vertex_array.push_back(left_end_pos); + vertex_array.push_back(right_end_pos); + vertex_array.push_back(right_start_pos); + } + } + } + + if (vertex_array.size() == 0) { + return; + } + + Ref<StandardMaterial3D> edge_connections_material = NavigationServer3D::get_singleton_mut()->get_debug_navigation_edge_connections_material(); + + Array mesh_array; + mesh_array.resize(Mesh::ARRAY_MAX); + mesh_array[Mesh::ARRAY_VERTEX] = vertex_array; + + g.navigation_debug_edge_connections_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, mesh_array); + g.navigation_debug_edge_connections_mesh->surface_set_material(0, edge_connections_material); + + RS::get_singleton()->instance_set_base(g.navigation_debug_edge_connections_instance, g.navigation_debug_edge_connections_mesh->get_rid()); + RS::get_singleton()->instance_set_visible(g.navigation_debug_edge_connections_instance, is_visible_in_tree()); + if (is_inside_tree()) { + RS::get_singleton()->instance_set_scenario(g.navigation_debug_edge_connections_instance, get_world_3d()->get_scenario()); + } + + bool enable_edge_connections = NavigationServer3D::get_singleton()->get_debug_navigation_enable_edge_connections(); + if (!enable_edge_connections) { + RS::get_singleton()->instance_set_visible(g.navigation_debug_edge_connections_instance, false); + } } +#endif // DEBUG_ENABLED diff --git a/modules/gridmap/grid_map.h b/modules/gridmap/grid_map.h index 0ed4695fb9..f83ce68b09 100644 --- a/modules/gridmap/grid_map.h +++ b/modules/gridmap/grid_map.h @@ -117,6 +117,10 @@ class GridMap : public Node3D { HashSet<IndexKey> cells; RID collision_debug; RID collision_debug_instance; +#ifdef DEBUG_ENABLED + RID navigation_debug_edge_connections_instance; + Ref<ArrayMesh> navigation_debug_edge_connections_mesh; +#endif // DEBUG_ENABLED bool dirty = false; RID static_body; @@ -186,6 +190,11 @@ class GridMap : public Node3D { bool _octant_update(const OctantKey &p_key); void _octant_clean_up(const OctantKey &p_key); void _octant_transform(const OctantKey &p_key); +#ifdef DEBUG_ENABLED + void _update_octant_navigation_debug_edge_connections_mesh(const OctantKey &p_key); + void _navigation_map_changed(RID p_map); + void _update_navigation_debug_edge_connections(); +#endif // DEBUG_ENABLED bool awaiting_update = false; void _queue_octants_dirty(); diff --git a/modules/lightmapper_rd/lightmapper_rd.cpp b/modules/lightmapper_rd/lightmapper_rd.cpp index 2dcf644a06..5b039e65c0 100644 --- a/modules/lightmapper_rd/lightmapper_rd.cpp +++ b/modules/lightmapper_rd/lightmapper_rd.cpp @@ -670,7 +670,7 @@ LightmapperRD::BakeError LightmapperRD::_dilate(RenderingDevice *rd, Ref<RDShade return BAKE_OK; } -LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_denoiser, int p_bounces, float p_bias, int p_max_texture_size, bool p_bake_sh, GenerateProbes p_generate_probes, const Ref<Image> &p_environment_panorama, const Basis &p_environment_transform, BakeStepFunc p_step_function, void *p_bake_userdata) { +LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_denoiser, int p_bounces, float p_bias, int p_max_texture_size, bool p_bake_sh, GenerateProbes p_generate_probes, const Ref<Image> &p_environment_panorama, const Basis &p_environment_transform, BakeStepFunc p_step_function, void *p_bake_userdata, float p_exposure_normalization) { if (p_step_function) { p_step_function(0.0, RTR("Begin Bake"), p_bake_userdata, true); } @@ -1165,6 +1165,8 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d rd->compute_list_bind_uniform_set(compute_list, compute_base_uniform_set, 0); rd->compute_list_bind_uniform_set(compute_list, light_uniform_set, 1); + push_constant.environment_xform[11] = p_exposure_normalization; + for (int i = 0; i < atlas_slices; i++) { push_constant.atlas_slice = i; rd->compute_list_set_push_constant(compute_list, &push_constant, sizeof(PushConstant)); @@ -1172,6 +1174,8 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d //no barrier, let them run all together } rd->compute_list_end(); //done + + push_constant.environment_xform[11] = 0.0; } #ifdef DEBUG_TEXTURES diff --git a/modules/lightmapper_rd/lightmapper_rd.h b/modules/lightmapper_rd/lightmapper_rd.h index bf6b4399ca..b33a475dbc 100644 --- a/modules/lightmapper_rd/lightmapper_rd.h +++ b/modules/lightmapper_rd/lightmapper_rd.h @@ -241,7 +241,7 @@ public: virtual void add_omni_light(bool p_static, const Vector3 &p_position, const Color &p_color, float p_energy, float p_range, float p_attenuation, float p_size, float p_shadow_blur) override; virtual void add_spot_light(bool p_static, const Vector3 &p_position, const Vector3 p_direction, const Color &p_color, float p_energy, float p_range, float p_attenuation, float p_spot_angle, float p_spot_attenuation, float p_size, float p_shadow_blur) override; virtual void add_probe(const Vector3 &p_position) override; - virtual BakeError bake(BakeQuality p_quality, bool p_use_denoiser, int p_bounces, float p_bias, int p_max_texture_size, bool p_bake_sh, GenerateProbes p_generate_probes, const Ref<Image> &p_environment_panorama, const Basis &p_environment_transform, BakeStepFunc p_step_function = nullptr, void *p_bake_userdata = nullptr) override; + virtual BakeError bake(BakeQuality p_quality, bool p_use_denoiser, int p_bounces, float p_bias, int p_max_texture_size, bool p_bake_sh, GenerateProbes p_generate_probes, const Ref<Image> &p_environment_panorama, const Basis &p_environment_transform, BakeStepFunc p_step_function = nullptr, void *p_bake_userdata = nullptr, float p_exposure_normalization = 1.0) override; int get_bake_texture_count() const override; Ref<Image> get_bake_texture(int p_index) const override; diff --git a/modules/lightmapper_rd/lm_compute.glsl b/modules/lightmapper_rd/lm_compute.glsl index efa6cd50b4..c2557dfed3 100644 --- a/modules/lightmapper_rd/lm_compute.glsl +++ b/modules/lightmapper_rd/lm_compute.glsl @@ -434,6 +434,7 @@ void main() { imageStore(primary_dynamic, ivec3(atlas_pos, params.atlas_slice), vec4(dynamic_light, 1.0)); dynamic_light += static_light * albedo; //send for bounces + dynamic_light *= params.env_transform[2][3]; // exposure_normalization imageStore(dest_light, ivec3(atlas_pos, params.atlas_slice), vec4(dynamic_light, 1.0)); #ifdef USE_SH_LIGHTMAPS @@ -444,6 +445,7 @@ void main() { imageStore(accum_light, ivec3(atlas_pos, params.atlas_slice * 4 + 3), sh_accum[3]); #else + static_light *= params.env_transform[2][3]; // exposure_normalization imageStore(accum_light, ivec3(atlas_pos, params.atlas_slice), vec4(static_light, 1.0)); #endif diff --git a/modules/mono/build_scripts/mono_configure.py b/modules/mono/build_scripts/mono_configure.py index 3277f9beeb..c2d5452837 100644 --- a/modules/mono/build_scripts/mono_configure.py +++ b/modules/mono/build_scripts/mono_configure.py @@ -16,7 +16,7 @@ def module_supports_tools_on(platform): def configure(env, env_mono): # is_android = env["platform"] == "android" - # is_javascript = env["platform"] == "javascript" + # is_web = env["platform"] == "web" # is_ios = env["platform"] == "ios" # is_ios_sim = is_ios and env["arch"] in ["x86_32", "x86_64"] @@ -153,6 +153,7 @@ def find_app_host_version(dotnet_cmd, search_version_str): from distutils.version import LooseVersion search_version = LooseVersion(search_version_str) + found_match = False try: env = dict(os.environ, DOTNET_CLI_UI_LANGUAGE="en-US") @@ -172,7 +173,10 @@ def find_app_host_version(dotnet_cmd, search_version_str): version = LooseVersion(version_str) if version >= search_version: - return version_str + search_version = version + found_match = True + if found_match: + return str(search_version) except (subprocess.CalledProcessError, OSError) as e: import sys diff --git a/modules/mono/config.py b/modules/mono/config.py index b599414a2c..ad78c8c898 100644 --- a/modules/mono/config.py +++ b/modules/mono/config.py @@ -1,4 +1,4 @@ -# Prior to .NET Core, we supported these: ["windows", "macos", "linuxbsd", "android", "haiku", "javascript", "ios"] +# Prior to .NET Core, we supported these: ["windows", "macos", "linuxbsd", "android", "haiku", "web", "ios"] # Eventually support for each them should be added back (except Haiku if not supported by .NET Core) supported_platforms = ["windows", "macos", "linuxbsd"] @@ -10,8 +10,8 @@ def can_build(env, platform): def get_opts(platform): from SCons.Variables import BoolVariable, PathVariable - default_mono_static = platform in ["ios", "javascript"] - default_mono_bundles_zlib = platform in ["javascript"] + default_mono_static = platform in ["ios", "web"] + default_mono_bundles_zlib = platform in ["web"] return [ PathVariable( diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp index 8b135051c5..2e59987fe6 100644 --- a/modules/mono/csharp_script.cpp +++ b/modules/mono/csharp_script.cpp @@ -694,7 +694,7 @@ bool CSharpLanguage::is_assembly_reloading_needed() { } assembly_path = GodotSharpDirs::get_res_temp_assemblies_dir() - .plus_file(assembly_name + ".dll"); + .path_join(assembly_name + ".dll"); assembly_path = ProjectSettings::get_singleton()->globalize_path(assembly_path); if (!FileAccess::exists(assembly_path)) { @@ -1085,7 +1085,7 @@ void CSharpLanguage::_editor_init_callback() { const void **interop_funcs = godotsharp::get_editor_interop_funcs(interop_funcs_size); Object *editor_plugin_obj = GDMono::get_singleton()->get_plugin_callbacks().LoadToolsAssemblyCallback( - GodotSharpDirs::get_data_editor_tools_dir().plus_file("GodotTools.dll").utf16(), + GodotSharpDirs::get_data_editor_tools_dir().path_join("GodotTools.dll").utf16(), interop_funcs, interop_funcs_size); CRASH_COND(editor_plugin_obj == nullptr); diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk/Sdk/Sdk.props b/modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk/Sdk/Sdk.props index ad41ab04d5..59ce1da17b 100644 --- a/modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk/Sdk/Sdk.props +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk/Sdk/Sdk.props @@ -81,7 +81,7 @@ <GodotPlatformConstants Condition=" '$(GodotTargetPlatform)' == 'haiku' ">GODOT_HAIKU;GODOT_PC</GodotPlatformConstants> <GodotPlatformConstants Condition=" '$(GodotTargetPlatform)' == 'android' ">GODOT_ANDROID;GODOT_MOBILE</GodotPlatformConstants> <GodotPlatformConstants Condition=" '$(GodotTargetPlatform)' == 'ios' ">GODOT_IPHONE;GODOT_IOS;GODOT_MOBILE</GodotPlatformConstants> - <GodotPlatformConstants Condition=" '$(GodotTargetPlatform)' == 'javascript' ">GODOT_JAVASCRIPT;GODOT_HTML5;GODOT_WASM;GODOT_WEB</GodotPlatformConstants> + <GodotPlatformConstants Condition=" '$(GodotTargetPlatform)' == 'web' ">GODOT_JAVASCRIPT;GODOT_HTML5;GODOT_WASM;GODOT_WEB</GodotPlatformConstants> <GodotDefineConstants>$(GodotDefineConstants);$(GodotPlatformConstants)</GodotDefineConstants> </PropertyGroup> diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Sample/ExportedFields.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Sample/ExportedFields.cs index ac9f59aa99..ac8d6473a6 100644 --- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Sample/ExportedFields.cs +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Sample/ExportedFields.cs @@ -94,16 +94,20 @@ namespace Godot.SourceGenerators.Sample [Export] private NodePath field_NodePath = new NodePath("foo"); [Export] private RID field_RID; - [Export] private Godot.Collections.Dictionary field_GodotDictionary = + [Export] + private Godot.Collections.Dictionary field_GodotDictionary = new() { { "foo", 10 }, { Vector2.Up, Colors.Chocolate } }; - [Export] private Godot.Collections.Array field_GodotArray = + [Export] + private Godot.Collections.Array field_GodotArray = new() { "foo", 10, Vector2.Up, Colors.Chocolate }; - [Export] private Godot.Collections.Dictionary<string, bool> field_GodotGenericDictionary = + [Export] + private Godot.Collections.Dictionary<string, bool> field_GodotGenericDictionary = new() { { "foo", true }, { "bar", false } }; - [Export] private Godot.Collections.Array<int> field_GodotGenericArray = + [Export] + private Godot.Collections.Array<int> field_GodotGenericArray = new() { 0, 1, 2, 3, 4, 5, 6 }; } } diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Sample/ExportedProperties.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Sample/ExportedProperties.cs index 4a0e8075f0..3020cfbc50 100644 --- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Sample/ExportedProperties.cs +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Sample/ExportedProperties.cs @@ -94,16 +94,20 @@ namespace Godot.SourceGenerators.Sample [Export] private NodePath property_NodePath { get; set; } = new NodePath("foo"); [Export] private RID property_RID { get; set; } - [Export] private Godot.Collections.Dictionary property_GodotDictionary { get; set; } = + [Export] + private Godot.Collections.Dictionary property_GodotDictionary { get; set; } = new() { { "foo", 10 }, { Vector2.Up, Colors.Chocolate } }; - [Export] private Godot.Collections.Array property_GodotArray { get; set; } = + [Export] + private Godot.Collections.Array property_GodotArray { get; set; } = new() { "foo", 10, Vector2.Up, Colors.Chocolate }; - [Export] private Godot.Collections.Dictionary<string, bool> property_GodotGenericDictionary { get; set; } = + [Export] + private Godot.Collections.Dictionary<string, bool> property_GodotGenericDictionary { get; set; } = new() { { "foo", true }, { "bar", false } }; - [Export] private Godot.Collections.Array<int> property_GodotGenericArray { get; set; } = + [Export] + private Godot.Collections.Array<int> property_GodotGenericArray { get; set; } = new() { 0, 1, 2, 3, 4, 5, 6 }; } } diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Sample/ScriptBoilerplate.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Sample/ScriptBoilerplate.cs index a1667dbb8f..e43a3469ae 100644 --- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Sample/ScriptBoilerplate.cs +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Sample/ScriptBoilerplate.cs @@ -7,7 +7,7 @@ namespace Godot.SourceGenerators.Sample private NodePath _nodePath; private int _velocity; - public override void _Process(float delta) + public override void _Process(double delta) { _ = delta; diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/Common.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/Common.cs index 3dfa8000ba..e28788ec0b 100644 --- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/Common.cs +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/Common.cs @@ -168,6 +168,32 @@ namespace Godot.SourceGenerators location?.SourceTree?.FilePath)); } + public static void ReportExportedMemberIsIndexer( + GeneratorExecutionContext context, + ISymbol exportedMemberSymbol + ) + { + var locations = exportedMemberSymbol.Locations; + var location = locations.FirstOrDefault(l => l.SourceTree != null) ?? locations.FirstOrDefault(); + + string message = $"Attempted to export indexer property: " + + $"'{exportedMemberSymbol.ToDisplayString()}'"; + + string description = $"{message}. Indexer properties can't be exported." + + " Remove the '[Export]' attribute."; + + context.ReportDiagnostic(Diagnostic.Create( + new DiagnosticDescriptor(id: "GD0105", + title: message, + messageFormat: message, + category: "Usage", + DiagnosticSeverity.Error, + isEnabledByDefault: true, + description), + location, + location?.SourceTree?.FilePath)); + } + public static void ReportSignalDelegateMissingSuffix( GeneratorExecutionContext context, INamedTypeSymbol delegateSymbol) diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/GodotPluginsInitializerGenerator.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/GodotPluginsInitializerGenerator.cs index 54da6218f3..7ec3f88e5d 100644 --- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/GodotPluginsInitializerGenerator.cs +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/GodotPluginsInitializerGenerator.cs @@ -27,7 +27,8 @@ namespace GodotPlugins.Game internal static partial class Main { [UnmanagedCallersOnly(EntryPoint = ""godotsharp_game_main_init"")] - private static godot_bool InitializeFromGameProject(IntPtr godotDllHandle, IntPtr outManagedCallbacks) + private static godot_bool InitializeFromGameProject(IntPtr godotDllHandle, IntPtr outManagedCallbacks, + IntPtr unmanagedCallbacks, int unmanagedCallbacksSize) { try { @@ -37,6 +38,8 @@ namespace GodotPlugins.Game NativeLibrary.SetDllImportResolver(coreApiAssembly, dllImportResolver); + NativeFuncs.Initialize(unmanagedCallbacks, unmanagedCallbacksSize); + ManagedCallbacks.Create(outManagedCallbacks); ScriptManagerBridge.LookupScriptsInAssembly(typeof(GodotPlugins.Game.Main).Assembly); diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/MarshalUtils.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/MarshalUtils.cs index 831ac3bdeb..efdd50098e 100644 --- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/MarshalUtils.cs +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/MarshalUtils.cs @@ -16,7 +16,7 @@ namespace Godot.SourceGenerators INamedTypeSymbol GetTypeByMetadataNameOrThrow(string fullyQualifiedMetadataName) { return compilation.GetTypeByMetadataName(fullyQualifiedMetadataName) ?? - throw new InvalidOperationException("Type not found: " + fullyQualifiedMetadataName); + throw new InvalidOperationException($"Type not found: '{fullyQualifiedMetadataName}'."); } GodotObjectType = GetTypeByMetadataNameOrThrow("Godot.Object"); diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertiesGenerator.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertiesGenerator.cs index 7629595b3a..fc46d82dff 100644 --- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertiesGenerator.cs +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertiesGenerator.cs @@ -112,7 +112,8 @@ namespace Godot.SourceGenerators var propertySymbols = members .Where(s => !s.IsStatic && s.Kind == SymbolKind.Property) - .Cast<IPropertySymbol>(); + .Cast<IPropertySymbol>() + .Where(s => !s.IsIndexer); var fieldSymbols = members .Where(s => !s.IsStatic && s.Kind == SymbolKind.Field && !s.IsImplicitlyDeclared) diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertyDefValGenerator.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertyDefValGenerator.cs index 85fadaa52e..c7745391d0 100644 --- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertyDefValGenerator.cs +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertyDefValGenerator.cs @@ -134,6 +134,12 @@ namespace Godot.SourceGenerators continue; } + if (property.IsIndexer) + { + Common.ReportExportedMemberIsIndexer(context, property); + continue; + } + // TODO: We should still restore read-only properties after reloading assembly. Two possible ways: reflection or turn RestoreGodotObjectData into a constructor overload. // Ignore properties without a getter or without a setter. Godot properties must be both readable and writable. if (property.IsWriteOnly) @@ -148,7 +154,6 @@ namespace Godot.SourceGenerators continue; } - var propertyType = property.Type; var marshalType = MarshalUtils.ConvertManagedTypeToMarshalType(propertyType, typeCache); diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSerializationGenerator.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSerializationGenerator.cs index 5a84122c4c..39a99ff8ba 100644 --- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSerializationGenerator.cs +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSerializationGenerator.cs @@ -112,7 +112,8 @@ namespace Godot.SourceGenerators var propertySymbols = members .Where(s => !s.IsStatic && s.Kind == SymbolKind.Property) - .Cast<IPropertySymbol>(); + .Cast<IPropertySymbol>() + .Where(s => !s.IsIndexer); var fieldSymbols = members .Where(s => !s.IsStatic && s.Kind == SymbolKind.Field && !s.IsImplicitlyDeclared) diff --git a/modules/mono/editor/GodotTools/GodotTools.Core/StringExtensions.cs b/modules/mono/editor/GodotTools/GodotTools.Core/StringExtensions.cs index 60a4f297c9..7c5502814f 100644 --- a/modules/mono/editor/GodotTools/GodotTools.Core/StringExtensions.cs +++ b/modules/mono/editor/GodotTools/GodotTools.Core/StringExtensions.cs @@ -34,7 +34,7 @@ namespace GodotTools.Core path = path.Replace('\\', '/'); path = path[path.Length - 1] == '/' ? path.Substring(0, path.Length - 1) : path; - string[] parts = path.Split(new[] {'/'}, StringSplitOptions.RemoveEmptyEntries); + string[] parts = path.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); path = string.Join(Path.DirectorySeparatorChar.ToString(), parts).Trim(); @@ -60,7 +60,7 @@ namespace GodotTools.Core public static string ToSafeDirName(this string dirName, bool allowDirSeparator = false) { - var invalidChars = new List<string> {":", "*", "?", "\"", "<", ">", "|"}; + var invalidChars = new List<string> { ":", "*", "?", "\"", "<", ">", "|" }; if (allowDirSeparator) { diff --git a/modules/mono/editor/GodotTools/GodotTools.IdeMessaging/Client.cs b/modules/mono/editor/GodotTools/GodotTools.IdeMessaging/Client.cs index bc09e1ebf9..72e2a1fc0d 100644 --- a/modules/mono/editor/GodotTools/GodotTools.IdeMessaging/Client.cs +++ b/modules/mono/editor/GodotTools/GodotTools.IdeMessaging/Client.cs @@ -123,12 +123,16 @@ namespace GodotTools.IdeMessaging string projectMetadataDir = Path.Combine(godotProjectDir, ".godot", "mono", "metadata"); // FileSystemWatcher requires an existing directory - if (!Directory.Exists(projectMetadataDir)) { + if (!Directory.Exists(projectMetadataDir)) + { // Check if the non hidden version exists string nonHiddenProjectMetadataDir = Path.Combine(godotProjectDir, "godot", "mono", "metadata"); - if (Directory.Exists(nonHiddenProjectMetadataDir)) { + if (Directory.Exists(nonHiddenProjectMetadataDir)) + { projectMetadataDir = nonHiddenProjectMetadataDir; - } else { + } + else + { Directory.CreateDirectory(projectMetadataDir); } } diff --git a/modules/mono/editor/GodotTools/GodotTools.IdeMessaging/Peer.cs b/modules/mono/editor/GodotTools/GodotTools.IdeMessaging/Peer.cs index 10d7e1898e..dd3913b4f3 100644 --- a/modules/mono/editor/GodotTools/GodotTools.IdeMessaging/Peer.cs +++ b/modules/mono/editor/GodotTools/GodotTools.IdeMessaging/Peer.cs @@ -78,7 +78,7 @@ namespace GodotTools.IdeMessaging clientStream.WriteTimeout = ClientWriteTimeout; clientReader = new StreamReader(clientStream, Encoding.UTF8); - clientWriter = new StreamWriter(clientStream, Encoding.UTF8) {NewLine = "\n"}; + clientWriter = new StreamWriter(clientStream, Encoding.UTF8) { NewLine = "\n" }; } public async Task Process() diff --git a/modules/mono/editor/GodotTools/GodotTools.IdeMessaging/ResponseAwaiter.cs b/modules/mono/editor/GodotTools/GodotTools.IdeMessaging/ResponseAwaiter.cs index 548e7f06ee..a57c82b608 100644 --- a/modules/mono/editor/GodotTools/GodotTools.IdeMessaging/ResponseAwaiter.cs +++ b/modules/mono/editor/GodotTools/GodotTools.IdeMessaging/ResponseAwaiter.cs @@ -17,7 +17,7 @@ namespace GodotTools.IdeMessaging if (content.Status == MessageStatus.Ok) SetResult(JsonConvert.DeserializeObject<T>(content.Body)); else - SetResult(new T {Status = content.Status}); + SetResult(new T { Status = content.Status }); } } } diff --git a/modules/mono/editor/GodotTools/GodotTools.IdeMessaging/Utils/NotifyAwaiter.cs b/modules/mono/editor/GodotTools/GodotTools.IdeMessaging/Utils/NotifyAwaiter.cs index d84a63c83c..a285d5fa97 100644 --- a/modules/mono/editor/GodotTools/GodotTools.IdeMessaging/Utils/NotifyAwaiter.cs +++ b/modules/mono/editor/GodotTools/GodotTools.IdeMessaging/Utils/NotifyAwaiter.cs @@ -21,14 +21,14 @@ namespace GodotTools.IdeMessaging.Utils public void OnCompleted(Action continuation) { if (this.continuation != null) - throw new InvalidOperationException("This awaiter has already been listened"); + throw new InvalidOperationException("This awaiter already has a continuation."); this.continuation = continuation; } public void SetResult(T result) { if (IsCompleted) - throw new InvalidOperationException("This awaiter is already completed"); + throw new InvalidOperationException("This awaiter is already completed."); IsCompleted = true; this.result = result; @@ -39,7 +39,7 @@ namespace GodotTools.IdeMessaging.Utils public void SetException(Exception exception) { if (IsCompleted) - throw new InvalidOperationException("This awaiter is already completed"); + throw new InvalidOperationException("This awaiter is already completed."); IsCompleted = true; this.exception = exception; diff --git a/modules/mono/editor/GodotTools/GodotTools.OpenVisualStudio/Program.cs b/modules/mono/editor/GodotTools/GodotTools.OpenVisualStudio/Program.cs index 7a4641dbbc..cc0deb6cc0 100644 --- a/modules/mono/editor/GodotTools/GodotTools.OpenVisualStudio/Program.cs +++ b/modules/mono/editor/GodotTools/GodotTools.OpenVisualStudio/Program.cs @@ -249,8 +249,8 @@ namespace GodotTools.OpenVisualStudio // Thread call was rejected, so try again. int IOleMessageFilter.RetryRejectedCall(IntPtr hTaskCallee, int dwTickCount, int dwRejectType) { + // flag = SERVERCALL_RETRYLATER if (dwRejectType == 2) - // flag = SERVERCALL_RETRYLATER { // Retry the thread call immediately if return >= 0 & < 100 return 99; diff --git a/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectGenerator.cs b/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectGenerator.cs index fb6d2a707b..f3c8e89dff 100644 --- a/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectGenerator.cs +++ b/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectGenerator.cs @@ -15,7 +15,7 @@ namespace GodotTools.ProjectEditor public static ProjectRootElement GenGameProject(string name) { if (name.Length == 0) - throw new ArgumentException("Project name is empty", nameof(name)); + throw new ArgumentException("Project name is empty.", nameof(name)); var root = ProjectRootElement.Create(NewProjectFileOptions.None); @@ -37,7 +37,7 @@ namespace GodotTools.ProjectEditor public static string GenAndSaveGameProject(string dir, string name) { if (name.Length == 0) - throw new ArgumentException("Project name is empty", nameof(name)); + throw new ArgumentException("Project name is empty.", nameof(name)); string path = Path.Combine(dir, name + ".csproj"); diff --git a/modules/mono/editor/GodotTools/GodotTools/Build/BuildManager.cs b/modules/mono/editor/GodotTools/GodotTools/Build/BuildManager.cs index 43256953f5..993c6d9217 100644 --- a/modules/mono/editor/GodotTools/GodotTools/Build/BuildManager.cs +++ b/modules/mono/editor/GodotTools/GodotTools/Build/BuildManager.cs @@ -62,7 +62,7 @@ namespace GodotTools.Build private static bool Build(BuildInfo buildInfo) { if (_buildInProgress != null) - throw new InvalidOperationException("A build is already in progress"); + throw new InvalidOperationException("A build is already in progress."); _buildInProgress = buildInfo; @@ -111,7 +111,7 @@ namespace GodotTools.Build public static async Task<bool> BuildAsync(BuildInfo buildInfo) { if (_buildInProgress != null) - throw new InvalidOperationException("A build is already in progress"); + throw new InvalidOperationException("A build is already in progress."); _buildInProgress = buildInfo; @@ -157,7 +157,7 @@ namespace GodotTools.Build private static bool Publish(BuildInfo buildInfo) { if (_buildInProgress != null) - throw new InvalidOperationException("A build is already in progress"); + throw new InvalidOperationException("A build is already in progress."); _buildInProgress = buildInfo; diff --git a/modules/mono/editor/GodotTools/GodotTools/Build/BuildOutputView.cs b/modules/mono/editor/GodotTools/GodotTools/Build/BuildOutputView.cs index 96d1fc28bf..ad4fce8daa 100644 --- a/modules/mono/editor/GodotTools/GodotTools/Build/BuildOutputView.cs +++ b/modules/mono/editor/GodotTools/GodotTools/Build/BuildOutputView.cs @@ -117,16 +117,16 @@ namespace GodotTools.Build } } - private void IssueActivated(int idx) + private void IssueActivated(long idx) { if (idx < 0 || idx >= _issuesList.ItemCount) - throw new IndexOutOfRangeException("Item list index out of range"); + throw new ArgumentOutOfRangeException(nameof(idx), "Item list index out of range."); // Get correct issue idx from issue list - int issueIndex = (int)_issuesList.GetItemMetadata(idx); + int issueIndex = (int)_issuesList.GetItemMetadata((int)idx); if (issueIndex < 0 || issueIndex >= _issues.Count) - throw new IndexOutOfRangeException("Issue index out of range"); + throw new InvalidOperationException("Issue index out of range."); BuildIssue issue = _issues[issueIndex]; @@ -293,7 +293,7 @@ namespace GodotTools.Build public void RestartBuild() { if (!HasBuildExited) - throw new InvalidOperationException("Build already started"); + throw new InvalidOperationException("Build already started."); BuildManager.RestartBuild(this); } @@ -301,7 +301,7 @@ namespace GodotTools.Build public void StopBuild() { if (!HasBuildExited) - throw new InvalidOperationException("Build is not in progress"); + throw new InvalidOperationException("Build is not in progress."); BuildManager.StopBuild(this); } @@ -311,7 +311,7 @@ namespace GodotTools.Build Copy } - private void IssuesListContextOptionPressed(int id) + private void IssuesListContextOptionPressed(long id) { switch ((IssuesContextMenuOption)id) { @@ -336,9 +336,9 @@ namespace GodotTools.Build } } - private void IssuesListClicked(int index, Vector2 atPosition, int mouseButtonIndex) + private void IssuesListClicked(long index, Vector2 atPosition, long mouseButtonIndex) { - if (mouseButtonIndex != (int)MouseButton.Right) + if (mouseButtonIndex != (long)MouseButton.Right) { return; } diff --git a/modules/mono/editor/GodotTools/GodotTools/Build/BuildSystem.cs b/modules/mono/editor/GodotTools/GodotTools/Build/BuildSystem.cs index 655be0ab5e..d0cd529d1f 100644 --- a/modules/mono/editor/GodotTools/GodotTools/Build/BuildSystem.cs +++ b/modules/mono/editor/GodotTools/GodotTools/Build/BuildSystem.cs @@ -176,8 +176,9 @@ namespace GodotTools.Build arguments.Add("--no-restore"); // Incremental or rebuild - if (buildInfo.Rebuild) - arguments.Add("--no-incremental"); + // TODO: Not supported in `dotnet publish` (https://github.com/dotnet/sdk/issues/11099) + // if (buildInfo.Rebuild) + // arguments.Add("--no-incremental"); // Configuration arguments.Add("-c"); diff --git a/modules/mono/editor/GodotTools/GodotTools/Build/MSBuildPanel.cs b/modules/mono/editor/GodotTools/GodotTools/Build/MSBuildPanel.cs index 6dae0a3a0e..4041026426 100644 --- a/modules/mono/editor/GodotTools/GodotTools/Build/MSBuildPanel.cs +++ b/modules/mono/editor/GodotTools/GodotTools/Build/MSBuildPanel.cs @@ -93,7 +93,7 @@ namespace GodotTools.Build private void ViewLogToggled(bool pressed) => BuildOutputView.LogVisible = pressed; - private void BuildMenuOptionPressed(int id) + private void BuildMenuOptionPressed(long id) { switch ((BuildMenuOptions)id) { @@ -139,7 +139,7 @@ namespace GodotTools.Build _errorsBtn = new Button { - HintTooltip = "Show Errors".TTR(), + TooltipText = "Show Errors".TTR(), Icon = GetThemeIcon("StatusError", "EditorIcons"), ExpandIcon = false, ToggleMode = true, @@ -151,7 +151,7 @@ namespace GodotTools.Build _warningsBtn = new Button { - HintTooltip = "Show Warnings".TTR(), + TooltipText = "Show Warnings".TTR(), Icon = GetThemeIcon("NodeWarning", "EditorIcons"), ExpandIcon = false, ToggleMode = true, @@ -175,7 +175,7 @@ namespace GodotTools.Build AddChild(BuildOutputView); } - public override void _Notification(int what) + public override void _Notification(long what) { base._Notification(what); diff --git a/modules/mono/editor/GodotTools/GodotTools/Build/NuGetUtils.cs b/modules/mono/editor/GodotTools/GodotTools/Build/NuGetUtils.cs index fdb86c8f34..d2e0e128b5 100644 --- a/modules/mono/editor/GodotTools/GodotTools/Build/NuGetUtils.cs +++ b/modules/mono/editor/GodotTools/GodotTools/Build/NuGetUtils.cs @@ -49,7 +49,7 @@ namespace GodotTools.Build { // Check that the root node is the expected one if (rootNode.Name != nuGetConfigRootName) - throw new Exception("Invalid root Xml node for NuGet.Config. " + + throw new FormatException("Invalid root Xml node for NuGet.Config. " + $"Expected '{nuGetConfigRootName}' got '{rootNode.Name}'."); } diff --git a/modules/mono/editor/GodotTools/GodotTools/Export/AotBuilder.cs b/modules/mono/editor/GodotTools/GodotTools/Export/AotBuilder.cs index fc325fc25b..2184cae6d6 100644 --- a/modules/mono/editor/GodotTools/GodotTools/Export/AotBuilder.cs +++ b/modules/mono/editor/GodotTools/GodotTools/Export/AotBuilder.cs @@ -76,13 +76,20 @@ namespace GodotTools.Export else { string arch = ""; - if (features.Contains("x86_64")) { + if (features.Contains("x86_64")) + { arch = "x86_64"; - } else if (features.Contains("x86_32")) { + } + else if (features.Contains("x86_32")) + { arch = "x86_32"; - } else if (features.Contains("arm64")) { + } + else if (features.Contains("arm64")) + { arch = "arm64"; - } else if (features.Contains("arm32")) { + } + else if (features.Contains("arm32")) + { arch = "arm32"; } CompileAssembliesForDesktop(exporter, platform, isDebug, arch, aotOpts, aotTempDir, outputDataDir, assembliesPrepared, bclDir); @@ -212,7 +219,7 @@ namespace GodotTools.Export int clangExitCode = OS.ExecuteCommand(XcodeHelper.FindXcodeTool("clang"), clangArgs); if (clangExitCode != 0) - throw new Exception($"Command 'clang' exited with code: {clangExitCode}"); + throw new InvalidOperationException($"Command 'clang' exited with code: {clangExitCode}."); objFilePathsForiOSArch[arch].Add(objFilePath); } @@ -318,7 +325,7 @@ MONO_AOT_MODE_LAST = 1000, int arExitCode = OS.ExecuteCommand(XcodeHelper.FindXcodeTool("ar"), arArgs); if (arExitCode != 0) - throw new Exception($"Command 'ar' exited with code: {arExitCode}"); + throw new InvalidOperationException($"Command 'ar' exited with code: {arExitCode}."); arFilePathsForAllArchs.Add(arOutputFilePath); } @@ -336,7 +343,7 @@ MONO_AOT_MODE_LAST = 1000, int lipoExitCode = OS.ExecuteCommand(XcodeHelper.FindXcodeTool("lipo"), lipoArgs); if (lipoExitCode != 0) - throw new Exception($"Command 'lipo' exited with code: {lipoExitCode}"); + throw new InvalidOperationException($"Command 'lipo' exited with code: {lipoExitCode}."); // TODO: Add the AOT lib and interpreter libs as device only to suppress warnings when targeting the simulator @@ -436,7 +443,7 @@ MONO_AOT_MODE_LAST = 1000, } else if (!Directory.Exists(androidToolchain)) { - throw new FileNotFoundException("Android toolchain not found: " + androidToolchain); + throw new FileNotFoundException($"Android toolchain not found: '{androidToolchain}'."); } var androidToolPrefixes = new Dictionary<string, string> @@ -533,12 +540,12 @@ MONO_AOT_MODE_LAST = 1000, Console.WriteLine($"Running: \"{process.StartInfo.FileName}\" {process.StartInfo.Arguments}"); if (!process.Start()) - throw new Exception("Failed to start process for Mono AOT compiler"); + throw new InvalidOperationException("Failed to start process for Mono AOT compiler."); process.WaitForExit(); if (process.ExitCode != 0) - throw new Exception($"Mono AOT compiler exited with code: {process.ExitCode}"); + throw new InvalidOperationException($"Mono AOT compiler exited with code: {process.ExitCode}."); } } diff --git a/modules/mono/editor/GodotTools/GodotTools/Export/ExportPlugin.cs b/modules/mono/editor/GodotTools/GodotTools/Export/ExportPlugin.cs index e1b5530b93..0d2bea2363 100644 --- a/modules/mono/editor/GodotTools/GodotTools/Export/ExportPlugin.cs +++ b/modules/mono/editor/GodotTools/GodotTools/Export/ExportPlugin.cs @@ -67,7 +67,7 @@ namespace GodotTools.Export } } - public override void _ExportBegin(string[] features, bool isDebug, string path, int flags) + public override void _ExportBegin(string[] features, bool isDebug, string path, long flags) { base._ExportBegin(features, isDebug, path, flags); @@ -90,7 +90,7 @@ namespace GodotTools.Export } } - private void _ExportBeginImpl(string[] features, bool isDebug, string path, int flags) + private void _ExportBeginImpl(string[] features, bool isDebug, string path, long flags) { _ = flags; // Unused @@ -98,21 +98,21 @@ namespace GodotTools.Export return; if (!DeterminePlatformFromFeatures(features, out string platform)) - throw new NotSupportedException("Target platform not supported"); + throw new NotSupportedException("Target platform not supported."); if (!new[] { OS.Platforms.Windows, OS.Platforms.LinuxBSD, OS.Platforms.MacOS } .Contains(platform)) { - throw new NotImplementedException("Target platform not yet implemented"); + throw new NotImplementedException("Target platform not yet implemented."); } string outputDir = new FileInfo(path).Directory?.FullName ?? - throw new FileNotFoundException("Output base directory not found"); + throw new FileNotFoundException("Output base directory not found."); string buildConfig = isDebug ? "ExportDebug" : "ExportRelease"; // TODO: This works for now, as we only implemented support for x86 family desktop so far, but it needs to be fixed - string arch = features.Contains("64") ? "x86_64" : "x86"; + string arch = features.Contains("x86_64") ? "x86_64" : "x86"; string ridOS = DetermineRuntimeIdentifierOS(platform); string ridArch = DetermineRuntimeIdentifierArch(arch); @@ -131,7 +131,7 @@ namespace GodotTools.Export if (!BuildManager.PublishProjectBlocking(buildConfig, platform, runtimeIdentifier, publishOutputTempDir)) { - throw new Exception("Failed to build project"); + throw new InvalidOperationException("Failed to build project."); } string soExt = ridOS switch diff --git a/modules/mono/editor/GodotTools/GodotTools/Export/XcodeHelper.cs b/modules/mono/editor/GodotTools/GodotTools/Export/XcodeHelper.cs index 93ef837a83..4f5bebfb42 100644 --- a/modules/mono/editor/GodotTools/GodotTools/Export/XcodeHelper.cs +++ b/modules/mono/editor/GodotTools/GodotTools/Export/XcodeHelper.cs @@ -16,7 +16,7 @@ namespace GodotTools.Export _XcodePath = FindXcode(); if (_XcodePath == null) - throw new Exception("Could not find Xcode"); + throw new FileNotFoundException("Could not find Xcode."); } return _XcodePath; diff --git a/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs b/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs index 0aca60dad4..1cfaea3ec9 100644 --- a/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs +++ b/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs @@ -111,7 +111,7 @@ namespace GodotTools _toolBarBuildButton.Show(); } - private void _MenuOptionPressed(int id) + private void _MenuOptionPressed(long id) { switch ((MenuOptions)id) { @@ -342,7 +342,7 @@ namespace GodotTools DotNetSolution.MigrateFromOldConfigNames(GodotSharpDirs.ProjectSlnPath); var msbuildProject = ProjectUtils.Open(GodotSharpDirs.ProjectCsProjPath) - ?? throw new Exception("Cannot open C# project"); + ?? throw new InvalidOperationException("Cannot open C# project."); // NOTE: The order in which changes are made to the project is important @@ -433,7 +433,7 @@ namespace GodotTools _toolBarBuildButton = new Button { Text = "Build", - HintTooltip = "Build Solution".TTR(), + TooltipText = "Build Solution".TTR(), FocusMode = Control.FocusModeEnum.None, Shortcut = buildSolutionShortcut, ShortcutInTooltip = true diff --git a/modules/mono/editor/GodotTools/GodotTools/HotReloadAssemblyWatcher.cs b/modules/mono/editor/GodotTools/GodotTools/HotReloadAssemblyWatcher.cs index 260d13a714..89ac8058b9 100644 --- a/modules/mono/editor/GodotTools/GodotTools/HotReloadAssemblyWatcher.cs +++ b/modules/mono/editor/GodotTools/GodotTools/HotReloadAssemblyWatcher.cs @@ -9,7 +9,7 @@ namespace GodotTools { private Timer _watchTimer; - public override void _Notification(int what) + public override void _Notification(long what) { if (what == Node.NotificationWmWindowFocusIn) { diff --git a/modules/mono/editor/GodotTools/GodotTools/Ides/GodotIdeManager.cs b/modules/mono/editor/GodotTools/GodotTools/Ides/GodotIdeManager.cs index 95b60aded1..9df90ac608 100644 --- a/modules/mono/editor/GodotTools/GodotTools/Ides/GodotIdeManager.cs +++ b/modules/mono/editor/GodotTools/GodotTools/Ides/GodotIdeManager.cs @@ -153,7 +153,7 @@ namespace GodotTools.Ides } default: - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(editorId)); } } @@ -180,17 +180,17 @@ namespace GodotTools.Ides public void SendOpenFile(string file) { - SendRequest<OpenFileResponse>(new OpenFileRequest {File = file}); + SendRequest<OpenFileResponse>(new OpenFileRequest { File = file }); } public void SendOpenFile(string file, int line) { - SendRequest<OpenFileResponse>(new OpenFileRequest {File = file, Line = line}); + SendRequest<OpenFileResponse>(new OpenFileRequest { File = file, Line = line }); } public void SendOpenFile(string file, int line, int column) { - SendRequest<OpenFileResponse>(new OpenFileRequest {File = file, Line = line, Column = column}); + SendRequest<OpenFileResponse>(new OpenFileRequest { File = file, Line = line, Column = column }); } } diff --git a/modules/mono/editor/GodotTools/GodotTools/Ides/MessagingServer.cs b/modules/mono/editor/GodotTools/GodotTools/Ides/MessagingServer.cs index 6f11831b80..62db6e3af5 100644 --- a/modules/mono/editor/GodotTools/GodotTools/Ides/MessagingServer.cs +++ b/modules/mono/editor/GodotTools/GodotTools/Ides/MessagingServer.cs @@ -385,7 +385,7 @@ namespace GodotTools.Ides // However, it doesn't fix resource loading if the rest of the path is also case insensitive. string scriptFileLocalized = FsPathUtils.LocalizePathWithCaseChecked(request.ScriptFile); - var response = new CodeCompletionResponse {Kind = request.Kind, ScriptFile = request.ScriptFile}; + var response = new CodeCompletionResponse { Kind = request.Kind, ScriptFile = request.ScriptFile }; response.Suggestions = await Task.Run(() => Internal.CodeCompletionRequest(response.Kind, scriptFileLocalized ?? request.ScriptFile)); return response; diff --git a/modules/mono/editor/GodotTools/GodotTools/Ides/Rider/RiderPathLocator.cs b/modules/mono/editor/GodotTools/GodotTools/Ides/Rider/RiderPathLocator.cs index 4caab035de..dad6e35344 100644 --- a/modules/mono/editor/GodotTools/GodotTools/Ides/Rider/RiderPathLocator.cs +++ b/modules/mono/editor/GodotTools/GodotTools/Ides/Rider/RiderPathLocator.cs @@ -42,7 +42,7 @@ namespace GodotTools.Ides.Rider { return CollectAllRiderPathsLinux(); } - throw new Exception("Unexpected OS."); + throw new InvalidOperationException("Unexpected OS."); } catch (Exception e) { @@ -216,7 +216,7 @@ namespace GodotTools.Ides.Rider return "../../build.txt"; if (OS.IsMacOS) return "Contents/Resources/build.txt"; - throw new Exception("Unknown OS."); + throw new InvalidOperationException("Unknown OS."); } [SupportedOSPlatform("windows")] diff --git a/modules/mono/editor/GodotTools/GodotTools/Internals/Internal.cs b/modules/mono/editor/GodotTools/GodotTools/Internals/Internal.cs index e3fe1622d0..fd810996f7 100644 --- a/modules/mono/editor/GodotTools/GodotTools/Internals/Internal.cs +++ b/modules/mono/editor/GodotTools/GodotTools/Internals/Internal.cs @@ -74,11 +74,11 @@ namespace GodotTools.Internals internal static unsafe void Initialize(IntPtr unmanagedCallbacks, int unmanagedCallbacksSize) { if (initialized) - throw new InvalidOperationException("Already initialized"); + throw new InvalidOperationException("Already initialized."); initialized = true; if (unmanagedCallbacksSize != sizeof(InternalUnmanagedCallbacks)) - throw new ArgumentException("Unmanaged callbacks size mismatch"); + throw new ArgumentException("Unmanaged callbacks size mismatch.", nameof(unmanagedCallbacksSize)); _unmanagedCallbacks = Unsafe.AsRef<InternalUnmanagedCallbacks>((void*)unmanagedCallbacks); } diff --git a/modules/mono/editor/GodotTools/GodotTools/Utils/OS.cs b/modules/mono/editor/GodotTools/GodotTools/Utils/OS.cs index 651922d019..c16f803226 100644 --- a/modules/mono/editor/GodotTools/GodotTools/Utils/OS.cs +++ b/modules/mono/editor/GodotTools/GodotTools/Utils/OS.cs @@ -30,7 +30,7 @@ namespace GodotTools.Utils public const string Haiku = "Haiku"; public const string Android = "Android"; public const string iOS = "iOS"; - public const string HTML5 = "HTML5"; + public const string Web = "Web"; } /// <summary> @@ -45,7 +45,7 @@ namespace GodotTools.Utils public const string Haiku = "haiku"; public const string Android = "android"; public const string iOS = "ios"; - public const string HTML5 = "javascript"; + public const string Web = "web"; } /// <summary> @@ -70,14 +70,12 @@ namespace GodotTools.Utils { ["Windows"] = Platforms.Windows, ["macOS"] = Platforms.MacOS, - ["LinuxBSD"] = Platforms.LinuxBSD, - // "X11" for compatibility, temporarily, while we are on an outdated branch - ["X11"] = Platforms.LinuxBSD, + ["Linux"] = Platforms.LinuxBSD, ["UWP"] = Platforms.UWP, ["Haiku"] = Platforms.Haiku, ["Android"] = Platforms.Android, ["iOS"] = Platforms.iOS, - ["HTML5"] = Platforms.HTML5 + ["Web"] = Platforms.Web }; public static readonly Dictionary<string, string> PlatformNameMap = new Dictionary<string, string> @@ -92,7 +90,7 @@ namespace GodotTools.Utils [Names.Haiku] = Platforms.Haiku, [Names.Android] = Platforms.Android, [Names.iOS] = Platforms.iOS, - [Names.HTML5] = Platforms.HTML5 + [Names.Web] = Platforms.Web }; public static readonly Dictionary<string, string> DotNetOSPlatformMap = new Dictionary<string, string> @@ -107,7 +105,7 @@ namespace GodotTools.Utils [Platforms.UWP] = DotNetOS.Win10, [Platforms.Android] = DotNetOS.Android, [Platforms.iOS] = DotNetOS.iOS, - [Platforms.HTML5] = DotNetOS.Browser + [Platforms.Web] = DotNetOS.Browser }; private static bool IsOS(string name) @@ -144,7 +142,7 @@ namespace GodotTools.Utils private static readonly Lazy<bool> _isHaiku = new(() => IsOS(Names.Haiku)); private static readonly Lazy<bool> _isAndroid = new(() => IsOS(Names.Android)); private static readonly Lazy<bool> _isiOS = new(() => IsOS(Names.iOS)); - private static readonly Lazy<bool> _isHTML5 = new(() => IsOS(Names.HTML5)); + private static readonly Lazy<bool> _isWeb = new(() => IsOS(Names.Web)); private static readonly Lazy<bool> _isUnixLike = new(() => IsAnyOS(UnixLikePlatforms)); [SupportedOSPlatformGuard("windows")] public static bool IsWindows => _isWindows.Value || IsUWP; @@ -161,7 +159,7 @@ namespace GodotTools.Utils [SupportedOSPlatformGuard("ios")] public static bool IsiOS => _isiOS.Value; - [SupportedOSPlatformGuard("browser")] public static bool IsHTML5 => _isHTML5.Value; + [SupportedOSPlatformGuard("browser")] public static bool IsWeb => _isWeb.Value; public static bool IsUnixLike => _isUnixLike.Value; public static char PathSep => IsWindows ? ';' : ':'; @@ -206,10 +204,10 @@ namespace GodotTools.Utils return searchDirs.Select(dir => Path.Combine(dir, name)).FirstOrDefault(File.Exists); return (from dir in searchDirs - select Path.Combine(dir, name) + select Path.Combine(dir, name) into path - from ext in windowsExts - select path + ext).FirstOrDefault(File.Exists); + from ext in windowsExts + select path + ext).FirstOrDefault(File.Exists); } [return: MaybeNull] @@ -257,7 +255,7 @@ namespace GodotTools.Utils using Process process = Process.Start(startInfo); if (process == null) - throw new Exception("No process was started"); + throw new InvalidOperationException("No process was started."); process.BeginOutputReadLine(); process.BeginErrorReadLine(); diff --git a/modules/mono/editor/bindings_generator.cpp b/modules/mono/editor/bindings_generator.cpp index d70a1e6c88..15a40c8ca5 100644 --- a/modules/mono/editor/bindings_generator.cpp +++ b/modules/mono/editor/bindings_generator.cpp @@ -1315,7 +1315,7 @@ Error BindingsGenerator::generate_cs_api(const String &p_output_dir) { // Generate GodotSharp source files - String core_proj_dir = output_dir.plus_file(CORE_API_ASSEMBLY_NAME); + String core_proj_dir = output_dir.path_join(CORE_API_ASSEMBLY_NAME); proj_err = generate_cs_core_project(core_proj_dir); if (proj_err != OK) { @@ -1325,7 +1325,7 @@ Error BindingsGenerator::generate_cs_api(const String &p_output_dir) { // Generate GodotSharpEditor source files - String editor_proj_dir = output_dir.plus_file(EDITOR_API_ASSEMBLY_NAME); + String editor_proj_dir = output_dir.path_join(EDITOR_API_ASSEMBLY_NAME); proj_err = generate_cs_editor_project(editor_proj_dir); if (proj_err != OK) { @@ -2585,6 +2585,16 @@ const String BindingsGenerator::_get_generic_type_parameters(const TypeInterface return params; } +StringName BindingsGenerator::_get_type_name_from_meta(Variant::Type p_type, GodotTypeInfo::Metadata p_meta) { + if (p_type == Variant::INT) { + return _get_int_type_name_from_meta(p_meta); + } else if (p_type == Variant::FLOAT) { + return _get_float_type_name_from_meta(p_meta); + } else { + return Variant::get_type_name(p_type); + } +} + StringName BindingsGenerator::_get_int_type_name_from_meta(GodotTypeInfo::Metadata p_meta) { switch (p_meta) { case GodotTypeInfo::METADATA_INT_IS_INT8: @@ -2612,8 +2622,8 @@ StringName BindingsGenerator::_get_int_type_name_from_meta(GodotTypeInfo::Metada return "ulong"; break; default: - // Assume INT32 - return "int"; + // Assume INT64 + return "long"; } } @@ -2626,12 +2636,8 @@ StringName BindingsGenerator::_get_float_type_name_from_meta(GodotTypeInfo::Meta return "double"; break; default: - // Assume real_t (float or double depending of REAL_T_IS_DOUBLE) -#ifdef REAL_T_IS_DOUBLE + // Assume FLOAT64 return "double"; -#else - return "float"; -#endif } } @@ -2922,13 +2928,7 @@ bool BindingsGenerator::_populate_object_type_interfaces() { } else if (return_info.type == Variant::NIL) { imethod.return_type.cname = name_cache.type_void; } else { - if (return_info.type == Variant::INT) { - imethod.return_type.cname = _get_int_type_name_from_meta(m ? m->get_argument_meta(-1) : GodotTypeInfo::METADATA_NONE); - } else if (return_info.type == Variant::FLOAT) { - imethod.return_type.cname = _get_float_type_name_from_meta(m ? m->get_argument_meta(-1) : GodotTypeInfo::METADATA_NONE); - } else { - imethod.return_type.cname = Variant::get_type_name(return_info.type); - } + imethod.return_type.cname = _get_type_name_from_meta(return_info.type, m ? m->get_argument_meta(-1) : GodotTypeInfo::METADATA_NONE); } for (int i = 0; i < argc; i++) { @@ -2952,13 +2952,7 @@ bool BindingsGenerator::_populate_object_type_interfaces() { } else if (arginfo.type == Variant::NIL) { iarg.type.cname = name_cache.type_Variant; } else { - if (arginfo.type == Variant::INT) { - iarg.type.cname = _get_int_type_name_from_meta(m ? m->get_argument_meta(i) : GodotTypeInfo::METADATA_NONE); - } else if (arginfo.type == Variant::FLOAT) { - iarg.type.cname = _get_float_type_name_from_meta(m ? m->get_argument_meta(i) : GodotTypeInfo::METADATA_NONE); - } else { - iarg.type.cname = Variant::get_type_name(arginfo.type); - } + iarg.type.cname = _get_type_name_from_meta(arginfo.type, m ? m->get_argument_meta(i) : GodotTypeInfo::METADATA_NONE); } iarg.name = escape_csharp_keyword(snake_to_camel_case(iarg.name)); @@ -3060,13 +3054,7 @@ bool BindingsGenerator::_populate_object_type_interfaces() { } else if (arginfo.type == Variant::NIL) { iarg.type.cname = name_cache.type_Variant; } else { - if (arginfo.type == Variant::INT) { - iarg.type.cname = _get_int_type_name_from_meta(GodotTypeInfo::METADATA_NONE); - } else if (arginfo.type == Variant::FLOAT) { - iarg.type.cname = _get_float_type_name_from_meta(GodotTypeInfo::METADATA_NONE); - } else { - iarg.type.cname = Variant::get_type_name(arginfo.type); - } + iarg.type.cname = _get_type_name_from_meta(arginfo.type, GodotTypeInfo::METADATA_NONE); } iarg.name = escape_csharp_keyword(snake_to_camel_case(iarg.name)); @@ -3880,7 +3868,7 @@ static void handle_cmdline_options(String glue_dir_path) { CRASH_COND(glue_dir_path.is_empty()); - if (bindings_generator.generate_cs_api(glue_dir_path.plus_file(API_SOLUTION_NAME)) != OK) { + if (bindings_generator.generate_cs_api(glue_dir_path.path_join(API_SOLUTION_NAME)) != OK) { ERR_PRINT(generate_all_glue_option + ": Failed to generate the C# API."); } } diff --git a/modules/mono/editor/bindings_generator.h b/modules/mono/editor/bindings_generator.h index c1295385dc..a479c44368 100644 --- a/modules/mono/editor/bindings_generator.h +++ b/modules/mono/editor/bindings_generator.h @@ -703,6 +703,7 @@ class BindingsGenerator { const String _get_generic_type_parameters(const TypeInterface &p_itype, const List<TypeReference> &p_generic_type_parameters); + StringName _get_type_name_from_meta(Variant::Type p_type, GodotTypeInfo::Metadata p_meta); StringName _get_int_type_name_from_meta(GodotTypeInfo::Metadata p_meta); StringName _get_float_type_name_from_meta(GodotTypeInfo::Metadata p_meta); diff --git a/modules/mono/editor/code_completion.cpp b/modules/mono/editor/code_completion.cpp index 7bce6f2c21..40296eef10 100644 --- a/modules/mono/editor/code_completion.cpp +++ b/modules/mono/editor/code_completion.cpp @@ -35,6 +35,7 @@ #include "editor/editor_settings.h" #include "scene/gui/control.h" #include "scene/main/node.h" +#include "scene/theme/theme_db.h" namespace gdmono { @@ -162,9 +163,9 @@ PackedStringArray get_code_completion(CompletionKind p_kind, const String &p_scr } if (dir_access->dir_exists(filename)) { - directories.push_back(dir_access->get_current_dir().plus_file(filename)); + directories.push_back(dir_access->get_current_dir().path_join(filename)); } else if (filename.ends_with(".tscn") || filename.ends_with(".scn")) { - suggestions.push_back(quoted(dir_access->get_current_dir().plus_file(filename))); + suggestions.push_back(quoted(dir_access->get_current_dir().path_join(filename))); } filename = dir_access->get_next(); @@ -195,7 +196,7 @@ PackedStringArray get_code_completion(CompletionKind p_kind, const String &p_scr Node *base = _try_find_owner_node_in_tree(script); if (base && Object::cast_to<Control>(base)) { List<StringName> sn; - Theme::get_default()->get_color_list(base->get_class(), &sn); + ThemeDB::get_singleton()->get_default_theme()->get_color_list(base->get_class(), &sn); for (const StringName &E : sn) { suggestions.push_back(quoted(E)); @@ -207,7 +208,7 @@ PackedStringArray get_code_completion(CompletionKind p_kind, const String &p_scr Node *base = _try_find_owner_node_in_tree(script); if (base && Object::cast_to<Control>(base)) { List<StringName> sn; - Theme::get_default()->get_constant_list(base->get_class(), &sn); + ThemeDB::get_singleton()->get_default_theme()->get_constant_list(base->get_class(), &sn); for (const StringName &E : sn) { suggestions.push_back(quoted(E)); @@ -219,7 +220,7 @@ PackedStringArray get_code_completion(CompletionKind p_kind, const String &p_scr Node *base = _try_find_owner_node_in_tree(script); if (base && Object::cast_to<Control>(base)) { List<StringName> sn; - Theme::get_default()->get_font_list(base->get_class(), &sn); + ThemeDB::get_singleton()->get_default_theme()->get_font_list(base->get_class(), &sn); for (const StringName &E : sn) { suggestions.push_back(quoted(E)); @@ -231,7 +232,7 @@ PackedStringArray get_code_completion(CompletionKind p_kind, const String &p_scr Node *base = _try_find_owner_node_in_tree(script); if (base && Object::cast_to<Control>(base)) { List<StringName> sn; - Theme::get_default()->get_font_size_list(base->get_class(), &sn); + ThemeDB::get_singleton()->get_default_theme()->get_font_size_list(base->get_class(), &sn); for (const StringName &E : sn) { suggestions.push_back(quoted(E)); @@ -243,7 +244,7 @@ PackedStringArray get_code_completion(CompletionKind p_kind, const String &p_scr Node *base = _try_find_owner_node_in_tree(script); if (base && Object::cast_to<Control>(base)) { List<StringName> sn; - Theme::get_default()->get_stylebox_list(base->get_class(), &sn); + ThemeDB::get_singleton()->get_default_theme()->get_stylebox_list(base->get_class(), &sn); for (const StringName &E : sn) { suggestions.push_back(quoted(E)); diff --git a/modules/mono/editor/editor_internal_calls.cpp b/modules/mono/editor/editor_internal_calls.cpp index 1ef78c3ac2..6f42ad6916 100644 --- a/modules/mono/editor/editor_internal_calls.cpp +++ b/modules/mono/editor/editor_internal_calls.cpp @@ -98,7 +98,7 @@ bool godot_icall_EditorProgress_Step(const godot_string *p_task, const godot_str } void godot_icall_Internal_FullExportTemplatesDir(godot_string *r_dest) { - String full_templates_dir = EditorPaths::get_singleton()->get_export_templates_dir().plus_file(VERSION_FULL_CONFIG); + String full_templates_dir = EditorPaths::get_singleton()->get_export_templates_dir().path_join(VERSION_FULL_CONFIG); memnew_placement(r_dest, String(full_templates_dir)); } diff --git a/modules/mono/editor/script_templates/CharacterBody2D/basic_movement.cs b/modules/mono/editor/script_templates/CharacterBody2D/basic_movement.cs index 1f5ea7532d..fbad482cf6 100644 --- a/modules/mono/editor/script_templates/CharacterBody2D/basic_movement.cs +++ b/modules/mono/editor/script_templates/CharacterBody2D/basic_movement.cs @@ -11,13 +11,13 @@ public partial class _CLASS_ : _BASE_ // Get the gravity from the project settings to be synced with RigidBody nodes. public float gravity = ProjectSettings.GetSetting("physics/2d/default_gravity").AsSingle(); - public override void _PhysicsProcess(float delta) + public override void _PhysicsProcess(double delta) { Vector2 velocity = Velocity; // Add the gravity. if (!IsOnFloor()) - velocity.y += gravity * delta; + velocity.y += gravity * (float)delta; // Handle Jump. if (Input.IsActionJustPressed("ui_accept") && IsOnFloor()) diff --git a/modules/mono/editor/script_templates/CharacterBody3D/basic_movement.cs b/modules/mono/editor/script_templates/CharacterBody3D/basic_movement.cs index 4e978b7549..abed246a1e 100644 --- a/modules/mono/editor/script_templates/CharacterBody3D/basic_movement.cs +++ b/modules/mono/editor/script_templates/CharacterBody3D/basic_movement.cs @@ -11,17 +11,17 @@ public partial class _CLASS_ : _BASE_ // Get the gravity from the project settings to be synced with RigidBody nodes. public float gravity = ProjectSettings.GetSetting("physics/3d/default_gravity").AsSingle(); - public override void _PhysicsProcess(float delta) + public override void _PhysicsProcess(double delta) { Vector3 velocity = Velocity; // Add the gravity. if (!IsOnFloor()) - velocity.y -= gravity * delta; + velocity.y -= gravity * (float)delta; // Handle Jump. if (Input.IsActionJustPressed("ui_accept") && IsOnFloor()) - velocity.y = JumpVelocity; + velocity.y = JumpVelocity; // Get the input direction and handle the movement/deceleration. // As good practice, you should replace UI actions with custom gameplay actions. diff --git a/modules/mono/editor/script_templates/Node/default.cs b/modules/mono/editor/script_templates/Node/default.cs index 4c86d1666f..74ece028fc 100644 --- a/modules/mono/editor/script_templates/Node/default.cs +++ b/modules/mono/editor/script_templates/Node/default.cs @@ -11,7 +11,7 @@ public partial class _CLASS_ : _BASE_ } // Called every frame. 'delta' is the elapsed time since the previous frame. - public override void _Process(float delta) + public override void _Process(double delta) { } } diff --git a/modules/mono/editor/script_templates/VisualShaderNodeCustom/basic.cs b/modules/mono/editor/script_templates/VisualShaderNodeCustom/basic.cs index bb482e0d6a..cd335934db 100644 --- a/modules/mono/editor/script_templates/VisualShaderNodeCustom/basic.cs +++ b/modules/mono/editor/script_templates/VisualShaderNodeCustom/basic.cs @@ -20,37 +20,37 @@ public partial class VisualShaderNode_CLASS_ : _BASE_ return ""; } - public override int _GetReturnIconType() + public override long _GetReturnIconType() { return 0; } - public override int _GetInputPortCount() + public override long _GetInputPortCount() { return 0; } - public override string _GetInputPortName(int port) + public override string _GetInputPortName(long port) { return ""; } - public override int _GetInputPortType(int port) + public override long _GetInputPortType(long port) { return 0; } - public override int _GetOutputPortCount() + public override long _GetOutputPortCount() { return 1; } - public override string _GetOutputPortName(int port) + public override string _GetOutputPortName(long port) { return "result"; } - public override int _GetOutputPortType(int port) + public override long _GetOutputPortType(long port) { return 0; } diff --git a/modules/mono/glue/GodotSharp/GodotPlugins/Main.cs b/modules/mono/glue/GodotSharp/GodotPlugins/Main.cs index dad7464410..8308bada24 100644 --- a/modules/mono/glue/GodotSharp/GodotPlugins/Main.cs +++ b/modules/mono/glue/GodotSharp/GodotPlugins/Main.cs @@ -153,7 +153,7 @@ namespace GodotPlugins string assemblyPath = new(nAssemblyPath); if (_editorApiAssembly == null) - throw new InvalidOperationException("The Godot editor API assembly is not loaded"); + throw new InvalidOperationException("The Godot editor API assembly is not loaded."); var (assembly, _) = LoadPlugin(assemblyPath); diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/AABB.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/AABB.cs index b3a36e8ac8..17f680361d 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/AABB.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/AABB.cs @@ -145,6 +145,9 @@ namespace Godot /// Gets the position of one of the 8 endpoints of the <see cref="AABB"/>. /// </summary> /// <param name="idx">Which endpoint to get.</param> + /// <exception cref="ArgumentOutOfRangeException"> + /// <paramref name="idx"/> is less than 0 or greater than 7. + /// </exception> /// <returns>An endpoint of the <see cref="AABB"/>.</returns> public Vector3 GetEndpoint(int idx) { diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Array.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Array.cs index f2984bd1fb..1c98dfcdf6 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Array.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Array.cs @@ -510,7 +510,7 @@ namespace Godot.Collections if (_convertToVariantCallback == null || _convertToManagedCallback == null) { throw new InvalidOperationException( - $"The array element type is not supported for conversion to Variant: '{typeof(T).FullName}'"); + $"The array element type is not supported for conversion to Variant: '{typeof(T).FullName}'."); } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs index 87adf9efe5..fbd59d649f 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs @@ -148,6 +148,9 @@ namespace Godot /// Access whole columns in the form of <see cref="Vector3"/>. /// </summary> /// <param name="column">Which column vector.</param> + /// <exception cref="ArgumentOutOfRangeException"> + /// <paramref name="column"/> is not 0, 1, 2 or 3. + /// </exception> /// <value>The basis column.</value> public Vector3 this[int column] { @@ -366,8 +369,8 @@ namespace Godot /// but are more efficient for some internal calculations. /// </summary> /// <param name="index">Which row.</param> - /// <exception cref="IndexOutOfRangeException"> - /// Thrown when the <paramref name="index"/> is not 0, 1 or 2. + /// <exception cref="ArgumentOutOfRangeException"> + /// <paramref name="index"/> is not 0, 1 or 2. /// </exception> /// <returns>One of <c>Row0</c>, <c>Row1</c>, or <c>Row2</c>.</returns> public Vector3 GetRow(int index) @@ -391,8 +394,8 @@ namespace Godot /// </summary> /// <param name="index">Which row.</param> /// <param name="value">The vector to set the row to.</param> - /// <exception cref="IndexOutOfRangeException"> - /// Thrown when the <paramref name="index"/> is not 0, 1 or 2. + /// <exception cref="ArgumentOutOfRangeException"> + /// <paramref name="index"/> is not 0, 1 or 2. /// </exception> public void SetRow(int index, Vector3 value) { @@ -498,6 +501,15 @@ namespace Godot ); } + internal Basis Lerp(Basis to, real_t weight) + { + Basis b = this; + b.Row0 = Row0.Lerp(to.Row0, weight); + b.Row1 = Row1.Lerp(to.Row1, weight); + b.Row2 = Row2.Lerp(to.Row2, weight); + return b; + } + /// <summary> /// Returns the orthonormalized version of the basis matrix (useful to /// call occasionally to avoid rounding errors for orthogonal matrices). diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/ScriptManagerBridge.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/ScriptManagerBridge.cs index 0dc5ba7678..3884781988 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/ScriptManagerBridge.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/ScriptManagerBridge.cs @@ -831,7 +831,7 @@ namespace Godot.Bridge } else { - interopProperties = ((godotsharp_property_info*)NativeMemory.Alloc((nuint)length))!; + interopProperties = ((godotsharp_property_info*)NativeMemory.Alloc((nuint)length, (nuint)sizeof(godotsharp_property_info)))!; } try @@ -951,7 +951,7 @@ namespace Godot.Bridge } else { - interopDefaultValues = ((godotsharp_property_def_val_pair*)NativeMemory.Alloc((nuint)length))!; + interopDefaultValues = ((godotsharp_property_def_val_pair*)NativeMemory.Alloc((nuint)length, (nuint)sizeof(godotsharp_property_def_val_pair)))!; } try diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs index 0cbaef3dad..33d8aef1a9 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs @@ -595,7 +595,7 @@ namespace Godot /// </summary> /// <param name="rgba">A string for the HTML hexadecimal representation of this color.</param> /// <exception name="ArgumentOutOfRangeException"> - /// Thrown when the given <paramref name="rgba"/> color code is invalid. + /// <paramref name="rgba"/> color code is invalid. /// </exception> private static Color FromHTML(string rgba) { diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Colors.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Colors.cs index bacf7c89e6..5bce66ea87 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Colors.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Colors.cs @@ -10,136 +10,136 @@ namespace Godot { // Color names and values are derived from core/math/color_names.inc internal static readonly Dictionary<string, Color> namedColors = new Dictionary<string, Color> { - { "ALICE_BLUE", new Color(0xF0F8FFFF) }, - { "ANTIQUE_WHITE", new Color(0xFAEBD7FF) }, + { "ALICEBLUE", new Color(0xF0F8FFFF) }, + { "ANTIQUEWHITE", new Color(0xFAEBD7FF) }, { "AQUA", new Color(0x00FFFFFF) }, { "AQUAMARINE", new Color(0x7FFFD4FF) }, { "AZURE", new Color(0xF0FFFFFF) }, { "BEIGE", new Color(0xF5F5DCFF) }, { "BISQUE", new Color(0xFFE4C4FF) }, { "BLACK", new Color(0x000000FF) }, - { "BLANCHED_ALMOND", new Color(0xFFEBCDFF) }, + { "BLANCHEDALMOND", new Color(0xFFEBCDFF) }, { "BLUE", new Color(0x0000FFFF) }, - { "BLUE_VIOLET", new Color(0x8A2BE2FF) }, + { "BLUEVIOLET", new Color(0x8A2BE2FF) }, { "BROWN", new Color(0xA52A2AFF) }, { "BURLYWOOD", new Color(0xDEB887FF) }, - { "CADET_BLUE", new Color(0x5F9EA0FF) }, + { "CADETBLUE", new Color(0x5F9EA0FF) }, { "CHARTREUSE", new Color(0x7FFF00FF) }, { "CHOCOLATE", new Color(0xD2691EFF) }, { "CORAL", new Color(0xFF7F50FF) }, - { "CORNFLOWER_BLUE", new Color(0x6495EDFF) }, + { "CORNFLOWERBLUE", new Color(0x6495EDFF) }, { "CORNSILK", new Color(0xFFF8DCFF) }, { "CRIMSON", new Color(0xDC143CFF) }, { "CYAN", new Color(0x00FFFFFF) }, - { "DARK_BLUE", new Color(0x00008BFF) }, - { "DARK_CYAN", new Color(0x008B8BFF) }, - { "DARK_GOLDENROD", new Color(0xB8860BFF) }, - { "DARK_GRAY", new Color(0xA9A9A9FF) }, - { "DARK_GREEN", new Color(0x006400FF) }, - { "DARK_KHAKI", new Color(0xBDB76BFF) }, - { "DARK_MAGENTA", new Color(0x8B008BFF) }, - { "DARK_OLIVE_GREEN", new Color(0x556B2FFF) }, - { "DARK_ORANGE", new Color(0xFF8C00FF) }, - { "DARK_ORCHID", new Color(0x9932CCFF) }, - { "DARK_RED", new Color(0x8B0000FF) }, - { "DARK_SALMON", new Color(0xE9967AFF) }, - { "DARK_SEA_GREEN", new Color(0x8FBC8FFF) }, - { "DARK_SLATE_BLUE", new Color(0x483D8BFF) }, - { "DARK_SLATE_GRAY", new Color(0x2F4F4FFF) }, - { "DARK_TURQUOISE", new Color(0x00CED1FF) }, - { "DARK_VIOLET", new Color(0x9400D3FF) }, - { "DEEP_PINK", new Color(0xFF1493FF) }, - { "DEEP_SKY_BLUE", new Color(0x00BFFFFF) }, - { "DIM_GRAY", new Color(0x696969FF) }, - { "DODGER_BLUE", new Color(0x1E90FFFF) }, + { "DARKBLUE", new Color(0x00008BFF) }, + { "DARKCYAN", new Color(0x008B8BFF) }, + { "DARKGOLDENROD", new Color(0xB8860BFF) }, + { "DARKGRAY", new Color(0xA9A9A9FF) }, + { "DARKGREEN", new Color(0x006400FF) }, + { "DARKKHAKI", new Color(0xBDB76BFF) }, + { "DARKMAGENTA", new Color(0x8B008BFF) }, + { "DARKOLIVEGREEN", new Color(0x556B2FFF) }, + { "DARKORANGE", new Color(0xFF8C00FF) }, + { "DARKORCHID", new Color(0x9932CCFF) }, + { "DARKRED", new Color(0x8B0000FF) }, + { "DARKSALMON", new Color(0xE9967AFF) }, + { "DARKSEAGREEN", new Color(0x8FBC8FFF) }, + { "DARKSLATEBLUE", new Color(0x483D8BFF) }, + { "DARKSLATEGRAY", new Color(0x2F4F4FFF) }, + { "DARKTURQUOISE", new Color(0x00CED1FF) }, + { "DARKVIOLET", new Color(0x9400D3FF) }, + { "DEEPPINK", new Color(0xFF1493FF) }, + { "DEEPSKYBLUE", new Color(0x00BFFFFF) }, + { "DIMGRAY", new Color(0x696969FF) }, + { "DODGERBLUE", new Color(0x1E90FFFF) }, { "FIREBRICK", new Color(0xB22222FF) }, - { "FLORAL_WHITE", new Color(0xFFFAF0FF) }, - { "FOREST_GREEN", new Color(0x228B22FF) }, + { "FLORALWHITE", new Color(0xFFFAF0FF) }, + { "FORESTGREEN", new Color(0x228B22FF) }, { "FUCHSIA", new Color(0xFF00FFFF) }, { "GAINSBORO", new Color(0xDCDCDCFF) }, - { "GHOST_WHITE", new Color(0xF8F8FFFF) }, + { "GHOSTWHITE", new Color(0xF8F8FFFF) }, { "GOLD", new Color(0xFFD700FF) }, { "GOLDENROD", new Color(0xDAA520FF) }, { "GRAY", new Color(0xBEBEBEFF) }, { "GREEN", new Color(0x00FF00FF) }, - { "GREEN_YELLOW", new Color(0xADFF2FFF) }, + { "GREENYELLOW", new Color(0xADFF2FFF) }, { "HONEYDEW", new Color(0xF0FFF0FF) }, - { "HOT_PINK", new Color(0xFF69B4FF) }, - { "INDIAN_RED", new Color(0xCD5C5CFF) }, + { "HOTPINK", new Color(0xFF69B4FF) }, + { "INDIANRED", new Color(0xCD5C5CFF) }, { "INDIGO", new Color(0x4B0082FF) }, { "IVORY", new Color(0xFFFFF0FF) }, { "KHAKI", new Color(0xF0E68CFF) }, { "LAVENDER", new Color(0xE6E6FAFF) }, - { "LAVENDER_BLUSH", new Color(0xFFF0F5FF) }, - { "LAWN_GREEN", new Color(0x7CFC00FF) }, - { "LEMON_CHIFFON", new Color(0xFFFACDFF) }, - { "LIGHT_BLUE", new Color(0xADD8E6FF) }, - { "LIGHT_CORAL", new Color(0xF08080FF) }, - { "LIGHT_CYAN", new Color(0xE0FFFFFF) }, - { "LIGHT_GOLDENROD", new Color(0xFAFAD2FF) }, - { "LIGHT_GRAY", new Color(0xD3D3D3FF) }, - { "LIGHT_GREEN", new Color(0x90EE90FF) }, - { "LIGHT_PINK", new Color(0xFFB6C1FF) }, - { "LIGHT_SALMON", new Color(0xFFA07AFF) }, - { "LIGHT_SEA_GREEN", new Color(0x20B2AAFF) }, - { "LIGHT_SKY_BLUE", new Color(0x87CEFAFF) }, - { "LIGHT_SLATE_GRAY", new Color(0x778899FF) }, - { "LIGHT_STEEL_BLUE", new Color(0xB0C4DEFF) }, - { "LIGHT_YELLOW", new Color(0xFFFFE0FF) }, + { "LAVENDERBLUSH", new Color(0xFFF0F5FF) }, + { "LAWNGREEN", new Color(0x7CFC00FF) }, + { "LEMONCHIFFON", new Color(0xFFFACDFF) }, + { "LIGHTBLUE", new Color(0xADD8E6FF) }, + { "LIGHTCORAL", new Color(0xF08080FF) }, + { "LIGHTCYAN", new Color(0xE0FFFFFF) }, + { "LIGHTGOLDENROD", new Color(0xFAFAD2FF) }, + { "LIGHTGRAY", new Color(0xD3D3D3FF) }, + { "LIGHTGREEN", new Color(0x90EE90FF) }, + { "LIGHTPINK", new Color(0xFFB6C1FF) }, + { "LIGHTSALMON", new Color(0xFFA07AFF) }, + { "LIGHTSEAGREEN", new Color(0x20B2AAFF) }, + { "LIGHTSKYBLUE", new Color(0x87CEFAFF) }, + { "LIGHTSLATEGRAY", new Color(0x778899FF) }, + { "LIGHTSTEELBLUE", new Color(0xB0C4DEFF) }, + { "LIGHTYELLOW", new Color(0xFFFFE0FF) }, { "LIME", new Color(0x00FF00FF) }, - { "LIME_GREEN", new Color(0x32CD32FF) }, + { "LIMEGREEN", new Color(0x32CD32FF) }, { "LINEN", new Color(0xFAF0E6FF) }, { "MAGENTA", new Color(0xFF00FFFF) }, { "MAROON", new Color(0xB03060FF) }, - { "MEDIUM_AQUAMARINE", new Color(0x66CDAAFF) }, - { "MEDIUM_BLUE", new Color(0x0000CDFF) }, - { "MEDIUM_ORCHID", new Color(0xBA55D3FF) }, - { "MEDIUM_PURPLE", new Color(0x9370DBFF) }, - { "MEDIUM_SEA_GREEN", new Color(0x3CB371FF) }, - { "MEDIUM_SLATE_BLUE", new Color(0x7B68EEFF) }, - { "MEDIUM_SPRING_GREEN", new Color(0x00FA9AFF) }, - { "MEDIUM_TURQUOISE", new Color(0x48D1CCFF) }, - { "MEDIUM_VIOLET_RED", new Color(0xC71585FF) }, - { "MIDNIGHT_BLUE", new Color(0x191970FF) }, - { "MINT_CREAM", new Color(0xF5FFFAFF) }, - { "MISTY_ROSE", new Color(0xFFE4E1FF) }, + { "MEDIUMAQUAMARINE", new Color(0x66CDAAFF) }, + { "MEDIUMBLUE", new Color(0x0000CDFF) }, + { "MEDIUMORCHID", new Color(0xBA55D3FF) }, + { "MEDIUMPURPLE", new Color(0x9370DBFF) }, + { "MEDIUMSEAGREEN", new Color(0x3CB371FF) }, + { "MEDIUMSLATEBLUE", new Color(0x7B68EEFF) }, + { "MEDIUMSPRINGGREEN", new Color(0x00FA9AFF) }, + { "MEDIUMTURQUOISE", new Color(0x48D1CCFF) }, + { "MEDIUMVIOLETRED", new Color(0xC71585FF) }, + { "MIDNIGHTBLUE", new Color(0x191970FF) }, + { "MINTCREAM", new Color(0xF5FFFAFF) }, + { "MISTYROSE", new Color(0xFFE4E1FF) }, { "MOCCASIN", new Color(0xFFE4B5FF) }, - { "NAVAJO_WHITE", new Color(0xFFDEADFF) }, - { "NAVY_BLUE", new Color(0x000080FF) }, - { "OLD_LACE", new Color(0xFDF5E6FF) }, + { "NAVAJOWHITE", new Color(0xFFDEADFF) }, + { "NAVYBLUE", new Color(0x000080FF) }, + { "OLDLACE", new Color(0xFDF5E6FF) }, { "OLIVE", new Color(0x808000FF) }, - { "OLIVE_DRAB", new Color(0x6B8E23FF) }, + { "OLIVEDRAB", new Color(0x6B8E23FF) }, { "ORANGE", new Color(0xFFA500FF) }, - { "ORANGE_RED", new Color(0xFF4500FF) }, + { "ORANGERED", new Color(0xFF4500FF) }, { "ORCHID", new Color(0xDA70D6FF) }, - { "PALE_GOLDENROD", new Color(0xEEE8AAFF) }, - { "PALE_GREEN", new Color(0x98FB98FF) }, - { "PALE_TURQUOISE", new Color(0xAFEEEEFF) }, - { "PALE_VIOLET_RED", new Color(0xDB7093FF) }, - { "PAPAYA_WHIP", new Color(0xFFEFD5FF) }, - { "PEACH_PUFF", new Color(0xFFDAB9FF) }, + { "PALEGOLDENROD", new Color(0xEEE8AAFF) }, + { "PALEGREEN", new Color(0x98FB98FF) }, + { "PALETURQUOISE", new Color(0xAFEEEEFF) }, + { "PALEVIOLETRED", new Color(0xDB7093FF) }, + { "PAPAYAWHIP", new Color(0xFFEFD5FF) }, + { "PEACHPUFF", new Color(0xFFDAB9FF) }, { "PERU", new Color(0xCD853FFF) }, { "PINK", new Color(0xFFC0CBFF) }, { "PLUM", new Color(0xDDA0DDFF) }, - { "POWDER_BLUE", new Color(0xB0E0E6FF) }, + { "POWDERBLUE", new Color(0xB0E0E6FF) }, { "PURPLE", new Color(0xA020F0FF) }, - { "REBECCA_PURPLE", new Color(0x663399FF) }, + { "REBECCAPURPLE", new Color(0x663399FF) }, { "RED", new Color(0xFF0000FF) }, - { "ROSY_BROWN", new Color(0xBC8F8FFF) }, - { "ROYAL_BLUE", new Color(0x4169E1FF) }, - { "SADDLE_BROWN", new Color(0x8B4513FF) }, + { "ROSYBROWN", new Color(0xBC8F8FFF) }, + { "ROYALBLUE", new Color(0x4169E1FF) }, + { "SADDLEBROWN", new Color(0x8B4513FF) }, { "SALMON", new Color(0xFA8072FF) }, - { "SANDY_BROWN", new Color(0xF4A460FF) }, - { "SEA_GREEN", new Color(0x2E8B57FF) }, + { "SANDYBROWN", new Color(0xF4A460FF) }, + { "SEAGREEN", new Color(0x2E8B57FF) }, { "SEASHELL", new Color(0xFFF5EEFF) }, { "SIENNA", new Color(0xA0522DFF) }, { "SILVER", new Color(0xC0C0C0FF) }, - { "SKY_BLUE", new Color(0x87CEEBFF) }, - { "SLATE_BLUE", new Color(0x6A5ACDFF) }, - { "SLATE_GRAY", new Color(0x708090FF) }, + { "SKYBLUE", new Color(0x87CEEBFF) }, + { "SLATEBLUE", new Color(0x6A5ACDFF) }, + { "SLATEGRAY", new Color(0x708090FF) }, { "SNOW", new Color(0xFFFAFAFF) }, - { "SPRING_GREEN", new Color(0x00FF7FFF) }, - { "STEEL_BLUE", new Color(0x4682B4FF) }, + { "SPRINGGREEN", new Color(0x00FF7FFF) }, + { "STEELBLUE", new Color(0x4682B4FF) }, { "TAN", new Color(0xD2B48CFF) }, { "TEAL", new Color(0x008080FF) }, { "THISTLE", new Color(0xD8BFD8FF) }, @@ -147,15 +147,15 @@ namespace Godot { "TRANSPARENT", new Color(0xFFFFFF00) }, { "TURQUOISE", new Color(0x40E0D0FF) }, { "VIOLET", new Color(0xEE82EEFF) }, - { "WEB_GRAY", new Color(0x808080FF) }, - { "WEB_GREEN", new Color(0x008000FF) }, - { "WEB_MAROON", new Color(0x800000FF) }, - { "WEB_PURPLE", new Color(0x800080FF) }, + { "WEBGRAY", new Color(0x808080FF) }, + { "WEBGREEN", new Color(0x008000FF) }, + { "WEBMAROON", new Color(0x800000FF) }, + { "WEBPURPLE", new Color(0x800080FF) }, { "WHEAT", new Color(0xF5DEB3FF) }, { "WHITE", new Color(0xFFFFFFFF) }, - { "WHITE_SMOKE", new Color(0xF5F5F5FF) }, + { "WHITESMOKE", new Color(0xF5F5F5FF) }, { "YELLOW", new Color(0xFFFF00FF) }, - { "YELLOW_GREEN", new Color(0x9ACD32FF) }, + { "YELLOWGREEN", new Color(0x9ACD32FF) }, }; #pragma warning disable CS1591 // Disable warning: "Missing XML comment for publicly visible type or member" diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Dictionary.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Dictionary.cs index 95ad097192..93103d0f6b 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Dictionary.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Dictionary.cs @@ -171,7 +171,7 @@ namespace Godot.Collections var self = (godot_dictionary)NativeValue; if (NativeFuncs.godotsharp_dictionary_contains_key(ref self, variantKey).ToBool()) - throw new ArgumentException("An element with the same key already exists", nameof(key)); + throw new ArgumentException("An element with the same key already exists.", nameof(key)); godot_variant variantValue = (godot_variant)value.NativeVar; NativeFuncs.godotsharp_dictionary_add(ref self, variantKey, variantValue); @@ -381,13 +381,13 @@ namespace Godot.Collections if (_convertKeyToVariantCallback == null || _convertKeyToManagedCallback == null) { throw new InvalidOperationException( - $"The dictionary key type is not supported for conversion to Variant: '{typeof(TKey).FullName}'"); + $"The dictionary key type is not supported for conversion to Variant: '{typeof(TKey).FullName}'."); } if (_convertValueToVariantCallback == null || _convertValueToManagedCallback == null) { throw new InvalidOperationException( - $"The dictionary value type is not supported for conversion to Variant: '{typeof(TValue).FullName}'"); + $"The dictionary value type is not supported for conversion to Variant: '{typeof(TValue).FullName}'."); } } @@ -556,7 +556,7 @@ namespace Godot.Collections var self = (godot_dictionary)_underlyingDict.NativeValue; if (NativeFuncs.godotsharp_dictionary_contains_key(ref self, variantKey).ToBool()) - throw new ArgumentException("An element with the same key already exists", nameof(key)); + throw new ArgumentException("An element with the same key already exists.", nameof(key)); using var variantValue = _convertValueToVariantCallback(value); NativeFuncs.godotsharp_dictionary_add(ref self, variantKey, variantValue); diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/DisposablesTracker.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/DisposablesTracker.cs index 75793ea446..421b588560 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/DisposablesTracker.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/DisposablesTracker.cs @@ -83,13 +83,13 @@ namespace Godot public static void UnregisterGodotObject(Object godotObject, WeakReference<Object> weakReferenceToSelf) { if (!GodotObjectInstances.TryRemove(weakReferenceToSelf, out _)) - throw new ArgumentException("Godot Object not registered", nameof(weakReferenceToSelf)); + throw new ArgumentException("Godot Object not registered.", nameof(weakReferenceToSelf)); } public static void UnregisterDisposable(WeakReference<IDisposable> weakReference) { if (!OtherInstances.TryRemove(weakReference, out _)) - throw new ArgumentException("Disposable not registered", nameof(weakReference)); + throw new ArgumentException("Disposable not registered.", nameof(weakReference)); } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Extensions/NodeExtensions.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Extensions/NodeExtensions.cs index df0e839866..03996bafdd 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Extensions/NodeExtensions.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Extensions/NodeExtensions.cs @@ -36,7 +36,7 @@ namespace Godot /// <seealso cref="GetNodeOrNull{T}(NodePath)"/> /// <param name="path">The path to the node to fetch.</param> /// <exception cref="InvalidCastException"> - /// Thrown when the given the fetched node can't be casted to the given type <typeparamref name="T"/>. + /// The fetched node can't be casted to the given type <typeparamref name="T"/>. /// </exception> /// <typeparam name="T">The type to cast to. Should be a descendant of <see cref="Node"/>.</typeparam> /// <returns> @@ -100,7 +100,7 @@ namespace Godot /// parameter in <see cref="AddChild(Node, bool, InternalMode)"/>). /// </param> /// <exception cref="InvalidCastException"> - /// Thrown when the given the fetched node can't be casted to the given type <typeparamref name="T"/>. + /// The fetched node can't be casted to the given type <typeparamref name="T"/>. /// </exception> /// <typeparam name="T">The type to cast to. Should be a descendant of <see cref="Node"/>.</typeparam> /// <returns> @@ -142,7 +142,7 @@ namespace Godot /// </summary> /// <seealso cref="GetOwnerOrNull{T}"/> /// <exception cref="InvalidCastException"> - /// Thrown when the given the fetched node can't be casted to the given type <typeparamref name="T"/>. + /// The fetched node can't be casted to the given type <typeparamref name="T"/>. /// </exception> /// <typeparam name="T">The type to cast to. Should be a descendant of <see cref="Node"/>.</typeparam> /// <returns> @@ -176,7 +176,7 @@ namespace Godot /// </summary> /// <seealso cref="GetParentOrNull{T}"/> /// <exception cref="InvalidCastException"> - /// Thrown when the given the fetched node can't be casted to the given type <typeparamref name="T"/>. + /// The fetched node can't be casted to the given type <typeparamref name="T"/>. /// </exception> /// <typeparam name="T">The type to cast to. Should be a descendant of <see cref="Node"/>.</typeparam> /// <returns> diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Extensions/PackedSceneExtensions.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Extensions/PackedSceneExtensions.cs index 435b59d5f3..8463403096 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Extensions/PackedSceneExtensions.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Extensions/PackedSceneExtensions.cs @@ -11,7 +11,7 @@ namespace Godot /// </summary> /// <seealso cref="InstantiateOrNull{T}(GenEditState)"/> /// <exception cref="InvalidCastException"> - /// Thrown when the given the instantiated node can't be casted to the given type <typeparamref name="T"/>. + /// The instantiated node can't be casted to the given type <typeparamref name="T"/>. /// </exception> /// <typeparam name="T">The type to cast to. Should be a descendant of <see cref="Node"/>.</typeparam> /// <returns>The instantiated scene.</returns> diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Extensions/ResourceLoaderExtensions.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Extensions/ResourceLoaderExtensions.cs index 25c11d5cf6..b246e56fa9 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Extensions/ResourceLoaderExtensions.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Extensions/ResourceLoaderExtensions.cs @@ -19,7 +19,7 @@ namespace Godot /// Returns an empty resource if no <see cref="ResourceFormatLoader"/> could handle the file. /// </summary> /// <exception cref="InvalidCastException"> - /// Thrown when the given the loaded resource can't be casted to the given type <typeparamref name="T"/>. + /// The loaded resource can't be casted to the given type <typeparamref name="T"/>. /// </exception> /// <typeparam name="T">The type to cast to. Should be a descendant of <see cref="Resource"/>.</typeparam> public static T Load<T>(string path, string typeHint = null, CacheMode cacheMode = CacheMode.Reuse) where T : class diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Mathf.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Mathf.cs index 00e775e6ad..b30012d214 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Mathf.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Mathf.cs @@ -175,7 +175,8 @@ namespace Godot } /// <summary> - /// Cubic interpolates between two values by a normalized value with pre and post values. + /// Cubic interpolates between two values by the factor defined in <paramref name="weight"/> + /// with pre and post values. /// </summary> /// <param name="from">The start value for interpolation.</param> /// <param name="to">The destination value for interpolation.</param> @@ -193,6 +194,93 @@ namespace Godot } /// <summary> + /// Cubic interpolates between two rotation values with shortest path + /// by the factor defined in <paramref name="weight"/> with pre and post values. + /// See also <see cref="LerpAngle"/>. + /// </summary> + /// <param name="from">The start value for interpolation.</param> + /// <param name="to">The destination value for interpolation.</param> + /// <param name="pre">The value which before "from" value for interpolation.</param> + /// <param name="post">The value which after "to" value for interpolation.</param> + /// <param name="weight">A value on the range of 0.0 to 1.0, representing the amount of interpolation.</param> + /// <returns>The resulting value of the interpolation.</returns> + public static real_t CubicInterpolateAngle(real_t from, real_t to, real_t pre, real_t post, real_t weight) + { + real_t fromRot = from % Mathf.Tau; + + real_t preDiff = (pre - fromRot) % Mathf.Tau; + real_t preRot = fromRot + (2.0f * preDiff) % Mathf.Tau - preDiff; + + real_t toDiff = (to - fromRot) % Mathf.Tau; + real_t toRot = fromRot + (2.0f * toDiff) % Mathf.Tau - toDiff; + + real_t postDiff = (post - toRot) % Mathf.Tau; + real_t postRot = toRot + (2.0f * postDiff) % Mathf.Tau - postDiff; + + return CubicInterpolate(fromRot, toRot, preRot, postRot, weight); + } + + /// <summary> + /// Cubic interpolates between two values by the factor defined in <paramref name="weight"/> + /// with pre and post values. + /// It can perform smoother interpolation than <see cref="CubicInterpolate"/> + /// by the time values. + /// </summary> + /// <param name="from">The start value for interpolation.</param> + /// <param name="to">The destination value for interpolation.</param> + /// <param name="pre">The value which before "from" value for interpolation.</param> + /// <param name="post">The value which after "to" value for interpolation.</param> + /// <param name="weight">A value on the range of 0.0 to 1.0, representing the amount of interpolation.</param> + /// <param name="toT"></param> + /// <param name="preT"></param> + /// <param name="postT"></param> + /// <returns>The resulting value of the interpolation.</returns> + public static real_t CubicInterpolateInTime(real_t from, real_t to, real_t pre, real_t post, real_t weight, real_t toT, real_t preT, real_t postT) + { + /* Barry-Goldman method */ + real_t t = Lerp(0.0f, toT, weight); + real_t a1 = Lerp(pre, from, preT == 0 ? 0.0f : (t - preT) / -preT); + real_t a2 = Lerp(from, to, toT == 0 ? 0.5f : t / toT); + real_t a3 = Lerp(to, post, postT - toT == 0 ? 1.0f : (t - toT) / (postT - toT)); + real_t b1 = Lerp(a1, a2, toT - preT == 0 ? 0.0f : (t - preT) / (toT - preT)); + real_t b2 = Lerp(a2, a3, postT == 0 ? 1.0f : t / postT); + return Lerp(b1, b2, toT == 0 ? 0.5f : t / toT); + } + + /// <summary> + /// Cubic interpolates between two rotation values with shortest path + /// by the factor defined in <paramref name="weight"/> with pre and post values. + /// See also <see cref="LerpAngle"/>. + /// It can perform smoother interpolation than <see cref="CubicInterpolateAngle"/> + /// by the time values. + /// </summary> + /// <param name="from">The start value for interpolation.</param> + /// <param name="to">The destination value for interpolation.</param> + /// <param name="pre">The value which before "from" value for interpolation.</param> + /// <param name="post">The value which after "to" value for interpolation.</param> + /// <param name="weight">A value on the range of 0.0 to 1.0, representing the amount of interpolation.</param> + /// <param name="toT"></param> + /// <param name="preT"></param> + /// <param name="postT"></param> + /// <returns>The resulting value of the interpolation.</returns> + public static real_t CubicInterpolateAngleInTime(real_t from, real_t to, real_t pre, real_t post, real_t weight, + real_t toT, real_t preT, real_t postT) + { + real_t fromRot = from % Mathf.Tau; + + real_t preDiff = (pre - fromRot) % Mathf.Tau; + real_t preRot = fromRot + (2.0f * preDiff) % Mathf.Tau - preDiff; + + real_t toDiff = (to - fromRot) % Mathf.Tau; + real_t toRot = fromRot + (2.0f * toDiff) % Mathf.Tau - toDiff; + + real_t postDiff = (post - toRot) % Mathf.Tau; + real_t postRot = toRot + (2.0f * postDiff) % Mathf.Tau - postDiff; + + return CubicInterpolateInTime(fromRot, toRot, preRot, postRot, weight, toT, preT, postT); + } + + /// <summary> /// Returns the point at the given <paramref name="t"/> on a one-dimensional Bezier curve defined by /// the given <paramref name="control1"/>, <paramref name="control2"/> and <paramref name="end"/> points. /// </summary> diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/InteropStructs.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/InteropStructs.cs index 44806e8ecf..fa79c2efbc 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/InteropStructs.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/InteropStructs.cs @@ -130,14 +130,14 @@ namespace Godot.NativeInterop [FieldOffset(0)] public AABB* _aabb; [FieldOffset(0)] public Basis* _basis; [FieldOffset(0)] public Transform3D* _transform3D; - [FieldOffset(0)] public Vector4* _vector4; - [FieldOffset(0)] public Vector4i* _vector4i; [FieldOffset(0)] public Projection* _projection; [FieldOffset(0)] private godot_variant_data_mem _mem; // The following fields are not in the C++ union, but this is how they're stored in _mem. [FieldOffset(0)] public godot_string_name _m_string_name; [FieldOffset(0)] public godot_string _m_string; + [FieldOffset(0)] public Vector4 _m_vector4; + [FieldOffset(0)] public Vector4i _m_vector4i; [FieldOffset(0)] public Vector3 _m_vector3; [FieldOffset(0)] public Vector3i _m_vector3i; [FieldOffset(0)] public Vector2 _m_vector2; @@ -232,18 +232,6 @@ namespace Godot.NativeInterop get => _data._transform3D; } - public readonly unsafe Vector4* Vector4 - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => _data._vector4; - } - - public readonly unsafe Vector4i* Vector4i - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => _data._vector4i; - } - public readonly unsafe Projection* Projection { [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -266,6 +254,22 @@ namespace Godot.NativeInterop set => _data._m_string = value; } + public Vector4 Vector4 + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + readonly get => _data._m_vector4; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + set => _data._m_vector4 = value; + } + + public Vector4i Vector4i + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + readonly get => _data._m_vector4i; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + set => _data._m_vector4i = value; + } + public Vector3 Vector3 { [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -406,6 +410,8 @@ namespace Godot.NativeInterop case Variant.Type.Rect2i: case Variant.Type.Vector3: case Variant.Type.Vector3i: + case Variant.Type.Vector4: + case Variant.Type.Vector4i: case Variant.Type.Plane: case Variant.Type.Quaternion: case Variant.Type.Color: diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/Marshaling.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/Marshaling.cs index eee19aea46..140fc167ba 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/Marshaling.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/Marshaling.cs @@ -613,9 +613,9 @@ namespace Godot.NativeInterop case Variant.Type.Transform2d: return *p_var.Transform2D; case Variant.Type.Vector4: - return *p_var.Vector4; + return p_var.Vector4; case Variant.Type.Vector4i: - return *p_var.Vector4i; + return p_var.Vector4i; case Variant.Type.Plane: return p_var.Plane; case Variant.Type.Quaternion: diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/NativeFuncs.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/NativeFuncs.cs index 48c1b48c59..bd00611383 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/NativeFuncs.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/NativeFuncs.cs @@ -22,11 +22,11 @@ namespace Godot.NativeInterop public static void Initialize(IntPtr unmanagedCallbacks, int unmanagedCallbacksSize) { if (initialized) - throw new InvalidOperationException("Already initialized"); + throw new InvalidOperationException("Already initialized."); initialized = true; if (unmanagedCallbacksSize != sizeof(UnmanagedCallbacks)) - throw new ArgumentException("Unmanaged callbacks size mismatch"); + throw new ArgumentException("Unmanaged callbacks size mismatch.", nameof(unmanagedCallbacksSize)); _unmanagedCallbacks = Unsafe.AsRef<UnmanagedCallbacks>((void*)unmanagedCallbacks); } @@ -176,10 +176,6 @@ namespace Godot.NativeInterop public static partial void godotsharp_variant_new_transform2d(out godot_variant r_dest, in Transform2D p_t2d); - public static partial void godotsharp_variant_new_vector4(out godot_variant r_dest, in Vector4 p_vec4); - - public static partial void godotsharp_variant_new_vector4i(out godot_variant r_dest, in Vector4i p_vec4i); - public static partial void godotsharp_variant_new_basis(out godot_variant r_dest, in Basis p_basis); public static partial void godotsharp_variant_new_transform3d(out godot_variant r_dest, in Transform3D p_trans); @@ -436,6 +432,15 @@ namespace Godot.NativeInterop public static partial void godotsharp_string_simplify_path(in godot_string p_self, out godot_string r_simplified_path); + public static partial void godotsharp_string_to_camel_case(in godot_string p_self, + out godot_string r_camel_case); + + public static partial void godotsharp_string_to_pascal_case(in godot_string p_self, + out godot_string r_pascal_case); + + public static partial void godotsharp_string_to_snake_case(in godot_string p_self, + out godot_string r_snake_case); + // NodePath public static partial void godotsharp_node_path_get_as_property_path(in godot_node_path p_self, diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/NativeFuncs.extended.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/NativeFuncs.extended.cs index 2ea3c18d26..9f0b55431b 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/NativeFuncs.extended.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/NativeFuncs.extended.cs @@ -11,31 +11,35 @@ namespace Godot.NativeInterop case Variant.Type.Nil: return default; case Variant.Type.Bool: - return new godot_variant() { Bool = src.Bool }; + return new godot_variant() { Bool = src.Bool, Type = Variant.Type.Bool }; case Variant.Type.Int: - return new godot_variant() { Int = src.Int }; + return new godot_variant() { Int = src.Int, Type = Variant.Type.Int }; case Variant.Type.Float: - return new godot_variant() { Float = src.Float }; + return new godot_variant() { Float = src.Float, Type = Variant.Type.Float }; case Variant.Type.Vector2: - return new godot_variant() { Vector2 = src.Vector2 }; + return new godot_variant() { Vector2 = src.Vector2, Type = Variant.Type.Vector2 }; case Variant.Type.Vector2i: - return new godot_variant() { Vector2i = src.Vector2i }; + return new godot_variant() { Vector2i = src.Vector2i, Type = Variant.Type.Vector2i }; case Variant.Type.Rect2: - return new godot_variant() { Rect2 = src.Rect2 }; + return new godot_variant() { Rect2 = src.Rect2, Type = Variant.Type.Rect2 }; case Variant.Type.Rect2i: - return new godot_variant() { Rect2i = src.Rect2i }; + return new godot_variant() { Rect2i = src.Rect2i, Type = Variant.Type.Rect2i }; case Variant.Type.Vector3: - return new godot_variant() { Vector3 = src.Vector3 }; + return new godot_variant() { Vector3 = src.Vector3, Type = Variant.Type.Vector3 }; case Variant.Type.Vector3i: - return new godot_variant() { Vector3i = src.Vector3i }; + return new godot_variant() { Vector3i = src.Vector3i, Type = Variant.Type.Vector3i }; + case Variant.Type.Vector4: + return new godot_variant() { Vector4 = src.Vector4, Type = Variant.Type.Vector4 }; + case Variant.Type.Vector4i: + return new godot_variant() { Vector4i = src.Vector4i, Type = Variant.Type.Vector4i }; case Variant.Type.Plane: - return new godot_variant() { Plane = src.Plane }; + return new godot_variant() { Plane = src.Plane, Type = Variant.Type.Plane }; case Variant.Type.Quaternion: - return new godot_variant() { Quaternion = src.Quaternion }; + return new godot_variant() { Quaternion = src.Quaternion, Type = Variant.Type.Quaternion }; case Variant.Type.Color: - return new godot_variant() { Color = src.Color }; + return new godot_variant() { Color = src.Color, Type = Variant.Type.Color }; case Variant.Type.Rid: - return new godot_variant() { RID = src.RID }; + return new godot_variant() { RID = src.RID, Type = Variant.Type.Rid }; } godotsharp_variant_new_copy(out godot_variant ret, src); diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/VariantConversionCallbacks.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/VariantConversionCallbacks.cs index 2b5bf2e142..9cde62c7c5 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/VariantConversionCallbacks.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/VariantConversionCallbacks.cs @@ -6,7 +6,7 @@ namespace Godot.NativeInterop; internal static unsafe class VariantConversionCallbacks { [SuppressMessage("ReSharper", "RedundantNameQualifier")] - internal static delegate* <in T, godot_variant> GetToVariantCallback<T>() + internal static delegate*<in T, godot_variant> GetToVariantCallback<T>() { static godot_variant FromBool(in bool @bool) => VariantUtils.CreateFromBool(@bool); @@ -74,6 +74,12 @@ internal static unsafe class VariantConversionCallbacks static godot_variant FromTransform3D(in Transform3D @transform3d) => VariantUtils.CreateFromTransform3D(@transform3d); + static godot_variant FromVector4(in Vector4 @vector4) => + VariantUtils.CreateFromVector4(@vector4); + + static godot_variant FromVector4I(in Vector4i vector4I) => + VariantUtils.CreateFromVector4i(vector4I); + static godot_variant FromAabb(in AABB @aabb) => VariantUtils.CreateFromAABB(@aabb); @@ -153,163 +159,175 @@ internal static unsafe class VariantConversionCallbacks if (typeOfT == typeof(bool)) { - return (delegate* <in T, godot_variant>)(delegate* <in bool, godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in bool, godot_variant>) &FromBool; } if (typeOfT == typeof(char)) { - return (delegate* <in T, godot_variant>)(delegate* <in char, godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in char, godot_variant>) &FromChar; } if (typeOfT == typeof(sbyte)) { - return (delegate* <in T, godot_variant>)(delegate* <in sbyte, godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in sbyte, godot_variant>) &FromInt8; } if (typeOfT == typeof(short)) { - return (delegate* <in T, godot_variant>)(delegate* <in short, godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in short, godot_variant>) &FromInt16; } if (typeOfT == typeof(int)) { - return (delegate* <in T, godot_variant>)(delegate* <in int, godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in int, godot_variant>) &FromInt32; } if (typeOfT == typeof(long)) { - return (delegate* <in T, godot_variant>)(delegate* <in long, godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in long, godot_variant>) &FromInt64; } if (typeOfT == typeof(byte)) { - return (delegate* <in T, godot_variant>)(delegate* <in byte, godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in byte, godot_variant>) &FromUInt8; } if (typeOfT == typeof(ushort)) { - return (delegate* <in T, godot_variant>)(delegate* <in ushort, godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in ushort, godot_variant>) &FromUInt16; } if (typeOfT == typeof(uint)) { - return (delegate* <in T, godot_variant>)(delegate* <in uint, godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in uint, godot_variant>) &FromUInt32; } if (typeOfT == typeof(ulong)) { - return (delegate* <in T, godot_variant>)(delegate* <in ulong, godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in ulong, godot_variant>) &FromUInt64; } if (typeOfT == typeof(float)) { - return (delegate* <in T, godot_variant>)(delegate* <in float, godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in float, godot_variant>) &FromFloat; } if (typeOfT == typeof(double)) { - return (delegate* <in T, godot_variant>)(delegate* <in double, godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in double, godot_variant>) &FromDouble; } if (typeOfT == typeof(Vector2)) { - return (delegate* <in T, godot_variant>)(delegate* <in Vector2, godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in Vector2, godot_variant>) &FromVector2; } if (typeOfT == typeof(Vector2i)) { - return (delegate* <in T, godot_variant>)(delegate* <in Vector2i, godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in Vector2i, godot_variant>) &FromVector2I; } if (typeOfT == typeof(Rect2)) { - return (delegate* <in T, godot_variant>)(delegate* <in Rect2, godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in Rect2, godot_variant>) &FromRect2; } if (typeOfT == typeof(Rect2i)) { - return (delegate* <in T, godot_variant>)(delegate* <in Rect2i, godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in Rect2i, godot_variant>) &FromRect2I; } if (typeOfT == typeof(Transform2D)) { - return (delegate* <in T, godot_variant>)(delegate* <in Transform2D, godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in Transform2D, godot_variant>) &FromTransform2D; } if (typeOfT == typeof(Vector3)) { - return (delegate* <in T, godot_variant>)(delegate* <in Vector3, godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in Vector3, godot_variant>) &FromVector3; } if (typeOfT == typeof(Vector3i)) { - return (delegate* <in T, godot_variant>)(delegate* <in Vector3i, godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in Vector3i, godot_variant>) &FromVector3I; } if (typeOfT == typeof(Basis)) { - return (delegate* <in T, godot_variant>)(delegate* <in Basis, godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in Basis, godot_variant>) &FromBasis; } if (typeOfT == typeof(Quaternion)) { - return (delegate* <in T, godot_variant>)(delegate* <in Quaternion, godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in Quaternion, godot_variant>) &FromQuaternion; } if (typeOfT == typeof(Transform3D)) { - return (delegate* <in T, godot_variant>)(delegate* <in Transform3D, godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in Transform3D, godot_variant>) &FromTransform3D; } + if (typeOfT == typeof(Vector4)) + { + return (delegate*<in T, godot_variant>)(delegate*<in Vector4, godot_variant>) + &FromVector4; + } + + if (typeOfT == typeof(Vector4i)) + { + return (delegate*<in T, godot_variant>)(delegate*<in Vector4i, godot_variant>) + &FromVector4I; + } + if (typeOfT == typeof(AABB)) { - return (delegate* <in T, godot_variant>)(delegate* <in AABB, godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in AABB, godot_variant>) &FromAabb; } if (typeOfT == typeof(Color)) { - return (delegate* <in T, godot_variant>)(delegate* <in Color, godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in Color, godot_variant>) &FromColor; } if (typeOfT == typeof(Plane)) { - return (delegate* <in T, godot_variant>)(delegate* <in Plane, godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in Plane, godot_variant>) &FromPlane; } if (typeOfT == typeof(Callable)) { - return (delegate* <in T, godot_variant>)(delegate* <in Callable, godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in Callable, godot_variant>) &FromCallable; } if (typeOfT == typeof(SignalInfo)) { - return (delegate* <in T, godot_variant>)(delegate* <in SignalInfo, godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in SignalInfo, godot_variant>) &FromSignalInfo; } @@ -321,42 +339,42 @@ internal static unsafe class VariantConversionCallbacks { case TypeCode.SByte: { - return (delegate* <in T, godot_variant>)(delegate* <in sbyte, godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in sbyte, godot_variant>) &FromInt8; } case TypeCode.Int16: { - return (delegate* <in T, godot_variant>)(delegate* <in short, godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in short, godot_variant>) &FromInt16; } case TypeCode.Int32: { - return (delegate* <in T, godot_variant>)(delegate* <in int, godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in int, godot_variant>) &FromInt32; } case TypeCode.Int64: { - return (delegate* <in T, godot_variant>)(delegate* <in long, godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in long, godot_variant>) &FromInt64; } case TypeCode.Byte: { - return (delegate* <in T, godot_variant>)(delegate* <in byte, godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in byte, godot_variant>) &FromUInt8; } case TypeCode.UInt16: { - return (delegate* <in T, godot_variant>)(delegate* <in ushort, godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in ushort, godot_variant>) &FromUInt16; } case TypeCode.UInt32: { - return (delegate* <in T, godot_variant>)(delegate* <in uint, godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in uint, godot_variant>) &FromUInt32; } case TypeCode.UInt64: { - return (delegate* <in T, godot_variant>)(delegate* <in ulong, godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in ulong, godot_variant>) &FromUInt64; } default: @@ -366,121 +384,121 @@ internal static unsafe class VariantConversionCallbacks if (typeOfT == typeof(string)) { - return (delegate* <in T, godot_variant>)(delegate* <in string, godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in string, godot_variant>) &FromString; } if (typeOfT == typeof(byte[])) { - return (delegate* <in T, godot_variant>)(delegate* <in byte[], godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in byte[], godot_variant>) &FromByteArray; } if (typeOfT == typeof(int[])) { - return (delegate* <in T, godot_variant>)(delegate* <in int[], godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in int[], godot_variant>) &FromInt32Array; } if (typeOfT == typeof(long[])) { - return (delegate* <in T, godot_variant>)(delegate* <in long[], godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in long[], godot_variant>) &FromInt64Array; } if (typeOfT == typeof(float[])) { - return (delegate* <in T, godot_variant>)(delegate* <in float[], godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in float[], godot_variant>) &FromFloatArray; } if (typeOfT == typeof(double[])) { - return (delegate* <in T, godot_variant>)(delegate* <in double[], godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in double[], godot_variant>) &FromDoubleArray; } if (typeOfT == typeof(string[])) { - return (delegate* <in T, godot_variant>)(delegate* <in string[], godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in string[], godot_variant>) &FromStringArray; } if (typeOfT == typeof(Vector2[])) { - return (delegate* <in T, godot_variant>)(delegate* <in Vector2[], godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in Vector2[], godot_variant>) &FromVector2Array; } if (typeOfT == typeof(Vector3[])) { - return (delegate* <in T, godot_variant>)(delegate* <in Vector3[], godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in Vector3[], godot_variant>) &FromVector3Array; } if (typeOfT == typeof(Color[])) { - return (delegate* <in T, godot_variant>)(delegate* <in Color[], godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in Color[], godot_variant>) &FromColorArray; } if (typeOfT == typeof(StringName[])) { - return (delegate* <in T, godot_variant>)(delegate* <in StringName[], godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in StringName[], godot_variant>) &FromStringNameArray; } if (typeOfT == typeof(NodePath[])) { - return (delegate* <in T, godot_variant>)(delegate* <in NodePath[], godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in NodePath[], godot_variant>) &FromNodePathArray; } if (typeOfT == typeof(RID[])) { - return (delegate* <in T, godot_variant>)(delegate* <in RID[], godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in RID[], godot_variant>) &FromRidArray; } if (typeof(Godot.Object).IsAssignableFrom(typeOfT)) { - return (delegate* <in T, godot_variant>)(delegate* <in Godot.Object, godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in Godot.Object, godot_variant>) &FromGodotObject; } if (typeOfT == typeof(StringName)) { - return (delegate* <in T, godot_variant>)(delegate* <in StringName, godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in StringName, godot_variant>) &FromStringName; } if (typeOfT == typeof(NodePath)) { - return (delegate* <in T, godot_variant>)(delegate* <in NodePath, godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in NodePath, godot_variant>) &FromNodePath; } if (typeOfT == typeof(RID)) { - return (delegate* <in T, godot_variant>)(delegate* <in RID, godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in RID, godot_variant>) &FromRid; } if (typeOfT == typeof(Godot.Collections.Dictionary)) { - return (delegate* <in T, godot_variant>)(delegate* <in Godot.Collections.Dictionary, godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in Godot.Collections.Dictionary, godot_variant>) &FromGodotDictionary; } if (typeOfT == typeof(Godot.Collections.Array)) { - return (delegate* <in T, godot_variant>)(delegate* <in Godot.Collections.Array, godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in Godot.Collections.Array, godot_variant>) &FromGodotArray; } if (typeOfT == typeof(Variant)) { - return (delegate* <in T, godot_variant>)(delegate* <in Variant, godot_variant>) + return (delegate*<in T, godot_variant>)(delegate*<in Variant, godot_variant>) &FromVariant; } @@ -488,7 +506,7 @@ internal static unsafe class VariantConversionCallbacks } [SuppressMessage("ReSharper", "RedundantNameQualifier")] - internal static delegate* <in godot_variant, T> GetToManagedCallback<T>() + internal static delegate*<in godot_variant, T> GetToManagedCallback<T>() { static bool ToBool(in godot_variant variant) => VariantUtils.ConvertToBool(variant); @@ -556,6 +574,12 @@ internal static unsafe class VariantConversionCallbacks static Transform3D ToTransform3D(in godot_variant variant) => VariantUtils.ConvertToTransform3D(variant); + static Vector4 ToVector4(in godot_variant variant) => + VariantUtils.ConvertToVector4(variant); + + static Vector4i ToVector4I(in godot_variant variant) => + VariantUtils.ConvertToVector4i(variant); + static AABB ToAabb(in godot_variant variant) => VariantUtils.ConvertToAABB(variant); @@ -638,163 +662,175 @@ internal static unsafe class VariantConversionCallbacks if (typeOfT == typeof(bool)) { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, bool>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, bool>) &ToBool; } if (typeOfT == typeof(char)) { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, char>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, char>) &ToChar; } if (typeOfT == typeof(sbyte)) { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, sbyte>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, sbyte>) &ToInt8; } if (typeOfT == typeof(short)) { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, short>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, short>) &ToInt16; } if (typeOfT == typeof(int)) { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, int>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, int>) &ToInt32; } if (typeOfT == typeof(long)) { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, long>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, long>) &ToInt64; } if (typeOfT == typeof(byte)) { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, byte>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, byte>) &ToUInt8; } if (typeOfT == typeof(ushort)) { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, ushort>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, ushort>) &ToUInt16; } if (typeOfT == typeof(uint)) { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, uint>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, uint>) &ToUInt32; } if (typeOfT == typeof(ulong)) { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, ulong>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, ulong>) &ToUInt64; } if (typeOfT == typeof(float)) { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, float>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, float>) &ToFloat; } if (typeOfT == typeof(double)) { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, double>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, double>) &ToDouble; } if (typeOfT == typeof(Vector2)) { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, Vector2>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, Vector2>) &ToVector2; } if (typeOfT == typeof(Vector2i)) { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, Vector2i>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, Vector2i>) &ToVector2I; } if (typeOfT == typeof(Rect2)) { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, Rect2>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, Rect2>) &ToRect2; } if (typeOfT == typeof(Rect2i)) { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, Rect2i>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, Rect2i>) &ToRect2I; } if (typeOfT == typeof(Transform2D)) { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, Transform2D>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, Transform2D>) &ToTransform2D; } if (typeOfT == typeof(Vector3)) { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, Vector3>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, Vector3>) &ToVector3; } if (typeOfT == typeof(Vector3i)) { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, Vector3i>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, Vector3i>) &ToVector3I; } if (typeOfT == typeof(Basis)) { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, Basis>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, Basis>) &ToBasis; } if (typeOfT == typeof(Quaternion)) { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, Quaternion>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, Quaternion>) &ToQuaternion; } if (typeOfT == typeof(Transform3D)) { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, Transform3D>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, Transform3D>) &ToTransform3D; } + if (typeOfT == typeof(Vector4)) + { + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, Vector4>) + &ToVector4; + } + + if (typeOfT == typeof(Vector4i)) + { + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, Vector4i>) + &ToVector4I; + } + if (typeOfT == typeof(AABB)) { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, AABB>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, AABB>) &ToAabb; } if (typeOfT == typeof(Color)) { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, Color>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, Color>) &ToColor; } if (typeOfT == typeof(Plane)) { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, Plane>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, Plane>) &ToPlane; } if (typeOfT == typeof(Callable)) { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, Callable>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, Callable>) &ToCallable; } if (typeOfT == typeof(SignalInfo)) { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, SignalInfo>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, SignalInfo>) &ToSignalInfo; } @@ -806,42 +842,42 @@ internal static unsafe class VariantConversionCallbacks { case TypeCode.SByte: { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, sbyte>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, sbyte>) &ToInt8; } case TypeCode.Int16: { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, short>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, short>) &ToInt16; } case TypeCode.Int32: { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, int>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, int>) &ToInt32; } case TypeCode.Int64: { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, long>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, long>) &ToInt64; } case TypeCode.Byte: { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, byte>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, byte>) &ToUInt8; } case TypeCode.UInt16: { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, ushort>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, ushort>) &ToUInt16; } case TypeCode.UInt32: { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, uint>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, uint>) &ToUInt32; } case TypeCode.UInt64: { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, ulong>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, ulong>) &ToUInt64; } default: @@ -851,121 +887,121 @@ internal static unsafe class VariantConversionCallbacks if (typeOfT == typeof(string)) { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, string>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, string>) &ToString; } if (typeOfT == typeof(byte[])) { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, byte[]>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, byte[]>) &ToByteArray; } if (typeOfT == typeof(int[])) { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, int[]>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, int[]>) &ToInt32Array; } if (typeOfT == typeof(long[])) { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, long[]>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, long[]>) &ToInt64Array; } if (typeOfT == typeof(float[])) { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, float[]>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, float[]>) &ToFloatArray; } if (typeOfT == typeof(double[])) { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, double[]>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, double[]>) &ToDoubleArray; } if (typeOfT == typeof(string[])) { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, string[]>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, string[]>) &ToStringArray; } if (typeOfT == typeof(Vector2[])) { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, Vector2[]>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, Vector2[]>) &ToVector2Array; } if (typeOfT == typeof(Vector3[])) { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, Vector3[]>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, Vector3[]>) &ToVector3Array; } if (typeOfT == typeof(Color[])) { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, Color[]>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, Color[]>) &ToColorArray; } if (typeOfT == typeof(StringName[])) { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, StringName[]>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, StringName[]>) &ToStringNameArray; } if (typeOfT == typeof(NodePath[])) { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, NodePath[]>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, NodePath[]>) &ToNodePathArray; } if (typeOfT == typeof(RID[])) { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, RID[]>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, RID[]>) &ToRidArray; } if (typeof(Godot.Object).IsAssignableFrom(typeOfT)) { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, Godot.Object>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, Godot.Object>) &ToGodotObject; } if (typeOfT == typeof(StringName)) { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, StringName>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, StringName>) &ToStringName; } if (typeOfT == typeof(NodePath)) { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, NodePath>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, NodePath>) &ToNodePath; } if (typeOfT == typeof(RID)) { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, RID>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, RID>) &ToRid; } if (typeOfT == typeof(Godot.Collections.Dictionary)) { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, Godot.Collections.Dictionary>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, Godot.Collections.Dictionary>) &ToGodotDictionary; } if (typeOfT == typeof(Godot.Collections.Array)) { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, Godot.Collections.Array>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, Godot.Collections.Array>) &ToGodotArray; } if (typeOfT == typeof(Variant)) { - return (delegate* <in godot_variant, T>)(delegate* <in godot_variant, Variant>) + return (delegate*<in godot_variant, T>)(delegate*<in godot_variant, Variant>) &ToVariant; } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/VariantUtils.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/VariantUtils.cs index 491ccf904e..57f9ec7d95 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/VariantUtils.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/VariantUtils.cs @@ -37,6 +37,12 @@ namespace Godot.NativeInterop public static godot_variant CreateFromVector3i(Vector3i from) => new() { Type = Variant.Type.Vector3i, Vector3i = from }; + public static godot_variant CreateFromVector4(Vector4 from) + => new() { Type = Variant.Type.Vector4, Vector4 = from }; + + public static godot_variant CreateFromVector4i(Vector4i from) + => new() { Type = Variant.Type.Vector4i, Vector4i = from }; + public static godot_variant CreateFromRect2(Rect2 from) => new() { Type = Variant.Type.Rect2, Rect2 = from }; @@ -58,18 +64,6 @@ namespace Godot.NativeInterop return ret; } - public static godot_variant CreateFromVector4(Vector4 from) - { - NativeFuncs.godotsharp_variant_new_vector4(out godot_variant ret, from); - return ret; - } - - public static godot_variant CreateFromVector4i(Vector4i from) - { - NativeFuncs.godotsharp_variant_new_vector4i(out godot_variant ret, from); - return ret; - } - public static godot_variant CreateFromBasis(Basis from) { NativeFuncs.godotsharp_variant_new_basis(out godot_variant ret, from); @@ -386,12 +380,12 @@ namespace Godot.NativeInterop public static unsafe Vector4 ConvertToVector4(in godot_variant p_var) => p_var.Type == Variant.Type.Vector4 ? - *p_var.Vector4 : + p_var.Vector4 : NativeFuncs.godotsharp_variant_as_vector4(p_var); public static unsafe Vector4i ConvertToVector4i(in godot_variant p_var) => p_var.Type == Variant.Type.Vector4i ? - *p_var.Vector4i : + p_var.Vector4i : NativeFuncs.godotsharp_variant_as_vector4i(p_var); public static unsafe Basis ConvertToBasis(in godot_variant p_var) diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Object.exceptions.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Object.exceptions.cs index eb2811c73d..0fcc4ee01b 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Object.exceptions.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Object.exceptions.cs @@ -1,4 +1,5 @@ using System; +using System.Text; #nullable enable @@ -60,19 +61,22 @@ namespace Godot { get { - string s = base.Message; - - if (string.IsNullOrEmpty(s)) + StringBuilder sb; + if (string.IsNullOrEmpty(base.Message)) + { + sb = new(Arg_NativeConstructorNotFoundException); + } + else { - s = Arg_NativeConstructorNotFoundException; + sb = new(base.Message); } if (!string.IsNullOrEmpty(_nativeClassName)) { - s += " " + string.Format("(Class '{0}')", _nativeClassName); + sb.Append($" (Method '{_nativeClassName}')"); } - return s; + return sb.ToString(); } } } @@ -115,19 +119,22 @@ namespace Godot { get { - string s = base.Message; - - if (string.IsNullOrEmpty(s)) + StringBuilder sb; + if (string.IsNullOrEmpty(base.Message)) + { + sb = new(Arg_NativeMethodBindNotFoundException); + } + else { - s = Arg_NativeMethodBindNotFoundException; + sb = new(base.Message); } if (!string.IsNullOrEmpty(_nativeMethodName)) { - s += " " + string.Format("(Method '{0}')", _nativeMethodName); + sb.Append($" (Method '{_nativeMethodName}')"); } - return s; + return sb.ToString(); } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Projection.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Projection.cs index 9d08e7120a..da895fd121 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Projection.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Projection.cs @@ -649,6 +649,9 @@ namespace Godot /// Access whole columns in the form of <see cref="Vector4"/>. /// </summary> /// <param name="column">Which column vector.</param> + /// <exception cref="ArgumentOutOfRangeException"> + /// <paramref name="column"/> is not 0, 1, 2 or 3. + /// </exception> public Vector4 this[int column] { get @@ -664,7 +667,7 @@ namespace Godot case 3: return w; default: - throw new IndexOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(column)); } } set @@ -684,7 +687,7 @@ namespace Godot w = value; return; default: - throw new IndexOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(column)); } } } @@ -694,6 +697,9 @@ namespace Godot /// </summary> /// <param name="column">Which column vector.</param> /// <param name="row">Which row of the column.</param> + /// <exception cref="ArgumentOutOfRangeException"> + /// <paramref name="column"/> or <paramref name="row"/> are not 0, 1, 2 or 3. + /// </exception> public real_t this[int column, int row] { get @@ -709,7 +715,7 @@ namespace Godot case 3: return w[row]; default: - throw new IndexOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(column)); } } set @@ -729,7 +735,7 @@ namespace Godot w[row] = value; return; default: - throw new IndexOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(column)); } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs index 999500ca13..d459fe8c96 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs @@ -47,6 +47,9 @@ namespace Godot /// <summary> /// Access quaternion components using their index. /// </summary> + /// <exception cref="ArgumentOutOfRangeException"> + /// <paramref name="index"/> is not 0, 1, 2 or 3. + /// </exception> /// <value> /// <c>[0]</c> is equivalent to <see cref="x"/>, /// <c>[1]</c> is equivalent to <see cref="y"/>, @@ -132,7 +135,7 @@ namespace Godot } /// <summary> - /// Performs a cubic spherical interpolation between quaternions <paramref name="preA"/>, this quaternion, + /// Performs a spherical cubic interpolation between quaternions <paramref name="preA"/>, this quaternion, /// <paramref name="b"/>, and <paramref name="postB"/>, by the given amount <paramref name="weight"/>. /// </summary> /// <param name="b">The destination quaternion.</param> @@ -140,12 +143,128 @@ namespace Godot /// <param name="postB">A quaternion after <paramref name="b"/>.</param> /// <param name="weight">A value on the range of 0.0 to 1.0, representing the amount of interpolation.</param> /// <returns>The interpolated quaternion.</returns> - public Quaternion CubicSlerp(Quaternion b, Quaternion preA, Quaternion postB, real_t weight) + public Quaternion SphericalCubicInterpolate(Quaternion b, Quaternion preA, Quaternion postB, real_t weight) { - real_t t2 = (1.0f - weight) * weight * 2f; - Quaternion sp = Slerp(b, weight); - Quaternion sq = preA.Slerpni(postB, weight); - return sp.Slerpni(sq, t2); +#if DEBUG + if (!IsNormalized()) + { + throw new InvalidOperationException("Quaternion is not normalized"); + } + if (!b.IsNormalized()) + { + throw new ArgumentException("Argument is not normalized", nameof(b)); + } +#endif + + // Align flip phases. + Quaternion fromQ = new Basis(this).GetRotationQuaternion(); + Quaternion preQ = new Basis(preA).GetRotationQuaternion(); + Quaternion toQ = new Basis(b).GetRotationQuaternion(); + Quaternion postQ = new Basis(postB).GetRotationQuaternion(); + + // Flip quaternions to shortest path if necessary. + bool flip1 = Math.Sign(fromQ.Dot(preQ)) < 0; + preQ = flip1 ? -preQ : preQ; + bool flip2 = Math.Sign(fromQ.Dot(toQ)) < 0; + toQ = flip2 ? -toQ : toQ; + bool flip3 = flip2 ? toQ.Dot(postQ) <= 0 : Math.Sign(toQ.Dot(postQ)) < 0; + postQ = flip3 ? -postQ : postQ; + + // Calc by Expmap in fromQ space. + Quaternion lnFrom = new Quaternion(0, 0, 0, 0); + Quaternion lnTo = (fromQ.Inverse() * toQ).Log(); + Quaternion lnPre = (fromQ.Inverse() * preQ).Log(); + Quaternion lnPost = (fromQ.Inverse() * postQ).Log(); + Quaternion ln = new Quaternion( + Mathf.CubicInterpolate(lnFrom.x, lnTo.x, lnPre.x, lnPost.x, weight), + Mathf.CubicInterpolate(lnFrom.y, lnTo.y, lnPre.y, lnPost.y, weight), + Mathf.CubicInterpolate(lnFrom.z, lnTo.z, lnPre.z, lnPost.z, weight), + 0); + Quaternion q1 = fromQ * ln.Exp(); + + // Calc by Expmap in toQ space. + lnFrom = (toQ.Inverse() * fromQ).Log(); + lnTo = new Quaternion(0, 0, 0, 0); + lnPre = (toQ.Inverse() * preQ).Log(); + lnPost = (toQ.Inverse() * postQ).Log(); + ln = new Quaternion( + Mathf.CubicInterpolate(lnFrom.x, lnTo.x, lnPre.x, lnPost.x, weight), + Mathf.CubicInterpolate(lnFrom.y, lnTo.y, lnPre.y, lnPost.y, weight), + Mathf.CubicInterpolate(lnFrom.z, lnTo.z, lnPre.z, lnPost.z, weight), + 0); + Quaternion q2 = toQ * ln.Exp(); + + // To cancel error made by Expmap ambiguity, do blends. + return q1.Slerp(q2, weight); + } + + /// <summary> + /// Performs a spherical cubic interpolation between quaternions <paramref name="preA"/>, this quaternion, + /// <paramref name="b"/>, and <paramref name="postB"/>, by the given amount <paramref name="weight"/>. + /// It can perform smoother interpolation than <see cref="SphericalCubicInterpolate"/> + /// by the time values. + /// </summary> + /// <param name="b">The destination quaternion.</param> + /// <param name="preA">A quaternion before this quaternion.</param> + /// <param name="postB">A quaternion after <paramref name="b"/>.</param> + /// <param name="weight">A value on the range of 0.0 to 1.0, representing the amount of interpolation.</param> + /// <param name="bT"></param> + /// <param name="preAT"></param> + /// <param name="postBT"></param> + /// <returns>The interpolated quaternion.</returns> + public Quaternion SphericalCubicInterpolateInTime(Quaternion b, Quaternion preA, Quaternion postB, real_t weight, real_t bT, real_t preAT, real_t postBT) + { +#if DEBUG + if (!IsNormalized()) + { + throw new InvalidOperationException("Quaternion is not normalized"); + } + if (!b.IsNormalized()) + { + throw new ArgumentException("Argument is not normalized", nameof(b)); + } +#endif + + // Align flip phases. + Quaternion fromQ = new Basis(this).GetRotationQuaternion(); + Quaternion preQ = new Basis(preA).GetRotationQuaternion(); + Quaternion toQ = new Basis(b).GetRotationQuaternion(); + Quaternion postQ = new Basis(postB).GetRotationQuaternion(); + + // Flip quaternions to shortest path if necessary. + bool flip1 = Math.Sign(fromQ.Dot(preQ)) < 0; + preQ = flip1 ? -preQ : preQ; + bool flip2 = Math.Sign(fromQ.Dot(toQ)) < 0; + toQ = flip2 ? -toQ : toQ; + bool flip3 = flip2 ? toQ.Dot(postQ) <= 0 : Math.Sign(toQ.Dot(postQ)) < 0; + postQ = flip3 ? -postQ : postQ; + + // Calc by Expmap in fromQ space. + Quaternion lnFrom = new Quaternion(0, 0, 0, 0); + Quaternion lnTo = (fromQ.Inverse() * toQ).Log(); + Quaternion lnPre = (fromQ.Inverse() * preQ).Log(); + Quaternion lnPost = (fromQ.Inverse() * postQ).Log(); + Quaternion ln = new Quaternion( + Mathf.CubicInterpolateInTime(lnFrom.x, lnTo.x, lnPre.x, lnPost.x, weight, bT, preAT, postBT), + Mathf.CubicInterpolateInTime(lnFrom.y, lnTo.y, lnPre.y, lnPost.y, weight, bT, preAT, postBT), + Mathf.CubicInterpolateInTime(lnFrom.z, lnTo.z, lnPre.z, lnPost.z, weight, bT, preAT, postBT), + 0); + Quaternion q1 = fromQ * ln.Exp(); + + // Calc by Expmap in toQ space. + lnFrom = (toQ.Inverse() * fromQ).Log(); + lnTo = new Quaternion(0, 0, 0, 0); + lnPre = (toQ.Inverse() * preQ).Log(); + lnPost = (toQ.Inverse() * postQ).Log(); + ln = new Quaternion( + Mathf.CubicInterpolateInTime(lnFrom.x, lnTo.x, lnPre.x, lnPost.x, weight, bT, preAT, postBT), + Mathf.CubicInterpolateInTime(lnFrom.y, lnTo.y, lnPre.y, lnPost.y, weight, bT, preAT, postBT), + Mathf.CubicInterpolateInTime(lnFrom.z, lnTo.z, lnPre.z, lnPost.z, weight, bT, preAT, postBT), + 0); + Quaternion q2 = toQ * ln.Exp(); + + // To cancel error made by Expmap ambiguity, do blends. + return q1.Slerp(q2, weight); } /// <summary> @@ -158,6 +277,34 @@ namespace Godot return (x * b.x) + (y * b.y) + (z * b.z) + (w * b.w); } + public Quaternion Exp() + { + Vector3 v = new Vector3(x, y, z); + real_t theta = v.Length(); + v = v.Normalized(); + if (theta < Mathf.Epsilon || !v.IsNormalized()) + { + return new Quaternion(0, 0, 0, 1); + } + return new Quaternion(v, theta); + } + + public real_t GetAngle() + { + return 2 * Mathf.Acos(w); + } + + public Vector3 GetAxis() + { + if (Mathf.Abs(w) > 1 - Mathf.Epsilon) + { + return new Vector3(x, y, z); + } + + real_t r = 1 / Mathf.Sqrt(1 - w * w); + return new Vector3(x * r, y * r, z * r); + } + /// <summary> /// Returns Euler angles (in the YXZ convention: when decomposing, /// first Z, then X, and Y last) corresponding to the rotation @@ -170,7 +317,7 @@ namespace Godot #if DEBUG if (!IsNormalized()) { - throw new InvalidOperationException("Quaternion is not normalized"); + throw new InvalidOperationException("Quaternion is not normalized."); } #endif var basis = new Basis(this); @@ -186,7 +333,7 @@ namespace Godot #if DEBUG if (!IsNormalized()) { - throw new InvalidOperationException("Quaternion is not normalized"); + throw new InvalidOperationException("Quaternion is not normalized."); } #endif return new Quaternion(-x, -y, -z, w); @@ -201,6 +348,12 @@ namespace Godot return Mathf.Abs(LengthSquared - 1) <= Mathf.Epsilon; } + public Quaternion Log() + { + Vector3 v = GetAxis() * GetAngle(); + return new Quaternion(v.x, v.y, v.z, 0); + } + /// <summary> /// Returns a copy of the quaternion, normalized to unit length. /// </summary> @@ -224,16 +377,16 @@ namespace Godot #if DEBUG if (!IsNormalized()) { - throw new InvalidOperationException("Quaternion is not normalized"); + throw new InvalidOperationException("Quaternion is not normalized."); } if (!to.IsNormalized()) { - throw new ArgumentException("Argument is not normalized", nameof(to)); + throw new ArgumentException("Argument is not normalized.", nameof(to)); } #endif // Calculate cosine. - real_t cosom = x * to.x + y * to.y + z * to.z + w * to.w; + real_t cosom = Dot(to); var to1 = new Quaternion(); @@ -241,17 +394,11 @@ namespace Godot if (cosom < 0.0) { cosom = -cosom; - to1.x = -to.x; - to1.y = -to.y; - to1.z = -to.z; - to1.w = -to.w; + to1 = -to; } else { - to1.x = to.x; - to1.y = to.y; - to1.z = to.z; - to1.w = to.w; + to1 = to; } real_t sinom, scale0, scale1; @@ -292,6 +439,17 @@ namespace Godot /// <returns>The resulting quaternion of the interpolation.</returns> public Quaternion Slerpni(Quaternion to, real_t weight) { +#if DEBUG + if (!IsNormalized()) + { + throw new InvalidOperationException("Quaternion is not normalized"); + } + if (!to.IsNormalized()) + { + throw new ArgumentException("Argument is not normalized", nameof(to)); + } +#endif + real_t dot = Dot(to); if (Mathf.Abs(dot) > 0.9999f) @@ -388,7 +546,7 @@ namespace Godot #if DEBUG if (!axis.IsNormalized()) { - throw new ArgumentException("Argument is not normalized", nameof(axis)); + throw new ArgumentException("Argument is not normalized.", nameof(axis)); } #endif @@ -444,7 +602,7 @@ namespace Godot #if DEBUG if (!quaternion.IsNormalized()) { - throw new InvalidOperationException("Quaternion is not normalized"); + throw new InvalidOperationException("Quaternion is not normalized."); } #endif var u = new Vector3(quaternion.x, quaternion.y, quaternion.z); diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs index f0bc5949df..44f951e314 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs @@ -287,6 +287,45 @@ namespace Godot return cap; } + /// <summary> + /// Returns the string converted to <c>camelCase</c>. + /// </summary> + /// <param name="instance">The string to convert.</param> + /// <returns>The converted string.</returns> + public static string ToCamelCase(this string instance) + { + using godot_string instanceStr = Marshaling.ConvertStringToNative(instance); + NativeFuncs.godotsharp_string_to_camel_case(instanceStr, out godot_string camelCase); + using (camelCase) + return Marshaling.ConvertStringToManaged(camelCase); + } + + /// <summary> + /// Returns the string converted to <c>PascalCase</c>. + /// </summary> + /// <param name="instance">The string to convert.</param> + /// <returns>The converted string.</returns> + public static string ToPascalCase(this string instance) + { + using godot_string instanceStr = Marshaling.ConvertStringToNative(instance); + NativeFuncs.godotsharp_string_to_pascal_case(instanceStr, out godot_string pascalCase); + using (pascalCase) + return Marshaling.ConvertStringToManaged(pascalCase); + } + + /// <summary> + /// Returns the string converted to <c>snake_case</c>. + /// </summary> + /// <param name="instance">The string to convert.</param> + /// <returns>The converted string.</returns> + public static string ToSnakeCase(this string instance) + { + using godot_string instanceStr = Marshaling.ConvertStringToNative(instance); + NativeFuncs.godotsharp_string_to_snake_case(instanceStr, out godot_string snakeCase); + using (snakeCase) + return Marshaling.ConvertStringToManaged(snakeCase); + } + private static string CamelcaseToUnderscore(this string instance, bool lowerCase) { string newString = string.Empty; diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs index 33b4f11f62..894667db76 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs @@ -75,6 +75,9 @@ namespace Godot /// The third column is the <see cref="origin"/> vector. /// </summary> /// <param name="column">Which column vector.</param> + /// <exception cref="ArgumentOutOfRangeException"> + /// <paramref name="column"/> is not 0, 1 or 2. + /// </exception> public Vector2 this[int column] { get diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform3D.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform3D.cs index 4b739bb86b..2f7891e7ef 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform3D.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform3D.cs @@ -32,6 +32,9 @@ namespace Godot /// The fourth column is the <see cref="origin"/> vector. /// </summary> /// <param name="column">Which column vector.</param> + /// <exception cref="ArgumentOutOfRangeException"> + /// <paramref name="column"/> is not 0, 1, 2 or 3. + /// </exception> public Vector3 this[int column] { get @@ -119,23 +122,9 @@ namespace Godot /// <returns>The interpolated transform.</returns> public Transform3D InterpolateWith(Transform3D transform, real_t weight) { - /* not sure if very "efficient" but good enough? */ - - Vector3 sourceScale = basis.Scale; - Quaternion sourceRotation = basis.GetRotationQuaternion(); - Vector3 sourceLocation = origin; - - Vector3 destinationScale = transform.basis.Scale; - Quaternion destinationRotation = transform.basis.GetRotationQuaternion(); - Vector3 destinationLocation = transform.origin; - - var interpolated = new Transform3D(); - Quaternion quaternion = sourceRotation.Slerp(destinationRotation, weight).Normalized(); - Vector3 scale = sourceScale.Lerp(destinationScale, weight); - interpolated.basis.SetQuaternionScale(quaternion, scale); - interpolated.origin = sourceLocation.Lerp(destinationLocation, weight); - - return interpolated; + Basis retBasis = basis.Lerp(transform.basis, weight); + Vector3 retOrigin = origin.Lerp(transform.origin, weight); + return new Transform3D(retBasis, retOrigin); } /// <summary> @@ -234,6 +223,34 @@ namespace Godot return new Transform3D(basis * tmpBasis, origin); } + /// <summary> + /// Returns a transform spherically interpolated between this transform and + /// another <paramref name="transform"/> by <paramref name="weight"/>. + /// </summary> + /// <param name="transform">The other transform.</param> + /// <param name="weight">A value on the range of 0.0 to 1.0, representing the amount of interpolation.</param> + /// <returns>The interpolated transform.</returns> + public Transform3D SphericalInterpolateWith(Transform3D transform, real_t weight) + { + /* not sure if very "efficient" but good enough? */ + + Vector3 sourceScale = basis.Scale; + Quaternion sourceRotation = basis.GetRotationQuaternion(); + Vector3 sourceLocation = origin; + + Vector3 destinationScale = transform.basis.Scale; + Quaternion destinationRotation = transform.basis.GetRotationQuaternion(); + Vector3 destinationLocation = transform.origin; + + var interpolated = new Transform3D(); + Quaternion quaternion = sourceRotation.Slerp(destinationRotation, weight).Normalized(); + Vector3 scale = sourceScale.Lerp(destinationScale, weight); + interpolated.basis.SetQuaternionScale(quaternion, scale); + interpolated.origin = sourceLocation.Lerp(destinationLocation, weight); + + return interpolated; + } + private void SetLookAt(Vector3 eye, Vector3 target, Vector3 up) { // Make rotation matrix diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs index 03ee12884b..87f397891e 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs @@ -39,8 +39,8 @@ namespace Godot /// <summary> /// Access vector components using their index. /// </summary> - /// <exception cref="IndexOutOfRangeException"> - /// Thrown when the given the <paramref name="index"/> is not 0 or 1. + /// <exception cref="ArgumentOutOfRangeException"> + /// <paramref name="index"/> is not 0 or 1. /// </exception> /// <value> /// <c>[0]</c> is equivalent to <see cref="x"/>, @@ -216,6 +216,29 @@ namespace Godot } /// <summary> + /// Performs a cubic interpolation between vectors <paramref name="preA"/>, this vector, + /// <paramref name="b"/>, and <paramref name="postB"/>, by the given amount <paramref name="weight"/>. + /// It can perform smoother interpolation than <see cref="CubicInterpolate"/> + /// by the time values. + /// </summary> + /// <param name="b">The destination vector.</param> + /// <param name="preA">A vector before this vector.</param> + /// <param name="postB">A vector after <paramref name="b"/>.</param> + /// <param name="weight">A value on the range of 0.0 to 1.0, representing the amount of interpolation.</param> + /// <param name="t"></param> + /// <param name="preAT"></param> + /// <param name="postBT"></param> + /// <returns>The interpolated vector.</returns> + public Vector2 CubicInterpolateInTime(Vector2 b, Vector2 preA, Vector2 postB, real_t weight, real_t t, real_t preAT, real_t postBT) + { + return new Vector2 + ( + Mathf.CubicInterpolateInTime(x, b.x, preA.x, postB.x, weight, t, preAT, postBT), + Mathf.CubicInterpolateInTime(y, b.y, preA.y, postB.y, weight, t, preAT, postBT) + ); + } + + /// <summary> /// Returns the point at the given <paramref name="t"/> on a one-dimensional Bezier curve defined by this vector /// and the given <paramref name="control1"/>, <paramref name="control2"/> and <paramref name="end"/> points. /// </summary> @@ -479,7 +502,7 @@ namespace Godot #if DEBUG if (!normal.IsNormalized()) { - throw new ArgumentException("Argument is not normalized", nameof(normal)); + throw new ArgumentException("Argument is not normalized.", nameof(normal)); } #endif return (2 * Dot(normal) * normal) - this; diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2i.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2i.cs index 666616edec..bdadf696e3 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2i.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2i.cs @@ -39,8 +39,8 @@ namespace Godot /// <summary> /// Access vector components using their index. /// </summary> - /// <exception cref="IndexOutOfRangeException"> - /// Thrown when the given the <paramref name="index"/> is not 0 or 1. + /// <exception cref="ArgumentOutOfRangeException"> + /// <paramref name="index"/> is not 0 or 1. /// </exception> /// <value> /// <c>[0]</c> is equivalent to <see cref="x"/>, diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs index cdba06c089..6649f3b784 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs @@ -48,8 +48,8 @@ namespace Godot /// <summary> /// Access vector components using their index. /// </summary> - /// <exception cref="IndexOutOfRangeException"> - /// Thrown when the given the <paramref name="index"/> is not 0, 1 or 2. + /// <exception cref="ArgumentOutOfRangeException"> + /// <paramref name="index"/> is not 0, 1 or 2. /// </exception> /// <value> /// <c>[0]</c> is equivalent to <see cref="x"/>, @@ -209,6 +209,30 @@ namespace Godot } /// <summary> + /// Performs a cubic interpolation between vectors <paramref name="preA"/>, this vector, + /// <paramref name="b"/>, and <paramref name="postB"/>, by the given amount <paramref name="weight"/>. + /// It can perform smoother interpolation than <see cref="CubicInterpolate"/> + /// by the time values. + /// </summary> + /// <param name="b">The destination vector.</param> + /// <param name="preA">A vector before this vector.</param> + /// <param name="postB">A vector after <paramref name="b"/>.</param> + /// <param name="weight">A value on the range of 0.0 to 1.0, representing the amount of interpolation.</param> + /// <param name="t"></param> + /// <param name="preAT"></param> + /// <param name="postBT"></param> + /// <returns>The interpolated vector.</returns> + public Vector3 CubicInterpolateInTime(Vector3 b, Vector3 preA, Vector3 postB, real_t weight, real_t t, real_t preAT, real_t postBT) + { + return new Vector3 + ( + Mathf.CubicInterpolateInTime(x, b.x, preA.x, postB.x, weight, t, preAT, postBT), + Mathf.CubicInterpolateInTime(y, b.y, preA.y, postB.y, weight, t, preAT, postBT), + Mathf.CubicInterpolateInTime(z, b.z, preA.z, postB.z, weight, t, preAT, postBT) + ); + } + + /// <summary> /// Returns the point at the given <paramref name="t"/> on a one-dimensional Bezier curve defined by this vector /// and the given <paramref name="control1"/>, <paramref name="control2"/> and <paramref name="end"/> points. /// </summary> @@ -497,7 +521,7 @@ namespace Godot #if DEBUG if (!normal.IsNormalized()) { - throw new ArgumentException("Argument is not normalized", nameof(normal)); + throw new ArgumentException("Argument is not normalized.", nameof(normal)); } #endif return (2.0f * Dot(normal) * normal) - this; @@ -515,7 +539,7 @@ namespace Godot #if DEBUG if (!axis.IsNormalized()) { - throw new ArgumentException("Argument is not normalized", nameof(axis)); + throw new ArgumentException("Argument is not normalized.", nameof(axis)); } #endif return new Basis(axis, angle) * this; diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3i.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3i.cs index 2947ef94a7..e88a043cb3 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3i.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3i.cs @@ -48,8 +48,8 @@ namespace Godot /// <summary> /// Access vector components using their <paramref name="index"/>. /// </summary> - /// <exception cref="IndexOutOfRangeException"> - /// Thrown when the given the <paramref name="index"/> is not 0, 1 or 2. + /// <exception cref="ArgumentOutOfRangeException"> + /// <paramref name="index"/> is not 0, 1 or 2. /// </exception> /// <value> /// <c>[0]</c> is equivalent to <see cref="x"/>, diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector4.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector4.cs index 705da04692..d1962c68cf 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector4.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector4.cs @@ -57,8 +57,8 @@ namespace Godot /// <summary> /// Access vector components using their index. /// </summary> - /// <exception cref="IndexOutOfRangeException"> - /// Thrown when the given the <paramref name="index"/> is not 0, 1, 2 or 3. + /// <exception cref="ArgumentOutOfRangeException"> + /// <paramref name="index"/> is not 0, 1, 2 or 3. /// </exception> /// <value> /// <c>[0]</c> is equivalent to <see cref="x"/>, @@ -81,7 +81,7 @@ namespace Godot case 3: return w; default: - throw new IndexOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(index)); } } set @@ -101,7 +101,7 @@ namespace Godot w = value; return; default: - throw new IndexOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(index)); } } } @@ -193,6 +193,31 @@ namespace Godot } /// <summary> + /// Performs a cubic interpolation between vectors <paramref name="preA"/>, this vector, + /// <paramref name="b"/>, and <paramref name="postB"/>, by the given amount <paramref name="weight"/>. + /// It can perform smoother interpolation than <see cref="CubicInterpolate"/> + /// by the time values. + /// </summary> + /// <param name="b">The destination vector.</param> + /// <param name="preA">A vector before this vector.</param> + /// <param name="postB">A vector after <paramref name="b"/>.</param> + /// <param name="weight">A value on the range of 0.0 to 1.0, representing the amount of interpolation.</param> + /// <param name="t"></param> + /// <param name="preAT"></param> + /// <param name="postBT"></param> + /// <returns>The interpolated vector.</returns> + public Vector4 CubicInterpolateInTime(Vector4 b, Vector4 preA, Vector4 postB, real_t weight, real_t t, real_t preAT, real_t postBT) + { + return new Vector4 + ( + Mathf.CubicInterpolateInTime(x, b.x, preA.x, postB.x, weight, t, preAT, postBT), + Mathf.CubicInterpolateInTime(y, b.y, preA.y, postB.y, weight, t, preAT, postBT), + Mathf.CubicInterpolateInTime(y, b.z, preA.z, postB.z, weight, t, preAT, postBT), + Mathf.CubicInterpolateInTime(w, b.w, preA.w, postB.w, weight, t, preAT, postBT) + ); + } + + /// <summary> /// Returns the normalized vector pointing from this vector to <paramref name="to"/>. /// </summary> /// <param name="to">The other vector to point towards.</param> diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector4i.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector4i.cs index 73134b0baf..4b1bb3ba19 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector4i.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector4i.cs @@ -57,8 +57,8 @@ namespace Godot /// <summary> /// Access vector components using their <paramref name="index"/>. /// </summary> - /// <exception cref="IndexOutOfRangeException"> - /// Thrown when the given the <paramref name="index"/> is not 0, 1, 2 or 3. + /// <exception cref="ArgumentOutOfRangeException"> + /// <paramref name="index"/> is not 0, 1, 2 or 3. /// </exception> /// <value> /// <c>[0]</c> is equivalent to <see cref="x"/>, @@ -81,7 +81,7 @@ namespace Godot case 3: return w; default: - throw new IndexOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(index)); } } set @@ -101,7 +101,7 @@ namespace Godot w = value; return; default: - throw new IndexOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(index)); } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Variant.cs b/modules/mono/glue/GodotSharp/GodotSharp/Variant.cs index 85ef258922..1f37694995 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Variant.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Variant.cs @@ -65,6 +65,8 @@ public partial struct Variant : IDisposable case Type.Rect2i: case Type.Vector3: case Type.Vector3i: + case Type.Vector4: + case Type.Vector4i: case Type.Plane: case Type.Quaternion: case Type.Color: diff --git a/modules/mono/glue/runtime_interop.cpp b/modules/mono/glue/runtime_interop.cpp index 0d68cb54b9..276701cdaa 100644 --- a/modules/mono/glue/runtime_interop.cpp +++ b/modules/mono/glue/runtime_interop.cpp @@ -548,14 +548,6 @@ void godotsharp_variant_new_transform2d(godot_variant *r_dest, const Transform2D memnew_placement(r_dest, Variant(*p_t2d)); } -void godotsharp_variant_new_vector4(godot_variant *r_dest, const Vector4 *p_vec4) { - memnew_placement(r_dest, Variant(*p_vec4)); -} - -void godotsharp_variant_new_vector4i(godot_variant *r_dest, const Vector4i *p_vec4i) { - memnew_placement(r_dest, Variant(*p_vec4i)); -} - void godotsharp_variant_new_basis(godot_variant *r_dest, const Basis *p_basis) { memnew_placement(r_dest, Variant(*p_basis)); } @@ -1096,6 +1088,18 @@ void godotsharp_string_simplify_path(const String *p_self, String *r_simplified_ memnew_placement(r_simplified_path, String(p_self->simplify_path())); } +void godotsharp_string_to_camel_case(const String *p_self, String *r_camel_case) { + memnew_placement(r_camel_case, String(p_self->to_camel_case())); +} + +void godotsharp_string_to_pascal_case(const String *p_self, String *r_pascal_case) { + memnew_placement(r_pascal_case, String(p_self->to_pascal_case())); +} + +void godotsharp_string_to_snake_case(const String *p_self, String *r_snake_case) { + memnew_placement(r_snake_case, String(p_self->to_snake_case())); +} + void godotsharp_node_path_get_as_property_path(const NodePath *p_ptr, NodePath *r_dest) { memnew_placement(r_dest, NodePath(p_ptr->get_as_property_path())); } @@ -1307,7 +1311,7 @@ void godotsharp_object_to_string(Object *p_ptr, godot_string *r_str) { #endif // Can't call 'Object::to_string()' here, as that can end up calling 'ToString' again resulting in an endless circular loop. memnew_placement(r_str, - String("[" + p_ptr->get_class() + ":" + itos(p_ptr->get_instance_id()) + "]")); + String("<" + p_ptr->get_class() + "#" + itos(p_ptr->get_instance_id()) + ">")); } #ifdef __cplusplus @@ -1365,8 +1369,6 @@ static const void *unmanaged_callbacks[]{ (void *)godotsharp_variant_new_node_path, (void *)godotsharp_variant_new_object, (void *)godotsharp_variant_new_transform2d, - (void *)godotsharp_variant_new_vector4, - (void *)godotsharp_variant_new_vector4i, (void *)godotsharp_variant_new_basis, (void *)godotsharp_variant_new_transform3d, (void *)godotsharp_variant_new_projection, @@ -1471,6 +1473,9 @@ static const void *unmanaged_callbacks[]{ (void *)godotsharp_string_sha256_buffer, (void *)godotsharp_string_sha256_text, (void *)godotsharp_string_simplify_path, + (void *)godotsharp_string_to_camel_case, + (void *)godotsharp_string_to_pascal_case, + (void *)godotsharp_string_to_snake_case, (void *)godotsharp_node_path_get_as_property_path, (void *)godotsharp_node_path_get_concatenated_names, (void *)godotsharp_node_path_get_concatenated_subnames, diff --git a/modules/mono/godotsharp_dirs.cpp b/modules/mono/godotsharp_dirs.cpp index 71576c2f80..c7e47d2718 100644 --- a/modules/mono/godotsharp_dirs.cpp +++ b/modules/mono/godotsharp_dirs.cpp @@ -64,7 +64,7 @@ String _get_expected_build_config() { String _get_mono_user_dir() { #ifdef TOOLS_ENABLED if (EditorPaths::get_singleton()) { - return EditorPaths::get_singleton()->get_data_dir().plus_file("mono"); + return EditorPaths::get_singleton()->get_data_dir().path_join("mono"); } else { String settings_path; @@ -72,23 +72,23 @@ String _get_mono_user_dir() { String exe_dir = OS::get_singleton()->get_executable_path().get_base_dir(); // On macOS, look outside .app bundle, since .app bundle is read-only. - if (OS::get_singleton()->has_feature("macos") && exe_dir.ends_with("MacOS") && exe_dir.plus_file("..").simplify_path().ends_with("Contents")) { - exe_dir = exe_dir.plus_file("../../..").simplify_path(); + if (OS::get_singleton()->has_feature("macos") && exe_dir.ends_with("MacOS") && exe_dir.path_join("..").simplify_path().ends_with("Contents")) { + exe_dir = exe_dir.path_join("../../..").simplify_path(); } Ref<DirAccess> d = DirAccess::create_for_path(exe_dir); if (d->file_exists("._sc_") || d->file_exists("_sc_")) { // contain yourself - settings_path = exe_dir.plus_file("editor_data"); + settings_path = exe_dir.path_join("editor_data"); } else { - settings_path = OS::get_singleton()->get_data_path().plus_file(OS::get_singleton()->get_godot_dir_name()); + settings_path = OS::get_singleton()->get_data_path().path_join(OS::get_singleton()->get_godot_dir_name()); } - return settings_path.plus_file("mono"); + return settings_path.path_join("mono"); } #else - return OS::get_singleton()->get_user_data_dir().plus_file("mono"); + return OS::get_singleton()->get_user_data_dir().path_join("mono"); #endif } @@ -126,27 +126,27 @@ public: private: _GodotSharpDirs() { - res_data_dir = ProjectSettings::get_singleton()->get_project_data_path().plus_file("mono"); - res_metadata_dir = res_data_dir.plus_file("metadata"); - res_config_dir = res_data_dir.plus_file("etc").plus_file("mono"); + res_data_dir = ProjectSettings::get_singleton()->get_project_data_path().path_join("mono"); + res_metadata_dir = res_data_dir.path_join("metadata"); + res_config_dir = res_data_dir.path_join("etc").path_join("mono"); // TODO use paths from csproj - res_temp_dir = res_data_dir.plus_file("temp"); - res_temp_assemblies_base_dir = res_temp_dir.plus_file("bin"); - res_temp_assemblies_dir = res_temp_assemblies_base_dir.plus_file(_get_expected_build_config()); + res_temp_dir = res_data_dir.path_join("temp"); + res_temp_assemblies_base_dir = res_temp_dir.path_join("bin"); + res_temp_assemblies_dir = res_temp_assemblies_base_dir.path_join(_get_expected_build_config()); - api_assemblies_base_dir = res_data_dir.plus_file("assemblies"); + api_assemblies_base_dir = res_data_dir.path_join("assemblies"); -#ifdef JAVASCRIPT_ENABLED +#ifdef WEB_ENABLED mono_user_dir = "user://"; #else mono_user_dir = _get_mono_user_dir(); #endif - mono_logs_dir = mono_user_dir.plus_file("mono_logs"); + mono_logs_dir = mono_user_dir.path_join("mono_logs"); #ifdef TOOLS_ENABLED - mono_solutions_dir = mono_user_dir.plus_file("solutions"); - build_logs_dir = mono_user_dir.plus_file("build_logs"); + mono_solutions_dir = mono_user_dir.path_join("solutions"); + build_logs_dir = mono_user_dir.path_join("build_logs"); String base_path = ProjectSettings::get_singleton()->globalize_path("res://"); #endif @@ -155,35 +155,35 @@ private: #ifdef TOOLS_ENABLED - String data_dir_root = exe_dir.plus_file("GodotSharp"); - data_editor_tools_dir = data_dir_root.plus_file("Tools"); - api_assemblies_base_dir = data_dir_root.plus_file("Api"); + String data_dir_root = exe_dir.path_join("GodotSharp"); + data_editor_tools_dir = data_dir_root.path_join("Tools"); + api_assemblies_base_dir = data_dir_root.path_join("Api"); - String data_mono_root_dir = data_dir_root.plus_file("Mono"); - data_mono_etc_dir = data_mono_root_dir.plus_file("etc"); + String data_mono_root_dir = data_dir_root.path_join("Mono"); + data_mono_etc_dir = data_mono_root_dir.path_join("etc"); #ifdef ANDROID_ENABLED data_mono_lib_dir = gdmono::android::support::get_app_native_lib_dir(); #else - data_mono_lib_dir = data_mono_root_dir.plus_file("lib"); + data_mono_lib_dir = data_mono_root_dir.path_join("lib"); #endif #ifdef WINDOWS_ENABLED - data_mono_bin_dir = data_mono_root_dir.plus_file("bin"); + data_mono_bin_dir = data_mono_root_dir.path_join("bin"); #endif #ifdef MACOS_ENABLED if (!DirAccess::exists(data_editor_tools_dir)) { - data_editor_tools_dir = exe_dir.plus_file("../Resources/GodotSharp/Tools"); + data_editor_tools_dir = exe_dir.path_join("../Resources/GodotSharp/Tools"); } if (!DirAccess::exists(api_assemblies_base_dir)) { - api_assemblies_base_dir = exe_dir.plus_file("../Resources/GodotSharp/Api"); + api_assemblies_base_dir = exe_dir.path_join("../Resources/GodotSharp/Api"); } if (!DirAccess::exists(data_mono_root_dir)) { - data_mono_etc_dir = exe_dir.plus_file("../Resources/GodotSharp/Mono/etc"); - data_mono_lib_dir = exe_dir.plus_file("../Resources/GodotSharp/Mono/lib"); + data_mono_etc_dir = exe_dir.path_join("../Resources/GodotSharp/Mono/etc"); + data_mono_lib_dir = exe_dir.path_join("../Resources/GodotSharp/Mono/lib"); } #endif @@ -191,40 +191,40 @@ private: String appname = ProjectSettings::get_singleton()->get("application/config/name"); String appname_safe = OS::get_singleton()->get_safe_dir_name(appname); - String data_dir_root = exe_dir.plus_file("data_" + appname_safe); + String data_dir_root = exe_dir.path_join("data_" + appname_safe); if (!DirAccess::exists(data_dir_root)) { - data_dir_root = exe_dir.plus_file("data_Godot"); + data_dir_root = exe_dir.path_join("data_Godot"); } - String data_mono_root_dir = data_dir_root.plus_file("Mono"); - data_mono_etc_dir = data_mono_root_dir.plus_file("etc"); + String data_mono_root_dir = data_dir_root.path_join("Mono"); + data_mono_etc_dir = data_mono_root_dir.path_join("etc"); #ifdef ANDROID_ENABLED data_mono_lib_dir = gdmono::android::support::get_app_native_lib_dir(); #else - data_mono_lib_dir = data_mono_root_dir.plus_file("lib"); - data_game_assemblies_dir = data_dir_root.plus_file("Assemblies"); + data_mono_lib_dir = data_mono_root_dir.path_join("lib"); + data_game_assemblies_dir = data_dir_root.path_join("Assemblies"); #endif #ifdef WINDOWS_ENABLED - data_mono_bin_dir = data_mono_root_dir.plus_file("bin"); + data_mono_bin_dir = data_mono_root_dir.path_join("bin"); #endif #ifdef MACOS_ENABLED if (!DirAccess::exists(data_mono_root_dir)) { - data_mono_etc_dir = exe_dir.plus_file("../Resources/GodotSharp/Mono/etc"); - data_mono_lib_dir = exe_dir.plus_file("../Resources/GodotSharp/Mono/lib"); + data_mono_etc_dir = exe_dir.path_join("../Resources/GodotSharp/Mono/etc"); + data_mono_lib_dir = exe_dir.path_join("../Resources/GodotSharp/Mono/lib"); } if (!DirAccess::exists(data_game_assemblies_dir)) { - data_game_assemblies_dir = exe_dir.plus_file("../Resources/GodotSharp/Assemblies"); + data_game_assemblies_dir = exe_dir.path_join("../Resources/GodotSharp/Assemblies"); } #endif #endif #ifdef TOOLS_ENABLED - api_assemblies_dir = api_assemblies_base_dir.plus_file(GDMono::get_expected_api_build_config()); + api_assemblies_dir = api_assemblies_base_dir.path_join(GDMono::get_expected_api_build_config()); #else api_assemblies_dir = data_dir_root; #endif diff --git a/modules/mono/mono_gd/gd_mono.cpp b/modules/mono/mono_gd/gd_mono.cpp index 0532cc915b..e698e92d7a 100644 --- a/modules/mono/mono_gd/gd_mono.cpp +++ b/modules/mono/mono_gd/gd_mono.cpp @@ -103,12 +103,12 @@ const char_t *get_data(const HostFxrCharString &p_char_str) { } #ifdef TOOLS_ENABLED -String find_hostfxr(size_t p_known_buffet_size, get_hostfxr_parameters *p_get_hostfxr_params) { +String find_hostfxr(size_t p_known_buffer_size, get_hostfxr_parameters *p_get_hostfxr_params) { // Pre-allocate a large buffer for the path to hostfxr Vector<char_t> buffer; - buffer.resize(p_known_buffet_size); + buffer.resize(p_known_buffer_size); - int rc = get_hostfxr_path(buffer.ptrw(), &p_known_buffet_size, p_get_hostfxr_params); + int rc = get_hostfxr_path(buffer.ptrw(), &p_known_buffer_size, p_get_hostfxr_params); ERR_FAIL_COND_V_MSG(rc != 0, String(), "get_hostfxr_path failed with code: " + itos(rc)); @@ -173,13 +173,13 @@ String find_hostfxr() { #if defined(WINDOWS_ENABLED) String probe_path = GodotSharpDirs::get_api_assemblies_dir() - .plus_file("hostfxr.dll"); + .path_join("hostfxr.dll"); #elif defined(MACOS_ENABLED) String probe_path = GodotSharpDirs::get_api_assemblies_dir() - .plus_file("libhostfxr.dylib"); + .path_join("libhostfxr.dylib"); #elif defined(UNIX_ENABLED) String probe_path = GodotSharpDirs::get_api_assemblies_dir() - .plus_file("libhostfxr.so"); + .path_join("libhostfxr.so"); #else #error "Platform not supported (yet?)" #endif @@ -270,7 +270,7 @@ load_assembly_and_get_function_pointer_fn initialize_hostfxr_self_contained( int i = 1; for (const String &E : cmdline_args) { HostFxrCharString &stored = argv_store.push_back(str_to_hostfxr(E))->get(); - argv.write[i] = stored.ptr(); + argv.write[i] = get_data(stored); i++; } @@ -305,10 +305,10 @@ godot_plugins_initialize_fn initialize_hostfxr_and_godot_plugins(bool &r_runtime godot_plugins_initialize_fn godot_plugins_initialize = nullptr; HostFxrCharString godot_plugins_path = str_to_hostfxr( - GodotSharpDirs::get_api_assemblies_dir().plus_file("GodotPlugins.dll")); + GodotSharpDirs::get_api_assemblies_dir().path_join("GodotPlugins.dll")); HostFxrCharString config_path = str_to_hostfxr( - GodotSharpDirs::get_api_assemblies_dir().plus_file("GodotPlugins.runtimeconfig.json")); + GodotSharpDirs::get_api_assemblies_dir().path_join("GodotPlugins.runtimeconfig.json")); load_assembly_and_get_function_pointer_fn load_assembly_and_get_function_pointer = initialize_hostfxr_for_config(get_data(config_path)); @@ -345,7 +345,7 @@ godot_plugins_initialize_fn initialize_hostfxr_and_godot_plugins(bool &r_runtime String assembly_name = get_assembly_name(); HostFxrCharString assembly_path = str_to_hostfxr(GodotSharpDirs::get_api_assemblies_dir() - .plus_file(assembly_name + ".dll")); + .path_join(assembly_name + ".dll")); load_assembly_and_get_function_pointer_fn load_assembly_and_get_function_pointer = initialize_hostfxr_self_contained(get_data(assembly_path)); @@ -356,7 +356,7 @@ godot_plugins_initialize_fn initialize_hostfxr_and_godot_plugins(bool &r_runtime print_verbose(".NET: hostfxr initialized"); int rc = load_assembly_and_get_function_pointer(get_data(assembly_path), - str_to_hostfxr("GodotPlugins.Game.Main, " + assembly_name), + get_data(str_to_hostfxr("GodotPlugins.Game.Main, " + assembly_name)), HOSTFXR_STR("InitializeFromGameProject"), UNMANAGEDCALLERSONLY_METHOD, nullptr, @@ -370,11 +370,11 @@ godot_plugins_initialize_fn try_load_native_aot_library(void *&r_aot_dll_handle) String assembly_name = get_assembly_name(); #if defined(WINDOWS_ENABLED) - String native_aot_so_path = GodotSharpDirs::get_api_assemblies_dir().plus_file(assembly_name + ".dll"); + String native_aot_so_path = GodotSharpDirs::get_api_assemblies_dir().path_join(assembly_name + ".dll"); #elif defined(MACOS_ENABLED) - String native_aot_so_path = GodotSharpDirs::get_api_assemblies_dir().plus_file(assembly_name + ".dylib"); + String native_aot_so_path = GodotSharpDirs::get_api_assemblies_dir().path_join(assembly_name + ".dylib"); #elif defined(UNIX_ENABLED) - String native_aot_so_path = GodotSharpDirs::get_api_assemblies_dir().plus_file(assembly_name + ".so"); + String native_aot_so_path = GodotSharpDirs::get_api_assemblies_dir().path_join(assembly_name + ".so"); #else #error "Platform not supported (yet?)" #endif @@ -514,7 +514,7 @@ bool GDMono::_load_project_assembly() { } String assembly_path = GodotSharpDirs::get_res_temp_assemblies_dir() - .plus_file(assembly_name + ".dll"); + .path_join(assembly_name + ".dll"); assembly_path = ProjectSettings::get_singleton()->globalize_path(assembly_path); if (!FileAccess::exists(assembly_path)) { diff --git a/modules/mono/utils/path_utils.cpp b/modules/mono/utils/path_utils.cpp index 19ad59a1bc..269e41e2f4 100644 --- a/modules/mono/utils/path_utils.cpp +++ b/modules/mono/utils/path_utils.cpp @@ -205,7 +205,7 @@ String relative_to_impl(const String &p_path, const String &p_relative_to) { return p_path; } - return String("..").plus_file(relative_to_impl(p_path, base_dir)); + return String("..").path_join(relative_to_impl(p_path, base_dir)); } } diff --git a/modules/navigation/editor/navigation_mesh_editor_plugin.cpp b/modules/navigation/editor/navigation_mesh_editor_plugin.cpp index c243e3e6e3..5cdff7b52a 100644 --- a/modules/navigation/editor/navigation_mesh_editor_plugin.cpp +++ b/modules/navigation/editor/navigation_mesh_editor_plugin.cpp @@ -110,7 +110,7 @@ NavigationMeshEditor::NavigationMeshEditor() { button_reset->set_flat(true); bake_hbox->add_child(button_reset); // No button text, we only use a revert icon which is set when entering the tree. - button_reset->set_tooltip(TTR("Clear the navigation mesh.")); + button_reset->set_tooltip_text(TTR("Clear the navigation mesh.")); button_reset->connect("pressed", callable_mp(this, &NavigationMeshEditor::_clear_pressed)); bake_info = memnew(Label); diff --git a/modules/noise/editor/noise_editor_plugin.cpp b/modules/noise/editor/noise_editor_plugin.cpp index b6f7cbd2f8..e8e73e4fd9 100644 --- a/modules/noise/editor/noise_editor_plugin.cpp +++ b/modules/noise/editor/noise_editor_plugin.cpp @@ -60,7 +60,7 @@ public: _3d_space_switch = memnew(Button); _3d_space_switch->set_text(TTR("3D")); - _3d_space_switch->set_tooltip(TTR("Toggles whether the noise preview is computed in 3D space.")); + _3d_space_switch->set_tooltip_text(TTR("Toggles whether the noise preview is computed in 3D space.")); _3d_space_switch->set_toggle_mode(true); _3d_space_switch->set_offset(SIDE_LEFT, PADDING_3D_SPACE_SWITCH); _3d_space_switch->set_offset(SIDE_TOP, PADDING_3D_SPACE_SWITCH); diff --git a/modules/openxr/editor/openxr_action_editor.cpp b/modules/openxr/editor/openxr_action_editor.cpp index 41c6465f43..52216fa483 100644 --- a/modules/openxr/editor/openxr_action_editor.cpp +++ b/modules/openxr/editor/openxr_action_editor.cpp @@ -104,7 +104,7 @@ OpenXRActionEditor::OpenXRActionEditor(Ref<OpenXRAction> p_action) { // maybe add dropdown to edit our toplevel paths, or do we deduce them from our suggested bindings? rem_action = memnew(Button); - rem_action->set_tooltip(TTR("Remove action")); + rem_action->set_tooltip_text(TTR("Remove action")); rem_action->connect("pressed", callable_mp(this, &OpenXRActionEditor::_on_remove_action)); rem_action->set_flat(true); add_child(rem_action); diff --git a/modules/openxr/editor/openxr_action_map_editor.cpp b/modules/openxr/editor/openxr_action_map_editor.cpp index 0a2d0a3110..fcbe4d57f6 100644 --- a/modules/openxr/editor/openxr_action_map_editor.cpp +++ b/modules/openxr/editor/openxr_action_map_editor.cpp @@ -316,13 +316,13 @@ OpenXRActionMapEditor::OpenXRActionMapEditor() { add_action_set = memnew(Button); add_action_set->set_text(TTR("Add Action Set")); - add_action_set->set_tooltip(TTR("Add an action set.")); + add_action_set->set_tooltip_text(TTR("Add an action set.")); add_action_set->connect("pressed", callable_mp(this, &OpenXRActionMapEditor::_on_add_action_set)); top_hb->add_child(add_action_set); add_interaction_profile = memnew(Button); add_interaction_profile->set_text(TTR("Add profile")); - add_interaction_profile->set_tooltip(TTR("Add an interaction profile.")); + add_interaction_profile->set_tooltip_text(TTR("Add an interaction profile.")); add_interaction_profile->connect("pressed", callable_mp(this, &OpenXRActionMapEditor::_on_add_interaction_profile)); top_hb->add_child(add_interaction_profile); @@ -331,13 +331,13 @@ OpenXRActionMapEditor::OpenXRActionMapEditor() { save_as = memnew(Button); save_as->set_text(TTR("Save")); - save_as->set_tooltip(TTR("Save this OpenXR action map.")); + save_as->set_tooltip_text(TTR("Save this OpenXR action map.")); save_as->connect("pressed", callable_mp(this, &OpenXRActionMapEditor::_on_save_action_map)); top_hb->add_child(save_as); _default = memnew(Button); _default->set_text(TTR("Reset to Default")); - _default->set_tooltip(TTR("Reset to default OpenXR action map.")); + _default->set_tooltip_text(TTR("Reset to default OpenXR action map.")); _default->connect("pressed", callable_mp(this, &OpenXRActionMapEditor::_on_reset_to_default_layout)); top_hb->add_child(_default); diff --git a/modules/openxr/editor/openxr_action_set_editor.cpp b/modules/openxr/editor/openxr_action_set_editor.cpp index 7bf8557c5b..804808a6b9 100644 --- a/modules/openxr/editor/openxr_action_set_editor.cpp +++ b/modules/openxr/editor/openxr_action_set_editor.cpp @@ -199,13 +199,13 @@ OpenXRActionSetEditor::OpenXRActionSetEditor(Ref<OpenXRActionMap> p_action_map, action_set_hb->add_child(action_set_priority); add_action = memnew(Button); - add_action->set_tooltip("Add Action."); + add_action->set_tooltip_text("Add Action."); add_action->connect("pressed", callable_mp(this, &OpenXRActionSetEditor::_on_add_action)); add_action->set_flat(true); action_set_hb->add_child(add_action); rem_action_set = memnew(Button); - rem_action_set->set_tooltip("Remove Action Set."); + rem_action_set->set_tooltip_text("Remove Action Set."); rem_action_set->connect("pressed", callable_mp(this, &OpenXRActionSetEditor::_on_remove_action_set)); rem_action_set->set_flat(true); action_set_hb->add_child(rem_action_set); diff --git a/modules/raycast/config.py b/modules/raycast/config.py index 438779343e..833ad50018 100644 --- a/modules/raycast/config.py +++ b/modules/raycast/config.py @@ -1,5 +1,8 @@ def can_build(env, platform): # Depends on Embree library, which only supports x86_64 and arm64. + if platform == "windows": + return env["arch"] == "x86_64" # TODO build for Windows on ARM + return env["arch"] in ["x86_64", "arm64"] diff --git a/modules/text_server_adv/SCsub b/modules/text_server_adv/SCsub index c6678307af..8d0245f0f6 100644 --- a/modules/text_server_adv/SCsub +++ b/modules/text_server_adv/SCsub @@ -140,15 +140,9 @@ if env["builtin_harfbuzz"]: env_harfbuzz.Prepend(CPPPATH=["#thirdparty/graphite/include"]) env_harfbuzz.Append(CCFLAGS=["-DGRAPHITE2_STATIC"]) - if env["platform"] == "android" or env["platform"] == "linuxbsd": + if env["platform"] in ["android", "linuxbsd", "web"]: env_harfbuzz.Append(CCFLAGS=["-DHAVE_PTHREAD"]) - if env["platform"] == "javascript": - if env["threads_enabled"]: - env_harfbuzz.Append(CCFLAGS=["-DHAVE_PTHREAD"]) - else: - env_harfbuzz.Append(CCFLAGS=["-DHB_NO_MT"]) - env_text_server_adv.Prepend(CPPPATH=["#thirdparty/harfbuzz/src"]) lib = env_harfbuzz.add_library("harfbuzz_builtin", thirdparty_sources) diff --git a/modules/text_server_adv/text_server_adv.cpp b/modules/text_server_adv/text_server_adv.cpp index 366e1ba604..abef48e2a1 100644 --- a/modules/text_server_adv/text_server_adv.cpp +++ b/modules/text_server_adv/text_server_adv.cpp @@ -2622,11 +2622,11 @@ Vector2 TextServerAdvanced::font_get_glyph_advance(const RID &p_font_rid, int64_ } if (fd->msdf) { - return (gl[p_glyph].advance + ea) * (double)p_size / (double)fd->msdf_source_size; + return (gl[p_glyph | mod].advance + ea) * (double)p_size / (double)fd->msdf_source_size; } else if ((fd->subpixel_positioning == SUBPIXEL_POSITIONING_DISABLED) || (fd->subpixel_positioning == SUBPIXEL_POSITIONING_AUTO && size.x > SUBPIXEL_POSITIONING_ONE_HALF_MAX_SIZE)) { - return (gl[p_glyph].advance + ea).round(); + return (gl[p_glyph | mod].advance + ea).round(); } else { - return gl[p_glyph].advance + ea; + return gl[p_glyph | mod].advance + ea; } } @@ -2669,9 +2669,9 @@ Vector2 TextServerAdvanced::font_get_glyph_offset(const RID &p_font_rid, const V const HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map; if (fd->msdf) { - return gl[p_glyph].rect.position * (double)p_size.x / (double)fd->msdf_source_size; + return gl[p_glyph | mod].rect.position * (double)p_size.x / (double)fd->msdf_source_size; } else { - return gl[p_glyph].rect.position; + return gl[p_glyph | mod].rect.position; } } @@ -2714,9 +2714,9 @@ Vector2 TextServerAdvanced::font_get_glyph_size(const RID &p_font_rid, const Vec const HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map; if (fd->msdf) { - return gl[p_glyph].rect.size * (double)p_size.x / (double)fd->msdf_source_size; + return gl[p_glyph | mod].rect.size * (double)p_size.x / (double)fd->msdf_source_size; } else { - return gl[p_glyph].rect.size; + return gl[p_glyph | mod].rect.size; } } @@ -2757,7 +2757,7 @@ Rect2 TextServerAdvanced::font_get_glyph_uv_rect(const RID &p_font_rid, const Ve } const HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map; - return gl[p_glyph].uv_rect; + return gl[p_glyph | mod].uv_rect; } void TextServerAdvanced::font_set_glyph_uv_rect(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph, const Rect2 &p_uv_rect) { @@ -2797,7 +2797,7 @@ int64_t TextServerAdvanced::font_get_glyph_texture_idx(const RID &p_font_rid, co } const HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map; - return gl[p_glyph].texture_idx; + return gl[p_glyph | mod].texture_idx; } void TextServerAdvanced::font_set_glyph_texture_idx(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph, int64_t p_texture_idx) { @@ -2837,12 +2837,12 @@ RID TextServerAdvanced::font_get_glyph_texture_rid(const RID &p_font_rid, const } const HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map; - ERR_FAIL_COND_V(gl[p_glyph].texture_idx < -1 || gl[p_glyph].texture_idx >= fd->cache[size]->textures.size(), RID()); + ERR_FAIL_COND_V(gl[p_glyph | mod].texture_idx < -1 || gl[p_glyph | mod].texture_idx >= fd->cache[size]->textures.size(), RID()); if (RenderingServer::get_singleton() != nullptr) { - if (gl[p_glyph].texture_idx != -1) { - if (fd->cache[size]->textures[gl[p_glyph].texture_idx].dirty) { - FontTexture &tex = fd->cache[size]->textures.write[gl[p_glyph].texture_idx]; + if (gl[p_glyph | mod].texture_idx != -1) { + if (fd->cache[size]->textures[gl[p_glyph | mod].texture_idx].dirty) { + FontTexture &tex = fd->cache[size]->textures.write[gl[p_glyph | mod].texture_idx]; Ref<Image> img; img.instantiate(); img->create_from_data(tex.texture_w, tex.texture_h, false, tex.format, tex.imgdata); @@ -2856,7 +2856,7 @@ RID TextServerAdvanced::font_get_glyph_texture_rid(const RID &p_font_rid, const } tex.dirty = false; } - return fd->cache[size]->textures[gl[p_glyph].texture_idx].texture->get_rid(); + return fd->cache[size]->textures[gl[p_glyph | mod].texture_idx].texture->get_rid(); } } @@ -2885,12 +2885,12 @@ Size2 TextServerAdvanced::font_get_glyph_texture_size(const RID &p_font_rid, con } const HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map; - ERR_FAIL_COND_V(gl[p_glyph].texture_idx < -1 || gl[p_glyph].texture_idx >= fd->cache[size]->textures.size(), Size2()); + ERR_FAIL_COND_V(gl[p_glyph | mod].texture_idx < -1 || gl[p_glyph | mod].texture_idx >= fd->cache[size]->textures.size(), Size2()); if (RenderingServer::get_singleton() != nullptr) { - if (gl[p_glyph].texture_idx != -1) { - if (fd->cache[size]->textures[gl[p_glyph].texture_idx].dirty) { - FontTexture &tex = fd->cache[size]->textures.write[gl[p_glyph].texture_idx]; + if (gl[p_glyph | mod].texture_idx != -1) { + if (fd->cache[size]->textures[gl[p_glyph | mod].texture_idx].dirty) { + FontTexture &tex = fd->cache[size]->textures.write[gl[p_glyph | mod].texture_idx]; Ref<Image> img; img.instantiate(); img->create_from_data(tex.texture_w, tex.texture_h, false, tex.format, tex.imgdata); @@ -2904,7 +2904,7 @@ Size2 TextServerAdvanced::font_get_glyph_texture_size(const RID &p_font_rid, con } tex.dirty = false; } - return fd->cache[size]->textures[gl[p_glyph].texture_idx].texture->get_size(); + return fd->cache[size]->textures[gl[p_glyph | mod].texture_idx].texture->get_size(); } } @@ -3229,7 +3229,7 @@ void TextServerAdvanced::font_draw_glyph(const RID &p_font_rid, const RID &p_can if (gl.texture_idx != -1) { Color modulate = p_color; #ifdef MODULE_FREETYPE_ENABLED - if (fd->cache[size]->face && (fd->cache[size]->textures[gl.texture_idx].format == Image::FORMAT_RGBA8) && !lcd_aa) { + if (fd->cache[size]->face && (fd->cache[size]->textures[gl.texture_idx].format == Image::FORMAT_RGBA8) && !lcd_aa && !fd->msdf) { modulate.r = modulate.g = modulate.b = 1.0; } #endif @@ -3321,7 +3321,7 @@ void TextServerAdvanced::font_draw_glyph_outline(const RID &p_font_rid, const RI if (gl.texture_idx != -1) { Color modulate = p_color; #ifdef MODULE_FREETYPE_ENABLED - if (fd->cache[size]->face && FT_HAS_COLOR(fd->cache[size]->face)) { + if (fd->cache[size]->face && (fd->cache[size]->textures[gl.texture_idx].format == Image::FORMAT_RGBA8) && !lcd_aa && !fd->msdf) { modulate.r = modulate.g = modulate.b = 1.0; } #endif diff --git a/modules/text_server_fb/text_server_fb.cpp b/modules/text_server_fb/text_server_fb.cpp index 53b303cb20..359bb056a8 100644 --- a/modules/text_server_fb/text_server_fb.cpp +++ b/modules/text_server_fb/text_server_fb.cpp @@ -1697,11 +1697,11 @@ Vector2 TextServerFallback::font_get_glyph_advance(const RID &p_font_rid, int64_ } if (fd->msdf) { - return (gl[p_glyph].advance + ea) * (double)p_size / (double)fd->msdf_source_size; + return (gl[p_glyph | mod].advance + ea) * (double)p_size / (double)fd->msdf_source_size; } else if ((fd->subpixel_positioning == SUBPIXEL_POSITIONING_DISABLED) || (fd->subpixel_positioning == SUBPIXEL_POSITIONING_AUTO && size.x > SUBPIXEL_POSITIONING_ONE_HALF_MAX_SIZE)) { - return (gl[p_glyph].advance + ea).round(); + return (gl[p_glyph | mod].advance + ea).round(); } else { - return gl[p_glyph].advance + ea; + return gl[p_glyph | mod].advance + ea; } } @@ -1744,9 +1744,9 @@ Vector2 TextServerFallback::font_get_glyph_offset(const RID &p_font_rid, const V const HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map; if (fd->msdf) { - return gl[p_glyph].rect.position * (double)p_size.x / (double)fd->msdf_source_size; + return gl[p_glyph | mod].rect.position * (double)p_size.x / (double)fd->msdf_source_size; } else { - return gl[p_glyph].rect.position; + return gl[p_glyph | mod].rect.position; } } @@ -1789,9 +1789,9 @@ Vector2 TextServerFallback::font_get_glyph_size(const RID &p_font_rid, const Vec const HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map; if (fd->msdf) { - return gl[p_glyph].rect.size * (double)p_size.x / (double)fd->msdf_source_size; + return gl[p_glyph | mod].rect.size * (double)p_size.x / (double)fd->msdf_source_size; } else { - return gl[p_glyph].rect.size; + return gl[p_glyph | mod].rect.size; } } @@ -1832,7 +1832,7 @@ Rect2 TextServerFallback::font_get_glyph_uv_rect(const RID &p_font_rid, const Ve } const HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map; - return gl[p_glyph].uv_rect; + return gl[p_glyph | mod].uv_rect; } void TextServerFallback::font_set_glyph_uv_rect(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph, const Rect2 &p_uv_rect) { @@ -1872,7 +1872,7 @@ int64_t TextServerFallback::font_get_glyph_texture_idx(const RID &p_font_rid, co } const HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map; - return gl[p_glyph].texture_idx; + return gl[p_glyph | mod].texture_idx; } void TextServerFallback::font_set_glyph_texture_idx(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph, int64_t p_texture_idx) { @@ -1912,12 +1912,12 @@ RID TextServerFallback::font_get_glyph_texture_rid(const RID &p_font_rid, const } const HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map; - ERR_FAIL_COND_V(gl[p_glyph].texture_idx < -1 || gl[p_glyph].texture_idx >= fd->cache[size]->textures.size(), RID()); + ERR_FAIL_COND_V(gl[p_glyph | mod].texture_idx < -1 || gl[p_glyph | mod].texture_idx >= fd->cache[size]->textures.size(), RID()); if (RenderingServer::get_singleton() != nullptr) { - if (gl[p_glyph].texture_idx != -1) { - if (fd->cache[size]->textures[gl[p_glyph].texture_idx].dirty) { - FontTexture &tex = fd->cache[size]->textures.write[gl[p_glyph].texture_idx]; + if (gl[p_glyph | mod].texture_idx != -1) { + if (fd->cache[size]->textures[gl[p_glyph | mod].texture_idx].dirty) { + FontTexture &tex = fd->cache[size]->textures.write[gl[p_glyph | mod].texture_idx]; Ref<Image> img; img.instantiate(); img->create_from_data(tex.texture_w, tex.texture_h, false, tex.format, tex.imgdata); @@ -1931,7 +1931,7 @@ RID TextServerFallback::font_get_glyph_texture_rid(const RID &p_font_rid, const } tex.dirty = false; } - return fd->cache[size]->textures[gl[p_glyph].texture_idx].texture->get_rid(); + return fd->cache[size]->textures[gl[p_glyph | mod].texture_idx].texture->get_rid(); } } @@ -1960,12 +1960,12 @@ Size2 TextServerFallback::font_get_glyph_texture_size(const RID &p_font_rid, con } const HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map; - ERR_FAIL_COND_V(gl[p_glyph].texture_idx < -1 || gl[p_glyph].texture_idx >= fd->cache[size]->textures.size(), Size2()); + ERR_FAIL_COND_V(gl[p_glyph | mod].texture_idx < -1 || gl[p_glyph | mod].texture_idx >= fd->cache[size]->textures.size(), Size2()); if (RenderingServer::get_singleton() != nullptr) { - if (gl[p_glyph].texture_idx != -1) { - if (fd->cache[size]->textures[gl[p_glyph].texture_idx].dirty) { - FontTexture &tex = fd->cache[size]->textures.write[gl[p_glyph].texture_idx]; + if (gl[p_glyph | mod].texture_idx != -1) { + if (fd->cache[size]->textures[gl[p_glyph | mod].texture_idx].dirty) { + FontTexture &tex = fd->cache[size]->textures.write[gl[p_glyph | mod].texture_idx]; Ref<Image> img; img.instantiate(); img->create_from_data(tex.texture_w, tex.texture_h, false, tex.format, tex.imgdata); @@ -1979,7 +1979,7 @@ Size2 TextServerFallback::font_get_glyph_texture_size(const RID &p_font_rid, con } tex.dirty = false; } - return fd->cache[size]->textures[gl[p_glyph].texture_idx].texture->get_size(); + return fd->cache[size]->textures[gl[p_glyph | mod].texture_idx].texture->get_size(); } } @@ -2286,7 +2286,7 @@ void TextServerFallback::font_draw_glyph(const RID &p_font_rid, const RID &p_can if (gl.texture_idx != -1) { Color modulate = p_color; #ifdef MODULE_FREETYPE_ENABLED - if (fd->cache[size]->face && (fd->cache[size]->textures[gl.texture_idx].format == Image::FORMAT_RGBA8) && !lcd_aa) { + if (fd->cache[size]->face && (fd->cache[size]->textures[gl.texture_idx].format == Image::FORMAT_RGBA8) && !lcd_aa && !fd->msdf) { modulate.r = modulate.g = modulate.b = 1.0; } #endif @@ -2378,7 +2378,7 @@ void TextServerFallback::font_draw_glyph_outline(const RID &p_font_rid, const RI if (gl.texture_idx != -1) { Color modulate = p_color; #ifdef MODULE_FREETYPE_ENABLED - if (fd->cache[size]->face && FT_HAS_COLOR(fd->cache[size]->face)) { + if (fd->cache[size]->face && (fd->cache[size]->textures[gl.texture_idx].format == Image::FORMAT_RGBA8) && !lcd_aa && !fd->msdf) { modulate.r = modulate.g = modulate.b = 1.0; } #endif diff --git a/modules/upnp/doc_classes/UPNP.xml b/modules/upnp/doc_classes/UPNP.xml index 847110abd4..4888dca822 100644 --- a/modules/upnp/doc_classes/UPNP.xml +++ b/modules/upnp/doc_classes/UPNP.xml @@ -1,16 +1,15 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="UPNP" inherits="RefCounted" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd"> <brief_description> - UPNP network functions. + Universal Plug and Play (UPnP) functions for network device discovery, querying and port forwarding. </brief_description> <description> - Provides UPNP functionality to discover [UPNPDevice]s on the local network and execute commands on them, like managing port mappings (port forwarding) and querying the local and remote network IP address. Note that methods on this class are synchronous and block the calling thread. - To forward a specific port: + This class can be used to discover compatible [UPNPDevice]s on the local network and execute commands on them, like managing port mappings (for port forwarding/NAT traversal) and querying the local and remote network IP address. Note that methods on this class are synchronous and block the calling thread. + To forward a specific port (here [code]7777[/code], note both [method discover] and [method add_port_mapping] can return errors that should be checked): [codeblock] - const PORT = 7777 var upnp = UPNP.new() - upnp.discover(2000, 2, "InternetGatewayDevice") - upnp.add_port_mapping(port) + upnp.discover() + upnp.add_port_mapping(7777) [/codeblock] To close a specific port (e.g. after you have finished using it): [codeblock] @@ -21,7 +20,7 @@ # Emitted when UPnP port mapping setup is completed (regardless of success or failure). signal upnp_completed(error) - # Replace this with your own server port number between 1025 and 65535. + # Replace this with your own server port number between 1024 and 65535. const SERVER_PORT = 3928 var thread = null @@ -48,6 +47,14 @@ # Wait for thread finish here to handle game exit while the thread is running. thread.wait_to_finish() [/codeblock] + [b]Terminology:[/b] In the context of UPnP networking, "gateway" (or "internet gateway device", short IGD) refers to network devices that allow computers in the local network to access the internet ("wide area network", WAN). These gateways are often also called "routers". + [b]Pitfalls:[/b] + - As explained above, these calls are blocking and shouldn't be run on the main thread, especially as they can block for multiple seconds at a time. Use threading! + - Networking is physical and messy. Packets get lost in transit or get filtered, addresses, free ports and assigned mappings change, and devices may leave or join the network at any time. Be mindful of this, be diligent when checking and handling errors, and handle these gracefully if you can: add clear error UI, timeouts and re-try handling. + - Port mappings may change (and be removed) at any time, and the remote/external IP address of the gateway can change likewise. You should consider re-querying the external IP and try to update/refresh the port mapping periodically (for example, every 5 minutes and on networking failures). + - Not all devices support UPnP, and some users disable UPnP support. You need to handle this (e.g. documenting and requiring the user to manually forward ports, or adding alternative methods of NAT traversal, like a relay/mirror server, or NAT hole punching, STUN/TURN, etc.). + - Consider what happens on mapping conflicts. Maybe multiple users on the same network would like to play your game at the same time, or maybe another application uses the same port. Make the port configurable, and optimally choose a port automatically (re-trying with a different port on failure). + [b]Further reading:[/b] If you want to know more about UPnP (and the Internet Gateway Device (IGD) and Port Control Protocol (PCP) specifically), [url=https://en.wikipedia.org/wiki/Universal_Plug_and_Play]Wikipedia[/url] is a good first stop, the specification can be found at the [url=https://openconnectivity.org/developer/specifications/upnp-resources/upnp/]Open Connectivity Foundation[/url] and Godot's implementation is based on the [url=https://github.com/miniupnp/miniupnp]MiniUPnP client[/url]. </description> <tutorials> </tutorials> @@ -67,9 +74,11 @@ <param index="3" name="proto" type="String" default=""UDP"" /> <param index="4" name="duration" type="int" default="0" /> <description> - Adds a mapping to forward the external [code]port[/code] (between 1 and 65535) on the default gateway (see [method get_gateway]) to the [code]internal_port[/code] on the local machine for the given protocol [code]proto[/code] (either [code]TCP[/code] or [code]UDP[/code], with UDP being the default). If a port mapping for the given port and protocol combination already exists on that gateway device, this method tries to overwrite it. If that is not desired, you can retrieve the gateway manually with [method get_gateway] and call [method add_port_mapping] on it, if any. + Adds a mapping to forward the external [code]port[/code] (between 1 and 65535, although recommended to use port 1024 or above) on the default gateway (see [method get_gateway]) to the [code]internal_port[/code] on the local machine for the given protocol [code]proto[/code] (either [code]TCP[/code] or [code]UDP[/code], with UDP being the default). If a port mapping for the given port and protocol combination already exists on that gateway device, this method tries to overwrite it. If that is not desired, you can retrieve the gateway manually with [method get_gateway] and call [method add_port_mapping] on it, if any. Note that forwarding a well-known port (below 1024) with UPnP may fail depending on the device. + Depending on the gateway device, if a mapping for that port already exists, it will either be updated or it will refuse this command due to that conflict, especially if the existing mapping for that port wasn't created via UPnP or points to a different network address (or device) than this one. If [code]internal_port[/code] is [code]0[/code] (the default), the same port number is used for both the external and the internal port (the [code]port[/code] value). - The description ([code]desc[/code]) is shown in some router UIs and can be used to point out which application added the mapping. The mapping's lease duration can be limited by specifying a [code]duration[/code] (in seconds). However, some routers are incompatible with one or both of these, so use with caution and add fallback logic in case of errors to retry without them if in doubt. + The description ([code]desc[/code]) is shown in some routers management UIs and can be used to point out which application added the mapping. + The mapping's lease [code]duration[/code] can be limited by specifying a duration in seconds. The default of [code]0[/code] means no duration, i.e. a permanent lease and notably some devices only support these permanent leases. Note that whether permanent or not, this is only a request and the gateway may still decide at any point to remove the mapping (which usually happens on a reboot of the gateway, when its external IP address changes, or on some models when it detects a port mapping has become inactive, i.e. had no traffic for multiple minutes). If not [code]0[/code] (permanent), the allowed range according to spec is between [code]120[/code] (2 minutes) and [code]86400[/code] seconds (24 hours). See [enum UPNPResult] for possible return values. </description> </method> @@ -84,7 +93,7 @@ <param index="0" name="port" type="int" /> <param index="1" name="proto" type="String" default=""UDP"" /> <description> - Deletes the port mapping for the given port and protocol combination on the default gateway (see [method get_gateway]) if one exists. [code]port[/code] must be a valid port between 1 and 65535, [code]proto[/code] can be either [code]TCP[/code] or [code]UDP[/code]. See [enum UPNPResult] for possible return values. + Deletes the port mapping for the given port and protocol combination on the default gateway (see [method get_gateway]) if one exists. [code]port[/code] must be a valid port between 1 and 65535, [code]proto[/code] can be either [code]TCP[/code] or [code]UDP[/code]. May be refused for mappings pointing to addresses other than this one, for well-known ports (below 1024), or for mappings not added via UPnP. See [enum UPNPResult] for possible return values. </description> </method> <method name="discover"> diff --git a/modules/upnp/doc_classes/UPNPDevice.xml b/modules/upnp/doc_classes/UPNPDevice.xml index b599acaba2..538ca72391 100644 --- a/modules/upnp/doc_classes/UPNPDevice.xml +++ b/modules/upnp/doc_classes/UPNPDevice.xml @@ -1,10 +1,10 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="UPNPDevice" inherits="RefCounted" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd"> <brief_description> - UPNP device. + Universal Plug and Play (UPnP) device. </brief_description> <description> - UPNP device. See [UPNP] for UPNP discovery and utility functions. Provides low-level access to UPNP control commands. Allows to manage port mappings (port forwarding) and to query network information of the device (like local and external IP address and status). Note that methods on this class are synchronous and block the calling thread. + Universal Plug and Play (UPnP) device. See [UPNP] for UPnP discovery and utility functions. Provides low-level access to UPNP control commands. Allows to manage port mappings (port forwarding) and to query network information of the device (like local and external IP address and status). Note that methods on this class are synchronous and block the calling thread. </description> <tutorials> </tutorials> diff --git a/modules/upnp/upnp.cpp b/modules/upnp/upnp.cpp index d762ca4f09..82fe39e003 100644 --- a/modules/upnp/upnp.cpp +++ b/modules/upnp/upnp.cpp @@ -319,8 +319,6 @@ int UPNP::add_port_mapping(int port, int port_internal, String desc, String prot return UPNP_RESULT_NO_GATEWAY; } - dev->delete_port_mapping(port, proto); - return dev->add_port_mapping(port, port_internal, desc, proto, duration); } diff --git a/modules/webrtc/SCsub b/modules/webrtc/SCsub index e6b9959840..e315633f55 100644 --- a/modules/webrtc/SCsub +++ b/modules/webrtc/SCsub @@ -5,7 +5,7 @@ Import("env_modules") env_webrtc = env_modules.Clone() -if env["platform"] == "javascript": +if env["platform"] == "web": # Our JavaScript/C++ interface. env.AddJSLibraries(["library_godot_webrtc.js"]) diff --git a/modules/webrtc/webrtc_data_channel_js.cpp b/modules/webrtc/webrtc_data_channel_js.cpp index 0fb074b0c2..232f6998d3 100644 --- a/modules/webrtc/webrtc_data_channel_js.cpp +++ b/modules/webrtc/webrtc_data_channel_js.cpp @@ -28,7 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifdef JAVASCRIPT_ENABLED +#ifdef WEB_ENABLED #include "webrtc_data_channel_js.h" diff --git a/modules/webrtc/webrtc_data_channel_js.h b/modules/webrtc/webrtc_data_channel_js.h index d059ec31ed..0caa76885a 100644 --- a/modules/webrtc/webrtc_data_channel_js.h +++ b/modules/webrtc/webrtc_data_channel_js.h @@ -31,7 +31,7 @@ #ifndef WEBRTC_DATA_CHANNEL_JS_H #define WEBRTC_DATA_CHANNEL_JS_H -#ifdef JAVASCRIPT_ENABLED +#ifdef WEB_ENABLED #include "webrtc_data_channel.h" @@ -89,6 +89,6 @@ public: ~WebRTCDataChannelJS(); }; -#endif // JAVASCRIPT_ENABLED +#endif // WEB_ENABLED #endif // WEBRTC_DATA_CHANNEL_JS_H diff --git a/modules/webrtc/webrtc_peer_connection.cpp b/modules/webrtc/webrtc_peer_connection.cpp index 75716017d7..d885b9262b 100644 --- a/modules/webrtc/webrtc_peer_connection.cpp +++ b/modules/webrtc/webrtc_peer_connection.cpp @@ -30,7 +30,7 @@ #include "webrtc_peer_connection.h" -#ifdef JAVASCRIPT_ENABLED +#ifdef WEB_ENABLED #include "webrtc_peer_connection_js.h" #endif @@ -44,7 +44,7 @@ void WebRTCPeerConnection::set_default_extension(const StringName &p_extension) } WebRTCPeerConnection *WebRTCPeerConnection::create() { -#ifdef JAVASCRIPT_ENABLED +#ifdef WEB_ENABLED return memnew(WebRTCPeerConnectionJS); #else if (default_extension == String()) { diff --git a/modules/webrtc/webrtc_peer_connection_js.cpp b/modules/webrtc/webrtc_peer_connection_js.cpp index ee3a302fa2..f48705253b 100644 --- a/modules/webrtc/webrtc_peer_connection_js.cpp +++ b/modules/webrtc/webrtc_peer_connection_js.cpp @@ -28,7 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifdef JAVASCRIPT_ENABLED +#ifdef WEB_ENABLED #include "webrtc_peer_connection_js.h" diff --git a/modules/webrtc/webrtc_peer_connection_js.h b/modules/webrtc/webrtc_peer_connection_js.h index 76b8c7fff8..50266129e4 100644 --- a/modules/webrtc/webrtc_peer_connection_js.h +++ b/modules/webrtc/webrtc_peer_connection_js.h @@ -31,7 +31,7 @@ #ifndef WEBRTC_PEER_CONNECTION_JS_H #define WEBRTC_PEER_CONNECTION_JS_H -#ifdef JAVASCRIPT_ENABLED +#ifdef WEB_ENABLED #include "webrtc_peer_connection.h" diff --git a/modules/websocket/SCsub b/modules/websocket/SCsub index dc0661995f..890fb71592 100644 --- a/modules/websocket/SCsub +++ b/modules/websocket/SCsub @@ -7,7 +7,7 @@ env_ws = env_modules.Clone() thirdparty_obj = [] -if env["platform"] == "javascript": +if env["platform"] == "web": # Our JavaScript/C++ interface. env.AddJSLibraries(["library_godot_websocket.js"]) diff --git a/modules/websocket/doc_classes/WebSocketClient.xml b/modules/websocket/doc_classes/WebSocketClient.xml index f586c58302..7d73194ea9 100644 --- a/modules/websocket/doc_classes/WebSocketClient.xml +++ b/modules/websocket/doc_classes/WebSocketClient.xml @@ -24,8 +24,8 @@ If [code]true[/code] is passed as [code]gd_mp_api[/code], the client will behave like a multiplayer peer for the [MultiplayerAPI], connections to non-Godot servers will not work, and [signal data_received] will not be emitted. If [code]false[/code] is passed instead (default), you must call [PacketPeer] functions ([code]put_packet[/code], [code]get_packet[/code], etc.) on the [WebSocketPeer] returned via [code]get_peer(1)[/code] and not on this object directly (e.g. [code]get_peer(1).put_packet(data)[/code]). You can optionally pass a list of [code]custom_headers[/code] to be added to the handshake HTTP request. - [b]Note:[/b] To avoid mixed content warnings or errors in HTML5, you may have to use a [code]url[/code] that starts with [code]wss://[/code] (secure) instead of [code]ws://[/code]. When doing so, make sure to use the fully qualified domain name that matches the one defined in the server's SSL certificate. Do not connect directly via the IP address for [code]wss://[/code] connections, as it won't match with the SSL certificate. - [b]Note:[/b] Specifying [code]custom_headers[/code] is not supported in HTML5 exports due to browsers restrictions. + [b]Note:[/b] To avoid mixed content warnings or errors in Web, you may have to use a [code]url[/code] that starts with [code]wss://[/code] (secure) instead of [code]ws://[/code]. When doing so, make sure to use the fully qualified domain name that matches the one defined in the server's SSL certificate. Do not connect directly via the IP address for [code]wss://[/code] connections, as it won't match with the SSL certificate. + [b]Note:[/b] Specifying [code]custom_headers[/code] is not supported in Web exports due to browsers restrictions. </description> </method> <method name="disconnect_from_host"> @@ -52,7 +52,7 @@ <members> <member name="trusted_ssl_certificate" type="X509Certificate" setter="set_trusted_ssl_certificate" getter="get_trusted_ssl_certificate"> If specified, this [X509Certificate] will be the only one accepted when connecting to an SSL host. Any other certificate provided by the server will be regarded as invalid. - [b]Note:[/b] Specifying a custom [code]trusted_ssl_certificate[/code] is not supported in HTML5 exports due to browsers restrictions. + [b]Note:[/b] Specifying a custom [code]trusted_ssl_certificate[/code] is not supported in Web exports due to browsers restrictions. </member> <member name="verify_ssl" type="bool" setter="set_verify_ssl_enabled" getter="is_verify_ssl_enabled"> If [code]true[/code], SSL certificate verification is enabled. diff --git a/modules/websocket/doc_classes/WebSocketMultiplayerPeer.xml b/modules/websocket/doc_classes/WebSocketMultiplayerPeer.xml index 23aa6ba3db..4cc4d515e7 100644 --- a/modules/websocket/doc_classes/WebSocketMultiplayerPeer.xml +++ b/modules/websocket/doc_classes/WebSocketMultiplayerPeer.xml @@ -27,7 +27,7 @@ Configures the buffer sizes for this WebSocket peer. Default values can be specified in the Project Settings under [code]network/limits[/code]. For server, values are meant per connected peer. The first two parameters define the size and queued packets limits of the input buffer, the last two of the output buffer. Buffer sizes are expressed in KiB, so [code]4 = 2^12 = 4096 bytes[/code]. All parameters will be rounded up to the nearest power of two. - [b]Note:[/b] HTML5 exports only use the input buffer since the output one is managed by browsers. + [b]Note:[/b] Web exports only use the input buffer since the output one is managed by browsers. </description> </method> </methods> diff --git a/modules/websocket/doc_classes/WebSocketPeer.xml b/modules/websocket/doc_classes/WebSocketPeer.xml index 43b765d2fe..627b9c607c 100644 --- a/modules/websocket/doc_classes/WebSocketPeer.xml +++ b/modules/websocket/doc_classes/WebSocketPeer.xml @@ -17,27 +17,27 @@ <description> Closes this WebSocket connection. [code]code[/code] is the status code for the closure (see RFC 6455 section 7.4 for a list of valid status codes). [code]reason[/code] is the human readable reason for closing the connection (can be any UTF-8 string that's smaller than 123 bytes). [b]Note:[/b] To achieve a clean close, you will need to keep polling until either [signal WebSocketClient.connection_closed] or [signal WebSocketServer.client_disconnected] is received. - [b]Note:[/b] The HTML5 export might not support all status codes. Please refer to browser-specific documentation for more details. + [b]Note:[/b] The Web export might not support all status codes. Please refer to browser-specific documentation for more details. </description> </method> <method name="get_connected_host" qualifiers="const"> <return type="String" /> <description> Returns the IP address of the connected peer. - [b]Note:[/b] Not available in the HTML5 export. + [b]Note:[/b] Not available in the Web export. </description> </method> <method name="get_connected_port" qualifiers="const"> <return type="int" /> <description> Returns the remote port of the connected peer. - [b]Note:[/b] Not available in the HTML5 export. + [b]Note:[/b] Not available in the Web export. </description> </method> <method name="get_current_outbound_buffered_amount" qualifiers="const"> <return type="int" /> <description> - Returns the current amount of data in the outbound websocket buffer. [b]Note:[/b] HTML5 exports use WebSocket.bufferedAmount, while other platforms use an internal buffer. + Returns the current amount of data in the outbound websocket buffer. [b]Note:[/b] Web exports use WebSocket.bufferedAmount, while other platforms use an internal buffer. </description> </method> <method name="get_write_mode" qualifiers="const"> @@ -57,7 +57,7 @@ <param index="0" name="enabled" type="bool" /> <description> Disable Nagle's algorithm on the underling TCP socket (default). See [method StreamPeerTCP.set_no_delay] for more information. - [b]Note:[/b] Not available in the HTML5 export. + [b]Note:[/b] Not available in the Web export. </description> </method> <method name="set_write_mode"> diff --git a/modules/websocket/doc_classes/WebSocketServer.xml b/modules/websocket/doc_classes/WebSocketServer.xml index 6a7bf8075c..19c36700e6 100644 --- a/modules/websocket/doc_classes/WebSocketServer.xml +++ b/modules/websocket/doc_classes/WebSocketServer.xml @@ -6,7 +6,7 @@ <description> This class implements a WebSocket server that can also support the high-level multiplayer API. After starting the server ([method listen]), you will need to [method MultiplayerPeer.poll] it at regular intervals (e.g. inside [method Node._process]). When clients connect, disconnect, or send data, you will receive the appropriate signal. - [b]Note:[/b] Not available in HTML5 exports. + [b]Note:[/b] Not available in Web exports. [b]Note:[/b] When exporting to Android, make sure to enable the [code]INTERNET[/code] permission in the Android export preset before exporting the project or using one-click deploy. Otherwise, network communication of any kind will be blocked by Android. </description> <tutorials> diff --git a/modules/websocket/emws_client.cpp b/modules/websocket/emws_client.cpp index e051a3b564..65e0703c00 100644 --- a/modules/websocket/emws_client.cpp +++ b/modules/websocket/emws_client.cpp @@ -28,7 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifdef JAVASCRIPT_ENABLED +#ifdef WEB_ENABLED #include "emws_client.h" @@ -82,12 +82,12 @@ Error EMWSClient::connect_to_host(String p_host, String p_path, uint16_t p_port, String str = "ws://"; if (p_custom_headers.size()) { - WARN_PRINT_ONCE("Custom headers are not supported in HTML5 platform."); + WARN_PRINT_ONCE("Custom headers are not supported in Web platform."); } if (p_ssl) { str = "wss://"; if (ssl_cert.is_valid()) { - WARN_PRINT_ONCE("Custom SSL certificate is not supported in HTML5 platform."); + WARN_PRINT_ONCE("Custom SSL certificate is not supported in Web platform."); } } str += p_host + ":" + itos(p_port) + p_path; @@ -126,11 +126,11 @@ void EMWSClient::disconnect_from_host(int p_code, String p_reason) { } IPAddress EMWSClient::get_connected_host() const { - ERR_FAIL_V_MSG(IPAddress(), "Not supported in HTML5 export."); + ERR_FAIL_V_MSG(IPAddress(), "Not supported in Web export."); } uint16_t EMWSClient::get_connected_port() const { - ERR_FAIL_V_MSG(0, "Not supported in HTML5 export."); + ERR_FAIL_V_MSG(0, "Not supported in Web export."); } int EMWSClient::get_max_packet_size() const { @@ -156,4 +156,4 @@ EMWSClient::~EMWSClient() { } } -#endif // JAVASCRIPT_ENABLED +#endif // WEB_ENABLED diff --git a/modules/websocket/emws_client.h b/modules/websocket/emws_client.h index b71fd78124..ff63a76753 100644 --- a/modules/websocket/emws_client.h +++ b/modules/websocket/emws_client.h @@ -31,7 +31,7 @@ #ifndef EMWS_CLIENT_H #define EMWS_CLIENT_H -#ifdef JAVASCRIPT_ENABLED +#ifdef WEB_ENABLED #include "core/error/error_list.h" #include "emws_peer.h" @@ -66,6 +66,6 @@ public: ~EMWSClient(); }; -#endif // JAVASCRIPT_ENABLED +#endif // WEB_ENABLED #endif // EMWS_CLIENT_H diff --git a/modules/websocket/emws_peer.cpp b/modules/websocket/emws_peer.cpp index 86169f88e9..859c92b457 100644 --- a/modules/websocket/emws_peer.cpp +++ b/modules/websocket/emws_peer.cpp @@ -28,7 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifdef JAVASCRIPT_ENABLED +#ifdef WEB_ENABLED #include "emws_peer.h" @@ -110,15 +110,15 @@ void EMWSPeer::close(int p_code, String p_reason) { } IPAddress EMWSPeer::get_connected_host() const { - ERR_FAIL_V_MSG(IPAddress(), "Not supported in HTML5 export."); + ERR_FAIL_V_MSG(IPAddress(), "Not supported in Web export."); } uint16_t EMWSPeer::get_connected_port() const { - ERR_FAIL_V_MSG(0, "Not supported in HTML5 export."); + ERR_FAIL_V_MSG(0, "Not supported in Web export."); } void EMWSPeer::set_no_delay(bool p_enabled) { - ERR_FAIL_MSG("'set_no_delay' is not supported in HTML5 export."); + ERR_FAIL_MSG("'set_no_delay' is not supported in Web export."); } EMWSPeer::EMWSPeer() { @@ -129,4 +129,4 @@ EMWSPeer::~EMWSPeer() { close(); } -#endif // JAVASCRIPT_ENABLED +#endif // WEB_ENABLED diff --git a/modules/websocket/emws_peer.h b/modules/websocket/emws_peer.h index f52f615c35..cdbc9212a5 100644 --- a/modules/websocket/emws_peer.h +++ b/modules/websocket/emws_peer.h @@ -31,7 +31,7 @@ #ifndef EMWS_PEER_H #define EMWS_PEER_H -#ifdef JAVASCRIPT_ENABLED +#ifdef WEB_ENABLED #include "core/error/error_list.h" #include "core/io/packet_peer.h" @@ -88,6 +88,6 @@ public: ~EMWSPeer(); }; -#endif // JAVASCRIPT_ENABLED +#endif // WEB_ENABLED #endif // EMWS_PEER_H diff --git a/modules/websocket/register_types.cpp b/modules/websocket/register_types.cpp index 056111ec92..faa7021b2f 100644 --- a/modules/websocket/register_types.cpp +++ b/modules/websocket/register_types.cpp @@ -36,7 +36,7 @@ #include "websocket_client.h" #include "websocket_server.h" -#ifdef JAVASCRIPT_ENABLED +#ifdef WEB_ENABLED #include "emscripten.h" #include "emws_client.h" #include "emws_peer.h" @@ -59,7 +59,7 @@ static void _editor_init_callback() { void initialize_websocket_module(ModuleInitializationLevel p_level) { if (p_level == MODULE_INITIALIZATION_LEVEL_SCENE) { -#ifdef JAVASCRIPT_ENABLED +#ifdef WEB_ENABLED EMWSPeer::make_default(); EMWSClient::make_default(); #else diff --git a/modules/websocket/remote_debugger_peer_websocket.cpp b/modules/websocket/remote_debugger_peer_websocket.cpp index 6319c3c664..f703873cbf 100644 --- a/modules/websocket/remote_debugger_peer_websocket.cpp +++ b/modules/websocket/remote_debugger_peer_websocket.cpp @@ -103,7 +103,7 @@ void RemoteDebuggerPeerWebSocket::close() { } bool RemoteDebuggerPeerWebSocket::can_block() const { -#ifdef JAVASCRIPT_ENABLED +#ifdef WEB_ENABLED return false; #else return true; @@ -111,7 +111,7 @@ bool RemoteDebuggerPeerWebSocket::can_block() const { } RemoteDebuggerPeerWebSocket::RemoteDebuggerPeerWebSocket(Ref<WebSocketPeer> p_peer) { -#ifdef JAVASCRIPT_ENABLED +#ifdef WEB_ENABLED ws_client = Ref<WebSocketClient>(memnew(EMWSClient)); #else ws_client = Ref<WebSocketClient>(memnew(WSLClient)); diff --git a/modules/websocket/remote_debugger_peer_websocket.h b/modules/websocket/remote_debugger_peer_websocket.h index 3227065ded..a37a789cbe 100644 --- a/modules/websocket/remote_debugger_peer_websocket.h +++ b/modules/websocket/remote_debugger_peer_websocket.h @@ -33,7 +33,7 @@ #include "core/debugger/remote_debugger_peer.h" -#ifdef JAVASCRIPT_ENABLED +#ifdef WEB_ENABLED #include "emws_client.h" #else #include "wsl_client.h" diff --git a/modules/websocket/wsl_client.cpp b/modules/websocket/wsl_client.cpp index 478dbb9d47..2bb57226ea 100644 --- a/modules/websocket/wsl_client.cpp +++ b/modules/websocket/wsl_client.cpp @@ -28,7 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef JAVASCRIPT_ENABLED +#ifndef WEB_ENABLED #include "wsl_client.h" #include "core/config/project_settings.h" @@ -404,4 +404,4 @@ WSLClient::~WSLClient() { disconnect_from_host(); } -#endif // JAVASCRIPT_ENABLED +#endif // WEB_ENABLED diff --git a/modules/websocket/wsl_client.h b/modules/websocket/wsl_client.h index 58b867fbe4..5d90bc4034 100644 --- a/modules/websocket/wsl_client.h +++ b/modules/websocket/wsl_client.h @@ -31,7 +31,7 @@ #ifndef WSL_CLIENT_H #define WSL_CLIENT_H -#ifndef JAVASCRIPT_ENABLED +#ifndef WEB_ENABLED #include "core/error/error_list.h" #include "core/io/stream_peer_ssl.h" @@ -86,6 +86,6 @@ public: ~WSLClient(); }; -#endif // JAVASCRIPT_ENABLED +#endif // WEB_ENABLED #endif // WSL_CLIENT_H diff --git a/modules/websocket/wsl_peer.cpp b/modules/websocket/wsl_peer.cpp index 15df4d039c..97bd87a526 100644 --- a/modules/websocket/wsl_peer.cpp +++ b/modules/websocket/wsl_peer.cpp @@ -28,7 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef JAVASCRIPT_ENABLED +#ifndef WEB_ENABLED #include "wsl_peer.h" @@ -348,4 +348,4 @@ WSLPeer::~WSLPeer() { _data = nullptr; } -#endif // JAVASCRIPT_ENABLED +#endif // WEB_ENABLED diff --git a/modules/websocket/wsl_peer.h b/modules/websocket/wsl_peer.h index aabd3fd43e..92672eb2c4 100644 --- a/modules/websocket/wsl_peer.h +++ b/modules/websocket/wsl_peer.h @@ -31,7 +31,7 @@ #ifndef WSL_PEER_H #define WSL_PEER_H -#ifndef JAVASCRIPT_ENABLED +#ifndef WEB_ENABLED #include "core/error/error_list.h" #include "core/io/packet_peer.h" @@ -110,6 +110,6 @@ public: ~WSLPeer(); }; -#endif // JAVASCRIPT_ENABLED +#endif // WEB_ENABLED #endif // WSL_PEER_H diff --git a/modules/websocket/wsl_server.cpp b/modules/websocket/wsl_server.cpp index 517b9643f8..7457ac7087 100644 --- a/modules/websocket/wsl_server.cpp +++ b/modules/websocket/wsl_server.cpp @@ -28,7 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef JAVASCRIPT_ENABLED +#ifndef WEB_ENABLED #include "wsl_server.h" #include "core/config/project_settings.h" @@ -326,4 +326,4 @@ WSLServer::~WSLServer() { stop(); } -#endif // JAVASCRIPT_ENABLED +#endif // WEB_ENABLED diff --git a/modules/websocket/wsl_server.h b/modules/websocket/wsl_server.h index ec7567c732..b0b7a6a5c9 100644 --- a/modules/websocket/wsl_server.h +++ b/modules/websocket/wsl_server.h @@ -31,7 +31,7 @@ #ifndef WSL_SERVER_H #define WSL_SERVER_H -#ifndef JAVASCRIPT_ENABLED +#ifndef WEB_ENABLED #include "websocket_server.h" #include "wsl_peer.h" @@ -93,6 +93,6 @@ public: ~WSLServer(); }; -#endif // JAVASCRIPT_ENABLED +#endif // WEB_ENABLED #endif // WSL_SERVER_H diff --git a/modules/webxr/SCsub b/modules/webxr/SCsub index 0a96af0811..81caa4a279 100644 --- a/modules/webxr/SCsub +++ b/modules/webxr/SCsub @@ -3,7 +3,7 @@ Import("env") Import("env_modules") -if env["platform"] == "javascript": +if env["platform"] == "web": env.AddJSLibraries(["native/library_godot_webxr.js"]) env.AddJSExterns(["native/webxr.externs.js"]) diff --git a/modules/webxr/doc_classes/WebXRInterface.xml b/modules/webxr/doc_classes/WebXRInterface.xml index 01ad962b20..49ff454f07 100644 --- a/modules/webxr/doc_classes/WebXRInterface.xml +++ b/modules/webxr/doc_classes/WebXRInterface.xml @@ -5,9 +5,9 @@ </brief_description> <description> WebXR is an open standard that allows creating VR and AR applications that run in the web browser. - As such, this interface is only available when running in an HTML5 export. + As such, this interface is only available when running in Web exports. WebXR supports a wide range of devices, from the very capable (like Valve Index, HTC Vive, Oculus Rift and Quest) down to the much less capable (like Google Cardboard, Oculus Go, GearVR, or plain smartphones). - Since WebXR is based on Javascript, it makes extensive use of callbacks, which means that [WebXRInterface] is forced to use signals, where other AR/VR interfaces would instead use functions that return a result immediately. This makes [WebXRInterface] quite a bit more complicated to initialize than other AR/VR interfaces. + Since WebXR is based on JavaScript, it makes extensive use of callbacks, which means that [WebXRInterface] is forced to use signals, where other AR/VR interfaces would instead use functions that return a result immediately. This makes [WebXRInterface] quite a bit more complicated to initialize than other AR/VR interfaces. Here's the minimum code required to start an immersive VR session: [codeblock] extends Node3D diff --git a/modules/webxr/register_types.cpp b/modules/webxr/register_types.cpp index cd403a4996..f4959c482f 100644 --- a/modules/webxr/register_types.cpp +++ b/modules/webxr/register_types.cpp @@ -33,7 +33,7 @@ #include "webxr_interface.h" #include "webxr_interface_js.h" -#ifdef JAVASCRIPT_ENABLED +#ifdef WEB_ENABLED Ref<WebXRInterfaceJS> webxr; #endif @@ -44,7 +44,7 @@ void initialize_webxr_module(ModuleInitializationLevel p_level) { GDREGISTER_ABSTRACT_CLASS(WebXRInterface); -#ifdef JAVASCRIPT_ENABLED +#ifdef WEB_ENABLED webxr.instantiate(); XRServer::get_singleton()->add_interface(webxr); #endif @@ -55,7 +55,7 @@ void uninitialize_webxr_module(ModuleInitializationLevel p_level) { return; } -#ifdef JAVASCRIPT_ENABLED +#ifdef WEB_ENABLED if (webxr.is_valid()) { // uninitialise our interface if it is initialised if (webxr->is_initialized()) { diff --git a/modules/webxr/webxr_interface_js.cpp b/modules/webxr/webxr_interface_js.cpp index 07e6760555..7d97dbfa0b 100644 --- a/modules/webxr/webxr_interface_js.cpp +++ b/modules/webxr/webxr_interface_js.cpp @@ -28,7 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifdef JAVASCRIPT_ENABLED +#ifdef WEB_ENABLED #include "webxr_interface_js.h" @@ -518,4 +518,4 @@ WebXRInterfaceJS::~WebXRInterfaceJS() { }; }; -#endif // JAVASCRIPT_ENABLED +#endif // WEB_ENABLED diff --git a/modules/webxr/webxr_interface_js.h b/modules/webxr/webxr_interface_js.h index f1ffedba46..dbe89dad83 100644 --- a/modules/webxr/webxr_interface_js.h +++ b/modules/webxr/webxr_interface_js.h @@ -31,7 +31,7 @@ #ifndef WEBXR_INTERFACE_JS_H #define WEBXR_INTERFACE_JS_H -#ifdef JAVASCRIPT_ENABLED +#ifdef WEB_ENABLED #include "webxr_interface.h" @@ -98,6 +98,6 @@ public: ~WebXRInterfaceJS(); }; -#endif // JAVASCRIPT_ENABLED +#endif // WEB_ENABLED #endif // WEBXR_INTERFACE_JS_H |