diff options
899 files changed, 30080 insertions, 17357 deletions
diff --git a/.github/workflows/linux_builds.yml b/.github/workflows/linux_builds.yml index b4bbaaacb1..ace1ce3fec 100644 --- a/.github/workflows/linux_builds.yml +++ b/.github/workflows/linux_builds.yml @@ -26,7 +26,7 @@ jobs: - name: Configure dependencies run: | sudo apt-get install build-essential pkg-config libx11-dev libxcursor-dev \ - libxinerama-dev libgl1-mesa-dev libglu-dev libasound2-dev libpulse-dev libudev-dev libxi-dev libxrandr-dev yasm + libxinerama-dev libgl1-mesa-dev libglu-dev libasound2-dev libpulse-dev libdbus-1-dev libudev-dev libxi-dev libxrandr-dev yasm # Upload cache on completion and check it out now - name: Load .scons_cache directory @@ -111,7 +111,7 @@ jobs: - name: Configure dependencies run: | sudo apt-get install build-essential pkg-config libx11-dev libxcursor-dev \ - libxinerama-dev libgl1-mesa-dev libglu-dev libasound2-dev libpulse-dev libudev-dev libxi-dev libxrandr-dev yasm \ + libxinerama-dev libgl1-mesa-dev libglu-dev libasound2-dev libpulse-dev libdbus-1-dev libudev-dev libxi-dev libxrandr-dev yasm \ xvfb wget unzip # Upload cache on completion and check it out now @@ -204,7 +204,7 @@ jobs: - name: Configure dependencies run: | sudo apt-get install build-essential pkg-config libx11-dev libxcursor-dev \ - libxinerama-dev libgl1-mesa-dev libglu-dev libasound2-dev libpulse-dev libudev-dev libxi-dev libxrandr-dev yasm + libxinerama-dev libgl1-mesa-dev libglu-dev libasound2-dev libpulse-dev libdbus-1-dev libudev-dev libxi-dev libxrandr-dev yasm # Upload cache on completion and check it out now - name: Load .scons_cache directory diff --git a/SConstruct b/SConstruct index f8e3a68edd..8b37bb8285 100644 --- a/SConstruct +++ b/SConstruct @@ -4,10 +4,12 @@ EnsureSConsVersion(3, 0, 0) EnsurePythonVersion(3, 5) # System +import atexit import glob import os import pickle import sys +import time from collections import OrderedDict # Local @@ -25,6 +27,8 @@ active_platform_ids = [] platform_exporters = [] platform_apis = [] +time_at_start = time.time() + for x in sorted(glob.glob("platform/*")): if not os.path.isdir(x) or not os.path.exists(x + "/detect.py"): continue @@ -551,11 +555,10 @@ if selected_platform in platform_list: if env["target"] == "release": if env["tools"]: - print("Tools can only be built with targets 'debug' and 'release_debug'.") + print("Error: The editor can only be built with `target=debug` or `target=release_debug`.") Exit(255) suffix += ".opt" env.Append(CPPDEFINES=["NDEBUG"]) - elif env["target"] == "release_debug": if env["tools"]: suffix += ".opt.tools" @@ -563,8 +566,14 @@ if selected_platform in platform_list: suffix += ".opt.debug" else: if env["tools"]: + print( + "Note: Building a debug binary (which will run slowly). Use `target=release_debug` to build an optimized release binary." + ) suffix += ".tools" else: + print( + "Note: Building a debug binary (which will run slowly). Use `target=release` to build an optimized release binary." + ) suffix += ".debug" if env["arch"] != "": @@ -743,3 +752,12 @@ if "env" in locals(): # TODO: replace this with `env.Dump(format="json")` # once we start requiring SCons 4.0 as min version. methods.dump(env) + + +def print_elapsed_time(): + elapsed_time_sec = round(time.time() - time_at_start, 3) + time_ms = round((elapsed_time_sec % 1) * 1000) + print(f"[Time elapsed: {time.strftime('%H:%M:%S', time.gmtime(elapsed_time_sec))}.{time_ms:03}]") + + +atexit.register(print_elapsed_time) diff --git a/core/SCsub b/core/SCsub index e3ba46be02..d9167b8f83 100644 --- a/core/SCsub +++ b/core/SCsub @@ -186,6 +186,7 @@ SConscript("io/SCsub") SConscript("debugger/SCsub") SConscript("input/SCsub") SConscript("variant/SCsub") +SConscript("extension/SCsub") SConscript("object/SCsub") SConscript("templates/SCsub") SConscript("string/SCsub") diff --git a/core/config/engine.cpp b/core/config/engine.cpp index 99ec1aeb5b..ad31966a65 100644 --- a/core/config/engine.cpp +++ b/core/config/engine.cpp @@ -190,6 +190,14 @@ bool Engine::is_validation_layers_enabled() const { return use_validation_layers; } +void Engine::set_print_error_messages(bool p_enabled) { + _print_error_enabled = p_enabled; +} + +bool Engine::is_printing_error_messages() const { + return _print_error_enabled; +} + void Engine::add_singleton(const Singleton &p_singleton) { singletons.push_back(p_singleton); singleton_ptrs[p_singleton.name] = p_singleton.ptr; @@ -228,9 +236,10 @@ Engine::Engine() { singleton = this; } -Engine::Singleton::Singleton(const StringName &p_name, Object *p_ptr) : +Engine::Singleton::Singleton(const StringName &p_name, Object *p_ptr, const StringName &p_class_name) : name(p_name), - ptr(p_ptr) { + ptr(p_ptr), + class_name(p_class_name) { #ifdef DEBUG_ENABLED RefCounted *rc = Object::cast_to<RefCounted>(p_ptr); if (rc && !rc->is_referenced()) { diff --git a/core/config/engine.h b/core/config/engine.h index 276da1c7ea..970cfb03e8 100644 --- a/core/config/engine.h +++ b/core/config/engine.h @@ -41,7 +41,8 @@ public: struct Singleton { StringName name; Object *ptr; - Singleton(const StringName &p_name = StringName(), Object *p_ptr = nullptr); + StringName class_name; //used for binding generation hinting + Singleton(const StringName &p_name = StringName(), Object *p_ptr = nullptr, const StringName &p_class_name = StringName()); }; private: @@ -100,6 +101,9 @@ public: void set_time_scale(float p_scale); float get_time_scale() const; + void set_print_error_messages(bool p_enabled); + bool is_printing_error_messages() const; + void set_frame_delay(uint32_t p_msec); uint32_t get_frame_delay() const; diff --git a/core/config/project_settings.cpp b/core/config/project_settings.cpp index 74ef05b797..ac4e0db5b7 100644 --- a/core/config/project_settings.cpp +++ b/core/config/project_settings.cpp @@ -248,7 +248,7 @@ struct _VCSort { String name; Variant::Type type; int order; - int flags; + uint32_t flags; bool operator<(const _VCSort &p_vcs) const { return order == p_vcs.order ? name < p_vcs.name : order < p_vcs.order; } }; @@ -1114,6 +1114,8 @@ ProjectSettings::ProjectSettings() { // Keep the enum values in sync with the `DisplayServer::ScreenOrientation` enum. custom_prop_info["display/window/handheld/orientation"] = PropertyInfo(Variant::INT, "display/window/handheld/orientation", PROPERTY_HINT_ENUM, "Landscape,Portrait,Reverse Landscape,Reverse Portrait,Sensor Landscape,Sensor Portrait,Sensor"); + // Keep the enum values in sync with the `DisplayServer::VSyncMode` enum. + custom_prop_info["display/window/vsync/vsync_mode"] = PropertyInfo(Variant::INT, "display/window/vsync/vsync_mode", PROPERTY_HINT_ENUM, "Disabled,Enabled,Adaptive,Mailbox"); custom_prop_info["rendering/driver/threads/thread_model"] = PropertyInfo(Variant::INT, "rendering/driver/threads/thread_model", PROPERTY_HINT_ENUM, "Single-Unsafe,Single-Safe,Multi-Threaded"); GLOBAL_DEF("physics/2d/run_on_thread", false); GLOBAL_DEF("physics/3d/run_on_thread", false); diff --git a/core/core_bind.cpp b/core/core_bind.cpp index 60759cd71c..a3349444c4 100644 --- a/core/core_bind.cpp +++ b/core/core_bind.cpp @@ -35,7 +35,6 @@ #include "core/debugger/engine_debugger.h" #include "core/io/file_access_compressed.h" #include "core/io/file_access_encrypted.h" -#include "core/io/json.h" #include "core/io/marshalls.h" #include "core/math/geometry_2d.h" #include "core/math/geometry_3d.h" @@ -426,6 +425,21 @@ String _OS::get_external_data_dir() const { return OS::get_singleton()->get_external_data_dir(); } +String _OS::get_config_dir() const { + // Exposed as `get_config_dir()` instead of `get_config_path()` for consistency with other exposed OS methods. + return OS::get_singleton()->get_config_path(); +} + +String _OS::get_data_dir() const { + // Exposed as `get_data_dir()` instead of `get_data_path()` for consistency with other exposed OS methods. + return OS::get_singleton()->get_data_path(); +} + +String _OS::get_cache_dir() const { + // Exposed as `get_cache_dir()` instead of `get_cache_path()` for consistency with other exposed OS methods. + return OS::get_singleton()->get_cache_path(); +} + bool _OS::is_debug_build() const { #ifdef DEBUG_ENABLED return true; @@ -518,6 +532,9 @@ void _OS::_bind_methods() { ClassDB::bind_method(D_METHOD("get_user_data_dir"), &_OS::get_user_data_dir); ClassDB::bind_method(D_METHOD("get_external_data_dir"), &_OS::get_external_data_dir); ClassDB::bind_method(D_METHOD("get_system_dir", "dir"), &_OS::get_system_dir); + ClassDB::bind_method(D_METHOD("get_config_dir"), &_OS::get_config_dir); + ClassDB::bind_method(D_METHOD("get_data_dir"), &_OS::get_data_dir); + ClassDB::bind_method(D_METHOD("get_cache_dir"), &_OS::get_cache_dir); ClassDB::bind_method(D_METHOD("get_unique_id"), &_OS::get_unique_id); ClassDB::bind_method(D_METHOD("print_all_textures_by_size"), &_OS::print_all_textures_by_size); @@ -1833,12 +1850,12 @@ bool _ClassDB::is_parent_class(const StringName &p_class, const StringName &p_in return ClassDB::is_parent_class(p_class, p_inherits); } -bool _ClassDB::can_instance(const StringName &p_class) const { - return ClassDB::can_instance(p_class); +bool _ClassDB::can_instantiate(const StringName &p_class) const { + return ClassDB::can_instantiate(p_class); } -Variant _ClassDB::instance(const StringName &p_class) const { - Object *obj = ClassDB::instance(p_class); +Variant _ClassDB::instantiate(const StringName &p_class) const { + Object *obj = ClassDB::instantiate(p_class); if (!obj) { return Variant(); } @@ -1967,8 +1984,8 @@ void _ClassDB::_bind_methods() { ClassDB::bind_method(D_METHOD("get_parent_class", "class"), &_ClassDB::get_parent_class); ClassDB::bind_method(D_METHOD("class_exists", "class"), &_ClassDB::class_exists); ClassDB::bind_method(D_METHOD("is_parent_class", "class", "inherits"), &_ClassDB::is_parent_class); - ClassDB::bind_method(D_METHOD("can_instance", "class"), &_ClassDB::can_instance); - ClassDB::bind_method(D_METHOD("instance", "class"), &_ClassDB::instance); + ClassDB::bind_method(D_METHOD("can_instantiate", "class"), &_ClassDB::can_instantiate); + ClassDB::bind_method(D_METHOD("instantiate", "class"), &_ClassDB::instantiate); ClassDB::bind_method(D_METHOD("class_has_signal", "class", "signal"), &_ClassDB::has_signal); ClassDB::bind_method(D_METHOD("class_get_signal", "class", "signal"), &_ClassDB::get_signal); @@ -2094,6 +2111,14 @@ bool _Engine::is_editor_hint() const { return Engine::get_singleton()->is_editor_hint(); } +void _Engine::set_print_error_messages(bool p_enabled) { + Engine::get_singleton()->set_print_error_messages(p_enabled); +} + +bool _Engine::is_printing_error_messages() const { + return Engine::get_singleton()->is_printing_error_messages(); +} + void _Engine::_bind_methods() { ClassDB::bind_method(D_METHOD("set_iterations_per_second", "iterations_per_second"), &_Engine::set_iterations_per_second); ClassDB::bind_method(D_METHOD("get_iterations_per_second"), &_Engine::get_iterations_per_second); @@ -2128,7 +2153,11 @@ void _Engine::_bind_methods() { ClassDB::bind_method(D_METHOD("set_editor_hint", "enabled"), &_Engine::set_editor_hint); ClassDB::bind_method(D_METHOD("is_editor_hint"), &_Engine::is_editor_hint); + ClassDB::bind_method(D_METHOD("set_print_error_messages", "enabled"), &_Engine::set_print_error_messages); + ClassDB::bind_method(D_METHOD("is_printing_error_messages"), &_Engine::is_printing_error_messages); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editor_hint"), "set_editor_hint", "is_editor_hint"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "print_error_messages"), "set_print_error_messages", "is_printing_error_messages"); ADD_PROPERTY(PropertyInfo(Variant::INT, "iterations_per_second"), "set_iterations_per_second", "get_iterations_per_second"); ADD_PROPERTY(PropertyInfo(Variant::INT, "target_fps"), "set_target_fps", "get_target_fps"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "time_scale"), "set_time_scale", "get_time_scale"); @@ -2137,80 +2166,6 @@ void _Engine::_bind_methods() { _Engine *_Engine::singleton = nullptr; -////// _JSON ////// - -void JSONParseResult::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_error"), &JSONParseResult::get_error); - ClassDB::bind_method(D_METHOD("get_error_string"), &JSONParseResult::get_error_string); - ClassDB::bind_method(D_METHOD("get_error_line"), &JSONParseResult::get_error_line); - ClassDB::bind_method(D_METHOD("get_result"), &JSONParseResult::get_result); - - ClassDB::bind_method(D_METHOD("set_error", "error"), &JSONParseResult::set_error); - ClassDB::bind_method(D_METHOD("set_error_string", "error_string"), &JSONParseResult::set_error_string); - ClassDB::bind_method(D_METHOD("set_error_line", "error_line"), &JSONParseResult::set_error_line); - ClassDB::bind_method(D_METHOD("set_result", "result"), &JSONParseResult::set_result); - - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "error", PROPERTY_HINT_NONE, "Error", PROPERTY_USAGE_CLASS_IS_ENUM), "set_error", "get_error"); - ADD_PROPERTY(PropertyInfo(Variant::STRING, "error_string"), "set_error_string", "get_error_string"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "error_line"), "set_error_line", "get_error_line"); - ADD_PROPERTY(PropertyInfo(Variant::NIL, "result", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NIL_IS_VARIANT), "set_result", "get_result"); -} - -void JSONParseResult::set_error(Error p_error) { - error = p_error; -} - -Error JSONParseResult::get_error() const { - return error; -} - -void JSONParseResult::set_error_string(const String &p_error_string) { - error_string = p_error_string; -} - -String JSONParseResult::get_error_string() const { - return error_string; -} - -void JSONParseResult::set_error_line(int p_error_line) { - error_line = p_error_line; -} - -int JSONParseResult::get_error_line() const { - return error_line; -} - -void JSONParseResult::set_result(const Variant &p_result) { - result = p_result; -} - -Variant JSONParseResult::get_result() const { - return result; -} - -void _JSON::_bind_methods() { - ClassDB::bind_method(D_METHOD("print", "value", "indent", "sort_keys", "full_precision"), &_JSON::print, DEFVAL(String()), DEFVAL(false), DEFVAL(false)); - ClassDB::bind_method(D_METHOD("parse", "json"), &_JSON::parse); -} - -String _JSON::print(const Variant &p_value, const String &p_indent, bool p_sort_keys, bool p_full_precision) { - return JSON::print(p_value, p_indent, p_sort_keys, p_full_precision); -} - -Ref<JSONParseResult> _JSON::parse(const String &p_json) { - Ref<JSONParseResult> result; - result.instance(); - - result->error = JSON::parse(p_json, result->result, result->error_string, result->error_line); - - if (result->error != OK) { - ERR_PRINT(vformat("Error parsing JSON at line %s: %s", result->error_line, result->error_string)); - } - return result; -} - -_JSON *_JSON::singleton = nullptr; - ////// _EngineDebugger ////// void _EngineDebugger::_bind_methods() { diff --git a/core/core_bind.h b/core/core_bind.h index b161effe95..673dbe32c4 100644 --- a/core/core_bind.h +++ b/core/core_bind.h @@ -230,6 +230,9 @@ public: String get_user_data_dir() const; String get_external_data_dir() const; + String get_config_dir() const; + String get_data_dir() const; + String get_cache_dir() const; Error set_thread_name(const String &p_name); Thread::ID get_thread_caller_id() const; @@ -582,8 +585,8 @@ public: StringName get_parent_class(const StringName &p_class) const; bool class_exists(const StringName &p_class) const; bool is_parent_class(const StringName &p_class, const StringName &p_inherits) const; - bool can_instance(const StringName &p_class) const; - Variant instance(const StringName &p_class) const; + bool can_instantiate(const StringName &p_class) const; + Variant instantiate(const StringName &p_class) const; bool has_signal(StringName p_class, StringName p_signal) const; Dictionary get_signal(StringName p_class, StringName p_signal) const; @@ -653,55 +656,10 @@ public: void set_editor_hint(bool p_enabled); bool is_editor_hint() const; - _Engine() { singleton = this; } -}; - -class _JSON; - -class JSONParseResult : public RefCounted { - GDCLASS(JSONParseResult, RefCounted); - - friend class _JSON; - - Error error; - String error_string; - int error_line = -1; - - Variant result; - -protected: - static void _bind_methods(); - -public: - void set_error(Error p_error); - Error get_error() const; - - void set_error_string(const String &p_error_string); - String get_error_string() const; + void set_print_error_messages(bool p_enabled); + bool is_printing_error_messages() const; - void set_error_line(int p_error_line); - int get_error_line() const; - - void set_result(const Variant &p_result); - Variant get_result() const; - - JSONParseResult() {} -}; - -class _JSON : public Object { - GDCLASS(_JSON, Object); - -protected: - static void _bind_methods(); - static _JSON *singleton; - -public: - static _JSON *get_singleton() { return singleton; } - - String print(const Variant &p_value, const String &p_indent = "", bool p_sort_keys = false, bool p_full_precision = false); - Ref<JSONParseResult> parse(const String &p_json); - - _JSON() { singleton = this; } + _Engine() { singleton = this; } }; class _EngineDebugger : public Object { diff --git a/core/core_constants.cpp b/core/core_constants.cpp index 7fc09fc3a6..0aad21276a 100644 --- a/core/core_constants.cpp +++ b/core/core_constants.cpp @@ -106,10 +106,6 @@ static Vector<_CoreConstant> _global_constants; VARIANT_ENUM_CAST(Key); VARIANT_ENUM_CAST(KeyModifierMask); -VARIANT_ENUM_CAST(MouseButton); -VARIANT_ENUM_CAST(JoyButton); -VARIANT_ENUM_CAST(JoyAxis); -VARIANT_ENUM_CAST(MIDIMessage); void register_global_constants() { BIND_CORE_ENUM_CONSTANT(SIDE_LEFT); @@ -512,7 +508,6 @@ void register_global_constants() { BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_NONE); BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_RANGE); - BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_EXP_RANGE); BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_ENUM); BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_EXP_EASING); BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_LENGTH); diff --git a/core/crypto/crypto.h b/core/crypto/crypto.h index a2ccbba58a..a46f42949d 100644 --- a/core/crypto/crypto.h +++ b/core/crypto/crypto.h @@ -82,6 +82,7 @@ public: virtual PackedByteArray finish() = 0; HMACContext() {} + virtual ~HMACContext() {} }; class Crypto : public RefCounted { diff --git a/core/debugger/remote_debugger_peer.cpp b/core/debugger/remote_debugger_peer.cpp index 39113eda14..ea5e32203c 100644 --- a/core/debugger/remote_debugger_peer.cpp +++ b/core/debugger/remote_debugger_peer.cpp @@ -84,7 +84,7 @@ RemoteDebuggerPeerTCP::RemoteDebuggerPeerTCP(Ref<StreamPeerTCP> p_tcp) { thread.start(_thread_func, this); #endif } else { - tcp_client.instance(); + tcp_client.instantiate(); } } diff --git a/core/extension/SCsub b/core/extension/SCsub new file mode 100644 index 0000000000..a3a54250c1 --- /dev/null +++ b/core/extension/SCsub @@ -0,0 +1,7 @@ +#!/usr/bin/env python + +Import("env") + +env_extension = env.Clone() + +env_extension.add_source_files(env.core_sources, "*.cpp") diff --git a/core/extension/extension_api_dump.cpp b/core/extension/extension_api_dump.cpp new file mode 100644 index 0000000000..3c132a619d --- /dev/null +++ b/core/extension/extension_api_dump.cpp @@ -0,0 +1,805 @@ +/*************************************************************************/ +/* extension_api_dump.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "extension_api_dump.h" +#include "core/config/engine.h" +#include "core/core_constants.h" +#include "core/io/file_access.h" +#include "core/io/json.h" +#include "core/templates/pair.h" +#include "core/version.h" + +#ifdef TOOLS_ENABLED + +Dictionary NativeExtensionAPIDump::generate_extension_api() { + Dictionary api_dump; + + { + //header + Dictionary header; + header["version_major"] = VERSION_MAJOR; + header["version_minor"] = VERSION_MINOR; +#if VERSION_PATCH + header["version_patch"] = VERSION_PATCH; +#else + header["version_patch"] = 0; +#endif + header["version_status"] = VERSION_STATUS; + header["version_build"] = VERSION_BUILD; + header["version_full_name"] = VERSION_FULL_NAME; + + api_dump["header"] = header; + } + + const uint32_t vec3_elems = 3; + const uint32_t ptrsize_32 = 4; + const uint32_t ptrsize_64 = 4; + static const char *build_config_name[4] = { "float_32", "float_64", "double_32", "double_64" }; + + { + //type sizes + struct { + Variant::Type type; + uint32_t size_32_bits_real_float; + uint32_t size_64_bits_real_float; + uint32_t size_32_bits_real_double; + uint32_t size_64_bits_real_double; + } type_size_array[Variant::VARIANT_MAX + 1] = { + { Variant::NIL, 0, 0, 0, 0 }, + { Variant::BOOL, sizeof(uint32_t), sizeof(uint32_t), sizeof(uint32_t), sizeof(uint32_t) }, + { Variant::INT, sizeof(int64_t), sizeof(int64_t), sizeof(int64_t), sizeof(int64_t) }, + { Variant::FLOAT, sizeof(double), sizeof(double), sizeof(double), sizeof(double) }, + { Variant::STRING, ptrsize_32, ptrsize_64, ptrsize_32, ptrsize_64 }, + { Variant::VECTOR2, 2 * sizeof(float), 2 * sizeof(float), 2 * sizeof(double), 2 * sizeof(double) }, + { Variant::VECTOR2I, 2 * sizeof(int32_t), 2 * sizeof(int32_t), 2 * sizeof(int32_t), 2 * sizeof(int32_t) }, + { Variant::RECT2, 4 * sizeof(float), 4 * sizeof(float), 4 * sizeof(double), 4 * sizeof(double) }, + { Variant::RECT2I, 4 * sizeof(int32_t), 4 * sizeof(int32_t), 4 * sizeof(int32_t), 4 * sizeof(int32_t) }, + { Variant::VECTOR3, vec3_elems * sizeof(float), vec3_elems * sizeof(float), vec3_elems * sizeof(double), vec3_elems * sizeof(double) }, + { Variant::VECTOR3I, 3 * sizeof(int32_t), 3 * sizeof(int32_t), 3 * sizeof(int32_t), 3 * sizeof(int32_t) }, + { Variant::TRANSFORM2D, 6 * sizeof(float), 6 * sizeof(float), 6 * sizeof(double), 6 * sizeof(double) }, + { Variant::PLANE, (vec3_elems + 1) * sizeof(float), (vec3_elems + 1) * sizeof(float), (vec3_elems + 1) * sizeof(double), (vec3_elems + 1) * sizeof(double) }, + { Variant::QUATERNION, 4 * sizeof(float), 4 * sizeof(float), 4 * sizeof(double), 4 * sizeof(double) }, + { Variant::AABB, (vec3_elems * 2) * sizeof(float), (vec3_elems * 2) * sizeof(float), (vec3_elems * 2) * sizeof(double), (vec3_elems * 2) * sizeof(double) }, + { Variant::BASIS, (vec3_elems * 3) * sizeof(float), (vec3_elems * 3) * sizeof(float), (vec3_elems * 3) * sizeof(double), (vec3_elems * 3) * sizeof(double) }, + { Variant::TRANSFORM3D, (vec3_elems * 4) * sizeof(float), (vec3_elems * 4) * sizeof(float), (vec3_elems * 4) * sizeof(double), (vec3_elems * 4) * sizeof(double) }, + { Variant::COLOR, 4 * sizeof(float), 4 * sizeof(float), 4 * sizeof(float), 4 * sizeof(float) }, + { Variant::STRING_NAME, ptrsize_32, ptrsize_64, ptrsize_32, ptrsize_64 }, + { Variant::NODE_PATH, ptrsize_32, ptrsize_64, ptrsize_32, ptrsize_64 }, + { Variant::RID, sizeof(uint64_t), sizeof(uint64_t), sizeof(uint64_t), sizeof(uint64_t) }, + { Variant::OBJECT, ptrsize_32, ptrsize_64, ptrsize_32, ptrsize_64 }, + { Variant::CALLABLE, sizeof(Callable), sizeof(Callable), sizeof(Callable), sizeof(Callable) }, //harcoded align + { Variant::SIGNAL, sizeof(Signal), sizeof(Signal), sizeof(Signal), sizeof(Signal) }, //harcoded align + { Variant::DICTIONARY, ptrsize_32, ptrsize_64, ptrsize_32, ptrsize_64 }, + { Variant::ARRAY, ptrsize_32, ptrsize_64, ptrsize_32, ptrsize_64 }, + { Variant::PACKED_BYTE_ARRAY, ptrsize_32, ptrsize_64, ptrsize_32, ptrsize_64 }, + { Variant::PACKED_INT32_ARRAY, ptrsize_32, ptrsize_64, ptrsize_32, ptrsize_64 }, + { Variant::PACKED_INT64_ARRAY, ptrsize_32, ptrsize_64, ptrsize_32, ptrsize_64 }, + { Variant::PACKED_FLOAT32_ARRAY, ptrsize_32, ptrsize_64, ptrsize_32, ptrsize_64 }, + { Variant::PACKED_FLOAT64_ARRAY, ptrsize_32, ptrsize_64, ptrsize_32, ptrsize_64 }, + { Variant::PACKED_STRING_ARRAY, ptrsize_32, ptrsize_64, ptrsize_32, ptrsize_64 }, + { Variant::PACKED_VECTOR2_ARRAY, ptrsize_32, ptrsize_64, ptrsize_32, ptrsize_64 }, + { Variant::PACKED_VECTOR3_ARRAY, ptrsize_32, ptrsize_64, ptrsize_32, ptrsize_64 }, + { Variant::PACKED_COLOR_ARRAY, ptrsize_32, ptrsize_64, ptrsize_32, ptrsize_64 }, + { Variant::VARIANT_MAX, sizeof(uint64_t) + sizeof(float) * 4, sizeof(uint64_t) + sizeof(float) * 4, sizeof(uint64_t) + sizeof(double) * 4, sizeof(uint64_t) + sizeof(double) * 4 }, + }; + + Array core_type_sizes; + + for (int i = 0; i < 4; i++) { + Dictionary d; + d["build_configuration"] = build_config_name[i]; + Array sizes; + for (int j = 0; j < Variant::VARIANT_MAX; j++) { + Variant::Type t = type_size_array[j].type; + String name = t == Variant::VARIANT_MAX ? String("Variant") : Variant::get_type_name(t); + Dictionary d2; + d2["name"] = name; + uint32_t size; + switch (i) { + case 0: + size = type_size_array[j].size_32_bits_real_float; + break; + case 1: + size = type_size_array[j].size_64_bits_real_float; + break; + case 2: + size = type_size_array[j].size_32_bits_real_double; + break; + case 3: + size = type_size_array[j].size_64_bits_real_double; + break; + } + d2["size"] = size; + sizes.push_back(d2); + } + d["sizes"] = sizes; + core_type_sizes.push_back(d); + } + api_dump["builtin_class_sizes"] = core_type_sizes; + } + + { + //member offsets sizes + struct { + Variant::Type type; + const char *member; + uint32_t offset_32_bits_real_float; + uint32_t offset_64_bits_real_float; + uint32_t offset_32_bits_real_double; + uint32_t offset_64_bits_real_double; + } member_offset_array[] = { + { Variant::VECTOR2, "x", 0, 0, 0, 0 }, + { Variant::VECTOR2, "y", sizeof(float), sizeof(float), sizeof(double), sizeof(double) }, + { Variant::VECTOR2I, "x", 0, 0, 0, 0 }, + { Variant::VECTOR2I, "y", sizeof(int32_t), sizeof(int32_t), sizeof(int32_t), sizeof(int32_t) }, + { Variant::RECT2, "position", 0, 0, 0, 0 }, + { Variant::RECT2, "size", 2 * sizeof(Vector2), 2 * sizeof(float), 2 * sizeof(double), 2 * sizeof(double) }, + { Variant::RECT2I, "position", 0, 0, 0, 0 }, + { Variant::RECT2I, "size", 2 * sizeof(int32_t), 2 * sizeof(int32_t), 2 * sizeof(int32_t), 2 * sizeof(int32_t) }, + { Variant::VECTOR3, "x", 0, 0, 0, 0 }, + { Variant::VECTOR3, "y", sizeof(float), sizeof(float), sizeof(double), sizeof(double) }, + { Variant::VECTOR3, "z", 2 * sizeof(float), 2 * sizeof(float), 2 * sizeof(double), 2 * sizeof(double) }, + { Variant::VECTOR3I, "x", 0, 0, 0, 0 }, + { Variant::VECTOR3I, "y", sizeof(int32_t), sizeof(int32_t), sizeof(int32_t), sizeof(int32_t) }, + { Variant::VECTOR3I, "z", 2 * sizeof(int32_t), 2 * sizeof(int32_t), 2 * sizeof(int32_t), 2 * sizeof(int32_t) }, + { Variant::TRANSFORM2D, "x", 0, 0, 0, 0 }, + { Variant::TRANSFORM2D, "y", 2 * sizeof(float), 2 * sizeof(float), 2 * sizeof(double), 2 * sizeof(double) }, + { Variant::TRANSFORM2D, "origin", 4 * sizeof(float), 4 * sizeof(float), 4 * sizeof(double), 4 * sizeof(double) }, + { Variant::PLANE, "normal", 0, 0, 0, 0 }, + { Variant::PLANE, "d", vec3_elems * sizeof(float), vec3_elems * sizeof(float), vec3_elems * sizeof(double), vec3_elems * sizeof(double) }, + { Variant::QUATERNION, "x", 0, 0, 0, 0 }, + { Variant::QUATERNION, "y", sizeof(float), sizeof(float), sizeof(double), sizeof(double) }, + { Variant::QUATERNION, "z", 2 * sizeof(float), 2 * sizeof(float), 2 * sizeof(double), 2 * sizeof(double) }, + { Variant::QUATERNION, "w", 3 * sizeof(float), 3 * sizeof(float), 3 * sizeof(double), 3 * sizeof(double) }, + { Variant::AABB, "position", 0, 0, 0, 0 }, + { Variant::AABB, "size", vec3_elems * sizeof(float), vec3_elems * sizeof(float), vec3_elems * sizeof(double), vec3_elems * sizeof(double) }, + //rememer that basis vectors are flipped! + { Variant::BASIS, "x", 0, 0, 0, 0 }, + { Variant::BASIS, "y", vec3_elems * sizeof(float), vec3_elems * sizeof(float), vec3_elems * sizeof(double), vec3_elems * sizeof(double) }, + { Variant::BASIS, "z", vec3_elems * 2 * sizeof(float), vec3_elems * 2 * sizeof(float), vec3_elems * 2 * sizeof(double), vec3_elems * 2 * sizeof(double) }, + { Variant::TRANSFORM3D, "basis", 0, 0, 0, 0 }, + { Variant::TRANSFORM3D, "origin", (vec3_elems * 3) * sizeof(float), (vec3_elems * 3) * sizeof(float), (vec3_elems * 3) * sizeof(double), (vec3_elems * 3) * sizeof(double) }, + { Variant::COLOR, "x", 0, 0, 0, 0 }, + { Variant::COLOR, "y", sizeof(float), sizeof(float), sizeof(float), sizeof(float) }, + { Variant::COLOR, "z", 2 * sizeof(float), 2 * sizeof(float), 2 * sizeof(float), 2 * sizeof(float) }, + { Variant::COLOR, "w", 3 * sizeof(float), 3 * sizeof(float), 3 * sizeof(float), 3 * sizeof(float) }, + { Variant::NIL, nullptr, 0, 0, 0, 0 }, + }; + + Array core_type_member_offsets; + + for (int i = 0; i < 4; i++) { + Dictionary d; + d["build_configuration"] = build_config_name[i]; + Array type_offsets; + uint32_t idx = 0; + + Variant::Type last_type = Variant::NIL; + + Dictionary d2; + Array members; + + while (true) { + Variant::Type t = member_offset_array[idx].type; + if (t != last_type) { + if (last_type != Variant::NIL) { + d2["members"] = members; + type_offsets.push_back(d2); + } + if (t == Variant::NIL) { + break; + } + + String name = t == Variant::VARIANT_MAX ? String("Variant") : Variant::get_type_name(t); + d2 = Dictionary(); + members = Array(); + d2["name"] = name; + last_type = t; + } + Dictionary d3; + uint32_t offset; + switch (i) { + case 0: + offset = member_offset_array[idx].offset_32_bits_real_float; + break; + case 1: + offset = member_offset_array[idx].offset_64_bits_real_float; + break; + case 2: + offset = member_offset_array[idx].offset_32_bits_real_double; + break; + case 3: + offset = member_offset_array[idx].offset_64_bits_real_double; + break; + } + d3["member"] = member_offset_array[idx].member; + d3["offset"] = offset; + members.push_back(d3); + idx++; + } + d["classes"] = type_offsets; + core_type_member_offsets.push_back(d); + } + api_dump["builtin_class_member_offsets"] = core_type_member_offsets; + } + + { + // global enums and constants + Array constants; + Map<String, List<Pair<String, int>>> enum_list; + + for (int i = 0; i < CoreConstants::get_global_constant_count(); i++) { + int value = CoreConstants::get_global_constant_value(i); + String enum_name = CoreConstants::get_global_constant_enum(i); + String name = CoreConstants::get_global_constant_name(i); + if (enum_name != String()) { + enum_list[enum_name].push_back(Pair<String, int>(name, value)); + } else { + Dictionary d; + d["name"] = name; + d["value"] = value; + constants.push_back(d); + } + } + + api_dump["global_constants"] = constants; + + Array enums; + for (Map<String, List<Pair<String, int>>>::Element *E = enum_list.front(); E; E = E->next()) { + Dictionary d1; + d1["name"] = E->key(); + Array values; + for (List<Pair<String, int>>::Element *F = E->get().front(); F; F = F->next()) { + Dictionary d2; + d2["name"] = F->get().first; + d2["value"] = F->get().second; + values.push_back(d2); + } + d1["values"] = values; + enums.push_back(d1); + } + + api_dump["global_enums"] = enums; + } + { + Array utility_funcs; + + List<StringName> utility_func_names; + Variant::get_utility_function_list(&utility_func_names); + + for (List<StringName>::Element *E = utility_func_names.front(); E; E = E->next()) { + StringName name = E->get(); + Dictionary func; + func["name"] = String(name); + if (Variant::has_utility_function_return_value(name)) { + Variant::Type rt = Variant::get_utility_function_return_type(name); + func["return_type"] = rt == Variant::NIL ? String("Variant") : Variant::get_type_name(rt); + } + switch (Variant::get_utility_function_type(name)) { + case Variant::UTILITY_FUNC_TYPE_MATH: + func["category"] = "math"; + break; + case Variant::UTILITY_FUNC_TYPE_RANDOM: + func["category"] = "random"; + break; + case Variant::UTILITY_FUNC_TYPE_GENERAL: + func["category"] = "general"; + break; + } + bool vararg = Variant::is_utility_function_vararg(name); + func["is_vararg"] = Variant::is_utility_function_vararg(name); + func["hash"] = Variant::get_utility_function_hash(name); + Array arguments; + int argcount = Variant::get_utility_function_argument_count(name); + for (int i = 0; i < argcount; i++) { + Dictionary arg; + String argname = vararg ? "arg" + itos(i + 1) : Variant::get_utility_function_argument_name(name, i); + arg["name"] = argname; + Variant::Type argtype = Variant::get_utility_function_argument_type(name, i); + arg["type"] = argtype == Variant::NIL ? String("Variant") : Variant::get_type_name(argtype); + //no default value support in utility functions + arguments.push_back(arg); + } + + if (arguments.size()) { + func["arguments"] = arguments; + } + + utility_funcs.push_back(func); + } + + api_dump["utility_functions"] = utility_funcs; + } + + { + // builtin types + + Array builtins; + + for (int i = 0; i < Variant::VARIANT_MAX; i++) { + if (i == Variant::OBJECT) { + continue; + } + + Variant::Type type = Variant::Type(i); + + Dictionary d; + d["name"] = Variant::get_type_name(type); + if (Variant::has_indexing(type)) { + Variant::Type index_type = Variant::get_indexed_element_type(type); + d["indexing_return_type"] = index_type == Variant::NIL ? String("Variant") : Variant::get_type_name(index_type); + } + + { + //members + Array members; + + List<StringName> member_names; + Variant::get_member_list(type, &member_names); + for (List<StringName>::Element *E = member_names.front(); E; E = E->next()) { + StringName member_name = E->get(); + Dictionary d2; + d2["name"] = String(member_name); + d2["type"] = Variant::get_type_name(Variant::get_member_type(type, member_name)); + members.push_back(d2); + } + if (members.size()) { + d["members"] = members; + } + } + { + //constants + Array constants; + + List<StringName> constant_names; + Variant::get_constants_for_type(type, &constant_names); + for (List<StringName>::Element *E = constant_names.front(); E; E = E->next()) { + StringName constant_name = E->get(); + Dictionary d2; + d2["name"] = String(constant_name); + Variant constant = Variant::get_constant_value(type, constant_name); + d2["type"] = Variant::get_type_name(constant.get_type()); + d2["value"] = constant.get_construct_string(); + constants.push_back(d2); + } + if (constants.size()) { + d["constants"] = constants; + } + } + { + //operators + Array operators; + + for (int j = 0; j < Variant::VARIANT_MAX; j++) { + for (int k = 0; k < Variant::OP_MAX; k++) { + Variant::Type rt = Variant::get_operator_return_type(Variant::Operator(k), type, Variant::Type(j)); + if (rt != Variant::NIL) { + Dictionary d2; + d2["name"] = Variant::get_operator_name(Variant::Operator(k)); + if (k != Variant::OP_NEGATE && k != Variant::OP_POSITIVE && k != Variant::OP_NOT && k != Variant::OP_BIT_NEGATE) { + d2["right_type"] = Variant::get_type_name(Variant::Type(j)); + } + operators.push_back(d2); + } + } + } + if (operators.size()) { + d["operators"] = operators; + } + } + { + //methods + Array methods; + + List<StringName> method_names; + Variant::get_builtin_method_list(type, &method_names); + for (List<StringName>::Element *E = method_names.front(); E; E = E->next()) { + StringName method_name = E->get(); + Dictionary d2; + d2["name"] = String(method_name); + if (Variant::has_builtin_method_return_value(type, method_name)) { + Variant::Type ret_type = Variant::get_builtin_method_return_type(type, method_name); + d2["return_type"] = ret_type == Variant::NIL ? String("Variant") : Variant::get_type_name(ret_type); + } + d2["is_vararg"] = Variant::is_builtin_method_vararg(type, method_name); + d2["is_const"] = Variant::is_builtin_method_const(type, method_name); + d2["is_static"] = Variant::is_builtin_method_static(type, method_name); + d2["hash"] = Variant::get_builtin_method_hash(type, method_name); + + Vector<Variant> default_args = Variant::get_builtin_method_default_arguments(type, method_name); + + Array arguments; + int argcount = Variant::get_builtin_method_argument_count(type, method_name); + for (int j = 0; j < argcount; j++) { + Dictionary d3; + d3["name"] = Variant::get_builtin_method_argument_name(type, method_name, j); + Variant::Type argtype = Variant::get_builtin_method_argument_type(type, method_name, j); + d3["type"] = argtype == Variant::NIL ? String("Variant") : Variant::get_type_name(argtype); + + if (j >= (argcount - default_args.size())) { + int dargidx = j - (argcount - default_args.size()); + d3["default_value"] = default_args[dargidx].get_construct_string(); + } + arguments.push_back(d3); + } + + if (arguments.size()) { + d2["arguments"] = arguments; + } + + methods.push_back(d2); + } + if (methods.size()) { + d["methods"] = methods; + } + } + { + //constructors + Array constructors; + + for (int j = 0; j < Variant::get_constructor_count(type); j++) { + Dictionary d2; + d2["index"] = j; + + Array arguments; + int argcount = Variant::get_constructor_argument_count(type, j); + for (int k = 0; k < argcount; k++) { + Dictionary d3; + d3["name"] = Variant::get_constructor_argument_name(type, j, k); + d3["type"] = Variant::get_type_name(Variant::get_constructor_argument_type(type, j, k)); + arguments.push_back(d3); + } + if (arguments.size()) { + d2["arguments"] = arguments; + } + constructors.push_back(d2); + } + + if (constructors.size()) { + d["constructors"] = constructors; + } + } + + builtins.push_back(d); + } + + api_dump["builtin_classes"] = builtins; + } + + { + // classes + Array classes; + + List<StringName> class_list; + + ClassDB::get_class_list(&class_list); + + class_list.sort_custom<StringName::AlphCompare>(); + + for (List<StringName>::Element *E = class_list.front(); E; E = E->next()) { + Dictionary d; + StringName class_name = E->get(); + d["name"] = String(class_name); + d["is_refcounted"] = ClassDB::is_parent_class(class_name, "RefCounted"); + d["is_instantiable"] = ClassDB::can_instantiate(class_name); + StringName parent_class = ClassDB::get_parent_class(class_name); + if (parent_class != StringName()) { + d["inherits"] = String(parent_class); + } + + { + ClassDB::APIType api = ClassDB::get_api_type(class_name); + static const char *api_type[5] = { "core", "editor", "extension", "editor_extension" }; + d["api_type"] = api_type[api]; + } + + { + //constants + Array constants; + List<String> constant_list; + ClassDB::get_integer_constant_list(class_name, &constant_list, true); + for (List<String>::Element *F = constant_list.front(); F; F = F->next()) { + StringName enum_name = ClassDB::get_integer_constant_enum(class_name, F->get()); + if (enum_name != StringName()) { + continue; //enums will be handled on their own + } + + Dictionary d2; + d2["name"] = String(F->get()); + d2["value"] = ClassDB::get_integer_constant(class_name, F->get()); + + constants.push_back(d2); + } + + if (constants.size()) { + d["constants"] = constants; + } + } + { + //enum + Array enums; + List<StringName> enum_list; + ClassDB::get_enum_list(class_name, &enum_list, true); + for (List<StringName>::Element *F = enum_list.front(); F; F = F->next()) { + Dictionary d2; + d2["name"] = String(F->get()); + + Array values; + List<StringName> enum_constant_list; + ClassDB::get_enum_constants(class_name, F->get(), &enum_constant_list, true); + for (List<StringName>::Element *G = enum_constant_list.front(); G; G = G->next()) { + Dictionary d3; + d3["name"] = String(G->get()); + d3["value"] = ClassDB::get_integer_constant(class_name, G->get()); + values.push_back(d3); + } + + d2["values"] = values; + + enums.push_back(d2); + } + + if (enums.size()) { + d["enums"] = enums; + } + } + { + //methods + Array methods; + List<MethodInfo> method_list; + ClassDB::get_method_list(class_name, &method_list, true); + for (List<MethodInfo>::Element *F = method_list.front(); F; F = F->next()) { + StringName method_name = F->get().name; + if (F->get().flags & METHOD_FLAG_VIRTUAL) { + //virtual method + const MethodInfo &mi = F->get(); + Dictionary d2; + d2["name"] = String(method_name); + d2["is_const"] = (F->get().flags & METHOD_FLAG_CONST) ? true : false; + d2["is_vararg"] = false; + d2["is_virtual"] = true; + // virtual functions have no hash since no MethodBind is involved + bool has_return = mi.return_val.type != Variant::NIL || (mi.return_val.usage & PROPERTY_USAGE_NIL_IS_VARIANT); + Array arguments; + for (int i = (has_return ? -1 : 0); i < mi.arguments.size(); i++) { + PropertyInfo pinfo = i == -1 ? mi.return_val : mi.arguments[i]; + Dictionary d3; + + if (i >= 0) { + d3["name"] = pinfo.name; + } + if (pinfo.class_name != StringName()) { + d3["type"] = String(pinfo.class_name); + } else { + Variant::Type type = pinfo.type; + if (type == Variant::NIL) { + d3["type"] = "Variant"; + } else { + d3["type"] = Variant::get_type_name(type); + } + } + + if (i == -1) { + d2["return_value"] = d3; + } else { + arguments.push_back(d3); + } + } + + if (arguments.size()) { + d2["arguments"] = arguments; + } + + methods.push_back(d2); + + } else if (F->get().name.begins_with("_")) { + //hidden method, ignore + + } else { + Dictionary d2; + d2["name"] = String(method_name); + + MethodBind *method = ClassDB::get_method(class_name, method_name); + if (!method) { + continue; + } + + d2["is_const"] = method->is_const(); + d2["is_vararg"] = method->is_vararg(); + d2["is_virtual"] = false; + d2["hash"] = method->get_hash(); + + Vector<Variant> default_args = method->get_default_arguments(); + + Array arguments; + for (int i = (method->has_return() ? -1 : 0); i < method->get_argument_count(); i++) { + PropertyInfo pinfo = i == -1 ? method->get_return_info() : method->get_argument_info(i); + Dictionary d3; + + if (i >= 0) { + d3["name"] = pinfo.name; + } + if (pinfo.class_name != StringName()) { + d3["type"] = String(pinfo.class_name); + } else { + Variant::Type type = pinfo.type; + if (type == Variant::NIL) { + d3["type"] = "Variant"; + } else { + d3["type"] = Variant::get_type_name(type); + } + } + + if (method->get_argument_meta(i) > 0) { + static const char *argmeta[11] = { "none", "int8", "int16", "int32", "int64", "uint8", "uint16", "uint32", "uint64", "float", "double" }; + d3["meta"] = argmeta[method->get_argument_meta(i)]; + } + + if (i >= 0 && i >= (method->get_argument_count() - default_args.size())) { + int dargidx = i - (method->get_argument_count() - default_args.size()); + d3["default_value"] = default_args[dargidx].get_construct_string(); + } + + if (i == -1) { + d2["return_value"] = d3; + } else { + arguments.push_back(d3); + } + } + + if (arguments.size()) { + d2["arguments"] = arguments; + } + + methods.push_back(d2); + } + } + + if (methods.size()) { + d["methods"] = methods; + } + } + + { + //signals + Array signals; + List<MethodInfo> signal_list; + ClassDB::get_signal_list(class_name, &signal_list, true); + for (List<MethodInfo>::Element *F = signal_list.front(); F; F = F->next()) { + StringName signal_name = F->get().name; + Dictionary d2; + d2["name"] = String(signal_name); + + Array arguments; + + for (int i = 0; i < F->get().arguments.size(); i++) { + Dictionary d3; + d3["name"] = F->get().arguments[i].name; + Variant::Type type = F->get().arguments[i].type; + if (F->get().arguments[i].class_name != StringName()) { + d3["type"] = String(F->get().arguments[i].class_name); + } else if (type == Variant::NIL) { + d3["type"] = "Variant"; + } else { + d3["type"] = Variant::get_type_name(type); + } + arguments.push_back(d3); + } + if (arguments.size()) { + d2["arguments"] = arguments; + } + + signals.push_back(d2); + } + + if (signals.size()) { + d["signals"] = signals; + } + } + { + //properties + Array properties; + List<PropertyInfo> property_list; + ClassDB::get_property_list(class_name, &property_list, true); + for (List<PropertyInfo>::Element *F = property_list.front(); F; F = F->next()) { + if (F->get().usage & PROPERTY_USAGE_CATEGORY || F->get().usage & PROPERTY_USAGE_GROUP || F->get().usage & PROPERTY_USAGE_SUBGROUP) { + continue; //not real properties + } + if (F->get().name.begins_with("_")) { + continue; //hidden property + } + StringName property_name = F->get().name; + Dictionary d2; + d2["name"] = String(property_name); + + if (F->get().class_name != StringName()) { + d2["type"] = String(F->get().class_name); + } else if (F->get().type == Variant::NIL && F->get().usage & PROPERTY_USAGE_NIL_IS_VARIANT) { + d2["type"] = "Variant"; + } else { + d2["type"] = Variant::get_type_name(F->get().type); + } + + d2["setter"] = ClassDB::get_property_setter(class_name, F->get().name); + d2["getter"] = ClassDB::get_property_getter(class_name, F->get().name); + d2["index"] = ClassDB::get_property_index(class_name, F->get().name); + properties.push_back(d2); + } + + if (properties.size()) { + d["properties"] = properties; + } + } + + classes.push_back(d); + } + + api_dump["classes"] = classes; + } + + { + // singletons + + Array singletons; + List<Engine::Singleton> singleton_list; + Engine::get_singleton()->get_singletons(&singleton_list); + + for (List<Engine::Singleton>::Element *E = singleton_list.front(); E; E = E->next()) { + const Engine::Singleton &s = E->get(); + Dictionary d; + d["name"] = s.name; + if (s.class_name != StringName()) { + d["type"] = String(s.class_name); + } else { + d["type"] = String(s.ptr->get_class()); + } + singletons.push_back(d); + } + + if (singletons.size()) { + api_dump["singletons"] = singletons; + } + } + + return api_dump; +} + +void NativeExtensionAPIDump::generate_extension_json_file(const String &p_path) { + Dictionary api = generate_extension_api(); + Ref<JSON> json; + json.instantiate(); + + String text = json->stringify(api, "\t", false); + FileAccessRef fa = FileAccess::open(p_path, FileAccess::WRITE); + CharString cs = text.ascii(); + fa->store_buffer((const uint8_t *)cs.ptr(), cs.length()); + fa->close(); +} +#endif diff --git a/platform/javascript/http_client.h.inc b/core/extension/extension_api_dump.h index 6544d41c98..a7825c10a9 100644 --- a/platform/javascript/http_client.h.inc +++ b/core/extension/extension_api_dump.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* http_client.h.inc */ +/* extension_api_dump.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,24 +28,18 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -// HTTPClient's additional private members in the javascript platform +#ifndef API_DUMP_H +#define API_DUMP_H -Error make_request(Method p_method, const String &p_url, const Vector<String> &p_headers, const uint8_t *p_body, int p_body_len); -static void _parse_headers(int p_len, const char **p_headers, void *p_ref); +#include "core/extension/native_extension.h" -int js_id = 0; -// 64 KiB by default (favors fast download speeds at the cost of memory usage). -int read_limit = 65536; -Status status = STATUS_DISCONNECTED; +#ifdef TOOLS_ENABLED -String host; -int port = -1; -bool use_tls = false; - -int polled_response_code = 0; -Vector<String> response_headers; -Vector<uint8_t> response_buffer; - -#ifdef DEBUG_ENABLED -uint64_t last_polling_frame = 0; +class NativeExtensionAPIDump { +public: + static Dictionary generate_extension_api(); + static void generate_extension_json_file(const String &p_path); +}; #endif + +#endif // API_DUMP_H diff --git a/core/extension/gdnative_interface.cpp b/core/extension/gdnative_interface.cpp new file mode 100644 index 0000000000..8f68b8d848 --- /dev/null +++ b/core/extension/gdnative_interface.cpp @@ -0,0 +1,694 @@ +/*************************************************************************/ +/* gdnative_interface.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "gdnative_interface.h" + +#include "core/config/engine.h" +#include "core/object/class_db.h" +#include "core/os/memory.h" +#include "core/variant/variant.h" +#include "core/version.h" + +// Memory Functions +static void *gdnative_alloc(size_t p_size) { + return memalloc(p_size); +} + +static void *gdnative_realloc(void *p_mem, size_t p_size) { + return memrealloc(p_mem, p_size); +} + +static void gdnative_free(void *p_mem) { + memfree(p_mem); +} + +// Helper print functions. +static void gdnative_print_error(const char *p_description, const char *p_function, const char *p_file, int32_t p_line) { + _err_print_error(p_function, p_file, p_line, p_description, ERR_HANDLER_ERROR); +} +static void gdnative_print_warning(const char *p_description, const char *p_function, const char *p_file, int32_t p_line) { + _err_print_error(p_function, p_file, p_line, p_description, ERR_HANDLER_WARNING); +} +static void gdnative_print_script_error(const char *p_description, const char *p_function, const char *p_file, int32_t p_line) { + _err_print_error(p_function, p_file, p_line, p_description, ERR_HANDLER_SCRIPT); +} + +// Variant functions + +static void gdnative_variant_new_copy(GDNativeVariantPtr r_dest, const GDNativeVariantPtr p_src) { + memnew_placement(reinterpret_cast<Variant *>(r_dest), Variant(*reinterpret_cast<Variant *>(p_src))); +} +static void gdnative_variant_new_nil(GDNativeVariantPtr r_dest) { + memnew_placement(reinterpret_cast<Variant *>(r_dest), Variant); +} +static void gdnative_variant_destroy(GDNativeVariantPtr p_self) { + reinterpret_cast<Variant *>(p_self)->~Variant(); +} + +// variant type + +#define memnew_placement_custom(m_placement, m_class, m_constr) _post_initialize(new (m_placement, sizeof(m_class), "") m_constr) + +static void gdnative_variant_call(GDNativeVariantPtr p_self, const GDNativeStringNamePtr p_method, const GDNativeVariantPtr *p_args, const GDNativeInt p_argcount, GDNativeVariantPtr r_return, GDNativeCallError *r_error) { + Variant *self = (Variant *)p_self; + const StringName *method = (const StringName *)p_method; + const Variant **args = (const Variant **)p_args; + Variant ret; + Callable::CallError error; + self->call(*method, args, p_argcount, ret, error); + memnew_placement_custom(r_return, Variant, Variant(ret)); + + if (r_error) { + r_error->error = (GDNativeCallErrorType)(error.error); + r_error->argument = error.argument; + r_error->expected = error.expected; + } +} + +static void gdnative_variant_call_static(GDNativeVariantType p_type, const GDNativeStringNamePtr p_method, const GDNativeVariantPtr *p_args, const GDNativeInt p_argcount, GDNativeVariantPtr r_return, GDNativeCallError *r_error) { + Variant::Type type = (Variant::Type)p_type; + const StringName *method = (const StringName *)p_method; + const Variant **args = (const Variant **)p_args; + Variant ret; + Callable::CallError error; + Variant::call_static(type, *method, args, p_argcount, ret, error); + memnew_placement_custom(r_return, Variant, Variant(ret)); + + if (r_error) { + r_error->error = (GDNativeCallErrorType)error.error; + r_error->argument = error.argument; + r_error->expected = error.expected; + } +} + +static void gdnative_variant_evaluate(GDNativeVariantOperator p_op, const GDNativeVariantPtr p_a, const GDNativeVariantPtr p_b, GDNativeVariantPtr r_return, GDNativeBool *r_valid) { + Variant::Operator op = (Variant::Operator)p_op; + const Variant *a = (const Variant *)p_a; + const Variant *b = (const Variant *)p_b; + Variant *ret = (Variant *)r_return; + bool valid; + Variant::evaluate(op, *a, *b, *ret, valid); + *r_valid = valid; +} + +static void gdnative_variant_set(GDNativeVariantPtr p_self, const GDNativeVariantPtr p_key, const GDNativeVariantPtr p_value, GDNativeBool *r_valid) { + Variant *self = (Variant *)p_self; + const Variant *key = (const Variant *)p_key; + const Variant *value = (const Variant *)p_value; + + bool valid; + self->set(*key, *value, &valid); + *r_valid = valid; +} + +static void gdnative_variant_set_named(GDNativeVariantPtr p_self, const GDNativeStringNamePtr p_key, const GDNativeVariantPtr p_value, GDNativeBool *r_valid) { + Variant *self = (Variant *)p_self; + const StringName *key = (const StringName *)p_key; + const Variant *value = (const Variant *)p_value; + + bool valid; + self->set_named(*key, *value, valid); + *r_valid = valid; +} + +static void gdnative_variant_set_keyed(GDNativeVariantPtr p_self, const GDNativeVariantPtr p_key, const GDNativeVariantPtr p_value, GDNativeBool *r_valid) { + Variant *self = (Variant *)p_self; + const Variant *key = (const Variant *)p_key; + const Variant *value = (const Variant *)p_value; + + bool valid; + self->set_keyed(*key, *value, valid); + *r_valid = valid; +} + +static void gdnative_variant_set_indexed(GDNativeVariantPtr p_self, GDNativeInt p_index, const GDNativeVariantPtr p_value, GDNativeBool *r_valid, GDNativeBool *r_oob) { + Variant *self = (Variant *)p_self; + const Variant *value = (const Variant *)p_value; + + bool valid; + bool oob; + self->set_indexed(p_index, value, valid, oob); + *r_valid = valid; + *r_oob = oob; +} + +static void gdnative_variant_get(const GDNativeVariantPtr p_self, const GDNativeVariantPtr p_key, GDNativeVariantPtr r_ret, GDNativeBool *r_valid) { + const Variant *self = (const Variant *)p_self; + const Variant *key = (const Variant *)p_key; + + bool valid; + memnew_placement_custom(r_ret, Variant, Variant(self->get(*key, &valid))); + *r_valid = valid; +} + +static void gdnative_variant_get_named(const GDNativeVariantPtr p_self, const GDNativeStringNamePtr p_key, GDNativeVariantPtr r_ret, GDNativeBool *r_valid) { + const Variant *self = (const Variant *)p_self; + const StringName *key = (const StringName *)p_key; + + bool valid; + memnew_placement_custom(r_ret, Variant, Variant(self->get_named(*key, valid))); + *r_valid = valid; +} + +static void gdnative_variant_get_keyed(const GDNativeVariantPtr p_self, const GDNativeVariantPtr p_key, GDNativeVariantPtr r_ret, GDNativeBool *r_valid) { + const Variant *self = (const Variant *)p_self; + const Variant *key = (const Variant *)p_key; + + bool valid; + memnew_placement_custom(r_ret, Variant, Variant(self->get_keyed(*key, valid))); + *r_valid = valid; +} + +static void gdnative_variant_get_indexed(const GDNativeVariantPtr p_self, GDNativeInt p_index, GDNativeVariantPtr r_ret, GDNativeBool *r_valid, GDNativeBool *r_oob) { + const Variant *self = (const Variant *)p_self; + + bool valid; + bool oob; + memnew_placement_custom(r_ret, Variant, Variant(self->get_indexed(p_index, valid, oob))); + *r_valid = valid; + *r_oob = oob; +} + +/// Iteration. +static GDNativeBool gdnative_variant_iter_init(const GDNativeVariantPtr p_self, GDNativeVariantPtr r_iter, GDNativeBool *r_valid) { + const Variant *self = (const Variant *)p_self; + Variant *iter = (Variant *)r_iter; + + bool valid; + bool ret = self->iter_init(*iter, valid); + *r_valid = valid; + return ret; +} + +static GDNativeBool gdnative_variant_iter_next(const GDNativeVariantPtr p_self, GDNativeVariantPtr r_iter, GDNativeBool *r_valid) { + const Variant *self = (const Variant *)p_self; + Variant *iter = (Variant *)r_iter; + + bool valid; + bool ret = self->iter_next(*iter, valid); + *r_valid = valid; + return ret; +} + +static void gdnative_variant_iter_get(const GDNativeVariantPtr p_self, GDNativeVariantPtr r_iter, GDNativeVariantPtr r_ret, GDNativeBool *r_valid) { + const Variant *self = (const Variant *)p_self; + Variant *iter = (Variant *)r_iter; + + bool valid; + memnew_placement_custom(r_ret, Variant, Variant(self->iter_next(*iter, valid))); + *r_valid = valid; +} + +/// Variant functions. +static GDNativeBool gdnative_variant_hash_compare(const GDNativeVariantPtr p_self, const GDNativeVariantPtr p_other) { + const Variant *self = (const Variant *)p_self; + const Variant *other = (const Variant *)p_other; + return self->hash_compare(*other); +} + +static GDNativeBool gdnative_variant_booleanize(const GDNativeVariantPtr p_self) { + const Variant *self = (const Variant *)p_self; + return self->booleanize(); +} + +static void gdnative_variant_blend(const GDNativeVariantPtr p_a, const GDNativeVariantPtr p_b, float p_c, GDNativeVariantPtr r_dst) { + const Variant *a = (const Variant *)p_a; + const Variant *b = (const Variant *)p_b; + memnew_placement(r_dst, Variant); + Variant::blend(*a, *b, p_c, *(Variant *)r_dst); +} + +static void gdnative_variant_interpolate(const GDNativeVariantPtr p_a, const GDNativeVariantPtr p_b, float p_c, GDNativeVariantPtr r_dst) { + const Variant *a = (const Variant *)p_a; + const Variant *b = (const Variant *)p_b; + memnew_placement(r_dst, Variant); + Variant::interpolate(*a, *b, p_c, *(Variant *)r_dst); +} + +static void gdnative_variant_duplicate(const GDNativeVariantPtr p_self, GDNativeVariantPtr r_ret, GDNativeBool p_deep) { + const Variant *self = (const Variant *)p_self; + memnew_placement_custom(r_ret, Variant, Variant(self->duplicate(p_deep))); +} + +static void gdnative_variant_stringify(const GDNativeVariantPtr p_self, GDNativeStringPtr r_ret) { + const Variant *self = (const Variant *)p_self; + memnew_placement_custom(r_ret, String, String(*self)); +} + +static GDNativeVariantType gdnative_variant_get_type(const GDNativeVariantPtr p_self) { + const Variant *self = (const Variant *)p_self; + return (GDNativeVariantType)self->get_type(); +} + +static GDNativeBool gdnative_variant_has_method(const GDNativeVariantPtr p_self, const GDNativeStringNamePtr p_method) { + const Variant *self = (const Variant *)p_self; + const StringName *method = (const StringName *)p_method; + return self->has_method(*method); +} + +static GDNativeBool gdnative_variant_has_member(GDNativeVariantType p_type, const GDNativeStringNamePtr p_member) { + return Variant::has_member((Variant::Type)p_type, *((const StringName *)p_member)); +} + +static GDNativeBool gdnative_variant_has_key(const GDNativeVariantPtr p_self, const GDNativeVariantPtr p_key, GDNativeBool *r_valid) { + const Variant *self = (const Variant *)p_self; + const Variant *key = (const Variant *)p_key; + bool valid; + return self->has_key(*key, valid); + *r_valid = valid; +} + +static void gdnative_variant_get_type_name(GDNativeVariantType p_type, GDNativeStringPtr r_ret) { + String name = Variant::get_type_name((Variant::Type)p_type); + memnew_placement_custom(r_ret, String, String(name)); +} + +static GDNativeBool gdnative_variant_can_convert(GDNativeVariantType p_from, GDNativeVariantType p_to) { + return Variant::can_convert((Variant::Type)p_from, (Variant::Type)p_to); +} + +static GDNativeBool gdnative_variant_can_convert_strict(GDNativeVariantType p_from, GDNativeVariantType p_to) { + return Variant::can_convert_strict((Variant::Type)p_from, (Variant::Type)p_to); +} + +// ptrcalls +static GDNativePtrOperatorEvaluator gdnative_variant_get_ptr_operator_evaluator(GDNativeVariantOperator p_operator, GDNativeVariantType p_type_a, GDNativeVariantType p_type_b) { + return (GDNativePtrOperatorEvaluator)Variant::get_ptr_operator_evaluator(Variant::Operator(p_operator), Variant::Type(p_type_a), Variant::Type(p_type_b)); +} +static GDNativePtrBuiltInMethod gdnative_variant_get_ptr_builtin_method(GDNativeVariantType p_type, const char *p_method, GDNativeInt p_hash) { + StringName method = p_method; + uint32_t hash = Variant::get_builtin_method_hash(Variant::Type(p_type), method); + if (hash != p_hash) { + ERR_PRINT_ONCE("Error getting method " + String(method) + ", hash mismatch."); + return nullptr; + } + + return (GDNativePtrBuiltInMethod)Variant::get_ptr_builtin_method(Variant::Type(p_type), method); +} +static GDNativePtrConstructor gdnative_variant_get_ptr_constructor(GDNativeVariantType p_type, int32_t p_constructor) { + return (GDNativePtrConstructor)Variant::get_ptr_constructor(Variant::Type(p_type), p_constructor); +} +static void gdnative_variant_construct(GDNativeVariantType p_type, GDNativeVariantPtr p_base, const GDNativeVariantPtr *p_args, int32_t p_argument_count, GDNativeCallError *r_error) { + memnew_placement(p_base, Variant); + + Callable::CallError error; + Variant::construct(Variant::Type(p_type), *(Variant *)p_base, (const Variant **)p_args, p_argument_count, error); + + if (r_error) { + r_error->error = (GDNativeCallErrorType)(error.error); + r_error->argument = error.argument; + r_error->expected = error.expected; + } +} +static GDNativePtrSetter gdnative_variant_get_ptr_setter(GDNativeVariantType p_type, const char *p_member) { + return (GDNativePtrSetter)Variant::get_member_ptr_setter(Variant::Type(p_type), p_member); +} +static GDNativePtrGetter gdnative_variant_get_ptr_getter(GDNativeVariantType p_type, const char *p_member) { + return (GDNativePtrGetter)Variant::get_member_ptr_getter(Variant::Type(p_type), p_member); +} +static GDNativePtrIndexedSetter gdnative_variant_get_ptr_indexed_setter(GDNativeVariantType p_type) { + return (GDNativePtrIndexedSetter)Variant::get_member_ptr_indexed_setter(Variant::Type(p_type)); +} +static GDNativePtrIndexedGetter gdnative_variant_get_ptr_indexed_getter(GDNativeVariantType p_type) { + return (GDNativePtrIndexedGetter)Variant::get_member_ptr_indexed_getter(Variant::Type(p_type)); +} +static GDNativePtrKeyedSetter gdnative_variant_get_ptr_keyed_setter(GDNativeVariantType p_type) { + return (GDNativePtrKeyedSetter)Variant::get_member_ptr_keyed_setter(Variant::Type(p_type)); +} +static GDNativePtrKeyedGetter gdnative_variant_get_ptr_keyed_getter(GDNativeVariantType p_type) { + return (GDNativePtrKeyedGetter)Variant::get_member_ptr_keyed_getter(Variant::Type(p_type)); +} +static GDNativePtrKeyedChecker gdnative_variant_get_ptr_keyed_checker(GDNativeVariantType p_type) { + return (GDNativePtrKeyedChecker)Variant::get_member_ptr_keyed_checker(Variant::Type(p_type)); +} +static void gdnative_variant_get_constant_value(GDNativeVariantType p_type, const char *p_constant, GDNativeVariantPtr r_ret) { + memnew_placement_custom(r_ret, Variant, Variant(Variant::get_constant_value(Variant::Type(p_type), p_constant))); +} +static GDNativePtrUtilityFunction gdnative_variant_get_ptr_utility_function(const char *p_function, GDNativeInt p_hash) { + StringName function = p_function; + uint32_t hash = Variant::get_utility_function_hash(function); + if (hash != p_hash) { + ERR_PRINT_ONCE("Error getting utility function " + String(function) + ", hash mismatch."); + return nullptr; + } + return (GDNativePtrUtilityFunction)Variant::get_ptr_utility_function(function); +} + +//string helpers + +static void gdnative_string_new_with_latin1_chars(GDNativeStringPtr r_dest, const char *p_contents) { + String *dest = (String *)r_dest; + memnew_placement(dest, String); + *dest = String(p_contents); +} + +static void gdnative_string_new_with_utf8_chars(GDNativeStringPtr r_dest, const char *p_contents) { + String *dest = (String *)r_dest; + memnew_placement(dest, String); + dest->parse_utf8(p_contents); +} + +static void gdnative_string_new_with_utf16_chars(GDNativeStringPtr r_dest, const char16_t *p_contents) { + String *dest = (String *)r_dest; + memnew_placement(dest, String); + dest->parse_utf16(p_contents); +} + +static void gdnative_string_new_with_utf32_chars(GDNativeStringPtr r_dest, const char32_t *p_contents) { + String *dest = (String *)r_dest; + memnew_placement(dest, String); + *dest = String((const char32_t *)p_contents); +} + +static void gdnative_string_new_with_wide_chars(GDNativeStringPtr r_dest, const wchar_t *p_contents) { + String *dest = (String *)r_dest; + if (sizeof(wchar_t) == 2) { + // wchar_t is 16 bit, parse. + memnew_placement(dest, String); + dest->parse_utf16((const char16_t *)p_contents); + } else { + // wchar_t is 32 bit, copy. + memnew_placement(dest, String); + *dest = String((const char32_t *)p_contents); + } +} + +static void gdnative_string_new_with_latin1_chars_and_len(GDNativeStringPtr r_dest, const char *p_contents, const GDNativeInt p_size) { + String *dest = (String *)r_dest; + memnew_placement(dest, String); + *dest = String(p_contents, p_size); +} + +static void gdnative_string_new_with_utf8_chars_and_len(GDNativeStringPtr r_dest, const char *p_contents, const GDNativeInt p_size) { + String *dest = (String *)r_dest; + memnew_placement(dest, String); + dest->parse_utf8(p_contents, p_size); +} + +static void gdnative_string_new_with_utf16_chars_and_len(GDNativeStringPtr r_dest, const char16_t *p_contents, const GDNativeInt p_size) { + String *dest = (String *)r_dest; + memnew_placement(dest, String); + dest->parse_utf16(p_contents, p_size); +} + +static void gdnative_string_new_with_utf32_chars_and_len(GDNativeStringPtr r_dest, const char32_t *p_contents, const GDNativeInt p_size) { + String *dest = (String *)r_dest; + memnew_placement(dest, String); + *dest = String((const char32_t *)p_contents, p_size); +} + +static void gdnative_string_new_with_wide_chars_and_len(GDNativeStringPtr r_dest, const wchar_t *p_contents, const GDNativeInt p_size) { + String *dest = (String *)r_dest; + if (sizeof(wchar_t) == 2) { + // wchar_t is 16 bit, parse. + memnew_placement(dest, String); + dest->parse_utf16((const char16_t *)p_contents, p_size); + } else { + // wchar_t is 32 bit, copy. + memnew_placement(dest, String); + *dest = String((const char32_t *)p_contents, p_size); + } +} + +static GDNativeInt gdnative_string_to_latin1_chars(const GDNativeStringPtr p_self, char *r_text, GDNativeInt p_max_write_length) { + String *self = (String *)p_self; + CharString cs = self->ascii(true); + GDNativeInt len = cs.length(); + if (r_text) { + const char *s_text = cs.ptr(); + for (GDNativeInt i = 0; i < MIN(len, p_max_write_length); i++) { + r_text[i] = s_text[i]; + } + } + return len; +} +static GDNativeInt gdnative_string_to_utf8_chars(const GDNativeStringPtr p_self, char *r_text, GDNativeInt p_max_write_length) { + String *self = (String *)p_self; + CharString cs = self->utf8(); + GDNativeInt len = cs.length(); + if (r_text) { + const char *s_text = cs.ptr(); + for (GDNativeInt i = 0; i < MIN(len, p_max_write_length); i++) { + r_text[i] = s_text[i]; + } + } + return len; +} +static GDNativeInt gdnative_string_to_utf16_chars(const GDNativeStringPtr p_self, char16_t *r_text, GDNativeInt p_max_write_length) { + String *self = (String *)p_self; + Char16String cs = self->utf16(); + GDNativeInt len = cs.length(); + if (r_text) { + const char16_t *s_text = cs.ptr(); + for (GDNativeInt i = 0; i < MIN(len, p_max_write_length); i++) { + r_text[i] = s_text[i]; + } + } + return len; +} +static GDNativeInt gdnative_string_to_utf32_chars(const GDNativeStringPtr p_self, char32_t *r_text, GDNativeInt p_max_write_length) { + String *self = (String *)p_self; + GDNativeInt len = self->length(); + if (r_text) { + const char32_t *s_text = self->ptr(); + for (GDNativeInt i = 0; i < MIN(len, p_max_write_length); i++) { + r_text[i] = s_text[i]; + } + } + return len; +} +static GDNativeInt gdnative_string_to_wide_chars(const GDNativeStringPtr p_self, wchar_t *r_text, GDNativeInt p_max_write_length) { + if (sizeof(wchar_t) == 4) { + return gdnative_string_to_utf32_chars(p_self, (char32_t *)r_text, p_max_write_length); + } else { + return gdnative_string_to_utf16_chars(p_self, (char16_t *)r_text, p_max_write_length); + } +} + +static char32_t *gdnative_string_operator_index(GDNativeStringPtr p_self, GDNativeInt p_index) { + String *self = (String *)p_self; + ERR_FAIL_INDEX_V(p_index, self->length() + 1, nullptr); + return &self->ptrw()[p_index]; +} + +static const char32_t *gdnative_string_operator_index_const(const GDNativeStringPtr p_self, GDNativeInt p_index) { + const String *self = (const String *)p_self; + ERR_FAIL_INDEX_V(p_index, self->length() + 1, nullptr); + return &self->ptr()[p_index]; +} + +/* OBJECT API */ + +static void gdnative_object_method_bind_ptrcall(GDNativeMethodBindPtr p_method_bind, GDNativeObjectPtr p_instance, const GDNativeTypePtr *p_args, GDNativeTypePtr p_ret) { + MethodBind *mb = (MethodBind *)p_method_bind; + Object *o = (Object *)p_instance; + mb->ptrcall(o, (const void **)p_args, p_ret); +} + +static void gdnative_object_destroy(GDNativeObjectPtr p_o) { + memdelete((Object *)p_o); +} + +static GDNativeObjectPtr gdnative_global_get_singleton(const char *p_name) { + return (GDNativeObjectPtr)Engine::get_singleton()->get_singleton_object(String(p_name)); +} + +static void *gdnative_object_get_instance_binding(GDNativeObjectPtr p_instance, void *p_token, GDNativeInstanceBindingCallbacks *p_callbacks) { + Object *o = (Object *)p_instance; + return o->get_instance_binding(p_token, p_callbacks); +} + +static GDNativeObjectPtr gdnative_object_get_instance_from_id(GDObjectInstanceID p_instance_id) { + return (GDNativeObjectPtr)ObjectDB::get_instance(ObjectID(p_instance_id)); +} + +static GDNativeObjectPtr gdnative_object_cast_to(const GDNativeObjectPtr p_object, void *p_class_tag) { + if (!p_object) { + return nullptr; + } + Object *o = (Object *)p_object; + + return o->is_class_ptr(p_class_tag) ? (GDNativeObjectPtr)o : (GDNativeObjectPtr) nullptr; +} + +static GDObjectInstanceID gdnative_object_get_instance_id(const GDNativeObjectPtr p_object) { + const Object *o = (const Object *)p_object; + return (GDObjectInstanceID)o->get_instance_id(); +} + +static GDNativeMethodBindPtr gdnative_classdb_get_method_bind(const char *p_classname, const char *p_methodname, GDNativeInt p_hash) { + MethodBind *mb = ClassDB::get_method(StringName(p_classname), StringName(p_methodname)); + ERR_FAIL_COND_V(!mb, nullptr); + if (mb->get_hash() != p_hash) { + ERR_PRINT_ONCE("Hash mismatch for method '" + String(p_classname) + "." + String(p_methodname) + "'."); + return nullptr; + } + // MethodBind *mb = ClassDB::get_method("Node", "get_name"); + return (GDNativeMethodBindPtr)mb; +} + +static GDNativeClassConstructor gdnative_classdb_get_constructor(const char *p_classname) { + ClassDB::ClassInfo *class_info = ClassDB::classes.getptr(StringName(p_classname)); + if (class_info) { + return (GDNativeClassConstructor)class_info->creation_func; + } + return nullptr; +} + +static void *gdnative_classdb_get_class_tag(const char *p_classname) { + ClassDB::ClassInfo *class_info = ClassDB::classes.getptr(p_classname); + return class_info ? class_info->class_ptr : nullptr; +} + +void gdnative_setup_interface(GDNativeInterface *p_interface) { + GDNativeInterface &gdni = *p_interface; + + gdni.version_major = VERSION_MAJOR; + gdni.version_minor = VERSION_MINOR; +#if VERSION_PATCH + gdni.version_patch = VERSION_PATCH; +#else + gdni.version_patch = 0; +#endif + gdni.version_string = VERSION_FULL_NAME; + + /* GODOT CORE */ + + gdni.mem_alloc = gdnative_alloc; + gdni.mem_realloc = gdnative_realloc; + gdni.mem_free = gdnative_free; + + gdni.print_error = gdnative_print_error; + gdni.print_warning = gdnative_print_warning; + gdni.print_script_error = gdnative_print_script_error; + + /* GODOT VARIANT */ + + // variant general + gdni.variant_new_copy = gdnative_variant_new_copy; + gdni.variant_new_nil = gdnative_variant_new_nil; + gdni.variant_destroy = gdnative_variant_destroy; + + gdni.variant_call = gdnative_variant_call; + gdni.variant_call_static = gdnative_variant_call_static; + gdni.variant_evaluate = gdnative_variant_evaluate; + gdni.variant_set = gdnative_variant_set; + gdni.variant_set_named = gdnative_variant_set_named; + gdni.variant_set_keyed = gdnative_variant_set_keyed; + gdni.variant_set_indexed = gdnative_variant_set_indexed; + gdni.variant_get = gdnative_variant_get; + gdni.variant_get_named = gdnative_variant_get_named; + gdni.variant_get_keyed = gdnative_variant_get_keyed; + gdni.variant_get_indexed = gdnative_variant_get_indexed; + gdni.variant_iter_init = gdnative_variant_iter_init; + gdni.variant_iter_next = gdnative_variant_iter_next; + gdni.variant_iter_get = gdnative_variant_iter_get; + gdni.variant_hash_compare = gdnative_variant_hash_compare; + gdni.variant_booleanize = gdnative_variant_booleanize; + gdni.variant_blend = gdnative_variant_blend; + gdni.variant_interpolate = gdnative_variant_interpolate; + gdni.variant_duplicate = gdnative_variant_duplicate; + gdni.variant_stringify = gdnative_variant_stringify; + + gdni.variant_get_type = gdnative_variant_get_type; + gdni.variant_has_method = gdnative_variant_has_method; + gdni.variant_has_member = gdnative_variant_has_member; + gdni.variant_has_key = gdnative_variant_has_key; + gdni.variant_get_type_name = gdnative_variant_get_type_name; + gdni.variant_can_convert = gdnative_variant_can_convert; + gdni.variant_can_convert_strict = gdnative_variant_can_convert_strict; + + //ptrcalls +#if 0 + GDNativeVariantFromTypeConstructorFunc (*get_variant_from_type_constructor)(GDNativeVariantType p_type); + GDNativeTypeFromVariantConstructorFunc (*get_variant_to_type_constructor)(GDNativeVariantType p_type); +#endif + + gdni.variant_get_ptr_operator_evaluator = gdnative_variant_get_ptr_operator_evaluator; + gdni.variant_get_ptr_builtin_method = gdnative_variant_get_ptr_builtin_method; + gdni.variant_get_ptr_constructor = gdnative_variant_get_ptr_constructor; + gdni.variant_construct = gdnative_variant_construct; + gdni.variant_get_ptr_setter = gdnative_variant_get_ptr_setter; + gdni.variant_get_ptr_getter = gdnative_variant_get_ptr_getter; + gdni.variant_get_ptr_indexed_setter = gdnative_variant_get_ptr_indexed_setter; + gdni.variant_get_ptr_indexed_getter = gdnative_variant_get_ptr_indexed_getter; + gdni.variant_get_ptr_keyed_setter = gdnative_variant_get_ptr_keyed_setter; + gdni.variant_get_ptr_keyed_getter = gdnative_variant_get_ptr_keyed_getter; + gdni.variant_get_ptr_keyed_checker = gdnative_variant_get_ptr_keyed_checker; + gdni.variant_get_constant_value = gdnative_variant_get_constant_value; + gdni.variant_get_ptr_utility_function = gdnative_variant_get_ptr_utility_function; + + // extra utilities + + gdni.string_new_with_latin1_chars = gdnative_string_new_with_latin1_chars; + gdni.string_new_with_utf8_chars = gdnative_string_new_with_utf8_chars; + gdni.string_new_with_utf16_chars = gdnative_string_new_with_utf16_chars; + gdni.string_new_with_utf32_chars = gdnative_string_new_with_utf32_chars; + gdni.string_new_with_wide_chars = gdnative_string_new_with_wide_chars; + gdni.string_new_with_latin1_chars_and_len = gdnative_string_new_with_latin1_chars_and_len; + gdni.string_new_with_utf8_chars_and_len = gdnative_string_new_with_utf8_chars_and_len; + gdni.string_new_with_utf16_chars_and_len = gdnative_string_new_with_utf16_chars_and_len; + gdni.string_new_with_utf32_chars_and_len = gdnative_string_new_with_utf32_chars_and_len; + gdni.string_new_with_wide_chars_and_len = gdnative_string_new_with_wide_chars_and_len; + gdni.string_to_latin1_chars = gdnative_string_to_latin1_chars; + gdni.string_to_utf8_chars = gdnative_string_to_utf8_chars; + gdni.string_to_utf16_chars = gdnative_string_to_utf16_chars; + gdni.string_to_utf32_chars = gdnative_string_to_utf32_chars; + gdni.string_to_wide_chars = gdnative_string_to_wide_chars; + gdni.string_operator_index = gdnative_string_operator_index; + gdni.string_operator_index_const = gdnative_string_operator_index_const; + + /* OBJECT */ + + gdni.object_method_bind_ptrcall = gdnative_object_method_bind_ptrcall; + gdni.object_destroy = gdnative_object_destroy; + gdni.global_get_singleton = gdnative_global_get_singleton; + gdni.object_get_instance_binding = gdnative_object_get_instance_binding; + + gdni.object_cast_to = gdnative_object_cast_to; + gdni.object_get_instance_from_id = gdnative_object_get_instance_from_id; + gdni.object_get_instance_id = gdnative_object_get_instance_id; + + /* CLASSDB */ + + gdni.classdb_get_constructor = gdnative_classdb_get_constructor; + gdni.classdb_get_method_bind = gdnative_classdb_get_method_bind; + gdni.classdb_get_class_tag = gdnative_classdb_get_class_tag; + + /* CLASSDB EXTENSION */ + + //these are filled by implementation, since it will want to keep track of registered classes + gdni.classdb_register_extension_class = nullptr; + gdni.classdb_register_extension_class_method = nullptr; + gdni.classdb_register_extension_class_integer_constant = nullptr; + gdni.classdb_register_extension_class_property = nullptr; + gdni.classdb_register_extension_class_signal = nullptr; + gdni.classdb_unregister_extension_class = nullptr; +} diff --git a/core/extension/gdnative_interface.h b/core/extension/gdnative_interface.h new file mode 100644 index 0000000000..c1ebb3e76a --- /dev/null +++ b/core/extension/gdnative_interface.h @@ -0,0 +1,438 @@ +/*************************************************************************/ +/* gdnative_interface.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef GDNATIVE_INTERFACE_H +#define GDNATIVE_INTERFACE_H + +/* This is a C class header, you can copy it and use it directly in your own binders. + * Together with the JSON file, you should be able to generate any binder. + */ + +#include <stddef.h> +#include <stdint.h> +#include <stdio.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* VARIANT TYPES */ + +typedef enum { + GDNATIVE_VARIANT_TYPE_NIL, + + /* atomic types */ + GDNATIVE_VARIANT_TYPE_BOOL, + GDNATIVE_VARIANT_TYPE_INT, + GDNATIVE_VARIANT_TYPE_FLOAT, + GDNATIVE_VARIANT_TYPE_STRING, + + /* math types */ + GDNATIVE_VARIANT_TYPE_VECTOR2, + GDNATIVE_VARIANT_TYPE_VECTOR2I, + GDNATIVE_VARIANT_TYPE_RECT2, + GDNATIVE_VARIANT_TYPE_RECT2I, + GDNATIVE_VARIANT_TYPE_VECTOR3, + GDNATIVE_VARIANT_TYPE_VECTOR3I, + GDNATIVE_VARIANT_TYPE_TRANSFORM2D, + GDNATIVE_VARIANT_TYPE_PLANE, + GDNATIVE_VARIANT_TYPE_QUATERNION, + GDNATIVE_VARIANT_TYPE_AABB, + GDNATIVE_VARIANT_TYPE_BASIS, + GDNATIVE_VARIANT_TYPE_TRANSFORM3D, + + /* misc types */ + GDNATIVE_VARIANT_TYPE_COLOR, + GDNATIVE_VARIANT_TYPE_STRING_NAME, + GDNATIVE_VARIANT_TYPE_NODE_PATH, + GDNATIVE_VARIANT_TYPE_RID, + GDNATIVE_VARIANT_TYPE_OBJECT, + GDNATIVE_VARIANT_TYPE_CALLABLE, + GDNATIVE_VARIANT_TYPE_SIGNAL, + GDNATIVE_VARIANT_TYPE_DICTIONARY, + GDNATIVE_VARIANT_TYPE_ARRAY, + + /* typed arrays */ + GDNATIVE_VARIANT_TYPE_PACKED_BYTE_ARRAY, + GDNATIVE_VARIANT_TYPE_PACKED_INT32_ARRAY, + GDNATIVE_VARIANT_TYPE_PACKED_INT64_ARRAY, + GDNATIVE_VARIANT_TYPE_PACKED_FLOAT32_ARRAY, + GDNATIVE_VARIANT_TYPE_PACKED_FLOAT64_ARRAY, + GDNATIVE_VARIANT_TYPE_PACKED_STRING_ARRAY, + GDNATIVE_VARIANT_TYPE_PACKED_VECTOR2_ARRAY, + GDNATIVE_VARIANT_TYPE_PACKED_VECTOR3_ARRAY, + GDNATIVE_VARIANT_TYPE_PACKED_COLOR_ARRAY, + + GDNATIVE_VARIANT_TYPE_VARIANT_MAX +} GDNativeVariantType; + +typedef enum { + /* comparison */ + GDNATIVE_VARIANT_OP_EQUAL, + GDNATIVE_VARIANT_OP_NOT_EQUAL, + GDNATIVE_VARIANT_OP_LESS, + GDNATIVE_VARIANT_OP_LESS_EQUAL, + GDNATIVE_VARIANT_OP_GREATER, + GDNATIVE_VARIANT_OP_GREATER_EQUAL, + /* mathematic */ + GDNATIVE_VARIANT_OP_ADD, + GDNATIVE_VARIANT_OP_SUBTRACT, + GDNATIVE_VARIANT_OP_MULTIPLY, + GDNATIVE_VARIANT_OP_DIVIDE, + GDNATIVE_VARIANT_OP_NEGATE, + GDNATIVE_VARIANT_OP_POSITIVE, + GDNATIVE_VARIANT_OP_MODULE, + /* bitwise */ + GDNATIVE_VARIANT_OP_SHIFT_LEFT, + GDNATIVE_VARIANT_OP_SHIFT_RIGHT, + GDNATIVE_VARIANT_OP_BIT_AND, + GDNATIVE_VARIANT_OP_BIT_OR, + GDNATIVE_VARIANT_OP_BIT_XOR, + GDNATIVE_VARIANT_OP_BIT_NEGATE, + /* logic */ + GDNATIVE_VARIANT_OP_AND, + GDNATIVE_VARIANT_OP_OR, + GDNATIVE_VARIANT_OP_XOR, + GDNATIVE_VARIANT_OP_NOT, + /* containment */ + GDNATIVE_VARIANT_OP_IN, + GDNATIVE_VARIANT_OP_MAX + +} GDNativeVariantOperator; + +typedef void *GDNativeVariantPtr; +typedef void *GDNativeStringNamePtr; +typedef void *GDNativeStringPtr; +typedef void *GDNativeObjectPtr; +typedef void *GDNativeTypePtr; +typedef void *GDNativeMethodBindPtr; +typedef int64_t GDNativeInt; +typedef uint32_t GDNativeBool; +typedef uint64_t GDObjectInstanceID; + +/* VARIANT DATA I/O */ + +typedef enum { + NATIVE_CALL_OK, + NATIVE_CALL_ERROR_INVALID_METHOD, + NATIVE_CALL_ERROR_INVALID_ARGUMENT, /* expected is variant type */ + NATIVE_CALL_ERROR_TOO_MANY_ARGUMENTS, /* expected is number of arguments */ + NATIVE_CALL_ERROR_TOO_FEW_ARGUMENTS, /* expected is number of arguments */ + NATIVE_CALL_ERROR_INSTANCE_IS_NULL, + +} GDNativeCallErrorType; + +typedef struct { + GDNativeCallErrorType error; + int32_t argument; + int32_t expected; +} GDNativeCallError; + +typedef void (*GDNativeVariantFromTypeConstructorFunc)(GDNativeVariantPtr, GDNativeTypePtr); +typedef void (*GDNativeTypeFromVariantConstructorFunc)(GDNativeTypePtr, GDNativeVariantPtr); +typedef void (*GDNativePtrOperatorEvaluator)(const GDNativeTypePtr p_left, const GDNativeTypePtr p_right, GDNativeTypePtr r_result); +typedef void (*GDNativePtrBuiltInMethod)(GDNativeTypePtr p_base, const GDNativeTypePtr *p_args, GDNativeTypePtr r_return, int p_argument_count); +typedef void (*GDNativePtrConstructor)(GDNativeTypePtr p_base, const GDNativeTypePtr *p_args); +typedef void (*GDNativePtrSetter)(GDNativeTypePtr p_base, const GDNativeTypePtr p_value); +typedef void (*GDNativePtrGetter)(const GDNativeTypePtr p_base, GDNativeTypePtr r_value); +typedef void (*GDNativePtrIndexedSetter)(GDNativeTypePtr p_base, GDNativeInt p_index, const GDNativeTypePtr p_value); +typedef void (*GDNativePtrIndexedGetter)(const GDNativeTypePtr p_base, GDNativeInt p_index, GDNativeTypePtr r_value); +typedef void (*GDNativePtrKeyedSetter)(GDNativeTypePtr p_base, const GDNativeTypePtr p_key, const GDNativeTypePtr p_value); +typedef void (*GDNativePtrKeyedGetter)(const GDNativeTypePtr p_base, const GDNativeTypePtr p_key, GDNativeTypePtr r_value); +typedef uint32_t (*GDNativePtrKeyedChecker)(const GDNativeVariantPtr p_base, const GDNativeVariantPtr p_key); +typedef void (*GDNativePtrUtilityFunction)(GDNativeTypePtr r_return, const GDNativeTypePtr *p_arguments, int p_argument_count); + +typedef GDNativeObjectPtr (*GDNativeClassConstructor)(); + +typedef void *(*GDNativeInstanceBindingCreateCallback)(void *p_token, void *p_instance); +typedef void (*GDNativeInstanceBindingFreeCallback)(void *p_token, void *p_instance, void *p_binding); +typedef GDNativeBool (*GDNativeInstanceBindingReferenceCallback)(void *p_token, void *p_instance, GDNativeBool p_reference); + +struct GDNativeInstanceBindingCallbacks { + GDNativeInstanceBindingCreateCallback create_callback; + GDNativeInstanceBindingFreeCallback free_callback; + GDNativeInstanceBindingReferenceCallback reference_callback; +}; + +/* EXTENSION CLASSES */ + +typedef void *GDExtensionClassInstancePtr; + +typedef GDNativeBool (*GDNativeExtensionClassSet)(GDExtensionClassInstancePtr p_instance, const GDNativeStringNamePtr p_name, const GDNativeVariantPtr p_value); +typedef GDNativeBool (*GDNativeExtensionClassGet)(GDExtensionClassInstancePtr p_instance, const GDNativeStringNamePtr p_name, GDNativeVariantPtr r_ret); + +typedef struct { + uint32_t type; + const char *name; + const char *class_name; + uint32_t hint; + const char *hint_string; + uint32_t usage; +} GDNativePropertyInfo; + +typedef const GDNativePropertyInfo *(*GDNativeExtensionClassGetPropertyList)(GDExtensionClassInstancePtr p_instance, uint32_t *r_count); +typedef void (*GDNativeExtensionClassFreePropertyList)(GDExtensionClassInstancePtr p_instance, const GDNativePropertyInfo *p_list); +typedef void (*GDNativeExtensionClassNotification)(GDExtensionClassInstancePtr p_instance, int32_t p_what); +typedef const char *(*GDNativeExtensionClassToString)(GDExtensionClassInstancePtr p_instance); +typedef void (*GDNativeExtensionClassReference)(GDExtensionClassInstancePtr p_instance); +typedef void (*GDNativeExtensionClassUnreference)(GDExtensionClassInstancePtr p_instance); +typedef void (*GDNativeExtensionClassCallVirtual)(GDExtensionClassInstancePtr p_instance, const GDNativeTypePtr *p_args, GDNativeTypePtr r_ret); +typedef GDExtensionClassInstancePtr (*GDNativeExtensionClassCreateInstance)(void *p_userdata); +typedef void (*GDNativeExtensionClassFreeInstance)(void *p_userdata, GDExtensionClassInstancePtr p_instance); +typedef GDNativeExtensionClassCallVirtual (*GDNativeExtensionClassGetVirtual)(void *p_userdata, const char *p_name); + +typedef struct { + GDNativeExtensionClassSet set_func; + GDNativeExtensionClassGet get_func; + GDNativeExtensionClassGetPropertyList get_property_list_func; + GDNativeExtensionClassFreePropertyList free_property_list_func; + GDNativeExtensionClassNotification notification_func; + GDNativeExtensionClassToString to_string_func; + GDNativeExtensionClassReference reference_func; + GDNativeExtensionClassUnreference unreference_func; + GDNativeExtensionClassCreateInstance create_instance_func; /* this one is mandatory */ + GDNativeExtensionClassFreeInstance free_instance_func; /* this one is mandatory */ + GDNativeExtensionClassGetVirtual get_firtual_func; + void *class_userdata; +} GDNativeExtensionClassCreationInfo; + +typedef void *GDNativeExtensionClassLibraryPtr; + +typedef const GDNativePropertyInfo *(*GDNativeExtensionClassGetPropertyList)(GDExtensionClassInstancePtr p_instance, uint32_t *r_count); + +/* Method */ + +typedef enum { + GDNATIVE_EXTENSION_METHOD_FLAG_NORMAL = 1, + GDNATIVE_EXTENSION_METHOD_FLAG_EDITOR = 2, + GDNATIVE_EXTENSION_METHOD_FLAG_NOSCRIPT = 4, + GDNATIVE_EXTENSION_METHOD_FLAG_CONST = 8, + GDNATIVE_EXTENSION_METHOD_FLAG_REVERSE = 16, /* used for events */ + GDNATIVE_EXTENSION_METHOD_FLAG_VIRTUAL = 32, + GDNATIVE_EXTENSION_METHOD_FLAG_FROM_SCRIPT = 64, + GDNATIVE_EXTENSION_METHOD_FLAG_VARARG = 128, + GDNATIVE_EXTENSION_METHOD_FLAG_STATIC = 256, + GDNATIVE_EXTENSION_METHOD_FLAGS_DEFAULT = GDNATIVE_EXTENSION_METHOD_FLAG_NORMAL, +} GDNativeExtensionClassMethodFlags; + +typedef enum { + GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE, + GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_INT_IS_INT8, + GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_INT_IS_INT16, + GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_INT_IS_INT32, + GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_INT_IS_INT64, + GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_INT_IS_UINT8, + GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_INT_IS_UINT16, + GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_INT_IS_UINT32, + GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_INT_IS_UINT64, + GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_REAL_IS_FLOAT, + GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_REAL_IS_DOUBLE +} GDNativeExtensionClassMethodArgumentMetadata; + +typedef void (*GDNativeExtensionClassMethodCall)(GDExtensionClassInstancePtr p_instance, const GDNativeVariantPtr *p_args, const GDNativeInt p_argument_count, GDNativeVariantPtr r_return, GDNativeCallError *r_error); +typedef void (*GDNativeExtensionClassMethodPtrCall)(GDExtensionClassInstancePtr p_instance, const GDNativeTypePtr *p_args, GDNativeTypePtr r_ret); + +/* passing -1 as argument in the following functions refers to the return type */ +typedef GDNativeVariantType (*GDNativeExtensionClassMethodGetArgumentType)(void *p_method_userdata, int32_t p_argument); +typedef void (*GDNativeExtensionClassMethodGetArgumentInfo)(void *p_method_userdata, int32_t p_argument, GDNativePropertyInfo *r_info); +typedef GDNativeExtensionClassMethodArgumentMetadata (*GDNativeExtensionClassMethodGetArgumentMetadata)(void *p_method_userdata, int32_t p_argument); + +typedef struct { + const char *name; + void *method_userdata; + GDNativeExtensionClassMethodCall call_func; + GDNativeExtensionClassMethodPtrCall ptrcall_func; + uint32_t method_flags; /* GDNativeExtensionClassMethodFlags */ + uint32_t argument_count; + GDNativeBool has_return_value; + GDNativeExtensionClassMethodGetArgumentType get_argument_type_func; + GDNativeExtensionClassMethodGetArgumentInfo get_argument_info_func; /* name and hint information for the argument can be omitted in release builds. Class name should always be present if it applies. */ + GDNativeExtensionClassMethodGetArgumentMetadata get_argument_metadata_func; + uint32_t default_argument_count; + GDNativeVariantPtr *default_arguments; +} GDNativeExtensionClassMethodInfo; + +/* INTERFACE */ + +typedef struct { + uint32_t version_major; + uint32_t version_minor; + uint32_t version_patch; + const char *version_string; + + /* GODOT CORE */ + void *(*mem_alloc)(size_t p_bytes); + void *(*mem_realloc)(void *p_ptr, size_t p_bytes); + void (*mem_free)(void *p_ptr); + + void (*print_error)(const char *p_description, const char *p_function, const char *p_file, int32_t p_line); + void (*print_warning)(const char *p_description, const char *p_function, const char *p_file, int32_t p_line); + void (*print_script_error)(const char *p_description, const char *p_function, const char *p_file, int32_t p_line); + + /* GODOT VARIANT */ + + /* variant general */ + void (*variant_new_copy)(GDNativeVariantPtr r_dest, const GDNativeVariantPtr p_src); + void (*variant_new_nil)(GDNativeVariantPtr r_dest); + void (*variant_destroy)(GDNativeVariantPtr p_self); + + /* variant type */ + void (*variant_call)(GDNativeVariantPtr p_self, const GDNativeStringNamePtr p_method, const GDNativeVariantPtr *p_args, const GDNativeInt p_argument_count, GDNativeVariantPtr r_return, GDNativeCallError *r_error); + void (*variant_call_static)(GDNativeVariantType p_type, const GDNativeStringNamePtr p_method, const GDNativeVariantPtr *p_args, const GDNativeInt p_argument_count, GDNativeVariantPtr r_return, GDNativeCallError *r_error); + void (*variant_evaluate)(GDNativeVariantOperator p_op, const GDNativeVariantPtr p_a, const GDNativeVariantPtr p_b, GDNativeVariantPtr r_return, GDNativeBool *r_valid); + void (*variant_set)(GDNativeVariantPtr p_self, const GDNativeVariantPtr p_key, const GDNativeVariantPtr p_value, GDNativeBool *r_valid); + void (*variant_set_named)(GDNativeVariantPtr p_self, const GDNativeStringNamePtr p_key, const GDNativeVariantPtr p_value, GDNativeBool *r_valid); + void (*variant_set_keyed)(GDNativeVariantPtr p_self, const GDNativeVariantPtr p_key, const GDNativeVariantPtr p_value, GDNativeBool *r_valid); + void (*variant_set_indexed)(GDNativeVariantPtr p_self, GDNativeInt p_index, const GDNativeVariantPtr p_value, GDNativeBool *r_valid, GDNativeBool *r_oob); + void (*variant_get)(const GDNativeVariantPtr p_self, const GDNativeVariantPtr p_key, GDNativeVariantPtr r_ret, GDNativeBool *r_valid); + void (*variant_get_named)(const GDNativeVariantPtr p_self, const GDNativeStringNamePtr p_key, GDNativeVariantPtr r_ret, GDNativeBool *r_valid); + void (*variant_get_keyed)(const GDNativeVariantPtr p_self, const GDNativeVariantPtr p_key, GDNativeVariantPtr r_ret, GDNativeBool *r_valid); + void (*variant_get_indexed)(const GDNativeVariantPtr p_self, GDNativeInt p_index, GDNativeVariantPtr r_ret, GDNativeBool *r_valid, GDNativeBool *r_oob); + GDNativeBool (*variant_iter_init)(const GDNativeVariantPtr p_self, GDNativeVariantPtr r_iter, GDNativeBool *r_valid); + GDNativeBool (*variant_iter_next)(const GDNativeVariantPtr p_self, GDNativeVariantPtr r_iter, GDNativeBool *r_valid); + void (*variant_iter_get)(const GDNativeVariantPtr p_self, GDNativeVariantPtr r_iter, GDNativeVariantPtr r_ret, GDNativeBool *r_valid); + GDNativeBool (*variant_hash_compare)(const GDNativeVariantPtr p_self, const GDNativeVariantPtr p_other); + GDNativeBool (*variant_booleanize)(const GDNativeVariantPtr p_self); + void (*variant_blend)(const GDNativeVariantPtr p_a, const GDNativeVariantPtr p_b, float p_c, GDNativeVariantPtr r_dst); + void (*variant_interpolate)(const GDNativeVariantPtr p_a, const GDNativeVariantPtr p_b, float p_c, GDNativeVariantPtr r_dst); + void (*variant_duplicate)(const GDNativeVariantPtr p_self, GDNativeVariantPtr r_ret, GDNativeBool p_deep); + void (*variant_stringify)(const GDNativeVariantPtr p_self, GDNativeStringPtr r_ret); + + GDNativeVariantType (*variant_get_type)(const GDNativeVariantPtr p_self); + GDNativeBool (*variant_has_method)(const GDNativeVariantPtr p_self, const GDNativeStringNamePtr p_method); + GDNativeBool (*variant_has_member)(GDNativeVariantType p_type, const GDNativeStringNamePtr p_member); + GDNativeBool (*variant_has_key)(const GDNativeVariantPtr p_self, const GDNativeVariantPtr p_key, GDNativeBool *r_valid); + void (*variant_get_type_name)(GDNativeVariantType p_type, GDNativeStringPtr r_name); + GDNativeBool (*variant_can_convert)(GDNativeVariantType p_from, GDNativeVariantType p_to); + GDNativeBool (*variant_can_convert_strict)(GDNativeVariantType p_from, GDNativeVariantType p_to); + + /* ptrcalls */ + GDNativeVariantFromTypeConstructorFunc (*get_variant_from_type_constructor)(GDNativeVariantType p_type); + GDNativeTypeFromVariantConstructorFunc (*get_variant_to_type_constructor)(GDNativeVariantType p_type); + GDNativePtrOperatorEvaluator (*variant_get_ptr_operator_evaluator)(GDNativeVariantOperator p_operator, GDNativeVariantType p_type_a, GDNativeVariantType p_type_b); + GDNativePtrBuiltInMethod (*variant_get_ptr_builtin_method)(GDNativeVariantType p_type, const char *p_method, GDNativeInt p_hash); + GDNativePtrConstructor (*variant_get_ptr_constructor)(GDNativeVariantType p_type, int32_t p_constructor); + void (*variant_construct)(GDNativeVariantType p_type, GDNativeVariantPtr p_base, const GDNativeVariantPtr *p_args, int32_t p_argument_count, GDNativeCallError *r_error); + GDNativePtrSetter (*variant_get_ptr_setter)(GDNativeVariantType p_type, const char *p_member); + GDNativePtrGetter (*variant_get_ptr_getter)(GDNativeVariantType p_type, const char *p_member); + GDNativePtrIndexedSetter (*variant_get_ptr_indexed_setter)(GDNativeVariantType p_type); + GDNativePtrIndexedGetter (*variant_get_ptr_indexed_getter)(GDNativeVariantType p_type); + GDNativePtrKeyedSetter (*variant_get_ptr_keyed_setter)(GDNativeVariantType p_type); + GDNativePtrKeyedGetter (*variant_get_ptr_keyed_getter)(GDNativeVariantType p_type); + GDNativePtrKeyedChecker (*variant_get_ptr_keyed_checker)(GDNativeVariantType p_type); + void (*variant_get_constant_value)(GDNativeVariantType p_type, const char *p_constant, GDNativeVariantPtr r_ret); + GDNativePtrUtilityFunction (*variant_get_ptr_utility_function)(const char *p_function, GDNativeInt p_hash); + + /* extra utilities */ + + void (*string_new_with_latin1_chars)(GDNativeStringPtr r_dest, const char *p_contents); + void (*string_new_with_utf8_chars)(GDNativeStringPtr r_dest, const char *p_contents); + void (*string_new_with_utf16_chars)(GDNativeStringPtr r_dest, const char16_t *p_contents); + void (*string_new_with_utf32_chars)(GDNativeStringPtr r_dest, const char32_t *p_contents); + void (*string_new_with_wide_chars)(GDNativeStringPtr r_dest, const wchar_t *p_contents); + void (*string_new_with_latin1_chars_and_len)(GDNativeStringPtr r_dest, const char *p_contents, const GDNativeInt p_size); + void (*string_new_with_utf8_chars_and_len)(GDNativeStringPtr r_dest, const char *p_contents, const GDNativeInt p_size); + void (*string_new_with_utf16_chars_and_len)(GDNativeStringPtr r_dest, const char16_t *p_contents, const GDNativeInt p_size); + void (*string_new_with_utf32_chars_and_len)(GDNativeStringPtr r_dest, const char32_t *p_contents, const GDNativeInt p_size); + void (*string_new_with_wide_chars_and_len)(GDNativeStringPtr r_dest, const wchar_t *p_contents, const GDNativeInt p_size); + /* Information about the following functions: + * - The return value is the resulting encoded string length. + * - The length returned is in characters, not in bytes. It also does not include a trailing zero. + * - These functions also do not write trailing zero, If you need it, write it yourself at the position indicated by the length (and make sure to allocate it). + * - Passing NULL in r_text means only the length is computed (again, without including trailing zero). + * - p_max_write_length argument is in characters, not bytes. It will be ignored if r_text is NULL. + * - p_max_write_length argument does not affect the return value, it's only to cap write length. + */ + GDNativeInt (*string_to_latin1_chars)(const GDNativeStringPtr p_self, char *r_text, GDNativeInt p_max_write_length); + GDNativeInt (*string_to_utf8_chars)(const GDNativeStringPtr p_self, char *r_text, GDNativeInt p_max_write_length); + GDNativeInt (*string_to_utf16_chars)(const GDNativeStringPtr p_self, char16_t *r_text, GDNativeInt p_max_write_length); + GDNativeInt (*string_to_utf32_chars)(const GDNativeStringPtr p_self, char32_t *r_text, GDNativeInt p_max_write_length); + GDNativeInt (*string_to_wide_chars)(const GDNativeStringPtr p_self, wchar_t *r_text, GDNativeInt p_max_write_length); + char32_t *(*string_operator_index)(GDNativeStringPtr p_self, GDNativeInt p_index); + const char32_t *(*string_operator_index_const)(const GDNativeStringPtr p_self, GDNativeInt p_index); + + /* OBJECT */ + + void (*object_method_bind_ptrcall)(GDNativeMethodBindPtr p_method_bind, GDNativeObjectPtr p_instance, const GDNativeTypePtr *p_args, GDNativeTypePtr r_ret); + void (*object_destroy)(GDNativeObjectPtr p_o); + GDNativeObjectPtr (*global_get_singleton)(const char *p_name); + void *(*object_get_instance_binding)(GDNativeObjectPtr p_o, void *p_token, GDNativeInstanceBindingCallbacks *p_callbacks); + + GDNativeObjectPtr (*object_cast_to)(const GDNativeObjectPtr p_object, void *p_class_tag); + GDNativeObjectPtr (*object_get_instance_from_id)(GDObjectInstanceID p_instance_id); + GDObjectInstanceID (*object_get_instance_id)(const GDNativeObjectPtr p_object); + + /* CLASSDB */ + + GDNativeClassConstructor (*classdb_get_constructor)(const char *p_classname); + GDNativeMethodBindPtr (*classdb_get_method_bind)(const char *p_classname, const char *p_methodname, GDNativeInt p_hash); + void *(*classdb_get_class_tag)(const char *p_classname); + + /* CLASSDB EXTENSION */ + + void (*classdb_register_extension_class)(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_parent_class_name, const GDNativeExtensionClassCreationInfo *p_extension_funcs); + void (*classdb_register_extension_class_method)(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const GDNativeExtensionClassMethodInfo *p_method_info); + void (*classdb_register_extension_class_integer_constant)(const GDNativeExtensionClassLibraryPtr p_library, const char *p_enum_name, const char *p_class_name, const char *p_constant_name, uint32_t p_constant_value); + void (*classdb_register_extension_class_property)(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const GDNativePropertyInfo *p_info, const char *p_setter, const char *p_getter); + void (*classdb_register_extension_class_signal)(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_signal_name, const GDNativePropertyInfo *p_argument_info, GDNativeInt p_argument_count); + void (*classdb_unregister_extension_class)(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name); /* Unregistering a parent class before a class that inherits it will result in failure. Inheritors must be unregistered first. */ +} GDNativeInterface; + +/* INITIALIZATION */ + +typedef enum { + GDNATIVE_INITIALIZATION_CORE, + GDNATIVE_INITIALIZATION_SERVERS, + GDNATIVE_INITIALIZATION_SCENE, + GDNATIVE_INITIALIZATION_EDITOR, +} GDNativeInitializationLevel; + +typedef struct { + /* Minimum initialization level required. + * If Core or Servers, the extension needs editor or game restart to take effect */ + GDNativeInitializationLevel minimum_initialization_level; + /* Up to the user to supply when initializing */ + void *userdata; + /* This function will be called multiple times for each initialization level. */ + void (*initialize)(void *userdata, GDNativeInitializationLevel p_level); + void (*deinitialize)(void *userdata, GDNativeInitializationLevel p_level); +} GDNativeInitialization; + +/* Define a C function prototype that implements the function below and expose it to dlopen() (or similar). + * It will be called on initialization. The name must be an unique one specified in the .gdextension config file. + */ + +typedef GDNativeBool (*GDNativeInitializationFunction)(const GDNativeInterface *p_interface, const GDNativeExtensionClassLibraryPtr p_library, GDNativeInitialization *r_initialization); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/core/extension/native_extension.cpp b/core/extension/native_extension.cpp new file mode 100644 index 0000000000..65718a7507 --- /dev/null +++ b/core/extension/native_extension.cpp @@ -0,0 +1,411 @@ +/*************************************************************************/ +/* native_extension.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "native_extension.h" +#include "core/io/config_file.h" +#include "core/object/class_db.h" +#include "core/object/method_bind.h" +#include "core/os/os.h" + +class NativeExtensionMethodBind : public MethodBind { + GDNativeExtensionClassMethodCall call_func; + GDNativeExtensionClassMethodPtrCall ptrcall_func; + GDNativeExtensionClassMethodGetArgumentType get_argument_type_func; + GDNativeExtensionClassMethodGetArgumentInfo get_argument_info_func; + GDNativeExtensionClassMethodGetArgumentMetadata get_argument_metadata_func; + void *method_userdata; + bool vararg; + +protected: + virtual Variant::Type _gen_argument_type(int p_arg) const { + return Variant::Type(get_argument_type_func(method_userdata, p_arg)); + } + virtual PropertyInfo _gen_argument_type_info(int p_arg) const { + GDNativePropertyInfo pinfo; + get_argument_info_func(method_userdata, p_arg, &pinfo); + PropertyInfo ret; + ret.type = Variant::Type(pinfo.type); + ret.name = pinfo.name; + ret.class_name = pinfo.class_name; + ret.hint = PropertyHint(pinfo.hint); + ret.usage = pinfo.usage; + ret.class_name = pinfo.class_name; + return ret; + } + +public: + virtual GodotTypeInfo::Metadata get_argument_meta(int p_arg) const { + return GodotTypeInfo::Metadata(get_argument_metadata_func(method_userdata, p_arg)); + } + + virtual Variant call(Object *p_object, const Variant **p_args, int p_arg_count, Callable::CallError &r_error) { + Variant ret; + GDExtensionClassInstancePtr extension_instance = p_object->_get_extension_instance(); + GDNativeCallError ce; + call_func(extension_instance, (const GDNativeVariantPtr *)p_args, p_arg_count, (GDNativeVariantPtr)&ret, &ce); + r_error.error = Callable::CallError::Error(ce.error); + r_error.argument = ce.argument; + r_error.expected = ce.expected; + return ret; + } + virtual void ptrcall(Object *p_object, const void **p_args, void *r_ret) { + ERR_FAIL_COND_MSG(vararg, "Vararg methods don't have ptrcall support. This is most likely an engine bug."); + GDExtensionClassInstancePtr extension_instance = p_object->_get_extension_instance(); + ptrcall_func(extension_instance, (const GDNativeTypePtr *)p_args, (GDNativeTypePtr)r_ret); + } + + virtual bool is_vararg() const { + return false; + } + NativeExtensionMethodBind(const GDNativeExtensionClassMethodInfo *p_method_info) { + method_userdata = p_method_info->method_userdata; + call_func = p_method_info->call_func; + ptrcall_func = p_method_info->ptrcall_func; + get_argument_type_func = p_method_info->get_argument_type_func; + get_argument_info_func = p_method_info->get_argument_info_func; + get_argument_metadata_func = p_method_info->get_argument_metadata_func; + + vararg = p_method_info->method_flags & GDNATIVE_EXTENSION_METHOD_FLAG_VARARG; + + _set_returns(p_method_info->has_return_value); + _set_const(p_method_info->method_flags & GDNATIVE_EXTENSION_METHOD_FLAG_CONST); +#ifdef DEBUG_METHODS_ENABLED + _generate_argument_types(p_method_info->argument_count); +#endif + set_argument_count(p_method_info->argument_count); + } +}; + +static GDNativeInterface gdnative_interface; + +void NativeExtension::_register_extension_class(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_parent_class_name, const GDNativeExtensionClassCreationInfo *p_extension_funcs) { + NativeExtension *self = (NativeExtension *)p_library; + + StringName class_name = p_class_name; + ERR_FAIL_COND_MSG(String(class_name).is_valid_identifier(), "Attempt to register extension clas '" + class_name + "', which is not a valid class identifier."); + ERR_FAIL_COND_MSG(ClassDB::class_exists(class_name), "Attempt to register extension class '" + class_name + "', which appears to be already registered."); + + Extension *parent_extension = nullptr; + StringName parent_class_name = p_parent_class_name; + + if (self->extension_classes.has(parent_class_name)) { + parent_extension = &self->extension_classes[parent_class_name]; + } else if (ClassDB::class_exists(parent_class_name)) { + if (ClassDB::get_api_type(parent_class_name) == ClassDB::API_EXTENSION || ClassDB::get_api_type(parent_class_name) == ClassDB::API_EDITOR_EXTENSION) { + ERR_PRINT("Unimplemented yet"); + //inheriting from another extension + } else { + //inheriting from engine class + } + } else { + ERR_FAIL_MSG("Attempt to register an extension class '" + String(class_name) + "' using non-existing parent class '" + String(parent_class_name) + "'"); + } + + self->extension_classes[class_name] = Extension(); + + Extension *extension = &self->extension_classes[class_name]; + + if (parent_extension) { + extension->native_extension.parent = &parent_extension->native_extension; + parent_extension->native_extension.children.push_back(&extension->native_extension); + } + + extension->native_extension.parent_class_name = parent_class_name; + extension->native_extension.class_name = class_name; + extension->native_extension.editor_class = self->level_initialized == INITIALIZATION_LEVEL_EDITOR; + extension->native_extension.set = p_extension_funcs->set_func; + extension->native_extension.get = p_extension_funcs->get_func; + extension->native_extension.get_property_list = p_extension_funcs->get_property_list_func; + extension->native_extension.free_property_list = p_extension_funcs->free_property_list_func; + extension->native_extension.notification = p_extension_funcs->notification_func; + extension->native_extension.to_string = p_extension_funcs->to_string_func; + extension->native_extension.reference = p_extension_funcs->reference_func; + extension->native_extension.unreference = p_extension_funcs->unreference_func; + extension->native_extension.class_userdata = p_extension_funcs->class_userdata; + extension->native_extension.create_instance = p_extension_funcs->create_instance_func; + extension->native_extension.free_instance = p_extension_funcs->free_instance_func; + + ClassDB::register_extension_class(&extension->native_extension); +} +void NativeExtension::_register_extension_class_method(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const GDNativeExtensionClassMethodInfo *p_method_info) { + NativeExtension *self = (NativeExtension *)p_library; + + StringName class_name = p_class_name; + StringName method_name = p_method_info->name; + ERR_FAIL_COND_MSG(self->extension_classes.has(class_name), "Attempt to register extension method '" + String(method_name) + "' for unexisting class '" + class_name + "'."); + + //Extension *extension = &self->extension_classes[class_name]; + + NativeExtensionMethodBind *method = memnew(NativeExtensionMethodBind(p_method_info)); + + ClassDB::bind_method_custom(class_name, method); +} +void NativeExtension::_register_extension_class_integer_constant(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_enum_name, const char *p_constant_name, uint32_t p_constant_value) { + NativeExtension *self = (NativeExtension *)p_library; + + StringName class_name = p_class_name; + ERR_FAIL_COND_MSG(self->extension_classes.has(class_name), "Attempt to register extension constant '" + String(p_constant_name) + "' for unexisting class '" + class_name + "'."); + + //Extension *extension = &self->extension_classes[class_name]; + + ClassDB::bind_integer_constant(class_name, p_enum_name, p_constant_name, p_constant_value); +} +void NativeExtension::_register_extension_class_property(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const GDNativePropertyInfo *p_info, const char *p_setter, const char *p_getter) { + NativeExtension *self = (NativeExtension *)p_library; + + StringName class_name = p_class_name; + ERR_FAIL_COND_MSG(self->extension_classes.has(class_name), "Attempt to register extension class property '" + String(p_info->name) + "' for unexisting class '" + class_name + "'."); + + //Extension *extension = &self->extension_classes[class_name]; + PropertyInfo pinfo; + pinfo.type = Variant::Type(p_info->type); + pinfo.name = p_info->name; + pinfo.class_name = p_info->class_name; + pinfo.hint = PropertyHint(p_info->hint); + pinfo.hint_string = p_info->hint_string; + pinfo.usage = p_info->usage; + + ClassDB::add_property(class_name, pinfo, p_setter, p_getter); +} + +void NativeExtension::_register_extension_class_signal(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_signal_name, const GDNativePropertyInfo *p_argument_info, GDNativeInt p_argument_count) { + NativeExtension *self = (NativeExtension *)p_library; + + StringName class_name = p_class_name; + ERR_FAIL_COND_MSG(self->extension_classes.has(class_name), "Attempt to register extension class signal '" + String(p_signal_name) + "' for unexisting class '" + class_name + "'."); + + MethodInfo s; + s.name = p_signal_name; + for (int i = 0; i < p_argument_count; i++) { + PropertyInfo arg; + arg.type = Variant::Type(p_argument_info[i].type); + arg.name = p_argument_info[i].name; + arg.class_name = p_argument_info[i].class_name; + arg.hint = PropertyHint(p_argument_info[i].hint); + arg.hint_string = p_argument_info[i].hint_string; + arg.usage = p_argument_info[i].usage; + s.arguments.push_back(arg); + } + ClassDB::add_signal(class_name, s); +} + +void NativeExtension::_unregister_extension_class(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name) { + NativeExtension *self = (NativeExtension *)p_library; + + StringName class_name = p_class_name; + ERR_FAIL_COND_MSG(self->extension_classes.has(class_name), "Attempt to unregister unexisting extension class '" + class_name + "'."); + Extension *ext = &self->extension_classes[class_name]; + ERR_FAIL_COND_MSG(ext->native_extension.children.size(), "Attempt to unregister class '" + class_name + "' while other extension classes inherit from it."); + + ClassDB::unregister_extension_class(class_name); + if (ext->native_extension.parent != nullptr) { + ext->native_extension.parent->children.erase(&ext->native_extension); + } + self->extension_classes.erase(class_name); +} + +Error NativeExtension::open_library(const String &p_path, const String &p_entry_symbol) { + Error err = OS::get_singleton()->open_dynamic_library(p_path, library, true); + if (err != OK) { + return err; + } + + void *entry_funcptr = nullptr; + + err = OS::get_singleton()->get_dynamic_library_symbol_handle(library, p_entry_symbol, entry_funcptr, false); + + if (err != OK) { + OS::get_singleton()->close_dynamic_library(library); + return err; + } + + GDNativeInitializationFunction initialization_function = (GDNativeInitializationFunction)entry_funcptr; + + initialization_function(&gdnative_interface, this, &initialization); + level_initialized = -1; + return OK; +} + +void NativeExtension::close_library() { + ERR_FAIL_COND(library == nullptr); + OS::get_singleton()->close_dynamic_library(library); + + library = nullptr; +} + +bool NativeExtension::is_library_open() const { + return library != nullptr; +} + +NativeExtension::InitializationLevel NativeExtension::get_minimum_library_initialization_level() const { + ERR_FAIL_COND_V(library == nullptr, INITIALIZATION_LEVEL_CORE); + return InitializationLevel(initialization.minimum_initialization_level); +} +void NativeExtension::initialize_library(InitializationLevel p_level) { + ERR_FAIL_COND(library == nullptr); + ERR_FAIL_COND(p_level <= int32_t(level_initialized)); + + level_initialized = int32_t(p_level); + + ERR_FAIL_COND(initialization.initialize == nullptr); + + initialization.initialize(initialization.userdata, GDNativeInitializationLevel(p_level)); +} +void NativeExtension::deinitialize_library(InitializationLevel p_level) { + ERR_FAIL_COND(library == nullptr); + ERR_FAIL_COND(p_level > int32_t(level_initialized)); + + level_initialized = int32_t(p_level) - 1; + initialization.deinitialize(initialization.userdata, GDNativeInitializationLevel(p_level)); +} + +void NativeExtension::_bind_methods() { + ClassDB::bind_method(D_METHOD("open_library", "path", "entry_symbol"), &NativeExtension::open_library); + ClassDB::bind_method(D_METHOD("close_library"), &NativeExtension::close_library); + ClassDB::bind_method(D_METHOD("is_library_open"), &NativeExtension::is_library_open); + + ClassDB::bind_method(D_METHOD("get_minimum_library_initialization_level"), &NativeExtension::get_minimum_library_initialization_level); + ClassDB::bind_method(D_METHOD("initialize_library", "level"), &NativeExtension::initialize_library); + + BIND_ENUM_CONSTANT(INITIALIZATION_LEVEL_CORE); + BIND_ENUM_CONSTANT(INITIALIZATION_LEVEL_SERVERS); + BIND_ENUM_CONSTANT(INITIALIZATION_LEVEL_SCENE); + BIND_ENUM_CONSTANT(INITIALIZATION_LEVEL_EDITOR); +} + +NativeExtension::NativeExtension() { +} + +NativeExtension::~NativeExtension() { + if (library != nullptr) { + close_library(); + } +} + +extern void gdnative_setup_interface(GDNativeInterface *p_interface); + +void NativeExtension::initialize_native_extensions() { + gdnative_setup_interface(&gdnative_interface); + + gdnative_interface.classdb_register_extension_class = _register_extension_class; + gdnative_interface.classdb_register_extension_class_method = _register_extension_class_method; + gdnative_interface.classdb_register_extension_class_integer_constant = _register_extension_class_integer_constant; + gdnative_interface.classdb_register_extension_class_property = _register_extension_class_property; + gdnative_interface.classdb_register_extension_class_signal = _register_extension_class_signal; + gdnative_interface.classdb_unregister_extension_class = _unregister_extension_class; +} + +RES NativeExtensionResourceLoader::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { + Ref<ConfigFile> config; + config.instantiate(); + + Error err = config->load(p_path); + + if (r_error) { + *r_error = err; + } + + if (err != OK) { + return RES(); + } + + if (!config->has_section_key("configuration", "entry_symbol")) { + if (r_error) { + *r_error = ERR_INVALID_DATA; + } + return RES(); + } + + String entry_symbol = config->get_value("configuration", "entry_symbol"); + + List<String> libraries; + + config->get_section_keys("libraries", &libraries); + + String library_path; + + for (List<String>::Element *E = libraries.front(); E; E = E->next()) { + Vector<String> tags = E->get().split("."); + bool all_tags_met = true; + for (int i = 0; i < tags.size(); i++) { + String tag = tags[i].strip_edges(); + if (!OS::get_singleton()->has_feature(tag)) { + all_tags_met = false; + break; + } + } + + if (all_tags_met) { + library_path = config->get_value("libraries", E->get()); + break; + } + } + + if (library_path != String()) { + if (r_error) { + *r_error = ERR_FILE_NOT_FOUND; + } + return RES(); + } + + if (!library_path.is_resource_file()) { + library_path = p_path.get_base_dir().plus_file(library_path); + } + + Ref<NativeExtension> lib; + lib.instantiate(); + err = lib->open_library(library_path, entry_symbol); + + if (r_error) { + *r_error = err; + } + + if (err != OK) { + return RES(); + } + + return lib; +} + +void NativeExtensionResourceLoader::get_recognized_extensions(List<String> *p_extensions) const { + p_extensions->push_back("gdextension"); +} + +bool NativeExtensionResourceLoader::handles_type(const String &p_type) const { + return p_type == "NativeExtension"; +} + +String NativeExtensionResourceLoader::get_resource_type(const String &p_path) const { + String el = p_path.get_extension().to_lower(); + if (el == "gdextension") { + return "NativeExtension"; + } + return ""; +} diff --git a/core/extension/native_extension.h b/core/extension/native_extension.h new file mode 100644 index 0000000000..0a23848eb2 --- /dev/null +++ b/core/extension/native_extension.h @@ -0,0 +1,94 @@ +/*************************************************************************/ +/* native_extension.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef NATIVE_EXTENSION_H +#define NATIVE_EXTENSION_H + +#include "core/extension/gdnative_interface.h" +#include "core/io/resource_loader.h" +#include "core/object/ref_counted.h" + +class NativeExtension : public RefCounted { + GDCLASS(NativeExtension, RefCounted) + + void *library = nullptr; // pointer if valid, + + struct Extension { + ObjectNativeExtension native_extension; + }; + + Map<StringName, Extension> extension_classes; + + static void _register_extension_class(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_parent_class_name, const GDNativeExtensionClassCreationInfo *p_extension_funcs); + static void _register_extension_class_method(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const GDNativeExtensionClassMethodInfo *p_method_info); + static void _register_extension_class_integer_constant(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_enum_name, const char *p_constant_name, uint32_t p_constant_value); + static void _register_extension_class_property(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const GDNativePropertyInfo *p_info, const char *p_setter, const char *p_getter); + static void _register_extension_class_signal(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_signal_name, const GDNativePropertyInfo *p_argument_info, GDNativeInt p_argument_count); + static void _unregister_extension_class(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name); + + GDNativeInitialization initialization; + int32_t level_initialized = -1; + +protected: + static void _bind_methods(); + +public: + Error open_library(const String &p_path, const String &p_entry_symbol); + void close_library(); + + enum InitializationLevel { + INITIALIZATION_LEVEL_CORE, + INITIALIZATION_LEVEL_SERVERS, + INITIALIZATION_LEVEL_SCENE, + INITIALIZATION_LEVEL_EDITOR, + }; + + bool is_library_open() const; + + InitializationLevel get_minimum_library_initialization_level() const; + void initialize_library(InitializationLevel p_level); + void deinitialize_library(InitializationLevel p_level); + + static void initialize_native_extensions(); + NativeExtension(); + ~NativeExtension(); +}; + +VARIANT_ENUM_CAST(NativeExtension::InitializationLevel) + +class NativeExtensionResourceLoader : public ResourceFormatLoader { +public: + virtual RES load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE); + virtual void get_recognized_extensions(List<String> *p_extensions) const; + virtual bool handles_type(const String &p_type) const; + virtual String get_resource_type(const String &p_path) const; +}; + +#endif // NATIVEEXTENSION_H diff --git a/core/extension/native_extension_manager.cpp b/core/extension/native_extension_manager.cpp new file mode 100644 index 0000000000..7be2593845 --- /dev/null +++ b/core/extension/native_extension_manager.cpp @@ -0,0 +1,130 @@ +/*************************************************************************/ +/* native_extension_manager.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "native_extension_manager.h" + +NativeExtensionManager::LoadStatus NativeExtensionManager::load_extension(const String &p_path) { + if (native_extension_map.has(p_path)) { + return LOAD_STATUS_ALREADY_LOADED; + } + Ref<NativeExtension> extension = ResourceLoader::load(p_path); + if (extension.is_null()) { + return LOAD_STATUS_FAILED; + } + + if (level >= 0) { //already initialized up to some level + int32_t minimum_level = extension->get_minimum_library_initialization_level(); + if (minimum_level < MIN(level, NativeExtension::INITIALIZATION_LEVEL_SCENE)) { + return LOAD_STATUS_NEEDS_RESTART; + } + //initialize up to current level + for (int32_t i = minimum_level; i < level; i++) { + extension->initialize_library(NativeExtension::InitializationLevel(level)); + } + } + native_extension_map[p_path] = extension; + return LOAD_STATUS_OK; +} + +NativeExtensionManager::LoadStatus NativeExtensionManager::reload_extension(const String &p_path) { + return LOAD_STATUS_OK; //TODO +} +NativeExtensionManager::LoadStatus NativeExtensionManager::unload_extension(const String &p_path) { + if (!native_extension_map.has(p_path)) { + return LOAD_STATUS_NOT_LOADED; + } + + Ref<NativeExtension> extension = native_extension_map[p_path]; + + if (level >= 0) { //already initialized up to some level + int32_t minimum_level = extension->get_minimum_library_initialization_level(); + if (minimum_level < MIN(level, NativeExtension::INITIALIZATION_LEVEL_SCENE)) { + return LOAD_STATUS_NEEDS_RESTART; + } + //initialize up to current level + for (int32_t i = level; i >= minimum_level; i--) { + extension->deinitialize_library(NativeExtension::InitializationLevel(level)); + } + } + native_extension_map.erase(p_path); + return LOAD_STATUS_OK; +} +Vector<String> NativeExtensionManager::get_loaded_extensions() const { + Vector<String> ret; + for (const Map<String, Ref<NativeExtension>>::Element *E = native_extension_map.front(); E; E = E->next()) { + ret.push_back(E->key()); + } + return ret; +} +Ref<NativeExtension> NativeExtensionManager::get_extension(const String &p_path) { + Map<String, Ref<NativeExtension>>::Element *E = native_extension_map.find(p_path); + ERR_FAIL_COND_V(!E, Ref<NativeExtension>()); + return E->get(); +} + +void NativeExtensionManager::initialize_extensions(NativeExtension::InitializationLevel p_level) { + ERR_FAIL_COND(int32_t(p_level) - 1 != level); + for (Map<String, Ref<NativeExtension>>::Element *E = native_extension_map.front(); E; E = E->next()) { + E->get()->initialize_library(p_level); + } + level = p_level; +} + +void NativeExtensionManager::deinitialize_extensions(NativeExtension::InitializationLevel p_level) { + ERR_FAIL_COND(int32_t(p_level) != level); + for (Map<String, Ref<NativeExtension>>::Element *E = native_extension_map.front(); E; E = E->next()) { + E->get()->deinitialize_library(p_level); + } + level = int32_t(p_level) - 1; +} + +NativeExtensionManager *NativeExtensionManager::get_singleton() { + return singleton; +} +void NativeExtensionManager::_bind_methods() { + ClassDB::bind_method(D_METHOD("load_extension", "path"), &NativeExtensionManager::load_extension); + ClassDB::bind_method(D_METHOD("reload_extension", "path"), &NativeExtensionManager::reload_extension); + ClassDB::bind_method(D_METHOD("unload_extension", "path"), &NativeExtensionManager::unload_extension); + ClassDB::bind_method(D_METHOD("get_loaded_extensions"), &NativeExtensionManager::get_loaded_extensions); + ClassDB::bind_method(D_METHOD("get_extension", "path"), &NativeExtensionManager::get_extension); + + BIND_ENUM_CONSTANT(LOAD_STATUS_OK); + BIND_ENUM_CONSTANT(LOAD_STATUS_FAILED); + BIND_ENUM_CONSTANT(LOAD_STATUS_ALREADY_LOADED); + BIND_ENUM_CONSTANT(LOAD_STATUS_NOT_LOADED); + BIND_ENUM_CONSTANT(LOAD_STATUS_NEEDS_RESTART); +} + +NativeExtensionManager *NativeExtensionManager::singleton = nullptr; + +NativeExtensionManager::NativeExtensionManager() { + ERR_FAIL_COND(singleton != nullptr); + singleton = this; +} diff --git a/scene/3d/immediate_geometry_3d.h b/core/extension/native_extension_manager.h index ee4938d9f7..78465bd5cf 100644 --- a/scene/3d/immediate_geometry_3d.h +++ b/core/extension/native_extension_manager.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* immediate_geometry_3d.h */ +/* native_extension_manager.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,45 +28,44 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef IMMEDIATE_GEOMETRY_3D_H -#define IMMEDIATE_GEOMETRY_3D_H +#ifndef NATIVE_EXTENSION_MANAGER_H +#define NATIVE_EXTENSION_MANAGER_H -#include "scene/3d/visual_instance_3d.h" -#include "scene/resources/mesh.h" +#include "core/extension/native_extension.h" -class ImmediateGeometry3D : public GeometryInstance3D { - GDCLASS(ImmediateGeometry3D, GeometryInstance3D); +class NativeExtensionManager : public Object { + GDCLASS(NativeExtensionManager, Object); - RID im; - //a list of textures drawn need to be kept, to avoid references - // in RenderingServer from becoming invalid if the texture is no longer used - List<Ref<Texture2D>> cached_textures; - bool empty = true; - AABB aabb; + int32_t level = -1; + Map<String, Ref<NativeExtension>> native_extension_map; -protected: static void _bind_methods(); -public: - void begin(Mesh::PrimitiveType p_primitive, const Ref<Texture2D> &p_texture = Ref<Texture2D>()); - void set_normal(const Vector3 &p_normal); - void set_tangent(const Plane &p_tangent); - void set_color(const Color &p_color); - void set_uv(const Vector2 &p_uv); - void set_uv2(const Vector2 &p_uv2); + static NativeExtensionManager *singleton; - void add_vertex(const Vector3 &p_vertex); +public: + enum LoadStatus { + LOAD_STATUS_OK, + LOAD_STATUS_FAILED, + LOAD_STATUS_ALREADY_LOADED, + LOAD_STATUS_NOT_LOADED, + LOAD_STATUS_NEEDS_RESTART, + }; - void end(); - void clear(); + LoadStatus load_extension(const String &p_path); + LoadStatus reload_extension(const String &p_path); + LoadStatus unload_extension(const String &p_path); + Vector<String> get_loaded_extensions() const; + Ref<NativeExtension> get_extension(const String &p_path); - void add_sphere(int p_lats, int p_lons, float p_radius, bool p_add_uv = true); + void initialize_extensions(NativeExtension::InitializationLevel p_level); + void deinitialize_extensions(NativeExtension::InitializationLevel p_level); - virtual AABB get_aabb() const override; - virtual Vector<Face3> get_faces(uint32_t p_usage_flags) const override; + static NativeExtensionManager *get_singleton(); - ImmediateGeometry3D(); - ~ImmediateGeometry3D(); + NativeExtensionManager(); }; -#endif // IMMEDIATE_GEOMETRY_H +VARIANT_ENUM_CAST(NativeExtensionManager::LoadStatus) + +#endif // NATIVEEXTENSIONMANAGER_H diff --git a/core/input/input.cpp b/core/input/input.cpp index 6e98b596d7..a712394b35 100644 --- a/core/input/input.cpp +++ b/core/input/input.cpp @@ -227,7 +227,7 @@ bool Input::is_key_pressed(int p_keycode) const { return keys_pressed.has(p_keycode); } -bool Input::is_mouse_button_pressed(int p_button) const { +bool Input::is_mouse_button_pressed(MouseButton p_button) const { _THREAD_SAFE_METHOD_ return (mouse_button_mask & (1 << (p_button - 1))) != 0; } @@ -236,7 +236,7 @@ static int _combine_device(int p_value, int p_device) { return p_value | (p_device << 20); } -bool Input::is_joy_button_pressed(int p_device, int p_button) const { +bool Input::is_joy_button_pressed(int p_device, JoyButton p_button) const { _THREAD_SAFE_METHOD_ return joy_buttons_pressed.has(_combine_device(p_button, p_device)); } @@ -352,7 +352,7 @@ Vector2 Input::get_vector(const StringName &p_negative_x, const StringName &p_po return vector; } -float Input::get_joy_axis(int p_device, int p_axis) const { +float Input::get_joy_axis(int p_device, JoyAxis p_axis) const { _THREAD_SAFE_METHOD_ int c = _combine_device(p_axis, p_device); if (_joy_axis.has(c)) { @@ -433,7 +433,7 @@ void Input::joy_connection_changed(int p_idx, bool p_connected, String p_name, S joy_buttons_pressed.erase(c); } for (int i = 0; i < JOY_AXIS_MAX; i++) { - set_joy_axis(p_idx, i, 0.0f); + set_joy_axis(p_idx, (JoyAxis)i, 0.0f); } } joy_names[p_idx] = js; @@ -488,9 +488,9 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em if (mb.is_valid()) { if (mb->is_pressed()) { - mouse_button_mask |= (1 << (mb->get_button_index() - 1)); + mouse_button_mask |= (MouseButton)(1 << (mb->get_button_index() - 1)); } else { - mouse_button_mask &= ~(1 << (mb->get_button_index() - 1)); + mouse_button_mask &= (MouseButton) ~(1 << (mb->get_button_index() - 1)); } Point2 pos = mb->get_global_position(); @@ -500,7 +500,7 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em if (event_dispatch_function && emulate_touch_from_mouse && !p_is_emulated && mb->get_button_index() == 1) { Ref<InputEventScreenTouch> touch_event; - touch_event.instance(); + touch_event.instantiate(); touch_event->set_pressed(mb->is_pressed()); touch_event->set_position(mb->get_position()); event_dispatch_function(touch_event); @@ -517,7 +517,7 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em if (event_dispatch_function && emulate_touch_from_mouse && !p_is_emulated && mm->get_button_mask() & 1) { Ref<InputEventScreenDrag> drag_event; - drag_event.instance(); + drag_event.instantiate(); drag_event->set_position(mm->get_position()); drag_event->set_relative(mm->get_relative()); @@ -555,7 +555,7 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em if (translate) { Ref<InputEventMouseButton> button_event; - button_event.instance(); + button_event.instantiate(); button_event->set_device(InputEvent::DEVICE_ID_TOUCH_MOUSE); button_event->set_position(st->get_position()); @@ -563,9 +563,9 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em button_event->set_pressed(st->is_pressed()); button_event->set_button_index(MOUSE_BUTTON_LEFT); if (st->is_pressed()) { - button_event->set_button_mask(mouse_button_mask | (1 << (MOUSE_BUTTON_LEFT - 1))); + button_event->set_button_mask(MouseButton(mouse_button_mask | MOUSE_BUTTON_MASK_LEFT)); } else { - button_event->set_button_mask(mouse_button_mask & ~(1 << (MOUSE_BUTTON_LEFT - 1))); + button_event->set_button_mask(MouseButton(mouse_button_mask & ~MOUSE_BUTTON_MASK_LEFT)); } _parse_input_event_impl(button_event, true); @@ -582,7 +582,7 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em if (emulate_mouse_from_touch && sd->get_index() == mouse_from_touch_index) { Ref<InputEventMouseMotion> motion_event; - motion_event.instance(); + motion_event.instantiate(); motion_event->set_device(InputEvent::DEVICE_ID_TOUCH_MOUSE); motion_event->set_position(sd->get_position()); @@ -644,7 +644,7 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em } } -void Input::set_joy_axis(int p_device, int p_axis, float p_value) { +void Input::set_joy_axis(int p_device, JoyAxis p_axis, float p_value) { _THREAD_SAFE_METHOD_ int c = _combine_device(p_axis, p_device); _joy_axis[c] = p_value; @@ -787,14 +787,14 @@ void Input::ensure_touch_mouse_raised() { mouse_from_touch_index = -1; Ref<InputEventMouseButton> button_event; - button_event.instance(); + button_event.instantiate(); button_event->set_device(InputEvent::DEVICE_ID_TOUCH_MOUSE); button_event->set_position(mouse_pos); button_event->set_global_position(mouse_pos); button_event->set_pressed(false); button_event->set_button_index(MOUSE_BUTTON_LEFT); - button_event->set_button_mask(mouse_button_mask & ~(1 << (MOUSE_BUTTON_LEFT - 1))); + button_event->set_button_mask(MouseButton(mouse_button_mask & ~MOUSE_BUTTON_MASK_LEFT)); _parse_input_event_impl(button_event, true); } @@ -821,7 +821,7 @@ void Input::set_default_cursor_shape(CursorShape p_shape) { // The default shape is set in Viewport::_gui_input_event. To instantly // see the shape in the viewport we need to trigger a mouse motion event. Ref<InputEventMouseMotion> mm; - mm.instance(); + mm.instantiate(); mm->set_position(mouse_pos); mm->set_global_position(mouse_pos); parse_input_event(mm); @@ -882,7 +882,7 @@ void Input::set_event_dispatch_function(EventDispatchFunc p_function) { event_dispatch_function = p_function; } -void Input::joy_button(int p_device, int p_button, bool p_pressed) { +void Input::joy_button(int p_device, JoyButton p_button, bool p_pressed) { _THREAD_SAFE_METHOD_; Joypad &joy = joy_names[p_device]; //printf("got button %i, mapping is %i\n", p_button, joy.mapping); @@ -898,17 +898,17 @@ void Input::joy_button(int p_device, int p_button, bool p_pressed) { JoyEvent map = _get_mapped_button_event(map_db[joy.mapping], p_button); if (map.type == TYPE_BUTTON) { - _button_event(p_device, map.index, p_pressed); + _button_event(p_device, (JoyButton)map.index, p_pressed); return; } if (map.type == TYPE_AXIS) { - _axis_event(p_device, map.index, p_pressed ? map.value : 0.0); + _axis_event(p_device, (JoyAxis)map.index, p_pressed ? map.value : 0.0); } // no event? } -void Input::joy_axis(int p_device, int p_axis, const JoyAxisValue &p_value) { +void Input::joy_axis(int p_device, JoyAxis p_axis, const JoyAxisValue &p_value) { _THREAD_SAFE_METHOD_; ERR_FAIL_INDEX(p_axis, JOY_AXIS_MAX); @@ -949,7 +949,7 @@ void Input::joy_axis(int p_device, int p_axis, const JoyAxisValue &p_value) { // Button already pressed or released; so ignore. return; } - _button_event(p_device, map.index, pressed); + _button_event(p_device, (JoyButton)map.index, pressed); // Ensure opposite D-Pad button is also released. switch (map.index) { @@ -981,7 +981,7 @@ void Input::joy_axis(int p_device, int p_axis, const JoyAxisValue &p_value) { } if (map.type == TYPE_AXIS) { - _axis_event(p_device, map.index, map.value); + _axis_event(p_device, (JoyAxis)map.index, map.value); return; } //printf("invalid mapping\n"); @@ -993,24 +993,24 @@ void Input::joy_hat(int p_device, int p_val) { JoyEvent map[HAT_MAX]; - map[HAT_UP].type = TYPE_BUTTON; - map[HAT_UP].index = JOY_BUTTON_DPAD_UP; - map[HAT_UP].value = 0; + map[HatDir::HAT_UP].type = TYPE_BUTTON; + map[HatDir::HAT_UP].index = JOY_BUTTON_DPAD_UP; + map[HatDir::HAT_UP].value = 0; - map[HAT_RIGHT].type = TYPE_BUTTON; - map[HAT_RIGHT].index = JOY_BUTTON_DPAD_RIGHT; - map[HAT_RIGHT].value = 0; + map[HatDir::HAT_RIGHT].type = TYPE_BUTTON; + map[HatDir::HAT_RIGHT].index = JOY_BUTTON_DPAD_RIGHT; + map[HatDir::HAT_RIGHT].value = 0; - map[HAT_DOWN].type = TYPE_BUTTON; - map[HAT_DOWN].index = JOY_BUTTON_DPAD_DOWN; - map[HAT_DOWN].value = 0; + map[HatDir::HAT_DOWN].type = TYPE_BUTTON; + map[HatDir::HAT_DOWN].index = JOY_BUTTON_DPAD_DOWN; + map[HatDir::HAT_DOWN].value = 0; - map[HAT_LEFT].type = TYPE_BUTTON; - map[HAT_LEFT].index = JOY_BUTTON_DPAD_LEFT; - map[HAT_LEFT].value = 0; + map[HatDir::HAT_LEFT].type = TYPE_BUTTON; + map[HatDir::HAT_LEFT].index = JOY_BUTTON_DPAD_LEFT; + map[HatDir::HAT_LEFT].value = 0; if (joy.mapping != -1) { - _get_mapped_hat_events(map_db[joy.mapping], 0, map); + _get_mapped_hat_events(map_db[joy.mapping], (HatDir)0, map); } int cur_val = joy_names[p_device].hat_current; @@ -1018,10 +1018,10 @@ void Input::joy_hat(int p_device, int p_val) { for (int hat_direction = 0, hat_mask = 1; hat_direction < HAT_MAX; hat_direction++, hat_mask <<= 1) { if ((p_val & hat_mask) != (cur_val & hat_mask)) { if (map[hat_direction].type == TYPE_BUTTON) { - _button_event(p_device, map[hat_direction].index, p_val & hat_mask); + _button_event(p_device, (JoyButton)map[hat_direction].index, p_val & hat_mask); } if (map[hat_direction].type == TYPE_AXIS) { - _axis_event(p_device, map[hat_direction].index, (p_val & hat_mask) ? map[hat_direction].value : 0.0); + _axis_event(p_device, (JoyAxis)map[hat_direction].index, (p_val & hat_mask) ? map[hat_direction].value : 0.0); } } } @@ -1029,9 +1029,9 @@ void Input::joy_hat(int p_device, int p_val) { joy_names[p_device].hat_current = p_val; } -void Input::_button_event(int p_device, int p_index, bool p_pressed) { +void Input::_button_event(int p_device, JoyButton p_index, bool p_pressed) { Ref<InputEventJoypadButton> ievent; - ievent.instance(); + ievent.instantiate(); ievent->set_device(p_device); ievent->set_button_index(p_index); ievent->set_pressed(p_pressed); @@ -1039,9 +1039,9 @@ void Input::_button_event(int p_device, int p_index, bool p_pressed) { parse_input_event(ievent); } -void Input::_axis_event(int p_device, int p_axis, float p_value) { +void Input::_axis_event(int p_device, JoyAxis p_axis, float p_value) { Ref<InputEventJoypadMotion> ievent; - ievent.instance(); + ievent.instantiate(); ievent->set_device(p_device); ievent->set_axis(p_axis); ievent->set_axis_value(p_value); @@ -1049,7 +1049,7 @@ void Input::_axis_event(int p_device, int p_axis, float p_value) { parse_input_event(ievent); } -Input::JoyEvent Input::_get_mapped_button_event(const JoyDeviceMapping &mapping, int p_button) { +Input::JoyEvent Input::_get_mapped_button_event(const JoyDeviceMapping &mapping, JoyButton p_button) { JoyEvent event; event.type = TYPE_MAX; @@ -1085,7 +1085,7 @@ Input::JoyEvent Input::_get_mapped_button_event(const JoyDeviceMapping &mapping, return event; } -Input::JoyEvent Input::_get_mapped_axis_event(const JoyDeviceMapping &mapping, int p_axis, float p_value) { +Input::JoyEvent Input::_get_mapped_axis_event(const JoyDeviceMapping &mapping, JoyAxis p_axis, float p_value) { JoyEvent event; event.type = TYPE_MAX; @@ -1156,23 +1156,23 @@ Input::JoyEvent Input::_get_mapped_axis_event(const JoyDeviceMapping &mapping, i return event; } -void Input::_get_mapped_hat_events(const JoyDeviceMapping &mapping, int p_hat, JoyEvent r_events[]) { +void Input::_get_mapped_hat_events(const JoyDeviceMapping &mapping, HatDir p_hat, JoyEvent r_events[]) { for (int i = 0; i < mapping.bindings.size(); i++) { const JoyBinding binding = mapping.bindings[i]; if (binding.inputType == TYPE_HAT && binding.input.hat.hat == p_hat) { int hat_direction; switch (binding.input.hat.hat_mask) { - case HAT_MASK_UP: - hat_direction = HAT_UP; + case HatMask::HAT_MASK_UP: + hat_direction = HatDir::HAT_UP; break; - case HAT_MASK_RIGHT: - hat_direction = HAT_RIGHT; + case HatMask::HAT_MASK_RIGHT: + hat_direction = HatDir::HAT_RIGHT; break; - case HAT_MASK_DOWN: - hat_direction = HAT_DOWN; + case HatMask::HAT_MASK_DOWN: + hat_direction = HatDir::HAT_DOWN; break; - case HAT_MASK_LEFT: - hat_direction = HAT_LEFT; + case HatMask::HAT_MASK_LEFT: + hat_direction = HatDir::HAT_LEFT; break; default: ERR_PRINT_ONCE("Joypad button mapping error."); @@ -1300,11 +1300,11 @@ void Input::parse_mapping(String p_mapping) { switch (input[0]) { case 'b': binding.inputType = TYPE_BUTTON; - binding.input.button = input.substr(1).to_int(); + binding.input.button = (JoyButton)input.substr(1).to_int(); break; case 'a': binding.inputType = TYPE_AXIS; - binding.input.axis.axis = input.substr(1).to_int(); + binding.input.axis.axis = (JoyAxis)input.substr(1).to_int(); binding.input.axis.range = input_range; binding.input.axis.invert = invert_axis; break; @@ -1312,7 +1312,7 @@ void Input::parse_mapping(String p_mapping) { ERR_CONTINUE_MSG(input.length() != 4 || input[2] != '.', String(entry[idx] + "\nInvalid hat input: " + input)); binding.inputType = TYPE_HAT; - binding.input.hat.hat = input.substr(1, 1).to_int(); + binding.input.hat.hat = (HatDir)input.substr(1, 1).to_int(); binding.input.hat.hat_mask = static_cast<HatMask>(input.substr(3).to_int()); break; default: diff --git a/core/input/input.h b/core/input/input.h index ecb4981b13..fbcd5836ea 100644 --- a/core/input/input.h +++ b/core/input/input.h @@ -72,22 +72,6 @@ public: CURSOR_MAX }; - enum HatMask { - HAT_MASK_CENTER = 0, - HAT_MASK_UP = 1, - HAT_MASK_RIGHT = 2, - HAT_MASK_DOWN = 4, - HAT_MASK_LEFT = 8, - }; - - enum HatDir { - HAT_UP, - HAT_RIGHT, - HAT_DOWN, - HAT_LEFT, - HAT_MAX, - }; - enum { JOYPADS_MAX = 16, }; @@ -149,7 +133,7 @@ private: bool connected = false; bool last_buttons[JOY_BUTTON_MAX] = { false }; float last_axis[JOY_AXIS_MAX] = { 0.0f }; - int last_hat = HAT_MASK_CENTER; + int last_hat = HatMask::HAT_MASK_CENTER; int mapping = -1; int hat_current = 0; }; @@ -183,16 +167,16 @@ private: struct JoyBinding { JoyType inputType; union { - int button; + JoyButton button; struct { - int axis; + JoyAxis axis; JoyAxisRange range; bool invert; } axis; struct { - int hat; + HatDir hat; HatMask hat_mask; } hat; @@ -218,13 +202,13 @@ private: Vector<JoyDeviceMapping> map_db; - JoyEvent _get_mapped_button_event(const JoyDeviceMapping &mapping, int p_button); - JoyEvent _get_mapped_axis_event(const JoyDeviceMapping &mapping, int p_axis, float p_value); - void _get_mapped_hat_events(const JoyDeviceMapping &mapping, int p_hat, JoyEvent r_events[HAT_MAX]); + JoyEvent _get_mapped_button_event(const JoyDeviceMapping &mapping, JoyButton p_button); + JoyEvent _get_mapped_axis_event(const JoyDeviceMapping &mapping, JoyAxis p_axis, float p_value); + void _get_mapped_hat_events(const JoyDeviceMapping &mapping, HatDir p_hat, JoyEvent r_events[HAT_MAX]); JoyButton _get_output_button(String output); JoyAxis _get_output_axis(String output); - void _button_event(int p_device, int p_index, bool p_pressed); - void _axis_event(int p_device, int p_axis, float p_value); + void _button_event(int p_device, JoyButton p_index, bool p_pressed); + void _axis_event(int p_device, JoyAxis p_axis, float p_value); void _parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_emulated); @@ -261,8 +245,8 @@ public: static Input *get_singleton(); bool is_key_pressed(int p_keycode) const; - bool is_mouse_button_pressed(int p_button) const; - bool is_joy_button_pressed(int p_device, int p_button) const; + bool is_mouse_button_pressed(MouseButton p_button) const; + bool is_joy_button_pressed(int p_device, JoyButton p_button) const; bool is_action_pressed(const StringName &p_action, bool p_exact = false) const; bool is_action_just_pressed(const StringName &p_action, bool p_exact = false) const; bool is_action_just_released(const StringName &p_action, bool p_exact = false) const; @@ -272,7 +256,7 @@ public: float get_axis(const StringName &p_negative_action, const StringName &p_positive_action) const; Vector2 get_vector(const StringName &p_negative_x, const StringName &p_positive_x, const StringName &p_negative_y, const StringName &p_positive_y, float p_deadzone = -1.0f) const; - float get_joy_axis(int p_device, int p_axis) const; + float get_joy_axis(int p_device, JoyAxis p_axis) const; String get_joy_name(int p_idx); Array get_connected_joypads(); Vector2 get_joy_vibration_strength(int p_device); @@ -299,7 +283,7 @@ public: void set_accelerometer(const Vector3 &p_accel); void set_magnetometer(const Vector3 &p_magnetometer); void set_gyroscope(const Vector3 &p_gyroscope); - void set_joy_axis(int p_device, int p_axis, float p_value); + void set_joy_axis(int p_device, JoyAxis p_axis, float p_value); void start_joy_vibration(int p_device, float p_weak_magnitude, float p_strong_magnitude, float p_duration = 0); void stop_joy_vibration(int p_device); @@ -325,8 +309,8 @@ public: void set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape = Input::CURSOR_ARROW, const Vector2 &p_hotspot = Vector2()); void parse_mapping(String p_mapping); - void joy_button(int p_device, int p_button, bool p_pressed); - void joy_axis(int p_device, int p_axis, const JoyAxisValue &p_value); + void joy_button(int p_device, JoyButton p_button, bool p_pressed); + void joy_axis(int p_device, JoyAxis p_axis, const JoyAxisValue &p_value); void joy_hat(int p_device, int p_val); void add_joy_mapping(String p_mapping, bool p_update_existing = false); diff --git a/core/input/input_enums.h b/core/input/input_enums.h new file mode 100644 index 0000000000..4479a85bfe --- /dev/null +++ b/core/input/input_enums.h @@ -0,0 +1,126 @@ +/*************************************************************************/ +/* input_enums.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef INPUT_ENUMS_H +#define INPUT_ENUMS_H + +enum HatDir { + HAT_UP = 0, + HAT_RIGHT = 1, + HAT_DOWN = 2, + HAT_LEFT = 3, + HAT_MAX = 4, +}; + +enum HatMask { + HAT_MASK_CENTER = 0, + HAT_MASK_UP = 1, + HAT_MASK_RIGHT = 2, + HAT_MASK_DOWN = 4, + HAT_MASK_LEFT = 8, +}; + +enum JoyAxis { + JOY_AXIS_INVALID = -1, + JOY_AXIS_LEFT_X = 0, + JOY_AXIS_LEFT_Y = 1, + JOY_AXIS_RIGHT_X = 2, + JOY_AXIS_RIGHT_Y = 3, + JOY_AXIS_TRIGGER_LEFT = 4, + JOY_AXIS_TRIGGER_RIGHT = 5, + JOY_AXIS_SDL_MAX = 6, + JOY_AXIS_MAX = 10, // OpenVR supports up to 5 Joysticks making a total of 10 axes. +}; + +enum JoyButton { + JOY_BUTTON_INVALID = -1, + JOY_BUTTON_A = 0, + JOY_BUTTON_B = 1, + JOY_BUTTON_X = 2, + JOY_BUTTON_Y = 3, + JOY_BUTTON_BACK = 4, + JOY_BUTTON_GUIDE = 5, + JOY_BUTTON_START = 6, + JOY_BUTTON_LEFT_STICK = 7, + JOY_BUTTON_RIGHT_STICK = 8, + JOY_BUTTON_LEFT_SHOULDER = 9, + JOY_BUTTON_RIGHT_SHOULDER = 10, + JOY_BUTTON_DPAD_UP = 11, + JOY_BUTTON_DPAD_DOWN = 12, + JOY_BUTTON_DPAD_LEFT = 13, + JOY_BUTTON_DPAD_RIGHT = 14, + JOY_BUTTON_MISC1 = 15, + JOY_BUTTON_PADDLE1 = 16, + JOY_BUTTON_PADDLE2 = 17, + JOY_BUTTON_PADDLE3 = 18, + JOY_BUTTON_PADDLE4 = 19, + JOY_BUTTON_TOUCHPAD = 20, + JOY_BUTTON_SDL_MAX = 21, + JOY_BUTTON_MAX = 36, // Android supports up to 36 buttons. +}; + +enum MIDIMessage { + MIDI_MESSAGE_NONE = 0, + MIDI_MESSAGE_NOTE_OFF = 0x8, + MIDI_MESSAGE_NOTE_ON = 0x9, + MIDI_MESSAGE_AFTERTOUCH = 0xA, + MIDI_MESSAGE_CONTROL_CHANGE = 0xB, + MIDI_MESSAGE_PROGRAM_CHANGE = 0xC, + MIDI_MESSAGE_CHANNEL_PRESSURE = 0xD, + MIDI_MESSAGE_PITCH_BEND = 0xE, +}; + +enum MouseButton { + MOUSE_BUTTON_NONE = 0, + MOUSE_BUTTON_LEFT = 1, + MOUSE_BUTTON_RIGHT = 2, + MOUSE_BUTTON_MIDDLE = 3, + MOUSE_BUTTON_WHEEL_UP = 4, + MOUSE_BUTTON_WHEEL_DOWN = 5, + MOUSE_BUTTON_WHEEL_LEFT = 6, + MOUSE_BUTTON_WHEEL_RIGHT = 7, + MOUSE_BUTTON_XBUTTON1 = 8, + MOUSE_BUTTON_XBUTTON2 = 9, + MOUSE_BUTTON_MASK_LEFT = (1 << (MOUSE_BUTTON_LEFT - 1)), + MOUSE_BUTTON_MASK_RIGHT = (1 << (MOUSE_BUTTON_RIGHT - 1)), + MOUSE_BUTTON_MASK_MIDDLE = (1 << (MOUSE_BUTTON_MIDDLE - 1)), + MOUSE_BUTTON_MASK_XBUTTON1 = (1 << (MOUSE_BUTTON_XBUTTON1 - 1)), + MOUSE_BUTTON_MASK_XBUTTON2 = (1 << (MOUSE_BUTTON_XBUTTON2 - 1)), +}; + +inline MouseButton &operator|=(MouseButton &a, MouseButton b) { + return (MouseButton &)((int &)a |= (int)b); +} + +inline MouseButton &operator&=(MouseButton &a, MouseButton b) { + return (MouseButton &)((int &)a &= (int)b); +} + +#endif // INPUT_ENUMS_H diff --git a/core/input/input_event.cpp b/core/input/input_event.cpp index 9c1cf15342..4a2abffae8 100644 --- a/core/input/input_event.cpp +++ b/core/input/input_event.cpp @@ -38,6 +38,7 @@ const int InputEvent::DEVICE_ID_INTERNAL = -2; void InputEvent::set_device(int p_device) { device = p_device; + emit_changed(); } int InputEvent::get_device() const { @@ -88,7 +89,7 @@ bool InputEvent::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, f return false; } -bool InputEvent::shortcut_match(const Ref<InputEvent> &p_event) const { +bool InputEvent::is_match(const Ref<InputEvent> &p_event, bool p_exact_match) const { return false; } @@ -110,7 +111,7 @@ void InputEvent::_bind_methods() { ClassDB::bind_method(D_METHOD("as_text"), &InputEvent::as_text); - ClassDB::bind_method(D_METHOD("shortcut_match", "event"), &InputEvent::shortcut_match); + ClassDB::bind_method(D_METHOD("is_match", "event", "exact_match"), &InputEvent::is_match, DEFVAL(true)); ClassDB::bind_method(D_METHOD("is_action_type"), &InputEvent::is_action_type); @@ -131,6 +132,7 @@ void InputEventFromWindow::_bind_methods() { void InputEventFromWindow::set_window_id(int64_t p_id) { window_id = p_id; + emit_changed(); } int64_t InputEventFromWindow::get_window_id() const { @@ -141,6 +143,7 @@ int64_t InputEventFromWindow::get_window_id() const { void InputEventWithModifiers::set_store_command(bool p_enabled) { store_command = p_enabled; + emit_changed(); } bool InputEventWithModifiers::is_storing_command() const { @@ -149,6 +152,7 @@ bool InputEventWithModifiers::is_storing_command() const { void InputEventWithModifiers::set_shift_pressed(bool p_enabled) { shift_pressed = p_enabled; + emit_changed(); } bool InputEventWithModifiers::is_shift_pressed() const { @@ -157,6 +161,7 @@ bool InputEventWithModifiers::is_shift_pressed() const { void InputEventWithModifiers::set_alt_pressed(bool p_enabled) { alt_pressed = p_enabled; + emit_changed(); } bool InputEventWithModifiers::is_alt_pressed() const { @@ -165,6 +170,7 @@ bool InputEventWithModifiers::is_alt_pressed() const { void InputEventWithModifiers::set_ctrl_pressed(bool p_enabled) { ctrl_pressed = p_enabled; + emit_changed(); } bool InputEventWithModifiers::is_ctrl_pressed() const { @@ -173,6 +179,7 @@ bool InputEventWithModifiers::is_ctrl_pressed() const { void InputEventWithModifiers::set_meta_pressed(bool p_enabled) { meta_pressed = p_enabled; + emit_changed(); } bool InputEventWithModifiers::is_meta_pressed() const { @@ -181,6 +188,7 @@ bool InputEventWithModifiers::is_meta_pressed() const { void InputEventWithModifiers::set_command_pressed(bool p_enabled) { command_pressed = p_enabled; + emit_changed(); } bool InputEventWithModifiers::is_command_pressed() const { @@ -194,6 +202,23 @@ void InputEventWithModifiers::set_modifiers_from_event(const InputEventWithModif set_meta_pressed(event->is_meta_pressed()); } +uint32_t InputEventWithModifiers::get_modifiers_mask() const { + uint32_t mask = 0; + if (is_ctrl_pressed()) { + mask |= KEY_MASK_CTRL; + } + if (is_shift_pressed()) { + mask |= KEY_MASK_SHIFT; + } + if (is_alt_pressed()) { + mask |= KEY_MASK_ALT; + } + if (is_meta_pressed()) { + mask |= KEY_MASK_META; + } + return mask; +} + String InputEventWithModifiers::as_text() const { Vector<String> mod_names; @@ -274,6 +299,7 @@ void InputEventWithModifiers::_validate_property(PropertyInfo &property) const { void InputEventKey::set_pressed(bool p_pressed) { pressed = p_pressed; + emit_changed(); } bool InputEventKey::is_pressed() const { @@ -282,6 +308,7 @@ bool InputEventKey::is_pressed() const { void InputEventKey::set_keycode(uint32_t p_keycode) { keycode = p_keycode; + emit_changed(); } uint32_t InputEventKey::get_keycode() const { @@ -290,6 +317,7 @@ uint32_t InputEventKey::get_keycode() const { void InputEventKey::set_physical_keycode(uint32_t p_keycode) { physical_keycode = p_keycode; + emit_changed(); } uint32_t InputEventKey::get_physical_keycode() const { @@ -298,6 +326,7 @@ uint32_t InputEventKey::get_physical_keycode() const { void InputEventKey::set_unicode(uint32_t p_unicode) { unicode = p_unicode; + emit_changed(); } uint32_t InputEventKey::get_unicode() const { @@ -306,6 +335,7 @@ uint32_t InputEventKey::get_unicode() const { void InputEventKey::set_echo(bool p_enable) { echo = p_enable; + emit_changed(); } bool InputEventKey::is_echo() const { @@ -313,39 +343,11 @@ bool InputEventKey::is_echo() const { } uint32_t InputEventKey::get_keycode_with_modifiers() const { - uint32_t sc = keycode; - if (is_ctrl_pressed()) { - sc |= KEY_MASK_CTRL; - } - if (is_alt_pressed()) { - sc |= KEY_MASK_ALT; - } - if (is_shift_pressed()) { - sc |= KEY_MASK_SHIFT; - } - if (is_meta_pressed()) { - sc |= KEY_MASK_META; - } - - return sc; + return keycode | get_modifiers_mask(); } uint32_t InputEventKey::get_physical_keycode_with_modifiers() const { - uint32_t sc = physical_keycode; - if (is_ctrl_pressed()) { - sc |= KEY_MASK_CTRL; - } - if (is_alt_pressed()) { - sc |= KEY_MASK_ALT; - } - if (is_shift_pressed()) { - sc |= KEY_MASK_SHIFT; - } - if (is_meta_pressed()) { - sc |= KEY_MASK_META; - } - - return sc; + return physical_keycode | get_modifiers_mask(); } String InputEventKey::as_text() const { @@ -386,7 +388,7 @@ String InputEventKey::to_string() { Ref<InputEventKey> InputEventKey::create_reference(uint32_t p_keycode) { Ref<InputEventKey> ie; - ie.instance(); + ie.instantiate(); ie->set_keycode(p_keycode & KEY_CODE_MASK); ie->set_unicode(p_keycode & KEY_CODE_MASK); @@ -442,16 +444,14 @@ bool InputEventKey::action_match(const Ref<InputEvent> &p_event, bool *p_pressed return match; } -bool InputEventKey::shortcut_match(const Ref<InputEvent> &p_event) const { +bool InputEventKey::is_match(const Ref<InputEvent> &p_event, bool p_exact_match) const { Ref<InputEventKey> key = p_event; if (key.is_null()) { return false; } - uint32_t code = get_keycode_with_modifiers(); - uint32_t event_code = key->get_keycode_with_modifiers(); - - return code == event_code; + return keycode == key->keycode && + (!p_exact_match || get_modifiers_mask() == key->get_modifiers_mask()); } void InputEventKey::_bind_methods() { @@ -482,6 +482,7 @@ void InputEventKey::_bind_methods() { void InputEventMouse::set_button_mask(int p_mask) { button_mask = p_mask; + emit_changed(); } int InputEventMouse::get_button_mask() const { @@ -529,11 +530,12 @@ float InputEventMouseButton::get_factor() const { return factor; } -void InputEventMouseButton::set_button_index(int p_index) { +void InputEventMouseButton::set_button_index(MouseButton p_index) { button_index = p_index; + emit_changed(); } -int InputEventMouseButton::get_button_index() const { +MouseButton InputEventMouseButton::get_button_index() const { return button_index; } @@ -558,7 +560,7 @@ Ref<InputEvent> InputEventMouseButton::xformed_by(const Transform2D &p_xform, co Vector2 l = p_xform.xform(get_position() + p_local_ofs); Ref<InputEventMouseButton> mb; - mb.instance(); + mb.instantiate(); mb->set_device(get_device()); mb->set_window_id(get_window_id()); @@ -599,6 +601,16 @@ bool InputEventMouseButton::action_match(const Ref<InputEvent> &p_event, bool *p return match; } +bool InputEventMouseButton::is_match(const Ref<InputEvent> &p_event, bool p_exact_match) const { + Ref<InputEventMouseButton> mb = p_event; + if (mb.is_null()) { + return false; + } + + return button_index == mb->button_index && + (!p_exact_match || get_modifiers_mask() == mb->get_modifiers_mask()); +} + static const char *_mouse_button_descriptions[9] = { TTRC("Left Mouse Button"), TTRC("Right Mouse Button"), @@ -734,7 +746,7 @@ Ref<InputEvent> InputEventMouseMotion::xformed_by(const Transform2D &p_xform, co Vector2 s = p_xform.basis_xform(get_speed()); Ref<InputEventMouseMotion> mm; - mm.instance(); + mm.instantiate(); mm->set_device(get_device()); mm->set_window_id(get_window_id()); @@ -848,16 +860,18 @@ void InputEventMouseMotion::_bind_methods() { /////////////////////////////////// -void InputEventJoypadMotion::set_axis(int p_axis) { +void InputEventJoypadMotion::set_axis(JoyAxis p_axis) { axis = p_axis; + emit_changed(); } -int InputEventJoypadMotion::get_axis() const { +JoyAxis InputEventJoypadMotion::get_axis() const { return axis; } void InputEventJoypadMotion::set_axis_value(float p_value) { axis_value = p_value; + emit_changed(); } float InputEventJoypadMotion::get_axis_value() const { @@ -904,6 +918,16 @@ bool InputEventJoypadMotion::action_match(const Ref<InputEvent> &p_event, bool * return match; } +bool InputEventJoypadMotion::is_match(const Ref<InputEvent> &p_event, bool p_exact_match) const { + Ref<InputEventJoypadMotion> jm = p_event; + if (jm.is_null()) { + return false; + } + + return axis == jm->axis && + (!p_exact_match || ((axis_value < 0) == (jm->axis_value < 0))); +} + static const char *_joy_axis_descriptions[JOY_AXIS_MAX] = { TTRC("Left Stick X-Axis, Joystick 0 X-Axis"), TTRC("Left Stick Y-Axis, Joystick 0 Y-Axis"), @@ -940,11 +964,12 @@ void InputEventJoypadMotion::_bind_methods() { /////////////////////////////////// -void InputEventJoypadButton::set_button_index(int p_index) { +void InputEventJoypadButton::set_button_index(JoyButton p_index) { button_index = p_index; + emit_changed(); } -int InputEventJoypadButton::get_button_index() const { +JoyButton InputEventJoypadButton::get_button_index() const { return button_index; } @@ -987,7 +1012,7 @@ bool InputEventJoypadButton::action_match(const Ref<InputEvent> &p_event, bool * return match; } -bool InputEventJoypadButton::shortcut_match(const Ref<InputEvent> &p_event) const { +bool InputEventJoypadButton::is_match(const Ref<InputEvent> &p_event, bool p_exact_match) const { Ref<InputEventJoypadButton> button = p_event; if (button.is_null()) { return false; @@ -1039,9 +1064,9 @@ String InputEventJoypadButton::to_string() { return vformat("InputEventJoypadButton: button_index=%d, pressed=%s, pressure=%.2f", button_index, p, pressure); } -Ref<InputEventJoypadButton> InputEventJoypadButton::create_reference(int p_btn_index) { +Ref<InputEventJoypadButton> InputEventJoypadButton::create_reference(JoyButton p_btn_index) { Ref<InputEventJoypadButton> ie; - ie.instance(); + ie.instantiate(); ie->set_button_index(p_btn_index); return ie; @@ -1090,7 +1115,7 @@ bool InputEventScreenTouch::is_pressed() const { Ref<InputEvent> InputEventScreenTouch::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const { Ref<InputEventScreenTouch> st; - st.instance(); + st.instantiate(); st->set_device(get_device()); st->set_window_id(get_window_id()); st->set_index(index); @@ -1163,7 +1188,7 @@ Vector2 InputEventScreenDrag::get_speed() const { Ref<InputEvent> InputEventScreenDrag::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const { Ref<InputEventScreenDrag> sd; - sd.instance(); + sd.instantiate(); sd->set_device(get_device()); sd->set_window_id(get_window_id()); @@ -1229,7 +1254,7 @@ float InputEventAction::get_strength() const { return strength; } -bool InputEventAction::shortcut_match(const Ref<InputEvent> &p_event) const { +bool InputEventAction::is_match(const Ref<InputEvent> &p_event, bool p_exact_match) const { if (p_event.is_null()) { return false; } @@ -1318,7 +1343,7 @@ real_t InputEventMagnifyGesture::get_factor() const { Ref<InputEvent> InputEventMagnifyGesture::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const { Ref<InputEventMagnifyGesture> ev; - ev.instance(); + ev.instantiate(); ev->set_device(get_device()); ev->set_window_id(get_window_id()); @@ -1358,7 +1383,7 @@ Vector2 InputEventPanGesture::get_delta() const { Ref<InputEvent> InputEventPanGesture::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const { Ref<InputEventPanGesture> ev; - ev.instance(); + ev.instantiate(); ev->set_device(get_device()); ev->set_window_id(get_window_id()); @@ -1396,11 +1421,11 @@ int InputEventMIDI::get_channel() const { return channel; } -void InputEventMIDI::set_message(const int p_message) { +void InputEventMIDI::set_message(const MIDIMessage p_message) { message = p_message; } -int InputEventMIDI::get_message() const { +MIDIMessage InputEventMIDI::get_message() const { return message; } diff --git a/core/input/input_event.h b/core/input/input_event.h index eed0d79326..76a45c04a4 100644 --- a/core/input/input_event.h +++ b/core/input/input_event.h @@ -31,6 +31,7 @@ #ifndef INPUT_EVENT_H #define INPUT_EVENT_H +#include "core/input/input_enums.h" #include "core/io/resource.h" #include "core/math/transform_2d.h" #include "core/string/ustring.h" @@ -41,72 +42,6 @@ * The events are pretty obvious. */ -enum MouseButton { - MOUSE_BUTTON_LEFT = 1, - MOUSE_BUTTON_RIGHT = 2, - MOUSE_BUTTON_MIDDLE = 3, - MOUSE_BUTTON_WHEEL_UP = 4, - MOUSE_BUTTON_WHEEL_DOWN = 5, - MOUSE_BUTTON_WHEEL_LEFT = 6, - MOUSE_BUTTON_WHEEL_RIGHT = 7, - MOUSE_BUTTON_XBUTTON1 = 8, - MOUSE_BUTTON_XBUTTON2 = 9, - MOUSE_BUTTON_MASK_LEFT = (1 << (MOUSE_BUTTON_LEFT - 1)), - MOUSE_BUTTON_MASK_RIGHT = (1 << (MOUSE_BUTTON_RIGHT - 1)), - MOUSE_BUTTON_MASK_MIDDLE = (1 << (MOUSE_BUTTON_MIDDLE - 1)), - MOUSE_BUTTON_MASK_XBUTTON1 = (1 << (MOUSE_BUTTON_XBUTTON1 - 1)), - MOUSE_BUTTON_MASK_XBUTTON2 = (1 << (MOUSE_BUTTON_XBUTTON2 - 1)) -}; - -enum JoyButton { - JOY_BUTTON_INVALID = -1, - JOY_BUTTON_A = 0, - JOY_BUTTON_B = 1, - JOY_BUTTON_X = 2, - JOY_BUTTON_Y = 3, - JOY_BUTTON_BACK = 4, - JOY_BUTTON_GUIDE = 5, - JOY_BUTTON_START = 6, - JOY_BUTTON_LEFT_STICK = 7, - JOY_BUTTON_RIGHT_STICK = 8, - JOY_BUTTON_LEFT_SHOULDER = 9, - JOY_BUTTON_RIGHT_SHOULDER = 10, - JOY_BUTTON_DPAD_UP = 11, - JOY_BUTTON_DPAD_DOWN = 12, - JOY_BUTTON_DPAD_LEFT = 13, - JOY_BUTTON_DPAD_RIGHT = 14, - JOY_BUTTON_MISC1 = 15, - JOY_BUTTON_PADDLE1 = 16, - JOY_BUTTON_PADDLE2 = 17, - JOY_BUTTON_PADDLE3 = 18, - JOY_BUTTON_PADDLE4 = 19, - JOY_BUTTON_TOUCHPAD = 20, - JOY_BUTTON_SDL_MAX = 21, - JOY_BUTTON_MAX = 36, // Android supports up to 36 buttons. -}; - -enum JoyAxis { - JOY_AXIS_INVALID = -1, - JOY_AXIS_LEFT_X = 0, - JOY_AXIS_LEFT_Y = 1, - JOY_AXIS_RIGHT_X = 2, - JOY_AXIS_RIGHT_Y = 3, - JOY_AXIS_TRIGGER_LEFT = 4, - JOY_AXIS_TRIGGER_RIGHT = 5, - JOY_AXIS_SDL_MAX = 6, - JOY_AXIS_MAX = 10, // OpenVR supports up to 5 Joysticks making a total of 10 axes. -}; - -enum MIDIMessage { - MIDI_MESSAGE_NOTE_OFF = 0x8, - MIDI_MESSAGE_NOTE_ON = 0x9, - MIDI_MESSAGE_AFTERTOUCH = 0xA, - MIDI_MESSAGE_CONTROL_CHANGE = 0xB, - MIDI_MESSAGE_PROGRAM_CHANGE = 0xC, - MIDI_MESSAGE_CHANNEL_PRESSURE = 0xD, - MIDI_MESSAGE_PITCH_BEND = 0xE, -}; - /** * Input Modifier Status * for keyboard/mouse events. @@ -142,7 +77,8 @@ public: virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const; virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const; - virtual bool shortcut_match(const Ref<InputEvent> &p_event) const; + virtual bool is_match(const Ref<InputEvent> &p_event, bool p_exact_match = true) const; + virtual bool is_action_type() const; virtual bool accumulate(const Ref<InputEvent> &p_event) { return false; } @@ -212,6 +148,8 @@ public: void set_modifiers_from_event(const InputEventWithModifiers *event); + uint32_t get_modifiers_mask() const; + virtual String as_text() const override; virtual String to_string() override; @@ -252,7 +190,7 @@ public: uint32_t get_physical_keycode_with_modifiers() const; virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const override; - virtual bool shortcut_match(const Ref<InputEvent> &p_event) const override; + virtual bool is_match(const Ref<InputEvent> &p_event, bool p_exact_match = true) const override; virtual bool is_action_type() const override { return true; } @@ -292,7 +230,7 @@ class InputEventMouseButton : public InputEventMouse { GDCLASS(InputEventMouseButton, InputEventMouse); float factor = 1; - int button_index = 0; + MouseButton button_index = MOUSE_BUTTON_NONE; bool pressed = false; //otherwise released bool double_click = false; //last even less than double click time @@ -303,8 +241,8 @@ public: void set_factor(float p_factor); float get_factor() const; - void set_button_index(int p_index); - int get_button_index() const; + void set_button_index(MouseButton p_index); + MouseButton get_button_index() const; void set_pressed(bool p_pressed); virtual bool is_pressed() const override; @@ -313,7 +251,9 @@ public: bool is_double_click() const; virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const override; + virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const override; + virtual bool is_match(const Ref<InputEvent> &p_event, bool p_exact_match = true) const override; virtual bool is_action_type() const override { return true; } virtual String as_text() const override; @@ -357,15 +297,15 @@ public: class InputEventJoypadMotion : public InputEvent { GDCLASS(InputEventJoypadMotion, InputEvent); - int axis = 0; ///< Joypad axis + JoyAxis axis = (JoyAxis)0; ///< Joypad axis float axis_value = 0; ///< -1 to 1 protected: static void _bind_methods(); public: - void set_axis(int p_axis); - int get_axis() const; + void set_axis(JoyAxis p_axis); + JoyAxis get_axis() const; void set_axis_value(float p_value); float get_axis_value() const; @@ -373,6 +313,7 @@ public: virtual bool is_pressed() const override; virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const override; + virtual bool is_match(const Ref<InputEvent> &p_event, bool p_exact_match = true) const override; virtual bool is_action_type() const override { return true; } virtual String as_text() const override; @@ -384,15 +325,15 @@ public: class InputEventJoypadButton : public InputEvent { GDCLASS(InputEventJoypadButton, InputEvent); - int button_index = 0; + JoyButton button_index = (JoyButton)0; bool pressed = false; float pressure = 0; //0 to 1 protected: static void _bind_methods(); public: - void set_button_index(int p_index); - int get_button_index() const; + void set_button_index(JoyButton p_index); + JoyButton get_button_index() const; void set_pressed(bool p_pressed); virtual bool is_pressed() const override; @@ -401,13 +342,14 @@ public: float get_pressure() const; virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const override; - virtual bool shortcut_match(const Ref<InputEvent> &p_event) const override; + virtual bool is_match(const Ref<InputEvent> &p_event, bool p_exact_match = true) const override; virtual bool is_action_type() const override { return true; } + virtual String as_text() const override; virtual String to_string() override; - static Ref<InputEventJoypadButton> create_reference(int p_btn_index); + static Ref<InputEventJoypadButton> create_reference(JoyButton p_btn_index); InputEventJoypadButton() {} }; @@ -491,9 +433,10 @@ public: virtual bool is_action(const StringName &p_action) const; virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const override; + virtual bool is_match(const Ref<InputEvent> &p_event, bool p_exact_match = true) const override; - virtual bool shortcut_match(const Ref<InputEvent> &p_event) const override; virtual bool is_action_type() const override { return true; } + virtual String as_text() const override; virtual String to_string() override; @@ -553,7 +496,7 @@ class InputEventMIDI : public InputEvent { GDCLASS(InputEventMIDI, InputEvent); int channel = 0; - int message = 0; + MIDIMessage message = MIDI_MESSAGE_NONE; int pitch = 0; int velocity = 0; int instrument = 0; @@ -568,8 +511,8 @@ public: void set_channel(const int p_channel); int get_channel() const; - void set_message(const int p_message); - int get_message() const; + void set_message(const MIDIMessage p_message); + MIDIMessage get_message() const; void set_pitch(const int p_pitch); int get_pitch() const; diff --git a/core/input/input_map.cpp b/core/input/input_map.cpp index c43fd64561..b5f067d499 100644 --- a/core/input/input_map.cpp +++ b/core/input/input_map.cpp @@ -45,6 +45,7 @@ void InputMap::_bind_methods() { ClassDB::bind_method(D_METHOD("erase_action", "action"), &InputMap::erase_action); ClassDB::bind_method(D_METHOD("action_set_deadzone", "action", "deadzone"), &InputMap::action_set_deadzone); + ClassDB::bind_method(D_METHOD("action_get_deadzone", "action"), &InputMap::action_get_deadzone); ClassDB::bind_method(D_METHOD("action_add_event", "action", "event"), &InputMap::action_add_event); ClassDB::bind_method(D_METHOD("action_has_event", "action", "event"), &InputMap::action_has_event); ClassDB::bind_method(D_METHOD("action_erase_event", "action", "event"), &InputMap::action_erase_event); @@ -130,12 +131,9 @@ List<Ref<InputEvent>>::Element *InputMap::_find_event(Action &p_action, const Re for (List<Ref<InputEvent>>::Element *E = p_action.inputs.front(); E; E = E->next()) { const Ref<InputEvent> e = E->get(); - //if (e.type != Ref<InputEvent>::KEY && e.device != p_event.device) -- unsure about the KEY comparison, why is this here? - // continue; - int device = e->get_device(); if (device == ALL_DEVICES || device == p_event->get_device()) { - if (p_exact_match && e->shortcut_match(p_event)) { + if (p_exact_match && e->is_match(p_event, true)) { return E; } else if (!p_exact_match && e->action_match(p_event, p_pressed, p_strength, p_raw_strength, p_action.deadzone)) { return E; diff --git a/core/io/compression.cpp b/core/io/compression.cpp index 6de626db99..ca56509253 100644 --- a/core/io/compression.cpp +++ b/core/io/compression.cpp @@ -238,7 +238,10 @@ int Compression::decompress_dynamic(Vector<uint8_t> *p_dst_vect, int p_max_dst_s case Z_DATA_ERROR: case Z_MEM_ERROR: case Z_STREAM_ERROR: - WARN_PRINT(strm.msg); + case Z_BUF_ERROR: + if (strm.msg) { + WARN_PRINT(strm.msg); + } (void)inflateEnd(&strm); p_dst_vect->resize(0); return ret; diff --git a/core/io/file_access_network.cpp b/core/io/file_access_network.cpp index 63a8f9c5b6..9ee3876c2f 100644 --- a/core/io/file_access_network.cpp +++ b/core/io/file_access_network.cpp @@ -210,7 +210,7 @@ FileAccessNetworkClient *FileAccessNetworkClient::singleton = nullptr; FileAccessNetworkClient::FileAccessNetworkClient() { singleton = this; - client.instance(); + client.instantiate(); } FileAccessNetworkClient::~FileAccessNetworkClient() { diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp index 449ebaa6ee..8000dd4290 100644 --- a/core/io/http_client.cpp +++ b/core/io/http_client.cpp @@ -30,9 +30,6 @@ #include "http_client.h" -#include "core/io/stream_peer_ssl.h" -#include "core/version.h" - const char *HTTPClient::_methods[METHOD_MAX] = { "GET", "HEAD", @@ -45,698 +42,23 @@ const char *HTTPClient::_methods[METHOD_MAX] = { "PATCH" }; -#ifndef JAVASCRIPT_ENABLED -Error HTTPClient::connect_to_host(const String &p_host, int p_port, bool p_ssl, bool p_verify_host) { - close(); - - conn_port = p_port; - conn_host = p_host; - - ssl = p_ssl; - ssl_verify_host = p_verify_host; - - String host_lower = conn_host.to_lower(); - if (host_lower.begins_with("http://")) { - conn_host = conn_host.substr(7, conn_host.length() - 7); - } else if (host_lower.begins_with("https://")) { - ssl = true; - conn_host = conn_host.substr(8, conn_host.length() - 8); - } - - ERR_FAIL_COND_V(conn_host.length() < HOST_MIN_LEN, ERR_INVALID_PARAMETER); - - if (conn_port < 0) { - if (ssl) { - conn_port = PORT_HTTPS; - } else { - conn_port = PORT_HTTP; - } - } - - connection = tcp_connection; - - if (conn_host.is_valid_ip_address()) { - // Host contains valid IP - Error err = tcp_connection->connect_to_host(IPAddress(conn_host), p_port); - if (err) { - status = STATUS_CANT_CONNECT; - return err; - } - - status = STATUS_CONNECTING; - } else { - // Host contains hostname and needs to be resolved to IP - resolving = IP::get_singleton()->resolve_hostname_queue_item(conn_host); - status = STATUS_RESOLVING; +HTTPClient *HTTPClient::create() { + if (_create) { + return _create(); } - - return OK; + return nullptr; } -void HTTPClient::set_connection(const Ref<StreamPeer> &p_connection) { - ERR_FAIL_COND_MSG(p_connection.is_null(), "Connection is not a reference to a valid StreamPeer object."); - - if (ssl) { - ERR_FAIL_NULL_MSG(Object::cast_to<StreamPeerSSL>(p_connection.ptr()), - "Connection is not a reference to a valid StreamPeerSSL object."); - } - - if (connection == p_connection) { - return; - } - - close(); - connection = p_connection; - status = STATUS_CONNECTED; +Error HTTPClient::_request_raw(Method p_method, const String &p_url, const Vector<String> &p_headers, const Vector<uint8_t> &p_body) { + int size = p_body.size(); + return request(p_method, p_url, p_headers, size > 0 ? p_body.ptr() : nullptr, size); } -Ref<StreamPeer> HTTPClient::get_connection() const { - return connection; +Error HTTPClient::_request(Method p_method, const String &p_url, const Vector<String> &p_headers, const String &p_body) { + int size = p_body.length(); + return request(p_method, p_url, p_headers, size > 0 ? (const uint8_t *)p_body.utf8().get_data() : nullptr, size); } -static bool _check_request_url(HTTPClient::Method p_method, const String &p_url) { - switch (p_method) { - case HTTPClient::METHOD_CONNECT: { - // Authority in host:port format, as in RFC7231 - int pos = p_url.find_char(':'); - return 0 < pos && pos < p_url.length() - 1; - } - case HTTPClient::METHOD_OPTIONS: { - if (p_url == "*") { - return true; - } - [[fallthrough]]; - } - default: - // Absolute path or absolute URL - return p_url.begins_with("/") || p_url.begins_with("http://") || p_url.begins_with("https://"); - } -} - -Error HTTPClient::request_raw(Method p_method, const String &p_url, const Vector<String> &p_headers, const Vector<uint8_t> &p_body) { - ERR_FAIL_INDEX_V(p_method, METHOD_MAX, ERR_INVALID_PARAMETER); - ERR_FAIL_COND_V(!_check_request_url(p_method, p_url), ERR_INVALID_PARAMETER); - ERR_FAIL_COND_V(status != STATUS_CONNECTED, ERR_INVALID_PARAMETER); - ERR_FAIL_COND_V(connection.is_null(), ERR_INVALID_DATA); - - String request = String(_methods[p_method]) + " " + p_url + " HTTP/1.1\r\n"; - bool add_host = true; - bool add_clen = p_body.size() > 0; - bool add_uagent = true; - bool add_accept = true; - for (int i = 0; i < p_headers.size(); i++) { - request += p_headers[i] + "\r\n"; - if (add_host && p_headers[i].findn("Host:") == 0) { - add_host = false; - } - if (add_clen && p_headers[i].findn("Content-Length:") == 0) { - add_clen = false; - } - if (add_uagent && p_headers[i].findn("User-Agent:") == 0) { - add_uagent = false; - } - if (add_accept && p_headers[i].findn("Accept:") == 0) { - add_accept = false; - } - } - if (add_host) { - if ((ssl && conn_port == PORT_HTTPS) || (!ssl && conn_port == PORT_HTTP)) { - // Don't append the standard ports - request += "Host: " + conn_host + "\r\n"; - } else { - request += "Host: " + conn_host + ":" + itos(conn_port) + "\r\n"; - } - } - if (add_clen) { - request += "Content-Length: " + itos(p_body.size()) + "\r\n"; - // Should it add utf8 encoding? - } - if (add_uagent) { - request += "User-Agent: GodotEngine/" + String(VERSION_FULL_BUILD) + " (" + OS::get_singleton()->get_name() + ")\r\n"; - } - if (add_accept) { - request += "Accept: */*\r\n"; - } - request += "\r\n"; - CharString cs = request.utf8(); - - Vector<uint8_t> data; - data.resize(cs.length()); - { - uint8_t *data_write = data.ptrw(); - for (int i = 0; i < cs.length(); i++) { - data_write[i] = cs[i]; - } - } - - data.append_array(p_body); - - const uint8_t *r = data.ptr(); - Error err = connection->put_data(&r[0], data.size()); - - if (err) { - close(); - status = STATUS_CONNECTION_ERROR; - return err; - } - - status = STATUS_REQUESTING; - head_request = p_method == METHOD_HEAD; - - return OK; -} - -Error HTTPClient::request(Method p_method, const String &p_url, const Vector<String> &p_headers, const String &p_body) { - ERR_FAIL_INDEX_V(p_method, METHOD_MAX, ERR_INVALID_PARAMETER); - ERR_FAIL_COND_V(!_check_request_url(p_method, p_url), ERR_INVALID_PARAMETER); - ERR_FAIL_COND_V(status != STATUS_CONNECTED, ERR_INVALID_PARAMETER); - ERR_FAIL_COND_V(connection.is_null(), ERR_INVALID_DATA); - - String request = String(_methods[p_method]) + " " + p_url + " HTTP/1.1\r\n"; - bool add_host = true; - bool add_uagent = true; - bool add_accept = true; - bool add_clen = p_body.length() > 0; - for (int i = 0; i < p_headers.size(); i++) { - request += p_headers[i] + "\r\n"; - if (add_host && p_headers[i].findn("Host:") == 0) { - add_host = false; - } - if (add_clen && p_headers[i].findn("Content-Length:") == 0) { - add_clen = false; - } - if (add_uagent && p_headers[i].findn("User-Agent:") == 0) { - add_uagent = false; - } - if (add_accept && p_headers[i].findn("Accept:") == 0) { - add_accept = false; - } - } - if (add_host) { - if ((ssl && conn_port == PORT_HTTPS) || (!ssl && conn_port == PORT_HTTP)) { - // Don't append the standard ports - request += "Host: " + conn_host + "\r\n"; - } else { - request += "Host: " + conn_host + ":" + itos(conn_port) + "\r\n"; - } - } - if (add_clen) { - request += "Content-Length: " + itos(p_body.utf8().length()) + "\r\n"; - // Should it add utf8 encoding? - } - if (add_uagent) { - request += "User-Agent: GodotEngine/" + String(VERSION_FULL_BUILD) + " (" + OS::get_singleton()->get_name() + ")\r\n"; - } - if (add_accept) { - request += "Accept: */*\r\n"; - } - request += "\r\n"; - request += p_body; - - CharString cs = request.utf8(); - Error err = connection->put_data((const uint8_t *)cs.ptr(), cs.length()); - if (err) { - close(); - status = STATUS_CONNECTION_ERROR; - return err; - } - - status = STATUS_REQUESTING; - head_request = p_method == METHOD_HEAD; - - return OK; -} - -bool HTTPClient::has_response() const { - return response_headers.size() != 0; -} - -bool HTTPClient::is_response_chunked() const { - return chunked; -} - -int HTTPClient::get_response_code() const { - return response_num; -} - -Error HTTPClient::get_response_headers(List<String> *r_response) { - if (!response_headers.size()) { - return ERR_INVALID_PARAMETER; - } - - for (int i = 0; i < response_headers.size(); i++) { - r_response->push_back(response_headers[i]); - } - - response_headers.clear(); - - return OK; -} - -void HTTPClient::close() { - if (tcp_connection->get_status() != StreamPeerTCP::STATUS_NONE) { - tcp_connection->disconnect_from_host(); - } - - connection.unref(); - status = STATUS_DISCONNECTED; - head_request = false; - if (resolving != IP::RESOLVER_INVALID_ID) { - IP::get_singleton()->erase_resolve_item(resolving); - resolving = IP::RESOLVER_INVALID_ID; - } - - response_headers.clear(); - response_str.clear(); - body_size = -1; - body_left = 0; - chunk_left = 0; - chunk_trailer_part = false; - read_until_eof = false; - response_num = 0; - handshaking = false; -} - -Error HTTPClient::poll() { - switch (status) { - case STATUS_RESOLVING: { - ERR_FAIL_COND_V(resolving == IP::RESOLVER_INVALID_ID, ERR_BUG); - - IP::ResolverStatus rstatus = IP::get_singleton()->get_resolve_item_status(resolving); - switch (rstatus) { - case IP::RESOLVER_STATUS_WAITING: - return OK; // Still resolving - - case IP::RESOLVER_STATUS_DONE: { - IPAddress host = IP::get_singleton()->get_resolve_item_address(resolving); - Error err = tcp_connection->connect_to_host(host, conn_port); - IP::get_singleton()->erase_resolve_item(resolving); - resolving = IP::RESOLVER_INVALID_ID; - if (err) { - status = STATUS_CANT_CONNECT; - return err; - } - - status = STATUS_CONNECTING; - } break; - case IP::RESOLVER_STATUS_NONE: - case IP::RESOLVER_STATUS_ERROR: { - IP::get_singleton()->erase_resolve_item(resolving); - resolving = IP::RESOLVER_INVALID_ID; - close(); - status = STATUS_CANT_RESOLVE; - return ERR_CANT_RESOLVE; - } break; - } - } break; - case STATUS_CONNECTING: { - StreamPeerTCP::Status s = tcp_connection->get_status(); - switch (s) { - case StreamPeerTCP::STATUS_CONNECTING: { - return OK; - } break; - case StreamPeerTCP::STATUS_CONNECTED: { - if (ssl) { - Ref<StreamPeerSSL> ssl; - if (!handshaking) { - // Connect the StreamPeerSSL and start handshaking - ssl = Ref<StreamPeerSSL>(StreamPeerSSL::create()); - ssl->set_blocking_handshake_enabled(false); - Error err = ssl->connect_to_stream(tcp_connection, ssl_verify_host, conn_host); - if (err != OK) { - close(); - status = STATUS_SSL_HANDSHAKE_ERROR; - return ERR_CANT_CONNECT; - } - connection = ssl; - handshaking = true; - } else { - // We are already handshaking, which means we can use your already active SSL connection - ssl = static_cast<Ref<StreamPeerSSL>>(connection); - if (ssl.is_null()) { - close(); - status = STATUS_SSL_HANDSHAKE_ERROR; - return ERR_CANT_CONNECT; - } - - ssl->poll(); // Try to finish the handshake - } - - if (ssl->get_status() == StreamPeerSSL::STATUS_CONNECTED) { - // Handshake has been successful - handshaking = false; - status = STATUS_CONNECTED; - return OK; - } else if (ssl->get_status() != StreamPeerSSL::STATUS_HANDSHAKING) { - // Handshake has failed - close(); - status = STATUS_SSL_HANDSHAKE_ERROR; - return ERR_CANT_CONNECT; - } - // ... we will need to poll more for handshake to finish - } else { - status = STATUS_CONNECTED; - } - return OK; - } break; - case StreamPeerTCP::STATUS_ERROR: - case StreamPeerTCP::STATUS_NONE: { - close(); - status = STATUS_CANT_CONNECT; - return ERR_CANT_CONNECT; - } break; - } - } break; - case STATUS_BODY: - case STATUS_CONNECTED: { - // Check if we are still connected - if (ssl) { - Ref<StreamPeerSSL> tmp = connection; - tmp->poll(); - if (tmp->get_status() != StreamPeerSSL::STATUS_CONNECTED) { - status = STATUS_CONNECTION_ERROR; - return ERR_CONNECTION_ERROR; - } - } else if (tcp_connection->get_status() != StreamPeerTCP::STATUS_CONNECTED) { - status = STATUS_CONNECTION_ERROR; - return ERR_CONNECTION_ERROR; - } - // Connection established, requests can now be made - return OK; - } break; - case STATUS_REQUESTING: { - while (true) { - uint8_t byte; - int rec = 0; - Error err = _get_http_data(&byte, 1, rec); - if (err != OK) { - close(); - status = STATUS_CONNECTION_ERROR; - return ERR_CONNECTION_ERROR; - } - - if (rec == 0) { - return OK; // Still requesting, keep trying! - } - - response_str.push_back(byte); - int rs = response_str.size(); - if ( - (rs >= 2 && response_str[rs - 2] == '\n' && response_str[rs - 1] == '\n') || - (rs >= 4 && response_str[rs - 4] == '\r' && response_str[rs - 3] == '\n' && response_str[rs - 2] == '\r' && response_str[rs - 1] == '\n')) { - // End of response, parse. - response_str.push_back(0); - String response; - response.parse_utf8((const char *)response_str.ptr()); - Vector<String> responses = response.split("\n"); - body_size = -1; - chunked = false; - body_left = 0; - chunk_left = 0; - chunk_trailer_part = false; - read_until_eof = false; - response_str.clear(); - response_headers.clear(); - response_num = RESPONSE_OK; - - // Per the HTTP 1.1 spec, keep-alive is the default. - // Not following that specification breaks standard implementations. - // Broken web servers should be fixed. - bool keep_alive = true; - - for (int i = 0; i < responses.size(); i++) { - String header = responses[i].strip_edges(); - String s = header.to_lower(); - if (s.length() == 0) { - continue; - } - if (s.begins_with("content-length:")) { - body_size = s.substr(s.find(":") + 1, s.length()).strip_edges().to_int(); - body_left = body_size; - - } else if (s.begins_with("transfer-encoding:")) { - String encoding = header.substr(header.find(":") + 1, header.length()).strip_edges(); - if (encoding == "chunked") { - chunked = true; - } - } else if (s.begins_with("connection: close")) { - keep_alive = false; - } - - if (i == 0 && responses[i].begins_with("HTTP")) { - String num = responses[i].get_slicec(' ', 1); - response_num = num.to_int(); - } else { - response_headers.push_back(header); - } - } - - // This is a HEAD request, we won't receive anything. - if (head_request) { - body_size = 0; - body_left = 0; - } - - if (body_size != -1 || chunked) { - status = STATUS_BODY; - } else if (!keep_alive) { - read_until_eof = true; - status = STATUS_BODY; - } else { - status = STATUS_CONNECTED; - } - return OK; - } - } - } break; - case STATUS_DISCONNECTED: { - return ERR_UNCONFIGURED; - } break; - case STATUS_CONNECTION_ERROR: - case STATUS_SSL_HANDSHAKE_ERROR: { - return ERR_CONNECTION_ERROR; - } break; - case STATUS_CANT_CONNECT: { - return ERR_CANT_CONNECT; - } break; - case STATUS_CANT_RESOLVE: { - return ERR_CANT_RESOLVE; - } break; - } - - return OK; -} - -int HTTPClient::get_response_body_length() const { - return body_size; -} - -PackedByteArray HTTPClient::read_response_body_chunk() { - ERR_FAIL_COND_V(status != STATUS_BODY, PackedByteArray()); - - PackedByteArray ret; - Error err = OK; - - if (chunked) { - while (true) { - if (chunk_trailer_part) { - // We need to consume the trailer part too or keep-alive will break - uint8_t b; - int rec = 0; - err = _get_http_data(&b, 1, rec); - - if (rec == 0) { - break; - } - - chunk.push_back(b); - int cs = chunk.size(); - if ((cs >= 2 && chunk[cs - 2] == '\r' && chunk[cs - 1] == '\n')) { - if (cs == 2) { - // Finally over - chunk_trailer_part = false; - status = STATUS_CONNECTED; - chunk.clear(); - break; - } else { - // We do not process nor return the trailer data - chunk.clear(); - } - } - } else if (chunk_left == 0) { - // Reading length - uint8_t b; - int rec = 0; - err = _get_http_data(&b, 1, rec); - - if (rec == 0) { - break; - } - - chunk.push_back(b); - - if (chunk.size() > 32) { - ERR_PRINT("HTTP Invalid chunk hex len"); - status = STATUS_CONNECTION_ERROR; - break; - } - - if (chunk.size() > 2 && chunk[chunk.size() - 2] == '\r' && chunk[chunk.size() - 1] == '\n') { - int len = 0; - for (int i = 0; i < chunk.size() - 2; i++) { - char c = chunk[i]; - int v = 0; - if (c >= '0' && c <= '9') { - v = c - '0'; - } else if (c >= 'a' && c <= 'f') { - v = c - 'a' + 10; - } else if (c >= 'A' && c <= 'F') { - v = c - 'A' + 10; - } else { - ERR_PRINT("HTTP Chunk len not in hex!!"); - status = STATUS_CONNECTION_ERROR; - break; - } - len <<= 4; - len |= v; - if (len > (1 << 24)) { - ERR_PRINT("HTTP Chunk too big!! >16mb"); - status = STATUS_CONNECTION_ERROR; - break; - } - } - - if (len == 0) { - // End reached! - chunk_trailer_part = true; - chunk.clear(); - break; - } - - chunk_left = len + 2; - chunk.resize(chunk_left); - } - } else { - int rec = 0; - err = _get_http_data(&chunk.write[chunk.size() - chunk_left], chunk_left, rec); - if (rec == 0) { - break; - } - chunk_left -= rec; - - if (chunk_left == 0) { - if (chunk[chunk.size() - 2] != '\r' || chunk[chunk.size() - 1] != '\n') { - ERR_PRINT("HTTP Invalid chunk terminator (not \\r\\n)"); - status = STATUS_CONNECTION_ERROR; - break; - } - - ret.resize(chunk.size() - 2); - uint8_t *w = ret.ptrw(); - memcpy(w, chunk.ptr(), chunk.size() - 2); - chunk.clear(); - } - - break; - } - } - - } else { - int to_read = !read_until_eof ? MIN(body_left, read_chunk_size) : read_chunk_size; - ret.resize(to_read); - int _offset = 0; - while (to_read > 0) { - int rec = 0; - { - uint8_t *w = ret.ptrw(); - err = _get_http_data(w + _offset, to_read, rec); - } - if (rec <= 0) { // Ended up reading less - ret.resize(_offset); - break; - } else { - _offset += rec; - to_read -= rec; - if (!read_until_eof) { - body_left -= rec; - } - } - if (err != OK) { - break; - } - } - } - - if (err != OK) { - close(); - - if (err == ERR_FILE_EOF) { - status = STATUS_DISCONNECTED; // Server disconnected - } else { - status = STATUS_CONNECTION_ERROR; - } - } else if (body_left == 0 && !chunked && !read_until_eof) { - status = STATUS_CONNECTED; - } - - return ret; -} - -HTTPClient::Status HTTPClient::get_status() const { - return status; -} - -void HTTPClient::set_blocking_mode(bool p_enable) { - blocking = p_enable; -} - -bool HTTPClient::is_blocking_mode_enabled() const { - return blocking; -} - -Error HTTPClient::_get_http_data(uint8_t *p_buffer, int p_bytes, int &r_received) { - if (blocking) { - // We can't use StreamPeer.get_data, since when reaching EOF we will get an - // error without knowing how many bytes we received. - Error err = ERR_FILE_EOF; - int read = 0; - int left = p_bytes; - r_received = 0; - while (left > 0) { - err = connection->get_partial_data(p_buffer + r_received, left, read); - if (err == OK) { - r_received += read; - } else if (err == ERR_FILE_EOF) { - r_received += read; - return err; - } else { - return err; - } - left -= read; - } - return err; - } else { - return connection->get_partial_data(p_buffer, p_bytes, r_received); - } -} - -void HTTPClient::set_read_chunk_size(int p_size) { - ERR_FAIL_COND(p_size < 256 || p_size > (1 << 24)); - read_chunk_size = p_size; -} - -int HTTPClient::get_read_chunk_size() const { - return read_chunk_size; -} - -HTTPClient::HTTPClient() { - tcp_connection.instance(); -} - -HTTPClient::~HTTPClient() {} - -#endif // #ifndef JAVASCRIPT_ENABLED - String HTTPClient::query_string_from_dict(const Dictionary &p_dict) { String query = ""; Array keys = p_dict.keys(); @@ -802,8 +124,8 @@ void HTTPClient::_bind_methods() { ClassDB::bind_method(D_METHOD("connect_to_host", "host", "port", "use_ssl", "verify_host"), &HTTPClient::connect_to_host, DEFVAL(-1), DEFVAL(false), DEFVAL(true)); ClassDB::bind_method(D_METHOD("set_connection", "connection"), &HTTPClient::set_connection); ClassDB::bind_method(D_METHOD("get_connection"), &HTTPClient::get_connection); - ClassDB::bind_method(D_METHOD("request_raw", "method", "url", "headers", "body"), &HTTPClient::request_raw); - ClassDB::bind_method(D_METHOD("request", "method", "url", "headers", "body"), &HTTPClient::request, DEFVAL(String())); + ClassDB::bind_method(D_METHOD("request_raw", "method", "url", "headers", "body"), &HTTPClient::_request_raw); + ClassDB::bind_method(D_METHOD("request", "method", "url", "headers", "body"), &HTTPClient::_request, DEFVAL(String())); ClassDB::bind_method(D_METHOD("close"), &HTTPClient::close); ClassDB::bind_method(D_METHOD("has_response"), &HTTPClient::has_response); diff --git a/core/io/http_client.h b/core/io/http_client.h index f70999836f..718c3a905e 100644 --- a/core/io/http_client.h +++ b/core/io/http_client.h @@ -142,7 +142,7 @@ public: }; -private: +protected: static const char *_methods[METHOD_MAX]; static const int HOST_MIN_LEN = 4; @@ -152,79 +152,48 @@ private: }; -#ifndef JAVASCRIPT_ENABLED - Status status = STATUS_DISCONNECTED; - IP::ResolverID resolving = IP::RESOLVER_INVALID_ID; - int conn_port = -1; - String conn_host; - bool ssl = false; - bool ssl_verify_host = false; - bool blocking = false; - bool handshaking = false; - bool head_request = false; - - Vector<uint8_t> response_str; - - bool chunked = false; - Vector<uint8_t> chunk; - int chunk_left = 0; - bool chunk_trailer_part = false; - int body_size = -1; - int body_left = 0; - bool read_until_eof = false; - - Ref<StreamPeerTCP> tcp_connection; - Ref<StreamPeer> connection; - - int response_num = 0; - Vector<String> response_headers; - // 64 KiB by default (favors fast download speeds at the cost of memory usage). - int read_chunk_size = 65536; - - Error _get_http_data(uint8_t *p_buffer, int p_bytes, int &r_received); - -#else -#include "platform/javascript/http_client.h.inc" -#endif - PackedStringArray _get_response_headers(); Dictionary _get_response_headers_as_dictionary(); + Error _request_raw(Method p_method, const String &p_url, const Vector<String> &p_headers, const Vector<uint8_t> &p_body); + Error _request(Method p_method, const String &p_url, const Vector<String> &p_headers, const String &p_body = String()); + + static HTTPClient *(*_create)(); static void _bind_methods(); public: - Error connect_to_host(const String &p_host, int p_port = -1, bool p_ssl = false, bool p_verify_host = true); + static HTTPClient *create(); - void set_connection(const Ref<StreamPeer> &p_connection); - Ref<StreamPeer> get_connection() const; + String query_string_from_dict(const Dictionary &p_dict); - Error request_raw(Method p_method, const String &p_url, const Vector<String> &p_headers, const Vector<uint8_t> &p_body); - Error request(Method p_method, const String &p_url, const Vector<String> &p_headers, const String &p_body = String()); + virtual Error request(Method p_method, const String &p_url, const Vector<String> &p_headers, const uint8_t *p_body, int p_body_size) = 0; + virtual Error connect_to_host(const String &p_host, int p_port = -1, bool p_ssl = false, bool p_verify_host = true) = 0; - void close(); + virtual void set_connection(const Ref<StreamPeer> &p_connection) = 0; + virtual Ref<StreamPeer> get_connection() const = 0; - Status get_status() const; + virtual void close() = 0; - bool has_response() const; - bool is_response_chunked() const; - int get_response_code() const; - Error get_response_headers(List<String> *r_response); - int get_response_body_length() const; + virtual Status get_status() const = 0; - PackedByteArray read_response_body_chunk(); // Can't get body as partial text because of most encodings UTF8, gzip, etc. + virtual bool has_response() const = 0; + virtual bool is_response_chunked() const = 0; + virtual int get_response_code() const = 0; + virtual Error get_response_headers(List<String> *r_response) = 0; + virtual int get_response_body_length() const = 0; - void set_blocking_mode(bool p_enable); // Useful mostly if running in a thread - bool is_blocking_mode_enabled() const; + virtual PackedByteArray read_response_body_chunk() = 0; // Can't get body as partial text because of most encodings UTF8, gzip, etc. - void set_read_chunk_size(int p_size); - int get_read_chunk_size() const; + virtual void set_blocking_mode(bool p_enable) = 0; // Useful mostly if running in a thread + virtual bool is_blocking_mode_enabled() const = 0; - Error poll(); + virtual void set_read_chunk_size(int p_size) = 0; + virtual int get_read_chunk_size() const = 0; - String query_string_from_dict(const Dictionary &p_dict); + virtual Error poll() = 0; - HTTPClient(); - ~HTTPClient(); + HTTPClient() {} + virtual ~HTTPClient() {} }; VARIANT_ENUM_CAST(HTTPClient::ResponseCode) diff --git a/core/io/http_client_tcp.cpp b/core/io/http_client_tcp.cpp new file mode 100644 index 0000000000..f291086808 --- /dev/null +++ b/core/io/http_client_tcp.cpp @@ -0,0 +1,667 @@ +/*************************************************************************/ +/* http_client_tcp.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef JAVASCRIPT_ENABLED + +#include "http_client_tcp.h" + +#include "core/io/stream_peer_ssl.h" +#include "core/version.h" + +HTTPClient *HTTPClientTCP::_create_func() { + return memnew(HTTPClientTCP); +} + +Error HTTPClientTCP::connect_to_host(const String &p_host, int p_port, bool p_ssl, bool p_verify_host) { + close(); + + conn_port = p_port; + conn_host = p_host; + + ssl = p_ssl; + ssl_verify_host = p_verify_host; + + String host_lower = conn_host.to_lower(); + if (host_lower.begins_with("http://")) { + conn_host = conn_host.substr(7, conn_host.length() - 7); + } else if (host_lower.begins_with("https://")) { + ssl = true; + conn_host = conn_host.substr(8, conn_host.length() - 8); + } + + ERR_FAIL_COND_V(conn_host.length() < HOST_MIN_LEN, ERR_INVALID_PARAMETER); + + if (conn_port < 0) { + if (ssl) { + conn_port = PORT_HTTPS; + } else { + conn_port = PORT_HTTP; + } + } + + connection = tcp_connection; + + if (conn_host.is_valid_ip_address()) { + // Host contains valid IP + Error err = tcp_connection->connect_to_host(IPAddress(conn_host), p_port); + if (err) { + status = STATUS_CANT_CONNECT; + return err; + } + + status = STATUS_CONNECTING; + } else { + // Host contains hostname and needs to be resolved to IP + resolving = IP::get_singleton()->resolve_hostname_queue_item(conn_host); + status = STATUS_RESOLVING; + } + + return OK; +} + +void HTTPClientTCP::set_connection(const Ref<StreamPeer> &p_connection) { + ERR_FAIL_COND_MSG(p_connection.is_null(), "Connection is not a reference to a valid StreamPeer object."); + + if (ssl) { + ERR_FAIL_NULL_MSG(Object::cast_to<StreamPeerSSL>(p_connection.ptr()), + "Connection is not a reference to a valid StreamPeerSSL object."); + } + + if (connection == p_connection) { + return; + } + + close(); + connection = p_connection; + status = STATUS_CONNECTED; +} + +Ref<StreamPeer> HTTPClientTCP::get_connection() const { + return connection; +} + +static bool _check_request_url(HTTPClientTCP::Method p_method, const String &p_url) { + switch (p_method) { + case HTTPClientTCP::METHOD_CONNECT: { + // Authority in host:port format, as in RFC7231 + int pos = p_url.find_char(':'); + return 0 < pos && pos < p_url.length() - 1; + } + case HTTPClientTCP::METHOD_OPTIONS: { + if (p_url == "*") { + return true; + } + [[fallthrough]]; + } + default: + // Absolute path or absolute URL + return p_url.begins_with("/") || p_url.begins_with("http://") || p_url.begins_with("https://"); + } +} + +Error HTTPClientTCP::request(Method p_method, const String &p_url, const Vector<String> &p_headers, const uint8_t *p_body, int p_body_size) { + ERR_FAIL_INDEX_V(p_method, METHOD_MAX, ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V(!_check_request_url(p_method, p_url), ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V(status != STATUS_CONNECTED, ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V(connection.is_null(), ERR_INVALID_DATA); + + String request = String(_methods[p_method]) + " " + p_url + " HTTP/1.1\r\n"; + bool add_host = true; + bool add_clen = p_body_size > 0; + bool add_uagent = true; + bool add_accept = true; + for (int i = 0; i < p_headers.size(); i++) { + request += p_headers[i] + "\r\n"; + if (add_host && p_headers[i].findn("Host:") == 0) { + add_host = false; + } + if (add_clen && p_headers[i].findn("Content-Length:") == 0) { + add_clen = false; + } + if (add_uagent && p_headers[i].findn("User-Agent:") == 0) { + add_uagent = false; + } + if (add_accept && p_headers[i].findn("Accept:") == 0) { + add_accept = false; + } + } + if (add_host) { + if ((ssl && conn_port == PORT_HTTPS) || (!ssl && conn_port == PORT_HTTP)) { + // Don't append the standard ports + request += "Host: " + conn_host + "\r\n"; + } else { + request += "Host: " + conn_host + ":" + itos(conn_port) + "\r\n"; + } + } + if (add_clen) { + request += "Content-Length: " + itos(p_body_size) + "\r\n"; + // Should it add utf8 encoding? + } + if (add_uagent) { + request += "User-Agent: GodotEngine/" + String(VERSION_FULL_BUILD) + " (" + OS::get_singleton()->get_name() + ")\r\n"; + } + if (add_accept) { + request += "Accept: */*\r\n"; + } + request += "\r\n"; + CharString cs = request.utf8(); + + Vector<uint8_t> data; + data.resize(cs.length() + p_body_size); + memcpy(data.ptrw(), cs.get_data(), cs.length()); + if (p_body_size > 0) { + memcpy(data.ptrw() + cs.length(), p_body, p_body_size); + } + + // TODO Implement non-blocking requests. + Error err = connection->put_data(data.ptr(), data.size()); + + if (err) { + close(); + status = STATUS_CONNECTION_ERROR; + return err; + } + + status = STATUS_REQUESTING; + head_request = p_method == METHOD_HEAD; + + return OK; +} + +bool HTTPClientTCP::has_response() const { + return response_headers.size() != 0; +} + +bool HTTPClientTCP::is_response_chunked() const { + return chunked; +} + +int HTTPClientTCP::get_response_code() const { + return response_num; +} + +Error HTTPClientTCP::get_response_headers(List<String> *r_response) { + if (!response_headers.size()) { + return ERR_INVALID_PARAMETER; + } + + for (int i = 0; i < response_headers.size(); i++) { + r_response->push_back(response_headers[i]); + } + + response_headers.clear(); + + return OK; +} + +void HTTPClientTCP::close() { + if (tcp_connection->get_status() != StreamPeerTCP::STATUS_NONE) { + tcp_connection->disconnect_from_host(); + } + + connection.unref(); + status = STATUS_DISCONNECTED; + head_request = false; + if (resolving != IP::RESOLVER_INVALID_ID) { + IP::get_singleton()->erase_resolve_item(resolving); + resolving = IP::RESOLVER_INVALID_ID; + } + + response_headers.clear(); + response_str.clear(); + body_size = -1; + body_left = 0; + chunk_left = 0; + chunk_trailer_part = false; + read_until_eof = false; + response_num = 0; + handshaking = false; +} + +Error HTTPClientTCP::poll() { + switch (status) { + case STATUS_RESOLVING: { + ERR_FAIL_COND_V(resolving == IP::RESOLVER_INVALID_ID, ERR_BUG); + + IP::ResolverStatus rstatus = IP::get_singleton()->get_resolve_item_status(resolving); + switch (rstatus) { + case IP::RESOLVER_STATUS_WAITING: + return OK; // Still resolving + + case IP::RESOLVER_STATUS_DONE: { + IPAddress host = IP::get_singleton()->get_resolve_item_address(resolving); + Error err = tcp_connection->connect_to_host(host, conn_port); + IP::get_singleton()->erase_resolve_item(resolving); + resolving = IP::RESOLVER_INVALID_ID; + if (err) { + status = STATUS_CANT_CONNECT; + return err; + } + + status = STATUS_CONNECTING; + } break; + case IP::RESOLVER_STATUS_NONE: + case IP::RESOLVER_STATUS_ERROR: { + IP::get_singleton()->erase_resolve_item(resolving); + resolving = IP::RESOLVER_INVALID_ID; + close(); + status = STATUS_CANT_RESOLVE; + return ERR_CANT_RESOLVE; + } break; + } + } break; + case STATUS_CONNECTING: { + StreamPeerTCP::Status s = tcp_connection->get_status(); + switch (s) { + case StreamPeerTCP::STATUS_CONNECTING: { + return OK; + } break; + case StreamPeerTCP::STATUS_CONNECTED: { + if (ssl) { + Ref<StreamPeerSSL> ssl; + if (!handshaking) { + // Connect the StreamPeerSSL and start handshaking + ssl = Ref<StreamPeerSSL>(StreamPeerSSL::create()); + ssl->set_blocking_handshake_enabled(false); + Error err = ssl->connect_to_stream(tcp_connection, ssl_verify_host, conn_host); + if (err != OK) { + close(); + status = STATUS_SSL_HANDSHAKE_ERROR; + return ERR_CANT_CONNECT; + } + connection = ssl; + handshaking = true; + } else { + // We are already handshaking, which means we can use your already active SSL connection + ssl = static_cast<Ref<StreamPeerSSL>>(connection); + if (ssl.is_null()) { + close(); + status = STATUS_SSL_HANDSHAKE_ERROR; + return ERR_CANT_CONNECT; + } + + ssl->poll(); // Try to finish the handshake + } + + if (ssl->get_status() == StreamPeerSSL::STATUS_CONNECTED) { + // Handshake has been successful + handshaking = false; + status = STATUS_CONNECTED; + return OK; + } else if (ssl->get_status() != StreamPeerSSL::STATUS_HANDSHAKING) { + // Handshake has failed + close(); + status = STATUS_SSL_HANDSHAKE_ERROR; + return ERR_CANT_CONNECT; + } + // ... we will need to poll more for handshake to finish + } else { + status = STATUS_CONNECTED; + } + return OK; + } break; + case StreamPeerTCP::STATUS_ERROR: + case StreamPeerTCP::STATUS_NONE: { + close(); + status = STATUS_CANT_CONNECT; + return ERR_CANT_CONNECT; + } break; + } + } break; + case STATUS_BODY: + case STATUS_CONNECTED: { + // Check if we are still connected + if (ssl) { + Ref<StreamPeerSSL> tmp = connection; + tmp->poll(); + if (tmp->get_status() != StreamPeerSSL::STATUS_CONNECTED) { + status = STATUS_CONNECTION_ERROR; + return ERR_CONNECTION_ERROR; + } + } else if (tcp_connection->get_status() != StreamPeerTCP::STATUS_CONNECTED) { + status = STATUS_CONNECTION_ERROR; + return ERR_CONNECTION_ERROR; + } + // Connection established, requests can now be made + return OK; + } break; + case STATUS_REQUESTING: { + while (true) { + uint8_t byte; + int rec = 0; + Error err = _get_http_data(&byte, 1, rec); + if (err != OK) { + close(); + status = STATUS_CONNECTION_ERROR; + return ERR_CONNECTION_ERROR; + } + + if (rec == 0) { + return OK; // Still requesting, keep trying! + } + + response_str.push_back(byte); + int rs = response_str.size(); + if ( + (rs >= 2 && response_str[rs - 2] == '\n' && response_str[rs - 1] == '\n') || + (rs >= 4 && response_str[rs - 4] == '\r' && response_str[rs - 3] == '\n' && response_str[rs - 2] == '\r' && response_str[rs - 1] == '\n')) { + // End of response, parse. + response_str.push_back(0); + String response; + response.parse_utf8((const char *)response_str.ptr()); + Vector<String> responses = response.split("\n"); + body_size = -1; + chunked = false; + body_left = 0; + chunk_left = 0; + chunk_trailer_part = false; + read_until_eof = false; + response_str.clear(); + response_headers.clear(); + response_num = RESPONSE_OK; + + // Per the HTTP 1.1 spec, keep-alive is the default. + // Not following that specification breaks standard implementations. + // Broken web servers should be fixed. + bool keep_alive = true; + + for (int i = 0; i < responses.size(); i++) { + String header = responses[i].strip_edges(); + String s = header.to_lower(); + if (s.length() == 0) { + continue; + } + if (s.begins_with("content-length:")) { + body_size = s.substr(s.find(":") + 1, s.length()).strip_edges().to_int(); + body_left = body_size; + + } else if (s.begins_with("transfer-encoding:")) { + String encoding = header.substr(header.find(":") + 1, header.length()).strip_edges(); + if (encoding == "chunked") { + chunked = true; + } + } else if (s.begins_with("connection: close")) { + keep_alive = false; + } + + if (i == 0 && responses[i].begins_with("HTTP")) { + String num = responses[i].get_slicec(' ', 1); + response_num = num.to_int(); + } else { + response_headers.push_back(header); + } + } + + // This is a HEAD request, we won't receive anything. + if (head_request) { + body_size = 0; + body_left = 0; + } + + if (body_size != -1 || chunked) { + status = STATUS_BODY; + } else if (!keep_alive) { + read_until_eof = true; + status = STATUS_BODY; + } else { + status = STATUS_CONNECTED; + } + return OK; + } + } + } break; + case STATUS_DISCONNECTED: { + return ERR_UNCONFIGURED; + } break; + case STATUS_CONNECTION_ERROR: + case STATUS_SSL_HANDSHAKE_ERROR: { + return ERR_CONNECTION_ERROR; + } break; + case STATUS_CANT_CONNECT: { + return ERR_CANT_CONNECT; + } break; + case STATUS_CANT_RESOLVE: { + return ERR_CANT_RESOLVE; + } break; + } + + return OK; +} + +int HTTPClientTCP::get_response_body_length() const { + return body_size; +} + +PackedByteArray HTTPClientTCP::read_response_body_chunk() { + ERR_FAIL_COND_V(status != STATUS_BODY, PackedByteArray()); + + PackedByteArray ret; + Error err = OK; + + if (chunked) { + while (true) { + if (chunk_trailer_part) { + // We need to consume the trailer part too or keep-alive will break + uint8_t b; + int rec = 0; + err = _get_http_data(&b, 1, rec); + + if (rec == 0) { + break; + } + + chunk.push_back(b); + int cs = chunk.size(); + if ((cs >= 2 && chunk[cs - 2] == '\r' && chunk[cs - 1] == '\n')) { + if (cs == 2) { + // Finally over + chunk_trailer_part = false; + status = STATUS_CONNECTED; + chunk.clear(); + break; + } else { + // We do not process nor return the trailer data + chunk.clear(); + } + } + } else if (chunk_left == 0) { + // Reading length + uint8_t b; + int rec = 0; + err = _get_http_data(&b, 1, rec); + + if (rec == 0) { + break; + } + + chunk.push_back(b); + + if (chunk.size() > 32) { + ERR_PRINT("HTTP Invalid chunk hex len"); + status = STATUS_CONNECTION_ERROR; + break; + } + + if (chunk.size() > 2 && chunk[chunk.size() - 2] == '\r' && chunk[chunk.size() - 1] == '\n') { + int len = 0; + for (int i = 0; i < chunk.size() - 2; i++) { + char c = chunk[i]; + int v = 0; + if (c >= '0' && c <= '9') { + v = c - '0'; + } else if (c >= 'a' && c <= 'f') { + v = c - 'a' + 10; + } else if (c >= 'A' && c <= 'F') { + v = c - 'A' + 10; + } else { + ERR_PRINT("HTTP Chunk len not in hex!!"); + status = STATUS_CONNECTION_ERROR; + break; + } + len <<= 4; + len |= v; + if (len > (1 << 24)) { + ERR_PRINT("HTTP Chunk too big!! >16mb"); + status = STATUS_CONNECTION_ERROR; + break; + } + } + + if (len == 0) { + // End reached! + chunk_trailer_part = true; + chunk.clear(); + break; + } + + chunk_left = len + 2; + chunk.resize(chunk_left); + } + } else { + int rec = 0; + err = _get_http_data(&chunk.write[chunk.size() - chunk_left], chunk_left, rec); + if (rec == 0) { + break; + } + chunk_left -= rec; + + if (chunk_left == 0) { + if (chunk[chunk.size() - 2] != '\r' || chunk[chunk.size() - 1] != '\n') { + ERR_PRINT("HTTP Invalid chunk terminator (not \\r\\n)"); + status = STATUS_CONNECTION_ERROR; + break; + } + + ret.resize(chunk.size() - 2); + uint8_t *w = ret.ptrw(); + memcpy(w, chunk.ptr(), chunk.size() - 2); + chunk.clear(); + } + + break; + } + } + + } else { + int to_read = !read_until_eof ? MIN(body_left, read_chunk_size) : read_chunk_size; + ret.resize(to_read); + int _offset = 0; + while (to_read > 0) { + int rec = 0; + { + uint8_t *w = ret.ptrw(); + err = _get_http_data(w + _offset, to_read, rec); + } + if (rec <= 0) { // Ended up reading less + ret.resize(_offset); + break; + } else { + _offset += rec; + to_read -= rec; + if (!read_until_eof) { + body_left -= rec; + } + } + if (err != OK) { + ret.resize(_offset); + break; + } + } + } + + if (err != OK) { + close(); + + if (err == ERR_FILE_EOF) { + status = STATUS_DISCONNECTED; // Server disconnected + } else { + status = STATUS_CONNECTION_ERROR; + } + } else if (body_left == 0 && !chunked && !read_until_eof) { + status = STATUS_CONNECTED; + } + + return ret; +} + +HTTPClientTCP::Status HTTPClientTCP::get_status() const { + return status; +} + +void HTTPClientTCP::set_blocking_mode(bool p_enable) { + blocking = p_enable; +} + +bool HTTPClientTCP::is_blocking_mode_enabled() const { + return blocking; +} + +Error HTTPClientTCP::_get_http_data(uint8_t *p_buffer, int p_bytes, int &r_received) { + if (blocking) { + // We can't use StreamPeer.get_data, since when reaching EOF we will get an + // error without knowing how many bytes we received. + Error err = ERR_FILE_EOF; + int read = 0; + int left = p_bytes; + r_received = 0; + while (left > 0) { + err = connection->get_partial_data(p_buffer + r_received, left, read); + if (err == OK) { + r_received += read; + } else if (err == ERR_FILE_EOF) { + r_received += read; + return err; + } else { + return err; + } + left -= read; + } + return err; + } else { + return connection->get_partial_data(p_buffer, p_bytes, r_received); + } +} + +void HTTPClientTCP::set_read_chunk_size(int p_size) { + ERR_FAIL_COND(p_size < 256 || p_size > (1 << 24)); + read_chunk_size = p_size; +} + +int HTTPClientTCP::get_read_chunk_size() const { + return read_chunk_size; +} + +HTTPClientTCP::HTTPClientTCP() { + tcp_connection.instantiate(); +} + +HTTPClient *(*HTTPClient::_create)() = HTTPClientTCP::_create_func; + +#endif // #ifndef JAVASCRIPT_ENABLED diff --git a/core/io/http_client_tcp.h b/core/io/http_client_tcp.h new file mode 100644 index 0000000000..e178399fbe --- /dev/null +++ b/core/io/http_client_tcp.h @@ -0,0 +1,92 @@ +/*************************************************************************/ +/* http_client_tcp.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef HTTP_CLIENT_TCP_H +#define HTTP_CLIENT_TCP_H + +#include "http_client.h" + +class HTTPClientTCP : public HTTPClient { +private: + Status status = STATUS_DISCONNECTED; + IP::ResolverID resolving = IP::RESOLVER_INVALID_ID; + int conn_port = -1; + String conn_host; + bool ssl = false; + bool ssl_verify_host = false; + bool blocking = false; + bool handshaking = false; + bool head_request = false; + + Vector<uint8_t> response_str; + + bool chunked = false; + Vector<uint8_t> chunk; + int chunk_left = 0; + bool chunk_trailer_part = false; + int body_size = -1; + int body_left = 0; + bool read_until_eof = false; + + Ref<StreamPeerTCP> tcp_connection; + Ref<StreamPeer> connection; + + int response_num = 0; + Vector<String> response_headers; + // 64 KiB by default (favors fast download speeds at the cost of memory usage). + int read_chunk_size = 65536; + + Error _get_http_data(uint8_t *p_buffer, int p_bytes, int &r_received); + +public: + static HTTPClient *_create_func(); + + Error request(Method p_method, const String &p_url, const Vector<String> &p_headers, const uint8_t *p_body, int p_body_size) override; + + Error connect_to_host(const String &p_host, int p_port = -1, bool p_ssl = false, bool p_verify_host = true) override; + void set_connection(const Ref<StreamPeer> &p_connection) override; + Ref<StreamPeer> get_connection() const override; + void close() override; + Status get_status() const override; + bool has_response() const override; + bool is_response_chunked() const override; + int get_response_code() const override; + Error get_response_headers(List<String> *r_response) override; + int get_response_body_length() const override; + PackedByteArray read_response_body_chunk() override; + void set_blocking_mode(bool p_enable) override; + bool is_blocking_mode_enabled() const override; + void set_read_chunk_size(int p_size) override; + int get_read_chunk_size() const override; + Error poll() override; + HTTPClientTCP(); +}; + +#endif // HTTP_CLIENT_TCP_H diff --git a/core/io/image.cpp b/core/io/image.cpp index 9cd0ea7b5d..3112dd217f 100644 --- a/core/io/image.cpp +++ b/core/io/image.cpp @@ -1945,7 +1945,7 @@ Error Image::generate_mipmap_roughness(RoughnessChannel p_roughness_channel, con memcpy(wr.ptr(), ptr, size); wr = uint8_t*(); Ref<Image> im; - im.instance(); + im.instantiate(); im->create(w, h, false, format, imgdata); im->save_png("res://mipmap_" + itos(i) + ".png"); } @@ -1985,6 +1985,7 @@ void Image::create(int p_width, int p_height, bool p_use_mipmaps, Format p_forma ERR_FAIL_COND_MSG(p_width > MAX_WIDTH, "Image width cannot be greater than " + itos(MAX_WIDTH) + "."); ERR_FAIL_COND_MSG(p_height > MAX_HEIGHT, "Image height cannot be greater than " + itos(MAX_HEIGHT) + "."); ERR_FAIL_COND_MSG(p_width * p_height > MAX_PIXELS, "Too many pixels for image, maximum is " + itos(MAX_PIXELS)); + ERR_FAIL_INDEX_MSG(p_format, FORMAT_MAX, "Image format out of range, please see Image's Format enum."); int mm = 0; int size = _get_dst_image_size(p_width, p_height, p_format, mm, p_use_mipmaps ? -1 : 0); @@ -2007,6 +2008,7 @@ void Image::create(int p_width, int p_height, bool p_use_mipmaps, Format p_forma ERR_FAIL_COND_MSG(p_width > MAX_WIDTH, "Image width cannot be greater than " + itos(MAX_WIDTH) + "."); ERR_FAIL_COND_MSG(p_height > MAX_HEIGHT, "Image height cannot be greater than " + itos(MAX_HEIGHT) + "."); ERR_FAIL_COND_MSG(p_width * p_height > MAX_PIXELS, "Too many pixels for image, maximum is " + itos(MAX_PIXELS)); + ERR_FAIL_INDEX_MSG(p_format, FORMAT_MAX, "Image format out of range, please see Image's Format enum."); int mm; int size = _get_dst_image_size(p_width, p_height, p_format, mm, p_use_mipmaps ? -1 : 0); @@ -2378,6 +2380,8 @@ Error Image::decompress() { } Error Image::compress(CompressMode p_mode, CompressSource p_source, float p_lossy_quality) { + ERR_FAIL_INDEX_V_MSG(p_mode, COMPRESS_MAX, ERR_INVALID_PARAMETER, "Invalid compress mode."); + ERR_FAIL_INDEX_V_MSG(p_source, COMPRESS_SOURCE_MAX, ERR_INVALID_PARAMETER, "Invalid compress source."); return compress_from_channels(p_mode, detect_used_channels(p_source), p_lossy_quality); } @@ -2403,6 +2407,9 @@ Error Image::compress_from_channels(CompressMode p_mode, UsedChannels p_channels ERR_FAIL_COND_V(!_image_compress_bptc_func, ERR_UNAVAILABLE); _image_compress_bptc_func(this, p_lossy_quality, p_channels); } break; + case COMPRESS_MAX: { + ERR_FAIL_V(ERR_INVALID_PARAMETER); + } break; } return OK; @@ -2997,6 +3004,8 @@ void Image::set_pixel(int p_x, int p_y, const Color &p_color) { } void Image::adjust_bcs(float p_brightness, float p_contrast, float p_saturation) { + ERR_FAIL_COND_MSG(!_can_modify(format), "Cannot adjust_bcs in compressed or custom image formats."); + uint8_t *w = data.ptrw(); uint32_t pixel_size = get_format_pixel_size(format); uint32_t pixel_count = data.size() / pixel_size; @@ -3280,7 +3289,7 @@ Ref<Image> Image::rgbe_to_srgb() { ERR_FAIL_COND_V(format != FORMAT_RGBE9995, Ref<Image>()); Ref<Image> new_image; - new_image.instance(); + new_image.instantiate(); new_image->create(width, height, false, Image::FORMAT_RGB8); for (int row = 0; row < height; row++) { @@ -3310,7 +3319,7 @@ Ref<Image> Image::get_image_from_mipmap(int p_mipamp) const { } Ref<Image> image; - image.instance(); + image.instantiate(); image->width = w; image->height = h; image->format = format; @@ -3627,7 +3636,7 @@ Image::Image(const uint8_t *p_mem_png_jpg, int p_len) { Ref<Resource> Image::duplicate(bool p_subresources) const { Ref<Image> copy; - copy.instance(); + copy.instantiate(); copy->_copy_internals_from(*this); return copy; } diff --git a/core/io/image.h b/core/io/image.h index 060e54a308..8f1b251ac3 100644 --- a/core/io/image.h +++ b/core/io/image.h @@ -336,11 +336,13 @@ public: COMPRESS_ETC, COMPRESS_ETC2, COMPRESS_BPTC, + COMPRESS_MAX, }; enum CompressSource { COMPRESS_SOURCE_GENERIC, COMPRESS_SOURCE_SRGB, - COMPRESS_SOURCE_NORMAL + COMPRESS_SOURCE_NORMAL, + COMPRESS_SOURCE_MAX, }; Error compress(CompressMode p_mode, CompressSource p_source = COMPRESS_SOURCE_GENERIC, float p_lossy_quality = 0.7); diff --git a/core/io/image_loader.cpp b/core/io/image_loader.cpp index 7de038e6fe..b45e9d26b1 100644 --- a/core/io/image_loader.cpp +++ b/core/io/image_loader.cpp @@ -163,7 +163,7 @@ RES ResourceFormatLoaderImage::load(const String &p_path, const String &p_origin } Ref<Image> image; - image.instance(); + image.instantiate(); Error err = ImageLoader::loader[idx]->load_image(image, f, false, 1.0); diff --git a/core/io/json.cpp b/core/io/json.cpp index 82ef2a6894..b3a2498212 100644 --- a/core/io/json.cpp +++ b/core/io/json.cpp @@ -45,7 +45,7 @@ const char *JSON::tk_name[TK_MAX] = { "EOF", }; -static String _make_indent(const String &p_indent, int p_size) { +String JSON::_make_indent(const String &p_indent, int p_size) { String indent_text = ""; if (!p_indent.is_empty()) { for (int i = 0; i < p_size; i++) { @@ -55,7 +55,7 @@ static String _make_indent(const String &p_indent, int p_size) { return indent_text; } -String JSON::_print_var(const Variant &p_var, const String &p_indent, int p_cur_indent, bool p_sort_keys, Set<const void *> &p_markers, bool p_full_precision) { +String JSON::_stringify(const Variant &p_var, const String &p_indent, int p_cur_indent, bool p_sort_keys, Set<const void *> &p_markers, bool p_full_precision) { String colon = ":"; String end_statement = ""; @@ -100,7 +100,7 @@ String JSON::_print_var(const Variant &p_var, const String &p_indent, int p_cur_ s += ","; s += end_statement; } - s += _make_indent(p_indent, p_cur_indent + 1) + _print_var(a[i], p_indent, p_cur_indent + 1, p_sort_keys, p_markers); + s += _make_indent(p_indent, p_cur_indent + 1) + _stringify(a[i], p_indent, p_cur_indent + 1, p_sort_keys, p_markers); } s += end_statement + _make_indent(p_indent, p_cur_indent) + "]"; p_markers.erase(a.id()); @@ -126,9 +126,9 @@ String JSON::_print_var(const Variant &p_var, const String &p_indent, int p_cur_ s += ","; s += end_statement; } - s += _make_indent(p_indent, p_cur_indent + 1) + _print_var(String(E->get()), p_indent, p_cur_indent + 1, p_sort_keys, p_markers); + s += _make_indent(p_indent, p_cur_indent + 1) + _stringify(String(E->get()), p_indent, p_cur_indent + 1, p_sort_keys, p_markers); s += colon; - s += _print_var(d[E->get()], p_indent, p_cur_indent + 1, p_sort_keys, p_markers); + s += _stringify(d[E->get()], p_indent, p_cur_indent + 1, p_sort_keys, p_markers); } s += end_statement + _make_indent(p_indent, p_cur_indent) + "}"; @@ -140,11 +140,6 @@ String JSON::_print_var(const Variant &p_var, const String &p_indent, int p_cur_ } } -String JSON::print(const Variant &p_var, const String &p_indent, bool p_sort_keys, bool p_full_precision) { - Set<const void *> markers; - return _print_var(p_var, p_indent, 0, p_sort_keys, markers, p_full_precision); -} - Error JSON::_get_token(const char32_t *p_str, int &index, int p_len, Token &r_token, int &line, String &r_err_str) { while (p_len > 0) { switch (p_str[index]) { @@ -499,7 +494,7 @@ Error JSON::_parse_object(Dictionary &object, const char32_t *p_str, int &index, return ERR_PARSE_ERROR; } -Error JSON::parse(const String &p_json, Variant &r_ret, String &r_err_str, int &r_err_line) { +Error JSON::_parse_string(const String &p_json, Variant &r_ret, String &r_err_str, int &r_err_line) { const char32_t *str = p_json.ptr(); int idx = 0; int len = p_json.length(); @@ -530,34 +525,24 @@ Error JSON::parse(const String &p_json, Variant &r_ret, String &r_err_str, int & return err; } -Error JSONParser::parse_string(const String &p_json_string) { - return JSON::parse(p_json_string, data, err_text, err_line); -} -String JSONParser::get_error_text() const { - return err_text; -} -int JSONParser::get_error_line() const { - return err_line; -} -Variant JSONParser::get_data() const { - return data; +String JSON::stringify(const Variant &p_var, const String &p_indent, bool p_sort_keys, bool p_full_precision) { + Set<const void *> markers; + return _stringify(p_var, p_indent, 0, p_sort_keys, markers, p_full_precision); } -Error JSONParser::decode_data(const Variant &p_data, const String &p_indent, bool p_sort_keys) { - string = JSON::print(p_data, p_indent, p_sort_keys); - data = p_data; - return OK; +Error JSON::parse(const String &p_json_string) { + Error err = _parse_string(p_json_string, data, err_str, err_line); + if (err == Error::OK) { + err_line = 0; + } + return err; } -String JSONParser::get_string() const { - return string; -} +void JSON::_bind_methods() { + ClassDB::bind_method(D_METHOD("stringify", "data", "indent", "sort_keys", "full_precision"), &JSON::stringify, DEFVAL(""), DEFVAL(true), DEFVAL(false)); + ClassDB::bind_method(D_METHOD("parse", "json_string"), &JSON::parse); -void JSONParser::_bind_methods() { - ClassDB::bind_method(D_METHOD("parse_string", "json_string"), &JSONParser::parse_string); - ClassDB::bind_method(D_METHOD("get_error_text"), &JSONParser::get_error_text); - ClassDB::bind_method(D_METHOD("get_error_line"), &JSONParser::get_error_line); - ClassDB::bind_method(D_METHOD("get_data"), &JSONParser::get_data); - ClassDB::bind_method(D_METHOD("decode_data", "data", "indent", "sort_keys"), &JSONParser::decode_data, DEFVAL(""), DEFVAL(true)); - ClassDB::bind_method(D_METHOD("get_string"), &JSONParser::get_string); + ClassDB::bind_method(D_METHOD("get_data"), &JSON::get_data); + ClassDB::bind_method(D_METHOD("get_error_line"), &JSON::get_error_line); + ClassDB::bind_method(D_METHOD("get_error_message"), &JSON::get_error_message); } diff --git a/core/io/json.h b/core/io/json.h index 5be8cc1e86..f20c97f540 100644 --- a/core/io/json.h +++ b/core/io/json.h @@ -33,7 +33,10 @@ #include "core/object/ref_counted.h" #include "core/variant/variant.h" -class JSON { + +class JSON : public RefCounted { + GDCLASS(JSON, RefCounted); + enum TokenType { TK_CURLY_BRACKET_OPEN, TK_CURLY_BRACKET_CLOSE, @@ -60,39 +63,30 @@ class JSON { Variant value; }; - static const char *tk_name[TK_MAX]; + Variant data; + String err_str; + int err_line = 0; - static String _print_var(const Variant &p_var, const String &p_indent, int p_cur_indent, bool p_sort_keys, Set<const void *> &p_markers, bool p_full_precision = false); + static const char *tk_name[]; + static String _make_indent(const String &p_indent, int p_size); + static String _stringify(const Variant &p_var, const String &p_indent, int p_cur_indent, bool p_sort_keys, Set<const void *> &p_markers, bool p_full_precision = false); static Error _get_token(const char32_t *p_str, int &index, int p_len, Token &r_token, int &line, String &r_err_str); static Error _parse_value(Variant &value, Token &token, const char32_t *p_str, int &index, int p_len, int &line, String &r_err_str); static Error _parse_array(Array &array, const char32_t *p_str, int &index, int p_len, int &line, String &r_err_str); static Error _parse_object(Dictionary &object, const char32_t *p_str, int &index, int p_len, int &line, String &r_err_str); - -public: - static String print(const Variant &p_var, const String &p_indent = "", bool p_sort_keys = true, bool p_full_precision = false); - static Error parse(const String &p_json, Variant &r_ret, String &r_err_str, int &r_err_line); -}; - -class JSONParser : public RefCounted { - GDCLASS(JSONParser, RefCounted); - - Variant data; - String string; - String err_text; - int err_line = 0; + static Error _parse_string(const String &p_json, Variant &r_ret, String &r_err_str, int &r_err_line); protected: static void _bind_methods(); public: - Error parse_string(const String &p_json_string); - String get_error_text() const; - int get_error_line() const; - Variant get_data() const; + String stringify(const Variant &p_var, const String &p_indent = "", bool p_sort_keys = true, bool p_full_precision = false); + Error parse(const String &p_json_string); - Error decode_data(const Variant &p_data, const String &p_indent = "", bool p_sort_keys = true); - String get_string() const; + inline Variant get_data() const { return data; } + inline int get_error_line() const { return err_line; } + inline String get_error_message() const { return err_str; } }; #endif // JSON_H diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp index 4c58c84c14..f342db2dad 100644 --- a/core/io/marshalls.cpp +++ b/core/io/marshalls.cpp @@ -111,6 +111,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int *r_len = 4; } + // Note: We cannot use sizeof(real_t) for decoding, in case a different size is encoded. + // Decoding math types always checks for the encoded size, while encoding always uses compilation setting. + // This does lead to some code duplication for decoding, but compatibility is the priority. switch (type & ENCODE_MASK) { case Variant::NIL: { r_variant = Variant(); @@ -144,18 +147,18 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::FLOAT: { if (type & ENCODE_FLAG_64) { - ERR_FAIL_COND_V(len < 8, ERR_INVALID_DATA); + ERR_FAIL_COND_V((size_t)len < sizeof(double), ERR_INVALID_DATA); double val = decode_double(buf); r_variant = val; if (r_len) { - (*r_len) += 8; + (*r_len) += sizeof(double); } } else { - ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); + ERR_FAIL_COND_V((size_t)len < sizeof(float), ERR_INVALID_DATA); float val = decode_float(buf); r_variant = val; if (r_len) { - (*r_len) += 4; + (*r_len) += sizeof(float); } } @@ -172,15 +175,25 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int // math types case Variant::VECTOR2: { - ERR_FAIL_COND_V(len < 4 * 2, ERR_INVALID_DATA); Vector2 val; - val.x = decode_float(&buf[0]); - val.y = decode_float(&buf[4]); - r_variant = val; + if (type & ENCODE_FLAG_64) { + ERR_FAIL_COND_V((size_t)len < sizeof(double) * 2, ERR_INVALID_DATA); + val.x = decode_double(&buf[0]); + val.y = decode_double(&buf[sizeof(double)]); - if (r_len) { - (*r_len) += 4 * 2; + if (r_len) { + (*r_len) += sizeof(double) * 2; + } + } else { + ERR_FAIL_COND_V((size_t)len < sizeof(float) * 2, ERR_INVALID_DATA); + val.x = decode_float(&buf[0]); + val.y = decode_float(&buf[sizeof(float)]); + + if (r_len) { + (*r_len) += sizeof(float) * 2; + } } + r_variant = val; } break; case Variant::VECTOR2I: { @@ -196,17 +209,29 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::RECT2: { - ERR_FAIL_COND_V(len < 4 * 4, ERR_INVALID_DATA); Rect2 val; - val.position.x = decode_float(&buf[0]); - val.position.y = decode_float(&buf[4]); - val.size.x = decode_float(&buf[8]); - val.size.y = decode_float(&buf[12]); - r_variant = val; + if (type & ENCODE_FLAG_64) { + ERR_FAIL_COND_V((size_t)len < sizeof(double) * 4, ERR_INVALID_DATA); + val.position.x = decode_double(&buf[0]); + val.position.y = decode_double(&buf[sizeof(double)]); + val.size.x = decode_double(&buf[sizeof(double) * 2]); + val.size.y = decode_double(&buf[sizeof(double) * 3]); - if (r_len) { - (*r_len) += 4 * 4; + if (r_len) { + (*r_len) += sizeof(double) * 4; + } + } else { + ERR_FAIL_COND_V((size_t)len < sizeof(float) * 4, ERR_INVALID_DATA); + val.position.x = decode_float(&buf[0]); + val.position.y = decode_float(&buf[sizeof(float)]); + val.size.x = decode_float(&buf[sizeof(float) * 2]); + val.size.y = decode_float(&buf[sizeof(float) * 3]); + + if (r_len) { + (*r_len) += sizeof(float) * 4; + } } + r_variant = val; } break; case Variant::RECT2I: { @@ -224,16 +249,27 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::VECTOR3: { - ERR_FAIL_COND_V(len < 4 * 3, ERR_INVALID_DATA); Vector3 val; - val.x = decode_float(&buf[0]); - val.y = decode_float(&buf[4]); - val.z = decode_float(&buf[8]); - r_variant = val; + if (type & ENCODE_FLAG_64) { + ERR_FAIL_COND_V((size_t)len < sizeof(double) * 3, ERR_INVALID_DATA); + val.x = decode_double(&buf[0]); + val.y = decode_double(&buf[sizeof(double)]); + val.z = decode_double(&buf[sizeof(double) * 2]); - if (r_len) { - (*r_len) += 4 * 3; + if (r_len) { + (*r_len) += sizeof(double) * 3; + } + } else { + ERR_FAIL_COND_V((size_t)len < sizeof(float) * 3, ERR_INVALID_DATA); + val.x = decode_float(&buf[0]); + val.y = decode_float(&buf[sizeof(float)]); + val.z = decode_float(&buf[sizeof(float) * 2]); + + if (r_len) { + (*r_len) += sizeof(float) * 3; + } } + r_variant = val; } break; case Variant::VECTOR3I: { @@ -250,101 +286,177 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::TRANSFORM2D: { - ERR_FAIL_COND_V(len < 4 * 6, ERR_INVALID_DATA); Transform2D val; - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 2; j++) { - val.elements[i][j] = decode_float(&buf[(i * 2 + j) * 4]); + if (type & ENCODE_FLAG_64) { + ERR_FAIL_COND_V((size_t)len < sizeof(double) * 6, ERR_INVALID_DATA); + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 2; j++) { + val.elements[i][j] = decode_double(&buf[(i * 2 + j) * sizeof(double)]); + } } - } - r_variant = val; + if (r_len) { + (*r_len) += sizeof(double) * 6; + } + } else { + ERR_FAIL_COND_V((size_t)len < sizeof(float) * 6, ERR_INVALID_DATA); + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 2; j++) { + val.elements[i][j] = decode_float(&buf[(i * 2 + j) * sizeof(float)]); + } + } - if (r_len) { - (*r_len) += 4 * 6; + if (r_len) { + (*r_len) += sizeof(float) * 6; + } } + r_variant = val; } break; case Variant::PLANE: { - ERR_FAIL_COND_V(len < 4 * 4, ERR_INVALID_DATA); Plane val; - val.normal.x = decode_float(&buf[0]); - val.normal.y = decode_float(&buf[4]); - val.normal.z = decode_float(&buf[8]); - val.d = decode_float(&buf[12]); - r_variant = val; + if (type & ENCODE_FLAG_64) { + ERR_FAIL_COND_V((size_t)len < sizeof(double) * 4, ERR_INVALID_DATA); + val.normal.x = decode_double(&buf[0]); + val.normal.y = decode_double(&buf[sizeof(double)]); + val.normal.z = decode_double(&buf[sizeof(double) * 2]); + val.d = decode_double(&buf[sizeof(double) * 3]); - if (r_len) { - (*r_len) += 4 * 4; + if (r_len) { + (*r_len) += sizeof(double) * 4; + } + } else { + ERR_FAIL_COND_V((size_t)len < sizeof(float) * 4, ERR_INVALID_DATA); + val.normal.x = decode_float(&buf[0]); + val.normal.y = decode_float(&buf[sizeof(float)]); + val.normal.z = decode_float(&buf[sizeof(float) * 2]); + val.d = decode_float(&buf[sizeof(float) * 3]); + + if (r_len) { + (*r_len) += sizeof(float) * 4; + } } + r_variant = val; } break; case Variant::QUATERNION: { - ERR_FAIL_COND_V(len < 4 * 4, ERR_INVALID_DATA); Quaternion val; - val.x = decode_float(&buf[0]); - val.y = decode_float(&buf[4]); - val.z = decode_float(&buf[8]); - val.w = decode_float(&buf[12]); - r_variant = val; + if (type & ENCODE_FLAG_64) { + ERR_FAIL_COND_V((size_t)len < sizeof(double) * 4, ERR_INVALID_DATA); + val.x = decode_double(&buf[0]); + val.y = decode_double(&buf[sizeof(double)]); + val.z = decode_double(&buf[sizeof(double) * 2]); + val.w = decode_double(&buf[sizeof(double) * 3]); - if (r_len) { - (*r_len) += 4 * 4; + if (r_len) { + (*r_len) += sizeof(double) * 4; + } + } else { + ERR_FAIL_COND_V((size_t)len < sizeof(float) * 4, ERR_INVALID_DATA); + val.x = decode_float(&buf[0]); + val.y = decode_float(&buf[sizeof(float)]); + val.z = decode_float(&buf[sizeof(float) * 2]); + val.w = decode_float(&buf[sizeof(float) * 3]); + + if (r_len) { + (*r_len) += sizeof(float) * 4; + } } + r_variant = val; } break; case Variant::AABB: { - ERR_FAIL_COND_V(len < 4 * 6, ERR_INVALID_DATA); AABB val; - val.position.x = decode_float(&buf[0]); - val.position.y = decode_float(&buf[4]); - val.position.z = decode_float(&buf[8]); - val.size.x = decode_float(&buf[12]); - val.size.y = decode_float(&buf[16]); - val.size.z = decode_float(&buf[20]); - r_variant = val; + if (type & ENCODE_FLAG_64) { + ERR_FAIL_COND_V((size_t)len < sizeof(double) * 6, ERR_INVALID_DATA); + val.position.x = decode_double(&buf[0]); + val.position.y = decode_double(&buf[sizeof(double)]); + val.position.z = decode_double(&buf[sizeof(double) * 2]); + val.size.x = decode_double(&buf[sizeof(double) * 3]); + val.size.y = decode_double(&buf[sizeof(double) * 4]); + val.size.z = decode_double(&buf[sizeof(double) * 5]); - if (r_len) { - (*r_len) += 4 * 6; + if (r_len) { + (*r_len) += sizeof(double) * 6; + } + } else { + ERR_FAIL_COND_V((size_t)len < sizeof(float) * 6, ERR_INVALID_DATA); + val.position.x = decode_float(&buf[0]); + val.position.y = decode_float(&buf[sizeof(float)]); + val.position.z = decode_float(&buf[sizeof(float) * 2]); + val.size.x = decode_float(&buf[sizeof(float) * 3]); + val.size.y = decode_float(&buf[sizeof(float) * 4]); + val.size.z = decode_float(&buf[sizeof(float) * 5]); + + if (r_len) { + (*r_len) += sizeof(float) * 6; + } } + r_variant = val; } break; case Variant::BASIS: { - ERR_FAIL_COND_V(len < 4 * 9, ERR_INVALID_DATA); Basis val; - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 3; j++) { - val.elements[i][j] = decode_float(&buf[(i * 3 + j) * 4]); + if (type & ENCODE_FLAG_64) { + ERR_FAIL_COND_V((size_t)len < sizeof(double) * 9, ERR_INVALID_DATA); + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + val.elements[i][j] = decode_double(&buf[(i * 3 + j) * sizeof(double)]); + } } - } - r_variant = val; + if (r_len) { + (*r_len) += sizeof(double) * 9; + } + } else { + ERR_FAIL_COND_V((size_t)len < sizeof(float) * 9, ERR_INVALID_DATA); + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + val.elements[i][j] = decode_float(&buf[(i * 3 + j) * sizeof(float)]); + } + } - if (r_len) { - (*r_len) += 4 * 9; + if (r_len) { + (*r_len) += sizeof(float) * 9; + } } + r_variant = val; } break; case Variant::TRANSFORM3D: { - ERR_FAIL_COND_V(len < 4 * 12, ERR_INVALID_DATA); Transform3D val; - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 3; j++) { - val.basis.elements[i][j] = decode_float(&buf[(i * 3 + j) * 4]); + if (type & ENCODE_FLAG_64) { + ERR_FAIL_COND_V((size_t)len < sizeof(double) * 12, ERR_INVALID_DATA); + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + val.basis.elements[i][j] = decode_double(&buf[(i * 3 + j) * sizeof(double)]); + } } - } - val.origin[0] = decode_float(&buf[36]); - val.origin[1] = decode_float(&buf[40]); - val.origin[2] = decode_float(&buf[44]); + val.origin[0] = decode_double(&buf[sizeof(double) * 9]); + val.origin[1] = decode_double(&buf[sizeof(double) * 10]); + val.origin[2] = decode_double(&buf[sizeof(double) * 11]); - r_variant = val; + if (r_len) { + (*r_len) += sizeof(double) * 12; + } + } else { + ERR_FAIL_COND_V((size_t)len < sizeof(float) * 12, ERR_INVALID_DATA); + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + val.basis.elements[i][j] = decode_float(&buf[(i * 3 + j) * sizeof(float)]); + } + } + val.origin[0] = decode_float(&buf[sizeof(float) * 9]); + val.origin[1] = decode_float(&buf[sizeof(float) * 10]); + val.origin[2] = decode_float(&buf[sizeof(float) * 11]); - if (r_len) { - (*r_len) += 4 * 12; + if (r_len) { + (*r_len) += sizeof(float) * 12; + } } + r_variant = val; } break; - // misc types case Variant::COLOR: { ERR_FAIL_COND_V(len < 4 * 4, ERR_INVALID_DATA); @@ -356,9 +468,8 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int r_variant = val; if (r_len) { - (*r_len) += 4 * 4; + (*r_len) += 4 * 4; // Colors should always be in single-precision. } - } break; case Variant::STRING_NAME: { String str; @@ -436,7 +547,7 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int r_variant = (Object *)nullptr; } else { Ref<EncodedObjectAsID> obj_as_id; - obj_as_id.instance(); + obj_as_id.instantiate(); obj_as_id->set_object_id(val); r_variant = obj_as_id; @@ -454,7 +565,7 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int if (str == String()) { r_variant = (Object *)nullptr; } else { - Object *obj = ClassDB::instance(str); + Object *obj = ClassDB::instantiate(str); ERR_FAIL_COND_V(!obj, ERR_UNAVAILABLE); ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); @@ -463,7 +574,7 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int buf += 4; len -= 4; if (r_len) { - (*r_len) += 4; + (*r_len) += 4; // Size of count number. } for (int i = 0; i < count; i++) { @@ -516,7 +627,7 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int len -= 4; if (r_len) { - (*r_len) += 4; + (*r_len) += 4; // Size of count number. } Dictionary d; @@ -559,7 +670,7 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int len -= 4; if (r_len) { - (*r_len) += 4; + (*r_len) += 4; // Size of count number. } Array varr; @@ -716,9 +827,8 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int len -= 4; if (r_len) { - (*r_len) += 4; + (*r_len) += 4; // Size of count number. } - //printf("string count: %i\n",count); for (int32_t i = 0; i < count; i++) { String str; @@ -739,30 +849,57 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int buf += 4; len -= 4; - ERR_FAIL_MUL_OF(count, 4 * 2, ERR_INVALID_DATA); - ERR_FAIL_COND_V(count < 0 || count * 4 * 2 > len, ERR_INVALID_DATA); Vector<Vector2> varray; - if (r_len) { - (*r_len) += 4; - } - - if (count) { - varray.resize(count); - Vector2 *w = varray.ptrw(); + if (type & ENCODE_FLAG_64) { + ERR_FAIL_MUL_OF(count, sizeof(double) * 2, ERR_INVALID_DATA); + ERR_FAIL_COND_V(count < 0 || count * sizeof(double) * 2 > (size_t)len, ERR_INVALID_DATA); - for (int32_t i = 0; i < count; i++) { - w[i].x = decode_float(buf + i * 4 * 2 + 4 * 0); - w[i].y = decode_float(buf + i * 4 * 2 + 4 * 1); + if (r_len) { + (*r_len) += 4; // Size of count number. } - int adv = 4 * 2 * count; + if (count) { + varray.resize(count); + Vector2 *w = varray.ptrw(); + + for (int32_t i = 0; i < count; i++) { + w[i].x = decode_double(buf + i * sizeof(double) * 2 + sizeof(double) * 0); + w[i].y = decode_double(buf + i * sizeof(double) * 2 + sizeof(double) * 1); + } + + int adv = sizeof(double) * 2 * count; + + if (r_len) { + (*r_len) += adv; + } + len -= adv; + buf += adv; + } + } else { + ERR_FAIL_MUL_OF(count, sizeof(float) * 2, ERR_INVALID_DATA); + ERR_FAIL_COND_V(count < 0 || count * sizeof(float) * 2 > (size_t)len, ERR_INVALID_DATA); if (r_len) { - (*r_len) += adv; + (*r_len) += 4; // Size of count number. } - } + if (count) { + varray.resize(count); + Vector2 *w = varray.ptrw(); + + for (int32_t i = 0; i < count; i++) { + w[i].x = decode_float(buf + i * sizeof(float) * 2 + sizeof(float) * 0); + w[i].y = decode_float(buf + i * sizeof(float) * 2 + sizeof(float) * 1); + } + + int adv = sizeof(float) * 2 * count; + + if (r_len) { + (*r_len) += adv; + } + } + } r_variant = varray; } break; @@ -772,32 +909,61 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int buf += 4; len -= 4; - ERR_FAIL_MUL_OF(count, 4 * 3, ERR_INVALID_DATA); - ERR_FAIL_COND_V(count < 0 || count * 4 * 3 > len, ERR_INVALID_DATA); - Vector<Vector3> varray; - if (r_len) { - (*r_len) += 4; - } - - if (count) { - varray.resize(count); - Vector3 *w = varray.ptrw(); + if (type & ENCODE_FLAG_64) { + ERR_FAIL_MUL_OF(count, sizeof(double) * 3, ERR_INVALID_DATA); + ERR_FAIL_COND_V(count < 0 || count * sizeof(double) * 3 > (size_t)len, ERR_INVALID_DATA); - for (int32_t i = 0; i < count; i++) { - w[i].x = decode_float(buf + i * 4 * 3 + 4 * 0); - w[i].y = decode_float(buf + i * 4 * 3 + 4 * 1); - w[i].z = decode_float(buf + i * 4 * 3 + 4 * 2); + if (r_len) { + (*r_len) += 4; // Size of count number. } - int adv = 4 * 3 * count; + if (count) { + varray.resize(count); + Vector3 *w = varray.ptrw(); + + for (int32_t i = 0; i < count; i++) { + w[i].x = decode_double(buf + i * sizeof(double) * 3 + sizeof(double) * 0); + w[i].y = decode_double(buf + i * sizeof(double) * 3 + sizeof(double) * 1); + w[i].z = decode_double(buf + i * sizeof(double) * 3 + sizeof(double) * 2); + } + + int adv = sizeof(double) * 3 * count; + + if (r_len) { + (*r_len) += adv; + } + len -= adv; + buf += adv; + } + } else { + ERR_FAIL_MUL_OF(count, sizeof(float) * 3, ERR_INVALID_DATA); + ERR_FAIL_COND_V(count < 0 || count * sizeof(float) * 3 > (size_t)len, ERR_INVALID_DATA); if (r_len) { - (*r_len) += adv; + (*r_len) += 4; // Size of count number. } - } + if (count) { + varray.resize(count); + Vector3 *w = varray.ptrw(); + + for (int32_t i = 0; i < count; i++) { + w[i].x = decode_float(buf + i * sizeof(float) * 3 + sizeof(float) * 0); + w[i].y = decode_float(buf + i * sizeof(float) * 3 + sizeof(float) * 1); + w[i].z = decode_float(buf + i * sizeof(float) * 3 + sizeof(float) * 2); + } + + int adv = sizeof(float) * 3 * count; + + if (r_len) { + (*r_len) += adv; + } + len -= adv; + buf += adv; + } + } r_variant = varray; } break; @@ -813,7 +979,7 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int Vector<Color> carray; if (r_len) { - (*r_len) += 4; + (*r_len) += 4; // Size of count number. } if (count) { @@ -821,6 +987,7 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int Color *w = carray.ptrw(); for (int32_t i = 0; i < count; i++) { + // Colors should always be in single-precision. w[i].r = decode_float(buf + i * 4 * 4 + 4 * 0); w[i].g = decode_float(buf + i * 4 * 4 + 4 * 1); w[i].b = decode_float(buf + i * 4 * 4 + 4 * 2); @@ -882,7 +1049,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo double d = p_variant; float f = d; if (double(f) != d) { - flags |= ENCODE_FLAG_64; //always encode real as double + flags |= ENCODE_FLAG_64; } } break; case Variant::OBJECT: { @@ -1013,11 +1180,11 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo case Variant::VECTOR2: { if (buf) { Vector2 v2 = p_variant; - encode_float(v2.x, &buf[0]); - encode_float(v2.y, &buf[4]); + encode_real(v2.x, &buf[0]); + encode_real(v2.y, &buf[sizeof(real_t)]); } - r_len += 2 * 4; + r_len += 2 * sizeof(real_t); } break; case Variant::VECTOR2I: { @@ -1033,12 +1200,12 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo case Variant::RECT2: { if (buf) { Rect2 r2 = p_variant; - encode_float(r2.position.x, &buf[0]); - encode_float(r2.position.y, &buf[4]); - encode_float(r2.size.x, &buf[8]); - encode_float(r2.size.y, &buf[12]); + encode_real(r2.position.x, &buf[0]); + encode_real(r2.position.y, &buf[sizeof(real_t)]); + encode_real(r2.size.x, &buf[sizeof(real_t) * 2]); + encode_real(r2.size.y, &buf[sizeof(real_t) * 3]); } - r_len += 4 * 4; + r_len += 4 * sizeof(real_t); } break; case Variant::RECT2I: { @@ -1055,12 +1222,12 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo case Variant::VECTOR3: { if (buf) { Vector3 v3 = p_variant; - encode_float(v3.x, &buf[0]); - encode_float(v3.y, &buf[4]); - encode_float(v3.z, &buf[8]); + encode_real(v3.x, &buf[0]); + encode_real(v3.y, &buf[sizeof(real_t)]); + encode_real(v3.z, &buf[sizeof(real_t) * 2]); } - r_len += 3 * 4; + r_len += 3 * sizeof(real_t); } break; case Variant::VECTOR3I: { @@ -1079,50 +1246,50 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo Transform2D val = p_variant; for (int i = 0; i < 3; i++) { for (int j = 0; j < 2; j++) { - memcpy(&buf[(i * 2 + j) * 4], &val.elements[i][j], sizeof(float)); + memcpy(&buf[(i * 2 + j) * sizeof(real_t)], &val.elements[i][j], sizeof(real_t)); } } } - r_len += 6 * 4; + r_len += 6 * sizeof(real_t); } break; case Variant::PLANE: { if (buf) { Plane p = p_variant; - encode_float(p.normal.x, &buf[0]); - encode_float(p.normal.y, &buf[4]); - encode_float(p.normal.z, &buf[8]); - encode_float(p.d, &buf[12]); + encode_real(p.normal.x, &buf[0]); + encode_real(p.normal.y, &buf[sizeof(real_t)]); + encode_real(p.normal.z, &buf[sizeof(real_t) * 2]); + encode_real(p.d, &buf[sizeof(real_t) * 3]); } - r_len += 4 * 4; + r_len += 4 * sizeof(real_t); } break; case Variant::QUATERNION: { if (buf) { Quaternion q = p_variant; - encode_float(q.x, &buf[0]); - encode_float(q.y, &buf[4]); - encode_float(q.z, &buf[8]); - encode_float(q.w, &buf[12]); + encode_real(q.x, &buf[0]); + encode_real(q.y, &buf[sizeof(real_t)]); + encode_real(q.z, &buf[sizeof(real_t) * 2]); + encode_real(q.w, &buf[sizeof(real_t) * 3]); } - r_len += 4 * 4; + r_len += 4 * sizeof(real_t); } break; case Variant::AABB: { if (buf) { AABB aabb = p_variant; - encode_float(aabb.position.x, &buf[0]); - encode_float(aabb.position.y, &buf[4]); - encode_float(aabb.position.z, &buf[8]); - encode_float(aabb.size.x, &buf[12]); - encode_float(aabb.size.y, &buf[16]); - encode_float(aabb.size.z, &buf[20]); + encode_real(aabb.position.x, &buf[0]); + encode_real(aabb.position.y, &buf[sizeof(real_t)]); + encode_real(aabb.position.z, &buf[sizeof(real_t) * 2]); + encode_real(aabb.size.x, &buf[sizeof(real_t) * 3]); + encode_real(aabb.size.y, &buf[sizeof(real_t) * 4]); + encode_real(aabb.size.z, &buf[sizeof(real_t) * 5]); } - r_len += 6 * 4; + r_len += 6 * sizeof(real_t); } break; case Variant::BASIS: { @@ -1130,12 +1297,12 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo Basis val = p_variant; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - memcpy(&buf[(i * 3 + j) * 4], &val.elements[i][j], sizeof(float)); + memcpy(&buf[(i * 3 + j) * sizeof(real_t)], &val.elements[i][j], sizeof(real_t)); } } } - r_len += 9 * 4; + r_len += 9 * sizeof(real_t); } break; case Variant::TRANSFORM3D: { @@ -1143,16 +1310,16 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo Transform3D val = p_variant; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - memcpy(&buf[(i * 3 + j) * 4], &val.basis.elements[i][j], sizeof(float)); + memcpy(&buf[(i * 3 + j) * sizeof(real_t)], &val.basis.elements[i][j], sizeof(real_t)); } } - encode_float(val.origin.x, &buf[36]); - encode_float(val.origin.y, &buf[40]); - encode_float(val.origin.z, &buf[44]); + encode_real(val.origin.x, &buf[sizeof(real_t) * 9]); + encode_real(val.origin.y, &buf[sizeof(real_t) * 10]); + encode_real(val.origin.z, &buf[sizeof(real_t) * 11]); } - r_len += 12 * 4; + r_len += 12 * sizeof(real_t); } break; @@ -1166,7 +1333,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo encode_float(c.a, &buf[12]); } - r_len += 4 * 4; + r_len += 4 * 4; // Colors should always be in single-precision. } break; case Variant::RID: { @@ -1441,13 +1608,13 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo for (int i = 0; i < len; i++) { Vector2 v = data.get(i); - encode_float(v.x, &buf[0]); - encode_float(v.y, &buf[4]); - buf += 4 * 2; + encode_real(v.x, &buf[0]); + encode_real(v.y, &buf[sizeof(real_t)]); + buf += sizeof(real_t) * 2; } } - r_len += 4 * 2 * len; + r_len += sizeof(real_t) * 2 * len; } break; case Variant::PACKED_VECTOR3_ARRAY: { @@ -1465,14 +1632,14 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo for (int i = 0; i < len; i++) { Vector3 v = data.get(i); - encode_float(v.x, &buf[0]); - encode_float(v.y, &buf[4]); - encode_float(v.z, &buf[8]); - buf += 4 * 3; + encode_real(v.x, &buf[0]); + encode_real(v.y, &buf[sizeof(real_t)]); + encode_real(v.z, &buf[sizeof(real_t) * 2]); + buf += sizeof(real_t) * 3; } } - r_len += 4 * 3 * len; + r_len += sizeof(real_t) * 3 * len; } break; case Variant::PACKED_COLOR_ARRAY: { @@ -1494,7 +1661,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo encode_float(c.g, &buf[4]); encode_float(c.b, &buf[8]); encode_float(c.a, &buf[12]); - buf += 4 * 4; + buf += 4 * 4; // Colors should always be in single-precision. } } diff --git a/core/io/marshalls.h b/core/io/marshalls.h index 7fac708f97..3ebed914a3 100644 --- a/core/io/marshalls.h +++ b/core/io/marshalls.h @@ -31,10 +31,18 @@ #ifndef MARSHALLS_H #define MARSHALLS_H +#include "core/math/math_defs.h" #include "core/object/ref_counted.h" #include "core/typedefs.h" #include "core/variant/variant.h" +// uintr_t is only for pairing with real_t, and we only need it in here. +#ifdef REAL_T_IS_DOUBLE +typedef uint64_t uintr_t; +#else +typedef uint32_t uintr_t; +#endif + /** * Miscellaneous helpers for marshalling data types, and encoding * in an endian independent way @@ -50,6 +58,12 @@ union MarshallDouble { double d; ///< double }; +// Behaves like one of the above, depending on compilation setting. +union MarshallReal { + uintr_t i; + real_t r; +}; + static inline unsigned int encode_uint16(uint16_t p_uint, uint8_t *p_arr) { for (int i = 0; i < 2; i++) { *p_arr = p_uint & 0xFF; @@ -96,6 +110,24 @@ static inline unsigned int encode_double(double p_double, uint8_t *p_arr) { return sizeof(uint64_t); } +static inline unsigned int encode_uintr(uintr_t p_uint, uint8_t *p_arr) { + for (size_t i = 0; i < sizeof(uintr_t); i++) { + *p_arr = p_uint & 0xFF; + p_arr++; + p_uint >>= 8; + } + + return sizeof(uintr_t); +} + +static inline unsigned int encode_real(real_t p_real, uint8_t *p_arr) { + MarshallReal mr; + mr.r = p_real; + encode_uintr(mr.i, p_arr); + + return sizeof(uintr_t); +} + static inline int encode_cstring(const char *p_string, uint8_t *p_data) { int len = 0; diff --git a/core/io/multiplayer_api.cpp b/core/io/multiplayer_api.cpp index 51ba8800e4..564397c88c 100644 --- a/core/io/multiplayer_api.cpp +++ b/core/io/multiplayer_api.cpp @@ -85,7 +85,7 @@ const MultiplayerAPI::RPCConfig _get_rpc_config_by_id(Node *p_node, uint16_t p_i if (id & (1 << 15)) { id = id & ~(1 << 15); config = p_node->get_node_rpc_methods(); - } else { + } else if (p_node->get_script_instance()) { config = p_node->get_script_instance()->get_rpc_methods(); } if (id < config.size()) { @@ -149,7 +149,7 @@ _FORCE_INLINE_ bool _can_call_mode(Node *p_node, MultiplayerAPI::RPCMode mode, i } void MultiplayerAPI::poll() { - if (!network_peer.is_valid() || network_peer->get_connection_status() == NetworkedMultiplayerPeer::CONNECTION_DISCONNECTED) { + if (!network_peer.is_valid() || network_peer->get_connection_status() == MultiplayerPeer::CONNECTION_DISCONNECTED) { return; } @@ -196,13 +196,13 @@ Node *MultiplayerAPI::get_root_node() { return root_node; } -void MultiplayerAPI::set_network_peer(const Ref<NetworkedMultiplayerPeer> &p_peer) { +void MultiplayerAPI::set_network_peer(const Ref<MultiplayerPeer> &p_peer) { if (p_peer == network_peer) { return; // Nothing to do } - ERR_FAIL_COND_MSG(p_peer.is_valid() && p_peer->get_connection_status() == NetworkedMultiplayerPeer::CONNECTION_DISCONNECTED, - "Supplied NetworkedMultiplayerPeer must be connecting or connected."); + ERR_FAIL_COND_MSG(p_peer.is_valid() && p_peer->get_connection_status() == MultiplayerPeer::CONNECTION_DISCONNECTED, + "Supplied MultiplayerPeer must be connecting or connected."); if (network_peer.is_valid()) { network_peer->disconnect("peer_connected", callable_mp(this, &MultiplayerAPI::_add_peer)); @@ -224,7 +224,7 @@ void MultiplayerAPI::set_network_peer(const Ref<NetworkedMultiplayerPeer> &p_pee } } -Ref<NetworkedMultiplayerPeer> MultiplayerAPI::get_network_peer() const { +Ref<MultiplayerPeer> MultiplayerAPI::get_network_peer() const { return network_peer; } @@ -513,7 +513,7 @@ void MultiplayerAPI::_process_simplify_path(int p_from, const uint8_t *p_packet, packet.write[1] = valid_rpc_checksum; encode_cstring(pname.get_data(), &packet.write[2]); - network_peer->set_transfer_mode(NetworkedMultiplayerPeer::TRANSFER_MODE_RELIABLE); + network_peer->set_transfer_mode(MultiplayerPeer::TRANSFER_MODE_RELIABLE); network_peer->set_target_peer(p_from); network_peer->put_packet(packet.ptr(), packet.size()); } @@ -592,7 +592,7 @@ bool MultiplayerAPI::_send_confirm_path(Node *p_node, NodePath p_path, PathSentC for (List<int>::Element *E = peers_to_add.front(); E; E = E->next()) { network_peer->set_target_peer(E->get()); // To all of you. - network_peer->set_transfer_mode(NetworkedMultiplayerPeer::TRANSFER_MODE_RELIABLE); + network_peer->set_transfer_mode(MultiplayerPeer::TRANSFER_MODE_RELIABLE); network_peer->put_packet(packet.ptr(), packet.size()); psc->confirmed_peers.insert(E->get(), false); // Insert into confirmed, but as false since it was not confirmed. @@ -760,9 +760,9 @@ Error MultiplayerAPI::_decode_and_decompress_variant(Variant &r_variant, const u void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, uint16_t p_rpc_id, const RPCConfig &p_config, const StringName &p_name, const Variant **p_arg, int p_argcount) { ERR_FAIL_COND_MSG(network_peer.is_null(), "Attempt to remote call/set when networking is not active in SceneTree."); - ERR_FAIL_COND_MSG(network_peer->get_connection_status() == NetworkedMultiplayerPeer::CONNECTION_CONNECTING, "Attempt to remote call/set when networking is not connected yet in SceneTree."); + ERR_FAIL_COND_MSG(network_peer->get_connection_status() == MultiplayerPeer::CONNECTION_CONNECTING, "Attempt to remote call/set when networking is not connected yet in SceneTree."); - ERR_FAIL_COND_MSG(network_peer->get_connection_status() == NetworkedMultiplayerPeer::CONNECTION_DISCONNECTED, "Attempt to remote call/set when networking is disconnected."); + ERR_FAIL_COND_MSG(network_peer->get_connection_status() == MultiplayerPeer::CONNECTION_DISCONNECTED, "Attempt to remote call/set when networking is disconnected."); ERR_FAIL_COND_MSG(p_argcount > 255, "Too many arguments >255."); @@ -974,7 +974,7 @@ void MultiplayerAPI::_server_disconnected() { void MultiplayerAPI::rpcp(Node *p_node, int p_peer_id, bool p_unreliable, const StringName &p_method, const Variant **p_arg, int p_argcount) { ERR_FAIL_COND_MSG(!network_peer.is_valid(), "Trying to call an RPC while no network peer is active."); ERR_FAIL_COND_MSG(!p_node->is_inside_tree(), "Trying to call an RPC on a node which is not inside SceneTree."); - ERR_FAIL_COND_MSG(network_peer->get_connection_status() != NetworkedMultiplayerPeer::CONNECTION_CONNECTED, "Trying to call an RPC via a network peer which is not connected."); + ERR_FAIL_COND_MSG(network_peer->get_connection_status() != MultiplayerPeer::CONNECTION_CONNECTED, "Trying to call an RPC via a network peer which is not connected."); int node_id = network_peer->get_unique_id(); bool skip_rpc = node_id == p_peer_id; @@ -1033,10 +1033,10 @@ void MultiplayerAPI::rpcp(Node *p_node, int p_peer_id, bool p_unreliable, const ERR_FAIL_COND_MSG(skip_rpc && !(call_local_native || call_local_script), "RPC '" + p_method + "' on yourself is not allowed by selected mode."); } -Error MultiplayerAPI::send_bytes(Vector<uint8_t> p_data, int p_to, NetworkedMultiplayerPeer::TransferMode p_mode) { +Error MultiplayerAPI::send_bytes(Vector<uint8_t> p_data, int p_to, MultiplayerPeer::TransferMode p_mode) { ERR_FAIL_COND_V_MSG(p_data.size() < 1, ERR_INVALID_DATA, "Trying to send an empty raw packet."); ERR_FAIL_COND_V_MSG(!network_peer.is_valid(), ERR_UNCONFIGURED, "Trying to send a raw packet while no network peer is active."); - ERR_FAIL_COND_V_MSG(network_peer->get_connection_status() != NetworkedMultiplayerPeer::CONNECTION_CONNECTED, ERR_UNCONFIGURED, "Trying to send a raw packet via a network peer which is not connected."); + ERR_FAIL_COND_V_MSG(network_peer->get_connection_status() != MultiplayerPeer::CONNECTION_CONNECTED, ERR_UNCONFIGURED, "Trying to send a raw packet via a network peer which is not connected."); MAKE_ROOM(p_data.size() + 1); const uint8_t *r = p_data.ptr(); @@ -1105,7 +1105,7 @@ bool MultiplayerAPI::is_object_decoding_allowed() const { void MultiplayerAPI::_bind_methods() { ClassDB::bind_method(D_METHOD("set_root_node", "node"), &MultiplayerAPI::set_root_node); ClassDB::bind_method(D_METHOD("get_root_node"), &MultiplayerAPI::get_root_node); - ClassDB::bind_method(D_METHOD("send_bytes", "bytes", "id", "mode"), &MultiplayerAPI::send_bytes, DEFVAL(NetworkedMultiplayerPeer::TARGET_PEER_BROADCAST), DEFVAL(NetworkedMultiplayerPeer::TRANSFER_MODE_RELIABLE)); + ClassDB::bind_method(D_METHOD("send_bytes", "bytes", "id", "mode"), &MultiplayerAPI::send_bytes, DEFVAL(MultiplayerPeer::TARGET_PEER_BROADCAST), DEFVAL(MultiplayerPeer::TRANSFER_MODE_RELIABLE)); ClassDB::bind_method(D_METHOD("has_network_peer"), &MultiplayerAPI::has_network_peer); ClassDB::bind_method(D_METHOD("get_network_peer"), &MultiplayerAPI::get_network_peer); ClassDB::bind_method(D_METHOD("get_network_unique_id"), &MultiplayerAPI::get_network_unique_id); @@ -1123,7 +1123,7 @@ void MultiplayerAPI::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "allow_object_decoding"), "set_allow_object_decoding", "is_object_decoding_allowed"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "refuse_new_network_connections"), "set_refuse_new_network_connections", "is_refusing_new_network_connections"); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "network_peer", PROPERTY_HINT_RESOURCE_TYPE, "NetworkedMultiplayerPeer", PROPERTY_USAGE_NONE), "set_network_peer", "get_network_peer"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "network_peer", PROPERTY_HINT_RESOURCE_TYPE, "MultiplayerPeer", PROPERTY_USAGE_NONE), "set_network_peer", "get_network_peer"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "root_node", PROPERTY_HINT_RESOURCE_TYPE, "Node", PROPERTY_USAGE_NONE), "set_root_node", "get_root_node"); ADD_PROPERTY_DEFAULT("refuse_new_network_connections", false); diff --git a/core/io/multiplayer_api.h b/core/io/multiplayer_api.h index 43804a20ec..e9f96383c9 100644 --- a/core/io/multiplayer_api.h +++ b/core/io/multiplayer_api.h @@ -31,7 +31,7 @@ #ifndef MULTIPLAYER_API_H #define MULTIPLAYER_API_H -#include "core/io/networked_multiplayer_peer.h" +#include "core/io/multiplayer_peer.h" #include "core/object/ref_counted.h" class MultiplayerAPI : public RefCounted { @@ -51,7 +51,7 @@ public: struct RPCConfig { StringName name; RPCMode rpc_mode = RPC_MODE_DISABLED; - NetworkedMultiplayerPeer::TransferMode transfer_mode = NetworkedMultiplayerPeer::TRANSFER_MODE_RELIABLE; + MultiplayerPeer::TransferMode transfer_mode = MultiplayerPeer::TRANSFER_MODE_RELIABLE; int channel = 0; bool operator==(RPCConfig const &p_other) const { @@ -83,7 +83,7 @@ private: Map<int, NodeInfo> nodes; }; - Ref<NetworkedMultiplayerPeer> network_peer; + Ref<MultiplayerPeer> network_peer; int rpc_sender_id = 0; Set<int> connected_peers; HashMap<NodePath, PathSentCache> path_send_cache; @@ -132,9 +132,9 @@ public: void clear(); void set_root_node(Node *p_node); Node *get_root_node(); - void set_network_peer(const Ref<NetworkedMultiplayerPeer> &p_peer); - Ref<NetworkedMultiplayerPeer> get_network_peer() const; - Error send_bytes(Vector<uint8_t> p_data, int p_to = NetworkedMultiplayerPeer::TARGET_PEER_BROADCAST, NetworkedMultiplayerPeer::TransferMode p_mode = NetworkedMultiplayerPeer::TRANSFER_MODE_RELIABLE); + void set_network_peer(const Ref<MultiplayerPeer> &p_peer); + Ref<MultiplayerPeer> get_network_peer() const; + Error send_bytes(Vector<uint8_t> p_data, int p_to = MultiplayerPeer::TARGET_PEER_BROADCAST, MultiplayerPeer::TransferMode p_mode = MultiplayerPeer::TRANSFER_MODE_RELIABLE); // Called by Node.rpc void rpcp(Node *p_node, int p_peer_id, bool p_unreliable, const StringName &p_method, const Variant **p_arg, int p_argcount); diff --git a/core/io/networked_multiplayer_peer.cpp b/core/io/multiplayer_peer.cpp index b6af046e77..8126b4cea3 100644 --- a/core/io/networked_multiplayer_peer.cpp +++ b/core/io/multiplayer_peer.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* networked_multiplayer_peer.cpp */ +/* multiplayer_peer.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,22 +28,22 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "networked_multiplayer_peer.h" +#include "multiplayer_peer.h" -void NetworkedMultiplayerPeer::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_transfer_mode", "mode"), &NetworkedMultiplayerPeer::set_transfer_mode); - ClassDB::bind_method(D_METHOD("get_transfer_mode"), &NetworkedMultiplayerPeer::get_transfer_mode); - ClassDB::bind_method(D_METHOD("set_target_peer", "id"), &NetworkedMultiplayerPeer::set_target_peer); +void MultiplayerPeer::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_transfer_mode", "mode"), &MultiplayerPeer::set_transfer_mode); + ClassDB::bind_method(D_METHOD("get_transfer_mode"), &MultiplayerPeer::get_transfer_mode); + ClassDB::bind_method(D_METHOD("set_target_peer", "id"), &MultiplayerPeer::set_target_peer); - ClassDB::bind_method(D_METHOD("get_packet_peer"), &NetworkedMultiplayerPeer::get_packet_peer); + ClassDB::bind_method(D_METHOD("get_packet_peer"), &MultiplayerPeer::get_packet_peer); - ClassDB::bind_method(D_METHOD("poll"), &NetworkedMultiplayerPeer::poll); + ClassDB::bind_method(D_METHOD("poll"), &MultiplayerPeer::poll); - ClassDB::bind_method(D_METHOD("get_connection_status"), &NetworkedMultiplayerPeer::get_connection_status); - ClassDB::bind_method(D_METHOD("get_unique_id"), &NetworkedMultiplayerPeer::get_unique_id); + ClassDB::bind_method(D_METHOD("get_connection_status"), &MultiplayerPeer::get_connection_status); + ClassDB::bind_method(D_METHOD("get_unique_id"), &MultiplayerPeer::get_unique_id); - ClassDB::bind_method(D_METHOD("set_refuse_new_connections", "enable"), &NetworkedMultiplayerPeer::set_refuse_new_connections); - ClassDB::bind_method(D_METHOD("is_refusing_new_connections"), &NetworkedMultiplayerPeer::is_refusing_new_connections); + ClassDB::bind_method(D_METHOD("set_refuse_new_connections", "enable"), &MultiplayerPeer::set_refuse_new_connections); + ClassDB::bind_method(D_METHOD("is_refusing_new_connections"), &MultiplayerPeer::is_refusing_new_connections); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "refuse_new_connections"), "set_refuse_new_connections", "is_refusing_new_connections"); ADD_PROPERTY(PropertyInfo(Variant::INT, "transfer_mode", PROPERTY_HINT_ENUM, "Unreliable,Unreliable Ordered,Reliable"), "set_transfer_mode", "get_transfer_mode"); diff --git a/core/io/networked_multiplayer_peer.h b/core/io/multiplayer_peer.h index 7c90f97d88..432f47280f 100644 --- a/core/io/networked_multiplayer_peer.h +++ b/core/io/multiplayer_peer.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* networked_multiplayer_peer.h */ +/* multiplayer_peer.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -33,8 +33,8 @@ #include "core/io/packet_peer.h" -class NetworkedMultiplayerPeer : public PacketPeer { - GDCLASS(NetworkedMultiplayerPeer, PacketPeer); +class MultiplayerPeer : public PacketPeer { + GDCLASS(MultiplayerPeer, PacketPeer); protected: static void _bind_methods(); @@ -73,10 +73,10 @@ public: virtual ConnectionStatus get_connection_status() const = 0; - NetworkedMultiplayerPeer() {} + MultiplayerPeer() {} }; -VARIANT_ENUM_CAST(NetworkedMultiplayerPeer::TransferMode) -VARIANT_ENUM_CAST(NetworkedMultiplayerPeer::ConnectionStatus) +VARIANT_ENUM_CAST(MultiplayerPeer::TransferMode) +VARIANT_ENUM_CAST(MultiplayerPeer::ConnectionStatus) #endif // NETWORKED_MULTIPLAYER_PEER_H diff --git a/core/io/resource.cpp b/core/io/resource.cpp index b970e85c99..efa622d976 100644 --- a/core/io/resource.cpp +++ b/core/io/resource.cpp @@ -164,7 +164,7 @@ Ref<Resource> Resource::duplicate_for_local_scene(Node *p_for_scene, Map<Ref<Res List<PropertyInfo> plist; get_property_list(&plist); - Ref<Resource> r = Object::cast_to<Resource>(ClassDB::instance(get_class())); + Ref<Resource> r = Object::cast_to<Resource>(ClassDB::instantiate(get_class())); ERR_FAIL_COND_V(r.is_null(), Ref<Resource>()); r->local_scene = p_for_scene; @@ -224,7 +224,7 @@ Ref<Resource> Resource::duplicate(bool p_subresources) const { List<PropertyInfo> plist; get_property_list(&plist); - Ref<Resource> r = (Resource *)ClassDB::instance(get_class()); + Ref<Resource> r = (Resource *)ClassDB::instantiate(get_class()); ERR_FAIL_COND_V(r.is_null(), Ref<Resource>()); for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) { diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index f83ba30514..0e9815245f 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -704,7 +704,7 @@ Error ResourceLoaderBinary::load() { if (res.is_null()) { //did not replace - Object *obj = ClassDB::instance(t); + Object *obj = ClassDB::instantiate(t); if (!obj) { error = ERR_FILE_CORRUPT; ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, local_path + ":Resource of unrecognized type in file: " + t + "."); diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index 1700766cbf..c5dfe1f2b0 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -1045,7 +1045,7 @@ bool ResourceLoader::add_custom_resource_format_loader(String script_path) { bool valid_type = ClassDB::is_parent_class(ibt, "ResourceFormatLoader"); ERR_FAIL_COND_V_MSG(!valid_type, false, "Script does not inherit a CustomResourceLoader: " + script_path + "."); - Object *obj = ClassDB::instance(ibt); + Object *obj = ClassDB::instantiate(ibt); ERR_FAIL_COND_V_MSG(obj == nullptr, false, "Cannot instance script as custom resource loader, expected 'ResourceFormatLoader' inheritance, got: " + String(ibt) + "."); diff --git a/core/io/resource_saver.cpp b/core/io/resource_saver.cpp index 389a4fdbbd..80cb85fba3 100644 --- a/core/io/resource_saver.cpp +++ b/core/io/resource_saver.cpp @@ -210,7 +210,7 @@ bool ResourceSaver::add_custom_resource_format_saver(String script_path) { bool valid_type = ClassDB::is_parent_class(ibt, "ResourceFormatSaver"); ERR_FAIL_COND_V_MSG(!valid_type, false, "Script does not inherit a CustomResourceSaver: " + script_path + "."); - Object *obj = ClassDB::instance(ibt); + Object *obj = ClassDB::instantiate(ibt); ERR_FAIL_COND_V_MSG(obj == nullptr, false, "Cannot instance script as custom resource saver, expected 'ResourceFormatSaver' inheritance, got: " + String(ibt) + "."); diff --git a/core/io/stream_peer.cpp b/core/io/stream_peer.cpp index ee5e9eca0c..27f8d4e88f 100644 --- a/core/io/stream_peer.cpp +++ b/core/io/stream_peer.cpp @@ -512,7 +512,7 @@ void StreamPeerBuffer::clear() { Ref<StreamPeerBuffer> StreamPeerBuffer::duplicate() const { Ref<StreamPeerBuffer> spb; - spb.instance(); + spb.instantiate(); spb->data = data; return spb; } diff --git a/core/io/tcp_server.cpp b/core/io/tcp_server.cpp index b760a9ef80..5e0c0390f9 100644 --- a/core/io/tcp_server.cpp +++ b/core/io/tcp_server.cpp @@ -43,7 +43,6 @@ Error TCPServer::listen(uint16_t p_port, const IPAddress &p_bind_address) { ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE); ERR_FAIL_COND_V(_sock->is_open(), ERR_ALREADY_IN_USE); ERR_FAIL_COND_V(!p_bind_address.is_valid() && !p_bind_address.is_wildcard(), ERR_INVALID_PARAMETER); - ERR_FAIL_COND_V_MSG(p_port < 0 || p_port > 65535, ERR_INVALID_PARAMETER, "The local port number must be between 0 and 65535 (inclusive)."); Error err; IP::Type ip_type = IP::TYPE_ANY; diff --git a/core/io/udp_server.cpp b/core/io/udp_server.cpp index 6a1af0c2a9..27a1cab721 100644 --- a/core/io/udp_server.cpp +++ b/core/io/udp_server.cpp @@ -91,7 +91,6 @@ Error UDPServer::listen(uint16_t p_port, const IPAddress &p_bind_address) { ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE); ERR_FAIL_COND_V(_sock->is_open(), ERR_ALREADY_IN_USE); ERR_FAIL_COND_V(!p_bind_address.is_valid() && !p_bind_address.is_wildcard(), ERR_INVALID_PARAMETER); - ERR_FAIL_COND_V_MSG(p_port < 0 || p_port > 65535, ERR_INVALID_PARAMETER, "The local port number must be between 0 and 65535 (inclusive)."); Error err; IP::Type ip_type = IP::TYPE_ANY; diff --git a/core/math/geometry_2d.h b/core/math/geometry_2d.h index 4958b5ac6a..a2894bc1d3 100644 --- a/core/math/geometry_2d.h +++ b/core/math/geometry_2d.h @@ -362,6 +362,19 @@ public: return (intersections & 1); } + static bool is_segment_intersecting_polygon(const Vector2 &p_from, const Vector2 &p_to, const Vector<Vector2> &p_polygon) { + int c = p_polygon.size(); + const Vector2 *p = p_polygon.ptr(); + for (int i = 0; i < c; i++) { + const Vector2 &v1 = p[i]; + const Vector2 &v2 = p[(i + 1) % c]; + if (segment_intersects_segment(p_from, p_to, v1, v2, nullptr)) { + return true; + } + } + return false; + } + static real_t vec2_cross(const Point2 &O, const Point2 &A, const Point2 &B) { return (real_t)(A.x - O.x) * (B.y - O.y) - (real_t)(A.y - O.y) * (B.x - O.x); } diff --git a/core/object/SCsub b/core/object/SCsub index 5d429960e5..dc116aeb19 100644 --- a/core/object/SCsub +++ b/core/object/SCsub @@ -2,6 +2,11 @@ Import("env") +import make_virtuals +from platform_methods import run_in_subprocess + +env.CommandNoCache(["gdvirtual.gen.inc"], "make_virtuals.py", run_in_subprocess(make_virtuals.run)) + env_object = env.Clone() env_object.add_source_files(env.core_sources, "*.cpp") diff --git a/core/object/class_db.cpp b/core/object/class_db.cpp index 5bf874ccae..a10405dfae 100644 --- a/core/object/class_db.cpp +++ b/core/object/class_db.cpp @@ -503,9 +503,9 @@ void ClassDB::add_compatibility_class(const StringName &p_class, const StringNam thread_local bool initializing_with_extension = false; thread_local ObjectNativeExtension *initializing_extension = nullptr; -thread_local void *initializing_extension_instance = nullptr; +thread_local GDExtensionClassInstancePtr initializing_extension_instance = nullptr; -void ClassDB::instance_get_native_extension_data(ObjectNativeExtension **r_extension, void **r_extension_instance) { +void ClassDB::instance_get_native_extension_data(ObjectNativeExtension **r_extension, GDExtensionClassInstancePtr *r_extension_instance) { if (initializing_with_extension) { *r_extension = initializing_extension; *r_extension_instance = initializing_extension_instance; @@ -516,7 +516,7 @@ void ClassDB::instance_get_native_extension_data(ObjectNativeExtension **r_exten } } -Object *ClassDB::instance(const StringName &p_class) { +Object *ClassDB::instantiate(const StringName &p_class) { ClassInfo *ti; { OBJTYPE_RLOCK; @@ -539,12 +539,12 @@ Object *ClassDB::instance(const StringName &p_class) { if (ti->native_extension) { initializing_with_extension = true; initializing_extension = ti->native_extension; - initializing_extension_instance = ti->native_extension->create_instance(ti->native_extension->create_instance_userdata); + initializing_extension_instance = ti->native_extension->create_instance(ti->native_extension->class_userdata); } return ti->creation_func(); } -bool ClassDB::can_instance(const StringName &p_class) { +bool ClassDB::can_instantiate(const StringName &p_class) { OBJTYPE_RLOCK; ClassInfo *ti = classes.getptr(p_class); @@ -1522,8 +1522,8 @@ Variant ClassDB::class_get_default_property_value(const StringName &p_class, con if (Engine::get_singleton()->has_singleton(p_class)) { c = Engine::get_singleton()->get_singleton_object(p_class); cleanup_c = false; - } else if (ClassDB::can_instance(p_class)) { - c = ClassDB::instance(p_class); + } else if (ClassDB::can_instantiate(p_class)) { + c = ClassDB::instantiate(p_class); cleanup_c = true; } @@ -1603,6 +1603,11 @@ void ClassDB::register_extension_class(ObjectNativeExtension *p_extension) { classes[p_extension->class_name] = c; } +void ClassDB::unregister_extension_class(const StringName &p_class) { + ERR_FAIL_COND(!classes.has(p_class)); + classes.erase(p_class); +} + RWLock ClassDB::lock; void ClassDB::cleanup_defaults() { diff --git a/core/object/class_db.h b/core/object/class_db.h index 4355c9b0ea..af528bfde7 100644 --- a/core/object/class_db.h +++ b/core/object/class_db.h @@ -204,6 +204,7 @@ public: } static void register_extension_class(ObjectNativeExtension *p_extension); + static void unregister_extension_class(const StringName &p_class); template <class T> static Object *_create_ptr_func() { @@ -230,9 +231,10 @@ public: static StringName get_compatibility_remapped_class(const StringName &p_class); static bool class_exists(const StringName &p_class); static bool is_parent_class(const StringName &p_class, const StringName &p_inherits); - static bool can_instance(const StringName &p_class); - static Object *instance(const StringName &p_class); - static void instance_get_native_extension_data(ObjectNativeExtension **r_extension, void **r_extension_instance); + static bool can_instantiate(const StringName &p_class); + static Object *instantiate(const StringName &p_class); + static void instance_get_native_extension_data(ObjectNativeExtension **r_extension, GDExtensionClassInstancePtr *r_extension_instance); + static APIType get_api_type(const StringName &p_class); static uint64_t get_api_hash(APIType p_api); diff --git a/core/object/make_virtuals.py b/core/object/make_virtuals.py new file mode 100644 index 0000000000..2c6b8cddc9 --- /dev/null +++ b/core/object/make_virtuals.py @@ -0,0 +1,152 @@ +proto = """ +#define GDVIRTUAL$VER($RET m_name $ARG) \\ +GDNativeExtensionClassCallVirtual _gdvirtual_##m_name = (_get_extension() && _get_extension()->get_virtual) ? _get_extension()->get_virtual(_get_extension()->class_userdata, #m_name) : (GDNativeExtensionClassCallVirtual) nullptr;\\ +StringName _gdvirtual_##m_name##_sn = #m_name;\\ +bool _gdvirtual_##m_name##_call($CALLARGS) $CONST { \\ + ScriptInstance *script_instance = ((Object*)(this))->get_script_instance();\\ + if (script_instance) {\\ + Callable::CallError ce; \\ + $CALLSIARGS\\ + $CALLSIBEGINscript_instance->call(_gdvirtual_##m_name##_sn, $CALLSIARGPASS, ce);\\ + if (ce.error == Callable::CallError::CALL_OK) {\\ + $CALLSIRET\\ + return true;\\ + } \\ + }\\ + if (_gdvirtual_##m_name) {\\ + $CALLPTRARGS\\ + $CALLPTRRETDEF\\ + _gdvirtual_##m_name(_get_extension_instance(),$CALLPTRARGPASS,$CALLPTRRETPASS);\\ + $CALLPTRRET\\ + return true;\\ + }\\ +\\ + return false;\\ +}\\ +\\ +_FORCE_INLINE_ static MethodInfo _gdvirtual_##m_name##_get_method_info() { \\ + MethodInfo method_info;\\ + method_info.name = #m_name;\\ + method_info.flags = METHOD_FLAG_VIRTUAL;\\ + $FILL_METHOD_INFO\\ + return method_info;\\ +} + + +""" + + +def generate_version(argcount, const=False, returns=False): + s = proto + sproto = str(argcount) + method_info = "" + if returns: + sproto += "R" + s = s.replace("$RET", "m_ret, ") + s = s.replace("$CALLPTRRETDEF", "PtrToArg<m_ret>::EncodeT ret;") + method_info += "\tmethod_info.return_val = GetTypeInfo<m_ret>::get_class_info();\\\n" + else: + s = s.replace("$RET", "") + s = s.replace("$CALLPTRRETDEF", "") + + if const: + sproto += "C" + s = s.replace("$CONST", "const") + method_info += "\tmethod_info.flags|=METHOD_FLAG_CONST;\\\n" + else: + s = s.replace("$CONST", "") + + s = s.replace("$VER", sproto) + argtext = "" + callargtext = "" + callsiargs = "" + callsiargptrs = "" + callptrargsptr = "" + if argcount > 0: + argtext += ", " + callsiargs = "Variant vargs[" + str(argcount) + "]={" + callsiargptrs = "\t\tconst Variant *vargptrs[" + str(argcount) + "]={" + callptrargsptr = "\t\tconst GDNativeTypePtr argptrs[" + str(argcount) + "]={" + callptrargs = "" + for i in range(argcount): + if i > 0: + argtext += ", " + callargtext += ", " + callsiargs += ", " + callsiargptrs += ", " + callptrargs += "\t\t" + callptrargsptr += ", " + argtext += "m_type" + str(i + 1) + callargtext += "const m_type" + str(i + 1) + "& arg" + str(i + 1) + callsiargs += "Variant(arg" + str(i + 1) + ")" + callsiargptrs += "&vargs[" + str(i) + "]" + callptrargs += ( + "PtrToArg<m_type" + str(i + 1) + ">::EncodeT argval" + str(i + 1) + " = arg" + str(i + 1) + ";\\\n" + ) + callptrargsptr += "&argval" + str(i + 1) + method_info += "\tmethod_info.arguments.push_back(GetTypeInfo<m_type" + str(i + 1) + ">::get_class_info());\\\n" + + if argcount: + callsiargs += "};\\\n" + callsiargptrs += "};\\\n" + s = s.replace("$CALLSIARGS", callsiargs + callsiargptrs) + s = s.replace("$CALLSIARGPASS", "(const Variant **)vargptrs," + str(argcount)) + callptrargsptr += "};\\\n" + s = s.replace("$CALLPTRARGS", callptrargs + callptrargsptr) + s = s.replace("$CALLPTRARGPASS", "(const GDNativeTypePtr*)argptrs") + else: + s = s.replace("$CALLSIARGS", "") + s = s.replace("$CALLSIARGPASS", "nullptr, 0") + s = s.replace("$CALLPTRARGS", "") + s = s.replace("$CALLPTRARGPASS", "nullptr") + + if returns: + if argcount > 0: + callargtext += "," + callargtext += " m_ret& r_ret" + s = s.replace("$CALLSIBEGIN", "Variant ret = ") + s = s.replace("$CALLSIRET", "r_ret = ret;") + s = s.replace("$CALLPTRRETPASS", "&ret") + s = s.replace("$CALLPTRRET", "r_ret = ret;") + else: + s = s.replace("$CALLSIBEGIN", "") + s = s.replace("$CALLSIRET", "") + s = s.replace("$CALLPTRRETPASS", "nullptr") + s = s.replace("$CALLPTRRET", "") + + s = s.replace("$ARG", argtext) + s = s.replace("$CALLARGS", callargtext) + s = s.replace("$FILL_METHOD_INFO", method_info) + + return s + + +def run(target, source, env): + + max_versions = 12 + + txt = """ +#ifndef GDVIRTUAL_GEN_H +#define GDVIRTUAL_GEN_H + + +""" + + for i in range(max_versions + 1): + + txt += "/* " + str(i) + " Arguments */\n\n" + txt += generate_version(i, False, False) + txt += generate_version(i, False, True) + txt += generate_version(i, True, False) + txt += generate_version(i, True, True) + + txt += "#endif" + + with open(target[0], "w") as f: + f.write(txt) + + +if __name__ == "__main__": + from platform_methods import subprocess_main + + subprocess_main(globals()) diff --git a/core/object/method_bind.cpp b/core/object/method_bind.cpp index 9c5ed60708..c53104fe3f 100644 --- a/core/object/method_bind.cpp +++ b/core/object/method_bind.cpp @@ -34,6 +34,35 @@ #include "method_bind.h" +uint32_t MethodBind::get_hash() const { + uint32_t hash = hash_djb2_one_32(has_return() ? 1 : 0); + hash = hash_djb2_one_32(get_argument_count(), hash); + +#ifndef _MSC_VER +#warning This needs proper class name and argument type for hashing +#endif +#if 0 + + for (int i = (has_return() ? -1 : 0); i < get_argument_count(); i++) { + PropertyInfo pi = i == -1 ? get_return_info() : get_argument_info(i); + hash = hash_djb2_one_32(get_argument_type(i), hash); + if (pi.class_name != StringName()) { + hash = hash_djb2_one_32(pi.class_name.operator String().hash(), hash); + } + } +#endif + hash = hash_djb2_one_32(get_default_argument_count(), hash); + for (int i = 0; i < get_default_argument_count(); i++) { + Variant v = get_default_argument(i); + hash = hash_djb2_one_32(v.hash(), hash); + } + + hash = hash_djb2_one_32(is_const(), hash); + hash = hash_djb2_one_32(is_vararg(), hash); + + return hash; +} + #ifdef DEBUG_METHODS_ENABLED PropertyInfo MethodBind::get_argument_info(int p_argument) const { ERR_FAIL_INDEX_V(p_argument, get_argument_count(), PropertyInfo()); diff --git a/core/object/method_bind.h b/core/object/method_bind.h index 7030ae201b..92b964772a 100644 --- a/core/object/method_bind.h +++ b/core/object/method_bind.h @@ -135,6 +135,8 @@ public: void set_default_arguments(const Vector<Variant> &p_defargs); + uint32_t get_hash() const; + MethodBind(); virtual ~MethodBind(); }; diff --git a/core/object/object.cpp b/core/object/object.cpp index 799e63a512..296d876701 100644 --- a/core/object/object.cpp +++ b/core/object/object.cpp @@ -386,12 +386,20 @@ void Object::set(const StringName &p_name, const Variant &p_value, bool *r_valid } if (_extension && _extension->set) { - if (_extension->set(_extension_instance, &p_name, &p_value)) { +// C style pointer casts should never trigger a compiler warning because the risk is assumed by the user, so GCC should keep quiet about it. +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wignored-qualifiers" +#endif + if (_extension->set(_extension_instance, (const GDNativeStringNamePtr)&p_name, (const GDNativeVariantPtr)&p_value)) { if (r_valid) { *r_valid = true; } return; } +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic pop +#endif } //try built-in setgetter @@ -459,14 +467,22 @@ Variant Object::get(const StringName &p_name, bool *r_valid) const { return ret; } } - if (_extension && _extension->get) { - if (_extension->get(_extension_instance, &p_name, &ret)) { +// C style pointer casts should never trigger a compiler warning because the risk is assumed by the user, so GCC should keep quiet about it. +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wignored-qualifiers" +#endif + + if (_extension->get(_extension_instance, (const GDNativeStringNamePtr)&p_name, (GDNativeVariantPtr)&ret)) { if (r_valid) { *r_valid = true; } return ret; } +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic pop +#endif } //try built-in setgetter @@ -616,7 +632,7 @@ void Object::get_property_list(List<PropertyInfo> *p_list, bool p_reversed) cons if (_extension && _extension->get_property_list) { uint32_t pcount; - const ObjectNativeExtension::PInfo *pinfo = _extension->get_property_list(_extension_instance, &pcount); + const GDNativePropertyInfo *pinfo = _extension->get_property_list(_extension_instance, &pcount); for (uint32_t i = 0; i < pcount; i++) { p_list->push_back(PropertyInfo(Variant::Type(pinfo[i].type), pinfo[i].class_name, PropertyHint(pinfo[i].hint), pinfo[i].hint_string, pinfo[i].usage, pinfo[i].class_name)); } @@ -871,7 +887,7 @@ void Object::set_script(const Variant &p_script) { Ref<Script> s = script; if (!s.is_null()) { - if (s->can_instance()) { + if (s->can_instantiate()) { OBJ_DEBUG_LOCK script_instance = s->instance_create(this); } else if (Engine::get_singleton()->is_editor_hint()) { @@ -920,7 +936,7 @@ void Object::set_meta(const String &p_name, const Variant &p_value) { } Variant Object::get_meta(const String &p_name) const { - ERR_FAIL_COND_V(!metadata.has(p_name), Variant()); + ERR_FAIL_COND_V_MSG(!metadata.has(p_name), Variant(), "The object does not have any 'meta' values with the key '" + p_name + "'."); return metadata[p_name]; } @@ -1287,10 +1303,10 @@ void Object::get_signals_connected_to_this(List<Connection> *p_connections) cons } Error Object::connect(const StringName &p_signal, const Callable &p_callable, const Vector<Variant> &p_binds, uint32_t p_flags) { - ERR_FAIL_COND_V(p_callable.is_null(), ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V_MSG(p_callable.is_null(), ERR_INVALID_PARAMETER, "Cannot connect to '" + p_signal + "': the provided callable is null."); Object *target_object = p_callable.get_object(); - ERR_FAIL_COND_V(!target_object, ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V_MSG(!target_object, ERR_INVALID_PARAMETER, "Cannot connect to '" + p_signal + "' to callable '" + p_callable + "': the callable object is null."); SignalData *s = signal_map.getptr(p_signal); if (!s) { @@ -1348,7 +1364,7 @@ Error Object::connect(const StringName &p_signal, const Callable &p_callable, co } bool Object::is_connected(const StringName &p_signal, const Callable &p_callable) const { - ERR_FAIL_COND_V(p_callable.is_null(), false); + ERR_FAIL_COND_V_MSG(p_callable.is_null(), false, "Cannot determine if connected to '" + p_signal + "': the provided callable is null."); const SignalData *s = signal_map.getptr(p_signal); if (!s) { bool signal_is_valid = ClassDB::has_signal(get_class_name(), p_signal); @@ -1375,10 +1391,10 @@ void Object::disconnect(const StringName &p_signal, const Callable &p_callable) } void Object::_disconnect(const StringName &p_signal, const Callable &p_callable, bool p_force) { - ERR_FAIL_COND(p_callable.is_null()); + ERR_FAIL_COND_MSG(p_callable.is_null(), "Cannot disconnect from '" + p_signal + "': the provided callable is null."); Object *target_object = p_callable.get_object(); - ERR_FAIL_COND(!target_object); + ERR_FAIL_COND_MSG(!target_object, "Cannot disconnect '" + p_signal + "' from callable '" + p_callable + "': the callable object is null."); SignalData *s = signal_map.getptr(p_signal); if (!s) { @@ -1753,42 +1769,41 @@ uint32_t Object::get_edited_version() const { } #endif -void *Object::get_script_instance_binding(int p_script_language_index) { -#ifdef DEBUG_ENABLED - ERR_FAIL_INDEX_V(p_script_language_index, MAX_SCRIPT_INSTANCE_BINDINGS, nullptr); -#endif - - //it's up to the script language to make this thread safe, if the function is called twice due to threads being out of sync - //just return the same pointer. - //if you want to put a big lock in the entire function and keep allocated pointers in a map or something, feel free to do it - //as it should not really affect performance much (won't be called too often), as in far most cases the condition below will be false afterwards - - if (!_script_instance_bindings[p_script_language_index]) { - void *script_data = ScriptServer::get_language(p_script_language_index)->alloc_instance_binding_data(this); - if (script_data) { - instance_binding_count.increment(); - _script_instance_bindings[p_script_language_index] = script_data; +void *Object::get_instance_binding(void *p_token, const GDNativeInstanceBindingCallbacks *p_callbacks) { + void *binding = nullptr; + _instance_binding_mutex.lock(); + for (uint32_t i = 0; i < _instance_binding_count; i++) { + if (_instance_bindings[i].token == p_token) { + binding = _instance_bindings[i].binding; + break; } } + if (unlikely(!binding)) { + uint32_t current_size = next_power_of_2(_instance_binding_count); + uint32_t new_size = next_power_of_2(_instance_binding_count + 1); - return _script_instance_bindings[p_script_language_index]; -} + if (current_size == 0 || new_size > current_size) { + _instance_bindings = (InstanceBinding *)memrealloc(_instance_bindings, new_size * sizeof(InstanceBinding)); + } -bool Object::has_script_instance_binding(int p_script_language_index) { - return _script_instance_bindings[p_script_language_index] != nullptr; -} + _instance_bindings[_instance_binding_count].free_callback = p_callbacks->free_callback; + _instance_bindings[_instance_binding_count].reference_callback = p_callbacks->reference_callback; + _instance_bindings[_instance_binding_count].token = p_token; -void Object::set_script_instance_binding(int p_script_language_index, void *p_data) { -#ifdef DEBUG_ENABLED - CRASH_COND(_script_instance_bindings[p_script_language_index] != nullptr); -#endif - _script_instance_bindings[p_script_language_index] = p_data; + binding = p_callbacks->create_callback(p_token, this); + _instance_bindings[_instance_binding_count].binding = binding; + + _instance_binding_count++; + } + + _instance_binding_mutex.unlock(); + + return binding; } void Object::_construct_object(bool p_reference) { type_is_reference = p_reference; _instance_id = ObjectDB::add_instance(this); - memset(_script_instance_bindings, 0, sizeof(void *) * MAX_SCRIPT_INSTANCE_BINDINGS); ClassDB::instance_get_native_extension_data(&_extension, &_extension_instance); @@ -1812,7 +1827,7 @@ Object::~Object() { script_instance = nullptr; if (_extension && _extension->free_instance) { - _extension->free_instance(_extension->create_instance_userdata, _extension_instance); + _extension->free_instance(_extension->class_userdata, _extension_instance); _extension = nullptr; _extension_instance = nullptr; } @@ -1848,12 +1863,13 @@ Object::~Object() { _instance_id = ObjectID(); _predelete_ok = 2; - if (!ScriptServer::are_languages_finished()) { - for (int i = 0; i < MAX_SCRIPT_INSTANCE_BINDINGS; i++) { - if (_script_instance_bindings[i]) { - ScriptServer::get_language(i)->free_instance_binding_data(_script_instance_bindings[i]); + if (_instance_bindings != nullptr) { + for (uint32_t i = 0; i < _instance_binding_count; i++) { + if (_instance_bindings[i].free_callback) { + _instance_bindings[i].free_callback(_instance_bindings[i].token, _instance_bindings[i].binding, this); } } + memfree(_instance_bindings); } } @@ -1871,7 +1887,6 @@ void ObjectDB::debug_objects(DebugFunc p_func) { for (uint32_t i = 0, count = slot_count; i < slot_max && count != 0; i++) { if (object_slots[i].validator) { p_func(object_slots[i].object); - count--; } } diff --git a/core/object/object.h b/core/object/object.h index 65621a47ca..8389d80afc 100644 --- a/core/object/object.h +++ b/core/object/object.h @@ -31,6 +31,7 @@ #ifndef OBJECT_H #define OBJECT_H +#include "core/extension/gdnative_interface.h" #include "core/object/object_id.h" #include "core/os/rw_lock.h" #include "core/os/spin_lock.h" @@ -57,8 +58,7 @@ enum PropertyHint { PROPERTY_HINT_NONE, ///< no hint provided. - PROPERTY_HINT_RANGE, ///< hint_text = "min,max,step,slider; //slider is optional" - PROPERTY_HINT_EXP_RANGE, ///< hint_text = "min,max,step", exponential edit + PROPERTY_HINT_RANGE, ///< hint_text = "min,max[,step][,or_greater][,or_lesser][,noslider][,radians][,degrees][,exp][,suffix:<keyword>] range. PROPERTY_HINT_ENUM, ///< hint_text= "val1,val2,val3,etc" PROPERTY_HINT_EXP_EASING, /// exponential easing function (Math::ease) use "attenuation" hint string to revert (flip h), "full" to also include in/out. (ie: "attenuation,inout") PROPERTY_HINT_LENGTH, ///< hint_text= "length" (as integer) @@ -151,7 +151,7 @@ struct PropertyInfo { String hint_string; uint32_t usage = PROPERTY_USAGE_DEFAULT; - _FORCE_INLINE_ PropertyInfo added_usage(int p_fl) const { + _FORCE_INLINE_ PropertyInfo added_usage(uint32_t p_fl) const { PropertyInfo pi = *this; pi.usage |= p_fl; return pi; @@ -163,7 +163,7 @@ struct PropertyInfo { PropertyInfo() {} - PropertyInfo(Variant::Type p_type, const String p_name, PropertyHint p_hint = PROPERTY_HINT_NONE, const String &p_hint_string = "", uint32_t p_usage = PROPERTY_USAGE_DEFAULT, const StringName &p_class_name = StringName()) : + PropertyInfo(const Variant::Type p_type, const String p_name, const PropertyHint p_hint = PROPERTY_HINT_NONE, const String &p_hint_string = "", const uint32_t p_usage = PROPERTY_USAGE_DEFAULT, const StringName &p_class_name = StringName()) : type(p_type), name(p_name), hint(p_hint), @@ -244,29 +244,18 @@ class MethodBind; struct ObjectNativeExtension { ObjectNativeExtension *parent = nullptr; + List<ObjectNativeExtension *> children; StringName parent_class_name; StringName class_name; bool editor_class = false; - bool (*set)(void *instance, const void *name, const void *value) = nullptr; - bool (*get)(void *instance, const void *name, void *ret_variant) = nullptr; - struct PInfo { - uint32_t type; - const char *name; - const char *class_name; - uint32_t hint; - const char *hint_string; - uint32_t usage; - }; - const PInfo *(*get_property_list)(void *instance, uint32_t *count) = nullptr; - void (*free_property_list)(void *instance, const PInfo *) = nullptr; - - //call is not used, as all methods registered in ClassDB - - void (*notification)(void *instance, int32_t what) = nullptr; - const char *(*to_string)(void *instance) = nullptr; - - void (*reference)(void *instance) = nullptr; - void (*unreference)(void *instance) = nullptr; + GDNativeExtensionClassSet set; + GDNativeExtensionClassGet get; + GDNativeExtensionClassGetPropertyList get_property_list; + GDNativeExtensionClassFreePropertyList free_property_list; + GDNativeExtensionClassNotification notification; + GDNativeExtensionClassToString to_string; + GDNativeExtensionClassReference reference; + GDNativeExtensionClassReference unreference; _FORCE_INLINE_ bool is_class(const String &p_class) const { const ObjectNativeExtension *e = this; @@ -278,11 +267,16 @@ struct ObjectNativeExtension { } return false; } - void *create_instance_userdata = nullptr; - void *(*create_instance)(void *create_instance_userdata) = nullptr; - void (*free_instance)(void *create_instance_userdata, void *instance) = nullptr; + void *class_userdata = nullptr; + + GDNativeExtensionClassCreateInstance create_instance; + GDNativeExtensionClassFreeInstance free_instance; + GDNativeExtensionClassGetVirtual get_virtual; }; +#define GDVIRTUAL_CALL(m_name, ...) _gdvirtual_##m_name##_call(__VA_ARGS__) +#define GDVIRTUAL_BIND(m_name) ClassDB::add_virtual_method(get_class_static(), _gdvirtual_##m_name##_get_method_info()); + /* the following is an incomprehensible blob of hacks and workarounds to compensate for many of the fallencies in C++. As a plus, this macro pretty much alone defines the object model. */ @@ -486,10 +480,6 @@ public: }; private: - enum { - MAX_SCRIPT_INSTANCE_BINDINGS = 8 - }; - #ifdef DEBUG_ENABLED friend struct _ObjectDebugLock; #endif @@ -497,7 +487,7 @@ private: friend void postinitialize_handler(Object *); ObjectNativeExtension *_extension = nullptr; - void *_extension_instance = nullptr; + GDExtensionClassInstancePtr _extension_instance = nullptr; struct SignalData { struct Slot { @@ -548,14 +538,38 @@ private: friend class RefCounted; bool type_is_reference = false; - SafeNumeric<uint32_t> instance_binding_count; - void *_script_instance_bindings[MAX_SCRIPT_INSTANCE_BINDINGS]; + + std::mutex _instance_binding_mutex; + struct InstanceBinding { + void *binding; + void *token; + GDNativeInstanceBindingFreeCallback free_callback = nullptr; + GDNativeInstanceBindingReferenceCallback reference_callback = nullptr; + }; + InstanceBinding *_instance_bindings = nullptr; + uint32_t _instance_binding_count = 0; Object(bool p_reference); protected: + _FORCE_INLINE_ bool _instance_binding_reference(bool p_reference) { + bool can_die = true; + if (_instance_bindings) { + _instance_binding_mutex.lock(); + for (uint32_t i = 0; i < _instance_binding_count; i++) { + if (_instance_bindings[i].reference_callback) { + if (!_instance_bindings[i].reference_callback(_instance_bindings[i].token, _instance_bindings[i].binding, p_reference)) { + can_die = false; + } + } + } + _instance_binding_mutex.unlock(); + } + return can_die; + } + friend class NativeExtensionMethodBind; _ALWAYS_INLINE_ const ObjectNativeExtension *_get_extension() const { return _extension; } - _ALWAYS_INLINE_ void *_get_extension_instance() const { return _extension_instance; } + _ALWAYS_INLINE_ GDExtensionClassInstancePtr _get_extension_instance() const { return _extension_instance; } virtual void _initialize_classv() { initialize_class(); } virtual bool _setv(const StringName &p_name, const Variant &p_property) { return false; }; virtual bool _getv(const StringName &p_name, Variant &r_property) const { return false; }; @@ -790,9 +804,7 @@ public: #endif //used by script languages to store binding data - void *get_script_instance_binding(int p_script_language_index); - bool has_script_instance_binding(int p_script_language_index); - void set_script_instance_binding(int p_script_language_index, void *p_data); + void *get_instance_binding(void *p_token, const GDNativeInstanceBindingCallbacks *p_callbacks); void clear_internal_resource_paths(); diff --git a/core/object/ref_counted.cpp b/core/object/ref_counted.cpp index 9862624972..2833f774dc 100644 --- a/core/object/ref_counted.cpp +++ b/core/object/ref_counted.cpp @@ -65,13 +65,8 @@ bool RefCounted::reference() { if (_get_extension() && _get_extension()->reference) { _get_extension()->reference(_get_extension_instance()); } - if (instance_binding_count.get() > 0 && !ScriptServer::are_languages_finished()) { - for (int i = 0; i < MAX_SCRIPT_INSTANCE_BINDINGS; i++) { - if (_script_instance_bindings[i]) { - ScriptServer::get_language(i)->refcount_incremented_instance_binding(this); - } - } - } + + _instance_binding_reference(true); } return success; @@ -89,14 +84,8 @@ bool RefCounted::unreference() { if (_get_extension() && _get_extension()->unreference) { _get_extension()->unreference(_get_extension_instance()); } - if (instance_binding_count.get() > 0 && !ScriptServer::are_languages_finished()) { - for (int i = 0; i < MAX_SCRIPT_INSTANCE_BINDINGS; i++) { - if (_script_instance_bindings[i]) { - bool script_ret = ScriptServer::get_language(i)->refcount_decremented_instance_binding(this); - die = die && script_ret; - } - } - } + + die = die && _instance_binding_reference(false); } return die; diff --git a/core/object/ref_counted.h b/core/object/ref_counted.h index 3dd7cc456b..e0af2c18bb 100644 --- a/core/object/ref_counted.h +++ b/core/object/ref_counted.h @@ -213,7 +213,7 @@ public: inline bool is_null() const { return reference == nullptr; } void unref() { - //TODO this should be moved to mutexes, since this engine does not really + // TODO: this should be moved to mutexes, since this engine does not really // do a lot of referencing on references and stuff // mutexes will avoid more crashes? @@ -223,7 +223,7 @@ public: reference = nullptr; } - void instance() { + void instantiate() { ref(memnew(T)); } @@ -258,6 +258,8 @@ struct PtrToArg<Ref<T>> { return Ref<T>(const_cast<T *>(reinterpret_cast<const T *>(p_ptr))); } + typedef Ref<T> EncodeT; + _FORCE_INLINE_ static void encode(Ref<T> p_val, const void *p_ptr) { *(Ref<RefCounted> *)p_ptr = p_val; } @@ -265,6 +267,8 @@ struct PtrToArg<Ref<T>> { template <class T> struct PtrToArg<const Ref<T> &> { + typedef Ref<T> EncodeT; + _FORCE_INLINE_ static Ref<T> convert(const void *p_ptr) { return Ref<T>((T *)p_ptr); } diff --git a/core/object/script_language.cpp b/core/object/script_language.cpp index dd6bc09abb..626a7413e7 100644 --- a/core/object/script_language.cpp +++ b/core/object/script_language.cpp @@ -100,7 +100,7 @@ Dictionary Script::_get_script_constant_map() { } void Script::_bind_methods() { - ClassDB::bind_method(D_METHOD("can_instance"), &Script::can_instance); + ClassDB::bind_method(D_METHOD("can_instantiate"), &Script::can_instantiate); //ClassDB::bind_method(D_METHOD("instance_create","base_object"),&Script::instance_create); ClassDB::bind_method(D_METHOD("instance_has", "base_object"), &Script::instance_has); ClassDB::bind_method(D_METHOD("has_source_code"), &Script::has_source_code); diff --git a/core/object/script_language.h b/core/object/script_language.h index a22e91870e..2cbaa0f52e 100644 --- a/core/object/script_language.h +++ b/core/object/script_language.h @@ -115,7 +115,7 @@ protected: Dictionary _get_script_constant_map(); public: - virtual bool can_instance() const = 0; + virtual bool can_instantiate() const = 0; virtual Ref<Script> get_base_script() const = 0; //for script inheritance @@ -268,6 +268,12 @@ public: String message; }; + struct ScriptError { + int line = -1; + int column = -1; + String message; + }; + void get_core_type_words(List<String> *p_core_type_words) const; virtual void get_reserved_words(List<String> *p_words) const = 0; virtual bool is_control_flow_keyword(String p_string) const = 0; @@ -276,7 +282,7 @@ public: virtual Ref<Script> get_template(const String &p_class_name, const String &p_base_class_name) const = 0; virtual void make_template(const String &p_class_name, const String &p_base_class_name, Ref<Script> &p_script) {} virtual bool is_using_templates() { return false; } - virtual bool validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path = "", List<String> *r_functions = nullptr, List<Warning> *r_warnings = nullptr, Set<int> *r_safe_lines = nullptr) const = 0; + virtual bool validate(const String &p_script, const String &p_path = "", List<String> *r_functions = nullptr, List<ScriptError> *r_errors = nullptr, List<Warning> *r_warnings = nullptr, Set<int> *r_safe_lines = nullptr) const = 0; virtual String validate_path(const String &p_path) const { return ""; } virtual Script *create_script() const = 0; virtual bool has_named_classes() const = 0; diff --git a/core/os/midi_driver.cpp b/core/os/midi_driver.cpp index a8be84c56c..ee87346dfc 100644 --- a/core/os/midi_driver.cpp +++ b/core/os/midi_driver.cpp @@ -45,23 +45,23 @@ void MIDIDriver::set_singleton() { void MIDIDriver::receive_input_packet(uint64_t timestamp, uint8_t *data, uint32_t length) { Ref<InputEventMIDI> event; - event.instance(); + event.instantiate(); uint32_t param_position = 1; if (length >= 1) { if (data[0] >= 0xF0) { // channel does not apply to system common messages event->set_channel(0); - event->set_message(data[0]); + event->set_message(MIDIMessage(data[0])); last_received_message = data[0]; } else if ((data[0] & 0x80) == 0x00) { // running status event->set_channel(last_received_message & 0xF); - event->set_message(last_received_message >> 4); + event->set_message(MIDIMessage(last_received_message >> 4)); param_position = 0; } else { event->set_channel(data[0] & 0xF); - event->set_message(data[0] >> 4); + event->set_message(MIDIMessage(data[0] >> 4)); param_position = 1; last_received_message = data[0]; } @@ -112,6 +112,8 @@ void MIDIDriver::receive_input_packet(uint64_t timestamp, uint8_t *data, uint32_ event->set_pressure(data[param_position]); } break; + default: + break; } Input *id = Input::get_singleton(); diff --git a/core/os/os.h b/core/os/os.h index 444f67431f..301718a8b3 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -58,8 +58,6 @@ class OS { int _orientation; bool _allow_hidpi = false; bool _allow_layered = false; - bool _use_vsync; - bool _vsync_via_compositor; bool _stdout_enabled = true; bool _stderr_enabled = true; diff --git a/core/register_core_types.cpp b/core/register_core_types.cpp index f67d615418..0739a0336d 100644 --- a/core/register_core_types.cpp +++ b/core/register_core_types.cpp @@ -37,6 +37,8 @@ #include "core/crypto/aes_context.h" #include "core/crypto/crypto.h" #include "core/crypto/hashing_context.h" +#include "core/extension/native_extension.h" +#include "core/extension/native_extension_manager.h" #include "core/input/input.h" #include "core/input/input_map.h" #include "core/io/config_file.h" @@ -46,7 +48,7 @@ #include "core/io/json.h" #include "core/io/marshalls.h" #include "core/io/multiplayer_api.h" -#include "core/io/networked_multiplayer_peer.h" +#include "core/io/multiplayer_peer.h" #include "core/io/packed_data_container.h" #include "core/io/packet_peer.h" #include "core/io/packet_peer_dtls.h" @@ -86,7 +88,6 @@ static _OS *_os = nullptr; static _Engine *_engine = nullptr; static _ClassDB *_classdb = nullptr; static _Marshalls *_marshalls = nullptr; -static _JSON *_json = nullptr; static _EngineDebugger *_engine_debugger = nullptr; static IP *ip = nullptr; @@ -96,6 +97,8 @@ static _Geometry3D *_geometry_3d = nullptr; extern Mutex _global_mutex; +static NativeExtensionManager *native_extension_manager = nullptr; + extern void register_global_constants(); extern void unregister_global_constants(); @@ -114,18 +117,18 @@ void register_core_types() { CoreStringNames::create(); - resource_format_po.instance(); + resource_format_po.instantiate(); ResourceLoader::add_resource_format_loader(resource_format_po); - resource_saver_binary.instance(); + resource_saver_binary.instantiate(); ResourceSaver::add_resource_format_saver(resource_saver_binary); - resource_loader_binary.instance(); + resource_loader_binary.instantiate(); ResourceLoader::add_resource_format_loader(resource_loader_binary); - resource_format_importer.instance(); + resource_format_importer.instantiate(); ResourceLoader::add_resource_format_loader(resource_format_importer); - resource_format_image.instance(); + resource_format_image.instantiate(); ResourceLoader::add_resource_format_loader(resource_format_image); ClassDB::register_class<Object>(); @@ -154,14 +157,20 @@ void register_core_types() { ClassDB::register_class<InputEventPanGesture>(); ClassDB::register_class<InputEventMIDI>(); + // Network + ClassDB::register_virtual_class<IP>(); + ClassDB::register_virtual_class<StreamPeer>(); ClassDB::register_class<StreamPeerBuffer>(); ClassDB::register_class<StreamPeerTCP>(); ClassDB::register_class<TCPServer>(); + + ClassDB::register_virtual_class<PacketPeer>(); + ClassDB::register_class<PacketPeerStream>(); ClassDB::register_class<PacketPeerUDP>(); ClassDB::register_class<UDPServer>(); - ClassDB::register_custom_instance_class<PacketPeerDTLS>(); - ClassDB::register_custom_instance_class<DTLSServer>(); + + ClassDB::register_custom_instance_class<HTTPClient>(); // Crypto ClassDB::register_class<HashingContext>(); @@ -171,22 +180,20 @@ void register_core_types() { ClassDB::register_custom_instance_class<HMACContext>(); ClassDB::register_custom_instance_class<Crypto>(); ClassDB::register_custom_instance_class<StreamPeerSSL>(); + ClassDB::register_custom_instance_class<PacketPeerDTLS>(); + ClassDB::register_custom_instance_class<DTLSServer>(); - resource_format_saver_crypto.instance(); + resource_format_saver_crypto.instantiate(); ResourceSaver::add_resource_format_saver(resource_format_saver_crypto); - resource_format_loader_crypto.instance(); + resource_format_loader_crypto.instantiate(); ResourceLoader::add_resource_format_loader(resource_format_loader_crypto); - ClassDB::register_virtual_class<IP>(); - ClassDB::register_virtual_class<PacketPeer>(); - ClassDB::register_class<PacketPeerStream>(); - ClassDB::register_virtual_class<NetworkedMultiplayerPeer>(); + ClassDB::register_virtual_class<MultiplayerPeer>(); ClassDB::register_class<MultiplayerAPI>(); ClassDB::register_class<MainLoop>(); ClassDB::register_class<Translation>(); ClassDB::register_class<OptimizedTranslation>(); ClassDB::register_class<UndoRedo>(); - ClassDB::register_class<HTTPClient>(); ClassDB::register_class<TriangleMesh>(); ClassDB::register_class<ResourceFormatLoader>(); @@ -199,7 +206,7 @@ void register_core_types() { ClassDB::register_class<_Semaphore>(); ClassDB::register_class<XMLParser>(); - ClassDB::register_class<JSONParser>(); + ClassDB::register_class<JSON>(); ClassDB::register_class<ConfigFile>(); @@ -212,10 +219,14 @@ void register_core_types() { ClassDB::register_class<EncodedObjectAsID>(); ClassDB::register_class<RandomNumberGenerator>(); - ClassDB::register_class<JSONParseResult>(); - ClassDB::register_virtual_class<ResourceImporter>(); + ClassDB::register_class<NativeExtension>(); + + ClassDB::register_virtual_class<NativeExtensionManager>(); + + native_extension_manager = memnew(NativeExtensionManager); + ip = IP::create(); _geometry_2d = memnew(_Geometry2D); @@ -227,7 +238,6 @@ void register_core_types() { _engine = memnew(_Engine); _classdb = memnew(_ClassDB); _marshalls = memnew(_Marshalls); - _json = memnew(_JSON); _engine_debugger = memnew(_EngineDebugger); } @@ -256,13 +266,12 @@ void register_core_singletons() { ClassDB::register_class<TranslationServer>(); ClassDB::register_virtual_class<Input>(); ClassDB::register_class<InputMap>(); - ClassDB::register_class<_JSON>(); ClassDB::register_class<Expression>(); ClassDB::register_class<_EngineDebugger>(); ClassDB::register_class<Time>(); Engine::get_singleton()->add_singleton(Engine::Singleton("ProjectSettings", ProjectSettings::get_singleton())); - Engine::get_singleton()->add_singleton(Engine::Singleton("IP", IP::get_singleton())); + Engine::get_singleton()->add_singleton(Engine::Singleton("IP", IP::get_singleton(), "IP")); Engine::get_singleton()->add_singleton(Engine::Singleton("Geometry2D", _Geometry2D::get_singleton())); Engine::get_singleton()->add_singleton(Engine::Singleton("Geometry3D", _Geometry3D::get_singleton())); Engine::get_singleton()->add_singleton(Engine::Singleton("ResourceLoader", _ResourceLoader::get_singleton())); @@ -274,19 +283,33 @@ void register_core_singletons() { Engine::get_singleton()->add_singleton(Engine::Singleton("TranslationServer", TranslationServer::get_singleton())); Engine::get_singleton()->add_singleton(Engine::Singleton("Input", Input::get_singleton())); Engine::get_singleton()->add_singleton(Engine::Singleton("InputMap", InputMap::get_singleton())); - Engine::get_singleton()->add_singleton(Engine::Singleton("JSON", _JSON::get_singleton())); Engine::get_singleton()->add_singleton(Engine::Singleton("EngineDebugger", _EngineDebugger::get_singleton())); Engine::get_singleton()->add_singleton(Engine::Singleton("Time", Time::get_singleton())); + Engine::get_singleton()->add_singleton(Engine::Singleton("NativeExtensionManager", NativeExtensionManager::get_singleton())); +} + +void register_core_extensions() { + //harcoded for now + if (ProjectSettings::get_singleton()->has_setting("native_extensions/paths")) { + Vector<String> paths = ProjectSettings::get_singleton()->get("native_extensions/paths"); + for (int i = 0; i < paths.size(); i++) { + NativeExtensionManager::LoadStatus status = native_extension_manager->load_extension(paths[i]); + ERR_CONTINUE_MSG(status != NativeExtensionManager::LOAD_STATUS_OK, "Error loading extension: " + paths[i]); + } + } + native_extension_manager->initialize_extensions(NativeExtension::INITIALIZATION_LEVEL_CORE); } void unregister_core_types() { + native_extension_manager->deinitialize_extensions(NativeExtension::INITIALIZATION_LEVEL_CORE); + + memdelete(native_extension_manager); memdelete(_resource_loader); memdelete(_resource_saver); memdelete(_os); memdelete(_engine); memdelete(_classdb); memdelete(_marshalls); - memdelete(_json); memdelete(_engine_debugger); memdelete(_geometry_2d); diff --git a/core/register_core_types.h b/core/register_core_types.h index baf7ddbe65..830f05607d 100644 --- a/core/register_core_types.h +++ b/core/register_core_types.h @@ -33,6 +33,7 @@ void register_core_types(); void register_core_settings(); +void register_core_extensions(); void register_core_singletons(); void unregister_core_types(); diff --git a/core/string/translation_po.cpp b/core/string/translation_po.cpp index d6b84cabc9..f9b4e661e4 100644 --- a/core/string/translation_po.cpp +++ b/core/string/translation_po.cpp @@ -188,7 +188,7 @@ void TranslationPO::set_plural_rule(const String &p_plural_rule) { plural_rule = plural_rule.replacen("(", ""); plural_rule = plural_rule.replacen(")", ""); _cache_plural_tests(plural_rule); - expr.instance(); + expr.instantiate(); input_name.push_back("n"); } diff --git a/core/templates/list.h b/core/templates/list.h index 010e35eed8..6047b89670 100644 --- a/core/templates/list.h +++ b/core/templates/list.h @@ -135,6 +135,83 @@ public: _FORCE_INLINE_ Element() {} }; + typedef T ValueType; + + struct Iterator { + _FORCE_INLINE_ T &operator*() const { + return E->get(); + } + _FORCE_INLINE_ T *operator->() const { return &E->get(); } + _FORCE_INLINE_ Iterator &operator++() { + E = E->next(); + return *this; + } + _FORCE_INLINE_ Iterator &operator--() { + E = E->prev(); + return *this; + } + + _FORCE_INLINE_ bool operator==(const Iterator &b) const { return E == b.E; } + _FORCE_INLINE_ bool operator!=(const Iterator &b) const { return E != b.E; } + + Iterator(Element *p_E) { E = p_E; } + Iterator() {} + Iterator(const Iterator &p_it) { E = p_it.E; } + + private: + Element *E = nullptr; + }; + + struct ConstIterator { + _FORCE_INLINE_ const T &operator*() const { + return E->get(); + } + _FORCE_INLINE_ const T *operator->() const { return &E->get(); } + _FORCE_INLINE_ ConstIterator &operator++() { + E = E->next(); + return *this; + } + _FORCE_INLINE_ ConstIterator &operator--() { + E = E->prev(); + return *this; + } + + _FORCE_INLINE_ bool operator==(const Iterator &b) const { return E == b.E; } + _FORCE_INLINE_ bool operator!=(const Iterator &b) const { return E != b.E; } + + _FORCE_INLINE_ ConstIterator(const Element *p_E) { E = p_E; } + _FORCE_INLINE_ ConstIterator() {} + _FORCE_INLINE_ ConstIterator(const ConstIterator &p_it) { E = p_it.E; } + + private: + const Element *E = nullptr; + }; + + _FORCE_INLINE_ Iterator begin() { + return Iterator(front()); + } + _FORCE_INLINE_ Iterator end() { + return Iterator(nullptr); + } + +#if 0 + //to use when replacing find() + _FORCE_INLINE_ Iterator find(const K &p_key) { + return Iterator(find(p_key)); + } +#endif + _FORCE_INLINE_ ConstIterator begin() const { + return ConstIterator(front()); + } + _FORCE_INLINE_ ConstIterator end() const { + return ConstIterator(nullptr); + } +#if 0 + //to use when replacing find() + _FORCE_INLINE_ ConstIterator find(const K &p_key) const { + return ConstIterator(find(p_key)); + } +#endif private: struct _Data { Element *first = nullptr; diff --git a/core/templates/local_vector.h b/core/templates/local_vector.h index 5f22e08eb8..668ec513d6 100644 --- a/core/templates/local_vector.h +++ b/core/templates/local_vector.h @@ -178,7 +178,7 @@ public: } int64_t find(const T &p_val, U p_from = 0) const { - for (U i = 0; i < count; i++) { + for (U i = p_from; i < count; i++) { if (data[i] == p_val) { return int64_t(i); } diff --git a/core/templates/map.h b/core/templates/map.h index 7dfee13d2c..a47547d355 100644 --- a/core/templates/map.h +++ b/core/templates/map.h @@ -33,6 +33,7 @@ #include "core/error/error_macros.h" #include "core/os/memory.h" +#include "core/templates/pair.h" // based on the very nice implementation of rb-trees by: // https://web.archive.org/web/20120507164830/http://web.mit.edu/~emin/www/source_code/red_black_tree/index.html @@ -55,11 +56,12 @@ public: Element *parent = nullptr; Element *_next = nullptr; Element *_prev = nullptr; - K _key; - V _value; - //_Data *data; + KeyValue<K, V> _data; public: + KeyValue<K, V> &key_value() { return _data; } + const KeyValue<K, V> &key_value() const { return _data; } + const Element *next() const { return _next; } @@ -73,23 +75,106 @@ public: return _prev; } const K &key() const { - return _key; + return _data.key; } V &value() { - return _value; + return _data.value; } const V &value() const { - return _value; + return _data.value; } V &get() { - return _value; + return _data.value; } const V &get() const { - return _value; + return _data.value; } - Element() {} + Element(const KeyValue<K, V> &p_data) : + _data(p_data) {} }; + typedef KeyValue<K, V> ValueType; + + struct Iterator { + _FORCE_INLINE_ KeyValue<K, V> &operator*() const { + return E->key_value(); + } + _FORCE_INLINE_ KeyValue<K, V> *operator->() const { return &E->key_value(); } + _FORCE_INLINE_ Iterator &operator++() { + E = E->next(); + return *this; + } + _FORCE_INLINE_ Iterator &operator--() { + E = E->prev(); + return *this; + } + + _FORCE_INLINE_ bool operator==(const Iterator &b) const { return E == b.E; } + _FORCE_INLINE_ bool operator!=(const Iterator &b) const { return E != b.E; } + + Iterator(Element *p_E) { E = p_E; } + Iterator() {} + Iterator(const Iterator &p_it) { E = p_it.E; } + + private: + Element *E = nullptr; + }; + + struct ConstIterator { + _FORCE_INLINE_ const KeyValue<K, V> &operator*() const { + return E->key_value(); + } + _FORCE_INLINE_ const KeyValue<K, V> *operator->() const { return &E->key_value(); } + _FORCE_INLINE_ ConstIterator &operator++() { + E = E->next(); + return *this; + } + _FORCE_INLINE_ ConstIterator &operator--() { + E = E->prev(); + return *this; + } + + _FORCE_INLINE_ bool operator==(const ConstIterator &b) const { return E == b.E; } + _FORCE_INLINE_ bool operator!=(const ConstIterator &b) const { return E != b.E; } + + ConstIterator(const Element *p_E) { E = p_E; } + ConstIterator() {} + ConstIterator(const ConstIterator &p_it) { E = p_it.E; } + + private: + const Element *E = nullptr; + }; + + _FORCE_INLINE_ Iterator begin() { + return Iterator(front()); + } + _FORCE_INLINE_ Iterator end() { + return Iterator(nullptr); + } + +#if 0 + //to use when replacing find() + _FORCE_INLINE_ Iterator find(const K &p_key) { + return Iterator(find(p_key)); + } +#endif + _FORCE_INLINE_ void remove(const Iterator &p_iter) { + return erase(p_iter.E); + } + + _FORCE_INLINE_ ConstIterator begin() const { + return ConstIterator(front()); + } + _FORCE_INLINE_ ConstIterator end() const { + return ConstIterator(nullptr); + } + +#if 0 + //to use when replacing find() + _FORCE_INLINE_ ConstIterator find(const K &p_key) const { + return ConstIterator(find(p_key)); + } +#endif private: struct _Data { Element *_root = nullptr; @@ -107,7 +192,7 @@ private: } void _create_root() { - _root = memnew_allocator(Element, A); + _root = memnew_allocator(Element(KeyValue<K, V>(K(), V())), A); _root->parent = _root->left = _root->right = _nil; _root->color = BLACK; } @@ -216,9 +301,9 @@ private: C less; while (node != _data._nil) { - if (less(p_key, node->_key)) { + if (less(p_key, node->_data.key)) { node = node->left; - } else if (less(node->_key, p_key)) { + } else if (less(node->_data.key, p_key)) { node = node->right; } else { return node; // found @@ -236,9 +321,9 @@ private: while (node != _data._nil) { prev = node; - if (less(p_key, node->_key)) { + if (less(p_key, node->_data.key)) { node = node->left; - } else if (less(node->_key, p_key)) { + } else if (less(node->_data.key, p_key)) { node = node->right; } else { return node; // found @@ -249,7 +334,7 @@ private: return nullptr; // tree empty } - if (less(p_key, prev->_key)) { + if (less(p_key, prev->_data.key)) { prev = prev->_prev; } @@ -312,25 +397,25 @@ private: while (node != _data._nil) { new_parent = node; - if (less(p_key, node->_key)) { + if (less(p_key, node->_data.key)) { node = node->left; - } else if (less(node->_key, p_key)) { + } else if (less(node->_data.key, p_key)) { node = node->right; } else { - node->_value = p_value; + node->_data.value = p_value; return node; // Return existing node with new value } } - Element *new_node = memnew_allocator(Element, A); + typedef KeyValue<K, V> KV; + Element *new_node = memnew_allocator(Element(KV(p_key, p_value)), A); new_node->parent = new_parent; new_node->right = _data._nil; new_node->left = _data._nil; - new_node->_key = p_key; - new_node->_value = p_value; + //new_node->data=_data; - if (new_parent == _data._root || less(p_key, new_parent->_key)) { + if (new_parent == _data._root || less(p_key, new_parent->_data.key)) { new_parent->left = new_node; } else { new_parent->right = new_node; @@ -575,7 +660,7 @@ public: CRASH_COND(!_data._root); const Element *e = find(p_key); CRASH_COND(!e); - return e->_value; + return e->_data.value; } V &operator[](const K &p_key) { @@ -588,7 +673,7 @@ public: e = insert(p_key, V()); } - return e->_value; + return e->_data.value; } Element *front() const { diff --git a/core/templates/pair.h b/core/templates/pair.h index bc1a764694..31706b6ecb 100644 --- a/core/templates/pair.h +++ b/core/templates/pair.h @@ -31,6 +31,8 @@ #ifndef PAIR_H #define PAIR_H +#include "core/typedefs.h" + template <class F, class S> struct Pair { F first; @@ -64,4 +66,37 @@ struct PairSort { } }; +template <class K, class V> +struct KeyValue { + const K key; + V value; + + void operator=(const KeyValue &p_kv) = delete; + _FORCE_INLINE_ KeyValue(const KeyValue &p_kv) : + key(p_kv.key), + value(p_kv.value) { + } + _FORCE_INLINE_ KeyValue(const K &p_key, const V &p_value) : + key(p_key), + value(p_value) { + } +}; + +template <class K, class V> +bool operator==(const KeyValue<K, V> &pair, const KeyValue<K, V> &other) { + return (pair.key == other.key) && (pair.value == other.value); +} + +template <class K, class V> +bool operator!=(const KeyValue<K, V> &pair, const KeyValue<K, V> &other) { + return (pair.key != other.key) || (pair.value != other.value); +} + +template <class K, class V> +struct KeyValueSort { + bool operator()(const KeyValue<K, V> &A, const KeyValue<K, V> &B) const { + return A.key < B.key; + } +}; + #endif // PAIR_H diff --git a/core/templates/rid_owner.h b/core/templates/rid_owner.h index c4aa93c394..4f5c74ca46 100644 --- a/core/templates/rid_owner.h +++ b/core/templates/rid_owner.h @@ -79,7 +79,7 @@ class RID_Alloc : public RID_AllocBase { SpinLock spin_lock; - _FORCE_INLINE_ RID _allocate_rid(const T *p_initializer) { + _FORCE_INLINE_ RID _allocate_rid() { if (THREAD_SAFE) { spin_lock.lock(); } @@ -114,11 +114,6 @@ class RID_Alloc : public RID_AllocBase { uint32_t free_chunk = free_index / elements_in_chunk; uint32_t free_element = free_index % elements_in_chunk; - if (p_initializer) { - T *ptr = &chunks[free_chunk][free_element]; - memnew_placement(ptr, T(*p_initializer)); - } - uint32_t validator = (uint32_t)(_gen_id() & 0x7FFFFFFF); uint64_t id = validator; id <<= 32; @@ -126,9 +121,7 @@ class RID_Alloc : public RID_AllocBase { validator_chunks[free_chunk][free_element] = validator; - if (!p_initializer) { - validator_chunks[free_chunk][free_element] |= 0x80000000; //mark uninitialized bit - } + validator_chunks[free_chunk][free_element] |= 0x80000000; //mark uninitialized bit alloc_count++; @@ -140,13 +133,20 @@ class RID_Alloc : public RID_AllocBase { } public: + RID make_rid() { + RID rid = _allocate_rid(); + initialize_rid(rid); + return rid; + } RID make_rid(const T &p_value) { - return _allocate_rid(&p_value); + RID rid = _allocate_rid(); + initialize_rid(rid, p_value); + return rid; } //allocate but don't initialize, use initialize_rid afterwards RID allocate_rid() { - return _allocate_rid(nullptr); + return _allocate_rid(); } _FORCE_INLINE_ T *getornull(const RID &p_rid, bool p_initialize = false) { @@ -193,7 +193,7 @@ public: if (THREAD_SAFE) { spin_lock.unlock(); } - if (validator_chunks[idx_chunk][idx_element] & 0x80000000) { + if ((validator_chunks[idx_chunk][idx_element] & 0x80000000) && validator_chunks[idx_chunk][idx_element] != 0xFFFFFFFF) { ERR_FAIL_V_MSG(nullptr, "Attempting to use an uninitialized RID"); } return nullptr; @@ -207,6 +207,11 @@ public: return ptr; } + void initialize_rid(RID p_rid) { + T *mem = getornull(p_rid, true); + ERR_FAIL_COND(!mem); + memnew_placement(mem, T); + } void initialize_rid(RID p_rid, const T &p_value) { T *mem = getornull(p_rid, true); ERR_FAIL_COND(!mem); @@ -333,7 +338,7 @@ public: description = p_descrption; } - RID_Alloc(uint32_t p_target_chunk_byte_size = 4096) { + RID_Alloc(uint32_t p_target_chunk_byte_size = 65536) { elements_in_chunk = sizeof(T) > p_target_chunk_byte_size ? 1 : (p_target_chunk_byte_size / sizeof(T)); } @@ -351,6 +356,9 @@ public: for (size_t i = 0; i < max_alloc; i++) { uint64_t validator = validator_chunks[i / elements_in_chunk][i % elements_in_chunk]; + if (validator & 0x80000000) { + continue; //uninitialized + } if (validator != 0xFFFFFFFF) { chunks[i / elements_in_chunk][i % elements_in_chunk].~T(); } @@ -431,7 +439,7 @@ public: alloc.set_description(p_descrption); } - RID_PtrOwner(uint32_t p_target_chunk_byte_size = 4096) : + RID_PtrOwner(uint32_t p_target_chunk_byte_size = 65536) : alloc(p_target_chunk_byte_size) {} }; @@ -440,6 +448,9 @@ class RID_Owner { RID_Alloc<T, THREAD_SAFE> alloc; public: + _FORCE_INLINE_ RID make_rid() { + return alloc.make_rid(); + } _FORCE_INLINE_ RID make_rid(const T &p_ptr) { return alloc.make_rid(p_ptr); } @@ -448,6 +459,10 @@ public: return alloc.allocate_rid(); } + _FORCE_INLINE_ void initialize_rid(RID p_rid) { + alloc.initialize_rid(p_rid); + } + _FORCE_INLINE_ void initialize_rid(RID p_rid, const T &p_ptr) { alloc.initialize_rid(p_rid, p_ptr); } @@ -483,7 +498,7 @@ public: void set_description(const char *p_descrption) { alloc.set_description(p_descrption); } - RID_Owner(uint32_t p_target_chunk_byte_size = 4096) : + RID_Owner(uint32_t p_target_chunk_byte_size = 65536) : alloc(p_target_chunk_byte_size) {} }; diff --git a/core/templates/set.h b/core/templates/set.h index 3036ecf27d..245c174862 100644 --- a/core/templates/set.h +++ b/core/templates/set.h @@ -77,6 +77,85 @@ public: Element() {} }; + typedef T ValueType; + + struct Iterator { + _FORCE_INLINE_ T &operator*() const { + return E->get(); + } + _FORCE_INLINE_ T *operator->() const { return &E->get(); } + _FORCE_INLINE_ Iterator &operator++() { + E = E->next(); + return *this; + } + _FORCE_INLINE_ Iterator &operator--() { + E = E->prev(); + return *this; + } + + _FORCE_INLINE_ bool operator==(const Iterator &b) const { return E == b.E; } + _FORCE_INLINE_ bool operator!=(const Iterator &b) const { return E != b.E; } + + Iterator(Element *p_E) { E = p_E; } + Iterator() {} + Iterator(const Iterator &p_it) { E = p_it.E; } + + private: + Element *E = nullptr; + }; + + struct ConstIterator { + _FORCE_INLINE_ const T &operator*() const { + return E->get(); + } + _FORCE_INLINE_ const T *operator->() const { return &E->get(); } + _FORCE_INLINE_ ConstIterator &operator++() { + E = E->next(); + return *this; + } + _FORCE_INLINE_ ConstIterator &operator--() { + E = E->prev(); + return *this; + } + + _FORCE_INLINE_ bool operator==(const Iterator &b) const { return E == b.E; } + _FORCE_INLINE_ bool operator!=(const Iterator &b) const { return E != b.E; } + + _FORCE_INLINE_ ConstIterator(const Element *p_E) { E = p_E; } + _FORCE_INLINE_ ConstIterator() {} + _FORCE_INLINE_ ConstIterator(const ConstIterator &p_it) { E = p_it.E; } + + private: + const Element *E = nullptr; + }; + + _FORCE_INLINE_ Iterator begin() { + return Iterator(front()); + } + _FORCE_INLINE_ Iterator end() { + return Iterator(nullptr); + } + +#if 0 + //to use when replacing find() + _FORCE_INLINE_ Iterator find(const K &p_key) { + return Iterator(find(p_key)); + } +#endif + + _FORCE_INLINE_ ConstIterator begin() const { + return ConstIterator(front()); + } + _FORCE_INLINE_ ConstIterator end() const { + return ConstIterator(nullptr); + } + +#if 0 + //to use when replacing find() + _FORCE_INLINE_ ConstIterator find(const K &p_key) const { + return ConstIterator(find(p_key)); + } +#endif private: struct _Data { Element *_root = nullptr; diff --git a/core/templates/vector.h b/core/templates/vector.h index dae8874a87..08cbef6ba4 100644 --- a/core/templates/vector.h +++ b/core/templates/vector.h @@ -187,6 +187,70 @@ public: return false; } + struct Iterator { + _FORCE_INLINE_ T &operator*() const { + return *elem_ptr; + } + _FORCE_INLINE_ T *operator->() const { return elem_ptr; } + _FORCE_INLINE_ Iterator &operator++() { + elem_ptr++; + return *this; + } + _FORCE_INLINE_ Iterator &operator--() { + elem_ptr--; + return *this; + } + + _FORCE_INLINE_ bool operator==(const Iterator &b) const { return elem_ptr == b.elem_ptr; } + _FORCE_INLINE_ bool operator!=(const Iterator &b) const { return elem_ptr != b.elem_ptr; } + + Iterator(T *p_ptr) { elem_ptr = p_ptr; } + Iterator() {} + Iterator(const Iterator &p_it) { elem_ptr = p_it.elem_ptr; } + + private: + T *elem_ptr = nullptr; + }; + + struct ConstIterator { + _FORCE_INLINE_ const T &operator*() const { + return *elem_ptr; + } + _FORCE_INLINE_ const T *operator->() const { return elem_ptr; } + _FORCE_INLINE_ ConstIterator &operator++() { + elem_ptr++; + return *this; + } + _FORCE_INLINE_ ConstIterator &operator--() { + elem_ptr--; + return *this; + } + + _FORCE_INLINE_ bool operator==(const ConstIterator &b) const { return elem_ptr == b.elem_ptr; } + _FORCE_INLINE_ bool operator!=(const ConstIterator &b) const { return elem_ptr != b.elem_ptr; } + + ConstIterator(T *p_ptr) { elem_ptr = p_ptr; } + ConstIterator() {} + ConstIterator(const ConstIterator &p_it) { elem_ptr = p_it.elem_ptr; } + + private: + const T *elem_ptr = nullptr; + }; + + _FORCE_INLINE_ Iterator begin() { + return Iterator(ptrw()); + } + _FORCE_INLINE_ Iterator end() { + return Iterator(ptrw() + size()); + } + + _FORCE_INLINE_ ConstIterator begin() const { + return ConstIterator(ptr()); + } + _FORCE_INLINE_ ConstIterator end() const { + return ConstIterator(ptr() + size()); + } + _FORCE_INLINE_ Vector() {} _FORCE_INLINE_ Vector(const Vector &p_from) { _cowdata._ref(p_from._cowdata); } diff --git a/core/variant/binder_common.h b/core/variant/binder_common.h index 830e0a5cbd..ef5867c685 100644 --- a/core/variant/binder_common.h +++ b/core/variant/binder_common.h @@ -31,6 +31,7 @@ #ifndef BINDER_COMMON_H #define BINDER_COMMON_H +#include "core/input/input_enums.h" #include "core/object/object.h" #include "core/templates/list.h" #include "core/templates/simple_type.h" @@ -76,6 +77,7 @@ struct VariantCaster<const T &> { _FORCE_INLINE_ static m_enum convert(const void *p_ptr) { \ return m_enum(*reinterpret_cast<const int *>(p_ptr)); \ } \ + typedef int64_t EncodeT; \ _FORCE_INLINE_ static void encode(m_enum p_val, const void *p_ptr) { \ *(int *)p_ptr = p_val; \ } \ @@ -90,6 +92,12 @@ VARIANT_ENUM_CAST(Error); VARIANT_ENUM_CAST(Side); VARIANT_ENUM_CAST(ClockDirection); VARIANT_ENUM_CAST(Corner); +VARIANT_ENUM_CAST(HatDir); +VARIANT_ENUM_CAST(HatMask); +VARIANT_ENUM_CAST(JoyAxis); +VARIANT_ENUM_CAST(JoyButton); +VARIANT_ENUM_CAST(MIDIMessage); +VARIANT_ENUM_CAST(MouseButton); VARIANT_ENUM_CAST(Orientation); VARIANT_ENUM_CAST(HAlign); VARIANT_ENUM_CAST(VAlign); @@ -110,6 +118,7 @@ struct PtrToArg<char32_t> { _FORCE_INLINE_ static char32_t convert(const void *p_ptr) { return char32_t(*reinterpret_cast<const int *>(p_ptr)); } + typedef int64_t EncodeT; _FORCE_INLINE_ static void encode(char32_t p_val, const void *p_ptr) { *(int *)p_ptr = p_val; } diff --git a/core/variant/callable.cpp b/core/variant/callable.cpp index 34b3e3ea35..ca6f3d615e 100644 --- a/core/variant/callable.cpp +++ b/core/variant/callable.cpp @@ -89,6 +89,10 @@ Callable Callable::unbind(int p_argcount) const { return Callable(memnew(CallableCustomUnbind(*this, p_argcount))); } +bool Callable::is_valid() const { + return get_object() && (is_custom() || get_object()->has_method(get_method())); +} + Object *Callable::get_object() const { if (is_null()) { return nullptr; diff --git a/core/variant/callable.h b/core/variant/callable.h index 20d0804292..52094af3aa 100644 --- a/core/variant/callable.h +++ b/core/variant/callable.h @@ -81,6 +81,7 @@ public: _FORCE_INLINE_ bool is_standard() const { return method != StringName(); } + bool is_valid() const; Callable bind(const Variant **p_arguments, int p_argcount) const; Callable unbind(int p_argcount) const; diff --git a/core/variant/dictionary.cpp b/core/variant/dictionary.cpp index b2f7c6aa0a..07b3a9a675 100644 --- a/core/variant/dictionary.cpp +++ b/core/variant/dictionary.cpp @@ -33,6 +33,11 @@ #include "core/templates/ordered_hash_map.h" #include "core/templates/safe_refcount.h" #include "core/variant/variant.h" +// required in this order by VariantInternal, do not remove this comment. +#include "core/object/class_db.h" +#include "core/object/object.h" +#include "core/variant/type_info.h" +#include "core/variant/variant_internal.h" struct DictionaryPrivate { SafeRefCount refcount; @@ -74,15 +79,32 @@ Variant Dictionary::get_value_at_index(int p_index) const { } Variant &Dictionary::operator[](const Variant &p_key) { - return _p->variant_map[p_key]; + if (p_key.get_type() == Variant::STRING_NAME) { + const StringName *sn = VariantInternal::get_string_name(&p_key); + return _p->variant_map[sn->operator String()]; + } else { + return _p->variant_map[p_key]; + } } const Variant &Dictionary::operator[](const Variant &p_key) const { - return _p->variant_map[p_key]; + if (p_key.get_type() == Variant::STRING_NAME) { + const StringName *sn = VariantInternal::get_string_name(&p_key); + return _p->variant_map[sn->operator String()]; + } else { + return _p->variant_map[p_key]; + } } const Variant *Dictionary::getptr(const Variant &p_key) const { - OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::ConstElement E = ((const OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator> *)&_p->variant_map)->find(p_key); + OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::ConstElement E; + + if (p_key.get_type() == Variant::STRING_NAME) { + const StringName *sn = VariantInternal::get_string_name(&p_key); + E = ((const OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator> *)&_p->variant_map)->find(sn->operator String()); + } else { + E = ((const OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator> *)&_p->variant_map)->find(p_key); + } if (!E) { return nullptr; @@ -91,8 +113,14 @@ const Variant *Dictionary::getptr(const Variant &p_key) const { } Variant *Dictionary::getptr(const Variant &p_key) { - OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::Element E = _p->variant_map.find(p_key); + OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::Element E; + if (p_key.get_type() == Variant::STRING_NAME) { + const StringName *sn = VariantInternal::get_string_name(&p_key); + E = ((OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator> *)&_p->variant_map)->find(sn->operator String()); + } else { + E = ((OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator> *)&_p->variant_map)->find(p_key); + } if (!E) { return nullptr; } @@ -100,7 +128,14 @@ Variant *Dictionary::getptr(const Variant &p_key) { } Variant Dictionary::get_valid(const Variant &p_key) const { - OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::ConstElement E = ((const OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator> *)&_p->variant_map)->find(p_key); + OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::ConstElement E; + + if (p_key.get_type() == Variant::STRING_NAME) { + const StringName *sn = VariantInternal::get_string_name(&p_key); + E = ((const OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator> *)&_p->variant_map)->find(sn->operator String()); + } else { + E = ((const OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator> *)&_p->variant_map)->find(p_key); + } if (!E) { return Variant(); @@ -126,7 +161,12 @@ bool Dictionary::is_empty() const { } bool Dictionary::has(const Variant &p_key) const { - return _p->variant_map.has(p_key); + if (p_key.get_type() == Variant::STRING_NAME) { + const StringName *sn = VariantInternal::get_string_name(&p_key); + return _p->variant_map.has(sn->operator String()); + } else { + return _p->variant_map.has(p_key); + } } bool Dictionary::has_all(const Array &p_keys) const { @@ -139,7 +179,12 @@ bool Dictionary::has_all(const Array &p_keys) const { } bool Dictionary::erase(const Variant &p_key) { - return _p->variant_map.erase(p_key); + if (p_key.get_type() == Variant::STRING_NAME) { + const StringName *sn = VariantInternal::get_string_name(&p_key); + return _p->variant_map.erase(sn->operator String()); + } else { + return _p->variant_map.erase(p_key); + } } bool Dictionary::operator==(const Dictionary &p_dictionary) const { diff --git a/core/variant/method_ptrcall.h b/core/variant/method_ptrcall.h index d4ec5e570c..7852187b77 100644 --- a/core/variant/method_ptrcall.h +++ b/core/variant/method_ptrcall.h @@ -45,6 +45,7 @@ struct PtrToArg {}; _FORCE_INLINE_ static m_type convert(const void *p_ptr) { \ return *reinterpret_cast<const m_type *>(p_ptr); \ } \ + typedef m_type EncodeT; \ _FORCE_INLINE_ static void encode(m_type p_val, void *p_ptr) { \ *((m_type *)p_ptr) = p_val; \ } \ @@ -54,6 +55,7 @@ struct PtrToArg {}; _FORCE_INLINE_ static m_type convert(const void *p_ptr) { \ return *reinterpret_cast<const m_type *>(p_ptr); \ } \ + typedef m_type EncodeT; \ _FORCE_INLINE_ static void encode(m_type p_val, void *p_ptr) { \ *((m_type *)p_ptr) = p_val; \ } \ @@ -65,6 +67,7 @@ struct PtrToArg {}; _FORCE_INLINE_ static m_type convert(const void *p_ptr) { \ return static_cast<m_type>(*reinterpret_cast<const m_conv *>(p_ptr)); \ } \ + typedef m_conv EncodeT; \ _FORCE_INLINE_ static void encode(m_type p_val, void *p_ptr) { \ *((m_conv *)p_ptr) = static_cast<m_conv>(p_val); \ } \ @@ -74,6 +77,7 @@ struct PtrToArg {}; _FORCE_INLINE_ static m_type convert(const void *p_ptr) { \ return static_cast<m_type>(*reinterpret_cast<const m_conv *>(p_ptr)); \ } \ + typedef m_conv EncodeT; \ _FORCE_INLINE_ static void encode(m_type p_val, void *p_ptr) { \ *((m_conv *)p_ptr) = static_cast<m_conv>(p_val); \ } \ @@ -85,6 +89,7 @@ struct PtrToArg {}; _FORCE_INLINE_ static m_type convert(const void *p_ptr) { \ return *reinterpret_cast<const m_type *>(p_ptr); \ } \ + typedef m_type EncodeT; \ _FORCE_INLINE_ static void encode(const m_type &p_val, void *p_ptr) { \ *((m_type *)p_ptr) = p_val; \ } \ @@ -94,12 +99,13 @@ struct PtrToArg {}; _FORCE_INLINE_ static m_type convert(const void *p_ptr) { \ return *reinterpret_cast<const m_type *>(p_ptr); \ } \ + typedef m_type EncodeT; \ _FORCE_INLINE_ static void encode(const m_type &p_val, void *p_ptr) { \ *((m_type *)p_ptr) = p_val; \ } \ } -MAKE_PTRARG(bool); +MAKE_PTRARGCONV(bool, uint32_t); // Integer types. MAKE_PTRARGCONV(uint8_t, int64_t); MAKE_PTRARGCONV(int8_t, int64_t); @@ -153,7 +159,7 @@ struct PtrToArg<T *> { _FORCE_INLINE_ static T *convert(const void *p_ptr) { return const_cast<T *>(reinterpret_cast<const T *>(p_ptr)); } - + typedef Object *EncodeT; _FORCE_INLINE_ static void encode(T *p_var, void *p_ptr) { *((T **)p_ptr) = p_var; } @@ -164,7 +170,7 @@ struct PtrToArg<const T *> { _FORCE_INLINE_ static const T *convert(const void *p_ptr) { return reinterpret_cast<const T *>(p_ptr); } - + typedef const Object *EncodeT; _FORCE_INLINE_ static void encode(T *p_var, void *p_ptr) { *((T **)p_ptr) = p_var; } @@ -177,7 +183,7 @@ struct PtrToArg<ObjectID> { _FORCE_INLINE_ static const ObjectID convert(const void *p_ptr) { return ObjectID(*reinterpret_cast<const uint64_t *>(p_ptr)); } - + typedef uint64_t EncodeT; _FORCE_INLINE_ static void encode(const ObjectID &p_val, void *p_ptr) { *((uint64_t *)p_ptr) = p_val; } diff --git a/core/variant/variant.cpp b/core/variant/variant.cpp index 4e45862fd3..badb5ba103 100644 --- a/core/variant/variant.cpp +++ b/core/variant/variant.cpp @@ -32,6 +32,7 @@ #include "core/core_string_names.h" #include "core/debugger/engine_debugger.h" +#include "core/io/json.h" #include "core/io/marshalls.h" #include "core/io/resource.h" #include "core/math/math_funcs.h" @@ -1838,6 +1839,11 @@ String Variant::stringify(List<const void *> &stack) const { return ""; } +String Variant::to_json_string() const { + JSON json; + return json.stringify(*this); +} + Variant::operator Vector2() const { if (type == VECTOR2) { return *reinterpret_cast<const Vector2 *>(_data._mem); diff --git a/core/variant/variant.h b/core/variant/variant.h index 75316da63f..373fe32921 100644 --- a/core/variant/variant.h +++ b/core/variant/variant.h @@ -499,6 +499,7 @@ public: static bool is_builtin_method_vararg(Variant::Type p_type, const StringName &p_method); static void get_builtin_method_list(Variant::Type p_type, List<StringName> *p_list); static int get_builtin_method_count(Variant::Type p_type); + static uint32_t get_builtin_method_hash(Variant::Type p_type, const StringName &p_method); void call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error); Variant call(const StringName &p_method, const Variant &p_arg1 = Variant(), const Variant &p_arg2 = Variant(), const Variant &p_arg3 = Variant(), const Variant &p_arg4 = Variant(), const Variant &p_arg5 = Variant()); @@ -586,7 +587,7 @@ public: typedef void (*PTRKeyedSetter)(void *base, const void *key, const void *value); typedef void (*PTRKeyedGetter)(const void *base, const void *key, void *value); - typedef bool (*PTRKeyedChecker)(const void *base, const void *key); + typedef uint32_t (*PTRKeyedChecker)(const void *base, const void *key); static PTRKeyedSetter get_member_ptr_keyed_setter(Variant::Type p_type); static PTRKeyedGetter get_member_ptr_keyed_getter(Variant::Type p_type); @@ -631,6 +632,7 @@ public: static bool has_utility_function_return_value(const StringName &p_name); static Variant::Type get_utility_function_return_type(const StringName &p_name); static bool is_utility_function_vararg(const StringName &p_name); + static uint32_t get_utility_function_hash(const StringName &p_name); static void get_utility_function_list(List<StringName> *r_functions); static int get_utility_function_count(); @@ -645,6 +647,7 @@ public: bool hash_compare(const Variant &p_variant) const; bool booleanize() const; String stringify(List<const void *> &stack) const; + String to_json_string() const; void static_assign(const Variant &p_variant); static void get_constants_for_type(Variant::Type p_type, List<StringName> *p_constants); diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp index 9c7cd23d72..733361fe58 100644 --- a/core/variant/variant_call.cpp +++ b/core/variant/variant_call.cpp @@ -1126,6 +1126,25 @@ bool Variant::is_builtin_method_vararg(Variant::Type p_type, const StringName &p return method->is_vararg; } +uint32_t Variant::get_builtin_method_hash(Variant::Type p_type, const StringName &p_method) { + ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, 0); + const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method); + ERR_FAIL_COND_V(!method, 0); + uint32_t hash = hash_djb2_one_32(method->is_const); + hash = hash_djb2_one_32(method->is_static, hash); + hash = hash_djb2_one_32(method->is_vararg, hash); + hash = hash_djb2_one_32(method->has_return_type, hash); + if (method->has_return_type) { + hash = hash_djb2_one_32(method->return_type, hash); + } + hash = hash_djb2_one_32(method->argument_count, hash); + for (int i = 0; i < method->argument_count; i++) { + hash = method->get_argument_type(i); + } + + return hash; +} + void Variant::get_method_list(List<MethodInfo> *p_list) const { if (type == OBJECT) { Object *obj = get_validated_object(); @@ -1611,6 +1630,7 @@ static void _register_variant_builtin_methods() { bind_method(Callable, is_null, sarray(), varray()); bind_method(Callable, is_custom, sarray(), varray()); bind_method(Callable, is_standard, sarray(), varray()); + bind_method(Callable, is_valid, sarray(), varray()); bind_method(Callable, get_object, sarray(), varray()); bind_method(Callable, get_object_id, sarray(), varray()); bind_method(Callable, get_method, sarray(), varray()); diff --git a/core/variant/variant_construct.cpp b/core/variant/variant_construct.cpp index 9e3ab5897b..a1a2bec369 100644 --- a/core/variant/variant_construct.cpp +++ b/core/variant/variant_construct.cpp @@ -28,543 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "variant.h" - -#include "core/core_string_names.h" -#include "core/crypto/crypto_core.h" -#include "core/debugger/engine_debugger.h" -#include "core/io/compression.h" -#include "core/object/class_db.h" -#include "core/os/os.h" -#include "core/templates/local_vector.h" -#include "core/templates/oa_hash_map.h" - -template <class T> -struct PtrConstruct {}; - -#define MAKE_PTRCONSTRUCT(m_type) \ - template <> \ - struct PtrConstruct<m_type> { \ - _FORCE_INLINE_ static void construct(const m_type &p_value, void *p_ptr) { \ - memnew_placement(p_ptr, m_type(p_value)); \ - } \ - }; - -MAKE_PTRCONSTRUCT(bool); -MAKE_PTRCONSTRUCT(int64_t); -MAKE_PTRCONSTRUCT(double); -MAKE_PTRCONSTRUCT(String); -MAKE_PTRCONSTRUCT(Vector2); -MAKE_PTRCONSTRUCT(Vector2i); -MAKE_PTRCONSTRUCT(Rect2); -MAKE_PTRCONSTRUCT(Rect2i); -MAKE_PTRCONSTRUCT(Vector3); -MAKE_PTRCONSTRUCT(Vector3i); -MAKE_PTRCONSTRUCT(Transform2D); -MAKE_PTRCONSTRUCT(Plane); -MAKE_PTRCONSTRUCT(Quaternion); -MAKE_PTRCONSTRUCT(AABB); -MAKE_PTRCONSTRUCT(Basis); -MAKE_PTRCONSTRUCT(Transform3D); -MAKE_PTRCONSTRUCT(Color); -MAKE_PTRCONSTRUCT(StringName); -MAKE_PTRCONSTRUCT(NodePath); -MAKE_PTRCONSTRUCT(RID); - -template <> -struct PtrConstruct<Object *> { - _FORCE_INLINE_ static void construct(Object *p_value, void *p_ptr) { - *((Object **)p_ptr) = p_value; - } -}; - -MAKE_PTRCONSTRUCT(Callable); -MAKE_PTRCONSTRUCT(Signal); -MAKE_PTRCONSTRUCT(Dictionary); -MAKE_PTRCONSTRUCT(Array); -MAKE_PTRCONSTRUCT(PackedByteArray); -MAKE_PTRCONSTRUCT(PackedInt32Array); -MAKE_PTRCONSTRUCT(PackedInt64Array); -MAKE_PTRCONSTRUCT(PackedFloat32Array); -MAKE_PTRCONSTRUCT(PackedFloat64Array); -MAKE_PTRCONSTRUCT(PackedStringArray); -MAKE_PTRCONSTRUCT(PackedVector2Array); -MAKE_PTRCONSTRUCT(PackedVector3Array); -MAKE_PTRCONSTRUCT(PackedColorArray); -MAKE_PTRCONSTRUCT(Variant); - -template <class T, class... P> -class VariantConstructor { - template <size_t... Is> - static _FORCE_INLINE_ void construct_helper(T &base, const Variant **p_args, Callable::CallError &r_error, IndexSequence<Is...>) { - r_error.error = Callable::CallError::CALL_OK; - -#ifdef DEBUG_METHODS_ENABLED - base = T(VariantCasterAndValidate<P>::cast(p_args, Is, r_error)...); -#else - base = T(VariantCaster<P>::cast(*p_args[Is])...); -#endif - } - - template <size_t... Is> - static _FORCE_INLINE_ void validated_construct_helper(T &base, const Variant **p_args, IndexSequence<Is...>) { - base = T((*VariantGetInternalPtr<P>::get_ptr(p_args[Is]))...); - } - - template <size_t... Is> - static _FORCE_INLINE_ void ptr_construct_helper(void *base, const void **p_args, IndexSequence<Is...>) { - PtrConstruct<T>::construct(T(PtrToArg<P>::convert(p_args[Is])...), base); - } - -public: - static void construct(Variant &r_ret, const Variant **p_args, Callable::CallError &r_error) { - r_error.error = Callable::CallError::CALL_OK; - VariantTypeChanger<T>::change(&r_ret); - construct_helper(*VariantGetInternalPtr<T>::get_ptr(&r_ret), p_args, r_error, BuildIndexSequence<sizeof...(P)>{}); - } - - static void validated_construct(Variant *r_ret, const Variant **p_args) { - VariantTypeChanger<T>::change(r_ret); - validated_construct_helper(*VariantGetInternalPtr<T>::get_ptr(r_ret), p_args, BuildIndexSequence<sizeof...(P)>{}); - } - static void ptr_construct(void *base, const void **p_args) { - ptr_construct_helper(base, p_args, BuildIndexSequence<sizeof...(P)>{}); - } - - static int get_argument_count() { - return sizeof...(P); - } - - static Variant::Type get_argument_type(int p_arg) { - return call_get_argument_type<P...>(p_arg); - } - - static Variant::Type get_base_type() { - return GetTypeInfo<T>::VARIANT_TYPE; - } -}; - -class VariantConstructorObject { -public: - static void construct(Variant &r_ret, const Variant **p_args, Callable::CallError &r_error) { - VariantInternal::clear(&r_ret); - if (p_args[0]->get_type() == Variant::NIL) { - VariantInternal::object_assign_null(&r_ret); - r_error.error = Callable::CallError::CALL_OK; - } else if (p_args[0]->get_type() == Variant::OBJECT) { - VariantInternal::object_assign(&r_ret, p_args[0]); - r_error.error = Callable::CallError::CALL_OK; - } else { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; - r_error.argument = 0; - r_error.expected = Variant::OBJECT; - } - } - - static void validated_construct(Variant *r_ret, const Variant **p_args) { - VariantInternal::clear(r_ret); - VariantInternal::object_assign(r_ret, p_args[0]); - } - static void ptr_construct(void *base, const void **p_args) { - PtrConstruct<Object *>::construct(PtrToArg<Object *>::convert(p_args[0]), base); - } - - static int get_argument_count() { - return 1; - } - - static Variant::Type get_argument_type(int p_arg) { - return Variant::OBJECT; - } - - static Variant::Type get_base_type() { - return Variant::OBJECT; - } -}; - -class VariantConstructorNilObject { -public: - static void construct(Variant &r_ret, const Variant **p_args, Callable::CallError &r_error) { - if (p_args[0]->get_type() != Variant::NIL) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; - r_error.argument = 0; - r_error.expected = Variant::NIL; - } - - VariantInternal::clear(&r_ret); - VariantInternal::object_assign_null(&r_ret); - } - - static void validated_construct(Variant *r_ret, const Variant **p_args) { - VariantInternal::clear(r_ret); - VariantInternal::object_assign_null(r_ret); - } - static void ptr_construct(void *base, const void **p_args) { - PtrConstruct<Object *>::construct(nullptr, base); - } - - static int get_argument_count() { - return 1; - } - - static Variant::Type get_argument_type(int p_arg) { - return Variant::NIL; - } - - static Variant::Type get_base_type() { - return Variant::OBJECT; - } -}; - -class VariantConstructorCallableArgs { -public: - static void construct(Variant &r_ret, const Variant **p_args, Callable::CallError &r_error) { - ObjectID object_id; - StringName method; - - if (p_args[0]->get_type() == Variant::NIL) { - // leave as is - } else if (p_args[0]->get_type() == Variant::OBJECT) { - object_id = VariantInternal::get_object_id(p_args[0]); - } else { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; - r_error.argument = 0; - r_error.expected = Variant::OBJECT; - return; - } - - if (p_args[1]->get_type() == Variant::STRING_NAME) { - method = *VariantGetInternalPtr<StringName>::get_ptr(p_args[1]); - } else if (p_args[1]->get_type() == Variant::STRING) { - method = *VariantGetInternalPtr<String>::get_ptr(p_args[1]); - } else { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; - r_error.argument = 1; - r_error.expected = Variant::STRING_NAME; - return; - } - - VariantTypeChanger<Callable>::change(&r_ret); - *VariantGetInternalPtr<Callable>::get_ptr(&r_ret) = Callable(object_id, method); - } - - static void validated_construct(Variant *r_ret, const Variant **p_args) { - VariantTypeChanger<Callable>::change(r_ret); - *VariantGetInternalPtr<Callable>::get_ptr(r_ret) = Callable(VariantInternal::get_object_id(p_args[0]), *VariantGetInternalPtr<StringName>::get_ptr(p_args[1])); - } - static void ptr_construct(void *base, const void **p_args) { - PtrConstruct<Callable>::construct(Callable(PtrToArg<Object *>::convert(p_args[0]), PtrToArg<StringName>::convert(p_args[1])), base); - } - - static int get_argument_count() { - return 2; - } - - static Variant::Type get_argument_type(int p_arg) { - if (p_arg == 0) { - return Variant::OBJECT; - } else { - return Variant::STRING_NAME; - } - } - - static Variant::Type get_base_type() { - return Variant::CALLABLE; - } -}; - -class VariantConstructorSignalArgs { -public: - static void construct(Variant &r_ret, const Variant **p_args, Callable::CallError &r_error) { - ObjectID object_id; - StringName method; - - if (p_args[0]->get_type() == Variant::NIL) { - // leave as is - } else if (p_args[0]->get_type() == Variant::OBJECT) { - object_id = VariantInternal::get_object_id(p_args[0]); - } else { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; - r_error.argument = 0; - r_error.expected = Variant::OBJECT; - return; - } - - if (p_args[1]->get_type() == Variant::STRING_NAME) { - method = *VariantGetInternalPtr<StringName>::get_ptr(p_args[1]); - } else if (p_args[1]->get_type() == Variant::STRING) { - method = *VariantGetInternalPtr<String>::get_ptr(p_args[1]); - } else { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; - r_error.argument = 1; - r_error.expected = Variant::STRING_NAME; - return; - } - - VariantTypeChanger<Signal>::change(&r_ret); - *VariantGetInternalPtr<Signal>::get_ptr(&r_ret) = Signal(object_id, method); - } - - static void validated_construct(Variant *r_ret, const Variant **p_args) { - VariantTypeChanger<Signal>::change(r_ret); - *VariantGetInternalPtr<Signal>::get_ptr(r_ret) = Signal(VariantInternal::get_object_id(p_args[0]), *VariantGetInternalPtr<StringName>::get_ptr(p_args[1])); - } - static void ptr_construct(void *base, const void **p_args) { - PtrConstruct<Signal>::construct(Signal(PtrToArg<Object *>::convert(p_args[0]), PtrToArg<StringName>::convert(p_args[1])), base); - } - - static int get_argument_count() { - return 2; - } - - static Variant::Type get_argument_type(int p_arg) { - if (p_arg == 0) { - return Variant::OBJECT; - } else { - return Variant::STRING_NAME; - } - } - - static Variant::Type get_base_type() { - return Variant::SIGNAL; - } -}; - -template <class T> -class VariantConstructorToArray { -public: - static void construct(Variant &r_ret, const Variant **p_args, Callable::CallError &r_error) { - if (p_args[0]->get_type() != GetTypeInfo<T>::VARIANT_TYPE) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; - r_error.argument = 0; - r_error.expected = GetTypeInfo<T>::VARIANT_TYPE; - return; - } - - VariantTypeChanger<Array>::change(&r_ret); - Array &dst_arr = *VariantGetInternalPtr<Array>::get_ptr(&r_ret); - const T &src_arr = *VariantGetInternalPtr<T>::get_ptr(p_args[0]); - - int size = src_arr.size(); - dst_arr.resize(size); - for (int i = 0; i < size; i++) { - dst_arr[i] = src_arr[i]; - } - } - - static void validated_construct(Variant *r_ret, const Variant **p_args) { - VariantTypeChanger<Array>::change(r_ret); - Array &dst_arr = *VariantGetInternalPtr<Array>::get_ptr(r_ret); - const T &src_arr = *VariantGetInternalPtr<T>::get_ptr(p_args[0]); - - int size = src_arr.size(); - dst_arr.resize(size); - for (int i = 0; i < size; i++) { - dst_arr[i] = src_arr[i]; - } - } - static void ptr_construct(void *base, const void **p_args) { - Array dst_arr; - T src_arr = PtrToArg<T>::convert(p_args[0]); - - int size = src_arr.size(); - dst_arr.resize(size); - for (int i = 0; i < size; i++) { - dst_arr[i] = src_arr[i]; - } - - PtrConstruct<Array>::construct(dst_arr, base); - } - - static int get_argument_count() { - return 1; - } - - static Variant::Type get_argument_type(int p_arg) { - return GetTypeInfo<T>::VARIANT_TYPE; - } - - static Variant::Type get_base_type() { - return Variant::ARRAY; - } -}; - -template <class T> -class VariantConstructorFromArray { -public: - static void construct(Variant &r_ret, const Variant **p_args, Callable::CallError &r_error) { - if (p_args[0]->get_type() != Variant::ARRAY) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; - r_error.argument = 0; - r_error.expected = Variant::ARRAY; - return; - } - - VariantTypeChanger<T>::change(&r_ret); - const Array &src_arr = *VariantGetInternalPtr<Array>::get_ptr(p_args[0]); - T &dst_arr = *VariantGetInternalPtr<T>::get_ptr(&r_ret); - - int size = src_arr.size(); - dst_arr.resize(size); - for (int i = 0; i < size; i++) { - dst_arr.write[i] = src_arr[i]; - } - } - - static void validated_construct(Variant *r_ret, const Variant **p_args) { - VariantTypeChanger<T>::change(r_ret); - const Array &src_arr = *VariantGetInternalPtr<Array>::get_ptr(p_args[0]); - T &dst_arr = *VariantGetInternalPtr<T>::get_ptr(r_ret); - - int size = src_arr.size(); - dst_arr.resize(size); - for (int i = 0; i < size; i++) { - dst_arr.write[i] = src_arr[i]; - } - } - static void ptr_construct(void *base, const void **p_args) { - Array src_arr = PtrToArg<Array>::convert(p_args[0]); - T dst_arr; - - int size = src_arr.size(); - dst_arr.resize(size); - for (int i = 0; i < size; i++) { - dst_arr.write[i] = src_arr[i]; - } - - PtrConstruct<T>::construct(dst_arr, base); - } - - static int get_argument_count() { - return 1; - } - - static Variant::Type get_argument_type(int p_arg) { - return Variant::ARRAY; - } - - static Variant::Type get_base_type() { - return GetTypeInfo<T>::VARIANT_TYPE; - } -}; - -class VariantConstructorNil { -public: - static void construct(Variant &r_ret, const Variant **p_args, Callable::CallError &r_error) { - if (p_args[0]->get_type() != Variant::NIL) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; - r_error.argument = 0; - r_error.expected = Variant::NIL; - return; - } - - r_error.error = Callable::CallError::CALL_OK; - VariantInternal::clear(&r_ret); - } - - static void validated_construct(Variant *r_ret, const Variant **p_args) { - VariantInternal::clear(r_ret); - } - static void ptr_construct(void *base, const void **p_args) { - PtrConstruct<Variant>::construct(Variant(), base); - } - - static int get_argument_count() { - return 1; - } - - static Variant::Type get_argument_type(int p_arg) { - return Variant::NIL; - } - - static Variant::Type get_base_type() { - return Variant::NIL; - } -}; - -template <class T> -class VariantConstructNoArgs { -public: - static void construct(Variant &r_ret, const Variant **p_args, Callable::CallError &r_error) { - VariantTypeChanger<T>::change_and_reset(&r_ret); - r_error.error = Callable::CallError::CALL_OK; - } - - static void validated_construct(Variant *r_ret, const Variant **p_args) { - VariantTypeChanger<T>::change_and_reset(r_ret); - } - static void ptr_construct(void *base, const void **p_args) { - PtrConstruct<T>::construct(T(), base); - } - - static int get_argument_count() { - return 0; - } - - static Variant::Type get_argument_type(int p_arg) { - return Variant::NIL; - } - - static Variant::Type get_base_type() { - return GetTypeInfo<T>::VARIANT_TYPE; - } -}; - -class VariantConstructNoArgsNil { -public: - static void construct(Variant &r_ret, const Variant **p_args, Callable::CallError &r_error) { - VariantInternal::clear(&r_ret); - r_error.error = Callable::CallError::CALL_OK; - } - - static void validated_construct(Variant *r_ret, const Variant **p_args) { - VariantInternal::clear(r_ret); - } - static void ptr_construct(void *base, const void **p_args) { - ERR_FAIL_MSG("can't ptrcall nil constructor"); - } - - static int get_argument_count() { - return 0; - } - - static Variant::Type get_argument_type(int p_arg) { - return Variant::NIL; - } - - static Variant::Type get_base_type() { - return Variant::NIL; - } -}; - -class VariantConstructNoArgsObject { -public: - static void construct(Variant &r_ret, const Variant **p_args, Callable::CallError &r_error) { - VariantInternal::clear(&r_ret); - VariantInternal::object_assign_null(&r_ret); - r_error.error = Callable::CallError::CALL_OK; - } - - static void validated_construct(Variant *r_ret, const Variant **p_args) { - VariantInternal::clear(r_ret); - VariantInternal::object_assign_null(r_ret); - } - static void ptr_construct(void *base, const void **p_args) { - PtrConstruct<Object *>::construct(nullptr, base); - } - - static int get_argument_count() { - return 0; - } - - static Variant::Type get_argument_type(int p_arg) { - return Variant::NIL; - } - - static Variant::Type get_base_type() { - return Variant::OBJECT; - } -}; +#include "variant_construct.h" struct VariantConstructData { void (*construct)(Variant &r_base, const Variant **p_args, Callable::CallError &r_error); diff --git a/core/variant/variant_construct.h b/core/variant/variant_construct.h new file mode 100644 index 0000000000..b03f4a8d3b --- /dev/null +++ b/core/variant/variant_construct.h @@ -0,0 +1,572 @@ +/*************************************************************************/ +/* variant_construct.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef VARIANT_CONSTRUCT_H +#define VARIANT_CONSTRUCT_H + +#include "variant.h" + +#include "core/core_string_names.h" +#include "core/crypto/crypto_core.h" +#include "core/debugger/engine_debugger.h" +#include "core/io/compression.h" +#include "core/object/class_db.h" +#include "core/os/os.h" +#include "core/templates/local_vector.h" +#include "core/templates/oa_hash_map.h" + +template <class T> +struct PtrConstruct {}; + +#define MAKE_PTRCONSTRUCT(m_type) \ + template <> \ + struct PtrConstruct<m_type> { \ + _FORCE_INLINE_ static void construct(const m_type &p_value, void *p_ptr) { \ + memnew_placement(p_ptr, m_type(p_value)); \ + } \ + }; + +MAKE_PTRCONSTRUCT(bool); +MAKE_PTRCONSTRUCT(int64_t); +MAKE_PTRCONSTRUCT(double); +MAKE_PTRCONSTRUCT(String); +MAKE_PTRCONSTRUCT(Vector2); +MAKE_PTRCONSTRUCT(Vector2i); +MAKE_PTRCONSTRUCT(Rect2); +MAKE_PTRCONSTRUCT(Rect2i); +MAKE_PTRCONSTRUCT(Vector3); +MAKE_PTRCONSTRUCT(Vector3i); +MAKE_PTRCONSTRUCT(Transform2D); +MAKE_PTRCONSTRUCT(Plane); +MAKE_PTRCONSTRUCT(Quaternion); +MAKE_PTRCONSTRUCT(AABB); +MAKE_PTRCONSTRUCT(Basis); +MAKE_PTRCONSTRUCT(Transform3D); +MAKE_PTRCONSTRUCT(Color); +MAKE_PTRCONSTRUCT(StringName); +MAKE_PTRCONSTRUCT(NodePath); +MAKE_PTRCONSTRUCT(RID); + +template <> +struct PtrConstruct<Object *> { + _FORCE_INLINE_ static void construct(Object *p_value, void *p_ptr) { + *((Object **)p_ptr) = p_value; + } +}; + +MAKE_PTRCONSTRUCT(Callable); +MAKE_PTRCONSTRUCT(Signal); +MAKE_PTRCONSTRUCT(Dictionary); +MAKE_PTRCONSTRUCT(Array); +MAKE_PTRCONSTRUCT(PackedByteArray); +MAKE_PTRCONSTRUCT(PackedInt32Array); +MAKE_PTRCONSTRUCT(PackedInt64Array); +MAKE_PTRCONSTRUCT(PackedFloat32Array); +MAKE_PTRCONSTRUCT(PackedFloat64Array); +MAKE_PTRCONSTRUCT(PackedStringArray); +MAKE_PTRCONSTRUCT(PackedVector2Array); +MAKE_PTRCONSTRUCT(PackedVector3Array); +MAKE_PTRCONSTRUCT(PackedColorArray); +MAKE_PTRCONSTRUCT(Variant); + +template <class T, class... P> +class VariantConstructor { + template <size_t... Is> + static _FORCE_INLINE_ void construct_helper(T &base, const Variant **p_args, Callable::CallError &r_error, IndexSequence<Is...>) { + r_error.error = Callable::CallError::CALL_OK; + +#ifdef DEBUG_METHODS_ENABLED + base = T(VariantCasterAndValidate<P>::cast(p_args, Is, r_error)...); +#else + base = T(VariantCaster<P>::cast(*p_args[Is])...); +#endif + } + + template <size_t... Is> + static _FORCE_INLINE_ void validated_construct_helper(T &base, const Variant **p_args, IndexSequence<Is...>) { + base = T((*VariantGetInternalPtr<P>::get_ptr(p_args[Is]))...); + } + + template <size_t... Is> + static _FORCE_INLINE_ void ptr_construct_helper(void *base, const void **p_args, IndexSequence<Is...>) { + PtrConstruct<T>::construct(T(PtrToArg<P>::convert(p_args[Is])...), base); + } + +public: + static void construct(Variant &r_ret, const Variant **p_args, Callable::CallError &r_error) { + r_error.error = Callable::CallError::CALL_OK; + VariantTypeChanger<T>::change(&r_ret); + construct_helper(*VariantGetInternalPtr<T>::get_ptr(&r_ret), p_args, r_error, BuildIndexSequence<sizeof...(P)>{}); + } + + static inline void validated_construct(Variant *r_ret, const Variant **p_args) { + VariantTypeChanger<T>::change(r_ret); + validated_construct_helper(*VariantGetInternalPtr<T>::get_ptr(r_ret), p_args, BuildIndexSequence<sizeof...(P)>{}); + } + static void ptr_construct(void *base, const void **p_args) { + ptr_construct_helper(base, p_args, BuildIndexSequence<sizeof...(P)>{}); + } + + static int get_argument_count() { + return sizeof...(P); + } + + static Variant::Type get_argument_type(int p_arg) { + return call_get_argument_type<P...>(p_arg); + } + + static Variant::Type get_base_type() { + return GetTypeInfo<T>::VARIANT_TYPE; + } +}; + +class VariantConstructorObject { +public: + static void construct(Variant &r_ret, const Variant **p_args, Callable::CallError &r_error) { + VariantInternal::clear(&r_ret); + if (p_args[0]->get_type() == Variant::NIL) { + VariantInternal::object_assign_null(&r_ret); + r_error.error = Callable::CallError::CALL_OK; + } else if (p_args[0]->get_type() == Variant::OBJECT) { + VariantInternal::object_assign(&r_ret, p_args[0]); + r_error.error = Callable::CallError::CALL_OK; + } else { + r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument = 0; + r_error.expected = Variant::OBJECT; + } + } + + static inline void validated_construct(Variant *r_ret, const Variant **p_args) { + VariantInternal::clear(r_ret); + VariantInternal::object_assign(r_ret, p_args[0]); + } + static void ptr_construct(void *base, const void **p_args) { + PtrConstruct<Object *>::construct(PtrToArg<Object *>::convert(p_args[0]), base); + } + + static int get_argument_count() { + return 1; + } + + static Variant::Type get_argument_type(int p_arg) { + return Variant::OBJECT; + } + + static Variant::Type get_base_type() { + return Variant::OBJECT; + } +}; + +class VariantConstructorNilObject { +public: + static void construct(Variant &r_ret, const Variant **p_args, Callable::CallError &r_error) { + if (p_args[0]->get_type() != Variant::NIL) { + r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument = 0; + r_error.expected = Variant::NIL; + } + + VariantInternal::clear(&r_ret); + VariantInternal::object_assign_null(&r_ret); + } + + static inline void validated_construct(Variant *r_ret, const Variant **p_args) { + VariantInternal::clear(r_ret); + VariantInternal::object_assign_null(r_ret); + } + static void ptr_construct(void *base, const void **p_args) { + PtrConstruct<Object *>::construct(nullptr, base); + } + + static int get_argument_count() { + return 1; + } + + static Variant::Type get_argument_type(int p_arg) { + return Variant::NIL; + } + + static Variant::Type get_base_type() { + return Variant::OBJECT; + } +}; + +class VariantConstructorCallableArgs { +public: + static void construct(Variant &r_ret, const Variant **p_args, Callable::CallError &r_error) { + ObjectID object_id; + StringName method; + + if (p_args[0]->get_type() == Variant::NIL) { + // leave as is + } else if (p_args[0]->get_type() == Variant::OBJECT) { + object_id = VariantInternal::get_object_id(p_args[0]); + } else { + r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument = 0; + r_error.expected = Variant::OBJECT; + return; + } + + if (p_args[1]->get_type() == Variant::STRING_NAME) { + method = *VariantGetInternalPtr<StringName>::get_ptr(p_args[1]); + } else if (p_args[1]->get_type() == Variant::STRING) { + method = *VariantGetInternalPtr<String>::get_ptr(p_args[1]); + } else { + r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument = 1; + r_error.expected = Variant::STRING_NAME; + return; + } + + VariantTypeChanger<Callable>::change(&r_ret); + *VariantGetInternalPtr<Callable>::get_ptr(&r_ret) = Callable(object_id, method); + } + + static inline void validated_construct(Variant *r_ret, const Variant **p_args) { + VariantTypeChanger<Callable>::change(r_ret); + *VariantGetInternalPtr<Callable>::get_ptr(r_ret) = Callable(VariantInternal::get_object_id(p_args[0]), *VariantGetInternalPtr<StringName>::get_ptr(p_args[1])); + } + static void ptr_construct(void *base, const void **p_args) { + PtrConstruct<Callable>::construct(Callable(PtrToArg<Object *>::convert(p_args[0]), PtrToArg<StringName>::convert(p_args[1])), base); + } + + static int get_argument_count() { + return 2; + } + + static Variant::Type get_argument_type(int p_arg) { + if (p_arg == 0) { + return Variant::OBJECT; + } else { + return Variant::STRING_NAME; + } + } + + static Variant::Type get_base_type() { + return Variant::CALLABLE; + } +}; + +class VariantConstructorSignalArgs { +public: + static void construct(Variant &r_ret, const Variant **p_args, Callable::CallError &r_error) { + ObjectID object_id; + StringName method; + + if (p_args[0]->get_type() == Variant::NIL) { + // leave as is + } else if (p_args[0]->get_type() == Variant::OBJECT) { + object_id = VariantInternal::get_object_id(p_args[0]); + } else { + r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument = 0; + r_error.expected = Variant::OBJECT; + return; + } + + if (p_args[1]->get_type() == Variant::STRING_NAME) { + method = *VariantGetInternalPtr<StringName>::get_ptr(p_args[1]); + } else if (p_args[1]->get_type() == Variant::STRING) { + method = *VariantGetInternalPtr<String>::get_ptr(p_args[1]); + } else { + r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument = 1; + r_error.expected = Variant::STRING_NAME; + return; + } + + VariantTypeChanger<Signal>::change(&r_ret); + *VariantGetInternalPtr<Signal>::get_ptr(&r_ret) = Signal(object_id, method); + } + + static inline void validated_construct(Variant *r_ret, const Variant **p_args) { + VariantTypeChanger<Signal>::change(r_ret); + *VariantGetInternalPtr<Signal>::get_ptr(r_ret) = Signal(VariantInternal::get_object_id(p_args[0]), *VariantGetInternalPtr<StringName>::get_ptr(p_args[1])); + } + static void ptr_construct(void *base, const void **p_args) { + PtrConstruct<Signal>::construct(Signal(PtrToArg<Object *>::convert(p_args[0]), PtrToArg<StringName>::convert(p_args[1])), base); + } + + static int get_argument_count() { + return 2; + } + + static Variant::Type get_argument_type(int p_arg) { + if (p_arg == 0) { + return Variant::OBJECT; + } else { + return Variant::STRING_NAME; + } + } + + static Variant::Type get_base_type() { + return Variant::SIGNAL; + } +}; + +template <class T> +class VariantConstructorToArray { +public: + static void construct(Variant &r_ret, const Variant **p_args, Callable::CallError &r_error) { + if (p_args[0]->get_type() != GetTypeInfo<T>::VARIANT_TYPE) { + r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument = 0; + r_error.expected = GetTypeInfo<T>::VARIANT_TYPE; + return; + } + + VariantTypeChanger<Array>::change(&r_ret); + Array &dst_arr = *VariantGetInternalPtr<Array>::get_ptr(&r_ret); + const T &src_arr = *VariantGetInternalPtr<T>::get_ptr(p_args[0]); + + int size = src_arr.size(); + dst_arr.resize(size); + for (int i = 0; i < size; i++) { + dst_arr[i] = src_arr[i]; + } + } + + static inline void validated_construct(Variant *r_ret, const Variant **p_args) { + VariantTypeChanger<Array>::change(r_ret); + Array &dst_arr = *VariantGetInternalPtr<Array>::get_ptr(r_ret); + const T &src_arr = *VariantGetInternalPtr<T>::get_ptr(p_args[0]); + + int size = src_arr.size(); + dst_arr.resize(size); + for (int i = 0; i < size; i++) { + dst_arr[i] = src_arr[i]; + } + } + static void ptr_construct(void *base, const void **p_args) { + Array dst_arr; + T src_arr = PtrToArg<T>::convert(p_args[0]); + + int size = src_arr.size(); + dst_arr.resize(size); + for (int i = 0; i < size; i++) { + dst_arr[i] = src_arr[i]; + } + + PtrConstruct<Array>::construct(dst_arr, base); + } + + static int get_argument_count() { + return 1; + } + + static Variant::Type get_argument_type(int p_arg) { + return GetTypeInfo<T>::VARIANT_TYPE; + } + + static Variant::Type get_base_type() { + return Variant::ARRAY; + } +}; + +template <class T> +class VariantConstructorFromArray { +public: + static void construct(Variant &r_ret, const Variant **p_args, Callable::CallError &r_error) { + if (p_args[0]->get_type() != Variant::ARRAY) { + r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument = 0; + r_error.expected = Variant::ARRAY; + return; + } + + VariantTypeChanger<T>::change(&r_ret); + const Array &src_arr = *VariantGetInternalPtr<Array>::get_ptr(p_args[0]); + T &dst_arr = *VariantGetInternalPtr<T>::get_ptr(&r_ret); + + int size = src_arr.size(); + dst_arr.resize(size); + for (int i = 0; i < size; i++) { + dst_arr.write[i] = src_arr[i]; + } + } + + static inline void validated_construct(Variant *r_ret, const Variant **p_args) { + VariantTypeChanger<T>::change(r_ret); + const Array &src_arr = *VariantGetInternalPtr<Array>::get_ptr(p_args[0]); + T &dst_arr = *VariantGetInternalPtr<T>::get_ptr(r_ret); + + int size = src_arr.size(); + dst_arr.resize(size); + for (int i = 0; i < size; i++) { + dst_arr.write[i] = src_arr[i]; + } + } + static void ptr_construct(void *base, const void **p_args) { + Array src_arr = PtrToArg<Array>::convert(p_args[0]); + T dst_arr; + + int size = src_arr.size(); + dst_arr.resize(size); + for (int i = 0; i < size; i++) { + dst_arr.write[i] = src_arr[i]; + } + + PtrConstruct<T>::construct(dst_arr, base); + } + + static int get_argument_count() { + return 1; + } + + static Variant::Type get_argument_type(int p_arg) { + return Variant::ARRAY; + } + + static Variant::Type get_base_type() { + return GetTypeInfo<T>::VARIANT_TYPE; + } +}; + +class VariantConstructorNil { +public: + static void construct(Variant &r_ret, const Variant **p_args, Callable::CallError &r_error) { + if (p_args[0]->get_type() != Variant::NIL) { + r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument = 0; + r_error.expected = Variant::NIL; + return; + } + + r_error.error = Callable::CallError::CALL_OK; + VariantInternal::clear(&r_ret); + } + + static inline void validated_construct(Variant *r_ret, const Variant **p_args) { + VariantInternal::clear(r_ret); + } + static void ptr_construct(void *base, const void **p_args) { + PtrConstruct<Variant>::construct(Variant(), base); + } + + static int get_argument_count() { + return 1; + } + + static Variant::Type get_argument_type(int p_arg) { + return Variant::NIL; + } + + static Variant::Type get_base_type() { + return Variant::NIL; + } +}; + +template <class T> +class VariantConstructNoArgs { +public: + static void construct(Variant &r_ret, const Variant **p_args, Callable::CallError &r_error) { + VariantTypeChanger<T>::change_and_reset(&r_ret); + r_error.error = Callable::CallError::CALL_OK; + } + + static inline void validated_construct(Variant *r_ret, const Variant **p_args) { + VariantTypeChanger<T>::change_and_reset(r_ret); + } + static void ptr_construct(void *base, const void **p_args) { + PtrConstruct<T>::construct(T(), base); + } + + static int get_argument_count() { + return 0; + } + + static Variant::Type get_argument_type(int p_arg) { + return Variant::NIL; + } + + static Variant::Type get_base_type() { + return GetTypeInfo<T>::VARIANT_TYPE; + } +}; + +class VariantConstructNoArgsNil { +public: + static void construct(Variant &r_ret, const Variant **p_args, Callable::CallError &r_error) { + VariantInternal::clear(&r_ret); + r_error.error = Callable::CallError::CALL_OK; + } + + static inline void validated_construct(Variant *r_ret, const Variant **p_args) { + VariantInternal::clear(r_ret); + } + static void ptr_construct(void *base, const void **p_args) { + ERR_FAIL_MSG("can't ptrcall nil constructor"); + } + + static int get_argument_count() { + return 0; + } + + static Variant::Type get_argument_type(int p_arg) { + return Variant::NIL; + } + + static Variant::Type get_base_type() { + return Variant::NIL; + } +}; + +class VariantConstructNoArgsObject { +public: + static void construct(Variant &r_ret, const Variant **p_args, Callable::CallError &r_error) { + VariantInternal::clear(&r_ret); + VariantInternal::object_assign_null(&r_ret); + r_error.error = Callable::CallError::CALL_OK; + } + + static inline void validated_construct(Variant *r_ret, const Variant **p_args) { + VariantInternal::clear(r_ret); + VariantInternal::object_assign_null(r_ret); + } + static void ptr_construct(void *base, const void **p_args) { + PtrConstruct<Object *>::construct(nullptr, base); + } + + static int get_argument_count() { + return 0; + } + + static Variant::Type get_argument_type(int p_arg) { + return Variant::NIL; + } + + static Variant::Type get_base_type() { + return Variant::OBJECT; + } +}; + +#endif // VARIANT_CONSTRUCT_H diff --git a/core/variant/variant_op.cpp b/core/variant/variant_op.cpp index e7badd22b8..16c7428781 100644 --- a/core/variant/variant_op.cpp +++ b/core/variant/variant_op.cpp @@ -28,1342 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "variant.h" - -#include "core/core_string_names.h" -#include "core/debugger/engine_debugger.h" -#include "core/object/class_db.h" - -template <class R, class A, class B> -class OperatorEvaluatorAdd { -public: - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); - const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); - *r_ret = a + b; - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - VariantTypeChanger<R>::change(r_ret); - *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) + *VariantGetInternalPtr<B>::get_ptr(right); - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<R>::encode(PtrToArg<A>::convert(left) + PtrToArg<B>::convert(right), r_ret); - } - static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } -}; - -template <class R, class A, class B> -class OperatorEvaluatorSub { -public: - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); - const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); - *r_ret = a - b; - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - VariantTypeChanger<R>::change(r_ret); - *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) - *VariantGetInternalPtr<B>::get_ptr(right); - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<R>::encode(PtrToArg<A>::convert(left) - PtrToArg<B>::convert(right), r_ret); - } - static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } -}; - -template <class R, class A, class B> -class OperatorEvaluatorMul { -public: - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); - const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); - *r_ret = a * b; - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - VariantTypeChanger<R>::change(r_ret); - *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) * *VariantGetInternalPtr<B>::get_ptr(right); - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<R>::encode(PtrToArg<A>::convert(left) * PtrToArg<B>::convert(right), r_ret); - } - static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } -}; - -template <class R, class A, class B> -class OperatorEvaluatorXForm { -public: - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); - const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); - *r_ret = a.xform(b); - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - VariantTypeChanger<R>::change(r_ret); - *VariantGetInternalPtr<R>::get_ptr(r_ret) = VariantGetInternalPtr<A>::get_ptr(left)->xform(*VariantGetInternalPtr<B>::get_ptr(right)); - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<R>::encode(PtrToArg<A>::convert(left).xform(PtrToArg<B>::convert(right)), r_ret); - } - static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } -}; - -template <class R, class A, class B> -class OperatorEvaluatorXFormInv { -public: - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); - const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); - *r_ret = b.xform_inv(a); - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - VariantTypeChanger<R>::change(r_ret); - *VariantGetInternalPtr<R>::get_ptr(r_ret) = VariantGetInternalPtr<B>::get_ptr(right)->xform_inv(*VariantGetInternalPtr<A>::get_ptr(left)); - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<R>::encode(PtrToArg<B>::convert(right).xform_inv(PtrToArg<A>::convert(left)), r_ret); - } - static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } -}; - -template <class R, class A, class B> -class OperatorEvaluatorDiv { -public: - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); - const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); - *r_ret = a / b; - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - VariantTypeChanger<R>::change(r_ret); - *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) / *VariantGetInternalPtr<B>::get_ptr(right); - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<R>::encode(PtrToArg<A>::convert(left) / PtrToArg<B>::convert(right), r_ret); - } - static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } -}; - -template <class R, class A, class B> -class OperatorEvaluatorDivNZ { -public: - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); - const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); - if (b == 0) { - r_valid = false; - *r_ret = "Division by zero error"; - return; - } - *r_ret = a / b; - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - VariantTypeChanger<R>::change(r_ret); - *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) / *VariantGetInternalPtr<B>::get_ptr(right); - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<R>::encode(PtrToArg<A>::convert(left) / PtrToArg<B>::convert(right), r_ret); - } - static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } -}; - -template <class R, class A, class B> -class OperatorEvaluatorMod { -public: - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); - const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); - *r_ret = a % b; - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - VariantTypeChanger<R>::change(r_ret); - *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) % *VariantGetInternalPtr<B>::get_ptr(right); - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<R>::encode(PtrToArg<A>::convert(left) % PtrToArg<B>::convert(right), r_ret); - } - static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } -}; - -template <class R, class A, class B> -class OperatorEvaluatorModNZ { -public: - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); - const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); - if (b == 0) { - r_valid = false; - *r_ret = "Module by zero error"; - return; - } - *r_ret = a % b; - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - VariantTypeChanger<R>::change(r_ret); - *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) % *VariantGetInternalPtr<B>::get_ptr(right); - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<R>::encode(PtrToArg<A>::convert(left) % PtrToArg<B>::convert(right), r_ret); - } - static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } -}; - -template <class R, class A> -class OperatorEvaluatorNeg { -public: - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); - *r_ret = -a; - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - VariantTypeChanger<R>::change(r_ret); - *VariantGetInternalPtr<R>::get_ptr(r_ret) = -*VariantGetInternalPtr<A>::get_ptr(left); - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<R>::encode(-PtrToArg<A>::convert(left), r_ret); - } - static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } -}; - -template <class R, class A> -class OperatorEvaluatorPos { -public: - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); - *r_ret = a; - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - VariantTypeChanger<R>::change(r_ret); - *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left); - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<R>::encode(PtrToArg<A>::convert(left), r_ret); - } - static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } -}; - -template <class R, class A, class B> -class OperatorEvaluatorShiftLeft { -public: - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); - const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); - -#if defined(DEBUG_ENABLED) - if (b < 0 || a < 0) { - *r_ret = "Invalid operands for bit shifting. Only positive operands are supported."; - r_valid = false; - return; - } -#endif - *r_ret = a << b; - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - VariantTypeChanger<R>::change(r_ret); - *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) << *VariantGetInternalPtr<B>::get_ptr(right); - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<R>::encode(PtrToArg<A>::convert(left) << PtrToArg<B>::convert(right), r_ret); - } - static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } -}; - -template <class R, class A, class B> -class OperatorEvaluatorShiftRight { -public: - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); - const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); - -#if defined(DEBUG_ENABLED) - if (b < 0 || a < 0) { - *r_ret = "Invalid operands for bit shifting. Only positive operands are supported."; - r_valid = false; - return; - } -#endif - *r_ret = a >> b; - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - VariantTypeChanger<R>::change(r_ret); - *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) >> *VariantGetInternalPtr<B>::get_ptr(right); - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<R>::encode(PtrToArg<A>::convert(left) >> PtrToArg<B>::convert(right), r_ret); - } - static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } -}; - -template <class R, class A, class B> -class OperatorEvaluatorBitOr { -public: - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); - const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); - *r_ret = a | b; - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - VariantTypeChanger<R>::change(r_ret); - *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) | *VariantGetInternalPtr<B>::get_ptr(right); - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<R>::encode(PtrToArg<A>::convert(left) | PtrToArg<B>::convert(right), r_ret); - } - static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } -}; - -template <class R, class A, class B> -class OperatorEvaluatorBitAnd { -public: - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); - const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); - *r_ret = a & b; - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - VariantTypeChanger<R>::change(r_ret); - *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) & *VariantGetInternalPtr<B>::get_ptr(right); - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<R>::encode(PtrToArg<A>::convert(left) & PtrToArg<B>::convert(right), r_ret); - } - static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } -}; - -template <class R, class A, class B> -class OperatorEvaluatorBitXor { -public: - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); - const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); - *r_ret = a ^ b; - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - VariantTypeChanger<R>::change(r_ret); - *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) ^ *VariantGetInternalPtr<B>::get_ptr(right); - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<R>::encode(PtrToArg<A>::convert(left) ^ PtrToArg<B>::convert(right), r_ret); - } - static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } -}; - -template <class R, class A> -class OperatorEvaluatorBitNeg { -public: - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); - *r_ret = ~a; - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - VariantTypeChanger<R>::change(r_ret); - *VariantGetInternalPtr<R>::get_ptr(r_ret) = ~*VariantGetInternalPtr<A>::get_ptr(left); - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<R>::encode(~PtrToArg<A>::convert(left), r_ret); - } - static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } -}; - -template <class A, class B> -class OperatorEvaluatorEqual { -public: - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); - const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); - *r_ret = a == b; - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - VariantTypeChanger<bool>::change(r_ret); - *VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) == *VariantGetInternalPtr<B>::get_ptr(right); - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<bool>::encode(PtrToArg<A>::convert(left) == PtrToArg<B>::convert(right), r_ret); - } - static Variant::Type get_return_type() { return Variant::BOOL; } -}; - -class OperatorEvaluatorEqualObject { -public: - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - const Object *a = p_left.get_validated_object(); - const Object *b = p_right.get_validated_object(); - *r_ret = a == b; - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - const Object *a = left->get_validated_object(); - const Object *b = right->get_validated_object(); - VariantTypeChanger<bool>::change(r_ret); - *VariantGetInternalPtr<bool>::get_ptr(r_ret) = a == b; - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<bool>::encode(PtrToArg<Object *>::convert(left) == PtrToArg<Object *>::convert(right), r_ret); - } - static Variant::Type get_return_type() { return Variant::BOOL; } -}; - -class OperatorEvaluatorEqualObjectNil { -public: - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - const Object *a = p_left.get_validated_object(); - *r_ret = a == nullptr; - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - const Object *a = left->get_validated_object(); - VariantTypeChanger<bool>::change(r_ret); - *VariantGetInternalPtr<bool>::get_ptr(r_ret) = a == nullptr; - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<bool>::encode(PtrToArg<Object *>::convert(left) == nullptr, r_ret); - } - static Variant::Type get_return_type() { return Variant::BOOL; } -}; - -class OperatorEvaluatorEqualNilObject { -public: - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - const Object *b = p_right.get_validated_object(); - *r_ret = nullptr == b; - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - const Object *b = right->get_validated_object(); - VariantTypeChanger<bool>::change(r_ret); - *VariantGetInternalPtr<bool>::get_ptr(r_ret) = nullptr == b; - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<bool>::encode(nullptr == PtrToArg<Object *>::convert(right), r_ret); - } - static Variant::Type get_return_type() { return Variant::BOOL; } -}; - -template <class A, class B> -class OperatorEvaluatorNotEqual { -public: - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); - const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); - *r_ret = a != b; - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - VariantTypeChanger<bool>::change(r_ret); - *VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) != *VariantGetInternalPtr<B>::get_ptr(right); - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<bool>::encode(PtrToArg<A>::convert(left) != PtrToArg<B>::convert(right), r_ret); - } - static Variant::Type get_return_type() { return Variant::BOOL; } -}; - -class OperatorEvaluatorNotEqualObject { -public: - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - Object *a = p_left.get_validated_object(); - Object *b = p_right.get_validated_object(); - *r_ret = a != b; - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - Object *a = left->get_validated_object(); - Object *b = right->get_validated_object(); - VariantTypeChanger<bool>::change(r_ret); - *VariantGetInternalPtr<bool>::get_ptr(r_ret) = a != b; - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<bool>::encode(PtrToArg<Object *>::convert(left) != PtrToArg<Object *>::convert(right), r_ret); - } - static Variant::Type get_return_type() { return Variant::BOOL; } -}; - -class OperatorEvaluatorNotEqualObjectNil { -public: - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - Object *a = p_left.get_validated_object(); - *r_ret = a != nullptr; - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - Object *a = left->get_validated_object(); - VariantTypeChanger<bool>::change(r_ret); - *VariantGetInternalPtr<bool>::get_ptr(r_ret) = a != nullptr; - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<bool>::encode(PtrToArg<Object *>::convert(left) != nullptr, r_ret); - } - static Variant::Type get_return_type() { return Variant::BOOL; } -}; - -class OperatorEvaluatorNotEqualNilObject { -public: - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - Object *b = p_right.get_validated_object(); - *r_ret = nullptr != b; - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - Object *b = right->get_validated_object(); - VariantTypeChanger<bool>::change(r_ret); - *VariantGetInternalPtr<bool>::get_ptr(r_ret) = nullptr != b; - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<bool>::encode(nullptr != PtrToArg<Object *>::convert(right), r_ret); - } - static Variant::Type get_return_type() { return Variant::BOOL; } -}; - -template <class A, class B> -class OperatorEvaluatorLess { -public: - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); - const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); - *r_ret = a < b; - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - VariantTypeChanger<bool>::change(r_ret); - *VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) < *VariantGetInternalPtr<B>::get_ptr(right); - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<bool>::encode(PtrToArg<A>::convert(left) < PtrToArg<B>::convert(right), r_ret); - } - static Variant::Type get_return_type() { return Variant::BOOL; } -}; - -template <class A, class B> -class OperatorEvaluatorLessEqual { -public: - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); - const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); - *r_ret = a <= b; - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - VariantTypeChanger<bool>::change(r_ret); - *VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) <= *VariantGetInternalPtr<B>::get_ptr(right); - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<bool>::encode(PtrToArg<A>::convert(left) <= PtrToArg<B>::convert(right), r_ret); - } - static Variant::Type get_return_type() { return Variant::BOOL; } -}; - -template <class A, class B> -class OperatorEvaluatorGreater { -public: - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); - const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); - *r_ret = a > b; - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - VariantTypeChanger<bool>::change(r_ret); - *VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) > *VariantGetInternalPtr<B>::get_ptr(right); - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<bool>::encode(PtrToArg<A>::convert(left) > PtrToArg<B>::convert(right), r_ret); - } - static Variant::Type get_return_type() { return Variant::BOOL; } -}; - -template <class A, class B> -class OperatorEvaluatorGreaterEqual { -public: - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); - const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); - *r_ret = a >= b; - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - VariantTypeChanger<bool>::change(r_ret); - *VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) >= *VariantGetInternalPtr<B>::get_ptr(right); - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<bool>::encode(PtrToArg<A>::convert(left) >= PtrToArg<B>::convert(right), r_ret); - } - static Variant::Type get_return_type() { return Variant::BOOL; } -}; - -template <class A, class B> -class OperatorEvaluatorAnd { -public: - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); - const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); - *r_ret = a && b; - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - VariantTypeChanger<bool>::change(r_ret); - *VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) && *VariantGetInternalPtr<B>::get_ptr(right); - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<bool>::encode(PtrToArg<A>::convert(left) && PtrToArg<B>::convert(right), r_ret); - } - static Variant::Type get_return_type() { return Variant::BOOL; } -}; - -template <class A, class B> -class OperatorEvaluatorOr { -public: - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); - const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); - *r_ret = a || b; - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - VariantTypeChanger<bool>::change(r_ret); - *VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) || *VariantGetInternalPtr<B>::get_ptr(right); - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<bool>::encode(PtrToArg<A>::convert(left) || PtrToArg<B>::convert(right), r_ret); - } - static Variant::Type get_return_type() { return Variant::BOOL; } -}; - -#define XOR_OP(m_a, m_b) (((m_a) || (m_b)) && !((m_a) && (m_b))) -template <class A, class B> -class OperatorEvaluatorXor { -public: - _FORCE_INLINE_ static bool xor_op(const A &a, const B &b) { - return ((a) || (b)) && !((a) && (b)); - } - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); - const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); - *r_ret = xor_op(a, b); - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - VariantTypeChanger<bool>::change(r_ret); - *VariantGetInternalPtr<bool>::get_ptr(r_ret) = xor_op(*VariantGetInternalPtr<A>::get_ptr(left), *VariantGetInternalPtr<B>::get_ptr(right)); - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<bool>::encode(xor_op(PtrToArg<A>::convert(left), PtrToArg<B>::convert(right)), r_ret); - } - static Variant::Type get_return_type() { return Variant::BOOL; } -}; - -template <class A> -class OperatorEvaluatorNot { -public: - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); - *r_ret = !a; - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - VariantTypeChanger<bool>::change(r_ret); - *VariantGetInternalPtr<bool>::get_ptr(r_ret) = !*VariantGetInternalPtr<A>::get_ptr(left); - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<bool>::encode(!PtrToArg<A>::convert(left)); - } - static Variant::Type get_return_type() { return Variant::BOOL; } -}; - -//// CUSTOM //// - -class OperatorEvaluatorAddArray { -public: - _FORCE_INLINE_ static void _add_arrays(Array &sum, const Array &array_a, const Array &array_b) { - int asize = array_a.size(); - int bsize = array_b.size(); - sum.resize(asize + bsize); - for (int i = 0; i < asize; i++) { - sum[i] = array_a[i]; - } - for (int i = 0; i < bsize; i++) { - sum[i + asize] = array_b[i]; - } - } - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - const Array &array_a = *VariantGetInternalPtr<Array>::get_ptr(&p_left); - const Array &array_b = *VariantGetInternalPtr<Array>::get_ptr(&p_right); - Array sum; - _add_arrays(sum, array_a, array_b); - *r_ret = sum; - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - VariantTypeChanger<Array>::change(r_ret); - _add_arrays(*VariantGetInternalPtr<Array>::get_ptr(r_ret), *VariantGetInternalPtr<Array>::get_ptr(left), *VariantGetInternalPtr<Array>::get_ptr(right)); - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - Array ret; - _add_arrays(ret, PtrToArg<Array>::convert(left), PtrToArg<Array>::convert(right)); - PtrToArg<Array>::encode(ret, r_ret); - } - static Variant::Type get_return_type() { return Variant::ARRAY; } -}; - -template <class T> -class OperatorEvaluatorAppendArray { -public: - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - const Vector<T> &array_a = *VariantGetInternalPtr<Vector<T>>::get_ptr(&p_left); - const Vector<T> &array_b = *VariantGetInternalPtr<Vector<T>>::get_ptr(&p_right); - Vector<T> sum = array_a; - sum.append_array(array_b); - *r_ret = sum; - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - VariantTypeChanger<Vector<T>>::change(r_ret); - *VariantGetInternalPtr<Vector<T>>::get_ptr(r_ret) = *VariantGetInternalPtr<Vector<T>>::get_ptr(left); - VariantGetInternalPtr<Vector<T>>::get_ptr(r_ret)->append_array(*VariantGetInternalPtr<Vector<T>>::get_ptr(right)); - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - Vector<T> sum = PtrToArg<Vector<T>>::convert(left); - sum.append_array(PtrToArg<Vector<T>>::convert(right)); - PtrToArg<Vector<T>>::encode(sum, r_ret); - } - static Variant::Type get_return_type() { return GetTypeInfo<Vector<T>>::VARIANT_TYPE; } -}; - -class OperatorEvaluatorStringModNil { -public: - _FORCE_INLINE_ static String do_mod(const String &s, bool *r_valid) { - Array values; - values.push_back(Variant()); - - String a = s.sprintf(values, r_valid); - if (r_valid) { - *r_valid = !*r_valid; - } - return a; - } - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - const String &a = *VariantGetInternalPtr<String>::get_ptr(&p_left); - *r_ret = do_mod(a, &r_valid); - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - VariantTypeChanger<String>::change(r_ret); - *VariantGetInternalPtr<String>::get_ptr(r_ret) = do_mod(*VariantGetInternalPtr<String>::get_ptr(left), nullptr); - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<String>::encode(do_mod(PtrToArg<String>::convert(left), nullptr), r_ret); - } - static Variant::Type get_return_type() { return Variant::STRING; } -}; - -class OperatorEvaluatorStringModArray { -public: - _FORCE_INLINE_ static String do_mod(const String &s, const Array &p_values, bool *r_valid) { - String a = s.sprintf(p_values, r_valid); - if (r_valid) { - *r_valid = !*r_valid; - } - return a; - } - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - const String &a = *VariantGetInternalPtr<String>::get_ptr(&p_left); - *r_ret = do_mod(a, *VariantGetInternalPtr<Array>::get_ptr(&p_right), &r_valid); - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - VariantTypeChanger<String>::change(r_ret); - *VariantGetInternalPtr<String>::get_ptr(r_ret) = do_mod(*VariantGetInternalPtr<String>::get_ptr(left), *VariantGetInternalPtr<Array>::get_ptr(right), nullptr); - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<String>::encode(do_mod(PtrToArg<String>::convert(left), PtrToArg<Array>::convert(right), nullptr), r_ret); - } - static Variant::Type get_return_type() { return Variant::STRING; } -}; - -class OperatorEvaluatorStringModObject { -public: - _FORCE_INLINE_ static String do_mod(const String &s, const Object *p_object, bool *r_valid) { - Array values; - values.push_back(p_object); - String a = s.sprintf(values, r_valid); - if (r_valid) { - *r_valid = !*r_valid; - } - - return a; - } - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - const String &a = *VariantGetInternalPtr<String>::get_ptr(&p_left); - *r_ret = do_mod(a, p_right.get_validated_object(), &r_valid); - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - VariantTypeChanger<String>::change(r_ret); - *VariantGetInternalPtr<String>::get_ptr(r_ret) = do_mod(*VariantGetInternalPtr<String>::get_ptr(left), right->get_validated_object(), nullptr); - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<String>::encode(do_mod(PtrToArg<String>::convert(left), PtrToArg<Object *>::convert(right), nullptr), r_ret); - } - static Variant::Type get_return_type() { return Variant::STRING; } -}; - -template <class T> -class OperatorEvaluatorStringModT { -public: - _FORCE_INLINE_ static String do_mod(const String &s, const T &p_value, bool *r_valid) { - Array values; - values.push_back(p_value); - String a = s.sprintf(values, r_valid); - if (r_valid) { - *r_valid = !*r_valid; - } - return a; - } - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - const String &a = *VariantGetInternalPtr<String>::get_ptr(&p_left); - *r_ret = do_mod(a, *VariantGetInternalPtr<T>::get_ptr(&p_right), &r_valid); - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - VariantTypeChanger<String>::change(r_ret); - *VariantGetInternalPtr<String>::get_ptr(r_ret) = do_mod(*VariantGetInternalPtr<String>::get_ptr(left), *VariantGetInternalPtr<T>::get_ptr(right), nullptr); - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<String>::encode(do_mod(PtrToArg<String>::convert(left), PtrToArg<T>::convert(right), nullptr), r_ret); - } - static Variant::Type get_return_type() { return Variant::STRING; } -}; - -template <Variant::Operator op, Variant::Type type_left, Variant::Type type_right> -class OperatorEvaluatorAlwaysTrue { -public: - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - *r_ret = true; - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - VariantTypeChanger<bool>::change(r_ret); - *VariantGetInternalPtr<bool>::get_ptr(r_ret) = true; - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<bool>::encode(true, r_ret); - } - static Variant::Type get_return_type() { return Variant::BOOL; } -}; - -template <Variant::Operator op, Variant::Type type_left, Variant::Type type_right> -class OperatorEvaluatorAlwaysFalse { -public: - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - *r_ret = false; - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - VariantTypeChanger<bool>::change(r_ret); - *VariantGetInternalPtr<bool>::get_ptr(r_ret) = false; - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<bool>::encode(false, r_ret); - } - static Variant::Type get_return_type() { return Variant::BOOL; } -}; - -///// OR /////// - -_FORCE_INLINE_ static bool _operate_or(bool p_left, bool p_right) { - return p_left || p_right; -} - -_FORCE_INLINE_ static bool _operate_and(bool p_left, bool p_right) { - return p_left && p_right; -} - -_FORCE_INLINE_ static bool _operate_xor(bool p_left, bool p_right) { - return (p_left || p_right) && !(p_left && p_right); -} - -_FORCE_INLINE_ static bool _operate_get_nil(const Variant *p_ptr) { - return p_ptr->get_validated_object() != nullptr; -} - -_FORCE_INLINE_ static bool _operate_get_bool(const Variant *p_ptr) { - return *VariantGetInternalPtr<bool>::get_ptr(p_ptr); -} - -_FORCE_INLINE_ static bool _operate_get_int(const Variant *p_ptr) { - return *VariantGetInternalPtr<int64_t>::get_ptr(p_ptr) != 0; -} - -_FORCE_INLINE_ static bool _operate_get_float(const Variant *p_ptr) { - return *VariantGetInternalPtr<double>::get_ptr(p_ptr) != 0.0; -} - -_FORCE_INLINE_ static bool _operate_get_object(const Variant *p_ptr) { - return p_ptr->get_validated_object() != nullptr; -} - -_FORCE_INLINE_ static bool _operate_get_ptr_nil(const void *p_ptr) { - return false; -} - -_FORCE_INLINE_ static bool _operate_get_ptr_bool(const void *p_ptr) { - return PtrToArg<bool>::convert(p_ptr); -} - -_FORCE_INLINE_ static bool _operate_get_ptr_int(const void *p_ptr) { - return PtrToArg<int64_t>::convert(p_ptr) != 0; -} - -_FORCE_INLINE_ static bool _operate_get_ptr_float(const void *p_ptr) { - return PtrToArg<double>::convert(p_ptr) != 0.0; -} - -_FORCE_INLINE_ static bool _operate_get_ptr_object(const void *p_ptr) { - return PtrToArg<Object *>::convert(p_ptr) != nullptr; -} - -#define OP_EVALUATOR(m_class_name, m_left, m_right, m_op) \ - class m_class_name { \ - public: \ - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { \ - *r_ret = m_op(_operate_get_##m_left(&p_left), _operate_get_##m_right(&p_right)); \ - r_valid = true; \ - } \ - \ - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { \ - VariantTypeChanger<bool>::change(r_ret); \ - *VariantGetInternalPtr<bool>::get_ptr(r_ret) = m_op(_operate_get_##m_left(left), _operate_get_##m_right(right)); \ - } \ - \ - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { \ - PtrToArg<bool>::encode(m_op(_operate_get_ptr_##m_left(left), _operate_get_ptr_##m_right(right)), r_ret); \ - } \ - \ - static Variant::Type get_return_type() { \ - return Variant::BOOL; \ - } \ - }; - -// OR - -// nil -OP_EVALUATOR(OperatorEvaluatorNilXBoolOr, nil, bool, _operate_or) -OP_EVALUATOR(OperatorEvaluatorBoolXNilOr, bool, nil, _operate_or) - -OP_EVALUATOR(OperatorEvaluatorNilXIntOr, nil, int, _operate_or) -OP_EVALUATOR(OperatorEvaluatorIntXNilOr, int, nil, _operate_or) - -OP_EVALUATOR(OperatorEvaluatorNilXFloatOr, nil, float, _operate_or) -OP_EVALUATOR(OperatorEvaluatorFloatXNilOr, float, nil, _operate_or) - -OP_EVALUATOR(OperatorEvaluatorObjectXNilOr, object, nil, _operate_or) -OP_EVALUATOR(OperatorEvaluatorNilXObjectOr, nil, object, _operate_or) - -// bool -OP_EVALUATOR(OperatorEvaluatorBoolXBoolOr, bool, bool, _operate_or) - -OP_EVALUATOR(OperatorEvaluatorBoolXIntOr, bool, int, _operate_or) -OP_EVALUATOR(OperatorEvaluatorIntXBoolOr, int, bool, _operate_or) - -OP_EVALUATOR(OperatorEvaluatorBoolXFloatOr, bool, float, _operate_or) -OP_EVALUATOR(OperatorEvaluatorFloatXBoolOr, float, bool, _operate_or) - -OP_EVALUATOR(OperatorEvaluatorBoolXObjectOr, bool, object, _operate_or) -OP_EVALUATOR(OperatorEvaluatorObjectXBoolOr, object, bool, _operate_or) - -// int -OP_EVALUATOR(OperatorEvaluatorIntXIntOr, int, int, _operate_or) - -OP_EVALUATOR(OperatorEvaluatorIntXFloatOr, int, float, _operate_or) -OP_EVALUATOR(OperatorEvaluatorFloatXIntOr, float, int, _operate_or) - -OP_EVALUATOR(OperatorEvaluatorIntXObjectOr, int, object, _operate_or) -OP_EVALUATOR(OperatorEvaluatorObjectXIntOr, object, int, _operate_or) - -// float -OP_EVALUATOR(OperatorEvaluatorFloatXFloatOr, float, float, _operate_or) - -OP_EVALUATOR(OperatorEvaluatorFloatXObjectOr, float, object, _operate_or) -OP_EVALUATOR(OperatorEvaluatorObjectXFloatOr, object, float, _operate_or) - -// object -OP_EVALUATOR(OperatorEvaluatorObjectXObjectOr, object, object, _operate_or) - -// AND - -// nil -OP_EVALUATOR(OperatorEvaluatorNilXBoolAnd, nil, bool, _operate_and) -OP_EVALUATOR(OperatorEvaluatorBoolXNilAnd, bool, nil, _operate_and) - -OP_EVALUATOR(OperatorEvaluatorNilXIntAnd, nil, int, _operate_and) -OP_EVALUATOR(OperatorEvaluatorIntXNilAnd, int, nil, _operate_and) - -OP_EVALUATOR(OperatorEvaluatorNilXFloatAnd, nil, float, _operate_and) -OP_EVALUATOR(OperatorEvaluatorFloatXNilAnd, float, nil, _operate_and) - -OP_EVALUATOR(OperatorEvaluatorObjectXNilAnd, object, nil, _operate_and) -OP_EVALUATOR(OperatorEvaluatorNilXObjectAnd, nil, object, _operate_and) - -// bool -OP_EVALUATOR(OperatorEvaluatorBoolXBoolAnd, bool, bool, _operate_and) - -OP_EVALUATOR(OperatorEvaluatorBoolXIntAnd, bool, int, _operate_and) -OP_EVALUATOR(OperatorEvaluatorIntXBoolAnd, int, bool, _operate_and) - -OP_EVALUATOR(OperatorEvaluatorBoolXFloatAnd, bool, float, _operate_and) -OP_EVALUATOR(OperatorEvaluatorFloatXBoolAnd, float, bool, _operate_and) - -OP_EVALUATOR(OperatorEvaluatorBoolXObjectAnd, bool, object, _operate_and) -OP_EVALUATOR(OperatorEvaluatorObjectXBoolAnd, object, bool, _operate_and) - -// int -OP_EVALUATOR(OperatorEvaluatorIntXIntAnd, int, int, _operate_and) - -OP_EVALUATOR(OperatorEvaluatorIntXFloatAnd, int, float, _operate_and) -OP_EVALUATOR(OperatorEvaluatorFloatXIntAnd, float, int, _operate_and) - -OP_EVALUATOR(OperatorEvaluatorIntXObjectAnd, int, object, _operate_and) -OP_EVALUATOR(OperatorEvaluatorObjectXIntAnd, object, int, _operate_and) - -// float -OP_EVALUATOR(OperatorEvaluatorFloatXFloatAnd, float, float, _operate_and) - -OP_EVALUATOR(OperatorEvaluatorFloatXObjectAnd, float, object, _operate_and) -OP_EVALUATOR(OperatorEvaluatorObjectXFloatAnd, object, float, _operate_and) - -// object -OP_EVALUATOR(OperatorEvaluatorObjectXObjectAnd, object, object, _operate_and) - -// XOR - -// nil -OP_EVALUATOR(OperatorEvaluatorNilXBoolXor, nil, bool, _operate_xor) -OP_EVALUATOR(OperatorEvaluatorBoolXNilXor, bool, nil, _operate_xor) - -OP_EVALUATOR(OperatorEvaluatorNilXIntXor, nil, int, _operate_xor) -OP_EVALUATOR(OperatorEvaluatorIntXNilXor, int, nil, _operate_xor) - -OP_EVALUATOR(OperatorEvaluatorNilXFloatXor, nil, float, _operate_xor) -OP_EVALUATOR(OperatorEvaluatorFloatXNilXor, float, nil, _operate_xor) - -OP_EVALUATOR(OperatorEvaluatorObjectXNilXor, object, nil, _operate_xor) -OP_EVALUATOR(OperatorEvaluatorNilXObjectXor, nil, object, _operate_xor) - -// bool -OP_EVALUATOR(OperatorEvaluatorBoolXBoolXor, bool, bool, _operate_xor) - -OP_EVALUATOR(OperatorEvaluatorBoolXIntXor, bool, int, _operate_xor) -OP_EVALUATOR(OperatorEvaluatorIntXBoolXor, int, bool, _operate_xor) - -OP_EVALUATOR(OperatorEvaluatorBoolXFloatXor, bool, float, _operate_xor) -OP_EVALUATOR(OperatorEvaluatorFloatXBoolXor, float, bool, _operate_xor) - -OP_EVALUATOR(OperatorEvaluatorBoolXObjectXor, bool, object, _operate_xor) -OP_EVALUATOR(OperatorEvaluatorObjectXBoolXor, object, bool, _operate_xor) - -// int -OP_EVALUATOR(OperatorEvaluatorIntXIntXor, int, int, _operate_xor) - -OP_EVALUATOR(OperatorEvaluatorIntXFloatXor, int, float, _operate_xor) -OP_EVALUATOR(OperatorEvaluatorFloatXIntXor, float, int, _operate_xor) - -OP_EVALUATOR(OperatorEvaluatorIntXObjectXor, int, object, _operate_xor) -OP_EVALUATOR(OperatorEvaluatorObjectXIntXor, object, int, _operate_xor) - -// float -OP_EVALUATOR(OperatorEvaluatorFloatXFloatXor, float, float, _operate_xor) - -OP_EVALUATOR(OperatorEvaluatorFloatXObjectXor, float, object, _operate_xor) -OP_EVALUATOR(OperatorEvaluatorObjectXFloatXor, object, float, _operate_xor) - -// object -OP_EVALUATOR(OperatorEvaluatorObjectXObjectXor, object, object, _operate_xor) - -class OperatorEvaluatorNotBool { -public: - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - *r_ret = !*VariantGetInternalPtr<bool>::get_ptr(&p_left); - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - VariantTypeChanger<bool>::change(r_ret); - *VariantGetInternalPtr<bool>::get_ptr(r_ret) = !*VariantGetInternalPtr<bool>::get_ptr(left); - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<bool>::encode(!PtrToArg<bool>::convert(left), r_ret); - } - static Variant::Type get_return_type() { return Variant::BOOL; } -}; - -class OperatorEvaluatorNotInt { -public: - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - *r_ret = !*VariantGetInternalPtr<int64_t>::get_ptr(&p_left); - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - VariantTypeChanger<bool>::change(r_ret); - *VariantGetInternalPtr<bool>::get_ptr(r_ret) = !*VariantGetInternalPtr<int64_t>::get_ptr(left); - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<bool>::encode(!PtrToArg<int64_t>::convert(left), r_ret); - } - static Variant::Type get_return_type() { return Variant::BOOL; } -}; - -class OperatorEvaluatorNotFloat { -public: - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - *r_ret = !*VariantGetInternalPtr<double>::get_ptr(&p_left); - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - VariantTypeChanger<bool>::change(r_ret); - *VariantGetInternalPtr<bool>::get_ptr(r_ret) = !*VariantGetInternalPtr<double>::get_ptr(left); - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<bool>::encode(!PtrToArg<double>::convert(left), r_ret); - } - static Variant::Type get_return_type() { return Variant::BOOL; } -}; - -class OperatorEvaluatorNotObject { -public: - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - *r_ret = p_left.get_validated_object() == nullptr; - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - VariantTypeChanger<bool>::change(r_ret); - *VariantGetInternalPtr<bool>::get_ptr(r_ret) = left->get_validated_object() == nullptr; - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<bool>::encode(PtrToArg<Object *>::convert(left) == nullptr, r_ret); - } - static Variant::Type get_return_type() { return Variant::BOOL; } -}; - -//// - -class OperatorEvaluatorInStringFind { -public: - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - const String &str_a = *VariantGetInternalPtr<String>::get_ptr(&p_left); - const String &str_b = *VariantGetInternalPtr<String>::get_ptr(&p_right); - - *r_ret = str_b.find(str_a) != -1; - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - const String &str_a = *VariantGetInternalPtr<String>::get_ptr(left); - const String &str_b = *VariantGetInternalPtr<String>::get_ptr(right); - VariantTypeChanger<bool>::change(r_ret); - *VariantGetInternalPtr<bool>::get_ptr(r_ret) = str_b.find(str_a) != -1; - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<bool>::encode(PtrToArg<String>::convert(right).find(PtrToArg<String>::convert(left)) != -1, r_ret); - } - static Variant::Type get_return_type() { return Variant::BOOL; } -}; - -template <class A, class B> -class OperatorEvaluatorInArrayFind { -public: - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); - const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); - - *r_ret = b.find(a) != -1; - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - const A &a = *VariantGetInternalPtr<A>::get_ptr(left); - const B &b = *VariantGetInternalPtr<B>::get_ptr(right); - VariantTypeChanger<bool>::change(r_ret); - *VariantGetInternalPtr<bool>::get_ptr(r_ret) = b.find(a) != -1; - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<bool>::encode(PtrToArg<B>::convert(right).find(PtrToArg<A>::convert(left)) != -1, r_ret); - } - static Variant::Type get_return_type() { return Variant::BOOL; } -}; - -class OperatorEvaluatorInArrayFindNil { -public: - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - const Array &b = *VariantGetInternalPtr<Array>::get_ptr(&p_right); - *r_ret = b.find(Variant()) != -1; - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - const Array &b = *VariantGetInternalPtr<Array>::get_ptr(right); - VariantTypeChanger<bool>::change(r_ret); - *VariantGetInternalPtr<bool>::get_ptr(r_ret) = b.find(Variant()) != -1; - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<bool>::encode(PtrToArg<Array>::convert(right).find(Variant()) != -1, r_ret); - } - static Variant::Type get_return_type() { return Variant::BOOL; } -}; - -class OperatorEvaluatorInArrayFindObject { -public: - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - const Array &b = *VariantGetInternalPtr<Array>::get_ptr(&p_right); - *r_ret = b.find(p_left) != -1; - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - const Array &b = *VariantGetInternalPtr<Array>::get_ptr(right); - VariantTypeChanger<bool>::change(r_ret); - *VariantGetInternalPtr<bool>::get_ptr(r_ret) = b.find(*left) != -1; - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<bool>::encode(PtrToArg<Array>::convert(right).find(PtrToArg<Object *>::convert(left)) != -1, r_ret); - } - static Variant::Type get_return_type() { return Variant::BOOL; } -}; - -template <class A> -class OperatorEvaluatorInDictionaryHas { -public: - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - const Dictionary &b = *VariantGetInternalPtr<Dictionary>::get_ptr(&p_right); - const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); - - *r_ret = b.has(a); - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - const Dictionary &b = *VariantGetInternalPtr<Dictionary>::get_ptr(right); - const A &a = *VariantGetInternalPtr<A>::get_ptr(left); - VariantTypeChanger<bool>::change(r_ret); - *VariantGetInternalPtr<bool>::get_ptr(r_ret) = b.has(a); - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<bool>::encode(PtrToArg<Dictionary>::convert(right).has(PtrToArg<A>::convert(left)), r_ret); - } - static Variant::Type get_return_type() { return Variant::BOOL; } -}; - -class OperatorEvaluatorInDictionaryHasNil { -public: - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - const Dictionary &b = *VariantGetInternalPtr<Dictionary>::get_ptr(&p_right); - - *r_ret = b.has(Variant()); - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - const Dictionary &b = *VariantGetInternalPtr<Dictionary>::get_ptr(right); - VariantTypeChanger<bool>::change(r_ret); - *VariantGetInternalPtr<bool>::get_ptr(r_ret) = b.has(Variant()); - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<bool>::encode(PtrToArg<Dictionary>::convert(right).has(Variant()), r_ret); - } - static Variant::Type get_return_type() { return Variant::BOOL; } -}; - -class OperatorEvaluatorInDictionaryHasObject { -public: - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - const Dictionary &b = *VariantGetInternalPtr<Dictionary>::get_ptr(&p_right); - - *r_ret = b.has(p_left); - r_valid = true; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - const Dictionary &b = *VariantGetInternalPtr<Dictionary>::get_ptr(right); - VariantTypeChanger<bool>::change(r_ret); - *VariantGetInternalPtr<bool>::get_ptr(r_ret) = b.has(*left); - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<bool>::encode(PtrToArg<Dictionary>::convert(right).has(PtrToArg<Object *>::convert(left)), r_ret); - } - static Variant::Type get_return_type() { return Variant::BOOL; } -}; - -class OperatorEvaluatorObjectHasPropertyString { -public: - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - Object *b = p_right.get_validated_object(); - if (!b) { - *r_ret = "Invalid base object for 'in'"; - r_valid = false; - return; - } - - const String &a = *VariantGetInternalPtr<String>::get_ptr(&p_left); - - b->get(a, &r_valid); - *r_ret = r_valid; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - Object *l = right->get_validated_object(); - ERR_FAIL_COND(l == nullptr); - const String &a = *VariantGetInternalPtr<String>::get_ptr(left); - - bool valid; - l->get(a, &valid); - VariantTypeChanger<bool>::change(r_ret); - *VariantGetInternalPtr<bool>::get_ptr(r_ret) = valid; - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - bool valid; - PtrToArg<Object *>::convert(right)->get(PtrToArg<String>::convert(left), &valid); - PtrToArg<bool>::encode(valid, r_ret); - } - static Variant::Type get_return_type() { return Variant::BOOL; } -}; - -class OperatorEvaluatorObjectHasPropertyStringName { -public: - static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - Object *b = p_right.get_validated_object(); - if (!b) { - *r_ret = "Invalid base object for 'in'"; - r_valid = false; - return; - } - - const StringName &a = *VariantGetInternalPtr<StringName>::get_ptr(&p_left); - - b->get(a, &r_valid); - *r_ret = r_valid; - } - static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { - Object *l = right->get_validated_object(); - ERR_FAIL_COND(l == nullptr); - const StringName &a = *VariantGetInternalPtr<StringName>::get_ptr(left); - - bool valid; - l->get(a, &valid); - VariantTypeChanger<bool>::change(r_ret); - *VariantGetInternalPtr<bool>::get_ptr(r_ret) = valid; - } - static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - bool valid; - PtrToArg<Object *>::convert(right)->get(PtrToArg<StringName>::convert(left), &valid); - PtrToArg<bool>::encode(valid, r_ret); - } - static Variant::Type get_return_type() { return Variant::BOOL; } -}; +#include "variant_op.h" typedef void (*VariantEvaluatorFunction)(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid); @@ -1996,8 +661,8 @@ static const char *_op_names[Variant::OP_MAX] = { "-", "*", "/", - "-", - "+", + "unary-", + "unary+", "%", "<<", ">>", diff --git a/core/variant/variant_op.h b/core/variant/variant_op.h new file mode 100644 index 0000000000..e744e76ea3 --- /dev/null +++ b/core/variant/variant_op.h @@ -0,0 +1,1316 @@ +/*************************************************************************/ +/* variant_op.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef VARIANT_OP_H +#define VARIANT_OP_H + +#include "variant.h" + +#include "core/core_string_names.h" +#include "core/debugger/engine_debugger.h" +#include "core/object/class_db.h" + +template <class R, class A, class B> +class OperatorEvaluatorAdd { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); + const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); + *r_ret = a + b; + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) + *VariantGetInternalPtr<B>::get_ptr(right); + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<R>::encode(PtrToArg<A>::convert(left) + PtrToArg<B>::convert(right), r_ret); + } + static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } +}; + +template <class R, class A, class B> +class OperatorEvaluatorSub { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); + const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); + *r_ret = a - b; + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) - *VariantGetInternalPtr<B>::get_ptr(right); + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<R>::encode(PtrToArg<A>::convert(left) - PtrToArg<B>::convert(right), r_ret); + } + static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } +}; + +template <class R, class A, class B> +class OperatorEvaluatorMul { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); + const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); + *r_ret = a * b; + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) * *VariantGetInternalPtr<B>::get_ptr(right); + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<R>::encode(PtrToArg<A>::convert(left) * PtrToArg<B>::convert(right), r_ret); + } + static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } +}; + +template <class R, class A, class B> +class OperatorEvaluatorXForm { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); + const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); + *r_ret = a.xform(b); + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + *VariantGetInternalPtr<R>::get_ptr(r_ret) = VariantGetInternalPtr<A>::get_ptr(left)->xform(*VariantGetInternalPtr<B>::get_ptr(right)); + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<R>::encode(PtrToArg<A>::convert(left).xform(PtrToArg<B>::convert(right)), r_ret); + } + static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } +}; + +template <class R, class A, class B> +class OperatorEvaluatorXFormInv { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); + const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); + *r_ret = b.xform_inv(a); + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + *VariantGetInternalPtr<R>::get_ptr(r_ret) = VariantGetInternalPtr<B>::get_ptr(right)->xform_inv(*VariantGetInternalPtr<A>::get_ptr(left)); + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<R>::encode(PtrToArg<B>::convert(right).xform_inv(PtrToArg<A>::convert(left)), r_ret); + } + static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } +}; + +template <class R, class A, class B> +class OperatorEvaluatorDiv { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); + const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); + *r_ret = a / b; + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) / *VariantGetInternalPtr<B>::get_ptr(right); + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<R>::encode(PtrToArg<A>::convert(left) / PtrToArg<B>::convert(right), r_ret); + } + static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } +}; + +template <class R, class A, class B> +class OperatorEvaluatorDivNZ { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); + const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); + if (b == 0) { + r_valid = false; + *r_ret = "Division by zero error"; + return; + } + *r_ret = a / b; + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) / *VariantGetInternalPtr<B>::get_ptr(right); + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<R>::encode(PtrToArg<A>::convert(left) / PtrToArg<B>::convert(right), r_ret); + } + static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } +}; + +template <class R, class A, class B> +class OperatorEvaluatorMod { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); + const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); + *r_ret = a % b; + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) % *VariantGetInternalPtr<B>::get_ptr(right); + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<R>::encode(PtrToArg<A>::convert(left) % PtrToArg<B>::convert(right), r_ret); + } + static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } +}; + +template <class R, class A, class B> +class OperatorEvaluatorModNZ { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); + const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); + if (b == 0) { + r_valid = false; + *r_ret = "Module by zero error"; + return; + } + *r_ret = a % b; + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) % *VariantGetInternalPtr<B>::get_ptr(right); + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<R>::encode(PtrToArg<A>::convert(left) % PtrToArg<B>::convert(right), r_ret); + } + static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } +}; + +template <class R, class A> +class OperatorEvaluatorNeg { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); + *r_ret = -a; + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + *VariantGetInternalPtr<R>::get_ptr(r_ret) = -*VariantGetInternalPtr<A>::get_ptr(left); + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<R>::encode(-PtrToArg<A>::convert(left), r_ret); + } + static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } +}; + +template <class R, class A> +class OperatorEvaluatorPos { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); + *r_ret = a; + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left); + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<R>::encode(PtrToArg<A>::convert(left), r_ret); + } + static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } +}; + +template <class R, class A, class B> +class OperatorEvaluatorShiftLeft { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); + const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); + +#if defined(DEBUG_ENABLED) + if (b < 0 || a < 0) { + *r_ret = "Invalid operands for bit shifting. Only positive operands are supported."; + r_valid = false; + return; + } +#endif + *r_ret = a << b; + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) << *VariantGetInternalPtr<B>::get_ptr(right); + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<R>::encode(PtrToArg<A>::convert(left) << PtrToArg<B>::convert(right), r_ret); + } + static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } +}; + +template <class R, class A, class B> +class OperatorEvaluatorShiftRight { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); + const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); + +#if defined(DEBUG_ENABLED) + if (b < 0 || a < 0) { + *r_ret = "Invalid operands for bit shifting. Only positive operands are supported."; + r_valid = false; + return; + } +#endif + *r_ret = a >> b; + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) >> *VariantGetInternalPtr<B>::get_ptr(right); + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<R>::encode(PtrToArg<A>::convert(left) >> PtrToArg<B>::convert(right), r_ret); + } + static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } +}; + +template <class R, class A, class B> +class OperatorEvaluatorBitOr { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); + const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); + *r_ret = a | b; + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) | *VariantGetInternalPtr<B>::get_ptr(right); + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<R>::encode(PtrToArg<A>::convert(left) | PtrToArg<B>::convert(right), r_ret); + } + static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } +}; + +template <class R, class A, class B> +class OperatorEvaluatorBitAnd { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); + const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); + *r_ret = a & b; + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) & *VariantGetInternalPtr<B>::get_ptr(right); + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<R>::encode(PtrToArg<A>::convert(left) & PtrToArg<B>::convert(right), r_ret); + } + static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } +}; + +template <class R, class A, class B> +class OperatorEvaluatorBitXor { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); + const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); + *r_ret = a ^ b; + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) ^ *VariantGetInternalPtr<B>::get_ptr(right); + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<R>::encode(PtrToArg<A>::convert(left) ^ PtrToArg<B>::convert(right), r_ret); + } + static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } +}; + +template <class R, class A> +class OperatorEvaluatorBitNeg { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); + *r_ret = ~a; + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + *VariantGetInternalPtr<R>::get_ptr(r_ret) = ~*VariantGetInternalPtr<A>::get_ptr(left); + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<R>::encode(~PtrToArg<A>::convert(left), r_ret); + } + static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } +}; + +template <class A, class B> +class OperatorEvaluatorEqual { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); + const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); + *r_ret = a == b; + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + *VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) == *VariantGetInternalPtr<B>::get_ptr(right); + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<bool>::encode(PtrToArg<A>::convert(left) == PtrToArg<B>::convert(right), r_ret); + } + static Variant::Type get_return_type() { return Variant::BOOL; } +}; + +class OperatorEvaluatorEqualObject { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + const Object *a = p_left.get_validated_object(); + const Object *b = p_right.get_validated_object(); + *r_ret = a == b; + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + const Object *a = left->get_validated_object(); + const Object *b = right->get_validated_object(); + *VariantGetInternalPtr<bool>::get_ptr(r_ret) = a == b; + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<bool>::encode(PtrToArg<Object *>::convert(left) == PtrToArg<Object *>::convert(right), r_ret); + } + static Variant::Type get_return_type() { return Variant::BOOL; } +}; + +class OperatorEvaluatorEqualObjectNil { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + const Object *a = p_left.get_validated_object(); + *r_ret = a == nullptr; + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + const Object *a = left->get_validated_object(); + *VariantGetInternalPtr<bool>::get_ptr(r_ret) = a == nullptr; + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<bool>::encode(PtrToArg<Object *>::convert(left) == nullptr, r_ret); + } + static Variant::Type get_return_type() { return Variant::BOOL; } +}; + +class OperatorEvaluatorEqualNilObject { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + const Object *b = p_right.get_validated_object(); + *r_ret = nullptr == b; + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + const Object *b = right->get_validated_object(); + *VariantGetInternalPtr<bool>::get_ptr(r_ret) = nullptr == b; + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<bool>::encode(nullptr == PtrToArg<Object *>::convert(right), r_ret); + } + static Variant::Type get_return_type() { return Variant::BOOL; } +}; + +template <class A, class B> +class OperatorEvaluatorNotEqual { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); + const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); + *r_ret = a != b; + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + *VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) != *VariantGetInternalPtr<B>::get_ptr(right); + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<bool>::encode(PtrToArg<A>::convert(left) != PtrToArg<B>::convert(right), r_ret); + } + static Variant::Type get_return_type() { return Variant::BOOL; } +}; + +class OperatorEvaluatorNotEqualObject { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + Object *a = p_left.get_validated_object(); + Object *b = p_right.get_validated_object(); + *r_ret = a != b; + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + Object *a = left->get_validated_object(); + Object *b = right->get_validated_object(); + *VariantGetInternalPtr<bool>::get_ptr(r_ret) = a != b; + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<bool>::encode(PtrToArg<Object *>::convert(left) != PtrToArg<Object *>::convert(right), r_ret); + } + static Variant::Type get_return_type() { return Variant::BOOL; } +}; + +class OperatorEvaluatorNotEqualObjectNil { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + Object *a = p_left.get_validated_object(); + *r_ret = a != nullptr; + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + Object *a = left->get_validated_object(); + *VariantGetInternalPtr<bool>::get_ptr(r_ret) = a != nullptr; + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<bool>::encode(PtrToArg<Object *>::convert(left) != nullptr, r_ret); + } + static Variant::Type get_return_type() { return Variant::BOOL; } +}; + +class OperatorEvaluatorNotEqualNilObject { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + Object *b = p_right.get_validated_object(); + *r_ret = nullptr != b; + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + Object *b = right->get_validated_object(); + *VariantGetInternalPtr<bool>::get_ptr(r_ret) = nullptr != b; + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<bool>::encode(nullptr != PtrToArg<Object *>::convert(right), r_ret); + } + static Variant::Type get_return_type() { return Variant::BOOL; } +}; + +template <class A, class B> +class OperatorEvaluatorLess { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); + const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); + *r_ret = a < b; + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + *VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) < *VariantGetInternalPtr<B>::get_ptr(right); + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<bool>::encode(PtrToArg<A>::convert(left) < PtrToArg<B>::convert(right), r_ret); + } + static Variant::Type get_return_type() { return Variant::BOOL; } +}; + +template <class A, class B> +class OperatorEvaluatorLessEqual { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); + const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); + *r_ret = a <= b; + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + *VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) <= *VariantGetInternalPtr<B>::get_ptr(right); + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<bool>::encode(PtrToArg<A>::convert(left) <= PtrToArg<B>::convert(right), r_ret); + } + static Variant::Type get_return_type() { return Variant::BOOL; } +}; + +template <class A, class B> +class OperatorEvaluatorGreater { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); + const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); + *r_ret = a > b; + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + *VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) > *VariantGetInternalPtr<B>::get_ptr(right); + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<bool>::encode(PtrToArg<A>::convert(left) > PtrToArg<B>::convert(right), r_ret); + } + static Variant::Type get_return_type() { return Variant::BOOL; } +}; + +template <class A, class B> +class OperatorEvaluatorGreaterEqual { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); + const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); + *r_ret = a >= b; + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + *VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) >= *VariantGetInternalPtr<B>::get_ptr(right); + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<bool>::encode(PtrToArg<A>::convert(left) >= PtrToArg<B>::convert(right), r_ret); + } + static Variant::Type get_return_type() { return Variant::BOOL; } +}; + +template <class A, class B> +class OperatorEvaluatorAnd { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); + const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); + *r_ret = a && b; + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + *VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) && *VariantGetInternalPtr<B>::get_ptr(right); + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<bool>::encode(PtrToArg<A>::convert(left) && PtrToArg<B>::convert(right), r_ret); + } + static Variant::Type get_return_type() { return Variant::BOOL; } +}; + +template <class A, class B> +class OperatorEvaluatorOr { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); + const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); + *r_ret = a || b; + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + *VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) || *VariantGetInternalPtr<B>::get_ptr(right); + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<bool>::encode(PtrToArg<A>::convert(left) || PtrToArg<B>::convert(right), r_ret); + } + static Variant::Type get_return_type() { return Variant::BOOL; } +}; + +#define XOR_OP(m_a, m_b) (((m_a) || (m_b)) && !((m_a) && (m_b))) +template <class A, class B> +class OperatorEvaluatorXor { +public: + _FORCE_INLINE_ static bool xor_op(const A &a, const B &b) { + return ((a) || (b)) && !((a) && (b)); + } + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); + const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); + *r_ret = xor_op(a, b); + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + *VariantGetInternalPtr<bool>::get_ptr(r_ret) = xor_op(*VariantGetInternalPtr<A>::get_ptr(left), *VariantGetInternalPtr<B>::get_ptr(right)); + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<bool>::encode(xor_op(PtrToArg<A>::convert(left), PtrToArg<B>::convert(right)), r_ret); + } + static Variant::Type get_return_type() { return Variant::BOOL; } +}; + +template <class A> +class OperatorEvaluatorNot { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); + *r_ret = !a; + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + *VariantGetInternalPtr<bool>::get_ptr(r_ret) = !*VariantGetInternalPtr<A>::get_ptr(left); + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<bool>::encode(!PtrToArg<A>::convert(left)); + } + static Variant::Type get_return_type() { return Variant::BOOL; } +}; + +//// CUSTOM //// + +class OperatorEvaluatorAddArray { +public: + _FORCE_INLINE_ static void _add_arrays(Array &sum, const Array &array_a, const Array &array_b) { + int asize = array_a.size(); + int bsize = array_b.size(); + sum.resize(asize + bsize); + for (int i = 0; i < asize; i++) { + sum[i] = array_a[i]; + } + for (int i = 0; i < bsize; i++) { + sum[i + asize] = array_b[i]; + } + } + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + const Array &array_a = *VariantGetInternalPtr<Array>::get_ptr(&p_left); + const Array &array_b = *VariantGetInternalPtr<Array>::get_ptr(&p_right); + Array sum; + _add_arrays(sum, array_a, array_b); + *r_ret = sum; + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + _add_arrays(*VariantGetInternalPtr<Array>::get_ptr(r_ret), *VariantGetInternalPtr<Array>::get_ptr(left), *VariantGetInternalPtr<Array>::get_ptr(right)); + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + Array ret; + _add_arrays(ret, PtrToArg<Array>::convert(left), PtrToArg<Array>::convert(right)); + PtrToArg<Array>::encode(ret, r_ret); + } + static Variant::Type get_return_type() { return Variant::ARRAY; } +}; + +template <class T> +class OperatorEvaluatorAppendArray { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + const Vector<T> &array_a = *VariantGetInternalPtr<Vector<T>>::get_ptr(&p_left); + const Vector<T> &array_b = *VariantGetInternalPtr<Vector<T>>::get_ptr(&p_right); + Vector<T> sum = array_a; + sum.append_array(array_b); + *r_ret = sum; + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + *VariantGetInternalPtr<Vector<T>>::get_ptr(r_ret) = *VariantGetInternalPtr<Vector<T>>::get_ptr(left); + VariantGetInternalPtr<Vector<T>>::get_ptr(r_ret)->append_array(*VariantGetInternalPtr<Vector<T>>::get_ptr(right)); + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + Vector<T> sum = PtrToArg<Vector<T>>::convert(left); + sum.append_array(PtrToArg<Vector<T>>::convert(right)); + PtrToArg<Vector<T>>::encode(sum, r_ret); + } + static Variant::Type get_return_type() { return GetTypeInfo<Vector<T>>::VARIANT_TYPE; } +}; + +class OperatorEvaluatorStringModNil { +public: + _FORCE_INLINE_ static String do_mod(const String &s, bool *r_valid) { + Array values; + values.push_back(Variant()); + + String a = s.sprintf(values, r_valid); + if (r_valid) { + *r_valid = !*r_valid; + } + return a; + } + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + const String &a = *VariantGetInternalPtr<String>::get_ptr(&p_left); + *r_ret = do_mod(a, &r_valid); + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + *VariantGetInternalPtr<String>::get_ptr(r_ret) = do_mod(*VariantGetInternalPtr<String>::get_ptr(left), nullptr); + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<String>::encode(do_mod(PtrToArg<String>::convert(left), nullptr), r_ret); + } + static Variant::Type get_return_type() { return Variant::STRING; } +}; + +class OperatorEvaluatorStringModArray { +public: + _FORCE_INLINE_ static String do_mod(const String &s, const Array &p_values, bool *r_valid) { + String a = s.sprintf(p_values, r_valid); + if (r_valid) { + *r_valid = !*r_valid; + } + return a; + } + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + const String &a = *VariantGetInternalPtr<String>::get_ptr(&p_left); + *r_ret = do_mod(a, *VariantGetInternalPtr<Array>::get_ptr(&p_right), &r_valid); + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + *VariantGetInternalPtr<String>::get_ptr(r_ret) = do_mod(*VariantGetInternalPtr<String>::get_ptr(left), *VariantGetInternalPtr<Array>::get_ptr(right), nullptr); + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<String>::encode(do_mod(PtrToArg<String>::convert(left), PtrToArg<Array>::convert(right), nullptr), r_ret); + } + static Variant::Type get_return_type() { return Variant::STRING; } +}; + +class OperatorEvaluatorStringModObject { +public: + _FORCE_INLINE_ static String do_mod(const String &s, const Object *p_object, bool *r_valid) { + Array values; + values.push_back(p_object); + String a = s.sprintf(values, r_valid); + if (r_valid) { + *r_valid = !*r_valid; + } + + return a; + } + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + const String &a = *VariantGetInternalPtr<String>::get_ptr(&p_left); + *r_ret = do_mod(a, p_right.get_validated_object(), &r_valid); + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + *VariantGetInternalPtr<String>::get_ptr(r_ret) = do_mod(*VariantGetInternalPtr<String>::get_ptr(left), right->get_validated_object(), nullptr); + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<String>::encode(do_mod(PtrToArg<String>::convert(left), PtrToArg<Object *>::convert(right), nullptr), r_ret); + } + static Variant::Type get_return_type() { return Variant::STRING; } +}; + +template <class T> +class OperatorEvaluatorStringModT { +public: + _FORCE_INLINE_ static String do_mod(const String &s, const T &p_value, bool *r_valid) { + Array values; + values.push_back(p_value); + String a = s.sprintf(values, r_valid); + if (r_valid) { + *r_valid = !*r_valid; + } + return a; + } + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + const String &a = *VariantGetInternalPtr<String>::get_ptr(&p_left); + *r_ret = do_mod(a, *VariantGetInternalPtr<T>::get_ptr(&p_right), &r_valid); + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + *VariantGetInternalPtr<String>::get_ptr(r_ret) = do_mod(*VariantGetInternalPtr<String>::get_ptr(left), *VariantGetInternalPtr<T>::get_ptr(right), nullptr); + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<String>::encode(do_mod(PtrToArg<String>::convert(left), PtrToArg<T>::convert(right), nullptr), r_ret); + } + static Variant::Type get_return_type() { return Variant::STRING; } +}; + +template <Variant::Operator op, Variant::Type type_left, Variant::Type type_right> +class OperatorEvaluatorAlwaysTrue { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + *r_ret = true; + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + *VariantGetInternalPtr<bool>::get_ptr(r_ret) = true; + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<bool>::encode(true, r_ret); + } + static Variant::Type get_return_type() { return Variant::BOOL; } +}; + +template <Variant::Operator op, Variant::Type type_left, Variant::Type type_right> +class OperatorEvaluatorAlwaysFalse { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + *r_ret = false; + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + *VariantGetInternalPtr<bool>::get_ptr(r_ret) = false; + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<bool>::encode(false, r_ret); + } + static Variant::Type get_return_type() { return Variant::BOOL; } +}; + +///// OR /////// + +_FORCE_INLINE_ static bool _operate_or(bool p_left, bool p_right) { + return p_left || p_right; +} + +_FORCE_INLINE_ static bool _operate_and(bool p_left, bool p_right) { + return p_left && p_right; +} + +_FORCE_INLINE_ static bool _operate_xor(bool p_left, bool p_right) { + return (p_left || p_right) && !(p_left && p_right); +} + +_FORCE_INLINE_ static bool _operate_get_nil(const Variant *p_ptr) { + return p_ptr->get_validated_object() != nullptr; +} + +_FORCE_INLINE_ static bool _operate_get_bool(const Variant *p_ptr) { + return *VariantGetInternalPtr<bool>::get_ptr(p_ptr); +} + +_FORCE_INLINE_ static bool _operate_get_int(const Variant *p_ptr) { + return *VariantGetInternalPtr<int64_t>::get_ptr(p_ptr) != 0; +} + +_FORCE_INLINE_ static bool _operate_get_float(const Variant *p_ptr) { + return *VariantGetInternalPtr<double>::get_ptr(p_ptr) != 0.0; +} + +_FORCE_INLINE_ static bool _operate_get_object(const Variant *p_ptr) { + return p_ptr->get_validated_object() != nullptr; +} + +_FORCE_INLINE_ static bool _operate_get_ptr_nil(const void *p_ptr) { + return false; +} + +_FORCE_INLINE_ static bool _operate_get_ptr_bool(const void *p_ptr) { + return PtrToArg<bool>::convert(p_ptr); +} + +_FORCE_INLINE_ static bool _operate_get_ptr_int(const void *p_ptr) { + return PtrToArg<int64_t>::convert(p_ptr) != 0; +} + +_FORCE_INLINE_ static bool _operate_get_ptr_float(const void *p_ptr) { + return PtrToArg<double>::convert(p_ptr) != 0.0; +} + +_FORCE_INLINE_ static bool _operate_get_ptr_object(const void *p_ptr) { + return PtrToArg<Object *>::convert(p_ptr) != nullptr; +} + +#define OP_EVALUATOR(m_class_name, m_left, m_right, m_op) \ + class m_class_name { \ + public: \ + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { \ + *r_ret = m_op(_operate_get_##m_left(&p_left), _operate_get_##m_right(&p_right)); \ + r_valid = true; \ + } \ + \ + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { \ + *VariantGetInternalPtr<bool>::get_ptr(r_ret) = m_op(_operate_get_##m_left(left), _operate_get_##m_right(right)); \ + } \ + \ + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { \ + PtrToArg<bool>::encode(m_op(_operate_get_ptr_##m_left(left), _operate_get_ptr_##m_right(right)), r_ret); \ + } \ + \ + static Variant::Type get_return_type() { \ + return Variant::BOOL; \ + } \ + }; + +// OR + +// nil +OP_EVALUATOR(OperatorEvaluatorNilXBoolOr, nil, bool, _operate_or) +OP_EVALUATOR(OperatorEvaluatorBoolXNilOr, bool, nil, _operate_or) + +OP_EVALUATOR(OperatorEvaluatorNilXIntOr, nil, int, _operate_or) +OP_EVALUATOR(OperatorEvaluatorIntXNilOr, int, nil, _operate_or) + +OP_EVALUATOR(OperatorEvaluatorNilXFloatOr, nil, float, _operate_or) +OP_EVALUATOR(OperatorEvaluatorFloatXNilOr, float, nil, _operate_or) + +OP_EVALUATOR(OperatorEvaluatorObjectXNilOr, object, nil, _operate_or) +OP_EVALUATOR(OperatorEvaluatorNilXObjectOr, nil, object, _operate_or) + +// bool +OP_EVALUATOR(OperatorEvaluatorBoolXBoolOr, bool, bool, _operate_or) + +OP_EVALUATOR(OperatorEvaluatorBoolXIntOr, bool, int, _operate_or) +OP_EVALUATOR(OperatorEvaluatorIntXBoolOr, int, bool, _operate_or) + +OP_EVALUATOR(OperatorEvaluatorBoolXFloatOr, bool, float, _operate_or) +OP_EVALUATOR(OperatorEvaluatorFloatXBoolOr, float, bool, _operate_or) + +OP_EVALUATOR(OperatorEvaluatorBoolXObjectOr, bool, object, _operate_or) +OP_EVALUATOR(OperatorEvaluatorObjectXBoolOr, object, bool, _operate_or) + +// int +OP_EVALUATOR(OperatorEvaluatorIntXIntOr, int, int, _operate_or) + +OP_EVALUATOR(OperatorEvaluatorIntXFloatOr, int, float, _operate_or) +OP_EVALUATOR(OperatorEvaluatorFloatXIntOr, float, int, _operate_or) + +OP_EVALUATOR(OperatorEvaluatorIntXObjectOr, int, object, _operate_or) +OP_EVALUATOR(OperatorEvaluatorObjectXIntOr, object, int, _operate_or) + +// float +OP_EVALUATOR(OperatorEvaluatorFloatXFloatOr, float, float, _operate_or) + +OP_EVALUATOR(OperatorEvaluatorFloatXObjectOr, float, object, _operate_or) +OP_EVALUATOR(OperatorEvaluatorObjectXFloatOr, object, float, _operate_or) + +// object +OP_EVALUATOR(OperatorEvaluatorObjectXObjectOr, object, object, _operate_or) + +// AND + +// nil +OP_EVALUATOR(OperatorEvaluatorNilXBoolAnd, nil, bool, _operate_and) +OP_EVALUATOR(OperatorEvaluatorBoolXNilAnd, bool, nil, _operate_and) + +OP_EVALUATOR(OperatorEvaluatorNilXIntAnd, nil, int, _operate_and) +OP_EVALUATOR(OperatorEvaluatorIntXNilAnd, int, nil, _operate_and) + +OP_EVALUATOR(OperatorEvaluatorNilXFloatAnd, nil, float, _operate_and) +OP_EVALUATOR(OperatorEvaluatorFloatXNilAnd, float, nil, _operate_and) + +OP_EVALUATOR(OperatorEvaluatorObjectXNilAnd, object, nil, _operate_and) +OP_EVALUATOR(OperatorEvaluatorNilXObjectAnd, nil, object, _operate_and) + +// bool +OP_EVALUATOR(OperatorEvaluatorBoolXBoolAnd, bool, bool, _operate_and) + +OP_EVALUATOR(OperatorEvaluatorBoolXIntAnd, bool, int, _operate_and) +OP_EVALUATOR(OperatorEvaluatorIntXBoolAnd, int, bool, _operate_and) + +OP_EVALUATOR(OperatorEvaluatorBoolXFloatAnd, bool, float, _operate_and) +OP_EVALUATOR(OperatorEvaluatorFloatXBoolAnd, float, bool, _operate_and) + +OP_EVALUATOR(OperatorEvaluatorBoolXObjectAnd, bool, object, _operate_and) +OP_EVALUATOR(OperatorEvaluatorObjectXBoolAnd, object, bool, _operate_and) + +// int +OP_EVALUATOR(OperatorEvaluatorIntXIntAnd, int, int, _operate_and) + +OP_EVALUATOR(OperatorEvaluatorIntXFloatAnd, int, float, _operate_and) +OP_EVALUATOR(OperatorEvaluatorFloatXIntAnd, float, int, _operate_and) + +OP_EVALUATOR(OperatorEvaluatorIntXObjectAnd, int, object, _operate_and) +OP_EVALUATOR(OperatorEvaluatorObjectXIntAnd, object, int, _operate_and) + +// float +OP_EVALUATOR(OperatorEvaluatorFloatXFloatAnd, float, float, _operate_and) + +OP_EVALUATOR(OperatorEvaluatorFloatXObjectAnd, float, object, _operate_and) +OP_EVALUATOR(OperatorEvaluatorObjectXFloatAnd, object, float, _operate_and) + +// object +OP_EVALUATOR(OperatorEvaluatorObjectXObjectAnd, object, object, _operate_and) + +// XOR + +// nil +OP_EVALUATOR(OperatorEvaluatorNilXBoolXor, nil, bool, _operate_xor) +OP_EVALUATOR(OperatorEvaluatorBoolXNilXor, bool, nil, _operate_xor) + +OP_EVALUATOR(OperatorEvaluatorNilXIntXor, nil, int, _operate_xor) +OP_EVALUATOR(OperatorEvaluatorIntXNilXor, int, nil, _operate_xor) + +OP_EVALUATOR(OperatorEvaluatorNilXFloatXor, nil, float, _operate_xor) +OP_EVALUATOR(OperatorEvaluatorFloatXNilXor, float, nil, _operate_xor) + +OP_EVALUATOR(OperatorEvaluatorObjectXNilXor, object, nil, _operate_xor) +OP_EVALUATOR(OperatorEvaluatorNilXObjectXor, nil, object, _operate_xor) + +// bool +OP_EVALUATOR(OperatorEvaluatorBoolXBoolXor, bool, bool, _operate_xor) + +OP_EVALUATOR(OperatorEvaluatorBoolXIntXor, bool, int, _operate_xor) +OP_EVALUATOR(OperatorEvaluatorIntXBoolXor, int, bool, _operate_xor) + +OP_EVALUATOR(OperatorEvaluatorBoolXFloatXor, bool, float, _operate_xor) +OP_EVALUATOR(OperatorEvaluatorFloatXBoolXor, float, bool, _operate_xor) + +OP_EVALUATOR(OperatorEvaluatorBoolXObjectXor, bool, object, _operate_xor) +OP_EVALUATOR(OperatorEvaluatorObjectXBoolXor, object, bool, _operate_xor) + +// int +OP_EVALUATOR(OperatorEvaluatorIntXIntXor, int, int, _operate_xor) + +OP_EVALUATOR(OperatorEvaluatorIntXFloatXor, int, float, _operate_xor) +OP_EVALUATOR(OperatorEvaluatorFloatXIntXor, float, int, _operate_xor) + +OP_EVALUATOR(OperatorEvaluatorIntXObjectXor, int, object, _operate_xor) +OP_EVALUATOR(OperatorEvaluatorObjectXIntXor, object, int, _operate_xor) + +// float +OP_EVALUATOR(OperatorEvaluatorFloatXFloatXor, float, float, _operate_xor) + +OP_EVALUATOR(OperatorEvaluatorFloatXObjectXor, float, object, _operate_xor) +OP_EVALUATOR(OperatorEvaluatorObjectXFloatXor, object, float, _operate_xor) + +// object +OP_EVALUATOR(OperatorEvaluatorObjectXObjectXor, object, object, _operate_xor) + +class OperatorEvaluatorNotBool { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + *r_ret = !*VariantGetInternalPtr<bool>::get_ptr(&p_left); + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + *VariantGetInternalPtr<bool>::get_ptr(r_ret) = !*VariantGetInternalPtr<bool>::get_ptr(left); + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<bool>::encode(!PtrToArg<bool>::convert(left), r_ret); + } + static Variant::Type get_return_type() { return Variant::BOOL; } +}; + +class OperatorEvaluatorNotInt { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + *r_ret = !*VariantGetInternalPtr<int64_t>::get_ptr(&p_left); + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + *VariantGetInternalPtr<bool>::get_ptr(r_ret) = !*VariantGetInternalPtr<int64_t>::get_ptr(left); + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<bool>::encode(!PtrToArg<int64_t>::convert(left), r_ret); + } + static Variant::Type get_return_type() { return Variant::BOOL; } +}; + +class OperatorEvaluatorNotFloat { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + *r_ret = !*VariantGetInternalPtr<double>::get_ptr(&p_left); + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + *VariantGetInternalPtr<bool>::get_ptr(r_ret) = !*VariantGetInternalPtr<double>::get_ptr(left); + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<bool>::encode(!PtrToArg<double>::convert(left), r_ret); + } + static Variant::Type get_return_type() { return Variant::BOOL; } +}; + +class OperatorEvaluatorNotObject { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + *r_ret = p_left.get_validated_object() == nullptr; + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + *VariantGetInternalPtr<bool>::get_ptr(r_ret) = left->get_validated_object() == nullptr; + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<bool>::encode(PtrToArg<Object *>::convert(left) == nullptr, r_ret); + } + static Variant::Type get_return_type() { return Variant::BOOL; } +}; + +//// + +class OperatorEvaluatorInStringFind { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + const String &str_a = *VariantGetInternalPtr<String>::get_ptr(&p_left); + const String &str_b = *VariantGetInternalPtr<String>::get_ptr(&p_right); + + *r_ret = str_b.find(str_a) != -1; + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + const String &str_a = *VariantGetInternalPtr<String>::get_ptr(left); + const String &str_b = *VariantGetInternalPtr<String>::get_ptr(right); + *VariantGetInternalPtr<bool>::get_ptr(r_ret) = str_b.find(str_a) != -1; + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<bool>::encode(PtrToArg<String>::convert(right).find(PtrToArg<String>::convert(left)) != -1, r_ret); + } + static Variant::Type get_return_type() { return Variant::BOOL; } +}; + +template <class A, class B> +class OperatorEvaluatorInArrayFind { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); + const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); + + *r_ret = b.find(a) != -1; + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + const A &a = *VariantGetInternalPtr<A>::get_ptr(left); + const B &b = *VariantGetInternalPtr<B>::get_ptr(right); + *VariantGetInternalPtr<bool>::get_ptr(r_ret) = b.find(a) != -1; + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<bool>::encode(PtrToArg<B>::convert(right).find(PtrToArg<A>::convert(left)) != -1, r_ret); + } + static Variant::Type get_return_type() { return Variant::BOOL; } +}; + +class OperatorEvaluatorInArrayFindNil { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + const Array &b = *VariantGetInternalPtr<Array>::get_ptr(&p_right); + *r_ret = b.find(Variant()) != -1; + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + const Array &b = *VariantGetInternalPtr<Array>::get_ptr(right); + *VariantGetInternalPtr<bool>::get_ptr(r_ret) = b.find(Variant()) != -1; + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<bool>::encode(PtrToArg<Array>::convert(right).find(Variant()) != -1, r_ret); + } + static Variant::Type get_return_type() { return Variant::BOOL; } +}; + +class OperatorEvaluatorInArrayFindObject { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + const Array &b = *VariantGetInternalPtr<Array>::get_ptr(&p_right); + *r_ret = b.find(p_left) != -1; + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + const Array &b = *VariantGetInternalPtr<Array>::get_ptr(right); + *VariantGetInternalPtr<bool>::get_ptr(r_ret) = b.find(*left) != -1; + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<bool>::encode(PtrToArg<Array>::convert(right).find(PtrToArg<Object *>::convert(left)) != -1, r_ret); + } + static Variant::Type get_return_type() { return Variant::BOOL; } +}; + +template <class A> +class OperatorEvaluatorInDictionaryHas { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + const Dictionary &b = *VariantGetInternalPtr<Dictionary>::get_ptr(&p_right); + const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); + + *r_ret = b.has(a); + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + const Dictionary &b = *VariantGetInternalPtr<Dictionary>::get_ptr(right); + const A &a = *VariantGetInternalPtr<A>::get_ptr(left); + *VariantGetInternalPtr<bool>::get_ptr(r_ret) = b.has(a); + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<bool>::encode(PtrToArg<Dictionary>::convert(right).has(PtrToArg<A>::convert(left)), r_ret); + } + static Variant::Type get_return_type() { return Variant::BOOL; } +}; + +class OperatorEvaluatorInDictionaryHasNil { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + const Dictionary &b = *VariantGetInternalPtr<Dictionary>::get_ptr(&p_right); + + *r_ret = b.has(Variant()); + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + const Dictionary &b = *VariantGetInternalPtr<Dictionary>::get_ptr(right); + *VariantGetInternalPtr<bool>::get_ptr(r_ret) = b.has(Variant()); + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<bool>::encode(PtrToArg<Dictionary>::convert(right).has(Variant()), r_ret); + } + static Variant::Type get_return_type() { return Variant::BOOL; } +}; + +class OperatorEvaluatorInDictionaryHasObject { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + const Dictionary &b = *VariantGetInternalPtr<Dictionary>::get_ptr(&p_right); + + *r_ret = b.has(p_left); + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + const Dictionary &b = *VariantGetInternalPtr<Dictionary>::get_ptr(right); + *VariantGetInternalPtr<bool>::get_ptr(r_ret) = b.has(*left); + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + PtrToArg<bool>::encode(PtrToArg<Dictionary>::convert(right).has(PtrToArg<Object *>::convert(left)), r_ret); + } + static Variant::Type get_return_type() { return Variant::BOOL; } +}; + +class OperatorEvaluatorObjectHasPropertyString { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + Object *b = p_right.get_validated_object(); + if (!b) { + *r_ret = "Invalid base object for 'in'"; + r_valid = false; + return; + } + + const String &a = *VariantGetInternalPtr<String>::get_ptr(&p_left); + + b->get(a, &r_valid); + *r_ret = r_valid; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + Object *l = right->get_validated_object(); + ERR_FAIL_COND(l == nullptr); + const String &a = *VariantGetInternalPtr<String>::get_ptr(left); + + bool valid; + l->get(a, &valid); + *VariantGetInternalPtr<bool>::get_ptr(r_ret) = valid; + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + bool valid; + PtrToArg<Object *>::convert(right)->get(PtrToArg<String>::convert(left), &valid); + PtrToArg<bool>::encode(valid, r_ret); + } + static Variant::Type get_return_type() { return Variant::BOOL; } +}; + +class OperatorEvaluatorObjectHasPropertyStringName { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + Object *b = p_right.get_validated_object(); + if (!b) { + *r_ret = "Invalid base object for 'in'"; + r_valid = false; + return; + } + + const StringName &a = *VariantGetInternalPtr<StringName>::get_ptr(&p_left); + + b->get(a, &r_valid); + *r_ret = r_valid; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + Object *l = right->get_validated_object(); + ERR_FAIL_COND(l == nullptr); + const StringName &a = *VariantGetInternalPtr<StringName>::get_ptr(left); + + bool valid; + l->get(a, &valid); + *VariantGetInternalPtr<bool>::get_ptr(r_ret) = valid; + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + bool valid; + PtrToArg<Object *>::convert(right)->get(PtrToArg<StringName>::convert(left), &valid); + PtrToArg<bool>::encode(valid, r_ret); + } + static Variant::Type get_return_type() { return Variant::BOOL; } +}; + +#endif // VARIANT_OP_H diff --git a/core/variant/variant_parser.cpp b/core/variant/variant_parser.cpp index 28930a19e2..86d5ae7f38 100644 --- a/core/variant/variant_parser.cpp +++ b/core/variant/variant_parser.cpp @@ -738,10 +738,10 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, String type = token.value; - Object *obj = ClassDB::instance(type); + Object *obj = ClassDB::instantiate(type); if (!obj) { - r_err_str = "Can't instance Object() of type: " + type; + r_err_str = "Can't instantiate Object() of type: " + type; return ERR_PARSE_ERROR; } @@ -1204,16 +1204,32 @@ Error VariantParser::_parse_tag(Token &token, Stream *p_stream, int &line, Strin r_tag.name = ""; r_tag.fields.clear(); - while (true) { - char32_t c = p_stream->get_char(); - if (p_stream->is_eof()) { - r_err_str = "Unexpected EOF while parsing simple tag"; - return ERR_PARSE_ERROR; + if (p_stream->is_utf8()) { + CharString cs; + while (true) { + char c = p_stream->get_char(); + if (p_stream->is_eof()) { + r_err_str = "Unexpected EOF while parsing simple tag"; + return ERR_PARSE_ERROR; + } + if (c == ']') { + break; + } + cs += c; } - if (c == ']') { - break; + r_tag.name.parse_utf8(cs.get_data(), cs.length()); + } else { + while (true) { + char32_t c = p_stream->get_char(); + if (p_stream->is_eof()) { + r_err_str = "Unexpected EOF while parsing simple tag"; + return ERR_PARSE_ERROR; + } + if (c == ']') { + break; + } + r_tag.name += String::chr(c); } - r_tag.name += String::chr(c); } r_tag.name = r_tag.name.strip_edges(); diff --git a/core/variant/variant_setget.cpp b/core/variant/variant_setget.cpp index ae2795f2fd..de1deace63 100644 --- a/core/variant/variant_setget.cpp +++ b/core/variant/variant_setget.cpp @@ -28,282 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "variant.h" - -#include "core/core_string_names.h" -#include "core/debugger/engine_debugger.h" -#include "core/object/class_db.h" -#include "core/templates/local_vector.h" -#include "core/variant/variant_internal.h" - -/**** NAMED SETTERS AND GETTERS ****/ - -#define SETGET_STRUCT(m_base_type, m_member_type, m_member) \ - struct VariantSetGet_##m_base_type##_##m_member { \ - static void get(const Variant *base, Variant *member) { \ - VariantTypeAdjust<m_member_type>::adjust(member); \ - *VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_member; \ - } \ - static void ptr_get(const void *base, void *member) { \ - PtrToArg<m_member_type>::encode(PtrToArg<m_base_type>::convert(base).m_member, member); \ - } \ - static void set(Variant *base, const Variant *value, bool &valid) { \ - if (value->get_type() == GetTypeInfo<m_member_type>::VARIANT_TYPE) { \ - VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_member = *VariantGetInternalPtr<m_member_type>::get_ptr(value); \ - valid = true; \ - } else { \ - valid = false; \ - } \ - } \ - static void validated_set(Variant *base, const Variant *value) { \ - VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_member = *VariantGetInternalPtr<m_member_type>::get_ptr(value); \ - } \ - static void ptr_set(void *base, const void *member) { \ - m_base_type b = PtrToArg<m_base_type>::convert(base); \ - b.m_member = PtrToArg<m_member_type>::convert(member); \ - PtrToArg<m_base_type>::encode(b, base); \ - } \ - static Variant::Type get_type() { return GetTypeInfo<m_member_type>::VARIANT_TYPE; } \ - }; - -#define SETGET_NUMBER_STRUCT(m_base_type, m_member_type, m_member) \ - struct VariantSetGet_##m_base_type##_##m_member { \ - static void get(const Variant *base, Variant *member) { \ - VariantTypeAdjust<m_member_type>::adjust(member); \ - *VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_member; \ - } \ - static void ptr_get(const void *base, void *member) { \ - PtrToArg<m_member_type>::encode(PtrToArg<m_base_type>::convert(base).m_member, member); \ - } \ - static void set(Variant *base, const Variant *value, bool &valid) { \ - if (value->get_type() == Variant::FLOAT) { \ - VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_member = *VariantGetInternalPtr<double>::get_ptr(value); \ - valid = true; \ - } else if (value->get_type() == Variant::INT) { \ - VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_member = *VariantGetInternalPtr<int64_t>::get_ptr(value); \ - valid = true; \ - } else { \ - valid = false; \ - } \ - } \ - static void validated_set(Variant *base, const Variant *value) { \ - VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_member = *VariantGetInternalPtr<m_member_type>::get_ptr(value); \ - } \ - static void ptr_set(void *base, const void *member) { \ - m_base_type b = PtrToArg<m_base_type>::convert(base); \ - b.m_member = PtrToArg<m_member_type>::convert(member); \ - PtrToArg<m_base_type>::encode(b, base); \ - } \ - static Variant::Type get_type() { return GetTypeInfo<m_member_type>::VARIANT_TYPE; } \ - }; - -#define SETGET_STRUCT_CUSTOM(m_base_type, m_member_type, m_member, m_custom) \ - struct VariantSetGet_##m_base_type##_##m_member { \ - static void get(const Variant *base, Variant *member) { \ - VariantTypeAdjust<m_member_type>::adjust(member); \ - *VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_custom; \ - } \ - static void ptr_get(const void *base, void *member) { \ - PtrToArg<m_member_type>::encode(PtrToArg<m_base_type>::convert(base).m_custom, member); \ - } \ - static void set(Variant *base, const Variant *value, bool &valid) { \ - if (value->get_type() == GetTypeInfo<m_member_type>::VARIANT_TYPE) { \ - VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_custom = *VariantGetInternalPtr<m_member_type>::get_ptr(value); \ - valid = true; \ - } else { \ - valid = false; \ - } \ - } \ - static void validated_set(Variant *base, const Variant *value) { \ - VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_custom = *VariantGetInternalPtr<m_member_type>::get_ptr(value); \ - } \ - static void ptr_set(void *base, const void *member) { \ - m_base_type b = PtrToArg<m_base_type>::convert(base); \ - b.m_custom = PtrToArg<m_member_type>::convert(member); \ - PtrToArg<m_base_type>::encode(b, base); \ - } \ - static Variant::Type get_type() { return GetTypeInfo<m_member_type>::VARIANT_TYPE; } \ - }; - -#define SETGET_NUMBER_STRUCT_CUSTOM(m_base_type, m_member_type, m_member, m_custom) \ - struct VariantSetGet_##m_base_type##_##m_member { \ - static void get(const Variant *base, Variant *member) { \ - VariantTypeAdjust<m_member_type>::adjust(member); \ - *VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_custom; \ - } \ - static void ptr_get(const void *base, void *member) { \ - PtrToArg<m_member_type>::encode(PtrToArg<m_base_type>::convert(base).m_custom, member); \ - } \ - static void set(Variant *base, const Variant *value, bool &valid) { \ - if (value->get_type() == Variant::FLOAT) { \ - VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_custom = *VariantGetInternalPtr<double>::get_ptr(value); \ - valid = true; \ - } else if (value->get_type() == Variant::INT) { \ - VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_custom = *VariantGetInternalPtr<int64_t>::get_ptr(value); \ - valid = true; \ - } else { \ - valid = false; \ - } \ - } \ - static void validated_set(Variant *base, const Variant *value) { \ - VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_custom = *VariantGetInternalPtr<m_member_type>::get_ptr(value); \ - } \ - static void ptr_set(void *base, const void *member) { \ - m_base_type b = PtrToArg<m_base_type>::convert(base); \ - b.m_custom = PtrToArg<m_member_type>::convert(member); \ - PtrToArg<m_base_type>::encode(b, base); \ - } \ - static Variant::Type get_type() { return GetTypeInfo<m_member_type>::VARIANT_TYPE; } \ - }; - -#define SETGET_STRUCT_FUNC(m_base_type, m_member_type, m_member, m_setter, m_getter) \ - struct VariantSetGet_##m_base_type##_##m_member { \ - static void get(const Variant *base, Variant *member) { \ - VariantTypeAdjust<m_member_type>::adjust(member); \ - *VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_getter(); \ - } \ - static void ptr_get(const void *base, void *member) { \ - PtrToArg<m_member_type>::encode(PtrToArg<m_base_type>::convert(base).m_getter(), member); \ - } \ - static void set(Variant *base, const Variant *value, bool &valid) { \ - if (value->get_type() == GetTypeInfo<m_member_type>::VARIANT_TYPE) { \ - VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_setter(*VariantGetInternalPtr<m_member_type>::get_ptr(value)); \ - valid = true; \ - } else { \ - valid = false; \ - } \ - } \ - static void validated_set(Variant *base, const Variant *value) { \ - VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_setter(*VariantGetInternalPtr<m_member_type>::get_ptr(value)); \ - } \ - static void ptr_set(void *base, const void *member) { \ - m_base_type b = PtrToArg<m_base_type>::convert(base); \ - b.m_setter(PtrToArg<m_member_type>::convert(member)); \ - PtrToArg<m_base_type>::encode(b, base); \ - } \ - static Variant::Type get_type() { return GetTypeInfo<m_member_type>::VARIANT_TYPE; } \ - }; - -#define SETGET_NUMBER_STRUCT_FUNC(m_base_type, m_member_type, m_member, m_setter, m_getter) \ - struct VariantSetGet_##m_base_type##_##m_member { \ - static void get(const Variant *base, Variant *member) { \ - VariantTypeAdjust<m_member_type>::adjust(member); \ - *VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_getter(); \ - } \ - static void ptr_get(const void *base, void *member) { \ - PtrToArg<m_member_type>::encode(PtrToArg<m_base_type>::convert(base).m_getter(), member); \ - } \ - static void set(Variant *base, const Variant *value, bool &valid) { \ - if (value->get_type() == Variant::FLOAT) { \ - VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_setter(*VariantGetInternalPtr<double>::get_ptr(value)); \ - valid = true; \ - } else if (value->get_type() == Variant::INT) { \ - VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_setter(*VariantGetInternalPtr<int64_t>::get_ptr(value)); \ - valid = true; \ - } else { \ - valid = false; \ - } \ - } \ - static void validated_set(Variant *base, const Variant *value) { \ - VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_setter(*VariantGetInternalPtr<m_member_type>::get_ptr(value)); \ - } \ - static void ptr_set(void *base, const void *member) { \ - m_base_type b = PtrToArg<m_base_type>::convert(base); \ - b.m_setter(PtrToArg<m_member_type>::convert(member)); \ - PtrToArg<m_base_type>::encode(b, base); \ - } \ - static Variant::Type get_type() { return GetTypeInfo<m_member_type>::VARIANT_TYPE; } \ - }; - -#define SETGET_STRUCT_FUNC_INDEX(m_base_type, m_member_type, m_member, m_setter, m_getter, m_index) \ - struct VariantSetGet_##m_base_type##_##m_member { \ - static void get(const Variant *base, Variant *member) { \ - VariantTypeAdjust<m_member_type>::adjust(member); \ - *VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_getter(m_index); \ - } \ - static void ptr_get(const void *base, void *member) { \ - PtrToArg<m_member_type>::encode(PtrToArg<m_base_type>::convert(base).m_getter(m_index), member); \ - } \ - static void set(Variant *base, const Variant *value, bool &valid) { \ - if (value->get_type() == GetTypeInfo<m_member_type>::VARIANT_TYPE) { \ - VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_setter(m_index, *VariantGetInternalPtr<m_member_type>::get_ptr(value)); \ - valid = true; \ - } else { \ - valid = false; \ - } \ - } \ - static void validated_set(Variant *base, const Variant *value) { \ - VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_setter(m_index, *VariantGetInternalPtr<m_member_type>::get_ptr(value)); \ - } \ - static void ptr_set(void *base, const void *member) { \ - m_base_type b = PtrToArg<m_base_type>::convert(base); \ - b.m_setter(m_index, PtrToArg<m_member_type>::convert(member)); \ - PtrToArg<m_base_type>::encode(b, base); \ - } \ - static Variant::Type get_type() { return GetTypeInfo<m_member_type>::VARIANT_TYPE; } \ - }; - -SETGET_NUMBER_STRUCT(Vector2, double, x) -SETGET_NUMBER_STRUCT(Vector2, double, y) - -SETGET_NUMBER_STRUCT(Vector2i, int64_t, x) -SETGET_NUMBER_STRUCT(Vector2i, int64_t, y) - -SETGET_NUMBER_STRUCT(Vector3, double, x) -SETGET_NUMBER_STRUCT(Vector3, double, y) -SETGET_NUMBER_STRUCT(Vector3, double, z) - -SETGET_NUMBER_STRUCT(Vector3i, int64_t, x) -SETGET_NUMBER_STRUCT(Vector3i, int64_t, y) -SETGET_NUMBER_STRUCT(Vector3i, int64_t, z) - -SETGET_STRUCT(Rect2, Vector2, position) -SETGET_STRUCT(Rect2, Vector2, size) -SETGET_STRUCT_FUNC(Rect2, Vector2, end, set_end, get_end) - -SETGET_STRUCT(Rect2i, Vector2i, position) -SETGET_STRUCT(Rect2i, Vector2i, size) -SETGET_STRUCT_FUNC(Rect2i, Vector2i, end, set_end, get_end) - -SETGET_STRUCT(AABB, Vector3, position) -SETGET_STRUCT(AABB, Vector3, size) -SETGET_STRUCT_FUNC(AABB, Vector3, end, set_end, get_end) - -SETGET_STRUCT_CUSTOM(Transform2D, Vector2, x, elements[0]) -SETGET_STRUCT_CUSTOM(Transform2D, Vector2, y, elements[1]) -SETGET_STRUCT_CUSTOM(Transform2D, Vector2, origin, elements[2]) - -SETGET_NUMBER_STRUCT_CUSTOM(Plane, double, x, normal.x) -SETGET_NUMBER_STRUCT_CUSTOM(Plane, double, y, normal.y) -SETGET_NUMBER_STRUCT_CUSTOM(Plane, double, z, normal.z) -SETGET_STRUCT(Plane, Vector3, normal) -SETGET_NUMBER_STRUCT(Plane, double, d) - -SETGET_NUMBER_STRUCT(Quaternion, double, x) -SETGET_NUMBER_STRUCT(Quaternion, double, y) -SETGET_NUMBER_STRUCT(Quaternion, double, z) -SETGET_NUMBER_STRUCT(Quaternion, double, w) - -SETGET_STRUCT_FUNC_INDEX(Basis, Vector3, x, set_axis, get_axis, 0) -SETGET_STRUCT_FUNC_INDEX(Basis, Vector3, y, set_axis, get_axis, 1) -SETGET_STRUCT_FUNC_INDEX(Basis, Vector3, z, set_axis, get_axis, 2) - -SETGET_STRUCT(Transform3D, Basis, basis) -SETGET_STRUCT(Transform3D, Vector3, origin) - -SETGET_NUMBER_STRUCT(Color, double, r) -SETGET_NUMBER_STRUCT(Color, double, g) -SETGET_NUMBER_STRUCT(Color, double, b) -SETGET_NUMBER_STRUCT(Color, double, a) - -SETGET_NUMBER_STRUCT_FUNC(Color, int64_t, r8, set_r8, get_r8) -SETGET_NUMBER_STRUCT_FUNC(Color, int64_t, g8, set_g8, get_g8) -SETGET_NUMBER_STRUCT_FUNC(Color, int64_t, b8, set_b8, get_b8) -SETGET_NUMBER_STRUCT_FUNC(Color, int64_t, a8, set_a8, get_a8) - -SETGET_NUMBER_STRUCT_FUNC(Color, double, h, set_h, get_h) -SETGET_NUMBER_STRUCT_FUNC(Color, double, s, set_s, get_s) -SETGET_NUMBER_STRUCT_FUNC(Color, double, v, set_v, get_v) +#include "variant_setget.h" struct VariantSetterGetterInfo { void (*setter)(Variant *base, const Variant *value, bool &valid); @@ -326,7 +51,7 @@ static void register_member(Variant::Type p_type, const StringName &p_member) { sgi.ptr_setter = T::ptr_set; sgi.getter = T::get; - sgi.validated_getter = T::get; + sgi.validated_getter = T::validated_get; sgi.ptr_getter = T::ptr_get; sgi.member_type = T::get_type(); @@ -1146,7 +871,7 @@ struct VariantKeyedSetGetDictionary { *r_valid = true; return VariantGetInternalPtr<Dictionary>::get_ptr(base)->has(*key); } - static bool ptr_has(const void *base, const void *key) { + static uint32_t ptr_has(const void *base, const void *key) { /* avoid ptrconvert for performance*/ const Dictionary &v = *reinterpret_cast<const Dictionary *>(base); return v.has(PtrToArg<Variant>::convert(key)); @@ -1196,7 +921,7 @@ struct VariantKeyedSetGetObject { obj->getvar(*key, &exists); return exists; } - static bool ptr_has(const void *base, const void *key) { + static uint32_t ptr_has(const void *base, const void *key) { const Object *obj = PtrToArg<Object *>::convert(base); ERR_FAIL_COND_V(!obj, false); bool valid; diff --git a/core/variant/variant_setget.h b/core/variant/variant_setget.h new file mode 100644 index 0000000000..dbf24ab3e3 --- /dev/null +++ b/core/variant/variant_setget.h @@ -0,0 +1,332 @@ +/*************************************************************************/ +/* variant_setget.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef VARIANT_SETGET_H +#define VARIANT_SETGET_H + +#include "variant.h" + +#include "core/core_string_names.h" +#include "core/debugger/engine_debugger.h" +#include "core/object/class_db.h" +#include "core/templates/local_vector.h" +#include "core/variant/variant_internal.h" + +/**** NAMED SETTERS AND GETTERS ****/ + +#define SETGET_STRUCT(m_base_type, m_member_type, m_member) \ + struct VariantSetGet_##m_base_type##_##m_member { \ + static void get(const Variant *base, Variant *member) { \ + VariantTypeAdjust<m_member_type>::adjust(member); \ + *VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_member; \ + } \ + static inline void validated_get(const Variant *base, Variant *member) { \ + *VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_member; \ + } \ + static void ptr_get(const void *base, void *member) { \ + PtrToArg<m_member_type>::encode(PtrToArg<m_base_type>::convert(base).m_member, member); \ + } \ + static void set(Variant *base, const Variant *value, bool &valid) { \ + if (value->get_type() == GetTypeInfo<m_member_type>::VARIANT_TYPE) { \ + VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_member = *VariantGetInternalPtr<m_member_type>::get_ptr(value); \ + valid = true; \ + } else { \ + valid = false; \ + } \ + } \ + static inline void validated_set(Variant *base, const Variant *value) { \ + VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_member = *VariantGetInternalPtr<m_member_type>::get_ptr(value); \ + } \ + static void ptr_set(void *base, const void *member) { \ + m_base_type b = PtrToArg<m_base_type>::convert(base); \ + b.m_member = PtrToArg<m_member_type>::convert(member); \ + PtrToArg<m_base_type>::encode(b, base); \ + } \ + static Variant::Type get_type() { return GetTypeInfo<m_member_type>::VARIANT_TYPE; } \ + }; + +#define SETGET_NUMBER_STRUCT(m_base_type, m_member_type, m_member) \ + struct VariantSetGet_##m_base_type##_##m_member { \ + static void get(const Variant *base, Variant *member) { \ + VariantTypeAdjust<m_member_type>::adjust(member); \ + *VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_member; \ + } \ + static inline void validated_get(const Variant *base, Variant *member) { \ + *VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_member; \ + } \ + static void ptr_get(const void *base, void *member) { \ + PtrToArg<m_member_type>::encode(PtrToArg<m_base_type>::convert(base).m_member, member); \ + } \ + static void set(Variant *base, const Variant *value, bool &valid) { \ + if (value->get_type() == Variant::FLOAT) { \ + VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_member = *VariantGetInternalPtr<double>::get_ptr(value); \ + valid = true; \ + } else if (value->get_type() == Variant::INT) { \ + VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_member = *VariantGetInternalPtr<int64_t>::get_ptr(value); \ + valid = true; \ + } else { \ + valid = false; \ + } \ + } \ + static inline void validated_set(Variant *base, const Variant *value) { \ + VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_member = *VariantGetInternalPtr<m_member_type>::get_ptr(value); \ + } \ + static void ptr_set(void *base, const void *member) { \ + m_base_type b = PtrToArg<m_base_type>::convert(base); \ + b.m_member = PtrToArg<m_member_type>::convert(member); \ + PtrToArg<m_base_type>::encode(b, base); \ + } \ + static Variant::Type get_type() { return GetTypeInfo<m_member_type>::VARIANT_TYPE; } \ + }; + +#define SETGET_STRUCT_CUSTOM(m_base_type, m_member_type, m_member, m_custom) \ + struct VariantSetGet_##m_base_type##_##m_member { \ + static void get(const Variant *base, Variant *member) { \ + VariantTypeAdjust<m_member_type>::adjust(member); \ + *VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_custom; \ + } \ + static inline void validated_get(const Variant *base, Variant *member) { \ + *VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_custom; \ + } \ + static void ptr_get(const void *base, void *member) { \ + PtrToArg<m_member_type>::encode(PtrToArg<m_base_type>::convert(base).m_custom, member); \ + } \ + static void set(Variant *base, const Variant *value, bool &valid) { \ + if (value->get_type() == GetTypeInfo<m_member_type>::VARIANT_TYPE) { \ + VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_custom = *VariantGetInternalPtr<m_member_type>::get_ptr(value); \ + valid = true; \ + } else { \ + valid = false; \ + } \ + } \ + static inline void validated_set(Variant *base, const Variant *value) { \ + VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_custom = *VariantGetInternalPtr<m_member_type>::get_ptr(value); \ + } \ + static void ptr_set(void *base, const void *member) { \ + m_base_type b = PtrToArg<m_base_type>::convert(base); \ + b.m_custom = PtrToArg<m_member_type>::convert(member); \ + PtrToArg<m_base_type>::encode(b, base); \ + } \ + static Variant::Type get_type() { return GetTypeInfo<m_member_type>::VARIANT_TYPE; } \ + }; + +#define SETGET_NUMBER_STRUCT_CUSTOM(m_base_type, m_member_type, m_member, m_custom) \ + struct VariantSetGet_##m_base_type##_##m_member { \ + static void get(const Variant *base, Variant *member) { \ + VariantTypeAdjust<m_member_type>::adjust(member); \ + *VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_custom; \ + } \ + static inline void validated_get(const Variant *base, Variant *member) { \ + *VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_custom; \ + } \ + static void ptr_get(const void *base, void *member) { \ + PtrToArg<m_member_type>::encode(PtrToArg<m_base_type>::convert(base).m_custom, member); \ + } \ + static void set(Variant *base, const Variant *value, bool &valid) { \ + if (value->get_type() == Variant::FLOAT) { \ + VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_custom = *VariantGetInternalPtr<double>::get_ptr(value); \ + valid = true; \ + } else if (value->get_type() == Variant::INT) { \ + VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_custom = *VariantGetInternalPtr<int64_t>::get_ptr(value); \ + valid = true; \ + } else { \ + valid = false; \ + } \ + } \ + static inline void validated_set(Variant *base, const Variant *value) { \ + VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_custom = *VariantGetInternalPtr<m_member_type>::get_ptr(value); \ + } \ + static void ptr_set(void *base, const void *member) { \ + m_base_type b = PtrToArg<m_base_type>::convert(base); \ + b.m_custom = PtrToArg<m_member_type>::convert(member); \ + PtrToArg<m_base_type>::encode(b, base); \ + } \ + static Variant::Type get_type() { return GetTypeInfo<m_member_type>::VARIANT_TYPE; } \ + }; + +#define SETGET_STRUCT_FUNC(m_base_type, m_member_type, m_member, m_setter, m_getter) \ + struct VariantSetGet_##m_base_type##_##m_member { \ + static void get(const Variant *base, Variant *member) { \ + VariantTypeAdjust<m_member_type>::adjust(member); \ + *VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_getter(); \ + } \ + static inline void validated_get(const Variant *base, Variant *member) { \ + *VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_getter(); \ + } \ + static void ptr_get(const void *base, void *member) { \ + PtrToArg<m_member_type>::encode(PtrToArg<m_base_type>::convert(base).m_getter(), member); \ + } \ + static void set(Variant *base, const Variant *value, bool &valid) { \ + if (value->get_type() == GetTypeInfo<m_member_type>::VARIANT_TYPE) { \ + VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_setter(*VariantGetInternalPtr<m_member_type>::get_ptr(value)); \ + valid = true; \ + } else { \ + valid = false; \ + } \ + } \ + static inline void validated_set(Variant *base, const Variant *value) { \ + VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_setter(*VariantGetInternalPtr<m_member_type>::get_ptr(value)); \ + } \ + static void ptr_set(void *base, const void *member) { \ + m_base_type b = PtrToArg<m_base_type>::convert(base); \ + b.m_setter(PtrToArg<m_member_type>::convert(member)); \ + PtrToArg<m_base_type>::encode(b, base); \ + } \ + static Variant::Type get_type() { return GetTypeInfo<m_member_type>::VARIANT_TYPE; } \ + }; + +#define SETGET_NUMBER_STRUCT_FUNC(m_base_type, m_member_type, m_member, m_setter, m_getter) \ + struct VariantSetGet_##m_base_type##_##m_member { \ + static void get(const Variant *base, Variant *member) { \ + VariantTypeAdjust<m_member_type>::adjust(member); \ + *VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_getter(); \ + } \ + static inline void validated_get(const Variant *base, Variant *member) { \ + *VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_getter(); \ + } \ + static void ptr_get(const void *base, void *member) { \ + PtrToArg<m_member_type>::encode(PtrToArg<m_base_type>::convert(base).m_getter(), member); \ + } \ + static void set(Variant *base, const Variant *value, bool &valid) { \ + if (value->get_type() == Variant::FLOAT) { \ + VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_setter(*VariantGetInternalPtr<double>::get_ptr(value)); \ + valid = true; \ + } else if (value->get_type() == Variant::INT) { \ + VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_setter(*VariantGetInternalPtr<int64_t>::get_ptr(value)); \ + valid = true; \ + } else { \ + valid = false; \ + } \ + } \ + static inline void validated_set(Variant *base, const Variant *value) { \ + VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_setter(*VariantGetInternalPtr<m_member_type>::get_ptr(value)); \ + } \ + static void ptr_set(void *base, const void *member) { \ + m_base_type b = PtrToArg<m_base_type>::convert(base); \ + b.m_setter(PtrToArg<m_member_type>::convert(member)); \ + PtrToArg<m_base_type>::encode(b, base); \ + } \ + static Variant::Type get_type() { return GetTypeInfo<m_member_type>::VARIANT_TYPE; } \ + }; + +#define SETGET_STRUCT_FUNC_INDEX(m_base_type, m_member_type, m_member, m_setter, m_getter, m_index) \ + struct VariantSetGet_##m_base_type##_##m_member { \ + static void get(const Variant *base, Variant *member) { \ + VariantTypeAdjust<m_member_type>::adjust(member); \ + *VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_getter(m_index); \ + } \ + static inline void validated_get(const Variant *base, Variant *member) { \ + *VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_getter(m_index); \ + } \ + static void ptr_get(const void *base, void *member) { \ + PtrToArg<m_member_type>::encode(PtrToArg<m_base_type>::convert(base).m_getter(m_index), member); \ + } \ + static void set(Variant *base, const Variant *value, bool &valid) { \ + if (value->get_type() == GetTypeInfo<m_member_type>::VARIANT_TYPE) { \ + VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_setter(m_index, *VariantGetInternalPtr<m_member_type>::get_ptr(value)); \ + valid = true; \ + } else { \ + valid = false; \ + } \ + } \ + static inline void validated_set(Variant *base, const Variant *value) { \ + VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_setter(m_index, *VariantGetInternalPtr<m_member_type>::get_ptr(value)); \ + } \ + static void ptr_set(void *base, const void *member) { \ + m_base_type b = PtrToArg<m_base_type>::convert(base); \ + b.m_setter(m_index, PtrToArg<m_member_type>::convert(member)); \ + PtrToArg<m_base_type>::encode(b, base); \ + } \ + static Variant::Type get_type() { return GetTypeInfo<m_member_type>::VARIANT_TYPE; } \ + }; + +SETGET_NUMBER_STRUCT(Vector2, double, x) +SETGET_NUMBER_STRUCT(Vector2, double, y) + +SETGET_NUMBER_STRUCT(Vector2i, int64_t, x) +SETGET_NUMBER_STRUCT(Vector2i, int64_t, y) + +SETGET_NUMBER_STRUCT(Vector3, double, x) +SETGET_NUMBER_STRUCT(Vector3, double, y) +SETGET_NUMBER_STRUCT(Vector3, double, z) + +SETGET_NUMBER_STRUCT(Vector3i, int64_t, x) +SETGET_NUMBER_STRUCT(Vector3i, int64_t, y) +SETGET_NUMBER_STRUCT(Vector3i, int64_t, z) + +SETGET_STRUCT(Rect2, Vector2, position) +SETGET_STRUCT(Rect2, Vector2, size) +SETGET_STRUCT_FUNC(Rect2, Vector2, end, set_end, get_end) + +SETGET_STRUCT(Rect2i, Vector2i, position) +SETGET_STRUCT(Rect2i, Vector2i, size) +SETGET_STRUCT_FUNC(Rect2i, Vector2i, end, set_end, get_end) + +SETGET_STRUCT(AABB, Vector3, position) +SETGET_STRUCT(AABB, Vector3, size) +SETGET_STRUCT_FUNC(AABB, Vector3, end, set_end, get_end) + +SETGET_STRUCT_CUSTOM(Transform2D, Vector2, x, elements[0]) +SETGET_STRUCT_CUSTOM(Transform2D, Vector2, y, elements[1]) +SETGET_STRUCT_CUSTOM(Transform2D, Vector2, origin, elements[2]) + +SETGET_NUMBER_STRUCT_CUSTOM(Plane, double, x, normal.x) +SETGET_NUMBER_STRUCT_CUSTOM(Plane, double, y, normal.y) +SETGET_NUMBER_STRUCT_CUSTOM(Plane, double, z, normal.z) +SETGET_STRUCT(Plane, Vector3, normal) +SETGET_NUMBER_STRUCT(Plane, double, d) + +SETGET_NUMBER_STRUCT(Quaternion, double, x) +SETGET_NUMBER_STRUCT(Quaternion, double, y) +SETGET_NUMBER_STRUCT(Quaternion, double, z) +SETGET_NUMBER_STRUCT(Quaternion, double, w) + +SETGET_STRUCT_FUNC_INDEX(Basis, Vector3, x, set_axis, get_axis, 0) +SETGET_STRUCT_FUNC_INDEX(Basis, Vector3, y, set_axis, get_axis, 1) +SETGET_STRUCT_FUNC_INDEX(Basis, Vector3, z, set_axis, get_axis, 2) + +SETGET_STRUCT(Transform3D, Basis, basis) +SETGET_STRUCT(Transform3D, Vector3, origin) + +SETGET_NUMBER_STRUCT(Color, double, r) +SETGET_NUMBER_STRUCT(Color, double, g) +SETGET_NUMBER_STRUCT(Color, double, b) +SETGET_NUMBER_STRUCT(Color, double, a) + +SETGET_NUMBER_STRUCT_FUNC(Color, int64_t, r8, set_r8, get_r8) +SETGET_NUMBER_STRUCT_FUNC(Color, int64_t, g8, set_g8, get_g8) +SETGET_NUMBER_STRUCT_FUNC(Color, int64_t, b8, set_b8, get_b8) +SETGET_NUMBER_STRUCT_FUNC(Color, int64_t, a8, set_a8, get_a8) + +SETGET_NUMBER_STRUCT_FUNC(Color, double, h, set_h, get_h) +SETGET_NUMBER_STRUCT_FUNC(Color, double, s, set_s, get_s) +SETGET_NUMBER_STRUCT_FUNC(Color, double, v, set_v, get_v) + +#endif // VARIANT_SETGET_H diff --git a/core/variant/variant_utility.cpp b/core/variant/variant_utility.cpp index 5d1efb4166..1f69e81d99 100644 --- a/core/variant/variant_utility.cpp +++ b/core/variant/variant_utility.cpp @@ -1348,8 +1348,8 @@ String Variant::get_utility_function_argument_name(const StringName &p_name, int if (!bfi) { return String(); } - ERR_FAIL_COND_V(bfi->is_vararg, String()); ERR_FAIL_INDEX_V(p_arg, bfi->argnames.size(), String()); + ERR_FAIL_COND_V(bfi->is_vararg, String()); return bfi->argnames[p_arg]; } @@ -1379,6 +1379,23 @@ bool Variant::is_utility_function_vararg(const StringName &p_name) { return bfi->is_vararg; } +uint32_t Variant::get_utility_function_hash(const StringName &p_name) { + const VariantUtilityFunctionInfo *bfi = utility_function_table.lookup_ptr(p_name); + ERR_FAIL_COND_V(!bfi, 0); + + uint32_t hash = hash_djb2_one_32(bfi->is_vararg); + hash = hash_djb2_one_32(bfi->returns_value, hash); + if (bfi->returns_value) { + hash = hash_djb2_one_32(bfi->return_type, hash); + } + hash = hash_djb2_one_32(bfi->argcount, hash); + for (int i = 0; i < bfi->argcount; i++) { + hash = hash_djb2_one_32(bfi->get_arg_type(i), hash); + } + + return hash; +} + void Variant::get_utility_function_list(List<StringName> *r_functions) { for (List<StringName>::Element *E = utility_function_name_table.front(); E; E = E->next()) { r_functions->push_back(E->get()); diff --git a/doc/classes/@GlobalScope.xml b/doc/classes/@GlobalScope.xml index 552fc41318..66511f5845 100644 --- a/doc/classes/@GlobalScope.xml +++ b/doc/classes/@GlobalScope.xml @@ -778,7 +778,7 @@ <return type="float"> </return> <description> - Returns a random floating point value on the interval [code][0, 1][/code]. + Returns a random floating point value between [code]0.0[/code] and [code]1.0[/code] (inclusive). [codeblock] randf() # Returns e.g. 0.375671 [/codeblock] @@ -792,7 +792,7 @@ <argument index="1" name="to" type="float"> </argument> <description> - Random range, any floating point value between [code]from[/code] and [code]to[/code]. + Returns a random floating point value on the interval between [code]from[/code] and [code]to[/code] (inclusive). [codeblock] prints(randf_range(-10, 10), randf_range(-10, 10)) # Prints e.g. -3.844535 7.45315 [/codeblock] @@ -819,7 +819,7 @@ <argument index="1" name="to" type="int"> </argument> <description> - Random range, any 32-bit integer value between [code]from[/code] and [code]to[/code] (inclusive). If [code]to[/code] is lesser than [code]from[/code] they are swapped. + Returns a random signed 32-bit integer between [code]from[/code] and [code]to[/code] (inclusive). If [code]to[/code] is lesser than [code]from[/code], they are swapped. [codeblock] print(randi_range(0, 1)) # Prints 0 or 1 print(randi_range(-10, 1000)) # Prints any number from -10 to 1000 @@ -1066,11 +1066,13 @@ <description> Returns the internal type of the given Variant object, using the [enum Variant.Type] values. [codeblock] - p = parse_json('["a", "b", "c"]') - if typeof(p) == TYPE_ARRAY: - print(p[0]) # Prints a + var json = JSON.new() + json.parse('["a", "b", "c"]') + var result = json.get_data() + if typeof(result) == TYPE_ARRAY: + print(result[0]) # Prints a else: - print("unexpected results") + print("Unexpected result") [/codeblock] </description> </method> @@ -1211,9 +1213,6 @@ <member name="InputMap" type="InputMap" setter="" getter=""> The [InputMap] singleton. </member> - <member name="JSON" type="JSON" setter="" getter=""> - The [JSON] singleton. - </member> <member name="JavaClassWrapper" type="JavaClassWrapper" setter="" getter=""> The [JavaClassWrapper] singleton. [b]Note:[/b] Only implemented on Android. @@ -1225,6 +1224,8 @@ <member name="Marshalls" type="Marshalls" setter="" getter=""> The [Marshalls] singleton. </member> + <member name="NativeExtensionManager" type="NativeExtensionManager" setter="" getter=""> + </member> <member name="NavigationMeshGenerator" type="NavigationMeshGenerator" setter="" getter=""> The [NavigationMeshGenerator] singleton. </member> @@ -2409,74 +2410,72 @@ </constant> <constant name="PROPERTY_HINT_RANGE" value="1" enum="PropertyHint"> Hints that an integer or float property should be within a range specified via the hint string [code]"min,max"[/code] or [code]"min,max,step"[/code]. The hint string can optionally include [code]"or_greater"[/code] and/or [code]"or_lesser"[/code] to allow manual input going respectively above the max or below the min values. Example: [code]"-360,360,1,or_greater,or_lesser"[/code]. + Additionally, other keywords can be included: "exp" for exponential range editing, "radians" for editing radian angles in degrees, "degrees" to hint at an angle and "noslider" to hide the slider. </constant> - <constant name="PROPERTY_HINT_EXP_RANGE" value="2" enum="PropertyHint"> - Hints that an integer or float property should be within an exponential range specified via the hint string [code]"min,max"[/code] or [code]"min,max,step"[/code]. The hint string can optionally include [code]"or_greater"[/code] and/or [code]"or_lesser"[/code] to allow manual input going respectively above the max or below the min values. Example: [code]"0.01,100,0.01,or_greater"[/code]. - </constant> - <constant name="PROPERTY_HINT_ENUM" value="3" enum="PropertyHint"> + <constant name="PROPERTY_HINT_ENUM" value="2" enum="PropertyHint"> Hints that an integer, float or string property is an enumerated value to pick in a list specified via a hint string such as [code]"Hello,Something,Else"[/code]. </constant> - <constant name="PROPERTY_HINT_EXP_EASING" value="4" enum="PropertyHint"> + <constant name="PROPERTY_HINT_EXP_EASING" value="3" enum="PropertyHint"> Hints that a float property should be edited via an exponential easing function. The hint string can include [code]"attenuation"[/code] to flip the curve horizontally and/or [code]"inout"[/code] to also include in/out easing. </constant> - <constant name="PROPERTY_HINT_LENGTH" value="5" enum="PropertyHint"> + <constant name="PROPERTY_HINT_LENGTH" value="4" enum="PropertyHint"> Deprecated hint, unused. </constant> - <constant name="PROPERTY_HINT_KEY_ACCEL" value="6" enum="PropertyHint"> + <constant name="PROPERTY_HINT_KEY_ACCEL" value="5" enum="PropertyHint"> Deprecated hint, unused. </constant> - <constant name="PROPERTY_HINT_FLAGS" value="7" enum="PropertyHint"> + <constant name="PROPERTY_HINT_FLAGS" value="6" enum="PropertyHint"> Hints that an integer property is a bitmask with named bit flags. For example, to allow toggling bits 0, 1, 2 and 4, the hint could be something like [code]"Bit0,Bit1,Bit2,,Bit4"[/code]. </constant> - <constant name="PROPERTY_HINT_LAYERS_2D_RENDER" value="8" enum="PropertyHint"> + <constant name="PROPERTY_HINT_LAYERS_2D_RENDER" value="7" enum="PropertyHint"> Hints that an integer property is a bitmask using the optionally named 2D render layers. </constant> - <constant name="PROPERTY_HINT_LAYERS_2D_PHYSICS" value="9" enum="PropertyHint"> + <constant name="PROPERTY_HINT_LAYERS_2D_PHYSICS" value="8" enum="PropertyHint"> Hints that an integer property is a bitmask using the optionally named 2D physics layers. </constant> - <constant name="PROPERTY_HINT_LAYERS_2D_NAVIGATION" value="10" enum="PropertyHint"> + <constant name="PROPERTY_HINT_LAYERS_2D_NAVIGATION" value="9" enum="PropertyHint"> Hints that an integer property is a bitmask using the optionally named 2D navigation layers. </constant> - <constant name="PROPERTY_HINT_LAYERS_3D_RENDER" value="11" enum="PropertyHint"> + <constant name="PROPERTY_HINT_LAYERS_3D_RENDER" value="10" enum="PropertyHint"> Hints that an integer property is a bitmask using the optionally named 3D render layers. </constant> - <constant name="PROPERTY_HINT_LAYERS_3D_PHYSICS" value="12" enum="PropertyHint"> + <constant name="PROPERTY_HINT_LAYERS_3D_PHYSICS" value="11" enum="PropertyHint"> Hints that an integer property is a bitmask using the optionally named 3D physics layers. </constant> - <constant name="PROPERTY_HINT_LAYERS_3D_NAVIGATION" value="13" enum="PropertyHint"> + <constant name="PROPERTY_HINT_LAYERS_3D_NAVIGATION" value="12" enum="PropertyHint"> Hints that an integer property is a bitmask using the optionally named 2D navigation layers. </constant> - <constant name="PROPERTY_HINT_FILE" value="14" enum="PropertyHint"> + <constant name="PROPERTY_HINT_FILE" value="13" enum="PropertyHint"> Hints that a string property is a path to a file. Editing it will show a file dialog for picking the path. The hint string can be a set of filters with wildcards like [code]"*.png,*.jpg"[/code]. </constant> - <constant name="PROPERTY_HINT_DIR" value="15" enum="PropertyHint"> + <constant name="PROPERTY_HINT_DIR" value="14" enum="PropertyHint"> Hints that a string property is a path to a directory. Editing it will show a file dialog for picking the path. </constant> - <constant name="PROPERTY_HINT_GLOBAL_FILE" value="16" enum="PropertyHint"> + <constant name="PROPERTY_HINT_GLOBAL_FILE" value="15" enum="PropertyHint"> Hints that a string property is an absolute path to a file outside the project folder. Editing it will show a file dialog for picking the path. The hint string can be a set of filters with wildcards like [code]"*.png,*.jpg"[/code]. </constant> - <constant name="PROPERTY_HINT_GLOBAL_DIR" value="17" enum="PropertyHint"> + <constant name="PROPERTY_HINT_GLOBAL_DIR" value="16" enum="PropertyHint"> Hints that a string property is an absolute path to a directory outside the project folder. Editing it will show a file dialog for picking the path. </constant> - <constant name="PROPERTY_HINT_RESOURCE_TYPE" value="18" enum="PropertyHint"> + <constant name="PROPERTY_HINT_RESOURCE_TYPE" value="17" enum="PropertyHint"> Hints that a property is an instance of a [Resource]-derived type, optionally specified via the hint string (e.g. [code]"Texture2D"[/code]). Editing it will show a popup menu of valid resource types to instantiate. </constant> - <constant name="PROPERTY_HINT_MULTILINE_TEXT" value="19" enum="PropertyHint"> + <constant name="PROPERTY_HINT_MULTILINE_TEXT" value="18" enum="PropertyHint"> Hints that a string property is text with line breaks. Editing it will show a text input field where line breaks can be typed. </constant> - <constant name="PROPERTY_HINT_PLACEHOLDER_TEXT" value="20" enum="PropertyHint"> + <constant name="PROPERTY_HINT_PLACEHOLDER_TEXT" value="19" enum="PropertyHint"> Hints that a string property should have a placeholder text visible on its input field, whenever the property is empty. The hint string is the placeholder text to use. </constant> - <constant name="PROPERTY_HINT_COLOR_NO_ALPHA" value="21" enum="PropertyHint"> + <constant name="PROPERTY_HINT_COLOR_NO_ALPHA" value="20" enum="PropertyHint"> Hints that a color property should be edited without changing its alpha component, i.e. only R, G and B channels are edited. </constant> - <constant name="PROPERTY_HINT_IMAGE_COMPRESS_LOSSY" value="22" enum="PropertyHint"> + <constant name="PROPERTY_HINT_IMAGE_COMPRESS_LOSSY" value="21" enum="PropertyHint"> Hints that an image is compressed using lossy compression. </constant> - <constant name="PROPERTY_HINT_IMAGE_COMPRESS_LOSSLESS" value="23" enum="PropertyHint"> + <constant name="PROPERTY_HINT_IMAGE_COMPRESS_LOSSLESS" value="22" enum="PropertyHint"> Hints that an image is compressed using lossless compression. </constant> - <constant name="PROPERTY_HINT_TYPE_STRING" value="25" enum="PropertyHint"> + <constant name="PROPERTY_HINT_TYPE_STRING" value="24" enum="PropertyHint"> Hint that a property represents a particular type. If a property is [constant TYPE_STRING], allows to set a type from the create dialog. If you need to create an [Array] to contain elements of a specific type, the [code]hint_string[/code] must encode nested types using [code]":"[/code] and [code]"/"[/code] for specifying [Resource] types. For instance: [codeblock] hint_string = "%s:" % [TYPE_INT] # Array of inteters. diff --git a/doc/classes/AcceptDialog.xml b/doc/classes/AcceptDialog.xml index f644606040..fd1e2ba104 100644 --- a/doc/classes/AcceptDialog.xml +++ b/doc/classes/AcceptDialog.xml @@ -21,6 +21,7 @@ <description> Adds a button with label [code]text[/code] and a custom [code]action[/code] to the dialog and returns the created button. [code]action[/code] will be passed to the [signal custom_action] signal when pressed. If [code]true[/code], [code]right[/code] will place the button to the right of any sibling buttons. + You can use [method remove_button] method to remove a button created with this method from the dialog. </description> </method> <method name="add_cancel_button"> @@ -30,6 +31,7 @@ </argument> <description> Adds a button with label [code]name[/code] and a cancel action to the dialog and returns the created button. + You can use [method remove_button] method to remove a button created with this method from the dialog. </description> </method> <method name="get_label"> @@ -55,6 +57,15 @@ Registers a [LineEdit] in the dialog. When the enter key is pressed, the dialog will be accepted. </description> </method> + <method name="remove_button"> + <return type="void"> + </return> + <argument index="0" name="button" type="Control"> + </argument> + <description> + Removes the [code]button[/code] from the dialog. Does NOT free the [code]button[/code]. The [code]button[/code] must be a [Button] added with [method add_button] or [method add_cancel_button] method. After removal, pressing the [code]button[/code] will no longer emit this dialog's [signal custom_action] or [signal cancelled] signals. + </description> + </method> </methods> <members> <member name="dialog_autowrap" type="bool" setter="set_autowrap" getter="has_autowrap" default="false"> diff --git a/doc/classes/ArrayMesh.xml b/doc/classes/ArrayMesh.xml index 1bbf9bcd93..7fbf53c7d1 100644 --- a/doc/classes/ArrayMesh.xml +++ b/doc/classes/ArrayMesh.xml @@ -43,7 +43,7 @@ [/csharp] [/codeblocks] The [MeshInstance3D] is ready to be added to the [SceneTree] to be shown. - See also [ImmediateGeometry3D], [MeshDataTool] and [SurfaceTool] for procedural geometry generation. + See also [ImmediateMesh], [MeshDataTool] and [SurfaceTool] for procedural geometry generation. [b]Note:[/b] Godot uses clockwise [url=https://learnopengl.com/Advanced-OpenGL/Face-culling]winding order[/url] for front faces of triangle primitive modes. </description> <tutorials> @@ -202,7 +202,31 @@ Sets a name for a given surface. </description> </method> - <method name="surface_update_region"> + <method name="surface_update_attribute_region"> + <return type="void"> + </return> + <argument index="0" name="surf_idx" type="int"> + </argument> + <argument index="1" name="offset" type="int"> + </argument> + <argument index="2" name="data" type="PackedByteArray"> + </argument> + <description> + </description> + </method> + <method name="surface_update_skin_region"> + <return type="void"> + </return> + <argument index="0" name="surf_idx" type="int"> + </argument> + <argument index="1" name="offset" type="int"> + </argument> + <argument index="2" name="data" type="PackedByteArray"> + </argument> + <description> + </description> + </method> + <method name="surface_update_vertex_region"> <return type="void"> </return> <argument index="0" name="surf_idx" type="int"> @@ -212,8 +236,6 @@ <argument index="2" name="data" type="PackedByteArray"> </argument> <description> - Updates a specified region of mesh arrays on the GPU. - [b]Warning:[/b] Only use if you know what you are doing. You can easily cause crashes by calling this function with improper arguments. </description> </method> </methods> diff --git a/doc/classes/BaseMaterial3D.xml b/doc/classes/BaseMaterial3D.xml index abe06bc7e1..2a378ed03e 100644 --- a/doc/classes/BaseMaterial3D.xml +++ b/doc/classes/BaseMaterial3D.xml @@ -347,8 +347,6 @@ </member> <member name="subsurf_scatter_transmittance_color" type="Color" setter="set_transmittance_color" getter="get_transmittance_color" default="Color(1, 1, 1, 1)"> </member> - <member name="subsurf_scatter_transmittance_curve" type="float" setter="set_transmittance_curve" getter="get_transmittance_curve" default="1.0"> - </member> <member name="subsurf_scatter_transmittance_depth" type="float" setter="set_transmittance_depth" getter="get_transmittance_depth" default="0.1"> </member> <member name="subsurf_scatter_transmittance_enabled" type="bool" setter="set_feature" getter="get_feature" default="false"> diff --git a/doc/classes/Button.xml b/doc/classes/Button.xml index c9078a4de5..239e0bb2d9 100644 --- a/doc/classes/Button.xml +++ b/doc/classes/Button.xml @@ -85,6 +85,9 @@ <member name="icon" type="Texture2D" setter="set_button_icon" getter="get_button_icon"> Button's icon, if text is present the icon will be placed before the text. </member> + <member name="icon_align" type="int" setter="set_icon_align" getter="get_icon_align" enum="Button.TextAlign" default="0"> + Specifies if the icon should be aligned to the left, right, or center of a button. Uses the same [enum TextAlign] constants as the text alignment. If centered, text will draw on top of the icon. + </member> <member name="language" type="String" setter="set_language" getter="get_language" default=""""> Language code used for line-breaking and text shaping algorithms, if left empty current locale is used instead. </member> diff --git a/doc/classes/Callable.xml b/doc/classes/Callable.xml index cbab1a8f50..3c61e8278f 100644 --- a/doc/classes/Callable.xml +++ b/doc/classes/Callable.xml @@ -133,6 +133,13 @@ Returns [code]true[/code] if this [Callable] is a standard callable, referencing an object and a method using a [StringName]. </description> </method> + <method name="is_valid" qualifiers="const"> + <return type="bool"> + </return> + <description> + Returns [code]true[/code] if the object exists and has a valid function assigned, or is a custom callable. + </description> + </method> <method name="operator !=" qualifiers="operator"> <return type="bool"> </return> diff --git a/doc/classes/CallbackTweener.xml b/doc/classes/CallbackTweener.xml new file mode 100644 index 0000000000..8ac285c3df --- /dev/null +++ b/doc/classes/CallbackTweener.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="CallbackTweener" inherits="Tweener" version="4.0"> + <brief_description> + Calls the specified method after optional delay. + </brief_description> + <description> + [CallbackTweener] is used to call a method in a tweening sequence. See [method Tween.tween_callback] for more usage information. + [b]Note:[/b] [method Tween.tween_callback] is the only correct way to create [CallbackTweener]. Any [CallbackTweener] created manually will not function correctly. + </description> + <tutorials> + </tutorials> + <methods> + <method name="set_delay"> + <return type="CallbackTweener"> + </return> + <argument index="0" name="delay" type="float"> + </argument> + <description> + Makes the callback call delayed by given time in seconds. Example: + [codeblock] + var tween = get_tree().create_tween() + tween.tween_callback(queue_free).set_delay(2) #this will call queue_free() after 2 seconds + [/codeblock] + </description> + </method> + </methods> + <constants> + </constants> +</class> diff --git a/doc/classes/Camera2D.xml b/doc/classes/Camera2D.xml index bf1a9cc929..4620b3d93c 100644 --- a/doc/classes/Camera2D.xml +++ b/doc/classes/Camera2D.xml @@ -161,6 +161,8 @@ </member> <member name="limit_smoothed" type="bool" setter="set_limit_smoothing_enabled" getter="is_limit_smoothing_enabled" default="false"> If [code]true[/code], the camera smoothly stops when reaches its limits. + This has no effect if smoothing is disabled. + [b]Note:[/b] To immediately update the camera's position to be within limits without smoothing, even with this setting enabled, invoke [method reset_smoothing]. </member> <member name="limit_top" type="int" setter="set_limit" getter="get_limit" default="-10000000"> Top scroll limit in pixels. The camera stops moving when reaching this value. diff --git a/doc/classes/CanvasLayer.xml b/doc/classes/CanvasLayer.xml index f4c04d7bca..eb99368079 100644 --- a/doc/classes/CanvasLayer.xml +++ b/doc/classes/CanvasLayer.xml @@ -39,9 +39,6 @@ <member name="rotation" type="float" setter="set_rotation" getter="get_rotation" default="0.0"> The layer's rotation in radians. </member> - <member name="rotation_degrees" type="float" setter="set_rotation_degrees" getter="get_rotation_degrees" default="0.0"> - The layer's rotation in degrees. - </member> <member name="scale" type="Vector2" setter="set_scale" getter="get_scale" default="Vector2(1, 1)"> The layer's scale. </member> diff --git a/doc/classes/CharacterBody2D.xml b/doc/classes/CharacterBody2D.xml index fbe5c34d7d..b2d8aba174 100644 --- a/doc/classes/CharacterBody2D.xml +++ b/doc/classes/CharacterBody2D.xml @@ -101,9 +101,6 @@ <member name="floor_max_angle" type="float" setter="set_floor_max_angle" getter="get_floor_max_angle" default="0.785398"> Maximum angle (in radians) where a slope is still considered a floor (or a ceiling), rather than a wall, when calling [method move_and_slide]. The default value equals 45 degrees. </member> - <member name="floor_max_angle_degrees" type="float" setter="set_floor_max_angle_degrees" getter="get_floor_max_angle_degrees" default="45.0"> - Maximum angle (in degrees) where a slope is still considered a floor (or a ceiling), rather than a wall, when calling [method move_and_slide]. - </member> <member name="infinite_inertia" type="bool" setter="set_infinite_inertia_enabled" getter="is_infinite_inertia_enabled" default="true"> If [code]true[/code], the body will be able to push [RigidBody2D] nodes when calling [method move_and_slide], but it also won't detect any collisions with them. If [code]false[/code], it will interact with [RigidBody2D] nodes like with [StaticBody2D]. </member> diff --git a/doc/classes/CharacterBody3D.xml b/doc/classes/CharacterBody3D.xml index f6c3d68b3c..c76e02fac0 100644 --- a/doc/classes/CharacterBody3D.xml +++ b/doc/classes/CharacterBody3D.xml @@ -87,9 +87,6 @@ <member name="floor_max_angle" type="float" setter="set_floor_max_angle" getter="get_floor_max_angle" default="0.785398"> Maximum angle (in radians) where a slope is still considered a floor (or a ceiling), rather than a wall, when calling [method move_and_slide]. The default value equals 45 degrees. </member> - <member name="floor_max_angle_degrees" type="float" setter="set_floor_max_angle_degrees" getter="get_floor_max_angle_degrees" default="45.0"> - Maximum angle (in degrees) where a slope is still considered a floor (or a ceiling), rather than a wall, when calling [method move_and_slide]. - </member> <member name="infinite_inertia" type="bool" setter="set_infinite_inertia_enabled" getter="is_infinite_inertia_enabled" default="true"> If [code]true[/code], the body will be able to push [RigidBody3D] nodes when calling [method move_and_slide], but it also won't detect any collisions with them. If [code]false[/code], it will interact with [RigidBody3D] nodes like with [StaticBody3D]. </member> diff --git a/doc/classes/ClassDB.xml b/doc/classes/ClassDB.xml index 860bdc7c8f..028781d313 100644 --- a/doc/classes/ClassDB.xml +++ b/doc/classes/ClassDB.xml @@ -9,7 +9,7 @@ <tutorials> </tutorials> <methods> - <method name="can_instance" qualifiers="const"> + <method name="can_instantiate" qualifiers="const"> <return type="bool"> </return> <argument index="0" name="class" type="StringName"> @@ -187,7 +187,7 @@ Returns the parent class of [code]class[/code]. </description> </method> - <method name="instance" qualifiers="const"> + <method name="instantiate" qualifiers="const"> <return type="Variant"> </return> <argument index="0" name="class" type="StringName"> diff --git a/doc/classes/CodeEdit.xml b/doc/classes/CodeEdit.xml index c7dbd86c55..30fd47cdb6 100644 --- a/doc/classes/CodeEdit.xml +++ b/doc/classes/CodeEdit.xml @@ -143,6 +143,20 @@ Inserts the selected entry into the text. If [code]replace[/code] is true, any existing text is replaced rather then merged. </description> </method> + <method name="do_indent"> + <return type="void"> + </return> + <description> + Perform an indent as if the user activated the "ui_text_indent" action. + </description> + </method> + <method name="do_unindent"> + <return type="void"> + </return> + <description> + Perform an unindent as if the user activated the "ui_text_unindent" action. + </description> + </method> <method name="fold_all_lines"> <return type="void"> </return> @@ -278,6 +292,13 @@ Returns [code]true[/code] if string [code]start_key[/code] exists. </description> </method> + <method name="indent_lines"> + <return type="void"> + </return> + <description> + Indents selected lines, or in the case of no selection the caret line by one. + </description> + </method> <method name="is_in_comment" qualifiers="const"> <return type="int"> </return> @@ -441,6 +462,13 @@ Unfolds all lines that were previously folded. </description> </method> + <method name="unindent_lines"> + <return type="void"> + </return> + <description> + Unindents selected lines, or in the case of no selection the caret line by one. + </description> + </method> <method name="update_code_completion_options"> <return type="void"> </return> @@ -475,6 +503,18 @@ </member> <member name="draw_line_numbers" type="bool" setter="set_draw_line_numbers" getter="is_draw_line_numbers_enabled" default="false"> </member> + <member name="indent_automatic" type="bool" setter="set_auto_indent_enabled" getter="is_auto_indent_enabled" default="false"> + Sets whether automatic indent are enabled, this will add an extra indent if a prefix or brace is found. + </member> + <member name="indent_automatic_prefixes" type="String[]" setter="set_auto_indent_prefixes" getter="get_auto_indent_prefixes" default="["(", ":", "[", "{"]"> + Prefixes to trigger an automatic indent. + </member> + <member name="indent_size" type="int" setter="set_indent_size" getter="get_indent_size" default="4"> + Size of tabs, if [code]indent_use_spaces[/code] is enabled the amount of spaces to use. + </member> + <member name="indent_use_spaces" type="bool" setter="set_indent_using_spaces" getter="is_indent_using_spaces" default="false"> + Use spaces instead of tabs for indentation. + </member> <member name="layout_direction" type="int" setter="set_layout_direction" getter="get_layout_direction" override="true" enum="Control.LayoutDirection" default="2" /> <member name="line_folding" type="bool" setter="set_line_folding_enabled" getter="is_line_folding_enabled" default="true"> Sets whether line folding is allowed. diff --git a/doc/classes/CollisionObject2D.xml b/doc/classes/CollisionObject2D.xml index 7c4c75bf0f..e96124c9eb 100644 --- a/doc/classes/CollisionObject2D.xml +++ b/doc/classes/CollisionObject2D.xml @@ -266,6 +266,9 @@ The physics layers this CollisionObject2D scans. Collision objects can scan one or more of 32 different layers. See also [member collision_layer]. [b]Note:[/b] A contact is detected if object A is in any of the layers that object B scans, or object B is in any layers that object A scans. See [url=https://docs.godotengine.org/en/latest/tutorials/physics/physics_introduction.html#collision-layers-and-masks]Collision layers and masks[/url] in the documentation for more information. </member> + <member name="disable_mode" type="int" setter="set_disable_mode" getter="get_disable_mode" enum="CollisionObject2D.DisableMode" default="0"> + Defines the behavior in physics when [member Node.process_mode] is set to [constant Node.PROCESS_MODE_DISABLED]. See [enum DisableMode] for more details about the different modes. + </member> <member name="input_pickable" type="bool" setter="set_pickable" getter="is_pickable" default="true"> If [code]true[/code], this object is pickable. A pickable object can detect the mouse pointer entering/leaving, and if the mouse is inside it, report input events. Requires at least one [code]collision_layer[/code] bit to be set. </member> @@ -294,5 +297,16 @@ </signal> </signals> <constants> + <constant name="DISABLE_MODE_REMOVE" value="0" enum="DisableMode"> + When [member Node.process_mode] is set to [constant Node.PROCESS_MODE_DISABLED], remove from the physics simulation to stop all physics interactions with this [CollisionObject2D]. + Automatically re-added to the physics simulation when the [Node] is processed again. + </constant> + <constant name="DISABLE_MODE_MAKE_STATIC" value="1" enum="DisableMode"> + When [member Node.process_mode] is set to [constant Node.PROCESS_MODE_DISABLED], make the body static. Doesn't affect [Area2D]. [PhysicsBody2D] can't be affected by forces or other bodies while static. + Automatically set [PhysicsBody2D] back to its original mode when the [Node] is processed again. + </constant> + <constant name="DISABLE_MODE_KEEP_ACTIVE" value="2" enum="DisableMode"> + When [member Node.process_mode] is set to [constant Node.PROCESS_MODE_DISABLED], do not affect the physics simulation. + </constant> </constants> </class> diff --git a/doc/classes/CollisionObject3D.xml b/doc/classes/CollisionObject3D.xml index 4ab37f5c7b..dfd1e85e56 100644 --- a/doc/classes/CollisionObject3D.xml +++ b/doc/classes/CollisionObject3D.xml @@ -230,6 +230,9 @@ The physics layers this CollisionObject3D scans. Collision objects can scan one or more of 32 different layers. See also [member collision_layer]. [b]Note:[/b] A contact is detected if object A is in any of the layers that object B scans, or object B is in any layers that object A scans. See [url=https://docs.godotengine.org/en/latest/tutorials/physics/physics_introduction.html#collision-layers-and-masks]Collision layers and masks[/url] in the documentation for more information. </member> + <member name="disable_mode" type="int" setter="set_disable_mode" getter="get_disable_mode" enum="CollisionObject3D.DisableMode" default="0"> + Defines the behavior in physics when [member Node.process_mode] is set to [constant Node.PROCESS_MODE_DISABLED]. See [enum DisableMode] for more details about the different modes. + </member> <member name="input_capture_on_drag" type="bool" setter="set_capture_input_on_drag" getter="get_capture_input_on_drag" default="false"> If [code]true[/code], the [CollisionObject3D] will continue to receive input events as the mouse is dragged across its shapes. </member> @@ -265,5 +268,16 @@ </signal> </signals> <constants> + <constant name="DISABLE_MODE_REMOVE" value="0" enum="DisableMode"> + When [member Node.process_mode] is set to [constant Node.PROCESS_MODE_DISABLED], remove from the physics simulation to stop all physics interactions with this [CollisionObject3D]. + Automatically re-added to the physics simulation when the [Node] is processed again. + </constant> + <constant name="DISABLE_MODE_MAKE_STATIC" value="1" enum="DisableMode"> + When [member Node.process_mode] is set to [constant Node.PROCESS_MODE_DISABLED], make the body static. Doesn't affect [Area2D]. [PhysicsBody3D] can't be affected by forces or other bodies while static. + Automatically set [PhysicsBody3D] back to its original mode when the [Node] is processed again. + </constant> + <constant name="DISABLE_MODE_KEEP_ACTIVE" value="2" enum="DisableMode"> + When [member Node.process_mode] is set to [constant Node.PROCESS_MODE_DISABLED], do not affect the physics simulation. + </constant> </constants> </class> diff --git a/doc/classes/Color.xml b/doc/classes/Color.xml index 29c21b3213..7b1415e40d 100644 --- a/doc/classes/Color.xml +++ b/doc/classes/Color.xml @@ -80,14 +80,16 @@ </argument> <argument index="2" name="b" type="float"> </argument> + <argument index="3" name="a" type="float"> + </argument> <description> - Constructs a [Color] from RGB values, typically between 0 and 1. Alpha will be 1. + Constructs a [Color] from RGBA values, typically between 0 and 1. [codeblocks] [gdscript] - var color = Color(0.2, 1.0, 0.7) # Similar to `Color8(51, 255, 178, 255)` + var color = Color(0.2, 1.0, 0.7, 0.8) # Similar to `Color8(51, 255, 178, 204)` [/gdscript] [csharp] - var color = new Color(0.2f, 1.0f, 0.7f); // Similar to `Color.Color8(51, 255, 178, 255)` + var color = new Color(0.2f, 1.0f, 0.7f, 0.8f); // Similar to `Color.Color8(51, 255, 178, 255, 204)` [/csharp] [/codeblocks] </description> @@ -101,16 +103,14 @@ </argument> <argument index="2" name="b" type="float"> </argument> - <argument index="3" name="a" type="float"> - </argument> <description> - Constructs a [Color] from RGBA values, typically between 0 and 1. + Constructs a [Color] from RGB values, typically between 0 and 1. Alpha will be 1. [codeblocks] [gdscript] - var color = Color(0.2, 1.0, 0.7, 0.8) # Similar to `Color8(51, 255, 178, 204)` + var color = Color(0.2, 1.0, 0.7) # Similar to `Color8(51, 255, 178, 255)` [/gdscript] [csharp] - var color = new Color(0.2f, 1.0f, 0.7f, 0.8f); // Similar to `Color.Color8(51, 255, 178, 255, 204)` + var color = new Color(0.2f, 1.0f, 0.7f); // Similar to `Color.Color8(51, 255, 178, 255)` [/csharp] [/codeblocks] </description> @@ -349,12 +349,6 @@ <method name="operator +" qualifiers="operator"> <return type="Color"> </return> - <description> - </description> - </method> - <method name="operator +" qualifiers="operator"> - <return type="Color"> - </return> <argument index="0" name="right" type="Color"> </argument> <description> @@ -363,12 +357,6 @@ <method name="operator -" qualifiers="operator"> <return type="Color"> </return> - <description> - </description> - </method> - <method name="operator -" qualifiers="operator"> - <return type="Color"> - </return> <argument index="0" name="right" type="Color"> </argument> <description> @@ -414,6 +402,18 @@ <description> </description> </method> + <method name="operator unary+" qualifiers="operator"> + <return type="Color"> + </return> + <description> + </description> + </method> + <method name="operator unary-" qualifiers="operator"> + <return type="Color"> + </return> + <description> + </description> + </method> <method name="to_abgr32" qualifiers="const"> <return type="int"> </return> diff --git a/doc/classes/Control.xml b/doc/classes/Control.xml index 9015caa0b4..47e26b7a2e 100644 --- a/doc/classes/Control.xml +++ b/doc/classes/Control.xml @@ -50,14 +50,6 @@ [/codeblocks] </description> </method> - <method name="_clips_input" qualifiers="virtual"> - <return type="bool"> - </return> - <description> - Virtual method to be implemented by the user. Returns whether [method _gui_input] should not be called for children controls outside this control's rectangle. Input will be clipped to the Rect of this [Control]. Similar to [member rect_clip_content], but doesn't affect visibility. - If not overridden, defaults to [code]false[/code]. - </description> - </method> <method name="_drop_data" qualifiers="virtual"> <return type="void"> </return> @@ -155,13 +147,13 @@ * control has [member mouse_filter] set to [constant MOUSE_FILTER_IGNORE]; * control is obstructed by another [Control] on top of it, which doesn't have [member mouse_filter] set to [constant MOUSE_FILTER_IGNORE]; * control's parent has [member mouse_filter] set to [constant MOUSE_FILTER_STOP] or has accepted the event; - * it happens outside parent's rectangle and the parent has either [member rect_clip_content] or [method _clips_input] enabled. + * it happens outside parent's rectangle and the parent has either [member rect_clip_content] enabled. </description> </method> - <method name="_has_point" qualifiers="virtual"> + <method name="_has_point" qualifiers="virtual const"> <return type="bool"> </return> - <argument index="0" name="point" type="Vector2"> + <argument index="0" name="" type="Vector2"> </argument> <description> Virtual method to be implemented by the user. Returns whether the given [code]point[/code] is inside this control. @@ -201,14 +193,14 @@ [codeblocks] [gdscript] func _make_custom_tooltip(for_text): - var tooltip = preload("res://SomeTooltipScene.tscn").instance() + var tooltip = preload("res://SomeTooltipScene.tscn").instantiate() tooltip.get_node("Label").text = for_text return tooltip [/gdscript] [csharp] public override Godot.Control _MakeCustomTooltip(String forText) { - Node tooltip = ResourceLoader.Load<PackedScene>("res://SomeTooltipScene.tscn").Instance(); + Node tooltip = ResourceLoader.Load<PackedScene>("res://SomeTooltipScene.tscn").Instantiate(); tooltip.GetNode<Label>("Label").Text = forText; return tooltip; } @@ -1135,7 +1127,7 @@ Offsets are often controlled by one or multiple parent [Container] nodes, so you should not modify them manually if your node is a direct child of a [Container]. Offsets update automatically when you move or resize the node. </member> <member name="rect_clip_content" type="bool" setter="set_clip_contents" getter="is_clipping_contents" default="false"> - Enables whether rendering of [CanvasItem] based children should be clipped to this control's rectangle. If [code]true[/code], parts of a child which would be visibly outside of this control's rectangle will not be rendered. + Enables whether rendering of [CanvasItem] based children should be clipped to this control's rectangle. If [code]true[/code], parts of a child which would be visibly outside of this control's rectangle will not be rendered and won't receive input. </member> <member name="rect_global_position" type="Vector2" setter="_set_global_position" getter="get_global_position"> The node's global position, relative to the world (usually to the top-left corner of the window). @@ -1152,13 +1144,10 @@ <member name="rect_rotation" type="float" setter="set_rotation" getter="get_rotation" default="0.0"> The node's rotation around its pivot, in radians. See [member rect_pivot_offset] to change the pivot's position. </member> - <member name="rect_rotation_degrees" type="float" setter="set_rotation_degrees" getter="get_rotation_degrees" default="0.0"> - The node's rotation around its pivot, in degrees. See [member rect_pivot_offset] to change the pivot's position. - </member> <member name="rect_scale" type="Vector2" setter="set_scale" getter="get_scale" default="Vector2(1, 1)"> The node's scale, relative to its [member rect_size]. Change this property to scale the node around its [member rect_pivot_offset]. The Control's [member hint_tooltip] will also scale according to this value. [b]Note:[/b] This property is mainly intended to be used for animation purposes. Text inside the Control will look pixelated or blurry when the Control is scaled. To support multiple resolutions in your project, use an appropriate viewport stretch mode as described in the [url=https://docs.godotengine.org/en/latest/tutorials/viewports/multiple_resolutions.html]documentation[/url] instead of scaling Controls individually. - [b]Note:[/b] If the Control node is a child of a [Container] node, the scale will be reset to [code]Vector2(1, 1)[/code] when the scene is instanced. To set the Control's scale when it's instanced, wait for one frame using [code]yield(get_tree(), "idle_frame")[/code] then set its [member rect_scale] property. + [b]Note:[/b] If the Control node is a child of a [Container] node, the scale will be reset to [code]Vector2(1, 1)[/code] when the scene is instantiated. To set the Control's scale when it's instantiated, wait for one frame using [code]yield(get_tree(), "idle_frame")[/code] then set its [member rect_scale] property. </member> <member name="rect_size" type="Vector2" setter="_set_size" getter="get_size" default="Vector2(0, 0)"> The size of the node's bounding rectangle, in pixels. [Container] nodes update this property automatically. diff --git a/doc/classes/Curve3Texture.xml b/doc/classes/Curve3Texture.xml new file mode 100644 index 0000000000..1b352dff0d --- /dev/null +++ b/doc/classes/Curve3Texture.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="Curve3Texture" inherits="Texture2D" version="4.0"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <methods> + </methods> + <members> + <member name="curve_x" type="Curve" setter="set_curve_x" getter="get_curve_x"> + </member> + <member name="curve_y" type="Curve" setter="set_curve_y" getter="get_curve_y"> + </member> + <member name="curve_z" type="Curve" setter="set_curve_z" getter="get_curve_z"> + </member> + <member name="width" type="int" setter="set_width" getter="get_width" default="2048"> + </member> + </members> + <constants> + </constants> +</class> diff --git a/doc/classes/CurveTexture.xml b/doc/classes/CurveTexture.xml index bc6b69d2d1..54065fe0f9 100644 --- a/doc/classes/CurveTexture.xml +++ b/doc/classes/CurveTexture.xml @@ -14,10 +14,16 @@ <member name="curve" type="Curve" setter="set_curve" getter="get_curve"> The [code]curve[/code] rendered onto the texture. </member> + <member name="texture_mode" type="int" setter="set_texture_mode" getter="get_texture_mode" enum="CurveTexture.TextureMode" default="0"> + </member> <member name="width" type="int" setter="set_width" getter="get_width" default="2048"> The width of the texture. </member> </members> <constants> + <constant name="TEXTURE_MODE_RGB" value="0" enum="TextureMode"> + </constant> + <constant name="TEXTURE_MODE_RED" value="1" enum="TextureMode"> + </constant> </constants> </class> diff --git a/doc/classes/CylinderMesh.xml b/doc/classes/CylinderMesh.xml index 3a81e98c3a..827fb5c10c 100644 --- a/doc/classes/CylinderMesh.xml +++ b/doc/classes/CylinderMesh.xml @@ -4,7 +4,7 @@ Class representing a cylindrical [PrimitiveMesh]. </brief_description> <description> - Class representing a cylindrical [PrimitiveMesh]. This class can be used to create cones by setting either the [member top_radius] or [member bottom_radius] properties to 0.0. + Class representing a cylindrical [PrimitiveMesh]. This class can be used to create cones by setting either the [member top_radius] or [member bottom_radius] properties to [code]0.0[/code]. </description> <tutorials> </tutorials> @@ -12,19 +12,19 @@ </methods> <members> <member name="bottom_radius" type="float" setter="set_bottom_radius" getter="get_bottom_radius" default="1.0"> - Bottom radius of the cylinder. + Bottom radius of the cylinder. If set to [code]0.0[/code], the bottom faces will not be generated, resulting in a conic shape. </member> <member name="height" type="float" setter="set_height" getter="get_height" default="2.0"> Full height of the cylinder. </member> <member name="radial_segments" type="int" setter="set_radial_segments" getter="get_radial_segments" default="64"> - Number of radial segments on the cylinder. + Number of radial segments on the cylinder. Higher values result in a more detailed cylinder/cone at the cost of performance. </member> <member name="rings" type="int" setter="set_rings" getter="get_rings" default="4"> - Number of edge rings along the height of the cylinder. + Number of edge rings along the height of the cylinder. Changing [member rings] does not have any visual impact unless a shader or procedural mesh tool is used to alter the vertex data. Higher values result in more subdivisions, which can be used to create smoother-looking effects with shaders or procedural mesh tools (at the cost of performance). When not altering the vertex data using a shader or procedural mesh tool, [member rings] should be kept to its default value. </member> <member name="top_radius" type="float" setter="set_top_radius" getter="get_top_radius" default="1.0"> - Top radius of the cylinder. + Top radius of the cylinder. If set to [code]0.0[/code], the top faces will not be generated, resulting in a conic shape. </member> </members> <constants> diff --git a/doc/classes/DirectionalLight3D.xml b/doc/classes/DirectionalLight3D.xml index 233b1f0c16..4f51adb8fc 100644 --- a/doc/classes/DirectionalLight3D.xml +++ b/doc/classes/DirectionalLight3D.xml @@ -15,9 +15,6 @@ <member name="directional_shadow_blend_splits" type="bool" setter="set_blend_splits" getter="is_blend_splits_enabled" default="false"> If [code]true[/code], shadow detail is sacrificed in exchange for smoother transitions between splits. </member> - <member name="directional_shadow_depth_range" type="int" setter="set_shadow_depth_range" getter="get_shadow_depth_range" enum="DirectionalLight3D.ShadowDepthRange" default="0"> - Optimizes shadow rendering for detail versus movement. See [enum ShadowDepthRange]. - </member> <member name="directional_shadow_fade_start" type="float" setter="set_param" getter="get_param" default="0.8"> Proportion of [member directional_shadow_max_distance] at which point the shadow starts to fade. At [member directional_shadow_max_distance] the shadow will disappear. </member> @@ -55,11 +52,5 @@ <constant name="SHADOW_PARALLEL_4_SPLITS" value="2" enum="ShadowMode"> Splits the view frustum in 4 areas, each with its own shadow map. This is the slowest directional shadow mode. </constant> - <constant name="SHADOW_DEPTH_RANGE_STABLE" value="0" enum="ShadowDepthRange"> - Keeps the shadow stable when the camera moves, at the cost of lower effective shadow resolution. - </constant> - <constant name="SHADOW_DEPTH_RANGE_OPTIMIZED" value="1" enum="ShadowDepthRange"> - Tries to achieve maximum shadow resolution. May result in saw effect on shadow edges. This mode typically works best in games where the camera will often move at high speeds, such as most racing games. - </constant> </constants> </class> diff --git a/doc/classes/DisplayServer.xml b/doc/classes/DisplayServer.xml index 0a4807f046..17b51d5cbe 100644 --- a/doc/classes/DisplayServer.xml +++ b/doc/classes/DisplayServer.xml @@ -44,9 +44,11 @@ </return> <argument index="0" name="mode" type="int" enum="DisplayServer.WindowMode"> </argument> - <argument index="1" name="flags" type="int"> + <argument index="1" name="vsync_mode" type="int" enum="DisplayServer.VSyncMode"> </argument> - <argument index="2" name="rect" type="Rect2i" default="Rect2i(0, 0, 0, 0)"> + <argument index="2" name="flags" type="int"> + </argument> + <argument index="3" name="rect" type="Rect2i" default="Rect2i(0, 0, 0, 0)"> </argument> <description> </description> @@ -436,7 +438,7 @@ </description> </method> <method name="mouse_get_button_state" qualifiers="const"> - <return type="int"> + <return type="int" enum="MouseButton"> </return> <description> </description> @@ -671,34 +673,6 @@ [b]Note:[/b] This method is implemented on Android, iOS and UWP. </description> </method> - <method name="vsync_is_enabled" qualifiers="const"> - <return type="bool"> - </return> - <description> - </description> - </method> - <method name="vsync_is_using_via_compositor" qualifiers="const"> - <return type="bool"> - </return> - <description> - </description> - </method> - <method name="vsync_set_enabled"> - <return type="void"> - </return> - <argument index="0" name="enabled" type="bool"> - </argument> - <description> - </description> - </method> - <method name="vsync_set_use_via_compositor"> - <return type="void"> - </return> - <argument index="0" name="enabled" type="bool"> - </argument> - <description> - </description> - </method> <method name="window_attach_instance_id"> <return type="void"> </return> @@ -791,6 +765,15 @@ <description> </description> </method> + <method name="window_get_vsync_mode" qualifiers="const"> + <return type="int" enum="DisplayServer.VSyncMode"> + </return> + <argument index="0" name="window_id" type="int" default="0"> + </argument> + <description> + Returns the VSync mode of the given window. + </description> + </method> <method name="window_move_to_foreground"> <return type="void"> </return> @@ -995,6 +978,19 @@ <description> </description> </method> + <method name="window_set_vsync_mode"> + <return type="void"> + </return> + <argument index="0" name="vsync_mode" type="int" enum="DisplayServer.VSyncMode"> + </argument> + <argument index="1" name="window_id" type="int" default="0"> + </argument> + <description> + Sets the VSync mode of the given window. + See [enum DisplayServer.VSyncMode] for possible values and how they affect the behavior of your application. + Depending on the platform and used renderer, the engine will fall back to [constant VSYNC_ENABLED], if the desired mode is not supported. + </description> + </method> <method name="window_set_window_event_callback"> <return type="void"> </return> @@ -1151,5 +1147,18 @@ </constant> <constant name="WINDOW_EVENT_DPI_CHANGE" value="6" enum="WindowEvent"> </constant> + <constant name="VSYNC_DISABLED" value="0" enum="VSyncMode"> + No vertical synchronization, which means the engine will display frames as fast as possible (tearing may be visible). + </constant> + <constant name="VSYNC_ENABLED" value="1" enum="VSyncMode"> + Default vertical synchronization mode, the image is displayed only on vertical blanking intervals (no tearing is visible). + </constant> + <constant name="VSYNC_ADAPTIVE" value="2" enum="VSyncMode"> + Behaves like [constant VSYNC_DISABLED] when the framerate drops below the screen's refresh rate to reduce stuttering (tearing may be visible), otherwise vertical synchronization is enabled to avoid tearing. + </constant> + <constant name="VSYNC_MAILBOX" value="3" enum="VSyncMode"> + Displays the most recent image in the queue on vertical blanking intervals, while rendering to the other images (no tearing is visible). + Although not guaranteed, the images can be rendered as fast as possible, which may reduce input lag. + </constant> </constants> </class> diff --git a/doc/classes/EditorPlugin.xml b/doc/classes/EditorPlugin.xml index 0c0439e9d3..753227513b 100644 --- a/doc/classes/EditorPlugin.xml +++ b/doc/classes/EditorPlugin.xml @@ -404,7 +404,7 @@ </argument> <description> Adds a custom type, which will appear in the list of nodes or resources. An icon can be optionally passed. - When given node or resource is selected, the base type will be instanced (e.g. "Node3D", "Control", "Resource"), then the script will be loaded and set to this object. + When given node or resource is selected, the base type will be instantiated (e.g. "Node3D", "Control", "Resource"), then the script will be loaded and set to this object. You can use the virtual method [method _handles] to check if your custom object is being edited by checking the script or using the [code]is[/code] keyword. During run-time, this will be a simple object with a script so this function does not need to be called then. </description> @@ -547,6 +547,7 @@ <return type="void"> </return> <description> + Minimizes the bottom panel. </description> </method> <method name="make_bottom_panel_item_visible"> @@ -555,6 +556,7 @@ <argument index="0" name="item" type="Control"> </argument> <description> + Makes a specific item in the bottom panel visible. </description> </method> <method name="queue_save_layout"> diff --git a/doc/classes/EditorSpinSlider.xml b/doc/classes/EditorSpinSlider.xml index 935335943f..b86e5e5c6e 100644 --- a/doc/classes/EditorSpinSlider.xml +++ b/doc/classes/EditorSpinSlider.xml @@ -18,6 +18,9 @@ </member> <member name="read_only" type="bool" setter="set_read_only" getter="is_read_only" default="false"> </member> + <member name="suffix" type="String" setter="set_suffix" getter="get_suffix" default=""""> + The suffix to display after the value (in a faded color). This should generally be a plural word. You may have to use an abbreviation if the suffix is too long to be displayed. + </member> </members> <constants> </constants> diff --git a/doc/classes/Engine.xml b/doc/classes/Engine.xml index ab480c50ab..c0a8407ece 100644 --- a/doc/classes/Engine.xml +++ b/doc/classes/Engine.xml @@ -173,6 +173,11 @@ Controls how much physics ticks are synchronized with real time. For 0 or less, the ticks are synchronized. Such values are recommended for network games, where clock synchronization matters. Higher values cause higher deviation of in-game clock and real clock, but allows smoothing out framerate jitters. The default value of 0.5 should be fine for most; values above 2 could cause the game to react to dropped frames with a noticeable delay and are not recommended. [b]Note:[/b] For best results, when using a custom physics interpolation solution, the physics jitter fix should be disabled by setting [member physics_jitter_fix] to [code]0[/code]. </member> + <member name="print_error_messages" type="bool" setter="set_print_error_messages" getter="is_printing_error_messages" default="true"> + If [code]false[/code], stops printing error and warning messages to the console and editor Output log. This can be used to hide error and warning messages during unit test suite runs. This property is equivalent to the [member ProjectSettings.application/run/disable_stderr] project setting. + [b]Warning:[/b] If you set this to [code]false[/code] anywhere in the project, important error messages may be hidden even if they are emitted from other scripts. If this is set to [code]false[/code] in a [code]@tool[/code] script, this will also impact the editor itself. Do [i]not[/i] report bugs before ensuring error messages are enabled (as they are by default). + [b]Note:[/b] This property does not impact the editor's Errors tab when running a project from the editor. + </member> <member name="target_fps" type="int" setter="set_target_fps" getter="get_target_fps" default="0"> The desired frames per second. If the hardware cannot keep up, this setting may not be respected. A value of 0 means no limit. </member> diff --git a/doc/classes/File.xml b/doc/classes/File.xml index 7feaaa2040..f98c31dc7f 100644 --- a/doc/classes/File.xml +++ b/doc/classes/File.xml @@ -486,6 +486,7 @@ </argument> <description> Stores any Variant value in the file. If [code]full_objects[/code] is [code]true[/code], encoding objects is allowed (and can potentially include code). + [b]Note:[/b] Not all properties are included. Only properties that are configured with the [constant PROPERTY_USAGE_STORAGE] flag set will be serialized. You can add a new usage flag to a property by overriding the [method Object._get_property_list] method in your class. You can also check how property usage is configured by calling [method Object._get_property_list]. See [enum PropertyUsageFlags] for the possible usage flags. </description> </method> </methods> diff --git a/doc/classes/HTTPClient.xml b/doc/classes/HTTPClient.xml index a549994a69..a08bed751f 100644 --- a/doc/classes/HTTPClient.xml +++ b/doc/classes/HTTPClient.xml @@ -158,7 +158,8 @@ <argument index="3" name="body" type="String" default=""""> </argument> <description> - Sends a request to the connected host. The URL parameter is just the part after the host, so for [code]http://somehost.com/index.php[/code], it is [code]index.php[/code]. + Sends a request to the connected host. + The URL parameter is usually just the part after the host, so for [code]http://somehost.com/index.php[/code], it is [code]/index.php[/code]. When sending requests to an HTTP proxy server, it should be an absolute URL. For [constant HTTPClient.METHOD_OPTIONS] requests, [code]*[/code] is also allowed. For [constant HTTPClient.METHOD_CONNECT] requests, it should be the authority component ([code]host:port[/code]). Headers are HTTP request headers. For available HTTP methods, see [enum Method]. To create a POST request with query strings to push to the server, do: [codeblocks] @@ -166,7 +167,7 @@ var fields = {"username" : "user", "password" : "pass"} var query_string = http_client.query_string_from_dict(fields) var headers = ["Content-Type: application/x-www-form-urlencoded", "Content-Length: " + str(query_string.length())] - var result = http_client.request(http_client.METHOD_POST, "index.php", headers, query_string) + var result = http_client.request(http_client.METHOD_POST, "/index.php", headers, query_string) [/gdscript] [csharp] var fields = new Godot.Collections.Dictionary { { "username", "user" }, { "password", "pass" } }; @@ -190,7 +191,8 @@ <argument index="3" name="body" type="PackedByteArray"> </argument> <description> - Sends a raw request to the connected host. The URL parameter is just the part after the host, so for [code]http://somehost.com/index.php[/code], it is [code]index.php[/code]. + Sends a raw request to the connected host. + The URL parameter is usually just the part after the host, so for [code]http://somehost.com/index.php[/code], it is [code]/index.php[/code]. When sending requests to an HTTP proxy server, it should be an absolute URL. For [constant HTTPClient.METHOD_OPTIONS] requests, [code]*[/code] is also allowed. For [constant HTTPClient.METHOD_CONNECT] requests, it should be the authority component ([code]host:port[/code]). Headers are HTTP request headers. For available HTTP methods, see [enum Method]. Sends the body data raw, as a byte array and does not encode it in any way. </description> diff --git a/doc/classes/ImageTexture.xml b/doc/classes/ImageTexture.xml index 5fef56e354..f89b6ad57b 100644 --- a/doc/classes/ImageTexture.xml +++ b/doc/classes/ImageTexture.xml @@ -61,10 +61,8 @@ </return> <argument index="0" name="image" type="Image"> </argument> - <argument index="1" name="immediate" type="bool" default="false"> - </argument> <description> - Replaces the texture's data with a new [Image]. If [code]immediate[/code] is [code]true[/code], it will take effect immediately after the call. + Replaces the texture's data with a new [Image]. [b]Note:[/b] The texture has to be initialized first with the [method create_from_image] method before it can be updated. The new image dimensions, format, and mipmaps configuration should match the existing texture's image configuration, otherwise it has to be re-created with the [method create_from_image] method. Use this method over [method create_from_image] if you need to update the texture frequently, which is faster than allocating additional memory for a new texture each time. </description> diff --git a/doc/classes/ImmediateGeometry3D.xml b/doc/classes/ImmediateGeometry3D.xml deleted file mode 100644 index d2d663847f..0000000000 --- a/doc/classes/ImmediateGeometry3D.xml +++ /dev/null @@ -1,113 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<class name="ImmediateGeometry3D" inherits="GeometryInstance3D" version="4.0"> - <brief_description> - Draws simple geometry from code. - </brief_description> - <description> - Draws simple geometry from code. Uses a drawing mode similar to OpenGL 1.x. - See also [ArrayMesh], [MeshDataTool] and [SurfaceTool] for procedural geometry generation. - [b]Note:[/b] ImmediateGeometry3D is best suited to small amounts of mesh data that change every frame. It will be slow when handling large amounts of mesh data. If mesh data doesn't change often, use [ArrayMesh], [MeshDataTool] or [SurfaceTool] instead. - [b]Note:[/b] Godot uses clockwise [url=https://learnopengl.com/Advanced-OpenGL/Face-culling]winding order[/url] for front faces of triangle primitive modes. - </description> - <tutorials> - </tutorials> - <methods> - <method name="add_sphere"> - <return type="void"> - </return> - <argument index="0" name="lats" type="int"> - </argument> - <argument index="1" name="lons" type="int"> - </argument> - <argument index="2" name="radius" type="float"> - </argument> - <argument index="3" name="add_uv" type="bool" default="true"> - </argument> - <description> - Simple helper to draw an UV sphere with given latitude, longitude and radius. - </description> - </method> - <method name="add_vertex"> - <return type="void"> - </return> - <argument index="0" name="position" type="Vector3"> - </argument> - <description> - Adds a vertex in local coordinate space with the currently set color/uv/etc. - </description> - </method> - <method name="begin"> - <return type="void"> - </return> - <argument index="0" name="primitive" type="int" enum="Mesh.PrimitiveType"> - </argument> - <argument index="1" name="texture" type="Texture2D" default="null"> - </argument> - <description> - Begin drawing (and optionally pass a texture override). When done call [method end]. For more information on how this works, search for [code]glBegin()[/code] and [code]glEnd()[/code] references. - For the type of primitive, see the [enum Mesh.PrimitiveType] enum. - </description> - </method> - <method name="clear"> - <return type="void"> - </return> - <description> - Clears everything that was drawn using begin/end. - </description> - </method> - <method name="end"> - <return type="void"> - </return> - <description> - Ends a drawing context and displays the results. - </description> - </method> - <method name="set_color"> - <return type="void"> - </return> - <argument index="0" name="color" type="Color"> - </argument> - <description> - The current drawing color. - </description> - </method> - <method name="set_normal"> - <return type="void"> - </return> - <argument index="0" name="normal" type="Vector3"> - </argument> - <description> - The next vertex's normal. - </description> - </method> - <method name="set_tangent"> - <return type="void"> - </return> - <argument index="0" name="tangent" type="Plane"> - </argument> - <description> - The next vertex's tangent (and binormal facing). - </description> - </method> - <method name="set_uv"> - <return type="void"> - </return> - <argument index="0" name="uv" type="Vector2"> - </argument> - <description> - The next vertex's UV. - </description> - </method> - <method name="set_uv2"> - <return type="void"> - </return> - <argument index="0" name="uv" type="Vector2"> - </argument> - <description> - The next vertex's second layer UV. - </description> - </method> - </methods> - <constants> - </constants> -</class> diff --git a/doc/classes/ImmediateMesh.xml b/doc/classes/ImmediateMesh.xml new file mode 100644 index 0000000000..d2ae091cad --- /dev/null +++ b/doc/classes/ImmediateMesh.xml @@ -0,0 +1,103 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="ImmediateMesh" inherits="Mesh" version="4.0"> + <brief_description> + Mesh optimized for creating geometry manually. + </brief_description> + <description> + Mesh optimized for creating geometry manually, similar to OpenGL1.x immediate mode. + </description> + <tutorials> + </tutorials> + <methods> + <method name="clear_surfaces"> + <return type="void"> + </return> + <description> + Clear all surfaces. + </description> + </method> + <method name="surface_add_vertex"> + <return type="void"> + </return> + <argument index="0" name="vertex" type="Vector3"> + </argument> + <description> + Add a 3D vertex using the current attributes previously set. + </description> + </method> + <method name="surface_add_vertex_2d"> + <return type="void"> + </return> + <argument index="0" name="vertex" type="Vector2"> + </argument> + <description> + Add a 2D vertex using the current attributes previously set. + </description> + </method> + <method name="surface_begin"> + <return type="void"> + </return> + <argument index="0" name="primitive" type="int" enum="Mesh.PrimitiveType"> + </argument> + <argument index="1" name="material" type="Material" default="null"> + </argument> + <description> + Begin a new surface. + </description> + </method> + <method name="surface_end"> + <return type="void"> + </return> + <description> + End and commit current surface. Note that surface being created will not be visible until this function is called. + </description> + </method> + <method name="surface_set_color"> + <return type="void"> + </return> + <argument index="0" name="color" type="Color"> + </argument> + <description> + Set the color attribute that will be pushed with the next vertex. + </description> + </method> + <method name="surface_set_normal"> + <return type="void"> + </return> + <argument index="0" name="normal" type="Vector3"> + </argument> + <description> + Set the normal attribute that will be pushed with the next vertex. + </description> + </method> + <method name="surface_set_tangent"> + <return type="void"> + </return> + <argument index="0" name="tangent" type="Plane"> + </argument> + <description> + Set the tangent attribute that will be pushed with the next vertex. + </description> + </method> + <method name="surface_set_uv"> + <return type="void"> + </return> + <argument index="0" name="uv" type="Vector2"> + </argument> + <description> + Set the UV attribute that will be pushed with the next vertex. + </description> + </method> + <method name="surface_set_uv2"> + <return type="void"> + </return> + <argument index="0" name="uv2" type="Vector2"> + </argument> + <description> + Set the UV2 attribute that will be pushed with the next vertex. + </description> + </method> + </methods> + <constants> + </constants> +</class> diff --git a/doc/classes/Input.xml b/doc/classes/Input.xml index 05a8bd268e..b970070659 100644 --- a/doc/classes/Input.xml +++ b/doc/classes/Input.xml @@ -123,7 +123,7 @@ </return> <argument index="0" name="device" type="int"> </argument> - <argument index="1" name="axis" type="int"> + <argument index="1" name="axis" type="int" enum="JoyAxis"> </argument> <description> Returns the current value of the joypad axis at given index (see [enum JoyAxis]). @@ -252,7 +252,7 @@ </return> <argument index="0" name="device" type="int"> </argument> - <argument index="1" name="button" type="int"> + <argument index="1" name="button" type="int" enum="JoyButton"> </argument> <description> Returns [code]true[/code] if you are pressing the joypad button (see [enum JoyButton]). @@ -279,7 +279,7 @@ <method name="is_mouse_button_pressed" qualifiers="const"> <return type="bool"> </return> - <argument index="0" name="button" type="int"> + <argument index="0" name="button" type="int" enum="MouseButton"> </argument> <description> Returns [code]true[/code] if you are pressing the mouse button specified with [enum MouseButton]. diff --git a/doc/classes/InputEvent.xml b/doc/classes/InputEvent.xml index 0c8db0de73..c28c4c4282 100644 --- a/doc/classes/InputEvent.xml +++ b/doc/classes/InputEvent.xml @@ -90,20 +90,23 @@ Returns [code]true[/code] if this input event is an echo event (only for events of type [InputEventKey]). </description> </method> - <method name="is_pressed" qualifiers="const"> + <method name="is_match" qualifiers="const"> <return type="bool"> </return> + <argument index="0" name="event" type="InputEvent"> + </argument> + <argument index="1" name="exact_match" type="bool" default="true"> + </argument> <description> - Returns [code]true[/code] if this input event is pressed. Not relevant for events of type [InputEventMouseMotion] or [InputEventScreenDrag]. + Returns [code]true[/code] if the specified [code]event[/code] matches this event. Only valid for action events i.e key ([InputEventKey]), button ([InputEventMouseButton] or [InputEventJoypadButton]), axis [InputEventJoypadMotion] or action ([InputEventAction]) events. + If [code]exact_match[/code] is [code]false[/code], it ignores the input modifiers for [InputEventKey] and [InputEventMouseButton] events, and the direction for [InputEventJoypadMotion] events. </description> </method> - <method name="shortcut_match" qualifiers="const"> + <method name="is_pressed" qualifiers="const"> <return type="bool"> </return> - <argument index="0" name="event" type="InputEvent"> - </argument> <description> - Returns [code]true[/code] if the given input event is checking for the same key ([InputEventKey]), button ([InputEventJoypadButton]) or action ([InputEventAction]). + Returns [code]true[/code] if this input event is pressed. Not relevant for events of type [InputEventMouseMotion] or [InputEventScreenDrag]. </description> </method> <method name="xformed_by" qualifiers="const"> diff --git a/doc/classes/InputEventJoypadButton.xml b/doc/classes/InputEventJoypadButton.xml index b1f4836f6e..f9afe42a7a 100644 --- a/doc/classes/InputEventJoypadButton.xml +++ b/doc/classes/InputEventJoypadButton.xml @@ -12,7 +12,7 @@ <methods> </methods> <members> - <member name="button_index" type="int" setter="set_button_index" getter="get_button_index" default="0"> + <member name="button_index" type="int" setter="set_button_index" getter="get_button_index" enum="JoyButton" default="0"> Button identifier. One of the [enum JoyButton] button constants. </member> <member name="pressed" type="bool" setter="set_pressed" getter="is_pressed" default="false"> diff --git a/doc/classes/InputEventJoypadMotion.xml b/doc/classes/InputEventJoypadMotion.xml index 39fdb14016..398b9eb6f6 100644 --- a/doc/classes/InputEventJoypadMotion.xml +++ b/doc/classes/InputEventJoypadMotion.xml @@ -12,7 +12,7 @@ <methods> </methods> <members> - <member name="axis" type="int" setter="set_axis" getter="get_axis" default="0"> + <member name="axis" type="int" setter="set_axis" getter="get_axis" enum="JoyAxis" default="0"> Axis identifier. Use one of the [enum JoyAxis] axis constants. </member> <member name="axis_value" type="float" setter="set_axis_value" getter="get_axis_value" default="0.0"> diff --git a/doc/classes/InputEventMIDI.xml b/doc/classes/InputEventMIDI.xml index 13bb9d8b85..afc9d476da 100644 --- a/doc/classes/InputEventMIDI.xml +++ b/doc/classes/InputEventMIDI.xml @@ -17,7 +17,7 @@ </member> <member name="instrument" type="int" setter="set_instrument" getter="get_instrument" default="0"> </member> - <member name="message" type="int" setter="set_message" getter="get_message" default="0"> + <member name="message" type="int" setter="set_message" getter="get_message" enum="MIDIMessage" default="0"> </member> <member name="pitch" type="int" setter="set_pitch" getter="get_pitch" default="0"> </member> diff --git a/doc/classes/InputEventMouseButton.xml b/doc/classes/InputEventMouseButton.xml index be71b42567..7a6c7410ef 100644 --- a/doc/classes/InputEventMouseButton.xml +++ b/doc/classes/InputEventMouseButton.xml @@ -12,7 +12,7 @@ <methods> </methods> <members> - <member name="button_index" type="int" setter="set_button_index" getter="get_button_index" default="0"> + <member name="button_index" type="int" setter="set_button_index" getter="get_button_index" enum="MouseButton" default="0"> The mouse button identifier, one of the [enum MouseButton] button or button wheel constants. </member> <member name="double_click" type="bool" setter="set_double_click" getter="is_double_click" default="false"> diff --git a/doc/classes/InputMap.xml b/doc/classes/InputMap.xml index 0fb18d8e81..3948ab0208 100644 --- a/doc/classes/InputMap.xml +++ b/doc/classes/InputMap.xml @@ -41,6 +41,15 @@ Removes all events from an action. </description> </method> + <method name="action_get_deadzone"> + <return type="float"> + </return> + <argument index="0" name="action" type="StringName"> + </argument> + <description> + Returns a deadzone value for the action. + </description> + </method> <method name="action_get_events"> <return type="Array"> </return> diff --git a/doc/classes/InstancePlaceholder.xml b/doc/classes/InstancePlaceholder.xml index defd23afb1..934764b461 100644 --- a/doc/classes/InstancePlaceholder.xml +++ b/doc/classes/InstancePlaceholder.xml @@ -4,7 +4,7 @@ Placeholder for the root [Node] of a [PackedScene]. </brief_description> <description> - Turning on the option [b]Load As Placeholder[/b] for an instanced scene in the editor causes it to be replaced by an [InstancePlaceholder] when running the game. This makes it possible to delay actually loading the scene until calling [method create_instance]. This is useful to avoid loading large scenes all at once by loading parts of it selectively. + Turning on the option [b]Load As Placeholder[/b] for an instantiated scene in the editor causes it to be replaced by an [InstancePlaceholder] when running the game. This makes it possible to delay actually loading the scene until calling [method create_instance]. This is useful to avoid loading large scenes all at once by loading parts of it selectively. The [InstancePlaceholder] does not have a transform. This causes any child nodes to be positioned relatively to the [Viewport] from point (0,0), rather than their parent as displayed in the editor. Replacing the placeholder with a scene with a transform will transform children relatively to their parent again. </description> <tutorials> diff --git a/doc/classes/IntervalTweener.xml b/doc/classes/IntervalTweener.xml new file mode 100644 index 0000000000..1c59003c70 --- /dev/null +++ b/doc/classes/IntervalTweener.xml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="IntervalTweener" inherits="Tweener" version="4.0"> + <brief_description> + Creates an idle interval in a [Tween] animation. + </brief_description> + <description> + [IntervalTweener] is used to make delays in a tweening sequence. See [method Tween.tween_interval] for more usage information. + [b]Note:[/b] [method Tween.tween_interval] is the only correct way to create [IntervalTweener]. Any [IntervalTweener] created manually will not function correctly. + </description> + <tutorials> + </tutorials> + <methods> + </methods> + <constants> + </constants> +</class> diff --git a/doc/classes/JSON.xml b/doc/classes/JSON.xml index 7baff7aa39..b95aaed143 100644 --- a/doc/classes/JSON.xml +++ b/doc/classes/JSON.xml @@ -1,45 +1,88 @@ <?xml version="1.0" encoding="UTF-8" ?> -<class name="JSON" inherits="Object" version="4.0"> +<class name="JSON" inherits="RefCounted" version="4.0"> <brief_description> - Helper class for parsing JSON data. + Helper class for creating and parsing JSON data. </brief_description> <description> - Helper class for parsing JSON data. For usage example and other important hints, see [JSONParseResult]. + The [JSON] enables all data types to be converted to and from a JSON string. This useful for serializing data to save to a file or send over the network. + [method stringify] is used to convert any data type into a JSON string. + [method parse] is used to convert any existing JSON data into a [Variant] that can be used within Godot. If successfully parsed, use [method get_data] to retrieve the [Variant], and use [code]typeof[/code] to check if the Variant's type is what you expect. JSON Objects are converted into a [Dictionary], but JSON data can be used to store [Array]s, numbers, [String]s and even just a boolean. + [b]Example[/b] + [codeblock] + var data_to_send = ["a", "b", "c"] + var json = JSON.new() + var json_string = json.stringify(data_to_send) + # Save data + # ... + # Retrieve data + var error = json.parse(json_string) + if error == OK: + var data_received = json.get_data() + if typeof(data_received) == TYPE_ARRAY: + print(data_received) # Prints array + else: + print("Unexpected data") + else: + print("JSON Parse Error: ", json.get_error_message(), " in ", json_string, " at line ", json.get_error_line()) + [/codeblock] </description> <tutorials> </tutorials> <methods> + <method name="get_data" qualifiers="const"> + <return type="Variant"> + </return> + <description> + Returns the [Variant] containing the data of a successful [method parse]. + [b]Note:[/b] It will return [code]Null[/code] if the last call to parse was unsuccessful or [method parse] has not yet been called. + </description> + </method> + <method name="get_error_line" qualifiers="const"> + <return type="int"> + </return> + <description> + Returns [code]0[/code] if the last call to [method parse] was successful, or the line number where the parse failed. + </description> + </method> + <method name="get_error_message" qualifiers="const"> + <return type="String"> + </return> + <description> + Returns an empty string if the last call to [method parse] was successful, or the error message if it failed. + </description> + </method> <method name="parse"> - <return type="JSONParseResult"> + <return type="int" enum="Error"> </return> - <argument index="0" name="json" type="String"> + <argument index="0" name="json_string" type="String"> </argument> <description> - Parses a JSON-encoded string and returns a [JSONParseResult] containing the result. + Attempts to parse the [code]json_string[/code] provided. + Returns an [enum Error]. If the parse was successful, it returns [code]OK[/code] and the result can be retrieved using [method get_data]. If unsuccessful, use [method get_error_line] and [method get_error_message] for identifying the source of the failure. </description> </method> - <method name="print"> + <method name="stringify"> <return type="String"> </return> - <argument index="0" name="value" type="Variant"> + <argument index="0" name="data" type="Variant"> </argument> <argument index="1" name="indent" type="String" default=""""> </argument> - <argument index="2" name="sort_keys" type="bool" default="false"> + <argument index="2" name="sort_keys" type="bool" default="true"> </argument> <argument index="3" name="full_precision" type="bool" default="false"> </argument> <description> Converts a [Variant] var to JSON text and returns the result. Useful for serializing data to store or send over the network. [b]Note:[/b] The JSON specification does not define integer or float types, but only a [i]number[/i] type. Therefore, converting a Variant to JSON text will convert all numerical values to [float] types. - [b]Note:[/b] If [code]full_precision[/code] is true, when printing floats, the unreliable digits are printed in addition to the reliable digits to guarantee exact decoding. - Use [code]indent[/code] parameter to pretty print the output. + [b]Note:[/b] If [code]full_precision[/code] is true, when stringifying floats, the unreliable digits are stringified in addition to the reliable digits to guarantee exact decoding. + Use [code]indent[/code] parameter to pretty stringify the output. [b]Example output:[/b] [codeblock] - ## JSON.print(my_dictionary) + ## JSON.stringify(my_dictionary) {"name":"my_dictionary","version":"1.0.0","entities":[{"name":"entity_0","value":"value_0"},{"name":"entity_1","value":"value_1"}]} - ## JSON.print(my_dictionary, "\t") + ## JSON.stringify(my_dictionary, "\t") { "name": "my_dictionary", "version": "1.0.0", diff --git a/doc/classes/JSONParseResult.xml b/doc/classes/JSONParseResult.xml deleted file mode 100644 index 7311343b68..0000000000 --- a/doc/classes/JSONParseResult.xml +++ /dev/null @@ -1,51 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<class name="JSONParseResult" inherits="RefCounted" version="4.0"> - <brief_description> - Data class wrapper for decoded JSON. - </brief_description> - <description> - Returned by [method JSON.parse], [JSONParseResult] contains the decoded JSON or error information if the JSON source wasn't successfully parsed. You can check if the JSON source was successfully parsed with [code]if json_result.error == OK[/code]. - </description> - <tutorials> - </tutorials> - <methods> - </methods> - <members> - <member name="error" type="int" setter="set_error" getter="get_error" enum="Error"> - The error type if the JSON source was not successfully parsed. See the [enum Error] constants. - </member> - <member name="error_line" type="int" setter="set_error_line" getter="get_error_line" default="-1"> - The line number where the error occurred if the JSON source was not successfully parsed. - </member> - <member name="error_string" type="String" setter="set_error_string" getter="get_error_string" default=""""> - The error message if the JSON source was not successfully parsed. See the [enum Error] constants. - </member> - <member name="result" type="Variant" setter="set_result" getter="get_result"> - A [Variant] containing the parsed JSON. Use [method @GlobalScope.typeof] or the [code]is[/code] keyword to check if it is what you expect. For example, if the JSON source starts with curly braces ([code]{}[/code]), a [Dictionary] will be returned. If the JSON source starts with brackets ([code][][/code]), an [Array] will be returned. - [b]Note:[/b] The JSON specification does not define integer or float types, but only a [i]number[/i] type. Therefore, parsing a JSON text will convert all numerical values to [float] types. - [b]Note:[/b] JSON objects do not preserve key order like Godot dictionaries, thus, you should not rely on keys being in a certain order if a dictionary is constructed from JSON. In contrast, JSON arrays retain the order of their elements: - [codeblocks] - [gdscript] - var p = JSON.parse('["hello", "world", "!"]') - if typeof(p.result) == TYPE_ARRAY: - print(p.result[0]) # Prints "hello" - else: - push_error("Unexpected results.") - [/gdscript] - [csharp] - JSONParseResult p = JSON.Parse("[\"hello\"], \"world\", \"!\"]"); - if (p.Result is Godot.Collections.Array) - { - GD.Print((p.Result as Godot.Collections.Array)[0]); // Prints "hello" - } - else - { - GD.PushError("Unexpected results."); - } - [/csharp] - [/codeblocks] - </member> - </members> - <constants> - </constants> -</class> diff --git a/doc/classes/JSONParser.xml b/doc/classes/JSONParser.xml deleted file mode 100644 index 991629f255..0000000000 --- a/doc/classes/JSONParser.xml +++ /dev/null @@ -1,57 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<class name="JSONParser" inherits="RefCounted" version="4.0"> - <brief_description> - </brief_description> - <description> - </description> - <tutorials> - </tutorials> - <methods> - <method name="decode_data"> - <return type="int" enum="Error"> - </return> - <argument index="0" name="data" type="Variant"> - </argument> - <argument index="1" name="indent" type="String" default=""""> - </argument> - <argument index="2" name="sort_keys" type="bool" default="true"> - </argument> - <description> - </description> - </method> - <method name="get_data" qualifiers="const"> - <return type="Variant"> - </return> - <description> - </description> - </method> - <method name="get_error_line" qualifiers="const"> - <return type="int"> - </return> - <description> - </description> - </method> - <method name="get_error_text" qualifiers="const"> - <return type="String"> - </return> - <description> - </description> - </method> - <method name="get_string" qualifiers="const"> - <return type="String"> - </return> - <description> - </description> - </method> - <method name="parse_string"> - <return type="int" enum="Error"> - </return> - <argument index="0" name="json_string" type="String"> - </argument> - <description> - </description> - </method> - </methods> - <constants> - </constants> -</class> diff --git a/doc/classes/Label.xml b/doc/classes/Label.xml index ee59f0c85a..0789ac9010 100644 --- a/doc/classes/Label.xml +++ b/doc/classes/Label.xml @@ -79,7 +79,7 @@ If [code]true[/code], wraps the text inside the node's bounding rectangle. If you resize the node, it will change its height automatically to show all the text. </member> <member name="clip_text" type="bool" setter="set_clip_text" getter="is_clipping_text" default="false"> - If [code]true[/code], the Label only shows the text that fits inside its bounding rectangle. It also lets you scale the node down freely. + If [code]true[/code], the Label only shows the text that fits inside its bounding rectangle and will clip text horizontally. </member> <member name="language" type="String" setter="set_language" getter="get_language" default=""""> Language code used for line-breaking and text shaping algorithms, if left empty current locale is used instead. diff --git a/doc/classes/Light3D.xml b/doc/classes/Light3D.xml index 84abf57cb6..815d20223d 100644 --- a/doc/classes/Light3D.xml +++ b/doc/classes/Light3D.xml @@ -4,7 +4,7 @@ Provides a base class for different kinds of light nodes. </brief_description> <description> - Light3D is the [i]abstract[/i] base class for light nodes. As it can't be instanced, it shouldn't be used directly. Other types of light nodes inherit from it. Light3D contains the common variables and parameters used for lighting. + Light3D is the [i]abstract[/i] base class for light nodes. As it can't be instantiated, it shouldn't be used directly. Other types of light nodes inherit from it. Light3D contains the common variables and parameters used for lighting. </description> <tutorials> <link title="3D lights and shadows">https://docs.godotengine.org/en/latest/tutorials/3d/lights_and_shadows.html</link> diff --git a/doc/classes/LineEdit.xml b/doc/classes/LineEdit.xml index f1e7c5f6e1..773f7b1a02 100644 --- a/doc/classes/LineEdit.xml +++ b/doc/classes/LineEdit.xml @@ -169,6 +169,7 @@ The caret's column position inside the [LineEdit]. When set, the text may scroll to accommodate it. </member> <member name="caret_force_displayed" type="bool" setter="set_caret_force_displayed" getter="is_caret_force_displayed" default="false"> + If [code]true[/code], the [LineEdit] will always show the caret, even if focus is lost. </member> <member name="caret_mid_grapheme" type="bool" setter="set_caret_mid_grapheme_enabled" getter="is_caret_mid_grapheme_enabled" default="false"> Allow moving caret, selecting and removing the individual composite character components. @@ -195,6 +196,28 @@ </member> <member name="max_length" type="int" setter="set_max_length" getter="get_max_length" default="0"> Maximum amount of characters that can be entered inside the [LineEdit]. If [code]0[/code], there is no limit. + When a limit is defined, characters that would exceed [member max_length] are truncated. This happens both for existing [member text] contents when setting the max length, or for new text inserted in the [LineEdit], including pasting. If any input text is truncated, the [signal text_change_rejected] signal is emitted with the truncated substring as parameter. + [b]Example:[/b] + [codeblocks] + [gdscript] + text = "Hello world" + max_length = 5 + # `text` becomes "Hello". + max_length = 10 + text += " goodbye" + # `text` becomes "Hello good". + # `text_change_rejected` is emitted with "bye" as parameter. + [/gdscript] + [csharp] + Text = "Hello world"; + MaxLength = 5; + // `Text` becomes "Hello". + MaxLength = 10; + Text += " goodbye"; + // `Text` becomes "Hello good". + // `text_change_rejected` is emitted with "bye" as parameter. + [/csharp] + [/codeblocks] </member> <member name="mouse_default_cursor_shape" type="int" setter="set_default_cursor_shape" getter="get_default_cursor_shape" override="true" enum="Control.CursorShape" default="1" /> <member name="placeholder_alpha" type="float" setter="set_placeholder_alpha" getter="get_placeholder_alpha" default="0.6"> @@ -237,8 +260,10 @@ </members> <signals> <signal name="text_change_rejected"> + <argument index="0" name="rejected_substring" type="String"> + </argument> <description> - Emitted when trying to append text that would overflow the [member max_length]. + Emitted when appending text that overflows the [member max_length]. The appended text is truncated to fit [member max_length], and the part that couldn't fit is passed as the [code]rejected_substring[/code] argument. </description> </signal> <signal name="text_changed"> diff --git a/doc/classes/MeshDataTool.xml b/doc/classes/MeshDataTool.xml index da02511dc0..c0ee1e1956 100644 --- a/doc/classes/MeshDataTool.xml +++ b/doc/classes/MeshDataTool.xml @@ -45,7 +45,7 @@ AddChild(mi); [/csharp] [/codeblocks] - See also [ArrayMesh], [ImmediateGeometry3D] and [SurfaceTool] for procedural geometry generation. + See also [ArrayMesh], [ImmediateMesh] and [SurfaceTool] for procedural geometry generation. [b]Note:[/b] Godot uses clockwise [url=https://learnopengl.com/Advanced-OpenGL/Face-culling]winding order[/url] for front faces of triangle primitive modes. </description> <tutorials> diff --git a/doc/classes/MeshInstance3D.xml b/doc/classes/MeshInstance3D.xml index b5ab296bd0..7c4e75793e 100644 --- a/doc/classes/MeshInstance3D.xml +++ b/doc/classes/MeshInstance3D.xml @@ -4,7 +4,7 @@ Node that instances meshes into a scenario. </brief_description> <description> - MeshInstance3D is a node that takes a [Mesh] resource and adds it to the current scenario by creating an instance of it. This is the class most often used render 3D geometry and can be used to instance a single [Mesh] in many places. This allows reuse of geometry which can save on resources. When a [Mesh] has to be instanced more than thousands of times at close proximity, consider using a [MultiMesh] in a [MultiMeshInstance3D] instead. + MeshInstance3D is a node that takes a [Mesh] resource and adds it to the current scenario by creating an instance of it. This is the class most often used render 3D geometry and can be used to instance a single [Mesh] in many places. This allows reuse of geometry which can save on resources. When a [Mesh] has to be instantiated more than thousands of times at close proximity, consider using a [MultiMesh] in a [MultiMeshInstance3D] instead. </description> <tutorials> <link title="3D Material Testers Demo">https://godotengine.org/asset-library/asset/123</link> diff --git a/doc/classes/MethodTweener.xml b/doc/classes/MethodTweener.xml new file mode 100644 index 0000000000..42b91abf93 --- /dev/null +++ b/doc/classes/MethodTweener.xml @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="MethodTweener" inherits="Tweener" version="4.0"> + <brief_description> + Interpolates an abstract value and supplies it to a method called over time. + </brief_description> + <description> + [MethodTweener] is similar to a combination of [CallbackTweener] and [PropertyTweener]. It calls a method providing an interpolated value as a paramater. See [method Tween.tween_method] for more usage information. + [b]Note:[/b] [method Tween.tween_method] is the only correct way to create [MethodTweener]. Any [MethodTweener] created manually will not function correctly. + </description> + <tutorials> + </tutorials> + <methods> + <method name="set_delay"> + <return type="MethodTweener"> + </return> + <argument index="0" name="delay" type="float"> + </argument> + <description> + Sets the time in seconds after which the [MethodTweener] will start interpolating. By default there's no delay. + </description> + </method> + <method name="set_ease"> + <return type="MethodTweener"> + </return> + <argument index="0" name="ease" type="int" enum="Tween.EaseType"> + </argument> + <description> + Sets the type of used easing from [enum Tween.EaseType]. If not set, the default easing is used from the [Tween] that contains this Tweener. + </description> + </method> + <method name="set_trans"> + <return type="MethodTweener"> + </return> + <argument index="0" name="trans" type="int" enum="Tween.TransitionType"> + </argument> + <description> + Sets the type of used transition from [enum Tween.TransitionType]. If not set, the default transition is used from the [Tween] that contains this Tweener. + </description> + </method> + </methods> + <constants> + </constants> +</class> diff --git a/doc/classes/MultiplayerAPI.xml b/doc/classes/MultiplayerAPI.xml index 5de5703d95..c4d8a5b1b9 100644 --- a/doc/classes/MultiplayerAPI.xml +++ b/doc/classes/MultiplayerAPI.xml @@ -4,7 +4,7 @@ High-level multiplayer API. </brief_description> <description> - This class implements most of the logic behind the high-level multiplayer API. See also [NetworkedMultiplayerPeer]. + This class implements most of the logic behind the high-level multiplayer API. See also [MultiplayerPeer]. By default, [SceneTree] has a reference to this class that is used to provide multiplayer capabilities (i.e. RPC/RSET) across the whole scene. It is possible to override the MultiplayerAPI instance used by specific Nodes by setting the [member Node.custom_multiplayer] property, effectively allowing to run both client and server in the same scene. [b]Note:[/b] The high-level multiplayer API protocol is an implementation detail and isn't meant to be used by non-Godot servers. It may change without notice. @@ -70,10 +70,10 @@ </argument> <argument index="1" name="id" type="int" default="0"> </argument> - <argument index="2" name="mode" type="int" enum="NetworkedMultiplayerPeer.TransferMode" default="2"> + <argument index="2" name="mode" type="int" enum="MultiplayerPeer.TransferMode" default="2"> </argument> <description> - Sends the given raw [code]bytes[/code] to a specific peer identified by [code]id[/code] (see [method NetworkedMultiplayerPeer.set_target_peer]). Default ID is [code]0[/code], i.e. broadcast to all peers. + Sends the given raw [code]bytes[/code] to a specific peer identified by [code]id[/code] (see [method MultiplayerPeer.set_target_peer]). Default ID is [code]0[/code], i.e. broadcast to all peers. </description> </method> </methods> @@ -82,7 +82,7 @@ If [code]true[/code], the MultiplayerAPI will allow encoding and decoding of object during RPCs/RSETs. [b]Warning:[/b] Deserialized objects can contain code which gets executed. Do not use this option if the serialized object comes from untrusted sources to avoid potential security threats such as remote code execution. </member> - <member name="network_peer" type="NetworkedMultiplayerPeer" setter="set_network_peer" getter="get_network_peer"> + <member name="network_peer" type="MultiplayerPeer" setter="set_network_peer" getter="get_network_peer"> The peer object to handle the RPC system (effectively enabling networking when set). Depending on the peer itself, the MultiplayerAPI will become a network server (check with [method is_network_server]) and will set root node's network mode to master, or it will become a regular peer with root node set to puppet. All child nodes are set to inherit the network mode by default. Handling of networking-related events (connection, disconnection, new clients) is done by connecting to MultiplayerAPI's signals. </member> <member name="refuse_new_network_connections" type="bool" setter="set_refuse_new_network_connections" getter="is_refusing_new_network_connections" default="false"> diff --git a/doc/classes/NetworkedMultiplayerPeer.xml b/doc/classes/MultiplayerPeer.xml index 06ea46f023..713cd64b82 100644 --- a/doc/classes/NetworkedMultiplayerPeer.xml +++ b/doc/classes/MultiplayerPeer.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8" ?> -<class name="NetworkedMultiplayerPeer" inherits="PacketPeer" version="4.0"> +<class name="MultiplayerPeer" inherits="PacketPeer" version="4.0"> <brief_description> A high-level network interface to simplify multiplayer interactions. </brief_description> @@ -13,7 +13,7 @@ </tutorials> <methods> <method name="get_connection_status" qualifiers="const"> - <return type="int" enum="NetworkedMultiplayerPeer.ConnectionStatus"> + <return type="int" enum="MultiplayerPeer.ConnectionStatus"> </return> <description> Returns the current state of the connection. See [enum ConnectionStatus]. @@ -23,14 +23,14 @@ <return type="int"> </return> <description> - Returns the ID of the [NetworkedMultiplayerPeer] who sent the most recent packet. + Returns the ID of the [MultiplayerPeer] who sent the most recent packet. </description> </method> <method name="get_unique_id" qualifiers="const"> <return type="int"> </return> <description> - Returns the ID of this [NetworkedMultiplayerPeer]. + Returns the ID of this [MultiplayerPeer]. </description> </method> <method name="poll"> @@ -53,9 +53,9 @@ </methods> <members> <member name="refuse_new_connections" type="bool" setter="set_refuse_new_connections" getter="is_refusing_new_connections" default="true"> - If [code]true[/code], this [NetworkedMultiplayerPeer] refuses new connections. + If [code]true[/code], this [MultiplayerPeer] refuses new connections. </member> - <member name="transfer_mode" type="int" setter="set_transfer_mode" getter="get_transfer_mode" enum="NetworkedMultiplayerPeer.TransferMode" default="0"> + <member name="transfer_mode" type="int" setter="set_transfer_mode" getter="get_transfer_mode" enum="MultiplayerPeer.TransferMode" default="0"> The manner in which to send packets to the [code]target_peer[/code]. See [enum TransferMode]. </member> </members> diff --git a/doc/classes/NativeExtension.xml b/doc/classes/NativeExtension.xml new file mode 100644 index 0000000000..c48af7df7b --- /dev/null +++ b/doc/classes/NativeExtension.xml @@ -0,0 +1,57 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="NativeExtension" inherits="RefCounted" version="4.0"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <methods> + <method name="close_library"> + <return type="void"> + </return> + <description> + </description> + </method> + <method name="get_minimum_library_initialization_level" qualifiers="const"> + <return type="int" enum="NativeExtension.InitializationLevel"> + </return> + <description> + </description> + </method> + <method name="initialize_library"> + <return type="void"> + </return> + <argument index="0" name="level" type="int" enum="NativeExtension.InitializationLevel"> + </argument> + <description> + </description> + </method> + <method name="is_library_open" qualifiers="const"> + <return type="bool"> + </return> + <description> + </description> + </method> + <method name="open_library"> + <return type="int" enum="Error"> + </return> + <argument index="0" name="path" type="String"> + </argument> + <argument index="1" name="entry_symbol" type="String"> + </argument> + <description> + </description> + </method> + </methods> + <constants> + <constant name="INITIALIZATION_LEVEL_CORE" value="0" enum="InitializationLevel"> + </constant> + <constant name="INITIALIZATION_LEVEL_SERVERS" value="1" enum="InitializationLevel"> + </constant> + <constant name="INITIALIZATION_LEVEL_SCENE" value="2" enum="InitializationLevel"> + </constant> + <constant name="INITIALIZATION_LEVEL_EDITOR" value="3" enum="InitializationLevel"> + </constant> + </constants> +</class> diff --git a/doc/classes/NativeExtensionManager.xml b/doc/classes/NativeExtensionManager.xml new file mode 100644 index 0000000000..ba9018ff4c --- /dev/null +++ b/doc/classes/NativeExtensionManager.xml @@ -0,0 +1,61 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="NativeExtensionManager" inherits="Object" version="4.0"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <methods> + <method name="get_extension"> + <return type="NativeExtension"> + </return> + <argument index="0" name="path" type="String"> + </argument> + <description> + </description> + </method> + <method name="get_loaded_extensions" qualifiers="const"> + <return type="PackedStringArray"> + </return> + <description> + </description> + </method> + <method name="load_extension"> + <return type="int" enum="NativeExtensionManager.LoadStatus"> + </return> + <argument index="0" name="path" type="String"> + </argument> + <description> + </description> + </method> + <method name="reload_extension"> + <return type="int" enum="NativeExtensionManager.LoadStatus"> + </return> + <argument index="0" name="path" type="String"> + </argument> + <description> + </description> + </method> + <method name="unload_extension"> + <return type="int" enum="NativeExtensionManager.LoadStatus"> + </return> + <argument index="0" name="path" type="String"> + </argument> + <description> + </description> + </method> + </methods> + <constants> + <constant name="LOAD_STATUS_OK" value="0" enum="LoadStatus"> + </constant> + <constant name="LOAD_STATUS_FAILED" value="1" enum="LoadStatus"> + </constant> + <constant name="LOAD_STATUS_ALREADY_LOADED" value="2" enum="LoadStatus"> + </constant> + <constant name="LOAD_STATUS_NOT_LOADED" value="3" enum="LoadStatus"> + </constant> + <constant name="LOAD_STATUS_NEEDS_RESTART" value="4" enum="LoadStatus"> + </constant> + </constants> +</class> diff --git a/doc/classes/Node.xml b/doc/classes/Node.xml index a9c38e4d06..fc971effd7 100644 --- a/doc/classes/Node.xml +++ b/doc/classes/Node.xml @@ -5,16 +5,16 @@ </brief_description> <description> Nodes are Godot's building blocks. They can be assigned as the child of another node, resulting in a tree arrangement. A given node can contain any number of nodes as children with the requirement that all siblings (direct children of a node) should have unique names. - A tree of nodes is called a [i]scene[/i]. Scenes can be saved to the disk and then instanced into other scenes. This allows for very high flexibility in the architecture and data model of Godot projects. + A tree of nodes is called a [i]scene[/i]. Scenes can be saved to the disk and then instantiated into other scenes. This allows for very high flexibility in the architecture and data model of Godot projects. [b]Scene tree:[/b] The [SceneTree] contains the active tree of nodes. When a node is added to the scene tree, it receives the [constant NOTIFICATION_ENTER_TREE] notification and its [method _enter_tree] callback is triggered. Child nodes are always added [i]after[/i] their parent node, i.e. the [method _enter_tree] callback of a parent node will be triggered before its child's. Once all nodes have been added in the scene tree, they receive the [constant NOTIFICATION_READY] notification and their respective [method _ready] callbacks are triggered. For groups of nodes, the [method _ready] callback is called in reverse order, starting with the children and moving up to the parent nodes. This means that when adding a node to the scene tree, the following order will be used for the callbacks: [method _enter_tree] of the parent, [method _enter_tree] of the children, [method _ready] of the children and finally [method _ready] of the parent (recursively for the entire scene tree). [b]Processing:[/b] Nodes can override the "process" state, so that they receive a callback on each frame requesting them to process (do something). Normal processing (callback [method _process], toggled with [method set_process]) happens as fast as possible and is dependent on the frame rate, so the processing time [i]delta[/i] (in seconds) is passed as an argument. Physics processing (callback [method _physics_process], toggled with [method set_physics_process]) happens a fixed number of times per second (60 by default) and is useful for code related to the physics engine. Nodes can also process input events. When present, the [method _input] function will be called for each input that the program receives. In many cases, this can be overkill (unless used for simple projects), and the [method _unhandled_input] function might be preferred; it is called when the input event was not handled by anyone else (typically, GUI [Control] nodes), ensuring that the node only receives the events that were meant for it. - To keep track of the scene hierarchy (especially when instancing scenes into other scenes), an "owner" can be set for the node with the [member owner] property. This keeps track of who instanced what. This is mostly useful when writing editors and tools, though. + To keep track of the scene hierarchy (especially when instancing scenes into other scenes), an "owner" can be set for the node with the [member owner] property. This keeps track of who instantiated what. This is mostly useful when writing editors and tools, though. Finally, when a node is freed with [method Object.free] or [method queue_free], it will also free all its children. [b]Groups:[/b] Nodes can be added to as many groups as you want to be easy to manage, you could create groups like "enemies" or "collectables" for example, depending on your game. See [method add_to_group], [method is_in_group] and [method remove_from_group]. You can then retrieve all nodes in these groups, iterate them and even call methods on groups via the methods on [SceneTree]. - [b]Networking with nodes:[/b] After connecting to a server (or making one, see [NetworkedMultiplayerENet]), it is possible to use the built-in RPC (remote procedure call) system to communicate over the network. By calling [method rpc] with a method name, it will be called locally and in all connected peers (peers = clients and the server that accepts connections). To identify which node receives the RPC call, Godot will use its [NodePath] (make sure node names are the same on all peers). Also, take a look at the high-level networking tutorial and corresponding demos. + [b]Networking with nodes:[/b] After connecting to a server (or making one, see [ENetMultiplayerPeer]), it is possible to use the built-in RPC (remote procedure call) system to communicate over the network. By calling [method rpc] with a method name, it will be called locally and in all connected peers (peers = clients and the server that accepts connections). To identify which node receives the RPC call, Godot will use its [NodePath] (make sure node names are the same on all peers). Also, take a look at the high-level networking tutorial and corresponding demos. </description> <tutorials> <link title="Scenes and nodes">https://docs.godotengine.org/en/latest/getting_started/step_by_step/scenes_and_nodes.html</link> @@ -128,7 +128,7 @@ </argument> <description> Adds a child node. Nodes can have any number of children, but every child must have a unique name. Child nodes are automatically deleted when the parent node is deleted, so an entire scene can be removed by deleting its topmost node. - If [code]legible_unique_name[/code] is [code]true[/code], the child node will have a human-readable name based on the name of the node being instanced instead of its type. + If [code]legible_unique_name[/code] is [code]true[/code], the child node will have a human-readable name based on the name of the node being instantiated instead of its type. [b]Note:[/b] If the child node already has a parent, the function will fail. Use [method remove_child] first to remove the node from its current parent. For example: [codeblocks] [gdscript] @@ -159,7 +159,7 @@ </argument> <description> Adds a [code]sibling[/code] node to current's node parent, at the same level as that node, right below it. - If [code]legible_unique_name[/code] is [code]true[/code], the child node will have a human-readable name based on the name of the node being instanced instead of its type. + If [code]legible_unique_name[/code] is [code]true[/code], the child node will have a human-readable name based on the name of the node being instantiated instead of its type. Use [method add_child] instead of this method if you don't need the child node to be added below a specific node in the list of children. </description> </method> @@ -182,6 +182,16 @@ Returns [code]true[/code] if the node can process while the scene tree is paused (see [member process_mode]). Always returns [code]true[/code] if the scene tree is not paused, and [code]false[/code] if the node is not in the tree. </description> </method> + <method name="create_tween"> + <return type="Tween"> + </return> + <description> + Creates a new [Tween] and binds it to this node. This is equivalent of doing: + [codeblock] + get_tree().create_tween().bind_node(self) + [/codeblock] + </description> + </method> <method name="duplicate" qualifiers="const"> <return type="Node"> </return> @@ -416,7 +426,7 @@ Returns [code]true[/code] if the [NodePath] points to a valid node and its subname points to a valid resource, e.g. [code]Area2D/CollisionShape2D:shape[/code]. Properties with a non-[Resource] type (e.g. nodes or primitive math types) are not considered resources. </description> </method> - <method name="is_a_parent_of" qualifiers="const"> + <method name="is_ancestor_of" qualifiers="const"> <return type="bool"> </return> <argument index="0" name="node" type="Node"> @@ -650,7 +660,7 @@ </argument> <description> Sends a remote procedure call request for the given [code]method[/code] to peers on the network (and locally), optionally sending all additional arguments as arguments to the method called by the RPC. The call request will only be received by nodes with the same [NodePath], including the exact same node name. Behaviour depends on the RPC configuration for the given method, see [method rpc_config]. Methods are not exposed to RPCs by default. Returns an empty [Variant]. - [b]Note:[/b] You can only safely use RPCs on clients after you received the [code]connected_to_server[/code] signal from the [SceneTree]. You also need to keep track of the connection state, either by the [SceneTree] signals like [code]server_disconnected[/code] or by checking [code]SceneTree.network_peer.get_connection_status() == CONNECTION_CONNECTED[/code]. + [b]Note:[/b] You can only safely use RPCs on clients after you received the [code]connected_to_server[/code] signal from the [MultiplayerAPI]. You also need to keep track of the connection state, either by the [MultiplayerAPI] signals like [code]server_disconnected[/code] or by checking [code]get_multiplayer().network_peer.get_connection_status() == CONNECTION_CONNECTED[/code]. </description> </method> <method name="rpc_config"> @@ -660,12 +670,12 @@ </argument> <argument index="1" name="rpc_mode" type="int" enum="MultiplayerAPI.RPCMode"> </argument> - <argument index="2" name="transfer_mode" type="int" enum="NetworkedMultiplayerPeer.TransferMode" default="2"> + <argument index="2" name="transfer_mode" type="int" enum="MultiplayerPeer.TransferMode" default="2"> </argument> <argument index="3" name="channel" type="int" default="0"> </argument> <description> - Changes the RPC mode for the given [code]method[/code] to the given [code]rpc_mode[/code], optionally specifying the [code]transfer_mode[/code] and [code]channel[/code] (on supported peers). See [enum MultiplayerAPI.RPCMode] and [enum NetworkedMultiplayerPeer.TransferMode]. An alternative is annotating methods and properties with the corresponding keywords ([code]remote[/code], [code]master[/code], [code]puppet[/code], [code]remotesync[/code], [code]mastersync[/code], [code]puppetsync[/code]). By default, methods are not exposed to networking (and RPCs). + Changes the RPC mode for the given [code]method[/code] to the given [code]rpc_mode[/code], optionally specifying the [code]transfer_mode[/code] and [code]channel[/code] (on supported peers). See [enum MultiplayerAPI.RPCMode] and [enum MultiplayerPeer.TransferMode]. An alternative is annotating methods and properties with the corresponding keywords ([code]remote[/code], [code]master[/code], [code]puppet[/code], [code]remotesync[/code], [code]mastersync[/code], [code]puppetsync[/code]). By default, methods are not exposed to networking (and RPCs). </description> </method> <method name="rpc_id" qualifiers="vararg"> @@ -676,7 +686,7 @@ <argument index="1" name="method" type="StringName"> </argument> <description> - Sends a [method rpc] to a specific peer identified by [code]peer_id[/code] (see [method NetworkedMultiplayerPeer.set_target_peer]). Returns an empty [Variant]. + Sends a [method rpc] to a specific peer identified by [code]peer_id[/code] (see [method MultiplayerPeer.set_target_peer]). Returns an empty [Variant]. </description> </method> <method name="set_display_folded"> @@ -795,7 +805,7 @@ The override to the default [MultiplayerAPI]. Set to [code]null[/code] to use the default [SceneTree] one. </member> <member name="filename" type="String" setter="set_filename" getter="get_filename"> - When a scene is instanced from a file, its topmost node contains the filename from which it was loaded. + When a scene is instantiated from a file, its topmost node contains the filename from which it was loaded. </member> <member name="multiplayer" type="MultiplayerAPI" setter="" getter="get_multiplayer"> The [MultiplayerAPI] instance associated with this node. Either the [member custom_multiplayer], or the default SceneTree one (if inside tree). @@ -874,7 +884,7 @@ Notification received when a node is unparented (parent removed it from the list of children). </constant> <constant name="NOTIFICATION_INSTANCED" value="20"> - Notification received when the node is instanced. + Notification received when the node is instantiated. </constant> <constant name="NOTIFICATION_DRAG_BEGIN" value="21"> Notification received when a drag begins. @@ -894,6 +904,12 @@ <constant name="NOTIFICATION_POST_ENTER_TREE" value="27"> Notification received when the node is ready, just before [constant NOTIFICATION_READY] is received. Unlike the latter, it's sent every time the node enters tree, instead of only once. </constant> + <constant name="NOTIFICATION_DISABLED" value="28"> + Notification received when the node is disabled. See [constant PROCESS_MODE_DISABLED]. + </constant> + <constant name="NOTIFICATION_ENABLED" value="29"> + Notification received when the node is enabled again after being disabled. See [constant PROCESS_MODE_DISABLED]. + </constant> <constant name="NOTIFICATION_EDITOR_PRE_SAVE" value="9001"> Notification received right before the scene with the node is saved in the editor. This notification is only sent in the Godot editor and will not occur in exported projects. </constant> diff --git a/doc/classes/Node2D.xml b/doc/classes/Node2D.xml index cc99abf9cb..9ffa333f17 100644 --- a/doc/classes/Node2D.xml +++ b/doc/classes/Node2D.xml @@ -122,9 +122,6 @@ <member name="global_rotation" type="float" setter="set_global_rotation" getter="get_global_rotation"> Global rotation in radians. </member> - <member name="global_rotation_degrees" type="float" setter="set_global_rotation_degrees" getter="get_global_rotation_degrees"> - Global rotation in degrees. - </member> <member name="global_scale" type="Vector2" setter="set_global_scale" getter="get_global_scale"> Global scale. </member> @@ -137,16 +134,11 @@ <member name="rotation" type="float" setter="set_rotation" getter="get_rotation" default="0.0"> Rotation in radians, relative to the node's parent. </member> - <member name="rotation_degrees" type="float" setter="set_rotation_degrees" getter="get_rotation_degrees" default="0.0"> - Rotation in degrees, relative to the node's parent. - </member> <member name="scale" type="Vector2" setter="set_scale" getter="get_scale" default="Vector2(1, 1)"> The node's scale. Unscaled value: [code](1, 1)[/code]. </member> <member name="skew" type="float" setter="set_skew" getter="get_skew" default="0.0"> </member> - <member name="skew_degrees" type="float" setter="set_skew_degrees" getter="get_skew_degrees" default="0.0"> - </member> <member name="transform" type="Transform2D" setter="set_transform" getter="get_transform"> Local [Transform2D]. </member> diff --git a/doc/classes/Node3D.xml b/doc/classes/Node3D.xml index 2dc8659d5d..14e03a2186 100644 --- a/doc/classes/Node3D.xml +++ b/doc/classes/Node3D.xml @@ -294,13 +294,10 @@ <member name="position" type="Vector3" setter="set_position" getter="get_position" default="Vector3(0, 0, 0)"> Local position or translation of this node relative to the parent. This is equivalent to [code]transform.origin[/code]. </member> - <member name="rotation" type="Vector3" setter="set_rotation" getter="get_rotation"> + <member name="rotation" type="Vector3" setter="set_rotation" getter="get_rotation" default="Vector3(0, 0, 0)"> Rotation part of the local transformation in radians, specified in terms of YXZ-Euler angles in the format (X angle, Y angle, Z angle). [b]Note:[/b] In the mathematical sense, rotation is a matrix and not a vector. The three Euler angles, which are the three independent parameters of the Euler-angle parametrization of the rotation matrix, are stored in a [Vector3] data structure not because the rotation is a vector, but only because [Vector3] exists as a convenient data-structure to store 3 floating-point numbers. Therefore, applying affine operations on the rotation "vector" is not meaningful. </member> - <member name="rotation_degrees" type="Vector3" setter="set_rotation_degrees" getter="get_rotation_degrees" default="Vector3(0, 0, 0)"> - Rotation part of the local transformation in degrees, specified in terms of YXZ-Euler angles in the format (X angle, Y angle, Z angle). - </member> <member name="scale" type="Vector3" setter="set_scale" getter="get_scale" default="Vector3(1, 1, 1)"> Scale part of the local transformation. </member> diff --git a/doc/classes/NodePath.xml b/doc/classes/NodePath.xml index 817ccd5160..0ba2e73ad4 100644 --- a/doc/classes/NodePath.xml +++ b/doc/classes/NodePath.xml @@ -20,6 +20,7 @@ @"/root/Main" # If your main scene's root node were named "Main". @"/root/MyAutoload" # If you have an autoloaded node or scene. [/codeblock] + [b]Note:[/b] In the editor, [NodePath] properties are automatically updated when moving, renaming or deleting a node in the scene tree, but they are never updated at runtime. </description> <tutorials> <link title="2D Role Playing Game Demo">https://godotengine.org/asset-library/asset/520</link> diff --git a/doc/classes/OS.xml b/doc/classes/OS.xml index 0789a7d231..a9396306f4 100644 --- a/doc/classes/OS.xml +++ b/doc/classes/OS.xml @@ -136,6 +136,14 @@ Returns the keycode of the given string (e.g. "Escape"). </description> </method> + <method name="get_cache_dir" qualifiers="const"> + <return type="String"> + </return> + <description> + Returns the [i]global[/i] cache data directory according to the operating system's standards. On desktop platforms, this path can be overridden by setting the [code]XDG_CACHE_HOME[/code] environment variable before starting the project. See [url=https://docs.godotengine.org/en/latest/tutorials/io/data_paths.html]File paths in Godot projects[/url] in the documentation for more information. See also [method get_config_dir] and [method get_data_dir]. + Not to be confused with [method get_user_data_dir], which returns the [i]project-specific[/i] user data path. + </description> + </method> <method name="get_cmdline_args"> <return type="PackedStringArray"> </return> @@ -167,6 +175,14 @@ [/codeblocks] </description> </method> + <method name="get_config_dir" qualifiers="const"> + <return type="String"> + </return> + <description> + Returns the [i]global[/i] user configuration directory according to the operating system's standards. On desktop platforms, this path can be overridden by setting the [code]XDG_CONFIG_HOME[/code] environment variable before starting the project. See [url=https://docs.godotengine.org/en/latest/tutorials/io/data_paths.html]File paths in Godot projects[/url] in the documentation for more information. See also [method get_cache_dir] and [method get_data_dir]. + Not to be confused with [method get_user_data_dir], which returns the [i]project-specific[/i] user data path. + </description> + </method> <method name="get_connected_midi_inputs"> <return type="PackedStringArray"> </return> @@ -176,6 +192,14 @@ [b]Note:[/b] This method is implemented on Linux, macOS and Windows. </description> </method> + <method name="get_data_dir" qualifiers="const"> + <return type="String"> + </return> + <description> + Returns the [i]global[/i] user data directory according to the operating system's standards. On desktop platforms, this path can be overridden by setting the [code]XDG_DATA_HOME[/code] environment variable before starting the project. See [url=https://docs.godotengine.org/en/latest/tutorials/io/data_paths.html]File paths in Godot projects[/url] in the documentation for more information. See also [method get_cache_dir] and [method get_config_dir]. + Not to be confused with [method get_user_data_dir], which returns the [i]project-specific[/i] user data path. + </description> + </method> <method name="get_environment" qualifiers="const"> <return type="String"> </return> @@ -310,6 +334,7 @@ On macOS, this is [code]~/Library/Application Support/Godot/app_userdata/[project_name][/code], or [code]~/Library/Application Support/[custom_name][/code] if [code]use_custom_user_dir[/code] is set. On Windows, this is [code]%APPDATA%\Godot\app_userdata\[project_name][/code], or [code]%APPDATA%\[custom_name][/code] if [code]use_custom_user_dir[/code] is set. [code]%APPDATA%[/code] expands to [code]%USERPROFILE%\AppData\Roaming[/code]. If the project name is empty, [code]user://[/code] falls back to [code]res://[/code]. + Not to be confused with [method get_data_dir], which returns the [i]global[/i] (non-project-specific) user data directory. </description> </method> <method name="has_environment" qualifiers="const"> diff --git a/doc/classes/PackedScene.xml b/doc/classes/PackedScene.xml index 5887238a32..f39cae8be5 100644 --- a/doc/classes/PackedScene.xml +++ b/doc/classes/PackedScene.xml @@ -11,13 +11,13 @@ [codeblocks] [gdscript] # Use load() instead of preload() if the path isn't known at compile-time. - var scene = preload("res://scene.tscn").instance() + var scene = preload("res://scene.tscn").instantiate() # Add the node as a child of the node the script is attached to. add_child(scene) [/gdscript] [csharp] // C# has no preload, so you have to always use ResourceLoader.Load<PackedScene>(). - var scene = ResourceLoader.Load<PackedScene>("res://scene.tscn").Instance(); + var scene = ResourceLoader.Load<PackedScene>("res://scene.tscn").Instantiate(); // Add the node as a child of the node the script is attached to. AddChild(scene); [/csharp] @@ -76,7 +76,7 @@ <link title="2D Role Playing Game Demo">https://godotengine.org/asset-library/asset/520</link> </tutorials> <methods> - <method name="can_instance" qualifiers="const"> + <method name="can_instantiate" qualifiers="const"> <return type="bool"> </return> <description> @@ -90,7 +90,7 @@ Returns the [code]SceneState[/code] representing the scene file contents. </description> </method> - <method name="instance" qualifiers="const"> + <method name="instantiate" qualifiers="const"> <return type="Node"> </return> <argument index="0" name="edit_state" type="int" enum="PackedScene.GenEditState" default="0"> @@ -117,14 +117,14 @@ </members> <constants> <constant name="GEN_EDIT_STATE_DISABLED" value="0" enum="GenEditState"> - If passed to [method instance], blocks edits to the scene state. + If passed to [method instantiate], blocks edits to the scene state. </constant> <constant name="GEN_EDIT_STATE_INSTANCE" value="1" enum="GenEditState"> - If passed to [method instance], provides local scene resources to the local scene. + If passed to [method instantiate], provides local scene resources to the local scene. [b]Note:[/b] Only available in editor builds. </constant> <constant name="GEN_EDIT_STATE_MAIN" value="2" enum="GenEditState"> - If passed to [method instance], provides local scene resources to the local scene. Only the main scene should receive the main edit state. + If passed to [method instantiate], provides local scene resources to the local scene. Only the main scene should receive the main edit state. [b]Note:[/b] Only available in editor builds. </constant> </constants> diff --git a/doc/classes/Performance.xml b/doc/classes/Performance.xml index ff73844803..a141961df5 100644 --- a/doc/classes/Performance.xml +++ b/doc/classes/Performance.xml @@ -157,69 +157,53 @@ Largest amount of memory the message queue buffer has used, in bytes. The message queue is used for deferred functions calls and notifications. </constant> <constant name="OBJECT_COUNT" value="6" enum="Monitor"> - Number of objects currently instanced (including nodes). + Number of objects currently instantiated (including nodes). </constant> <constant name="OBJECT_RESOURCE_COUNT" value="7" enum="Monitor"> Number of resources currently used. </constant> <constant name="OBJECT_NODE_COUNT" value="8" enum="Monitor"> - Number of nodes currently instanced in the scene tree. This also includes the root node. + Number of nodes currently instantiated in the scene tree. This also includes the root node. </constant> <constant name="OBJECT_ORPHAN_NODE_COUNT" value="9" enum="Monitor"> Number of orphan nodes, i.e. nodes which are not parented to a node of the scene tree. </constant> - <constant name="RENDER_OBJECTS_IN_FRAME" value="10" enum="Monitor"> - 3D objects drawn per frame. + <constant name="RENDER_TOTAL_OBJECTS_IN_FRAME" value="10" enum="Monitor"> </constant> - <constant name="RENDER_VERTICES_IN_FRAME" value="11" enum="Monitor"> - Vertices drawn per frame. 3D only. + <constant name="RENDER_TOTAL_PRIMITIVES_IN_FRAME" value="11" enum="Monitor"> </constant> - <constant name="RENDER_MATERIAL_CHANGES_IN_FRAME" value="12" enum="Monitor"> - Material changes per frame. 3D only. + <constant name="RENDER_TOTAL_DRAW_CALLS_IN_FRAME" value="12" enum="Monitor"> </constant> - <constant name="RENDER_SHADER_CHANGES_IN_FRAME" value="13" enum="Monitor"> - Shader changes per frame. 3D only. - </constant> - <constant name="RENDER_SURFACE_CHANGES_IN_FRAME" value="14" enum="Monitor"> - Render surface changes per frame. 3D only. - </constant> - <constant name="RENDER_DRAW_CALLS_IN_FRAME" value="15" enum="Monitor"> - Draw calls per frame. 3D only. - </constant> - <constant name="RENDER_VIDEO_MEM_USED" value="16" enum="Monitor"> + <constant name="RENDER_VIDEO_MEM_USED" value="13" enum="Monitor"> The amount of video memory used, i.e. texture and vertex memory combined. </constant> - <constant name="RENDER_TEXTURE_MEM_USED" value="17" enum="Monitor"> + <constant name="RENDER_TEXTURE_MEM_USED" value="14" enum="Monitor"> The amount of texture memory used. </constant> - <constant name="RENDER_VERTEX_MEM_USED" value="18" enum="Monitor"> - The amount of vertex memory used. - </constant> - <constant name="RENDER_USAGE_VIDEO_MEM_TOTAL" value="19" enum="Monitor"> - Unimplemented in the GLES2 rendering backend, always returns 0. + <constant name="RENDER_BUFFER_MEM_USED" value="15" enum="Monitor"> </constant> - <constant name="PHYSICS_2D_ACTIVE_OBJECTS" value="20" enum="Monitor"> + <constant name="PHYSICS_2D_ACTIVE_OBJECTS" value="16" enum="Monitor"> Number of active [RigidBody2D] nodes in the game. </constant> - <constant name="PHYSICS_2D_COLLISION_PAIRS" value="21" enum="Monitor"> + <constant name="PHYSICS_2D_COLLISION_PAIRS" value="17" enum="Monitor"> Number of collision pairs in the 2D physics engine. </constant> - <constant name="PHYSICS_2D_ISLAND_COUNT" value="22" enum="Monitor"> + <constant name="PHYSICS_2D_ISLAND_COUNT" value="18" enum="Monitor"> Number of islands in the 2D physics engine. </constant> - <constant name="PHYSICS_3D_ACTIVE_OBJECTS" value="23" enum="Monitor"> + <constant name="PHYSICS_3D_ACTIVE_OBJECTS" value="19" enum="Monitor"> Number of active [RigidBody3D] and [VehicleBody3D] nodes in the game. </constant> - <constant name="PHYSICS_3D_COLLISION_PAIRS" value="24" enum="Monitor"> + <constant name="PHYSICS_3D_COLLISION_PAIRS" value="20" enum="Monitor"> Number of collision pairs in the 3D physics engine. </constant> - <constant name="PHYSICS_3D_ISLAND_COUNT" value="25" enum="Monitor"> + <constant name="PHYSICS_3D_ISLAND_COUNT" value="21" enum="Monitor"> Number of islands in the 3D physics engine. </constant> - <constant name="AUDIO_OUTPUT_LATENCY" value="26" enum="Monitor"> + <constant name="AUDIO_OUTPUT_LATENCY" value="22" enum="Monitor"> Output latency of the [AudioServer]. </constant> - <constant name="MONITOR_MAX" value="27" enum="Monitor"> + <constant name="MONITOR_MAX" value="23" enum="Monitor"> Represents the size of the [enum Monitor] enum. </constant> </constants> diff --git a/doc/classes/PhysicalBone3D.xml b/doc/classes/PhysicalBone3D.xml index 736b44ee1c..2ed862e9ce 100644 --- a/doc/classes/PhysicalBone3D.xml +++ b/doc/classes/PhysicalBone3D.xml @@ -66,12 +66,9 @@ <member name="joint_offset" type="Transform3D" setter="set_joint_offset" getter="get_joint_offset" default="Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0)"> Sets the joint's transform. </member> - <member name="joint_rotation" type="Vector3" setter="set_joint_rotation" getter="get_joint_rotation"> + <member name="joint_rotation" type="Vector3" setter="set_joint_rotation" getter="get_joint_rotation" default="Vector3(0, 0, 0)"> Sets the joint's rotation in radians. </member> - <member name="joint_rotation_degrees" type="Vector3" setter="set_joint_rotation_degrees" getter="get_joint_rotation_degrees" default="Vector3(0, 0, 0)"> - Sets the joint's rotation in degrees. - </member> <member name="joint_type" type="int" setter="set_joint_type" getter="get_joint_type" enum="PhysicalBone3D.JointType" default="0"> Sets the joint type. See [enum JointType] for possible values. </member> diff --git a/doc/classes/PhysicsServer3D.xml b/doc/classes/PhysicsServer3D.xml index aa1f7597ea..88ce222324 100644 --- a/doc/classes/PhysicsServer3D.xml +++ b/doc/classes/PhysicsServer3D.xml @@ -772,6 +772,25 @@ Sets a body state (see [enum BodyState] constants). </description> </method> + <method name="body_test_motion"> + <return type="bool"> + </return> + <argument index="0" name="body" type="RID"> + </argument> + <argument index="1" name="from" type="Transform3D"> + </argument> + <argument index="2" name="motion" type="Vector3"> + </argument> + <argument index="3" name="infinite_inertia" type="bool"> + </argument> + <argument index="4" name="margin" type="float" default="0.001"> + </argument> + <argument index="5" name="result" type="PhysicsTestMotionResult3D" default="null"> + </argument> + <description> + Returns [code]true[/code] if a collision would result from moving in the given direction from a given point in space. Margin increases the size of the shapes involved in the collision detection. [PhysicsTestMotionResult3D] can be passed to return additional information in. + </description> + </method> <method name="box_shape_create"> <return type="RID"> </return> diff --git a/doc/classes/PhysicsShapeQueryParameters2D.xml b/doc/classes/PhysicsShapeQueryParameters2D.xml index 321a713e26..229a40638a 100644 --- a/doc/classes/PhysicsShapeQueryParameters2D.xml +++ b/doc/classes/PhysicsShapeQueryParameters2D.xml @@ -4,7 +4,7 @@ Parameters to be sent to a 2D shape physics query. </brief_description> <description> - This class contains the shape and other parameters for 2D intersection/collision queries. See also [PhysicsShapeQueryResult2D]. + This class contains the shape and other parameters for 2D intersection/collision queries. </description> <tutorials> </tutorials> diff --git a/doc/classes/PhysicsShapeQueryParameters3D.xml b/doc/classes/PhysicsShapeQueryParameters3D.xml index 52916a8418..9ca892acb3 100644 --- a/doc/classes/PhysicsShapeQueryParameters3D.xml +++ b/doc/classes/PhysicsShapeQueryParameters3D.xml @@ -4,7 +4,7 @@ Parameters to be sent to a 3D shape physics query. </brief_description> <description> - This class contains the shape and other parameters for 3D intersection/collision queries. See also [PhysicsShapeQueryResult3D]. + This class contains the shape and other parameters for 3D intersection/collision queries. </description> <tutorials> </tutorials> diff --git a/doc/classes/PhysicsShapeQueryResult2D.xml b/doc/classes/PhysicsShapeQueryResult2D.xml deleted file mode 100644 index 07b7bc90e2..0000000000 --- a/doc/classes/PhysicsShapeQueryResult2D.xml +++ /dev/null @@ -1,58 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<class name="PhysicsShapeQueryResult2D" inherits="RefCounted" version="4.0"> - <brief_description> - Result of a 2D shape query in [PhysicsServer2D]. - </brief_description> - <description> - The result of a 2D shape query in [PhysicsServer2D]. See also [PhysicsShapeQueryParameters2D]. - </description> - <tutorials> - </tutorials> - <methods> - <method name="get_result_count" qualifiers="const"> - <return type="int"> - </return> - <description> - Returns the number of objects that intersected with the shape. - </description> - </method> - <method name="get_result_object" qualifiers="const"> - <return type="Object"> - </return> - <argument index="0" name="idx" type="int"> - </argument> - <description> - Returns the [Object] that intersected with the shape at index [code]idx[/code]. - </description> - </method> - <method name="get_result_object_id" qualifiers="const"> - <return type="int"> - </return> - <argument index="0" name="idx" type="int"> - </argument> - <description> - Returns the instance ID of the [Object] that intersected with the shape at index [code]idx[/code]. - </description> - </method> - <method name="get_result_object_shape" qualifiers="const"> - <return type="int"> - </return> - <argument index="0" name="idx" type="int"> - </argument> - <description> - Returns the child index of the object's [Shape2D] that intersected with the shape at index [code]idx[/code]. - </description> - </method> - <method name="get_result_rid" qualifiers="const"> - <return type="RID"> - </return> - <argument index="0" name="idx" type="int"> - </argument> - <description> - Returns the [RID] of the object that intersected with the shape at index [code]idx[/code]. - </description> - </method> - </methods> - <constants> - </constants> -</class> diff --git a/doc/classes/PhysicsShapeQueryResult3D.xml b/doc/classes/PhysicsShapeQueryResult3D.xml deleted file mode 100644 index d0ca227a68..0000000000 --- a/doc/classes/PhysicsShapeQueryResult3D.xml +++ /dev/null @@ -1,58 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<class name="PhysicsShapeQueryResult3D" inherits="RefCounted" version="4.0"> - <brief_description> - Result of a 3D shape query in [PhysicsServer3D]. - </brief_description> - <description> - The result of a 3D shape query in [PhysicsServer3D]. See also [PhysicsShapeQueryParameters3D]. - </description> - <tutorials> - </tutorials> - <methods> - <method name="get_result_count" qualifiers="const"> - <return type="int"> - </return> - <description> - Returns the number of objects that intersected with the shape. - </description> - </method> - <method name="get_result_object" qualifiers="const"> - <return type="Object"> - </return> - <argument index="0" name="idx" type="int"> - </argument> - <description> - Returns the [Object] that intersected with the shape at index [code]idx[/code]. - </description> - </method> - <method name="get_result_object_id" qualifiers="const"> - <return type="int"> - </return> - <argument index="0" name="idx" type="int"> - </argument> - <description> - Returns the instance ID of the [Object] that intersected with the shape at index [code]idx[/code]. - </description> - </method> - <method name="get_result_object_shape" qualifiers="const"> - <return type="int"> - </return> - <argument index="0" name="idx" type="int"> - </argument> - <description> - Returns the child index of the object's [Shape3D] that intersected with the shape at index [code]idx[/code]. - </description> - </method> - <method name="get_result_rid" qualifiers="const"> - <return type="RID"> - </return> - <argument index="0" name="idx" type="int"> - </argument> - <description> - Returns the [RID] of the object that intersected with the shape at index [code]idx[/code]. - </description> - </method> - </methods> - <constants> - </constants> -</class> diff --git a/doc/classes/PhysicsTestMotionResult2D.xml b/doc/classes/PhysicsTestMotionResult2D.xml index da04ffa86a..bf3497386e 100644 --- a/doc/classes/PhysicsTestMotionResult2D.xml +++ b/doc/classes/PhysicsTestMotionResult2D.xml @@ -19,10 +19,16 @@ </member> <member name="collider_velocity" type="Vector2" setter="" getter="get_collider_velocity" default="Vector2(0, 0)"> </member> + <member name="collision_depth" type="float" setter="" getter="get_collision_depth" default="0.0"> + </member> <member name="collision_normal" type="Vector2" setter="" getter="get_collision_normal" default="Vector2(0, 0)"> </member> <member name="collision_point" type="Vector2" setter="" getter="get_collision_point" default="Vector2(0, 0)"> </member> + <member name="collision_safe_fraction" type="float" setter="" getter="get_collision_safe_fraction" default="0.0"> + </member> + <member name="collision_unsafe_fraction" type="float" setter="" getter="get_collision_unsafe_fraction" default="0.0"> + </member> <member name="motion" type="Vector2" setter="" getter="get_motion" default="Vector2(0, 0)"> </member> <member name="motion_remainder" type="Vector2" setter="" getter="get_motion_remainder" default="Vector2(0, 0)"> diff --git a/doc/classes/PhysicsTestMotionResult3D.xml b/doc/classes/PhysicsTestMotionResult3D.xml new file mode 100644 index 0000000000..08c72ba965 --- /dev/null +++ b/doc/classes/PhysicsTestMotionResult3D.xml @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="PhysicsTestMotionResult3D" inherits="RefCounted" version="4.0"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <methods> + </methods> + <members> + <member name="collider" type="Object" setter="" getter="get_collider"> + </member> + <member name="collider_id" type="int" setter="" getter="get_collider_id" default="0"> + </member> + <member name="collider_rid" type="RID" setter="" getter="get_collider_rid"> + </member> + <member name="collider_shape" type="int" setter="" getter="get_collider_shape" default="0"> + </member> + <member name="collider_velocity" type="Vector3" setter="" getter="get_collider_velocity" default="Vector3(0, 0, 0)"> + </member> + <member name="collision_depth" type="float" setter="" getter="get_collision_depth" default="0.0"> + </member> + <member name="collision_normal" type="Vector3" setter="" getter="get_collision_normal" default="Vector3(0, 0, 0)"> + </member> + <member name="collision_point" type="Vector3" setter="" getter="get_collision_point" default="Vector3(0, 0, 0)"> + </member> + <member name="collision_safe_fraction" type="float" setter="" getter="get_collision_safe_fraction" default="0.0"> + </member> + <member name="collision_unsafe_fraction" type="float" setter="" getter="get_collision_unsafe_fraction" default="0.0"> + </member> + <member name="motion" type="Vector3" setter="" getter="get_motion" default="Vector3(0, 0, 0)"> + </member> + <member name="motion_remainder" type="Vector3" setter="" getter="get_motion_remainder" default="Vector3(0, 0, 0)"> + </member> + </members> + <constants> + </constants> +</class> diff --git a/doc/classes/Plane.xml b/doc/classes/Plane.xml index cca5793fc7..12869061c4 100644 --- a/doc/classes/Plane.xml +++ b/doc/classes/Plane.xml @@ -169,23 +169,23 @@ <description> </description> </method> - <method name="operator +" qualifiers="operator"> - <return type="Plane"> + <method name="operator ==" qualifiers="operator"> + <return type="bool"> </return> + <argument index="0" name="right" type="Plane"> + </argument> <description> </description> </method> - <method name="operator -" qualifiers="operator"> + <method name="operator unary+" qualifiers="operator"> <return type="Plane"> </return> <description> </description> </method> - <method name="operator ==" qualifiers="operator"> - <return type="bool"> + <method name="operator unary-" qualifiers="operator"> + <return type="Plane"> </return> - <argument index="0" name="right" type="Plane"> - </argument> <description> </description> </method> diff --git a/doc/classes/PlaneMesh.xml b/doc/classes/PlaneMesh.xml index c95ba29ea2..56bf98772b 100644 --- a/doc/classes/PlaneMesh.xml +++ b/doc/classes/PlaneMesh.xml @@ -12,6 +12,9 @@ <methods> </methods> <members> + <member name="center_offset" type="Vector3" setter="set_center_offset" getter="get_center_offset" default="Vector3(0, 0, 0)"> + Offset of the generated plane. Useful for particles. + </member> <member name="size" type="Vector2" setter="set_size" getter="get_size" default="Vector2(2, 2)"> Size of the generated plane. </member> diff --git a/doc/classes/Polygon2D.xml b/doc/classes/Polygon2D.xml index c33a1424a7..5a53063148 100644 --- a/doc/classes/Polygon2D.xml +++ b/doc/classes/Polygon2D.xml @@ -118,12 +118,9 @@ <member name="texture_offset" type="Vector2" setter="set_texture_offset" getter="get_texture_offset" default="Vector2(0, 0)"> Amount to offset the polygon's [code]texture[/code]. If [code](0, 0)[/code] the texture's origin (its top-left corner) will be placed at the polygon's [code]position[/code]. </member> - <member name="texture_rotation" type="float" setter="set_texture_rotation" getter="get_texture_rotation"> + <member name="texture_rotation" type="float" setter="set_texture_rotation" getter="get_texture_rotation" default="0.0"> The texture's rotation in radians. </member> - <member name="texture_rotation_degrees" type="float" setter="set_texture_rotation_degrees" getter="get_texture_rotation_degrees" default="0.0"> - The texture's rotation in degrees. - </member> <member name="texture_scale" type="Vector2" setter="set_texture_scale" getter="get_texture_scale" default="Vector2(1, 1)"> Amount to multiply the [code]uv[/code] coordinates when using a [code]texture[/code]. Larger values make the texture smaller, and vice versa. </member> diff --git a/doc/classes/Popup.xml b/doc/classes/Popup.xml index b8d8a55412..89695989c8 100644 --- a/doc/classes/Popup.xml +++ b/doc/classes/Popup.xml @@ -13,6 +13,7 @@ <members> <member name="borderless" type="bool" setter="set_flag" getter="get_flag" override="true" default="true" /> <member name="close_on_parent_focus" type="bool" setter="set_close_on_parent_focus" getter="get_close_on_parent_focus" default="true"> + If [code]true[/code], the [Popup] will close when its parent is focused. </member> <member name="transient" type="bool" setter="set_transient" getter="is_transient" override="true" default="true" /> <member name="unresizable" type="bool" setter="set_flag" getter="get_flag" override="true" default="true" /> diff --git a/doc/classes/PopupMenu.xml b/doc/classes/PopupMenu.xml index e448d18d73..3489c5435a 100644 --- a/doc/classes/PopupMenu.xml +++ b/doc/classes/PopupMenu.xml @@ -260,6 +260,7 @@ <return type="int"> </return> <description> + Returns the index of the currently focused item. Returns [code]-1[/code] if no item is focused. </description> </method> <method name="get_item_accelerator" qualifiers="const"> diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml index 04d1af3f6a..fbd257cdba 100644 --- a/doc/classes/ProjectSettings.xml +++ b/doc/classes/ProjectSettings.xml @@ -266,10 +266,12 @@ Icon set in [code].ico[/code] format used on Windows to set the game's icon. This is done automatically on start by calling [method DisplayServer.set_native_icon]. </member> <member name="application/run/disable_stderr" type="bool" setter="" getter="" default="false"> - If [code]true[/code], disables printing to standard error in an exported build. + If [code]true[/code], disables printing to standard error. If [code]true[/code], this also hides error and warning messages printed by [method @GlobalScope.push_error] and [method @GlobalScope.push_warning]. See also [member application/run/disable_stdout]. + Changes to this setting will only be applied upon restarting the application. </member> <member name="application/run/disable_stdout" type="bool" setter="" getter="" default="false"> - If [code]true[/code], disables printing to standard output in an exported build. + If [code]true[/code], disables printing to standard output. This is equivalent to starting the editor or project with the [code]--quiet[/code] command line argument. See also [member application/run/disable_stderr]. + Changes to this setting will only be applied upon restarting the application. </member> <member name="application/run/flush_stdout_on_print" type="bool" setter="" getter="" default="false"> If [code]true[/code], flushes the standard output stream every time a line is printed. This affects both terminal logging and file logging. @@ -443,7 +445,7 @@ </member> <member name="debug/settings/fps/force_fps" type="int" setter="" getter="" default="0"> Maximum number of frames per second allowed. The actual number of frames per second may still be below this value if the game is lagging. - If [member display/window/vsync/use_vsync] is enabled, it takes precedence and the forced FPS number cannot exceed the monitor's refresh rate. + If [member display/window/vsync/vsync_mode] is set to [code]Enabled[/code] or [code]Adaptive[/code], it takes precedence and the forced FPS number cannot exceed the monitor's refresh rate. This setting is therefore mostly relevant for lowering the maximum FPS below VSync, e.g. to perform non-real-time rendering of static frames, or test the project under lag conditions. </member> <member name="debug/settings/gdscript/max_call_stack" type="int" setter="" getter="" default="1024"> @@ -530,12 +532,10 @@ <member name="display/window/size/width" type="int" setter="" getter="" default="1024"> Sets the game's main viewport width. On desktop platforms, this is the default window size. Stretch mode settings also use this as a reference when enabled. </member> - <member name="display/window/vsync/use_vsync" type="bool" setter="" getter="" default="true"> - If [code]true[/code], enables vertical synchronization. This eliminates tearing that may appear in moving scenes, at the cost of higher input latency and stuttering at lower framerates. If [code]false[/code], vertical synchronization will be disabled, however, many platforms will enforce it regardless (such as mobile platforms and HTML5). - </member> - <member name="display/window/vsync/vsync_via_compositor" type="bool" setter="" getter="" default="false"> - If [code]Use Vsync[/code] is enabled and this setting is [code]true[/code], enables vertical synchronization via the operating system's window compositor when in windowed mode and the compositor is enabled. This will prevent stutter in certain situations. (Windows only.) - [b]Note:[/b] This option is experimental and meant to alleviate stutter experienced by some users. However, some users have experienced a Vsync framerate halving (e.g. from 60 FPS to 30 FPS) when using it. + <member name="display/window/vsync/vsync_mode" type="int" setter="" getter="" default="1"> + Sets the VSync mode for the main game window. + See [enum DisplayServer.VSyncMode] for possible values and how they affect the behavior of your application. + Depending on the platform and used renderer, the engine will fall back to [code]Enabled[/code], if the desired mode is not supported. </member> <member name="editor/node_naming/name_casing" type="int" setter="" getter="" default="0"> When creating node names automatically, set the type of casing in this project. This is mostly an editor setting. @@ -1428,8 +1428,6 @@ </member> <member name="rendering/global_illumination/sdfgi/probe_ray_count" type="int" setter="" getter="" default="1"> </member> - <member name="rendering/global_illumination/voxel_gi/anisotropic" type="bool" setter="" getter="" default="false"> - </member> <member name="rendering/global_illumination/voxel_gi/quality" type="int" setter="" getter="" default="1"> </member> <member name="rendering/lightmapping/bake_performance/max_rays_per_pass" type="int" setter="" getter="" default="32"> diff --git a/doc/classes/PropertyTweener.xml b/doc/classes/PropertyTweener.xml new file mode 100644 index 0000000000..1e77bb33c6 --- /dev/null +++ b/doc/classes/PropertyTweener.xml @@ -0,0 +1,78 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="PropertyTweener" inherits="Tweener" version="4.0"> + <brief_description> + Interpolates an [Object]'s property over time. + </brief_description> + <description> + [PropertyTweener] is used to interpolate a property in an object. See [method Tween.tween_property] for more usage information. + [b]Note:[/b] [method Tween.tween_property] is the only correct way to create [PropertyTweener]. Any [PropertyTweener] created manually will not function correctly. + </description> + <tutorials> + </tutorials> + <methods> + <method name="as_relative"> + <return type="PropertyTweener"> + </return> + <description> + When called, the final value will be used as a relative value instead. Example: + [codeblock] + var tween = get_tree().create_tween() + tween.tween_property(self, "position", Vector2.RIGHT * 100, 1).as_relative() #the node will move by 100 pixels to the right + [/codeblock] + </description> + </method> + <method name="from"> + <return type="PropertyTweener"> + </return> + <argument index="0" name="value" type="Variant"> + </argument> + <description> + Sets a custom initial value to the [PropertyTweener]. Example: + [codeblock] + var tween = get_tree().create_tween() + tween.tween_property(self, "position", Vector2(200, 100), 1).from(Vector2(100, 100) #this will move the node from position (100, 100) to (200, 100) + [/codeblock] + </description> + </method> + <method name="from_current"> + <return type="PropertyTweener"> + </return> + <description> + Makes the [PropertyTweener] use the current property value (i.e. at the time of creating this [PropertyTweener]) as a starting point. This is equivalent of using [method from] with the current value. These two calls will do the same: + [codeblock] + tween.tween_property(self, "position", Vector2(200, 100), 1).from(position) + tween.tween_property(self, "position", Vector2(200, 100), 1).from_current() + [/codeblock] + </description> + </method> + <method name="set_delay"> + <return type="PropertyTweener"> + </return> + <argument index="0" name="delay" type="float"> + </argument> + <description> + Sets the time in seconds after which the [PropertyTweener] will start interpolating. By default there's no delay. + </description> + </method> + <method name="set_ease"> + <return type="PropertyTweener"> + </return> + <argument index="0" name="ease" type="int" enum="Tween.EaseType"> + </argument> + <description> + Sets the type of used easing from [enum Tween.EaseType]. If not set, the default easing is used from the [Tween] that contains this Tweener. + </description> + </method> + <method name="set_trans"> + <return type="PropertyTweener"> + </return> + <argument index="0" name="trans" type="int" enum="Tween.TransitionType"> + </argument> + <description> + Sets the type of used transition from [enum Tween.TransitionType]. If not set, the default transition is used from the [Tween] that contains this Tweener. + </description> + </method> + </methods> + <constants> + </constants> +</class> diff --git a/doc/classes/QuadMesh.xml b/doc/classes/QuadMesh.xml index 94d638888c..4209e3db14 100644 --- a/doc/classes/QuadMesh.xml +++ b/doc/classes/QuadMesh.xml @@ -13,6 +13,9 @@ <methods> </methods> <members> + <member name="center_offset" type="Vector3" setter="set_center_offset" getter="get_center_offset" default="Vector3(0, 0, 0)"> + Offset of the generated Quad. Useful for particles. + </member> <member name="size" type="Vector2" setter="set_size" getter="get_size" default="Vector2(1, 1)"> Size on the X and Y axes. </member> diff --git a/doc/classes/Quaternion.xml b/doc/classes/Quaternion.xml index 660204ee7d..06434ab268 100644 --- a/doc/classes/Quaternion.xml +++ b/doc/classes/Quaternion.xml @@ -177,17 +177,17 @@ </description> </method> <method name="operator *" qualifiers="operator"> - <return type="Quaternion"> + <return type="Vector3"> </return> - <argument index="0" name="right" type="Quaternion"> + <argument index="0" name="right" type="Vector3"> </argument> <description> </description> </method> <method name="operator *" qualifiers="operator"> - <return type="Vector3"> + <return type="Quaternion"> </return> - <argument index="0" name="right" type="Vector3"> + <argument index="0" name="right" type="Quaternion"> </argument> <description> </description> @@ -211,12 +211,6 @@ <method name="operator +" qualifiers="operator"> <return type="Quaternion"> </return> - <description> - </description> - </method> - <method name="operator +" qualifiers="operator"> - <return type="Quaternion"> - </return> <argument index="0" name="right" type="Quaternion"> </argument> <description> @@ -225,12 +219,6 @@ <method name="operator -" qualifiers="operator"> <return type="Quaternion"> </return> - <description> - </description> - </method> - <method name="operator -" qualifiers="operator"> - <return type="Quaternion"> - </return> <argument index="0" name="right" type="Quaternion"> </argument> <description> @@ -268,6 +256,18 @@ <description> </description> </method> + <method name="operator unary+" qualifiers="operator"> + <return type="Quaternion"> + </return> + <description> + </description> + </method> + <method name="operator unary-" qualifiers="operator"> + <return type="Quaternion"> + </return> + <description> + </description> + </method> <method name="slerp" qualifiers="const"> <return type="Quaternion"> </return> diff --git a/doc/classes/RDFramebufferPass.xml b/doc/classes/RDFramebufferPass.xml new file mode 100644 index 0000000000..c26c41f93f --- /dev/null +++ b/doc/classes/RDFramebufferPass.xml @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="RDFramebufferPass" inherits="RefCounted" version="4.0"> + <brief_description> + Framebuffer pass attachment description. + </brief_description> + <description> + This class contains the list of attachment descriptions for a framebuffer pass. Each points with an index to a previously supplied list of texture attachments. + Multipass framebuffers can optimize some configurations in mobile, on desktop they provide little to no advantage. + </description> + <tutorials> + </tutorials> + <methods> + </methods> + <members> + <member name="color_attachments" type="PackedInt32Array" setter="set_color_attachments" getter="get_color_attachments" default="PackedInt32Array()"> + Color attachments in order starting from 0. If this attachment is not used by the shader, pass ATTACHMENT_UNUSED to skip. + </member> + <member name="depth_attachment" type="int" setter="set_depth_attachment" getter="get_depth_attachment" default="-1"> + Depth attachment. ATTACHMENT_UNUSED should be used if no depth buffer is required for this pass. + </member> + <member name="input_attachments" type="PackedInt32Array" setter="set_input_attachments" getter="get_input_attachments" default="PackedInt32Array()"> + Used for multipass framebuffers (more than one render pass). Converts an attachment to an input. Make sure to also supply it properly in the [RDUniform] for the uniform set. + </member> + <member name="preserve_attachments" type="PackedInt32Array" setter="set_preserve_attachments" getter="get_preserve_attachments" default="PackedInt32Array()"> + Attachments to preserve in this pass (otherwise they are erased). + </member> + <member name="resolve_attachments" type="PackedInt32Array" setter="set_resolve_attachments" getter="get_resolve_attachments" default="PackedInt32Array()"> + If the color attachments are multisampled, non-multisampled resolve attachments can be provided. + </member> + </members> + <constants> + <constant name="ATTACHMENT_UNUSED" value="-1"> + </constant> + </constants> +</class> diff --git a/doc/classes/RDPipelineSpecializationConstant.xml b/doc/classes/RDPipelineSpecializationConstant.xml new file mode 100644 index 0000000000..4d9481b846 --- /dev/null +++ b/doc/classes/RDPipelineSpecializationConstant.xml @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="RDPipelineSpecializationConstant" inherits="RefCounted" version="4.0"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <methods> + </methods> + <members> + <member name="constant_id" type="int" setter="set_constant_id" getter="get_constant_id" default="0"> + </member> + <member name="value" type="Variant" setter="set_value" getter="get_value"> + </member> + </members> + <constants> + </constants> +</class> diff --git a/doc/classes/RandomNumberGenerator.xml b/doc/classes/RandomNumberGenerator.xml index 6fcb79b5fe..9c84cdd03e 100644 --- a/doc/classes/RandomNumberGenerator.xml +++ b/doc/classes/RandomNumberGenerator.xml @@ -23,7 +23,7 @@ <return type="float"> </return> <description> - Generates a pseudo-random float between [code]0.0[/code] and [code]1.0[/code] (inclusive). + Returns a pseudo-random float between [code]0.0[/code] and [code]1.0[/code] (inclusive). </description> </method> <method name="randf_range"> @@ -34,7 +34,7 @@ <argument index="1" name="to" type="float"> </argument> <description> - Generates a pseudo-random float between [code]from[/code] and [code]to[/code] (inclusive). + Returns a pseudo-random float between [code]from[/code] and [code]to[/code] (inclusive). </description> </method> <method name="randfn"> @@ -45,14 +45,14 @@ <argument index="1" name="deviation" type="float" default="1.0"> </argument> <description> - Generates a [url=https://en.wikipedia.org/wiki/Normal_distribution]normally-distributed[/url] pseudo-random number, using Box-Muller transform with the specified [code]mean[/code] and a standard [code]deviation[/code]. This is also called Gaussian distribution. + Returns a [url=https://en.wikipedia.org/wiki/Normal_distribution]normally-distributed[/url] pseudo-random number, using Box-Muller transform with the specified [code]mean[/code] and a standard [code]deviation[/code]. This is also called Gaussian distribution. </description> </method> <method name="randi"> <return type="int"> </return> <description> - Generates a pseudo-random 32-bit unsigned integer between [code]0[/code] and [code]4294967295[/code] (inclusive). + Returns a pseudo-random 32-bit unsigned integer between [code]0[/code] and [code]4294967295[/code] (inclusive). </description> </method> <method name="randi_range"> @@ -63,14 +63,14 @@ <argument index="1" name="to" type="int"> </argument> <description> - Generates a pseudo-random 32-bit signed integer between [code]from[/code] and [code]to[/code] (inclusive). + Returns a pseudo-random 32-bit signed integer between [code]from[/code] and [code]to[/code] (inclusive). </description> </method> <method name="randomize"> <return type="void"> </return> <description> - Setups a time-based seed to generator. + Setups a time-based seed to for this [RandomNumberGenerator] instance. Unlike the [@GlobalScope] random number generation functions, different [RandomNumberGenerator] instances can use different seeds. </description> </method> </methods> diff --git a/doc/classes/ReflectionProbe.xml b/doc/classes/ReflectionProbe.xml index 1d32a8b509..db01faced8 100644 --- a/doc/classes/ReflectionProbe.xml +++ b/doc/classes/ReflectionProbe.xml @@ -28,8 +28,8 @@ <member name="enable_shadows" type="bool" setter="set_enable_shadows" getter="are_shadows_enabled" default="false"> If [code]true[/code], computes shadows in the reflection probe. This makes the reflection probe slower to render; you may want to disable this if using the [constant UPDATE_ALWAYS] [member update_mode]. </member> - <member name="extents" type="Vector3" setter="set_extents" getter="get_extents" default="Vector3(1, 1, 1)"> - The size of the reflection probe. The larger the extents the more space covered by the probe which will lower the perceived resolution. It is best to keep the extents only as large as you need them. + <member name="extents" type="Vector3" setter="set_extents" getter="get_extents" default="Vector3(10, 10, 10)"> + The size of the reflection probe. The larger the extents, the more space covered by the probe, which will lower the perceived resolution. It is best to keep the extents only as large as you need them. </member> <member name="intensity" type="float" setter="set_intensity" getter="get_intensity" default="1.0"> Defines the reflection intensity. Intensity modulates the strength of the reflection. diff --git a/doc/classes/RenderingDevice.xml b/doc/classes/RenderingDevice.xml index dc56e6fd5d..901a985961 100644 --- a/doc/classes/RenderingDevice.xml +++ b/doc/classes/RenderingDevice.xml @@ -140,6 +140,8 @@ </return> <argument index="0" name="shader" type="RID"> </argument> + <argument index="1" name="specialization_constants" type="RDPipelineSpecializationConstant[]" default="[]"> + </argument> <description> </description> </method> @@ -341,13 +343,29 @@ <description> </description> </method> + <method name="draw_list_switch_to_next_pass"> + <return type="int"> + </return> + <description> + </description> + </method> + <method name="draw_list_switch_to_next_pass_split"> + <return type="PackedInt64Array"> + </return> + <argument index="0" name="splits" type="int"> + </argument> + <description> + </description> + </method> <method name="framebuffer_create"> <return type="RID"> </return> - <argument index="0" name="textures" type="Array"> + <argument index="0" name="textures" type="RID[]"> </argument> <argument index="1" name="validate_with_format" type="int" default="-1"> </argument> + <argument index="2" name="view_count" type="int" default="1"> + </argument> <description> </description> </method> @@ -363,11 +381,27 @@ <description> </description> </method> + <method name="framebuffer_create_multipass"> + <return type="RID"> + </return> + <argument index="0" name="textures" type="RID[]"> + </argument> + <argument index="1" name="passes" type="RDFramebufferPass[]"> + </argument> + <argument index="2" name="validate_with_format" type="int" default="-1"> + </argument> + <argument index="3" name="view_count" type="int" default="1"> + </argument> + <description> + </description> + </method> <method name="framebuffer_format_create"> <return type="int"> </return> <argument index="0" name="attachments" type="RDAttachmentFormat[]"> </argument> + <argument index="1" name="view_count" type="int" default="1"> + </argument> <description> </description> </method> @@ -379,11 +413,25 @@ <description> </description> </method> + <method name="framebuffer_format_create_multipass"> + <return type="int"> + </return> + <argument index="0" name="attachments" type="RDAttachmentFormat[]"> + </argument> + <argument index="1" name="passes" type="RDFramebufferPass[]"> + </argument> + <argument index="2" name="view_count" type="int" default="1"> + </argument> + <description> + </description> + </method> <method name="framebuffer_format_get_texture_samples"> <return type="int" enum="RenderingDevice.TextureSamples"> </return> <argument index="0" name="format" type="int"> </argument> + <argument index="1" name="render_pass" type="int" default="0"> + </argument> <description> </description> </method> @@ -469,6 +517,14 @@ <description> </description> </method> + <method name="get_memory_usage" qualifiers="const"> + <return type="int"> + </return> + <argument index="0" name="arg0" type="int" enum="RenderingDevice.MemoryType"> + </argument> + <description> + </description> + </method> <method name="index_array_create"> <return type="RID"> </return> @@ -524,6 +580,10 @@ </argument> <argument index="8" name="dynamic_state_flags" type="int" default="0"> </argument> + <argument index="9" name="for_render_pass" type="int" default="0"> + </argument> + <argument index="10" name="specialization_constants" type="RDPipelineSpecializationConstant[]" default="[]"> + </argument> <description> </description> </method> @@ -1653,6 +1713,12 @@ </constant> <constant name="SHADER_LANGUAGE_HLSL" value="1" enum="ShaderLanguage"> </constant> + <constant name="PIPELINE_SPECIALIZATION_CONSTANT_TYPE_BOOL" value="0" enum="PipelineSpecializationConstantType"> + </constant> + <constant name="PIPELINE_SPECIALIZATION_CONSTANT_TYPE_INT" value="1" enum="PipelineSpecializationConstantType"> + </constant> + <constant name="PIPELINE_SPECIALIZATION_CONSTANT_TYPE_FLOAT" value="2" enum="PipelineSpecializationConstantType"> + </constant> <constant name="LIMIT_MAX_BOUND_UNIFORM_SETS" value="0" enum="Limit"> </constant> <constant name="LIMIT_MAX_FRAMEBUFFER_COLOR_ATTACHMENTS" value="1" enum="Limit"> @@ -1723,6 +1789,12 @@ </constant> <constant name="LIMIT_MAX_COMPUTE_WORKGROUP_SIZE_Z" value="34" enum="Limit"> </constant> + <constant name="MEMORY_TEXTURES" value="0" enum="MemoryType"> + </constant> + <constant name="MEMORY_BUFFERS" value="1" enum="MemoryType"> + </constant> + <constant name="MEMORY_TOTAL" value="2" enum="MemoryType"> + </constant> <constant name="INVALID_ID" value="-1"> </constant> <constant name="INVALID_FORMAT_ID" value="-1"> diff --git a/doc/classes/RenderingServer.xml b/doc/classes/RenderingServer.xml index 44e0202307..6b45653bf2 100644 --- a/doc/classes/RenderingServer.xml +++ b/doc/classes/RenderingServer.xml @@ -18,42 +18,92 @@ <link title="Optimization using Servers">https://docs.godotengine.org/en/latest/tutorials/optimization/using_servers.html</link> </tutorials> <methods> - <method name="black_bars_set_images"> - <return type="void"> + <method name="bake_render_uv2"> + <return type="Image[]"> </return> - <argument index="0" name="left" type="RID"> + <argument index="0" name="base" type="RID"> + </argument> + <argument index="1" name="material_overrides" type="Array"> + </argument> + <argument index="2" name="image_size" type="Vector2i"> </argument> - <argument index="1" name="top" type="RID"> + <description> + </description> + </method> + <method name="camera_create"> + <return type="RID"> + </return> + <description> + Creates a camera and adds it to the RenderingServer. It can be accessed with the RID that is returned. This RID will be used in all [code]camera_*[/code] RenderingServer functions. + Once finished with your RID, you will want to free the RID using the RenderingServer's [method free_rid] static method. + </description> + </method> + <method name="camera_effects_create"> + <return type="RID"> + </return> + <description> + </description> + </method> + <method name="camera_effects_set_custom_exposure"> + <return type="void"> + </return> + <argument index="0" name="camera_effects" type="RID"> </argument> - <argument index="2" name="right" type="RID"> + <argument index="1" name="enable" type="bool"> </argument> - <argument index="3" name="bottom" type="RID"> + <argument index="2" name="exposure" type="float"> </argument> <description> - Sets images to be rendered in the window margin. </description> </method> - <method name="black_bars_set_margins"> + <method name="camera_effects_set_dof_blur"> <return type="void"> </return> - <argument index="0" name="left" type="int"> + <argument index="0" name="camera_effects" type="RID"> + </argument> + <argument index="1" name="far_enable" type="bool"> + </argument> + <argument index="2" name="far_distance" type="float"> </argument> - <argument index="1" name="top" type="int"> + <argument index="3" name="far_transition" type="float"> </argument> - <argument index="2" name="right" type="int"> + <argument index="4" name="near_enable" type="bool"> </argument> - <argument index="3" name="bottom" type="int"> + <argument index="5" name="near_distance" type="float"> + </argument> + <argument index="6" name="near_transition" type="float"> + </argument> + <argument index="7" name="amount" type="float"> </argument> <description> - Sets margin size, where black bars (or images, if [method black_bars_set_images] was used) are rendered. </description> </method> - <method name="camera_create"> - <return type="RID"> + <method name="camera_effects_set_dof_blur_bokeh_shape"> + <return type="void"> </return> + <argument index="0" name="shape" type="int" enum="RenderingServer.DOFBokehShape"> + </argument> + <description> + </description> + </method> + <method name="camera_effects_set_dof_blur_quality"> + <return type="void"> + </return> + <argument index="0" name="quality" type="int" enum="RenderingServer.DOFBlurQuality"> + </argument> + <argument index="1" name="use_jitter" type="bool"> + </argument> + <description> + </description> + </method> + <method name="camera_set_camera_effects"> + <return type="void"> + </return> + <argument index="0" name="camera" type="RID"> + </argument> + <argument index="1" name="effects" type="RID"> + </argument> <description> - Creates a camera and adds it to the RenderingServer. It can be accessed with the RID that is returned. This RID will be used in all [code]camera_*[/code] RenderingServer functions. - Once finished with your RID, you will want to free the RID using the RenderingServer's [method free_rid] static method. </description> </method> <method name="camera_set_cull_mask"> @@ -155,6 +205,246 @@ Once finished with your RID, you will want to free the RID using the RenderingServer's [method free_rid] static method. </description> </method> + <method name="canvas_item_add_circle"> + <return type="void"> + </return> + <argument index="0" name="item" type="RID"> + </argument> + <argument index="1" name="pos" type="Vector2"> + </argument> + <argument index="2" name="radius" type="float"> + </argument> + <argument index="3" name="color" type="Color"> + </argument> + <description> + </description> + </method> + <method name="canvas_item_add_clip_ignore"> + <return type="void"> + </return> + <argument index="0" name="item" type="RID"> + </argument> + <argument index="1" name="ignore" type="bool"> + </argument> + <description> + </description> + </method> + <method name="canvas_item_add_line"> + <return type="void"> + </return> + <argument index="0" name="item" type="RID"> + </argument> + <argument index="1" name="from" type="Vector2"> + </argument> + <argument index="2" name="to" type="Vector2"> + </argument> + <argument index="3" name="color" type="Color"> + </argument> + <argument index="4" name="width" type="float" default="1.0"> + </argument> + <description> + </description> + </method> + <method name="canvas_item_add_mesh"> + <return type="void"> + </return> + <argument index="0" name="item" type="RID"> + </argument> + <argument index="1" name="mesh" type="RID"> + </argument> + <argument index="2" name="transform" type="Transform2D" default="Transform2D(1, 0, 0, 1, 0, 0)"> + </argument> + <argument index="3" name="modulate" type="Color" default="Color(1, 1, 1, 1)"> + </argument> + <argument index="4" name="texture" type="RID"> + </argument> + <description> + </description> + </method> + <method name="canvas_item_add_multimesh"> + <return type="void"> + </return> + <argument index="0" name="item" type="RID"> + </argument> + <argument index="1" name="mesh" type="RID"> + </argument> + <argument index="2" name="texture" type="RID"> + </argument> + <description> + </description> + </method> + <method name="canvas_item_add_nine_patch"> + <return type="void"> + </return> + <argument index="0" name="item" type="RID"> + </argument> + <argument index="1" name="rect" type="Rect2"> + </argument> + <argument index="2" name="source" type="Rect2"> + </argument> + <argument index="3" name="texture" type="RID"> + </argument> + <argument index="4" name="topleft" type="Vector2"> + </argument> + <argument index="5" name="bottomright" type="Vector2"> + </argument> + <argument index="6" name="x_axis_mode" type="int" enum="RenderingServer.NinePatchAxisMode" default="0"> + </argument> + <argument index="7" name="y_axis_mode" type="int" enum="RenderingServer.NinePatchAxisMode" default="0"> + </argument> + <argument index="8" name="draw_center" type="bool" default="true"> + </argument> + <argument index="9" name="modulate" type="Color" default="Color(1, 1, 1, 1)"> + </argument> + <description> + </description> + </method> + <method name="canvas_item_add_particles"> + <return type="void"> + </return> + <argument index="0" name="item" type="RID"> + </argument> + <argument index="1" name="particles" type="RID"> + </argument> + <argument index="2" name="texture" type="RID"> + </argument> + <description> + </description> + </method> + <method name="canvas_item_add_polygon"> + <return type="void"> + </return> + <argument index="0" name="item" type="RID"> + </argument> + <argument index="1" name="points" type="PackedVector2Array"> + </argument> + <argument index="2" name="colors" type="PackedColorArray"> + </argument> + <argument index="3" name="uvs" type="PackedVector2Array" default="PackedVector2Array()"> + </argument> + <argument index="4" name="texture" type="RID"> + </argument> + <description> + </description> + </method> + <method name="canvas_item_add_polyline"> + <return type="void"> + </return> + <argument index="0" name="item" type="RID"> + </argument> + <argument index="1" name="points" type="PackedVector2Array"> + </argument> + <argument index="2" name="colors" type="PackedColorArray"> + </argument> + <argument index="3" name="width" type="float" default="1.0"> + </argument> + <argument index="4" name="antialiased" type="bool" default="false"> + </argument> + <description> + </description> + </method> + <method name="canvas_item_add_primitive"> + <return type="void"> + </return> + <argument index="0" name="item" type="RID"> + </argument> + <argument index="1" name="points" type="PackedVector2Array"> + </argument> + <argument index="2" name="colors" type="PackedColorArray"> + </argument> + <argument index="3" name="uvs" type="PackedVector2Array"> + </argument> + <argument index="4" name="texture" type="RID"> + </argument> + <argument index="5" name="width" type="float" default="1.0"> + </argument> + <description> + </description> + </method> + <method name="canvas_item_add_rect"> + <return type="void"> + </return> + <argument index="0" name="item" type="RID"> + </argument> + <argument index="1" name="rect" type="Rect2"> + </argument> + <argument index="2" name="color" type="Color"> + </argument> + <description> + </description> + </method> + <method name="canvas_item_add_set_transform"> + <return type="void"> + </return> + <argument index="0" name="item" type="RID"> + </argument> + <argument index="1" name="transform" type="Transform2D"> + </argument> + <description> + </description> + </method> + <method name="canvas_item_add_texture_rect"> + <return type="void"> + </return> + <argument index="0" name="item" type="RID"> + </argument> + <argument index="1" name="rect" type="Rect2"> + </argument> + <argument index="2" name="texture" type="RID"> + </argument> + <argument index="3" name="tile" type="bool" default="false"> + </argument> + <argument index="4" name="modulate" type="Color" default="Color(1, 1, 1, 1)"> + </argument> + <argument index="5" name="transpose" type="bool" default="false"> + </argument> + <description> + </description> + </method> + <method name="canvas_item_add_texture_rect_region"> + <return type="void"> + </return> + <argument index="0" name="item" type="RID"> + </argument> + <argument index="1" name="rect" type="Rect2"> + </argument> + <argument index="2" name="texture" type="RID"> + </argument> + <argument index="3" name="src_rect" type="Rect2"> + </argument> + <argument index="4" name="modulate" type="Color" default="Color(1, 1, 1, 1)"> + </argument> + <argument index="5" name="transpose" type="bool" default="false"> + </argument> + <argument index="6" name="clip_uv" type="bool" default="true"> + </argument> + <description> + </description> + </method> + <method name="canvas_item_add_triangle_array"> + <return type="void"> + </return> + <argument index="0" name="item" type="RID"> + </argument> + <argument index="1" name="indices" type="PackedInt32Array"> + </argument> + <argument index="2" name="points" type="PackedVector2Array"> + </argument> + <argument index="3" name="colors" type="PackedColorArray"> + </argument> + <argument index="4" name="uvs" type="PackedVector2Array" default="PackedVector2Array()"> + </argument> + <argument index="5" name="bones" type="PackedInt32Array" default="PackedInt32Array()"> + </argument> + <argument index="6" name="weights" type="PackedFloat32Array" default="PackedFloat32Array()"> + </argument> + <argument index="7" name="texture" type="RID"> + </argument> + <argument index="8" name="count" type="int" default="-1"> + </argument> + <description> + </description> + </method> <method name="canvas_item_clear"> <return type="void"> </return> @@ -164,6 +454,40 @@ Clears the [CanvasItem] and removes all commands in it. </description> </method> + <method name="canvas_item_create"> + <return type="RID"> + </return> + <description> + </description> + </method> + <method name="canvas_item_set_canvas_group_mode"> + <return type="void"> + </return> + <argument index="0" name="item" type="RID"> + </argument> + <argument index="1" name="mode" type="int" enum="RenderingServer.CanvasGroupMode"> + </argument> + <argument index="2" name="clear_margin" type="float" default="5.0"> + </argument> + <argument index="3" name="fit_empty" type="bool" default="false"> + </argument> + <argument index="4" name="fit_margin" type="float" default="0.0"> + </argument> + <argument index="5" name="blur_mipmaps" type="bool" default="false"> + </argument> + <description> + </description> + </method> + <method name="canvas_item_set_clip"> + <return type="void"> + </return> + <argument index="0" name="item" type="RID"> + </argument> + <argument index="1" name="clip" type="bool"> + </argument> + <description> + </description> + </method> <method name="canvas_item_set_copy_to_backbuffer"> <return type="void"> </return> @@ -177,6 +501,58 @@ Sets the [CanvasItem] to copy a rect to the backbuffer. </description> </method> + <method name="canvas_item_set_custom_rect"> + <return type="void"> + </return> + <argument index="0" name="item" type="RID"> + </argument> + <argument index="1" name="use_custom_rect" type="bool"> + </argument> + <argument index="2" name="rect" type="Rect2" default="Rect2(0, 0, 0, 0)"> + </argument> + <description> + </description> + </method> + <method name="canvas_item_set_default_texture_filter"> + <return type="void"> + </return> + <argument index="0" name="item" type="RID"> + </argument> + <argument index="1" name="filter" type="int" enum="RenderingServer.CanvasItemTextureFilter"> + </argument> + <description> + </description> + </method> + <method name="canvas_item_set_default_texture_repeat"> + <return type="void"> + </return> + <argument index="0" name="item" type="RID"> + </argument> + <argument index="1" name="repeat" type="int" enum="RenderingServer.CanvasItemTextureRepeat"> + </argument> + <description> + </description> + </method> + <method name="canvas_item_set_distance_field_mode"> + <return type="void"> + </return> + <argument index="0" name="item" type="RID"> + </argument> + <argument index="1" name="enabled" type="bool"> + </argument> + <description> + </description> + </method> + <method name="canvas_item_set_draw_behind_parent"> + <return type="void"> + </return> + <argument index="0" name="item" type="RID"> + </argument> + <argument index="1" name="enabled" type="bool"> + </argument> + <description> + </description> + </method> <method name="canvas_item_set_draw_index"> <return type="void"> </return> @@ -188,6 +564,16 @@ Sets the index for the [CanvasItem]. </description> </method> + <method name="canvas_item_set_light_mask"> + <return type="void"> + </return> + <argument index="0" name="item" type="RID"> + </argument> + <argument index="1" name="mask" type="int"> + </argument> + <description> + </description> + </method> <method name="canvas_item_set_material"> <return type="void"> </return> @@ -199,6 +585,56 @@ Sets a new material to the [CanvasItem]. </description> </method> + <method name="canvas_item_set_modulate"> + <return type="void"> + </return> + <argument index="0" name="item" type="RID"> + </argument> + <argument index="1" name="color" type="Color"> + </argument> + <description> + </description> + </method> + <method name="canvas_item_set_parent"> + <return type="void"> + </return> + <argument index="0" name="item" type="RID"> + </argument> + <argument index="1" name="parent" type="RID"> + </argument> + <description> + </description> + </method> + <method name="canvas_item_set_self_modulate"> + <return type="void"> + </return> + <argument index="0" name="item" type="RID"> + </argument> + <argument index="1" name="color" type="Color"> + </argument> + <description> + </description> + </method> + <method name="canvas_item_set_sort_children_by_y"> + <return type="void"> + </return> + <argument index="0" name="item" type="RID"> + </argument> + <argument index="1" name="enabled" type="bool"> + </argument> + <description> + </description> + </method> + <method name="canvas_item_set_transform"> + <return type="void"> + </return> + <argument index="0" name="item" type="RID"> + </argument> + <argument index="1" name="transform" type="Transform2D"> + </argument> + <description> + </description> + </method> <method name="canvas_item_set_use_parent_material"> <return type="void"> </return> @@ -210,6 +646,32 @@ Sets if the [CanvasItem] uses its parent's material. </description> </method> + <method name="canvas_item_set_visibility_notifier"> + <return type="void"> + </return> + <argument index="0" name="item" type="RID"> + </argument> + <argument index="1" name="enable" type="bool"> + </argument> + <argument index="2" name="area" type="Rect2"> + </argument> + <argument index="3" name="enter_callable" type="Callable"> + </argument> + <argument index="4" name="exit_callable" type="Callable"> + </argument> + <description> + </description> + </method> + <method name="canvas_item_set_visible"> + <return type="void"> + </return> + <argument index="0" name="item" type="RID"> + </argument> + <argument index="1" name="visible" type="bool"> + </argument> + <description> + </description> + </method> <method name="canvas_item_set_z_as_relative_to_parent"> <return type="void"> </return> @@ -270,6 +732,16 @@ Once finished with your RID, you will want to free the RID using the RenderingServer's [method free_rid] static method. </description> </method> + <method name="canvas_light_occluder_set_as_sdf_collision"> + <return type="void"> + </return> + <argument index="0" name="occluder" type="RID"> + </argument> + <argument index="1" name="enable" type="bool"> + </argument> + <description> + </description> + </method> <method name="canvas_light_occluder_set_enabled"> <return type="void"> </return> @@ -537,6 +1009,14 @@ Sets the shape of the occluder polygon. </description> </method> + <method name="canvas_set_disable_scale"> + <return type="void"> + </return> + <argument index="0" name="disable" type="bool"> + </argument> + <description> + </description> + </method> <method name="canvas_set_item_mirroring"> <return type="void"> </return> @@ -561,12 +1041,174 @@ Modulates all colors in the given canvas. </description> </method> + <method name="canvas_set_shadow_texture_size"> + <return type="void"> + </return> + <argument index="0" name="size" type="int"> + </argument> + <description> + </description> + </method> + <method name="canvas_texture_create"> + <return type="RID"> + </return> + <description> + </description> + </method> + <method name="canvas_texture_set_channel"> + <return type="void"> + </return> + <argument index="0" name="canvas_texture" type="RID"> + </argument> + <argument index="1" name="channel" type="int" enum="RenderingServer.CanvasTextureChannel"> + </argument> + <argument index="2" name="texture" type="RID"> + </argument> + <description> + </description> + </method> + <method name="canvas_texture_set_shading_parameters"> + <return type="void"> + </return> + <argument index="0" name="canvas_texture" type="RID"> + </argument> + <argument index="1" name="base_color" type="Color"> + </argument> + <argument index="2" name="shininess" type="float"> + </argument> + <description> + </description> + </method> + <method name="canvas_texture_set_texture_filter"> + <return type="void"> + </return> + <argument index="0" name="canvas_texture" type="RID"> + </argument> + <argument index="1" name="filter" type="int" enum="RenderingServer.CanvasItemTextureFilter"> + </argument> + <description> + </description> + </method> + <method name="canvas_texture_set_texture_repeat"> + <return type="void"> + </return> + <argument index="0" name="canvas_texture" type="RID"> + </argument> + <argument index="1" name="repeat" type="int" enum="RenderingServer.CanvasItemTextureRepeat"> + </argument> + <description> + </description> + </method> <method name="create_local_rendering_device" qualifiers="const"> <return type="RenderingDevice"> </return> <description> </description> </method> + <method name="decal_create"> + <return type="RID"> + </return> + <description> + </description> + </method> + <method name="decal_set_albedo_mix"> + <return type="void"> + </return> + <argument index="0" name="decal" type="RID"> + </argument> + <argument index="1" name="albedo_mix" type="float"> + </argument> + <description> + </description> + </method> + <method name="decal_set_cull_mask"> + <return type="void"> + </return> + <argument index="0" name="decal" type="RID"> + </argument> + <argument index="1" name="mask" type="int"> + </argument> + <description> + </description> + </method> + <method name="decal_set_distance_fade"> + <return type="void"> + </return> + <argument index="0" name="decal" type="RID"> + </argument> + <argument index="1" name="enabled" type="bool"> + </argument> + <argument index="2" name="begin" type="float"> + </argument> + <argument index="3" name="length" type="float"> + </argument> + <description> + </description> + </method> + <method name="decal_set_emission_energy"> + <return type="void"> + </return> + <argument index="0" name="decal" type="RID"> + </argument> + <argument index="1" name="energy" type="float"> + </argument> + <description> + </description> + </method> + <method name="decal_set_extents"> + <return type="void"> + </return> + <argument index="0" name="decal" type="RID"> + </argument> + <argument index="1" name="extents" type="Vector3"> + </argument> + <description> + </description> + </method> + <method name="decal_set_fade"> + <return type="void"> + </return> + <argument index="0" name="decal" type="RID"> + </argument> + <argument index="1" name="above" type="float"> + </argument> + <argument index="2" name="below" type="float"> + </argument> + <description> + </description> + </method> + <method name="decal_set_modulate"> + <return type="void"> + </return> + <argument index="0" name="decal" type="RID"> + </argument> + <argument index="1" name="color" type="Color"> + </argument> + <description> + </description> + </method> + <method name="decal_set_normal_fade"> + <return type="void"> + </return> + <argument index="0" name="decal" type="RID"> + </argument> + <argument index="1" name="fade" type="float"> + </argument> + <description> + </description> + </method> + <method name="decal_set_texture"> + <return type="void"> + </return> + <argument index="0" name="decal" type="RID"> + </argument> + <argument index="1" name="type" type="int" enum="RenderingServer.DecalTexture"> + </argument> + <argument index="2" name="texture" type="RID"> + </argument> + <description> + </description> + </method> <method name="directional_light_create"> <return type="RID"> </return> @@ -576,6 +1218,36 @@ To place in a scene, attach this directional light to an instance using [method instance_set_base] using the returned RID. </description> </method> + <method name="directional_shadow_atlas_set_size"> + <return type="void"> + </return> + <argument index="0" name="size" type="int"> + </argument> + <argument index="1" name="is_16bits" type="bool"> + </argument> + <description> + </description> + </method> + <method name="directional_shadow_quality_set"> + <return type="void"> + </return> + <argument index="0" name="quality" type="int" enum="RenderingServer.ShadowQuality"> + </argument> + <description> + </description> + </method> + <method name="environment_bake_panorama"> + <return type="Image"> + </return> + <argument index="0" name="environment" type="RID"> + </argument> + <argument index="1" name="bake_irradiance" type="bool"> + </argument> + <argument index="2" name="size" type="Vector2i"> + </argument> + <description> + </description> + </method> <method name="environment_create"> <return type="RID"> </return> @@ -584,6 +1256,22 @@ Once finished with your RID, you will want to free the RID using the RenderingServer's [method free_rid] static method. </description> </method> + <method name="environment_glow_set_use_bicubic_upscale"> + <return type="void"> + </return> + <argument index="0" name="enable" type="bool"> + </argument> + <description> + </description> + </method> + <method name="environment_glow_set_use_high_quality"> + <return type="void"> + </return> + <argument index="0" name="enable" type="bool"> + </argument> + <description> + </description> + </method> <method name="environment_set_adjustment"> <return type="void"> </return> @@ -721,6 +1409,58 @@ <description> </description> </method> + <method name="environment_set_sdfgi"> + <return type="void"> + </return> + <argument index="0" name="env" type="RID"> + </argument> + <argument index="1" name="enable" type="bool"> + </argument> + <argument index="2" name="cascades" type="int" enum="RenderingServer.EnvironmentSDFGICascades"> + </argument> + <argument index="3" name="min_cell_size" type="float"> + </argument> + <argument index="4" name="y_scale" type="int" enum="RenderingServer.EnvironmentSDFGIYScale"> + </argument> + <argument index="5" name="use_occlusion" type="bool"> + </argument> + <argument index="6" name="bounce_feedback" type="float"> + </argument> + <argument index="7" name="read_sky" type="bool"> + </argument> + <argument index="8" name="energy" type="float"> + </argument> + <argument index="9" name="normal_bias" type="float"> + </argument> + <argument index="10" name="probe_bias" type="float"> + </argument> + <description> + </description> + </method> + <method name="environment_set_sdfgi_frames_to_converge"> + <return type="void"> + </return> + <argument index="0" name="frames" type="int" enum="RenderingServer.EnvironmentSDFGIFramesToConverge"> + </argument> + <description> + </description> + </method> + <method name="environment_set_sdfgi_frames_to_update_light"> + <return type="void"> + </return> + <argument index="0" name="frames" type="int" enum="RenderingServer.EnvironmentSDFGIFramesToUpdateLight"> + </argument> + <description> + </description> + </method> + <method name="environment_set_sdfgi_ray_count"> + <return type="void"> + </return> + <argument index="0" name="ray_count" type="int" enum="RenderingServer.EnvironmentSDFGIRayCount"> + </argument> + <description> + </description> + </method> <method name="environment_set_sky"> <return type="void"> </return> @@ -781,6 +1521,24 @@ Sets the variables to be used with the "screen space ambient occlusion" post-process effect. See [Environment] for more details. </description> </method> + <method name="environment_set_ssao_quality"> + <return type="void"> + </return> + <argument index="0" name="quality" type="int" enum="RenderingServer.EnvironmentSSAOQuality"> + </argument> + <argument index="1" name="half_size" type="bool"> + </argument> + <argument index="2" name="adaptive_target" type="float"> + </argument> + <argument index="3" name="blur_passes" type="int"> + </argument> + <argument index="4" name="fadeout_from" type="float"> + </argument> + <argument index="5" name="fadeout_to" type="float"> + </argument> + <description> + </description> + </method> <method name="environment_set_ssr"> <return type="void"> </return> @@ -800,6 +1558,14 @@ Sets the variables to be used with the "screen space reflections" post-process effect. See [Environment] for more details. </description> </method> + <method name="environment_set_ssr_roughness_quality"> + <return type="void"> + </return> + <argument index="0" name="quality" type="int" enum="RenderingServer.EnvironmentSSRRoughnessQuality"> + </argument> + <description> + </description> + </method> <method name="environment_set_tonemap"> <return type="void"> </return> @@ -825,11 +1591,48 @@ Sets the variables to be used with the "tonemap" post-process effect. See [Environment] for more details. </description> </method> - <method name="finish"> + <method name="environment_set_volumetric_fog"> + <return type="void"> + </return> + <argument index="0" name="env" type="RID"> + </argument> + <argument index="1" name="enable" type="bool"> + </argument> + <argument index="2" name="density" type="float"> + </argument> + <argument index="3" name="light" type="Color"> + </argument> + <argument index="4" name="light_energy" type="float"> + </argument> + <argument index="5" name="length" type="float"> + </argument> + <argument index="6" name="p_detail_spread" type="float"> + </argument> + <argument index="7" name="gi_inject" type="float"> + </argument> + <argument index="8" name="temporal_reprojection" type="bool"> + </argument> + <argument index="9" name="temporal_reprojection_amount" type="float"> + </argument> + <description> + </description> + </method> + <method name="environment_set_volumetric_fog_filter_active"> <return type="void"> </return> + <argument index="0" name="active" type="bool"> + </argument> + <description> + </description> + </method> + <method name="environment_set_volumetric_fog_volume_size"> + <return type="void"> + </return> + <argument index="0" name="size" type="int"> + </argument> + <argument index="1" name="depth" type="int"> + </argument> <description> - Removes buffers and clears testcubes. </description> </method> <method name="force_draw"> @@ -840,14 +1643,12 @@ <argument index="1" name="frame_step" type="float" default="0.0"> </argument> <description> - Forces a frame to be drawn when the function is called. Drawing a frame updates all [Viewport]s that are set to update. Use with extreme caution. </description> </method> <method name="force_sync"> <return type="void"> </return> <description> - Synchronizes threads. </description> </method> <method name="free_rid"> @@ -865,13 +1666,12 @@ <description> </description> </method> - <method name="get_render_info"> + <method name="get_rendering_info"> <return type="int"> </return> - <argument index="0" name="info" type="int" enum="RenderingServer.RenderInfo"> + <argument index="0" name="info" type="int" enum="RenderingServer.RenderingInfo"> </argument> <description> - Returns a certain information, see [enum RenderInfo] for options. </description> </method> <method name="get_test_cube"> @@ -963,6 +1763,16 @@ <description> </description> </method> + <method name="global_variable_set_override"> + <return type="void"> + </return> + <argument index="0" name="name" type="StringName"> + </argument> + <argument index="1" name="value" type="Variant"> + </argument> + <description> + </description> + </method> <method name="has_changed" qualifiers="const"> <return type="bool"> </return> @@ -988,226 +1798,146 @@ Returns [code]true[/code] if the OS supports a certain feature. Features might be [code]s3tc[/code], [code]etc[/code], [code]etc2[/code] and [code]pvrtc[/code]. </description> </method> - <method name="immediate_begin"> + <method name="instance_attach_object_instance_id"> <return type="void"> </return> - <argument index="0" name="immediate" type="RID"> - </argument> - <argument index="1" name="primitive" type="int" enum="RenderingServer.PrimitiveType"> - </argument> - <argument index="2" name="texture" type="RID"> + <argument index="0" name="instance" type="RID"> </argument> - <description> - Sets up [ImmediateGeometry3D] internals to prepare for drawing. Equivalent to [method ImmediateGeometry3D.begin]. - </description> - </method> - <method name="immediate_clear"> - <return type="void"> - </return> - <argument index="0" name="immediate" type="RID"> + <argument index="1" name="id" type="int"> </argument> <description> - Clears everything that was set up between [method immediate_begin] and [method immediate_end]. Equivalent to [method ImmediateGeometry3D.clear]. + Attaches a unique Object ID to instance. Object ID must be attached to instance for proper culling with [method instances_cull_aabb], [method instances_cull_convex], and [method instances_cull_ray]. </description> </method> - <method name="immediate_color"> + <method name="instance_attach_skeleton"> <return type="void"> </return> - <argument index="0" name="immediate" type="RID"> + <argument index="0" name="instance" type="RID"> </argument> - <argument index="1" name="color" type="Color"> + <argument index="1" name="skeleton" type="RID"> </argument> <description> - Sets the color to be used with next vertex. Equivalent to [method ImmediateGeometry3D.set_color]. + Attaches a skeleton to an instance. Removes the previous skeleton from the instance. </description> </method> - <method name="immediate_create"> + <method name="instance_create"> <return type="RID"> </return> <description> - Creates an immediate geometry and adds it to the RenderingServer. It can be accessed with the RID that is returned. This RID will be used in all [code]immediate_*[/code] RenderingServer functions. + Creates a visual instance and adds it to the RenderingServer. It can be accessed with the RID that is returned. This RID will be used in all [code]instance_*[/code] RenderingServer functions. Once finished with your RID, you will want to free the RID using the RenderingServer's [method free_rid] static method. - To place in a scene, attach this immediate geometry to an instance using [method instance_set_base] using the returned RID. - </description> - </method> - <method name="immediate_end"> - <return type="void"> - </return> - <argument index="0" name="immediate" type="RID"> - </argument> - <description> - Ends drawing the [ImmediateGeometry3D] and displays it. Equivalent to [method ImmediateGeometry3D.end]. + An instance is a way of placing a 3D object in the scenario. Objects like particles, meshes, and reflection probes need to be associated with an instance to be visible in the scenario using [method instance_set_base]. </description> </method> - <method name="immediate_get_material" qualifiers="const"> + <method name="instance_create2"> <return type="RID"> </return> - <argument index="0" name="immediate" type="RID"> - </argument> - <description> - Returns the material assigned to the [ImmediateGeometry3D]. - </description> - </method> - <method name="immediate_normal"> - <return type="void"> - </return> - <argument index="0" name="immediate" type="RID"> + <argument index="0" name="base" type="RID"> </argument> - <argument index="1" name="normal" type="Vector3"> + <argument index="1" name="scenario" type="RID"> </argument> <description> - Sets the normal to be used with next vertex. Equivalent to [method ImmediateGeometry3D.set_normal]. + Creates a visual instance, adds it to the RenderingServer, and sets both base and scenario. It can be accessed with the RID that is returned. This RID will be used in all [code]instance_*[/code] RenderingServer functions. + Once finished with your RID, you will want to free the RID using the RenderingServer's [method free_rid] static method. </description> </method> - <method name="immediate_set_material"> - <return type="void"> + <method name="instance_geometry_get_shader_parameter" qualifiers="const"> + <return type="Variant"> </return> - <argument index="0" name="immediate" type="RID"> + <argument index="0" name="instance" type="RID"> </argument> - <argument index="1" name="material" type="RID"> + <argument index="1" name="parameter" type="StringName"> </argument> <description> - Sets the material to be used to draw the [ImmediateGeometry3D]. </description> </method> - <method name="immediate_tangent"> - <return type="void"> + <method name="instance_geometry_get_shader_parameter_default_value" qualifiers="const"> + <return type="Variant"> </return> - <argument index="0" name="immediate" type="RID"> + <argument index="0" name="instance" type="RID"> </argument> - <argument index="1" name="tangent" type="Plane"> + <argument index="1" name="parameter" type="StringName"> </argument> <description> - Sets the tangent to be used with next vertex. Equivalent to [method ImmediateGeometry3D.set_tangent]. </description> </method> - <method name="immediate_uv"> - <return type="void"> + <method name="instance_geometry_get_shader_parameter_list" qualifiers="const"> + <return type="Array"> </return> - <argument index="0" name="immediate" type="RID"> - </argument> - <argument index="1" name="tex_uv" type="Vector2"> + <argument index="0" name="instance" type="RID"> </argument> <description> - Sets the UV to be used with next vertex. Equivalent to [method ImmediateGeometry3D.set_uv]. </description> </method> - <method name="immediate_uv2"> + <method name="instance_geometry_set_cast_shadows_setting"> <return type="void"> </return> - <argument index="0" name="immediate" type="RID"> + <argument index="0" name="instance" type="RID"> </argument> - <argument index="1" name="tex_uv" type="Vector2"> + <argument index="1" name="shadow_casting_setting" type="int" enum="RenderingServer.ShadowCastingSetting"> </argument> <description> - Sets the UV2 to be used with next vertex. Equivalent to [method ImmediateGeometry3D.set_uv2]. + Sets the shadow casting setting to one of [enum ShadowCastingSetting]. Equivalent to [member GeometryInstance3D.cast_shadow]. </description> </method> - <method name="immediate_vertex"> + <method name="instance_geometry_set_flag"> <return type="void"> </return> - <argument index="0" name="immediate" type="RID"> - </argument> - <argument index="1" name="vertex" type="Vector3"> + <argument index="0" name="instance" type="RID"> </argument> - <description> - Adds the next vertex using the information provided in advance. Equivalent to [method ImmediateGeometry3D.add_vertex]. - </description> - </method> - <method name="immediate_vertex_2d"> - <return type="void"> - </return> - <argument index="0" name="immediate" type="RID"> + <argument index="1" name="flag" type="int" enum="RenderingServer.InstanceFlags"> </argument> - <argument index="1" name="vertex" type="Vector2"> + <argument index="2" name="enabled" type="bool"> </argument> <description> - Adds the next vertex using the information provided in advance. This is a helper class that calls [method immediate_vertex] under the hood. Equivalent to [method ImmediateGeometry3D.add_vertex]. + Sets the flag for a given [enum InstanceFlags]. See [enum InstanceFlags] for more details. </description> </method> - <method name="init"> - <return type="void"> - </return> - <description> - Initializes the rendering server. This function is called internally by platform-dependent code during engine initialization. If called from a running game, it will not do anything. - </description> - </method> - <method name="instance_attach_object_instance_id"> + <method name="instance_geometry_set_lightmap"> <return type="void"> </return> <argument index="0" name="instance" type="RID"> </argument> - <argument index="1" name="id" type="int"> + <argument index="1" name="lightmap" type="RID"> </argument> - <description> - Attaches a unique Object ID to instance. Object ID must be attached to instance for proper culling with [method instances_cull_aabb], [method instances_cull_convex], and [method instances_cull_ray]. - </description> - </method> - <method name="instance_attach_skeleton"> - <return type="void"> - </return> - <argument index="0" name="instance" type="RID"> + <argument index="2" name="lightmap_uv_scale" type="Rect2"> </argument> - <argument index="1" name="skeleton" type="RID"> + <argument index="3" name="lightmap_slice" type="int"> </argument> <description> - Attaches a skeleton to an instance. Removes the previous skeleton from the instance. </description> </method> - <method name="instance_create"> - <return type="RID"> - </return> - <description> - Creates a visual instance and adds it to the RenderingServer. It can be accessed with the RID that is returned. This RID will be used in all [code]instance_*[/code] RenderingServer functions. - Once finished with your RID, you will want to free the RID using the RenderingServer's [method free_rid] static method. - An instance is a way of placing a 3D object in the scenario. Objects like particles, meshes, and reflection probes need to be associated with an instance to be visible in the scenario using [method instance_set_base]. - </description> - </method> - <method name="instance_create2"> - <return type="RID"> - </return> - <argument index="0" name="base" type="RID"> - </argument> - <argument index="1" name="scenario" type="RID"> - </argument> - <description> - Creates a visual instance, adds it to the RenderingServer, and sets both base and scenario. It can be accessed with the RID that is returned. This RID will be used in all [code]instance_*[/code] RenderingServer functions. - Once finished with your RID, you will want to free the RID using the RenderingServer's [method free_rid] static method. - </description> - </method> - <method name="instance_geometry_set_cast_shadows_setting"> + <method name="instance_geometry_set_lod_bias"> <return type="void"> </return> <argument index="0" name="instance" type="RID"> </argument> - <argument index="1" name="shadow_casting_setting" type="int" enum="RenderingServer.ShadowCastingSetting"> + <argument index="1" name="lod_bias" type="float"> </argument> <description> - Sets the shadow casting setting to one of [enum ShadowCastingSetting]. Equivalent to [member GeometryInstance3D.cast_shadow]. </description> </method> - <method name="instance_geometry_set_flag"> + <method name="instance_geometry_set_material_override"> <return type="void"> </return> <argument index="0" name="instance" type="RID"> </argument> - <argument index="1" name="flag" type="int" enum="RenderingServer.InstanceFlags"> - </argument> - <argument index="2" name="enabled" type="bool"> + <argument index="1" name="material" type="RID"> </argument> <description> - Sets the flag for a given [enum InstanceFlags]. See [enum InstanceFlags] for more details. + Sets a material that will override the material for all surfaces on the mesh associated with this instance. Equivalent to [member GeometryInstance3D.material_override]. </description> </method> - <method name="instance_geometry_set_material_override"> + <method name="instance_geometry_set_shader_parameter"> <return type="void"> </return> <argument index="0" name="instance" type="RID"> </argument> - <argument index="1" name="material" type="RID"> + <argument index="1" name="parameter" type="StringName"> + </argument> + <argument index="2" name="value" type="Variant"> </argument> <description> - Sets a material that will override the material for all surfaces on the mesh associated with this instance. Equivalent to [member GeometryInstance3D.material_override]. </description> </method> <method name="instance_geometry_set_visibility_range"> @@ -1262,17 +1992,6 @@ Sets a custom AABB to use when culling objects from the view frustum. Equivalent to [method GeometryInstance3D.set_custom_aabb]. </description> </method> - <method name="instance_set_exterior"> - <return type="void"> - </return> - <argument index="0" name="instance" type="RID"> - </argument> - <argument index="1" name="enabled" type="bool"> - </argument> - <description> - Function not implemented in Godot 3.x. - </description> - </method> <method name="instance_set_extra_visibility_margin"> <return type="void"> </return> @@ -1401,17 +2120,6 @@ If [code]true[/code], this directional light will blend between shadow map splits resulting in a smoother transition between them. Equivalent to [member DirectionalLight3D.directional_shadow_blend_splits]. </description> </method> - <method name="light_directional_set_shadow_depth_range_mode"> - <return type="void"> - </return> - <argument index="0" name="light" type="RID"> - </argument> - <argument index="1" name="range_mode" type="int" enum="RenderingServer.LightDirectionalShadowDepthRangeMode"> - </argument> - <description> - Sets the shadow depth range mode for this directional light. Equivalent to [member DirectionalLight3D.directional_shadow_depth_range]. See [enum LightDirectionalShadowDepthRangeMode] for options. - </description> - </method> <method name="light_directional_set_shadow_mode"> <return type="void"> </return> @@ -1477,6 +2185,16 @@ Sets the cull mask for this Light3D. Lights only affect objects in the selected layers. Equivalent to [member Light3D.light_cull_mask]. </description> </method> + <method name="light_set_max_sdfgi_cascade"> + <return type="void"> + </return> + <argument index="0" name="light" type="RID"> + </argument> + <argument index="1" name="cascade" type="int"> + </argument> + <description> + </description> + </method> <method name="light_set_negative"> <return type="void"> </return> @@ -1545,6 +2263,100 @@ Sets the color of the shadow cast by the light. Equivalent to [member Light3D.shadow_color]. </description> </method> + <method name="lightmap_create"> + <return type="RID"> + </return> + <description> + </description> + </method> + <method name="lightmap_get_probe_capture_bsp_tree" qualifiers="const"> + <return type="PackedInt32Array"> + </return> + <argument index="0" name="lightmap" type="RID"> + </argument> + <description> + </description> + </method> + <method name="lightmap_get_probe_capture_points" qualifiers="const"> + <return type="PackedVector3Array"> + </return> + <argument index="0" name="lightmap" type="RID"> + </argument> + <description> + </description> + </method> + <method name="lightmap_get_probe_capture_sh" qualifiers="const"> + <return type="PackedColorArray"> + </return> + <argument index="0" name="lightmap" type="RID"> + </argument> + <description> + </description> + </method> + <method name="lightmap_get_probe_capture_tetrahedra" qualifiers="const"> + <return type="PackedInt32Array"> + </return> + <argument index="0" name="lightmap" type="RID"> + </argument> + <description> + </description> + </method> + <method name="lightmap_set_probe_bounds"> + <return type="void"> + </return> + <argument index="0" name="lightmap" type="RID"> + </argument> + <argument index="1" name="bounds" type="AABB"> + </argument> + <description> + </description> + </method> + <method name="lightmap_set_probe_capture_data"> + <return type="void"> + </return> + <argument index="0" name="lightmap" type="RID"> + </argument> + <argument index="1" name="points" type="PackedVector3Array"> + </argument> + <argument index="2" name="point_sh" type="PackedColorArray"> + </argument> + <argument index="3" name="tetrahedra" type="PackedInt32Array"> + </argument> + <argument index="4" name="bsp_tree" type="PackedInt32Array"> + </argument> + <description> + </description> + </method> + <method name="lightmap_set_probe_capture_update_speed"> + <return type="void"> + </return> + <argument index="0" name="speed" type="float"> + </argument> + <description> + </description> + </method> + <method name="lightmap_set_probe_interior"> + <return type="void"> + </return> + <argument index="0" name="lightmap" type="RID"> + </argument> + <argument index="1" name="interior" type="bool"> + </argument> + <description> + </description> + </method> + <method name="lightmap_set_textures"> + <return type="void"> + </return> + <argument index="0" name="lightmap" type="RID"> + </argument> + <argument index="1" name="light" type="RID"> + </argument> + <argument index="2" name="uses_sh" type="bool"> + </argument> + <description> + </description> + </method> <method name="make_sphere_mesh"> <return type="RID"> </return> @@ -1623,6 +2435,35 @@ Sets a shader material's shader. </description> </method> + <method name="mesh_add_surface"> + <return type="void"> + </return> + <argument index="0" name="mesh" type="RID"> + </argument> + <argument index="1" name="surface" type="Dictionary"> + </argument> + <description> + </description> + </method> + <method name="mesh_add_surface_from_arrays"> + <return type="void"> + </return> + <argument index="0" name="mesh" type="RID"> + </argument> + <argument index="1" name="primitive" type="int" enum="RenderingServer.PrimitiveType"> + </argument> + <argument index="2" name="arrays" type="Array"> + </argument> + <argument index="3" name="blend_shapes" type="Array" default="[]"> + </argument> + <argument index="4" name="lods" type="Dictionary" default="{ +}"> + </argument> + <argument index="5" name="compress_format" type="int" default="0"> + </argument> + <description> + </description> + </method> <method name="mesh_clear"> <return type="void"> </return> @@ -1641,6 +2482,16 @@ To place in a scene, attach this mesh to an instance using [method instance_set_base] using the returned RID. </description> </method> + <method name="mesh_create_from_surfaces"> + <return type="RID"> + </return> + <argument index="0" name="surfaces" type="Dictionary[]"> + </argument> + <argument index="1" name="blend_shape_count" type="int" default="0"> + </argument> + <description> + </description> + </method> <method name="mesh_get_blend_shape_count" qualifiers="const"> <return type="int"> </return> @@ -1668,6 +2519,16 @@ Returns a mesh's custom aabb. </description> </method> + <method name="mesh_get_surface"> + <return type="Dictionary"> + </return> + <argument index="0" name="mesh" type="RID"> + </argument> + <argument index="1" name="surface" type="int"> + </argument> + <description> + </description> + </method> <method name="mesh_get_surface_count" qualifiers="const"> <return type="int"> </return> @@ -1699,6 +2560,16 @@ Sets a mesh's custom aabb. </description> </method> + <method name="mesh_set_shadow_mesh"> + <return type="void"> + </return> + <argument index="0" name="mesh" type="RID"> + </argument> + <argument index="1" name="shadow_mesh" type="RID"> + </argument> + <description> + </description> + </method> <method name="mesh_surface_get_arrays" qualifiers="const"> <return type="Array"> </return> @@ -1787,7 +2658,35 @@ Sets a mesh's surface's material. </description> </method> - <method name="mesh_surface_update_region"> + <method name="mesh_surface_update_attribute_region"> + <return type="void"> + </return> + <argument index="0" name="mesh" type="RID"> + </argument> + <argument index="1" name="surface" type="int"> + </argument> + <argument index="2" name="offset" type="int"> + </argument> + <argument index="3" name="data" type="PackedByteArray"> + </argument> + <description> + </description> + </method> + <method name="mesh_surface_update_skin_region"> + <return type="void"> + </return> + <argument index="0" name="mesh" type="RID"> + </argument> + <argument index="1" name="surface" type="int"> + </argument> + <argument index="2" name="offset" type="int"> + </argument> + <argument index="3" name="data" type="PackedByteArray"> + </argument> + <description> + </description> + </method> + <method name="mesh_surface_update_vertex_region"> <return type="void"> </return> <argument index="0" name="mesh" type="RID"> @@ -1799,7 +2698,6 @@ <argument index="3" name="data" type="PackedByteArray"> </argument> <description> - Updates a specific region of a vertex buffer for the specified surface. Warning: this function alters the vertex buffer directly with no safety mechanisms, you can easily corrupt your mesh. </description> </method> <method name="multimesh_allocate_data"> @@ -2008,11 +2906,11 @@ <method name="occluder_set_mesh"> <return type="void"> </return> - <argument index="0" name="arg0" type="RID"> + <argument index="0" name="occluder" type="RID"> </argument> - <argument index="1" name="arg1" type="PackedVector3Array"> + <argument index="1" name="vertices" type="PackedVector3Array"> </argument> - <argument index="2" name="arg2" type="PackedInt32Array"> + <argument index="2" name="indices" type="PackedInt32Array"> </argument> <description> </description> @@ -2026,6 +2924,110 @@ To place in a scene, attach this omni light to an instance using [method instance_set_base] using the returned RID. </description> </method> + <method name="particles_collision_create"> + <return type="RID"> + </return> + <description> + </description> + </method> + <method name="particles_collision_height_field_update"> + <return type="void"> + </return> + <argument index="0" name="particles_collision" type="RID"> + </argument> + <description> + </description> + </method> + <method name="particles_collision_set_attractor_attenuation"> + <return type="void"> + </return> + <argument index="0" name="particles_collision" type="RID"> + </argument> + <argument index="1" name="curve" type="float"> + </argument> + <description> + </description> + </method> + <method name="particles_collision_set_attractor_directionality"> + <return type="void"> + </return> + <argument index="0" name="particles_collision" type="RID"> + </argument> + <argument index="1" name="amount" type="float"> + </argument> + <description> + </description> + </method> + <method name="particles_collision_set_attractor_strength"> + <return type="void"> + </return> + <argument index="0" name="particles_collision" type="RID"> + </argument> + <argument index="1" name="setrngth" type="float"> + </argument> + <description> + </description> + </method> + <method name="particles_collision_set_box_extents"> + <return type="void"> + </return> + <argument index="0" name="particles_collision" type="RID"> + </argument> + <argument index="1" name="extents" type="Vector3"> + </argument> + <description> + </description> + </method> + <method name="particles_collision_set_collision_type"> + <return type="void"> + </return> + <argument index="0" name="particles_collision" type="RID"> + </argument> + <argument index="1" name="type" type="int" enum="RenderingServer.ParticlesCollisionType"> + </argument> + <description> + </description> + </method> + <method name="particles_collision_set_cull_mask"> + <return type="void"> + </return> + <argument index="0" name="particles_collision" type="RID"> + </argument> + <argument index="1" name="mask" type="int"> + </argument> + <description> + </description> + </method> + <method name="particles_collision_set_field_texture"> + <return type="void"> + </return> + <argument index="0" name="particles_collision" type="RID"> + </argument> + <argument index="1" name="texture" type="RID"> + </argument> + <description> + </description> + </method> + <method name="particles_collision_set_height_field_resolution"> + <return type="void"> + </return> + <argument index="0" name="particles_collision" type="RID"> + </argument> + <argument index="1" name="resolution" type="int" enum="RenderingServer.ParticlesCollisionHeightfieldResolution"> + </argument> + <description> + </description> + </method> + <method name="particles_collision_set_sphere_radius"> + <return type="void"> + </return> + <argument index="0" name="particles_collision" type="RID"> + </argument> + <argument index="1" name="radius" type="float"> + </argument> + <description> + </description> + </method> <method name="particles_create"> <return type="RID"> </return> @@ -2035,6 +3037,24 @@ To place in a scene, attach these particles to an instance using [method instance_set_base] using the returned RID. </description> </method> + <method name="particles_emit"> + <return type="void"> + </return> + <argument index="0" name="particles" type="RID"> + </argument> + <argument index="1" name="transform" type="Transform3D"> + </argument> + <argument index="2" name="velocity" type="Vector3"> + </argument> + <argument index="3" name="color" type="Color"> + </argument> + <argument index="4" name="custom" type="Color"> + </argument> + <argument index="5" name="emit_flags" type="int"> + </argument> + <description> + </description> + </method> <method name="particles_get_current_aabb"> <return type="AABB"> </return> @@ -2091,6 +3111,16 @@ Sets the number of particles to be drawn and allocates the memory for them. Equivalent to [member GPUParticles3D.amount]. </description> </method> + <method name="particles_set_collision_base_size"> + <return type="void"> + </return> + <argument index="0" name="particles" type="RID"> + </argument> + <argument index="1" name="size" type="float"> + </argument> + <description> + </description> + </method> <method name="particles_set_custom_aabb"> <return type="void"> </return> @@ -2192,6 +3222,16 @@ If [code]true[/code], uses fractional delta which smooths the movement of the particles. Equivalent to [member GPUParticles3D.fract_delta]. </description> </method> + <method name="particles_set_interpolate"> + <return type="void"> + </return> + <argument index="0" name="particles" type="RID"> + </argument> + <argument index="1" name="enable" type="bool"> + </argument> + <description> + </description> + </method> <method name="particles_set_lifetime"> <return type="void"> </return> @@ -2203,6 +3243,16 @@ Sets the lifetime of each particle in the system. Equivalent to [member GPUParticles3D.lifetime]. </description> </method> + <method name="particles_set_mode"> + <return type="void"> + </return> + <argument index="0" name="particles" type="RID"> + </argument> + <argument index="1" name="mode" type="int" enum="RenderingServer.ParticlesMode"> + </argument> + <description> + </description> + </method> <method name="particles_set_one_shot"> <return type="void"> </return> @@ -2258,6 +3308,48 @@ Sets the speed scale of the particle system. Equivalent to [member GPUParticles3D.speed_scale]. </description> </method> + <method name="particles_set_subemitter"> + <return type="void"> + </return> + <argument index="0" name="particles" type="RID"> + </argument> + <argument index="1" name="subemitter_particles" type="RID"> + </argument> + <description> + </description> + </method> + <method name="particles_set_trail_bind_poses"> + <return type="void"> + </return> + <argument index="0" name="particles" type="RID"> + </argument> + <argument index="1" name="bind_poses" type="Transform3D[]"> + </argument> + <description> + </description> + </method> + <method name="particles_set_trails"> + <return type="void"> + </return> + <argument index="0" name="particles" type="RID"> + </argument> + <argument index="1" name="enable" type="bool"> + </argument> + <argument index="2" name="length_sec" type="float"> + </argument> + <description> + </description> + </method> + <method name="particles_set_transform_align"> + <return type="void"> + </return> + <argument index="0" name="particles" type="RID"> + </argument> + <argument index="1" name="align" type="int" enum="RenderingServer.ParticlesTransformAlign"> + </argument> + <description> + </description> + </method> <method name="particles_set_use_local_coordinates"> <return type="void"> </return> @@ -2374,6 +3466,16 @@ Sets the intensity of the reflection probe. Intensity modulates the strength of the reflection. Equivalent to [member ReflectionProbe.intensity]. </description> </method> + <method name="reflection_probe_set_lod_threshold"> + <return type="void"> + </return> + <argument index="0" name="probe" type="RID"> + </argument> + <argument index="1" name="pixels" type="float"> + </argument> + <description> + </description> + </method> <method name="reflection_probe_set_max_distance"> <return type="void"> </return> @@ -2396,6 +3498,16 @@ Sets the origin offset to be used when this reflection probe is in box project mode. Equivalent to [member ReflectionProbe.origin_offset]. </description> </method> + <method name="reflection_probe_set_resolution"> + <return type="void"> + </return> + <argument index="0" name="probe" type="RID"> + </argument> + <argument index="1" name="resolution" type="int"> + </argument> + <description> + </description> + </method> <method name="reflection_probe_set_update_mode"> <return type="void"> </return> @@ -2440,18 +3552,18 @@ <description> </description> </method> - <method name="scenario_set_debug"> + <method name="scenario_set_environment"> <return type="void"> </return> <argument index="0" name="scenario" type="RID"> </argument> - <argument index="1" name="debug_mode" type="int" enum="RenderingServer.ScenarioDebugMode"> + <argument index="1" name="environment" type="RID"> </argument> <description> - Sets the [enum ScenarioDebugMode] for this scenario. See [enum ScenarioDebugMode] for options. + Sets the environment that will be used with this scenario. </description> </method> - <method name="scenario_set_environment"> + <method name="scenario_set_fallback_environment"> <return type="void"> </return> <argument index="0" name="scenario" type="RID"> @@ -2459,18 +3571,19 @@ <argument index="1" name="environment" type="RID"> </argument> <description> - Sets the environment that will be used with this scenario. + Sets the fallback environment to be used by this scenario. The fallback environment is used if no environment is set. Internally, this is used by the editor to provide a default environment. </description> </method> - <method name="scenario_set_fallback_environment"> + <method name="screen_space_roughness_limiter_set_active"> <return type="void"> </return> - <argument index="0" name="scenario" type="RID"> + <argument index="0" name="enable" type="bool"> </argument> - <argument index="1" name="environment" type="RID"> + <argument index="1" name="amount" type="float"> + </argument> + <argument index="2" name="limit" type="float"> </argument> <description> - Sets the fallback environment to be used by this scenario. The fallback environment is used if no environment is set. Internally, this is used by the editor to provide a default environment. </description> </method> <method name="set_boot_image"> @@ -2528,7 +3641,7 @@ </return> <argument index="0" name="shader" type="RID"> </argument> - <argument index="1" name="name" type="StringName"> + <argument index="1" name="param" type="StringName"> </argument> <description> Returns a default texture from a shader searched by name. @@ -2537,15 +3650,15 @@ <method name="shader_get_param_default" qualifiers="const"> <return type="Variant"> </return> - <argument index="0" name="material" type="RID"> + <argument index="0" name="shader" type="RID"> </argument> - <argument index="1" name="parameter" type="StringName"> + <argument index="1" name="param" type="StringName"> </argument> <description> </description> </method> <method name="shader_get_param_list" qualifiers="const"> - <return type="Array"> + <return type="Dictionary[]"> </return> <argument index="0" name="shader" type="RID"> </argument> @@ -2553,28 +3666,25 @@ Returns the parameters of a shader. </description> </method> - <method name="shader_set_code"> + <method name="shader_set_default_texture_param"> <return type="void"> </return> <argument index="0" name="shader" type="RID"> </argument> - <argument index="1" name="code" type="String"> + <argument index="1" name="param" type="StringName"> + </argument> + <argument index="2" name="texture" type="RID"> </argument> <description> - Sets a shader's code. + Sets a shader's default texture. Overwrites the texture given by name. </description> </method> - <method name="shader_set_default_texture_param"> + <method name="shadows_quality_set"> <return type="void"> </return> - <argument index="0" name="shader" type="RID"> - </argument> - <argument index="1" name="name" type="StringName"> - </argument> - <argument index="2" name="texture" type="RID"> + <argument index="0" name="quality" type="int" enum="RenderingServer.ShadowQuality"> </argument> <description> - Sets a shader's default texture. Overwrites the texture given by name. </description> </method> <method name="skeleton_allocate_data"> @@ -2654,6 +3764,30 @@ Returns the number of bones allocated for this skeleton. </description> </method> + <method name="skeleton_set_base_transform_2d"> + <return type="void"> + </return> + <argument index="0" name="skeleton" type="RID"> + </argument> + <argument index="1" name="base_transform" type="Transform2D"> + </argument> + <description> + </description> + </method> + <method name="sky_bake_panorama"> + <return type="Image"> + </return> + <argument index="0" name="sky" type="RID"> + </argument> + <argument index="1" name="energy" type="float"> + </argument> + <argument index="2" name="bake_irradiance" type="bool"> + </argument> + <argument index="3" name="size" type="Vector2i"> + </argument> + <description> + </description> + </method> <method name="sky_create"> <return type="RID"> </return> @@ -2673,6 +3807,26 @@ Sets the material that the sky uses to render the background and reflection maps. </description> </method> + <method name="sky_set_mode"> + <return type="void"> + </return> + <argument index="0" name="sky" type="RID"> + </argument> + <argument index="1" name="mode" type="int" enum="RenderingServer.SkyMode"> + </argument> + <description> + </description> + </method> + <method name="sky_set_radiance_size"> + <return type="void"> + </return> + <argument index="0" name="sky" type="RID"> + </argument> + <argument index="1" name="radiance_size" type="int"> + </argument> + <description> + </description> + </method> <method name="spot_light_create"> <return type="RID"> </return> @@ -2682,6 +3836,24 @@ To place in a scene, attach this spot light to an instance using [method instance_set_base] using the returned RID. </description> </method> + <method name="sub_surface_scattering_set_quality"> + <return type="void"> + </return> + <argument index="0" name="quality" type="int" enum="RenderingServer.SubSurfaceScatteringQuality"> + </argument> + <description> + </description> + </method> + <method name="sub_surface_scattering_set_scale"> + <return type="void"> + </return> + <argument index="0" name="scale" type="float"> + </argument> + <argument index="1" name="depth_scale" type="float"> + </argument> + <description> + </description> + </method> <method name="texture_2d_create"> <return type="RID"> </return> @@ -2698,6 +3870,162 @@ <description> </description> </method> + <method name="texture_2d_layer_get" qualifiers="const"> + <return type="Image"> + </return> + <argument index="0" name="texture" type="RID"> + </argument> + <argument index="1" name="layer" type="int"> + </argument> + <description> + </description> + </method> + <method name="texture_2d_layered_create"> + <return type="RID"> + </return> + <argument index="0" name="layers" type="Image[]"> + </argument> + <argument index="1" name="layered_type" type="int" enum="RenderingServer.TextureLayeredType"> + </argument> + <description> + </description> + </method> + <method name="texture_2d_layered_placeholder_create"> + <return type="RID"> + </return> + <argument index="0" name="layered_type" type="int" enum="RenderingServer.TextureLayeredType"> + </argument> + <description> + </description> + </method> + <method name="texture_2d_placeholder_create"> + <return type="RID"> + </return> + <description> + </description> + </method> + <method name="texture_2d_update"> + <return type="void"> + </return> + <argument index="0" name="texture" type="RID"> + </argument> + <argument index="1" name="image" type="Image"> + </argument> + <argument index="2" name="layer" type="int"> + </argument> + <description> + </description> + </method> + <method name="texture_3d_create"> + <return type="RID"> + </return> + <argument index="0" name="format" type="int" enum="Image.Format"> + </argument> + <argument index="1" name="width" type="int"> + </argument> + <argument index="2" name="height" type="int"> + </argument> + <argument index="3" name="depth" type="int"> + </argument> + <argument index="4" name="mipmaps" type="bool"> + </argument> + <argument index="5" name="data" type="Image[]"> + </argument> + <description> + </description> + </method> + <method name="texture_3d_get" qualifiers="const"> + <return type="Image[]"> + </return> + <argument index="0" name="texture" type="RID"> + </argument> + <description> + </description> + </method> + <method name="texture_3d_placeholder_create"> + <return type="RID"> + </return> + <description> + </description> + </method> + <method name="texture_3d_update"> + <return type="void"> + </return> + <argument index="0" name="texture" type="RID"> + </argument> + <argument index="1" name="data" type="Image[]"> + </argument> + <description> + </description> + </method> + <method name="texture_get_path" qualifiers="const"> + <return type="String"> + </return> + <argument index="0" name="texture" type="RID"> + </argument> + <description> + </description> + </method> + <method name="texture_proxy_create"> + <return type="RID"> + </return> + <argument index="0" name="base" type="RID"> + </argument> + <description> + </description> + </method> + <method name="texture_proxy_update"> + <return type="void"> + </return> + <argument index="0" name="texture" type="RID"> + </argument> + <argument index="1" name="proxy_to" type="RID"> + </argument> + <description> + </description> + </method> + <method name="texture_replace"> + <return type="void"> + </return> + <argument index="0" name="texture" type="RID"> + </argument> + <argument index="1" name="by_texture" type="RID"> + </argument> + <description> + </description> + </method> + <method name="texture_set_force_redraw_if_visible"> + <return type="void"> + </return> + <argument index="0" name="texture" type="RID"> + </argument> + <argument index="1" name="enable" type="bool"> + </argument> + <description> + </description> + </method> + <method name="texture_set_path"> + <return type="void"> + </return> + <argument index="0" name="texture" type="RID"> + </argument> + <argument index="1" name="path" type="String"> + </argument> + <description> + </description> + </method> + <method name="texture_set_size_override"> + <return type="void"> + </return> + <argument index="0" name="texture" type="RID"> + </argument> + <argument index="1" name="width" type="int"> + </argument> + <argument index="2" name="height" type="int"> + </argument> + <description> + </description> + </method> <method name="viewport_attach_camera"> <return type="void"> </return> @@ -2772,10 +4100,11 @@ </return> <argument index="0" name="viewport" type="RID"> </argument> - <argument index="1" name="info" type="int" enum="RenderingServer.ViewportRenderInfo"> + <argument index="1" name="type" type="int" enum="RenderingServer.ViewportRenderInfoType"> + </argument> + <argument index="2" name="info" type="int" enum="RenderingServer.ViewportRenderInfo"> </argument> <description> - Returns a viewport's render information. For options, see the [enum ViewportRenderInfo] constants. </description> </method> <method name="viewport_get_texture" qualifiers="const"> @@ -2860,48 +4189,67 @@ Sets the debug draw mode of a viewport. See [enum ViewportDebugDraw] for options. </description> </method> - <method name="viewport_set_disable_environment"> + <method name="viewport_set_default_canvas_item_texture_filter"> <return type="void"> </return> <argument index="0" name="viewport" type="RID"> </argument> - <argument index="1" name="disabled" type="bool"> + <argument index="1" name="filter" type="int" enum="RenderingServer.CanvasItemTextureFilter"> </argument> <description> - If [code]true[/code], rendering of a viewport's environment is disabled. </description> </method> - <method name="viewport_set_global_canvas_transform"> + <method name="viewport_set_default_canvas_item_texture_repeat"> <return type="void"> </return> <argument index="0" name="viewport" type="RID"> </argument> - <argument index="1" name="transform" type="Transform2D"> + <argument index="1" name="repeat" type="int" enum="RenderingServer.CanvasItemTextureRepeat"> </argument> <description> - Sets the viewport's global transformation matrix. </description> </method> - <method name="viewport_set_hide_canvas"> + <method name="viewport_set_disable_2d"> <return type="void"> </return> <argument index="0" name="viewport" type="RID"> </argument> - <argument index="1" name="hidden" type="bool"> + <argument index="1" name="disable" type="bool"> </argument> <description> If [code]true[/code], the viewport's canvas is not rendered. </description> </method> - <method name="viewport_set_hide_scenario"> + <method name="viewport_set_disable_3d"> + <return type="void"> + </return> + <argument index="0" name="viewport" type="RID"> + </argument> + <argument index="1" name="disable" type="bool"> + </argument> + <description> + </description> + </method> + <method name="viewport_set_disable_environment"> <return type="void"> </return> <argument index="0" name="viewport" type="RID"> </argument> - <argument index="1" name="hidden" type="bool"> + <argument index="1" name="disabled" type="bool"> </argument> <description> - Currently unimplemented in Godot 3.x. + If [code]true[/code], rendering of a viewport's environment is disabled. + </description> + </method> + <method name="viewport_set_global_canvas_transform"> + <return type="void"> + </return> + <argument index="0" name="viewport" type="RID"> + </argument> + <argument index="1" name="transform" type="Transform2D"> + </argument> + <description> + Sets the viewport's global transformation matrix. </description> </method> <method name="viewport_set_measure_render_time"> @@ -2972,7 +4320,29 @@ </argument> <description> Sets a viewport's scenario. - The scenario contains information about the [enum ScenarioDebugMode], environment information, reflection atlas etc. + The scenario contains information about environment information, reflection atlas etc. + </description> + </method> + <method name="viewport_set_screen_space_aa"> + <return type="void"> + </return> + <argument index="0" name="viewport" type="RID"> + </argument> + <argument index="1" name="mode" type="int" enum="RenderingServer.ViewportScreenSpaceAA"> + </argument> + <description> + </description> + </method> + <method name="viewport_set_sdf_oversize_and_scale"> + <return type="void"> + </return> + <argument index="0" name="viewport" type="RID"> + </argument> + <argument index="1" name="oversize" type="int" enum="RenderingServer.ViewportSDFOversize"> + </argument> + <argument index="2" name="scale" type="int" enum="RenderingServer.ViewportSDFScale"> + </argument> + <description> </description> </method> <method name="viewport_set_shadow_atlas_quadrant_subdivision"> @@ -3014,6 +4384,26 @@ Sets the viewport's width and height. </description> </method> + <method name="viewport_set_snap_2d_transforms_to_pixel"> + <return type="void"> + </return> + <argument index="0" name="viewport" type="RID"> + </argument> + <argument index="1" name="enabled" type="bool"> + </argument> + <description> + </description> + </method> + <method name="viewport_set_snap_2d_vertices_to_pixel"> + <return type="void"> + </return> + <argument index="0" name="viewport" type="RID"> + </argument> + <argument index="1" name="enabled" type="bool"> + </argument> + <description> + </description> + </method> <method name="viewport_set_transparent_background"> <return type="void"> </return> @@ -3067,6 +4457,188 @@ If [code]true[/code], the viewport uses augmented or virtual reality technologies. See [XRInterface]. </description> </method> + <method name="visibility_notifier_create"> + <return type="RID"> + </return> + <description> + </description> + </method> + <method name="visibility_notifier_set_aabb"> + <return type="void"> + </return> + <argument index="0" name="notifier" type="RID"> + </argument> + <argument index="1" name="aabb" type="AABB"> + </argument> + <description> + </description> + </method> + <method name="visibility_notifier_set_callbacks"> + <return type="void"> + </return> + <argument index="0" name="notifier" type="RID"> + </argument> + <argument index="1" name="enter_callable" type="Callable"> + </argument> + <argument index="2" name="exit_callable" type="Callable"> + </argument> + <description> + </description> + </method> + <method name="voxel_gi_allocate_data"> + <return type="void"> + </return> + <argument index="0" name="voxel_gi" type="RID"> + </argument> + <argument index="1" name="to_cell_xform" type="Transform3D"> + </argument> + <argument index="2" name="aabb" type="AABB"> + </argument> + <argument index="3" name="octree_size" type="Vector3i"> + </argument> + <argument index="4" name="octree_cells" type="PackedByteArray"> + </argument> + <argument index="5" name="data_cells" type="PackedByteArray"> + </argument> + <argument index="6" name="distance_field" type="PackedByteArray"> + </argument> + <argument index="7" name="level_counts" type="PackedInt32Array"> + </argument> + <description> + </description> + </method> + <method name="voxel_gi_create"> + <return type="RID"> + </return> + <description> + </description> + </method> + <method name="voxel_gi_get_data_cells" qualifiers="const"> + <return type="PackedByteArray"> + </return> + <argument index="0" name="voxel_gi" type="RID"> + </argument> + <description> + </description> + </method> + <method name="voxel_gi_get_distance_field" qualifiers="const"> + <return type="PackedByteArray"> + </return> + <argument index="0" name="voxel_gi" type="RID"> + </argument> + <description> + </description> + </method> + <method name="voxel_gi_get_level_counts" qualifiers="const"> + <return type="PackedInt32Array"> + </return> + <argument index="0" name="voxel_gi" type="RID"> + </argument> + <description> + </description> + </method> + <method name="voxel_gi_get_octree_cells" qualifiers="const"> + <return type="PackedByteArray"> + </return> + <argument index="0" name="voxel_gi" type="RID"> + </argument> + <description> + </description> + </method> + <method name="voxel_gi_get_octree_size" qualifiers="const"> + <return type="Vector3i"> + </return> + <argument index="0" name="voxel_gi" type="RID"> + </argument> + <description> + </description> + </method> + <method name="voxel_gi_get_to_cell_xform" qualifiers="const"> + <return type="Transform3D"> + </return> + <argument index="0" name="voxel_gi" type="RID"> + </argument> + <description> + </description> + </method> + <method name="voxel_gi_set_bias"> + <return type="void"> + </return> + <argument index="0" name="voxel_gi" type="RID"> + </argument> + <argument index="1" name="bias" type="float"> + </argument> + <description> + </description> + </method> + <method name="voxel_gi_set_dynamic_range"> + <return type="void"> + </return> + <argument index="0" name="voxel_gi" type="RID"> + </argument> + <argument index="1" name="range" type="float"> + </argument> + <description> + </description> + </method> + <method name="voxel_gi_set_energy"> + <return type="void"> + </return> + <argument index="0" name="voxel_gi" type="RID"> + </argument> + <argument index="1" name="energy" type="float"> + </argument> + <description> + </description> + </method> + <method name="voxel_gi_set_interior"> + <return type="void"> + </return> + <argument index="0" name="voxel_gi" type="RID"> + </argument> + <argument index="1" name="enable" type="bool"> + </argument> + <description> + </description> + </method> + <method name="voxel_gi_set_normal_bias"> + <return type="void"> + </return> + <argument index="0" name="voxel_gi" type="RID"> + </argument> + <argument index="1" name="bias" type="float"> + </argument> + <description> + </description> + </method> + <method name="voxel_gi_set_propagation"> + <return type="void"> + </return> + <argument index="0" name="voxel_gi" type="RID"> + </argument> + <argument index="1" name="amount" type="float"> + </argument> + <description> + </description> + </method> + <method name="voxel_gi_set_quality"> + <return type="void"> + </return> + <argument index="0" name="quality" type="int" enum="RenderingServer.VoxelGIQuality"> + </argument> + <description> + </description> + </method> + <method name="voxel_gi_set_use_two_bounces"> + <return type="void"> + </return> + <argument index="0" name="voxel_gi" type="RID"> + </argument> + <argument index="1" name="enable" type="bool"> + </argument> + <description> + </description> + </method> </methods> <members> <member name="render_loop_enabled" type="bool" setter="set_render_loop_enabled" getter="is_render_loop_enabled"> @@ -3104,6 +4676,8 @@ <constant name="MAX_CURSORS" value="8"> Unused enum in Godot 3.x. </constant> + <constant name="MAX_2D_DIRECTIONAL_LIGHTS" value="8"> + </constant> <constant name="TEXTURE_LAYERED_2D_ARRAY" value="0" enum="TextureLayeredType"> </constant> <constant name="TEXTURE_LAYERED_CUBEMAP" value="1" enum="TextureLayeredType"> @@ -3181,6 +4755,26 @@ <constant name="ARRAY_MAX" value="13" enum="ArrayType"> Represents the size of the [enum ArrayType] enum. </constant> + <constant name="ARRAY_CUSTOM_COUNT" value="4"> + </constant> + <constant name="ARRAY_CUSTOM_RGBA8_UNORM" value="0" enum="ArrayCustomFormat"> + </constant> + <constant name="ARRAY_CUSTOM_RGBA8_SNORM" value="1" enum="ArrayCustomFormat"> + </constant> + <constant name="ARRAY_CUSTOM_RG_HALF" value="2" enum="ArrayCustomFormat"> + </constant> + <constant name="ARRAY_CUSTOM_RGBA_HALF" value="3" enum="ArrayCustomFormat"> + </constant> + <constant name="ARRAY_CUSTOM_R_FLOAT" value="4" enum="ArrayCustomFormat"> + </constant> + <constant name="ARRAY_CUSTOM_RG_FLOAT" value="5" enum="ArrayCustomFormat"> + </constant> + <constant name="ARRAY_CUSTOM_RGB_FLOAT" value="6" enum="ArrayCustomFormat"> + </constant> + <constant name="ARRAY_CUSTOM_RGBA_FLOAT" value="7" enum="ArrayCustomFormat"> + </constant> + <constant name="ARRAY_CUSTOM_MAX" value="8" enum="ArrayCustomFormat"> + </constant> <constant name="ARRAY_FORMAT_VERTEX" value="1" enum="ArrayFormat"> Flag used to mark a vertex array. </constant> @@ -3220,6 +4814,8 @@ </constant> <constant name="ARRAY_FORMAT_CUSTOM_BASE" value="13" enum="ArrayFormat"> </constant> + <constant name="ARRAY_FORMAT_CUSTOM_BITS" value="3" enum="ArrayFormat"> + </constant> <constant name="ARRAY_FORMAT_CUSTOM0_SHIFT" value="13" enum="ArrayFormat"> </constant> <constant name="ARRAY_FORMAT_CUSTOM1_SHIFT" value="16" enum="ArrayFormat"> @@ -3328,6 +4924,8 @@ <constant name="LIGHT_PARAM_SHADOW_BLUR" value="16" enum="LightParam"> Blurs the edges of the shadow. Can be used to hide pixel artifacts in low resolution shadow maps. A high value can make shadows appear grainy and can cause other unwanted artifacts. Try to keep as near default as possible. </constant> + <constant name="LIGHT_PARAM_SHADOW_VOLUMETRIC_FOG_FADE" value="17" enum="LightParam"> + </constant> <constant name="LIGHT_PARAM_TRANSMITTANCE_BIAS" value="18" enum="LightParam"> </constant> <constant name="LIGHT_PARAM_MAX" value="19" enum="LightParam"> @@ -3354,11 +4952,17 @@ <constant name="LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS" value="2" enum="LightDirectionalShadowMode"> Use 4 splits for shadow projection when using directional light. </constant> - <constant name="LIGHT_DIRECTIONAL_SHADOW_DEPTH_RANGE_STABLE" value="0" enum="LightDirectionalShadowDepthRangeMode"> - Keeps shadows stable as camera moves but has lower effective resolution. + <constant name="SHADOW_QUALITY_HARD" value="0" enum="ShadowQuality"> + </constant> + <constant name="SHADOW_QUALITY_SOFT_LOW" value="1" enum="ShadowQuality"> + </constant> + <constant name="SHADOW_QUALITY_SOFT_MEDIUM" value="2" enum="ShadowQuality"> + </constant> + <constant name="SHADOW_QUALITY_SOFT_HIGH" value="3" enum="ShadowQuality"> + </constant> + <constant name="SHADOW_QUALITY_SOFT_ULTRA" value="4" enum="ShadowQuality"> </constant> - <constant name="LIGHT_DIRECTIONAL_SHADOW_DEPTH_RANGE_OPTIMIZED" value="1" enum="LightDirectionalShadowDepthRangeMode"> - Optimize use of shadow maps, increasing the effective resolution. But may result in shadows moving or flickering slightly. + <constant name="SHADOW_QUALITY_MAX" value="5" enum="ShadowQuality"> </constant> <constant name="REFLECTION_PROBE_UPDATE_ONCE" value="0" enum="ReflectionProbeUpdateMode"> Reflection probe will update reflections once and then stop. @@ -3382,15 +4986,71 @@ </constant> <constant name="DECAL_TEXTURE_MAX" value="4" enum="DecalTexture"> </constant> + <constant name="VOXEL_GI_QUALITY_LOW" value="0" enum="VoxelGIQuality"> + </constant> + <constant name="VOXEL_GI_QUALITY_HIGH" value="1" enum="VoxelGIQuality"> + </constant> + <constant name="PARTICLES_MODE_2D" value="0" enum="ParticlesMode"> + </constant> + <constant name="PARTICLES_MODE_3D" value="1" enum="ParticlesMode"> + </constant> + <constant name="PARTICLES_TRANSFORM_ALIGN_DISABLED" value="0" enum="ParticlesTransformAlign"> + </constant> + <constant name="PARTICLES_TRANSFORM_ALIGN_Z_BILLBOARD" value="1" enum="ParticlesTransformAlign"> + </constant> + <constant name="PARTICLES_TRANSFORM_ALIGN_Y_TO_VELOCITY" value="2" enum="ParticlesTransformAlign"> + </constant> + <constant name="PARTICLES_TRANSFORM_ALIGN_Z_BILLBOARD_Y_TO_VELOCITY" value="3" enum="ParticlesTransformAlign"> + </constant> + <constant name="PARTICLES_EMIT_FLAG_POSITION" value="1"> + </constant> + <constant name="PARTICLES_EMIT_FLAG_ROTATION_SCALE" value="2"> + </constant> + <constant name="PARTICLES_EMIT_FLAG_VELOCITY" value="4"> + </constant> + <constant name="PARTICLES_EMIT_FLAG_COLOR" value="8"> + </constant> + <constant name="PARTICLES_EMIT_FLAG_CUSTOM" value="16"> + </constant> <constant name="PARTICLES_DRAW_ORDER_INDEX" value="0" enum="ParticlesDrawOrder"> Draw particles in the order that they appear in the particles array. </constant> <constant name="PARTICLES_DRAW_ORDER_LIFETIME" value="1" enum="ParticlesDrawOrder"> Sort particles based on their lifetime. </constant> + <constant name="PARTICLES_DRAW_ORDER_REVERSE_LIFETIME" value="2" enum="ParticlesDrawOrder"> + </constant> <constant name="PARTICLES_DRAW_ORDER_VIEW_DEPTH" value="3" enum="ParticlesDrawOrder"> Sort particles based on their distance to the camera. </constant> + <constant name="PARTICLES_COLLISION_TYPE_SPHERE_ATTRACT" value="0" enum="ParticlesCollisionType"> + </constant> + <constant name="PARTICLES_COLLISION_TYPE_BOX_ATTRACT" value="1" enum="ParticlesCollisionType"> + </constant> + <constant name="PARTICLES_COLLISION_TYPE_VECTOR_FIELD_ATTRACT" value="2" enum="ParticlesCollisionType"> + </constant> + <constant name="PARTICLES_COLLISION_TYPE_SPHERE_COLLIDE" value="3" enum="ParticlesCollisionType"> + </constant> + <constant name="PARTICLES_COLLISION_TYPE_BOX_COLLIDE" value="4" enum="ParticlesCollisionType"> + </constant> + <constant name="PARTICLES_COLLISION_TYPE_SDF_COLLIDE" value="5" enum="ParticlesCollisionType"> + </constant> + <constant name="PARTICLES_COLLISION_TYPE_HEIGHTFIELD_COLLIDE" value="6" enum="ParticlesCollisionType"> + </constant> + <constant name="PARTICLES_COLLISION_HEIGHTFIELD_RESOLUTION_256" value="0" enum="ParticlesCollisionHeightfieldResolution"> + </constant> + <constant name="PARTICLES_COLLISION_HEIGHTFIELD_RESOLUTION_512" value="1" enum="ParticlesCollisionHeightfieldResolution"> + </constant> + <constant name="PARTICLES_COLLISION_HEIGHTFIELD_RESOLUTION_1024" value="2" enum="ParticlesCollisionHeightfieldResolution"> + </constant> + <constant name="PARTICLES_COLLISION_HEIGHTFIELD_RESOLUTION_2048" value="3" enum="ParticlesCollisionHeightfieldResolution"> + </constant> + <constant name="PARTICLES_COLLISION_HEIGHTFIELD_RESOLUTION_4096" value="4" enum="ParticlesCollisionHeightfieldResolution"> + </constant> + <constant name="PARTICLES_COLLISION_HEIGHTFIELD_RESOLUTION_8192" value="5" enum="ParticlesCollisionHeightfieldResolution"> + </constant> + <constant name="PARTICLES_COLLISION_HEIGHTFIELD_RESOLUTION_MAX" value="6" enum="ParticlesCollisionHeightfieldResolution"> + </constant> <constant name="VIEWPORT_UPDATE_DISABLED" value="0" enum="ViewportUpdateMode"> Do not update the viewport. </constant> @@ -3414,6 +5074,24 @@ <constant name="VIEWPORT_CLEAR_ONLY_NEXT_FRAME" value="2" enum="ViewportClearMode"> The viewport is cleared once, then the clear mode is set to [constant VIEWPORT_CLEAR_NEVER]. </constant> + <constant name="VIEWPORT_SDF_OVERSIZE_100_PERCENT" value="0" enum="ViewportSDFOversize"> + </constant> + <constant name="VIEWPORT_SDF_OVERSIZE_120_PERCENT" value="1" enum="ViewportSDFOversize"> + </constant> + <constant name="VIEWPORT_SDF_OVERSIZE_150_PERCENT" value="2" enum="ViewportSDFOversize"> + </constant> + <constant name="VIEWPORT_SDF_OVERSIZE_200_PERCENT" value="3" enum="ViewportSDFOversize"> + </constant> + <constant name="VIEWPORT_SDF_OVERSIZE_MAX" value="4" enum="ViewportSDFOversize"> + </constant> + <constant name="VIEWPORT_SDF_SCALE_100_PERCENT" value="0" enum="ViewportSDFScale"> + </constant> + <constant name="VIEWPORT_SDF_SCALE_50_PERCENT" value="1" enum="ViewportSDFScale"> + </constant> + <constant name="VIEWPORT_SDF_SCALE_25_PERCENT" value="2" enum="ViewportSDFScale"> + </constant> + <constant name="VIEWPORT_SDF_SCALE_MAX" value="3" enum="ViewportSDFScale"> + </constant> <constant name="VIEWPORT_MSAA_DISABLED" value="0" enum="ViewportMSAA"> Multisample antialiasing is disabled. </constant> @@ -3437,26 +5115,29 @@ </constant> <constant name="VIEWPORT_SCREEN_SPACE_AA_MAX" value="2" enum="ViewportScreenSpaceAA"> </constant> + <constant name="VIEWPORT_OCCLUSION_BUILD_QUALITY_LOW" value="0" enum="ViewportOcclusionCullingBuildQuality"> + </constant> + <constant name="VIEWPORT_OCCLUSION_BUILD_QUALITY_MEDIUM" value="1" enum="ViewportOcclusionCullingBuildQuality"> + </constant> + <constant name="VIEWPORT_OCCLUSION_BUILD_QUALITY_HIGH" value="2" enum="ViewportOcclusionCullingBuildQuality"> + </constant> <constant name="VIEWPORT_RENDER_INFO_OBJECTS_IN_FRAME" value="0" enum="ViewportRenderInfo"> Number of objects drawn in a single frame. </constant> - <constant name="VIEWPORT_RENDER_INFO_VERTICES_IN_FRAME" value="1" enum="ViewportRenderInfo"> + <constant name="VIEWPORT_RENDER_INFO_PRIMITIVES_IN_FRAME" value="1" enum="ViewportRenderInfo"> Number of vertices drawn in a single frame. </constant> - <constant name="VIEWPORT_RENDER_INFO_MATERIAL_CHANGES_IN_FRAME" value="2" enum="ViewportRenderInfo"> - Number of material changes during this frame. + <constant name="VIEWPORT_RENDER_INFO_DRAW_CALLS_IN_FRAME" value="2" enum="ViewportRenderInfo"> + Number of draw calls during this frame. </constant> - <constant name="VIEWPORT_RENDER_INFO_SHADER_CHANGES_IN_FRAME" value="3" enum="ViewportRenderInfo"> - Number of shader changes during this frame. + <constant name="VIEWPORT_RENDER_INFO_MAX" value="3" enum="ViewportRenderInfo"> + Represents the size of the [enum ViewportRenderInfo] enum. </constant> - <constant name="VIEWPORT_RENDER_INFO_SURFACE_CHANGES_IN_FRAME" value="4" enum="ViewportRenderInfo"> - Number of surface changes during this frame. + <constant name="VIEWPORT_RENDER_INFO_TYPE_VISIBLE" value="0" enum="ViewportRenderInfoType"> </constant> - <constant name="VIEWPORT_RENDER_INFO_DRAW_CALLS_IN_FRAME" value="5" enum="ViewportRenderInfo"> - Number of draw calls during this frame. + <constant name="VIEWPORT_RENDER_INFO_TYPE_SHADOW" value="1" enum="ViewportRenderInfoType"> </constant> - <constant name="VIEWPORT_RENDER_INFO_MAX" value="6" enum="ViewportRenderInfo"> - Represents the size of the [enum ViewportRenderInfo] enum. + <constant name="VIEWPORT_RENDER_INFO_TYPE_MAX" value="2" enum="ViewportRenderInfoType"> </constant> <constant name="VIEWPORT_DEBUG_DRAW_DISABLED" value="0" enum="ViewportDebugDraw"> Debug draw is disabled. Default setting. @@ -3508,11 +5189,25 @@ </constant> <constant name="VIEWPORT_DEBUG_DRAW_GI_BUFFER" value="17" enum="ViewportDebugDraw"> </constant> + <constant name="VIEWPORT_DEBUG_DRAW_DISABLE_LOD" value="18" enum="ViewportDebugDraw"> + </constant> + <constant name="VIEWPORT_DEBUG_DRAW_CLUSTER_OMNI_LIGHTS" value="19" enum="ViewportDebugDraw"> + </constant> + <constant name="VIEWPORT_DEBUG_DRAW_CLUSTER_SPOT_LIGHTS" value="20" enum="ViewportDebugDraw"> + </constant> + <constant name="VIEWPORT_DEBUG_DRAW_CLUSTER_DECALS" value="21" enum="ViewportDebugDraw"> + </constant> + <constant name="VIEWPORT_DEBUG_DRAW_CLUSTER_REFLECTION_PROBES" value="22" enum="ViewportDebugDraw"> + </constant> <constant name="VIEWPORT_DEBUG_DRAW_OCCLUDERS" value="23" enum="ViewportDebugDraw"> </constant> + <constant name="SKY_MODE_AUTOMATIC" value="0" enum="SkyMode"> + </constant> <constant name="SKY_MODE_QUALITY" value="1" enum="SkyMode"> Uses high quality importance sampling to process the radiance map. In general, this results in much higher quality than [constant Sky.PROCESS_MODE_REALTIME] but takes much longer to generate. This should not be used if you plan on changing the sky at runtime. If you are finding that the reflection is not blurry enough and is showing sparkles or fireflies, try increasing [member ProjectSettings.rendering/reflections/sky_reflections/ggx_samples]. </constant> + <constant name="SKY_MODE_INCREMENTAL" value="2" enum="SkyMode"> + </constant> <constant name="SKY_MODE_REALTIME" value="3" enum="SkyMode"> Uses the fast filtering algorithm to process the radiance map. In general this results in lower quality, but substantially faster run times. [b]Note:[/b] The fast filtering algorithm is limited to 256x256 cubemaps, so [member Sky.radiance_size] must be set to [constant Sky.RADIANCE_SIZE_256]. @@ -3609,64 +5304,88 @@ <constant name="ENV_SSAO_QUALITY_ULTRA" value="4" enum="EnvironmentSSAOQuality"> Highest quality screen space ambient occlusion. Uses the adaptive setting which can be dynamically adjusted to smoothly balance performance and visual quality. </constant> - <constant name="SUB_SURFACE_SCATTERING_QUALITY_DISABLED" value="0" enum="SubSurfaceScatteringQuality"> + <constant name="ENV_SDFGI_CASCADES_4" value="0" enum="EnvironmentSDFGICascades"> </constant> - <constant name="SUB_SURFACE_SCATTERING_QUALITY_LOW" value="1" enum="SubSurfaceScatteringQuality"> + <constant name="ENV_SDFGI_CASCADES_6" value="1" enum="EnvironmentSDFGICascades"> </constant> - <constant name="SUB_SURFACE_SCATTERING_QUALITY_MEDIUM" value="2" enum="SubSurfaceScatteringQuality"> + <constant name="ENV_SDFGI_CASCADES_8" value="2" enum="EnvironmentSDFGICascades"> </constant> - <constant name="SUB_SURFACE_SCATTERING_QUALITY_HIGH" value="3" enum="SubSurfaceScatteringQuality"> + <constant name="ENV_SDFGI_Y_SCALE_DISABLED" value="0" enum="EnvironmentSDFGIYScale"> </constant> - <constant name="DOF_BLUR_QUALITY_VERY_LOW" value="0" enum="DOFBlurQuality"> - Lowest quality DOF blur. This is the fastest setting, but you may be able to see filtering artifacts. + <constant name="ENV_SDFGI_Y_SCALE_75_PERCENT" value="1" enum="EnvironmentSDFGIYScale"> </constant> - <constant name="DOF_BLUR_QUALITY_LOW" value="1" enum="DOFBlurQuality"> - Low quality DOF blur. + <constant name="ENV_SDFGI_Y_SCALE_50_PERCENT" value="2" enum="EnvironmentSDFGIYScale"> </constant> - <constant name="DOF_BLUR_QUALITY_MEDIUM" value="2" enum="DOFBlurQuality"> - Medium quality DOF blur. + <constant name="ENV_SDFGI_RAY_COUNT_4" value="0" enum="EnvironmentSDFGIRayCount"> </constant> - <constant name="DOF_BLUR_QUALITY_HIGH" value="3" enum="DOFBlurQuality"> - Highest quality DOF blur. Results in the smoothest looking blur by taking the most samples, but is also significantly slower. + <constant name="ENV_SDFGI_RAY_COUNT_8" value="1" enum="EnvironmentSDFGIRayCount"> </constant> - <constant name="DOF_BOKEH_BOX" value="0" enum="DOFBokehShape"> - Calculate the DOF blur using a box filter. The fastest option, but results in obvious lines in blur pattern. + <constant name="ENV_SDFGI_RAY_COUNT_16" value="2" enum="EnvironmentSDFGIRayCount"> </constant> - <constant name="DOF_BOKEH_HEXAGON" value="1" enum="DOFBokehShape"> - Calculates DOF blur using a hexagon shaped filter. + <constant name="ENV_SDFGI_RAY_COUNT_32" value="3" enum="EnvironmentSDFGIRayCount"> </constant> - <constant name="DOF_BOKEH_CIRCLE" value="2" enum="DOFBokehShape"> - Calculates DOF blur using a circle shaped filter. Best quality and most realistic, but slowest. Use only for areas where a lot of performance can be dedicated to post-processing (e.g. cutscenes). + <constant name="ENV_SDFGI_RAY_COUNT_64" value="4" enum="EnvironmentSDFGIRayCount"> </constant> - <constant name="SHADOW_QUALITY_HARD" value="0" enum="ShadowQuality"> + <constant name="ENV_SDFGI_RAY_COUNT_96" value="5" enum="EnvironmentSDFGIRayCount"> </constant> - <constant name="SHADOW_QUALITY_SOFT_LOW" value="1" enum="ShadowQuality"> + <constant name="ENV_SDFGI_RAY_COUNT_128" value="6" enum="EnvironmentSDFGIRayCount"> </constant> - <constant name="SHADOW_QUALITY_SOFT_MEDIUM" value="2" enum="ShadowQuality"> + <constant name="ENV_SDFGI_RAY_COUNT_MAX" value="7" enum="EnvironmentSDFGIRayCount"> </constant> - <constant name="SHADOW_QUALITY_SOFT_HIGH" value="3" enum="ShadowQuality"> + <constant name="ENV_SDFGI_CONVERGE_IN_5_FRAMES" value="0" enum="EnvironmentSDFGIFramesToConverge"> </constant> - <constant name="SHADOW_QUALITY_SOFT_ULTRA" value="4" enum="ShadowQuality"> + <constant name="ENV_SDFGI_CONVERGE_IN_10_FRAMES" value="1" enum="EnvironmentSDFGIFramesToConverge"> </constant> - <constant name="SHADOW_QUALITY_MAX" value="5" enum="ShadowQuality"> + <constant name="ENV_SDFGI_CONVERGE_IN_15_FRAMES" value="2" enum="EnvironmentSDFGIFramesToConverge"> </constant> - <constant name="SCENARIO_DEBUG_DISABLED" value="0" enum="ScenarioDebugMode"> - Do not use a debug mode. + <constant name="ENV_SDFGI_CONVERGE_IN_20_FRAMES" value="3" enum="EnvironmentSDFGIFramesToConverge"> </constant> - <constant name="SCENARIO_DEBUG_WIREFRAME" value="1" enum="ScenarioDebugMode"> - Draw all objects as wireframe models. + <constant name="ENV_SDFGI_CONVERGE_IN_25_FRAMES" value="4" enum="EnvironmentSDFGIFramesToConverge"> </constant> - <constant name="SCENARIO_DEBUG_OVERDRAW" value="2" enum="ScenarioDebugMode"> - Draw all objects in a way that displays how much overdraw is occurring. Overdraw occurs when a section of pixels is drawn and shaded and then another object covers it up. To optimize a scene, you should reduce overdraw. + <constant name="ENV_SDFGI_CONVERGE_IN_30_FRAMES" value="5" enum="EnvironmentSDFGIFramesToConverge"> </constant> - <constant name="SCENARIO_DEBUG_SHADELESS" value="3" enum="ScenarioDebugMode"> - Draw all objects without shading. Equivalent to setting all objects shaders to [code]unshaded[/code]. + <constant name="ENV_SDFGI_CONVERGE_MAX" value="6" enum="EnvironmentSDFGIFramesToConverge"> </constant> - <constant name="VIEWPORT_OCCLUSION_BUILD_QUALITY_LOW" value="0" enum="ViewportOcclusionCullingBuildQuality"> + <constant name="ENV_SDFGI_UPDATE_LIGHT_IN_1_FRAME" value="0" enum="EnvironmentSDFGIFramesToUpdateLight"> </constant> - <constant name="VIEWPORT_OCCLUSION_BUILD_QUALITY_MEDIUM" value="1" enum="ViewportOcclusionCullingBuildQuality"> + <constant name="ENV_SDFGI_UPDATE_LIGHT_IN_2_FRAMES" value="1" enum="EnvironmentSDFGIFramesToUpdateLight"> </constant> - <constant name="VIEWPORT_OCCLUSION_BUILD_QUALITY_HIGH" value="2" enum="ViewportOcclusionCullingBuildQuality"> + <constant name="ENV_SDFGI_UPDATE_LIGHT_IN_4_FRAMES" value="2" enum="EnvironmentSDFGIFramesToUpdateLight"> + </constant> + <constant name="ENV_SDFGI_UPDATE_LIGHT_IN_8_FRAMES" value="3" enum="EnvironmentSDFGIFramesToUpdateLight"> + </constant> + <constant name="ENV_SDFGI_UPDATE_LIGHT_IN_16_FRAMES" value="4" enum="EnvironmentSDFGIFramesToUpdateLight"> + </constant> + <constant name="ENV_SDFGI_UPDATE_LIGHT_MAX" value="5" enum="EnvironmentSDFGIFramesToUpdateLight"> + </constant> + <constant name="SUB_SURFACE_SCATTERING_QUALITY_DISABLED" value="0" enum="SubSurfaceScatteringQuality"> + </constant> + <constant name="SUB_SURFACE_SCATTERING_QUALITY_LOW" value="1" enum="SubSurfaceScatteringQuality"> + </constant> + <constant name="SUB_SURFACE_SCATTERING_QUALITY_MEDIUM" value="2" enum="SubSurfaceScatteringQuality"> + </constant> + <constant name="SUB_SURFACE_SCATTERING_QUALITY_HIGH" value="3" enum="SubSurfaceScatteringQuality"> + </constant> + <constant name="DOF_BOKEH_BOX" value="0" enum="DOFBokehShape"> + Calculate the DOF blur using a box filter. The fastest option, but results in obvious lines in blur pattern. + </constant> + <constant name="DOF_BOKEH_HEXAGON" value="1" enum="DOFBokehShape"> + Calculates DOF blur using a hexagon shaped filter. + </constant> + <constant name="DOF_BOKEH_CIRCLE" value="2" enum="DOFBokehShape"> + Calculates DOF blur using a circle shaped filter. Best quality and most realistic, but slowest. Use only for areas where a lot of performance can be dedicated to post-processing (e.g. cutscenes). + </constant> + <constant name="DOF_BLUR_QUALITY_VERY_LOW" value="0" enum="DOFBlurQuality"> + Lowest quality DOF blur. This is the fastest setting, but you may be able to see filtering artifacts. + </constant> + <constant name="DOF_BLUR_QUALITY_LOW" value="1" enum="DOFBlurQuality"> + Low quality DOF blur. + </constant> + <constant name="DOF_BLUR_QUALITY_MEDIUM" value="2" enum="DOFBlurQuality"> + Medium quality DOF blur. + </constant> + <constant name="DOF_BLUR_QUALITY_HIGH" value="3" enum="DOFBlurQuality"> + Highest quality DOF blur. Results in the smoothest looking blur by taking the most samples, but is also significantly slower. </constant> <constant name="INSTANCE_NONE" value="0" enum="InstanceType"> The instance does not have a type. @@ -3677,35 +5396,34 @@ <constant name="INSTANCE_MULTIMESH" value="2" enum="InstanceType"> The instance is a multimesh. </constant> - <constant name="INSTANCE_IMMEDIATE" value="3" enum="InstanceType"> - The instance is an immediate geometry. - </constant> - <constant name="INSTANCE_PARTICLES" value="4" enum="InstanceType"> + <constant name="INSTANCE_PARTICLES" value="3" enum="InstanceType"> The instance is a particle emitter. </constant> - <constant name="INSTANCE_PARTICLES_COLLISION" value="5" enum="InstanceType"> + <constant name="INSTANCE_PARTICLES_COLLISION" value="4" enum="InstanceType"> </constant> - <constant name="INSTANCE_LIGHT" value="6" enum="InstanceType"> + <constant name="INSTANCE_LIGHT" value="5" enum="InstanceType"> The instance is a light. </constant> - <constant name="INSTANCE_REFLECTION_PROBE" value="7" enum="InstanceType"> + <constant name="INSTANCE_REFLECTION_PROBE" value="6" enum="InstanceType"> The instance is a reflection probe. </constant> - <constant name="INSTANCE_DECAL" value="8" enum="InstanceType"> + <constant name="INSTANCE_DECAL" value="7" enum="InstanceType"> The instance is a decal. </constant> - <constant name="INSTANCE_VOXEL_GI" value="9" enum="InstanceType"> + <constant name="INSTANCE_VOXEL_GI" value="8" enum="InstanceType"> The instance is a VoxelGI. </constant> - <constant name="INSTANCE_LIGHTMAP" value="10" enum="InstanceType"> + <constant name="INSTANCE_LIGHTMAP" value="9" enum="InstanceType"> The instance is a lightmap. </constant> - <constant name="INSTANCE_OCCLUDER" value="11" enum="InstanceType"> + <constant name="INSTANCE_OCCLUDER" value="10" enum="InstanceType"> </constant> - <constant name="INSTANCE_MAX" value="13" enum="InstanceType"> + <constant name="INSTANCE_VISIBLITY_NOTIFIER" value="11" enum="InstanceType"> + </constant> + <constant name="INSTANCE_MAX" value="12" enum="InstanceType"> Represents the size of the [enum InstanceType] enum. </constant> - <constant name="INSTANCE_GEOMETRY_MASK" value="30" enum="InstanceType"> + <constant name="INSTANCE_GEOMETRY_MASK" value="14" enum="InstanceType"> A combination of the flags of geometry instances (mesh, multimesh, immediate and particles). </constant> <constant name="INSTANCE_FLAG_USE_BAKED_LIGHT" value="0" enum="InstanceFlags"> @@ -3734,6 +5452,20 @@ <constant name="SHADOW_CASTING_SETTING_SHADOWS_ONLY" value="3" enum="ShadowCastingSetting"> Only render the shadows from the object. The object itself will not be drawn. </constant> + <constant name="BAKE_CHANNEL_ALBEDO_ALPHA" value="0" enum="BakeChannels"> + </constant> + <constant name="BAKE_CHANNEL_NORMAL" value="1" enum="BakeChannels"> + </constant> + <constant name="BAKE_CHANNEL_ORM" value="2" enum="BakeChannels"> + </constant> + <constant name="BAKE_CHANNEL_EMISSION" value="3" enum="BakeChannels"> + </constant> + <constant name="CANVAS_TEXTURE_CHANNEL_DIFFUSE" value="0" enum="CanvasTextureChannel"> + </constant> + <constant name="CANVAS_TEXTURE_CHANNEL_NORMAL" value="1" enum="CanvasTextureChannel"> + </constant> + <constant name="CANVAS_TEXTURE_CHANNEL_SPECULAR" value="2" enum="CanvasTextureChannel"> + </constant> <constant name="NINE_PATCH_STRETCH" value="0" enum="NinePatchAxisMode"> The nine patch gets stretched where needed. </constant> @@ -3880,35 +5612,17 @@ </constant> <constant name="GLOBAL_VAR_TYPE_MAX" value="28" enum="GlobalVariableType"> </constant> - <constant name="INFO_OBJECTS_IN_FRAME" value="0" enum="RenderInfo"> - The amount of objects in the frame. - </constant> - <constant name="INFO_VERTICES_IN_FRAME" value="1" enum="RenderInfo"> - The amount of vertices in the frame. - </constant> - <constant name="INFO_MATERIAL_CHANGES_IN_FRAME" value="2" enum="RenderInfo"> - The amount of modified materials in the frame. - </constant> - <constant name="INFO_SHADER_CHANGES_IN_FRAME" value="3" enum="RenderInfo"> - The amount of shader rebinds in the frame. - </constant> - <constant name="INFO_SURFACE_CHANGES_IN_FRAME" value="4" enum="RenderInfo"> - The amount of surface changes in the frame. + <constant name="RENDERING_INFO_TOTAL_OBJECTS_IN_FRAME" value="0" enum="RenderingInfo"> </constant> - <constant name="INFO_DRAW_CALLS_IN_FRAME" value="5" enum="RenderInfo"> - The amount of draw calls in frame. + <constant name="RENDERING_INFO_TOTAL_PRIMITIVES_IN_FRAME" value="1" enum="RenderingInfo"> </constant> - <constant name="INFO_USAGE_VIDEO_MEM_TOTAL" value="6" enum="RenderInfo"> - Unimplemented in the GLES2 rendering backend, always returns 0. + <constant name="RENDERING_INFO_TOTAL_DRAW_CALLS_IN_FRAME" value="2" enum="RenderingInfo"> </constant> - <constant name="INFO_VIDEO_MEM_USED" value="7" enum="RenderInfo"> - The amount of video memory used, i.e. texture and vertex memory combined. + <constant name="RENDERING_INFO_TEXTURE_MEM_USED" value="3" enum="RenderingInfo"> </constant> - <constant name="INFO_TEXTURE_MEM_USED" value="8" enum="RenderInfo"> - The amount of texture memory used. + <constant name="RENDERING_INFO_BUFFER_MEM_USED" value="4" enum="RenderingInfo"> </constant> - <constant name="INFO_VERTEX_MEM_USED" value="9" enum="RenderInfo"> - The amount of vertex memory used. + <constant name="RENDERING_INFO_VIDEO_MEM_USED" value="5" enum="RenderingInfo"> </constant> <constant name="FEATURE_SHADERS" value="0" enum="Features"> Hardware supports shaders. This enum is currently unused in Godot 3.x. diff --git a/doc/classes/Resource.xml b/doc/classes/Resource.xml index 6edb3b1a11..c8800a3c25 100644 --- a/doc/classes/Resource.xml +++ b/doc/classes/Resource.xml @@ -4,7 +4,7 @@ Base class for all resources. </brief_description> <description> - Resource is the base class for all Godot-specific resource types, serving primarily as data containers. Since they inherit from [RefCounted], resources are reference-counted and freed when no longer in use. They are also cached once loaded from disk, so that any further attempts to load a resource from a given path will return the same reference (all this in contrast to a [Node], which is not reference-counted and can be instanced from disk as many times as desired). Resources can be saved externally on disk or bundled into another object, such as a [Node] or another resource. + Resource is the base class for all Godot-specific resource types, serving primarily as data containers. Since they inherit from [RefCounted], resources are reference-counted and freed when no longer in use. They are also cached once loaded from disk, so that any further attempts to load a resource from a given path will return the same reference (all this in contrast to a [Node], which is not reference-counted and can be instantiated from disk as many times as desired). Resources can be saved externally on disk or bundled into another object, such as a [Node] or another resource. [b]Note:[/b] In C#, resources will not be freed instantly after they are no longer in use. Instead, garbage collection will run periodically and will free resources that are no longer in use. This means that unused resources will linger on for a while before being removed. </description> <tutorials> diff --git a/doc/classes/RichTextLabel.xml b/doc/classes/RichTextLabel.xml index 623ee7520d..38884a027f 100644 --- a/doc/classes/RichTextLabel.xml +++ b/doc/classes/RichTextLabel.xml @@ -170,6 +170,15 @@ Terminates the current tag. Use after [code]push_*[/code] methods to close BBCodes manually. Does not need to follow [code]add_*[/code] methods. </description> </method> + <method name="push_bgcolor"> + <return type="void"> + </return> + <argument index="0" name="bgcolor" type="Color"> + </argument> + <description> + Adds a [code][bgcolor][/code] tag to the tag stack. + </description> + </method> <method name="push_bold"> <return type="void"> </return> @@ -221,6 +230,15 @@ Adds a [code][dropcap][/code] tag to the tag stack. Drop cap (dropped capital) is a decorative element at the beginning of a paragraph that is larger than the rest of the text. </description> </method> + <method name="push_fgcolor"> + <return type="void"> + </return> + <argument index="0" name="fgcolor" type="Color"> + </argument> + <description> + Adds a [code][fgcolor][/code] tag to the tag stack. + </description> + </method> <method name="push_font"> <return type="void"> </return> @@ -592,11 +610,15 @@ </constant> <constant name="ITEM_RAINBOW" value="20" enum="ItemType"> </constant> - <constant name="ITEM_META" value="21" enum="ItemType"> + <constant name="ITEM_BGCOLOR" value="21" enum="ItemType"> + </constant> + <constant name="ITEM_FGCOLOR" value="22" enum="ItemType"> + </constant> + <constant name="ITEM_META" value="23" enum="ItemType"> </constant> - <constant name="ITEM_DROPCAP" value="22" enum="ItemType"> + <constant name="ITEM_DROPCAP" value="24" enum="ItemType"> </constant> - <constant name="ITEM_CUSTOMFX" value="23" enum="ItemType"> + <constant name="ITEM_CUSTOMFX" value="25" enum="ItemType"> </constant> </constants> <theme_items> diff --git a/doc/classes/SceneState.xml b/doc/classes/SceneState.xml index f9e0ef76b9..6d804cc697 100644 --- a/doc/classes/SceneState.xml +++ b/doc/classes/SceneState.xml @@ -95,7 +95,7 @@ <argument index="0" name="idx" type="int"> </argument> <description> - Returns the node's index, which is its position relative to its siblings. This is only relevant and saved in scenes for cases where new nodes are added to an instanced or inherited scene among siblings from the base scene. Despite the name, this index is not related to the [code]idx[/code] argument used here and in other methods. + Returns the node's index, which is its position relative to its siblings. This is only relevant and saved in scenes for cases where new nodes are added to an instantiated or inherited scene among siblings from the base scene. Despite the name, this index is not related to the [code]idx[/code] argument used here and in other methods. </description> </method> <method name="get_node_instance" qualifiers="const"> @@ -199,14 +199,14 @@ </methods> <constants> <constant name="GEN_EDIT_STATE_DISABLED" value="0" enum="GenEditState"> - If passed to [method PackedScene.instance], blocks edits to the scene state. + If passed to [method PackedScene.instantiate], blocks edits to the scene state. </constant> <constant name="GEN_EDIT_STATE_INSTANCE" value="1" enum="GenEditState"> - If passed to [method PackedScene.instance], provides inherited scene resources to the local scene. + If passed to [method PackedScene.instantiate], provides inherited scene resources to the local scene. [b]Note:[/b] Only available in editor builds. </constant> <constant name="GEN_EDIT_STATE_MAIN" value="2" enum="GenEditState"> - If passed to [method PackedScene.instance], provides local scene resources to the local scene. Only the main scene should receive the main edit state. + If passed to [method PackedScene.instantiate], provides local scene resources to the local scene. Only the main scene should receive the main edit state. [b]Note:[/b] Only available in editor builds. </constant> </constants> diff --git a/doc/classes/SceneTree.xml b/doc/classes/SceneTree.xml index 7a15153fc2..bf51b4dfa7 100644 --- a/doc/classes/SceneTree.xml +++ b/doc/classes/SceneTree.xml @@ -90,6 +90,13 @@ The timer will be automatically freed after its time elapses. </description> </method> + <method name="create_tween"> + <return type="Tween"> + </return> + <description> + Creates and returns a new [Tween]. + </description> + </method> <method name="get_first_node_in_group"> <return type="Node"> </return> @@ -105,20 +112,6 @@ Returns the current frame number, i.e. the total frame count since the application started. </description> </method> - <method name="get_network_connected_peers" qualifiers="const"> - <return type="PackedInt32Array"> - </return> - <description> - Returns the peer IDs of all connected peers of this [SceneTree]'s [member network_peer]. - </description> - </method> - <method name="get_network_unique_id" qualifiers="const"> - <return type="int"> - </return> - <description> - Returns the unique peer ID of this [SceneTree]'s [member network_peer]. - </description> - </method> <method name="get_node_count" qualifiers="const"> <return type="int"> </return> @@ -135,11 +128,11 @@ Returns a list of all nodes assigned to the given group. </description> </method> - <method name="get_rpc_sender_id" qualifiers="const"> - <return type="int"> + <method name="get_processed_tweens"> + <return type="Array"> </return> <description> - Returns the sender's peer ID for the most recently received RPC call. + Returns an array of currently exising [Tween]s in the [SceneTree] (both running and paused). </description> </method> <method name="has_group" qualifiers="const"> @@ -151,20 +144,6 @@ Returns [code]true[/code] if the given group exists. </description> </method> - <method name="has_network_peer" qualifiers="const"> - <return type="bool"> - </return> - <description> - Returns [code]true[/code] if there is a [member network_peer] set. - </description> - </method> - <method name="is_network_server" qualifiers="const"> - <return type="bool"> - </return> - <description> - Returns [code]true[/code] if this [SceneTree]'s [member network_peer] is in server mode (listening for connections). - </description> - </method> <method name="notify_group"> <return type="void"> </return> @@ -287,32 +266,16 @@ If [code]true[/code] (default value), enables automatic polling of the [MultiplayerAPI] for this SceneTree during [signal process_frame]. If [code]false[/code], you need to manually call [method MultiplayerAPI.poll] to process network packets and deliver RPCs/RSETs. This allows running RPCs/RSETs in a different loop (e.g. physics, thread, specific time step) and for manual [Mutex] protection when accessing the [MultiplayerAPI] from threads. </member> - <member name="network_peer" type="NetworkedMultiplayerPeer" setter="set_network_peer" getter="get_network_peer"> - The peer object to handle the RPC system (effectively enabling networking when set). Depending on the peer itself, the [SceneTree] will become a network server (check with [method is_network_server]) and will set the root node's network mode to master, or it will become a regular peer with the root node set to puppet. All child nodes are set to inherit the network mode by default. Handling of networking-related events (connection, disconnection, new clients) is done by connecting to [SceneTree]'s signals. - </member> <member name="paused" type="bool" setter="set_pause" getter="is_paused" default="false"> If [code]true[/code], the [SceneTree] is paused. Doing so will have the following behavior: - 2D and 3D physics will be stopped. - [method Node._process], [method Node._physics_process] and [method Node._input] will not be called anymore in nodes. </member> - <member name="refuse_new_network_connections" type="bool" setter="set_refuse_new_network_connections" getter="is_refusing_new_network_connections" default="false"> - If [code]true[/code], the [SceneTree]'s [member network_peer] refuses new incoming connections. - </member> <member name="root" type="Window" setter="" getter="get_root"> The [SceneTree]'s root [Window]. </member> </members> <signals> - <signal name="connected_to_server"> - <description> - Emitted whenever this [SceneTree]'s [member network_peer] successfully connected to a server. Only emitted on clients. - </description> - </signal> - <signal name="connection_failed"> - <description> - Emitted whenever this [SceneTree]'s [member network_peer] fails to establish a connection to a server. Only emitted on clients. - </description> - </signal> <signal name="files_dropped"> <argument index="0" name="files" type="PackedStringArray"> </argument> @@ -322,20 +285,6 @@ Emitted when files are dragged from the OS file manager and dropped in the game window. The arguments are a list of file paths and the identifier of the screen where the drag originated. </description> </signal> - <signal name="network_peer_connected"> - <argument index="0" name="id" type="int"> - </argument> - <description> - Emitted whenever this [SceneTree]'s [member network_peer] connects with a new peer. ID is the peer ID of the new peer. Clients get notified when other clients connect to the same server. Upon connecting to a server, a client also receives this signal for the server (with ID being 1). - </description> - </signal> - <signal name="network_peer_disconnected"> - <argument index="0" name="id" type="int"> - </argument> - <description> - Emitted whenever this [SceneTree]'s [member network_peer] disconnects from a peer. Clients get notified when other clients disconnect from the same server. - </description> - </signal> <signal name="node_added"> <argument index="0" name="node" type="Node"> </argument> @@ -374,11 +323,6 @@ Emitted immediately before [method Node._process] is called on every node in the [SceneTree]. </description> </signal> - <signal name="server_disconnected"> - <description> - Emitted whenever this [SceneTree]'s [member network_peer] disconnected from server. Only emitted on clients. - </description> - </signal> <signal name="tree_changed"> <description> Emitted whenever the [SceneTree] hierarchy changed (children being moved or renamed, etc.). diff --git a/doc/classes/Script.xml b/doc/classes/Script.xml index 56272760bd..e7527d73e2 100644 --- a/doc/classes/Script.xml +++ b/doc/classes/Script.xml @@ -11,11 +11,11 @@ <link title="Scripting">https://docs.godotengine.org/en/latest/getting_started/step_by_step/scripting.html</link> </tutorials> <methods> - <method name="can_instance" qualifiers="const"> + <method name="can_instantiate" qualifiers="const"> <return type="bool"> </return> <description> - Returns [code]true[/code] if the script can be instanced. + Returns [code]true[/code] if the script can be instantiated. </description> </method> <method name="get_base_script" qualifiers="const"> diff --git a/doc/classes/SoftBody3D.xml b/doc/classes/SoftBody3D.xml index 7999ad774d..b143c60d9d 100644 --- a/doc/classes/SoftBody3D.xml +++ b/doc/classes/SoftBody3D.xml @@ -93,6 +93,9 @@ </member> <member name="damping_coefficient" type="float" setter="set_damping_coefficient" getter="get_damping_coefficient" default="0.01"> </member> + <member name="disable_mode" type="int" setter="set_disable_mode" getter="get_disable_mode" enum="SoftBody3D.DisableMode" default="0"> + Defines the behavior in physics when [member Node.process_mode] is set to [constant Node.PROCESS_MODE_DISABLED]. See [enum DisableMode] for more details about the different modes. + </member> <member name="drag_coefficient" type="float" setter="set_drag_coefficient" getter="get_drag_coefficient" default="0.0"> </member> <member name="linear_stiffness" type="float" setter="set_linear_stiffness" getter="get_linear_stiffness" default="0.5"> @@ -113,5 +116,12 @@ </member> </members> <constants> + <constant name="DISABLE_MODE_REMOVE" value="0" enum="DisableMode"> + When [member Node.process_mode] is set to [constant Node.PROCESS_MODE_DISABLED], remove from the physics simulation to stop all physics interactions with this [SoftBody3D]. + Automatically re-added to the physics simulation when the [Node] is processed again. + </constant> + <constant name="DISABLE_MODE_KEEP_ACTIVE" value="1" enum="DisableMode"> + When [member Node.process_mode] is set to [constant Node.PROCESS_MODE_DISABLED], do not affect the physics simulation. + </constant> </constants> </class> diff --git a/doc/classes/Sprite3D.xml b/doc/classes/Sprite3D.xml index f7f2ff0de1..ddb9d543e8 100644 --- a/doc/classes/Sprite3D.xml +++ b/doc/classes/Sprite3D.xml @@ -21,7 +21,6 @@ The number of columns in the sprite sheet. </member> <member name="region_enabled" type="bool" setter="set_region_enabled" getter="is_region_enabled" default="false"> - If [code]true[/code], texture will be cut from a larger atlas texture. See [member region_rect]. </member> <member name="region_rect" type="Rect2" setter="set_region_rect" getter="get_region_rect" default="Rect2(0, 0, 0, 0)"> The region of the atlas texture to display. [member region_enabled] must be [code]true[/code]. @@ -39,11 +38,6 @@ Emitted when the [member frame] changes. </description> </signal> - <signal name="texture_changed"> - <description> - Emitted when the [member texture] changes. - </description> - </signal> </signals> <constants> </constants> diff --git a/doc/classes/SurfaceTool.xml b/doc/classes/SurfaceTool.xml index 22d1b52479..a8b836ff0c 100644 --- a/doc/classes/SurfaceTool.xml +++ b/doc/classes/SurfaceTool.xml @@ -24,7 +24,7 @@ The above [SurfaceTool] now contains one vertex of a triangle which has a UV coordinate and a specified [Color]. If another vertex were added without calling [method set_uv] or [method set_color], then the last values would be used. Vertex attributes must be passed [b]before[/b] calling [method add_vertex]. Failure to do so will result in an error when committing the vertex information to a mesh. Additionally, the attributes used before the first vertex is added determine the format of the mesh. For example, if you only add UVs to the first vertex, you cannot add color to any of the subsequent vertices. - See also [ArrayMesh], [ImmediateGeometry3D] and [MeshDataTool] for procedural geometry generation. + See also [ArrayMesh], [ImmediateMesh] and [MeshDataTool] for procedural geometry generation. [b]Note:[/b] Godot uses clockwise [url=https://learnopengl.com/Advanced-OpenGL/Face-culling]winding order[/url] for front faces of triangle primitive modes. </description> <tutorials> diff --git a/doc/classes/TextEdit.xml b/doc/classes/TextEdit.xml index 03e4556c92..5de6c059c3 100644 --- a/doc/classes/TextEdit.xml +++ b/doc/classes/TextEdit.xml @@ -10,6 +10,13 @@ <tutorials> </tutorials> <methods> + <method name="_backspace" qualifiers="virtual"> + <return type="void"> + </return> + <description> + A virtual method that is called whenever backspace is triggered. + </description> + </method> <method name="add_gutter"> <return type="void"> </return> @@ -18,6 +25,13 @@ <description> </description> </method> + <method name="backspace"> + <return type="void"> + </return> + <description> + Causes the [TextEdit] to perform a backspace. + </description> + </method> <method name="center_viewport_to_cursor"> <return type="void"> </return> @@ -96,6 +110,12 @@ Cut's the current selection. </description> </method> + <method name="delete_selection"> + <return type="void"> + </return> + <description> + </description> + </method> <method name="deselect"> <return type="void"> </return> @@ -110,6 +130,14 @@ Gets the caret pixel draw poistion. </description> </method> + <method name="get_first_non_whitespace_column" qualifiers="const"> + <return type="int"> + </return> + <argument index="0" name="line" type="int"> + </argument> + <description> + </description> + </method> <method name="get_gutter_count" qualifiers="const"> <return type="int"> </return> @@ -140,6 +168,15 @@ <description> </description> </method> + <method name="get_indent_level" qualifiers="const"> + <return type="int"> + </return> + <argument index="0" name="line" type="int"> + </argument> + <description> + Returns the indent level of a specific line. + </description> + </method> <method name="get_line" qualifiers="const"> <return type="String"> </return> @@ -274,6 +311,13 @@ Returns the selection end line. </description> </method> + <method name="get_tab_size" qualifiers="const"> + <return type="int"> + </return> + <description> + Returns the [TextEdit]'s' tab size. + </description> + </method> <method name="get_visible_line_count" qualifiers="const"> <return type="int"> </return> @@ -354,6 +398,16 @@ Triggers a right-click menu action by the specified index. See [enum MenuItems] for a list of available indexes. </description> </method> + <method name="merge_gutters"> + <return type="void"> + </return> + <argument index="0" name="from_line" type="int"> + </argument> + <argument index="1" name="to_line" type="int"> + </argument> + <description> + </description> + </method> <method name="paste"> <return type="void"> </return> @@ -611,6 +665,15 @@ <description> </description> </method> + <method name="set_tab_size"> + <return type="void"> + </return> + <argument index="0" name="size" type="int"> + </argument> + <description> + Sets the tab size for the [TextEdit] to use. + </description> + </method> <method name="undo"> <return type="void"> </return> diff --git a/doc/classes/TileData.xml b/doc/classes/TileData.xml index 1f0f807a08..bb793024eb 100644 --- a/doc/classes/TileData.xml +++ b/doc/classes/TileData.xml @@ -7,7 +7,7 @@ <tutorials> </tutorials> <methods> - <method name="add_collision_shape"> + <method name="add_collision_polygon"> <return type="void"> </return> <argument index="0" name="layer_id" type="int"> @@ -15,27 +15,27 @@ <description> </description> </method> - <method name="get_collision_shape_one_way_margin" qualifiers="const"> + <method name="get_collision_polygon_one_way_margin" qualifiers="const"> <return type="float"> </return> <argument index="0" name="layer_id" type="int"> </argument> - <argument index="1" name="shape_index" type="int"> + <argument index="1" name="polygon_index" type="int"> </argument> <description> </description> </method> - <method name="get_collision_shape_shape" qualifiers="const"> - <return type="Shape2D"> + <method name="get_collision_polygon_points" qualifiers="const"> + <return type="PackedVector2Array"> </return> <argument index="0" name="layer_id" type="int"> </argument> - <argument index="1" name="shape_index" type="int"> + <argument index="1" name="polygon_index" type="int"> </argument> <description> </description> </method> - <method name="get_collision_shapes_count" qualifiers="const"> + <method name="get_collision_polygons_count" qualifiers="const"> <return type="int"> </return> <argument index="0" name="layer_id" type="int"> @@ -83,68 +83,68 @@ <description> </description> </method> - <method name="is_collision_shape_one_way" qualifiers="const"> + <method name="is_collision_polygon_one_way" qualifiers="const"> <return type="bool"> </return> <argument index="0" name="layer_id" type="int"> </argument> - <argument index="1" name="shape_index" type="int"> + <argument index="1" name="polygon_index" type="int"> </argument> <description> </description> </method> - <method name="remove_collision_shape"> + <method name="remove_collision_polygon"> <return type="void"> </return> <argument index="0" name="layer_id" type="int"> </argument> - <argument index="1" name="shape_index" type="int"> + <argument index="1" name="polygon_index" type="int"> </argument> <description> </description> </method> - <method name="set_collision_shape_one_way"> + <method name="set_collision_polygon_one_way"> <return type="void"> </return> <argument index="0" name="layer_id" type="int"> </argument> - <argument index="1" name="shape_index" type="int"> + <argument index="1" name="polygon_index" type="int"> </argument> <argument index="2" name="one_way" type="bool"> </argument> <description> </description> </method> - <method name="set_collision_shape_one_way_margin"> + <method name="set_collision_polygon_one_way_margin"> <return type="void"> </return> <argument index="0" name="layer_id" type="int"> </argument> - <argument index="1" name="shape_index" type="int"> + <argument index="1" name="polygon_index" type="int"> </argument> <argument index="2" name="one_way_margin" type="float"> </argument> <description> </description> </method> - <method name="set_collision_shape_shape"> + <method name="set_collision_polygon_points"> <return type="void"> </return> <argument index="0" name="layer_id" type="int"> </argument> - <argument index="1" name="shape_index" type="int"> + <argument index="1" name="polygon_index" type="int"> </argument> - <argument index="2" name="shape" type="Shape2D"> + <argument index="2" name="polygon" type="PackedVector2Array"> </argument> <description> </description> </method> - <method name="set_collision_shapes_count"> + <method name="set_collision_polygons_count"> <return type="void"> </return> <argument index="0" name="layer_id" type="int"> </argument> - <argument index="1" name="shapes_count" type="int"> + <argument index="1" name="polygons_count" type="int"> </argument> <description> </description> diff --git a/doc/classes/TileSet.xml b/doc/classes/TileSet.xml index 7d8b589f78..436e15387d 100644 --- a/doc/classes/TileSet.xml +++ b/doc/classes/TileSet.xml @@ -289,8 +289,6 @@ </member> <member name="tile_size" type="Vector2i" setter="set_tile_size" getter="get_tile_size" default="Vector2i(16, 16)"> </member> - <member name="tile_skew" type="Vector2" setter="set_tile_skew" getter="get_tile_skew" default="Vector2(0, 0)"> - </member> <member name="uv_clipping" type="bool" setter="set_uv_clipping" getter="is_uv_clipping" default="false"> </member> <member name="y_sorting" type="bool" setter="set_y_sorting" getter="is_y_sorting" default="false"> @@ -324,37 +322,37 @@ </constant> <constant name="TILE_OFFSET_AXIS_VERTICAL" value="1" enum="TileOffsetAxis"> </constant> - <constant name="TileSet::CELL_NEIGHBOR_RIGHT_SIDE" value="0" enum="CellNeighbor"> + <constant name="CELL_NEIGHBOR_RIGHT_SIDE" value="0" enum="CellNeighbor"> </constant> - <constant name="TileSet::CELL_NEIGHBOR_RIGHT_CORNER" value="1" enum="CellNeighbor"> + <constant name="CELL_NEIGHBOR_RIGHT_CORNER" value="1" enum="CellNeighbor"> </constant> - <constant name="TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE" value="2" enum="CellNeighbor"> + <constant name="CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE" value="2" enum="CellNeighbor"> </constant> - <constant name="TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER" value="3" enum="CellNeighbor"> + <constant name="CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER" value="3" enum="CellNeighbor"> </constant> - <constant name="TileSet::CELL_NEIGHBOR_BOTTOM_SIDE" value="4" enum="CellNeighbor"> + <constant name="CELL_NEIGHBOR_BOTTOM_SIDE" value="4" enum="CellNeighbor"> </constant> - <constant name="TileSet::CELL_NEIGHBOR_BOTTOM_CORNER" value="5" enum="CellNeighbor"> + <constant name="CELL_NEIGHBOR_BOTTOM_CORNER" value="5" enum="CellNeighbor"> </constant> - <constant name="TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE" value="6" enum="CellNeighbor"> + <constant name="CELL_NEIGHBOR_BOTTOM_LEFT_SIDE" value="6" enum="CellNeighbor"> </constant> - <constant name="TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_CORNER" value="7" enum="CellNeighbor"> + <constant name="CELL_NEIGHBOR_BOTTOM_LEFT_CORNER" value="7" enum="CellNeighbor"> </constant> - <constant name="TileSet::CELL_NEIGHBOR_LEFT_SIDE" value="8" enum="CellNeighbor"> + <constant name="CELL_NEIGHBOR_LEFT_SIDE" value="8" enum="CellNeighbor"> </constant> - <constant name="TileSet::CELL_NEIGHBOR_LEFT_CORNER" value="9" enum="CellNeighbor"> + <constant name="CELL_NEIGHBOR_LEFT_CORNER" value="9" enum="CellNeighbor"> </constant> - <constant name="TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE" value="10" enum="CellNeighbor"> + <constant name="CELL_NEIGHBOR_TOP_LEFT_SIDE" value="10" enum="CellNeighbor"> </constant> - <constant name="TileSet::CELL_NEIGHBOR_TOP_LEFT_CORNER" value="11" enum="CellNeighbor"> + <constant name="CELL_NEIGHBOR_TOP_LEFT_CORNER" value="11" enum="CellNeighbor"> </constant> - <constant name="TileSet::CELL_NEIGHBOR_TOP_SIDE" value="12" enum="CellNeighbor"> + <constant name="CELL_NEIGHBOR_TOP_SIDE" value="12" enum="CellNeighbor"> </constant> - <constant name="TileSet::CELL_NEIGHBOR_TOP_CORNER" value="13" enum="CellNeighbor"> + <constant name="CELL_NEIGHBOR_TOP_CORNER" value="13" enum="CellNeighbor"> </constant> - <constant name="TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE" value="14" enum="CellNeighbor"> + <constant name="CELL_NEIGHBOR_TOP_RIGHT_SIDE" value="14" enum="CellNeighbor"> </constant> - <constant name="TileSet::CELL_NEIGHBOR_TOP_RIGHT_CORNER" value="15" enum="CellNeighbor"> + <constant name="CELL_NEIGHBOR_TOP_RIGHT_CORNER" value="15" enum="CellNeighbor"> </constant> <constant name="TERRAIN_MODE_MATCH_CORNERS_AND_SIDES" value="0" enum="TerrainMode"> </constant> diff --git a/doc/classes/Tree.xml b/doc/classes/Tree.xml index 6a65d4ff7d..b498b9bb90 100644 --- a/doc/classes/Tree.xml +++ b/doc/classes/Tree.xml @@ -96,6 +96,14 @@ Returns the column index at [code]position[/code], or -1 if no item is there. </description> </method> + <method name="get_column_expand_ratio" qualifiers="const"> + <return type="int"> + </return> + <argument index="0" name="column" type="int"> + </argument> + <description> + </description> + </method> <method name="get_column_title" qualifiers="const"> <return type="String"> </return> @@ -232,7 +240,7 @@ Returns the last pressed button's index. </description> </method> - <method name="get_root"> + <method name="get_root" qualifiers="const"> <return type="TreeItem"> </return> <description> @@ -264,12 +272,50 @@ To tell whether a column of an item is selected, use [method TreeItem.is_selected]. </description> </method> + <method name="is_column_clipping_content" qualifiers="const"> + <return type="bool"> + </return> + <argument index="0" name="column" type="int"> + </argument> + <description> + </description> + </method> + <method name="is_column_expanding" qualifiers="const"> + <return type="bool"> + </return> + <argument index="0" name="column" type="int"> + </argument> + <description> + </description> + </method> <method name="scroll_to_item"> <return type="void"> </return> <argument index="0" name="item" type="Object"> </argument> <description> + Causes the [Tree] to jump to the specified item. + </description> + </method> + <method name="set_column_clip_content"> + <return type="void"> + </return> + <argument index="0" name="column" type="int"> + </argument> + <argument index="1" name="enable" type="bool"> + </argument> + <description> + </description> + </method> + <method name="set_column_custom_minimum_width"> + <return type="void"> + </return> + <argument index="0" name="column" type="int"> + </argument> + <argument index="1" name="min_width" type="int"> + </argument> + <description> + Overrides the calculated minimum width of a column. It can be set to `0` to restore the default behavior. Columns that have the "Expand" flag will use their "min_width" in a similar fashion to [member Control.size_flags_stretch_ratio]. </description> </method> <method name="set_column_expand"> @@ -283,15 +329,14 @@ If [code]true[/code], the column will have the "Expand" flag of [Control]. Columns that have the "Expand" flag will use their "min_width" in a similar fashion to [member Control.size_flags_stretch_ratio]. </description> </method> - <method name="set_column_min_width"> + <method name="set_column_expand_ratio"> <return type="void"> </return> <argument index="0" name="column" type="int"> </argument> - <argument index="1" name="min_width" type="int"> + <argument index="1" name="ratio" type="int"> </argument> <description> - Sets the minimum width of a column. Columns that have the "Expand" flag will use their "min_width" in a similar fashion to [member Control.size_flags_stretch_ratio]. </description> </method> <method name="set_column_title"> @@ -372,6 +417,12 @@ If [code]true[/code], the tree's root is hidden. </member> <member name="rect_clip_content" type="bool" setter="set_clip_contents" getter="is_clipping_contents" override="true" default="true" /> + <member name="scroll_horizontal_enabled" type="bool" setter="set_h_scroll_enabled" getter="is_h_scroll_enabled" default="true"> + If [code]true[/code], enables horizontal scrolling. + </member> + <member name="scroll_vertical_enabled" type="bool" setter="set_v_scroll_enabled" getter="is_v_scroll_enabled" default="true"> + If [code]true[/code], enables vertical scrolling. + </member> <member name="select_mode" type="int" setter="set_select_mode" getter="get_select_mode" enum="Tree.SelectMode" default="0"> Allows single or multiple selection. See the [enum SelectMode] constants. </member> diff --git a/doc/classes/TreeItem.xml b/doc/classes/TreeItem.xml index 0256d83fea..85c9caa101 100644 --- a/doc/classes/TreeItem.xml +++ b/doc/classes/TreeItem.xml @@ -192,7 +192,7 @@ Returns [code]true[/code] if [code]expand_right[/code] is set. </description> </method> - <method name="get_first_child"> + <method name="get_first_child" qualifiers="const"> <return type="TreeItem"> </return> <description> @@ -260,7 +260,7 @@ Returns the metadata value that was set for the given column using [method set_metadata]. </description> </method> - <method name="get_next"> + <method name="get_next" qualifiers="const"> <return type="TreeItem"> </return> <description> @@ -288,7 +288,7 @@ Returns OpenType feature [code]tag[/code] of the item's text. </description> </method> - <method name="get_parent"> + <method name="get_parent" qualifiers="const"> <return type="TreeItem"> </return> <description> @@ -391,7 +391,7 @@ Returns the given column's tooltip. </description> </method> - <method name="get_tree"> + <method name="get_tree" qualifiers="const"> <return type="Tree"> </return> <description> diff --git a/doc/classes/Tween.xml b/doc/classes/Tween.xml index 00cca40093..253822cf32 100644 --- a/doc/classes/Tween.xml +++ b/doc/classes/Tween.xml @@ -1,453 +1,397 @@ <?xml version="1.0" encoding="UTF-8" ?> -<class name="Tween" inherits="Node" version="4.0"> +<class name="Tween" inherits="RefCounted" version="4.0"> <brief_description> - Smoothly animates a node's properties over time. + Lightweight object used for general-purpose animation via script, using [Tweener]s. </brief_description> <description> - Tweens are useful for animations requiring a numerical property to be interpolated over a range of values. The name [i]tween[/i] comes from [i]in-betweening[/i], an animation technique where you specify [i]keyframes[/i] and the computer interpolates the frames that appear between them. - [Tween] is more suited than [AnimationPlayer] for animations where you don't know the final values in advance. For example, interpolating a dynamically-chosen camera zoom value is best done with a [Tween] node; it would be difficult to do the same thing with an [AnimationPlayer] node. - Here is a brief usage example that makes a 2D node move smoothly between two positions: - [codeblocks] - [gdscript] - var tween = get_node("Tween") - tween.interpolate_property($Node2D, "position", - Vector2(0, 0), Vector2(100, 100), 1, - Tween.TRANS_LINEAR, Tween.EASE_IN_OUT) - tween.start() - [/gdscript] - [csharp] - var tween = GetNode<Tween>("Tween"); - tween.InterpolateProperty(GetNode<Node2D>("Node2D"), "position", - new Vector2(0, 0), new Vector2(100, 100), 1, - Tween.TransitionType.Linear, Tween.EaseType.InOut); - tween.Start(); - [/csharp] - [/codeblocks] - Many methods require a property name, such as [code]"position"[/code] above. You can find the correct property name by hovering over the property in the Inspector. You can also provide the components of a property directly by using [code]"property:component"[/code] (e.g. [code]position:x[/code]), where it would only apply to that particular component. - Many of the methods accept [code]trans_type[/code] and [code]ease_type[/code]. The first accepts an [enum TransitionType] constant, and refers to the way the timing of the animation is handled (see [url=https://easings.net/]easings.net[/url] for some examples). The second accepts an [enum EaseType] constant, and controls where the [code]trans_type[/code] is applied to the interpolation (in the beginning, the end, or both). If you don't know which transition and easing to pick, you can try different [enum TransitionType] constants with [constant EASE_IN_OUT], and use the one that looks best. + Tweens are mostly useful for animations requiring a numerical property to be interpolated over a range of values. The name [i]tween[/i] comes from [i]in-betweening[/i], an animation technique where you specify [i]keyframes[/i] and the computer interpolates the frames that appear between them. + [Tween] is more suited than [AnimationPlayer] for animations where you don't know the final values in advance. For example, interpolating a dynamically-chosen camera zoom value is best done with a [Tween]; it would be difficult to do the same thing with an [AnimationPlayer] node. Tweens are also more light-weight than [AnimationPlayer], so they are very much suited for simple animations or general tasks that don't require visual tweaking provided by the editor. They can be used in a fire-and-forget manner for some logic that normally would be done by code. You can e.g. make something shoot periodically by using a looped [CallbackTweener] with a delay. + A [Tween] can be created by using either [method SceneTree.create_tween] or [method Node.create_tween]. [Tween]s created manually (i.e. by using [code]Tween.new()[/code]) are invalid. They can't be used for tweening values, but you can do manual interpolation with [method interpolate_value]. + A [Tween] animation is composed of a sequence of [Tweener]s, which by default are executed one after another. You can create a sequence by appending [Tweener]s to the [Tween]. Animating something with a [Tweener] is called tweening. Example tweening sequence looks like this: + [codeblock] + var tween = get_tree().create_tween() + tween.tween_property($Sprite, "modulate", Color.red, 1) + tween.tween_property($Sprite, "scale", Vector2(), 1) + tween.tween_callback($Sprite.queue_free) + [/codeblock] + This sequence will make the [code]$Sprite[/code] node turn red, then shrink and finally the [method Node.queue_free] is called to remove the sprite. See methods [method tween_property], [method tween_interval], [method tween_callback] and [method tween_method] for more usage information. + When a [Tweener] is created with one of the [code]tween_*[/code] methods, a chained method call can be used to tweak the properties of this [Tweener]. For example, if you want to set different transition type in the above example, you can do: + [codeblock] + var tween = get_tree().create_tween() + tween.tween_property($Sprite, "modulate", Color.red, 1).set_trans(Tween.TRANS_SINE) + tween.tween_property($Sprite, "scale", Vector2(), 1).set_trans(Tween.TRANS_BOUNCE) + tween.tween_callback($Sprite.queue_free) + [/codeblock] + Most of the [Tween] methods can be chained this way too. In this example the [Tween] is bound and have set a default transition: + [codeblock] + var tween = get_tree().create_tween().bind_node(self).set_trans(Tween.TRANS_ELASTIC) + tween.tween_property($Sprite, "modulate", Color.red, 1) + tween.tween_property($Sprite, "scale", Vector2(), 1) + tween.tween_callback($Sprite.queue_free) + [/codeblock] + Another interesting use for [Tween]s is animating arbitrary set of objects: + [codeblock] + var tween = create_tween() + for sprite in get_children(): + tween.tween_property(sprite, "position", Vector2(), 1) + [/codeblock] + In the example above, all children of a node are moved one after another to position (0, 0). + Some [Tweener]s use transitions and eases. The first accepts an [enum TransitionType] constant, and refers to the way the timing of the animation is handled (see [url=https://easings.net/]easings.net[/url] for some examples). The second accepts an [enum EaseType] constant, and controls where the [code]trans_type[/code] is applied to the interpolation (in the beginning, the end, or both). If you don't know which transition and easing to pick, you can try different [enum TransitionType] constants with [constant EASE_IN_OUT], and use the one that looks best. [url=https://raw.githubusercontent.com/godotengine/godot-docs/master/img/tween_cheatsheet.png]Tween easing and transition types cheatsheet[/url] + [b]Note:[/b] All [Tween]s will automatically start by default. To prevent a [Tween] from autostarting, you can call [method stop] immediately after it was created. </description> <tutorials> </tutorials> <methods> - <method name="follow_method"> - <return type="void"> + <method name="bind_node"> + <return type="Tween"> </return> - <argument index="0" name="object" type="Object"> - </argument> - <argument index="1" name="method" type="StringName"> - </argument> - <argument index="2" name="initial_val" type="Variant"> - </argument> - <argument index="3" name="target" type="Object"> - </argument> - <argument index="4" name="target_method" type="StringName"> - </argument> - <argument index="5" name="duration" type="float"> - </argument> - <argument index="6" name="trans_type" type="int" enum="Tween.TransitionType" default="0"> - </argument> - <argument index="7" name="ease_type" type="int" enum="Tween.EaseType" default="2"> - </argument> - <argument index="8" name="delay" type="float" default="0"> + <argument index="0" name="node" type="Node"> </argument> <description> - Follows [code]method[/code] of [code]object[/code] and applies the returned value on [code]target_method[/code] of [code]target[/code], beginning from [code]initial_val[/code] for [code]duration[/code] seconds, [code]delay[/code] later. Methods are called with consecutive values. - Use [enum TransitionType] for [code]trans_type[/code] and [enum EaseType] for [code]ease_type[/code] parameters. These values control the timing and direction of the interpolation. See the class description for more information. + Binds this [Tween] with the given [code]node[/code]. [Tween]s are processed directly by the [SceneTree], so they run independently of the animated nodes. When you bind a [Node] with the [Tween], the [Tween] will halt the animation when the object is not inside tree and the [Tween] will be automatically killed when the bound object is freed. Also [constant TWEEN_PAUSE_BOUND] will make the pausing behavior dependent on the bound node. + For a shorter way to create and bind a [Tween], you can use [method Node.create_tween]. </description> </method> - <method name="follow_property"> - <return type="void"> + <method name="chain"> + <return type="Tween"> </return> - <argument index="0" name="object" type="Object"> - </argument> - <argument index="1" name="property" type="NodePath"> - </argument> - <argument index="2" name="initial_val" type="Variant"> - </argument> - <argument index="3" name="target" type="Object"> - </argument> - <argument index="4" name="target_property" type="NodePath"> - </argument> - <argument index="5" name="duration" type="float"> - </argument> - <argument index="6" name="trans_type" type="int" enum="Tween.TransitionType" default="0"> - </argument> - <argument index="7" name="ease_type" type="int" enum="Tween.EaseType" default="2"> - </argument> - <argument index="8" name="delay" type="float" default="0"> - </argument> <description> - Follows [code]property[/code] of [code]object[/code] and applies it on [code]target_property[/code] of [code]target[/code], beginning from [code]initial_val[/code] for [code]duration[/code] seconds, [code]delay[/code] seconds later. - Use [enum TransitionType] for [code]trans_type[/code] and [enum EaseType] for [code]ease_type[/code] parameters. These values control the timing and direction of the interpolation. See the class description for more information. + Used to chain two [Tweener]s after [method set_parallel] is called with [code]true[/code]. + [codeblock] + var tween = create_tween().set_parallel(true) + tween.tween_property(...) + tween.tween_property(...) #will run parallelly with above + tween.chain().tween_property(...) #will run after two above are finished + [/codeblock] </description> </method> - <method name="get_runtime" qualifiers="const"> - <return type="float"> + <method name="custom_step"> + <return type="bool"> </return> + <argument index="0" name="delta" type="float"> + </argument> <description> - Returns the total time needed for all tweens to end. If you have two tweens, one lasting 10 seconds and the other 20 seconds, it would return 20 seconds, as by that time all tweens would have finished. + Processes the [Tween] by given [code]delta[/code] value, in seconds. Mostly useful when the [Tween] is paused, for controlling it manually. Can also be used to end the [Tween] animation immediately, by using [code]delta[/code] longer than the whole duration. + Returns [code]true[/code] if the [Tween] still has [Tweener]s that haven't finished. + [b]Note:[/b] The [Tween] will become invalid after finished, but you can call [method stop] after the step, to keep it and reset. </description> </method> - <method name="interpolate_callback"> - <return type="void"> + <method name="interpolate_value"> + <return type="Variant"> </return> - <argument index="0" name="object" type="Object"> - </argument> - <argument index="1" name="duration" type="float"> + <argument index="0" name="trans_type" type="Variant"> </argument> - <argument index="2" name="callback" type="String"> + <argument index="1" name="ease_type" type="Variant"> </argument> - <argument index="3" name="arg1" type="Variant" default="null"> + <argument index="2" name="elapsed_time" type="float"> </argument> - <argument index="4" name="arg2" type="Variant" default="null"> + <argument index="3" name="initial_value" type="float"> </argument> - <argument index="5" name="arg3" type="Variant" default="null"> + <argument index="4" name="delta_value" type="int" enum="Tween.TransitionType"> </argument> - <argument index="6" name="arg4" type="Variant" default="null"> - </argument> - <argument index="7" name="arg5" type="Variant" default="null"> + <argument index="5" name="duration" type="int" enum="Tween.EaseType"> </argument> <description> - Calls [code]callback[/code] of [code]object[/code] after [code]duration[/code]. [code]arg1[/code]-[code]arg5[/code] are arguments to be passed to the callback. + This method can be used for manual interpolation of a value, when you don't want [Tween] to do animating for you. It's similar to [method @GlobalScope.lerp], but with support for custom transition and easing. + [code]elapsed_time[/code] is the time in seconds that passed after the interping started and it's used to control the position of the interpolation. E.g. when it's equal to half of the [code]duration[/code], the interpolated value will be halfway between initial and final values. This value can also be greater than [code]duration[/code] or lower than 0, which will extrapolate the value. + [code]initial_value[/code] is the starting value of the interpolation. + [code]delta_value[/code] is the change of the value in the interpolation, i.e. it's equal to [code]final_value - initial_value[/code]. + [code]duration[/code] is the total time of the interpolation. </description> </method> - <method name="interpolate_deferred_callback"> - <return type="void"> + <method name="is_running"> + <return type="bool"> </return> - <argument index="0" name="object" type="Object"> - </argument> - <argument index="1" name="duration" type="float"> - </argument> - <argument index="2" name="callback" type="String"> - </argument> - <argument index="3" name="arg1" type="Variant" default="null"> - </argument> - <argument index="4" name="arg2" type="Variant" default="null"> - </argument> - <argument index="5" name="arg3" type="Variant" default="null"> - </argument> - <argument index="6" name="arg4" type="Variant" default="null"> - </argument> - <argument index="7" name="arg5" type="Variant" default="null"> - </argument> <description> - Calls [code]callback[/code] of [code]object[/code] after [code]duration[/code] on the main thread (similar to [method Object.call_deferred]). [code]arg1[/code]-[code]arg5[/code] are arguments to be passed to the callback. + Returns whether the [Tween] is currently running, i.e. it wasn't paused and it's not finished. </description> </method> - <method name="interpolate_method"> - <return type="void"> + <method name="is_valid"> + <return type="bool"> </return> - <argument index="0" name="object" type="Object"> - </argument> - <argument index="1" name="method" type="StringName"> - </argument> - <argument index="2" name="initial_val" type="Variant"> - </argument> - <argument index="3" name="final_val" type="Variant"> - </argument> - <argument index="4" name="duration" type="float"> - </argument> - <argument index="5" name="trans_type" type="int" enum="Tween.TransitionType" default="0"> - </argument> - <argument index="6" name="ease_type" type="int" enum="Tween.EaseType" default="2"> - </argument> - <argument index="7" name="delay" type="float" default="0"> - </argument> <description> - Animates [code]method[/code] of [code]object[/code] from [code]initial_val[/code] to [code]final_val[/code] for [code]duration[/code] seconds, [code]delay[/code] seconds later. Methods are called with consecutive values. - Use [enum TransitionType] for [code]trans_type[/code] and [enum EaseType] for [code]ease_type[/code] parameters. These values control the timing and direction of the interpolation. See the class description for more information. + Returns whether the [Tween] is valid. A valid [Tween] is a [Tween] contained by the scene tree (i.e. the array from [method SceneTree.get_processed_tweens] will contain this [Tween]). [Tween] might become invalid when it has finished tweening or was killed, also when created with [code]Tween.new()[/code]. Invalid [Tween] can't have [Tweener]s appended, because it can't animate them. You can however still use [method interpolate_value]. </description> </method> - <method name="interpolate_property"> + <method name="kill"> <return type="void"> </return> - <argument index="0" name="object" type="Object"> - </argument> - <argument index="1" name="property" type="NodePath"> - </argument> - <argument index="2" name="initial_val" type="Variant"> - </argument> - <argument index="3" name="final_val" type="Variant"> - </argument> - <argument index="4" name="duration" type="float"> - </argument> - <argument index="5" name="trans_type" type="int" enum="Tween.TransitionType" default="0"> - </argument> - <argument index="6" name="ease_type" type="int" enum="Tween.EaseType" default="2"> - </argument> - <argument index="7" name="delay" type="float" default="0"> - </argument> <description> - Animates [code]property[/code] of [code]object[/code] from [code]initial_val[/code] to [code]final_val[/code] for [code]duration[/code] seconds, [code]delay[/code] seconds later. Setting the initial value to [code]null[/code] uses the current value of the property. - Use [enum TransitionType] for [code]trans_type[/code] and [enum EaseType] for [code]ease_type[/code] parameters. These values control the timing and direction of the interpolation. See the class description for more information. + Aborts all tweening operations and invalidates the [Tween]. </description> </method> - <method name="is_active" qualifiers="const"> - <return type="bool"> + <method name="parallel"> + <return type="Tween"> </return> <description> - Returns [code]true[/code] if any tweens are currently running. - [b]Note:[/b] This method doesn't consider tweens that have ended. + Makes the next [Tweener] run parallely to the previous one. Example: + [codeblock] + var tween = create_tween() + tween.tween_property(...) + tween.parallel().tween_property(...) + tween.parallel().tween_property(...) + [/codeblock] + All [Tweener]s in the example will run at the same time. + You can make the [Tween] parallel by default by using [method set_parallel]. </description> </method> - <method name="remove"> + <method name="pause"> <return type="void"> </return> - <argument index="0" name="object" type="Object"> - </argument> - <argument index="1" name="key" type="StringName" default=""""> - </argument> <description> - Stops animation and removes a tween, given its object and property/method pair. By default, all tweens are removed, unless [code]key[/code] is specified. + Pauses the tweening. The animation can be resumed by using [method play]. </description> </method> - <method name="remove_all"> + <method name="play"> <return type="void"> </return> <description> - Stops animation and removes all tweens. + Resumes a paused or stopped [Tween]. </description> </method> - <method name="reset"> - <return type="void"> + <method name="set_ease"> + <return type="Tween"> </return> - <argument index="0" name="object" type="Object"> - </argument> - <argument index="1" name="key" type="StringName" default=""""> + <argument index="0" name="ease" type="int" enum="Tween.EaseType"> </argument> <description> - Resets a tween to its initial value (the one given, not the one before the tween), given its object and property/method pair. By default, all tweens are removed, unless [code]key[/code] is specified. + Sets the default ease type for [PropertyTweener]s and [MethodTweener]s animated by this [Tween]. </description> </method> - <method name="reset_all"> - <return type="void"> + <method name="set_loops"> + <return type="Tween"> </return> + <argument index="0" name="loops" type="int" default="0"> + </argument> <description> - Resets all tweens to their initial values (the ones given, not those before the tween). + Sets the number of times the tweening sequence will be repeated, i.e. [code]set_loops(2)[/code] will run the animation twice. + Calling this method without arguments will make the [Tween] run infinitely, until it is either killed by [method kill] or by freeing bound node, or all the animated objects have been freed (which makes further animation impossible). </description> </method> - <method name="resume"> - <return type="void"> + <method name="set_parallel"> + <return type="Tween"> </return> - <argument index="0" name="object" type="Object"> - </argument> - <argument index="1" name="key" type="StringName" default=""""> + <argument index="0" name="parallel" type="bool" default="true"> </argument> <description> - Continues animating a stopped tween, given its object and property/method pair. By default, all tweens are resumed, unless [code]key[/code] is specified. + If [code]parallel[/code] is [code]true[/code], the [Tweener]s appended after this method will by default run simultanously, as opposed to sequentially. </description> </method> - <method name="resume_all"> - <return type="void"> + <method name="set_pause_mode"> + <return type="Tween"> </return> + <argument index="0" name="mode" type="int" enum="Tween.TweenPauseMode"> + </argument> <description> - Continues animating all stopped tweens. + Determines the behavior of the [Tween] when the [SceneTree] is paused. Check [enum TweenPauseMode] for options. + Default value is [constant TWEEN_PAUSE_BOUND]. </description> </method> - <method name="seek"> - <return type="void"> + <method name="set_process_mode"> + <return type="Tween"> </return> - <argument index="0" name="time" type="float"> + <argument index="0" name="mode" type="int" enum="Tween.TweenProcessMode"> </argument> <description> - Sets the interpolation to the given [code]time[/code] in seconds. + Determines whether the [Tween] should run during idle frame (see [method Node._process]) or physics frame (see [method Node._physics_process]. + Default value is [constant TWEEN_PROCESS_IDLE]. </description> </method> - <method name="set_active"> - <return type="void"> + <method name="set_speed_scale"> + <return type="Tween"> </return> - <argument index="0" name="active" type="bool"> + <argument index="0" name="speed" type="float"> </argument> <description> - Activates/deactivates the tween. See also [method stop_all] and [method resume_all]. + Scales the speed of tweening. This affects all [Tweener]s and their delays. </description> </method> - <method name="start"> - <return type="void"> + <method name="set_trans"> + <return type="Tween"> </return> + <argument index="0" name="trans" type="int" enum="Tween.TransitionType"> + </argument> <description> - Starts the tween. You can define animations both before and after this. + Sets the default transition type for [PropertyTweener]s and [MethodTweener]s animated by this [Tween]. </description> </method> <method name="stop"> <return type="void"> </return> - <argument index="0" name="object" type="Object"> - </argument> - <argument index="1" name="key" type="StringName" default=""""> - </argument> <description> - Stops a tween, given its object and property/method pair. By default, all tweens are stopped, unless [code]key[/code] is specified. + Stops the tweening and resets the [Tween] to its initial state. This will not remove any appended [Tweener]s. </description> </method> - <method name="stop_all"> - <return type="void"> + <method name="tween_callback"> + <return type="CallbackTweener"> </return> + <argument index="0" name="callback" type="Callable"> + </argument> <description> - Stops animating all tweens. + Creates and appends a [CallbackTweener]. This method can be used to call an arbitrary method in any object. Use [method Callable.bind] to bind additional arguments for the call. + Example: object that keeps shooting every 1 second. + [codeblock] + var tween = get_tree().create_tween().set_loops() + tween.tween_callback(shoot).set_delay(1) + [/codeblock] + Example: turning a sprite red and then blue, with 2 second delay. + [codeblock] + var tween = get_tree().create_tween() + tween.tween_callback($Sprite.set_modulate.bind(Color.red)).set_delay(2) + tween.tween_callback($Sprite.set_modulate.bind(Color.blue)).set_delay(2) + [/codeblock] </description> </method> - <method name="targeting_method"> - <return type="void"> + <method name="tween_interval"> + <return type="IntervalTweener"> </return> - <argument index="0" name="object" type="Object"> - </argument> - <argument index="1" name="method" type="StringName"> - </argument> - <argument index="2" name="initial" type="Object"> - </argument> - <argument index="3" name="initial_method" type="StringName"> - </argument> - <argument index="4" name="final_val" type="Variant"> + <argument index="0" name="time" type="float"> </argument> - <argument index="5" name="duration" type="float"> + <description> + Creates and appends an [IntervalTweener]. This method can be used to create delays in the tween animation, as an alternative for using the delay in other [Tweener]s or when there's no animation (in which case the [Tween] acts as a timer). [code]time[/code] is the length of the interval, in seconds. + Example: creating an interval in code execution. + [codeblock] + #... some code + var tween = create_tween() + tween.tween_interval(2) + await tween.finished + #... more code + [/codeblock] + Example: creating an object that moves back and forth and jumps every few seconds. + [codeblock] + var tween = create_tween().set_loops() + tween.tween_property("position:x", 200, 1).as_relative() + tween.tween_callback(jump) + tween.tween_interval(2) + tween.tween_property("position:x", -200, 1).as_relative() + tween.tween_callback(jump) + tween.tween_interval(2) + [/codeblock] + </description> + </method> + <method name="tween_method"> + <return type="MethodTweener"> + </return> + <argument index="0" name="method" type="Callable"> </argument> - <argument index="6" name="trans_type" type="int" enum="Tween.TransitionType" default="0"> + <argument index="1" name="from" type="float"> </argument> - <argument index="7" name="ease_type" type="int" enum="Tween.EaseType" default="2"> + <argument index="2" name="to" type="float"> </argument> - <argument index="8" name="delay" type="float" default="0"> + <argument index="3" name="duration" type="float"> </argument> <description> - Animates [code]method[/code] of [code]object[/code] from the value returned by [code]initial_method[/code] to [code]final_val[/code] for [code]duration[/code] seconds, [code]delay[/code] seconds later. Methods are animated by calling them with consecutive values. - Use [enum TransitionType] for [code]trans_type[/code] and [enum EaseType] for [code]ease_type[/code] parameters. These values control the timing and direction of the interpolation. See the class description for more information. + Creates and appends a [MethodTweener]. This method is similar to a combination of [method tween_callback] and [method tween_property]. It calls a method over time with a tweened value provided as an argument. The value is tweened between [code]from[/code] and [code]to[/code] over the time specified by [code]duration[/code], in seconds. Use [method Callable.bind] to bind additional arguments for the call. You can use [method MethodTweener.set_ease] and [method MethodTweener.set_trans] to tweak the easing and transition of the value or [method MethodTweener.set_delay] to delay the tweening. + Example: making a 3D object look from one point to another point. + [codeblock] + var tween = create_tween() + tween.tween_method(look_at.bind(Vector3.UP), Vector3(-1, 0, -1), Vector3(1, 0, -1), 1) #the look_at() method takes up vector as second argument + [/codeblock] + Example: setting a text of a [Label], using an intermediate method and after a delay. + [codeblock] + func _ready(): + var tween = create_tween() + tween.tween_method(set_label_text, 0, 10, 1).set_delay(1) + + func set_label_text(value: int): + $Label.text = "Counting " + str(value) + [/codeblock] </description> </method> - <method name="targeting_property"> - <return type="void"> + <method name="tween_property"> + <return type="PropertyTweener"> </return> <argument index="0" name="object" type="Object"> </argument> <argument index="1" name="property" type="NodePath"> </argument> - <argument index="2" name="initial" type="Object"> - </argument> - <argument index="3" name="initial_val" type="NodePath"> - </argument> - <argument index="4" name="final_val" type="Variant"> + <argument index="2" name="final_val" type="Variant"> </argument> - <argument index="5" name="duration" type="float"> + <argument index="3" name="duration" type="float"> </argument> - <argument index="6" name="trans_type" type="int" enum="Tween.TransitionType" default="0"> - </argument> - <argument index="7" name="ease_type" type="int" enum="Tween.EaseType" default="2"> - </argument> - <argument index="8" name="delay" type="float" default="0"> - </argument> - <description> - Animates [code]property[/code] of [code]object[/code] from the current value of the [code]initial_val[/code] property of [code]initial[/code] to [code]final_val[/code] for [code]duration[/code] seconds, [code]delay[/code] seconds later. - Use [enum TransitionType] for [code]trans_type[/code] and [enum EaseType] for [code]ease_type[/code] parameters. These values control the timing and direction of the interpolation. See the class description for more information. - </description> - </method> - <method name="tell" qualifiers="const"> - <return type="float"> - </return> <description> - Returns the current time of the tween. + Creates and appends a [PropertyTweener]. This method tweens a [code]property[/code] of an [code]object[/code] between an initial value and [code]final_val[/code] in a span of time equal to [code]duration[/code], in seconds. The initial value by default is a value at the time the tweening of the [PropertyTweener] start. For example: + [codeblock] + var tween = create_tween() + tween.tween_property($Sprite, "position", Vector2(100, 200) + tween.tween_property($Sprite, "position", Vector2(200, 300) + [/codeblock] + will move the sprite to position (100, 200) and then to (200, 300). If you use [method PropertyTweener.from] or [method PropertyTweener.from_current], the starting position will be overwritten by the given value instead. See other methods in [PropertyTweener] to see how the tweening can be tweaked further. + [b]Note:[/b] You can find the correct property name by hovering over the property in the Inspector. You can also provide the components of a property directly by using [code]"property:component"[/code] (eg. [code]position:x[/code]), where it would only apply to that particular component. + Example: moving object twice from the same position, with different transition types. + [codeblock] + var tween = create_tween() + tween.tween_property($Sprite, "position", Vector2.RIGHT * 300).as_relative().set_trans(Tween.TRANS_SINE) + tween.tween_property($Sprite, "position", Vector2.RIGHT * 300).as_relative().from_current().set_trans(Tween.TRANS_EXPO) + [/codeblock] </description> </method> </methods> - <members> - <member name="playback_process_mode" type="int" setter="set_tween_process_mode" getter="get_tween_process_mode" enum="Tween.TweenProcessMode" default="1"> - The tween's animation process thread. See [enum TweenProcessMode]. - </member> - <member name="playback_speed" type="float" setter="set_speed_scale" getter="get_speed_scale" default="1.0"> - The tween's speed multiplier. For example, set it to [code]1.0[/code] for normal speed, [code]2.0[/code] for two times normal speed, or [code]0.5[/code] for half of the normal speed. A value of [code]0[/code] pauses the animation, but see also [method set_active] or [method stop_all] for this. - </member> - <member name="repeat" type="bool" setter="set_repeat" getter="is_repeat" default="false"> - If [code]true[/code], the tween loops. - </member> - </members> <signals> - <signal name="tween_all_completed"> + <signal name="finished"> <description> - Emitted when all processes in a tween end. + Emitted when the [Tween] has finished all tweening. Never emitted when the [Tween] is set to infinite looping (see [method set_loops]). + [b]Note:[/b] The [Tween] is removed (invalidated) after this signal is emitted, but it doesn't happen immediately, but on the next processing frame. Calling [method stop] inside the signal callback will preserve the [Tween]. </description> </signal> - <signal name="tween_completed"> - <argument index="0" name="object" type="Object"> - </argument> - <argument index="1" name="key" type="NodePath"> + <signal name="loop_finished"> + <argument index="0" name="loop_count" type="int"> </argument> <description> - Emitted when a tween ends. + Emitted when a full loop is complete (see [method set_loops]), providing the loop index. This signal is not emitted after final loop, use [signal finished] instead for this case. </description> </signal> - <signal name="tween_started"> - <argument index="0" name="object" type="Object"> - </argument> - <argument index="1" name="key" type="NodePath"> + <signal name="step_finished"> + <argument index="0" name="idx" type="int"> </argument> <description> - Emitted when a tween starts. - </description> - </signal> - <signal name="tween_step"> - <argument index="0" name="object" type="Object"> - </argument> - <argument index="1" name="key" type="NodePath"> - </argument> - <argument index="2" name="elapsed" type="float"> - </argument> - <argument index="3" name="value" type="Object"> - </argument> - <description> - Emitted at each step of the animation. + Emitted when one step of the [Tween] is complete, providing the step index. One step is either a single [Tweener] or a group of [Tweener]s running parallelly. </description> </signal> </signals> <constants> <constant name="TWEEN_PROCESS_PHYSICS" value="0" enum="TweenProcessMode"> - The tween updates with the [code]_physics_process[/code] callback. + The [Tween] updates during physics frame. </constant> <constant name="TWEEN_PROCESS_IDLE" value="1" enum="TweenProcessMode"> - The tween updates with the [code]_process[/code] callback. + The [Tween] updates during idle + </constant> + <constant name="TWEEN_PAUSE_BOUND" value="0" enum="TweenPauseMode"> + </constant> + <constant name="TWEEN_PAUSE_STOP" value="1" enum="TweenPauseMode"> + </constant> + <constant name="TWEEN_PAUSE_PROCESS" value="2" enum="TweenPauseMode"> </constant> <constant name="TRANS_LINEAR" value="0" enum="TransitionType"> - The animation is interpolated linearly. </constant> <constant name="TRANS_SINE" value="1" enum="TransitionType"> - The animation is interpolated using a sine function. </constant> <constant name="TRANS_QUINT" value="2" enum="TransitionType"> - The animation is interpolated with a quintic (to the power of 5) function. </constant> <constant name="TRANS_QUART" value="3" enum="TransitionType"> - The animation is interpolated with a quartic (to the power of 4) function. </constant> <constant name="TRANS_QUAD" value="4" enum="TransitionType"> - The animation is interpolated with a quadratic (to the power of 2) function. </constant> <constant name="TRANS_EXPO" value="5" enum="TransitionType"> - The animation is interpolated with an exponential (to the power of x) function. </constant> <constant name="TRANS_ELASTIC" value="6" enum="TransitionType"> - The animation is interpolated with elasticity, wiggling around the edges. </constant> <constant name="TRANS_CUBIC" value="7" enum="TransitionType"> - The animation is interpolated with a cubic (to the power of 3) function. </constant> <constant name="TRANS_CIRC" value="8" enum="TransitionType"> - The animation is interpolated with a function using square roots. </constant> <constant name="TRANS_BOUNCE" value="9" enum="TransitionType"> - The animation is interpolated by bouncing at the end. </constant> <constant name="TRANS_BACK" value="10" enum="TransitionType"> - The animation is interpolated backing out at ends. </constant> <constant name="EASE_IN" value="0" enum="EaseType"> - The interpolation starts slowly and speeds up towards the end. </constant> <constant name="EASE_OUT" value="1" enum="EaseType"> - The interpolation starts quickly and slows down towards the end. </constant> <constant name="EASE_IN_OUT" value="2" enum="EaseType"> - A combination of [constant EASE_IN] and [constant EASE_OUT]. The interpolation is slowest at both ends. </constant> <constant name="EASE_OUT_IN" value="3" enum="EaseType"> - A combination of [constant EASE_IN] and [constant EASE_OUT]. The interpolation is fastest at both ends. </constant> </constants> </class> diff --git a/doc/classes/Tweener.xml b/doc/classes/Tweener.xml new file mode 100644 index 0000000000..5cd502ced9 --- /dev/null +++ b/doc/classes/Tweener.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="Tweener" inherits="RefCounted" version="4.0"> + <brief_description> + Abstract class for all Tweeners used by [Tween]. + </brief_description> + <description> + Tweeners are objects that perform a specific animating task, e.g. interpolating a property or calling a method at a given time. A [Tweener] can't be created manually, you need to use a dedicated method from [Tween] or [Node]. + </description> + <tutorials> + </tutorials> + <methods> + </methods> + <signals> + <signal name="finished"> + <description> + Emited when the [Tweener] has just finished its job. + </description> + </signal> + </signals> + <constants> + </constants> +</class> diff --git a/doc/classes/Vector2.xml b/doc/classes/Vector2.xml index 07d09c31dc..498aefbef0 100644 --- a/doc/classes/Vector2.xml +++ b/doc/classes/Vector2.xml @@ -304,12 +304,6 @@ <method name="operator +" qualifiers="operator"> <return type="Vector2"> </return> - <description> - </description> - </method> - <method name="operator +" qualifiers="operator"> - <return type="Vector2"> - </return> <argument index="0" name="right" type="Vector2"> </argument> <description> @@ -318,12 +312,6 @@ <method name="operator -" qualifiers="operator"> <return type="Vector2"> </return> - <description> - </description> - </method> - <method name="operator -" qualifiers="operator"> - <return type="Vector2"> - </return> <argument index="0" name="right" type="Vector2"> </argument> <description> @@ -401,6 +389,18 @@ <description> </description> </method> + <method name="operator unary+" qualifiers="operator"> + <return type="Vector2"> + </return> + <description> + </description> + </method> + <method name="operator unary-" qualifiers="operator"> + <return type="Vector2"> + </return> + <description> + </description> + </method> <method name="orthogonal" qualifiers="const"> <return type="Vector2"> </return> diff --git a/doc/classes/Vector2i.xml b/doc/classes/Vector2i.xml index 930ec944ba..5f190de8ca 100644 --- a/doc/classes/Vector2i.xml +++ b/doc/classes/Vector2i.xml @@ -126,12 +126,6 @@ <method name="operator +" qualifiers="operator"> <return type="Vector2i"> </return> - <description> - </description> - </method> - <method name="operator +" qualifiers="operator"> - <return type="Vector2i"> - </return> <argument index="0" name="right" type="Vector2i"> </argument> <description> @@ -140,12 +134,6 @@ <method name="operator -" qualifiers="operator"> <return type="Vector2i"> </return> - <description> - </description> - </method> - <method name="operator -" qualifiers="operator"> - <return type="Vector2i"> - </return> <argument index="0" name="right" type="Vector2i"> </argument> <description> @@ -223,6 +211,18 @@ <description> </description> </method> + <method name="operator unary+" qualifiers="operator"> + <return type="Vector2i"> + </return> + <description> + </description> + </method> + <method name="operator unary-" qualifiers="operator"> + <return type="Vector2i"> + </return> + <description> + </description> + </method> <method name="sign" qualifiers="const"> <return type="Vector2i"> </return> diff --git a/doc/classes/Vector3.xml b/doc/classes/Vector3.xml index eb1fd5f098..1361666c18 100644 --- a/doc/classes/Vector3.xml +++ b/doc/classes/Vector3.xml @@ -318,12 +318,6 @@ <method name="operator +" qualifiers="operator"> <return type="Vector3"> </return> - <description> - </description> - </method> - <method name="operator +" qualifiers="operator"> - <return type="Vector3"> - </return> <argument index="0" name="right" type="Vector3"> </argument> <description> @@ -332,12 +326,6 @@ <method name="operator -" qualifiers="operator"> <return type="Vector3"> </return> - <description> - </description> - </method> - <method name="operator -" qualifiers="operator"> - <return type="Vector3"> - </return> <argument index="0" name="right" type="Vector3"> </argument> <description> @@ -415,6 +403,18 @@ <description> </description> </method> + <method name="operator unary+" qualifiers="operator"> + <return type="Vector3"> + </return> + <description> + </description> + </method> + <method name="operator unary-" qualifiers="operator"> + <return type="Vector3"> + </return> + <description> + </description> + </method> <method name="outer" qualifiers="const"> <return type="Basis"> </return> diff --git a/doc/classes/Vector3i.xml b/doc/classes/Vector3i.xml index 8b45a62afa..e08bafa665 100644 --- a/doc/classes/Vector3i.xml +++ b/doc/classes/Vector3i.xml @@ -134,12 +134,6 @@ <method name="operator +" qualifiers="operator"> <return type="Vector3i"> </return> - <description> - </description> - </method> - <method name="operator +" qualifiers="operator"> - <return type="Vector3i"> - </return> <argument index="0" name="right" type="Vector3i"> </argument> <description> @@ -148,12 +142,6 @@ <method name="operator -" qualifiers="operator"> <return type="Vector3i"> </return> - <description> - </description> - </method> - <method name="operator -" qualifiers="operator"> - <return type="Vector3i"> - </return> <argument index="0" name="right" type="Vector3i"> </argument> <description> @@ -231,6 +219,18 @@ <description> </description> </method> + <method name="operator unary+" qualifiers="operator"> + <return type="Vector3i"> + </return> + <description> + </description> + </method> + <method name="operator unary-" qualifiers="operator"> + <return type="Vector3i"> + </return> + <description> + </description> + </method> <method name="sign" qualifiers="const"> <return type="Vector3i"> </return> diff --git a/doc/classes/Viewport.xml b/doc/classes/Viewport.xml index 292be34a0d..00827fe324 100644 --- a/doc/classes/Viewport.xml +++ b/doc/classes/Viewport.xml @@ -60,10 +60,11 @@ <method name="get_render_info"> <return type="int"> </return> - <argument index="0" name="info" type="int" enum="Viewport.RenderInfo"> + <argument index="0" name="type" type="int" enum="Viewport.RenderInfoType"> + </argument> + <argument index="1" name="info" type="int" enum="Viewport.RenderInfo"> </argument> <description> - Returns information about the viewport from the rendering pipeline. </description> </method> <method name="get_shadow_atlas_quadrant_subdiv" qualifiers="const"> @@ -208,6 +209,9 @@ <member name="debug_draw" type="int" setter="set_debug_draw" getter="get_debug_draw" enum="Viewport.DebugDraw" default="0"> The overlay mode for test rendered geometry in debug purposes. </member> + <member name="disable_3d" type="bool" setter="set_disable_3d" getter="is_3d_disabled" default="false"> + Disable 3D rendering (but keep 2D rendering). + </member> <member name="global_canvas_transform" type="Transform2D" setter="set_global_canvas_transform" getter="get_global_canvas_transform"> The global canvas transform of the viewport. The canvas transform is relative to this. </member> @@ -347,23 +351,20 @@ <constant name="RENDER_INFO_OBJECTS_IN_FRAME" value="0" enum="RenderInfo"> Amount of objects in frame. </constant> - <constant name="RENDER_INFO_VERTICES_IN_FRAME" value="1" enum="RenderInfo"> + <constant name="RENDER_INFO_PRIMITIVES_IN_FRAME" value="1" enum="RenderInfo"> Amount of vertices in frame. </constant> - <constant name="RENDER_INFO_MATERIAL_CHANGES_IN_FRAME" value="2" enum="RenderInfo"> - Amount of material changes in frame. + <constant name="RENDER_INFO_DRAW_CALLS_IN_FRAME" value="2" enum="RenderInfo"> + Amount of draw calls in frame. </constant> - <constant name="RENDER_INFO_SHADER_CHANGES_IN_FRAME" value="3" enum="RenderInfo"> - Amount of shader changes in frame. + <constant name="RENDER_INFO_MAX" value="3" enum="RenderInfo"> + Represents the size of the [enum RenderInfo] enum. </constant> - <constant name="RENDER_INFO_SURFACE_CHANGES_IN_FRAME" value="4" enum="RenderInfo"> - Amount of surface changes in frame. + <constant name="RENDER_INFO_TYPE_VISIBLE" value="0" enum="RenderInfoType"> </constant> - <constant name="RENDER_INFO_DRAW_CALLS_IN_FRAME" value="5" enum="RenderInfo"> - Amount of draw calls in frame. + <constant name="RENDER_INFO_TYPE_SHADOW" value="1" enum="RenderInfoType"> </constant> - <constant name="RENDER_INFO_MAX" value="6" enum="RenderInfo"> - Represents the size of the [enum RenderInfo] enum. + <constant name="RENDER_INFO_TYPE_MAX" value="2" enum="RenderInfoType"> </constant> <constant name="DEBUG_DRAW_DISABLED" value="0" enum="DebugDraw"> Objects are displayed normally. diff --git a/doc/classes/VoxelGIData.xml b/doc/classes/VoxelGIData.xml index 88a0411e2b..f613002233 100644 --- a/doc/classes/VoxelGIData.xml +++ b/doc/classes/VoxelGIData.xml @@ -66,12 +66,6 @@ </method> </methods> <members> - <member name="anisotropy_strength" type="float" setter="set_anisotropy_strength" getter="get_anisotropy_strength" default="0.5"> - </member> - <member name="ao" type="float" setter="set_ao" getter="get_ao" default="0.0"> - </member> - <member name="ao_size" type="float" setter="set_ao_size" getter="get_ao_size" default="0.5"> - </member> <member name="bias" type="float" setter="set_bias" getter="get_bias" default="1.5"> </member> <member name="dynamic_range" type="float" setter="set_dynamic_range" getter="get_dynamic_range" default="4.0"> diff --git a/doc/classes/Window.xml b/doc/classes/Window.xml index 6ae5a5f449..73a95967bd 100644 --- a/doc/classes/Window.xml +++ b/doc/classes/Window.xml @@ -19,6 +19,13 @@ <description> </description> </method> + <method name="get_contents_minimum_size" qualifiers="const"> + <return type="Vector2"> + </return> + <description> + Returns the combined minimum size from the child [Control] nodes of the window. + </description> + </method> <method name="get_flag" qualifiers="const"> <return type="bool"> </return> diff --git a/doc/classes/WorldEnvironment.xml b/doc/classes/WorldEnvironment.xml index c1cf639ec0..6aa2db00b4 100644 --- a/doc/classes/WorldEnvironment.xml +++ b/doc/classes/WorldEnvironment.xml @@ -5,7 +5,7 @@ </brief_description> <description> The [WorldEnvironment] node is used to configure the default [Environment] for the scene. - The parameters defined in the [WorldEnvironment] can be overridden by an [Environment] node set on the current [Camera3D]. Additionally, only one [WorldEnvironment] may be instanced in a given scene at a time. + The parameters defined in the [WorldEnvironment] can be overridden by an [Environment] node set on the current [Camera3D]. Additionally, only one [WorldEnvironment] may be instantiated in a given scene at a time. The [WorldEnvironment] allows the user to specify default lighting parameters (e.g. ambient lighting), various post-processing effects (e.g. SSAO, DOF, Tonemapping), and how to draw the background (e.g. solid color, skybox). Usually, these are added in order to improve the realism/color balance of the scene. </description> <tutorials> diff --git a/doc/classes/float.xml b/doc/classes/float.xml index f75c130039..585c847d22 100644 --- a/doc/classes/float.xml +++ b/doc/classes/float.xml @@ -145,16 +145,6 @@ <method name="operator +" qualifiers="operator"> <return type="float"> </return> - <description> - Unary plus operator. Doesn't have any effect. - [codeblock] - var a = +2.5 # a is 2.5. - [/codeblock] - </description> - </method> - <method name="operator +" qualifiers="operator"> - <return type="float"> - </return> <argument index="0" name="right" type="float"> </argument> <description> @@ -173,17 +163,6 @@ <method name="operator -" qualifiers="operator"> <return type="float"> </return> - <description> - Unary minus operator. Negates the number. - [codeblock] - var a = -2.5 # a is -2.5. - print(-a) # 2.5 - [/codeblock] - </description> - </method> - <method name="operator -" qualifiers="operator"> - <return type="float"> - </return> <argument index="0" name="right" type="float"> </argument> <description> @@ -308,6 +287,18 @@ Returns [code]true[/code] if this [float] is greater than or equal to the given [int]. </description> </method> + <method name="operator unary+" qualifiers="operator"> + <return type="float"> + </return> + <description> + </description> + </method> + <method name="operator unary-" qualifiers="operator"> + <return type="float"> + </return> + <description> + </description> + </method> </methods> <constants> </constants> diff --git a/doc/classes/int.xml b/doc/classes/int.xml index b0ad963998..95918c9007 100644 --- a/doc/classes/int.xml +++ b/doc/classes/int.xml @@ -126,21 +126,21 @@ </description> </method> <method name="operator *" qualifiers="operator"> - <return type="float"> + <return type="int"> </return> - <argument index="0" name="right" type="float"> + <argument index="0" name="right" type="int"> </argument> <description> - Multiplies an [int] and a [float]. The result is a [float]. + Multiplies two [int]s. </description> </method> <method name="operator *" qualifiers="operator"> - <return type="int"> + <return type="float"> </return> - <argument index="0" name="right" type="int"> + <argument index="0" name="right" type="float"> </argument> <description> - Multiplies two [int]s. + Multiplies an [int] and a [float]. The result is a [float]. </description> </method> <method name="operator *" qualifiers="operator"> @@ -204,16 +204,6 @@ </description> </method> <method name="operator +" qualifiers="operator"> - <return type="int"> - </return> - <description> - Unary plus operator. Doesn't have any effect. - [codeblock] - var a = +1 # a is 1. - [/codeblock] - </description> - </method> - <method name="operator +" qualifiers="operator"> <return type="float"> </return> <argument index="0" name="right" type="float"> @@ -232,17 +222,6 @@ </description> </method> <method name="operator -" qualifiers="operator"> - <return type="int"> - </return> - <description> - Unary minus operator. Negates the number. - [codeblock] - var a = -1 # a is -1. - print(-a) # 1 - [/codeblock] - </description> - </method> - <method name="operator -" qualifiers="operator"> <return type="float"> </return> <argument index="0" name="right" type="float"> @@ -414,6 +393,18 @@ [/codeblock] </description> </method> + <method name="operator unary+" qualifiers="operator"> + <return type="int"> + </return> + <description> + </description> + </method> + <method name="operator unary-" qualifiers="operator"> + <return type="int"> + </return> + <description> + </description> + </method> <method name="operator |" qualifiers="operator"> <return type="int"> </return> diff --git a/doc/tools/makerst.py b/doc/tools/makerst.py index 1c6055f8ca..9be7751d3d 100755 --- a/doc/tools/makerst.py +++ b/doc/tools/makerst.py @@ -350,6 +350,9 @@ def main(): # type: () -> None pattern = re.compile(args.filter) + # Create the output folder recursively if it doesn't already exist. + os.makedirs(args.output, exist_ok=True) + for class_name, class_def in state.classes.items(): if args.filter and not pattern.search(class_def.filepath): continue @@ -358,6 +361,8 @@ def main(): # type: () -> None if not state.errored: print("No errors found.") + if not args.dry_run: + print("Wrote reStructuredText files for each class to: %s" % args.output) else: print("Errors were found in the class reference XML. Please check the messages above.") exit(1) @@ -837,7 +842,7 @@ def rstize_text(text, state): # type: (str, State) -> str inside_code = True elif cmd == "gdscript": tag_depth += 1 - tag_text = "\n .. code-tab:: gdscript GDScript\n" + tag_text = "\n .. code-tab:: gdscript\n" inside_code = True elif cmd == "csharp": tag_depth += 1 diff --git a/doc/translations/ar.po b/doc/translations/ar.po index 77a3d39f27..4199bca6c7 100644 --- a/doc/translations/ar.po +++ b/doc/translations/ar.po @@ -701,7 +701,7 @@ msgid "" "the FileSystem dock into the script.\n" "[codeblock]\n" "# Instance a scene.\n" -"var diamond = preload(\"res://diamond.tscn\").instance()\n" +"var diamond = preload(\"res://diamond.tscn\").instantiate()\n" "[/codeblock]" msgstr "" @@ -13825,7 +13825,7 @@ msgid "" "Example of usage with custom scene instance:\n" "[codeblock]\n" "func _make_custom_tooltip(for_text):\n" -" var tooltip = preload(\"SomeTooltipScene.tscn\").instance()\n" +" var tooltip = preload(\"SomeTooltipScene.tscn\").instantiate()\n" " tooltip.get_node(\"Label\").text = for_text\n" " return tooltip\n" "[/codeblock]" @@ -34691,7 +34691,7 @@ msgid "" "[codeblock]\n" "# Use `load()` instead of `preload()` if the path isn't known at compile-" "time.\n" -"var scene = preload(\"res://scene.tscn\").instance()\n" +"var scene = preload(\"res://scene.tscn\").instantiate()\n" "# Add the node as a child of the node the script is attached to.\n" "add_child(scene)\n" "[/codeblock]\n" diff --git a/doc/translations/ca.po b/doc/translations/ca.po index 8ea801181d..c72cba18bc 100644 --- a/doc/translations/ca.po +++ b/doc/translations/ca.po @@ -732,7 +732,7 @@ msgid "" "the FileSystem dock into the script.\n" "[codeblock]\n" "# Instance a scene.\n" -"var diamond = preload(\"res://diamond.tscn\").instance()\n" +"var diamond = preload(\"res://diamond.tscn\").instantiate()\n" "[/codeblock]" msgstr "" @@ -13856,7 +13856,7 @@ msgid "" "Example of usage with custom scene instance:\n" "[codeblock]\n" "func _make_custom_tooltip(for_text):\n" -" var tooltip = preload(\"SomeTooltipScene.tscn\").instance()\n" +" var tooltip = preload(\"SomeTooltipScene.tscn\").instantiate()\n" " tooltip.get_node(\"Label\").text = for_text\n" " return tooltip\n" "[/codeblock]" @@ -34722,7 +34722,7 @@ msgid "" "[codeblock]\n" "# Use `load()` instead of `preload()` if the path isn't known at compile-" "time.\n" -"var scene = preload(\"res://scene.tscn\").instance()\n" +"var scene = preload(\"res://scene.tscn\").instantiate()\n" "# Add the node as a child of the node the script is attached to.\n" "add_child(scene)\n" "[/codeblock]\n" diff --git a/doc/translations/classes.pot b/doc/translations/classes.pot index f138276364..321e67f759 100644 --- a/doc/translations/classes.pot +++ b/doc/translations/classes.pot @@ -702,7 +702,7 @@ msgid "" "the FileSystem dock into the script.\n" "[codeblock]\n" "# Instance a scene.\n" -"var diamond = preload(\"res://diamond.tscn\").instance()\n" +"var diamond = preload(\"res://diamond.tscn\").instantiate()\n" "[/codeblock]" msgstr "" @@ -13826,7 +13826,7 @@ msgid "" "Example of usage with custom scene instance:\n" "[codeblock]\n" "func _make_custom_tooltip(for_text):\n" -" var tooltip = preload(\"SomeTooltipScene.tscn\").instance()\n" +" var tooltip = preload(\"SomeTooltipScene.tscn\").instantiate()\n" " tooltip.get_node(\"Label\").text = for_text\n" " return tooltip\n" "[/codeblock]" @@ -34692,7 +34692,7 @@ msgid "" "[codeblock]\n" "# Use `load()` instead of `preload()` if the path isn't known at compile-" "time.\n" -"var scene = preload(\"res://scene.tscn\").instance()\n" +"var scene = preload(\"res://scene.tscn\").instantiate()\n" "# Add the node as a child of the node the script is attached to.\n" "add_child(scene)\n" "[/codeblock]\n" diff --git a/doc/translations/cs.po b/doc/translations/cs.po index a267656497..3584fc5062 100644 --- a/doc/translations/cs.po +++ b/doc/translations/cs.po @@ -1058,7 +1058,7 @@ msgid "" "the FileSystem dock into the script.\n" "[codeblock]\n" "# Instance a scene.\n" -"var diamond = preload(\"res://diamond.tscn\").instance()\n" +"var diamond = preload(\"res://diamond.tscn\").instantiate()\n" "[/codeblock]" msgstr "" @@ -14318,7 +14318,7 @@ msgid "" "Example of usage with custom scene instance:\n" "[codeblock]\n" "func _make_custom_tooltip(for_text):\n" -" var tooltip = preload(\"SomeTooltipScene.tscn\").instance()\n" +" var tooltip = preload(\"SomeTooltipScene.tscn\").instantiate()\n" " tooltip.get_node(\"Label\").text = for_text\n" " return tooltip\n" "[/codeblock]" @@ -35192,7 +35192,7 @@ msgid "" "[codeblock]\n" "# Use `load()` instead of `preload()` if the path isn't known at compile-" "time.\n" -"var scene = preload(\"res://scene.tscn\").instance()\n" +"var scene = preload(\"res://scene.tscn\").instantiate()\n" "# Add the node as a child of the node the script is attached to.\n" "add_child(scene)\n" "[/codeblock]\n" diff --git a/doc/translations/de.po b/doc/translations/de.po index 181d64d525..76eff809ff 100644 --- a/doc/translations/de.po +++ b/doc/translations/de.po @@ -992,7 +992,7 @@ msgid "" "the FileSystem dock into the script.\n" "[codeblock]\n" "# Instance a scene.\n" -"var diamond = preload(\"res://diamond.tscn\").instance()\n" +"var diamond = preload(\"res://diamond.tscn\").instantiate()\n" "[/codeblock]" msgstr "" @@ -14154,7 +14154,7 @@ msgid "" "Example of usage with custom scene instance:\n" "[codeblock]\n" "func _make_custom_tooltip(for_text):\n" -" var tooltip = preload(\"SomeTooltipScene.tscn\").instance()\n" +" var tooltip = preload(\"SomeTooltipScene.tscn\").instantiate()\n" " tooltip.get_node(\"Label\").text = for_text\n" " return tooltip\n" "[/codeblock]" @@ -35118,7 +35118,7 @@ msgid "" "[codeblock]\n" "# Use `load()` instead of `preload()` if the path isn't known at compile-" "time.\n" -"var scene = preload(\"res://scene.tscn\").instance()\n" +"var scene = preload(\"res://scene.tscn\").instantiate()\n" "# Add the node as a child of the node the script is attached to.\n" "add_child(scene)\n" "[/codeblock]\n" diff --git a/doc/translations/es.po b/doc/translations/es.po index 7df36316b7..44b3b22597 100644 --- a/doc/translations/es.po +++ b/doc/translations/es.po @@ -1119,7 +1119,7 @@ msgid "" "the FileSystem dock into the script.\n" "[codeblock]\n" "# Instance a scene.\n" -"var diamond = preload(\"res://diamond.tscn\").instance()\n" +"var diamond = preload(\"res://diamond.tscn\").instantiate()\n" "[/codeblock]" msgstr "" @@ -18123,7 +18123,7 @@ msgid "" "Example of usage with custom scene instance:\n" "[codeblock]\n" "func _make_custom_tooltip(for_text):\n" -" var tooltip = preload(\"SomeTooltipScene.tscn\").instance()\n" +" var tooltip = preload(\"SomeTooltipScene.tscn\").instantiate()\n" " tooltip.get_node(\"Label\").text = for_text\n" " return tooltip\n" "[/codeblock]" @@ -18150,7 +18150,7 @@ msgstr "" "Ejemplo de uso con una instancia de una escena personalizada<\n" "[codeblock]\n" "func _make_custom_tooltip(for_text):\n" -" var sugerencia = preload(\"algunaEscenaSugerencia.tscn\").instance()\n" +" var sugerencia = preload(\"algunaEscenaSugerencia.tscn\").instantiate()\n" " tooltip.get_node(\"etiqueta\").text = para_texto\n" " return sugerencia\n" "[/codeblock]" @@ -46659,7 +46659,7 @@ msgid "" "[codeblock]\n" "# Use `load()` instead of `preload()` if the path isn't known at compile-" "time.\n" -"var scene = preload(\"res://scene.tscn\").instance()\n" +"var scene = preload(\"res://scene.tscn\").instantiate()\n" "# Add the node as a child of the node the script is attached to.\n" "add_child(scene)\n" "[/codeblock]\n" diff --git a/doc/translations/fa.po b/doc/translations/fa.po index e440146dd3..2a185fadc5 100644 --- a/doc/translations/fa.po +++ b/doc/translations/fa.po @@ -707,7 +707,7 @@ msgid "" "the FileSystem dock into the script.\n" "[codeblock]\n" "# Instance a scene.\n" -"var diamond = preload(\"res://diamond.tscn\").instance()\n" +"var diamond = preload(\"res://diamond.tscn\").instantiate()\n" "[/codeblock]" msgstr "" @@ -13831,7 +13831,7 @@ msgid "" "Example of usage with custom scene instance:\n" "[codeblock]\n" "func _make_custom_tooltip(for_text):\n" -" var tooltip = preload(\"SomeTooltipScene.tscn\").instance()\n" +" var tooltip = preload(\"SomeTooltipScene.tscn\").instantiate()\n" " tooltip.get_node(\"Label\").text = for_text\n" " return tooltip\n" "[/codeblock]" @@ -34697,7 +34697,7 @@ msgid "" "[codeblock]\n" "# Use `load()` instead of `preload()` if the path isn't known at compile-" "time.\n" -"var scene = preload(\"res://scene.tscn\").instance()\n" +"var scene = preload(\"res://scene.tscn\").instantiate()\n" "# Add the node as a child of the node the script is attached to.\n" "add_child(scene)\n" "[/codeblock]\n" diff --git a/doc/translations/fi.po b/doc/translations/fi.po index 92ec4f29dd..a5f470c60b 100644 --- a/doc/translations/fi.po +++ b/doc/translations/fi.po @@ -720,7 +720,7 @@ msgid "" "the FileSystem dock into the script.\n" "[codeblock]\n" "# Instance a scene.\n" -"var diamond = preload(\"res://diamond.tscn\").instance()\n" +"var diamond = preload(\"res://diamond.tscn\").instantiate()\n" "[/codeblock]" msgstr "" @@ -13844,7 +13844,7 @@ msgid "" "Example of usage with custom scene instance:\n" "[codeblock]\n" "func _make_custom_tooltip(for_text):\n" -" var tooltip = preload(\"SomeTooltipScene.tscn\").instance()\n" +" var tooltip = preload(\"SomeTooltipScene.tscn\").instantiate()\n" " tooltip.get_node(\"Label\").text = for_text\n" " return tooltip\n" "[/codeblock]" @@ -34710,7 +34710,7 @@ msgid "" "[codeblock]\n" "# Use `load()` instead of `preload()` if the path isn't known at compile-" "time.\n" -"var scene = preload(\"res://scene.tscn\").instance()\n" +"var scene = preload(\"res://scene.tscn\").instantiate()\n" "# Add the node as a child of the node the script is attached to.\n" "add_child(scene)\n" "[/codeblock]\n" diff --git a/doc/translations/fr.po b/doc/translations/fr.po index 7717474c0f..2d9b1db565 100644 --- a/doc/translations/fr.po +++ b/doc/translations/fr.po @@ -1017,7 +1017,7 @@ msgid "" "the FileSystem dock into the script.\n" "[codeblock]\n" "# Instance a scene.\n" -"var diamond = preload(\"res://diamond.tscn\").instance()\n" +"var diamond = preload(\"res://diamond.tscn\").instantiate()\n" "[/codeblock]" msgstr "" @@ -14162,7 +14162,7 @@ msgid "" "Example of usage with custom scene instance:\n" "[codeblock]\n" "func _make_custom_tooltip(for_text):\n" -" var tooltip = preload(\"SomeTooltipScene.tscn\").instance()\n" +" var tooltip = preload(\"SomeTooltipScene.tscn\").instantiate()\n" " tooltip.get_node(\"Label\").text = for_text\n" " return tooltip\n" "[/codeblock]" @@ -35061,7 +35061,7 @@ msgid "" "[codeblock]\n" "# Use `load()` instead of `preload()` if the path isn't known at compile-" "time.\n" -"var scene = preload(\"res://scene.tscn\").instance()\n" +"var scene = preload(\"res://scene.tscn\").instantiate()\n" "# Add the node as a child of the node the script is attached to.\n" "add_child(scene)\n" "[/codeblock]\n" diff --git a/doc/translations/id.po b/doc/translations/id.po index edfd392f4f..cd841fc553 100644 --- a/doc/translations/id.po +++ b/doc/translations/id.po @@ -733,7 +733,7 @@ msgid "" "the FileSystem dock into the script.\n" "[codeblock]\n" "# Instance a scene.\n" -"var diamond = preload(\"res://diamond.tscn\").instance()\n" +"var diamond = preload(\"res://diamond.tscn\").instantiate()\n" "[/codeblock]" msgstr "" @@ -13857,7 +13857,7 @@ msgid "" "Example of usage with custom scene instance:\n" "[codeblock]\n" "func _make_custom_tooltip(for_text):\n" -" var tooltip = preload(\"SomeTooltipScene.tscn\").instance()\n" +" var tooltip = preload(\"SomeTooltipScene.tscn\").instantiate()\n" " tooltip.get_node(\"Label\").text = for_text\n" " return tooltip\n" "[/codeblock]" @@ -34723,7 +34723,7 @@ msgid "" "[codeblock]\n" "# Use `load()` instead of `preload()` if the path isn't known at compile-" "time.\n" -"var scene = preload(\"res://scene.tscn\").instance()\n" +"var scene = preload(\"res://scene.tscn\").instantiate()\n" "# Add the node as a child of the node the script is attached to.\n" "add_child(scene)\n" "[/codeblock]\n" diff --git a/doc/translations/it.po b/doc/translations/it.po index 353eae4116..aa085f6158 100644 --- a/doc/translations/it.po +++ b/doc/translations/it.po @@ -985,7 +985,7 @@ msgid "" "the FileSystem dock into the script.\n" "[codeblock]\n" "# Instance a scene.\n" -"var diamond = preload(\"res://diamond.tscn\").instance()\n" +"var diamond = preload(\"res://diamond.tscn\").instantiate()\n" "[/codeblock]" msgstr "" @@ -14115,7 +14115,7 @@ msgid "" "Example of usage with custom scene instance:\n" "[codeblock]\n" "func _make_custom_tooltip(for_text):\n" -" var tooltip = preload(\"SomeTooltipScene.tscn\").instance()\n" +" var tooltip = preload(\"SomeTooltipScene.tscn\").instantiate()\n" " tooltip.get_node(\"Label\").text = for_text\n" " return tooltip\n" "[/codeblock]" @@ -34990,7 +34990,7 @@ msgid "" "[codeblock]\n" "# Use `load()` instead of `preload()` if the path isn't known at compile-" "time.\n" -"var scene = preload(\"res://scene.tscn\").instance()\n" +"var scene = preload(\"res://scene.tscn\").instantiate()\n" "# Add the node as a child of the node the script is attached to.\n" "add_child(scene)\n" "[/codeblock]\n" diff --git a/doc/translations/ja.po b/doc/translations/ja.po index 1424b24153..ee900d58c2 100644 --- a/doc/translations/ja.po +++ b/doc/translations/ja.po @@ -1091,7 +1091,7 @@ msgid "" "the FileSystem dock into the script.\n" "[codeblock]\n" "# Instance a scene.\n" -"var diamond = preload(\"res://diamond.tscn\").instance()\n" +"var diamond = preload(\"res://diamond.tscn\").instantiate()\n" "[/codeblock]" msgstr "" @@ -15045,7 +15045,7 @@ msgid "" "Example of usage with custom scene instance:\n" "[codeblock]\n" "func _make_custom_tooltip(for_text):\n" -" var tooltip = preload(\"SomeTooltipScene.tscn\").instance()\n" +" var tooltip = preload(\"SomeTooltipScene.tscn\").instantiate()\n" " tooltip.get_node(\"Label\").text = for_text\n" " return tooltip\n" "[/codeblock]" @@ -35964,7 +35964,7 @@ msgid "" "[codeblock]\n" "# Use `load()` instead of `preload()` if the path isn't known at compile-" "time.\n" -"var scene = preload(\"res://scene.tscn\").instance()\n" +"var scene = preload(\"res://scene.tscn\").instantiate()\n" "# Add the node as a child of the node the script is attached to.\n" "add_child(scene)\n" "[/codeblock]\n" diff --git a/doc/translations/ko.po b/doc/translations/ko.po index 8e8aef2eaf..60416fb63c 100644 --- a/doc/translations/ko.po +++ b/doc/translations/ko.po @@ -709,7 +709,7 @@ msgid "" "the FileSystem dock into the script.\n" "[codeblock]\n" "# Instance a scene.\n" -"var diamond = preload(\"res://diamond.tscn\").instance()\n" +"var diamond = preload(\"res://diamond.tscn\").instantiate()\n" "[/codeblock]" msgstr "" @@ -13833,7 +13833,7 @@ msgid "" "Example of usage with custom scene instance:\n" "[codeblock]\n" "func _make_custom_tooltip(for_text):\n" -" var tooltip = preload(\"SomeTooltipScene.tscn\").instance()\n" +" var tooltip = preload(\"SomeTooltipScene.tscn\").instantiate()\n" " tooltip.get_node(\"Label\").text = for_text\n" " return tooltip\n" "[/codeblock]" @@ -34699,7 +34699,7 @@ msgid "" "[codeblock]\n" "# Use `load()` instead of `preload()` if the path isn't known at compile-" "time.\n" -"var scene = preload(\"res://scene.tscn\").instance()\n" +"var scene = preload(\"res://scene.tscn\").instantiate()\n" "# Add the node as a child of the node the script is attached to.\n" "add_child(scene)\n" "[/codeblock]\n" diff --git a/doc/translations/nl.po b/doc/translations/nl.po index 096e59f497..c0dc01c653 100644 --- a/doc/translations/nl.po +++ b/doc/translations/nl.po @@ -735,7 +735,7 @@ msgid "" "the FileSystem dock into the script.\n" "[codeblock]\n" "# Instance a scene.\n" -"var diamond = preload(\"res://diamond.tscn\").instance()\n" +"var diamond = preload(\"res://diamond.tscn\").instantiate()\n" "[/codeblock]" msgstr "" @@ -13859,7 +13859,7 @@ msgid "" "Example of usage with custom scene instance:\n" "[codeblock]\n" "func _make_custom_tooltip(for_text):\n" -" var tooltip = preload(\"SomeTooltipScene.tscn\").instance()\n" +" var tooltip = preload(\"SomeTooltipScene.tscn\").instantiate()\n" " tooltip.get_node(\"Label\").text = for_text\n" " return tooltip\n" "[/codeblock]" @@ -34725,7 +34725,7 @@ msgid "" "[codeblock]\n" "# Use `load()` instead of `preload()` if the path isn't known at compile-" "time.\n" -"var scene = preload(\"res://scene.tscn\").instance()\n" +"var scene = preload(\"res://scene.tscn\").instantiate()\n" "# Add the node as a child of the node the script is attached to.\n" "add_child(scene)\n" "[/codeblock]\n" diff --git a/doc/translations/pl.po b/doc/translations/pl.po index 5ef41b155a..2664f263cb 100644 --- a/doc/translations/pl.po +++ b/doc/translations/pl.po @@ -737,7 +737,7 @@ msgid "" "the FileSystem dock into the script.\n" "[codeblock]\n" "# Instance a scene.\n" -"var diamond = preload(\"res://diamond.tscn\").instance()\n" +"var diamond = preload(\"res://diamond.tscn\").instantiate()\n" "[/codeblock]" msgstr "" @@ -13877,7 +13877,7 @@ msgid "" "Example of usage with custom scene instance:\n" "[codeblock]\n" "func _make_custom_tooltip(for_text):\n" -" var tooltip = preload(\"SomeTooltipScene.tscn\").instance()\n" +" var tooltip = preload(\"SomeTooltipScene.tscn\").instantiate()\n" " tooltip.get_node(\"Label\").text = for_text\n" " return tooltip\n" "[/codeblock]" @@ -34744,7 +34744,7 @@ msgid "" "[codeblock]\n" "# Use `load()` instead of `preload()` if the path isn't known at compile-" "time.\n" -"var scene = preload(\"res://scene.tscn\").instance()\n" +"var scene = preload(\"res://scene.tscn\").instantiate()\n" "# Add the node as a child of the node the script is attached to.\n" "add_child(scene)\n" "[/codeblock]\n" diff --git a/doc/translations/pt_BR.po b/doc/translations/pt_BR.po index ef62950d51..f86bed9585 100644 --- a/doc/translations/pt_BR.po +++ b/doc/translations/pt_BR.po @@ -748,7 +748,7 @@ msgid "" "the FileSystem dock into the script.\n" "[codeblock]\n" "# Instance a scene.\n" -"var diamond = preload(\"res://diamond.tscn\").instance()\n" +"var diamond = preload(\"res://diamond.tscn\").instantiate()\n" "[/codeblock]" msgstr "" @@ -13872,7 +13872,7 @@ msgid "" "Example of usage with custom scene instance:\n" "[codeblock]\n" "func _make_custom_tooltip(for_text):\n" -" var tooltip = preload(\"SomeTooltipScene.tscn\").instance()\n" +" var tooltip = preload(\"SomeTooltipScene.tscn\").instantiate()\n" " tooltip.get_node(\"Label\").text = for_text\n" " return tooltip\n" "[/codeblock]" @@ -34738,7 +34738,7 @@ msgid "" "[codeblock]\n" "# Use `load()` instead of `preload()` if the path isn't known at compile-" "time.\n" -"var scene = preload(\"res://scene.tscn\").instance()\n" +"var scene = preload(\"res://scene.tscn\").instantiate()\n" "# Add the node as a child of the node the script is attached to.\n" "add_child(scene)\n" "[/codeblock]\n" diff --git a/doc/translations/ro.po b/doc/translations/ro.po index 5f018aa497..b25c3911cc 100644 --- a/doc/translations/ro.po +++ b/doc/translations/ro.po @@ -709,7 +709,7 @@ msgid "" "the FileSystem dock into the script.\n" "[codeblock]\n" "# Instance a scene.\n" -"var diamond = preload(\"res://diamond.tscn\").instance()\n" +"var diamond = preload(\"res://diamond.tscn\").instantiate()\n" "[/codeblock]" msgstr "" @@ -13833,7 +13833,7 @@ msgid "" "Example of usage with custom scene instance:\n" "[codeblock]\n" "func _make_custom_tooltip(for_text):\n" -" var tooltip = preload(\"SomeTooltipScene.tscn\").instance()\n" +" var tooltip = preload(\"SomeTooltipScene.tscn\").instantiate()\n" " tooltip.get_node(\"Label\").text = for_text\n" " return tooltip\n" "[/codeblock]" @@ -34699,7 +34699,7 @@ msgid "" "[codeblock]\n" "# Use `load()` instead of `preload()` if the path isn't known at compile-" "time.\n" -"var scene = preload(\"res://scene.tscn\").instance()\n" +"var scene = preload(\"res://scene.tscn\").instantiate()\n" "# Add the node as a child of the node the script is attached to.\n" "add_child(scene)\n" "[/codeblock]\n" diff --git a/doc/translations/ru.po b/doc/translations/ru.po index 0d227beff7..cf5289d7f9 100644 --- a/doc/translations/ru.po +++ b/doc/translations/ru.po @@ -1072,7 +1072,7 @@ msgid "" "the FileSystem dock into the script.\n" "[codeblock]\n" "# Instance a scene.\n" -"var diamond = preload(\"res://diamond.tscn\").instance()\n" +"var diamond = preload(\"res://diamond.tscn\").instantiate()\n" "[/codeblock]" msgstr "" @@ -14338,7 +14338,7 @@ msgid "" "Example of usage with custom scene instance:\n" "[codeblock]\n" "func _make_custom_tooltip(for_text):\n" -" var tooltip = preload(\"SomeTooltipScene.tscn\").instance()\n" +" var tooltip = preload(\"SomeTooltipScene.tscn\").instantiate()\n" " tooltip.get_node(\"Label\").text = for_text\n" " return tooltip\n" "[/codeblock]" @@ -35238,7 +35238,7 @@ msgid "" "[codeblock]\n" "# Use `load()` instead of `preload()` if the path isn't known at compile-" "time.\n" -"var scene = preload(\"res://scene.tscn\").instance()\n" +"var scene = preload(\"res://scene.tscn\").instantiate()\n" "# Add the node as a child of the node the script is attached to.\n" "add_child(scene)\n" "[/codeblock]\n" diff --git a/doc/translations/sr_Cyrl.po b/doc/translations/sr_Cyrl.po index d53711d996..06399d5e87 100644 --- a/doc/translations/sr_Cyrl.po +++ b/doc/translations/sr_Cyrl.po @@ -719,7 +719,7 @@ msgid "" "the FileSystem dock into the script.\n" "[codeblock]\n" "# Instance a scene.\n" -"var diamond = preload(\"res://diamond.tscn\").instance()\n" +"var diamond = preload(\"res://diamond.tscn\").instantiate()\n" "[/codeblock]" msgstr "" @@ -13843,7 +13843,7 @@ msgid "" "Example of usage with custom scene instance:\n" "[codeblock]\n" "func _make_custom_tooltip(for_text):\n" -" var tooltip = preload(\"SomeTooltipScene.tscn\").instance()\n" +" var tooltip = preload(\"SomeTooltipScene.tscn\").instantiate()\n" " tooltip.get_node(\"Label\").text = for_text\n" " return tooltip\n" "[/codeblock]" @@ -34709,7 +34709,7 @@ msgid "" "[codeblock]\n" "# Use `load()` instead of `preload()` if the path isn't known at compile-" "time.\n" -"var scene = preload(\"res://scene.tscn\").instance()\n" +"var scene = preload(\"res://scene.tscn\").instantiate()\n" "# Add the node as a child of the node the script is attached to.\n" "add_child(scene)\n" "[/codeblock]\n" diff --git a/doc/translations/th.po b/doc/translations/th.po index 7686e22f19..cdf1c6d7e2 100644 --- a/doc/translations/th.po +++ b/doc/translations/th.po @@ -725,7 +725,7 @@ msgid "" "the FileSystem dock into the script.\n" "[codeblock]\n" "# Instance a scene.\n" -"var diamond = preload(\"res://diamond.tscn\").instance()\n" +"var diamond = preload(\"res://diamond.tscn\").instantiate()\n" "[/codeblock]" msgstr "" @@ -13849,7 +13849,7 @@ msgid "" "Example of usage with custom scene instance:\n" "[codeblock]\n" "func _make_custom_tooltip(for_text):\n" -" var tooltip = preload(\"SomeTooltipScene.tscn\").instance()\n" +" var tooltip = preload(\"SomeTooltipScene.tscn\").instantiate()\n" " tooltip.get_node(\"Label\").text = for_text\n" " return tooltip\n" "[/codeblock]" @@ -34715,7 +34715,7 @@ msgid "" "[codeblock]\n" "# Use `load()` instead of `preload()` if the path isn't known at compile-" "time.\n" -"var scene = preload(\"res://scene.tscn\").instance()\n" +"var scene = preload(\"res://scene.tscn\").instantiate()\n" "# Add the node as a child of the node the script is attached to.\n" "add_child(scene)\n" "[/codeblock]\n" diff --git a/doc/translations/tr.po b/doc/translations/tr.po index df9897f1d6..646a3fb5b3 100644 --- a/doc/translations/tr.po +++ b/doc/translations/tr.po @@ -701,7 +701,7 @@ msgid "" "the FileSystem dock into the script.\n" "[codeblock]\n" "# Instance a scene.\n" -"var diamond = preload(\"res://diamond.tscn\").instance()\n" +"var diamond = preload(\"res://diamond.tscn\").instantiate()\n" "[/codeblock]" msgstr "" @@ -13825,7 +13825,7 @@ msgid "" "Example of usage with custom scene instance:\n" "[codeblock]\n" "func _make_custom_tooltip(for_text):\n" -" var tooltip = preload(\"SomeTooltipScene.tscn\").instance()\n" +" var tooltip = preload(\"SomeTooltipScene.tscn\").instantiate()\n" " tooltip.get_node(\"Label\").text = for_text\n" " return tooltip\n" "[/codeblock]" @@ -34691,7 +34691,7 @@ msgid "" "[codeblock]\n" "# Use `load()` instead of `preload()` if the path isn't known at compile-" "time.\n" -"var scene = preload(\"res://scene.tscn\").instance()\n" +"var scene = preload(\"res://scene.tscn\").instantiate()\n" "# Add the node as a child of the node the script is attached to.\n" "add_child(scene)\n" "[/codeblock]\n" diff --git a/doc/translations/uk.po b/doc/translations/uk.po index d1296da87a..c2232d81ab 100644 --- a/doc/translations/uk.po +++ b/doc/translations/uk.po @@ -787,7 +787,7 @@ msgid "" "the FileSystem dock into the script.\n" "[codeblock]\n" "# Instance a scene.\n" -"var diamond = preload(\"res://diamond.tscn\").instance()\n" +"var diamond = preload(\"res://diamond.tscn\").instantiate()\n" "[/codeblock]" msgstr "" @@ -13911,7 +13911,7 @@ msgid "" "Example of usage with custom scene instance:\n" "[codeblock]\n" "func _make_custom_tooltip(for_text):\n" -" var tooltip = preload(\"SomeTooltipScene.tscn\").instance()\n" +" var tooltip = preload(\"SomeTooltipScene.tscn\").instantiate()\n" " tooltip.get_node(\"Label\").text = for_text\n" " return tooltip\n" "[/codeblock]" @@ -34777,7 +34777,7 @@ msgid "" "[codeblock]\n" "# Use `load()` instead of `preload()` if the path isn't known at compile-" "time.\n" -"var scene = preload(\"res://scene.tscn\").instance()\n" +"var scene = preload(\"res://scene.tscn\").instantiate()\n" "# Add the node as a child of the node the script is attached to.\n" "add_child(scene)\n" "[/codeblock]\n" diff --git a/doc/translations/zh_Hans.po b/doc/translations/zh_Hans.po index edfb11dec1..40d1eb68bc 100644 --- a/doc/translations/zh_Hans.po +++ b/doc/translations/zh_Hans.po @@ -934,7 +934,7 @@ msgid "" "the FileSystem dock into the script.\n" "[codeblock]\n" "# Instance a scene.\n" -"var diamond = preload(\"res://diamond.tscn\").instance()\n" +"var diamond = preload(\"res://diamond.tscn\").instantiate()\n" "[/codeblock]" msgstr "" @@ -14058,7 +14058,7 @@ msgid "" "Example of usage with custom scene instance:\n" "[codeblock]\n" "func _make_custom_tooltip(for_text):\n" -" var tooltip = preload(\"SomeTooltipScene.tscn\").instance()\n" +" var tooltip = preload(\"SomeTooltipScene.tscn\").instantiate()\n" " tooltip.get_node(\"Label\").text = for_text\n" " return tooltip\n" "[/codeblock]" @@ -34928,7 +34928,7 @@ msgid "" "[codeblock]\n" "# Use `load()` instead of `preload()` if the path isn't known at compile-" "time.\n" -"var scene = preload(\"res://scene.tscn\").instance()\n" +"var scene = preload(\"res://scene.tscn\").instantiate()\n" "# Add the node as a child of the node the script is attached to.\n" "add_child(scene)\n" "[/codeblock]\n" diff --git a/doc/translations/zh_Hant.po b/doc/translations/zh_Hant.po index 3afec7ead8..13515dff67 100644 --- a/doc/translations/zh_Hant.po +++ b/doc/translations/zh_Hant.po @@ -738,7 +738,7 @@ msgid "" "the FileSystem dock into the script.\n" "[codeblock]\n" "# Instance a scene.\n" -"var diamond = preload(\"res://diamond.tscn\").instance()\n" +"var diamond = preload(\"res://diamond.tscn\").instantiate()\n" "[/codeblock]" msgstr "" @@ -13862,7 +13862,7 @@ msgid "" "Example of usage with custom scene instance:\n" "[codeblock]\n" "func _make_custom_tooltip(for_text):\n" -" var tooltip = preload(\"SomeTooltipScene.tscn\").instance()\n" +" var tooltip = preload(\"SomeTooltipScene.tscn\").instantiate()\n" " tooltip.get_node(\"Label\").text = for_text\n" " return tooltip\n" "[/codeblock]" @@ -34728,7 +34728,7 @@ msgid "" "[codeblock]\n" "# Use `load()` instead of `preload()` if the path isn't known at compile-" "time.\n" -"var scene = preload(\"res://scene.tscn\").instance()\n" +"var scene = preload(\"res://scene.tscn\").instantiate()\n" "# Add the node as a child of the node the script is attached to.\n" "add_child(scene)\n" "[/codeblock]\n" diff --git a/drivers/png/image_loader_png.cpp b/drivers/png/image_loader_png.cpp index 8cc76b01e1..f7f7f2dd22 100644 --- a/drivers/png/image_loader_png.cpp +++ b/drivers/png/image_loader_png.cpp @@ -59,7 +59,7 @@ void ImageLoaderPNG::get_recognized_extensions(List<String> *p_extensions) const Ref<Image> ImageLoaderPNG::load_mem_png(const uint8_t *p_png, int p_size) { Ref<Image> img; - img.instance(); + img.instantiate(); // the value of p_force_linear does not matter since it only applies to 16 bit Error err = PNGDriverCommon::png_to_image(p_png, p_size, false, img); diff --git a/drivers/register_driver_types.cpp b/drivers/register_driver_types.cpp index 18262c74c4..83702ea2cc 100644 --- a/drivers/register_driver_types.cpp +++ b/drivers/register_driver_types.cpp @@ -40,7 +40,7 @@ void register_core_driver_types() { image_loader_png = memnew(ImageLoaderPNG); ImageLoader::add_image_format_loader(image_loader_png); - resource_saver_png.instance(); + resource_saver_png.instantiate(); ResourceSaver::add_resource_format_saver(resource_saver_png); } diff --git a/drivers/unix/ip_unix.cpp b/drivers/unix/ip_unix.cpp index e8f8ae4717..8a880ab9c8 100644 --- a/drivers/unix/ip_unix.cpp +++ b/drivers/unix/ip_unix.cpp @@ -41,19 +41,7 @@ #include <windows.h> #include <ws2tcpip.h> #ifndef UWP_ENABLED -#if defined(__MINGW32__) && (!defined(__MINGW64_VERSION_MAJOR) || __MINGW64_VERSION_MAJOR < 4) -// MinGW-w64 on Ubuntu 12.04 (our Travis build env) has bugs in this code where -// some includes are missing in dependencies of iphlpapi.h for WINVER >= 0x0600 (Vista). -// We don't use this Vista code for now, so working it around by disabling it. -// MinGW-w64 >= 4.0 seems to be better judging by its headers. -#undef _WIN32_WINNT -#define _WIN32_WINNT 0x0501 // Windows XP, disable Vista API #include <iphlpapi.h> -#undef _WIN32_WINNT -#define _WIN32_WINNT 0x0600 // Re-enable Vista API -#else -#include <iphlpapi.h> -#endif // MINGW hack #endif #else // UNIX #include <netdb.h> diff --git a/drivers/vulkan/rendering_device_vulkan.cpp b/drivers/vulkan/rendering_device_vulkan.cpp index c69b516f37..d3d49503d8 100644 --- a/drivers/vulkan/rendering_device_vulkan.cpp +++ b/drivers/vulkan/rendering_device_vulkan.cpp @@ -1398,12 +1398,15 @@ Error RenderingDeviceVulkan::_buffer_allocate(Buffer *p_buffer, uint32_t p_size, p_buffer->buffer_info.range = p_size; p_buffer->usage = p_usage; + buffer_memory += p_size; + return OK; } Error RenderingDeviceVulkan::_buffer_free(Buffer *p_buffer) { ERR_FAIL_COND_V(p_buffer->size == 0, ERR_INVALID_PARAMETER); + buffer_memory -= p_buffer->size; vmaDestroyBuffer(allocator, p_buffer->buffer, p_buffer->allocation); p_buffer->buffer = VK_NULL_HANDLE; p_buffer->allocation = nullptr; @@ -1896,7 +1899,7 @@ RID RenderingDeviceVulkan::texture_create(const TextureFormat &p_format, const T VkResult err = vmaCreateImage(allocator, &image_create_info, &allocInfo, &texture.image, &texture.allocation, &texture.allocation_info); ERR_FAIL_COND_V_MSG(err, RID(), "vmaCreateImage failed with error " + itos(err) + "."); - + image_memory += texture.allocation_info.size; texture.type = p_format.texture_type; texture.format = p_format.format; texture.width = image_create_info.extent.width; @@ -2029,7 +2032,7 @@ RID RenderingDeviceVulkan::texture_create(const TextureFormat &p_format, const T if (p_data.size()) { for (uint32_t i = 0; i < image_create_info.arrayLayers; i++) { - texture_update(id, i, p_data[i]); + _texture_update(id, i, p_data[i], RD::BARRIER_MASK_ALL, true); } } return id; @@ -2276,10 +2279,14 @@ RID RenderingDeviceVulkan::texture_create_shared_from_slice(const TextureView &p } Error RenderingDeviceVulkan::texture_update(RID p_texture, uint32_t p_layer, const Vector<uint8_t> &p_data, uint32_t p_post_barrier) { + return _texture_update(p_texture, p_layer, p_data, p_post_barrier, false); +} + +Error RenderingDeviceVulkan::_texture_update(RID p_texture, uint32_t p_layer, const Vector<uint8_t> &p_data, uint32_t p_post_barrier, bool p_use_setup_queue) { _THREAD_SAFE_METHOD_ - ERR_FAIL_COND_V_MSG(draw_list || compute_list, ERR_INVALID_PARAMETER, - "Updating textures in is forbidden during creation of a draw or compute list"); + ERR_FAIL_COND_V_MSG((draw_list || compute_list) && !p_use_setup_queue, ERR_INVALID_PARAMETER, + "Updating textures is forbidden during creation of a draw or compute list"); Texture *texture = texture_owner.getornull(p_texture); ERR_FAIL_COND_V(!texture, ERR_INVALID_PARAMETER); @@ -2320,7 +2327,7 @@ Error RenderingDeviceVulkan::texture_update(RID p_texture, uint32_t p_layer, con const uint8_t *r = p_data.ptr(); - VkCommandBuffer command_buffer = p_post_barrier ? frames[frame].draw_command_buffer : frames[frame].setup_command_buffer; + VkCommandBuffer command_buffer = p_use_setup_queue ? frames[frame].setup_command_buffer : frames[frame].draw_command_buffer; //barrier to transfer { @@ -2373,7 +2380,7 @@ Error RenderingDeviceVulkan::texture_update(RID p_texture, uint32_t p_layer, con to_allocate >>= get_compressed_image_format_pixel_rshift(texture->format); uint32_t alloc_offset, alloc_size; - Error err = _staging_buffer_allocate(to_allocate, required_align, alloc_offset, alloc_size, false, p_post_barrier); + Error err = _staging_buffer_allocate(to_allocate, required_align, alloc_offset, alloc_size, false, !p_use_setup_queue); ERR_FAIL_COND_V(err, ERR_CANT_CREATE); uint8_t *write_ptr; @@ -3244,12 +3251,7 @@ bool RenderingDeviceVulkan::texture_is_format_supported_for_usage(DataFormat p_f /**** ATTACHMENT ****/ /********************/ -VkRenderPass RenderingDeviceVulkan::_render_pass_create(const Vector<AttachmentFormat> &p_format, InitialAction p_initial_color_action, FinalAction p_final_color_action, InitialAction p_initial_depth_action, FinalAction p_final_depth_action, int *r_color_attachment_count, uint32_t p_view_count) { - Vector<VkAttachmentDescription> attachments; - Vector<VkAttachmentReference> color_references; - Vector<VkAttachmentReference> depth_stencil_references; - Vector<VkAttachmentReference> resolve_references; - +VkRenderPass RenderingDeviceVulkan::_render_pass_create(const Vector<AttachmentFormat> &p_attachments, const Vector<FramebufferPass> &p_passes, InitialAction p_initial_action, FinalAction p_final_action, InitialAction p_initial_depth_action, FinalAction p_final_depth_action, uint32_t p_view_count, Vector<TextureSamples> *r_samples) { // Set up dependencies from/to external equivalent to the default (implicit) one, and then amend them const VkPipelineStageFlags default_access_mask = VK_ACCESS_INPUT_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | @@ -3262,27 +3264,31 @@ VkRenderPass RenderingDeviceVulkan::_render_pass_create(const Vector<AttachmentF { 0, VK_SUBPASS_EXTERNAL, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, default_access_mask, 0, 0 } }; VkSubpassDependency &dependency_from_external = dependencies[0]; VkSubpassDependency &dependency_to_external = dependencies[1]; + LocalVector<int32_t> attachment_last_pass; + attachment_last_pass.resize(p_attachments.size()); - for (int i = 0; i < p_format.size(); i++) { - ERR_FAIL_INDEX_V(p_format[i].format, DATA_FORMAT_MAX, VK_NULL_HANDLE); - ERR_FAIL_INDEX_V(p_format[i].samples, TEXTURE_SAMPLES_MAX, VK_NULL_HANDLE); - ERR_FAIL_COND_V_MSG(!(p_format[i].usage_flags & (TEXTURE_USAGE_COLOR_ATTACHMENT_BIT | TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | TEXTURE_USAGE_RESOLVE_ATTACHMENT_BIT)), + Vector<VkAttachmentDescription> attachments; + + for (int i = 0; i < p_attachments.size(); i++) { + ERR_FAIL_INDEX_V(p_attachments[i].format, DATA_FORMAT_MAX, VK_NULL_HANDLE); + ERR_FAIL_INDEX_V(p_attachments[i].samples, TEXTURE_SAMPLES_MAX, VK_NULL_HANDLE); + ERR_FAIL_COND_V_MSG(!(p_attachments[i].usage_flags & (TEXTURE_USAGE_COLOR_ATTACHMENT_BIT | TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | TEXTURE_USAGE_RESOLVE_ATTACHMENT_BIT)), VK_NULL_HANDLE, "Texture format for index (" + itos(i) + ") requires an attachment (depth, stencil or resolve) bit set."); VkAttachmentDescription description = {}; description.flags = 0; - description.format = vulkan_formats[p_format[i].format]; - description.samples = rasterization_sample_count[p_format[i].samples]; + description.format = vulkan_formats[p_attachments[i].format]; + description.samples = rasterization_sample_count[p_attachments[i].samples]; - bool is_depth_stencil = p_format[i].usage_flags & TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; - bool is_sampled = p_format[i].usage_flags & TEXTURE_USAGE_SAMPLING_BIT; - bool is_storage = p_format[i].usage_flags & TEXTURE_USAGE_STORAGE_BIT; + bool is_sampled = p_attachments[i].usage_flags & TEXTURE_USAGE_SAMPLING_BIT; + bool is_storage = p_attachments[i].usage_flags & TEXTURE_USAGE_STORAGE_BIT; + bool is_depth = p_attachments[i].usage_flags & TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; // For each UNDEFINED, assume the prior use was a *read*, as we'd be discarding the output of a write // Also, each UNDEFINED will do an immediate layout transition (write), s.t. we must ensure execution synchronization vs. // the read. If this is a performance issue, one could track the actual last accessor of each resource, adding only that // stage - switch (is_depth_stencil ? p_initial_depth_action : p_initial_color_action) { + switch (is_depth ? p_initial_depth_action : p_initial_action) { case INITIAL_ACTION_CLEAR_REGION: case INITIAL_ACTION_CLEAR: { description.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; @@ -3291,11 +3297,11 @@ VkRenderPass RenderingDeviceVulkan::_render_pass_create(const Vector<AttachmentF dependency_from_external.srcStageMask |= reading_stages; } break; case INITIAL_ACTION_KEEP: { - if (p_format[i].usage_flags & TEXTURE_USAGE_COLOR_ATTACHMENT_BIT) { + if (p_attachments[i].usage_flags & TEXTURE_USAGE_COLOR_ATTACHMENT_BIT) { description.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD; description.initialLayout = is_sampled ? VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL : (is_storage ? VK_IMAGE_LAYOUT_GENERAL : VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); description.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; - } else if (p_format[i].usage_flags & TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) { + } else if (p_attachments[i].usage_flags & TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) { description.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD; description.initialLayout = is_sampled ? VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL : (is_storage ? VK_IMAGE_LAYOUT_GENERAL : VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); description.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_LOAD; @@ -3308,11 +3314,11 @@ VkRenderPass RenderingDeviceVulkan::_render_pass_create(const Vector<AttachmentF } } break; case INITIAL_ACTION_DROP: { - if (p_format[i].usage_flags & TEXTURE_USAGE_COLOR_ATTACHMENT_BIT) { + if (p_attachments[i].usage_flags & TEXTURE_USAGE_COLOR_ATTACHMENT_BIT) { description.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; description.initialLayout = is_sampled ? VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL : (is_storage ? VK_IMAGE_LAYOUT_GENERAL : VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); description.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; - } else if (p_format[i].usage_flags & TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) { + } else if (p_attachments[i].usage_flags & TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) { description.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; description.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; //don't care what is there description.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; @@ -3326,11 +3332,11 @@ VkRenderPass RenderingDeviceVulkan::_render_pass_create(const Vector<AttachmentF } break; case INITIAL_ACTION_CLEAR_REGION_CONTINUE: case INITIAL_ACTION_CONTINUE: { - if (p_format[i].usage_flags & TEXTURE_USAGE_COLOR_ATTACHMENT_BIT) { + if (p_attachments[i].usage_flags & TEXTURE_USAGE_COLOR_ATTACHMENT_BIT) { description.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD; description.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; description.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; - } else if (p_format[i].usage_flags & TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) { + } else if (p_attachments[i].usage_flags & TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) { description.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD; description.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; description.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_LOAD; @@ -3346,14 +3352,14 @@ VkRenderPass RenderingDeviceVulkan::_render_pass_create(const Vector<AttachmentF } } - switch (is_depth_stencil ? p_final_depth_action : p_final_color_action) { + switch (is_depth ? p_final_depth_action : p_final_action) { case FINAL_ACTION_READ: { - if (p_format[i].usage_flags & TEXTURE_USAGE_COLOR_ATTACHMENT_BIT) { + if (p_attachments[i].usage_flags & TEXTURE_USAGE_COLOR_ATTACHMENT_BIT) { description.storeOp = VK_ATTACHMENT_STORE_OP_STORE; description.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; description.finalLayout = is_sampled ? VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL : (is_storage ? VK_IMAGE_LAYOUT_GENERAL : VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); update_external_dependency_for_store(dependency_to_external, is_sampled, is_storage, false); - } else if (p_format[i].usage_flags & TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) { + } else if (p_attachments[i].usage_flags & TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) { description.storeOp = VK_ATTACHMENT_STORE_OP_STORE; description.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE; description.finalLayout = is_sampled ? VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL : (is_storage ? VK_IMAGE_LAYOUT_GENERAL : VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); @@ -3366,11 +3372,11 @@ VkRenderPass RenderingDeviceVulkan::_render_pass_create(const Vector<AttachmentF } } break; case FINAL_ACTION_DISCARD: { - if (p_format[i].usage_flags & TEXTURE_USAGE_COLOR_ATTACHMENT_BIT) { + if (p_attachments[i].usage_flags & TEXTURE_USAGE_COLOR_ATTACHMENT_BIT) { description.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; description.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; description.finalLayout = is_sampled ? VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL : (is_storage ? VK_IMAGE_LAYOUT_GENERAL : VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); - } else if (p_format[i].usage_flags & TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) { + } else if (p_attachments[i].usage_flags & TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) { description.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; description.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; description.finalLayout = is_sampled ? VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL : (is_storage ? VK_IMAGE_LAYOUT_GENERAL : VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); @@ -3381,11 +3387,11 @@ VkRenderPass RenderingDeviceVulkan::_render_pass_create(const Vector<AttachmentF } } break; case FINAL_ACTION_CONTINUE: { - if (p_format[i].usage_flags & TEXTURE_USAGE_COLOR_ATTACHMENT_BIT) { + if (p_attachments[i].usage_flags & TEXTURE_USAGE_COLOR_ATTACHMENT_BIT) { description.storeOp = VK_ATTACHMENT_STORE_OP_STORE; description.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; description.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; - } else if (p_format[i].usage_flags & TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) { + } else if (p_attachments[i].usage_flags & TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) { description.storeOp = VK_ATTACHMENT_STORE_OP_STORE; description.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE; description.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; @@ -3401,27 +3407,194 @@ VkRenderPass RenderingDeviceVulkan::_render_pass_create(const Vector<AttachmentF } } + attachment_last_pass[i] = -1; + attachments.push_back(description); + } + + LocalVector<VkSubpassDescription> subpasses; + LocalVector<LocalVector<VkAttachmentReference>> color_reference_array; + LocalVector<LocalVector<VkAttachmentReference>> input_reference_array; + LocalVector<LocalVector<VkAttachmentReference>> resolve_reference_array; + LocalVector<LocalVector<uint32_t>> preserve_reference_array; + LocalVector<VkAttachmentReference> depth_reference_array; + + subpasses.resize(p_passes.size()); + color_reference_array.resize(p_passes.size()); + input_reference_array.resize(p_passes.size()); + resolve_reference_array.resize(p_passes.size()); + preserve_reference_array.resize(p_passes.size()); + depth_reference_array.resize(p_passes.size()); + + LocalVector<VkSubpassDependency> subpass_dependencies; + + for (int i = 0; i < p_passes.size(); i++) { + const FramebufferPass *pass = &p_passes[i]; - VkAttachmentReference reference; - reference.attachment = i; + LocalVector<VkAttachmentReference> &color_references = color_reference_array[i]; - if (p_format[i].usage_flags & TEXTURE_USAGE_COLOR_ATTACHMENT_BIT) { - reference.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; + TextureSamples texture_samples = TEXTURE_SAMPLES_1; + bool is_multisample_first = true; + + for (int j = 0; j < pass->color_attachments.size(); j++) { + int32_t attachment = pass->color_attachments[j]; + VkAttachmentReference reference; + if (attachment == FramebufferPass::ATTACHMENT_UNUSED) { + reference.attachment = VK_ATTACHMENT_UNUSED; + reference.layout = VK_IMAGE_LAYOUT_UNDEFINED; + } else { + ERR_FAIL_INDEX_V_MSG(attachment, p_attachments.size(), VK_NULL_HANDLE, "Invalid framebuffer format attachment(" + itos(attachment) + "), in pass (" + itos(i) + "), color attachment (" + itos(j) + ")."); + ERR_FAIL_COND_V_MSG(!(p_attachments[attachment].usage_flags & TEXTURE_USAGE_COLOR_ATTACHMENT_BIT), VK_NULL_HANDLE, "Invalid framebuffer format attachment(" + itos(attachment) + "), in pass (" + itos(i) + "), it's marked as depth, but it's not usable as color attachment."); + ERR_FAIL_COND_V_MSG(attachment_last_pass[attachment] == i, VK_NULL_HANDLE, "Invalid framebuffer format attachment(" + itos(attachment) + "), in pass (" + itos(i) + "), it already was used for something else before in this pass."); + + if (is_multisample_first) { + texture_samples = p_attachments[attachment].samples; + is_multisample_first = false; + } else { + ERR_FAIL_COND_V_MSG(texture_samples != p_attachments[attachment].samples, VK_NULL_HANDLE, "Invalid framebuffer format attachment(" + itos(attachment) + "), in pass (" + itos(i) + "), if an attachment is marked as multisample, all of them should be multisample and use the same number of samples."); + } + reference.attachment = attachment; + reference.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; + attachment_last_pass[attachment] = i; + } color_references.push_back(reference); - } else if (p_format[i].usage_flags & TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) { - reference.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; - depth_stencil_references.push_back(reference); - } else if (p_format[i].usage_flags & TEXTURE_USAGE_RESOLVE_ATTACHMENT_BIT) { - reference.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; + } + + LocalVector<VkAttachmentReference> &input_references = input_reference_array[i]; + + for (int j = 0; j < pass->input_attachments.size(); j++) { + int32_t attachment = pass->input_attachments[j]; + VkAttachmentReference reference; + if (attachment == FramebufferPass::ATTACHMENT_UNUSED) { + reference.attachment = VK_ATTACHMENT_UNUSED; + reference.layout = VK_IMAGE_LAYOUT_UNDEFINED; + } else { + ERR_FAIL_INDEX_V_MSG(attachment, p_attachments.size(), VK_NULL_HANDLE, "Invalid framebuffer format attachment(" + itos(attachment) + "), in pass (" + itos(i) + "), input attachment (" + itos(j) + ")."); + ERR_FAIL_COND_V_MSG(!(p_attachments[attachment].usage_flags & TEXTURE_USAGE_COLOR_ATTACHMENT_BIT), VK_NULL_HANDLE, "Invalid framebuffer format attachment(" + itos(attachment) + "), in pass (" + itos(i) + "), it's marked as depth, but it's not usable as input attachment."); + ERR_FAIL_COND_V_MSG(attachment_last_pass[attachment] == i, VK_NULL_HANDLE, "Invalid framebuffer format attachment(" + itos(attachment) + "), in pass (" + itos(i) + "), it already was used for something else before in this pass."); + reference.attachment = attachment; + reference.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + attachment_last_pass[attachment] = i; + } + input_references.push_back(reference); + } + + LocalVector<VkAttachmentReference> &resolve_references = resolve_reference_array[i]; + + if (pass->resolve_attachments.size() > 0) { + ERR_FAIL_COND_V_MSG(pass->resolve_attachments.size() != pass->color_attachments.size(), VK_NULL_HANDLE, "The amount of resolve attachments (" + itos(pass->resolve_attachments.size()) + ") must match the number of color attachments (" + itos(pass->color_attachments.size()) + ")."); + ERR_FAIL_COND_V_MSG(texture_samples == TEXTURE_SAMPLES_1, VK_NULL_HANDLE, "Resolve attachments specified, but color attachments are not multisample."); + } + for (int j = 0; j < pass->resolve_attachments.size(); j++) { + int32_t attachment = pass->resolve_attachments[j]; + VkAttachmentReference reference; + if (attachment == FramebufferPass::ATTACHMENT_UNUSED) { + reference.attachment = VK_ATTACHMENT_UNUSED; + reference.layout = VK_IMAGE_LAYOUT_UNDEFINED; + } else { + ERR_FAIL_INDEX_V_MSG(attachment, p_attachments.size(), VK_NULL_HANDLE, "Invalid framebuffer format attachment(" + itos(attachment) + "), in pass (" + itos(i) + "), resolve attachment (" + itos(j) + ")."); + ERR_FAIL_COND_V_MSG(pass->color_attachments[j] == FramebufferPass::ATTACHMENT_UNUSED, VK_NULL_HANDLE, "Invalid framebuffer format attachment(" + itos(attachment) + "), in pass (" + itos(i) + "), resolve attachment (" + itos(j) + "), the respective color attachment is marked as unused."); + ERR_FAIL_COND_V_MSG(!(p_attachments[attachment].usage_flags & TEXTURE_USAGE_COLOR_ATTACHMENT_BIT), VK_NULL_HANDLE, "Invalid framebuffer format attachment(" + itos(attachment) + "), in pass (" + itos(i) + "), it's marked as depth, but it's not usable as resolve attachment."); + ERR_FAIL_COND_V_MSG(attachment_last_pass[attachment] == i, VK_NULL_HANDLE, "Invalid framebuffer format attachment(" + itos(attachment) + "), in pass (" + itos(i) + "), it already was used for something else before in this pass."); + bool multisample = p_attachments[attachment].samples > TEXTURE_SAMPLES_1; + ERR_FAIL_COND_V_MSG(multisample, VK_NULL_HANDLE, "Invalid framebuffer format attachment(" + itos(attachment) + "), in pass (" + itos(i) + "), resolve attachments can't be multisample."); + reference.attachment = attachment; + reference.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + attachment_last_pass[attachment] = i; + } resolve_references.push_back(reference); - // if resolves are done, we need to ensure the copy is safe - dependency_to_external.dstStageMask |= VK_PIPELINE_STAGE_TRANSFER_BIT; - dependency_to_external.dstAccessMask |= VK_ACCESS_TRANSFER_READ_BIT; + } + + LocalVector<uint32_t> &preserve_references = preserve_reference_array[i]; + + for (int j = 0; j < pass->preserve_attachments.size(); j++) { + int32_t attachment = pass->preserve_attachments[j]; + + ERR_FAIL_COND_V_MSG(attachment == FramebufferPass::ATTACHMENT_UNUSED, VK_NULL_HANDLE, "Invalid framebuffer format attachment(" + itos(attachment) + "), in pass (" + itos(i) + "), preserve attachment (" + itos(j) + "). Preserve attachments can't be unused."); + + ERR_FAIL_INDEX_V_MSG(attachment, p_attachments.size(), VK_NULL_HANDLE, "Invalid framebuffer format attachment(" + itos(attachment) + "), in pass (" + itos(i) + "), preserve attachment (" + itos(j) + ")."); + ERR_FAIL_COND_V_MSG(attachment_last_pass[attachment] == i, VK_NULL_HANDLE, "Invalid framebuffer format attachment(" + itos(attachment) + "), in pass (" + itos(i) + "), it already was used for something else before in this pass."); + + attachment_last_pass[attachment] = i; + + preserve_references.push_back(attachment); + } + + VkAttachmentReference &depth_stencil_reference = depth_reference_array[i]; + + if (pass->depth_attachment != FramebufferPass::ATTACHMENT_UNUSED) { + int32_t attachment = pass->depth_attachment; + ERR_FAIL_INDEX_V_MSG(attachment, p_attachments.size(), VK_NULL_HANDLE, "Invalid framebuffer depth format attachment(" + itos(attachment) + "), in pass (" + itos(i) + "), depth attachment."); + ERR_FAIL_COND_V_MSG(!(p_attachments[attachment].usage_flags & TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT), VK_NULL_HANDLE, "Invalid framebuffer depth format attachment(" + itos(attachment) + "), in pass (" + itos(i) + "), it's marked as depth, but it's not a depth attachment."); + ERR_FAIL_COND_V_MSG(attachment_last_pass[attachment] == i, VK_NULL_HANDLE, "Invalid framebuffer depth format attachment(" + itos(attachment) + "), in pass (" + itos(i) + "), it already was used for something else before in this pass."); + depth_stencil_reference.attachment = attachment; + depth_stencil_reference.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; + attachment_last_pass[attachment] = i; + + if (is_multisample_first) { + texture_samples = p_attachments[attachment].samples; + is_multisample_first = false; + } else { + ERR_FAIL_COND_V_MSG(texture_samples != p_attachments[attachment].samples, VK_NULL_HANDLE, "Invalid framebuffer depth format attachment(" + itos(attachment) + "), in pass (" + itos(i) + "), if an attachment is marked as multisample, all of them should be multisample and use the same number of samples including the depth."); + } + + } else { + depth_stencil_reference.attachment = VK_ATTACHMENT_UNUSED; + depth_stencil_reference.layout = VK_IMAGE_LAYOUT_UNDEFINED; + } + + VkSubpassDescription &subpass = subpasses[i]; + subpass.flags = 0; + subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; + subpass.inputAttachmentCount = input_references.size(); + if (input_references.size()) { + subpass.pInputAttachments = input_references.ptr(); + } else { + subpass.pInputAttachments = nullptr; + } + subpass.colorAttachmentCount = color_references.size(); + if (color_references.size()) { + subpass.pColorAttachments = color_references.ptr(); + } else { + subpass.pColorAttachments = nullptr; + } + if (depth_stencil_reference.attachment != VK_ATTACHMENT_UNUSED) { + subpass.pDepthStencilAttachment = &depth_stencil_reference; + } else { + subpass.pDepthStencilAttachment = nullptr; + } + + if (resolve_references.size()) { + subpass.pResolveAttachments = resolve_references.ptr(); + } else { + subpass.pResolveAttachments = nullptr; + } + + subpass.preserveAttachmentCount = preserve_references.size(); + if (preserve_references.size()) { + subpass.pPreserveAttachments = preserve_references.ptr(); } else { - ERR_FAIL_V_MSG(VK_NULL_HANDLE, "Texture index " + itos(i) + " is neither color, depth stencil or resolve so it can't be used as attachment."); + subpass.pPreserveAttachments = nullptr; } + if (r_samples) { + r_samples->push_back(texture_samples); + } + + if (i > 0) { + VkSubpassDependency dependency; + dependency.srcSubpass = i - 1; + dependency.dstSubpass = i; + dependency.srcStageMask = 0; + dependency.srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT; + dependency.dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT; + + dependency.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; + dependency.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT; + dependency.dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT; + subpass_dependencies.push_back(dependency); + } + /* // NOTE: Big Mallet Approach -- any layout transition causes a full barrier if (reference.layout != description.initialLayout) { // NOTE: this should be smarter based on the texture's knowledge of its previous role @@ -3433,41 +3606,28 @@ VkRenderPass RenderingDeviceVulkan::_render_pass_create(const Vector<AttachmentF dependency_to_external.dstStageMask |= VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; dependency_to_external.dstAccessMask |= VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT; } + */ } - ERR_FAIL_COND_V_MSG(depth_stencil_references.size() > 1, VK_NULL_HANDLE, - "Formats can only have one depth/stencil attachment, supplied (" + itos(depth_stencil_references.size()) + ")."); - - ERR_FAIL_COND_V_MSG(resolve_references.size() > 1, VK_NULL_HANDLE, - "Formats can only have one resolve attachment, supplied (" + itos(resolve_references.size()) + ")."); - - VkSubpassDescription subpass; - subpass.flags = 0; - subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; - subpass.inputAttachmentCount = 0; //unsupported for now - subpass.pInputAttachments = nullptr; - subpass.colorAttachmentCount = color_references.size(); - subpass.pColorAttachments = color_references.ptr(); - subpass.pDepthStencilAttachment = depth_stencil_references.ptr(); - subpass.pResolveAttachments = resolve_references.ptr(); - subpass.preserveAttachmentCount = 0; - subpass.pPreserveAttachments = nullptr; - VkRenderPassCreateInfo render_pass_create_info; render_pass_create_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; render_pass_create_info.pNext = nullptr; render_pass_create_info.flags = 0; render_pass_create_info.attachmentCount = attachments.size(); render_pass_create_info.pAttachments = attachments.ptr(); - render_pass_create_info.subpassCount = 1; - render_pass_create_info.pSubpasses = &subpass; + render_pass_create_info.subpassCount = subpasses.size(); + render_pass_create_info.pSubpasses = subpasses.ptr(); // Commenting this because it seems it just avoids raster and compute to work at the same time. // Other barriers seem to be protecting the render pass fine. // render_pass_create_info.dependencyCount = 2; // render_pass_create_info.pDependencies = dependencies; - render_pass_create_info.dependencyCount = 0; - render_pass_create_info.pDependencies = nullptr; + render_pass_create_info.dependencyCount = subpass_dependencies.size(); + if (subpass_dependencies.size()) { + render_pass_create_info.pDependencies = subpass_dependencies.ptr(); + } else { + render_pass_create_info.pDependencies = nullptr; + } const uint32_t view_mask = (1 << p_view_count) - 1; const uint32_t correlation_mask = (1 << p_view_count) - 1; @@ -3498,17 +3658,29 @@ VkRenderPass RenderingDeviceVulkan::_render_pass_create(const Vector<AttachmentF VkResult res = vkCreateRenderPass(device, &render_pass_create_info, nullptr, &render_pass); ERR_FAIL_COND_V_MSG(res, VK_NULL_HANDLE, "vkCreateRenderPass failed with error " + itos(res) + "."); - if (r_color_attachment_count) { - *r_color_attachment_count = color_references.size(); - } return render_pass; } RenderingDevice::FramebufferFormatID RenderingDeviceVulkan::framebuffer_format_create(const Vector<AttachmentFormat> &p_format, uint32_t p_view_count) { + FramebufferPass pass; + for (int i = 0; i < p_format.size(); i++) { + if (p_format[i].usage_flags & TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) { + pass.depth_attachment = i; + } else { + pass.color_attachments.push_back(i); + } + } + + Vector<FramebufferPass> passes; + passes.push_back(pass); + return framebuffer_format_create_multipass(p_format, passes, p_view_count); +} +RenderingDevice::FramebufferFormatID RenderingDeviceVulkan::framebuffer_format_create_multipass(const Vector<AttachmentFormat> &p_attachments, Vector<FramebufferPass> &p_passes, uint32_t p_view_count) { _THREAD_SAFE_METHOD_ FramebufferFormatKey key; - key.attachments = p_format; + key.attachments = p_attachments; + key.passes = p_passes; key.view_count = p_view_count; const Map<FramebufferFormatKey, FramebufferFormatID>::Element *E = framebuffer_format_cache.find(key); @@ -3517,8 +3689,8 @@ RenderingDevice::FramebufferFormatID RenderingDeviceVulkan::framebuffer_format_c return E->get(); } - int color_references; - VkRenderPass render_pass = _render_pass_create(p_format, INITIAL_ACTION_CLEAR, FINAL_ACTION_READ, INITIAL_ACTION_CLEAR, FINAL_ACTION_READ, &color_references, p_view_count); //actions don't matter for this use case + Vector<TextureSamples> samples; + VkRenderPass render_pass = _render_pass_create(p_attachments, p_passes, INITIAL_ACTION_CLEAR, FINAL_ACTION_READ, INITIAL_ACTION_CLEAR, FINAL_ACTION_READ, p_view_count, &samples); //actions don't matter for this use case if (render_pass == VK_NULL_HANDLE) { //was likely invalid return INVALID_ID; @@ -3528,9 +3700,8 @@ RenderingDevice::FramebufferFormatID RenderingDeviceVulkan::framebuffer_format_c E = framebuffer_format_cache.insert(key, id); FramebufferFormat fb_format; fb_format.E = E; - fb_format.color_attachments = color_references; fb_format.render_pass = render_pass; - fb_format.samples = p_format[0].samples; + fb_format.pass_samples = samples; fb_format.view_count = p_view_count; framebuffer_formats[id] = fb_format; return id; @@ -3538,6 +3709,7 @@ RenderingDevice::FramebufferFormatID RenderingDeviceVulkan::framebuffer_format_c RenderingDevice::FramebufferFormatID RenderingDeviceVulkan::framebuffer_format_create_empty(TextureSamples p_samples) { FramebufferFormatKey key; + key.passes.push_back(FramebufferPass()); const Map<FramebufferFormatKey, FramebufferFormatID>::Element *E = framebuffer_format_cache.find(key); if (E) { @@ -3583,18 +3755,18 @@ RenderingDevice::FramebufferFormatID RenderingDeviceVulkan::framebuffer_format_c FramebufferFormat fb_format; fb_format.E = E; - fb_format.color_attachments = 0; fb_format.render_pass = render_pass; - fb_format.samples = p_samples; + fb_format.pass_samples.push_back(p_samples); framebuffer_formats[id] = fb_format; return id; } -RenderingDevice::TextureSamples RenderingDeviceVulkan::framebuffer_format_get_texture_samples(FramebufferFormatID p_format) { +RenderingDevice::TextureSamples RenderingDeviceVulkan::framebuffer_format_get_texture_samples(FramebufferFormatID p_format, uint32_t p_pass) { Map<FramebufferFormatID, FramebufferFormat>::Element *E = framebuffer_formats.find(p_format); ERR_FAIL_COND_V(!E, TEXTURE_SAMPLES_1); + ERR_FAIL_COND_V(p_pass >= uint32_t(E->get().pass_samples.size()), TEXTURE_SAMPLES_1); - return E->get().samples; + return E->get().pass_samples[p_pass]; } /***********************/ @@ -3615,6 +3787,30 @@ RID RenderingDeviceVulkan::framebuffer_create_empty(const Size2i &p_size, Textur RID RenderingDeviceVulkan::framebuffer_create(const Vector<RID> &p_texture_attachments, FramebufferFormatID p_format_check, uint32_t p_view_count) { _THREAD_SAFE_METHOD_ + FramebufferPass pass; + + for (int i = 0; i < p_texture_attachments.size(); i++) { + Texture *texture = texture_owner.getornull(p_texture_attachments[i]); + ERR_FAIL_COND_V_MSG(!texture, RID(), "Texture index supplied for framebuffer (" + itos(i) + ") is not a valid texture."); + + ERR_FAIL_COND_V_MSG(texture->layers != p_view_count, RID(), "Layers of our texture doesn't match view count for this framebuffer"); + + if (texture->usage_flags & TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) { + pass.depth_attachment = i; + } else { + pass.color_attachments.push_back(i); + } + } + + Vector<FramebufferPass> passes; + passes.push_back(pass); + + return framebuffer_create_multipass(p_texture_attachments, passes, p_format_check, p_view_count); +} + +RID RenderingDeviceVulkan::framebuffer_create_multipass(const Vector<RID> &p_texture_attachments, Vector<FramebufferPass> &p_passes, FramebufferFormatID p_format_check, uint32_t p_view_count) { + _THREAD_SAFE_METHOD_ + Vector<AttachmentFormat> attachments; Size2i size; @@ -3639,7 +3835,7 @@ RID RenderingDeviceVulkan::framebuffer_create(const Vector<RID> &p_texture_attac attachments.push_back(af); } - FramebufferFormatID format_id = framebuffer_format_create(attachments, p_view_count); + FramebufferFormatID format_id = framebuffer_format_create_multipass(attachments, p_passes, p_view_count); if (format_id == INVALID_ID) { return RID(); } @@ -4178,6 +4374,8 @@ RID RenderingDeviceVulkan::shader_create(const Vector<ShaderStageData> &p_stages uint32_t stages_processed = 0; + Vector<Shader::SpecializationConstant> specialization_constants; + bool is_compute = false; uint32_t compute_local_size[3] = { 0, 0, 0 }; @@ -4364,6 +4562,62 @@ RID RenderingDeviceVulkan::shader_create(const Vector<ShaderStageData> &p_stages } } + { + //specialization constants + + uint32_t sc_count = 0; + result = spvReflectEnumerateSpecializationConstants(&module, &sc_count, nullptr); + ERR_FAIL_COND_V_MSG(result != SPV_REFLECT_RESULT_SUCCESS, RID(), + "Reflection of SPIR-V shader stage '" + String(shader_stage_names[p_stages[i].shader_stage]) + "' failed enumerating specialization constants."); + + if (sc_count) { + Vector<SpvReflectSpecializationConstant *> spec_constants; + spec_constants.resize(sc_count); + + result = spvReflectEnumerateSpecializationConstants(&module, &sc_count, spec_constants.ptrw()); + ERR_FAIL_COND_V_MSG(result != SPV_REFLECT_RESULT_SUCCESS, RID(), + "Reflection of SPIR-V shader stage '" + String(shader_stage_names[p_stages[i].shader_stage]) + "' failed obtaining specialization constants."); + + for (uint32_t j = 0; j < sc_count; j++) { + int32_t existing = -1; + Shader::SpecializationConstant sconst; + sconst.constant.constant_id = spec_constants[j]->constant_id; + switch (spec_constants[j]->constant_type) { + case SPV_REFLECT_SPECIALIZATION_CONSTANT_BOOL: { + sconst.constant.type = PIPELINE_SPECIALIZATION_CONSTANT_TYPE_BOOL; + sconst.constant.bool_value = spec_constants[j]->default_value.int_bool_value != 0; + } break; + case SPV_REFLECT_SPECIALIZATION_CONSTANT_INT: { + sconst.constant.type = PIPELINE_SPECIALIZATION_CONSTANT_TYPE_INT; + sconst.constant.int_value = spec_constants[j]->default_value.int_bool_value; + } break; + case SPV_REFLECT_SPECIALIZATION_CONSTANT_FLOAT: { + sconst.constant.type = PIPELINE_SPECIALIZATION_CONSTANT_TYPE_FLOAT; + sconst.constant.float_value = spec_constants[j]->default_value.float_value; + } break; + } + sconst.stage_flags = 1 << p_stages[i].shader_stage; + + print_line("spec constant " + itos(i) + ": " + String(spec_constants[j]->name) + " type " + itos(spec_constants[j]->constant_type) + " id " + itos(spec_constants[j]->constant_id)); + + for (int k = 0; k < specialization_constants.size(); k++) { + if (specialization_constants[k].constant.constant_id == sconst.constant.constant_id) { + ERR_FAIL_COND_V_MSG(specialization_constants[k].constant.type != sconst.constant.type, RID(), "More than one specialization constant used for id (" + itos(sconst.constant.constant_id) + "), but their types differ."); + ERR_FAIL_COND_V_MSG(specialization_constants[k].constant.int_value != sconst.constant.int_value, RID(), "More than one specialization constant used for id (" + itos(sconst.constant.constant_id) + "), but their default values differ."); + existing = k; + break; + } + } + + if (existing > 0) { + specialization_constants.write[existing].stage_flags |= sconst.stage_flags; + } else { + specialization_constants.push_back(sconst); + } + } + } + } + if (stage == SHADER_STAGE_VERTEX) { uint32_t iv_count = 0; result = spvReflectEnumerateInputVariables(&module, &iv_count, nullptr); @@ -4401,8 +4655,9 @@ RID RenderingDeviceVulkan::shader_create(const Vector<ShaderStageData> &p_stages "Reflection of SPIR-V shader stage '" + String(shader_stage_names[p_stages[i].shader_stage]) + "' failed obtaining output variables."); for (uint32_t j = 0; j < ov_count; j++) { - if (output_vars[j]) { - fragment_outputs = MAX(fragment_outputs, output_vars[j]->location + 1); + const SpvReflectInterfaceVariable *refvar = output_vars[j]; + if (refvar != nullptr && refvar->built_in != SpvBuiltInFragDepth) { + fragment_outputs |= 1 << refvar->location; } } } @@ -4453,12 +4708,13 @@ RID RenderingDeviceVulkan::shader_create(const Vector<ShaderStageData> &p_stages Shader shader; shader.vertex_input_mask = vertex_input_mask; - shader.fragment_outputs = fragment_outputs; + shader.fragment_output_mask = fragment_outputs; shader.push_constant = push_constant; shader.is_compute = is_compute; shader.compute_local_size[0] = compute_local_size[0]; shader.compute_local_size[1] = compute_local_size[1]; shader.compute_local_size[2] = compute_local_size[2]; + shader.specialization_constants = specialization_constants; String error_text; @@ -5194,6 +5450,49 @@ RID RenderingDeviceVulkan::uniform_set_create(const Vector<Uniform> &p_uniforms, write.pTexelBufferView = nullptr; } break; case UNIFORM_TYPE_INPUT_ATTACHMENT: { + ERR_FAIL_COND_V_MSG(shader->is_compute, RID(), "InputAttachment (binding: " + itos(uniform.binding) + ") supplied for compute shader (this is not allowed)."); + + if (uniform.ids.size() != set_uniform.length) { + if (set_uniform.length > 1) { + ERR_FAIL_V_MSG(RID(), "InputAttachment (binding: " + itos(uniform.binding) + ") is an array of (" + itos(set_uniform.length) + ") textures, so it should be provided equal number of texture IDs to satisfy it (IDs provided: " + itos(uniform.ids.size()) + ")."); + } else { + ERR_FAIL_V_MSG(RID(), "InputAttachment (binding: " + itos(uniform.binding) + ") should provide one ID referencing a texture (IDs provided: " + itos(uniform.ids.size()) + ")."); + } + } + + Vector<VkDescriptorImageInfo> image_info; + + for (int j = 0; j < uniform.ids.size(); j++) { + Texture *texture = texture_owner.getornull(uniform.ids[j]); + + ERR_FAIL_COND_V_MSG(!texture, RID(), + "InputAttachment (binding: " + itos(uniform.binding) + ", index " + itos(j) + ") is not a valid texture."); + + ERR_FAIL_COND_V_MSG(!(texture->usage_flags & TEXTURE_USAGE_SAMPLING_BIT), RID(), + "InputAttachment (binding: " + itos(uniform.binding) + ", index " + itos(j) + ") needs the TEXTURE_USAGE_SAMPLING_BIT usage flag set in order to be used as uniform."); + + VkDescriptorImageInfo img_info; + img_info.sampler = VK_NULL_HANDLE; + img_info.imageView = texture->view; + + if (texture->owner.is_valid()) { + texture = texture_owner.getornull(texture->owner); + ERR_FAIL_COND_V(!texture, RID()); //bug, should never happen + } + + img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + + image_info.push_back(img_info); + } + + write.dstArrayElement = 0; + write.descriptorCount = uniform.ids.size(); + write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; + write.pImageInfo = image_infos.push_back(image_info)->get().ptr(); + write.pBufferInfo = nullptr; + write.pTexelBufferView = nullptr; + + type_size = uniform.ids.size(); } break; default: { } @@ -5265,6 +5564,13 @@ bool RenderingDeviceVulkan::uniform_set_is_valid(RID p_uniform_set) { return uniform_set_owner.owns(p_uniform_set); } +void RenderingDeviceVulkan::uniform_set_set_invalidation_callback(RID p_uniform_set, UniformSetInvalidatedCallback p_callback, void *p_userdata) { + UniformSet *us = uniform_set_owner.getornull(p_uniform_set); + ERR_FAIL_COND(!us); + us->invalidated_callback = p_callback; + us->invalidated_callback_userdata = p_userdata; +} + Error RenderingDeviceVulkan::buffer_update(RID p_buffer, uint32_t p_offset, uint32_t p_size, const void *p_data, uint32_t p_post_barrier) { _THREAD_SAFE_METHOD_ @@ -5404,7 +5710,7 @@ Vector<uint8_t> RenderingDeviceVulkan::buffer_get_data(RID p_buffer) { /**** RENDER PIPELINE ****/ /*************************/ -RID RenderingDeviceVulkan::render_pipeline_create(RID p_shader, FramebufferFormatID p_framebuffer_format, VertexFormatID p_vertex_format, RenderPrimitive p_render_primitive, const PipelineRasterizationState &p_rasterization_state, const PipelineMultisampleState &p_multisample_state, const PipelineDepthStencilState &p_depth_stencil_state, const PipelineColorBlendState &p_blend_state, int p_dynamic_state_flags) { +RID RenderingDeviceVulkan::render_pipeline_create(RID p_shader, FramebufferFormatID p_framebuffer_format, VertexFormatID p_vertex_format, RenderPrimitive p_render_primitive, const PipelineRasterizationState &p_rasterization_state, const PipelineMultisampleState &p_multisample_state, const PipelineDepthStencilState &p_depth_stencil_state, const PipelineColorBlendState &p_blend_state, int p_dynamic_state_flags, uint32_t p_for_render_pass, const Vector<PipelineSpecializationConstant> &p_specialization_constants) { _THREAD_SAFE_METHOD_ //needs a shader @@ -5423,8 +5729,16 @@ RID RenderingDeviceVulkan::render_pipeline_create(RID p_shader, FramebufferForma { //validate shader vs framebuffer - ERR_FAIL_COND_V_MSG(shader->fragment_outputs != fb_format.color_attachments, RID(), - "Mismatch fragment output bindings (" + itos(shader->fragment_outputs) + ") and framebuffer color buffers (" + itos(fb_format.color_attachments) + ") when binding both in render pipeline."); + ERR_FAIL_COND_V_MSG(p_for_render_pass >= uint32_t(fb_format.E->key().passes.size()), RID(), "Render pass requested for pipeline creation (" + itos(p_for_render_pass) + ") is out of bounds"); + const FramebufferPass &pass = fb_format.E->key().passes[p_for_render_pass]; + uint32_t output_mask = 0; + for (int i = 0; i < pass.color_attachments.size(); i++) { + if (pass.color_attachments[i] != FramebufferPass::ATTACHMENT_UNUSED) { + output_mask |= 1 << i; + } + } + ERR_FAIL_COND_V_MSG(shader->fragment_output_mask != output_mask, RID(), + "Mismatch fragment shader output mask (" + itos(shader->fragment_output_mask) + ") and framebuffer color output mask (" + itos(output_mask) + ") when binding both in render pipeline."); } //vertex VkPipelineVertexInputStateCreateInfo pipeline_vertex_input_state_create_info; @@ -5609,44 +5923,53 @@ RID RenderingDeviceVulkan::render_pipeline_create(RID p_shader, FramebufferForma ERR_FAIL_INDEX_V(p_blend_state.logic_op, LOGIC_OP_MAX, RID()); color_blend_state_create_info.logicOp = logic_operations[p_blend_state.logic_op]; - ERR_FAIL_COND_V(fb_format.color_attachments != p_blend_state.attachments.size(), RID()); - Vector<VkPipelineColorBlendAttachmentState> attachment_states; + { + const FramebufferPass &pass = fb_format.E->key().passes[p_for_render_pass]; + + for (int i = 0; i < pass.color_attachments.size(); i++) { + if (pass.color_attachments[i] != FramebufferPass::ATTACHMENT_UNUSED) { + int idx = attachment_states.size(); + + ERR_FAIL_INDEX_V(idx, p_blend_state.attachments.size(), RID()); + VkPipelineColorBlendAttachmentState state; + state.blendEnable = p_blend_state.attachments[idx].enable_blend; + + ERR_FAIL_INDEX_V(p_blend_state.attachments[idx].src_color_blend_factor, BLEND_FACTOR_MAX, RID()); + state.srcColorBlendFactor = blend_factors[p_blend_state.attachments[idx].src_color_blend_factor]; + ERR_FAIL_INDEX_V(p_blend_state.attachments[idx].dst_color_blend_factor, BLEND_FACTOR_MAX, RID()); + state.dstColorBlendFactor = blend_factors[p_blend_state.attachments[idx].dst_color_blend_factor]; + ERR_FAIL_INDEX_V(p_blend_state.attachments[idx].color_blend_op, BLEND_OP_MAX, RID()); + state.colorBlendOp = blend_operations[p_blend_state.attachments[idx].color_blend_op]; + + ERR_FAIL_INDEX_V(p_blend_state.attachments[idx].src_alpha_blend_factor, BLEND_FACTOR_MAX, RID()); + state.srcAlphaBlendFactor = blend_factors[p_blend_state.attachments[idx].src_alpha_blend_factor]; + ERR_FAIL_INDEX_V(p_blend_state.attachments[idx].dst_alpha_blend_factor, BLEND_FACTOR_MAX, RID()); + state.dstAlphaBlendFactor = blend_factors[p_blend_state.attachments[idx].dst_alpha_blend_factor]; + ERR_FAIL_INDEX_V(p_blend_state.attachments[idx].alpha_blend_op, BLEND_OP_MAX, RID()); + state.alphaBlendOp = blend_operations[p_blend_state.attachments[idx].alpha_blend_op]; + + state.colorWriteMask = 0; + if (p_blend_state.attachments[idx].write_r) { + state.colorWriteMask |= VK_COLOR_COMPONENT_R_BIT; + } + if (p_blend_state.attachments[idx].write_g) { + state.colorWriteMask |= VK_COLOR_COMPONENT_G_BIT; + } + if (p_blend_state.attachments[idx].write_b) { + state.colorWriteMask |= VK_COLOR_COMPONENT_B_BIT; + } + if (p_blend_state.attachments[idx].write_a) { + state.colorWriteMask |= VK_COLOR_COMPONENT_A_BIT; + } - for (int i = 0; i < p_blend_state.attachments.size(); i++) { - VkPipelineColorBlendAttachmentState state; - state.blendEnable = p_blend_state.attachments[i].enable_blend; - - ERR_FAIL_INDEX_V(p_blend_state.attachments[i].src_color_blend_factor, BLEND_FACTOR_MAX, RID()); - state.srcColorBlendFactor = blend_factors[p_blend_state.attachments[i].src_color_blend_factor]; - ERR_FAIL_INDEX_V(p_blend_state.attachments[i].dst_color_blend_factor, BLEND_FACTOR_MAX, RID()); - state.dstColorBlendFactor = blend_factors[p_blend_state.attachments[i].dst_color_blend_factor]; - ERR_FAIL_INDEX_V(p_blend_state.attachments[i].color_blend_op, BLEND_OP_MAX, RID()); - state.colorBlendOp = blend_operations[p_blend_state.attachments[i].color_blend_op]; - - ERR_FAIL_INDEX_V(p_blend_state.attachments[i].src_alpha_blend_factor, BLEND_FACTOR_MAX, RID()); - state.srcAlphaBlendFactor = blend_factors[p_blend_state.attachments[i].src_alpha_blend_factor]; - ERR_FAIL_INDEX_V(p_blend_state.attachments[i].dst_alpha_blend_factor, BLEND_FACTOR_MAX, RID()); - state.dstAlphaBlendFactor = blend_factors[p_blend_state.attachments[i].dst_alpha_blend_factor]; - ERR_FAIL_INDEX_V(p_blend_state.attachments[i].alpha_blend_op, BLEND_OP_MAX, RID()); - state.alphaBlendOp = blend_operations[p_blend_state.attachments[i].alpha_blend_op]; - - state.colorWriteMask = 0; - if (p_blend_state.attachments[i].write_r) { - state.colorWriteMask |= VK_COLOR_COMPONENT_R_BIT; - } - if (p_blend_state.attachments[i].write_g) { - state.colorWriteMask |= VK_COLOR_COMPONENT_G_BIT; - } - if (p_blend_state.attachments[i].write_b) { - state.colorWriteMask |= VK_COLOR_COMPONENT_B_BIT; - } - if (p_blend_state.attachments[i].write_a) { - state.colorWriteMask |= VK_COLOR_COMPONENT_A_BIT; + attachment_states.push_back(state); + idx++; + }; } - attachment_states.push_back(state); - }; + ERR_FAIL_COND_V(attachment_states.size() != p_blend_state.attachments.size(), RID()); + } color_blend_state_create_info.attachmentCount = attachment_states.size(); color_blend_state_create_info.pAttachments = attachment_states.ptr(); @@ -5705,8 +6028,63 @@ RID RenderingDeviceVulkan::render_pipeline_create(RID p_shader, FramebufferForma graphics_pipeline_create_info.pNext = nullptr; graphics_pipeline_create_info.flags = 0; - graphics_pipeline_create_info.stageCount = shader->pipeline_stages.size(); - graphics_pipeline_create_info.pStages = shader->pipeline_stages.ptr(); + Vector<VkPipelineShaderStageCreateInfo> pipeline_stages = shader->pipeline_stages; + Vector<VkSpecializationInfo> specialization_info; + Vector<Vector<VkSpecializationMapEntry>> specialization_map_entries; + Vector<uint32_t> specialization_constant_data; + + if (shader->specialization_constants.size()) { + specialization_constant_data.resize(shader->specialization_constants.size()); + uint32_t *data_ptr = specialization_constant_data.ptrw(); + specialization_info.resize(pipeline_stages.size()); + specialization_map_entries.resize(pipeline_stages.size()); + for (int i = 0; i < shader->specialization_constants.size(); i++) { + //see if overriden + const Shader::SpecializationConstant &sc = shader->specialization_constants[i]; + data_ptr[i] = sc.constant.int_value; //just copy the 32 bits + + for (int j = 0; j < p_specialization_constants.size(); j++) { + const PipelineSpecializationConstant &psc = p_specialization_constants[j]; + if (psc.constant_id == sc.constant.constant_id) { + ERR_FAIL_COND_V_MSG(psc.type != sc.constant.type, RID(), "Specialization constant provided for id (" + itos(sc.constant.constant_id) + ") is of the wrong type."); + data_ptr[i] = sc.constant.int_value; + break; + } + } + + VkSpecializationMapEntry entry; + + entry.constantID = sc.constant.constant_id; + entry.offset = i * sizeof(uint32_t); + entry.size = sizeof(uint32_t); + + for (int j = 0; j < SHADER_STAGE_MAX; j++) { + if (sc.stage_flags & (1 << j)) { + VkShaderStageFlagBits stage = shader_stage_masks[j]; + for (int k = 0; k < pipeline_stages.size(); k++) { + if (pipeline_stages[k].stage == stage) { + specialization_map_entries.write[k].push_back(entry); + } + } + } + } + } + + for (int k = 0; k < pipeline_stages.size(); k++) { + if (specialization_map_entries[k].size()) { + specialization_info.write[k].dataSize = specialization_constant_data.size() * sizeof(uint32_t); + specialization_info.write[k].pData = data_ptr; + specialization_info.write[k].mapEntryCount = specialization_map_entries[k].size(); + specialization_info.write[k].pMapEntries = specialization_map_entries[k].ptr(); + + pipeline_stages.write[k].pSpecializationInfo = specialization_info.ptr(); + } + } + } + + graphics_pipeline_create_info.stageCount = pipeline_stages.size(); + graphics_pipeline_create_info.pStages = pipeline_stages.ptr(); + graphics_pipeline_create_info.pVertexInputState = &pipeline_vertex_input_state_create_info; graphics_pipeline_create_info.pInputAssemblyState = &input_assembly_create_info; graphics_pipeline_create_info.pTessellationState = &tessellation_create_info; @@ -5719,7 +6097,7 @@ RID RenderingDeviceVulkan::render_pipeline_create(RID p_shader, FramebufferForma graphics_pipeline_create_info.layout = shader->pipeline_layout; graphics_pipeline_create_info.renderPass = fb_format.render_pass; - graphics_pipeline_create_info.subpass = 0; + graphics_pipeline_create_info.subpass = p_for_render_pass; graphics_pipeline_create_info.basePipelineHandle = VK_NULL_HANDLE; graphics_pipeline_create_info.basePipelineIndex = 0; @@ -5736,6 +6114,7 @@ RID RenderingDeviceVulkan::render_pipeline_create(RID p_shader, FramebufferForma #ifdef DEBUG_ENABLED pipeline.validation.dynamic_state = p_dynamic_state_flags; pipeline.validation.framebuffer_format = p_framebuffer_format; + pipeline.validation.render_pass = p_for_render_pass; pipeline.validation.vertex_format = p_vertex_format; pipeline.validation.uses_restart_indices = input_assembly_create_info.primitiveRestartEnable; @@ -5774,7 +6153,7 @@ bool RenderingDeviceVulkan::render_pipeline_is_valid(RID p_pipeline) { /**** COMPUTE PIPELINE ****/ /**************************/ -RID RenderingDeviceVulkan::compute_pipeline_create(RID p_shader) { +RID RenderingDeviceVulkan::compute_pipeline_create(RID p_shader, const Vector<PipelineSpecializationConstant> &p_specialization_constants) { _THREAD_SAFE_METHOD_ //needs a shader @@ -5796,6 +6175,44 @@ RID RenderingDeviceVulkan::compute_pipeline_create(RID p_shader) { compute_pipeline_create_info.basePipelineHandle = VK_NULL_HANDLE; compute_pipeline_create_info.basePipelineIndex = 0; + VkSpecializationInfo specialization_info; + Vector<VkSpecializationMapEntry> specialization_map_entries; + Vector<uint32_t> specialization_constant_data; + + if (shader->specialization_constants.size()) { + specialization_constant_data.resize(shader->specialization_constants.size()); + uint32_t *data_ptr = specialization_constant_data.ptrw(); + for (int i = 0; i < shader->specialization_constants.size(); i++) { + //see if overriden + const Shader::SpecializationConstant &sc = shader->specialization_constants[i]; + data_ptr[i] = sc.constant.int_value; //just copy the 32 bits + + for (int j = 0; j < p_specialization_constants.size(); j++) { + const PipelineSpecializationConstant &psc = p_specialization_constants[j]; + if (psc.constant_id == sc.constant.constant_id) { + ERR_FAIL_COND_V_MSG(psc.type != sc.constant.type, RID(), "Specialization constant provided for id (" + itos(sc.constant.constant_id) + ") is of the wrong type."); + data_ptr[i] = sc.constant.int_value; + break; + } + } + + VkSpecializationMapEntry entry; + + entry.constantID = sc.constant.constant_id; + entry.offset = i * sizeof(uint32_t); + entry.size = sizeof(uint32_t); + + specialization_map_entries.push_back(entry); + } + + specialization_info.dataSize = specialization_constant_data.size() * sizeof(uint32_t); + specialization_info.pData = data_ptr; + specialization_info.mapEntryCount = specialization_map_entries.size(); + specialization_info.pMapEntries = specialization_map_entries.ptr(); + + compute_pipeline_create_info.stage.pSpecializationInfo = &specialization_info; + } + ComputePipeline pipeline; VkResult err = vkCreateComputePipelines(device, VK_NULL_HANDLE, 1, &compute_pipeline_create_info, nullptr, &pipeline.pipeline); ERR_FAIL_COND_V_MSG(err, RID(), "vkCreateComputePipelines failed with error " + itos(err) + "."); @@ -5874,13 +6291,14 @@ RenderingDevice::DrawListID RenderingDeviceVulkan::draw_list_begin_for_screen(Di ERR_FAIL_COND_V_MSG(compute_list != nullptr, INVALID_ID, "Only one draw/compute list can be active at the same time."); VkCommandBuffer command_buffer = frames[frame].draw_command_buffer; - draw_list = memnew(DrawList); - draw_list->command_buffer = command_buffer; + + Size2i size = Size2i(context->window_get_width(p_screen), context->window_get_height(p_screen)); + + _draw_list_allocate(Rect2i(Vector2i(), size), 0, 0); #ifdef DEBUG_ENABLED - draw_list->validation.framebuffer_format = screen_get_framebuffer_format(); + draw_list_framebuffer_format = screen_get_framebuffer_format(); #endif - draw_list_count = 0; - draw_list_split = false; + draw_list_subpass_count = 1; VkRenderPassBeginInfo render_pass_begin; render_pass_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; @@ -5888,8 +6306,8 @@ RenderingDevice::DrawListID RenderingDeviceVulkan::draw_list_begin_for_screen(Di render_pass_begin.renderPass = context->window_get_render_pass(p_screen); render_pass_begin.framebuffer = context->window_get_framebuffer(p_screen); - render_pass_begin.renderArea.extent.width = context->window_get_width(p_screen); - render_pass_begin.renderArea.extent.height = context->window_get_height(p_screen); + render_pass_begin.renderArea.extent.width = size.width; + render_pass_begin.renderArea.extent.height = size.height; render_pass_begin.renderArea.offset.x = 0; render_pass_begin.renderArea.offset.y = 0; @@ -5929,7 +6347,7 @@ RenderingDevice::DrawListID RenderingDeviceVulkan::draw_list_begin_for_screen(Di return int64_t(ID_TYPE_DRAW_LIST) << ID_BASE_SHIFT; } -Error RenderingDeviceVulkan::_draw_list_setup_framebuffer(Framebuffer *p_framebuffer, InitialAction p_initial_color_action, FinalAction p_final_color_action, InitialAction p_initial_depth_action, FinalAction p_final_depth_action, VkFramebuffer *r_framebuffer, VkRenderPass *r_render_pass) { +Error RenderingDeviceVulkan::_draw_list_setup_framebuffer(Framebuffer *p_framebuffer, InitialAction p_initial_color_action, FinalAction p_final_color_action, InitialAction p_initial_depth_action, FinalAction p_final_depth_action, VkFramebuffer *r_framebuffer, VkRenderPass *r_render_pass, uint32_t *r_subpass_count) { Framebuffer::VersionKey vk; vk.initial_color_action = p_initial_color_action; vk.final_color_action = p_final_color_action; @@ -5941,7 +6359,7 @@ Error RenderingDeviceVulkan::_draw_list_setup_framebuffer(Framebuffer *p_framebu //need to create this version Framebuffer::Version version; - version.render_pass = _render_pass_create(framebuffer_formats[p_framebuffer->format_id].E->key().attachments, p_initial_color_action, p_final_color_action, p_initial_depth_action, p_final_depth_action, nullptr, p_framebuffer->view_count); + version.render_pass = _render_pass_create(framebuffer_formats[p_framebuffer->format_id].E->key().attachments, framebuffer_formats[p_framebuffer->format_id].E->key().passes, p_initial_color_action, p_final_color_action, p_initial_depth_action, p_final_depth_action, p_framebuffer->view_count); VkFramebufferCreateInfo framebuffer_create_info; framebuffer_create_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; @@ -5965,11 +6383,14 @@ Error RenderingDeviceVulkan::_draw_list_setup_framebuffer(Framebuffer *p_framebu VkResult err = vkCreateFramebuffer(device, &framebuffer_create_info, nullptr, &version.framebuffer); ERR_FAIL_COND_V_MSG(err, ERR_CANT_CREATE, "vkCreateFramebuffer failed with error " + itos(err) + "."); + version.subpass_count = framebuffer_formats[p_framebuffer->format_id].E->key().passes.size(); + p_framebuffer->framebuffers.insert(vk, version); } const Framebuffer::Version &version = p_framebuffer->framebuffers[vk]; *r_framebuffer = version.framebuffer; *r_render_pass = version.render_pass; + *r_subpass_count = version.subpass_count; return OK; } @@ -6159,15 +6580,23 @@ RenderingDevice::DrawListID RenderingDeviceVulkan::draw_list_begin(RID p_framebu if (p_initial_color_action == INITIAL_ACTION_CLEAR) { //check clear values - int color_attachments = framebuffer_formats[framebuffer->format_id].color_attachments; - ERR_FAIL_COND_V_MSG(p_clear_color_values.size() != color_attachments, INVALID_ID, - "Clear color values supplied (" + itos(p_clear_color_values.size()) + ") differ from the amount required for framebuffer (" + itos(color_attachments) + ")."); + int color_count = 0; + for (int i = 0; i < framebuffer->texture_ids.size(); i++) { + Texture *texture = texture_owner.getornull(framebuffer->texture_ids[i]); + + if (texture->usage_flags & TEXTURE_USAGE_COLOR_ATTACHMENT_BIT) { + color_count++; + } + } + + ERR_FAIL_COND_V_MSG(p_clear_color_values.size() != color_count, INVALID_ID, + "Clear color values supplied (" + itos(p_clear_color_values.size()) + ") differ from the amount required for framebuffer color attachments (" + itos(color_count) + ")."); } VkFramebuffer vkframebuffer; VkRenderPass render_pass; - Error err = _draw_list_setup_framebuffer(framebuffer, p_initial_color_action, p_final_color_action, p_initial_depth_action, p_final_depth_action, &vkframebuffer, &render_pass); + Error err = _draw_list_setup_framebuffer(framebuffer, p_initial_color_action, p_final_color_action, p_initial_depth_action, p_final_depth_action, &vkframebuffer, &render_pass, &draw_list_subpass_count); ERR_FAIL_COND_V(err != OK, INVALID_ID); VkCommandBuffer command_buffer = frames[frame].draw_command_buffer; @@ -6177,13 +6606,14 @@ RenderingDevice::DrawListID RenderingDeviceVulkan::draw_list_begin(RID p_framebu return INVALID_ID; } - draw_list = memnew(DrawList); - draw_list->command_buffer = command_buffer; + draw_list_render_pass = render_pass; + draw_list_vkframebuffer = vkframebuffer; + + _draw_list_allocate(Rect2i(viewport_offset, viewport_size), 0, 0); #ifdef DEBUG_ENABLED - draw_list->validation.framebuffer_format = framebuffer->format_id; + draw_list_framebuffer_format = framebuffer->format_id; #endif - draw_list_count = 0; - draw_list_split = false; + draw_list_current_subpass = 0; if (needs_clear_color || needs_clear_depth) { _draw_list_insert_clear_region(draw_list, framebuffer, viewport_offset, viewport_size, needs_clear_color, p_clear_color_values, needs_clear_depth, p_clear_depth, p_clear_stencil); @@ -6207,7 +6637,6 @@ RenderingDevice::DrawListID RenderingDeviceVulkan::draw_list_begin(RID p_framebu vkCmdSetScissor(command_buffer, 0, 1, &scissor); - draw_list->viewport = Rect2i(viewport_offset, viewport_size); return int64_t(ID_TYPE_DRAW_LIST) << ID_BASE_SHIFT; } @@ -6249,47 +6678,23 @@ Error RenderingDeviceVulkan::draw_list_begin_split(RID p_framebuffer, uint32_t p if (p_initial_color_action == INITIAL_ACTION_CLEAR) { //check clear values - int color_attachments = framebuffer_formats[framebuffer->format_id].color_attachments; - ERR_FAIL_COND_V_MSG(p_clear_color_values.size() != color_attachments, ERR_INVALID_PARAMETER, - "Clear color values supplied (" + itos(p_clear_color_values.size()) + ") differ from the amount required for framebuffer (" + itos(color_attachments) + ")."); - } - - if (p_splits > (uint32_t)split_draw_list_allocators.size()) { - uint32_t from = split_draw_list_allocators.size(); - split_draw_list_allocators.resize(p_splits); - for (uint32_t i = from; i < p_splits; i++) { - VkCommandPoolCreateInfo cmd_pool_info; - cmd_pool_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; - cmd_pool_info.pNext = nullptr; - cmd_pool_info.queueFamilyIndex = context->get_graphics_queue(); - cmd_pool_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; - - VkResult res = vkCreateCommandPool(device, &cmd_pool_info, nullptr, &split_draw_list_allocators.write[i].command_pool); - ERR_FAIL_COND_V_MSG(res, ERR_CANT_CREATE, "vkCreateCommandPool failed with error " + itos(res) + "."); - - for (int j = 0; j < frame_count; j++) { - VkCommandBuffer command_buffer; - - VkCommandBufferAllocateInfo cmdbuf; - //no command buffer exists, create it. - cmdbuf.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; - cmdbuf.pNext = nullptr; - cmdbuf.commandPool = split_draw_list_allocators[i].command_pool; - cmdbuf.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY; - cmdbuf.commandBufferCount = 1; - - VkResult err = vkAllocateCommandBuffers(device, &cmdbuf, &command_buffer); - ERR_FAIL_COND_V_MSG(err, ERR_CANT_CREATE, "vkAllocateCommandBuffers failed with error " + itos(err) + "."); + int color_count = 0; + for (int i = 0; i < framebuffer->texture_ids.size(); i++) { + Texture *texture = texture_owner.getornull(framebuffer->texture_ids[i]); - split_draw_list_allocators.write[i].command_buffers.push_back(command_buffer); + if (texture->usage_flags & TEXTURE_USAGE_COLOR_ATTACHMENT_BIT) { + color_count++; } } + + ERR_FAIL_COND_V_MSG(p_clear_color_values.size() != color_count, ERR_INVALID_PARAMETER, + "Clear color values supplied (" + itos(p_clear_color_values.size()) + ") differ from the amount required for framebuffer (" + itos(color_count) + ")."); } VkFramebuffer vkframebuffer; VkRenderPass render_pass; - Error err = _draw_list_setup_framebuffer(framebuffer, p_initial_color_action, p_final_color_action, p_initial_depth_action, p_final_depth_action, &vkframebuffer, &render_pass); + Error err = _draw_list_setup_framebuffer(framebuffer, p_initial_color_action, p_final_color_action, p_initial_depth_action, p_final_depth_action, &vkframebuffer, &render_pass, &draw_list_subpass_count); ERR_FAIL_COND_V(err != OK, ERR_CANT_CREATE); VkCommandBuffer frame_command_buffer = frames[frame].draw_command_buffer; @@ -6299,53 +6704,24 @@ Error RenderingDeviceVulkan::draw_list_begin_split(RID p_framebuffer, uint32_t p return ERR_CANT_CREATE; } - draw_list = memnew_arr(DrawList, p_splits); - draw_list_count = p_splits; - draw_list_split = true; - - for (uint32_t i = 0; i < p_splits; i++) { - //take a command buffer and initialize it - VkCommandBuffer command_buffer = split_draw_list_allocators[i].command_buffers[frame]; - - VkCommandBufferInheritanceInfo inheritance_info; - inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO; - inheritance_info.pNext = nullptr; - inheritance_info.renderPass = render_pass; - inheritance_info.subpass = 0; - inheritance_info.framebuffer = vkframebuffer; - inheritance_info.occlusionQueryEnable = false; - inheritance_info.queryFlags = 0; //? - inheritance_info.pipelineStatistics = 0; - - VkCommandBufferBeginInfo cmdbuf_begin; - cmdbuf_begin.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; - cmdbuf_begin.pNext = nullptr; - cmdbuf_begin.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT; - cmdbuf_begin.pInheritanceInfo = &inheritance_info; - - VkResult res = vkResetCommandBuffer(command_buffer, 0); - if (res) { - memdelete_arr(draw_list); - draw_list = nullptr; - ERR_FAIL_V_MSG(ERR_CANT_CREATE, "vkResetCommandBuffer failed with error " + itos(res) + "."); - } - - res = vkBeginCommandBuffer(command_buffer, &cmdbuf_begin); - if (res) { - memdelete_arr(draw_list); - draw_list = nullptr; - ERR_FAIL_V_MSG(ERR_CANT_CREATE, "vkBeginCommandBuffer failed with error " + itos(res) + "."); - } + draw_list_current_subpass = 0; - draw_list[i].command_buffer = command_buffer; #ifdef DEBUG_ENABLED - draw_list[i].validation.framebuffer_format = framebuffer->format_id; + draw_list_framebuffer_format = framebuffer->format_id; #endif + draw_list_render_pass = render_pass; + draw_list_vkframebuffer = vkframebuffer; - if (i == 0 && (needs_clear_color || needs_clear_depth)) { - _draw_list_insert_clear_region(draw_list, framebuffer, viewport_offset, viewport_size, needs_clear_color, p_clear_color_values, needs_clear_depth, p_clear_depth, p_clear_stencil); - } + err = _draw_list_allocate(Rect2i(viewport_offset, viewport_size), p_splits, 0); + if (err != OK) { + return err; + } + + if (needs_clear_color || needs_clear_depth) { + _draw_list_insert_clear_region(&draw_list[0], framebuffer, viewport_offset, viewport_size, needs_clear_color, p_clear_color_values, needs_clear_depth, p_clear_depth, p_clear_stencil); + } + for (uint32_t i = 0; i < p_splits; i++) { VkViewport viewport; viewport.x = viewport_offset.x; viewport.y = viewport_offset.y; @@ -6354,7 +6730,7 @@ Error RenderingDeviceVulkan::draw_list_begin_split(RID p_framebuffer, uint32_t p viewport.minDepth = 0; viewport.maxDepth = 1.0; - vkCmdSetViewport(command_buffer, 0, 1, &viewport); + vkCmdSetViewport(draw_list[i].command_buffer, 0, 1, &viewport); VkRect2D scissor; scissor.offset.x = viewport_offset.x; @@ -6362,10 +6738,8 @@ Error RenderingDeviceVulkan::draw_list_begin_split(RID p_framebuffer, uint32_t p scissor.extent.width = viewport_size.width; scissor.extent.height = viewport_size.height; - vkCmdSetScissor(command_buffer, 0, 1, &scissor); + vkCmdSetScissor(draw_list[i].command_buffer, 0, 1, &scissor); r_split_ids[i] = (int64_t(ID_TYPE_SPLIT_DRAW_LIST) << ID_BASE_SHIFT) + i; - - draw_list[i].viewport = Rect2i(viewport_offset, viewport_size); } return OK; @@ -6410,7 +6784,7 @@ void RenderingDeviceVulkan::draw_list_bind_render_pipeline(DrawListID p_list, RI const RenderPipeline *pipeline = render_pipeline_owner.getornull(p_render_pipeline); ERR_FAIL_COND(!pipeline); #ifdef DEBUG_ENABLED - ERR_FAIL_COND(pipeline->validation.framebuffer_format != dl->validation.framebuffer_format); + ERR_FAIL_COND(pipeline->validation.framebuffer_format != draw_list_framebuffer_format && pipeline->validation.render_pass != draw_list_current_subpass); #endif if (p_render_pipeline == dl->state.pipeline) { @@ -6749,30 +7123,162 @@ void RenderingDeviceVulkan::draw_list_disable_scissor(DrawListID p_list) { vkCmdSetScissor(dl->command_buffer, 0, 1, &scissor); } -void RenderingDeviceVulkan::draw_list_end(uint32_t p_post_barrier) { - _THREAD_SAFE_METHOD_ +RenderingDevice::DrawListID RenderingDeviceVulkan::draw_list_switch_to_next_pass() { + ERR_FAIL_COND_V(draw_list == nullptr, INVALID_ID); + ERR_FAIL_COND_V(draw_list_current_subpass >= draw_list_subpass_count - 1, INVALID_FORMAT_ID); - ERR_FAIL_COND_MSG(!draw_list, "Immediate draw list is already inactive."); + draw_list_current_subpass++; + + Rect2i viewport; + _draw_list_free(&viewport); + + vkCmdNextSubpass(frames[frame].draw_command_buffer, VK_SUBPASS_CONTENTS_INLINE); + + _draw_list_allocate(viewport, 0, draw_list_current_subpass); + + return int64_t(ID_TYPE_DRAW_LIST) << ID_BASE_SHIFT; +} +Error RenderingDeviceVulkan::draw_list_switch_to_next_pass_split(uint32_t p_splits, DrawListID *r_split_ids) { + ERR_FAIL_COND_V(draw_list == nullptr, ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V(draw_list_current_subpass >= draw_list_subpass_count - 1, ERR_INVALID_PARAMETER); + + draw_list_current_subpass++; + + Rect2i viewport; + _draw_list_free(&viewport); + + vkCmdNextSubpass(frames[frame].draw_command_buffer, VK_SUBPASS_CONTENTS_INLINE); + + _draw_list_allocate(viewport, p_splits, draw_list_current_subpass); + + for (uint32_t i = 0; i < p_splits; i++) { + r_split_ids[i] = (int64_t(ID_TYPE_SPLIT_DRAW_LIST) << ID_BASE_SHIFT) + i; + } + + return OK; +} +Error RenderingDeviceVulkan::_draw_list_allocate(const Rect2i &p_viewport, uint32_t p_splits, uint32_t p_subpass) { + if (p_splits == 0) { + draw_list = memnew(DrawList); + draw_list->command_buffer = frames[frame].draw_command_buffer; + draw_list->viewport = p_viewport; + draw_list_count = 0; + draw_list_split = false; + } else { + if (p_splits > (uint32_t)split_draw_list_allocators.size()) { + uint32_t from = split_draw_list_allocators.size(); + split_draw_list_allocators.resize(p_splits); + for (uint32_t i = from; i < p_splits; i++) { + VkCommandPoolCreateInfo cmd_pool_info; + cmd_pool_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; + cmd_pool_info.pNext = nullptr; + cmd_pool_info.queueFamilyIndex = context->get_graphics_queue(); + cmd_pool_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; + + VkResult res = vkCreateCommandPool(device, &cmd_pool_info, nullptr, &split_draw_list_allocators.write[i].command_pool); + ERR_FAIL_COND_V_MSG(res, ERR_CANT_CREATE, "vkCreateCommandPool failed with error " + itos(res) + "."); + + for (int j = 0; j < frame_count; j++) { + VkCommandBuffer command_buffer; + + VkCommandBufferAllocateInfo cmdbuf; + //no command buffer exists, create it. + cmdbuf.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; + cmdbuf.pNext = nullptr; + cmdbuf.commandPool = split_draw_list_allocators[i].command_pool; + cmdbuf.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY; + cmdbuf.commandBufferCount = 1; + + VkResult err = vkAllocateCommandBuffers(device, &cmdbuf, &command_buffer); + ERR_FAIL_COND_V_MSG(err, ERR_CANT_CREATE, "vkAllocateCommandBuffers failed with error " + itos(err) + "."); + + split_draw_list_allocators.write[i].command_buffers.push_back(command_buffer); + } + } + } + draw_list = memnew_arr(DrawList, p_splits); + draw_list_count = p_splits; + draw_list_split = true; + + for (uint32_t i = 0; i < p_splits; i++) { + //take a command buffer and initialize it + VkCommandBuffer command_buffer = split_draw_list_allocators[i].command_buffers[frame]; + + VkCommandBufferInheritanceInfo inheritance_info; + inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO; + inheritance_info.pNext = nullptr; + inheritance_info.renderPass = draw_list_render_pass; + inheritance_info.subpass = p_subpass; + inheritance_info.framebuffer = draw_list_vkframebuffer; + inheritance_info.occlusionQueryEnable = false; + inheritance_info.queryFlags = 0; //? + inheritance_info.pipelineStatistics = 0; + + VkCommandBufferBeginInfo cmdbuf_begin; + cmdbuf_begin.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; + cmdbuf_begin.pNext = nullptr; + cmdbuf_begin.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT; + cmdbuf_begin.pInheritanceInfo = &inheritance_info; + + VkResult res = vkResetCommandBuffer(command_buffer, 0); + if (res) { + memdelete_arr(draw_list); + draw_list = nullptr; + ERR_FAIL_V_MSG(ERR_CANT_CREATE, "vkResetCommandBuffer failed with error " + itos(res) + "."); + } + + res = vkBeginCommandBuffer(command_buffer, &cmdbuf_begin); + if (res) { + memdelete_arr(draw_list); + draw_list = nullptr; + ERR_FAIL_V_MSG(ERR_CANT_CREATE, "vkBeginCommandBuffer failed with error " + itos(res) + "."); + } + + draw_list[i].command_buffer = command_buffer; + draw_list[i].viewport = p_viewport; + } + } + + return OK; +} + +void RenderingDeviceVulkan::_draw_list_free(Rect2i *r_last_viewport) { if (draw_list_split) { //send all command buffers VkCommandBuffer *command_buffers = (VkCommandBuffer *)alloca(sizeof(VkCommandBuffer) * draw_list_count); for (uint32_t i = 0; i < draw_list_count; i++) { vkEndCommandBuffer(draw_list[i].command_buffer); command_buffers[i] = draw_list[i].command_buffer; + if (r_last_viewport) { + if (i == 0 || draw_list[i].viewport_set) { + *r_last_viewport = draw_list[i].viewport; + } + } } vkCmdExecuteCommands(frames[frame].draw_command_buffer, draw_list_count, command_buffers); - vkCmdEndRenderPass(frames[frame].draw_command_buffer); memdelete_arr(draw_list); draw_list = nullptr; } else { + if (r_last_viewport) { + *r_last_viewport = draw_list->viewport; + } //just end the list - vkCmdEndRenderPass(draw_list->command_buffer); memdelete(draw_list); draw_list = nullptr; } +} + +void RenderingDeviceVulkan::draw_list_end(uint32_t p_post_barrier) { + _THREAD_SAFE_METHOD_ + + ERR_FAIL_COND_MSG(!draw_list, "Immediate draw list is already inactive."); + + _draw_list_free(); + + vkCmdEndRenderPass(frames[frame].draw_command_buffer); for (int i = 0; i < draw_list_bound_textures.size(); i++) { Texture *texture = texture_owner.getornull(draw_list_bound_textures[i]); @@ -7497,6 +8003,10 @@ void RenderingDeviceVulkan::_free_internal(RID p_id) { } else if (uniform_set_owner.owns(p_id)) { UniformSet *uniform_set = uniform_set_owner.getornull(p_id); frames[frame].uniform_sets_to_dispose_of.push_back(*uniform_set); + if (uniform_set->invalidated_callback != nullptr) { + uniform_set->invalidated_callback(p_id, uniform_set->invalidated_callback_userdata); + } + uniform_set_owner.free(p_id); } else if (render_pipeline_owner.owns(p_id)) { RenderPipeline *pipeline = render_pipeline_owner.getornull(p_id); @@ -7781,6 +8291,7 @@ void RenderingDeviceVulkan::_free_pending_resources(int p_frame) { vkDestroyImageView(device, texture->view, nullptr); if (texture->owner.is_null()) { //actually owns the image and the allocation too + image_memory -= texture->allocation_info.size; vmaDestroyImage(allocator, texture->image, texture->allocation); } frames[p_frame].textures_to_dispose_of.pop_front(); @@ -7804,10 +8315,16 @@ uint32_t RenderingDeviceVulkan::get_frame_delay() const { return frame_count; } -uint64_t RenderingDeviceVulkan::get_memory_usage() const { - VmaStats stats; - vmaCalculateStats(allocator, &stats); - return stats.total.usedBytes; +uint64_t RenderingDeviceVulkan::get_memory_usage(MemoryType p_type) const { + if (p_type == MEMORY_BUFFERS) { + return buffer_memory; + } else if (p_type == MEMORY_TEXTURES) { + return image_memory; + } else { + VmaStats stats; + vmaCalculateStats(allocator, &stats); + return stats.total.usedBytes; + } } void RenderingDeviceVulkan::_flush(bool p_current_frame) { diff --git a/drivers/vulkan/rendering_device_vulkan.h b/drivers/vulkan/rendering_device_vulkan.h index f4fe9cf956..8b95ff43b8 100644 --- a/drivers/vulkan/rendering_device_vulkan.h +++ b/drivers/vulkan/rendering_device_vulkan.h @@ -156,6 +156,7 @@ class RenderingDeviceVulkan : public RenderingDevice { uint32_t texture_upload_region_size_px = 0; Vector<uint8_t> _texture_get_data_from_image(Texture *tex, VkImage p_image, VmaAllocation p_allocation, uint32_t p_layer, bool p_2d = false); + Error _texture_update(RID p_texture, uint32_t p_layer, const Vector<uint8_t> &p_data, uint32_t p_post_barrier, bool p_use_setup_queue); /*****************/ /**** SAMPLER ****/ @@ -234,12 +235,87 @@ class RenderingDeviceVulkan : public RenderingDevice { struct FramebufferFormatKey { Vector<AttachmentFormat> attachments; + Vector<FramebufferPass> passes; uint32_t view_count = 1; bool operator<(const FramebufferFormatKey &p_key) const { if (view_count != p_key.view_count) { return view_count < p_key.view_count; } + uint32_t pass_size = passes.size(); + uint32_t key_pass_size = p_key.passes.size(); + if (pass_size != key_pass_size) { + return pass_size < key_pass_size; + } + const FramebufferPass *pass_ptr = passes.ptr(); + const FramebufferPass *key_pass_ptr = p_key.passes.ptr(); + + for (uint32_t i = 0; i < pass_size; i++) { + { //compare color attachments + uint32_t attachment_size = pass_ptr[i].color_attachments.size(); + uint32_t key_attachment_size = key_pass_ptr[i].color_attachments.size(); + if (attachment_size != key_attachment_size) { + return attachment_size < key_attachment_size; + } + const int32_t *pass_attachment_ptr = pass_ptr[i].color_attachments.ptr(); + const int32_t *key_pass_attachment_ptr = key_pass_ptr[i].color_attachments.ptr(); + + for (uint32_t j = 0; j < attachment_size; j++) { + if (pass_attachment_ptr[j] != key_pass_attachment_ptr[j]) { + return pass_attachment_ptr[j] < key_pass_attachment_ptr[j]; + } + } + } + { //compare input attachments + uint32_t attachment_size = pass_ptr[i].input_attachments.size(); + uint32_t key_attachment_size = key_pass_ptr[i].input_attachments.size(); + if (attachment_size != key_attachment_size) { + return attachment_size < key_attachment_size; + } + const int32_t *pass_attachment_ptr = pass_ptr[i].input_attachments.ptr(); + const int32_t *key_pass_attachment_ptr = key_pass_ptr[i].input_attachments.ptr(); + + for (uint32_t j = 0; j < attachment_size; j++) { + if (pass_attachment_ptr[j] != key_pass_attachment_ptr[j]) { + return pass_attachment_ptr[j] < key_pass_attachment_ptr[j]; + } + } + } + { //compare resolve attachments + uint32_t attachment_size = pass_ptr[i].resolve_attachments.size(); + uint32_t key_attachment_size = key_pass_ptr[i].resolve_attachments.size(); + if (attachment_size != key_attachment_size) { + return attachment_size < key_attachment_size; + } + const int32_t *pass_attachment_ptr = pass_ptr[i].resolve_attachments.ptr(); + const int32_t *key_pass_attachment_ptr = key_pass_ptr[i].resolve_attachments.ptr(); + + for (uint32_t j = 0; j < attachment_size; j++) { + if (pass_attachment_ptr[j] != key_pass_attachment_ptr[j]) { + return pass_attachment_ptr[j] < key_pass_attachment_ptr[j]; + } + } + } + { //compare preserve attachments + uint32_t attachment_size = pass_ptr[i].preserve_attachments.size(); + uint32_t key_attachment_size = key_pass_ptr[i].preserve_attachments.size(); + if (attachment_size != key_attachment_size) { + return attachment_size < key_attachment_size; + } + const int32_t *pass_attachment_ptr = pass_ptr[i].preserve_attachments.ptr(); + const int32_t *key_pass_attachment_ptr = key_pass_ptr[i].preserve_attachments.ptr(); + + for (uint32_t j = 0; j < attachment_size; j++) { + if (pass_attachment_ptr[j] != key_pass_attachment_ptr[j]) { + return pass_attachment_ptr[j] < key_pass_attachment_ptr[j]; + } + } + } + if (pass_ptr[i].depth_attachment != key_pass_ptr[i].depth_attachment) { + return pass_ptr[i].depth_attachment < key_pass_ptr[i].depth_attachment; + } + } + int as = attachments.size(); int bs = p_key.attachments.size(); if (as != bs) { @@ -266,16 +342,14 @@ class RenderingDeviceVulkan : public RenderingDevice { } }; - VkRenderPass _render_pass_create(const Vector<AttachmentFormat> &p_format, InitialAction p_initial_action, FinalAction p_final_action, InitialAction p_initial_depth_action, FinalAction p_final_depthcolor_action, int *r_color_attachment_count = nullptr, uint32_t p_view_count = 1); - + VkRenderPass _render_pass_create(const Vector<AttachmentFormat> &p_attachments, const Vector<FramebufferPass> &p_passes, InitialAction p_initial_action, FinalAction p_final_action, InitialAction p_initial_depth_action, FinalAction p_final_depth_action, uint32_t p_view_count = 1, Vector<TextureSamples> *r_samples = nullptr); // This is a cache and it's never freed, it ensures // IDs for a given format are always unique. Map<FramebufferFormatKey, FramebufferFormatID> framebuffer_format_cache; struct FramebufferFormat { const Map<FramebufferFormatKey, FramebufferFormatID>::Element *E; VkRenderPass render_pass = VK_NULL_HANDLE; //here for constructing shaders, never used, see section (7.2. Render Pass Compatibility from Vulkan spec) - int color_attachments = 0; //used for pipeline validation - TextureSamples samples; + Vector<TextureSamples> pass_samples; uint32_t view_count = 1; // number of views }; @@ -289,6 +363,7 @@ class RenderingDeviceVulkan : public RenderingDevice { InitialAction initial_depth_action; FinalAction final_depth_action; uint32_t view_count; + bool operator<(const VersionKey &p_key) const { if (initial_color_action == p_key.initial_color_action) { if (final_color_action == p_key.final_color_action) { @@ -316,6 +391,7 @@ class RenderingDeviceVulkan : public RenderingDevice { struct Version { VkFramebuffer framebuffer = VK_NULL_HANDLE; VkRenderPass render_pass = VK_NULL_HANDLE; //this one is owned + uint32_t subpass_count = 1; }; Map<VersionKey, Version> framebuffers; @@ -536,7 +612,7 @@ class RenderingDeviceVulkan : public RenderingDevice { }; uint32_t vertex_input_mask = 0; //inputs used, this is mostly for validation - int fragment_outputs = 0; + uint32_t fragment_output_mask = 0; struct PushConstant { uint32_t push_constant_size = 0; @@ -547,11 +623,17 @@ class RenderingDeviceVulkan : public RenderingDevice { uint32_t compute_local_size[3] = { 0, 0, 0 }; + struct SpecializationConstant { + PipelineSpecializationConstant constant; + uint32_t stage_flags = 0; + }; + bool is_compute = false; int max_output = 0; Vector<Set> sets; Vector<uint32_t> set_formats; Vector<VkPipelineShaderStageCreateInfo> pipeline_stages; + Vector<SpecializationConstant> specialization_constants; VkPipelineLayout pipeline_layout = VK_NULL_HANDLE; }; @@ -656,6 +738,8 @@ class RenderingDeviceVulkan : public RenderingDevice { LocalVector<AttachableTexture> attachable_textures; //used for validation Vector<Texture *> mutable_sampled_textures; //used for layout change Vector<Texture *> mutable_storage_textures; //used for layout change + UniformSetInvalidatedCallback invalidated_callback = nullptr; + void *invalidated_callback_userdata = nullptr; }; RID_Owner<UniformSet, true> uniform_set_owner; @@ -680,6 +764,7 @@ class RenderingDeviceVulkan : public RenderingDevice { #ifdef DEBUG_ENABLED struct Validation { FramebufferFormatID framebuffer_format = 0; + uint32_t render_pass = 0; uint32_t dynamic_state = 0; VertexFormatID vertex_format = 0; bool uses_restart_indices = false; @@ -735,6 +820,7 @@ class RenderingDeviceVulkan : public RenderingDevice { struct DrawList { VkCommandBuffer command_buffer = VK_NULL_HANDLE; // If persistent, this is owned, otherwise it's shared with the ringbuffer. Rect2i viewport; + bool viewport_set = false; struct SetState { uint32_t pipeline_expected_format = 0; @@ -758,7 +844,6 @@ class RenderingDeviceVulkan : public RenderingDevice { #ifdef DEBUG_ENABLED struct Validation { bool active = true; // Means command buffer was not closed, so you can keep adding things. - FramebufferFormatID framebuffer_format = INVALID_ID; // Actual render pass values. uint32_t dynamic_state = 0; VertexFormatID vertex_format = INVALID_ID; @@ -794,7 +879,15 @@ class RenderingDeviceVulkan : public RenderingDevice { }; DrawList *draw_list = nullptr; // One for regular draw lists, multiple for split. + uint32_t draw_list_subpass_count = 0; uint32_t draw_list_count = 0; + VkRenderPass draw_list_render_pass; + VkFramebuffer draw_list_vkframebuffer; +#ifdef DEBUG_ENABLED + FramebufferFormatID draw_list_framebuffer_format = INVALID_ID; +#endif + uint32_t draw_list_current_subpass = 0; + bool draw_list_split = false; Vector<RID> draw_list_bound_textures; Vector<RID> draw_list_storage_textures; @@ -802,10 +895,12 @@ class RenderingDeviceVulkan : public RenderingDevice { bool draw_list_unbind_depth_textures = false; void _draw_list_insert_clear_region(DrawList *draw_list, Framebuffer *framebuffer, Point2i viewport_offset, Point2i viewport_size, bool p_clear_color, const Vector<Color> &p_clear_colors, bool p_clear_depth, float p_depth, uint32_t p_stencil); - Error _draw_list_setup_framebuffer(Framebuffer *p_framebuffer, InitialAction p_initial_color_action, FinalAction p_final_color_action, InitialAction p_initial_depth_action, FinalAction p_final_depth_action, VkFramebuffer *r_framebuffer, VkRenderPass *r_render_pass); + Error _draw_list_setup_framebuffer(Framebuffer *p_framebuffer, InitialAction p_initial_color_action, FinalAction p_final_color_action, InitialAction p_initial_depth_action, FinalAction p_final_depth_action, VkFramebuffer *r_framebuffer, VkRenderPass *r_render_pass, uint32_t *r_subpass_count); Error _draw_list_render_pass_begin(Framebuffer *framebuffer, InitialAction p_initial_color_action, FinalAction p_final_color_action, InitialAction p_initial_depth_action, FinalAction p_final_depth_action, const Vector<Color> &p_clear_colors, float p_clear_depth, uint32_t p_clear_stencil, Point2i viewport_offset, Point2i viewport_size, VkFramebuffer vkframebuffer, VkRenderPass render_pass, VkCommandBuffer command_buffer, VkSubpassContents subpass_contents, const Vector<RID> &p_storage_textures); _FORCE_INLINE_ DrawList *_get_draw_list_ptr(DrawListID p_id); Buffer *_get_buffer_from_owner(RID p_buffer, VkPipelineStageFlags &dst_stage_mask, VkAccessFlags &dst_access, uint32_t p_post_barrier); + Error _draw_list_allocate(const Rect2i &p_viewport, uint32_t p_splits, uint32_t p_subpass); + void _draw_list_free(Rect2i *r_last_viewport = nullptr); /**********************/ /**** COMPUTE LIST ****/ @@ -919,6 +1014,9 @@ class RenderingDeviceVulkan : public RenderingDevice { VulkanContext *context = nullptr; + uint64_t image_memory = 0; + uint64_t buffer_memory = 0; + void _free_internal(RID p_id); void _flush(bool p_current_frame); @@ -951,10 +1049,12 @@ public: /*********************/ virtual FramebufferFormatID framebuffer_format_create(const Vector<AttachmentFormat> &p_format, uint32_t p_view_count = 1); + virtual FramebufferFormatID framebuffer_format_create_multipass(const Vector<AttachmentFormat> &p_attachments, Vector<FramebufferPass> &p_passes, uint32_t p_view_count = 1); virtual FramebufferFormatID framebuffer_format_create_empty(TextureSamples p_samples = TEXTURE_SAMPLES_1); - virtual TextureSamples framebuffer_format_get_texture_samples(FramebufferFormatID p_format); + virtual TextureSamples framebuffer_format_get_texture_samples(FramebufferFormatID p_format, uint32_t p_pass = 0); virtual RID framebuffer_create(const Vector<RID> &p_texture_attachments, FramebufferFormatID p_format_check = INVALID_ID, uint32_t p_view_count = 1); + virtual RID framebuffer_create_multipass(const Vector<RID> &p_texture_attachments, Vector<FramebufferPass> &p_passes, FramebufferFormatID p_format_check = INVALID_ID, uint32_t p_view_count = 1); virtual RID framebuffer_create_empty(const Size2i &p_size, TextureSamples p_samples = TEXTURE_SAMPLES_1, FramebufferFormatID p_format_check = INVALID_ID); virtual FramebufferFormatID framebuffer_get_format(RID p_framebuffer); @@ -996,6 +1096,7 @@ public: virtual RID uniform_set_create(const Vector<Uniform> &p_uniforms, RID p_shader, uint32_t p_shader_set); virtual bool uniform_set_is_valid(RID p_uniform_set); + virtual void uniform_set_set_invalidation_callback(RID p_uniform_set, UniformSetInvalidatedCallback p_callback, void *p_userdata); virtual Error buffer_update(RID p_buffer, uint32_t p_offset, uint32_t p_size, const void *p_data, uint32_t p_post_barrier = BARRIER_MASK_ALL); //works for any buffer virtual Error buffer_clear(RID p_buffer, uint32_t p_offset, uint32_t p_size, uint32_t p_post_barrier = BARRIER_MASK_ALL); @@ -1005,14 +1106,14 @@ public: /**** RENDER PIPELINE ****/ /*************************/ - virtual RID render_pipeline_create(RID p_shader, FramebufferFormatID p_framebuffer_format, VertexFormatID p_vertex_format, RenderPrimitive p_render_primitive, const PipelineRasterizationState &p_rasterization_state, const PipelineMultisampleState &p_multisample_state, const PipelineDepthStencilState &p_depth_stencil_state, const PipelineColorBlendState &p_blend_state, int p_dynamic_state_flags = 0); + virtual RID render_pipeline_create(RID p_shader, FramebufferFormatID p_framebuffer_format, VertexFormatID p_vertex_format, RenderPrimitive p_render_primitive, const PipelineRasterizationState &p_rasterization_state, const PipelineMultisampleState &p_multisample_state, const PipelineDepthStencilState &p_depth_stencil_state, const PipelineColorBlendState &p_blend_state, int p_dynamic_state_flags = 0, uint32_t p_for_render_pass = 0, const Vector<PipelineSpecializationConstant> &p_specialization_constants = Vector<PipelineSpecializationConstant>()); virtual bool render_pipeline_is_valid(RID p_pipeline); /**************************/ /**** COMPUTE PIPELINE ****/ /**************************/ - virtual RID compute_pipeline_create(RID p_shader); + virtual RID compute_pipeline_create(RID p_shader, const Vector<PipelineSpecializationConstant> &p_specialization_constants = Vector<PipelineSpecializationConstant>()); virtual bool compute_pipeline_is_valid(RID p_pipeline); /****************/ @@ -1044,6 +1145,9 @@ public: virtual void draw_list_enable_scissor(DrawListID p_list, const Rect2 &p_rect); virtual void draw_list_disable_scissor(DrawListID p_list); + virtual DrawListID draw_list_switch_to_next_pass(); + virtual Error draw_list_switch_to_next_pass_split(uint32_t p_splits, DrawListID *r_split_ids); + virtual void draw_list_end(uint32_t p_post_barrier = BARRIER_MASK_ALL); /***********************/ @@ -1100,7 +1204,7 @@ public: virtual RenderingDevice *create_local_device(); - virtual uint64_t get_memory_usage() const; + virtual uint64_t get_memory_usage(MemoryType p_type) const; virtual void set_resource_name(RID p_id, const String p_name); diff --git a/drivers/vulkan/vulkan_context.cpp b/drivers/vulkan/vulkan_context.cpp index 6ed43b5d31..d35c519320 100644 --- a/drivers/vulkan/vulkan_context.cpp +++ b/drivers/vulkan/vulkan_context.cpp @@ -1013,11 +1013,11 @@ Error VulkanContext::_create_device() { return OK; } -Error VulkanContext::_initialize_queues(VkSurfaceKHR surface) { +Error VulkanContext::_initialize_queues(VkSurfaceKHR p_surface) { // Iterate over each queue to learn whether it supports presenting: VkBool32 *supportsPresent = (VkBool32 *)malloc(queue_family_count * sizeof(VkBool32)); for (uint32_t i = 0; i < queue_family_count; i++) { - fpGetPhysicalDeviceSurfaceSupportKHR(gpu, i, surface, &supportsPresent[i]); + fpGetPhysicalDeviceSurfaceSupportKHR(gpu, i, p_surface, &supportsPresent[i]); } // Search for a graphics and a present queue in the array of queue @@ -1091,10 +1091,10 @@ Error VulkanContext::_initialize_queues(VkSurfaceKHR surface) { // Get the list of VkFormat's that are supported: uint32_t formatCount; - VkResult err = fpGetPhysicalDeviceSurfaceFormatsKHR(gpu, surface, &formatCount, nullptr); + VkResult err = fpGetPhysicalDeviceSurfaceFormatsKHR(gpu, p_surface, &formatCount, nullptr); ERR_FAIL_COND_V(err, ERR_CANT_CREATE); VkSurfaceFormatKHR *surfFormats = (VkSurfaceFormatKHR *)malloc(formatCount * sizeof(VkSurfaceFormatKHR)); - err = fpGetPhysicalDeviceSurfaceFormatsKHR(gpu, surface, &formatCount, surfFormats); + err = fpGetPhysicalDeviceSurfaceFormatsKHR(gpu, p_surface, &formatCount, surfFormats); if (err) { free(surfFormats); ERR_FAIL_V(ERR_CANT_CREATE); @@ -1169,9 +1169,6 @@ Error VulkanContext::_create_semaphores() { err = vkCreateFence(device, &fence_ci, nullptr, &fences[i]); ERR_FAIL_COND_V(err, ERR_CANT_CREATE); - err = vkCreateSemaphore(device, &semaphoreCreateInfo, nullptr, &image_acquired_semaphores[i]); - ERR_FAIL_COND_V(err, ERR_CANT_CREATE); - err = vkCreateSemaphore(device, &semaphoreCreateInfo, nullptr, &draw_complete_semaphores[i]); ERR_FAIL_COND_V(err, ERR_CANT_CREATE); @@ -1192,7 +1189,7 @@ bool VulkanContext::_use_validation_layers() { return Engine::get_singleton()->is_validation_layers_enabled(); } -Error VulkanContext::_window_create(DisplayServer::WindowID p_window_id, VkSurfaceKHR p_surface, int p_width, int p_height) { +Error VulkanContext::_window_create(DisplayServer::WindowID p_window_id, DisplayServer::VSyncMode p_vsync_mode, VkSurfaceKHR p_surface, int p_width, int p_height) { ERR_FAIL_COND_V(windows.has(p_window_id), ERR_INVALID_PARAMETER); if (!queues_initialized) { @@ -1201,15 +1198,40 @@ Error VulkanContext::_window_create(DisplayServer::WindowID p_window_id, VkSurfa // is created. Error err = _initialize_queues(p_surface); ERR_FAIL_COND_V(err != OK, ERR_CANT_CREATE); + } else { + // make sure any of the surfaces supports present (validation layer complains if this is not done). + bool any_supports_present = false; + for (uint32_t i = 0; i < queue_family_count; i++) { + VkBool32 supports; + fpGetPhysicalDeviceSurfaceSupportKHR(gpu, i, p_surface, &supports); + if (supports) { + any_supports_present = true; + break; + } + } + + ERR_FAIL_COND_V_MSG(!any_supports_present, ERR_CANT_CREATE, "Surface passed for sub-window creation does not support presenting"); } Window window; window.surface = p_surface; window.width = p_width; window.height = p_height; + window.vsync_mode = p_vsync_mode; Error err = _update_swap_chain(&window); ERR_FAIL_COND_V(err != OK, ERR_CANT_CREATE); + VkSemaphoreCreateInfo semaphoreCreateInfo = { + /*sType*/ VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, + /*pNext*/ nullptr, + /*flags*/ 0, + }; + + for (uint32_t i = 0; i < FRAME_LAG; i++) { + VkResult vkerr = vkCreateSemaphore(device, &semaphoreCreateInfo, nullptr, &window.image_acquired_semaphores[i]); + ERR_FAIL_COND_V(vkerr, ERR_CANT_CREATE); + } + windows[p_window_id] = window; return OK; } @@ -1249,6 +1271,10 @@ VkFramebuffer VulkanContext::window_get_framebuffer(DisplayServer::WindowID p_wi void VulkanContext::window_destroy(DisplayServer::WindowID p_window_id) { ERR_FAIL_COND(!windows.has(p_window_id)); _clean_up_swap_chain(&windows[p_window_id]); + for (uint32_t i = 0; i < FRAME_LAG; i++) { + vkDestroySemaphore(device, windows[p_window_id].image_acquired_semaphores[i], nullptr); + } + vkDestroySurfaceKHR(inst, windows[p_window_id].surface, nullptr); windows.erase(p_window_id); } @@ -1335,7 +1361,6 @@ Error VulkanContext::_update_swap_chain(Window *window) { } // The FIFO present mode is guaranteed by the spec to be supported // and to have no tearing. It's a great default present mode to use. - VkPresentModeKHR swapchainPresentMode = VK_PRESENT_MODE_FIFO_KHR; // There are times when you may wish to use another present mode. The // following code shows how to select them, and the comments provide some @@ -1364,16 +1389,41 @@ Error VulkanContext::_update_swap_chain(Window *window) { // the application wants the late image to be immediately displayed, even // though that may mean some tearing. - if (window->presentMode != swapchainPresentMode) { - for (size_t i = 0; i < presentModeCount; ++i) { - if (presentModes[i] == window->presentMode) { - swapchainPresentMode = window->presentMode; - break; - } + VkPresentModeKHR requested_present_mode = VkPresentModeKHR::VK_PRESENT_MODE_FIFO_KHR; + switch (window->vsync_mode) { + case DisplayServer::VSYNC_MAILBOX: + requested_present_mode = VkPresentModeKHR::VK_PRESENT_MODE_MAILBOX_KHR; + break; + case DisplayServer::VSYNC_ADAPTIVE: + requested_present_mode = VkPresentModeKHR::VK_PRESENT_MODE_FIFO_RELAXED_KHR; + break; + case DisplayServer::VSYNC_ENABLED: + requested_present_mode = VkPresentModeKHR::VK_PRESENT_MODE_FIFO_KHR; + break; + case DisplayServer::VSYNC_DISABLED: + requested_present_mode = VkPresentModeKHR::VK_PRESENT_MODE_IMMEDIATE_KHR; + break; + } + + // Check if the requested mode is available. + bool present_mode_available = false; + for (uint32_t i = 0; i < presentModeCount; i++) { + if (presentModes[i] == requested_present_mode) { + present_mode_available = true; } } + + // Set the windows present mode if it is available, otherwise FIFO is used (guaranteed supported). + if (present_mode_available) { + window->presentMode = requested_present_mode; + } else { + WARN_PRINT("Requested VSync mode is not available!"); + window->vsync_mode = DisplayServer::VSYNC_ENABLED; //Set to default + } + + print_verbose("Using present mode: " + String(string_VkPresentModeKHR(window->presentMode))); + free(presentModes); - ERR_FAIL_COND_V_MSG(swapchainPresentMode != window->presentMode, ERR_CANT_CREATE, "Present mode specified is not supported\n"); // Determine the number of VkImages to use in the swap chain. // Application desires to acquire 3 images at a time for triple @@ -1430,7 +1480,7 @@ Error VulkanContext::_update_swap_chain(Window *window) { /*pQueueFamilyIndices*/ nullptr, /*preTransform*/ (VkSurfaceTransformFlagBitsKHR)preTransform, /*compositeAlpha*/ compositeAlpha, - /*presentMode*/ swapchainPresentMode, + /*presentMode*/ window->presentMode, /*clipped*/ true, /*oldSwapchain*/ VK_NULL_HANDLE, }; @@ -1703,6 +1753,8 @@ Error VulkanContext::prepare_buffers() { for (Map<int, Window>::Element *E = windows.front(); E; E = E->next()) { Window *w = &E->get(); + w->semaphore_acquired = false; + if (w->swapchain == VK_NULL_HANDLE) { continue; } @@ -1711,7 +1763,7 @@ Error VulkanContext::prepare_buffers() { // Get the index of the next available swapchain image: err = fpAcquireNextImageKHR(device, w->swapchain, UINT64_MAX, - image_acquired_semaphores[frame_index], VK_NULL_HANDLE, &w->current_buffer); + w->image_acquired_semaphores[frame_index], VK_NULL_HANDLE, &w->current_buffer); if (err == VK_ERROR_OUT_OF_DATE_KHR) { // swapchain is out of date (e.g. the window was resized) and @@ -1724,8 +1776,10 @@ Error VulkanContext::prepare_buffers() { // presentation engine will still present the image correctly. print_verbose("Vulkan: Early suboptimal swapchain."); break; + } else if (err != VK_SUCCESS) { + ERR_BREAK_MSG(err != VK_SUCCESS, "Vulkan: Did not create swapchain successfully."); } else { - ERR_FAIL_COND_V(err, ERR_CANT_CREATE); + w->semaphore_acquired = true; } } while (err != VK_SUCCESS); } @@ -1775,14 +1829,25 @@ Error VulkanContext::swap_buffers() { commands_to_submit = command_buffer_count; } + VkSemaphore *semaphores_to_acquire = (VkSemaphore *)alloca(windows.size() * sizeof(VkSemaphore)); + uint32_t semaphores_to_acquire_count = 0; + + for (Map<int, Window>::Element *E = windows.front(); E; E = E->next()) { + Window *w = &E->get(); + + if (w->semaphore_acquired) { + semaphores_to_acquire[semaphores_to_acquire_count++] = w->image_acquired_semaphores[frame_index]; + } + } + VkPipelineStageFlags pipe_stage_flags; VkSubmitInfo submit_info; submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; submit_info.pNext = nullptr; submit_info.pWaitDstStageMask = &pipe_stage_flags; pipe_stage_flags = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; - submit_info.waitSemaphoreCount = 1; - submit_info.pWaitSemaphores = &image_acquired_semaphores[frame_index]; + submit_info.waitSemaphoreCount = semaphores_to_acquire_count; + submit_info.pWaitSemaphores = semaphores_to_acquire; submit_info.commandBufferCount = commands_to_submit; submit_info.pCommandBuffers = commands_ptr; submit_info.signalSemaphoreCount = 1; @@ -2122,6 +2187,17 @@ String VulkanContext::get_device_pipeline_cache_uuid() const { return pipeline_cache_id; } +DisplayServer::VSyncMode VulkanContext::get_vsync_mode(DisplayServer::WindowID p_window) const { + ERR_FAIL_COND_V_MSG(!windows.has(p_window), DisplayServer::VSYNC_ENABLED, "Could not get VSync mode for window with WindowID " + itos(p_window) + " because it does not exist."); + return windows[p_window].vsync_mode; +} + +void VulkanContext::set_vsync_mode(DisplayServer::WindowID p_window, DisplayServer::VSyncMode p_mode) { + ERR_FAIL_COND_MSG(!windows.has(p_window), "Could not set VSync mode for window with WindowID " + itos(p_window) + " because it does not exist."); + windows[p_window].vsync_mode = p_mode; + _update_swap_chain(&windows[p_window]); +} + VulkanContext::VulkanContext() { command_buffer_queue.resize(1); // First one is always the setup command. command_buffer_queue.write[0] = nullptr; @@ -2134,7 +2210,6 @@ VulkanContext::~VulkanContext() { if (device_initialized) { for (uint32_t i = 0; i < FRAME_LAG; i++) { vkDestroyFence(device, fences[i], nullptr); - vkDestroySemaphore(device, image_acquired_semaphores[i], nullptr); vkDestroySemaphore(device, draw_complete_semaphores[i], nullptr); if (separate_present_queue) { vkDestroySemaphore(device, image_ownership_semaphores[i], nullptr); diff --git a/drivers/vulkan/vulkan_context.h b/drivers/vulkan/vulkan_context.h index 738ead4f96..83e9524046 100644 --- a/drivers/vulkan/vulkan_context.h +++ b/drivers/vulkan/vulkan_context.h @@ -70,7 +70,6 @@ private: }; VkInstance inst = VK_NULL_HANDLE; - VkSurfaceKHR surface = VK_NULL_HANDLE; VkPhysicalDevice gpu = VK_NULL_HANDLE; VkPhysicalDeviceProperties gpu_props; uint32_t queue_family_count = 0; @@ -101,7 +100,6 @@ private: VkQueue present_queue = VK_NULL_HANDLE; VkColorSpaceKHR color_space; VkFormat format; - VkSemaphore image_acquired_semaphores[FRAME_LAG]; VkSemaphore draw_complete_semaphores[FRAME_LAG]; VkSemaphore image_ownership_semaphores[FRAME_LAG]; int frame_index = 0; @@ -121,9 +119,12 @@ private: VkSwapchainKHR swapchain = VK_NULL_HANDLE; SwapchainImageResources *swapchain_image_resources = VK_NULL_HANDLE; VkPresentModeKHR presentMode = VK_PRESENT_MODE_FIFO_KHR; + VkSemaphore image_acquired_semaphores[FRAME_LAG]; + bool semaphore_acquired = false; uint32_t current_buffer = 0; int width = 0; int height = 0; + DisplayServer::VSyncMode vsync_mode = DisplayServer::VSYNC_ENABLED; VkCommandPool present_cmd_pool = VK_NULL_HANDLE; // For separate present queue. VkRenderPass render_pass = VK_NULL_HANDLE; }; @@ -208,7 +209,7 @@ private: Error _create_physical_device(); - Error _initialize_queues(VkSurfaceKHR surface); + Error _initialize_queues(VkSurfaceKHR p_surface); Error _create_device(); @@ -222,7 +223,7 @@ private: protected: virtual const char *_get_platform_surface_extension() const = 0; - virtual Error _window_create(DisplayServer::WindowID p_window_id, VkSurfaceKHR p_surface, int p_width, int p_height); + virtual Error _window_create(DisplayServer::WindowID p_window_id, DisplayServer::VSyncMode p_vsync_mode, VkSurfaceKHR p_surface, int p_width, int p_height); virtual bool _use_validation_layers(); @@ -276,6 +277,9 @@ public: String get_device_name() const; String get_device_pipeline_cache_uuid() const; + void set_vsync_mode(DisplayServer::WindowID p_window, DisplayServer::VSyncMode p_mode); + DisplayServer::VSyncMode get_vsync_mode(DisplayServer::WindowID p_window = 0) const; + VulkanContext(); virtual ~VulkanContext(); }; diff --git a/editor/action_map_editor.cpp b/editor/action_map_editor.cpp index b0b79ca069..7ed603410d 100644 --- a/editor/action_map_editor.cpp +++ b/editor/action_map_editor.cpp @@ -310,7 +310,7 @@ void InputEventConfigurationDialog::_update_input_list() { MouseButton mouse_buttons[9] = { MOUSE_BUTTON_LEFT, MOUSE_BUTTON_RIGHT, MOUSE_BUTTON_MIDDLE, MOUSE_BUTTON_WHEEL_UP, MOUSE_BUTTON_WHEEL_DOWN, MOUSE_BUTTON_WHEEL_LEFT, MOUSE_BUTTON_WHEEL_RIGHT, MOUSE_BUTTON_XBUTTON1, MOUSE_BUTTON_XBUTTON2 }; for (int i = 0; i < 9; i++) { Ref<InputEventMouseButton> mb; - mb.instance(); + mb.instantiate(); mb->set_button_index(mouse_buttons[i]); String desc = get_event_text(mb); @@ -333,8 +333,8 @@ void InputEventConfigurationDialog::_update_input_list() { for (int i = 0; i < JOY_BUTTON_MAX; i++) { Ref<InputEventJoypadButton> joyb; - joyb.instance(); - joyb->set_button_index(i); + joyb.instantiate(); + joyb->set_button_index((JoyButton)i); String desc = get_event_text(joyb); if (!search_term.is_empty() && desc.findn(search_term) == -1) { @@ -358,8 +358,8 @@ void InputEventConfigurationDialog::_update_input_list() { int axis = i / 2; int direction = (i & 1) ? 1 : -1; Ref<InputEventJoypadMotion> joym; - joym.instance(); - joym->set_axis(axis); + joym.instantiate(); + joym->set_axis((JoyAxis)axis); joym->set_axis_value(direction); String desc = get_event_text(joym); @@ -458,7 +458,7 @@ void InputEventConfigurationDialog::_input_list_item_selected() { case InputEventConfigurationDialog::INPUT_KEY: { int kc = selected->get_meta("__keycode"); Ref<InputEventKey> k; - k.instance(); + k.instantiate(); if (physical_key_checkbox->is_pressed()) { k->set_physical_keycode(kc); @@ -481,8 +481,8 @@ void InputEventConfigurationDialog::_input_list_item_selected() { case InputEventConfigurationDialog::INPUT_MOUSE_BUTTON: { int idx = selected->get_meta("__index"); Ref<InputEventMouseButton> mb; - mb.instance(); - mb->set_button_index(idx); + mb.instantiate(); + mb->set_button_index((MouseButton)idx); // Maintain modifier state from checkboxes mb->set_alt_pressed(mod_checkboxes[MOD_ALT]->is_pressed()); mb->set_shift_pressed(mod_checkboxes[MOD_SHIFT]->is_pressed()); @@ -495,7 +495,7 @@ void InputEventConfigurationDialog::_input_list_item_selected() { } break; case InputEventConfigurationDialog::INPUT_JOY_BUTTON: { int idx = selected->get_meta("__index"); - Ref<InputEventJoypadButton> jb = InputEventJoypadButton::create_reference(idx); + Ref<InputEventJoypadButton> jb = InputEventJoypadButton::create_reference((JoyButton)idx); _set_event(jb); } break; case InputEventConfigurationDialog::INPUT_JOY_MOTION: { @@ -503,8 +503,8 @@ void InputEventConfigurationDialog::_input_list_item_selected() { int value = selected->get_meta("__value"); Ref<InputEventJoypadMotion> jm; - jm.instance(); - jm->set_axis(axis); + jm.instantiate(); + jm->set_axis((JoyAxis)axis); jm->set_axis_value(value); _set_event(jm); } break; @@ -1123,11 +1123,12 @@ ActionMapEditor::ActionMapEditor() { action_tree->set_hide_root(true); action_tree->set_column_titles_visible(true); action_tree->set_column_title(0, TTR("Action")); + action_tree->set_column_clip_content(0, true); action_tree->set_column_title(1, TTR("Deadzone")); action_tree->set_column_expand(1, false); - action_tree->set_column_min_width(1, 80 * EDSCALE); + action_tree->set_column_custom_minimum_width(1, 80 * EDSCALE); action_tree->set_column_expand(2, false); - action_tree->set_column_min_width(2, 50 * EDSCALE); + action_tree->set_column_custom_minimum_width(2, 50 * EDSCALE); action_tree->connect("item_edited", callable_mp(this, &ActionMapEditor::_action_edited)); action_tree->connect("item_activated", callable_mp(this, &ActionMapEditor::_tree_item_activated)); action_tree->connect("button_pressed", callable_mp(this, &ActionMapEditor::_tree_button_pressed)); diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index 4196bc8940..f61fb6bab3 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -3760,7 +3760,7 @@ Ref<Animation> AnimationTrackEditor::_create_and_get_reset_animation() { return player->get_animation("RESET"); } else { Ref<Animation> reset_anim; - reset_anim.instance(); + reset_anim.instantiate(); reset_anim->set_length(ANIM_MIN_LENGTH); undo_redo->add_do_method(player, "add_animation", "RESET", reset_anim); undo_redo->add_do_method(AnimationPlayerEditor::singleton, "_animation_player_changed", player); @@ -5983,7 +5983,7 @@ AnimationTrackEditor::AnimationTrackEditor() { //default plugins Ref<AnimationTrackEditDefaultPlugin> def_plugin; - def_plugin.instance(); + def_plugin.instantiate(); add_track_edit_plugin(def_plugin); //dialogs diff --git a/editor/audio_stream_preview.cpp b/editor/audio_stream_preview.cpp index 539657afd7..ad6e3ac1dc 100644 --- a/editor/audio_stream_preview.cpp +++ b/editor/audio_stream_preview.cpp @@ -192,7 +192,7 @@ Ref<AudioStreamPreview> AudioStreamPreviewGenerator::generate_preview(const Ref< } } - preview->preview.instance(); + preview->preview.instantiate(); preview->preview->preview = maxmin; preview->preview->length = len_s; diff --git a/editor/audio_stream_preview.h b/editor/audio_stream_preview.h index 61567598ed..9cf47fd51a 100644 --- a/editor/audio_stream_preview.h +++ b/editor/audio_stream_preview.h @@ -75,6 +75,15 @@ class AudioStreamPreviewGenerator : public Node { thread = p_rhs.thread; return *this; } + Preview(const Preview &p_rhs) { + preview = p_rhs.preview; + base_stream = p_rhs.base_stream; + playback = p_rhs.playback; + generating.set_to(generating.is_set()); + id = p_rhs.id; + thread = p_rhs.thread; + } + Preview() {} }; Map<ObjectID, Preview> previews; diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp index 807a45eb32..03914bec3b 100644 --- a/editor/code_editor.cpp +++ b/editor/code_editor.cpp @@ -105,6 +105,11 @@ void FindReplaceBar::_notification(int p_what) { hide_button->set_custom_minimum_size(hide_button->get_normal_texture()->get_size()); } else if (p_what == NOTIFICATION_THEME_CHANGED) { matches_label->add_theme_color_override("font_color", results_count > 0 ? get_theme_color("font_color", "Label") : get_theme_color("error_color", "Editor")); + } else if (p_what == NOTIFICATION_PREDELETE) { + if (base_text_editor) { + base_text_editor->remove_find_replace_bar(); + base_text_editor = nullptr; + } } } @@ -117,7 +122,7 @@ void FindReplaceBar::_unhandled_input(const Ref<InputEvent> &p_event) { } Control *focus_owner = get_focus_owner(); - if (text_editor->has_focus() || (focus_owner && vbc_lineedit->is_a_parent_of(focus_owner))) { + if (text_editor->has_focus() || (focus_owner && vbc_lineedit->is_ancestor_of(focus_owner))) { bool accepted = true; switch (k->get_keycode()) { @@ -595,6 +600,10 @@ void FindReplaceBar::set_text_edit(CodeTextEditor *p_text_editor) { text_editor = nullptr; } + if (!p_text_editor) { + return; + } + results_count = -1; base_text_editor = p_text_editor; text_editor = base_text_editor->get_text_editor(); @@ -729,8 +738,8 @@ void CodeTextEditor::_input(const Ref<InputEvent> &event) { accept_event(); return; } - if (ED_IS_SHORTCUT("script_text_editor/clone_down", key_event)) { - clone_lines_down(); + if (ED_IS_SHORTCUT("script_text_editor/duplicate_selection", key_event)) { + duplicate_selection(); accept_event(); return; } @@ -930,7 +939,7 @@ void CodeTextEditor::update_editor_settings() { text_editor->set_highlight_current_line(EditorSettings::get_singleton()->get("text_editor/highlighting/highlight_current_line")); text_editor->set_indent_using_spaces(EditorSettings::get_singleton()->get("text_editor/indent/type")); text_editor->set_indent_size(EditorSettings::get_singleton()->get("text_editor/indent/size")); - text_editor->set_auto_indent(EditorSettings::get_singleton()->get("text_editor/indent/auto_indent")); + text_editor->set_auto_indent_enabled(EditorSettings::get_singleton()->get("text_editor/indent/auto_indent")); text_editor->set_draw_tabs(EditorSettings::get_singleton()->get("text_editor/indent/draw_tabs")); text_editor->set_draw_spaces(EditorSettings::get_singleton()->get("text_editor/indent/draw_spaces")); text_editor->set_smooth_scroll_enabled(EditorSettings::get_singleton()->get("text_editor/navigation/smooth_scrolling")); @@ -1255,7 +1264,7 @@ void CodeTextEditor::_delete_line(int p_line) { text_editor->cursor_set_line(1); text_editor->cursor_set_column(0); } - text_editor->backspace_at_cursor(); + text_editor->backspace(); text_editor->unfold_line(p_line); text_editor->cursor_set_line(p_line); } @@ -1278,7 +1287,7 @@ void CodeTextEditor::delete_lines() { text_editor->end_complex_operation(); } -void CodeTextEditor::clone_lines_down() { +void CodeTextEditor::duplicate_selection() { const int cursor_column = text_editor->cursor_get_column(); int from_line = text_editor->cursor_get_line(); int to_line = text_editor->cursor_get_line(); @@ -1612,15 +1621,19 @@ void CodeTextEditor::validate_script() { idle->start(); } -void CodeTextEditor::_warning_label_gui_input(const Ref<InputEvent> &p_event) { - Ref<InputEventMouseButton> mb = p_event; - if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MOUSE_BUTTON_LEFT) { - _warning_button_pressed(); - } +void CodeTextEditor::_error_button_pressed() { + _set_show_errors_panel(!is_errors_panel_opened); + _set_show_warnings_panel(false); } void CodeTextEditor::_warning_button_pressed() { _set_show_warnings_panel(!is_warnings_panel_opened); + _set_show_errors_panel(false); +} + +void CodeTextEditor::_set_show_errors_panel(bool p_show) { + is_errors_panel_opened = p_show; + emit_signal("show_errors_panel", p_show); } void CodeTextEditor::_set_show_warnings_panel(bool p_show) { @@ -1653,6 +1666,7 @@ void CodeTextEditor::_notification(int p_what) { _update_font(); } break; case NOTIFICATION_ENTER_TREE: { + error_button->set_icon(get_theme_icon("StatusError", "EditorIcons")); warning_button->set_icon(get_theme_icon("NodeWarning", "EditorIcons")); add_theme_constant_override("separation", 4 * EDSCALE); } break; @@ -1662,16 +1676,28 @@ void CodeTextEditor::_notification(int p_what) { } set_process_input(is_visible_in_tree()); } break; + case NOTIFICATION_PREDELETE: { + if (find_replace_bar) { + find_replace_bar->set_text_edit(nullptr); + } + } break; default: break; } } -void CodeTextEditor::set_warning_nb(int p_warning_nb) { - warning_count_label->set_text(itos(p_warning_nb)); - warning_count_label->set_visible(p_warning_nb > 0); - warning_button->set_visible(p_warning_nb > 0); - if (!p_warning_nb) { +void CodeTextEditor::set_error_count(int p_error_count) { + error_button->set_text(itos(p_error_count)); + error_button->set_visible(p_error_count > 0); + if (!p_error_count) { + _set_show_errors_panel(false); + } +} + +void CodeTextEditor::set_warning_count(int p_warning_count) { + warning_button->set_text(itos(p_warning_count)); + warning_button->set_visible(p_warning_count > 0); + if (!p_warning_count) { _set_show_warnings_panel(false); } } @@ -1738,6 +1764,7 @@ void CodeTextEditor::_bind_methods() { ADD_SIGNAL(MethodInfo("validate_script")); ADD_SIGNAL(MethodInfo("load_theme_settings")); + ADD_SIGNAL(MethodInfo("show_errors_panel")); ADD_SIGNAL(MethodInfo("show_warnings_panel")); } @@ -1796,7 +1823,7 @@ CodeTextEditor::CodeTextEditor() { text_editor->set_draw_line_numbers(true); text_editor->set_brace_matching(true); - text_editor->set_auto_indent(true); + text_editor->set_auto_indent_enabled(true); status_bar = memnew(HBoxContainer); add_child(status_bar); @@ -1835,6 +1862,22 @@ CodeTextEditor::CodeTextEditor() { error->set_mouse_filter(MOUSE_FILTER_STOP); error->connect("gui_input", callable_mp(this, &CodeTextEditor::_error_pressed)); + // Errors + error_button = memnew(Button); + error_button->set_flat(true); + status_bar->add_child(error_button); + error_button->set_v_size_flags(SIZE_EXPAND | SIZE_SHRINK_CENTER); + error_button->set_default_cursor_shape(CURSOR_POINTING_HAND); + error_button->connect("pressed", callable_mp(this, &CodeTextEditor::_error_button_pressed)); + error_button->set_tooltip(TTR("Errors")); + + error_button->add_theme_color_override("font_color", EditorNode::get_singleton()->get_gui_base()->get_theme_color("error_color", "Editor")); + error_button->add_theme_font_override("font", EditorNode::get_singleton()->get_gui_base()->get_theme_font("status_source", "EditorFonts")); + error_button->add_theme_font_size_override("font_size", EditorNode::get_singleton()->get_gui_base()->get_theme_font_size("status_source_size", "EditorFonts")); + + is_errors_panel_opened = false; + set_error_count(0); + // Warnings warning_button = memnew(Button); warning_button->set_flat(true); @@ -1844,20 +1887,12 @@ CodeTextEditor::CodeTextEditor() { warning_button->connect("pressed", callable_mp(this, &CodeTextEditor::_warning_button_pressed)); warning_button->set_tooltip(TTR("Warnings")); - warning_count_label = memnew(Label); - status_bar->add_child(warning_count_label); - warning_count_label->set_v_size_flags(SIZE_EXPAND | SIZE_SHRINK_CENTER); - warning_count_label->set_align(Label::ALIGN_RIGHT); - warning_count_label->set_default_cursor_shape(CURSOR_POINTING_HAND); - warning_count_label->set_mouse_filter(MOUSE_FILTER_STOP); - warning_count_label->set_tooltip(TTR("Warnings")); - warning_count_label->add_theme_color_override("font_color", EditorNode::get_singleton()->get_gui_base()->get_theme_color("warning_color", "Editor")); - warning_count_label->add_theme_font_override("font", EditorNode::get_singleton()->get_gui_base()->get_theme_font("status_source", "EditorFonts")); - warning_count_label->add_theme_font_size_override("font_size", EditorNode::get_singleton()->get_gui_base()->get_theme_font_size("status_source_size", "EditorFonts")); - warning_count_label->connect("gui_input", callable_mp(this, &CodeTextEditor::_warning_label_gui_input)); + warning_button->add_theme_color_override("font_color", EditorNode::get_singleton()->get_gui_base()->get_theme_color("warning_color", "Editor")); + warning_button->add_theme_font_override("font", EditorNode::get_singleton()->get_gui_base()->get_theme_font("status_source", "EditorFonts")); + warning_button->add_theme_font_size_override("font_size", EditorNode::get_singleton()->get_gui_base()->get_theme_font_size("status_source_size", "EditorFonts")); is_warnings_panel_opened = false; - set_warning_nb(0); + set_warning_count(0); // Line and column line_and_col_txt = memnew(Label); diff --git a/editor/code_editor.h b/editor/code_editor.h index f368305e85..0e5a84b3d5 100644 --- a/editor/code_editor.h +++ b/editor/code_editor.h @@ -145,8 +145,8 @@ class CodeTextEditor : public VBoxContainer { HBoxContainer *status_bar; Button *toggle_scripts_button; + Button *error_button; Button *warning_button; - Label *warning_count_label; Label *line_and_col_txt; @@ -184,8 +184,9 @@ class CodeTextEditor : public VBoxContainer { CodeTextEditorCodeCompleteFunc code_complete_func; void *code_complete_ud; - void _warning_label_gui_input(const Ref<InputEvent> &p_event); + void _error_button_pressed(); void _warning_button_pressed(); + void _set_show_errors_panel(bool p_show); void _set_show_warnings_panel(bool p_show); void _error_pressed(const Ref<InputEvent> &p_event); @@ -205,6 +206,7 @@ protected: static void _bind_methods(); bool is_warnings_panel_opened; + bool is_errors_panel_opened; public: void trim_trailing_whitespace(); @@ -223,7 +225,7 @@ public: void move_lines_up(); void move_lines_down(); void delete_lines(); - void clone_lines_down(); + void duplicate_selection(); /// Toggle inline comment on currently selected lines, or on current line if nothing is selected, /// by adding or removing comment delimiter @@ -238,7 +240,8 @@ public: Variant get_edit_state(); void set_edit_state(const Variant &p_state); - void set_warning_nb(int p_warning_nb); + void set_error_count(int p_error_count); + void set_warning_count(int p_warning_count); void update_editor_settings(); void set_error(const String &p_error); diff --git a/editor/create_dialog.cpp b/editor/create_dialog.cpp index 968b24893c..027cee3f1c 100644 --- a/editor/create_dialog.cpp +++ b/editor/create_dialog.cpp @@ -130,7 +130,7 @@ bool CreateDialog::_should_hide_type(const String &p_type) const { } if (ClassDB::class_exists(p_type)) { - if (!ClassDB::can_instance(p_type)) { + if (!ClassDB::can_instantiate(p_type)) { return true; // Can't create abstract class. } @@ -234,8 +234,8 @@ void CreateDialog::_configure_search_option_item(TreeItem *r_item, const String r_item->set_text(0, p_type); } - bool can_instance = (p_cpp_type && ClassDB::can_instance(p_type)) || !p_cpp_type; - if (!can_instance) { + bool can_instantiate = (p_cpp_type && ClassDB::can_instantiate(p_type)) || !p_cpp_type; + if (!can_instantiate) { r_item->set_custom_color(0, search_options->get_theme_color("disabled_font_color", "Editor")); r_item->set_icon(0, EditorNode::get_singleton()->get_class_icon(p_type, "NodeDisabled")); r_item->set_selectable(0, false); @@ -247,7 +247,7 @@ void CreateDialog::_configure_search_option_item(TreeItem *r_item, const String r_item->set_collapsed(false); } else { // Don't collapse the root node or an abstract node on the first tree level. - bool should_collapse = p_type != base_type && (r_item->get_parent()->get_text(0) != base_type || can_instance); + bool should_collapse = p_type != base_type && (r_item->get_parent()->get_text(0) != base_type || can_instantiate); if (should_collapse && bool(EditorSettings::get_singleton()->get("docks/scene_tree/start_create_dialog_fully_expanded"))) { should_collapse = false; // Collapse all nodes anyway. @@ -432,7 +432,7 @@ Variant CreateDialog::instance_selected() { obj = EditorNode::get_editor_data().instance_custom_type(selected->get_text(0), custom); } } else { - obj = ClassDB::instance(selected->get_text(0)); + obj = ClassDB::instantiate(selected->get_text(0)); } // Check if any Object-type property should be instantiated. @@ -442,7 +442,7 @@ Variant CreateDialog::instance_selected() { for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { PropertyInfo pi = E->get(); if (pi.type == Variant::OBJECT && pi.usage & PROPERTY_USAGE_EDITOR_INSTANTIATE_OBJECT) { - Object *prop = ClassDB::instance(pi.class_name); + Object *prop = ClassDB::instantiate(pi.class_name); ((Object *)obj)->set(pi.name, prop); } } diff --git a/editor/debugger/editor_debugger_node.cpp b/editor/debugger/editor_debugger_node.cpp index ded0ee3aa7..5f90680115 100644 --- a/editor/debugger/editor_debugger_node.cpp +++ b/editor/debugger/editor_debugger_node.cpp @@ -65,7 +65,7 @@ EditorDebuggerNode::EditorDebuggerNode() { add_child(tabs); Ref<StyleBoxEmpty> empty; - empty.instance(); + empty.instantiate(); tabs->add_theme_style_override("panel", empty); auto_switch_remote_scene_tree = EDITOR_DEF("debugger/auto_switch_to_remote_scene_tree", false); diff --git a/editor/debugger/editor_debugger_server.cpp b/editor/debugger/editor_debugger_server.cpp index 662f247062..e8524e0702 100644 --- a/editor/debugger/editor_debugger_server.cpp +++ b/editor/debugger/editor_debugger_server.cpp @@ -60,7 +60,7 @@ EditorDebuggerServer *EditorDebuggerServerTCP::create(const String &p_protocol) } EditorDebuggerServerTCP::EditorDebuggerServerTCP() { - server.instance(); + server.instantiate(); } Error EditorDebuggerServerTCP::start() { diff --git a/editor/debugger/editor_network_profiler.cpp b/editor/debugger/editor_network_profiler.cpp index 2d57dff69d..1c781c4d98 100644 --- a/editor/debugger/editor_network_profiler.cpp +++ b/editor/debugger/editor_network_profiler.cpp @@ -178,19 +178,24 @@ EditorNetworkProfiler::EditorNetworkProfiler() { counters_display->set_column_titles_visible(true); counters_display->set_column_title(0, TTR("Node")); counters_display->set_column_expand(0, true); - counters_display->set_column_min_width(0, 60 * EDSCALE); + counters_display->set_column_clip_content(0, true); + counters_display->set_column_custom_minimum_width(0, 60 * EDSCALE); counters_display->set_column_title(1, TTR("Incoming RPC")); counters_display->set_column_expand(1, false); - counters_display->set_column_min_width(1, 120 * EDSCALE); + counters_display->set_column_clip_content(1, true); + counters_display->set_column_custom_minimum_width(1, 120 * EDSCALE); counters_display->set_column_title(2, TTR("Incoming RSET")); counters_display->set_column_expand(2, false); - counters_display->set_column_min_width(2, 120 * EDSCALE); + counters_display->set_column_clip_content(2, true); + counters_display->set_column_custom_minimum_width(2, 120 * EDSCALE); counters_display->set_column_title(3, TTR("Outgoing RPC")); counters_display->set_column_expand(3, false); - counters_display->set_column_min_width(3, 120 * EDSCALE); + counters_display->set_column_clip_content(3, true); + counters_display->set_column_custom_minimum_width(3, 120 * EDSCALE); counters_display->set_column_title(4, TTR("Outgoing RSET")); counters_display->set_column_expand(4, false); - counters_display->set_column_min_width(4, 120 * EDSCALE); + counters_display->set_column_clip_content(4, true); + counters_display->set_column_custom_minimum_width(4, 120 * EDSCALE); add_child(counters_display); frame_delay = memnew(Timer); diff --git a/editor/debugger/editor_profiler.cpp b/editor/debugger/editor_profiler.cpp index d60e2783ec..5f4d1b6f36 100644 --- a/editor/debugger/editor_profiler.cpp +++ b/editor/debugger/editor_profiler.cpp @@ -305,17 +305,17 @@ void EditorProfiler::_update_plot() { } Ref<Image> img; - img.instance(); + img.instantiate(); img->create(w, h, false, Image::FORMAT_RGBA8, graph_image); if (reset_texture) { if (graph_texture.is_null()) { - graph_texture.instance(); + graph_texture.instantiate(); } graph_texture->create_from_image(img); } - graph_texture->update(img, true); + graph_texture->update(img); graph->set_texture(graph_texture); graph->update(); @@ -631,13 +631,16 @@ EditorProfiler::EditorProfiler() { variables->set_column_titles_visible(true); variables->set_column_title(0, TTR("Name")); variables->set_column_expand(0, true); - variables->set_column_min_width(0, 60 * EDSCALE); + variables->set_column_clip_content(0, true); + variables->set_column_expand_ratio(0, 60); variables->set_column_title(1, TTR("Time")); variables->set_column_expand(1, false); - variables->set_column_min_width(1, 100 * EDSCALE); + variables->set_column_clip_content(1, true); + variables->set_column_expand_ratio(1, 100); variables->set_column_title(2, TTR("Calls")); variables->set_column_expand(2, false); - variables->set_column_min_width(2, 60 * EDSCALE); + variables->set_column_clip_content(2, true); + variables->set_column_expand_ratio(2, 60); variables->connect("item_edited", callable_mp(this, &EditorProfiler::_item_edited)); graph = memnew(TextureRect); diff --git a/editor/debugger/editor_visual_profiler.cpp b/editor/debugger/editor_visual_profiler.cpp index 5bb10b3794..a0e8a3bd35 100644 --- a/editor/debugger/editor_visual_profiler.cpp +++ b/editor/debugger/editor_visual_profiler.cpp @@ -299,17 +299,17 @@ void EditorVisualProfiler::_update_plot() { } Ref<Image> img; - img.instance(); + img.instantiate(); img->create(w, h, false, Image::FORMAT_RGBA8, graph_image); if (reset_texture) { if (graph_texture.is_null()) { - graph_texture.instance(); + graph_texture.instantiate(); } graph_texture->create_from_image(img); } - graph_texture->update(img, true); + graph_texture->update(img); graph->set_texture(graph_texture); graph->update(); @@ -773,13 +773,16 @@ EditorVisualProfiler::EditorVisualProfiler() { variables->set_column_titles_visible(true); variables->set_column_title(0, TTR("Name")); variables->set_column_expand(0, true); - variables->set_column_min_width(0, 60); + variables->set_column_clip_content(0, true); + variables->set_column_custom_minimum_width(0, 60); variables->set_column_title(1, TTR("CPU")); variables->set_column_expand(1, false); - variables->set_column_min_width(1, 60 * EDSCALE); + variables->set_column_clip_content(1, true); + variables->set_column_custom_minimum_width(1, 60 * EDSCALE); variables->set_column_title(2, TTR("GPU")); variables->set_column_expand(2, false); - variables->set_column_min_width(2, 60 * EDSCALE); + variables->set_column_clip_content(2, true); + variables->set_column_custom_minimum_width(2, 60 * EDSCALE); variables->connect("cell_selected", callable_mp(this, &EditorVisualProfiler::_item_selected)); graph = memnew(TextureRect); diff --git a/editor/debugger/script_editor_debugger.cpp b/editor/debugger/script_editor_debugger.cpp index 7493cc2a8d..b877ab030f 100644 --- a/editor/debugger/script_editor_debugger.cpp +++ b/editor/debugger/script_editor_debugger.cpp @@ -1643,9 +1643,11 @@ ScriptEditorDebugger::ScriptEditorDebugger(EditorNode *p_editor) { error_tree->set_columns(2); error_tree->set_column_expand(0, false); - error_tree->set_column_min_width(0, 140); + error_tree->set_column_custom_minimum_width(0, 140); + error_tree->set_column_clip_content(0, true); error_tree->set_column_expand(1, true); + error_tree->set_column_clip_content(1, true); error_tree->set_select_mode(Tree::SELECT_ROW); error_tree->set_hide_root(true); @@ -1731,13 +1733,13 @@ ScriptEditorDebugger::ScriptEditorDebugger(EditorNode *p_editor) { vmem_tree->set_column_expand(0, true); vmem_tree->set_column_expand(1, false); vmem_tree->set_column_title(1, TTR("Type")); - vmem_tree->set_column_min_width(1, 100 * EDSCALE); + vmem_tree->set_column_custom_minimum_width(1, 100 * EDSCALE); vmem_tree->set_column_expand(2, false); vmem_tree->set_column_title(2, TTR("Format")); - vmem_tree->set_column_min_width(2, 150 * EDSCALE); + vmem_tree->set_column_custom_minimum_width(2, 150 * EDSCALE); vmem_tree->set_column_expand(3, false); vmem_tree->set_column_title(3, TTR("Usage")); - vmem_tree->set_column_min_width(3, 80 * EDSCALE); + vmem_tree->set_column_custom_minimum_width(3, 80 * EDSCALE); vmem_tree->set_hide_root(true); tabs->add_child(vmem_vb); diff --git a/editor/dependency_editor.cpp b/editor/dependency_editor.cpp index 7534b419fe..ef571e5c7a 100644 --- a/editor/dependency_editor.cpp +++ b/editor/dependency_editor.cpp @@ -226,7 +226,11 @@ DependencyEditor::DependencyEditor() { tree->set_columns(2); tree->set_column_titles_visible(true); tree->set_column_title(0, TTR("Resource")); + tree->set_column_clip_content(0, true); + tree->set_column_expand_ratio(0, 2); tree->set_column_title(1, TTR("Path")); + tree->set_column_clip_content(1, true); + tree->set_column_expand_ratio(1, 1); tree->set_hide_root(true); tree->connect("button_pressed", callable_mp(this, &DependencyEditor::_load_pressed)); @@ -769,9 +773,11 @@ OrphanResourcesDialog::OrphanResourcesDialog() { files = memnew(Tree); files->set_columns(2); files->set_column_titles_visible(true); - files->set_column_min_width(1, 100); + files->set_column_custom_minimum_width(1, 100 * EDSCALE); files->set_column_expand(0, true); + files->set_column_clip_content(0, true); files->set_column_expand(1, false); + files->set_column_clip_content(1, true); files->set_column_title(0, TTR("Resource")); files->set_column_title(1, TTR("Owns")); files->set_hide_root(true); diff --git a/editor/doc_tools.cpp b/editor/doc_tools.cpp index d3df4d91a6..befafec6cb 100644 --- a/editor/doc_tools.cpp +++ b/editor/doc_tools.cpp @@ -206,14 +206,14 @@ static Variant get_documentation_default_value(const StringName &p_class_name, c Variant default_value = Variant(); r_default_value_valid = false; - if (ClassDB::can_instance(p_class_name)) { + if (ClassDB::can_instantiate(p_class_name)) { default_value = ClassDB::class_get_default_property_value(p_class_name, p_property_name, &r_default_value_valid); } else { - // Cannot get default value of classes that can't be instanced + // Cannot get default value of classes that can't be instantiated List<StringName> inheriting_classes; ClassDB::get_direct_inheriters_from_class(p_class_name, &inheriting_classes); for (List<StringName>::Element *E2 = inheriting_classes.front(); E2; E2 = E2->next()) { - if (ClassDB::can_instance(E2->get())) { + if (ClassDB::can_instantiate(E2->get())) { default_value = ClassDB::class_get_default_property_value(E2->get(), p_property_name, &r_default_value_valid); if (r_default_value_valid) { break; diff --git a/editor/editor_asset_installer.cpp b/editor/editor_asset_installer.cpp index 38f417a8ce..83319ee5a5 100644 --- a/editor/editor_asset_installer.cpp +++ b/editor/editor_asset_installer.cpp @@ -132,14 +132,54 @@ void EditorAssetInstaller::open(const String &p_path, int p_depth) { Map<String, Ref<Texture2D>> extension_guess; { - extension_guess["png"] = tree->get_theme_icon("ImageTexture", "EditorIcons"); + extension_guess["bmp"] = tree->get_theme_icon("ImageTexture", "EditorIcons"); + extension_guess["dds"] = tree->get_theme_icon("ImageTexture", "EditorIcons"); + extension_guess["exr"] = tree->get_theme_icon("ImageTexture", "EditorIcons"); + extension_guess["hdr"] = tree->get_theme_icon("ImageTexture", "EditorIcons"); extension_guess["jpg"] = tree->get_theme_icon("ImageTexture", "EditorIcons"); - extension_guess["atlastex"] = tree->get_theme_icon("AtlasTexture", "EditorIcons"); + extension_guess["jpeg"] = tree->get_theme_icon("ImageTexture", "EditorIcons"); + extension_guess["png"] = tree->get_theme_icon("ImageTexture", "EditorIcons"); + extension_guess["svg"] = tree->get_theme_icon("ImageTexture", "EditorIcons"); + extension_guess["svgz"] = tree->get_theme_icon("ImageTexture", "EditorIcons"); + extension_guess["tga"] = tree->get_theme_icon("ImageTexture", "EditorIcons"); + extension_guess["webp"] = tree->get_theme_icon("ImageTexture", "EditorIcons"); + + extension_guess["wav"] = tree->get_theme_icon("AudioStreamSample", "EditorIcons"); + extension_guess["ogg"] = tree->get_theme_icon("AudioStreamOGGVorbis", "EditorIcons"); + extension_guess["mp3"] = tree->get_theme_icon("AudioStreamMP3", "EditorIcons"); + extension_guess["scn"] = tree->get_theme_icon("PackedScene", "EditorIcons"); extension_guess["tscn"] = tree->get_theme_icon("PackedScene", "EditorIcons"); + extension_guess["escn"] = tree->get_theme_icon("PackedScene", "EditorIcons"); + extension_guess["dae"] = tree->get_theme_icon("PackedScene", "EditorIcons"); + extension_guess["gltf"] = tree->get_theme_icon("PackedScene", "EditorIcons"); + extension_guess["glb"] = tree->get_theme_icon("PackedScene", "EditorIcons"); + extension_guess["gdshader"] = tree->get_theme_icon("Shader", "EditorIcons"); extension_guess["gd"] = tree->get_theme_icon("GDScript", "EditorIcons"); + if (Engine::get_singleton()->has_singleton("GodotSharp")) { + extension_guess["cs"] = tree->get_theme_icon("CSharpScript", "EditorIcons"); + } else { + // Mark C# support as unavailable. + extension_guess["cs"] = tree->get_theme_icon("ImportFail", "EditorIcons"); + } extension_guess["vs"] = tree->get_theme_icon("VisualScript", "EditorIcons"); + + extension_guess["res"] = tree->get_theme_icon("Resource", "EditorIcons"); + extension_guess["tres"] = tree->get_theme_icon("Resource", "EditorIcons"); + extension_guess["atlastex"] = tree->get_theme_icon("AtlasTexture", "EditorIcons"); + // By default, OBJ files are imported as Mesh resources rather than PackedScenes. + extension_guess["obj"] = tree->get_theme_icon("Mesh", "EditorIcons"); + + extension_guess["txt"] = tree->get_theme_icon("TextFile", "EditorIcons"); + extension_guess["md"] = tree->get_theme_icon("TextFile", "EditorIcons"); + extension_guess["rst"] = tree->get_theme_icon("TextFile", "EditorIcons"); + extension_guess["json"] = tree->get_theme_icon("TextFile", "EditorIcons"); + extension_guess["yml"] = tree->get_theme_icon("TextFile", "EditorIcons"); + extension_guess["yaml"] = tree->get_theme_icon("TextFile", "EditorIcons"); + extension_guess["toml"] = tree->get_theme_icon("TextFile", "EditorIcons"); + extension_guess["cfg"] = tree->get_theme_icon("TextFile", "EditorIcons"); + extension_guess["ini"] = tree->get_theme_icon("TextFile", "EditorIcons"); } Ref<Texture2D> generic_extension = tree->get_theme_icon("Object", "EditorIcons"); diff --git a/editor/editor_atlas_packer.cpp b/editor/editor_atlas_packer.cpp index 1b4a505edb..85541c093a 100644 --- a/editor/editor_atlas_packer.cpp +++ b/editor/editor_atlas_packer.cpp @@ -105,7 +105,7 @@ void EditorAtlasPacker::chart_pack(Vector<Chart> &charts, int &r_width, int &r_h } Ref<BitMap> src_bitmap; - src_bitmap.instance(); + src_bitmap.instantiate(); src_bitmap->create(aabb.size / divide_by); int w = src_bitmap->get_size().width; diff --git a/editor/editor_audio_buses.cpp b/editor/editor_audio_buses.cpp index e08334c00e..3e3428ad93 100644 --- a/editor/editor_audio_buses.cpp +++ b/editor/editor_audio_buses.cpp @@ -525,7 +525,7 @@ void EditorAudioBus::_effect_add(int p_which) { StringName name = effect_options->get_item_metadata(p_which); - Object *fx = ClassDB::instance(name); + Object *fx = ClassDB::instantiate(name); ERR_FAIL_COND(!fx); AudioEffect *afx = Object::cast_to<AudioEffect>(fx); ERR_FAIL_COND(!afx); @@ -921,7 +921,7 @@ EditorAudioBus::EditorAudioBus(EditorAudioBuses *p_buses, bool p_is_master) { ClassDB::get_inheriters_from_class("AudioEffect", &effects); effects.sort_custom<StringName::AlphCompare>(); for (List<StringName>::Element *E = effects.front(); E; E = E->next()) { - if (!ClassDB::can_instance(E->get())) { + if (!ClassDB::can_instantiate(E->get())) { continue; } @@ -1238,7 +1238,7 @@ void EditorAudioBuses::_file_dialog_callback(const String &p_string) { } else if (file_dialog->get_file_mode() == EditorFileDialog::FILE_MODE_SAVE_FILE) { if (new_layout) { Ref<AudioBusLayout> empty_state; - empty_state.instance(); + empty_state.instantiate(); AudioServer::get_singleton()->set_bus_layout(empty_state); } diff --git a/editor/editor_autoload_settings.cpp b/editor/editor_autoload_settings.cpp index 304c2fe532..12ae55fbc1 100644 --- a/editor/editor_autoload_settings.cpp +++ b/editor/editor_autoload_settings.cpp @@ -349,14 +349,14 @@ Node *EditorAutoloadSettings::_create_autoload(const String &p_path) { Node *n = nullptr; if (res->is_class("PackedScene")) { Ref<PackedScene> ps = res; - n = ps->instance(); + n = ps->instantiate(); } else if (res->is_class("Script")) { Ref<Script> s = res; StringName ibt = s->get_instance_base_type(); bool valid_type = ClassDB::is_parent_class(ibt, "Node"); ERR_FAIL_COND_V_MSG(!valid_type, nullptr, "Script does not inherit a Node: " + p_path + "."); - Object *obj = ClassDB::instance(ibt); + Object *obj = ClassDB::instantiate(ibt); ERR_FAIL_COND_V_MSG(obj == nullptr, nullptr, "Cannot instance script for autoload, expected 'Node' inheritance, got: " + String(ibt) + "."); @@ -882,19 +882,17 @@ EditorAutoloadSettings::EditorAutoloadSettings() { tree->set_column_title(0, TTR("Name")); tree->set_column_expand(0, true); - tree->set_column_min_width(0, 100 * EDSCALE); + tree->set_column_expand_ratio(0, 1); tree->set_column_title(1, TTR("Path")); tree->set_column_expand(1, true); - tree->set_column_min_width(1, 100 * EDSCALE); + tree->set_column_clip_content(1, true); + tree->set_column_expand_ratio(1, 2); tree->set_column_title(2, TTR("Global Variable")); tree->set_column_expand(2, false); - // Reserve enough space for translations of "Global Variable" which may be longer. - tree->set_column_min_width(2, 150 * EDSCALE); tree->set_column_expand(3, false); - tree->set_column_min_width(3, 120 * EDSCALE); tree->connect("cell_selected", callable_mp(this, &EditorAutoloadSettings::_autoload_selected)); tree->connect("item_edited", callable_mp(this, &EditorAutoloadSettings::_autoload_edited)); diff --git a/editor/editor_data.cpp b/editor/editor_data.cpp index 56c6a416af..3823d7e14f 100644 --- a/editor/editor_data.cpp +++ b/editor/editor_data.cpp @@ -476,7 +476,7 @@ Variant EditorData::instance_custom_type(const String &p_type, const String &p_i if (get_custom_types()[p_inherits][i].name == p_type) { Ref<Script> script = get_custom_types()[p_inherits][i].script; - Variant ob = ClassDB::instance(p_inherits); + Variant ob = ClassDB::instantiate(p_inherits); ERR_FAIL_COND_V(!ob, Variant()); Node *n = Object::cast_to<Node>(ob); if (n) { @@ -603,7 +603,7 @@ bool EditorData::check_and_update_scene(int p_idx) { if (must_reload) { Ref<PackedScene> pscene; - pscene.instance(); + pscene.instantiate(); EditorProgress ep("update_scene", TTR("Updating Scene"), 2); ep.step(TTR("Storing local changes..."), 0); @@ -611,7 +611,7 @@ bool EditorData::check_and_update_scene(int p_idx) { Error err = pscene->pack(edited_scene[p_idx].root); ERR_FAIL_COND_V(err != OK, false); ep.step(TTR("Updating scene..."), 1); - Node *new_scene = pscene->instance(PackedScene::GEN_EDIT_STATE_MAIN); + Node *new_scene = pscene->instantiate(PackedScene::GEN_EDIT_STATE_MAIN); ERR_FAIL_COND_V(!new_scene, false); //transfer selection @@ -908,7 +908,7 @@ StringName EditorData::script_class_get_base(const String &p_class) const { Variant EditorData::script_class_instance(const String &p_class) { if (ScriptServer::is_global_class(p_class)) { - Variant obj = ClassDB::instance(ScriptServer::get_global_class_native_base(p_class)); + Variant obj = ClassDB::instantiate(ScriptServer::get_global_class_native_base(p_class)); if (obj) { Ref<Script> script = script_class_load_script(p_class); if (script.is_valid()) { diff --git a/editor/editor_export.cpp b/editor/editor_export.cpp index 7c5a06107d..fc483b46b7 100644 --- a/editor/editor_export.cpp +++ b/editor/editor_export.cpp @@ -430,7 +430,7 @@ bool EditorExportPlatform::exists_export_template(String template_file_name, Str Ref<EditorExportPreset> EditorExportPlatform::create_preset() { Ref<EditorExportPreset> preset; - preset.instance(); + preset.instantiate(); preset->platform = Ref<EditorExportPlatform>(this); List<ExportOption> options; @@ -873,7 +873,7 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> & if (FileAccess::exists(path + ".import")) { //file is imported, replace by what it imports Ref<ConfigFile> config; - config.instance(); + config.instantiate(); err = config->load(path + ".import"); if (err != OK) { ERR_PRINT("Could not parse: '" + path + "', not exported."); @@ -1391,7 +1391,7 @@ EditorExport *EditorExport::singleton = nullptr; void EditorExport::_save() { Ref<ConfigFile> config; - config.instance(); + config.instantiate(); for (int i = 0; i < export_presets.size(); i++) { Ref<EditorExportPreset> preset = export_presets[i]; String section = "preset." + itos(i); @@ -1546,7 +1546,7 @@ void EditorExport::_notification(int p_what) { void EditorExport::load_config() { Ref<ConfigFile> config; - config.instance(); + config.instantiate(); Error err = config->load("res://export_presets.cfg"); if (err != OK) { return; diff --git a/editor/editor_feature_profile.cpp b/editor/editor_feature_profile.cpp index 51c6b473ad..58d2b6e86e 100644 --- a/editor/editor_feature_profile.cpp +++ b/editor/editor_feature_profile.cpp @@ -161,21 +161,21 @@ String EditorFeatureProfile::get_feature_description(Feature p_feature) { } Error EditorFeatureProfile::save_to_file(const String &p_path) { - Dictionary json; - json["type"] = "feature_profile"; + Dictionary data; + data["type"] = "feature_profile"; Array dis_classes; for (Set<StringName>::Element *E = disabled_classes.front(); E; E = E->next()) { dis_classes.push_back(String(E->get())); } dis_classes.sort(); - json["disabled_classes"] = dis_classes; + data["disabled_classes"] = dis_classes; Array dis_editors; for (Set<StringName>::Element *E = disabled_editors.front(); E; E = E->next()) { dis_editors.push_back(String(E->get())); } dis_editors.sort(); - json["disabled_editors"] = dis_editors; + data["disabled_editors"] = dis_editors; Array dis_props; @@ -185,7 +185,7 @@ Error EditorFeatureProfile::save_to_file(const String &p_path) { } } - json["disabled_properties"] = dis_props; + data["disabled_properties"] = dis_props; Array dis_features; for (int i = 0; i < FEATURE_MAX; i++) { @@ -194,12 +194,13 @@ Error EditorFeatureProfile::save_to_file(const String &p_path) { } } - json["disabled_features"] = dis_features; + data["disabled_features"] = dis_features; FileAccessRef f = FileAccess::open(p_path, FileAccess::WRITE); ERR_FAIL_COND_V_MSG(!f, ERR_CANT_CREATE, "Cannot create file '" + p_path + "'."); - String text = JSON::print(json, "\t"); + JSON json; + String text = json.stringify(data, "\t"); f->store_string(text); f->close(); return OK; @@ -212,26 +213,24 @@ Error EditorFeatureProfile::load_from_file(const String &p_path) { return err; } - String err_str; - int err_line; - Variant v; - err = JSON::parse(text, v, err_str, err_line); + JSON json; + err = json.parse(text); if (err != OK) { - ERR_PRINT("Error parsing '" + p_path + "' on line " + itos(err_line) + ": " + err_str); + ERR_PRINT("Error parsing '" + p_path + "' on line " + itos(json.get_error_line()) + ": " + json.get_error_message()); return ERR_PARSE_ERROR; } - Dictionary json = v; + Dictionary data = json.get_data(); - if (!json.has("type") || String(json["type"]) != "feature_profile") { + if (!data.has("type") || String(data["type"]) != "feature_profile") { ERR_PRINT("Error parsing '" + p_path + "', it's not a feature profile."); return ERR_PARSE_ERROR; } disabled_classes.clear(); - if (json.has("disabled_classes")) { - Array disabled_classes_arr = json["disabled_classes"]; + if (data.has("disabled_classes")) { + Array disabled_classes_arr = data["disabled_classes"]; for (int i = 0; i < disabled_classes_arr.size(); i++) { disabled_classes.insert(disabled_classes_arr[i]); } @@ -239,8 +238,8 @@ Error EditorFeatureProfile::load_from_file(const String &p_path) { disabled_editors.clear(); - if (json.has("disabled_editors")) { - Array disabled_editors_arr = json["disabled_editors"]; + if (data.has("disabled_editors")) { + Array disabled_editors_arr = data["disabled_editors"]; for (int i = 0; i < disabled_editors_arr.size(); i++) { disabled_editors.insert(disabled_editors_arr[i]); } @@ -248,16 +247,16 @@ Error EditorFeatureProfile::load_from_file(const String &p_path) { disabled_properties.clear(); - if (json.has("disabled_properties")) { - Array disabled_properties_arr = json["disabled_properties"]; + if (data.has("disabled_properties")) { + Array disabled_properties_arr = data["disabled_properties"]; for (int i = 0; i < disabled_properties_arr.size(); i++) { String s = disabled_properties_arr[i]; set_disable_class_property(s.get_slice(":", 0), s.get_slice(":", 1), true); } } - if (json.has("disabled_features")) { - Array disabled_features_arr = json["disabled_features"]; + if (data.has("disabled_features")) { + Array disabled_features_arr = data["disabled_features"]; for (int i = 0; i < FEATURE_MAX; i++) { bool found = false; String f = feature_identifiers[i]; @@ -312,7 +311,7 @@ void EditorFeatureProfileManager::_notification(int p_what) { if (p_what == NOTIFICATION_READY) { current_profile = EDITOR_GET("_default_feature_profile"); if (current_profile != String()) { - current.instance(); + current.instantiate(); Error err = current->load_from_file(EditorSettings::get_singleton()->get_feature_profiles_dir().plus_file(current_profile + ".profile")); if (err != OK) { ERR_PRINT("Error loading default feature profile: " + current_profile); @@ -474,7 +473,7 @@ void EditorFeatureProfileManager::_create_new_profile() { } Ref<EditorFeatureProfile> new_profile; - new_profile.instance(); + new_profile.instantiate(); new_profile->save_to_file(file); _update_profile_list(name); @@ -731,7 +730,7 @@ void EditorFeatureProfileManager::_update_selected_profile() { ERR_FAIL_COND(current.is_null()); //nothing selected, current should never be null } else { //reload edited, if different from current - edited.instance(); + edited.instantiate(); Error err = edited->load_from_file(EditorSettings::get_singleton()->get_feature_profiles_dir().plus_file(profile + ".profile")); ERR_FAIL_COND_MSG(err != OK, "Error when loading EditorSettings from file '" + EditorSettings::get_singleton()->get_feature_profiles_dir().plus_file(profile + ".profile") + "'."); } @@ -780,7 +779,7 @@ void EditorFeatureProfileManager::_import_profiles(const Vector<String> &p_paths //test it first for (int i = 0; i < p_paths.size(); i++) { Ref<EditorFeatureProfile> profile; - profile.instance(); + profile.instantiate(); Error err = profile->load_from_file(p_paths[i]); String basefile = p_paths[i].get_file(); if (err != OK) { @@ -799,7 +798,7 @@ void EditorFeatureProfileManager::_import_profiles(const Vector<String> &p_paths //do it second for (int i = 0; i < p_paths.size(); i++) { Ref<EditorFeatureProfile> profile; - profile.instance(); + profile.instantiate(); Error err = profile->load_from_file(p_paths[i]); ERR_CONTINUE(err != OK); String basefile = p_paths[i].get_file(); diff --git a/editor/editor_file_dialog.cpp b/editor/editor_file_dialog.cpp index f3cee7576d..fe4c6f490d 100644 --- a/editor/editor_file_dialog.cpp +++ b/editor/editor_file_dialog.cpp @@ -1544,7 +1544,7 @@ EditorFileDialog::EditorFileDialog() { pathhb->add_child(memnew(VSeparator)); Ref<ButtonGroup> view_mode_group; - view_mode_group.instance(); + view_mode_group.instantiate(); mode_thumbnails = memnew(Button); mode_thumbnails->set_flat(true); diff --git a/editor/editor_file_system.cpp b/editor/editor_file_system.cpp index 3f715c1f93..a2507f3cf2 100644 --- a/editor/editor_file_system.cpp +++ b/editor/editor_file_system.cpp @@ -1524,7 +1524,7 @@ Error EditorFileSystem::_reimport_group(const String &p_group_file, const Vector Map<String, String> base_paths; for (int i = 0; i < p_files.size(); i++) { Ref<ConfigFile> config; - config.instance(); + config.instantiate(); Error err = config->load(p_files[i] + ".import"); ERR_CONTINUE(err != OK); ERR_CONTINUE(!config->has_section_key("remap", "importer")); @@ -1706,7 +1706,7 @@ void EditorFileSystem::_reimport_file(const String &p_file, const Map<StringName //use existing if (p_custom_options == nullptr) { Ref<ConfigFile> cf; - cf.instance(); + cf.instantiate(); Error err = cf->load(p_file + ".import"); if (err == OK) { if (cf->has_section("params")) { @@ -2068,7 +2068,7 @@ void EditorFileSystem::_move_group_files(EditorFileSystemDirectory *efd, const S files[i]->import_group_file = p_new_location; Ref<ConfigFile> config; - config.instance(); + config.instantiate(); String path = efd->get_file_path(i) + ".import"; Error err = config->load(path); if (err != OK) { diff --git a/editor/editor_folding.cpp b/editor/editor_folding.cpp index 4030aecbf5..5d6c415d39 100644 --- a/editor/editor_folding.cpp +++ b/editor/editor_folding.cpp @@ -50,7 +50,7 @@ Vector<String> EditorFolding::_get_unfolds(const Object *p_object) { void EditorFolding::save_resource_folding(const RES &p_resource, const String &p_path) { Ref<ConfigFile> config; - config.instance(); + config.instantiate(); Vector<String> unfolds = _get_unfolds(p_resource.ptr()); config->set_value("folding", "sections_unfolded", unfolds); @@ -70,7 +70,7 @@ void EditorFolding::_set_unfolds(Object *p_object, const Vector<String> &p_unfol void EditorFolding::load_resource_folding(RES p_resource, const String &p_path) { Ref<ConfigFile> config; - config.instance(); + config.instantiate(); String file = p_path.get_file() + "-folding-" + p_path.md5_text() + ".cfg"; file = EditorSettings::get_singleton()->get_project_settings_dir().plus_file(file); @@ -137,7 +137,7 @@ void EditorFolding::save_scene_folding(const Node *p_scene, const String &p_path } Ref<ConfigFile> config; - config.instance(); + config.instantiate(); Array unfolds, res_unfolds; Set<RES> resources; @@ -155,7 +155,7 @@ void EditorFolding::save_scene_folding(const Node *p_scene, const String &p_path void EditorFolding::load_scene_folding(Node *p_scene, const String &p_path) { Ref<ConfigFile> config; - config.instance(); + config.instantiate(); String path = EditorSettings::get_singleton()->get_project_settings_dir(); String file = p_path.get_file() + "-folding-" + p_path.md5_text() + ".cfg"; diff --git a/editor/editor_fonts.cpp b/editor/editor_fonts.cpp index 2f5451fba3..d548196a2d 100644 --- a/editor/editor_fonts.cpp +++ b/editor/editor_fonts.cpp @@ -55,7 +55,7 @@ // the custom spacings might only work with Noto Sans #define MAKE_DEFAULT_FONT(m_name) \ Ref<Font> m_name; \ - m_name.instance(); \ + m_name.instantiate(); \ if (CustomFont.is_valid()) { \ m_name->add_data(CustomFont); \ m_name->add_data(DefaultFont); \ @@ -68,7 +68,7 @@ #define MAKE_BOLD_FONT(m_name) \ Ref<Font> m_name; \ - m_name.instance(); \ + m_name.instantiate(); \ if (CustomFontBold.is_valid()) { \ m_name->add_data(CustomFontBold); \ m_name->add_data(DefaultFontBold); \ @@ -81,7 +81,7 @@ #define MAKE_SOURCE_FONT(m_name) \ Ref<Font> m_name; \ - m_name.instance(); \ + m_name.instantiate(); \ if (CustomFontSource.is_valid()) { \ m_name->add_data(CustomFontSource); \ m_name->add_data(dfmono); \ @@ -129,7 +129,7 @@ void editor_register_fonts(Ref<Theme> p_theme) { String custom_font_path = EditorSettings::get_singleton()->get("interface/editor/main_font"); Ref<FontData> CustomFont; if (custom_font_path.length() > 0 && dir->file_exists(custom_font_path)) { - CustomFont.instance(); + CustomFont.instantiate(); CustomFont->load_resource(custom_font_path, default_font_size); CustomFont->set_antialiased(font_antialiased); CustomFont->set_hinting(font_hinting); @@ -143,7 +143,7 @@ void editor_register_fonts(Ref<Theme> p_theme) { String custom_font_path_bold = EditorSettings::get_singleton()->get("interface/editor/main_font_bold"); Ref<FontData> CustomFontBold; if (custom_font_path_bold.length() > 0 && dir->file_exists(custom_font_path_bold)) { - CustomFontBold.instance(); + CustomFontBold.instantiate(); CustomFontBold->load_resource(custom_font_path_bold, default_font_size); CustomFontBold->set_antialiased(font_antialiased); CustomFontBold->set_hinting(font_hinting); @@ -157,7 +157,7 @@ void editor_register_fonts(Ref<Theme> p_theme) { String custom_font_path_source = EditorSettings::get_singleton()->get("interface/editor/code_font"); Ref<FontData> CustomFontSource; if (custom_font_path_source.length() > 0 && dir->file_exists(custom_font_path_source)) { - CustomFontSource.instance(); + CustomFontSource.instantiate(); CustomFontSource->load_resource(custom_font_path_source, default_font_size); CustomFontSource->set_antialiased(font_antialiased); CustomFontSource->set_hinting(font_hinting); @@ -178,105 +178,105 @@ void editor_register_fonts(Ref<Theme> p_theme) { /* Droid Sans */ Ref<FontData> DefaultFont; - DefaultFont.instance(); + DefaultFont.instantiate(); DefaultFont->load_memory(_font_NotoSansUI_Regular, _font_NotoSansUI_Regular_size, "ttf", default_font_size); DefaultFont->set_antialiased(font_antialiased); DefaultFont->set_hinting(font_hinting); DefaultFont->set_force_autohinter(true); //just looks better..i think? Ref<FontData> DefaultFontBold; - DefaultFontBold.instance(); + DefaultFontBold.instantiate(); DefaultFontBold->load_memory(_font_NotoSansUI_Bold, _font_NotoSansUI_Bold_size, "ttf", default_font_size); DefaultFontBold->set_antialiased(font_antialiased); DefaultFontBold->set_hinting(font_hinting); DefaultFontBold->set_force_autohinter(true); // just looks better..i think? Ref<FontData> FontFallback; - FontFallback.instance(); + FontFallback.instantiate(); FontFallback->load_memory(_font_DroidSansFallback, _font_DroidSansFallback_size, "ttf", default_font_size); FontFallback->set_antialiased(font_antialiased); FontFallback->set_hinting(font_hinting); FontFallback->set_force_autohinter(true); //just looks better..i think? Ref<FontData> FontJapanese; - FontJapanese.instance(); + FontJapanese.instantiate(); FontJapanese->load_memory(_font_DroidSansJapanese, _font_DroidSansJapanese_size, "ttf", default_font_size); FontJapanese->set_antialiased(font_antialiased); FontJapanese->set_hinting(font_hinting); FontJapanese->set_force_autohinter(true); //just looks better..i think? Ref<FontData> FontArabic; - FontArabic.instance(); + FontArabic.instantiate(); FontArabic->load_memory(_font_NotoNaskhArabicUI_Regular, _font_NotoNaskhArabicUI_Regular_size, "ttf", default_font_size); FontArabic->set_antialiased(font_antialiased); FontArabic->set_hinting(font_hinting); FontArabic->set_force_autohinter(true); //just looks better..i think? Ref<FontData> FontBengali; - FontBengali.instance(); + FontBengali.instantiate(); FontBengali->load_memory(_font_NotoSansBengali_Regular, _font_NotoSansBengali_Regular_size, "ttf", default_font_size); FontBengali->set_antialiased(font_antialiased); FontBengali->set_hinting(font_hinting); FontBengali->set_force_autohinter(true); //just looks better..i think? Ref<FontData> FontGeorgian; - FontGeorgian.instance(); + FontGeorgian.instantiate(); FontGeorgian->load_memory(_font_NotoSansGeorgian_Regular, _font_NotoSansGeorgian_Regular_size, "ttf", default_font_size); FontGeorgian->set_antialiased(font_antialiased); FontGeorgian->set_hinting(font_hinting); FontGeorgian->set_force_autohinter(true); //just looks better..i think? Ref<FontData> FontHebrew; - FontHebrew.instance(); + FontHebrew.instantiate(); FontHebrew->load_memory(_font_NotoSansHebrew_Regular, _font_NotoSansHebrew_Regular_size, "ttf", default_font_size); FontHebrew->set_antialiased(font_antialiased); FontHebrew->set_hinting(font_hinting); FontHebrew->set_force_autohinter(true); //just looks better..i think? Ref<FontData> FontMalayalam; - FontMalayalam.instance(); + FontMalayalam.instantiate(); FontMalayalam->load_memory(_font_NotoSansMalayalamUI_Regular, _font_NotoSansMalayalamUI_Regular_size, "ttf", default_font_size); FontMalayalam->set_antialiased(font_antialiased); FontMalayalam->set_hinting(font_hinting); FontMalayalam->set_force_autohinter(true); //just looks better..i think? Ref<FontData> FontOriya; - FontOriya.instance(); + FontOriya.instantiate(); FontOriya->load_memory(_font_NotoSansOriyaUI_Regular, _font_NotoSansOriyaUI_Regular_size, "ttf", default_font_size); FontOriya->set_antialiased(font_antialiased); FontOriya->set_hinting(font_hinting); FontOriya->set_force_autohinter(true); //just looks better..i think? Ref<FontData> FontSinhala; - FontSinhala.instance(); + FontSinhala.instantiate(); FontSinhala->load_memory(_font_NotoSansSinhalaUI_Regular, _font_NotoSansSinhalaUI_Regular_size, "ttf", default_font_size); FontSinhala->set_antialiased(font_antialiased); FontSinhala->set_hinting(font_hinting); FontSinhala->set_force_autohinter(true); //just looks better..i think? Ref<FontData> FontTamil; - FontTamil.instance(); + FontTamil.instantiate(); FontTamil->load_memory(_font_NotoSansTamilUI_Regular, _font_NotoSansTamilUI_Regular_size, "ttf", default_font_size); FontTamil->set_antialiased(font_antialiased); FontTamil->set_hinting(font_hinting); FontTamil->set_force_autohinter(true); //just looks better..i think? Ref<FontData> FontTelugu; - FontTelugu.instance(); + FontTelugu.instantiate(); FontTelugu->load_memory(_font_NotoSansTeluguUI_Regular, _font_NotoSansTeluguUI_Regular_size, "ttf", default_font_size); FontTelugu->set_antialiased(font_antialiased); FontTelugu->set_hinting(font_hinting); FontTelugu->set_force_autohinter(true); //just looks better..i think? Ref<FontData> FontThai; - FontThai.instance(); + FontThai.instantiate(); FontThai->load_memory(_font_NotoSansThaiUI_Regular, _font_NotoSansThaiUI_Regular_size, "ttf", default_font_size); FontThai->set_antialiased(font_antialiased); FontThai->set_hinting(font_hinting); FontThai->set_force_autohinter(true); //just looks better..i think? Ref<FontData> FontHindi; - FontHindi.instance(); + FontHindi.instantiate(); FontHindi->load_memory(_font_NotoSansDevanagariUI_Regular, _font_NotoSansDevanagariUI_Regular_size, "ttf", default_font_size); FontHindi->set_antialiased(font_antialiased); FontHindi->set_hinting(font_hinting); @@ -285,7 +285,7 @@ void editor_register_fonts(Ref<Theme> p_theme) { /* Hack */ Ref<FontData> dfmono; - dfmono.instance(); + dfmono.instantiate(); dfmono->load_memory(_font_Hack_Regular, _font_Hack_Regular_size, "ttf", default_font_size); dfmono->set_antialiased(font_antialiased); dfmono->set_hinting(font_hinting); diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp index 7365e8fd7d..16db465a4a 100644 --- a/editor/editor_help.cpp +++ b/editor/editor_help.cpp @@ -1909,7 +1909,7 @@ void FindBar::_unhandled_input(const Ref<InputEvent> &p_event) { Ref<InputEventKey> k = p_event; if (k.is_valid()) { - if (k->is_pressed() && (rich_text_label->has_focus() || is_a_parent_of(get_focus_owner()))) { + if (k->is_pressed() && (rich_text_label->has_focus() || is_ancestor_of(get_focus_owner()))) { bool accepted = true; switch (k->get_keycode()) { diff --git a/editor/editor_help_search.cpp b/editor/editor_help_search.cpp index b93ffa9321..a9bbb92079 100644 --- a/editor/editor_help_search.cpp +++ b/editor/editor_help_search.cpp @@ -237,9 +237,11 @@ EditorHelpSearch::EditorHelpSearch() { results_tree->set_v_size_flags(Control::SIZE_EXPAND_FILL); results_tree->set_columns(2); results_tree->set_column_title(0, TTR("Name")); + results_tree->set_column_clip_content(0, true); results_tree->set_column_title(1, TTR("Member Type")); results_tree->set_column_expand(1, false); - results_tree->set_column_min_width(1, 150 * EDSCALE); + results_tree->set_column_custom_minimum_width(1, 150 * EDSCALE); + results_tree->set_column_clip_content(1, true); results_tree->set_custom_minimum_size(Size2(0, 100) * EDSCALE); results_tree->set_hide_root(true); results_tree->set_select_mode(Tree::SELECT_ROW); diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index 69709315ff..4dd57cb1a8 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -417,7 +417,7 @@ bool EditorPropertyRevert::may_node_be_in_instance(Node *p_node) { return might_be; // or might not be } -bool EditorPropertyRevert::get_instanced_node_original_property(Node *p_node, const StringName &p_prop, Variant &value) { +bool EditorPropertyRevert::get_instantiated_node_original_property(Node *p_node, const StringName &p_prop, Variant &value) { Node *node = p_node; Node *orig = node; @@ -524,7 +524,7 @@ bool EditorPropertyRevert::can_property_revert(Object *p_object, const StringNam if (node && EditorPropertyRevert::may_node_be_in_instance(node)) { //check for difference including instantiation Variant vorig; - if (EditorPropertyRevert::get_instanced_node_original_property(node, p_property, vorig)) { + if (EditorPropertyRevert::get_instantiated_node_original_property(node, p_property, vorig)) { Variant v = p_object->get(p_property); if (EditorPropertyRevert::is_node_property_different(node, v, vorig)) { @@ -764,7 +764,7 @@ void EditorProperty::_gui_input(const Ref<InputEvent> &p_event) { Variant vorig; Node *node = Object::cast_to<Node>(object); - if (node && EditorPropertyRevert::may_node_be_in_instance(node) && EditorPropertyRevert::get_instanced_node_original_property(node, property, vorig)) { + if (node && EditorPropertyRevert::may_node_be_in_instance(node) && EditorPropertyRevert::get_instantiated_node_original_property(node, property, vorig)) { emit_changed(property, vorig.duplicate(true)); update_property(); return; @@ -1038,7 +1038,7 @@ void EditorInspectorPlugin::parse_category(Object *p_object, const String &p_par } } -bool EditorInspectorPlugin::parse_property(Object *p_object, Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, int p_usage, bool p_wide) { +bool EditorInspectorPlugin::parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const uint32_t p_usage, const bool p_wide) { if (get_script_instance()) { Variant arg[6] = { p_object, p_type, p_path, p_hint, p_hint_text, p_usage @@ -1182,15 +1182,19 @@ void EditorInspectorSection::_notification(int p_what) { Size2 size = get_size(); Point2 offset; + Rect2 rect; offset.y = font->get_height(font_size); if (arrow.is_valid()) { offset.y = MAX(offset.y, arrow->get_height()); } offset.y += get_theme_constant("vseparation", "Tree"); - offset.x += get_theme_constant("inspector_margin", "Editor"); - - Rect2 rect(offset, size - offset); + if (is_layout_rtl()) { + rect = Rect2(offset, size - offset - Vector2(get_theme_constant("inspector_margin", "Editor"), 0)); + } else { + offset.x += get_theme_constant("inspector_margin", "Editor"); + rect = Rect2(offset, size - offset); + } //set children for (int i = 0; i < get_child_count(); i++) { @@ -1433,7 +1437,7 @@ EditorInspectorSection::~EditorInspectorSection() { Ref<EditorInspectorPlugin> EditorInspector::inspector_plugins[MAX_PLUGINS]; int EditorInspector::inspector_plugin_count = 0; -EditorProperty *EditorInspector::instantiate_property_editor(Object *p_object, Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, int p_usage, bool p_wide) { +EditorProperty *EditorInspector::instantiate_property_editor(Object *p_object, const Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, const uint32_t p_usage, const bool p_wide) { for (int i = inspector_plugin_count - 1; i >= 0; i--) { inspector_plugins[i]->parse_property(p_object, p_type, p_path, p_hint, p_hint_text, p_usage, p_wide); if (inspector_plugins[i]->added_editors.size()) { diff --git a/editor/editor_inspector.h b/editor/editor_inspector.h index e4bcab3e3f..ee70bd4397 100644 --- a/editor/editor_inspector.h +++ b/editor/editor_inspector.h @@ -40,7 +40,7 @@ class UndoRedo; class EditorPropertyRevert { public: static bool may_node_be_in_instance(Node *p_node); - static bool get_instanced_node_original_property(Node *p_node, const StringName &p_prop, Variant &value); + static bool get_instantiated_node_original_property(Node *p_node, const StringName &p_prop, Variant &value); static bool is_node_property_different(Node *p_node, const Variant &p_current, const Variant &p_orig); static bool can_property_revert(Object *p_object, const StringName &p_property); @@ -83,7 +83,7 @@ private: bool draw_top_bg; bool _is_property_different(const Variant &p_current, const Variant &p_orig); - bool _get_instanced_node_original_property(const StringName &p_prop, Variant &value); + bool _get_instantiated_node_original_property(const StringName &p_prop, Variant &value); void _focusable_focused(int p_index); bool selectable; @@ -198,7 +198,7 @@ public: virtual bool can_handle(Object *p_object); virtual void parse_begin(Object *p_object); virtual void parse_category(Object *p_object, const String &p_parse_category); - virtual bool parse_property(Object *p_object, Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, int p_usage, bool p_wide = false); + virtual bool parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const uint32_t p_usage, const bool p_wide = false); virtual void parse_end(); }; @@ -271,7 +271,7 @@ class EditorInspector : public ScrollContainer { VBoxContainer *main_vbox; - //map use to cache the instanced editors + //map use to cache the instantiated editors Map<StringName, List<EditorProperty *>> editor_property_map; List<EditorInspectorSection *> sections; Set<StringName> pending; @@ -356,7 +356,7 @@ public: static void remove_inspector_plugin(const Ref<EditorInspectorPlugin> &p_plugin); static void cleanup_plugins(); - static EditorProperty *instantiate_property_editor(Object *p_object, Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, int p_usage, bool p_wide = false); + static EditorProperty *instantiate_property_editor(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const uint32_t p_usage, const bool p_wide = false); void set_undo_redo(UndoRedo *p_undo_redo); diff --git a/editor/editor_layouts_dialog.cpp b/editor/editor_layouts_dialog.cpp index 0bf1863459..437841ccc1 100644 --- a/editor/editor_layouts_dialog.cpp +++ b/editor/editor_layouts_dialog.cpp @@ -83,7 +83,7 @@ void EditorLayoutsDialog::_post_popup() { layout_names->clear(); Ref<ConfigFile> config; - config.instance(); + config.instantiate(); Error err = config->load(EditorSettings::get_singleton()->get_editor_layouts_config()); if (err != OK) { return; diff --git a/editor/editor_log.cpp b/editor/editor_log.cpp index 35d8021394..b3e90236a6 100644 --- a/editor/editor_log.cpp +++ b/editor/editor_log.cpp @@ -103,7 +103,7 @@ void EditorLog::_start_state_save_timer() { void EditorLog::_save_state() { Ref<ConfigFile> config; - config.instance(); + config.instantiate(); // Load and amend existing config if it exists. config->load(EditorSettings::get_singleton()->get_project_settings_dir().plus_file("editor_layout.cfg")); @@ -122,22 +122,21 @@ void EditorLog::_load_state() { is_loading_state = true; Ref<ConfigFile> config; - config.instance(); - Error err = config->load(EditorSettings::get_singleton()->get_project_settings_dir().plus_file("editor_layout.cfg")); - - if (err == OK) { - const String section = "editor_log"; - for (Map<MessageType, LogFilter *>::Element *E = type_filter_map.front(); E; E = E->next()) { - E->get()->set_active(config->get_value(section, "log_filter_" + itos(E->key()), false)); - } + config.instantiate(); + config->load(EditorSettings::get_singleton()->get_project_settings_dir().plus_file("editor_layout.cfg")); - collapse = config->get_value(section, "collapse", false); - collapse_button->set_pressed(collapse); - bool show_search = config->get_value(section, "show_search", true); - search_box->set_visible(show_search); - show_search_button->set_pressed(show_search); + // Run the below code even if config->load returns an error, since we want the defaults to be set even if the file does not exist yet. + const String section = "editor_log"; + for (Map<MessageType, LogFilter *>::Element *E = type_filter_map.front(); E; E = E->next()) { + E->get()->set_active(config->get_value(section, "log_filter_" + itos(E->key()), true)); } + collapse = config->get_value(section, "collapse", false); + collapse_button->set_pressed(collapse); + bool show_search = config->get_value(section, "show_search", true); + search_box->set_visible(show_search); + show_search_button->set_pressed(show_search); + is_loading_state = false; } diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 657ec9d70b..e7c0b02ae2 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -32,6 +32,7 @@ #include "core/config/project_settings.h" #include "core/core_bind.h" +#include "core/extension/native_extension_manager.h" #include "core/input/input.h" #include "core/io/config_file.h" #include "core/io/file_access.h" @@ -136,6 +137,7 @@ #include "editor/plugins/gpu_particles_3d_editor_plugin.h" #include "editor/plugins/gpu_particles_collision_sdf_editor_plugin.h" #include "editor/plugins/gradient_editor_plugin.h" +#include "editor/plugins/input_event_editor_plugin.h" #include "editor/plugins/item_list_editor_plugin.h" #include "editor/plugins/light_occluder_2d_editor_plugin.h" #include "editor/plugins/lightmap_gi_editor_plugin.h" @@ -590,8 +592,7 @@ void EditorNode::_notification(int p_what) { _initializing_addons = false; } - RenderingServer::get_singleton()->viewport_set_hide_scenario(get_scene_root()->get_viewport_rid(), true); - RenderingServer::get_singleton()->viewport_set_hide_canvas(get_scene_root()->get_viewport_rid(), true); + RenderingServer::get_singleton()->viewport_set_disable_2d(get_scene_root()->get_viewport_rid(), true); RenderingServer::get_singleton()->viewport_set_disable_environment(get_viewport()->get_viewport_rid(), true); feature_profile_manager->notify_changed(); @@ -708,6 +709,7 @@ void EditorNode::_notification(int p_what) { p->set_item_icon(p->get_item_index(HELP_DOCS), gui_base->get_theme_icon("Instance", "EditorIcons")); p->set_item_icon(p->get_item_index(HELP_QA), gui_base->get_theme_icon("Instance", "EditorIcons")); p->set_item_icon(p->get_item_index(HELP_REPORT_A_BUG), gui_base->get_theme_icon("Instance", "EditorIcons")); + p->set_item_icon(p->get_item_index(HELP_SUGGEST_A_FEATURE), gui_base->get_theme_icon("Instance", "EditorIcons")); p->set_item_icon(p->get_item_index(HELP_SEND_DOCS_FEEDBACK), gui_base->get_theme_icon("Instance", "EditorIcons")); p->set_item_icon(p->get_item_index(HELP_COMMUNITY), gui_base->get_theme_icon("Instance", "EditorIcons")); p->set_item_icon(p->get_item_index(HELP_ABOUT), gui_base->get_theme_icon("Godot", "EditorIcons")); @@ -1243,7 +1245,7 @@ void EditorNode::_get_scene_metadata(const String &p_file) { String path = EditorSettings::get_singleton()->get_project_settings_dir().plus_file(p_file.get_file() + "-editstate-" + p_file.md5_text() + ".cfg"); Ref<ConfigFile> cf; - cf.instance(); + cf.instantiate(); Error err = cf->load(path); if (err != OK || !cf->has_section("editor_states")) { @@ -1277,7 +1279,7 @@ void EditorNode::_set_scene_metadata(const String &p_file, int p_idx) { String path = EditorSettings::get_singleton()->get_project_settings_dir().plus_file(p_file.get_file() + "-editstate-" + p_file.md5_text() + ".cfg"); Ref<ConfigFile> cf; - cf.instance(); + cf.instantiate(); Dictionary md; @@ -1422,7 +1424,7 @@ void EditorNode::_save_scene_with_preview(String p_file, int p_idx) { // We cannot fallback on the 2D editor, because it may not have been used yet, // which would result in an invalid texture. if (c3d == 0 && c2d == 0) { - img.instance(); + img.instantiate(); img->create(1, 1, false, Image::FORMAT_RGB8); } else if (c3d < c2d) { Ref<ViewportTexture> viewport_texture = scene_root->get_texture(); @@ -1607,16 +1609,16 @@ void EditorNode::_save_scene(String p_file, int idx) { if (ResourceCache::has(p_file)) { // something may be referencing this resource and we are good with that. // we must update it, but also let the previous scene state go, as - // old version still work for referencing changes in instanced or inherited scenes + // old version still work for referencing changes in instantiated or inherited scenes sdata = Ref<PackedScene>(Object::cast_to<PackedScene>(ResourceCache::get(p_file))); if (sdata.is_valid()) { sdata->recreate_state(); } else { - sdata.instance(); + sdata.instantiate(); } } else { - sdata.instance(); + sdata.instantiate(); } Error err = sdata->pack(scene); @@ -1625,15 +1627,6 @@ void EditorNode::_save_scene(String p_file, int idx) { return; } - // force creation of node path cache - // (hacky but needed for the tree to update properly) - Node *dummy_scene = sdata->instance(PackedScene::GEN_EDIT_STATE_INSTANCE); - if (!dummy_scene) { - show_accept(TTR("Couldn't save scene. Likely dependencies (instances or inheritance) couldn't be satisfied."), TTR("OK")); - return; - } - memdelete(dummy_scene); - int flg = 0; if (EditorSettings::get_singleton()->get("filesystem/on_save/compress_binary_resources")) { flg |= ResourceSaver::FLAG_COMPRESS; @@ -1849,11 +1842,11 @@ void EditorNode::_dialog_action(String p_file) { } Ref<ConfigFile> config; - config.instance(); + config.instantiate(); Error err = config->load(EditorSettings::get_singleton()->get_editor_layouts_config()); if (err == ERR_FILE_CANT_OPEN || err == ERR_FILE_NOT_FOUND) { - config.instance(); // new config + config.instantiate(); // new config } else if (err != OK) { show_warning(TTR("An error occurred while trying to save the editor layout.\nMake sure the editor's user data path is writable.")); return; @@ -1877,7 +1870,7 @@ void EditorNode::_dialog_action(String p_file) { } Ref<ConfigFile> config; - config.instance(); + config.instantiate(); Error err = config->load(EditorSettings::get_singleton()->get_editor_layouts_config()); if (err != OK || !config->has_section(p_file)) { @@ -2082,7 +2075,7 @@ void EditorNode::_edit_current() { editable_warning = TTR("This resource belongs to a scene that was imported, so it's not editable.\nPlease read the documentation relevant to importing scenes to better understand this workflow."); } else { if ((!get_edited_scene() || get_edited_scene()->get_filename() != base_path) && ResourceLoader::get_resource_type(base_path) == "PackedScene") { - editable_warning = TTR("This resource belongs to a scene that was instanced or inherited.\nChanges to it won't be kept when saving the current scene."); + editable_warning = TTR("This resource belongs to a scene that was instantiated or inherited.\nChanges to it won't be kept when saving the current scene."); } } } else if (current_res->get_path().is_resource_file()) { @@ -2804,6 +2797,9 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { case HELP_REPORT_A_BUG: { OS::get_singleton()->shell_open("https://github.com/godotengine/godot/issues"); } break; + case HELP_SUGGEST_A_FEATURE: { + OS::get_singleton()->shell_open("https://github.com/godotengine/godot-proposals#readme"); + } break; case HELP_SEND_DOCS_FEEDBACK: { OS::get_singleton()->shell_open("https://github.com/godotengine/godot-docs/issues"); } break; @@ -3144,7 +3140,7 @@ void EditorNode::set_addon_plugin_enabled(const String &p_addon, bool p_enabled, } Ref<ConfigFile> cf; - cf.instance(); + cf.instantiate(); if (!DirAccess::exists(p_addon.get_base_dir())) { _remove_plugin_from_enabled(p_addon); WARN_PRINT("Addon '" + p_addon + "' failed to load. No directory found. Removing from enabled plugins."); @@ -3525,7 +3521,7 @@ Error EditorNode::load_scene(const String &p_scene, bool p_ignore_broken_deps, b sdata->set_path(lpath, true); //take over path } - Node *new_scene = sdata->instance(PackedScene::GEN_EDIT_STATE_MAIN); + Node *new_scene = sdata->instantiate(PackedScene::GEN_EDIT_STATE_MAIN); if (!new_scene) { sdata.unref(); @@ -3589,11 +3585,11 @@ void EditorNode::open_request(const String &p_path) { } void EditorNode::request_instance_scene(const String &p_path) { - scene_tree_dock->instance(p_path); + scene_tree_dock->instantiate(p_path); } -void EditorNode::request_instance_scenes(const Vector<String> &p_files) { - scene_tree_dock->instance_scenes(p_files); +void EditorNode::request_instantiate_scenes(const Vector<String> &p_files) { + scene_tree_dock->instantiate_scenes(p_files); } ImportDock *EditorNode::get_import_dock() { @@ -3617,8 +3613,8 @@ void EditorNode::_inherit_request(String p_file) { _dialog_action(p_file); } -void EditorNode::_instance_request(const Vector<String> &p_files) { - request_instance_scenes(p_files); +void EditorNode::_instantiate_request(const Vector<String> &p_files) { + request_instantiate_scenes(p_files); } void EditorNode::_close_messages() { @@ -3780,9 +3776,12 @@ void EditorNode::register_editor_types() { ClassDB::register_class<EditorScenePostImport>(); //ClassDB::register_type<EditorImportExport>(); ClassDB::register_class<EditorDebuggerPlugin>(); + + NativeExtensionManager::get_singleton()->initialize_extensions(NativeExtension::INITIALIZATION_LEVEL_EDITOR); } void EditorNode::unregister_editor_types() { + NativeExtensionManager::get_singleton()->deinitialize_extensions(NativeExtension::INITIALIZATION_LEVEL_EDITOR); _init_callbacks.clear(); if (EditorPaths::get_singleton()) { EditorPaths::free(); @@ -3876,6 +3875,21 @@ Ref<ImageTexture> EditorNode::_load_custom_class_icon(const String &p_path) cons return nullptr; } +void EditorNode::_pick_main_scene_custom_action(const String &p_custom_action_name) { + if (p_custom_action_name == "select_current") { + Node *scene = editor_data.get_edited_scene_root(); + + if (!scene) { + show_accept(TTR("There is no defined scene to run."), TTR("OK")); + return; + } + + pick_main_scene->hide(); + current_option = SETTINGS_PICK_MAIN_SCENE; + _dialog_action(scene->get_filename()); + } +} + Ref<Texture2D> EditorNode::get_object_icon(const Object *p_object, const String &p_fallback) const { ERR_FAIL_COND_V(!p_object || !gui_base, nullptr); @@ -4352,7 +4366,7 @@ void EditorNode::_save_docks() { return; //scanning, do not touch docks } Ref<ConfigFile> config; - config.instance(); + config.instantiate(); // Load and amend existing config if it exists. config->load(EditorSettings::get_singleton()->get_project_settings_dir().plus_file("editor_layout.cfg")); @@ -4417,7 +4431,7 @@ void EditorNode::_dock_split_dragged(int ofs) { void EditorNode::_load_docks() { Ref<ConfigFile> config; - config.instance(); + config.instantiate(); Error err = config->load(EditorSettings::get_singleton()->get_project_settings_dir().plus_file("editor_layout.cfg")); if (err != OK) { //no config @@ -4650,7 +4664,7 @@ bool EditorNode::has_scenes_in_session() { return false; } Ref<ConfigFile> config; - config.instance(); + config.instantiate(); Error err = config->load(EditorSettings::get_singleton()->get_project_settings_dir().plus_file("editor_layout.cfg")); if (err != OK) { return false; @@ -4670,6 +4684,14 @@ bool EditorNode::ensure_main_scene(bool p_from_native) { current_option = -1; pick_main_scene->set_text(TTR("No main scene has ever been defined, select one?\nYou can change it later in \"Project Settings\" under the 'application' category.")); pick_main_scene->popup_centered(); + + if (editor_data.get_edited_scene_root()) { + select_current_scene_button->set_disabled(false); + select_current_scene_button->grab_focus(); + } else { + select_current_scene_button->set_disabled(true); + } + return false; } @@ -4743,7 +4765,7 @@ void EditorNode::_update_layouts_menu() { editor_layouts->add_shortcut(ED_SHORTCUT("layout/default", TTR("Default")), SETTINGS_LAYOUT_DEFAULT); Ref<ConfigFile> config; - config.instance(); + config.instantiate(); Error err = config->load(EditorSettings::get_singleton()->get_editor_layouts_config()); if (err != OK) { return; //no config @@ -4786,7 +4808,7 @@ void EditorNode::_layout_menu_option(int p_id) { } break; default: { Ref<ConfigFile> config; - config.instance(); + config.instantiate(); Error err = config->load(EditorSettings::get_singleton()->get_editor_layouts_config()); if (err != OK) { return; //no config @@ -5337,7 +5359,7 @@ void EditorNode::reload_scene(const String &p_path) { if (scene_idx == -1) { if (get_edited_scene()) { - //scene is not open, so at it might be instanced. We'll refresh the whole scene later. + //scene is not open, so at it might be instantiated. We'll refresh the whole scene later. editor_data.get_undo_redo().clear_history(); } return; @@ -5734,87 +5756,87 @@ EditorNode::EditorNode() { { //register importers at the beginning, so dialogs are created with the right extensions Ref<ResourceImporterTexture> import_texture; - import_texture.instance(); + import_texture.instantiate(); ResourceFormatImporter::get_singleton()->add_importer(import_texture); Ref<ResourceImporterLayeredTexture> import_cubemap; - import_cubemap.instance(); + import_cubemap.instantiate(); import_cubemap->set_mode(ResourceImporterLayeredTexture::MODE_CUBEMAP); ResourceFormatImporter::get_singleton()->add_importer(import_cubemap); Ref<ResourceImporterLayeredTexture> import_array; - import_array.instance(); + import_array.instantiate(); import_array->set_mode(ResourceImporterLayeredTexture::MODE_2D_ARRAY); ResourceFormatImporter::get_singleton()->add_importer(import_array); Ref<ResourceImporterLayeredTexture> import_cubemap_array; - import_cubemap_array.instance(); + import_cubemap_array.instantiate(); import_cubemap_array->set_mode(ResourceImporterLayeredTexture::MODE_CUBEMAP_ARRAY); ResourceFormatImporter::get_singleton()->add_importer(import_cubemap_array); Ref<ResourceImporterLayeredTexture> import_3d; - import_3d.instance(); + import_3d.instantiate(); import_3d->set_mode(ResourceImporterLayeredTexture::MODE_3D); ResourceFormatImporter::get_singleton()->add_importer(import_3d); Ref<ResourceImporterImage> import_image; - import_image.instance(); + import_image.instantiate(); ResourceFormatImporter::get_singleton()->add_importer(import_image); Ref<ResourceImporterTextureAtlas> import_texture_atlas; - import_texture_atlas.instance(); + import_texture_atlas.instantiate(); ResourceFormatImporter::get_singleton()->add_importer(import_texture_atlas); Ref<ResourceImporterCSVTranslation> import_csv_translation; - import_csv_translation.instance(); + import_csv_translation.instantiate(); ResourceFormatImporter::get_singleton()->add_importer(import_csv_translation); Ref<ResourceImporterWAV> import_wav; - import_wav.instance(); + import_wav.instantiate(); ResourceFormatImporter::get_singleton()->add_importer(import_wav); Ref<ResourceImporterOBJ> import_obj; - import_obj.instance(); + import_obj.instantiate(); ResourceFormatImporter::get_singleton()->add_importer(import_obj); Ref<ResourceImporterShaderFile> import_shader_file; - import_shader_file.instance(); + import_shader_file.instantiate(); ResourceFormatImporter::get_singleton()->add_importer(import_shader_file); Ref<ResourceImporterScene> import_scene; - import_scene.instance(); + import_scene.instantiate(); ResourceFormatImporter::get_singleton()->add_importer(import_scene); { Ref<EditorSceneImporterCollada> import_collada; - import_collada.instance(); + import_collada.instantiate(); import_scene->add_importer(import_collada); Ref<EditorOBJImporter> import_obj2; - import_obj2.instance(); + import_obj2.instantiate(); import_scene->add_importer(import_obj2); Ref<EditorSceneImporterESCN> import_escn; - import_escn.instance(); + import_escn.instantiate(); import_scene->add_importer(import_escn); } Ref<ResourceImporterBitMap> import_bitmap; - import_bitmap.instance(); + import_bitmap.instantiate(); ResourceFormatImporter::get_singleton()->add_importer(import_bitmap); } { Ref<EditorInspectorDefaultPlugin> eidp; - eidp.instance(); + eidp.instantiate(); EditorInspector::add_inspector_plugin(eidp); Ref<EditorInspectorRootMotionPlugin> rmp; - rmp.instance(); + rmp.instantiate(); EditorInspector::add_inspector_plugin(rmp); Ref<EditorInspectorShaderModePlugin> smp; - smp.instance(); + smp.instantiate(); EditorInspector::add_inspector_plugin(smp); } @@ -6117,9 +6139,9 @@ EditorNode::EditorNode() { scene_root_parent->set_v_size_flags(Control::SIZE_EXPAND_FILL); scene_root = memnew(SubViewport); - //scene_root->set_usage(Viewport::USAGE_2D); canvas BG mode prevents usage of this as 2D + scene_root->set_embed_subwindows_hint(true); + scene_root->set_disable_3d(true); - RenderingServer::get_singleton()->viewport_set_hide_scenario(scene_root->get_viewport_rid(), true); scene_root->set_disable_input(true); scene_root->set_as_audio_listener_2d(true); @@ -6366,6 +6388,7 @@ EditorNode::EditorNode() { p->add_icon_shortcut(gui_base->get_theme_icon("Instance", "EditorIcons"), ED_SHORTCUT("editor/online_docs", TTR("Online Documentation")), HELP_DOCS); p->add_icon_shortcut(gui_base->get_theme_icon("Instance", "EditorIcons"), ED_SHORTCUT("editor/q&a", TTR("Questions & Answers")), HELP_QA); p->add_icon_shortcut(gui_base->get_theme_icon("Instance", "EditorIcons"), ED_SHORTCUT("editor/report_a_bug", TTR("Report a Bug")), HELP_REPORT_A_BUG); + p->add_icon_shortcut(gui_base->get_theme_icon("Instance", "EditorIcons"), ED_SHORTCUT("editor/suggest_a_feature", TTR("Suggest a Feature")), HELP_SUGGEST_A_FEATURE); p->add_icon_shortcut(gui_base->get_theme_icon("Instance", "EditorIcons"), ED_SHORTCUT("editor/send_docs_feedback", TTR("Send Docs Feedback")), HELP_SEND_DOCS_FEEDBACK); p->add_icon_shortcut(gui_base->get_theme_icon("Instance", "EditorIcons"), ED_SHORTCUT("editor/community", TTR("Community")), HELP_COMMUNITY); p->add_separator(); @@ -6517,7 +6540,7 @@ EditorNode::EditorNode() { filesystem_dock = memnew(FileSystemDock(this)); filesystem_dock->connect("inherit", callable_mp(this, &EditorNode::_inherit_request)); - filesystem_dock->connect("instance", callable_mp(this, &EditorNode::_instance_request)); + filesystem_dock->connect("instance", callable_mp(this, &EditorNode::_instantiate_request)); filesystem_dock->connect("display_mode_changed", callable_mp(this, &EditorNode::_save_docks)); // Scene: Top left @@ -6557,7 +6580,7 @@ EditorNode::EditorNode() { const String docks_section = "docks"; overridden_default_layout = -1; - default_layout.instance(); + default_layout.instantiate(); // Dock numbers are based on DockSlot enum value + 1 default_layout->set_value(docks_section, "dock_3", "Scene,Import"); default_layout->set_value(docks_section, "dock_4", "FileSystem"); @@ -6817,6 +6840,7 @@ EditorNode::EditorNode() { add_editor_plugin(memnew(MeshEditorPlugin(this))); add_editor_plugin(memnew(MaterialEditorPlugin(this))); add_editor_plugin(memnew(GPUParticlesCollisionSDFEditorPlugin(this))); + add_editor_plugin(memnew(InputEventEditorPlugin(this))); for (int i = 0; i < EditorPlugins::get_plugin_count(); i++) { add_editor_plugin(EditorPlugins::create(i, this)); @@ -6838,31 +6862,31 @@ EditorNode::EditorNode() { { Ref<StandardMaterial3DConversionPlugin> spatial_mat_convert; - spatial_mat_convert.instance(); + spatial_mat_convert.instantiate(); resource_conversion_plugins.push_back(spatial_mat_convert); Ref<CanvasItemMaterialConversionPlugin> canvas_item_mat_convert; - canvas_item_mat_convert.instance(); + canvas_item_mat_convert.instantiate(); resource_conversion_plugins.push_back(canvas_item_mat_convert); Ref<ParticlesMaterialConversionPlugin> particles_mat_convert; - particles_mat_convert.instance(); + particles_mat_convert.instantiate(); resource_conversion_plugins.push_back(particles_mat_convert); Ref<ProceduralSkyMaterialConversionPlugin> procedural_sky_mat_convert; - procedural_sky_mat_convert.instance(); + procedural_sky_mat_convert.instantiate(); resource_conversion_plugins.push_back(procedural_sky_mat_convert); Ref<PanoramaSkyMaterialConversionPlugin> panorama_sky_mat_convert; - panorama_sky_mat_convert.instance(); + panorama_sky_mat_convert.instantiate(); resource_conversion_plugins.push_back(panorama_sky_mat_convert); Ref<PhysicalSkyMaterialConversionPlugin> physical_sky_mat_convert; - physical_sky_mat_convert.instance(); + physical_sky_mat_convert.instantiate(); resource_conversion_plugins.push_back(physical_sky_mat_convert); Ref<VisualShaderConversionPlugin> vshader_convert; - vshader_convert.instance(); + vshader_convert.instantiate(); resource_conversion_plugins.push_back(vshader_convert); } update_spinner_step_msec = OS::get_singleton()->get_ticks_msec(); @@ -6875,12 +6899,12 @@ EditorNode::EditorNode() { editor_plugins_force_input_forwarding = memnew(EditorPluginList); Ref<EditorExportTextSceneToBinaryPlugin> export_text_to_binary_plugin; - export_text_to_binary_plugin.instance(); + export_text_to_binary_plugin.instantiate(); EditorExport::get_singleton()->add_export_plugin(export_text_to_binary_plugin); Ref<PackedSceneEditorTranslationParserPlugin> packed_scene_translation_parser_plugin; - packed_scene_translation_parser_plugin.instance(); + packed_scene_translation_parser_plugin.instantiate(); EditorTranslationParser::get_singleton()->add_parser(packed_scene_translation_parser_plugin, EditorTranslationParser::STANDARD); _edit_current(); @@ -6901,7 +6925,7 @@ EditorNode::EditorNode() { saved_version = 1; unsaved_cache = true; - _last_instanced_scene = nullptr; + _last_instantiated_scene = nullptr; quick_open = memnew(EditorQuickOpen); gui_base->add_child(quick_open); @@ -6945,6 +6969,8 @@ EditorNode::EditorNode() { gui_base->add_child(pick_main_scene); pick_main_scene->get_ok_button()->set_text(TTR("Select")); pick_main_scene->connect("confirmed", callable_mp(this, &EditorNode::_menu_option), varray(SETTINGS_PICK_MAIN_SCENE)); + select_current_scene_button = pick_main_scene->add_button(TTR("Select Current"), true, "select_current"); + pick_main_scene->connect("custom_action", callable_mp(this, &EditorNode::_pick_main_scene_custom_action)); for (int i = 0; i < _init_callbacks.size(); i++) { _init_callbacks[i](); diff --git a/editor/editor_node.h b/editor/editor_node.h index 037ed263c5..07bed6999b 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -194,6 +194,7 @@ private: HELP_DOCS, HELP_QA, HELP_REPORT_A_BUG, + HELP_SUGGEST_A_FEATURE, HELP_SEND_DOCS_FEEDBACK, HELP_COMMUNITY, HELP_ABOUT, @@ -300,6 +301,7 @@ private: ConfirmationDialog *save_confirmation; ConfirmationDialog *import_confirmation; ConfirmationDialog *pick_main_scene; + Button *select_current_scene_button; AcceptDialog *accept; EditorAbout *about; AcceptDialog *warning; @@ -332,7 +334,7 @@ private: EditorNativeShaderSourceVisualizer *native_shader_source_visualizer; String defer_load_scene; - Node *_last_instanced_scene; + Node *_last_instantiated_scene; EditorLog *log; CenterContainer *tabs_center; @@ -491,7 +493,7 @@ private: void _discard_changes(const String &p_str = String()); void _inherit_request(String p_file); - void _instance_request(const Vector<String> &p_files); + void _instantiate_request(const Vector<String> &p_files); void _display_top_editors(bool p_display); void _set_top_editors(Vector<EditorPlugin *> p_editor_plugins_over); @@ -662,6 +664,8 @@ private: bool _is_class_editor_disabled_by_feature_profile(const StringName &p_class); Ref<ImageTexture> _load_custom_class_icon(const String &p_path) const; + void _pick_main_scene_custom_action(const String &p_custom_action_name); + protected: void _notification(int p_what); @@ -770,7 +774,7 @@ public: static VSplitContainer *get_top_split() { return singleton->top_split; } void request_instance_scene(const String &p_path); - void request_instance_scenes(const Vector<String> &p_files); + void request_instantiate_scenes(const Vector<String> &p_files); FileSystemDock *get_filesystem_dock(); ImportDock *get_import_dock(); SceneTreeDock *get_scene_tree_dock(); diff --git a/editor/editor_plugin_settings.cpp b/editor/editor_plugin_settings.cpp index 1db24bb908..b4e5a58c21 100644 --- a/editor/editor_plugin_settings.cpp +++ b/editor/editor_plugin_settings.cpp @@ -57,7 +57,7 @@ void EditorPluginSettings::update_plugins() { for (int i = 0; i < plugins.size(); i++) { Ref<ConfigFile> cf; - cf.instance(); + cf.instantiate(); const String path = plugins[i]; Error err2 = cf->load(path); @@ -212,14 +212,19 @@ EditorPluginSettings::EditorPluginSettings() { plugin_list->set_column_title(3, TTR("Status:")); plugin_list->set_column_title(4, TTR("Edit:")); plugin_list->set_column_expand(0, true); + plugin_list->set_column_clip_content(0, true); plugin_list->set_column_expand(1, false); + plugin_list->set_column_clip_content(1, true); plugin_list->set_column_expand(2, false); + plugin_list->set_column_clip_content(2, true); plugin_list->set_column_expand(3, false); + plugin_list->set_column_clip_content(3, true); plugin_list->set_column_expand(4, false); - plugin_list->set_column_min_width(1, 100 * EDSCALE); - plugin_list->set_column_min_width(2, 250 * EDSCALE); - plugin_list->set_column_min_width(3, 80 * EDSCALE); - plugin_list->set_column_min_width(4, 40 * EDSCALE); + plugin_list->set_column_clip_content(4, true); + plugin_list->set_column_custom_minimum_width(1, 100 * EDSCALE); + plugin_list->set_column_custom_minimum_width(2, 250 * EDSCALE); + plugin_list->set_column_custom_minimum_width(3, 80 * EDSCALE); + plugin_list->set_column_custom_minimum_width(4, 40 * EDSCALE); plugin_list->set_hide_root(true); plugin_list->connect("item_edited", callable_mp(this, &EditorPluginSettings::_plugin_activity_changed)); diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index 3feeaec070..84105f0cb7 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -491,6 +491,7 @@ void EditorPropertyEnum::update_property() { } void EditorPropertyEnum::setup(const Vector<String> &p_options) { + options->clear(); int64_t current_val = 0; for (int i = 0; i < p_options.size(); i++) { Vector<String> text_split = p_options[i].split(":"); @@ -892,11 +893,17 @@ void EditorPropertyFloat::_value_changed(double val) { return; } + if (angle_in_radians) { + val = Math::deg2rad(val); + } emit_changed(get_edited_property(), val); } void EditorPropertyFloat::update_property() { double val = get_edited_object()->get(get_edited_property()); + if (angle_in_radians) { + val = Math::rad2deg(val); + } setting = true; spin->set_value(val); setting = false; @@ -905,7 +912,8 @@ void EditorPropertyFloat::update_property() { void EditorPropertyFloat::_bind_methods() { } -void EditorPropertyFloat::setup(double p_min, double p_max, double p_step, bool p_no_slider, bool p_exp_range, bool p_greater, bool p_lesser) { +void EditorPropertyFloat::setup(double p_min, double p_max, double p_step, bool p_no_slider, bool p_exp_range, bool p_greater, bool p_lesser, const String &p_suffix, bool p_angle_in_radians) { + angle_in_radians = p_angle_in_radians; spin->set_min(p_min); spin->set_max(p_max); spin->set_step(p_step); @@ -913,6 +921,7 @@ void EditorPropertyFloat::setup(double p_min, double p_max, double p_step, bool spin->set_exp_ratio(p_exp_range); spin->set_allow_greater(p_greater); spin->set_allow_lesser(p_lesser); + spin->set_suffix(p_suffix); } EditorPropertyFloat::EditorPropertyFloat() { @@ -921,7 +930,6 @@ EditorPropertyFloat::EditorPropertyFloat() { add_child(spin); add_focusable(spin); spin->connect("value_changed", callable_mp(this, &EditorPropertyFloat::_value_changed)); - setting = false; } ///////////////////// EASING ///////////////////////// @@ -1171,7 +1179,7 @@ void EditorPropertyVector2::_notification(int p_what) { void EditorPropertyVector2::_bind_methods() { } -void EditorPropertyVector2::setup(double p_min, double p_max, double p_step, bool p_no_slider) { +void EditorPropertyVector2::setup(double p_min, double p_max, double p_step, bool p_no_slider, const String &p_suffix) { for (int i = 0; i < 2; i++) { spin[i]->set_min(p_min); spin[i]->set_max(p_max); @@ -1179,6 +1187,7 @@ void EditorPropertyVector2::setup(double p_min, double p_max, double p_step, boo spin[i]->set_hide_slider(p_no_slider); spin[i]->set_allow_greater(true); spin[i]->set_allow_lesser(true); + spin[i]->set_suffix(p_suffix); } } @@ -1257,7 +1266,7 @@ void EditorPropertyRect2::_notification(int p_what) { void EditorPropertyRect2::_bind_methods() { } -void EditorPropertyRect2::setup(double p_min, double p_max, double p_step, bool p_no_slider) { +void EditorPropertyRect2::setup(double p_min, double p_max, double p_step, bool p_no_slider, const String &p_suffix) { for (int i = 0; i < 4; i++) { spin[i]->set_min(p_min); spin[i]->set_max(p_max); @@ -1265,6 +1274,7 @@ void EditorPropertyRect2::setup(double p_min, double p_max, double p_step, bool spin[i]->set_hide_slider(p_no_slider); spin[i]->set_allow_greater(true); spin[i]->set_allow_lesser(true); + spin[i]->set_suffix(p_suffix); } } @@ -1325,6 +1335,11 @@ void EditorPropertyVector3::_value_changed(double val, const String &p_name) { v3.x = spin[0]->get_value(); v3.y = spin[1]->get_value(); v3.z = spin[2]->get_value(); + if (angle_in_radians) { + v3.x = Math::deg2rad(v3.x); + v3.y = Math::deg2rad(v3.y); + v3.z = Math::deg2rad(v3.z); + } emit_changed(get_edited_property(), v3, p_name); } @@ -1333,6 +1348,11 @@ void EditorPropertyVector3::update_property() { } void EditorPropertyVector3::update_using_vector(Vector3 p_vector) { + if (angle_in_radians) { + p_vector.x = Math::rad2deg(p_vector.x); + p_vector.y = Math::rad2deg(p_vector.y); + p_vector.z = Math::rad2deg(p_vector.z); + } setting = true; spin[0]->set_value(p_vector.x); spin[1]->set_value(p_vector.y); @@ -1345,6 +1365,12 @@ Vector3 EditorPropertyVector3::get_vector() { v3.x = spin[0]->get_value(); v3.y = spin[1]->get_value(); v3.z = spin[2]->get_value(); + if (angle_in_radians) { + v3.x = Math::deg2rad(v3.x); + v3.y = Math::deg2rad(v3.y); + v3.z = Math::deg2rad(v3.z); + } + return v3; } @@ -1362,7 +1388,8 @@ void EditorPropertyVector3::_notification(int p_what) { void EditorPropertyVector3::_bind_methods() { } -void EditorPropertyVector3::setup(double p_min, double p_max, double p_step, bool p_no_slider) { +void EditorPropertyVector3::setup(double p_min, double p_max, double p_step, bool p_no_slider, const String &p_suffix, bool p_angle_in_radians) { + angle_in_radians = p_angle_in_radians; for (int i = 0; i < 3; i++) { spin[i]->set_min(p_min); spin[i]->set_max(p_max); @@ -1370,6 +1397,7 @@ void EditorPropertyVector3::setup(double p_min, double p_max, double p_step, boo spin[i]->set_hide_slider(p_no_slider); spin[i]->set_allow_greater(true); spin[i]->set_allow_lesser(true); + spin[i]->set_suffix(p_suffix); } } @@ -1406,7 +1434,6 @@ EditorPropertyVector3::EditorPropertyVector3(bool p_force_wide) { if (!horizontal) { set_label_reference(spin[0]); //show text and buttons around this } - setting = false; } ///////////////////// VECTOR2i ///////////////////////// @@ -1444,7 +1471,7 @@ void EditorPropertyVector2i::_notification(int p_what) { void EditorPropertyVector2i::_bind_methods() { } -void EditorPropertyVector2i::setup(int p_min, int p_max, bool p_no_slider) { +void EditorPropertyVector2i::setup(int p_min, int p_max, bool p_no_slider, const String &p_suffix) { for (int i = 0; i < 2; i++) { spin[i]->set_min(p_min); spin[i]->set_max(p_max); @@ -1452,6 +1479,7 @@ void EditorPropertyVector2i::setup(int p_min, int p_max, bool p_no_slider) { spin[i]->set_hide_slider(p_no_slider); spin[i]->set_allow_greater(true); spin[i]->set_allow_lesser(true); + spin[i]->set_suffix(p_suffix); } } @@ -1530,7 +1558,7 @@ void EditorPropertyRect2i::_notification(int p_what) { void EditorPropertyRect2i::_bind_methods() { } -void EditorPropertyRect2i::setup(int p_min, int p_max, bool p_no_slider) { +void EditorPropertyRect2i::setup(int p_min, int p_max, bool p_no_slider, const String &p_suffix) { for (int i = 0; i < 4; i++) { spin[i]->set_min(p_min); spin[i]->set_max(p_max); @@ -1538,6 +1566,7 @@ void EditorPropertyRect2i::setup(int p_min, int p_max, bool p_no_slider) { spin[i]->set_hide_slider(p_no_slider); spin[i]->set_allow_greater(true); spin[i]->set_allow_lesser(true); + spin[i]->set_suffix(p_suffix); } } @@ -1624,7 +1653,7 @@ void EditorPropertyVector3i::_notification(int p_what) { void EditorPropertyVector3i::_bind_methods() { } -void EditorPropertyVector3i::setup(int p_min, int p_max, bool p_no_slider) { +void EditorPropertyVector3i::setup(int p_min, int p_max, bool p_no_slider, const String &p_suffix) { for (int i = 0; i < 3; i++) { spin[i]->set_min(p_min); spin[i]->set_max(p_max); @@ -1632,6 +1661,7 @@ void EditorPropertyVector3i::setup(int p_min, int p_max, bool p_no_slider) { spin[i]->set_hide_slider(p_no_slider); spin[i]->set_allow_greater(true); spin[i]->set_allow_lesser(true); + spin[i]->set_suffix(p_suffix); } } @@ -1709,7 +1739,7 @@ void EditorPropertyPlane::_notification(int p_what) { void EditorPropertyPlane::_bind_methods() { } -void EditorPropertyPlane::setup(double p_min, double p_max, double p_step, bool p_no_slider) { +void EditorPropertyPlane::setup(double p_min, double p_max, double p_step, bool p_no_slider, const String &p_suffix) { for (int i = 0; i < 4; i++) { spin[i]->set_min(p_min); spin[i]->set_max(p_max); @@ -1717,6 +1747,7 @@ void EditorPropertyPlane::setup(double p_min, double p_max, double p_step, bool spin[i]->set_hide_slider(p_no_slider); spin[i]->set_allow_greater(true); spin[i]->set_allow_lesser(true); + spin[i]->set_suffix(p_suffix); } } @@ -1795,7 +1826,7 @@ void EditorPropertyQuaternion::_notification(int p_what) { void EditorPropertyQuaternion::_bind_methods() { } -void EditorPropertyQuaternion::setup(double p_min, double p_max, double p_step, bool p_no_slider) { +void EditorPropertyQuaternion::setup(double p_min, double p_max, double p_step, bool p_no_slider, const String &p_suffix) { for (int i = 0; i < 4; i++) { spin[i]->set_min(p_min); spin[i]->set_max(p_max); @@ -1803,6 +1834,7 @@ void EditorPropertyQuaternion::setup(double p_min, double p_max, double p_step, spin[i]->set_hide_slider(p_no_slider); spin[i]->set_allow_greater(true); spin[i]->set_allow_lesser(true); + spin[i]->set_suffix(p_suffix); } } @@ -1884,7 +1916,7 @@ void EditorPropertyAABB::_notification(int p_what) { void EditorPropertyAABB::_bind_methods() { } -void EditorPropertyAABB::setup(double p_min, double p_max, double p_step, bool p_no_slider) { +void EditorPropertyAABB::setup(double p_min, double p_max, double p_step, bool p_no_slider, const String &p_suffix) { for (int i = 0; i < 6; i++) { spin[i]->set_min(p_min); spin[i]->set_max(p_max); @@ -1892,6 +1924,7 @@ void EditorPropertyAABB::setup(double p_min, double p_max, double p_step, bool p spin[i]->set_hide_slider(p_no_slider); spin[i]->set_allow_greater(true); spin[i]->set_allow_lesser(true); + spin[i]->set_suffix(p_suffix); } } @@ -1960,7 +1993,7 @@ void EditorPropertyTransform2D::_notification(int p_what) { void EditorPropertyTransform2D::_bind_methods() { } -void EditorPropertyTransform2D::setup(double p_min, double p_max, double p_step, bool p_no_slider) { +void EditorPropertyTransform2D::setup(double p_min, double p_max, double p_step, bool p_no_slider, const String &p_suffix) { for (int i = 0; i < 6; i++) { spin[i]->set_min(p_min); spin[i]->set_max(p_max); @@ -1968,6 +2001,7 @@ void EditorPropertyTransform2D::setup(double p_min, double p_max, double p_step, spin[i]->set_hide_slider(p_no_slider); spin[i]->set_allow_greater(true); spin[i]->set_allow_lesser(true); + spin[i]->set_suffix(p_suffix); } } @@ -2041,7 +2075,7 @@ void EditorPropertyBasis::_notification(int p_what) { void EditorPropertyBasis::_bind_methods() { } -void EditorPropertyBasis::setup(double p_min, double p_max, double p_step, bool p_no_slider) { +void EditorPropertyBasis::setup(double p_min, double p_max, double p_step, bool p_no_slider, const String &p_suffix) { for (int i = 0; i < 9; i++) { spin[i]->set_min(p_min); spin[i]->set_max(p_max); @@ -2049,6 +2083,7 @@ void EditorPropertyBasis::setup(double p_min, double p_max, double p_step, bool spin[i]->set_hide_slider(p_no_slider); spin[i]->set_allow_greater(true); spin[i]->set_allow_lesser(true); + spin[i]->set_suffix(p_suffix); } } @@ -2130,7 +2165,7 @@ void EditorPropertyTransform3D::_notification(int p_what) { void EditorPropertyTransform3D::_bind_methods() { } -void EditorPropertyTransform3D::setup(double p_min, double p_max, double p_step, bool p_no_slider) { +void EditorPropertyTransform3D::setup(double p_min, double p_max, double p_step, bool p_no_slider, const String &p_suffix) { for (int i = 0; i < 12; i++) { spin[i]->set_min(p_min); spin[i]->set_max(p_max); @@ -2138,6 +2173,7 @@ void EditorPropertyTransform3D::setup(double p_min, double p_max, double p_step, spin[i]->set_hide_slider(p_no_slider); spin[i]->set_allow_greater(true); spin[i]->set_allow_lesser(true); + spin[i]->set_suffix(p_suffix); } } @@ -2535,7 +2571,7 @@ void EditorPropertyResource::_viewport_selected(const NodePath &p_path) { } Ref<ViewportTexture> vt; - vt.instance(); + vt.instantiate(); vt->set_viewport_path_in_scene(get_tree()->get_edited_scene_root()->get_path_to(to_node)); vt->setup_local_to_scene(); @@ -2698,31 +2734,97 @@ void EditorInspectorDefaultPlugin::parse_begin(Object *p_object) { //do none } -bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, int p_usage, bool p_wide) { +bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const uint32_t p_usage, const bool p_wide) { + Control *editor = EditorInspectorDefaultPlugin::get_editor_for_property(p_object, p_type, p_path, p_hint, p_hint_text, p_usage, p_wide); + if (editor) { + add_property_editor(p_path, editor); + } + return false; +} + +void EditorInspectorDefaultPlugin::parse_end() { + //do none +} + +struct EditorPropertyRangeHint { + bool angle_in_degrees = false; + bool greater = true; + bool lesser = true; + double min = -99999; + double max = 99999; + double step = 0; + String suffix; + bool exp_range = false; + bool hide_slider = true; + bool radians = false; +}; + +static EditorPropertyRangeHint _parse_range_hint(PropertyHint p_hint, const String &p_hint_text, double p_default_step) { + EditorPropertyRangeHint hint; + hint.step = p_default_step; + bool degrees = false; + if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) { + hint.greater = false; //if using ranged, assume false by default + hint.lesser = false; + + hint.min = p_hint_text.get_slice(",", 0).to_float(); + hint.max = p_hint_text.get_slice(",", 1).to_float(); + if (p_hint_text.get_slice_count(",") >= 3) { + hint.step = p_hint_text.get_slice(",", 2).to_float(); + } + hint.hide_slider = false; + for (int i = 2; i < p_hint_text.get_slice_count(","); i++) { + String slice = p_hint_text.get_slice(",", i).strip_edges(); + if (slice == "radians") { + hint.radians = true; + } else if (slice == "degrees") { + degrees = true; + } else if (slice == "or_greater") { + hint.greater = true; + } else if (slice == "or_lesser") { + hint.lesser = true; + } else if (slice == "noslider") { + hint.hide_slider = true; + } else if (slice == "exp") { + hint.exp_range = true; + } else if (slice.begins_with("suffix:")) { + hint.suffix = " " + slice.replace_first("suffix:", "").strip_edges(); + } + } + } + + if ((hint.radians || degrees) && hint.suffix == String()) { + hint.suffix = U"\u00B0"; + } + + return hint; +} + +EditorProperty *EditorInspectorDefaultPlugin::get_editor_for_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const uint32_t p_usage, const bool p_wide) { double default_float_step = EDITOR_GET("interface/inspector/default_float_step"); switch (p_type) { // atomic types case Variant::NIL: { EditorPropertyNil *editor = memnew(EditorPropertyNil); - add_property_editor(p_path, editor); + return editor; } break; case Variant::BOOL: { EditorPropertyCheck *editor = memnew(EditorPropertyCheck); - add_property_editor(p_path, editor); + return editor; } break; case Variant::INT: { if (p_hint == PROPERTY_HINT_ENUM) { EditorPropertyEnum *editor = memnew(EditorPropertyEnum); Vector<String> options = p_hint_text.split(","); editor->setup(options); - add_property_editor(p_path, editor); + return editor; } else if (p_hint == PROPERTY_HINT_FLAGS) { EditorPropertyFlags *editor = memnew(EditorPropertyFlags); Vector<String> options = p_hint_text.split(","); editor->setup(options); - add_property_editor(p_path, editor); + return editor; } else if (p_hint == PROPERTY_HINT_LAYERS_2D_PHYSICS || p_hint == PROPERTY_HINT_LAYERS_2D_RENDER || @@ -2755,41 +2857,20 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ } EditorPropertyLayers *editor = memnew(EditorPropertyLayers); editor->setup(lt); - add_property_editor(p_path, editor); + return editor; } else if (p_hint == PROPERTY_HINT_OBJECT_ID) { EditorPropertyObjectID *editor = memnew(EditorPropertyObjectID); editor->setup(p_hint_text); - add_property_editor(p_path, editor); + return editor; } else { EditorPropertyInteger *editor = memnew(EditorPropertyInteger); - int min = 0, max = 65535, step = 1; - bool greater = true, lesser = true; - if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) { - greater = false; //if using ranged, assume false by default - lesser = false; - min = p_hint_text.get_slice(",", 0).to_int(); - max = p_hint_text.get_slice(",", 1).to_int(); + EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, 1); - if (p_hint_text.get_slice_count(",") >= 3) { - step = p_hint_text.get_slice(",", 2).to_int(); - } + editor->setup(hint.min, hint.max, hint.step, hint.greater, hint.lesser); - for (int i = 2; i < p_hint_text.get_slice_count(","); i++) { - String slice = p_hint_text.get_slice(",", i).strip_edges(); - if (slice == "or_greater") { - greater = true; - } - if (slice == "or_lesser") { - lesser = true; - } - } - } - - editor->setup(min, max, step, greater, lesser); - - add_property_editor(p_path, editor); + return editor; } } break; case Variant::FLOAT: { @@ -2809,39 +2890,15 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ } editor->setup(full, flip); - add_property_editor(p_path, editor); + return editor; } else { EditorPropertyFloat *editor = memnew(EditorPropertyFloat); - double min = -65535, max = 65535, step = default_float_step; - bool hide_slider = true; - bool exp_range = false; - bool greater = true, lesser = true; - - if ((p_hint == PROPERTY_HINT_RANGE || p_hint == PROPERTY_HINT_EXP_RANGE) && p_hint_text.get_slice_count(",") >= 2) { - greater = false; //if using ranged, assume false by default - lesser = false; - min = p_hint_text.get_slice(",", 0).to_float(); - max = p_hint_text.get_slice(",", 1).to_float(); - if (p_hint_text.get_slice_count(",") >= 3) { - step = p_hint_text.get_slice(",", 2).to_float(); - } - hide_slider = false; - exp_range = p_hint == PROPERTY_HINT_EXP_RANGE; - for (int i = 2; i < p_hint_text.get_slice_count(","); i++) { - String slice = p_hint_text.get_slice(",", i).strip_edges(); - if (slice == "or_greater") { - greater = true; - } - if (slice == "or_lesser") { - lesser = true; - } - } - } - editor->setup(min, max, step, hide_slider, exp_range, greater, lesser); + EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, default_float_step); + editor->setup(hint.min, hint.max, hint.step, hint.hide_slider, hint.exp_range, hint.greater, hint.lesser, hint.suffix, hint.radians); - add_property_editor(p_path, editor); + return editor; } } break; case Variant::STRING: { @@ -2849,14 +2906,14 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ EditorPropertyTextEnum *editor = memnew(EditorPropertyTextEnum); Vector<String> options = p_hint_text.split(","); editor->setup(options); - add_property_editor(p_path, editor); + return editor; } else if (p_hint == PROPERTY_HINT_MULTILINE_TEXT) { EditorPropertyMultilineText *editor = memnew(EditorPropertyMultilineText); - add_property_editor(p_path, editor); + return editor; } else if (p_hint == PROPERTY_HINT_TYPE_STRING) { EditorPropertyClassName *editor = memnew(EditorPropertyClassName); editor->setup("Object", p_hint_text); - add_property_editor(p_path, editor); + return editor; } else if (p_hint == PROPERTY_HINT_DIR || p_hint == PROPERTY_HINT_FILE || p_hint == PROPERTY_HINT_SAVE_FILE || p_hint == PROPERTY_HINT_GLOBAL_DIR || p_hint == PROPERTY_HINT_GLOBAL_FILE) { Vector<String> extensions = p_hint_text.split(","); bool global = p_hint == PROPERTY_HINT_GLOBAL_DIR || p_hint == PROPERTY_HINT_GLOBAL_FILE; @@ -2867,7 +2924,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ if (save) { editor->set_save_mode(); } - add_property_editor(p_path, editor); + return editor; } else if (p_hint == PROPERTY_HINT_METHOD_OF_VARIANT_TYPE || p_hint == PROPERTY_HINT_METHOD_OF_BASE_TYPE || p_hint == PROPERTY_HINT_METHOD_OF_INSTANCE || @@ -2905,14 +2962,14 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ } } editor->setup(type, p_hint_text); - add_property_editor(p_path, editor); + return editor; } else { EditorPropertyText *editor = memnew(EditorPropertyText); if (p_hint == PROPERTY_HINT_PLACEHOLDER_TEXT) { editor->set_placeholder(p_hint_text); } - add_property_editor(p_path, editor); + return editor; } } break; @@ -2920,204 +2977,82 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ case Variant::VECTOR2: { EditorPropertyVector2 *editor = memnew(EditorPropertyVector2(p_wide)); - double min = -65535, max = 65535, step = default_float_step; - bool hide_slider = true; - - if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) { - min = p_hint_text.get_slice(",", 0).to_float(); - max = p_hint_text.get_slice(",", 1).to_float(); - if (p_hint_text.get_slice_count(",") >= 3) { - step = p_hint_text.get_slice(",", 2).to_float(); - } - hide_slider = false; - } - editor->setup(min, max, step, hide_slider); - add_property_editor(p_path, editor); + EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, default_float_step); + editor->setup(hint.min, hint.max, hint.step, hint.hide_slider, hint.suffix); + return editor; } break; case Variant::VECTOR2I: { EditorPropertyVector2i *editor = memnew(EditorPropertyVector2i(p_wide)); - int min = -65535, max = 65535; - bool hide_slider = true; - - if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) { - min = p_hint_text.get_slice(",", 0).to_float(); - max = p_hint_text.get_slice(",", 1).to_float(); - hide_slider = false; - } - - editor->setup(min, max, hide_slider); - add_property_editor(p_path, editor); + EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, 1); + editor->setup(hint.min, hint.max, hint.hide_slider, hint.suffix); + return editor; } break; case Variant::RECT2: { EditorPropertyRect2 *editor = memnew(EditorPropertyRect2(p_wide)); - double min = -65535, max = 65535, step = default_float_step; - bool hide_slider = true; - - if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) { - min = p_hint_text.get_slice(",", 0).to_float(); - max = p_hint_text.get_slice(",", 1).to_float(); - if (p_hint_text.get_slice_count(",") >= 3) { - step = p_hint_text.get_slice(",", 2).to_float(); - } - hide_slider = false; - } - - editor->setup(min, max, step, hide_slider); - add_property_editor(p_path, editor); + EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, default_float_step); + editor->setup(hint.min, hint.max, hint.step, hint.hide_slider, hint.suffix); + return editor; } break; case Variant::RECT2I: { EditorPropertyRect2i *editor = memnew(EditorPropertyRect2i(p_wide)); - int min = -65535, max = 65535; - bool hide_slider = true; - - if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) { - min = p_hint_text.get_slice(",", 0).to_float(); - max = p_hint_text.get_slice(",", 1).to_float(); - hide_slider = false; - } + EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, 1); + editor->setup(hint.min, hint.max, hint.hide_slider, hint.suffix); - editor->setup(min, max, hide_slider); - add_property_editor(p_path, editor); + return editor; } break; case Variant::VECTOR3: { EditorPropertyVector3 *editor = memnew(EditorPropertyVector3(p_wide)); - double min = -65535, max = 65535, step = default_float_step; - bool hide_slider = true; - - if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) { - min = p_hint_text.get_slice(",", 0).to_float(); - max = p_hint_text.get_slice(",", 1).to_float(); - if (p_hint_text.get_slice_count(",") >= 3) { - step = p_hint_text.get_slice(",", 2).to_float(); - } - hide_slider = false; - } - - editor->setup(min, max, step, hide_slider); - add_property_editor(p_path, editor); + EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, default_float_step); + editor->setup(hint.min, hint.max, hint.step, hint.hide_slider, hint.suffix, hint.radians); + return editor; } break; case Variant::VECTOR3I: { EditorPropertyVector3i *editor = memnew(EditorPropertyVector3i(p_wide)); - int min = -65535, max = 65535; - bool hide_slider = true; - - if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) { - min = p_hint_text.get_slice(",", 0).to_float(); - max = p_hint_text.get_slice(",", 1).to_float(); - - hide_slider = false; - } - - editor->setup(min, max, hide_slider); - add_property_editor(p_path, editor); + EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, 1); + editor->setup(hint.min, hint.max, hint.hide_slider, hint.suffix); + return editor; } break; case Variant::TRANSFORM2D: { EditorPropertyTransform2D *editor = memnew(EditorPropertyTransform2D); - double min = -65535, max = 65535, step = default_float_step; - bool hide_slider = true; - - if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) { - min = p_hint_text.get_slice(",", 0).to_float(); - max = p_hint_text.get_slice(",", 1).to_float(); - if (p_hint_text.get_slice_count(",") >= 3) { - step = p_hint_text.get_slice(",", 2).to_float(); - } - hide_slider = false; - } - - editor->setup(min, max, step, hide_slider); - add_property_editor(p_path, editor); + EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, default_float_step); + editor->setup(hint.min, hint.max, hint.step, hint.hide_slider, hint.suffix); + return editor; } break; case Variant::PLANE: { EditorPropertyPlane *editor = memnew(EditorPropertyPlane(p_wide)); - double min = -65535, max = 65535, step = default_float_step; - bool hide_slider = true; - - if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) { - min = p_hint_text.get_slice(",", 0).to_float(); - max = p_hint_text.get_slice(",", 1).to_float(); - if (p_hint_text.get_slice_count(",") >= 3) { - step = p_hint_text.get_slice(",", 2).to_float(); - } - hide_slider = false; - } - - editor->setup(min, max, step, hide_slider); - add_property_editor(p_path, editor); + EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, default_float_step); + editor->setup(hint.min, hint.max, hint.step, hint.hide_slider, hint.suffix); + return editor; } break; case Variant::QUATERNION: { EditorPropertyQuaternion *editor = memnew(EditorPropertyQuaternion); - double min = -65535, max = 65535, step = default_float_step; - bool hide_slider = true; - - if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) { - min = p_hint_text.get_slice(",", 0).to_float(); - max = p_hint_text.get_slice(",", 1).to_float(); - if (p_hint_text.get_slice_count(",") >= 3) { - step = p_hint_text.get_slice(",", 2).to_float(); - } - hide_slider = false; - } - - editor->setup(min, max, step, hide_slider); - add_property_editor(p_path, editor); + EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, default_float_step); + editor->setup(hint.min, hint.max, hint.step, hint.hide_slider, hint.suffix); + return editor; } break; case Variant::AABB: { EditorPropertyAABB *editor = memnew(EditorPropertyAABB); - double min = -65535, max = 65535, step = default_float_step; - bool hide_slider = true; - - if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) { - min = p_hint_text.get_slice(",", 0).to_float(); - max = p_hint_text.get_slice(",", 1).to_float(); - if (p_hint_text.get_slice_count(",") >= 3) { - step = p_hint_text.get_slice(",", 2).to_float(); - } - hide_slider = false; - } - - editor->setup(min, max, step, hide_slider); - add_property_editor(p_path, editor); + EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, default_float_step); + editor->setup(hint.min, hint.max, hint.step, hint.hide_slider, hint.suffix); + return editor; } break; case Variant::BASIS: { EditorPropertyBasis *editor = memnew(EditorPropertyBasis); - double min = -65535, max = 65535, step = default_float_step; - bool hide_slider = true; - - if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) { - min = p_hint_text.get_slice(",", 0).to_float(); - max = p_hint_text.get_slice(",", 1).to_float(); - if (p_hint_text.get_slice_count(",") >= 3) { - step = p_hint_text.get_slice(",", 2).to_float(); - } - hide_slider = false; - } - - editor->setup(min, max, step, hide_slider); - add_property_editor(p_path, editor); + EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, default_float_step); + editor->setup(hint.min, hint.max, hint.step, hint.hide_slider, hint.suffix); + return editor; } break; case Variant::TRANSFORM3D: { EditorPropertyTransform3D *editor = memnew(EditorPropertyTransform3D); - double min = -65535, max = 65535, step = default_float_step; - bool hide_slider = true; - - if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) { - min = p_hint_text.get_slice(",", 0).to_float(); - max = p_hint_text.get_slice(",", 1).to_float(); - if (p_hint_text.get_slice_count(",") >= 3) { - step = p_hint_text.get_slice(",", 2).to_float(); - } - hide_slider = false; - } - - editor->setup(min, max, step, hide_slider); - add_property_editor(p_path, editor); + EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, default_float_step); + editor->setup(hint.min, hint.max, hint.step, hint.hide_slider, hint.suffix); + return editor; } break; @@ -3125,21 +3060,21 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ case Variant::COLOR: { EditorPropertyColor *editor = memnew(EditorPropertyColor); editor->setup(p_hint != PROPERTY_HINT_COLOR_NO_ALPHA); - add_property_editor(p_path, editor); + return editor; } break; case Variant::STRING_NAME: { if (p_hint == PROPERTY_HINT_ENUM) { EditorPropertyTextEnum *editor = memnew(EditorPropertyTextEnum); Vector<String> options = p_hint_text.split(","); editor->setup(options, true); - add_property_editor(p_path, editor); + return editor; } else { EditorPropertyText *editor = memnew(EditorPropertyText); if (p_hint == PROPERTY_HINT_PLACEHOLDER_TEXT) { editor->set_placeholder(p_hint_text); } editor->set_string_name(true); - add_property_editor(p_path, editor); + return editor; } } break; case Variant::NODE_PATH: { @@ -3152,12 +3087,12 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ Vector<StringName> sn = Variant(types); //convert via variant editor->setup(NodePath(), sn, (p_usage & PROPERTY_USAGE_NODE_PATH_FROM_SCENE_ROOT)); } - add_property_editor(p_path, editor); + return editor; } break; case Variant::RID: { EditorPropertyRID *editor = memnew(EditorPropertyRID); - add_property_editor(p_path, editor); + return editor; } break; case Variant::OBJECT: { EditorPropertyResource *editor = memnew(EditorPropertyResource); @@ -3176,70 +3111,66 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ } } - add_property_editor(p_path, editor); + return editor; } break; case Variant::DICTIONARY: { EditorPropertyDictionary *editor = memnew(EditorPropertyDictionary); - add_property_editor(p_path, editor); + return editor; } break; case Variant::ARRAY: { EditorPropertyArray *editor = memnew(EditorPropertyArray); editor->setup(Variant::ARRAY, p_hint_text); - add_property_editor(p_path, editor); + return editor; } break; case Variant::PACKED_BYTE_ARRAY: { EditorPropertyArray *editor = memnew(EditorPropertyArray); editor->setup(Variant::PACKED_BYTE_ARRAY); - add_property_editor(p_path, editor); + return editor; } break; case Variant::PACKED_INT32_ARRAY: { EditorPropertyArray *editor = memnew(EditorPropertyArray); editor->setup(Variant::PACKED_INT32_ARRAY); - add_property_editor(p_path, editor); + return editor; } break; case Variant::PACKED_INT64_ARRAY: { EditorPropertyArray *editor = memnew(EditorPropertyArray); editor->setup(Variant::PACKED_INT64_ARRAY); - add_property_editor(p_path, editor); + return editor; } break; case Variant::PACKED_FLOAT32_ARRAY: { EditorPropertyArray *editor = memnew(EditorPropertyArray); editor->setup(Variant::PACKED_FLOAT32_ARRAY); - add_property_editor(p_path, editor); + return editor; } break; case Variant::PACKED_FLOAT64_ARRAY: { EditorPropertyArray *editor = memnew(EditorPropertyArray); editor->setup(Variant::PACKED_FLOAT64_ARRAY); - add_property_editor(p_path, editor); + return editor; } break; case Variant::PACKED_STRING_ARRAY: { EditorPropertyArray *editor = memnew(EditorPropertyArray); editor->setup(Variant::PACKED_STRING_ARRAY); - add_property_editor(p_path, editor); + return editor; } break; case Variant::PACKED_VECTOR2_ARRAY: { EditorPropertyArray *editor = memnew(EditorPropertyArray); editor->setup(Variant::PACKED_VECTOR2_ARRAY); - add_property_editor(p_path, editor); + return editor; } break; case Variant::PACKED_VECTOR3_ARRAY: { EditorPropertyArray *editor = memnew(EditorPropertyArray); editor->setup(Variant::PACKED_VECTOR3_ARRAY); - add_property_editor(p_path, editor); + return editor; } break; case Variant::PACKED_COLOR_ARRAY: { EditorPropertyArray *editor = memnew(EditorPropertyArray); editor->setup(Variant::PACKED_COLOR_ARRAY); - add_property_editor(p_path, editor); + } break; default: { } } - return false; //can be overridden, although it will most likely be last anyway -} - -void EditorInspectorDefaultPlugin::parse_end() { - //do none + return nullptr; } diff --git a/editor/editor_properties.h b/editor/editor_properties.h index dcde7dda3d..d880017cc1 100644 --- a/editor/editor_properties.h +++ b/editor/editor_properties.h @@ -298,7 +298,8 @@ public: class EditorPropertyFloat : public EditorProperty { GDCLASS(EditorPropertyFloat, EditorProperty); EditorSpinSlider *spin; - bool setting; + bool setting = false; + bool angle_in_radians = false; void _value_changed(double p_val); protected: @@ -306,7 +307,7 @@ protected: public: virtual void update_property() override; - void setup(double p_min, double p_max, double p_step, bool p_no_slider, bool p_exp_range, bool p_greater, bool p_lesser); + void setup(double p_min, double p_max, double p_step, bool p_no_slider, bool p_exp_range, bool p_greater, bool p_lesser, const String &p_suffix = String(), bool p_angle_in_radians = false); EditorPropertyFloat(); }; @@ -363,7 +364,7 @@ protected: public: virtual void update_property() override; - void setup(double p_min, double p_max, double p_step, bool p_no_slider); + void setup(double p_min, double p_max, double p_step, bool p_no_slider, const String &p_suffix = String()); EditorPropertyVector2(bool p_force_wide = false); }; @@ -379,14 +380,15 @@ protected: public: virtual void update_property() override; - void setup(double p_min, double p_max, double p_step, bool p_no_slider); + void setup(double p_min, double p_max, double p_step, bool p_no_slider, const String &p_suffix = String()); EditorPropertyRect2(bool p_force_wide = false); }; class EditorPropertyVector3 : public EditorProperty { GDCLASS(EditorPropertyVector3, EditorProperty); EditorSpinSlider *spin[3]; - bool setting; + bool setting = false; + bool angle_in_radians = false; void _value_changed(double p_val, const String &p_name); protected: @@ -397,7 +399,7 @@ public: virtual void update_property() override; virtual void update_using_vector(Vector3 p_vector); virtual Vector3 get_vector(); - void setup(double p_min, double p_max, double p_step, bool p_no_slider); + void setup(double p_min, double p_max, double p_step, bool p_no_slider, const String &p_suffix = String(), bool p_angle_in_radians = false); EditorPropertyVector3(bool p_force_wide = false); }; @@ -413,7 +415,7 @@ protected: public: virtual void update_property() override; - void setup(int p_min, int p_max, bool p_no_slider); + void setup(int p_min, int p_max, bool p_no_slider, const String &p_suffix = String()); EditorPropertyVector2i(bool p_force_wide = false); }; @@ -429,7 +431,7 @@ protected: public: virtual void update_property() override; - void setup(int p_min, int p_max, bool p_no_slider); + void setup(int p_min, int p_max, bool p_no_slider, const String &p_suffix = String()); EditorPropertyRect2i(bool p_force_wide = false); }; @@ -445,7 +447,7 @@ protected: public: virtual void update_property() override; - void setup(int p_min, int p_max, bool p_no_slider); + void setup(int p_min, int p_max, bool p_no_slider, const String &p_suffix = String()); EditorPropertyVector3i(bool p_force_wide = false); }; @@ -461,7 +463,7 @@ protected: public: virtual void update_property() override; - void setup(double p_min, double p_max, double p_step, bool p_no_slider); + void setup(double p_min, double p_max, double p_step, bool p_no_slider, const String &p_suffix = String()); EditorPropertyPlane(bool p_force_wide = false); }; @@ -477,7 +479,7 @@ protected: public: virtual void update_property() override; - void setup(double p_min, double p_max, double p_step, bool p_no_slider); + void setup(double p_min, double p_max, double p_step, bool p_no_slider, const String &p_suffix = String()); EditorPropertyQuaternion(); }; @@ -493,7 +495,7 @@ protected: public: virtual void update_property() override; - void setup(double p_min, double p_max, double p_step, bool p_no_slider); + void setup(double p_min, double p_max, double p_step, bool p_no_slider, const String &p_suffix = String()); EditorPropertyAABB(); }; @@ -509,7 +511,7 @@ protected: public: virtual void update_property() override; - void setup(double p_min, double p_max, double p_step, bool p_no_slider); + void setup(double p_min, double p_max, double p_step, bool p_no_slider, const String &p_suffix = String()); EditorPropertyTransform2D(); }; @@ -525,7 +527,7 @@ protected: public: virtual void update_property() override; - void setup(double p_min, double p_max, double p_step, bool p_no_slider); + void setup(double p_min, double p_max, double p_step, bool p_no_slider, const String &p_suffix = String()); EditorPropertyBasis(); }; @@ -542,7 +544,7 @@ protected: public: virtual void update_property() override; virtual void update_using_transform(Transform3D p_transform); - void setup(double p_min, double p_max, double p_step, bool p_no_slider); + void setup(double p_min, double p_max, double p_step, bool p_no_slider, const String &p_suffix = String()); EditorPropertyTransform3D(); }; @@ -647,8 +649,10 @@ class EditorInspectorDefaultPlugin : public EditorInspectorPlugin { public: virtual bool can_handle(Object *p_object) override; virtual void parse_begin(Object *p_object) override; - virtual bool parse_property(Object *p_object, Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, int p_usage, bool p_wide = false) override; + virtual bool parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const uint32_t p_usage, const bool p_wide = false) override; virtual void parse_end() override; + + static EditorProperty *get_editor_for_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const uint32_t p_usage, const bool p_wide = false); }; #endif // EDITOR_PROPERTIES_H diff --git a/editor/editor_properties_array_dict.cpp b/editor/editor_properties_array_dict.cpp index 66fabcd940..3216728be1 100644 --- a/editor/editor_properties_array_dict.cpp +++ b/editor/editor_properties_array_dict.cpp @@ -337,7 +337,7 @@ void EditorPropertyArray::update_property() { editor->setup("Object"); prop = editor; } else { - prop = EditorInspector::instantiate_property_editor(nullptr, value_type, "", subtype_hint, subtype_hint_string, 0); + prop = EditorInspector::instantiate_property_editor(nullptr, value_type, "", subtype_hint, subtype_hint_string, PROPERTY_USAGE_NONE); } prop->set_object_and_property(object.ptr(), prop_name); @@ -550,6 +550,8 @@ void EditorPropertyArray::_length_changed(double p_page) { void EditorPropertyArray::setup(Variant::Type p_array_type, const String &p_hint_string) { array_type = p_array_type; + // The format of p_hint_string is: + // subType/subTypeHint:nextSubtype ... etc if (array_type == Variant::ARRAY && !p_hint_string.is_empty()) { int hint_subtype_separator = p_hint_string.find(":"); if (hint_subtype_separator >= 0) { @@ -572,7 +574,7 @@ void EditorPropertyArray::_bind_methods() { } EditorPropertyArray::EditorPropertyArray() { - object.instance(); + object.instantiate(); page_len = int(EDITOR_GET("interface/inspector/max_array_dictionary_items_per_page")); edit = memnew(Button); edit->set_h_size_flags(SIZE_EXPAND_FILL); @@ -971,7 +973,7 @@ void EditorPropertyDictionary::update_property() { PanelContainer *pc = memnew(PanelContainer); vbox->add_child(pc); Ref<StyleBoxFlat> flat; - flat.instance(); + flat.instantiate(); for (int j = 0; j < 4; j++) { flat->set_default_margin(Side(j), 2 * EDSCALE); } @@ -1066,7 +1068,7 @@ void EditorPropertyDictionary::_bind_methods() { } EditorPropertyDictionary::EditorPropertyDictionary() { - object.instance(); + object.instantiate(); page_len = int(EDITOR_GET("interface/inspector/max_array_dictionary_items_per_page")); edit = memnew(Button); edit->set_h_size_flags(SIZE_EXPAND_FILL); diff --git a/editor/editor_resource_picker.cpp b/editor/editor_resource_picker.cpp index b591007a93..350fc5eccb 100644 --- a/editor/editor_resource_picker.cpp +++ b/editor/editor_resource_picker.cpp @@ -271,7 +271,7 @@ void EditorResourcePicker::_edit_menu_cbk(int p_which) { } String orig_type = edited_resource->get_class(); - Object *inst = ClassDB::instance(orig_type); + Object *inst = ClassDB::instantiate(orig_type); Ref<Resource> unique_resource = Ref<Resource>(Object::cast_to<Resource>(inst)); ERR_FAIL_COND(unique_resource.is_null()); @@ -334,7 +334,7 @@ void EditorResourcePicker::_edit_menu_cbk(int p_which) { Variant obj; if (ScriptServer::is_global_class(intype)) { - obj = ClassDB::instance(ScriptServer::get_global_class_native_base(intype)); + obj = ClassDB::instantiate(ScriptServer::get_global_class_native_base(intype)); if (obj) { Ref<Script> script = ResourceLoader::load(ScriptServer::get_global_class_path(intype)); if (script.is_valid()) { @@ -342,7 +342,7 @@ void EditorResourcePicker::_edit_menu_cbk(int p_which) { } } } else { - obj = ClassDB::instance(intype); + obj = ClassDB::instantiate(intype); } if (!obj) { @@ -395,7 +395,7 @@ void EditorResourcePicker::set_create_options(Object *p_menu_node) { } } - if (!is_custom_resource && !(ScriptServer::is_global_class(t) || ClassDB::can_instance(t))) { + if (!is_custom_resource && !(ScriptServer::is_global_class(t) || ClassDB::can_instantiate(t))) { continue; } diff --git a/editor/editor_resource_preview.cpp b/editor/editor_resource_preview.cpp index 0f1b70936a..f904ae80a7 100644 --- a/editor/editor_resource_preview.cpp +++ b/editor/editor_resource_preview.cpp @@ -177,7 +177,7 @@ void EditorResourcePreview::_generate_preview(Ref<ImageTexture> &r_texture, Ref< Ref<Image> small_image = r_texture->get_image(); small_image = small_image->duplicate(); small_image->resize(small_thumbnail_size, small_thumbnail_size, Image::INTERPOLATE_CUBIC); - r_small_texture.instance(); + r_small_texture.instantiate(); r_small_texture->create_from_image(small_image); } @@ -293,21 +293,21 @@ void EditorResourcePreview::_thread() { if (cache_valid) { Ref<Image> img; - img.instance(); + img.instantiate(); Ref<Image> small_img; - small_img.instance(); + small_img.instantiate(); if (img->load(cache_base + ".png") != OK) { cache_valid = false; } else { - texture.instance(); + texture.instantiate(); texture->create_from_image(img); if (has_small_texture) { if (small_img->load(cache_base + "_small.png") != OK) { cache_valid = false; } else { - small_texture.instance(); + small_texture.instantiate(); small_texture->create_from_image(small_img); } } diff --git a/editor/editor_run_native.cpp b/editor/editor_run_native.cpp index 1ffa20d1ea..a604022391 100644 --- a/editor/editor_run_native.cpp +++ b/editor/editor_run_native.cpp @@ -49,7 +49,7 @@ void EditorRunNative::_notification(int p_what) { if (!im->is_empty()) { im->resize(16 * EDSCALE, 16 * EDSCALE); Ref<ImageTexture> small_icon; - small_icon.instance(); + small_icon.instantiate(); small_icon->create_from_image(im); MenuButton *mb = memnew(MenuButton); mb->get_popup()->connect("id_pressed", callable_mp(this, &EditorRunNative::_run_native), varray(i)); diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index 3f66326b41..080563f375 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -79,7 +79,7 @@ bool EditorSettings::_set_only(const StringName &p_name, const Variant &p_value) Ref<InputEvent> shortcut = arr[i + 1]; Ref<Shortcut> sc; - sc.instance(); + sc.instantiate(); sc->set_shortcut(shortcut); add_shortcut(name, sc); } @@ -240,19 +240,19 @@ void EditorSettings::_get_property_list(List<PropertyInfo> *p_list) const { } for (Set<_EVCSort>::Element *E = vclist.front(); E; E = E->next()) { - int pinfo = 0; + uint32_t pusage = PROPERTY_USAGE_NONE; if (E->get().save || !optimize_save) { - pinfo |= PROPERTY_USAGE_STORAGE; + pusage |= PROPERTY_USAGE_STORAGE; } if (!E->get().name.begins_with("_") && !E->get().name.begins_with("projects/")) { - pinfo |= PROPERTY_USAGE_EDITOR; + pusage |= PROPERTY_USAGE_EDITOR; } else { - pinfo |= PROPERTY_USAGE_STORAGE; //hiddens must always be saved + pusage |= PROPERTY_USAGE_STORAGE; //hiddens must always be saved } PropertyInfo pi(E->get().type, E->get().name); - pi.usage = pinfo; + pi.usage = pusage; if (hints.has(E->get().name)) { pi = hints[E->get().name]; } @@ -631,6 +631,7 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) { _initial_set("editors/3d/navigation/zoom_style", 0); hints["editors/3d/navigation/zoom_style"] = PropertyInfo(Variant::INT, "editors/3d/navigation/zoom_style", PROPERTY_HINT_ENUM, "Vertical, Horizontal"); + _initial_set("editors/3d/navigation/emulate_numpad", false); _initial_set("editors/3d/navigation/emulate_3_button_mouse", false); _initial_set("editors/3d/navigation/orbit_modifier", 0); hints["editors/3d/navigation/orbit_modifier"] = PropertyInfo(Variant::INT, "editors/3d/navigation/orbit_modifier", PROPERTY_HINT_ENUM, "None,Shift,Alt,Meta,Ctrl"); @@ -1476,7 +1477,7 @@ Ref<Shortcut> EditorSettings::get_shortcut(const String &p_name) const { Ref<Shortcut> sc; const Map<String, List<Ref<InputEvent>>>::Element *builtin_override = builtin_action_overrides.find(p_name); if (builtin_override) { - sc.instance(); + sc.instantiate(); sc->set_shortcut(builtin_override->get().front()->get()); sc->set_name(InputMap::get_singleton()->get_builtin_display_name(p_name)); } @@ -1485,7 +1486,7 @@ Ref<Shortcut> EditorSettings::get_shortcut(const String &p_name) const { if (sc.is_null()) { const OrderedHashMap<String, List<Ref<InputEvent>>>::ConstElement builtin_default = InputMap::get_singleton()->get_builtins().find(p_name); if (builtin_default) { - sc.instance(); + sc.instantiate(); sc->set_shortcut(builtin_default.get().front()->get()); sc->set_name(InputMap::get_singleton()->get_builtin_display_name(p_name)); } @@ -1528,7 +1529,7 @@ Ref<Shortcut> ED_SHORTCUT(const String &p_path, const String &p_name, uint32_t p Ref<InputEventKey> ie; if (p_keycode) { - ie.instance(); + ie.instantiate(); ie->set_unicode(p_keycode & KEY_CODE_MASK); ie->set_keycode(p_keycode & KEY_CODE_MASK); @@ -1540,7 +1541,7 @@ Ref<Shortcut> ED_SHORTCUT(const String &p_path, const String &p_name, uint32_t p if (!EditorSettings::get_singleton()) { Ref<Shortcut> sc; - sc.instance(); + sc.instantiate(); sc->set_name(p_name); sc->set_shortcut(ie); sc->set_meta("original", ie); @@ -1554,7 +1555,7 @@ Ref<Shortcut> ED_SHORTCUT(const String &p_path, const String &p_name, uint32_t p return sc; } - sc.instance(); + sc.instantiate(); sc->set_name(p_name); sc->set_shortcut(ie); sc->set_meta("original", ie); //to compare against changes @@ -1585,7 +1586,7 @@ void EditorSettings::set_builtin_action_override(const String &p_name, const Arr // Check equality of each event. for (List<Ref<InputEvent>>::Element *E = builtin_events.front(); E; E = E->next()) { - if (!E->get()->shortcut_match(p_events[event_idx])) { + if (!E->get()->is_match(p_events[event_idx])) { same_as_builtin = false; break; } diff --git a/editor/editor_spin_slider.cpp b/editor/editor_spin_slider.cpp index 4f0d75ecce..aa4a394d30 100644 --- a/editor/editor_spin_slider.cpp +++ b/editor/editor_spin_slider.cpp @@ -206,24 +206,34 @@ void EditorSpinSlider::_notification(int p_what) { // EditorSpinSliders with a label have more space on the left, so add an // higher margin to match the location where the text begins. // The margin values below were determined by empirical testing. - stylebox->set_default_margin(SIDE_LEFT, (get_label() != String() ? 23 : 16) * EDSCALE); + if (is_layout_rtl()) { + stylebox->set_default_margin(SIDE_LEFT, 0); + stylebox->set_default_margin(SIDE_RIGHT, (get_label() != String() ? 23 : 16) * EDSCALE); + } else { + stylebox->set_default_margin(SIDE_LEFT, (get_label() != String() ? 23 : 16) * EDSCALE); + stylebox->set_default_margin(SIDE_RIGHT, 0); + } value_input->add_theme_style_override("normal", stylebox); } if (p_what == NOTIFICATION_DRAW) { updown_offset = -1; + RID ci = get_canvas_item(); + bool rtl = is_layout_rtl(); + Vector2 size = get_size(); + Ref<StyleBox> sb = get_theme_stylebox("normal", "LineEdit"); if (!flat) { - draw_style_box(sb, Rect2(Vector2(), get_size())); + draw_style_box(sb, Rect2(Vector2(), size)); } Ref<Font> font = get_theme_font("font", "LineEdit"); int font_size = get_theme_font_size("font_size", "LineEdit"); int sep_base = 4 * EDSCALE; int sep = sep_base + sb->get_offset().x; //make it have the same margin on both sides, looks better - int string_width = font->get_string_size(label, font_size).width; - int number_width = get_size().width - sb->get_minimum_size().width - string_width - sep; + int label_width = font->get_string_size(label, font_size).width; + int number_width = size.width - sb->get_minimum_size().width - label_width - sep; Ref<Texture2D> updown = get_theme_icon("updown", "SpinBox"); @@ -233,7 +243,7 @@ void EditorSpinSlider::_notification(int p_what) { String numstr = get_text_value(); - int vofs = (get_size().height - font->get_height(font_size)) / 2 + font->get_ascent(font_size); + int vofs = (size.height - font->get_height(font_size)) / 2 + font->get_ascent(font_size); Color fc = get_theme_color("font_color", "LineEdit"); Color lc; @@ -245,22 +255,59 @@ void EditorSpinSlider::_notification(int p_what) { if (flat && label != String()) { Color label_bg_color = get_theme_color("dark_color_3", "Editor"); - draw_rect(Rect2(Vector2(), Vector2(sb->get_offset().x * 2 + string_width, get_size().height)), label_bg_color); + if (rtl) { + draw_rect(Rect2(Vector2(size.width - (sb->get_offset().x * 2 + label_width), 0), Vector2(sb->get_offset().x * 2 + label_width, size.height)), label_bg_color); + } else { + draw_rect(Rect2(Vector2(), Vector2(sb->get_offset().x * 2 + label_width, size.height)), label_bg_color); + } } if (has_focus()) { Ref<StyleBox> focus = get_theme_stylebox("focus", "LineEdit"); - draw_style_box(focus, Rect2(Vector2(), get_size())); + draw_style_box(focus, Rect2(Vector2(), size)); } - draw_string(font, Vector2(Math::round(sb->get_offset().x), vofs), label, HALIGN_LEFT, -1, font_size, lc * Color(1, 1, 1, 0.5)); + if (rtl) { + draw_string(font, Vector2(Math::round(size.width - sb->get_offset().x - label_width), vofs), label, HALIGN_RIGHT, -1, font_size, lc * Color(1, 1, 1, 0.5)); + } else { + draw_string(font, Vector2(Math::round(sb->get_offset().x), vofs), label, HALIGN_LEFT, -1, font_size, lc * Color(1, 1, 1, 0.5)); + } - draw_string(font, Vector2(Math::round(sb->get_offset().x + string_width + sep), vofs), numstr, HALIGN_LEFT, number_width, font_size, fc); + int suffix_start = numstr.length(); + RID num_rid = TS->create_shaped_text(); + TS->shaped_text_add_string(num_rid, numstr + U"\u2009" + suffix, font->get_rids(), font_size); + + float text_start = rtl ? Math::round(sb->get_offset().x) : Math::round(sb->get_offset().x + label_width + sep); + Vector2 text_ofs = rtl ? Vector2(text_start + (number_width - TS->shaped_text_get_width(num_rid)), vofs) : Vector2(text_start, vofs); + const Vector<TextServer::Glyph> visual = TS->shaped_text_get_glyphs(num_rid); + int v_size = visual.size(); + const TextServer::Glyph *glyphs = visual.ptr(); + for (int i = 0; i < v_size; i++) { + for (int j = 0; j < glyphs[i].repeat; j++) { + if (text_ofs.x >= text_start && (text_ofs.x + glyphs[i].advance) <= (text_start + number_width)) { + Color color = fc; + if (glyphs[i].start >= suffix_start) { + color.a *= 0.4; + } + if (glyphs[i].font_rid != RID()) { + TS->font_draw_glyph(glyphs[i].font_rid, ci, glyphs[i].font_size, text_ofs + Vector2(glyphs[i].x_off, glyphs[i].y_off), glyphs[i].index, color); + } else if ((glyphs[i].flags & TextServer::GRAPHEME_IS_VIRTUAL) != TextServer::GRAPHEME_IS_VIRTUAL) { + TS->draw_hex_code_box(ci, glyphs[i].font_size, text_ofs + Vector2(glyphs[i].x_off, glyphs[i].y_off), glyphs[i].index, color); + } + } + text_ofs.x += glyphs[i].advance; + } + } + TS->free(num_rid); if (get_step() == 1) { Ref<Texture2D> updown2 = get_theme_icon("updown", "SpinBox"); - int updown_vofs = (get_size().height - updown2->get_height()) / 2; - updown_offset = get_size().width - sb->get_margin(SIDE_RIGHT) - updown2->get_width(); + int updown_vofs = (size.height - updown2->get_height()) / 2; + if (rtl) { + updown_offset = sb->get_margin(SIDE_LEFT); + } else { + updown_offset = size.width - sb->get_margin(SIDE_RIGHT) - updown2->get_width(); + } Color c(1, 1, 1); if (hover_updown) { c *= Color(1.2, 1.2, 1.2); @@ -271,9 +318,9 @@ void EditorSpinSlider::_notification(int p_what) { } } else if (!hide_slider) { int grabber_w = 4 * EDSCALE; - int width = get_size().width - sb->get_minimum_size().width - grabber_w; + int width = size.width - sb->get_minimum_size().width - grabber_w; int ofs = sb->get_offset().x; - int svofs = (get_size().height + vofs) / 2 - 1; + int svofs = (size.height + vofs) / 2 - 1; Color c = fc; c.a = 0.2; @@ -365,6 +412,15 @@ String EditorSpinSlider::get_label() const { return label; } +void EditorSpinSlider::set_suffix(const String &p_suffix) { + suffix = p_suffix; + update(); +} + +String EditorSpinSlider::get_suffix() const { + return suffix; +} + void EditorSpinSlider::_evaluate_input_text() { // Replace comma with dot to support it as decimal separator (GH-6028). // This prevents using functions like `pow()`, but using functions @@ -373,7 +429,7 @@ void EditorSpinSlider::_evaluate_input_text() { const String text = TS->parse_number(value_input->get_text().replace(",", ".")); Ref<Expression> expr; - expr.instance(); + expr.instantiate(); Error err = expr->parse(text); if (err != OK) { return; @@ -468,6 +524,9 @@ void EditorSpinSlider::_bind_methods() { ClassDB::bind_method(D_METHOD("set_label", "label"), &EditorSpinSlider::set_label); ClassDB::bind_method(D_METHOD("get_label"), &EditorSpinSlider::get_label); + ClassDB::bind_method(D_METHOD("set_suffix", "suffix"), &EditorSpinSlider::set_suffix); + ClassDB::bind_method(D_METHOD("get_suffix"), &EditorSpinSlider::get_suffix); + ClassDB::bind_method(D_METHOD("set_read_only", "read_only"), &EditorSpinSlider::set_read_only); ClassDB::bind_method(D_METHOD("is_read_only"), &EditorSpinSlider::is_read_only); @@ -477,6 +536,7 @@ void EditorSpinSlider::_bind_methods() { ClassDB::bind_method(D_METHOD("_gui_input"), &EditorSpinSlider::_gui_input); ADD_PROPERTY(PropertyInfo(Variant::STRING, "label"), "set_label", "get_label"); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "suffix"), "set_suffix", "get_suffix"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "read_only"), "set_read_only", "is_read_only"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "flat"), "set_flat", "is_flat"); } diff --git a/editor/editor_spin_slider.h b/editor/editor_spin_slider.h index 50d04c9583..c30ff30390 100644 --- a/editor/editor_spin_slider.h +++ b/editor/editor_spin_slider.h @@ -39,6 +39,7 @@ class EditorSpinSlider : public Range { GDCLASS(EditorSpinSlider, Range); String label; + String suffix; int updown_offset; bool hover_updown; bool mouse_hover; @@ -93,6 +94,9 @@ public: void set_label(const String &p_label); String get_label() const; + void set_suffix(const String &p_suffix); + String get_suffix() const; + void set_hide_slider(bool p_hide); bool is_hiding_slider() const; diff --git a/editor/editor_themes.cpp b/editor/editor_themes.cpp index fa543b7455..131a77e52f 100644 --- a/editor/editor_themes.cpp +++ b/editor/editor_themes.cpp @@ -766,12 +766,12 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { theme->set_stylebox("sub_inspector_bg" + itos(i), "Editor", sub_inspector_bg); Ref<StyleBoxFlat> bg_color; - bg_color.instance(); + bg_color.instantiate(); bg_color->set_bg_color(si_base_color * Color(0.7, 0.7, 0.7, 0.8)); bg_color->set_border_width_all(0); Ref<StyleBoxFlat> bg_color_selected; - bg_color_selected.instance(); + bg_color_selected.instantiate(); bg_color_selected->set_border_width_all(0); bg_color_selected->set_bg_color(si_base_color * Color(0.8, 0.8, 0.8, 0.8)); diff --git a/editor/editor_vcs_interface.h b/editor/editor_vcs_interface.h index af952eaffc..52ab6d68ee 100644 --- a/editor/editor_vcs_interface.h +++ b/editor/editor_vcs_interface.h @@ -46,16 +46,16 @@ protected: static void _bind_methods(); // Implemented by addons as end points for the proxy functions - bool _initialize(String p_project_root_path); - bool _is_vcs_initialized(); - Dictionary _get_modified_files_data(); - void _stage_file(String p_file_path); - void _unstage_file(String p_file_path); - void _commit(String p_msg); - Array _get_file_diff(String p_file_path); - bool _shut_down(); - String _get_project_name(); - String _get_vcs_name(); + virtual bool _initialize(String p_project_root_path); + virtual bool _is_vcs_initialized(); + virtual Dictionary _get_modified_files_data(); + virtual void _stage_file(String p_file_path); + virtual void _unstage_file(String p_file_path); + virtual void _commit(String p_msg); + virtual Array _get_file_diff(String p_file_path); + virtual bool _shut_down(); + virtual String _get_project_name(); + virtual String _get_vcs_name(); public: static EditorVCSInterface *get_singleton(); diff --git a/editor/export_template_manager.cpp b/editor/export_template_manager.cpp index 76c6fcc3d3..dd4ce74406 100644 --- a/editor/export_template_manager.cpp +++ b/editor/export_template_manager.cpp @@ -242,10 +242,8 @@ void ExportTemplateManager::_refresh_mirrors_completed(int p_status, int p_code, response_json.parse_utf8((const char *)r, p_data.size()); } - Variant response; - String errs; - int errline; - Error err = JSON::parse(response_json, response, errs, errline); + JSON json; + Error err = json.parse(response_json); if (err != OK) { EditorNode::get_singleton()->show_warning(TTR("Error parsing JSON with the list of mirrors. Please report this issue!")); is_refreshing_mirrors = false; @@ -260,7 +258,7 @@ void ExportTemplateManager::_refresh_mirrors_completed(int p_status, int p_code, mirrors_available = false; - Dictionary data = response; + Dictionary data = json.get_data(); if (data.has("mirrors")) { Array mirrors = data["mirrors"]; diff --git a/editor/fileserver/editor_file_server.cpp b/editor/fileserver/editor_file_server.cpp index 654915e3e5..8f019a95fd 100644 --- a/editor/fileserver/editor_file_server.cpp +++ b/editor/fileserver/editor_file_server.cpp @@ -312,7 +312,7 @@ void EditorFileServer::stop() { } EditorFileServer::EditorFileServer() { - server.instance(); + server.instantiate(); quit = false; active = false; cmd = CMD_NONE; diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index fe1fa9f9d6..3dc854d6bd 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -815,7 +815,8 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) { if (searched_string.length() > 0) { // Display the search results. - _search(EditorFileSystem::get_singleton()->get_filesystem(), &file_list, 128); + // Limit the number of results displayed to avoid an infinite loop. + _search(EditorFileSystem::get_singleton()->get_filesystem(), &file_list, 10000); } else { if (display_mode == DISPLAY_MODE_TREE_ONLY || always_show_folders) { // Display folders in the list. @@ -945,7 +946,7 @@ void FileSystemDock::_select_file(const String &p_path, bool p_select_in_favorit } else if (fpath != "Favorites") { if (FileAccess::exists(fpath + ".import")) { Ref<ConfigFile> config; - config.instance(); + config.instantiate(); Error err = config->load(fpath + ".import"); if (err == OK) { if (config->has_section_key("remap", "importer")) { @@ -1985,20 +1986,6 @@ void FileSystemDock::_resource_created() { editor->save_resource_as(RES(r), fpath); } -void FileSystemDock::_focus_current_search_box() { - LineEdit *current_search_box = nullptr; - if (display_mode == DISPLAY_MODE_TREE_ONLY) { - current_search_box = tree_search_box; - } else if (display_mode == DISPLAY_MODE_SPLIT) { - current_search_box = file_list_search_box; - } - - if (current_search_box) { - current_search_box->grab_focus(); - current_search_box->select_all(); - } -} - void FileSystemDock::_search_changed(const String &p_text, const Control *p_from) { if (searched_string.length() == 0) { // Register the uncollapsed paths before they change. @@ -2040,7 +2027,17 @@ void FileSystemDock::fix_dependencies(const String &p_for_file) { } void FileSystemDock::focus_on_filter() { - file_list_search_box->grab_focus(); + LineEdit *current_search_box = nullptr; + if (display_mode == DISPLAY_MODE_TREE_ONLY) { + current_search_box = tree_search_box; + } else if (display_mode == DISPLAY_MODE_SPLIT) { + current_search_box = file_list_search_box; + } + + if (current_search_box) { + current_search_box->grab_focus(); + current_search_box->select_all(); + } } void FileSystemDock::set_file_list_display_mode(FileListDisplayMode p_mode) { @@ -2590,7 +2587,7 @@ void FileSystemDock::_tree_gui_input(Ref<InputEvent> p_event) { } else if (ED_IS_SHORTCUT("filesystem_dock/rename", p_event)) { _tree_rmb_option(FILE_RENAME); } else if (ED_IS_SHORTCUT("editor/open_search", p_event)) { - _focus_current_search_box(); + focus_on_filter(); } else { return; } @@ -2611,7 +2608,7 @@ void FileSystemDock::_file_list_gui_input(Ref<InputEvent> p_event) { } else if (ED_IS_SHORTCUT("filesystem_dock/rename", p_event)) { _file_list_rmb_option(FILE_RENAME); } else if (ED_IS_SHORTCUT("editor/open_search", p_event)) { - _focus_current_search_box(); + focus_on_filter(); } else { return; } @@ -2675,7 +2672,7 @@ void FileSystemDock::_update_import_dock() { for (int i = 0; i < efiles.size(); i++) { String fpath = efiles[i]; Ref<ConfigFile> cf; - cf.instance(); + cf.instantiate(); Error err = cf->load(fpath + ".import"); if (err != OK) { imports.clear(); diff --git a/editor/filesystem_dock.h b/editor/filesystem_dock.h index 12c567fb69..21a7abe622 100644 --- a/editor/filesystem_dock.h +++ b/editor/filesystem_dock.h @@ -253,7 +253,6 @@ private: void _toggle_split_mode(bool p_active); - void _focus_current_search_box(); void _search_changed(const String &p_text, const Control *p_from); MenuButton *_create_file_menu_button(); diff --git a/editor/find_in_files.cpp b/editor/find_in_files.cpp index c29b5d5906..cb8de09a9a 100644 --- a/editor/find_in_files.cpp +++ b/editor/find_in_files.cpp @@ -638,7 +638,7 @@ void FindInFilesPanel::set_with_replace(bool with_replace) { // Results show checkboxes on their left so they can be opted out _results_display->set_columns(2); _results_display->set_column_expand(0, false); - _results_display->set_column_min_width(0, 48 * EDSCALE); + _results_display->set_column_custom_minimum_width(0, 48 * EDSCALE); } else { // Results are single-cell items diff --git a/editor/icons/CenterView.svg b/editor/icons/CenterView.svg new file mode 100644 index 0000000000..c2a918fe81 --- /dev/null +++ b/editor/icons/CenterView.svg @@ -0,0 +1 @@ +<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><circle cx="4" cy="12" fill="none" r="2"/><g fill="#e0e0e0"><path d="m7.3333333 6c-.7386666 0-1.3333333.5946667-1.3333333 1.3333333v1.3333334c0 .7386663.5946667 1.3333333 1.3333333 1.3333333h1.3333334c.7386666 0 1.3333333-.594667 1.3333333-1.3333333v-1.3333334c0-.7386666-.5946667-1.3333333-1.3333333-1.3333333z" stroke-width=".666667"/><g stroke-width=".830398"><path d="m2.9918978 5.5000002c-.7478701.0001968-1.1170118.9026572-.5810669 1.4205652l.2441488.2424178h-2.15497967v1.6548989h2.15497967l-.2441488.242418c-.8159014.77992.3929613 1.9802119 1.178451 1.1700959l1.6667154-1.6548989c.3253369-.3231472.3253369-.8469488 0-1.170096l-1.6667154-1.6548989c-.1568986-.1601378-.3723426-.2504824-.5973507-.2504937z"/><path d="m13.008102 10.5c.74787-.000197 1.117012-.9026571.581067-1.4205651l-.244149-.242418h2.15498v-1.6548988h-2.15498l.244149-.2424179c.815901-.7799207-.392961-1.9802122-1.178451-1.1700961l-1.666715 1.6548987c-.325337.3231474-.325337.846949 0 1.1700961l1.666715 1.6548991c.156899.160138.372343.250482.597351.250494z"/><path d="m5.5000001 13.008102c.000197.74787.902657 1.117012 1.420565.581067l.242418-.244149v2.15498h1.654899v-2.15498l.242418.244149c.77992.815901 1.9802119-.392961 1.1700959-1.178451l-1.6548989-1.666715c-.323147-.325337-.846949-.325337-1.170096 0l-1.654899 1.666715c-.160138.156899-.250482.372343-.250494.597351z"/><path d="m10.5 2.9918983c-.000197-.7478701-.9026571-1.1170121-1.4205651-.581067l-.242418.244149v-2.1549801h-1.6548989v2.1549801l-.242418-.2441491c-.77992-.815901-1.9802121.3929611-1.170096 1.1784512l1.654899 1.6667148c.3231469.325337.8469489.325337 1.1700959 0l1.6548991-1.6667148c.160138-.156899.250482-.3723431.250494-.597351z"/></g></g></svg> diff --git a/editor/icons/ImmediateMesh.svg b/editor/icons/ImmediateMesh.svg new file mode 100644 index 0000000000..9521530876 --- /dev/null +++ b/editor/icons/ImmediateMesh.svg @@ -0,0 +1 @@ +<svg height="16" viewBox="0 0 14.999999 14.999999" width="16" xmlns="http://www.w3.org/2000/svg"><path d="m2 2v2h5v-2zm5 2v3h2v-3zm2-2v2h5v-2zm-2 7v3h2v-3zm-5 3v2h5v-2zm7 0v2h5v-2z" fill="#ffca5f" transform="scale(.93749994)"/></svg> diff --git a/editor/icons/ORMMaterial3D.svg b/editor/icons/ORMMaterial3D.svg index 3d6db6910d..e09208155d 100644 --- a/editor/icons/ORMMaterial3D.svg +++ b/editor/icons/ORMMaterial3D.svg @@ -1 +1 @@ -<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><path d="m5.0534707 10.652714q0 .729229-.4538398 1.253141-.4538403.516832-1.0868283.516832h-1.1943162q-.6389592 0-1.1047425-.509753-.47175502-.509751-.47175502-1.26022v-5.5223119q0-.7575473.47175502-1.2672998.4717549-.5097517 1.1047425-.5097517h1.1943162q.6270165 0 1.0868283.516832.4538398.5168313.4538398 1.2602195zm-1.0808559-.233636v-5.0550395q0-.5734707-.3344086-.8141867-.1074887-.0849591-.2567782-.0778788h-.9912826q-.2567779 0-.4120391.2690357-.1552611.2690357-.1552611.6230298v5.0550395q0 .559311.3164938.807108.1074885.08496.2508064.08496h.9912826q.2746925 0 .4359254-.276116.1552614-.276115.1552614-.61595z" fill="#f00"/><path d="m9.9872948 12.451006h-1.0427362l-1.4698137-3.9222572h-.7931457v3.9222572h-1.0094573v-9.076416h2.739956q.5435541 0 .9318066.4601926.3882524.4601933.3882524 1.1540217v2.1239667q0 1.0053443-.6766682 1.3168588-.2107668.099119-.4659043.099119zm-1.2590481-5.64267v-1.5858953q0-.4743524-.2884169-.6867495-.088743-.070798-.2052192-.063719h-1.5530114v2.9452329h1.7194053q.2828702-.00708.3161488-.389394.011093-.1132781.011093-.2194752z" fill="#008000"/><path d="m10.201004 3.7285848q0-.4106342.529158-.3681546.126777.014161.209458.014161v.00708h.115753l1.692202 4.9205216 1.697714-4.9205216h.06063v-.00708h.463013q.198434 0 .297651.212397.03307.063719.03307.1415978v8.694102h-1.01422v-5.6001914l-1.058314 3.2284284h-.953584l-1.058315-2.9310723v5.3028353h-1.014218z" fill="#00f"/></svg> +<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><path d="m8 3.1191406-3.7636719 1.8808594 3.7636719 1.8828125 3.763672-1.8828125z" fill="#80ff45"/><path d="m3 6.6191406v2.3808594 1.382812l1.234375.617188 2.765625 1.382812v-1.382812-2-.3808594l-3.2382812-1.6191406z" fill="#ff4545"/><path d="m13 6.6191406-.761719.3808594-3.238281 1.6191406v3.7636714l2.765625-1.382812 1.234375-.617188v-1.382812z" fill="#45d7ff"/></svg> diff --git a/editor/icons/RectangleAddRemove.svg b/editor/icons/RectangleAddRemove.svg deleted file mode 100644 index 87e2155a0d..0000000000 --- a/editor/icons/RectangleAddRemove.svg +++ /dev/null @@ -1 +0,0 @@ -<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><path d="m2 2c-.5522619.0000552-.9999448.4477381-1 1v10c.0000552.552262.4477381.999945 1 1h6v-2h-5v-8h10v1h2v-2c-.000055-.5522619-.447738-.9999448-1-1zm9.25 4v2.25h-2.25v1.5h2.25v2.25h1.5v-2.25h2.25v-1.5h-2.25v-2.25zm-2.25 7.5v1.5h6v-1.5z" fill="#e0e0e0"/></svg> diff --git a/editor/icons/TileChecked.svg b/editor/icons/TileChecked.svg new file mode 100644 index 0000000000..33b99a0e4c --- /dev/null +++ b/editor/icons/TileChecked.svg @@ -0,0 +1 @@ +<svg height="16" viewBox="0 0 16 15.999999" width="16" xmlns="http://www.w3.org/2000/svg"><path d="m3.3333333 1c-1.2887 0-2.3333333 1.0446683-2.3333333 2.3333333v9.3333337c0 1.2887 1.0446683 2.333333 2.3333333 2.333333h9.3333337c1.2887 0 2.333333-1.044668 2.333333-2.333333v-9.3333337c0-1.2887-1.044668-2.3333333-2.333333-2.3333333z" fill="#808080" stroke-width="1.16667"/><path d="m11.500773 3.7343508-5.6117507 5.6117502-1.7045017-1.6814543-1.4992276 1.4992276 3.2037293 3.1806817 7.1109777-7.1109775z" fill="#fff" stroke-width="1.06023"/></svg> diff --git a/editor/icons/TileUnchecked.svg b/editor/icons/TileUnchecked.svg new file mode 100644 index 0000000000..cd8db4ee19 --- /dev/null +++ b/editor/icons/TileUnchecked.svg @@ -0,0 +1 @@ +<svg height="16" viewBox="0 0 16 15.999999" width="16" xmlns="http://www.w3.org/2000/svg"><path d="m3.3333333 1c-1.2887 0-2.3333333 1.0446683-2.3333333 2.3333333v9.3333337c0 1.2887 1.0446683 2.333333 2.3333333 2.333333h9.3333337c1.2887 0 2.333333-1.044668 2.333333-2.333333v-9.3333337c0-1.2887-1.044668-2.3333333-2.333333-2.3333333z" fill="#808080" stroke-width="1.16667"/></svg> diff --git a/editor/import/editor_import_collada.cpp b/editor/import/editor_import_collada.cpp index dc1bd38a99..ddf89f077b 100644 --- a/editor/import/editor_import_collada.cpp +++ b/editor/import/editor_import_collada.cpp @@ -850,7 +850,7 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<EditorSceneImpor } Ref<SurfaceTool> surftool; - surftool.instance(); + surftool.instantiate(); surftool->begin(Mesh::PRIMITIVE_TRIANGLES); for (int k = 0; k < vertex_array.size(); k++) { @@ -1544,7 +1544,7 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones } Vector3 s = xform.basis.get_scale(); - bool singular_matrix = Math::is_equal_approx(s.x, 0.0f) || Math::is_equal_approx(s.y, 0.0f) || Math::is_equal_approx(s.z, 0.0f); + bool singular_matrix = Math::is_zero_approx(s.x) || Math::is_zero_approx(s.y) || Math::is_zero_approx(s.z); Quaternion q = singular_matrix ? Quaternion() : xform.basis.get_rotation_quaternion(); Vector3 l = xform.origin; @@ -1595,7 +1595,7 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones xform = sk->get_bone_rest(nm.bone).affine_inverse() * xform; Vector3 s = xform.basis.get_scale(); - bool singular_matrix = Math::is_equal_approx(s.x, 0.0f) || Math::is_equal_approx(s.y, 0.0f) || Math::is_equal_approx(s.z, 0.0f); + bool singular_matrix = Math::is_zero_approx(s.x) || Math::is_zero_approx(s.y) || Math::is_zero_approx(s.z); Quaternion q = singular_matrix ? Quaternion() : xform.basis.get_rotation_quaternion(); Vector3 l = xform.origin; diff --git a/editor/import/resource_importer_bitmask.cpp b/editor/import/resource_importer_bitmask.cpp index ffef759c07..7fd9230284 100644 --- a/editor/import/resource_importer_bitmask.cpp +++ b/editor/import/resource_importer_bitmask.cpp @@ -78,7 +78,7 @@ Error ResourceImporterBitMap::import(const String &p_source_file, const String & int create_from = p_options["create_from"]; float threshold = p_options["threshold"]; Ref<Image> image; - image.instance(); + image.instantiate(); Error err = ImageLoader::load_image(p_source_file, image); if (err != OK) { return err; @@ -88,7 +88,7 @@ Error ResourceImporterBitMap::import(const String &p_source_file, const String & int h = image->get_height(); Ref<BitMap> bitmap; - bitmap.instance(); + bitmap.instantiate(); bitmap->create(Size2(w, h)); for (int i = 0; i < h; i++) { diff --git a/editor/import/resource_importer_csv_translation.cpp b/editor/import/resource_importer_csv_translation.cpp index c9e446a1a2..07647d8b6a 100644 --- a/editor/import/resource_importer_csv_translation.cpp +++ b/editor/import/resource_importer_csv_translation.cpp @@ -104,7 +104,7 @@ Error ResourceImporterCSVTranslation::import(const String &p_source_file, const locales.push_back(locale); Ref<Translation> translation; - translation.instance(); + translation.instantiate(); translation->set_locale(locale); translations.push_back(translation); } diff --git a/editor/import/resource_importer_layered_texture.cpp b/editor/import/resource_importer_layered_texture.cpp index 6d2215c379..2ac8b8bd7d 100644 --- a/editor/import/resource_importer_layered_texture.cpp +++ b/editor/import/resource_importer_layered_texture.cpp @@ -186,7 +186,7 @@ void ResourceImporterLayeredTexture::_save_tex(Vector<Ref<Image>> p_images, cons for (int i = 0; i < mm_d; i++) { Ref<Image> mm; - mm.instance(); + mm.instantiate(); mm->create(mm_w, mm_h, false, p_images[0]->get_format()); Vector3 pos; pos.z = float(i) * float(d) / float(mm_d) + 0.5; @@ -328,7 +328,7 @@ Error ResourceImporterLayeredTexture::import(const String &p_source_file, const } Ref<Image> image; - image.instance(); + image.instantiate(); Error err = ImageLoader::load_image(p_source_file, image, nullptr, false, 1.0); if (err != OK) { return err; diff --git a/editor/import/resource_importer_obj.cpp b/editor/import/resource_importer_obj.cpp index 3aa17ee581..01603c0a6a 100644 --- a/editor/import/resource_importer_obj.cpp +++ b/editor/import/resource_importer_obj.cpp @@ -57,7 +57,7 @@ static Error _parse_material_library(const String &p_path, Map<String, Ref<Stand //vertex current_name = l.replace("newmtl", "").strip_edges(); - current.instance(); + current.instantiate(); current->set_name(current_name); material_map[current_name] = current; } else if (l.begins_with("Ka ")) { @@ -207,7 +207,7 @@ static Error _parse_obj(const String &p_path, List<Ref<Mesh>> &r_meshes, bool p_ ERR_FAIL_COND_V_MSG(!f, ERR_CANT_OPEN, vformat("Couldn't open OBJ file '%s', it may not exist or not be readable.", p_path)); Ref<ArrayMesh> mesh; - mesh.instance(); + mesh.instantiate(); bool generate_tangents = p_generate_tangents; Vector3 scale_mesh = p_scale_mesh; @@ -378,7 +378,7 @@ static Error _parse_obj(const String &p_path, List<Ref<Mesh>> &r_meshes, bool p_ if (!p_single_mesh) { mesh->set_name(name); r_meshes.push_back(mesh); - mesh.instance(); + mesh.instantiate(); current_group = ""; current_material = ""; } @@ -440,7 +440,7 @@ Node *EditorOBJImporter::import_scene(const String &p_path, uint32_t p_flags, in for (List<Ref<Mesh>>::Element *E = meshes.front(); E; E = E->next()) { Ref<EditorSceneImporterMesh> mesh; - mesh.instance(); + mesh.instantiate(); Ref<Mesh> m = E->get(); for (int i = 0; i < m->get_surface_count(); i++) { mesh->add_surface(m->surface_get_primitive_type(i), m->surface_get_arrays(i), Array(), Dictionary(), m->surface_get_material(i)); diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp index 08aa2fecbb..c14b948dae 100644 --- a/editor/import/resource_importer_scene.cpp +++ b/editor/import/resource_importer_scene.cpp @@ -1422,7 +1422,7 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p } if (root_type != "Node3D") { - Node *base_node = Object::cast_to<Node>(ClassDB::instance(root_type)); + Node *base_node = Object::cast_to<Node>(ClassDB::instantiate(root_type)); if (base_node) { scene->replace_by(base_node); @@ -1557,7 +1557,7 @@ Node *EditorSceneImporterESCN::import_scene(const String &p_path, uint32_t p_fla Ref<PackedScene> ps = ResourceFormatLoaderText::singleton->load(p_path, p_path, &error); ERR_FAIL_COND_V_MSG(!ps.is_valid(), nullptr, "Cannot load scene as text resource from path '" + p_path + "'."); - Node *scene = ps->instance(); + Node *scene = ps->instantiate(); ERR_FAIL_COND_V(!scene, nullptr); return scene; diff --git a/editor/import/resource_importer_shader_file.cpp b/editor/import/resource_importer_shader_file.cpp index 70119bfd1c..4d92490675 100644 --- a/editor/import/resource_importer_shader_file.cpp +++ b/editor/import/resource_importer_shader_file.cpp @@ -99,7 +99,7 @@ Error ResourceImporterShaderFile::import(const String &p_source_file, const Stri String file_txt = file->get_as_utf8_string(); Ref<RDShaderFile> shader_file; - shader_file.instance(); + shader_file.instantiate(); String base_path = p_source_file.get_base_dir(); err = shader_file->parse_versions_from_text(file_txt, "", _include_function, &base_path); diff --git a/editor/import/resource_importer_texture.cpp b/editor/import/resource_importer_texture.cpp index 72df65a787..daf7b15794 100644 --- a/editor/import/resource_importer_texture.cpp +++ b/editor/import/resource_importer_texture.cpp @@ -88,7 +88,7 @@ void ResourceImporterTexture::update_imports() { for (Map<StringName, MakeInfo>::Element *E = make_flags.front(); E; E = E->next()) { Ref<ConfigFile> cf; - cf.instance(); + cf.instantiate(); String src_path = String(E->key()) + ".import"; Error err = cf->load(src_path); @@ -411,13 +411,13 @@ Error ResourceImporterTexture::import(const String &p_source_file, const String Image::RoughnessChannel roughness_channel = Image::ROUGHNESS_CHANNEL_R; if (mipmaps && roughness > 1 && FileAccess::exists(normal_map)) { - normal_image.instance(); + normal_image.instantiate(); if (ImageLoader::load_image(normal_map, normal_image) == OK) { roughness_channel = Image::RoughnessChannel(roughness - 2); } } Ref<Image> image; - image.instance(); + image.instantiate(); Error err = ImageLoader::load_image(p_source_file, image, nullptr, hdr_as_srgb, scale); if (err != OK) { return err; diff --git a/editor/import/resource_importer_texture_atlas.cpp b/editor/import/resource_importer_texture_atlas.cpp index d5d1a14be3..dec1466da1 100644 --- a/editor/import/resource_importer_texture_atlas.cpp +++ b/editor/import/resource_importer_texture_atlas.cpp @@ -87,7 +87,7 @@ Error ResourceImporterTextureAtlas::import(const String &p_source_file, const St //it's a simple hack Ref<Image> broken = memnew(Image((const char **)atlas_import_failed_xpm)); Ref<ImageTexture> broken_texture; - broken_texture.instance(); + broken_texture.instantiate(); broken_texture->create_from_image(broken); String target_file = p_save_path + ".tex"; @@ -201,7 +201,7 @@ Error ResourceImporterTextureAtlas::import_group_file(const String &p_group_file const Map<StringName, Variant> &options = E->get(); Ref<Image> image; - image.instance(); + image.instantiate(); Error err = ImageLoader::load_image(source, image); ERR_CONTINUE(err != OK); @@ -240,7 +240,7 @@ Error ResourceImporterTextureAtlas::import_group_file(const String &p_group_file pack_data.is_mesh = true; Ref<BitMap> bit_map; - bit_map.instance(); + bit_map.instantiate(); bit_map->create_from_image_alpha(image); Vector<Vector<Vector2>> polygons = bit_map->clip_opaque_to_polygons(Rect2(0, 0, image->get_width(), image->get_height())); @@ -272,7 +272,7 @@ Error ResourceImporterTextureAtlas::import_group_file(const String &p_group_file //blit the atlas Ref<Image> new_atlas; - new_atlas.instance(); + new_atlas.instantiate(); new_atlas->create(atlas_width, atlas_height, false, Image::FORMAT_RGBA8); for (int i = 0; i < pack_data_files.size(); i++) { @@ -303,7 +303,7 @@ Error ResourceImporterTextureAtlas::import_group_file(const String &p_group_file cache.reference_ptr(resptr); } else { Ref<ImageTexture> res_cache; - res_cache.instance(); + res_cache.instantiate(); res_cache->create_from_image(new_atlas); res_cache->set_path(p_group_file); cache = res_cache; @@ -321,7 +321,7 @@ Error ResourceImporterTextureAtlas::import_group_file(const String &p_group_file //region Ref<AtlasTexture> atlas_texture; - atlas_texture.instance(); + atlas_texture.instantiate(); atlas_texture->set_atlas(cache); atlas_texture->set_region(Rect2(offset, pack_data.region.size)); atlas_texture->set_margin(Rect2(pack_data.region.position, Size2(pack_data.image->get_width(), pack_data.image->get_height()) - pack_data.region.size)); @@ -329,7 +329,7 @@ Error ResourceImporterTextureAtlas::import_group_file(const String &p_group_file texture = atlas_texture; } else { Ref<ArrayMesh> mesh; - mesh.instance(); + mesh.instantiate(); for (int i = 0; i < pack_data.chart_pieces.size(); i++) { const EditorAtlasPacker::Chart &chart = charts[pack_data.chart_pieces[i]]; @@ -375,7 +375,7 @@ Error ResourceImporterTextureAtlas::import_group_file(const String &p_group_file } Ref<MeshTexture> mesh_texture; - mesh_texture.instance(); + mesh_texture.instantiate(); mesh_texture->set_base_texture(cache); mesh_texture->set_image_size(pack_data.image->get_size()); mesh_texture->set_mesh(mesh); diff --git a/editor/import/resource_importer_wav.cpp b/editor/import/resource_importer_wav.cpp index e615212569..2db1db9e51 100644 --- a/editor/import/resource_importer_wav.cpp +++ b/editor/import/resource_importer_wav.cpp @@ -78,7 +78,7 @@ void ResourceImporterWAV::get_import_options(List<ImportOption> *r_options, int r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "force/8_bit"), false)); r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "force/mono"), false)); r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "force/max_rate", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), false)); - r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "force/max_rate_hz", PROPERTY_HINT_EXP_RANGE, "11025,192000,1"), 44100)); + r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "force/max_rate_hz", PROPERTY_HINT_RANGE, "11025,192000,1,exp"), 44100)); r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "edit/trim"), false)); r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "edit/normalize"), false)); r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "edit/loop"), false)); @@ -508,7 +508,7 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s } Ref<AudioStreamSample> sample; - sample.instance(); + sample.instantiate(); sample->set_data(dst_data); sample->set_format(dst_format); sample->set_mix_rate(rate); diff --git a/editor/import/scene_import_settings.cpp b/editor/import/scene_import_settings.cpp index 600f3fe2f0..f9f47ec4f4 100644 --- a/editor/import/scene_import_settings.cpp +++ b/editor/import/scene_import_settings.cpp @@ -435,7 +435,7 @@ void SceneImportSettings::open_settings(const String &p_path) { base_subresource_settings.clear(); Ref<ConfigFile> config; - config.instance(); + config.instantiate(); Error err = config->load(p_path + ".import"); if (err == OK) { List<String> keys; @@ -1105,12 +1105,12 @@ SceneImportSettings::SceneImportSettings() { { Ref<StandardMaterial3D> selection_mat; - selection_mat.instance(); + selection_mat.instantiate(); selection_mat->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED); selection_mat->set_albedo(Color(1, 0.8, 1.0)); Ref<SurfaceTool> st; - st.instance(); + st.instantiate(); st->begin(Mesh::PRIMITIVE_LINES); AABB base_aabb; @@ -1126,7 +1126,7 @@ SceneImportSettings::SceneImportSettings() { st->add_vertex(b.lerp(a, 0.2)); } - selection_mesh.instance(); + selection_mesh.instantiate(); st->commit(selection_mesh); selection_mesh->surface_set_material(0, selection_mat); @@ -1141,7 +1141,7 @@ SceneImportSettings::SceneImportSettings() { base_viewport->add_child(mesh_preview); mesh_preview->hide(); - material_preview.instance(); + material_preview.instantiate(); } inspector = memnew(EditorInspector); @@ -1163,13 +1163,13 @@ SceneImportSettings::SceneImportSettings() { external_path_tree->set_columns(3); external_path_tree->set_column_titles_visible(true); external_path_tree->set_column_expand(0, true); - external_path_tree->set_column_min_width(0, 100 * EDSCALE); + external_path_tree->set_column_custom_minimum_width(0, 100 * EDSCALE); external_path_tree->set_column_title(0, TTR("Resource")); external_path_tree->set_column_expand(1, true); - external_path_tree->set_column_min_width(1, 100 * EDSCALE); + external_path_tree->set_column_custom_minimum_width(1, 100 * EDSCALE); external_path_tree->set_column_title(1, TTR("Path")); external_path_tree->set_column_expand(2, false); - external_path_tree->set_column_min_width(2, 200 * EDSCALE); + external_path_tree->set_column_custom_minimum_width(2, 200 * EDSCALE); external_path_tree->set_column_title(2, TTR("Status")); save_path = memnew(EditorFileDialog); save_path->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_DIR); diff --git a/editor/import/scene_importer_mesh.cpp b/editor/import/scene_importer_mesh.cpp index bf17ea7bca..ce78166d1e 100644 --- a/editor/import/scene_importer_mesh.cpp +++ b/editor/import/scene_importer_mesh.cpp @@ -215,6 +215,7 @@ void EditorSceneImporterMesh::generate_lods() { int index_target = indices.size() * threshold; float max_mesh_error_percentage = 1e0f; float mesh_error = 0.0f; + float scale = SurfaceTool::simplify_scale_func((const float *)vertices_ptr, vertex_count, sizeof(Vector3)); while (index_target > min_indices) { Vector<int> new_indices; new_indices.resize(indices.size()); @@ -223,8 +224,8 @@ void EditorSceneImporterMesh::generate_lods() { break; } Surface::LOD lod; - lod.distance = mesh_error; - if (Math::is_equal_approx(mesh_error, 0.0f)) { + lod.distance = mesh_error * scale; + if (Math::is_zero_approx(mesh_error)) { break; } if (new_len <= 0) { @@ -251,7 +252,7 @@ Ref<ArrayMesh> EditorSceneImporterMesh::get_mesh(const Ref<Mesh> &p_base) { mesh = p_base; } if (mesh.is_null()) { - mesh.instance(); + mesh.instantiate(); } mesh->set_name(get_name()); if (has_meta("import_id")) { @@ -320,7 +321,7 @@ void EditorSceneImporterMesh::create_shadow_mesh() { } } - shadow_mesh.instance(); + shadow_mesh.instantiate(); for (int i = 0; i < surfaces.size(); i++) { LocalVector<int> vertex_remap; @@ -528,7 +529,7 @@ Vector<Ref<Shape3D>> EditorSceneImporterMesh::convex_decompose() const { } Ref<ConvexPolygonShape3D> shape; - shape.instance(); + shape.instantiate(); shape->set_points(convex_points); ret.push_back(shape); } @@ -587,7 +588,7 @@ Ref<NavigationMesh> EditorSceneImporterMesh::create_navigation_mesh() { } Ref<NavigationMesh> nm; - nm.instance(); + nm.instantiate(); nm->set_vertices(vertices); Vector<int> v3; @@ -733,7 +734,7 @@ Error EditorSceneImporterMesh::lightmap_unwrap_cached(const Transform3D &p_base_ for (int i = 0; i < lightmap_surfaces.size(); i++) { Ref<SurfaceTool> st; - st.instance(); + st.instantiate(); st->begin(Mesh::PRIMITIVE_TRIANGLES); st->set_material(lightmap_surfaces[i].material); st->set_meta("name", lightmap_surfaces[i].name); diff --git a/editor/import_dock.cpp b/editor/import_dock.cpp index 17c51f0f85..6fa9864830 100644 --- a/editor/import_dock.cpp +++ b/editor/import_dock.cpp @@ -91,7 +91,7 @@ public: void ImportDock::set_edit_path(const String &p_path) { Ref<ConfigFile> config; - config.instance(); + config.instantiate(); Error err = config->load(p_path + ".import"); if (err != OK) { clear(); @@ -182,7 +182,7 @@ void ImportDock::set_edit_multiple_paths(const Vector<String> &p_paths) { for (int i = 0; i < p_paths.size(); i++) { Ref<ConfigFile> config; - config.instance(); + config.instantiate(); Error err = config->load(p_paths[i] + ".import"); ERR_CONTINUE(err != OK); @@ -328,7 +328,7 @@ void ImportDock::_importer_selected(int i_idx) { Ref<ConfigFile> config; if (params->paths.size()) { - config.instance(); + config.instantiate(); Error err = config->load(params->paths[0] + ".import"); if (err != OK) { config.unref(); @@ -440,7 +440,7 @@ void ImportDock::_reimport_attempt() { } for (int i = 0; i < params->paths.size(); i++) { Ref<ConfigFile> config; - config.instance(); + config.instantiate(); Error err = config->load(params->paths[i] + ".import"); ERR_CONTINUE(err != OK); @@ -477,7 +477,7 @@ void ImportDock::_advanced_options() { void ImportDock::_reimport() { for (int i = 0; i < params->paths.size(); i++) { Ref<ConfigFile> config; - config.instance(); + config.instantiate(); Error err = config->load(params->paths[i] + ".import"); ERR_CONTINUE(err != OK); diff --git a/editor/localization_editor.cpp b/editor/localization_editor.cpp index 161f1dde0d..208d4437d3 100644 --- a/editor/localization_editor.cpp +++ b/editor/localization_editor.cpp @@ -728,8 +728,10 @@ LocalizationEditor::LocalizationEditor() { translation_remap_options->set_column_title(1, TTR("Locale")); translation_remap_options->set_column_titles_visible(true); translation_remap_options->set_column_expand(0, true); + translation_remap_options->set_column_clip_content(0, true); translation_remap_options->set_column_expand(1, false); - translation_remap_options->set_column_min_width(1, 200); + translation_remap_options->set_column_clip_content(1, true); + translation_remap_options->set_column_custom_minimum_width(1, 200); translation_remap_options->connect("item_edited", callable_mp(this, &LocalizationEditor::_translation_res_option_changed)); translation_remap_options->connect("button_pressed", callable_mp(this, &LocalizationEditor::_translation_res_option_delete)); tmc->add_child(translation_remap_options); diff --git a/editor/node_3d_editor_gizmos.cpp b/editor/node_3d_editor_gizmos.cpp index 19663e46e1..2a399f4b03 100644 --- a/editor/node_3d_editor_gizmos.cpp +++ b/editor/node_3d_editor_gizmos.cpp @@ -600,8 +600,6 @@ bool EditorNode3DGizmo::intersect_ray(Camera3D *p_camera, const Point2 &p_point, r_normal = -p_camera->project_ray_normal(p_point); return true; } - - return false; } if (collision_segments.size()) { @@ -652,8 +650,6 @@ bool EditorNode3DGizmo::intersect_ray(Camera3D *p_camera, const Point2 &p_point, r_normal = -p_camera->project_ray_normal(p_point); return true; } - - return false; } if (collision_mesh.is_valid()) { @@ -759,7 +755,7 @@ EditorNode3DGizmo::EditorNode3DGizmo() { hidden = false; base = nullptr; selected = false; - instanced = false; + instantiated = false; spatial_node = nullptr; gizmo_plugin = nullptr; selectable_icon_size = -1.0f; @@ -3427,7 +3423,7 @@ void LightmapGIGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { array[RS::ARRAY_COLOR] = colors; Ref<ArrayMesh> mesh; - mesh.instance(); + mesh.instantiate(); mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, array, Array(), Dictionary(), 0); //no compression mesh->surface_set_material(0, material_probes); diff --git a/editor/plugins/animation_blend_space_1d_editor.cpp b/editor/plugins/animation_blend_space_1d_editor.cpp index f7c0ebcfaf..b6dd9474d3 100644 --- a/editor/plugins/animation_blend_space_1d_editor.cpp +++ b/editor/plugins/animation_blend_space_1d_editor.cpp @@ -386,7 +386,7 @@ void AnimationNodeBlendSpace1DEditor::_add_menu_type(int p_index) { } else { String type = menu->get_item_metadata(p_index); - Object *obj = ClassDB::instance(type); + Object *obj = ClassDB::instantiate(type); ERR_FAIL_COND(!obj); AnimationNode *an = Object::cast_to<AnimationNode>(obj); ERR_FAIL_COND(!an); @@ -413,7 +413,7 @@ void AnimationNodeBlendSpace1DEditor::_add_menu_type(int p_index) { void AnimationNodeBlendSpace1DEditor::_add_animation_type(int p_index) { Ref<AnimationNodeAnimation> anim; - anim.instance(); + anim.instantiate(); anim->set_animation(animations_to_add[p_index]); @@ -594,7 +594,7 @@ AnimationNodeBlendSpace1DEditor::AnimationNodeBlendSpace1DEditor() { add_child(top_hb); Ref<ButtonGroup> bg; - bg.instance(); + bg.instantiate(); tool_blend = memnew(Button); tool_blend->set_flat(true); diff --git a/editor/plugins/animation_blend_space_2d_editor.cpp b/editor/plugins/animation_blend_space_2d_editor.cpp index e719df53d5..359df95bce 100644 --- a/editor/plugins/animation_blend_space_2d_editor.cpp +++ b/editor/plugins/animation_blend_space_2d_editor.cpp @@ -308,7 +308,7 @@ void AnimationNodeBlendSpace2DEditor::_add_menu_type(int p_index) { } else { String type = menu->get_item_metadata(p_index); - Object *obj = ClassDB::instance(type); + Object *obj = ClassDB::instantiate(type); ERR_FAIL_COND(!obj); AnimationNode *an = Object::cast_to<AnimationNode>(obj); ERR_FAIL_COND(!an); @@ -335,7 +335,7 @@ void AnimationNodeBlendSpace2DEditor::_add_menu_type(int p_index) { void AnimationNodeBlendSpace2DEditor::_add_animation_type(int p_index) { Ref<AnimationNodeAnimation> anim; - anim.instance(); + anim.instantiate(); anim->set_animation(animations_to_add[p_index]); @@ -818,7 +818,7 @@ AnimationNodeBlendSpace2DEditor::AnimationNodeBlendSpace2DEditor() { add_child(top_hb); Ref<ButtonGroup> bg; - bg.instance(); + bg.instantiate(); tool_blend = memnew(Button); tool_blend->set_flat(true); diff --git a/editor/plugins/animation_blend_tree_editor_plugin.cpp b/editor/plugins/animation_blend_tree_editor_plugin.cpp index 867c701733..dcde89f177 100644 --- a/editor/plugins/animation_blend_tree_editor_plugin.cpp +++ b/editor/plugins/animation_blend_tree_editor_plugin.cpp @@ -288,14 +288,14 @@ void AnimationNodeBlendTreeEditor::_add_node(int p_idx) { ERR_FAIL_COND(!anode.is_valid()); base_name = anode->get_class(); } else if (add_options[p_idx].type != String()) { - AnimationNode *an = Object::cast_to<AnimationNode>(ClassDB::instance(add_options[p_idx].type)); + AnimationNode *an = Object::cast_to<AnimationNode>(ClassDB::instantiate(add_options[p_idx].type)); ERR_FAIL_COND(!an); anode = Ref<AnimationNode>(an); base_name = add_options[p_idx].name; } else { ERR_FAIL_COND(add_options[p_idx].script.is_null()); String base_type = add_options[p_idx].script->get_instance_base_type(); - AnimationNode *an = Object::cast_to<AnimationNode>(ClassDB::instance(base_type)); + AnimationNode *an = Object::cast_to<AnimationNode>(ClassDB::instantiate(base_type)); ERR_FAIL_COND(!an); anode = Ref<AnimationNode>(an); anode->set_script(add_options[p_idx].script); diff --git a/editor/plugins/animation_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp index 4a3f3212fa..2b92943f7e 100644 --- a/editor/plugins/animation_player_editor_plugin.cpp +++ b/editor/plugins/animation_player_editor_plugin.cpp @@ -121,11 +121,11 @@ void AnimationPlayerEditor::_notification(int p_what) { Ref<Image> reset_img = reset_icon->get_image(); Ref<Image> autoplay_reset_img; Size2 icon_size = Size2(autoplay_img->get_width(), autoplay_img->get_height()); - autoplay_reset_img.instance(); + autoplay_reset_img.instantiate(); autoplay_reset_img->create(icon_size.x * 2, icon_size.y, false, autoplay_img->get_format()); autoplay_reset_img->blit_rect(autoplay_img, Rect2(Point2(), icon_size), Point2()); autoplay_reset_img->blit_rect(reset_img, Rect2(Point2(), icon_size), Point2(icon_size.x, 0)); - autoplay_reset_icon.instance(); + autoplay_reset_icon.instantiate(); autoplay_reset_icon->create_from_image(autoplay_reset_img); } stop->set_icon(get_theme_icon("Stop", "EditorIcons")); @@ -569,8 +569,10 @@ void AnimationPlayerEditor::_animation_blend() { blend_editor.dialog->popup_centered(Size2(400, 400) * EDSCALE); blend_editor.tree->set_hide_root(true); - blend_editor.tree->set_column_min_width(0, 10); - blend_editor.tree->set_column_min_width(1, 3); + blend_editor.tree->set_column_expand_ratio(0, 10); + blend_editor.tree->set_column_clip_content(0, true); + blend_editor.tree->set_column_expand_ratio(1, 3); + blend_editor.tree->set_column_clip_content(1, true); List<StringName> anims; player->get_animation_list(&anims); diff --git a/editor/plugins/animation_state_machine_editor.cpp b/editor/plugins/animation_state_machine_editor.cpp index fe5a0cab4d..94e526922d 100644 --- a/editor/plugins/animation_state_machine_editor.cpp +++ b/editor/plugins/animation_state_machine_editor.cpp @@ -257,7 +257,7 @@ void AnimationNodeStateMachineEditor::_state_machine_gui_input(const Ref<InputEv } else { Ref<AnimationNodeStateMachineTransition> tr; - tr.instance(); + tr.instantiate(); tr->set_switch_mode(AnimationNodeStateMachineTransition::SwitchMode(transition_mode->get_selected())); updating = true; @@ -423,7 +423,7 @@ void AnimationNodeStateMachineEditor::_add_menu_type(int p_index) { } else { String type = menu->get_item_metadata(p_index); - Object *obj = ClassDB::instance(type); + Object *obj = ClassDB::instantiate(type); ERR_FAIL_COND(!obj); AnimationNode *an = Object::cast_to<AnimationNode>(obj); ERR_FAIL_COND(!an); @@ -462,7 +462,7 @@ void AnimationNodeStateMachineEditor::_add_menu_type(int p_index) { void AnimationNodeStateMachineEditor::_add_animation_type(int p_index) { Ref<AnimationNodeAnimation> anim; - anim.instance(); + anim.instantiate(); anim->set_animation(animations_to_add[p_index]); @@ -1213,7 +1213,7 @@ AnimationNodeStateMachineEditor::AnimationNodeStateMachineEditor() { add_child(top_hb); Ref<ButtonGroup> bg; - bg.instance(); + bg.instantiate(); tool_select = memnew(Button); tool_select->set_flat(true); diff --git a/editor/plugins/animation_tree_editor_plugin.cpp b/editor/plugins/animation_tree_editor_plugin.cpp index c33b06ff32..e90665f84d 100644 --- a/editor/plugins/animation_tree_editor_plugin.cpp +++ b/editor/plugins/animation_tree_editor_plugin.cpp @@ -76,7 +76,7 @@ void AnimationTreeEditor::_update_path() { } Ref<ButtonGroup> group; - group.instance(); + group.instantiate(); Button *b = memnew(Button); b->set_text("Root"); diff --git a/editor/plugins/asset_library_editor_plugin.cpp b/editor/plugins/asset_library_editor_plugin.cpp index 93bb170128..cd61ebd418 100644 --- a/editor/plugins/asset_library_editor_plugin.cpp +++ b/editor/plugins/asset_library_editor_plugin.cpp @@ -86,7 +86,7 @@ void EditorAssetLibraryItem::_bind_methods() { EditorAssetLibraryItem::EditorAssetLibraryItem() { Ref<StyleBoxEmpty> border; - border.instance(); + border.instantiate(); border->set_default_margin(SIDE_LEFT, 5 * EDSCALE); border->set_default_margin(SIDE_RIGHT, 5 * EDSCALE); border->set_default_margin(SIDE_BOTTOM, 5 * EDSCALE); @@ -155,7 +155,7 @@ void EditorAssetLibraryItemDescription::set_image(int p_type, int p_index, const thumbnail->blend_rect(overlay, overlay->get_used_rect(), overlay_pos); Ref<ImageTexture> tex; - tex.instance(); + tex.instantiate(); tex->create_from_image(thumbnail); preview_images[i].button->set_icon(tex); @@ -761,7 +761,7 @@ void EditorAssetLibrary::_image_update(bool use_cache, bool final, const PackedB } Ref<ImageTexture> tex; - tex.instance(); + tex.instantiate(); tex->create_from_image(image); obj->call("set_image", image_queue[p_queue_id].image_type, image_queue[p_queue_id].image_index, tex); @@ -1098,11 +1098,9 @@ void EditorAssetLibrary::_http_request_completed(int p_status, int p_code, const Dictionary d; { - Variant js; - String errs; - int errl; - JSON::parse(str, js, errs, errl); - d = js; + JSON json; + json.parse(str); + d = json.get_data(); } RequestType requested = requesting; @@ -1437,7 +1435,7 @@ EditorAssetLibrary::EditorAssetLibrary(bool p_templates_only) { library_scroll_bg->add_child(library_scroll); Ref<StyleBoxEmpty> border2; - border2.instance(); + border2.instantiate(); border2->set_default_margin(SIDE_LEFT, 15 * EDSCALE); border2->set_default_margin(SIDE_RIGHT, 35 * EDSCALE); border2->set_default_margin(SIDE_BOTTOM, 15 * EDSCALE); diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 5d248176c1..7282475ddf 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -1241,7 +1241,7 @@ bool CanvasItemEditor::_gui_input_zoom_or_pan(const Ref<InputEvent> &p_event, bo Ref<InputEventPanGesture> pan_gesture = p_event; if (pan_gesture.is_valid() && !p_already_accepted) { - // If control key pressed, then zoom instead of pan + // If ctrl key pressed, then zoom instead of pan. if (pan_gesture->is_ctrl_pressed()) { const float factor = pan_gesture->get_delta().y; @@ -4242,7 +4242,7 @@ void CanvasItemEditor::_insert_animation_keys(bool p_location, bool p_rotation, AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(n2d, "position", n2d->get_position(), p_on_existing); } if (key_rot && p_rotation) { - AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(n2d, "rotation_degrees", Math::rad2deg(n2d->get_rotation()), p_on_existing); + AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(n2d, "rotation", n2d->get_rotation(), p_on_existing); } if (key_scale && p_scale) { AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(n2d, "scale", n2d->get_scale(), p_on_existing); @@ -4274,7 +4274,7 @@ void CanvasItemEditor::_insert_animation_keys(bool p_location, bool p_rotation, AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(F->get(), "position", F->get()->get_position(), p_on_existing); } if (key_rot) { - AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(F->get(), "rotation_degrees", Math::rad2deg(F->get()->get_rotation()), p_on_existing); + AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(F->get(), "rotation", F->get()->get_rotation(), p_on_existing); } if (key_scale) { AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(F->get(), "scale", F->get()->get_scale(), p_on_existing); @@ -4290,7 +4290,7 @@ void CanvasItemEditor::_insert_animation_keys(bool p_location, bool p_rotation, AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(ctrl, "rect_position", ctrl->get_position(), p_on_existing); } if (key_rot) { - AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(ctrl, "rect_rotation", ctrl->get_rotation_degrees(), p_on_existing); + AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(ctrl, "rect_rotation", ctrl->get_rotation(), p_on_existing); } if (key_scale) { AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(ctrl, "rect_size", ctrl->get_size(), p_on_existing); @@ -4317,11 +4317,11 @@ void CanvasItemEditor::_button_toggle_anchor_mode(bool p_status) { void CanvasItemEditor::_update_override_camera_button(bool p_game_running) { if (p_game_running) { override_camera_button->set_disabled(false); - override_camera_button->set_tooltip(TTR("Game Camera Override\nOverrides game camera with editor viewport camera.")); + override_camera_button->set_tooltip(TTR("Project Camera Override\nOverrides the running project's camera with the editor viewport camera.")); } else { override_camera_button->set_disabled(true); override_camera_button->set_pressed(false); - override_camera_button->set_tooltip(TTR("Game Camera Override\nNo game instance running.")); + override_camera_button->set_tooltip(TTR("Project Camera Override\nNo project instance running. Run the project from the editor to use this feature.")); } } @@ -5423,24 +5423,32 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { lock_button->connect("pressed", callable_mp(this, &CanvasItemEditor::_popup_callback), varray(LOCK_SELECTED)); lock_button->set_tooltip(TTR("Lock the selected object in place (can't be moved).")); + // Define the shortcut globally (without a context) so that it works if the Scene tree dock is currently focused. + lock_button->set_shortcut(ED_SHORTCUT("editor/lock_selected_nodes", TTR("Lock Selected Node(s)"), KEY_MASK_CMD | KEY_L)); unlock_button = memnew(Button); unlock_button->set_flat(true); hb->add_child(unlock_button); unlock_button->connect("pressed", callable_mp(this, &CanvasItemEditor::_popup_callback), varray(UNLOCK_SELECTED)); unlock_button->set_tooltip(TTR("Unlock the selected object (can be moved).")); + // Define the shortcut globally (without a context) so that it works if the Scene tree dock is currently focused. + unlock_button->set_shortcut(ED_SHORTCUT("editor/unlock_selected_nodes", TTR("Unlock Selected Node(s)"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_L)); group_button = memnew(Button); group_button->set_flat(true); hb->add_child(group_button); group_button->connect("pressed", callable_mp(this, &CanvasItemEditor::_popup_callback), varray(GROUP_SELECTED)); group_button->set_tooltip(TTR("Makes sure the object's children are not selectable.")); + // Define the shortcut globally (without a context) so that it works if the Scene tree dock is currently focused. + group_button->set_shortcut(ED_SHORTCUT("editor/group_selected_nodes", TTR("Group Selected Node(s)"), KEY_MASK_CMD | KEY_G)); ungroup_button = memnew(Button); ungroup_button->set_flat(true); hb->add_child(ungroup_button); ungroup_button->connect("pressed", callable_mp(this, &CanvasItemEditor::_popup_callback), varray(UNGROUP_SELECTED)); ungroup_button->set_tooltip(TTR("Restores the object's children's ability to be selected.")); + // Define the shortcut globally (without a context) so that it works if the Scene tree dock is currently focused. + ungroup_button->set_shortcut(ED_SHORTCUT("editor/ungroup_selected_nodes", TTR("Ungroup Selected Node(s)"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_G)); hb->add_child(memnew(VSeparator)); @@ -5478,7 +5486,7 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { p = view_menu->get_popup(); p->set_hide_on_checkable_item_selection(false); - p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_grid", TTR("Always Show Grid"), KEY_MASK_CTRL | KEY_G), SHOW_GRID); + p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_grid", TTR("Always Show Grid"), KEY_NUMBERSIGN), SHOW_GRID); p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_helpers", TTR("Show Helpers"), KEY_H), SHOW_HELPERS); p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_rulers", TTR("Show Rulers")), SHOW_RULERS); p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_guides", TTR("Show Guides"), KEY_Y), SHOW_GUIDES); @@ -5623,12 +5631,12 @@ void CanvasItemEditorPlugin::make_visible(bool p_visible) { if (p_visible) { canvas_item_editor->show(); canvas_item_editor->set_physics_process(true); - RenderingServer::get_singleton()->viewport_set_hide_canvas(editor->get_scene_root()->get_viewport_rid(), false); + RenderingServer::get_singleton()->viewport_set_disable_2d(editor->get_scene_root()->get_viewport_rid(), false); } else { canvas_item_editor->hide(); canvas_item_editor->set_physics_process(false); - RenderingServer::get_singleton()->viewport_set_hide_canvas(editor->get_scene_root()->get_viewport_rid(), true); + RenderingServer::get_singleton()->viewport_set_disable_2d(editor->get_scene_root()->get_viewport_rid(), true); } } @@ -5698,7 +5706,7 @@ void CanvasItemEditorViewport::_create_preview(const Vector<String> &files) cons label_desc->show(); } else { if (scene.is_valid()) { - Node *instance = scene->instance(); + Node *instance = scene->instantiate(); if (instance) { preview_node->add_child(instance); } @@ -5811,26 +5819,26 @@ bool CanvasItemEditorViewport::_create_instance(Node *parent, String &path, cons return false; } - Node *instanced_scene = sdata->instance(PackedScene::GEN_EDIT_STATE_INSTANCE); - if (!instanced_scene) { // error on instancing + Node *instantiated_scene = sdata->instantiate(PackedScene::GEN_EDIT_STATE_INSTANCE); + if (!instantiated_scene) { // error on instancing return false; } if (editor->get_edited_scene()->get_filename() != "") { // cyclical instancing - if (_cyclical_dependency_exists(editor->get_edited_scene()->get_filename(), instanced_scene)) { - memdelete(instanced_scene); + if (_cyclical_dependency_exists(editor->get_edited_scene()->get_filename(), instantiated_scene)) { + memdelete(instantiated_scene); return false; } } - instanced_scene->set_filename(ProjectSettings::get_singleton()->localize_path(path)); + instantiated_scene->set_filename(ProjectSettings::get_singleton()->localize_path(path)); - editor_data->get_undo_redo().add_do_method(parent, "add_child", instanced_scene); - editor_data->get_undo_redo().add_do_method(instanced_scene, "set_owner", editor->get_edited_scene()); - editor_data->get_undo_redo().add_do_reference(instanced_scene); - editor_data->get_undo_redo().add_undo_method(parent, "remove_child", instanced_scene); + editor_data->get_undo_redo().add_do_method(parent, "add_child", instantiated_scene); + editor_data->get_undo_redo().add_do_method(instantiated_scene, "set_owner", editor->get_edited_scene()); + editor_data->get_undo_redo().add_do_reference(instantiated_scene); + editor_data->get_undo_redo().add_undo_method(parent, "remove_child", instantiated_scene); - String new_name = parent->validate_child_name(instanced_scene); + String new_name = parent->validate_child_name(instantiated_scene); EditorDebuggerNode *ed = EditorDebuggerNode::get_singleton(); editor_data->get_undo_redo().add_do_method(ed, "live_debug_instance_node", editor->get_edited_scene()->get_path_to(parent), path, new_name); editor_data->get_undo_redo().add_undo_method(ed, "live_debug_remove_node", NodePath(String(editor->get_edited_scene()->get_path_to(parent)) + "/" + new_name)); @@ -5841,11 +5849,11 @@ bool CanvasItemEditorViewport::_create_instance(Node *parent, String &path, cons target_pos = canvas_item_editor->snap_point(target_pos); target_pos = parent_ci->get_global_transform_with_canvas().affine_inverse().xform(target_pos); // Preserve instance position of the original scene. - CanvasItem *instance_ci = Object::cast_to<CanvasItem>(instanced_scene); + CanvasItem *instance_ci = Object::cast_to<CanvasItem>(instantiated_scene); if (instance_ci) { target_pos += instance_ci->_edit_get_position(); } - editor_data->get_undo_redo().add_do_method(instanced_scene, "set_position", target_pos); + editor_data->get_undo_redo().add_do_method(instantiated_scene, "set_position", target_pos); } return true; @@ -5928,7 +5936,7 @@ bool CanvasItemEditorViewport::can_drop_data(const Point2 &p_point, const Varian if (d.has("type")) { if (String(d["type"]) == "files") { Vector<String> files = d["files"]; - bool can_instance = false; + bool can_instantiate = false; for (int i = 0; i < files.size(); i++) { // check if dragged files contain resource or scene can be created at least once RES res = ResourceLoader::load(files[i]); if (res.is_null()) { @@ -5937,11 +5945,11 @@ bool CanvasItemEditorViewport::can_drop_data(const Point2 &p_point, const Varian String type = res->get_class(); if (type == "PackedScene") { Ref<PackedScene> sdata = Ref<PackedScene>(Object::cast_to<PackedScene>(*res)); - Node *instanced_scene = sdata->instance(PackedScene::GEN_EDIT_STATE_INSTANCE); - if (!instanced_scene) { + Node *instantiated_scene = sdata->instantiate(PackedScene::GEN_EDIT_STATE_INSTANCE); + if (!instantiated_scene) { continue; } - memdelete(instanced_scene); + memdelete(instantiated_scene); } else if (type == "Texture2D" || type == "ImageTexture" || type == "ViewportTexture" || @@ -5956,10 +5964,10 @@ bool CanvasItemEditorViewport::can_drop_data(const Point2 &p_point, const Varian } else { continue; } - can_instance = true; + can_instantiate = true; break; } - if (can_instance) { + if (can_instantiate) { if (!preview_node->get_parent()) { // create preview only once _create_preview(files); } @@ -5967,7 +5975,7 @@ bool CanvasItemEditorViewport::can_drop_data(const Point2 &p_point, const Varian preview_node->set_position((p_point - trans.get_origin()) / trans.get_scale().x); label->set_text(vformat(TTR("Adding %s..."), default_type)); } - return can_instance; + return can_instantiate; } } label->hide(); @@ -6092,7 +6100,7 @@ CanvasItemEditorViewport::CanvasItemEditorViewport(EditorNode *p_node, CanvasIte vbc->add_child(btn_group); btn_group->set_h_size_flags(0); - button_group.instance(); + button_group.instantiate(); for (int i = 0; i < types.size(); i++) { CheckBox *check = memnew(CheckBox); btn_group->add_child(check); diff --git a/editor/plugins/collision_polygon_3d_editor_plugin.cpp b/editor/plugins/collision_polygon_3d_editor_plugin.cpp index a0df7e289e..6f90d278bd 100644 --- a/editor/plugins/collision_polygon_3d_editor_plugin.cpp +++ b/editor/plugins/collision_polygon_3d_editor_plugin.cpp @@ -358,9 +358,9 @@ void CollisionPolygon3DEditor::_polygon_draw() { float depth = _get_depth() * 0.5; - imgeom->clear(); + imesh->clear_surfaces(); imgeom->set_material_override(line_material); - imgeom->begin(Mesh::PRIMITIVE_LINES, Ref<Texture2D>()); + imesh->surface_begin(Mesh::PRIMITIVE_LINES); Rect2 rect; @@ -382,10 +382,10 @@ void CollisionPolygon3DEditor::_polygon_draw() { Vector3 point = Vector3(p.x, p.y, depth); Vector3 next_point = Vector3(p2.x, p2.y, depth); - imgeom->set_color(Color(1, 0.3, 0.1, 0.8)); - imgeom->add_vertex(point); - imgeom->set_color(Color(1, 0.3, 0.1, 0.8)); - imgeom->add_vertex(next_point); + imesh->surface_set_color(Color(1, 0.3, 0.1, 0.8)); + imesh->surface_add_vertex(point); + imesh->surface_set_color(Color(1, 0.3, 0.1, 0.8)); + imesh->surface_add_vertex(next_point); //Color col=Color(1,0.3,0.1,0.8); //vpc->draw_line(point,next_point,col,2); @@ -402,45 +402,43 @@ void CollisionPolygon3DEditor::_polygon_draw() { r.size.y = rect.size.y; r.size.z = 0; - imgeom->set_color(Color(0.8, 0.8, 0.8, 0.2)); - imgeom->add_vertex(r.position); - imgeom->set_color(Color(0.8, 0.8, 0.8, 0.2)); - imgeom->add_vertex(r.position + Vector3(0.3, 0, 0)); - imgeom->set_color(Color(0.8, 0.8, 0.8, 0.2)); - imgeom->add_vertex(r.position); - imgeom->set_color(Color(0.8, 0.8, 0.8, 0.2)); - imgeom->add_vertex(r.position + Vector3(0.0, 0.3, 0)); - - imgeom->set_color(Color(0.8, 0.8, 0.8, 0.2)); - imgeom->add_vertex(r.position + Vector3(r.size.x, 0, 0)); - imgeom->set_color(Color(0.8, 0.8, 0.8, 0.2)); - imgeom->add_vertex(r.position + Vector3(r.size.x, 0, 0) - Vector3(0.3, 0, 0)); - imgeom->set_color(Color(0.8, 0.8, 0.8, 0.2)); - imgeom->add_vertex(r.position + Vector3(r.size.x, 0, 0)); - imgeom->set_color(Color(0.8, 0.8, 0.8, 0.2)); - imgeom->add_vertex(r.position + Vector3(r.size.x, 0, 0) + Vector3(0, 0.3, 0)); - - imgeom->set_color(Color(0.8, 0.8, 0.8, 0.2)); - imgeom->add_vertex(r.position + Vector3(0, r.size.y, 0)); - imgeom->set_color(Color(0.8, 0.8, 0.8, 0.2)); - imgeom->add_vertex(r.position + Vector3(0, r.size.y, 0) - Vector3(0, 0.3, 0)); - imgeom->set_color(Color(0.8, 0.8, 0.8, 0.2)); - imgeom->add_vertex(r.position + Vector3(0, r.size.y, 0)); - imgeom->set_color(Color(0.8, 0.8, 0.8, 0.2)); - imgeom->add_vertex(r.position + Vector3(0, r.size.y, 0) + Vector3(0.3, 0, 0)); - - imgeom->set_color(Color(0.8, 0.8, 0.8, 0.2)); - imgeom->add_vertex(r.position + r.size); - imgeom->set_color(Color(0.8, 0.8, 0.8, 0.2)); - imgeom->add_vertex(r.position + r.size - Vector3(0.3, 0, 0)); - imgeom->set_color(Color(0.8, 0.8, 0.8, 0.2)); - imgeom->add_vertex(r.position + r.size); - imgeom->set_color(Color(0.8, 0.8, 0.8, 0.2)); - imgeom->add_vertex(r.position + r.size - Vector3(0.0, 0.3, 0)); - - imgeom->end(); - - m->clear_surfaces(); + imesh->surface_set_color(Color(0.8, 0.8, 0.8, 0.2)); + imesh->surface_add_vertex(r.position); + imesh->surface_set_color(Color(0.8, 0.8, 0.8, 0.2)); + imesh->surface_add_vertex(r.position + Vector3(0.3, 0, 0)); + imesh->surface_set_color(Color(0.8, 0.8, 0.8, 0.2)); + imesh->surface_add_vertex(r.position); + imesh->surface_set_color(Color(0.8, 0.8, 0.8, 0.2)); + imesh->surface_add_vertex(r.position + Vector3(0.0, 0.3, 0)); + + imesh->surface_set_color(Color(0.8, 0.8, 0.8, 0.2)); + imesh->surface_add_vertex(r.position + Vector3(r.size.x, 0, 0)); + imesh->surface_set_color(Color(0.8, 0.8, 0.8, 0.2)); + imesh->surface_add_vertex(r.position + Vector3(r.size.x, 0, 0) - Vector3(0.3, 0, 0)); + imesh->surface_set_color(Color(0.8, 0.8, 0.8, 0.2)); + imesh->surface_add_vertex(r.position + Vector3(r.size.x, 0, 0)); + imesh->surface_set_color(Color(0.8, 0.8, 0.8, 0.2)); + imesh->surface_add_vertex(r.position + Vector3(r.size.x, 0, 0) + Vector3(0, 0.3, 0)); + + imesh->surface_set_color(Color(0.8, 0.8, 0.8, 0.2)); + imesh->surface_add_vertex(r.position + Vector3(0, r.size.y, 0)); + imesh->surface_set_color(Color(0.8, 0.8, 0.8, 0.2)); + imesh->surface_add_vertex(r.position + Vector3(0, r.size.y, 0) - Vector3(0, 0.3, 0)); + imesh->surface_set_color(Color(0.8, 0.8, 0.8, 0.2)); + imesh->surface_add_vertex(r.position + Vector3(0, r.size.y, 0)); + imesh->surface_set_color(Color(0.8, 0.8, 0.8, 0.2)); + imesh->surface_add_vertex(r.position + Vector3(0, r.size.y, 0) + Vector3(0.3, 0, 0)); + + imesh->surface_set_color(Color(0.8, 0.8, 0.8, 0.2)); + imesh->surface_add_vertex(r.position + r.size); + imesh->surface_set_color(Color(0.8, 0.8, 0.8, 0.2)); + imesh->surface_add_vertex(r.position + r.size - Vector3(0.3, 0, 0)); + imesh->surface_set_color(Color(0.8, 0.8, 0.8, 0.2)); + imesh->surface_add_vertex(r.position + r.size); + imesh->surface_set_color(Color(0.8, 0.8, 0.8, 0.2)); + imesh->surface_add_vertex(r.position + r.size - Vector3(0.0, 0.3, 0)); + + imesh->surface_end(); if (poly.size() == 0) { return; @@ -515,7 +513,9 @@ CollisionPolygon3DEditor::CollisionPolygon3DEditor(EditorNode *p_editor) { mode = MODE_EDIT; wip_active = false; - imgeom = memnew(ImmediateGeometry3D); + imgeom = memnew(MeshInstance3D); + imesh.instantiate(); + imgeom->set_mesh(imesh); imgeom->set_transform(Transform3D(Basis(), Vector3(0, 0, 0.00001))); line_material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D)); @@ -537,7 +537,7 @@ CollisionPolygon3DEditor::CollisionPolygon3DEditor(EditorNode *p_editor) { pointsm = memnew(MeshInstance3D); imgeom->add_child(pointsm); - m.instance(); + m.instantiate(); pointsm->set_mesh(m); pointsm->set_transform(Transform3D(Basis(), Vector3(0, 0, 0.00001))); diff --git a/editor/plugins/collision_polygon_3d_editor_plugin.h b/editor/plugins/collision_polygon_3d_editor_plugin.h index c66518e3e5..5db0f7308a 100644 --- a/editor/plugins/collision_polygon_3d_editor_plugin.h +++ b/editor/plugins/collision_polygon_3d_editor_plugin.h @@ -34,8 +34,8 @@ #include "editor/editor_node.h" #include "editor/editor_plugin.h" #include "scene/3d/collision_polygon_3d.h" -#include "scene/3d/immediate_geometry_3d.h" #include "scene/3d/mesh_instance_3d.h" +#include "scene/resources/immediate_mesh.h" class CanvasItemEditor; @@ -60,7 +60,8 @@ class CollisionPolygon3DEditor : public HBoxContainer { EditorNode *editor; Panel *panel; Node3D *node; - ImmediateGeometry3D *imgeom; + Ref<ImmediateMesh> imesh; + MeshInstance3D *imgeom; MeshInstance3D *pointsm; Ref<ArrayMesh> m; diff --git a/editor/plugins/cpu_particles_2d_editor_plugin.cpp b/editor/plugins/cpu_particles_2d_editor_plugin.cpp index 3403aeceba..6a56cd31d1 100644 --- a/editor/plugins/cpu_particles_2d_editor_plugin.cpp +++ b/editor/plugins/cpu_particles_2d_editor_plugin.cpp @@ -74,7 +74,7 @@ void CPUParticles2DEditorPlugin::_menu_callback(int p_idx) { void CPUParticles2DEditorPlugin::_generate_emission_mask() { Ref<Image> img; - img.instance(); + img.instantiate(); Error err = ImageLoader::load_image(source_emission_file, img); ERR_FAIL_COND_MSG(err != OK, "Error loading image '" + source_emission_file + "'."); diff --git a/editor/plugins/curve_editor_plugin.cpp b/editor/plugins/curve_editor_plugin.cpp index 7a38fd2bd5..706243fe25 100644 --- a/editor/plugins/curve_editor_plugin.cpp +++ b/editor/plugins/curve_editor_plugin.cpp @@ -127,6 +127,8 @@ void CurveEditor::on_gui_input(const Ref<InputEvent> &p_event) { case MOUSE_BUTTON_LEFT: _dragging = true; break; + default: + break; } } @@ -776,7 +778,7 @@ void EditorInspectorPluginCurve::parse_begin(Object *p_object) { CurveEditorPlugin::CurveEditorPlugin(EditorNode *p_node) { Ref<EditorInspectorPluginCurve> curve_plugin; - curve_plugin.instance(); + curve_plugin.instantiate(); EditorInspector::add_inspector_plugin(curve_plugin); get_editor_interface()->get_resource_previewer()->add_preview_generator(memnew(CurvePreviewGenerator)); @@ -798,7 +800,7 @@ Ref<Texture2D> CurvePreviewGenerator::generate(const Ref<Resource> &p_from, cons int thumbnail_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size"); thumbnail_size *= EDSCALE; Ref<Image> img_ref; - img_ref.instance(); + img_ref.instantiate(); Image &im = **img_ref; im.create(thumbnail_size, thumbnail_size / 2, false, Image::FORMAT_RGBA8); diff --git a/editor/plugins/editor_preview_plugins.cpp b/editor/plugins/editor_preview_plugins.cpp index 235ccb18cb..a233d66d82 100644 --- a/editor/plugins/editor_preview_plugins.cpp +++ b/editor/plugins/editor_preview_plugins.cpp @@ -174,7 +174,7 @@ Ref<Texture2D> EditorImagePreviewPlugin::generate(const RES &p_from, const Size2 post_process_preview(img); Ref<ImageTexture> ptex; - ptex.instance(); + ptex.instantiate(); ptex->create_from_image(img); return ptex; @@ -219,7 +219,7 @@ Ref<Texture2D> EditorBitmapPreviewPlugin::generate(const RES &p_from, const Size } Ref<Image> img; - img.instance(); + img.instantiate(); img->create(bm->get_size().width, bm->get_size().height, false, Image::FORMAT_L8, data); if (img->is_compressed()) { @@ -278,7 +278,7 @@ Ref<Texture2D> EditorPackedScenePreviewPlugin::generate_from_path(const String & } Ref<Image> img; - img.instance(); + img.instantiate(); Error err = img->load(path); if (err == OK) { Ref<ImageTexture> ptex = Ref<ImageTexture>(memnew(ImageTexture)); @@ -501,7 +501,7 @@ Ref<Texture2D> EditorScriptPreviewPlugin::generate(const RES &p_from, const Size int line = 0; int col = 0; Ref<Image> img; - img.instance(); + img.instantiate(); int thumbnail_size = MAX(p_size.x, p_size.y); img->create(thumbnail_size, thumbnail_size, false, Image::FORMAT_RGBA8); @@ -688,7 +688,7 @@ Ref<Texture2D> EditorAudioStreamPreviewPlugin::generate(const RES &p_from, const Ref<ImageTexture> ptex = Ref<ImageTexture>(memnew(ImageTexture)); Ref<Image> image; - image.instance(); + image.instantiate(); image->create(w, h, false, Image::FORMAT_RGB8, img); ptex->create_from_image(image); return ptex; @@ -881,7 +881,7 @@ Ref<Texture2D> EditorFontPreviewPlugin::generate_from_path(const String &p_path, if (res->is_class("Font")) { sampled_font = res->duplicate(); } else if (res->is_class("FontData")) { - sampled_font.instance(); + sampled_font.instantiate(); sampled_font->add_data(res->duplicate()); } diff --git a/editor/plugins/font_editor_plugin.cpp b/editor/plugins/font_editor_plugin.cpp index 8de7dc2447..e385a84087 100644 --- a/editor/plugins/font_editor_plugin.cpp +++ b/editor/plugins/font_editor_plugin.cpp @@ -119,7 +119,7 @@ void FontDataPreview::set_data(const Ref<FontData> &p_data) { } FontDataPreview::FontDataPreview() { - line.instance(); + line.instantiate(); } /*************************************************************************/ @@ -290,7 +290,7 @@ void EditorInspectorPluginFont::parse_begin(Object *p_object) { add_custom_control(editor); } -bool EditorInspectorPluginFont::parse_property(Object *p_object, Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, int p_usage, bool p_wide) { +bool EditorInspectorPluginFont::parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const uint32_t p_usage, const bool p_wide) { if (p_path.begins_with("language_support_override/") && p_object->is_class("FontData")) { String lang = p_path.replace("language_support_override/", ""); @@ -326,6 +326,6 @@ bool EditorInspectorPluginFont::parse_property(Object *p_object, Variant::Type p FontEditorPlugin::FontEditorPlugin(EditorNode *p_node) { Ref<EditorInspectorPluginFont> fd_plugin; - fd_plugin.instance(); + fd_plugin.instantiate(); EditorInspector::add_inspector_plugin(fd_plugin); } diff --git a/editor/plugins/font_editor_plugin.h b/editor/plugins/font_editor_plugin.h index 04e6c1dac7..71464003a0 100644 --- a/editor/plugins/font_editor_plugin.h +++ b/editor/plugins/font_editor_plugin.h @@ -94,7 +94,7 @@ class EditorInspectorPluginFont : public EditorInspectorPlugin { public: virtual bool can_handle(Object *p_object) override; virtual void parse_begin(Object *p_object) override; - virtual bool parse_property(Object *p_object, Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, int p_usage, bool p_wide) override; + virtual bool parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const uint32_t p_usage, const bool p_wide = false) override; }; /*************************************************************************/ diff --git a/editor/plugins/gpu_particles_2d_editor_plugin.cpp b/editor/plugins/gpu_particles_2d_editor_plugin.cpp index b447304a3f..37f900280b 100644 --- a/editor/plugins/gpu_particles_2d_editor_plugin.cpp +++ b/editor/plugins/gpu_particles_2d_editor_plugin.cpp @@ -146,7 +146,7 @@ void GPUParticles2DEditorPlugin::_generate_emission_mask() { } Ref<Image> img; - img.instance(); + img.instantiate(); Error err = ImageLoader::load_image(source_emission_file, img); ERR_FAIL_COND_MSG(err != OK, "Error loading image '" + source_emission_file + "'."); @@ -270,11 +270,11 @@ void GPUParticles2DEditorPlugin::_generate_emission_mask() { } } - img.instance(); + img.instantiate(); img->create(w, h, false, Image::FORMAT_RGF, texdata); Ref<ImageTexture> imgt; - imgt.instance(); + imgt.instantiate(); imgt->create_from_image(img); pm->set_emission_point_texture(imgt); @@ -291,10 +291,10 @@ void GPUParticles2DEditorPlugin::_generate_emission_mask() { } } - img.instance(); + img.instantiate(); img->create(w, h, false, Image::FORMAT_RGBA8, colordata); - imgt.instance(); + imgt.instantiate(); imgt->create_from_image(img); pm->set_emission_color_texture(imgt); } @@ -314,10 +314,10 @@ void GPUParticles2DEditorPlugin::_generate_emission_mask() { } } - img.instance(); + img.instantiate(); img->create(w, h, false, Image::FORMAT_RGF, normdata); - imgt.instance(); + imgt.instantiate(); imgt->create_from_image(img); pm->set_emission_normal_texture(imgt); diff --git a/editor/plugins/gpu_particles_3d_editor_plugin.cpp b/editor/plugins/gpu_particles_3d_editor_plugin.cpp index 17c7397729..571bcf9c4a 100644 --- a/editor/plugins/gpu_particles_3d_editor_plugin.cpp +++ b/editor/plugins/gpu_particles_3d_editor_plugin.cpp @@ -359,7 +359,7 @@ void GPUParticles3DEditor::_generate_emission_points() { Ref<Image> image = memnew(Image(w, h, false, Image::FORMAT_RGBF, point_img)); Ref<ImageTexture> tex; - tex.instance(); + tex.instantiate(); Ref<ParticlesMaterial> material = node->get_process_material(); ERR_FAIL_COND(material.is_null()); @@ -387,7 +387,7 @@ void GPUParticles3DEditor::_generate_emission_points() { Ref<Image> image2 = memnew(Image(w, h, false, Image::FORMAT_RGBF, point_img2)); Ref<ImageTexture> tex2; - tex2.instance(); + tex2.instantiate(); material->set_emission_normal_texture(tex2); } else { diff --git a/editor/plugins/gpu_particles_collision_sdf_editor_plugin.cpp b/editor/plugins/gpu_particles_collision_sdf_editor_plugin.cpp index 8c4928b7cb..a2dee4a1dc 100644 --- a/editor/plugins/gpu_particles_collision_sdf_editor_plugin.cpp +++ b/editor/plugins/gpu_particles_collision_sdf_editor_plugin.cpp @@ -137,7 +137,7 @@ void GPUParticlesCollisionSDFEditorPlugin::_sdf_save_path_and_bake(const String Ref<ConfigFile> config; - config.instance(); + config.instantiate(); if (FileAccess::exists(p_path + ".import")) { config->load(p_path + ".import"); } diff --git a/editor/plugins/gradient_editor_plugin.cpp b/editor/plugins/gradient_editor_plugin.cpp index 46fa00f730..355bdb69d8 100644 --- a/editor/plugins/gradient_editor_plugin.cpp +++ b/editor/plugins/gradient_editor_plugin.cpp @@ -92,6 +92,6 @@ void EditorInspectorPluginGradient::parse_begin(Object *p_object) { GradientEditorPlugin::GradientEditorPlugin(EditorNode *p_node) { Ref<EditorInspectorPluginGradient> plugin; - plugin.instance(); + plugin.instantiate(); add_inspector_plugin(plugin); } diff --git a/editor/plugins/input_event_editor_plugin.cpp b/editor/plugins/input_event_editor_plugin.cpp new file mode 100644 index 0000000000..f1aa10844b --- /dev/null +++ b/editor/plugins/input_event_editor_plugin.cpp @@ -0,0 +1,122 @@ +/*************************************************************************/ +/* input_event_editor_plugin.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "input_event_editor_plugin.h" + +void InputEventConfigContainer::_bind_methods() { +} + +void InputEventConfigContainer::_configure_pressed() { + config_dialog->popup_and_configure(input_event); +} + +void InputEventConfigContainer::_event_changed() { + input_event_text->set_text(input_event->as_text()); +} + +void InputEventConfigContainer::_config_dialog_confirmed() { + Ref<InputEvent> ie = config_dialog->get_event(); + input_event->copy_from(ie); + _event_changed(); +} + +Size2 InputEventConfigContainer::get_minimum_size() const { + // Don't bother with a minimum x size for the control - we don't want the inspector + // to jump in size if a long text is placed in the label (e.g. Joypad Axis description) + return Size2(0, HBoxContainer::get_minimum_size().y); +} + +void InputEventConfigContainer::set_event(const Ref<InputEvent> &p_event) { + Ref<InputEventKey> k = p_event; + Ref<InputEventMouseButton> m = p_event; + Ref<InputEventJoypadButton> jb = p_event; + Ref<InputEventJoypadMotion> jm = p_event; + + if (k.is_valid()) { + config_dialog->set_allowed_input_types(InputEventConfigurationDialog::InputType::INPUT_KEY); + } else if (m.is_valid()) { + config_dialog->set_allowed_input_types(InputEventConfigurationDialog::InputType::INPUT_MOUSE_BUTTON); + } else if (jb.is_valid()) { + config_dialog->set_allowed_input_types(InputEventConfigurationDialog::InputType::INPUT_JOY_BUTTON); + } else if (jm.is_valid()) { + config_dialog->set_allowed_input_types(InputEventConfigurationDialog::InputType::INPUT_JOY_MOTION); + } + + input_event = p_event; + _event_changed(); + input_event->connect("changed", callable_mp(this, &InputEventConfigContainer::_event_changed)); +} + +InputEventConfigContainer::InputEventConfigContainer() { + MarginContainer *mc = memnew(MarginContainer); + mc->add_theme_constant_override("margin_left", 10); + mc->add_theme_constant_override("margin_right", 10); + mc->add_theme_constant_override("margin_top", 10); + mc->add_theme_constant_override("margin_bottom", 10); + add_child(mc); + + HBoxContainer *hb = memnew(HBoxContainer); + mc->add_child(hb); + + open_config_button = memnew(Button); + open_config_button->set_text("Configure"); + open_config_button->connect("pressed", callable_mp(this, &InputEventConfigContainer::_configure_pressed)); + hb->add_child(open_config_button); + + input_event_text = memnew(Label); + hb->add_child(input_event_text); + + config_dialog = memnew(InputEventConfigurationDialog); + config_dialog->connect("confirmed", callable_mp(this, &InputEventConfigContainer::_config_dialog_confirmed)); + add_child(config_dialog); +} + +bool EditorInspectorPluginInputEvent::can_handle(Object *p_object) { + Ref<InputEventKey> k = Ref<InputEventKey>(p_object); + Ref<InputEventMouseButton> m = Ref<InputEventMouseButton>(p_object); + Ref<InputEventJoypadButton> jb = Ref<InputEventJoypadButton>(p_object); + Ref<InputEventJoypadMotion> jm = Ref<InputEventJoypadMotion>(p_object); + + return k.is_valid() || m.is_valid() || jb.is_valid() || jm.is_valid(); +} + +void EditorInspectorPluginInputEvent::parse_begin(Object *p_object) { + Ref<InputEvent> ie = Ref<InputEvent>(p_object); + + InputEventConfigContainer *picker_controls = memnew(InputEventConfigContainer); + picker_controls->set_event(ie); + add_custom_control(picker_controls); +} + +InputEventEditorPlugin::InputEventEditorPlugin(EditorNode *p_node) { + Ref<EditorInspectorPluginInputEvent> plugin; + plugin.instantiate(); + add_inspector_plugin(plugin); +} diff --git a/editor/plugins/input_event_editor_plugin.h b/editor/plugins/input_event_editor_plugin.h new file mode 100644 index 0000000000..bc8293c9e5 --- /dev/null +++ b/editor/plugins/input_event_editor_plugin.h @@ -0,0 +1,79 @@ +/*************************************************************************/ +/* input_event_editor_plugin.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef INPUT_EVENT_EDITOR_PLUGIN_H +#define INPUT_EVENT_EDITOR_PLUGIN_H + +#include "editor/action_map_editor.h" +#include "editor/editor_inspector.h" +#include "editor/editor_node.h" + +class InputEventConfigContainer : public HBoxContainer { + GDCLASS(InputEventConfigContainer, HBoxContainer); + + Label *input_event_text; + Button *open_config_button; + + Ref<InputEvent> input_event; + InputEventConfigurationDialog *config_dialog; + + void _config_dialog_confirmed(); + void _configure_pressed(); + + void _event_changed(); + +protected: + static void _bind_methods(); + +public: + virtual Size2 get_minimum_size() const override; + void set_event(const Ref<InputEvent> &p_event); + + InputEventConfigContainer(); +}; + +class EditorInspectorPluginInputEvent : public EditorInspectorPlugin { + GDCLASS(EditorInspectorPluginInputEvent, EditorInspectorPlugin); + +public: + virtual bool can_handle(Object *p_object) override; + virtual void parse_begin(Object *p_object) override; +}; + +class InputEventEditorPlugin : public EditorPlugin { + GDCLASS(InputEventEditorPlugin, EditorPlugin); + +public: + virtual String get_name() const override { return "InputEvent"; } + + InputEventEditorPlugin(EditorNode *p_node); +}; + +#endif // INPUT_EVENT_EDITOR_PLUGIN_H diff --git a/editor/plugins/material_editor_plugin.cpp b/editor/plugins/material_editor_plugin.cpp index 81f0ecacf2..17a634ee14 100644 --- a/editor/plugins/material_editor_plugin.cpp +++ b/editor/plugins/material_editor_plugin.cpp @@ -111,7 +111,7 @@ MaterialEditor::MaterialEditor() { vc->set_anchors_and_offsets_preset(PRESET_WIDE); viewport = memnew(SubViewport); Ref<World3D> world_3d; - world_3d.instance(); + world_3d.instantiate(); viewport->set_world_3d(world_3d); //use own world vc->add_child(viewport); viewport->set_disable_input(true); @@ -146,9 +146,9 @@ MaterialEditor::MaterialEditor() { box_xform.origin.y = 0.2; box_instance->set_transform(box_xform); - sphere_mesh.instance(); + sphere_mesh.instantiate(); sphere_instance->set_mesh(sphere_mesh); - box_mesh.instance(); + box_mesh.instantiate(); box_instance->set_mesh(box_mesh); set_custom_minimum_size(Size2(1, 150) * EDSCALE); @@ -223,7 +223,7 @@ void EditorInspectorPluginMaterial::parse_begin(Object *p_object) { } EditorInspectorPluginMaterial::EditorInspectorPluginMaterial() { - env.instance(); + env.instantiate(); Ref<Sky> sky = memnew(Sky()); env->set_sky(sky); env->set_background(Environment::BG_COLOR); @@ -233,7 +233,7 @@ EditorInspectorPluginMaterial::EditorInspectorPluginMaterial() { MaterialEditorPlugin::MaterialEditorPlugin(EditorNode *p_node) { Ref<EditorInspectorPluginMaterial> plugin; - plugin.instance(); + plugin.instantiate(); add_inspector_plugin(plugin); } @@ -251,10 +251,10 @@ Ref<Resource> StandardMaterial3DConversionPlugin::convert(const Ref<Resource> &p ERR_FAIL_COND_V(!mat.is_valid(), Ref<Resource>()); Ref<ShaderMaterial> smat; - smat.instance(); + smat.instantiate(); Ref<Shader> shader; - shader.instance(); + shader.instantiate(); String code = RS::get_singleton()->shader_get_code(mat->get_shader_rid()); @@ -295,10 +295,10 @@ Ref<Resource> ParticlesMaterialConversionPlugin::convert(const Ref<Resource> &p_ ERR_FAIL_COND_V(!mat.is_valid(), Ref<Resource>()); Ref<ShaderMaterial> smat; - smat.instance(); + smat.instantiate(); Ref<Shader> shader; - shader.instance(); + shader.instantiate(); String code = RS::get_singleton()->shader_get_code(mat->get_shader_rid()); @@ -332,10 +332,10 @@ Ref<Resource> CanvasItemMaterialConversionPlugin::convert(const Ref<Resource> &p ERR_FAIL_COND_V(!mat.is_valid(), Ref<Resource>()); Ref<ShaderMaterial> smat; - smat.instance(); + smat.instantiate(); Ref<Shader> shader; - shader.instance(); + shader.instantiate(); String code = RS::get_singleton()->shader_get_code(mat->get_shader_rid()); @@ -369,10 +369,10 @@ Ref<Resource> ProceduralSkyMaterialConversionPlugin::convert(const Ref<Resource> ERR_FAIL_COND_V(!mat.is_valid(), Ref<Resource>()); Ref<ShaderMaterial> smat; - smat.instance(); + smat.instantiate(); Ref<Shader> shader; - shader.instance(); + shader.instantiate(); String code = RS::get_singleton()->shader_get_code(mat->get_shader_rid()); @@ -406,10 +406,10 @@ Ref<Resource> PanoramaSkyMaterialConversionPlugin::convert(const Ref<Resource> & ERR_FAIL_COND_V(!mat.is_valid(), Ref<Resource>()); Ref<ShaderMaterial> smat; - smat.instance(); + smat.instantiate(); Ref<Shader> shader; - shader.instance(); + shader.instantiate(); String code = RS::get_singleton()->shader_get_code(mat->get_shader_rid()); @@ -443,10 +443,10 @@ Ref<Resource> PhysicalSkyMaterialConversionPlugin::convert(const Ref<Resource> & ERR_FAIL_COND_V(!mat.is_valid(), Ref<Resource>()); Ref<ShaderMaterial> smat; - smat.instance(); + smat.instantiate(); Ref<Shader> shader; - shader.instance(); + shader.instantiate(); String code = RS::get_singleton()->shader_get_code(mat->get_shader_rid()); diff --git a/editor/plugins/mesh_editor_plugin.cpp b/editor/plugins/mesh_editor_plugin.cpp index 8d488dce20..fcc6b84efb 100644 --- a/editor/plugins/mesh_editor_plugin.cpp +++ b/editor/plugins/mesh_editor_plugin.cpp @@ -110,7 +110,7 @@ void MeshEditor::_bind_methods() { MeshEditor::MeshEditor() { viewport = memnew(SubViewport); Ref<World3D> world_3d; - world_3d.instance(); + world_3d.instantiate(); viewport->set_world_3d(world_3d); //use own world add_child(viewport); viewport->set_disable_input(true); @@ -182,6 +182,6 @@ void EditorInspectorPluginMesh::parse_begin(Object *p_object) { MeshEditorPlugin::MeshEditorPlugin(EditorNode *p_node) { Ref<EditorInspectorPluginMesh> plugin; - plugin.instance(); + plugin.instantiate(); add_inspector_plugin(plugin); } diff --git a/editor/plugins/mesh_library_editor_plugin.cpp b/editor/plugins/mesh_library_editor_plugin.cpp index e64992759d..5d1d29cbc8 100644 --- a/editor/plugins/mesh_library_editor_plugin.cpp +++ b/editor/plugins/mesh_library_editor_plugin.cpp @@ -193,7 +193,7 @@ void MeshLibraryEditor::_import_scene(Node *p_scene, Ref<MeshLibrary> p_library, void MeshLibraryEditor::_import_scene_cbk(const String &p_str) { Ref<PackedScene> ps = ResourceLoader::load(p_str, "PackedScene"); ERR_FAIL_COND(ps.is_null()); - Node *scene = ps->instance(); + Node *scene = ps->instantiate(); ERR_FAIL_COND_MSG(!scene, "Cannot create an instance from PackedScene '" + p_str + "'."); diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp index 4aa08d425c..72a63539b3 100644 --- a/editor/plugins/node_3d_editor_plugin.cpp +++ b/editor/plugins/node_3d_editor_plugin.cpp @@ -1407,6 +1407,8 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { } } break; + default: + break; } } @@ -1974,6 +1976,13 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { return; } + if (EditorSettings::get_singleton()->get("editors/3d/navigation/emulate_numpad")) { + const uint32_t code = k->get_keycode(); + if (code >= KEY_0 && code <= KEY_9) { + k->set_keycode(code - KEY_0 + KEY_KP_0); + } + } + if (ED_IS_SHORTCUT("spatial_editor/snap", p_event)) { if (_edit.mode != TRANSFORM_NONE) { _edit.snap = !_edit.snap; @@ -2511,25 +2520,21 @@ void Node3DEditorViewport::_notification(int p_what) { } if (show_info) { + const String viewport_size = vformat(String::utf8("%d × %d"), viewport->get_size().x, viewport->get_size().y); String text; - text += "X: " + rtos(current_camera->get_position().x).pad_decimals(1) + "\n"; - text += "Y: " + rtos(current_camera->get_position().y).pad_decimals(1) + "\n"; - text += "Z: " + rtos(current_camera->get_position().z).pad_decimals(1) + "\n"; - text += TTR("Pitch") + ": " + itos(Math::round(current_camera->get_rotation_degrees().x)) + "\n"; - text += TTR("Yaw") + ": " + itos(Math::round(current_camera->get_rotation_degrees().y)) + "\n\n"; - - text += TTR("Size") + - vformat( - ": %dx%d (%.1fMP)\n", - viewport->get_size().x, - viewport->get_size().y, - viewport->get_size().x * viewport->get_size().y * 0.000'001); - text += TTR("Objects Drawn") + ": " + itos(viewport->get_render_info(Viewport::RENDER_INFO_OBJECTS_IN_FRAME)) + "\n"; - text += TTR("Material Changes") + ": " + itos(viewport->get_render_info(Viewport::RENDER_INFO_MATERIAL_CHANGES_IN_FRAME)) + "\n"; - text += TTR("Shader Changes") + ": " + itos(viewport->get_render_info(Viewport::RENDER_INFO_SHADER_CHANGES_IN_FRAME)) + "\n"; - text += TTR("Surface Changes") + ": " + itos(viewport->get_render_info(Viewport::RENDER_INFO_SURFACE_CHANGES_IN_FRAME)) + "\n"; - text += TTR("Draw Calls") + ": " + itos(viewport->get_render_info(Viewport::RENDER_INFO_DRAW_CALLS_IN_FRAME)) + "\n"; - text += TTR("Vertices") + ": " + itos(viewport->get_render_info(Viewport::RENDER_INFO_VERTICES_IN_FRAME)); + text += vformat(TTR("X: %s\n"), rtos(current_camera->get_position().x).pad_decimals(1)); + text += vformat(TTR("Y: %s\n"), rtos(current_camera->get_position().y).pad_decimals(1)); + text += vformat(TTR("Z: %s\n"), rtos(current_camera->get_position().z).pad_decimals(1)); + text += "\n"; + text += vformat( + TTR("Size: %s (%.1fMP)\n"), + viewport_size, + viewport->get_size().x * viewport->get_size().y * 0.000001); + + text += "\n"; + text += vformat(TTR("Objects: %d\n"), viewport->get_render_info(Viewport::RENDER_INFO_TYPE_VISIBLE, Viewport::RENDER_INFO_OBJECTS_IN_FRAME)); + text += vformat(TTR("Primitives: %d\n"), viewport->get_render_info(Viewport::RENDER_INFO_TYPE_VISIBLE, Viewport::RENDER_INFO_PRIMITIVES_IN_FRAME)); + text += vformat(TTR("Draw Calls: %d"), viewport->get_render_info(Viewport::RENDER_INFO_TYPE_VISIBLE, Viewport::RENDER_INFO_DRAW_CALLS_IN_FRAME)); info_label->set_text(text); } @@ -3261,14 +3266,12 @@ void Node3DEditorViewport::_toggle_camera_preview(bool p_activate) { if (!preview) { preview_camera->hide(); } - view_menu->set_disabled(false); surface->update(); } else { previewing = preview; previewing->connect("tree_exiting", callable_mp(this, &Node3DEditorViewport::_preview_exited_scene)); RS::get_singleton()->viewport_attach_camera(viewport->get_viewport_rid(), preview->get_camera()); //replace - view_menu->set_disabled(true); surface->update(); } } @@ -3515,7 +3518,6 @@ void Node3DEditorViewport::set_state(const Dictionary &p_state) { previewing = Object::cast_to<Camera3D>(pv); previewing->connect("tree_exiting", callable_mp(this, &Node3DEditorViewport::_preview_exited_scene)); RS::get_singleton()->viewport_attach_camera(viewport->get_viewport_rid(), previewing->get_camera()); //replace - view_menu->set_disabled(true); surface->update(); preview_camera->set_pressed(true); preview_camera->show(); @@ -3723,7 +3725,7 @@ void Node3DEditorViewport::_create_preview(const Vector<String> &files) const { preview_node->add_child(mesh_instance); } else { if (scene.is_valid()) { - Node *instance = scene->instance(); + Node *instance = scene->instantiate(); if (instance) { preview_node->add_child(instance); } @@ -3768,49 +3770,49 @@ bool Node3DEditorViewport::_create_instance(Node *parent, String &path, const Po Ref<PackedScene> scene = Ref<PackedScene>(Object::cast_to<PackedScene>(*res)); Ref<Mesh> mesh = Ref<Mesh>(Object::cast_to<Mesh>(*res)); - Node *instanced_scene = nullptr; + Node *instantiated_scene = nullptr; if (mesh != nullptr || scene != nullptr) { if (mesh != nullptr) { MeshInstance3D *mesh_instance = memnew(MeshInstance3D); mesh_instance->set_mesh(mesh); mesh_instance->set_name(path.get_file().get_basename()); - instanced_scene = mesh_instance; + instantiated_scene = mesh_instance; } else { if (!scene.is_valid()) { // invalid scene return false; } else { - instanced_scene = scene->instance(PackedScene::GEN_EDIT_STATE_INSTANCE); + instantiated_scene = scene->instantiate(PackedScene::GEN_EDIT_STATE_INSTANCE); } } } - if (instanced_scene == nullptr) { + if (instantiated_scene == nullptr) { return false; } if (editor->get_edited_scene()->get_filename() != "") { // cyclical instancing - if (_cyclical_dependency_exists(editor->get_edited_scene()->get_filename(), instanced_scene)) { - memdelete(instanced_scene); + if (_cyclical_dependency_exists(editor->get_edited_scene()->get_filename(), instantiated_scene)) { + memdelete(instantiated_scene); return false; } } if (scene != nullptr) { - instanced_scene->set_filename(ProjectSettings::get_singleton()->localize_path(path)); + instantiated_scene->set_filename(ProjectSettings::get_singleton()->localize_path(path)); } - editor_data->get_undo_redo().add_do_method(parent, "add_child", instanced_scene); - editor_data->get_undo_redo().add_do_method(instanced_scene, "set_owner", editor->get_edited_scene()); - editor_data->get_undo_redo().add_do_reference(instanced_scene); - editor_data->get_undo_redo().add_undo_method(parent, "remove_child", instanced_scene); + editor_data->get_undo_redo().add_do_method(parent, "add_child", instantiated_scene); + editor_data->get_undo_redo().add_do_method(instantiated_scene, "set_owner", editor->get_edited_scene()); + editor_data->get_undo_redo().add_do_reference(instantiated_scene); + editor_data->get_undo_redo().add_undo_method(parent, "remove_child", instantiated_scene); - String new_name = parent->validate_child_name(instanced_scene); + String new_name = parent->validate_child_name(instantiated_scene); EditorDebuggerNode *ed = EditorDebuggerNode::get_singleton(); editor_data->get_undo_redo().add_do_method(ed, "live_debug_instance_node", editor->get_edited_scene()->get_path_to(parent), path, new_name); editor_data->get_undo_redo().add_undo_method(ed, "live_debug_remove_node", NodePath(String(editor->get_edited_scene()->get_path_to(parent)) + "/" + new_name)); - Node3D *node3d = Object::cast_to<Node3D>(instanced_scene); + Node3D *node3d = Object::cast_to<Node3D>(instantiated_scene); if (node3d) { Transform3D global_transform; Node3D *parent_node3d = Object::cast_to<Node3D>(parent); @@ -3821,7 +3823,7 @@ bool Node3DEditorViewport::_create_instance(Node *parent, String &path, const Po global_transform.origin = spatial_editor->snap_point(_get_instance_position(p_point)); global_transform.basis *= node3d->get_transform().basis; - editor_data->get_undo_redo().add_do_method(instanced_scene, "set_global_transform", global_transform); + editor_data->get_undo_redo().add_do_method(instantiated_scene, "set_global_transform", global_transform); } return true; @@ -3864,7 +3866,7 @@ void Node3DEditorViewport::_perform_drop_data() { } bool Node3DEditorViewport::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const { - bool can_instance = false; + bool can_instantiate = false; if (!preview_node->is_inside_tree()) { Dictionary d = p_data; @@ -3886,11 +3888,11 @@ bool Node3DEditorViewport::can_drop_data_fw(const Point2 &p_point, const Variant String type = res->get_class(); if (type == "PackedScene") { Ref<PackedScene> sdata = ResourceLoader::load(files[i]); - Node *instanced_scene = sdata->instance(PackedScene::GEN_EDIT_STATE_INSTANCE); - if (!instanced_scene) { + Node *instantiated_scene = sdata->instantiate(PackedScene::GEN_EDIT_STATE_INSTANCE); + if (!instantiated_scene) { continue; } - memdelete(instanced_scene); + memdelete(instantiated_scene); } else if (type == "Mesh" || type == "ArrayMesh" || type == "PrimitiveMesh") { Ref<Mesh> mesh = ResourceLoader::load(files[i]); if (!mesh.is_valid()) { @@ -3899,24 +3901,24 @@ bool Node3DEditorViewport::can_drop_data_fw(const Point2 &p_point, const Variant } else { continue; } - can_instance = true; + can_instantiate = true; break; } } - if (can_instance) { + if (can_instantiate) { _create_preview(files); } } } else { - can_instance = true; + can_instantiate = true; } - if (can_instance) { + if (can_instantiate) { Transform3D global_transform = Transform3D(Basis(), _get_instance_position(p_point)); preview_node->set_global_transform(global_transform); } - return can_instance; + return can_instantiate; } void Node3DEditorViewport::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) { @@ -5326,7 +5328,7 @@ void Node3DEditor::_init_indicators() { origin_enabled = true; grid_enabled = true; - indicator_mat.instance(); + indicator_mat.instantiate(); indicator_mat->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED); indicator_mat->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); indicator_mat->set_flag(StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, true); @@ -5406,7 +5408,7 @@ void Node3DEditor::_init_indicators() { "}"); for (int i = 0; i < 3; i++) { - grid_mat[i].instance(); + grid_mat[i].instantiate(); grid_mat[i]->set_shader(grid_shader); } @@ -6225,31 +6227,47 @@ void Node3DEditor::_sun_environ_settings_pressed() { sun_environ_popup->popup(); } -void Node3DEditor::_add_sun_to_scene() { +void Node3DEditor::_add_sun_to_scene(bool p_already_added_environment) { sun_environ_popup->hide(); + if (!p_already_added_environment && world_env_count == 0 && Input::get_singleton()->is_key_pressed(KEY_SHIFT)) { + // Prevent infinite feedback loop between the sun and environment methods. + _add_environment_to_scene(true); + } + Node *base = get_tree()->get_edited_scene_root(); if (!base) { - EditorNode::get_singleton()->show_warning(TTR("A root node is needed for this operation")); - return; + // Create a root node so we can add child nodes to it. + EditorNode::get_singleton()->get_scene_tree_dock()->add_root_node(memnew(Node3D)); + base = get_tree()->get_edited_scene_root(); } ERR_FAIL_COND(!base); Node *new_sun = preview_sun->duplicate(); undo_redo->create_action("Add Preview Sun to Scene"); undo_redo->add_do_method(base, "add_child", new_sun); + // Move to the beginning of the scene tree since more "global" nodes + // generally look better when placed at the top. + undo_redo->add_do_method(base, "move_child", new_sun, 0); undo_redo->add_do_method(new_sun, "set_owner", base); undo_redo->add_undo_method(base, "remove_child", new_sun); undo_redo->add_do_reference(new_sun); undo_redo->commit_action(); } -void Node3DEditor::_add_environment_to_scene() { + +void Node3DEditor::_add_environment_to_scene(bool p_already_added_sun) { sun_environ_popup->hide(); + if (!p_already_added_sun && directional_light_count == 0 && Input::get_singleton()->is_key_pressed(KEY_SHIFT)) { + // Prevent infinite feedback loop between the sun and environment methods. + _add_sun_to_scene(true); + } + Node *base = get_tree()->get_edited_scene_root(); if (!base) { - EditorNode::get_singleton()->show_warning(TTR("A root node is needed for this operation")); - return; + // Create a root node so we can add child nodes to it. + EditorNode::get_singleton()->get_scene_tree_dock()->add_root_node(memnew(Node3D)); + base = get_tree()->get_edited_scene_root(); } ERR_FAIL_COND(!base); @@ -6258,6 +6276,9 @@ void Node3DEditor::_add_environment_to_scene() { undo_redo->create_action("Add Preview Environment to Scene"); undo_redo->add_do_method(base, "add_child", new_env); + // Move to the beginning of the scene tree since more "global" nodes + // generally look better when placed at the top. + undo_redo->add_do_method(base, "move_child", new_env, 0); undo_redo->add_do_method(new_env, "set_owner", base); undo_redo->add_undo_method(base, "remove_child", new_env); undo_redo->add_do_reference(new_env); @@ -6380,7 +6401,7 @@ void Node3DEditor::_request_gizmo(Object *p_obj) { if (!sp) { return; } - if (editor->get_edited_scene() && (sp == editor->get_edited_scene() || (sp->get_owner() && editor->get_edited_scene()->is_a_parent_of(sp)))) { + if (editor->get_edited_scene() && (sp == editor->get_edited_scene() || (sp->get_owner() && editor->get_edited_scene()->is_ancestor_of(sp)))) { Ref<EditorNode3DGizmo> seg; for (int i = 0; i < gizmo_plugins_by_priority.size(); ++i) { @@ -6454,7 +6475,7 @@ void Node3DEditor::_toggle_maximize_view(Object *p_viewport) { } void Node3DEditor::_node_added(Node *p_node) { - if (EditorNode::get_singleton()->get_scene_root()->is_a_parent_of(p_node)) { + if (EditorNode::get_singleton()->get_scene_root()->is_ancestor_of(p_node)) { if (Object::cast_to<WorldEnvironment>(p_node)) { world_env_count++; if (world_env_count == 1) { @@ -6470,7 +6491,7 @@ void Node3DEditor::_node_added(Node *p_node) { } void Node3DEditor::_node_removed(Node *p_node) { - if (EditorNode::get_singleton()->get_scene_root()->is_a_parent_of(p_node)) { + if (EditorNode::get_singleton()->get_scene_root()->is_ancestor_of(p_node)) { if (Object::cast_to<WorldEnvironment>(p_node)) { world_env_count--; if (world_env_count == 0) { @@ -6785,6 +6806,8 @@ Node3DEditor::Node3DEditor(EditorNode *p_editor) { button_binds.write[0] = MENU_LOCK_SELECTED; tool_button[TOOL_LOCK_SELECTED]->connect("pressed", callable_mp(this, &Node3DEditor::_menu_item_pressed), button_binds); tool_button[TOOL_LOCK_SELECTED]->set_tooltip(TTR("Lock the selected object in place (can't be moved).")); + // Define the shortcut globally (without a context) so that it works if the Scene tree dock is currently focused. + tool_button[TOOL_LOCK_SELECTED]->set_shortcut(ED_SHORTCUT("editor/lock_selected_nodes", TTR("Lock Selected Node(s)"), KEY_MASK_CMD | KEY_L)); tool_button[TOOL_UNLOCK_SELECTED] = memnew(Button); hbc_menu->add_child(tool_button[TOOL_UNLOCK_SELECTED]); @@ -6792,6 +6815,8 @@ Node3DEditor::Node3DEditor(EditorNode *p_editor) { button_binds.write[0] = MENU_UNLOCK_SELECTED; tool_button[TOOL_UNLOCK_SELECTED]->connect("pressed", callable_mp(this, &Node3DEditor::_menu_item_pressed), button_binds); tool_button[TOOL_UNLOCK_SELECTED]->set_tooltip(TTR("Unlock the selected object (can be moved).")); + // Define the shortcut globally (without a context) so that it works if the Scene tree dock is currently focused. + tool_button[TOOL_UNLOCK_SELECTED]->set_shortcut(ED_SHORTCUT("editor/unlock_selected_nodes", TTR("Unlock Selected Node(s)"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_L)); tool_button[TOOL_GROUP_SELECTED] = memnew(Button); hbc_menu->add_child(tool_button[TOOL_GROUP_SELECTED]); @@ -6799,6 +6824,8 @@ Node3DEditor::Node3DEditor(EditorNode *p_editor) { button_binds.write[0] = MENU_GROUP_SELECTED; tool_button[TOOL_GROUP_SELECTED]->connect("pressed", callable_mp(this, &Node3DEditor::_menu_item_pressed), button_binds); tool_button[TOOL_GROUP_SELECTED]->set_tooltip(TTR("Makes sure the object's children are not selectable.")); + // Define the shortcut globally (without a context) so that it works if the Scene tree dock is currently focused. + tool_button[TOOL_GROUP_SELECTED]->set_shortcut(ED_SHORTCUT("editor/group_selected_nodes", TTR("Group Selected Node(s)"), KEY_MASK_CMD | KEY_G)); tool_button[TOOL_UNGROUP_SELECTED] = memnew(Button); hbc_menu->add_child(tool_button[TOOL_UNGROUP_SELECTED]); @@ -6806,6 +6833,8 @@ Node3DEditor::Node3DEditor(EditorNode *p_editor) { button_binds.write[0] = MENU_UNGROUP_SELECTED; tool_button[TOOL_UNGROUP_SELECTED]->connect("pressed", callable_mp(this, &Node3DEditor::_menu_item_pressed), button_binds); tool_button[TOOL_UNGROUP_SELECTED]->set_tooltip(TTR("Restores the object's children's ability to be selected.")); + // Define the shortcut globally (without a context) so that it works if the Scene tree dock is currently focused. + tool_button[TOOL_UNGROUP_SELECTED]->set_shortcut(ED_SHORTCUT("editor/ungroup_selected_nodes", TTR("Ungroup Selected Node(s)"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_G)); hbc_menu->add_child(memnew(VSeparator)); @@ -6924,7 +6953,7 @@ Node3DEditor::Node3DEditor(EditorNode *p_editor) { p->add_separator(); p->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_origin", TTR("View Origin")), MENU_VIEW_ORIGIN); - p->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_grid", TTR("View Grid")), MENU_VIEW_GRID); + p->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_grid", TTR("View Grid"), KEY_NUMBERSIGN), MENU_VIEW_GRID); p->add_separator(); p->add_shortcut(ED_SHORTCUT("spatial_editor/settings", TTR("Settings...")), MENU_VIEW_CAMERA_SETTINGS); @@ -7080,8 +7109,6 @@ Node3DEditor::Node3DEditor(EditorNode *p_editor) { xform_dialog->connect("confirmed", callable_mp(this, &Node3DEditor::_xform_dialog_action)); - scenario_debug = RenderingServer::SCENARIO_DEBUG_DISABLED; - selected = nullptr; set_process_unhandled_key_input(true); @@ -7124,9 +7151,9 @@ Node3DEditor::Node3DEditor(EditorNode *p_editor) { sun_direction->set_default_cursor_shape(CURSOR_MOVE); String sun_dir_shader_code = "shader_type canvas_item; uniform vec3 sun_direction; uniform vec3 sun_color; void fragment() { vec3 n; n.xy = UV * 2.0 - 1.0; n.z = sqrt(max(0.0, 1.0 - dot(n.xy, n.xy))); COLOR.rgb = dot(n,sun_direction) * sun_color; COLOR.a = 1.0 - smoothstep(0.99,1.0,length(n.xy)); }"; - sun_direction_shader.instance(); + sun_direction_shader.instantiate(); sun_direction_shader->set_code(sun_dir_shader_code); - sun_direction_material.instance(); + sun_direction_material.instantiate(); sun_direction_material->set_shader(sun_direction_shader); sun_direction_material->set_shader_param("sun_direction", Vector3(0, 0, 1)); sun_direction_material->set_shader_param("sun_color", Vector3(1, 1, 1)); @@ -7179,7 +7206,8 @@ Node3DEditor::Node3DEditor(EditorNode *p_editor) { sun_add_to_scene = memnew(Button); sun_add_to_scene->set_text(TTR("Add Sun to Scene")); - sun_add_to_scene->connect("pressed", callable_mp(this, &Node3DEditor::_add_sun_to_scene)); + sun_add_to_scene->set_tooltip(TTR("Adds a DirectionalLight3D node matching the preview sun settings to the current scene.\nHold Shift while clicking to also add the preview environment to the current scene.")); + sun_add_to_scene->connect("pressed", callable_mp(this, &Node3DEditor::_add_sun_to_scene), varray(false)); sun_vb->add_spacer(); sun_vb->add_child(sun_add_to_scene); @@ -7243,7 +7271,8 @@ Node3DEditor::Node3DEditor(EditorNode *p_editor) { environ_add_to_scene = memnew(Button); environ_add_to_scene->set_text(TTR("Add Environment to Scene")); - environ_add_to_scene->connect("pressed", callable_mp(this, &Node3DEditor::_add_environment_to_scene)); + environ_add_to_scene->set_tooltip(TTR("Adds a WorldEnvironment node matching the preview environment settings to the current scene.\nHold Shift while clicking to also add the preview sun to the current scene.")); + environ_add_to_scene->connect("pressed", callable_mp(this, &Node3DEditor::_add_environment_to_scene), varray(false)); environ_vb->add_spacer(); environ_vb->add_child(environ_add_to_scene); @@ -7257,11 +7286,11 @@ Node3DEditor::Node3DEditor(EditorNode *p_editor) { preview_sun->set_shadow(true); preview_sun->set_shadow_mode(DirectionalLight3D::SHADOW_PARALLEL_4_SPLITS); preview_environment = memnew(WorldEnvironment); - environment.instance(); + environment.instantiate(); preview_environment->set_environment(environment); Ref<Sky> sky; - sky.instance(); - sky_material.instance(); + sky.instantiate(); + sky_material.instantiate(); sky->set_material(sky_material); environment->set_sky(sky); environment->set_background(Environment::BG_SKY); @@ -7392,17 +7421,17 @@ Node3DEditorPlugin::~Node3DEditorPlugin() { } void EditorNode3DGizmoPlugin::create_material(const String &p_name, const Color &p_color, bool p_billboard, bool p_on_top, bool p_use_vertex_color) { - Color instanced_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/instanced", Color(0.7, 0.7, 0.7, 0.6)); + Color instantiated_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/instantiated", Color(0.7, 0.7, 0.7, 0.6)); Vector<Ref<StandardMaterial3D>> mats; for (int i = 0; i < 4; i++) { bool selected = i % 2 == 1; - bool instanced = i < 2; + bool instantiated = i < 2; Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D)); - Color color = instanced ? instanced_color : p_color; + Color color = instantiated ? instantiated_color : p_color; if (!selected) { color.a *= 0.3; @@ -7434,17 +7463,17 @@ void EditorNode3DGizmoPlugin::create_material(const String &p_name, const Color } void EditorNode3DGizmoPlugin::create_icon_material(const String &p_name, const Ref<Texture2D> &p_texture, bool p_on_top, const Color &p_albedo) { - Color instanced_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/instanced", Color(0.7, 0.7, 0.7, 0.6)); + Color instantiated_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/instantiated", Color(0.7, 0.7, 0.7, 0.6)); Vector<Ref<StandardMaterial3D>> icons; for (int i = 0; i < 4; i++) { bool selected = i % 2 == 1; - bool instanced = i < 2; + bool instantiated = i < 2; Ref<StandardMaterial3D> icon = Ref<StandardMaterial3D>(memnew(StandardMaterial3D)); - Color color = instanced ? instanced_color : p_albedo; + Color color = instantiated ? instantiated_color : p_albedo; if (!selected) { color.a *= 0.85; @@ -7603,7 +7632,7 @@ Ref<EditorNode3DGizmo> EditorNode3DGizmoPlugin::create_gizmo(Node3D *p_spatial) Ref<EditorNode3DGizmo> ref; if (has_gizmo(p_spatial)) { - ref.instance(); + ref.instantiate(); } return ref; } diff --git a/editor/plugins/node_3d_editor_plugin.h b/editor/plugins/node_3d_editor_plugin.h index 6f03516409..a195a0eee0 100644 --- a/editor/plugins/node_3d_editor_plugin.h +++ b/editor/plugins/node_3d_editor_plugin.h @@ -34,7 +34,6 @@ #include "editor/editor_node.h" #include "editor/editor_plugin.h" #include "editor/editor_scale.h" -#include "scene/3d/immediate_geometry_3d.h" #include "scene/3d/light_3d.h" #include "scene/3d/visual_instance_3d.h" #include "scene/3d/world_environment.h" @@ -52,7 +51,7 @@ class EditorNode3DGizmo : public Node3DGizmo { GDCLASS(EditorNode3DGizmo, Node3DGizmo); bool selected; - bool instanced; + bool instantiated; public: void set_selected(bool p_selected) { selected = p_selected; } @@ -601,8 +600,6 @@ private: ToolMode tool_mode; - RenderingServer::ScenarioDebugMode scenario_debug; - RID origin; RID origin_instance; bool origin_enabled; @@ -808,8 +805,8 @@ private: void _preview_settings_changed(); void _sun_environ_settings_pressed(); - void _add_sun_to_scene(); - void _add_environment_to_scene(); + void _add_sun_to_scene(bool p_already_added_environment = false); + void _add_environment_to_scene(bool p_already_added_sun = false); protected: void _notification(int p_what); diff --git a/editor/plugins/occluder_instance_3d_editor_plugin.cpp b/editor/plugins/occluder_instance_3d_editor_plugin.cpp index 0821f140b3..b0cafd83be 100644 --- a/editor/plugins/occluder_instance_3d_editor_plugin.cpp +++ b/editor/plugins/occluder_instance_3d_editor_plugin.cpp @@ -56,7 +56,7 @@ void OccluderInstance3DEditorPlugin::_bake_select_file(const String &p_file) { } break; case OccluderInstance3D::BAKE_ERROR_NO_MESHES: { - EditorNode::get_singleton()->show_warning(TTR("No meshes to bake.")); + EditorNode::get_singleton()->show_warning(TTR("No meshes to bake.\nMake sure there is at least one MeshInstance3D node in the scene whose visual layers are part of the OccluderInstance3D's Bake Mask property.")); break; } default: { diff --git a/editor/plugins/ot_features_plugin.cpp b/editor/plugins/ot_features_plugin.cpp index ebfdf2c7cd..2ac90762e3 100644 --- a/editor/plugins/ot_features_plugin.cpp +++ b/editor/plugins/ot_features_plugin.cpp @@ -191,7 +191,7 @@ void EditorInspectorPluginOpenTypeFeatures::parse_begin(Object *p_object) { void EditorInspectorPluginOpenTypeFeatures::parse_category(Object *p_object, const String &p_parse_category) { } -bool EditorInspectorPluginOpenTypeFeatures::parse_property(Object *p_object, Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, int p_usage, bool p_wide) { +bool EditorInspectorPluginOpenTypeFeatures::parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const uint32_t p_usage, const bool p_wide) { if (p_path == "opentype_features/_new") { OpenTypeFeaturesAdd *editor = memnew(OpenTypeFeaturesAdd); add_property_editor(p_path, editor); @@ -208,6 +208,6 @@ bool EditorInspectorPluginOpenTypeFeatures::parse_property(Object *p_object, Var OpenTypeFeaturesEditorPlugin::OpenTypeFeaturesEditorPlugin(EditorNode *p_node) { Ref<EditorInspectorPluginOpenTypeFeatures> ftr_plugin; - ftr_plugin.instance(); + ftr_plugin.instantiate(); EditorInspector::add_inspector_plugin(ftr_plugin); } diff --git a/editor/plugins/ot_features_plugin.h b/editor/plugins/ot_features_plugin.h index 9559a6c0c3..dbafa3bbf6 100644 --- a/editor/plugins/ot_features_plugin.h +++ b/editor/plugins/ot_features_plugin.h @@ -88,7 +88,7 @@ public: virtual bool can_handle(Object *p_object) override; virtual void parse_begin(Object *p_object) override; virtual void parse_category(Object *p_object, const String &p_parse_category) override; - virtual bool parse_property(Object *p_object, Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, int p_usage, bool p_wide) override; + virtual bool parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const uint32_t p_usage, const bool p_wide = false) override; }; /*************************************************************************/ diff --git a/editor/plugins/path_3d_editor_plugin.cpp b/editor/plugins/path_3d_editor_plugin.cpp index b0eb13c3c6..82b51f8a06 100644 --- a/editor/plugins/path_3d_editor_plugin.cpp +++ b/editor/plugins/path_3d_editor_plugin.cpp @@ -554,7 +554,7 @@ Path3DEditorPlugin::Path3DEditorPlugin(EditorNode *p_node) { mirror_handle_length = true; Ref<Path3DGizmoPlugin> gizmo_plugin; - gizmo_plugin.instance(); + gizmo_plugin.instantiate(); Node3DEditor::get_singleton()->add_gizmo_plugin(gizmo_plugin); sep = memnew(VSeparator); diff --git a/editor/plugins/polygon_2d_editor_plugin.cpp b/editor/plugins/polygon_2d_editor_plugin.cpp index 8a14db0cfd..1a13a028c8 100644 --- a/editor/plugins/polygon_2d_editor_plugin.cpp +++ b/editor/plugins/polygon_2d_editor_plugin.cpp @@ -162,7 +162,7 @@ void Polygon2DEditor::_update_bone_list() { } Ref<ButtonGroup> bg; - bg.instance(); + bg.instantiate(); for (int i = 0; i < node->get_bone_count(); i++) { CheckBox *cb = memnew(CheckBox); NodePath np = node->get_bone_path(i); @@ -1231,7 +1231,7 @@ Polygon2DEditor::Polygon2DEditor(EditorNode *p_editor) : uv_edit->add_child(uv_main_vb); HBoxContainer *uv_mode_hb = memnew(HBoxContainer); - uv_edit_group.instance(); + uv_edit_group.instantiate(); uv_edit_mode[0] = memnew(Button); uv_mode_hb->add_child(uv_edit_mode[0]); diff --git a/editor/plugins/resource_preloader_editor_plugin.cpp b/editor/plugins/resource_preloader_editor_plugin.cpp index b8b2c6d343..488aa8c861 100644 --- a/editor/plugins/resource_preloader_editor_plugin.cpp +++ b/editor/plugins/resource_preloader_editor_plugin.cpp @@ -367,8 +367,10 @@ ResourcePreloaderEditor::ResourcePreloaderEditor() { tree = memnew(Tree); tree->connect("button_pressed", callable_mp(this, &ResourcePreloaderEditor::_cell_button_pressed)); tree->set_columns(2); - tree->set_column_min_width(0, 2); - tree->set_column_min_width(1, 3); + tree->set_column_expand_ratio(0, 2); + tree->set_column_clip_content(0, true); + tree->set_column_expand_ratio(1, 3); + tree->set_column_clip_content(1, true); tree->set_column_expand(0, true); tree->set_column_expand(1, true); tree->set_v_size_flags(SIZE_EXPAND_FILL); diff --git a/editor/plugins/root_motion_editor_plugin.cpp b/editor/plugins/root_motion_editor_plugin.cpp index 1e6237ced1..120b0bc0bb 100644 --- a/editor/plugins/root_motion_editor_plugin.cpp +++ b/editor/plugins/root_motion_editor_plugin.cpp @@ -278,7 +278,7 @@ void EditorInspectorRootMotionPlugin::parse_begin(Object *p_object) { //do none } -bool EditorInspectorRootMotionPlugin::parse_property(Object *p_object, Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, int p_usage, bool p_wide) { +bool EditorInspectorRootMotionPlugin::parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const uint32_t p_usage, const bool p_wide) { if (p_path == "root_motion_track" && p_object->is_class("AnimationTree") && p_type == Variant::NODE_PATH) { EditorPropertyRootMotion *editor = memnew(EditorPropertyRootMotion); if (p_hint == PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE && p_hint_text != String()) { diff --git a/editor/plugins/root_motion_editor_plugin.h b/editor/plugins/root_motion_editor_plugin.h index c70fff7db7..1484af62e8 100644 --- a/editor/plugins/root_motion_editor_plugin.h +++ b/editor/plugins/root_motion_editor_plugin.h @@ -65,7 +65,7 @@ class EditorInspectorRootMotionPlugin : public EditorInspectorPlugin { public: virtual bool can_handle(Object *p_object) override; virtual void parse_begin(Object *p_object) override; - virtual bool parse_property(Object *p_object, Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, int p_usage, bool p_wide = false) override; + virtual bool parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const uint32_t p_usage, const bool p_wide = false) override; virtual void parse_end() override; }; diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 0410ab3a45..498d5b0711 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -71,7 +71,7 @@ Array EditorSyntaxHighlighter::_get_supported_languages() const { Ref<EditorSyntaxHighlighter> EditorSyntaxHighlighter::_create() const { Ref<EditorSyntaxHighlighter> syntax_highlighter; - syntax_highlighter.instance(); + syntax_highlighter.instantiate(); if (get_script_instance()) { syntax_highlighter->set_script(get_script_instance()->get_script()); } @@ -201,7 +201,7 @@ void EditorStandardSyntaxHighlighter::_update_cache() { Ref<EditorSyntaxHighlighter> EditorStandardSyntaxHighlighter::_create() const { Ref<EditorStandardSyntaxHighlighter> syntax_highlighter; - syntax_highlighter.instance(); + syntax_highlighter.instantiate(); return syntax_highlighter; } @@ -209,7 +209,7 @@ Ref<EditorSyntaxHighlighter> EditorStandardSyntaxHighlighter::_create() const { Ref<EditorSyntaxHighlighter> EditorPlainTextSyntaxHighlighter::_create() const { Ref<EditorPlainTextSyntaxHighlighter> syntax_highlighter; - syntax_highlighter.instance(); + syntax_highlighter.instantiate(); return syntax_highlighter; } @@ -760,6 +760,7 @@ void ScriptEditor::_close_tab(int p_idx, bool p_save, bool p_history_back) { _update_members_overview_visibility(); _update_help_overview_visibility(); _save_layout(); + _update_find_replace_bar(); } void ScriptEditor::_close_current_tab(bool p_save) { @@ -829,6 +830,7 @@ void ScriptEditor::_close_all_tabs() { _close_current_tab(false); } + _update_find_replace_bar(); } void ScriptEditor::_ask_close_current_unsaved_tab(ScriptEditorBase *current) { @@ -1629,7 +1631,7 @@ void ScriptEditor::_help_overview_selected(int p_idx) { } void ScriptEditor::_script_selected(int p_idx) { - grab_focus_block = !Input::get_singleton()->is_mouse_button_pressed(1); //amazing hack, simply amazing + grab_focus_block = !Input::get_singleton()->is_mouse_button_pressed(MOUSE_BUTTON_LEFT); //amazing hack, simply amazing _go_to_tab(script_list->get_item_metadata(p_idx)); grab_focus_block = false; @@ -1640,15 +1642,13 @@ void ScriptEditor::ensure_select_current() { ScriptEditorBase *se = _get_current_editor(); if (se) { se->enable_editor(); - se->set_find_replace_bar(find_replace_bar); if (!grab_focus_block && is_visible_in_tree()) { se->ensure_focus(); } - } else { - find_replace_bar->hide(); } } + _update_find_replace_bar(); _update_selected_editor_menu(); } @@ -2520,6 +2520,16 @@ void ScriptEditor::_file_removed(const String &p_removed_file) { } } +void ScriptEditor::_update_find_replace_bar() { + ScriptEditorBase *se = _get_current_editor(); + if (se) { + se->set_find_replace_bar(find_replace_bar); + } else { + find_replace_bar->set_text_edit(nullptr); + find_replace_bar->hide(); + } +} + void ScriptEditor::_autosave_scripts() { save_all_scripts(); } @@ -2771,6 +2781,8 @@ void ScriptEditor::_script_list_gui_input(const Ref<InputEvent> &ev) { case MOUSE_BUTTON_RIGHT: { _make_script_list_context_menu(); } break; + default: + break; } } } diff --git a/editor/plugins/script_editor_plugin.h b/editor/plugins/script_editor_plugin.h index 1d379059d4..72a649ffbf 100644 --- a/editor/plugins/script_editor_plugin.h +++ b/editor/plugins/script_editor_plugin.h @@ -80,7 +80,7 @@ public: virtual Ref<EditorSyntaxHighlighter> _create() const override; - EditorStandardSyntaxHighlighter() { highlighter.instance(); } + EditorStandardSyntaxHighlighter() { highlighter.instantiate(); } }; class EditorPlainTextSyntaxHighlighter : public EditorSyntaxHighlighter { @@ -328,6 +328,7 @@ class ScriptEditor : public PanelContainer { void _show_error_dialog(String p_path); void _close_tab(int p_idx, bool p_save = true, bool p_history_back = true); + void _update_find_replace_bar(); void _close_current_tab(bool p_save = true); void _close_discard_current_tab(const String &p_str); diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index 3ec20ae68e..cc0fbcc634 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -109,13 +109,11 @@ ConnectionInfoDialog::ConnectionInfoDialog() { //////////////////////////////////////////////////////////////////////////////// Vector<String> ScriptTextEditor::get_functions() { - String errortxt; - int line = -1, col; CodeEdit *te = code_editor->get_text_editor(); String text = te->get_text(); List<String> fnc; - if (script->get_language()->validate(text, line, col, errortxt, script->get_path(), &fnc)) { + if (script->get_language()->validate(text, script->get_path(), &fnc)) { //if valid rewrite functions to latest functions.clear(); for (List<String>::Element *E = fnc.front(); E; E = E->next()) { @@ -168,7 +166,6 @@ void ScriptTextEditor::enable_editor() { void ScriptTextEditor::_load_theme_settings() { CodeEdit *text_edit = code_editor->get_text_editor(); - text_edit->clear_keywords(); Color updated_marked_line_color = EDITOR_GET("text_editor/highlighting/mark_color"); Color updated_safe_line_number_color = EDITOR_GET("text_editor/highlighting/safe_line_number_color"); @@ -222,47 +219,10 @@ void ScriptTextEditor::_set_theme_for_script() { String end = comment.get_slice_count(" ") > 1 ? comment.get_slice(" ", 1) : String(); text_edit->add_comment_delimiter(beg, end, end == ""); } +} - /* add keywords for auto completion */ - // singleton autoloads (as types, just as engine singletons are) - Map<StringName, ProjectSettings::AutoloadInfo> autoloads = ProjectSettings::get_singleton()->get_autoload_list(); - for (Map<StringName, ProjectSettings::AutoloadInfo>::Element *E = autoloads.front(); E; E = E->next()) { - const ProjectSettings::AutoloadInfo &info = E->value(); - if (info.is_singleton) { - text_edit->add_keyword(info.name); - } - } - - // engine types - List<StringName> types; - ClassDB::get_class_list(&types); - for (List<StringName>::Element *E = types.front(); E; E = E->next()) { - String n = E->get(); - if (n.begins_with("_")) { - n = n.substr(1, n.length()); - } - text_edit->add_keyword(n); - } - - // user types - List<StringName> global_classes; - ScriptServer::get_global_class_list(&global_classes); - for (List<StringName>::Element *E = global_classes.front(); E; E = E->next()) { - text_edit->add_keyword(E->get()); - } - - List<String> keywords; - script->get_language()->get_reserved_words(&keywords); - for (List<String>::Element *E = keywords.front(); E; E = E->next()) { - text_edit->add_keyword(E->get()); - } - - // core types - List<String> core_types; - script->get_language()->get_core_type_words(&core_types); - for (List<String>::Element *E = core_types.front(); E; E = E->next()) { - text_edit->add_keyword(E->get()); - } +void ScriptTextEditor::_show_errors_panel(bool p_show) { + errors_panel->set_visible(p_show); } void ScriptTextEditor::_show_warnings_panel(bool p_show) { @@ -279,6 +239,12 @@ void ScriptTextEditor::_warning_clicked(Variant p_line) { } } +void ScriptTextEditor::_error_clicked(Variant p_line) { + if (p_line.get_type() == Variant::INT) { + code_editor->get_text_editor()->cursor_set_line(p_line.operator int64_t()); + } +} + void ScriptTextEditor::reload_text() { ERR_FAIL_COND(script.is_null()); @@ -429,23 +395,21 @@ Ref<Texture2D> ScriptTextEditor::get_theme_icon() { } void ScriptTextEditor::_validate_script() { - String errortxt; - int line = -1, col; CodeEdit *te = code_editor->get_text_editor(); String text = te->get_text(); List<String> fnc; Set<int> safe_lines; List<ScriptLanguage::Warning> warnings; + List<ScriptLanguage::ScriptError> errors; - if (!script->get_language()->validate(text, line, col, errortxt, script->get_path(), &fnc, &warnings, &safe_lines)) { - String error_text = "error(" + itos(line) + "," + itos(col) + "): " + errortxt; + if (!script->get_language()->validate(text, script->get_path(), &fnc, &errors, &warnings, &safe_lines)) { + String error_text = TTR("Error at ") + "(" + itos(errors[0].line) + "," + itos(errors[0].column) + "): " + errors[0].message; code_editor->set_error(error_text); - code_editor->set_error_pos(line - 1, col - 1); + code_editor->set_error_pos(errors[0].line - 1, errors[0].column - 1); script_is_valid = false; } else { code_editor->set_error(""); - line = -1; if (!script->is_tool()) { script->set_source_code(text); script->update_exports(); @@ -487,7 +451,8 @@ void ScriptTextEditor::_validate_script() { } } - code_editor->set_warning_nb(warning_nb); + code_editor->set_error_count(errors.size()); + code_editor->set_warning_count(warning_nb); // Add script warnings. warnings_panel->push_table(3); @@ -521,23 +486,52 @@ void ScriptTextEditor::_validate_script() { } warnings_panel->pop(); // Table. - line--; + errors_panel->clear(); + errors_panel->push_table(2); + for (List<ScriptLanguage::ScriptError>::Element *E = errors.front(); E; E = E->next()) { + ScriptLanguage::ScriptError err = E->get(); + + errors_panel->push_cell(); + errors_panel->push_meta(err.line - 1); + errors_panel->push_color(warnings_panel->get_theme_color("error_color", "Editor")); + errors_panel->add_text(TTR("Line") + " " + itos(err.line) + ":"); + errors_panel->pop(); // Color. + errors_panel->pop(); // Meta goto. + errors_panel->pop(); // Cell. + + errors_panel->push_cell(); + errors_panel->add_text(err.message); + errors_panel->pop(); // Cell. + } + errors_panel->pop(); // Table + bool highlight_safe = EDITOR_DEF("text_editor/highlighting/highlight_type_safe_lines", true); bool last_is_safe = false; for (int i = 0; i < te->get_line_count(); i++) { - te->set_line_background_color(i, (line == i) ? marked_line_color : Color(0, 0, 0, 0)); + if (errors.is_empty()) { + te->set_line_background_color(i, Color(0, 0, 0, 0)); + } else { + for (List<ScriptLanguage::ScriptError>::Element *E = errors.front(); E; E = E->next()) { + bool error_line = i == E->get().line - 1; + te->set_line_background_color(i, error_line ? marked_line_color : Color(0, 0, 0, 0)); + if (error_line) { + break; + } + } + } + if (highlight_safe) { if (safe_lines.has(i + 1)) { te->set_line_gutter_item_color(i, line_number_gutter, safe_line_number_color); last_is_safe = true; - } else if (last_is_safe && (te->is_line_comment(i) || te->get_line(i).strip_edges().is_empty())) { + } else if (last_is_safe && (te->is_in_comment(i) != -1 || te->get_line(i).strip_edges().is_empty())) { te->set_line_gutter_item_color(i, line_number_gutter, safe_line_number_color); } else { te->set_line_gutter_item_color(i, line_number_gutter, default_line_number_color); last_is_safe = false; } } else { - te->set_line_gutter_item_color(line, 1, default_line_number_color); + te->set_line_gutter_item_color(i, 1, default_line_number_color); } } @@ -1044,7 +1038,7 @@ void ScriptTextEditor::_edit_option(int p_op) { return; } - tx->indent_selected_lines_left(); + tx->unindent_lines(); } break; case EDIT_INDENT_RIGHT: { Ref<Script> scr = script; @@ -1052,13 +1046,13 @@ void ScriptTextEditor::_edit_option(int p_op) { return; } - tx->indent_selected_lines_right(); + tx->indent_lines(); } break; case EDIT_DELETE_LINE: { code_editor->delete_lines(); } break; - case EDIT_CLONE_DOWN: { - code_editor->clone_lines_down(); + case EDIT_DUPLICATE_SELECTION: { + code_editor->duplicate_selection(); } break; case EDIT_TOGGLE_FOLD_LINE: { tx->toggle_foldable_line(tx->cursor_get_line()); @@ -1450,6 +1444,7 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data } if (d.has("type") && (String(d["type"]) == "files" || String(d["type"]) == "files_and_dirs")) { + const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", false) ? "'" : "\""; Array files = d["files"]; String text_to_drop; @@ -1460,9 +1455,9 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data } if (preload) { - text_to_drop += "preload(\"" + String(files[i]).c_escape() + "\")"; + text_to_drop += "preload(" + String(files[i]).c_escape().quote(quote_style) + ")"; } else { - text_to_drop += "\"" + String(files[i]).c_escape() + "\""; + text_to_drop += String(files[i]).c_escape().quote(quote_style); } } @@ -1675,6 +1670,7 @@ void ScriptTextEditor::_enable_code_editor() { editor_box->set_v_size_flags(SIZE_EXPAND_FILL); editor_box->add_child(code_editor); + code_editor->connect("show_errors_panel", callable_mp(this, &ScriptTextEditor::_show_errors_panel)); code_editor->connect("show_warnings_panel", callable_mp(this, &ScriptTextEditor::_show_warnings_panel)); code_editor->connect("validate_script", callable_mp(this, &ScriptTextEditor::_validate_script)); code_editor->connect("load_theme_settings", callable_mp(this, &ScriptTextEditor::_load_theme_settings)); @@ -1695,6 +1691,13 @@ void ScriptTextEditor::_enable_code_editor() { "normal_font_size", EditorNode::get_singleton()->get_gui_base()->get_theme_font_size("main_size", "EditorFonts")); warnings_panel->connect("meta_clicked", callable_mp(this, &ScriptTextEditor::_warning_clicked)); + editor_box->add_child(errors_panel); + errors_panel->add_theme_font_override( + "normal_font", EditorNode::get_singleton()->get_gui_base()->get_theme_font("main", "EditorFonts")); + errors_panel->add_theme_font_size_override( + "normal_font_size", EditorNode::get_singleton()->get_gui_base()->get_theme_font_size("main_size", "EditorFonts")); + errors_panel->connect("meta_clicked", callable_mp(this, &ScriptTextEditor::_error_clicked)); + add_child(context_menu); context_menu->connect("id_pressed", callable_mp(this, &ScriptTextEditor::_edit_option)); @@ -1757,7 +1760,7 @@ void ScriptTextEditor::_enable_code_editor() { edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/fold_all_lines"), EDIT_FOLD_ALL_LINES); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/unfold_all_lines"), EDIT_UNFOLD_ALL_LINES); edit_menu->get_popup()->add_separator(); - edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/clone_down"), EDIT_CLONE_DOWN); + edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/duplicate_selection"), EDIT_DUPLICATE_SELECTION); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_text_completion_query"), EDIT_COMPLETE); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/evaluate_selection"), EDIT_EVALUATE); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/trim_trailing_whitespace"), EDIT_TRIM_TRAILING_WHITESAPCE); @@ -1826,6 +1829,14 @@ ScriptTextEditor::ScriptTextEditor() { warnings_panel->set_focus_mode(FOCUS_CLICK); warnings_panel->hide(); + errors_panel = memnew(RichTextLabel); + errors_panel->set_custom_minimum_size(Size2(0, 100 * EDSCALE)); + errors_panel->set_h_size_flags(SIZE_EXPAND_FILL); + errors_panel->set_meta_underline(true); + errors_panel->set_selection_enabled(true); + errors_panel->set_focus_mode(FOCUS_CLICK); + errors_panel->hide(); + update_settings(); code_editor->get_text_editor()->set_code_hint_draw_below(EditorSettings::get_singleton()->get("text_editor/completion/put_callhint_tooltip_below_current_line")); @@ -1851,11 +1862,11 @@ ScriptTextEditor::ScriptTextEditor() { highlighter_menu->set_name("highlighter_menu"); Ref<EditorPlainTextSyntaxHighlighter> plain_highlighter; - plain_highlighter.instance(); + plain_highlighter.instantiate(); add_syntax_highlighter(plain_highlighter); Ref<EditorStandardSyntaxHighlighter> highlighter; - highlighter.instance(); + highlighter.instantiate(); add_syntax_highlighter(highlighter); set_syntax_highlighter(highlighter); @@ -1886,6 +1897,7 @@ ScriptTextEditor::~ScriptTextEditor() { if (!editor_enabled) { memdelete(code_editor); memdelete(warnings_panel); + memdelete(errors_panel); memdelete(context_menu); memdelete(color_panel); memdelete(edit_hb); @@ -1922,9 +1934,9 @@ void ScriptTextEditor::register_editor() { ED_SHORTCUT("script_text_editor/fold_all_lines", TTR("Fold All Lines"), 0); ED_SHORTCUT("script_text_editor/unfold_all_lines", TTR("Unfold All Lines"), 0); #ifdef OSX_ENABLED - ED_SHORTCUT("script_text_editor/clone_down", TTR("Clone Down"), KEY_MASK_SHIFT | KEY_MASK_CMD | KEY_C); + ED_SHORTCUT("script_text_editor/duplicate_selection", TTR("Duplicate Selection"), KEY_MASK_SHIFT | KEY_MASK_CMD | KEY_C); #else - ED_SHORTCUT("script_text_editor/clone_down", TTR("Clone Down"), KEY_MASK_SHIFT | KEY_MASK_CMD | KEY_D); + ED_SHORTCUT("script_text_editor/duplicate_selection", TTR("Duplicate Selection"), KEY_MASK_SHIFT | KEY_MASK_CMD | KEY_D); #endif ED_SHORTCUT("script_text_editor/evaluate_selection", TTR("Evaluate Selection"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_E); ED_SHORTCUT("script_text_editor/trim_trailing_whitespace", TTR("Trim Trailing Whitespace"), KEY_MASK_CMD | KEY_MASK_ALT | KEY_T); diff --git a/editor/plugins/script_text_editor.h b/editor/plugins/script_text_editor.h index 7bb961bf19..e4a13951e4 100644 --- a/editor/plugins/script_text_editor.h +++ b/editor/plugins/script_text_editor.h @@ -55,6 +55,7 @@ class ScriptTextEditor : public ScriptEditorBase { CodeTextEditor *code_editor = nullptr; RichTextLabel *warnings_panel = nullptr; + RichTextLabel *errors_panel = nullptr; Ref<Script> script; bool script_is_valid = false; @@ -116,7 +117,7 @@ class ScriptTextEditor : public ScriptEditorBase { EDIT_INDENT_RIGHT, EDIT_INDENT_LEFT, EDIT_DELETE_LINE, - EDIT_CLONE_DOWN, + EDIT_DUPLICATE_SELECTION, EDIT_PICK_COLOR, EDIT_TO_UPPERCASE, EDIT_TO_LOWERCASE, @@ -161,7 +162,9 @@ protected: void _load_theme_settings(); void _set_theme_for_script(); + void _show_errors_panel(bool p_show); void _show_warnings_panel(bool p_show); + void _error_clicked(Variant p_line); void _warning_clicked(Variant p_line); void _notification(int p_what); diff --git a/editor/plugins/shader_editor_plugin.cpp b/editor/plugins/shader_editor_plugin.cpp index e4a5a3796e..c1216a9732 100644 --- a/editor/plugins/shader_editor_plugin.cpp +++ b/editor/plugins/shader_editor_plugin.cpp @@ -240,7 +240,7 @@ void ShaderTextEditor::_validate_script() { warnings.sort_custom<WarningsComparator>(); _update_warning_panel(); } else { - set_warning_nb(0); + set_warning_count(0); } emit_signal("script_changed"); } @@ -280,14 +280,14 @@ void ShaderTextEditor::_update_warning_panel() { } warnings_panel->pop(); // Table. - set_warning_nb(warning_count); + set_warning_count(warning_count); } void ShaderTextEditor::_bind_methods() { } ShaderTextEditor::ShaderTextEditor() { - syntax_highlighter.instance(); + syntax_highlighter.instantiate(); get_text_editor()->set_syntax_highlighter(syntax_highlighter); } @@ -323,25 +323,19 @@ void ShaderEditor::_menu_option(int p_option) { if (shader.is_null()) { return; } - - CodeEdit *tx = shader_editor->get_text_editor(); - tx->indent_selected_lines_left(); - + shader_editor->get_text_editor()->unindent_lines(); } break; case EDIT_INDENT_RIGHT: { if (shader.is_null()) { return; } - - CodeEdit *tx = shader_editor->get_text_editor(); - tx->indent_selected_lines_right(); - + shader_editor->get_text_editor()->indent_lines(); } break; case EDIT_DELETE_LINE: { shader_editor->delete_lines(); } break; - case EDIT_CLONE_DOWN: { - shader_editor->clone_lines_down(); + case EDIT_DUPLICATE_SELECTION: { + shader_editor->duplicate_selection(); } break; case EDIT_TOGGLE_COMMENT: { if (shader.is_null()) { @@ -698,7 +692,7 @@ ShaderEditor::ShaderEditor(EditorNode *p_node) { edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_right"), EDIT_INDENT_RIGHT); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/delete_line"), EDIT_DELETE_LINE); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_comment"), EDIT_TOGGLE_COMMENT); - edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/clone_down"), EDIT_CLONE_DOWN); + edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/duplicate_selection"), EDIT_DUPLICATE_SELECTION); edit_menu->get_popup()->add_separator(); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_text_completion_query"), EDIT_COMPLETE); edit_menu->get_popup()->connect("id_pressed", callable_mp(this, &ShaderEditor::_menu_option)); diff --git a/editor/plugins/shader_editor_plugin.h b/editor/plugins/shader_editor_plugin.h index d7da73f2ae..77579754d3 100644 --- a/editor/plugins/shader_editor_plugin.h +++ b/editor/plugins/shader_editor_plugin.h @@ -91,7 +91,7 @@ class ShaderEditor : public PanelContainer { EDIT_INDENT_LEFT, EDIT_INDENT_RIGHT, EDIT_DELETE_LINE, - EDIT_CLONE_DOWN, + EDIT_DUPLICATE_SELECTION, EDIT_TOGGLE_COMMENT, EDIT_COMPLETE, SEARCH_FIND, diff --git a/editor/plugins/shader_file_editor_plugin.cpp b/editor/plugins/shader_file_editor_plugin.cpp index 47d7f8204b..85ccc5b798 100644 --- a/editor/plugins/shader_file_editor_plugin.cpp +++ b/editor/plugins/shader_file_editor_plugin.cpp @@ -272,7 +272,7 @@ ShaderFileEditor::ShaderFileEditor(EditorNode *p_node) { main_vb->add_child(stage_hb); Ref<ButtonGroup> bg; - bg.instance(); + bg.instantiate(); for (int i = 0; i < RD::SHADER_STAGE_MAX; i++) { Button *button = memnew(Button(stage_str[i])); button->set_toggle_mode(true); diff --git a/editor/plugins/skeleton_3d_editor_plugin.cpp b/editor/plugins/skeleton_3d_editor_plugin.cpp index a97584ebce..0b04c2e50e 100644 --- a/editor/plugins/skeleton_3d_editor_plugin.cpp +++ b/editor/plugins/skeleton_3d_editor_plugin.cpp @@ -700,7 +700,7 @@ Skeleton3DEditorPlugin::Skeleton3DEditorPlugin(EditorNode *p_node) { editor = p_node; Ref<EditorInspectorPluginSkeleton> skeleton_plugin; - skeleton_plugin.instance(); + skeleton_plugin.instantiate(); skeleton_plugin->editor = editor; EditorInspector::add_inspector_plugin(skeleton_plugin); diff --git a/editor/plugins/sprite_2d_editor_plugin.cpp b/editor/plugins/sprite_2d_editor_plugin.cpp index 4a7f6c0f7e..ef328bcfe2 100644 --- a/editor/plugins/sprite_2d_editor_plugin.cpp +++ b/editor/plugins/sprite_2d_editor_plugin.cpp @@ -186,7 +186,7 @@ void Sprite2DEditor::_update_mesh_data() { } Ref<BitMap> bm; - bm.instance(); + bm.instantiate(); bm->create_from_image_alpha(image); int shrink = shrink_pixels->get_value(); @@ -322,7 +322,7 @@ void Sprite2DEditor::_convert_to_mesh_2d_node() { } Ref<ArrayMesh> mesh; - mesh.instance(); + mesh.instantiate(); Array a; a.resize(Mesh::ARRAY_MAX); @@ -435,7 +435,7 @@ void Sprite2DEditor::_create_light_occluder_2d_node() { Vector<Vector2> outline = computed_outline_lines[i]; Ref<OccluderPolygon2D> polygon; - polygon.instance(); + polygon.instantiate(); PackedVector2Array a; a.resize(outline.size()); diff --git a/editor/plugins/sprite_frames_editor_plugin.cpp b/editor/plugins/sprite_frames_editor_plugin.cpp index af72f59c1c..70c7b3072b 100644 --- a/editor/plugins/sprite_frames_editor_plugin.cpp +++ b/editor/plugins/sprite_frames_editor_plugin.cpp @@ -227,7 +227,7 @@ void SpriteFramesEditor::_sheet_add_frames() { int y = (yp * height) + region_rect.position.y; Ref<AtlasTexture> at; - at.instance(); + at.instantiate(); at->set_atlas(split_sheet_preview->get_texture()); at->set_region(Rect2(x, y, width, height)); diff --git a/editor/plugins/style_box_editor_plugin.cpp b/editor/plugins/style_box_editor_plugin.cpp index 64df982d5d..91c5e96f08 100644 --- a/editor/plugins/style_box_editor_plugin.cpp +++ b/editor/plugins/style_box_editor_plugin.cpp @@ -44,7 +44,7 @@ void EditorInspectorPluginStyleBox::parse_begin(Object *p_object) { add_custom_control(preview); } -bool EditorInspectorPluginStyleBox::parse_property(Object *p_object, Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, int p_usage, bool p_wide) { +bool EditorInspectorPluginStyleBox::parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, const uint32_t p_usage, bool p_wide) { return false; //do not want } @@ -93,6 +93,6 @@ StyleBoxPreview::StyleBoxPreview() { StyleBoxEditorPlugin::StyleBoxEditorPlugin(EditorNode *p_node) { Ref<EditorInspectorPluginStyleBox> inspector_plugin; - inspector_plugin.instance(); + inspector_plugin.instantiate(); add_inspector_plugin(inspector_plugin); } diff --git a/editor/plugins/style_box_editor_plugin.h b/editor/plugins/style_box_editor_plugin.h index d4a235cd10..8ca348bd80 100644 --- a/editor/plugins/style_box_editor_plugin.h +++ b/editor/plugins/style_box_editor_plugin.h @@ -61,7 +61,7 @@ class EditorInspectorPluginStyleBox : public EditorInspectorPlugin { public: virtual bool can_handle(Object *p_object) override; virtual void parse_begin(Object *p_object) override; - virtual bool parse_property(Object *p_object, Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, int p_usage, bool p_wide = false) override; + virtual bool parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const uint32_t p_usage, const bool p_wide = false) override; virtual void parse_end() override; }; diff --git a/editor/plugins/text_editor.cpp b/editor/plugins/text_editor.cpp index 621f843e6f..5766646f7d 100644 --- a/editor/plugins/text_editor.cpp +++ b/editor/plugins/text_editor.cpp @@ -320,16 +320,16 @@ void TextEditor::_edit_option(int p_op) { code_editor->move_lines_down(); } break; case EDIT_INDENT_LEFT: { - tx->indent_selected_lines_left(); + tx->unindent_lines(); } break; case EDIT_INDENT_RIGHT: { - tx->indent_selected_lines_right(); + tx->indent_lines(); } break; case EDIT_DELETE_LINE: { code_editor->delete_lines(); } break; - case EDIT_CLONE_DOWN: { - code_editor->clone_lines_down(); + case EDIT_DUPLICATE_SELECTION: { + code_editor->duplicate_selection(); } break; case EDIT_TOGGLE_FOLD_LINE: { tx->toggle_foldable_line(tx->cursor_get_line()); @@ -559,7 +559,7 @@ TextEditor::TextEditor() { edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/fold_all_lines"), EDIT_FOLD_ALL_LINES); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/unfold_all_lines"), EDIT_UNFOLD_ALL_LINES); edit_menu->get_popup()->add_separator(); - edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/clone_down"), EDIT_CLONE_DOWN); + edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/duplicate_selection"), EDIT_DUPLICATE_SELECTION); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/trim_trailing_whitespace"), EDIT_TRIM_TRAILING_WHITESAPCE); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_indent_to_spaces"), EDIT_CONVERT_INDENT_TO_SPACES); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_indent_to_tabs"), EDIT_CONVERT_INDENT_TO_TABS); @@ -581,11 +581,11 @@ TextEditor::TextEditor() { highlighter_menu->connect("id_pressed", callable_mp(this, &TextEditor::_change_syntax_highlighter)); Ref<EditorPlainTextSyntaxHighlighter> plain_highlighter; - plain_highlighter.instance(); + plain_highlighter.instantiate(); add_syntax_highlighter(plain_highlighter); Ref<EditorStandardSyntaxHighlighter> highlighter; - highlighter.instance(); + highlighter.instantiate(); add_syntax_highlighter(highlighter); set_syntax_highlighter(plain_highlighter); diff --git a/editor/plugins/text_editor.h b/editor/plugins/text_editor.h index 4e667dc676..86a4910ac0 100644 --- a/editor/plugins/text_editor.h +++ b/editor/plugins/text_editor.h @@ -66,7 +66,7 @@ private: EDIT_INDENT_RIGHT, EDIT_INDENT_LEFT, EDIT_DELETE_LINE, - EDIT_CLONE_DOWN, + EDIT_DUPLICATE_SELECTION, EDIT_TO_UPPERCASE, EDIT_TO_LOWERCASE, EDIT_CAPITALIZE, diff --git a/editor/plugins/texture_3d_editor_plugin.cpp b/editor/plugins/texture_3d_editor_plugin.cpp index 36297c8a4a..696aa88e23 100644 --- a/editor/plugins/texture_3d_editor_plugin.cpp +++ b/editor/plugins/texture_3d_editor_plugin.cpp @@ -85,9 +85,9 @@ void Texture3DEditor::_make_shaders() { " COLOR = textureLod(tex,vec3(UV,layer),0.0);\n" "}"; - shader.instance(); + shader.instantiate(); shader->set_code(shader_3d); - material.instance(); + material.instantiate(); material->set_shader(shader); } @@ -207,6 +207,6 @@ void EditorInspectorPlugin3DTexture::parse_begin(Object *p_object) { Texture3DEditorPlugin::Texture3DEditorPlugin(EditorNode *p_node) { Ref<EditorInspectorPlugin3DTexture> plugin; - plugin.instance(); + plugin.instantiate(); add_inspector_plugin(plugin); } diff --git a/editor/plugins/texture_editor_plugin.cpp b/editor/plugins/texture_editor_plugin.cpp index ecf7370834..10b942d9ee 100644 --- a/editor/plugins/texture_editor_plugin.cpp +++ b/editor/plugins/texture_editor_plugin.cpp @@ -160,6 +160,6 @@ void EditorInspectorPluginTexture::parse_begin(Object *p_object) { TextureEditorPlugin::TextureEditorPlugin(EditorNode *p_node) { Ref<EditorInspectorPluginTexture> plugin; - plugin.instance(); + plugin.instantiate(); add_inspector_plugin(plugin); } diff --git a/editor/plugins/texture_layered_editor_plugin.cpp b/editor/plugins/texture_layered_editor_plugin.cpp index 89ed98d53e..3f46cd64a2 100644 --- a/editor/plugins/texture_layered_editor_plugin.cpp +++ b/editor/plugins/texture_layered_editor_plugin.cpp @@ -112,7 +112,7 @@ void TextureLayeredEditor::_make_shaders() { " COLOR = textureLod(tex,vec3(UV,layer),0.0);\n" "}"; - shaders[0].instance(); + shaders[0].instantiate(); shaders[0]->set_code(shader_2d_array); String shader_cube = "" @@ -125,7 +125,7 @@ void TextureLayeredEditor::_make_shaders() { " COLOR = textureLod(tex,n,0.0);\n" "}"; - shaders[1].instance(); + shaders[1].instantiate(); shaders[1]->set_code(shader_cube); String shader_cube_array = "" @@ -139,11 +139,11 @@ void TextureLayeredEditor::_make_shaders() { " COLOR = textureLod(tex,vec4(n,layer),0.0);\n" "}"; - shaders[2].instance(); + shaders[2].instantiate(); shaders[2]->set_code(shader_cube_array); for (int i = 0; i < 3; i++) { - materials[i].instance(); + materials[i].instantiate(); materials[i]->set_shader(shaders[i]); } } @@ -271,6 +271,6 @@ void EditorInspectorPluginLayeredTexture::parse_begin(Object *p_object) { TextureLayeredEditorPlugin::TextureLayeredEditorPlugin(EditorNode *p_node) { Ref<EditorInspectorPluginLayeredTexture> plugin; - plugin.instance(); + plugin.instantiate(); add_inspector_plugin(plugin); } diff --git a/editor/plugins/theme_editor_plugin.cpp b/editor/plugins/theme_editor_plugin.cpp index 22b39c59f5..be1aeb309f 100644 --- a/editor/plugins/theme_editor_plugin.cpp +++ b/editor/plugins/theme_editor_plugin.cpp @@ -930,11 +930,14 @@ ThemeItemImportTree::ThemeItemImportTree() { import_items_tree->set_column_title(IMPORT_ITEM, TTR("Import")); import_items_tree->set_column_title(IMPORT_ITEM_DATA, TTR("With Data")); import_items_tree->set_column_expand(0, true); + import_items_tree->set_column_clip_content(0, true); import_items_tree->set_column_expand(IMPORT_ITEM, false); import_items_tree->set_column_expand(IMPORT_ITEM_DATA, false); - import_items_tree->set_column_min_width(0, 160 * EDSCALE); - import_items_tree->set_column_min_width(IMPORT_ITEM, 80 * EDSCALE); - import_items_tree->set_column_min_width(IMPORT_ITEM_DATA, 80 * EDSCALE); + import_items_tree->set_column_custom_minimum_width(0, 160 * EDSCALE); + import_items_tree->set_column_custom_minimum_width(IMPORT_ITEM, 80 * EDSCALE); + import_items_tree->set_column_custom_minimum_width(IMPORT_ITEM_DATA, 80 * EDSCALE); + import_items_tree->set_column_clip_content(1, true); + import_items_tree->set_column_clip_content(2, true); ScrollContainer *import_bulk_sc = memnew(ScrollContainer); import_bulk_sc->set_custom_minimum_size(Size2(260.0, 0.0) * EDSCALE); @@ -2263,7 +2266,7 @@ void ThemeTypeEditor::_update_type_items() { } else { item_editor->set_edited_resource(RES()); } - item_editor->connect("resource_selected", callable_mp(this, &ThemeTypeEditor::_edit_resource_item), varray(item_control)); + item_editor->connect("resource_selected", callable_mp(this, &ThemeTypeEditor::_edit_resource_item)); item_editor->connect("resource_changed", callable_mp(this, &ThemeTypeEditor::_font_item_changed), varray(E.key())); } else { if (Theme::get_default()->has_font(E.key(), edited_type)) { @@ -2334,7 +2337,7 @@ void ThemeTypeEditor::_update_type_items() { } else { item_editor->set_edited_resource(RES()); } - item_editor->connect("resource_selected", callable_mp(this, &ThemeTypeEditor::_edit_resource_item), varray(item_control)); + item_editor->connect("resource_selected", callable_mp(this, &ThemeTypeEditor::_edit_resource_item)); item_editor->connect("resource_changed", callable_mp(this, &ThemeTypeEditor::_icon_item_changed), varray(E.key())); } else { if (Theme::get_default()->has_icon(E.key(), edited_type)) { @@ -2381,7 +2384,7 @@ void ThemeTypeEditor::_update_type_items() { } else { item_editor->set_edited_resource(RES()); } - item_editor->connect("resource_selected", callable_mp(this, &ThemeTypeEditor::_edit_resource_item), varray(item_control)); + item_editor->connect("resource_selected", callable_mp(this, &ThemeTypeEditor::_edit_resource_item)); item_editor->connect("resource_changed", callable_mp(this, &ThemeTypeEditor::_stylebox_item_changed), varray(leading_stylebox.item_name)); stylebox_items_list->add_child(item_control); @@ -2408,7 +2411,7 @@ void ThemeTypeEditor::_update_type_items() { } else { item_editor->set_edited_resource(RES()); } - item_editor->connect("resource_selected", callable_mp(this, &ThemeTypeEditor::_edit_resource_item), varray(item_control)); + item_editor->connect("resource_selected", callable_mp(this, &ThemeTypeEditor::_edit_resource_item)); item_editor->connect("resource_changed", callable_mp(this, &ThemeTypeEditor::_stylebox_item_changed), varray(E.key())); Button *pin_leader_button = memnew(Button); @@ -2417,7 +2420,7 @@ void ThemeTypeEditor::_update_type_items() { pin_leader_button->set_icon(get_theme_icon("Pin", "EditorIcons")); pin_leader_button->set_tooltip(TTR("Pin this StyleBox as a main style. Editing its properties will update the same properties in all other StyleBoxes of this type.")); item_control->add_child(pin_leader_button); - pin_leader_button->connect("pressed", callable_mp(this, &ThemeTypeEditor::_pin_leading_stylebox), varray(stylebox_value, E.key())); + pin_leader_button->connect("pressed", callable_mp(this, &ThemeTypeEditor::_pin_leading_stylebox), varray(item_editor, E.key())); } else { if (Theme::get_default()->has_stylebox(E.key(), edited_type)) { item_editor->set_edited_resource(Theme::get_default()->get_stylebox(E.key(), edited_type)); @@ -2612,6 +2615,10 @@ void ThemeTypeEditor::_item_remove_cbk(int p_data_type, String p_item_name) { } break; case Theme::DATA_TYPE_STYLEBOX: { edited_theme->clear_stylebox(p_item_name, edited_type); + + if (leading_stylebox.pinned && leading_stylebox.item_name == p_item_name) { + _unpin_leading_stylebox(); + } } break; } } @@ -2661,6 +2668,10 @@ void ThemeTypeEditor::_item_rename_confirmed(int p_data_type, String p_item_name } break; case Theme::DATA_TYPE_STYLEBOX: { edited_theme->rename_stylebox(p_item_name, new_name, edited_type); + + if (leading_stylebox.pinned && leading_stylebox.item_name == p_item_name) { + leading_stylebox.item_name = new_name; + } } break; } } @@ -2695,7 +2706,7 @@ void ThemeTypeEditor::_font_size_item_changed(float p_value, String p_item_name) edited_theme->set_font_size(p_item_name, edited_type, int(p_value)); } -void ThemeTypeEditor::_edit_resource_item(RES p_resource, Control *p_editor) { +void ThemeTypeEditor::_edit_resource_item(RES p_resource) { EditorNode::get_singleton()->edit_resource(p_resource); } @@ -2723,16 +2734,21 @@ void ThemeTypeEditor::_stylebox_item_changed(Ref<StyleBox> p_value, String p_ite } } -void ThemeTypeEditor::_pin_leading_stylebox(Ref<StyleBox> p_stylebox, String p_item_name) { +void ThemeTypeEditor::_pin_leading_stylebox(Control *p_editor, String p_item_name) { if (leading_stylebox.stylebox.is_valid()) { leading_stylebox.stylebox->disconnect("changed", callable_mp(this, &ThemeTypeEditor::_update_stylebox_from_leading)); } + Ref<StyleBox> stylebox; + if (Object::cast_to<EditorResourcePicker>(p_editor)) { + stylebox = Object::cast_to<EditorResourcePicker>(p_editor)->get_edited_resource(); + } + LeadingStylebox leader; leader.pinned = true; leader.item_name = p_item_name; - leader.stylebox = p_stylebox; - leader.ref_stylebox = (p_stylebox.is_valid() ? p_stylebox->duplicate() : RES()); + leader.stylebox = stylebox; + leader.ref_stylebox = (stylebox.is_valid() ? stylebox->duplicate() : RES()); leading_stylebox = leader; if (leading_stylebox.stylebox.is_valid()) { diff --git a/editor/plugins/theme_editor_plugin.h b/editor/plugins/theme_editor_plugin.h index 77baf46395..cdedbbec8d 100644 --- a/editor/plugins/theme_editor_plugin.h +++ b/editor/plugins/theme_editor_plugin.h @@ -329,11 +329,11 @@ class ThemeTypeEditor : public MarginContainer { void _color_item_changed(Color p_value, String p_item_name); void _constant_item_changed(float p_value, String p_item_name); void _font_size_item_changed(float p_value, String p_item_name); - void _edit_resource_item(RES p_resource, Control *p_editor); + void _edit_resource_item(RES p_resource); void _font_item_changed(Ref<Font> p_value, String p_item_name); void _icon_item_changed(Ref<Texture2D> p_value, String p_item_name); void _stylebox_item_changed(Ref<StyleBox> p_value, String p_item_name); - void _pin_leading_stylebox(Ref<StyleBox> p_stylebox, String p_item_name); + void _pin_leading_stylebox(Control *p_editor, String p_item_name); void _unpin_leading_stylebox(); void _update_stylebox_from_leading(); diff --git a/editor/plugins/theme_editor_preview.cpp b/editor/plugins/theme_editor_preview.cpp index cb7b5949d1..0b02150444 100644 --- a/editor/plugins/theme_editor_preview.cpp +++ b/editor/plugins/theme_editor_preview.cpp @@ -403,7 +403,7 @@ void SceneThemeEditorPreview::_reload_scene() { preview_content->remove_child(node); } - Node *instance = loaded_scene->instance(); + Node *instance = loaded_scene->instantiate(); if (!instance || !Object::cast_to<Control>(instance)) { EditorNode::get_singleton()->show_warning(TTR("Invalid PackedScene resource, must have a Control node at its root.")); emit_signal("scene_invalidated"); @@ -435,7 +435,7 @@ bool SceneThemeEditorPreview::set_preview_scene(const String &p_path) { return false; } - Node *instance = loaded_scene->instance(); + Node *instance = loaded_scene->instantiate(); if (!instance || !Object::cast_to<Control>(instance)) { EditorNode::get_singleton()->show_warning(TTR("Invalid PackedScene resource, must have a Control node at its root.")); return false; diff --git a/editor/plugins/tiles/tile_atlas_view.cpp b/editor/plugins/tiles/tile_atlas_view.cpp index 78f181e321..374a255df3 100644 --- a/editor/plugins/tiles/tile_atlas_view.cpp +++ b/editor/plugins/tiles/tile_atlas_view.cpp @@ -33,7 +33,6 @@ #include "core/input/input.h" #include "core/os/keyboard.h" #include "scene/gui/box_container.h" -#include "scene/gui/center_container.h" #include "scene/gui/label.h" #include "scene/gui/panel.h" #include "scene/gui/texture_rect.h" @@ -44,21 +43,41 @@ void TileAtlasView::_gui_input(const Ref<InputEvent> &p_event) { bool ctrl = Input::get_singleton()->is_key_pressed(KEY_CTRL); - Ref<InputEventMouseButton> b = p_event; - if (b.is_valid()) { - if (ctrl && b->is_pressed() && b->get_button_index() == MOUSE_BUTTON_WHEEL_DOWN) { + Ref<InputEventMouseButton> mb = p_event; + if (mb.is_valid()) { + drag_type = DRAG_TYPE_NONE; + if (ctrl && mb->is_pressed() && mb->get_button_index() == MOUSE_BUTTON_WHEEL_DOWN) { // Zoom out zoom_widget->set_zoom_by_increments(-2); - emit_signal("transform_changed", zoom_widget->get_zoom(), Vector2(scroll_container->get_h_scroll(), scroll_container->get_v_scroll())); - _update_zoom(zoom_widget->get_zoom(), true); + emit_signal("transform_changed", zoom_widget->get_zoom(), panning); + _update_zoom_and_panning(true); accept_event(); } - if (ctrl && b->is_pressed() && b->get_button_index() == MOUSE_BUTTON_WHEEL_UP) { + if (ctrl && mb->is_pressed() && mb->get_button_index() == MOUSE_BUTTON_WHEEL_UP) { // Zoom in zoom_widget->set_zoom_by_increments(2); - emit_signal("transform_changed", zoom_widget->get_zoom(), Vector2(scroll_container->get_h_scroll(), scroll_container->get_v_scroll())); - _update_zoom(zoom_widget->get_zoom(), true); + emit_signal("transform_changed", zoom_widget->get_zoom(), panning); + _update_zoom_and_panning(true); + accept_event(); + } + + if (mb->get_button_index() == MOUSE_BUTTON_MIDDLE || mb->get_button_index() == MOUSE_BUTTON_RIGHT) { + if (mb->is_pressed()) { + drag_type = DRAG_TYPE_PAN; + } else { + drag_type = DRAG_TYPE_NONE; + } + accept_event(); + } + } + + Ref<InputEventMouseMotion> mm = p_event; + if (mm.is_valid()) { + if (drag_type == DRAG_TYPE_PAN) { + panning += mm->get_relative(); + _update_zoom_and_panning(); + emit_signal("transform_changed", zoom_widget->get_zoom(), panning); accept_event(); } } @@ -103,25 +122,27 @@ Size2i TileAtlasView::_compute_alternative_tiles_control_size() { return size; } -void TileAtlasView::_update_zoom(float p_zoom, bool p_zoom_on_mouse_pos, Vector2i p_scroll) { +void TileAtlasView::_update_zoom_and_panning(bool p_zoom_on_mouse_pos) { + float zoom = zoom_widget->get_zoom(); + // Compute the minimum sizes. Size2i base_tiles_control_size = _compute_base_tiles_control_size(); - base_tiles_root_control->set_custom_minimum_size(Vector2(base_tiles_control_size) * p_zoom); + base_tiles_root_control->set_custom_minimum_size(Vector2(base_tiles_control_size) * zoom); Size2i alternative_tiles_control_size = _compute_alternative_tiles_control_size(); - alternative_tiles_root_control->set_custom_minimum_size(Vector2(alternative_tiles_control_size) * p_zoom); + alternative_tiles_root_control->set_custom_minimum_size(Vector2(alternative_tiles_control_size) * zoom); // Set the texture for the base tiles. Ref<Texture2D> texture = tile_set_atlas_source->get_texture(); // Set the scales. if (base_tiles_control_size.x > 0 && base_tiles_control_size.y > 0) { - base_tiles_drawing_root->set_scale(Vector2(p_zoom, p_zoom)); + base_tiles_drawing_root->set_scale(Vector2(zoom, zoom)); } else { base_tiles_drawing_root->set_scale(Vector2(1, 1)); } if (alternative_tiles_control_size.x > 0 && alternative_tiles_control_size.y > 0) { - alternative_tiles_drawing_root->set_scale(Vector2(p_zoom, p_zoom)); + alternative_tiles_drawing_root->set_scale(Vector2(zoom, zoom)); } else { alternative_tiles_drawing_root->set_scale(Vector2(1, 1)); } @@ -129,64 +150,40 @@ void TileAtlasView::_update_zoom(float p_zoom, bool p_zoom_on_mouse_pos, Vector2 // Update the margin container's margins. const char *constants[] = { "margin_left", "margin_top", "margin_right", "margin_bottom" }; for (int i = 0; i < 4; i++) { - margin_container->add_theme_constant_override(constants[i], margin_container_paddings[i] * p_zoom); + margin_container->add_theme_constant_override(constants[i], margin_container_paddings[i] * zoom); } // Update the backgrounds. background_left->update(); background_right->update(); - if (p_scroll != Vector2i(-1, -1)) { - scroll_container->set_h_scroll(p_scroll.x); - scroll_container->set_v_scroll(p_scroll.y); - } - // Zoom on the position. - if (previous_zoom != p_zoom) { - // TODO: solve this. - // There is however an issue with scrollcainter preventing this, as it seems - // that the scrollbars are not updated right aways after its children update. - - // Compute point on previous area. - /*Vector2 max = Vector2(scroll_container->get_h_scrollbar()->get_max(), scroll_container->get_v_scrollbar()->get_max()); - Vector2 min = Vector2(scroll_container->get_h_scrollbar()->get_min(), scroll_container->get_v_scrollbar()->get_min()); - Vector2 value = Vector2(scroll_container->get_h_scrollbar()->get_value(), scroll_container->get_v_scrollbar()->get_value()); - - Vector2 old_max = max * previous_zoom / p_zoom; - - Vector2 max_pixel_change = max - old_max; - Vector2 ratio = ((value + scroll_container->get_local_mouse_position()) / old_max).max(Vector2()).min(Vector2(1,1)); - Vector2 offset = max_pixel_change * ratio; - - print_line("--- ZOOMED ---"); - print_line(vformat("max: %s", max)); - print_line(vformat("min: %s", min)); - print_line(vformat("value: %s", value)); - print_line(vformat("size: %s", scroll_container->get_size())); - print_line(vformat("mouse_pos: %s", scroll_container->get_local_mouse_position())); - - print_line(vformat("ratio: %s", ratio)); - print_line(vformat("max_pixel_change: %s", max_pixel_change)); - print_line(vformat("offset: %s", offset)); - + if (p_zoom_on_mouse_pos) { + // Offset the panning relative to the center of panel. + Vector2 relative_mpos = get_local_mouse_position() - get_size() / 2; + panning = (panning - relative_mpos) * zoom / previous_zoom + relative_mpos; + } else { + // Center of panel. + panning = panning * zoom / previous_zoom; + } + button_center_view->set_disabled(panning.is_equal_approx(Vector2())); - print_line(vformat("value before: %s", Vector2(scroll_container->get_h_scroll(), scroll_container->get_v_scroll()))); - scroll_container->set_h_scroll(10000);//scroll_container->get_h_scroll()+offset.x); - scroll_container->set_v_scroll(10000);//scroll_container->get_v_scroll()+offset.y); - print_line(vformat("value after: %s", Vector2(scroll_container->get_h_scroll(), scroll_container->get_v_scroll()))); - */ + previous_zoom = zoom; - previous_zoom = p_zoom; - } + center_container->set_begin(panning - center_container->get_minimum_size() / 2); + center_container->set_size(center_container->get_minimum_size()); } -void TileAtlasView::_scroll_changed() { - emit_signal("transform_changed", zoom_widget->get_zoom(), Vector2(scroll_container->get_h_scroll(), scroll_container->get_v_scroll())); +void TileAtlasView::_zoom_widget_changed() { + _update_zoom_and_panning(); + emit_signal("transform_changed", zoom_widget->get_zoom(), panning); } -void TileAtlasView::_zoom_widget_changed() { - _update_zoom(zoom_widget->get_zoom()); - emit_signal("transform_changed", zoom_widget->get_zoom(), Vector2(scroll_container->get_h_scroll(), scroll_container->get_v_scroll())); +void TileAtlasView::_center_view() { + panning = Vector2(); + button_center_view->set_disabled(true); + _update_zoom_and_panning(); + emit_signal("transform_changed", zoom_widget->get_zoom(), panning); } void TileAtlasView::_base_tiles_root_control_gui_input(const Ref<InputEvent> &p_event) { @@ -415,7 +412,7 @@ void TileAtlasView::set_atlas_source(TileSet *p_tile_set, TileSetAtlasSource *p_ _update_alternative_tiles_rect_cache(); // Update everything. - _update_zoom(zoom_widget->get_zoom()); + _update_zoom_and_panning(); // Change children control size. Size2i base_tiles_control_size = _compute_base_tiles_control_size(); @@ -448,9 +445,10 @@ float TileAtlasView::get_zoom() const { return zoom_widget->get_zoom(); }; -void TileAtlasView::set_transform(float p_zoom, Vector2i p_scroll) { +void TileAtlasView::set_transform(float p_zoom, Vector2i p_panning) { zoom_widget->set_zoom(p_zoom); - _update_zoom(zoom_widget->get_zoom(), false, p_scroll); + panning = p_panning; + _update_zoom_and_panning(); }; void TileAtlasView::set_padding(Side p_side, int p_padding) { @@ -525,7 +523,7 @@ Rect2i TileAtlasView::get_alternative_tile_rect(const Vector2i p_coords, int p_a } void TileAtlasView::update() { - scroll_container->update(); + base_tiles_draw->update(); base_tiles_texture_grid->update(); base_tiles_shape_grid->update(); base_tiles_dark->update(); @@ -534,124 +532,149 @@ void TileAtlasView::update() { background_right->update(); } +void TileAtlasView::_notification(int p_what) { + switch (p_what) { + case NOTIFICATION_READY: + button_center_view->set_icon(get_theme_icon("CenterView", "EditorIcons")); + break; + } +} + void TileAtlasView::_bind_methods() { + ClassDB::bind_method("_gui_input", &TileAtlasView::_gui_input); + ADD_SIGNAL(MethodInfo("transform_changed", PropertyInfo(Variant::FLOAT, "zoom"), PropertyInfo(Variant::VECTOR2, "scroll"))); } TileAtlasView::TileAtlasView() { - Panel *panel_container = memnew(Panel); - panel_container->set_h_size_flags(SIZE_EXPAND_FILL); - panel_container->set_v_size_flags(SIZE_EXPAND_FILL); - panel_container->set_anchors_and_offsets_preset(Control::PRESET_WIDE); - add_child(panel_container); - - //Scrolling - scroll_container = memnew(ScrollContainer); - scroll_container->get_h_scrollbar()->connect("value_changed", callable_mp(this, &TileAtlasView::_scroll_changed).unbind(1)); - scroll_container->get_v_scrollbar()->connect("value_changed", callable_mp(this, &TileAtlasView::_scroll_changed).unbind(1)); - panel_container->add_child(scroll_container); - scroll_container->set_anchors_and_offsets_preset(Control::PRESET_WIDE); + set_texture_filter(CanvasItem::TEXTURE_FILTER_NEAREST); + + Panel *panel = memnew(Panel); + panel->set_clip_contents(true); + panel->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); + panel->set_anchors_and_offsets_preset(Control::PRESET_WIDE); + panel->set_h_size_flags(SIZE_EXPAND_FILL); + panel->set_v_size_flags(SIZE_EXPAND_FILL); + add_child(panel); + // Scrollingsc zoom_widget = memnew(EditorZoomWidget); add_child(zoom_widget); zoom_widget->set_anchors_and_offsets_preset(Control::PRESET_TOP_LEFT, Control::PRESET_MODE_MINSIZE, 2 * EDSCALE); zoom_widget->connect("zoom_changed", callable_mp(this, &TileAtlasView::_zoom_widget_changed).unbind(1)); - CenterContainer *center_container = memnew(CenterContainer); - center_container->set_h_size_flags(SIZE_EXPAND_FILL); - center_container->set_v_size_flags(SIZE_EXPAND_FILL); + button_center_view = memnew(Button); + button_center_view->set_icon(get_theme_icon("CenterView", "EditorIcons")); + button_center_view->set_anchors_and_offsets_preset(Control::PRESET_TOP_RIGHT, Control::PRESET_MODE_MINSIZE, 5); + button_center_view->connect("pressed", callable_mp(this, &TileAtlasView::_center_view)); + button_center_view->set_flat(true); + button_center_view->set_disabled(true); + add_child(button_center_view); + + center_container = memnew(CenterContainer); + center_container->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); + center_container->set_anchors_preset(Control::PRESET_CENTER); center_container->connect("gui_input", callable_mp(this, &TileAtlasView::_gui_input)); - scroll_container->add_child(center_container); + panel->add_child(center_container); missing_source_label = memnew(Label); missing_source_label->set_text(TTR("No atlas source with a valid texture selected.")); center_container->add_child(missing_source_label); margin_container = memnew(MarginContainer); + margin_container->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); center_container->add_child(margin_container); hbox = memnew(HBoxContainer); + hbox->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); hbox->add_theme_constant_override("separation", 10); hbox->hide(); margin_container->add_child(hbox); VBoxContainer *left_vbox = memnew(VBoxContainer); + left_vbox->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); hbox->add_child(left_vbox); VBoxContainer *right_vbox = memnew(VBoxContainer); + right_vbox->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); hbox->add_child(right_vbox); // Base tiles. Label *base_tile_label = memnew(Label); + base_tile_label->set_mouse_filter(Control::MOUSE_FILTER_PASS); base_tile_label->set_text(TTR("Base Tiles")); base_tile_label->set_align(Label::ALIGN_CENTER); left_vbox->add_child(base_tile_label); base_tiles_root_control = memnew(Control); + base_tiles_root_control->set_mouse_filter(Control::MOUSE_FILTER_PASS); base_tiles_root_control->set_v_size_flags(Control::SIZE_EXPAND_FILL); base_tiles_root_control->connect("gui_input", callable_mp(this, &TileAtlasView::_base_tiles_root_control_gui_input)); left_vbox->add_child(base_tiles_root_control); background_left = memnew(Control); + background_left->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); background_left->set_anchors_and_offsets_preset(Control::PRESET_WIDE); background_left->set_texture_repeat(TextureRepeat::TEXTURE_REPEAT_ENABLED); - background_left->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); background_left->connect("draw", callable_mp(this, &TileAtlasView::_draw_background_left)); base_tiles_root_control->add_child(background_left); base_tiles_drawing_root = memnew(Control); + base_tiles_drawing_root->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); base_tiles_drawing_root->set_anchors_and_offsets_preset(Control::PRESET_WIDE); base_tiles_drawing_root->set_texture_filter(TEXTURE_FILTER_NEAREST); - base_tiles_drawing_root->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); base_tiles_root_control->add_child(base_tiles_drawing_root); base_tiles_draw = memnew(Control); + base_tiles_draw->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); base_tiles_draw->set_anchors_and_offsets_preset(Control::PRESET_WIDE); base_tiles_draw->connect("draw", callable_mp(this, &TileAtlasView::_draw_base_tiles)); - base_tiles_draw->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); base_tiles_drawing_root->add_child(base_tiles_draw); base_tiles_texture_grid = memnew(Control); + base_tiles_texture_grid->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); base_tiles_texture_grid->set_anchors_and_offsets_preset(Control::PRESET_WIDE); base_tiles_texture_grid->connect("draw", callable_mp(this, &TileAtlasView::_draw_base_tiles_texture_grid)); - base_tiles_texture_grid->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); base_tiles_drawing_root->add_child(base_tiles_texture_grid); base_tiles_shape_grid = memnew(Control); + base_tiles_shape_grid->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); base_tiles_shape_grid->set_anchors_and_offsets_preset(Control::PRESET_WIDE); base_tiles_shape_grid->connect("draw", callable_mp(this, &TileAtlasView::_draw_base_tiles_shape_grid)); - base_tiles_shape_grid->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); base_tiles_drawing_root->add_child(base_tiles_shape_grid); base_tiles_dark = memnew(Control); + base_tiles_dark->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); base_tiles_dark->set_anchors_and_offsets_preset(Control::PRESET_WIDE); base_tiles_dark->connect("draw", callable_mp(this, &TileAtlasView::_draw_base_tiles_dark)); - base_tiles_dark->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); base_tiles_drawing_root->add_child(base_tiles_dark); // Alternative tiles. Label *alternative_tiles_label = memnew(Label); + alternative_tiles_label->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); alternative_tiles_label->set_text(TTR("Alternative Tiles")); alternative_tiles_label->set_align(Label::ALIGN_CENTER); right_vbox->add_child(alternative_tiles_label); alternative_tiles_root_control = memnew(Control); + alternative_tiles_root_control->set_mouse_filter(Control::MOUSE_FILTER_PASS); alternative_tiles_root_control->connect("gui_input", callable_mp(this, &TileAtlasView::_alternative_tiles_root_control_gui_input)); right_vbox->add_child(alternative_tiles_root_control); background_right = memnew(Control); + background_right->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); background_right->set_texture_repeat(TextureRepeat::TEXTURE_REPEAT_ENABLED); background_right->connect("draw", callable_mp(this, &TileAtlasView::_draw_background_right)); - background_right->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); + alternative_tiles_root_control->add_child(background_right); alternative_tiles_drawing_root = memnew(Control); - alternative_tiles_drawing_root->set_texture_filter(TEXTURE_FILTER_NEAREST); alternative_tiles_drawing_root->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); + alternative_tiles_drawing_root->set_texture_filter(TEXTURE_FILTER_NEAREST); alternative_tiles_root_control->add_child(alternative_tiles_drawing_root); alternatives_draw = memnew(Control); - alternatives_draw->connect("draw", callable_mp(this, &TileAtlasView::_draw_alternatives)); alternatives_draw->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); + alternatives_draw->connect("draw", callable_mp(this, &TileAtlasView::_draw_alternatives)); alternative_tiles_drawing_root->add_child(alternatives_draw); } diff --git a/editor/plugins/tiles/tile_atlas_view.h b/editor/plugins/tiles/tile_atlas_view.h index 28fd3ed1e0..bafc2b3985 100644 --- a/editor/plugins/tiles/tile_atlas_view.h +++ b/editor/plugins/tiles/tile_atlas_view.h @@ -34,6 +34,7 @@ #include "editor/editor_zoom_widget.h" #include "scene/gui/box_container.h" #include "scene/gui/button.h" +#include "scene/gui/center_container.h" #include "scene/gui/label.h" #include "scene/gui/margin_container.h" #include "scene/gui/scroll_container.h" @@ -48,17 +49,24 @@ private: TileSetAtlasSource *tile_set_atlas_source; int source_id = -1; + enum DragType { + DRAG_TYPE_NONE, + DRAG_TYPE_PAN, + }; + DragType drag_type = DRAG_TYPE_NONE; float previous_zoom = 1.0; EditorZoomWidget *zoom_widget; + Button *button_center_view; + CenterContainer *center_container; + Vector2 panning; + void _update_zoom_and_panning(bool p_zoom_on_mouse_pos = false); void _zoom_widget_changed(); - void _scroll_changed(); - void _update_zoom(float p_zoom, bool p_zoom_on_mouse_pos = false, Vector2i p_scroll = Vector2i(-1, -1)); + void _center_view(); void _gui_input(const Ref<InputEvent> &p_event); Map<Vector2, Map<int, Rect2i>> alternative_tiles_rect_cache; void _update_alternative_tiles_rect_cache(); - ScrollContainer *scroll_container; MarginContainer *margin_container; int margin_container_paddings[4] = { 0, 0, 0, 0 }; HBoxContainer *hbox; @@ -102,16 +110,15 @@ private: Size2i _compute_alternative_tiles_control_size(); protected: + void _notification(int p_what); static void _bind_methods(); public: // Global. void set_atlas_source(TileSet *p_tile_set, TileSetAtlasSource *p_tile_set_atlas_source, int p_source_id); - ScrollContainer *get_scroll_container() { return scroll_container; }; - float get_zoom() const; - void set_transform(float p_zoom, Vector2i p_scroll); + void set_transform(float p_zoom, Vector2i p_panning); void set_padding(Side p_side, int p_padding); diff --git a/editor/plugins/tiles/tile_data_editors.cpp b/editor/plugins/tiles/tile_data_editors.cpp index 191440bdb3..d9d0e48fb3 100644 --- a/editor/plugins/tiles/tile_data_editors.cpp +++ b/editor/plugins/tiles/tile_data_editors.cpp @@ -32,202 +32,2436 @@ #include "tile_set_editor.h" -TileData *TileDataEditor::_get_tile_data(TileSet *p_tile_set, int p_atlas_source_id, Vector2i p_atlas_coords, int p_alternative_tile) { - ERR_FAIL_COND_V(!p_tile_set, nullptr); - ERR_FAIL_COND_V(!p_tile_set->has_source(p_atlas_source_id), nullptr); +#include "core/math/geometry_2d.h" +#include "core/os/keyboard.h" + +#include "editor/editor_properties.h" +#include "editor/editor_scale.h" + +void TileDataEditor::_call_tile_set_changed() { + _tile_set_changed(); +} + +TileData *TileDataEditor::_get_tile_data(TileMapCell p_cell) { + ERR_FAIL_COND_V(!tile_set.is_valid(), nullptr); + ERR_FAIL_COND_V(!tile_set->has_source(p_cell.source_id), nullptr); TileData *td = nullptr; - TileSetSource *source = *p_tile_set->get_source(p_atlas_source_id); + TileSetSource *source = *tile_set->get_source(p_cell.source_id); TileSetAtlasSource *atlas_source = Object::cast_to<TileSetAtlasSource>(source); if (atlas_source) { - ERR_FAIL_COND_V(!atlas_source->has_tile(p_atlas_coords), nullptr); - ERR_FAIL_COND_V(!atlas_source->has_alternative_tile(p_atlas_coords, p_alternative_tile), nullptr); - td = Object::cast_to<TileData>(atlas_source->get_tile_data(p_atlas_coords, p_alternative_tile)); + ERR_FAIL_COND_V(!atlas_source->has_tile(p_cell.get_atlas_coords()), nullptr); + ERR_FAIL_COND_V(!atlas_source->has_alternative_tile(p_cell.get_atlas_coords(), p_cell.alternative_tile), nullptr); + td = Object::cast_to<TileData>(atlas_source->get_tile_data(p_cell.get_atlas_coords(), p_cell.alternative_tile)); } return td; } -void TileDataEditor::edit(TileSet *p_tile_set, int p_atlas_source_id, Vector2i p_atlas_coords, int p_alternative_tile, String p_property) { +void TileDataEditor::_bind_methods() { + ADD_SIGNAL(MethodInfo("needs_redraw")); } -void TileDataTextureOffsetEditor::draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileSet *p_tile_set, int p_atlas_source_id, Vector2i p_atlas_coords, int p_alternative_tile, String p_property) { - TileData *tile_data = _get_tile_data(p_tile_set, p_atlas_source_id, p_atlas_coords, p_alternative_tile); - ERR_FAIL_COND(!tile_data); +void TileDataEditor::set_tile_set(Ref<TileSet> p_tile_set) { + if (tile_set.is_valid()) { + tile_set->disconnect("changed", callable_mp(this, &TileDataEditor::_call_tile_set_changed)); + } + tile_set = p_tile_set; + if (tile_set.is_valid()) { + tile_set->connect("changed", callable_mp(this, &TileDataEditor::_call_tile_set_changed)); + } + _call_tile_set_changed(); +} - bool valid; - Variant value = tile_data->get(p_property, &valid); - if (!valid) { - return; +bool DummyObject::_set(const StringName &p_name, const Variant &p_value) { + if (properties.has(p_name)) { + properties[p_name] = p_value; + return true; } - ERR_FAIL_COND(value.get_type() != Variant::VECTOR2I); + return false; +} - Vector2i tile_set_tile_size = p_tile_set->get_tile_size(); - Rect2i rect = Rect2i(-tile_set_tile_size / 2, tile_set_tile_size); - p_tile_set->draw_tile_shape(p_canvas_item, p_transform.xform(rect), Color(1.0, 0.0, 0.0)); +bool DummyObject::_get(const StringName &p_name, Variant &r_ret) const { + if (properties.has(p_name)) { + r_ret = properties[p_name]; + return true; + } + return false; +} + +bool DummyObject::has_dummy_property(StringName p_name) { + return properties.has(p_name); +} + +void DummyObject::add_dummy_property(StringName p_name) { + ERR_FAIL_COND(properties.has(p_name)); + properties[p_name] = Variant(); +} + +void DummyObject::remove_dummy_property(StringName p_name) { + ERR_FAIL_COND(!properties.has(p_name)); + properties.erase(p_name); +} + +void DummyObject::clear_dummy_properties() { + properties.clear(); +} + +void GenericTilePolygonEditor::_base_control_draw() { + ERR_FAIL_COND(!tile_set.is_valid()); + + real_t grab_threshold = EDITOR_GET("editors/poly_editor/point_grab_radius"); + + Color grid_color = EditorSettings::get_singleton()->get("editors/tiles_editor/grid_color"); + const Ref<Texture2D> handle = get_theme_icon("EditorPathSharpHandle", "EditorIcons"); + const Ref<Texture2D> add_handle = get_theme_icon("EditorHandleAdd", "EditorIcons"); + + Size2 tile_size = tile_set->get_tile_size(); + + Transform2D xform; + xform.set_origin(base_control->get_size() / 2 + panning); + xform.set_scale(Vector2(editor_zoom_widget->get_zoom(), editor_zoom_widget->get_zoom())); + base_control->draw_set_transform_matrix(xform); + + // Draw the tile shape filled. + tile_set->draw_tile_shape(base_control, Rect2(-tile_size / 2, tile_size), Color(1.0, 1.0, 1.0, 0.3), true); + + // Draw the background. + if (background_texture.is_valid()) { + base_control->draw_texture_rect_region(background_texture, Rect2(-background_region.size / 2 - background_offset, background_region.size), background_region, background_modulate, background_transpose); + } + + // Draw the polygons. + for (unsigned int i = 0; i < polygons.size(); i++) { + const Vector<Vector2> &polygon = polygons[i]; + Color color = polygon_color; + if (!in_creation_polygon.is_empty()) { + color = color.darkened(0.3); + } + color.a = 0.5; + Vector<Color> v_color; + v_color.push_back(color); + base_control->draw_polygon(polygon, v_color); + + color.a = 0.7; + for (int j = 0; j < polygon.size(); j++) { + base_control->draw_line(polygon[j], polygon[(j + 1) % polygon.size()], color); + } + } + + // Draw the polygon in creation. + if (!in_creation_polygon.is_empty()) { + for (int i = 0; i < in_creation_polygon.size() - 1; i++) { + base_control->draw_line(in_creation_polygon[i], in_creation_polygon[i + 1], Color(1.0, 1.0, 1.0)); + } + } + + Point2 in_creation_point = xform.affine_inverse().xform(base_control->get_local_mouse_position()); + float in_creation_distance = grab_threshold * 2.0; + _snap_to_tile_shape(in_creation_point, in_creation_distance, grab_threshold / editor_zoom_widget->get_zoom()); + if (button_pixel_snap->is_pressed()) { + _snap_to_half_pixel(in_creation_point); + } + + if (drag_type == DRAG_TYPE_CREATE_POINT && !in_creation_polygon.is_empty()) { + base_control->draw_line(in_creation_polygon[in_creation_polygon.size() - 1], in_creation_point, Color(1.0, 1.0, 1.0)); + } + + // Draw the handles. + int tinted_polygon_index = -1; + int tinted_point_index = -1; + if (drag_type == DRAG_TYPE_DRAG_POINT) { + tinted_polygon_index = drag_polygon_index; + tinted_point_index = drag_point_index; + } else if (hovered_point_index >= 0) { + tinted_polygon_index = hovered_polygon_index; + tinted_point_index = hovered_point_index; + } + + base_control->draw_set_transform_matrix(Transform2D()); + if (!in_creation_polygon.is_empty()) { + for (int i = 0; i < in_creation_polygon.size(); i++) { + base_control->draw_texture(handle, xform.xform(in_creation_polygon[i]) - handle->get_size() / 2); + } + } else { + for (int i = 0; i < (int)polygons.size(); i++) { + const Vector<Vector2> &polygon = polygons[i]; + for (int j = 0; j < polygon.size(); j++) { + const Color modulate = (tinted_polygon_index == i && tinted_point_index == j) ? Color(0.5, 1, 2) : Color(1, 1, 1); + base_control->draw_texture(handle, xform.xform(polygon[j]) - handle->get_size() / 2, modulate); + } + } + } + + // Draw the text on top of the selected point. + if (tinted_polygon_index >= 0) { + Ref<Font> font = get_theme_font("font", "Label"); + int font_size = get_theme_font_size("font_size", "Label"); + String text = multiple_polygon_mode ? vformat("%d:%d", tinted_polygon_index, tinted_point_index) : vformat("%d", tinted_point_index); + Size2 text_size = font->get_string_size(text, font_size); + base_control->draw_string(font, xform.xform(polygons[tinted_polygon_index][tinted_point_index]) - text_size * 0.5, text, HALIGN_LEFT, -1, font_size, Color(1.0, 1.0, 1.0, 0.5)); + } + + if (drag_type == DRAG_TYPE_CREATE_POINT) { + base_control->draw_texture(handle, xform.xform(in_creation_point) - handle->get_size() / 2, Color(0.5, 1, 2)); + } + + // Draw the point creation preview in edit mode. + if (hovered_segment_index >= 0) { + base_control->draw_texture(add_handle, xform.xform(hovered_segment_point) - add_handle->get_size() / 2); + } + + // Draw the tile shape line. + base_control->draw_set_transform_matrix(xform); + tile_set->draw_tile_shape(base_control, Rect2(-tile_size / 2, tile_size), grid_color, false); + base_control->draw_set_transform_matrix(Transform2D()); +} + +void GenericTilePolygonEditor::_center_view() { + panning = Vector2(); + base_control->update(); + button_center_view->set_disabled(true); +} + +void GenericTilePolygonEditor::_zoom_changed() { + base_control->update(); +} + +void GenericTilePolygonEditor::_advanced_menu_item_pressed(int p_item_pressed) { + switch (p_item_pressed) { + case RESET_TO_DEFAULT_TILE: + undo_redo->create_action(TTR("Edit Polygons")); + undo_redo->add_do_method(this, "clear_polygons"); + undo_redo->add_do_method(this, "add_polygon", tile_set->get_tile_shape_polygon()); + undo_redo->add_do_method(base_control, "update"); + undo_redo->add_do_method(this, "emit_signal", "polygons_changed"); + undo_redo->add_undo_method(this, "clear_polygons"); + for (unsigned int i = 0; i < polygons.size(); i++) { + undo_redo->add_undo_method(this, "add_polygon", polygons[i]); + } + undo_redo->add_undo_method(base_control, "update"); + undo_redo->add_undo_method(this, "emit_signal", "polygons_changed"); + undo_redo->commit_action(true); + break; + case CLEAR_TILE: + undo_redo->create_action(TTR("Edit Polygons")); + undo_redo->add_do_method(this, "clear_polygons"); + undo_redo->add_do_method(base_control, "update"); + undo_redo->add_do_method(this, "emit_signal", "polygons_changed"); + undo_redo->add_undo_method(this, "clear_polygons"); + for (unsigned int i = 0; i < polygons.size(); i++) { + undo_redo->add_undo_method(this, "add_polygon", polygons[i]); + } + undo_redo->add_undo_method(base_control, "update"); + undo_redo->add_undo_method(this, "emit_signal", "polygons_changed"); + undo_redo->commit_action(true); + break; + default: + break; + } +} + +void GenericTilePolygonEditor::_grab_polygon_point(Vector2 p_pos, const Transform2D &p_polygon_xform, int &r_polygon_index, int &r_point_index) { + const real_t grab_threshold = EDITOR_GET("editors/poly_editor/point_grab_radius"); + r_polygon_index = -1; + r_point_index = -1; + float closest_distance = grab_threshold + 1.0; + for (unsigned int i = 0; i < polygons.size(); i++) { + const Vector<Vector2> &polygon = polygons[i]; + for (int j = 0; j < polygon.size(); j++) { + float distance = p_pos.distance_to(p_polygon_xform.xform(polygon[j])); + if (distance < grab_threshold && distance < closest_distance) { + r_polygon_index = i; + r_point_index = j; + closest_distance = distance; + } + } + } +} + +void GenericTilePolygonEditor::_grab_polygon_segment_point(Vector2 p_pos, const Transform2D &p_polygon_xform, int &r_polygon_index, int &r_segment_index, Vector2 &r_point) { + const real_t grab_threshold = EDITOR_GET("editors/poly_editor/point_grab_radius"); + + Point2 point = p_polygon_xform.affine_inverse().xform(p_pos); + r_polygon_index = -1; + r_segment_index = -1; + float closest_distance = grab_threshold * 2.0; + for (unsigned int i = 0; i < polygons.size(); i++) { + const Vector<Vector2> &polygon = polygons[i]; + for (int j = 0; j < polygon.size(); j++) { + Vector2 segment[2] = { polygon[j], polygon[(j + 1) % polygon.size()] }; + Vector2 closest_point = Geometry2D::get_closest_point_to_segment(point, segment); + float distance = closest_point.distance_to(point); + if (distance < grab_threshold / editor_zoom_widget->get_zoom() && distance < closest_distance) { + r_polygon_index = i; + r_segment_index = j; + r_point = closest_point; + closest_distance = distance; + } + } + } +} + +void GenericTilePolygonEditor::_snap_to_tile_shape(Point2 &r_point, float &r_current_snapped_dist, float p_snap_dist) { + ERR_FAIL_COND(!tile_set.is_valid()); + + Vector<Point2> polygon = tile_set->get_tile_shape_polygon(); + Point2 snapped_point = r_point; + + // Snap to polygon vertices. + bool snapped = false; + for (int i = 0; i < polygon.size(); i++) { + float distance = r_point.distance_to(polygon[i]); + if (distance < p_snap_dist && distance < r_current_snapped_dist) { + snapped_point = polygon[i]; + r_current_snapped_dist = distance; + snapped = true; + } + } + + // Snap to edges if we did not snap to vertices. + if (!snapped) { + for (int i = 0; i < polygon.size(); i++) { + Point2 segment[2] = { polygon[i], polygon[(i + 1) % polygon.size()] }; + Point2 point = Geometry2D::get_closest_point_to_segment(r_point, segment); + float distance = r_point.distance_to(point); + if (distance < p_snap_dist && distance < r_current_snapped_dist) { + snapped_point = point; + r_current_snapped_dist = distance; + } + } + } + + r_point = snapped_point; +} + +void GenericTilePolygonEditor::_snap_to_half_pixel(Point2 &r_point) { + r_point = (r_point * 2).round() / 2.0; +} + +void GenericTilePolygonEditor::_base_control_gui_input(Ref<InputEvent> p_event) { + real_t grab_threshold = EDITOR_GET("editors/poly_editor/point_grab_radius"); + + hovered_polygon_index = -1; + hovered_point_index = -1; + hovered_segment_index = -1; + hovered_segment_point = Vector2(); + + Transform2D xform; + xform.set_origin(base_control->get_size() / 2 + panning); + xform.set_scale(Vector2(editor_zoom_widget->get_zoom(), editor_zoom_widget->get_zoom())); + + Ref<InputEventMouseMotion> mm = p_event; + if (mm.is_valid()) { + if (drag_type == DRAG_TYPE_DRAG_POINT) { + ERR_FAIL_INDEX(drag_polygon_index, (int)polygons.size()); + ERR_FAIL_INDEX(drag_point_index, polygons[drag_polygon_index].size()); + Point2 point = xform.affine_inverse().xform(mm->get_position()); + float distance = grab_threshold * 2.0; + _snap_to_tile_shape(point, distance, grab_threshold / editor_zoom_widget->get_zoom()); + if (button_pixel_snap->is_pressed()) { + _snap_to_half_pixel(point); + } + polygons[drag_polygon_index].write[drag_point_index] = point; + } else if (drag_type == DRAG_TYPE_PAN) { + panning += mm->get_position() - drag_last_pos; + drag_last_pos = mm->get_position(); + button_center_view->set_disabled(panning.is_equal_approx(Vector2())); + } else { + // Update hovered point. + _grab_polygon_point(mm->get_position(), xform, hovered_polygon_index, hovered_point_index); + + // If we have no hovered point, check if we hover a segment. + if (hovered_point_index == -1) { + _grab_polygon_segment_point(mm->get_position(), xform, hovered_polygon_index, hovered_segment_index, hovered_segment_point); + } + } + } + + Ref<InputEventMouseButton> mb = p_event; + if (mb.is_valid()) { + if (mb->get_button_index() == MOUSE_BUTTON_WHEEL_UP && mb->is_ctrl_pressed()) { + editor_zoom_widget->set_zoom_by_increments(1); + _zoom_changed(); + accept_event(); + } else if (mb->get_button_index() == MOUSE_BUTTON_WHEEL_DOWN && mb->is_ctrl_pressed()) { + editor_zoom_widget->set_zoom_by_increments(-1); + _zoom_changed(); + accept_event(); + } else if (mb->get_button_index() == MOUSE_BUTTON_LEFT) { + if (mb->is_pressed()) { + if (tools_button_group->get_pressed_button() != button_create) { + in_creation_polygon.clear(); + } + if (tools_button_group->get_pressed_button() == button_create) { + // Create points. + if (in_creation_polygon.size() >= 3 && mb->get_position().distance_to(xform.xform(in_creation_polygon[0])) < grab_threshold) { + // Closes and create polygon. + if (!multiple_polygon_mode) { + clear_polygons(); + } + int added = add_polygon(in_creation_polygon); + + in_creation_polygon.clear(); + button_edit->set_pressed(true); + undo_redo->create_action(TTR("Edit Polygons")); + if (!multiple_polygon_mode) { + undo_redo->add_do_method(this, "clear_polygons"); + } + undo_redo->add_do_method(this, "add_polygon", in_creation_polygon); + undo_redo->add_do_method(base_control, "update"); + undo_redo->add_undo_method(this, "remove_polygon", added); + undo_redo->add_undo_method(base_control, "update"); + undo_redo->commit_action(false); + emit_signal("polygons_changed"); + } else { + // Create a new point. + drag_type = DRAG_TYPE_CREATE_POINT; + } + } else if (tools_button_group->get_pressed_button() == button_edit) { + // Edit points. + int closest_polygon; + int closest_point; + _grab_polygon_point(mb->get_position(), xform, closest_polygon, closest_point); + if (closest_polygon >= 0) { + drag_type = DRAG_TYPE_DRAG_POINT; + drag_polygon_index = closest_polygon; + drag_point_index = closest_point; + drag_old_polygon = polygons[drag_polygon_index]; + } else { + // Create a point. + Vector2 point_to_create; + _grab_polygon_segment_point(mb->get_position(), xform, closest_polygon, closest_point, point_to_create); + if (closest_polygon >= 0) { + polygons[closest_polygon].insert(closest_point + 1, point_to_create); + drag_type = DRAG_TYPE_DRAG_POINT; + drag_polygon_index = closest_polygon; + drag_point_index = closest_point + 1; + drag_old_polygon = polygons[closest_polygon]; + } + } + } else if (tools_button_group->get_pressed_button() == button_delete) { + // Remove point. + int closest_polygon; + int closest_point; + _grab_polygon_point(mb->get_position(), xform, closest_polygon, closest_point); + if (closest_polygon >= 0) { + PackedVector2Array old_polygon = polygons[closest_polygon]; + polygons[closest_polygon].remove(closest_point); + undo_redo->create_action(TTR("Edit Polygons")); + if (polygons[closest_polygon].size() < 3) { + remove_polygon(closest_polygon); + undo_redo->add_do_method(this, "remove_polygon", closest_polygon); + undo_redo->add_undo_method(this, "add_polygon", old_polygon, closest_polygon); + } else { + undo_redo->add_do_method(this, "set_polygon", closest_polygon, polygons[closest_polygon]); + undo_redo->add_undo_method(this, "set_polygon", closest_polygon, old_polygon); + } + undo_redo->add_do_method(base_control, "update"); + undo_redo->add_undo_method(base_control, "update"); + undo_redo->commit_action(false); + emit_signal("polygons_changed"); + } + } + } else { + if (drag_type == DRAG_TYPE_DRAG_POINT) { + undo_redo->create_action(TTR("Edit Polygons")); + undo_redo->add_do_method(this, "set_polygon", drag_polygon_index, polygons[drag_polygon_index]); + undo_redo->add_do_method(base_control, "update"); + undo_redo->add_undo_method(this, "set_polygon", drag_polygon_index, drag_old_polygon); + undo_redo->add_undo_method(base_control, "update"); + undo_redo->commit_action(false); + emit_signal("polygons_changed"); + } else if (drag_type == DRAG_TYPE_CREATE_POINT) { + Point2 point = xform.affine_inverse().xform(mb->get_position()); + float distance = grab_threshold * 2; + _snap_to_tile_shape(point, distance, grab_threshold / editor_zoom_widget->get_zoom()); + if (button_pixel_snap->is_pressed()) { + _snap_to_half_pixel(point); + } + in_creation_polygon.push_back(point); + } + drag_type = DRAG_TYPE_NONE; + drag_point_index = -1; + } + + } else if (mb->get_button_index() == MOUSE_BUTTON_RIGHT) { + if (mb->is_pressed()) { + if (tools_button_group->get_pressed_button() == button_edit) { + // Remove point or pan. + int closest_polygon; + int closest_point; + _grab_polygon_point(mb->get_position(), xform, closest_polygon, closest_point); + if (closest_polygon >= 0) { + PackedVector2Array old_polygon = polygons[closest_polygon]; + polygons[closest_polygon].remove(closest_point); + undo_redo->create_action(TTR("Edit Polygons")); + if (polygons[closest_polygon].size() < 3) { + remove_polygon(closest_polygon); + undo_redo->add_do_method(this, "remove_polygon", closest_polygon); + undo_redo->add_undo_method(this, "add_polygon", old_polygon, closest_polygon); + } else { + undo_redo->add_do_method(this, "set_polygon", closest_polygon, polygons[closest_polygon]); + undo_redo->add_undo_method(this, "set_polygon", closest_polygon, old_polygon); + } + undo_redo->add_do_method(base_control, "update"); + undo_redo->add_undo_method(base_control, "update"); + undo_redo->commit_action(false); + emit_signal("polygons_changed"); + } else { + drag_type = DRAG_TYPE_PAN; + drag_last_pos = mb->get_position(); + } + } else { + drag_type = DRAG_TYPE_PAN; + drag_last_pos = mb->get_position(); + } + } else { + drag_type = DRAG_TYPE_NONE; + } + } else if (mb->get_button_index() == MOUSE_BUTTON_MIDDLE) { + if (mb->is_pressed()) { + drag_type = DRAG_TYPE_PAN; + drag_last_pos = mb->get_position(); + } else { + drag_type = DRAG_TYPE_NONE; + } + } + } + + base_control->update(); +} + +void GenericTilePolygonEditor::set_tile_set(Ref<TileSet> p_tile_set) { + if (tile_set != p_tile_set) { + // Set the default tile shape + clear_polygons(); + if (p_tile_set.is_valid()) { + add_polygon(p_tile_set->get_tile_shape_polygon()); + } + } + tile_set = p_tile_set; +} + +void GenericTilePolygonEditor::set_background(Ref<Texture2D> p_texture, Rect2 p_region, Vector2 p_offset, bool p_flip_h, bool p_flip_v, bool p_transpose, Color p_modulate) { + background_texture = p_texture; + background_region = p_region; + background_offset = p_offset; + background_h_flip = p_flip_h; + background_v_flip = p_flip_v; + background_transpose = p_transpose; + background_modulate = p_modulate; + base_control->update(); +} + +int GenericTilePolygonEditor::get_polygon_count() { + return polygons.size(); +} + +int GenericTilePolygonEditor::add_polygon(Vector<Point2> p_polygon, int p_index) { + ERR_FAIL_COND_V(p_polygon.size() < 3, -1); + ERR_FAIL_COND_V(!multiple_polygon_mode && polygons.size() >= 1, -1); + + if (p_index < 0) { + polygons.push_back(p_polygon); + base_control->update(); + button_edit->set_pressed(true); + return polygons.size() - 1; + } else { + polygons.insert(p_index, p_polygon); + button_edit->set_pressed(true); + base_control->update(); + return p_index; + } +} + +void GenericTilePolygonEditor::remove_polygon(int p_index) { + ERR_FAIL_INDEX(p_index, (int)polygons.size()); + polygons.remove(p_index); + + if (polygons.size() == 0) { + button_create->set_pressed(true); + } + base_control->update(); +} + +void GenericTilePolygonEditor::clear_polygons() { + polygons.clear(); + base_control->update(); +} + +void GenericTilePolygonEditor::set_polygon(int p_polygon_index, Vector<Point2> p_polygon) { + ERR_FAIL_INDEX(p_polygon_index, (int)polygons.size()); + ERR_FAIL_COND(p_polygon.size() < 3); + polygons[p_polygon_index] = p_polygon; + button_edit->set_pressed(true); + base_control->update(); } -void TileDataIntegerEditor::draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileSet *p_tile_set, int p_atlas_source_id, Vector2i p_atlas_coords, int p_alternative_tile, String p_property) { - TileData *tile_data = _get_tile_data(p_tile_set, p_atlas_source_id, p_atlas_coords, p_alternative_tile); +Vector<Point2> GenericTilePolygonEditor::get_polygon(int p_polygon_index) { + ERR_FAIL_INDEX_V(p_polygon_index, (int)polygons.size(), Vector<Point2>()); + return polygons[p_polygon_index]; +} + +void GenericTilePolygonEditor::set_polygons_color(Color p_color) { + polygon_color = p_color; + base_control->update(); +} + +void GenericTilePolygonEditor::set_multiple_polygon_mode(bool p_multiple_polygon_mode) { + multiple_polygon_mode = p_multiple_polygon_mode; +} + +void GenericTilePolygonEditor::_notification(int p_what) { + switch (p_what) { + case NOTIFICATION_READY: + button_create->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon("CurveCreate", "EditorIcons")); + button_edit->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon("CurveEdit", "EditorIcons")); + button_delete->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon("CurveDelete", "EditorIcons")); + button_center_view->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon("CenterView", "EditorIcons")); + button_pixel_snap->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon("Snap", "EditorIcons")); + button_advanced_menu->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon("GuiTabMenu", "EditorIcons")); + break; + } +} + +void GenericTilePolygonEditor::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_polygon_count"), &GenericTilePolygonEditor::get_polygon_count); + ClassDB::bind_method(D_METHOD("add_polygon", "polygon", "index"), &GenericTilePolygonEditor::add_polygon, DEFVAL(-1)); + ClassDB::bind_method(D_METHOD("remove_polygon", "index"), &GenericTilePolygonEditor::remove_polygon); + ClassDB::bind_method(D_METHOD("clear_polygons"), &GenericTilePolygonEditor::clear_polygons); + ClassDB::bind_method(D_METHOD("set_polygon", "index", "polygon"), &GenericTilePolygonEditor::set_polygon); + ClassDB::bind_method(D_METHOD("get_polygon", "index"), &GenericTilePolygonEditor::set_polygon); + + ADD_SIGNAL(MethodInfo("polygons_changed")); +} + +GenericTilePolygonEditor::GenericTilePolygonEditor() { + toolbar = memnew(HBoxContainer); + add_child(toolbar); + + tools_button_group.instantiate(); + + button_create = memnew(Button); + button_create->set_flat(true); + button_create->set_toggle_mode(true); + button_create->set_button_group(tools_button_group); + button_create->set_pressed(true); + toolbar->add_child(button_create); + + button_edit = memnew(Button); + button_edit->set_flat(true); + button_edit->set_toggle_mode(true); + button_edit->set_button_group(tools_button_group); + toolbar->add_child(button_edit); + + button_delete = memnew(Button); + button_delete->set_flat(true); + button_delete->set_toggle_mode(true); + button_delete->set_button_group(tools_button_group); + toolbar->add_child(button_delete); + + button_advanced_menu = memnew(MenuButton); + button_advanced_menu->set_flat(true); + button_advanced_menu->set_toggle_mode(true); + button_advanced_menu->get_popup()->add_item(TTR("Reset to default tile shape"), RESET_TO_DEFAULT_TILE); + button_advanced_menu->get_popup()->add_item(TTR("Clear"), CLEAR_TILE); + button_advanced_menu->get_popup()->connect("id_pressed", callable_mp(this, &GenericTilePolygonEditor::_advanced_menu_item_pressed)); + toolbar->add_child(button_advanced_menu); + + toolbar->add_child(memnew(VSeparator)); + + button_pixel_snap = memnew(Button); + button_pixel_snap->set_flat(true); + button_pixel_snap->set_toggle_mode(true); + button_pixel_snap->set_pressed(true); + toolbar->add_child(button_pixel_snap); + + Control *root = memnew(Control); + root->set_h_size_flags(Control::SIZE_EXPAND_FILL); + root->set_custom_minimum_size(Size2(0, 200 * EDSCALE)); + root->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); + add_child(root); + + panel = memnew(Panel); + panel->set_anchors_and_offsets_preset(Control::PRESET_WIDE); + panel->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); + root->add_child(panel); + + base_control = memnew(Control); + base_control->set_texture_filter(CanvasItem::TEXTURE_FILTER_NEAREST); + base_control->set_anchors_and_offsets_preset(Control::PRESET_WIDE); + base_control->connect("draw", callable_mp(this, &GenericTilePolygonEditor::_base_control_draw)); + base_control->connect("gui_input", callable_mp(this, &GenericTilePolygonEditor::_base_control_gui_input)); + base_control->set_clip_contents(true); + root->add_child(base_control); + + editor_zoom_widget = memnew(EditorZoomWidget); + editor_zoom_widget->set_position(Vector2(5, 5)); + editor_zoom_widget->connect("zoom_changed", callable_mp(this, &GenericTilePolygonEditor::_zoom_changed).unbind(1)); + root->add_child(editor_zoom_widget); + + button_center_view = memnew(Button); + button_center_view->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon("CenterView", "EditorIcons")); + button_center_view->set_anchors_and_offsets_preset(Control::PRESET_TOP_RIGHT, Control::PRESET_MODE_MINSIZE, 5); + button_center_view->connect("pressed", callable_mp(this, &GenericTilePolygonEditor::_center_view)); + button_center_view->set_flat(true); + button_center_view->set_disabled(true); + root->add_child(button_center_view); +} + +void TileDataDefaultEditor::_property_value_changed(StringName p_property, Variant p_value, StringName p_field) { + ERR_FAIL_COND(!dummy_object); + dummy_object->set(p_property, p_value); +} + +Variant TileDataDefaultEditor::_get_painted_value() { + ERR_FAIL_COND_V(!dummy_object, Variant()); + return dummy_object->get(property); +} + +void TileDataDefaultEditor::_set_painted_value(TileSetAtlasSource *p_tile_set_atlas_source, Vector2 p_coords, int p_alternative_tile) { + TileData *tile_data = Object::cast_to<TileData>(p_tile_set_atlas_source->get_tile_data(p_coords, p_alternative_tile)); ERR_FAIL_COND(!tile_data); + Variant value = tile_data->get(property); + dummy_object->set(property, value); + if (property_editor) { + property_editor->update_property(); + } +} - bool valid; - Variant value = tile_data->get(p_property, &valid); - if (!valid) { - return; +void TileDataDefaultEditor::_set_value(TileSetAtlasSource *p_tile_set_atlas_source, Vector2 p_coords, int p_alternative_tile, Variant p_value) { + TileData *tile_data = Object::cast_to<TileData>(p_tile_set_atlas_source->get_tile_data(p_coords, p_alternative_tile)); + ERR_FAIL_COND(!tile_data); + tile_data->set(property, p_value); +} + +Variant TileDataDefaultEditor::_get_value(TileSetAtlasSource *p_tile_set_atlas_source, Vector2 p_coords, int p_alternative_tile) { + TileData *tile_data = Object::cast_to<TileData>(p_tile_set_atlas_source->get_tile_data(p_coords, p_alternative_tile)); + ERR_FAIL_COND_V(!tile_data, Variant()); + return tile_data->get(property); +} + +void TileDataDefaultEditor::_setup_undo_redo_action(TileSetAtlasSource *p_tile_set_atlas_source, Map<TileMapCell, Variant> p_previous_values, Variant p_new_value) { + for (Map<TileMapCell, Variant>::Element *E = p_previous_values.front(); E; E = E->next()) { + Vector2i coords = E->key().get_atlas_coords(); + undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/%s", coords.x, coords.y, E->key().alternative_tile, property), E->get()); + undo_redo->add_do_property(p_tile_set_atlas_source, vformat("%d:%d/%d/%s", coords.x, coords.y, E->key().alternative_tile, property), p_new_value); } - ERR_FAIL_COND(value.get_type() != Variant::INT); +} - Ref<Font> font = TileSetEditor::get_singleton()->get_theme_font("bold", "EditorFonts"); - int height = font->get_height(); - int width = 200; - p_canvas_item->draw_string(font, p_transform.get_origin() + Vector2i(-width / 2, height / 2), vformat("%d", value), HALIGN_CENTER, width, -1, Color(1, 1, 1), 1, Color(0, 0, 0, 1)); +void TileDataDefaultEditor::forward_draw_over_atlas(TileAtlasView *p_tile_atlas_view, TileSetAtlasSource *p_tile_set_atlas_source, CanvasItem *p_canvas_item, Transform2D p_transform) { + if (drag_type == DRAG_TYPE_PAINT_RECT) { + Color grid_color = EditorSettings::get_singleton()->get("editors/tiles_editor/grid_color"); + Color selection_color = Color().from_hsv(Math::fposmod(grid_color.get_h() + 0.5, 1.0), grid_color.get_s(), grid_color.get_v(), 1.0); + + p_canvas_item->draw_set_transform_matrix(p_transform); + + Rect2i rect; + rect.set_position(p_tile_atlas_view->get_atlas_tile_coords_at_pos(drag_start_pos)); + rect.set_end(p_tile_atlas_view->get_atlas_tile_coords_at_pos(p_transform.affine_inverse().xform(p_canvas_item->get_local_mouse_position()))); + rect = rect.abs(); + + Set<TileMapCell> edited; + for (int x = rect.get_position().x; x <= rect.get_end().x; x++) { + for (int y = rect.get_position().y; y <= rect.get_end().y; y++) { + Vector2i coords = Vector2i(x, y); + coords = p_tile_set_atlas_source->get_tile_at_coords(coords); + if (coords != TileSetSource::INVALID_ATLAS_COORDS) { + TileMapCell cell; + cell.source_id = 0; + cell.set_atlas_coords(coords); + cell.alternative_tile = 0; + edited.insert(cell); + } + } + } + + for (Set<TileMapCell>::Element *E = edited.front(); E; E = E->next()) { + Vector2i coords = E->get().get_atlas_coords(); + p_canvas_item->draw_rect(p_tile_set_atlas_source->get_tile_texture_region(coords), selection_color, false); + } + p_canvas_item->draw_set_transform_matrix(Transform2D()); + } +}; + +void TileDataDefaultEditor::forward_draw_over_alternatives(TileAtlasView *p_tile_atlas_view, TileSetAtlasSource *p_tile_set_atlas_source, CanvasItem *p_canvas_item, Transform2D p_transform){ + +}; + +void TileDataDefaultEditor::forward_painting_atlas_gui_input(TileAtlasView *p_tile_atlas_view, TileSetAtlasSource *p_tile_set_atlas_source, const Ref<InputEvent> &p_event) { + Ref<InputEventMouseMotion> mm = p_event; + if (mm.is_valid()) { + if (drag_type == DRAG_TYPE_PAINT) { + Vector<Vector2i> line = Geometry2D::bresenham_line(p_tile_atlas_view->get_atlas_tile_coords_at_pos(drag_last_pos), p_tile_atlas_view->get_atlas_tile_coords_at_pos(mm->get_position())); + for (int i = 0; i < line.size(); i++) { + Vector2i coords = p_tile_set_atlas_source->get_tile_at_coords(line[i]); + if (coords != TileSetSource::INVALID_ATLAS_COORDS) { + TileMapCell cell; + cell.source_id = 0; + cell.set_atlas_coords(coords); + cell.alternative_tile = 0; + if (!drag_modified.has(cell)) { + drag_modified[cell] = _get_value(p_tile_set_atlas_source, coords, 0); + } + _set_value(p_tile_set_atlas_source, coords, 0, drag_painted_value); + } + } + drag_last_pos = mm->get_position(); + } + } + + Ref<InputEventMouseButton> mb = p_event; + if (mb.is_valid()) { + if (mb->get_button_index() == MOUSE_BUTTON_LEFT) { + if (mb->is_pressed()) { + if (picker_button->is_pressed()) { + Vector2i coords = p_tile_atlas_view->get_atlas_tile_coords_at_pos(mb->get_position()); + coords = p_tile_set_atlas_source->get_tile_at_coords(coords); + if (coords != TileSetSource::INVALID_ATLAS_COORDS) { + _set_painted_value(p_tile_set_atlas_source, coords, 0); + picker_button->set_pressed(false); + } + } else if (mb->is_ctrl_pressed()) { + drag_type = DRAG_TYPE_PAINT_RECT; + drag_modified.clear(); + drag_painted_value = _get_painted_value(); + drag_start_pos = mb->get_position(); + } else { + drag_type = DRAG_TYPE_PAINT; + drag_modified.clear(); + drag_painted_value = _get_painted_value(); + Vector2i coords = p_tile_atlas_view->get_atlas_tile_coords_at_pos(mb->get_position()); + coords = p_tile_set_atlas_source->get_tile_at_coords(coords); + if (coords != TileSetSource::INVALID_ATLAS_COORDS) { + TileMapCell cell; + cell.source_id = 0; + cell.set_atlas_coords(coords); + cell.alternative_tile = 0; + drag_modified[cell] = _get_value(p_tile_set_atlas_source, coords, 0); + _set_value(p_tile_set_atlas_source, coords, 0, drag_painted_value); + } + drag_last_pos = mb->get_position(); + } + } else { + if (drag_type == DRAG_TYPE_PAINT_RECT) { + Rect2i rect; + rect.set_position(p_tile_atlas_view->get_atlas_tile_coords_at_pos(drag_start_pos)); + rect.set_end(p_tile_atlas_view->get_atlas_tile_coords_at_pos(mb->get_position())); + rect = rect.abs(); + + drag_modified.clear(); + for (int x = rect.get_position().x; x <= rect.get_end().x; x++) { + for (int y = rect.get_position().y; y <= rect.get_end().y; y++) { + Vector2i coords = Vector2i(x, y); + coords = p_tile_set_atlas_source->get_tile_at_coords(coords); + if (coords != TileSetSource::INVALID_ATLAS_COORDS) { + TileMapCell cell; + cell.source_id = 0; + cell.set_atlas_coords(coords); + cell.alternative_tile = 0; + drag_modified[cell] = _get_value(p_tile_set_atlas_source, coords, 0); + } + } + } + undo_redo->create_action(TTR("Painting Tiles Property")); + _setup_undo_redo_action(p_tile_set_atlas_source, drag_modified, drag_painted_value); + undo_redo->commit_action(true); + drag_type = DRAG_TYPE_NONE; + } else if (drag_type == DRAG_TYPE_PAINT) { + undo_redo->create_action(TTR("Painting Tiles Property")); + _setup_undo_redo_action(p_tile_set_atlas_source, drag_modified, drag_painted_value); + undo_redo->commit_action(false); + drag_type = DRAG_TYPE_NONE; + } + } + } + } } -void TileDataFloatEditor::draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileSet *p_tile_set, int p_atlas_source_id, Vector2i p_atlas_coords, int p_alternative_tile, String p_property) { - TileData *tile_data = _get_tile_data(p_tile_set, p_atlas_source_id, p_atlas_coords, p_alternative_tile); +void TileDataDefaultEditor::forward_painting_alternatives_gui_input(TileAtlasView *p_tile_atlas_view, TileSetAtlasSource *p_tile_set_atlas_source, const Ref<InputEvent> &p_event) { + Ref<InputEventMouseMotion> mm = p_event; + if (mm.is_valid()) { + if (drag_type == DRAG_TYPE_PAINT) { + Vector3i tile = p_tile_atlas_view->get_alternative_tile_at_pos(mm->get_position()); + Vector2i coords = Vector2i(tile.x, tile.y); + int alternative_tile = tile.z; + + if (coords != TileSetSource::INVALID_ATLAS_COORDS) { + TileMapCell cell; + cell.source_id = 0; + cell.set_atlas_coords(coords); + cell.alternative_tile = alternative_tile; + if (!drag_modified.has(cell)) { + drag_modified[cell] = _get_value(p_tile_set_atlas_source, coords, alternative_tile); + } + _set_value(p_tile_set_atlas_source, coords, alternative_tile, drag_painted_value); + } + + drag_last_pos = mm->get_position(); + } + } + + Ref<InputEventMouseButton> mb = p_event; + if (mb.is_valid()) { + if (mb->get_button_index() == MOUSE_BUTTON_LEFT) { + if (mb->is_pressed()) { + if (picker_button->is_pressed()) { + Vector3i tile = p_tile_atlas_view->get_alternative_tile_at_pos(mb->get_position()); + Vector2i coords = Vector2i(tile.x, tile.y); + int alternative_tile = tile.z; + if (coords != TileSetSource::INVALID_ATLAS_COORDS) { + _set_painted_value(p_tile_set_atlas_source, coords, alternative_tile); + picker_button->set_pressed(false); + } + } else { + drag_type = DRAG_TYPE_PAINT; + drag_modified.clear(); + drag_painted_value = _get_painted_value(); + + Vector3i tile = p_tile_atlas_view->get_alternative_tile_at_pos(mb->get_position()); + Vector2i coords = Vector2i(tile.x, tile.y); + int alternative_tile = tile.z; + + if (coords != TileSetSource::INVALID_ATLAS_COORDS) { + TileMapCell cell; + cell.source_id = 0; + cell.set_atlas_coords(coords); + cell.alternative_tile = alternative_tile; + drag_modified[cell] = _get_value(p_tile_set_atlas_source, coords, alternative_tile); + _set_value(p_tile_set_atlas_source, coords, alternative_tile, drag_painted_value); + } + drag_last_pos = mb->get_position(); + } + } else { + undo_redo->create_action(TTR("Painting Tiles Property")); + _setup_undo_redo_action(p_tile_set_atlas_source, drag_modified, drag_painted_value); + undo_redo->commit_action(false); + drag_type = DRAG_TYPE_NONE; + } + } + } +} + +void TileDataDefaultEditor::draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileMapCell p_cell, bool p_selected) { + TileData *tile_data = _get_tile_data(p_cell); ERR_FAIL_COND(!tile_data); bool valid; - Variant value = tile_data->get(p_property, &valid); + Variant value = tile_data->get(property, &valid); if (!valid) { return; } - ERR_FAIL_COND(value.get_type() != Variant::FLOAT); - Ref<Font> font = TileSetEditor::get_singleton()->get_theme_font("bold", "EditorFonts"); - int height = font->get_height(); - int width = 200; - p_canvas_item->draw_string(font, p_transform.get_origin() + Vector2i(-width / 2, height / 2), vformat("%.2f", value), HALIGN_CENTER, width, -1, Color(1, 1, 1), 1, Color(0, 0, 0, 1)); + if (value.get_type() == Variant::BOOL) { + Ref<Texture2D> texture = (bool)value ? tile_bool_checked : tile_bool_unchecked; + int size = MIN(tile_set->get_tile_size().x, tile_set->get_tile_size().y) / 3; + Rect2 rect = p_transform.xform(Rect2(Vector2(-size / 2, -size / 2), Vector2(size, size))); + p_canvas_item->draw_texture_rect(texture, rect); + } else if (value.get_type() == Variant::COLOR) { + int size = MIN(tile_set->get_tile_size().x, tile_set->get_tile_size().y) / 3; + Rect2 rect = p_transform.xform(Rect2(Vector2(-size / 2, -size / 2), Vector2(size, size))); + p_canvas_item->draw_rect(rect, value); + } else { + Ref<Font> font = TileSetEditor::get_singleton()->get_theme_font("bold", "EditorFonts"); + String text; + switch (value.get_type()) { + case Variant::INT: + text = vformat("%d", value); + break; + case Variant::FLOAT: + text = vformat("%.2f", value); + break; + case Variant::STRING: + case Variant::STRING_NAME: + text = value; + break; + default: + return; + break; + } + + Color color = Color(1, 1, 1); + if (p_selected) { + Color grid_color = EditorSettings::get_singleton()->get("editors/tiles_editor/grid_color"); + Color selection_color = Color().from_hsv(Math::fposmod(grid_color.get_h() + 0.5, 1.0), grid_color.get_s(), grid_color.get_v(), 1.0); + selection_color.set_v(0.9); + color = selection_color; + } else if (is_visible_in_tree()) { + Variant painted_value = _get_painted_value(); + bool equal = (painted_value.get_type() == Variant::FLOAT && value.get_type() == Variant::FLOAT) ? Math::is_equal_approx(float(painted_value), float(value)) : painted_value == value; + if (equal) { + color = Color(0.7, 0.7, 0.7); + } + } + + Vector2 string_size = font->get_string_size(text); + p_canvas_item->draw_string(font, p_transform.get_origin() + Vector2i(-string_size.x / 2, string_size.y / 2), text, HALIGN_CENTER, string_size.x, -1, color, 1, Color(0, 0, 0, 1)); + } } -void TileDataPositionEditor::draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileSet *p_tile_set, int p_atlas_source_id, Vector2i p_atlas_coords, int p_alternative_tile, String p_property) { - TileData *tile_data = _get_tile_data(p_tile_set, p_atlas_source_id, p_atlas_coords, p_alternative_tile); +void TileDataDefaultEditor::setup_property_editor(Variant::Type p_type, String p_property, String p_label, Variant p_default_value) { + ERR_FAIL_COND_MSG(!property.is_empty(), "Cannot setup TileDataDefaultEditor twice"); + property = p_property; + + // Update everything. + if (property_editor) { + property_editor->queue_delete(); + } + + // Update the dummy object. + dummy_object->add_dummy_property(p_property); + + // Get the default value for the type. + if (p_default_value == Variant()) { + Callable::CallError error; + Variant painted_value; + Variant::construct(p_type, painted_value, nullptr, 0, error); + dummy_object->set(p_property, painted_value); + } else { + dummy_object->set(p_property, p_default_value); + } + + // Create and setup the property editor. + property_editor = EditorInspectorDefaultPlugin::get_editor_for_property(dummy_object, p_type, p_property, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT); + property_editor->set_object_and_property(dummy_object, p_property); + if (p_label.is_empty()) { + property_editor->set_label(p_property); + } else { + property_editor->set_label(p_label); + } + property_editor->connect("property_changed", callable_mp(this, &TileDataDefaultEditor::_property_value_changed).unbind(1)); + property_editor->update_property(); + add_child(property_editor); +} + +void TileDataDefaultEditor::_notification(int p_what) { + switch (p_what) { + case NOTIFICATION_ENTER_TREE: + case NOTIFICATION_THEME_CHANGED: + picker_button->set_icon(get_theme_icon("ColorPick", "EditorIcons")); + tile_bool_checked = get_theme_icon("TileChecked", "EditorIcons"); + tile_bool_unchecked = get_theme_icon("TileUnchecked", "EditorIcons"); + break; + default: + break; + } +} + +TileDataDefaultEditor::TileDataDefaultEditor() { + label = memnew(Label); + label->set_text("Painting:"); + add_child(label); + + toolbar->add_child(memnew(VSeparator)); + + picker_button = memnew(Button); + picker_button->set_flat(true); + picker_button->set_toggle_mode(true); + picker_button->set_shortcut(ED_SHORTCUT("tiles_editor/picker", "Picker", KEY_P)); + toolbar->add_child(picker_button); +} + +TileDataDefaultEditor::~TileDataDefaultEditor() { + toolbar->queue_delete(); + memdelete(dummy_object); +} + +void TileDataTextureOffsetEditor::draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileMapCell p_cell, bool p_selected) { + TileData *tile_data = _get_tile_data(p_cell); + ERR_FAIL_COND(!tile_data); + + Vector2i tile_set_tile_size = tile_set->get_tile_size(); + Rect2i rect = Rect2i(-tile_set_tile_size / 2, tile_set_tile_size); + Color color = Color(1.0, 0.0, 0.0); + if (p_selected) { + Color grid_color = EditorSettings::get_singleton()->get("editors/tiles_editor/grid_color"); + Color selection_color = Color().from_hsv(Math::fposmod(grid_color.get_h() + 0.5, 1.0), grid_color.get_s(), grid_color.get_v(), 1.0); + color = selection_color; + } + tile_set->draw_tile_shape(p_canvas_item, p_transform.xform(rect), color); +} + +void TileDataPositionEditor::draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileMapCell p_cell, bool p_selected) { + TileData *tile_data = _get_tile_data(p_cell); ERR_FAIL_COND(!tile_data); bool valid; - Variant value = tile_data->get(p_property, &valid); + Variant value = tile_data->get(property, &valid); if (!valid) { return; } ERR_FAIL_COND(value.get_type() != Variant::VECTOR2I && value.get_type() != Variant::VECTOR2); + Color color = Color(1.0, 1.0, 1.0); + if (p_selected) { + Color grid_color = EditorSettings::get_singleton()->get("editors/tiles_editor/grid_color"); + Color selection_color = Color().from_hsv(Math::fposmod(grid_color.get_h() + 0.5, 1.0), grid_color.get_s(), grid_color.get_v(), 1.0); + color = selection_color; + } Ref<Texture2D> position_icon = TileSetEditor::get_singleton()->get_theme_icon("EditorPosition", "EditorIcons"); - p_canvas_item->draw_texture(position_icon, p_transform.xform(Vector2(value)) - position_icon->get_size() / 2); + p_canvas_item->draw_texture(position_icon, p_transform.xform(Vector2(value)) - position_icon->get_size() / 2, color); } -void TileDataYSortEditor::draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileSet *p_tile_set, int p_atlas_source_id, Vector2i p_atlas_coords, int p_alternative_tile, String p_property) { - TileData *tile_data = _get_tile_data(p_tile_set, p_atlas_source_id, p_atlas_coords, p_alternative_tile); +void TileDataYSortEditor::draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileMapCell p_cell, bool p_selected) { + TileData *tile_data = _get_tile_data(p_cell); ERR_FAIL_COND(!tile_data); - bool valid; - Variant value = tile_data->get(p_property, &valid); - if (!valid) { - return; + Color color = Color(1.0, 1.0, 1.0); + if (p_selected) { + Color grid_color = EditorSettings::get_singleton()->get("editors/tiles_editor/grid_color"); + Color selection_color = Color().from_hsv(Math::fposmod(grid_color.get_h() + 0.5, 1.0), grid_color.get_s(), grid_color.get_v(), 1.0); + color = selection_color; } - ERR_FAIL_COND(value.get_type() != Variant::INT); - Ref<Texture2D> position_icon = TileSetEditor::get_singleton()->get_theme_icon("EditorPosition", "EditorIcons"); - p_canvas_item->draw_texture(position_icon, p_transform.xform(Vector2(0, value)) - position_icon->get_size() / 2); + p_canvas_item->draw_texture(position_icon, p_transform.xform(Vector2(0, tile_data->get_y_sort_origin())) - position_icon->get_size() / 2, color); } -void TileDataOcclusionShapeEditor::draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileSet *p_tile_set, int p_atlas_source_id, Vector2i p_atlas_coords, int p_alternative_tile, String p_property) { - TileData *tile_data = _get_tile_data(p_tile_set, p_atlas_source_id, p_atlas_coords, p_alternative_tile); +void TileDataOcclusionShapeEditor::draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileMapCell p_cell, bool p_selected) { + TileData *tile_data = _get_tile_data(p_cell); ERR_FAIL_COND(!tile_data); - Vector<String> components = String(p_property).split("/", true); - if (components[0].begins_with("occlusion_layer_") && components[0].trim_prefix("occlusion_layer_").is_valid_int()) { - int occlusion_layer = components[0].trim_prefix("occlusion_layer_").to_int(); - if (occlusion_layer >= 0 && occlusion_layer < p_tile_set->get_occlusion_layers_count()) { - // Draw all shapes. - Vector<Color> debug_occlusion_color; - debug_occlusion_color.push_back(Color(0.5, 0, 0, 0.6)); + Color grid_color = EditorSettings::get_singleton()->get("editors/tiles_editor/grid_color"); + Color selection_color = Color().from_hsv(Math::fposmod(grid_color.get_h() + 0.5, 1.0), grid_color.get_s(), grid_color.get_v(), 1.0); + Color color = grid_color.darkened(0.2); + if (p_selected) { + color = selection_color.darkened(0.2); + } + color.a *= 0.5; - RenderingServer::get_singleton()->canvas_item_add_set_transform(p_canvas_item->get_canvas_item(), p_transform); - Ref<OccluderPolygon2D> occluder = tile_data->get_occluder(occlusion_layer); - if (occluder.is_valid() && occluder->get_polygon().size() >= 3) { - p_canvas_item->draw_polygon(Variant(occluder->get_polygon()), debug_occlusion_color); - } - RenderingServer::get_singleton()->canvas_item_add_set_transform(p_canvas_item->get_canvas_item(), Transform2D()); + Vector<Color> debug_occlusion_color; + debug_occlusion_color.push_back(color); + + RenderingServer::get_singleton()->canvas_item_add_set_transform(p_canvas_item->get_canvas_item(), p_transform); + Ref<OccluderPolygon2D> occluder = tile_data->get_occluder(occlusion_layer); + if (occluder.is_valid() && occluder->get_polygon().size() >= 3) { + p_canvas_item->draw_polygon(Variant(occluder->get_polygon()), debug_occlusion_color); + } + RenderingServer::get_singleton()->canvas_item_add_set_transform(p_canvas_item->get_canvas_item(), Transform2D()); +} + +Variant TileDataOcclusionShapeEditor::_get_painted_value() { + Ref<OccluderPolygon2D> occluder_polygon; + occluder_polygon.instantiate(); + if (polygon_editor->get_polygon_count() >= 1) { + occluder_polygon->set_polygon(polygon_editor->get_polygon(0)); + } + return occluder_polygon; +} + +void TileDataOcclusionShapeEditor::_set_painted_value(TileSetAtlasSource *p_tile_set_atlas_source, Vector2 p_coords, int p_alternative_tile) { + TileData *tile_data = Object::cast_to<TileData>(p_tile_set_atlas_source->get_tile_data(p_coords, p_alternative_tile)); + ERR_FAIL_COND(!tile_data); + + Ref<OccluderPolygon2D> occluder_polygon = tile_data->get_occluder(occlusion_layer); + polygon_editor->clear_polygons(); + if (occluder_polygon.is_valid()) { + polygon_editor->add_polygon(occluder_polygon->get_polygon()); + } + polygon_editor->set_background(p_tile_set_atlas_source->get_texture(), p_tile_set_atlas_source->get_tile_texture_region(p_coords), p_tile_set_atlas_source->get_tile_effective_texture_offset(p_coords, p_alternative_tile), tile_data->get_flip_h(), tile_data->get_flip_v(), tile_data->get_transpose(), tile_data->get_modulate()); +} + +void TileDataOcclusionShapeEditor::_set_value(TileSetAtlasSource *p_tile_set_atlas_source, Vector2 p_coords, int p_alternative_tile, Variant p_value) { + TileData *tile_data = Object::cast_to<TileData>(p_tile_set_atlas_source->get_tile_data(p_coords, p_alternative_tile)); + ERR_FAIL_COND(!tile_data); + Ref<OccluderPolygon2D> occluder_polygon = p_value; + tile_data->set_occluder(occlusion_layer, occluder_polygon); + + polygon_editor->set_background(p_tile_set_atlas_source->get_texture(), p_tile_set_atlas_source->get_tile_texture_region(p_coords), p_tile_set_atlas_source->get_tile_effective_texture_offset(p_coords, p_alternative_tile), tile_data->get_flip_h(), tile_data->get_flip_v(), tile_data->get_transpose(), tile_data->get_modulate()); +} + +Variant TileDataOcclusionShapeEditor::_get_value(TileSetAtlasSource *p_tile_set_atlas_source, Vector2 p_coords, int p_alternative_tile) { + TileData *tile_data = Object::cast_to<TileData>(p_tile_set_atlas_source->get_tile_data(p_coords, p_alternative_tile)); + ERR_FAIL_COND_V(!tile_data, Variant()); + return tile_data->get_occluder(occlusion_layer); +} + +void TileDataOcclusionShapeEditor::_setup_undo_redo_action(TileSetAtlasSource *p_tile_set_atlas_source, Map<TileMapCell, Variant> p_previous_values, Variant p_new_value) { + for (Map<TileMapCell, Variant>::Element *E = p_previous_values.front(); E; E = E->next()) { + Vector2i coords = E->key().get_atlas_coords(); + undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/occlusion_layer_%d/polygon", coords.x, coords.y, E->key().alternative_tile, occlusion_layer), E->get()); + undo_redo->add_do_property(p_tile_set_atlas_source, vformat("%d:%d/%d/occlusion_layer_%d/polygon", coords.x, coords.y, E->key().alternative_tile, occlusion_layer), p_new_value); + } +} + +void TileDataOcclusionShapeEditor::_tile_set_changed() { + polygon_editor->set_tile_set(tile_set); +} + +void TileDataOcclusionShapeEditor::_notification(int p_what) { + switch (p_what) { + case NOTIFICATION_ENTER_TREE: + polygon_editor->set_polygons_color(get_tree()->get_debug_collisions_color()); + break; + default: + break; + } +} + +TileDataOcclusionShapeEditor::TileDataOcclusionShapeEditor() { + polygon_editor = memnew(GenericTilePolygonEditor); + add_child(polygon_editor); +} + +void TileDataCollisionEditor::_property_value_changed(StringName p_property, Variant p_value, StringName p_field) { + dummy_object->set(p_property, p_value); +} + +void TileDataCollisionEditor::_polygons_changed() { + // Update the dummy object properties and their editors. + for (int i = 0; i < polygon_editor->get_polygon_count(); i++) { + StringName one_way_property = vformat("polygon_%d_one_way", i); + StringName one_way_margin_property = vformat("polygon_%d_one_way_margin", i); + + if (!dummy_object->has_dummy_property(one_way_property)) { + dummy_object->add_dummy_property(one_way_property); + dummy_object->set(one_way_property, false); } + + if (!dummy_object->has_dummy_property(one_way_margin_property)) { + dummy_object->add_dummy_property(one_way_margin_property); + dummy_object->set(one_way_margin_property, 1.0); + } + + if (!property_editors.has(one_way_property)) { + EditorProperty *one_way_property_editor = EditorInspectorDefaultPlugin::get_editor_for_property(dummy_object, Variant::BOOL, one_way_property, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT); + one_way_property_editor->set_object_and_property(dummy_object, one_way_property); + one_way_property_editor->set_label(one_way_property); + one_way_property_editor->connect("property_changed", callable_mp(this, &TileDataCollisionEditor::_property_value_changed).unbind(1)); + one_way_property_editor->update_property(); + add_child(one_way_property_editor); + property_editors[one_way_property] = one_way_property_editor; + } + + if (!property_editors.has(one_way_margin_property)) { + EditorProperty *one_way_margin_property_editor = EditorInspectorDefaultPlugin::get_editor_for_property(dummy_object, Variant::FLOAT, one_way_margin_property, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT); + one_way_margin_property_editor->set_object_and_property(dummy_object, one_way_margin_property); + one_way_margin_property_editor->set_label(one_way_margin_property); + one_way_margin_property_editor->connect("property_changed", callable_mp(this, &TileDataCollisionEditor::_property_value_changed).unbind(1)); + one_way_margin_property_editor->update_property(); + add_child(one_way_margin_property_editor); + property_editors[one_way_margin_property] = one_way_margin_property_editor; + } + } + + // Remove uneeded properties and their editors. + for (int i = polygon_editor->get_polygon_count(); dummy_object->has_dummy_property(vformat("polygon_%d_one_way", i)); i++) { + dummy_object->remove_dummy_property(vformat("polygon_%d_one_way", i)); + } + for (int i = polygon_editor->get_polygon_count(); dummy_object->has_dummy_property(vformat("polygon_%d_one_way_margin", i)); i++) { + dummy_object->remove_dummy_property(vformat("polygon_%d_one_way_margin", i)); + } + for (int i = polygon_editor->get_polygon_count(); property_editors.has(vformat("polygon_%d_one_way", i)); i++) { + property_editors[vformat("polygon_%d_one_way", i)]->queue_delete(); + property_editors.erase(vformat("polygon_%d_one_way", i)); } + for (int i = polygon_editor->get_polygon_count(); property_editors.has(vformat("polygon_%d_one_way_margin", i)); i++) { + property_editors[vformat("polygon_%d_one_way_margin", i)]->queue_delete(); + property_editors.erase(vformat("polygon_%d_one_way_margin", i)); + } +} + +Variant TileDataCollisionEditor::_get_painted_value() { + Array array; + for (int i = 0; i < polygon_editor->get_polygon_count(); i++) { + ERR_FAIL_COND_V(polygon_editor->get_polygon(i).size() < 3, Variant()); + Dictionary dict; + dict["points"] = polygon_editor->get_polygon(i); + dict["one_way"] = dummy_object->get(vformat("polygon_%d_one_way", i)); + dict["one_way_margin"] = dummy_object->get(vformat("polygon_%d_one_way_margin", i)); + array.push_back(dict); + } + + return array; } -void TileDataCollisionShapeEditor::draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileSet *p_tile_set, int p_atlas_source_id, Vector2i p_atlas_coords, int p_alternative_tile, String p_property) { - TileData *tile_data = _get_tile_data(p_tile_set, p_atlas_source_id, p_atlas_coords, p_alternative_tile); +void TileDataCollisionEditor::_set_painted_value(TileSetAtlasSource *p_tile_set_atlas_source, Vector2 p_coords, int p_alternative_tile) { + TileData *tile_data = Object::cast_to<TileData>(p_tile_set_atlas_source->get_tile_data(p_coords, p_alternative_tile)); ERR_FAIL_COND(!tile_data); - Vector<String> components = String(p_property).split("/", true); - if (components[0].begins_with("physics_layer_") && components[0].trim_prefix("physics_layer_").is_valid_int()) { - int physics_layer = components[0].trim_prefix("physics_layer_").to_int(); - if (physics_layer >= 0 && physics_layer < p_tile_set->get_physics_layers_count()) { - // Draw all shapes. - Color debug_collision_color = p_canvas_item->get_tree()->get_debug_collisions_color(); - RenderingServer::get_singleton()->canvas_item_add_set_transform(p_canvas_item->get_canvas_item(), p_transform); - for (int i = 0; i < tile_data->get_collision_shapes_count(physics_layer); i++) { - Ref<Shape2D> shape = tile_data->get_collision_shape_shape(physics_layer, i); - if (shape.is_valid()) { - shape->draw(p_canvas_item->get_canvas_item(), debug_collision_color); - } - } - RenderingServer::get_singleton()->canvas_item_add_set_transform(p_canvas_item->get_canvas_item(), Transform2D()); + polygon_editor->clear_polygons(); + for (int i = 0; i < tile_data->get_collision_polygons_count(physics_layer); i++) { + Vector<Vector2> polygon = tile_data->get_collision_polygon_points(physics_layer, i); + if (polygon.size() >= 3) { + polygon_editor->add_polygon(polygon); } } + + _polygons_changed(); + for (int i = 0; i < tile_data->get_collision_polygons_count(physics_layer); i++) { + dummy_object->set(vformat("polygon_%d_one_way", i), tile_data->is_collision_polygon_one_way(physics_layer, i)); + dummy_object->set(vformat("polygon_%d_one_way_margin", i), tile_data->get_collision_polygon_one_way_margin(physics_layer, i)); + } + for (Map<StringName, EditorProperty *>::Element *E = property_editors.front(); E; E = E->next()) { + E->get()->update_property(); + } + + polygon_editor->set_background(p_tile_set_atlas_source->get_texture(), p_tile_set_atlas_source->get_tile_texture_region(p_coords), p_tile_set_atlas_source->get_tile_effective_texture_offset(p_coords, p_alternative_tile), tile_data->get_flip_h(), tile_data->get_flip_v(), tile_data->get_transpose(), tile_data->get_modulate()); } -void TileDataTerrainsEditor::draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileSet *p_tile_set, int p_atlas_source_id, Vector2i p_atlas_coords, int p_alternative_tile, String p_property) { - TileData *tile_data = _get_tile_data(p_tile_set, p_atlas_source_id, p_atlas_coords, p_alternative_tile); +void TileDataCollisionEditor::_set_value(TileSetAtlasSource *p_tile_set_atlas_source, Vector2 p_coords, int p_alternative_tile, Variant p_value) { + TileData *tile_data = Object::cast_to<TileData>(p_tile_set_atlas_source->get_tile_data(p_coords, p_alternative_tile)); ERR_FAIL_COND(!tile_data); - Vector<String> components = String(p_property).split("/", true); - if (components[0] == "terrain_mode" || components[0] == "terrain" || components[0] == "terrains_peering_bit") { - TileSetPluginAtlasTerrain::draw_terrains(p_canvas_item, p_transform, p_tile_set, tile_data); + Array array = p_value; + tile_data->set_collision_polygons_count(physics_layer, array.size()); + for (int i = 0; i < array.size(); i++) { + Dictionary dict = array[i]; + tile_data->set_collision_polygon_points(physics_layer, i, dict["points"]); + tile_data->set_collision_polygon_one_way(physics_layer, i, dict["one_way"]); + tile_data->set_collision_polygon_one_way_margin(physics_layer, i, dict["one_way_margin"]); + } + + polygon_editor->set_background(p_tile_set_atlas_source->get_texture(), p_tile_set_atlas_source->get_tile_texture_region(p_coords), p_tile_set_atlas_source->get_tile_effective_texture_offset(p_coords, p_alternative_tile), tile_data->get_flip_h(), tile_data->get_flip_v(), tile_data->get_transpose(), tile_data->get_modulate()); +} + +Variant TileDataCollisionEditor::_get_value(TileSetAtlasSource *p_tile_set_atlas_source, Vector2 p_coords, int p_alternative_tile) { + TileData *tile_data = Object::cast_to<TileData>(p_tile_set_atlas_source->get_tile_data(p_coords, p_alternative_tile)); + ERR_FAIL_COND_V(!tile_data, Variant()); + + Array array; + for (int i = 0; i < tile_data->get_collision_polygons_count(physics_layer); i++) { + Dictionary dict; + dict["points"] = tile_data->get_collision_polygon_points(physics_layer, i); + dict["one_way"] = tile_data->is_collision_polygon_one_way(physics_layer, i); + dict["one_way_margin"] = tile_data->get_collision_polygon_one_way_margin(physics_layer, i); + array.push_back(dict); + } + return array; +} + +void TileDataCollisionEditor::_setup_undo_redo_action(TileSetAtlasSource *p_tile_set_atlas_source, Map<TileMapCell, Variant> p_previous_values, Variant p_new_value) { + Array new_array = p_new_value; + for (Map<TileMapCell, Variant>::Element *E = p_previous_values.front(); E; E = E->next()) { + Array old_array = E->get(); + + Vector2i coords = E->key().get_atlas_coords(); + undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/physics_layer_%d/polygons_count", coords.x, coords.y, E->key().alternative_tile, physics_layer), old_array.size()); + for (int i = 0; i < old_array.size(); i++) { + Dictionary dict = old_array[i]; + undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/physics_layer_%d/polygon_%d/points", coords.x, coords.y, E->key().alternative_tile, physics_layer, i), dict["points"]); + undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/physics_layer_%d/polygon_%d/one_way", coords.x, coords.y, E->key().alternative_tile, physics_layer, i), dict["one_way"]); + undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/physics_layer_%d/polygon_%d/one_way_margin", coords.x, coords.y, E->key().alternative_tile, physics_layer, i), dict["one_way_margin"]); + } + + undo_redo->add_do_property(p_tile_set_atlas_source, vformat("%d:%d/%d/physics_layer_%d/polygons_count", coords.x, coords.y, E->key().alternative_tile, physics_layer), new_array.size()); + for (int i = 0; i < new_array.size(); i++) { + Dictionary dict = new_array[i]; + undo_redo->add_do_property(p_tile_set_atlas_source, vformat("%d:%d/%d/physics_layer_%d/polygon_%d/points", coords.x, coords.y, E->key().alternative_tile, physics_layer, i), dict["points"]); + undo_redo->add_do_property(p_tile_set_atlas_source, vformat("%d:%d/%d/physics_layer_%d/polygon_%d/one_way", coords.x, coords.y, E->key().alternative_tile, physics_layer, i), dict["one_way"]); + undo_redo->add_do_property(p_tile_set_atlas_source, vformat("%d:%d/%d/physics_layer_%d/polygon_%d/one_way_margin", coords.x, coords.y, E->key().alternative_tile, physics_layer, i), dict["one_way_margin"]); + } + } +} + +void TileDataCollisionEditor::_tile_set_changed() { + polygon_editor->set_tile_set(tile_set); + _polygons_changed(); +} + +void TileDataCollisionEditor::_notification(int p_what) { + switch (p_what) { + case NOTIFICATION_ENTER_TREE: + polygon_editor->set_polygons_color(get_tree()->get_debug_collisions_color()); + break; + default: + break; } } -void TileDataNavigationPolygonEditor::draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileSet *p_tile_set, int p_atlas_source_id, Vector2i p_atlas_coords, int p_alternative_tile, String p_property) { - TileData *tile_data = _get_tile_data(p_tile_set, p_atlas_source_id, p_atlas_coords, p_alternative_tile); +TileDataCollisionEditor::TileDataCollisionEditor() { + polygon_editor = memnew(GenericTilePolygonEditor); + polygon_editor->set_multiple_polygon_mode(true); + polygon_editor->connect("polygons_changed", callable_mp(this, &TileDataCollisionEditor::_polygons_changed)); + add_child(polygon_editor); + + _polygons_changed(); +} + +TileDataCollisionEditor::~TileDataCollisionEditor() { + memdelete(dummy_object); +} + +void TileDataCollisionEditor::draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileMapCell p_cell, bool p_selected) { + TileData *tile_data = _get_tile_data(p_cell); ERR_FAIL_COND(!tile_data); - Vector<String> components = String(p_property).split("/", true); - if (components[0].begins_with("navigation_layer_") && components[0].trim_prefix("navigation_layer_").is_valid_int()) { - int navigation_layer = components[0].trim_prefix("navigation_layer_").to_int(); - if (navigation_layer >= 0 && navigation_layer < p_tile_set->get_navigation_layers_count()) { - // Draw all shapes. - RenderingServer::get_singleton()->canvas_item_add_set_transform(p_canvas_item->get_canvas_item(), p_transform); + // Draw all shapes. + Vector<Color> color; + if (p_selected) { + Color grid_color = EditorSettings::get_singleton()->get("editors/tiles_editor/grid_color"); + Color selection_color = Color().from_hsv(Math::fposmod(grid_color.get_h() + 0.5, 1.0), grid_color.get_s(), grid_color.get_v(), 1.0); + selection_color.a = 0.7; + color.push_back(selection_color); + } else { + Color debug_collision_color = p_canvas_item->get_tree()->get_debug_collisions_color(); + color.push_back(debug_collision_color); + } + + RenderingServer::get_singleton()->canvas_item_add_set_transform(p_canvas_item->get_canvas_item(), p_transform); + for (int i = 0; i < tile_data->get_collision_polygons_count(physics_layer); i++) { + Vector<Vector2> polygon = tile_data->get_collision_polygon_points(physics_layer, i); + if (polygon.size() >= 3) { + p_canvas_item->draw_polygon(polygon, color); + } + } + RenderingServer::get_singleton()->canvas_item_add_set_transform(p_canvas_item->get_canvas_item(), Transform2D()); +} + +void TileDataTerrainsEditor::_update_terrain_selector() { + ERR_FAIL_COND(!tile_set.is_valid()); + + // Update the terrain set selector. + Vector<String> options; + options.push_back(String(TTR("No terrains")) + String(":-1")); + for (int i = 0; i < tile_set->get_terrain_sets_count(); i++) { + options.push_back(vformat("Terrain Set %d", i)); + } + terrain_set_property_editor->setup(options); + terrain_set_property_editor->update_property(); + + // Update the terrain selector. + int terrain_set = int(dummy_object->get("terrain_set")); + if (terrain_set == -1) { + terrain_property_editor->hide(); + } else { + options.clear(); + Vector<Vector<Ref<Texture2D>>> icons = tile_set->generate_terrains_icons(Size2(16, 16) * EDSCALE); + options.push_back(String(TTR("No terrain")) + String(":-1")); + for (int i = 0; i < tile_set->get_terrains_count(terrain_set); i++) { + String name = tile_set->get_terrain_name(terrain_set, i); + if (name.is_empty()) { + options.push_back(vformat("Terrain %d", i)); + } else { + options.push_back(name); + } + } + terrain_property_editor->setup(options); + terrain_property_editor->update_property(); + + // Kind of a hack to set icons. + // We could provide a way to modify that in the EditorProperty. + OptionButton *option_button = Object::cast_to<OptionButton>(terrain_property_editor->get_child(0)); + for (int terrain = 0; terrain < tile_set->get_terrains_count(terrain_set); terrain++) { + option_button->set_item_icon(terrain + 1, icons[terrain_set][terrain]); + } + terrain_property_editor->show(); + } +} + +void TileDataTerrainsEditor::_property_value_changed(StringName p_property, Variant p_value, StringName p_field) { + Variant old_value = dummy_object->get(p_property); + dummy_object->set(p_property, p_value); + if (p_property == "terrain_set") { + if (p_value != old_value) { + dummy_object->set("terrain", -1); + } + _update_terrain_selector(); + } + emit_signal("needs_redraw"); +} + +void TileDataTerrainsEditor::_tile_set_changed() { + ERR_FAIL_COND(!tile_set.is_valid()); + + // Fix if wrong values are selected. + if (int(dummy_object->get("terrain_set")) > tile_set->get_terrain_sets_count()) { + dummy_object->set("terrain_set", -1); + } + int terrain_set = int(dummy_object->get("terrain")); + if (terrain_set >= 0) { + if (int(dummy_object->get("terrain")) > tile_set->get_terrains_count(terrain_set)) { + dummy_object->set("terrain", -1); + } + } + + _update_terrain_selector(); +} + +void TileDataTerrainsEditor::forward_draw_over_atlas(TileAtlasView *p_tile_atlas_view, TileSetAtlasSource *p_tile_set_atlas_source, CanvasItem *p_canvas_item, Transform2D p_transform) { + ERR_FAIL_COND(!tile_set.is_valid()); - Ref<NavigationPolygon> navigation_polygon = tile_data->get_navigation_polygon(navigation_layer); - if (navigation_polygon.is_valid()) { - Vector<Vector2> verts = navigation_polygon->get_vertices(); - if (verts.size() < 3) { - return; + // Draw the hovered terrain bit, or the whole tile if it has the wrong terrain set. + Vector2i hovered_coords = TileSetSource::INVALID_ATLAS_COORDS; + if (drag_type == DRAG_TYPE_NONE) { + Vector2i mouse_pos = p_transform.affine_inverse().xform(p_canvas_item->get_local_mouse_position()); + hovered_coords = p_tile_atlas_view->get_atlas_tile_coords_at_pos(mouse_pos); + hovered_coords = p_tile_set_atlas_source->get_tile_at_coords(hovered_coords); + if (hovered_coords != TileSetSource::INVALID_ATLAS_COORDS) { + TileData *tile_data = Object::cast_to<TileData>(p_tile_set_atlas_source->get_tile_data(hovered_coords, 0)); + int terrain_set = tile_data->get_terrain_set(); + Rect2i texture_region = p_tile_set_atlas_source->get_tile_texture_region(hovered_coords); + Vector2i position = (texture_region.position + texture_region.get_end()) / 2 + p_tile_set_atlas_source->get_tile_effective_texture_offset(hovered_coords, 0); + + if (terrain_set >= 0 && terrain_set == int(dummy_object->get("terrain_set"))) { + // Draw hovered bit. + Transform2D xform; + xform.set_origin(position); + + Vector<Color> color; + color.push_back(Color(1.0, 1.0, 1.0, 0.5)); + + for (int i = 0; i < TileSet::CELL_NEIGHBOR_MAX; i++) { + TileSet::CellNeighbor bit = TileSet::CellNeighbor(i); + if (tile_set->is_valid_peering_bit_terrain(terrain_set, bit)) { + Vector<Vector2> polygon = tile_set->get_terrain_bit_polygon(terrain_set, bit); + if (Geometry2D::is_point_in_polygon(xform.affine_inverse().xform(mouse_pos), polygon)) { + p_canvas_item->draw_set_transform_matrix(p_transform * xform); + p_canvas_item->draw_polygon(polygon, color); + } + } } + } else { + // Draw hovered tile. + Vector2i tile_size = tile_set->get_tile_size(); + Rect2i rect = p_transform.xform(Rect2i(position - tile_size / 2, tile_size)); + tile_set->draw_tile_shape(p_canvas_item, rect, Color(1.0, 1.0, 1.0, 0.5), true); + } + } + } + + // Dim terrains with wrong terrain set. + Ref<Font> font = TileSetEditor::get_singleton()->get_theme_font("bold", "EditorFonts"); + for (int i = 0; i < p_tile_set_atlas_source->get_tiles_count(); i++) { + Vector2i coords = p_tile_set_atlas_source->get_tile_id(i); + if (coords != hovered_coords) { + TileData *tile_data = Object::cast_to<TileData>(p_tile_set_atlas_source->get_tile_data(coords, 0)); + if (tile_data->get_terrain_set() != int(dummy_object->get("terrain_set"))) { + // Dimming + p_canvas_item->draw_set_transform_matrix(p_transform); + Rect2i rect = p_tile_set_atlas_source->get_tile_texture_region(coords); + p_canvas_item->draw_rect(rect, Color(0.0, 0.0, 0.0, 0.3)); + + // Text + p_canvas_item->draw_set_transform_matrix(Transform2D()); + Rect2i texture_region = p_tile_set_atlas_source->get_tile_texture_region(coords); + Vector2i position = (texture_region.position + texture_region.get_end()) / 2 + p_tile_set_atlas_source->get_tile_effective_texture_offset(coords, 0); + + Color color = Color(1, 1, 1); + String text; + if (tile_data->get_terrain_set() >= 0) { + text = vformat("%d", tile_data->get_terrain_set()); + } else { + text = "-"; + } + Vector2 string_size = font->get_string_size(text); + p_canvas_item->draw_string(font, p_transform.xform(position) + Vector2i(-string_size.x / 2, string_size.y / 2), text, HALIGN_CENTER, string_size.x, -1, color, 1, Color(0, 0, 0, 1)); + } + } + } + p_canvas_item->draw_set_transform_matrix(Transform2D()); + + if (drag_type == DRAG_TYPE_PAINT_TERRAIN_SET_RECT) { + // Draw selection rectangle. + Color grid_color = EditorSettings::get_singleton()->get("editors/tiles_editor/grid_color"); + Color selection_color = Color().from_hsv(Math::fposmod(grid_color.get_h() + 0.5, 1.0), grid_color.get_s(), grid_color.get_v(), 1.0); + + p_canvas_item->draw_set_transform_matrix(p_transform); - Color color = p_canvas_item->get_tree()->get_debug_navigation_color(); + Rect2i rect; + rect.set_position(p_tile_atlas_view->get_atlas_tile_coords_at_pos(drag_start_pos)); + rect.set_end(p_tile_atlas_view->get_atlas_tile_coords_at_pos(p_transform.affine_inverse().xform(p_canvas_item->get_local_mouse_position()))); + rect = rect.abs(); - RandomPCG rand; - for (int i = 0; i < navigation_polygon->get_polygon_count(); i++) { - // An array of vertices for this polygon. - Vector<int> polygon = navigation_polygon->get_polygon(i); - Vector<Vector2> vertices; - vertices.resize(polygon.size()); + Set<TileMapCell> edited; + for (int x = rect.get_position().x; x <= rect.get_end().x; x++) { + for (int y = rect.get_position().y; y <= rect.get_end().y; y++) { + Vector2i coords = Vector2i(x, y); + coords = p_tile_set_atlas_source->get_tile_at_coords(coords); + if (coords != TileSetSource::INVALID_ATLAS_COORDS) { + TileMapCell cell; + cell.source_id = 0; + cell.set_atlas_coords(coords); + cell.alternative_tile = 0; + edited.insert(cell); + } + } + } + + for (Set<TileMapCell>::Element *E = edited.front(); E; E = E->next()) { + Vector2i coords = E->get().get_atlas_coords(); + p_canvas_item->draw_rect(p_tile_set_atlas_source->get_tile_texture_region(coords), selection_color, false); + } + p_canvas_item->draw_set_transform_matrix(Transform2D()); + } else if (drag_type == DRAG_TYPE_PAINT_TERRAIN_BITS_RECT) { + // Highlight selected peering bits. + Dictionary painted = Dictionary(drag_painted_value); + int terrain_set = int(painted["terrain_set"]); + + Rect2i rect; + rect.set_position(p_tile_atlas_view->get_atlas_tile_coords_at_pos(drag_start_pos)); + rect.set_end(p_tile_atlas_view->get_atlas_tile_coords_at_pos(p_transform.affine_inverse().xform(p_canvas_item->get_local_mouse_position()))); + rect = rect.abs(); + + Set<TileMapCell> edited; + for (int x = rect.get_position().x; x <= rect.get_end().x; x++) { + for (int y = rect.get_position().y; y <= rect.get_end().y; y++) { + Vector2i coords = Vector2i(x, y); + coords = p_tile_set_atlas_source->get_tile_at_coords(coords); + if (coords != TileSetSource::INVALID_ATLAS_COORDS) { + TileData *tile_data = Object::cast_to<TileData>(p_tile_set_atlas_source->get_tile_data(coords, 0)); + if (tile_data->get_terrain_set() == terrain_set) { + TileMapCell cell; + cell.source_id = 0; + cell.set_atlas_coords(coords); + cell.alternative_tile = 0; + edited.insert(cell); + } + } + } + } + + Vector2 end = p_transform.affine_inverse().xform(p_canvas_item->get_local_mouse_position()); + Vector<Point2> mouse_pos_rect_polygon; + mouse_pos_rect_polygon.push_back(drag_start_pos); + mouse_pos_rect_polygon.push_back(Vector2(end.x, drag_start_pos.y)); + mouse_pos_rect_polygon.push_back(end); + mouse_pos_rect_polygon.push_back(Vector2(drag_start_pos.x, end.y)); + + Vector<Color> color; + color.push_back(Color(1.0, 1.0, 1.0, 0.5)); + + p_canvas_item->draw_set_transform_matrix(p_transform); + + for (Set<TileMapCell>::Element *E = edited.front(); E; E = E->next()) { + Vector2i coords = E->get().get_atlas_coords(); + + Rect2i texture_region = p_tile_set_atlas_source->get_tile_texture_region(coords); + Vector2i position = (texture_region.position + texture_region.get_end()) / 2 + p_tile_set_atlas_source->get_tile_effective_texture_offset(coords, 0); + + for (int i = 0; i < TileSet::CELL_NEIGHBOR_MAX; i++) { + TileSet::CellNeighbor bit = TileSet::CellNeighbor(i); + if (tile_set->is_valid_peering_bit_terrain(terrain_set, bit)) { + Vector<Vector2> polygon = tile_set->get_terrain_bit_polygon(terrain_set, bit); for (int j = 0; j < polygon.size(); j++) { - ERR_FAIL_INDEX(polygon[j], verts.size()); - vertices.write[j] = verts[polygon[j]]; + polygon.write[j] += position; + } + if (!Geometry2D::intersect_polygons(polygon, mouse_pos_rect_polygon).is_empty()) { + // Draw bit. + p_canvas_item->draw_polygon(polygon, color); + } + } + } + } + + p_canvas_item->draw_set_transform_matrix(Transform2D()); + } +} + +void TileDataTerrainsEditor::forward_draw_over_alternatives(TileAtlasView *p_tile_atlas_view, TileSetAtlasSource *p_tile_set_atlas_source, CanvasItem *p_canvas_item, Transform2D p_transform) { + ERR_FAIL_COND(!tile_set.is_valid()); + + // Draw the hovered terrain bit, or the whole tile if it has the wrong terrain set. + Vector2i hovered_coords = TileSetSource::INVALID_ATLAS_COORDS; + int hovered_alternative = TileSetSource::INVALID_TILE_ALTERNATIVE; + if (drag_type == DRAG_TYPE_NONE) { + Vector2i mouse_pos = p_transform.affine_inverse().xform(p_canvas_item->get_local_mouse_position()); + Vector3i hovered = p_tile_atlas_view->get_alternative_tile_at_pos(mouse_pos); + hovered_coords = Vector2i(hovered.x, hovered.y); + hovered_alternative = hovered.z; + if (hovered_coords != TileSetSource::INVALID_ATLAS_COORDS) { + TileData *tile_data = Object::cast_to<TileData>(p_tile_set_atlas_source->get_tile_data(hovered_coords, hovered_alternative)); + int terrain_set = tile_data->get_terrain_set(); + Rect2i texture_region = p_tile_atlas_view->get_alternative_tile_rect(hovered_coords, hovered_alternative); + Vector2i position = (texture_region.position + texture_region.get_end()) / 2 + p_tile_set_atlas_source->get_tile_effective_texture_offset(hovered_coords, hovered_alternative); + + if (terrain_set == int(dummy_object->get("terrain_set"))) { + // Draw hovered bit. + Transform2D xform; + xform.set_origin(position); + + Vector<Color> color; + color.push_back(Color(1.0, 1.0, 1.0, 0.5)); + + for (int i = 0; i < TileSet::CELL_NEIGHBOR_MAX; i++) { + TileSet::CellNeighbor bit = TileSet::CellNeighbor(i); + if (tile_set->is_valid_peering_bit_terrain(terrain_set, bit)) { + Vector<Vector2> polygon = tile_set->get_terrain_bit_polygon(terrain_set, bit); + if (Geometry2D::is_point_in_polygon(xform.affine_inverse().xform(mouse_pos), polygon)) { + p_canvas_item->draw_set_transform_matrix(p_transform * xform); + p_canvas_item->draw_polygon(polygon, color); + } + } + } + } else { + // Draw hovered tile. + Vector2i tile_size = tile_set->get_tile_size(); + Rect2i rect = p_transform.xform(Rect2i(position - tile_size / 2, tile_size)); + tile_set->draw_tile_shape(p_canvas_item, rect, Color(1.0, 1.0, 1.0, 0.5), true); + } + } + } + + // Dim terrains with wrong terrain set. + Ref<Font> font = TileSetEditor::get_singleton()->get_theme_font("bold", "EditorFonts"); + for (int i = 0; i < p_tile_set_atlas_source->get_tiles_count(); i++) { + Vector2i coords = p_tile_set_atlas_source->get_tile_id(i); + for (int j = 1; j < p_tile_set_atlas_source->get_alternative_tiles_count(coords); j++) { + int alternative_tile = p_tile_set_atlas_source->get_alternative_tile_id(coords, j); + if (coords != hovered_coords || alternative_tile != hovered_alternative) { + TileData *tile_data = Object::cast_to<TileData>(p_tile_set_atlas_source->get_tile_data(coords, alternative_tile)); + if (tile_data->get_terrain_set() != int(dummy_object->get("terrain_set"))) { + // Dimming + p_canvas_item->draw_set_transform_matrix(p_transform); + Rect2i rect = p_tile_atlas_view->get_alternative_tile_rect(coords, alternative_tile); + p_canvas_item->draw_rect(rect, Color(0.0, 0.0, 0.0, 0.3)); + + // Text + p_canvas_item->draw_set_transform_matrix(Transform2D()); + Rect2i texture_region = p_tile_atlas_view->get_alternative_tile_rect(coords, alternative_tile); + Vector2i position = (texture_region.position + texture_region.get_end()) / 2 + p_tile_set_atlas_source->get_tile_effective_texture_offset(coords, 0); + + Color color = Color(1, 1, 1); + String text; + if (tile_data->get_terrain_set() >= 0) { + text = vformat("%d", tile_data->get_terrain_set()); + } else { + text = "-"; + } + Vector2 string_size = font->get_string_size(text); + p_canvas_item->draw_string(font, p_transform.xform(position) + Vector2i(-string_size.x / 2, string_size.y / 2), text, HALIGN_CENTER, string_size.x, -1, color, 1, Color(0, 0, 0, 1)); + } + } + } + } + + p_canvas_item->draw_set_transform_matrix(Transform2D()); +} + +void TileDataTerrainsEditor::forward_painting_atlas_gui_input(TileAtlasView *p_tile_atlas_view, TileSetAtlasSource *p_tile_set_atlas_source, const Ref<InputEvent> &p_event) { + Ref<InputEventMouseMotion> mm = p_event; + if (mm.is_valid()) { + if (drag_type == DRAG_TYPE_PAINT_TERRAIN_SET) { + Vector<Vector2i> line = Geometry2D::bresenham_line(p_tile_atlas_view->get_atlas_tile_coords_at_pos(drag_last_pos), p_tile_atlas_view->get_atlas_tile_coords_at_pos(mm->get_position())); + for (int i = 0; i < line.size(); i++) { + Vector2i coords = p_tile_set_atlas_source->get_tile_at_coords(line[i]); + if (coords != TileSetSource::INVALID_ATLAS_COORDS) { + int terrain_set = drag_painted_value; + TileMapCell cell; + cell.source_id = 0; + cell.set_atlas_coords(coords); + cell.alternative_tile = 0; + + // Save the old terrain_set and terrains bits. + TileData *tile_data = Object::cast_to<TileData>(p_tile_set_atlas_source->get_tile_data(coords, 0)); + if (!drag_modified.has(cell)) { + Dictionary dict; + dict["terrain_set"] = tile_data->get_terrain_set(); + Array array; + for (int j = 0; j < TileSet::CELL_NEIGHBOR_MAX; j++) { + TileSet::CellNeighbor bit = TileSet::CellNeighbor(j); + array.push_back(tile_data->is_valid_peering_bit_terrain(bit) ? tile_data->get_peering_bit_terrain(bit) : -1); + } + dict["terrain_peering_bits"] = array; + drag_modified[cell] = dict; + } + + // Set the terrain_set. + tile_data->set_terrain_set(terrain_set); + } + } + drag_last_pos = mm->get_position(); + } else if (drag_type == DRAG_TYPE_PAINT_TERRAIN_BITS) { + int terrain_set = Dictionary(drag_painted_value)["terrain_set"]; + int terrain = Dictionary(drag_painted_value)["terrain"]; + Vector<Vector2i> line = Geometry2D::bresenham_line(p_tile_atlas_view->get_atlas_tile_coords_at_pos(drag_last_pos), p_tile_atlas_view->get_atlas_tile_coords_at_pos(mm->get_position())); + for (int i = 0; i < line.size(); i++) { + Vector2i coords = p_tile_set_atlas_source->get_tile_at_coords(line[i]); + if (coords != TileSetSource::INVALID_ATLAS_COORDS) { + TileMapCell cell; + cell.source_id = 0; + cell.set_atlas_coords(coords); + cell.alternative_tile = 0; + + TileData *tile_data = Object::cast_to<TileData>(p_tile_set_atlas_source->get_tile_data(coords, 0)); + if (tile_data->get_terrain_set() == terrain_set) { + // Save the old terrain_set and terrains bits. + if (!drag_modified.has(cell)) { + Dictionary dict; + dict["terrain_set"] = tile_data->get_terrain_set(); + Array array; + for (int j = 0; j < TileSet::CELL_NEIGHBOR_MAX; j++) { + TileSet::CellNeighbor bit = TileSet::CellNeighbor(j); + array.push_back(tile_data->is_valid_peering_bit_terrain(bit) ? tile_data->get_peering_bit_terrain(bit) : -1); + } + dict["terrain_peering_bits"] = array; + drag_modified[cell] = dict; + } + + // Set the terrains bits. + Rect2i texture_region = p_tile_set_atlas_source->get_tile_texture_region(coords); + Vector2i position = (texture_region.position + texture_region.get_end()) / 2 + p_tile_set_atlas_source->get_tile_effective_texture_offset(coords, 0); + for (int j = 0; j < TileSet::CELL_NEIGHBOR_MAX; j++) { + TileSet::CellNeighbor bit = TileSet::CellNeighbor(j); + if (tile_data->is_valid_peering_bit_terrain(bit)) { + Vector<Vector2> polygon = tile_set->get_terrain_bit_polygon(tile_data->get_terrain_set(), bit); + if (Geometry2D::is_segment_intersecting_polygon(mm->get_position() - position, drag_last_pos - position, polygon)) { + tile_data->set_peering_bit_terrain(bit, terrain); + } + } + } + } + } + } + drag_last_pos = mm->get_position(); + } + } + + Ref<InputEventMouseButton> mb = p_event; + if (mb.is_valid()) { + if (mb->get_button_index() == MOUSE_BUTTON_LEFT) { + if (mb->is_pressed()) { + if (picker_button->is_pressed()) { + Vector2i coords = p_tile_atlas_view->get_atlas_tile_coords_at_pos(mb->get_position()); + coords = p_tile_set_atlas_source->get_tile_at_coords(coords); + if (coords != TileSetSource::INVALID_ATLAS_COORDS) { + TileData *tile_data = Object::cast_to<TileData>(p_tile_set_atlas_source->get_tile_data(coords, 0)); + int terrain_set = tile_data->get_terrain_set(); + Rect2i texture_region = p_tile_set_atlas_source->get_tile_texture_region(coords); + Vector2i position = (texture_region.position + texture_region.get_end()) / 2 + p_tile_set_atlas_source->get_tile_effective_texture_offset(coords, 0); + dummy_object->set("terrain_set", terrain_set); + dummy_object->set("terrain", -1); + for (int i = 0; i < TileSet::CELL_NEIGHBOR_MAX; i++) { + TileSet::CellNeighbor bit = TileSet::CellNeighbor(i); + if (tile_set->is_valid_peering_bit_terrain(terrain_set, bit)) { + Vector<Vector2> polygon = tile_set->get_terrain_bit_polygon(terrain_set, bit); + if (Geometry2D::is_point_in_polygon(mb->get_position() - position, polygon)) { + dummy_object->set("terrain", tile_data->get_peering_bit_terrain(bit)); + } + } + } + terrain_set_property_editor->update_property(); + _update_terrain_selector(); + picker_button->set_pressed(false); + } + } else { + Vector2i coords = p_tile_atlas_view->get_atlas_tile_coords_at_pos(mb->get_position()); + coords = p_tile_set_atlas_source->get_tile_at_coords(coords); + TileData *tile_data = nullptr; + if (coords != TileSetAtlasSource::INVALID_ATLAS_COORDS) { + tile_data = Object::cast_to<TileData>(p_tile_set_atlas_source->get_tile_data(coords, 0)); + } + int terrain_set = int(dummy_object->get("terrain_set")); + int terrain = int(dummy_object->get("terrain")); + if (terrain_set == -1 || !tile_data || tile_data->get_terrain_set() != terrain_set) { + if (mb->is_ctrl_pressed()) { + // Paint terrain set with rect. + drag_type = DRAG_TYPE_PAINT_TERRAIN_SET_RECT; + drag_modified.clear(); + drag_painted_value = terrain_set; + drag_start_pos = mb->get_position(); + } else { + // Paint terrain set. + drag_type = DRAG_TYPE_PAINT_TERRAIN_SET; + drag_modified.clear(); + drag_painted_value = terrain_set; + + if (coords != TileSetSource::INVALID_ATLAS_COORDS) { + TileMapCell cell; + cell.source_id = 0; + cell.set_atlas_coords(coords); + cell.alternative_tile = 0; + + // Save the old terrain_set and terrains bits. + Dictionary dict; + dict["terrain_set"] = tile_data->get_terrain_set(); + Array array; + for (int i = 0; i < TileSet::CELL_NEIGHBOR_MAX; i++) { + TileSet::CellNeighbor bit = TileSet::CellNeighbor(i); + array.push_back(tile_data->is_valid_peering_bit_terrain(bit) ? tile_data->get_peering_bit_terrain(bit) : -1); + } + dict["terrain_peering_bits"] = array; + drag_modified[cell] = dict; + + // Set the terrain_set. + tile_data->set_terrain_set(terrain_set); + } + drag_last_pos = mb->get_position(); + } + } else if (tile_data && tile_data->get_terrain_set() == terrain_set) { + if (mb->is_ctrl_pressed()) { + // Paint terrain set with rect. + drag_type = DRAG_TYPE_PAINT_TERRAIN_BITS_RECT; + drag_modified.clear(); + Dictionary painted_dict; + painted_dict["terrain_set"] = terrain_set; + painted_dict["terrain"] = terrain; + drag_painted_value = painted_dict; + drag_start_pos = mb->get_position(); + } else { + // Paint terrain bits. + drag_type = DRAG_TYPE_PAINT_TERRAIN_BITS; + drag_modified.clear(); + Dictionary painted_dict; + painted_dict["terrain_set"] = terrain_set; + painted_dict["terrain"] = terrain; + drag_painted_value = painted_dict; + + if (coords != TileSetSource::INVALID_ATLAS_COORDS) { + TileMapCell cell; + cell.source_id = 0; + cell.set_atlas_coords(coords); + cell.alternative_tile = 0; + + // Save the old terrain_set and terrains bits. + Dictionary dict; + dict["terrain_set"] = tile_data->get_terrain_set(); + Array array; + for (int i = 0; i < TileSet::CELL_NEIGHBOR_MAX; i++) { + TileSet::CellNeighbor bit = TileSet::CellNeighbor(i); + array.push_back(tile_data->is_valid_peering_bit_terrain(bit) ? tile_data->get_peering_bit_terrain(bit) : -1); + } + dict["terrain_peering_bits"] = array; + drag_modified[cell] = dict; + + // Set the terrain bit. + Rect2i texture_region = p_tile_set_atlas_source->get_tile_texture_region(coords); + Vector2i position = (texture_region.position + texture_region.get_end()) / 2 + p_tile_set_atlas_source->get_tile_effective_texture_offset(coords, 0); + + for (int i = 0; i < TileSet::CELL_NEIGHBOR_MAX; i++) { + TileSet::CellNeighbor bit = TileSet::CellNeighbor(i); + if (tile_set->is_valid_peering_bit_terrain(terrain_set, bit)) { + Vector<Vector2> polygon = tile_set->get_terrain_bit_polygon(terrain_set, bit); + if (Geometry2D::is_point_in_polygon(mb->get_position() - position, polygon)) { + tile_data->set_peering_bit_terrain(bit, terrain); + } + } + } + } + drag_last_pos = mb->get_position(); + } + } + } + } else { + if (drag_type == DRAG_TYPE_PAINT_TERRAIN_SET_RECT) { + Rect2i rect; + rect.set_position(p_tile_atlas_view->get_atlas_tile_coords_at_pos(drag_start_pos)); + rect.set_end(p_tile_atlas_view->get_atlas_tile_coords_at_pos(mb->get_position())); + rect = rect.abs(); + + Set<TileMapCell> edited; + for (int x = rect.get_position().x; x <= rect.get_end().x; x++) { + for (int y = rect.get_position().y; y <= rect.get_end().y; y++) { + Vector2i coords = Vector2i(x, y); + coords = p_tile_set_atlas_source->get_tile_at_coords(coords); + if (coords != TileSetSource::INVALID_ATLAS_COORDS) { + TileMapCell cell; + cell.source_id = 0; + cell.set_atlas_coords(coords); + cell.alternative_tile = 0; + edited.insert(cell); + } + } + } + undo_redo->create_action(TTR("Painting Terrain Set")); + for (Set<TileMapCell>::Element *E = edited.front(); E; E = E->next()) { + Vector2i coords = E->get().get_atlas_coords(); + TileData *tile_data = Object::cast_to<TileData>(p_tile_set_atlas_source->get_tile_data(coords, 0)); + undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/terrain_set", coords.x, coords.y, E->get().alternative_tile), tile_data->get_terrain_set()); + undo_redo->add_do_property(p_tile_set_atlas_source, vformat("%d:%d/%d/terrain_set", coords.x, coords.y, E->get().alternative_tile), drag_painted_value); + for (int i = 0; i < TileSet::CELL_NEIGHBOR_MAX; i++) { + TileSet::CellNeighbor bit = TileSet::CellNeighbor(i); + if (tile_data->is_valid_peering_bit_terrain(bit)) { + undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/terrains_peering_bit/" + String(TileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[i]), coords.x, coords.y, E->get().alternative_tile), tile_data->get_peering_bit_terrain(bit)); + } + } + } + undo_redo->commit_action(true); + drag_type = DRAG_TYPE_NONE; + } else if (drag_type == DRAG_TYPE_PAINT_TERRAIN_SET) { + undo_redo->create_action(TTR("Painting Terrain Set")); + for (Map<TileMapCell, Variant>::Element *E = drag_modified.front(); E; E = E->next()) { + Dictionary dict = E->get(); + Vector2i coords = E->key().get_atlas_coords(); + undo_redo->add_do_property(p_tile_set_atlas_source, vformat("%d:%d/%d/terrain_set", coords.x, coords.y, E->key().alternative_tile), drag_painted_value); + undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/terrain_set", coords.x, coords.y, E->key().alternative_tile), dict["terrain_set"]); + Array array = dict["terrain_peering_bits"]; + for (int i = 0; i < array.size(); i++) { + TileSet::CellNeighbor bit = TileSet::CellNeighbor(i); + if (tile_set->is_valid_peering_bit_terrain(dict["terrain_set"], bit)) { + undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/terrains_peering_bit/" + String(TileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[i]), coords.x, coords.y, E->key().alternative_tile), array[i]); + } + } + } + undo_redo->commit_action(false); + drag_type = DRAG_TYPE_NONE; + } else if (drag_type == DRAG_TYPE_PAINT_TERRAIN_BITS) { + Dictionary painted = Dictionary(drag_painted_value); + int terrain_set = int(painted["terrain_set"]); + int terrain = int(painted["terrain"]); + undo_redo->create_action(TTR("Painting Terrain")); + for (Map<TileMapCell, Variant>::Element *E = drag_modified.front(); E; E = E->next()) { + Dictionary dict = E->get(); + Vector2i coords = E->key().get_atlas_coords(); + Array array = dict["terrain_peering_bits"]; + for (int i = 0; i < array.size(); i++) { + TileSet::CellNeighbor bit = TileSet::CellNeighbor(i); + if (tile_set->is_valid_peering_bit_terrain(terrain_set, bit)) { + undo_redo->add_do_property(p_tile_set_atlas_source, vformat("%d:%d/%d/terrains_peering_bit/" + String(TileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[i]), coords.x, coords.y, E->key().alternative_tile), terrain); + } + if (tile_set->is_valid_peering_bit_terrain(dict["terrain_set"], bit)) { + undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/terrains_peering_bit/" + String(TileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[i]), coords.x, coords.y, E->key().alternative_tile), array[i]); + } + } + } + undo_redo->commit_action(false); + drag_type = DRAG_TYPE_NONE; + } else if (drag_type == DRAG_TYPE_PAINT_TERRAIN_BITS_RECT) { + Dictionary painted = Dictionary(drag_painted_value); + int terrain_set = int(painted["terrain_set"]); + int terrain = int(painted["terrain"]); + + Rect2i rect; + rect.set_position(p_tile_atlas_view->get_atlas_tile_coords_at_pos(drag_start_pos)); + rect.set_end(p_tile_atlas_view->get_atlas_tile_coords_at_pos(mb->get_position())); + rect = rect.abs(); + + Set<TileMapCell> edited; + for (int x = rect.get_position().x; x <= rect.get_end().x; x++) { + for (int y = rect.get_position().y; y <= rect.get_end().y; y++) { + Vector2i coords = Vector2i(x, y); + coords = p_tile_set_atlas_source->get_tile_at_coords(coords); + if (coords != TileSetSource::INVALID_ATLAS_COORDS) { + TileData *tile_data = Object::cast_to<TileData>(p_tile_set_atlas_source->get_tile_data(coords, 0)); + if (tile_data->get_terrain_set() == terrain_set) { + TileMapCell cell; + cell.source_id = 0; + cell.set_atlas_coords(coords); + cell.alternative_tile = 0; + edited.insert(cell); + } + } + } + } + + Vector<Point2> mouse_pos_rect_polygon; + mouse_pos_rect_polygon.push_back(drag_start_pos); + mouse_pos_rect_polygon.push_back(Vector2(mb->get_position().x, drag_start_pos.y)); + mouse_pos_rect_polygon.push_back(mb->get_position()); + mouse_pos_rect_polygon.push_back(Vector2(drag_start_pos.x, mb->get_position().y)); + + undo_redo->create_action(TTR("Painting Terrain")); + for (Set<TileMapCell>::Element *E = edited.front(); E; E = E->next()) { + Vector2i coords = E->get().get_atlas_coords(); + TileData *tile_data = Object::cast_to<TileData>(p_tile_set_atlas_source->get_tile_data(coords, 0)); + + for (int i = 0; i < TileSet::CELL_NEIGHBOR_MAX; i++) { + TileSet::CellNeighbor bit = TileSet::CellNeighbor(i); + if (tile_set->is_valid_peering_bit_terrain(terrain_set, bit)) { + Rect2i texture_region = p_tile_set_atlas_source->get_tile_texture_region(coords); + Vector2i position = (texture_region.position + texture_region.get_end()) / 2 + p_tile_set_atlas_source->get_tile_effective_texture_offset(coords, 0); + + Vector<Vector2> polygon = tile_set->get_terrain_bit_polygon(terrain_set, bit); + for (int j = 0; j < polygon.size(); j++) { + polygon.write[j] += position; + } + if (!Geometry2D::intersect_polygons(polygon, mouse_pos_rect_polygon).is_empty()) { + // Draw bit. + undo_redo->add_do_property(p_tile_set_atlas_source, vformat("%d:%d/%d/terrains_peering_bit/" + String(TileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[i]), coords.x, coords.y, E->get().alternative_tile), terrain); + undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/terrains_peering_bit/" + String(TileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[i]), coords.x, coords.y, E->get().alternative_tile), tile_data->get_peering_bit_terrain(bit)); + } + } + } + } + undo_redo->commit_action(true); + drag_type = DRAG_TYPE_NONE; + } + } + } + } +} + +void TileDataTerrainsEditor::forward_painting_alternatives_gui_input(TileAtlasView *p_tile_atlas_view, TileSetAtlasSource *p_tile_set_atlas_source, const Ref<InputEvent> &p_event) { + Ref<InputEventMouseMotion> mm = p_event; + if (mm.is_valid()) { + if (drag_type == DRAG_TYPE_PAINT_TERRAIN_SET) { + Vector3i tile = p_tile_atlas_view->get_alternative_tile_at_pos(mm->get_position()); + Vector2i coords = Vector2i(tile.x, tile.y); + int alternative_tile = tile.z; + + if (coords != TileSetSource::INVALID_ATLAS_COORDS) { + TileMapCell cell; + cell.source_id = 0; + cell.set_atlas_coords(coords); + cell.alternative_tile = alternative_tile; + TileData *tile_data = Object::cast_to<TileData>(p_tile_set_atlas_source->get_tile_data(coords, alternative_tile)); + if (!drag_modified.has(cell)) { + Dictionary dict; + dict["terrain_set"] = tile_data->get_terrain_set(); + Array array; + for (int j = 0; j < TileSet::CELL_NEIGHBOR_MAX; j++) { + TileSet::CellNeighbor bit = TileSet::CellNeighbor(j); + array.push_back(tile_data->is_valid_peering_bit_terrain(bit) ? tile_data->get_peering_bit_terrain(bit) : -1); + } + dict["terrain_peering_bits"] = array; + drag_modified[cell] = dict; + } + tile_data->set_terrain_set(drag_painted_value); + } + + drag_last_pos = mm->get_position(); + } else if (drag_type == DRAG_TYPE_PAINT_TERRAIN_BITS) { + Dictionary painted = Dictionary(drag_painted_value); + int terrain_set = int(painted["terrain_set"]); + int terrain = int(painted["terrain"]); + + Vector3i tile = p_tile_atlas_view->get_alternative_tile_at_pos(mm->get_position()); + Vector2i coords = Vector2i(tile.x, tile.y); + int alternative_tile = tile.z; + + if (coords != TileSetSource::INVALID_ATLAS_COORDS) { + TileMapCell cell; + cell.source_id = 0; + cell.set_atlas_coords(coords); + cell.alternative_tile = alternative_tile; + + // Save the old terrain_set and terrains bits. + TileData *tile_data = Object::cast_to<TileData>(p_tile_set_atlas_source->get_tile_data(coords, alternative_tile)); + if (tile_data->get_terrain_set() == terrain_set) { + if (!drag_modified.has(cell)) { + Dictionary dict; + dict["terrain_set"] = tile_data->get_terrain_set(); + Array array; + for (int j = 0; j < TileSet::CELL_NEIGHBOR_MAX; j++) { + TileSet::CellNeighbor bit = TileSet::CellNeighbor(j); + array.push_back(tile_data->is_valid_peering_bit_terrain(bit) ? tile_data->get_peering_bit_terrain(bit) : -1); + } + dict["terrain_peering_bits"] = array; + drag_modified[cell] = dict; + } + + // Set the terrains bits. + Rect2i texture_region = p_tile_atlas_view->get_alternative_tile_rect(coords, alternative_tile); + Vector2i position = (texture_region.position + texture_region.get_end()) / 2 + p_tile_set_atlas_source->get_tile_effective_texture_offset(coords, alternative_tile); + for (int j = 0; j < TileSet::CELL_NEIGHBOR_MAX; j++) { + TileSet::CellNeighbor bit = TileSet::CellNeighbor(j); + if (tile_data->is_valid_peering_bit_terrain(bit)) { + Vector<Vector2> polygon = tile_set->get_terrain_bit_polygon(tile_data->get_terrain_set(), bit); + if (Geometry2D::is_segment_intersecting_polygon(mm->get_position() - position, drag_last_pos - position, polygon)) { + tile_data->set_peering_bit_terrain(bit, terrain); + } + } + } + } + } + drag_last_pos = mm->get_position(); + } + } + + Ref<InputEventMouseButton> mb = p_event; + if (mb.is_valid()) { + if (mb->get_button_index() == MOUSE_BUTTON_LEFT) { + if (mb->is_pressed()) { + if (picker_button->is_pressed()) { + Vector3i tile = p_tile_atlas_view->get_alternative_tile_at_pos(mb->get_position()); + Vector2i coords = Vector2i(tile.x, tile.y); + int alternative_tile = tile.z; + + if (coords != TileSetSource::INVALID_ATLAS_COORDS) { + TileData *tile_data = Object::cast_to<TileData>(p_tile_set_atlas_source->get_tile_data(coords, alternative_tile)); + int terrain_set = tile_data->get_terrain_set(); + Rect2i texture_region = p_tile_atlas_view->get_alternative_tile_rect(coords, alternative_tile); + Vector2i position = (texture_region.position + texture_region.get_end()) / 2 + p_tile_set_atlas_source->get_tile_effective_texture_offset(coords, alternative_tile); + dummy_object->set("terrain_set", terrain_set); + dummy_object->set("terrain", -1); + for (int i = 0; i < TileSet::CELL_NEIGHBOR_MAX; i++) { + TileSet::CellNeighbor bit = TileSet::CellNeighbor(i); + if (tile_set->is_valid_peering_bit_terrain(terrain_set, bit)) { + Vector<Vector2> polygon = tile_set->get_terrain_bit_polygon(terrain_set, bit); + if (Geometry2D::is_point_in_polygon(mb->get_position() - position, polygon)) { + dummy_object->set("terrain", tile_data->get_peering_bit_terrain(bit)); + } + } + } + terrain_set_property_editor->update_property(); + _update_terrain_selector(); + picker_button->set_pressed(false); } + } else { + int terrain_set = int(dummy_object->get("terrain_set")); + int terrain = int(dummy_object->get("terrain")); + + Vector3i tile = p_tile_atlas_view->get_alternative_tile_at_pos(mb->get_position()); + Vector2i coords = Vector2i(tile.x, tile.y); + int alternative_tile = tile.z; - // Generate the polygon color, slightly randomly modified from the settings one. - Color random_variation_color; - random_variation_color.set_hsv(color.get_h() + rand.random(-1.0, 1.0) * 0.05, color.get_s(), color.get_v() + rand.random(-1.0, 1.0) * 0.1); - random_variation_color.a = color.a; - Vector<Color> colors; - colors.push_back(random_variation_color); + TileData *tile_data = Object::cast_to<TileData>(p_tile_set_atlas_source->get_tile_data(coords, alternative_tile)); - RenderingServer::get_singleton()->canvas_item_add_polygon(p_canvas_item->get_canvas_item(), vertices, colors); + if (terrain_set == -1 || !tile_data || tile_data->get_terrain_set() != terrain_set) { + drag_type = DRAG_TYPE_PAINT_TERRAIN_SET; + drag_modified.clear(); + drag_painted_value = int(dummy_object->get("terrain_set")); + if (coords != TileSetSource::INVALID_ATLAS_COORDS) { + TileMapCell cell; + cell.source_id = 0; + cell.set_atlas_coords(coords); + cell.alternative_tile = alternative_tile; + Dictionary dict; + dict["terrain_set"] = tile_data->get_terrain_set(); + Array array; + for (int i = 0; i < TileSet::CELL_NEIGHBOR_MAX; i++) { + TileSet::CellNeighbor bit = TileSet::CellNeighbor(i); + array.push_back(tile_data->is_valid_peering_bit_terrain(bit) ? tile_data->get_peering_bit_terrain(bit) : -1); + } + dict["terrain_peering_bits"] = array; + drag_modified[cell] = dict; + tile_data->set_terrain_set(drag_painted_value); + } + drag_last_pos = mb->get_position(); + } else if (tile_data && tile_data->get_terrain_set() == terrain_set) { + // Paint terrain bits. + drag_type = DRAG_TYPE_PAINT_TERRAIN_BITS; + drag_modified.clear(); + Dictionary painted_dict; + painted_dict["terrain_set"] = terrain_set; + painted_dict["terrain"] = terrain; + drag_painted_value = painted_dict; + + if (coords != TileSetSource::INVALID_ATLAS_COORDS) { + TileMapCell cell; + cell.source_id = 0; + cell.set_atlas_coords(coords); + cell.alternative_tile = alternative_tile; + + // Save the old terrain_set and terrains bits. + Dictionary dict; + dict["terrain_set"] = tile_data->get_terrain_set(); + Array array; + for (int i = 0; i < TileSet::CELL_NEIGHBOR_MAX; i++) { + TileSet::CellNeighbor bit = TileSet::CellNeighbor(i); + array.push_back(tile_data->is_valid_peering_bit_terrain(bit) ? tile_data->get_peering_bit_terrain(bit) : -1); + } + dict["terrain_peering_bits"] = array; + drag_modified[cell] = dict; + + // Set the terrain bit. + Rect2i texture_region = p_tile_atlas_view->get_alternative_tile_rect(coords, alternative_tile); + Vector2i position = (texture_region.position + texture_region.get_end()) / 2 + p_tile_set_atlas_source->get_tile_effective_texture_offset(coords, alternative_tile); + for (int i = 0; i < TileSet::CELL_NEIGHBOR_MAX; i++) { + TileSet::CellNeighbor bit = TileSet::CellNeighbor(i); + if (tile_set->is_valid_peering_bit_terrain(terrain_set, bit)) { + Vector<Vector2> polygon = tile_set->get_terrain_bit_polygon(terrain_set, bit); + if (Geometry2D::is_point_in_polygon(mb->get_position() - position, polygon)) { + tile_data->set_peering_bit_terrain(bit, terrain); + } + } + } + } + drag_last_pos = mb->get_position(); + } + } + } else { + if (drag_type == DRAG_TYPE_PAINT_TERRAIN_SET) { + undo_redo->create_action(TTR("Painting Tiles Property")); + for (Map<TileMapCell, Variant>::Element *E = drag_modified.front(); E; E = E->next()) { + Dictionary dict = E->get(); + Vector2i coords = E->key().get_atlas_coords(); + undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/terrain_set", coords.x, coords.y, E->key().alternative_tile), dict["terrain_set"]); + undo_redo->add_do_property(p_tile_set_atlas_source, vformat("%d:%d/%d/terrain_set", coords.x, coords.y, E->key().alternative_tile), drag_painted_value); + Array array = dict["terrain_peering_bits"]; + for (int i = 0; i < array.size(); i++) { + undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/terrains_peering_bit/" + String(TileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[i]), coords.x, coords.y, E->key().alternative_tile), array[i]); + } + } + undo_redo->commit_action(false); + drag_type = DRAG_TYPE_NONE; + } else if (drag_type == DRAG_TYPE_PAINT_TERRAIN_BITS) { + Dictionary painted = Dictionary(drag_painted_value); + int terrain_set = int(painted["terrain_set"]); + int terrain = int(painted["terrain"]); + undo_redo->create_action(TTR("Painting Terrain")); + for (Map<TileMapCell, Variant>::Element *E = drag_modified.front(); E; E = E->next()) { + Dictionary dict = E->get(); + Vector2i coords = E->key().get_atlas_coords(); + Array array = dict["terrain_peering_bits"]; + for (int i = 0; i < array.size(); i++) { + TileSet::CellNeighbor bit = TileSet::CellNeighbor(i); + if (tile_set->is_valid_peering_bit_terrain(terrain_set, bit)) { + undo_redo->add_do_property(p_tile_set_atlas_source, vformat("%d:%d/%d/terrains_peering_bit/" + String(TileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[i]), coords.x, coords.y, E->key().alternative_tile), terrain); + } + if (tile_set->is_valid_peering_bit_terrain(dict["terrain_set"], bit)) { + undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/terrains_peering_bit/" + String(TileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[i]), coords.x, coords.y, E->key().alternative_tile), array[i]); + } + } + } + undo_redo->commit_action(false); + drag_type = DRAG_TYPE_NONE; } } + } + } +} + +void TileDataTerrainsEditor::draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileMapCell p_cell, bool p_selected) { + TileData *tile_data = _get_tile_data(p_cell); + ERR_FAIL_COND(!tile_data); - RenderingServer::get_singleton()->canvas_item_add_set_transform(p_canvas_item->get_canvas_item(), Transform2D()); + tile_set->draw_terrains(p_canvas_item, p_transform, tile_data); +} + +void TileDataTerrainsEditor::_notification(int p_what) { + switch (p_what) { + case NOTIFICATION_ENTER_TREE: + case NOTIFICATION_THEME_CHANGED: + picker_button->set_icon(get_theme_icon("ColorPick", "EditorIcons")); + break; + default: + break; + } +} + +TileDataTerrainsEditor::TileDataTerrainsEditor() { + label = memnew(Label); + label->set_text("Painting:"); + add_child(label); + + // Toolbar + toolbar->add_child(memnew(VSeparator)); + + picker_button = memnew(Button); + picker_button->set_flat(true); + picker_button->set_toggle_mode(true); + picker_button->set_shortcut(ED_SHORTCUT("tiles_editor/picker", "Picker", KEY_P)); + toolbar->add_child(picker_button); + + // Setup + dummy_object->add_dummy_property("terrain_set"); + dummy_object->set("terrain_set", -1); + dummy_object->add_dummy_property("terrain"); + dummy_object->set("terrain", -1); + + // Get the default value for the type. + terrain_set_property_editor = memnew(EditorPropertyEnum); + terrain_set_property_editor->set_object_and_property(dummy_object, "terrain_set"); + terrain_set_property_editor->set_label("Terrain Set"); + terrain_set_property_editor->connect("property_changed", callable_mp(this, &TileDataTerrainsEditor::_property_value_changed).unbind(1)); + add_child(terrain_set_property_editor); + + terrain_property_editor = memnew(EditorPropertyEnum); + terrain_property_editor->set_object_and_property(dummy_object, "terrain"); + terrain_property_editor->set_label("Terrain"); + terrain_property_editor->connect("property_changed", callable_mp(this, &TileDataTerrainsEditor::_property_value_changed).unbind(1)); + add_child(terrain_property_editor); +} + +TileDataTerrainsEditor::~TileDataTerrainsEditor() { + toolbar->queue_delete(); + memdelete(dummy_object); +} + +Variant TileDataNavigationEditor::_get_painted_value() { + Ref<NavigationPolygon> navigation_polygon; + navigation_polygon.instantiate(); + + for (int i = 0; i < polygon_editor->get_polygon_count(); i++) { + Vector<Vector2> polygon = polygon_editor->get_polygon(i); + navigation_polygon->add_outline(polygon); + } + + navigation_polygon->make_polygons_from_outlines(); + return navigation_polygon; +} + +void TileDataNavigationEditor::_set_painted_value(TileSetAtlasSource *p_tile_set_atlas_source, Vector2 p_coords, int p_alternative_tile) { + TileData *tile_data = Object::cast_to<TileData>(p_tile_set_atlas_source->get_tile_data(p_coords, p_alternative_tile)); + ERR_FAIL_COND(!tile_data); + + Ref<NavigationPolygon> navigation_polygon = tile_data->get_navigation_polygon(navigation_layer); + polygon_editor->clear_polygons(); + if (navigation_polygon.is_valid()) { + for (int i = 0; i < navigation_polygon->get_outline_count(); i++) { + polygon_editor->add_polygon(navigation_polygon->get_outline(i)); + } + } + polygon_editor->set_background(p_tile_set_atlas_source->get_texture(), p_tile_set_atlas_source->get_tile_texture_region(p_coords), p_tile_set_atlas_source->get_tile_effective_texture_offset(p_coords, p_alternative_tile), tile_data->get_flip_h(), tile_data->get_flip_v(), tile_data->get_transpose(), tile_data->get_modulate()); +} + +void TileDataNavigationEditor::_set_value(TileSetAtlasSource *p_tile_set_atlas_source, Vector2 p_coords, int p_alternative_tile, Variant p_value) { + TileData *tile_data = Object::cast_to<TileData>(p_tile_set_atlas_source->get_tile_data(p_coords, p_alternative_tile)); + ERR_FAIL_COND(!tile_data); + Ref<NavigationPolygon> navigation_polygon = p_value; + tile_data->set_navigation_polygon(navigation_layer, navigation_polygon); + + polygon_editor->set_background(p_tile_set_atlas_source->get_texture(), p_tile_set_atlas_source->get_tile_texture_region(p_coords), p_tile_set_atlas_source->get_tile_effective_texture_offset(p_coords, p_alternative_tile), tile_data->get_flip_h(), tile_data->get_flip_v(), tile_data->get_transpose(), tile_data->get_modulate()); +} + +Variant TileDataNavigationEditor::_get_value(TileSetAtlasSource *p_tile_set_atlas_source, Vector2 p_coords, int p_alternative_tile) { + TileData *tile_data = Object::cast_to<TileData>(p_tile_set_atlas_source->get_tile_data(p_coords, p_alternative_tile)); + ERR_FAIL_COND_V(!tile_data, Variant()); + return tile_data->get_navigation_polygon(navigation_layer); +} + +void TileDataNavigationEditor::_setup_undo_redo_action(TileSetAtlasSource *p_tile_set_atlas_source, Map<TileMapCell, Variant> p_previous_values, Variant p_new_value) { + for (Map<TileMapCell, Variant>::Element *E = p_previous_values.front(); E; E = E->next()) { + Vector2i coords = E->key().get_atlas_coords(); + undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/navigation_layer_%d/polygon", coords.x, coords.y, E->key().alternative_tile, navigation_layer), E->get()); + undo_redo->add_do_property(p_tile_set_atlas_source, vformat("%d:%d/%d/navigation_layer_%d/polygon", coords.x, coords.y, E->key().alternative_tile, navigation_layer), p_new_value); + } +} + +void TileDataNavigationEditor::_tile_set_changed() { + polygon_editor->set_tile_set(tile_set); +} + +void TileDataNavigationEditor::_notification(int p_what) { + switch (p_what) { + case NOTIFICATION_ENTER_TREE: + polygon_editor->set_polygons_color(get_tree()->get_debug_navigation_color()); + break; + default: + break; + } +} + +TileDataNavigationEditor::TileDataNavigationEditor() { + polygon_editor = memnew(GenericTilePolygonEditor); + polygon_editor->set_multiple_polygon_mode(true); + add_child(polygon_editor); +} + +void TileDataNavigationEditor::draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileMapCell p_cell, bool p_selected) { + TileData *tile_data = _get_tile_data(p_cell); + ERR_FAIL_COND(!tile_data); + + // Draw all shapes. + RenderingServer::get_singleton()->canvas_item_add_set_transform(p_canvas_item->get_canvas_item(), p_transform); + + Ref<NavigationPolygon> navigation_polygon = tile_data->get_navigation_polygon(navigation_layer); + if (navigation_polygon.is_valid()) { + Vector<Vector2> verts = navigation_polygon->get_vertices(); + if (verts.size() < 3) { + return; + } + + Color color = p_canvas_item->get_tree()->get_debug_navigation_color(); + if (p_selected) { + Color grid_color = EditorSettings::get_singleton()->get("editors/tiles_editor/grid_color"); + Color selection_color = Color().from_hsv(Math::fposmod(grid_color.get_h() + 0.5, 1.0), grid_color.get_s(), grid_color.get_v(), 1.0); + selection_color.a = 0.7; + color = selection_color; + } + + RandomPCG rand; + for (int i = 0; i < navigation_polygon->get_polygon_count(); i++) { + // An array of vertices for this polygon. + Vector<int> polygon = navigation_polygon->get_polygon(i); + Vector<Vector2> vertices; + vertices.resize(polygon.size()); + for (int j = 0; j < polygon.size(); j++) { + ERR_FAIL_INDEX(polygon[j], verts.size()); + vertices.write[j] = verts[polygon[j]]; + } + + // Generate the polygon color, slightly randomly modified from the settings one. + Color random_variation_color; + random_variation_color.set_hsv(color.get_h() + rand.random(-1.0, 1.0) * 0.05, color.get_s(), color.get_v() + rand.random(-1.0, 1.0) * 0.1); + random_variation_color.a = color.a; + Vector<Color> colors; + colors.push_back(random_variation_color); + + RenderingServer::get_singleton()->canvas_item_add_polygon(p_canvas_item->get_canvas_item(), vertices, colors); } } + + RenderingServer::get_singleton()->canvas_item_add_set_transform(p_canvas_item->get_canvas_item(), Transform2D()); } diff --git a/editor/plugins/tiles/tile_data_editors.h b/editor/plugins/tiles/tile_data_editors.h index b82189e1ee..781f26cc02 100644 --- a/editor/plugins/tiles/tile_data_editors.h +++ b/editor/plugins/tiles/tile_data_editors.h @@ -31,87 +31,378 @@ #ifndef TILE_DATA_EDITORS_H #define TILE_DATA_EDITORS_H +#include "tile_atlas_view.h" + +#include "editor/editor_node.h" +#include "editor/editor_properties.h" + +#include "scene/gui/box_container.h" #include "scene/gui/control.h" +#include "scene/gui/label.h" #include "scene/resources/tile_set.h" -class TileDataEditor : public Control { - GDCLASS(TileDataEditor, Control); +class TileDataEditor : public VBoxContainer { + GDCLASS(TileDataEditor, VBoxContainer); + +private: + void _call_tile_set_changed(); protected: - TileData *tile_data; - String property; + Ref<TileSet> tile_set; + TileData *_get_tile_data(TileMapCell p_cell); + virtual void _tile_set_changed(){}; - TileData *_get_tile_data(TileSet *p_tile_set, int p_atlas_source_id, Vector2i p_atlas_coords, int p_alternative_tile); + static void _bind_methods(); public: - // Edits a TileData property. - void edit(TileSet *p_tile_set, int p_atlas_source_id, Vector2i p_atlas_coords, int p_alternative_tile, String p_property); + void set_tile_set(Ref<TileSet> p_tile_set); + + // Input to handle painting. + virtual Control *get_toolbar() { return nullptr; }; + virtual void forward_draw_over_atlas(TileAtlasView *p_tile_atlas_view, TileSetAtlasSource *p_tile_atlas_source, CanvasItem *p_canvas_item, Transform2D p_transform){}; + virtual void forward_draw_over_alternatives(TileAtlasView *p_tile_atlas_view, TileSetAtlasSource *p_tile_atlas_source, CanvasItem *p_canvas_item, Transform2D p_transform){}; + virtual void forward_painting_atlas_gui_input(TileAtlasView *p_tile_atlas_view, TileSetAtlasSource *p_tile_atlas_source, const Ref<InputEvent> &p_event){}; + virtual void forward_painting_alternatives_gui_input(TileAtlasView *p_tile_atlas_view, TileSetAtlasSource *p_tile_atlas_source, const Ref<InputEvent> &p_event){}; - // Used to draw the value over a tile. - virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileSet *p_tile_set, int p_atlas_source_id, Vector2i p_atlas_coords, int p_alternative_tile, String p_property){}; + // Used to draw the tile data property value over a tile. + virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileMapCell p_cell, bool p_selected = false){}; }; -class TileDataTextureOffsetEditor : public TileDataEditor { - GDCLASS(TileDataTextureOffsetEditor, TileDataEditor); +class DummyObject : public Object { + GDCLASS(DummyObject, Object) +private: + Map<String, Variant> properties; + +protected: + bool _set(const StringName &p_name, const Variant &p_value); + bool _get(const StringName &p_name, Variant &r_ret) const; public: - virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileSet *p_tile_set, int p_atlas_source_id, Vector2i p_atlas_coords, int p_alternative_tile, String p_property) override; + bool has_dummy_property(StringName p_name); + void add_dummy_property(StringName p_name); + void remove_dummy_property(StringName p_name); + void clear_dummy_properties(); }; -class TileDataIntegerEditor : public TileDataEditor { - GDCLASS(TileDataIntegerEditor, TileDataEditor); +class GenericTilePolygonEditor : public VBoxContainer { + GDCLASS(GenericTilePolygonEditor, VBoxContainer); + +private: + Ref<TileSet> tile_set; + LocalVector<Vector<Point2>> polygons; + bool multiple_polygon_mode = false; + + UndoRedo *undo_redo = EditorNode::get_undo_redo(); + + // UI + int hovered_polygon_index = -1; + int hovered_point_index = -1; + int hovered_segment_index = -1; + Vector2 hovered_segment_point; + + enum DragType { + DRAG_TYPE_NONE, + DRAG_TYPE_DRAG_POINT, + DRAG_TYPE_CREATE_POINT, + DRAG_TYPE_PAN, + }; + DragType drag_type; + int drag_polygon_index; + int drag_point_index; + Vector2 drag_last_pos; + PackedVector2Array drag_old_polygon; + + HBoxContainer *toolbar; + Ref<ButtonGroup> tools_button_group; + Button *button_create; + Button *button_edit; + Button *button_delete; + Button *button_pixel_snap; + MenuButton *button_advanced_menu; + + Vector<Point2> in_creation_polygon; + + Panel *panel; + Control *base_control; + EditorZoomWidget *editor_zoom_widget; + Button *button_center_view; + Vector2 panning; + + Ref<Texture2D> background_texture; + Rect2 background_region; + Vector2 background_offset; + bool background_h_flip; + bool background_v_flip; + bool background_transpose; + Color background_modulate; + + Color polygon_color = Color(1.0, 0.0, 0.0); + + enum AdvancedMenuOption { + RESET_TO_DEFAULT_TILE, + CLEAR_TILE, + }; + + void _base_control_draw(); + void _zoom_changed(); + void _advanced_menu_item_pressed(int p_item_pressed); + void _center_view(); + void _base_control_gui_input(Ref<InputEvent> p_event); + + void _snap_to_tile_shape(Point2 &r_point, float &r_current_snapped_dist, float p_snap_dist); + void _snap_to_half_pixel(Point2 &r_point); + void _grab_polygon_point(Vector2 p_pos, const Transform2D &p_polygon_xform, int &r_polygon_index, int &r_point_index); + void _grab_polygon_segment_point(Vector2 p_pos, const Transform2D &p_polygon_xform, int &r_polygon_index, int &r_segment_index, Vector2 &r_point); + +protected: + void _notification(int p_what); + static void _bind_methods(); public: - virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileSet *p_tile_set, int p_atlas_source_id, Vector2i p_atlas_coords, int p_alternative_tile, String p_property) override; + void set_tile_set(Ref<TileSet> p_tile_set); + void set_background(Ref<Texture2D> p_texture, Rect2 p_region = Rect2(), Vector2 p_offset = Vector2(), bool p_flip_h = false, bool p_flip_v = false, bool p_transpose = false, Color p_modulate = Color(1.0, 1.0, 1.0, 0.0)); + + int get_polygon_count(); + int add_polygon(Vector<Point2> p_polygon, int p_index = -1); + void remove_polygon(int p_index); + void clear_polygons(); + void set_polygon(int p_polygon_index, Vector<Point2> p_polygon); + Vector<Point2> get_polygon(int p_polygon_index); + + void set_polygons_color(Color p_color); + void set_multiple_polygon_mode(bool p_multiple_polygon_mode); + + GenericTilePolygonEditor(); }; -class TileDataFloatEditor : public TileDataEditor { - GDCLASS(TileDataFloatEditor, TileDataEditor); +class TileDataDefaultEditor : public TileDataEditor { + GDCLASS(TileDataDefaultEditor, TileDataEditor); + +private: + // Toolbar + HBoxContainer *toolbar = memnew(HBoxContainer); + Button *picker_button; + + // UI + Ref<Texture2D> tile_bool_checked; + Ref<Texture2D> tile_bool_unchecked; + Label *label; + + EditorProperty *property_editor = nullptr; + + // Painting state. + enum DragType { + DRAG_TYPE_NONE = 0, + DRAG_TYPE_PAINT, + DRAG_TYPE_PAINT_RECT, + }; + DragType drag_type = DRAG_TYPE_NONE; + Vector2 drag_start_pos; + Vector2 drag_last_pos; + Map<TileMapCell, Variant> drag_modified; + Variant drag_painted_value; + + void _property_value_changed(StringName p_property, Variant p_value, StringName p_field); + +protected: + DummyObject *dummy_object = memnew(DummyObject); + + UndoRedo *undo_redo = EditorNode::get_undo_redo(); + + StringName type; + String property; + void _notification(int p_what); + + virtual Variant _get_painted_value(); + virtual void _set_painted_value(TileSetAtlasSource *p_tile_set_atlas_source, Vector2 p_coords, int p_alternative_tile); + virtual void _set_value(TileSetAtlasSource *p_tile_set_atlas_source, Vector2 p_coords, int p_alternative_tile, Variant p_value); + virtual Variant _get_value(TileSetAtlasSource *p_tile_set_atlas_source, Vector2 p_coords, int p_alternative_tile); + virtual void _setup_undo_redo_action(TileSetAtlasSource *p_tile_set_atlas_source, Map<TileMapCell, Variant> p_previous_values, Variant p_new_value); public: - virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileSet *p_tile_set, int p_atlas_source_id, Vector2i p_atlas_coords, int p_alternative_tile, String p_property) override; + virtual Control *get_toolbar() override { return toolbar; }; + virtual void forward_draw_over_atlas(TileAtlasView *p_tile_atlas_view, TileSetAtlasSource *p_tile_atlas_source, CanvasItem *p_canvas_item, Transform2D p_transform) override; + virtual void forward_draw_over_alternatives(TileAtlasView *p_tile_atlas_view, TileSetAtlasSource *p_tile_atlas_source, CanvasItem *p_canvas_item, Transform2D p_transform) override; + virtual void forward_painting_atlas_gui_input(TileAtlasView *p_tile_atlas_view, TileSetAtlasSource *p_tile_atlas_source, const Ref<InputEvent> &p_event) override; + virtual void forward_painting_alternatives_gui_input(TileAtlasView *p_tile_atlas_view, TileSetAtlasSource *p_tile_atlas_source, const Ref<InputEvent> &p_event) override; + virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileMapCell p_cell, bool p_selected = false) override; + + void setup_property_editor(Variant::Type p_type, String p_property, String p_label = "", Variant p_default_value = Variant()); + + TileDataDefaultEditor(); + ~TileDataDefaultEditor(); }; -class TileDataPositionEditor : public TileDataEditor { - GDCLASS(TileDataPositionEditor, TileDataEditor); +class TileDataTextureOffsetEditor : public TileDataDefaultEditor { + GDCLASS(TileDataTextureOffsetEditor, TileDataDefaultEditor); public: - virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileSet *p_tile_set, int p_atlas_source_id, Vector2i p_atlas_coords, int p_alternative_tile, String p_property) override; + virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileMapCell p_cell, bool p_selected = false) override; }; -class TileDataYSortEditor : public TileDataEditor { - GDCLASS(TileDataYSortEditor, TileDataEditor); +class TileDataPositionEditor : public TileDataDefaultEditor { + GDCLASS(TileDataPositionEditor, TileDataDefaultEditor); public: - virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileSet *p_tile_set, int p_atlas_source_id, Vector2i p_atlas_coords, int p_alternative_tile, String p_property) override; + virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileMapCell p_cell, bool p_selected = false) override; }; -class TileDataOcclusionShapeEditor : public TileDataEditor { - GDCLASS(TileDataOcclusionShapeEditor, TileDataEditor); +class TileDataYSortEditor : public TileDataDefaultEditor { + GDCLASS(TileDataYSortEditor, TileDataDefaultEditor); public: - virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileSet *p_tile_set, int p_atlas_source_id, Vector2i p_atlas_coords, int p_alternative_tile, String p_property) override; + virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileMapCell p_cell, bool p_selected = false) override; }; -class TileDataCollisionShapeEditor : public TileDataEditor { - GDCLASS(TileDataCollisionShapeEditor, TileDataEditor); +class TileDataOcclusionShapeEditor : public TileDataDefaultEditor { + GDCLASS(TileDataOcclusionShapeEditor, TileDataDefaultEditor); + +private: + int occlusion_layer = -1; + + // UI + GenericTilePolygonEditor *polygon_editor; + + void _polygon_changed(PackedVector2Array p_polygon); + + virtual Variant _get_painted_value() override; + virtual void _set_painted_value(TileSetAtlasSource *p_tile_set_atlas_source, Vector2 p_coords, int p_alternative_tile) override; + virtual void _set_value(TileSetAtlasSource *p_tile_set_atlas_source, Vector2 p_coords, int p_alternative_tile, Variant p_value) override; + virtual Variant _get_value(TileSetAtlasSource *p_tile_set_atlas_source, Vector2 p_coords, int p_alternative_tile) override; + virtual void _setup_undo_redo_action(TileSetAtlasSource *p_tile_set_atlas_source, Map<TileMapCell, Variant> p_previous_values, Variant p_new_value) override; + +protected: + UndoRedo *undo_redo = EditorNode::get_undo_redo(); + + virtual void _tile_set_changed() override; + + void _notification(int p_what); + +public: + virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileMapCell p_cell, bool p_selected = false) override; + + void set_occlusion_layer(int p_occlusion_layer) { occlusion_layer = p_occlusion_layer; } + + TileDataOcclusionShapeEditor(); +}; + +class TileDataCollisionEditor : public TileDataDefaultEditor { + GDCLASS(TileDataCollisionEditor, TileDataDefaultEditor); + + int physics_layer = -1; + + // UI + GenericTilePolygonEditor *polygon_editor; + DummyObject *dummy_object = memnew(DummyObject); + Map<StringName, EditorProperty *> property_editors; + + void _property_value_changed(StringName p_property, Variant p_value, StringName p_field); + void _polygons_changed(); + + virtual Variant _get_painted_value() override; + virtual void _set_painted_value(TileSetAtlasSource *p_tile_set_atlas_source, Vector2 p_coords, int p_alternative_tile) override; + virtual void _set_value(TileSetAtlasSource *p_tile_set_atlas_source, Vector2 p_coords, int p_alternative_tile, Variant p_value) override; + virtual Variant _get_value(TileSetAtlasSource *p_tile_set_atlas_source, Vector2 p_coords, int p_alternative_tile) override; + virtual void _setup_undo_redo_action(TileSetAtlasSource *p_tile_set_atlas_source, Map<TileMapCell, Variant> p_previous_values, Variant p_new_value) override; + +protected: + UndoRedo *undo_redo = EditorNode::get_undo_redo(); + + virtual void _tile_set_changed() override; + + void _notification(int p_what); public: - virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileSet *p_tile_set, int p_atlas_source_id, Vector2i p_atlas_coords, int p_alternative_tile, String p_property) override; + virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileMapCell p_cell, bool p_selected = false) override; + + void set_physics_layer(int p_physics_layer) { physics_layer = p_physics_layer; } + + TileDataCollisionEditor(); + ~TileDataCollisionEditor(); }; class TileDataTerrainsEditor : public TileDataEditor { GDCLASS(TileDataTerrainsEditor, TileDataEditor); +private: + // Toolbar + HBoxContainer *toolbar = memnew(HBoxContainer); + Button *picker_button; + + // Painting state. + enum DragType { + DRAG_TYPE_NONE = 0, + DRAG_TYPE_PAINT_TERRAIN_SET, + DRAG_TYPE_PAINT_TERRAIN_SET_RECT, + DRAG_TYPE_PAINT_TERRAIN_BITS, + DRAG_TYPE_PAINT_TERRAIN_BITS_RECT, + }; + DragType drag_type = DRAG_TYPE_NONE; + Vector2 drag_start_pos; + Vector2 drag_last_pos; + Map<TileMapCell, Variant> drag_modified; + Variant drag_painted_value; + + // UI + Label *label; + DummyObject *dummy_object = memnew(DummyObject); + EditorPropertyEnum *terrain_set_property_editor = nullptr; + EditorPropertyEnum *terrain_property_editor = nullptr; + + void _property_value_changed(StringName p_property, Variant p_value, StringName p_field); + + void _update_terrain_selector(); + +protected: + virtual void _tile_set_changed() override; + + void _notification(int p_what); + + UndoRedo *undo_redo = EditorNode::get_undo_redo(); + public: - virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileSet *p_tile_set, int p_atlas_source_id, Vector2i p_atlas_coords, int p_alternative_tile, String p_property) override; + virtual Control *get_toolbar() override { return toolbar; }; + virtual void forward_draw_over_atlas(TileAtlasView *p_tile_atlas_view, TileSetAtlasSource *p_tile_atlas_source, CanvasItem *p_canvas_item, Transform2D p_transform) override; + virtual void forward_draw_over_alternatives(TileAtlasView *p_tile_atlas_view, TileSetAtlasSource *p_tile_atlas_source, CanvasItem *p_canvas_item, Transform2D p_transform) override; + virtual void forward_painting_atlas_gui_input(TileAtlasView *p_tile_atlas_view, TileSetAtlasSource *p_tile_atlas_source, const Ref<InputEvent> &p_event) override; + virtual void forward_painting_alternatives_gui_input(TileAtlasView *p_tile_atlas_view, TileSetAtlasSource *p_tile_atlas_source, const Ref<InputEvent> &p_event) override; + virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileMapCell p_cell, bool p_selected = false) override; + + TileDataTerrainsEditor(); + ~TileDataTerrainsEditor(); }; -class TileDataNavigationPolygonEditor : public TileDataEditor { - GDCLASS(TileDataNavigationPolygonEditor, TileDataEditor); +class TileDataNavigationEditor : public TileDataDefaultEditor { + GDCLASS(TileDataNavigationEditor, TileDataDefaultEditor); + +private: + int navigation_layer = -1; + PackedVector2Array navigation_polygon; + + // UI + GenericTilePolygonEditor *polygon_editor; + + void _polygon_changed(PackedVector2Array p_polygon); + + virtual Variant _get_painted_value() override; + virtual void _set_painted_value(TileSetAtlasSource *p_tile_set_atlas_source, Vector2 p_coords, int p_alternative_tile) override; + virtual void _set_value(TileSetAtlasSource *p_tile_set_atlas_source, Vector2 p_coords, int p_alternative_tile, Variant p_value) override; + virtual Variant _get_value(TileSetAtlasSource *p_tile_set_atlas_source, Vector2 p_coords, int p_alternative_tile) override; + virtual void _setup_undo_redo_action(TileSetAtlasSource *p_tile_set_atlas_source, Map<TileMapCell, Variant> p_previous_values, Variant p_new_value) override; + +protected: + UndoRedo *undo_redo = EditorNode::get_undo_redo(); + + virtual void _tile_set_changed() override; + + void _notification(int p_what); public: - virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileSet *p_tile_set, int p_atlas_source_id, Vector2i p_atlas_coords, int p_alternative_tile, String p_property) override; + virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileMapCell p_cell, bool p_selected = false) override; + + void set_navigation_layer(int p_navigation_layer) { navigation_layer = p_navigation_layer; } + + TileDataNavigationEditor(); }; #endif // TILE_DATA_EDITORS_H diff --git a/editor/plugins/tiles/tile_map_editor.cpp b/editor/plugins/tiles/tile_map_editor.cpp index ef13d8ea12..86bd115ac2 100644 --- a/editor/plugins/tiles/tile_map_editor.cpp +++ b/editor/plugins/tiles/tile_map_editor.cpp @@ -1756,7 +1756,7 @@ TileMapEditorTilesPlugin::TileMapEditorTilesPlugin() { HBoxContainer *tilemap_tiles_tools_buttons = memnew(HBoxContainer); - tool_buttons_group.instance(); + tool_buttons_group.instantiate(); select_tool_button = memnew(Button); select_tool_button->set_flat(true); @@ -2989,6 +2989,7 @@ void TileMapEditorTerrainsPlugin::_update_terrains_tree() { } // Fill in the terrain list. + Vector<Vector<Ref<Texture2D>>> icons = tile_set->generate_terrains_icons(Size2(16, 16) * EDSCALE); for (int terrain_set_index = 0; terrain_set_index < tile_set->get_terrain_sets_count(); terrain_set_index++) { // Add an item for the terrain set. TreeItem *terrain_set_tree_item = terrains_tree->create_item(); @@ -3007,58 +3008,12 @@ void TileMapEditorTerrainsPlugin::_update_terrains_tree() { terrain_set_tree_item->set_selectable(0, false); for (int terrain_index = 0; terrain_index < tile_set->get_terrains_count(terrain_set_index); terrain_index++) { - // Compute the terrains_tile_pattern used for terrain preview (whenever possible). - TerrainsTilePattern terrains_tile_pattern; - int max_bit_count = -1; - for (Set<TerrainsTilePattern>::Element *E = per_terrain_terrains_tile_patterns[terrain_set_index][terrain_index].front(); E; E = E->next()) { - int count = 0; - for (int i = 0; i < E->get().size(); i++) { - if (int(E->get()[i]) == terrain_index) { - count++; - } - } - if (count > max_bit_count) { - terrains_tile_pattern = E->get(); - max_bit_count = count; - } - } - - // Get the preview. - Ref<Texture2D> icon; - Rect2 region; - if (max_bit_count >= 0) { - double max_probability = -1.0; - for (Set<TileMapCell>::Element *E = per_terrain_terrains_tile_patterns_tiles[terrain_set_index][terrains_tile_pattern].front(); E; E = E->next()) { - Ref<TileSetSource> source = tile_set->get_source(E->get().source_id); - - Ref<TileSetAtlasSource> atlas_source = source; - if (atlas_source.is_valid()) { - TileData *tile_data = Object::cast_to<TileData>(atlas_source->get_tile_data(E->get().get_atlas_coords(), E->get().alternative_tile)); - if (tile_data->get_probability() > max_probability) { - icon = atlas_source->get_texture(); - region = atlas_source->get_tile_texture_region(E->get().get_atlas_coords()); - max_probability = tile_data->get_probability(); - } - } - } - } else { - Ref<Image> image; - image.instance(); - image->create(1, 1, false, Image::FORMAT_RGBA8); - image->set_pixel(0, 0, tile_set->get_terrain_color(terrain_set_index, terrain_index)); - Ref<ImageTexture> image_texture; - image_texture.instance(); - image_texture->create_from_image(image); - image_texture->set_size_override(Size2(32, 32) * EDSCALE); - icon = image_texture; - } - // Add the item to the terrain list. TreeItem *terrain_tree_item = terrains_tree->create_item(terrain_set_tree_item); terrain_tree_item->set_text(0, tile_set->get_terrain_name(terrain_set_index, terrain_index)); terrain_tree_item->set_icon_max_width(0, 32 * EDSCALE); - terrain_tree_item->set_icon(0, icon); - terrain_tree_item->set_icon_region(0, region); + terrain_tree_item->set_icon(0, icons[terrain_set_index][terrain_index]); + Dictionary metadata_dict; metadata_dict["terrain_set"] = terrain_set_index; metadata_dict["terrain_id"] = terrain_index; @@ -3188,7 +3143,7 @@ TileMapEditorTerrainsPlugin::TileMapEditorTerrainsPlugin() { HBoxContainer *tilemap_tiles_tools_buttons = memnew(HBoxContainer); - tool_buttons_group.instance(); + tool_buttons_group.instantiate(); paint_tool_button = memnew(Button); paint_tool_button->set_flat(true); diff --git a/editor/plugins/tiles/tile_set_atlas_source_editor.cpp b/editor/plugins/tiles/tile_set_atlas_source_editor.cpp index eb52aff318..9d849a0df5 100644 --- a/editor/plugins/tiles/tile_set_atlas_source_editor.cpp +++ b/editor/plugins/tiles/tile_set_atlas_source_editor.cpp @@ -357,6 +357,7 @@ void TileSetAtlasSourceEditor::AtlasTileProxyObject::_bind_methods() { void TileSetAtlasSourceEditor::_inspector_property_selected(String p_property) { selected_property = p_property; _update_atlas_view(); + _update_current_tile_data_editor(); } void TileSetAtlasSourceEditor::_update_tile_id_label() { @@ -398,17 +399,315 @@ void TileSetAtlasSourceEditor::_update_fix_selected_and_hovered_tiles() { } } +void TileSetAtlasSourceEditor::_update_atlas_source_inspector() { + // Update visibility. + bool visible = tools_button_group->get_pressed_button() == tool_setup_atlas_source_button; + atlas_source_inspector_label->set_visible(visible); + atlas_source_inspector->set_visible(visible); +} + void TileSetAtlasSourceEditor::_update_tile_inspector() { - bool has_atlas_tile_selected = (tools_button_group->get_pressed_button() == tool_select_button) && !selection.is_empty(); + // Update visibility. + if (tools_button_group->get_pressed_button() == tool_select_button) { + if (!selection.is_empty()) { + tile_proxy_object->edit(tile_set_atlas_source, selection); + } + tile_inspector_label->show(); + tile_inspector->set_visible(!selection.is_empty()); + tile_inspector_no_tile_selected_label->set_visible(selection.is_empty()); + } else { + tile_inspector_label->hide(); + tile_inspector->hide(); + tile_inspector_no_tile_selected_label->hide(); + } +} - // Update the proxy object. - if (has_atlas_tile_selected) { - tile_proxy_object->edit(tile_set_atlas_source, selection); +void TileSetAtlasSourceEditor::_update_tile_data_editors() { + String previously_selected; + if (tile_data_editors_tree && tile_data_editors_tree->get_selected()) { + previously_selected = tile_data_editors_tree->get_selected()->get_metadata(0); + } + + tile_data_editors_tree->clear(); + + TreeItem *root = tile_data_editors_tree->create_item(); + + TreeItem *group; +#define ADD_TILE_DATA_EDITOR_GROUP(text) \ + group = tile_data_editors_tree->create_item(root); \ + group->set_custom_bg_color(0, group_color); \ + group->set_selectable(0, false); \ + group->set_disable_folding(true); \ + group->set_text(0, text); + + TreeItem *item; +#define ADD_TILE_DATA_EDITOR(parent, text, property) \ + item = tile_data_editors_tree->create_item(parent); \ + item->set_text(0, text); \ + item->set_metadata(0, property); \ + if (property == previously_selected) { \ + item->select(0); \ + } + + // Theming. + tile_data_editors_tree->add_theme_constant_override("vseparation", 1); + tile_data_editors_tree->add_theme_constant_override("hseparation", 3); + + Color group_color = get_theme_color("prop_category", "Editor"); + + // List of editors. + // --- Rendering --- + ADD_TILE_DATA_EDITOR_GROUP("Rendering"); + + ADD_TILE_DATA_EDITOR(group, "Texture Offset", "texture_offset"); + if (!tile_data_editors.has("texture_offset")) { + TileDataTextureOffsetEditor *tile_data_texture_offset_editor = memnew(TileDataTextureOffsetEditor); + tile_data_texture_offset_editor->hide(); + tile_data_texture_offset_editor->setup_property_editor(Variant::VECTOR2, "texture_offset"); + tile_data_texture_offset_editor->connect("needs_redraw", callable_mp((CanvasItem *)tile_atlas_control_unscaled, &Control::update)); + tile_data_texture_offset_editor->connect("needs_redraw", callable_mp((CanvasItem *)alternative_tiles_control_unscaled, &Control::update)); + tile_data_editors["texture_offset"] = tile_data_texture_offset_editor; + } + + ADD_TILE_DATA_EDITOR(group, "Modulate", "modulate"); + if (!tile_data_editors.has("modulate")) { + TileDataDefaultEditor *tile_data_modulate_editor = memnew(TileDataDefaultEditor()); + tile_data_modulate_editor->hide(); + tile_data_modulate_editor->setup_property_editor(Variant::COLOR, "modulate", "", Color(1.0, 1.0, 1.0, 1.0)); + tile_data_modulate_editor->connect("needs_redraw", callable_mp((CanvasItem *)tile_atlas_control_unscaled, &Control::update)); + tile_data_modulate_editor->connect("needs_redraw", callable_mp((CanvasItem *)alternative_tiles_control_unscaled, &Control::update)); + tile_data_editors["modulate"] = tile_data_modulate_editor; + } + + ADD_TILE_DATA_EDITOR(group, "Z Index", "z_index"); + if (!tile_data_editors.has("z_index")) { + TileDataDefaultEditor *tile_data_z_index_editor = memnew(TileDataDefaultEditor()); + tile_data_z_index_editor->hide(); + tile_data_z_index_editor->setup_property_editor(Variant::INT, "z_index"); + tile_data_z_index_editor->connect("needs_redraw", callable_mp((CanvasItem *)tile_atlas_control_unscaled, &Control::update)); + tile_data_z_index_editor->connect("needs_redraw", callable_mp((CanvasItem *)alternative_tiles_control_unscaled, &Control::update)); + tile_data_editors["z_index"] = tile_data_z_index_editor; + } + + ADD_TILE_DATA_EDITOR(group, "Y Sort Origin", "y_sort_origin"); + if (!tile_data_editors.has("y_sort_origin")) { + TileDataYSortEditor *tile_data_y_sort_editor = memnew(TileDataYSortEditor); + tile_data_y_sort_editor->hide(); + tile_data_y_sort_editor->setup_property_editor(Variant::INT, "y_sort_origin"); + tile_data_y_sort_editor->connect("needs_redraw", callable_mp((CanvasItem *)tile_atlas_control_unscaled, &Control::update)); + tile_data_y_sort_editor->connect("needs_redraw", callable_mp((CanvasItem *)alternative_tiles_control_unscaled, &Control::update)); + tile_data_editors["y_sort_origin"] = tile_data_y_sort_editor; + } + + for (int i = 0; i < tile_set->get_occlusion_layers_count(); i++) { + ADD_TILE_DATA_EDITOR(group, vformat("Occlusion Layer %d", i), vformat("occlusion_layer_%d", i)); + if (!tile_data_editors.has(vformat("occlusion_layer_%d", i))) { + TileDataOcclusionShapeEditor *tile_data_occlusion_shape_editor = memnew(TileDataOcclusionShapeEditor()); + tile_data_occlusion_shape_editor->hide(); + tile_data_occlusion_shape_editor->set_occlusion_layer(i); + tile_data_occlusion_shape_editor->connect("needs_redraw", callable_mp((CanvasItem *)tile_atlas_control_unscaled, &Control::update)); + tile_data_occlusion_shape_editor->connect("needs_redraw", callable_mp((CanvasItem *)alternative_tiles_control_unscaled, &Control::update)); + tile_data_editors[vformat("occlusion_layer_%d", i)] = tile_data_occlusion_shape_editor; + } + } + for (int i = tile_set->get_occlusion_layers_count(); tile_data_editors.has(vformat("occlusion_layer_%d", i)); i++) { + tile_data_editors[vformat("occlusion_layer_%d", i)]->queue_delete(); + tile_data_editors.erase(vformat("occlusion_layer_%d", i)); + } + + // --- Rendering --- + ADD_TILE_DATA_EDITOR(root, "Terrains", "terrain_set"); + if (!tile_data_editors.has("terrain_set")) { + TileDataTerrainsEditor *tile_data_terrains_editor = memnew(TileDataTerrainsEditor); + tile_data_terrains_editor->hide(); + tile_data_terrains_editor->connect("needs_redraw", callable_mp((CanvasItem *)tile_atlas_control_unscaled, &Control::update)); + tile_data_terrains_editor->connect("needs_redraw", callable_mp((CanvasItem *)alternative_tiles_control_unscaled, &Control::update)); + tile_data_editors["terrain_set"] = tile_data_terrains_editor; + } + + // --- Miscellaneous --- + ADD_TILE_DATA_EDITOR(root, "Probability", "probability"); + if (!tile_data_editors.has("probability")) { + TileDataDefaultEditor *tile_data_probability_editor = memnew(TileDataDefaultEditor()); + tile_data_probability_editor->hide(); + tile_data_probability_editor->setup_property_editor(Variant::FLOAT, "probability", "", 1.0); + tile_data_probability_editor->connect("needs_redraw", callable_mp((CanvasItem *)tile_atlas_control_unscaled, &Control::update)); + tile_data_probability_editor->connect("needs_redraw", callable_mp((CanvasItem *)alternative_tiles_control_unscaled, &Control::update)); + tile_data_editors["probability"] = tile_data_probability_editor; + } + + // --- Physics --- + ADD_TILE_DATA_EDITOR_GROUP("Physics"); + for (int i = 0; i < tile_set->get_physics_layers_count(); i++) { + ADD_TILE_DATA_EDITOR(group, vformat("Physics Layer %d", i), vformat("physics_layer_%d", i)); + if (!tile_data_editors.has(vformat("physics_layer_%d", i))) { + TileDataCollisionEditor *tile_data_collision_editor = memnew(TileDataCollisionEditor()); + tile_data_collision_editor->hide(); + tile_data_collision_editor->set_physics_layer(i); + tile_data_collision_editor->connect("needs_redraw", callable_mp((CanvasItem *)tile_atlas_control_unscaled, &Control::update)); + tile_data_collision_editor->connect("needs_redraw", callable_mp((CanvasItem *)alternative_tiles_control_unscaled, &Control::update)); + tile_data_editors[vformat("physics_layer_%d", i)] = tile_data_collision_editor; + } + } + for (int i = tile_set->get_physics_layers_count(); tile_data_editors.has(vformat("physics_layer_%d", i)); i++) { + tile_data_editors[vformat("physics_layer_%d", i)]->queue_delete(); + tile_data_editors.erase(vformat("physics_layer_%d", i)); + } + + // --- Navigation --- + ADD_TILE_DATA_EDITOR_GROUP("Navigation"); + for (int i = 0; i < tile_set->get_navigation_layers_count(); i++) { + ADD_TILE_DATA_EDITOR(group, vformat("Navigation Layer %d", i), vformat("navigation_layer_%d", i)); + if (!tile_data_editors.has(vformat("navigation_layer_%d", i))) { + TileDataNavigationEditor *tile_data_navigation_editor = memnew(TileDataNavigationEditor()); + tile_data_navigation_editor->hide(); + tile_data_navigation_editor->set_navigation_layer(i); + tile_data_navigation_editor->connect("needs_redraw", callable_mp((CanvasItem *)tile_atlas_control_unscaled, &Control::update)); + tile_data_navigation_editor->connect("needs_redraw", callable_mp((CanvasItem *)alternative_tiles_control_unscaled, &Control::update)); + tile_data_editors[vformat("navigation_layer_%d", i)] = tile_data_navigation_editor; + } + } + for (int i = tile_set->get_navigation_layers_count(); tile_data_editors.has(vformat("navigation_layer_%d", i)); i++) { + tile_data_editors[vformat("navigation_layer_%d", i)]->queue_delete(); + tile_data_editors.erase(vformat("navigation_layer_%d", i)); + } + + // --- Custom Data --- + ADD_TILE_DATA_EDITOR_GROUP("Custom Data"); + for (int i = 0; i < tile_set->get_custom_data_layers_count(); i++) { + if (tile_set->get_custom_data_name(i).is_empty()) { + ADD_TILE_DATA_EDITOR(group, vformat("Custom Data %d", i), vformat("custom_data_%d", i)); + } else { + ADD_TILE_DATA_EDITOR(group, tile_set->get_custom_data_name(i), vformat("custom_data_%d", i)); + } + if (!tile_data_editors.has(vformat("custom_data_%d", i))) { + TileDataDefaultEditor *tile_data_custom_data_editor = memnew(TileDataDefaultEditor()); + tile_data_custom_data_editor->hide(); + tile_data_custom_data_editor->setup_property_editor(tile_set->get_custom_data_type(i), vformat("custom_data_%d", i), tile_set->get_custom_data_name(i)); + tile_data_custom_data_editor->connect("needs_redraw", callable_mp((CanvasItem *)tile_atlas_control_unscaled, &Control::update)); + tile_data_custom_data_editor->connect("needs_redraw", callable_mp((CanvasItem *)alternative_tiles_control_unscaled, &Control::update)); + tile_data_editors[vformat("custom_data_%d", i)] = tile_data_custom_data_editor; + } + } + for (int i = tile_set->get_custom_data_layers_count(); tile_data_editors.has(vformat("custom_data_%d", i)); i++) { + tile_data_editors[vformat("custom_data_%d", i)]->queue_delete(); + tile_data_editors.erase(vformat("custom_data_%d", i)); + } + +#undef ADD_TILE_DATA_EDITOR_GROUP +#undef ADD_TILE_DATA_EDITOR + + // Add tile data editors as children. + for (Map<String, TileDataEditor *>::Element *E = tile_data_editors.front(); E; E = E->next()) { + // Tile Data Editor. + TileDataEditor *tile_data_editor = E->get(); + if (!tile_data_editor->is_inside_tree()) { + tile_data_painting_editor_container->add_child(tile_data_editor); + } + tile_data_editor->set_tile_set(tile_set); + + // Toolbar. + Control *toolbar = tile_data_editor->get_toolbar(); + if (!toolbar->is_inside_tree()) { + tool_settings_tile_data_toolbar_container->add_child(toolbar); + } + toolbar->hide(); } // Update visibility. - tile_inspector_label->set_visible(has_atlas_tile_selected); - tile_inspector->set_visible(has_atlas_tile_selected); + bool is_visible = tools_button_group->get_pressed_button() == tool_paint_button; + tile_data_editor_dropdown_button->set_visible(is_visible); + tile_data_editor_dropdown_button->set_text(TTR("Select a property editor")); + tile_data_editors_label->set_visible(is_visible); +} + +void TileSetAtlasSourceEditor::_update_current_tile_data_editor() { + // Find the property to use. + String property; + if (tools_button_group->get_pressed_button() == tool_select_button && tile_inspector->is_visible() && !tile_inspector->get_selected_path().is_empty()) { + Vector<String> components = tile_inspector->get_selected_path().split("/"); + if (components.size() >= 1) { + property = components[0]; + + // Workaround for terrains as they don't have a common first component. + if (property.begins_with("terrains_")) { + property = "terrain_set"; + } + } + } else if (tools_button_group->get_pressed_button() == tool_paint_button && tile_data_editors_tree->get_selected()) { + property = tile_data_editors_tree->get_selected()->get_metadata(0); + tile_data_editor_dropdown_button->set_text(tile_data_editors_tree->get_selected()->get_text(0)); + } + + // Hide all editors but the current one. + for (Map<String, TileDataEditor *>::Element *E = tile_data_editors.front(); E; E = E->next()) { + E->get()->hide(); + E->get()->get_toolbar()->hide(); + } + if (tile_data_editors.has(property)) { + current_tile_data_editor = tile_data_editors[property]; + } else { + current_tile_data_editor = nullptr; + } + + // Get the correct editor for the TileData's property. + if (current_tile_data_editor) { + current_tile_data_editor_toolbar = current_tile_data_editor->get_toolbar(); + current_property = property; + current_tile_data_editor->set_visible(tools_button_group->get_pressed_button() == tool_paint_button); + current_tile_data_editor_toolbar->set_visible(tools_button_group->get_pressed_button() == tool_paint_button); + } +} + +void TileSetAtlasSourceEditor::_tile_data_editor_dropdown_button_draw() { + if (!has_theme_icon("arrow", "OptionButton")) { + return; + } + + RID ci = tile_data_editor_dropdown_button->get_canvas_item(); + Ref<Texture2D> arrow = Control::get_theme_icon("arrow", "OptionButton"); + Color clr = Color(1, 1, 1); + if (get_theme_constant("modulate_arrow")) { + switch (tile_data_editor_dropdown_button->get_draw_mode()) { + case BaseButton::DRAW_PRESSED: + clr = get_theme_color("font_pressed_color"); + break; + case BaseButton::DRAW_HOVER: + clr = get_theme_color("font_hover_color"); + break; + case BaseButton::DRAW_DISABLED: + clr = get_theme_color("font_disabled_color"); + break; + default: + clr = get_theme_color("font_color"); + } + } + + Size2 size = tile_data_editor_dropdown_button->get_size(); + + Point2 ofs; + if (is_layout_rtl()) { + ofs = Point2(get_theme_constant("arrow_margin", "OptionButton"), int(Math::abs((size.height - arrow->get_height()) / 2))); + } else { + ofs = Point2(size.width - arrow->get_width() - get_theme_constant("arrow_margin", "OptionButton"), int(Math::abs((size.height - arrow->get_height()) / 2))); + } + arrow->draw(ci, ofs, clr); +} + +void TileSetAtlasSourceEditor::_tile_data_editor_dropdown_button_pressed() { + Size2 size = tile_data_editor_dropdown_button->get_size(); + tile_data_editors_popup->set_position(tile_data_editor_dropdown_button->get_screen_position() + Size2(0, size.height * get_global_transform().get_scale().y)); + tile_data_editors_popup->set_size(Size2(size.width, 0)); + tile_data_editors_popup->popup(); +} + +void TileSetAtlasSourceEditor::_tile_data_editors_tree_selected() { + tile_data_editors_popup->call_deferred("hide"); + _update_current_tile_data_editor(); + tile_atlas_control->update(); + tile_atlas_control_unscaled->update(); + alternative_tiles_control->update(); + alternative_tiles_control_unscaled->update(); } void TileSetAtlasSourceEditor::_update_atlas_view() { @@ -467,19 +766,28 @@ void TileSetAtlasSourceEditor::_update_atlas_view() { } void TileSetAtlasSourceEditor::_update_toolbar() { - // Hide all settings. - for (int i = 0; i < tool_settings->get_child_count(); i++) { - Object::cast_to<CanvasItem>(tool_settings->get_child(i))->hide(); - } - - // SHow only the correct settings. - if (tools_button_group->get_pressed_button() == tool_select_button) { - } else if (tools_button_group->get_pressed_button() == tool_add_remove_button) { - tool_settings_vsep->show(); - tools_settings_erase_button->show(); - } else if (tools_button_group->get_pressed_button() == tool_add_remove_rect_button) { + // Show the tools and settings. + if (tools_button_group->get_pressed_button() == tool_setup_atlas_source_button) { + if (current_tile_data_editor_toolbar) { + current_tile_data_editor_toolbar->hide(); + } tool_settings_vsep->show(); tools_settings_erase_button->show(); + tool_advanced_menu_buttom->show(); + } else if (tools_button_group->get_pressed_button() == tool_select_button) { + if (current_tile_data_editor_toolbar) { + current_tile_data_editor_toolbar->hide(); + } + tool_settings_vsep->hide(); + tools_settings_erase_button->hide(); + tool_advanced_menu_buttom->hide(); + } else if (tools_button_group->get_pressed_button() == tool_paint_button) { + if (current_tile_data_editor_toolbar) { + current_tile_data_editor_toolbar->show(); + } + tool_settings_vsep->hide(); + tools_settings_erase_button->hide(); + tool_advanced_menu_buttom->hide(); } } @@ -499,357 +807,336 @@ void TileSetAtlasSourceEditor::_tile_atlas_control_gui_input(const Ref<InputEven // Update the hovered coords. hovered_base_tile_coords = tile_atlas_view->get_atlas_tile_coords_at_pos(tile_atlas_control->get_local_mouse_position()); - // Handle the event. - Ref<InputEventMouseMotion> mm = p_event; - if (mm.is_valid()) { - Vector2i start_base_tiles_coords = tile_atlas_view->get_atlas_tile_coords_at_pos(drag_start_mouse_pos); - Vector2i last_base_tiles_coords = tile_atlas_view->get_atlas_tile_coords_at_pos(drag_last_mouse_pos); - Vector2i new_base_tiles_coords = tile_atlas_view->get_atlas_tile_coords_at_pos(tile_atlas_control->get_local_mouse_position()); + // Forward the event to the current tile data editor if we are in the painting mode. + if (tools_button_group->get_pressed_button() == tool_paint_button) { + if (current_tile_data_editor) { + current_tile_data_editor->forward_painting_atlas_gui_input(tile_atlas_view, tile_set_atlas_source, p_event); + } + // Update only what's needed. + tile_set_atlas_source_changed_needs_update = false; - Vector2i grid_size = tile_set_atlas_source->get_atlas_grid_size(); + tile_atlas_control->update(); + tile_atlas_control_unscaled->update(); + alternative_tiles_control->update(); + alternative_tiles_control_unscaled->update(); + tile_atlas_view->update(); + return; + } else { + // Handle the event. + Ref<InputEventMouseMotion> mm = p_event; + if (mm.is_valid()) { + Vector2i start_base_tiles_coords = tile_atlas_view->get_atlas_tile_coords_at_pos(drag_start_mouse_pos); + Vector2i last_base_tiles_coords = tile_atlas_view->get_atlas_tile_coords_at_pos(drag_last_mouse_pos); + Vector2i new_base_tiles_coords = tile_atlas_view->get_atlas_tile_coords_at_pos(tile_atlas_control->get_local_mouse_position()); - if (drag_type == DRAG_TYPE_NONE) { - if (selection.size() == 1) { - // Change the cursor depending on the hovered thing. - TileSelection selected = selection.front()->get(); - if (selected.tile != TileSetSource::INVALID_ATLAS_COORDS && selected.alternative == 0) { - Vector2 mouse_local_pos = tile_atlas_control->get_local_mouse_position(); - Vector2i size_in_atlas = tile_set_atlas_source->get_tile_size_in_atlas(selected.tile); - Rect2 region = tile_set_atlas_source->get_tile_texture_region(selected.tile); - Size2 zoomed_size = resize_handle->get_size() / tile_atlas_view->get_zoom(); - Rect2 rect = region.grow_individual(zoomed_size.x, zoomed_size.y, 0, 0); - const Vector2i coords[] = { Vector2i(0, 0), Vector2i(1, 0), Vector2i(1, 1), Vector2i(0, 1) }; - const Vector2i directions[] = { Vector2i(0, -1), Vector2i(1, 0), Vector2i(0, 1), Vector2i(-1, 0) }; - CursorShape cursor_shape = CURSOR_ARROW; - bool can_grow[4]; - for (int i = 0; i < 4; i++) { - can_grow[i] = tile_set_atlas_source->can_move_tile_in_atlas(selected.tile, selected.tile + directions[i]); - can_grow[i] |= (i % 2 == 0) ? size_in_atlas.y > 1 : size_in_atlas.x > 1; - } - for (int i = 0; i < 4; i++) { - Vector2 pos = rect.position + Vector2(rect.size.x, rect.size.y) * coords[i]; - if (can_grow[i] && can_grow[(i + 3) % 4] && Rect2(pos, zoomed_size).has_point(mouse_local_pos)) { - cursor_shape = (i % 2) ? CURSOR_BDIAGSIZE : CURSOR_FDIAGSIZE; + Vector2i grid_size = tile_set_atlas_source->get_atlas_grid_size(); + + if (drag_type == DRAG_TYPE_NONE) { + if (selection.size() == 1) { + // Change the cursor depending on the hovered thing. + TileSelection selected = selection.front()->get(); + if (selected.tile != TileSetSource::INVALID_ATLAS_COORDS && selected.alternative == 0) { + Vector2 mouse_local_pos = tile_atlas_control->get_local_mouse_position(); + Vector2i size_in_atlas = tile_set_atlas_source->get_tile_size_in_atlas(selected.tile); + Rect2 region = tile_set_atlas_source->get_tile_texture_region(selected.tile); + Size2 zoomed_size = resize_handle->get_size() / tile_atlas_view->get_zoom(); + Rect2 rect = region.grow_individual(zoomed_size.x, zoomed_size.y, 0, 0); + const Vector2i coords[] = { Vector2i(0, 0), Vector2i(1, 0), Vector2i(1, 1), Vector2i(0, 1) }; + const Vector2i directions[] = { Vector2i(0, -1), Vector2i(1, 0), Vector2i(0, 1), Vector2i(-1, 0) }; + CursorShape cursor_shape = CURSOR_ARROW; + bool can_grow[4]; + for (int i = 0; i < 4; i++) { + can_grow[i] = tile_set_atlas_source->can_move_tile_in_atlas(selected.tile, selected.tile + directions[i]); + can_grow[i] |= (i % 2 == 0) ? size_in_atlas.y > 1 : size_in_atlas.x > 1; } - Vector2 next_pos = rect.position + Vector2(rect.size.x, rect.size.y) * coords[(i + 1) % 4]; - if (can_grow[i] && Rect2((pos + next_pos) / 2.0, zoomed_size).has_point(mouse_local_pos)) { - cursor_shape = (i % 2) ? CURSOR_HSIZE : CURSOR_VSIZE; + for (int i = 0; i < 4; i++) { + Vector2 pos = rect.position + Vector2(rect.size.x, rect.size.y) * coords[i]; + if (can_grow[i] && can_grow[(i + 3) % 4] && Rect2(pos, zoomed_size).has_point(mouse_local_pos)) { + cursor_shape = (i % 2) ? CURSOR_BDIAGSIZE : CURSOR_FDIAGSIZE; + } + Vector2 next_pos = rect.position + Vector2(rect.size.x, rect.size.y) * coords[(i + 1) % 4]; + if (can_grow[i] && Rect2((pos + next_pos) / 2.0, zoomed_size).has_point(mouse_local_pos)) { + cursor_shape = (i % 2) ? CURSOR_HSIZE : CURSOR_VSIZE; + } } + tile_atlas_control->set_default_cursor_shape(cursor_shape); } - tile_atlas_control->set_default_cursor_shape(cursor_shape); } - } - } else if (drag_type == DRAG_TYPE_CREATE_BIG_TILE) { - // Create big tile. - new_base_tiles_coords = new_base_tiles_coords.max(Vector2i(0, 0)).min(grid_size - Vector2i(1, 1)); - - Rect2i new_rect = Rect2i(start_base_tiles_coords, new_base_tiles_coords - start_base_tiles_coords).abs(); - new_rect.size += Vector2i(1, 1); - // Check if the new tile can fit in the new rect. - if (tile_set_atlas_source->can_move_tile_in_atlas(drag_current_tile, new_rect.position, new_rect.size)) { - // Move and resize the tile. - tile_set_atlas_source->move_tile_in_atlas(drag_current_tile, new_rect.position, new_rect.size); - drag_current_tile = new_rect.position; - } - } else if (drag_type == DRAG_TYPE_CREATE_TILES) { - // Create tiles. - last_base_tiles_coords = last_base_tiles_coords.max(Vector2i(0, 0)).min(grid_size - Vector2i(1, 1)); - new_base_tiles_coords = new_base_tiles_coords.max(Vector2i(0, 0)).min(grid_size - Vector2i(1, 1)); - - Vector<Point2i> line = Geometry2D::bresenham_line(last_base_tiles_coords, new_base_tiles_coords); - for (int i = 0; i < line.size(); i++) { - if (tile_set_atlas_source->get_tile_at_coords(line[i]) == TileSetSource::INVALID_ATLAS_COORDS) { - tile_set_atlas_source->create_tile(line[i]); - drag_modified_tiles.insert(line[i]); + } else if (drag_type == DRAG_TYPE_CREATE_BIG_TILE) { + // Create big tile. + new_base_tiles_coords = new_base_tiles_coords.max(Vector2i(0, 0)).min(grid_size - Vector2i(1, 1)); + + Rect2i new_rect = Rect2i(start_base_tiles_coords, new_base_tiles_coords - start_base_tiles_coords).abs(); + new_rect.size += Vector2i(1, 1); + // Check if the new tile can fit in the new rect. + if (tile_set_atlas_source->can_move_tile_in_atlas(drag_current_tile, new_rect.position, new_rect.size)) { + // Move and resize the tile. + tile_set_atlas_source->move_tile_in_atlas(drag_current_tile, new_rect.position, new_rect.size); + drag_current_tile = new_rect.position; + } + } else if (drag_type == DRAG_TYPE_CREATE_TILES) { + // Create tiles. + last_base_tiles_coords = last_base_tiles_coords.max(Vector2i(0, 0)).min(grid_size - Vector2i(1, 1)); + new_base_tiles_coords = new_base_tiles_coords.max(Vector2i(0, 0)).min(grid_size - Vector2i(1, 1)); + + Vector<Point2i> line = Geometry2D::bresenham_line(last_base_tiles_coords, new_base_tiles_coords); + for (int i = 0; i < line.size(); i++) { + if (tile_set_atlas_source->get_tile_at_coords(line[i]) == TileSetSource::INVALID_ATLAS_COORDS) { + tile_set_atlas_source->create_tile(line[i]); + drag_modified_tiles.insert(line[i]); + } } - } - drag_last_mouse_pos = tile_atlas_control->get_local_mouse_position(); + drag_last_mouse_pos = tile_atlas_control->get_local_mouse_position(); - } else if (drag_type == DRAG_TYPE_REMOVE_TILES) { - // Remove tiles. - last_base_tiles_coords = last_base_tiles_coords.max(Vector2i(0, 0)).min(grid_size - Vector2i(1, 1)); - new_base_tiles_coords = new_base_tiles_coords.max(Vector2i(0, 0)).min(grid_size - Vector2i(1, 1)); + } else if (drag_type == DRAG_TYPE_REMOVE_TILES) { + // Remove tiles. + last_base_tiles_coords = last_base_tiles_coords.max(Vector2i(0, 0)).min(grid_size - Vector2i(1, 1)); + new_base_tiles_coords = new_base_tiles_coords.max(Vector2i(0, 0)).min(grid_size - Vector2i(1, 1)); - Vector<Point2i> line = Geometry2D::bresenham_line(last_base_tiles_coords, new_base_tiles_coords); - for (int i = 0; i < line.size(); i++) { - Vector2i base_tile_coords = tile_set_atlas_source->get_tile_at_coords(line[i]); - if (base_tile_coords != TileSetSource::INVALID_ATLAS_COORDS) { - drag_modified_tiles.insert(base_tile_coords); + Vector<Point2i> line = Geometry2D::bresenham_line(last_base_tiles_coords, new_base_tiles_coords); + for (int i = 0; i < line.size(); i++) { + Vector2i base_tile_coords = tile_set_atlas_source->get_tile_at_coords(line[i]); + if (base_tile_coords != TileSetSource::INVALID_ATLAS_COORDS) { + drag_modified_tiles.insert(base_tile_coords); + } } - } - drag_last_mouse_pos = tile_atlas_control->get_local_mouse_position(); - } else if (drag_type == DRAG_TYPE_MOVE_TILE) { - // Move tile. - Vector2 mouse_offset = (Vector2(tile_set_atlas_source->get_tile_size_in_atlas(drag_current_tile)) / 2.0 - Vector2(0.5, 0.5)) * tile_set->get_tile_size(); - Vector2i coords = tile_atlas_view->get_atlas_tile_coords_at_pos(tile_atlas_control->get_local_mouse_position() - mouse_offset); - coords = coords.max(Vector2i(0, 0)).min(grid_size - Vector2i(1, 1)); - if (drag_current_tile != coords && tile_set_atlas_source->can_move_tile_in_atlas(drag_current_tile, coords)) { - tile_set_atlas_source->move_tile_in_atlas(drag_current_tile, coords); - selection.clear(); - selection.insert({ coords, 0 }); - drag_current_tile = coords; + drag_last_mouse_pos = tile_atlas_control->get_local_mouse_position(); + } else if (drag_type == DRAG_TYPE_MOVE_TILE) { + // Move tile. + Vector2 mouse_offset = (Vector2(tile_set_atlas_source->get_tile_size_in_atlas(drag_current_tile)) / 2.0 - Vector2(0.5, 0.5)) * tile_set->get_tile_size(); + Vector2i coords = tile_atlas_view->get_atlas_tile_coords_at_pos(tile_atlas_control->get_local_mouse_position() - mouse_offset); + coords = coords.max(Vector2i(0, 0)).min(grid_size - Vector2i(1, 1)); + if (drag_current_tile != coords && tile_set_atlas_source->can_move_tile_in_atlas(drag_current_tile, coords)) { + tile_set_atlas_source->move_tile_in_atlas(drag_current_tile, coords); + selection.clear(); + selection.insert({ coords, 0 }); + drag_current_tile = coords; - // Update only what's needed. - tile_set_atlas_source_changed_needs_update = false; - _update_tile_inspector(); - _update_atlas_view(); - _update_tile_id_label(); - } - } else if (drag_type >= DRAG_TYPE_RESIZE_TOP_LEFT && drag_type <= DRAG_TYPE_RESIZE_LEFT) { - // Resizing a tile. - new_base_tiles_coords = new_base_tiles_coords.max(Vector2i(-1, -1)).min(grid_size); + // Update only what's needed. + tile_set_atlas_source_changed_needs_update = false; + _update_tile_inspector(); + _update_atlas_view(); + _update_tile_id_label(); + _update_current_tile_data_editor(); + } + } else if (drag_type == DRAG_TYPE_MAY_POPUP_MENU) { + if (Vector2(drag_start_mouse_pos).distance_to(tile_atlas_control->get_local_mouse_position()) > 5.0 * EDSCALE) { + drag_type = DRAG_TYPE_NONE; + } + } else if (drag_type >= DRAG_TYPE_RESIZE_TOP_LEFT && drag_type <= DRAG_TYPE_RESIZE_LEFT) { + // Resizing a tile. + new_base_tiles_coords = new_base_tiles_coords.max(Vector2i(-1, -1)).min(grid_size); - Rect2i old_rect = Rect2i(drag_current_tile, tile_set_atlas_source->get_tile_size_in_atlas(drag_current_tile)); - Rect2i new_rect = old_rect; + Rect2i old_rect = Rect2i(drag_current_tile, tile_set_atlas_source->get_tile_size_in_atlas(drag_current_tile)); + Rect2i new_rect = old_rect; - if (drag_type == DRAG_TYPE_RESIZE_LEFT || drag_type == DRAG_TYPE_RESIZE_TOP_LEFT || drag_type == DRAG_TYPE_RESIZE_BOTTOM_LEFT) { - new_rect.position.x = MIN(new_base_tiles_coords.x + 1, old_rect.get_end().x - 1); - new_rect.size.x = old_rect.get_end().x - new_rect.position.x; - } - if (drag_type == DRAG_TYPE_RESIZE_TOP || drag_type == DRAG_TYPE_RESIZE_TOP_LEFT || drag_type == DRAG_TYPE_RESIZE_TOP_RIGHT) { - new_rect.position.y = MIN(new_base_tiles_coords.y + 1, old_rect.get_end().y - 1); - new_rect.size.y = old_rect.get_end().y - new_rect.position.y; - } + if (drag_type == DRAG_TYPE_RESIZE_LEFT || drag_type == DRAG_TYPE_RESIZE_TOP_LEFT || drag_type == DRAG_TYPE_RESIZE_BOTTOM_LEFT) { + new_rect.position.x = MIN(new_base_tiles_coords.x + 1, old_rect.get_end().x - 1); + new_rect.size.x = old_rect.get_end().x - new_rect.position.x; + } + if (drag_type == DRAG_TYPE_RESIZE_TOP || drag_type == DRAG_TYPE_RESIZE_TOP_LEFT || drag_type == DRAG_TYPE_RESIZE_TOP_RIGHT) { + new_rect.position.y = MIN(new_base_tiles_coords.y + 1, old_rect.get_end().y - 1); + new_rect.size.y = old_rect.get_end().y - new_rect.position.y; + } - if (drag_type == DRAG_TYPE_RESIZE_RIGHT || drag_type == DRAG_TYPE_RESIZE_TOP_RIGHT || drag_type == DRAG_TYPE_RESIZE_BOTTOM_RIGHT) { - new_rect.set_end(Vector2i(MAX(new_base_tiles_coords.x, old_rect.position.x + 1), new_rect.get_end().y)); - } - if (drag_type == DRAG_TYPE_RESIZE_BOTTOM || drag_type == DRAG_TYPE_RESIZE_BOTTOM_LEFT || drag_type == DRAG_TYPE_RESIZE_BOTTOM_RIGHT) { - new_rect.set_end(Vector2i(new_rect.get_end().x, MAX(new_base_tiles_coords.y, old_rect.position.y + 1))); - } + if (drag_type == DRAG_TYPE_RESIZE_RIGHT || drag_type == DRAG_TYPE_RESIZE_TOP_RIGHT || drag_type == DRAG_TYPE_RESIZE_BOTTOM_RIGHT) { + new_rect.set_end(Vector2i(MAX(new_base_tiles_coords.x, old_rect.position.x + 1), new_rect.get_end().y)); + } + if (drag_type == DRAG_TYPE_RESIZE_BOTTOM || drag_type == DRAG_TYPE_RESIZE_BOTTOM_LEFT || drag_type == DRAG_TYPE_RESIZE_BOTTOM_RIGHT) { + new_rect.set_end(Vector2i(new_rect.get_end().x, MAX(new_base_tiles_coords.y, old_rect.position.y + 1))); + } - if (tile_set_atlas_source->can_move_tile_in_atlas(drag_current_tile, new_rect.position, new_rect.size)) { - tile_set_atlas_source->move_tile_in_atlas(drag_current_tile, new_rect.position, new_rect.size); - selection.clear(); - selection.insert({ new_rect.position, 0 }); - drag_current_tile = new_rect.position; + if (tile_set_atlas_source->can_move_tile_in_atlas(drag_current_tile, new_rect.position, new_rect.size)) { + tile_set_atlas_source->move_tile_in_atlas(drag_current_tile, new_rect.position, new_rect.size); + selection.clear(); + selection.insert({ new_rect.position, 0 }); + drag_current_tile = new_rect.position; - // Update only what's needed. - tile_set_atlas_source_changed_needs_update = false; - _update_tile_inspector(); - _update_atlas_view(); - _update_tile_id_label(); + // Update only what's needed. + tile_set_atlas_source_changed_needs_update = false; + _update_tile_inspector(); + _update_atlas_view(); + _update_tile_id_label(); + _update_current_tile_data_editor(); + } } + + // Redraw for the hovered tile. + tile_atlas_control->update(); + tile_atlas_control_unscaled->update(); + alternative_tiles_control->update(); + alternative_tiles_control_unscaled->update(); + tile_atlas_view->update(); + return; } - // Redraw for the hovered tile. - tile_atlas_control->update(); - tile_atlas_control_unscaled->update(); - alternative_tiles_control->update(); - alternative_tiles_control_unscaled->update(); - tile_atlas_view->update(); - return; - } + Ref<InputEventMouseButton> mb = p_event; + if (mb.is_valid()) { + Vector2 mouse_local_pos = tile_atlas_control->get_local_mouse_position(); + if (mb->get_button_index() == MOUSE_BUTTON_LEFT) { + if (mb->is_pressed()) { + // Left click pressed. + if (tools_button_group->get_pressed_button() == tool_setup_atlas_source_button) { + if (tools_settings_erase_button->is_pressed()) { + // Erasing + if (mb->is_ctrl_pressed() || mb->is_shift_pressed()) { + // Remove tiles using rect. + + // Setup the dragging info. + drag_type = DRAG_TYPE_REMOVE_TILES_USING_RECT; + drag_start_mouse_pos = mouse_local_pos; + drag_last_mouse_pos = drag_start_mouse_pos; + } else { + // Remove tiles. - Ref<InputEventMouseButton> mb = p_event; - if (mb.is_valid()) { - Vector2 mouse_local_pos = tile_atlas_control->get_local_mouse_position(); - if (mb->get_button_index() == MOUSE_BUTTON_LEFT) { - if (mb->is_pressed()) { - // Left click pressed. - if (tools_button_group->get_pressed_button() == tool_add_remove_button) { - if (tools_settings_erase_button->is_pressed()) { - // Remove tiles. - - // Setup the dragging info. - drag_type = DRAG_TYPE_REMOVE_TILES; - drag_start_mouse_pos = mouse_local_pos; - drag_last_mouse_pos = drag_start_mouse_pos; - - // Remove a first tile. - Vector2i coords = tile_atlas_view->get_atlas_tile_coords_at_pos(drag_start_mouse_pos); - if (coords != TileSetSource::INVALID_ATLAS_COORDS) { - coords = tile_set_atlas_source->get_tile_at_coords(coords); - } - if (coords != TileSetSource::INVALID_ATLAS_COORDS) { - drag_modified_tiles.insert(coords); - } - } else { - if (mb->is_shift_pressed()) { - // Create a big tile. - Vector2i coords = tile_atlas_view->get_atlas_tile_coords_at_pos(mouse_local_pos); - if (coords != TileSetSource::INVALID_ATLAS_COORDS && tile_set_atlas_source->get_tile_at_coords(coords) == TileSetSource::INVALID_ATLAS_COORDS) { - // Setup the dragging info, only if we start on an empty tile. - drag_type = DRAG_TYPE_CREATE_BIG_TILE; + // Setup the dragging info. + drag_type = DRAG_TYPE_REMOVE_TILES; drag_start_mouse_pos = mouse_local_pos; drag_last_mouse_pos = drag_start_mouse_pos; - drag_current_tile = coords; - // Create a tile. - tile_set_atlas_source->create_tile(coords); + // Remove a first tile. + Vector2i coords = tile_atlas_view->get_atlas_tile_coords_at_pos(drag_start_mouse_pos); + if (coords != TileSetSource::INVALID_ATLAS_COORDS) { + coords = tile_set_atlas_source->get_tile_at_coords(coords); + } + if (coords != TileSetSource::INVALID_ATLAS_COORDS) { + drag_modified_tiles.insert(coords); + } } } else { - // Create tiles. - - // Setup the dragging info. - drag_type = DRAG_TYPE_CREATE_TILES; - drag_start_mouse_pos = mouse_local_pos; - drag_last_mouse_pos = drag_start_mouse_pos; - - // Create a first tile if needed. - Vector2i coords = tile_atlas_view->get_atlas_tile_coords_at_pos(drag_start_mouse_pos); - if (coords != TileSetSource::INVALID_ATLAS_COORDS && tile_set_atlas_source->get_tile_at_coords(coords) == TileSetSource::INVALID_ATLAS_COORDS) { - tile_set_atlas_source->create_tile(coords); - drag_modified_tiles.insert(coords); - } - } - } - } else if (tools_button_group->get_pressed_button() == tool_add_remove_rect_button) { - if (tools_settings_erase_button->is_pressed()) { - // Remove tiles using rect. - - // Setup the dragging info. - drag_type = DRAG_TYPE_REMOVE_TILES_USING_RECT; - drag_start_mouse_pos = mouse_local_pos; - drag_last_mouse_pos = drag_start_mouse_pos; - } else { - if (mb->is_shift_pressed()) { - // Create a big tile. - Vector2i coords = tile_atlas_view->get_atlas_tile_coords_at_pos(mouse_local_pos); - if (coords != TileSetSource::INVALID_ATLAS_COORDS && tile_set_atlas_source->get_tile_at_coords(coords) == TileSetSource::INVALID_ATLAS_COORDS) { - // Setup the dragging info, only if we start on an empty tile. - drag_type = DRAG_TYPE_CREATE_BIG_TILE; + // Creating + if (mb->is_shift_pressed()) { + // Create a big tile. + Vector2i coords = tile_atlas_view->get_atlas_tile_coords_at_pos(mouse_local_pos); + if (coords != TileSetSource::INVALID_ATLAS_COORDS && tile_set_atlas_source->get_tile_at_coords(coords) == TileSetSource::INVALID_ATLAS_COORDS) { + // Setup the dragging info, only if we start on an empty tile. + drag_type = DRAG_TYPE_CREATE_BIG_TILE; + drag_start_mouse_pos = mouse_local_pos; + drag_last_mouse_pos = drag_start_mouse_pos; + drag_current_tile = coords; + + // Create a tile. + tile_set_atlas_source->create_tile(coords); + } + } else if (mb->is_ctrl_pressed()) { + // Create tiles using rect. + drag_type = DRAG_TYPE_CREATE_TILES_USING_RECT; drag_start_mouse_pos = mouse_local_pos; drag_last_mouse_pos = drag_start_mouse_pos; - drag_current_tile = coords; + } else { + // Create tiles. - // Create a tile. - tile_set_atlas_source->create_tile(coords); + // Setup the dragging info. + drag_type = DRAG_TYPE_CREATE_TILES; + drag_start_mouse_pos = mouse_local_pos; + drag_last_mouse_pos = drag_start_mouse_pos; + + // Create a first tile if needed. + Vector2i coords = tile_atlas_view->get_atlas_tile_coords_at_pos(drag_start_mouse_pos); + if (coords != TileSetSource::INVALID_ATLAS_COORDS && tile_set_atlas_source->get_tile_at_coords(coords) == TileSetSource::INVALID_ATLAS_COORDS) { + tile_set_atlas_source->create_tile(coords); + drag_modified_tiles.insert(coords); + } } - } else { - // Create tiles using rect. - drag_type = DRAG_TYPE_CREATE_TILES_USING_RECT; - drag_start_mouse_pos = mouse_local_pos; - drag_last_mouse_pos = drag_start_mouse_pos; } - } - } else if (tools_button_group->get_pressed_button() == tool_select_button) { - // Dragging a handle. - drag_type = DRAG_TYPE_NONE; - if (selection.size() == 1) { - TileSelection selected = selection.front()->get(); - if (selected.tile != TileSetSource::INVALID_ATLAS_COORDS && selected.alternative == 0) { - Vector2i size_in_atlas = tile_set_atlas_source->get_tile_size_in_atlas(selected.tile); - Rect2 region = tile_set_atlas_source->get_tile_texture_region(selected.tile); - Size2 zoomed_size = resize_handle->get_size() / tile_atlas_view->get_zoom(); - Rect2 rect = region.grow_individual(zoomed_size.x, zoomed_size.y, 0, 0); - const Vector2i coords[] = { Vector2i(0, 0), Vector2i(1, 0), Vector2i(1, 1), Vector2i(0, 1) }; - const Vector2i directions[] = { Vector2i(0, -1), Vector2i(1, 0), Vector2i(0, 1), Vector2i(-1, 0) }; - CursorShape cursor_shape = CURSOR_ARROW; - bool can_grow[4]; - for (int i = 0; i < 4; i++) { - can_grow[i] = tile_set_atlas_source->can_move_tile_in_atlas(selected.tile, selected.tile + directions[i]); - can_grow[i] |= (i % 2 == 0) ? size_in_atlas.y > 1 : size_in_atlas.x > 1; - } - for (int i = 0; i < 4; i++) { - Vector2 pos = rect.position + Vector2(rect.size.x, rect.size.y) * coords[i]; - if (can_grow[i] && can_grow[(i + 3) % 4] && Rect2(pos, zoomed_size).has_point(mouse_local_pos)) { - drag_type = (DragType)((int)DRAG_TYPE_RESIZE_TOP_LEFT + i * 2); - drag_start_mouse_pos = mouse_local_pos; - drag_last_mouse_pos = drag_start_mouse_pos; - drag_current_tile = selected.tile; - drag_start_tile_shape = Rect2i(selected.tile, tile_set_atlas_source->get_tile_size_in_atlas(selected.tile)); - cursor_shape = (i % 2) ? CURSOR_BDIAGSIZE : CURSOR_FDIAGSIZE; + } else if (tools_button_group->get_pressed_button() == tool_select_button) { + // Dragging a handle. + drag_type = DRAG_TYPE_NONE; + if (selection.size() == 1) { + TileSelection selected = selection.front()->get(); + if (selected.tile != TileSetSource::INVALID_ATLAS_COORDS && selected.alternative == 0) { + Vector2i size_in_atlas = tile_set_atlas_source->get_tile_size_in_atlas(selected.tile); + Rect2 region = tile_set_atlas_source->get_tile_texture_region(selected.tile); + Size2 zoomed_size = resize_handle->get_size() / tile_atlas_view->get_zoom(); + Rect2 rect = region.grow_individual(zoomed_size.x, zoomed_size.y, 0, 0); + const Vector2i coords[] = { Vector2i(0, 0), Vector2i(1, 0), Vector2i(1, 1), Vector2i(0, 1) }; + const Vector2i directions[] = { Vector2i(0, -1), Vector2i(1, 0), Vector2i(0, 1), Vector2i(-1, 0) }; + CursorShape cursor_shape = CURSOR_ARROW; + bool can_grow[4]; + for (int i = 0; i < 4; i++) { + can_grow[i] = tile_set_atlas_source->can_move_tile_in_atlas(selected.tile, selected.tile + directions[i]); + can_grow[i] |= (i % 2 == 0) ? size_in_atlas.y > 1 : size_in_atlas.x > 1; } - Vector2 next_pos = rect.position + Vector2(rect.size.x, rect.size.y) * coords[(i + 1) % 4]; - if (can_grow[i] && Rect2((pos + next_pos) / 2.0, zoomed_size).has_point(mouse_local_pos)) { - drag_type = (DragType)((int)DRAG_TYPE_RESIZE_TOP + i * 2); - drag_start_mouse_pos = mouse_local_pos; - drag_last_mouse_pos = drag_start_mouse_pos; - drag_current_tile = selected.tile; - drag_start_tile_shape = Rect2i(selected.tile, tile_set_atlas_source->get_tile_size_in_atlas(selected.tile)); - cursor_shape = (i % 2) ? CURSOR_HSIZE : CURSOR_VSIZE; + for (int i = 0; i < 4; i++) { + Vector2 pos = rect.position + Vector2(rect.size.x, rect.size.y) * coords[i]; + if (can_grow[i] && can_grow[(i + 3) % 4] && Rect2(pos, zoomed_size).has_point(mouse_local_pos)) { + drag_type = (DragType)((int)DRAG_TYPE_RESIZE_TOP_LEFT + i * 2); + drag_start_mouse_pos = mouse_local_pos; + drag_last_mouse_pos = drag_start_mouse_pos; + drag_current_tile = selected.tile; + drag_start_tile_shape = Rect2i(selected.tile, tile_set_atlas_source->get_tile_size_in_atlas(selected.tile)); + cursor_shape = (i % 2) ? CURSOR_BDIAGSIZE : CURSOR_FDIAGSIZE; + } + Vector2 next_pos = rect.position + Vector2(rect.size.x, rect.size.y) * coords[(i + 1) % 4]; + if (can_grow[i] && Rect2((pos + next_pos) / 2.0, zoomed_size).has_point(mouse_local_pos)) { + drag_type = (DragType)((int)DRAG_TYPE_RESIZE_TOP + i * 2); + drag_start_mouse_pos = mouse_local_pos; + drag_last_mouse_pos = drag_start_mouse_pos; + drag_current_tile = selected.tile; + drag_start_tile_shape = Rect2i(selected.tile, tile_set_atlas_source->get_tile_size_in_atlas(selected.tile)); + cursor_shape = (i % 2) ? CURSOR_HSIZE : CURSOR_VSIZE; + } } + tile_atlas_control->set_default_cursor_shape(cursor_shape); } - tile_atlas_control->set_default_cursor_shape(cursor_shape); } - } - // Selecting then dragging a tile. - if (drag_type == DRAG_TYPE_NONE) { - TileSelection selected = { TileSetSource::INVALID_ATLAS_COORDS, TileSetSource::INVALID_TILE_ALTERNATIVE }; - Vector2i coords = tile_atlas_view->get_atlas_tile_coords_at_pos(mouse_local_pos); - if (coords != TileSetSource::INVALID_ATLAS_COORDS) { - coords = tile_set_atlas_source->get_tile_at_coords(coords); + // Selecting then dragging a tile. + if (drag_type == DRAG_TYPE_NONE) { + TileSelection selected = { TileSetSource::INVALID_ATLAS_COORDS, TileSetSource::INVALID_TILE_ALTERNATIVE }; + Vector2i coords = tile_atlas_view->get_atlas_tile_coords_at_pos(mouse_local_pos); if (coords != TileSetSource::INVALID_ATLAS_COORDS) { - selected = { coords, 0 }; + coords = tile_set_atlas_source->get_tile_at_coords(coords); + if (coords != TileSetSource::INVALID_ATLAS_COORDS) { + selected = { coords, 0 }; + } } - } - bool shift = mb->is_shift_pressed(); - if (!shift && selection.size() == 1 && selected.tile != TileSetSource::INVALID_ATLAS_COORDS && selection.has(selected)) { - // Start move dragging. - drag_type = DRAG_TYPE_MOVE_TILE; - drag_start_mouse_pos = mouse_local_pos; - drag_last_mouse_pos = drag_start_mouse_pos; - drag_current_tile = selected.tile; - drag_start_tile_shape = Rect2i(selected.tile, tile_set_atlas_source->get_tile_size_in_atlas(selected.tile)); - tile_atlas_control->set_default_cursor_shape(CURSOR_MOVE); - } else { - // Start selection dragging. - drag_type = DRAG_TYPE_RECT_SELECT; - drag_start_mouse_pos = mouse_local_pos; - drag_last_mouse_pos = drag_start_mouse_pos; + bool shift = mb->is_shift_pressed(); + if (!shift && selection.size() == 1 && selected.tile != TileSetSource::INVALID_ATLAS_COORDS && selection.has(selected)) { + // Start move dragging. + drag_type = DRAG_TYPE_MOVE_TILE; + drag_start_mouse_pos = mouse_local_pos; + drag_last_mouse_pos = drag_start_mouse_pos; + drag_current_tile = selected.tile; + drag_start_tile_shape = Rect2i(selected.tile, tile_set_atlas_source->get_tile_size_in_atlas(selected.tile)); + tile_atlas_control->set_default_cursor_shape(CURSOR_MOVE); + } else { + // Start selection dragging. + drag_type = DRAG_TYPE_RECT_SELECT; + drag_start_mouse_pos = mouse_local_pos; + drag_last_mouse_pos = drag_start_mouse_pos; + } } } + } else { + // Left click released. + _end_dragging(); } - } else { - // Left click released. - _end_dragging(); - } - tile_atlas_control->update(); - tile_atlas_control_unscaled->update(); - alternative_tiles_control->update(); - alternative_tiles_control_unscaled->update(); - tile_atlas_view->update(); - return; - } else if (mb->get_button_index() == MOUSE_BUTTON_RIGHT) { - if (mb->is_pressed()) { + tile_atlas_control->update(); + tile_atlas_control_unscaled->update(); + alternative_tiles_control->update(); + alternative_tiles_control_unscaled->update(); + tile_atlas_view->update(); + return; + } else if (mb->get_button_index() == MOUSE_BUTTON_RIGHT) { // Right click pressed. - - TileSelection selected = { tile_atlas_view->get_atlas_tile_coords_at_pos(mouse_local_pos), 0 }; - if (selected.tile != TileSetSource::INVALID_ATLAS_COORDS) { - selected.tile = tile_set_atlas_source->get_tile_at_coords(selected.tile); - } - - // Set the selection if needed. - if (selection.size() <= 1) { - if (selected.tile != TileSetSource::INVALID_ATLAS_COORDS) { - undo_redo->create_action(TTR("Select tiles")); - undo_redo->add_undo_method(this, "_set_selection_from_array", _get_selection_as_array()); - selection.clear(); - selection.insert(selected); - undo_redo->add_do_method(this, "_set_selection_from_array", _get_selection_as_array()); - undo_redo->commit_action(false); - _update_tile_inspector(); - _update_tile_id_label(); - } - } - - // Pops up the correct menu, depending on whether we have a tile or not. - if (selected.tile != TileSetSource::INVALID_ATLAS_COORDS && selection.has(selected)) { - // We have a tile. - menu_option_coords = selected.tile; - menu_option_alternative = 0; - base_tile_popup_menu->popup(Rect2i(get_global_mouse_position(), Size2i())); - } else if (hovered_base_tile_coords != TileSetSource::INVALID_ATLAS_COORDS) { - // We don't have a tile, but can create one. - menu_option_coords = hovered_base_tile_coords; - menu_option_alternative = TileSetSource::INVALID_TILE_ALTERNATIVE; - empty_base_tile_popup_menu->popup(Rect2i(get_global_mouse_position(), Size2i())); + if (mb->is_pressed()) { + drag_type = DRAG_TYPE_MAY_POPUP_MENU; + drag_start_mouse_pos = tile_atlas_control->get_local_mouse_position(); + } else { + // Right click released. + _end_dragging(); } - } else { - // Right click released. - _end_dragging(); + tile_atlas_control->update(); + tile_atlas_control_unscaled->update(); + alternative_tiles_control->update(); + alternative_tiles_control_unscaled->update(); + tile_atlas_view->update(); + return; } - tile_atlas_control->update(); - tile_atlas_control_unscaled->update(); - alternative_tiles_control->update(); - alternative_tiles_control_unscaled->update(); - tile_atlas_view->update(); - return; } } } @@ -1000,10 +1287,45 @@ void TileSetAtlasSourceEditor::_end_dragging() { } _update_tile_inspector(); _update_tile_id_label(); + _update_current_tile_data_editor(); undo_redo->add_do_method(this, "_set_selection_from_array", _get_selection_as_array()); undo_redo->commit_action(false); - break; - } + } break; + case DRAG_TYPE_MAY_POPUP_MENU: { + Vector2 mouse_local_pos = tile_atlas_control->get_local_mouse_position(); + TileSelection selected = { tile_atlas_view->get_atlas_tile_coords_at_pos(mouse_local_pos), 0 }; + if (selected.tile != TileSetSource::INVALID_ATLAS_COORDS) { + selected.tile = tile_set_atlas_source->get_tile_at_coords(selected.tile); + } + + // Set the selection if needed. + if (selection.size() <= 1) { + if (selected.tile != TileSetSource::INVALID_ATLAS_COORDS) { + undo_redo->create_action(TTR("Select tiles")); + undo_redo->add_undo_method(this, "_set_selection_from_array", _get_selection_as_array()); + selection.clear(); + selection.insert(selected); + undo_redo->add_do_method(this, "_set_selection_from_array", _get_selection_as_array()); + undo_redo->commit_action(false); + _update_tile_inspector(); + _update_tile_id_label(); + _update_current_tile_data_editor(); + } + } + + // Pops up the correct menu, depending on whether we have a tile or not. + if (selected.tile != TileSetSource::INVALID_ATLAS_COORDS && selection.has(selected)) { + // We have a tile. + menu_option_coords = selected.tile; + menu_option_alternative = 0; + base_tile_popup_menu->popup(Rect2i(get_global_mouse_position(), Size2i())); + } else if (hovered_base_tile_coords != TileSetSource::INVALID_ATLAS_COORDS) { + // We don't have a tile, but can create one. + menu_option_coords = hovered_base_tile_coords; + menu_option_alternative = TileSetSource::INVALID_TILE_ALTERNATIVE; + empty_base_tile_popup_menu->popup(Rect2i(get_global_mouse_position(), Size2i())); + } + } break; case DRAG_TYPE_RESIZE_TOP_LEFT: case DRAG_TYPE_RESIZE_TOP: case DRAG_TYPE_RESIZE_TOP_RIGHT: @@ -1166,6 +1488,7 @@ void TileSetAtlasSourceEditor::_set_selection_from_array(Array p_selection) { _update_tile_inspector(); _update_tile_id_label(); _update_atlas_view(); + _update_current_tile_data_editor(); } Array TileSetAtlasSourceEditor::_get_selection_as_array() { @@ -1297,7 +1620,7 @@ void TileSetAtlasSourceEditor::_tile_atlas_control_draw() { tile_atlas_control->draw_rect(tile_set_atlas_source->get_tile_texture_region(hovered_tile), Color(1.0, 1.0, 1.0), false); } else { // Draw empty tile, only in add/remove tiles mode. - if (tools_button_group->get_pressed_button() == tool_add_remove_button || tools_button_group->get_pressed_button() == tool_add_remove_rect_button) { + if (tools_button_group->get_pressed_button() == tool_setup_atlas_source_button) { Vector2i margins = tile_set_atlas_source->get_margins(); Vector2i separation = tile_set_atlas_source->get_separation(); Vector2i tile_size = tile_set_atlas_source->get_texture_region_size(); @@ -1310,9 +1633,8 @@ void TileSetAtlasSourceEditor::_tile_atlas_control_draw() { } void TileSetAtlasSourceEditor::_tile_atlas_control_unscaled_draw() { - // Draw the preview of the selected property. - TileDataEditor *tile_data_editor = TileSetEditor::get_singleton()->get_tile_data_editor(selected_property); - if (tile_data_editor && tile_inspector->is_visible_in_tree()) { + if (current_tile_data_editor) { + // Draw the preview of the selected property. for (int i = 0; i < tile_set_atlas_source->get_tiles_count(); i++) { Vector2i coords = tile_set_atlas_source->get_tile_id(i); Rect2i texture_region = tile_set_atlas_source->get_tile_texture_region(coords); @@ -1321,7 +1643,41 @@ void TileSetAtlasSourceEditor::_tile_atlas_control_unscaled_draw() { Transform2D xform = tile_atlas_control->get_parent_control()->get_transform(); xform.translate(position); - tile_data_editor->draw_over_tile(tile_atlas_control_unscaled, xform, *tile_set, tile_set_atlas_source_id, coords, 0, selected_property); + if (tools_button_group->get_pressed_button() == tool_select_button && selection.has({ coords, 0 })) { + continue; + } + + TileMapCell cell; + cell.source_id = tile_set_atlas_source_id; + cell.set_atlas_coords(coords); + cell.alternative_tile = 0; + current_tile_data_editor->draw_over_tile(tile_atlas_control_unscaled, xform, cell); + } + + // Draw the selection on top of other. + if (tools_button_group->get_pressed_button() == tool_select_button) { + for (Set<TileSelection>::Element *E = selection.front(); E; E = E->next()) { + if (E->get().alternative != 0) { + continue; + } + Rect2i texture_region = tile_set_atlas_source->get_tile_texture_region(E->get().tile); + Vector2i position = (texture_region.position + texture_region.get_end()) / 2 + tile_set_atlas_source->get_tile_effective_texture_offset(E->get().tile, 0); + + Transform2D xform = tile_atlas_control->get_parent_control()->get_transform(); + xform.translate(position); + + TileMapCell cell; + cell.source_id = tile_set_atlas_source_id; + cell.set_atlas_coords(E->get().tile); + cell.alternative_tile = 0; + current_tile_data_editor->draw_over_tile(tile_atlas_control_unscaled, xform, cell, true); + } + } + + // Call the TileData's editor custom draw function. + if (tools_button_group->get_pressed_button() == tool_paint_button) { + Transform2D xform = tile_atlas_control->get_parent_control()->get_transform(); + current_tile_data_editor->forward_draw_over_atlas(tile_atlas_view, tile_set_atlas_source, tile_atlas_control_unscaled, xform); } } } @@ -1330,6 +1686,19 @@ void TileSetAtlasSourceEditor::_tile_alternatives_control_gui_input(const Ref<In // Update the hovered alternative tile. hovered_alternative_tile_coords = tile_atlas_view->get_alternative_tile_at_pos(alternative_tiles_control->get_local_mouse_position()); + // Forward the event to the current tile data editor if we are in the painting mode. + if (tools_button_group->get_pressed_button() == tool_paint_button) { + if (current_tile_data_editor) { + current_tile_data_editor->forward_painting_alternatives_gui_input(tile_atlas_view, tile_set_atlas_source, p_event); + } + tile_atlas_control->update(); + tile_atlas_control_unscaled->update(); + alternative_tiles_control->update(); + alternative_tiles_control_unscaled->update(); + tile_atlas_view->update(); + return; + } + Ref<InputEventMouseMotion> mm = p_event; if (mm.is_valid()) { tile_atlas_control->update(); @@ -1425,7 +1794,60 @@ void TileSetAtlasSourceEditor::_tile_alternatives_control_draw() { } void TileSetAtlasSourceEditor::_tile_alternatives_control_unscaled_draw() { - //TODO + // Draw the preview of the selected property. + if (current_tile_data_editor) { + // Draw the preview of the currently selected property. + for (int i = 0; i < tile_set_atlas_source->get_tiles_count(); i++) { + Vector2i coords = tile_set_atlas_source->get_tile_id(i); + for (int j = 0; j < tile_set_atlas_source->get_alternative_tiles_count(coords); j++) { + int alternative_tile = tile_set_atlas_source->get_alternative_tile_id(coords, j); + if (alternative_tile == 0) { + continue; + } + Rect2i rect = tile_atlas_view->get_alternative_tile_rect(coords, alternative_tile); + Vector2 position = (rect.get_position() + rect.get_end()) / 2; + + Transform2D xform = alternative_tiles_control->get_parent_control()->get_transform(); + xform.translate(position); + + if (tools_button_group->get_pressed_button() == tool_select_button && selection.has({ coords, alternative_tile })) { + continue; + } + + TileMapCell cell; + cell.source_id = tile_set_atlas_source_id; + cell.set_atlas_coords(coords); + cell.alternative_tile = alternative_tile; + current_tile_data_editor->draw_over_tile(alternative_tiles_control_unscaled, xform, cell); + } + } + + // Draw the selection on top of other. + if (tools_button_group->get_pressed_button() == tool_select_button) { + for (Set<TileSelection>::Element *E = selection.front(); E; E = E->next()) { + if (E->get().alternative == 0) { + continue; + } + Rect2i rect = tile_atlas_view->get_alternative_tile_rect(E->get().tile, E->get().alternative); + Vector2 position = (rect.get_position() + rect.get_end()) / 2; + + Transform2D xform = alternative_tiles_control->get_parent_control()->get_transform(); + xform.translate(position); + + TileMapCell cell; + cell.source_id = tile_set_atlas_source_id; + cell.set_atlas_coords(E->get().tile); + cell.alternative_tile = E->get().alternative; + current_tile_data_editor->draw_over_tile(alternative_tiles_control_unscaled, xform, cell, true); + } + } + + // Call the TileData's editor custom draw function. + if (tools_button_group->get_pressed_button() == tool_paint_button) { + Transform2D xform = tile_atlas_control->get_parent_control()->get_transform(); + current_tile_data_editor->forward_draw_over_alternatives(tile_atlas_view, tile_set_atlas_source, alternative_tiles_control_unscaled, xform); + } + } } void TileSetAtlasSourceEditor::_tile_set_atlas_source_changed() { @@ -1449,15 +1871,23 @@ void TileSetAtlasSourceEditor::_undo_redo_inspector_callback(Object *p_undo_redo AtlasTileProxyObject *tile_data = Object::cast_to<AtlasTileProxyObject>(p_edited); if (tile_data) { Vector<String> components = String(p_property).split("/", true, 2); - if (components.size() == 2 && components[1] == "shapes_count") { + if (components.size() == 2 && components[1] == "polygons_count") { int layer_index = components[0].trim_prefix("physics_layer_").to_int(); - int new_shapes_count = p_new_value; - int old_shapes_count = tile_data->get(vformat("physics_layer_%d/shapes_count", layer_index)); - if (new_shapes_count < old_shapes_count) { - for (int i = new_shapes_count - 1; i < old_shapes_count; i++) { - ADD_UNDO(tile_data, vformat("physics_layer_%d/shape_%d/shape", layer_index, i)); - ADD_UNDO(tile_data, vformat("physics_layer_%d/shape_%d/one_way", layer_index, i)); - ADD_UNDO(tile_data, vformat("physics_layer_%d/shape_%d/one_way_margin", layer_index, i)); + int new_polygons_count = p_new_value; + int old_polygons_count = tile_data->get(vformat("physics_layer_%d/polygons_count", layer_index)); + if (new_polygons_count < old_polygons_count) { + for (int i = new_polygons_count - 1; i < old_polygons_count; i++) { + ADD_UNDO(tile_data, vformat("physics_layer_%d/polygon_%d/points", layer_index, i)); + ADD_UNDO(tile_data, vformat("physics_layer_%d/polygon_%d/one_way", layer_index, i)); + ADD_UNDO(tile_data, vformat("physics_layer_%d/polygon_%d/one_way_margin", layer_index, i)); + } + } + } else if (p_property == "terrain_set") { + int current_terrain_set = tile_data->get("terrain_set"); + for (int i = 0; i < TileSet::CELL_NEIGHBOR_MAX; i++) { + TileSet::CellNeighbor bit = TileSet::CellNeighbor(i); + if (tile_set->is_valid_peering_bit_terrain(current_terrain_set, bit)) { + ADD_UNDO(tile_data, "terrains_peering_bit/" + String(TileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[i])); } } } @@ -1500,7 +1930,10 @@ void TileSetAtlasSourceEditor::edit(Ref<TileSet> p_tile_set, TileSetAtlasSource _update_fix_selected_and_hovered_tiles(); _update_tile_id_label(); _update_atlas_view(); + _update_atlas_source_inspector(); _update_tile_inspector(); + _update_tile_data_editors(); + _update_current_tile_data_editor(); } void TileSetAtlasSourceEditor::init_source() { @@ -1616,13 +2049,13 @@ void TileSetAtlasSourceEditor::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: case NOTIFICATION_THEME_CHANGED: + tool_setup_atlas_source_button->set_icon(get_theme_icon("Tools", "EditorIcons")); tool_select_button->set_icon(get_theme_icon("ToolSelect", "EditorIcons")); - tool_add_remove_button->set_icon(get_theme_icon("EditAddRemove", "EditorIcons")); - tool_add_remove_rect_button->set_icon(get_theme_icon("RectangleAddRemove", "EditorIcons")); + tool_paint_button->set_icon(get_theme_icon("CanvasItem", "EditorIcons")); tools_settings_erase_button->set_icon(get_theme_icon("Eraser", "EditorIcons")); - tool_advanced_menu_buttom->set_icon(get_theme_icon("Tools", "EditorIcons")); + tool_advanced_menu_buttom->set_icon(get_theme_icon("GuiTabMenu", "EditorIcons")); resize_handle = get_theme_icon("EditorHandle", "EditorIcons"); resize_handle_disabled = get_theme_icon("EditorHandleDisabled", "EditorIcons"); @@ -1636,7 +2069,10 @@ void TileSetAtlasSourceEditor::_notification(int p_what) { _update_fix_selected_and_hovered_tiles(); _update_tile_id_label(); _update_atlas_view(); + _update_atlas_source_inspector(); _update_tile_inspector(); + _update_tile_data_editors(); + _update_current_tile_data_editor(); tile_set_atlas_source_changed_needs_update = false; } @@ -1675,7 +2111,6 @@ TileSetAtlasSourceEditor::TileSetAtlasSourceEditor() { // Tile inspector. tile_inspector_label = memnew(Label); tile_inspector_label->set_text(TTR("Tile Properties:")); - tile_inspector_label->hide(); middle_vbox_container->add_child(tile_inspector_label); tile_proxy_object = memnew(AtlasTileProxyObject(this)); @@ -1689,6 +2124,36 @@ TileSetAtlasSourceEditor::TileSetAtlasSourceEditor() { tile_inspector->connect("property_selected", callable_mp(this, &TileSetAtlasSourceEditor::_inspector_property_selected)); middle_vbox_container->add_child(tile_inspector); + tile_inspector_no_tile_selected_label = memnew(Label); + tile_inspector_no_tile_selected_label->set_align(Label::ALIGN_CENTER); + tile_inspector_no_tile_selected_label->set_text(TTR("No tile selected.")); + middle_vbox_container->add_child(tile_inspector_no_tile_selected_label); + + // Property values palette. + tile_data_editors_popup = memnew(Popup); + + tile_data_editors_label = memnew(Label); + tile_data_editors_label->set_text(TTR("Paint Properties:")); + middle_vbox_container->add_child(tile_data_editors_label); + + tile_data_editor_dropdown_button = memnew(Button); + tile_data_editor_dropdown_button->connect("draw", callable_mp(this, &TileSetAtlasSourceEditor::_tile_data_editor_dropdown_button_draw)); + tile_data_editor_dropdown_button->connect("pressed", callable_mp(this, &TileSetAtlasSourceEditor::_tile_data_editor_dropdown_button_pressed)); + middle_vbox_container->add_child(tile_data_editor_dropdown_button); + tile_data_editor_dropdown_button->add_child(tile_data_editors_popup); + + tile_data_editors_tree = memnew(Tree); + tile_data_editors_tree->set_hide_root(true); + tile_data_editors_tree->set_anchors_and_offsets_preset(Control::PRESET_WIDE); + tile_data_editors_tree->set_h_scroll_enabled(false); + tile_data_editors_tree->set_v_scroll_enabled(false); + tile_data_editors_tree->connect("item_selected", callable_mp(this, &TileSetAtlasSourceEditor::_tile_data_editors_tree_selected)); + tile_data_editors_popup->add_child(tile_data_editors_tree); + + tile_data_painting_editor_container = memnew(VBoxContainer); + tile_data_painting_editor_container->set_h_size_flags(SIZE_EXPAND_FILL); + middle_vbox_container->add_child(tile_data_painting_editor_container); + // Atlas source inspector. atlas_source_inspector_label = memnew(Label); atlas_source_inspector_label->set_text(TTR("Atlas Properties:")); @@ -1719,47 +2184,41 @@ TileSetAtlasSourceEditor::TileSetAtlasSourceEditor() { add_child(confirm_auto_create_tiles); // -- Toolbox -- - tools_button_group.instance(); + tools_button_group.instantiate(); + tools_button_group->connect("pressed", callable_mp(this, &TileSetAtlasSourceEditor::_update_fix_selected_and_hovered_tiles).unbind(1)); + tools_button_group->connect("pressed", callable_mp(this, &TileSetAtlasSourceEditor::_update_tile_id_label).unbind(1)); + tools_button_group->connect("pressed", callable_mp(this, &TileSetAtlasSourceEditor::_update_atlas_source_inspector).unbind(1)); + tools_button_group->connect("pressed", callable_mp(this, &TileSetAtlasSourceEditor::_update_tile_inspector).unbind(1)); + tools_button_group->connect("pressed", callable_mp(this, &TileSetAtlasSourceEditor::_update_tile_data_editors).unbind(1)); + tools_button_group->connect("pressed", callable_mp(this, &TileSetAtlasSourceEditor::_update_current_tile_data_editor).unbind(1)); + tools_button_group->connect("pressed", callable_mp(this, &TileSetAtlasSourceEditor::_update_atlas_view).unbind(1)); + tools_button_group->connect("pressed", callable_mp(this, &TileSetAtlasSourceEditor::_update_toolbar).unbind(1)); toolbox = memnew(HBoxContainer); right_panel->add_child(toolbox); + tool_setup_atlas_source_button = memnew(Button); + tool_setup_atlas_source_button->set_flat(true); + tool_setup_atlas_source_button->set_toggle_mode(true); + tool_setup_atlas_source_button->set_pressed(true); + tool_setup_atlas_source_button->set_button_group(tools_button_group); + tool_setup_atlas_source_button->set_tooltip(TTR("Atlas Setup. Add/Remove tiles tool (use the shift key to create big tiles, control for rectangle editing).")); + toolbox->add_child(tool_setup_atlas_source_button); + tool_select_button = memnew(Button); tool_select_button->set_flat(true); tool_select_button->set_toggle_mode(true); - tool_select_button->set_pressed(true); + tool_select_button->set_pressed(false); tool_select_button->set_button_group(tools_button_group); tool_select_button->set_tooltip(TTR("Select tiles.")); - tool_select_button->connect("pressed", callable_mp(this, &TileSetAtlasSourceEditor::_update_fix_selected_and_hovered_tiles)); - tool_select_button->connect("pressed", callable_mp(this, &TileSetAtlasSourceEditor::_update_tile_id_label)); - tool_select_button->connect("pressed", callable_mp(this, &TileSetAtlasSourceEditor::_update_tile_inspector)); - tool_select_button->connect("pressed", callable_mp(this, &TileSetAtlasSourceEditor::_update_atlas_view)); - tool_select_button->connect("pressed", callable_mp(this, &TileSetAtlasSourceEditor::_update_toolbar)); toolbox->add_child(tool_select_button); - tool_add_remove_button = memnew(Button); - tool_add_remove_button->set_flat(true); - tool_add_remove_button->set_toggle_mode(true); - tool_add_remove_button->set_button_group(tools_button_group); - tool_add_remove_button->set_tooltip(TTR("Add/Remove tiles tool (use the shift key to create big tiles).")); - tool_add_remove_button->connect("pressed", callable_mp(this, &TileSetAtlasSourceEditor::_update_fix_selected_and_hovered_tiles)); - tool_add_remove_button->connect("pressed", callable_mp(this, &TileSetAtlasSourceEditor::_update_tile_id_label)); - tool_add_remove_button->connect("pressed", callable_mp(this, &TileSetAtlasSourceEditor::_update_tile_inspector)); - tool_add_remove_button->connect("pressed", callable_mp(this, &TileSetAtlasSourceEditor::_update_atlas_view)); - tool_add_remove_button->connect("pressed", callable_mp(this, &TileSetAtlasSourceEditor::_update_toolbar)); - toolbox->add_child(tool_add_remove_button); - - tool_add_remove_rect_button = memnew(Button); - tool_add_remove_rect_button->set_flat(true); - tool_add_remove_rect_button->set_toggle_mode(true); - tool_add_remove_rect_button->set_button_group(tools_button_group); - tool_add_remove_rect_button->set_tooltip(TTR("Add/Remove tiles rectangle tool (use the shift key to create big tiles).")); - tool_add_remove_rect_button->connect("pressed", callable_mp(this, &TileSetAtlasSourceEditor::_update_fix_selected_and_hovered_tiles)); - tool_add_remove_rect_button->connect("pressed", callable_mp(this, &TileSetAtlasSourceEditor::_update_tile_id_label)); - tool_add_remove_rect_button->connect("pressed", callable_mp(this, &TileSetAtlasSourceEditor::_update_tile_inspector)); - tool_add_remove_rect_button->connect("pressed", callable_mp(this, &TileSetAtlasSourceEditor::_update_atlas_view)); - tool_add_remove_rect_button->connect("pressed", callable_mp(this, &TileSetAtlasSourceEditor::_update_toolbar)); - toolbox->add_child(tool_add_remove_rect_button); + tool_paint_button = memnew(Button); + tool_paint_button->set_flat(true); + tool_paint_button->set_toggle_mode(true); + tool_paint_button->set_button_group(tools_button_group); + tool_paint_button->set_tooltip(TTR("Paint properties.")); + toolbox->add_child(tool_paint_button); // Tool settings. tool_settings = memnew(HBoxContainer); @@ -1768,6 +2227,9 @@ TileSetAtlasSourceEditor::TileSetAtlasSourceEditor() { tool_settings_vsep = memnew(VSeparator); tool_settings->add_child(tool_settings_vsep); + tool_settings_tile_data_toolbar_container = memnew(HBoxContainer); + tool_settings->add_child(tool_settings_tile_data_toolbar_container); + tools_settings_erase_button = memnew(Button); tools_settings_erase_button->set_flat(true); tools_settings_erase_button->set_toggle_mode(true); @@ -1775,9 +2237,6 @@ TileSetAtlasSourceEditor::TileSetAtlasSourceEditor() { tools_settings_erase_button->set_shortcut_context(this); tool_settings->add_child(tools_settings_erase_button); - VSeparator *tool_advanced_vsep = memnew(VSeparator); - toolbox->add_child(tool_advanced_vsep); - tool_advanced_menu_buttom = memnew(MenuButton); tool_advanced_menu_buttom->set_flat(true); tool_advanced_menu_buttom->get_popup()->add_item(TTR("Cleanup Tiles Outside Texture"), ADVANCED_CLEANUP_TILES_OUTSIDE_TEXTURE); @@ -1844,7 +2303,7 @@ TileSetAtlasSourceEditor::TileSetAtlasSourceEditor() { alternative_tiles_control_unscaled = memnew(Control); alternative_tiles_control_unscaled->set_anchors_and_offsets_preset(Control::PRESET_WIDE); alternative_tiles_control_unscaled->connect("draw", callable_mp(this, &TileSetAtlasSourceEditor::_tile_alternatives_control_unscaled_draw)); - tile_atlas_view->add_control_over_atlas_tiles(alternative_tiles_control_unscaled, false); + tile_atlas_view->add_control_over_alternative_tiles(alternative_tiles_control_unscaled, false); alternative_tiles_control_unscaled->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); tile_atlas_view_missing_source_label = memnew(Label); diff --git a/editor/plugins/tiles/tile_set_atlas_source_editor.h b/editor/plugins/tiles/tile_set_atlas_source_editor.h index 70f2cdbe01..dbb0756a16 100644 --- a/editor/plugins/tiles/tile_set_atlas_source_editor.h +++ b/editor/plugins/tiles/tile_set_atlas_source_editor.h @@ -32,6 +32,7 @@ #define TILE_SET_ATLAS_SOURCE_EDITOR_H #include "tile_atlas_view.h" +#include "tile_data_editors.h" #include "editor/editor_node.h" #include "scene/gui/split_container.h" @@ -113,10 +114,27 @@ private: bool tile_set_atlas_source_changed_needs_update = false; + // -- Properties painting -- + VBoxContainer *tile_data_painting_editor_container; + Label *tile_data_editors_label; + Button *tile_data_editor_dropdown_button; + Popup *tile_data_editors_popup; + Tree *tile_data_editors_tree; + void _tile_data_editor_dropdown_button_draw(); + void _tile_data_editor_dropdown_button_pressed(); + + // -- Tile data editors -- + String current_property; + Control *current_tile_data_editor_toolbar = nullptr; + Map<String, TileDataEditor *> tile_data_editors; + TileDataEditor *current_tile_data_editor = nullptr; + void _tile_data_editors_tree_selected(); + // -- Inspector -- AtlasTileProxyObject *tile_proxy_object; Label *tile_inspector_label; EditorInspector *tile_inspector; + Label *tile_inspector_no_tile_selected_label; String selected_property; void _inspector_property_selected(String p_property); @@ -142,6 +160,8 @@ private: DRAG_TYPE_RECT_SELECT, + DRAG_TYPE_MAY_POPUP_MENU, + // Warning: keep in this order. DRAG_TYPE_RESIZE_TOP_LEFT, DRAG_TYPE_RESIZE_TOP, @@ -179,15 +199,16 @@ private: // Tool buttons. Ref<ButtonGroup> tools_button_group; + Button *tool_setup_atlas_source_button; Button *tool_select_button; - Button *tool_add_remove_button; - Button *tool_add_remove_rect_button; + Button *tool_paint_button; Label *tool_tile_id_label; + // Tool settings. HBoxContainer *tool_settings; VSeparator *tool_settings_vsep; + HBoxContainer *tool_settings_tile_data_toolbar_container; Button *tools_settings_erase_button; - MenuButton *tool_advanced_menu_buttom; // Selection. @@ -226,7 +247,10 @@ private: void _update_tile_id_label(); void _update_source_inspector(); void _update_fix_selected_and_hovered_tiles(); + void _update_atlas_source_inspector(); void _update_tile_inspector(); + void _update_tile_data_editors(); + void _update_current_tile_data_editor(); void _update_manage_tile_properties_button(); void _update_atlas_view(); void _update_toolbar(); diff --git a/editor/plugins/tiles/tile_set_editor.cpp b/editor/plugins/tiles/tile_set_editor.cpp index ae5620a4e3..2c2ebd107f 100644 --- a/editor/plugins/tiles/tile_set_editor.cpp +++ b/editor/plugins/tiles/tile_set_editor.cpp @@ -347,11 +347,11 @@ void TileSetEditor::_undo_redo_inspector_callback(Object *p_undo_redo, Object *p int old_layer_count = tile_set->get_physics_layers_count(); if (new_layer_count < old_layer_count) { for (int physics_layer_index = new_layer_count - 1; physics_layer_index < old_layer_count; physics_layer_index++) { - ADD_UNDO(tile_data, vformat("physics_layer_%d/shapes_count", physics_layer_index)); - for (int shape_index = 0; shape_index < tile_data->get_collision_shapes_count(physics_layer_index); shape_index++) { - ADD_UNDO(tile_data, vformat("physics_layer_%d/shape_%d/shape", physics_layer_index, shape_index)); - ADD_UNDO(tile_data, vformat("physics_layer_%d/shape_%d/one_way", physics_layer_index, shape_index)); - ADD_UNDO(tile_data, vformat("physics_layer_%d/shape_%d/one_way_margin", physics_layer_index, shape_index)); + ADD_UNDO(tile_data, vformat("physics_layer_%d/polygons_count", physics_layer_index)); + for (int polygon_index = 0; polygon_index < tile_data->get_collision_polygons_count(physics_layer_index); polygon_index++) { + ADD_UNDO(tile_data, vformat("physics_layer_%d/polygon_%d/points", physics_layer_index, polygon_index)); + ADD_UNDO(tile_data, vformat("physics_layer_%d/polygon_%d/one_way", physics_layer_index, polygon_index)); + ADD_UNDO(tile_data, vformat("physics_layer_%d/polygon_%d/one_way_margin", physics_layer_index, polygon_index)); } } } @@ -359,53 +359,11 @@ void TileSetEditor::_undo_redo_inspector_callback(Object *p_undo_redo, Object *p (components.size() == 2 && components[0].begins_with("terrain_set_") && components[0].trim_prefix("terrain_set_").is_valid_int() && components[1] == "mode") || (components.size() == 2 && components[0].begins_with("terrain_set_") && components[0].trim_prefix("terrain_set_").is_valid_int() && components[1] == "terrains_count" && tile_data->get_terrain_set() == components[0].trim_prefix("terrain_set_").to_int() && (int)p_new_value < tile_set->get_terrains_count(tile_data->get_terrain_set()))) { ADD_UNDO(tile_data, "terrain_set"); - if (tile_data->is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_RIGHT_SIDE)) { - ADD_UNDO(tile_data, "terrains_peering_bit/right_side"); - } - if (tile_data->is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_RIGHT_CORNER)) { - ADD_UNDO(tile_data, "terrains_peering_bit/right_corner"); - } - if (tile_data->is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE)) { - ADD_UNDO(tile_data, "terrains_peering_bit/bottom_right_side"); - } - if (tile_data->is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER)) { - ADD_UNDO(tile_data, "terrains_peering_bit/bottom_right_corner"); - } - if (tile_data->is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_BOTTOM_SIDE)) { - ADD_UNDO(tile_data, "terrains_peering_bit/bottom_side"); - } - if (tile_data->is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_BOTTOM_CORNER)) { - ADD_UNDO(tile_data, "terrains_peering_bit/bottom_corner"); - } - if (tile_data->is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE)) { - ADD_UNDO(tile_data, "terrains_peering_bit/bottom_left_side"); - } - if (tile_data->is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_CORNER)) { - ADD_UNDO(tile_data, "terrains_peering_bit/bottom_left_corner"); - } - if (tile_data->is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_LEFT_SIDE)) { - ADD_UNDO(tile_data, "terrains_peering_bit/left_side"); - } - if (tile_data->is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_LEFT_CORNER)) { - ADD_UNDO(tile_data, "terrains_peering_bit/left_corner"); - } - if (tile_data->is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE)) { - ADD_UNDO(tile_data, "terrains_peering_bit/top_left_side"); - } - if (tile_data->is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_TOP_LEFT_CORNER)) { - ADD_UNDO(tile_data, "terrains_peering_bit/top_left_corner"); - } - if (tile_data->is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_TOP_SIDE)) { - ADD_UNDO(tile_data, "terrains_peering_bit/top_side"); - } - if (tile_data->is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_TOP_CORNER)) { - ADD_UNDO(tile_data, "terrains_peering_bit/top_corner"); - } - if (tile_data->is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE)) { - ADD_UNDO(tile_data, "terrains_peering_bit/top_right_side"); - } - if (tile_data->is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_TOP_RIGHT_CORNER)) { - ADD_UNDO(tile_data, "terrains_peering_bit/top_right_corner"); + for (int l = 0; l < TileSet::CELL_NEIGHBOR_MAX; l++) { + TileSet::CellNeighbor bit = TileSet::CellNeighbor(l); + if (tile_data->is_valid_peering_bit_terrain(bit)) { + ADD_UNDO(tile_data, "terrains_peering_bit/" + String(TileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[l])); + } } } else if (p_property == "navigation_layers_count") { int new_layer_count = p_new_value; @@ -440,30 +398,6 @@ void TileSetEditor::_bind_methods() { ClassDB::bind_method(D_METHOD("_drop_data_fw"), &TileSetEditor::drop_data_fw); } -TileDataEditor *TileSetEditor::get_tile_data_editor(String p_property) { - Vector<String> components = String(p_property).split("/", true); - - if (p_property == "z_index") { - return tile_data_integer_editor; - } else if (p_property == "probability") { - return tile_data_float_editor; - } else if (p_property == "y_sort_origin") { - return tile_data_y_sort_editor; - } else if (p_property == "texture_offset") { - return tile_data_texture_offset_editor; - } else if (components.size() >= 1 && components[0].begins_with("occlusion_layer_")) { - return tile_data_occlusion_shape_editor; - } else if (components.size() >= 1 && components[0].begins_with("physics_layer_")) { - return tile_data_collision_shape_editor; - } else if (p_property == "mode" || p_property == "terrain" || (components.size() >= 1 && components[0] == "terrains_peering_bit")) { - return tile_data_terrains_editor; - } else if (components.size() >= 1 && components[0].begins_with("navigation_layer_")) { - return tile_data_navigation_polygon_editor; - } - - return nullptr; -} - void TileSetEditor::edit(Ref<TileSet> p_tile_set) { if (p_tile_set == tile_set) { return; @@ -575,14 +509,4 @@ TileSetEditor::~TileSetEditor() { if (tile_set.is_valid()) { tile_set->disconnect("changed", callable_mp(this, &TileSetEditor::_tile_set_changed)); } - - // Delete tile data editors. - memdelete(tile_data_texture_offset_editor); - memdelete(tile_data_y_sort_editor); - memdelete(tile_data_integer_editor); - memdelete(tile_data_float_editor); - memdelete(tile_data_occlusion_shape_editor); - memdelete(tile_data_collision_shape_editor); - memdelete(tile_data_terrains_editor); - memdelete(tile_data_navigation_polygon_editor); } diff --git a/editor/plugins/tiles/tile_set_editor.h b/editor/plugins/tiles/tile_set_editor.h index f584c043cc..9e50aca62f 100644 --- a/editor/plugins/tiles/tile_set_editor.h +++ b/editor/plugins/tiles/tile_set_editor.h @@ -33,7 +33,6 @@ #include "scene/gui/box_container.h" #include "scene/resources/tile_set.h" -#include "tile_data_editors.h" #include "tile_set_atlas_source_editor.h" #include "tile_set_scenes_collection_source_editor.h" @@ -54,16 +53,6 @@ private: void _update_atlas_sources_list(int force_selected_id = -1); - // List of tile data editors. - TileDataTextureOffsetEditor *tile_data_texture_offset_editor = memnew(TileDataTextureOffsetEditor); - TileDataYSortEditor *tile_data_y_sort_editor = memnew(TileDataYSortEditor); - TileDataIntegerEditor *tile_data_integer_editor = memnew(TileDataIntegerEditor); - TileDataFloatEditor *tile_data_float_editor = memnew(TileDataFloatEditor); - TileDataOcclusionShapeEditor *tile_data_occlusion_shape_editor = memnew(TileDataOcclusionShapeEditor); - TileDataCollisionShapeEditor *tile_data_collision_shape_editor = memnew(TileDataCollisionShapeEditor); - TileDataTerrainsEditor *tile_data_terrains_editor = memnew(TileDataTerrainsEditor); - TileDataNavigationPolygonEditor *tile_data_navigation_polygon_editor = memnew(TileDataNavigationPolygonEditor); - // -- Sources management -- Button *sources_delete_button; MenuButton *sources_add_button; @@ -84,7 +73,6 @@ protected: public: _FORCE_INLINE_ static TileSetEditor *get_singleton() { return singleton; } - TileDataEditor *get_tile_data_editor(String property); void edit(Ref<TileSet> p_tile_set); void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from); bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const; diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index e393f960bd..30643b7ecd 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -110,6 +110,7 @@ void VisualShaderGraphPlugin::_bind_methods() { ClassDB::bind_method("set_uniform_name", &VisualShaderGraphPlugin::set_uniform_name); ClassDB::bind_method("set_expression", &VisualShaderGraphPlugin::set_expression); ClassDB::bind_method("update_curve", &VisualShaderGraphPlugin::update_curve); + ClassDB::bind_method("update_curve3", &VisualShaderGraphPlugin::update_curve3); ClassDB::bind_method("update_constant", &VisualShaderGraphPlugin::update_constant); } @@ -211,9 +212,19 @@ void VisualShaderGraphPlugin::set_uniform_name(VisualShader::Type p_type, int p_ } void VisualShaderGraphPlugin::update_curve(int p_node_id) { - if (links.has(p_node_id) && links[p_node_id].curve_editor) { + if (links.has(p_node_id) && links[p_node_id].curve_editors[0]) { if (((VisualShaderNodeCurveTexture *)links[p_node_id].visual_node)->get_texture().is_valid()) { - links[p_node_id].curve_editor->set_curve(((VisualShaderNodeCurveTexture *)links[p_node_id].visual_node)->get_texture()->get_curve()); + links[p_node_id].curve_editors[0]->set_curve(((VisualShaderNodeCurveTexture *)links[p_node_id].visual_node)->get_texture()->get_curve()); + } + } +} + +void VisualShaderGraphPlugin::update_curve3(int p_node_id) { + if (links.has(p_node_id) && links[p_node_id].curve_editors[0] && links[p_node_id].curve_editors[1] && links[p_node_id].curve_editors[2]) { + if (((VisualShaderNodeCurve3Texture *)links[p_node_id].visual_node)->get_texture().is_valid()) { + links[p_node_id].curve_editors[0]->set_curve(((VisualShaderNodeCurve3Texture *)links[p_node_id].visual_node)->get_texture()->get_curve_x()); + links[p_node_id].curve_editors[1]->set_curve(((VisualShaderNodeCurve3Texture *)links[p_node_id].visual_node)->get_texture()->get_curve_y()); + links[p_node_id].curve_editors[2]->set_curve(((VisualShaderNodeCurve3Texture *)links[p_node_id].visual_node)->get_texture()->get_curve_z()); } } } @@ -265,8 +276,8 @@ void VisualShaderGraphPlugin::register_expression_edit(int p_node_id, CodeEdit * links[p_node_id].expression_edit = p_expression_edit; } -void VisualShaderGraphPlugin::register_curve_editor(int p_node_id, CurveEditor *p_curve_editor) { - links[p_node_id].curve_editor = p_curve_editor; +void VisualShaderGraphPlugin::register_curve_editor(int p_node_id, int p_index, CurveEditor *p_curve_editor) { + links[p_node_id].curve_editors[p_index] = p_curve_editor; } void VisualShaderGraphPlugin::update_uniform_refs() { @@ -312,7 +323,7 @@ void VisualShaderGraphPlugin::make_dirty(bool p_enabled) { } void VisualShaderGraphPlugin::register_link(VisualShader::Type p_type, int p_id, VisualShaderNode *p_visual_node, GraphNode *p_graph_node) { - links.insert(p_id, { p_type, p_visual_node, p_graph_node, p_visual_node->get_output_port_for_preview() != -1, -1, Map<int, InputPort>(), Map<int, Port>(), nullptr, nullptr, nullptr, nullptr, nullptr }); + links.insert(p_id, { p_type, p_visual_node, p_graph_node, p_visual_node->get_output_port_for_preview() != -1, -1, Map<int, InputPort>(), Map<int, Port>(), nullptr, nullptr, nullptr, nullptr, { nullptr, nullptr, nullptr } }); } void VisualShaderGraphPlugin::register_output_port(int p_node_id, int p_port, TextureButton *p_button) { @@ -472,6 +483,18 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id) { custom_editor = hbox; } + Ref<VisualShaderNodeCurve3Texture> curve3 = vsnode; + if (curve3.is_valid()) { + if (curve3->get_texture().is_valid() && !curve3->get_texture()->is_connected("changed", callable_mp(VisualShaderEditor::get_singleton()->get_graph_plugin(), &VisualShaderGraphPlugin::update_curve3))) { + curve3->get_texture()->connect("changed", callable_mp(VisualShaderEditor::get_singleton()->get_graph_plugin(), &VisualShaderGraphPlugin::update_curve3), varray(p_id)); + } + + HBoxContainer *hbox = memnew(HBoxContainer); + custom_editor->set_h_size_flags(Control::SIZE_EXPAND_FILL); + hbox->add_child(custom_editor); + custom_editor = hbox; + } + Ref<VisualShaderNodeFloatConstant> float_const = vsnode; if (float_const.is_valid()) { HBoxContainer *hbox = memnew(HBoxContainer); @@ -495,19 +518,12 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id) { port_offset++; node->add_child(custom_editor); - if (curve.is_valid()) { + bool is_curve = curve.is_valid() || curve3.is_valid(); + + if (is_curve) { VisualShaderEditor::get_singleton()->graph->add_child(node); VisualShaderEditor::get_singleton()->_update_created_node(node); - CurveEditor *curve_editor = memnew(CurveEditor); - node->add_child(curve_editor); - register_curve_editor(p_id, curve_editor); - curve_editor->set_custom_minimum_size(Size2(300, 0)); - curve_editor->set_h_size_flags(Control::SIZE_EXPAND_FILL); - if (curve->get_texture().is_valid()) { - curve_editor->set_curve(curve->get_texture()->get_curve()); - } - TextureButton *preview = memnew(TextureButton); preview->set_toggle_mode(true); preview->set_normal_texture(VisualShaderEditor::get_singleton()->get_theme_icon("GuiVisibilityHidden", "EditorIcons")); @@ -519,12 +535,59 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id) { preview->connect("pressed", callable_mp(VisualShaderEditor::get_singleton(), &VisualShaderEditor::_preview_select_port), varray(p_id, 0), CONNECT_DEFERRED); custom_editor->add_child(preview); + if (vsnode->get_output_port_for_preview() >= 0) { + show_port_preview(p_type, p_id, vsnode->get_output_port_for_preview()); + } + } + + if (curve.is_valid()) { + CurveEditor *curve_editor = memnew(CurveEditor); + node->add_child(curve_editor); + register_curve_editor(p_id, 0, curve_editor); + curve_editor->set_custom_minimum_size(Size2(300, 0)); + curve_editor->set_h_size_flags(Control::SIZE_EXPAND_FILL); + if (curve->get_texture().is_valid()) { + curve_editor->set_curve(curve->get_texture()->get_curve()); + } + } + + if (curve3.is_valid()) { + CurveEditor *curve_editor_x = memnew(CurveEditor); + node->add_child(curve_editor_x); + register_curve_editor(p_id, 0, curve_editor_x); + curve_editor_x->set_custom_minimum_size(Size2(300, 0)); + curve_editor_x->set_h_size_flags(Control::SIZE_EXPAND_FILL); + if (curve3->get_texture().is_valid()) { + curve_editor_x->set_curve(curve3->get_texture()->get_curve_x()); + } + + CurveEditor *curve_editor_y = memnew(CurveEditor); + node->add_child(curve_editor_y); + register_curve_editor(p_id, 1, curve_editor_y); + curve_editor_y->set_custom_minimum_size(Size2(300, 0)); + curve_editor_y->set_h_size_flags(Control::SIZE_EXPAND_FILL); + if (curve3->get_texture().is_valid()) { + curve_editor_y->set_curve(curve3->get_texture()->get_curve_y()); + } + + CurveEditor *curve_editor_z = memnew(CurveEditor); + node->add_child(curve_editor_z); + register_curve_editor(p_id, 2, curve_editor_z); + curve_editor_z->set_custom_minimum_size(Size2(300, 0)); + curve_editor_z->set_h_size_flags(Control::SIZE_EXPAND_FILL); + if (curve3->get_texture().is_valid()) { + curve_editor_z->set_curve(curve3->get_texture()->get_curve_z()); + } + } + + if (is_curve) { VisualShaderNode::PortType port_left = vsnode->get_input_port_type(0); VisualShaderNode::PortType port_right = vsnode->get_output_port_type(0); node->set_slot(0, true, port_left, type_color[port_left], true, port_right, type_color[port_right]); VisualShaderEditor::get_singleton()->call_deferred("_set_node_size", (int)p_type, p_id, size); } + if (vsnode->is_use_prop_slots()) { return; } @@ -818,7 +881,7 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id) { if (is_expression) { CodeEdit *expression_box = memnew(CodeEdit); Ref<CodeHighlighter> expression_syntax_highlighter; - expression_syntax_highlighter.instance(); + expression_syntax_highlighter.instantiate(); expression_node->set_ctrl_pressed(expression_box, 0); node->add_child(expression_box); register_expression_edit(p_id, expression_box); @@ -888,6 +951,7 @@ void VisualShaderGraphPlugin::remove_node(VisualShader::Type p_type, int p_id) { void VisualShaderGraphPlugin::connect_nodes(VisualShader::Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port) { if (visual_shader->get_shader_type() == p_type) { VisualShaderEditor::get_singleton()->graph->connect_node(itos(p_from_node), p_from_port, itos(p_to_node), p_to_port); + connections.push_back({ p_from_node, p_from_port, p_to_node, p_to_port }); if (links[p_to_node].input_ports.has(p_to_port) && links[p_to_node].input_ports[p_to_port].default_input_button != nullptr) { links[p_to_node].input_ports[p_to_port].default_input_button->hide(); } @@ -897,6 +961,12 @@ void VisualShaderGraphPlugin::connect_nodes(VisualShader::Type p_type, int p_fro void VisualShaderGraphPlugin::disconnect_nodes(VisualShader::Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port) { if (visual_shader->get_shader_type() == p_type) { VisualShaderEditor::get_singleton()->graph->disconnect_node(itos(p_from_node), p_from_port, itos(p_to_node), p_to_port); + for (List<VisualShader::Connection>::Element *E = connections.front(); E; E = E->next()) { + if (E->get().from_node == p_from_node && E->get().from_port == p_from_port && E->get().to_node == p_to_node && E->get().to_port == p_to_port) { + connections.erase(E); + break; + } + } if (links[p_to_node].input_ports.has(p_to_port) && links[p_to_node].input_ports[p_to_port].default_input_button != nullptr && links[p_to_node].visual_node->get_input_port_default_value(p_to_port).get_type() != Variant::NIL) { links[p_to_node].input_ports[p_to_port].default_input_button->show(); set_input_port_default_value(p_type, p_to_node, p_to_port, links[p_to_node].visual_node->get_input_port_default_value(p_to_port)); @@ -1053,7 +1123,7 @@ void VisualShaderEditor::update_custom_nodes() { Ref<Script> script = Ref<Script>(res); Ref<VisualShaderNodeCustom> ref; - ref.instance(); + ref.instantiate(); ref->set_script(script); String name; @@ -2209,7 +2279,7 @@ void VisualShaderEditor::_add_node(int p_idx, int p_op_idx, String p_resource_pa bool is_custom = add_options[p_idx].is_custom; if (!is_custom && add_options[p_idx].type != String()) { - VisualShaderNode *vsn = Object::cast_to<VisualShaderNode>(ClassDB::instance(add_options[p_idx].type)); + VisualShaderNode *vsn = Object::cast_to<VisualShaderNode>(ClassDB::instantiate(add_options[p_idx].type)); ERR_FAIL_COND(!vsn); VisualShaderNodeFloatConstant *constant = Object::cast_to<VisualShaderNodeFloatConstant>(vsn); @@ -2234,7 +2304,7 @@ void VisualShaderEditor::_add_node(int p_idx, int p_op_idx, String p_resource_pa } else { ERR_FAIL_COND(add_options[p_idx].script.is_null()); String base_type = add_options[p_idx].script->get_instance_base_type(); - VisualShaderNode *vsn = Object::cast_to<VisualShaderNode>(ClassDB::instance(base_type)); + VisualShaderNode *vsn = Object::cast_to<VisualShaderNode>(ClassDB::instantiate(base_type)); ERR_FAIL_COND(!vsn); vsnode = Ref<VisualShaderNode>(vsn); vsnode->set_script(add_options[p_idx].script); @@ -2315,6 +2385,13 @@ void VisualShaderEditor::_add_node(int p_idx, int p_op_idx, String p_resource_pa undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, _from_node, _from_slot, to_node, to_slot); undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, _from_node, _from_slot, to_node, to_slot); } else { + // Need to setting up Input node properly before committing since `is_port_types_compatible` (calling below) is using `mode` and `shader_type`. + VisualShaderNodeInput *input = Object::cast_to<VisualShaderNodeInput>(vsnode.ptr()); + if (input) { + input->set_shader_mode(visual_shader->get_mode()); + input->set_shader_type(visual_shader->get_shader_type()); + } + // Attempting to connect to the first correct port. for (int i = 0; i < vsnode->get_output_port_count(); i++) { if (visual_shader->is_port_types_compatible(vsnode->get_output_port_type(i), input_port_type)) { @@ -2373,6 +2450,11 @@ void VisualShaderEditor::_add_node(int p_idx, int p_op_idx, String p_resource_pa graph_plugin->call_deferred("update_curve", id_to_use); } + VisualShaderNodeCurve3Texture *curve3 = Object::cast_to<VisualShaderNodeCurve3Texture>(vsnode.ptr()); + if (curve3) { + graph_plugin->call_deferred("update_curve3", id_to_use); + } + if (p_resource_path.is_empty()) { undo_redo->commit_action(); } else { @@ -2381,7 +2463,7 @@ void VisualShaderEditor::_add_node(int p_idx, int p_op_idx, String p_resource_pa VisualShaderNodeTexture *texture2d = Object::cast_to<VisualShaderNodeTexture>(vsnode.ptr()); VisualShaderNodeTexture3D *texture3d = Object::cast_to<VisualShaderNodeTexture3D>(vsnode.ptr()); - if (texture2d || texture3d || curve) { + if (texture2d || texture3d || curve || curve3) { undo_redo->add_do_method(vsnode.ptr(), "set_texture", ResourceLoader::load(p_resource_path)); return; } @@ -3576,6 +3658,10 @@ void VisualShaderEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da saved_node_pos = p_point + Vector2(0, i * 250 * EDSCALE); saved_node_pos_dirty = true; _add_node(curve_node_option_idx, -1, arr[i], i); + } else if (type == "Curve3Texture") { + saved_node_pos = p_point + Vector2(0, i * 250 * EDSCALE); + saved_node_pos_dirty = true; + _add_node(curve3_node_option_idx, -1, arr[i], i); } else if (ClassDB::get_parent_class(type) == "Texture2D") { saved_node_pos = p_point + Vector2(0, i * 250 * EDSCALE); saved_node_pos_dirty = true; @@ -3835,7 +3921,7 @@ VisualShaderEditor::VisualShaderEditor() { preview_vbox->add_theme_constant_override("separation", 0); preview_text = memnew(CodeEdit); - syntax_highlighter.instance(); + syntax_highlighter.instantiate(); preview_vbox->add_child(preview_text); preview_text->set_v_size_flags(Control::SIZE_EXPAND_FILL); preview_text->set_syntax_highlighter(syntax_highlighter); @@ -4297,6 +4383,8 @@ VisualShaderEditor::VisualShaderEditor() { add_options.push_back(AddOption("CubeMap", "Textures", "Functions", "VisualShaderNodeCubemap", TTR("Perform the cubic texture lookup."), -1, -1)); curve_node_option_idx = add_options.size(); add_options.push_back(AddOption("CurveTexture", "Textures", "Functions", "VisualShaderNodeCurveTexture", TTR("Perform the curve texture lookup."), -1, -1)); + curve3_node_option_idx = add_options.size(); + add_options.push_back(AddOption("CurveTexture3", "Textures", "Functions", "VisualShaderNodeCurve3Texture", TTR("Perform the ternary curve texture lookup."), -1, -1)); texture2d_node_option_idx = add_options.size(); add_options.push_back(AddOption("Texture2D", "Textures", "Functions", "VisualShaderNodeTexture", TTR("Perform the 2D texture lookup."), -1, -1)); texture2d_array_node_option_idx = add_options.size(); @@ -4427,10 +4515,10 @@ VisualShaderEditor::VisualShaderEditor() { undo_redo = EditorNode::get_singleton()->get_undo_redo(); Ref<VisualShaderNodePluginDefault> default_plugin; - default_plugin.instance(); + default_plugin.instantiate(); add_plugin(default_plugin); - graph_plugin.instance(); + graph_plugin.instantiate(); property_editor = memnew(CustomPropertyEditor); add_child(property_editor); @@ -4857,7 +4945,7 @@ void EditorInspectorShaderModePlugin::parse_begin(Object *p_object) { //do none } -bool EditorInspectorShaderModePlugin::parse_property(Object *p_object, Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, int p_usage, bool p_wide) { +bool EditorInspectorShaderModePlugin::parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const uint32_t p_usage, const bool p_wide) { if (p_path == "mode" && p_object->is_class("VisualShader") && p_type == Variant::INT) { EditorPropertyShaderMode *editor = memnew(EditorPropertyShaderMode); Vector<String> options = p_hint_text.split(","); @@ -4885,14 +4973,14 @@ void VisualShaderNodePortPreview::_shader_changed() { String shader_code = shader->generate_preview_shader(type, node, port, default_textures); Ref<Shader> preview_shader; - preview_shader.instance(); + preview_shader.instantiate(); preview_shader->set_code(shader_code); for (int i = 0; i < default_textures.size(); i++) { preview_shader->set_default_texture_param(default_textures[i].name, default_textures[i].param); } Ref<ShaderMaterial> material; - material.instance(); + material.instantiate(); material->set_shader(preview_shader); //find if a material is also being edited and copy parameters to this one @@ -4977,7 +5065,7 @@ Ref<Resource> VisualShaderConversionPlugin::convert(const Ref<Resource> &p_resou ERR_FAIL_COND_V(!vshader.is_valid(), Ref<Resource>()); Ref<Shader> shader; - shader.instance(); + shader.instantiate(); String code = vshader->get_code(); shader->set_code(code); diff --git a/editor/plugins/visual_shader_editor_plugin.h b/editor/plugins/visual_shader_editor_plugin.h index 4c7489a694..2b354db7b3 100644 --- a/editor/plugins/visual_shader_editor_plugin.h +++ b/editor/plugins/visual_shader_editor_plugin.h @@ -75,7 +75,7 @@ private: LineEdit *uniform_name = nullptr; OptionButton *const_op = nullptr; CodeEdit *expression_edit = nullptr; - CurveEditor *curve_editor = nullptr; + CurveEditor *curve_editors[3] = { nullptr, nullptr, nullptr }; }; Ref<VisualShader> visual_shader; @@ -97,7 +97,7 @@ public: void register_default_input_button(int p_node_id, int p_port_id, Button *p_button); void register_constant_option_btn(int p_node_id, OptionButton *p_button); void register_expression_edit(int p_node_id, CodeEdit *p_expression_edit); - void register_curve_editor(int p_node_id, CurveEditor *p_curve_editor); + void register_curve_editor(int p_node_id, int p_index, CurveEditor *p_curve_editor); void clear_links(); void set_shader_type(VisualShader::Type p_type); bool is_preview_visible(int p_id) const; @@ -117,6 +117,7 @@ public: void update_uniform_refs(); void set_uniform_name(VisualShader::Type p_type, int p_node_id, const String &p_name); void update_curve(int p_node_id); + void update_curve3(int p_node_id); void update_constant(VisualShader::Type p_type, int p_node_id); void set_expression(VisualShader::Type p_type, int p_node_id, const String &p_expression); int get_constant_index(float p_constant) const; @@ -289,6 +290,7 @@ class VisualShaderEditor : public VBoxContainer { int texture3d_node_option_idx; int custom_node_option_idx; int curve_node_option_idx; + int curve3_node_option_idx; List<String> keyword_list; List<VisualShaderNodeUniformRef> uniform_refs; @@ -505,7 +507,7 @@ class EditorInspectorShaderModePlugin : public EditorInspectorPlugin { public: virtual bool can_handle(Object *p_object) override; virtual void parse_begin(Object *p_object) override; - virtual bool parse_property(Object *p_object, Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, int p_usage, bool p_wide = false) override; + virtual bool parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const uint32_t p_usage, const bool p_wide = false) override; virtual void parse_end() override; }; diff --git a/editor/plugins/voxel_gi_editor_plugin.cpp b/editor/plugins/voxel_gi_editor_plugin.cpp index d30cc7ad17..162379a49d 100644 --- a/editor/plugins/voxel_gi_editor_plugin.cpp +++ b/editor/plugins/voxel_gi_editor_plugin.cpp @@ -69,10 +69,7 @@ void VoxelGIEditorPlugin::_notification(int p_what) { const Vector3i size = voxel_gi->get_estimated_cell_size(); String text = vformat(String::utf8("%d × %d × %d"), size.x, size.y, size.z); - int data_size = 4; - if (GLOBAL_GET("rendering/quality/voxel_gi/anisotropic")) { - data_size += 4; - } + const int data_size = 4; const double size_mb = size.x * size.y * size.z * data_size / (1024.0 * 1024.0); text += " - " + vformat(TTR("VRAM Size: %s MB"), String::num(size_mb, 2)); diff --git a/editor/project_export.cpp b/editor/project_export.cpp index ec65694772..ad88e1b45b 100644 --- a/editor/project_export.cpp +++ b/editor/project_export.cpp @@ -64,6 +64,7 @@ void ProjectExportDialog::_notification(int p_what) { duplicate_preset->set_icon(presets->get_theme_icon("Duplicate", "EditorIcons")); delete_preset->set_icon(presets->get_theme_icon("Remove", "EditorIcons")); connect("confirmed", callable_mp(this, &ProjectExportDialog::_export_pck_zip)); + _update_export_all(); } break; } } @@ -182,10 +183,12 @@ void ProjectExportDialog::_update_export_all() { } } + export_all_button->set_disabled(!can_export); + if (can_export) { - export_all_button->set_disabled(false); + export_all_button->set_tooltip(TTR("Export the project for all the presets defined.")); } else { - export_all_button->set_disabled(true); + export_all_button->set_tooltip(TTR("All presets must have an export path defined for Export All to work.")); } } @@ -433,6 +436,7 @@ void ProjectExportDialog::_export_path_changed(const StringName &p_property, con current->set_export_path(p_value); _update_presets(); + _update_export_all(); } void ProjectExportDialog::_enc_filters_changed(const String &p_filters) { @@ -589,6 +593,10 @@ void ProjectExportDialog::_delete_preset_confirm() { get_ok_button()->set_disabled(true); EditorExport::get_singleton()->remove_export_preset(idx); _update_presets(); + + // The Export All button might become enabled (if all other presets have an export path defined), + // or it could be disabled (if there are no presets anymore). + _update_export_all(); } Variant ProjectExportDialog::get_drag_data_fw(const Point2 &p_point, Control *p_from) { @@ -1110,9 +1118,9 @@ ProjectExportDialog::ProjectExportDialog() { exclude_filters->connect("text_changed", callable_mp(this, &ProjectExportDialog::_filter_changed)); script_mode = memnew(OptionButton); - resources_vb->add_margin_child(TTR("Script Export Mode:"), script_mode); + resources_vb->add_margin_child(TTR("GDScript Export Mode:"), script_mode); script_mode->add_item(TTR("Text"), (int)EditorExportPreset::MODE_SCRIPT_TEXT); - script_mode->add_item(TTR("Compiled"), (int)EditorExportPreset::MODE_SCRIPT_COMPILED); + script_mode->add_item(TTR("Compiled Bytecode (Faster Loading)"), (int)EditorExportPreset::MODE_SCRIPT_COMPILED); script_mode->connect("item_selected", callable_mp(this, &ProjectExportDialog::_script_export_mode_changed)); // Feature tags. @@ -1137,12 +1145,12 @@ ProjectExportDialog::ProjectExportDialog() { enc_pck = memnew(CheckButton); enc_pck->connect("toggled", callable_mp(this, &ProjectExportDialog::_enc_pck_changed)); - enc_pck->set_text(TTR("Encrypt exported PCK")); + enc_pck->set_text(TTR("Encrypt Exported PCK")); sec_vb->add_child(enc_pck); enc_directory = memnew(CheckButton); enc_directory->connect("toggled", callable_mp(this, &ProjectExportDialog::_enc_directory_changed)); - enc_directory->set_text("Encrypt index (file names and info)."); + enc_directory->set_text("Encrypt Index (File Names and Info)"); sec_vb->add_child(enc_directory); enc_in_filters = memnew(LineEdit); @@ -1160,9 +1168,9 @@ ProjectExportDialog::ProjectExportDialog() { script_key = memnew(LineEdit); script_key->connect("text_changed", callable_mp(this, &ProjectExportDialog::_script_encryption_key_changed)); script_key_error = memnew(Label); - script_key_error->set_text("- " + TTR("Invalid Encryption Key (must be 64 characters long)")); + script_key_error->set_text("- " + TTR("Invalid Encryption Key (must be 64 hexadecimal characters long)")); script_key_error->add_theme_color_override("font_color", EditorNode::get_singleton()->get_gui_base()->get_theme_color("error_color", "Editor")); - sec_vb->add_margin_child(TTR("Encryption Key (256-bits as hex):"), script_key); + sec_vb->add_margin_child(TTR("Encryption Key (256-bits as hexadecimal):"), script_key); sec_vb->add_child(script_key_error); sections->add_child(sec_vb); @@ -1199,8 +1207,8 @@ ProjectExportDialog::ProjectExportDialog() { updating = false; get_cancel_button()->set_text(TTR("Close")); - get_ok_button()->set_text(TTR("Export PCK/Zip")); - export_button = add_button(TTR("Export Project"), !DisplayServer::get_singleton()->get_swap_cancel_ok(), "export"); + get_ok_button()->set_text(TTR("Export PCK/ZIP...")); + export_button = add_button(TTR("Export Project..."), !DisplayServer::get_singleton()->get_swap_cancel_ok(), "export"); export_button->connect("pressed", callable_mp(this, &ProjectExportDialog::_export_project)); // Disable initially before we select a valid preset export_button->set_disabled(true); @@ -1209,19 +1217,19 @@ ProjectExportDialog::ProjectExportDialog() { export_all_dialog = memnew(ConfirmationDialog); add_child(export_all_dialog); export_all_dialog->set_title("Export All"); - export_all_dialog->set_text(TTR("Export mode?")); + export_all_dialog->set_text(TTR("Choose an export mode:")); export_all_dialog->get_ok_button()->hide(); export_all_dialog->add_button(TTR("Debug"), true, "debug"); export_all_dialog->add_button(TTR("Release"), true, "release"); export_all_dialog->connect("custom_action", callable_mp(this, &ProjectExportDialog::_export_all_dialog_action)); - export_all_button = add_button(TTR("Export All"), !DisplayServer::get_singleton()->get_swap_cancel_ok(), "export"); + export_all_button = add_button(TTR("Export All..."), !DisplayServer::get_singleton()->get_swap_cancel_ok(), "export"); export_all_button->connect("pressed", callable_mp(this, &ProjectExportDialog::_export_all_dialog)); export_all_button->set_disabled(true); export_pck_zip = memnew(EditorFileDialog); export_pck_zip->add_filter("*.zip ; " + TTR("ZIP File")); - export_pck_zip->add_filter("*.pck ; " + TTR("Godot Game Pack")); + export_pck_zip->add_filter("*.pck ; " + TTR("Godot Project Pack")); export_pck_zip->set_access(EditorFileDialog::ACCESS_FILESYSTEM); export_pck_zip->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE); add_child(export_pck_zip); @@ -1282,8 +1290,6 @@ ProjectExportDialog::ProjectExportDialog() { default_filename = "UnnamedProject"; } } - - _update_export_all(); } ProjectExportDialog::~ProjectExportDialog() { diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp index fdd114bb1e..50a763f05a 100644 --- a/editor/project_manager.cpp +++ b/editor/project_manager.cpp @@ -862,7 +862,7 @@ public: rasterizer_container->add_child(l); Container *rshb = memnew(HBoxContainer); rasterizer_container->add_child(rshb); - rasterizer_button_group.instance(); + rasterizer_button_group.instantiate(); Container *rvb = memnew(VBoxContainer); rvb->set_h_size_flags(Control::SIZE_EXPAND_FILL); @@ -1145,7 +1145,7 @@ void ProjectList::load_project_icon(int p_index) { Ref<Texture2D> icon; if (item.icon != "") { Ref<Image> img; - img.instance(); + img.instantiate(); Error err = img->load(item.icon.replace_first("res://", item.path + "/")); if (err == OK) { img->resize(default_icon->get_width(), default_icon->get_height(), Image::INTERPOLATE_LANCZOS); diff --git a/editor/property_editor.cpp b/editor/property_editor.cpp index ba3c9aafb4..7414c2d8e6 100644 --- a/editor/property_editor.cpp +++ b/editor/property_editor.cpp @@ -192,7 +192,7 @@ void CustomPropertyEditor::_menu_option(int p_which) { String orig_type = res_orig->get_class(); - Object *inst = ClassDB::instance(orig_type); + Object *inst = ClassDB::instantiate(orig_type); Ref<Resource> res = Ref<Resource>(Object::cast_to<Resource>(inst)); @@ -262,7 +262,7 @@ void CustomPropertyEditor::_menu_option(int p_which) { return; } - Variant obj = ClassDB::instance(intype); + Variant obj = ClassDB::instantiate(intype); if (!obj) { if (ScriptServer::is_global_class(intype)) { @@ -908,7 +908,7 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant:: } } - if (!is_custom_resource && !ClassDB::can_instance(t)) { + if (!is_custom_resource && !ClassDB::can_instantiate(t)) { continue; } @@ -1078,7 +1078,7 @@ void CustomPropertyEditor::_type_create_selected(int p_idx) { String intype = inheritors_array[p_idx]; - Variant obj = ClassDB::instance(intype); + Variant obj = ClassDB::instantiate(intype); if (!obj) { if (ScriptServer::is_global_class(intype)) { @@ -1111,7 +1111,7 @@ void CustomPropertyEditor::_node_path_selected(NodePath p_path) { } Ref<ViewportTexture> vt; - vt.instance(); + vt.instantiate(); vt->set_viewport_path_in_scene(get_tree()->get_edited_scene_root()->get_path_to(to_node)); vt->setup_local_to_scene(); v = vt; @@ -1268,7 +1268,7 @@ void CustomPropertyEditor::_action_pressed(int p_which) { String intype = inheritors_array[0]; if (hint == PROPERTY_HINT_RESOURCE_TYPE) { - Variant obj = ClassDB::instance(intype); + Variant obj = ClassDB::instantiate(intype); if (!obj) { if (ScriptServer::is_global_class(intype)) { @@ -1332,7 +1332,7 @@ void CustomPropertyEditor::_action_pressed(int p_which) { propvalues.push_back(p); } - Ref<Resource> res = Ref<Resource>(ClassDB::instance(res_orig->get_class())); + Ref<Resource> res = Ref<Resource>(ClassDB::instantiate(res_orig->get_class())); ERR_FAIL_COND(res.is_null()); @@ -1453,7 +1453,7 @@ void CustomPropertyEditor::_modified(String p_string) { case Variant::INT: { String text = TS->parse_number(value_editor[0]->get_text()); Ref<Expression> expr; - expr.instance(); + expr.instantiate(); Error err = expr->parse(text); if (err != OK) { v = value_editor[0]->get_text().to_int(); @@ -1629,7 +1629,7 @@ void CustomPropertyEditor::_modified(String p_string) { real_t CustomPropertyEditor::_parse_real_expression(String text) { Ref<Expression> expr; - expr.instance(); + expr.instantiate(); Error err = expr->parse(text); real_t out; if (err != OK) { diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index 36d9fa176f..a9dcbc9f09 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -58,7 +58,7 @@ void SceneTreeDock::_nodes_drag_begin() { } void SceneTreeDock::_quick_open() { - instance_scenes(quick_open->get_selected_files(), scene_tree->get_selected()); + instantiate_scenes(quick_open->get_selected_files(), scene_tree->get_selected()); } void SceneTreeDock::_input(Ref<InputEvent> p_event) { @@ -89,7 +89,7 @@ void SceneTreeDock::_unhandled_key_input(Ref<InputEvent> p_event) { } else if (ED_IS_SHORTCUT("scene_tree/add_child_node", p_event)) { _tool_selected(TOOL_NEW); } else if (ED_IS_SHORTCUT("scene_tree/instance_scene", p_event)) { - _tool_selected(TOOL_INSTANCE); + _tool_selected(TOOL_INSTANTIATE); } else if (ED_IS_SHORTCUT("scene_tree/expand_collapse_all", p_event)) { _tool_selected(TOOL_EXPAND_COLLAPSE); } else if (ED_IS_SHORTCUT("scene_tree/cut_node", p_event)) { @@ -128,13 +128,13 @@ void SceneTreeDock::_unhandled_key_input(Ref<InputEvent> p_event) { accept_event(); } -void SceneTreeDock::instance(const String &p_file) { +void SceneTreeDock::instantiate(const String &p_file) { Vector<String> scenes; scenes.push_back(p_file); - instance_scenes(scenes, scene_tree->get_selected()); + instantiate_scenes(scenes, scene_tree->get_selected()); } -void SceneTreeDock::instance_scenes(const Vector<String> &p_files, Node *p_parent) { +void SceneTreeDock::instantiate_scenes(const Vector<String> &p_files, Node *p_parent) { Node *parent = p_parent; if (!parent) { @@ -147,18 +147,18 @@ void SceneTreeDock::instance_scenes(const Vector<String> &p_files, Node *p_paren if (!parent) { if (p_files.size() == 1) { - accept->set_text(TTR("No parent to instance a child at.")); + accept->set_text(TTR("No parent to instantiate a child at.")); } else { - accept->set_text(TTR("No parent to instance the scenes at.")); + accept->set_text(TTR("No parent to instantiate the scenes at.")); } accept->popup_centered(); return; }; - _perform_instance_scenes(p_files, parent, -1); + _perform_instantiate_scenes(p_files, parent, -1); } -void SceneTreeDock::_perform_instance_scenes(const Vector<String> &p_files, Node *parent, int p_pos) { +void SceneTreeDock::_perform_instantiate_scenes(const Vector<String> &p_files, Node *parent, int p_pos) { ERR_FAIL_COND(!parent); Vector<Node *> instances; @@ -175,8 +175,8 @@ void SceneTreeDock::_perform_instance_scenes(const Vector<String> &p_files, Node break; } - Node *instanced_scene = sdata->instance(PackedScene::GEN_EDIT_STATE_INSTANCE); - if (!instanced_scene) { + Node *instantiated_scene = sdata->instantiate(PackedScene::GEN_EDIT_STATE_INSTANCE); + if (!instantiated_scene) { current_option = -1; accept->set_text(vformat(TTR("Error instancing scene from %s"), p_files[i])); accept->popup_centered(); @@ -185,7 +185,7 @@ void SceneTreeDock::_perform_instance_scenes(const Vector<String> &p_files, Node } if (edited_scene->get_filename() != "") { - if (_cyclical_dependency_exists(edited_scene->get_filename(), instanced_scene)) { + if (_cyclical_dependency_exists(edited_scene->get_filename(), instantiated_scene)) { accept->set_text(vformat(TTR("Cannot instance the scene '%s' because the current scene exists within one of its nodes."), p_files[i])); accept->popup_centered(); error = true; @@ -193,9 +193,9 @@ void SceneTreeDock::_perform_instance_scenes(const Vector<String> &p_files, Node } } - instanced_scene->set_filename(ProjectSettings::get_singleton()->localize_path(p_files[i])); + instantiated_scene->set_filename(ProjectSettings::get_singleton()->localize_path(p_files[i])); - instances.push_back(instanced_scene); + instances.push_back(instantiated_scene); } if (error) { @@ -208,19 +208,19 @@ void SceneTreeDock::_perform_instance_scenes(const Vector<String> &p_files, Node editor_data->get_undo_redo().create_action(TTR("Instance Scene(s)")); for (int i = 0; i < instances.size(); i++) { - Node *instanced_scene = instances[i]; + Node *instantiated_scene = instances[i]; - editor_data->get_undo_redo().add_do_method(parent, "add_child", instanced_scene); + editor_data->get_undo_redo().add_do_method(parent, "add_child", instantiated_scene); if (p_pos >= 0) { - editor_data->get_undo_redo().add_do_method(parent, "move_child", instanced_scene, p_pos + i); + editor_data->get_undo_redo().add_do_method(parent, "move_child", instantiated_scene, p_pos + i); } - editor_data->get_undo_redo().add_do_method(instanced_scene, "set_owner", edited_scene); + editor_data->get_undo_redo().add_do_method(instantiated_scene, "set_owner", edited_scene); editor_data->get_undo_redo().add_do_method(editor_selection, "clear"); - editor_data->get_undo_redo().add_do_method(editor_selection, "add_node", instanced_scene); - editor_data->get_undo_redo().add_do_reference(instanced_scene); - editor_data->get_undo_redo().add_undo_method(parent, "remove_child", instanced_scene); + editor_data->get_undo_redo().add_do_method(editor_selection, "add_node", instantiated_scene); + editor_data->get_undo_redo().add_do_reference(instantiated_scene); + editor_data->get_undo_redo().add_undo_method(parent, "remove_child", instantiated_scene); - String new_name = parent->validate_child_name(instanced_scene); + String new_name = parent->validate_child_name(instantiated_scene); EditorDebuggerNode *ed = EditorDebuggerNode::get_singleton(); editor_data->get_undo_redo().add_do_method(ed, "live_debug_instance_node", edited_scene->get_path_to(parent), p_files[i], new_name); editor_data->get_undo_redo().add_undo_method(ed, "live_debug_remove_node", NodePath(String(edited_scene->get_path_to(parent)).plus_file(new_name))); @@ -241,8 +241,8 @@ void SceneTreeDock::_replace_with_branch_scene(const String &p_file, Node *base) return; } - Node *instanced_scene = sdata->instance(PackedScene::GEN_EDIT_STATE_INSTANCE); - if (!instanced_scene) { + Node *instantiated_scene = sdata->instantiate(PackedScene::GEN_EDIT_STATE_INSTANCE); + if (!instantiated_scene) { accept->set_text(vformat(TTR("Error instancing scene from %s"), p_file)); accept->popup_centered(); return; @@ -254,10 +254,10 @@ void SceneTreeDock::_replace_with_branch_scene(const String &p_file, Node *base) Node *parent = base->get_parent(); int pos = base->get_index(); undo_redo->add_do_method(parent, "remove_child", base); - undo_redo->add_undo_method(parent, "remove_child", instanced_scene); - undo_redo->add_do_method(parent, "add_child", instanced_scene); + undo_redo->add_undo_method(parent, "remove_child", instantiated_scene); + undo_redo->add_do_method(parent, "add_child", instantiated_scene); undo_redo->add_undo_method(parent, "add_child", base); - undo_redo->add_do_method(parent, "move_child", instanced_scene, pos); + undo_redo->add_do_method(parent, "move_child", instantiated_scene, pos); undo_redo->add_undo_method(parent, "move_child", base, pos); List<Node *> owned; @@ -266,17 +266,17 @@ void SceneTreeDock::_replace_with_branch_scene(const String &p_file, Node *base) for (List<Node *>::Element *F = owned.front(); F; F = F->next()) { owners.push_back(F->get()); } - undo_redo->add_do_method(instanced_scene, "set_owner", edited_scene); + undo_redo->add_do_method(instantiated_scene, "set_owner", edited_scene); undo_redo->add_undo_method(this, "_set_owners", edited_scene, owners); undo_redo->add_do_method(editor_selection, "clear"); undo_redo->add_undo_method(editor_selection, "clear"); - undo_redo->add_do_method(editor_selection, "add_node", instanced_scene); + undo_redo->add_do_method(editor_selection, "add_node", instantiated_scene); undo_redo->add_undo_method(editor_selection, "add_node", base); - undo_redo->add_do_property(scene_tree, "set_selected", instanced_scene); + undo_redo->add_do_property(scene_tree, "set_selected", instantiated_scene); undo_redo->add_undo_property(scene_tree, "set_selected", base); - undo_redo->add_do_reference(instanced_scene); + undo_redo->add_do_reference(instantiated_scene); undo_redo->add_undo_reference(base); undo_redo->commit_action(); } @@ -313,7 +313,7 @@ bool SceneTreeDock::_track_inherit(const String &p_target_scene_path, Node *p_de String path = ss->get_path(); Ref<PackedScene> data = ResourceLoader::load(path); if (data.is_valid()) { - p = data->instance(PackedScene::GEN_EDIT_STATE_INSTANCE); + p = data->instantiate(PackedScene::GEN_EDIT_STATE_INSTANCE); if (!p) { continue; } @@ -359,7 +359,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { break; } - if (reset_create_dialog) { + if (reset_create_dialog && !p_confirm_override) { create_dialog->set_base_type("Node"); reset_create_dialog = false; } @@ -388,7 +388,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { emit_signal("add_node_used"); } } break; - case TOOL_INSTANCE: { + case TOOL_INSTANTIATE: { if (!profile_allow_editing) { break; } @@ -400,7 +400,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { } quick_open->popup_dialog("PackedScene", true); - quick_open->set_title(TTR("Instance Child Scene")); + quick_open->set_title(TTR("Instantiate Child Scene")); if (!p_confirm_override) { emit_signal("add_node_used"); } @@ -881,7 +881,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { if (node == editor_data->get_edited_scene_root()) { msg = vformat(TTR("Delete the root node \"%s\"?"), node->get_name()); } else if (node->get_filename() == "" && node->get_child_count() > 0) { - // Display this message only for non-instanced scenes + // Display this message only for non-instantiated scenes msg = vformat(TTR("Delete node \"%s\" and its children?"), node->get_name()); } else { msg = vformat(TTR("Delete node \"%s\"?"), node->get_name()); @@ -922,13 +922,13 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { Node *tocopy = selection.front()->get(); if (tocopy == scene) { - accept->set_text(TTR("Can't save the root node branch as an instanced scene.\nTo create an editable copy of the current scene, duplicate it using the FileSystem dock context menu\nor create an inherited scene using Scene > New Inherited Scene... instead.")); + accept->set_text(TTR("Can't save the root node branch as an instantiated scene.\nTo create an editable copy of the current scene, duplicate it using the FileSystem dock context menu\nor create an inherited scene using Scene > New Inherited Scene... instead.")); accept->popup_centered(); break; } if (tocopy != editor_data->get_edited_scene_root() && tocopy->get_filename() != "") { - accept->set_text(TTR("Can't save the branch of an already instanced scene.\nTo create a variation of a scene, you can make an inherited scene based on the instanced scene using Scene > New Inherited Scene... instead.")); + accept->set_text(TTR("Can't save the branch of an already instantiated scene.\nTo create a variation of a scene, you can make an inherited scene based on the instantiated scene using Scene > New Inherited Scene... instead.")); accept->popup_centered(); break; } @@ -1103,14 +1103,14 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { if (TOOL_CREATE_FAVORITE == p_tool) { String name = selected_favorite_root.get_slicec(' ', 0); if (ScriptServer::is_global_class(name)) { - new_node = Object::cast_to<Node>(ClassDB::instance(ScriptServer::get_global_class_native_base(name))); + new_node = Object::cast_to<Node>(ClassDB::instantiate(ScriptServer::get_global_class_native_base(name))); Ref<Script> script = ResourceLoader::load(ScriptServer::get_global_class_path(name), "Script"); if (new_node && script.is_valid()) { new_node->set_script(script); new_node->set_name(name); } } else { - new_node = Object::cast_to<Node>(ClassDB::instance(selected_favorite_root)); + new_node = Object::cast_to<Node>(ClassDB::instantiate(selected_favorite_root)); } if (!new_node) { @@ -1134,12 +1134,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { } } - editor_data->get_undo_redo().create_action(TTR("New Scene Root")); - editor_data->get_undo_redo().add_do_method(editor, "set_edited_scene", new_node); - editor_data->get_undo_redo().add_do_method(scene_tree, "update_tree"); - editor_data->get_undo_redo().add_do_reference(new_node); - editor_data->get_undo_redo().add_undo_method(editor, "set_edited_scene", (Object *)nullptr); - editor_data->get_undo_redo().commit_action(); + add_root_node(new_node); editor->edit_node(new_node); editor_selection->clear(); @@ -1162,6 +1157,15 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { } } +void SceneTreeDock::add_root_node(Node *p_node) { + editor_data->get_undo_redo().create_action(TTR("New Scene Root")); + editor_data->get_undo_redo().add_do_method(editor, "set_edited_scene", p_node); + editor_data->get_undo_redo().add_do_method(scene_tree, "update_tree"); + editor_data->get_undo_redo().add_do_reference(p_node); + editor_data->get_undo_redo().add_undo_method(editor, "set_edited_scene", (Object *)nullptr); + editor_data->get_undo_redo().commit_action(); +} + void SceneTreeDock::_node_collapsed(Object *p_obj) { TreeItem *ti = Object::cast_to<TreeItem>(p_obj); if (!ti) { @@ -1406,9 +1410,102 @@ void SceneTreeDock::fill_path_renames(Node *p_node, Node *p_new_parent, List<Pai _fill_path_renames(base_path, new_base_path, p_node, p_renames); } +bool SceneTreeDock::_update_node_path(const NodePath &p_root_path, NodePath &r_node_path, List<Pair<NodePath, NodePath>> *p_renames) { + NodePath root_path_new = p_root_path; + for (List<Pair<NodePath, NodePath>>::Element *F = p_renames->front(); F; F = F->next()) { + if (p_root_path == F->get().first) { + root_path_new = F->get().second; + break; + } + } + + // Goes through all paths to check if it's matching. + for (List<Pair<NodePath, NodePath>>::Element *F = p_renames->front(); F; F = F->next()) { + NodePath rel_path_old = p_root_path.rel_path_to(F->get().first); + + // If old path detected, then it needs to be replaced with the new one. + if (r_node_path == rel_path_old) { + NodePath rel_path_new = F->get().second; + + // If not empty, get new relative path. + if (!rel_path_new.is_empty()) { + rel_path_new = root_path_new.rel_path_to(rel_path_new); + } + + r_node_path = rel_path_new; + return true; + } + + // Update the node itself if it has a valid node path and has not been deleted. + if (p_root_path == F->get().first && r_node_path != NodePath() && F->get().second != NodePath()) { + NodePath abs_path = NodePath(String(root_path_new).plus_file(r_node_path)).simplified(); + NodePath rel_path_new = F->get().second.rel_path_to(abs_path); + + r_node_path = rel_path_new; + return true; + } + } + + return false; +} + +bool SceneTreeDock::_check_node_path_recursive(const NodePath &p_root_path, Variant &r_variant, List<Pair<NodePath, NodePath>> *p_renames) { + switch (r_variant.get_type()) { + case Variant::NODE_PATH: { + NodePath node_path = r_variant; + if (_update_node_path(p_root_path, node_path, p_renames)) { + r_variant = node_path; + return true; + } + } break; + + case Variant::ARRAY: { + Array a = r_variant; + bool updated = false; + for (int i = 0; i < a.size(); i++) { + Variant value = a[i]; + if (_check_node_path_recursive(p_root_path, value, p_renames)) { + if (!updated) { + a = a.duplicate(); // Need to duplicate for undo-redo to work. + updated = true; + } + a[i] = value; + } + } + if (updated) { + r_variant = a; + return true; + } + } break; + + case Variant::DICTIONARY: { + Dictionary d = r_variant; + bool updated = false; + for (int i = 0; i < d.size(); i++) { + Variant value = d.get_value_at_index(i); + if (_check_node_path_recursive(p_root_path, value, p_renames)) { + if (!updated) { + d = d.duplicate(); // Need to duplicate for undo-redo to work. + updated = true; + } + d[d.get_key_at_index(i)] = value; + } + } + if (updated) { + r_variant = d; + return true; + } + } break; + + default: { + } + } + + return false; +} + void SceneTreeDock::perform_node_renames(Node *p_base, List<Pair<NodePath, NodePath>> *p_renames, Map<Ref<Animation>, Set<int>> *r_rem_anims) { Map<Ref<Animation>, Set<int>> rem_anims; - if (!r_rem_anims) { r_rem_anims = &rem_anims; } @@ -1421,60 +1518,22 @@ void SceneTreeDock::perform_node_renames(Node *p_base, List<Pair<NodePath, NodeP return; } - // Renaming node paths used in script instances - if (p_base->get_script_instance()) { - ScriptInstance *si = p_base->get_script_instance(); - - if (si) { - List<PropertyInfo> properties; - si->get_property_list(&properties); - NodePath root_path = p_base->get_path(); - - for (List<PropertyInfo>::Element *E = properties.front(); E; E = E->next()) { - String propertyname = E->get().name; - Variant p = p_base->get(propertyname); - if (p.get_type() == Variant::NODE_PATH) { - NodePath root_path_new = root_path; - for (List<Pair<NodePath, NodePath>>::Element *F = p_renames->front(); F; F = F->next()) { - if (root_path == F->get().first) { - root_path_new = F->get().second; - break; - } - } - - // Goes through all paths to check if its matching - for (List<Pair<NodePath, NodePath>>::Element *F = p_renames->front(); F; F = F->next()) { - NodePath rel_path_old = root_path.rel_path_to(F->get().first); - - // if old path detected, then it needs to be replaced with the new one - if (p == rel_path_old) { - NodePath rel_path_new = F->get().second; - - // if not empty, get new relative path - if (!rel_path_new.is_empty()) { - rel_path_new = root_path_new.rel_path_to(F->get().second); - } - - editor_data->get_undo_redo().add_do_property(p_base, propertyname, rel_path_new); - editor_data->get_undo_redo().add_undo_property(p_base, propertyname, rel_path_old); - - p_base->set(propertyname, rel_path_new); - break; - } - - // update the node itself if it has a valid node path and has not been deleted - if (root_path == F->get().first && p != NodePath() && F->get().second != NodePath()) { - NodePath abs_path = NodePath(String(root_path).plus_file(p)).simplified(); - NodePath rel_path_new = F->get().second.rel_path_to(abs_path); - - editor_data->get_undo_redo().add_do_property(p_base, propertyname, rel_path_new); - editor_data->get_undo_redo().add_undo_property(p_base, propertyname, p); + // Renaming node paths used in node properties. + List<PropertyInfo> properties; + p_base->get_property_list(&properties); + NodePath base_root_path = p_base->get_path(); - p_base->set(propertyname, rel_path_new); - } - } - } - } + for (List<PropertyInfo>::Element *E = properties.front(); E; E = E->next()) { + if (!(E->get().usage & (PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_EDITOR))) { + continue; + } + String propertyname = E->get().name; + Variant old_variant = p_base->get(propertyname); + Variant updated_variant = old_variant; + if (_check_node_path_recursive(base_root_path, updated_variant, p_renames)) { + editor_data->get_undo_redo().add_do_property(p_base, propertyname, updated_variant); + editor_data->get_undo_redo().add_undo_property(p_base, propertyname, old_variant); + p_base->set(propertyname, updated_variant); } } @@ -1637,7 +1696,7 @@ bool SceneTreeDock::_validate_no_instance() { for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { if (E->get() != edited_scene && E->get()->get_filename() != "") { - accept->set_text(TTR("This operation can't be done on instanced scenes.")); + accept->set_text(TTR("This operation can't be done on instantiated scenes.")); accept->popup_centered(); return false; } @@ -2215,7 +2274,7 @@ void SceneTreeDock::replace_node(Node *p_node, Node *p_by_node, bool p_keep_prop Node *newnode = p_by_node; if (p_keep_properties) { - Node *default_oldnode = Object::cast_to<Node>(ClassDB::instance(n->get_class())); + Node *default_oldnode = Object::cast_to<Node>(ClassDB::instantiate(n->get_class())); List<PropertyInfo> pinfo; n->get_property_list(&pinfo); @@ -2456,7 +2515,7 @@ void SceneTreeDock::_files_dropped(Vector<String> p_files, NodePath p_to, int p_ int to_pos = -1; _normalize_drop(node, to_pos, p_type); - _perform_instance_scenes(p_files, node, to_pos); + _perform_instantiate_scenes(p_files, node, to_pos); } void SceneTreeDock::_script_dropped(String p_file, NodePath p_to) { @@ -2539,7 +2598,7 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) { menu->clear(); if (profile_allow_editing) { menu->add_icon_shortcut(get_theme_icon("Add", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/add_child_node"), TOOL_NEW); - menu->add_icon_shortcut(get_theme_icon("Instance", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/instance_scene"), TOOL_INSTANCE); + menu->add_icon_shortcut(get_theme_icon("Instance", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/instance_scene"), TOOL_INSTANTIATE); } menu->set_size(Size2(1, 1)); @@ -2572,7 +2631,7 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) { } menu->add_icon_shortcut(get_theme_icon("Add", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/add_child_node"), TOOL_NEW); - menu->add_icon_shortcut(get_theme_icon("Instance", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/instance_scene"), TOOL_INSTANCE); + menu->add_icon_shortcut(get_theme_icon("Instance", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/instance_scene"), TOOL_INSTANTIATE); } menu->add_icon_shortcut(get_theme_icon("Collapse", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/expand_collapse_all"), TOOL_EXPAND_COLLAPSE); menu->add_separator(); @@ -2810,7 +2869,7 @@ void SceneTreeDock::open_add_child_dialog() { } void SceneTreeDock::open_instance_child_dialog() { - _tool_selected(TOOL_INSTANCE, true); + _tool_selected(TOOL_INSTANTIATE, true); } void SceneTreeDock::add_remote_tree_editor(Control *p_remote) { @@ -2956,7 +3015,7 @@ void SceneTreeDock::_clear_clipboard() { void SceneTreeDock::_create_remap_for_node(Node *p_node, Map<RES, RES> &r_remap) { List<PropertyInfo> props; p_node->get_property_list(&props); - bool is_instanced = EditorPropertyRevert::may_node_be_in_instance(p_node); + bool is_instantiated = EditorPropertyRevert::may_node_be_in_instance(p_node); for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) { @@ -2967,9 +3026,9 @@ void SceneTreeDock::_create_remap_for_node(Node *p_node, Map<RES, RES> &r_remap) if (v.is_ref()) { RES res = v; if (res.is_valid()) { - if (is_instanced) { + if (is_instantiated) { Variant orig; - if (EditorPropertyRevert::get_instanced_node_original_property(p_node, E->get().name, orig)) { + if (EditorPropertyRevert::get_instantiated_node_original_property(p_node, E->get().name, orig)) { if (!EditorPropertyRevert::is_node_property_different(p_node, v, orig)) { continue; } @@ -3017,7 +3076,7 @@ void SceneTreeDock::_bind_methods() { ClassDB::bind_method(D_METHOD("_input"), &SceneTreeDock::_input); ClassDB::bind_method(D_METHOD("_update_script_button"), &SceneTreeDock::_update_script_button); - ClassDB::bind_method(D_METHOD("instance"), &SceneTreeDock::instance); + ClassDB::bind_method(D_METHOD("instantiate"), &SceneTreeDock::instantiate); ClassDB::bind_method(D_METHOD("get_tree_editor"), &SceneTreeDock::get_tree_editor); ClassDB::bind_method(D_METHOD("replace_node"), &SceneTreeDock::replace_node); @@ -3051,7 +3110,7 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor, Node *p_scene_root, EditorSel ED_SHORTCUT("scene_tree/rename", TTR("Rename"), KEY_F2); ED_SHORTCUT("scene_tree/batch_rename", TTR("Batch Rename"), KEY_MASK_SHIFT | KEY_F2); ED_SHORTCUT("scene_tree/add_child_node", TTR("Add Child Node"), KEY_MASK_CMD | KEY_A); - ED_SHORTCUT("scene_tree/instance_scene", TTR("Instance Child Scene"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_A); + ED_SHORTCUT("scene_tree/instance_scene", TTR("Instantiate Child Scene"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_A); ED_SHORTCUT("scene_tree/expand_collapse_all", TTR("Expand/Collapse All")); ED_SHORTCUT("scene_tree/cut_node", TTR("Cut"), KEY_MASK_CMD | KEY_X); ED_SHORTCUT("scene_tree/copy_node", TTR("Copy"), KEY_MASK_CMD | KEY_C); @@ -3080,8 +3139,8 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor, Node *p_scene_root, EditorSel button_instance = memnew(Button); button_instance->set_flat(true); - button_instance->connect("pressed", callable_mp(this, &SceneTreeDock::_tool_selected), make_binds(TOOL_INSTANCE, false)); - button_instance->set_tooltip(TTR("Instance a scene file as a Node. Creates an inherited scene if no root node exists.")); + button_instance->connect("pressed", callable_mp(this, &SceneTreeDock::_tool_selected), make_binds(TOOL_INSTANTIATE, false)); + button_instance->set_tooltip(TTR("Instantiate a scene file as a Node. Creates an inherited scene if no root node exists.")); button_instance->set_shortcut(ED_GET_SHORTCUT("scene_tree/instance_scene")); filter_hbc->add_child(button_instance); diff --git a/editor/scene_tree_dock.h b/editor/scene_tree_dock.h index 53f31375f8..08d992d465 100644 --- a/editor/scene_tree_dock.h +++ b/editor/scene_tree_dock.h @@ -55,7 +55,7 @@ class SceneTreeDock : public VBoxContainer { enum Tool { TOOL_NEW, - TOOL_INSTANCE, + TOOL_INSTANTIATE, TOOL_EXPAND_COLLAPSE, TOOL_CUT, TOOL_COPY, @@ -224,7 +224,7 @@ class SceneTreeDock : public VBoxContainer { void _filter_changed(const String &p_filter); - void _perform_instance_scenes(const Vector<String> &p_files, Node *parent, int p_pos); + void _perform_instantiate_scenes(const Vector<String> &p_files, Node *parent, int p_pos); void _replace_with_branch_scene(const String &p_file, Node *base); void _file_selected(String p_file); @@ -247,6 +247,9 @@ class SceneTreeDock : public VBoxContainer { static SceneTreeDock *singleton; static void _update_configuration_warning(); + static bool _update_node_path(const NodePath &p_root_path, NodePath &r_node_path, List<Pair<NodePath, NodePath>> *p_renames); + static bool _check_node_path_recursive(const NodePath &p_root_path, Variant &r_variant, List<Pair<NodePath, NodePath>> *p_renames); + protected: void _notification(int p_what); static void _bind_methods(); @@ -258,9 +261,10 @@ public: void _focus_node(); void import_subscene(); + void add_root_node(Node *p_node); void set_edited_scene(Node *p_scene); - void instance(const String &p_file); - void instance_scenes(const Vector<String> &p_files, Node *p_parent = nullptr); + void instantiate(const String &p_file); + void instantiate_scenes(const Vector<String> &p_files, Node *p_parent = nullptr); void set_selected(Node *p_node, bool p_emit_selected = false); void fill_path_renames(Node *p_node, Node *p_new_parent, List<Pair<NodePath, NodePath>> *p_renames); void perform_node_renames(Node *p_base, List<Pair<NodePath, NodePath>> *p_renames, Map<Ref<Animation>, Set<int>> *r_rem_anims = nullptr); diff --git a/editor/scene_tree_editor.cpp b/editor/scene_tree_editor.cpp index 1de88a4a4e..ee66f28045 100644 --- a/editor/scene_tree_editor.cpp +++ b/editor/scene_tree_editor.cpp @@ -951,7 +951,7 @@ Variant SceneTreeEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from Node *n = get_node(np); if (n) { - // Only allow selection if not part of an instanced scene. + // Only allow selection if not part of an instantiated scene. if (!n->get_owner() || n->get_owner() == get_scene_node() || n->get_owner()->get_filename() == String()) { selected.push_back(n); icons.push_back(next->get_icon(0)); diff --git a/editor/script_create_dialog.cpp b/editor/script_create_dialog.cpp index 01743bccab..97edf84488 100644 --- a/editor/script_create_dialog.cpp +++ b/editor/script_create_dialog.cpp @@ -40,38 +40,35 @@ #include "editor/editor_scale.h" #include "editor_file_system.h" -void ScriptCreateDialog::_theme_changed() { - for (int i = 0; i < ScriptServer::get_language_count(); i++) { - String lang = ScriptServer::get_language(i)->get_type(); - Ref<Texture2D> lang_icon = gc->get_theme_icon(lang, "EditorIcons"); - if (lang_icon.is_valid()) { - language_menu->set_item_icon(i, lang_icon); - } - } - - String last_lang = EditorSettings::get_singleton()->get_project_metadata("script_setup", "last_selected_language", ""); - if (!last_lang.is_empty()) { - for (int i = 0; i < language_menu->get_item_count(); i++) { - if (language_menu->get_item_text(i) == last_lang) { - language_menu->select(i); - current_language = i; - break; +void ScriptCreateDialog::_notification(int p_what) { + switch (p_what) { + case NOTIFICATION_ENTER_TREE: + case NOTIFICATION_THEME_CHANGED: { + for (int i = 0; i < ScriptServer::get_language_count(); i++) { + String lang = ScriptServer::get_language(i)->get_type(); + Ref<Texture2D> lang_icon = get_theme_icon(lang, "EditorIcons"); + if (lang_icon.is_valid()) { + language_menu->set_item_icon(i, lang_icon); + } } - } - } else { - language_menu->select(default_language); - } - path_button->set_icon(gc->get_theme_icon("Folder", "EditorIcons")); - parent_browse_button->set_icon(gc->get_theme_icon("Folder", "EditorIcons")); - parent_search_button->set_icon(gc->get_theme_icon("ClassList", "EditorIcons")); - status_panel->add_theme_style_override("panel", gc->get_theme_stylebox("bg", "Tree")); -} + String last_lang = EditorSettings::get_singleton()->get_project_metadata("script_setup", "last_selected_language", ""); + if (!last_lang.is_empty()) { + for (int i = 0; i < language_menu->get_item_count(); i++) { + if (language_menu->get_item_text(i) == last_lang) { + language_menu->select(i); + current_language = i; + break; + } + } + } else { + language_menu->select(default_language); + } -void ScriptCreateDialog::_notification(int p_what) { - switch (p_what) { - case NOTIFICATION_ENTER_TREE: { - _theme_changed(); + path_button->set_icon(get_theme_icon("Folder", "EditorIcons")); + parent_browse_button->set_icon(get_theme_icon("Folder", "EditorIcons")); + parent_search_button->set_icon(get_theme_icon("ClassList", "EditorIcons")); + status_panel->add_theme_style_override("panel", get_theme_stylebox("bg", "Tree")); } break; } } @@ -451,7 +448,7 @@ void ScriptCreateDialog::_lang_changed(int l) { override_info += ", "; } } - template_menu->set_item_icon(extended.id, gc->get_theme_icon("Override", "EditorIcons")); + template_menu->set_item_icon(extended.id, get_theme_icon("Override", "EditorIcons")); template_menu->get_popup()->set_item_tooltip(extended.id, override_info.as_string()); } // Reselect last selected template @@ -609,18 +606,18 @@ void ScriptCreateDialog::_path_submitted(const String &p_path) { void ScriptCreateDialog::_msg_script_valid(bool valid, const String &p_msg) { error_label->set_text("- " + p_msg); if (valid) { - error_label->add_theme_color_override("font_color", gc->get_theme_color("success_color", "Editor")); + error_label->add_theme_color_override("font_color", get_theme_color("success_color", "Editor")); } else { - error_label->add_theme_color_override("font_color", gc->get_theme_color("error_color", "Editor")); + error_label->add_theme_color_override("font_color", get_theme_color("error_color", "Editor")); } } void ScriptCreateDialog::_msg_path_valid(bool valid, const String &p_msg) { path_error_label->set_text("- " + p_msg); if (valid) { - path_error_label->add_theme_color_override("font_color", gc->get_theme_color("success_color", "Editor")); + path_error_label->add_theme_color_override("font_color", get_theme_color("success_color", "Editor")); } else { - path_error_label->add_theme_color_override("font_color", gc->get_theme_color("error_color", "Editor")); + path_error_label->add_theme_color_override("font_color", get_theme_color("error_color", "Editor")); } } @@ -748,15 +745,11 @@ void ScriptCreateDialog::_bind_methods() { } ScriptCreateDialog::ScriptCreateDialog() { - /* DIALOG */ - /* Main Controls */ - gc = memnew(GridContainer); + GridContainer *gc = memnew(GridContainer); gc->set_columns(2); - gc->connect("theme_changed", callable_mp(this, &ScriptCreateDialog::_theme_changed)); - /* Error Messages Field */ VBoxContainer *vb = memnew(VBoxContainer); @@ -784,6 +777,7 @@ ScriptCreateDialog::ScriptCreateDialog() { status_panel = memnew(PanelContainer); status_panel->set_h_size_flags(Control::SIZE_FILL); + status_panel->set_v_size_flags(Control::SIZE_EXPAND_FILL); status_panel->add_child(vb); /* Spacing */ @@ -795,10 +789,7 @@ ScriptCreateDialog::ScriptCreateDialog() { vb->add_child(gc); vb->add_child(spacing); vb->add_child(status_panel); - HBoxContainer *hb = memnew(HBoxContainer); - hb->add_child(vb); - - add_child(hb); + add_child(vb); /* Language */ @@ -827,14 +818,13 @@ ScriptCreateDialog::ScriptCreateDialog() { base_type = "Object"; - hb = memnew(HBoxContainer); + HBoxContainer *hb = memnew(HBoxContainer); hb->set_h_size_flags(Control::SIZE_EXPAND_FILL); parent_name = memnew(LineEdit); parent_name->connect("text_changed", callable_mp(this, &ScriptCreateDialog::_parent_name_changed)); parent_name->set_h_size_flags(Control::SIZE_EXPAND_FILL); hb->add_child(parent_name); parent_search_button = memnew(Button); - parent_search_button->set_flat(true); parent_search_button->connect("pressed", callable_mp(this, &ScriptCreateDialog::_browse_class_in_tree)); hb->add_child(parent_search_button); parent_browse_button = memnew(Button); diff --git a/editor/script_create_dialog.h b/editor/script_create_dialog.h index a020be0478..7c2ef1e150 100644 --- a/editor/script_create_dialog.h +++ b/editor/script_create_dialog.h @@ -45,7 +45,6 @@ class CreateDialog; class ScriptCreateDialog : public ConfirmationDialog { GDCLASS(ScriptCreateDialog, ConfirmationDialog); - GridContainer *gc; LineEdit *class_name; Label *error_label; Label *path_error_label; @@ -127,7 +126,6 @@ class ScriptCreateDialog : public ConfirmationDialog { void _update_dialog(); protected: - void _theme_changed(); void _notification(int p_what); static void _bind_methods(); diff --git a/editor/settings_config_dialog.cpp b/editor/settings_config_dialog.cpp index c05a3c2f89..c2c99ed17f 100644 --- a/editor/settings_config_dialog.cpp +++ b/editor/settings_config_dialog.cpp @@ -285,7 +285,7 @@ void EditorSettingsDialog::_update_shortcuts() { event_strings.push_back(I->get()->as_text()); // Only check if the events have been the same so far - once one fails, we don't need to check any more. - if (same_as_defaults && !key_default_events[count]->shortcut_match(I->get())) { + if (same_as_defaults && !key_default_events[count]->is_match(I->get())) { same_as_defaults = false; } count++; diff --git a/editor/translations/ca.po b/editor/translations/ca.po index 26e9ac5a45..e9dc4400fc 100644 --- a/editor/translations/ca.po +++ b/editor/translations/ca.po @@ -15,12 +15,13 @@ # Carles Pastor Badosa <cpbadosa@gmail.com>, 2021. # Roberto Pérez <djleizar@gmail.com>, 2021. # Joel Garcia Cascalló <jocsencat@gmail.com>, 2021. +# DFC <damiafluixacanals28@gmail.com>, 2021. msgid "" msgstr "" "Project-Id-Version: Godot Engine editor\n" "POT-Creation-Date: \n" -"PO-Revision-Date: 2021-05-14 11:19+0000\n" -"Last-Translator: Joel Garcia Cascalló <jocsencat@gmail.com>\n" +"PO-Revision-Date: 2021-06-29 12:48+0000\n" +"Last-Translator: DFC <damiafluixacanals28@gmail.com>\n" "Language-Team: Catalan <https://hosted.weblate.org/projects/godot-engine/" "godot/ca/>\n" "Language: ca\n" @@ -28,7 +29,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n != 1;\n" -"X-Generator: Weblate 4.7-dev\n" +"X-Generator: Weblate 4.7.1-dev\n" #: core/math/expression.cpp modules/gdscript/gdscript_functions.cpp #: modules/visual_script/visual_script_builtin_funcs.cpp @@ -1129,7 +1130,7 @@ msgstr "Gràcies de la part de la Comunitat del Godot!" #: editor/editor_about.cpp editor/editor_node.cpp editor/project_manager.cpp msgid "Click to copy." -msgstr "" +msgstr "Fes click per a copiar." #: editor/editor_about.cpp msgid "Godot Engine contributors" @@ -2331,6 +2332,8 @@ msgid "" "An error occurred while trying to save the editor layout.\n" "Make sure the editor's user data path is writable." msgstr "" +"S'ha produit un error al desar el diseny de l'editor.\n" +"Assegura't de que el directori de dades d'usuari de l'editor és editable." #: editor/editor_node.cpp msgid "" @@ -2338,6 +2341,9 @@ msgid "" "To restore the Default layout to its base settings, use the Delete Layout " "option and delete the Default layout." msgstr "" +"S'ha anulat el diseny per defecte de l'editor.\n" +"Per a restaurar el Diseny per defecte a la seva configuració base, usa la " +"opció d'Esborrar el Diseny i esborra el Diseny per defecte." #: editor/editor_node.cpp msgid "Layout name not found!" @@ -2401,7 +2407,7 @@ msgstr "No s'ha definit cap escena per executar." #: editor/editor_node.cpp msgid "Save scene before running..." -msgstr "" +msgstr "Desar l'escena abans de executar-la..." #: editor/editor_node.cpp msgid "Could not start subprocess!" @@ -3022,7 +3028,7 @@ msgstr "Quant a" #: editor/editor_node.cpp msgid "Support Godot Development" -msgstr "" +msgstr "Contribueix a el Desenvolupament de Godot" #: editor/editor_node.cpp msgid "Play the project." @@ -3726,6 +3732,8 @@ msgstr "Estat: No s'ha pogut importar. Corregiu el fitxer i torneu a importar." msgid "" "Importing has been disabled for this file, so it can't be opened for editing." msgstr "" +"La importació s'ha desactivat per a aquest fitxer, per tant aquest no pot " +"ser obert per a editar." #: editor/filesystem_dock.cpp msgid "Cannot move/rename resources root." @@ -3772,6 +3780,12 @@ msgid "" "\n" "Do you wish to overwrite them?" msgstr "" +"Els fitxers o directoris següents entren en conflicte amb els elements de la " +"ubicació de destí '%s':\n" +"\n" +"%s\n" +"\n" +"Vols reemplaçar-los?" #: editor/filesystem_dock.cpp msgid "Renaming file:" @@ -4136,7 +4150,7 @@ msgstr "Carrega Valors predeterminats" #: editor/import_dock.cpp msgid "Keep File (No Import)" -msgstr "" +msgstr "Mantenir Fitxer (No Importar)" #: editor/import_dock.cpp msgid "%d Files" diff --git a/editor/translations/cs.po b/editor/translations/cs.po index 8f1e930115..2557308828 100644 --- a/editor/translations/cs.po +++ b/editor/translations/cs.po @@ -30,8 +30,8 @@ msgid "" msgstr "" "Project-Id-Version: Godot Engine editor\n" "POT-Creation-Date: \n" -"PO-Revision-Date: 2021-05-21 11:33+0000\n" -"Last-Translator: swifterik <blaha.j502@gmail.com>\n" +"PO-Revision-Date: 2021-06-25 02:57+0000\n" +"Last-Translator: Vojtěch Šamla <auzkok@seznam.cz>\n" "Language-Team: Czech <https://hosted.weblate.org/projects/godot-engine/godot/" "cs/>\n" "Language: cs\n" @@ -39,7 +39,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;\n" -"X-Generator: Weblate 4.7-dev\n" +"X-Generator: Weblate 4.7.1-dev\n" #: core/math/expression.cpp modules/gdscript/gdscript_functions.cpp #: modules/visual_script/visual_script_builtin_funcs.cpp @@ -5224,11 +5224,11 @@ msgstr "" "čtvercové oblasti [0.0, 1.0]." #: editor/plugins/baked_lightmap_editor_plugin.cpp -#, fuzzy msgid "" "Godot editor was built without ray tracing support, lightmaps can't be baked." msgstr "" -"Godot byl sestaven bez podpory ray tracingu, světelné mapy nelze zapéct." +"Editor Godot byl sestaven bez podpory ray tracingu, světelné mapy nelze " +"zapéct." #: editor/plugins/baked_lightmap_editor_plugin.cpp msgid "Bake Lightmaps" diff --git a/editor/translations/de.po b/editor/translations/de.po index 89ffa6e87c..fcf5522011 100644 --- a/editor/translations/de.po +++ b/editor/translations/de.po @@ -69,12 +69,14 @@ # El Captian <elcaptian@posteo.me>, 2021. # Ron Eric Hackländer <mail@roneric.net>, 2021. # Stephan Kerbl <stephankerbl@gmail.com>, 2021. +# Philipp Wabnitz <philipp.wabnitz@s2011.tu-chemnitz.de>, 2021. +# jmih03 <joerni@mail.de>, 2021. msgid "" msgstr "" "Project-Id-Version: Godot Engine editor\n" "POT-Creation-Date: \n" -"PO-Revision-Date: 2021-06-07 23:43+0000\n" -"Last-Translator: Linux User <no-ads@mail.de>\n" +"PO-Revision-Date: 2021-06-28 22:34+0000\n" +"Last-Translator: jmih03 <joerni@mail.de>\n" "Language-Team: German <https://hosted.weblate.org/projects/godot-engine/" "godot/de/>\n" "Language: de\n" @@ -82,7 +84,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n != 1;\n" -"X-Generator: Weblate 4.7-dev\n" +"X-Generator: Weblate 4.7.1-dev\n" #: core/math/expression.cpp modules/gdscript/gdscript_functions.cpp #: modules/visual_script/visual_script_builtin_funcs.cpp @@ -1189,7 +1191,7 @@ msgstr "Die Godot-Gemeinschaft bedankt sich!" #: editor/editor_about.cpp editor/editor_node.cpp editor/project_manager.cpp msgid "Click to copy." -msgstr "" +msgstr "Zum kopieren klicken." #: editor/editor_about.cpp msgid "Godot Engine contributors" @@ -7153,7 +7155,7 @@ msgstr "" #: editor/plugins/script_editor_plugin.cpp editor/script_editor_debugger.cpp msgid "Debugger" -msgstr "Testhilfsprogramm" +msgstr "Debugger" #: editor/plugins/script_editor_plugin.cpp msgid "Search Results" @@ -7416,6 +7418,7 @@ msgid "Play IK" msgstr "IK abspielen" #: editor/plugins/spatial_editor_plugin.cpp +#, fuzzy msgid "Orthogonal" msgstr "Orthogonal" @@ -7661,7 +7664,7 @@ msgid "" "To zoom further, change the camera's clipping planes (View -> Settings...)" msgstr "" "Um weiter zoomen zu können müssen die Kameraausschnittebenen geändert werden " -"(Anzeige -> Einstellungen… )" +"(Ansicht -> Einstellungen… )" #: editor/plugins/spatial_editor_plugin.cpp msgid "" @@ -10353,7 +10356,7 @@ msgstr "Ereignis hinzufügen" #: editor/project_settings_editor.cpp msgid "Button" -msgstr "Knopf" +msgstr "Button" #: editor/project_settings_editor.cpp msgid "Left Button." @@ -12330,6 +12333,8 @@ msgid "" "Either Debug Keystore, Debug User AND Debug Password settings must be " "configured OR none of them." msgstr "" +"Die drei Einstellungen Debug Keystore, Debug User und Debug Password müssen " +"entweder alle angegeben, oder alle nicht angegeben sein." #: platform/android/export/export.cpp msgid "Debug keystore not configured in the Editor Settings nor in the preset." @@ -12342,6 +12347,8 @@ msgid "" "Either Release Keystore, Release User AND Release Password settings must be " "configured OR none of them." msgstr "" +"Die drei Einstellungen Release Keystore, Release User und Release Password " +"müssen entweder alle angegeben, oder alle nicht angegeben sein." #: platform/android/export/export.cpp msgid "Release keystore incorrectly configured in the export preset." diff --git a/editor/translations/es.po b/editor/translations/es.po index 660e17420d..7d3288527c 100644 --- a/editor/translations/es.po +++ b/editor/translations/es.po @@ -64,12 +64,15 @@ # Juan camilo <jugarciago01@gmail.com>, 2021. # Manuel González <mgoopazo@gmail.com>, 2021. # softonicblip <blazeawardspace@gmail.com>, 2021. +# Ib Quezada <ib@ibquezada.com>, 2021. +# hiking <joaquinfc@protonmail.com>, 2021. +# pabloggomez <pgg2733@gmail.com>, 2021. msgid "" msgstr "" "Project-Id-Version: Godot Engine editor\n" "POT-Creation-Date: \n" -"PO-Revision-Date: 2021-06-03 22:23+0000\n" -"Last-Translator: softonicblip <blazeawardspace@gmail.com>\n" +"PO-Revision-Date: 2021-06-23 21:56+0000\n" +"Last-Translator: pabloggomez <pgg2733@gmail.com>\n" "Language-Team: Spanish <https://hosted.weblate.org/projects/godot-engine/" "godot/es/>\n" "Language: es\n" @@ -77,7 +80,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n != 1;\n" -"X-Generator: Weblate 4.7-dev\n" +"X-Generator: Weblate 4.7.1-dev\n" #: core/math/expression.cpp modules/gdscript/gdscript_functions.cpp #: modules/visual_script/visual_script_builtin_funcs.cpp @@ -1188,7 +1191,7 @@ msgstr "¡Muchas gracias de parte de la comunidad de Godot!" #: editor/editor_about.cpp editor/editor_node.cpp editor/project_manager.cpp msgid "Click to copy." -msgstr "" +msgstr "Clic para copiar." #: editor/editor_about.cpp msgid "Godot Engine contributors" @@ -4929,8 +4932,8 @@ msgstr "Eliminar el nodo o transición seleccionado/a." #: editor/plugins/animation_state_machine_editor.cpp msgid "Toggle autoplay this animation on start, restart or seek to zero." msgstr "" -"Act./Desact. reproducción automática de esta animación al comenzar, " -"reiniciar o hacer seek hasta el cero." +"Alternar reproducción automática de esta animación al comenzar, reiniciar o " +"hacer puesta a cero." #: editor/plugins/animation_state_machine_editor.cpp msgid "Set the end animation. This is useful for sub-transitions." @@ -12328,6 +12331,8 @@ msgid "" "Either Debug Keystore, Debug User AND Debug Password settings must be " "configured OR none of them." msgstr "" +"Deben configurarse los ajustes de Depuración de Claves, Depuración de " +"Usuarios Y Depuración de Contraseñas O ninguno de ellos." #: platform/android/export/export.cpp msgid "Debug keystore not configured in the Editor Settings nor in the preset." @@ -12339,6 +12344,8 @@ msgid "" "Either Release Keystore, Release User AND Release Password settings must be " "configured OR none of them." msgstr "" +"Deben configurarse los ajustes de Liberación del Almacén de Claves, " +"Liberación del Usuario Y Liberación de la Contraseña O ninguno de ellos." #: platform/android/export/export.cpp msgid "Release keystore incorrectly configured in the export preset." diff --git a/editor/translations/es_AR.po b/editor/translations/es_AR.po index 3c3174f6c8..4bac2d84e9 100644 --- a/editor/translations/es_AR.po +++ b/editor/translations/es_AR.po @@ -21,7 +21,7 @@ msgid "" msgstr "" "Project-Id-Version: Godot Engine editor\n" "POT-Creation-Date: \n" -"PO-Revision-Date: 2021-05-29 13:49+0000\n" +"PO-Revision-Date: 2021-06-20 13:35+0000\n" "Last-Translator: Lisandro Lorea <lisandrolorea@gmail.com>\n" "Language-Team: Spanish (Argentina) <https://hosted.weblate.org/projects/" "godot-engine/godot/es_AR/>\n" @@ -30,7 +30,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n != 1;\n" -"X-Generator: Weblate 4.7-dev\n" +"X-Generator: Weblate 4.7\n" #: core/math/expression.cpp modules/gdscript/gdscript_functions.cpp #: modules/visual_script/visual_script_builtin_funcs.cpp @@ -1138,7 +1138,7 @@ msgstr "Gracias de parte de la comunidad Godot!" #: editor/editor_about.cpp editor/editor_node.cpp editor/project_manager.cpp msgid "Click to copy." -msgstr "" +msgstr "Click para copiar." #: editor/editor_about.cpp msgid "Godot Engine contributors" @@ -12265,6 +12265,8 @@ msgid "" "Either Debug Keystore, Debug User AND Debug Password settings must be " "configured OR none of them." msgstr "" +"Deben estar configurados o bien Debug Keystore, Debug User Y Debug Password " +"o bien ninguno de ellos." #: platform/android/export/export.cpp msgid "Debug keystore not configured in the Editor Settings nor in the preset." @@ -12276,6 +12278,8 @@ msgid "" "Either Release Keystore, Release User AND Release Password settings must be " "configured OR none of them." msgstr "" +"Deben estar configurados o bien Release Keystore, Release User y Release " +"Passoword o bien ninguno de ellos." #: platform/android/export/export.cpp msgid "Release keystore incorrectly configured in the export preset." diff --git a/editor/translations/eu.po b/editor/translations/eu.po index e21c8ce5ba..0f8ef2de33 100644 --- a/editor/translations/eu.po +++ b/editor/translations/eu.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Godot Engine editor\n" -"PO-Revision-Date: 2021-06-14 12:34+0000\n" +"PO-Revision-Date: 2021-06-20 13:35+0000\n" "Last-Translator: Erik Zubiria <erik@ezsd.net>\n" "Language-Team: Basque <https://hosted.weblate.org/projects/godot-engine/" "godot/eu/>\n" @@ -16,7 +16,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8-bit\n" "Plural-Forms: nplurals=2; plural=n != 1;\n" -"X-Generator: Weblate 4.7-dev\n" +"X-Generator: Weblate 4.7\n" #: core/math/expression.cpp modules/gdscript/gdscript_functions.cpp #: modules/visual_script/visual_script_builtin_funcs.cpp @@ -259,93 +259,93 @@ msgstr "Interpolazio mota" #: editor/animation_track_editor.cpp msgid "Loop Wrap Mode (Interpolate end with beginning on loop)" -msgstr "" +msgstr "Loop Modu Bildua (bukaera interpolatu looparen hasierarekin)" #: editor/animation_track_editor.cpp msgid "Remove this track." -msgstr "" +msgstr "Pista hau ezabatu." #: editor/animation_track_editor.cpp msgid "Time (s): " -msgstr "" +msgstr "Denbora (s): " #: editor/animation_track_editor.cpp msgid "Toggle Track Enabled" -msgstr "" +msgstr "Pista Akt./Desakt." #: editor/animation_track_editor.cpp msgid "Continuous" -msgstr "" +msgstr "Etengabea" #: editor/animation_track_editor.cpp msgid "Discrete" -msgstr "" +msgstr "Diskretua" #: editor/animation_track_editor.cpp msgid "Trigger" -msgstr "" +msgstr "Kakoa" #: editor/animation_track_editor.cpp msgid "Capture" -msgstr "" +msgstr "Kaptura" #: editor/animation_track_editor.cpp msgid "Nearest" -msgstr "" +msgstr "Gertukoena" #: editor/animation_track_editor.cpp editor/plugins/curve_editor_plugin.cpp #: editor/property_editor.cpp msgid "Linear" -msgstr "" +msgstr "Lineal" #: editor/animation_track_editor.cpp msgid "Cubic" -msgstr "" +msgstr "Kubiko" #: editor/animation_track_editor.cpp msgid "Clamp Loop Interp" -msgstr "" +msgstr "Loop Ebakitzailearen Interp" #: editor/animation_track_editor.cpp msgid "Wrap Loop Interp" -msgstr "" +msgstr "Loop Inguratzailearen Interp" #: editor/animation_track_editor.cpp #: editor/plugins/canvas_item_editor_plugin.cpp msgid "Insert Key" -msgstr "" +msgstr "Sartu Giltza" #: editor/animation_track_editor.cpp msgid "Duplicate Key(s)" -msgstr "" +msgstr "Bikoiztu Giltza(k)" #: editor/animation_track_editor.cpp msgid "Delete Key(s)" -msgstr "" +msgstr "Ezabatu Giltza(k)" #: editor/animation_track_editor.cpp msgid "Change Animation Update Mode" -msgstr "" +msgstr "Animazioaren Eguneraketa Modua Aldatu" #: editor/animation_track_editor.cpp msgid "Change Animation Interpolation Mode" -msgstr "" +msgstr "Animazioaren Interpolazio Modua Aldatu" #: editor/animation_track_editor.cpp msgid "Change Animation Loop Mode" -msgstr "" +msgstr "Animazioaren Loop Modua Aldatu" #: editor/animation_track_editor.cpp msgid "Remove Anim Track" -msgstr "" +msgstr "Ezabatu Animazio Pista" #: editor/animation_track_editor.cpp msgid "Create NEW track for %s and insert key?" -msgstr "" +msgstr "%s-rentzat pista berria sortu eta giltza sartu?" #: editor/animation_track_editor.cpp msgid "Create %d NEW tracks and insert keys?" -msgstr "" +msgstr "%d pista berri sortu eta giltzak sartu?" #: editor/animation_track_editor.cpp editor/create_dialog.cpp #: editor/editor_audio_buses.cpp editor/editor_feature_profile.cpp @@ -357,39 +357,41 @@ msgstr "" #: editor/script_create_dialog.cpp #: modules/visual_script/visual_script_editor.cpp msgid "Create" -msgstr "" +msgstr "Sortu" #: editor/animation_track_editor.cpp msgid "Anim Insert" -msgstr "" +msgstr "Animazioa Sartu" #: editor/animation_track_editor.cpp msgid "AnimationPlayer can't animate itself, only other players." -msgstr "" +msgstr "AnimationPlayer bat ezin da norbera animatu, soilik beste playerrak." #: editor/animation_track_editor.cpp msgid "Anim Create & Insert" -msgstr "" +msgstr "Animazioa Sortu eta Txertatu" #: editor/animation_track_editor.cpp msgid "Anim Insert Track & Key" -msgstr "" +msgstr "Pista eta Animazio Giltza Sartu" #: editor/animation_track_editor.cpp msgid "Anim Insert Key" -msgstr "" +msgstr "Animazio Giltza Sartu" #: editor/animation_track_editor.cpp msgid "Change Animation Step" -msgstr "" +msgstr "Animazioaren Urratsa Aldatu" #: editor/animation_track_editor.cpp msgid "Rearrange Tracks" -msgstr "" +msgstr "Pistak Berrantolatu" #: editor/animation_track_editor.cpp msgid "Transform tracks only apply to Spatial-based nodes." msgstr "" +"Transformazio pistak Spatial-en oinarritutako nodoetan bakarrik aplikatzen " +"dira." #: editor/animation_track_editor.cpp msgid "" @@ -398,38 +400,42 @@ msgid "" "-AudioStreamPlayer2D\n" "-AudioStreamPlayer3D" msgstr "" +"Audio pistek era hontako nodoak bakarrik apunta ditzakete:\n" +"-AudioStreamPlayer\n" +"-AudioStreamPlayer2D\n" +"-AudioStreamPlayer3D" #: editor/animation_track_editor.cpp msgid "Animation tracks can only point to AnimationPlayer nodes." -msgstr "" +msgstr "Animazio pistek AnimationPlayer nodoak bakarrik apunta ditzakete." #: editor/animation_track_editor.cpp msgid "An animation player can't animate itself, only other players." -msgstr "" +msgstr "Animazio irakurgailua ezin da norbera animatu, bakarrik beste batzuk." #: editor/animation_track_editor.cpp msgid "Not possible to add a new track without a root" -msgstr "" +msgstr "Ez da posiblea pista berri bat gehitzea sustrairik gabe" #: editor/animation_track_editor.cpp msgid "Invalid track for Bezier (no suitable sub-properties)" -msgstr "" +msgstr "Bezier-entzat pista baliogabea (ez dago azpipropietate egokirik)" #: editor/animation_track_editor.cpp msgid "Add Bezier Track" -msgstr "" +msgstr "Gehitu Bezier Pista" #: editor/animation_track_editor.cpp msgid "Track path is invalid, so can't add a key." -msgstr "" +msgstr "Pistaren bidea baliogabea da, beraz ezin da giltzarik gehitu." #: editor/animation_track_editor.cpp msgid "Track is not of type Spatial, can't insert key" -msgstr "" +msgstr "Pista ez da Spatial erakoa, ezin da giltza txertatu" #: editor/animation_track_editor.cpp msgid "Add Transform Track Key" -msgstr "" +msgstr "Gehitu Pistaren Transformazio Giltza" #: editor/animation_track_editor.cpp msgid "Add Track Key" diff --git a/editor/translations/fi.po b/editor/translations/fi.po index 4b7aad362e..9b0cb63c86 100644 --- a/editor/translations/fi.po +++ b/editor/translations/fi.po @@ -16,7 +16,7 @@ msgid "" msgstr "" "Project-Id-Version: Godot Engine editor\n" "POT-Creation-Date: \n" -"PO-Revision-Date: 2021-05-19 20:16+0000\n" +"PO-Revision-Date: 2021-06-20 13:35+0000\n" "Last-Translator: Tapani Niemi <tapani.niemi@kapsi.fi>\n" "Language-Team: Finnish <https://hosted.weblate.org/projects/godot-engine/" "godot/fi/>\n" @@ -25,7 +25,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n != 1;\n" -"X-Generator: Weblate 4.7-dev\n" +"X-Generator: Weblate 4.7\n" #: core/math/expression.cpp modules/gdscript/gdscript_functions.cpp #: modules/visual_script/visual_script_builtin_funcs.cpp @@ -1120,7 +1120,7 @@ msgstr "Kiitos Godot-yhteisöltä!" #: editor/editor_about.cpp editor/editor_node.cpp editor/project_manager.cpp msgid "Click to copy." -msgstr "" +msgstr "Napsauta kopioidaksesi." #: editor/editor_about.cpp msgid "Godot Engine contributors" @@ -12204,6 +12204,8 @@ msgid "" "Either Debug Keystore, Debug User AND Debug Password settings must be " "configured OR none of them." msgstr "" +"Joko Debug Keystore, Debug User JA Debug Password asetukset on kaikki " +"konfiguroitava TAI ei mitään niistä." #: platform/android/export/export.cpp msgid "Debug keystore not configured in the Editor Settings nor in the preset." @@ -12215,6 +12217,8 @@ msgid "" "Either Release Keystore, Release User AND Release Password settings must be " "configured OR none of them." msgstr "" +"Joko Release Keystore, Release User JA Release Password asetukset on kaikki " +"konfiguroitava TAI ei mitään niistä." #: platform/android/export/export.cpp msgid "Release keystore incorrectly configured in the export preset." diff --git a/editor/translations/fr.po b/editor/translations/fr.po index 577c44aff0..129ab4f687 100644 --- a/editor/translations/fr.po +++ b/editor/translations/fr.po @@ -73,7 +73,7 @@ # Kevin Bouancheau <kevin.bouancheau@gmail.com>, 2020. # LaurentOngaro <laurent@gameamea.com>, 2020. # Julien Humbert <julroy67@gmail.com>, 2020. -# Nathan <bonnemainsnathan@gmail.com>, 2020. +# Nathan <bonnemainsnathan@gmail.com>, 2020, 2021. # Léo Vincent <l009.vincent@gmail.com>, 2020. # Joseph Boudou <joseph.boudou@matabio.net>, 2020. # Vincent Foulon <vincent.foulon80@gmail.com>, 2020. @@ -84,8 +84,8 @@ msgid "" msgstr "" "Project-Id-Version: Godot Engine editor\n" "POT-Creation-Date: \n" -"PO-Revision-Date: 2021-04-30 23:03+0000\n" -"Last-Translator: Julien Vanelian <julienvanelian@hotmail.com>\n" +"PO-Revision-Date: 2021-06-20 13:35+0000\n" +"Last-Translator: Nathan <bonnemainsnathan@gmail.com>\n" "Language-Team: French <https://hosted.weblate.org/projects/godot-engine/" "godot/fr/>\n" "Language: fr\n" @@ -93,7 +93,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n > 1;\n" -"X-Generator: Weblate 4.7-dev\n" +"X-Generator: Weblate 4.7\n" #: core/math/expression.cpp modules/gdscript/gdscript_functions.cpp #: modules/visual_script/visual_script_builtin_funcs.cpp @@ -1203,7 +1203,7 @@ msgstr "La communauté Godot vous dit merci !" #: editor/editor_about.cpp editor/editor_node.cpp editor/project_manager.cpp msgid "Click to copy." -msgstr "" +msgstr "Cliquez pour copier." #: editor/editor_about.cpp msgid "Godot Engine contributors" @@ -12370,6 +12370,8 @@ msgid "" "Either Debug Keystore, Debug User AND Debug Password settings must be " "configured OR none of them." msgstr "" +"Il faut configurer soit les paramètres Debug Keystore, Debug User ET Debug " +"Password, soit aucun d'entre eux." #: platform/android/export/export.cpp msgid "Debug keystore not configured in the Editor Settings nor in the preset." @@ -12382,6 +12384,8 @@ msgid "" "Either Release Keystore, Release User AND Release Password settings must be " "configured OR none of them." msgstr "" +"Il faut configurer soit les paramètres Release Keystore, Release User ET " +"Release Password, soit aucun d'entre eux." #: platform/android/export/export.cpp msgid "Release keystore incorrectly configured in the export preset." diff --git a/editor/translations/ko.po b/editor/translations/ko.po index f2f3ac1562..9224ef5e65 100644 --- a/editor/translations/ko.po +++ b/editor/translations/ko.po @@ -27,8 +27,8 @@ msgid "" msgstr "" "Project-Id-Version: Godot Engine editor\n" "POT-Creation-Date: \n" -"PO-Revision-Date: 2021-06-11 14:49+0000\n" -"Last-Translator: Postive_ Cloud <postive12@gmail.com>\n" +"PO-Revision-Date: 2021-06-20 13:35+0000\n" +"Last-Translator: Myeongjin Lee <aranet100@gmail.com>\n" "Language-Team: Korean <https://hosted.weblate.org/projects/godot-engine/" "godot/ko/>\n" "Language: ko\n" @@ -36,7 +36,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=1; plural=0;\n" -"X-Generator: Weblate 4.7-dev\n" +"X-Generator: Weblate 4.7\n" #: core/math/expression.cpp modules/gdscript/gdscript_functions.cpp #: modules/visual_script/visual_script_builtin_funcs.cpp @@ -1134,7 +1134,7 @@ msgstr "Godot 커뮤니티에서 감사드립니다!" #: editor/editor_about.cpp editor/editor_node.cpp editor/project_manager.cpp msgid "Click to copy." -msgstr "" +msgstr "클릭하여 복사합니다." #: editor/editor_about.cpp msgid "Godot Engine contributors" @@ -12124,6 +12124,8 @@ msgid "" "Either Debug Keystore, Debug User AND Debug Password settings must be " "configured OR none of them." msgstr "" +"Debug Keystore, Debug User 및 Debug Password 설정을 구성하거나 그 중 어느 것" +"도 없어야 합니다." #: platform/android/export/export.cpp msgid "Debug keystore not configured in the Editor Settings nor in the preset." @@ -12134,6 +12136,8 @@ msgid "" "Either Release Keystore, Release User AND Release Password settings must be " "configured OR none of them." msgstr "" +"Release Keystore, Release User 및 Release Password 설정을 구성하거나 그 중 어" +"느 것도 없어야 합니다." #: platform/android/export/export.cpp msgid "Release keystore incorrectly configured in the export preset." diff --git a/editor/translations/pl.po b/editor/translations/pl.po index 9ae69c3d75..83d36da5bb 100644 --- a/editor/translations/pl.po +++ b/editor/translations/pl.po @@ -52,7 +52,7 @@ msgid "" msgstr "" "Project-Id-Version: Godot Engine editor\n" "POT-Creation-Date: \n" -"PO-Revision-Date: 2021-05-19 20:16+0000\n" +"PO-Revision-Date: 2021-06-20 13:35+0000\n" "Last-Translator: Tomek <kobewi4e@gmail.com>\n" "Language-Team: Polish <https://hosted.weblate.org/projects/godot-engine/" "godot/pl/>\n" @@ -62,7 +62,7 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=3; plural=n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 " "|| n%100>=20) ? 1 : 2;\n" -"X-Generator: Weblate 4.7-dev\n" +"X-Generator: Weblate 4.7\n" #: core/math/expression.cpp modules/gdscript/gdscript_functions.cpp #: modules/visual_script/visual_script_builtin_funcs.cpp @@ -86,7 +86,7 @@ msgstr "Niewłaściwe dane %i (nie przekazane) w wyrażeniu" #: core/math/expression.cpp msgid "self can't be used because instance is null (not passed)" msgstr "" -"self nie może być użyte, ponieważ instancja jest nullem (nie przekazano)" +"self nie może zostać użyte, ponieważ instancja jest nullem (nie przekazana)" #: core/math/expression.cpp msgid "Invalid operands to operator %s, %s and %s." @@ -1159,7 +1159,7 @@ msgstr "Podziękowania od społeczności Godota!" #: editor/editor_about.cpp editor/editor_node.cpp editor/project_manager.cpp msgid "Click to copy." -msgstr "" +msgstr "Kliknij, by skopiować." #: editor/editor_about.cpp msgid "Godot Engine contributors" @@ -12236,6 +12236,8 @@ msgid "" "Either Debug Keystore, Debug User AND Debug Password settings must be " "configured OR none of them." msgstr "" +"Albo ustawienia Debug Keystore, Debug User ORAZ Debug Password muszą być " +"skonfigurowane, ALBO żadne z nich." #: platform/android/export/export.cpp msgid "Debug keystore not configured in the Editor Settings nor in the preset." @@ -12248,6 +12250,8 @@ msgid "" "Either Release Keystore, Release User AND Release Password settings must be " "configured OR none of them." msgstr "" +"Albo ustawienia Release Keystore, Release User ORAZ Release Password muszą " +"być skonfigurowane, ALBO żadne z nich." #: platform/android/export/export.cpp msgid "Release keystore incorrectly configured in the export preset." diff --git a/editor/translations/pt_BR.po b/editor/translations/pt_BR.po index 1fae91fc0d..49a7b43571 100644 --- a/editor/translations/pt_BR.po +++ b/editor/translations/pt_BR.po @@ -117,12 +117,13 @@ # Arthur Phillip D. Silva <artphil.dev@gmail.com>, 2021. # Gustavo HM 102 <gustavohm102@gmail.com>, 2021. # Douglas Leão <djlsplays@gmail.com>, 2021. +# PauloFRs <paulofr1@hotmail.com>, 2021. msgid "" msgstr "" "Project-Id-Version: Godot Engine editor\n" "POT-Creation-Date: 2016-05-30\n" -"PO-Revision-Date: 2021-06-12 01:23+0000\n" -"Last-Translator: Douglas Leão <djlsplays@gmail.com>\n" +"PO-Revision-Date: 2021-06-29 08:04+0000\n" +"Last-Translator: PauloFRs <paulofr1@hotmail.com>\n" "Language-Team: Portuguese (Brazil) <https://hosted.weblate.org/projects/" "godot-engine/godot/pt_BR/>\n" "Language: pt_BR\n" @@ -130,7 +131,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n > 1;\n" -"X-Generator: Weblate 4.7-dev\n" +"X-Generator: Weblate 4.7.1-dev\n" #: core/math/expression.cpp modules/gdscript/gdscript_functions.cpp #: modules/visual_script/visual_script_builtin_funcs.cpp @@ -153,7 +154,7 @@ msgstr "Entrada inválida %i (não passada) na expressão" #: core/math/expression.cpp msgid "self can't be used because instance is null (not passed)" -msgstr "self não pode ser usado porque a instância é nula (não passada)" +msgstr "self não pode ser usado porque sua instância é null (não passado)" #: core/math/expression.cpp msgid "Invalid operands to operator %s, %s and %s." @@ -1230,7 +1231,7 @@ msgstr "Agradecimentos da comunidade Godot!" #: editor/editor_about.cpp editor/editor_node.cpp editor/project_manager.cpp msgid "Click to copy." -msgstr "" +msgstr "Clique para copiar." #: editor/editor_about.cpp msgid "Godot Engine contributors" @@ -1911,7 +1912,7 @@ msgstr "Gerenciar perfis de recurso do editor" #: editor/editor_file_dialog.cpp scene/gui/file_dialog.cpp msgid "Select Current Folder" -msgstr "Selecione a Pasta Atual" +msgstr "Selecionar a Pasta Atual" #: editor/editor_file_dialog.cpp scene/gui/file_dialog.cpp msgid "File Exists, Overwrite?" @@ -12328,6 +12329,8 @@ msgid "" "Either Debug Keystore, Debug User AND Debug Password settings must be " "configured OR none of them." msgstr "" +"As configurações Debug Keystore, Debug User E Debug Password devem ser " +"configuradas OU nenhuma delas." #: platform/android/export/export.cpp msgid "Debug keystore not configured in the Editor Settings nor in the preset." @@ -12340,6 +12343,8 @@ msgid "" "Either Release Keystore, Release User AND Release Password settings must be " "configured OR none of them." msgstr "" +"As configurações de Release Keystore, Release User AND Release Password " +"devem ser definidas OU nenhuma delas." #: platform/android/export/export.cpp msgid "Release keystore incorrectly configured in the export preset." diff --git a/editor/translations/ru.po b/editor/translations/ru.po index fe4b510539..0da9285077 100644 --- a/editor/translations/ru.po +++ b/editor/translations/ru.po @@ -95,12 +95,13 @@ # nec-trou <darya.bilyalova@gmail.com>, 2021. # IindinAndEdresia <kapitan_pol@inbox.ru>, 2021. # Bualma Show <appleaidar6@gmail.com>, 2021. +# enderlorde <madel.laboratories@gmail.com>, 2021. msgid "" msgstr "" "Project-Id-Version: Godot Engine editor\n" "POT-Creation-Date: \n" -"PO-Revision-Date: 2021-06-07 23:43+0000\n" -"Last-Translator: Bualma Show <appleaidar6@gmail.com>\n" +"PO-Revision-Date: 2021-06-27 07:10+0000\n" +"Last-Translator: Danil Alexeev <danil@alexeev.xyz>\n" "Language-Team: Russian <https://hosted.weblate.org/projects/godot-engine/" "godot/ru/>\n" "Language: ru\n" @@ -109,7 +110,7 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" "%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n" -"X-Generator: Weblate 4.7-dev\n" +"X-Generator: Weblate 4.7.1-dev\n" #: core/math/expression.cpp modules/gdscript/gdscript_functions.cpp #: modules/visual_script/visual_script_builtin_funcs.cpp @@ -1207,7 +1208,7 @@ msgstr "Спасибо от сообщества Godot!" #: editor/editor_about.cpp editor/editor_node.cpp editor/project_manager.cpp msgid "Click to copy." -msgstr "" +msgstr "Нажмите, чтобы скопировать." #: editor/editor_about.cpp msgid "Godot Engine contributors" @@ -3154,7 +3155,7 @@ msgstr "Инспектор" #: editor/editor_node.cpp msgid "Expand Bottom Panel" -msgstr "Расширить боковую панель" +msgstr "Развернуть нижнюю панель" #: editor/editor_node.cpp msgid "Output" @@ -5813,7 +5814,7 @@ msgstr "Кадрировать выбранное" #: editor/plugins/canvas_item_editor_plugin.cpp msgid "Preview Canvas Scale" -msgstr "Предпросмотр Canvas Scale" +msgstr "Предпросмотр масштаба холста" #: editor/plugins/canvas_item_editor_plugin.cpp msgid "Translation mask for inserting keys." @@ -8437,7 +8438,7 @@ msgstr "Приоритет" #: editor/plugins/tile_set_editor_plugin.cpp msgid "Z Index" -msgstr "Положение по оси Z" +msgstr "Z-индекс" #: editor/plugins/tile_set_editor_plugin.cpp msgid "Region Mode" @@ -12287,6 +12288,8 @@ msgid "" "Either Debug Keystore, Debug User AND Debug Password settings must be " "configured OR none of them." msgstr "" +"ЛИБО должны быть заданы настройки Debug Keystore, Debug User И Debug " +"Password, ЛИБО ни одна из них." #: platform/android/export/export.cpp msgid "Debug keystore not configured in the Editor Settings nor in the preset." @@ -12299,6 +12302,8 @@ msgid "" "Either Release Keystore, Release User AND Release Password settings must be " "configured OR none of them." msgstr "" +"ЛИБО должны быть заданы настройки Release Keystore, Release User И Release " +"Password, ЛИБО ни одна из них." #: platform/android/export/export.cpp msgid "Release keystore incorrectly configured in the export preset." diff --git a/editor/translations/uk.po b/editor/translations/uk.po index 67f369bb15..5f0fe3d721 100644 --- a/editor/translations/uk.po +++ b/editor/translations/uk.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: Ukrainian (Godot Engine)\n" "POT-Creation-Date: \n" -"PO-Revision-Date: 2021-05-18 14:51+0000\n" +"PO-Revision-Date: 2021-06-20 13:35+0000\n" "Last-Translator: Yuri Chornoivan <yurchor@ukr.net>\n" "Language-Team: Ukrainian <https://hosted.weblate.org/projects/godot-engine/" "godot/uk/>\n" @@ -30,7 +30,7 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" "%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n" -"X-Generator: Weblate 4.7-dev\n" +"X-Generator: Weblate 4.7\n" #: core/math/expression.cpp modules/gdscript/gdscript_functions.cpp #: modules/visual_script/visual_script_builtin_funcs.cpp @@ -1137,7 +1137,7 @@ msgstr "Спасибі від спільноти Godot!" #: editor/editor_about.cpp editor/editor_node.cpp editor/project_manager.cpp msgid "Click to copy." -msgstr "" +msgstr "Клацніть, щоб скопіювати." #: editor/editor_about.cpp msgid "Godot Engine contributors" @@ -12244,6 +12244,8 @@ msgid "" "Either Debug Keystore, Debug User AND Debug Password settings must be " "configured OR none of them." msgstr "" +"Має бути налаштовано діагностику сховища ключів, діагностику користувача АБО " +"діагностику пароля АБО не налаштовано діагностику жодного з цих компонентів." #: platform/android/export/export.cpp msgid "Debug keystore not configured in the Editor Settings nor in the preset." @@ -12256,6 +12258,8 @@ msgid "" "Either Release Keystore, Release User AND Release Password settings must be " "configured OR none of them." msgstr "" +"Має бути налаштовано параметри сховища ключів випуску, користувача випуску і " +"пароля випуску або не налаштовано жоден з цих параметрів." #: platform/android/export/export.cpp msgid "Release keystore incorrectly configured in the export preset." diff --git a/editor/translations/zh_CN.po b/editor/translations/zh_CN.po index 53259bcc6f..6994841e78 100644 --- a/editor/translations/zh_CN.po +++ b/editor/translations/zh_CN.po @@ -83,7 +83,7 @@ msgid "" msgstr "" "Project-Id-Version: Chinese (Simplified) (Godot Engine)\n" "POT-Creation-Date: 2018-01-20 12:15+0200\n" -"PO-Revision-Date: 2021-05-29 13:49+0000\n" +"PO-Revision-Date: 2021-06-20 13:35+0000\n" "Last-Translator: Haoyu Qiu <timothyqiu32@gmail.com>\n" "Language-Team: Chinese (Simplified) <https://hosted.weblate.org/projects/" "godot-engine/godot/zh_Hans/>\n" @@ -92,7 +92,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=1; plural=0;\n" -"X-Generator: Weblate 4.7-dev\n" +"X-Generator: Weblate 4.7\n" #: core/math/expression.cpp modules/gdscript/gdscript_functions.cpp #: modules/visual_script/visual_script_builtin_funcs.cpp @@ -1179,7 +1179,7 @@ msgstr "Godot 社区感谢你!" #: editor/editor_about.cpp editor/editor_node.cpp editor/project_manager.cpp msgid "Click to copy." -msgstr "" +msgstr "点击复制。" #: editor/editor_about.cpp msgid "Godot Engine contributors" @@ -12043,7 +12043,7 @@ msgstr "未在项目中安装 Android 构建模板。从项目菜单安装它。 msgid "" "Either Debug Keystore, Debug User AND Debug Password settings must be " "configured OR none of them." -msgstr "" +msgstr "Debug Keystore、Debug User、Debug Password 必须全部填写或者全部留空。" #: platform/android/export/export.cpp msgid "Debug keystore not configured in the Editor Settings nor in the preset." @@ -12054,6 +12054,7 @@ msgid "" "Either Release Keystore, Release User AND Release Password settings must be " "configured OR none of them." msgstr "" +"Release Keystore、Release User、Release Password 必须全部填写或者全部留空。" #: platform/android/export/export.cpp msgid "Release keystore incorrectly configured in the export preset." diff --git a/main/main.cpp b/main/main.cpp index 667aebebae..1ab36701ff 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -34,6 +34,7 @@ #include "core/core_string_names.h" #include "core/crypto/crypto.h" #include "core/debugger/engine_debugger.h" +#include "core/extension/extension_api_dump.h" #include "core/input/input.h" #include "core/input/input_map.h" #include "core/io/dir_access.h" @@ -150,9 +151,9 @@ static bool auto_build_solutions = false; static DisplayServer::WindowMode window_mode = DisplayServer::WINDOW_MODE_WINDOWED; static DisplayServer::ScreenOrientation window_orientation = DisplayServer::SCREEN_LANDSCAPE; +static DisplayServer::VSyncMode window_vsync_mode = DisplayServer::VSYNC_ENABLED; static uint32_t window_flags = 0; static Size2i window_size = Size2i(1024, 600); -static bool window_vsync_via_compositor = false; static int init_screen = -1; static bool init_fullscreen = false; @@ -174,7 +175,9 @@ static int frame_delay = 0; static bool disable_render_loop = false; static int fixed_fps = -1; static bool print_fps = false; - +#ifdef TOOLS_ENABLED +static bool dump_extension_api = false; +#endif bool profile_gpu = false; /* Helper methods */ @@ -335,8 +338,6 @@ void Main::print_help(const char *p_binary) { OS::get_singleton()->print(" --position <X>,<Y> Request window position.\n"); OS::get_singleton()->print(" --low-dpi Force low-DPI mode (macOS and Windows only).\n"); OS::get_singleton()->print(" --no-window Disable window creation (Windows only). Useful together with --script.\n"); - OS::get_singleton()->print(" --enable-vsync-via-compositor When vsync is enabled, vsync via the OS' window compositor (Windows only).\n"); - OS::get_singleton()->print(" --disable-vsync-via-compositor Disable vsync via the OS' window compositor (Windows only).\n"); OS::get_singleton()->print(" --single-window Use a single window (no separate subwindows).\n"); OS::get_singleton()->print(" --tablet-driver Pen tablet input driver.\n"); OS::get_singleton()->print("\n"); @@ -406,6 +407,8 @@ Error Main::test_setup() { translation_server = memnew(TranslationServer); + register_core_extensions(); + // From `Main::setup2()`. preregister_module_types(); preregister_server_types(); @@ -594,11 +597,9 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph Vector<String> breakpoints; bool use_custom_res = true; bool force_res = false; - bool saw_vsync_via_compositor_override = false; #ifdef TOOLS_ENABLED bool found_project = false; #endif - bool use_vsync = false; packed_data = PackedData::get_singleton(); if (!packed_data) { @@ -820,12 +821,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph } else if (I->get() == "--no-window") { // disable window creation (Windows only) OS::get_singleton()->set_no_window_mode(true); - } else if (I->get() == "--enable-vsync-via-compositor") { - window_vsync_via_compositor = true; - saw_vsync_via_compositor_override = true; - } else if (I->get() == "--disable-vsync-via-compositor") { - window_vsync_via_compositor = false; - saw_vsync_via_compositor_override = true; #endif } else if (I->get() == "--profiling") { // enable profiling @@ -887,7 +882,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph auto_build_solutions = true; editor = true; cmdline_tool = true; -#ifdef DEBUG_METHODS_ENABLED + } else if (I->get() == "--gdnative-generate-json-api" || I->get() == "--gdnative-generate-json-builtin-api") { // Register as an editor instance to use low-end fallback if relevant. editor = true; @@ -895,7 +890,13 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph // We still pass it to the main arguments since the argument handling itself is not done in this function main_args.push_back(I->get()); -#endif + } else if (I->get() == "--dump-extension-api") { + // Register as an editor instance to use low-end fallback if relevant. + editor = true; + cmdline_tool = true; + dump_extension_api = true; + print_line("dump extension?"); + main_args.push_back(I->get()); } else if (I->get() == "--export" || I->get() == "--export-debug" || I->get() == "--export-pack") { // Export project // Actually handling is done in start(). @@ -1198,6 +1199,8 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph OS::get_singleton()->set_cmdline(execpath, main_args); + register_core_extensions(); //before display + GLOBAL_DEF("rendering/driver/driver_name", "Vulkan"); ProjectSettings::get_singleton()->set_custom_property_info("rendering/driver/driver_name", PropertyInfo(Variant::STRING, @@ -1274,19 +1277,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph OS::get_singleton()->_allow_hidpi = GLOBAL_DEF("display/window/dpi/allow_hidpi", false); } - use_vsync = GLOBAL_DEF_RST("display/window/vsync/use_vsync", true); - OS::get_singleton()->_use_vsync = use_vsync; - - if (!saw_vsync_via_compositor_override) { - // If one of the command line options to enable/disable vsync via the - // window compositor ("--enable-vsync-via-compositor" or - // "--disable-vsync-via-compositor") was present then it overrides the - // project setting. - window_vsync_via_compositor = GLOBAL_DEF("display/window/vsync/vsync_via_compositor", false); - } - - OS::get_singleton()->_vsync_via_compositor = window_vsync_via_compositor; - /* todo restore OS::get_singleton()->_allow_layered = GLOBAL_DEF("display/window/per_pixel_transparency/allowed", false); video_mode.layered = GLOBAL_DEF("display/window/per_pixel_transparency/enabled", false); @@ -1344,7 +1334,9 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph { window_orientation = DisplayServer::ScreenOrientation(int(GLOBAL_DEF_BASIC("display/window/handheld/orientation", DisplayServer::ScreenOrientation::SCREEN_LANDSCAPE))); } - + { + window_vsync_mode = DisplayServer::VSyncMode(int(GLOBAL_DEF("display/window/vsync/vsync_mode", DisplayServer::VSyncMode::VSYNC_ENABLED))); + } Engine::get_singleton()->set_iterations_per_second(GLOBAL_DEF_BASIC("physics/common/physics_fps", 60)); ProjectSettings::get_singleton()->set_custom_property_info("physics/common/physics_fps", PropertyInfo(Variant::INT, "physics/common/physics_fps", @@ -1537,14 +1529,14 @@ Error Main::setup2(Thread::ID p_main_tid_override) { String rendering_driver; // temp broken Error err; - display_server = DisplayServer::create(display_driver_idx, rendering_driver, window_mode, window_flags, window_size, err); + display_server = DisplayServer::create(display_driver_idx, rendering_driver, window_mode, window_vsync_mode, window_flags, window_size, err); if (err != OK || display_server == nullptr) { //ok i guess we can't use this display server, try other ones for (int i = 0; i < DisplayServer::get_create_function_count(); i++) { if (i == display_driver_idx) { continue; //don't try the same twice } - display_server = DisplayServer::create(i, rendering_driver, window_mode, window_flags, window_size, err); + display_server = DisplayServer::create(i, rendering_driver, window_mode, window_vsync_mode, window_flags, window_size, err); if (err == OK && display_server != nullptr) { break; } @@ -1669,7 +1661,7 @@ Error Main::setup2(Thread::ID p_main_tid_override) { boot_logo_path = boot_logo_path.strip_edges(); if (boot_logo_path != String()) { - boot_logo.instance(); + boot_logo.instantiate(); Error load_err = ImageLoader::load_image(boot_logo_path, boot_logo); if (load_err) { ERR_PRINT("Non-existing or invalid boot splash at '" + boot_logo_path + "'. Loading default splash."); @@ -2004,6 +1996,11 @@ bool Main::start() { return false; } + + if (dump_extension_api) { + NativeExtensionAPIDump::generate_extension_json_file("extension_api.json"); + return false; + } #endif if (script == "" && game_path == "" && String(GLOBAL_GET("application/run/main_scene")) != "") { @@ -2037,9 +2034,9 @@ bool Main::start() { return false; } - if (script_res->can_instance()) { + if (script_res->can_instantiate()) { StringName instance_type = script_res->get_instance_base_type(); - Object *obj = ClassDB::instance(instance_type); + Object *obj = ClassDB::instantiate(instance_type); MainLoop *script_loop = Object::cast_to<MainLoop>(obj); if (!script_loop) { if (obj) { @@ -2060,7 +2057,7 @@ bool Main::start() { String script_path = ScriptServer::get_global_class_path(main_loop_type); Ref<Script> script_res = ResourceLoader::load(script_path); StringName script_base = ScriptServer::get_global_class_native_base(main_loop_type); - Object *obj = ClassDB::instance(script_base); + Object *obj = ClassDB::instantiate(script_base); MainLoop *script_loop = Object::cast_to<MainLoop>(obj); if (!script_loop) { if (obj) { @@ -2083,7 +2080,7 @@ bool Main::start() { DisplayServer::get_singleton()->alert("Error: MainLoop type doesn't exist: " + main_loop_type); return false; } else { - Object *ml = ClassDB::instance(main_loop_type); + Object *ml = ClassDB::instantiate(main_loop_type); ERR_FAIL_COND_V_MSG(!ml, false, "Can't instance MainLoop type."); main_loop = Object::cast_to<MainLoop>(ml); @@ -2140,14 +2137,14 @@ bool Main::start() { Node *n = nullptr; if (res->is_class("PackedScene")) { Ref<PackedScene> ps = res; - n = ps->instance(); + n = ps->instantiate(); } else if (res->is_class("Script")) { Ref<Script> script_res = res; StringName ibt = script_res->get_instance_base_type(); bool valid_type = ClassDB::is_parent_class(ibt, "Node"); ERR_CONTINUE_MSG(!valid_type, "Script does not inherit a Node: " + info.path); - Object *obj = ClassDB::instance(ibt); + Object *obj = ClassDB::instantiate(ibt); ERR_CONTINUE_MSG(obj == nullptr, "Cannot instance script for autoload, expected 'Node' inheritance, got: " + @@ -2350,7 +2347,7 @@ bool Main::start() { Node *scene = nullptr; Ref<PackedScene> scenedata = ResourceLoader::load(local_game_path); if (scenedata.is_valid()) { - scene = scenedata->instance(); + scene = scenedata->instantiate(); } ERR_FAIL_COND_V_MSG(!scene, false, "Failed loading scene: " + local_game_path); @@ -2375,7 +2372,7 @@ bool Main::start() { String iconpath = GLOBAL_DEF("application/config/icon", "Variant()"); if ((iconpath != "") && (!hasicon)) { Ref<Image> icon; - icon.instance(); + icon.instantiate(); if (ImageLoader::load_image(iconpath, icon) == OK) { DisplayServer::get_singleton()->set_icon(icon); hasicon = true; diff --git a/main/performance.cpp b/main/performance.cpp index a2e53f2ee2..9f5be7b8c4 100644 --- a/main/performance.cpp +++ b/main/performance.cpp @@ -60,16 +60,12 @@ void Performance::_bind_methods() { BIND_ENUM_CONSTANT(OBJECT_RESOURCE_COUNT); BIND_ENUM_CONSTANT(OBJECT_NODE_COUNT); BIND_ENUM_CONSTANT(OBJECT_ORPHAN_NODE_COUNT); - BIND_ENUM_CONSTANT(RENDER_OBJECTS_IN_FRAME); - BIND_ENUM_CONSTANT(RENDER_VERTICES_IN_FRAME); - BIND_ENUM_CONSTANT(RENDER_MATERIAL_CHANGES_IN_FRAME); - BIND_ENUM_CONSTANT(RENDER_SHADER_CHANGES_IN_FRAME); - BIND_ENUM_CONSTANT(RENDER_SURFACE_CHANGES_IN_FRAME); - BIND_ENUM_CONSTANT(RENDER_DRAW_CALLS_IN_FRAME); + BIND_ENUM_CONSTANT(RENDER_TOTAL_OBJECTS_IN_FRAME); + BIND_ENUM_CONSTANT(RENDER_TOTAL_PRIMITIVES_IN_FRAME); + BIND_ENUM_CONSTANT(RENDER_TOTAL_DRAW_CALLS_IN_FRAME); BIND_ENUM_CONSTANT(RENDER_VIDEO_MEM_USED); BIND_ENUM_CONSTANT(RENDER_TEXTURE_MEM_USED); - BIND_ENUM_CONSTANT(RENDER_VERTEX_MEM_USED); - BIND_ENUM_CONSTANT(RENDER_USAGE_VIDEO_MEM_TOTAL); + BIND_ENUM_CONSTANT(RENDER_BUFFER_MEM_USED); BIND_ENUM_CONSTANT(PHYSICS_2D_ACTIVE_OBJECTS); BIND_ENUM_CONSTANT(PHYSICS_2D_COLLISION_PAIRS); BIND_ENUM_CONSTANT(PHYSICS_2D_ISLAND_COUNT); @@ -103,16 +99,12 @@ String Performance::get_monitor_name(Monitor p_monitor) const { "object/resources", "object/nodes", "object/orphan_nodes", - "raster/objects_drawn", - "raster/vertices_drawn", - "raster/mat_changes", - "raster/shader_changes", - "raster/surface_changes", - "raster/draw_calls", + "raster/total_objects_drawn", + "raster/total_primitives_drawn", + "raster/total_draw_calls", "video/video_mem", "video/texture_mem", - "video/vertex_mem", - "video/video_mem_max", + "video/buffer_mem", "physics_2d/active_objects", "physics_2d/collision_pairs", "physics_2d/islands", @@ -148,26 +140,18 @@ float Performance::get_monitor(Monitor p_monitor) const { return _get_node_count(); case OBJECT_ORPHAN_NODE_COUNT: return Node::orphan_node_count; - case RENDER_OBJECTS_IN_FRAME: - return RS::get_singleton()->get_render_info(RS::INFO_OBJECTS_IN_FRAME); - case RENDER_VERTICES_IN_FRAME: - return RS::get_singleton()->get_render_info(RS::INFO_VERTICES_IN_FRAME); - case RENDER_MATERIAL_CHANGES_IN_FRAME: - return RS::get_singleton()->get_render_info(RS::INFO_MATERIAL_CHANGES_IN_FRAME); - case RENDER_SHADER_CHANGES_IN_FRAME: - return RS::get_singleton()->get_render_info(RS::INFO_SHADER_CHANGES_IN_FRAME); - case RENDER_SURFACE_CHANGES_IN_FRAME: - return RS::get_singleton()->get_render_info(RS::INFO_SURFACE_CHANGES_IN_FRAME); - case RENDER_DRAW_CALLS_IN_FRAME: - return RS::get_singleton()->get_render_info(RS::INFO_DRAW_CALLS_IN_FRAME); + case RENDER_TOTAL_OBJECTS_IN_FRAME: + return RS::get_singleton()->get_rendering_info(RS::RENDERING_INFO_TOTAL_OBJECTS_IN_FRAME); + case RENDER_TOTAL_PRIMITIVES_IN_FRAME: + return RS::get_singleton()->get_rendering_info(RS::RENDERING_INFO_TOTAL_PRIMITIVES_IN_FRAME); + case RENDER_TOTAL_DRAW_CALLS_IN_FRAME: + return RS::get_singleton()->get_rendering_info(RS::RENDERING_INFO_TOTAL_DRAW_CALLS_IN_FRAME); case RENDER_VIDEO_MEM_USED: - return RS::get_singleton()->get_render_info(RS::INFO_VIDEO_MEM_USED); + return RS::get_singleton()->get_rendering_info(RS::RENDERING_INFO_VIDEO_MEM_USED); case RENDER_TEXTURE_MEM_USED: - return RS::get_singleton()->get_render_info(RS::INFO_TEXTURE_MEM_USED); - case RENDER_VERTEX_MEM_USED: - return RS::get_singleton()->get_render_info(RS::INFO_VERTEX_MEM_USED); - case RENDER_USAGE_VIDEO_MEM_TOTAL: - return RS::get_singleton()->get_render_info(RS::INFO_USAGE_VIDEO_MEM_TOTAL); + return RS::get_singleton()->get_rendering_info(RS::RENDERING_INFO_TEXTURE_MEM_USED); + case RENDER_BUFFER_MEM_USED: + return RS::get_singleton()->get_rendering_info(RS::RENDERING_INFO_BUFFER_MEM_USED); case PHYSICS_2D_ACTIVE_OBJECTS: return PhysicsServer2D::get_singleton()->get_process_info(PhysicsServer2D::INFO_ACTIVE_OBJECTS); case PHYSICS_2D_COLLISION_PAIRS: @@ -207,10 +191,6 @@ Performance::MonitorType Performance::get_monitor_type(Monitor p_monitor) const MONITOR_TYPE_QUANTITY, MONITOR_TYPE_QUANTITY, MONITOR_TYPE_QUANTITY, - MONITOR_TYPE_QUANTITY, - MONITOR_TYPE_QUANTITY, - MONITOR_TYPE_QUANTITY, - MONITOR_TYPE_MEMORY, MONITOR_TYPE_MEMORY, MONITOR_TYPE_MEMORY, MONITOR_TYPE_MEMORY, diff --git a/main/performance.h b/main/performance.h index 122e5a4f9a..174b3500d1 100644 --- a/main/performance.h +++ b/main/performance.h @@ -73,16 +73,12 @@ public: OBJECT_RESOURCE_COUNT, OBJECT_NODE_COUNT, OBJECT_ORPHAN_NODE_COUNT, - RENDER_OBJECTS_IN_FRAME, - RENDER_VERTICES_IN_FRAME, - RENDER_MATERIAL_CHANGES_IN_FRAME, - RENDER_SHADER_CHANGES_IN_FRAME, - RENDER_SURFACE_CHANGES_IN_FRAME, - RENDER_DRAW_CALLS_IN_FRAME, + RENDER_TOTAL_OBJECTS_IN_FRAME, + RENDER_TOTAL_PRIMITIVES_IN_FRAME, + RENDER_TOTAL_DRAW_CALLS_IN_FRAME, RENDER_VIDEO_MEM_USED, RENDER_TEXTURE_MEM_USED, - RENDER_VERTEX_MEM_USED, - RENDER_USAGE_VIDEO_MEM_TOTAL, + RENDER_BUFFER_MEM_USED, PHYSICS_2D_ACTIVE_OBJECTS, PHYSICS_2D_COLLISION_PAIRS, PHYSICS_2D_ISLAND_COUNT, diff --git a/misc/dist/linux/godot.6 b/misc/dist/linux/godot.6 index 4140094813..3e5bdefdce 100644 --- a/misc/dist/linux/godot.6 +++ b/misc/dist/linux/godot.6 @@ -85,12 +85,6 @@ Force low\-DPI mode (macOS and Windows only). .TP \fB\-\-no\-window\fR Disable window creation (Windows only). Useful together with \fB\-\-script\fR. -.TP -\fB\-\-enable\-vsync\-via\-compositor\fR -When vsync is enabled, vsync via the OS' window compositor (Windows only). -.TP -\fB\-\-disable\-vsync\-via\-compositor\fR -Disable vsync via the OS' window compositor (Windows only). .SS "Debug options:" .TP \fB\-d\fR, \fB\-\-debug\fR diff --git a/misc/dist/shell/_godot.zsh-completion b/misc/dist/shell/_godot.zsh-completion index 8e14240b53..b29746bfc4 100644 --- a/misc/dist/shell/_godot.zsh-completion +++ b/misc/dist/shell/_godot.zsh-completion @@ -51,8 +51,6 @@ _arguments \ '--position[request window position]:position in X,Y format' \ '--low-dpi[force low-DPI mode (macOS and Windows only)]' \ '--no-window[disable window creation (Windows only), useful together with --script]' \ - "--enable-vsync-via-compositor[when Vsync is enabled, Vsync via the OS' window compositor (Windows only)]" \ - "--disable-vsync-via-compositor[disable Vsync via the OS' window compositor (Windows only)]" \ '(-d --debug)'{-d,--debug}'[debug (local stdout debugger)]' \ '(-b --breakpoints)'{-b,--breakpoints}'[specify the breakpoint list as source::line comma-separated pairs, no spaces (use %20 instead)]:breakpoint list' \ '--profiling[enable profiling in the script debugger]' \ diff --git a/misc/dist/shell/godot.bash-completion b/misc/dist/shell/godot.bash-completion index 14f2be37b1..03861e43f8 100644 --- a/misc/dist/shell/godot.bash-completion +++ b/misc/dist/shell/godot.bash-completion @@ -54,8 +54,6 @@ _complete_godot_options() { --position --low-dpi --no-window ---enable-vsync-via-compositor ---disable-vsync-via-compositor --debug --breakpoints --profiling diff --git a/misc/dist/shell/godot.fish b/misc/dist/shell/godot.fish index a485a1dcdb..1367665bbc 100644 --- a/misc/dist/shell/godot.fish +++ b/misc/dist/shell/godot.fish @@ -61,8 +61,6 @@ complete -c godot -l resolution -d "Request window resolution" -x complete -c godot -l position -d "Request window position" -x complete -c godot -l low-dpi -d "Force low-DPI mode (macOS and Windows only)" complete -c godot -l no-window -d "Disable window creation (Windows only), useful together with --script" -complete -c godot -l enable-vsync-via-compositor -d "When Vsync is enabled, Vsync via the OS' window compositor (Windows only)" -complete -c godot -l disable-vsync-via-compositor -d "Disable Vsync via the OS' window compositor (Windows only)" # Debug options: complete -c godot -s d -l debug -d "Debug (local stdout debugger)" diff --git a/modules/basis_universal/register_types.cpp b/modules/basis_universal/register_types.cpp index 772ac87dbf..23639a4f2f 100644 --- a/modules/basis_universal/register_types.cpp +++ b/modules/basis_universal/register_types.cpp @@ -260,7 +260,7 @@ static Ref<Image> basis_universal_unpacker(const Vector<uint8_t> &p_buffer) { }; }; - image.instance(); + image.instantiate(); image->create(info.m_width, info.m_height, info.m_total_levels > 1, imgfmt, gpudata); return image; diff --git a/modules/basis_universal/texture_basisu.cpp b/modules/basis_universal/texture_basisu.cpp index 6a5f6313c4..9e917420ce 100644 --- a/modules/basis_universal/texture_basisu.cpp +++ b/modules/basis_universal/texture_basisu.cpp @@ -130,7 +130,7 @@ void TextureBasisU::set_basisu_data(const Vector<uint8_t>& p_data) { }; Ref<Image> img; - img.instance(); + img.instantiate(); img->create(info.m_width, info.m_height, info.m_total_levels > 1, imgfmt, gpudata); RenderingServer::get_singleton()->texture_allocate(texture, tex_size.x, tex_size.y, 0, img->get_format(), RS::TEXTURE_TYPE_2D, flags); diff --git a/modules/bmp/image_loader_bmp.cpp b/modules/bmp/image_loader_bmp.cpp index 27b49a6609..171895ed24 100644 --- a/modules/bmp/image_loader_bmp.cpp +++ b/modules/bmp/image_loader_bmp.cpp @@ -298,7 +298,7 @@ static Ref<Image> _bmp_mem_loader_func(const uint8_t *p_bmp, int p_size) { Error open_memfile_error = memfile.open_custom(p_bmp, p_size); ERR_FAIL_COND_V_MSG(open_memfile_error, Ref<Image>(), "Could not create memfile for BMP image buffer."); Ref<Image> img; - img.instance(); + img.instantiate(); Error load_error = ImageLoaderBMP().load_image(img, &memfile, false, 1.0f); ERR_FAIL_COND_V_MSG(load_error, Ref<Image>(), "Failed to load BMP image."); return img; diff --git a/modules/camera/camera_osx.mm b/modules/camera/camera_osx.mm index 9b59b68075..6bc56add20 100644 --- a/modules/camera/camera_osx.mm +++ b/modules/camera/camera_osx.mm @@ -162,7 +162,7 @@ uint8_t *w = img_data[0].ptrw(); memcpy(w, dataY, new_width * new_height); - img[0].instance(); + img[0].instantiate(); img[0]->create(new_width, new_height, 0, Image::FORMAT_R8, img_data[0]); } @@ -181,7 +181,7 @@ memcpy(w, dataCbCr, 2 * new_width * new_height); ///TODO GLES2 doesn't support FORMAT_RG8, need to do some form of conversion - img[1].instance(); + img[1].instantiate(); img[1]->create(new_width, new_height, 0, Image::FORMAT_RG8, img_data[1]); } @@ -341,7 +341,7 @@ void CameraOSX::update_feeds() { if (!found) { Ref<CameraFeedOSX> newfeed; - newfeed.instance(); + newfeed.instantiate(); newfeed->set_device(device); // assume display camera so inverse diff --git a/modules/csg/csg_shape.cpp b/modules/csg/csg_shape.cpp index d6690bb96c..fd8b213293 100644 --- a/modules/csg/csg_shape.cpp +++ b/modules/csg/csg_shape.cpp @@ -44,7 +44,7 @@ void CSGShape3D::set_use_collision(bool p_enable) { } if (use_collision) { - root_collision_shape.instance(); + root_collision_shape.instantiate(); root_collision_instance = PhysicsServer3D::get_singleton()->body_create(); PhysicsServer3D::get_singleton()->body_set_mode(root_collision_instance, PhysicsServer3D::BODY_MODE_STATIC); PhysicsServer3D::get_singleton()->body_set_state(root_collision_instance, PhysicsServer3D::BODY_STATE_TRANSFORM, get_global_transform()); @@ -411,7 +411,7 @@ void CSGShape3D::_update_shape() { } } - root_mesh.instance(); + root_mesh.instantiate(); //create surfaces for (int i = 0; i < surfaces.size(); i++) { @@ -498,7 +498,7 @@ void CSGShape3D::_notification(int p_what) { } if (use_collision && is_root_shape()) { - root_collision_shape.instance(); + root_collision_shape.instantiate(); root_collision_instance = PhysicsServer3D::get_singleton()->body_create(); PhysicsServer3D::get_singleton()->body_set_mode(root_collision_instance, PhysicsServer3D::BODY_MODE_STATIC); PhysicsServer3D::get_singleton()->body_set_state(root_collision_instance, PhysicsServer3D::BODY_STATE_TRANSFORM, get_global_transform()); @@ -868,7 +868,7 @@ void CSGMesh3D::_bind_methods() { ClassDB::bind_method(D_METHOD("get_material"), &CSGMesh3D::get_material); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "mesh", PROPERTY_HINT_RESOURCE_TYPE, "Mesh"), "set_mesh", "get_mesh"); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "StandardMaterial3D,ShaderMaterial"), "set_material", "get_material"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "BaseMaterial3D,ShaderMaterial"), "set_material", "get_material"); } void CSGMesh3D::set_mesh(const Ref<Mesh> &p_mesh) { @@ -1027,7 +1027,7 @@ void CSGSphere3D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "radial_segments", PROPERTY_HINT_RANGE, "1,100,1"), "set_radial_segments", "get_radial_segments"); ADD_PROPERTY(PropertyInfo(Variant::INT, "rings", PROPERTY_HINT_RANGE, "1,100,1"), "set_rings", "get_rings"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "smooth_faces"), "set_smooth_faces", "get_smooth_faces"); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "StandardMaterial3D,ShaderMaterial"), "set_material", "get_material"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "BaseMaterial3D,ShaderMaterial"), "set_material", "get_material"); } void CSGSphere3D::set_radius(const float p_radius) { @@ -1197,7 +1197,7 @@ void CSGBox3D::_bind_methods() { ClassDB::bind_method(D_METHOD("get_material"), &CSGBox3D::get_material); ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "size"), "set_size", "get_size"); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "StandardMaterial3D,ShaderMaterial"), "set_material", "get_material"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "BaseMaterial3D,ShaderMaterial"), "set_material", "get_material"); } void CSGBox3D::set_size(const Vector3 &p_size) { @@ -1373,12 +1373,12 @@ void CSGCylinder3D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_smooth_faces", "smooth_faces"), &CSGCylinder3D::set_smooth_faces); ClassDB::bind_method(D_METHOD("get_smooth_faces"), &CSGCylinder3D::get_smooth_faces); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "radius", PROPERTY_HINT_EXP_RANGE, "0.001,1000.0,0.001,or_greater"), "set_radius", "get_radius"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "height", PROPERTY_HINT_EXP_RANGE, "0.001,1000.0,0.001,or_greater"), "set_height", "get_height"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "radius", PROPERTY_HINT_RANGE, "0.001,1000.0,0.001,or_greater,exp"), "set_radius", "get_radius"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "height", PROPERTY_HINT_RANGE, "0.001,1000.0,0.001,or_greater,exp"), "set_height", "get_height"); ADD_PROPERTY(PropertyInfo(Variant::INT, "sides", PROPERTY_HINT_RANGE, "3,64,1"), "set_sides", "get_sides"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "cone"), "set_cone", "is_cone"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "smooth_faces"), "set_smooth_faces", "get_smooth_faces"); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "StandardMaterial3D,ShaderMaterial"), "set_material", "get_material"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "BaseMaterial3D,ShaderMaterial"), "set_material", "get_material"); } void CSGCylinder3D::set_radius(const float p_radius) { @@ -1592,12 +1592,12 @@ void CSGTorus3D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_smooth_faces", "smooth_faces"), &CSGTorus3D::set_smooth_faces); ClassDB::bind_method(D_METHOD("get_smooth_faces"), &CSGTorus3D::get_smooth_faces); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "inner_radius", PROPERTY_HINT_EXP_RANGE, "0.001,1000.0,0.001,or_greater"), "set_inner_radius", "get_inner_radius"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "outer_radius", PROPERTY_HINT_EXP_RANGE, "0.001,1000.0,0.001,or_greater"), "set_outer_radius", "get_outer_radius"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "inner_radius", PROPERTY_HINT_RANGE, "0.001,1000.0,0.001,or_greater,exp"), "set_inner_radius", "get_inner_radius"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "outer_radius", PROPERTY_HINT_RANGE, "0.001,1000.0,0.001,or_greater,exp"), "set_outer_radius", "get_outer_radius"); ADD_PROPERTY(PropertyInfo(Variant::INT, "sides", PROPERTY_HINT_RANGE, "3,64,1"), "set_sides", "get_sides"); ADD_PROPERTY(PropertyInfo(Variant::INT, "ring_sides", PROPERTY_HINT_RANGE, "3,64,1"), "set_ring_sides", "get_ring_sides"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "smooth_faces"), "set_smooth_faces", "get_smooth_faces"); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "StandardMaterial3D,ShaderMaterial"), "set_material", "get_material"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "BaseMaterial3D,ShaderMaterial"), "set_material", "get_material"); } void CSGTorus3D::set_inner_radius(const float p_inner_radius) { @@ -2158,13 +2158,13 @@ void CSGPolygon3D::_notification(int p_what) { void CSGPolygon3D::_validate_property(PropertyInfo &property) const { if (property.name.begins_with("spin") && mode != MODE_SPIN) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } if (property.name.begins_with("path") && mode != MODE_PATH) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } if (property.name == "depth" && mode != MODE_DEPTH) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } CSGShape3D::_validate_property(property); @@ -2224,17 +2224,17 @@ void CSGPolygon3D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::PACKED_VECTOR2_ARRAY, "polygon"), "set_polygon", "get_polygon"); ADD_PROPERTY(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Depth,Spin,Path"), "set_mode", "get_mode"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "depth", PROPERTY_HINT_EXP_RANGE, "0.001,1000.0,0.001,or_greater"), "set_depth", "get_depth"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "depth", PROPERTY_HINT_RANGE, "0.001,1000.0,0.001,or_greater,exp"), "set_depth", "get_depth"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "spin_degrees", PROPERTY_HINT_RANGE, "1,360,0.1"), "set_spin_degrees", "get_spin_degrees"); ADD_PROPERTY(PropertyInfo(Variant::INT, "spin_sides", PROPERTY_HINT_RANGE, "3,64,1"), "set_spin_sides", "get_spin_sides"); ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "path_node", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Path3D"), "set_path_node", "get_path_node"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "path_interval", PROPERTY_HINT_EXP_RANGE, "0.001,1000.0,0.001,or_greater"), "set_path_interval", "get_path_interval"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "path_interval", PROPERTY_HINT_RANGE, "0.001,1000.0,0.001,or_greater,exp"), "set_path_interval", "get_path_interval"); ADD_PROPERTY(PropertyInfo(Variant::INT, "path_rotation", PROPERTY_HINT_ENUM, "Polygon,Path,PathFollow"), "set_path_rotation", "get_path_rotation"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "path_local"), "set_path_local", "is_path_local"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "path_continuous_u"), "set_path_continuous_u", "is_path_continuous_u"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "path_joined"), "set_path_joined", "is_path_joined"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "smooth_faces"), "set_smooth_faces", "get_smooth_faces"); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "StandardMaterial3D,ShaderMaterial"), "set_material", "get_material"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "BaseMaterial3D,ShaderMaterial"), "set_material", "get_material"); BIND_ENUM_CONSTANT(MODE_DEPTH); BIND_ENUM_CONSTANT(MODE_SPIN); diff --git a/modules/dds/register_types.cpp b/modules/dds/register_types.cpp index 1444d33171..60282c3f36 100644 --- a/modules/dds/register_types.cpp +++ b/modules/dds/register_types.cpp @@ -35,7 +35,7 @@ static Ref<ResourceFormatDDS> resource_loader_dds; void register_dds_types() { - resource_loader_dds.instance(); + resource_loader_dds.instantiate(); ResourceLoader::add_resource_format_loader(resource_loader_dds); } diff --git a/modules/enet/config.py b/modules/enet/config.py index 5fd343c75d..3662b2d94e 100644 --- a/modules/enet/config.py +++ b/modules/enet/config.py @@ -8,7 +8,7 @@ def configure(env): def get_doc_classes(): return [ - "NetworkedMultiplayerENet", + "ENetMultiplayerPeer", ] diff --git a/modules/enet/doc_classes/NetworkedMultiplayerENet.xml b/modules/enet/doc_classes/ENetMultiplayerPeer.xml index 271cb03c9f..5b2c72dce4 100644 --- a/modules/enet/doc_classes/NetworkedMultiplayerENet.xml +++ b/modules/enet/doc_classes/ENetMultiplayerPeer.xml @@ -1,10 +1,10 @@ <?xml version="1.0" encoding="UTF-8" ?> -<class name="NetworkedMultiplayerENet" inherits="NetworkedMultiplayerPeer" version="4.0"> +<class name="ENetMultiplayerPeer" inherits="MultiplayerPeer" version="4.0"> <brief_description> PacketPeer implementation using the [url=http://enet.bespin.org/index.html]ENet[/url] library. </brief_description> <description> - A PacketPeer implementation that should be passed to [member SceneTree.network_peer] after being initialized as either a client or server. Events can then be handled by connecting to [SceneTree] signals. + A PacketPeer implementation that should be passed to [member MultiplayerAPI.network_peer] after being initialized as either a client or server. Events can then be handled by connecting to [SceneTree] signals. ENet's purpose is to provide a relatively thin, simple and robust network communication layer on top of UDP (User Datagram Protocol). [b]Note:[/b] ENet only uses UDP, not TCP. When forwarding the server port to make your server accessible on the public Internet, you only need to forward the server port in UDP. You can use the [UPNP] class to try to forward the server port automatically when starting the server. </description> @@ -36,7 +36,7 @@ <argument index="4" name="local_port" type="int" default="0"> </argument> <description> - Create client that connects to a server at [code]address[/code] using specified [code]port[/code]. The given address needs to be either a fully qualified domain name (e.g. [code]"www.example.com"[/code]) or an IP address in IPv4 or IPv6 format (e.g. [code]"192.168.1.1"[/code]). The [code]port[/code] is the port the server is listening on. The [code]in_bandwidth[/code] and [code]out_bandwidth[/code] parameters can be used to limit the incoming and outgoing bandwidth to the given number of bytes per second. The default of 0 means unlimited bandwidth. Note that ENet will strategically drop packets on specific sides of a connection between peers to ensure the peer's bandwidth is not overwhelmed. The bandwidth parameters also determine the window size of a connection which limits the amount of reliable packets that may be in transit at any given time. Returns [constant OK] if a client was created, [constant ERR_ALREADY_IN_USE] if this NetworkedMultiplayerENet instance already has an open connection (in which case you need to call [method close_connection] first) or [constant ERR_CANT_CREATE] if the client could not be created. If [code]local_port[/code] is specified, the client will also listen to the given port; this is useful for some NAT traversal techniques. + Create client that connects to a server at [code]address[/code] using specified [code]port[/code]. The given address needs to be either a fully qualified domain name (e.g. [code]"www.example.com"[/code]) or an IP address in IPv4 or IPv6 format (e.g. [code]"192.168.1.1"[/code]). The [code]port[/code] is the port the server is listening on. The [code]in_bandwidth[/code] and [code]out_bandwidth[/code] parameters can be used to limit the incoming and outgoing bandwidth to the given number of bytes per second. The default of 0 means unlimited bandwidth. Note that ENet will strategically drop packets on specific sides of a connection between peers to ensure the peer's bandwidth is not overwhelmed. The bandwidth parameters also determine the window size of a connection which limits the amount of reliable packets that may be in transit at any given time. Returns [constant OK] if a client was created, [constant ERR_ALREADY_IN_USE] if this ENetMultiplayerPeer instance already has an open connection (in which case you need to call [method close_connection] first) or [constant ERR_CANT_CREATE] if the client could not be created. If [code]local_port[/code] is specified, the client will also listen to the given port; this is useful for some NAT traversal techniques. </description> </method> <method name="create_server"> @@ -51,7 +51,7 @@ <argument index="3" name="out_bandwidth" type="int" default="0"> </argument> <description> - Create server that listens to connections via [code]port[/code]. The port needs to be an available, unused port between 0 and 65535. Note that ports below 1024 are privileged and may require elevated permissions depending on the platform. To change the interface the server listens on, use [method set_bind_ip]. The default IP is the wildcard [code]"*"[/code], which listens on all available interfaces. [code]max_clients[/code] is the maximum number of clients that are allowed at once, any number up to 4095 may be used, although the achievable number of simultaneous clients may be far lower and depends on the application. For additional details on the bandwidth parameters, see [method create_client]. Returns [constant OK] if a server was created, [constant ERR_ALREADY_IN_USE] if this NetworkedMultiplayerENet instance already has an open connection (in which case you need to call [method close_connection] first) or [constant ERR_CANT_CREATE] if the server could not be created. + Create server that listens to connections via [code]port[/code]. The port needs to be an available, unused port between 0 and 65535. Note that ports below 1024 are privileged and may require elevated permissions depending on the platform. To change the interface the server listens on, use [method set_bind_ip]. The default IP is the wildcard [code]"*"[/code], which listens on all available interfaces. [code]max_clients[/code] is the maximum number of clients that are allowed at once, any number up to 4095 may be used, although the achievable number of simultaneous clients may be far lower and depends on the application. For additional details on the bandwidth parameters, see [method create_client]. Returns [constant OK] if a server was created, [constant ERR_ALREADY_IN_USE] if this ENetMultiplayerPeer instance already has an open connection (in which case you need to call [method close_connection] first) or [constant ERR_CANT_CREATE] if the server could not be created. </description> </method> <method name="disconnect_peer"> @@ -150,12 +150,12 @@ </methods> <members> <member name="always_ordered" type="bool" setter="set_always_ordered" getter="is_always_ordered" default="false"> - Enforce ordered packets when using [constant NetworkedMultiplayerPeer.TRANSFER_MODE_UNRELIABLE] (thus behaving similarly to [constant NetworkedMultiplayerPeer.TRANSFER_MODE_UNRELIABLE_ORDERED]). This is the only way to use ordering with the RPC system. + Enforce ordered packets when using [constant MultiplayerPeer.TRANSFER_MODE_UNRELIABLE] (thus behaving similarly to [constant MultiplayerPeer.TRANSFER_MODE_UNRELIABLE_ORDERED]). This is the only way to use ordering with the RPC system. </member> <member name="channel_count" type="int" setter="set_channel_count" getter="get_channel_count" default="3"> The number of channels to be used by ENet. Channels are used to separate different kinds of data. In reliable or ordered mode, for example, the packet delivery order is ensured on a per-channel basis. This is done to combat latency and reduces ordering restrictions on packets. The delivery status of a packet in one channel won't stall the delivery of other packets in another channel. </member> - <member name="compression_mode" type="int" setter="set_compression_mode" getter="get_compression_mode" enum="NetworkedMultiplayerENet.CompressionMode" default="0"> + <member name="compression_mode" type="int" setter="set_compression_mode" getter="get_compression_mode" enum="ENetMultiplayerPeer.CompressionMode" default="0"> The compression method used for network packets. These have different tradeoffs of compression speed versus bandwidth, you may need to test which one works best for your use case if you use compression at all. </member> <member name="dtls_verify" type="bool" setter="set_dtls_verify_enabled" getter="is_dtls_verify_enabled" default="true"> @@ -168,7 +168,7 @@ <member name="transfer_channel" type="int" setter="set_transfer_channel" getter="get_transfer_channel" default="-1"> Set the default channel to be used to transfer data. By default, this value is [code]-1[/code] which means that ENet will only use 2 channels: one for reliable packets, and one for unreliable packets. The channel [code]0[/code] is reserved and cannot be used. Setting this member to any value between [code]0[/code] and [member channel_count] (excluded) will force ENet to use that channel for sending data. See [member channel_count] for more information about ENet channels. </member> - <member name="transfer_mode" type="int" setter="set_transfer_mode" getter="get_transfer_mode" override="true" enum="NetworkedMultiplayerPeer.TransferMode" default="2" /> + <member name="transfer_mode" type="int" setter="set_transfer_mode" getter="get_transfer_mode" override="true" enum="MultiplayerPeer.TransferMode" default="2" /> <member name="use_dtls" type="bool" setter="set_dtls_enabled" getter="is_dtls_enabled" default="false"> When enabled, the client or server created by this peer, will use [PacketPeerDTLS] instead of raw UDP sockets for communicating with the remote peer. This will make the communication encrypted with DTLS at the cost of higher resource usage and potentially larger packet size. Note: When creating a DTLS server, make sure you setup the key/certificate pair via [method set_dtls_key] and [method set_dtls_certificate]. For DTLS clients, have a look at the [member dtls_verify] option, and configure the certificate accordingly via [method set_dtls_certificate]. diff --git a/modules/enet/networked_multiplayer_enet.cpp b/modules/enet/enet_multiplayer_peer.cpp index 94260e8c13..a9726426ad 100644 --- a/modules/enet/networked_multiplayer_enet.cpp +++ b/modules/enet/enet_multiplayer_peer.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* networked_multiplayer_enet.cpp */ +/* enet_multiplayer_peer.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,45 +28,45 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "networked_multiplayer_enet.h" +#include "enet_multiplayer_peer.h" #include "core/io/ip.h" #include "core/io/marshalls.h" #include "core/os/os.h" -void NetworkedMultiplayerENet::set_transfer_mode(TransferMode p_mode) { +void ENetMultiplayerPeer::set_transfer_mode(TransferMode p_mode) { transfer_mode = p_mode; } -NetworkedMultiplayerPeer::TransferMode NetworkedMultiplayerENet::get_transfer_mode() const { +MultiplayerPeer::TransferMode ENetMultiplayerPeer::get_transfer_mode() const { return transfer_mode; } -void NetworkedMultiplayerENet::set_target_peer(int p_peer) { +void ENetMultiplayerPeer::set_target_peer(int p_peer) { target_peer = p_peer; } -int NetworkedMultiplayerENet::get_packet_peer() const { +int ENetMultiplayerPeer::get_packet_peer() const { ERR_FAIL_COND_V_MSG(!active, 1, "The multiplayer instance isn't currently active."); ERR_FAIL_COND_V(incoming_packets.size() == 0, 1); return incoming_packets.front()->get().from; } -int NetworkedMultiplayerENet::get_packet_channel() const { +int ENetMultiplayerPeer::get_packet_channel() const { ERR_FAIL_COND_V_MSG(!active, -1, "The multiplayer instance isn't currently active."); ERR_FAIL_COND_V(incoming_packets.size() == 0, -1); return incoming_packets.front()->get().channel; } -int NetworkedMultiplayerENet::get_last_packet_channel() const { +int ENetMultiplayerPeer::get_last_packet_channel() const { ERR_FAIL_COND_V_MSG(!active, -1, "The multiplayer instance isn't currently active."); ERR_FAIL_COND_V(!current_packet.packet, -1); return current_packet.channel; } -Error NetworkedMultiplayerENet::create_server(int p_port, int p_max_clients, int p_in_bandwidth, int p_out_bandwidth) { +Error ENetMultiplayerPeer::create_server(int p_port, int p_max_clients, int p_in_bandwidth, int p_out_bandwidth) { ERR_FAIL_COND_V_MSG(active, ERR_ALREADY_IN_USE, "The multiplayer instance is already active."); ERR_FAIL_COND_V_MSG(p_port < 0 || p_port > 65535, ERR_INVALID_PARAMETER, "The local port number must be between 0 and 65535 (inclusive)."); ERR_FAIL_COND_V_MSG(p_max_clients < 1 || p_max_clients > 4095, ERR_INVALID_PARAMETER, "The number of clients must be set between 1 and 4095 (inclusive)."); @@ -115,7 +115,7 @@ Error NetworkedMultiplayerENet::create_server(int p_port, int p_max_clients, int connection_status = CONNECTION_CONNECTED; return OK; } -Error NetworkedMultiplayerENet::create_client(const String &p_address, int p_port, int p_in_bandwidth, int p_out_bandwidth, int p_local_port) { +Error ENetMultiplayerPeer::create_client(const String &p_address, int p_port, int p_in_bandwidth, int p_out_bandwidth, int p_local_port) { ERR_FAIL_COND_V_MSG(active, ERR_ALREADY_IN_USE, "The multiplayer instance is already active."); ERR_FAIL_COND_V_MSG(p_port < 1 || p_port > 65535, ERR_INVALID_PARAMETER, "The remote port number must be between 1 and 65535 (inclusive)."); ERR_FAIL_COND_V_MSG(p_local_port < 0 || p_local_port > 65535, ERR_INVALID_PARAMETER, "The local port number must be between 0 and 65535 (inclusive)."); @@ -199,7 +199,7 @@ Error NetworkedMultiplayerENet::create_client(const String &p_address, int p_por return OK; } -void NetworkedMultiplayerENet::poll() { +void ENetMultiplayerPeer::poll() { ERR_FAIL_COND_MSG(!active, "The multiplayer instance isn't currently active."); _pop_current_packet(); @@ -426,13 +426,13 @@ void NetworkedMultiplayerENet::poll() { } } -bool NetworkedMultiplayerENet::is_server() const { +bool ENetMultiplayerPeer::is_server() const { ERR_FAIL_COND_V_MSG(!active, false, "The multiplayer instance isn't currently active."); return server; } -void NetworkedMultiplayerENet::close_connection(uint32_t wait_usec) { +void ENetMultiplayerPeer::close_connection(uint32_t wait_usec) { ERR_FAIL_COND_MSG(!active, "The multiplayer instance isn't currently active."); _pop_current_packet(); @@ -463,7 +463,7 @@ void NetworkedMultiplayerENet::close_connection(uint32_t wait_usec) { connection_status = CONNECTION_DISCONNECTED; } -void NetworkedMultiplayerENet::disconnect_peer(int p_peer, bool now) { +void ENetMultiplayerPeer::disconnect_peer(int p_peer, bool now) { ERR_FAIL_COND_MSG(!active, "The multiplayer instance isn't currently active."); ERR_FAIL_COND_MSG(!is_server(), "Can't disconnect a peer when not acting as a server."); ERR_FAIL_COND_MSG(!peer_map.has(p_peer), vformat("Peer ID %d not found in the list of peers.", p_peer)); @@ -498,11 +498,11 @@ void NetworkedMultiplayerENet::disconnect_peer(int p_peer, bool now) { } } -int NetworkedMultiplayerENet::get_available_packet_count() const { +int ENetMultiplayerPeer::get_available_packet_count() const { return incoming_packets.size(); } -Error NetworkedMultiplayerENet::get_packet(const uint8_t **r_buffer, int &r_buffer_size) { +Error ENetMultiplayerPeer::get_packet(const uint8_t **r_buffer, int &r_buffer_size) { ERR_FAIL_COND_V_MSG(incoming_packets.size() == 0, ERR_UNAVAILABLE, "No incoming packets available."); _pop_current_packet(); @@ -516,7 +516,7 @@ Error NetworkedMultiplayerENet::get_packet(const uint8_t **r_buffer, int &r_buff return OK; } -Error NetworkedMultiplayerENet::put_packet(const uint8_t *p_buffer, int p_buffer_size) { +Error ENetMultiplayerPeer::put_packet(const uint8_t *p_buffer, int p_buffer_size) { ERR_FAIL_COND_V_MSG(!active, ERR_UNCONFIGURED, "The multiplayer instance isn't currently active."); ERR_FAIL_COND_V_MSG(connection_status != CONNECTION_CONNECTED, ERR_UNCONFIGURED, "The multiplayer instance isn't currently connected to any server or client."); @@ -591,11 +591,11 @@ Error NetworkedMultiplayerENet::put_packet(const uint8_t *p_buffer, int p_buffer return OK; } -int NetworkedMultiplayerENet::get_max_packet_size() const { +int ENetMultiplayerPeer::get_max_packet_size() const { return 1 << 24; // Anything is good } -void NetworkedMultiplayerENet::_pop_current_packet() { +void ENetMultiplayerPeer::_pop_current_packet() { if (current_packet.packet) { enet_packet_destroy(current_packet.packet); current_packet.packet = nullptr; @@ -604,11 +604,11 @@ void NetworkedMultiplayerENet::_pop_current_packet() { } } -NetworkedMultiplayerPeer::ConnectionStatus NetworkedMultiplayerENet::get_connection_status() const { +MultiplayerPeer::ConnectionStatus ENetMultiplayerPeer::get_connection_status() const { return connection_status; } -uint32_t NetworkedMultiplayerENet::_gen_unique_id() const { +uint32_t ENetMultiplayerPeer::_gen_unique_id() const { uint32_t hash = 0; while (hash == 0 || hash == 1) { @@ -629,12 +629,12 @@ uint32_t NetworkedMultiplayerENet::_gen_unique_id() const { return hash; } -int NetworkedMultiplayerENet::get_unique_id() const { +int ENetMultiplayerPeer::get_unique_id() const { ERR_FAIL_COND_V_MSG(!active, 0, "The multiplayer instance isn't currently active."); return unique_id; } -void NetworkedMultiplayerENet::set_refuse_new_connections(bool p_enable) { +void ENetMultiplayerPeer::set_refuse_new_connections(bool p_enable) { refuse_connections = p_enable; #ifdef GODOT_ENET if (active) { @@ -643,20 +643,20 @@ void NetworkedMultiplayerENet::set_refuse_new_connections(bool p_enable) { #endif } -bool NetworkedMultiplayerENet::is_refusing_new_connections() const { +bool ENetMultiplayerPeer::is_refusing_new_connections() const { return refuse_connections; } -void NetworkedMultiplayerENet::set_compression_mode(CompressionMode p_mode) { +void ENetMultiplayerPeer::set_compression_mode(CompressionMode p_mode) { compression_mode = p_mode; } -NetworkedMultiplayerENet::CompressionMode NetworkedMultiplayerENet::get_compression_mode() const { +ENetMultiplayerPeer::CompressionMode ENetMultiplayerPeer::get_compression_mode() const { return compression_mode; } -size_t NetworkedMultiplayerENet::enet_compress(void *context, const ENetBuffer *inBuffers, size_t inBufferCount, size_t inLimit, enet_uint8 *outData, size_t outLimit) { - NetworkedMultiplayerENet *enet = (NetworkedMultiplayerENet *)(context); +size_t ENetMultiplayerPeer::enet_compress(void *context, const ENetBuffer *inBuffers, size_t inBufferCount, size_t inLimit, enet_uint8 *outData, size_t outLimit) { + ENetMultiplayerPeer *enet = (ENetMultiplayerPeer *)(context); if (size_t(enet->src_compressor_mem.size()) < inLimit) { enet->src_compressor_mem.resize(inLimit); @@ -709,8 +709,8 @@ size_t NetworkedMultiplayerENet::enet_compress(void *context, const ENetBuffer * return ret; } -size_t NetworkedMultiplayerENet::enet_decompress(void *context, const enet_uint8 *inData, size_t inLimit, enet_uint8 *outData, size_t outLimit) { - NetworkedMultiplayerENet *enet = (NetworkedMultiplayerENet *)(context); +size_t ENetMultiplayerPeer::enet_decompress(void *context, const enet_uint8 *inData, size_t inLimit, enet_uint8 *outData, size_t outLimit) { + ENetMultiplayerPeer *enet = (ENetMultiplayerPeer *)(context); int ret = -1; switch (enet->compression_mode) { case COMPRESS_FASTLZ: { @@ -732,7 +732,7 @@ size_t NetworkedMultiplayerENet::enet_decompress(void *context, const enet_uint8 } } -void NetworkedMultiplayerENet::_setup_compressor() { +void ENetMultiplayerPeer::_setup_compressor() { switch (compression_mode) { case COMPRESS_NONE: { enet_host_compress(host, nullptr); @@ -748,11 +748,11 @@ void NetworkedMultiplayerENet::_setup_compressor() { } } -void NetworkedMultiplayerENet::enet_compressor_destroy(void *context) { +void ENetMultiplayerPeer::enet_compressor_destroy(void *context) { // Nothing to do } -IPAddress NetworkedMultiplayerENet::get_peer_address(int p_peer_id) const { +IPAddress ENetMultiplayerPeer::get_peer_address(int p_peer_id) const { ERR_FAIL_COND_V_MSG(!peer_map.has(p_peer_id), IPAddress(), vformat("Peer ID %d not found in the list of peers.", p_peer_id)); ERR_FAIL_COND_V_MSG(!is_server() && p_peer_id != 1, IPAddress(), "Can't get the address of peers other than the server (ID -1) when acting as a client."); ERR_FAIL_COND_V_MSG(peer_map[p_peer_id] == nullptr, IPAddress(), vformat("Peer ID %d found in the list of peers, but is null.", p_peer_id)); @@ -767,7 +767,7 @@ IPAddress NetworkedMultiplayerENet::get_peer_address(int p_peer_id) const { return out; } -int NetworkedMultiplayerENet::get_peer_port(int p_peer_id) const { +int ENetMultiplayerPeer::get_peer_port(int p_peer_id) const { ERR_FAIL_COND_V_MSG(!peer_map.has(p_peer_id), 0, vformat("Peer ID %d not found in the list of peers.", p_peer_id)); ERR_FAIL_COND_V_MSG(!is_server() && p_peer_id != 1, 0, "Can't get the address of peers other than the server (ID -1) when acting as a client."); ERR_FAIL_COND_V_MSG(peer_map[p_peer_id] == nullptr, 0, vformat("Peer ID %d found in the list of peers, but is null.", p_peer_id)); @@ -778,12 +778,12 @@ int NetworkedMultiplayerENet::get_peer_port(int p_peer_id) const { #endif } -int NetworkedMultiplayerENet::get_local_port() const { +int ENetMultiplayerPeer::get_local_port() const { ERR_FAIL_COND_V_MSG(!active || !host, 0, "The multiplayer instance isn't currently active."); return host->address.port; } -void NetworkedMultiplayerENet::set_peer_timeout(int p_peer_id, int p_timeout_limit, int p_timeout_min, int p_timeout_max) { +void ENetMultiplayerPeer::set_peer_timeout(int p_peer_id, int p_timeout_limit, int p_timeout_min, int p_timeout_max) { ERR_FAIL_COND_MSG(!peer_map.has(p_peer_id), vformat("Peer ID %d not found in the list of peers.", p_peer_id)); ERR_FAIL_COND_MSG(!is_server() && p_peer_id != 1, "Can't change the timeout of peers other then the server when acting as a client."); ERR_FAIL_COND_MSG(peer_map[p_peer_id] == nullptr, vformat("Peer ID %d found in the list of peers, but is null.", p_peer_id)); @@ -791,73 +791,73 @@ void NetworkedMultiplayerENet::set_peer_timeout(int p_peer_id, int p_timeout_lim enet_peer_timeout(peer_map[p_peer_id], p_timeout_limit, p_timeout_min, p_timeout_max); } -void NetworkedMultiplayerENet::set_transfer_channel(int p_channel) { +void ENetMultiplayerPeer::set_transfer_channel(int p_channel) { ERR_FAIL_COND_MSG(p_channel < -1 || p_channel >= channel_count, vformat("The transfer channel must be set between 0 and %d, inclusive (got %d).", channel_count - 1, p_channel)); ERR_FAIL_COND_MSG(p_channel == SYSCH_CONFIG, vformat("The channel %d is reserved.", SYSCH_CONFIG)); transfer_channel = p_channel; } -int NetworkedMultiplayerENet::get_transfer_channel() const { +int ENetMultiplayerPeer::get_transfer_channel() const { return transfer_channel; } -void NetworkedMultiplayerENet::set_channel_count(int p_channel) { +void ENetMultiplayerPeer::set_channel_count(int p_channel) { ERR_FAIL_COND_MSG(active, "The channel count can't be set while the multiplayer instance is active."); ERR_FAIL_COND_MSG(p_channel < SYSCH_MAX, vformat("The channel count must be greater than or equal to %d to account for reserved channels (got %d).", SYSCH_MAX, p_channel)); channel_count = p_channel; } -int NetworkedMultiplayerENet::get_channel_count() const { +int ENetMultiplayerPeer::get_channel_count() const { return channel_count; } -void NetworkedMultiplayerENet::set_always_ordered(bool p_ordered) { +void ENetMultiplayerPeer::set_always_ordered(bool p_ordered) { always_ordered = p_ordered; } -bool NetworkedMultiplayerENet::is_always_ordered() const { +bool ENetMultiplayerPeer::is_always_ordered() const { return always_ordered; } -void NetworkedMultiplayerENet::set_server_relay_enabled(bool p_enabled) { +void ENetMultiplayerPeer::set_server_relay_enabled(bool p_enabled) { ERR_FAIL_COND_MSG(active, "Server relaying can't be toggled while the multiplayer instance is active."); server_relay = p_enabled; } -bool NetworkedMultiplayerENet::is_server_relay_enabled() const { +bool ENetMultiplayerPeer::is_server_relay_enabled() const { return server_relay; } -void NetworkedMultiplayerENet::_bind_methods() { - ClassDB::bind_method(D_METHOD("create_server", "port", "max_clients", "in_bandwidth", "out_bandwidth"), &NetworkedMultiplayerENet::create_server, DEFVAL(32), DEFVAL(0), DEFVAL(0)); - ClassDB::bind_method(D_METHOD("create_client", "address", "port", "in_bandwidth", "out_bandwidth", "local_port"), &NetworkedMultiplayerENet::create_client, DEFVAL(0), DEFVAL(0), DEFVAL(0)); - ClassDB::bind_method(D_METHOD("close_connection", "wait_usec"), &NetworkedMultiplayerENet::close_connection, DEFVAL(100)); - ClassDB::bind_method(D_METHOD("disconnect_peer", "id", "now"), &NetworkedMultiplayerENet::disconnect_peer, DEFVAL(false)); - ClassDB::bind_method(D_METHOD("set_compression_mode", "mode"), &NetworkedMultiplayerENet::set_compression_mode); - ClassDB::bind_method(D_METHOD("get_compression_mode"), &NetworkedMultiplayerENet::get_compression_mode); - ClassDB::bind_method(D_METHOD("set_bind_ip", "ip"), &NetworkedMultiplayerENet::set_bind_ip); - ClassDB::bind_method(D_METHOD("set_dtls_enabled", "enabled"), &NetworkedMultiplayerENet::set_dtls_enabled); - ClassDB::bind_method(D_METHOD("is_dtls_enabled"), &NetworkedMultiplayerENet::is_dtls_enabled); - ClassDB::bind_method(D_METHOD("set_dtls_key", "key"), &NetworkedMultiplayerENet::set_dtls_key); - ClassDB::bind_method(D_METHOD("set_dtls_certificate", "certificate"), &NetworkedMultiplayerENet::set_dtls_certificate); - ClassDB::bind_method(D_METHOD("set_dtls_verify_enabled", "enabled"), &NetworkedMultiplayerENet::set_dtls_verify_enabled); - ClassDB::bind_method(D_METHOD("is_dtls_verify_enabled"), &NetworkedMultiplayerENet::is_dtls_verify_enabled); - ClassDB::bind_method(D_METHOD("get_peer_address", "id"), &NetworkedMultiplayerENet::get_peer_address); - ClassDB::bind_method(D_METHOD("get_peer_port", "id"), &NetworkedMultiplayerENet::get_peer_port); - ClassDB::bind_method(D_METHOD("get_local_port"), &NetworkedMultiplayerENet::get_local_port); - ClassDB::bind_method(D_METHOD("set_peer_timeout", "id", "timeout_limit", "timeout_min", "timeout_max"), &NetworkedMultiplayerENet::set_peer_timeout); - - ClassDB::bind_method(D_METHOD("get_packet_channel"), &NetworkedMultiplayerENet::get_packet_channel); - ClassDB::bind_method(D_METHOD("get_last_packet_channel"), &NetworkedMultiplayerENet::get_last_packet_channel); - ClassDB::bind_method(D_METHOD("set_transfer_channel", "channel"), &NetworkedMultiplayerENet::set_transfer_channel); - ClassDB::bind_method(D_METHOD("get_transfer_channel"), &NetworkedMultiplayerENet::get_transfer_channel); - ClassDB::bind_method(D_METHOD("set_channel_count", "channels"), &NetworkedMultiplayerENet::set_channel_count); - ClassDB::bind_method(D_METHOD("get_channel_count"), &NetworkedMultiplayerENet::get_channel_count); - ClassDB::bind_method(D_METHOD("set_always_ordered", "ordered"), &NetworkedMultiplayerENet::set_always_ordered); - ClassDB::bind_method(D_METHOD("is_always_ordered"), &NetworkedMultiplayerENet::is_always_ordered); - ClassDB::bind_method(D_METHOD("set_server_relay_enabled", "enabled"), &NetworkedMultiplayerENet::set_server_relay_enabled); - ClassDB::bind_method(D_METHOD("is_server_relay_enabled"), &NetworkedMultiplayerENet::is_server_relay_enabled); +void ENetMultiplayerPeer::_bind_methods() { + ClassDB::bind_method(D_METHOD("create_server", "port", "max_clients", "in_bandwidth", "out_bandwidth"), &ENetMultiplayerPeer::create_server, DEFVAL(32), DEFVAL(0), DEFVAL(0)); + ClassDB::bind_method(D_METHOD("create_client", "address", "port", "in_bandwidth", "out_bandwidth", "local_port"), &ENetMultiplayerPeer::create_client, DEFVAL(0), DEFVAL(0), DEFVAL(0)); + ClassDB::bind_method(D_METHOD("close_connection", "wait_usec"), &ENetMultiplayerPeer::close_connection, DEFVAL(100)); + ClassDB::bind_method(D_METHOD("disconnect_peer", "id", "now"), &ENetMultiplayerPeer::disconnect_peer, DEFVAL(false)); + ClassDB::bind_method(D_METHOD("set_compression_mode", "mode"), &ENetMultiplayerPeer::set_compression_mode); + ClassDB::bind_method(D_METHOD("get_compression_mode"), &ENetMultiplayerPeer::get_compression_mode); + ClassDB::bind_method(D_METHOD("set_bind_ip", "ip"), &ENetMultiplayerPeer::set_bind_ip); + ClassDB::bind_method(D_METHOD("set_dtls_enabled", "enabled"), &ENetMultiplayerPeer::set_dtls_enabled); + ClassDB::bind_method(D_METHOD("is_dtls_enabled"), &ENetMultiplayerPeer::is_dtls_enabled); + ClassDB::bind_method(D_METHOD("set_dtls_key", "key"), &ENetMultiplayerPeer::set_dtls_key); + ClassDB::bind_method(D_METHOD("set_dtls_certificate", "certificate"), &ENetMultiplayerPeer::set_dtls_certificate); + ClassDB::bind_method(D_METHOD("set_dtls_verify_enabled", "enabled"), &ENetMultiplayerPeer::set_dtls_verify_enabled); + ClassDB::bind_method(D_METHOD("is_dtls_verify_enabled"), &ENetMultiplayerPeer::is_dtls_verify_enabled); + ClassDB::bind_method(D_METHOD("get_peer_address", "id"), &ENetMultiplayerPeer::get_peer_address); + ClassDB::bind_method(D_METHOD("get_peer_port", "id"), &ENetMultiplayerPeer::get_peer_port); + ClassDB::bind_method(D_METHOD("get_local_port"), &ENetMultiplayerPeer::get_local_port); + ClassDB::bind_method(D_METHOD("set_peer_timeout", "id", "timeout_limit", "timeout_min", "timeout_max"), &ENetMultiplayerPeer::set_peer_timeout); + + ClassDB::bind_method(D_METHOD("get_packet_channel"), &ENetMultiplayerPeer::get_packet_channel); + ClassDB::bind_method(D_METHOD("get_last_packet_channel"), &ENetMultiplayerPeer::get_last_packet_channel); + ClassDB::bind_method(D_METHOD("set_transfer_channel", "channel"), &ENetMultiplayerPeer::set_transfer_channel); + ClassDB::bind_method(D_METHOD("get_transfer_channel"), &ENetMultiplayerPeer::get_transfer_channel); + ClassDB::bind_method(D_METHOD("set_channel_count", "channels"), &ENetMultiplayerPeer::set_channel_count); + ClassDB::bind_method(D_METHOD("get_channel_count"), &ENetMultiplayerPeer::get_channel_count); + ClassDB::bind_method(D_METHOD("set_always_ordered", "ordered"), &ENetMultiplayerPeer::set_always_ordered); + ClassDB::bind_method(D_METHOD("is_always_ordered"), &ENetMultiplayerPeer::is_always_ordered); + ClassDB::bind_method(D_METHOD("set_server_relay_enabled", "enabled"), &ENetMultiplayerPeer::set_server_relay_enabled); + ClassDB::bind_method(D_METHOD("is_server_relay_enabled"), &ENetMultiplayerPeer::is_server_relay_enabled); ADD_PROPERTY(PropertyInfo(Variant::INT, "compression_mode", PROPERTY_HINT_ENUM, "None,Range Coder,FastLZ,ZLib,ZStd"), "set_compression_mode", "get_compression_mode"); ADD_PROPERTY(PropertyInfo(Variant::INT, "transfer_channel"), "set_transfer_channel", "get_transfer_channel"); @@ -874,7 +874,7 @@ void NetworkedMultiplayerENet::_bind_methods() { BIND_ENUM_CONSTANT(COMPRESS_ZSTD); } -NetworkedMultiplayerENet::NetworkedMultiplayerENet() { +ENetMultiplayerPeer::ENetMultiplayerPeer() { enet_compressor.context = this; enet_compressor.compress = enet_compress; enet_compressor.decompress = enet_decompress; @@ -883,7 +883,7 @@ NetworkedMultiplayerENet::NetworkedMultiplayerENet() { bind_ip = IPAddress("*"); } -NetworkedMultiplayerENet::~NetworkedMultiplayerENet() { +ENetMultiplayerPeer::~ENetMultiplayerPeer() { if (active) { close_connection(); } @@ -891,36 +891,36 @@ NetworkedMultiplayerENet::~NetworkedMultiplayerENet() { // Sets IP for ENet to bind when using create_server or create_client // if no IP is set, then ENet bind to ENET_HOST_ANY -void NetworkedMultiplayerENet::set_bind_ip(const IPAddress &p_ip) { +void ENetMultiplayerPeer::set_bind_ip(const IPAddress &p_ip) { ERR_FAIL_COND_MSG(!p_ip.is_valid() && !p_ip.is_wildcard(), vformat("Invalid bind IP address: %s", String(p_ip))); bind_ip = p_ip; } -void NetworkedMultiplayerENet::set_dtls_enabled(bool p_enabled) { +void ENetMultiplayerPeer::set_dtls_enabled(bool p_enabled) { ERR_FAIL_COND(active); dtls_enabled = p_enabled; } -bool NetworkedMultiplayerENet::is_dtls_enabled() const { +bool ENetMultiplayerPeer::is_dtls_enabled() const { return dtls_enabled; } -void NetworkedMultiplayerENet::set_dtls_verify_enabled(bool p_enabled) { +void ENetMultiplayerPeer::set_dtls_verify_enabled(bool p_enabled) { ERR_FAIL_COND(active); dtls_verify = p_enabled; } -bool NetworkedMultiplayerENet::is_dtls_verify_enabled() const { +bool ENetMultiplayerPeer::is_dtls_verify_enabled() const { return dtls_verify; } -void NetworkedMultiplayerENet::set_dtls_key(Ref<CryptoKey> p_key) { +void ENetMultiplayerPeer::set_dtls_key(Ref<CryptoKey> p_key) { ERR_FAIL_COND(active); dtls_key = p_key; } -void NetworkedMultiplayerENet::set_dtls_certificate(Ref<X509Certificate> p_cert) { +void ENetMultiplayerPeer::set_dtls_certificate(Ref<X509Certificate> p_cert) { ERR_FAIL_COND(active); dtls_cert = p_cert; } diff --git a/modules/enet/networked_multiplayer_enet.h b/modules/enet/enet_multiplayer_peer.h index 2d928859fa..e6d45eb16a 100644 --- a/modules/enet/networked_multiplayer_enet.h +++ b/modules/enet/enet_multiplayer_peer.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* networked_multiplayer_enet.h */ +/* enet_multiplayer_peer.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -33,12 +33,12 @@ #include "core/crypto/crypto.h" #include "core/io/compression.h" -#include "core/io/networked_multiplayer_peer.h" +#include "core/io/multiplayer_peer.h" #include <enet/enet.h> -class NetworkedMultiplayerENet : public NetworkedMultiplayerPeer { - GDCLASS(NetworkedMultiplayerENet, NetworkedMultiplayerPeer); +class ENetMultiplayerPeer : public MultiplayerPeer { + GDCLASS(ENetMultiplayerPeer, MultiplayerPeer); public: enum CompressionMode { @@ -168,8 +168,8 @@ public: void set_server_relay_enabled(bool p_enabled); bool is_server_relay_enabled() const; - NetworkedMultiplayerENet(); - ~NetworkedMultiplayerENet(); + ENetMultiplayerPeer(); + ~ENetMultiplayerPeer(); void set_bind_ip(const IPAddress &p_ip); void set_dtls_enabled(bool p_enabled); @@ -180,6 +180,6 @@ public: void set_dtls_certificate(Ref<X509Certificate> p_cert); }; -VARIANT_ENUM_CAST(NetworkedMultiplayerENet::CompressionMode); +VARIANT_ENUM_CAST(ENetMultiplayerPeer::CompressionMode); #endif // NETWORKED_MULTIPLAYER_ENET_H diff --git a/modules/enet/register_types.cpp b/modules/enet/register_types.cpp index 8da2d17e13..7a32903d76 100644 --- a/modules/enet/register_types.cpp +++ b/modules/enet/register_types.cpp @@ -30,7 +30,7 @@ #include "register_types.h" #include "core/error/error_macros.h" -#include "networked_multiplayer_enet.h" +#include "enet_multiplayer_peer.h" static bool enet_ok = false; @@ -41,7 +41,7 @@ void register_enet_types() { enet_ok = true; } - ClassDB::register_class<NetworkedMultiplayerENet>(); + ClassDB::register_class<ENetMultiplayerPeer>(); } void unregister_enet_types() { diff --git a/modules/fbx/data/fbx_material.cpp b/modules/fbx/data/fbx_material.cpp index d54ac86e9f..cf5d70fa5b 100644 --- a/modules/fbx/data/fbx_material.cpp +++ b/modules/fbx/data/fbx_material.cpp @@ -160,7 +160,7 @@ Ref<StandardMaterial3D> FBXMaterial::import_material(ImportState &state) { const String p_fbx_current_directory = state.path; Ref<StandardMaterial3D> spatial_material; - spatial_material.instance(); + spatial_material.instantiate(); // read the material file // is material two sided @@ -223,7 +223,7 @@ Ref<StandardMaterial3D> FBXMaterial::import_material(ImportState &state) { } else if (fbx_texture_data != nullptr && fbx_texture_data->Media() != nullptr && fbx_texture_data->Media()->IsEmbedded()) { // This is an embedded texture. Extract it. Ref<Image> image; - //image.instance(); // oooo double instance bug? why make Image::_png_blah call + //image.instantiate(); // oooo double instance bug? why make Image::_png_blah call const String extension = texture_name.get_extension().to_upper(); if (extension == "PNG") { @@ -256,7 +256,7 @@ Ref<StandardMaterial3D> FBXMaterial::import_material(ImportState &state) { } Ref<ImageTexture> image_texture; - image_texture.instance(); + image_texture.instantiate(); image_texture->create_from_image(image); texture = image_texture; @@ -324,7 +324,7 @@ Ref<StandardMaterial3D> FBXMaterial::import_material(ImportState &state) { if (spatial_material.is_null()) { // Done here so if no data no material is created. - spatial_material.instance(); + spatial_material.instantiate(); } const FBXDocParser::TypedProperty<real_t> *real_value = dynamic_cast<const FBXDocParser::TypedProperty<real_t> *>(prop); @@ -420,7 +420,7 @@ Ref<StandardMaterial3D> FBXMaterial::import_material(ImportState &state) { } break; case PROPERTY_DESC_COAT_ROUGHNESS: { // meaning is that approx equal to zero is disabled not actually zero. ;) - if (real_value && Math::is_equal_approx(real_value->Value(), 0.0f)) { + if (real_value && Math::is_zero_approx(real_value->Value())) { print_verbose("clearcoat real value: " + rtos(real_value->Value())); spatial_material->set_clearcoat_gloss(1.0 - real_value->Value()); } else { @@ -428,7 +428,7 @@ Ref<StandardMaterial3D> FBXMaterial::import_material(ImportState &state) { } } break; case PROPERTY_DESC_EMISSIVE: { - if (real_value && Math::is_equal_approx(real_value->Value(), 0.0f)) { + if (real_value && Math::is_zero_approx(real_value->Value())) { print_verbose("Emissive real value: " + rtos(real_value->Value())); spatial_material->set_emission_energy(real_value->Value()); } else if (vector_value && !vector_value->Value().is_equal_approx(Vector3(0, 0, 0))) { diff --git a/modules/fbx/data/fbx_mesh_data.cpp b/modules/fbx/data/fbx_mesh_data.cpp index 8f32c523f9..0d33b8e7c6 100644 --- a/modules/fbx/data/fbx_mesh_data.cpp +++ b/modules/fbx/data/fbx_mesh_data.cpp @@ -211,7 +211,7 @@ EditorSceneImporterMeshNode3D *FBXMeshData::create_fbx_mesh(const ImportState &s const int surface_id = polygon_surfaces[*polygon_id]; if (surfaces.has(surface_id) == false) { SurfaceData sd; - sd.surface_tool.instance(); + sd.surface_tool.instantiate(); sd.surface_tool->begin(Mesh::PRIMITIVE_TRIANGLES); if (surface_id < 0) { @@ -316,7 +316,7 @@ EditorSceneImporterMeshNode3D *FBXMeshData::create_fbx_mesh(const ImportState &s Vector3 *normals_ptr = morph_data->normals.ptrw(); Ref<SurfaceTool> morph_st; - morph_st.instance(); + morph_st.instantiate(); morph_st->begin(Mesh::PRIMITIVE_TRIANGLES); for (unsigned int vi = 0; vi < surface->vertices_map.size(); vi += 1) { @@ -345,7 +345,7 @@ EditorSceneImporterMeshNode3D *FBXMeshData::create_fbx_mesh(const ImportState &s // Phase 6. Compose the mesh and return it. Ref<EditorSceneImporterMesh> mesh; - mesh.instance(); + mesh.instantiate(); // Add blend shape info. for (const String *morph_name = morphs.next(nullptr); morph_name != nullptr; morph_name = morphs.next(morph_name)) { diff --git a/modules/fbx/editor_scene_importer_fbx.cpp b/modules/fbx/editor_scene_importer_fbx.cpp index 40deaae74d..e3f36ef3e3 100644 --- a/modules/fbx/editor_scene_importer_fbx.cpp +++ b/modules/fbx/editor_scene_importer_fbx.cpp @@ -373,7 +373,7 @@ Node3D *EditorSceneImporterFBX::_generate_scene( scene_root->add_child(state.root); state.root->set_owner(scene_root); - state.fbx_root_node.instance(); + state.fbx_root_node.instantiate(); state.fbx_root_node->godot_node = state.root; // Size relative to cm. @@ -389,11 +389,11 @@ Node3D *EditorSceneImporterFBX::_generate_scene( // Enabled by default. state.enable_animation_import = true; Ref<FBXNode> root_node; - root_node.instance(); + root_node.instantiate(); // make sure fake noFBXDocParser::PropertyPtr ptrde always has a transform too ;) Ref<PivotTransform> pivot_transform; - pivot_transform.instance(); + pivot_transform.instantiate(); root_node->pivot_transform = pivot_transform; root_node->node_name = "root node"; root_node->current_node_id = 0; @@ -479,7 +479,7 @@ Node3D *EditorSceneImporterFBX::_generate_scene( if (state.renderer_mesh_data.has(mesh_id)) { mesh_vertex_data = state.renderer_mesh_data[mesh_id]; } else { - mesh_vertex_data.instance(); + mesh_vertex_data.instantiate(); state.renderer_mesh_data.insert(mesh_id, mesh_vertex_data); } @@ -535,7 +535,7 @@ Node3D *EditorSceneImporterFBX::_generate_scene( ERR_CONTINUE_MSG(!mat, "Could not convert fbx material by id: " + itos(material_id)); Ref<FBXMaterial> material; - material.instance(); + material.instantiate(); material->set_imported_material(mat); Ref<StandardMaterial3D> godot_material = material->import_material(state); @@ -575,7 +575,7 @@ Node3D *EditorSceneImporterFBX::_generate_scene( if (state.skeleton_map.has(armature_id)) { fbx_skeleton_inst = state.skeleton_map[armature_id]; } else { - fbx_skeleton_inst.instance(); + fbx_skeleton_inst.instantiate(); state.skeleton_map.insert(armature_id, fbx_skeleton_inst); } @@ -650,7 +650,7 @@ Node3D *EditorSceneImporterFBX::_generate_scene( if (state.renderer_mesh_data.has(mesh_id)) { mesh_data_precached = state.renderer_mesh_data[mesh_id]; } else { - mesh_data_precached.instance(); + mesh_data_precached.instantiate(); state.renderer_mesh_data.insert(mesh_id, mesh_data_precached); } @@ -735,7 +735,7 @@ Node3D *EditorSceneImporterFBX::_generate_scene( Ref<Skin> skin; if (!state.MeshSkins.has(mesh_id)) { print_verbose("Created new skin"); - skin.instance(); + skin.instantiate(); state.MeshSkins.insert(mesh_id, skin); } else { print_verbose("Grabbed skin"); @@ -848,7 +848,7 @@ Node3D *EditorSceneImporterFBX::_generate_scene( } Ref<Animation> animation; - animation.instance(); + animation.instantiate(); animation->set_name(animation_name); animation->set_length(duration); @@ -1312,7 +1312,7 @@ void EditorSceneImporterFBX::BuildDocumentBones(Ref<FBXBone> p_parent_bone, // declare our bone element reference (invalid, unless we create a bone in this step) // this lets us pass valid armature information into children objects and this is why we moved this up here - // previously this was created .instanced() on the same line. + // previously this was created .instantiated() on the same line. Ref<FBXBone> bone_element; if (model != nullptr) { @@ -1324,7 +1324,7 @@ void EditorSceneImporterFBX::BuildDocumentBones(Ref<FBXBone> p_parent_bone, ERR_FAIL_COND_MSG(state.fbx_bone_map.has(limb_node->ID()), "[serious] duplicate LimbNode detected"); bool parent_is_bone = state.fbx_bone_map.find(p_id); - bone_element.instance(); + bone_element.instantiate(); // used to build the bone hierarchy in the skeleton bone_element->parent_bone_id = parent_is_bone ? p_id : 0; @@ -1404,12 +1404,12 @@ void EditorSceneImporterFBX::BuildDocumentNodes( uint64_t current_node_id = model->ID(); Ref<FBXNode> new_node; - new_node.instance(); + new_node.instantiate(); new_node->current_node_id = current_node_id; new_node->node_name = ImportUtils::FBXNodeToName(model->Name()); Ref<PivotTransform> fbx_transform; - fbx_transform.instance(); + fbx_transform.instantiate(); fbx_transform->set_parent(parent_transform); fbx_transform->set_model(model); fbx_transform->debug_pivot_xform("name: " + new_node->node_name); diff --git a/modules/fbx/fbx_parser/FBXParser.cpp b/modules/fbx/fbx_parser/FBXParser.cpp index 163518d18f..a92b23f4ee 100644 --- a/modules/fbx/fbx_parser/FBXParser.cpp +++ b/modules/fbx/fbx_parser/FBXParser.cpp @@ -1167,7 +1167,7 @@ Transform3D ReadMatrix(const ElementPtr element) { // clean values to prevent any IBM damage on inverse() / affine_inverse() for (float &value : values) { - if (::Math::is_equal_approx(0, value)) { + if (::Math::is_zero_approx(value)) { value = 0; } } diff --git a/modules/fbx/register_types.cpp b/modules/fbx/register_types.cpp index c0591dbc77..b615c91cd2 100644 --- a/modules/fbx/register_types.cpp +++ b/modules/fbx/register_types.cpp @@ -36,7 +36,7 @@ #ifdef TOOLS_ENABLED static void _editor_init() { Ref<EditorSceneImporterFBX> import_fbx; - import_fbx.instance(); + import_fbx.instantiate(); ResourceImporterScene::get_singleton()->add_importer(import_fbx); } #endif diff --git a/modules/fbx/tools/import_utils.h b/modules/fbx/tools/import_utils.h index 7625f67256..fbe7dbd82f 100644 --- a/modules/fbx/tools/import_utils.h +++ b/modules/fbx/tools/import_utils.h @@ -137,15 +137,15 @@ public: static Vector3 safe_import_vector3(const Vector3 &p_vec) { Vector3 vector = p_vec; - if (Math::is_equal_approx(0, vector.x)) { + if (Math::is_zero_approx(vector.x)) { vector.x = 0; } - if (Math::is_equal_approx(0, vector.y)) { + if (Math::is_zero_approx(vector.y)) { vector.y = 0; } - if (Math::is_equal_approx(0, vector.z)) { + if (Math::is_zero_approx(vector.z)) { vector.z = 0; } return vector; @@ -317,7 +317,7 @@ public: // } // } else { // Ref<Image> img; - // img.instance(); + // img.instantiate(); // PoolByteArray arr; // uint32_t size = tex->mWidth * tex->mHeight; // arr.resize(size); @@ -362,7 +362,7 @@ public: // if (found) { // image_state.raw_image = AssimpUtils::load_image(state, state.assimp_scene, path); // if (image_state.raw_image.is_valid()) { - // image_state.texture.instance(); + // image_state.texture.instantiate(); // image_state.texture->create_from_image(image_state.raw_image); // image_state.texture->set_storage(ImageTexture::STORAGE_COMPRESS_LOSSY); // return true; diff --git a/modules/fbx/tools/validation_tools.h b/modules/fbx/tools/validation_tools.h index 6c15eb7e12..906a721045 100644 --- a/modules/fbx/tools/validation_tools.h +++ b/modules/fbx/tools/validation_tools.h @@ -34,8 +34,7 @@ #ifdef TOOLS_ENABLED #include "core/io/file_access.h" -#include "core/io/json.h" -#include "core/string/ustring.h" +#include "core/string/print_string.h" #include "core/templates/local_vector.h" #include "core/templates/map.h" diff --git a/modules/gdnative/doc_classes/MultiplayerPeerGDNative.xml b/modules/gdnative/doc_classes/MultiplayerPeerGDNative.xml index 9f33d32e81..b88f5e7e1e 100644 --- a/modules/gdnative/doc_classes/MultiplayerPeerGDNative.xml +++ b/modules/gdnative/doc_classes/MultiplayerPeerGDNative.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8" ?> -<class name="MultiplayerPeerGDNative" inherits="NetworkedMultiplayerPeer" version="4.0"> +<class name="MultiplayerPeerGDNative" inherits="MultiplayerPeer" version="4.0"> <brief_description> </brief_description> <description> diff --git a/modules/gdnative/gdnative.cpp b/modules/gdnative/gdnative.cpp index fa11132dd9..1ff591a87f 100644 --- a/modules/gdnative/gdnative.cpp +++ b/modules/gdnative/gdnative.cpp @@ -52,7 +52,7 @@ extern const godot_gdnative_core_api_struct api_struct; Map<String, Vector<Ref<GDNative>>> GDNativeLibrary::loaded_libraries; GDNativeLibrary::GDNativeLibrary() { - config_file.instance(); + config_file.instantiate(); symbol_prefix = default_symbol_prefix; load_once = default_load_once; @@ -112,7 +112,7 @@ bool GDNativeLibrary::_get(const StringName &p_name, Variant &r_property) const } void GDNativeLibrary::reset_state() { - config_file.instance(); + config_file.instantiate(); current_library_path = ""; current_dependencies.clear(); symbol_prefix = default_symbol_prefix; @@ -532,7 +532,7 @@ Error GDNative::get_symbol(StringName p_procedure_name, void *&r_handle, bool p_ RES GDNativeLibraryResourceLoader::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { Ref<GDNativeLibrary> lib; - lib.instance(); + lib.instantiate(); Ref<ConfigFile> config = lib->get_config_file(); diff --git a/modules/gdnative/gdnative_library_editor_plugin.cpp b/modules/gdnative/gdnative_library_editor_plugin.cpp index b4ac0d886e..bdbf151393 100644 --- a/modules/gdnative/gdnative_library_editor_plugin.cpp +++ b/modules/gdnative/gdnative_library_editor_plugin.cpp @@ -356,12 +356,12 @@ GDNativeLibraryEditor::GDNativeLibraryEditor() { tree->set_column_titles_visible(true); tree->set_columns(4); tree->set_column_expand(0, false); - tree->set_column_min_width(0, int(200 * EDSCALE)); + tree->set_column_custom_minimum_width(0, int(200 * EDSCALE)); tree->set_column_title(0, TTR("Platform")); tree->set_column_title(1, TTR("Dynamic Library")); tree->set_column_title(2, TTR("Dependencies")); tree->set_column_expand(3, false); - tree->set_column_min_width(3, int(110 * EDSCALE)); + tree->set_column_custom_minimum_width(3, int(110 * EDSCALE)); tree->connect("button_pressed", callable_mp(this, &GDNativeLibraryEditor::_on_item_button)); tree->connect("item_collapsed", callable_mp(this, &GDNativeLibraryEditor::_on_item_collapsed)); tree->connect("item_activated", callable_mp(this, &GDNativeLibraryEditor::_on_item_activated)); diff --git a/modules/gdnative/include/gdnative/variant.h b/modules/gdnative/include/gdnative/variant.h index dd4f76cf57..a88bd2878a 100644 --- a/modules/gdnative/include/gdnative/variant.h +++ b/modules/gdnative/include/gdnative/variant.h @@ -164,7 +164,7 @@ typedef void (*godot_validated_keyed_getter)(const godot_variant *p_base, const typedef bool (*godot_validated_keyed_checker)(const godot_variant *p_base, const godot_variant *p_key, bool *r_valid); typedef void (*godot_ptr_keyed_setter)(void *p_base, const void *p_key, const void *p_value); typedef void (*godot_ptr_keyed_getter)(const void *p_base, const void *p_key, void *r_value); -typedef bool (*godot_ptr_keyed_checker)(const godot_variant *p_base, const godot_variant *p_key); +typedef uint32_t (*godot_ptr_keyed_checker)(const godot_variant *p_base, const godot_variant *p_key); typedef void (*godot_validated_utility_function)(godot_variant *r_return, const godot_variant **p_arguments, int p_argument_count); typedef void (*godot_ptr_utility_function)(void *r_return, const void **p_arguments, int p_argument_count); diff --git a/modules/gdnative/include/net/godot_net.h b/modules/gdnative/include/net/godot_net.h index 2fa576a5bf..94e7739ef9 100644 --- a/modules/gdnative/include/net/godot_net.h +++ b/modules/gdnative/include/net/godot_net.h @@ -90,7 +90,7 @@ typedef struct { godot_int (*get_available_packet_count)(const void *); godot_int (*get_max_packet_size)(const void *); - /* This is NetworkedMultiplayerPeer */ + /* This is MultiplayerPeer */ void (*set_transfer_mode)(void *, godot_int); godot_int (*get_transfer_mode)(const void *); // 0 = broadcast, 1 = server, <0 = all but abs(value) diff --git a/modules/gdnative/include/pluginscript/godot_pluginscript.h b/modules/gdnative/include/pluginscript/godot_pluginscript.h index 34ed4f097d..02ee4066d0 100644 --- a/modules/gdnative/include/pluginscript/godot_pluginscript.h +++ b/modules/gdnative/include/pluginscript/godot_pluginscript.h @@ -132,7 +132,7 @@ typedef struct { godot_bool can_inherit_from_file; godot_string (*get_template_source_code)(godot_pluginscript_language_data *p_data, const godot_string *p_class_name, const godot_string *p_base_class_name); - godot_bool (*validate)(godot_pluginscript_language_data *p_data, const godot_string *p_script, int *r_line_error, int *r_col_error, godot_string *r_test_error, const godot_string *p_path, godot_packed_string_array *r_functions); + godot_bool (*validate)(godot_pluginscript_language_data *p_data, const godot_string *p_script, const godot_string *p_path, godot_packed_string_array *r_functions, godot_array *r_errors); // errors = Array of Dictionary with "line", "column", "message" keys int (*find_function)(godot_pluginscript_language_data *p_data, const godot_string *p_function, const godot_string *p_code); // Can be nullptr godot_string (*make_function)(godot_pluginscript_language_data *p_data, const godot_string *p_class, const godot_string *p_name, const godot_packed_string_array *p_args); godot_error (*complete_code)(godot_pluginscript_language_data *p_data, const godot_string *p_code, const godot_string *p_path, godot_object *p_owner, godot_array *r_options, godot_bool *r_force, godot_string *r_call_hint); diff --git a/modules/gdnative/nativescript/api_generator.cpp b/modules/gdnative/nativescript/api_generator.cpp index 57717010f7..477bc9f74d 100644 --- a/modules/gdnative/nativescript/api_generator.cpp +++ b/modules/gdnative/nativescript/api_generator.cpp @@ -251,7 +251,7 @@ List<ClassAPI> generate_c_api_classes() { class_api.singleton_name = name; } } - class_api.is_instantiable = !class_api.is_singleton && ClassDB::can_instance(class_name); + class_api.is_instantiable = !class_api.is_singleton && ClassDB::can_instantiate(class_name); { List<StringName> inheriters; @@ -405,7 +405,7 @@ List<ClassAPI> generate_c_api_classes() { arg_type = Variant::get_type_name(arg_info.type); } } else { - arg_type = Variant::get_type_name(arg_info.type); + arg_type = get_type_name(arg_info); } method_api.argument_names.push_back(arg_name); diff --git a/modules/gdnative/nativescript/godot_nativescript.cpp b/modules/gdnative/nativescript/godot_nativescript.cpp index b10a747568..70b14836bf 100644 --- a/modules/gdnative/nativescript/godot_nativescript.cpp +++ b/modules/gdnative/nativescript/godot_nativescript.cpp @@ -332,7 +332,7 @@ void GDAPI godot_nativescript_unregister_instance_binding_data_functions(int p_i } void GDAPI *godot_nativescript_get_instance_binding_data(int p_idx, godot_object *p_object) { - return NativeScriptLanguage::get_singleton()->get_instance_binding_data(p_idx, (Object *)p_object); + return nullptr; } void GDAPI godot_nativescript_profiling_add_data(const char *p_signature, uint64_t p_time) { diff --git a/modules/gdnative/nativescript/nativescript.cpp b/modules/gdnative/nativescript/nativescript.cpp index 6c2d038654..d7943827c2 100644 --- a/modules/gdnative/nativescript/nativescript.cpp +++ b/modules/gdnative/nativescript/nativescript.cpp @@ -170,7 +170,7 @@ String NativeScript::get_script_class_icon_path() const { return script_class_icon_path; } -bool NativeScript::can_instance() const { +bool NativeScript::can_instantiate() const { NativeScriptDesc *script_data = get_script_desc(); #ifdef TOOLS_ENABLED @@ -503,7 +503,7 @@ Variant NativeScript::_new(const Variant **p_args, int p_argcount, Callable::Cal Object *owner = nullptr; if (!(script_data->base_native_type == "")) { - owner = ClassDB::instance(script_data->base_native_type); + owner = ClassDB::instantiate(script_data->base_native_type); } else { owner = memnew(RefCounted); } @@ -1035,7 +1035,7 @@ Ref<Script> NativeScriptLanguage::get_template(const String &p_class_name, const return Ref<NativeScript>(s); } -bool NativeScriptLanguage::validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path, List<String> *r_functions, List<ScriptLanguage::Warning> *r_warnings, Set<int> *r_safe_lines) const { +bool NativeScriptLanguage::validate(const String &p_script, const String &p_path, List<String> *r_functions, List<ScriptLanguage::ScriptError> *r_errors, List<ScriptLanguage::Warning> *r_warnings, Set<int> *r_safe_lines) const { return true; } @@ -1258,6 +1258,8 @@ void NativeScriptLanguage::unregister_binding_functions(int p_idx) { } void *NativeScriptLanguage::get_instance_binding_data(int p_idx, Object *p_object) { + return nullptr; +#if 0 ERR_FAIL_INDEX_V(p_idx, binding_functions.size(), nullptr); ERR_FAIL_COND_V_MSG(!binding_functions[p_idx].first, nullptr, "Tried to get binding data for a nativescript binding that does not exist."); @@ -1287,9 +1289,12 @@ void *NativeScriptLanguage::get_instance_binding_data(int p_idx, Object *p_objec } return (*binding_data)[p_idx]; +#endif } void *NativeScriptLanguage::alloc_instance_binding_data(Object *p_object) { + return nullptr; +#if 0 Vector<void *> *binding_data = new Vector<void *>; binding_data->resize(binding_functions.size()); @@ -1301,9 +1306,11 @@ void *NativeScriptLanguage::alloc_instance_binding_data(Object *p_object) { binding_instances.insert(binding_data); return (void *)binding_data; +#endif } void NativeScriptLanguage::free_instance_binding_data(void *p_data) { +#if 0 if (!p_data) { return; } @@ -1323,9 +1330,11 @@ void NativeScriptLanguage::free_instance_binding_data(void *p_data) { binding_instances.erase(&binding_data); delete &binding_data; +#endif } void NativeScriptLanguage::refcount_incremented_instance_binding(Object *p_object) { +#if 0 void *data = p_object->get_script_instance_binding(lang_idx); if (!data) { @@ -1347,9 +1356,11 @@ void NativeScriptLanguage::refcount_incremented_instance_binding(Object *p_objec binding_functions[i].second.refcount_incremented_instance_binding(binding_data[i], p_object); } } +#endif } bool NativeScriptLanguage::refcount_decremented_instance_binding(Object *p_object) { +#if 0 void *data = p_object->get_script_instance_binding(lang_idx); if (!data) { @@ -1375,6 +1386,8 @@ bool NativeScriptLanguage::refcount_decremented_instance_binding(Object *p_objec } return can_die; +#endif + return false; } void NativeScriptLanguage::set_global_type_tag(int p_idx, StringName p_class_name, const void *p_type_tag) { @@ -1422,7 +1435,7 @@ void NativeScriptLanguage::init_library(const Ref<GDNativeLibrary> &lib) { if (!E) { Ref<GDNative> gdn; - gdn.instance(); + gdn.instantiate(); gdn->set_library(lib); // TODO check the return value? diff --git a/modules/gdnative/nativescript/nativescript.h b/modules/gdnative/nativescript/nativescript.h index 1756321281..777a878660 100644 --- a/modules/gdnative/nativescript/nativescript.h +++ b/modules/gdnative/nativescript/nativescript.h @@ -137,7 +137,7 @@ public: void set_script_class_icon_path(String p_icon_path); String get_script_class_icon_path() const; - virtual bool can_instance() const override; + virtual bool can_instantiate() const override; virtual Ref<Script> get_base_script() const override; //for script inheritance @@ -317,7 +317,7 @@ public: virtual void get_comment_delimiters(List<String> *p_delimiters) const; virtual void get_string_delimiters(List<String> *p_delimiters) const; virtual Ref<Script> get_template(const String &p_class_name, const String &p_base_class_name) const; - virtual bool validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path, List<String> *r_functions, List<ScriptLanguage::Warning> *r_warnings = nullptr, Set<int> *r_safe_lines = nullptr) const; + virtual bool validate(const String &p_script, const String &p_path, List<String> *r_functions, List<ScriptLanguage::ScriptError> *r_errors = nullptr, List<ScriptLanguage::Warning> *r_warnings = nullptr, Set<int> *r_safe_lines = nullptr) const; virtual Script *create_script() const; virtual bool has_named_classes() const; virtual bool supports_builtin_mode() const; diff --git a/modules/gdnative/nativescript/register_types.cpp b/modules/gdnative/nativescript/register_types.cpp index 0353ab2092..0191cfd809 100644 --- a/modules/gdnative/nativescript/register_types.cpp +++ b/modules/gdnative/nativescript/register_types.cpp @@ -50,10 +50,10 @@ void register_nativescript_types() { native_script_language->set_language_index(ScriptServer::get_language_count()); ScriptServer::register_language(native_script_language); - resource_saver_gdns.instance(); + resource_saver_gdns.instantiate(); ResourceSaver::add_resource_format_saver(resource_saver_gdns); - resource_loader_gdns.instance(); + resource_loader_gdns.instantiate(); ResourceLoader::add_resource_format_loader(resource_loader_gdns); } diff --git a/modules/gdnative/net/multiplayer_peer_gdnative.cpp b/modules/gdnative/net/multiplayer_peer_gdnative.cpp index 8b5fc8db5c..8ceba0f339 100644 --- a/modules/gdnative/net/multiplayer_peer_gdnative.cpp +++ b/modules/gdnative/net/multiplayer_peer_gdnative.cpp @@ -61,13 +61,13 @@ int MultiplayerPeerGDNative::get_available_packet_count() const { return interface->get_available_packet_count(interface->data); } -/* NetworkedMultiplayerPeer */ +/* MultiplayerPeer */ void MultiplayerPeerGDNative::set_transfer_mode(TransferMode p_mode) { ERR_FAIL_COND(interface == nullptr); interface->set_transfer_mode(interface->data, (godot_int)p_mode); } -NetworkedMultiplayerPeer::TransferMode MultiplayerPeerGDNative::get_transfer_mode() const { +MultiplayerPeer::TransferMode MultiplayerPeerGDNative::get_transfer_mode() const { ERR_FAIL_COND_V(interface == nullptr, TRANSFER_MODE_UNRELIABLE); return (TransferMode)interface->get_transfer_mode(interface->data); } @@ -107,7 +107,7 @@ bool MultiplayerPeerGDNative::is_refusing_new_connections() const { return interface->is_refusing_new_connections(interface->data); } -NetworkedMultiplayerPeer::ConnectionStatus MultiplayerPeerGDNative::get_connection_status() const { +MultiplayerPeer::ConnectionStatus MultiplayerPeerGDNative::get_connection_status() const { ERR_FAIL_COND_V(interface == nullptr, CONNECTION_DISCONNECTED); return (ConnectionStatus)interface->get_connection_status(interface->data); } diff --git a/modules/gdnative/net/multiplayer_peer_gdnative.h b/modules/gdnative/net/multiplayer_peer_gdnative.h index 593b2534dd..7c10ab77f7 100644 --- a/modules/gdnative/net/multiplayer_peer_gdnative.h +++ b/modules/gdnative/net/multiplayer_peer_gdnative.h @@ -31,12 +31,12 @@ #ifndef MULTIPLAYER_PEER_GDNATIVE_H #define MULTIPLAYER_PEER_GDNATIVE_H -#include "core/io/networked_multiplayer_peer.h" +#include "core/io/multiplayer_peer.h" #include "modules/gdnative/gdnative.h" #include "modules/gdnative/include/net/godot_net.h" -class MultiplayerPeerGDNative : public NetworkedMultiplayerPeer { - GDCLASS(MultiplayerPeerGDNative, NetworkedMultiplayerPeer); +class MultiplayerPeerGDNative : public MultiplayerPeer { + GDCLASS(MultiplayerPeerGDNative, MultiplayerPeer); protected: static void _bind_methods(); @@ -55,7 +55,7 @@ public: virtual int get_max_packet_size() const override; virtual int get_available_packet_count() const override; - /* Specific to NetworkedMultiplayerPeer */ + /* Specific to MultiplayerPeer */ virtual void set_transfer_mode(TransferMode p_mode) override; virtual TransferMode get_transfer_mode() const override; virtual void set_target_peer(int p_peer_id) override; diff --git a/modules/gdnative/pluginscript/pluginscript_language.cpp b/modules/gdnative/pluginscript/pluginscript_language.cpp index 0291ae560b..79aba342c9 100644 --- a/modules/gdnative/pluginscript/pluginscript_language.cpp +++ b/modules/gdnative/pluginscript/pluginscript_language.cpp @@ -112,20 +112,29 @@ Ref<Script> PluginScriptLanguage::get_template(const String &p_class_name, const return script; } -bool PluginScriptLanguage::validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path, List<String> *r_functions, List<ScriptLanguage::Warning> *r_warnings, Set<int> *r_safe_lines) const { +bool PluginScriptLanguage::validate(const String &p_script, const String &p_path, List<String> *r_functions, List<ScriptLanguage::ScriptError> *r_errors, List<ScriptLanguage::Warning> *r_warnings, Set<int> *r_safe_lines) const { PackedStringArray functions; + Array errors; if (_desc.validate) { bool ret = _desc.validate( _data, (godot_string *)&p_script, - &r_line_error, - &r_col_error, - (godot_string *)&r_test_error, (godot_string *)&p_path, - (godot_packed_string_array *)&functions); + (godot_packed_string_array *)&functions, + (godot_array *)&errors); for (int i = 0; i < functions.size(); i++) { r_functions->push_back(functions[i]); } + if (r_errors) { + for (int i = 0; i < errors.size(); i++) { + Dictionary error = errors[i]; + ScriptLanguage::ScriptError e; + e.line = error["line"]; + e.column = error["column"]; + e.message = error["message"]; + r_errors->push_back(e); + } + } return ret; } return true; diff --git a/modules/gdnative/pluginscript/pluginscript_language.h b/modules/gdnative/pluginscript/pluginscript_language.h index 957bf355ca..26ab4a95e3 100644 --- a/modules/gdnative/pluginscript/pluginscript_language.h +++ b/modules/gdnative/pluginscript/pluginscript_language.h @@ -75,7 +75,7 @@ public: virtual void get_comment_delimiters(List<String> *p_delimiters) const; virtual void get_string_delimiters(List<String> *p_delimiters) const; virtual Ref<Script> get_template(const String &p_class_name, const String &p_base_class_name) const; - virtual bool validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path = "", List<String> *r_functions = nullptr, List<ScriptLanguage::Warning> *r_warnings = nullptr, Set<int> *r_safe_lines = nullptr) const; + virtual bool validate(const String &p_script, const String &p_path = "", List<String> *r_functions = nullptr, List<ScriptLanguage::ScriptError> *r_errors = nullptr, List<ScriptLanguage::Warning> *r_warnings = nullptr, Set<int> *r_safe_lines = nullptr) const; virtual Script *create_script() const; virtual bool has_named_classes() const; virtual bool supports_builtin_mode() const; diff --git a/modules/gdnative/pluginscript/pluginscript_script.cpp b/modules/gdnative/pluginscript/pluginscript_script.cpp index 1dabb1db63..7fc8178e34 100644 --- a/modules/gdnative/pluginscript/pluginscript_script.cpp +++ b/modules/gdnative/pluginscript/pluginscript_script.cpp @@ -38,13 +38,13 @@ #ifdef DEBUG_ENABLED #define __ASSERT_SCRIPT_REASON "Cannot retrieve PluginScript class for this script, is your code correct?" -#define ASSERT_SCRIPT_VALID() \ - { \ - ERR_FAIL_COND_MSG(!can_instance(), __ASSERT_SCRIPT_REASON); \ +#define ASSERT_SCRIPT_VALID() \ + { \ + ERR_FAIL_COND_MSG(!can_instantiate(), __ASSERT_SCRIPT_REASON); \ } -#define ASSERT_SCRIPT_VALID_V(ret) \ - { \ - ERR_FAIL_COND_V_MSG(!can_instance(), ret, __ASSERT_SCRIPT_REASON); \ +#define ASSERT_SCRIPT_VALID_V(ret) \ + { \ + ERR_FAIL_COND_V_MSG(!can_instantiate(), ret, __ASSERT_SCRIPT_REASON); \ } #else #define ASSERT_SCRIPT_VALID() @@ -96,7 +96,7 @@ Variant PluginScript::_new(const Variant **p_args, int p_argcount, Callable::Cal if (get_instance_base_type() == "") { owner = memnew(RefCounted); } else { - owner = ClassDB::instance(get_instance_base_type()); + owner = ClassDB::instantiate(get_instance_base_type()); } if (!owner) { @@ -133,7 +133,7 @@ void PluginScript::_placeholder_erased(PlaceHolderScriptInstance *p_placeholder) #endif -bool PluginScript::can_instance() const { +bool PluginScript::can_instantiate() const { bool can = _valid || (!_tool && !ScriptServer::is_scripting_enabled()); return can; } @@ -198,7 +198,7 @@ ScriptInstance *PluginScript::instance_create(Object *p_this) { StringName base_type = get_instance_base_type(); if (base_type) { if (!ClassDB::is_parent_class(p_this->get_class_name(), base_type)) { - String msg = "Script inherits from native type '" + String(base_type) + "', so it can't be instanced in object of type: '" + p_this->get_class() + "'"; + String msg = "Script inherits from native type '" + String(base_type) + "', so it can't be instantiated in object of type: '" + p_this->get_class() + "'"; // TODO: implement PluginscriptLanguage::debug_break_parse // if (EngineDebugger::is_active()) { // _language->debug_break_parse(get_path(), 0, msg); diff --git a/modules/gdnative/pluginscript/pluginscript_script.h b/modules/gdnative/pluginscript/pluginscript_script.h index 97989a19d8..838195147f 100644 --- a/modules/gdnative/pluginscript/pluginscript_script.h +++ b/modules/gdnative/pluginscript/pluginscript_script.h @@ -92,7 +92,7 @@ public: return _icon_path; } - virtual bool can_instance() const override; + virtual bool can_instantiate() const override; virtual Ref<Script> get_base_script() const override; //for script inheritance diff --git a/modules/gdnative/register_types.cpp b/modules/gdnative/register_types.cpp index cf19c0c44c..8e20a2b90d 100644 --- a/modules/gdnative/register_types.cpp +++ b/modules/gdnative/register_types.cpp @@ -230,7 +230,7 @@ static void editor_init_callback() { ProjectSettingsEditor::get_singleton()->get_tabs()->add_child(library_editor); Ref<GDNativeExportPlugin> export_plugin; - export_plugin.instance(); + export_plugin.instantiate(); EditorExport::get_singleton()->add_export_plugin(export_plugin); @@ -262,10 +262,10 @@ void register_gdnative_types() { ClassDB::register_class<GDNativeLibrary>(); ClassDB::register_class<GDNative>(); - resource_loader_gdnlib.instance(); + resource_loader_gdnlib.instantiate(); ResourceLoader::add_resource_format_loader(resource_loader_gdnlib); - resource_saver_gdnlib.instance(); + resource_saver_gdnlib.instantiate(); ResourceSaver::add_resource_format_saver(resource_saver_gdnlib); GDNativeCallRegistry::singleton = memnew(GDNativeCallRegistry); @@ -298,7 +298,7 @@ void register_gdnative_types() { Ref<GDNativeLibrary> lib = ResourceLoader::load(path); Ref<GDNative> singleton; - singleton.instance(); + singleton.instantiate(); singleton->set_library(lib); if (!singleton->initialize()) { diff --git a/modules/gdnative/videodecoder/register_types.cpp b/modules/gdnative/videodecoder/register_types.cpp index 394831daeb..e822d42312 100644 --- a/modules/gdnative/videodecoder/register_types.cpp +++ b/modules/gdnative/videodecoder/register_types.cpp @@ -36,7 +36,7 @@ static Ref<ResourceFormatLoaderVideoStreamGDNative> resource_loader_vsgdnative; void register_videodecoder_types() { - resource_loader_vsgdnative.instance(); + resource_loader_vsgdnative.instantiate(); ResourceLoader::add_resource_format_loader(resource_loader_vsgdnative, true); ClassDB::register_class<VideoStreamGDNative>(); diff --git a/modules/gdnative/videodecoder/video_stream_gdnative.cpp b/modules/gdnative/videodecoder/video_stream_gdnative.cpp index 8b0434c7dd..4c9bfb395d 100644 --- a/modules/gdnative/videodecoder/video_stream_gdnative.cpp +++ b/modules/gdnative/videodecoder/video_stream_gdnative.cpp @@ -122,7 +122,7 @@ bool VideoStreamPlaybackGDNative::open_file(const String &p_file) { samples_decoded = 0; Ref<Image> img; - img.instance(); + img.instantiate(); img->create((int)texture_size.width, false, (int)texture_size.height, Image::FORMAT_RGBA8); texture->create_from_image(img); @@ -185,7 +185,7 @@ void VideoStreamPlaybackGDNative::update_texture() { Ref<Image> img = memnew(Image(texture_size.width, texture_size.height, 0, Image::FORMAT_RGBA8, *pba)); - texture->update(img, true); + texture->update(img); } // ctor and dtor diff --git a/modules/gdnative/xr/xr_interface_gdnative.cpp b/modules/gdnative/xr/xr_interface_gdnative.cpp index ff959affa3..e51542e23d 100644 --- a/modules/gdnative/xr/xr_interface_gdnative.cpp +++ b/modules/gdnative/xr/xr_interface_gdnative.cpp @@ -258,7 +258,7 @@ void GDAPI godot_xr_register_interface(const godot_xr_interface_gdnative *p_inte ERR_FAIL_COND_MSG(p_interface->version.major < 4, "GDNative XR interfaces build for Godot 3.x are not supported."); Ref<XRInterfaceGDNative> new_interface; - new_interface.instance(); + new_interface.instantiate(); new_interface->set_interface((const godot_xr_interface_gdnative *)p_interface); XRServer::get_singleton()->add_interface(new_interface); } @@ -331,7 +331,7 @@ godot_int GDAPI godot_xr_add_controller(char *p_device_name, godot_int p_hand, g ERR_FAIL_NULL_V(input, 0); Ref<XRPositionalTracker> new_tracker; - new_tracker.instance(); + new_tracker.instantiate(); new_tracker->set_tracker_name(p_device_name); new_tracker->set_tracker_type(XRServer::TRACKER_CONTROLLER); if (p_hand == 1) { @@ -412,7 +412,7 @@ void GDAPI godot_xr_set_controller_button(godot_int p_controller_id, godot_int p if (tracker.is_valid()) { int joyid = tracker->get_joy_id(); if (joyid != -1) { - input->joy_button(joyid, p_button, p_is_pressed); + input->joy_button(joyid, (JoyButton)p_button, p_is_pressed); } } } @@ -431,7 +431,7 @@ void GDAPI godot_xr_set_controller_axis(godot_int p_controller_id, godot_int p_a Input::JoyAxisValue jx; jx.min = p_can_be_negative ? -1 : 0; jx.value = p_value; - input->joy_axis(joyid, p_axis, jx); + input->joy_axis(joyid, (JoyAxis)p_axis, jx); } } } diff --git a/modules/gdscript/doc_classes/@GDScript.xml b/modules/gdscript/doc_classes/@GDScript.xml index 58620f2b3e..839aa6b3c6 100644 --- a/modules/gdscript/doc_classes/@GDScript.xml +++ b/modules/gdscript/doc_classes/@GDScript.xml @@ -177,7 +177,7 @@ [b]Note:[/b] Resource paths can be obtained by right clicking on a resource in the Assets Panel and choosing "Copy Path" or by dragging the file from the FileSystem dock into the script. [codeblock] # Instance a scene. - var diamond = preload("res://diamond.tscn").instance() + var diamond = preload("res://diamond.tscn").instantiate() [/codeblock] </description> </method> diff --git a/modules/gdscript/editor/gdscript_highlighter.cpp b/modules/gdscript/editor/gdscript_highlighter.cpp index b867b03903..79ec9eb65f 100644 --- a/modules/gdscript/editor/gdscript_highlighter.cpp +++ b/modules/gdscript/editor/gdscript_highlighter.cpp @@ -622,6 +622,6 @@ void GDScriptSyntaxHighlighter::add_color_region(const String &p_start_key, cons Ref<EditorSyntaxHighlighter> GDScriptSyntaxHighlighter::_create() const { Ref<GDScriptSyntaxHighlighter> syntax_highlighter; - syntax_highlighter.instance(); + syntax_highlighter.instantiate(); return syntax_highlighter; } diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index 1567576009..8b12b1eae4 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -72,7 +72,7 @@ void GDScriptNativeClass::_bind_methods() { } Variant GDScriptNativeClass::_new() { - Object *o = instance(); + Object *o = instantiate(); ERR_FAIL_COND_V_MSG(!o, Variant(), "Class type: '" + String(name) + "' is not instantiable."); RefCounted *rc = Object::cast_to<RefCounted>(o); @@ -83,8 +83,8 @@ Variant GDScriptNativeClass::_new() { } } -Object *GDScriptNativeClass::instance() { - return ClassDB::instance(name); +Object *GDScriptNativeClass::instantiate() { + return ClassDB::instantiate(name); } void GDScript::_super_implicit_constructor(GDScript *p_script, GDScriptInstance *p_instance, Callable::CallError &r_error) { @@ -170,7 +170,7 @@ Variant GDScript::_new(const Variant **p_args, int p_argcount, Callable::CallErr ERR_FAIL_COND_V(_baseptr->native.is_null(), Variant()); if (_baseptr->native.ptr()) { - owner = _baseptr->native->instance(); + owner = _baseptr->native->instantiate(); } else { owner = memnew(RefCounted); //by default, no base means use reference } @@ -196,7 +196,7 @@ Variant GDScript::_new(const Variant **p_args, int p_argcount, Callable::CallErr } } -bool GDScript::can_instance() const { +bool GDScript::can_instantiate() const { #ifdef TOOLS_ENABLED return valid && (tool || ScriptServer::is_scripting_enabled()); #else @@ -346,9 +346,9 @@ ScriptInstance *GDScript::instance_create(Object *p_this) { if (top->native.is_valid()) { if (!ClassDB::is_parent_class(p_this->get_class_name(), top->native->get_name())) { if (EngineDebugger::is_active()) { - GDScriptLanguage::get_singleton()->debug_break_parse(get_path(), 1, "Script inherits from native type '" + String(top->native->get_name()) + "', so it can't be instanced in object of type: '" + p_this->get_class() + "'"); + GDScriptLanguage::get_singleton()->debug_break_parse(get_path(), 1, "Script inherits from native type '" + String(top->native->get_name()) + "', so it can't be instantiated in object of type: '" + p_this->get_class() + "'"); } - ERR_FAIL_V_MSG(nullptr, "Script inherits from native type '" + String(top->native->get_name()) + "', so it can't be instanced in object of type '" + p_this->get_class() + "'" + "."); + ERR_FAIL_V_MSG(nullptr, "Script inherits from native type '" + String(top->native->get_name()) + "', so it can't be instantiated in object of type '" + p_this->get_class() + "'" + "."); } } @@ -1170,7 +1170,7 @@ void GDScript::_init_rpc_methods_properties() { nd.name = E->key(); nd.rpc_mode = E->get()->get_rpc_mode(); // TODO - nd.transfer_mode = NetworkedMultiplayerPeer::TRANSFER_MODE_RELIABLE; + nd.transfer_mode = MultiplayerPeer::TRANSFER_MODE_RELIABLE; nd.channel = 0; if (-1 == rpc_functions.find(nd)) { rpc_functions.push_back(nd); @@ -2256,7 +2256,7 @@ RES ResourceFormatLoaderGDScript::load(const String &p_path, const String &p_ori if (script.is_null()) { // Don't fail loading because of parsing error. - script.instance(); + script.instantiate(); } if (r_error) { diff --git a/modules/gdscript/gdscript.h b/modules/gdscript/gdscript.h index 602553bb1a..078b7a2fd0 100644 --- a/modules/gdscript/gdscript.h +++ b/modules/gdscript/gdscript.h @@ -51,7 +51,7 @@ protected: public: _FORCE_INLINE_ const StringName &get_name() const { return name; } Variant _new(); - Object *instance(); + Object *instantiate(); GDScriptNativeClass(const StringName &p_name); }; @@ -80,10 +80,10 @@ class GDScript : public Script { GDScript *_base = nullptr; //fast pointer access GDScript *_owner = nullptr; //for subclasses - Set<StringName> members; //members are just indices to the instanced script. + Set<StringName> members; //members are just indices to the instantiated script. Map<StringName, Variant> constants; Map<StringName, GDScriptFunction *> member_functions; - Map<StringName, MemberInfo> member_indices; //members are just indices to the instanced script. + Map<StringName, MemberInfo> member_indices; //members are just indices to the instantiated script. Map<StringName, Ref<GDScript>> subclasses; Map<StringName, Vector<StringName>> _signals; Vector<MultiplayerAPI::RPCConfig> rpc_functions; @@ -196,7 +196,7 @@ public: StringName debug_get_member_by_index(int p_idx) const; Variant _new(const Variant **p_args, int p_argcount, Callable::CallError &r_error); - virtual bool can_instance() const override; + virtual bool can_instantiate() const override; virtual Ref<Script> get_base_script() const override; @@ -447,7 +447,7 @@ public: virtual Ref<Script> get_template(const String &p_class_name, const String &p_base_class_name) const; virtual bool is_using_templates(); virtual void make_template(const String &p_class_name, const String &p_base_class_name, Ref<Script> &p_script); - virtual bool validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path = "", List<String> *r_functions = nullptr, List<ScriptLanguage::Warning> *r_warnings = nullptr, Set<int> *r_safe_lines = nullptr) const; + virtual bool validate(const String &p_script, const String &p_path = "", List<String> *r_functions = nullptr, List<ScriptLanguage::ScriptError> *r_errors = nullptr, List<ScriptLanguage::Warning> *r_warnings = nullptr, Set<int> *r_safe_lines = nullptr) const; virtual Script *create_script() const; virtual bool has_named_classes() const; virtual bool supports_builtin_mode() const; diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp index 2c848cb1de..e7fb33a6a7 100644 --- a/modules/gdscript/gdscript_analyzer.cpp +++ b/modules/gdscript/gdscript_analyzer.cpp @@ -229,7 +229,7 @@ Error GDScriptAnalyzer::resolve_inheritance(GDScriptParser::ClassNode *p_class, push_error(vformat(R"(Could not resolve super class inheritance from "%s".)", name), p_class); return err; } - } else if (class_exists(name) && ClassDB::can_instance(GDScriptParser::get_real_class_name(name))) { + } else if (class_exists(name) && ClassDB::can_instantiate(GDScriptParser::get_real_class_name(name))) { base.kind = GDScriptParser::DataType::NATIVE; base.native_type = name; } else { @@ -3447,6 +3447,7 @@ GDScriptParser::DataType GDScriptAnalyzer::get_operation_type(Variant::Operator } r_valid = true; + result.type_source = GDScriptParser::DataType::ANNOTATED_INFERRED; result.kind = GDScriptParser::DataType::BUILTIN; result.builtin_type = Variant::get_operator_return_type(p_operation, a_type, b_type); diff --git a/modules/gdscript/gdscript_byte_codegen.cpp b/modules/gdscript/gdscript_byte_codegen.cpp index 6998cc5bb7..5a297cc50a 100644 --- a/modules/gdscript/gdscript_byte_codegen.cpp +++ b/modules/gdscript/gdscript_byte_codegen.cpp @@ -554,6 +554,14 @@ void GDScriptByteCodeGenerator::write_unary_operator(const Address &p_target, Va void GDScriptByteCodeGenerator::write_binary_operator(const Address &p_target, Variant::Operator p_operator, const Address &p_left_operand, const Address &p_right_operand) { if (HAS_BUILTIN_TYPE(p_left_operand) && HAS_BUILTIN_TYPE(p_right_operand)) { + if (p_target.mode == Address::TEMPORARY) { + Variant::Type result_type = Variant::get_operator_return_type(p_operator, p_left_operand.type.builtin_type, p_right_operand.type.builtin_type); + Variant::Type temp_type = temporaries[p_target.address].type; + if (result_type != temp_type) { + write_type_adjust(p_target, result_type); + } + } + // Gather specific operator. Variant::ValidatedOperatorEvaluator op_func = Variant::get_validated_operator_evaluator(p_operator, p_left_operand.type.builtin_type, p_right_operand.type.builtin_type); diff --git a/modules/gdscript/gdscript_cache.cpp b/modules/gdscript/gdscript_cache.cpp index a3b1fb93f9..1a844bf241 100644 --- a/modules/gdscript/gdscript_cache.cpp +++ b/modules/gdscript/gdscript_cache.cpp @@ -134,7 +134,7 @@ Ref<GDScriptParserRef> GDScriptCache::get_parser(const String &p_path, GDScriptP return ref; } GDScriptParser *parser = memnew(GDScriptParser); - ref.instance(); + ref.instantiate(); ref->parser = parser; ref->path = p_path; singleton->parser_map[p_path] = ref.ptr(); @@ -180,7 +180,7 @@ Ref<GDScript> GDScriptCache::get_shallow_script(const String &p_path, const Stri } Ref<GDScript> script; - script.instance(); + script.instantiate(); script->set_path(p_path, true); script->set_script_path(p_path); script->load_source_code(p_path); diff --git a/modules/gdscript/gdscript_compiler.cpp b/modules/gdscript/gdscript_compiler.cpp index 6d6b9e15af..7fa8e9c067 100644 --- a/modules/gdscript/gdscript_compiler.cpp +++ b/modules/gdscript/gdscript_compiler.cpp @@ -2587,7 +2587,7 @@ void GDScriptCompiler::_make_scripts(GDScript *p_script, const GDScriptParser::C if (orphan_subclass.is_valid()) { subclass = orphan_subclass; } else { - subclass.instance(); + subclass.instantiate(); } } diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp index 18b7810919..c1a7bedbc8 100644 --- a/modules/gdscript/gdscript_editor.cpp +++ b/modules/gdscript/gdscript_editor.cpp @@ -104,7 +104,7 @@ Ref<Script> GDScriptLanguage::get_template(const String &p_class_name, const Str _template = _get_processed_template(_template, p_base_class_name); Ref<GDScript> script; - script.instance(); + script.instantiate(); script->set_source_code(_template); return script; @@ -131,7 +131,7 @@ static void get_function_names_recursively(const GDScriptParser::ClassNode *p_cl } } -bool GDScriptLanguage::validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path, List<String> *r_functions, List<ScriptLanguage::Warning> *r_warnings, Set<int> *r_safe_lines) const { +bool GDScriptLanguage::validate(const String &p_script, const String &p_path, List<String> *r_functions, List<ScriptLanguage::ScriptError> *r_errors, List<ScriptLanguage::Warning> *r_warnings, Set<int> *r_safe_lines) const { GDScriptParser parser; GDScriptAnalyzer analyzer(&parser); @@ -156,10 +156,16 @@ bool GDScriptLanguage::validate(const String &p_script, int &r_line_error, int & } #endif if (err) { - GDScriptParser::ParserError parse_error = parser.get_errors().front()->get(); - r_line_error = parse_error.line; - r_col_error = parse_error.column; - r_test_error = parse_error.message; + if (r_errors) { + for (const List<GDScriptParser::ParserError>::Element *E = parser.get_errors().front(); E; E = E->next()) { + const GDScriptParser::ParserError &pe = E->get(); + ScriptLanguage::ScriptError e; + e.line = pe.line; + e.column = pe.column; + e.message = pe.message; + r_errors->push_back(e); + } + } return false; } else { const GDScriptParser::ClassNode *cl = parser.get_tree(); @@ -2378,7 +2384,7 @@ static void _find_call_arguments(GDScriptParser::CompletionContext &p_context, c r_forced = r_result.size() > 0; } -Error GDScriptLanguage::complete_code(const String &p_code, const String &p_path, Object *p_owner, List<ScriptCodeCompletionOption> *r_options, bool &r_forced, String &r_call_hint) { +::Error GDScriptLanguage::complete_code(const String &p_code, const String &p_path, Object *p_owner, List<ScriptCodeCompletionOption> *r_options, bool &r_forced, String &r_call_hint) { const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", false) ? "'" : "\""; GDScriptParser parser; @@ -2894,7 +2900,7 @@ static Error _lookup_symbol_from_base(const GDScriptParser::DataType &p_base, co Variant v; REF v_ref; if (base_type.builtin_type == Variant::OBJECT) { - v_ref.instance(); + v_ref.instantiate(); v = v_ref; } else { Callable::CallError err; @@ -2929,7 +2935,7 @@ static Error _lookup_symbol_from_base(const GDScriptParser::DataType &p_base, co return ERR_CANT_RESOLVE; } -Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol, const String &p_path, Object *p_owner, LookupResult &r_result) { +::Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol, const String &p_path, Object *p_owner, LookupResult &r_result) { //before parsing, try the usual stuff if (ClassDB::class_exists(p_symbol)) { r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS; @@ -3032,9 +3038,9 @@ Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol if (!is_function) { // Guess in autoloads as singletons. if (ProjectSettings::get_singleton()->has_autoload(p_symbol)) { - const ProjectSettings::AutoloadInfo &singleton = ProjectSettings::get_singleton()->get_autoload(p_symbol); - if (singleton.is_singleton) { - String script = singleton.path; + const ProjectSettings::AutoloadInfo &autoload = ProjectSettings::get_singleton()->get_autoload(p_symbol); + if (autoload.is_singleton) { + String script = autoload.path; if (!script.ends_with(".gd")) { // Not a script, try find the script anyway, // may have some success. diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index ba208ebfe8..1a22820c63 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -157,7 +157,6 @@ GDScriptParser::GDScriptParser() { register_annotation(MethodInfo("@export_multiline"), AnnotationInfo::VARIABLE, &GDScriptParser::export_annotations<PROPERTY_HINT_MULTILINE_TEXT, Variant::STRING>); register_annotation(MethodInfo("@export_placeholder"), AnnotationInfo::VARIABLE, &GDScriptParser::export_annotations<PROPERTY_HINT_PLACEHOLDER_TEXT, Variant::STRING>); register_annotation(MethodInfo("@export_range", { Variant::FLOAT, "min" }, { Variant::FLOAT, "max" }, { Variant::FLOAT, "step" }, { Variant::STRING, "slider1" }, { Variant::STRING, "slider2" }), AnnotationInfo::VARIABLE, &GDScriptParser::export_annotations<PROPERTY_HINT_RANGE, Variant::FLOAT>, 3); - register_annotation(MethodInfo("@export_exp_range", { Variant::FLOAT, "min" }, { Variant::FLOAT, "max" }, { Variant::FLOAT, "step" }, { Variant::STRING, "slider1" }, { Variant::STRING, "slider2" }), AnnotationInfo::VARIABLE, &GDScriptParser::export_annotations<PROPERTY_HINT_EXP_RANGE, Variant::FLOAT>, 3); register_annotation(MethodInfo("@export_exp_easing", { Variant::STRING, "hint1" }, { Variant::STRING, "hint2" }), AnnotationInfo::VARIABLE, &GDScriptParser::export_annotations<PROPERTY_HINT_EXP_EASING, Variant::FLOAT>, 2); register_annotation(MethodInfo("@export_color_no_alpha"), AnnotationInfo::VARIABLE, &GDScriptParser::export_annotations<PROPERTY_HINT_COLOR_NO_ALPHA, Variant::COLOR>); register_annotation(MethodInfo("@export_node_path", { Variant::STRING, "type" }), AnnotationInfo::VARIABLE, &GDScriptParser::export_annotations<PROPERTY_HINT_NODE_PATH_VALID_TYPES, Variant::NODE_PATH>, 1, true); diff --git a/modules/gdscript/language_server/gdscript_extend_parser.cpp b/modules/gdscript/language_server/gdscript_extend_parser.cpp index 15236d900d..f817964a3c 100644 --- a/modules/gdscript/language_server/gdscript_extend_parser.cpp +++ b/modules/gdscript/language_server/gdscript_extend_parser.cpp @@ -32,7 +32,6 @@ #include "../gdscript.h" #include "../gdscript_analyzer.h" -#include "core/io/json.h" #include "gdscript_language_protocol.h" #include "gdscript_workspace.h" @@ -183,7 +182,7 @@ void ExtendGDScriptParser::parse_class_symbol(const GDScriptParser::ClassNode *p symbol.detail += ": " + m.get_datatype().to_string(); } if (m.variable->initializer != nullptr && m.variable->initializer->is_constant) { - symbol.detail += " = " + JSON::print(m.variable->initializer->reduced_value); + symbol.detail += " = " + m.variable->initializer->reduced_value.to_json_string(); } symbol.documentation = parse_documentation(LINE_NUMBER_TO_INDEX(m.variable->start_line)); @@ -224,10 +223,10 @@ void ExtendGDScriptParser::parse_class_symbol(const GDScriptParser::ClassNode *p } } } else { - value_text = JSON::print(default_value); + value_text = default_value.to_json_string(); } } else { - value_text = JSON::print(default_value); + value_text = default_value.to_json_string(); } if (!value_text.is_empty()) { symbol.detail += " = " + value_text; @@ -353,8 +352,7 @@ void ExtendGDScriptParser::parse_function_symbol(const GDScriptParser::FunctionN parameters += ": " + parameter->get_datatype().to_string(); } if (parameter->default_value != nullptr) { - String value = JSON::print(parameter->default_value->reduced_value); - parameters += " = " + value; + parameters += " = " + parameter->default_value->reduced_value.to_json_string(); } } r_symbol.detail += parameters + ")"; diff --git a/modules/gdscript/language_server/gdscript_language_protocol.cpp b/modules/gdscript/language_server/gdscript_language_protocol.cpp index c16a7fa889..0d1f98778e 100644 --- a/modules/gdscript/language_server/gdscript_language_protocol.cpp +++ b/modules/gdscript/language_server/gdscript_language_protocol.cpp @@ -31,7 +31,6 @@ #include "gdscript_language_protocol.h" #include "core/config/project_settings.h" -#include "core/io/json.h" #include "editor/doc_tools.h" #include "editor/editor_log.h" #include "editor/editor_node.h" @@ -194,7 +193,7 @@ Dictionary GDScriptLanguageProtocol::initialize(const Dictionary &p_params) { vformat("GDScriptLanguageProtocol: Can't initialize invalid peer '%d'.", latest_client_id)); Ref<LSPeer> peer = clients.get(latest_client_id); if (peer != nullptr) { - String msg = JSON::print(request); + String msg = Variant(request).to_json_string(); msg = format_output(msg); (*peer)->res_queue.push_back(msg.utf8()); } @@ -280,7 +279,7 @@ void GDScriptLanguageProtocol::notify_client(const String &p_method, const Varia ERR_FAIL_COND(peer == nullptr); Dictionary message = make_notification(p_method, p_params); - String msg = JSON::print(message); + String msg = Variant(message).to_json_string(); msg = format_output(msg); peer->res_queue.push_back(msg.utf8()); } @@ -294,10 +293,10 @@ bool GDScriptLanguageProtocol::is_goto_native_symbols_enabled() const { } GDScriptLanguageProtocol::GDScriptLanguageProtocol() { - server.instance(); + server.instantiate(); singleton = this; - workspace.instance(); - text_document.instance(); + workspace.instantiate(); + text_document.instantiate(); set_scope("textDocument", text_document.ptr()); set_scope("completionItem", text_document.ptr()); set_scope("workspace", workspace.ptr()); diff --git a/modules/gdscript/language_server/gdscript_text_document.cpp b/modules/gdscript/language_server/gdscript_text_document.cpp index 030633274c..59d2e6c8fa 100644 --- a/modules/gdscript/language_server/gdscript_text_document.cpp +++ b/modules/gdscript/language_server/gdscript_text_document.cpp @@ -40,6 +40,7 @@ void GDScriptTextDocument::_bind_methods() { ClassDB::bind_method(D_METHOD("didOpen"), &GDScriptTextDocument::didOpen); + ClassDB::bind_method(D_METHOD("didClose"), &GDScriptTextDocument::didClose); ClassDB::bind_method(D_METHOD("didChange"), &GDScriptTextDocument::didChange); ClassDB::bind_method(D_METHOD("nativeSymbol"), &GDScriptTextDocument::nativeSymbol); ClassDB::bind_method(D_METHOD("documentSymbol"), &GDScriptTextDocument::documentSymbol); @@ -61,6 +62,11 @@ void GDScriptTextDocument::didOpen(const Variant &p_param) { sync_script_content(doc.uri, doc.text); } +void GDScriptTextDocument::didClose(const Variant &p_param) { + // Left empty on purpose. Godot does nothing special on closing a document, + // but it satisfies LSP clients that require didClose be implemented. +} + void GDScriptTextDocument::didChange(const Variant &p_param) { lsp::TextDocumentItem doc = load_document_item(p_param); Dictionary dict = p_param; diff --git a/modules/gdscript/language_server/gdscript_text_document.h b/modules/gdscript/language_server/gdscript_text_document.h index 17f1d5d5e3..e2987f779c 100644 --- a/modules/gdscript/language_server/gdscript_text_document.h +++ b/modules/gdscript/language_server/gdscript_text_document.h @@ -43,6 +43,7 @@ protected: FileAccess *file_checker; void didOpen(const Variant &p_param); + void didClose(const Variant &p_param); void didChange(const Variant &p_param); void sync_script_content(const String &p_path, const String &p_content); diff --git a/modules/gdscript/language_server/gdscript_workspace.cpp b/modules/gdscript/language_server/gdscript_workspace.cpp index d83f77ed82..1915c92cbf 100644 --- a/modules/gdscript/language_server/gdscript_workspace.cpp +++ b/modules/gdscript/language_server/gdscript_workspace.cpp @@ -426,7 +426,7 @@ Node *GDScriptWorkspace::_get_owner_scene_node(String p_path) { RES owner_res = ResourceLoader::load(owner_path); if (Object::cast_to<PackedScene>(owner_res.ptr())) { Ref<PackedScene> owner_packed_scene = Ref<PackedScene>(Object::cast_to<PackedScene>(*owner_res)); - owner_scene_node = owner_packed_scene->instance(); + owner_scene_node = owner_packed_scene->instantiate(); break; } } diff --git a/modules/gdscript/register_types.cpp b/modules/gdscript/register_types.cpp index 867142019f..ad4ed8bf71 100644 --- a/modules/gdscript/register_types.cpp +++ b/modules/gdscript/register_types.cpp @@ -92,12 +92,12 @@ public: static void _editor_init() { Ref<EditorExportGDScript> gd_export; - gd_export.instance(); + gd_export.instantiate(); EditorExport::get_singleton()->add_export_plugin(gd_export); #ifdef TOOLS_ENABLED Ref<GDScriptSyntaxHighlighter> gdscript_syntax_highlighter; - gdscript_syntax_highlighter.instance(); + gdscript_syntax_highlighter.instantiate(); ScriptEditor::get_singleton()->register_syntax_highlighter(gdscript_syntax_highlighter); #endif @@ -117,10 +117,10 @@ void register_gdscript_types() { script_language_gd = memnew(GDScriptLanguage); ScriptServer::register_language(script_language_gd); - resource_loader_gd.instance(); + resource_loader_gd.instantiate(); ResourceLoader::add_resource_format_loader(resource_loader_gd); - resource_saver_gd.instance(); + resource_saver_gd.instantiate(); ResourceSaver::add_resource_format_saver(resource_saver_gd); gdscript_cache = memnew(GDScriptCache); @@ -128,7 +128,7 @@ void register_gdscript_types() { #ifdef TOOLS_ENABLED EditorNode::add_init_callback(_editor_init); - gdscript_translation_parser_plugin.instance(); + gdscript_translation_parser_plugin.instantiate(); EditorTranslationParser::get_singleton()->add_parser(gdscript_translation_parser_plugin, EditorTranslationParser::STANDARD); #endif // TOOLS_ENABLED diff --git a/modules/gdscript/tests/gdscript_test_runner.cpp b/modules/gdscript/tests/gdscript_test_runner.cpp index 67bc927517..b7faebb4ef 100644 --- a/modules/gdscript/tests/gdscript_test_runner.cpp +++ b/modules/gdscript/tests/gdscript_test_runner.cpp @@ -75,14 +75,14 @@ void init_autoloads() { Node *n = nullptr; if (res->is_class("PackedScene")) { Ref<PackedScene> ps = res; - n = ps->instance(); + n = ps->instantiate(); } else if (res->is_class("Script")) { Ref<Script> script_res = res; StringName ibt = script_res->get_instance_base_type(); bool valid_type = ClassDB::is_parent_class(ibt, "Node"); ERR_CONTINUE_MSG(!valid_type, "Script does not inherit a Node: " + info.path); - Object *obj = ClassDB::instance(ibt); + Object *obj = ClassDB::instantiate(ibt); ERR_CONTINUE_MSG(obj == nullptr, "Cannot instance script for autoload, expected 'Node' inheritance, got: " + @@ -420,7 +420,7 @@ GDScriptTest::TestResult GDScriptTest::execute_test_code(bool p_is_generating) { // Create script. Ref<GDScript> script; - script.instance(); + script.instantiate(); script->set_path(source_file); script->set_script_path(source_file); err = script->load_source_code(source_file); @@ -510,7 +510,7 @@ GDScriptTest::TestResult GDScriptTest::execute_test_code(bool p_is_generating) { script->reload(); // Create object instance for test. - Object *obj = ClassDB::instance(script->get_native()->get_name()); + Object *obj = ClassDB::instantiate(script->get_native()->get_name()); Ref<RefCounted> obj_ref; if (obj->is_ref_counted()) { obj_ref = Ref<RefCounted>(Object::cast_to<RefCounted>(obj)); diff --git a/modules/gdscript/tests/test_gdscript.cpp b/modules/gdscript/tests/test_gdscript.cpp index c37d52febd..7aa5895981 100644 --- a/modules/gdscript/tests/test_gdscript.cpp +++ b/modules/gdscript/tests/test_gdscript.cpp @@ -165,7 +165,7 @@ static void test_compiler(const String &p_code, const String &p_script_path, con GDScriptCompiler compiler; Ref<GDScript> script; - script.instance(); + script.instantiate(); script->set_path(p_script_path); err = compiler.compile(&parser, script.ptr(), false); diff --git a/modules/gltf/editor_scene_exporter_gltf_plugin.cpp b/modules/gltf/editor_scene_exporter_gltf_plugin.cpp index 4cdaccde6f..ae080bcc9a 100644 --- a/modules/gltf/editor_scene_exporter_gltf_plugin.cpp +++ b/modules/gltf/editor_scene_exporter_gltf_plugin.cpp @@ -49,7 +49,7 @@ bool SceneExporterGLTFPlugin::has_main_screen() const { SceneExporterGLTFPlugin::SceneExporterGLTFPlugin(EditorNode *p_node) { editor = p_node; - convert_gltf2.instance(); + convert_gltf2.instantiate(); file_export_lib = memnew(EditorFileDialog); editor->get_gui_base()->add_child(file_export_lib); file_export_lib->connect("file_selected", callable_mp(this, &SceneExporterGLTFPlugin::_gltf2_dialog_action)); diff --git a/modules/gltf/editor_scene_importer_gltf.cpp b/modules/gltf/editor_scene_importer_gltf.cpp index 21b4bb75fb..cef5278f03 100644 --- a/modules/gltf/editor_scene_importer_gltf.cpp +++ b/modules/gltf/editor_scene_importer_gltf.cpp @@ -30,7 +30,6 @@ #include "core/crypto/crypto_core.h" #include "core/io/file_access.h" -#include "core/io/json.h" #include "core/math/disjoint_set.h" #include "core/math/math_defs.h" #include "core/os/os.h" @@ -60,7 +59,7 @@ Node *EditorSceneImporterGLTF::import_scene(const String &p_path, List<String> *r_missing_deps, Error *r_err) { Ref<PackedSceneGLTF> importer; - importer.instance(); + importer.instantiate(); return importer->import_scene(p_path, p_flags, p_bake_fps, r_missing_deps, r_err, Ref<GLTFState>()); } @@ -91,13 +90,13 @@ Node *PackedSceneGLTF::import_scene(const String &p_path, uint32_t p_flags, Error *r_err, Ref<GLTFState> r_state) { if (r_state == Ref<GLTFState>()) { - r_state.instance(); + r_state.instantiate(); } r_state->use_named_skin_binds = p_flags & EditorSceneImporter::IMPORT_USE_NAMED_SKIN_BINDS; Ref<GLTFDocument> gltf_document; - gltf_document.instance(); + gltf_document.instantiate(); Error err = gltf_document->parse(r_state, p_path); if (r_err) { *r_err = err; @@ -139,9 +138,9 @@ void PackedSceneGLTF::save_scene(Node *p_node, const String &p_path, *r_err = err; } Ref<GLTFDocument> gltf_document; - gltf_document.instance(); + gltf_document.instantiate(); Ref<GLTFState> state; - state.instance(); + state.instantiate(); err = gltf_document->serialize(state, p_node, p_path); if (r_err) { *r_err = err; @@ -172,7 +171,7 @@ Error PackedSceneGLTF::export_gltf(Node *p_root, String p_path, int32_t flags = p_flags; real_t baked_fps = p_bake_fps; Ref<PackedSceneGLTF> exporter; - exporter.instance(); + exporter.instantiate(); exporter->save_scene(p_root, path, "", flags, baked_fps, &deps, &err); int32_t error_code = err; if (error_code != 0) { diff --git a/modules/gltf/editor_scene_importer_gltf.h b/modules/gltf/editor_scene_importer_gltf.h index af1a885f2b..566d5cfd34 100644 --- a/modules/gltf/editor_scene_importer_gltf.h +++ b/modules/gltf/editor_scene_importer_gltf.h @@ -32,7 +32,6 @@ #define EDITOR_SCENE_IMPORTER_GLTF_H #include "core/config/project_settings.h" -#include "core/io/json.h" #include "core/object/object.h" #include "core/templates/vector.h" #include "editor/import/resource_importer_scene.h" diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp index 988a75ac93..660c2ab305 100644 --- a/modules/gltf/gltf_document.cpp +++ b/modules/gltf/gltf_document.cpp @@ -238,15 +238,13 @@ Error GLTFDocument::_parse_json(const String &p_path, Ref<GLTFState> state) { String text; text.parse_utf8((const char *)array.ptr(), array.size()); - String err_txt; - int err_line; - Variant v; - err = JSON::parse(text, v, err_txt, err_line); + JSON json; + err = json.parse(text); if (err != OK) { - _err_print_error("", p_path.utf8().get_data(), err_line, err_txt.utf8().get_data(), ERR_HANDLER_SCRIPT); + _err_print_error("", p_path.utf8().get_data(), json.get_error_line(), json.get_error_message().utf8().get_data(), ERR_HANDLER_SCRIPT); return err; } - state->json = v; + state->json = json.get_data(); return OK; } @@ -299,16 +297,14 @@ Error GLTFDocument::_parse_glb(const String &p_path, Ref<GLTFState> state) { String text; text.parse_utf8((const char *)json_data.ptr(), json_data.size()); - String err_txt; - int err_line; - Variant v; - err = JSON::parse(text, v, err_txt, err_line); + JSON json; + err = json.parse(text); if (err != OK) { - _err_print_error("", p_path.utf8().get_data(), err_line, err_txt.utf8().get_data(), ERR_HANDLER_SCRIPT); + _err_print_error("", p_path.utf8().get_data(), json.get_error_line(), json.get_error_message().utf8().get_data(), ERR_HANDLER_SCRIPT); return err; } - state->json = v; + state->json = json.get_data(); //data? @@ -569,7 +565,7 @@ Error GLTFDocument::_parse_nodes(Ref<GLTFState> state) { const Array &nodes = state->json["nodes"]; for (int i = 0; i < nodes.size(); i++) { Ref<GLTFNode> node; - node.instance(); + node.instantiate(); const Dictionary &n = nodes[i]; if (n.has("name")) { @@ -830,7 +826,7 @@ Error GLTFDocument::_parse_buffer_views(Ref<GLTFState> state) { const Dictionary &d = buffers[i]; Ref<GLTFBufferView> buffer_view; - buffer_view.instance(); + buffer_view.instantiate(); ERR_FAIL_COND_V(!d.has("buffer"), ERR_PARSE_ERROR); buffer_view->buffer = d["buffer"]; @@ -976,7 +972,7 @@ Error GLTFDocument::_parse_accessors(Ref<GLTFState> state) { const Dictionary &d = accessors[i]; Ref<GLTFAccessor> accessor; - accessor.instance(); + accessor.instantiate(); ERR_FAIL_COND_V(!d.has("componentType"), ERR_PARSE_ERROR); accessor->component_type = d["componentType"]; @@ -1118,7 +1114,7 @@ Error GLTFDocument::_encode_buffer_view(Ref<GLTFState> state, const double *src, } Ref<GLTFBufferView> bv; - bv.instance(); + bv.instantiate(); const uint32_t offset = bv->byte_offset = byte_offset; Vector<uint8_t> &gltf_buffer = state->buffers.write[0]; @@ -1512,7 +1508,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_ints(Ref<GLTFState> state, c ERR_FAIL_COND_V(attribs.size() == 0, -1); Ref<GLTFAccessor> accessor; - accessor.instance(); + accessor.instantiate(); GLTFBufferIndex buffer_view_i; int64_t size = state->buffers[0].size(); const GLTFDocument::GLTFType type = GLTFDocument::TYPE_SCALAR; @@ -1596,7 +1592,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_vec2(Ref<GLTFState> state, c ERR_FAIL_COND_V(attribs.size() % element_count != 0, -1); Ref<GLTFAccessor> accessor; - accessor.instance(); + accessor.instantiate(); GLTFBufferIndex buffer_view_i; int64_t size = state->buffers[0].size(); const GLTFDocument::GLTFType type = GLTFDocument::TYPE_VEC2; @@ -1645,7 +1641,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_color(Ref<GLTFState> state, ERR_FAIL_COND_V(attribs.size() % element_count != 0, -1); Ref<GLTFAccessor> accessor; - accessor.instance(); + accessor.instantiate(); GLTFBufferIndex buffer_view_i; int64_t size = state->buffers[0].size(); const GLTFDocument::GLTFType type = GLTFDocument::TYPE_VEC4; @@ -1710,7 +1706,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_weights(Ref<GLTFState> state ERR_FAIL_COND_V(attribs.size() % element_count != 0, -1); Ref<GLTFAccessor> accessor; - accessor.instance(); + accessor.instantiate(); GLTFBufferIndex buffer_view_i; int64_t size = state->buffers[0].size(); const GLTFDocument::GLTFType type = GLTFDocument::TYPE_VEC4; @@ -1757,7 +1753,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_joints(Ref<GLTFState> state, ERR_FAIL_COND_V(attribs.size() % element_count != 0, -1); Ref<GLTFAccessor> accessor; - accessor.instance(); + accessor.instantiate(); GLTFBufferIndex buffer_view_i; int64_t size = state->buffers[0].size(); const GLTFDocument::GLTFType type = GLTFDocument::TYPE_VEC4; @@ -1806,7 +1802,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_quaternions(Ref<GLTFState> s ERR_FAIL_COND_V(attribs.size() % element_count != 0, -1); Ref<GLTFAccessor> accessor; - accessor.instance(); + accessor.instantiate(); GLTFBufferIndex buffer_view_i; int64_t size = state->buffers[0].size(); const GLTFDocument::GLTFType type = GLTFDocument::TYPE_VEC4; @@ -1871,7 +1867,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_floats(Ref<GLTFState> state, ERR_FAIL_COND_V(!attribs.size(), -1); Ref<GLTFAccessor> accessor; - accessor.instance(); + accessor.instantiate(); GLTFBufferIndex buffer_view_i; int64_t size = state->buffers[0].size(); const GLTFDocument::GLTFType type = GLTFDocument::TYPE_SCALAR; @@ -1917,7 +1913,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_vec3(Ref<GLTFState> state, c ERR_FAIL_COND_V(attribs.size() % element_count != 0, -1); Ref<GLTFAccessor> accessor; - accessor.instance(); + accessor.instantiate(); GLTFBufferIndex buffer_view_i; int64_t size = state->buffers[0].size(); const GLTFDocument::GLTFType type = GLTFDocument::TYPE_VEC3; @@ -1985,7 +1981,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_xform(Ref<GLTFState> state, ERR_FAIL_COND_V(attribs.size() % element_count != 0, -1); Ref<GLTFAccessor> accessor; - accessor.instance(); + accessor.instantiate(); GLTFBufferIndex buffer_view_i; int64_t size = state->buffers[0].size(); const GLTFDocument::GLTFType type = GLTFDocument::TYPE_MAT4; @@ -2335,7 +2331,7 @@ Error GLTFDocument::_serialize_meshes(Ref<GLTFState> state) { //generate indices because they need to be swapped for CW/CCW const Vector<Vector3> &vertices = array[Mesh::ARRAY_VERTEX]; Ref<SurfaceTool> st; - st.instance(); + st.instantiate(); st->create_from_triangle_arrays(array); st->index(); Vector<int32_t> generated_indices = st->commit_to_arrays()[Mesh::ARRAY_INDEX]; @@ -2459,7 +2455,7 @@ Error GLTFDocument::_parse_meshes(Ref<GLTFState> state) { Dictionary d = meshes[i]; Ref<GLTFMesh> mesh; - mesh.instance(); + mesh.instantiate(); bool has_vertex_color = false; ERR_FAIL_COND_V(!d.has("primitives"), ERR_PARSE_ERROR); @@ -2467,7 +2463,7 @@ Error GLTFDocument::_parse_meshes(Ref<GLTFState> state) { Array primitives = d["primitives"]; const Dictionary &extras = d.has("extras") ? (Dictionary)d["extras"] : Dictionary(); Ref<EditorSceneImporterMesh> import_mesh; - import_mesh.instance(); + import_mesh.instantiate(); String mesh_name = "mesh"; if (d.has("name") && !String(d["name"]).is_empty()) { mesh_name = d["name"]; @@ -2652,7 +2648,7 @@ Error GLTFDocument::_parse_meshes(Ref<GLTFState> state) { if (generate_tangents) { //must generate mikktspace tangents.. ergh.. Ref<SurfaceTool> st; - st.instance(); + st.instantiate(); st->create_from_triangle_arrays(array); if (a.has("JOINTS_0") && a.has("JOINTS_1")) { st->set_skin_weight_count(SurfaceTool::SKIN_8_WEIGHTS); @@ -2771,7 +2767,7 @@ Error GLTFDocument::_parse_meshes(Ref<GLTFState> state) { if (generate_tangents) { Ref<SurfaceTool> st; - st.instance(); + st.instantiate(); st->create_from_triangle_arrays(array_copy); if (a.has("JOINTS_0") && a.has("JOINTS_1")) { st->set_skin_weight_count(SurfaceTool::SKIN_8_WEIGHTS); @@ -2799,7 +2795,7 @@ Error GLTFDocument::_parse_meshes(Ref<GLTFState> state) { } else if (has_vertex_color) { Ref<StandardMaterial3D> mat3d; - mat3d.instance(); + mat3d.instantiate(); mat3d->set_flag(BaseMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); mat = mat3d; } @@ -2847,7 +2843,7 @@ Error GLTFDocument::_serialize_images(Ref<GLTFState> state, const String &p_path GLTFBufferViewIndex bvi; Ref<GLTFBufferView> bv; - bv.instance(); + bv.instantiate(); const GLTFBufferIndex bi = 0; bv->buffer = bi; @@ -2879,7 +2875,7 @@ Error GLTFDocument::_serialize_images(Ref<GLTFState> state, const String &p_path name = _gen_unique_name(state, name); name = name.pad_zeros(3); Ref<_Directory> dir; - dir.instance(); + dir.instantiate(); String texture_dir = "textures"; String new_texture_dir = p_path.get_base_dir() + "/" + texture_dir; dir->open(p_path.get_base_dir()); @@ -3038,7 +3034,7 @@ Error GLTFDocument::_parse_images(Ref<GLTFState> state, const String &p_base_pat } Ref<ImageTexture> t; - t.instance(); + t.instantiate(); t->create_from_image(img); state->images.push_back(t); @@ -3079,7 +3075,7 @@ Error GLTFDocument::_parse_textures(Ref<GLTFState> state) { ERR_FAIL_COND_V(!d.has("source"), ERR_PARSE_ERROR); Ref<GLTFTexture> t; - t.instance(); + t.instantiate(); t->set_src_image(d["source"]); state->textures.push_back(t); } @@ -3090,7 +3086,7 @@ Error GLTFDocument::_parse_textures(Ref<GLTFState> state) { GLTFTextureIndex GLTFDocument::_set_texture(Ref<GLTFState> state, Ref<Texture2D> p_texture) { ERR_FAIL_COND_V(p_texture.is_null(), -1); Ref<GLTFTexture> gltf_texture; - gltf_texture.instance(); + gltf_texture.instantiate(); ERR_FAIL_COND_V(p_texture->get_image().is_null(), -1); GLTFImageIndex gltf_src_image_i = state->images.size(); state->images.push_back(p_texture); @@ -3163,9 +3159,9 @@ Error GLTFDocument::_serialize_materials(Ref<GLTFState> state) { Ref<Texture2D> ao_texture = material->get_texture(BaseMaterial3D::TEXTURE_AMBIENT_OCCLUSION); BaseMaterial3D::TextureChannel ao_channel = material->get_ao_texture_channel(); Ref<ImageTexture> orm_texture; - orm_texture.instance(); + orm_texture.instantiate(); Ref<Image> orm_image; - orm_image.instance(); + orm_image.instantiate(); int32_t height = 0; int32_t width = 0; Ref<Image> ao_image; @@ -3285,7 +3281,7 @@ Error GLTFDocument::_serialize_materials(Ref<GLTFState> state) { if (material->get_feature(BaseMaterial3D::FEATURE_NORMAL_MAPPING)) { Dictionary nt; Ref<ImageTexture> tex; - tex.instance(); + tex.instantiate(); { Ref<Texture2D> normal_texture = material->get_texture(BaseMaterial3D::TEXTURE_NORMAL); // Code for uncompressing RG normal maps @@ -3373,7 +3369,7 @@ Error GLTFDocument::_parse_materials(Ref<GLTFState> state) { const Dictionary &d = materials[i]; Ref<StandardMaterial3D> material; - material.instance(); + material.instantiate(); if (d.has("name") && !String(d["name"]).is_empty()) { material->set_name(d["name"]); } else { @@ -3389,7 +3385,7 @@ Error GLTFDocument::_parse_materials(Ref<GLTFState> state) { Dictionary sgm = pbr_spec_gloss_extensions["KHR_materials_pbrSpecularGlossiness"]; Ref<GLTFSpecGloss> spec_gloss; - spec_gloss.instance(); + spec_gloss.instantiate(); if (sgm.has("diffuseTexture")) { const Dictionary &diffuse_texture_dict = sgm["diffuseTexture"]; if (diffuse_texture_dict.has("index")) { @@ -3572,7 +3568,7 @@ void GLTFDocument::spec_gloss_to_rough_metal(Ref<GLTFSpecGloss> r_spec_gloss, Re return; } Ref<Image> rm_img; - rm_img.instance(); + rm_img.instantiate(); bool has_roughness = false; bool has_metal = false; p_material->set_roughness(1.0f); @@ -3600,7 +3596,7 @@ void GLTFDocument::spec_gloss_to_rough_metal(Ref<GLTFSpecGloss> r_spec_gloss, Re if (!Math::is_equal_approx(mr.g, 1.0f)) { has_roughness = true; } - if (!Math::is_equal_approx(mr.b, 0.0f)) { + if (!Math::is_zero_approx(mr.b)) { has_metal = true; } mr.g *= r_spec_gloss->gloss_factor; @@ -3614,11 +3610,11 @@ void GLTFDocument::spec_gloss_to_rough_metal(Ref<GLTFSpecGloss> r_spec_gloss, Re rm_img->generate_mipmaps(); r_spec_gloss->diffuse_img->generate_mipmaps(); Ref<ImageTexture> diffuse_image_texture; - diffuse_image_texture.instance(); + diffuse_image_texture.instantiate(); diffuse_image_texture->create_from_image(r_spec_gloss->diffuse_img); p_material->set_texture(BaseMaterial3D::TEXTURE_ALBEDO, diffuse_image_texture); Ref<ImageTexture> rm_image_texture; - rm_image_texture.instance(); + rm_image_texture.instantiate(); rm_image_texture->create_from_image(rm_img); if (has_roughness) { p_material->set_texture(BaseMaterial3D::TEXTURE_ROUGHNESS, rm_image_texture); @@ -3894,7 +3890,7 @@ Error GLTFDocument::_parse_skins(Ref<GLTFState> state) { const Dictionary &d = skins[i]; Ref<GLTFSkin> skin; - skin.instance(); + skin.instantiate(); ERR_FAIL_COND_V(!d.has("joints"), ERR_PARSE_ERROR); @@ -4022,7 +4018,7 @@ Error GLTFDocument::_determine_skeletons(Ref<GLTFState> state) { for (GLTFSkeletonIndex skel_i = 0; skel_i < skeleton_owners.size(); ++skel_i) { const GLTFNodeIndex skeleton_owner = skeleton_owners[skel_i]; Ref<GLTFSkeleton> skeleton; - skeleton.instance(); + skeleton.instantiate(); Vector<GLTFNodeIndex> skeleton_nodes; skeleton_sets.get_members(skeleton_nodes, skeleton_owner); @@ -4270,7 +4266,7 @@ Error GLTFDocument::_create_skins(Ref<GLTFState> state) { Ref<GLTFSkin> gltf_skin = state->skins.write[skin_i]; Ref<Skin> skin; - skin.instance(); + skin.instantiate(); // Some skins don't have IBM's! What absolute monsters! const bool has_ibms = !gltf_skin->inverse_binds.is_empty(); @@ -4452,7 +4448,7 @@ Error GLTFDocument::_parse_lights(Ref<GLTFState> state) { const Dictionary &d = lights[light_i]; Ref<GLTFLight> light; - light.instance(); + light.instantiate(); ERR_FAIL_COND_V(!d.has("type"), ERR_PARSE_ERROR); const String &type = d["type"]; light->type = type; @@ -4497,7 +4493,7 @@ Error GLTFDocument::_parse_cameras(Ref<GLTFState> state) { const Dictionary &d = cameras[i]; Ref<GLTFCamera> camera; - camera.instance(); + camera.instantiate(); ERR_FAIL_COND_V(!d.has("type"), ERR_PARSE_ERROR); const String &type = d["type"]; if (type == "orthographic") { @@ -4700,7 +4696,7 @@ Error GLTFDocument::_parse_animations(Ref<GLTFState> state) { const Dictionary &d = animations[i]; Ref<GLTFAnimation> animation; - animation.instance(); + animation.instantiate(); if (!d.has("channels") || !d.has("samplers")) { continue; @@ -4868,7 +4864,7 @@ GLTFMeshIndex GLTFDocument::_convert_mesh_instance(Ref<GLTFState> state, MeshIns return -1; } Ref<EditorSceneImporterMesh> import_mesh; - import_mesh.instance(); + import_mesh.instantiate(); Ref<Mesh> godot_mesh = p_mesh_instance->get_mesh(); if (godot_mesh.is_null()) { return -1; @@ -4905,7 +4901,7 @@ GLTFMeshIndex GLTFDocument::_convert_mesh_instance(Ref<GLTFState> state, MeshIns blend_weights.write[blend_i] = 0.0f; } Ref<GLTFMesh> gltf_mesh; - gltf_mesh.instance(); + gltf_mesh.instantiate(); gltf_mesh->set_mesh(import_mesh); gltf_mesh->set_blend_weights(blend_weights); GLTFMeshIndex mesh_i = state->meshes.size(); @@ -5010,7 +5006,7 @@ GLTFCameraIndex GLTFDocument::_convert_camera(Ref<GLTFState> state, Camera3D *p_ print_verbose("glTF: Converting camera: " + p_camera->get_name()); Ref<GLTFCamera> c; - c.instance(); + c.instantiate(); if (p_camera->get_projection() == Camera3D::Projection::PROJECTION_PERSPECTIVE) { c->set_perspective(true); @@ -5031,7 +5027,7 @@ GLTFLightIndex GLTFDocument::_convert_light(Ref<GLTFState> state, Light3D *p_lig print_verbose("glTF: Converting light: " + p_light->get_name()); Ref<GLTFLight> l; - l.instance(); + l.instantiate(); l->color = p_light->get_color(); if (cast_to<DirectionalLight3D>(p_light)) { l->type = "directional"; @@ -5066,7 +5062,7 @@ GLTFLightIndex GLTFDocument::_convert_light(Ref<GLTFState> state, Light3D *p_lig GLTFSkeletonIndex GLTFDocument::_convert_skeleton(Ref<GLTFState> state, Skeleton3D *p_skeleton) { print_verbose("glTF: Converting skeleton: " + p_skeleton->get_name()); Ref<GLTFSkeleton> gltf_skeleton; - gltf_skeleton.instance(); + gltf_skeleton.instantiate(); gltf_skeleton->set_name(_gen_unique_name(state, p_skeleton->get_name())); gltf_skeleton->godot_skeleton = p_skeleton; GLTFSkeletonIndex skeleton_i = state->skeletons.size(); @@ -5096,7 +5092,7 @@ void GLTFDocument::_convert_scene_node(Ref<GLTFState> state, Node *p_current, No return; } Ref<GLTFNode> gltf_node; - gltf_node.instance(); + gltf_node.instantiate(); gltf_node->set_name(_gen_unique_name(state, p_current->get_name())); if (cast_to<Node3D>(p_current)) { Node3D *spatial = cast_to<Node3D>(p_current); @@ -5162,9 +5158,9 @@ void GLTFDocument::_convert_csg_shape_to_gltf(Node *p_current, GLTFNodeIndex p_g mat = csg->get_material_override(); } Ref<GLTFMesh> gltf_mesh; - gltf_mesh.instance(); + gltf_mesh.instantiate(); Ref<EditorSceneImporterMesh> import_mesh; - import_mesh.instance(); + import_mesh.instantiate(); Ref<ArrayMesh> array_mesh = csg->get_meshes()[1]; for (int32_t surface_i = 0; surface_i < array_mesh->get_surface_count(); surface_i++) { import_mesh->add_surface(Mesh::PrimitiveType::PRIMITIVE_TRIANGLES, array_mesh->surface_get_arrays(surface_i), Array(), Dictionary(), mat, array_mesh->surface_get_name(surface_i)); @@ -5250,7 +5246,7 @@ void GLTFDocument::_convert_grid_map_to_gltf(Node *p_scene_parent, const GLTFNod cell_xform.set_origin(grid_map->map_to_world( Vector3(cell_location.x, cell_location.y, cell_location.z))); Ref<GLTFMesh> gltf_mesh; - gltf_mesh.instance(); + gltf_mesh.instantiate(); gltf_mesh = import_mesh_node; new_gltf_node->mesh = state->meshes.size(); state->meshes.push_back(gltf_mesh); @@ -5287,14 +5283,14 @@ void GLTFDocument::_convert_mult_mesh_instance_to_gltf(Node *p_scene_parent, con Ref<ArrayMesh> mm = multi_mesh->get_mesh(); if (mm.is_valid()) { Ref<EditorSceneImporterMesh> mesh; - mesh.instance(); + mesh.instantiate(); for (int32_t surface_i = 0; surface_i < mm->get_surface_count(); surface_i++) { Array surface = mm->surface_get_arrays(surface_i); mesh->add_surface(mm->surface_get_primitive_type(surface_i), surface, Array(), Dictionary(), mm->surface_get_material(surface_i), mm->get_name()); } Ref<GLTFMesh> gltf_mesh; - gltf_mesh.instance(); + gltf_mesh.instantiate(); gltf_mesh->set_name(multi_mesh->get_name()); gltf_mesh->set_mesh(mesh); new_gltf_node->mesh = state->meshes.size(); @@ -5541,6 +5537,8 @@ struct EditorSceneImporterGLTFInterpolate<Quaternion> { template <class T> T GLTFDocument::_interpolate_track(const Vector<float> &p_times, const Vector<T> &p_values, const float p_time, const GLTFAnimation::Interpolation p_interp) { + ERR_FAIL_COND_V(!p_values.size(), T()); + ERR_FAIL_COND_V(p_times.size() != p_values.size(), p_values[0]); //could use binary search, worth it? int idx = -1; for (int i = 0; i < p_times.size(); i++) { @@ -5615,7 +5613,7 @@ void GLTFDocument::_import_animation(Ref<GLTFState> state, AnimationPlayer *ap, } Ref<Animation> animation; - animation.instance(); + animation.instantiate(); animation->set_name(name); if (anim->get_loop()) { @@ -5826,7 +5824,7 @@ void GLTFDocument::_convert_mesh_instances(Ref<GLTFState> state) { skin = skeleton->register_skin(nullptr)->get_skin(); } Ref<GLTFSkin> gltf_skin; - gltf_skin.instance(); + gltf_skin.instantiate(); Array json_joints; GLTFSkeletonIndex skeleton_gltf_i = -1; @@ -5868,7 +5866,7 @@ void GLTFDocument::_convert_mesh_instances(Ref<GLTFState> state) { BoneId bone_index = skeleton->find_bone(godot_bone_name); ERR_CONTINUE(bone_index == -1); Ref<GLTFNode> joint_node; - joint_node.instance(); + joint_node.instantiate(); String gltf_bone_name = _gen_unique_bone_name(state, skeleton_gltf_i, godot_bone_name); joint_node->set_name(gltf_bone_name); @@ -6091,7 +6089,7 @@ GLTFAnimation::Track GLTFDocument::_convert_animation_track(Ref<GLTFState> state Vector3 translation = p_animation->track_get_key_value(p_track_i, key_i); p_track.translation_track.values.write[key_i] = translation; } - } else if (path.find(":rotation_degrees") != -1) { + } else if (path.find(":rotation") != -1) { p_track.rotation_track.times = times; p_track.rotation_track.interpolation = gltf_interpolation; @@ -6099,11 +6097,7 @@ GLTFAnimation::Track GLTFDocument::_convert_animation_track(Ref<GLTFState> state p_track.rotation_track.interpolation = gltf_interpolation; for (int32_t key_i = 0; key_i < key_count; key_i++) { - Vector3 rotation_degrees = p_animation->track_get_key_value(p_track_i, key_i); - Vector3 rotation_radian; - rotation_radian.x = Math::deg2rad(rotation_degrees.x); - rotation_radian.y = Math::deg2rad(rotation_degrees.y); - rotation_radian.z = Math::deg2rad(rotation_degrees.z); + Vector3 rotation_radian = p_animation->track_get_key_value(p_track_i, key_i); p_track.rotation_track.values.write[key_i] = Quaternion(rotation_radian); } } else if (path.find(":scale") != -1) { @@ -6190,7 +6184,7 @@ GLTFAnimation::Track GLTFDocument::_convert_animation_track(Ref<GLTFState> state void GLTFDocument::_convert_animation(Ref<GLTFState> state, AnimationPlayer *ap, String p_animation_track_name) { Ref<Animation> animation = ap->get_animation(p_animation_track_name); Ref<GLTFAnimation> gltf_animation; - gltf_animation.instance(); + gltf_animation.instantiate(); gltf_animation->set_name(_gen_unique_name(state, p_animation_track_name)); for (int32_t track_i = 0; track_i < animation->get_track_count(); track_i++) { @@ -6584,7 +6578,7 @@ Error GLTFDocument::_serialize_file(Ref<GLTFState> state, const String p_path) { FileAccessRef f = FileAccess::open(p_path, FileAccess::WRITE, &err); ERR_FAIL_COND_V(!f, FAILED); - String json = JSON::print(state->json); + String json = Variant(state->json).to_json_string(); const uint32_t magic = 0x46546C67; // GLTF const int32_t header_size = 12; @@ -6625,7 +6619,7 @@ Error GLTFDocument::_serialize_file(Ref<GLTFState> state, const String p_path) { ERR_FAIL_COND_V(!f, FAILED); f->create(FileAccess::ACCESS_RESOURCES); - String json = JSON::print(state->json); + String json = Variant(state->json).to_json_string(); f->store_string(json); f->close(); } diff --git a/modules/gltf/register_types.cpp b/modules/gltf/register_types.cpp index dc995c9249..d11c7cb9cd 100644 --- a/modules/gltf/register_types.cpp +++ b/modules/gltf/register_types.cpp @@ -51,7 +51,7 @@ #ifdef TOOLS_ENABLED static void _editor_init() { Ref<EditorSceneImporterGLTF> import_gltf; - import_gltf.instance(); + import_gltf.instantiate(); ResourceImporterScene::get_singleton()->add_importer(import_gltf); } #endif diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp index 45af59622f..e9134b32d9 100644 --- a/modules/gridmap/grid_map.cpp +++ b/modules/gridmap/grid_map.cpp @@ -780,7 +780,7 @@ void GridMap::_update_octants_callback() { while (to_delete.front()) { octant_map.erase(to_delete.front()->get()); - to_delete.pop_back(); + to_delete.pop_front(); } _update_visibility(); @@ -1012,7 +1012,7 @@ void GridMap::make_baked_meshes(bool p_gen_lightmap_uv, float p_lightmap_uv_texe Ref<Material> surf_mat = mesh->surface_get_material(i); if (!mat_map.has(surf_mat)) { Ref<SurfaceTool> st; - st.instance(); + st.instantiate(); st->begin(Mesh::PRIMITIVE_TRIANGLES); st->set_material(surf_mat); mat_map[surf_mat] = st; @@ -1024,7 +1024,7 @@ void GridMap::make_baked_meshes(bool p_gen_lightmap_uv, float p_lightmap_uv_texe for (Map<OctantKey, Map<Ref<Material>, Ref<SurfaceTool>>>::Element *E = surface_map.front(); E; E = E->next()) { Ref<ArrayMesh> mesh; - mesh.instance(); + mesh.instantiate(); for (Map<Ref<Material>, Ref<SurfaceTool>>::Element *F = E->get().front(); F; F = F->next()) { F->get()->commit(mesh); } diff --git a/modules/gridmap/grid_map_editor_plugin.cpp b/modules/gridmap/grid_map_editor_plugin.cpp index 80551de1ba..a2f570e6a5 100644 --- a/modules/gridmap/grid_map_editor_plugin.cpp +++ b/modules/gridmap/grid_map_editor_plugin.cpp @@ -1085,7 +1085,7 @@ void GridMapEditor::_notification(int p_what) { if (input_action == INPUT_PAINT) { // Simulate mouse released event to stop drawing when editor focus exists. Ref<InputEventMouseButton> release; - release.instance(); + release.instantiate(); release->set_button_index(MOUSE_BUTTON_LEFT); forward_spatial_input_event(nullptr, release); } @@ -1356,7 +1356,7 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { Array d; d.resize(RS::ARRAY_MAX); - inner_mat.instance(); + inner_mat.instantiate(); inner_mat->set_albedo(Color(0.7, 0.7, 1.0, 0.2)); inner_mat->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED); inner_mat->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA); @@ -1365,14 +1365,14 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { RenderingServer::get_singleton()->mesh_add_surface_from_arrays(selection_mesh, RS::PRIMITIVE_TRIANGLES, d); RenderingServer::get_singleton()->mesh_surface_set_material(selection_mesh, 0, inner_mat->get_rid()); - outer_mat.instance(); + outer_mat.instantiate(); outer_mat->set_albedo(Color(0.7, 0.7, 1.0, 0.8)); outer_mat->set_on_top_of_alpha(); outer_mat->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED); outer_mat->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA); - selection_floor_mat.instance(); + selection_floor_mat.instantiate(); selection_floor_mat->set_albedo(Color(0.80, 0.80, 1.0, 1)); selection_floor_mat->set_on_top_of_alpha(); selection_floor_mat->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED); @@ -1399,7 +1399,7 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { _set_selection(false); - indicator_mat.instance(); + indicator_mat.instantiate(); indicator_mat->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED); indicator_mat->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA); indicator_mat->set_flag(StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, true); diff --git a/modules/jpg/image_loader_jpegd.cpp b/modules/jpg/image_loader_jpegd.cpp index d237544d66..b5e4753e8d 100644 --- a/modules/jpg/image_loader_jpegd.cpp +++ b/modules/jpg/image_loader_jpegd.cpp @@ -127,7 +127,7 @@ void ImageLoaderJPG::get_recognized_extensions(List<String> *p_extensions) const static Ref<Image> _jpegd_mem_loader_func(const uint8_t *p_png, int p_size) { Ref<Image> img; - img.instance(); + img.instantiate(); Error err = jpeg_load_image_from_buffer(img.ptr(), p_png, p_size); ERR_FAIL_COND_V(err, Ref<Image>()); return img; diff --git a/modules/jsonrpc/jsonrpc.cpp b/modules/jsonrpc/jsonrpc.cpp index 306c0ff087..3d0759d83e 100644 --- a/modules/jsonrpc/jsonrpc.cpp +++ b/modules/jsonrpc/jsonrpc.cpp @@ -29,6 +29,7 @@ /*************************************************************************/ #include "jsonrpc.h" + #include "core/io/json.h" JSONRPC::JSONRPC() { @@ -156,19 +157,17 @@ String JSONRPC::process_string(const String &p_input) { } Variant ret; - Variant input; - String err_message; - int err_line; - if (OK != JSON::parse(p_input, input, err_message, err_line)) { - ret = make_response_error(JSONRPC::PARSE_ERROR, "Parse error"); + JSON json; + if (json.parse(p_input) == OK) { + ret = process_action(json.get_data(), true); } else { - ret = process_action(input, true); + ret = make_response_error(JSONRPC::PARSE_ERROR, "Parse error"); } if (ret.get_type() == Variant::NIL) { return ""; } - return JSON::print(ret); + return ret.to_json_string(); } void JSONRPC::set_scope(const String &p_scope, Object *p_obj) { diff --git a/modules/lightmapper_rd/lightmapper_rd.cpp b/modules/lightmapper_rd/lightmapper_rd.cpp index 3b0fbb1c47..b75cf6502e 100644 --- a/modules/lightmapper_rd/lightmapper_rd.cpp +++ b/modules/lightmapper_rd/lightmapper_rd.cpp @@ -248,13 +248,13 @@ Lightmapper::BakeError LightmapperRD::_blit_meshes_into_atlas(int p_max_texture_ for (int i = 0; i < atlas_slices; i++) { Ref<Image> albedo; - albedo.instance(); + albedo.instantiate(); albedo->create(atlas_size.width, atlas_size.height, false, Image::FORMAT_RGBA8); albedo->set_as_black(); albedo_images.write[i] = albedo; Ref<Image> emission; - emission.instance(); + emission.instantiate(); emission->create(atlas_size.width, atlas_size.height, false, Image::FORMAT_RGBAH); emission->set_as_black(); emission_images.write[i] = emission; @@ -479,7 +479,7 @@ void LightmapperRD::_create_acceleration_structures(RenderingDevice *rd, Size2i } Ref<Image> img; - img.instance(); + img.instantiate(); img->create(grid_size, grid_size, false, Image::FORMAT_L8, grid_usage); img->save_png("res://grid_layer_" + itos(1000 + i).substr(1, 3) + ".png"); } @@ -725,7 +725,7 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d panorama_tex = p_environment_panorama; panorama_tex->convert(Image::FORMAT_RGBAF); } else { - panorama_tex.instance(); + panorama_tex.instantiate(); panorama_tex->create(8, 8, false, Image::FORMAT_RGBAF); for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { @@ -782,7 +782,7 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d //shaders Ref<RDShaderFile> raster_shader; - raster_shader.instance(); + raster_shader.instantiate(); Error err = raster_shader->parse_versions_from_text(lm_raster_shader_glsl); if (err != OK) { raster_shader->print_errors("raster_shader"); @@ -915,7 +915,7 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d for (int i = 0; i < atlas_slices; i++) { Vector<uint8_t> s = rd->texture_get_data(position_tex, i); Ref<Image> img; - img.instance(); + img.instantiate(); img->create(atlas_size.width, atlas_size.height, false, Image::FORMAT_RGBAF, s); img->save_exr("res://1_position_" + itos(i) + ".exr", false); @@ -933,7 +933,7 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d /* Plot direct light */ Ref<RDShaderFile> compute_shader; - compute_shader.instance(); + compute_shader.instantiate(); err = compute_shader->parse_versions_from_text(lm_compute_shader_glsl, p_bake_sh ? "\n#define USE_SH_LIGHTMAPS\n" : ""); if (err != OK) { FREE_TEXTURES @@ -1129,7 +1129,7 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d for (int i = 0; i < atlas_slices; i++) { Vector<uint8_t> s = rd->texture_get_data(light_source_tex, i); Ref<Image> img; - img.instance(); + img.instantiate(); img->create(atlas_size.width, atlas_size.height, false, Image::FORMAT_RGBAH, s); img->save_exr("res://2_light_primary_" + itos(i) + ".exr", false); } @@ -1379,12 +1379,12 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d #if 0 for (int i = 0; i < probe_positions.size(); i++) { Ref<Image> img; - img.instance(); + img.instantiate(); img->create(6, 4, false, Image::FORMAT_RGB8); for (int j = 0; j < 6; j++) { Vector<uint8_t> s = rd->texture_get_data(lightprobe_tex, i * 6 + j); Ref<Image> img2; - img2.instance(); + img2.instantiate(); img2->create(2, 2, false, Image::FORMAT_RGBAF, s); img2->convert(Image::FORMAT_RGB8); img->blit_rect(img2, Rect2(0, 0, 2, 2), Point2((j % 3) * 2, (j / 3) * 2)); @@ -1405,7 +1405,7 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d for (int i = 0; i < atlas_slices * (p_bake_sh ? 4 : 1); i++) { Vector<uint8_t> s = rd->texture_get_data(light_accum_tex, i); Ref<Image> img; - img.instance(); + img.instantiate(); img->create(atlas_size.width, atlas_size.height, false, Image::FORMAT_RGBAH, s); Ref<Image> denoised = denoiser->denoise_image(img); @@ -1432,7 +1432,7 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d for (int i = 0; i < atlas_slices * (p_bake_sh ? 4 : 1); i++) { Vector<uint8_t> s = rd->texture_get_data(light_accum_tex, i); Ref<Image> img; - img.instance(); + img.instantiate(); img->create(atlas_size.width, atlas_size.height, false, Image::FORMAT_RGBAH, s); img->save_exr("res://4_light_secondary_" + itos(i) + ".exr", false); } @@ -1484,7 +1484,7 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d for (int i = 0; i < atlas_slices * (p_bake_sh ? 4 : 1); i++) { Vector<uint8_t> s = rd->texture_get_data(light_accum_tex, i); Ref<Image> img; - img.instance(); + img.instantiate(); img->create(atlas_size.width, atlas_size.height, false, Image::FORMAT_RGBAH, s); img->convert(Image::FORMAT_RGBA8); img->save_png("res://5_dilated_" + itos(i) + ".png"); @@ -1494,7 +1494,7 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d /* BLEND SEAMS */ //shaders Ref<RDShaderFile> blendseams_shader; - blendseams_shader.instance(); + blendseams_shader.instantiate(); err = blendseams_shader->parse_versions_from_text(lm_blendseams_shader_glsl); if (err != OK) { FREE_TEXTURES @@ -1641,7 +1641,7 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d for (int i = 0; i < atlas_slices * (p_bake_sh ? 4 : 1); i++) { Vector<uint8_t> s = rd->texture_get_data(light_accum_tex, i); Ref<Image> img; - img.instance(); + img.instantiate(); img->create(atlas_size.width, atlas_size.height, false, Image::FORMAT_RGBAH, s); img->save_exr("res://5_blendseams" + itos(i) + ".exr", false); } @@ -1653,7 +1653,7 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d for (int i = 0; i < atlas_slices * (p_bake_sh ? 4 : 1); i++) { Vector<uint8_t> s = rd->texture_get_data(light_accum_tex, i); Ref<Image> img; - img.instance(); + img.instantiate(); img->create(atlas_size.width, atlas_size.height, false, Image::FORMAT_RGBAH, s); img->convert(Image::FORMAT_RGBH); //remove alpha bake_textures.push_back(img); @@ -1668,7 +1668,7 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d #ifdef DEBUG_TEXTURES { Ref<Image> img2; - img2.instance(); + img2.instantiate(); img2->create(probe_values.size(), 1, false, Image::FORMAT_RGBAF, probe_data); img2->save_exr("res://6_lightprobes.exr", false); } diff --git a/modules/mbedtls/crypto_mbedtls.cpp b/modules/mbedtls/crypto_mbedtls.cpp index 3cd2da3d85..2522f1bb11 100644 --- a/modules/mbedtls/crypto_mbedtls.cpp +++ b/modules/mbedtls/crypto_mbedtls.cpp @@ -249,6 +249,13 @@ PackedByteArray HMACContextMbedTLS::finish() { return out; } +HMACContextMbedTLS::~HMACContextMbedTLS() { + if (ctx != nullptr) { + mbedtls_md_free((mbedtls_md_context_t *)ctx); + memfree((mbedtls_md_context_t *)ctx); + } +} + Crypto *CryptoMbedTLS::create() { return memnew(CryptoMbedTLS); } @@ -324,7 +331,7 @@ void CryptoMbedTLS::load_default_certificates(String p_path) { Ref<CryptoKey> CryptoMbedTLS::generate_rsa(int p_bytes) { Ref<CryptoKeyMbedTLS> out; - out.instance(); + out.instantiate(); int ret = mbedtls_pk_setup(&(out->pkey), mbedtls_pk_info_from_type(MBEDTLS_PK_RSA)); ERR_FAIL_COND_V(ret != 0, nullptr); ret = mbedtls_rsa_gen_key(mbedtls_pk_rsa(out->pkey), mbedtls_ctr_drbg_random, &ctr_drbg, p_bytes, 65537); @@ -366,7 +373,7 @@ Ref<X509Certificate> CryptoMbedTLS::generate_self_signed_certificate(Ref<CryptoK buf[4095] = '\0'; // Make sure strlen can't fail. Ref<X509CertificateMbedTLS> out; - out.instance(); + out.instantiate(); out->load_from_memory(buf, strlen((char *)buf) + 1); // Use strlen to find correct output size. return out; } diff --git a/modules/mbedtls/crypto_mbedtls.h b/modules/mbedtls/crypto_mbedtls.h index 5ced4d136c..afa1ea7a64 100644 --- a/modules/mbedtls/crypto_mbedtls.h +++ b/modules/mbedtls/crypto_mbedtls.h @@ -119,6 +119,7 @@ public: virtual PackedByteArray finish(); HMACContextMbedTLS() {} + ~HMACContextMbedTLS(); }; class CryptoMbedTLS : public Crypto { diff --git a/modules/mbedtls/dtls_server_mbedtls.cpp b/modules/mbedtls/dtls_server_mbedtls.cpp index 5d895d8579..b1b6b3844b 100644 --- a/modules/mbedtls/dtls_server_mbedtls.cpp +++ b/modules/mbedtls/dtls_server_mbedtls.cpp @@ -45,7 +45,7 @@ void DTLSServerMbedTLS::stop() { Ref<PacketPeerDTLS> DTLSServerMbedTLS::take_connection(Ref<PacketPeerUDP> p_udp_peer) { Ref<PacketPeerMbedDTLS> out; - out.instance(); + out.instantiate(); ERR_FAIL_COND_V(!out.is_valid(), out); ERR_FAIL_COND_V(!p_udp_peer.is_valid(), out); @@ -68,7 +68,7 @@ void DTLSServerMbedTLS::finalize() { } DTLSServerMbedTLS::DTLSServerMbedTLS() { - _cookies.instance(); + _cookies.instantiate(); } DTLSServerMbedTLS::~DTLSServerMbedTLS() { diff --git a/modules/mbedtls/packet_peer_mbed_dtls.cpp b/modules/mbedtls/packet_peer_mbed_dtls.cpp index 11c9f64e21..114bf49e9e 100644 --- a/modules/mbedtls/packet_peer_mbed_dtls.cpp +++ b/modules/mbedtls/packet_peer_mbed_dtls.cpp @@ -245,7 +245,7 @@ int PacketPeerMbedDTLS::get_max_packet_size() const { } PacketPeerMbedDTLS::PacketPeerMbedDTLS() { - ssl_ctx.instance(); + ssl_ctx.instantiate(); } PacketPeerMbedDTLS::~PacketPeerMbedDTLS() { diff --git a/modules/mbedtls/stream_peer_mbedtls.cpp b/modules/mbedtls/stream_peer_mbedtls.cpp index bc72b04fa4..5727f5f82f 100644 --- a/modules/mbedtls/stream_peer_mbedtls.cpp +++ b/modules/mbedtls/stream_peer_mbedtls.cpp @@ -273,7 +273,7 @@ int StreamPeerMbedTLS::get_available_bytes() const { } StreamPeerMbedTLS::StreamPeerMbedTLS() { - ssl_ctx.instance(); + ssl_ctx.instantiate(); } StreamPeerMbedTLS::~StreamPeerMbedTLS() { diff --git a/modules/minimp3/audio_stream_mp3.cpp b/modules/minimp3/audio_stream_mp3.cpp index 600bbe9bb5..2cc974322d 100644 --- a/modules/minimp3/audio_stream_mp3.cpp +++ b/modules/minimp3/audio_stream_mp3.cpp @@ -126,7 +126,7 @@ Ref<AudioStreamPlayback> AudioStreamMP3::instance_playback() { "to it. AudioStreamMP3 should not be created from the " "inspector or with `.new()`. Instead, load an audio file."); - mp3s.instance(); + mp3s.instantiate(); mp3s->mp3_stream = Ref<AudioStreamMP3>(this); mp3s->mp3d = (mp3dec_ex_t *)memalloc(sizeof(mp3dec_ex_t)); diff --git a/modules/minimp3/register_types.cpp b/modules/minimp3/register_types.cpp index 4ab4c743d6..27ea512b69 100644 --- a/modules/minimp3/register_types.cpp +++ b/modules/minimp3/register_types.cpp @@ -41,7 +41,7 @@ void register_minimp3_types() { #ifdef TOOLS_ENABLED if (Engine::get_singleton()->is_editor_hint()) { Ref<ResourceImporterMP3> mp3_import; - mp3_import.instance(); + mp3_import.instantiate(); ResourceFormatImporter::get_singleton()->add_importer(mp3_import); } #endif diff --git a/modules/minimp3/resource_importer_mp3.cpp b/modules/minimp3/resource_importer_mp3.cpp index dc16125726..dc360c12ba 100644 --- a/modules/minimp3/resource_importer_mp3.cpp +++ b/modules/minimp3/resource_importer_mp3.cpp @@ -90,7 +90,7 @@ Error ResourceImporterMP3::import(const String &p_source_file, const String &p_s memdelete(f); Ref<AudioStreamMP3> mp3_stream; - mp3_stream.instance(); + mp3_stream.instantiate(); mp3_stream->set_data(data); ERR_FAIL_COND_V(!mp3_stream->get_data().size(), ERR_FILE_CORRUPT); diff --git a/modules/mobile_vr/register_types.cpp b/modules/mobile_vr/register_types.cpp index e7d33ba8a7..7d138aa4c9 100644 --- a/modules/mobile_vr/register_types.cpp +++ b/modules/mobile_vr/register_types.cpp @@ -37,7 +37,7 @@ void register_mobile_vr_types() { if (XRServer::get_singleton()) { Ref<MobileVRInterface> mobile_vr; - mobile_vr.instance(); + mobile_vr.instantiate(); XRServer::get_singleton()->add_interface(mobile_vr); } } diff --git a/modules/mono/build_scripts/mono_configure.py b/modules/mono/build_scripts/mono_configure.py index 309abfbff7..8e441e7e07 100644 --- a/modules/mono/build_scripts/mono_configure.py +++ b/modules/mono/build_scripts/mono_configure.py @@ -101,12 +101,6 @@ def configure(env, env_mono): mono_lib_names = ["mono-2.0-sgen", "monosgen-2.0"] - is_travis = os.environ.get("TRAVIS") == "true" - - if is_travis: - # Travis CI may have a Mono version lower than 5.12 - env_mono.Append(CPPDEFINES=["NO_PENDING_EXCEPTIONS"]) - if is_android and not env["android_arch"] in android_arch_dirs: raise RuntimeError("This module does not support the specified 'android_arch': " + env["android_arch"]) diff --git a/modules/mono/class_db_api_json.cpp b/modules/mono/class_db_api_json.cpp index bd02ec0eac..25193a1352 100644 --- a/modules/mono/class_db_api_json.cpp +++ b/modules/mono/class_db_api_json.cpp @@ -240,7 +240,8 @@ void class_db_api_to_json(const String &p_output_file, ClassDB::APIType p_api) { FileAccessRef f = FileAccess::open(p_output_file, FileAccess::WRITE); ERR_FAIL_COND_MSG(!f, "Cannot open file '" + p_output_file + "'."); - f->store_string(JSON::print(classes_dict, /*indent: */ "\t")); + JSON json; + f->store_string(json.stringify(classes_dict, "\t")); f->close(); print_line(String() + "ClassDB API JSON written to: " + ProjectSettings::get_singleton()->globalize_path(p_output_file)); diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp index 576256b6ec..ff6a47f59b 100644 --- a/modules/mono/csharp_script.cpp +++ b/modules/mono/csharp_script.cpp @@ -38,7 +38,6 @@ #include "core/debugger/engine_debugger.h" #include "core/debugger/script_debugger.h" #include "core/io/file_access.h" -#include "core/io/json.h" #include "core/os/mutex.h" #include "core/os/os.h" #include "core/os/thread.h" @@ -376,7 +375,7 @@ Ref<Script> CSharpLanguage::get_template(const String &p_class_name, const Strin .replace("%CLASS%", class_name_no_spaces); Ref<CSharpScript> script; - script.instance(); + script.instantiate(); script->set_source_code(script_template); script->set_name(class_name_no_spaces); @@ -1511,6 +1510,7 @@ void CSharpLanguage::free_instance_binding_data(void *p_data) { } void CSharpLanguage::refcount_incremented_instance_binding(Object *p_object) { +#if 0 RefCounted *rc_owner = Object::cast_to<RefCounted>(p_object); #ifdef DEBUG_ENABLED @@ -1545,9 +1545,11 @@ void CSharpLanguage::refcount_incremented_instance_binding(Object *p_object) { gchandle.release(); gchandle = strong_gchandle; } +#endif } bool CSharpLanguage::refcount_decremented_instance_binding(Object *p_object) { +#if 0 RefCounted *rc_owner = Object::cast_to<RefCounted>(p_object); #ifdef DEBUG_ENABLED @@ -1587,6 +1589,8 @@ bool CSharpLanguage::refcount_decremented_instance_binding(Object *p_object) { } return refcount == 0; +#endif + return false; } CSharpInstance *CSharpInstance::create_for_managed_type(Object *p_owner, CSharpScript *p_script, const MonoGCHandleData &p_gchandle) { @@ -2265,8 +2269,10 @@ CSharpInstance::~CSharpInstance() { // Otherwise, the unsafe reference debug checks will incorrectly detect a bug. bool die = _unreference_owner_unsafe(); CRASH_COND(die); // `owner_keep_alive` holds a reference, so it can't die - +#if 0 void *data = owner->get_script_instance_binding(CSharpLanguage::get_singleton()->get_language_index()); + + CRASH_COND(data == nullptr); CSharpScriptBinding &script_binding = ((Map<Object *, CSharpScriptBinding>::Element *)data)->get(); @@ -2285,6 +2291,7 @@ CSharpInstance::~CSharpInstance() { // The "instance binding" holds a reference so the refcount should be at least 2 before `scope_keep_owner_alive` goes out of scope CRASH_COND(rc_owner->reference_get_count() <= 1); #endif +#endif } if (script.is_valid() && owner) { @@ -3031,7 +3038,7 @@ void CSharpScript::update_script_class_info(Ref<CSharpScript> p_script) { nd.name = methods[i]->get_name(); nd.rpc_mode = mode; // TODO Transfer mode, channel - nd.transfer_mode = NetworkedMultiplayerPeer::TRANSFER_MODE_RELIABLE; + nd.transfer_mode = MultiplayerPeer::TRANSFER_MODE_RELIABLE; nd.channel = 0; if (-1 == p_script->rpc_functions.find(nd)) { p_script->rpc_functions.push_back(nd); @@ -3050,7 +3057,7 @@ void CSharpScript::update_script_class_info(Ref<CSharpScript> p_script) { p_script->load_script_signals(p_script->script_class, p_script->native); } -bool CSharpScript::can_instance() const { +bool CSharpScript::can_instantiate() const { #ifdef TOOLS_ENABLED bool extra_cond = tool || ScriptServer::is_scripting_enabled(); #else @@ -3102,7 +3109,7 @@ CSharpInstance *CSharpScript::_create_instance(const Variant **p_args, int p_arg // Hold it alive. Important if we have to dispose a script instance binding before creating the CSharpInstance. ref = Ref<RefCounted>(static_cast<RefCounted *>(p_owner)); } - +#if 0 // If the object had a script instance binding, dispose it before adding the CSharpInstance if (p_owner->has_script_instance_binding(CSharpLanguage::get_singleton()->get_language_index())) { void *data = p_owner->get_script_instance_binding(CSharpLanguage::get_singleton()->get_language_index()); @@ -3124,7 +3131,7 @@ CSharpInstance *CSharpScript::_create_instance(const Variant **p_args, int p_arg script_binding.inited = false; } } - +#endif CSharpInstance *instance = memnew(CSharpInstance(Ref<CSharpScript>(this))); instance->base_ref_counted = p_is_ref_counted; instance->owner = p_owner; @@ -3183,7 +3190,7 @@ Variant CSharpScript::_new(const Variant **p_args, int p_argcount, Callable::Cal GD_MONO_SCOPE_THREAD_ATTACH; - Object *owner = ClassDB::instance(NATIVE_GDMONOCLASS_NAME(native)); + Object *owner = ClassDB::instantiate(NATIVE_GDMONOCLASS_NAME(native)); REF ref; RefCounted *r = Object::cast_to<RefCounted>(owner); @@ -3217,10 +3224,10 @@ ScriptInstance *CSharpScript::instance_create(Object *p_this) { if (EngineDebugger::is_active()) { CSharpLanguage::get_singleton()->debug_break_parse(get_path(), 0, "Script inherits from native type '" + String(native_name) + - "', so it can't be instanced in object of type: '" + p_this->get_class() + "'"); + "', so it can't be instantiated in object of type: '" + p_this->get_class() + "'"); } ERR_FAIL_V_MSG(nullptr, "Script inherits from native type '" + String(native_name) + - "', so it can't be instanced in object of type: '" + p_this->get_class() + "'."); + "', so it can't be instantiated in object of type: '" + p_this->get_class() + "'."); } } diff --git a/modules/mono/csharp_script.h b/modules/mono/csharp_script.h index 965e882c5b..da6b60aee2 100644 --- a/modules/mono/csharp_script.h +++ b/modules/mono/csharp_script.h @@ -191,7 +191,7 @@ protected: void _get_property_list(List<PropertyInfo> *p_properties) const; public: - bool can_instance() const override; + bool can_instantiate() const override; StringName get_instance_base_type() const override; ScriptInstance *instance_create(Object *p_this) override; PlaceHolderScriptInstance *placeholder_instance_create(Object *p_this) override; @@ -455,9 +455,8 @@ public: Ref<Script> get_template(const String &p_class_name, const String &p_base_class_name) const override; bool is_using_templates() override; void make_template(const String &p_class_name, const String &p_base_class_name, Ref<Script> &p_script) override; - /* TODO */ bool validate(const String &p_script, int &r_line_error, int &r_col_error, - String &r_test_error, const String &p_path, List<String> *r_functions, - List<ScriptLanguage::Warning> *r_warnings = nullptr, Set<int> *r_safe_lines = nullptr) const override { + /* TODO */ bool validate(const String &p_script, const String &p_path, List<String> *r_functions, + List<ScriptLanguage::ScriptError> *r_errors = nullptr, List<ScriptLanguage::Warning> *r_warnings = nullptr, Set<int> *r_safe_lines = nullptr) const override { return true; } String validate_path(const String &p_path) const override; diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Extensions/PackedSceneExtensions.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Extensions/PackedSceneExtensions.cs index 763f470504..214bbf5179 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Extensions/PackedSceneExtensions.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Extensions/PackedSceneExtensions.cs @@ -8,9 +8,9 @@ namespace Godot /// `Node.NotificationInstanced` notification on the root node. /// </summary> /// <typeparam name="T">The type to cast to. Should be a descendant of Node.</typeparam> - public T Instance<T>(PackedScene.GenEditState editState = (PackedScene.GenEditState)0) where T : class + public T Instantiate<T>(PackedScene.GenEditState editState = (PackedScene.GenEditState)0) where T : class { - return (T)(object)Instance(editState); + return (T)(object)Instantiate(editState); } /// <summary> @@ -19,9 +19,9 @@ namespace Godot /// `Node.NotificationInstanced` notification on the root node. /// </summary> /// <typeparam name="T">The type to cast to. Should be a descendant of Node.</typeparam> - public T InstanceOrNull<T>(PackedScene.GenEditState editState = (PackedScene.GenEditState)0) where T : class + public T InstantiateOrNull<T>(PackedScene.GenEditState editState = (PackedScene.GenEditState)0) where T : class { - return Instance(editState) as T; + return Instantiate(editState) as T; } } } diff --git a/modules/mono/glue/base_object_glue.cpp b/modules/mono/glue/base_object_glue.cpp index 2b6d2761ca..2d04cedb9b 100644 --- a/modules/mono/glue/base_object_glue.cpp +++ b/modules/mono/glue/base_object_glue.cpp @@ -64,7 +64,7 @@ void godot_icall_Object_Disposed(MonoObject *p_obj, Object *p_ptr) { return; } } - +#if 0 void *data = p_ptr->get_script_instance_binding(CSharpLanguage::get_singleton()->get_language_index()); if (data) { @@ -76,6 +76,7 @@ void godot_icall_Object_Disposed(MonoObject *p_obj, Object *p_ptr) { } } } +#endif } void godot_icall_RefCounted_Disposed(MonoObject *p_obj, Object *p_ptr, MonoBoolean p_is_finalizer) { @@ -84,7 +85,7 @@ void godot_icall_RefCounted_Disposed(MonoObject *p_obj, Object *p_ptr, MonoBoole // This is only called with RefCounted derived classes CRASH_COND(!Object::cast_to<RefCounted>(p_ptr)); #endif - +#if 0 RefCounted *rc = static_cast<RefCounted *>(p_ptr); if (rc->get_script_instance()) { @@ -124,6 +125,7 @@ void godot_icall_RefCounted_Disposed(MonoObject *p_obj, Object *p_ptr, MonoBoole } } } +#endif } void godot_icall_Object_ConnectEventSignals(Object *p_ptr) { @@ -153,10 +155,10 @@ MonoObject *godot_icall_Object_weakref(Object *p_ptr) { return nullptr; } - wref.instance(); + wref.instantiate(); wref->set_ref(r); } else { - wref.instance(); + wref.instantiate(); wref->set_obj(p_ptr); } diff --git a/modules/mono/mono_gd/gd_mono.cpp b/modules/mono/mono_gd/gd_mono.cpp index a3acfbd995..02d875f669 100644 --- a/modules/mono/mono_gd/gd_mono.cpp +++ b/modules/mono/mono_gd/gd_mono.cpp @@ -691,7 +691,7 @@ static bool try_get_cached_api_hash_for(const String &p_api_assemblies_dir, bool } Ref<ConfigFile> cfg; - cfg.instance(); + cfg.instantiate(); Error cfg_err = cfg->load(cached_api_hash_path); ERR_FAIL_COND_V(cfg_err != OK, false); @@ -717,7 +717,7 @@ static void create_cached_api_hash_for(const String &p_api_assemblies_dir) { String cached_api_hash_path = p_api_assemblies_dir.plus_file("api_hash_cache.cfg"); Ref<ConfigFile> cfg; - cfg.instance(); + cfg.instantiate(); cfg->set_value("core", "modified_time", FileAccess::get_modified_time(core_api_assembly_path)); cfg->set_value("editor", "modified_time", FileAccess::get_modified_time(editor_api_assembly_path)); diff --git a/modules/mono/mono_gd/gd_mono_internals.cpp b/modules/mono/mono_gd/gd_mono_internals.cpp index d7df18d5da..d6545d50ec 100644 --- a/modules/mono/mono_gd/gd_mono_internals.cpp +++ b/modules/mono/mono_gd/gd_mono_internals.cpp @@ -45,7 +45,7 @@ namespace GDMonoInternals { void tie_managed_to_unmanaged(MonoObject *managed, Object *unmanaged) { // This method should not fail - +#if 0 CRASH_COND(!unmanaged); // All mono objects created from the managed world (e.g.: 'new Player()') @@ -108,6 +108,7 @@ void tie_managed_to_unmanaged(MonoObject *managed, Object *unmanaged) { CSharpInstance *csharp_instance = CSharpInstance::create_for_managed_type(unmanaged, script.ptr(), gchandle); unmanaged->set_script_and_instance(script, csharp_instance); +#endif } void unhandled_exception(MonoException *p_exc) { diff --git a/modules/mono/mono_gd/gd_mono_utils.cpp b/modules/mono/mono_gd/gd_mono_utils.cpp index df45cb8e92..080398c997 100644 --- a/modules/mono/mono_gd/gd_mono_utils.cpp +++ b/modules/mono/mono_gd/gd_mono_utils.cpp @@ -54,6 +54,7 @@ namespace GDMonoUtils { MonoObject *unmanaged_get_managed(Object *unmanaged) { +#if 0 if (!unmanaged) { return nullptr; } @@ -120,6 +121,8 @@ MonoObject *unmanaged_get_managed(Object *unmanaged) { } return mono_object; +#endif + return nullptr; } void set_main_thread(MonoThread *p_thread) { @@ -238,7 +241,7 @@ GDMonoClass *get_class_native_base(GDMonoClass *p_class) { MonoObject *create_managed_for_godot_object(GDMonoClass *p_class, const StringName &p_native, Object *p_object) { bool parent_is_object_class = ClassDB::is_parent_class(p_object->get_class_name(), p_native); ERR_FAIL_COND_V_MSG(!parent_is_object_class, nullptr, - "Type inherits from native type '" + p_native + "', so it can't be instanced in object of type: '" + p_object->get_class() + "'."); + "Type inherits from native type '" + p_native + "', so it can't be instantiated in object of type: '" + p_object->get_class() + "'."); MonoObject *mono_object = mono_object_new(mono_domain_get(), p_class->get_mono_ptr()); ERR_FAIL_NULL_V(mono_object, nullptr); diff --git a/modules/mono/register_types.cpp b/modules/mono/register_types.cpp index 80eb47bfd4..b4a6bfdcd4 100644 --- a/modules/mono/register_types.cpp +++ b/modules/mono/register_types.cpp @@ -52,10 +52,10 @@ void register_mono_types() { script_language_cs->set_language_index(ScriptServer::get_language_count()); ScriptServer::register_language(script_language_cs); - resource_loader_cs.instance(); + resource_loader_cs.instantiate(); ResourceLoader::add_resource_format_loader(resource_loader_cs); - resource_saver_cs.instance(); + resource_saver_cs.instantiate(); ResourceSaver::add_resource_format_saver(resource_saver_cs); } diff --git a/modules/gdnavigation/SCsub b/modules/navigation/SCsub index 22b5509b32..22b5509b32 100644 --- a/modules/gdnavigation/SCsub +++ b/modules/navigation/SCsub diff --git a/modules/gdnavigation/config.py b/modules/navigation/config.py index d22f9454ed..d22f9454ed 100644 --- a/modules/gdnavigation/config.py +++ b/modules/navigation/config.py diff --git a/modules/gdnavigation/gd_navigation_server.cpp b/modules/navigation/godot_navigation_server.cpp index d5e6e5e69f..df003cfe6f 100644 --- a/modules/gdnavigation/gd_navigation_server.cpp +++ b/modules/navigation/godot_navigation_server.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* gd_navigation_server.cpp */ +/* godot_navigation_server.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,7 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "gd_navigation_server.h" +#include "godot_navigation_server.h" #include "core/os/mutex.h" @@ -44,96 +44,96 @@ /// an instance of that struct with the submitted parameters. /// Then, that struct is stored in an array; the `sync` function consume that array. -#define COMMAND_1(F_NAME, T_0, D_0) \ - struct MERGE(F_NAME, _command) : public SetCommand { \ - T_0 d_0; \ - MERGE(F_NAME, _command) \ - (T_0 p_d_0) : \ - d_0(p_d_0) {} \ - virtual void exec(GdNavigationServer *server) { \ - server->MERGE(_cmd_, F_NAME)(d_0); \ - } \ - }; \ - void GdNavigationServer::F_NAME(T_0 D_0) const { \ - auto cmd = memnew(MERGE(F_NAME, _command)( \ - D_0)); \ - add_command(cmd); \ - } \ - void GdNavigationServer::MERGE(_cmd_, F_NAME)(T_0 D_0) - -#define COMMAND_2(F_NAME, T_0, D_0, T_1, D_1) \ - struct MERGE(F_NAME, _command) : public SetCommand { \ - T_0 d_0; \ - T_1 d_1; \ - MERGE(F_NAME, _command) \ - ( \ - T_0 p_d_0, \ - T_1 p_d_1) : \ - d_0(p_d_0), \ - d_1(p_d_1) {} \ - virtual void exec(GdNavigationServer *server) { \ - server->MERGE(_cmd_, F_NAME)(d_0, d_1); \ - } \ - }; \ - void GdNavigationServer::F_NAME(T_0 D_0, T_1 D_1) const { \ - auto cmd = memnew(MERGE(F_NAME, _command)( \ - D_0, \ - D_1)); \ - add_command(cmd); \ - } \ - void GdNavigationServer::MERGE(_cmd_, F_NAME)(T_0 D_0, T_1 D_1) - -#define COMMAND_4(F_NAME, T_0, D_0, T_1, D_1, T_2, D_2, T_3, D_3) \ - struct MERGE(F_NAME, _command) : public SetCommand { \ - T_0 d_0; \ - T_1 d_1; \ - T_2 d_2; \ - T_3 d_3; \ - MERGE(F_NAME, _command) \ - ( \ - T_0 p_d_0, \ - T_1 p_d_1, \ - T_2 p_d_2, \ - T_3 p_d_3) : \ - d_0(p_d_0), \ - d_1(p_d_1), \ - d_2(p_d_2), \ - d_3(p_d_3) {} \ - virtual void exec(GdNavigationServer *server) { \ - server->MERGE(_cmd_, F_NAME)(d_0, d_1, d_2, d_3); \ - } \ - }; \ - void GdNavigationServer::F_NAME(T_0 D_0, T_1 D_1, T_2 D_2, T_3 D_3) const { \ - auto cmd = memnew(MERGE(F_NAME, _command)( \ - D_0, \ - D_1, \ - D_2, \ - D_3)); \ - add_command(cmd); \ - } \ - void GdNavigationServer::MERGE(_cmd_, F_NAME)(T_0 D_0, T_1 D_1, T_2 D_2, T_3 D_3) - -GdNavigationServer::GdNavigationServer() : +#define COMMAND_1(F_NAME, T_0, D_0) \ + struct MERGE(F_NAME, _command) : public SetCommand { \ + T_0 d_0; \ + MERGE(F_NAME, _command) \ + (T_0 p_d_0) : \ + d_0(p_d_0) {} \ + virtual void exec(GodotNavigationServer *server) { \ + server->MERGE(_cmd_, F_NAME)(d_0); \ + } \ + }; \ + void GodotNavigationServer::F_NAME(T_0 D_0) const { \ + auto cmd = memnew(MERGE(F_NAME, _command)( \ + D_0)); \ + add_command(cmd); \ + } \ + void GodotNavigationServer::MERGE(_cmd_, F_NAME)(T_0 D_0) + +#define COMMAND_2(F_NAME, T_0, D_0, T_1, D_1) \ + struct MERGE(F_NAME, _command) : public SetCommand { \ + T_0 d_0; \ + T_1 d_1; \ + MERGE(F_NAME, _command) \ + ( \ + T_0 p_d_0, \ + T_1 p_d_1) : \ + d_0(p_d_0), \ + d_1(p_d_1) {} \ + virtual void exec(GodotNavigationServer *server) { \ + server->MERGE(_cmd_, F_NAME)(d_0, d_1); \ + } \ + }; \ + void GodotNavigationServer::F_NAME(T_0 D_0, T_1 D_1) const { \ + auto cmd = memnew(MERGE(F_NAME, _command)( \ + D_0, \ + D_1)); \ + add_command(cmd); \ + } \ + void GodotNavigationServer::MERGE(_cmd_, F_NAME)(T_0 D_0, T_1 D_1) + +#define COMMAND_4(F_NAME, T_0, D_0, T_1, D_1, T_2, D_2, T_3, D_3) \ + struct MERGE(F_NAME, _command) : public SetCommand { \ + T_0 d_0; \ + T_1 d_1; \ + T_2 d_2; \ + T_3 d_3; \ + MERGE(F_NAME, _command) \ + ( \ + T_0 p_d_0, \ + T_1 p_d_1, \ + T_2 p_d_2, \ + T_3 p_d_3) : \ + d_0(p_d_0), \ + d_1(p_d_1), \ + d_2(p_d_2), \ + d_3(p_d_3) {} \ + virtual void exec(GodotNavigationServer *server) { \ + server->MERGE(_cmd_, F_NAME)(d_0, d_1, d_2, d_3); \ + } \ + }; \ + void GodotNavigationServer::F_NAME(T_0 D_0, T_1 D_1, T_2 D_2, T_3 D_3) const { \ + auto cmd = memnew(MERGE(F_NAME, _command)( \ + D_0, \ + D_1, \ + D_2, \ + D_3)); \ + add_command(cmd); \ + } \ + void GodotNavigationServer::MERGE(_cmd_, F_NAME)(T_0 D_0, T_1 D_1, T_2 D_2, T_3 D_3) + +GodotNavigationServer::GodotNavigationServer() : NavigationServer3D() { } -GdNavigationServer::~GdNavigationServer() { +GodotNavigationServer::~GodotNavigationServer() { flush_queries(); } -void GdNavigationServer::add_command(SetCommand *command) const { - GdNavigationServer *mut_this = const_cast<GdNavigationServer *>(this); +void GodotNavigationServer::add_command(SetCommand *command) const { + GodotNavigationServer *mut_this = const_cast<GodotNavigationServer *>(this); { MutexLock lock(commands_mutex); mut_this->commands.push_back(command); } } -RID GdNavigationServer::map_create() const { - GdNavigationServer *mut_this = const_cast<GdNavigationServer *>(this); +RID GodotNavigationServer::map_create() const { + GodotNavigationServer *mut_this = const_cast<GodotNavigationServer *>(this); MutexLock lock(mut_this->operations_mutex); - NavMap *space = memnew(NavMap); - RID rid = map_owner.make_rid(space); + RID rid = map_owner.make_rid(); + NavMap *space = map_owner.getornull(rid); space->set_self(rid); return rid; } @@ -155,7 +155,7 @@ COMMAND_2(map_set_active, RID, p_map, bool, p_active) { } } -bool GdNavigationServer::map_is_active(RID p_map) const { +bool GodotNavigationServer::map_is_active(RID p_map) const { NavMap *map = map_owner.getornull(p_map); ERR_FAIL_COND_V(map == nullptr, false); @@ -169,7 +169,7 @@ COMMAND_2(map_set_up, RID, p_map, Vector3, p_up) { map->set_up(p_up); } -Vector3 GdNavigationServer::map_get_up(RID p_map) const { +Vector3 GodotNavigationServer::map_get_up(RID p_map) const { const NavMap *map = map_owner.getornull(p_map); ERR_FAIL_COND_V(map == nullptr, Vector3()); @@ -183,7 +183,7 @@ COMMAND_2(map_set_cell_size, RID, p_map, real_t, p_cell_size) { map->set_cell_size(p_cell_size); } -real_t GdNavigationServer::map_get_cell_size(RID p_map) const { +real_t GodotNavigationServer::map_get_cell_size(RID p_map) const { const NavMap *map = map_owner.getornull(p_map); ERR_FAIL_COND_V(map == nullptr, 0); @@ -197,53 +197,53 @@ COMMAND_2(map_set_edge_connection_margin, RID, p_map, real_t, p_connection_margi map->set_edge_connection_margin(p_connection_margin); } -real_t GdNavigationServer::map_get_edge_connection_margin(RID p_map) const { +real_t GodotNavigationServer::map_get_edge_connection_margin(RID p_map) const { const NavMap *map = map_owner.getornull(p_map); ERR_FAIL_COND_V(map == nullptr, 0); return map->get_edge_connection_margin(); } -Vector<Vector3> GdNavigationServer::map_get_path(RID p_map, Vector3 p_origin, Vector3 p_destination, bool p_optimize, uint32_t p_layers) const { +Vector<Vector3> GodotNavigationServer::map_get_path(RID p_map, Vector3 p_origin, Vector3 p_destination, bool p_optimize, uint32_t p_layers) const { const NavMap *map = map_owner.getornull(p_map); ERR_FAIL_COND_V(map == nullptr, Vector<Vector3>()); return map->get_path(p_origin, p_destination, p_optimize, p_layers); } -Vector3 GdNavigationServer::map_get_closest_point_to_segment(RID p_map, const Vector3 &p_from, const Vector3 &p_to, const bool p_use_collision) const { +Vector3 GodotNavigationServer::map_get_closest_point_to_segment(RID p_map, const Vector3 &p_from, const Vector3 &p_to, const bool p_use_collision) const { const NavMap *map = map_owner.getornull(p_map); ERR_FAIL_COND_V(map == nullptr, Vector3()); return map->get_closest_point_to_segment(p_from, p_to, p_use_collision); } -Vector3 GdNavigationServer::map_get_closest_point(RID p_map, const Vector3 &p_point) const { +Vector3 GodotNavigationServer::map_get_closest_point(RID p_map, const Vector3 &p_point) const { const NavMap *map = map_owner.getornull(p_map); ERR_FAIL_COND_V(map == nullptr, Vector3()); return map->get_closest_point(p_point); } -Vector3 GdNavigationServer::map_get_closest_point_normal(RID p_map, const Vector3 &p_point) const { +Vector3 GodotNavigationServer::map_get_closest_point_normal(RID p_map, const Vector3 &p_point) const { const NavMap *map = map_owner.getornull(p_map); ERR_FAIL_COND_V(map == nullptr, Vector3()); return map->get_closest_point_normal(p_point); } -RID GdNavigationServer::map_get_closest_point_owner(RID p_map, const Vector3 &p_point) const { +RID GodotNavigationServer::map_get_closest_point_owner(RID p_map, const Vector3 &p_point) const { const NavMap *map = map_owner.getornull(p_map); ERR_FAIL_COND_V(map == nullptr, RID()); return map->get_closest_point_owner(p_point); } -RID GdNavigationServer::region_create() const { - GdNavigationServer *mut_this = const_cast<GdNavigationServer *>(this); +RID GodotNavigationServer::region_create() const { + GodotNavigationServer *mut_this = const_cast<GodotNavigationServer *>(this); MutexLock lock(mut_this->operations_mutex); - NavRegion *reg = memnew(NavRegion); - RID rid = region_owner.make_rid(reg); + RID rid = region_owner.make_rid(); + NavRegion *reg = region_owner.getornull(rid); reg->set_self(rid); return rid; } @@ -284,7 +284,7 @@ COMMAND_2(region_set_layers, RID, p_region, uint32_t, p_layers) { region->set_layers(p_layers); } -uint32_t GdNavigationServer::region_get_layers(RID p_region) const { +uint32_t GodotNavigationServer::region_get_layers(RID p_region) const { NavRegion *region = region_owner.getornull(p_region); ERR_FAIL_COND_V(region == nullptr, 0); @@ -298,7 +298,7 @@ COMMAND_2(region_set_navmesh, RID, p_region, Ref<NavigationMesh>, p_nav_mesh) { region->set_mesh(p_nav_mesh); } -void GdNavigationServer::region_bake_navmesh(Ref<NavigationMesh> r_mesh, Node *p_node) const { +void GodotNavigationServer::region_bake_navmesh(Ref<NavigationMesh> r_mesh, Node *p_node) const { ERR_FAIL_COND(r_mesh.is_null()); ERR_FAIL_COND(p_node == nullptr); @@ -308,32 +308,32 @@ void GdNavigationServer::region_bake_navmesh(Ref<NavigationMesh> r_mesh, Node *p #endif } -int GdNavigationServer::region_get_connections_count(RID p_region) const { +int GodotNavigationServer::region_get_connections_count(RID p_region) const { NavRegion *region = region_owner.getornull(p_region); ERR_FAIL_COND_V(!region, 0); return region->get_connections_count(); } -Vector3 GdNavigationServer::region_get_connection_pathway_start(RID p_region, int p_connection_id) const { +Vector3 GodotNavigationServer::region_get_connection_pathway_start(RID p_region, int p_connection_id) const { NavRegion *region = region_owner.getornull(p_region); ERR_FAIL_COND_V(!region, Vector3()); return region->get_connection_pathway_start(p_connection_id); } -Vector3 GdNavigationServer::region_get_connection_pathway_end(RID p_region, int p_connection_id) const { +Vector3 GodotNavigationServer::region_get_connection_pathway_end(RID p_region, int p_connection_id) const { NavRegion *region = region_owner.getornull(p_region); ERR_FAIL_COND_V(!region, Vector3()); return region->get_connection_pathway_end(p_connection_id); } -RID GdNavigationServer::agent_create() const { - GdNavigationServer *mut_this = const_cast<GdNavigationServer *>(this); +RID GodotNavigationServer::agent_create() const { + GodotNavigationServer *mut_this = const_cast<GodotNavigationServer *>(this); MutexLock lock(mut_this->operations_mutex); - RvoAgent *agent = memnew(RvoAgent()); - RID rid = agent_owner.make_rid(agent); + RID rid = agent_owner.make_rid(); + RvoAgent *agent = agent_owner.getornull(rid); agent->set_self(rid); return rid; } @@ -428,7 +428,7 @@ COMMAND_2(agent_set_ignore_y, RID, p_agent, bool, p_ignore) { agent->get_agent()->ignore_y_ = p_ignore; } -bool GdNavigationServer::agent_is_map_changed(RID p_agent) const { +bool GodotNavigationServer::agent_is_map_changed(RID p_agent) const { RvoAgent *agent = agent_owner.getornull(p_agent); ERR_FAIL_COND_V(agent == nullptr, false); @@ -472,7 +472,6 @@ COMMAND_1(free, RID, p_object) { active_maps.remove(map_index); active_maps_update_id.remove(map_index); map_owner.free(p_object); - memdelete(map); } else if (region_owner.owns(p_object)) { NavRegion *region = region_owner.getornull(p_object); @@ -484,7 +483,6 @@ COMMAND_1(free, RID, p_object) { } region_owner.free(p_object); - memdelete(region); } else if (agent_owner.owns(p_object)) { RvoAgent *agent = agent_owner.getornull(p_object); @@ -496,20 +494,19 @@ COMMAND_1(free, RID, p_object) { } agent_owner.free(p_object); - memdelete(agent); } else { ERR_FAIL_COND("Invalid ID."); } } -void GdNavigationServer::set_active(bool p_active) const { - GdNavigationServer *mut_this = const_cast<GdNavigationServer *>(this); +void GodotNavigationServer::set_active(bool p_active) const { + GodotNavigationServer *mut_this = const_cast<GodotNavigationServer *>(this); MutexLock lock(mut_this->operations_mutex); mut_this->active = p_active; } -void GdNavigationServer::flush_queries() { +void GodotNavigationServer::flush_queries() { // In c++ we can't be sure that this is performed in the main thread // even with mutable functions. MutexLock lock(commands_mutex); @@ -521,7 +518,7 @@ void GdNavigationServer::flush_queries() { commands.clear(); } -void GdNavigationServer::process(real_t p_delta_time) { +void GodotNavigationServer::process(real_t p_delta_time) { flush_queries(); if (!active) { diff --git a/modules/gdnavigation/gd_navigation_server.h b/modules/navigation/godot_navigation_server.h index 759d15e508..65224493fd 100644 --- a/modules/gdnavigation/gd_navigation_server.h +++ b/modules/navigation/godot_navigation_server.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* gd_navigation_server.h */ +/* godot_navigation_server.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,8 +28,8 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef GD_NAVIGATION_SERVER_H -#define GD_NAVIGATION_SERVER_H +#ifndef GODOT_NAVIGATION_SERVER_H +#define GODOT_NAVIGATION_SERVER_H #include "core/templates/local_vector.h" #include "core/templates/rid.h" @@ -61,31 +61,31 @@ virtual void F_NAME(T_0 D_0, T_1 D_1, T_2 D_2, T_3 D_3 = D_3_DEF) const; \ void MERGE(_cmd_, F_NAME)(T_0 D_0, T_1 D_1, T_2 D_2, T_3 D_3) -class GdNavigationServer; +class GodotNavigationServer; struct SetCommand { virtual ~SetCommand() {} - virtual void exec(GdNavigationServer *server) = 0; + virtual void exec(GodotNavigationServer *server) = 0; }; -class GdNavigationServer : public NavigationServer3D { +class GodotNavigationServer : public NavigationServer3D { Mutex commands_mutex; /// Mutex used to make any operation threadsafe. Mutex operations_mutex; std::vector<SetCommand *> commands; - mutable RID_PtrOwner<NavMap> map_owner; - mutable RID_PtrOwner<NavRegion> region_owner; - mutable RID_PtrOwner<RvoAgent> agent_owner; + mutable RID_Owner<NavMap> map_owner; + mutable RID_Owner<NavRegion> region_owner; + mutable RID_Owner<RvoAgent> agent_owner; bool active = true; LocalVector<NavMap *> active_maps; LocalVector<uint32_t> active_maps_update_id; public: - GdNavigationServer(); - virtual ~GdNavigationServer(); + GodotNavigationServer(); + virtual ~GodotNavigationServer(); void add_command(SetCommand *command) const; @@ -146,4 +146,4 @@ public: #undef COMMAND_2 #undef COMMAND_4_DEF -#endif // GD_NAVIGATION_SERVER_H +#endif // GODOT_NAVIGATION_SERVER_H diff --git a/modules/gdnavigation/nav_map.cpp b/modules/navigation/nav_map.cpp index 41306f0687..41306f0687 100644 --- a/modules/gdnavigation/nav_map.cpp +++ b/modules/navigation/nav_map.cpp diff --git a/modules/gdnavigation/nav_map.h b/modules/navigation/nav_map.h index 8e013a72eb..8e013a72eb 100644 --- a/modules/gdnavigation/nav_map.h +++ b/modules/navigation/nav_map.h diff --git a/modules/gdnavigation/nav_region.cpp b/modules/navigation/nav_region.cpp index 81b15a49f5..81b15a49f5 100644 --- a/modules/gdnavigation/nav_region.cpp +++ b/modules/navigation/nav_region.cpp diff --git a/modules/gdnavigation/nav_region.h b/modules/navigation/nav_region.h index f8b067e638..f8b067e638 100644 --- a/modules/gdnavigation/nav_region.h +++ b/modules/navigation/nav_region.h diff --git a/modules/gdnavigation/nav_rid.h b/modules/navigation/nav_rid.h index a0a60a3643..a0a60a3643 100644 --- a/modules/gdnavigation/nav_rid.h +++ b/modules/navigation/nav_rid.h diff --git a/modules/gdnavigation/nav_utils.h b/modules/navigation/nav_utils.h index 35da391eea..35da391eea 100644 --- a/modules/gdnavigation/nav_utils.h +++ b/modules/navigation/nav_utils.h diff --git a/modules/gdnavigation/navigation_mesh_editor_plugin.cpp b/modules/navigation/navigation_mesh_editor_plugin.cpp index aa9248d2a1..aa9248d2a1 100644 --- a/modules/gdnavigation/navigation_mesh_editor_plugin.cpp +++ b/modules/navigation/navigation_mesh_editor_plugin.cpp diff --git a/modules/gdnavigation/navigation_mesh_editor_plugin.h b/modules/navigation/navigation_mesh_editor_plugin.h index c39269865b..c39269865b 100644 --- a/modules/gdnavigation/navigation_mesh_editor_plugin.h +++ b/modules/navigation/navigation_mesh_editor_plugin.h diff --git a/modules/gdnavigation/navigation_mesh_generator.cpp b/modules/navigation/navigation_mesh_generator.cpp index b94f4b4c6c..0d8330c1da 100644 --- a/modules/gdnavigation/navigation_mesh_generator.cpp +++ b/modules/navigation/navigation_mesh_generator.cpp @@ -177,7 +177,7 @@ void NavigationMeshGenerator::_parse_geometry(Transform3D p_accumulated_transfor BoxShape3D *box = Object::cast_to<BoxShape3D>(*s); if (box) { Ref<BoxMesh> box_mesh; - box_mesh.instance(); + box_mesh.instantiate(); box_mesh->set_size(box->get_size()); mesh = box_mesh; } @@ -185,7 +185,7 @@ void NavigationMeshGenerator::_parse_geometry(Transform3D p_accumulated_transfor CapsuleShape3D *capsule = Object::cast_to<CapsuleShape3D>(*s); if (capsule) { Ref<CapsuleMesh> capsule_mesh; - capsule_mesh.instance(); + capsule_mesh.instantiate(); capsule_mesh->set_radius(capsule->get_radius()); capsule_mesh->set_mid_height(capsule->get_height() / 2.0); mesh = capsule_mesh; @@ -194,7 +194,7 @@ void NavigationMeshGenerator::_parse_geometry(Transform3D p_accumulated_transfor CylinderShape3D *cylinder = Object::cast_to<CylinderShape3D>(*s); if (cylinder) { Ref<CylinderMesh> cylinder_mesh; - cylinder_mesh.instance(); + cylinder_mesh.instantiate(); cylinder_mesh->set_height(cylinder->get_height()); cylinder_mesh->set_bottom_radius(cylinder->get_radius()); cylinder_mesh->set_top_radius(cylinder->get_radius()); @@ -204,7 +204,7 @@ void NavigationMeshGenerator::_parse_geometry(Transform3D p_accumulated_transfor SphereShape3D *sphere = Object::cast_to<SphereShape3D>(*s); if (sphere) { Ref<SphereMesh> sphere_mesh; - sphere_mesh.instance(); + sphere_mesh.instantiate(); sphere_mesh->set_radius(sphere->get_radius()); sphere_mesh->set_height(sphere->get_radius() * 2.0); mesh = sphere_mesh; diff --git a/modules/gdnavigation/navigation_mesh_generator.h b/modules/navigation/navigation_mesh_generator.h index 847c7d097b..847c7d097b 100644 --- a/modules/gdnavigation/navigation_mesh_generator.h +++ b/modules/navigation/navigation_mesh_generator.h diff --git a/modules/gdnavigation/register_types.cpp b/modules/navigation/register_types.cpp index 8443d3d242..0f3c412d4a 100644 --- a/modules/gdnavigation/register_types.cpp +++ b/modules/navigation/register_types.cpp @@ -31,9 +31,10 @@ #include "register_types.h" #include "core/config/engine.h" -#include "gd_navigation_server.h" #include "servers/navigation_server_3d.h" +#include "godot_navigation_server.h" + #ifndef _3D_DISABLED #include "navigation_mesh_generator.h" #endif @@ -42,19 +43,15 @@ #include "navigation_mesh_editor_plugin.h" #endif -/** - @author AndreaCatania -*/ - #ifndef _3D_DISABLED NavigationMeshGenerator *_nav_mesh_generator = nullptr; #endif NavigationServer3D *new_server() { - return memnew(GdNavigationServer); + return memnew(GodotNavigationServer); } -void register_gdnavigation_types() { +void register_navigation_types() { NavigationServer3DManager::set_default_server(new_server); #ifndef _3D_DISABLED @@ -65,15 +62,10 @@ void register_gdnavigation_types() { #ifdef TOOLS_ENABLED EditorPlugins::add_by_type<NavigationMeshEditorPlugin>(); - - ClassDB::APIType prev_api = ClassDB::get_current_api(); - ClassDB::set_current_api(ClassDB::API_EDITOR); - - ClassDB::set_current_api(prev_api); #endif } -void unregister_gdnavigation_types() { +void unregister_navigation_types() { #ifndef _3D_DISABLED if (_nav_mesh_generator) { memdelete(_nav_mesh_generator); diff --git a/modules/gdnavigation/register_types.h b/modules/navigation/register_types.h index c2bb08c649..4737c818eb 100644 --- a/modules/gdnavigation/register_types.h +++ b/modules/navigation/register_types.h @@ -28,14 +28,10 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -/** - @author AndreaCatania -*/ +#ifndef NAVIGATION_REGISTER_TYPES_H +#define NAVIGATION_REGISTER_TYPES_H -#ifndef GDNAVIGATION_REGISTER_TYPES_H -#define GDNAVIGATION_REGISTER_TYPES_H +void register_navigation_types(); +void unregister_navigation_types(); -void register_gdnavigation_types(); -void unregister_gdnavigation_types(); - -#endif // GDNAVIGATION_REGISTER_TYPES_H +#endif // NAVIGATION_REGISTER_TYPES_H diff --git a/modules/gdnavigation/rvo_agent.cpp b/modules/navigation/rvo_agent.cpp index 21e43d08c1..21e43d08c1 100644 --- a/modules/gdnavigation/rvo_agent.cpp +++ b/modules/navigation/rvo_agent.cpp diff --git a/modules/gdnavigation/rvo_agent.h b/modules/navigation/rvo_agent.h index 369cb1f9a3..369cb1f9a3 100644 --- a/modules/gdnavigation/rvo_agent.h +++ b/modules/navigation/rvo_agent.h diff --git a/modules/opensimplex/noise_texture.cpp b/modules/opensimplex/noise_texture.cpp index 9e0155da94..66c52ffbf9 100644 --- a/modules/opensimplex/noise_texture.cpp +++ b/modules/opensimplex/noise_texture.cpp @@ -187,6 +187,7 @@ Ref<OpenSimplexNoise> NoiseTexture::get_noise() { } void NoiseTexture::set_width(int p_width) { + ERR_FAIL_COND(p_width <= 0); if (p_width == size.x) { return; } @@ -195,6 +196,7 @@ void NoiseTexture::set_width(int p_width) { } void NoiseTexture::set_height(int p_height) { + ERR_FAIL_COND(p_height <= 0); if (p_height == size.y) { return; } diff --git a/modules/pvr/image_compress_pvrtc.cpp b/modules/pvr/image_compress_pvrtc.cpp index 4d0430fa92..980cac17d3 100644 --- a/modules/pvr/image_compress_pvrtc.cpp +++ b/modules/pvr/image_compress_pvrtc.cpp @@ -43,6 +43,10 @@ static void _compress_pvrtc1_4bpp(Image *p_img) { if (!img->is_size_po2() || img->get_width() != img->get_height()) { make_mipmaps = img->has_mipmaps(); img->resize_to_po2(true); + // Resizing can fail for some formats + if (!img->is_size_po2() || img->get_width() != img->get_height()) { + ERR_FAIL_MSG("Failed to resize the image for compression."); + } } img->convert(Image::FORMAT_RGBA8); if (!img->has_mipmaps() && make_mipmaps) { @@ -52,7 +56,7 @@ static void _compress_pvrtc1_4bpp(Image *p_img) { bool use_alpha = img->detect_alpha(); Ref<Image> new_img; - new_img.instance(); + new_img.instantiate(); new_img->create(img->get_width(), img->get_height(), img->has_mipmaps(), use_alpha ? Image::FORMAT_PVRTC1_4A : Image::FORMAT_PVRTC1_4); Vector<uint8_t> data = new_img->get_data(); diff --git a/modules/pvr/register_types.cpp b/modules/pvr/register_types.cpp index aeac564c93..ef72087d25 100644 --- a/modules/pvr/register_types.cpp +++ b/modules/pvr/register_types.cpp @@ -36,7 +36,7 @@ static Ref<ResourceFormatPVR> resource_loader_pvr; void register_pvr_types() { - resource_loader_pvr.instance(); + resource_loader_pvr.instantiate(); ResourceLoader::add_resource_format_loader(resource_loader_pvr); _register_pvrtc_compress_func(); diff --git a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp index 78b4749939..768b419348 100644 --- a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp +++ b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp @@ -129,7 +129,7 @@ Ref<AudioStreamPlayback> AudioStreamOGGVorbis::instance_playback() { "to it. AudioStreamOGGVorbis should not be created from the " "inspector or with `.new()`. Instead, load an audio file."); - ovs.instance(); + ovs.instantiate(); ovs->vorbis_stream = Ref<AudioStreamOGGVorbis>(this); ovs->ogg_alloc.alloc_buffer = (char *)memalloc(decode_mem_size); ovs->ogg_alloc.alloc_buffer_length_in_bytes = decode_mem_size; diff --git a/modules/stb_vorbis/register_types.cpp b/modules/stb_vorbis/register_types.cpp index 6f7eb53bc8..d9c6c06d65 100644 --- a/modules/stb_vorbis/register_types.cpp +++ b/modules/stb_vorbis/register_types.cpp @@ -41,7 +41,7 @@ void register_stb_vorbis_types() { #ifdef TOOLS_ENABLED if (Engine::get_singleton()->is_editor_hint()) { Ref<ResourceImporterOGGVorbis> ogg_import; - ogg_import.instance(); + ogg_import.instantiate(); ResourceFormatImporter::get_singleton()->add_importer(ogg_import); } #endif diff --git a/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp b/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp index a0de5e5f0f..85de698efd 100644 --- a/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp +++ b/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp @@ -90,7 +90,7 @@ Error ResourceImporterOGGVorbis::import(const String &p_source_file, const Strin memdelete(f); Ref<AudioStreamOGGVorbis> ogg_stream; - ogg_stream.instance(); + ogg_stream.instantiate(); ogg_stream->set_data(data); ERR_FAIL_COND_V(!ogg_stream->get_data().size(), ERR_FILE_CORRUPT); diff --git a/modules/text_server_adv/dynamic_font_adv.cpp b/modules/text_server_adv/dynamic_font_adv.cpp index c29aac05bb..62eedebb59 100644 --- a/modules/text_server_adv/dynamic_font_adv.cpp +++ b/modules/text_server_adv/dynamic_font_adv.cpp @@ -420,7 +420,7 @@ DynamicFontDataAdvanced::Character DynamicFontDataAdvanced::bitmap_to_character( Ref<Image> img = memnew(Image(tex.texture_size, tex.texture_size, 0, require_format, tex.imgdata)); if (tex.texture.is_null()) { - tex.texture.instance(); + tex.texture.instantiate(); tex.texture->create_from_image(img); } else { tex.texture->update(img); //update diff --git a/modules/text_server_fb/dynamic_font_fb.cpp b/modules/text_server_fb/dynamic_font_fb.cpp index a261ba8f37..7e77987074 100644 --- a/modules/text_server_fb/dynamic_font_fb.cpp +++ b/modules/text_server_fb/dynamic_font_fb.cpp @@ -306,7 +306,7 @@ DynamicFontDataFallback::Character DynamicFontDataFallback::bitmap_to_character( Ref<Image> img = memnew(Image(tex.texture_size, tex.texture_size, 0, require_format, tex.imgdata)); if (tex.texture.is_null()) { - tex.texture.instance(); + tex.texture.instantiate(); tex.texture->create_from_image(img); } else { tex.texture->update(img); //update diff --git a/modules/tga/image_loader_tga.cpp b/modules/tga/image_loader_tga.cpp index 6eaa2d24a8..f0d7c335bd 100644 --- a/modules/tga/image_loader_tga.cpp +++ b/modules/tga/image_loader_tga.cpp @@ -343,7 +343,7 @@ static Ref<Image> _tga_mem_loader_func(const uint8_t *p_tga, int p_size) { Error open_memfile_error = memfile.open_custom(p_tga, p_size); ERR_FAIL_COND_V_MSG(open_memfile_error, Ref<Image>(), "Could not create memfile for TGA image buffer."); Ref<Image> img; - img.instance(); + img.instantiate(); Error load_error = ImageLoaderTGA().load_image(img, &memfile, false, 1.0f); ERR_FAIL_COND_V_MSG(load_error, Ref<Image>(), "Failed to load TGA image."); return img; diff --git a/modules/theora/register_types.cpp b/modules/theora/register_types.cpp index 0218b8c7a4..fd6c9dcd3c 100644 --- a/modules/theora/register_types.cpp +++ b/modules/theora/register_types.cpp @@ -35,7 +35,7 @@ static Ref<ResourceFormatLoaderTheora> resource_loader_theora; void register_theora_types() { - resource_loader_theora.instance(); + resource_loader_theora.instantiate(); ResourceLoader::add_resource_format_loader(resource_loader_theora, true); ClassDB::register_class<VideoStreamTheora>(); diff --git a/modules/theora/video_stream_theora.cpp b/modules/theora/video_stream_theora.cpp index 4400445f30..2f6faec8ec 100644 --- a/modules/theora/video_stream_theora.cpp +++ b/modules/theora/video_stream_theora.cpp @@ -108,7 +108,7 @@ void VideoStreamPlaybackTheora::video_write() { Ref<Image> img = memnew(Image(size.x, size.y, 0, Image::FORMAT_RGBA8, frame_data)); //zero copy image creation - texture->update(img, true); //zero copy send to visual server + texture->update(img); //zero copy send to visual server frames_pending = 1; } @@ -335,7 +335,7 @@ void VideoStreamPlaybackTheora::set_file(const String &p_file) { size.y = h; Ref<Image> img; - img.instance(); + img.instantiate(); img->create(w, h, false, Image::FORMAT_RGBA8); } else { diff --git a/modules/upnp/upnp.cpp b/modules/upnp/upnp.cpp index 8e4e833d45..efe618012a 100644 --- a/modules/upnp/upnp.cpp +++ b/modules/upnp/upnp.cpp @@ -92,7 +92,7 @@ int UPNP::discover(int timeout, int ttl, const String &device_filter) { void UPNP::add_device_to_list(UPNPDev *dev, UPNPDev *devlist) { Ref<UPNPDevice> new_device; - new_device.instance(); + new_device.instantiate(); new_device->set_description_url(dev->descURL); new_device->set_service_type(dev->st); diff --git a/modules/visual_script/visual_script.cpp b/modules/visual_script/visual_script.cpp index 7badb1b717..c4b3f9ba44 100644 --- a/modules/visual_script/visual_script.cpp +++ b/modules/visual_script/visual_script.cpp @@ -725,7 +725,7 @@ int VisualScript::get_available_id() const { ///////////////////////////////// -bool VisualScript::can_instance() const { +bool VisualScript::can_instantiate() const { return true; // ScriptServer::is_scripting_enabled(); } @@ -1025,7 +1025,7 @@ void VisualScript::_set_data(const Dictionary &p_data) { MultiplayerAPI::RPCConfig nd; nd.name = E->get(); nd.rpc_mode = vsf->get_rpc_mode(); - nd.transfer_mode = NetworkedMultiplayerPeer::TRANSFER_MODE_RELIABLE; // TODO + nd.transfer_mode = MultiplayerPeer::TRANSFER_MODE_RELIABLE; // TODO if (rpc_functions.find(nd) == -1) { rpc_functions.push_back(nd); } @@ -1958,7 +1958,7 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o for (const Set<int>::Element *F = node_ids.front(); F; F = F->next()) { Ref<VisualScriptNode> node = script->nodes[F->get()].node; - VisualScriptNodeInstance *instance = node->instance(this); // Create instance. + VisualScriptNodeInstance *instance = node->instantiate(this); // Create instance. ERR_FAIL_COND(!instance); instance->base = node.ptr(); @@ -2262,7 +2262,7 @@ void VisualScriptLanguage::get_string_delimiters(List<String> *p_delimiters) con Ref<Script> VisualScriptLanguage::get_template(const String &p_class_name, const String &p_base_class_name) const { Ref<VisualScript> script; - script.instance(); + script.instantiate(); script->set_instance_base_type(p_base_class_name); return script; } @@ -2276,7 +2276,7 @@ void VisualScriptLanguage::make_template(const String &p_class_name, const Strin script->set_instance_base_type(p_base_class_name); } -bool VisualScriptLanguage::validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path, List<String> *r_functions, List<ScriptLanguage::Warning> *r_warnings, Set<int> *r_safe_lines) const { +bool VisualScriptLanguage::validate(const String &p_script, const String &p_path, List<String> *r_functions, List<ScriptLanguage::ScriptError> *r_errors, List<ScriptLanguage::Warning> *r_warnings, Set<int> *r_safe_lines) const { return false; } diff --git a/modules/visual_script/visual_script.h b/modules/visual_script/visual_script.h index 438ec99a56..932ebeb27f 100644 --- a/modules/visual_script/visual_script.h +++ b/modules/visual_script/visual_script.h @@ -87,7 +87,7 @@ public: void set_breakpoint(bool p_breakpoint); bool is_breakpoint() const; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) = 0; + virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) = 0; struct TypeGuess { Variant::Type type = Variant::NIL; @@ -325,7 +325,7 @@ public: void set_instance_base_type(const StringName &p_type); - virtual bool can_instance() const override; + virtual bool can_instantiate() const override; virtual Ref<Script> get_base_script() const override; virtual StringName get_instance_base_type() const override; @@ -571,7 +571,7 @@ public: virtual Ref<Script> get_template(const String &p_class_name, const String &p_base_class_name) const; virtual bool is_using_templates(); virtual void make_template(const String &p_class_name, const String &p_base_class_name, Ref<Script> &p_script); - virtual bool validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path = "", List<String> *r_functions = nullptr, List<ScriptLanguage::Warning> *r_warnings = nullptr, Set<int> *r_safe_lines = nullptr) const; + virtual bool validate(const String &p_script, const String &p_path = "", List<String> *r_functions = nullptr, List<ScriptLanguage::ScriptError> *r_errors = nullptr, List<ScriptLanguage::Warning> *r_warnings = nullptr, Set<int> *r_safe_lines = nullptr) const; virtual Script *create_script() const; virtual bool has_named_classes() const; virtual bool supports_builtin_mode() const; @@ -619,7 +619,7 @@ public: template <class T> static Ref<VisualScriptNode> create_node_generic(const String &p_name) { Ref<T> node; - node.instance(); + node.instantiate(); return node; } diff --git a/modules/visual_script/visual_script_builtin_funcs.cpp b/modules/visual_script/visual_script_builtin_funcs.cpp index a3133f126d..f17ad62531 100644 --- a/modules/visual_script/visual_script_builtin_funcs.cpp +++ b/modules/visual_script/visual_script_builtin_funcs.cpp @@ -1187,7 +1187,7 @@ public: } }; -VisualScriptNodeInstance *VisualScriptBuiltinFunc::instance(VisualScriptInstance *p_instance) { +VisualScriptNodeInstance *VisualScriptBuiltinFunc::instantiate(VisualScriptInstance *p_instance) { VisualScriptNodeInstanceBuiltinFunc *instance = memnew(VisualScriptNodeInstanceBuiltinFunc); instance->node = this; instance->instance = p_instance; diff --git a/modules/visual_script/visual_script_builtin_funcs.h b/modules/visual_script/visual_script_builtin_funcs.h index 1fafaf1d98..7196d4b46a 100644 --- a/modules/visual_script/visual_script_builtin_funcs.h +++ b/modules/visual_script/visual_script_builtin_funcs.h @@ -139,7 +139,7 @@ public: void set_func(BuiltinFunc p_which); BuiltinFunc get_func(); - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; + virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override; VisualScriptBuiltinFunc(VisualScriptBuiltinFunc::BuiltinFunc func); VisualScriptBuiltinFunc(); diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index 96f103f95a..8712bfa06b 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -1300,10 +1300,10 @@ void VisualScriptEditor::_create_function_dialog() { void VisualScriptEditor::_create_function() { String name = _validate_name((func_name_box->get_text() == "") ? "new_func" : func_name_box->get_text()); selected = name; - Vector2 ofs = _get_available_pos(); + Vector2 pos = _get_available_pos(); Ref<VisualScriptFunction> func_node; - func_node.instance(); + func_node.instantiate(); func_node->set_name(name); for (int i = 0; i < func_input_vbox->get_child_count(); i++) { @@ -1322,7 +1322,7 @@ void VisualScriptEditor::_create_function() { undo_redo->create_action(TTR("Add Function")); undo_redo->add_do_method(script.ptr(), "add_function", name, func_node_id); undo_redo->add_undo_method(script.ptr(), "remove_function", name); - undo_redo->add_do_method(script.ptr(), "add_node", func_node_id, func_node, ofs); + undo_redo->add_do_method(script.ptr(), "add_node", func_node_id, func_node, pos); undo_redo->add_undo_method(script.ptr(), "remove_node", func_node_id); undo_redo->add_do_method(this, "_update_members"); undo_redo->add_undo_method(this, "_update_members"); @@ -1417,18 +1417,18 @@ void VisualScriptEditor::_member_button(Object *p_item, int p_column, int p_butt } else if (p_button == 0) { String name = _validate_name("new_function"); selected = name; - Vector2 ofs = _get_available_pos(); + Vector2 pos = _get_available_pos(); Ref<VisualScriptFunction> func_node; - func_node.instance(); + func_node.instantiate(); func_node->set_name(name); int fn_id = script->get_available_id(); undo_redo->create_action(TTR("Add Function")); undo_redo->add_do_method(script.ptr(), "add_function", name, fn_id); - undo_redo->add_do_method(script.ptr(), "add_node", fn_id, func_node, ofs); + undo_redo->add_do_method(script.ptr(), "add_node", fn_id, func_node, pos); undo_redo->add_undo_method(script.ptr(), "remove_function", name); - undo_redo->add_do_method(script.ptr(), "remove_node", fn_id); + undo_redo->add_undo_method(script.ptr(), "remove_node", fn_id); undo_redo->add_do_method(this, "_update_members"); undo_redo->add_undo_method(this, "_update_members"); undo_redo->add_do_method(this, "_update_graph"); @@ -1621,17 +1621,19 @@ void VisualScriptEditor::_expression_text_changed(const String &p_text, int p_id updating_graph = false; } -Vector2 VisualScriptEditor::_get_available_pos(bool centered, Vector2 ofs) const { - if (centered) { - ofs = graph->get_scroll_ofs() + graph->get_size() * 0.5; - } - +Vector2 VisualScriptEditor::_get_pos_in_graph(Vector2 p_point) const { + Vector2 pos = (graph->get_scroll_ofs() + p_point) / (graph->get_zoom() * EDSCALE); if (graph->is_using_snap()) { int snap = graph->get_snap(); - ofs = ofs.snapped(Vector2(snap, snap)); + pos = pos.snapped(Vector2(snap, snap)); } + return pos; +} - ofs /= EDSCALE; +Vector2 VisualScriptEditor::_get_available_pos(bool p_centered, Vector2 p_pos) const { + if (p_centered) { + p_pos = _get_pos_in_graph(graph->get_size() * 0.5); + } while (true) { bool exists = false; @@ -1639,8 +1641,8 @@ Vector2 VisualScriptEditor::_get_available_pos(bool centered, Vector2 ofs) const script->get_node_list(&existing); for (List<int>::Element *E = existing.front(); E; E = E->next()) { Point2 pos = script->get_node_position(E->get()); - if (pos.distance_to(ofs) < 50) { - ofs += Vector2(graph->get_snap(), graph->get_snap()); + if (pos.distance_to(p_pos) < 50) { + p_pos += Vector2(graph->get_snap(), graph->get_snap()); exists = true; break; } @@ -1651,7 +1653,7 @@ Vector2 VisualScriptEditor::_get_available_pos(bool centered, Vector2 ofs) const break; } - return ofs; + return p_pos; } String VisualScriptEditor::_validate_name(const String &p_name) const { @@ -2049,16 +2051,9 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da return; } - Vector2 ofs = graph->get_scroll_ofs() + p_point; - - if (graph->is_using_snap()) { - int snap = graph->get_snap(); - ofs = ofs.snapped(Vector2(snap, snap)); - } - - ofs /= EDSCALE; + Vector2 pos = _get_pos_in_graph(p_point); - int new_id = _create_new_node_from_name(d["node_type"], ofs); + int new_id = _create_new_node_from_name(d["node_type"], pos); Node *node = graph->get_node(itos(new_id)); if (node) { @@ -2073,23 +2068,17 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da #else bool use_set = Input::get_singleton()->is_key_pressed(KEY_CTRL); #endif - Vector2 ofs = graph->get_scroll_ofs() + p_point; - if (graph->is_using_snap()) { - int snap = graph->get_snap(); - ofs = ofs.snapped(Vector2(snap, snap)); - } - - ofs /= EDSCALE; + Vector2 pos = _get_pos_in_graph(p_point); Ref<VisualScriptNode> vnode; if (use_set) { Ref<VisualScriptVariableSet> vnodes; - vnodes.instance(); + vnodes.instantiate(); vnodes->set_variable(d["variable"]); vnode = vnodes; } else { Ref<VisualScriptVariableGet> vnodeg; - vnodeg.instance(); + vnodeg.instantiate(); vnodeg->set_variable(d["variable"]); vnode = vnodeg; } @@ -2097,7 +2086,7 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da int new_id = script->get_available_id(); undo_redo->create_action(TTR("Add Node")); - undo_redo->add_do_method(script.ptr(), "add_node", new_id, vnode, ofs); + undo_redo->add_do_method(script.ptr(), "add_node", new_id, vnode, pos); undo_redo->add_undo_method(script.ptr(), "remove_node", new_id); undo_redo->add_do_method(this, "_update_graph"); undo_redo->add_undo_method(this, "_update_graph"); @@ -2111,22 +2100,16 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da } if (String(d["type"]) == "visual_script_function_drag") { - Vector2 ofs = graph->get_scroll_ofs() + p_point; - if (graph->is_using_snap()) { - int snap = graph->get_snap(); - ofs = ofs.snapped(Vector2(snap, snap)); - } - - ofs /= EDSCALE; + Vector2 pos = _get_pos_in_graph(p_point); Ref<VisualScriptFunctionCall> vnode; - vnode.instance(); + vnode.instantiate(); vnode->set_call_mode(VisualScriptFunctionCall::CALL_MODE_SELF); int new_id = script->get_available_id(); undo_redo->create_action(TTR("Add Node")); - undo_redo->add_do_method(script.ptr(), "add_node", new_id, vnode, ofs); + undo_redo->add_do_method(script.ptr(), "add_node", new_id, vnode, pos); undo_redo->add_do_method(vnode.ptr(), "set_base_type", script->get_instance_base_type()); undo_redo->add_do_method(vnode.ptr(), "set_function", d["function"]); @@ -2143,22 +2126,16 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da } if (String(d["type"]) == "visual_script_signal_drag") { - Vector2 ofs = graph->get_scroll_ofs() + p_point; - if (graph->is_using_snap()) { - int snap = graph->get_snap(); - ofs = ofs.snapped(Vector2(snap, snap)); - } - - ofs /= EDSCALE; + Vector2 pos = _get_pos_in_graph(p_point); Ref<VisualScriptEmitSignal> vnode; - vnode.instance(); + vnode.instantiate(); vnode->set_signal(d["signal"]); int new_id = script->get_available_id(); undo_redo->create_action(TTR("Add Node")); - undo_redo->add_do_method(script.ptr(), "add_node", new_id, vnode, ofs); + undo_redo->add_do_method(script.ptr(), "add_node", new_id, vnode, pos); undo_redo->add_undo_method(script.ptr(), "remove_node", new_id); undo_redo->add_do_method(this, "_update_graph"); undo_redo->add_undo_method(this, "_update_graph"); @@ -2172,22 +2149,16 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da } if (String(d["type"]) == "resource") { - Vector2 ofs = graph->get_scroll_ofs() + p_point; - if (graph->is_using_snap()) { - int snap = graph->get_snap(); - ofs = ofs.snapped(Vector2(snap, snap)); - } - - ofs /= EDSCALE; + Vector2 pos = _get_pos_in_graph(p_point); Ref<VisualScriptPreload> prnode; - prnode.instance(); + prnode.instantiate(); prnode->set_preload(d["resource"]); int new_id = script->get_available_id(); undo_redo->create_action(TTR("Add Preload Node")); - undo_redo->add_do_method(script.ptr(), "add_node", new_id, prnode, ofs); + undo_redo->add_do_method(script.ptr(), "add_node", new_id, prnode, pos); undo_redo->add_undo_method(script.ptr(), "remove_node", new_id); undo_redo->add_do_method(this, "_update_graph"); undo_redo->add_undo_method(this, "_update_graph"); @@ -2201,13 +2172,7 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da } if (String(d["type"]) == "files") { - Vector2 ofs = graph->get_scroll_ofs() + p_point; - if (graph->is_using_snap()) { - int snap = graph->get_snap(); - ofs = ofs.snapped(Vector2(snap, snap)); - } - - ofs /= EDSCALE; + Vector2 pos = _get_pos_in_graph(p_point); Array files = d["files"]; @@ -2224,14 +2189,14 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da } Ref<VisualScriptPreload> prnode; - prnode.instance(); + prnode.instantiate(); prnode->set_preload(res); - undo_redo->add_do_method(script.ptr(), "add_node", new_id, prnode, ofs); + undo_redo->add_do_method(script.ptr(), "add_node", new_id, prnode, pos); undo_redo->add_undo_method(script.ptr(), "remove_node", new_id); new_ids.push_back(new_id); new_id++; - ofs += Vector2(20, 20) * EDSCALE; + pos += Vector2(20, 20); } undo_redo->add_do_method(this, "_update_graph"); @@ -2264,13 +2229,7 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da Array nodes = d["nodes"]; - Vector2 ofs = graph->get_scroll_ofs() + p_point; - - if (graph->is_using_snap()) { - int snap = graph->get_snap(); - ofs = ofs.snapped(Vector2(snap, snap)); - } - ofs /= EDSCALE; + Vector2 pos = _get_pos_in_graph(p_point); undo_redo->create_action(TTR("Add Node(s) From Tree")); int base_id = script->get_available_id(); @@ -2290,13 +2249,13 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da if (use_node) { Ref<VisualScriptSceneNode> scene_node; - scene_node.instance(); + scene_node.instantiate(); scene_node->set_node_path(sn->get_path_to(node)); n = scene_node; } else { // ! Doesn't work properly. Ref<VisualScriptFunctionCall> call; - call.instance(); + call.instantiate(); call->set_call_mode(VisualScriptFunctionCall::CALL_MODE_NODE_PATH); call->set_base_path(sn->get_path_to(node)); call->set_base_type(node->get_class()); @@ -2305,11 +2264,11 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da selecting_method_id = base_id; } - undo_redo->add_do_method(script.ptr(), "add_node", base_id, n, ofs); + undo_redo->add_do_method(script.ptr(), "add_node", base_id, n, pos); undo_redo->add_undo_method(script.ptr(), "remove_node", base_id); base_id++; - ofs += Vector2(25, 25); + pos += Vector2(25, 25); } undo_redo->add_do_method(this, "_update_graph"); undo_redo->add_undo_method(this, "_update_graph"); @@ -2331,14 +2290,8 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da } Node *node = Object::cast_to<Node>(obj); - Vector2 ofs = graph->get_scroll_ofs() + p_point; - - if (graph->is_using_snap()) { - int snap = graph->get_snap(); - ofs = ofs.snapped(Vector2(snap, snap)); - } + Vector2 pos = _get_pos_in_graph(p_point); - ofs /= EDSCALE; #ifdef OSX_ENABLED bool use_get = Input::get_singleton()->is_key_pressed(KEY_META); #else @@ -2358,7 +2311,7 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da if (!use_get) { Ref<VisualScriptPropertySet> pset; - pset.instance(); + pset.instantiate(); pset->set_call_mode(VisualScriptPropertySet::CALL_MODE_INSTANCE); pset->set_base_type(obj->get_class()); /*if (use_value) { @@ -2368,14 +2321,14 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da vnode = pset; } else { Ref<VisualScriptPropertyGet> pget; - pget.instance(); + pget.instantiate(); pget->set_call_mode(VisualScriptPropertyGet::CALL_MODE_INSTANCE); pget->set_base_type(obj->get_class()); vnode = pget; } - undo_redo->add_do_method(script.ptr(), "add_node", base_id, vnode, ofs); + undo_redo->add_do_method(script.ptr(), "add_node", base_id, vnode, pos); undo_redo->add_do_method(vnode.ptr(), "set_property", d["property"]); if (!use_get) { undo_redo->add_do_method(vnode.ptr(), "set_default_input_value", 0, d["value"]); @@ -2400,7 +2353,7 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da if (!use_get) { Ref<VisualScriptPropertySet> pset; - pset.instance(); + pset.instantiate(); if (sn == node) { pset->set_call_mode(VisualScriptPropertySet::CALL_MODE_SELF); } else { @@ -2411,7 +2364,7 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da vnode = pset; } else { Ref<VisualScriptPropertyGet> pget; - pget.instance(); + pget.instantiate(); if (sn == node) { pget->set_call_mode(VisualScriptPropertyGet::CALL_MODE_SELF); } else { @@ -2420,7 +2373,7 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da } vnode = pget; } - undo_redo->add_do_method(script.ptr(), "add_node", base_id, vnode, ofs); + undo_redo->add_do_method(script.ptr(), "add_node", base_id, vnode, pos); undo_redo->add_do_method(vnode.ptr(), "set_property", d["property"]); if (!use_get) { undo_redo->add_do_method(vnode.ptr(), "set_default_input_value", 0, d["value"]); @@ -2666,7 +2619,7 @@ void VisualScriptEditor::add_callback(const String &p_function, PackedStringArra } Ref<VisualScriptFunction> func; - func.instance(); + func.instantiate(); for (int i = 0; i < p_args.size(); i++) { String name = p_args[i]; Variant::Type type = Variant::NIL; @@ -3009,7 +2962,7 @@ void VisualScriptEditor::_graph_connect_to_empty(const String &p_from, int p_fro if (!vsn.is_valid()) { return; } - if (vsn->get_output_value_port_count()) { + if (vsn->get_output_value_port_count() || vsn->get_output_sequence_port_count()) { port_action_pos = p_release_pos; } @@ -3075,19 +3028,12 @@ VisualScriptNode::TypeGuess VisualScriptEditor::_guess_output_type(int p_port_ac } void VisualScriptEditor::_port_action_menu(int p_option) { - Vector2 ofs = graph->get_scroll_ofs() + port_action_pos; - if (graph->is_using_snap()) { - int snap = graph->get_snap(); - ofs = ofs.snapped(Vector2(snap, snap)); - } - ofs /= EDSCALE; - Set<int> vn; switch (p_option) { case CREATE_CALL_SET_GET: { Ref<VisualScriptFunctionCall> n; - n.instance(); + n.instantiate(); VisualScriptNode::TypeGuess tg = _guess_output_type(port_action_node, port_action_output, vn); @@ -3172,13 +3118,7 @@ void VisualScriptEditor::connect_data(Ref<VisualScriptNode> vnode_old, Ref<Visua } void VisualScriptEditor::_selected_connect_node(const String &p_text, const String &p_category, const bool p_connecting) { - Vector2 ofs = graph->get_scroll_ofs() + port_action_pos; - if (graph->is_using_snap()) { - int snap = graph->get_snap(); - ofs = ofs.snapped(Vector2(snap, snap)); - } - ofs /= EDSCALE; - ofs /= graph->get_zoom(); + Vector2 pos = _get_pos_in_graph(port_action_pos); Set<int> vn; @@ -3216,7 +3156,7 @@ void VisualScriptEditor::_selected_connect_node(const String &p_text, const Stri } undo_redo->create_action(TTR("Add Node")); - undo_redo->add_do_method(script.ptr(), "add_node", new_id, vnode_new, ofs); + undo_redo->add_do_method(script.ptr(), "add_node", new_id, vnode_new, pos); if (vnode_old.is_valid() && p_connecting) { connect_seq(vnode_old, vnode_new, new_id); connect_data(vnode_old, vnode_new, new_id); @@ -3234,16 +3174,16 @@ void VisualScriptEditor::_selected_connect_node(const String &p_text, const Stri if (p_category == String("method")) { Ref<VisualScriptFunctionCall> n; - n.instance(); + n.instantiate(); vnode = n; } else if (p_category == String("set")) { Ref<VisualScriptPropertySet> n; - n.instance(); + n.instantiate(); vnode = n; script_prop_set = n; } else if (p_category == String("get")) { Ref<VisualScriptPropertyGet> n; - n.instance(); + n.instantiate(); n->set_property(p_text); vnode = n; } @@ -3251,35 +3191,35 @@ void VisualScriptEditor::_selected_connect_node(const String &p_text, const Stri if (p_category == String("action")) { if (p_text == "VisualScriptCondition") { Ref<VisualScriptCondition> n; - n.instance(); + n.instantiate(); vnode = n; } if (p_text == "VisualScriptSwitch") { Ref<VisualScriptSwitch> n; - n.instance(); + n.instantiate(); vnode = n; } else if (p_text == "VisualScriptSequence") { Ref<VisualScriptSequence> n; - n.instance(); + n.instantiate(); vnode = n; } else if (p_text == "VisualScriptIterator") { Ref<VisualScriptIterator> n; - n.instance(); + n.instantiate(); vnode = n; } else if (p_text == "VisualScriptWhile") { Ref<VisualScriptWhile> n; - n.instance(); + n.instantiate(); vnode = n; } else if (p_text == "VisualScriptReturn") { Ref<VisualScriptReturn> n; - n.instance(); + n.instantiate(); vnode = n; } } int new_id = script->get_available_id(); undo_redo->create_action(TTR("Add Node")); - undo_redo->add_do_method(script.ptr(), "add_node", new_id, vnode, ofs); + undo_redo->add_do_method(script.ptr(), "add_node", new_id, vnode, pos); undo_redo->add_undo_method(script.ptr(), "remove_node", new_id); undo_redo->add_do_method(this, "_update_graph", new_id); undo_redo->add_undo_method(this, "_update_graph", new_id); @@ -3468,7 +3408,7 @@ void VisualScriptEditor::_selected_new_virtual_method(const String &p_text, cons selected = name; Ref<VisualScriptFunction> func_node; - func_node.instance(); + func_node.instantiate(); func_node->set_name(name); int fn_id = script->get_available_id(); undo_redo->create_action(TTR("Add Function")); @@ -3478,18 +3418,18 @@ void VisualScriptEditor::_selected_new_virtual_method(const String &p_text, cons func_node->add_argument(minfo.arguments[i].type, minfo.arguments[i].name, -1, minfo.arguments[i].hint, minfo.arguments[i].hint_string); } - Vector2 ofs = _get_available_pos(); + Vector2 pos = _get_available_pos(); - undo_redo->add_do_method(script.ptr(), "add_node", fn_id, func_node, ofs); + undo_redo->add_do_method(script.ptr(), "add_node", fn_id, func_node, pos); undo_redo->add_undo_method(script.ptr(), "remove_node", fn_id); if (minfo.return_val.type != Variant::NIL || minfo.return_val.usage & PROPERTY_USAGE_NIL_IS_VARIANT) { Ref<VisualScriptReturn> ret_node; - ret_node.instance(); + ret_node.instantiate(); ret_node->set_return_type(minfo.return_val.type); ret_node->set_enable_return_value(true); ret_node->set_name(name); int nid = script->get_available_id() + 1; - undo_redo->add_do_method(script.ptr(), "add_node", nid, ret_node, _get_available_pos(false, ofs + Vector2(500, 0))); + undo_redo->add_do_method(script.ptr(), "add_node", nid, ret_node, _get_available_pos(false, pos + Vector2(500, 0))); undo_redo->add_undo_method(script.ptr(), "remove_node", nid); } @@ -3993,16 +3933,16 @@ void VisualScriptEditor::_menu_option(int p_what) { { String new_fn = _validate_name("new_function"); - Vector2 ofs = _get_available_pos(false, script->get_node_position(start_node) - Vector2(80, 150)); + Vector2 pos = _get_available_pos(false, script->get_node_position(start_node) - Vector2(80, 150)); Ref<VisualScriptFunction> func_node; - func_node.instance(); + func_node.instantiate(); func_node->set_name(new_fn); undo_redo->create_action(TTR("Create Function")); undo_redo->add_do_method(script.ptr(), "add_function", new_fn, fn_id); - undo_redo->add_do_method(script.ptr(), "add_node", fn_id, func_node, ofs); + undo_redo->add_do_method(script.ptr(), "add_node", fn_id, func_node, pos); undo_redo->add_undo_method(script.ptr(), "remove_function", new_fn); undo_redo->add_undo_method(script.ptr(), "remove_node", fn_id); undo_redo->add_do_method(this, "_update_members"); @@ -4041,12 +3981,12 @@ void VisualScriptEditor::_menu_option(int p_what) { int m = 1; for (Set<int>::Element *G = end_nodes.front(); G; G = G->next()) { Ref<VisualScriptReturn> ret_node; - ret_node.instance(); + ret_node.instantiate(); int ret_id = fn_id + (m++); selections.insert(ret_id); - Vector2 ofsi = _get_available_pos(false, script->get_node_position(G->get()) + Vector2(80, -100)); - undo_redo->add_do_method(script.ptr(), "add_node", ret_id, ret_node, ofsi); + Vector2 posi = _get_available_pos(false, script->get_node_position(G->get()) + Vector2(80, -100)); + undo_redo->add_do_method(script.ptr(), "add_node", ret_id, ret_node, posi); undo_redo->add_undo_method(script.ptr(), "remove_node", ret_id); undo_redo->add_do_method(script.ptr(), "sequence_connect", G->get(), 0, ret_id); @@ -4529,7 +4469,7 @@ void VisualScriptEditor::register_editor() { Ref<VisualScriptNode> _VisualScriptEditor::create_node_custom(const String &p_name) { Ref<VisualScriptCustomNode> node; - node.instance(); + node.instantiate(); node->set_script(singleton->custom_nodes[p_name]); return node; } diff --git a/modules/visual_script/visual_script_editor.h b/modules/visual_script/visual_script_editor.h index ca06b807cc..1f0f087be7 100644 --- a/modules/visual_script/visual_script_editor.h +++ b/modules/visual_script/visual_script_editor.h @@ -226,7 +226,8 @@ class VisualScriptEditor : public ScriptEditorBase { void _update_node_size(int p_id); void _port_name_focus_out(const Node *p_name_box, int p_id, int p_port, bool is_input); - Vector2 _get_available_pos(bool centered = true, Vector2 ofs = Vector2()) const; + Vector2 _get_pos_in_graph(Vector2 p_point) const; + Vector2 _get_available_pos(bool p_centered = true, Vector2 p_pos = Vector2()) const; bool node_has_sequence_connections(int p_id); diff --git a/modules/visual_script/visual_script_expression.cpp b/modules/visual_script/visual_script_expression.cpp index cb4230bea9..d63fbeb726 100644 --- a/modules/visual_script/visual_script_expression.cpp +++ b/modules/visual_script/visual_script_expression.cpp @@ -1498,7 +1498,7 @@ public: } }; -VisualScriptNodeInstance *VisualScriptExpression::instance(VisualScriptInstance *p_instance) { +VisualScriptNodeInstance *VisualScriptExpression::instantiate(VisualScriptInstance *p_instance) { _compile_expression(); VisualScriptNodeInstanceExpression *instance = memnew(VisualScriptNodeInstanceExpression); instance->instance = p_instance; diff --git a/modules/visual_script/visual_script_expression.h b/modules/visual_script/visual_script_expression.h index c35075ea53..ef16222b42 100644 --- a/modules/visual_script/visual_script_expression.h +++ b/modules/visual_script/visual_script_expression.h @@ -273,7 +273,7 @@ public: virtual String get_text() const override; virtual String get_category() const override { return "operators"; } - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; + virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override; VisualScriptExpression(); ~VisualScriptExpression(); diff --git a/modules/visual_script/visual_script_flow_control.cpp b/modules/visual_script/visual_script_flow_control.cpp index e977f9c96b..af86f90b25 100644 --- a/modules/visual_script/visual_script_flow_control.cpp +++ b/modules/visual_script/visual_script_flow_control.cpp @@ -138,7 +138,7 @@ public: } }; -VisualScriptNodeInstance *VisualScriptReturn::instance(VisualScriptInstance *p_instance) { +VisualScriptNodeInstance *VisualScriptReturn::instantiate(VisualScriptInstance *p_instance) { VisualScriptNodeInstanceReturn *instance = memnew(VisualScriptNodeInstanceReturn); instance->node = this; instance->instance = p_instance; @@ -154,7 +154,7 @@ VisualScriptReturn::VisualScriptReturn() { template <bool with_value> static Ref<VisualScriptNode> create_return_node(const String &p_name) { Ref<VisualScriptReturn> node; - node.instance(); + node.instantiate(); node->set_enable_return_value(with_value); return node; } @@ -231,7 +231,7 @@ public: } }; -VisualScriptNodeInstance *VisualScriptCondition::instance(VisualScriptInstance *p_instance) { +VisualScriptNodeInstance *VisualScriptCondition::instantiate(VisualScriptInstance *p_instance) { VisualScriptNodeInstanceCondition *instance = memnew(VisualScriptNodeInstanceCondition); instance->node = this; instance->instance = p_instance; @@ -311,7 +311,7 @@ public: } }; -VisualScriptNodeInstance *VisualScriptWhile::instance(VisualScriptInstance *p_instance) { +VisualScriptNodeInstance *VisualScriptWhile::instantiate(VisualScriptInstance *p_instance) { VisualScriptNodeInstanceWhile *instance = memnew(VisualScriptNodeInstanceWhile); instance->node = this; instance->instance = p_instance; @@ -435,7 +435,7 @@ public: } }; -VisualScriptNodeInstance *VisualScriptIterator::instance(VisualScriptInstance *p_instance) { +VisualScriptNodeInstance *VisualScriptIterator::instantiate(VisualScriptInstance *p_instance) { VisualScriptNodeInstanceIterator *instance = memnew(VisualScriptNodeInstanceIterator); instance->node = this; instance->instance = p_instance; @@ -534,7 +534,7 @@ public: } }; -VisualScriptNodeInstance *VisualScriptSequence::instance(VisualScriptInstance *p_instance) { +VisualScriptNodeInstance *VisualScriptSequence::instantiate(VisualScriptInstance *p_instance) { VisualScriptNodeInstanceSequence *instance = memnew(VisualScriptNodeInstanceSequence); instance->node = this; instance->instance = p_instance; @@ -618,7 +618,7 @@ public: } }; -VisualScriptNodeInstance *VisualScriptSwitch::instance(VisualScriptInstance *p_instance) { +VisualScriptNodeInstance *VisualScriptSwitch::instantiate(VisualScriptInstance *p_instance) { VisualScriptNodeInstanceSwitch *instance = memnew(VisualScriptNodeInstanceSwitch); instance->instance = p_instance; instance->case_count = case_values.size(); @@ -831,7 +831,7 @@ public: } }; -VisualScriptNodeInstance *VisualScriptTypeCast::instance(VisualScriptInstance *p_instance) { +VisualScriptNodeInstance *VisualScriptTypeCast::instantiate(VisualScriptInstance *p_instance) { VisualScriptNodeInstanceTypeCast *instance = memnew(VisualScriptNodeInstanceTypeCast); instance->instance = p_instance; instance->base_type = base_type; diff --git a/modules/visual_script/visual_script_flow_control.h b/modules/visual_script/visual_script_flow_control.h index d9c4dedafd..73822fcc37 100644 --- a/modules/visual_script/visual_script_flow_control.h +++ b/modules/visual_script/visual_script_flow_control.h @@ -64,7 +64,7 @@ public: void set_enable_return_value(bool p_enable); bool is_return_value_enabled() const; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; + virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override; VisualScriptReturn(); }; @@ -91,7 +91,7 @@ public: virtual String get_text() const override; virtual String get_category() const override { return "flow_control"; } - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; + virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override; VisualScriptCondition(); }; @@ -118,7 +118,7 @@ public: virtual String get_text() const override; virtual String get_category() const override { return "flow_control"; } - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; + virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override; VisualScriptWhile(); }; @@ -145,7 +145,7 @@ public: virtual String get_text() const override; virtual String get_category() const override { return "flow_control"; } - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; + virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override; VisualScriptIterator(); }; @@ -177,7 +177,7 @@ public: void set_steps(int p_steps); int get_steps() const; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; + virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override; VisualScriptSequence(); }; @@ -220,7 +220,7 @@ public: virtual String get_text() const override; virtual String get_category() const override { return "flow_control"; } - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; + virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override; VisualScriptSwitch(); }; @@ -258,7 +258,7 @@ public: virtual TypeGuess guess_output_type(TypeGuess *p_inputs, int p_output) const override; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; + virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override; VisualScriptTypeCast(); }; diff --git a/modules/visual_script/visual_script_func_nodes.cpp b/modules/visual_script/visual_script_func_nodes.cpp index a0ba7b1962..8f7b514881 100644 --- a/modules/visual_script/visual_script_func_nodes.cpp +++ b/modules/visual_script/visual_script_func_nodes.cpp @@ -513,19 +513,19 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo &property) const if (property.name == "base_script") { if (call_mode != CALL_MODE_INSTANCE) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } } if (property.name == "basic_type") { if (call_mode != CALL_MODE_BASIC_TYPE) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } } if (property.name == "singleton") { if (call_mode != CALL_MODE_SINGLETON) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } else { List<Engine::Singleton> names; Engine::get_singleton()->get_singletons(&names); @@ -543,7 +543,7 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo &property) const if (property.name == "node_path") { if (call_mode != CALL_MODE_NODE_PATH) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } else { Node *bnode = _get_base_node(); if (bnode) { @@ -614,7 +614,7 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo &property) const } if (mc == 0) { - property.usage = 0; //do not show + property.usage = PROPERTY_USAGE_NONE; //do not show } else { property.hint_string = "0," + itos(mc) + ",1"; } @@ -622,7 +622,7 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo &property) const if (property.name == "rpc_call_mode") { if (call_mode == CALL_MODE_BASIC_TYPE) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } } } @@ -856,7 +856,7 @@ public: } }; -VisualScriptNodeInstance *VisualScriptFunctionCall::instance(VisualScriptInstance *p_instance) { +VisualScriptNodeInstance *VisualScriptFunctionCall::instantiate(VisualScriptInstance *p_instance) { VisualScriptNodeInstanceFunctionCall *instance = memnew(VisualScriptNodeInstanceFunctionCall); instance->node = this; instance->instance = p_instance; @@ -891,7 +891,7 @@ VisualScriptFunctionCall::VisualScriptFunctionCall() { template <VisualScriptFunctionCall::CallMode cmode> static Ref<VisualScriptNode> create_function_call_node(const String &p_name) { Ref<VisualScriptFunctionCall> node; - node.instance(); + node.instantiate(); node->set_call_mode(cmode); return node; } @@ -1278,19 +1278,19 @@ void VisualScriptPropertySet::_validate_property(PropertyInfo &property) const { if (property.name == "base_script") { if (call_mode != CALL_MODE_INSTANCE) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } } if (property.name == "basic_type") { if (call_mode != CALL_MODE_BASIC_TYPE) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } } if (property.name == "node_path") { if (call_mode != CALL_MODE_NODE_PATH) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } else { Node *bnode = _get_base_node(); if (bnode) { @@ -1352,7 +1352,7 @@ void VisualScriptPropertySet::_validate_property(PropertyInfo &property) const { property.hint_string = options; property.type = Variant::STRING; if (options == "") { - property.usage = 0; //hide if type has no usable index + property.usage = PROPERTY_USAGE_NONE; //hide if type has no usable index } } } @@ -1587,7 +1587,7 @@ public: } }; -VisualScriptNodeInstance *VisualScriptPropertySet::instance(VisualScriptInstance *p_instance) { +VisualScriptNodeInstance *VisualScriptPropertySet::instantiate(VisualScriptInstance *p_instance) { VisualScriptNodeInstancePropertySet *instance = memnew(VisualScriptNodeInstancePropertySet); instance->node = this; instance->instance = p_instance; @@ -1618,7 +1618,7 @@ VisualScriptPropertySet::VisualScriptPropertySet() { template <VisualScriptPropertySet::CallMode cmode> static Ref<VisualScriptNode> create_property_set_node(const String &p_name) { Ref<VisualScriptPropertySet> node; - node.instance(); + node.instantiate(); node->set_call_mode(cmode); return node; } @@ -1956,19 +1956,19 @@ void VisualScriptPropertyGet::_validate_property(PropertyInfo &property) const { if (property.name == "base_script") { if (call_mode != CALL_MODE_INSTANCE) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } } if (property.name == "basic_type") { if (call_mode != CALL_MODE_BASIC_TYPE) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } } if (property.name == "node_path") { if (call_mode != CALL_MODE_NODE_PATH) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } else { Node *bnode = _get_base_node(); if (bnode) { @@ -2029,7 +2029,7 @@ void VisualScriptPropertyGet::_validate_property(PropertyInfo &property) const { property.hint_string = options; property.type = Variant::STRING; if (options == "") { - property.usage = 0; //hide if type has no usable index + property.usage = PROPERTY_USAGE_NONE; //hide if type has no usable index } } } @@ -2175,7 +2175,7 @@ public: } }; -VisualScriptNodeInstance *VisualScriptPropertyGet::instance(VisualScriptInstance *p_instance) { +VisualScriptNodeInstance *VisualScriptPropertyGet::instantiate(VisualScriptInstance *p_instance) { VisualScriptNodeInstancePropertyGet *instance = memnew(VisualScriptNodeInstancePropertyGet); instance->node = this; instance->instance = p_instance; @@ -2197,7 +2197,7 @@ VisualScriptPropertyGet::VisualScriptPropertyGet() { template <VisualScriptPropertyGet::CallMode cmode> static Ref<VisualScriptNode> create_property_get_node(const String &p_name) { Ref<VisualScriptPropertyGet> node; - node.instance(); + node.instantiate(); node->set_call_mode(cmode); return node; } @@ -2321,7 +2321,7 @@ public: } }; -VisualScriptNodeInstance *VisualScriptEmitSignal::instance(VisualScriptInstance *p_instance) { +VisualScriptNodeInstance *VisualScriptEmitSignal::instantiate(VisualScriptInstance *p_instance) { VisualScriptNodeInstanceEmitSignal *instance = memnew(VisualScriptNodeInstanceEmitSignal); instance->node = this; instance->instance = p_instance; @@ -2340,7 +2340,7 @@ static Ref<VisualScriptNode> create_basic_type_call_node(const String &p_name) { String method = path[3]; Ref<VisualScriptFunctionCall> node; - node.instance(); + node.instantiate(); Variant::Type type = Variant::VARIANT_MAX; diff --git a/modules/visual_script/visual_script_func_nodes.h b/modules/visual_script/visual_script_func_nodes.h index 2ff9b7a981..eb17be1fbe 100644 --- a/modules/visual_script/visual_script_func_nodes.h +++ b/modules/visual_script/visual_script_func_nodes.h @@ -125,7 +125,7 @@ public: void set_rpc_call_mode(RPCCallMode p_mode); RPCCallMode get_rpc_call_mode() const; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; + virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override; virtual TypeGuess guess_output_type(TypeGuess *p_inputs, int p_output) const override; @@ -231,7 +231,7 @@ public: void set_assign_op(AssignOp p_op); AssignOp get_assign_op() const; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; + virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override; virtual TypeGuess guess_output_type(TypeGuess *p_inputs, int p_output) const override; VisualScriptPropertySet(); @@ -314,7 +314,7 @@ public: void set_index(const StringName &p_type); StringName get_index() const; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; + virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override; VisualScriptPropertyGet(); }; @@ -351,7 +351,7 @@ public: void set_signal(const StringName &p_type); StringName get_signal() const; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; + virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override; VisualScriptEmitSignal(); }; diff --git a/modules/visual_script/visual_script_nodes.cpp b/modules/visual_script/visual_script_nodes.cpp index 07dc3dfaf6..b93c710652 100644 --- a/modules/visual_script/visual_script_nodes.cpp +++ b/modules/visual_script/visual_script_nodes.cpp @@ -296,7 +296,7 @@ public: } }; -VisualScriptNodeInstance *VisualScriptFunction::instance(VisualScriptInstance *p_instance) { +VisualScriptNodeInstance *VisualScriptFunction::instantiate(VisualScriptInstance *p_instance) { VisualScriptNodeInstanceFunction *instance = memnew(VisualScriptNodeInstanceFunction); instance->node = this; instance->instance = p_instance; @@ -791,7 +791,7 @@ public: } }; -VisualScriptNodeInstance *VisualScriptComposeArray::instance(VisualScriptInstance *p_instance) { +VisualScriptNodeInstance *VisualScriptComposeArray::instantiate(VisualScriptInstance *p_instance) { VisualScriptComposeArrayNode *instance = memnew(VisualScriptComposeArrayNode); instance->input_count = inputports.size(); return instance; @@ -912,73 +912,135 @@ PropertyInfo VisualScriptOperator::get_output_value_port_info(int p_idx) const { return pinfo; } -static const char *op_names[] = { - //comparison - "Are Equal", //OP_EQUAL, - "Are Not Equal", //OP_NOT_EQUAL, - "Less Than", //OP_LESS, - "Less Than or Equal", //OP_LESS_EQUAL, - "Greater Than", //OP_GREATER, - "Greater Than or Equal", //OP_GREATER_EQUAL, - //mathematic - "Add", //OP_ADD, - "Subtract", //OP_SUBTRACT, - "Multiply", //OP_MULTIPLY, - "Divide", //OP_DIVIDE, - "Negate", //OP_NEGATE, - "Positive", //OP_POSITIVE, - "Remainder", //OP_MODULE, - "Concatenate", //OP_STRING_CONCAT, - //bitwise - "Bit Shift Left", //OP_SHIFT_LEFT, - "Bit Shift Right", //OP_SHIFT_RIGHT, - "Bit And", //OP_BIT_AND, - "Bit Or", //OP_BIT_OR, - "Bit Xor", //OP_BIT_XOR, - "Bit Negate", //OP_BIT_NEGATE, - //logic - "And", //OP_AND, - "Or", //OP_OR, - "Xor", //OP_XOR, - "Not", //OP_NOT, - //containment - "In", //OP_IN, -}; - String VisualScriptOperator::get_caption() const { - static const char32_t *op_names[] = { - //comparison - U"A = B", //OP_EQUAL, - U"A \u2260 B", //OP_NOT_EQUAL, - U"A < B", //OP_LESS, - U"A \u2264 B", //OP_LESS_EQUAL, - U"A > B", //OP_GREATER, - U"A \u2265 B", //OP_GREATER_EQUAL, - //mathematic - U"A + B", //OP_ADD, - U"A - B", //OP_SUBTRACT, - U"A \u00D7 B", //OP_MULTIPLY, - U"A \u00F7 B", //OP_DIVIDE, - U"\u00AC A", //OP_NEGATE, - U"+ A", //OP_POSITIVE, - U"A mod B", //OP_MODULE, - U"A .. B", //OP_STRING_CONCAT, - //bitwise - U"A << B", //OP_SHIFT_LEFT, - U"A >> B", //OP_SHIFT_RIGHT, - U"A & B", //OP_BIT_AND, - U"A | B", //OP_BIT_OR, - U"A ^ B", //OP_BIT_XOR, - U"~A", //OP_BIT_NEGATE, - //logic - U"A and B", //OP_AND, - U"A or B", //OP_OR, - U"A xor B", //OP_XOR, - U"not A", //OP_NOT, - U"A in B", //OP_IN, - - }; - return op_names[op]; + switch (op) { + // comparison + case Variant::OP_EQUAL: + return U"A = B"; + case Variant::OP_NOT_EQUAL: + return U"A \u2260 B"; + case Variant::OP_LESS: + return U"A < B"; + case Variant::OP_LESS_EQUAL: + return U"A \u2264 B"; + case Variant::OP_GREATER: + return U"A > B"; + case Variant::OP_GREATER_EQUAL: + return U"A \u2265 B"; + + // mathematic + case Variant::OP_ADD: + return U"A + B"; + case Variant::OP_SUBTRACT: + return U"A - B"; + case Variant::OP_MULTIPLY: + return U"A \u00D7 B"; + case Variant::OP_DIVIDE: + return U"A \u00F7 B"; + case Variant::OP_NEGATE: + return U"\u00AC A"; + case Variant::OP_POSITIVE: + return U"+ A"; + case Variant::OP_MODULE: + return U"A mod B"; + + // bitwise + case Variant::OP_SHIFT_LEFT: + return U"A << B"; + case Variant::OP_SHIFT_RIGHT: + return U"A >> B"; + case Variant::OP_BIT_AND: + return U"A & B"; + case Variant::OP_BIT_OR: + return U"A | B"; + case Variant::OP_BIT_XOR: + return U"A ^ B"; + case Variant::OP_BIT_NEGATE: + return U"~A"; + + // logic + case Variant::OP_AND: + return U"A and B"; + case Variant::OP_OR: + return U"A or B"; + case Variant::OP_XOR: + return U"A xor B"; + case Variant::OP_NOT: + return U"not A"; + case Variant::OP_IN: + return U"A in B"; + + default: { + ERR_FAIL_V_MSG( + U"Unknown node", + U"Unknown node type encountered, caption not available."); + } + } +} + +String VisualScriptOperator::get_operator_name(Variant::Operator p_op) { + switch (p_op) { + // comparison + case Variant::OP_EQUAL: + return "Are Equal"; + case Variant::OP_NOT_EQUAL: + return "Are Not Equal"; + case Variant::OP_LESS: + return "Less Than"; + case Variant::OP_LESS_EQUAL: + return "Less Than or Equal"; + case Variant::OP_GREATER: + return "Greater Than"; + case Variant::OP_GREATER_EQUAL: + return "Greater Than or Equal"; + + // mathematic + case Variant::OP_ADD: + return "Add"; + case Variant::OP_SUBTRACT: + return "Subtract"; + case Variant::OP_MULTIPLY: + return "Multiply"; + case Variant::OP_DIVIDE: + return "Divide"; + case Variant::OP_NEGATE: + return "Negate"; + case Variant::OP_POSITIVE: + return "Positive"; + case Variant::OP_MODULE: + return "Remainder"; + + // bitwise + case Variant::OP_SHIFT_LEFT: + return "Bit Shift Left"; + case Variant::OP_SHIFT_RIGHT: + return "Bit Shift Right"; + case Variant::OP_BIT_AND: + return "Bit And"; + case Variant::OP_BIT_OR: + return "Bit Or"; + case Variant::OP_BIT_XOR: + return "Bit Xor"; + case Variant::OP_BIT_NEGATE: + return "Bit Negate"; + + // logic + case Variant::OP_AND: + return "And"; + case Variant::OP_OR: + return "Or"; + case Variant::OP_XOR: + return "Xor"; + case Variant::OP_NOT: + return "Not"; + case Variant::OP_IN: + return "In"; + + default: { + ERR_FAIL_INDEX_V(p_op, Variant::OP_MAX, ""); + return "Unknown Operator"; + } + } } void VisualScriptOperator::set_operator(Variant::Operator p_op) { @@ -1018,7 +1080,7 @@ void VisualScriptOperator::_bind_methods() { if (i > 0) { types += ","; } - types += op_names[i]; + types += get_operator_name(static_cast<Variant::Operator>(i)); } String argt = "Any"; @@ -1051,9 +1113,9 @@ public: r_error_str = *p_outputs[0]; } else { if (unary) { - r_error_str = String(op_names[op]) + RTR(": Invalid argument of type: ") + Variant::get_type_name(p_inputs[0]->get_type()); + r_error_str = String(Variant::get_operator_name(op)) + RTR(": Invalid argument of type: ") + Variant::get_type_name(p_inputs[0]->get_type()); } else { - r_error_str = String(op_names[op]) + RTR(": Invalid arguments: ") + "A: " + Variant::get_type_name(p_inputs[0]->get_type()) + " B: " + Variant::get_type_name(p_inputs[1]->get_type()); + r_error_str = String(Variant::get_operator_name(op)) + RTR(": Invalid arguments: ") + "A: " + Variant::get_type_name(p_inputs[0]->get_type()) + " B: " + Variant::get_type_name(p_inputs[1]->get_type()); } } } @@ -1062,7 +1124,7 @@ public: } }; -VisualScriptNodeInstance *VisualScriptOperator::instance(VisualScriptInstance *p_instance) { +VisualScriptNodeInstance *VisualScriptOperator::instantiate(VisualScriptInstance *p_instance) { VisualScriptNodeInstanceOperator *instance = memnew(VisualScriptNodeInstanceOperator); instance->unary = get_input_value_port_count() == 1; instance->op = op; @@ -1077,7 +1139,7 @@ VisualScriptOperator::VisualScriptOperator() { template <Variant::Operator OP> static Ref<VisualScriptNode> create_op_node(const String &p_name) { Ref<VisualScriptOperator> node; - node.instance(); + node.instantiate(); node->set_operator(OP); return node; } @@ -1169,7 +1231,7 @@ public: } }; -VisualScriptNodeInstance *VisualScriptSelect::instance(VisualScriptInstance *p_instance) { +VisualScriptNodeInstance *VisualScriptSelect::instantiate(VisualScriptInstance *p_instance) { VisualScriptNodeInstanceSelect *instance = memnew(VisualScriptNodeInstanceSelect); return instance; } @@ -1277,7 +1339,7 @@ public: } }; -VisualScriptNodeInstance *VisualScriptVariableGet::instance(VisualScriptInstance *p_instance) { +VisualScriptNodeInstance *VisualScriptVariableGet::instantiate(VisualScriptInstance *p_instance) { VisualScriptNodeInstanceVariableGet *instance = memnew(VisualScriptNodeInstanceVariableGet); instance->node = this; instance->instance = p_instance; @@ -1389,7 +1451,7 @@ public: } }; -VisualScriptNodeInstance *VisualScriptVariableSet::instance(VisualScriptInstance *p_instance) { +VisualScriptNodeInstance *VisualScriptVariableSet::instantiate(VisualScriptInstance *p_instance) { VisualScriptNodeInstanceVariableSet *instance = memnew(VisualScriptNodeInstanceVariableSet); instance->node = this; instance->instance = p_instance; @@ -1472,7 +1534,7 @@ void VisualScriptConstant::_validate_property(PropertyInfo &property) const { if (property.name == "value") { property.type = type; if (type == Variant::NIL) { - property.usage = 0; //do not save if nil + property.usage = PROPERTY_USAGE_NONE; //do not save if nil } } } @@ -1504,7 +1566,7 @@ public: } }; -VisualScriptNodeInstance *VisualScriptConstant::instance(VisualScriptInstance *p_instance) { +VisualScriptNodeInstance *VisualScriptConstant::instantiate(VisualScriptInstance *p_instance) { VisualScriptNodeInstanceConstant *instance = memnew(VisualScriptNodeInstanceConstant); instance->constant = value; return instance; @@ -1597,7 +1659,7 @@ public: } }; -VisualScriptNodeInstance *VisualScriptPreload::instance(VisualScriptInstance *p_instance) { +VisualScriptNodeInstance *VisualScriptPreload::instantiate(VisualScriptInstance *p_instance) { VisualScriptNodeInstancePreload *instance = memnew(VisualScriptNodeInstancePreload); instance->preload = preload; return instance; @@ -1662,7 +1724,7 @@ public: } }; -VisualScriptNodeInstance *VisualScriptIndexGet::instance(VisualScriptInstance *p_instance) { +VisualScriptNodeInstance *VisualScriptIndexGet::instantiate(VisualScriptInstance *p_instance) { VisualScriptNodeInstanceIndexGet *instance = memnew(VisualScriptNodeInstanceIndexGet); return instance; } @@ -1732,7 +1794,7 @@ public: } }; -VisualScriptNodeInstance *VisualScriptIndexSet::instance(VisualScriptInstance *p_instance) { +VisualScriptNodeInstance *VisualScriptIndexSet::instantiate(VisualScriptInstance *p_instance) { VisualScriptNodeInstanceIndexSet *instance = memnew(VisualScriptNodeInstanceIndexSet); return instance; } @@ -1798,7 +1860,7 @@ public: } }; -VisualScriptNodeInstance *VisualScriptGlobalConstant::instance(VisualScriptInstance *p_instance) { +VisualScriptNodeInstance *VisualScriptGlobalConstant::instantiate(VisualScriptInstance *p_instance) { VisualScriptNodeInstanceGlobalConstant *instance = memnew(VisualScriptNodeInstanceGlobalConstant); instance->index = index; return instance; @@ -1916,7 +1978,7 @@ public: } }; -VisualScriptNodeInstance *VisualScriptClassConstant::instance(VisualScriptInstance *p_instance) { +VisualScriptNodeInstance *VisualScriptClassConstant::instantiate(VisualScriptInstance *p_instance) { VisualScriptNodeInstanceClassConstant *instance = memnew(VisualScriptNodeInstanceClassConstant); instance->value = ClassDB::get_integer_constant(base_type, name, &instance->valid); return instance; @@ -2050,7 +2112,7 @@ public: } }; -VisualScriptNodeInstance *VisualScriptBasicTypeConstant::instance(VisualScriptInstance *p_instance) { +VisualScriptNodeInstance *VisualScriptBasicTypeConstant::instantiate(VisualScriptInstance *p_instance) { VisualScriptNodeInstanceBasicTypeConstant *instance = memnew(VisualScriptNodeInstanceBasicTypeConstant); instance->value = Variant::get_constant_value(type, name, &instance->valid); return instance; @@ -2062,7 +2124,7 @@ void VisualScriptBasicTypeConstant::_validate_property(PropertyInfo &property) c Variant::get_constants_for_type(type, &constants); if (constants.size() == 0) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; return; } property.hint_string = ""; @@ -2174,7 +2236,7 @@ public: } }; -VisualScriptNodeInstance *VisualScriptMathConstant::instance(VisualScriptInstance *p_instance) { +VisualScriptNodeInstance *VisualScriptMathConstant::instantiate(VisualScriptInstance *p_instance) { VisualScriptNodeInstanceMathConstant *instance = memnew(VisualScriptNodeInstanceMathConstant); instance->value = const_value[constant]; return instance; @@ -2268,7 +2330,7 @@ public: } }; -VisualScriptNodeInstance *VisualScriptEngineSingleton::instance(VisualScriptInstance *p_instance) { +VisualScriptNodeInstance *VisualScriptEngineSingleton::instantiate(VisualScriptInstance *p_instance) { VisualScriptNodeInstanceEngineSingleton *instance = memnew(VisualScriptNodeInstanceEngineSingleton); instance->singleton = Engine::get_singleton()->get_singleton_object(singleton); return instance; @@ -2394,7 +2456,7 @@ public: } }; -VisualScriptNodeInstance *VisualScriptSceneNode::instance(VisualScriptInstance *p_instance) { +VisualScriptNodeInstance *VisualScriptSceneNode::instantiate(VisualScriptInstance *p_instance) { VisualScriptNodeInstanceSceneNode *instance = memnew(VisualScriptNodeInstanceSceneNode); instance->node = this; instance->instance = p_instance; @@ -2574,7 +2636,7 @@ public: } }; -VisualScriptNodeInstance *VisualScriptSceneTree::instance(VisualScriptInstance *p_instance) { +VisualScriptNodeInstance *VisualScriptSceneTree::instantiate(VisualScriptInstance *p_instance) { VisualScriptNodeInstanceSceneTree *instance = memnew(VisualScriptNodeInstanceSceneTree); instance->node = this; instance->instance = p_instance; @@ -2655,7 +2717,7 @@ public: } }; -VisualScriptNodeInstance *VisualScriptResourcePath::instance(VisualScriptInstance *p_instance) { +VisualScriptNodeInstance *VisualScriptResourcePath::instantiate(VisualScriptInstance *p_instance) { VisualScriptNodeInstanceResourcePath *instance = memnew(VisualScriptNodeInstanceResourcePath); instance->path = path; return instance; @@ -2727,7 +2789,7 @@ public: } }; -VisualScriptNodeInstance *VisualScriptSelf::instance(VisualScriptInstance *p_instance) { +VisualScriptNodeInstance *VisualScriptSelf::instantiate(VisualScriptInstance *p_instance) { VisualScriptNodeInstanceSelf *instance = memnew(VisualScriptNodeInstanceSelf); instance->instance = p_instance; return instance; @@ -2908,7 +2970,7 @@ public: } }; -VisualScriptNodeInstance *VisualScriptCustomNode::instance(VisualScriptInstance *p_instance) { +VisualScriptNodeInstance *VisualScriptCustomNode::instantiate(VisualScriptInstance *p_instance) { VisualScriptNodeInstanceCustomNode *instance = memnew(VisualScriptNodeInstanceCustomNode); instance->instance = p_instance; instance->node = this; @@ -3059,7 +3121,7 @@ public: } }; -VisualScriptNodeInstance *VisualScriptSubCall::instance(VisualScriptInstance *p_instance) { +VisualScriptNodeInstance *VisualScriptSubCall::instantiate(VisualScriptInstance *p_instance) { VisualScriptNodeInstanceSubCall *instance = memnew(VisualScriptNodeInstanceSubCall); instance->instance = p_instance; Ref<Script> script = get_script(); @@ -3172,7 +3234,7 @@ public: } }; -VisualScriptNodeInstance *VisualScriptComment::instance(VisualScriptInstance *p_instance) { +VisualScriptNodeInstance *VisualScriptComment::instantiate(VisualScriptInstance *p_instance) { VisualScriptNodeInstanceComment *instance = memnew(VisualScriptNodeInstanceComment); instance->instance = p_instance; return instance; @@ -3279,7 +3341,7 @@ public: } }; -VisualScriptNodeInstance *VisualScriptConstructor::instance(VisualScriptInstance *p_instance) { +VisualScriptNodeInstance *VisualScriptConstructor::instantiate(VisualScriptInstance *p_instance) { VisualScriptNodeInstanceConstructor *instance = memnew(VisualScriptNodeInstanceConstructor); instance->instance = p_instance; instance->type = type; @@ -3308,7 +3370,7 @@ static Ref<VisualScriptNode> create_constructor_node(const String &p_name) { ERR_FAIL_COND_V(!constructor_map.has(p_name), Ref<VisualScriptNode>()); Ref<VisualScriptConstructor> vsc; - vsc.instance(); + vsc.instantiate(); vsc->set_constructor_type(constructor_map[p_name].first); vsc->set_constructor(constructor_map[p_name].second); @@ -3389,7 +3451,7 @@ public: } }; -VisualScriptNodeInstance *VisualScriptLocalVar::instance(VisualScriptInstance *p_instance) { +VisualScriptNodeInstance *VisualScriptLocalVar::instantiate(VisualScriptInstance *p_instance) { VisualScriptNodeInstanceLocalVar *instance = memnew(VisualScriptNodeInstanceLocalVar); instance->instance = p_instance; instance->name = name; @@ -3497,7 +3559,7 @@ public: } }; -VisualScriptNodeInstance *VisualScriptLocalVarSet::instance(VisualScriptInstance *p_instance) { +VisualScriptNodeInstance *VisualScriptLocalVarSet::instantiate(VisualScriptInstance *p_instance) { VisualScriptNodeInstanceLocalVarSet *instance = memnew(VisualScriptNodeInstanceLocalVarSet); instance->instance = p_instance; instance->name = name; @@ -3634,7 +3696,7 @@ public: } }; -VisualScriptNodeInstance *VisualScriptInputAction::instance(VisualScriptInstance *p_instance) { +VisualScriptNodeInstance *VisualScriptInputAction::instantiate(VisualScriptInstance *p_instance) { VisualScriptNodeInstanceInputAction *instance = memnew(VisualScriptNodeInstanceInputAction); instance->instance = p_instance; instance->action = name; @@ -3812,7 +3874,7 @@ public: } }; -VisualScriptNodeInstance *VisualScriptDeconstruct::instance(VisualScriptInstance *p_instance) { +VisualScriptNodeInstance *VisualScriptDeconstruct::instantiate(VisualScriptInstance *p_instance) { VisualScriptNodeInstanceDeconstruct *instance = memnew(VisualScriptNodeInstanceDeconstruct); instance->instance = p_instance; instance->outputs.resize(elements.size()); @@ -3849,7 +3911,7 @@ VisualScriptDeconstruct::VisualScriptDeconstruct() { template <Variant::Type T> static Ref<VisualScriptNode> create_node_deconst_typed(const String &p_name) { Ref<VisualScriptDeconstruct> node; - node.instance(); + node.instantiate(); node->set_deconstruct_type(T); return node; } diff --git a/modules/visual_script/visual_script_nodes.h b/modules/visual_script/visual_script_nodes.h index 7392443e4e..b599b92b3a 100644 --- a/modules/visual_script/visual_script_nodes.h +++ b/modules/visual_script/visual_script_nodes.h @@ -97,7 +97,7 @@ public: void set_rpc_mode(MultiplayerAPI::RPCMode p_mode); MultiplayerAPI::RPCMode get_rpc_mode() const; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; + virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override; virtual void reset_state() override; @@ -192,7 +192,7 @@ public: virtual String get_text() const override; virtual String get_category() const override { return "functions"; } - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; + virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override; VisualScriptComposeArray(); }; @@ -227,7 +227,9 @@ public: void set_typed(Variant::Type p_op); Variant::Type get_typed() const; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; + static String get_operator_name(Variant::Operator p_op); + + virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override; VisualScriptOperator(); }; @@ -259,7 +261,7 @@ public: void set_typed(Variant::Type p_op); Variant::Type get_typed() const; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; + virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override; VisualScriptSelect(); }; @@ -291,7 +293,7 @@ public: void set_variable(StringName p_variable); StringName get_variable() const; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; + virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override; VisualScriptVariableGet(); }; @@ -323,7 +325,7 @@ public: void set_variable(StringName p_variable); StringName get_variable() const; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; + virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override; VisualScriptVariableSet(); }; @@ -359,7 +361,7 @@ public: void set_constant_value(Variant p_value); Variant get_constant_value() const; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; + virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override; VisualScriptConstant(); }; @@ -390,7 +392,7 @@ public: void set_preload(const Ref<Resource> &p_preload); Ref<Resource> get_preload() const; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; + virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override; VisualScriptPreload(); }; @@ -413,7 +415,7 @@ public: virtual String get_caption() const override; virtual String get_category() const override { return "operators"; } - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; + virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override; VisualScriptIndexGet(); }; @@ -436,7 +438,7 @@ public: virtual String get_caption() const override; virtual String get_category() const override { return "operators"; } - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; + virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override; VisualScriptIndexSet(); }; @@ -466,7 +468,7 @@ public: void set_global_constant(int p_which); int get_global_constant(); - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; + virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override; VisualScriptGlobalConstant(); }; @@ -502,7 +504,7 @@ public: void set_base_type(const StringName &p_which); StringName get_base_type(); - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; + virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override; VisualScriptClassConstant(); }; @@ -539,7 +541,7 @@ public: void set_basic_type(Variant::Type p_which); Variant::Type get_basic_type() const; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; + virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override; VisualScriptBasicTypeConstant(); }; @@ -586,7 +588,7 @@ public: void set_math_constant(MathConstant p_which); MathConstant get_math_constant(); - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; + virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override; VisualScriptMathConstant(); }; @@ -621,7 +623,7 @@ public: void set_singleton(const String &p_string); String get_singleton(); - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; + virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override; virtual TypeGuess guess_output_type(TypeGuess *p_inputs, int p_output) const override; @@ -655,7 +657,7 @@ public: void set_node_path(const NodePath &p_path); NodePath get_node_path(); - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; + virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override; virtual TypeGuess guess_output_type(TypeGuess *p_inputs, int p_output) const override; @@ -684,7 +686,7 @@ public: virtual String get_caption() const override; virtual String get_category() const override { return "data"; } - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; + virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override; virtual TypeGuess guess_output_type(TypeGuess *p_inputs, int p_output) const override; @@ -717,7 +719,7 @@ public: void set_resource_path(const String &p_path); String get_resource_path(); - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; + virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override; VisualScriptResourcePath(); }; @@ -743,7 +745,7 @@ public: virtual String get_caption() const override; virtual String get_category() const override { return "data"; } - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; + virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override; virtual TypeGuess guess_output_type(TypeGuess *p_inputs, int p_output) const override; @@ -788,7 +790,7 @@ public: virtual String get_text() const override; virtual String get_category() const override; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; + virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override; void _script_changed(); @@ -819,7 +821,7 @@ public: virtual String get_text() const override; virtual String get_category() const override; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; + virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override; VisualScriptSubCall(); }; @@ -859,7 +861,7 @@ public: void set_size(const Size2 &p_size); Size2 get_size() const; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; + virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override; VisualScriptComment(); }; @@ -894,7 +896,7 @@ public: void set_constructor(const Dictionary &p_info); Dictionary get_constructor() const; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; + virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override; VisualScriptConstructor(); }; @@ -929,7 +931,7 @@ public: void set_var_type(Variant::Type p_type); Variant::Type get_var_type() const; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; + virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override; VisualScriptLocalVar(); }; @@ -965,7 +967,7 @@ public: void set_var_type(Variant::Type p_type); Variant::Type get_var_type() const; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; + virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override; VisualScriptLocalVarSet(); }; @@ -1010,7 +1012,7 @@ public: void set_action_mode(Mode p_mode); Mode get_action_mode() const; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; + virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override; VisualScriptInputAction(); }; @@ -1056,7 +1058,7 @@ public: void set_deconstruct_type(Variant::Type p_type); Variant::Type get_deconstruct_type() const; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; + virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override; VisualScriptDeconstruct(); }; diff --git a/modules/visual_script/visual_script_yield_nodes.cpp b/modules/visual_script/visual_script_yield_nodes.cpp index 52fe659983..d8bc926a1d 100644 --- a/modules/visual_script/visual_script_yield_nodes.cpp +++ b/modules/visual_script/visual_script_yield_nodes.cpp @@ -113,7 +113,7 @@ public: } Ref<VisualScriptFunctionState> state; - state.instance(); + state.instantiate(); int ret = STEP_YIELD_BIT; switch (mode) { @@ -138,7 +138,7 @@ public: } }; -VisualScriptNodeInstance *VisualScriptYield::instance(VisualScriptInstance *p_instance) { +VisualScriptNodeInstance *VisualScriptYield::instantiate(VisualScriptInstance *p_instance) { VisualScriptNodeInstanceYield *instance = memnew(VisualScriptNodeInstanceYield); //instance->instance=p_instance; instance->mode = yield_mode; @@ -174,7 +174,7 @@ float VisualScriptYield::get_wait_time() { void VisualScriptYield::_validate_property(PropertyInfo &property) const { if (property.name == "wait_time") { if (yield_mode != YIELD_WAIT) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } } } @@ -202,7 +202,7 @@ VisualScriptYield::VisualScriptYield() { template <VisualScriptYield::YieldMode MODE> static Ref<VisualScriptNode> create_yield_node(const String &p_name) { Ref<VisualScriptYield> node; - node.instance(); + node.instantiate(); node->set_yield_mode(MODE); return node; } @@ -421,7 +421,7 @@ void VisualScriptYieldSignal::_validate_property(PropertyInfo &property) const { if (property.name == "node_path") { if (call_mode != CALL_MODE_NODE_PATH) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } else { Node *bnode = _get_base_node(); if (bnode) { @@ -548,7 +548,7 @@ public: } Ref<VisualScriptFunctionState> state; - state.instance(); + state.instantiate(); state->connect_to_signal(object, signal, Array()); @@ -559,7 +559,7 @@ public: } }; -VisualScriptNodeInstance *VisualScriptYieldSignal::instance(VisualScriptInstance *p_instance) { +VisualScriptNodeInstance *VisualScriptYieldSignal::instantiate(VisualScriptInstance *p_instance) { VisualScriptNodeInstanceYieldSignal *instance = memnew(VisualScriptNodeInstanceYieldSignal); instance->node = this; instance->instance = p_instance; @@ -578,7 +578,7 @@ VisualScriptYieldSignal::VisualScriptYieldSignal() { template <VisualScriptYieldSignal::CallMode cmode> static Ref<VisualScriptNode> create_yield_signal_node(const String &p_name) { Ref<VisualScriptYieldSignal> node; - node.instance(); + node.instantiate(); node->set_call_mode(cmode); return node; } diff --git a/modules/visual_script/visual_script_yield_nodes.h b/modules/visual_script/visual_script_yield_nodes.h index cc7ce0a1c6..fa596173a6 100644 --- a/modules/visual_script/visual_script_yield_nodes.h +++ b/modules/visual_script/visual_script_yield_nodes.h @@ -76,7 +76,7 @@ public: void set_wait_time(float p_time); float get_wait_time(); - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; + virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override; VisualScriptYield(); }; @@ -135,7 +135,7 @@ public: void set_call_mode(CallMode p_mode); CallMode get_call_mode() const; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; + virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override; VisualScriptYieldSignal(); }; diff --git a/modules/webm/register_types.cpp b/modules/webm/register_types.cpp index 82157a71c9..9cfaba83c1 100644 --- a/modules/webm/register_types.cpp +++ b/modules/webm/register_types.cpp @@ -35,7 +35,7 @@ static Ref<ResourceFormatLoaderWebm> resource_loader_webm; void register_webm_types() { - resource_loader_webm.instance(); + resource_loader_webm.instantiate(); ResourceLoader::add_resource_format_loader(resource_loader_webm, true); ClassDB::register_class<VideoStreamWebm>(); diff --git a/modules/webm/video_stream_webm.cpp b/modules/webm/video_stream_webm.cpp index 6ec0bde7bd..12e0f5bd25 100644 --- a/modules/webm/video_stream_webm.cpp +++ b/modules/webm/video_stream_webm.cpp @@ -116,7 +116,7 @@ bool VideoStreamPlaybackWebm::open_file(const String &p_file) { frame_data.resize((webm->getWidth() * webm->getHeight()) << 2); Ref<Image> img; - img.instance(); + img.instantiate(); img->create(webm->getWidth(), webm->getHeight(), false, Image::FORMAT_RGBA8); texture->create_from_image(img); diff --git a/modules/webp/image_loader_webp.cpp b/modules/webp/image_loader_webp.cpp index 772445190c..5bebad2b53 100644 --- a/modules/webp/image_loader_webp.cpp +++ b/modules/webp/image_loader_webp.cpp @@ -205,7 +205,7 @@ Error webp_load_image_from_buffer(Image *p_image, const uint8_t *p_buffer, int p static Ref<Image> _webp_mem_loader_func(const uint8_t *p_png, int p_size) { Ref<Image> img; - img.instance(); + img.instantiate(); Error err = webp_load_image_from_buffer(img.ptr(), p_png, p_size); ERR_FAIL_COND_V(err, Ref<Image>()); return img; diff --git a/modules/webrtc/config.py b/modules/webrtc/config.py index 0a075ccef1..3281415f38 100644 --- a/modules/webrtc/config.py +++ b/modules/webrtc/config.py @@ -10,7 +10,7 @@ def get_doc_classes(): return [ "WebRTCPeerConnection", "WebRTCDataChannel", - "WebRTCMultiplayer", + "WebRTCMultiplayerPeer", ] diff --git a/modules/webrtc/doc_classes/WebRTCMultiplayer.xml b/modules/webrtc/doc_classes/WebRTCMultiplayerPeer.xml index 5b9459bc27..26c5bfa6ce 100644 --- a/modules/webrtc/doc_classes/WebRTCMultiplayer.xml +++ b/modules/webrtc/doc_classes/WebRTCMultiplayerPeer.xml @@ -1,12 +1,12 @@ <?xml version="1.0" encoding="UTF-8" ?> -<class name="WebRTCMultiplayer" inherits="NetworkedMultiplayerPeer" version="4.0"> +<class name="WebRTCMultiplayerPeer" inherits="MultiplayerPeer" version="4.0"> <brief_description> A simple interface to create a peer-to-peer mesh network composed of [WebRTCPeerConnection] that is compatible with the [MultiplayerAPI]. </brief_description> <description> This class constructs a full mesh of [WebRTCPeerConnection] (one connection for each peer) that can be used as a [member MultiplayerAPI.network_peer]. You can add each [WebRTCPeerConnection] via [method add_peer] or remove them via [method remove_peer]. Peers must be added in [constant WebRTCPeerConnection.STATE_NEW] state to allow it to create the appropriate channels. This class will not create offers nor set descriptions, it will only poll them, and notify connections and disconnections. - [signal NetworkedMultiplayerPeer.connection_succeeded] and [signal NetworkedMultiplayerPeer.server_disconnected] will not be emitted unless [code]server_compatibility[/code] is [code]true[/code] in [method initialize]. Beside that data transfer works like in a [NetworkedMultiplayerPeer]. + [signal MultiplayerPeer.connection_succeeded] and [signal MultiplayerPeer.server_disconnected] will not be emitted unless [code]server_compatibility[/code] is [code]true[/code] in [method initialize]. Beside that data transfer works like in a [MultiplayerPeer]. </description> <tutorials> </tutorials> @@ -66,8 +66,8 @@ </argument> <description> Initialize the multiplayer peer with the given [code]peer_id[/code] (must be between 1 and 2147483647). - If [code]server_compatibilty[/code] is [code]false[/code] (default), the multiplayer peer will be immediately in state [constant NetworkedMultiplayerPeer.CONNECTION_CONNECTED] and [signal NetworkedMultiplayerPeer.connection_succeeded] will not be emitted. - If [code]server_compatibilty[/code] is [code]true[/code] the peer will suppress all [signal NetworkedMultiplayerPeer.peer_connected] signals until a peer with id [constant NetworkedMultiplayerPeer.TARGET_PEER_SERVER] connects and then emit [signal NetworkedMultiplayerPeer.connection_succeeded]. After that the signal [signal NetworkedMultiplayerPeer.peer_connected] will be emitted for every already connected peer, and any new peer that might connect. If the server peer disconnects after that, signal [signal NetworkedMultiplayerPeer.server_disconnected] will be emitted and state will become [constant NetworkedMultiplayerPeer.CONNECTION_CONNECTED]. + If [code]server_compatibilty[/code] is [code]false[/code] (default), the multiplayer peer will be immediately in state [constant MultiplayerPeer.CONNECTION_CONNECTED] and [signal MultiplayerPeer.connection_succeeded] will not be emitted. + If [code]server_compatibilty[/code] is [code]true[/code] the peer will suppress all [signal MultiplayerPeer.peer_connected] signals until a peer with id [constant MultiplayerPeer.TARGET_PEER_SERVER] connects and then emit [signal MultiplayerPeer.connection_succeeded]. After that the signal [signal MultiplayerPeer.peer_connected] will be emitted for every already connected peer, and any new peer that might connect. If the server peer disconnects after that, signal [signal MultiplayerPeer.server_disconnected] will be emitted and state will become [constant MultiplayerPeer.CONNECTION_CONNECTED]. </description> </method> <method name="remove_peer"> @@ -76,13 +76,13 @@ <argument index="0" name="peer_id" type="int"> </argument> <description> - Remove the peer with given [code]peer_id[/code] from the mesh. If the peer was connected, and [signal NetworkedMultiplayerPeer.peer_connected] was emitted for it, then [signal NetworkedMultiplayerPeer.peer_disconnected] will be emitted. + Remove the peer with given [code]peer_id[/code] from the mesh. If the peer was connected, and [signal MultiplayerPeer.peer_connected] was emitted for it, then [signal MultiplayerPeer.peer_disconnected] will be emitted. </description> </method> </methods> <members> <member name="refuse_new_connections" type="bool" setter="set_refuse_new_connections" getter="is_refusing_new_connections" override="true" default="false" /> - <member name="transfer_mode" type="int" setter="set_transfer_mode" getter="get_transfer_mode" override="true" enum="NetworkedMultiplayerPeer.TransferMode" default="2" /> + <member name="transfer_mode" type="int" setter="set_transfer_mode" getter="get_transfer_mode" override="true" enum="MultiplayerPeer.TransferMode" default="2" /> </members> <constants> </constants> diff --git a/modules/webrtc/register_types.cpp b/modules/webrtc/register_types.cpp index ecfaed9089..fcdf04fc2b 100644 --- a/modules/webrtc/register_types.cpp +++ b/modules/webrtc/register_types.cpp @@ -41,7 +41,7 @@ #include "webrtc_data_channel_gdnative.h" #include "webrtc_peer_connection_gdnative.h" #endif -#include "webrtc_multiplayer.h" +#include "webrtc_multiplayer_peer.h" void register_webrtc_types() { #define _SET_HINT(NAME, _VAL_, _MAX_) \ @@ -62,7 +62,7 @@ void register_webrtc_types() { ClassDB::register_class<WebRTCDataChannelGDNative>(); #endif ClassDB::register_virtual_class<WebRTCDataChannel>(); - ClassDB::register_class<WebRTCMultiplayer>(); + ClassDB::register_class<WebRTCMultiplayerPeer>(); } void unregister_webrtc_types() {} diff --git a/modules/webrtc/webrtc_multiplayer.cpp b/modules/webrtc/webrtc_multiplayer_peer.cpp index 741cad5640..ac75f9e860 100644 --- a/modules/webrtc/webrtc_multiplayer.cpp +++ b/modules/webrtc/webrtc_multiplayer_peer.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* webrtc_multiplayer.cpp */ +/* webrtc_multiplayer_peer.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,43 +28,43 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "webrtc_multiplayer.h" +#include "webrtc_multiplayer_peer.h" #include "core/io/marshalls.h" #include "core/os/os.h" -void WebRTCMultiplayer::_bind_methods() { - ClassDB::bind_method(D_METHOD("initialize", "peer_id", "server_compatibility"), &WebRTCMultiplayer::initialize, DEFVAL(false)); - ClassDB::bind_method(D_METHOD("add_peer", "peer", "peer_id", "unreliable_lifetime"), &WebRTCMultiplayer::add_peer, DEFVAL(1)); - ClassDB::bind_method(D_METHOD("remove_peer", "peer_id"), &WebRTCMultiplayer::remove_peer); - ClassDB::bind_method(D_METHOD("has_peer", "peer_id"), &WebRTCMultiplayer::has_peer); - ClassDB::bind_method(D_METHOD("get_peer", "peer_id"), &WebRTCMultiplayer::get_peer); - ClassDB::bind_method(D_METHOD("get_peers"), &WebRTCMultiplayer::get_peers); - ClassDB::bind_method(D_METHOD("close"), &WebRTCMultiplayer::close); +void WebRTCMultiplayerPeer::_bind_methods() { + ClassDB::bind_method(D_METHOD("initialize", "peer_id", "server_compatibility"), &WebRTCMultiplayerPeer::initialize, DEFVAL(false)); + ClassDB::bind_method(D_METHOD("add_peer", "peer", "peer_id", "unreliable_lifetime"), &WebRTCMultiplayerPeer::add_peer, DEFVAL(1)); + ClassDB::bind_method(D_METHOD("remove_peer", "peer_id"), &WebRTCMultiplayerPeer::remove_peer); + ClassDB::bind_method(D_METHOD("has_peer", "peer_id"), &WebRTCMultiplayerPeer::has_peer); + ClassDB::bind_method(D_METHOD("get_peer", "peer_id"), &WebRTCMultiplayerPeer::get_peer); + ClassDB::bind_method(D_METHOD("get_peers"), &WebRTCMultiplayerPeer::get_peers); + ClassDB::bind_method(D_METHOD("close"), &WebRTCMultiplayerPeer::close); } -void WebRTCMultiplayer::set_transfer_mode(TransferMode p_mode) { +void WebRTCMultiplayerPeer::set_transfer_mode(TransferMode p_mode) { transfer_mode = p_mode; } -NetworkedMultiplayerPeer::TransferMode WebRTCMultiplayer::get_transfer_mode() const { +MultiplayerPeer::TransferMode WebRTCMultiplayerPeer::get_transfer_mode() const { return transfer_mode; } -void WebRTCMultiplayer::set_target_peer(int p_peer_id) { +void WebRTCMultiplayerPeer::set_target_peer(int p_peer_id) { target_peer = p_peer_id; } -/* Returns the ID of the NetworkedMultiplayerPeer who sent the most recent packet: */ -int WebRTCMultiplayer::get_packet_peer() const { +/* Returns the ID of the MultiplayerPeer who sent the most recent packet: */ +int WebRTCMultiplayerPeer::get_packet_peer() const { return next_packet_peer; } -bool WebRTCMultiplayer::is_server() const { +bool WebRTCMultiplayerPeer::is_server() const { return unique_id == TARGET_PEER_SERVER; } -void WebRTCMultiplayer::poll() { +void WebRTCMultiplayerPeer::poll() { if (peer_map.size() == 0) { return; } @@ -147,7 +147,7 @@ void WebRTCMultiplayer::poll() { } } -void WebRTCMultiplayer::_find_next_peer() { +void WebRTCMultiplayerPeer::_find_next_peer() { Map<int, Ref<ConnectedPeer>>::Element *E = peer_map.find(next_packet_peer); if (E) { E = E->next(); @@ -180,19 +180,19 @@ void WebRTCMultiplayer::_find_next_peer() { next_packet_peer = 0; } -void WebRTCMultiplayer::set_refuse_new_connections(bool p_enable) { +void WebRTCMultiplayerPeer::set_refuse_new_connections(bool p_enable) { refuse_connections = p_enable; } -bool WebRTCMultiplayer::is_refusing_new_connections() const { +bool WebRTCMultiplayerPeer::is_refusing_new_connections() const { return refuse_connections; } -NetworkedMultiplayerPeer::ConnectionStatus WebRTCMultiplayer::get_connection_status() const { +MultiplayerPeer::ConnectionStatus WebRTCMultiplayerPeer::get_connection_status() const { return connection_status; } -Error WebRTCMultiplayer::initialize(int p_self_id, bool p_server_compat) { +Error WebRTCMultiplayerPeer::initialize(int p_self_id, bool p_server_compat) { ERR_FAIL_COND_V(p_self_id < 0 || p_self_id > ~(1 << 31), ERR_INVALID_PARAMETER); unique_id = p_self_id; server_compat = p_server_compat; @@ -206,12 +206,12 @@ Error WebRTCMultiplayer::initialize(int p_self_id, bool p_server_compat) { return OK; } -int WebRTCMultiplayer::get_unique_id() const { +int WebRTCMultiplayerPeer::get_unique_id() const { ERR_FAIL_COND_V(connection_status == CONNECTION_DISCONNECTED, 1); return unique_id; } -void WebRTCMultiplayer::_peer_to_dict(Ref<ConnectedPeer> p_connected_peer, Dictionary &r_dict) { +void WebRTCMultiplayerPeer::_peer_to_dict(Ref<ConnectedPeer> p_connected_peer, Dictionary &r_dict) { Array channels; for (List<Ref<WebRTCDataChannel>>::Element *F = p_connected_peer->channels.front(); F; F = F->next()) { channels.push_back(F->get()); @@ -221,18 +221,18 @@ void WebRTCMultiplayer::_peer_to_dict(Ref<ConnectedPeer> p_connected_peer, Dicti r_dict["channels"] = channels; } -bool WebRTCMultiplayer::has_peer(int p_peer_id) { +bool WebRTCMultiplayerPeer::has_peer(int p_peer_id) { return peer_map.has(p_peer_id); } -Dictionary WebRTCMultiplayer::get_peer(int p_peer_id) { +Dictionary WebRTCMultiplayerPeer::get_peer(int p_peer_id) { ERR_FAIL_COND_V(!peer_map.has(p_peer_id), Dictionary()); Dictionary out; _peer_to_dict(peer_map[p_peer_id], out); return out; } -Dictionary WebRTCMultiplayer::get_peers() { +Dictionary WebRTCMultiplayerPeer::get_peers() { Dictionary out; for (Map<int, Ref<ConnectedPeer>>::Element *E = peer_map.front(); E; E = E->next()) { Dictionary d; @@ -242,7 +242,7 @@ Dictionary WebRTCMultiplayer::get_peers() { return out; } -Error WebRTCMultiplayer::add_peer(Ref<WebRTCPeerConnection> p_peer, int p_peer_id, int p_unreliable_lifetime) { +Error WebRTCMultiplayerPeer::add_peer(Ref<WebRTCPeerConnection> p_peer, int p_peer_id, int p_unreliable_lifetime) { ERR_FAIL_COND_V(p_peer_id < 0 || p_peer_id > ~(1 << 31), ERR_INVALID_PARAMETER); ERR_FAIL_COND_V(p_unreliable_lifetime < 0, ERR_INVALID_PARAMETER); ERR_FAIL_COND_V(refuse_connections, ERR_UNAUTHORIZED); @@ -277,7 +277,7 @@ Error WebRTCMultiplayer::add_peer(Ref<WebRTCPeerConnection> p_peer, int p_peer_i return OK; } -void WebRTCMultiplayer::remove_peer(int p_peer_id) { +void WebRTCMultiplayerPeer::remove_peer(int p_peer_id) { ERR_FAIL_COND(!peer_map.has(p_peer_id)); Ref<ConnectedPeer> peer = peer_map[p_peer_id]; peer_map.erase(p_peer_id); @@ -291,7 +291,7 @@ void WebRTCMultiplayer::remove_peer(int p_peer_id) { } } -Error WebRTCMultiplayer::get_packet(const uint8_t **r_buffer, int &r_buffer_size) { +Error WebRTCMultiplayerPeer::get_packet(const uint8_t **r_buffer, int &r_buffer_size) { // Peer not available if (next_packet_peer == 0 || !peer_map.has(next_packet_peer)) { _find_next_peer(); @@ -309,7 +309,7 @@ Error WebRTCMultiplayer::get_packet(const uint8_t **r_buffer, int &r_buffer_size ERR_FAIL_V(ERR_BUG); } -Error WebRTCMultiplayer::put_packet(const uint8_t *p_buffer, int p_buffer_size) { +Error WebRTCMultiplayerPeer::put_packet(const uint8_t *p_buffer, int p_buffer_size) { ERR_FAIL_COND_V(connection_status == CONNECTION_DISCONNECTED, ERR_UNCONFIGURED); int ch = CH_RELIABLE; @@ -351,7 +351,7 @@ Error WebRTCMultiplayer::put_packet(const uint8_t *p_buffer, int p_buffer_size) return OK; } -int WebRTCMultiplayer::get_available_packet_count() const { +int WebRTCMultiplayerPeer::get_available_packet_count() const { if (next_packet_peer == 0) { return 0; // To be sure next call to get_packet works if size > 0 . } @@ -364,11 +364,11 @@ int WebRTCMultiplayer::get_available_packet_count() const { return size; } -int WebRTCMultiplayer::get_max_packet_size() const { +int WebRTCMultiplayerPeer::get_max_packet_size() const { return 1200; } -void WebRTCMultiplayer::close() { +void WebRTCMultiplayerPeer::close() { peer_map.clear(); unique_id = 0; next_packet_peer = 0; @@ -376,7 +376,7 @@ void WebRTCMultiplayer::close() { connection_status = CONNECTION_DISCONNECTED; } -WebRTCMultiplayer::WebRTCMultiplayer() { +WebRTCMultiplayerPeer::WebRTCMultiplayerPeer() { unique_id = 0; next_packet_peer = 0; target_peer = 0; @@ -387,6 +387,6 @@ WebRTCMultiplayer::WebRTCMultiplayer() { server_compat = false; } -WebRTCMultiplayer::~WebRTCMultiplayer() { +WebRTCMultiplayerPeer::~WebRTCMultiplayerPeer() { close(); } diff --git a/modules/webrtc/webrtc_multiplayer.h b/modules/webrtc/webrtc_multiplayer_peer.h index 2ddb98f656..1d9387b6dc 100644 --- a/modules/webrtc/webrtc_multiplayer.h +++ b/modules/webrtc/webrtc_multiplayer_peer.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* webrtc_multiplayer.h */ +/* webrtc_multiplayer_peer.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -31,11 +31,11 @@ #ifndef WEBRTC_MULTIPLAYER_H #define WEBRTC_MULTIPLAYER_H -#include "core/io/networked_multiplayer_peer.h" +#include "core/io/multiplayer_peer.h" #include "webrtc_peer_connection.h" -class WebRTCMultiplayer : public NetworkedMultiplayerPeer { - GDCLASS(WebRTCMultiplayer, NetworkedMultiplayerPeer); +class WebRTCMultiplayerPeer : public MultiplayerPeer { + GDCLASS(WebRTCMultiplayerPeer, MultiplayerPeer); protected: static void _bind_methods(); @@ -77,8 +77,8 @@ private: void _find_next_peer(); public: - WebRTCMultiplayer(); - ~WebRTCMultiplayer(); + WebRTCMultiplayerPeer(); + ~WebRTCMultiplayerPeer(); Error initialize(int p_self_id, bool p_server_compat = false); Error add_peer(Ref<WebRTCPeerConnection> p_peer, int p_peer_id, int p_unreliable_lifetime = 1); @@ -94,7 +94,7 @@ public: int get_available_packet_count() const override; int get_max_packet_size() const override; - // NetworkedMultiplayerPeer + // MultiplayerPeer void set_transfer_mode(TransferMode p_mode) override; TransferMode get_transfer_mode() const override; void set_target_peer(int p_peer_id) override; diff --git a/modules/websocket/doc_classes/WebSocketClient.xml b/modules/websocket/doc_classes/WebSocketClient.xml index 6af610c689..40c0ad17ad 100644 --- a/modules/websocket/doc_classes/WebSocketClient.xml +++ b/modules/websocket/doc_classes/WebSocketClient.xml @@ -6,7 +6,7 @@ <description> This class implements a WebSocket client compatible with any RFC 6455-compliant WebSocket server. This client can be optionally used as a network peer for the [MultiplayerAPI]. - After starting the client ([method connect_to_url]), you will need to [method NetworkedMultiplayerPeer.poll] it at regular intervals (e.g. inside [method Node._process]). + After starting the client ([method connect_to_url]), you will need to [method MultiplayerPeer.poll] it at regular intervals (e.g. inside [method Node._process]). You will receive appropriate signals when connecting, disconnecting, or when new data is available. </description> <tutorials> diff --git a/modules/websocket/doc_classes/WebSocketMultiplayerPeer.xml b/modules/websocket/doc_classes/WebSocketMultiplayerPeer.xml index 0679acf78a..ee1b60f739 100644 --- a/modules/websocket/doc_classes/WebSocketMultiplayerPeer.xml +++ b/modules/websocket/doc_classes/WebSocketMultiplayerPeer.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8" ?> -<class name="WebSocketMultiplayerPeer" inherits="NetworkedMultiplayerPeer" version="4.0"> +<class name="WebSocketMultiplayerPeer" inherits="MultiplayerPeer" version="4.0"> <brief_description> Base class for WebSocket server and client. </brief_description> @@ -39,7 +39,7 @@ </methods> <members> <member name="refuse_new_connections" type="bool" setter="set_refuse_new_connections" getter="is_refusing_new_connections" override="true" default="false" /> - <member name="transfer_mode" type="int" setter="set_transfer_mode" getter="get_transfer_mode" override="true" enum="NetworkedMultiplayerPeer.TransferMode" default="2" /> + <member name="transfer_mode" type="int" setter="set_transfer_mode" getter="get_transfer_mode" override="true" enum="MultiplayerPeer.TransferMode" default="2" /> </members> <signals> <signal name="peer_packet"> diff --git a/modules/websocket/doc_classes/WebSocketServer.xml b/modules/websocket/doc_classes/WebSocketServer.xml index 78f2832770..26e09fd8b3 100644 --- a/modules/websocket/doc_classes/WebSocketServer.xml +++ b/modules/websocket/doc_classes/WebSocketServer.xml @@ -5,7 +5,7 @@ </brief_description> <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 NetworkedMultiplayerPeer.poll] it at regular intervals (e.g. inside [method Node._process]). When clients connect, disconnect, or send data, you will receive the appropriate signal. + 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. </description> <tutorials> @@ -89,6 +89,9 @@ <member name="ca_chain" type="X509Certificate" setter="set_ca_chain" getter="get_ca_chain"> When using SSL (see [member private_key] and [member ssl_certificate]), you can set this to a valid [X509Certificate] to be provided as additional CA chain information during the SSL handshake. </member> + <member name="handshake_timeout" type="float" setter="set_handshake_timeout" getter="get_handshake_timeout" default="3.0"> + The time in seconds before a pending client (i.e. a client that has not yet finished the HTTP handshake) is considered stale and forcefully disconnected. + </member> <member name="private_key" type="CryptoKey" setter="set_private_key" getter="get_private_key"> When set to a valid [CryptoKey] (along with [member ssl_certificate]) will cause the server to require SSL instead of regular TCP (i.e. the [code]wss://[/code] protocol). </member> diff --git a/modules/websocket/editor_debugger_server_websocket.cpp b/modules/websocket/editor_debugger_server_websocket.cpp index b02d212c42..2e61cbfc08 100644 --- a/modules/websocket/editor_debugger_server_websocket.cpp +++ b/modules/websocket/editor_debugger_server_websocket.cpp @@ -50,9 +50,9 @@ void EditorDebuggerServerWebSocket::poll() { Error EditorDebuggerServerWebSocket::start() { int remote_port = (int)EditorSettings::get_singleton()->get("network/debug/remote_port"); - Vector<String> protocols; - protocols.push_back("binary"); // compatibility with EMSCRIPTEN TCP-to-WebSocket layer. - return server->listen(remote_port, protocols); + Vector<String> compatible_protocols; + compatible_protocols.push_back("binary"); // compatibility with EMSCRIPTEN TCP-to-WebSocket layer. + return server->listen(remote_port, compatible_protocols); } void EditorDebuggerServerWebSocket::stop() { diff --git a/modules/websocket/emws_client.cpp b/modules/websocket/emws_client.cpp index 626498e1ae..744053b6e2 100644 --- a/modules/websocket/emws_client.cpp +++ b/modules/websocket/emws_client.cpp @@ -107,7 +107,7 @@ Ref<WebSocketPeer> EMWSClient::get_peer(int p_peer_id) const { return _peer; } -NetworkedMultiplayerPeer::ConnectionStatus EMWSClient::get_connection_status() const { +MultiplayerPeer::ConnectionStatus EMWSClient::get_connection_status() const { if (_peer->is_connected_to_host()) { if (_is_connecting) return CONNECTION_CONNECTING; diff --git a/modules/websocket/websocket_client.cpp b/modules/websocket/websocket_client.cpp index 27f0f9af6b..af1dc8ff54 100644 --- a/modules/websocket/websocket_client.cpp +++ b/modules/websocket/websocket_client.cpp @@ -42,9 +42,9 @@ Error WebSocketClient::connect_to_url(String p_url, const Vector<String> p_proto _is_multiplayer = gd_mp_api; String host = p_url; - String path = "/"; - String scheme = ""; - int port = 80; + String path; + String scheme; + int port = 0; Error err = p_url.parse_url(scheme, host, port, path); ERR_FAIL_COND_V_MSG(err != OK, err, "Invalid URL: " + p_url); @@ -55,6 +55,9 @@ Error WebSocketClient::connect_to_url(String p_url, const Vector<String> p_proto if (port == 0) { port = ssl ? 443 : 80; } + if (path.is_empty()) { + path = "/"; + } return connect_to_host(host, path, port, ssl, p_protocols, p_custom_headers); } diff --git a/modules/websocket/websocket_multiplayer_peer.cpp b/modules/websocket/websocket_multiplayer_peer.cpp index fa0ef7060f..1beeb67b91 100644 --- a/modules/websocket/websocket_multiplayer_peer.cpp +++ b/modules/websocket/websocket_multiplayer_peer.cpp @@ -123,13 +123,13 @@ Error WebSocketMultiplayerPeer::put_packet(const uint8_t *p_buffer, int p_buffer } // -// NetworkedMultiplayerPeer +// MultiplayerPeer // void WebSocketMultiplayerPeer::set_transfer_mode(TransferMode p_mode) { // Websocket uses TCP, reliable } -NetworkedMultiplayerPeer::TransferMode WebSocketMultiplayerPeer::get_transfer_mode() const { +MultiplayerPeer::TransferMode WebSocketMultiplayerPeer::get_transfer_mode() const { // Websocket uses TCP, reliable return TRANSFER_MODE_RELIABLE; } diff --git a/modules/websocket/websocket_multiplayer_peer.h b/modules/websocket/websocket_multiplayer_peer.h index 48a6607d89..e3ccd1a795 100644 --- a/modules/websocket/websocket_multiplayer_peer.h +++ b/modules/websocket/websocket_multiplayer_peer.h @@ -32,12 +32,12 @@ #define WEBSOCKET_MULTIPLAYER_PEER_H #include "core/error/error_list.h" -#include "core/io/networked_multiplayer_peer.h" +#include "core/io/multiplayer_peer.h" #include "core/templates/list.h" #include "websocket_peer.h" -class WebSocketMultiplayerPeer : public NetworkedMultiplayerPeer { - GDCLASS(WebSocketMultiplayerPeer, NetworkedMultiplayerPeer); +class WebSocketMultiplayerPeer : public MultiplayerPeer { + GDCLASS(WebSocketMultiplayerPeer, MultiplayerPeer); private: Vector<uint8_t> _make_pkt(uint8_t p_type, int32_t p_from, int32_t p_to, const uint8_t *p_data, uint32_t p_data_size); @@ -78,7 +78,7 @@ protected: int _gen_unique_id() const; public: - /* NetworkedMultiplayerPeer */ + /* MultiplayerPeer */ void set_transfer_mode(TransferMode p_mode) override; TransferMode get_transfer_mode() const override; void set_target_peer(int p_target_peer) override; diff --git a/modules/websocket/websocket_server.cpp b/modules/websocket/websocket_server.cpp index dfe4471659..b996852f28 100644 --- a/modules/websocket/websocket_server.cpp +++ b/modules/websocket/websocket_server.cpp @@ -65,6 +65,10 @@ void WebSocketServer::_bind_methods() { ClassDB::bind_method(D_METHOD("set_ca_chain"), &WebSocketServer::set_ca_chain); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "ca_chain", PROPERTY_HINT_RESOURCE_TYPE, "X509Certificate", PROPERTY_USAGE_NONE), "set_ca_chain", "get_ca_chain"); + ClassDB::bind_method(D_METHOD("get_handshake_timeout"), &WebSocketServer::get_handshake_timeout); + ClassDB::bind_method(D_METHOD("set_handshake_timeout", "timeout"), &WebSocketServer::set_handshake_timeout); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "handshake_timeout"), "set_handshake_timeout", "get_handshake_timeout"); + ADD_SIGNAL(MethodInfo("client_close_request", PropertyInfo(Variant::INT, "id"), PropertyInfo(Variant::INT, "code"), PropertyInfo(Variant::STRING, "reason"))); ADD_SIGNAL(MethodInfo("client_disconnected", PropertyInfo(Variant::INT, "id"), PropertyInfo(Variant::BOOL, "was_clean_close"))); ADD_SIGNAL(MethodInfo("client_connected", PropertyInfo(Variant::INT, "id"), PropertyInfo(Variant::STRING, "protocol"))); @@ -108,7 +112,16 @@ void WebSocketServer::set_ca_chain(Ref<X509Certificate> p_ca_chain) { ca_chain = p_ca_chain; } -NetworkedMultiplayerPeer::ConnectionStatus WebSocketServer::get_connection_status() const { +float WebSocketServer::get_handshake_timeout() const { + return handshake_timeout / 1000.0; +} + +void WebSocketServer::set_handshake_timeout(float p_timeout) { + ERR_FAIL_COND(p_timeout <= 0.0); + handshake_timeout = p_timeout * 1000; +} + +MultiplayerPeer::ConnectionStatus WebSocketServer::get_connection_status() const { if (is_listening()) { return CONNECTION_CONNECTED; } diff --git a/modules/websocket/websocket_server.h b/modules/websocket/websocket_server.h index bc5e591e7b..26864f3085 100644 --- a/modules/websocket/websocket_server.h +++ b/modules/websocket/websocket_server.h @@ -48,6 +48,7 @@ protected: Ref<CryptoKey> private_key; Ref<X509Certificate> ssl_cert; Ref<X509Certificate> ca_chain; + uint32_t handshake_timeout = 3000; public: virtual Error listen(int p_port, const Vector<String> p_protocols = Vector<String>(), bool gd_mp_api = false) = 0; @@ -78,6 +79,9 @@ public: Ref<X509Certificate> get_ca_chain() const; void set_ca_chain(Ref<X509Certificate> p_ca_chain); + float get_handshake_timeout() const; + void set_handshake_timeout(float p_timeout); + WebSocketServer(); ~WebSocketServer(); }; diff --git a/modules/websocket/wsl_client.cpp b/modules/websocket/wsl_client.cpp index 111d2178d6..49997b42d3 100644 --- a/modules/websocket/wsl_client.cpp +++ b/modules/websocket/wsl_client.cpp @@ -158,6 +158,7 @@ bool WSLClient::_verify_headers(String &r_protocol) { Error WSLClient::connect_to_host(String p_host, String p_path, uint16_t p_port, bool p_ssl, const Vector<String> p_protocols, const Vector<String> p_custom_headers) { ERR_FAIL_COND_V(_connection.is_valid(), ERR_ALREADY_IN_USE); + ERR_FAIL_COND_V(p_path.is_empty(), ERR_INVALID_PARAMETER); _peer = Ref<WSLPeer>(memnew(WSLPeer)); IPAddress addr; @@ -287,7 +288,7 @@ Ref<WebSocketPeer> WSLClient::get_peer(int p_peer_id) const { return _peer; } -NetworkedMultiplayerPeer::ConnectionStatus WSLClient::get_connection_status() const { +MultiplayerPeer::ConnectionStatus WSLClient::get_connection_status() const { if (_peer->is_connected_to_host()) { return CONNECTION_CONNECTED; } @@ -337,8 +338,8 @@ Error WSLClient::set_buffers(int p_in_buffer, int p_in_packets, int p_out_buffer } WSLClient::WSLClient() { - _peer.instance(); - _tcp.instance(); + _peer.instantiate(); + _tcp.instantiate(); disconnect_from_host(); } diff --git a/modules/websocket/wsl_server.cpp b/modules/websocket/wsl_server.cpp index dc5b23c31e..c889562732 100644 --- a/modules/websocket/wsl_server.cpp +++ b/modules/websocket/wsl_server.cpp @@ -95,28 +95,33 @@ bool WSLServer::PendingPeer::_parse_request(const Vector<String> p_protocols) { return true; } -Error WSLServer::PendingPeer::do_handshake(const Vector<String> p_protocols) { - if (OS::get_singleton()->get_ticks_msec() - time > WSL_SERVER_TIMEOUT) { +Error WSLServer::PendingPeer::do_handshake(const Vector<String> p_protocols, uint64_t p_timeout) { + if (OS::get_singleton()->get_ticks_msec() - time > p_timeout) { + print_verbose(vformat("WebSocket handshake timed out after %.3f seconds.", p_timeout * 0.001)); return ERR_TIMEOUT; } + if (use_ssl) { Ref<StreamPeerSSL> ssl = static_cast<Ref<StreamPeerSSL>>(connection); if (ssl.is_null()) { - return FAILED; + ERR_FAIL_V_MSG(ERR_BUG, "Couldn't get StreamPeerSSL for WebSocket handshake."); } ssl->poll(); if (ssl->get_status() == StreamPeerSSL::STATUS_HANDSHAKING) { return ERR_BUSY; } else if (ssl->get_status() != StreamPeerSSL::STATUS_CONNECTED) { + print_verbose(vformat("WebSocket SSL connection error during handshake (StreamPeerSSL status code %d).", ssl->get_status())); return FAILED; } } + if (!has_request) { int read = 0; while (true) { - ERR_FAIL_COND_V_MSG(req_pos >= WSL_MAX_HEADER_SIZE, ERR_OUT_OF_MEMORY, "Response headers too big."); + ERR_FAIL_COND_V_MSG(req_pos >= WSL_MAX_HEADER_SIZE, ERR_OUT_OF_MEMORY, "WebSocket response headers are too big."); Error err = connection->get_partial_data(&req_buf[req_pos], 1, read); if (err != OK) { // Got an error + print_verbose(vformat("WebSocket error while getting partial data (StreamPeer error code %d).", err)); return FAILED; } else if (read != 1) { // Busy, wait next poll return ERR_BUSY; @@ -143,17 +148,21 @@ Error WSLServer::PendingPeer::do_handshake(const Vector<String> p_protocols) { req_pos += 1; } } + if (has_request && response_sent < response.size() - 1) { int sent = 0; Error err = connection->put_partial_data((const uint8_t *)response.get_data() + response_sent, response.size() - response_sent - 1, sent); if (err != OK) { + print_verbose(vformat("WebSocket error while putting partial data (StreamPeer error code %d).", err)); return err; } response_sent += sent; } + if (response_sent < response.size() - 1) { return ERR_BUSY; } + return OK; } @@ -188,7 +197,7 @@ void WSLServer::poll() { List<Ref<PendingPeer>> remove_peers; for (List<Ref<PendingPeer>>::Element *E = _pending.front(); E; E = E->next()) { Ref<PendingPeer> ppeer = E->get(); - Error err = ppeer->do_handshake(_protocols); + Error err = ppeer->do_handshake(_protocols, handshake_timeout); if (err == ERR_BUSY) { continue; } else if (err != OK) { @@ -301,7 +310,7 @@ Error WSLServer::set_buffers(int p_in_buffer, int p_in_packets, int p_out_buffer } WSLServer::WSLServer() { - _server.instance(); + _server.instantiate(); } WSLServer::~WSLServer() { diff --git a/modules/websocket/wsl_server.h b/modules/websocket/wsl_server.h index 39177a16a8..a428c89f4f 100644 --- a/modules/websocket/wsl_server.h +++ b/modules/websocket/wsl_server.h @@ -40,8 +40,6 @@ #include "core/io/stream_peer_tcp.h" #include "core/io/tcp_server.h" -#define WSL_SERVER_TIMEOUT 1000 - class WSLServer : public WebSocketServer { GDCIIMPL(WSLServer, WebSocketServer); @@ -64,7 +62,7 @@ private: CharString response; int response_sent = 0; - Error do_handshake(const Vector<String> p_protocols); + Error do_handshake(const Vector<String> p_protocols, uint64_t p_timeout); }; int _in_buf_size = DEF_BUF_SHIFT; diff --git a/modules/webxr/register_types.cpp b/modules/webxr/register_types.cpp index 8baf7e05b8..6df0234811 100644 --- a/modules/webxr/register_types.cpp +++ b/modules/webxr/register_types.cpp @@ -38,7 +38,7 @@ void register_webxr_types() { #ifdef JAVASCRIPT_ENABLED Ref<WebXRInterfaceJS> webxr; - webxr.instance(); + webxr.instantiate(); XRServer::get_singleton()->add_interface(webxr); #endif } diff --git a/modules/webxr/webxr_interface_js.cpp b/modules/webxr/webxr_interface_js.cpp index 13981e73e1..2eab0cdb07 100644 --- a/modules/webxr/webxr_interface_js.cpp +++ b/modules/webxr/webxr_interface_js.cpp @@ -400,7 +400,7 @@ void WebXRInterfaceJS::_update_tracker(int p_controller_id) { Ref<XRPositionalTracker> tracker = xr_server->find_by_type_and_id(XRServer::TRACKER_CONTROLLER, p_controller_id + 1); if (godot_webxr_is_controller_connected(p_controller_id)) { if (tracker.is_null()) { - tracker.instance(); + tracker.instantiate(); tracker->set_tracker_type(XRServer::TRACKER_CONTROLLER); // Controller id's 0 and 1 are always the left and right hands. if (p_controller_id < 2) { diff --git a/platform/android/display_server_android.cpp b/platform/android/display_server_android.cpp index ff61eeaee1..1fcc3d4a5c 100644 --- a/platform/android/display_server_android.cpp +++ b/platform/android/display_server_android.cpp @@ -358,8 +358,8 @@ Vector<String> DisplayServerAndroid::get_rendering_drivers_func() { return drivers; } -DisplayServer *DisplayServerAndroid::create_func(const String &p_rendering_driver, DisplayServer::WindowMode p_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error) { - DisplayServer *ds = memnew(DisplayServerAndroid(p_rendering_driver, p_mode, p_flags, p_resolution, r_error)); +DisplayServer *DisplayServerAndroid::create_func(const String &p_rendering_driver, DisplayServer::WindowMode p_mode, DisplayServer::VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error) { + DisplayServer *ds = memnew(DisplayServerAndroid(p_rendering_driver, p_mode, p_vsync_mode, p_flags, p_resolution, r_error)); if (r_error != OK) { ds->alert("Your video card driver does not support any of the supported Vulkan versions.", "Unable to initialize Video driver"); } @@ -377,10 +377,11 @@ void DisplayServerAndroid::reset_window() { ERR_FAIL_COND(!native_window); ERR_FAIL_COND(!context_vulkan); + VSyncMode last_vsync_mode = context_vulkan->get_vsync_mode(MAIN_WINDOW_ID); context_vulkan->window_destroy(MAIN_WINDOW_ID); Size2i display_size = OS_Android::get_singleton()->get_display_size(); - if (context_vulkan->window_create(native_window, display_size.width, display_size.height) == -1) { + if (context_vulkan->window_create(native_window, last_vsync_mode, display_size.width, display_size.height) == -1) { memdelete(context_vulkan); context_vulkan = nullptr; ERR_FAIL_MSG("Failed to reset Vulkan window."); @@ -402,7 +403,7 @@ void DisplayServerAndroid::notify_surface_changed(int p_width, int p_height) { rect_changed_callback.call(reinterpret_cast<const Variant **>(&sizep), 1, ret, ce); } -DisplayServerAndroid::DisplayServerAndroid(const String &p_rendering_driver, DisplayServer::WindowMode p_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error) { +DisplayServerAndroid::DisplayServerAndroid(const String &p_rendering_driver, DisplayServer::WindowMode p_mode, DisplayServer::VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error) { rendering_driver = p_rendering_driver; // TODO: rendering_driver is broken, change when different drivers are supported again @@ -410,8 +411,6 @@ DisplayServerAndroid::DisplayServerAndroid(const String &p_rendering_driver, Dis keep_screen_on = GLOBAL_GET("display/window/energy_saving/keep_screen_on"); - buttons_state = 0; - #if defined(OPENGL_ENABLED) if (rendering_driver == "opengl") { bool gl_initialization_error = false; @@ -448,7 +447,7 @@ DisplayServerAndroid::DisplayServerAndroid(const String &p_rendering_driver, Dis } Size2i display_size = OS_Android::get_singleton()->get_display_size(); - if (context_vulkan->window_create(native_window, display_size.width, display_size.height) == -1) { + if (context_vulkan->window_create(native_window, p_vsync_mode, display_size.width, display_size.height) == -1) { memdelete(context_vulkan); context_vulkan = nullptr; ERR_FAIL_MSG("Failed to create Vulkan window."); @@ -484,16 +483,16 @@ DisplayServerAndroid::~DisplayServerAndroid() { void DisplayServerAndroid::process_joy_event(DisplayServerAndroid::JoypadEvent p_event) { switch (p_event.type) { case JOY_EVENT_BUTTON: - Input::get_singleton()->joy_button(p_event.device, p_event.index, p_event.pressed); + Input::get_singleton()->joy_button(p_event.device, (JoyButton)p_event.index, p_event.pressed); break; case JOY_EVENT_AXIS: Input::JoyAxisValue value; value.min = -1; value.value = p_event.value; - Input::get_singleton()->joy_axis(p_event.device, p_event.index, value); + Input::get_singleton()->joy_axis(p_event.device, (JoyAxis)p_event.index, value); break; case JOY_EVENT_HAT: - Input::get_singleton()->joy_hat(p_event.device, p_event.hat); + Input::get_singleton()->joy_hat(p_event.device, (HatMask)p_event.hat); break; default: return; @@ -528,7 +527,7 @@ void DisplayServerAndroid::process_key_event(int p_keycode, int p_scancode, int } Ref<InputEventKey> ev; - ev.instance(); + ev.instantiate(); int val = unicode; int keycode = android_get_keysym(p_keycode); int phy_keycode = android_get_keysym(p_scancode); @@ -575,7 +574,7 @@ void DisplayServerAndroid::process_touch(int p_event, int p_pointer, const Vecto //end all if exist for (int i = 0; i < touch.size(); i++) { Ref<InputEventScreenTouch> ev; - ev.instance(); + ev.instantiate(); ev->set_index(touch[i].id); ev->set_pressed(false); ev->set_position(touch[i].pos); @@ -592,7 +591,7 @@ void DisplayServerAndroid::process_touch(int p_event, int p_pointer, const Vecto //send touch for (int i = 0; i < touch.size(); i++) { Ref<InputEventScreenTouch> ev; - ev.instance(); + ev.instantiate(); ev->set_index(touch[i].id); ev->set_pressed(true); ev->set_position(touch[i].pos); @@ -618,7 +617,7 @@ void DisplayServerAndroid::process_touch(int p_event, int p_pointer, const Vecto continue; //no move unncesearily Ref<InputEventScreenDrag> ev; - ev.instance(); + ev.instantiate(); ev->set_index(touch[i].id); ev->set_position(p_points[idx].pos); ev->set_relative(p_points[idx].pos - touch[i].pos); @@ -633,7 +632,7 @@ void DisplayServerAndroid::process_touch(int p_event, int p_pointer, const Vecto //end all if exist for (int i = 0; i < touch.size(); i++) { Ref<InputEventScreenTouch> ev; - ev.instance(); + ev.instantiate(); ev->set_index(touch[i].id); ev->set_pressed(false); ev->set_position(touch[i].pos); @@ -649,7 +648,7 @@ void DisplayServerAndroid::process_touch(int p_event, int p_pointer, const Vecto touch.push_back(tp); Ref<InputEventScreenTouch> ev; - ev.instance(); + ev.instantiate(); ev->set_index(tp.id); ev->set_pressed(true); @@ -664,7 +663,7 @@ void DisplayServerAndroid::process_touch(int p_event, int p_pointer, const Vecto for (int i = 0; i < touch.size(); i++) { if (touch[i].id == p_pointer) { Ref<InputEventScreenTouch> ev; - ev.instance(); + ev.instantiate(); ev->set_index(touch[i].id); ev->set_pressed(false); ev->set_position(touch[i].pos); @@ -685,7 +684,7 @@ void DisplayServerAndroid::process_hover(int p_type, Point2 p_pos) { case AMOTION_EVENT_ACTION_HOVER_ENTER: // hover enter case AMOTION_EVENT_ACTION_HOVER_EXIT: { // hover exit Ref<InputEventMouseMotion> ev; - ev.instance(); + ev.instantiate(); _set_key_modifier_state(ev); ev->set_position(p_pos); ev->set_global_position(p_pos); @@ -697,12 +696,12 @@ void DisplayServerAndroid::process_hover(int p_type, Point2 p_pos) { } void DisplayServerAndroid::process_mouse_event(int input_device, int event_action, int event_android_buttons_mask, Point2 event_pos, float event_vertical_factor, float event_horizontal_factor) { - int event_buttons_mask = _android_button_mask_to_godot_button_mask(event_android_buttons_mask); + MouseButton event_buttons_mask = _android_button_mask_to_godot_button_mask(event_android_buttons_mask); switch (event_action) { case AMOTION_EVENT_ACTION_BUTTON_PRESS: case AMOTION_EVENT_ACTION_BUTTON_RELEASE: { Ref<InputEventMouseButton> ev; - ev.instance(); + ev.instantiate(); _set_key_modifier_state(ev); if ((input_device & AINPUT_SOURCE_MOUSE) == AINPUT_SOURCE_MOUSE) { ev->set_position(event_pos); @@ -712,7 +711,7 @@ void DisplayServerAndroid::process_mouse_event(int input_device, int event_actio ev->set_global_position(hover_prev_pos); } ev->set_pressed(event_action == AMOTION_EVENT_ACTION_BUTTON_PRESS); - int changed_button_mask = buttons_state ^ event_buttons_mask; + MouseButton changed_button_mask = MouseButton(buttons_state ^ event_buttons_mask); buttons_state = event_buttons_mask; @@ -723,7 +722,7 @@ void DisplayServerAndroid::process_mouse_event(int input_device, int event_actio case AMOTION_EVENT_ACTION_MOVE: { Ref<InputEventMouseMotion> ev; - ev.instance(); + ev.instantiate(); _set_key_modifier_state(ev); if ((input_device & AINPUT_SOURCE_MOUSE) == AINPUT_SOURCE_MOUSE) { ev->set_position(event_pos); @@ -740,7 +739,7 @@ void DisplayServerAndroid::process_mouse_event(int input_device, int event_actio } break; case AMOTION_EVENT_ACTION_SCROLL: { Ref<InputEventMouseButton> ev; - ev.instance(); + ev.instantiate(); if ((input_device & AINPUT_SOURCE_MOUSE) == AINPUT_SOURCE_MOUSE) { ev->set_position(event_pos); ev->set_global_position(event_pos); @@ -765,11 +764,11 @@ void DisplayServerAndroid::process_mouse_event(int input_device, int event_actio } } -void DisplayServerAndroid::_wheel_button_click(int event_buttons_mask, const Ref<InputEventMouseButton> &ev, int wheel_button, float factor) { +void DisplayServerAndroid::_wheel_button_click(MouseButton event_buttons_mask, const Ref<InputEventMouseButton> &ev, MouseButton wheel_button, float factor) { Ref<InputEventMouseButton> evd = ev->duplicate(); _set_key_modifier_state(evd); evd->set_button_index(wheel_button); - evd->set_button_mask(event_buttons_mask ^ (1 << (wheel_button - 1))); + evd->set_button_mask(MouseButton(event_buttons_mask ^ (1 << (wheel_button - 1)))); evd->set_factor(factor); Input::get_singleton()->accumulate_input_event(evd); Ref<InputEventMouseButton> evdd = evd->duplicate(); @@ -779,9 +778,9 @@ void DisplayServerAndroid::_wheel_button_click(int event_buttons_mask, const Ref } void DisplayServerAndroid::process_double_tap(int event_android_button_mask, Point2 p_pos) { - int event_button_mask = _android_button_mask_to_godot_button_mask(event_android_button_mask); + MouseButton event_button_mask = _android_button_mask_to_godot_button_mask(event_android_button_mask); Ref<InputEventMouseButton> ev; - ev.instance(); + ev.instantiate(); _set_key_modifier_state(ev); ev->set_position(p_pos); ev->set_global_position(p_pos); @@ -792,7 +791,7 @@ void DisplayServerAndroid::process_double_tap(int event_android_button_mask, Poi Input::get_singleton()->accumulate_input_event(ev); } -int DisplayServerAndroid::_button_index_from_mask(int button_mask) { +MouseButton DisplayServerAndroid::_button_index_from_mask(MouseButton button_mask) { switch (button_mask) { case MOUSE_BUTTON_MASK_LEFT: return MOUSE_BUTTON_LEFT; @@ -805,13 +804,13 @@ int DisplayServerAndroid::_button_index_from_mask(int button_mask) { case MOUSE_BUTTON_MASK_XBUTTON2: return MOUSE_BUTTON_XBUTTON2; default: - return 0; + return MOUSE_BUTTON_NONE; } } void DisplayServerAndroid::process_scroll(Point2 p_pos) { Ref<InputEventPanGesture> ev; - ev.instance(); + ev.instantiate(); _set_key_modifier_state(ev); ev->set_position(p_pos); ev->set_delta(p_pos - scroll_prev_pos); @@ -863,12 +862,12 @@ Point2i DisplayServerAndroid::mouse_get_position() const { return hover_prev_pos; } -int DisplayServerAndroid::mouse_get_button_state() const { +MouseButton DisplayServerAndroid::mouse_get_button_state() const { return buttons_state; } -int DisplayServerAndroid::_android_button_mask_to_godot_button_mask(int android_button_mask) { - int godot_button_mask = 0; +MouseButton DisplayServerAndroid::_android_button_mask_to_godot_button_mask(int android_button_mask) { + MouseButton godot_button_mask = MOUSE_BUTTON_NONE; if (android_button_mask & AMOTION_EVENT_BUTTON_PRIMARY) { godot_button_mask |= MOUSE_BUTTON_MASK_LEFT; } @@ -903,3 +902,17 @@ void DisplayServerAndroid::cursor_set_shape(DisplayServer::CursorShape p_shape) DisplayServer::CursorShape DisplayServerAndroid::cursor_get_shape() const { return cursor_shape; } + +void DisplayServerAndroid::window_set_vsync_mode(DisplayServer::VSyncMode p_vsync_mode, WindowID p_window) { +#if defined(VULKAN_ENABLED) + context_vulkan->set_vsync_mode(p_window, p_vsync_mode); +#endif +} + +DisplayServer::VSyncMode DisplayServerAndroid::window_get_vsync_mode(WindowID p_window) const { +#if defined(VULKAN_ENABLED) + return context_vulkan->get_vsync_mode(p_window); +#else + return DisplayServer::VSYNC_ENABLED; +#endif +} diff --git a/platform/android/display_server_android.h b/platform/android/display_server_android.h index a2f47dcccb..bd5bed31cd 100644 --- a/platform/android/display_server_android.h +++ b/platform/android/display_server_android.h @@ -68,7 +68,7 @@ private: bool control_mem = false; bool meta_mem = false; - int buttons_state; + MouseButton buttons_state = MOUSE_BUTTON_NONE; // https://developer.android.com/reference/android/view/PointerIcon // mapping between Godot's cursor shape to Android's' @@ -92,7 +92,7 @@ private: 1003, //CURSOR_HELP }; const int CURSOR_TYPE_NULL = 0; - MouseMode mouse_mode; + MouseMode mouse_mode = MouseMode::MOUSE_MODE_VISIBLE; bool keep_screen_on; @@ -120,11 +120,11 @@ private: void _set_key_modifier_state(Ref<InputEventWithModifiers> ev); - static int _button_index_from_mask(int button_mask); + static MouseButton _button_index_from_mask(MouseButton button_mask); - static int _android_button_mask_to_godot_button_mask(int android_button_mask); + static MouseButton _android_button_mask_to_godot_button_mask(int android_button_mask); - void _wheel_button_click(int event_buttons_mask, const Ref<InputEventMouseButton> &ev, int wheel_button, float factor); + void _wheel_button_click(MouseButton event_buttons_mask, const Ref<InputEventMouseButton> &ev, MouseButton wheel_button, float factor); public: static DisplayServerAndroid *get_singleton(); @@ -188,6 +188,8 @@ public: virtual void window_move_to_foreground(WindowID p_window = MAIN_WINDOW_ID); virtual bool window_can_draw(WindowID p_window = MAIN_WINDOW_ID) const; virtual bool can_any_window_draw() const; + virtual void window_set_vsync_mode(DisplayServer::VSyncMode p_vsync_mode, WindowID p_window = MAIN_WINDOW_ID); + virtual DisplayServer::VSyncMode window_get_vsync_mode(WindowID p_vsync_mode) const; virtual void alert(const String &p_alert, const String &p_title); @@ -211,7 +213,7 @@ public: void mouse_set_mode(MouseMode p_mode); MouseMode mouse_get_mode() const; - static DisplayServer *create_func(const String &p_rendering_driver, WindowMode p_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error); + static DisplayServer *create_func(const String &p_rendering_driver, WindowMode p_mode, DisplayServer::VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error); static Vector<String> get_rendering_drivers_func(); static void register_android_driver(); @@ -219,9 +221,9 @@ public: void notify_surface_changed(int p_width, int p_height); virtual Point2i mouse_get_position() const; - virtual int mouse_get_button_state() const; + virtual MouseButton mouse_get_button_state() const; - DisplayServerAndroid(const String &p_rendering_driver, WindowMode p_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error); + DisplayServerAndroid(const String &p_rendering_driver, WindowMode p_mode, DisplayServer::VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error); ~DisplayServerAndroid(); }; diff --git a/platform/android/export/export.cpp b/platform/android/export/export.cpp index 1a0c206e28..6661698d3e 100644 --- a/platform/android/export/export.cpp +++ b/platform/android/export/export.cpp @@ -34,6 +34,7 @@ #include "core/io/dir_access.h" #include "core/io/file_access.h" #include "core/io/image_loader.h" +#include "core/io/json.h" #include "core/io/marshalls.h" #include "core/io/zip_io.h" #include "core/os/os.h" @@ -206,6 +207,7 @@ static const char *LEGACY_BUILD_SPLASH_IMAGE_EXPORT_PATH = "res/drawable-nodpi-v static const char *SPLASH_BG_COLOR_PATH = "res/drawable-nodpi/splash_bg_color.png"; static const char *LEGACY_BUILD_SPLASH_BG_COLOR_PATH = "res/drawable-nodpi-v4/splash_bg_color.png"; static const char *SPLASH_CONFIG_PATH = "res://android/build/res/drawable/splash_drawable.xml"; +static const char *GDNATIVE_LIBS_PATH = "res://android/build/libs/gdnativelibs.json"; const String SPLASH_CONFIG_XML_CONTENT = R"SPLASH(<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> @@ -277,6 +279,11 @@ class EditorExportPlatformAndroid : public EditorExportPlatform { EditorProgress *ep = nullptr; }; + struct CustomExportData { + bool debug; + Vector<String> libs; + }; + Vector<PluginConfigAndroid> plugins; String last_plugin_names; uint64_t last_custom_build_time = 0; @@ -757,6 +764,33 @@ class EditorExportPlatformAndroid : public EditorExportPlatform { return OK; } + static Error copy_gradle_so(void *p_userdata, const SharedObject &p_so) { + ERR_FAIL_COND_V_MSG(!p_so.path.get_file().begins_with("lib"), FAILED, + "Android .so file names must start with \"lib\", but got: " + p_so.path); + Vector<String> abis = get_abis(); + CustomExportData *export_data = (CustomExportData *)p_userdata; + bool exported = false; + for (int i = 0; i < p_so.tags.size(); ++i) { + int abi_index = abis.find(p_so.tags[i]); + if (abi_index != -1) { + exported = true; + String base = "res://android/build/libs"; + String type = export_data->debug ? "debug" : "release"; + String abi = abis[abi_index]; + String filename = p_so.path.get_file(); + String dst_path = base.plus_file(type).plus_file(abi).plus_file(filename); + Vector<uint8_t> data = FileAccess::get_file_as_array(p_so.path); + print_verbose("Copying .so file from " + p_so.path + " to " + dst_path); + Error err = store_file_at_path(dst_path, data); + ERR_FAIL_COND_V_MSG(err, err, "Failed to copy .so file from " + p_so.path + " to " + dst_path); + export_data->libs.push_back(dst_path); + } + } + ERR_FAIL_COND_V_MSG(!exported, FAILED, + "Cannot determine ABI for library \"" + p_so.path + "\". One of the supported ABIs must be used as a tag: " + String(" ").join(abis)); + return OK; + } + void _get_permissions(const Ref<EditorExportPreset> &p_preset, bool p_give_internet, Vector<String> &r_permissions) { const char **aperms = android_perms; while (*aperms) { @@ -858,6 +892,7 @@ class EditorExportPlatformAndroid : public EditorExportPlatform { int xr_mode_index = p_preset->get("xr_features/xr_mode"); bool backup_allowed = p_preset->get("user_data_backup/allow"); + bool classify_as_game = p_preset->get("package/classify_as_game"); Vector<String> perms; // Write permissions into the perms variable. @@ -955,6 +990,10 @@ class EditorExportPlatformAndroid : public EditorExportPlatform { encode_uint32(backup_allowed, &p_manifest.write[iofs + 16]); } + if (tname == "application" && attrname == "isGame") { + encode_uint32(classify_as_game, &p_manifest.write[iofs + 16]); + } + if (tname == "instrumentation" && attrname == "targetPackage") { string_table.write[attr_value] = get_package_name(package_name); } @@ -1461,7 +1500,7 @@ class EditorExportPlatformAndroid : public EditorExportPlatform { String project_splash_path = ProjectSettings::get_singleton()->get("application/boot_splash/image"); if (!project_splash_path.is_empty()) { - splash_image.instance(); + splash_image.instantiate(); print_verbose("Loading splash image: " + project_splash_path); const Error err = ImageLoader::load_image(project_splash_path, splash_image); if (err) { @@ -1501,7 +1540,7 @@ class EditorExportPlatformAndroid : public EditorExportPlatform { } print_verbose("Creating splash background color image."); - splash_bg_color_image.instance(); + splash_bg_color_image.instantiate(); splash_bg_color_image->create(splash_image->get_width(), splash_image->get_height(), false, splash_image->get_format()); splash_bg_color_image->fill(bg_color); @@ -1512,9 +1551,9 @@ class EditorExportPlatformAndroid : public EditorExportPlatform { void load_icon_refs(const Ref<EditorExportPreset> &p_preset, Ref<Image> &icon, Ref<Image> &foreground, Ref<Image> &background) { String project_icon_path = ProjectSettings::get_singleton()->get("application/config/icon"); - icon.instance(); - foreground.instance(); - background.instance(); + icon.instantiate(); + foreground.instantiate(); + background.instantiate(); // Regular icon: user selection -> project icon -> default. String path = static_cast<String>(p_preset->get(launcher_icon_option)).strip_edges(); @@ -1673,6 +1712,7 @@ public: r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "package/unique_name", PROPERTY_HINT_PLACEHOLDER_TEXT, "ext.domain.name"), "org.godotengine.$genname")); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "package/name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Game Name [default if blank]"), "")); r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "package/signed"), true)); + r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "package/classify_as_game"), true)); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, launcher_icon_option, PROPERTY_HINT_FILE, "*.png"), "")); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, launcher_adaptive_icon_foreground_option, PROPERTY_HINT_FILE, "*.png"), "")); @@ -1849,7 +1889,7 @@ public: err = OS::get_singleton()->execute(adb, args, &output, &rv, true); print_verbose(output); if (err || rv != 0) { - EditorNode::add_io_error("Could not install to device."); + EditorNode::add_io_error("Could not install to device: " + output); CLEANUP_AND_RETURN(ERR_CANT_CREATE); } @@ -2380,6 +2420,28 @@ public: } } + void _remove_copied_libs() { + print_verbose("Removing previously installed libraries..."); + Error error; + String libs_json = FileAccess::get_file_as_string(GDNATIVE_LIBS_PATH, &error); + if (error || libs_json.is_empty()) { + print_verbose("No previously installed libraries found"); + return; + } + + JSON json; + error = json.parse(libs_json); + ERR_FAIL_COND_MSG(error, "Error parsing \"" + libs_json + "\" on line " + itos(json.get_error_line()) + ": " + json.get_error_message()); + + Vector<String> libs = json.get_data(); + DirAccessRef da = DirAccess::create(DirAccess::ACCESS_RESOURCES); + for (int i = 0; i < libs.size(); i++) { + print_verbose("Removing previously installed library " + libs[i]); + da->remove(libs[i]); + } + da->remove(GDNATIVE_LIBS_PATH); + } + String join_list(List<String> parts, const String &separator) const { String ret; for (int i = 0; i < parts.size(); ++i) { @@ -2491,13 +2553,22 @@ public: //stores all the project files inside the Gradle project directory. Also includes all ABIs _clear_assets_directory(); + _remove_copied_libs(); if (!apk_expansion) { print_verbose("Exporting project files.."); - err = export_project_files(p_preset, rename_and_store_file_in_gradle_project, nullptr, ignore_so_file); + CustomExportData user_data; + user_data.debug = p_debug; + err = export_project_files(p_preset, rename_and_store_file_in_gradle_project, &user_data, copy_gradle_so); if (err != OK) { EditorNode::add_io_error("Could not export project files to gradle project\n"); return err; } + if (user_data.libs.size() > 0) { + FileAccessRef fa = FileAccess::open(GDNATIVE_LIBS_PATH, FileAccess::WRITE); + JSON json; + fa->store_string(json.stringify(user_data.libs, "\t")); + fa->close(); + } } else { print_verbose("Saving apk expansion file.."); err = save_apk_expansion_file(p_preset, p_path); @@ -2568,19 +2639,35 @@ public: // Sensitive additions must be done below the logging statement. print_verbose("Build Android project using gradle command: " + String("\n") + build_command + " " + join_list(cmdline, String(" "))); - if (should_sign && !p_debug) { - // Pass the release keystore info as well - String release_keystore = p_preset->get("keystore/release"); - String release_username = p_preset->get("keystore/release_user"); - String release_password = p_preset->get("keystore/release_password"); - if (!FileAccess::exists(release_keystore)) { - EditorNode::add_io_error("Could not find keystore, unable to export."); - return ERR_FILE_CANT_OPEN; - } + if (should_sign) { + if (p_debug) { + String debug_keystore = p_preset->get("keystore/debug"); + String debug_password = p_preset->get("keystore/debug_password"); + String debug_user = p_preset->get("keystore/debug_user"); + + if (debug_keystore.is_empty()) { + debug_keystore = EditorSettings::get_singleton()->get("export/android/debug_keystore"); + debug_password = EditorSettings::get_singleton()->get("export/android/debug_keystore_pass"); + debug_user = EditorSettings::get_singleton()->get("export/android/debug_keystore_user"); + } - cmdline.push_back("-Prelease_keystore_file=" + release_keystore); // argument to specify the release keystore file. - cmdline.push_back("-Prelease_keystore_alias=" + release_username); // argument to specify the release keystore alias. - cmdline.push_back("-Prelease_keystore_password=" + release_password); // argument to specity the release keystore password. + cmdline.push_back("-Pdebug_keystore_file=" + debug_keystore); // argument to specify the debug keystore file. + cmdline.push_back("-Pdebug_keystore_alias=" + debug_user); // argument to specify the debug keystore alias. + cmdline.push_back("-Pdebug_keystore_password=" + debug_password); // argument to specify the debug keystore password. + } else { + // Pass the release keystore info as well + String release_keystore = p_preset->get("keystore/release"); + String release_username = p_preset->get("keystore/release_user"); + String release_password = p_preset->get("keystore/release_password"); + if (!FileAccess::exists(release_keystore)) { + EditorNode::add_io_error("Could not find keystore, unable to export."); + return ERR_FILE_CANT_OPEN; + } + + cmdline.push_back("-Prelease_keystore_file=" + release_keystore); // argument to specify the release keystore file. + cmdline.push_back("-Prelease_keystore_alias=" + release_username); // argument to specify the release keystore alias. + cmdline.push_back("-Prelease_keystore_password=" + release_password); // argument to specify the release keystore password. + } } int result = EditorNode::get_singleton()->execute_and_show_output(TTR("Building Android Project (gradle)"), build_command, cmdline); @@ -2941,11 +3028,11 @@ public: EditorExportPlatformAndroid() { Ref<Image> img = memnew(Image(_android_logo)); - logo.instance(); + logo.instantiate(); logo->create_from_image(img); img = Ref<Image>(memnew(Image(_android_run_icon))); - run_icon.instance(); + run_icon.instantiate(); run_icon->create_from_image(img); devices_changed.set(); diff --git a/platform/android/export/gradle_export_util.h b/platform/android/export/gradle_export_util.h index 6ab678b8a1..52a7e4c5cf 100644 --- a/platform/android/export/gradle_export_util.h +++ b/platform/android/export/gradle_export_util.h @@ -96,14 +96,6 @@ Error create_directory(const String &p_dir) { return OK; } -// Implementation of EditorExportSaveSharedObject. -// This method will only be called as an input to export_project_files. -// This method lets the .so files for all ABIs to be copied -// into the gradle project from the .AAR file -Error ignore_so_file(void *p_userdata, const SharedObject &p_so) { - return OK; -} - // Writes p_data into a file at p_path, creating directories if necessary. // Note: this will overwrite the file at p_path if it already exists. Error store_file_at_path(const String &p_path, const Vector<uint8_t> &p_data) { @@ -260,9 +252,13 @@ String _get_activity_tag(const Ref<EditorExportPreset> &p_preset) { String _get_application_tag(const Ref<EditorExportPreset> &p_preset) { String manifest_application_text = vformat( " <application android:label=\"@string/godot_project_name_string\"\n" - " android:allowBackup=\"%s\" tools:ignore=\"GoogleAppIndexingWarning\"\n" - " android:icon=\"@mipmap/icon\">\n\n", - bool_to_string(p_preset->get("user_data_backup/allow"))); + " android:allowBackup=\"%s\"\n" + " android:icon=\"@mipmap/icon\"\n" + " android:isGame=\"%s\"\n" + " tools:replace=\"android:allowBackup,android:isGame\"\n" + " tools:ignore=\"GoogleAppIndexingWarning\">\n\n", + bool_to_string(p_preset->get("user_data_backup/allow")), + bool_to_string(p_preset->get("package/classify_as_game"))); manifest_application_text += _get_activity_tag(p_preset); manifest_application_text += " </application>\n"; diff --git a/platform/android/java/app/AndroidManifest.xml b/platform/android/java/app/AndroidManifest.xml index 15feea15a4..0874d77645 100644 --- a/platform/android/java/app/AndroidManifest.xml +++ b/platform/android/java/app/AndroidManifest.xml @@ -19,8 +19,9 @@ <application android:label="@string/godot_project_name_string" android:allowBackup="false" - tools:ignore="GoogleAppIndexingWarning" - android:icon="@mipmap/icon" > + android:icon="@mipmap/icon" + android:isGame="true" + tools:ignore="GoogleAppIndexingWarning" > <!-- Records the version of the Godot editor used for building --> <meta-data diff --git a/platform/android/java/app/build.gradle b/platform/android/java/app/build.gradle index 1b1fb47bd8..18e07c3762 100644 --- a/platform/android/java/app/build.gradle +++ b/platform/android/java/app/build.gradle @@ -6,7 +6,7 @@ buildscript { repositories { google() - jcenter() + mavenCentral() } dependencies { classpath libraries.androidGradlePlugin @@ -18,9 +18,8 @@ apply plugin: 'com.android.application' allprojects { repositories { - mavenCentral() google() - jcenter() + mavenCentral() // Godot user plugins custom maven repos String[] mavenRepos = getGodotPluginsMavenRepos() @@ -113,6 +112,15 @@ android { } signingConfigs { + debug { + if (hasCustomDebugKeystore()) { + storeFile new File(getDebugKeystoreFile()) + storePassword getDebugKeystorePassword() + keyAlias getDebugKeyAlias() + keyPassword getDebugKeystorePassword() + } + } + release { File keystoreFile = new File(getReleaseKeystoreFile()) if (keystoreFile.isFile()) { diff --git a/platform/android/java/app/config.gradle b/platform/android/java/app/config.gradle index b278d15bdf..81fc87b7ef 100644 --- a/platform/android/java/app/config.gradle +++ b/platform/android/java/app/config.gradle @@ -1,11 +1,11 @@ ext.versions = [ - androidGradlePlugin: '4.0.1', + androidGradlePlugin: '4.2.1', compileSdk : 29, minSdk : 18, targetSdk : 29, buildTools : '30.0.3', supportCoreUtils : '1.0.0', - kotlinVersion : '1.4.10', + kotlinVersion : '1.5.10', v4Support : '1.0.0', javaVersion : 1.8, ndkVersion : '21.4.7075529' // Also update 'platform/android/detect.py#get_project_ndk_version()' when this is updated. @@ -191,6 +191,35 @@ ext.getGodotPluginsLocalBinaries = { -> return binDeps } +ext.getDebugKeystoreFile = { -> + String keystoreFile = project.hasProperty("debug_keystore_file") ? project.property("debug_keystore_file") : "" + if (keystoreFile == null || keystoreFile.isEmpty()) { + keystoreFile = "." + } + return keystoreFile +} + +ext.hasCustomDebugKeystore = { -> + File keystoreFile = new File(getDebugKeystoreFile()) + return keystoreFile.isFile() +} + +ext.getDebugKeystorePassword = { -> + String keystorePassword = project.hasProperty("debug_keystore_password") ? project.property("debug_keystore_password") : "" + if (keystorePassword == null || keystorePassword.isEmpty()) { + keystorePassword = "android" + } + return keystorePassword +} + +ext.getDebugKeyAlias = { -> + String keyAlias = project.hasProperty("debug_keystore_alias") ? project.property("debug_keystore_alias") : "" + if (keyAlias == null || keyAlias.isEmpty()) { + keyAlias = "androiddebugkey" + } + return keyAlias +} + ext.getReleaseKeystoreFile = { -> String keystoreFile = project.hasProperty("release_keystore_file") ? project.property("release_keystore_file") : "" if (keystoreFile == null || keystoreFile.isEmpty()) { diff --git a/platform/android/java/build.gradle b/platform/android/java/build.gradle index a28888d80d..ee24a46d9f 100644 --- a/platform/android/java/build.gradle +++ b/platform/android/java/build.gradle @@ -5,7 +5,7 @@ buildscript { repositories { google() - jcenter() + mavenCentral() } dependencies { classpath libraries.androidGradlePlugin @@ -16,7 +16,6 @@ buildscript { allprojects { repositories { google() - jcenter() mavenCentral() } } diff --git a/platform/android/java/gradle/wrapper/gradle-wrapper.properties b/platform/android/java/gradle/wrapper/gradle-wrapper.properties index a7d8a0f310..74c5636f8a 100644 --- a/platform/android/java/gradle/wrapper/gradle-wrapper.properties +++ b/platform/android/java/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon Sep 02 02:44:30 PDT 2019 +#Wed Jun 23 23:42:22 PDT 2021 distributionBase=GRADLE_USER_HOME +distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip +zipStoreBase=GRADLE_USER_HOME diff --git a/platform/android/java/lib/src/org/godotengine/godot/Dictionary.java b/platform/android/java/lib/src/org/godotengine/godot/Dictionary.java index 0572cf3589..b12844702a 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/Dictionary.java +++ b/platform/android/java/lib/src/org/godotengine/godot/Dictionary.java @@ -43,10 +43,10 @@ public class Dictionary extends HashMap<String, Object> { for (String key : keys) { ret[i] = key; i++; - }; + } return ret; - }; + } public Object[] get_values() { Object[] ret = new Object[size()]; @@ -55,21 +55,21 @@ public class Dictionary extends HashMap<String, Object> { for (String key : keys) { ret[i] = get(key); i++; - }; + } return ret; - }; + } public void set_keys(String[] keys) { keys_cache = keys; - }; + } public void set_values(Object[] vals) { int i = 0; for (String key : keys_cache) { put(key, vals[i]); i++; - }; + } keys_cache = null; - }; -}; + } +} diff --git a/platform/android/java/lib/src/org/godotengine/godot/FullScreenGodotApp.java b/platform/android/java/lib/src/org/godotengine/godot/FullScreenGodotApp.java index 1ed16e04ca..89497d1526 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/FullScreenGodotApp.java +++ b/platform/android/java/lib/src/org/godotengine/godot/FullScreenGodotApp.java @@ -96,14 +96,6 @@ public abstract class FullScreenGodotApp extends FragmentActivity implements God } } - @Override - public boolean onKeyMultiple(final int inKeyCode, int repeatCount, KeyEvent event) { - if (godotFragment != null && godotFragment.onKeyMultiple(inKeyCode, repeatCount, event)) { - return true; - } - return super.onKeyMultiple(inKeyCode, repeatCount, event); - } - /** * Used to initialize the Godot fragment instance in {@link FullScreenGodotApp#onCreate(Bundle)}. */ diff --git a/platform/android/java/lib/src/org/godotengine/godot/Godot.java b/platform/android/java/lib/src/org/godotengine/godot/Godot.java index 0c16214c8a..8ffa4a9249 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/Godot.java +++ b/platform/android/java/lib/src/org/godotengine/godot/Godot.java @@ -70,10 +70,8 @@ import android.os.VibrationEffect; import android.os.Vibrator; import android.provider.Settings.Secure; import android.view.Display; -import android.view.InputDevice; import android.view.KeyEvent; import android.view.LayoutInflater; -import android.view.MotionEvent; import android.view.Surface; import android.view.View; import android.view.ViewGroup; @@ -175,7 +173,7 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC public static GodotNetUtils netUtils; public interface ResultCallback { - public void callback(int requestCode, int resultCode, Intent data); + void callback(int requestCode, int resultCode, Intent data); } public ResultCallback result_callback; @@ -220,7 +218,7 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC for (int i = 0; i < permissions.length; i++) { GodotLib.requestPermissionResult(permissions[i], grantResults[i] == PackageManager.PERMISSION_GRANTED); } - }; + } /** * Invoked on the render thread when the Godot setup is complete. @@ -281,29 +279,20 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC editText.setView(mRenderView); io.setEdit(editText); - view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { - @Override - public void onGlobalLayout() { - Point fullSize = new Point(); - activity.getWindowManager().getDefaultDisplay().getSize(fullSize); - Rect gameSize = new Rect(); - mRenderView.getView().getWindowVisibleDisplayFrame(gameSize); - - final int keyboardHeight = fullSize.y - gameSize.bottom; - GodotLib.setVirtualKeyboardHeight(keyboardHeight); - } + view.getViewTreeObserver().addOnGlobalLayoutListener(() -> { + Point fullSize = new Point(); + activity.getWindowManager().getDefaultDisplay().getSize(fullSize); + Rect gameSize = new Rect(); + mRenderView.getView().getWindowVisibleDisplayFrame(gameSize); + final int keyboardHeight = fullSize.y - gameSize.bottom; + GodotLib.setVirtualKeyboardHeight(keyboardHeight); }); - mRenderView.queueOnRenderThread(new Runnable() { - @Override - public void run() { - // Must occur after GodotLib.setup has completed. - for (GodotPlugin plugin : pluginRegistry.getAllPlugins()) { - plugin.onRegisterPluginWithGodotNative(); - } - - setKeepScreenOn("True".equals(GodotLib.getGlobal("display/window/energy_saving/keep_screen_on"))); + mRenderView.queueOnRenderThread(() -> { + for (GodotPlugin plugin : pluginRegistry.getAllPlugins()) { + plugin.onRegisterPluginWithGodotNative(); } + setKeepScreenOn("True".equals(GodotLib.getGlobal("display/window/energy_saving/keep_screen_on"))); }); // Include the returned non-null views in the Godot view hierarchy. @@ -316,14 +305,11 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC } public void setKeepScreenOn(final boolean p_enabled) { - runOnUiThread(new Runnable() { - @Override - public void run() { - if (p_enabled) { - getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - } else { - getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - } + runOnUiThread(() -> { + if (p_enabled) { + getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + } else { + getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } }); } @@ -370,21 +356,14 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC public void alert(final String message, final String title) { final Activity activity = getActivity(); - runOnUiThread(new Runnable() { - @Override - public void run() { - AlertDialog.Builder builder = new AlertDialog.Builder(activity); - builder.setMessage(message).setTitle(title); - builder.setPositiveButton( - "OK", - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - dialog.cancel(); - } - }); - AlertDialog dialog = builder.create(); - dialog.show(); - } + runOnUiThread(() -> { + AlertDialog.Builder builder = new AlertDialog.Builder(activity); + builder.setMessage(message).setTitle(title); + builder.setPositiveButton( + "OK", + (dialog, id) -> dialog.cancel()); + AlertDialog dialog = builder.create(); + dialog.show(); }); } @@ -534,7 +513,7 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC String main_pack_md5 = null; String main_pack_key = null; - List<String> new_args = new LinkedList<String>(); + List<String> new_args = new LinkedList<>(); for (int i = 0; i < command_line.length; i++) { boolean has_extra = i < command_line.length - 1; @@ -755,19 +734,16 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC public void UiChangeListener() { final View decorView = getActivity().getWindow().getDecorView(); - decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() { - @Override - public void onSystemUiVisibilityChange(int visibility) { - if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - decorView.setSystemUiVisibility( - View.SYSTEM_UI_FLAG_LAYOUT_STABLE | - View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | - View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | - View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | - View.SYSTEM_UI_FLAG_FULLSCREEN | - View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); - } + decorView.setOnSystemUiVisibilityChangeListener(visibility -> { + if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + decorView.setSystemUiVisibility( + View.SYSTEM_UI_FLAG_LAYOUT_STABLE | + View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | + View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | + View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | + View.SYSTEM_UI_FLAG_FULLSCREEN | + View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); } } }); @@ -780,7 +756,7 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC int displayRotation = display.getRotation(); float[] adjustedValues = new float[3]; - final int axisSwap[][] = { + final int[][] axisSwap = { { 1, -1, 0, 1 }, // ROTATION_0 { -1, -1, 1, 0 }, // ROTATION_90 { -1, 1, 0, 1 }, // ROTATION_180 @@ -798,21 +774,18 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC final int typeOfSensor = event.sensor.getType(); if (mRenderView != null) { - mRenderView.queueOnRenderThread(new Runnable() { - @Override - public void run() { - if (typeOfSensor == Sensor.TYPE_ACCELEROMETER) { - GodotLib.accelerometer(-x, y, -z); - } - if (typeOfSensor == Sensor.TYPE_GRAVITY) { - GodotLib.gravity(-x, y, -z); - } - if (typeOfSensor == Sensor.TYPE_MAGNETIC_FIELD) { - GodotLib.magnetometer(-x, y, -z); - } - if (typeOfSensor == Sensor.TYPE_GYROSCOPE) { - GodotLib.gyroscope(x, -y, z); - } + mRenderView.queueOnRenderThread(() -> { + if (typeOfSensor == Sensor.TYPE_ACCELEROMETER) { + GodotLib.accelerometer(-x, y, -z); + } + if (typeOfSensor == Sensor.TYPE_GRAVITY) { + GodotLib.gravity(-x, y, -z); + } + if (typeOfSensor == Sensor.TYPE_MAGNETIC_FIELD) { + GodotLib.magnetometer(-x, y, -z); + } + if (typeOfSensor == Sensor.TYPE_GYROSCOPE) { + GodotLib.gyroscope(x, -y, z); } }); } @@ -847,12 +820,7 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC } if (shouldQuit && mRenderView != null) { - mRenderView.queueOnRenderThread(new Runnable() { - @Override - public void run() { - GodotLib.back(); - } - }); + mRenderView.queueOnRenderThread(GodotLib::back); } } @@ -897,7 +865,7 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC byte[] messageDigest = complete.digest(); // Create Hex String - StringBuffer hexString = new StringBuffer(); + StringBuilder hexString = new StringBuilder(); for (int i = 0; i < messageDigest.length; i++) { String s = Integer.toHexString(0xFF & messageDigest[i]); @@ -918,33 +886,6 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC } } - public boolean onKeyMultiple(final int inKeyCode, int repeatCount, KeyEvent event) { - String s = event.getCharacters(); - if (s == null || s.length() == 0) - return false; - - final char[] cc = s.toCharArray(); - int cnt = 0; - for (int i = cc.length; --i >= 0; cnt += cc[i] != 0 ? 1 : 0) - ; - if (cnt == 0) - return false; - mRenderView.queueOnRenderThread(new Runnable() { - // This method will be called on the rendering thread: - public void run() { - for (int i = 0, n = cc.length; i < n; i++) { - int keyCode; - if ((keyCode = cc[i]) != 0) { - // Simulate key down and up... - GodotLib.key(0, 0, keyCode, true); - GodotLib.key(0, 0, keyCode, false); - } - } - } - }); - return true; - } - public boolean requestPermission(String p_name) { return PermissionsUtil.requestPermission(p_name, getActivity()); } diff --git a/platform/android/java/lib/src/org/godotengine/godot/GodotGLRenderView.java b/platform/android/java/lib/src/org/godotengine/godot/GodotGLRenderView.java index b3ee55ea64..a9d45c943b 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/GodotGLRenderView.java +++ b/platform/android/java/lib/src/org/godotengine/godot/GodotGLRenderView.java @@ -232,13 +232,10 @@ public class GodotGLRenderView extends GLSurfaceView implements GodotRenderView public void onResume() { super.onResume(); - queueEvent(new Runnable() { - @Override - public void run() { - // Resume the renderer - godotRenderer.onActivityResumed(); - GodotLib.focusin(); - } + queueEvent(() -> { + // Resume the renderer + godotRenderer.onActivityResumed(); + GodotLib.focusin(); }); } @@ -246,13 +243,10 @@ public class GodotGLRenderView extends GLSurfaceView implements GodotRenderView public void onPause() { super.onPause(); - queueEvent(new Runnable() { - @Override - public void run() { - GodotLib.focusout(); - // Pause the renderer - godotRenderer.onActivityPaused(); - } + queueEvent(() -> { + GodotLib.focusout(); + // Pause the renderer + godotRenderer.onActivityPaused(); }); } } diff --git a/platform/android/java/lib/src/org/godotengine/godot/GodotIO.java b/platform/android/java/lib/src/org/godotengine/godot/GodotIO.java index 12a8bdb90b..66882e8e72 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/GodotIO.java +++ b/platform/android/java/lib/src/org/godotengine/godot/GodotIO.java @@ -34,11 +34,9 @@ import org.godotengine.godot.input.*; import android.app.Activity; import android.content.*; -import android.content.Intent; import android.content.pm.ActivityInfo; import android.content.res.AssetManager; import android.graphics.Point; -import android.media.*; import android.net.Uri; import android.os.*; import android.util.DisplayMetrics; @@ -73,7 +71,7 @@ public class GodotIO { public int last_file_id = 1; - class AssetData { + static class AssetData { public boolean eof = false; public String path; public InputStream is; @@ -232,7 +230,7 @@ public class GodotIO { /// DIRECTORIES ///////////////////////// - class AssetDir { + static class AssetDir { public String[] files; public int current; public String path; @@ -323,8 +321,8 @@ public class GodotIO { am = p_activity.getAssets(); activity = p_activity; //streams = new HashMap<Integer, AssetData>(); - streams = new SparseArray<AssetData>(); - dirs = new SparseArray<AssetDir>(); + streams = new SparseArray<>(); + dirs = new SparseArray<>(); } ///////////////////////// @@ -386,7 +384,7 @@ public class GodotIO { Point size = new Point(); display.getRealSize(size); - int result[] = { 0, 0, size.x, size.y }; + int[] result = { 0, 0, size.x, size.y }; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { WindowInsets insets = activity.getWindow().getDecorView().getRootWindowInsets(); DisplayCutout cutout = insets.getDisplayCutout(); @@ -408,12 +406,12 @@ public class GodotIO { //InputMethodManager inputMgr = (InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE); //inputMgr.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); - }; + } public void hideKeyboard() { if (edit != null) edit.hideKeyboard(); - }; + } public void setScreenOrientation(int p_orientation) { switch (p_orientation) { diff --git a/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java b/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java index 8108118388..95870acda1 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java +++ b/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java @@ -34,7 +34,6 @@ import android.app.Activity; import android.hardware.SensorEvent; import android.view.Surface; -import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.opengles.GL10; /** diff --git a/platform/android/java/lib/src/org/godotengine/godot/GodotRenderView.java b/platform/android/java/lib/src/org/godotengine/godot/GodotRenderView.java index ac333dd827..79007764a7 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/GodotRenderView.java +++ b/platform/android/java/lib/src/org/godotengine/godot/GodotRenderView.java @@ -35,18 +35,18 @@ import org.godotengine.godot.input.GodotInputHandler; import android.view.SurfaceView; public interface GodotRenderView { - abstract public SurfaceView getView(); + SurfaceView getView(); - abstract public void initInputDevices(); + void initInputDevices(); - abstract public void queueOnRenderThread(Runnable event); + void queueOnRenderThread(Runnable event); - abstract public void onActivityPaused(); - abstract public void onActivityResumed(); + void onActivityPaused(); + void onActivityResumed(); - abstract public void onBackPressed(); + void onBackPressed(); - abstract public GodotInputHandler getInputHandler(); + GodotInputHandler getInputHandler(); - abstract public void setPointerIcon(int pointerType); + void setPointerIcon(int pointerType); } diff --git a/platform/android/java/lib/src/org/godotengine/godot/GodotRenderer.java b/platform/android/java/lib/src/org/godotengine/godot/GodotRenderer.java index 59bdbf7f8d..878a119c5c 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/GodotRenderer.java +++ b/platform/android/java/lib/src/org/godotengine/godot/GodotRenderer.java @@ -34,7 +34,6 @@ import org.godotengine.godot.plugin.GodotPlugin; import org.godotengine.godot.plugin.GodotPluginRegistry; import org.godotengine.godot.utils.GLUtils; -import android.content.Context; import android.opengl.GLSurfaceView; import javax.microedition.khronos.egl.EGLConfig; diff --git a/platform/android/java/lib/src/org/godotengine/godot/GodotVulkanRenderView.java b/platform/android/java/lib/src/org/godotengine/godot/GodotVulkanRenderView.java index 169c6cf770..6fca7f2a57 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/GodotVulkanRenderView.java +++ b/platform/android/java/lib/src/org/godotengine/godot/GodotVulkanRenderView.java @@ -39,7 +39,6 @@ import android.annotation.SuppressLint; import android.content.Context; import android.os.Build; import android.view.GestureDetector; -import android.view.InputDevice; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.PointerIcon; @@ -150,13 +149,10 @@ public class GodotVulkanRenderView extends VkSurfaceView implements GodotRenderV public void onResume() { super.onResume(); - queueOnVkThread(new Runnable() { - @Override - public void run() { - // Resume the renderer - mRenderer.onVkResume(); - GodotLib.focusin(); - } + queueOnVkThread(() -> { + // Resume the renderer + mRenderer.onVkResume(); + GodotLib.focusin(); }); } @@ -164,13 +160,10 @@ public class GodotVulkanRenderView extends VkSurfaceView implements GodotRenderV public void onPause() { super.onPause(); - queueOnVkThread(new Runnable() { - @Override - public void run() { - GodotLib.focusout(); - // Pause the renderer - mRenderer.onVkPause(); - } + queueOnVkThread(() -> { + GodotLib.focusout(); + // Pause the renderer + mRenderer.onVkPause(); }); } } diff --git a/platform/android/java/lib/src/org/godotengine/godot/input/GodotGestureHandler.java b/platform/android/java/lib/src/org/godotengine/godot/input/GodotGestureHandler.java index 2c39d06832..1d60c21c60 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/input/GodotGestureHandler.java +++ b/platform/android/java/lib/src/org/godotengine/godot/input/GodotGestureHandler.java @@ -75,12 +75,7 @@ public class GodotGestureHandler extends GestureDetector.SimpleOnGestureListener final int x = Math.round(event.getX()); final int y = Math.round(event.getY()); final int buttonMask = event.getButtonState(); - queueEvent(new Runnable() { - @Override - public void run() { - GodotLib.doubleTap(buttonMask, x, y); - } - }); + queueEvent(() -> GodotLib.doubleTap(buttonMask, x, y)); return true; } @@ -89,12 +84,7 @@ public class GodotGestureHandler extends GestureDetector.SimpleOnGestureListener //Log.i("GodotGesture", "onScroll"); final int x = Math.round(distanceX); final int y = Math.round(distanceY); - queueEvent(new Runnable() { - @Override - public void run() { - GodotLib.scroll(x, y); - } - }); + queueEvent(() -> GodotLib.scroll(x, y)); return true; } diff --git a/platform/android/java/lib/src/org/godotengine/godot/input/GodotInputHandler.java b/platform/android/java/lib/src/org/godotengine/godot/input/GodotInputHandler.java index 435b8b325f..4dc9157545 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/input/GodotInputHandler.java +++ b/platform/android/java/lib/src/org/godotengine/godot/input/GodotInputHandler.java @@ -45,13 +45,9 @@ import android.view.InputDevice.MotionRange; import android.view.KeyEvent; import android.view.MotionEvent; -import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; -import java.util.HashMap; import java.util.HashSet; -import java.util.List; -import java.util.Map; import java.util.Set; /** @@ -64,7 +60,7 @@ public class GodotInputHandler implements InputDeviceListener { private final String tag = this.getClass().getSimpleName(); private final SparseIntArray mJoystickIds = new SparseIntArray(4); - private final SparseArray<Joystick> mJoysticksDevices = new SparseArray<Joystick>(4); + private final SparseArray<Joystick> mJoysticksDevices = new SparseArray<>(4); public GodotInputHandler(GodotRenderView godotView) { mRenderView = godotView; @@ -101,22 +97,12 @@ public class GodotInputHandler implements InputDeviceListener { final int button = getGodotButton(keyCode); final int godotJoyId = mJoystickIds.get(deviceId); - queueEvent(new Runnable() { - @Override - public void run() { - GodotLib.joybutton(godotJoyId, button, false); - } - }); + queueEvent(() -> GodotLib.joybutton(godotJoyId, button, false)); } } else { final int scanCode = event.getScanCode(); final int chr = event.getUnicodeChar(0); - queueEvent(new Runnable() { - @Override - public void run() { - GodotLib.key(keyCode, scanCode, chr, false); - } - }); + queueEvent(() -> GodotLib.key(keyCode, scanCode, chr, false)); } return true; @@ -147,22 +133,12 @@ public class GodotInputHandler implements InputDeviceListener { final int button = getGodotButton(keyCode); final int godotJoyId = mJoystickIds.get(deviceId); - queueEvent(new Runnable() { - @Override - public void run() { - GodotLib.joybutton(godotJoyId, button, true); - } - }); + queueEvent(() -> GodotLib.joybutton(godotJoyId, button, true)); } } else { final int scanCode = event.getScanCode(); final int chr = event.getUnicodeChar(0); - queueEvent(new Runnable() { - @Override - public void run() { - GodotLib.key(keyCode, scanCode, chr, true); - } - }); + queueEvent(() -> GodotLib.key(keyCode, scanCode, chr, true)); } return true; @@ -194,19 +170,16 @@ public class GodotInputHandler implements InputDeviceListener { final int action = event.getActionMasked(); final int pointer_idx = event.getPointerId(event.getActionIndex()); - mRenderView.queueOnRenderThread(new Runnable() { - @Override - public void run() { - switch (action) { - case MotionEvent.ACTION_DOWN: - case MotionEvent.ACTION_CANCEL: - case MotionEvent.ACTION_UP: - case MotionEvent.ACTION_MOVE: - case MotionEvent.ACTION_POINTER_UP: - case MotionEvent.ACTION_POINTER_DOWN: { - GodotLib.touch(event.getSource(), action, pointer_idx, evcount, arr); - } break; - } + mRenderView.queueOnRenderThread(() -> { + switch (action) { + case MotionEvent.ACTION_DOWN: + case MotionEvent.ACTION_CANCEL: + case MotionEvent.ACTION_UP: + case MotionEvent.ACTION_MOVE: + case MotionEvent.ACTION_POINTER_UP: + case MotionEvent.ACTION_POINTER_DOWN: { + GodotLib.touch(event.getSource(), action, pointer_idx, evcount, arr); + } break; } }); } @@ -232,13 +205,7 @@ public class GodotInputHandler implements InputDeviceListener { // save value to prevent repeats joystick.axesValues.put(axis, value); final int godotAxisIdx = i; - queueEvent(new Runnable() { - @Override - public void run() { - GodotLib.joyaxis(godotJoyId, godotAxisIdx, value); - //Log.i(tag, "GodotLib.joyaxis("+godotJoyId+", "+godotAxisIdx+", "+value+");"); - } - }); + queueEvent(() -> GodotLib.joyaxis(godotJoyId, godotAxisIdx, value)); } } @@ -248,13 +215,7 @@ public class GodotInputHandler implements InputDeviceListener { if (joystick.hatX != hatX || joystick.hatY != hatY) { joystick.hatX = hatX; joystick.hatY = hatY; - queueEvent(new Runnable() { - @Override - public void run() { - GodotLib.joyhat(godotJoyId, hatX, hatY); - //Log.i(tag, "GodotLib.joyhat("+godotJoyId+", "+hatX+", "+hatY+");"); - } - }); + queueEvent(() -> GodotLib.joyhat(godotJoyId, hatX, hatY)); } } return true; @@ -263,12 +224,7 @@ public class GodotInputHandler implements InputDeviceListener { final float x = event.getX(); final float y = event.getY(); final int type = event.getAction(); - queueEvent(new Runnable() { - @Override - public void run() { - GodotLib.hover(type, x, y); - } - }); + queueEvent(() -> GodotLib.hover(type, x, y)); return true; } else if (event.isFromSource(InputDevice.SOURCE_MOUSE) || event.isFromSource(InputDevice.SOURCE_MOUSE_RELATIVE)) { @@ -333,7 +289,7 @@ public class GodotInputHandler implements InputDeviceListener { //Helps with creating new joypad mappings. Log.i(tag, "=== New Input Device: " + joystick.name); - Set<Integer> already = new HashSet<Integer>(); + Set<Integer> already = new HashSet<>(); for (InputDevice.MotionRange range : device.getMotionRanges()) { boolean isJoystick = range.isFromSource(InputDevice.SOURCE_JOYSTICK); boolean isGamepad = range.isFromSource(InputDevice.SOURCE_GAMEPAD); @@ -360,12 +316,7 @@ public class GodotInputHandler implements InputDeviceListener { } mJoysticksDevices.put(deviceId, joystick); - queueEvent(new Runnable() { - @Override - public void run() { - GodotLib.joyconnectionchanged(id, true, joystick.name); - } - }); + queueEvent(() -> GodotLib.joyconnectionchanged(id, true, joystick.name)); } @Override @@ -378,12 +329,7 @@ public class GodotInputHandler implements InputDeviceListener { mJoystickIds.delete(deviceId); mJoysticksDevices.delete(deviceId); - queueEvent(new Runnable() { - @Override - public void run() { - GodotLib.joyconnectionchanged(godotJoyId, false, ""); - } - }); + queueEvent(() -> GodotLib.joyconnectionchanged(godotJoyId, false, "")); } @Override @@ -472,12 +418,7 @@ public class GodotInputHandler implements InputDeviceListener { final float x = event.getX(); final float y = event.getY(); final int type = event.getAction(); - queueEvent(new Runnable() { - @Override - public void run() { - GodotLib.hover(type, x, y); - } - }); + queueEvent(() -> GodotLib.hover(type, x, y)); return true; } case MotionEvent.ACTION_BUTTON_PRESS: @@ -487,12 +428,7 @@ public class GodotInputHandler implements InputDeviceListener { final float y = event.getY(); final int buttonsMask = event.getButtonState(); final int action = event.getAction(); - queueEvent(new Runnable() { - @Override - public void run() { - GodotLib.touch(event.getSource(), action, 0, 1, new float[] { 0, x, y }, buttonsMask); - } - }); + queueEvent(() -> GodotLib.touch(event.getSource(), action, 0, 1, new float[] { 0, x, y }, buttonsMask)); return true; } case MotionEvent.ACTION_SCROLL: { @@ -502,12 +438,7 @@ public class GodotInputHandler implements InputDeviceListener { final int action = event.getAction(); final float verticalFactor = event.getAxisValue(MotionEvent.AXIS_VSCROLL); final float horizontalFactor = event.getAxisValue(MotionEvent.AXIS_HSCROLL); - queueEvent(new Runnable() { - @Override - public void run() { - GodotLib.touch(event.getSource(), action, 0, 1, new float[] { 0, x, y }, buttonsMask, verticalFactor, horizontalFactor); - } - }); + queueEvent(() -> GodotLib.touch(event.getSource(), action, 0, 1, new float[] { 0, x, y }, buttonsMask, verticalFactor, horizontalFactor)); } case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_UP: { diff --git a/platform/android/java/lib/src/org/godotengine/godot/input/GodotTextInputWrapper.java b/platform/android/java/lib/src/org/godotengine/godot/input/GodotTextInputWrapper.java index 3e0e6a65fd..020870a110 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/input/GodotTextInputWrapper.java +++ b/platform/android/java/lib/src/org/godotengine/godot/input/GodotTextInputWrapper.java @@ -94,17 +94,14 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene public void beforeTextChanged(final CharSequence pCharSequence, final int start, final int count, final int after) { //Log.d(TAG, "beforeTextChanged(" + pCharSequence + ")start: " + start + ",count: " + count + ",after: " + after); - mRenderView.queueOnRenderThread(new Runnable() { - @Override - public void run() { - for (int i = 0; i < count; ++i) { - GodotLib.key(KeyEvent.KEYCODE_DEL, KeyEvent.KEYCODE_DEL, 0, true); - GodotLib.key(KeyEvent.KEYCODE_DEL, KeyEvent.KEYCODE_DEL, 0, false); - - if (mHasSelection) { - mHasSelection = false; - break; - } + mRenderView.queueOnRenderThread(() -> { + for (int i = 0; i < count; ++i) { + GodotLib.key(KeyEvent.KEYCODE_DEL, KeyEvent.KEYCODE_DEL, 0, true); + GodotLib.key(KeyEvent.KEYCODE_DEL, KeyEvent.KEYCODE_DEL, 0, false); + + if (mHasSelection) { + mHasSelection = false; + break; } } }); @@ -118,18 +115,15 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene for (int i = start; i < start + count; ++i) { newChars[i - start] = pCharSequence.charAt(i); } - mRenderView.queueOnRenderThread(new Runnable() { - @Override - public void run() { - for (int i = 0; i < count; ++i) { - int key = newChars[i]; - if ((key == '\n') && !mEdit.isMultiline()) { - // Return keys are handled through action events - continue; - } - GodotLib.key(0, 0, key, true); - GodotLib.key(0, 0, key, false); + mRenderView.queueOnRenderThread(() -> { + for (int i = 0; i < count; ++i) { + int key = newChars[i]; + if ((key == '\n') && !mEdit.isMultiline()) { + // Return keys are handled through action events + continue; } + GodotLib.key(0, 0, key, true); + GodotLib.key(0, 0, key, false); } }); } @@ -139,23 +133,21 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene if (mEdit == pTextView && isFullScreenEdit()) { final String characters = pKeyEvent.getCharacters(); - mRenderView.queueOnRenderThread(new Runnable() { - @Override - public void run() { - for (int i = 0; i < characters.length(); i++) { - final int ch = characters.codePointAt(i); - GodotLib.key(0, 0, ch, true); - GodotLib.key(0, 0, ch, false); - } + mRenderView.queueOnRenderThread(() -> { + for (int i = 0; i < characters.length(); i++) { + final int ch = characters.codePointAt(i); + GodotLib.key(0, 0, ch, true); + GodotLib.key(0, 0, ch, false); } }); } if (pActionID == EditorInfo.IME_ACTION_DONE) { // Enter key has been pressed - GodotLib.key(KeyEvent.KEYCODE_ENTER, KeyEvent.KEYCODE_ENTER, 0, true); - GodotLib.key(KeyEvent.KEYCODE_ENTER, KeyEvent.KEYCODE_ENTER, 0, false); - + mRenderView.queueOnRenderThread(() -> { + GodotLib.key(KeyEvent.KEYCODE_ENTER, KeyEvent.KEYCODE_ENTER, 0, true); + GodotLib.key(KeyEvent.KEYCODE_ENTER, KeyEvent.KEYCODE_ENTER, 0, false); + }); mRenderView.getView().requestFocus(); return true; } diff --git a/platform/android/java/lib/src/org/godotengine/godot/input/InputManagerCompat.java b/platform/android/java/lib/src/org/godotengine/godot/input/InputManagerCompat.java index 62810ad3a4..21fdc658bb 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/input/InputManagerCompat.java +++ b/platform/android/java/lib/src/org/godotengine/godot/input/InputManagerCompat.java @@ -28,14 +28,14 @@ public interface InputManagerCompat { * @param id The device id * @return The input device or null if not found */ - public InputDevice getInputDevice(int id); + InputDevice getInputDevice(int id); /** * Gets the ids of all input devices in the system. * * @return The input device ids. */ - public int[] getInputDeviceIds(); + int[] getInputDeviceIds(); /** * Registers an input device listener to receive notifications about when @@ -46,7 +46,7 @@ public interface InputManagerCompat { * null if the listener should be invoked on the calling thread's * looper. */ - public void registerInputDeviceListener(InputManagerCompat.InputDeviceListener listener, + void registerInputDeviceListener(InputManagerCompat.InputDeviceListener listener, Handler handler); /** @@ -54,7 +54,7 @@ public interface InputManagerCompat { * * @param listener The listener to unregister. */ - public void unregisterInputDeviceListener(InputManagerCompat.InputDeviceListener listener); + void unregisterInputDeviceListener(InputManagerCompat.InputDeviceListener listener); /* * The following three calls are to simulate V16 behavior on pre-Jellybean @@ -69,7 +69,7 @@ public interface InputManagerCompat { * * @param event the motion event from the app */ - public void onGenericMotionEvent(MotionEvent event); + void onGenericMotionEvent(MotionEvent event); /** * Tell the V9 input manager that it should stop polling for disconnected @@ -77,7 +77,7 @@ public interface InputManagerCompat { * might want to call it whenever your game is not active (or whenever you * don't care about being notified of new input devices) */ - public void onPause(); + void onPause(); /** * Tell the V9 input manager that it should start polling for disconnected @@ -85,9 +85,9 @@ public interface InputManagerCompat { * might want to call it less often (only when the gameplay is actually * active) */ - public void onResume(); + void onResume(); - public interface InputDeviceListener { + interface InputDeviceListener { /** * Called whenever the input manager detects that a device has been * added. This will only be called in the V9 version when a motion event @@ -119,7 +119,7 @@ public interface InputManagerCompat { /** * Use this to construct a compatible InputManager. */ - public static class Factory { + class Factory { /** * Constructs and returns a compatible InputManger * diff --git a/platform/android/java/lib/src/org/godotengine/godot/input/InputManagerV16.java b/platform/android/java/lib/src/org/godotengine/godot/input/InputManagerV16.java index 61828dccae..0dbc13c77b 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/input/InputManagerV16.java +++ b/platform/android/java/lib/src/org/godotengine/godot/input/InputManagerV16.java @@ -34,7 +34,7 @@ public class InputManagerV16 implements InputManagerCompat { public InputManagerV16(Context context) { mInputManager = (InputManager)context.getSystemService(Context.INPUT_SERVICE); - mListeners = new HashMap<InputManagerCompat.InputDeviceListener, V16InputDeviceListener>(); + mListeners = new HashMap<>(); } @Override diff --git a/platform/android/java/lib/src/org/godotengine/godot/input/Joystick.java b/platform/android/java/lib/src/org/godotengine/godot/input/Joystick.java index 4b7318c718..bff90d7ce9 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/input/Joystick.java +++ b/platform/android/java/lib/src/org/godotengine/godot/input/Joystick.java @@ -41,12 +41,12 @@ import java.util.List; class Joystick { int device_id; String name; - List<Integer> axes = new ArrayList<Integer>(); + List<Integer> axes = new ArrayList<>(); protected boolean hasAxisHat = false; /* * Keep track of values so we can prevent flooding the engine with useless events. */ - protected final SparseArray axesValues = new SparseArray<Float>(4); + protected final SparseArray<Float> axesValues = new SparseArray<>(4); protected int hatX; protected int hatY; } diff --git a/platform/android/java/lib/src/org/godotengine/godot/plugin/GodotPlugin.java b/platform/android/java/lib/src/org/godotengine/godot/plugin/GodotPlugin.java index 6c8a3d4219..2dc8359615 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/plugin/GodotPlugin.java +++ b/platform/android/java/lib/src/org/godotengine/godot/plugin/GodotPlugin.java @@ -136,7 +136,7 @@ public abstract class GodotPlugin { nativeRegisterSingleton(pluginName, pluginObject); Set<Method> filteredMethods = new HashSet<>(); - Class clazz = pluginObject.getClass(); + Class<?> clazz = pluginObject.getClass(); Method[] methods = clazz.getDeclaredMethods(); for (Method method : methods) { @@ -157,8 +157,8 @@ public abstract class GodotPlugin { for (Method method : filteredMethods) { List<String> ptr = new ArrayList<>(); - Class[] paramTypes = method.getParameterTypes(); - for (Class c : paramTypes) { + Class<?>[] paramTypes = method.getParameterTypes(); + for (Class<?> c : paramTypes) { ptr.add(c.getName()); } diff --git a/platform/android/java/lib/src/org/godotengine/godot/utils/Crypt.java b/platform/android/java/lib/src/org/godotengine/godot/utils/Crypt.java index d6e49bb635..2b6e4ad2be 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/utils/Crypt.java +++ b/platform/android/java/lib/src/org/godotengine/godot/utils/Crypt.java @@ -39,10 +39,10 @@ public class Crypt { // Create MD5 Hash MessageDigest digest = java.security.MessageDigest.getInstance("MD5"); digest.update(input.getBytes()); - byte messageDigest[] = digest.digest(); + byte[] messageDigest = digest.digest(); // Create Hex String - StringBuffer hexString = new StringBuffer(); + StringBuilder hexString = new StringBuilder(); for (int i = 0; i < messageDigest.length; i++) hexString.append(Integer.toHexString(0xFF & messageDigest[i])); return hexString.toString(); diff --git a/platform/android/java/lib/src/org/godotengine/godot/xr/regular/RegularContextFactory.java b/platform/android/java/lib/src/org/godotengine/godot/xr/regular/RegularContextFactory.java index 71610d2d00..c852e8759a 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/xr/regular/RegularContextFactory.java +++ b/platform/android/java/lib/src/org/godotengine/godot/xr/regular/RegularContextFactory.java @@ -30,7 +30,6 @@ package org.godotengine.godot.xr.regular; -import org.godotengine.godot.GodotLib; import org.godotengine.godot.utils.GLUtils; import android.opengl.GLSurfaceView; diff --git a/platform/android/java_godot_lib_jni.cpp b/platform/android/java_godot_lib_jni.cpp index d59366bb64..4c66789a83 100644 --- a/platform/android/java_godot_lib_jni.cpp +++ b/platform/android/java_godot_lib_jni.cpp @@ -324,15 +324,15 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyhat(JNIEnv *env, j int hat = 0; if (p_hat_x != 0) { if (p_hat_x < 0) - hat |= Input::HAT_MASK_LEFT; + hat |= HatMask::HAT_MASK_LEFT; else - hat |= Input::HAT_MASK_RIGHT; + hat |= HatMask::HAT_MASK_RIGHT; } if (p_hat_y != 0) { if (p_hat_y < 0) - hat |= Input::HAT_MASK_UP; + hat |= HatMask::HAT_MASK_UP; else - hat |= Input::HAT_MASK_DOWN; + hat |= HatMask::HAT_MASK_DOWN; } jevent.hat = hat; diff --git a/platform/android/plugin/godot_plugin_jni.cpp b/platform/android/plugin/godot_plugin_jni.cpp index ba3e9fa20f..cf0c02e2bf 100644 --- a/platform/android/plugin/godot_plugin_jni.cpp +++ b/platform/android/plugin/godot_plugin_jni.cpp @@ -43,7 +43,7 @@ extern "C" { JNIEXPORT void JNICALL Java_org_godotengine_godot_plugin_GodotPlugin_nativeRegisterSingleton(JNIEnv *env, jclass clazz, jstring name, jobject obj) { String singname = jstring_to_string(name, env); - JNISingleton *s = (JNISingleton *)ClassDB::instance("JNISingleton"); + JNISingleton *s = (JNISingleton *)ClassDB::instantiate("JNISingleton"); s->set_instance(env->NewGlobalRef(obj)); jni_singletons[singname] = s; diff --git a/platform/android/vulkan/vulkan_context_android.cpp b/platform/android/vulkan/vulkan_context_android.cpp index 63f2026fae..a031f3beee 100644 --- a/platform/android/vulkan/vulkan_context_android.cpp +++ b/platform/android/vulkan/vulkan_context_android.cpp @@ -36,7 +36,7 @@ const char *VulkanContextAndroid::_get_platform_surface_extension() const { return VK_KHR_ANDROID_SURFACE_EXTENSION_NAME; } -int VulkanContextAndroid::window_create(ANativeWindow *p_window, int p_width, int p_height) { +int VulkanContextAndroid::window_create(ANativeWindow *p_window, DisplayServer::VSyncMode p_vsync_mode, int p_width, int p_height) { VkAndroidSurfaceCreateInfoKHR createInfo; createInfo.sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR; createInfo.pNext = nullptr; @@ -49,7 +49,7 @@ int VulkanContextAndroid::window_create(ANativeWindow *p_window, int p_width, in ERR_FAIL_V_MSG(-1, "vkCreateAndroidSurfaceKHR failed with error " + itos(err)); } - return _window_create(DisplayServer::MAIN_WINDOW_ID, surface, p_width, p_height); + return _window_create(DisplayServer::MAIN_WINDOW_ID, p_vsync_mode, surface, p_width, p_height); } bool VulkanContextAndroid::_use_validation_layers() { diff --git a/platform/android/vulkan/vulkan_context_android.h b/platform/android/vulkan/vulkan_context_android.h index 5a84eaf8f3..182ce33c97 100644 --- a/platform/android/vulkan/vulkan_context_android.h +++ b/platform/android/vulkan/vulkan_context_android.h @@ -39,7 +39,7 @@ class VulkanContextAndroid : public VulkanContext { virtual const char *_get_platform_surface_extension() const override; public: - int window_create(ANativeWindow *p_window, int p_width, int p_height); + int window_create(ANativeWindow *p_window, DisplayServer::VSyncMode p_vsync_mode, int p_width, int p_height); VulkanContextAndroid() = default; ~VulkanContextAndroid() override = default; diff --git a/platform/iphone/display_server_iphone.h b/platform/iphone/display_server_iphone.h index 34c56382a4..6f64130b23 100644 --- a/platform/iphone/display_server_iphone.h +++ b/platform/iphone/display_server_iphone.h @@ -67,7 +67,7 @@ class DisplayServerIPhone : public DisplayServer { void perform_event(const Ref<InputEvent> &p_event); - DisplayServerIPhone(const String &p_rendering_driver, DisplayServer::WindowMode p_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error); + DisplayServerIPhone(const String &p_rendering_driver, DisplayServer::WindowMode p_mode, DisplayServer::VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error); ~DisplayServerIPhone(); public: @@ -76,7 +76,7 @@ public: static DisplayServerIPhone *get_singleton(); static void register_iphone_driver(); - static DisplayServer *create_func(const String &p_rendering_driver, WindowMode p_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error); + static DisplayServer *create_func(const String &p_rendering_driver, WindowMode p_mode, DisplayServer::VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error); static Vector<String> get_rendering_drivers_func(); // MARK: - Events @@ -176,6 +176,9 @@ public: virtual bool can_any_window_draw() const override; + virtual void window_set_vsync_mode(DisplayServer::VSyncMode p_vsync_mode, WindowID p_window = MAIN_WINDOW_ID) override; + virtual DisplayServer::VSyncMode window_get_vsync_mode(WindowID p_vsync_mode) const override; + virtual bool screen_is_touchscreen(int p_screen) const override; virtual void virtual_keyboard_show(const String &p_existing_text, const Rect2 &p_screen_rect, bool p_multiline, int p_max_length, int p_cursor_start, int p_cursor_end) override; diff --git a/platform/iphone/display_server_iphone.mm b/platform/iphone/display_server_iphone.mm index 9e74de0842..bd95e2c703 100644 --- a/platform/iphone/display_server_iphone.mm +++ b/platform/iphone/display_server_iphone.mm @@ -48,7 +48,7 @@ DisplayServerIPhone *DisplayServerIPhone::get_singleton() { return (DisplayServerIPhone *)DisplayServer::get_singleton(); } -DisplayServerIPhone::DisplayServerIPhone(const String &p_rendering_driver, DisplayServer::WindowMode p_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error) { +DisplayServerIPhone::DisplayServerIPhone(const String &p_rendering_driver, WindowMode p_mode, DisplayServer::VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error) { rendering_driver = p_rendering_driver; #if defined(OPENGL_ENABLED) @@ -108,7 +108,7 @@ DisplayServerIPhone::DisplayServerIPhone(const String &p_rendering_driver, Displ } Size2i size = Size2i(layer.bounds.size.width, layer.bounds.size.height) * screen_get_max_scale(); - if (context_vulkan->window_create(MAIN_WINDOW_ID, layer, size.width, size.height) != OK) { + if (context_vulkan->window_create(MAIN_WINDOW_ID, p_vsync_mode, layer, size.width, size.height) != OK) { memdelete(context_vulkan); context_vulkan = nullptr; ERR_FAIL_MSG("Failed to create Vulkan window."); @@ -147,8 +147,8 @@ DisplayServerIPhone::~DisplayServerIPhone() { #endif } -DisplayServer *DisplayServerIPhone::create_func(const String &p_rendering_driver, WindowMode p_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error) { - return memnew(DisplayServerIPhone(p_rendering_driver, p_mode, p_flags, p_resolution, r_error)); +DisplayServer *DisplayServerIPhone::create_func(const String &p_rendering_driver, WindowMode p_mode, DisplayServer::VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error) { + return memnew(DisplayServerIPhone(p_rendering_driver, p_mode, p_vsync_mode, p_flags, p_resolution, r_error)); } Vector<String> DisplayServerIPhone::get_rendering_drivers_func() { @@ -224,7 +224,7 @@ void DisplayServerIPhone::_window_callback(const Callable &p_callable, const Var void DisplayServerIPhone::touch_press(int p_idx, int p_x, int p_y, bool p_pressed, bool p_double_click) { if (!GLOBAL_DEF("debug/disable_touch", false)) { Ref<InputEventScreenTouch> ev; - ev.instance(); + ev.instantiate(); ev->set_index(p_idx); ev->set_pressed(p_pressed); @@ -236,7 +236,7 @@ void DisplayServerIPhone::touch_press(int p_idx, int p_x, int p_y, bool p_presse void DisplayServerIPhone::touch_drag(int p_idx, int p_prev_x, int p_prev_y, int p_x, int p_y) { if (!GLOBAL_DEF("debug/disable_touch", false)) { Ref<InputEventScreenDrag> ev; - ev.instance(); + ev.instantiate(); ev->set_index(p_idx); ev->set_position(Vector2(p_x, p_y)); ev->set_relative(Vector2(p_x - p_prev_x, p_y - p_prev_y)); @@ -256,7 +256,7 @@ void DisplayServerIPhone::touches_cancelled(int p_idx) { void DisplayServerIPhone::key(uint32_t p_key, bool p_pressed) { Ref<InputEventKey> ev; - ev.instance(); + ev.instantiate(); ev->set_echo(false); ev->set_pressed(p_pressed); ev->set_keycode(p_key); @@ -581,3 +581,19 @@ void DisplayServerIPhone::resize_window(CGSize viewSize) { Variant resize_rect = Rect2i(Point2i(), size); _window_callback(window_resize_callback, resize_rect); } + +void DisplayServerIPhone::window_set_vsync_mode(DisplayServer::VSyncMode p_vsync_mode, WindowID p_window) { + _THREAD_SAFE_METHOD_ +#if defined(VULKAN_ENABLED) + context_vulkan->set_vsync_mode(p_window, p_vsync_mode); +#endif +} + +DisplayServer::VSyncMode DisplayServerIPhone::window_get_vsync_mode(WindowID p_window) const { + _THREAD_SAFE_METHOD_ +#if defined(VULKAN_ENABLED) + return context_vulkan->get_vsync_mode(p_window); +#else + return DisplayServer::VSYNC_ENABLED; +#endif +} diff --git a/platform/iphone/export/export.cpp b/platform/iphone/export/export.cpp index e2df573b09..1d1961ac2f 100644 --- a/platform/iphone/export/export.cpp +++ b/platform/iphone/export/export.cpp @@ -367,6 +367,26 @@ void EditorExportPlatformIOS::get_export_options(List<ExportOption> *r_options) for (int i = 0; i < found_plugins.size(); i++) { r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "plugins/" + found_plugins[i].name), false)); } + + for (int i = 0; i < found_plugins.size(); i++) { + // Editable plugin plist values + PluginConfigIOS plugin = found_plugins[i]; + const String *K = nullptr; + + while ((K = plugin.plist.next(K))) { + String key = *K; + PluginConfigIOS::PlistItem item = plugin.plist[key]; + switch (item.type) { + case PluginConfigIOS::PlistItemType::STRING_INPUT: { + String preset_name = "plugins_plist/" + key; + r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, preset_name), item.value)); + } break; + default: + continue; + } + } + } + plugins_changed.clear(); plugins = found_plugins; @@ -820,7 +840,7 @@ Error EditorExportPlatformIOS::_export_loading_screen_file(const Ref<EditorExpor if (custom_launch_image_2x.length() > 0 && custom_launch_image_3x.length() > 0) { Ref<Image> image; String image_path = p_dest_dir.plus_file("splash@2x.png"); - image.instance(); + image.instantiate(); Error err = image->load(custom_launch_image_2x); if (err) { @@ -834,7 +854,7 @@ Error EditorExportPlatformIOS::_export_loading_screen_file(const Ref<EditorExpor image.unref(); image_path = p_dest_dir.plus_file("splash@3x.png"); - image.instance(); + image.instantiate(); err = image->load(custom_launch_image_3x); if (err) { @@ -851,7 +871,7 @@ Error EditorExportPlatformIOS::_export_loading_screen_file(const Ref<EditorExpor const String splash_path = ProjectSettings::get_singleton()->get("application/boot_splash/image"); if (!splash_path.is_empty()) { - splash.instance(); + splash.instantiate(); const Error err = splash->load(splash_path); if (err) { splash.unref(); @@ -1467,13 +1487,28 @@ Error EditorExportPlatformIOS::_export_ios_plugins(const Ref<EditorExportPreset> while ((K = plugin.plist.next(K))) { String key = *K; - String value = plugin.plist[key]; + PluginConfigIOS::PlistItem item = plugin.plist[key]; + + String value; + + switch (item.type) { + case PluginConfigIOS::PlistItemType::STRING_INPUT: { + String preset_name = "plugins_plist/" + key; + String input_value = p_preset->get(preset_name); + value = "<string>" + input_value + "</string>"; + } break; + default: + value = item.value; + break; + } if (key.is_empty() || value.is_empty()) { continue; } - plist_values[key] = value; + String plist_key = "<key>" + key + "</key>"; + + plist_values[plist_key] = value; } // CPP Code @@ -1500,7 +1535,7 @@ Error EditorExportPlatformIOS::_export_ios_plugins(const Ref<EditorExportPreset> continue; } - p_config_data.plist_content += "<key>" + key + "</key><string>" + value + "</string>\n"; + p_config_data.plist_content += key + value + "\n"; } } @@ -1999,7 +2034,7 @@ bool EditorExportPlatformIOS::can_export(const Ref<EditorExportPreset> &p_preset EditorExportPlatformIOS::EditorExportPlatformIOS() { Ref<Image> img = memnew(Image(_iphone_logo)); - logo.instance(); + logo.instantiate(); logo->create_from_image(img); plugins_changed.set(); @@ -2014,7 +2049,7 @@ EditorExportPlatformIOS::~EditorExportPlatformIOS() { void register_iphone_exporter() { Ref<EditorExportPlatformIOS> platform; - platform.instance(); + platform.instantiate(); EditorExport::get_singleton()->add_export_platform(platform); } diff --git a/platform/iphone/plugin/godot_plugin_config.h b/platform/iphone/plugin/godot_plugin_config.h index 4d0c67bfff..06770260aa 100644 --- a/platform/iphone/plugin/godot_plugin_config.h +++ b/platform/iphone/plugin/godot_plugin_config.h @@ -70,6 +70,20 @@ struct PluginConfigIOS { inline static const char *PLIST_SECTION = "plist"; + enum PlistItemType { + UNKNOWN, + STRING, + INTEGER, + BOOLEAN, + RAW, + STRING_INPUT, + }; + + struct PlistItem { + PlistItemType type; + String value; + }; + // Set to true when the config file is properly loaded. bool valid_config = false; bool supports_targets = false; @@ -93,8 +107,10 @@ struct PluginConfigIOS { Vector<String> linker_flags; // Optional plist section - // Supports only string types for now - HashMap<String, String> plist; + // String value is default value. + // Currently supports `string`, `boolean`, `integer`, `raw`, `string_input` types + // <name>:<type> = <value> + HashMap<String, PlistItem> plist; }; static inline String resolve_local_dependency_path(String plugin_config_dir, String dependency_path) { @@ -273,13 +289,68 @@ static inline PluginConfigIOS load_plugin_config(Ref<ConfigFile> config_file, co config_file->get_section_keys(PluginConfigIOS::PLIST_SECTION, &keys); for (int i = 0; i < keys.size(); i++) { - String value = config_file->get_value(PluginConfigIOS::PLIST_SECTION, keys[i], String()); + Vector<String> key_components = keys[i].split(":"); + + String key_value = ""; + PluginConfigIOS::PlistItemType key_type = PluginConfigIOS::PlistItemType::UNKNOWN; + + if (key_components.size() == 1) { + key_value = key_components[0]; + key_type = PluginConfigIOS::PlistItemType::STRING; + } else if (key_components.size() == 2) { + key_value = key_components[0]; + + if (key_components[1].to_lower() == "string") { + key_type = PluginConfigIOS::PlistItemType::STRING; + } else if (key_components[1].to_lower() == "integer") { + key_type = PluginConfigIOS::PlistItemType::INTEGER; + } else if (key_components[1].to_lower() == "boolean") { + key_type = PluginConfigIOS::PlistItemType::BOOLEAN; + } else if (key_components[1].to_lower() == "raw") { + key_type = PluginConfigIOS::PlistItemType::RAW; + } else if (key_components[1].to_lower() == "string_input") { + key_type = PluginConfigIOS::PlistItemType::STRING_INPUT; + } + } - if (value.is_empty()) { + if (key_value.is_empty() || key_type == PluginConfigIOS::PlistItemType::UNKNOWN) { continue; } - plugin_config.plist[keys[i]] = value; + String value; + + switch (key_type) { + case PluginConfigIOS::PlistItemType::STRING: { + String raw_value = config_file->get_value(PluginConfigIOS::PLIST_SECTION, keys[i], String()); + value = "<string>" + raw_value + "</string>"; + } break; + case PluginConfigIOS::PlistItemType::INTEGER: { + int raw_value = config_file->get_value(PluginConfigIOS::PLIST_SECTION, keys[i], 0); + Dictionary value_dictionary; + String value_format = "<integer>$value</integer>"; + value_dictionary["value"] = raw_value; + value = value_format.format(value_dictionary, "$_"); + } break; + case PluginConfigIOS::PlistItemType::BOOLEAN: + if (config_file->get_value(PluginConfigIOS::PLIST_SECTION, keys[i], false)) { + value = "<true/>"; + } else { + value = "<false/>"; + } + break; + case PluginConfigIOS::PlistItemType::RAW: { + String raw_value = config_file->get_value(PluginConfigIOS::PLIST_SECTION, keys[i], String()); + value = raw_value; + } break; + case PluginConfigIOS::PlistItemType::STRING_INPUT: { + String raw_value = config_file->get_value(PluginConfigIOS::PLIST_SECTION, keys[i], String()); + value = raw_value; + } break; + default: + continue; + } + + plugin_config.plist[key_value] = PluginConfigIOS::PlistItem{ key_type, value }; } } diff --git a/platform/iphone/vulkan_context_iphone.h b/platform/iphone/vulkan_context_iphone.h index 88764e270e..ec6aaf46e8 100644 --- a/platform/iphone/vulkan_context_iphone.h +++ b/platform/iphone/vulkan_context_iphone.h @@ -39,7 +39,7 @@ class VulkanContextIPhone : public VulkanContext { virtual const char *_get_platform_surface_extension() const; public: - Error window_create(DisplayServer::WindowID p_window_id, CALayer *p_metal_layer, int p_width, int p_height); + Error window_create(DisplayServer::WindowID p_window_id, DisplayServer::VSyncMode p_vsync_mode, CALayer *p_metal_layer, int p_width, int p_height); VulkanContextIPhone(); ~VulkanContextIPhone(); diff --git a/platform/iphone/vulkan_context_iphone.mm b/platform/iphone/vulkan_context_iphone.mm index 08c9007fbb..17f2b167b3 100644 --- a/platform/iphone/vulkan_context_iphone.mm +++ b/platform/iphone/vulkan_context_iphone.mm @@ -35,7 +35,7 @@ const char *VulkanContextIPhone::_get_platform_surface_extension() const { return VK_MVK_IOS_SURFACE_EXTENSION_NAME; } -Error VulkanContextIPhone::window_create(DisplayServer::WindowID p_window_id, CALayer *p_metal_layer, int p_width, int p_height) { +Error VulkanContextIPhone::window_create(DisplayServer::WindowID p_window_id, DisplayServer::VSyncMode p_vsync_mode, CALayer *p_metal_layer, int p_width, int p_height) { VkIOSSurfaceCreateInfoMVK createInfo; createInfo.sType = VK_STRUCTURE_TYPE_IOS_SURFACE_CREATE_INFO_MVK; createInfo.pNext = nullptr; @@ -47,7 +47,7 @@ Error VulkanContextIPhone::window_create(DisplayServer::WindowID p_window_id, CA vkCreateIOSSurfaceMVK(_get_instance(), &createInfo, nullptr, &surface); ERR_FAIL_COND_V(err, ERR_CANT_CREATE); - return _window_create(p_window_id, surface, p_width, p_height); + return _window_create(p_window_id, p_vsync_mode, surface, p_width, p_height); } VulkanContextIPhone::VulkanContextIPhone() {} diff --git a/platform/javascript/display_server_javascript.cpp b/platform/javascript/display_server_javascript.cpp index 1cc05a2e19..f1b92264e2 100644 --- a/platform/javascript/display_server_javascript.cpp +++ b/platform/javascript/display_server_javascript.cpp @@ -128,7 +128,7 @@ void DisplayServerJavaScript::dom2godot_mod(T *emscripten_event_ptr, Ref<InputEv Ref<InputEventKey> DisplayServerJavaScript::setup_key_event(const EmscriptenKeyboardEvent *emscripten_event) { Ref<InputEventKey> ev; - ev.instance(); + ev.instantiate(); ev->set_echo(emscripten_event->repeat); dom2godot_mod(emscripten_event, ev); ev->set_keycode(dom_code2godot_scancode(emscripten_event->code, emscripten_event->key, false)); @@ -181,7 +181,7 @@ EM_BOOL DisplayServerJavaScript::mouse_button_callback(int p_event_type, const E DisplayServerJavaScript *display = get_singleton(); Ref<InputEventMouseButton> ev; - ev.instance(); + ev.instantiate(); ev->set_pressed(p_event_type == EMSCRIPTEN_EVENT_MOUSEDOWN); ev->set_position(compute_position_in_canvas(p_event->clientX, p_event->clientY)); ev->set_global_position(ev->get_position()); @@ -229,8 +229,8 @@ EM_BOOL DisplayServerJavaScript::mouse_button_callback(int p_event_type, const E } Input *input = Input::get_singleton(); - int mask = input->get_mouse_button_mask(); - int button_flag = 1 << (ev->get_button_index() - 1); + MouseButton mask = input->get_mouse_button_mask(); + MouseButton button_flag = MouseButton(1 << (ev->get_button_index() - 1)); if (ev->is_pressed()) { // Since the event is consumed, focus manually. The containing iframe, // if exists, may not have focus yet, so focus even if already focused. @@ -261,7 +261,7 @@ EM_BOOL DisplayServerJavaScript::mousemove_callback(int p_event_type, const Emsc return false; Ref<InputEventMouseMotion> ev; - ev.instance(); + ev.instantiate(); dom2godot_mod(p_event, ev); ev->set_button_mask(input_mask); @@ -452,7 +452,7 @@ EM_BOOL DisplayServerJavaScript::wheel_callback(int p_event_type, const Emscript Input *input = Input::get_singleton(); Ref<InputEventMouseButton> ev; - ev.instance(); + ev.instantiate(); ev->set_position(input->get_mouse_position()); ev->set_global_position(ev->get_position()); @@ -478,11 +478,11 @@ EM_BOOL DisplayServerJavaScript::wheel_callback(int p_event_type, const Emscript int button_flag = 1 << (ev->get_button_index() - 1); ev->set_pressed(true); - ev->set_button_mask(input->get_mouse_button_mask() | button_flag); + ev->set_button_mask(MouseButton(input->get_mouse_button_mask() | button_flag)); input->parse_input_event(ev); ev->set_pressed(false); - ev->set_button_mask(input->get_mouse_button_mask() & ~button_flag); + ev->set_button_mask(MouseButton(input->get_mouse_button_mask() & ~button_flag)); input->parse_input_event(ev); return true; @@ -492,7 +492,7 @@ EM_BOOL DisplayServerJavaScript::wheel_callback(int p_event_type, const Emscript EM_BOOL DisplayServerJavaScript::touch_press_callback(int p_event_type, const EmscriptenTouchEvent *p_event, void *p_user_data) { DisplayServerJavaScript *display = get_singleton(); Ref<InputEventScreenTouch> ev; - ev.instance(); + ev.instantiate(); int lowest_id_index = -1; for (int i = 0; i < p_event->numTouches; ++i) { const EmscriptenTouchPoint &touch = p_event->touches[i]; @@ -514,7 +514,7 @@ EM_BOOL DisplayServerJavaScript::touch_press_callback(int p_event_type, const Em EM_BOOL DisplayServerJavaScript::touchmove_callback(int p_event_type, const EmscriptenTouchEvent *p_event, void *p_user_data) { DisplayServerJavaScript *display = get_singleton(); Ref<InputEventScreenDrag> ev; - ev.instance(); + ev.instantiate(); int lowest_id_index = -1; for (int i = 0; i < p_event->numTouches; ++i) { const EmscriptenTouchPoint &touch = p_event->touches[i]; @@ -553,12 +553,12 @@ void DisplayServerJavaScript::vk_input_text_callback(const char *p_text, int p_c Input *input = Input::get_singleton(); Ref<InputEventKey> k; for (int i = 0; i < p_cursor; i++) { - k.instance(); + k.instantiate(); k->set_pressed(true); k->set_echo(false); k->set_keycode(KEY_RIGHT); input->parse_input_event(k); - k.instance(); + k.instantiate(); k->set_pressed(false); k->set_echo(false); k->set_keycode(KEY_RIGHT); diff --git a/platform/javascript/export/export.cpp b/platform/javascript/export/export.cpp index 7e49feee61..bf4244eda4 100644 --- a/platform/javascript/export/export.cpp +++ b/platform/javascript/export/export.cpp @@ -29,7 +29,6 @@ /*************************************************************************/ #include "core/io/image_loader.h" -#include "core/io/json.h" #include "core/io/stream_peer_ssl.h" #include "core/io/tcp_server.h" #include "core/io/zip_io.h" @@ -91,7 +90,7 @@ public: mimes["png"] = "image/png"; mimes["svg"] = "image/svg"; mimes["wasm"] = "application/wasm"; - server.instance(); + server.instantiate(); stop(); } @@ -136,8 +135,11 @@ public: // Wrong protocol ERR_FAIL_COND_MSG(req[0] != "GET" || req[2] != "HTTP/1.1", "Invalid method or HTTP version."); - const String req_file = req[1].get_file(); - const String req_ext = req[1].get_extension(); + const int query_index = req[1].find_char('?'); + const String path = (query_index == -1) ? req[1] : req[1].substr(0, query_index); + + const String req_file = path.get_file(); + const String req_ext = path.get_extension(); const String cache_path = EditorPaths::get_singleton()->get_cache_dir().plus_file("web"); const String filepath = cache_path.plus_file(req_file); @@ -290,7 +292,7 @@ class EditorExportPlatformJavaScript : public EditorExportPlatform { Ref<Image> _get_project_icon() const { Ref<Image> icon; - icon.instance(); + icon.instantiate(); const String icon_path = String(GLOBAL_GET("application/config/icon")).strip_edges(); if (icon_path.is_empty() || ImageLoader::load_image(icon_path, icon) != OK) { return EditorNode::get_singleton()->get_editor_theme()->get_icon("DefaultProjectIcon", "EditorIcons")->get_image(); @@ -300,7 +302,7 @@ class EditorExportPlatformJavaScript : public EditorExportPlatform { Ref<Image> _get_project_splash() const { Ref<Image> splash; - splash.instance(); + splash.instantiate(); const String splash_path = String(GLOBAL_GET("application/boot_splash/image")).strip_edges(); if (splash_path.is_empty() || ImageLoader::load_image(splash_path, splash) != OK) { return Ref<Image>(memnew(Image(boot_splash_png))); @@ -448,6 +450,7 @@ void EditorExportPlatformJavaScript::_fix_html(Vector<uint8_t> &p_html, const Re } config["canvasResizePolicy"] = p_preset->get("html/canvas_resize_policy"); config["experimentalVK"] = p_preset->get("html/experimental_virtual_keyboard"); + config["focusCanvas"] = p_preset->get("html/focus_canvas_on_start"); config["gdnativeLibs"] = libs; config["executable"] = p_name; config["args"] = args; @@ -465,7 +468,7 @@ void EditorExportPlatformJavaScript::_fix_html(Vector<uint8_t> &p_html, const Re } // Replaces HTML string - const String str_config = JSON::print(config); + const String str_config = Variant(config).to_json_string(); const String custom_head_include = p_preset->get("html/head_include"); Map<String, String> replaces; replaces["$GODOT_URL"] = p_name + ".js"; @@ -482,7 +485,7 @@ Error EditorExportPlatformJavaScript::_add_manifest_icon(const String &p_path, c Ref<Image> icon; if (!p_icon.is_empty()) { - icon.instance(); + icon.instantiate(); const Error err = ImageLoader::load_image(p_icon, icon); if (err != OK) { EditorNode::get_singleton()->show_warning(TTR("Could not read file:") + "\n" + p_icon); @@ -518,7 +521,7 @@ Error EditorExportPlatformJavaScript::_build_pwa(const Ref<EditorExportPreset> & replaces["@GODOT_NAME@"] = name; replaces["@GODOT_OFFLINE_PAGE@"] = name + ".offline.html"; Array files; - replaces["@GODOT_OPT_CACHE@"] = JSON::print(files); + replaces["@GODOT_OPT_CACHE@"] = Variant(files).to_json_string(); files.push_back(name + ".html"); files.push_back(name + ".js"); files.push_back(name + ".wasm"); @@ -537,7 +540,7 @@ Error EditorExportPlatformJavaScript::_build_pwa(const Ref<EditorExportPreset> & files.push_back(p_shared_objects[i].path.get_file()); } } - replaces["@GODOT_CACHE@"] = JSON::print(files); + replaces["@GODOT_CACHE@"] = Variant(files).to_json_string(); const String sw_path = dir.plus_file(name + ".service.worker.js"); Vector<uint8_t> sw; @@ -605,7 +608,7 @@ Error EditorExportPlatformJavaScript::_build_pwa(const Ref<EditorExportPreset> & } manifest["icons"] = icons_arr; - CharString cs = JSON::print(manifest).utf8(); + CharString cs = Variant(manifest).to_json_string().utf8(); err = _write_or_error((const uint8_t *)cs.get_data(), cs.length(), dir.plus_file(name + ".manifest.json")); if (err != OK) { return err; @@ -648,6 +651,7 @@ void EditorExportPlatformJavaScript::get_export_options(List<ExportOption> *r_op r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "html/custom_html_shell", PROPERTY_HINT_FILE, "*.html"), "")); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "html/head_include", PROPERTY_HINT_MULTILINE_TEXT), "")); r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "html/canvas_resize_policy", PROPERTY_HINT_ENUM, "None,Project,Adaptive"), 2)); + r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "html/focus_canvas_on_start"), true)); r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "html/experimental_virtual_keyboard"), false)); r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "progressive_web_app/enabled"), false)); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "progressive_web_app/offline_page", PROPERTY_HINT_FILE, "*.html"), "")); @@ -965,22 +969,22 @@ void EditorExportPlatformJavaScript::_server_thread_poll(void *data) { } EditorExportPlatformJavaScript::EditorExportPlatformJavaScript() { - server.instance(); + server.instantiate(); server_thread.start(_server_thread_poll, this); Ref<Image> img = memnew(Image(_javascript_logo)); - logo.instance(); + logo.instantiate(); logo->create_from_image(img); img = Ref<Image>(memnew(Image(_javascript_run_icon))); - run_icon.instance(); + run_icon.instantiate(); run_icon->create_from_image(img); Ref<Theme> theme = EditorNode::get_singleton()->get_editor_theme(); if (theme.is_valid()) { stop_icon = theme->get_icon("Stop", "EditorIcons"); } else { - stop_icon.instance(); + stop_icon.instantiate(); } } @@ -1001,6 +1005,6 @@ void register_javascript_exporter() { EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING, "export/web/ssl_certificate", PROPERTY_HINT_GLOBAL_FILE, "*.crt,*.pem")); Ref<EditorExportPlatformJavaScript> platform; - platform.instance(); + platform.instantiate(); EditorExport::get_singleton()->add_export_platform(platform); } diff --git a/platform/javascript/http_client_javascript.cpp b/platform/javascript/http_client_javascript.cpp index a6cf4b0eb8..f7d78abcea 100644 --- a/platform/javascript/http_client_javascript.cpp +++ b/platform/javascript/http_client_javascript.cpp @@ -28,45 +28,19 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "core/io/http_client.h" +#include "http_client_javascript.h" -#ifdef __cplusplus -extern "C" { -#endif - -#include "stddef.h" - -typedef enum { - GODOT_JS_FETCH_STATE_REQUESTING = 0, - GODOT_JS_FETCH_STATE_BODY = 1, - GODOT_JS_FETCH_STATE_DONE = 2, - GODOT_JS_FETCH_STATE_ERROR = -1, -} godot_js_fetch_state_t; - -extern int godot_js_fetch_create(const char *p_method, const char *p_url, const char **p_headers, int p_headers_len, const uint8_t *p_body, int p_body_len); -extern int godot_js_fetch_read_headers(int p_id, void (*parse_callback)(int p_size, const char **p_headers, void *p_ref), void *p_ref); -extern int godot_js_fetch_read_chunk(int p_id, uint8_t *p_buf, int p_buf_size); -extern void godot_js_fetch_free(int p_id); -extern godot_js_fetch_state_t godot_js_fetch_state_get(int p_id); -extern int godot_js_fetch_body_length_get(int p_id); -extern int godot_js_fetch_http_status_get(int p_id); -extern int godot_js_fetch_is_chunked(int p_id); - -#ifdef __cplusplus -} -#endif - -void HTTPClient::_parse_headers(int p_len, const char **p_headers, void *p_ref) { - HTTPClient *client = static_cast<HTTPClient *>(p_ref); +void HTTPClientJavaScript::_parse_headers(int p_len, const char **p_headers, void *p_ref) { + HTTPClientJavaScript *client = static_cast<HTTPClientJavaScript *>(p_ref); for (int i = 0; i < p_len; i++) { client->response_headers.push_back(String::utf8(p_headers[i])); } } -Error HTTPClient::connect_to_host(const String &p_host, int p_port, bool p_ssl, bool p_verify_host) { +Error HTTPClientJavaScript::connect_to_host(const String &p_host, int p_port, bool p_ssl, bool p_verify_host) { close(); if (p_ssl && !p_verify_host) { - WARN_PRINT("Disabling HTTPClient's host verification is not supported for the HTML5 platform, host will be verified"); + WARN_PRINT("Disabling HTTPClientJavaScript's host verification is not supported for the HTML5 platform, host will be verified"); } port = p_port; @@ -97,15 +71,15 @@ Error HTTPClient::connect_to_host(const String &p_host, int p_port, bool p_ssl, return OK; } -void HTTPClient::set_connection(const Ref<StreamPeer> &p_connection) { - ERR_FAIL_MSG("Accessing an HTTPClient's StreamPeer is not supported for the HTML5 platform."); +void HTTPClientJavaScript::set_connection(const Ref<StreamPeer> &p_connection) { + ERR_FAIL_MSG("Accessing an HTTPClientJavaScript's StreamPeer is not supported for the HTML5 platform."); } -Ref<StreamPeer> HTTPClient::get_connection() const { - ERR_FAIL_V_MSG(REF(), "Accessing an HTTPClient's StreamPeer is not supported for the HTML5 platform."); +Ref<StreamPeer> HTTPClientJavaScript::get_connection() const { + ERR_FAIL_V_MSG(REF(), "Accessing an HTTPClientJavaScript's StreamPeer is not supported for the HTML5 platform."); } -Error HTTPClient::make_request(Method p_method, const String &p_url, const Vector<String> &p_headers, const uint8_t *p_body, int p_body_len) { +Error HTTPClientJavaScript::request(Method p_method, const String &p_url, const Vector<String> &p_headers, const uint8_t *p_body, int p_body_len) { ERR_FAIL_INDEX_V(p_method, METHOD_MAX, ERR_INVALID_PARAMETER); ERR_FAIL_COND_V_MSG(p_method == METHOD_TRACE || p_method == METHOD_CONNECT, ERR_UNAVAILABLE, "HTTP methods TRACE and CONNECT are not supported for the HTML5 platform."); ERR_FAIL_COND_V(status != STATUS_CONNECTED, ERR_INVALID_PARAMETER); @@ -128,22 +102,7 @@ Error HTTPClient::make_request(Method p_method, const String &p_url, const Vecto return OK; } -Error HTTPClient::request_raw(Method p_method, const String &p_url, const Vector<String> &p_headers, const Vector<uint8_t> &p_body) { - if (p_body.is_empty()) { - return make_request(p_method, p_url, p_headers, nullptr, 0); - } - return make_request(p_method, p_url, p_headers, p_body.ptr(), p_body.size()); -} - -Error HTTPClient::request(Method p_method, const String &p_url, const Vector<String> &p_headers, const String &p_body) { - if (p_body.is_empty()) { - return make_request(p_method, p_url, p_headers, nullptr, 0); - } - const CharString cs = p_body.utf8(); - return make_request(p_method, p_url, p_headers, (const uint8_t *)cs.get_data(), cs.size() - 1); -} - -void HTTPClient::close() { +void HTTPClientJavaScript::close() { host = ""; port = -1; use_tls = false; @@ -157,23 +116,23 @@ void HTTPClient::close() { } } -HTTPClient::Status HTTPClient::get_status() const { +HTTPClientJavaScript::Status HTTPClientJavaScript::get_status() const { return status; } -bool HTTPClient::has_response() const { +bool HTTPClientJavaScript::has_response() const { return response_headers.size() > 0; } -bool HTTPClient::is_response_chunked() const { +bool HTTPClientJavaScript::is_response_chunked() const { return godot_js_fetch_is_chunked(js_id); } -int HTTPClient::get_response_code() const { +int HTTPClientJavaScript::get_response_code() const { return polled_response_code; } -Error HTTPClient::get_response_headers(List<String> *r_response) { +Error HTTPClientJavaScript::get_response_headers(List<String> *r_response) { if (!response_headers.size()) { return ERR_INVALID_PARAMETER; } @@ -184,11 +143,11 @@ Error HTTPClient::get_response_headers(List<String> *r_response) { return OK; } -int HTTPClient::get_response_body_length() const { +int HTTPClientJavaScript::get_response_body_length() const { return godot_js_fetch_body_length_get(js_id); } -PackedByteArray HTTPClient::read_response_body_chunk() { +PackedByteArray HTTPClientJavaScript::read_response_body_chunk() { ERR_FAIL_COND_V(status != STATUS_BODY, PackedByteArray()); if (response_buffer.size() != read_limit) { @@ -213,23 +172,23 @@ PackedByteArray HTTPClient::read_response_body_chunk() { return chunk; } -void HTTPClient::set_blocking_mode(bool p_enable) { - ERR_FAIL_COND_MSG(p_enable, "HTTPClient blocking mode is not supported for the HTML5 platform."); +void HTTPClientJavaScript::set_blocking_mode(bool p_enable) { + ERR_FAIL_COND_MSG(p_enable, "HTTPClientJavaScript blocking mode is not supported for the HTML5 platform."); } -bool HTTPClient::is_blocking_mode_enabled() const { +bool HTTPClientJavaScript::is_blocking_mode_enabled() const { return false; } -void HTTPClient::set_read_chunk_size(int p_size) { +void HTTPClientJavaScript::set_read_chunk_size(int p_size) { read_limit = p_size; } -int HTTPClient::get_read_chunk_size() const { +int HTTPClientJavaScript::get_read_chunk_size() const { return read_limit; } -Error HTTPClient::poll() { +Error HTTPClientJavaScript::poll() { switch (status) { case STATUS_DISCONNECTED: return ERR_UNCONFIGURED; @@ -263,7 +222,7 @@ Error HTTPClient::poll() { #ifdef DEBUG_ENABLED // forcing synchronous requests is not possible on the web if (last_polling_frame == Engine::get_singleton()->get_process_frames()) { - WARN_PRINT("HTTPClient polled multiple times in one frame, " + WARN_PRINT("HTTPClientJavaScript polled multiple times in one frame, " "but request cannot progress more than once per " "frame on the HTML5 platform."); } @@ -294,9 +253,15 @@ Error HTTPClient::poll() { return OK; } -HTTPClient::HTTPClient() { +HTTPClient *HTTPClientJavaScript::_create_func() { + return memnew(HTTPClientJavaScript); +} + +HTTPClient *(*HTTPClient::_create)() = HTTPClientJavaScript::_create_func; + +HTTPClientJavaScript::HTTPClientJavaScript() { } -HTTPClient::~HTTPClient() { +HTTPClientJavaScript::~HTTPClientJavaScript() { close(); } diff --git a/platform/javascript/http_client_javascript.h b/platform/javascript/http_client_javascript.h new file mode 100644 index 0000000000..33f91f67b6 --- /dev/null +++ b/platform/javascript/http_client_javascript.h @@ -0,0 +1,108 @@ +/*************************************************************************/ +/* http_client_javascript.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef HTTP_CLIENT_JAVASCRIPT_H +#define HTTP_CLIENT_JAVASCRIPT_H + +#include "core/io/http_client.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#include "stddef.h" + +typedef enum { + GODOT_JS_FETCH_STATE_REQUESTING = 0, + GODOT_JS_FETCH_STATE_BODY = 1, + GODOT_JS_FETCH_STATE_DONE = 2, + GODOT_JS_FETCH_STATE_ERROR = -1, +} godot_js_fetch_state_t; + +extern int godot_js_fetch_create(const char *p_method, const char *p_url, const char **p_headers, int p_headers_len, const uint8_t *p_body, int p_body_len); +extern int godot_js_fetch_read_headers(int p_id, void (*parse_callback)(int p_size, const char **p_headers, void *p_ref), void *p_ref); +extern int godot_js_fetch_read_chunk(int p_id, uint8_t *p_buf, int p_buf_size); +extern void godot_js_fetch_free(int p_id); +extern godot_js_fetch_state_t godot_js_fetch_state_get(int p_id); +extern int godot_js_fetch_body_length_get(int p_id); +extern int godot_js_fetch_http_status_get(int p_id); +extern int godot_js_fetch_is_chunked(int p_id); + +#ifdef __cplusplus +} +#endif + +class HTTPClientJavaScript : public HTTPClient { +private: + int js_id = 0; + Status status = STATUS_DISCONNECTED; + + // 64 KiB by default (favors fast download speeds at the cost of memory usage). + int read_limit = 65536; + + String host; + int port = -1; + bool use_tls = false; + + int polled_response_code = 0; + Vector<String> response_headers; + Vector<uint8_t> response_buffer; + +#ifdef DEBUG_ENABLED + uint64_t last_polling_frame = 0; +#endif + + static void _parse_headers(int p_len, const char **p_headers, void *p_ref); + +public: + static HTTPClient *_create_func(); + + Error request(Method p_method, const String &p_url, const Vector<String> &p_headers, const uint8_t *p_body, int p_body_size) override; + + Error connect_to_host(const String &p_host, int p_port = -1, bool p_ssl = false, bool p_verify_host = true) override; + void set_connection(const Ref<StreamPeer> &p_connection) override; + Ref<StreamPeer> get_connection() const override; + void close() override; + Status get_status() const override; + bool has_response() const override; + bool is_response_chunked() const override; + int get_response_code() const override; + Error get_response_headers(List<String> *r_response) override; + int get_response_body_length() const override; + PackedByteArray read_response_body_chunk() override; + void set_blocking_mode(bool p_enable) override; + bool is_blocking_mode_enabled() const override; + void set_read_chunk_size(int p_size) override; + int get_read_chunk_size() const override; + Error poll() override; + HTTPClientJavaScript(); + ~HTTPClientJavaScript(); +}; +#endif // HTTP_CLIENT_JAVASCRIPT_H diff --git a/platform/javascript/javascript_singleton.cpp b/platform/javascript/javascript_singleton.cpp index 9de2edc9a7..1dd73ef8e9 100644 --- a/platform/javascript/javascript_singleton.cpp +++ b/platform/javascript/javascript_singleton.cpp @@ -183,7 +183,7 @@ Variant JavaScriptObjectImpl::_js2variant(int p_type, godot_js_wrapper_ex *p_val case Variant::FLOAT: return p_val->r; case Variant::STRING: { - String out((const char *)p_val->p); + String out = String::utf8((const char *)p_val->p); free(p_val->p); return out; } diff --git a/platform/javascript/js/engine/config.js b/platform/javascript/js/engine/config.js index 6072782875..ba61b14eb7 100644 --- a/platform/javascript/js/engine/config.js +++ b/platform/javascript/js/engine/config.js @@ -91,6 +91,14 @@ const InternalConfig = function (initConfig) { // eslint-disable-line no-unused- */ args: [], /** + * When enabled, the game canvas will automatically grab the focus when the engine starts. + * + * @memberof EngineConfig + * @type {boolean} + * @default + */ + focusCanvas: true, + /** * When enabled, this will turn on experimental virtual keyboard support on mobile. * * @memberof EngineConfig @@ -238,6 +246,7 @@ const InternalConfig = function (initConfig) { // eslint-disable-line no-unused- this.persistentPaths = parse('persistentPaths', this.persistentPaths); this.persistentDrops = parse('persistentDrops', this.persistentDrops); this.experimentalVK = parse('experimentalVK', this.experimentalVK); + this.focusCanvas = parse('focusCanvas', this.focusCanvas); this.gdnativeLibs = parse('gdnativeLibs', this.gdnativeLibs); this.fileSizes = parse('fileSizes', this.fileSizes); this.args = parse('args', this.args); @@ -324,6 +333,7 @@ const InternalConfig = function (initConfig) { // eslint-disable-line no-unused- 'locale': locale, 'persistentDrops': this.persistentDrops, 'virtualKeyboard': this.experimentalVK, + 'focusCanvas': this.focusCanvas, 'onExecute': this.onExecute, 'onExit': function (p_code) { cleanup(); // We always need to call the cleanup callback to free memory. diff --git a/platform/javascript/js/libs/library_godot_os.js b/platform/javascript/js/libs/library_godot_os.js index 7414b8cc47..5aa750757c 100644 --- a/platform/javascript/js/libs/library_godot_os.js +++ b/platform/javascript/js/libs/library_godot_os.js @@ -72,6 +72,9 @@ const GodotConfig = { GodotConfig.persistent_drops = !!p_opts['persistentDrops']; GodotConfig.on_execute = p_opts['onExecute']; GodotConfig.on_exit = p_opts['onExit']; + if (p_opts['focusCanvas']) { + GodotConfig.canvas.focus(); + } }, locate_file: function (file) { diff --git a/platform/linuxbsd/SCsub b/platform/linuxbsd/SCsub index 1751d56e71..8aebd57fd2 100644 --- a/platform/linuxbsd/SCsub +++ b/platform/linuxbsd/SCsub @@ -9,6 +9,7 @@ common_linuxbsd = [ "crash_handler_linuxbsd.cpp", "os_linuxbsd.cpp", "joypad_linux.cpp", + "freedesktop_screensaver.cpp", ] if "x11" in env and env["x11"]: diff --git a/platform/linuxbsd/detect.py b/platform/linuxbsd/detect.py index 1487210174..eba672ddcb 100644 --- a/platform/linuxbsd/detect.py +++ b/platform/linuxbsd/detect.py @@ -72,6 +72,7 @@ def get_opts(): BoolVariable("use_tsan", "Use LLVM/GCC compiler thread sanitizer (TSAN)", False), BoolVariable("use_msan", "Use LLVM compiler memory sanitizer (MSAN)", False), BoolVariable("pulseaudio", "Detect and use PulseAudio", True), + BoolVariable("dbus", "Detect and use D-Bus to handle screensaver", True), BoolVariable("udev", "Use udev for gamepad connection callbacks", True), BoolVariable("x11", "Enable X11 display", True), BoolVariable("debug_symbols", "Add debugging symbols to release/release_debug builds", True), @@ -347,6 +348,14 @@ def configure(env): else: print("PulseAudio development libraries not found, disabling driver") + if env["dbus"]: + if os.system("pkg-config --exists dbus-1") == 0: # 0 means found + print("Enabling D-Bus") + env.Append(CPPDEFINES=["DBUS_ENABLED"]) + env.ParseConfig("pkg-config --cflags --libs dbus-1") + else: + print("D-Bus development libraries not found, disabling dependent features") + if platform.system() == "Linux": env.Append(CPPDEFINES=["JOYDEV_ENABLED"]) if env["udev"]: diff --git a/platform/linuxbsd/display_server_x11.cpp b/platform/linuxbsd/display_server_x11.cpp index 8b6922699c..8f0742041c 100644 --- a/platform/linuxbsd/display_server_x11.cpp +++ b/platform/linuxbsd/display_server_x11.cpp @@ -121,6 +121,9 @@ bool DisplayServerX11::has_feature(Feature p_feature) const { case FEATURE_ICON: case FEATURE_NATIVE_ICON: case FEATURE_SWAP_BUFFERS: +#ifdef DBUS_ENABLED + case FEATURE_KEEP_SCREEN_ON: +#endif return true; default: { } @@ -450,7 +453,7 @@ Point2i DisplayServerX11::mouse_get_absolute_position() const { return Vector2i(); } -int DisplayServerX11::mouse_get_button_state() const { +MouseButton DisplayServerX11::mouse_get_button_state() const { return last_button_state; } @@ -822,6 +825,26 @@ bool DisplayServerX11::screen_is_touchscreen(int p_screen) const { return DisplayServer::screen_is_touchscreen(p_screen); } +#ifdef DBUS_ENABLED +void DisplayServerX11::screen_set_keep_on(bool p_enable) { + if (screen_is_kept_on() == p_enable) { + return; + } + + if (p_enable) { + screensaver->inhibit(); + } else { + screensaver->uninhibit(); + } + + keep_screen_on = p_enable; +} + +bool DisplayServerX11::screen_is_kept_on() const { + return keep_screen_on; +} +#endif + Vector<DisplayServer::WindowID> DisplayServerX11::get_window_list() const { _THREAD_SAFE_METHOD_ @@ -832,10 +855,10 @@ Vector<DisplayServer::WindowID> DisplayServerX11::get_window_list() const { return ret; } -DisplayServer::WindowID DisplayServerX11::create_sub_window(WindowMode p_mode, uint32_t p_flags, const Rect2i &p_rect) { +DisplayServer::WindowID DisplayServerX11::create_sub_window(WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Rect2i &p_rect) { _THREAD_SAFE_METHOD_ - WindowID id = _create_window(p_mode, p_flags, p_rect); + WindowID id = _create_window(p_mode, p_vsync_mode, p_flags, p_rect); for (int i = 0; i < WINDOW_FLAG_MAX; i++) { if (p_flags & (1 << i)) { window_set_flag(WindowFlags(i), true, id); @@ -2172,13 +2195,13 @@ void DisplayServerX11::_get_key_modifier_state(unsigned int p_x11_state, Ref<Inp state->set_meta_pressed((p_x11_state & Mod4Mask)); } -unsigned int DisplayServerX11::_get_mouse_button_state(unsigned int p_x11_button, int p_x11_type) { - unsigned int mask = 1 << (p_x11_button - 1); +MouseButton DisplayServerX11::_get_mouse_button_state(MouseButton p_x11_button, int p_x11_type) { + MouseButton mask = MouseButton(1 << (p_x11_button - 1)); if (p_x11_type == ButtonPress) { last_button_state |= mask; } else { - last_button_state &= ~mask; + last_button_state &= MouseButton(~mask); } return last_button_state; @@ -2255,7 +2278,7 @@ void DisplayServerX11::_handle_key_event(WindowID p_window, XKeyEvent *p_event, tmp.parse_utf8(utf8string, utf8bytes); for (int i = 0; i < tmp.length(); i++) { Ref<InputEventKey> k; - k.instance(); + k.instantiate(); if (physical_keycode == 0 && keycode == 0 && tmp[i] == 0) { continue; } @@ -2346,7 +2369,7 @@ void DisplayServerX11::_handle_key_event(WindowID p_window, XKeyEvent *p_event, //print_verbose("mod1: "+itos(xkeyevent->state&Mod1Mask)+" mod 5: "+itos(xkeyevent->state&Mod5Mask)); Ref<InputEventKey> k; - k.instance(); + k.instantiate(); k->set_window_id(p_window); _get_key_modifier_state(xkeyevent->state, k); @@ -2904,7 +2927,7 @@ void DisplayServerX11::process_events() { bool is_begin = event_data->evtype == XI_TouchBegin; Ref<InputEventScreenTouch> st; - st.instance(); + st.instantiate(); st->set_window_id(window_id); st->set_index(index); st->set_position(pos); @@ -2938,7 +2961,7 @@ void DisplayServerX11::process_events() { if (curr_pos_elem->value() != pos) { Ref<InputEventScreenDrag> sd; - sd.instance(); + sd.instantiate(); sd->set_window_id(window_id); sd->set_index(index); sd->set_position(pos); @@ -3091,7 +3114,7 @@ void DisplayServerX11::process_events() { // Release every pointer to avoid sticky points for (Map<int, Vector2>::Element *E = xi.state.front(); E; E = E->next()) { Ref<InputEventScreenTouch> st; - st.instance(); + st.instantiate(); st->set_index(E->key()); st->set_window_id(window_id); st->set_position(E->get()); @@ -3126,15 +3149,15 @@ void DisplayServerX11::process_events() { } Ref<InputEventMouseButton> mb; - mb.instance(); + mb.instantiate(); mb->set_window_id(window_id); _get_key_modifier_state(event.xbutton.state, mb); - mb->set_button_index(event.xbutton.button); - if (mb->get_button_index() == 2) { - mb->set_button_index(3); - } else if (mb->get_button_index() == 3) { - mb->set_button_index(2); + mb->set_button_index((MouseButton)event.xbutton.button); + if (mb->get_button_index() == MOUSE_BUTTON_RIGHT) { + mb->set_button_index(MOUSE_BUTTON_MIDDLE); + } else if (mb->get_button_index() == MOUSE_BUTTON_MIDDLE) { + mb->set_button_index(MOUSE_BUTTON_RIGHT); } mb->set_button_mask(_get_mouse_button_state(mb->get_button_index(), event.xbutton.type)); mb->set_position(Vector2(event.xbutton.x, event.xbutton.y)); @@ -3291,13 +3314,13 @@ void DisplayServerX11::process_events() { } Ref<InputEventMouseMotion> mm; - mm.instance(); + mm.instantiate(); mm->set_window_id(window_id); if (xi.pressure_supported) { mm->set_pressure(xi.pressure); } else { - mm->set_pressure((mouse_get_button_state() & (1 << (MOUSE_BUTTON_LEFT - 1))) ? 1.0f : 0.0f); + mm->set_pressure((mouse_get_button_state() & MOUSE_BUTTON_MASK_LEFT) ? 1.0f : 0.0f); } mm->set_tilt(xi.tilt); @@ -3618,6 +3641,22 @@ void DisplayServerX11::set_icon(const Ref<Image> &p_icon) { XSetErrorHandler(oldHandler); } +void DisplayServerX11::window_set_vsync_mode(DisplayServer::VSyncMode p_vsync_mode, WindowID p_window) { + _THREAD_SAFE_METHOD_ +#if defined(VULKAN_ENABLED) + context_vulkan->set_vsync_mode(p_window, p_vsync_mode); +#endif +} + +DisplayServer::VSyncMode DisplayServerX11::window_get_vsync_mode(WindowID p_window) const { + _THREAD_SAFE_METHOD_ +#if defined(VULKAN_ENABLED) + return context_vulkan->get_vsync_mode(p_window); +#else + return DisplayServer::VSYNC_ENABLED; +#endif +} + Vector<String> DisplayServerX11::get_rendering_drivers_func() { Vector<String> drivers; @@ -3631,8 +3670,8 @@ Vector<String> DisplayServerX11::get_rendering_drivers_func() { return drivers; } -DisplayServer *DisplayServerX11::create_func(const String &p_rendering_driver, WindowMode p_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error) { - DisplayServer *ds = memnew(DisplayServerX11(p_rendering_driver, p_mode, p_flags, p_resolution, r_error)); +DisplayServer *DisplayServerX11::create_func(const String &p_rendering_driver, WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error) { + DisplayServer *ds = memnew(DisplayServerX11(p_rendering_driver, p_mode, p_vsync_mode, p_flags, p_resolution, r_error)); if (r_error != OK) { ds->alert("Your video card driver does not support any of the supported Vulkan versions.\n" "Please update your drivers or if you have a very old or integrated GPU upgrade it.", @@ -3641,7 +3680,7 @@ DisplayServer *DisplayServerX11::create_func(const String &p_rendering_driver, W return ds; } -DisplayServerX11::WindowID DisplayServerX11::_create_window(WindowMode p_mode, uint32_t p_flags, const Rect2i &p_rect) { +DisplayServerX11::WindowID DisplayServerX11::_create_window(WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Rect2i &p_rect) { //Create window long visualMask = VisualScreenMask; @@ -3805,7 +3844,7 @@ DisplayServerX11::WindowID DisplayServerX11::_create_window(WindowMode p_mode, u #if defined(VULKAN_ENABLED) if (context_vulkan) { - Error err = context_vulkan->window_create(id, wd.x11_window, x11_display, p_rect.size.width, p_rect.size.height); + Error err = context_vulkan->window_create(id, p_vsync_mode, wd.x11_window, x11_display, p_rect.size.width, p_rect.size.height); ERR_FAIL_COND_V_MSG(err != OK, INVALID_WINDOW_ID, "Can't create a Vulkan window"); } #endif @@ -3842,7 +3881,7 @@ DisplayServerX11::WindowID DisplayServerX11::_create_window(WindowMode p_mode, u return id; } -DisplayServerX11::DisplayServerX11(const String &p_rendering_driver, WindowMode p_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error) { +DisplayServerX11::DisplayServerX11(const String &p_rendering_driver, WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error) { Input::get_singleton()->set_event_dispatch_function(_dispatch_input_events); r_error = OK; @@ -3855,8 +3894,6 @@ DisplayServerX11::DisplayServerX11(const String &p_rendering_driver, WindowMode img[i] = nullptr; } - last_button_state = 0; - xmbstring = nullptr; last_click_ms = 0; @@ -4080,7 +4117,7 @@ DisplayServerX11::DisplayServerX11(const String &p_rendering_driver, WindowMode Point2i window_position( (screen_get_size(0).width - p_resolution.width) / 2, (screen_get_size(0).height - p_resolution.height) / 2); - WindowID main_window = _create_window(p_mode, p_flags, Rect2i(window_position, p_resolution)); + WindowID main_window = _create_window(p_mode, p_vsync_mode, p_flags, Rect2i(window_position, p_resolution)); if (main_window == INVALID_WINDOW_ID) { r_error = ERR_CANT_CREATE; return; @@ -4272,6 +4309,11 @@ DisplayServerX11::DisplayServerX11(const String &p_rendering_driver, WindowMode _update_real_mouse_position(windows[MAIN_WINDOW_ID]); +#ifdef DBUS_ENABLED + screensaver = memnew(FreeDesktopScreenSaver); + screen_set_keep_on(GLOBAL_DEF("display/window/energy_saving/keep_screen_on", true)); +#endif + r_error = OK; } @@ -4336,6 +4378,10 @@ DisplayServerX11::~DisplayServerX11() { if (xmbstring) { memfree(xmbstring); } + +#ifdef DBUS_ENABLED + memdelete(screensaver); +#endif } void DisplayServerX11::register_x11_driver() { diff --git a/platform/linuxbsd/display_server_x11.h b/platform/linuxbsd/display_server_x11.h index 10686d8424..c5cf5ee4cb 100644 --- a/platform/linuxbsd/display_server_x11.h +++ b/platform/linuxbsd/display_server_x11.h @@ -55,6 +55,10 @@ #include "platform/linuxbsd/vulkan_context_x11.h" #endif +#if defined(DBUS_ENABLED) +#include "freedesktop_screensaver.h" +#endif + #include <X11/Xcursor/Xcursor.h> #include <X11/Xlib.h> #include <X11/extensions/XInput2.h> @@ -103,6 +107,11 @@ class DisplayServerX11 : public DisplayServer { RenderingDeviceVulkan *rendering_device_vulkan; #endif +#if defined(DBUS_ENABLED) + FreeDesktopScreenSaver *screensaver; + bool keep_screen_on = false; +#endif + struct WindowData { Window x11_window; ::XIC xic; @@ -143,7 +152,7 @@ class DisplayServerX11 : public DisplayServer { Map<WindowID, WindowData> windows; WindowID window_id_counter = MAIN_WINDOW_ID; - WindowID _create_window(WindowMode p_mode, uint32_t p_flags, const Rect2i &p_rect); + WindowID _create_window(WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Rect2i &p_rect); String internal_clipboard; Window xdnd_source_window; @@ -162,7 +171,7 @@ class DisplayServerX11 : public DisplayServer { Point2i last_click_pos; uint64_t last_click_ms; int last_click_button_index; - uint32_t last_button_state; + MouseButton last_button_state = MOUSE_BUTTON_NONE; bool app_focused = false; uint64_t time_since_no_focus = 0; @@ -187,7 +196,7 @@ class DisplayServerX11 : public DisplayServer { bool _refresh_device_info(); - unsigned int _get_mouse_button_state(unsigned int p_x11_button, int p_x11_type); + MouseButton _get_mouse_button_state(MouseButton p_x11_button, int p_x11_type); void _get_key_modifier_state(unsigned int p_x11_state, Ref<InputEventWithModifiers> state); void _flush_mouse_motion(); @@ -279,7 +288,7 @@ public: virtual void mouse_warp_to_position(const Point2i &p_to); virtual Point2i mouse_get_position() const; virtual Point2i mouse_get_absolute_position() const; - virtual int mouse_get_button_state() const; + virtual MouseButton mouse_get_button_state() const; virtual void clipboard_set(const String &p_text); virtual String clipboard_get() const; @@ -291,9 +300,14 @@ public: virtual int screen_get_dpi(int p_screen = SCREEN_OF_MAIN_WINDOW) const; virtual bool screen_is_touchscreen(int p_screen = SCREEN_OF_MAIN_WINDOW) const; +#if defined(DBUS_ENABLED) + virtual void screen_set_keep_on(bool p_enable); + virtual bool screen_is_kept_on() const; +#endif + virtual Vector<DisplayServer::WindowID> get_window_list() const; - virtual WindowID create_sub_window(WindowMode p_mode, uint32_t p_flags, const Rect2i &p_rect = Rect2i()); + virtual WindowID create_sub_window(WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Rect2i &p_rect = Rect2i()); virtual void show_window(WindowID p_id); virtual void delete_sub_window(WindowID p_id); @@ -348,6 +362,9 @@ public: virtual void window_set_ime_active(const bool p_active, WindowID p_window = MAIN_WINDOW_ID); virtual void window_set_ime_position(const Point2i &p_pos, WindowID p_window = MAIN_WINDOW_ID); + virtual void window_set_vsync_mode(DisplayServer::VSyncMode p_vsync_mode, WindowID p_window = MAIN_WINDOW_ID) override; + virtual DisplayServer::VSyncMode window_get_vsync_mode(WindowID p_vsync_mode) const override; + virtual void cursor_set_shape(CursorShape p_shape); virtual CursorShape cursor_get_shape() const; virtual void cursor_set_custom_image(const RES &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot); @@ -369,12 +386,12 @@ public: virtual void set_native_icon(const String &p_filename); virtual void set_icon(const Ref<Image> &p_icon); - static DisplayServer *create_func(const String &p_rendering_driver, WindowMode p_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error); + static DisplayServer *create_func(const String &p_rendering_driver, WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error); static Vector<String> get_rendering_drivers_func(); static void register_x11_driver(); - DisplayServerX11(const String &p_rendering_driver, WindowMode p_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error); + DisplayServerX11(const String &p_rendering_driver, WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error); ~DisplayServerX11(); }; diff --git a/platform/linuxbsd/export/export.cpp b/platform/linuxbsd/export/export.cpp index 3ee088dd35..5c6be2d7d4 100644 --- a/platform/linuxbsd/export/export.cpp +++ b/platform/linuxbsd/export/export.cpp @@ -39,11 +39,11 @@ static Error fixup_embedded_pck(const String &p_path, int64_t p_embedded_start, void register_linuxbsd_exporter() { Ref<EditorExportPlatformPC> platform; - platform.instance(); + platform.instantiate(); Ref<Image> img = memnew(Image(_linuxbsd_logo)); Ref<ImageTexture> logo; - logo.instance(); + logo.instantiate(); logo->create_from_image(img); platform->set_logo(logo); platform->set_name("Linux/X11"); diff --git a/platform/linuxbsd/freedesktop_screensaver.cpp b/platform/linuxbsd/freedesktop_screensaver.cpp new file mode 100644 index 0000000000..a6a3b27d76 --- /dev/null +++ b/platform/linuxbsd/freedesktop_screensaver.cpp @@ -0,0 +1,125 @@ +/*************************************************************************/ +/* freedesktop_screensaver.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "freedesktop_screensaver.h" + +#ifdef DBUS_ENABLED + +#include "core/config/project_settings.h" + +#include <dbus/dbus.h> + +#define BUS_OBJECT_NAME "org.freedesktop.ScreenSaver" +#define BUS_OBJECT_PATH "/org/freedesktop/ScreenSaver" +#define BUS_INTERFACE "org.freedesktop.ScreenSaver" + +void FreeDesktopScreenSaver::inhibit() { + if (unsupported) { + return; + } + + DBusError error; + dbus_error_init(&error); + + DBusConnection *bus = dbus_bus_get(DBUS_BUS_SESSION, &error); + if (dbus_error_is_set(&error)) { + unsupported = true; + return; + } + + String app_name_string = ProjectSettings::get_singleton()->get("application/config/name"); + CharString app_name_utf8 = app_name_string.utf8(); + const char *app_name = app_name_string.is_empty() ? "Godot Engine" : app_name_utf8.get_data(); + + const char *reason = "Running Godot Engine project"; + + DBusMessage *message = dbus_message_new_method_call( + BUS_OBJECT_NAME, BUS_OBJECT_PATH, BUS_INTERFACE, + "Inhibit"); + dbus_message_append_args( + message, + DBUS_TYPE_STRING, &app_name, + DBUS_TYPE_STRING, &reason, + DBUS_TYPE_INVALID); + + DBusMessage *reply = dbus_connection_send_with_reply_and_block(bus, message, 50, &error); + dbus_message_unref(message); + if (dbus_error_is_set(&error)) { + dbus_connection_unref(bus); + unsupported = false; + return; + } + + DBusMessageIter reply_iter; + dbus_message_iter_init(reply, &reply_iter); + dbus_message_iter_get_basic(&reply_iter, &cookie); + print_verbose("FreeDesktopScreenSaver: Acquired screensaver inhibition cookie: " + uitos(cookie)); + + dbus_message_unref(reply); + dbus_connection_unref(bus); +} + +void FreeDesktopScreenSaver::uninhibit() { + if (unsupported) { + return; + } + + DBusError error; + dbus_error_init(&error); + + DBusConnection *bus = dbus_bus_get(DBUS_BUS_SESSION, &error); + if (dbus_error_is_set(&error)) { + unsupported = true; + return; + } + + DBusMessage *message = dbus_message_new_method_call( + BUS_OBJECT_NAME, BUS_OBJECT_PATH, BUS_INTERFACE, + "UnInhibit"); + dbus_message_append_args( + message, + DBUS_TYPE_UINT32, &cookie, + DBUS_TYPE_INVALID); + + DBusMessage *reply = dbus_connection_send_with_reply_and_block(bus, message, 50, &error); + if (dbus_error_is_set(&error)) { + dbus_connection_unref(bus); + unsupported = true; + return; + } + + print_verbose("FreeDesktopScreenSaver: Released screensaver inhibition cookie: " + uitos(cookie)); + + dbus_message_unref(message); + dbus_message_unref(reply); + dbus_connection_unref(bus); +} + +#endif // DBUS_ENABLED diff --git a/platform/linuxbsd/freedesktop_screensaver.h b/platform/linuxbsd/freedesktop_screensaver.h new file mode 100644 index 0000000000..f27e60fce4 --- /dev/null +++ b/platform/linuxbsd/freedesktop_screensaver.h @@ -0,0 +1,47 @@ +/*************************************************************************/ +/* freedesktop_screensaver.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifdef DBUS_ENABLED + +#include <dbus/dbus.h> +#include <stdint.h> + +class FreeDesktopScreenSaver { +private: + uint32_t cookie = 0; + bool unsupported = false; + +public: + FreeDesktopScreenSaver() {} + void inhibit(); + void uninhibit(); +}; + +#endif // DBUS_ENABLED diff --git a/platform/linuxbsd/joypad_linux.cpp b/platform/linuxbsd/joypad_linux.cpp index e8f4352dff..8b6dbc4c20 100644 --- a/platform/linuxbsd/joypad_linux.cpp +++ b/platform/linuxbsd/joypad_linux.cpp @@ -475,7 +475,7 @@ void JoypadLinux::process_joypads() { switch (ev.type) { case EV_KEY: - input->joy_button(i, joy->key_map[ev.code], ev.value); + input->joy_button(i, (JoyButton)joy->key_map[ev.code], ev.value); break; case EV_ABS: @@ -484,29 +484,29 @@ void JoypadLinux::process_joypads() { case ABS_HAT0X: if (ev.value != 0) { if (ev.value < 0) { - joy->dpad = (joy->dpad | Input::HAT_MASK_LEFT) & ~Input::HAT_MASK_RIGHT; + joy->dpad = (HatMask)((joy->dpad | HatMask::HAT_MASK_LEFT) & ~HatMask::HAT_MASK_RIGHT); } else { - joy->dpad = (joy->dpad | Input::HAT_MASK_RIGHT) & ~Input::HAT_MASK_LEFT; + joy->dpad = (HatMask)((joy->dpad | HatMask::HAT_MASK_RIGHT) & ~HatMask::HAT_MASK_LEFT); } } else { - joy->dpad &= ~(Input::HAT_MASK_LEFT | Input::HAT_MASK_RIGHT); + joy->dpad &= ~(HatMask::HAT_MASK_LEFT | HatMask::HAT_MASK_RIGHT); } - input->joy_hat(i, joy->dpad); + input->joy_hat(i, (HatMask)joy->dpad); break; case ABS_HAT0Y: if (ev.value != 0) { if (ev.value < 0) { - joy->dpad = (joy->dpad | Input::HAT_MASK_UP) & ~Input::HAT_MASK_DOWN; + joy->dpad = (HatMask)((joy->dpad | HatMask::HAT_MASK_UP) & ~HatMask::HAT_MASK_DOWN); } else { - joy->dpad = (joy->dpad | Input::HAT_MASK_DOWN) & ~Input::HAT_MASK_UP; + joy->dpad = (HatMask)((joy->dpad | HatMask::HAT_MASK_DOWN) & ~HatMask::HAT_MASK_UP); } } else { - joy->dpad &= ~(Input::HAT_MASK_UP | Input::HAT_MASK_DOWN); + joy->dpad &= ~(HatMask::HAT_MASK_UP | HatMask::HAT_MASK_DOWN); } - input->joy_hat(i, joy->dpad); + input->joy_hat(i, (HatMask)joy->dpad); break; default: @@ -526,7 +526,7 @@ void JoypadLinux::process_joypads() { for (int j = 0; j < MAX_ABS; j++) { int index = joy->abs_map[j]; if (index != -1) { - input->joy_axis(i, index, joy->curr_axis[index]); + input->joy_axis(i, (JoyAxis)index, joy->curr_axis[index]); } } if (len == 0 || (len < 0 && errno != EAGAIN)) { diff --git a/platform/linuxbsd/vulkan_context_x11.cpp b/platform/linuxbsd/vulkan_context_x11.cpp index 021db630e0..88cb00a8a1 100644 --- a/platform/linuxbsd/vulkan_context_x11.cpp +++ b/platform/linuxbsd/vulkan_context_x11.cpp @@ -35,7 +35,7 @@ const char *VulkanContextX11::_get_platform_surface_extension() const { return VK_KHR_XLIB_SURFACE_EXTENSION_NAME; } -Error VulkanContextX11::window_create(DisplayServer::WindowID p_window_id, ::Window p_window, Display *p_display, int p_width, int p_height) { +Error VulkanContextX11::window_create(DisplayServer::WindowID p_window_id, DisplayServer::VSyncMode p_vsync_mode, ::Window p_window, Display *p_display, int p_width, int p_height) { VkXlibSurfaceCreateInfoKHR createInfo; createInfo.sType = VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR; createInfo.pNext = nullptr; @@ -46,7 +46,7 @@ Error VulkanContextX11::window_create(DisplayServer::WindowID p_window_id, ::Win VkSurfaceKHR surface; VkResult err = vkCreateXlibSurfaceKHR(_get_instance(), &createInfo, nullptr, &surface); ERR_FAIL_COND_V(err, ERR_CANT_CREATE); - return _window_create(p_window_id, surface, p_width, p_height); + return _window_create(p_window_id, p_vsync_mode, surface, p_width, p_height); } VulkanContextX11::VulkanContextX11() { diff --git a/platform/linuxbsd/vulkan_context_x11.h b/platform/linuxbsd/vulkan_context_x11.h index 26472444ad..de4a9c7b90 100644 --- a/platform/linuxbsd/vulkan_context_x11.h +++ b/platform/linuxbsd/vulkan_context_x11.h @@ -38,7 +38,7 @@ class VulkanContextX11 : public VulkanContext { virtual const char *_get_platform_surface_extension() const; public: - Error window_create(DisplayServer::WindowID p_window_id, ::Window p_window, Display *p_display, int p_width, int p_height); + Error window_create(DisplayServer::WindowID p_window_id, DisplayServer::VSyncMode p_vsync_mode, ::Window p_window, Display *p_display, int p_width, int p_height); VulkanContextX11(); ~VulkanContextX11(); diff --git a/platform/osx/display_server_osx.h b/platform/osx/display_server_osx.h index 9fac99810b..c7b9e411b8 100644 --- a/platform/osx/display_server_osx.h +++ b/platform/osx/display_server_osx.h @@ -145,7 +145,7 @@ public: WindowID window_id_counter = MAIN_WINDOW_ID; - WindowID _create_window(WindowMode p_mode, const Rect2i &p_rect); + WindowID _create_window(WindowMode p_mode, VSyncMode p_vsync_mode, const Rect2i &p_rect); void _update_window(WindowData p_wd); void _send_window_event(const WindowData &wd, WindowEvent p_event); static void _dispatch_input_events(const Ref<InputEvent> &p_event); @@ -173,7 +173,7 @@ public: MouseMode mouse_mode; Point2i last_mouse_pos; - uint32_t last_button_state; + MouseButton last_button_state = MOUSE_BUTTON_NONE; bool window_focused; bool drop_events; @@ -217,7 +217,7 @@ public: virtual void mouse_warp_to_position(const Point2i &p_to) override; virtual Point2i mouse_get_position() const override; virtual Point2i mouse_get_absolute_position() const override; - virtual int mouse_get_button_state() const override; + virtual MouseButton mouse_get_button_state() const override; virtual void clipboard_set(const String &p_text) override; virtual String clipboard_get() const override; @@ -232,7 +232,7 @@ public: virtual Vector<int> get_window_list() const override; - virtual WindowID create_sub_window(WindowMode p_mode, uint32_t p_flags, const Rect2i &p_rect = Rect2i()) override; + virtual WindowID create_sub_window(WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Rect2i &p_rect = Rect2i()) override; virtual void show_window(WindowID p_id) override; virtual void delete_sub_window(WindowID p_id) override; @@ -286,6 +286,9 @@ public: virtual void window_attach_instance_id(ObjectID p_instance, WindowID p_window = MAIN_WINDOW_ID) override; virtual ObjectID window_get_attached_instance_id(WindowID p_window = MAIN_WINDOW_ID) const override; + virtual void window_set_vsync_mode(DisplayServer::VSyncMode p_vsync_mode, WindowID p_window = MAIN_WINDOW_ID) override; + virtual DisplayServer::VSyncMode window_get_vsync_mode(WindowID p_vsync_mode) const override; + virtual Point2i ime_get_selection() const override; virtual String ime_get_text() const override; @@ -314,12 +317,12 @@ public: virtual void console_set_visible(bool p_enabled) override; virtual bool is_console_visible() const override; - static DisplayServer *create_func(const String &p_rendering_driver, WindowMode p_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error); + static DisplayServer *create_func(const String &p_rendering_driver, WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error); static Vector<String> get_rendering_drivers_func(); static void register_osx_driver(); - DisplayServerOSX(const String &p_rendering_driver, WindowMode p_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error); + DisplayServerOSX(const String &p_rendering_driver, WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error); ~DisplayServerOSX(); }; diff --git a/platform/osx/display_server_osx.mm b/platform/osx/display_server_osx.mm index 408feb4db9..dec6da42fe 100644 --- a/platform/osx/display_server_osx.mm +++ b/platform/osx/display_server_osx.mm @@ -119,7 +119,7 @@ static NSCursor *_cursorFromSelector(SEL selector, SEL fallback = nil) { if ([event type] == NSEventTypeKeyDown) { if (([event modifierFlags] & NSEventModifierFlagCommand) && [event keyCode] == 0x2f) { Ref<InputEventKey> k; - k.instance(); + k.instantiate(); _get_key_modifier_state([event modifierFlags], k); k->set_window_id(DisplayServerOSX::INVALID_WINDOW_ID); @@ -813,18 +813,18 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; DS_OSX->cursor_set_shape(p_shape); } -static void _mouseDownEvent(DisplayServer::WindowID window_id, NSEvent *event, int index, int mask, bool pressed) { +static void _mouseDownEvent(DisplayServer::WindowID window_id, NSEvent *event, MouseButton index, MouseButton mask, bool pressed) { ERR_FAIL_COND(!DS_OSX->windows.has(window_id)); DisplayServerOSX::WindowData &wd = DS_OSX->windows[window_id]; if (pressed) { DS_OSX->last_button_state |= mask; } else { - DS_OSX->last_button_state &= ~mask; + DS_OSX->last_button_state &= (MouseButton)~mask; } Ref<InputEventMouseButton> mb; - mb.instance(); + mb.instantiate(); mb->set_window_id(window_id); const Vector2 pos = _get_mouse_pos(wd, [event locationInWindow]); _get_key_modifier_state([event modifierFlags], mb); @@ -928,7 +928,7 @@ static void _mouseDownEvent(DisplayServer::WindowID window_id, NSEvent *event, i } Ref<InputEventMouseMotion> mm; - mm.instance(); + mm.instantiate(); mm->set_window_id(window_id); mm->set_button_mask(DS_OSX->last_button_state); @@ -1016,7 +1016,7 @@ static void _mouseDownEvent(DisplayServer::WindowID window_id, NSEvent *event, i DisplayServerOSX::WindowData &wd = DS_OSX->windows[window_id]; Ref<InputEventMagnifyGesture> ev; - ev.instance(); + ev.instantiate(); ev->set_window_id(window_id); _get_key_modifier_state([event modifierFlags], ev); ev->set_position(_get_mouse_pos(wd, [event locationInWindow])); @@ -1485,14 +1485,14 @@ static int remapKey(unsigned int key, unsigned int state) { } } -inline void sendScrollEvent(DisplayServer::WindowID window_id, int button, double factor, int modifierFlags) { +inline void sendScrollEvent(DisplayServer::WindowID window_id, MouseButton button, double factor, int modifierFlags) { ERR_FAIL_COND(!DS_OSX->windows.has(window_id)); DisplayServerOSX::WindowData &wd = DS_OSX->windows[window_id]; - unsigned int mask = 1 << (button - 1); + MouseButton mask = MouseButton(1 << (button - 1)); Ref<InputEventMouseButton> sc; - sc.instance(); + sc.instantiate(); sc->set_window_id(window_id); _get_key_modifier_state(modifierFlags, sc); @@ -1501,19 +1501,19 @@ inline void sendScrollEvent(DisplayServer::WindowID window_id, int button, doubl sc->set_pressed(true); sc->set_position(wd.mouse_pos); sc->set_global_position(wd.mouse_pos); - DS_OSX->last_button_state |= mask; + DS_OSX->last_button_state |= (MouseButton)mask; sc->set_button_mask(DS_OSX->last_button_state); Input::get_singleton()->accumulate_input_event(sc); - sc.instance(); + sc.instantiate(); sc->set_window_id(window_id); sc->set_button_index(button); sc->set_factor(factor); sc->set_pressed(false); sc->set_position(wd.mouse_pos); sc->set_global_position(wd.mouse_pos); - DS_OSX->last_button_state &= ~mask; + DS_OSX->last_button_state &= (MouseButton)~mask; sc->set_button_mask(DS_OSX->last_button_state); Input::get_singleton()->accumulate_input_event(sc); @@ -1524,7 +1524,7 @@ inline void sendPanEvent(DisplayServer::WindowID window_id, double dx, double dy DisplayServerOSX::WindowData &wd = DS_OSX->windows[window_id]; Ref<InputEventPanGesture> pg; - pg.instance(); + pg.instantiate(); pg->set_window_id(window_id); _get_key_modifier_state(modifierFlags, pg); @@ -2120,6 +2120,12 @@ void DisplayServerOSX::mouse_set_mode(MouseMode p_mode) { ignore_warp = true; warp_events.clear(); mouse_mode = p_mode; + + if (mouse_mode == MOUSE_MODE_VISIBLE || mouse_mode == MOUSE_MODE_CONFINED) { + CursorShape p_shape = cursor_shape; + cursor_shape = DisplayServer::CURSOR_MAX; + cursor_set_shape(p_shape); + } } DisplayServer::MouseMode DisplayServerOSX::mouse_get_mode() const { @@ -2173,7 +2179,7 @@ Point2i DisplayServerOSX::mouse_get_absolute_position() const { return Vector2i(); } -int DisplayServerOSX::mouse_get_button_state() const { +MouseButton DisplayServerOSX::mouse_get_button_state() const { return last_button_state; } @@ -2382,10 +2388,10 @@ Vector<DisplayServer::WindowID> DisplayServerOSX::get_window_list() const { return ret; } -DisplayServer::WindowID DisplayServerOSX::create_sub_window(WindowMode p_mode, uint32_t p_flags, const Rect2i &p_rect) { +DisplayServer::WindowID DisplayServerOSX::create_sub_window(WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Rect2i &p_rect) { _THREAD_SAFE_METHOD_ - WindowID id = _create_window(p_mode, p_rect); + WindowID id = _create_window(p_mode, p_vsync_mode, p_rect); for (int i = 0; i < WINDOW_FLAG_MAX; i++) { if (p_flags & (1 << i)) { window_set_flag(WindowFlags(i), true, id); @@ -3375,7 +3381,7 @@ void DisplayServerOSX::_process_key_events() { const KeyEvent &ke = key_event_buffer[i]; if (ke.raw) { // Non IME input - no composite characters, pass events as is - k.instance(); + k.instantiate(); k->set_window_id(ke.window_id); _get_key_modifier_state(ke.osx_state, k); @@ -3389,7 +3395,7 @@ void DisplayServerOSX::_process_key_events() { } else { // IME input if ((i == 0 && ke.keycode == 0) || (i > 0 && key_event_buffer[i - 1].keycode == 0)) { - k.instance(); + k.instantiate(); k->set_window_id(ke.window_id); _get_key_modifier_state(ke.osx_state, k); @@ -3402,7 +3408,7 @@ void DisplayServerOSX::_process_key_events() { _push_input(k); } if (ke.keycode != 0) { - k.instance(); + k.instantiate(); k->set_window_id(ke.window_id); _get_key_modifier_state(ke.osx_state, k); @@ -3540,6 +3546,22 @@ void DisplayServerOSX::set_icon(const Ref<Image> &p_icon) { [nsimg release]; } +void DisplayServerOSX::window_set_vsync_mode(DisplayServer::VSyncMode p_vsync_mode, WindowID p_window) { + _THREAD_SAFE_METHOD_ +#if defined(VULKAN_ENABLED) + context_vulkan->set_vsync_mode(p_window, p_vsync_mode); +#endif +} + +DisplayServer::VSyncMode DisplayServerOSX::window_get_vsync_mode(WindowID p_window) const { + _THREAD_SAFE_METHOD_ +#if defined(VULKAN_ENABLED) + return context_vulkan->get_vsync_mode(p_window); +#else + return DisplayServer::VSYNC_ENABLED; +#endif +} + Vector<String> DisplayServerOSX::get_rendering_drivers_func() { Vector<String> drivers; @@ -3590,15 +3612,15 @@ ObjectID DisplayServerOSX::window_get_attached_instance_id(WindowID p_window) co return windows[p_window].instance_id; } -DisplayServer *DisplayServerOSX::create_func(const String &p_rendering_driver, WindowMode p_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error) { - DisplayServer *ds = memnew(DisplayServerOSX(p_rendering_driver, p_mode, p_flags, p_resolution, r_error)); +DisplayServer *DisplayServerOSX::create_func(const String &p_rendering_driver, WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error) { + DisplayServer *ds = memnew(DisplayServerOSX(p_rendering_driver, p_mode, p_vsync_mode, p_flags, p_resolution, r_error)); if (r_error != OK) { ds->alert("Your video card driver does not support any of the supported Metal versions.", "Unable to initialize Video driver"); } return ds; } -DisplayServerOSX::WindowID DisplayServerOSX::_create_window(WindowMode p_mode, const Rect2i &p_rect) { +DisplayServerOSX::WindowID DisplayServerOSX::_create_window(WindowMode p_mode, VSyncMode p_vsync_mode, const Rect2i &p_rect) { WindowID id; const float scale = screen_get_max_scale(); { @@ -3645,7 +3667,7 @@ DisplayServerOSX::WindowID DisplayServerOSX::_create_window(WindowMode p_mode, c #if defined(VULKAN_ENABLED) if (rendering_driver == "vulkan") { if (context_vulkan) { - Error err = context_vulkan->window_create(window_id_counter, wd.window_view, p_rect.size.width, p_rect.size.height); + Error err = context_vulkan->window_create(window_id_counter, p_vsync_mode, wd.window_view, p_rect.size.width, p_rect.size.height); ERR_FAIL_COND_V_MSG(err != OK, INVALID_WINDOW_ID, "Can't create a Vulkan context"); } } @@ -3744,7 +3766,7 @@ bool DisplayServerOSX::is_console_visible() const { return isatty(STDIN_FILENO); } -DisplayServerOSX::DisplayServerOSX(const String &p_rendering_driver, WindowMode p_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error) { +DisplayServerOSX::DisplayServerOSX(const String &p_rendering_driver, WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error) { Input::get_singleton()->set_event_dispatch_function(_dispatch_input_events); r_error = OK; @@ -3755,7 +3777,6 @@ DisplayServerOSX::DisplayServerOSX(const String &p_rendering_driver, WindowMode key_event_pos = 0; mouse_mode = MOUSE_MODE_VISIBLE; - last_button_state = 0; autoreleasePool = [[NSAutoreleasePool alloc] init]; @@ -3881,7 +3902,7 @@ DisplayServerOSX::DisplayServerOSX(const String &p_rendering_driver, WindowMode Point2i window_position( screen_get_position(0).x + (screen_get_size(0).width - p_resolution.width) / 2, screen_get_position(0).y + (screen_get_size(0).height - p_resolution.height) / 2); - WindowID main_window = _create_window(p_mode, Rect2i(window_position, p_resolution)); + WindowID main_window = _create_window(p_mode, p_vsync_mode, Rect2i(window_position, p_resolution)); ERR_FAIL_COND(main_window == INVALID_WINDOW_ID); for (int i = 0; i < WINDOW_FLAG_MAX; i++) { if (p_flags & (1 << i)) { diff --git a/platform/osx/export/export.cpp b/platform/osx/export/export.cpp index f52853ca9e..ea34b8a24e 100644 --- a/platform/osx/export/export.cpp +++ b/platform/osx/export/export.cpp @@ -163,9 +163,13 @@ void EditorExportPlatformOSX::get_export_options(List<ExportOption> *r_options) r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/replace_existing_signature"), true)); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/entitlements/custom_file", PROPERTY_HINT_GLOBAL_FILE, "*.plist"), "")); - r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/allow_jit_code_execution"), false)); - r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/allow_unsigned_executable_memory"), false)); - r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/allow_dyld_environment_variables"), false)); + if (!Engine::get_singleton()->has_singleton("GodotSharp")) { + // These entitlements are required to run managed code, and are always enabled in Mono builds. + r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/allow_jit_code_execution"), false)); + r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/allow_unsigned_executable_memory"), false)); + r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/allow_dyld_environment_variables"), false)); + } + r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/disable_library_validation"), false)); r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/audio_input"), false)); r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/camera"), false)); @@ -700,7 +704,7 @@ Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_p } } else { Ref<Image> icon; - icon.instance(); + icon.instantiate(); icon->load(iconpath); if (!icon->is_empty()) { _make_icon(icon, data); @@ -786,18 +790,29 @@ Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_p ent_f->store_line("<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">"); ent_f->store_line("<plist version=\"1.0\">"); ent_f->store_line("<dict>"); - if ((bool)p_preset->get("codesign/entitlements/allow_jit_code_execution")) { + if (Engine::get_singleton()->has_singleton("GodotSharp")) { + // These entitlements are required to run managed code, and are always enabled in Mono builds. ent_f->store_line("<key>com.apple.security.cs.allow-jit</key>"); ent_f->store_line("<true/>"); - } - if ((bool)p_preset->get("codesign/entitlements/allow_unsigned_executable_memory")) { ent_f->store_line("<key>com.apple.security.cs.allow-unsigned-executable-memory</key>"); ent_f->store_line("<true/>"); - } - if ((bool)p_preset->get("codesign/entitlements/allow_dyld_environment_variables")) { ent_f->store_line("<key>com.apple.security.cs.allow-dyld-environment-variables</key>"); ent_f->store_line("<true/>"); + } else { + if ((bool)p_preset->get("codesign/entitlements/allow_jit_code_execution")) { + ent_f->store_line("<key>com.apple.security.cs.allow-jit</key>"); + ent_f->store_line("<true/>"); + } + if ((bool)p_preset->get("codesign/entitlements/allow_unsigned_executable_memory")) { + ent_f->store_line("<key>com.apple.security.cs.allow-unsigned-executable-memory</key>"); + ent_f->store_line("<true/>"); + } + if ((bool)p_preset->get("codesign/entitlements/allow_dyld_environment_variables")) { + ent_f->store_line("<key>com.apple.security.cs.allow-dyld-environment-variables</key>"); + ent_f->store_line("<true/>"); + } } + if ((bool)p_preset->get("codesign/entitlements/disable_library_validation")) { ent_f->store_line("<key>com.apple.security.cs.disable-library-validation</key>"); ent_f->store_line("<true/>"); @@ -1151,7 +1166,7 @@ bool EditorExportPlatformOSX::can_export(const Ref<EditorExportPreset> &p_preset EditorExportPlatformOSX::EditorExportPlatformOSX() { Ref<Image> img = memnew(Image(_osx_logo)); - logo.instance(); + logo.instantiate(); logo->create_from_image(img); } @@ -1160,7 +1175,7 @@ EditorExportPlatformOSX::~EditorExportPlatformOSX() { void register_osx_exporter() { Ref<EditorExportPlatformOSX> platform; - platform.instance(); + platform.instantiate(); EditorExport::get_singleton()->add_export_platform(platform); } diff --git a/platform/osx/joypad_osx.cpp b/platform/osx/joypad_osx.cpp index b12526915f..126ebc1908 100644 --- a/platform/osx/joypad_osx.cpp +++ b/platform/osx/joypad_osx.cpp @@ -390,38 +390,38 @@ bool joypad::check_ff_features() { static int process_hat_value(int p_min, int p_max, int p_value) { int range = (p_max - p_min + 1); int value = p_value - p_min; - int hat_value = Input::HAT_MASK_CENTER; + int hat_value = HatMask::HAT_MASK_CENTER; if (range == 4) { value *= 2; } switch (value) { case 0: - hat_value = Input::HAT_MASK_UP; + hat_value = (HatMask)HatMask::HAT_MASK_UP; break; case 1: - hat_value = Input::HAT_MASK_UP | Input::HAT_MASK_RIGHT; + hat_value = (HatMask)(HatMask::HAT_MASK_UP | HatMask::HAT_MASK_RIGHT); break; case 2: - hat_value = Input::HAT_MASK_RIGHT; + hat_value = (HatMask)HatMask::HAT_MASK_RIGHT; break; case 3: - hat_value = Input::HAT_MASK_DOWN | Input::HAT_MASK_RIGHT; + hat_value = (HatMask)(HatMask::HAT_MASK_DOWN | HatMask::HAT_MASK_RIGHT); break; case 4: - hat_value = Input::HAT_MASK_DOWN; + hat_value = (HatMask)HatMask::HAT_MASK_DOWN; break; case 5: - hat_value = Input::HAT_MASK_DOWN | Input::HAT_MASK_LEFT; + hat_value = (HatMask)(HatMask::HAT_MASK_DOWN | HatMask::HAT_MASK_LEFT); break; case 6: - hat_value = Input::HAT_MASK_LEFT; + hat_value = (HatMask)HatMask::HAT_MASK_LEFT; break; case 7: - hat_value = Input::HAT_MASK_UP | Input::HAT_MASK_LEFT; + hat_value = (HatMask)(HatMask::HAT_MASK_UP | HatMask::HAT_MASK_LEFT); break; default: - hat_value = Input::HAT_MASK_CENTER; + hat_value = (HatMask)HatMask::HAT_MASK_CENTER; break; } return hat_value; @@ -458,17 +458,17 @@ void JoypadOSX::process_joypads() { for (int j = 0; j < joy.axis_elements.size(); j++) { rec_element &elem = joy.axis_elements.write[j]; int value = joy.get_hid_element_state(&elem); - input->joy_axis(joy.id, j, axis_correct(value, elem.min, elem.max)); + input->joy_axis(joy.id, (JoyAxis)j, axis_correct(value, elem.min, elem.max)); } for (int j = 0; j < joy.button_elements.size(); j++) { int value = joy.get_hid_element_state(&joy.button_elements.write[j]); - input->joy_button(joy.id, j, (value >= 1)); + input->joy_button(joy.id, (JoyButton)j, (value >= 1)); } for (int j = 0; j < joy.hat_elements.size(); j++) { rec_element &elem = joy.hat_elements.write[j]; int value = joy.get_hid_element_state(&elem); int hat_value = process_hat_value(elem.min, elem.max, value); - input->joy_hat(joy.id, hat_value); + input->joy_hat(joy.id, (HatMask)hat_value); } if (joy.ffservice) { diff --git a/platform/osx/vulkan_context_osx.h b/platform/osx/vulkan_context_osx.h index 8b6a75adfb..22d43688a3 100644 --- a/platform/osx/vulkan_context_osx.h +++ b/platform/osx/vulkan_context_osx.h @@ -38,7 +38,7 @@ class VulkanContextOSX : public VulkanContext { virtual const char *_get_platform_surface_extension() const; public: - Error window_create(DisplayServer::WindowID p_window_id, id p_window, int p_width, int p_height); + Error window_create(DisplayServer::WindowID p_window_id, DisplayServer::VSyncMode p_vsync_mode, id p_window, int p_width, int p_height); VulkanContextOSX(); ~VulkanContextOSX(); diff --git a/platform/osx/vulkan_context_osx.mm b/platform/osx/vulkan_context_osx.mm index 6b87fbd489..7e18e177c1 100644 --- a/platform/osx/vulkan_context_osx.mm +++ b/platform/osx/vulkan_context_osx.mm @@ -35,7 +35,7 @@ const char *VulkanContextOSX::_get_platform_surface_extension() const { return VK_MVK_MACOS_SURFACE_EXTENSION_NAME; } -Error VulkanContextOSX::window_create(DisplayServer::WindowID p_window_id, id p_window, int p_width, int p_height) { +Error VulkanContextOSX::window_create(DisplayServer::WindowID p_window_id, DisplayServer::VSyncMode p_vsync_mode, id p_window, int p_width, int p_height) { VkMacOSSurfaceCreateInfoMVK createInfo; createInfo.sType = VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK; createInfo.pNext = nullptr; @@ -45,7 +45,7 @@ Error VulkanContextOSX::window_create(DisplayServer::WindowID p_window_id, id p_ VkSurfaceKHR surface; VkResult err = vkCreateMacOSSurfaceMVK(_get_instance(), &createInfo, nullptr, &surface); ERR_FAIL_COND_V(err, ERR_CANT_CREATE); - return _window_create(p_window_id, surface, p_width, p_height); + return _window_create(p_window_id, p_vsync_mode, surface, p_width, p_height); } VulkanContextOSX::VulkanContextOSX() { diff --git a/platform/uwp/app.cpp b/platform/uwp/app.cpp index 67f054aeaa..1da17ffc5d 100644 --- a/platform/uwp/app.cpp +++ b/platform/uwp/app.cpp @@ -145,7 +145,7 @@ void App::SetWindow(CoreWindow ^ p_window) { Main::setup2(); } -static int _get_button(Windows::UI::Input::PointerPoint ^ pt) { +static MouseButton _get_button(Windows::UI::Input::PointerPoint ^ pt) { using namespace Windows::UI::Input; #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP @@ -177,7 +177,7 @@ static int _get_button(Windows::UI::Input::PointerPoint ^ pt) { } #endif - return 0; + return MOUSE_BUTTON_NONE; }; static bool _is_touch(Windows::UI::Input::PointerPoint ^ pointerPoint) { @@ -241,10 +241,10 @@ static int _get_finger(uint32_t p_touch_id) { void App::pointer_event(Windows::UI::Core::CoreWindow ^ sender, Windows::UI::Core::PointerEventArgs ^ args, bool p_pressed, bool p_is_wheel) { Windows::UI::Input::PointerPoint ^ point = args->CurrentPoint; Windows::Foundation::Point pos = _get_pixel_position(window, point->Position, os); - int but = _get_button(point); + MouseButton but = _get_button(point); if (_is_touch(point)) { Ref<InputEventScreenTouch> screen_touch; - screen_touch.instance(); + screen_touch.instantiate(); screen_touch->set_device(0); screen_touch->set_pressed(p_pressed); screen_touch->set_position(Vector2(pos.X, pos.Y)); @@ -256,7 +256,7 @@ void App::pointer_event(Windows::UI::Core::CoreWindow ^ sender, Windows::UI::Cor os->input_event(screen_touch); } else { Ref<InputEventMouseButton> mouse_button; - mouse_button.instance(); + mouse_button.instantiate(); mouse_button->set_device(0); mouse_button->set_pressed(p_pressed); mouse_button->set_button_index(but); @@ -324,7 +324,7 @@ void App::OnPointerMoved(Windows::UI::Core::CoreWindow ^ sender, Windows::UI::Co if (_is_touch(point)) { Ref<InputEventScreenDrag> screen_drag; - screen_drag.instance(); + screen_drag.instantiate(); screen_drag->set_device(0); screen_drag->set_position(Vector2(pos.X, pos.Y)); screen_drag->set_index(_get_finger(point->PointerId)); @@ -338,7 +338,7 @@ void App::OnPointerMoved(Windows::UI::Core::CoreWindow ^ sender, Windows::UI::Co } Ref<InputEventMouseMotion> mouse_motion; - mouse_motion.instance(); + mouse_motion.instantiate(); mouse_motion->set_device(0); mouse_motion->set_position(Vector2(pos.X, pos.Y)); mouse_motion->set_global_position(Vector2(pos.X, pos.Y)); @@ -361,7 +361,7 @@ void App::OnMouseMoved(MouseDevice ^ mouse_device, MouseEventArgs ^ args) { pos.Y = last_mouse_pos.Y + args->MouseDelta.Y; Ref<InputEventMouseMotion> mouse_motion; - mouse_motion.instance(); + mouse_motion.instantiate(); mouse_motion->set_device(0); mouse_motion->set_position(Vector2(pos.X, pos.Y)); mouse_motion->set_global_position(Vector2(pos.X, pos.Y)); diff --git a/platform/uwp/export/export.cpp b/platform/uwp/export/export.cpp index a7edc6e6e5..1075ae38ce 100644 --- a/platform/uwp/export/export.cpp +++ b/platform/uwp/export/export.cpp @@ -1429,7 +1429,7 @@ public: EditorExportPlatformUWP() { Ref<Image> img = memnew(Image(_uwp_logo)); - logo.instance(); + logo.instantiate(); logo->create_from_image(img); } }; @@ -1446,6 +1446,6 @@ void register_uwp_exporter() { #endif // WINDOWS_ENABLED Ref<EditorExportPlatformUWP> exporter; - exporter.instance(); + exporter.instantiate(); EditorExport::get_singleton()->add_export_platform(exporter); } diff --git a/platform/uwp/os_uwp.cpp b/platform/uwp/os_uwp.cpp index 65934b6681..e26e204f5f 100644 --- a/platform/uwp/os_uwp.cpp +++ b/platform/uwp/os_uwp.cpp @@ -126,8 +126,6 @@ void OS_UWP::set_keep_screen_on(bool p_enabled) { } void OS_UWP::initialize_core() { - last_button_state = 0; - //RedirectIOToConsole(); FileAccess::make_default<FileAccessWindows>(FileAccess::ACCESS_RESOURCES); @@ -423,7 +421,7 @@ Point2 OS_UWP::get_mouse_position() const { return Point2(old_x, old_y); } -int OS_UWP::get_mouse_button_state() const { +MouseButton OS_UWP::get_mouse_button_state() const { return last_button_state; } @@ -562,7 +560,7 @@ void OS_UWP::process_key_events() { KeyEvent &kev = key_event_buffer[i]; Ref<InputEventKey> key_event; - key_event.instance(); + key_event.instantiate(); key_event->set_alt_pressed(kev.alt); key_event->set_shift_pressed(kev.shift); key_event->set_ctrl_pressed(kev.control); diff --git a/platform/uwp/os_uwp.h b/platform/uwp/os_uwp.h index a4d3d6d52a..3a735889b0 100644 --- a/platform/uwp/os_uwp.h +++ b/platform/uwp/os_uwp.h @@ -106,7 +106,7 @@ private: bool control_mem; bool meta_mem; bool force_quit; - uint32_t last_button_state; + MouseButton last_button_state = MOUSE_BUTTON_NONE; CursorShape cursor_shape; @@ -173,7 +173,7 @@ public: MouseMode get_mouse_mode() const; virtual Point2 get_mouse_position() const; - virtual int get_mouse_button_state() const; + virtual MouseButton get_mouse_button_state() const; virtual void set_window_title(const String &p_title); virtual void set_video_mode(const VideoMode &p_video_mode, int p_screen = 0); diff --git a/platform/windows/context_gl_windows.cpp b/platform/windows/context_gl_windows.cpp index 7cf9738f13..74b12cbb3b 100644 --- a/platform/windows/context_gl_windows.cpp +++ b/platform/windows/context_gl_windows.cpp @@ -66,46 +66,13 @@ int ContextGL_Windows::get_window_height() { return OS::get_singleton()->get_video_mode().height; } -bool ContextGL_Windows::should_vsync_via_compositor() { - if (OS::get_singleton()->is_window_fullscreen() || !OS::get_singleton()->is_vsync_via_compositor_enabled()) { - return false; - } - - // Note: All Windows versions supported by Godot have a compositor. - // It can be disabled on earlier Windows versions. - BOOL dwm_enabled; - - if (SUCCEEDED(DwmIsCompositionEnabled(&dwm_enabled))) { - return dwm_enabled; - } - - return false; -} - void ContextGL_Windows::swap_buffers() { SwapBuffers(hDC); - - if (use_vsync) { - bool vsync_via_compositor_now = should_vsync_via_compositor(); - - if (vsync_via_compositor_now && wglGetSwapIntervalEXT() == 0) { - DwmFlush(); - } - - if (vsync_via_compositor_now != vsync_via_compositor) { - // The previous frame had a different operating mode than this - // frame. Set the 'vsync_via_compositor' member variable and the - // OpenGL swap interval to their proper values. - set_use_vsync(true); - } - } } void ContextGL_Windows::set_use_vsync(bool p_use) { - vsync_via_compositor = p_use && should_vsync_via_compositor(); - if (wglSwapIntervalEXT) { - int swap_interval = (p_use && !vsync_via_compositor) ? 1 : 0; + int swap_interval = p_use ? 1 : 0; wglSwapIntervalEXT(swap_interval); } @@ -210,7 +177,6 @@ ContextGL_Windows::ContextGL_Windows(HWND hwnd, bool p_opengl_3_context) { opengl_3_context = p_opengl_3_context; hWnd = hwnd; use_vsync = false; - vsync_via_compositor = false; pixel_format = 0; } diff --git a/platform/windows/context_gl_windows.h b/platform/windows/context_gl_windows.h index e44e2945ca..c8e8a0891d 100644 --- a/platform/windows/context_gl_windows.h +++ b/platform/windows/context_gl_windows.h @@ -50,13 +50,10 @@ class ContextGL_Windows { HWND hWnd; bool opengl_3_context; bool use_vsync; - bool vsync_via_compositor; PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT; PFNWGLGETSWAPINTERVALEXTPROC wglGetSwapIntervalEXT; - static bool should_vsync_via_compositor(); - public: void release_current(); diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp index f16595f379..4f64809abc 100644 --- a/platform/windows/display_server_windows.cpp +++ b/platform/windows/display_server_windows.cpp @@ -161,7 +161,7 @@ Point2i DisplayServerWindows::mouse_get_position() const { //return Point2(old_x, old_y); } -int DisplayServerWindows::mouse_get_button_state() const { +MouseButton DisplayServerWindows::mouse_get_button_state() const { return last_button_state; } @@ -477,10 +477,10 @@ DisplayServer::WindowID DisplayServerWindows::get_window_at_screen_position(cons return INVALID_WINDOW_ID; } -DisplayServer::WindowID DisplayServerWindows::create_sub_window(WindowMode p_mode, uint32_t p_flags, const Rect2i &p_rect) { +DisplayServer::WindowID DisplayServerWindows::create_sub_window(WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Rect2i &p_rect) { _THREAD_SAFE_METHOD_ - WindowID window_id = _create_window(p_mode, p_flags, p_rect); + WindowID window_id = _create_window(p_mode, p_vsync_mode, p_flags, p_rect); ERR_FAIL_COND_V_MSG(window_id == INVALID_WINDOW_ID, INVALID_WINDOW_ID, "Failed to create sub window."); WindowData &wd = windows[window_id]; @@ -1697,11 +1697,20 @@ void DisplayServerWindows::set_icon(const Ref<Image> &p_icon) { SendMessage(windows[MAIN_WINDOW_ID].hWnd, WM_SETICON, ICON_BIG, (LPARAM)hicon); } -void DisplayServerWindows::vsync_set_use_via_compositor(bool p_enable) { +void DisplayServerWindows::window_set_vsync_mode(DisplayServer::VSyncMode p_vsync_mode, WindowID p_window) { + _THREAD_SAFE_METHOD_ +#if defined(VULKAN_ENABLED) + context_vulkan->set_vsync_mode(p_window, p_vsync_mode); +#endif } -bool DisplayServerWindows::vsync_is_using_via_compositor() const { - return false; +DisplayServer::VSyncMode DisplayServerWindows::window_get_vsync_mode(WindowID p_window) const { + _THREAD_SAFE_METHOD_ +#if defined(VULKAN_ENABLED) + return context_vulkan->get_vsync_mode(p_window); +#else + return DisplayServer::VSYNC_ENABLED; +#endif } void DisplayServerWindows::set_context(Context p_context) { @@ -1727,7 +1736,7 @@ void DisplayServerWindows::_touch_event(WindowID p_window, bool p_pressed, float } Ref<InputEventScreenTouch> event; - event.instance(); + event.instantiate(); event->set_index(idx); event->set_window_id(p_window); event->set_pressed(p_pressed); @@ -1746,7 +1755,7 @@ void DisplayServerWindows::_drag_event(WindowID p_window, float p_x, float p_y, return; Ref<InputEventScreenDrag> event; - event.instance(); + event.instantiate(); event->set_window_id(p_window); event->set_index(idx); event->set_position(Vector2(p_x, p_y)); @@ -1965,7 +1974,7 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA if (raw->header.dwType == RIM_TYPEMOUSE) { Ref<InputEventMouseMotion> mm; - mm.instance(); + mm.instantiate(); mm->set_window_id(window_id); mm->set_ctrl_pressed(control_mem); @@ -2062,7 +2071,7 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA break; Ref<InputEventMouseMotion> mm; - mm.instance(); + mm.instantiate(); mm->set_window_id(window_id); mm->set_ctrl_pressed(GetKeyState(VK_CONTROL) < 0); mm->set_shift_pressed(GetKeyState(VK_SHIFT) < 0); @@ -2196,7 +2205,7 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA } Ref<InputEventMouseMotion> mm; - mm.instance(); + mm.instantiate(); mm->set_window_id(window_id); if (pen_info.penMask & PEN_MASK_PRESSURE) { @@ -2302,7 +2311,7 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA } Ref<InputEventMouseMotion> mm; - mm.instance(); + mm.instantiate(); mm->set_window_id(window_id); mm->set_ctrl_pressed((wParam & MK_CONTROL) != 0); mm->set_shift_pressed((wParam & MK_SHIFT) != 0); @@ -2385,47 +2394,47 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA case WM_XBUTTONDOWN: case WM_XBUTTONUP: { Ref<InputEventMouseButton> mb; - mb.instance(); + mb.instantiate(); mb->set_window_id(window_id); switch (uMsg) { case WM_LBUTTONDOWN: { mb->set_pressed(true); - mb->set_button_index(1); + mb->set_button_index(MOUSE_BUTTON_LEFT); } break; case WM_LBUTTONUP: { mb->set_pressed(false); - mb->set_button_index(1); + mb->set_button_index(MOUSE_BUTTON_LEFT); } break; case WM_MBUTTONDOWN: { mb->set_pressed(true); - mb->set_button_index(3); + mb->set_button_index(MOUSE_BUTTON_MIDDLE); } break; case WM_MBUTTONUP: { mb->set_pressed(false); - mb->set_button_index(3); + mb->set_button_index(MOUSE_BUTTON_MIDDLE); } break; case WM_RBUTTONDOWN: { mb->set_pressed(true); - mb->set_button_index(2); + mb->set_button_index(MOUSE_BUTTON_RIGHT); } break; case WM_RBUTTONUP: { mb->set_pressed(false); - mb->set_button_index(2); + mb->set_button_index(MOUSE_BUTTON_RIGHT); } break; case WM_LBUTTONDBLCLK: { mb->set_pressed(true); - mb->set_button_index(1); + mb->set_button_index(MOUSE_BUTTON_LEFT); mb->set_double_click(true); } break; case WM_RBUTTONDBLCLK: { mb->set_pressed(true); - mb->set_button_index(2); + mb->set_button_index(MOUSE_BUTTON_RIGHT); mb->set_double_click(true); } break; case WM_MBUTTONDBLCLK: { mb->set_pressed(true); - mb->set_button_index(3); + mb->set_button_index(MOUSE_BUTTON_MIDDLE); mb->set_double_click(true); } break; case WM_MOUSEWHEEL: { @@ -2492,9 +2501,9 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA mb->set_alt_pressed(alt_mem); //mb->is_alt_pressed()=(wParam&MK_MENU)!=0; if (mb->is_pressed()) { - last_button_state |= (1 << (mb->get_button_index() - 1)); + last_button_state |= MouseButton(1 << (mb->get_button_index() - 1)); } else { - last_button_state &= ~(1 << (mb->get_button_index() - 1)); + last_button_state &= (MouseButton) ~(1 << (mb->get_button_index() - 1)); } mb->set_button_mask(last_button_state); @@ -2534,7 +2543,7 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA //send release for mouse wheel Ref<InputEventMouseButton> mbd = mb->duplicate(); mbd->set_window_id(window_id); - last_button_state &= ~(1 << (mbd->get_button_index() - 1)); + last_button_state &= (MouseButton) ~(1 << (mbd->get_button_index() - 1)); mbd->set_button_mask(last_button_state); mbd->set_pressed(false); Input::get_singleton()->accumulate_input_event(mbd); @@ -2843,7 +2852,7 @@ void DisplayServerWindows::_process_key_events() { prev_wc = 0; } Ref<InputEventKey> k; - k.instance(); + k.instantiate(); k->set_window_id(ke.window_id); k->set_shift_pressed(ke.shift); @@ -2870,7 +2879,7 @@ void DisplayServerWindows::_process_key_events() { case WM_KEYUP: case WM_KEYDOWN: { Ref<InputEventKey> k; - k.instance(); + k.instantiate(); k->set_window_id(ke.window_id); k->set_shift_pressed(ke.shift); @@ -2968,7 +2977,7 @@ void DisplayServerWindows::_update_tablet_ctx(const String &p_old_driver, const } } -DisplayServer::WindowID DisplayServerWindows::_create_window(WindowMode p_mode, uint32_t p_flags, const Rect2i &p_rect) { +DisplayServer::WindowID DisplayServerWindows::_create_window(WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Rect2i &p_rect) { DWORD dwExStyle; DWORD dwStyle; @@ -3030,7 +3039,7 @@ DisplayServer::WindowID DisplayServerWindows::_create_window(WindowMode p_mode, #ifdef VULKAN_ENABLED if (rendering_driver == "vulkan") { - if (context_vulkan->window_create(id, wd.hWnd, hInstance, WindowRect.right - WindowRect.left, WindowRect.bottom - WindowRect.top) == -1) { + if (context_vulkan->window_create(id, p_vsync_mode, wd.hWnd, hInstance, WindowRect.right - WindowRect.left, WindowRect.bottom - WindowRect.top) == -1) { memdelete(context_vulkan); context_vulkan = nullptr; windows.erase(id); @@ -3151,7 +3160,7 @@ void DisplayServerWindows::tablet_set_current_driver(const String &p_driver) { } } -DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, WindowMode p_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error) { +DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error) { drop_events = false; key_event_pos = 0; @@ -3270,7 +3279,6 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win } context_gles2->set_use_vsync(video_mode.use_vsync); - set_vsync_via_compositor(video_mode.vsync_via_compositor); if (RasterizerGLES2::is_viable() == OK) { RasterizerGLES2::register_config(); @@ -3286,7 +3294,7 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win (screen_get_size(0).width - p_resolution.width) / 2, (screen_get_size(0).height - p_resolution.height) / 2); - WindowID main_window = _create_window(p_mode, 0, Rect2i(window_position, p_resolution)); + WindowID main_window = _create_window(p_mode, p_vsync_mode, 0, Rect2i(window_position, p_resolution)); ERR_FAIL_COND_MSG(main_window == INVALID_WINDOW_ID, "Failed to create main window."); for (int i = 0; i < WINDOW_FLAG_MAX; i++) { @@ -3347,8 +3355,8 @@ Vector<String> DisplayServerWindows::get_rendering_drivers_func() { return drivers; } -DisplayServer *DisplayServerWindows::create_func(const String &p_rendering_driver, WindowMode p_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error) { - DisplayServer *ds = memnew(DisplayServerWindows(p_rendering_driver, p_mode, p_flags, p_resolution, r_error)); +DisplayServer *DisplayServerWindows::create_func(const String &p_rendering_driver, WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error) { + DisplayServer *ds = memnew(DisplayServerWindows(p_rendering_driver, p_mode, p_vsync_mode, p_flags, p_resolution, r_error)); if (r_error != OK) { ds->alert("Your video card driver does not support any of the supported Vulkan versions.\n" "Please update your drivers or if you have a very old or integrated GPU upgrade it.", diff --git a/platform/windows/display_server_windows.h b/platform/windows/display_server_windows.h index a734077e59..394bed79b0 100644 --- a/platform/windows/display_server_windows.h +++ b/platform/windows/display_server_windows.h @@ -389,7 +389,7 @@ class DisplayServerWindows : public DisplayServer { JoypadWindows *joypad; - WindowID _create_window(WindowMode p_mode, uint32_t p_flags, const Rect2i &p_rect); + WindowID _create_window(WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Rect2i &p_rect); WindowID window_id_counter = MAIN_WINDOW_ID; Map<WindowID, WindowData> windows; @@ -408,7 +408,7 @@ class DisplayServerWindows : public DisplayServer { bool shift_mem = false; bool control_mem = false; bool meta_mem = false; - uint32_t last_button_state = 0; + MouseButton last_button_state = MOUSE_BUTTON_NONE; bool use_raw_input = false; bool drop_events = false; bool in_dispatch_input_event = false; @@ -449,7 +449,7 @@ public: virtual void mouse_warp_to_position(const Point2i &p_to); virtual Point2i mouse_get_position() const; - virtual int mouse_get_button_state() const; + virtual MouseButton mouse_get_button_state() const; virtual void clipboard_set(const String &p_text); virtual String clipboard_get() const; @@ -469,7 +469,7 @@ public: virtual Vector<DisplayServer::WindowID> get_window_list() const; - virtual WindowID create_sub_window(WindowMode p_mode, uint32_t p_flags, const Rect2i &p_rect = Rect2i()); + virtual WindowID create_sub_window(WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Rect2i &p_rect = Rect2i()); virtual void show_window(WindowID p_window); virtual void delete_sub_window(WindowID p_window); @@ -525,6 +525,9 @@ public: virtual void window_set_ime_active(const bool p_active, WindowID p_window = MAIN_WINDOW_ID); virtual void window_set_ime_position(const Point2i &p_pos, WindowID p_window = MAIN_WINDOW_ID); + virtual void window_set_vsync_mode(DisplayServer::VSyncMode p_vsync_mode, WindowID p_window = MAIN_WINDOW_ID) override; + virtual DisplayServer::VSyncMode window_get_vsync_mode(WindowID p_vsync_mode) const override; + virtual void console_set_visible(bool p_enabled); virtual bool is_console_visible() const; @@ -558,16 +561,13 @@ public: virtual void set_native_icon(const String &p_filename); virtual void set_icon(const Ref<Image> &p_icon); - virtual void vsync_set_use_via_compositor(bool p_enable); - virtual bool vsync_is_using_via_compositor() const; - virtual void set_context(Context p_context); - static DisplayServer *create_func(const String &p_rendering_driver, WindowMode p_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error); + static DisplayServer *create_func(const String &p_rendering_driver, WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error); static Vector<String> get_rendering_drivers_func(); static void register_windows_driver(); - DisplayServerWindows(const String &p_rendering_driver, WindowMode p_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error); + DisplayServerWindows(const String &p_rendering_driver, WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error); ~DisplayServerWindows(); }; diff --git a/platform/windows/export/export.cpp b/platform/windows/export/export.cpp index 803d9371f5..10f953f2ec 100644 --- a/platform/windows/export/export.cpp +++ b/platform/windows/export/export.cpp @@ -310,7 +310,7 @@ Error EditorExportPlatformWindows::_code_sign(const Ref<EditorExportPreset> &p_p args.push_back(p_path); #ifndef WINDOWS_ENABLED args.push_back("-out"); - args.push_back(p_path); + args.push_back(p_path + "_signed"); #endif String str; @@ -326,6 +326,16 @@ Error EditorExportPlatformWindows::_code_sign(const Ref<EditorExportPreset> &p_p return FAILED; } +#ifndef WINDOWS_ENABLED + DirAccessRef tmp_dir = DirAccess::create_for_path(p_path.get_base_dir()); + + err = tmp_dir->remove(p_path); + ERR_FAIL_COND_V(err != OK, err); + + err = tmp_dir->rename(p_path + "_signed", p_path); + ERR_FAIL_COND_V(err != OK, err); +#endif + return OK; } @@ -344,11 +354,11 @@ void register_windows_exporter() { #endif Ref<EditorExportPlatformWindows> platform; - platform.instance(); + platform.instantiate(); Ref<Image> img = memnew(Image(_windows_logo)); Ref<ImageTexture> logo; - logo.instance(); + logo.instantiate(); logo->create_from_image(img); platform->set_logo(logo); platform->set_name("Windows Desktop"); diff --git a/platform/windows/joypad_windows.cpp b/platform/windows/joypad_windows.cpp index da36dc1f2b..94da63e49d 100644 --- a/platform/windows/joypad_windows.cpp +++ b/platform/windows/joypad_windows.cpp @@ -330,7 +330,7 @@ void JoypadWindows::process_joypads() { if (joy.state.dwPacketNumber != joy.last_packet) { int button_mask = XINPUT_GAMEPAD_DPAD_UP; for (int j = 0; j <= 16; j++) { - input->joy_button(joy.id, j, joy.state.Gamepad.wButtons & button_mask); + input->joy_button(joy.id, (JoyButton)j, joy.state.Gamepad.wButtons & button_mask); button_mask = button_mask * 2; } @@ -381,12 +381,12 @@ void JoypadWindows::process_joypads() { for (int j = 0; j < 128; j++) { if (js.rgbButtons[j] & 0x80) { if (!joy->last_buttons[j]) { - input->joy_button(joy->id, j, true); + input->joy_button(joy->id, (JoyButton)j, true); joy->last_buttons[j] = true; } } else { if (joy->last_buttons[j]) { - input->joy_button(joy->id, j, false); + input->joy_button(joy->id, (JoyButton)j, false); joy->last_buttons[j] = false; } } @@ -400,7 +400,7 @@ void JoypadWindows::process_joypads() { for (int j = 0; j < joy->joy_axis.size(); j++) { for (int k = 0; k < count; k++) { if (joy->joy_axis[j] == axes[k]) { - input->joy_axis(joy->id, j, axis_correct(values[k])); + input->joy_axis(joy->id, (JoyAxis)j, axis_correct(values[k])); break; }; }; @@ -410,38 +410,38 @@ void JoypadWindows::process_joypads() { } void JoypadWindows::post_hat(int p_device, DWORD p_dpad) { - int dpad_val = 0; + HatMask dpad_val = (HatMask)0; // Should be -1 when centered, but according to docs: // "Some drivers report the centered position of the POV indicator as 65,535. Determine whether the indicator is centered as follows: // BOOL POVCentered = (LOWORD(dwPOV) == 0xFFFF);" // https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ee416628(v%3Dvs.85)#remarks if (LOWORD(p_dpad) == 0xFFFF) { - dpad_val = Input::HAT_MASK_CENTER; + dpad_val = (HatMask)HatMask::HAT_MASK_CENTER; } if (p_dpad == 0) { - dpad_val = Input::HAT_MASK_UP; + dpad_val = (HatMask)HatMask::HAT_MASK_UP; } else if (p_dpad == 4500) { - dpad_val = (Input::HAT_MASK_UP | Input::HAT_MASK_RIGHT); + dpad_val = (HatMask)(HatMask::HAT_MASK_UP | HatMask::HAT_MASK_RIGHT); } else if (p_dpad == 9000) { - dpad_val = Input::HAT_MASK_RIGHT; + dpad_val = (HatMask)HatMask::HAT_MASK_RIGHT; } else if (p_dpad == 13500) { - dpad_val = (Input::HAT_MASK_RIGHT | Input::HAT_MASK_DOWN); + dpad_val = (HatMask)(HatMask::HAT_MASK_RIGHT | HatMask::HAT_MASK_DOWN); } else if (p_dpad == 18000) { - dpad_val = Input::HAT_MASK_DOWN; + dpad_val = (HatMask)HatMask::HAT_MASK_DOWN; } else if (p_dpad == 22500) { - dpad_val = (Input::HAT_MASK_DOWN | Input::HAT_MASK_LEFT); + dpad_val = (HatMask)(HatMask::HAT_MASK_DOWN | HatMask::HAT_MASK_LEFT); } else if (p_dpad == 27000) { - dpad_val = Input::HAT_MASK_LEFT; + dpad_val = (HatMask)HatMask::HAT_MASK_LEFT; } else if (p_dpad == 31500) { - dpad_val = (Input::HAT_MASK_LEFT | Input::HAT_MASK_UP); + dpad_val = (HatMask)(HatMask::HAT_MASK_LEFT | HatMask::HAT_MASK_UP); } input->joy_hat(p_device, dpad_val); }; diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index c956fe49ae..56d673afc3 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -634,13 +634,13 @@ String OS_Windows::get_config_path() const { // The XDG Base Directory specification technically only applies on Linux/*BSD, but it doesn't hurt to support it on Windows as well. if (has_environment("XDG_CONFIG_HOME")) { if (get_environment("XDG_CONFIG_HOME").is_absolute_path()) { - return get_environment("XDG_CONFIG_HOME"); + return get_environment("XDG_CONFIG_HOME").replace("\\", "/"); } else { WARN_PRINT_ONCE("`XDG_CONFIG_HOME` is a relative path. Ignoring its value and falling back to `%APPDATA%` or `.` per the XDG Base Directory specification."); } } if (has_environment("APPDATA")) { - return get_environment("APPDATA"); + return get_environment("APPDATA").replace("\\", "/"); } return "."; } @@ -649,7 +649,7 @@ String OS_Windows::get_data_path() const { // The XDG Base Directory specification technically only applies on Linux/*BSD, but it doesn't hurt to support it on Windows as well. if (has_environment("XDG_DATA_HOME")) { if (get_environment("XDG_DATA_HOME").is_absolute_path()) { - return get_environment("XDG_DATA_HOME"); + return get_environment("XDG_DATA_HOME").replace("\\", "/"); } else { WARN_PRINT_ONCE("`XDG_DATA_HOME` is a relative path. Ignoring its value and falling back to `get_config_path()` per the XDG Base Directory specification."); } @@ -661,13 +661,13 @@ String OS_Windows::get_cache_path() const { // The XDG Base Directory specification technically only applies on Linux/*BSD, but it doesn't hurt to support it on Windows as well. if (has_environment("XDG_CACHE_HOME")) { if (get_environment("XDG_CACHE_HOME").is_absolute_path()) { - return get_environment("XDG_CACHE_HOME"); + return get_environment("XDG_CACHE_HOME").replace("\\", "/"); } else { WARN_PRINT_ONCE("`XDG_CACHE_HOME` is a relative path. Ignoring its value and falling back to `%TEMP%` or `get_config_path()` per the XDG Base Directory specification."); } } if (has_environment("TEMP")) { - return get_environment("TEMP"); + return get_environment("TEMP").replace("\\", "/"); } return get_config_path(); } @@ -710,7 +710,7 @@ String OS_Windows::get_system_dir(SystemDir p_dir) const { PWSTR szPath; HRESULT res = SHGetKnownFolderPath(id, 0, nullptr, &szPath); ERR_FAIL_COND_V(res != S_OK, String()); - String path = String::utf16((const char16_t *)szPath); + String path = String::utf16((const char16_t *)szPath).replace("\\", "/"); CoTaskMemFree(szPath); return path; } diff --git a/platform/windows/vulkan_context_win.cpp b/platform/windows/vulkan_context_win.cpp index e5e176ab93..191792b329 100644 --- a/platform/windows/vulkan_context_win.cpp +++ b/platform/windows/vulkan_context_win.cpp @@ -35,18 +35,17 @@ const char *VulkanContextWindows::_get_platform_surface_extension() const { return VK_KHR_WIN32_SURFACE_EXTENSION_NAME; } -int VulkanContextWindows::window_create(DisplayServer::WindowID p_window_id, HWND p_window, HINSTANCE p_instance, int p_width, int p_height) { +int VulkanContextWindows::window_create(DisplayServer::WindowID p_window_id, DisplayServer::VSyncMode p_vsync_mode, HWND p_window, HINSTANCE p_instance, int p_width, int p_height) { VkWin32SurfaceCreateInfoKHR createInfo; createInfo.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR; createInfo.pNext = nullptr; createInfo.flags = 0; createInfo.hinstance = p_instance; createInfo.hwnd = p_window; - VkSurfaceKHR surface; VkResult err = vkCreateWin32SurfaceKHR(_get_instance(), &createInfo, nullptr, &surface); ERR_FAIL_COND_V(err, -1); - return _window_create(p_window_id, surface, p_width, p_height); + return _window_create(p_window_id, p_vsync_mode, surface, p_width, p_height); } VulkanContextWindows::VulkanContextWindows() { diff --git a/platform/windows/vulkan_context_win.h b/platform/windows/vulkan_context_win.h index 4fe987218d..39dd2641fd 100644 --- a/platform/windows/vulkan_context_win.h +++ b/platform/windows/vulkan_context_win.h @@ -38,7 +38,7 @@ class VulkanContextWindows : public VulkanContext { virtual const char *_get_platform_surface_extension() const; public: - int window_create(DisplayServer::WindowID p_window_id, HWND p_window, HINSTANCE p_instance, int p_width, int p_height); + int window_create(DisplayServer::WindowID p_window_id, DisplayServer::VSyncMode p_vsync_mode, HWND p_window, HINSTANCE p_instance, int p_width, int p_height); VulkanContextWindows(); ~VulkanContextWindows(); diff --git a/platform/windows/windows_terminal_logger.cpp b/platform/windows/windows_terminal_logger.cpp index c1f3827d15..8cab7ca521 100644 --- a/platform/windows/windows_terminal_logger.cpp +++ b/platform/windows/windows_terminal_logger.cpp @@ -108,47 +108,47 @@ void WindowsTerminalLogger::log_error(const char *p_function, const char *p_file SetConsoleTextAttribute(hCon, basecol | FOREGROUND_INTENSITY); switch (p_type) { case ERR_ERROR: - logf("ERROR:"); + logf_error("ERROR:"); break; case ERR_WARNING: - logf("WARNING:"); + logf_error("WARNING:"); break; case ERR_SCRIPT: - logf("SCRIPT ERROR:"); + logf_error("SCRIPT ERROR:"); break; case ERR_SHADER: - logf("SHADER ERROR:"); + logf_error("SHADER ERROR:"); break; } SetConsoleTextAttribute(hCon, basecol); if (p_rationale && p_rationale[0]) { - logf(" %s\n", p_rationale); + logf_error(" %s\n", p_rationale); } else { - logf(" %s\n", p_code); + logf_error(" %s\n", p_code); } // `FOREGROUND_INTENSITY` alone results in gray text. SetConsoleTextAttribute(hCon, FOREGROUND_INTENSITY); switch (p_type) { case ERR_ERROR: - logf(" at: "); + logf_error(" at: "); break; case ERR_WARNING: - logf(" at: "); + logf_error(" at: "); break; case ERR_SCRIPT: - logf(" at: "); + logf_error(" at: "); break; case ERR_SHADER: - logf(" at: "); + logf_error(" at: "); break; } if (p_rationale && p_rationale[0]) { - logf("(%s:%i)\n", p_file, p_line); + logf_error("(%s:%i)\n", p_file, p_line); } else { - logf("%s (%s:%i)\n", p_function, p_file, p_line); + logf_error("%s (%s:%i)\n", p_function, p_file, p_line); } SetConsoleTextAttribute(hCon, sbi.wAttributes); diff --git a/scene/2d/area_2d.cpp b/scene/2d/area_2d.cpp index 597693aa6a..cf84767151 100644 --- a/scene/2d/area_2d.cpp +++ b/scene/2d/area_2d.cpp @@ -551,7 +551,7 @@ void Area2D::_bind_methods() { ADD_GROUP("Physics Overrides", ""); ADD_PROPERTY(PropertyInfo(Variant::INT, "space_override", PROPERTY_HINT_ENUM, "Disabled,Combine,Combine-Replace,Replace,Replace-Combine"), "set_space_override_mode", "get_space_override_mode"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gravity_point"), "set_gravity_is_point", "is_gravity_a_point"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "gravity_distance_scale", PROPERTY_HINT_EXP_RANGE, "0,1024,0.001,or_greater"), "set_gravity_distance_scale", "get_gravity_distance_scale"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "gravity_distance_scale", PROPERTY_HINT_RANGE, "0,1024,0.001,or_greater,exp"), "set_gravity_distance_scale", "get_gravity_distance_scale"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "gravity_vec"), "set_gravity_vector", "get_gravity_vector"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "gravity", PROPERTY_HINT_RANGE, "-4096,4096,0.001,or_lesser,or_greater"), "set_gravity", "get_gravity"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "linear_damp", PROPERTY_HINT_RANGE, "0,100,0.001,or_greater"), "set_linear_damp", "get_linear_damp"); diff --git a/scene/2d/audio_stream_player_2d.cpp b/scene/2d/audio_stream_player_2d.cpp index 127ef6762d..860ccfec64 100644 --- a/scene/2d/audio_stream_player_2d.cpp +++ b/scene/2d/audio_stream_player_2d.cpp @@ -494,7 +494,7 @@ void AudioStreamPlayer2D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "playing", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "_set_playing", "is_playing"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "autoplay"), "set_autoplay", "is_autoplay_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "stream_paused", PROPERTY_HINT_NONE, ""), "set_stream_paused", "get_stream_paused"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "max_distance", PROPERTY_HINT_EXP_RANGE, "1,4096,1,or_greater"), "set_max_distance", "get_max_distance"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "max_distance", PROPERTY_HINT_RANGE, "1,4096,1,or_greater,exp"), "set_max_distance", "get_max_distance"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "attenuation", PROPERTY_HINT_EXP_EASING, "attenuation"), "set_attenuation", "get_attenuation"); ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "bus", PROPERTY_HINT_ENUM, ""), "set_bus", "get_bus"); ADD_PROPERTY(PropertyInfo(Variant::INT, "area_mask", PROPERTY_HINT_LAYERS_2D_PHYSICS), "set_area_mask", "get_area_mask"); diff --git a/scene/2d/camera_2d.cpp b/scene/2d/camera_2d.cpp index 926997a715..f293081987 100644 --- a/scene/2d/camera_2d.cpp +++ b/scene/2d/camera_2d.cpp @@ -178,20 +178,23 @@ Transform2D Camera2D::get_camera_transform() { } Rect2 screen_rect(-screen_offset + ret_camera_pos, screen_size * zoom); - if (screen_rect.position.x < limit[SIDE_LEFT]) { - screen_rect.position.x = limit[SIDE_LEFT]; - } - if (screen_rect.position.x + screen_rect.size.x > limit[SIDE_RIGHT]) { - screen_rect.position.x = limit[SIDE_RIGHT] - screen_rect.size.x; - } + if (!limit_smoothing_enabled) { + if (screen_rect.position.x < limit[SIDE_LEFT]) { + screen_rect.position.x = limit[SIDE_LEFT]; + } - if (screen_rect.position.y + screen_rect.size.y > limit[SIDE_BOTTOM]) { - screen_rect.position.y = limit[SIDE_BOTTOM] - screen_rect.size.y; - } + if (screen_rect.position.x + screen_rect.size.x > limit[SIDE_RIGHT]) { + screen_rect.position.x = limit[SIDE_RIGHT] - screen_rect.size.x; + } + + if (screen_rect.position.y + screen_rect.size.y > limit[SIDE_BOTTOM]) { + screen_rect.position.y = limit[SIDE_BOTTOM] - screen_rect.size.y; + } - if (screen_rect.position.y < limit[SIDE_TOP]) { - screen_rect.position.y = limit[SIDE_TOP]; + if (screen_rect.position.y < limit[SIDE_TOP]) { + screen_rect.position.y = limit[SIDE_TOP]; + } } if (offset != Vector2()) { diff --git a/scene/2d/canvas_modulate.cpp b/scene/2d/canvas_modulate.cpp index 52eabefbcb..4de99959a3 100644 --- a/scene/2d/canvas_modulate.cpp +++ b/scene/2d/canvas_modulate.cpp @@ -81,7 +81,7 @@ TypedArray<String> CanvasModulate::get_configuration_warnings() const { get_tree()->get_nodes_in_group("_canvas_modulate_" + itos(get_canvas().get_id()), &nodes); if (nodes.size() > 1) { - warnings.push_back(TTR("Only one visible CanvasModulate is allowed per scene (or set of instanced scenes). The first created one will work, while the rest will be ignored.")); + warnings.push_back(TTR("Only one visible CanvasModulate is allowed per scene (or set of instantiated scenes). The first created one will work, while the rest will be ignored.")); } } diff --git a/scene/2d/collision_object_2d.cpp b/scene/2d/collision_object_2d.cpp index a633923be7..93d154bb01 100644 --- a/scene/2d/collision_object_2d.cpp +++ b/scene/2d/collision_object_2d.cpp @@ -31,7 +31,6 @@ #include "collision_object_2d.h" #include "scene/scene_string_names.h" -#include "servers/physics_server_2d.h" void CollisionObject2D::_notification(int p_what) { switch (p_what) { @@ -44,16 +43,22 @@ void CollisionObject2D::_notification(int p_what) { PhysicsServer2D::get_singleton()->body_set_state(rid, PhysicsServer2D::BODY_STATE_TRANSFORM, global_transform); } - RID space = get_world_2d()->get_space(); - if (area) { - PhysicsServer2D::get_singleton()->area_set_space(rid, space); - } else { - PhysicsServer2D::get_singleton()->body_set_space(rid, space); + bool disabled = !is_enabled(); + + if (disabled && (disable_mode != DISABLE_MODE_REMOVE)) { + _apply_disabled(); } - _update_pickable(); + if (!disabled || (disable_mode != DISABLE_MODE_REMOVE)) { + RID space = get_world_2d()->get_space(); + if (area) { + PhysicsServer2D::get_singleton()->area_set_space(rid, space); + } else { + PhysicsServer2D::get_singleton()->body_set_space(rid, space); + } + } - //get space + _update_pickable(); } break; case NOTIFICATION_ENTER_CANVAS: { @@ -67,6 +72,7 @@ void CollisionObject2D::_notification(int p_what) { case NOTIFICATION_VISIBILITY_CHANGED: { _update_pickable(); } break; + case NOTIFICATION_TRANSFORM_CHANGED: { if (only_update_transform_changes) { return; @@ -79,15 +85,22 @@ void CollisionObject2D::_notification(int p_what) { } else { PhysicsServer2D::get_singleton()->body_set_state(rid, PhysicsServer2D::BODY_STATE_TRANSFORM, global_transform); } - } break; + case NOTIFICATION_EXIT_TREE: { - if (area) { - PhysicsServer2D::get_singleton()->area_set_space(rid, RID()); - } else { - PhysicsServer2D::get_singleton()->body_set_space(rid, RID()); + bool disabled = !is_enabled(); + + if (!disabled || (disable_mode != DISABLE_MODE_REMOVE)) { + if (area) { + PhysicsServer2D::get_singleton()->area_set_space(rid, RID()); + } else { + PhysicsServer2D::get_singleton()->body_set_space(rid, RID()); + } } + if (disabled && (disable_mode != DISABLE_MODE_REMOVE)) { + _apply_enabled(); + } } break; case NOTIFICATION_EXIT_CANVAS: { @@ -97,6 +110,14 @@ void CollisionObject2D::_notification(int p_what) { PhysicsServer2D::get_singleton()->body_attach_canvas_instance_id(rid, ObjectID()); } } break; + + case NOTIFICATION_DISABLED: { + _apply_disabled(); + } break; + + case NOTIFICATION_ENABLED: { + _apply_enabled(); + } break; } } @@ -158,6 +179,79 @@ bool CollisionObject2D::get_collision_mask_bit(int p_bit) const { return get_collision_mask() & (1 << p_bit); } +void CollisionObject2D::set_disable_mode(DisableMode p_mode) { + if (disable_mode == p_mode) { + return; + } + + bool disabled = is_inside_tree() && !is_enabled(); + + if (disabled) { + // Cancel previous disable mode. + _apply_enabled(); + } + + disable_mode = p_mode; + + if (disabled) { + // Apply new disable mode. + _apply_disabled(); + } +} + +CollisionObject2D::DisableMode CollisionObject2D::get_disable_mode() const { + return disable_mode; +} + +void CollisionObject2D::_apply_disabled() { + switch (disable_mode) { + case DISABLE_MODE_REMOVE: { + if (is_inside_tree()) { + if (area) { + PhysicsServer2D::get_singleton()->area_set_space(rid, RID()); + } else { + PhysicsServer2D::get_singleton()->body_set_space(rid, RID()); + } + } + } break; + + case DISABLE_MODE_MAKE_STATIC: { + if (!area && (body_mode != PhysicsServer2D::BODY_MODE_STATIC)) { + PhysicsServer2D::get_singleton()->body_set_mode(rid, PhysicsServer2D::BODY_MODE_STATIC); + } + } break; + + case DISABLE_MODE_KEEP_ACTIVE: { + // Nothing to do. + } break; + } +} + +void CollisionObject2D::_apply_enabled() { + switch (disable_mode) { + case DISABLE_MODE_REMOVE: { + if (is_inside_tree()) { + RID space = get_world_2d()->get_space(); + if (area) { + PhysicsServer2D::get_singleton()->area_set_space(rid, space); + } else { + PhysicsServer2D::get_singleton()->body_set_space(rid, space); + } + } + } break; + + case DISABLE_MODE_MAKE_STATIC: { + if (!area && (body_mode != PhysicsServer2D::BODY_MODE_STATIC)) { + PhysicsServer2D::get_singleton()->body_set_mode(rid, body_mode); + } + } break; + + case DISABLE_MODE_KEEP_ACTIVE: { + // Nothing to do. + } break; + } +} + uint32_t CollisionObject2D::create_shape_owner(Object *p_owner) { ShapeData sd; uint32_t id; @@ -412,6 +506,22 @@ bool CollisionObject2D::is_only_update_transform_changes_enabled() const { return only_update_transform_changes; } +void CollisionObject2D::set_body_mode(PhysicsServer2D::BodyMode p_mode) { + ERR_FAIL_COND(area); + + if (body_mode == p_mode) { + return; + } + + body_mode = p_mode; + + if (is_inside_tree() && !is_enabled() && (disable_mode == DISABLE_MODE_MAKE_STATIC)) { + return; + } + + PhysicsServer2D::get_singleton()->body_set_mode(rid, p_mode); +} + void CollisionObject2D::_update_pickable() { if (!is_inside_tree()) { return; @@ -445,6 +555,8 @@ void CollisionObject2D::_bind_methods() { ClassDB::bind_method(D_METHOD("get_collision_layer_bit", "bit"), &CollisionObject2D::get_collision_layer_bit); ClassDB::bind_method(D_METHOD("set_collision_mask_bit", "bit", "value"), &CollisionObject2D::set_collision_mask_bit); ClassDB::bind_method(D_METHOD("get_collision_mask_bit", "bit"), &CollisionObject2D::get_collision_mask_bit); + ClassDB::bind_method(D_METHOD("set_disable_mode", "mode"), &CollisionObject2D::set_disable_mode); + ClassDB::bind_method(D_METHOD("get_disable_mode"), &CollisionObject2D::get_disable_mode); ClassDB::bind_method(D_METHOD("set_pickable", "enabled"), &CollisionObject2D::set_pickable); ClassDB::bind_method(D_METHOD("is_pickable"), &CollisionObject2D::is_pickable); ClassDB::bind_method(D_METHOD("create_shape_owner", "owner"), &CollisionObject2D::create_shape_owner); @@ -473,12 +585,18 @@ void CollisionObject2D::_bind_methods() { ADD_SIGNAL(MethodInfo("mouse_entered")); ADD_SIGNAL(MethodInfo("mouse_exited")); + ADD_PROPERTY(PropertyInfo(Variant::INT, "disable_mode", PROPERTY_HINT_ENUM, "Remove,MakeStatic,KeepActive"), "set_disable_mode", "get_disable_mode"); + ADD_GROUP("Collision", "collision_"); ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_layer", PROPERTY_HINT_LAYERS_2D_PHYSICS), "set_collision_layer", "get_collision_layer"); ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_2D_PHYSICS), "set_collision_mask", "get_collision_mask"); ADD_GROUP("Input", "input_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "input_pickable"), "set_pickable", "is_pickable"); + + BIND_ENUM_CONSTANT(DISABLE_MODE_REMOVE); + BIND_ENUM_CONSTANT(DISABLE_MODE_MAKE_STATIC); + BIND_ENUM_CONSTANT(DISABLE_MODE_KEEP_ACTIVE); } CollisionObject2D::CollisionObject2D(RID p_rid, bool p_area) { @@ -493,6 +611,7 @@ CollisionObject2D::CollisionObject2D(RID p_rid, bool p_area) { PhysicsServer2D::get_singleton()->area_attach_object_instance_id(rid, get_instance_id()); } else { PhysicsServer2D::get_singleton()->body_attach_object_instance_id(rid, get_instance_id()); + PhysicsServer2D::get_singleton()->body_set_mode(rid, body_mode); } } diff --git a/scene/2d/collision_object_2d.h b/scene/2d/collision_object_2d.h index e10f3097d9..7a71affbb5 100644 --- a/scene/2d/collision_object_2d.h +++ b/scene/2d/collision_object_2d.h @@ -33,10 +33,19 @@ #include "scene/2d/node_2d.h" #include "scene/resources/shape_2d.h" +#include "servers/physics_server_2d.h" class CollisionObject2D : public Node2D { GDCLASS(CollisionObject2D, Node2D); +public: + enum DisableMode { + DISABLE_MODE_REMOVE, + DISABLE_MODE_MAKE_STATIC, + DISABLE_MODE_KEEP_ACTIVE, + }; + +private: uint32_t collision_layer = 1; uint32_t collision_mask = 1; @@ -44,6 +53,10 @@ class CollisionObject2D : public Node2D { RID rid; bool pickable = false; + DisableMode disable_mode = DISABLE_MODE_REMOVE; + + PhysicsServer2D::BodyMode body_mode = PhysicsServer2D::BODY_MODE_STATIC; + struct ShapeData { Object *owner = nullptr; Transform2D xform; @@ -64,6 +77,9 @@ class CollisionObject2D : public Node2D { Map<uint32_t, ShapeData> shapes; bool only_update_transform_changes = false; //this is used for sync physics in CharacterBody2D + void _apply_disabled(); + void _apply_enabled(); + protected: CollisionObject2D(RID p_rid, bool p_area); @@ -79,6 +95,8 @@ protected: void set_only_update_transform_changes(bool p_enable); bool is_only_update_transform_changes_enabled() const; + void set_body_mode(PhysicsServer2D::BodyMode p_mode); + public: void set_collision_layer(uint32_t p_layer); uint32_t get_collision_layer() const; @@ -92,6 +110,9 @@ public: void set_collision_mask_bit(int p_bit, bool p_value); bool get_collision_mask_bit(int p_bit) const; + void set_disable_mode(DisableMode p_mode); + DisableMode get_disable_mode() const; + uint32_t create_shape_owner(Object *p_owner); void remove_shape_owner(uint32_t owner); void get_shape_owners(List<uint32_t> *r_owners); @@ -131,4 +152,6 @@ public: ~CollisionObject2D(); }; +VARIANT_ENUM_CAST(CollisionObject2D::DisableMode); + #endif // COLLISION_OBJECT_2D_H diff --git a/scene/2d/cpu_particles_2d.cpp b/scene/2d/cpu_particles_2d.cpp index 1578643d14..24f3301ce1 100644 --- a/scene/2d/cpu_particles_2d.cpp +++ b/scene/2d/cpu_particles_2d.cpp @@ -464,31 +464,31 @@ Vector2 CPUParticles2D::get_gravity() const { void CPUParticles2D::_validate_property(PropertyInfo &property) const { if (property.name == "color" && color_ramp.is_valid()) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } if (property.name == "emission_sphere_radius" && emission_shape != EMISSION_SHAPE_SPHERE) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } if (property.name == "emission_rect_extents" && emission_shape != EMISSION_SHAPE_RECTANGLE) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } if ((property.name == "emission_point_texture" || property.name == "emission_color_texture") && (emission_shape < EMISSION_SHAPE_POINTS)) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } if (property.name == "emission_normals" && emission_shape != EMISSION_SHAPE_DIRECTED_POINTS) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } if (property.name == "emission_points" && emission_shape != EMISSION_SHAPE_POINTS && emission_shape != EMISSION_SHAPE_DIRECTED_POINTS) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } if (property.name == "emission_colors" && emission_shape != EMISSION_SHAPE_POINTS && emission_shape != EMISSION_SHAPE_DIRECTED_POINTS) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } } @@ -1202,7 +1202,7 @@ void CPUParticles2D::_bind_methods() { ClassDB::bind_method(D_METHOD("restart"), &CPUParticles2D::restart); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "emitting"), "set_emitting", "is_emitting"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "amount", PROPERTY_HINT_EXP_RANGE, "1,1000000,1"), "set_amount", "get_amount"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "amount", PROPERTY_HINT_RANGE, "1,1000000,1,exp"), "set_amount", "get_amount"); ADD_GROUP("Time", ""); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "lifetime", PROPERTY_HINT_RANGE, "0.01,600.0,0.01,or_greater"), "set_lifetime", "get_lifetime"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "one_shot"), "set_one_shot", "get_one_shot"); @@ -1313,7 +1313,7 @@ void CPUParticles2D::_bind_methods() { ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "damping_random", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_param_randomness", "get_param_randomness", PARAM_DAMPING); ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "damping_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_param_curve", "get_param_curve", PARAM_DAMPING); ADD_GROUP("Angle", ""); - ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angle", PROPERTY_HINT_RANGE, "-720,720,0.1,or_lesser,or_greater"), "set_param", "get_param", PARAM_ANGLE); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angle", PROPERTY_HINT_RANGE, "-720,720,0.1,or_lesser,or_greater,degrees"), "set_param", "get_param", PARAM_ANGLE); ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angle_random", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_param_randomness", "get_param_randomness", PARAM_ANGLE); ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "angle_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_param_curve", "get_param_curve", PARAM_ANGLE); ADD_GROUP("Scale", ""); diff --git a/scene/2d/gpu_particles_2d.cpp b/scene/2d/gpu_particles_2d.cpp index d7404ff479..adfb94d574 100644 --- a/scene/2d/gpu_particles_2d.cpp +++ b/scene/2d/gpu_particles_2d.cpp @@ -451,7 +451,7 @@ void GPUParticles2D::_notification(int p_what) { RS::get_singleton()->canvas_item_add_particles(get_canvas_item(), particles, texture_rid); #ifdef TOOLS_ENABLED - if (Engine::get_singleton()->is_editor_hint() && (this == get_tree()->get_edited_scene_root() || get_tree()->get_edited_scene_root()->is_a_parent_of(this))) { + if (Engine::get_singleton()->is_editor_hint() && (this == get_tree()->get_edited_scene_root() || get_tree()->get_edited_scene_root()->is_ancestor_of(this))) { draw_rect(visibility_rect, Color(0, 0.7, 0.9, 0.4), false); } #endif @@ -531,7 +531,7 @@ void GPUParticles2D::_bind_methods() { ClassDB::bind_method(D_METHOD("get_trail_section_subdivisions"), &GPUParticles2D::get_trail_section_subdivisions); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "emitting"), "set_emitting", "is_emitting"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "amount", PROPERTY_HINT_EXP_RANGE, "1,1000000,1"), "set_amount", "get_amount"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "amount", PROPERTY_HINT_RANGE, "1,1000000,1,exp"), "set_amount", "get_amount"); ADD_GROUP("Time", ""); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "lifetime", PROPERTY_HINT_RANGE, "0.01,600.0,0.01,or_greater"), "set_lifetime", "get_lifetime"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "one_shot"), "set_one_shot", "get_one_shot"); diff --git a/scene/2d/joints_2d.cpp b/scene/2d/joints_2d.cpp index 8a4ccc2f96..dbba6917b5 100644 --- a/scene/2d/joints_2d.cpp +++ b/scene/2d/joints_2d.cpp @@ -274,7 +274,7 @@ void PinJoint2D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_softness", "softness"), &PinJoint2D::set_softness); ClassDB::bind_method(D_METHOD("get_softness"), &PinJoint2D::get_softness); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "softness", PROPERTY_HINT_EXP_RANGE, "0.00,16,0.01"), "set_softness", "get_softness"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "softness", PROPERTY_HINT_RANGE, "0.00,16,0.01,exp"), "set_softness", "get_softness"); } PinJoint2D::PinJoint2D() { @@ -336,8 +336,8 @@ void GrooveJoint2D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_initial_offset", "offset"), &GrooveJoint2D::set_initial_offset); ClassDB::bind_method(D_METHOD("get_initial_offset"), &GrooveJoint2D::get_initial_offset); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "length", PROPERTY_HINT_EXP_RANGE, "1,65535,1"), "set_length", "get_length"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "initial_offset", PROPERTY_HINT_EXP_RANGE, "1,65535,1"), "set_initial_offset", "get_initial_offset"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "length", PROPERTY_HINT_RANGE, "1,65535,1,exp"), "set_length", "get_length"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "initial_offset", PROPERTY_HINT_RANGE, "1,65535,1,exp"), "set_initial_offset", "get_initial_offset"); } GrooveJoint2D::GrooveJoint2D() { @@ -433,10 +433,10 @@ void DampedSpringJoint2D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_damping", "damping"), &DampedSpringJoint2D::set_damping); ClassDB::bind_method(D_METHOD("get_damping"), &DampedSpringJoint2D::get_damping); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "length", PROPERTY_HINT_EXP_RANGE, "1,65535,1"), "set_length", "get_length"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "rest_length", PROPERTY_HINT_EXP_RANGE, "0,65535,1"), "set_rest_length", "get_rest_length"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "stiffness", PROPERTY_HINT_EXP_RANGE, "0.1,64,0.1"), "set_stiffness", "get_stiffness"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "damping", PROPERTY_HINT_EXP_RANGE, "0.01,16,0.01"), "set_damping", "get_damping"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "length", PROPERTY_HINT_RANGE, "1,65535,1,exp"), "set_length", "get_length"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "rest_length", PROPERTY_HINT_RANGE, "0,65535,1,exp"), "set_rest_length", "get_rest_length"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "stiffness", PROPERTY_HINT_RANGE, "0.1,64,0.1,exp"), "set_stiffness", "get_stiffness"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "damping", PROPERTY_HINT_RANGE, "0.01,16,0.01,exp"), "set_damping", "get_damping"); } DampedSpringJoint2D::DampedSpringJoint2D() { diff --git a/scene/2d/navigation_region_2d.cpp b/scene/2d/navigation_region_2d.cpp index d2caf5bea8..ea639ae3a3 100644 --- a/scene/2d/navigation_region_2d.cpp +++ b/scene/2d/navigation_region_2d.cpp @@ -169,7 +169,7 @@ Ref<NavigationMesh> NavigationPolygon::get_mesh() { MutexLock lock(navmesh_generation); if (navmesh.is_null()) { - navmesh.instance(); + navmesh.instantiate(); Vector<Vector3> verts; { verts.resize(get_vertices().size()); diff --git a/scene/2d/node_2d.cpp b/scene/2d/node_2d.cpp index 9d86ec88be..6fd383ddab 100644 --- a/scene/2d/node_2d.cpp +++ b/scene/2d/node_2d.cpp @@ -164,14 +164,6 @@ void Node2D::set_skew(real_t p_radians) { _update_transform(); } -void Node2D::set_rotation_degrees(real_t p_degrees) { - set_rotation(Math::deg2rad(p_degrees)); -} - -void Node2D::set_skew_degrees(real_t p_degrees) { - set_skew(Math::deg2rad(p_degrees)); -} - void Node2D::set_scale(const Size2 &p_scale) { if (_xform_dirty) { ((Node2D *)this)->_update_xform_values(); @@ -210,14 +202,6 @@ real_t Node2D::get_skew() const { return skew; } -real_t Node2D::get_rotation_degrees() const { - return Math::rad2deg(get_rotation()); -} - -real_t Node2D::get_skew_degrees() const { - return Math::rad2deg(get_skew()); -} - Size2 Node2D::get_scale() const { if (_xform_dirty) { ((Node2D *)this)->_update_xform_values(); @@ -293,14 +277,6 @@ void Node2D::set_global_rotation(real_t p_radians) { } } -real_t Node2D::get_global_rotation_degrees() const { - return Math::rad2deg(get_global_rotation()); -} - -void Node2D::set_global_rotation_degrees(real_t p_degrees) { - set_global_rotation(Math::deg2rad(p_degrees)); -} - Size2 Node2D::get_global_scale() const { return get_global_transform().get_scale(); } @@ -403,16 +379,12 @@ bool Node2D::is_y_sort_enabled() const { void Node2D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_position", "position"), &Node2D::set_position); ClassDB::bind_method(D_METHOD("set_rotation", "radians"), &Node2D::set_rotation); - ClassDB::bind_method(D_METHOD("set_rotation_degrees", "degrees"), &Node2D::set_rotation_degrees); ClassDB::bind_method(D_METHOD("set_skew", "radians"), &Node2D::set_skew); - ClassDB::bind_method(D_METHOD("set_skew_degrees", "degrees"), &Node2D::set_skew_degrees); ClassDB::bind_method(D_METHOD("set_scale", "scale"), &Node2D::set_scale); ClassDB::bind_method(D_METHOD("get_position"), &Node2D::get_position); ClassDB::bind_method(D_METHOD("get_rotation"), &Node2D::get_rotation); - ClassDB::bind_method(D_METHOD("get_rotation_degrees"), &Node2D::get_rotation_degrees); ClassDB::bind_method(D_METHOD("get_skew"), &Node2D::get_skew); - ClassDB::bind_method(D_METHOD("get_skew_degrees"), &Node2D::get_skew_degrees); ClassDB::bind_method(D_METHOD("get_scale"), &Node2D::get_scale); ClassDB::bind_method(D_METHOD("rotate", "radians"), &Node2D::rotate); @@ -426,8 +398,6 @@ void Node2D::_bind_methods() { ClassDB::bind_method(D_METHOD("get_global_position"), &Node2D::get_global_position); ClassDB::bind_method(D_METHOD("set_global_rotation", "radians"), &Node2D::set_global_rotation); ClassDB::bind_method(D_METHOD("get_global_rotation"), &Node2D::get_global_rotation); - ClassDB::bind_method(D_METHOD("set_global_rotation_degrees", "degrees"), &Node2D::set_global_rotation_degrees); - ClassDB::bind_method(D_METHOD("get_global_rotation_degrees"), &Node2D::get_global_rotation_degrees); ClassDB::bind_method(D_METHOD("set_global_scale", "scale"), &Node2D::set_global_scale); ClassDB::bind_method(D_METHOD("get_global_scale"), &Node2D::get_global_scale); @@ -452,17 +422,14 @@ void Node2D::_bind_methods() { ClassDB::bind_method(D_METHOD("get_relative_transform_to_parent", "parent"), &Node2D::get_relative_transform_to_parent); ADD_GROUP("Transform", ""); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "position"), "set_position", "get_position"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "rotation", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_rotation", "get_rotation"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "rotation_degrees", PROPERTY_HINT_RANGE, "-360,360,0.1,or_lesser,or_greater", PROPERTY_USAGE_EDITOR), "set_rotation_degrees", "get_rotation_degrees"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "position", PROPERTY_HINT_RANGE, "-99999,99999,0,or_lesser,or_greater,noslider,suffix:px"), "set_position", "get_position"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "rotation", PROPERTY_HINT_RANGE, "-360,360,0.1,or_lesser,or_greater,radians"), "set_rotation", "get_rotation"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "scale"), "set_scale", "get_scale"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "skew", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_skew", "get_skew"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "skew_degrees", PROPERTY_HINT_RANGE, "-89.9,89.9,0.1", PROPERTY_USAGE_EDITOR), "set_skew_degrees", "get_skew_degrees"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "skew", PROPERTY_HINT_RANGE, "-89.9,89.9,0.1,radians"), "set_skew", "get_skew"); ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM2D, "transform", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_transform", "get_transform"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "global_position", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_global_position", "get_global_position"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "global_rotation", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_global_rotation", "get_global_rotation"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "global_rotation_degrees", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_global_rotation_degrees", "get_global_rotation_degrees"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "global_scale", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_global_scale", "get_global_scale"); ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM2D, "global_transform", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_global_transform", "get_global_transform"); diff --git a/scene/2d/node_2d.h b/scene/2d/node_2d.h index 339efd9179..3e66541e32 100644 --- a/scene/2d/node_2d.h +++ b/scene/2d/node_2d.h @@ -75,9 +75,7 @@ public: void set_position(const Point2 &p_pos); void set_rotation(real_t p_radians); - void set_rotation_degrees(real_t p_degrees); void set_skew(real_t p_radians); - void set_skew_degrees(real_t p_radians); void set_scale(const Size2 &p_scale); void rotate(real_t p_radians); @@ -90,20 +88,16 @@ public: Point2 get_position() const; real_t get_rotation() const; real_t get_skew() const; - real_t get_rotation_degrees() const; - real_t get_skew_degrees() const; Size2 get_scale() const; Point2 get_global_position() const; real_t get_global_rotation() const; - real_t get_global_rotation_degrees() const; Size2 get_global_scale() const; void set_transform(const Transform2D &p_transform); void set_global_transform(const Transform2D &p_transform); void set_global_position(const Point2 &p_pos); void set_global_rotation(real_t p_radians); - void set_global_rotation_degrees(real_t p_degrees); void set_global_scale(const Size2 &p_scale); void set_z_index(int p_z); diff --git a/scene/2d/physical_bone_2d.cpp b/scene/2d/physical_bone_2d.cpp index 0c1be16174..d547914e16 100644 --- a/scene/2d/physical_bone_2d.cpp +++ b/scene/2d/physical_bone_2d.cpp @@ -31,33 +31,37 @@ #include "physical_bone_2d.h" void PhysicalBone2D::_notification(int p_what) { - if (p_what == NOTIFICATION_INTERNAL_PHYSICS_PROCESS) { - // Position the RigidBody in the correct position - if (follow_bone_when_simulating) { - _position_at_bone2d(); - } + switch (p_what) { + case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: { + // Position the RigidBody in the correct position. + if (follow_bone_when_simulating) { + _position_at_bone2d(); + } - // Keep the child joint in the correct position. - if (child_joint && auto_configure_joint) { - child_joint->set_global_position(get_global_position()); - } - } else if (p_what == NOTIFICATION_READY) { - _find_skeleton_parent(); - _find_joint_child(); + // Keep the child joint in the correct position. + if (child_joint && auto_configure_joint) { + child_joint->set_global_position(get_global_position()); + } + } break; - // Configure joint - if (child_joint && auto_configure_joint) { - _auto_configure_joint(); - } + case NOTIFICATION_READY: { + _find_skeleton_parent(); + _find_joint_child(); - // Simulate physics if set - if (simulate_physics) { - _start_physics_simulation(); - } else { - _stop_physics_simulation(); - } + // Configure joint. + if (child_joint && auto_configure_joint) { + _auto_configure_joint(); + } + + // Simulate physics if set. + if (simulate_physics) { + _start_physics_simulation(); + } else { + _stop_physics_simulation(); + } - set_physics_process_internal(true); + set_physics_process_internal(true); + } break; } } @@ -156,16 +160,16 @@ void PhysicalBone2D::_start_physics_simulation() { // Apply the correct mode RigidBody2D::Mode rigid_mode = get_mode(); if (rigid_mode == RigidBody2D::MODE_STATIC) { - PhysicsServer2D::get_singleton()->body_set_mode(get_rid(), PhysicsServer2D::BodyMode::BODY_MODE_STATIC); + set_body_mode(PhysicsServer2D::BODY_MODE_STATIC); } else if (rigid_mode == RigidBody2D::MODE_DYNAMIC) { - PhysicsServer2D::get_singleton()->body_set_mode(get_rid(), PhysicsServer2D::BodyMode::BODY_MODE_DYNAMIC); + set_body_mode(PhysicsServer2D::BODY_MODE_DYNAMIC); } else if (rigid_mode == RigidBody2D::MODE_KINEMATIC) { - PhysicsServer2D::get_singleton()->body_set_mode(get_rid(), PhysicsServer2D::BodyMode::BODY_MODE_KINEMATIC); + set_body_mode(PhysicsServer2D::BODY_MODE_KINEMATIC); } else if (rigid_mode == RigidBody2D::MODE_DYNAMIC_LOCKED) { - PhysicsServer2D::get_singleton()->body_set_mode(get_rid(), PhysicsServer2D::BodyMode::BODY_MODE_DYNAMIC_LOCKED); + set_body_mode(PhysicsServer2D::BODY_MODE_DYNAMIC_LOCKED); } else { - // Default to Rigid - PhysicsServer2D::get_singleton()->body_set_mode(get_rid(), PhysicsServer2D::BodyMode::BODY_MODE_DYNAMIC); + // Default to Dynamic. + set_body_mode(PhysicsServer2D::BODY_MODE_DYNAMIC); } _internal_simulate_physics = true; diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp index ce63b25ce0..be619ed60d 100644 --- a/scene/2d/physics_body_2d.cpp +++ b/scene/2d/physics_body_2d.cpp @@ -49,7 +49,7 @@ void PhysicsBody2D::_bind_methods() { PhysicsBody2D::PhysicsBody2D(PhysicsServer2D::BodyMode p_mode) : CollisionObject2D(PhysicsServer2D::get_singleton()->body_create(), false) { - PhysicsServer2D::get_singleton()->body_set_mode(get_rid(), p_mode); + set_body_mode(p_mode); set_pickable(false); } @@ -64,7 +64,7 @@ Ref<KinematicCollision2D> PhysicsBody2D::_move(const Vector2 &p_motion, bool p_i if (move_and_collide(p_motion, p_infinite_inertia, result, p_margin, p_exclude_raycast_shapes, p_test_only)) { if (motion_cache.is_null()) { - motion_cache.instance(); + motion_cache.instantiate(); motion_cache->owner = this; } @@ -76,13 +76,46 @@ Ref<KinematicCollision2D> PhysicsBody2D::_move(const Vector2 &p_motion, bool p_i return Ref<KinematicCollision2D>(); } -bool PhysicsBody2D::move_and_collide(const Vector2 &p_motion, bool p_infinite_inertia, PhysicsServer2D::MotionResult &r_result, real_t p_margin, bool p_exclude_raycast_shapes, bool p_test_only) { +bool PhysicsBody2D::move_and_collide(const Vector2 &p_motion, bool p_infinite_inertia, PhysicsServer2D::MotionResult &r_result, real_t p_margin, bool p_exclude_raycast_shapes, bool p_test_only, bool p_cancel_sliding) { if (is_only_update_transform_changes_enabled()) { ERR_PRINT("Move functions do not work together with 'sync to physics' option. Please read the documentation."); } Transform2D gt = get_global_transform(); bool colliding = PhysicsServer2D::get_singleton()->body_test_motion(get_rid(), gt, p_motion, p_infinite_inertia, p_margin, &r_result, p_exclude_raycast_shapes); + // Restore direction of motion to be along original motion, + // in order to avoid sliding due to recovery, + // but only if collision depth is low enough to avoid tunneling. + real_t motion_length = p_motion.length(); + if (motion_length > CMP_EPSILON) { + real_t precision = 0.001; + + if (colliding && p_cancel_sliding) { + // Can't just use margin as a threshold because collision depth is calculated on unsafe motion, + // so even in normal resting cases the depth can be a bit more than the margin. + precision += motion_length * (r_result.collision_unsafe_fraction - r_result.collision_safe_fraction); + + if (r_result.collision_depth > (real_t)p_margin + precision) { + p_cancel_sliding = false; + } + } + + if (p_cancel_sliding) { + // Check depth of recovery. + Vector2 motion_normal = p_motion / motion_length; + real_t dot = r_result.motion.dot(motion_normal); + Vector2 recovery = r_result.motion - motion_normal * dot; + real_t recovery_length = recovery.length(); + // Fixes cases where canceling slide causes the motion to go too deep into the ground, + // Becauses we're only taking rest information into account and not general recovery. + if (recovery_length < (real_t)p_margin + precision) { + // Apply adjustment to motion. + r_result.motion = motion_normal * dot; + r_result.remainder = p_motion - r_result.motion; + } + } + } + if (!p_test_only) { gt.elements[2] += r_result.motion; set_global_transform(gt); @@ -186,9 +219,9 @@ void StaticBody2D::set_kinematic_motion_enabled(bool p_enabled) { kinematic_motion = p_enabled; if (kinematic_motion) { - PhysicsServer2D::get_singleton()->body_set_mode(get_rid(), PhysicsServer2D::BODY_MODE_KINEMATIC); + set_body_mode(PhysicsServer2D::BODY_MODE_KINEMATIC); } else { - PhysicsServer2D::get_singleton()->body_set_mode(get_rid(), PhysicsServer2D::BODY_MODE_STATIC); + set_body_mode(PhysicsServer2D::BODY_MODE_STATIC); } _update_kinematic_motion(); @@ -199,28 +232,30 @@ bool StaticBody2D::is_kinematic_motion_enabled() const { } void StaticBody2D::_notification(int p_what) { - if (p_what == NOTIFICATION_INTERNAL_PHYSICS_PROCESS) { + switch (p_what) { + case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: { #ifdef TOOLS_ENABLED - if (Engine::get_singleton()->is_editor_hint()) { - return; - } + if (Engine::get_singleton()->is_editor_hint()) { + return; + } #endif - ERR_FAIL_COND(!kinematic_motion); + ERR_FAIL_COND(!kinematic_motion); - real_t delta_time = get_physics_process_delta_time(); + real_t delta_time = get_physics_process_delta_time(); - Transform2D new_transform = get_global_transform(); + Transform2D new_transform = get_global_transform(); - new_transform.translate(constant_linear_velocity * delta_time); - new_transform.set_rotation(new_transform.get_rotation() + constant_angular_velocity * delta_time); + new_transform.translate(constant_linear_velocity * delta_time); + new_transform.set_rotation(new_transform.get_rotation() + constant_angular_velocity * delta_time); - PhysicsServer2D::get_singleton()->body_set_state(get_rid(), PhysicsServer2D::BODY_STATE_TRANSFORM, new_transform); + PhysicsServer2D::get_singleton()->body_set_state(get_rid(), PhysicsServer2D::BODY_STATE_TRANSFORM, new_transform); - // Propagate transform change to node. - set_block_transform_notify(true); - set_global_transform(new_transform); - set_block_transform_notify(false); + // Propagate transform change to node. + set_block_transform_notify(true); + set_global_transform(new_transform); + set_block_transform_notify(false); + } break; } } @@ -495,18 +530,18 @@ void RigidBody2D::set_mode(Mode p_mode) { mode = p_mode; switch (p_mode) { case MODE_DYNAMIC: { - PhysicsServer2D::get_singleton()->body_set_mode(get_rid(), PhysicsServer2D::BODY_MODE_DYNAMIC); + set_body_mode(PhysicsServer2D::BODY_MODE_DYNAMIC); } break; case MODE_STATIC: { - PhysicsServer2D::get_singleton()->body_set_mode(get_rid(), PhysicsServer2D::BODY_MODE_STATIC); + set_body_mode(PhysicsServer2D::BODY_MODE_STATIC); } break; case MODE_KINEMATIC: { - PhysicsServer2D::get_singleton()->body_set_mode(get_rid(), PhysicsServer2D::BODY_MODE_KINEMATIC); + set_body_mode(PhysicsServer2D::BODY_MODE_KINEMATIC); } break; case MODE_DYNAMIC_LOCKED: { - PhysicsServer2D::get_singleton()->body_set_mode(get_rid(), PhysicsServer2D::BODY_MODE_DYNAMIC_LOCKED); + set_body_mode(PhysicsServer2D::BODY_MODE_DYNAMIC_LOCKED); } break; } @@ -762,18 +797,19 @@ bool RigidBody2D::is_contact_monitor_enabled() const { void RigidBody2D::_notification(int p_what) { #ifdef TOOLS_ENABLED - if (p_what == NOTIFICATION_ENTER_TREE) { - if (Engine::get_singleton()->is_editor_hint()) { - set_notify_local_transform(true); //used for warnings and only in editor - } - } + switch (p_what) { + case NOTIFICATION_ENTER_TREE: { + if (Engine::get_singleton()->is_editor_hint()) { + set_notify_local_transform(true); //used for warnings and only in editor + } + } break; - if (p_what == NOTIFICATION_LOCAL_TRANSFORM_CHANGED) { - if (Engine::get_singleton()->is_editor_hint()) { - update_configuration_warnings(); - } + case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: { + if (Engine::get_singleton()->is_editor_hint()) { + update_configuration_warnings(); + } + } break; } - #endif } @@ -855,8 +891,8 @@ void RigidBody2D::_bind_methods() { BIND_VMETHOD(MethodInfo("_integrate_forces", PropertyInfo(Variant::OBJECT, "state", PROPERTY_HINT_RESOURCE_TYPE, "PhysicsDirectBodyState2D"))); ADD_PROPERTY(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Dynamic,Static,DynamicLocked,Kinematic"), "set_mode", "get_mode"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "mass", PROPERTY_HINT_EXP_RANGE, "0.01,65535,0.01"), "set_mass", "get_mass"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "inertia", PROPERTY_HINT_EXP_RANGE, "0.01,65535,0.01", PROPERTY_USAGE_NONE), "set_inertia", "get_inertia"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "mass", PROPERTY_HINT_RANGE, "0.01,65535,0.01,exp"), "set_mass", "get_mass"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "inertia", PROPERTY_HINT_RANGE, "0.01,65535,0.01,exp", PROPERTY_USAGE_NONE), "set_inertia", "get_inertia"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "physics_material_override", PROPERTY_HINT_RESOURCE_TYPE, "PhysicsMaterial"), "set_physics_material_override", "get_physics_material_override"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "gravity_scale", PROPERTY_HINT_RANGE, "-128,128,0.01"), "set_gravity_scale", "get_gravity_scale"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "custom_integrator"), "set_use_custom_integrator", "is_using_custom_integrator"); @@ -942,15 +978,16 @@ void CharacterBody2D::move_and_slide() { floor_normal = Vector2(); floor_velocity = Vector2(); - int slide_count = max_slides; - while (slide_count) { + // No sliding on first attempt to keep floor motion stable when possible. + bool sliding_enabled = false; + for (int iteration = 0; iteration < max_slides; ++iteration) { PhysicsServer2D::MotionResult result; bool found_collision = false; for (int i = 0; i < 2; ++i) { bool collided; if (i == 0) { //collide - collided = move_and_collide(motion, infinite_inertia, result, margin); + collided = move_and_collide(motion, infinite_inertia, result, margin, true, false, !sliding_enabled); if (!collided) { motion = Vector2(); //clear because no collision happened and motion completed } @@ -966,7 +1003,6 @@ void CharacterBody2D::move_and_slide() { found_collision = true; motion_results.push_back(result); - motion = result.remainder; if (up_direction == Vector2()) { //all is a wall @@ -980,7 +1016,7 @@ void CharacterBody2D::move_and_slide() { floor_velocity = result.collider_velocity; if (stop_on_slope) { - if ((body_velocity_normal + up_direction).length() < 0.01 && result.motion.length() < 1) { + if ((body_velocity_normal + up_direction).length() < 0.01) { Transform2D gt = get_global_transform(); gt.elements[2] -= result.motion.slide(up_direction); set_global_transform(gt); @@ -995,16 +1031,20 @@ void CharacterBody2D::move_and_slide() { } } - motion = motion.slide(result.collision_normal); - linear_velocity = linear_velocity.slide(result.collision_normal); + if (sliding_enabled || !on_floor) { + motion = result.remainder.slide(result.collision_normal); + linear_velocity = linear_velocity.slide(result.collision_normal); + } else { + motion = result.remainder; + } } + + sliding_enabled = true; } if (!found_collision || motion == Vector2()) { break; } - - --slide_count; } if (!was_on_floor || snap == Vector2()) { @@ -1120,7 +1160,7 @@ Ref<KinematicCollision2D> CharacterBody2D::_get_slide_collision(int p_bounce) { } if (slide_colliders[p_bounce].is_null()) { - slide_colliders.write[p_bounce].instance(); + slide_colliders.write[p_bounce].instantiate(); slide_colliders.write[p_bounce]->owner = this; } @@ -1207,14 +1247,6 @@ void CharacterBody2D::set_floor_max_angle(real_t p_radians) { floor_max_angle = p_radians; } -real_t CharacterBody2D::get_floor_max_angle_degrees() const { - return Math::rad2deg(floor_max_angle); -} - -void CharacterBody2D::set_floor_max_angle_degrees(real_t p_degrees) { - floor_max_angle = Math::deg2rad(p_degrees); -} - const Vector2 &CharacterBody2D::get_snap() const { return snap; } @@ -1232,26 +1264,28 @@ void CharacterBody2D::set_up_direction(const Vector2 &p_up_direction) { } void CharacterBody2D::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE) { - last_valid_transform = get_global_transform(); - - // Reset move_and_slide() data. - on_floor = false; - on_floor_body = RID(); - on_ceiling = false; - on_wall = false; - motion_results.clear(); - floor_velocity = Vector2(); - } + switch (p_what) { + case NOTIFICATION_ENTER_TREE: { + last_valid_transform = get_global_transform(); + + // Reset move_and_slide() data. + on_floor = false; + on_floor_body = RID(); + on_ceiling = false; + on_wall = false; + motion_results.clear(); + floor_velocity = Vector2(); + } break; - if (p_what == NOTIFICATION_LOCAL_TRANSFORM_CHANGED) { - //used by sync to physics, send the new transform to the physics - Transform2D new_transform = get_global_transform(); - PhysicsServer2D::get_singleton()->body_set_state(get_rid(), PhysicsServer2D::BODY_STATE_TRANSFORM, new_transform); - //but then revert changes - set_notify_local_transform(false); - set_global_transform(last_valid_transform); - set_notify_local_transform(true); + case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: { + // Used by sync to physics, send the new transform to the physics. + Transform2D new_transform = get_global_transform(); + PhysicsServer2D::get_singleton()->body_set_state(get_rid(), PhysicsServer2D::BODY_STATE_TRANSFORM, new_transform); + // But then revert changes. + set_notify_local_transform(false); + set_global_transform(last_valid_transform); + set_notify_local_transform(true); + } break; } } @@ -1271,8 +1305,6 @@ void CharacterBody2D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_max_slides", "max_slides"), &CharacterBody2D::set_max_slides); ClassDB::bind_method(D_METHOD("get_floor_max_angle"), &CharacterBody2D::get_floor_max_angle); ClassDB::bind_method(D_METHOD("set_floor_max_angle", "radians"), &CharacterBody2D::set_floor_max_angle); - ClassDB::bind_method(D_METHOD("get_floor_max_angle_degrees"), &CharacterBody2D::get_floor_max_angle_degrees); - ClassDB::bind_method(D_METHOD("set_floor_max_angle_degrees", "degrees"), &CharacterBody2D::set_floor_max_angle_degrees); ClassDB::bind_method(D_METHOD("get_snap"), &CharacterBody2D::get_snap); ClassDB::bind_method(D_METHOD("set_snap", "snap"), &CharacterBody2D::set_snap); ClassDB::bind_method(D_METHOD("get_up_direction"), &CharacterBody2D::get_up_direction); @@ -1293,8 +1325,7 @@ void CharacterBody2D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "stop_on_slope"), "set_stop_on_slope_enabled", "is_stop_on_slope_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "infinite_inertia"), "set_infinite_inertia_enabled", "is_infinite_inertia_enabled"); ADD_PROPERTY(PropertyInfo(Variant::INT, "max_slides"), "set_max_slides", "get_max_slides"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "floor_max_angle", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_floor_max_angle", "get_floor_max_angle"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "floor_max_angle_degrees", PROPERTY_HINT_RANGE, "0,180,0.1", PROPERTY_USAGE_EDITOR), "set_floor_max_angle_degrees", "get_floor_max_angle_degrees"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "floor_max_angle", PROPERTY_HINT_RANGE, "0,180,0.1"), "set_floor_max_angle", "get_floor_max_angle"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "snap"), "set_snap", "get_snap"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "up_direction"), "set_up_direction", "get_up_direction"); diff --git a/scene/2d/physics_body_2d.h b/scene/2d/physics_body_2d.h index f084a247aa..5a5417eaf3 100644 --- a/scene/2d/physics_body_2d.h +++ b/scene/2d/physics_body_2d.h @@ -50,7 +50,7 @@ protected: Ref<KinematicCollision2D> _move(const Vector2 &p_motion, bool p_infinite_inertia = true, bool p_exclude_raycast_shapes = true, bool p_test_only = false, real_t p_margin = 0.08); public: - bool move_and_collide(const Vector2 &p_motion, bool p_infinite_inertia, PhysicsServer2D::MotionResult &r_result, real_t p_margin, bool p_exclude_raycast_shapes = true, bool p_test_only = false); + bool move_and_collide(const Vector2 &p_motion, bool p_infinite_inertia, PhysicsServer2D::MotionResult &r_result, real_t p_margin, bool p_exclude_raycast_shapes = true, bool p_test_only = false, bool p_cancel_sliding = true); bool test_move(const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia = true, bool p_exclude_raycast_shapes = true, const Ref<KinematicCollision2D> &r_collision = Ref<KinematicCollision2D>(), real_t p_margin = 0.08); TypedArray<PhysicsBody2D> get_collision_exceptions(); @@ -303,9 +303,6 @@ private: real_t get_floor_max_angle() const; void set_floor_max_angle(real_t p_radians); - real_t get_floor_max_angle_degrees() const; - void set_floor_max_angle_degrees(real_t p_degrees); - const Vector2 &get_snap() const; void set_snap(const Vector2 &p_snap); diff --git a/scene/2d/polygon_2d.cpp b/scene/2d/polygon_2d.cpp index 1eec2a3833..7366be5a7d 100644 --- a/scene/2d/polygon_2d.cpp +++ b/scene/2d/polygon_2d.cpp @@ -365,7 +365,7 @@ void Polygon2D::_notification(int p_what) { arr[RS::ARRAY_INDEX] = index_array; RS::get_singleton()->mesh_add_surface_from_arrays(mesh, RS::PRIMITIVE_TRIANGLES, arr, Array(), Dictionary(), RS::ARRAY_FLAG_USE_2D_VERTICES); - RS::get_singleton()->canvas_item_add_mesh(get_canvas_item(), mesh, Transform2D(), Color(), texture.is_valid() ? texture->get_rid() : RID()); + RS::get_singleton()->canvas_item_add_mesh(get_canvas_item(), mesh, Transform2D(), Color(1, 1, 1), texture.is_valid() ? texture->get_rid() : RID()); } } break; @@ -462,14 +462,6 @@ real_t Polygon2D::get_texture_rotation() const { return tex_rot; } -void Polygon2D::set_texture_rotation_degrees(real_t p_rot) { - set_texture_rotation(Math::deg2rad(p_rot)); -} - -real_t Polygon2D::get_texture_rotation_degrees() const { - return Math::rad2deg(get_texture_rotation()); -} - void Polygon2D::set_texture_scale(const Size2 &p_scale) { tex_scale = p_scale; update(); @@ -613,9 +605,6 @@ void Polygon2D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_texture_rotation", "texture_rotation"), &Polygon2D::set_texture_rotation); ClassDB::bind_method(D_METHOD("get_texture_rotation"), &Polygon2D::get_texture_rotation); - ClassDB::bind_method(D_METHOD("set_texture_rotation_degrees", "texture_rotation"), &Polygon2D::set_texture_rotation_degrees); - ClassDB::bind_method(D_METHOD("get_texture_rotation_degrees"), &Polygon2D::get_texture_rotation_degrees); - ClassDB::bind_method(D_METHOD("set_texture_scale", "texture_scale"), &Polygon2D::set_texture_scale); ClassDB::bind_method(D_METHOD("get_texture_scale"), &Polygon2D::get_texture_scale); @@ -657,8 +646,7 @@ void Polygon2D::_bind_methods() { ADD_GROUP("Texture2D", "texture_"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "texture_offset"), "set_texture_offset", "get_texture_offset"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "texture_scale"), "set_texture_scale", "get_texture_scale"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "texture_rotation_degrees", PROPERTY_HINT_RANGE, "-360,360,0.1,or_lesser,or_greater"), "set_texture_rotation_degrees", "get_texture_rotation_degrees"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "texture_rotation", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_texture_rotation", "get_texture_rotation"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "texture_rotation", PROPERTY_HINT_RANGE, "-360,360,0.1,or_lesser,or_greater,radians"), "set_texture_rotation", "get_texture_rotation"); ADD_GROUP("Skeleton", ""); ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "skeleton", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Skeleton2D"), "set_skeleton", "get_skeleton"); diff --git a/scene/2d/polygon_2d.h b/scene/2d/polygon_2d.h index f9f36ff9a2..bf386b9ace 100644 --- a/scene/2d/polygon_2d.h +++ b/scene/2d/polygon_2d.h @@ -120,9 +120,6 @@ public: void set_texture_rotation(real_t p_rot); real_t get_texture_rotation() const; - void set_texture_rotation_degrees(real_t p_rot); - real_t get_texture_rotation_degrees() const; - void set_texture_scale(const Size2 &p_scale); Size2 get_texture_scale() const; diff --git a/scene/2d/remote_transform_2d.cpp b/scene/2d/remote_transform_2d.cpp index a7613dc009..e7cef965fe 100644 --- a/scene/2d/remote_transform_2d.cpp +++ b/scene/2d/remote_transform_2d.cpp @@ -35,7 +35,7 @@ void RemoteTransform2D::_update_cache() { cache = ObjectID(); if (has_node(remote_node)) { Node *node = get_node(remote_node); - if (!node || this == node || node->is_a_parent_of(this) || this->is_a_parent_of(node)) { + if (!node || this == node || node->is_ancestor_of(this) || this->is_ancestor_of(node)) { return; } diff --git a/scene/2d/touch_screen_button.cpp b/scene/2d/touch_screen_button.cpp index 4e58984b37..0a6393551c 100644 --- a/scene/2d/touch_screen_button.cpp +++ b/scene/2d/touch_screen_button.cpp @@ -288,7 +288,7 @@ void TouchScreenButton::_press(int p_finger_pressed) { if (action != StringName()) { Input::get_singleton()->action_press(action); Ref<InputEventAction> iea; - iea.instance(); + iea.instantiate(); iea->set_action(action); iea->set_pressed(true); get_viewport()->input(iea, true); @@ -305,7 +305,7 @@ void TouchScreenButton::_release(bool p_exiting_tree) { Input::get_singleton()->action_release(action); if (!p_exiting_tree) { Ref<InputEventAction> iea; - iea.instance(); + iea.instantiate(); iea->set_action(action); iea->set_pressed(false); get_viewport()->input(iea, true); diff --git a/scene/3d/area_3d.cpp b/scene/3d/area_3d.cpp index 44708cddff..cd64a813dd 100644 --- a/scene/3d/area_3d.cpp +++ b/scene/3d/area_3d.cpp @@ -601,7 +601,7 @@ void Area3D::_bind_methods() { ADD_GROUP("Physics Overrides", ""); ADD_PROPERTY(PropertyInfo(Variant::INT, "space_override", PROPERTY_HINT_ENUM, "Disabled,Combine,Combine-Replace,Replace,Replace-Combine"), "set_space_override_mode", "get_space_override_mode"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gravity_point"), "set_gravity_is_point", "is_gravity_a_point"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "gravity_distance_scale", PROPERTY_HINT_EXP_RANGE, "0,1024,0.001,or_greater"), "set_gravity_distance_scale", "get_gravity_distance_scale"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "gravity_distance_scale", PROPERTY_HINT_RANGE, "0,1024,0.001,or_greater,exp"), "set_gravity_distance_scale", "get_gravity_distance_scale"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "gravity_vec"), "set_gravity_vector", "get_gravity_vector"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "gravity", PROPERTY_HINT_RANGE, "-32,32,0.001,or_lesser,or_greater"), "set_gravity", "get_gravity"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "linear_damp", PROPERTY_HINT_RANGE, "0,100,0.001,or_greater"), "set_linear_damp", "get_linear_damp"); diff --git a/scene/3d/audio_stream_player_3d.cpp b/scene/3d/audio_stream_player_3d.cpp index 9640043031..ba559b4ecb 100644 --- a/scene/3d/audio_stream_player_3d.cpp +++ b/scene/3d/audio_stream_player_3d.cpp @@ -967,13 +967,13 @@ void AudioStreamPlayer3D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "playing", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "_set_playing", "is_playing"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "autoplay"), "set_autoplay", "is_autoplay_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "stream_paused", PROPERTY_HINT_NONE, ""), "set_stream_paused", "get_stream_paused"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "max_distance", PROPERTY_HINT_EXP_RANGE, "0,4096,1,or_greater"), "set_max_distance", "get_max_distance"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "max_distance", PROPERTY_HINT_RANGE, "0,4096,1,or_greater,exp"), "set_max_distance", "get_max_distance"); ADD_PROPERTY(PropertyInfo(Variant::INT, "out_of_range_mode", PROPERTY_HINT_ENUM, "Mix,Pause"), "set_out_of_range_mode", "get_out_of_range_mode"); ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "bus", PROPERTY_HINT_ENUM, ""), "set_bus", "get_bus"); ADD_PROPERTY(PropertyInfo(Variant::INT, "area_mask", PROPERTY_HINT_LAYERS_2D_PHYSICS), "set_area_mask", "get_area_mask"); ADD_GROUP("Emission Angle", "emission_angle"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "emission_angle_enabled"), "set_emission_angle_enabled", "is_emission_angle_enabled"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "emission_angle_degrees", PROPERTY_HINT_RANGE, "0.1,90,0.1"), "set_emission_angle", "get_emission_angle"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "emission_angle_degrees", PROPERTY_HINT_RANGE, "0.1,90,0.1,degrees"), "set_emission_angle", "get_emission_angle"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "emission_angle_filter_attenuation_db", PROPERTY_HINT_RANGE, "-80,0,0.1"), "set_emission_angle_filter_attenuation_db", "get_emission_angle_filter_attenuation_db"); ADD_GROUP("Attenuation Filter", "attenuation_filter_"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "attenuation_filter_cutoff_hz", PROPERTY_HINT_RANGE, "1,20500,1"), "set_attenuation_filter_cutoff_hz", "get_attenuation_filter_cutoff_hz"); @@ -997,7 +997,7 @@ void AudioStreamPlayer3D::_bind_methods() { } AudioStreamPlayer3D::AudioStreamPlayer3D() { - velocity_tracker.instance(); + velocity_tracker.instantiate(); AudioServer::get_singleton()->connect("bus_layout_changed", callable_mp(this, &AudioStreamPlayer3D::_bus_layout_changed)); set_disable_scale(true); } diff --git a/scene/3d/camera_3d.cpp b/scene/3d/camera_3d.cpp index 62bbebe6e7..1ed8c0b4eb 100644 --- a/scene/3d/camera_3d.cpp +++ b/scene/3d/camera_3d.cpp @@ -513,11 +513,11 @@ void Camera3D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "doppler_tracking", PROPERTY_HINT_ENUM, "Disabled,Idle,Physics"), "set_doppler_tracking", "get_doppler_tracking"); ADD_PROPERTY(PropertyInfo(Variant::INT, "projection", PROPERTY_HINT_ENUM, "Perspective,Orthogonal,Frustum"), "set_projection", "get_projection"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "current"), "set_current", "is_current"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "fov", PROPERTY_HINT_RANGE, "1,179,0.1"), "set_fov", "get_fov"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "fov", PROPERTY_HINT_RANGE, "1,179,0.1,degrees"), "set_fov", "get_fov"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "size", PROPERTY_HINT_RANGE, "0.1,16384,0.01"), "set_size", "get_size"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "frustum_offset"), "set_frustum_offset", "get_frustum_offset"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "near", PROPERTY_HINT_EXP_RANGE, "0.001,10,0.001,or_greater"), "set_near", "get_near"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "far", PROPERTY_HINT_EXP_RANGE, "0.01,4000,0.01,or_greater"), "set_far", "get_far"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "near", PROPERTY_HINT_RANGE, "0.001,10,0.001,or_greater,exp"), "set_near", "get_near"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "far", PROPERTY_HINT_RANGE, "0.01,4000,0.01,or_greater,exp"), "set_far", "get_far"); BIND_ENUM_CONSTANT(PROJECTION_PERSPECTIVE); BIND_ENUM_CONSTANT(PROJECTION_ORTHOGONAL); @@ -661,7 +661,7 @@ Camera3D::Camera3D() { set_perspective(75.0, 0.05, 4000.0); RenderingServer::get_singleton()->camera_set_cull_mask(camera, layers); //active=false; - velocity_tracker.instance(); + velocity_tracker.instantiate(); set_notify_transform(true); set_disable_scale(true); } diff --git a/scene/3d/collision_object_3d.cpp b/scene/3d/collision_object_3d.cpp index a04667e53b..40e3f7c764 100644 --- a/scene/3d/collision_object_3d.cpp +++ b/scene/3d/collision_object_3d.cpp @@ -32,7 +32,6 @@ #include "core/config/engine.h" #include "scene/scene_string_names.h" -#include "servers/physics_server_3d.h" void CollisionObject3D::_notification(int p_what) { switch (p_what) { @@ -59,15 +58,22 @@ void CollisionObject3D::_notification(int p_what) { PhysicsServer3D::get_singleton()->body_set_state(rid, PhysicsServer3D::BODY_STATE_TRANSFORM, get_global_transform()); } - RID space = get_world_3d()->get_space(); - if (area) { - PhysicsServer3D::get_singleton()->area_set_space(rid, space); - } else { - PhysicsServer3D::get_singleton()->body_set_space(rid, space); + bool disabled = !is_enabled(); + + if (disabled && (disable_mode != DISABLE_MODE_REMOVE)) { + _apply_disabled(); + } + + if (!disabled || (disable_mode != DISABLE_MODE_REMOVE)) { + RID space = get_world_3d()->get_space(); + if (area) { + PhysicsServer3D::get_singleton()->area_set_space(rid, space); + } else { + PhysicsServer3D::get_singleton()->body_set_space(rid, space); + } } _update_pickable(); - //get space } break; case NOTIFICATION_TRANSFORM_CHANGED: { @@ -78,19 +84,34 @@ void CollisionObject3D::_notification(int p_what) { } _on_transform_changed(); - } break; + case NOTIFICATION_VISIBILITY_CHANGED: { _update_pickable(); - } break; + case NOTIFICATION_EXIT_WORLD: { - if (area) { - PhysicsServer3D::get_singleton()->area_set_space(rid, RID()); - } else { - PhysicsServer3D::get_singleton()->body_set_space(rid, RID()); + bool disabled = !is_enabled(); + + if (!disabled || (disable_mode != DISABLE_MODE_REMOVE)) { + if (area) { + PhysicsServer3D::get_singleton()->area_set_space(rid, RID()); + } else { + PhysicsServer3D::get_singleton()->body_set_space(rid, RID()); + } + } + + if (disabled && (disable_mode != DISABLE_MODE_REMOVE)) { + _apply_enabled(); } + } break; + case NOTIFICATION_DISABLED: { + _apply_disabled(); + } break; + + case NOTIFICATION_ENABLED: { + _apply_enabled(); } break; } } @@ -153,6 +174,79 @@ bool CollisionObject3D::get_collision_mask_bit(int p_bit) const { return get_collision_mask() & (1 << p_bit); } +void CollisionObject3D::set_disable_mode(DisableMode p_mode) { + if (disable_mode == p_mode) { + return; + } + + bool disabled = is_inside_tree() && !is_enabled(); + + if (disabled) { + // Cancel previous disable mode. + _apply_enabled(); + } + + disable_mode = p_mode; + + if (disabled) { + // Apply new disable mode. + _apply_disabled(); + } +} + +CollisionObject3D::DisableMode CollisionObject3D::get_disable_mode() const { + return disable_mode; +} + +void CollisionObject3D::_apply_disabled() { + switch (disable_mode) { + case DISABLE_MODE_REMOVE: { + if (is_inside_tree()) { + if (area) { + PhysicsServer3D::get_singleton()->area_set_space(rid, RID()); + } else { + PhysicsServer3D::get_singleton()->body_set_space(rid, RID()); + } + } + } break; + + case DISABLE_MODE_MAKE_STATIC: { + if (!area && (body_mode != PhysicsServer3D::BODY_MODE_STATIC)) { + PhysicsServer3D::get_singleton()->body_set_mode(rid, PhysicsServer3D::BODY_MODE_STATIC); + } + } break; + + case DISABLE_MODE_KEEP_ACTIVE: { + // Nothing to do. + } break; + } +} + +void CollisionObject3D::_apply_enabled() { + switch (disable_mode) { + case DISABLE_MODE_REMOVE: { + if (is_inside_tree()) { + RID space = get_world_3d()->get_space(); + if (area) { + PhysicsServer3D::get_singleton()->area_set_space(rid, space); + } else { + PhysicsServer3D::get_singleton()->body_set_space(rid, space); + } + } + } break; + + case DISABLE_MODE_MAKE_STATIC: { + if (!area && (body_mode != PhysicsServer3D::BODY_MODE_STATIC)) { + PhysicsServer3D::get_singleton()->body_set_mode(rid, body_mode); + } + } break; + + case DISABLE_MODE_KEEP_ACTIVE: { + // Nothing to do. + } break; + } +} + void CollisionObject3D::_input_event(Node *p_camera, const Ref<InputEvent> &p_input_event, const Vector3 &p_pos, const Vector3 &p_normal, int p_shape) { if (get_script_instance()) { get_script_instance()->call(SceneStringNames::get_singleton()->_input_event, p_camera, p_input_event, p_pos, p_normal, p_shape); @@ -174,6 +268,22 @@ void CollisionObject3D::_mouse_exit() { emit_signal(SceneStringNames::get_singleton()->mouse_exited); } +void CollisionObject3D::set_body_mode(PhysicsServer3D::BodyMode p_mode) { + ERR_FAIL_COND(area); + + if (body_mode == p_mode) { + return; + } + + body_mode = p_mode; + + if (is_inside_tree() && !is_enabled() && (disable_mode == DISABLE_MODE_MAKE_STATIC)) { + return; + } + + PhysicsServer3D::get_singleton()->body_set_mode(rid, p_mode); +} + void CollisionObject3D::_update_pickable() { if (!is_inside_tree()) { return; @@ -305,6 +415,8 @@ void CollisionObject3D::_bind_methods() { ClassDB::bind_method(D_METHOD("get_collision_layer_bit", "bit"), &CollisionObject3D::get_collision_layer_bit); ClassDB::bind_method(D_METHOD("set_collision_mask_bit", "bit", "value"), &CollisionObject3D::set_collision_mask_bit); ClassDB::bind_method(D_METHOD("get_collision_mask_bit", "bit"), &CollisionObject3D::get_collision_mask_bit); + ClassDB::bind_method(D_METHOD("set_disable_mode", "mode"), &CollisionObject3D::set_disable_mode); + ClassDB::bind_method(D_METHOD("get_disable_mode"), &CollisionObject3D::get_disable_mode); ClassDB::bind_method(D_METHOD("set_ray_pickable", "ray_pickable"), &CollisionObject3D::set_ray_pickable); ClassDB::bind_method(D_METHOD("is_ray_pickable"), &CollisionObject3D::is_ray_pickable); ClassDB::bind_method(D_METHOD("set_capture_input_on_drag", "enable"), &CollisionObject3D::set_capture_input_on_drag); @@ -332,6 +444,8 @@ void CollisionObject3D::_bind_methods() { ADD_SIGNAL(MethodInfo("mouse_entered")); ADD_SIGNAL(MethodInfo("mouse_exited")); + ADD_PROPERTY(PropertyInfo(Variant::INT, "disable_mode", PROPERTY_HINT_ENUM, "Remove,MakeStatic,KeepActive"), "set_disable_mode", "get_disable_mode"); + ADD_GROUP("Collision", "collision_"); ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_layer", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_layer", "get_collision_layer"); ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask"); @@ -339,6 +453,10 @@ void CollisionObject3D::_bind_methods() { ADD_GROUP("Input", "input_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "input_ray_pickable"), "set_ray_pickable", "is_ray_pickable"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "input_capture_on_drag"), "set_capture_input_on_drag", "get_capture_input_on_drag"); + + BIND_ENUM_CONSTANT(DISABLE_MODE_REMOVE); + BIND_ENUM_CONSTANT(DISABLE_MODE_MAKE_STATIC); + BIND_ENUM_CONSTANT(DISABLE_MODE_KEEP_ACTIVE); } uint32_t CollisionObject3D::create_shape_owner(Object *p_owner) { @@ -540,8 +658,8 @@ CollisionObject3D::CollisionObject3D(RID p_rid, bool p_area) { PhysicsServer3D::get_singleton()->area_attach_object_instance_id(rid, get_instance_id()); } else { PhysicsServer3D::get_singleton()->body_attach_object_instance_id(rid, get_instance_id()); + PhysicsServer3D::get_singleton()->body_set_mode(rid, body_mode); } - //set_transform_notify(true); } void CollisionObject3D::set_capture_input_on_drag(bool p_capture) { diff --git a/scene/3d/collision_object_3d.h b/scene/3d/collision_object_3d.h index 50a9b4fcd0..a3a890db75 100644 --- a/scene/3d/collision_object_3d.h +++ b/scene/3d/collision_object_3d.h @@ -33,10 +33,19 @@ #include "scene/3d/node_3d.h" #include "scene/resources/shape_3d.h" +#include "servers/physics_server_3d.h" class CollisionObject3D : public Node3D { GDCLASS(CollisionObject3D, Node3D); +public: + enum DisableMode { + DISABLE_MODE_REMOVE, + DISABLE_MODE_MAKE_STATIC, + DISABLE_MODE_KEEP_ACTIVE, + }; + +private: uint32_t collision_layer = 1; uint32_t collision_mask = 1; @@ -44,6 +53,10 @@ class CollisionObject3D : public Node3D { RID rid; + DisableMode disable_mode = DISABLE_MODE_REMOVE; + + PhysicsServer3D::BodyMode body_mode = PhysicsServer3D::BODY_MODE_STATIC; + struct ShapeData { Object *owner = nullptr; Transform3D xform; @@ -76,6 +89,9 @@ class CollisionObject3D : public Node3D { void _update_debug_shapes(); void _clear_debug_shapes(); + void _apply_disabled(); + void _apply_enabled(); + protected: CollisionObject3D(RID p_rid, bool p_area); @@ -89,6 +105,8 @@ protected: virtual void _mouse_enter(); virtual void _mouse_exit(); + void set_body_mode(PhysicsServer3D::BodyMode p_mode); + public: void set_collision_layer(uint32_t p_layer); uint32_t get_collision_layer() const; @@ -102,6 +120,9 @@ public: void set_collision_mask_bit(int p_bit, bool p_value); bool get_collision_mask_bit(int p_bit) const; + void set_disable_mode(DisableMode p_mode); + DisableMode get_disable_mode() const; + uint32_t create_shape_owner(Object *p_owner); void remove_shape_owner(uint32_t owner); void get_shape_owners(List<uint32_t> *r_owners); @@ -138,4 +159,6 @@ public: ~CollisionObject3D(); }; +VARIANT_ENUM_CAST(CollisionObject3D::DisableMode); + #endif // COLLISION_OBJECT__H diff --git a/scene/3d/cpu_particles_3d.cpp b/scene/3d/cpu_particles_3d.cpp index 2301fef651..6dc865ec0e 100644 --- a/scene/3d/cpu_particles_3d.cpp +++ b/scene/3d/cpu_particles_3d.cpp @@ -435,27 +435,27 @@ Vector3 CPUParticles3D::get_gravity() const { void CPUParticles3D::_validate_property(PropertyInfo &property) const { if (property.name == "color" && color_ramp.is_valid()) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } if (property.name == "emission_sphere_radius" && emission_shape != EMISSION_SHAPE_SPHERE) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } if (property.name == "emission_box_extents" && emission_shape != EMISSION_SHAPE_BOX) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } if ((property.name == "emission_point_texture" || property.name == "emission_color_texture") && (emission_shape < EMISSION_SHAPE_POINTS)) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } if (property.name == "emission_normals" && emission_shape != EMISSION_SHAPE_DIRECTED_POINTS) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } if (property.name.begins_with("orbit_") && !particle_flags[PARTICLE_FLAG_DISABLE_Z]) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } } @@ -1273,11 +1273,11 @@ void CPUParticles3D::_bind_methods() { ClassDB::bind_method(D_METHOD("restart"), &CPUParticles3D::restart); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "emitting"), "set_emitting", "is_emitting"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "amount", PROPERTY_HINT_EXP_RANGE, "1,1000000,1"), "set_amount", "get_amount"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "amount", PROPERTY_HINT_RANGE, "1,1000000,1,exp"), "set_amount", "get_amount"); ADD_GROUP("Time", ""); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "lifetime", PROPERTY_HINT_EXP_RANGE, "0.01,600.0,0.01,or_greater"), "set_lifetime", "get_lifetime"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "lifetime", PROPERTY_HINT_RANGE, "0.01,600.0,0.01,or_greater,exp"), "set_lifetime", "get_lifetime"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "one_shot"), "set_one_shot", "get_one_shot"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "preprocess", PROPERTY_HINT_EXP_RANGE, "0.00,600.0,0.01"), "set_pre_process_time", "get_pre_process_time"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "preprocess", PROPERTY_HINT_RANGE, "0.00,600.0,0.01,exp"), "set_pre_process_time", "get_pre_process_time"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "speed_scale", PROPERTY_HINT_RANGE, "0,64,0.01"), "set_speed_scale", "get_speed_scale"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "explosiveness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_explosiveness_ratio", "get_explosiveness_ratio"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "randomness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_randomness_ratio", "get_randomness_ratio"); @@ -1390,7 +1390,7 @@ void CPUParticles3D::_bind_methods() { ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "damping_random", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_param_randomness", "get_param_randomness", PARAM_DAMPING); ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "damping_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_param_curve", "get_param_curve", PARAM_DAMPING); ADD_GROUP("Angle", ""); - ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angle", PROPERTY_HINT_RANGE, "-720,720,0.1,or_lesser,or_greater"), "set_param", "get_param", PARAM_ANGLE); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angle", PROPERTY_HINT_RANGE, "-720,720,0.1,or_lesser,or_greater,degrees"), "set_param", "get_param", PARAM_ANGLE); ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angle_random", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_param_randomness", "get_param_randomness", PARAM_ANGLE); ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "angle_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_param_curve", "get_param_curve", PARAM_ANGLE); ADD_GROUP("Scale", ""); diff --git a/scene/3d/gpu_particles_3d.cpp b/scene/3d/gpu_particles_3d.cpp index d7f4bfeb4e..f78027e6c7 100644 --- a/scene/3d/gpu_particles_3d.cpp +++ b/scene/3d/gpu_particles_3d.cpp @@ -385,7 +385,7 @@ void GPUParticles3D::_validate_property(PropertyInfo &property) const { if (property.name.begins_with("draw_pass_")) { int index = property.name.get_slicec('_', 2).to_int() - 1; if (index >= draw_passes.size()) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; return; } } @@ -562,12 +562,12 @@ void GPUParticles3D::_bind_methods() { ClassDB::bind_method(D_METHOD("get_transform_align"), &GPUParticles3D::get_transform_align); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "emitting"), "set_emitting", "is_emitting"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "amount", PROPERTY_HINT_EXP_RANGE, "1,1000000,1"), "set_amount", "get_amount"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "amount", PROPERTY_HINT_RANGE, "1,1000000,1,exp"), "set_amount", "get_amount"); ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "sub_emitter", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "GPUParticles3D"), "set_sub_emitter", "get_sub_emitter"); ADD_GROUP("Time", ""); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "lifetime", PROPERTY_HINT_EXP_RANGE, "0.01,600.0,0.01,or_greater"), "set_lifetime", "get_lifetime"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "lifetime", PROPERTY_HINT_RANGE, "0.01,600.0,0.01,or_greater,exp"), "set_lifetime", "get_lifetime"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "one_shot"), "set_one_shot", "get_one_shot"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "preprocess", PROPERTY_HINT_EXP_RANGE, "0.00,600.0,0.01"), "set_pre_process_time", "get_pre_process_time"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "preprocess", PROPERTY_HINT_RANGE, "0.00,600.0,0.01,exp"), "set_pre_process_time", "get_pre_process_time"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "speed_scale", PROPERTY_HINT_RANGE, "0,64,0.01"), "set_speed_scale", "get_speed_scale"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "explosiveness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_explosiveness_ratio", "get_explosiveness_ratio"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "randomness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_randomness_ratio", "get_randomness_ratio"); diff --git a/scene/3d/gpu_particles_collision_3d.cpp b/scene/3d/gpu_particles_collision_3d.cpp index 322bc60fce..c1e71b9565 100644 --- a/scene/3d/gpu_particles_collision_3d.cpp +++ b/scene/3d/gpu_particles_collision_3d.cpp @@ -495,7 +495,7 @@ Ref<Image> GPUParticlesCollisionSDF::bake() { _compute_sdf(¶ms); Ref<Image> ret; - ret.instance(); + ret.instantiate(); ret->create(sdf_size.x, sdf_size.y * sdf_size.z, false, Image::FORMAT_RF, data); ret->convert(Image::FORMAT_RH); //convert to half, save space ret->set_meta("depth", sdf_size.z); //hack, make sure to add to the docs of this function diff --git a/scene/3d/immediate_geometry_3d.cpp b/scene/3d/immediate_geometry_3d.cpp deleted file mode 100644 index d64babaa9d..0000000000 --- a/scene/3d/immediate_geometry_3d.cpp +++ /dev/null @@ -1,157 +0,0 @@ -/*************************************************************************/ -/* immediate_geometry_3d.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "immediate_geometry_3d.h" - -void ImmediateGeometry3D::begin(Mesh::PrimitiveType p_primitive, const Ref<Texture2D> &p_texture) { - RS::get_singleton()->immediate_begin(im, (RS::PrimitiveType)p_primitive, p_texture.is_valid() ? p_texture->get_rid() : RID()); - if (p_texture.is_valid()) { - cached_textures.push_back(p_texture); - } -} - -void ImmediateGeometry3D::set_normal(const Vector3 &p_normal) { - RS::get_singleton()->immediate_normal(im, p_normal); -} - -void ImmediateGeometry3D::set_tangent(const Plane &p_tangent) { - RS::get_singleton()->immediate_tangent(im, p_tangent); -} - -void ImmediateGeometry3D::set_color(const Color &p_color) { - RS::get_singleton()->immediate_color(im, p_color); -} - -void ImmediateGeometry3D::set_uv(const Vector2 &p_uv) { - RS::get_singleton()->immediate_uv(im, p_uv); -} - -void ImmediateGeometry3D::set_uv2(const Vector2 &p_uv2) { - RS::get_singleton()->immediate_uv2(im, p_uv2); -} - -void ImmediateGeometry3D::add_vertex(const Vector3 &p_vertex) { - RS::get_singleton()->immediate_vertex(im, p_vertex); - if (empty) { - aabb.position = p_vertex; - aabb.size = Vector3(); - empty = false; - } else { - aabb.expand_to(p_vertex); - } -} - -void ImmediateGeometry3D::end() { - RS::get_singleton()->immediate_end(im); -} - -void ImmediateGeometry3D::clear() { - RS::get_singleton()->immediate_clear(im); - empty = true; - cached_textures.clear(); -} - -AABB ImmediateGeometry3D::get_aabb() const { - return aabb; -} - -Vector<Face3> ImmediateGeometry3D::get_faces(uint32_t p_usage_flags) const { - return Vector<Face3>(); -} - -void ImmediateGeometry3D::add_sphere(int p_lats, int p_lons, float p_radius, bool p_add_uv) { - const double lat_step = Math_TAU / p_lats; - const double lon_step = Math_TAU / p_lons; - - for (int i = 1; i <= p_lats; i++) { - double lat0 = lat_step * (i - 1) - Math_TAU / 4; - double z0 = Math::sin(lat0); - double zr0 = Math::cos(lat0); - - double lat1 = lat_step * i - Math_TAU / 4; - double z1 = Math::sin(lat1); - double zr1 = Math::cos(lat1); - - for (int j = p_lons; j >= 1; j--) { - double lng0 = lon_step * (j - 1); - double x0 = Math::cos(lng0); - double y0 = Math::sin(lng0); - - double lng1 = lon_step * j; - double x1 = Math::cos(lng1); - double y1 = Math::sin(lng1); - - Vector3 v[4] = { - Vector3(x1 * zr0, z0, y1 * zr0), - Vector3(x1 * zr1, z1, y1 * zr1), - Vector3(x0 * zr1, z1, y0 * zr1), - Vector3(x0 * zr0, z0, y0 * zr0) - }; - -#define ADD_POINT(m_idx) \ - if (p_add_uv) { \ - set_uv(Vector2(Math::atan2(v[m_idx].x, v[m_idx].z) / Math_PI * 0.5 + 0.5, v[m_idx].y * 0.5 + 0.5)); \ - set_tangent(Plane(Vector3(-v[m_idx].z, v[m_idx].y, v[m_idx].x), 1)); \ - } \ - set_normal(v[m_idx]); \ - add_vertex(v[m_idx] * p_radius); - - ADD_POINT(0); - ADD_POINT(1); - ADD_POINT(2); - - ADD_POINT(2); - ADD_POINT(3); - ADD_POINT(0); - } - } -} - -void ImmediateGeometry3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("begin", "primitive", "texture"), &ImmediateGeometry3D::begin, DEFVAL(Ref<Texture2D>())); - ClassDB::bind_method(D_METHOD("set_normal", "normal"), &ImmediateGeometry3D::set_normal); - ClassDB::bind_method(D_METHOD("set_tangent", "tangent"), &ImmediateGeometry3D::set_tangent); - ClassDB::bind_method(D_METHOD("set_color", "color"), &ImmediateGeometry3D::set_color); - ClassDB::bind_method(D_METHOD("set_uv", "uv"), &ImmediateGeometry3D::set_uv); - ClassDB::bind_method(D_METHOD("set_uv2", "uv"), &ImmediateGeometry3D::set_uv2); - ClassDB::bind_method(D_METHOD("add_vertex", "position"), &ImmediateGeometry3D::add_vertex); - ClassDB::bind_method(D_METHOD("add_sphere", "lats", "lons", "radius", "add_uv"), &ImmediateGeometry3D::add_sphere, DEFVAL(true)); - ClassDB::bind_method(D_METHOD("end"), &ImmediateGeometry3D::end); - ClassDB::bind_method(D_METHOD("clear"), &ImmediateGeometry3D::clear); -} - -ImmediateGeometry3D::ImmediateGeometry3D() { - im = RenderingServer::get_singleton()->immediate_create(); - set_base(im); -} - -ImmediateGeometry3D::~ImmediateGeometry3D() { - RenderingServer::get_singleton()->free(im); -} diff --git a/scene/3d/light_3d.cpp b/scene/3d/light_3d.cpp index d45749d36b..8478821ba1 100644 --- a/scene/3d/light_3d.cpp +++ b/scene/3d/light_3d.cpp @@ -209,19 +209,19 @@ void Light3D::_validate_property(PropertyInfo &property) const { } if (get_light_type() == RS::LIGHT_DIRECTIONAL && property.name == "light_size") { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } if (get_light_type() == RS::LIGHT_DIRECTIONAL && property.name == "light_specular") { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } if (get_light_type() == RS::LIGHT_DIRECTIONAL && property.name == "light_projector") { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } if (get_light_type() != RS::LIGHT_DIRECTIONAL && property.name == "light_angular_distance") { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } } @@ -353,7 +353,7 @@ Light3D::Light3D(RenderingServer::LightType p_type) { } Light3D::Light3D() { - ERR_PRINT("Light3D should not be instanced directly; use the DirectionalLight3D, OmniLight3D or SpotLight3D subtypes instead."); + ERR_PRINT("Light3D should not be instantiated directly; use the DirectionalLight3D, OmniLight3D or SpotLight3D subtypes instead."); } Light3D::~Light3D() { @@ -375,15 +375,6 @@ DirectionalLight3D::ShadowMode DirectionalLight3D::get_shadow_mode() const { return shadow_mode; } -void DirectionalLight3D::set_shadow_depth_range(ShadowDepthRange p_range) { - shadow_depth_range = p_range; - RS::get_singleton()->light_directional_set_shadow_depth_range_mode(light, RS::LightDirectionalShadowDepthRangeMode(p_range)); -} - -DirectionalLight3D::ShadowDepthRange DirectionalLight3D::get_shadow_depth_range() const { - return shadow_depth_range; -} - void DirectionalLight3D::set_blend_splits(bool p_enable) { blend_splits = p_enable; RS::get_singleton()->light_directional_set_blend_splits(light, p_enable); @@ -406,9 +397,6 @@ void DirectionalLight3D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_shadow_mode", "mode"), &DirectionalLight3D::set_shadow_mode); ClassDB::bind_method(D_METHOD("get_shadow_mode"), &DirectionalLight3D::get_shadow_mode); - ClassDB::bind_method(D_METHOD("set_shadow_depth_range", "mode"), &DirectionalLight3D::set_shadow_depth_range); - ClassDB::bind_method(D_METHOD("get_shadow_depth_range"), &DirectionalLight3D::get_shadow_depth_range); - ClassDB::bind_method(D_METHOD("set_blend_splits", "enabled"), &DirectionalLight3D::set_blend_splits); ClassDB::bind_method(D_METHOD("is_blend_splits_enabled"), &DirectionalLight3D::is_blend_splits_enabled); @@ -422,18 +410,14 @@ void DirectionalLight3D::_bind_methods() { ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "directional_shadow_split_3", PROPERTY_HINT_RANGE, "0,1,0.001"), "set_param", "get_param", PARAM_SHADOW_SPLIT_3_OFFSET); ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "directional_shadow_fade_start", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_param", "get_param", PARAM_SHADOW_FADE_START); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "directional_shadow_blend_splits"), "set_blend_splits", "is_blend_splits_enabled"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "directional_shadow_depth_range", PROPERTY_HINT_ENUM, "Stable,Optimized"), "set_shadow_depth_range", "get_shadow_depth_range"); - ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "directional_shadow_max_distance", PROPERTY_HINT_EXP_RANGE, "0,8192,0.1,or_greater"), "set_param", "get_param", PARAM_SHADOW_MAX_DISTANCE); - ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "directional_shadow_pancake_size", PROPERTY_HINT_EXP_RANGE, "0,1024,0.1,or_greater"), "set_param", "get_param", PARAM_SHADOW_PANCAKE_SIZE); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "directional_shadow_max_distance", PROPERTY_HINT_RANGE, "0,8192,0.1,or_greater,exp"), "set_param", "get_param", PARAM_SHADOW_MAX_DISTANCE); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "directional_shadow_pancake_size", PROPERTY_HINT_RANGE, "0,1024,0.1,or_greater,exp"), "set_param", "get_param", PARAM_SHADOW_PANCAKE_SIZE); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_in_sky_only"), "set_sky_only", "is_sky_only"); BIND_ENUM_CONSTANT(SHADOW_ORTHOGONAL); BIND_ENUM_CONSTANT(SHADOW_PARALLEL_2_SPLITS); BIND_ENUM_CONSTANT(SHADOW_PARALLEL_4_SPLITS); - - BIND_ENUM_CONSTANT(SHADOW_DEPTH_RANGE_STABLE); - BIND_ENUM_CONSTANT(SHADOW_DEPTH_RANGE_OPTIMIZED); } DirectionalLight3D::DirectionalLight3D() : @@ -444,7 +428,6 @@ DirectionalLight3D::DirectionalLight3D() : // Leave normal bias untouched as it doesn't benefit DirectionalLight3D as much as OmniLight3D. set_param(PARAM_SHADOW_BIAS, 0.05); set_shadow_mode(SHADOW_PARALLEL_4_SPLITS); - set_shadow_depth_range(SHADOW_DEPTH_RANGE_STABLE); blend_splits = false; } @@ -472,7 +455,7 @@ void OmniLight3D::_bind_methods() { ClassDB::bind_method(D_METHOD("get_shadow_mode"), &OmniLight3D::get_shadow_mode); ADD_GROUP("Omni", "omni_"); - ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "omni_range", PROPERTY_HINT_EXP_RANGE, "0,4096,0.1,or_greater"), "set_param", "get_param", PARAM_RANGE); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "omni_range", PROPERTY_HINT_RANGE, "0,4096,0.1,or_greater,exp"), "set_param", "get_param", PARAM_RANGE); ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "omni_attenuation", PROPERTY_HINT_EXP_EASING, "attenuation"), "set_param", "get_param", PARAM_ATTENUATION); ADD_PROPERTY(PropertyInfo(Variant::INT, "omni_shadow_mode", PROPERTY_HINT_ENUM, "Dual Paraboloid,Cube"), "set_shadow_mode", "get_shadow_mode"); @@ -504,8 +487,8 @@ TypedArray<String> SpotLight3D::get_configuration_warnings() const { void SpotLight3D::_bind_methods() { ADD_GROUP("Spot", "spot_"); - ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "spot_range", PROPERTY_HINT_EXP_RANGE, "0,4096,0.1,or_greater"), "set_param", "get_param", PARAM_RANGE); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "spot_range", PROPERTY_HINT_RANGE, "0,4096,0.1,or_greater,exp"), "set_param", "get_param", PARAM_RANGE); ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "spot_attenuation", PROPERTY_HINT_EXP_EASING, "attenuation"), "set_param", "get_param", PARAM_ATTENUATION); - ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "spot_angle", PROPERTY_HINT_RANGE, "0,180,0.1"), "set_param", "get_param", PARAM_SPOT_ANGLE); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "spot_angle", PROPERTY_HINT_RANGE, "0,180,0.1,degrees"), "set_param", "get_param", PARAM_SPOT_ANGLE); ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "spot_angle_attenuation", PROPERTY_HINT_EXP_EASING, "attenuation"), "set_param", "get_param", PARAM_SPOT_ATTENUATION); } diff --git a/scene/3d/light_3d.h b/scene/3d/light_3d.h index e145b08b74..d0308a3025 100644 --- a/scene/3d/light_3d.h +++ b/scene/3d/light_3d.h @@ -149,15 +149,9 @@ public: SHADOW_PARALLEL_4_SPLITS, }; - enum ShadowDepthRange { - SHADOW_DEPTH_RANGE_STABLE = RS::LIGHT_DIRECTIONAL_SHADOW_DEPTH_RANGE_STABLE, - SHADOW_DEPTH_RANGE_OPTIMIZED = RS::LIGHT_DIRECTIONAL_SHADOW_DEPTH_RANGE_OPTIMIZED, - }; - private: bool blend_splits; ShadowMode shadow_mode; - ShadowDepthRange shadow_depth_range; bool sky_only = false; protected: @@ -167,9 +161,6 @@ public: void set_shadow_mode(ShadowMode p_mode); ShadowMode get_shadow_mode() const; - void set_shadow_depth_range(ShadowDepthRange p_range); - ShadowDepthRange get_shadow_depth_range() const; - void set_blend_splits(bool p_enable); bool is_blend_splits_enabled() const; @@ -180,7 +171,6 @@ public: }; VARIANT_ENUM_CAST(DirectionalLight3D::ShadowMode) -VARIANT_ENUM_CAST(DirectionalLight3D::ShadowDepthRange) class OmniLight3D : public Light3D { GDCLASS(OmniLight3D, Light3D); diff --git a/scene/3d/lightmap_gi.cpp b/scene/3d/lightmap_gi.cpp index a3f681e53c..66e3535fc4 100644 --- a/scene/3d/lightmap_gi.cpp +++ b/scene/3d/lightmap_gi.cpp @@ -717,7 +717,7 @@ LightmapGI::BakeError LightmapGI::bake(Node *p_from_node, String p_image_data_pa w_albedo[i + 3] = 255; } - md.albedo_on_uv2.instance(); + md.albedo_on_uv2.instantiate(); md.albedo_on_uv2->create(lightmap_size.width, lightmap_size.height, false, Image::FORMAT_RGBA8, albedom); } @@ -940,7 +940,7 @@ LightmapGI::BakeError LightmapGI::bake(Node *p_from_node, String p_image_data_pa } break; case ENVIRONMENT_MODE_CUSTOM_COLOR: { - environment_image.instance(); + environment_image.instantiate(); environment_image->create(128, 64, false, Image::FORMAT_RGBAF); Color c = environment_custom_color; c.r *= environment_custom_energy; @@ -972,7 +972,7 @@ LightmapGI::BakeError LightmapGI::bake(Node *p_from_node, String p_image_data_pa } //we assume they are all the same, so let's create a large one for saving Ref<Image> large_image; - large_image.instance(); + large_image.instantiate(); large_image->create(images[0]->get_width(), images[0]->get_height() * images.size(), false, images[0]->get_format()); @@ -984,7 +984,7 @@ LightmapGI::BakeError LightmapGI::bake(Node *p_from_node, String p_image_data_pa Ref<ConfigFile> config; - config.instance(); + config.instantiate(); if (FileAccess::exists(base_path + ".import")) { config->load(base_path + ".import"); } @@ -1017,7 +1017,7 @@ LightmapGI::BakeError LightmapGI::bake(Node *p_from_node, String p_image_data_pa set_light_data(Ref<LightmapGIData>()); //clear data->clear(); } else { - data.instance(); + data.instantiate(); } data->set_light_texture(texture); @@ -1367,13 +1367,13 @@ LightmapGI::GenerateProbes LightmapGI::get_generate_probes() const { void LightmapGI::_validate_property(PropertyInfo &property) const { if (property.name == "environment_custom_sky" && environment_mode != ENVIRONMENT_MODE_CUSTOM_SKY) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } if (property.name == "environment_custom_color" && environment_mode != ENVIRONMENT_MODE_CUSTOM_COLOR) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } if (property.name == "environment_custom_energy" && environment_mode != ENVIRONMENT_MODE_CUSTOM_COLOR && environment_mode != ENVIRONMENT_MODE_CUSTOM_SKY) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } } diff --git a/scene/3d/mesh_instance_3d.cpp b/scene/3d/mesh_instance_3d.cpp index c495f68890..279a1fb7de 100644 --- a/scene/3d/mesh_instance_3d.cpp +++ b/scene/3d/mesh_instance_3d.cpp @@ -100,7 +100,7 @@ void MeshInstance3D::_get_property_list(List<PropertyInfo> *p_list) const { if (mesh.is_valid()) { for (int i = 0; i < mesh->get_surface_count(); i++) { - p_list->push_back(PropertyInfo(Variant::OBJECT, "surface_material_override/" + itos(i), PROPERTY_HINT_RESOURCE_TYPE, "ShaderMaterial,StandardMaterial3D", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_DEFERRED_SET_RESOURCE)); + p_list->push_back(PropertyInfo(Variant::OBJECT, "surface_material_override/" + itos(i), PROPERTY_HINT_RESOURCE_TYPE, "BaseMaterial3D,ShaderMaterial", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_DEFERRED_SET_RESOURCE)); } } } @@ -405,14 +405,14 @@ void MeshInstance3D::create_debug_tangents() { if (lines.size()) { Ref<StandardMaterial3D> sm; - sm.instance(); + sm.instantiate(); sm->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED); sm->set_flag(StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, true); sm->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); Ref<ArrayMesh> am; - am.instance(); + am.instantiate(); Array a; a.resize(Mesh::ARRAY_MAX); a[Mesh::ARRAY_VERTEX] = lines; diff --git a/scene/3d/node_3d.cpp b/scene/3d/node_3d.cpp index f78a2ff14e..d6c6ec75b4 100644 --- a/scene/3d/node_3d.cpp +++ b/scene/3d/node_3d.cpp @@ -328,10 +328,6 @@ void Node3D::set_rotation(const Vector3 &p_euler_rad) { } } -void Node3D::set_rotation_degrees(const Vector3 &p_euler_deg) { - set_rotation(p_euler_deg * (Math_PI / 180.0)); -} - void Node3D::set_scale(const Vector3 &p_scale) { if (data.dirty & DIRTY_VECTORS) { data.rotation = data.local_transform.basis.get_rotation(); @@ -361,10 +357,6 @@ Vector3 Node3D::get_rotation() const { return data.rotation; } -Vector3 Node3D::get_rotation_degrees() const { - return get_rotation() * (180.0 / Math_PI); -} - Vector3 Node3D::get_scale() const { if (data.dirty & DIRTY_VECTORS) { data.scale = data.local_transform.basis.get_scale(); @@ -749,8 +741,6 @@ void Node3D::_bind_methods() { ClassDB::bind_method(D_METHOD("get_position"), &Node3D::get_position); ClassDB::bind_method(D_METHOD("set_rotation", "euler"), &Node3D::set_rotation); ClassDB::bind_method(D_METHOD("get_rotation"), &Node3D::get_rotation); - ClassDB::bind_method(D_METHOD("set_rotation_degrees", "euler_degrees"), &Node3D::set_rotation_degrees); - ClassDB::bind_method(D_METHOD("get_rotation_degrees"), &Node3D::get_rotation_degrees); ClassDB::bind_method(D_METHOD("set_scale", "scale"), &Node3D::set_scale); ClassDB::bind_method(D_METHOD("get_scale"), &Node3D::get_scale); ClassDB::bind_method(D_METHOD("set_global_transform", "global"), &Node3D::set_global_transform); @@ -814,9 +804,8 @@ void Node3D::_bind_methods() { //ADD_PROPERTY( PropertyInfo(Variant::TRANSFORM3D,"transform/global",PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR ), "set_global_transform", "get_global_transform") ; ADD_GROUP("Transform", ""); ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM3D, "global_transform", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_global_transform", "get_global_transform"); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "position", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_position", "get_position"); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "rotation_degrees", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_rotation_degrees", "get_rotation_degrees"); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "rotation", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_rotation", "get_rotation"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "position", PROPERTY_HINT_RANGE, "-99999,99999,0,or_greater,or_lesser,noslider,suffix:m", PROPERTY_USAGE_EDITOR), "set_position", "get_position"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "rotation", PROPERTY_HINT_RANGE, "-360,360,0.1,or_lesser,or_greater,radians", PROPERTY_USAGE_EDITOR), "set_rotation", "get_rotation"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "scale", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_scale", "get_scale"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "top_level"), "set_as_top_level", "is_set_as_top_level"); ADD_GROUP("Matrix", ""); diff --git a/scene/3d/node_3d.h b/scene/3d/node_3d.h index c7e36cf2ec..fe6324c796 100644 --- a/scene/3d/node_3d.h +++ b/scene/3d/node_3d.h @@ -131,12 +131,10 @@ public: void set_position(const Vector3 &p_position); void set_rotation(const Vector3 &p_euler_rad); - void set_rotation_degrees(const Vector3 &p_euler_deg); void set_scale(const Vector3 &p_scale); Vector3 get_position() const; Vector3 get_rotation() const; - Vector3 get_rotation_degrees() const; Vector3 get_scale() const; void set_transform(const Transform3D &p_transform); diff --git a/scene/3d/occluder_instance_3d.cpp b/scene/3d/occluder_instance_3d.cpp index 429e1d4b98..7b736e689c 100644 --- a/scene/3d/occluder_instance_3d.cpp +++ b/scene/3d/occluder_instance_3d.cpp @@ -114,7 +114,7 @@ Ref<ArrayMesh> Occluder3D::get_debug_mesh() const { arrays[Mesh::ARRAY_VERTEX] = vertices; arrays[Mesh::ARRAY_INDEX] = indices; - debug_mesh.instance(); + debug_mesh.instantiate(); debug_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, arrays); return debug_mesh; } @@ -174,10 +174,12 @@ void OccluderInstance3D::set_occluder(const Ref<Occluder3D> &p_occluder) { } update_gizmo(); + update_configuration_warnings(); } void OccluderInstance3D::_occluder_changed() { update_gizmo(); + update_configuration_warnings(); } Ref<Occluder3D> OccluderInstance3D::get_occluder() const { @@ -186,6 +188,7 @@ Ref<Occluder3D> OccluderInstance3D::get_occluder() const { void OccluderInstance3D::set_bake_mask(uint32_t p_mask) { bake_mask = p_mask; + update_configuration_warnings(); } uint32_t OccluderInstance3D::get_bake_mask() const { @@ -303,7 +306,7 @@ OccluderInstance3D::BakeError OccluderInstance3D::bake(Node *p_from_node, String if (get_occluder().is_valid()) { occ = get_occluder(); } else { - occ.instance(); + occ.instantiate(); occ->set_path(p_occluder_path); } @@ -314,6 +317,31 @@ OccluderInstance3D::BakeError OccluderInstance3D::bake(Node *p_from_node, String return BAKE_ERROR_OK; } +TypedArray<String> OccluderInstance3D::get_configuration_warnings() const { + TypedArray<String> warnings = Node::get_configuration_warnings(); + + if (!bool(GLOBAL_GET("rendering/occlusion_culling/use_occlusion_culling"))) { + warnings.push_back(TTR("Occlusion culling is disabled in the Project Settings, which means occlusion culling won't be performed in the root viewport.\nTo resolve this, open the Project Settings and enable Rendering > Occlusion Culling > Use Occlusion Culling.")); + } + + if (bake_mask == 0) { + // NOTE: This warning will not be emitted if none of the 20 checkboxes + // exposed in the editor are checked. This is because there are + // currently 12 unexposed layers in the editor inspector. + warnings.push_back(TTR("The Bake Mask has no bits enabled, which means baking will not produce any occluder meshes for this OccluderInstance3D.\nTo resolve this, enable at least one bit in the Bake Mask property.")); + } + + if (occluder.is_null()) { + warnings.push_back(TTR("No occluder mesh is defined in the Occluder property, so no occlusion culling will be performed using this OccluderInstance3D.\nTo resolve this, select the OccluderInstance3D then use the Bake Occluders button at the top of the 3D editor viewport.")); + } else if (occluder->get_vertices().size() < 3) { + // Using the "New Occluder" dropdown button won't result in a correct occluder, + // so warn the user about this. + warnings.push_back(TTR("The occluder mesh has less than 3 vertices, so no occlusion culling will be performed using this OccluderInstance3D.\nTo generate a proper occluder mesh, select the OccluderInstance3D then use the Bake Occluders button at the top of the 3D editor viewport.")); + } + + return warnings; +} + void OccluderInstance3D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_bake_mask", "mask"), &OccluderInstance3D::set_bake_mask); ClassDB::bind_method(D_METHOD("get_bake_mask"), &OccluderInstance3D::get_bake_mask); diff --git a/scene/3d/occluder_instance_3d.h b/scene/3d/occluder_instance_3d.h index 4bb468274d..d382cd090e 100644 --- a/scene/3d/occluder_instance_3d.h +++ b/scene/3d/occluder_instance_3d.h @@ -82,6 +82,8 @@ protected: static void _bind_methods(); public: + virtual TypedArray<String> get_configuration_warnings() const override; + enum BakeError { BAKE_ERROR_OK, BAKE_ERROR_NO_SAVE_PATH, diff --git a/scene/3d/physics_body_3d.cpp b/scene/3d/physics_body_3d.cpp index 28a0c72fe3..e7482d35e7 100644 --- a/scene/3d/physics_body_3d.cpp +++ b/scene/3d/physics_body_3d.cpp @@ -65,7 +65,7 @@ void PhysicsBody3D::_bind_methods() { PhysicsBody3D::PhysicsBody3D(PhysicsServer3D::BodyMode p_mode) : CollisionObject3D(PhysicsServer3D::get_singleton()->body_create(), false) { - PhysicsServer3D::get_singleton()->body_set_mode(get_rid(), p_mode); + set_body_mode(p_mode); } PhysicsBody3D::~PhysicsBody3D() { @@ -106,7 +106,7 @@ Ref<KinematicCollision3D> PhysicsBody3D::_move(const Vector3 &p_motion, bool p_i PhysicsServer3D::MotionResult result; if (move_and_collide(p_motion, p_infinite_inertia, result, p_margin, p_exclude_raycast_shapes, p_test_only)) { if (motion_cache.is_null()) { - motion_cache.instance(); + motion_cache.instantiate(); motion_cache->owner = this; } @@ -118,10 +118,43 @@ Ref<KinematicCollision3D> PhysicsBody3D::_move(const Vector3 &p_motion, bool p_i return Ref<KinematicCollision3D>(); } -bool PhysicsBody3D::move_and_collide(const Vector3 &p_motion, bool p_infinite_inertia, PhysicsServer3D::MotionResult &r_result, real_t p_margin, bool p_exclude_raycast_shapes, bool p_test_only) { +bool PhysicsBody3D::move_and_collide(const Vector3 &p_motion, bool p_infinite_inertia, PhysicsServer3D::MotionResult &r_result, real_t p_margin, bool p_exclude_raycast_shapes, bool p_test_only, bool p_cancel_sliding) { Transform3D gt = get_global_transform(); bool colliding = PhysicsServer3D::get_singleton()->body_test_motion(get_rid(), gt, p_motion, p_infinite_inertia, p_margin, &r_result, p_exclude_raycast_shapes); + // Restore direction of motion to be along original motion, + // in order to avoid sliding due to recovery, + // but only if collision depth is low enough to avoid tunneling. + real_t motion_length = p_motion.length(); + if (motion_length > CMP_EPSILON) { + real_t precision = CMP_EPSILON; + + if (colliding && p_cancel_sliding) { + // Can't just use margin as a threshold because collision depth is calculated on unsafe motion, + // so even in normal resting cases the depth can be a bit more than the margin. + precision += motion_length * (r_result.collision_unsafe_fraction - r_result.collision_safe_fraction); + + if (r_result.collision_depth > (real_t)p_margin + precision) { + p_cancel_sliding = false; + } + } + + if (p_cancel_sliding) { + // Check depth of recovery. + Vector3 motion_normal = p_motion / motion_length; + real_t dot = r_result.motion.dot(motion_normal); + Vector3 recovery = r_result.motion - motion_normal * dot; + real_t recovery_length = recovery.length(); + // Fixes cases where canceling slide causes the motion to go too deep into the ground, + // Becauses we're only taking rest information into account and not general recovery. + if (recovery_length < (real_t)p_margin + precision) { + // Apply adjustment to motion. + r_result.motion = motion_normal * dot; + r_result.remainder = p_motion - r_result.motion; + } + } + } + for (int i = 0; i < 3; i++) { if (locked_axis & (1 << i)) { r_result.motion[i] = 0; @@ -200,9 +233,9 @@ void StaticBody3D::set_kinematic_motion_enabled(bool p_enabled) { kinematic_motion = p_enabled; if (kinematic_motion) { - PhysicsServer3D::get_singleton()->body_set_mode(get_rid(), PhysicsServer3D::BODY_MODE_KINEMATIC); + set_body_mode(PhysicsServer3D::BODY_MODE_KINEMATIC); } else { - PhysicsServer3D::get_singleton()->body_set_mode(get_rid(), PhysicsServer3D::BODY_MODE_STATIC); + set_body_mode(PhysicsServer3D::BODY_MODE_STATIC); } _update_kinematic_motion(); @@ -249,35 +282,37 @@ Vector3 StaticBody3D::get_angular_velocity() const { } void StaticBody3D::_notification(int p_what) { - if (p_what == NOTIFICATION_INTERNAL_PHYSICS_PROCESS) { + switch (p_what) { + case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: { #ifdef TOOLS_ENABLED - if (Engine::get_singleton()->is_editor_hint()) { - return; - } + if (Engine::get_singleton()->is_editor_hint()) { + return; + } #endif - ERR_FAIL_COND(!kinematic_motion); + ERR_FAIL_COND(!kinematic_motion); - real_t delta_time = get_physics_process_delta_time(); + real_t delta_time = get_physics_process_delta_time(); - Transform3D new_transform = get_global_transform(); - new_transform.origin += constant_linear_velocity * delta_time; + Transform3D new_transform = get_global_transform(); + new_transform.origin += constant_linear_velocity * delta_time; - real_t ang_vel = constant_angular_velocity.length(); - if (!Math::is_zero_approx(ang_vel)) { - Vector3 ang_vel_axis = constant_angular_velocity / ang_vel; - Basis rot(ang_vel_axis, ang_vel * delta_time); - new_transform.basis = rot * new_transform.basis; - new_transform.orthonormalize(); - } + real_t ang_vel = constant_angular_velocity.length(); + if (!Math::is_zero_approx(ang_vel)) { + Vector3 ang_vel_axis = constant_angular_velocity / ang_vel; + Basis rot(ang_vel_axis, ang_vel * delta_time); + new_transform.basis = rot * new_transform.basis; + new_transform.orthonormalize(); + } - PhysicsServer3D::get_singleton()->body_set_state(get_rid(), PhysicsServer3D::BODY_STATE_TRANSFORM, new_transform); + PhysicsServer3D::get_singleton()->body_set_state(get_rid(), PhysicsServer3D::BODY_STATE_TRANSFORM, new_transform); - // Propagate transform change to node. - set_ignore_transform_notification(true); - set_global_transform(new_transform); - set_ignore_transform_notification(false); - _on_transform_changed(); + // Propagate transform change to node. + set_ignore_transform_notification(true); + set_global_transform(new_transform); + set_ignore_transform_notification(false); + _on_transform_changed(); + } break; } } @@ -565,18 +600,19 @@ void RigidBody3D::_direct_state_changed(Object *p_state) { void RigidBody3D::_notification(int p_what) { #ifdef TOOLS_ENABLED - if (p_what == NOTIFICATION_ENTER_TREE) { - if (Engine::get_singleton()->is_editor_hint()) { - set_notify_local_transform(true); //used for warnings and only in editor - } - } + switch (p_what) { + case NOTIFICATION_ENTER_TREE: { + if (Engine::get_singleton()->is_editor_hint()) { + set_notify_local_transform(true); //used for warnings and only in editor + } + } break; - if (p_what == NOTIFICATION_LOCAL_TRANSFORM_CHANGED) { - if (Engine::get_singleton()->is_editor_hint()) { - update_configuration_warnings(); - } + case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: { + if (Engine::get_singleton()->is_editor_hint()) { + update_configuration_warnings(); + } + } break; } - #endif } @@ -584,18 +620,16 @@ void RigidBody3D::set_mode(Mode p_mode) { mode = p_mode; switch (p_mode) { case MODE_DYNAMIC: { - PhysicsServer3D::get_singleton()->body_set_mode(get_rid(), PhysicsServer3D::BODY_MODE_DYNAMIC); + set_body_mode(PhysicsServer3D::BODY_MODE_DYNAMIC); } break; case MODE_STATIC: { - PhysicsServer3D::get_singleton()->body_set_mode(get_rid(), PhysicsServer3D::BODY_MODE_STATIC); - + set_body_mode(PhysicsServer3D::BODY_MODE_STATIC); } break; case MODE_DYNAMIC_LOCKED: { - PhysicsServer3D::get_singleton()->body_set_mode(get_rid(), PhysicsServer3D::BODY_MODE_DYNAMIC_LOCKED); - + set_body_mode(PhysicsServer3D::BODY_MODE_DYNAMIC_LOCKED); } break; case MODE_KINEMATIC: { - PhysicsServer3D::get_singleton()->body_set_mode(get_rid(), PhysicsServer3D::BODY_MODE_KINEMATIC); + set_body_mode(PhysicsServer3D::BODY_MODE_KINEMATIC); } break; } update_configuration_warnings(); @@ -902,7 +936,7 @@ void RigidBody3D::_bind_methods() { BIND_VMETHOD(MethodInfo("_integrate_forces", PropertyInfo(Variant::OBJECT, "state", PROPERTY_HINT_RESOURCE_TYPE, "PhysicsDirectBodyState3D"))); ADD_PROPERTY(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Dynamic,Static,DynamicLocked,Kinematic"), "set_mode", "get_mode"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "mass", PROPERTY_HINT_EXP_RANGE, "0.01,65535,0.01"), "set_mass", "get_mass"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "mass", PROPERTY_HINT_RANGE, "0.01,65535,0.01,exp"), "set_mass", "get_mass"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "physics_material_override", PROPERTY_HINT_RESOURCE_TYPE, "PhysicsMaterial"), "set_physics_material_override", "get_physics_material_override"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "gravity_scale", PROPERTY_HINT_RANGE, "-128,128,0.01"), "set_gravity_scale", "get_gravity_scale"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "custom_integrator"), "set_use_custom_integrator", "is_using_custom_integrator"); @@ -978,15 +1012,16 @@ void CharacterBody3D::move_and_slide() { floor_normal = Vector3(); floor_velocity = Vector3(); - int slide_count = max_slides; - while (slide_count) { + // No sliding on first attempt to keep motion stable when possible. + bool sliding_enabled = false; + for (int iteration = 0; iteration < max_slides; ++iteration) { PhysicsServer3D::MotionResult result; bool found_collision = false; for (int i = 0; i < 2; ++i) { bool collided; if (i == 0) { //collide - collided = move_and_collide(motion, infinite_inertia, result, margin); + collided = move_and_collide(motion, infinite_inertia, result, margin, true, false, !sliding_enabled); if (!collided) { motion = Vector3(); //clear because no collision happened and motion completed } @@ -1002,7 +1037,6 @@ void CharacterBody3D::move_and_slide() { found_collision = true; motion_results.push_back(result); - motion = result.remainder; if (up_direction == Vector3()) { //all is a wall @@ -1016,7 +1050,7 @@ void CharacterBody3D::move_and_slide() { floor_velocity = result.collider_velocity; if (stop_on_slope) { - if ((body_velocity_normal + up_direction).length() < 0.01 && result.motion.length() < 1) { + if ((body_velocity_normal + up_direction).length() < 0.01) { Transform3D gt = get_global_transform(); gt.origin -= result.motion.slide(up_direction); set_global_transform(gt); @@ -1031,22 +1065,26 @@ void CharacterBody3D::move_and_slide() { } } - motion = motion.slide(result.collision_normal); - linear_velocity = linear_velocity.slide(result.collision_normal); + if (sliding_enabled || !on_floor) { + motion = result.remainder.slide(result.collision_normal); + linear_velocity = linear_velocity.slide(result.collision_normal); - for (int j = 0; j < 3; j++) { - if (locked_axis & (1 << j)) { - linear_velocity[j] = 0.0; + for (int j = 0; j < 3; j++) { + if (locked_axis & (1 << j)) { + linear_velocity[j] = 0.0; + } } + } else { + motion = result.remainder; } } + + sliding_enabled = true; } if (!found_collision || motion == Vector3()) { break; } - - --slide_count; } if (!was_on_floor || snap == Vector3()) { @@ -1168,7 +1206,7 @@ Ref<KinematicCollision3D> CharacterBody3D::_get_slide_collision(int p_bounce) { } if (slide_colliders[p_bounce].is_null()) { - slide_colliders.write[p_bounce].instance(); + slide_colliders.write[p_bounce].instantiate(); slide_colliders.write[p_bounce]->owner = this; } @@ -1208,14 +1246,6 @@ void CharacterBody3D::set_floor_max_angle(real_t p_radians) { floor_max_angle = p_radians; } -real_t CharacterBody3D::get_floor_max_angle_degrees() const { - return Math::rad2deg(floor_max_angle); -} - -void CharacterBody3D::set_floor_max_angle_degrees(real_t p_degrees) { - floor_max_angle = Math::deg2rad(p_degrees); -} - const Vector3 &CharacterBody3D::get_snap() const { return snap; } @@ -1233,14 +1263,16 @@ void CharacterBody3D::set_up_direction(const Vector3 &p_up_direction) { } void CharacterBody3D::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE) { - // Reset move_and_slide() data. - on_floor = false; - on_floor_body = RID(); - on_ceiling = false; - on_wall = false; - motion_results.clear(); - floor_velocity = Vector3(); + switch (p_what) { + case NOTIFICATION_ENTER_TREE: { + // Reset move_and_slide() data. + on_floor = false; + on_floor_body = RID(); + on_ceiling = false; + on_wall = false; + motion_results.clear(); + floor_velocity = Vector3(); + } break; } } @@ -1260,8 +1292,6 @@ void CharacterBody3D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_max_slides", "max_slides"), &CharacterBody3D::set_max_slides); ClassDB::bind_method(D_METHOD("get_floor_max_angle"), &CharacterBody3D::get_floor_max_angle); ClassDB::bind_method(D_METHOD("set_floor_max_angle", "radians"), &CharacterBody3D::set_floor_max_angle); - ClassDB::bind_method(D_METHOD("get_floor_max_angle_degrees"), &CharacterBody3D::get_floor_max_angle_degrees); - ClassDB::bind_method(D_METHOD("set_floor_max_angle_degrees", "degrees"), &CharacterBody3D::set_floor_max_angle_degrees); ClassDB::bind_method(D_METHOD("get_snap"), &CharacterBody3D::get_snap); ClassDB::bind_method(D_METHOD("set_snap", "snap"), &CharacterBody3D::set_snap); ClassDB::bind_method(D_METHOD("get_up_direction"), &CharacterBody3D::get_up_direction); @@ -1280,8 +1310,7 @@ void CharacterBody3D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "stop_on_slope"), "set_stop_on_slope_enabled", "is_stop_on_slope_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "infinite_inertia"), "set_infinite_inertia_enabled", "is_infinite_inertia_enabled"); ADD_PROPERTY(PropertyInfo(Variant::INT, "max_slides"), "set_max_slides", "get_max_slides"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "floor_max_angle", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_floor_max_angle", "get_floor_max_angle"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "floor_max_angle_degrees", PROPERTY_HINT_RANGE, "0,180,0.1", PROPERTY_USAGE_EDITOR), "set_floor_max_angle_degrees", "get_floor_max_angle_degrees"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "floor_max_angle", PROPERTY_HINT_RANGE, "0,180,0.1,radians"), "set_floor_max_angle", "get_floor_max_angle"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "snap"), "set_snap", "get_snap"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "up_direction"), "set_up_direction", "get_up_direction"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "collision/safe_margin", PROPERTY_HINT_RANGE, "0.001,256,0.001"), "set_safe_margin", "get_safe_margin"); @@ -2095,7 +2124,8 @@ void PhysicalBone3D::_notification(int p_what) { _reload_joint(); } break; - case NOTIFICATION_EXIT_TREE: + + case NOTIFICATION_EXIT_TREE: { if (parent_skeleton) { if (-1 != bone_id) { parent_skeleton->unbind_physical_bone_from_bone(bone_id); @@ -2105,12 +2135,13 @@ void PhysicalBone3D::_notification(int p_what) { } parent_skeleton = nullptr; PhysicsServer3D::get_singleton()->joint_clear(joint); - break; - case NOTIFICATION_TRANSFORM_CHANGED: + } break; + + case NOTIFICATION_TRANSFORM_CHANGED: { if (Engine::get_singleton()->is_editor_hint()) { update_offset(); } - break; + } break; } } @@ -2156,8 +2187,6 @@ void PhysicalBone3D::_bind_methods() { ClassDB::bind_method(D_METHOD("get_joint_offset"), &PhysicalBone3D::get_joint_offset); ClassDB::bind_method(D_METHOD("set_joint_rotation", "euler"), &PhysicalBone3D::set_joint_rotation); ClassDB::bind_method(D_METHOD("get_joint_rotation"), &PhysicalBone3D::get_joint_rotation); - ClassDB::bind_method(D_METHOD("set_joint_rotation_degrees", "euler_degrees"), &PhysicalBone3D::set_joint_rotation_degrees); - ClassDB::bind_method(D_METHOD("get_joint_rotation_degrees"), &PhysicalBone3D::get_joint_rotation_degrees); ClassDB::bind_method(D_METHOD("set_body_offset", "offset"), &PhysicalBone3D::set_body_offset); ClassDB::bind_method(D_METHOD("get_body_offset"), &PhysicalBone3D::get_body_offset); @@ -2192,12 +2221,11 @@ void PhysicalBone3D::_bind_methods() { ADD_GROUP("Joint", "joint_"); ADD_PROPERTY(PropertyInfo(Variant::INT, "joint_type", PROPERTY_HINT_ENUM, "None,PinJoint,ConeJoint,HingeJoint,SliderJoint,6DOFJoint"), "set_joint_type", "get_joint_type"); ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM3D, "joint_offset"), "set_joint_offset", "get_joint_offset"); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "joint_rotation_degrees", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_joint_rotation_degrees", "get_joint_rotation_degrees"); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "joint_rotation", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_joint_rotation", "get_joint_rotation"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "joint_rotation", PROPERTY_HINT_RANGE, "-360,360,0.01,or_lesser,or_greater,radians"), "set_joint_rotation", "get_joint_rotation"); ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM3D, "body_offset"), "set_body_offset", "get_body_offset"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "mass", PROPERTY_HINT_EXP_RANGE, "0.01,65535,0.01"), "set_mass", "get_mass"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "mass", PROPERTY_HINT_RANGE, "0.01,65535,0.01,exp"), "set_mass", "get_mass"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "friction", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_friction", "get_friction"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "bounce", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_bounce", "get_bounce"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "gravity_scale", PROPERTY_HINT_RANGE, "-10,10,0.01"), "set_gravity_scale", "get_gravity_scale"); @@ -2428,14 +2456,6 @@ Vector3 PhysicalBone3D::get_joint_rotation() const { return joint_offset.basis.get_rotation(); } -void PhysicalBone3D::set_joint_rotation_degrees(const Vector3 &p_euler_deg) { - set_joint_rotation(p_euler_deg * (Math_PI / 180.0)); -} - -Vector3 PhysicalBone3D::get_joint_rotation_degrees() const { - return get_joint_rotation() * (180.0 / Math_PI); -} - const Transform3D &PhysicalBone3D::get_body_offset() const { return body_offset; } @@ -2605,7 +2625,7 @@ void PhysicalBone3D::_start_physics_simulation() { return; } reset_to_rest_position(); - PhysicsServer3D::get_singleton()->body_set_mode(get_rid(), PhysicsServer3D::BODY_MODE_DYNAMIC); + set_body_mode(PhysicsServer3D::BODY_MODE_DYNAMIC); PhysicsServer3D::get_singleton()->body_set_collision_layer(get_rid(), get_collision_layer()); PhysicsServer3D::get_singleton()->body_set_collision_mask(get_rid(), get_collision_mask()); PhysicsServer3D::get_singleton()->body_set_force_integration_callback(get_rid(), callable_mp(this, &PhysicalBone3D::_direct_state_changed)); @@ -2618,11 +2638,11 @@ void PhysicalBone3D::_stop_physics_simulation() { return; } if (parent_skeleton->get_animate_physical_bones()) { - PhysicsServer3D::get_singleton()->body_set_mode(get_rid(), PhysicsServer3D::BODY_MODE_KINEMATIC); + set_body_mode(PhysicsServer3D::BODY_MODE_KINEMATIC); PhysicsServer3D::get_singleton()->body_set_collision_layer(get_rid(), get_collision_layer()); PhysicsServer3D::get_singleton()->body_set_collision_mask(get_rid(), get_collision_mask()); } else { - PhysicsServer3D::get_singleton()->body_set_mode(get_rid(), PhysicsServer3D::BODY_MODE_STATIC); + set_body_mode(PhysicsServer3D::BODY_MODE_STATIC); PhysicsServer3D::get_singleton()->body_set_collision_layer(get_rid(), 0); PhysicsServer3D::get_singleton()->body_set_collision_mask(get_rid(), 0); } diff --git a/scene/3d/physics_body_3d.h b/scene/3d/physics_body_3d.h index 7d7adf1624..9d45ce3799 100644 --- a/scene/3d/physics_body_3d.h +++ b/scene/3d/physics_body_3d.h @@ -53,7 +53,7 @@ protected: Ref<KinematicCollision3D> _move(const Vector3 &p_motion, bool p_infinite_inertia = true, bool p_exclude_raycast_shapes = true, bool p_test_only = false, real_t p_margin = 0.001); public: - bool move_and_collide(const Vector3 &p_motion, bool p_infinite_inertia, PhysicsServer3D::MotionResult &r_result, real_t p_margin, bool p_exclude_raycast_shapes = true, bool p_test_only = false); + bool move_and_collide(const Vector3 &p_motion, bool p_infinite_inertia, PhysicsServer3D::MotionResult &r_result, real_t p_margin, bool p_exclude_raycast_shapes = true, bool p_test_only = false, bool p_cancel_sliding = true); bool test_move(const Transform3D &p_from, const Vector3 &p_motion, bool p_infinite_inertia = true, bool p_exclude_raycast_shapes = true, const Ref<KinematicCollision3D> &r_collision = Ref<KinematicCollision3D>(), real_t p_margin = 0.001); void set_axis_lock(PhysicsServer3D::BodyAxis p_axis, bool p_lock); @@ -307,9 +307,6 @@ private: real_t get_floor_max_angle() const; void set_floor_max_angle(real_t p_radians); - real_t get_floor_max_angle_degrees() const; - void set_floor_max_angle_degrees(real_t p_degrees); - const Vector3 &get_snap() const; void set_snap(const Vector3 &p_snap); @@ -551,9 +548,6 @@ public: void set_joint_rotation(const Vector3 &p_euler_rad); Vector3 get_joint_rotation() const; - void set_joint_rotation_degrees(const Vector3 &p_euler_deg); - Vector3 get_joint_rotation_degrees() const; - void set_body_offset(const Transform3D &p_offset); const Transform3D &get_body_offset() const; diff --git a/scene/3d/ray_cast_3d.cpp b/scene/3d/ray_cast_3d.cpp index db841101e5..dfab3d4a17 100644 --- a/scene/3d/ray_cast_3d.cpp +++ b/scene/3d/ray_cast_3d.cpp @@ -419,6 +419,8 @@ void RayCast3D::_update_debug_shape_material(bool p_check_collision) { debug_material = material; material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED); + // Use double-sided rendering so that the RayCast can be seen if the camera is inside. + material->set_cull_mode(BaseMaterial3D::CULL_DISABLED); material->set_transparency(BaseMaterial3D::TRANSPARENCY_ALPHA); } diff --git a/scene/3d/reflection_probe.cpp b/scene/3d/reflection_probe.cpp index 7762156b4a..c289fc4fd7 100644 --- a/scene/3d/reflection_probe.cpp +++ b/scene/3d/reflection_probe.cpp @@ -232,7 +232,7 @@ void ReflectionProbe::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "update_mode", PROPERTY_HINT_ENUM, "Once (Fast),Always (Slow)"), "set_update_mode", "get_update_mode"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "intensity", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_intensity", "get_intensity"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "max_distance", PROPERTY_HINT_EXP_RANGE, "0,16384,0.1,or_greater"), "set_max_distance", "get_max_distance"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "max_distance", PROPERTY_HINT_RANGE, "0,16384,0.1,or_greater,exp"), "set_max_distance", "get_max_distance"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "extents"), "set_extents", "get_extents"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "origin_offset"), "set_origin_offset", "get_origin_offset"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "box_projection"), "set_enable_box_projection", "is_box_projection_enabled"); diff --git a/scene/3d/reflection_probe.h b/scene/3d/reflection_probe.h index 15c2da3ae0..4bf20c89c5 100644 --- a/scene/3d/reflection_probe.h +++ b/scene/3d/reflection_probe.h @@ -55,7 +55,7 @@ private: RID probe; float intensity = 1.0; float max_distance = 0.0; - Vector3 extents = Vector3(1, 1, 1); + Vector3 extents = Vector3(10, 10, 10); Vector3 origin_offset = Vector3(0, 0, 0); bool box_projection = false; bool enable_shadows = false; diff --git a/scene/3d/remote_transform_3d.cpp b/scene/3d/remote_transform_3d.cpp index a7b3a6f1ec..d5fb1fa6ab 100644 --- a/scene/3d/remote_transform_3d.cpp +++ b/scene/3d/remote_transform_3d.cpp @@ -34,7 +34,7 @@ void RemoteTransform3D::_update_cache() { cache = ObjectID(); if (has_node(remote_node)) { Node *node = get_node(remote_node); - if (!node || this == node || node->is_a_parent_of(this) || this->is_a_parent_of(node)) { + if (!node || this == node || node->is_ancestor_of(this) || this->is_ancestor_of(node)) { return; } diff --git a/scene/3d/skeleton_3d.cpp b/scene/3d/skeleton_3d.cpp index f9d613a4bb..fa3b16935c 100644 --- a/scene/3d/skeleton_3d.cpp +++ b/scene/3d/skeleton_3d.cpp @@ -797,7 +797,7 @@ Ref<SkinReference> Skeleton3D::register_skin(const Ref<Skin> &p_skin) { //when skeletons did not support skins. It is also used by gizmo //to display the skeleton. - skin.instance(); + skin.instantiate(); skin->set_bind_count(bones.size()); _update_process_order(); //just in case @@ -826,7 +826,7 @@ Ref<SkinReference> Skeleton3D::register_skin(const Ref<Skin> &p_skin) { ERR_FAIL_COND_V(skin.is_null(), Ref<SkinReference>()); Ref<SkinReference> skin_ref; - skin_ref.instance(); + skin_ref.instantiate(); skin_ref->skeleton_node = this; skin_ref->bind_count = 0; diff --git a/scene/3d/soft_body_3d.cpp b/scene/3d/soft_body_3d.cpp index df5474d03e..efd8a2b50c 100644 --- a/scene/3d/soft_body_3d.cpp +++ b/scene/3d/soft_body_3d.cpp @@ -81,7 +81,7 @@ void SoftBodyRenderingServerHandler::close() { } void SoftBodyRenderingServerHandler::commit_changes() { - RS::get_singleton()->mesh_surface_update_region(mesh, surface, 0, buffer); + RS::get_singleton()->mesh_surface_update_vertex_region(mesh, surface, 0, buffer); } void SoftBodyRenderingServerHandler::set_vertex(int p_vertex_id, const void *p_vector3) { @@ -266,12 +266,13 @@ void SoftBody3D::_notification(int p_what) { PhysicsServer3D::get_singleton()->soft_body_set_space(physics_rid, space); prepare_physics_server(); } break; + case NOTIFICATION_READY: { if (!parent_collision_ignore.is_empty()) { add_collision_exception_with(get_node(parent_collision_ignore)); } - } break; + case NOTIFICATION_TRANSFORM_CHANGED: { if (Engine::get_singleton()->is_editor_hint()) { _reset_points_offsets(); @@ -285,27 +286,36 @@ void SoftBody3D::_notification(int p_what) { set_as_top_level(true); set_transform(Transform3D()); set_notify_transform(true); - } break; + case NOTIFICATION_VISIBILITY_CHANGED: { _update_pickable(); - } break; + case NOTIFICATION_EXIT_WORLD: { PhysicsServer3D::get_singleton()->soft_body_set_space(physics_rid, RID()); - } break; - } -#ifdef TOOLS_ENABLED + case NOTIFICATION_DISABLED: { + if (is_inside_tree() && (disable_mode == DISABLE_MODE_REMOVE)) { + prepare_physics_server(); + } + } break; - if (p_what == NOTIFICATION_LOCAL_TRANSFORM_CHANGED) { - if (Engine::get_singleton()->is_editor_hint()) { - update_configuration_warnings(); - } - } + case NOTIFICATION_ENABLED: { + if (is_inside_tree() && (disable_mode == DISABLE_MODE_REMOVE)) { + prepare_physics_server(); + } + } break; +#ifdef TOOLS_ENABLED + case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: { + if (Engine::get_singleton()->is_editor_hint()) { + update_configuration_warnings(); + } + } break; #endif + } } void SoftBody3D::_bind_methods() { @@ -326,6 +336,9 @@ void SoftBody3D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_parent_collision_ignore", "parent_collision_ignore"), &SoftBody3D::set_parent_collision_ignore); ClassDB::bind_method(D_METHOD("get_parent_collision_ignore"), &SoftBody3D::get_parent_collision_ignore); + ClassDB::bind_method(D_METHOD("set_disable_mode", "mode"), &SoftBody3D::set_disable_mode); + ClassDB::bind_method(D_METHOD("get_disable_mode"), &SoftBody3D::get_disable_mode); + ClassDB::bind_method(D_METHOD("get_collision_exceptions"), &SoftBody3D::get_collision_exceptions); ClassDB::bind_method(D_METHOD("add_collision_exception_with", "body"), &SoftBody3D::add_collision_exception_with); ClassDB::bind_method(D_METHOD("remove_collision_exception_with", "body"), &SoftBody3D::remove_collision_exception_with); @@ -364,6 +377,11 @@ void SoftBody3D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "drag_coefficient", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_drag_coefficient", "get_drag_coefficient"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "ray_pickable"), "set_ray_pickable", "is_ray_pickable"); + + ADD_PROPERTY(PropertyInfo(Variant::INT, "disable_mode", PROPERTY_HINT_ENUM, "Remove,KeepActive"), "set_disable_mode", "get_disable_mode"); + + BIND_ENUM_CONSTANT(DISABLE_MODE_REMOVE); + BIND_ENUM_CONSTANT(DISABLE_MODE_KEEP_ACTIVE); } TypedArray<String> SoftBody3D::get_configuration_warnings() const { @@ -421,6 +439,7 @@ void SoftBody3D::_draw_soft_mesh() { } void SoftBody3D::prepare_physics_server() { +#ifdef TOOLS_ENABLED if (Engine::get_singleton()->is_editor_hint()) { if (get_mesh().is_valid()) { PhysicsServer3D::get_singleton()->soft_body_set_mesh(physics_rid, get_mesh()); @@ -430,8 +449,9 @@ void SoftBody3D::prepare_physics_server() { return; } +#endif - if (get_mesh().is_valid()) { + if (get_mesh().is_valid() && (is_enabled() || (disable_mode != DISABLE_MODE_REMOVE))) { become_mesh_owner(); PhysicsServer3D::get_singleton()->soft_body_set_mesh(physics_rid, get_mesh()); RS::get_singleton()->connect("frame_pre_draw", callable_mp(this, &SoftBody3D::_draw_soft_mesh)); @@ -465,7 +485,7 @@ void SoftBody3D::become_mesh_owner() { surface_format |= Mesh::ARRAY_FLAG_USE_DYNAMIC_UPDATE; Ref<ArrayMesh> soft_mesh; - soft_mesh.instance(); + soft_mesh.instantiate(); soft_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, surface_arrays, surface_blend_arrays, surface_lods, surface_format); soft_mesh->surface_set_material(0, mesh->surface_get_material(0)); @@ -527,6 +547,28 @@ bool SoftBody3D::get_collision_layer_bit(int p_bit) const { return get_collision_layer() & (1 << p_bit); } +void SoftBody3D::set_disable_mode(DisableMode p_mode) { + if (disable_mode == p_mode) { + return; + } + + bool inside_tree = is_inside_tree(); + + if (inside_tree && (disable_mode == DISABLE_MODE_REMOVE)) { + prepare_physics_server(); + } + + disable_mode = p_mode; + + if (inside_tree && (disable_mode == DISABLE_MODE_REMOVE)) { + prepare_physics_server(); + } +} + +SoftBody3D::DisableMode SoftBody3D::get_disable_mode() const { + return disable_mode; +} + void SoftBody3D::set_parent_collision_ignore(const NodePath &p_parent_collision_ignore) { parent_collision_ignore = p_parent_collision_ignore; } diff --git a/scene/3d/soft_body_3d.h b/scene/3d/soft_body_3d.h index 0d0d39d48f..81aa0c10c6 100644 --- a/scene/3d/soft_body_3d.h +++ b/scene/3d/soft_body_3d.h @@ -67,6 +67,11 @@ class SoftBody3D : public MeshInstance3D { GDCLASS(SoftBody3D, MeshInstance3D); public: + enum DisableMode { + DISABLE_MODE_REMOVE, + DISABLE_MODE_KEEP_ACTIVE, + }; + struct PinnedPoint { int point_index = -1; NodePath spatial_attachment_path; @@ -83,6 +88,8 @@ private: RID physics_rid; + DisableMode disable_mode = DISABLE_MODE_REMOVE; + bool mesh_owner = false; uint32_t collision_mask = 1; uint32_t collision_layer = 1; @@ -137,6 +144,9 @@ public: void set_collision_layer_bit(int p_bit, bool p_value); bool get_collision_layer_bit(int p_bit) const; + void set_disable_mode(DisableMode p_mode); + DisableMode get_disable_mode() const; + void set_parent_collision_ignore(const NodePath &p_parent_collision_ignore); const NodePath &get_parent_collision_ignore() const; @@ -192,4 +202,6 @@ private: int _has_pinned_point(int p_point_index) const; }; +VARIANT_ENUM_CAST(SoftBody3D::DisableMode); + #endif // SOFT_PHYSICS_BODY_H diff --git a/scene/3d/sprite_3d.cpp b/scene/3d/sprite_3d.cpp index 9ec461d973..13f8002721 100644 --- a/scene/3d/sprite_3d.cpp +++ b/scene/3d/sprite_3d.cpp @@ -164,6 +164,8 @@ void SpriteBase3D::_im_update() { _draw(); pending_update = false; + + //texture->draw_rect_region(ci,dst_rect,src_rect,modulate); } void SpriteBase3D::_queue_update() { @@ -204,6 +206,7 @@ Ref<TriangleMesh> SpriteBase3D::generate_triangle_mesh() const { float pixel_size = get_pixel_size(); Vector2 vertices[4] = { + (final_rect.position + Vector2(0, final_rect.size.y)) * pixel_size, (final_rect.position + final_rect.size) * pixel_size, (final_rect.position + Vector2(final_rect.size.x, 0)) * pixel_size, @@ -313,6 +316,9 @@ void SpriteBase3D::_bind_methods() { ClassDB::bind_method(D_METHOD("get_item_rect"), &SpriteBase3D::get_item_rect); ClassDB::bind_method(D_METHOD("generate_triangle_mesh"), &SpriteBase3D::generate_triangle_mesh); + ClassDB::bind_method(D_METHOD("_queue_update"), &SpriteBase3D::_queue_update); + ClassDB::bind_method(D_METHOD("_im_update"), &SpriteBase3D::_im_update); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "centered"), "set_centered", "is_centered"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "offset"), "set_offset", "get_offset"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "flip_h"), "set_flip_h", "is_flipped_h"); @@ -343,21 +349,89 @@ SpriteBase3D::SpriteBase3D() { flags[i] = i == FLAG_TRANSPARENT || i == FLAG_DOUBLE_SIDED; } - immediate = RenderingServer::get_singleton()->immediate_create(); - set_base(immediate); + material = RenderingServer::get_singleton()->material_create(); + // Set defaults for material, names need to match up those in StandardMaterial3D + RS::get_singleton()->material_set_param(material, "albedo", Color(1, 1, 1, 1)); + RS::get_singleton()->material_set_param(material, "specular", 0.5); + RS::get_singleton()->material_set_param(material, "metallic", 0.0); + RS::get_singleton()->material_set_param(material, "roughness", 1.0); + RS::get_singleton()->material_set_param(material, "uv1_offset", Vector3(0, 0, 0)); + RS::get_singleton()->material_set_param(material, "uv1_scale", Vector3(1, 1, 1)); + RS::get_singleton()->material_set_param(material, "uv2_offset", Vector3(0, 0, 0)); + RS::get_singleton()->material_set_param(material, "uv2_scale", Vector3(1, 1, 1)); + RS::get_singleton()->material_set_param(material, "alpha_scissor_threshold", 0.98); + + mesh = RenderingServer::get_singleton()->mesh_create(); + + PackedVector3Array mesh_vertices; + PackedVector3Array mesh_normals; + PackedFloat32Array mesh_tangents; + PackedColorArray mesh_colors; + PackedVector2Array mesh_uvs; + PackedInt32Array indices; + + mesh_vertices.resize(4); + mesh_normals.resize(4); + mesh_tangents.resize(16); + mesh_colors.resize(4); + mesh_uvs.resize(4); + + // create basic mesh and store format information + for (int i = 0; i < 4; i++) { + mesh_normals.write[i] = Vector3(0.0, 0.0, 0.0); + mesh_tangents.write[i * 4 + 0] = 0.0; + mesh_tangents.write[i * 4 + 1] = 0.0; + mesh_tangents.write[i * 4 + 2] = 0.0; + mesh_tangents.write[i * 4 + 3] = 0.0; + mesh_colors.write[i] = Color(1.0, 1.0, 1.0, 1.0); + mesh_uvs.write[i] = Vector2(0.0, 0.0); + mesh_vertices.write[i] = Vector3(0.0, 0.0, 0.0); + } + + indices.resize(6); + indices.write[0] = 0; + indices.write[1] = 1; + indices.write[2] = 2; + indices.write[3] = 0; + indices.write[4] = 2; + indices.write[5] = 3; + + Array mesh_array; + mesh_array.resize(RS::ARRAY_MAX); + mesh_array[RS::ARRAY_VERTEX] = mesh_vertices; + mesh_array[RS::ARRAY_NORMAL] = mesh_normals; + mesh_array[RS::ARRAY_TANGENT] = mesh_tangents; + mesh_array[RS::ARRAY_COLOR] = mesh_colors; + mesh_array[RS::ARRAY_TEX_UV] = mesh_uvs; + mesh_array[RS::ARRAY_INDEX] = indices; + + RS::SurfaceData sd; + RS::get_singleton()->mesh_create_surface_data_from_arrays(&sd, RS::PRIMITIVE_TRIANGLES, mesh_array); + + mesh_surface_format = sd.format; + vertex_buffer = sd.vertex_data; + attribute_buffer = sd.attribute_data; + + sd.material = material; + + RS::get_singleton()->mesh_surface_make_offsets_from_format(sd.format, sd.vertex_count, sd.index_count, mesh_surface_offsets, vertex_stride, attrib_stride, skin_stride); + RS::get_singleton()->mesh_add_surface(mesh, sd); + set_base(mesh); } SpriteBase3D::~SpriteBase3D() { - RenderingServer::get_singleton()->free(immediate); + RenderingServer::get_singleton()->free(mesh); + RenderingServer::get_singleton()->free(material); } /////////////////////////////////////////// void Sprite3D::_draw() { - RID immediate = get_immediate(); - - RS::get_singleton()->immediate_clear(immediate); + if (get_base() != get_mesh()) { + set_base(get_mesh()); + } if (!texture.is_valid()) { + set_base(RID()); return; } Vector2 tsize = texture->get_size(); @@ -366,7 +440,7 @@ void Sprite3D::_draw() { } Rect2 base_rect; - if (region_enabled) { + if (region) { base_rect = region_rect; } else { base_rect = Rect2(0, 0, texture->get_width(), texture->get_height()); @@ -399,6 +473,7 @@ void Sprite3D::_draw() { float pixel_size = get_pixel_size(); Vector2 vertices[4] = { + (final_rect.position + Vector2(0, final_rect.size.y)) * pixel_size, (final_rect.position + final_rect.size) * pixel_size, (final_rect.position + Vector2(final_rect.size.x, 0)) * pixel_size, @@ -426,6 +501,7 @@ void Sprite3D::_draw() { SWAP(uvs[0], uvs[1]); SWAP(uvs[2], uvs[3]); } + if (is_flipped_v()) { SWAP(uvs[0], uvs[3]); SWAP(uvs[1], uvs[2]); @@ -442,11 +518,6 @@ void Sprite3D::_draw() { tangent = Plane(1, 0, 0, 1); } - RID mat = StandardMaterial3D::get_material_rid_for_2d(get_draw_flag(FLAG_SHADED), get_draw_flag(FLAG_TRANSPARENT), get_draw_flag(FLAG_DOUBLE_SIDED), get_alpha_cut_mode() == ALPHA_CUT_DISCARD, get_alpha_cut_mode() == ALPHA_CUT_OPAQUE_PREPASS, get_billboard_mode() == StandardMaterial3D::BILLBOARD_ENABLED, get_billboard_mode() == StandardMaterial3D::BILLBOARD_FIXED_Y); - RS::get_singleton()->immediate_set_material(immediate, mat); - - RS::get_singleton()->immediate_begin(immediate, RS::PRIMITIVE_TRIANGLES, texture->get_rid()); - int x_axis = ((axis + 1) % 3); int y_axis = ((axis + 2) % 3); @@ -466,31 +537,80 @@ void Sprite3D::_draw() { AABB aabb; - for (int i = 0; i < 6; i++) { - static const int index[6] = { 0, 1, 2, 0, 2, 3 }; + // Everything except position and UV is compressed + uint8_t *vertex_write_buffer = vertex_buffer.ptrw(); + uint8_t *attribute_write_buffer = attribute_buffer.ptrw(); + + uint32_t v_normal; + { + Vector3 n = normal * Vector3(0.5, 0.5, 0.5) + Vector3(0.5, 0.5, 0.5); + + uint32_t value = 0; + value |= CLAMP(int(n.x * 1023.0), 0, 1023); + value |= CLAMP(int(n.y * 1023.0), 0, 1023) << 10; + value |= CLAMP(int(n.z * 1023.0), 0, 1023) << 20; + + v_normal = value; + } + uint32_t v_tangent; + { + Plane t = tangent; + uint32_t value = 0; + value |= CLAMP(int((t.normal.x * 0.5 + 0.5) * 1023.0), 0, 1023); + value |= CLAMP(int((t.normal.y * 0.5 + 0.5) * 1023.0), 0, 1023) << 10; + value |= CLAMP(int((t.normal.z * 0.5 + 0.5) * 1023.0), 0, 1023) << 20; + if (t.d > 0) { + value |= 3 << 30; + } + v_tangent = value; + } - RS::get_singleton()->immediate_normal(immediate, normal); - RS::get_singleton()->immediate_tangent(immediate, tangent); - RS::get_singleton()->immediate_color(immediate, color); - RS::get_singleton()->immediate_uv(immediate, uvs[index[i]]); + uint8_t v_color[4] = { + uint8_t(CLAMP(color.r * 255.0, 0.0, 255.0)), + uint8_t(CLAMP(color.g * 255.0, 0.0, 255.0)), + uint8_t(CLAMP(color.b * 255.0, 0.0, 255.0)), + uint8_t(CLAMP(color.a * 255.0, 0.0, 255.0)) + }; + for (int i = 0; i < 4; i++) { Vector3 vtx; - vtx[x_axis] = vertices[index[i]][0]; - vtx[y_axis] = vertices[index[i]][1]; - RS::get_singleton()->immediate_vertex(immediate, vtx); + vtx[x_axis] = vertices[i][0]; + vtx[y_axis] = vertices[i][1]; if (i == 0) { aabb.position = vtx; aabb.size = Vector3(); } else { aabb.expand_to(vtx); } + + float v_uv[2] = { uvs[i].x, uvs[i].y }; + memcpy(&attribute_write_buffer[i * attrib_stride + mesh_surface_offsets[RS::ARRAY_TEX_UV]], v_uv, 8); + + float v_vertex[3] = { vtx.x, vtx.y, vtx.z }; + + memcpy(&vertex_write_buffer[i * vertex_stride + mesh_surface_offsets[RS::ARRAY_VERTEX]], &v_vertex, sizeof(float) * 3); + memcpy(&vertex_write_buffer[i * vertex_stride + mesh_surface_offsets[RS::ARRAY_NORMAL]], &v_normal, 4); + memcpy(&vertex_write_buffer[i * vertex_stride + mesh_surface_offsets[RS::ARRAY_TANGENT]], &v_tangent, 4); + memcpy(&attribute_write_buffer[i * attrib_stride + mesh_surface_offsets[RS::ARRAY_COLOR]], v_color, 4); } + + RID mesh = get_mesh(); + RS::get_singleton()->mesh_surface_update_vertex_region(mesh, 0, 0, vertex_buffer); + RS::get_singleton()->mesh_surface_update_attribute_region(mesh, 0, 0, attribute_buffer); + + RS::get_singleton()->mesh_set_custom_aabb(mesh, aabb); set_aabb(aabb); - RS::get_singleton()->immediate_end(immediate); -} -void Sprite3D::_texture_changed() { - _queue_update(); + RID shader_rid; + StandardMaterial3D::get_material_for_2d(get_draw_flag(FLAG_SHADED), get_draw_flag(FLAG_TRANSPARENT), get_draw_flag(FLAG_DOUBLE_SIDED), get_alpha_cut_mode() == ALPHA_CUT_DISCARD, get_alpha_cut_mode() == ALPHA_CUT_OPAQUE_PREPASS, get_billboard_mode() == StandardMaterial3D::BILLBOARD_ENABLED, get_billboard_mode() == StandardMaterial3D::BILLBOARD_FIXED_Y, &shader_rid); + if (last_shader != shader_rid) { + RS::get_singleton()->material_set_shader(get_material(), shader_rid); + last_shader = shader_rid; + } + if (last_texture != texture->get_rid()) { + RS::get_singleton()->material_set_param(get_material(), "texture_albedo", texture->get_rid()); + last_texture = texture->get_rid(); + } } void Sprite3D::set_texture(const Ref<Texture2D> &p_texture) { @@ -498,38 +618,36 @@ void Sprite3D::set_texture(const Ref<Texture2D> &p_texture) { return; } if (texture.is_valid()) { - texture->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &Sprite3D::_texture_changed)); + texture->disconnect(CoreStringNames::get_singleton()->changed, Callable(this, "_queue_update")); } texture = p_texture; if (texture.is_valid()) { - texture->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &Sprite3D::_texture_changed)); + texture->connect(CoreStringNames::get_singleton()->changed, Callable(this, "_queue_update")); } _queue_update(); - emit_signal(SceneStringNames::get_singleton()->texture_changed); } Ref<Texture2D> Sprite3D::get_texture() const { return texture; } -void Sprite3D::set_region_enabled(bool p_region_enabled) { - if (p_region_enabled == region_enabled) { +void Sprite3D::set_region_enabled(bool p_region) { + if (p_region == region) { return; } - region_enabled = p_region_enabled; + region = p_region; _queue_update(); - notify_property_list_changed(); } bool Sprite3D::is_region_enabled() const { - return region_enabled; + return region; } void Sprite3D::set_region_rect(const Rect2 &p_region_rect) { bool changed = region_rect != p_region_rect; region_rect = p_region_rect; - if (region_enabled && changed) { + if (region && changed) { _queue_update(); } } @@ -596,7 +714,7 @@ Rect2 Sprite3D::get_item_rect() const { Size2i s; - if (region_enabled) { + if (region) { s = region_rect.size; } else { s = texture->get_size(); @@ -625,10 +743,6 @@ void Sprite3D::_validate_property(PropertyInfo &property) const { if (property.name == "frame_coords") { property.usage |= PROPERTY_USAGE_KEYING_INCREMENTS; } - - if (!region_enabled && property.name == "region_rect") { - property.usage = PROPERTY_USAGE_NOEDITOR; - } } void Sprite3D::_bind_methods() { @@ -653,32 +767,28 @@ void Sprite3D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_hframes", "hframes"), &Sprite3D::set_hframes); ClassDB::bind_method(D_METHOD("get_hframes"), &Sprite3D::get_hframes); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_texture", "get_texture"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture"); ADD_GROUP("Animation", ""); ADD_PROPERTY(PropertyInfo(Variant::INT, "hframes", PROPERTY_HINT_RANGE, "1,16384,1"), "set_hframes", "get_hframes"); ADD_PROPERTY(PropertyInfo(Variant::INT, "vframes", PROPERTY_HINT_RANGE, "1,16384,1"), "set_vframes", "get_vframes"); ADD_PROPERTY(PropertyInfo(Variant::INT, "frame"), "set_frame", "get_frame"); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "frame_coords", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_frame_coords", "get_frame_coords"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "frame_coords", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_frame_coords", "get_frame_coords"); ADD_GROUP("Region", "region_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "region_enabled"), "set_region_enabled", "is_region_enabled"); ADD_PROPERTY(PropertyInfo(Variant::RECT2, "region_rect"), "set_region_rect", "get_region_rect"); ADD_SIGNAL(MethodInfo("frame_changed")); - ADD_SIGNAL(MethodInfo("texture_changed")); } Sprite3D::Sprite3D() { - region_enabled = false; - frame = 0; - vframes = 1; - hframes = 1; } //////////////////////////////////////// void AnimatedSprite3D::_draw() { - RID immediate = get_immediate(); - RS::get_singleton()->immediate_clear(immediate); + if (get_base() != get_mesh()) { + set_base(get_mesh()); + } if (frames.is_null()) { return; @@ -694,7 +804,8 @@ void AnimatedSprite3D::_draw() { Ref<Texture2D> texture = frames->get_frame(animation, frame); if (!texture.is_valid()) { - return; //no texture no life + set_base(RID()); + return; //no texuture no life } Vector2 tsize = texture->get_size(); if (tsize.x == 0 || tsize.y == 0) { @@ -729,6 +840,7 @@ void AnimatedSprite3D::_draw() { float pixel_size = get_pixel_size(); Vector2 vertices[4] = { + (final_rect.position + Vector2(0, final_rect.size.y)) * pixel_size, (final_rect.position + final_rect.size) * pixel_size, (final_rect.position + Vector2(final_rect.size.x, 0)) * pixel_size, @@ -772,12 +884,6 @@ void AnimatedSprite3D::_draw() { tangent = Plane(1, 0, 0, -1); } - RID mat = StandardMaterial3D::get_material_rid_for_2d(get_draw_flag(FLAG_SHADED), get_draw_flag(FLAG_TRANSPARENT), get_draw_flag(FLAG_DOUBLE_SIDED), get_alpha_cut_mode() == ALPHA_CUT_DISCARD, get_alpha_cut_mode() == ALPHA_CUT_OPAQUE_PREPASS, get_billboard_mode() == StandardMaterial3D::BILLBOARD_ENABLED, get_billboard_mode() == StandardMaterial3D::BILLBOARD_FIXED_Y); - - RS::get_singleton()->immediate_set_material(immediate, mat); - - RS::get_singleton()->immediate_begin(immediate, RS::PRIMITIVE_TRIANGLES, texture->get_rid()); - int x_axis = ((axis + 1) % 3); int y_axis = ((axis + 2) % 3); @@ -797,30 +903,79 @@ void AnimatedSprite3D::_draw() { AABB aabb; - for (int i = 0; i < 6; i++) { - static const int indices[6] = { - 0, 1, 2, - 0, 2, 3 - }; + // Everything except position and UV is compressed + uint8_t *vertex_write_buffer = vertex_buffer.ptrw(); + uint8_t *attribute_write_buffer = attribute_buffer.ptrw(); + + uint32_t v_normal; + { + Vector3 n = normal * Vector3(0.5, 0.5, 0.5) + Vector3(0.5, 0.5, 0.5); + + uint32_t value = 0; + value |= CLAMP(int(n.x * 1023.0), 0, 1023); + value |= CLAMP(int(n.y * 1023.0), 0, 1023) << 10; + value |= CLAMP(int(n.z * 1023.0), 0, 1023) << 20; + + v_normal = value; + } + uint32_t v_tangent; + { + Plane t = tangent; + uint32_t value = 0; + value |= CLAMP(int((t.normal.x * 0.5 + 0.5) * 1023.0), 0, 1023); + value |= CLAMP(int((t.normal.y * 0.5 + 0.5) * 1023.0), 0, 1023) << 10; + value |= CLAMP(int((t.normal.z * 0.5 + 0.5) * 1023.0), 0, 1023) << 20; + if (t.d > 0) { + value |= 3 << 30; + } + v_tangent = value; + } - RS::get_singleton()->immediate_normal(immediate, normal); - RS::get_singleton()->immediate_tangent(immediate, tangent); - RS::get_singleton()->immediate_color(immediate, color); - RS::get_singleton()->immediate_uv(immediate, uvs[indices[i]]); + uint8_t v_color[4] = { + uint8_t(CLAMP(color.r * 255.0, 0.0, 255.0)), + uint8_t(CLAMP(color.g * 255.0, 0.0, 255.0)), + uint8_t(CLAMP(color.b * 255.0, 0.0, 255.0)), + uint8_t(CLAMP(color.a * 255.0, 0.0, 255.0)) + }; + for (int i = 0; i < 4; i++) { Vector3 vtx; - vtx[x_axis] = vertices[indices[i]][0]; - vtx[y_axis] = vertices[indices[i]][1]; - RS::get_singleton()->immediate_vertex(immediate, vtx); + vtx[x_axis] = vertices[i][0]; + vtx[y_axis] = vertices[i][1]; if (i == 0) { aabb.position = vtx; aabb.size = Vector3(); } else { aabb.expand_to(vtx); } + + float v_uv[2] = { uvs[i].x, uvs[i].y }; + memcpy(&attribute_write_buffer[i * attrib_stride + mesh_surface_offsets[RS::ARRAY_TEX_UV]], v_uv, 8); + + float v_vertex[3] = { vtx.x, vtx.y, vtx.z }; + memcpy(&vertex_write_buffer[i * vertex_stride + mesh_surface_offsets[RS::ARRAY_VERTEX]], &v_vertex, sizeof(float) * 3); + memcpy(&vertex_write_buffer[i * vertex_stride + mesh_surface_offsets[RS::ARRAY_NORMAL]], &v_normal, 4); + memcpy(&vertex_write_buffer[i * vertex_stride + mesh_surface_offsets[RS::ARRAY_TANGENT]], &v_tangent, 4); + memcpy(&attribute_write_buffer[i * attrib_stride + mesh_surface_offsets[RS::ARRAY_COLOR]], v_color, 4); } + + RID mesh = get_mesh(); + RS::get_singleton()->mesh_surface_update_vertex_region(mesh, 0, 0, vertex_buffer); + RS::get_singleton()->mesh_surface_update_attribute_region(mesh, 0, 0, attribute_buffer); + + RS::get_singleton()->mesh_set_custom_aabb(mesh, aabb); set_aabb(aabb); - RS::get_singleton()->immediate_end(immediate); + + RID shader_rid; + StandardMaterial3D::get_material_for_2d(get_draw_flag(FLAG_SHADED), get_draw_flag(FLAG_TRANSPARENT), get_draw_flag(FLAG_DOUBLE_SIDED), get_alpha_cut_mode() == ALPHA_CUT_DISCARD, get_alpha_cut_mode() == ALPHA_CUT_OPAQUE_PREPASS, get_billboard_mode() == StandardMaterial3D::BILLBOARD_ENABLED, get_billboard_mode() == StandardMaterial3D::BILLBOARD_FIXED_Y, &shader_rid); + if (last_shader != shader_rid) { + RS::get_singleton()->material_set_shader(get_material(), shader_rid); + last_shader = shader_rid; + } + if (last_texture != texture->get_rid()) { + RS::get_singleton()->material_set_param(get_material(), "texture_albedo", texture->get_rid()); + last_texture = texture->get_rid(); + } } void AnimatedSprite3D::_validate_property(PropertyInfo &property) const { @@ -914,11 +1069,11 @@ void AnimatedSprite3D::_notification(int p_what) { void AnimatedSprite3D::set_sprite_frames(const Ref<SpriteFrames> &p_frames) { if (frames.is_valid()) { - frames->disconnect("changed", callable_mp(this, &AnimatedSprite3D::_res_changed)); + frames->disconnect("changed", Callable(this, "_res_changed")); } frames = p_frames; if (frames.is_valid()) { - frames->connect("changed", callable_mp(this, &AnimatedSprite3D::_res_changed)); + frames->connect("changed", Callable(this, "_res_changed")); } if (!frames.is_valid()) { @@ -944,9 +1099,8 @@ void AnimatedSprite3D::set_frame(int p_frame) { if (frames->has_animation(animation)) { int limit = frames->get_frame_count(animation); - if (p_frame >= limit) { + if (p_frame >= limit) p_frame = limit - 1; - } } if (p_frame < 0) { @@ -960,7 +1114,6 @@ void AnimatedSprite3D::set_frame(int p_frame) { frame = p_frame; _reset_timeout(); _queue_update(); - emit_signal(SceneStringNames::get_singleton()->frame_changed); } @@ -1061,8 +1214,7 @@ StringName AnimatedSprite3D::get_animation() const { } TypedArray<String> AnimatedSprite3D::get_configuration_warnings() const { - TypedArray<String> warnings = Node::get_configuration_warnings(); - + TypedArray<String> warnings = SpriteBase3D::get_configuration_warnings(); if (frames.is_null()) { warnings.push_back(TTR("A SpriteFrames resource must be created or set in the \"Frames\" property in order for AnimatedSprite3D to display frames.")); } @@ -1087,11 +1239,13 @@ void AnimatedSprite3D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_frame", "frame"), &AnimatedSprite3D::set_frame); ClassDB::bind_method(D_METHOD("get_frame"), &AnimatedSprite3D::get_frame); + ClassDB::bind_method(D_METHOD("_res_changed"), &AnimatedSprite3D::_res_changed); + ADD_SIGNAL(MethodInfo("frame_changed")); ADD_SIGNAL(MethodInfo("animation_finished")); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "frames", PROPERTY_HINT_RESOURCE_TYPE, "SpriteFrames"), "set_sprite_frames", "get_sprite_frames"); - ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "animation"), "set_animation", "get_animation"); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "animation"), "set_animation", "get_animation"); ADD_PROPERTY(PropertyInfo(Variant::INT, "frame"), "set_frame", "get_frame"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "playing"), "_set_playing", "_is_playing"); } diff --git a/scene/3d/sprite_3d.h b/scene/3d/sprite_3d.h index e3dd117804..404ef57e6a 100644 --- a/scene/3d/sprite_3d.h +++ b/scene/3d/sprite_3d.h @@ -31,8 +31,8 @@ #ifndef SPRITE_3D_H #define SPRITE_3D_H +#include "scene/2d/animated_sprite_2d.h" #include "scene/3d/visual_instance_3d.h" -#include "scene/resources/sprite_frames.h" class SpriteBase3D : public GeometryInstance3D { GDCLASS(SpriteBase3D, GeometryInstance3D); @@ -75,9 +75,10 @@ private: float pixel_size = 0.01; AABB aabb; - RID immediate; + RID mesh; + RID material; - bool flags[FLAG_MAX]; + bool flags[FLAG_MAX] = {}; AlphaCutMode alpha_cut = ALPHA_CUT_DISABLED; StandardMaterial3D::BillboardMode billboard_mode = StandardMaterial3D::BILLBOARD_DISABLED; bool pending_update = false; @@ -91,7 +92,17 @@ protected: static void _bind_methods(); virtual void _draw() = 0; _FORCE_INLINE_ void set_aabb(const AABB &p_aabb) { aabb = p_aabb; } - _FORCE_INLINE_ RID &get_immediate() { return immediate; } + _FORCE_INLINE_ RID &get_mesh() { return mesh; } + _FORCE_INLINE_ RID &get_material() { return material; } + + uint32_t mesh_surface_offsets[RS::ARRAY_MAX]; + PackedByteArray vertex_buffer; + PackedByteArray attribute_buffer; + uint32_t vertex_stride; + uint32_t attrib_stride; + uint32_t skin_stride; + uint32_t mesh_surface_format; + void _queue_update(); public: @@ -107,7 +118,7 @@ public: void set_flip_v(bool p_flip); bool is_flipped_v() const; - void set_region_enabled(bool p_region_enabled); + void set_region_enabled(bool p_region); bool is_region_enabled() const; void set_region_rect(const Rect2 &p_region_rect); @@ -147,15 +158,16 @@ class Sprite3D : public SpriteBase3D { GDCLASS(Sprite3D, SpriteBase3D); Ref<Texture2D> texture; - bool region_enabled; + bool region = false; Rect2 region_rect; - int frame; + int frame = 0; - int vframes; - int hframes; + int vframes = 1; + int hframes = 1; - void _texture_changed(); + RID last_shader; + RID last_texture; protected: virtual void _draw() override; @@ -167,7 +179,7 @@ public: void set_texture(const Ref<Texture2D> &p_texture); Ref<Texture2D> get_texture() const; - void set_region_enabled(bool p_region_enabled); + void set_region_enabled(bool p_region); bool is_region_enabled() const; void set_region_rect(const Rect2 &p_region_rect); @@ -199,14 +211,9 @@ class AnimatedSprite3D : public SpriteBase3D { StringName animation = "default"; int frame = 0; - bool centered = true; - - float timeout = 0.0; - - bool hflip = true; - bool vflip = true; + bool centered = false; - Color modulate; + float timeout = 0; void _res_changed(); @@ -214,6 +221,9 @@ class AnimatedSprite3D : public SpriteBase3D { void _set_playing(bool p_playing); bool _is_playing() const; + RID last_shader; + RID last_texture; + protected: virtual void _draw() override; static void _bind_methods(); @@ -236,10 +246,11 @@ public: virtual Rect2 get_item_rect() const override; - TypedArray<String> get_configuration_warnings() const override; + virtual TypedArray<String> get_configuration_warnings() const override; AnimatedSprite3D(); }; VARIANT_ENUM_CAST(SpriteBase3D::DrawFlags); VARIANT_ENUM_CAST(SpriteBase3D::AlphaCutMode); + #endif // SPRITE_3D_H diff --git a/scene/3d/vehicle_body_3d.cpp b/scene/3d/vehicle_body_3d.cpp index 0d88769b70..b0e37b81a5 100644 --- a/scene/3d/vehicle_body_3d.cpp +++ b/scene/3d/vehicle_body_3d.cpp @@ -79,26 +79,29 @@ public: }; void VehicleWheel3D::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE) { - VehicleBody3D *cb = Object::cast_to<VehicleBody3D>(get_parent()); - if (!cb) { - return; - } - body = cb; - local_xform = get_transform(); - cb->wheels.push_back(this); - - m_chassisConnectionPointCS = get_transform().origin; - m_wheelDirectionCS = -get_transform().basis.get_axis(Vector3::AXIS_Y).normalized(); - m_wheelAxleCS = get_transform().basis.get_axis(Vector3::AXIS_X).normalized(); - } - if (p_what == NOTIFICATION_EXIT_TREE) { - VehicleBody3D *cb = Object::cast_to<VehicleBody3D>(get_parent()); - if (!cb) { - return; - } - cb->wheels.erase(this); - body = nullptr; + switch (p_what) { + case NOTIFICATION_ENTER_TREE: { + VehicleBody3D *cb = Object::cast_to<VehicleBody3D>(get_parent()); + if (!cb) { + return; + } + body = cb; + local_xform = get_transform(); + cb->wheels.push_back(this); + + m_chassisConnectionPointCS = get_transform().origin; + m_wheelDirectionCS = -get_transform().basis.get_axis(Vector3::AXIS_Y).normalized(); + m_wheelAxleCS = get_transform().basis.get_axis(Vector3::AXIS_X).normalized(); + } break; + + case NOTIFICATION_EXIT_TREE: { + VehicleBody3D *cb = Object::cast_to<VehicleBody3D>(get_parent()); + if (!cb) { + return; + } + cb->wheels.erase(this); + body = nullptr; + } break; } } diff --git a/scene/3d/visual_instance_3d.cpp b/scene/3d/visual_instance_3d.cpp index c16e3c2d78..bd47af8100 100644 --- a/scene/3d/visual_instance_3d.cpp +++ b/scene/3d/visual_instance_3d.cpp @@ -246,9 +246,9 @@ void GeometryInstance3D::_get_property_list(List<PropertyInfo> *p_list) const { has_def_value = true; } if (instance_uniforms.has(pi.name)) { - pi.usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE | (has_def_value ? (PROPERTY_USAGE_CHECKABLE | PROPERTY_USAGE_CHECKED) : 0); + pi.usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE | (has_def_value ? (PROPERTY_USAGE_CHECKABLE | PROPERTY_USAGE_CHECKED) : PROPERTY_USAGE_NONE); } else { - pi.usage = PROPERTY_USAGE_EDITOR | (has_def_value ? PROPERTY_USAGE_CHECKABLE : 0); //do not save if not changed + pi.usage = PROPERTY_USAGE_EDITOR | (has_def_value ? PROPERTY_USAGE_CHECKABLE : PROPERTY_USAGE_NONE); //do not save if not changed } pi.name = "shader_params/" + pi.name; @@ -293,7 +293,12 @@ void GeometryInstance3D::set_shader_instance_uniform(const StringName &p_uniform instance_uniforms.erase(p_value); } else { instance_uniforms[p_uniform] = p_value; - RS::get_singleton()->instance_geometry_set_shader_parameter(get_instance(), p_uniform, p_value); + if (p_value.get_type() == Variant::OBJECT) { + RID tex_id = p_value; + RS::get_singleton()->instance_geometry_set_shader_parameter(get_instance(), p_uniform, tex_id); + } else { + RS::get_singleton()->instance_geometry_set_shader_parameter(get_instance(), p_uniform, p_value); + } } } @@ -389,7 +394,7 @@ void GeometryInstance3D::_bind_methods() { ClassDB::bind_method(D_METHOD("get_aabb"), &GeometryInstance3D::get_aabb); ADD_GROUP("Geometry", ""); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material_override", PROPERTY_HINT_RESOURCE_TYPE, "ShaderMaterial,StandardMaterial3D", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_DEFERRED_SET_RESOURCE), "set_material_override", "get_material_override"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material_override", PROPERTY_HINT_RESOURCE_TYPE, "BaseMaterial3D,ShaderMaterial", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_DEFERRED_SET_RESOURCE), "set_material_override", "get_material_override"); ADD_PROPERTY(PropertyInfo(Variant::INT, "cast_shadow", PROPERTY_HINT_ENUM, "Off,On,Double-Sided,Shadows Only"), "set_cast_shadows_setting", "get_cast_shadows_setting"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "extra_cull_margin", PROPERTY_HINT_RANGE, "0,16384,0.01"), "set_extra_cull_margin", "get_extra_cull_margin"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "lod_bias", PROPERTY_HINT_RANGE, "0.001,128,0.001"), "set_lod_bias", "get_lod_bias"); diff --git a/scene/3d/voxel_gi.cpp b/scene/3d/voxel_gi.cpp index e00be9204c..3da59ac4c0 100644 --- a/scene/3d/voxel_gi.cpp +++ b/scene/3d/voxel_gi.cpp @@ -55,7 +55,7 @@ void VoxelGIData::_set_data(const Dictionary &p_data) { } else if (p_data.has("octree_df_png")) { Vector<uint8_t> octree_df_png = p_data["octree_df_png"]; Ref<Image> img; - img.instance(); + img.instantiate(); Error err = img->load_png_from_buffer(octree_df_png); ERR_FAIL_COND(err != OK); ERR_FAIL_COND(img->get_format() != Image::FORMAT_L8); @@ -76,7 +76,7 @@ Dictionary VoxelGIData::_get_data() const { d["octree_data"] = get_data_cells(); if (otsize != Vector3i()) { Ref<Image> img; - img.instance(); + img.instantiate(); img->create(otsize.x * otsize.y, otsize.z, false, Image::FORMAT_L8, get_distance_field()); Vector<uint8_t> df_png = img->save_png_to_buffer(); ERR_FAIL_COND_V(df_png.size() == 0, Dictionary()); @@ -143,15 +143,6 @@ float VoxelGIData::get_propagation() const { return propagation; } -void VoxelGIData::set_anisotropy_strength(float p_anisotropy_strength) { - RS::get_singleton()->voxel_gi_set_anisotropy_strength(probe, p_anisotropy_strength); - anisotropy_strength = p_anisotropy_strength; -} - -float VoxelGIData::get_anisotropy_strength() const { - return anisotropy_strength; -} - void VoxelGIData::set_energy(float p_energy) { RS::get_singleton()->voxel_gi_set_energy(probe, p_energy); energy = p_energy; @@ -161,24 +152,6 @@ float VoxelGIData::get_energy() const { return energy; } -void VoxelGIData::set_ao(float p_ao) { - RS::get_singleton()->voxel_gi_set_ao(probe, p_ao); - ao = p_ao; -} - -float VoxelGIData::get_ao() const { - return ao; -} - -void VoxelGIData::set_ao_size(float p_ao_size) { - RS::get_singleton()->voxel_gi_set_ao_size(probe, p_ao_size); - ao_size = p_ao_size; -} - -float VoxelGIData::get_ao_size() const { - return ao_size; -} - void VoxelGIData::set_bias(float p_bias) { RS::get_singleton()->voxel_gi_set_bias(probe, p_bias); bias = p_bias; @@ -219,15 +192,6 @@ RID VoxelGIData::get_rid() const { return probe; } -void VoxelGIData::_validate_property(PropertyInfo &property) const { - if (property.name == "anisotropy_strength") { - bool anisotropy_enabled = ProjectSettings::get_singleton()->get("rendering/global_illumination/voxel_gi/anisotropic"); - if (!anisotropy_enabled) { - property.usage = PROPERTY_USAGE_NOEDITOR; - } - } -} - void VoxelGIData::_bind_methods() { ClassDB::bind_method(D_METHOD("allocate", "to_cell_xform", "aabb", "octree_size", "octree_cells", "data_cells", "distance_field", "level_counts"), &VoxelGIData::allocate); @@ -253,15 +217,6 @@ void VoxelGIData::_bind_methods() { ClassDB::bind_method(D_METHOD("set_propagation", "propagation"), &VoxelGIData::set_propagation); ClassDB::bind_method(D_METHOD("get_propagation"), &VoxelGIData::get_propagation); - ClassDB::bind_method(D_METHOD("set_anisotropy_strength", "strength"), &VoxelGIData::set_anisotropy_strength); - ClassDB::bind_method(D_METHOD("get_anisotropy_strength"), &VoxelGIData::get_anisotropy_strength); - - ClassDB::bind_method(D_METHOD("set_ao", "ao"), &VoxelGIData::set_ao); - ClassDB::bind_method(D_METHOD("get_ao"), &VoxelGIData::get_ao); - - ClassDB::bind_method(D_METHOD("set_ao_size", "strength"), &VoxelGIData::set_ao_size); - ClassDB::bind_method(D_METHOD("get_ao_size"), &VoxelGIData::get_ao_size); - ClassDB::bind_method(D_METHOD("set_interior", "interior"), &VoxelGIData::set_interior); ClassDB::bind_method(D_METHOD("is_interior"), &VoxelGIData::is_interior); @@ -278,9 +233,6 @@ void VoxelGIData::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "bias", PROPERTY_HINT_RANGE, "0,8,0.01"), "set_bias", "get_bias"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "normal_bias", PROPERTY_HINT_RANGE, "0,8,0.01"), "set_normal_bias", "get_normal_bias"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "propagation", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_propagation", "get_propagation"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "anisotropy_strength", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_anisotropy_strength", "get_anisotropy_strength"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "ao", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_ao", "get_ao"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "ao_size", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_ao_size", "get_ao_size"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_two_bounces"), "set_use_two_bounces", "is_using_two_bounces"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "interior"), "set_interior", "is_interior"); } @@ -467,7 +419,7 @@ void VoxelGI::bake(Node *p_from_node, bool p_create_visual_debug) { Ref<VoxelGIData> probe_data = get_probe_data(); if (probe_data.is_null()) { - probe_data.instance(); + probe_data.instantiate(); } if (bake_step_function) { diff --git a/scene/3d/voxel_gi.h b/scene/3d/voxel_gi.h index 5b9ee28b33..434d209421 100644 --- a/scene/3d/voxel_gi.h +++ b/scene/3d/voxel_gi.h @@ -51,15 +51,11 @@ class VoxelGIData : public Resource { float bias = 1.5; float normal_bias = 0.0; float propagation = 0.7; - float anisotropy_strength = 0.5; - float ao = 0.0; - float ao_size = 0.5; bool interior = false; bool use_two_bounces = false; protected: static void _bind_methods(); - void _validate_property(PropertyInfo &property) const override; public: void allocate(const Transform3D &p_to_cell_xform, const AABB &p_aabb, const Vector3 &p_octree_size, const Vector<uint8_t> &p_octree_cells, const Vector<uint8_t> &p_data_cells, const Vector<uint8_t> &p_distance_field, const Vector<int> &p_level_counts); @@ -77,15 +73,6 @@ public: void set_propagation(float p_propagation); float get_propagation() const; - void set_anisotropy_strength(float p_anisotropy_strength); - float get_anisotropy_strength() const; - - void set_ao(float p_ao); - float get_ao() const; - - void set_ao_size(float p_ao_size); - float get_ao_size() const; - void set_energy(float p_energy); float get_energy() const; diff --git a/scene/3d/voxelizer.cpp b/scene/3d/voxelizer.cpp index ee0c3fe9b6..12f055c01d 100644 --- a/scene/3d/voxelizer.cpp +++ b/scene/3d/voxelizer.cpp @@ -931,14 +931,14 @@ void Voxelizer::_debug_mesh(int p_idx, int p_level, const AABB &p_aabb, Ref<Mult Ref<MultiMesh> Voxelizer::create_debug_multimesh() { Ref<MultiMesh> mm; - mm.instance(); + mm.instantiate(); mm->set_transform_format(MultiMesh::TRANSFORM_3D); mm->set_use_colors(true); mm->set_instance_count(leaf_voxel_count); Ref<ArrayMesh> mesh; - mesh.instance(); + mesh.instantiate(); { Array arr; @@ -985,7 +985,7 @@ Ref<MultiMesh> Voxelizer::create_debug_multimesh() { { Ref<StandardMaterial3D> fsm; - fsm.instance(); + fsm.instantiate(); fsm->set_flag(StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, true); fsm->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); fsm->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED); diff --git a/scene/3d/world_environment.cpp b/scene/3d/world_environment.cpp index 829ecc5ec2..352bef072f 100644 --- a/scene/3d/world_environment.cpp +++ b/scene/3d/world_environment.cpp @@ -145,7 +145,7 @@ TypedArray<String> WorldEnvironment::get_configuration_warnings() const { } if (camera_effects.is_valid() && get_viewport()->find_world_3d()->get_camera_effects() != camera_effects) { - warnings.push_back(TTR("Only one WorldEnvironment is allowed per scene (or set of instanced scenes).")); + warnings.push_back(TTR("Only one WorldEnvironment is allowed per scene (or set of instantiated scenes).")); } return warnings; diff --git a/scene/3d/xr_nodes.cpp b/scene/3d/xr_nodes.cpp index 4f2c816934..a91e712b0b 100644 --- a/scene/3d/xr_nodes.cpp +++ b/scene/3d/xr_nodes.cpp @@ -204,7 +204,7 @@ void XRController3D::_notification(int p_what) { // check button states for (int i = 0; i < 16; i++) { bool was_pressed = (button_states & mask) == mask; - bool is_pressed = Input::get_singleton()->is_joy_button_pressed(joy_id, i); + bool is_pressed = Input::get_singleton()->is_joy_button_pressed(joy_id, (JoyButton)i); if (!was_pressed && is_pressed) { emit_signal("button_pressed", i); @@ -304,7 +304,7 @@ bool XRController3D::is_button_pressed(int p_button) const { return false; }; - return Input::get_singleton()->is_joy_button_pressed(joy_id, p_button); + return Input::get_singleton()->is_joy_button_pressed(joy_id, (JoyButton)p_button); }; float XRController3D::get_joystick_axis(int p_axis) const { @@ -313,7 +313,7 @@ float XRController3D::get_joystick_axis(int p_axis) const { return 0.0; }; - return Input::get_singleton()->get_joy_axis(joy_id, p_axis); + return Input::get_singleton()->get_joy_axis(joy_id, (JoyAxis)p_axis); }; real_t XRController3D::get_rumble() const { diff --git a/scene/animation/animation_blend_space_1d.cpp b/scene/animation/animation_blend_space_1d.cpp index 15f562242f..3818c7edd1 100644 --- a/scene/animation/animation_blend_space_1d.cpp +++ b/scene/animation/animation_blend_space_1d.cpp @@ -47,7 +47,7 @@ void AnimationNodeBlendSpace1D::_validate_property(PropertyInfo &property) const String left = property.name.get_slicec('/', 0); int idx = left.get_slicec('_', 2).to_int(); if (idx >= blend_points_used) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } } AnimationRootNode::_validate_property(property); diff --git a/scene/animation/animation_blend_space_2d.cpp b/scene/animation/animation_blend_space_2d.cpp index 9c4bc107dd..935ec457aa 100644 --- a/scene/animation/animation_blend_space_2d.cpp +++ b/scene/animation/animation_blend_space_2d.cpp @@ -34,8 +34,8 @@ void AnimationNodeBlendSpace2D::get_parameter_list(List<PropertyInfo> *r_list) const { r_list->push_back(PropertyInfo(Variant::VECTOR2, blend_position)); - r_list->push_back(PropertyInfo(Variant::INT, closest, PROPERTY_HINT_NONE, "", 0)); - r_list->push_back(PropertyInfo(Variant::FLOAT, length_internal, PROPERTY_HINT_NONE, "", 0)); + r_list->push_back(PropertyInfo(Variant::INT, closest, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE)); + r_list->push_back(PropertyInfo(Variant::FLOAT, length_internal, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE)); } Variant AnimationNodeBlendSpace2D::get_parameter_default_value(const StringName &p_parameter) const { @@ -556,13 +556,13 @@ String AnimationNodeBlendSpace2D::get_caption() const { void AnimationNodeBlendSpace2D::_validate_property(PropertyInfo &property) const { if (auto_triangles && property.name == "triangles") { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } if (property.name.begins_with("blend_point_")) { String left = property.name.get_slicec('/', 0); int idx = left.get_slicec('_', 2).to_int(); if (idx >= blend_points_used) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } } AnimationRootNode::_validate_property(property); diff --git a/scene/animation/animation_blend_tree.cpp b/scene/animation/animation_blend_tree.cpp index 79a1dc1ac0..6a988042b5 100644 --- a/scene/animation/animation_blend_tree.cpp +++ b/scene/animation/animation_blend_tree.cpp @@ -43,7 +43,7 @@ StringName AnimationNodeAnimation::get_animation() const { Vector<String> (*AnimationNodeAnimation::get_editable_animation_list)() = nullptr; void AnimationNodeAnimation::get_parameter_list(List<PropertyInfo> *r_list) const { - r_list->push_back(PropertyInfo(Variant::FLOAT, time, PROPERTY_HINT_NONE, "", 0)); + r_list->push_back(PropertyInfo(Variant::FLOAT, time, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE)); } void AnimationNodeAnimation::_validate_property(PropertyInfo &property) const { @@ -130,10 +130,10 @@ AnimationNodeAnimation::AnimationNodeAnimation() { void AnimationNodeOneShot::get_parameter_list(List<PropertyInfo> *r_list) const { r_list->push_back(PropertyInfo(Variant::BOOL, active)); - r_list->push_back(PropertyInfo(Variant::BOOL, prev_active, PROPERTY_HINT_NONE, "", 0)); - r_list->push_back(PropertyInfo(Variant::FLOAT, time, PROPERTY_HINT_NONE, "", 0)); - r_list->push_back(PropertyInfo(Variant::FLOAT, remaining, PROPERTY_HINT_NONE, "", 0)); - r_list->push_back(PropertyInfo(Variant::FLOAT, time_to_restart, PROPERTY_HINT_NONE, "", 0)); + r_list->push_back(PropertyInfo(Variant::BOOL, prev_active, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE)); + r_list->push_back(PropertyInfo(Variant::FLOAT, time, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE)); + r_list->push_back(PropertyInfo(Variant::FLOAT, remaining, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE)); + r_list->push_back(PropertyInfo(Variant::FLOAT, time_to_restart, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE)); } Variant AnimationNodeOneShot::get_parameter_default_value(const StringName &p_parameter) const { @@ -607,10 +607,10 @@ void AnimationNodeTransition::get_parameter_list(List<PropertyInfo> *r_list) con } r_list->push_back(PropertyInfo(Variant::INT, current, PROPERTY_HINT_ENUM, anims)); - r_list->push_back(PropertyInfo(Variant::INT, prev_current, PROPERTY_HINT_NONE, "", 0)); - r_list->push_back(PropertyInfo(Variant::INT, prev, PROPERTY_HINT_NONE, "", 0)); - r_list->push_back(PropertyInfo(Variant::FLOAT, time, PROPERTY_HINT_NONE, "", 0)); - r_list->push_back(PropertyInfo(Variant::FLOAT, prev_xfading, PROPERTY_HINT_NONE, "", 0)); + r_list->push_back(PropertyInfo(Variant::INT, prev_current, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE)); + r_list->push_back(PropertyInfo(Variant::INT, prev, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE)); + r_list->push_back(PropertyInfo(Variant::FLOAT, time, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE)); + r_list->push_back(PropertyInfo(Variant::FLOAT, prev_xfading, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE)); } Variant AnimationNodeTransition::get_parameter_default_value(const StringName &p_parameter) const { @@ -752,7 +752,7 @@ void AnimationNodeTransition::_validate_property(PropertyInfo &property) const { if (n != "count") { int idx = n.to_int(); if (idx >= enabled_inputs) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } } } @@ -1164,7 +1164,7 @@ void AnimationNodeBlendTree::_bind_methods() { AnimationNodeBlendTree::AnimationNodeBlendTree() { Ref<AnimationNodeOutput> output; - output.instance(); + output.instantiate(); Node n; n.node = output; n.position = Vector2(300, 150); diff --git a/scene/animation/animation_node_state_machine.cpp b/scene/animation/animation_node_state_machine.cpp index 65918a2989..f494f5c163 100644 --- a/scene/animation/animation_node_state_machine.cpp +++ b/scene/animation/animation_node_state_machine.cpp @@ -496,7 +496,7 @@ void AnimationNodeStateMachinePlayback::_bind_methods() { } AnimationNodeStateMachinePlayback::AnimationNodeStateMachinePlayback() { - set_local_to_scene(true); //only one per instanced scene + set_local_to_scene(true); //only one per instantiated scene } /////////////////////////////////////////////////////// @@ -520,7 +520,7 @@ void AnimationNodeStateMachine::get_parameter_list(List<PropertyInfo> *r_list) c Variant AnimationNodeStateMachine::get_parameter_default_value(const StringName &p_parameter) const { if (p_parameter == playback) { Ref<AnimationNodeStateMachinePlayback> p; - p.instance(); + p.instantiate(); return p; } else { return false; //advance condition diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index e3748a4ae1..6154eef3cf 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -513,7 +513,7 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float } #endif - static_cast<Node2D *>(pa->object)->set_rotation(Math::deg2rad((double)value)); + static_cast<Node2D *>(pa->object)->set_rotation((double)value); } break; case SP_NODE2D_SCALE: { #ifdef DEBUG_ENABLED @@ -1511,7 +1511,7 @@ Ref<AnimatedValuesBackup> AnimationPlayer::backup_animated_values(Node *p_root_o _ensure_node_caches(playback.current.from, p_root_override); - backup.instance(); + backup.instantiate(); for (int i = 0; i < playback.current.from->node_cache.size(); i++) { TrackNodeCache *nc = playback.current.from->node_cache[i]; if (!nc) { diff --git a/scene/animation/animation_tree.cpp b/scene/animation/animation_tree.cpp index 6fac70bdd5..1e07f83d09 100644 --- a/scene/animation/animation_tree.cpp +++ b/scene/animation/animation_tree.cpp @@ -385,7 +385,7 @@ void AnimationNode::_set_filters(const Array &p_filters) { void AnimationNode::_validate_property(PropertyInfo &property) const { if (!has_filter() && (property.name == "filter_enabled" || property.name == "filters")) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } } diff --git a/scene/animation/root_motion_view.cpp b/scene/animation/root_motion_view.cpp index b963cf5702..770996820d 100644 --- a/scene/animation/root_motion_view.cpp +++ b/scene/animation/root_motion_view.cpp @@ -77,7 +77,7 @@ bool RootMotionView::get_zero_y() const { void RootMotionView::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE) { - RS::get_singleton()->immediate_set_material(immediate, StandardMaterial3D::get_material_rid_for_2d(false, true, false, false, false)); + immediate_material = StandardMaterial3D::get_material_for_2d(false, true, false, false, false); first = true; } @@ -119,11 +119,12 @@ void RootMotionView::_notification(int p_what) { } accumulated.origin.z = Math::fposmod(accumulated.origin.z, cell_size); - RS::get_singleton()->immediate_clear(immediate); + immediate->clear_surfaces(); int cells_in_radius = int((radius / cell_size) + 1.0); - RS::get_singleton()->immediate_begin(immediate, RS::PRIMITIVE_LINES); + immediate->surface_begin(Mesh::PRIMITIVE_LINES, immediate_material); + for (int i = -cells_in_radius; i < cells_in_radius; i++) { for (int j = -cells_in_radius; j < cells_in_radius; j++) { Vector3 from(i * cell_size, 0, j * cell_size); @@ -138,21 +139,21 @@ void RootMotionView::_notification(int p_what) { c_i.a *= MAX(0, 1.0 - from_i.length() / radius); c_j.a *= MAX(0, 1.0 - from_j.length() / radius); - RS::get_singleton()->immediate_color(immediate, c); - RS::get_singleton()->immediate_vertex(immediate, from); + immediate->surface_set_color(c); + immediate->surface_add_vertex(from); - RS::get_singleton()->immediate_color(immediate, c_i); - RS::get_singleton()->immediate_vertex(immediate, from_i); + immediate->surface_set_color(c_i); + immediate->surface_add_vertex(from_i); - RS::get_singleton()->immediate_color(immediate, c); - RS::get_singleton()->immediate_vertex(immediate, from); + immediate->surface_set_color(c); + immediate->surface_add_vertex(from); - RS::get_singleton()->immediate_color(immediate, c_j); - RS::get_singleton()->immediate_vertex(immediate, from_j); + immediate->surface_set_color(c_j); + immediate->surface_add_vertex(from_j); } } - RS::get_singleton()->immediate_end(immediate); + immediate->surface_end(); } } @@ -188,12 +189,13 @@ void RootMotionView::_bind_methods() { } RootMotionView::RootMotionView() { - set_process_internal(true); - immediate = RenderingServer::get_singleton()->immediate_create(); - set_base(immediate); + if (Engine::get_singleton()->is_editor_hint()) { + set_process_internal(true); + } + immediate.instantiate(); + set_base(immediate->get_rid()); } RootMotionView::~RootMotionView() { set_base(RID()); - RenderingServer::get_singleton()->free(immediate); } diff --git a/scene/animation/root_motion_view.h b/scene/animation/root_motion_view.h index 4cd3c7b443..55fd2d2b73 100644 --- a/scene/animation/root_motion_view.h +++ b/scene/animation/root_motion_view.h @@ -32,12 +32,12 @@ #define ROOT_MOTION_VIEW_H #include "scene/3d/visual_instance_3d.h" - +#include "scene/resources/immediate_mesh.h" class RootMotionView : public VisualInstance3D { GDCLASS(RootMotionView, VisualInstance3D); public: - RID immediate; + Ref<ImmediateMesh> immediate; NodePath path; float cell_size = 1.0; float radius = 10.0; @@ -46,6 +46,8 @@ public: bool first = true; bool zero_y = true; + Ref<Material> immediate_material; + Transform3D accumulated; private: diff --git a/scene/animation/tween.cpp b/scene/animation/tween.cpp index b4e597f75e..7bf616e602 100644 --- a/scene/animation/tween.cpp +++ b/scene/animation/tween.cpp @@ -30,535 +30,407 @@ #include "tween.h" -void Tween::_add_pending_command(StringName p_key, const Variant &p_arg1, const Variant &p_arg2, const Variant &p_arg3, const Variant &p_arg4, const Variant &p_arg5, const Variant &p_arg6, const Variant &p_arg7, const Variant &p_arg8, const Variant &p_arg9, const Variant &p_arg10) { - // Add a new pending command and reference it - pending_commands.push_back(PendingCommand()); - PendingCommand &cmd = pending_commands.back()->get(); - - // Update the command with the target key - cmd.key = p_key; - - // Determine command argument count - int &count = cmd.args; - if (p_arg10.get_type() != Variant::NIL) { - count = 10; - } else if (p_arg9.get_type() != Variant::NIL) { - count = 9; - } else if (p_arg8.get_type() != Variant::NIL) { - count = 8; - } else if (p_arg7.get_type() != Variant::NIL) { - count = 7; - } else if (p_arg6.get_type() != Variant::NIL) { - count = 6; - } else if (p_arg5.get_type() != Variant::NIL) { - count = 5; - } else if (p_arg4.get_type() != Variant::NIL) { - count = 4; - } else if (p_arg3.get_type() != Variant::NIL) { - count = 3; - } else if (p_arg2.get_type() != Variant::NIL) { - count = 2; - } else if (p_arg1.get_type() != Variant::NIL) { - count = 1; - } else { - count = 0; - } +#include "scene/main/node.h" - // Add the specified arguments to the command - if (count > 0) { - cmd.arg[0] = p_arg1; - } - if (count > 1) { - cmd.arg[1] = p_arg2; - } - if (count > 2) { - cmd.arg[2] = p_arg3; - } - if (count > 3) { - cmd.arg[3] = p_arg4; - } - if (count > 4) { - cmd.arg[4] = p_arg5; - } - if (count > 5) { - cmd.arg[5] = p_arg6; - } - if (count > 6) { - cmd.arg[6] = p_arg7; - } - if (count > 7) { - cmd.arg[7] = p_arg8; - } - if (count > 8) { - cmd.arg[8] = p_arg9; +void Tweener::set_tween(Ref<Tween> p_tween) { + tween = p_tween; +} + +void Tweener::_bind_methods() { + ADD_SIGNAL(MethodInfo("finished")); +} + +void Tween::start_tweeners() { + if (tweeners.is_empty()) { + dead = true; + ERR_FAIL_MSG("Tween without commands, aborting."); } - if (count > 9) { - cmd.arg[9] = p_arg10; + + for (List<Ref<Tweener>>::Element *E = tweeners.write[current_step].front(); E; E = E->next()) { + E->get()->start(); } } -void Tween::_process_pending_commands() { - // For each pending command... - for (List<PendingCommand>::Element *E = pending_commands.front(); E; E = E->next()) { - // Get the command - PendingCommand &cmd = E->get(); - Callable::CallError err; - - // Grab all of the arguments for the command - Variant *arg[10] = { - &cmd.arg[0], - &cmd.arg[1], - &cmd.arg[2], - &cmd.arg[3], - &cmd.arg[4], - &cmd.arg[5], - &cmd.arg[6], - &cmd.arg[7], - &cmd.arg[8], - &cmd.arg[9], - }; - - // Execute the command (and retrieve any errors) - this->call(cmd.key, (const Variant **)arg, cmd.args, err); - } +Ref<PropertyTweener> Tween::tween_property(Object *p_target, NodePath p_property, Variant p_to, float p_duration) { + ERR_FAIL_NULL_V(p_target, nullptr); + ERR_FAIL_COND_V_MSG(invalid, nullptr, "Tween was created outside the scene tree, can't use Tweeners."); + ERR_FAIL_COND_V_MSG(started, nullptr, "Can't append to a Tween that has started. Use stop() first."); - // Clear the pending commands - pending_commands.clear(); + Ref<PropertyTweener> tweener = memnew(PropertyTweener(p_target, p_property, p_to, p_duration)); + append(tweener); + return tweener; } -bool Tween::_set(const StringName &p_name, const Variant &p_value) { - // Set the correct attribute based on the given name - String name = p_name; - if (name == "playback/speed" || name == "speed") { // Backwards compatibility - set_speed_scale(p_value); - return true; +Ref<IntervalTweener> Tween::tween_interval(float p_time) { + ERR_FAIL_COND_V_MSG(invalid, nullptr, "Tween was created outside the scene tree, can't use Tweeners."); + ERR_FAIL_COND_V_MSG(started, nullptr, "Can't append to a Tween that has started. Use stop() first."); - } else if (name == "playback/active") { - set_active(p_value); - return true; + Ref<IntervalTweener> tweener = memnew(IntervalTweener(p_time)); + append(tweener); + return tweener; +} - } else if (name == "playback/repeat") { - set_repeat(p_value); - return true; - } - return false; +Ref<CallbackTweener> Tween::tween_callback(Callable p_callback) { + ERR_FAIL_COND_V_MSG(invalid, nullptr, "Tween was created outside the scene tree, can't use Tweeners."); + ERR_FAIL_COND_V_MSG(started, nullptr, "Can't append to a Tween that has started. Use stop() first."); + + Ref<CallbackTweener> tweener = memnew(CallbackTweener(p_callback)); + append(tweener); + return tweener; } -bool Tween::_get(const StringName &p_name, Variant &r_ret) const { - // Get the correct attribute based on the given name - String name = p_name; - if (name == "playback/speed") { // Backwards compatibility - r_ret = speed_scale; - return true; +Ref<MethodTweener> Tween::tween_method(Callable p_callback, float p_from, float p_to, float p_duration) { + ERR_FAIL_COND_V_MSG(invalid, nullptr, "Tween was created outside the scene tree, can't use Tweeners."); + ERR_FAIL_COND_V_MSG(started, nullptr, "Can't append to a Tween that has started. Use stop() first."); - } else if (name == "playback/active") { - r_ret = is_active(); - return true; + Ref<MethodTweener> tweener = memnew(MethodTweener(p_callback, p_from, p_to, p_duration)); + append(tweener); + return tweener; +} - } else if (name == "playback/repeat") { - r_ret = is_repeat(); - return true; +Ref<Tween> Tween::append(Ref<Tweener> p_tweener) { + ERR_FAIL_COND_V_MSG(invalid, nullptr, "Tween was created outside the scene tree, can't use Tweeners."); + ERR_FAIL_COND_V_MSG(started, nullptr, "Can't append to a Tween that has started. Use stop() first."); + p_tweener->set_tween(this); + + if (parallel_enabled) { + current_step = MAX(current_step, 0); + } else { + current_step++; } - return false; -} - -void Tween::_get_property_list(List<PropertyInfo> *p_list) const { - // Add the property info for the Tween object - p_list->push_back(PropertyInfo(Variant::BOOL, "playback/active", PROPERTY_HINT_NONE, "")); - p_list->push_back(PropertyInfo(Variant::BOOL, "playback/repeat", PROPERTY_HINT_NONE, "")); - p_list->push_back(PropertyInfo(Variant::FLOAT, "playback/speed", PROPERTY_HINT_RANGE, "-64,64,0.01")); -} - -void Tween::_notification(int p_what) { - // What notification did we receive? - switch (p_what) { - case NOTIFICATION_ENTER_TREE: { - // Are we not already active? - if (!is_active()) { - // Make sure that a previous process state was not saved - // Only process if "processing" is set - set_physics_process_internal(false); - set_process_internal(false); - } - } break; + parallel_enabled = default_parallel; - case NOTIFICATION_READY: { - // Do nothing - } break; + tweeners.resize(current_step + 1); + tweeners.write[current_step].push_back(p_tweener); - case NOTIFICATION_INTERNAL_PROCESS: { - // Are we processing during physics time? - if (tween_process_mode == TWEEN_PROCESS_PHYSICS) { - // Do nothing since we aren't aligned with physics when we should be - break; - } + return this; +} - // Should we update? - if (is_active()) { - // Update the tweens - _tween_process(get_process_delta_time()); - } - } break; +void Tween::stop() { + started = false; + running = false; + dead = false; +} - case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: { - // Are we processing during 'regular' time? - if (tween_process_mode == TWEEN_PROCESS_IDLE) { - // Do nothing since we would only process during idle time - break; - } +void Tween::pause() { + running = false; +} - // Should we update? - if (is_active()) { - // Update the tweens - _tween_process(get_physics_process_delta_time()); - } - } break; +void Tween::play() { + ERR_FAIL_COND_MSG(invalid, "Tween invalid, can't play."); + ERR_FAIL_COND_MSG(dead, "Can't play finished Tween, use stop() first to reset its state."); + running = true; +} - case NOTIFICATION_EXIT_TREE: { - // We've left the tree. Stop all tweens - stop_all(); - } break; - } +void Tween::kill() { + running = false; // For the sake of is_running(). + dead = true; } -void Tween::_bind_methods() { - // Bind getters and setters - ClassDB::bind_method(D_METHOD("is_active"), &Tween::is_active); - ClassDB::bind_method(D_METHOD("set_active", "active"), &Tween::set_active); +bool Tween::is_running() { + return running; +} - ClassDB::bind_method(D_METHOD("is_repeat"), &Tween::is_repeat); - ClassDB::bind_method(D_METHOD("set_repeat", "repeat"), &Tween::set_repeat); +void Tween::set_valid(bool p_valid) { + invalid = !p_valid; +} - ClassDB::bind_method(D_METHOD("set_speed_scale", "speed"), &Tween::set_speed_scale); - ClassDB::bind_method(D_METHOD("get_speed_scale"), &Tween::get_speed_scale); - - ClassDB::bind_method(D_METHOD("set_tween_process_mode", "mode"), &Tween::set_tween_process_mode); - ClassDB::bind_method(D_METHOD("get_tween_process_mode"), &Tween::get_tween_process_mode); - - // Bind the various Tween control methods - ClassDB::bind_method(D_METHOD("start"), &Tween::start); - ClassDB::bind_method(D_METHOD("reset", "object", "key"), &Tween::reset, DEFVAL("")); - ClassDB::bind_method(D_METHOD("reset_all"), &Tween::reset_all); - ClassDB::bind_method(D_METHOD("stop", "object", "key"), &Tween::stop, DEFVAL("")); - ClassDB::bind_method(D_METHOD("stop_all"), &Tween::stop_all); - ClassDB::bind_method(D_METHOD("resume", "object", "key"), &Tween::resume, DEFVAL("")); - ClassDB::bind_method(D_METHOD("resume_all"), &Tween::resume_all); - ClassDB::bind_method(D_METHOD("remove", "object", "key"), &Tween::remove, DEFVAL("")); - ClassDB::bind_method(D_METHOD("_remove_by_uid", "uid"), &Tween::_remove_by_uid); - ClassDB::bind_method(D_METHOD("remove_all"), &Tween::remove_all); - ClassDB::bind_method(D_METHOD("seek", "time"), &Tween::seek); - ClassDB::bind_method(D_METHOD("tell"), &Tween::tell); - ClassDB::bind_method(D_METHOD("get_runtime"), &Tween::get_runtime); - - // Bind interpolation and follow methods - ClassDB::bind_method(D_METHOD("interpolate_property", "object", "property", "initial_val", "final_val", "duration", "trans_type", "ease_type", "delay"), &Tween::interpolate_property, DEFVAL(TRANS_LINEAR), DEFVAL(EASE_IN_OUT), DEFVAL(0)); - ClassDB::bind_method(D_METHOD("interpolate_method", "object", "method", "initial_val", "final_val", "duration", "trans_type", "ease_type", "delay"), &Tween::interpolate_method, DEFVAL(TRANS_LINEAR), DEFVAL(EASE_IN_OUT), DEFVAL(0)); - ClassDB::bind_method(D_METHOD("interpolate_callback", "object", "duration", "callback", "arg1", "arg2", "arg3", "arg4", "arg5"), &Tween::interpolate_callback, DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(Variant())); - ClassDB::bind_method(D_METHOD("interpolate_deferred_callback", "object", "duration", "callback", "arg1", "arg2", "arg3", "arg4", "arg5"), &Tween::interpolate_deferred_callback, DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(Variant())); - ClassDB::bind_method(D_METHOD("follow_property", "object", "property", "initial_val", "target", "target_property", "duration", "trans_type", "ease_type", "delay"), &Tween::follow_property, DEFVAL(TRANS_LINEAR), DEFVAL(EASE_IN_OUT), DEFVAL(0)); - ClassDB::bind_method(D_METHOD("follow_method", "object", "method", "initial_val", "target", "target_method", "duration", "trans_type", "ease_type", "delay"), &Tween::follow_method, DEFVAL(TRANS_LINEAR), DEFVAL(EASE_IN_OUT), DEFVAL(0)); - ClassDB::bind_method(D_METHOD("targeting_property", "object", "property", "initial", "initial_val", "final_val", "duration", "trans_type", "ease_type", "delay"), &Tween::targeting_property, DEFVAL(TRANS_LINEAR), DEFVAL(EASE_IN_OUT), DEFVAL(0)); - ClassDB::bind_method(D_METHOD("targeting_method", "object", "method", "initial", "initial_method", "final_val", "duration", "trans_type", "ease_type", "delay"), &Tween::targeting_method, DEFVAL(TRANS_LINEAR), DEFVAL(EASE_IN_OUT), DEFVAL(0)); - - // Add the Tween signals - ADD_SIGNAL(MethodInfo("tween_started", PropertyInfo(Variant::OBJECT, "object"), PropertyInfo(Variant::NODE_PATH, "key"))); - ADD_SIGNAL(MethodInfo("tween_step", PropertyInfo(Variant::OBJECT, "object"), PropertyInfo(Variant::NODE_PATH, "key"), PropertyInfo(Variant::FLOAT, "elapsed"), PropertyInfo(Variant::OBJECT, "value"))); - ADD_SIGNAL(MethodInfo("tween_completed", PropertyInfo(Variant::OBJECT, "object"), PropertyInfo(Variant::NODE_PATH, "key"))); - ADD_SIGNAL(MethodInfo("tween_all_completed")); - - // Add the properties and tie them to the getters and setters - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "repeat"), "set_repeat", "is_repeat"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "playback_process_mode", PROPERTY_HINT_ENUM, "Physics,Idle"), "set_tween_process_mode", "get_tween_process_mode"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "playback_speed", PROPERTY_HINT_RANGE, "-64,64,0.01"), "set_speed_scale", "get_speed_scale"); - - // Bind Idle vs Physics process - BIND_ENUM_CONSTANT(TWEEN_PROCESS_PHYSICS); - BIND_ENUM_CONSTANT(TWEEN_PROCESS_IDLE); +bool Tween::is_valid() { + return invalid; +} - // Bind the Transition type constants - BIND_ENUM_CONSTANT(TRANS_LINEAR); - BIND_ENUM_CONSTANT(TRANS_SINE); - BIND_ENUM_CONSTANT(TRANS_QUINT); - BIND_ENUM_CONSTANT(TRANS_QUART); - BIND_ENUM_CONSTANT(TRANS_QUAD); - BIND_ENUM_CONSTANT(TRANS_EXPO); - BIND_ENUM_CONSTANT(TRANS_ELASTIC); - BIND_ENUM_CONSTANT(TRANS_CUBIC); - BIND_ENUM_CONSTANT(TRANS_CIRC); - BIND_ENUM_CONSTANT(TRANS_BOUNCE); - BIND_ENUM_CONSTANT(TRANS_BACK); +Ref<Tween> Tween::bind_node(Node *p_node) { + bound_node = p_node->get_instance_id(); + is_bound = true; + return this; +} - // Bind the easing constants - BIND_ENUM_CONSTANT(EASE_IN); - BIND_ENUM_CONSTANT(EASE_OUT); - BIND_ENUM_CONSTANT(EASE_IN_OUT); - BIND_ENUM_CONSTANT(EASE_OUT_IN); +Ref<Tween> Tween::set_process_mode(TweenProcessMode p_mode) { + process_mode = p_mode; + return this; } -Variant Tween::_get_initial_val(const InterpolateData &p_data) const { - // What type of data are we interpolating? - switch (p_data.type) { - case INTER_PROPERTY: - case INTER_METHOD: - case FOLLOW_PROPERTY: - case FOLLOW_METHOD: - // Simply use the given initial value - return p_data.initial_val; - - case TARGETING_PROPERTY: - case TARGETING_METHOD: { - // Get the object that is being targeted - Object *object = ObjectDB::get_instance(p_data.target_id); - ERR_FAIL_COND_V(object == nullptr, p_data.initial_val); - - // Are we targeting a property or a method? - Variant initial_val; - if (p_data.type == TARGETING_PROPERTY) { - // Get the property from the target object - bool valid = false; - initial_val = object->get_indexed(p_data.target_key, &valid); - ERR_FAIL_COND_V(!valid, p_data.initial_val); - } else { - // Call the method and get the initial value from it - Callable::CallError error; - initial_val = object->call(p_data.target_key[0], nullptr, 0, error); - ERR_FAIL_COND_V(error.error != Callable::CallError::CALL_OK, p_data.initial_val); - } - return initial_val; - } +Tween::TweenProcessMode Tween::get_process_mode() { + return process_mode; +} + +Ref<Tween> Tween::set_pause_mode(TweenPauseMode p_mode) { + pause_mode = p_mode; + return this; +} + +Tween::TweenPauseMode Tween::get_pause_mode() { + return pause_mode; +} + +Ref<Tween> Tween::set_parallel(bool p_parallel) { + default_parallel = p_parallel; + parallel_enabled = p_parallel; + return this; +} + +Ref<Tween> Tween::set_loops(int p_loops) { + loops = p_loops; + return this; +} + +Ref<Tween> Tween::set_speed_scale(float p_speed) { + speed_scale = p_speed; + return this; +} + +Ref<Tween> Tween::set_trans(TransitionType p_trans) { + default_transition = p_trans; + return this; +} - case INTER_CALLBACK: - // Callback does not have a special initial value - break; +Tween::TransitionType Tween::get_trans() { + return default_transition; +} + +Ref<Tween> Tween::set_ease(EaseType p_ease) { + default_ease = p_ease; + return this; +} + +Tween::EaseType Tween::get_ease() { + return default_ease; +} + +Ref<Tween> Tween::parallel() { + parallel_enabled = true; + return this; +} + +Ref<Tween> Tween::chain() { + parallel_enabled = false; + return this; +} + +bool Tween::custom_step(float p_delta) { + bool r = running; + running = true; + bool ret = step(p_delta); + running = running && r; // Running might turn false when Tween finished. + return ret; +} + +bool Tween::step(float p_delta) { + ERR_FAIL_COND_V_MSG(tweeners.is_empty(), false, "Tween started, but has no Tweeners."); + + if (dead) { + return false; } - // If we've made it here, just return the delta value as the initial value - return p_data.delta_val; -} - -Variant Tween::_get_final_val(const InterpolateData &p_data) const { - switch (p_data.type) { - case FOLLOW_PROPERTY: - case FOLLOW_METHOD: { - // Get the object that is being followed - Object *target = ObjectDB::get_instance(p_data.target_id); - ERR_FAIL_COND_V(target == nullptr, p_data.initial_val); - - // We want to figure out the final value - Variant final_val; - if (p_data.type == FOLLOW_PROPERTY) { - // Read the property as-is - bool valid = false; - final_val = target->get_indexed(p_data.target_key, &valid); - ERR_FAIL_COND_V(!valid, p_data.initial_val); - } else { - // We're looking at a method. Call the method on the target object - Callable::CallError error; - final_val = target->call(p_data.target_key[0], nullptr, 0, error); - ERR_FAIL_COND_V(error.error != Callable::CallError::CALL_OK, p_data.initial_val); - } - // If we're looking at an INT value, instead convert it to a FLOAT - // This is better for interpolation - if (final_val.get_type() == Variant::INT) { - final_val = final_val.operator real_t(); - } + if (!running) { + return true; + } - return final_val; - } - default: { - // If we're not following a final value/method, use the final value from the data - return p_data.final_val; + if (is_bound) { + Object *bound_instance = ObjectDB::get_instance(bound_node); + if (bound_instance) { + Node *bound_node = Object::cast_to<Node>(bound_instance); + // This can't by anything else than Node, so we can omit checking if casting succeeded. + if (!bound_node->is_inside_tree()) { + return true; + } + } else { + return false; } } -} -Variant &Tween::_get_delta_val(InterpolateData &p_data) { - // What kind of data are we interpolating? - switch (p_data.type) { - case INTER_PROPERTY: - case INTER_METHOD: - // Simply return the given delta value - return p_data.delta_val; - - case FOLLOW_PROPERTY: - case FOLLOW_METHOD: { - // We're following an object, so grab that instance - Object *target = ObjectDB::get_instance(p_data.target_id); - ERR_FAIL_COND_V(target == nullptr, p_data.initial_val); - - // We want to figure out the final value - Variant final_val; - if (p_data.type == FOLLOW_PROPERTY) { - // Read the property as-is - bool valid = false; - final_val = target->get_indexed(p_data.target_key, &valid); - ERR_FAIL_COND_V(!valid, p_data.initial_val); - } else { - // We're looking at a method. Call the method on the target object - Callable::CallError error; - final_val = target->call(p_data.target_key[0], nullptr, 0, error); - ERR_FAIL_COND_V(error.error != Callable::CallError::CALL_OK, p_data.initial_val); - } + if (!started) { + current_step = 0; + loops_done = 0; + start_tweeners(); + started = true; + } - // If we're looking at an INT value, instead convert it to a FLOAT - // This is better for interpolation - if (final_val.get_type() == Variant::INT) { - final_val = final_val.operator real_t(); - } + float rem_delta = p_delta * speed_scale; + bool step_active = false; - // Calculate the delta based on the initial value and the final value - _calc_delta_val(p_data.initial_val, final_val, p_data.delta_val); - return p_data.delta_val; + while (rem_delta > 0 && running) { + float step_delta = rem_delta; + step_active = false; + + for (List<Ref<Tweener>>::Element *E = tweeners.write[current_step].front(); E; E = E->next()) { + // Modified inside Tweener.step(). + float temp_delta = rem_delta; + // Turns to true if any Tweener returns true (i.e. is still not finished). + step_active = E->get()->step(temp_delta) || step_active; + step_delta = MIN(temp_delta, rem_delta); } - case TARGETING_PROPERTY: - case TARGETING_METHOD: { - // Grab the initial value from the data to calculate delta - Variant initial_val = _get_initial_val(p_data); + rem_delta = step_delta; - // If we're looking at an INT value, instead convert it to a FLOAT - // This is better for interpolation - if (initial_val.get_type() == Variant::INT) { - initial_val = initial_val.operator real_t(); - } + if (!step_active) { + emit_signal("step_finished", current_step); + current_step++; - // Calculate the delta based on the initial value and the final value - _calc_delta_val(initial_val, p_data.final_val, p_data.delta_val); - return p_data.delta_val; + if (current_step == tweeners.size()) { + loops_done++; + if (loops_done == loops) { + running = false; + dead = true; + emit_signal("finished"); + } else { + emit_signal("loop_finished", loops_done); + current_step = 0; + start_tweeners(); + } + } else { + start_tweeners(); + } } + } + + return true; +} - case INTER_CALLBACK: - // Callbacks have no special delta - break; +bool Tween::should_pause() { + if (is_bound && pause_mode == TWEEN_PAUSE_BOUND) { + Object *bound_instance = ObjectDB::get_instance(bound_node); + if (bound_instance) { + Node *bound_node = Object::cast_to<Node>(bound_instance); + return !bound_node->can_process(); + } } - // If we've made it here, use the initial value as the delta - return p_data.initial_val; + + return pause_mode != TWEEN_PAUSE_PROCESS; } -Variant Tween::_run_equation(InterpolateData &p_data) { - // Get the initial and delta values from the data - Variant initial_val = _get_initial_val(p_data); - Variant &delta_val = _get_delta_val(p_data); - Variant result; +Variant Tween::interpolate_variant(Variant p_initial_val, Variant p_delta_val, float p_time, float p_duration, TransitionType p_trans, EaseType p_ease) { + ERR_FAIL_INDEX_V(p_trans, TransitionType::TRANS_MAX, Variant()); + ERR_FAIL_INDEX_V(p_ease, EaseType::EASE_MAX, Variant()); +// Helper macro to run equation on sub-elements of the value (e.g. x and y of Vector2). #define APPLY_EQUATION(element) \ - r.element = _run_equation(p_data.trans_type, p_data.ease_type, p_data.elapsed - p_data.delay, i.element, d.element, p_data.duration); + r.element = run_equation(p_trans, p_ease, p_time, i.element, d.element, p_duration); - // What type of data are we interpolating? - switch (initial_val.get_type()) { - case Variant::BOOL: - // Run the boolean specific equation (checking if it is at least 0.5) - result = (_run_equation(p_data.trans_type, p_data.ease_type, p_data.elapsed - p_data.delay, initial_val, delta_val, p_data.duration)) >= 0.5; - break; + switch (p_initial_val.get_type()) { + case Variant::BOOL: { + return (run_equation(p_trans, p_ease, p_time, p_initial_val, p_delta_val, p_duration)) >= 0.5; + } - case Variant::INT: - // Run the integer specific equation - result = (int)_run_equation(p_data.trans_type, p_data.ease_type, p_data.elapsed - p_data.delay, (int)initial_val, (int)delta_val, p_data.duration); - break; + case Variant::INT: { + return (int)run_equation(p_trans, p_ease, p_time, (int)p_initial_val, (int)p_delta_val, p_duration); + } - case Variant::FLOAT: - // Run the FLOAT specific equation - result = _run_equation(p_data.trans_type, p_data.ease_type, p_data.elapsed - p_data.delay, (real_t)initial_val, (real_t)delta_val, p_data.duration); - break; + case Variant::FLOAT: { + return run_equation(p_trans, p_ease, p_time, (real_t)p_initial_val, (real_t)p_delta_val, p_duration); + } case Variant::VECTOR2: { - // Get vectors for initial and delta values - Vector2 i = initial_val; - Vector2 d = delta_val; + Vector2 i = p_initial_val; + Vector2 d = p_delta_val; Vector2 r; - // Execute the equation and mutate the r vector - // This uses the custom APPLY_EQUATION macro defined above APPLY_EQUATION(x); APPLY_EQUATION(y); - result = r; - } break; + return r; + } + + case Variant::VECTOR2I: { + Vector2i i = p_initial_val; + Vector2i d = p_delta_val; + Vector2i r; + + APPLY_EQUATION(x); + APPLY_EQUATION(y); + return r; + } case Variant::RECT2: { - // Get the Rect2 for initial and delta value - Rect2 i = initial_val; - Rect2 d = delta_val; + Rect2 i = p_initial_val; + Rect2 d = p_delta_val; Rect2 r; - // Execute the equation for the position and size of Rect2 APPLY_EQUATION(position.x); APPLY_EQUATION(position.y); APPLY_EQUATION(size.x); APPLY_EQUATION(size.y); - result = r; - } break; + return r; + } + + case Variant::RECT2I: { + Rect2i i = p_initial_val; + Rect2i d = p_delta_val; + Rect2i r; + + APPLY_EQUATION(position.x); + APPLY_EQUATION(position.y); + APPLY_EQUATION(size.x); + APPLY_EQUATION(size.y); + return r; + } case Variant::VECTOR3: { - // Get vectors for initial and delta values - Vector3 i = initial_val; - Vector3 d = delta_val; + Vector3 i = p_initial_val; + Vector3 d = p_delta_val; Vector3 r; - // Execute the equation and mutate the r vector - // This uses the custom APPLY_EQUATION macro defined above APPLY_EQUATION(x); APPLY_EQUATION(y); APPLY_EQUATION(z); - result = r; - } break; + return r; + } + + case Variant::VECTOR3I: { + Vector3i i = p_initial_val; + Vector3i d = p_delta_val; + Vector3i r; + + APPLY_EQUATION(x); + APPLY_EQUATION(y); + APPLY_EQUATION(z); + return r; + } case Variant::TRANSFORM2D: { - // Get the transforms for initial and delta values - Transform2D i = initial_val; - Transform2D d = delta_val; + Transform2D i = p_initial_val; + Transform2D d = p_delta_val; Transform2D r; - // Execute the equation on the transforms and mutate the r transform - // This uses the custom APPLY_EQUATION macro defined above APPLY_EQUATION(elements[0][0]); APPLY_EQUATION(elements[0][1]); APPLY_EQUATION(elements[1][0]); APPLY_EQUATION(elements[1][1]); APPLY_EQUATION(elements[2][0]); APPLY_EQUATION(elements[2][1]); - result = r; - } break; + return r; + } case Variant::QUATERNION: { - // Get the quaternian for the initial and delta values - Quaternion i = initial_val; - Quaternion d = delta_val; + Quaternion i = p_initial_val; + Quaternion d = p_delta_val; Quaternion r; - // Execute the equation on the quaternian values and mutate the r quaternian - // This uses the custom APPLY_EQUATION macro defined above APPLY_EQUATION(x); APPLY_EQUATION(y); APPLY_EQUATION(z); APPLY_EQUATION(w); - result = r; - } break; + return r; + } case Variant::AABB: { - // Get the AABB's for the initial and delta values - AABB i = initial_val; - AABB d = delta_val; + AABB i = p_initial_val; + AABB d = p_delta_val; AABB r; - // Execute the equation for the position and size of the AABB's and mutate the r AABB - // This uses the custom APPLY_EQUATION macro defined above APPLY_EQUATION(position.x); APPLY_EQUATION(position.y); APPLY_EQUATION(position.z); APPLY_EQUATION(size.x); APPLY_EQUATION(size.y); APPLY_EQUATION(size.z); - result = r; - } break; + return r; + } case Variant::BASIS: { - // Get the basis for initial and delta values - Basis i = initial_val; - Basis d = delta_val; + Basis i = p_initial_val; + Basis d = p_delta_val; Basis r; - // Execute the equation on all the basis and mutate the r basis - // This uses the custom APPLY_EQUATION macro defined above APPLY_EQUATION(elements[0][0]); APPLY_EQUATION(elements[0][1]); APPLY_EQUATION(elements[0][2]); @@ -568,17 +440,14 @@ Variant Tween::_run_equation(InterpolateData &p_data) { APPLY_EQUATION(elements[2][0]); APPLY_EQUATION(elements[2][1]); APPLY_EQUATION(elements[2][2]); - result = r; - } break; + return r; + } case Variant::TRANSFORM3D: { - // Get the transforms for the initial and delta values - Transform3D i = initial_val; - Transform3D d = delta_val; + Transform3D i = p_initial_val; + Transform3D d = p_delta_val; Transform3D r; - // Execute the equation for each of the transforms and their origin and mutate the r transform - // This uses the custom APPLY_EQUATION macro defined above APPLY_EQUATION(basis.elements[0][0]); APPLY_EQUATION(basis.elements[0][1]); APPLY_EQUATION(basis.elements[0][2]); @@ -591,634 +460,67 @@ Variant Tween::_run_equation(InterpolateData &p_data) { APPLY_EQUATION(origin.x); APPLY_EQUATION(origin.y); APPLY_EQUATION(origin.z); - result = r; - } break; + return r; + } case Variant::COLOR: { - // Get the Color for initial and delta value - Color i = initial_val; - Color d = delta_val; + Color i = p_initial_val; + Color d = p_delta_val; Color r; - // Apply the equation on the Color RGBA, and mutate the r color - // This uses the custom APPLY_EQUATION macro defined above APPLY_EQUATION(r); APPLY_EQUATION(g); APPLY_EQUATION(b); APPLY_EQUATION(a); - result = r; - } break; - - default: { - // If unknown, just return the initial value - result = initial_val; - } break; - }; -#undef APPLY_EQUATION - // Return the result that was computed - return result; -} - -bool Tween::_apply_tween_value(InterpolateData &p_data, Variant &value) { - // Get the object we want to apply the new value to - Object *object = ObjectDB::get_instance(p_data.id); - ERR_FAIL_COND_V(object == nullptr, false); - - // What kind of data are we mutating? - switch (p_data.type) { - case INTER_PROPERTY: - case FOLLOW_PROPERTY: - case TARGETING_PROPERTY: { - // Simply set the property on the object - bool valid = false; - object->set_indexed(p_data.key, value, &valid); - return valid; + return r; } - case INTER_METHOD: - case FOLLOW_METHOD: - case TARGETING_METHOD: { - // We want to call the method on the target object - Callable::CallError error; - - // Do we have a non-nil value passed in? - if (value.get_type() != Variant::NIL) { - // Pass it as an argument to the function call - Variant *arg[1] = { &value }; - object->call(p_data.key[0], (const Variant **)arg, 1, error); - } else { - // Don't pass any argument - object->call(p_data.key[0], nullptr, 0, error); - } - - // Did we get an error from the function call? - return error.error == Callable::CallError::CALL_OK; + default: { + return p_initial_val; } - - case INTER_CALLBACK: - // Nothing to apply for a callback - break; }; - // No issues found! - return true; -} - -void Tween::_tween_process(float p_delta) { - // Process all of the pending commands - _process_pending_commands(); - - // If the scale is 0, make no progress on the tweens - if (speed_scale == 0) { - return; - } - - // Update the delta and whether we are pending an update - p_delta *= speed_scale; - pending_update++; - - // Are we repeating the interpolations? - if (repeat) { - // For each interpolation... - bool repeats_finished = true; - for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) { - // Get the data from it - InterpolateData &data = E->get(); - - // Is not finished? - if (!data.finish) { - // We aren't finished yet, no need to check the rest - repeats_finished = false; - break; - } - } - - // If we are all finished, we can reset all of the tweens - if (repeats_finished) { - reset_all(); - } - } - - // Are all of the tweens complete? - int any_unfinished = 0; - - // For each tween we wish to interpolate... - for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) { - // Get the data from it - InterpolateData &data = E->get(); - - // Is the data not active or already finished? No need to go any further - if (!data.active || data.finish) { - continue; - } - - // Track if we hit one that isn't finished yet - any_unfinished++; - - // Get the target object for this interpolation - Object *object = ObjectDB::get_instance(data.id); - if (object == nullptr) { - continue; - } - - // Are we still delaying this tween? - bool prev_delaying = data.elapsed <= data.delay; - data.elapsed += p_delta; - if (data.elapsed < data.delay) { - continue; - } else if (prev_delaying) { - // We can apply the tween's value to the data and emit that the tween has started - _apply_tween_value(data, data.initial_val); - emit_signal("tween_started", object, NodePath(Vector<StringName>(), data.key, false)); - } - - // Are we at the end of the tween? - if (data.elapsed > (data.delay + data.duration)) { - // Set the elapsed time to the end and mark this one as finished - data.elapsed = data.delay + data.duration; - data.finish = true; - } - - // Are we interpolating a callback? - if (data.type == INTER_CALLBACK) { - // Is the tween completed? - if (data.finish) { - // Are we calling this callback deferred or immediately? - if (data.call_deferred) { - // Run the deferred function callback, applying the correct number of arguments - switch (data.args) { - case 0: - object->call_deferred(data.key[0]); - break; - case 1: - object->call_deferred(data.key[0], data.arg[0]); - break; - case 2: - object->call_deferred(data.key[0], data.arg[0], data.arg[1]); - break; - case 3: - object->call_deferred(data.key[0], data.arg[0], data.arg[1], data.arg[2]); - break; - case 4: - object->call_deferred(data.key[0], data.arg[0], data.arg[1], data.arg[2], data.arg[3]); - break; - case 5: - object->call_deferred(data.key[0], data.arg[0], data.arg[1], data.arg[2], data.arg[3], data.arg[4]); - break; - } - } else { - // Call the function directly with the arguments - Callable::CallError error; - Variant *arg[5] = { - &data.arg[0], - &data.arg[1], - &data.arg[2], - &data.arg[3], - &data.arg[4], - }; - object->call(data.key[0], (const Variant **)arg, data.args, error); - } - } - } else { - // We can apply the value directly - Variant result = _run_equation(data); - _apply_tween_value(data, result); - - // Emit that the tween has taken a step - emit_signal("tween_step", object, NodePath(Vector<StringName>(), data.key, false), data.elapsed, result); - } - - // Is the tween now finished? - if (data.finish) { - // Set it to the final value directly - Variant final_val = _get_final_val(data); - _apply_tween_value(data, final_val); - - // Mark the tween as completed and emit the signal - data.elapsed = 0; - emit_signal("tween_completed", object, NodePath(Vector<StringName>(), data.key, false)); - - // If we are not repeating the tween, remove it - if (!repeat) { - call_deferred("_remove_by_uid", data.uid); - any_unfinished--; - } - } - } - // One less update left to go - pending_update--; - - // If all tweens are completed, we no longer need to be active - if (any_unfinished == 0) { - set_active(false); - emit_signal("tween_all_completed"); - } -} - -void Tween::set_tween_process_mode(TweenProcessMode p_mode) { - tween_process_mode = p_mode; -} - -Tween::TweenProcessMode Tween::get_tween_process_mode() const { - return tween_process_mode; -} - -bool Tween::is_active() const { - return is_processing_internal() || is_physics_processing_internal(); -} - -void Tween::set_active(bool p_active) { - // Do nothing if it's the same active mode that we currently are - if (is_active() == p_active) { - return; - } - - // Depending on physics or idle, set processing - switch (tween_process_mode) { - case TWEEN_PROCESS_IDLE: - set_process_internal(p_active); - break; - case TWEEN_PROCESS_PHYSICS: - set_physics_process_internal(p_active); - break; - } -} - -bool Tween::is_repeat() const { - return repeat; -} - -void Tween::set_repeat(bool p_repeat) { - repeat = p_repeat; -} - -void Tween::set_speed_scale(float p_speed) { - speed_scale = p_speed; -} - -float Tween::get_speed_scale() const { - return speed_scale; -} - -void Tween::start() { - ERR_FAIL_COND_MSG(!is_inside_tree(), "Tween was not added to the SceneTree!"); - - // Are there any pending updates? - if (pending_update != 0) { - // Start the tweens after deferring - call_deferred("start"); - return; - } - - pending_update++; - for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) { - InterpolateData &data = E->get(); - data.active = true; - } - pending_update--; - - // We want to be activated - set_active(true); - - // Don't resume from current position if stop_all() function has been used - if (was_stopped) { - seek(0); - } - was_stopped = false; -} - -void Tween::reset(Object *p_object, StringName p_key) { - // Find all interpolations that use the same object and target string - pending_update++; - for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) { - // Get the target object - InterpolateData &data = E->get(); - Object *object = ObjectDB::get_instance(data.id); - if (object == nullptr) { - continue; - } - - // Do we have the correct object and key? - if (object == p_object && (data.concatenated_key == p_key || p_key == "")) { - // Reset the tween to the initial state - data.elapsed = 0; - data.finish = false; - - // Also apply the initial state if there isn't a delay - if (data.delay == 0) { - _apply_tween_value(data, data.initial_val); - } - } - } - pending_update--; -} - -void Tween::reset_all() { - // Go through all interpolations - pending_update++; - for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) { - // Get the target data and set it back to the initial state - InterpolateData &data = E->get(); - data.elapsed = 0; - data.finish = false; - - // If there isn't a delay, apply the value to the object - if (data.delay == 0) { - _apply_tween_value(data, data.initial_val); - } - } - pending_update--; -} - -void Tween::stop(Object *p_object, StringName p_key) { - // Find the tween that has the given target object and string key - pending_update++; - for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) { - // Get the object the tween is targeting - InterpolateData &data = E->get(); - Object *object = ObjectDB::get_instance(data.id); - if (object == nullptr) { - continue; - } - - // Is this the correct object and does it have the given key? - if (object == p_object && (data.concatenated_key == p_key || p_key == "")) { - // Disable the tween - data.active = false; - } - } - pending_update--; -} - -void Tween::stop_all() { - // We no longer need to be active since all tweens have been stopped - set_active(false); - was_stopped = true; - // For each interpolation... - pending_update++; - for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) { - // Simply set it inactive - InterpolateData &data = E->get(); - data.active = false; - } - pending_update--; -} - -void Tween::resume(Object *p_object, StringName p_key) { - // We need to be activated - // TODO: What if no tween is found?? - set_active(true); - - // Find the tween that uses the given target object and string key - pending_update++; - for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) { - // Grab the object - InterpolateData &data = E->get(); - Object *object = ObjectDB::get_instance(data.id); - if (object == nullptr) { - continue; - } - - // If the object and string key match, activate it - if (object == p_object && (data.concatenated_key == p_key || p_key == "")) { - data.active = true; - } - } - pending_update--; -} - -void Tween::resume_all() { - // Set ourselves active so we can process tweens - // TODO: What if there are no tweens? We get set to active for no reason! - set_active(true); - - // For each interpolation... - pending_update++; - for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) { - // Simply grab it and set it to active - InterpolateData &data = E->get(); - data.active = true; - } - pending_update--; -} - -void Tween::remove(Object *p_object, StringName p_key) { - // If we are still updating, call this function again later - if (pending_update != 0) { - call_deferred("remove", p_object, p_key); - return; - } - - // For each interpolation... - List<List<InterpolateData>::Element *> for_removal; - for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) { - // Get the target object - InterpolateData &data = E->get(); - Object *object = ObjectDB::get_instance(data.id); - if (object == nullptr) { - continue; - } - - // If the target object and string key match, queue it for removal - if (object == p_object && (data.concatenated_key == p_key || p_key == "")) { - for_removal.push_back(E); - } - } - - // For each interpolation we wish to remove... - for (List<List<InterpolateData>::Element *>::Element *E = for_removal.front(); E; E = E->next()) { - // Erase it - interpolates.erase(E->get()); - } -} - -void Tween::_remove_by_uid(int uid) { - // If we are still updating, call this function again later - if (pending_update != 0) { - call_deferred("_remove_by_uid", uid); - return; - } - - // Find the interpolation that matches the given UID - for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) { - if (uid == E->get().uid) { - // It matches, erase it and stop looking - E->erase(); - break; - } - } -} - -void Tween::_push_interpolate_data(InterpolateData &p_data) { - pending_update++; - - // Add the new interpolation - p_data.uid = ++uid; - interpolates.push_back(p_data); - - pending_update--; +#undef APPLY_EQUATION } -void Tween::remove_all() { - // If we are still updating, call this function again later - if (pending_update != 0) { - call_deferred("remove_all"); - return; - } - // We no longer need to be active - set_active(false); - - // Clear out all interpolations and reset the uid - interpolates.clear(); - uid = 0; -} - -void Tween::seek(real_t p_time) { - // Go through each interpolation... - pending_update++; - for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) { - // Get the target data - InterpolateData &data = E->get(); - - // Update the elapsed data to be set to the target time - data.elapsed = p_time; - - // Are we at the end? - if (data.elapsed < data.delay) { - // There is still time left to go - data.finish = false; - continue; - } else if (data.elapsed >= (data.delay + data.duration)) { - // We are past the end of it, set the elapsed time to the end and mark as finished - data.elapsed = (data.delay + data.duration); - data.finish = true; - } else { - // We are not finished with this interpolation yet - data.finish = false; +Variant Tween::calculate_delta_value(Variant p_intial_val, Variant p_final_val) { + switch (p_intial_val.get_type()) { + case Variant::BOOL: { + return (int)p_final_val - (int)p_intial_val; } - // If we are a callback, do nothing special - if (data.type == INTER_CALLBACK) { - continue; + case Variant::RECT2: { + Rect2 i = p_intial_val; + Rect2 f = p_final_val; + return Rect2(f.position - i.position, f.size - i.size); } - // Run the equation on the data and apply the value - Variant result = _run_equation(data); - _apply_tween_value(data, result); - } - pending_update--; -} - -real_t Tween::tell() const { - // We want to grab the position of the furthest along tween - pending_update++; - real_t pos = 0.0; - - // For each interpolation... - for (const List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) { - // Get the data and figure out if its position is further along than the previous ones - const InterpolateData &data = E->get(); - if (data.elapsed > pos) { - // Save it if so - pos = data.elapsed; + case Variant::RECT2I: { + Rect2i i = p_intial_val; + Rect2i f = p_final_val; + return Rect2i(f.position - i.position, f.size - i.size); } - } - pending_update--; - return pos; -} - -real_t Tween::get_runtime() const { - // If the tween isn't moving, it'll last forever - if (speed_scale == 0) { - return INFINITY; - } - - pending_update++; - - // For each interpolation... - real_t runtime = 0.0; - for (const List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) { - // Get the tween data and see if it's runtime is greater than the previous tweens - const InterpolateData &data = E->get(); - real_t t = data.delay + data.duration; - if (t > runtime) { - // This is the longest running tween - runtime = t; - } - } - pending_update--; - - // Adjust the runtime for the current speed scale - return runtime / speed_scale; -} - -bool Tween::_calc_delta_val(const Variant &p_initial_val, const Variant &p_final_val, Variant &p_delta_val) { - // Get the initial, final, and delta values - const Variant &initial_val = p_initial_val; - const Variant &final_val = p_final_val; - Variant &delta_val = p_delta_val; - - // What kind of data are we interpolating? - switch (initial_val.get_type()) { - case Variant::BOOL: - // We'll treat booleans just like integers - case Variant::INT: - // Compute the integer delta - delta_val = (int)final_val - (int)initial_val; - break; - - case Variant::FLOAT: - // Convert to FLOAT and find the delta - delta_val = (real_t)final_val - (real_t)initial_val; - break; - - case Variant::VECTOR2: - // Convert to Vectors and find the delta - delta_val = final_val.operator Vector2() - initial_val.operator Vector2(); - break; - - case Variant::RECT2: { - // Build a new Rect2 and use the new position and sizes to make a delta - Rect2 i = initial_val; - Rect2 f = final_val; - delta_val = Rect2(f.position - i.position, f.size - i.size); - } break; - - case Variant::VECTOR3: - // Convert to Vectors and find the delta - delta_val = final_val.operator Vector3() - initial_val.operator Vector3(); - break; case Variant::TRANSFORM2D: { - // Build a new transform which is the difference between the initial and final values - Transform2D i = initial_val; - Transform2D f = final_val; - Transform2D d = Transform2D(); - d[0][0] = f.elements[0][0] - i.elements[0][0]; - d[0][1] = f.elements[0][1] - i.elements[0][1]; - d[1][0] = f.elements[1][0] - i.elements[1][0]; - d[1][1] = f.elements[1][1] - i.elements[1][1]; - d[2][0] = f.elements[2][0] - i.elements[2][0]; - d[2][1] = f.elements[2][1] - i.elements[2][1]; - delta_val = d; - } break; - - case Variant::QUATERNION: - // Convert to quaternianls and find the delta - delta_val = final_val.operator Quaternion() - initial_val.operator Quaternion(); - break; + Transform2D i = p_intial_val; + Transform2D f = p_final_val; + return Transform2D(f.elements[0][0] - i.elements[0][0], + f.elements[0][1] - i.elements[0][1], + f.elements[1][0] - i.elements[1][0], + f.elements[1][1] - i.elements[1][1], + f.elements[2][0] - i.elements[2][0], + f.elements[2][1] - i.elements[2][1]); + } case Variant::AABB: { - // Build a new AABB and use the new position and sizes to make a delta - AABB i = initial_val; - AABB f = final_val; - delta_val = AABB(f.position - i.position, f.size - i.size); - } break; + AABB i = p_intial_val; + AABB f = p_final_val; + return AABB(f.position - i.position, f.size - i.size); + } case Variant::BASIS: { - // Build a new basis which is the delta between the initial and final values - Basis i = initial_val; - Basis f = final_val; - delta_val = Basis(f.elements[0][0] - i.elements[0][0], + Basis i = p_intial_val; + Basis f = p_final_val; + return Basis(f.elements[0][0] - i.elements[0][0], f.elements[0][1] - i.elements[0][1], f.elements[0][2] - i.elements[0][2], f.elements[1][0] - i.elements[1][0], @@ -1227,14 +529,12 @@ bool Tween::_calc_delta_val(const Variant &p_initial_val, const Variant &p_final f.elements[2][0] - i.elements[2][0], f.elements[2][1] - i.elements[2][1], f.elements[2][2] - i.elements[2][2]); - } break; + } case Variant::TRANSFORM3D: { - // Build a new transform which is the difference between the initial and final values - Transform3D i = initial_val; - Transform3D f = final_val; - Transform3D d; - d.set(f.basis.elements[0][0] - i.basis.elements[0][0], + Transform3D i = p_intial_val; + Transform3D f = p_final_val; + return Transform3D(f.basis.elements[0][0] - i.basis.elements[0][0], f.basis.elements[0][1] - i.basis.elements[0][1], f.basis.elements[0][2] - i.basis.elements[0][2], f.basis.elements[1][0] - i.basis.elements[1][0], @@ -1246,569 +546,342 @@ bool Tween::_calc_delta_val(const Variant &p_initial_val, const Variant &p_final f.origin.x - i.origin.x, f.origin.y - i.origin.y, f.origin.z - i.origin.z); - - delta_val = d; - } break; - - case Variant::COLOR: { - // Make a new color which is the difference between each the color's RGBA attributes - Color i = initial_val; - Color f = final_val; - delta_val = Color(f.r - i.r, f.g - i.g, f.b - i.b, f.a - i.a); - } break; + } default: { - static Variant::Type supported_types[] = { - Variant::BOOL, - Variant::INT, - Variant::FLOAT, - Variant::VECTOR2, - Variant::RECT2, - Variant::VECTOR3, - Variant::TRANSFORM2D, - Variant::QUATERNION, - Variant::AABB, - Variant::BASIS, - Variant::TRANSFORM3D, - Variant::COLOR, - }; - - int length = *(&supported_types + 1) - supported_types; - String error_msg = "Invalid parameter type. Supported types are: "; - for (int i = 0; i < length; i++) { - if (i != 0) { - error_msg += ", "; - } - error_msg += Variant::get_type_name(supported_types[i]); - } - error_msg += "."; - ERR_PRINT(error_msg); - return false; + return Variant::evaluate(Variant::OP_SUBTRACT, p_final_val, p_intial_val); } }; - return true; } -void Tween::_build_interpolation(InterpolateType p_interpolation_type, Object *p_object, NodePath *p_property, StringName *p_method, Variant p_initial_val, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) { - // TODO: Add initialization+implementation for remaining interpolation types - // TODO: Fix this method's organization to take advantage of the type - - // Make a new interpolation data - InterpolateData data; - data.active = true; - data.type = p_interpolation_type; - data.finish = false; - data.elapsed = 0; +void Tween::_bind_methods() { + ClassDB::bind_method(D_METHOD("tween_property", "object", "property", "final_val", "duration"), &Tween::tween_property); + ClassDB::bind_method(D_METHOD("tween_interval", "time"), &Tween::tween_interval); + ClassDB::bind_method(D_METHOD("tween_callback", "callback"), &Tween::tween_callback); + ClassDB::bind_method(D_METHOD("tween_method", "method", "from", "to", "duration"), &Tween::tween_method); + + ClassDB::bind_method(D_METHOD("custom_step", "delta"), &Tween::custom_step); + ClassDB::bind_method(D_METHOD("stop"), &Tween::stop); + ClassDB::bind_method(D_METHOD("pause"), &Tween::pause); + ClassDB::bind_method(D_METHOD("play"), &Tween::play); + ClassDB::bind_method(D_METHOD("kill"), &Tween::kill); + + ClassDB::bind_method(D_METHOD("is_running"), &Tween::is_running); + ClassDB::bind_method(D_METHOD("is_valid"), &Tween::is_valid); + ClassDB::bind_method(D_METHOD("bind_node", "node"), &Tween::bind_node); + ClassDB::bind_method(D_METHOD("set_process_mode", "mode"), &Tween::set_process_mode); + ClassDB::bind_method(D_METHOD("set_pause_mode", "mode"), &Tween::set_pause_mode); + + ClassDB::bind_method(D_METHOD("set_parallel", "parallel"), &Tween::set_parallel, DEFVAL(true)); + ClassDB::bind_method(D_METHOD("set_loops", "loops"), &Tween::set_loops, DEFVAL(0)); + ClassDB::bind_method(D_METHOD("set_speed_scale", "speed"), &Tween::set_speed_scale); + ClassDB::bind_method(D_METHOD("set_trans", "trans"), &Tween::set_trans); + ClassDB::bind_method(D_METHOD("set_ease", "ease"), &Tween::set_ease); - // Validate and apply interpolation data + ClassDB::bind_method(D_METHOD("parallel"), &Tween::parallel); + ClassDB::bind_method(D_METHOD("chain"), &Tween::chain); - // Give it the object - ERR_FAIL_COND_MSG(p_object == nullptr, "Invalid object provided to Tween."); - data.id = p_object->get_instance_id(); + ClassDB::bind_method(D_METHOD("interpolate_value", "trans_type", "ease_type", "elapsed_time", "initial_value", "delta_value", "duration"), &Tween::interpolate_variant); - // Validate the initial and final values - ERR_FAIL_COND_MSG(p_initial_val.get_type() != p_final_val.get_type(), "Initial value type '" + Variant::get_type_name(p_initial_val.get_type()) + "' does not match final value type '" + Variant::get_type_name(p_final_val.get_type()) + "'."); - data.initial_val = p_initial_val; - data.final_val = p_final_val; + ADD_SIGNAL(MethodInfo("step_finished", PropertyInfo(Variant::INT, "idx"))); + ADD_SIGNAL(MethodInfo("loop_finished", PropertyInfo(Variant::INT, "loop_count"))); + ADD_SIGNAL(MethodInfo("finished")); - // Check the Duration - ERR_FAIL_COND_MSG(p_duration < 0, "Only non-negative duration values allowed in Tweens."); - data.duration = p_duration; + BIND_ENUM_CONSTANT(TWEEN_PROCESS_PHYSICS); + BIND_ENUM_CONSTANT(TWEEN_PROCESS_IDLE); - // Tween Delay - ERR_FAIL_COND_MSG(p_delay < 0, "Only non-negative delay values allowed in Tweens."); - data.delay = p_delay; + BIND_ENUM_CONSTANT(TWEEN_PAUSE_BOUND); + BIND_ENUM_CONSTANT(TWEEN_PAUSE_STOP); + BIND_ENUM_CONSTANT(TWEEN_PAUSE_PROCESS); - // Transition type - ERR_FAIL_COND_MSG(p_trans_type < 0 || p_trans_type >= TRANS_COUNT, "Invalid transition type provided to Tween."); - data.trans_type = p_trans_type; + BIND_ENUM_CONSTANT(TRANS_LINEAR); + BIND_ENUM_CONSTANT(TRANS_SINE); + BIND_ENUM_CONSTANT(TRANS_QUINT); + BIND_ENUM_CONSTANT(TRANS_QUART); + BIND_ENUM_CONSTANT(TRANS_QUAD); + BIND_ENUM_CONSTANT(TRANS_EXPO); + BIND_ENUM_CONSTANT(TRANS_ELASTIC); + BIND_ENUM_CONSTANT(TRANS_CUBIC); + BIND_ENUM_CONSTANT(TRANS_CIRC); + BIND_ENUM_CONSTANT(TRANS_BOUNCE); + BIND_ENUM_CONSTANT(TRANS_BACK); - // Easing type - ERR_FAIL_COND_MSG(p_ease_type < 0 || p_ease_type >= EASE_COUNT, "Invalid easing type provided to Tween."); - data.ease_type = p_ease_type; + BIND_ENUM_CONSTANT(EASE_IN); + BIND_ENUM_CONSTANT(EASE_OUT); + BIND_ENUM_CONSTANT(EASE_IN_OUT); + BIND_ENUM_CONSTANT(EASE_OUT_IN); +} - // Is the property defined? - if (p_property) { - // Check that the object actually contains the given property - bool prop_valid = false; - p_object->get_indexed(p_property->get_subnames(), &prop_valid); - ERR_FAIL_COND_MSG(!prop_valid, "Tween target object has no property named: " + p_property->get_concatenated_subnames() + "."); +Ref<PropertyTweener> PropertyTweener::from(Variant p_value) { + initial_val = p_value; + do_continue = false; + return this; +} - data.key = p_property->get_subnames(); - data.concatenated_key = p_property->get_concatenated_subnames(); - } +Ref<PropertyTweener> PropertyTweener::from_current() { + do_continue = false; + return this; +} - // Is the method defined? - if (p_method) { - // Does the object even have the requested method? - ERR_FAIL_COND_MSG(!p_object->has_method(*p_method), "Tween target object has no method named: " + *p_method + "."); +Ref<PropertyTweener> PropertyTweener::as_relative() { + relative = true; + return this; +} - data.key.push_back(*p_method); - data.concatenated_key = *p_method; - } +Ref<PropertyTweener> PropertyTweener::set_trans(Tween::TransitionType p_trans) { + trans_type = p_trans; + return this; +} - // Is there not a valid delta? - if (!_calc_delta_val(data.initial_val, data.final_val, data.delta_val)) { - return; - } +Ref<PropertyTweener> PropertyTweener::set_ease(Tween::EaseType p_ease) { + ease_type = p_ease; + return this; +} - // Add this interpolation to the total - _push_interpolate_data(data); +Ref<PropertyTweener> PropertyTweener::set_delay(float p_delay) { + delay = p_delay; + return this; } -void Tween::interpolate_property(Object *p_object, NodePath p_property, Variant p_initial_val, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) { - // If we are busy updating, call this function again later - if (pending_update != 0) { - _add_pending_command("interpolate_property", p_object, p_property, p_initial_val, p_final_val, p_duration, p_trans_type, p_ease_type, p_delay); +void PropertyTweener::start() { + elapsed_time = 0; + finished = false; + + Object *target_instance = ObjectDB::get_instance(target); + if (!target_instance) { + WARN_PRINT("Target object freed before starting, aborting Tweener."); return; } - // Check that the target object is valid - ERR_FAIL_COND_MSG(p_object == nullptr, vformat("The Tween \"%s\"'s target node is `null`. Is the node reference correct?", get_name())); - - // Get the property from the node path - p_property = p_property.get_as_property_path(); - - // If no initial value given, grab the initial value from the object - // TODO: Is this documented? This is very useful and removes a lot of clutter from tweens! - if (p_initial_val.get_type() == Variant::NIL) { - p_initial_val = p_object->get_indexed(p_property.get_subnames()); + if (do_continue) { + initial_val = target_instance->get_indexed(property); } - // Convert any integers into REALs as they are better for interpolation - if (p_initial_val.get_type() == Variant::INT) { - p_initial_val = p_initial_val.operator real_t(); - } - if (p_final_val.get_type() == Variant::INT) { - p_final_val = p_final_val.operator real_t(); + if (relative) { + final_val = Variant::evaluate(Variant::Operator::OP_ADD, initial_val, base_final_val); } - // Build the interpolation data - _build_interpolation(INTER_PROPERTY, p_object, &p_property, nullptr, p_initial_val, p_final_val, p_duration, p_trans_type, p_ease_type, p_delay); + delta_val = tween->calculate_delta_value(initial_val, final_val); } -void Tween::interpolate_method(Object *p_object, StringName p_method, Variant p_initial_val, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) { - // If we are busy updating, call this function again later - if (pending_update != 0) { - _add_pending_command("interpolate_method", p_object, p_method, p_initial_val, p_final_val, p_duration, p_trans_type, p_ease_type, p_delay); - return; +bool PropertyTweener::step(float &r_delta) { + if (finished) { + // This is needed in case there's a parallel Tweener with longer duration. + return false; } - // Check that the target object is valid - ERR_FAIL_COND_MSG(p_object == nullptr, vformat("The Tween \"%s\"'s target node is `null`. Is the node reference correct?", get_name())); - - // Convert any integers into REALs as they are better for interpolation - if (p_initial_val.get_type() == Variant::INT) { - p_initial_val = p_initial_val.operator real_t(); - } - if (p_final_val.get_type() == Variant::INT) { - p_final_val = p_final_val.operator real_t(); + Object *target_instance = ObjectDB::get_instance(target); + if (!target_instance) { + return false; } + elapsed_time += r_delta; - // Build the interpolation data - _build_interpolation(INTER_METHOD, p_object, nullptr, &p_method, p_initial_val, p_final_val, p_duration, p_trans_type, p_ease_type, p_delay); -} - -void Tween::interpolate_callback(Object *p_object, real_t p_duration, String p_callback, VARIANT_ARG_DECLARE) { - // If we are already updating, call this function again later - if (pending_update != 0) { - _add_pending_command("interpolate_callback", p_object, p_duration, p_callback, p_arg1, p_arg2, p_arg3, p_arg4, p_arg5); - return; + if (elapsed_time < delay) { + r_delta = 0; + return true; } - // Check that the target object is valid - ERR_FAIL_COND(p_object == nullptr); - - // Duration cannot be negative - ERR_FAIL_COND(p_duration < 0); - - // Check whether the object even has the callback - ERR_FAIL_COND_MSG(!p_object->has_method(p_callback), "Object has no callback named: " + p_callback + "."); - - // Build a new InterpolationData - InterpolateData data; - data.active = true; - data.type = INTER_CALLBACK; - data.finish = false; - data.call_deferred = false; - data.elapsed = 0; - - // Give the data it's configuration - data.id = p_object->get_instance_id(); - data.key.push_back(p_callback); - data.concatenated_key = p_callback; - data.duration = p_duration; - data.delay = 0; - - // Add arguments to the interpolation - int args = 0; - if (p_arg5.get_type() != Variant::NIL) { - args = 5; - } else if (p_arg4.get_type() != Variant::NIL) { - args = 4; - } else if (p_arg3.get_type() != Variant::NIL) { - args = 3; - } else if (p_arg2.get_type() != Variant::NIL) { - args = 2; - } else if (p_arg1.get_type() != Variant::NIL) { - args = 1; + float time = MIN(elapsed_time - delay, duration); + target_instance->set_indexed(property, tween->interpolate_variant(initial_val, delta_val, time, duration, trans_type, ease_type)); + + if (time < duration) { + r_delta = 0; + return true; } else { - args = 0; + finished = true; + r_delta = elapsed_time - delay - duration; + emit_signal("finished"); + return false; } - - data.args = args; - data.arg[0] = p_arg1; - data.arg[1] = p_arg2; - data.arg[2] = p_arg3; - data.arg[3] = p_arg4; - data.arg[4] = p_arg5; - - // Add the new interpolation - _push_interpolate_data(data); } -void Tween::interpolate_deferred_callback(Object *p_object, real_t p_duration, String p_callback, VARIANT_ARG_DECLARE) { - // If we are already updating, call this function again later - if (pending_update != 0) { - _add_pending_command("interpolate_deferred_callback", p_object, p_duration, p_callback, p_arg1, p_arg2, p_arg3, p_arg4, p_arg5); - return; +void PropertyTweener::set_tween(Ref<Tween> p_tween) { + tween = p_tween; + if (trans_type == Tween::TRANS_MAX) { + trans_type = tween->get_trans(); } - - // Check that the target object is valid - ERR_FAIL_COND(p_object == nullptr); - - // No negative durations allowed - ERR_FAIL_COND(p_duration < 0); - - // Confirm the callback exists on the object - ERR_FAIL_COND_MSG(!p_object->has_method(p_callback), "Object has no callback named: " + p_callback + "."); - - // Create a new InterpolateData for the callback - InterpolateData data; - data.active = true; - data.type = INTER_CALLBACK; - data.finish = false; - data.call_deferred = true; - data.elapsed = 0; - - // Give the data it's configuration - data.id = p_object->get_instance_id(); - data.key.push_back(p_callback); - data.concatenated_key = p_callback; - data.duration = p_duration; - data.delay = 0; - - // Collect arguments for the callback - int args = 0; - if (p_arg5.get_type() != Variant::NIL) { - args = 5; - } else if (p_arg4.get_type() != Variant::NIL) { - args = 4; - } else if (p_arg3.get_type() != Variant::NIL) { - args = 3; - } else if (p_arg2.get_type() != Variant::NIL) { - args = 2; - } else if (p_arg1.get_type() != Variant::NIL) { - args = 1; - } else { - args = 0; + if (ease_type == Tween::EASE_MAX) { + ease_type = tween->get_ease(); } +} - data.args = args; - data.arg[0] = p_arg1; - data.arg[1] = p_arg2; - data.arg[2] = p_arg3; - data.arg[3] = p_arg4; - data.arg[4] = p_arg5; +void PropertyTweener::_bind_methods() { + ClassDB::bind_method(D_METHOD("from", "value"), &PropertyTweener::from); + ClassDB::bind_method(D_METHOD("from_current"), &PropertyTweener::from_current); + ClassDB::bind_method(D_METHOD("as_relative"), &PropertyTweener::as_relative); + ClassDB::bind_method(D_METHOD("set_trans", "trans"), &PropertyTweener::set_trans); + ClassDB::bind_method(D_METHOD("set_ease", "ease"), &PropertyTweener::set_ease); + ClassDB::bind_method(D_METHOD("set_delay", "delay"), &PropertyTweener::set_delay); +} - // Add the new interpolation - _push_interpolate_data(data); +PropertyTweener::PropertyTweener(Object *p_target, NodePath p_property, Variant p_to, float p_duration) { + target = p_target->get_instance_id(); + property = p_property.get_as_property_path().get_subnames(); + initial_val = p_target->get_indexed(property); + base_final_val = p_to; + final_val = base_final_val; + duration = p_duration; } -void Tween::follow_property(Object *p_object, NodePath p_property, Variant p_initial_val, Object *p_target, NodePath p_target_property, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) { - // If we are already updating, call this function again later - if (pending_update != 0) { - _add_pending_command("follow_property", p_object, p_property, p_initial_val, p_target, p_target_property, p_duration, p_trans_type, p_ease_type, p_delay); - return; - } +PropertyTweener::PropertyTweener() { + ERR_FAIL_MSG("Can't create empty PropertyTweener. Use get_tree().tween_property() or tween_property() instead."); +} - // Get the two properties from their paths - p_property = p_property.get_as_property_path(); - p_target_property = p_target_property.get_as_property_path(); +void IntervalTweener::start() { + elapsed_time = 0; + finished = false; +} - // If no initial value is given, grab it from the source object - // TODO: Is this documented? It's really helpful for decluttering tweens - if (p_initial_val.get_type() == Variant::NIL) { - p_initial_val = p_object->get_indexed(p_property.get_subnames()); +bool IntervalTweener::step(float &r_delta) { + if (finished) { + return false; } - // Convert initial INT values to FLOAT as they are better for interpolation - if (p_initial_val.get_type() == Variant::INT) { - p_initial_val = p_initial_val.operator real_t(); + elapsed_time += r_delta; + + if (elapsed_time < duration) { + r_delta = 0; + return true; + } else { + finished = true; + r_delta = elapsed_time - duration; + emit_signal("finished"); + return false; } +} - // Confirm the source and target objects are valid - ERR_FAIL_COND(p_object == nullptr); - ERR_FAIL_COND(p_target == nullptr); +IntervalTweener::IntervalTweener(float p_time) { + duration = p_time; +} - // No negative durations - ERR_FAIL_COND(p_duration < 0); +IntervalTweener::IntervalTweener() { + ERR_FAIL_MSG("Can't create empty IntervalTweener. Use get_tree().tween_interval() instead."); +} - // Ensure transition and easing types are valid - ERR_FAIL_COND(p_trans_type < 0 || p_trans_type >= TRANS_COUNT); - ERR_FAIL_COND(p_ease_type < 0 || p_ease_type >= EASE_COUNT); +Ref<CallbackTweener> CallbackTweener::set_delay(float p_delay) { + delay = p_delay; + return this; +} - // No negative delays - ERR_FAIL_COND(p_delay < 0); +void CallbackTweener::start() { + elapsed_time = 0; + finished = false; +} - // Confirm the source and target objects have the desired properties - bool prop_valid = false; - p_object->get_indexed(p_property.get_subnames(), &prop_valid); - ERR_FAIL_COND(!prop_valid); +bool CallbackTweener::step(float &r_delta) { + if (finished) { + return false; + } - bool target_prop_valid = false; - Variant target_val = p_target->get_indexed(p_target_property.get_subnames(), &target_prop_valid); - ERR_FAIL_COND(!target_prop_valid); + elapsed_time += r_delta; + if (elapsed_time >= delay) { + Variant result; + Callable::CallError ce; + callback.call(nullptr, 0, result, ce); + if (ce.error != Callable::CallError::CALL_OK) { + ERR_FAIL_V_MSG(false, "Error calling method from CallbackTweener: " + Variant::get_call_error_text(this, callback.get_method(), nullptr, 0, ce)); + } - // Convert target INT to FLOAT since it is better for interpolation - if (target_val.get_type() == Variant::INT) { - target_val = target_val.operator real_t(); + finished = true; + r_delta = elapsed_time - delay; + emit_signal("finished"); + return false; } - // Verify that the target value and initial value are the same type - ERR_FAIL_COND(target_val.get_type() != p_initial_val.get_type()); - - // Create a new InterpolateData - InterpolateData data; - data.active = true; - data.type = FOLLOW_PROPERTY; - data.finish = false; - data.elapsed = 0; - - // Give the InterpolateData it's configuration - data.id = p_object->get_instance_id(); - data.key = p_property.get_subnames(); - data.concatenated_key = p_property.get_concatenated_subnames(); - data.initial_val = p_initial_val; - data.target_id = p_target->get_instance_id(); - data.target_key = p_target_property.get_subnames(); - data.duration = p_duration; - data.trans_type = p_trans_type; - data.ease_type = p_ease_type; - data.delay = p_delay; - - // Add the interpolation - _push_interpolate_data(data); -} - -void Tween::follow_method(Object *p_object, StringName p_method, Variant p_initial_val, Object *p_target, StringName p_target_method, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) { - // If we are currently updating, call this function again later - if (pending_update != 0) { - _add_pending_command("follow_method", p_object, p_method, p_initial_val, p_target, p_target_method, p_duration, p_trans_type, p_ease_type, p_delay); - return; - } - // Convert initial INT values to FLOAT as they are better for interpolation - if (p_initial_val.get_type() == Variant::INT) { - p_initial_val = p_initial_val.operator real_t(); - } + r_delta = 0; + return true; +} - // Verify the source and target objects are valid - ERR_FAIL_COND(p_object == nullptr); - ERR_FAIL_COND(p_target == nullptr); +void CallbackTweener::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_delay", "delay"), &CallbackTweener::set_delay); +} - // No negative durations - ERR_FAIL_COND(p_duration < 0); +CallbackTweener::CallbackTweener(Callable p_callback) { + callback = p_callback; +} - // Ensure that the transition and ease types are valid - ERR_FAIL_COND(p_trans_type < 0 || p_trans_type >= TRANS_COUNT); - ERR_FAIL_COND(p_ease_type < 0 || p_ease_type >= EASE_COUNT); +CallbackTweener::CallbackTweener() { + ERR_FAIL_MSG("Can't create empty CallbackTweener. Use get_tree().tween_callback() instead."); +} - // No negative delays - ERR_FAIL_COND(p_delay < 0); +Ref<MethodTweener> MethodTweener::set_delay(float p_delay) { + delay = p_delay; + return this; +} - // Confirm both objects have the target methods - ERR_FAIL_COND_MSG(!p_object->has_method(p_method), "Object has no method named: " + p_method + "."); - ERR_FAIL_COND_MSG(!p_target->has_method(p_target_method), "Target has no method named: " + p_target_method + "."); +Ref<MethodTweener> MethodTweener::set_trans(Tween::TransitionType p_trans) { + trans_type = p_trans; + return this; +} - // Call the method to get the target value - Callable::CallError error; - Variant target_val = p_target->call(p_target_method, nullptr, 0, error); - ERR_FAIL_COND(error.error != Callable::CallError::CALL_OK); +Ref<MethodTweener> MethodTweener::set_ease(Tween::EaseType p_ease) { + ease_type = p_ease; + return this; +} - // Convert target INT values to FLOAT as they are better for interpolation - if (target_val.get_type() == Variant::INT) { - target_val = target_val.operator real_t(); - } - ERR_FAIL_COND(target_val.get_type() != p_initial_val.get_type()); - - // Make the new InterpolateData for the method follow - InterpolateData data; - data.active = true; - data.type = FOLLOW_METHOD; - data.finish = false; - data.elapsed = 0; - - // Give the data it's configuration - data.id = p_object->get_instance_id(); - data.key.push_back(p_method); - data.concatenated_key = p_method; - data.initial_val = p_initial_val; - data.target_id = p_target->get_instance_id(); - data.target_key.push_back(p_target_method); - data.duration = p_duration; - data.trans_type = p_trans_type; - data.ease_type = p_ease_type; - data.delay = p_delay; - - // Add the new interpolation - _push_interpolate_data(data); -} - -void Tween::targeting_property(Object *p_object, NodePath p_property, Object *p_initial, NodePath p_initial_property, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) { - // If we are currently updating, call this function again later - if (pending_update != 0) { - _add_pending_command("targeting_property", p_object, p_property, p_initial, p_initial_property, p_final_val, p_duration, p_trans_type, p_ease_type, p_delay); - return; - } - // Grab the target property and the target property - p_property = p_property.get_as_property_path(); - p_initial_property = p_initial_property.get_as_property_path(); +void MethodTweener::start() { + elapsed_time = 0; + finished = false; +} - // Convert the initial INT values to FLOAT as they are better for Interpolation - if (p_final_val.get_type() == Variant::INT) { - p_final_val = p_final_val.operator real_t(); +bool MethodTweener::step(float &r_delta) { + if (finished) { + return false; } - // Verify both objects are valid - ERR_FAIL_COND(p_object == nullptr); - ERR_FAIL_COND(p_initial == nullptr); - - // No negative durations - ERR_FAIL_COND(p_duration < 0); - - // Ensure transition and easing types are valid - ERR_FAIL_COND(p_trans_type < 0 || p_trans_type >= TRANS_COUNT); - ERR_FAIL_COND(p_ease_type < 0 || p_ease_type >= EASE_COUNT); - - // No negative delays - ERR_FAIL_COND(p_delay < 0); - - // Ensure the initial and target properties exist on their objects - bool prop_valid = false; - p_object->get_indexed(p_property.get_subnames(), &prop_valid); - ERR_FAIL_COND(!prop_valid); + elapsed_time += r_delta; - bool initial_prop_valid = false; - Variant initial_val = p_initial->get_indexed(p_initial_property.get_subnames(), &initial_prop_valid); - ERR_FAIL_COND(!initial_prop_valid); - - // Convert the initial INT value to FLOAT as it is better for interpolation - if (initial_val.get_type() == Variant::INT) { - initial_val = initial_val.operator real_t(); - } - ERR_FAIL_COND(initial_val.get_type() != p_final_val.get_type()); - - // Build the InterpolateData object - InterpolateData data; - data.active = true; - data.type = TARGETING_PROPERTY; - data.finish = false; - data.elapsed = 0; - - // Give the data it's configuration - data.id = p_object->get_instance_id(); - data.key = p_property.get_subnames(); - data.concatenated_key = p_property.get_concatenated_subnames(); - data.target_id = p_initial->get_instance_id(); - data.target_key = p_initial_property.get_subnames(); - data.initial_val = initial_val; - data.final_val = p_final_val; - data.duration = p_duration; - data.trans_type = p_trans_type; - data.ease_type = p_ease_type; - data.delay = p_delay; - - // Ensure there is a valid delta - if (!_calc_delta_val(data.initial_val, data.final_val, data.delta_val)) { - return; + if (elapsed_time < delay) { + r_delta = 0; + return true; } - // Add the interpolation - _push_interpolate_data(data); -} + float time = MIN(elapsed_time - delay, duration); + Variant current_val = tween->interpolate_variant(initial_val, delta_val, time, duration, trans_type, ease_type); + const Variant **argptr = (const Variant **)alloca(sizeof(Variant *)); + argptr[0] = ¤t_val; -void Tween::targeting_method(Object *p_object, StringName p_method, Object *p_initial, StringName p_initial_method, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) { - // If we are currently updating, call this function again later - if (pending_update != 0) { - _add_pending_command("targeting_method", p_object, p_method, p_initial, p_initial_method, p_final_val, p_duration, p_trans_type, p_ease_type, p_delay); - return; + Variant result; + Callable::CallError ce; + callback.call(argptr, 1, result, ce); + if (ce.error != Callable::CallError::CALL_OK) { + ERR_FAIL_V_MSG(false, "Error calling method from MethodTweener: " + Variant::get_call_error_text(this, callback.get_method(), argptr, 1, ce)); } - // Convert final INT values to FLOAT as they are better for interpolation - if (p_final_val.get_type() == Variant::INT) { - p_final_val = p_final_val.operator real_t(); + if (time < duration) { + r_delta = 0; + return true; + } else { + finished = true; + r_delta = elapsed_time - delay - duration; + emit_signal("finished"); + return false; } +} - // Make sure the given objects are valid - ERR_FAIL_COND(p_object == nullptr); - ERR_FAIL_COND(p_initial == nullptr); - - // No negative durations - ERR_FAIL_COND(p_duration < 0); - - // Ensure transition and easing types are valid - ERR_FAIL_COND(p_trans_type < 0 || p_trans_type >= TRANS_COUNT); - ERR_FAIL_COND(p_ease_type < 0 || p_ease_type >= EASE_COUNT); - - // No negative delays - ERR_FAIL_COND(p_delay < 0); - - // Make sure both objects have the given method - ERR_FAIL_COND_MSG(!p_object->has_method(p_method), "Object has no method named: " + p_method + "."); - ERR_FAIL_COND_MSG(!p_initial->has_method(p_initial_method), "Initial Object has no method named: " + p_initial_method + "."); - - // Call the method to get the initial value - Callable::CallError error; - Variant initial_val = p_initial->call(p_initial_method, nullptr, 0, error); - ERR_FAIL_COND(error.error != Callable::CallError::CALL_OK); - - // Convert initial INT values to FLOAT as they aer better for interpolation - if (initial_val.get_type() == Variant::INT) { - initial_val = initial_val.operator real_t(); +void MethodTweener::set_tween(Ref<Tween> p_tween) { + tween = p_tween; + if (trans_type == Tween::TRANS_MAX) { + trans_type = tween->get_trans(); } - ERR_FAIL_COND(initial_val.get_type() != p_final_val.get_type()); - - // Build the new InterpolateData object - InterpolateData data; - data.active = true; - data.type = TARGETING_METHOD; - data.finish = false; - data.elapsed = 0; - - // Configure the data - data.id = p_object->get_instance_id(); - data.key.push_back(p_method); - data.concatenated_key = p_method; - data.target_id = p_initial->get_instance_id(); - data.target_key.push_back(p_initial_method); - data.initial_val = initial_val; - data.final_val = p_final_val; - data.duration = p_duration; - data.trans_type = p_trans_type; - data.ease_type = p_ease_type; - data.delay = p_delay; - - // Ensure there is a valid delta - if (!_calc_delta_val(data.initial_val, data.final_val, data.delta_val)) { - return; + if (ease_type == Tween::EASE_MAX) { + ease_type = tween->get_ease(); } +} - // Add the interpolation - _push_interpolate_data(data); +void MethodTweener::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_delay", "delay"), &MethodTweener::set_delay); + ClassDB::bind_method(D_METHOD("set_trans", "trans"), &MethodTweener::set_trans); + ClassDB::bind_method(D_METHOD("set_ease", "ease"), &MethodTweener::set_ease); } -Tween::Tween() { +MethodTweener::MethodTweener(Callable p_callback, float p_from, float p_to, float p_duration) { + callback = p_callback; + initial_val = p_from; + delta_val = tween->calculate_delta_value(p_from, p_to); + duration = p_duration; } -Tween::~Tween() { +MethodTweener::MethodTweener() { + ERR_FAIL_MSG("Can't create empty MethodTweener. Use get_tree().tween_method() instead."); } diff --git a/scene/animation/tween.h b/scene/animation/tween.h index 142c0c65e0..947cdb7c2d 100644 --- a/scene/animation/tween.h +++ b/scene/animation/tween.h @@ -31,10 +31,33 @@ #ifndef TWEEN_H #define TWEEN_H -#include "scene/main/node.h" +#include "core/object/ref_counted.h" -class Tween : public Node { - GDCLASS(Tween, Node); +class Tween; +class Node; + +class Tweener : public RefCounted { + GDCLASS(Tweener, RefCounted); + +public: + virtual void set_tween(Ref<Tween> p_tween); + virtual void start() = 0; + virtual bool step(float &r_delta) = 0; + +protected: + static void _bind_methods(); + Ref<Tween> tween; + float elapsed_time = 0; + bool finished = false; +}; + +class PropertyTweener; +class IntervalTweener; +class CallbackTweener; +class MethodTweener; + +class Tween : public RefCounted { + GDCLASS(Tween, RefCounted); public: enum TweenProcessMode { @@ -42,6 +65,12 @@ public: TWEEN_PROCESS_IDLE, }; + enum TweenPauseMode { + TWEEN_PAUSE_BOUND, + TWEEN_PAUSE_STOP, + TWEEN_PAUSE_PROCESS, + }; + enum TransitionType { TRANS_LINEAR, TRANS_SINE, @@ -54,8 +83,7 @@ public: TRANS_CIRC, TRANS_BOUNCE, TRANS_BACK, - - TRANS_COUNT, + TRANS_MAX }; enum EaseType { @@ -63,130 +91,187 @@ public: EASE_OUT, EASE_IN_OUT, EASE_OUT_IN, - - EASE_COUNT, + EASE_MAX }; private: - enum InterpolateType { - INTER_PROPERTY, - INTER_METHOD, - FOLLOW_PROPERTY, - FOLLOW_METHOD, - TARGETING_PROPERTY, - TARGETING_METHOD, - INTER_CALLBACK, - }; + TweenProcessMode process_mode = TweenProcessMode::TWEEN_PROCESS_IDLE; + TweenPauseMode pause_mode = TweenPauseMode::TWEEN_PAUSE_STOP; + TransitionType default_transition = TransitionType::TRANS_LINEAR; + EaseType default_ease = EaseType::EASE_IN_OUT; + ObjectID bound_node; - struct InterpolateData { - bool active = false; - InterpolateType type = INTER_CALLBACK; - bool finish = false; - bool call_deferred = false; - real_t elapsed = 0.0; - ObjectID id; - Vector<StringName> key; - StringName concatenated_key; - Variant initial_val; - Variant delta_val; - Variant final_val; - ObjectID target_id; - Vector<StringName> target_key; - real_t duration = 0.0; - TransitionType trans_type = TransitionType::TRANS_BACK; - EaseType ease_type = EaseType::EASE_COUNT; - real_t delay = 0.0; - int args = 0; - Variant arg[5]; - int uid = 0; - }; + Vector<List<Ref<Tweener>>> tweeners; + int current_step = -1; + int loops = 1; + int loops_done = 0; + float speed_scale = 1; - String autoplay; - TweenProcessMode tween_process_mode = TWEEN_PROCESS_IDLE; - bool repeat = false; - float speed_scale = 1.0; - mutable int pending_update = 0; - int uid = 0; - bool was_stopped = false; + bool is_bound = false; + bool started = false; + bool running = true; + bool dead = false; + bool invalid = true; + bool default_parallel = false; + bool parallel_enabled = false; - List<InterpolateData> interpolates; + typedef real_t (*interpolater)(real_t t, real_t b, real_t c, real_t d); + static interpolater interpolaters[TRANS_MAX][EASE_MAX]; - struct PendingCommand { - StringName key; - int args = 0; - Variant arg[10]; - }; - List<PendingCommand> pending_commands; + void start_tweeners(); - void _add_pending_command(StringName p_key, const Variant &p_arg1 = Variant(), const Variant &p_arg2 = Variant(), const Variant &p_arg3 = Variant(), const Variant &p_arg4 = Variant(), const Variant &p_arg5 = Variant(), const Variant &p_arg6 = Variant(), const Variant &p_arg7 = Variant(), const Variant &p_arg8 = Variant(), const Variant &p_arg9 = Variant(), const Variant &p_arg10 = Variant()); - void _process_pending_commands(); +protected: + static void _bind_methods(); - typedef real_t (*interpolater)(real_t t, real_t b, real_t c, real_t d); - static interpolater interpolaters[TRANS_COUNT][EASE_COUNT]; +public: + Ref<PropertyTweener> tween_property(Object *p_target, NodePath p_property, Variant p_to, float p_duration); + Ref<IntervalTweener> tween_interval(float p_time); + Ref<CallbackTweener> tween_callback(Callable p_callback); + Ref<MethodTweener> tween_method(Callable p_callback, float p_from, float p_to, float p_duration); + Ref<Tween> append(Ref<Tweener> p_tweener); - real_t _run_equation(TransitionType p_trans_type, EaseType p_ease_type, real_t t, real_t b, real_t c, real_t d); - Variant &_get_delta_val(InterpolateData &p_data); - Variant _get_initial_val(const InterpolateData &p_data) const; - Variant _get_final_val(const InterpolateData &p_data) const; - Variant _run_equation(InterpolateData &p_data); - bool _calc_delta_val(const Variant &p_initial_val, const Variant &p_final_val, Variant &p_delta_val); - bool _apply_tween_value(InterpolateData &p_data, Variant &value); + bool custom_step(float p_delta); + void stop(); + void pause(); + void play(); + void kill(); - void _tween_process(float p_delta); - void _remove_by_uid(int uid); - void _push_interpolate_data(InterpolateData &p_data); - void _build_interpolation(InterpolateType p_interpolation_type, Object *p_object, NodePath *p_property, StringName *p_method, Variant p_initial_val, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay); + bool is_running(); + void set_valid(bool p_valid); + bool is_valid(); -protected: - bool _set(const StringName &p_name, const Variant &p_value); - bool _get(const StringName &p_name, Variant &r_ret) const; - void _get_property_list(List<PropertyInfo> *p_list) const; - void _notification(int p_what); + Ref<Tween> bind_node(Node *p_node); + Ref<Tween> set_process_mode(TweenProcessMode p_mode); + TweenProcessMode get_process_mode(); + Ref<Tween> set_pause_mode(TweenPauseMode p_mode); + TweenPauseMode get_pause_mode(); - static void _bind_methods(); + Ref<Tween> set_parallel(bool p_parallel); + Ref<Tween> set_loops(int p_loops); + Ref<Tween> set_speed_scale(float p_speed); + Ref<Tween> set_trans(TransitionType p_trans); + TransitionType get_trans(); + Ref<Tween> set_ease(EaseType p_ease); + EaseType get_ease(); -public: - bool is_active() const; - void set_active(bool p_active); - - bool is_repeat() const; - void set_repeat(bool p_repeat); - - void set_tween_process_mode(TweenProcessMode p_mode); - TweenProcessMode get_tween_process_mode() const; - - void set_speed_scale(float p_speed); - float get_speed_scale() const; - - void start(); - void reset(Object *p_object, StringName p_key); - void reset_all(); - void stop(Object *p_object, StringName p_key); - void stop_all(); - void resume(Object *p_object, StringName p_key); - void resume_all(); - void remove(Object *p_object, StringName p_key); - void remove_all(); - - void seek(real_t p_time); - real_t tell() const; - real_t get_runtime() const; - - void interpolate_property(Object *p_object, NodePath p_property, Variant p_initial_val, Variant p_final_val, real_t p_duration, TransitionType p_trans_type = TRANS_LINEAR, EaseType p_ease_type = EASE_IN_OUT, real_t p_delay = 0); - void interpolate_method(Object *p_object, StringName p_method, Variant p_initial_val, Variant p_final_val, real_t p_duration, TransitionType p_trans_type = TRANS_LINEAR, EaseType p_ease_type = EASE_IN_OUT, real_t p_delay = 0); - void interpolate_callback(Object *p_object, real_t p_duration, String p_callback, VARIANT_ARG_DECLARE); - void interpolate_deferred_callback(Object *p_object, real_t p_duration, String p_callback, VARIANT_ARG_DECLARE); - void follow_property(Object *p_object, NodePath p_property, Variant p_initial_val, Object *p_target, NodePath p_target_property, real_t p_duration, TransitionType p_trans_type = TRANS_LINEAR, EaseType p_ease_type = EASE_IN_OUT, real_t p_delay = 0); - void follow_method(Object *p_object, StringName p_method, Variant p_initial_val, Object *p_target, StringName p_target_method, real_t p_duration, TransitionType p_trans_type = TRANS_LINEAR, EaseType p_ease_type = EASE_IN_OUT, real_t p_delay = 0); - void targeting_property(Object *p_object, NodePath p_property, Object *p_initial, NodePath p_initial_property, Variant p_final_val, real_t p_duration, TransitionType p_trans_type = TRANS_LINEAR, EaseType p_ease_type = EASE_IN_OUT, real_t p_delay = 0); - void targeting_method(Object *p_object, StringName p_method, Object *p_initial, StringName p_initial_method, Variant p_final_val, real_t p_duration, TransitionType p_trans_type = TRANS_LINEAR, EaseType p_ease_type = EASE_IN_OUT, real_t p_delay = 0); - - Tween(); - ~Tween(); + Ref<Tween> parallel(); + Ref<Tween> chain(); + + real_t run_equation(TransitionType p_trans_type, EaseType p_ease_type, real_t t, real_t b, real_t c, real_t d); + Variant interpolate_variant(Variant p_initial_val, Variant p_delta_val, float p_time, float p_duration, Tween::TransitionType p_trans, Tween::EaseType p_ease); + Variant calculate_delta_value(Variant p_intial_val, Variant p_final_val); + + bool step(float p_delta); + bool should_pause(); + + Tween() {} }; +VARIANT_ENUM_CAST(Tween::TweenPauseMode); VARIANT_ENUM_CAST(Tween::TweenProcessMode); VARIANT_ENUM_CAST(Tween::TransitionType); VARIANT_ENUM_CAST(Tween::EaseType); +class PropertyTweener : public Tweener { + GDCLASS(PropertyTweener, Tweener); + +public: + Ref<PropertyTweener> from(Variant p_value); + Ref<PropertyTweener> from_current(); + Ref<PropertyTweener> as_relative(); + Ref<PropertyTweener> set_trans(Tween::TransitionType p_trans); + Ref<PropertyTweener> set_ease(Tween::EaseType p_ease); + Ref<PropertyTweener> set_delay(float p_delay); + + void set_tween(Ref<Tween> p_tween) override; + void start() override; + bool step(float &r_delta) override; + + PropertyTweener(Object *p_target, NodePath p_property, Variant p_to, float p_duration); + PropertyTweener(); + +protected: + static void _bind_methods(); + +private: + ObjectID target; + Vector<StringName> property; + Variant initial_val; + Variant base_final_val; + Variant final_val; + Variant delta_val; + + float duration = 0; + Tween::TransitionType trans_type = Tween::TRANS_MAX; // This is set inside set_tween(); + Tween::EaseType ease_type = Tween::EASE_MAX; + + float delay = 0; + bool do_continue = true; + bool relative = false; +}; + +class IntervalTweener : public Tweener { + GDCLASS(IntervalTweener, Tweener); + +public: + void start() override; + bool step(float &r_delta) override; + + IntervalTweener(float p_time); + IntervalTweener(); + +private: + float duration = 0; +}; + +class CallbackTweener : public Tweener { + GDCLASS(CallbackTweener, Tweener); + +public: + Ref<CallbackTweener> set_delay(float p_delay); + + void start() override; + bool step(float &r_delta) override; + + CallbackTweener(Callable p_callback); + CallbackTweener(); + +protected: + static void _bind_methods(); + +private: + Callable callback; + float delay = 0; +}; + +class MethodTweener : public Tweener { + GDCLASS(MethodTweener, Tweener); + +public: + Ref<MethodTweener> set_trans(Tween::TransitionType p_trans); + Ref<MethodTweener> set_ease(Tween::EaseType p_ease); + Ref<MethodTweener> set_delay(float p_delay); + + void set_tween(Ref<Tween> p_tween) override; + void start() override; + bool step(float &r_delta) override; + + MethodTweener(Callable p_callback, float p_from, float p_to, float p_duration); + MethodTweener(); + +protected: + static void _bind_methods(); + +private: + float duration = 0; + float delay = 0; + Tween::TransitionType trans_type = Tween::TRANS_MAX; + Tween::EaseType ease_type = Tween::EASE_MAX; + + Ref<Tween> tween; + Variant initial_val; + Variant delta_val; + Callable callback; +}; + #endif diff --git a/scene/debugger/scene_debugger.cpp b/scene/debugger/scene_debugger.cpp index 11ce9b2ddc..1e121ab6e5 100644 --- a/scene/debugger/scene_debugger.cpp +++ b/scene/debugger/scene_debugger.cpp @@ -525,7 +525,7 @@ void LiveEditor::_node_set_func(int p_id, const StringName &p_prop, const Varian for (Set<Node *>::Element *F = E->get().front(); F; F = F->next()) { Node *n = F->get(); - if (base && !base->is_a_parent_of(n)) { + if (base && !base->is_ancestor_of(n)) { continue; } @@ -569,7 +569,7 @@ void LiveEditor::_node_call_func(int p_id, const StringName &p_method, VARIANT_A for (Set<Node *>::Element *F = E->get().front(); F; F = F->next()) { Node *n = F->get(); - if (base && !base->is_a_parent_of(n)) { + if (base && !base->is_ancestor_of(n)) { continue; } @@ -652,7 +652,7 @@ void LiveEditor::_create_node_func(const NodePath &p_parent, const String &p_typ for (Set<Node *>::Element *F = E->get().front(); F; F = F->next()) { Node *n = F->get(); - if (base && !base->is_a_parent_of(n)) { + if (base && !base->is_ancestor_of(n)) { continue; } @@ -661,7 +661,7 @@ void LiveEditor::_create_node_func(const NodePath &p_parent, const String &p_typ } Node *n2 = n->get_node(p_parent); - Node *no = Object::cast_to<Node>(ClassDB::instance(p_type)); + Node *no = Object::cast_to<Node>(ClassDB::instantiate(p_type)); if (!no) { continue; } @@ -696,7 +696,7 @@ void LiveEditor::_instance_node_func(const NodePath &p_parent, const String &p_p for (Set<Node *>::Element *F = E->get().front(); F; F = F->next()) { Node *n = F->get(); - if (base && !base->is_a_parent_of(n)) { + if (base && !base->is_ancestor_of(n)) { continue; } @@ -705,7 +705,7 @@ void LiveEditor::_instance_node_func(const NodePath &p_parent, const String &p_p } Node *n2 = n->get_node(p_parent); - Node *no = ps->instance(); + Node *no = ps->instantiate(); if (!no) { continue; } @@ -736,7 +736,7 @@ void LiveEditor::_remove_node_func(const NodePath &p_at) { Node *n = F->get(); - if (base && !base->is_a_parent_of(n)) { + if (base && !base->is_ancestor_of(n)) { continue; } @@ -772,7 +772,7 @@ void LiveEditor::_remove_and_keep_node_func(const NodePath &p_at, ObjectID p_kee Node *n = F->get(); - if (base && !base->is_a_parent_of(n)) { + if (base && !base->is_ancestor_of(n)) { continue; } @@ -811,7 +811,7 @@ void LiveEditor::_restore_node_func(ObjectID p_id, const NodePath &p_at, int p_a Node *n = F->get(); - if (base && !base->is_a_parent_of(n)) { + if (base && !base->is_ancestor_of(n)) { continue; } @@ -862,7 +862,7 @@ void LiveEditor::_duplicate_node_func(const NodePath &p_at, const String &p_new_ for (Set<Node *>::Element *F = E->get().front(); F; F = F->next()) { Node *n = F->get(); - if (base && !base->is_a_parent_of(n)) { + if (base && !base->is_ancestor_of(n)) { continue; } @@ -901,7 +901,7 @@ void LiveEditor::_reparent_node_func(const NodePath &p_at, const NodePath &p_new for (Set<Node *>::Element *F = E->get().front(); F; F = F->next()) { Node *n = F->get(); - if (base && !base->is_a_parent_of(n)) { + if (base && !base->is_ancestor_of(n)) { continue; } diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp index 66155958cf..c1ae0479f5 100644 --- a/scene/gui/base_button.cpp +++ b/scene/gui/base_button.cpp @@ -391,7 +391,7 @@ bool BaseButton::_is_focus_owner_in_shorcut_context() const { Control *vp_focus = get_focus_owner(); // If the context is valid and the viewport focus is valid, check if the context is the focus or is a parent of it. - return ctx_node && vp_focus && (ctx_node == vp_focus || ctx_node->is_a_parent_of(vp_focus)); + return ctx_node && vp_focus && (ctx_node == vp_focus || ctx_node->is_ancestor_of(vp_focus)); } void BaseButton::_bind_methods() { diff --git a/scene/gui/button.cpp b/scene/gui/button.cpp index c0df5271b4..bcc273114b 100644 --- a/scene/gui/button.cpp +++ b/scene/gui/button.cpp @@ -49,9 +49,14 @@ Size2 Button::get_minimum_size() const { if (!_icon.is_null()) { minsize.height = MAX(minsize.height, _icon->get_height()); - minsize.width += _icon->get_width(); - if (xl_text != "") { - minsize.width += get_theme_constant("hseparation"); + + if (icon_align != ALIGN_CENTER) { + minsize.width += _icon->get_width(); + if (xl_text != "") { + minsize.width += get_theme_constant("hseparation"); + } + } else { + minsize.width = MAX(minsize.width, _icon->get_width()); } } } @@ -202,6 +207,21 @@ void Button::_notification(int p_what) { } Rect2 icon_region = Rect2(); + TextAlign icon_align_rtl_checked = icon_align; + TextAlign align_rtl_checked = align; + // Swap icon and text alignment sides if right-to-left layout is set. + if (rtl) { + if (icon_align == ALIGN_RIGHT) { + icon_align_rtl_checked = ALIGN_LEFT; + } else if (icon_align == ALIGN_LEFT) { + icon_align_rtl_checked = ALIGN_RIGHT; + } + if (align == ALIGN_RIGHT) { + align_rtl_checked = ALIGN_LEFT; + } else if (align == ALIGN_LEFT) { + align_rtl_checked = ALIGN_RIGHT; + } + } if (!_icon.is_null()) { int valign = size.height - style->get_minimum_size().y; if (is_disabled()) { @@ -209,20 +229,27 @@ void Button::_notification(int p_what) { } float icon_ofs_region = 0.0; - if (rtl) { - if (_internal_margin[SIDE_RIGHT] > 0) { - icon_ofs_region = _internal_margin[SIDE_RIGHT] + get_theme_constant("hseparation"); - } - } else { + Point2 style_offset; + Size2 icon_size = _icon->get_size(); + if (icon_align_rtl_checked == ALIGN_LEFT) { + style_offset.x = style->get_margin(SIDE_LEFT); if (_internal_margin[SIDE_LEFT] > 0) { icon_ofs_region = _internal_margin[SIDE_LEFT] + get_theme_constant("hseparation"); } + } else if (icon_align_rtl_checked == ALIGN_CENTER) { + style_offset.x = 0.0; + } else if (icon_align_rtl_checked == ALIGN_RIGHT) { + style_offset.x = -style->get_margin(SIDE_RIGHT); + if (_internal_margin[SIDE_RIGHT] > 0) { + icon_ofs_region = -_internal_margin[SIDE_RIGHT] - get_theme_constant("hseparation"); + } } + style_offset.y = style->get_margin(SIDE_TOP); if (expand_icon) { Size2 _size = get_size() - style->get_offset() * 2; _size.width -= get_theme_constant("hseparation") + icon_ofs_region; - if (!clip_text) { + if (!clip_text && icon_align_rtl_checked != ALIGN_CENTER) { _size.width -= text_buf->get_size().width; } float icon_width = _icon->get_width() * _size.height / _icon->get_height(); @@ -233,21 +260,26 @@ void Button::_notification(int p_what) { icon_height = _icon->get_height() * icon_width / _icon->get_width(); } - if (rtl) { - icon_region = Rect2(Point2(size.width - (icon_ofs_region + icon_width + style->get_margin(SIDE_RIGHT)), style->get_margin(SIDE_TOP) + (_size.height - icon_height) / 2), Size2(icon_width, icon_height)); - } else { - icon_region = Rect2(style->get_offset() + Point2(icon_ofs_region, (_size.height - icon_height) / 2), Size2(icon_width, icon_height)); - } + icon_size = Size2(icon_width, icon_height); + } + + if (icon_align_rtl_checked == ALIGN_LEFT) { + icon_region = Rect2(style_offset + Point2(icon_ofs_region, Math::floor((valign - icon_size.y) * 0.5)), icon_size); + } else if (icon_align_rtl_checked == ALIGN_CENTER) { + icon_region = Rect2(style_offset + Point2(icon_ofs_region + Math::floor((size.x - icon_size.x) * 0.5), Math::floor((valign - icon_size.y) * 0.5)), icon_size); } else { - if (rtl) { - icon_region = Rect2(Point2(size.width - (icon_ofs_region + _icon->get_size().width + style->get_margin(SIDE_RIGHT)), style->get_margin(SIDE_TOP) + Math::floor((valign - _icon->get_height()) / 2.0)), _icon->get_size()); - } else { - icon_region = Rect2(style->get_offset() + Point2(icon_ofs_region, Math::floor((valign - _icon->get_height()) / 2.0)), _icon->get_size()); - } + icon_region = Rect2(style_offset + Point2(icon_ofs_region + size.x - icon_size.x, Math::floor((valign - icon_size.y) * 0.5)), icon_size); + } + + if (icon_region.size.width > 0) { + draw_texture_rect_region(_icon, icon_region, Rect2(Point2(), _icon->get_size()), color_icon); } } Point2 icon_ofs = !_icon.is_null() ? Point2(icon_region.size.width + get_theme_constant("hseparation"), 0) : Point2(); + if (align_rtl_checked == ALIGN_CENTER && icon_align_rtl_checked == ALIGN_CENTER) { + icon_ofs.x = 0.0; + } int text_clip = size.width - style->get_minimum_size().width - icon_ofs.width; text_buf->set_width(clip_text ? text_clip : -1); @@ -262,20 +294,15 @@ void Button::_notification(int p_what) { Point2 text_ofs = (size - style->get_minimum_size() - icon_ofs - text_buf->get_size() - Point2(_internal_margin[SIDE_RIGHT] - _internal_margin[SIDE_LEFT], 0)) / 2.0; - switch (align) { + switch (align_rtl_checked) { case ALIGN_LEFT: { - if (rtl) { - if (_internal_margin[SIDE_RIGHT] > 0) { - text_ofs.x = size.x - style->get_margin(SIDE_RIGHT) - text_width - _internal_margin[SIDE_RIGHT] - get_theme_constant("hseparation"); - } else { - text_ofs.x = size.x - style->get_margin(SIDE_RIGHT) - text_width; - } + if (icon_align_rtl_checked != ALIGN_LEFT) { + icon_ofs.x = 0.0; + } + if (_internal_margin[SIDE_LEFT] > 0) { + text_ofs.x = style->get_margin(SIDE_LEFT) + icon_ofs.x + _internal_margin[SIDE_LEFT] + get_theme_constant("hseparation"); } else { - if (_internal_margin[SIDE_LEFT] > 0) { - text_ofs.x = style->get_margin(SIDE_LEFT) + icon_ofs.x + _internal_margin[SIDE_LEFT] + get_theme_constant("hseparation"); - } else { - text_ofs.x = style->get_margin(SIDE_LEFT) + icon_ofs.x; - } + text_ofs.x = style->get_margin(SIDE_LEFT) + icon_ofs.x; } text_ofs.y += style->get_offset().y; } break; @@ -283,31 +310,24 @@ void Button::_notification(int p_what) { if (text_ofs.x < 0) { text_ofs.x = 0; } - text_ofs += icon_ofs; + if (icon_align_rtl_checked == ALIGN_LEFT) { + text_ofs += icon_ofs; + } text_ofs += style->get_offset(); } break; case ALIGN_RIGHT: { - if (rtl) { - if (_internal_margin[SIDE_LEFT] > 0) { - text_ofs.x = style->get_margin(SIDE_LEFT) + icon_ofs.x + _internal_margin[SIDE_LEFT] + get_theme_constant("hseparation"); - } else { - text_ofs.x = style->get_margin(SIDE_LEFT) + icon_ofs.x; - } + if (_internal_margin[SIDE_RIGHT] > 0) { + text_ofs.x = size.x - style->get_margin(SIDE_RIGHT) - text_width - _internal_margin[SIDE_RIGHT] - get_theme_constant("hseparation"); } else { - if (_internal_margin[SIDE_RIGHT] > 0) { - text_ofs.x = size.x - style->get_margin(SIDE_RIGHT) - text_width - _internal_margin[SIDE_RIGHT] - get_theme_constant("hseparation"); - } else { - text_ofs.x = size.x - style->get_margin(SIDE_RIGHT) - text_width; - } + text_ofs.x = size.x - style->get_margin(SIDE_RIGHT) - text_width; } text_ofs.y += style->get_offset().y; + if (icon_align_rtl_checked == ALIGN_RIGHT) { + text_ofs.x -= icon_ofs.x; + } } break; } - if (rtl) { - text_ofs.x -= icon_ofs.x; - } - Color font_outline_color = get_theme_color("font_outline_color"); int outline_size = get_theme_constant("outline_size"); if (outline_size > 0 && font_outline_color.a > 0) { @@ -315,10 +335,6 @@ void Button::_notification(int p_what) { } text_buf->draw(ci, text_ofs, color); - - if (!_icon.is_null() && icon_region.size.width > 0) { - draw_texture_rect_region(_icon, icon_region, Rect2(Point2(), _icon->get_size()), color_icon); - } } break; } } @@ -457,6 +473,16 @@ Button::TextAlign Button::get_text_align() const { return align; } +void Button::set_icon_align(TextAlign p_align) { + icon_align = p_align; + minimum_size_changed(); + update(); +} + +Button::TextAlign Button::get_icon_align() const { + return icon_align; +} + bool Button::_set(const StringName &p_name, const Variant &p_value) { String str = p_name; if (str.begins_with("opentype_features/")) { @@ -519,14 +545,16 @@ void Button::_bind_methods() { ClassDB::bind_method(D_METHOD("get_language"), &Button::get_language); ClassDB::bind_method(D_METHOD("set_button_icon", "texture"), &Button::set_icon); ClassDB::bind_method(D_METHOD("get_button_icon"), &Button::get_icon); - ClassDB::bind_method(D_METHOD("set_expand_icon"), &Button::set_expand_icon); - ClassDB::bind_method(D_METHOD("is_expand_icon"), &Button::is_expand_icon); ClassDB::bind_method(D_METHOD("set_flat", "enabled"), &Button::set_flat); + ClassDB::bind_method(D_METHOD("is_flat"), &Button::is_flat); ClassDB::bind_method(D_METHOD("set_clip_text", "enabled"), &Button::set_clip_text); ClassDB::bind_method(D_METHOD("get_clip_text"), &Button::get_clip_text); ClassDB::bind_method(D_METHOD("set_text_align", "align"), &Button::set_text_align); ClassDB::bind_method(D_METHOD("get_text_align"), &Button::get_text_align); - ClassDB::bind_method(D_METHOD("is_flat"), &Button::is_flat); + ClassDB::bind_method(D_METHOD("set_icon_align", "icon_align"), &Button::set_icon_align); + ClassDB::bind_method(D_METHOD("get_icon_align"), &Button::get_icon_align); + ClassDB::bind_method(D_METHOD("set_expand_icon"), &Button::set_expand_icon); + ClassDB::bind_method(D_METHOD("is_expand_icon"), &Button::is_expand_icon); BIND_ENUM_CONSTANT(ALIGN_LEFT); BIND_ENUM_CONSTANT(ALIGN_CENTER); @@ -539,11 +567,12 @@ void Button::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "flat"), "set_flat", "is_flat"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "clip_text"), "set_clip_text", "get_clip_text"); ADD_PROPERTY(PropertyInfo(Variant::INT, "align", PROPERTY_HINT_ENUM, "Left,Center,Right"), "set_text_align", "get_text_align"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "icon_align", PROPERTY_HINT_ENUM, "Left,Center,Right"), "set_icon_align", "get_icon_align"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "expand_icon"), "set_expand_icon", "is_expand_icon"); } Button::Button(const String &p_text) { - text_buf.instance(); + text_buf.instantiate(); text_buf->set_flags(TextServer::BREAK_MANDATORY); set_mouse_filter(MOUSE_FILTER_STOP); diff --git a/scene/gui/button.h b/scene/gui/button.h index d968f63f51..253d079680 100644 --- a/scene/gui/button.h +++ b/scene/gui/button.h @@ -58,6 +58,7 @@ private: bool expand_icon = false; bool clip_text = false; TextAlign align = ALIGN_CENTER; + TextAlign icon_align = ALIGN_LEFT; float _internal_margin[4] = {}; void _shape(); @@ -102,6 +103,9 @@ public: void set_text_align(TextAlign p_align); TextAlign get_text_align() const; + void set_icon_align(TextAlign p_align); + TextAlign get_icon_align() const; + Button(const String &p_text = String()); ~Button(); }; diff --git a/scene/gui/code_edit.cpp b/scene/gui/code_edit.cpp index 5b720945b8..ba1534ed5c 100644 --- a/scene/gui/code_edit.cpp +++ b/scene/gui/code_edit.cpp @@ -122,7 +122,7 @@ void CodeEdit::_notification(int p_what) { ERR_CONTINUE(l < 0 || l >= code_completion_options_count); Ref<TextLine> tl; - tl.instance(); + tl.instantiate(); tl->add_string(code_completion_options[l].display, cache.font, cache.font_size); int yofs = (row_height - tl->get_size().y) / 2; @@ -248,6 +248,8 @@ void CodeEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { } update(); } break; + default: + break; } return; } @@ -358,7 +360,7 @@ void CodeEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { return; } if (k->is_action("ui_text_backspace", true)) { - backspace_at_cursor(); + backspace(); _filter_code_completion_candidates(); accept_event(); return; @@ -385,14 +387,34 @@ void CodeEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { set_code_hint(""); } - /* Override input to unfold lines where needed. */ - if (!is_readonly()) { - if (k->is_action("ui_text_newline_above", true) || k->is_action("ui_text_newline_blank", true) || k->is_action("ui_text_newline", true)) { - unfold_line(cursor_get_line()); - } - if (cursor_get_line() > 0 && k->is_action("ui_text_backspace", true)) { - unfold_line(cursor_get_line() - 1); - } + /* Indentation */ + if (k->is_action("ui_text_indent", true)) { + do_indent(); + accept_event(); + return; + } + + if (k->is_action("ui_text_dedent", true)) { + do_unindent(); + accept_event(); + return; + } + + // Override new line actions, for auto indent + if (k->is_action("ui_text_newline_above", true)) { + _new_line(false, true); + accept_event(); + return; + } + if (k->is_action("ui_text_newline_blank", true)) { + _new_line(false); + accept_event(); + return; + } + if (k->is_action("ui_text_newline", true)) { + _new_line(); + accept_event(); + return; } /* Remove shift otherwise actions will not match. */ @@ -437,6 +459,443 @@ Control::CursorShape CodeEdit::get_cursor_shape(const Point2 &p_pos) const { return TextEdit::get_cursor_shape(p_pos); } +/* Indent management */ +void CodeEdit::set_indent_size(const int p_size) { + ERR_FAIL_COND_MSG(p_size <= 0, "Indend size must be greater than 0."); + if (indent_size == p_size) { + return; + } + + indent_size = p_size; + if (indent_using_spaces) { + indent_text = String(" ").repeat(p_size); + } else { + indent_text = "\t"; + } + set_tab_size(p_size); +} + +int CodeEdit::get_indent_size() const { + return indent_size; +} + +void CodeEdit::set_indent_using_spaces(const bool p_use_spaces) { + indent_using_spaces = p_use_spaces; + if (indent_using_spaces) { + indent_text = String(" ").repeat(indent_size); + } else { + indent_text = "\t"; + } +} + +bool CodeEdit::is_indent_using_spaces() const { + return indent_using_spaces; +} + +void CodeEdit::set_auto_indent_enabled(bool p_enabled) { + auto_indent = p_enabled; +} + +bool CodeEdit::is_auto_indent_enabled() const { + return auto_indent; +} + +void CodeEdit::set_auto_indent_prefixes(const TypedArray<String> &p_prefixes) { + auto_indent_prefixes.clear(); + for (int i = 0; i < p_prefixes.size(); i++) { + const String prefix = p_prefixes[i]; + auto_indent_prefixes.insert(prefix[0]); + } +} + +TypedArray<String> CodeEdit::get_auto_indent_prefixes() const { + TypedArray<String> prefixes; + for (const Set<char32_t>::Element *E = auto_indent_prefixes.front(); E; E = E->next()) { + prefixes.push_back(String::chr(E->get())); + } + return prefixes; +} + +void CodeEdit::do_indent() { + if (is_readonly()) { + return; + } + + if (is_selection_active()) { + indent_lines(); + return; + } + + if (!indent_using_spaces) { + _insert_text_at_cursor("\t"); + return; + } + + int spaces_to_add = _calculate_spaces_till_next_right_indent(cursor_get_column()); + if (spaces_to_add > 0) { + _insert_text_at_cursor(String(" ").repeat(spaces_to_add)); + } +} + +void CodeEdit::indent_lines() { + if (is_readonly()) { + return; + } + + begin_complex_operation(); + + /* This value informs us by how much we changed selection position by indenting right. */ + /* Default is 1 for tab indentation. */ + int selection_offset = 1; + + int start_line = cursor_get_line(); + int end_line = start_line; + if (is_selection_active()) { + start_line = get_selection_from_line(); + end_line = get_selection_to_line(); + + /* Ignore the last line if the selection is not past the first column. */ + if (get_selection_to_column() == 0) { + selection_offset = 0; + end_line--; + } + } + + for (int i = start_line; i <= end_line; i++) { + const String line_text = get_line(i); + if (line_text.size() == 0 && is_selection_active()) { + continue; + } + + if (!indent_using_spaces) { + set_line(i, '\t' + line_text); + continue; + } + + /* We don't really care where selection is - we just need to know indentation level at the beginning of the line. */ + /* Since we will add this many spaces, we want to move the whole selection and caret by this much. */ + int spaces_to_add = _calculate_spaces_till_next_right_indent(get_first_non_whitespace_column(i)); + set_line(i, String(" ").repeat(spaces_to_add) + line_text); + selection_offset = spaces_to_add; + } + + /* Fix selection and caret being off after shifting selection right.*/ + if (is_selection_active()) { + select(start_line, get_selection_from_column() + selection_offset, get_selection_to_line(), get_selection_to_column() + selection_offset); + } + cursor_set_column(cursor_get_column() + selection_offset, false); + + end_complex_operation(); +} + +void CodeEdit::do_unindent() { + if (is_readonly()) { + return; + } + + int cc = cursor_get_column(); + + if (is_selection_active() || cc <= 0) { + unindent_lines(); + return; + } + + int cl = cursor_get_line(); + const String &line = get_line(cl); + + if (line[cc - 1] == '\t') { + _remove_text(cl, cc - 1, cl, cc); + cursor_set_column(MAX(0, cc - 1)); + return; + } + + if (line[cc - 1] != ' ') { + return; + } + + int spaces_to_remove = _calculate_spaces_till_next_left_indent(cc); + if (spaces_to_remove > 0) { + for (int i = 1; i <= spaces_to_remove; i++) { + if (line[cc - i] != ' ') { + spaces_to_remove = i - 1; + break; + } + } + _remove_text(cl, cc - spaces_to_remove, cl, cc); + cursor_set_column(MAX(0, cc - spaces_to_remove)); + } +} + +void CodeEdit::unindent_lines() { + if (is_readonly()) { + return; + } + + begin_complex_operation(); + + /* Moving caret and selection after unindenting can get tricky because */ + /* changing content of line can move caret and selection on its own (if new line ends before previous position of either), */ + /* therefore we just remember initial values and at the end of the operation offset them by number of removed characters. */ + int removed_characters = 0; + int initial_selection_end_column = 0; + int initial_cursor_column = cursor_get_column(); + + int start_line = cursor_get_line(); + int end_line = start_line; + if (is_selection_active()) { + start_line = get_selection_from_line(); + end_line = get_selection_to_line(); + + /* Ignore the last line if the selection is not past the first column. */ + initial_selection_end_column = get_selection_to_column(); + if (initial_selection_end_column == 0) { + end_line--; + } + } + + bool first_line_edited = false; + bool last_line_edited = false; + + for (int i = start_line; i <= end_line; i++) { + String line_text = get_line(i); + + if (line_text.begins_with("\t")) { + line_text = line_text.substr(1, line_text.length()); + + set_line(i, line_text); + removed_characters = 1; + + first_line_edited = (i == start_line) ? true : first_line_edited; + last_line_edited = (i == end_line) ? true : last_line_edited; + continue; + } + + if (line_text.begins_with(" ")) { + /* When unindenting we aim to remove spaces before line that has selection no matter what is selected, */ + /* Here we remove only enough spaces to align text to nearest full multiple of indentation_size. */ + /* In case where selection begins at the start of indentation_size multiple we remove whole indentation level. */ + int spaces_to_remove = _calculate_spaces_till_next_left_indent(get_first_non_whitespace_column(i)); + line_text = line_text.substr(spaces_to_remove, line_text.length()); + + set_line(i, line_text); + removed_characters = spaces_to_remove; + + first_line_edited = (i == start_line) ? true : first_line_edited; + last_line_edited = (i == end_line) ? true : last_line_edited; + } + } + + if (is_selection_active()) { + /* Fix selection being off by one on the first line. */ + if (first_line_edited) { + select(get_selection_from_line(), get_selection_from_column() - removed_characters, get_selection_to_line(), initial_selection_end_column); + } + + /* Fix selection being off by one on the last line. */ + if (last_line_edited) { + select(get_selection_from_line(), get_selection_from_column(), get_selection_to_line(), initial_selection_end_column - removed_characters); + } + } + cursor_set_column(initial_cursor_column - removed_characters, false); + + end_complex_operation(); +} + +int CodeEdit::_calculate_spaces_till_next_left_indent(int p_column) const { + int spaces_till_indent = p_column % indent_size; + if (spaces_till_indent == 0) { + spaces_till_indent = indent_size; + } + return spaces_till_indent; +} + +int CodeEdit::_calculate_spaces_till_next_right_indent(int p_column) const { + return indent_size - p_column % indent_size; +} + +/* TODO: remove once brace completion is refactored. */ +static char32_t _get_right_pair_symbol(char32_t c) { + if (c == '"') { + return '"'; + } + if (c == '\'') { + return '\''; + } + if (c == '(') { + return ')'; + } + if (c == '[') { + return ']'; + } + if (c == '{') { + return '}'; + } + return 0; +} + +static bool _is_pair_left_symbol(char32_t c) { + return c == '"' || + c == '\'' || + c == '(' || + c == '[' || + c == '{'; +} + +void CodeEdit::_new_line(bool p_split_current_line, bool p_above) { + if (is_readonly()) { + return; + } + + const int cc = cursor_get_column(); + const int cl = cursor_get_line(); + const String line = get_line(cl); + + String ins = "\n"; + + /* Append current indentation. */ + int space_count = 0; + int line_col = 0; + for (; line_col < cc; line_col++) { + if (line[line_col] == '\t') { + ins += indent_text; + space_count = 0; + continue; + } + + if (line[line_col] == ' ') { + space_count++; + + if (space_count == indent_size) { + ins += indent_text; + space_count = 0; + } + continue; + } + break; + } + + if (is_line_folded(cl)) { + unfold_line(cl); + } + + /* Indent once again if the previous line needs it, ie ':'. */ + /* Then add an addition new line for any closing pairs aka '()'. */ + /* Skip this in comments or if we are going above. */ + bool brace_indent = false; + if (auto_indent && !p_above && cc > 0 && is_in_comment(cl) == -1) { + bool should_indent = false; + char32_t indent_char = ' '; + + for (; line_col < cc; line_col++) { + char32_t c = line[line_col]; + if (auto_indent_prefixes.has(c)) { + should_indent = true; + indent_char = c; + continue; + } + + /* Make sure this is the last char, trailing whitespace or comments are okay. */ + if (should_indent && (!_is_whitespace(c) && is_in_comment(cl, cc) == -1)) { + should_indent = false; + } + } + + if (should_indent) { + ins += indent_text; + + /* TODO: Change when brace completion is refactored. */ + char32_t closing_char = _get_right_pair_symbol(indent_char); + if (closing_char != 0 && closing_char == line[cc]) { + /* No need to move the brace below if we are not taking the text with us. */ + if (p_split_current_line) { + brace_indent = true; + ins += "\n" + ins.substr(1, ins.length() - 2); + } else { + brace_indent = false; + ins = "\n" + ins.substr(1, ins.length() - 2); + } + } + } + } + + begin_complex_operation(); + + bool first_line = false; + if (!p_split_current_line) { + if (p_above) { + if (cl > 0) { + cursor_set_line(cl - 1, false); + cursor_set_column(get_line(cursor_get_line()).length()); + } else { + cursor_set_column(0); + first_line = true; + } + } else { + cursor_set_column(line.length()); + } + } + + insert_text_at_cursor(ins); + + if (first_line) { + cursor_set_line(0); + } else if (brace_indent) { + cursor_set_line(cursor_get_line() - 1, false); + cursor_set_column(get_line(cursor_get_line()).length()); + } + + end_complex_operation(); +} + +void CodeEdit::backspace() { + if (is_readonly()) { + return; + } + + int cc = cursor_get_column(); + int cl = cursor_get_line(); + + if (cc == 0 && cl == 0) { + return; + } + + if (is_selection_active()) { + delete_selection(); + return; + } + + if (cl > 0 && is_line_hidden(cl - 1)) { + unfold_line(cursor_get_line() - 1); + } + + int prev_line = cc ? cl : cl - 1; + int prev_column = cc ? (cc - 1) : (get_line(cl - 1).length()); + + merge_gutters(cl, prev_line); + + /* TODO: Change when brace completion is refactored. */ + if (auto_brace_completion_enabled && cc > 0 && _is_pair_left_symbol(get_line(cl)[cc - 1])) { + _consume_backspace_for_pair_symbol(prev_line, prev_column); + cursor_set_line(prev_line, false, true); + cursor_set_column(prev_column); + return; + } + + /* For space indentation we need to do a simple unindent if there are no chars to the left, acting in the */ + /* same way as tabs. */ + if (indent_using_spaces && cc != 0) { + if (get_first_non_whitespace_column(cl) > cc) { + prev_column = cc - _calculate_spaces_till_next_left_indent(cc); + prev_line = cl; + } + } + + _remove_text(prev_line, prev_column, cl, cc); + + cursor_set_line(prev_line, false, true); + cursor_set_column(prev_column); +} + /* Main Gutter */ void CodeEdit::_update_draw_main_gutter() { set_gutter_draw(main_gutter, draw_breakpoints || draw_bookmarks || draw_executing_lines); @@ -615,7 +1074,7 @@ bool CodeEdit::is_line_numbers_zero_padded() const { void CodeEdit::_line_number_draw_callback(int p_line, int p_gutter, const Rect2 &p_region) { String fc = TS->format_number(String::num(p_line + 1).lpad(line_number_digits, line_number_padding)); Ref<TextLine> tl; - tl.instance(); + tl.instantiate(); tl->add_string(fc, cache.font, cache.font_size); int yofs = p_region.position.y + (get_row_height() - tl->get_size().y) / 2; Color number_color = get_line_gutter_item_color(p_line, line_number_gutter); @@ -1284,6 +1743,25 @@ void CodeEdit::cancel_code_completion() { } void CodeEdit::_bind_methods() { + /* Indent management */ + ClassDB::bind_method(D_METHOD("set_indent_size", "size"), &CodeEdit::set_indent_size); + ClassDB::bind_method(D_METHOD("get_indent_size"), &CodeEdit::get_indent_size); + + ClassDB::bind_method(D_METHOD("set_indent_using_spaces", "use_spaces"), &CodeEdit::set_indent_using_spaces); + ClassDB::bind_method(D_METHOD("is_indent_using_spaces"), &CodeEdit::is_indent_using_spaces); + + ClassDB::bind_method(D_METHOD("set_auto_indent_enabled", "enable"), &CodeEdit::set_auto_indent_enabled); + ClassDB::bind_method(D_METHOD("is_auto_indent_enabled"), &CodeEdit::is_auto_indent_enabled); + + ClassDB::bind_method(D_METHOD("set_auto_indent_prefixes", "prefixes"), &CodeEdit::set_auto_indent_prefixes); + ClassDB::bind_method(D_METHOD("get_auto_indent_prefixes"), &CodeEdit::get_auto_indent_prefixes); + + ClassDB::bind_method(D_METHOD("do_indent"), &CodeEdit::do_indent); + ClassDB::bind_method(D_METHOD("do_unindent"), &CodeEdit::do_unindent); + + ClassDB::bind_method(D_METHOD("indent_lines"), &CodeEdit::indent_lines); + ClassDB::bind_method(D_METHOD("unindent_lines"), &CodeEdit::unindent_lines); + /* Main Gutter */ ClassDB::bind_method(D_METHOD("_main_gutter_draw_callback"), &CodeEdit::_main_gutter_draw_callback); @@ -1434,6 +1912,12 @@ void CodeEdit::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "code_completion_enabled"), "set_code_completion_enabled", "is_code_completion_enabled"); ADD_PROPERTY(PropertyInfo(Variant::PACKED_STRING_ARRAY, "code_completion_prefixes"), "set_code_completion_prefixes", "get_code_comletion_prefixes"); + ADD_GROUP("Indentation", "indent_"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "indent_size"), "set_indent_size", "get_indent_size"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "indent_use_spaces"), "set_indent_using_spaces", "is_indent_using_spaces"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "indent_automatic"), "set_auto_indent_enabled", "is_auto_indent_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::PACKED_STRING_ARRAY, "indent_automatic_prefixes"), "set_auto_indent_prefixes", "get_auto_indent_prefixes"); + /* Signals */ ADD_SIGNAL(MethodInfo("breakpoint_toggled", PropertyInfo(Variant::INT, "line"))); ADD_SIGNAL(MethodInfo("request_code_completion")); @@ -2060,6 +2544,12 @@ void CodeEdit::_lines_edited_from(int p_from_line, int p_to_line) { } CodeEdit::CodeEdit() { + /* Indent management */ + auto_indent_prefixes.insert(':'); + auto_indent_prefixes.insert('{'); + auto_indent_prefixes.insert('['); + auto_indent_prefixes.insert('('); + /* Text Direction */ set_layout_direction(LAYOUT_DIRECTION_LTR); set_text_direction(TEXT_DIRECTION_LTR); diff --git a/scene/gui/code_edit.h b/scene/gui/code_edit.h index 52b3f52a03..25b518402b 100644 --- a/scene/gui/code_edit.h +++ b/scene/gui/code_edit.h @@ -53,6 +53,19 @@ public: }; private: + /* Indent management */ + int indent_size = 4; + String indent_text = "\t"; + + bool auto_indent = false; + Set<char32_t> auto_indent_prefixes; + + bool indent_using_spaces = false; + int _calculate_spaces_till_next_left_indent(int p_column) const; + int _calculate_spaces_till_next_right_indent(int p_column) const; + + void _new_line(bool p_split_current_line = true, bool p_above = false); + /* Main Gutter */ enum MainGutterType { MAIN_GUTTER_BREAKPOINT = 0x01, @@ -206,6 +219,27 @@ protected: public: virtual CursorShape get_cursor_shape(const Point2 &p_pos = Point2i()) const override; + /* Indent management */ + void set_indent_size(const int p_size); + int get_indent_size() const; + + void set_indent_using_spaces(const bool p_use_spaces); + bool is_indent_using_spaces() const; + + void set_auto_indent_enabled(bool p_enabled); + bool is_auto_indent_enabled() const; + + void set_auto_indent_prefixes(const TypedArray<String> &p_prefixes); + TypedArray<String> get_auto_indent_prefixes() const; + + void do_indent(); + void do_unindent(); + + void indent_lines(); + void unindent_lines(); + + virtual void backspace() override; + /* Main Gutter */ void set_draw_breakpoints_gutter(bool p_draw); bool is_drawing_breakpoints_gutter() const; diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index f394b9e3a5..659d14ae70 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -40,6 +40,8 @@ #endif #include "scene/main/window.h" +List<Color> ColorPicker::preset_cache; + void ColorPicker::_notification(int p_what) { switch (p_what) { case NOTIFICATION_THEME_CHANGED: { @@ -57,11 +59,17 @@ void ColorPicker::_notification(int p_what) { #ifdef TOOLS_ENABLED if (Engine::get_singleton()->is_editor_hint()) { - PackedColorArray saved_presets = EditorSettings::get_singleton()->get_project_metadata("color_picker", "presets", PackedColorArray()); + if (preset_cache.is_empty()) { + PackedColorArray saved_presets = EditorSettings::get_singleton()->get_project_metadata("color_picker", "presets", PackedColorArray()); + for (int i = 0; i < saved_presets.size(); i++) { + preset_cache.push_back(saved_presets[i]); + } + } - for (int i = 0; i < saved_presets.size(); i++) { - add_preset(saved_presets[i]); + for (int i = 0; i < preset_cache.size(); i++) { + presets.push_back(preset_cache[i]); } + preset->update(); } #endif } break; @@ -88,7 +96,7 @@ Ref<Shader> ColorPicker::wheel_shader; Ref<Shader> ColorPicker::circle_shader; void ColorPicker::init_shaders() { - wheel_shader.instance(); + wheel_shader.instantiate(); wheel_shader->set_code( "shader_type canvas_item;" "void fragment() {" @@ -107,7 +115,7 @@ void ColorPicker::init_shaders() { " COLOR = vec4(clamp((abs(fract(((a - TAU) / TAU) + vec3(3.0, 2.0, 1.0) / 3.0) * 6.0 - 3.0) - 1.0), 0.0, 1.0), (b + b2 + b3 + b4) / 4.00);" "}"); - circle_shader.instance(); + circle_shader.instantiate(); circle_shader->set_code( "shader_type canvas_item;" "uniform float v = 1.0;" @@ -413,6 +421,7 @@ void ColorPicker::add_preset(const Color &p_color) { presets.move_to_back(presets.find(p_color)); } else { presets.push_back(p_color); + preset_cache.push_back(p_color); } preset->update(); @@ -427,6 +436,7 @@ void ColorPicker::add_preset(const Color &p_color) { void ColorPicker::erase_preset(const Color &p_color) { if (presets.find(p_color)) { presets.erase(presets.find(p_color)); + preset_cache.erase(preset_cache.find(p_color)); preset->update(); #ifdef TOOLS_ENABLED @@ -1213,9 +1223,9 @@ ColorPicker::ColorPicker() : wheel_edit->set_custom_minimum_size(Size2(get_theme_constant("sv_width"), get_theme_constant("sv_height"))); hb_edit->add_child(wheel_edit); - wheel_mat.instance(); + wheel_mat.instantiate(); wheel_mat->set_shader(wheel_shader); - circle_mat.instance(); + circle_mat.instantiate(); circle_mat->set_shader(circle_shader); MarginContainer *wheel_margin(memnew(MarginContainer)); diff --git a/scene/gui/color_picker.h b/scene/gui/color_picker.h index 3bd2ff9375..60da3957aa 100644 --- a/scene/gui/color_picker.h +++ b/scene/gui/color_picker.h @@ -58,6 +58,7 @@ public: private: static Ref<Shader> wheel_shader; static Ref<Shader> circle_shader; + static List<Color> preset_cache; Control *screen = nullptr; Control *uv_edit = memnew(Control); diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 64a3f1ca77..d42b505f7b 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -650,27 +650,11 @@ void Control::_notification(int p_notification) { } } -bool Control::clips_input() const { - if (get_script_instance()) { - return get_script_instance()->call(SceneStringNames::get_singleton()->_clips_input); - } - return false; -} - bool Control::has_point(const Point2 &p_point) const { - if (get_script_instance()) { - Variant v = p_point; - const Variant *p = &v; - Callable::CallError ce; - Variant ret = get_script_instance()->call(SceneStringNames::get_singleton()->_has_point, &p, 1, ce); - if (ce.error == Callable::CallError::CALL_OK) { - return ret; - } + bool ret; + if (GDVIRTUAL_CALL(_has_point, p_point, ret)) { + return ret; } - /*if (has_stylebox("mask")) { - Ref<StyleBox> mask = get_stylebox("mask"); - return mask->test_mask(p_point,Rect2(Point2(),get_size())); - }*/ return Rect2(Point2(), get_size()).has_point(p_point); } @@ -1084,7 +1068,7 @@ Rect2 Control::get_parent_anchorable_rect() const { } else { #ifdef TOOLS_ENABLED Node *edited_root = get_tree()->get_edited_scene_root(); - if (edited_root && (this == edited_root || edited_root->is_a_parent_of(this))) { + if (edited_root && (this == edited_root || edited_root->is_ancestor_of(this))) { parent_rect.size = Size2(ProjectSettings::get_singleton()->get("display/window/size/width"), ProjectSettings::get_singleton()->get("display/window/size/height")); } else { parent_rect = get_viewport()->get_visible_rect(); @@ -1504,7 +1488,7 @@ Point2 Control::get_global_position() const { Point2 Control::get_screen_position() const { ERR_FAIL_COND_V(!is_inside_tree(), Point2()); - Point2 global_pos = get_global_position(); + Point2 global_pos = get_viewport()->get_canvas_transform().xform(get_global_position()); Window *w = Object::cast_to<Window>(get_viewport()); if (w && !w->is_embedding_subwindows()) { global_pos += w->get_position(); @@ -2473,14 +2457,6 @@ real_t Control::get_rotation() const { return data.rotation; } -void Control::set_rotation_degrees(real_t p_degrees) { - set_rotation(Math::deg2rad(p_degrees)); -} - -real_t Control::get_rotation_degrees() const { - return Math::rad2deg(get_rotation()); -} - void Control::_override_changed() { notification(NOTIFICATION_THEME_CHANGED); emit_signal(SceneStringNames::get_singleton()->theme_changed); @@ -2648,7 +2624,6 @@ void Control::_bind_methods() { ClassDB::bind_method(D_METHOD("set_global_position", "position", "keep_offsets"), &Control::set_global_position, DEFVAL(false)); ClassDB::bind_method(D_METHOD("_set_global_position", "position"), &Control::_set_global_position); ClassDB::bind_method(D_METHOD("set_rotation", "radians"), &Control::set_rotation); - ClassDB::bind_method(D_METHOD("set_rotation_degrees", "degrees"), &Control::set_rotation_degrees); ClassDB::bind_method(D_METHOD("set_scale", "scale"), &Control::set_scale); ClassDB::bind_method(D_METHOD("set_pivot_offset", "pivot_offset"), &Control::set_pivot_offset); ClassDB::bind_method(D_METHOD("get_offset", "offset"), &Control::get_offset); @@ -2657,7 +2632,6 @@ void Control::_bind_methods() { ClassDB::bind_method(D_METHOD("get_position"), &Control::get_position); ClassDB::bind_method(D_METHOD("get_size"), &Control::get_size); ClassDB::bind_method(D_METHOD("get_rotation"), &Control::get_rotation); - ClassDB::bind_method(D_METHOD("get_rotation_degrees"), &Control::get_rotation_degrees); ClassDB::bind_method(D_METHOD("get_scale"), &Control::get_scale); ClassDB::bind_method(D_METHOD("get_pivot_offset"), &Control::get_pivot_offset); ClassDB::bind_method(D_METHOD("get_custom_minimum_size"), &Control::get_custom_minimum_size); @@ -2784,7 +2758,6 @@ void Control::_bind_methods() { BIND_VMETHOD(MethodInfo( PropertyInfo(Variant::OBJECT, "control", PROPERTY_HINT_RESOURCE_TYPE, "Control"), "_make_custom_tooltip", PropertyInfo(Variant::STRING, "for_text"))); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_clips_input")); ADD_GROUP("Anchor", "anchor_"); ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "anchor_left", PROPERTY_HINT_RANGE, "0,1,0.001,or_lesser,or_greater"), "_set_anchor", "get_anchor", SIDE_LEFT); @@ -2810,8 +2783,7 @@ void Control::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "rect_global_position", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "_set_global_position", "get_global_position"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "rect_size", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "_set_size", "get_size"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "rect_min_size"), "set_custom_minimum_size", "get_custom_minimum_size"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "rect_rotation", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_rotation", "get_rotation"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "rect_rotation_degrees", PROPERTY_HINT_RANGE, "-360,360,0.1,or_lesser,or_greater"), "set_rotation_degrees", "get_rotation_degrees"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "rect_rotation", PROPERTY_HINT_RANGE, "-360,360,0.1,or_lesser,or_greater,radians"), "set_rotation", "get_rotation"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "rect_scale"), "set_scale", "get_scale"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "rect_pivot_offset"), "set_pivot_offset", "get_pivot_offset"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "rect_clip_content"), "set_clip_contents", "is_clipping_contents"); @@ -2940,5 +2912,5 @@ void Control::_bind_methods() { ADD_SIGNAL(MethodInfo("minimum_size_changed")); ADD_SIGNAL(MethodInfo("theme_changed")); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_has_point", PropertyInfo(Variant::VECTOR2, "point"))); + GDVIRTUAL_BIND(_has_point); } diff --git a/scene/gui/control.h b/scene/gui/control.h index a05025c32d..0642686a9f 100644 --- a/scene/gui/control.h +++ b/scene/gui/control.h @@ -32,6 +32,7 @@ #define CONTROL_H #include "core/math/transform_2d.h" +#include "core/object/gdvirtual.gen.inc" #include "core/templates/rid.h" #include "scene/gui/shortcut.h" #include "scene/main/canvas_item.h" @@ -264,6 +265,7 @@ private: static bool has_theme_item_in_types(Control *p_theme_owner, Window *p_theme_owner_window, Theme::DataType p_data_type, const StringName &p_name, List<StringName> p_theme_types); _FORCE_INLINE_ void _get_theme_type_dependencies(const StringName &p_theme_type, List<StringName> *p_list) const; + GDVIRTUAL1RC(bool, _has_point, Vector2) protected: virtual void add_child_notify(Node *p_child) override; virtual void remove_child_notify(Node *p_child) override; @@ -329,7 +331,6 @@ public: virtual Size2 get_minimum_size() const; virtual Size2 get_combined_minimum_size() const; virtual bool has_point(const Point2 &p_point) const; - virtual bool clips_input() const; virtual void set_drag_forwarding(Control *p_target); virtual Variant get_drag_data(const Point2 &p_point); virtual bool can_drop_data(const Point2 &p_point, const Variant &p_data) const; @@ -384,9 +385,7 @@ public: void set_rect(const Rect2 &p_rect); // Reset anchors to begin and set rect, for faster container children sorting. void set_rotation(real_t p_radians); - void set_rotation_degrees(real_t p_degrees); real_t get_rotation() const; - real_t get_rotation_degrees() const; void set_h_grow_direction(GrowDirection p_direction); GrowDirection get_h_grow_direction() const; diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp index f63ae7569f..dceab00607 100644 --- a/scene/gui/dialogs.cpp +++ b/scene/gui/dialogs.cpp @@ -263,6 +263,28 @@ Button *AcceptDialog::add_cancel_button(const String &p_cancel) { return b; } +void AcceptDialog::remove_button(Control *p_button) { + Button *button = Object::cast_to<Button>(p_button); + ERR_FAIL_NULL(button); + ERR_FAIL_COND_MSG(button->get_parent() != hbc, vformat("Cannot remove button %s as it does not belong to this dialog.", button->get_name())); + ERR_FAIL_COND_MSG(button == ok, "Cannot remove dialog's OK button."); + + Node *right_spacer = hbc->get_child(button->get_index() + 1); + // Should always be valid but let's avoid crashing + if (right_spacer) { + hbc->remove_child(right_spacer); + memdelete(right_spacer); + } + hbc->remove_child(button); + + if (button->is_connected("pressed", callable_mp(this, &AcceptDialog::_custom_action))) { + button->disconnect("pressed", callable_mp(this, &AcceptDialog::_custom_action)); + } + if (button->is_connected("pressed", callable_mp(this, &AcceptDialog::_cancel_pressed))) { + button->disconnect("pressed", callable_mp(this, &AcceptDialog::_cancel_pressed)); + } +} + void AcceptDialog::_bind_methods() { ClassDB::bind_method(D_METHOD("get_ok_button"), &AcceptDialog::get_ok_button); ClassDB::bind_method(D_METHOD("get_label"), &AcceptDialog::get_label); @@ -270,6 +292,7 @@ void AcceptDialog::_bind_methods() { ClassDB::bind_method(D_METHOD("get_hide_on_ok"), &AcceptDialog::get_hide_on_ok); ClassDB::bind_method(D_METHOD("add_button", "text", "right", "action"), &AcceptDialog::add_button, DEFVAL(false), DEFVAL("")); ClassDB::bind_method(D_METHOD("add_cancel_button", "name"), &AcceptDialog::add_cancel_button); + ClassDB::bind_method(D_METHOD("remove_button", "button"), &AcceptDialog::remove_button); ClassDB::bind_method(D_METHOD("register_text_enter", "line_edit"), &AcceptDialog::register_text_enter); ClassDB::bind_method(D_METHOD("set_text", "text"), &AcceptDialog::set_text); ClassDB::bind_method(D_METHOD("get_text"), &AcceptDialog::get_text); diff --git a/scene/gui/dialogs.h b/scene/gui/dialogs.h index d389806fff..8e803a2a7c 100644 --- a/scene/gui/dialogs.h +++ b/scene/gui/dialogs.h @@ -82,6 +82,7 @@ public: Button *get_ok_button() { return ok; } Button *add_button(const String &p_text, bool p_right = false, const String &p_action = ""); Button *add_cancel_button(const String &p_cancel = ""); + void remove_button(Control *p_button); void set_hide_on_ok(bool p_hide); bool get_hide_on_ok() const; diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index 5ef89e38f0..39aa6749e7 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -239,10 +239,6 @@ void GraphEdit::disconnect_node(const StringName &p_from, int p_from_port, const } } -bool GraphEdit::clips_input() const { - return true; -} - void GraphEdit::get_connection_list(List<Connection> *r_connections) const { *r_connections = connections; } diff --git a/scene/gui/graph_edit.h b/scene/gui/graph_edit.h index e8300f901c..5251de1722 100644 --- a/scene/gui/graph_edit.h +++ b/scene/gui/graph_edit.h @@ -235,7 +235,6 @@ protected: virtual void add_child_notify(Node *p_child) override; virtual void remove_child_notify(Node *p_child) override; void _notification(int p_what); - virtual bool clips_input() const override; public: Error connect_node(const StringName &p_from, int p_from_port, const StringName &p_to, int p_to_port); diff --git a/scene/gui/graph_node.cpp b/scene/gui/graph_node.cpp index 77c502cf8d..836bffdf46 100644 --- a/scene/gui/graph_node.cpp +++ b/scene/gui/graph_node.cpp @@ -757,7 +757,7 @@ void GraphNode::_connpos_update() { continue; } - Size2i size = c->get_combined_minimum_size(); + Size2i size = c->get_rect().size; int y = sb->get_margin(SIDE_TOP) + vofs; int h = size.y; @@ -1021,6 +1021,6 @@ void GraphNode::_bind_methods() { } GraphNode::GraphNode() { - title_buf.instance(); + title_buf.instantiate(); set_mouse_filter(MOUSE_FILTER_STOP); } diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp index 150980b2e9..b0d54bf8c9 100644 --- a/scene/gui/item_list.cpp +++ b/scene/gui/item_list.cpp @@ -57,7 +57,7 @@ int ItemList::add_item(const String &p_item, const Ref<Texture2D> &p_texture, bo item.icon_region = Rect2i(); item.icon_modulate = Color(1, 1, 1, 1); item.text = p_item; - item.text_buf.instance(); + item.text_buf.instantiate(); item.selectable = p_selectable; item.selected = false; item.disabled = false; @@ -80,7 +80,7 @@ int ItemList::add_icon_item(const Ref<Texture2D> &p_item, bool p_selectable) { item.icon_region = Rect2i(); item.icon_modulate = Color(1, 1, 1, 1); //item.text=p_item; - item.text_buf.instance(); + item.text_buf.instantiate(); item.selectable = p_selectable; item.selected = false; item.disabled = false; diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp index 0ce0130ad5..6580d794d1 100644 --- a/scene/gui/label.cpp +++ b/scene/gui/label.cpp @@ -453,6 +453,7 @@ void Label::set_text(const String &p_string) { visible_chars = get_total_character_count() * percent_visible; } update(); + minimum_size_changed(); } void Label::set_text_direction(Control::TextDirection p_text_direction) { diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index 089893e63b..f2d0d9bb22 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -1470,19 +1470,23 @@ int LineEdit::get_scroll_offset() const { } void LineEdit::insert_text_at_caret(String p_text) { - if ((max_length <= 0) || (text.length() + p_text.length() <= max_length)) { - String pre = text.substr(0, caret_column); - String post = text.substr(caret_column, text.length() - caret_column); - text = pre + p_text + post; - _shape(); - TextServer::Direction dir = TS->shaped_text_get_dominant_direciton_in_range(text_rid, caret_column, caret_column + p_text.length()); - if (dir != TextServer::DIRECTION_AUTO) { - input_direction = (TextDirection)dir; + if (max_length > 0) { + // Truncate text to append to fit in max_length, if needed. + int available_chars = max_length - text.length(); + if (p_text.length() > available_chars) { + emit_signal("text_change_rejected", p_text.substr(available_chars)); + p_text = p_text.substr(0, available_chars); } - set_caret_column(caret_column + p_text.length()); - } else { - emit_signal("text_change_rejected"); } + String pre = text.substr(0, caret_column); + String post = text.substr(caret_column, text.length() - caret_column); + text = pre + p_text + post; + _shape(); + TextServer::Direction dir = TS->shaped_text_get_dominant_direciton_in_range(text_rid, caret_column, caret_column + p_text.length()); + if (dir != TextServer::DIRECTION_AUTO) { + input_direction = (TextDirection)dir; + } + set_caret_column(caret_column + p_text.length()); } void LineEdit::clear_internal() { @@ -2158,7 +2162,7 @@ void LineEdit::_bind_methods() { ClassDB::bind_method(D_METHOD("get_right_icon"), &LineEdit::get_right_icon); ADD_SIGNAL(MethodInfo("text_changed", PropertyInfo(Variant::STRING, "new_text"))); - ADD_SIGNAL(MethodInfo("text_change_rejected")); + ADD_SIGNAL(MethodInfo("text_change_rejected", PropertyInfo(Variant::STRING, "rejected_substring"))); ADD_SIGNAL(MethodInfo("text_submitted", PropertyInfo(Variant::STRING, "new_text"))); BIND_ENUM_CONSTANT(ALIGN_LEFT); @@ -2198,7 +2202,7 @@ void LineEdit::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::STRING, "text"), "set_text", "get_text"); ADD_PROPERTY(PropertyInfo(Variant::INT, "align", PROPERTY_HINT_ENUM, "Left,Center,Right,Fill"), "set_align", "get_align"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "max_length"), "set_max_length", "get_max_length"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "max_length", PROPERTY_HINT_RANGE, "0,1000,1,or_greater"), "set_max_length", "get_max_length"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editable"), "set_editable", "is_editable"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "secret"), "set_secret", "is_secret"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "secret_character"), "set_secret_character", "get_secret_character"); @@ -2221,7 +2225,7 @@ void LineEdit::_bind_methods() { ADD_GROUP("Caret", "caret_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret_blink"), "set_caret_blink_enabled", "is_caret_blink_enabled"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "caret_blink_speed", PROPERTY_HINT_RANGE, "0.1,10,0.01"), "set_caret_blink_speed", "get_caret_blink_speed"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "caret_column"), "set_caret_column", "get_caret_column"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "caret_column", PROPERTY_HINT_RANGE, "0,1000,1,or_greater"), "set_caret_column", "get_caret_column"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret_force_displayed"), "set_caret_force_displayed", "is_caret_force_displayed"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret_mid_grapheme"), "set_caret_mid_grapheme_enabled", "is_caret_mid_grapheme_enabled"); } diff --git a/scene/gui/link_button.cpp b/scene/gui/link_button.cpp index d45ffde715..ee0618a991 100644 --- a/scene/gui/link_button.cpp +++ b/scene/gui/link_button.cpp @@ -301,7 +301,7 @@ void LinkButton::_bind_methods() { } LinkButton::LinkButton() { - text_buf.instance(); + text_buf.instantiate(); set_focus_mode(FOCUS_NONE); set_default_cursor_shape(CURSOR_POINTING_HAND); } diff --git a/scene/gui/popup_menu.h b/scene/gui/popup_menu.h index e4cbe984c9..74718395d3 100644 --- a/scene/gui/popup_menu.h +++ b/scene/gui/popup_menu.h @@ -80,8 +80,8 @@ class PopupMenu : public Popup { } Item() { - text_buf.instance(); - accel_text_buf.instance(); + text_buf.instantiate(); + accel_text_buf.instantiate(); checkable_type = CHECKABLE_TYPE_NONE; } }; diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 987d05bf71..f32ad2144a 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -934,6 +934,11 @@ int RichTextLabel::_draw_line(ItemFrame *p_frame, int p_line, const Vector2 &p_o } } + Vector2 fbg_line_off = off + p_ofs; + // Draw background color box + Vector2i chr_range = TS->shaped_text_get_range(rid); + _draw_fbg_boxes(ci, rid, fbg_line_off, it_from, it_to, chr_range.x, chr_range.y, 0); + // Draw main text. Color selection_fg = get_theme_color("font_selected_color"); Color selection_bg = get_theme_color("selection_color"); @@ -1079,6 +1084,9 @@ int RichTextLabel::_draw_line(ItemFrame *p_frame, int p_line, const Vector2 &p_o off.x += glyphs[i].advance; } } + // Draw foreground color box + _draw_fbg_boxes(ci, rid, fbg_line_off, it_from, it_to, chr_range.x, chr_range.y, 1); + off.y += TS->shaped_text_get_descent(rid) + l.text_buf->get_spacing_bottom(); } @@ -2036,6 +2044,36 @@ bool RichTextLabel::_find_meta(Item *p_item, Variant *r_meta, ItemMeta **r_item) return false; } +Color RichTextLabel::_find_bgcolor(Item *p_item) { + Item *item = p_item; + + while (item) { + if (item->type == ITEM_BGCOLOR) { + ItemBGColor *color = static_cast<ItemBGColor *>(item); + return color->color; + } + + item = item->parent; + } + + return Color(0, 0, 0, 0); +} + +Color RichTextLabel::_find_fgcolor(Item *p_item) { + Item *item = p_item; + + while (item) { + if (item->type == ITEM_FGCOLOR) { + ItemFGColor *color = static_cast<ItemFGColor *>(item); + return color->color; + } + + item = item->parent; + } + + return Color(0, 0, 0, 0); +} + bool RichTextLabel::_find_layout_subitem(Item *from, Item *to) { if (from && from != to) { if (from->type != ITEM_FONT && from->type != ITEM_COLOR && from->type != ITEM_UNDERLINE && from->type != ITEM_STRIKETHROUGH) { @@ -2546,6 +2584,22 @@ void RichTextLabel::push_rainbow(float p_saturation, float p_value, float p_freq _add_item(item, true); } +void RichTextLabel::push_bgcolor(const Color &p_color) { + ERR_FAIL_COND(current->type == ITEM_TABLE); + ItemBGColor *item = memnew(ItemBGColor); + + item->color = p_color; + _add_item(item, true); +} + +void RichTextLabel::push_fgcolor(const Color &p_color) { + ERR_FAIL_COND(current->type == ITEM_TABLE); + ItemFGColor *item = memnew(ItemFGColor); + + item->color = p_color; + _add_item(item, true); +} + void RichTextLabel::push_customfx(Ref<RichTextEffect> p_custom_effect, Dictionary p_environment) { ItemCustomFX *item = memnew(ItemCustomFX); item->custom_effect = p_custom_effect; @@ -3352,6 +3406,23 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) { pos = brk_end + 1; tag_stack.push_front("rainbow"); set_process_internal(true); + + } else if (tag.begins_with("bgcolor=")) { + String color_str = tag.substr(8, tag.length()); + Color color = Color::from_string(color_str, base_color); + + push_bgcolor(color); + pos = brk_end + 1; + tag_stack.push_front("bgcolor"); + + } else if (tag.begins_with("fgcolor=")) { + String color_str = tag.substr(8, tag.length()); + Color color = Color::from_string(color_str, base_color); + + push_fgcolor(color); + pos = brk_end + 1; + tag_stack.push_front("fgcolor"); + } else { Vector<String> &expr = split_tag_block; if (expr.size() < 1) { @@ -3918,6 +3989,8 @@ void RichTextLabel::_bind_methods() { ClassDB::bind_method(D_METHOD("set_cell_size_override", "min_size", "max_size"), &RichTextLabel::set_cell_size_override); ClassDB::bind_method(D_METHOD("set_cell_padding", "padding"), &RichTextLabel::set_cell_padding); ClassDB::bind_method(D_METHOD("push_cell"), &RichTextLabel::push_cell); + ClassDB::bind_method(D_METHOD("push_fgcolor", "fgcolor"), &RichTextLabel::push_fgcolor); + ClassDB::bind_method(D_METHOD("push_bgcolor", "bgcolor"), &RichTextLabel::push_bgcolor); ClassDB::bind_method(D_METHOD("pop"), &RichTextLabel::pop); ClassDB::bind_method(D_METHOD("clear"), &RichTextLabel::clear); @@ -4012,7 +4085,7 @@ void RichTextLabel::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "selection_enabled"), "set_selection_enabled", "is_selection_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "override_selected_font_color"), "set_override_selected_font_color", "is_overriding_selected_font_color"); - ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "custom_effects", PROPERTY_HINT_ARRAY_TYPE, "RichTextEffect", (PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE)), "set_effects", "get_effects"); + ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "custom_effects", PROPERTY_HINT_ARRAY_TYPE, vformat("%s/%s:%s", Variant::OBJECT, PROPERTY_HINT_RESOURCE_TYPE, "RichTextEffect"), (PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE)), "set_effects", "get_effects"); ADD_PROPERTY(PropertyInfo(Variant::INT, "text_direction", PROPERTY_HINT_ENUM, "Auto,Left-to-Right,Right-to-Left,Inherited"), "set_text_direction", "get_text_direction"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "language"), "set_language", "get_language"); @@ -4056,6 +4129,8 @@ void RichTextLabel::_bind_methods() { BIND_ENUM_CONSTANT(ITEM_WAVE); BIND_ENUM_CONSTANT(ITEM_TORNADO); BIND_ENUM_CONSTANT(ITEM_RAINBOW); + BIND_ENUM_CONSTANT(ITEM_BGCOLOR); + BIND_ENUM_CONSTANT(ITEM_FGCOLOR); BIND_ENUM_CONSTANT(ITEM_META); BIND_ENUM_CONSTANT(ITEM_DROPCAP); BIND_ENUM_CONSTANT(ITEM_CUSTOMFX); @@ -4108,6 +4183,65 @@ Size2 RichTextLabel::get_minimum_size() const { return size; } +void RichTextLabel::_draw_fbg_boxes(RID p_ci, RID p_rid, Vector2 line_off, Item *it_from, Item *it_to, int start, int end, int fbg_flag) { + Vector2i fbg_index = Vector2i(end, start); + Color last_color = Color(0, 0, 0, 0); + bool draw_box = false; + // Draw a box based on color tags associated with glyphs + for (int i = start; i < end; i++) { + Item *it = _get_item_at_pos(it_from, it_to, i); + Color color = Color(0, 0, 0, 0); + + if (fbg_flag == 0) { + color = _find_bgcolor(it); + } else { + color = _find_fgcolor(it); + } + + bool change_to_color = ((color.a > 0) && ((last_color.a - 0.0) < 0.01)); + bool change_from_color = (((color.a - 0.0) < 0.01) && (last_color.a > 0.0)); + bool change_color = (((color.a > 0) == (last_color.a > 0)) && (color != last_color)); + + if (change_to_color) { + fbg_index.x = MIN(i, fbg_index.x); + fbg_index.y = MAX(i, fbg_index.y); + } + + if (change_from_color || change_color) { + fbg_index.x = MIN(i, fbg_index.x); + fbg_index.y = MAX(i, fbg_index.y); + draw_box = true; + } + + if (draw_box) { + Vector<Vector2> sel = TS->shaped_text_get_selection(p_rid, fbg_index.x, fbg_index.y); + for (int j = 0; j < sel.size(); j++) { + Vector2 rect_off = line_off + Vector2(sel[j].x, -TS->shaped_text_get_ascent(p_rid)); + Vector2 rect_size = Vector2(sel[j].y - sel[j].x, TS->shaped_text_get_size(p_rid).y); + RenderingServer::get_singleton()->canvas_item_add_rect(p_ci, Rect2(rect_off, rect_size), last_color); + } + fbg_index = Vector2i(end, start); + draw_box = false; + } + + if (change_color) { + fbg_index.x = MIN(i, fbg_index.x); + fbg_index.y = MAX(i, fbg_index.y); + } + + last_color = color; + } + + if (last_color.a > 0) { + Vector<Vector2> sel = TS->shaped_text_get_selection(p_rid, fbg_index.x, end); + for (int i = 0; i < sel.size(); i++) { + Vector2 rect_off = line_off + Vector2(sel[i].x, -TS->shaped_text_get_ascent(p_rid)); + Vector2 rect_size = Vector2(sel[i].y - sel[i].x, TS->shaped_text_get_size(p_rid).y); + RenderingServer::get_singleton()->canvas_item_add_rect(p_ci, Rect2(rect_off, rect_size), last_color); + } + } +} + Ref<RichTextEffect> RichTextLabel::_get_custom_effect_by_code(String p_bbcode_identifier) { for (int i = 0; i < custom_effects.size(); i++) { if (!custom_effects[i].is_valid()) { diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h index 9cf94b0cd7..999d8b05fd 100644 --- a/scene/gui/rich_text_label.h +++ b/scene/gui/rich_text_label.h @@ -75,6 +75,8 @@ public: ITEM_WAVE, ITEM_TORNADO, ITEM_RAINBOW, + ITEM_BGCOLOR, + ITEM_FGCOLOR, ITEM_META, ITEM_DROPCAP, ITEM_CUSTOMFX @@ -100,7 +102,7 @@ private: int char_offset = 0; int char_count = 0; - Line() { text_buf.instance(); } + Line() { text_buf.instantiate(); } }; struct Item { @@ -307,13 +309,23 @@ private: ItemRainbow() { type = ITEM_RAINBOW; } }; + struct ItemBGColor : public Item { + Color color; + ItemBGColor() { type = ITEM_BGCOLOR; } + }; + + struct ItemFGColor : public Item { + Color color; + ItemFGColor() { type = ITEM_FGCOLOR; } + }; + struct ItemCustomFX : public ItemFX { Ref<CharFXTransform> char_fx_transform; Ref<RichTextEffect> custom_effect; ItemCustomFX() { type = ITEM_CUSTOMFX; - char_fx_transform.instance(); + char_fx_transform.instantiate(); } virtual ~ItemCustomFX() { @@ -422,6 +434,8 @@ private: bool _find_underline(Item *p_item); bool _find_strikethrough(Item *p_item); bool _find_meta(Item *p_item, Variant *r_meta, ItemMeta **r_item = nullptr); + Color _find_bgcolor(Item *p_item); + Color _find_fgcolor(Item *p_item); bool _find_layout_subitem(Item *from, Item *to); void _fetch_item_fx_stack(Item *p_item, Vector<ItemFX *> &r_stack); @@ -437,6 +451,8 @@ private: Ref<RichTextEffect> _get_custom_effect_by_code(String p_bbcode_identifier); virtual Dictionary parse_expressions_for_values(Vector<String> p_expressions); + void _draw_fbg_boxes(RID p_ci, RID p_rid, Vector2 line_off, Item *it_from, Item *it_to, int start, int end, int fbg_flag); + bool use_bbcode = false; String bbcode; @@ -474,6 +490,8 @@ public: void push_wave(float p_frequency, float p_amplitude); void push_tornado(float p_frequency, float p_radius); void push_rainbow(float p_saturation, float p_value, float p_frequency); + void push_bgcolor(const Color &p_color); + void push_fgcolor(const Color &p_color); void push_customfx(Ref<RichTextEffect> p_custom_effect, Dictionary p_environment); void set_table_column_expand(int p_column, bool p_expand, int p_ratio = 1); void set_cell_row_background_color(const Color &p_odd_row_bg, const Color &p_even_row_bg); diff --git a/scene/gui/scroll_container.cpp b/scene/gui/scroll_container.cpp index 5f872644ab..177f146b6a 100644 --- a/scene/gui/scroll_container.cpp +++ b/scene/gui/scroll_container.cpp @@ -32,10 +32,6 @@ #include "core/os/os.h" #include "scene/main/window.h" -bool ScrollContainer::clips_input() const { - return true; -} - Size2 ScrollContainer::get_minimum_size() const { Ref<StyleBox> sb = get_theme_stylebox("bg"); Size2 min_size; @@ -239,13 +235,13 @@ void ScrollContainer::_update_scrollbar_position() { } void ScrollContainer::_gui_focus_changed(Control *p_control) { - if (follow_focus && is_a_parent_of(p_control)) { + if (follow_focus && is_ancestor_of(p_control)) { ensure_control_visible(p_control); } } void ScrollContainer::ensure_control_visible(Control *p_control) { - ERR_FAIL_COND_MSG(!is_a_parent_of(p_control), "Must be a parent of the control."); + ERR_FAIL_COND_MSG(!is_ancestor_of(p_control), "Must be an ancestor of the control."); Rect2 global_rect = get_global_rect(); Rect2 other_rect = p_control->get_global_rect(); diff --git a/scene/gui/scroll_container.h b/scene/gui/scroll_container.h index c77a0d62f5..4733fdabca 100644 --- a/scene/gui/scroll_container.h +++ b/scene/gui/scroll_container.h @@ -108,8 +108,6 @@ public: VScrollBar *get_v_scrollbar(); void ensure_control_visible(Control *p_control); - virtual bool clips_input() const override; - TypedArray<String> get_configuration_warnings() const override; ScrollContainer(); diff --git a/scene/gui/shortcut.cpp b/scene/gui/shortcut.cpp index cbbcf9e069..962c6dcc60 100644 --- a/scene/gui/shortcut.cpp +++ b/scene/gui/shortcut.cpp @@ -42,7 +42,7 @@ Ref<InputEvent> Shortcut::get_shortcut() const { } bool Shortcut::is_shortcut(const Ref<InputEvent> &p_event) const { - return shortcut.is_valid() && shortcut->shortcut_match(p_event); + return shortcut.is_valid() && shortcut->is_match(p_event, true); } String Shortcut::get_as_text() const { diff --git a/scene/gui/spin_box.cpp b/scene/gui/spin_box.cpp index 4ac73ae6b5..941dd30057 100644 --- a/scene/gui/spin_box.cpp +++ b/scene/gui/spin_box.cpp @@ -52,7 +52,7 @@ void SpinBox::_value_changed(double) { void SpinBox::_text_submitted(const String &p_string) { Ref<Expression> expr; - expr.instance(); + expr.instantiate(); String num = TS->parse_number(p_string); // Ignore the prefix and suffix in the expression @@ -140,6 +140,8 @@ void SpinBox::_gui_input(const Ref<InputEvent> &p_event) { accept_event(); } } break; + default: + break; } } diff --git a/scene/gui/split_container.cpp b/scene/gui/split_container.cpp index df4cf9a740..9796b32c6b 100644 --- a/scene/gui/split_container.cpp +++ b/scene/gui/split_container.cpp @@ -38,7 +38,7 @@ Control *SplitContainer::_getch(int p_idx) const { for (int i = 0; i < get_child_count(); i++) { Control *c = Object::cast_to<Control>(get_child(i)); - if (!c || !c->is_visible_in_tree()) { + if (!c || !c->is_visible()) { continue; } if (c->is_set_as_top_level()) { diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp index acf0641005..133966013b 100644 --- a/scene/gui/tab_container.cpp +++ b/scene/gui/tab_container.cpp @@ -586,7 +586,7 @@ void TabContainer::_refresh_texts() { Control *control = Object::cast_to<Control>(tabs[i]); String text = control->has_meta("_tab_name") ? String(tr(String(control->get_meta("_tab_name")))) : String(tr(control->get_name())); Ref<TextLine> name; - name.instance(); + name.instantiate(); name->set_direction(rtl ? TextServer::DIRECTION_RTL : TextServer::DIRECTION_LTR); name->add_string(text, font, font_size, Dictionary(), TranslationServer::get_singleton()->get_tool_locale()); text_buf.push_back(name); diff --git a/scene/gui/tabs.cpp b/scene/gui/tabs.cpp index 11096e7976..6f1cff9ec8 100644 --- a/scene/gui/tabs.cpp +++ b/scene/gui/tabs.cpp @@ -743,7 +743,7 @@ void Tabs::add_tab(const String &p_str, const Ref<Texture2D> &p_icon) { Tab t; t.text = p_str; t.xl_text = tr(p_str); - t.text_buf.instance(); + t.text_buf.instantiate(); t.text_buf->set_direction(is_layout_rtl() ? TextServer::DIRECTION_RTL : TextServer::DIRECTION_LTR); t.text_buf->add_string(t.xl_text, get_theme_font("font"), get_theme_font_size("font_size"), Dictionary(), TranslationServer::get_singleton()->get_tool_locale()); t.icon = p_icon; diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 6f78d586f1..6f96b530a6 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -102,14 +102,6 @@ static char32_t _get_right_pair_symbol(char32_t c) { return 0; } -static int _find_first_non_whitespace_column_of_line(const String &line) { - int left = 0; - while (left < line.length() && _is_whitespace(line[left])) { - left++; - } - return left; -} - /////////////////////////////////////////////////////////////////////////////// void TextEdit::Text::set_font(const Ref<Font> &p_font) { @@ -120,8 +112,12 @@ void TextEdit::Text::set_font_size(int p_font_size) { font_size = p_font_size; } -void TextEdit::Text::set_indent_size(int p_indent_size) { - indent_size = p_indent_size; +void TextEdit::Text::set_tab_size(int p_tab_size) { + tab_size = p_tab_size; +} + +int TextEdit::Text::get_tab_size() const { + return tab_size; } void TextEdit::Text::set_font_features(const Dictionary &p_features) { @@ -204,9 +200,9 @@ void TextEdit::Text::invalidate_cache(int p_line, int p_column, const String &p_ } // Apply tab align. - if (indent_size > 0) { + if (tab_size > 0) { Vector<float> tabs; - tabs.push_back(font->get_char_size(' ', 0, font_size).width * indent_size); + tabs.push_back(font->get_char_size(' ', 0, font_size).width * tab_size); text.write[p_line].data_buf->tab_align(tabs); } } @@ -214,9 +210,9 @@ void TextEdit::Text::invalidate_cache(int p_line, int p_column, const String &p_ void TextEdit::Text::invalidate_all_lines() { for (int i = 0; i < text.size(); i++) { text.write[i].data_buf->set_width(width); - if (indent_size > 0) { + if (tab_size > 0) { Vector<float> tabs; - tabs.push_back(font->get_char_size(' ', 0, font_size).width * indent_size); + tabs.push_back(font->get_char_size(' ', 0, font_size).width * tab_size); text.write[i].data_buf->tab_align(tabs); } } @@ -822,7 +818,7 @@ void TextEdit::_notification(int p_what) { if (draw_minimap) { int minimap_visible_lines = _get_minimap_visible_rows(); int minimap_line_height = (minimap_char_size.y + minimap_line_spacing); - int minimap_tab_size = minimap_char_size.x * indent_size; + int minimap_tab_size = minimap_char_size.x * text.get_tab_size(); // calculate viewport size and y offset int viewport_height = (draw_amount - 1) * minimap_line_height; @@ -1114,7 +1110,7 @@ void TextEdit::_notification(int p_what) { } Ref<TextLine> tl; - tl.instance(); + tl.instantiate(); tl->add_string(text, cache.font, cache.font_size); int yofs = ofs_y + (row_height - tl->get_size().y) / 2; @@ -1695,7 +1691,13 @@ void TextEdit::_consume_backspace_for_pair_symbol(int prev_line, int prev_column } } -void TextEdit::backspace_at_cursor() { +void TextEdit::backspace() { + ScriptInstance *si = get_script_instance(); + if (si && si->has_method("_backspace")) { + si->call("_backspace"); + return; + } + if (readonly) { return; } @@ -1704,34 +1706,15 @@ void TextEdit::backspace_at_cursor() { return; } + if (is_selection_active()) { + delete_selection(); + return; + } + int prev_line = cursor.column ? cursor.line : cursor.line - 1; int prev_column = cursor.column ? (cursor.column - 1) : (text[cursor.line - 1].length()); - if (cursor.line != prev_line) { - for (int i = 0; i < gutters.size(); i++) { - if (!gutters[i].overwritable) { - continue; - } - - if (text.get_line_gutter_text(cursor.line, i) != "") { - text.set_line_gutter_text(prev_line, i, text.get_line_gutter_text(cursor.line, i)); - text.set_line_gutter_item_color(prev_line, i, text.get_line_gutter_item_color(cursor.line, i)); - } - - if (text.get_line_gutter_icon(cursor.line, i).is_valid()) { - text.set_line_gutter_icon(prev_line, i, text.get_line_gutter_icon(cursor.line, i)); - text.set_line_gutter_item_color(prev_line, i, text.get_line_gutter_item_color(cursor.line, i)); - } - - if (text.get_line_gutter_metadata(cursor.line, i) != "") { - text.set_line_gutter_metadata(prev_line, i, text.get_line_gutter_metadata(cursor.line, i)); - } - - if (text.is_line_gutter_clickable(cursor.line, i)) { - text.set_line_gutter_clickable(prev_line, i, true); - } - } - } + merge_gutters(cursor.line, prev_line); if (is_line_hidden(cursor.line)) { set_line_as_hidden(prev_line, true); @@ -1742,168 +1725,13 @@ void TextEdit::backspace_at_cursor() { _is_pair_left_symbol(text[cursor.line][cursor.column - 1])) { _consume_backspace_for_pair_symbol(prev_line, prev_column); } else { - // Handle space indentation. - if (cursor.column != 0 && indent_using_spaces) { - // Check if there are no other chars before cursor, just indentation. - bool unindent = true; - int i = 0; - while (i < cursor.column && i < text[cursor.line].length()) { - if (!_is_whitespace(text[cursor.line][i])) { - unindent = false; - break; - } - i++; - } - - // Then we can remove all spaces as a single character. - if (unindent) { - // We want to remove spaces up to closest indent, or whole indent if cursor is pointing at it. - int spaces_to_delete = _calculate_spaces_till_next_left_indent(cursor.column); - prev_column = cursor.column - spaces_to_delete; - _remove_text(cursor.line, prev_column, cursor.line, cursor.column); - } else { - _remove_text(prev_line, prev_column, cursor.line, cursor.column); - } - } else { - _remove_text(prev_line, prev_column, cursor.line, cursor.column); - } + _remove_text(prev_line, prev_column, cursor.line, cursor.column); } cursor_set_line(prev_line, false, true); cursor_set_column(prev_column); } -void TextEdit::indent_selected_lines_right() { - int start_line; - int end_line; - - // This value informs us by how much we changed selection position by indenting right. - // Default is 1 for tab indentation. - int selection_offset = 1; - begin_complex_operation(); - - if (is_selection_active()) { - start_line = get_selection_from_line(); - end_line = get_selection_to_line(); - } else { - start_line = cursor.line; - end_line = start_line; - } - - // Ignore if the cursor is not past the first column. - if (is_selection_active() && get_selection_to_column() == 0) { - selection_offset = 0; - end_line--; - } - - for (int i = start_line; i <= end_line; i++) { - String line_text = get_line(i); - if (line_text.size() == 0 && is_selection_active()) { - continue; - } - if (indent_using_spaces) { - // We don't really care where selection is - we just need to know indentation level at the beginning of the line. - int left = _find_first_non_whitespace_column_of_line(line_text); - int spaces_to_add = _calculate_spaces_till_next_right_indent(left); - // Since we will add these many spaces, we want to move the whole selection and cursor by this much. - selection_offset = spaces_to_add; - for (int j = 0; j < spaces_to_add; j++) { - line_text = ' ' + line_text; - } - } else { - line_text = '\t' + line_text; - } - set_line(i, line_text); - } - - // Fix selection and cursor being off after shifting selection right. - if (is_selection_active()) { - select(selection.from_line, selection.from_column + selection_offset, selection.to_line, selection.to_column + selection_offset); - } - cursor_set_column(cursor.column + selection_offset, false); - end_complex_operation(); - update(); -} - -void TextEdit::indent_selected_lines_left() { - int start_line; - int end_line; - - // Moving cursor and selection after unindenting can get tricky because - // changing content of line can move cursor and selection on its own (if new line ends before previous position of either), - // therefore we just remember initial values and at the end of the operation offset them by number of removed characters. - int removed_characters = 0; - int initial_selection_end_column = selection.to_column; - int initial_cursor_column = cursor.column; - - begin_complex_operation(); - - if (is_selection_active()) { - start_line = get_selection_from_line(); - end_line = get_selection_to_line(); - } else { - start_line = cursor.line; - end_line = start_line; - } - - // Ignore if the cursor is not past the first column. - if (is_selection_active() && get_selection_to_column() == 0) { - end_line--; - } - String first_line_text = get_line(start_line); - String last_line_text = get_line(end_line); - - for (int i = start_line; i <= end_line; i++) { - String line_text = get_line(i); - - if (line_text.begins_with("\t")) { - line_text = line_text.substr(1, line_text.length()); - set_line(i, line_text); - removed_characters = 1; - } else if (line_text.begins_with(" ")) { - // When unindenting we aim to remove spaces before line that has selection no matter what is selected, - // so we start of by finding first non whitespace character of line - int left = _find_first_non_whitespace_column_of_line(line_text); - - // Here we remove only enough spaces to align text to nearest full multiple of indentation_size. - // In case where selection begins at the start of indentation_size multiple we remove whole indentation level. - int spaces_to_remove = _calculate_spaces_till_next_left_indent(left); - - line_text = line_text.substr(spaces_to_remove, line_text.length()); - set_line(i, line_text); - removed_characters = spaces_to_remove; - } - } - - if (is_selection_active()) { - // Fix selection being off by one on the first line. - if (first_line_text != get_line(start_line)) { - select(selection.from_line, selection.from_column - removed_characters, - selection.to_line, initial_selection_end_column); - } - // Fix selection being off by one on the last line. - if (last_line_text != get_line(end_line)) { - select(selection.from_line, selection.from_column, - selection.to_line, initial_selection_end_column - removed_characters); - } - } - cursor_set_column(initial_cursor_column - removed_characters, false); - end_complex_operation(); - update(); -} - -int TextEdit::_calculate_spaces_till_next_left_indent(int column) { - int spaces_till_indent = column % indent_size; - if (spaces_till_indent == 0) { - spaces_till_indent = indent_size; - } - return spaces_till_indent; -} - -int TextEdit::_calculate_spaces_till_next_right_indent(int column) { - return indent_size - column % indent_size; -} - void TextEdit::_swap_current_input_direction() { if (input_direction == TEXT_DIRECTION_LTR) { input_direction = TEXT_DIRECTION_RTL; @@ -1919,90 +1747,8 @@ void TextEdit::_new_line(bool p_split_current_line, bool p_above) { return; } - String ins = "\n"; - - // Keep indentation. - int space_count = 0; - for (int i = 0; i < cursor.column; i++) { - if (text[cursor.line][i] == '\t') { - if (indent_using_spaces) { - ins += space_indent; - } else { - ins += "\t"; - } - space_count = 0; - } else if (text[cursor.line][i] == ' ') { - space_count++; - - if (space_count == indent_size) { - if (indent_using_spaces) { - ins += space_indent; - } else { - ins += "\t"; - } - space_count = 0; - } - } else { - break; - } - } - - bool brace_indent = false; - - // No need to indent if we are going upwards. - if (auto_indent && !p_above) { - // Indent once again if previous line will end with ':','{','[','(' and the line is not a comment - // (i.e. colon/brace precedes current cursor position). - if (cursor.column > 0) { - bool indent_char_found = false; - bool should_indent = false; - char indent_char = ':'; - char c = text[cursor.line][cursor.column]; - - for (int i = 0; i < cursor.column; i++) { - c = text[cursor.line][i]; - switch (c) { - case ':': - case '{': - case '[': - case '(': - indent_char_found = true; - should_indent = true; - indent_char = c; - continue; - } - - if (indent_char_found && is_line_comment(cursor.line)) { - should_indent = true; - break; - } else if (indent_char_found && !_is_whitespace(c)) { - should_indent = false; - indent_char_found = false; - } - } - - if (!is_line_comment(cursor.line) && should_indent) { - if (indent_using_spaces) { - ins += space_indent; - } else { - ins += "\t"; - } - - // No need to move the brace below if we are not taking the text with us. - char32_t closing_char = _get_right_pair_symbol(indent_char); - if ((closing_char != 0) && (closing_char == text[cursor.line][cursor.column])) { - if (p_split_current_line) { - brace_indent = true; - ins += "\n" + ins.substr(1, ins.length() - 2); - } else { - brace_indent = false; - ins = "\n" + ins.substr(1, ins.length() - 2); - } - } - } - } - } begin_complex_operation(); + bool first_line = false; if (!p_split_current_line) { if (p_above) { @@ -2018,83 +1764,13 @@ void TextEdit::_new_line(bool p_split_current_line, bool p_above) { } } - insert_text_at_cursor(ins); + insert_text_at_cursor("\n"); if (first_line) { cursor_set_line(0); - } else if (brace_indent) { - cursor_set_line(cursor.line - 1, false); - cursor_set_column(text[cursor.line].length()); - } - end_complex_operation(); -} - -void TextEdit::_indent_right() { - if (readonly) { - return; } - if (is_selection_active()) { - indent_selected_lines_right(); - } else { - // Simple indent. - if (indent_using_spaces) { - // Insert only as much spaces as needed till next indentation level. - int spaces_to_add = _calculate_spaces_till_next_right_indent(cursor.column); - String indent_to_insert = String(); - for (int i = 0; i < spaces_to_add; i++) { - indent_to_insert = ' ' + indent_to_insert; - } - _insert_text_at_cursor(indent_to_insert); - } else { - _insert_text_at_cursor("\t"); - } - } -} - -void TextEdit::_indent_left() { - if (readonly) { - return; - } - - if (is_selection_active()) { - indent_selected_lines_left(); - } else { - // Simple unindent. - int cc = cursor.column; - const String &line = text[cursor.line]; - - int left = _find_first_non_whitespace_column_of_line(line); - cc = MIN(cc, left); - - while (cc < indent_size && cc < left && line[cc] == ' ') { - cc++; - } - - if (cc > 0 && cc <= text[cursor.line].length()) { - if (text[cursor.line][cc - 1] == '\t') { - // Tabs unindentation. - _remove_text(cursor.line, cc - 1, cursor.line, cc); - if (cursor.column >= left) { - cursor_set_column(MAX(0, cursor.column - 1)); - } - update(); - } else { - // Spaces unindentation. - int spaces_to_remove = _calculate_spaces_till_next_left_indent(cc); - if (spaces_to_remove > 0) { - _remove_text(cursor.line, cc - spaces_to_remove, cursor.line, cc); - if (cursor.column > left - spaces_to_remove) { // Inside text? - cursor_set_column(MAX(0, cursor.column - spaces_to_remove)); - } - update(); - } - } - } else if (cc == 0 && line.length() > 0 && line[0] == '\t') { - _remove_text(cursor.line, 0, cursor.line, 1); - update(); - } - } + end_complex_operation(); } void TextEdit::_move_cursor_left(bool p_select, bool p_move_by_word) { @@ -2331,20 +2007,24 @@ void TextEdit::_move_cursor_page_down(bool p_select) { } } -void TextEdit::_backspace(bool p_word, bool p_all_to_left) { +void TextEdit::_do_backspace(bool p_word, bool p_all_to_left) { if (readonly) { return; } - if (is_selection_active()) { - _delete_selection(); + if (is_selection_active() || (!p_all_to_left && !p_word)) { + backspace(); return; } + if (p_all_to_left) { int cursor_current_column = cursor.column; cursor.column = 0; _remove_text(cursor.line, 0, cursor.line, cursor_current_column); - } else if (p_word) { + return; + } + + if (p_word) { int line = cursor.line; int column = cursor.column; @@ -2360,8 +2040,7 @@ void TextEdit::_backspace(bool p_word, bool p_all_to_left) { cursor_set_line(line, false); cursor_set_column(column); - } else { - backspace_at_cursor(); + return; } } @@ -2371,7 +2050,7 @@ void TextEdit::_delete(bool p_word, bool p_all_to_right) { } if (is_selection_active()) { - _delete_selection(); + delete_selection(); return; } int curline_len = text[cursor.line].length(); @@ -2416,15 +2095,16 @@ void TextEdit::_delete(bool p_word, bool p_all_to_right) { update(); } -void TextEdit::_delete_selection() { - if (is_selection_active()) { - selection.active = false; - update(); - _remove_text(selection.from_line, selection.from_column, selection.to_line, selection.to_column); - cursor_set_line(selection.from_line, false, false); - cursor_set_column(selection.from_column); - update(); +void TextEdit::delete_selection() { + if (!is_selection_active()) { + return; } + + selection.active = false; + _remove_text(selection.from_line, selection.from_column, selection.to_line, selection.to_column); + cursor_set_line(selection.from_line, false, false); + cursor_set_column(selection.from_column); + update(); } void TextEdit::_move_cursor_document_start(bool p_select) { @@ -2459,7 +2139,7 @@ void TextEdit::_move_cursor_document_end(bool p_select) { void TextEdit::_handle_unicode_character(uint32_t unicode, bool p_had_selection) { if (p_had_selection) { - _delete_selection(); + delete_selection(); } // Remove the old character if in insert mode and no selection. @@ -2942,31 +2622,19 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { return; } - // INDENTATION. - if (k->is_action("ui_text_dedent", true)) { - _indent_left(); - accept_event(); - return; - } - if (k->is_action("ui_text_indent", true)) { - _indent_right(); - accept_event(); - return; - } - // BACKSPACE AND DELETE. if (k->is_action("ui_text_backspace_all_to_left", true)) { - _backspace(false, true); + _do_backspace(false, true); accept_event(); return; } if (k->is_action("ui_text_backspace_word", true)) { - _backspace(true); + _do_backspace(true); accept_event(); return; } if (k->is_action("ui_text_backspace", true)) { - _backspace(); + _do_backspace(); accept_event(); return; } @@ -4340,14 +4008,6 @@ bool TextEdit::is_wrap_enabled() const { return wrap_enabled; } -void TextEdit::set_max_chars(int p_max_chars) { - max_chars = p_max_chars; -} - -int TextEdit::get_max_chars() const { - return max_chars; -} - void TextEdit::_reset_caret_blink_timer() { if (caret_blink_enabled) { draw_caret = true; @@ -4540,6 +4200,39 @@ bool TextEdit::is_gutter_overwritable(int p_gutter) const { return gutters[p_gutter].overwritable; } +void TextEdit::merge_gutters(int p_from_line, int p_to_line) { + ERR_FAIL_INDEX(p_from_line, text.size()); + ERR_FAIL_INDEX(p_to_line, text.size()); + if (p_from_line == p_to_line) { + return; + } + + for (int i = 0; i < gutters.size(); i++) { + if (!gutters[i].overwritable) { + continue; + } + + if (text.get_line_gutter_text(p_from_line, i) != "") { + text.set_line_gutter_text(p_to_line, i, text.get_line_gutter_text(p_from_line, i)); + text.set_line_gutter_item_color(p_to_line, i, text.get_line_gutter_item_color(p_from_line, i)); + } + + if (text.get_line_gutter_icon(p_from_line, i).is_valid()) { + text.set_line_gutter_icon(p_to_line, i, text.get_line_gutter_icon(p_from_line, i)); + text.set_line_gutter_item_color(p_to_line, i, text.get_line_gutter_item_color(p_from_line, i)); + } + + if (text.get_line_gutter_metadata(p_from_line, i) != "") { + text.set_line_gutter_metadata(p_to_line, i, text.get_line_gutter_metadata(p_from_line, i)); + } + + if (text.is_line_gutter_clickable(p_from_line, i)) { + text.set_line_gutter_clickable(p_to_line, i, true); + } + } + update(); +} + void TextEdit::set_gutter_custom_draw(int p_gutter, Object *p_object, const StringName &p_callback) { ERR_FAIL_INDEX(p_gutter, gutters.size()); ERR_FAIL_NULL(p_object); @@ -4625,18 +4318,6 @@ Color TextEdit::get_line_background_color(int p_line) { return text.get_line_background_color(p_line); } -void TextEdit::add_keyword(const String &p_keyword) { - keywords.insert(p_keyword); -} - -void TextEdit::clear_keywords() { - keywords.clear(); -} - -void TextEdit::set_auto_indent(bool p_auto_indent) { - auto_indent = p_auto_indent; -} - void TextEdit::cut() { if (readonly) { return; @@ -4652,7 +4333,7 @@ void TextEdit::cut() { _remove_text(cursor.line, 0, cursor.line + 1, 0); } else { _remove_text(cursor.line, 0, cursor.line, text[cursor.line].length()); - backspace_at_cursor(); + backspace(); cursor_set_line(cursor.line + 1); } @@ -5199,7 +4880,6 @@ int TextEdit::get_last_unhidden_line() const { int TextEdit::get_indent_level(int p_line) const { ERR_FAIL_INDEX_V(p_line, text.size(), 0); - // Counts number of tabs and spaces before line starts. int tab_count = 0; int whitespace_count = 0; int line_length = text[p_line].size(); @@ -5212,28 +4892,17 @@ int TextEdit::get_indent_level(int p_line) const { break; } } - return tab_count * indent_size + whitespace_count; + return tab_count * text.get_tab_size() + whitespace_count; } -bool TextEdit::is_line_comment(int p_line) const { - // Checks to see if this line is the start of a comment. - ERR_FAIL_INDEX_V(p_line, text.size(), false); +int TextEdit::get_first_non_whitespace_column(int p_line) const { + ERR_FAIL_INDEX_V(p_line, text.size(), 0); - int line_length = text[p_line].size(); - for (int i = 0; i < line_length - 1; i++) { - if (_is_whitespace(text[p_line][i])) { - continue; - } - if (_is_symbol(text[p_line][i])) { - if (text[p_line][i] == '\\') { - i++; // Skip quoted anything. - continue; - } - return text[p_line][i] == '#' || (i + 1 < line_length && text[p_line][i] == '/' && text[p_line][i + 1] == '/'); - } - break; + int col = 0; + while (col < text[p_line].length() && _is_whitespace(text[p_line][col])) { + col++; } - return false; + return col; } int TextEdit::get_line_count() const { @@ -5409,32 +5078,18 @@ void TextEdit::_push_current_op() { } } -void TextEdit::set_indent_using_spaces(const bool p_use_spaces) { - indent_using_spaces = p_use_spaces; -} - -bool TextEdit::is_indent_using_spaces() const { - return indent_using_spaces; -} - -void TextEdit::set_indent_size(const int p_size) { - ERR_FAIL_COND_MSG(p_size <= 0, "Indend size must be greater than 0."); - if (indent_size != p_size) { - indent_size = p_size; - text.set_indent_size(p_size); - text.invalidate_all_lines(); - } - - space_indent = ""; - for (int i = 0; i < p_size; i++) { - space_indent += " "; +void TextEdit::set_tab_size(const int p_size) { + ERR_FAIL_COND_MSG(p_size <= 0, "Tab size must be greater than 0."); + if (p_size == text.get_tab_size()) { + return; } - + text.set_tab_size(p_size); + text.invalidate_all_lines(); update(); } -int TextEdit::get_indent_size() { - return indent_size; +int TextEdit::get_tab_size() const { + return text.get_tab_size(); } void TextEdit::set_draw_tabs(bool p_draw) { @@ -6027,6 +5682,11 @@ void TextEdit::_bind_methods() { ClassDB::bind_method(D_METHOD("set_language", "language"), &TextEdit::set_language); ClassDB::bind_method(D_METHOD("get_language"), &TextEdit::get_language); + ClassDB::bind_method(D_METHOD("get_first_non_whitespace_column", "line"), &TextEdit::get_first_non_whitespace_column); + ClassDB::bind_method(D_METHOD("get_indent_level", "line"), &TextEdit::get_indent_level); + ClassDB::bind_method(D_METHOD("set_tab_size", "size"), &TextEdit::set_tab_size); + ClassDB::bind_method(D_METHOD("get_tab_size"), &TextEdit::get_tab_size); + ClassDB::bind_method(D_METHOD("set_text", "text"), &TextEdit::set_text); ClassDB::bind_method(D_METHOD("insert_text_at_cursor", "text"), &TextEdit::insert_text_at_cursor); @@ -6081,6 +5741,10 @@ void TextEdit::_bind_methods() { ClassDB::bind_method(D_METHOD("set_selecting_enabled", "enable"), &TextEdit::set_selecting_enabled); ClassDB::bind_method(D_METHOD("is_selecting_enabled"), &TextEdit::is_selecting_enabled); + ClassDB::bind_method(D_METHOD("delete_selection"), &TextEdit::delete_selection); + ClassDB::bind_method(D_METHOD("backspace"), &TextEdit::backspace); + BIND_VMETHOD(MethodInfo("_backspace")); + ClassDB::bind_method(D_METHOD("cut"), &TextEdit::cut); ClassDB::bind_method(D_METHOD("copy"), &TextEdit::copy); ClassDB::bind_method(D_METHOD("paste"), &TextEdit::paste); @@ -6136,6 +5800,7 @@ void TextEdit::_bind_methods() { ClassDB::bind_method(D_METHOD("is_gutter_clickable", "gutter"), &TextEdit::is_gutter_clickable); ClassDB::bind_method(D_METHOD("set_gutter_overwritable", "gutter", "overwritable"), &TextEdit::set_gutter_overwritable); ClassDB::bind_method(D_METHOD("is_gutter_overwritable", "gutter"), &TextEdit::is_gutter_overwritable); + ClassDB::bind_method(D_METHOD("merge_gutters", "from_line", "to_line"), &TextEdit::merge_gutters); ClassDB::bind_method(D_METHOD("set_gutter_custom_draw", "column", "object", "callback"), &TextEdit::set_gutter_custom_draw); // Line gutters. @@ -6262,7 +5927,7 @@ TextEdit::TextEdit() { _update_caches(); set_default_cursor_shape(CURSOR_IBEAM); - text.set_indent_size(indent_size); + text.set_tab_size(text.get_tab_size()); text.clear(); h_scroll = memnew(HScrollBar); diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h index c04d758abb..dcd5c6d0f8 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -96,7 +96,7 @@ private: bool hidden = false; Line() { - data_buf.instance(); + data_buf.instantiate(); } }; @@ -112,11 +112,12 @@ private: int width = -1; - int indent_size = 4; + int tab_size = 4; int gutter_count = 0; public: - void set_indent_size(int p_indent_size); + void set_tab_size(int p_tab_size); + int get_tab_size() const; void set_font(const Ref<Font> &p_font); void set_font_size(int p_font_size); void set_font_features(const Dictionary &p_features); @@ -257,11 +258,7 @@ private: uint32_t version = 0; uint32_t saved_version = 0; - int max_chars = 0; bool readonly = true; // Initialise to opposite first, so we get past the early-out in set_readonly. - bool indent_using_spaces = false; - int indent_size = 4; - String space_indent = " "; Timer *caret_blink_timer; bool caret_blink_enabled = false; @@ -296,7 +293,6 @@ private: bool scroll_past_end_of_file_enabled = false; bool brace_matching_enabled = false; bool highlight_current_line = false; - bool auto_indent = false; String cut_copy_line; bool insert_mode = false; @@ -420,14 +416,9 @@ private: void _clear(); - int _calculate_spaces_till_next_left_indent(int column); - int _calculate_spaces_till_next_right_indent(int column); - // Methods used in shortcuts void _swap_current_input_direction(); void _new_line(bool p_split_current = true, bool p_above = false); - void _indent_right(); - void _indent_left(); void _move_cursor_left(bool p_select, bool p_move_by_word = false); void _move_cursor_right(bool p_select, bool p_move_by_word = false); void _move_cursor_up(bool p_select); @@ -436,9 +427,8 @@ private: void _move_cursor_to_line_end(bool p_select); void _move_cursor_page_up(bool p_select); void _move_cursor_page_down(bool p_select); - void _backspace(bool p_word = false, bool p_all_to_left = false); + void _do_backspace(bool p_word = false, bool p_all_to_left = false); void _delete(bool p_word = false, bool p_all_to_right = false); - void _delete_selection(); void _move_cursor_document_start(bool p_select); void _move_cursor_document_end(bool p_select); void _handle_unicode_character(uint32_t unicode, bool p_had_selection); @@ -522,6 +512,8 @@ public: void set_gutter_overwritable(int p_gutter, bool p_overwritable); bool is_gutter_overwritable(int p_gutter) const; + void merge_gutters(int p_from_line, int p_to_line); + void set_gutter_custom_draw(int p_gutter, Object *p_object, const StringName &p_callback); // Line gutters. @@ -635,12 +627,9 @@ public: bool has_ime_text() const; void set_line(int line, String new_text); int get_row_height() const; - void backspace_at_cursor(); - void indent_selected_lines_left(); - void indent_selected_lines_right(); int get_indent_level(int p_line) const; - bool is_line_comment(int p_line) const; + int get_first_non_whitespace_column(int p_line) const; inline void set_scroll_pass_end_of_file(bool p_enabled) { scroll_past_end_of_file_enabled = p_enabled; @@ -653,7 +642,6 @@ public: brace_matching_enabled = p_enabled; update(); } - void set_auto_indent(bool p_auto_indent); void center_viewport_to_cursor(); @@ -689,9 +677,6 @@ public: void set_readonly(bool p_readonly); bool is_readonly() const; - void set_max_chars(int p_max_chars); - int get_max_chars() const; - void set_wrap_enabled(bool p_wrap_enabled); bool is_wrap_enabled() const; bool line_wraps(int line) const; @@ -699,6 +684,9 @@ public: void clear(); + void delete_selection(); + + virtual void backspace(); void cut(); void copy(); void paste(); @@ -730,10 +718,8 @@ public: void redo(); void clear_undo_history(); - void set_indent_using_spaces(const bool p_use_spaces); - bool is_indent_using_spaces() const; - void set_indent_size(const int p_size); - int get_indent_size(); + void set_tab_size(const int p_size); + int get_tab_size() const; void set_draw_tabs(bool p_draw); bool is_drawing_tabs() const; void set_draw_spaces(bool p_draw); @@ -744,9 +730,6 @@ public: void set_insert_mode(bool p_enabled); bool is_insert_mode() const; - void add_keyword(const String &p_keyword); - void clear_keywords(); - double get_v_scroll() const; void set_v_scroll(double p_scroll); diff --git a/scene/gui/texture_progress_bar.cpp b/scene/gui/texture_progress_bar.cpp index 46ce9d5ca9..5e5dec3579 100644 --- a/scene/gui/texture_progress_bar.cpp +++ b/scene/gui/texture_progress_bar.cpp @@ -221,43 +221,87 @@ void TextureProgressBar::draw_nine_patch_stretched(const Ref<Texture2D> &p_textu double width_texture = 0.0; double first_section_size = 0.0; double last_section_size = 0.0; - switch (mode) { - case FILL_LEFT_TO_RIGHT: - case FILL_RIGHT_TO_LEFT: { + switch (p_mode) { + case FILL_LEFT_TO_RIGHT: { width_total = dst_rect.size.x; width_texture = texture_size.x; first_section_size = topleft.x; last_section_size = bottomright.x; } break; - case FILL_TOP_TO_BOTTOM: - case FILL_BOTTOM_TO_TOP: { + case FILL_RIGHT_TO_LEFT: { + width_total = dst_rect.size.x; + width_texture = texture_size.x; + // In contrast to `FILL_LEFT_TO_RIGHT`, `first_section_size` and `last_section_size` should switch value. + first_section_size = bottomright.x; + last_section_size = topleft.x; + } break; + case FILL_TOP_TO_BOTTOM: { width_total = dst_rect.size.y; width_texture = texture_size.y; first_section_size = topleft.y; last_section_size = bottomright.y; } break; + case FILL_BOTTOM_TO_TOP: { + width_total = dst_rect.size.y; + width_texture = texture_size.y; + // Similar to `FILL_RIGHT_TO_LEFT`. + first_section_size = bottomright.y; + last_section_size = topleft.y; + } break; case FILL_BILINEAR_LEFT_AND_RIGHT: { - // TODO: Implement + width_total = dst_rect.size.x; + width_texture = texture_size.x; + first_section_size = topleft.x; + last_section_size = bottomright.x; } break; case FILL_BILINEAR_TOP_AND_BOTTOM: { - // TODO: Implement + width_total = dst_rect.size.y; + width_texture = texture_size.y; + first_section_size = topleft.y; + last_section_size = bottomright.y; } break; case FILL_CLOCKWISE: case FILL_CLOCKWISE_AND_COUNTER_CLOCKWISE: case FILL_COUNTER_CLOCKWISE: { - // Those modes are circular, not relevant for nine patch + // Those modes are circular, not relevant for nine patch. } break; + case FILL_MODE_MAX: + break; } double width_filled = width_total * p_ratio; double middle_section_size = MAX(0.0, width_texture - first_section_size - last_section_size); - middle_section_size *= MIN(1.0, (MAX(0.0, width_filled - first_section_size) / MAX(1.0, width_total - first_section_size - last_section_size))); - last_section_size = MAX(0.0, last_section_size - (width_total - width_filled)); - first_section_size = MIN(first_section_size, width_filled); - width_texture = MIN(width_texture, first_section_size + middle_section_size + last_section_size); + // Maximum middle texture size. + double max_middle_texture_size = middle_section_size; + + // Maximum real middle texture size. + double max_middle_real_size = MAX(0.0, width_total - (first_section_size + last_section_size)); + + switch (p_mode) { + case FILL_BILINEAR_LEFT_AND_RIGHT: + case FILL_BILINEAR_TOP_AND_BOTTOM: { + last_section_size = MAX(0.0, last_section_size - (width_total - width_filled) * 0.5); + first_section_size = MAX(0.0, first_section_size - (width_total - width_filled) * 0.5); + + // When `width_filled` increases, `middle_section_size` only increases when either of `first_section_size` and `last_section_size` is zero. + // Also, it should always be smaller than or equal to `(width_total - (first_section_size + last_section_size))`. + double real_middle_size = width_filled - first_section_size - last_section_size; + middle_section_size *= MIN(max_middle_real_size, real_middle_size) / max_middle_real_size; + + width_texture = MIN(width_texture, first_section_size + middle_section_size + last_section_size); + } break; + case FILL_MODE_MAX: + break; + default: { + middle_section_size *= MIN(1.0, (MAX(0.0, width_filled - first_section_size) / MAX(1.0, width_total - first_section_size - last_section_size))); + last_section_size = MAX(0.0, last_section_size - (width_total - width_filled)); + first_section_size = MIN(first_section_size, width_filled); + width_texture = MIN(width_texture, first_section_size + middle_section_size + last_section_size); + } + } - switch (mode) { + switch (p_mode) { case FILL_LEFT_TO_RIGHT: { src_rect.size.x = width_texture; dst_rect.size.x = width_filled; @@ -287,16 +331,32 @@ void TextureProgressBar::draw_nine_patch_stretched(const Ref<Texture2D> &p_textu bottomright.y = first_section_size; } break; case FILL_BILINEAR_LEFT_AND_RIGHT: { - // TODO: Implement + double center_mapped_from_real_width = (width_total * 0.5 - topleft.x) / max_middle_real_size * max_middle_texture_size + topleft.x; + double drift_from_unscaled_center = (src_rect.size.x * 0.5 - center_mapped_from_real_width) * (last_section_size - first_section_size) / (bottomright.x - topleft.x); + src_rect.position.x += center_mapped_from_real_width + drift_from_unscaled_center - width_texture * 0.5; + src_rect.size.x = width_texture; + dst_rect.position.x += (width_total - width_filled) * 0.5; + dst_rect.size.x = width_filled; + topleft.x = first_section_size; + bottomright.x = last_section_size; } break; case FILL_BILINEAR_TOP_AND_BOTTOM: { - // TODO: Implement + double center_mapped_from_real_width = (width_total * 0.5 - topleft.y) / max_middle_real_size * max_middle_texture_size + topleft.y; + double drift_from_unscaled_center = (src_rect.size.y * 0.5 - center_mapped_from_real_width) * (last_section_size - first_section_size) / (bottomright.y - topleft.y); + src_rect.position.y += center_mapped_from_real_width + drift_from_unscaled_center - width_texture * 0.5; + src_rect.size.y = width_texture; + dst_rect.position.y += (width_total - width_filled) * 0.5; + dst_rect.size.y = width_filled; + topleft.y = first_section_size; + bottomright.y = last_section_size; } break; case FILL_CLOCKWISE: case FILL_CLOCKWISE_AND_COUNTER_CLOCKWISE: case FILL_COUNTER_CLOCKWISE: { - // Those modes are circular, not relevant for nine patch + // Those modes are circular, not relevant for nine patch. } break; + case FILL_MODE_MAX: + break; } } @@ -310,19 +370,34 @@ void TextureProgressBar::_notification(int p_what) { const float corners[12] = { -0.125, -0.375, -0.625, -0.875, 0.125, 0.375, 0.625, 0.875, 1.125, 1.375, 1.625, 1.875 }; switch (p_what) { case NOTIFICATION_DRAW: { - if (nine_patch_stretch && (mode == FILL_LEFT_TO_RIGHT || mode == FILL_RIGHT_TO_LEFT || mode == FILL_TOP_TO_BOTTOM || mode == FILL_BOTTOM_TO_TOP)) { + if (nine_patch_stretch && (mode == FILL_LEFT_TO_RIGHT || mode == FILL_RIGHT_TO_LEFT || mode == FILL_TOP_TO_BOTTOM || mode == FILL_BOTTOM_TO_TOP || mode == FILL_BILINEAR_LEFT_AND_RIGHT || mode == FILL_BILINEAR_TOP_AND_BOTTOM)) { if (under.is_valid()) { - draw_nine_patch_stretched(under, FILL_LEFT_TO_RIGHT, 1.0, tint_under); + draw_nine_patch_stretched(under, mode, 1.0, tint_under); } if (progress.is_valid()) { draw_nine_patch_stretched(progress, mode, get_as_ratio(), tint_progress); } if (over.is_valid()) { - draw_nine_patch_stretched(over, FILL_LEFT_TO_RIGHT, 1.0, tint_over); + draw_nine_patch_stretched(over, mode, 1.0, tint_over); } } else { if (under.is_valid()) { - draw_texture(under, Point2(), tint_under); + switch (mode) { + case FILL_CLOCKWISE: + case FILL_COUNTER_CLOCKWISE: + case FILL_CLOCKWISE_AND_COUNTER_CLOCKWISE: { + if (nine_patch_stretch) { + Rect2 region = Rect2(Point2(), get_size()); + draw_texture_rect(under, region, false, tint_under); + } else { + draw_texture(under, Point2(), tint_under); + } + } break; + case FILL_MODE_MAX: + break; + default: + draw_texture(under, Point2(), tint_under); + } } if (progress.is_valid()) { Size2 s = progress->get_size(); @@ -353,7 +428,7 @@ void TextureProgressBar::_notification(int p_what) { float val = get_as_ratio() * rad_max_degrees / 360; if (val == 1) { Rect2 region = Rect2(Point2(), s); - draw_texture_rect_region(progress, region, region, tint_progress); + draw_texture_rect(progress, region, false, tint_progress); } else if (val != 0) { Array pts; float direction = mode == FILL_COUNTER_CLOCKWISE ? -1 : 1; @@ -416,12 +491,29 @@ void TextureProgressBar::_notification(int p_what) { Rect2 region = Rect2(Point2(0, s.y / 2 - s.y * get_as_ratio() / 2), Size2(s.x, s.y * get_as_ratio())); draw_texture_rect_region(progress, region, region, tint_progress); } break; + case FILL_MODE_MAX: + break; default: draw_texture_rect_region(progress, Rect2(Point2(), Size2(s.x * get_as_ratio(), s.y)), Rect2(Point2(), Size2(s.x * get_as_ratio(), s.y)), tint_progress); } } if (over.is_valid()) { - draw_texture(over, Point2(), tint_over); + switch (mode) { + case FILL_CLOCKWISE: + case FILL_COUNTER_CLOCKWISE: + case FILL_CLOCKWISE_AND_COUNTER_CLOCKWISE: { + if (nine_patch_stretch) { + Rect2 region = Rect2(Point2(), get_size()); + draw_texture_rect(over, region, false, tint_over); + } else { + draw_texture(over, Point2(), tint_over); + } + } break; + case FILL_MODE_MAX: + break; + default: + draw_texture(over, Point2(), tint_over); + } } } } break; @@ -429,7 +521,7 @@ void TextureProgressBar::_notification(int p_what) { } void TextureProgressBar::set_fill_mode(int p_fill) { - ERR_FAIL_INDEX(p_fill, 9); + ERR_FAIL_INDEX(p_fill, FILL_MODE_MAX); mode = (FillMode)p_fill; update(); } @@ -512,7 +604,7 @@ void TextureProgressBar::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture_under", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_under_texture", "get_under_texture"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture_over", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_over_texture", "get_over_texture"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture_progress", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_progress_texture", "get_progress_texture"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "fill_mode", PROPERTY_HINT_ENUM, "Left to Right,Right to Left,Top to Bottom,Bottom to Top,Clockwise,Counter Clockwise,Bilinear (Left and Right),Bilinear (Top and Bottom), Clockwise and Counter Clockwise"), "set_fill_mode", "get_fill_mode"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "fill_mode", PROPERTY_HINT_ENUM, "Left to Right,Right to Left,Top to Bottom,Bottom to Top,Clockwise,Counter Clockwise,Bilinear (Left and Right),Bilinear (Top and Bottom),Clockwise and Counter Clockwise"), "set_fill_mode", "get_fill_mode"); ADD_GROUP("Tint", "tint_"); ADD_PROPERTY(PropertyInfo(Variant::COLOR, "tint_under"), "set_tint_under", "get_tint_under"); ADD_PROPERTY(PropertyInfo(Variant::COLOR, "tint_over"), "set_tint_over", "get_tint_over"); diff --git a/scene/gui/texture_progress_bar.h b/scene/gui/texture_progress_bar.h index a3883a7017..d147c43a26 100644 --- a/scene/gui/texture_progress_bar.h +++ b/scene/gui/texture_progress_bar.h @@ -54,7 +54,8 @@ public: FILL_COUNTER_CLOCKWISE, FILL_BILINEAR_LEFT_AND_RIGHT, FILL_BILINEAR_TOP_AND_BOTTOM, - FILL_CLOCKWISE_AND_COUNTER_CLOCKWISE + FILL_CLOCKWISE_AND_COUNTER_CLOCKWISE, + FILL_MODE_MAX, }; void set_fill_mode(int p_fill); diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 26d881955b..98de71d81c 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -489,11 +489,11 @@ TreeItem *TreeItem::create_child(int p_idx) { return ti; } -Tree *TreeItem::get_tree() { +Tree *TreeItem::get_tree() const { return tree; } -TreeItem *TreeItem::get_next() { +TreeItem *TreeItem::get_next() const { return next; } @@ -516,11 +516,11 @@ TreeItem *TreeItem::get_prev() { return prev; } -TreeItem *TreeItem::get_parent() { +TreeItem *TreeItem::get_parent() const { return parent; } -TreeItem *TreeItem::get_first_child() { +TreeItem *TreeItem::get_first_child() const { return first_child; } @@ -953,6 +953,56 @@ bool TreeItem::is_folding_disabled() const { return disable_folding; } +Size2 TreeItem::get_minimum_size(int p_column) { + ERR_FAIL_INDEX_V(p_column, cells.size(), Size2()); + Tree *tree = get_tree(); + ERR_FAIL_COND_V(!tree, Size2()); + + Size2 size; + + // Default offset? + //size.width += (disable_folding || tree->hide_folding) ? tree->cache.hseparation : tree->cache.item_margin; + + // Text. + const TreeItem::Cell &cell = cells[p_column]; + if (!cell.text.is_empty()) { + if (cell.dirty) { + tree->update_item_cell(this, p_column); + } + Size2 text_size = cell.text_buf->get_size(); + size.width += text_size.width; + size.height = MAX(size.height, text_size.height); + } + + // Icon. + if (cell.mode == CELL_MODE_CHECK) { + size.width += tree->cache.checked->get_width() + tree->cache.hseparation; + } + if (cell.icon.is_valid()) { + Size2i icon_size = cell.get_icon_size(); + if (cell.icon_max_w > 0 && icon_size.width > cell.icon_max_w) { + icon_size.width = cell.icon_max_w; + } + size.width += icon_size.width + tree->cache.hseparation; + size.height = MAX(size.height, icon_size.height); + } + + // Buttons. + for (int i = 0; i < cell.buttons.size(); i++) { + Ref<Texture2D> texture = cell.buttons[i].texture; + if (texture.is_valid()) { + Size2 button_size = texture->get_size() + tree->cache.button_pressed->get_minimum_size(); + size.width += button_size.width; + size.height = MAX(size.height, button_size.height); + } + } + if (cell.buttons.size() >= 2) { + size.width += (cell.buttons.size() - 1) * tree->cache.button_margin; + } + + return size; +} + Variant TreeItem::_call_recursive_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { if (p_argcount < 1) { r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; @@ -1202,6 +1252,9 @@ void Tree::update_cache() { cache.item_margin = get_theme_constant("item_margin"); cache.button_margin = get_theme_constant("button_margin"); + cache.font_outline_color = get_theme_color("font_outline_color"); + cache.font_outline_size = get_theme_constant("outline_size"); + cache.draw_guides = get_theme_constant("draw_guides"); cache.guide_color = get_theme_color("guide_color"); cache.draw_relationship_lines = get_theme_constant("draw_relationship_lines"); @@ -1463,7 +1516,7 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 int htotal = 0; int label_h = compute_item_height(p_item); - bool rtl = is_layout_rtl(); + bool rtl = cache.rtl; /* Calculate height of the label part */ label_h += cache.vseparation; @@ -1509,6 +1562,20 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 } } + if (!rtl && p_item->cells[i].buttons.size()) { + int button_w = 0; + for (int j = p_item->cells[i].buttons.size() - 1; j >= 0; j--) { + Ref<Texture2D> b = p_item->cells[i].buttons[j].texture; + button_w += b->get_size().width + cache.button_pressed->get_minimum_size().width + cache.button_margin; + } + + int total_ofs = ofs - cache.offset.x; + + if (total_ofs + w > p_draw_size.width) { + w = MAX(button_w, p_draw_size.width - total_ofs); + } + } + int bw = 0; for (int j = p_item->cells[i].buttons.size() - 1; j >= 0; j--) { Ref<Texture2D> b = p_item->cells[i].buttons[j].texture; @@ -1633,8 +1700,8 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 } Color col = p_item->cells[i].custom_color ? p_item->cells[i].color : get_theme_color(p_item->cells[i].selected ? "font_selected_color" : "font_color"); - Color font_outline_color = get_theme_color("font_outline_color"); - int outline_size = get_theme_constant("outline_size"); + Color font_outline_color = cache.font_outline_color; + int outline_size = cache.font_outline_size; Color icon_col = p_item->cells[i].icon_color; if (p_item->cells[i].dirty) { @@ -1846,78 +1913,76 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 int prev_hl_ofs = base_ofs; while (c) { - if (cache.draw_relationship_lines > 0 && (!hide_root || c->parent != root)) { - int root_ofs = children_pos.x + ((p_item->disable_folding || hide_folding) ? cache.hseparation : cache.item_margin); - int parent_ofs = p_pos.x + cache.item_margin; - Point2i root_pos = Point2i(root_ofs, children_pos.y + label_h / 2) - cache.offset + p_draw_ofs; + if (htotal >= 0) { + int child_h = draw_item(children_pos, p_draw_ofs, p_draw_size, c); - if (c->get_first_child() != nullptr) { - root_pos -= Point2i(cache.arrow->get_width(), 0); - } + // Draw relationship lines. + if (cache.draw_relationship_lines > 0 && (!hide_root || c->parent != root)) { + int root_ofs = children_pos.x + ((p_item->disable_folding || hide_folding) ? cache.hseparation : cache.item_margin); + int parent_ofs = p_pos.x + cache.item_margin; + Point2i root_pos = Point2i(root_ofs, children_pos.y + label_h / 2) - cache.offset + p_draw_ofs; - float line_width = cache.relationship_line_width; - float parent_line_width = cache.parent_hl_line_width; - float children_line_width = cache.children_hl_line_width; + if (c->get_first_child() != nullptr) { + root_pos -= Point2i(cache.arrow->get_width(), 0); + } + + float line_width = cache.relationship_line_width; + float parent_line_width = cache.parent_hl_line_width; + float children_line_width = cache.children_hl_line_width; #ifdef TOOLS_ENABLED - line_width *= Math::round(EDSCALE); - parent_line_width *= Math::round(EDSCALE); - children_line_width *= Math::round(EDSCALE); + line_width *= Math::round(EDSCALE); + parent_line_width *= Math::round(EDSCALE); + children_line_width *= Math::round(EDSCALE); #endif - Point2i parent_pos = Point2i(parent_ofs - cache.arrow->get_width() / 2, p_pos.y + label_h / 2 + cache.arrow->get_height() / 2) - cache.offset + p_draw_ofs; + Point2i parent_pos = Point2i(parent_ofs - cache.arrow->get_width() / 2, p_pos.y + label_h / 2 + cache.arrow->get_height() / 2) - cache.offset + p_draw_ofs; - int more_prev_ofs = 0; + int more_prev_ofs = 0; - if (root_pos.y + line_width >= 0) { - if (rtl) { - root_pos.x = get_size().width - root_pos.x; - parent_pos.x = get_size().width - parent_pos.x; - } + if (root_pos.y + line_width >= 0) { + if (rtl) { + root_pos.x = get_size().width - root_pos.x; + parent_pos.x = get_size().width - parent_pos.x; + } - // Order of parts on this bend: the horizontal line first, then the vertical line. - if (_is_branch_selected(c)) { - // If this item or one of its children is selected, we draw the line using parent highlight style. - RenderingServer::get_singleton()->canvas_item_add_line(ci, root_pos, Point2i(parent_pos.x + Math::floor(parent_line_width / 2), root_pos.y), cache.parent_hl_line_color, parent_line_width); - RenderingServer::get_singleton()->canvas_item_add_line(ci, Point2i(parent_pos.x, root_pos.y + Math::floor(parent_line_width / 2)), Point2i(parent_pos.x, prev_hl_ofs), cache.parent_hl_line_color, parent_line_width); - - more_prev_ofs = cache.parent_hl_line_margin; - prev_hl_ofs = root_pos.y + Math::floor(parent_line_width / 2); - } else if (p_item->is_selected(0)) { - // If parent item is selected (but this item is not), we draw the line using children highlight style. - // Siblings of the selected branch can be drawn with a slight offset and their vertical line must appear as highlighted. - if (_is_sibling_branch_selected(c)) { - RenderingServer::get_singleton()->canvas_item_add_line(ci, root_pos, Point2i(parent_pos.x + Math::floor(parent_line_width / 2), root_pos.y), cache.children_hl_line_color, children_line_width); + // Order of parts on this bend: the horizontal line first, then the vertical line. + if (_is_branch_selected(c)) { + // If this item or one of its children is selected, we draw the line using parent highlight style. + RenderingServer::get_singleton()->canvas_item_add_line(ci, root_pos, Point2i(parent_pos.x + Math::floor(parent_line_width / 2), root_pos.y), cache.parent_hl_line_color, parent_line_width); RenderingServer::get_singleton()->canvas_item_add_line(ci, Point2i(parent_pos.x, root_pos.y + Math::floor(parent_line_width / 2)), Point2i(parent_pos.x, prev_hl_ofs), cache.parent_hl_line_color, parent_line_width); + more_prev_ofs = cache.parent_hl_line_margin; prev_hl_ofs = root_pos.y + Math::floor(parent_line_width / 2); + } else if (p_item->is_selected(0)) { + // If parent item is selected (but this item is not), we draw the line using children highlight style. + // Siblings of the selected branch can be drawn with a slight offset and their vertical line must appear as highlighted. + if (_is_sibling_branch_selected(c)) { + RenderingServer::get_singleton()->canvas_item_add_line(ci, root_pos, Point2i(parent_pos.x + Math::floor(parent_line_width / 2), root_pos.y), cache.children_hl_line_color, children_line_width); + RenderingServer::get_singleton()->canvas_item_add_line(ci, Point2i(parent_pos.x, root_pos.y + Math::floor(parent_line_width / 2)), Point2i(parent_pos.x, prev_hl_ofs), cache.parent_hl_line_color, parent_line_width); + + prev_hl_ofs = root_pos.y + Math::floor(parent_line_width / 2); + } else { + RenderingServer::get_singleton()->canvas_item_add_line(ci, root_pos, Point2i(parent_pos.x + Math::floor(children_line_width / 2), root_pos.y), cache.children_hl_line_color, children_line_width); + RenderingServer::get_singleton()->canvas_item_add_line(ci, Point2i(parent_pos.x, root_pos.y + Math::floor(children_line_width / 2)), Point2i(parent_pos.x, prev_ofs + Math::floor(children_line_width / 2)), cache.children_hl_line_color, children_line_width); + } } else { - RenderingServer::get_singleton()->canvas_item_add_line(ci, root_pos, Point2i(parent_pos.x + Math::floor(children_line_width / 2), root_pos.y), cache.children_hl_line_color, children_line_width); - RenderingServer::get_singleton()->canvas_item_add_line(ci, Point2i(parent_pos.x, root_pos.y + Math::floor(children_line_width / 2)), Point2i(parent_pos.x, prev_ofs + Math::floor(children_line_width / 2)), cache.children_hl_line_color, children_line_width); - } - } else { - // If nothing of the above is true, we draw the line using normal style. - // Siblings of the selected branch can be drawn with a slight offset and their vertical line must appear as highlighted. - if (_is_sibling_branch_selected(c)) { - RenderingServer::get_singleton()->canvas_item_add_line(ci, root_pos, Point2i(parent_pos.x + cache.parent_hl_line_margin, root_pos.y), cache.relationship_line_color, line_width); - RenderingServer::get_singleton()->canvas_item_add_line(ci, Point2i(parent_pos.x, root_pos.y + Math::floor(parent_line_width / 2)), Point2i(parent_pos.x, prev_hl_ofs), cache.parent_hl_line_color, parent_line_width); + // If nothing of the above is true, we draw the line using normal style. + // Siblings of the selected branch can be drawn with a slight offset and their vertical line must appear as highlighted. + if (_is_sibling_branch_selected(c)) { + RenderingServer::get_singleton()->canvas_item_add_line(ci, root_pos, Point2i(parent_pos.x + cache.parent_hl_line_margin, root_pos.y), cache.relationship_line_color, line_width); + RenderingServer::get_singleton()->canvas_item_add_line(ci, Point2i(parent_pos.x, root_pos.y + Math::floor(parent_line_width / 2)), Point2i(parent_pos.x, prev_hl_ofs), cache.parent_hl_line_color, parent_line_width); - prev_hl_ofs = root_pos.y + Math::floor(parent_line_width / 2); - } else { - RenderingServer::get_singleton()->canvas_item_add_line(ci, root_pos, Point2i(parent_pos.x + Math::floor(line_width / 2), root_pos.y), cache.relationship_line_color, line_width); - RenderingServer::get_singleton()->canvas_item_add_line(ci, Point2i(parent_pos.x, root_pos.y + Math::floor(line_width / 2)), Point2i(parent_pos.x, prev_ofs + Math::floor(line_width / 2)), cache.relationship_line_color, line_width); + prev_hl_ofs = root_pos.y + Math::floor(parent_line_width / 2); + } else { + RenderingServer::get_singleton()->canvas_item_add_line(ci, root_pos, Point2i(parent_pos.x + Math::floor(line_width / 2), root_pos.y), cache.relationship_line_color, line_width); + RenderingServer::get_singleton()->canvas_item_add_line(ci, Point2i(parent_pos.x, root_pos.y + Math::floor(line_width / 2)), Point2i(parent_pos.x, prev_ofs + Math::floor(line_width / 2)), cache.relationship_line_color, line_width); + } } } - } - if (htotal < 0) { - return -1; + prev_ofs = root_pos.y + more_prev_ofs; } - prev_ofs = root_pos.y + more_prev_ofs; - } - - if (htotal >= 0) { - int child_h = draw_item(children_pos, p_draw_ofs, p_draw_size, c); if (child_h < 0) { if (cache.draw_relationship_lines == 0) { @@ -2090,13 +2155,24 @@ void Tree::_range_click_timeout() { } } + if (!root) { + return; + } + click_handled = false; Ref<InputEventMouseButton> mb; - mb.instance(); + mb.instantiate(); + + int x_limit = get_size().width - cache.bg->get_minimum_size().width; + if (h_scroll->is_visible()) { + x_limit -= h_scroll->get_minimum_size().width; + } + + cache.rtl = is_layout_rtl(); propagate_mouse_activated = false; // done from outside, so signal handler can't clear the tree in the middle of emit (which is a common case) blocked++; - propagate_mouse_event(pos + cache.offset, 0, 0, false, root, MOUSE_BUTTON_LEFT, mb); + propagate_mouse_event(pos + cache.offset, 0, 0, x_limit + cache.offset.width, false, root, MOUSE_BUTTON_LEFT, mb); blocked--; if (range_click_timer->is_one_shot()) { @@ -2119,7 +2195,7 @@ void Tree::_range_click_timeout() { } } -int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool p_double_click, TreeItem *p_item, int p_button, const Ref<InputEventWithModifiers> &p_mod) { +int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, int x_limit, bool p_double_click, TreeItem *p_item, int p_button, const Ref<InputEventWithModifiers> &p_mod) { int item_h = compute_item_height(p_item) + cache.vseparation; bool skip = (p_item == root && hide_root); @@ -2144,6 +2220,9 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool int col = -1; int col_ofs = 0; int col_width = 0; + + int limit_w = x_limit; + for (int i = 0; i < columns.size(); i++) { col_width = get_column_width(i); @@ -2159,6 +2238,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool if (x > col_width) { col_ofs += col_width; x -= col_width; + limit_w -= col_width; continue; } @@ -2172,10 +2252,12 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool int margin = x_ofs + cache.item_margin; //-cache.hseparation; //int lm = cache.bg->get_margin(SIDE_LEFT); col_width -= margin; + limit_w -= margin; col_ofs += margin; x -= margin; } else { col_width -= cache.hseparation; + limit_w -= cache.hseparation; x -= cache.hseparation; } @@ -2189,6 +2271,16 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool bool already_selected = c.selected; bool already_cursor = (p_item == selected_item) && col == selected_col; + if (!cache.rtl && p_item->cells[col].buttons.size()) { + int button_w = 0; + for (int j = p_item->cells[col].buttons.size() - 1; j >= 0; j--) { + Ref<Texture2D> b = p_item->cells[col].buttons[j].texture; + button_w += b->get_size().width + cache.button_pressed->get_minimum_size().width + cache.button_margin; + } + + col_width = MAX(button_w, MIN(limit_w, col_width)); + } + for (int j = c.buttons.size() - 1; j >= 0; j--) { Ref<Texture2D> b = c.buttons[j].texture; int w = b->get_size().width + cache.button_pressed->get_minimum_size().width; @@ -2210,6 +2302,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool //emit_signal("button_pressed"); return -1; } + col_width -= w + cache.button_margin; } @@ -2420,7 +2513,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool TreeItem *c = p_item->first_child; while (c) { - int child_h = propagate_mouse_event(new_pos, x_ofs, y_ofs, p_double_click, c, p_button, p_mod); + int child_h = propagate_mouse_event(new_pos, x_ofs, y_ofs, x_limit, p_double_click, c, p_button, p_mod); if (child_h < 0) { return -1; // break, stop propagating, no need to anymore @@ -3098,8 +3191,14 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { pressing_for_editor = false; propagate_mouse_activated = false; + int x_limit = get_size().width - cache.bg->get_minimum_size().width; + if (h_scroll->is_visible()) { + x_limit -= h_scroll->get_minimum_size().width; + } + + cache.rtl = is_layout_rtl(); blocked++; - propagate_mouse_event(pos + cache.offset, 0, 0, b->is_double_click(), root, b->get_button_index(), b); + propagate_mouse_event(pos + cache.offset, 0, 0, x_limit + cache.offset.width, b->is_double_click(), root, b->get_button_index(), b); blocked--; if (pressing_for_editor) { @@ -3161,6 +3260,8 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { } } break; + default: + break; } } @@ -3276,7 +3377,7 @@ Size2 Tree::get_internal_min_size() const { size.height += get_item_height(root); } for (int i = 0; i < columns.size(); i++) { - size.width += columns[i].min_width; + size.width += get_column_minimum_width(i); } return size; @@ -3300,26 +3401,38 @@ void Tree::update_scrollbars() { h_scroll->set_begin(Point2(0, size.height - hmin.height)); h_scroll->set_end(Point2(size.width - vmin.width, size.height)); - Size2 min = get_internal_min_size(); + Size2 internal_min_size = get_internal_min_size(); - if (min.height < size.height - hmin.height) { - v_scroll->hide(); - cache.offset.y = 0; - } else { + bool display_vscroll = internal_min_size.height + cache.bg->get_margin(SIDE_TOP) > size.height; + bool display_hscroll = internal_min_size.width + cache.bg->get_margin(SIDE_LEFT) > size.width; + for (int i = 0; i < 2; i++) { + // Check twice, as both values are dependent on each other. + if (display_hscroll) { + display_vscroll = internal_min_size.height + cache.bg->get_margin(SIDE_TOP) + hmin.height > size.height; + } + if (display_vscroll) { + display_hscroll = internal_min_size.width + cache.bg->get_margin(SIDE_LEFT) + vmin.width > size.width; + } + } + + if (display_vscroll) { v_scroll->show(); - v_scroll->set_max(min.height); + v_scroll->set_max(internal_min_size.height); v_scroll->set_page(size.height - hmin.height - tbh); cache.offset.y = v_scroll->get_value(); + } else { + v_scroll->hide(); + cache.offset.y = 0; } - if (min.width < size.width - vmin.width) { - h_scroll->hide(); - cache.offset.x = 0; - } else { + if (display_hscroll) { h_scroll->show(); - h_scroll->set_max(min.width); + h_scroll->set_max(internal_min_size.width); h_scroll->set_page(size.width - vmin.width); cache.offset.x = h_scroll->get_value(); + } else { + h_scroll->hide(); + cache.offset.x = 0; } } @@ -3437,6 +3550,9 @@ void Tree::_notification(int p_what) { Point2 draw_ofs; draw_ofs += bg->get_offset(); Size2 draw_size = get_size() - bg->get_minimum_size(); + if (h_scroll->is_visible()) { + draw_size.width -= h_scroll->get_minimum_size().width; + } bg->draw(ci, Rect2(Point2(), get_size())); @@ -3445,7 +3561,9 @@ void Tree::_notification(int p_what) { draw_ofs.y += tbh; draw_size.y -= tbh; - if (root) { + cache.rtl = is_layout_rtl(); + + if (root && get_size().x > 0 && get_size().y > 0) { draw_item(Point2(), draw_ofs, draw_size, root); } @@ -3456,7 +3574,7 @@ void Tree::_notification(int p_what) { Ref<StyleBox> sb = (cache.click_type == Cache::CLICK_TITLE && cache.click_index == i) ? cache.title_button_pressed : ((cache.hover_type == Cache::CLICK_TITLE && cache.hover_index == i) ? cache.title_button_hover : cache.title_button); Ref<Font> f = cache.tb_font; Rect2 tbrect = Rect2(ofs2 - cache.offset.x, bg->get_margin(SIDE_TOP), get_column_width(i), tbh); - if (is_layout_rtl()) { + if (cache.rtl) { tbrect.position.x = get_size().width - tbrect.size.x - tbrect.position.x; } sb->draw(ci, tbrect); @@ -3513,7 +3631,17 @@ void Tree::_update_all() { } Size2 Tree::get_minimum_size() const { - return Size2(1, 1); + if (h_scroll_enabled && v_scroll_enabled) { + return Size2(); + } else { + Vector2 min_size = get_internal_min_size(); + Ref<StyleBox> bg = cache.bg; + if (bg.is_valid()) { + min_size.x += bg->get_margin(SIDE_LEFT) + bg->get_margin(SIDE_RIGHT); + min_size.y += bg->get_margin(SIDE_TOP) + bg->get_margin(SIDE_BOTTOM); + } + return Vector2(h_scroll_enabled ? 0 : min_size.x, v_scroll_enabled ? 0 : min_size.y); + } } TreeItem *Tree::create_item(TreeItem *p_parent, int p_idx) { @@ -3541,11 +3669,11 @@ TreeItem *Tree::create_item(TreeItem *p_parent, int p_idx) { return ti; } -TreeItem *Tree::get_root() { +TreeItem *Tree::get_root() const { return root; } -TreeItem *Tree::get_last_item() { +TreeItem *Tree::get_last_item() const { TreeItem *last = root; while (last) { @@ -3675,13 +3803,13 @@ bool Tree::is_root_hidden() const { return hide_root; } -void Tree::set_column_min_width(int p_column, int p_min_width) { +void Tree::set_column_custom_minimum_width(int p_column, int p_min_width) { ERR_FAIL_INDEX(p_column, columns.size()); - if (p_min_width < 1) { + if (p_min_width < 0) { return; } - columns.write[p_column].min_width = p_min_width; + columns.write[p_column].custom_min_width = p_min_width; update(); } @@ -3692,6 +3820,36 @@ void Tree::set_column_expand(int p_column, bool p_expand) { update(); } +void Tree::set_column_expand_ratio(int p_column, int p_ratio) { + ERR_FAIL_INDEX(p_column, columns.size()); + columns.write[p_column].expand_ratio = p_ratio; + update(); +} + +void Tree::set_column_clip_content(int p_column, bool p_fit) { + ERR_FAIL_INDEX(p_column, columns.size()); + + columns.write[p_column].clip_content = p_fit; + update(); +} + +bool Tree::is_column_expanding(int p_column) const { + ERR_FAIL_INDEX_V(p_column, columns.size(), false); + + return columns[p_column].expand; +} +int Tree::get_column_expand_ratio(int p_column) const { + ERR_FAIL_INDEX_V(p_column, columns.size(), 1); + + return columns[p_column].expand_ratio; +} + +bool Tree::is_column_clipping_content(int p_column) const { + ERR_FAIL_INDEX_V(p_column, columns.size(), false); + + return columns[p_column].clip_content; +} + TreeItem *Tree::get_selected() const { return selected_item; } @@ -3748,44 +3906,81 @@ TreeItem *Tree::get_next_selected(TreeItem *p_item) { return nullptr; } -int Tree::get_column_width(int p_column) const { +int Tree::get_column_minimum_width(int p_column) const { ERR_FAIL_INDEX_V(p_column, columns.size(), -1); - if (!columns[p_column].expand) { - return columns[p_column].min_width; + int min_width = columns[p_column].custom_min_width; + + if (show_column_titles) { + min_width = MAX(cache.font->get_string_size(columns[p_column].title).width, min_width); + } + + if (!columns[p_column].clip_content) { + int depth = 0; + TreeItem *next; + for (TreeItem *item = get_root(); item; item = next) { + next = item->get_next_visible(); + // Compute the depth in tree. + if (next && p_column == 0) { + if (next->get_parent() == item) { + depth += 1; + } else { + TreeItem *common_parent = item->get_parent(); + while (common_parent != next->get_parent()) { + common_parent = common_parent->get_parent(); + depth -= 1; + } + } + } + + // Get the item minimum size. + Size2 item_size = item->get_minimum_size(p_column); + if (p_column == 0) { + item_size.width += cache.item_margin * depth; + } + min_width = MAX(min_width, item_size.width); + } } - int expand_area = get_size().width; + return min_width; +} - Ref<StyleBox> bg = cache.bg; +int Tree::get_column_width(int p_column) const { + ERR_FAIL_INDEX_V(p_column, columns.size(), -1); - if (bg.is_valid()) { - expand_area -= bg->get_margin(SIDE_LEFT) + bg->get_margin(SIDE_RIGHT); - } + int column_width = get_column_minimum_width(p_column); - if (v_scroll->is_visible_in_tree()) { - expand_area -= v_scroll->get_combined_minimum_size().width; - } + if (columns[p_column].expand) { + int expand_area = get_size().width; - int expanding_columns = 0; - int expanding_total = 0; + Ref<StyleBox> bg = cache.bg; - for (int i = 0; i < columns.size(); i++) { - if (!columns[i].expand) { - expand_area -= columns[i].min_width; - } else { - expanding_total += columns[i].min_width; - expanding_columns++; + if (bg.is_valid()) { + expand_area -= bg->get_margin(SIDE_LEFT) + bg->get_margin(SIDE_RIGHT); } - } - if (expand_area < expanding_total) { - return columns[p_column].min_width; - } + if (v_scroll->is_visible_in_tree()) { + expand_area -= v_scroll->get_combined_minimum_size().width; + } - ERR_FAIL_COND_V(expanding_columns == 0, -1); // shouldn't happen + int expanding_total = 0; - return expand_area * columns[p_column].min_width / expanding_total; + for (int i = 0; i < columns.size(); i++) { + expand_area -= get_column_minimum_width(i); + if (columns[i].expand) { + expanding_total += columns[i].expand_ratio; + } + } + + if (expand_area >= expanding_total && expanding_total > 0) { + column_width += expand_area * columns[p_column].expand_ratio / expanding_total; + } + } + + if (p_column < columns.size() - 1) { + column_width += cache.hseparation; + } + return column_width; } void Tree::propagate_set_columns(TreeItem *p_item) { @@ -4047,6 +4242,24 @@ void Tree::scroll_to_item(TreeItem *p_item) { } } +void Tree::set_h_scroll_enabled(bool p_enable) { + h_scroll_enabled = p_enable; + minimum_size_changed(); +} + +bool Tree::is_h_scroll_enabled() const { + return h_scroll_enabled; +} + +void Tree::set_v_scroll_enabled(bool p_enable) { + v_scroll_enabled = p_enable; + minimum_size_changed(); +} + +bool Tree::is_v_scroll_enabled() const { + return v_scroll_enabled; +} + TreeItem *Tree::_search_item_text(TreeItem *p_at, const String &p_find, int *r_col, bool p_selectable, bool p_backwards) { TreeItem *from = p_at; TreeItem *loop = nullptr; // Safe-guard against infinite loop. @@ -4422,8 +4635,14 @@ void Tree::_bind_methods() { ClassDB::bind_method(D_METHOD("create_item", "parent", "idx"), &Tree::_create_item, DEFVAL(Variant()), DEFVAL(-1)); ClassDB::bind_method(D_METHOD("get_root"), &Tree::get_root); - ClassDB::bind_method(D_METHOD("set_column_min_width", "column", "min_width"), &Tree::set_column_min_width); + ClassDB::bind_method(D_METHOD("set_column_custom_minimum_width", "column", "min_width"), &Tree::set_column_custom_minimum_width); ClassDB::bind_method(D_METHOD("set_column_expand", "column", "expand"), &Tree::set_column_expand); + ClassDB::bind_method(D_METHOD("set_column_expand_ratio", "column", "ratio"), &Tree::set_column_expand_ratio); + ClassDB::bind_method(D_METHOD("set_column_clip_content", "column", "enable"), &Tree::set_column_clip_content); + ClassDB::bind_method(D_METHOD("is_column_expanding", "column"), &Tree::is_column_expanding); + ClassDB::bind_method(D_METHOD("is_column_clipping_content", "column"), &Tree::is_column_clipping_content); + ClassDB::bind_method(D_METHOD("get_column_expand_ratio", "column"), &Tree::get_column_expand_ratio); + ClassDB::bind_method(D_METHOD("get_column_width", "column"), &Tree::get_column_width); ClassDB::bind_method(D_METHOD("set_hide_root", "enable"), &Tree::set_hide_root); @@ -4468,6 +4687,12 @@ void Tree::_bind_methods() { ClassDB::bind_method(D_METHOD("get_scroll"), &Tree::get_scroll); ClassDB::bind_method(D_METHOD("scroll_to_item", "item"), &Tree::_scroll_to_item); + ClassDB::bind_method(D_METHOD("set_h_scroll_enabled", "h_scroll"), &Tree::set_h_scroll_enabled); + ClassDB::bind_method(D_METHOD("is_h_scroll_enabled"), &Tree::is_h_scroll_enabled); + + ClassDB::bind_method(D_METHOD("set_v_scroll_enabled", "h_scroll"), &Tree::set_v_scroll_enabled); + ClassDB::bind_method(D_METHOD("is_v_scroll_enabled"), &Tree::is_v_scroll_enabled); + ClassDB::bind_method(D_METHOD("set_hide_folding", "hide"), &Tree::set_hide_folding); ClassDB::bind_method(D_METHOD("is_folding_hidden"), &Tree::is_folding_hidden); @@ -4487,6 +4712,8 @@ void Tree::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "hide_root"), "set_hide_root", "is_root_hidden"); ADD_PROPERTY(PropertyInfo(Variant::INT, "drop_mode_flags", PROPERTY_HINT_FLAGS, "On Item,In Between"), "set_drop_mode_flags", "get_drop_mode_flags"); ADD_PROPERTY(PropertyInfo(Variant::INT, "select_mode", PROPERTY_HINT_ENUM, "Single,Row,Multi"), "set_select_mode", "get_select_mode"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "scroll_horizontal_enabled"), "set_h_scroll_enabled", "is_h_scroll_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "scroll_vertical_enabled"), "set_v_scroll_enabled", "is_v_scroll_enabled"); ADD_SIGNAL(MethodInfo("item_selected")); ADD_SIGNAL(MethodInfo("cell_selected")); diff --git a/scene/gui/tree.h b/scene/gui/tree.h index 0571a605a5..10e6642303 100644 --- a/scene/gui/tree.h +++ b/scene/gui/tree.h @@ -115,7 +115,7 @@ private: Ref<Font> custom_font; Cell() { - text_buf.instance(); + text_buf.instantiate(); } Size2 get_icon_size() const; @@ -315,16 +315,18 @@ public: void set_disable_folding(bool p_disable); bool is_folding_disabled() const; + Size2 get_minimum_size(int p_column); + /* Item manipulation */ TreeItem *create_child(int p_idx = -1); - Tree *get_tree(); + Tree *get_tree() const; TreeItem *get_prev(); - TreeItem *get_next(); - TreeItem *get_parent(); - TreeItem *get_first_child(); + TreeItem *get_next() const; + TreeItem *get_parent() const; + TreeItem *get_first_child() const; TreeItem *get_prev_visible(bool p_wrap = false); TreeItem *get_next_visible(bool p_wrap = false); @@ -408,15 +410,17 @@ private: int drop_mode_flags = 0; struct ColumnInfo { - int min_width = 1; + int custom_min_width = 0; + int expand_ratio = 1; bool expand = true; + bool clip_content = false; String title; Ref<TextLine> text_buf; Dictionary opentype_features; String language; Control::TextDirection text_direction = Control::TEXT_DIRECTION_INHERITED; ColumnInfo() { - text_buf.instance(); + text_buf.instantiate(); } }; @@ -448,7 +452,7 @@ private: void draw_item_rect(TreeItem::Cell &p_cell, const Rect2i &p_rect, const Color &p_color, const Color &p_icon_color, int p_ol_size, const Color &p_ol_color); int draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 &p_draw_size, TreeItem *p_item); void select_single_item(TreeItem *p_selected, TreeItem *p_current, int p_col, TreeItem *p_prev = nullptr, bool *r_in_range = nullptr, bool p_force_deselect = false); - int propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool p_double_click, TreeItem *p_item, int p_button, const Ref<InputEventWithModifiers> &p_mod); + int propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, int x_limit, bool p_double_click, TreeItem *p_item, int p_button, const Ref<InputEventWithModifiers> &p_mod); void _text_editor_submit(String p_text); void _text_editor_modal_close(); void value_editor_changed(double p_value); @@ -502,6 +506,7 @@ private: Color parent_hl_line_color; Color children_hl_line_color; Color custom_button_font_highlight; + Color font_outline_color; int hseparation = 0; int vseparation = 0; @@ -516,6 +521,7 @@ private: int draw_guides = 0; int scroll_border = 0; int scroll_speed = 0; + int font_outline_size = 0; enum ClickType { CLICK_NONE, @@ -538,6 +544,8 @@ private: Point2i text_editor_position; + bool rtl = false; + } cache; int _get_title_button_height() const; @@ -546,6 +554,9 @@ private: HScrollBar *h_scroll; VScrollBar *v_scroll; + bool h_scroll_enabled = true; + bool v_scroll_enabled = true; + Size2 get_internal_min_size() const; void update_cache(); void update_scrollbars(); @@ -623,12 +634,19 @@ public: void clear(); TreeItem *create_item(TreeItem *p_parent = nullptr, int p_idx = -1); - TreeItem *get_root(); - TreeItem *get_last_item(); + TreeItem *get_root() const; + TreeItem *get_last_item() const; - void set_column_min_width(int p_column, int p_min_width); + void set_column_custom_minimum_width(int p_column, int p_min_width); void set_column_expand(int p_column, bool p_expand); + void set_column_expand_ratio(int p_column, int p_ratio); + void set_column_clip_content(int p_column, bool p_fit); + int get_column_minimum_width(int p_column) const; int get_column_width(int p_column) const; + int get_column_expand_ratio(int p_column) const; + + bool is_column_expanding(int p_column) const; + bool is_column_clipping_content(int p_column) const; void set_hide_root(bool p_enabled); bool is_root_hidden() const; @@ -679,6 +697,10 @@ public: Point2 get_scroll() const; void scroll_to_item(TreeItem *p_item); + void set_h_scroll_enabled(bool p_enable); + bool is_h_scroll_enabled() const; + void set_v_scroll_enabled(bool p_enable); + bool is_v_scroll_enabled() const; void set_cursor_can_exit_tree(bool p_enable); diff --git a/scene/gui/video_player.cpp b/scene/gui/video_player.cpp index ed3c0b7a56..229b5384ea 100644 --- a/scene/gui/video_player.cpp +++ b/scene/gui/video_player.cpp @@ -452,7 +452,7 @@ void VideoPlayer::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "stream", PROPERTY_HINT_RESOURCE_TYPE, "VideoStream"), "set_stream", "get_stream"); //ADD_PROPERTY( PropertyInfo(Variant::BOOL, "stream/loop"), "set_loop", "has_loop") ; ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "volume_db", PROPERTY_HINT_RANGE, "-80,24,0.01"), "set_volume_db", "get_volume_db"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "volume", PROPERTY_HINT_EXP_RANGE, "0,15,0.01", PROPERTY_USAGE_NONE), "set_volume", "get_volume"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "volume", PROPERTY_HINT_RANGE, "0,15,0.01,exp", PROPERTY_USAGE_NONE), "set_volume", "get_volume"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "autoplay"), "set_autoplay", "has_autoplay"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "paused"), "set_paused", "is_paused"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "expand"), "set_expand", "has_expand"); diff --git a/scene/main/canvas_item.cpp b/scene/main/canvas_item.cpp index 361f584a5d..f81a3ef630 100644 --- a/scene/main/canvas_item.cpp +++ b/scene/main/canvas_item.cpp @@ -239,7 +239,7 @@ bool CanvasItemMaterial::get_particles_anim_loop() const { void CanvasItemMaterial::_validate_property(PropertyInfo &property) const { if (property.name.begins_with("particles_anim_") && !particles_animation) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } } @@ -1227,7 +1227,7 @@ void CanvasItem::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "texture_repeat", PROPERTY_HINT_ENUM, "Inherit,Disabled,Enabled,Mirror"), "set_texture_repeat", "get_texture_repeat"); ADD_GROUP("Material", ""); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "ShaderMaterial,CanvasItemMaterial"), "set_material", "get_material"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "CanvasItemMaterial,ShaderMaterial"), "set_material", "get_material"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_parent_material"), "set_use_parent_material", "get_use_parent_material"); // ADD_PROPERTY(PropertyInfo(Variant::BOOL,"transform/notify"),"set_transform_notify","is_transform_notify_enabled"); diff --git a/scene/main/canvas_layer.cpp b/scene/main/canvas_layer.cpp index f699e68715..4540e42b4c 100644 --- a/scene/main/canvas_layer.cpp +++ b/scene/main/canvas_layer.cpp @@ -103,14 +103,6 @@ real_t CanvasLayer::get_rotation() const { return rot; } -void CanvasLayer::set_rotation_degrees(real_t p_degrees) { - set_rotation(Math::deg2rad(p_degrees)); -} - -real_t CanvasLayer::get_rotation_degrees() const { - return Math::rad2deg(get_rotation()); -} - void CanvasLayer::set_scale(const Vector2 &p_scale) { if (locrotscale_dirty) { _update_locrotscale(); @@ -277,9 +269,6 @@ void CanvasLayer::_bind_methods() { ClassDB::bind_method(D_METHOD("set_rotation", "radians"), &CanvasLayer::set_rotation); ClassDB::bind_method(D_METHOD("get_rotation"), &CanvasLayer::get_rotation); - ClassDB::bind_method(D_METHOD("set_rotation_degrees", "degrees"), &CanvasLayer::set_rotation_degrees); - ClassDB::bind_method(D_METHOD("get_rotation_degrees"), &CanvasLayer::get_rotation_degrees); - ClassDB::bind_method(D_METHOD("set_scale", "scale"), &CanvasLayer::set_scale); ClassDB::bind_method(D_METHOD("get_scale"), &CanvasLayer::get_scale); @@ -298,8 +287,7 @@ void CanvasLayer::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "layer", PROPERTY_HINT_RANGE, "-128,128,1"), "set_layer", "get_layer"); ADD_GROUP("Transform", ""); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "offset"), "set_offset", "get_offset"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "rotation_degrees", PROPERTY_HINT_RANGE, "-1080,1080,0.1,or_lesser,or_greater", PROPERTY_USAGE_EDITOR), "set_rotation_degrees", "get_rotation_degrees"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "rotation", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_rotation", "get_rotation"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "rotation", PROPERTY_HINT_RANGE, "-1080,1080,0.1,or_lesser,or_greater,radians"), "set_rotation", "get_rotation"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "scale"), "set_scale", "get_scale"); ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM2D, "transform"), "set_transform", "get_transform"); ADD_GROUP("", ""); diff --git a/scene/main/canvas_layer.h b/scene/main/canvas_layer.h index 899039340a..5de1ebf18d 100644 --- a/scene/main/canvas_layer.h +++ b/scene/main/canvas_layer.h @@ -79,9 +79,6 @@ public: void set_rotation(real_t p_radians); real_t get_rotation() const; - void set_rotation_degrees(real_t p_degrees); - real_t get_rotation_degrees() const; - void set_scale(const Size2 &p_scale); Size2 get_scale() const; diff --git a/scene/main/http_request.cpp b/scene/main/http_request.cpp index 927b114fbc..775dfa4c46 100644 --- a/scene/main/http_request.cpp +++ b/scene/main/http_request.cpp @@ -322,7 +322,8 @@ bool HTTPRequest::_update_connection() { } else { // Did not request yet, do request - Error err = client->request_raw(method, request_string, headers, request_data); + int size = request_data.size(); + Error err = client->request(method, request_string, headers, size > 0 ? request_data.ptr() : nullptr, size); if (err != OK) { call_deferred("_request_done", RESULT_CONNECTION_ERROR, 0, PackedStringArray(), PackedByteArray()); return true; @@ -627,7 +628,7 @@ void HTTPRequest::_bind_methods() { } HTTPRequest::HTTPRequest() { - client.instance(); + client = Ref<HTTPClient>(HTTPClient::create()); timer = memnew(Timer); timer->set_one_shot(true); timer->connect("timeout", callable_mp(this, &HTTPRequest::_timeout)); diff --git a/scene/main/instance_placeholder.cpp b/scene/main/instance_placeholder.cpp index 1661984e30..89dac5f5a8 100644 --- a/scene/main/instance_placeholder.cpp +++ b/scene/main/instance_placeholder.cpp @@ -88,7 +88,7 @@ Node *InstancePlaceholder::create_instance(bool p_replace, const Ref<PackedScene if (!ps.is_valid()) { return nullptr; } - Node *scene = ps->instance(); + Node *scene = ps->instantiate(); if (!scene) { return nullptr; } diff --git a/scene/main/node.cpp b/scene/main/node.cpp index e1abea81ef..787b283e8c 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -35,6 +35,7 @@ #include "core/object/message_queue.h" #include "core/string/print_string.h" #include "instance_placeholder.h" +#include "scene/animation/tween.h" #include "scene/debugger/scene_debugger.h" #include "scene/resources/packed_scene.h" #include "scene/scene_string_names.h" @@ -402,6 +403,7 @@ void Node::set_process_mode(ProcessMode p_mode) { } bool prev_can_process = can_process(); + bool prev_enabled = _is_enabled(); data.process_mode = p_mode; @@ -416,6 +418,7 @@ void Node::set_process_mode(ProcessMode p_mode) { } bool next_can_process = can_process(); + bool next_enabled = _is_enabled(); int pause_notification = 0; @@ -425,7 +428,16 @@ void Node::set_process_mode(ProcessMode p_mode) { pause_notification = NOTIFICATION_UNPAUSED; } - _propagate_process_owner(data.process_owner, pause_notification); + int enabled_notification = 0; + + if (prev_enabled && !next_enabled) { + enabled_notification = NOTIFICATION_DISABLED; + } else if (!prev_enabled && next_enabled) { + enabled_notification = NOTIFICATION_ENABLED; + } + + _propagate_process_owner(data.process_owner, pause_notification, enabled_notification); + #ifdef TOOLS_ENABLED // This is required for the editor to update the visibility of disabled nodes // It's very expensive during runtime to change, so editor-only @@ -454,17 +466,21 @@ Node::ProcessMode Node::get_process_mode() const { return data.process_mode; } -void Node::_propagate_process_owner(Node *p_owner, int p_notification) { +void Node::_propagate_process_owner(Node *p_owner, int p_pause_notification, int p_enabled_notification) { data.process_owner = p_owner; - if (p_notification != 0) { - notification(p_notification); + if (p_pause_notification != 0) { + notification(p_pause_notification); + } + + if (p_enabled_notification != 0) { + notification(p_enabled_notification); } for (int i = 0; i < data.children.size(); i++) { Node *c = data.children[i]; if (c->data.process_mode == PROCESS_MODE_INHERIT) { - c->_propagate_process_owner(p_owner, p_notification); + c->_propagate_process_owner(p_owner, p_pause_notification, p_enabled_notification); } } } @@ -491,7 +507,7 @@ bool Node::is_network_master() const { /***** RPC CONFIG ********/ -uint16_t Node::rpc_config(const StringName &p_method, MultiplayerAPI::RPCMode p_rpc_mode, NetworkedMultiplayerPeer::TransferMode p_transfer_mode, int p_channel) { +uint16_t Node::rpc_config(const StringName &p_method, MultiplayerAPI::RPCMode p_rpc_mode, MultiplayerPeer::TransferMode p_transfer_mode, int p_channel) { for (int i = 0; i < data.rpc_methods.size(); i++) { if (data.rpc_methods[i].name == p_method) { MultiplayerAPI::RPCConfig &nd = data.rpc_methods.write[i]; @@ -668,6 +684,27 @@ bool Node::_can_process(bool p_paused) const { } } +bool Node::_is_enabled() const { + ProcessMode process_mode; + + if (data.process_mode == PROCESS_MODE_INHERIT) { + if (!data.process_owner) { + process_mode = PROCESS_MODE_PAUSABLE; + } else { + process_mode = data.process_owner->data.process_mode; + } + } else { + process_mode = data.process_mode; + } + + return (process_mode != PROCESS_MODE_DISABLED); +} + +bool Node::is_enabled() const { + ERR_FAIL_COND_V(!is_inside_tree(), false); + return _is_enabled(); +} + float Node::get_physics_process_delta_time() const { if (data.tree) { return data.tree->get_physics_process_time(); @@ -1040,7 +1077,7 @@ void Node::add_child(Node *p_child, bool p_legible_unique_name) { ERR_FAIL_COND_MSG(p_child == this, vformat("Can't add child '%s' to itself.", p_child->get_name())); // adding to itself! ERR_FAIL_COND_MSG(p_child->data.parent, vformat("Can't add child '%s' to '%s', already has a parent '%s'.", p_child->get_name(), get_name(), p_child->data.parent->get_name())); //Fail if node has a parent #ifdef DEBUG_ENABLED - ERR_FAIL_COND_MSG(p_child->is_a_parent_of(this), vformat("Can't add child '%s' to '%s' as it would result in a cyclic dependency since '%s' is already a parent of '%s'.", p_child->get_name(), get_name(), p_child->get_name(), get_name())); + ERR_FAIL_COND_MSG(p_child->is_ancestor_of(this), vformat("Can't add child '%s' to '%s' as it would result in a cyclic dependency since '%s' is already a parent of '%s'.", p_child->get_name(), get_name(), p_child->get_name(), get_name())); #endif ERR_FAIL_COND_MSG(data.blocked > 0, "Parent node is busy setting up children, add_node() failed. Consider using call_deferred(\"add_child\", child) instead."); @@ -1283,7 +1320,7 @@ Node *Node::find_parent(const String &p_mask) const { return nullptr; } -bool Node::is_a_parent_of(const Node *p_node) const { +bool Node::is_ancestor_of(const Node *p_node) const { ERR_FAIL_NULL_V(p_node, false); Node *p = p_node->data.parent; while (p) { @@ -1686,6 +1723,13 @@ int Node::get_index() const { return data.pos; } +Ref<Tween> Node::create_tween() { + ERR_FAIL_COND_V_MSG(!data.tree, nullptr, "Can't create Tween when not inside scene tree."); + Ref<Tween> tween = get_tree()->create_tween(); + tween->bind_node(this); + return tween; +} + void Node::remove_and_skip() { ERR_FAIL_COND(!data.parent); @@ -1741,7 +1785,7 @@ String Node::get_editor_description() const { void Node::set_editable_instance(Node *p_node, bool p_editable) { ERR_FAIL_NULL(p_node); - ERR_FAIL_COND(!is_a_parent_of(p_node)); + ERR_FAIL_COND(!is_ancestor_of(p_node)); if (!p_editable) { p_node->data.editable_instance = false; // Avoid this flag being needlessly saved; @@ -1756,13 +1800,13 @@ bool Node::is_editable_instance(const Node *p_node) const { if (!p_node) { return false; // Easier, null is never editable. :) } - ERR_FAIL_COND_V(!is_a_parent_of(p_node), false); + ERR_FAIL_COND_V(!is_ancestor_of(p_node), false); return p_node->data.editable_instance; } Node *Node::get_deepest_editable_node(Node *p_start_node) const { ERR_FAIL_NULL_V(p_start_node, nullptr); - ERR_FAIL_COND_V(!is_a_parent_of(p_start_node), p_start_node); + ERR_FAIL_COND_V(!is_ancestor_of(p_start_node), p_start_node); Node const *iterated_item = p_start_node; Node *node = p_start_node; @@ -1805,7 +1849,7 @@ bool Node::get_scene_instance_load_placeholder() const { Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const { Node *node = nullptr; - bool instanced = false; + bool instantiated = false; if (Object::cast_to<InstancePlaceholder>(this)) { const InstancePlaceholder *ip = Object::cast_to<const InstancePlaceholder>(this); @@ -1822,13 +1866,13 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const ges = PackedScene::GEN_EDIT_STATE_INSTANCE; } #endif - node = res->instance(ges); + node = res->instantiate(ges); ERR_FAIL_COND_V(!node, nullptr); - instanced = true; + instantiated = true; } else { - Object *obj = ClassDB::instance(get_class()); + Object *obj = ClassDB::instantiate(get_class()); ERR_FAIL_COND_V(!obj, nullptr); node = Object::cast_to<Node>(obj); if (!node) { @@ -1848,9 +1892,9 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const List<const Node *> node_tree; node_tree.push_front(this); - if (instanced) { - // Since nodes in the instanced hierarchy won't be duplicated explicitly, we need to make an inventory - // of all the nodes in the tree of the instanced scene in order to transfer the values of the properties + if (instantiated) { + // Since nodes in the instantiated hierarchy won't be duplicated explicitly, we need to make an inventory + // of all the nodes in the tree of the instantiated scene in order to transfer the values of the properties Vector<const Node *> instance_roots; instance_roots.push_back(this); @@ -1858,8 +1902,8 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const for (List<const Node *>::Element *N = node_tree.front(); N; N = N->next()) { for (int i = 0; i < N->get()->get_child_count(); ++i) { Node *descendant = N->get()->get_child(i); - // Skip nodes not really belonging to the instanced hierarchy; they'll be processed normally later - // but remember non-instanced nodes that are hidden below instanced ones + // Skip nodes not really belonging to the instantiated hierarchy; they'll be processed normally later + // but remember non-instantiated nodes that are hidden below instantiated ones if (!instance_roots.has(descendant->get_owner())) { if (descendant->get_parent() && descendant->get_parent() != this && descendant->data.owner != descendant->get_parent()) { hidden_roots.push_back(descendant); @@ -1942,7 +1986,7 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const if (get_child(i)->data.parent_owned) { continue; } - if (instanced && get_child(i)->data.owner == this) { + if (instantiated && get_child(i)->data.owner == this) { continue; //part of instance } @@ -2066,7 +2110,7 @@ void Node::remap_nested_resources(RES p_resource, const Map<RES, RES> &p_resourc // because re-targeting of connections from some descendant to another is not possible // if the emitter node comes later in tree order than the receiver void Node::_duplicate_signals(const Node *p_original, Node *p_copy) const { - if ((this != p_original) && !(p_original->is_a_parent_of(this))) { + if ((this != p_original) && !(p_original->is_ancestor_of(this))) { return; } @@ -2449,7 +2493,9 @@ String Node::get_configuration_warnings_as_string() const { if (i > 0) { all_warnings += "\n\n"; } - all_warnings += String(warnings[i]); + // Format as a bullet point list to make multiple warnings easier to distinguish + // from each other. + all_warnings += String::utf8("• ") + String(warnings[i]); } return all_warnings; } @@ -2459,7 +2505,7 @@ void Node::update_configuration_warnings() { if (!is_inside_tree()) { return; } - if (get_tree()->get_edited_scene_root() && (get_tree()->get_edited_scene_root() == this || get_tree()->get_edited_scene_root()->is_a_parent_of(this))) { + if (get_tree()->get_edited_scene_root() && (get_tree()->get_edited_scene_root() == this || get_tree()->get_edited_scene_root()->is_ancestor_of(this))) { get_tree()->emit_signal(SceneStringNames::get_singleton()->node_configuration_warning_changed, this); } #endif @@ -2506,7 +2552,7 @@ void Node::_bind_methods() { ClassDB::bind_method(D_METHOD("get_node_and_resource", "path"), &Node::_get_node_and_resource); ClassDB::bind_method(D_METHOD("is_inside_tree"), &Node::is_inside_tree); - ClassDB::bind_method(D_METHOD("is_a_parent_of", "node"), &Node::is_a_parent_of); + ClassDB::bind_method(D_METHOD("is_ancestor_of", "node"), &Node::is_ancestor_of); ClassDB::bind_method(D_METHOD("is_greater_than", "node"), &Node::is_greater_than); ClassDB::bind_method(D_METHOD("get_path"), &Node::get_path); ClassDB::bind_method(D_METHOD("get_path_to", "node"), &Node::get_path_to); @@ -2555,6 +2601,7 @@ void Node::_bind_methods() { ClassDB::bind_method(D_METHOD("is_physics_processing_internal"), &Node::is_physics_processing_internal); ClassDB::bind_method(D_METHOD("get_tree"), &Node::get_tree); + ClassDB::bind_method(D_METHOD("create_tween"), &Node::create_tween); ClassDB::bind_method(D_METHOD("duplicate", "flags"), &Node::duplicate, DEFVAL(DUPLICATE_USE_INSTANCING | DUPLICATE_SIGNALS | DUPLICATE_GROUPS | DUPLICATE_SCRIPTS)); ClassDB::bind_method(D_METHOD("replace_by", "node", "keep_groups"), &Node::replace_by, DEFVAL(false)); @@ -2576,7 +2623,7 @@ void Node::_bind_methods() { ClassDB::bind_method(D_METHOD("get_multiplayer"), &Node::get_multiplayer); ClassDB::bind_method(D_METHOD("get_custom_multiplayer"), &Node::get_custom_multiplayer); ClassDB::bind_method(D_METHOD("set_custom_multiplayer", "api"), &Node::set_custom_multiplayer); - ClassDB::bind_method(D_METHOD("rpc_config", "method", "rpc_mode", "transfer_mode", "channel"), &Node::rpc_config, DEFVAL(NetworkedMultiplayerPeer::TRANSFER_MODE_RELIABLE), DEFVAL(0)); + ClassDB::bind_method(D_METHOD("rpc_config", "method", "rpc_mode", "transfer_mode", "channel"), &Node::rpc_config, DEFVAL(MultiplayerPeer::TRANSFER_MODE_RELIABLE), DEFVAL(0)); ClassDB::bind_method(D_METHOD("set_editor_description", "editor_description"), &Node::set_editor_description); ClassDB::bind_method(D_METHOD("get_editor_description"), &Node::get_editor_description); @@ -2619,6 +2666,8 @@ void Node::_bind_methods() { BIND_CONSTANT(NOTIFICATION_INTERNAL_PROCESS); BIND_CONSTANT(NOTIFICATION_INTERNAL_PHYSICS_PROCESS); BIND_CONSTANT(NOTIFICATION_POST_ENTER_TREE); + BIND_CONSTANT(NOTIFICATION_DISABLED); + BIND_CONSTANT(NOTIFICATION_ENABLED); BIND_CONSTANT(NOTIFICATION_EDITOR_PRE_SAVE); BIND_CONSTANT(NOTIFICATION_EDITOR_POST_SAVE); diff --git a/scene/main/node.h b/scene/main/node.h index e7b36f351b..c6727ce884 100644 --- a/scene/main/node.h +++ b/scene/main/node.h @@ -41,6 +41,9 @@ class Viewport; class SceneState; +class Tween; +class PropertyTweener; + class Node : public Object { GDCLASS(Node, Object); OBJ_CATEGORY("Nodes"); @@ -163,7 +166,7 @@ private: void _propagate_after_exit_tree(); void _propagate_validate_owner(); void _print_stray_nodes(); - void _propagate_process_owner(Node *p_owner, int p_notification); + void _propagate_process_owner(Node *p_owner, int p_pause_notification, int p_enabled_notification); Array _get_node_and_resource(const NodePath &p_path); void _duplicate_signals(const Node *p_original, Node *p_copy) const; @@ -181,6 +184,7 @@ private: void _propagate_pause_notification(bool p_enable); _FORCE_INLINE_ bool _can_process(bool p_paused) const; + _FORCE_INLINE_ bool _is_enabled() const; protected: void _block() { data.blocked++; } @@ -224,6 +228,8 @@ public: NOTIFICATION_INTERNAL_PROCESS = 25, NOTIFICATION_INTERNAL_PHYSICS_PROCESS = 26, NOTIFICATION_POST_ENTER_TREE = 27, + NOTIFICATION_DISABLED = 28, + NOTIFICATION_ENABLED = 29, //keep these linked to node NOTIFICATION_WM_MOUSE_ENTER = 1002, @@ -279,7 +285,7 @@ public: _FORCE_INLINE_ bool is_inside_tree() const { return data.inside_tree; } - bool is_a_parent_of(const Node *p_node) const; + bool is_ancestor_of(const Node *p_node) const; bool is_greater_than(const Node *p_node) const; NodePath get_path() const; @@ -308,6 +314,8 @@ public: void remove_and_skip(); int get_index() const; + Ref<Tween> create_tween(); + void print_tree(); void print_tree_pretty(); @@ -380,6 +388,7 @@ public: ProcessMode get_process_mode() const; bool can_process() const; bool can_process_notification(int p_what) const; + bool is_enabled() const; void request_ready(); @@ -421,7 +430,7 @@ public: int get_network_master() const; bool is_network_master() const; - uint16_t rpc_config(const StringName &p_method, MultiplayerAPI::RPCMode p_rpc_mode, NetworkedMultiplayerPeer::TransferMode p_transfer_mode, int p_channel = 0); // config a local method for RPC + uint16_t rpc_config(const StringName &p_method, MultiplayerAPI::RPCMode p_rpc_mode, MultiplayerPeer::TransferMode p_transfer_mode, int p_channel = 0); // config a local method for RPC Vector<MultiplayerAPI::RPCConfig> get_node_rpc_methods() const; void rpc(const StringName &p_method, VARIANT_ARG_LIST); // RPC, honors RPCMode, TransferMode, channel diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index 001c857d4c..fefe4c9f0d 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -41,6 +41,7 @@ #include "core/os/os.h" #include "core/string/print_string.h" #include "node.h" +#include "scene/animation/tween.h" #include "scene/debugger/scene_debugger.h" #include "scene/resources/font.h" #include "scene/resources/material.h" @@ -412,6 +413,9 @@ bool SceneTree::physics_process(float p_time) { _notify_group_pause("physics_process", Node::NOTIFICATION_PHYSICS_PROCESS); _flush_ugc(); MessageQueue::get_singleton()->flush(); //small little hack + + process_tweens(p_time, true); + flush_transform_notifications(); root_lock--; @@ -476,6 +480,8 @@ bool SceneTree::process(float p_time) { E = N; } + process_tweens(p_time, false); + flush_transform_notifications(); //additional transforms after timers update _call_idle_callbacks(); @@ -510,6 +516,32 @@ bool SceneTree::process(float p_time) { return _quit; } +void SceneTree::process_tweens(float p_delta, bool p_physics) { + // This methods works similarly to how SceneTreeTimers are handled. + List<Ref<Tween>>::Element *L = tweens.back(); + + for (List<Ref<Tween>>::Element *E = tweens.front(); E;) { + List<Ref<Tween>>::Element *N = E->next(); + // Don't process if paused or process mode doesn't match. + if ((paused && E->get()->should_pause()) || (p_physics == (E->get()->get_process_mode() == Tween::TWEEN_PROCESS_IDLE))) { + if (E == L) { + break; + } + E = N; + continue; + } + + if (!E->get()->step(p_delta)) { + E->get()->set_valid(false); + tweens.erase(E); + } + if (E == L) { + break; + } + E = N; + } +} + void SceneTree::finalize() { _flush_delete_queue(); @@ -591,7 +623,7 @@ void SceneTree::set_quit_on_go_back(bool p_enable) { #ifdef TOOLS_ENABLED bool SceneTree::is_node_being_edited(const Node *p_node) const { - return Engine::get_singleton()->is_editor_hint() && edited_scene_root && (edited_scene_root->is_a_parent_of(p_node) || edited_scene_root == p_node); + return Engine::get_singleton()->is_editor_hint() && edited_scene_root && (edited_scene_root->is_ancestor_of(p_node) || edited_scene_root == p_node); } #endif @@ -1061,7 +1093,7 @@ Error SceneTree::change_scene(const String &p_path) { Error SceneTree::change_scene_to(const Ref<PackedScene> &p_scene) { Node *new_scene = nullptr; if (p_scene.is_valid()) { - new_scene = p_scene->instance(); + new_scene = p_scene->instantiate(); ERR_FAIL_COND_V(!new_scene, ERR_CANT_CREATE); } @@ -1082,31 +1114,32 @@ void SceneTree::add_current_scene(Node *p_current) { Ref<SceneTreeTimer> SceneTree::create_timer(float p_delay_sec, bool p_process_always) { Ref<SceneTreeTimer> stt; - stt.instance(); + stt.instantiate(); stt->set_process_always(p_process_always); stt->set_time_left(p_delay_sec); timers.push_back(stt); return stt; } -void SceneTree::_network_peer_connected(int p_id) { - emit_signal("network_peer_connected", p_id); -} - -void SceneTree::_network_peer_disconnected(int p_id) { - emit_signal("network_peer_disconnected", p_id); +Ref<Tween> SceneTree::create_tween() { + Ref<Tween> tween; + tween.instantiate(); + tween->set_valid(true); + tweens.push_back(tween); + return tween; } -void SceneTree::_connected_to_server() { - emit_signal("connected_to_server"); -} +Array SceneTree::get_processed_tweens() { + Array ret; + ret.resize(tweens.size()); -void SceneTree::_connection_failed() { - emit_signal("connection_failed"); -} + int i = 0; + for (List<Ref<Tween>>::Element *E = tweens.front(); E; E = E->next()) { + ret[i] = E->get(); + i++; + } -void SceneTree::_server_disconnected() { - emit_signal("server_disconnected"); + return ret; } Ref<MultiplayerAPI> SceneTree::get_multiplayer() const { @@ -1124,58 +1157,8 @@ bool SceneTree::is_multiplayer_poll_enabled() const { void SceneTree::set_multiplayer(Ref<MultiplayerAPI> p_multiplayer) { ERR_FAIL_COND(!p_multiplayer.is_valid()); - if (multiplayer.is_valid()) { - multiplayer->disconnect("network_peer_connected", callable_mp(this, &SceneTree::_network_peer_connected)); - multiplayer->disconnect("network_peer_disconnected", callable_mp(this, &SceneTree::_network_peer_disconnected)); - multiplayer->disconnect("connected_to_server", callable_mp(this, &SceneTree::_connected_to_server)); - multiplayer->disconnect("connection_failed", callable_mp(this, &SceneTree::_connection_failed)); - multiplayer->disconnect("server_disconnected", callable_mp(this, &SceneTree::_server_disconnected)); - } - multiplayer = p_multiplayer; multiplayer->set_root_node(root); - - multiplayer->connect("network_peer_connected", callable_mp(this, &SceneTree::_network_peer_connected)); - multiplayer->connect("network_peer_disconnected", callable_mp(this, &SceneTree::_network_peer_disconnected)); - multiplayer->connect("connected_to_server", callable_mp(this, &SceneTree::_connected_to_server)); - multiplayer->connect("connection_failed", callable_mp(this, &SceneTree::_connection_failed)); - multiplayer->connect("server_disconnected", callable_mp(this, &SceneTree::_server_disconnected)); -} - -void SceneTree::set_network_peer(const Ref<NetworkedMultiplayerPeer> &p_network_peer) { - multiplayer->set_network_peer(p_network_peer); -} - -Ref<NetworkedMultiplayerPeer> SceneTree::get_network_peer() const { - return multiplayer->get_network_peer(); -} - -bool SceneTree::is_network_server() const { - return multiplayer->is_network_server(); -} - -bool SceneTree::has_network_peer() const { - return multiplayer->has_network_peer(); -} - -int SceneTree::get_network_unique_id() const { - return multiplayer->get_network_unique_id(); -} - -Vector<int> SceneTree::get_network_connected_peers() const { - return multiplayer->get_network_connected_peers(); -} - -int SceneTree::get_rpc_sender_id() const { - return multiplayer->get_rpc_sender_id(); -} - -void SceneTree::set_refuse_new_network_connections(bool p_refuse) { - multiplayer->set_refuse_new_network_connections(p_refuse); -} - -bool SceneTree::is_refusing_new_network_connections() const { - return multiplayer->is_refusing_new_network_connections(); } void SceneTree::_bind_methods() { @@ -1197,6 +1180,8 @@ void SceneTree::_bind_methods() { ClassDB::bind_method(D_METHOD("is_paused"), &SceneTree::is_paused); ClassDB::bind_method(D_METHOD("create_timer", "time_sec", "process_always"), &SceneTree::create_timer, DEFVAL(true)); + ClassDB::bind_method(D_METHOD("create_tween"), &SceneTree::create_tween); + ClassDB::bind_method(D_METHOD("get_processed_tweens"), &SceneTree::get_processed_tweens); ClassDB::bind_method(D_METHOD("get_node_count"), &SceneTree::get_node_count); ClassDB::bind_method(D_METHOD("get_frame"), &SceneTree::get_frame); @@ -1242,24 +1227,12 @@ void SceneTree::_bind_methods() { ClassDB::bind_method(D_METHOD("get_multiplayer"), &SceneTree::get_multiplayer); ClassDB::bind_method(D_METHOD("set_multiplayer_poll_enabled", "enabled"), &SceneTree::set_multiplayer_poll_enabled); ClassDB::bind_method(D_METHOD("is_multiplayer_poll_enabled"), &SceneTree::is_multiplayer_poll_enabled); - ClassDB::bind_method(D_METHOD("set_network_peer", "peer"), &SceneTree::set_network_peer); - ClassDB::bind_method(D_METHOD("get_network_peer"), &SceneTree::get_network_peer); - ClassDB::bind_method(D_METHOD("is_network_server"), &SceneTree::is_network_server); - ClassDB::bind_method(D_METHOD("has_network_peer"), &SceneTree::has_network_peer); - ClassDB::bind_method(D_METHOD("get_network_connected_peers"), &SceneTree::get_network_connected_peers); - ClassDB::bind_method(D_METHOD("get_network_unique_id"), &SceneTree::get_network_unique_id); - ClassDB::bind_method(D_METHOD("get_rpc_sender_id"), &SceneTree::get_rpc_sender_id); - ClassDB::bind_method(D_METHOD("set_refuse_new_network_connections", "refuse"), &SceneTree::set_refuse_new_network_connections); - ClassDB::bind_method(D_METHOD("is_refusing_new_network_connections"), &SceneTree::is_refusing_new_network_connections); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "debug_collisions_hint"), "set_debug_collisions_hint", "is_debugging_collisions_hint"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "debug_navigation_hint"), "set_debug_navigation_hint", "is_debugging_navigation_hint"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "paused"), "set_pause", "is_paused"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "refuse_new_network_connections"), "set_refuse_new_network_connections", "is_refusing_new_network_connections"); - ADD_PROPERTY_DEFAULT("refuse_new_network_connections", false); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "edited_scene_root", PROPERTY_HINT_RESOURCE_TYPE, "Node", PROPERTY_USAGE_NONE), "set_edited_scene_root", "get_edited_scene_root"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "current_scene", PROPERTY_HINT_RESOURCE_TYPE, "Node", PROPERTY_USAGE_NONE), "set_current_scene", "get_current_scene"); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "network_peer", PROPERTY_HINT_RESOURCE_TYPE, "NetworkedMultiplayerPeer", PROPERTY_USAGE_NONE), "set_network_peer", "get_network_peer"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "root", PROPERTY_HINT_RESOURCE_TYPE, "Node", PROPERTY_USAGE_NONE), "", "get_root"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "multiplayer", PROPERTY_HINT_RESOURCE_TYPE, "MultiplayerAPI", PROPERTY_USAGE_NONE), "set_multiplayer", "get_multiplayer"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "multiplayer_poll"), "set_multiplayer_poll_enabled", "is_multiplayer_poll_enabled"); @@ -1275,11 +1248,6 @@ void SceneTree::_bind_methods() { ADD_SIGNAL(MethodInfo("physics_frame")); ADD_SIGNAL(MethodInfo("files_dropped", PropertyInfo(Variant::PACKED_STRING_ARRAY, "files"), PropertyInfo(Variant::INT, "screen"))); - ADD_SIGNAL(MethodInfo("network_peer_connected", PropertyInfo(Variant::INT, "id"))); - ADD_SIGNAL(MethodInfo("network_peer_disconnected", PropertyInfo(Variant::INT, "id"))); - ADD_SIGNAL(MethodInfo("connected_to_server")); - ADD_SIGNAL(MethodInfo("connection_failed")); - ADD_SIGNAL(MethodInfo("server_disconnected")); BIND_ENUM_CONSTANT(GROUP_CALL_DEFAULT); BIND_ENUM_CONSTANT(GROUP_CALL_REVERSE); diff --git a/scene/main/scene_tree.h b/scene/main/scene_tree.h index 78c4c14e97..0be0e185a5 100644 --- a/scene/main/scene_tree.h +++ b/scene/main/scene_tree.h @@ -47,6 +47,7 @@ class Window; class Material; class Mesh; class SceneDebugger; +class Tween; class SceneTreeTimer : public RefCounted { GDCLASS(SceneTreeTimer, RefCounted); @@ -151,19 +152,13 @@ private: //void _call_group(uint32_t p_call_flags,const StringName& p_group,const StringName& p_function,const Variant& p_arg1,const Variant& p_arg2); List<Ref<SceneTreeTimer>> timers; + List<Ref<Tween>> tweens; ///network/// Ref<MultiplayerAPI> multiplayer; bool multiplayer_poll = true; - void _network_peer_connected(int p_id); - void _network_peer_disconnected(int p_id); - - void _connected_to_server(); - void _connection_failed(); - void _server_disconnected(); - static SceneTree *singleton; friend class Node; @@ -171,6 +166,7 @@ private: void node_added(Node *p_node); void node_removed(Node *p_node); void node_renamed(Node *p_node); + void process_tweens(float p_delta, bool p_physics_frame); Group *add_to_group(const StringName &p_group, Node *p_node); void remove_from_group(const StringName &p_group, Node *p_node); @@ -318,6 +314,8 @@ public: Error reload_current_scene(); Ref<SceneTreeTimer> create_timer(float p_delay_sec, bool p_process_always = true); + Ref<Tween> create_tween(); + Array get_processed_tweens(); //used by Main::start, don't use otherwise void add_current_scene(Node *p_current); @@ -332,16 +330,6 @@ public: void set_multiplayer_poll_enabled(bool p_enabled); bool is_multiplayer_poll_enabled() const; void set_multiplayer(Ref<MultiplayerAPI> p_multiplayer); - void set_network_peer(const Ref<NetworkedMultiplayerPeer> &p_network_peer); - Ref<NetworkedMultiplayerPeer> get_network_peer() const; - bool is_network_server() const; - bool has_network_peer() const; - int get_network_unique_id() const; - Vector<int> get_network_connected_peers() const; - int get_rpc_sender_id() const; - - void set_refuse_new_network_connections(bool p_refuse); - bool is_refusing_new_network_connections() const; static void add_idle_callback(IdleCallback p_callback); diff --git a/scene/main/shader_globals_override.cpp b/scene/main/shader_globals_override.cpp index 3d65c12cb7..d22a6b2875 100644 --- a/scene/main/shader_globals_override.cpp +++ b/scene/main/shader_globals_override.cpp @@ -63,7 +63,12 @@ bool ShaderGlobalsOverride::_set(const StringName &p_name, const Variant &p_valu if (o) { o->override = p_value; if (active) { - RS::get_singleton()->global_variable_set_override(*r, p_value); + if (o->override.get_type() == Variant::OBJECT) { + RID tex_rid = p_value; + RS::get_singleton()->global_variable_set_override(*r, tex_rid); + } else { + RS::get_singleton()->global_variable_set_override(*r, p_value); + } } o->in_use = p_value.get_type() != Variant::NIL; return true; @@ -228,7 +233,12 @@ void ShaderGlobalsOverride::_activate() { while ((K = overrides.next(K))) { Override *o = overrides.getptr(*K); if (o->in_use && o->override.get_type() != Variant::NIL) { - RS::get_singleton()->global_variable_set_override(*K, o->override); + if (o->override.get_type() == Variant::OBJECT) { + RID tex_rid = o->override; + RS::get_singleton()->global_variable_set_override(*K, tex_rid); + } else { + RS::get_singleton()->global_variable_set_override(*K, o->override); + } } } diff --git a/scene/main/timer.cpp b/scene/main/timer.cpp index a5ceec9c8b..f52237251c 100644 --- a/scene/main/timer.cpp +++ b/scene/main/timer.cpp @@ -37,7 +37,7 @@ void Timer::_notification(int p_what) { case NOTIFICATION_READY: { if (autostart) { #ifdef TOOLS_ENABLED - if (Engine::get_singleton()->is_editor_hint() && get_tree()->get_edited_scene_root() && (get_tree()->get_edited_scene_root() == this || get_tree()->get_edited_scene_root()->is_a_parent_of(this))) { + if (Engine::get_singleton()->is_editor_hint() && get_tree()->get_edited_scene_root() && (get_tree()->get_edited_scene_root() == this || get_tree()->get_edited_scene_root()->is_ancestor_of(this))) { break; } #endif @@ -207,7 +207,7 @@ void Timer::_bind_methods() { ADD_SIGNAL(MethodInfo("timeout")); ADD_PROPERTY(PropertyInfo(Variant::INT, "process_callback", PROPERTY_HINT_ENUM, "Physics,Idle"), "set_timer_process_callback", "get_timer_process_callback"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "wait_time", PROPERTY_HINT_EXP_RANGE, "0.001,4096,0.001,or_greater"), "set_wait_time", "get_wait_time"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "wait_time", PROPERTY_HINT_RANGE, "0.001,4096,0.001,or_greater,exp"), "set_wait_time", "get_wait_time"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "one_shot"), "set_one_shot", "is_one_shot"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "autostart"), "set_autostart", "has_autostart"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "paused", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_paused", "is_paused"); diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 84a6dbe889..9a2e0c5230 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -594,7 +594,7 @@ void Viewport::_process_picking() { if (!has_mouse_event) { Ref<InputEventMouseMotion> mm; - mm.instance(); + mm.instantiate(); mm->set_device(InputEvent::DEVICE_ID_INTERNAL); mm->set_global_position(physics_last_mousepos); @@ -644,9 +644,9 @@ void Viewport::_process_picking() { physics_last_mouse_state.meta = mb->is_meta_pressed(); if (mb->is_pressed()) { - physics_last_mouse_state.mouse_mask |= (1 << (mb->get_button_index() - 1)); + physics_last_mouse_state.mouse_mask |= (MouseButton)(1 << (mb->get_button_index() - 1)); } else { - physics_last_mouse_state.mouse_mask &= ~(1 << (mb->get_button_index() - 1)); + physics_last_mouse_state.mouse_mask &= (MouseButton) ~(1 << (mb->get_button_index() - 1)); // If touch mouse raised, assume we don't know last mouse pos until new events come if (mb->get_device() == InputEvent::DEVICE_ID_TOUCH_MOUSE) { @@ -929,6 +929,15 @@ bool Viewport::is_audio_listener_2d() const { return audio_listener_2d; } +void Viewport::set_disable_3d(bool p_disable) { + disable_3d = p_disable; + RenderingServer::get_singleton()->viewport_set_disable_3d(viewport, disable_3d); +} + +bool Viewport::is_3d_disabled() const { + return disable_3d; +} + void Viewport::enable_canvas_transform_override(bool p_enable) { if (override_canvas_transform == p_enable) { return; @@ -1746,7 +1755,7 @@ Control *Viewport::_gui_find_control_at_pos(CanvasItem *p_node, const Point2 &p_ Control *c = Object::cast_to<Control>(p_node); - if (!c || !c->clips_input() || c->has_point(matrix.affine_inverse().xform(p_global))) { + if (!c || !c->is_clipping_contents() || c->has_point(matrix.affine_inverse().xform(p_global))) { for (int i = p_node->get_child_count() - 1; i >= 0; i--) { CanvasItem *ci = Object::cast_to<CanvasItem>(p_node->get_child(i)); if (!ci || ci->is_set_as_top_level()) { @@ -1770,7 +1779,7 @@ Control *Viewport::_gui_find_control_at_pos(CanvasItem *p_node, const Point2 &p_ } Control *drag_preview = _gui_get_drag_preview(); - if (!drag_preview || (c != drag_preview && !drag_preview->is_a_parent_of(c))) { + if (!drag_preview || (c != drag_preview && !drag_preview->is_ancestor_of(c))) { r_inv_xform = matrix; return c; } @@ -2585,10 +2594,10 @@ void Viewport::_drop_mouse_focus() { for (int i = 0; i < 3; i++) { if (mask & (1 << i)) { Ref<InputEventMouseButton> mb; - mb.instance(); + mb.instantiate(); mb->set_position(c->get_local_mouse_position()); mb->set_global_position(c->get_local_mouse_position()); - mb->set_button_index(i + 1); + mb->set_button_index(MouseButton(i + 1)); mb->set_pressed(false); c->call(SceneStringNames::get_singleton()->_gui_input, mb); } @@ -2661,12 +2670,12 @@ void Viewport::_post_gui_grab_click_focus() { for (int i = 0; i < 3; i++) { if (mask & (1 << i)) { Ref<InputEventMouseButton> mb; - mb.instance(); + mb.instantiate(); //send unclick mb->set_position(click); - mb->set_button_index(i + 1); + mb->set_button_index(MouseButton(i + 1)); mb->set_pressed(false); gui.mouse_focus->call(SceneStringNames::get_singleton()->_gui_input, mb); } @@ -2679,12 +2688,12 @@ void Viewport::_post_gui_grab_click_focus() { for (int i = 0; i < 3; i++) { if (mask & (1 << i)) { Ref<InputEventMouseButton> mb; - mb.instance(); + mb.instantiate(); //send click mb->set_position(click); - mb->set_button_index(i + 1); + mb->set_button_index(MouseButton(i + 1)); mb->set_pressed(true); gui.mouse_focus->call_deferred(SceneStringNames::get_singleton()->_gui_input, mb); } @@ -3023,7 +3032,7 @@ void Viewport::input(const Ref<InputEvent> &p_event, bool p_local_coords) { return; } - if (Engine::get_singleton()->is_editor_hint() && get_tree()->get_edited_scene_root() && get_tree()->get_edited_scene_root()->is_a_parent_of(this)) { + if (Engine::get_singleton()->is_editor_hint() && get_tree()->get_edited_scene_root() && get_tree()->get_edited_scene_root()->is_ancestor_of(this)) { return; } @@ -3065,7 +3074,7 @@ void Viewport::unhandled_input(const Ref<InputEvent> &p_event, bool p_local_coor return; } - if (Engine::get_singleton()->is_editor_hint() && get_tree()->get_edited_scene_root() && get_tree()->get_edited_scene_root()->is_a_parent_of(this)) { + if (Engine::get_singleton()->is_editor_hint() && get_tree()->get_edited_scene_root() && get_tree()->get_edited_scene_root()->is_ancestor_of(this)) { return; } @@ -3259,8 +3268,8 @@ Viewport::DebugDraw Viewport::get_debug_draw() const { return debug_draw; } -int Viewport::get_render_info(RenderInfo p_info) { - return RS::get_singleton()->viewport_get_render_info(viewport, RS::ViewportRenderInfo(p_info)); +int Viewport::get_render_info(RenderInfoType p_type, RenderInfo p_info) { + return RS::get_singleton()->viewport_get_render_info(viewport, RS::ViewportRenderInfoType(p_type), RS::ViewportRenderInfo(p_info)); } void Viewport::set_snap_controls_to_pixels(bool p_enable) { @@ -3490,7 +3499,7 @@ void Viewport::_bind_methods() { ClassDB::bind_method(D_METHOD("set_debug_draw", "debug_draw"), &Viewport::set_debug_draw); ClassDB::bind_method(D_METHOD("get_debug_draw"), &Viewport::get_debug_draw); - ClassDB::bind_method(D_METHOD("get_render_info", "info"), &Viewport::get_render_info); + ClassDB::bind_method(D_METHOD("get_render_info", "type", "info"), &Viewport::get_render_info); ClassDB::bind_method(D_METHOD("set_use_xr", "use"), &Viewport::set_use_xr); ClassDB::bind_method(D_METHOD("is_using_xr"), &Viewport::is_using_xr); @@ -3516,6 +3525,9 @@ void Viewport::_bind_methods() { ClassDB::bind_method(D_METHOD("set_as_audio_listener_2d", "enable"), &Viewport::set_as_audio_listener_2d); ClassDB::bind_method(D_METHOD("is_audio_listener_2d"), &Viewport::is_audio_listener_2d); + ClassDB::bind_method(D_METHOD("set_disable_3d", "disable"), &Viewport::set_disable_3d); + ClassDB::bind_method(D_METHOD("is_3d_disabled"), &Viewport::is_3d_disabled); + ClassDB::bind_method(D_METHOD("get_mouse_position"), &Viewport::get_mouse_position); ClassDB::bind_method(D_METHOD("warp_mouse", "to_position"), &Viewport::warp_mouse); @@ -3582,6 +3594,7 @@ void Viewport::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "snap_2d_transforms_to_pixel"), "set_snap_2d_transforms_to_pixel", "is_snap_2d_transforms_to_pixel_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "snap_2d_vertices_to_pixel"), "set_snap_2d_vertices_to_pixel", "is_snap_2d_vertices_to_pixel_enabled"); ADD_GROUP("Rendering", ""); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "disable_3d"), "set_disable_3d", "is_3d_disabled"); ADD_PROPERTY(PropertyInfo(Variant::INT, "msaa", PROPERTY_HINT_ENUM, "Disabled (Fastest),2x (Fast),4x (Average),8x (Slow),16x (Slower)"), "set_msaa", "get_msaa"); ADD_PROPERTY(PropertyInfo(Variant::INT, "screen_space_aa", PROPERTY_HINT_ENUM, "Disabled (Fastest),FXAA (Fast)"), "set_screen_space_aa", "get_screen_space_aa"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_debanding"), "set_use_debanding", "is_using_debanding"); @@ -3637,13 +3650,14 @@ void Viewport::_bind_methods() { BIND_ENUM_CONSTANT(SCREEN_SPACE_AA_MAX); BIND_ENUM_CONSTANT(RENDER_INFO_OBJECTS_IN_FRAME); - BIND_ENUM_CONSTANT(RENDER_INFO_VERTICES_IN_FRAME); - BIND_ENUM_CONSTANT(RENDER_INFO_MATERIAL_CHANGES_IN_FRAME); - BIND_ENUM_CONSTANT(RENDER_INFO_SHADER_CHANGES_IN_FRAME); - BIND_ENUM_CONSTANT(RENDER_INFO_SURFACE_CHANGES_IN_FRAME); + BIND_ENUM_CONSTANT(RENDER_INFO_PRIMITIVES_IN_FRAME); BIND_ENUM_CONSTANT(RENDER_INFO_DRAW_CALLS_IN_FRAME); BIND_ENUM_CONSTANT(RENDER_INFO_MAX); + BIND_ENUM_CONSTANT(RENDER_INFO_TYPE_VISIBLE); + BIND_ENUM_CONSTANT(RENDER_INFO_TYPE_SHADOW); + BIND_ENUM_CONSTANT(RENDER_INFO_TYPE_MAX); + BIND_ENUM_CONSTANT(DEBUG_DRAW_DISABLED); BIND_ENUM_CONSTANT(DEBUG_DRAW_UNSHADED); BIND_ENUM_CONSTANT(DEBUG_DRAW_LIGHTING); @@ -3698,7 +3712,7 @@ Viewport::Viewport() { viewport = RenderingServer::get_singleton()->viewport_create(); texture_rid = RenderingServer::get_singleton()->viewport_get_texture(viewport); - default_texture.instance(); + default_texture.instantiate(); default_texture->vp = const_cast<Viewport *>(this); viewport_textures.insert(default_texture.ptr()); default_texture->proxy = RS::get_singleton()->texture_proxy_create(texture_rid); diff --git a/scene/main/viewport.h b/scene/main/viewport.h index d905e44a82..0f3bb8707d 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -115,14 +115,17 @@ public: enum RenderInfo { RENDER_INFO_OBJECTS_IN_FRAME, - RENDER_INFO_VERTICES_IN_FRAME, - RENDER_INFO_MATERIAL_CHANGES_IN_FRAME, - RENDER_INFO_SHADER_CHANGES_IN_FRAME, - RENDER_INFO_SURFACE_CHANGES_IN_FRAME, + RENDER_INFO_PRIMITIVES_IN_FRAME, RENDER_INFO_DRAW_CALLS_IN_FRAME, RENDER_INFO_MAX }; + enum RenderInfoType { + RENDER_INFO_TYPE_VISIBLE, + RENDER_INFO_TYPE_SHADOW, + RENDER_INFO_TYPE_MAX + }; + enum DebugDraw { DEBUG_DRAW_DISABLED, DEBUG_DRAW_UNSHADED, @@ -288,6 +291,8 @@ private: void _update_listener(); void _update_listener_2d(); + bool disable_3d = false; + void _propagate_enter_world(Node *p_node); void _propagate_exit_world(Node *p_node); void _propagate_viewport_notification(Node *p_node, int p_what); @@ -503,6 +508,9 @@ public: void set_as_audio_listener_2d(bool p_enable); bool is_audio_listener_2d() const; + void set_disable_3d(bool p_disable); + bool is_3d_disabled() const; + void update_canvas_items(); Rect2 get_visible_rect() const; @@ -591,7 +599,7 @@ public: void set_debug_draw(DebugDraw p_debug_draw); DebugDraw get_debug_draw() const; - int get_render_info(RenderInfo p_info); + int get_render_info(RenderInfoType p_type, RenderInfo p_info); void set_snap_controls_to_pixels(bool p_enable); bool is_snap_controls_to_pixels_enabled() const; @@ -694,6 +702,7 @@ VARIANT_ENUM_CAST(Viewport::SDFScale); VARIANT_ENUM_CAST(Viewport::SDFOversize); VARIANT_ENUM_CAST(SubViewport::ClearMode); VARIANT_ENUM_CAST(Viewport::RenderInfo); +VARIANT_ENUM_CAST(Viewport::RenderInfoType); VARIANT_ENUM_CAST(Viewport::DefaultCanvasItemTextureFilter); VARIANT_ENUM_CAST(Viewport::DefaultCanvasItemTextureRepeat); diff --git a/scene/main/window.cpp b/scene/main/window.cpp index d793be1869..9299f8d6be 100644 --- a/scene/main/window.cpp +++ b/scene/main/window.cpp @@ -227,7 +227,8 @@ void Window::_make_window() { } } - window_id = DisplayServer::get_singleton()->create_sub_window(DisplayServer::WindowMode(mode), f, Rect2i(position, size)); + DisplayServer::VSyncMode vsync_mode = DisplayServer::get_singleton()->window_get_vsync_mode(DisplayServer::MAIN_WINDOW_ID); + window_id = DisplayServer::get_singleton()->create_sub_window(DisplayServer::WindowMode(mode), vsync_mode, f, Rect2i(position, size)); ERR_FAIL_COND(window_id == DisplayServer::INVALID_WINDOW_ID); DisplayServer::get_singleton()->window_set_current_screen(current_screen, window_id); DisplayServer::get_singleton()->window_set_max_size(max_size, window_id); @@ -1393,6 +1394,8 @@ void Window::_bind_methods() { ClassDB::bind_method(D_METHOD("is_embedded"), &Window::is_embedded); + ClassDB::bind_method(D_METHOD("get_contents_minimum_size"), &Window::get_contents_minimum_size); + ClassDB::bind_method(D_METHOD("set_content_scale_size", "size"), &Window::set_content_scale_size); ClassDB::bind_method(D_METHOD("get_content_scale_size"), &Window::get_content_scale_size); diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp index 2a97ae3acf..ea0df685a1 100644 --- a/scene/register_scene_types.cpp +++ b/scene/register_scene_types.cpp @@ -31,6 +31,7 @@ #include "register_scene_types.h" #include "core/config/project_settings.h" +#include "core/extension/native_extension_manager.h" #include "core/object/class_db.h" #include "core/os/os.h" #include "scene/2d/animated_sprite_2d.h" @@ -146,6 +147,7 @@ #include "scene/resources/font.h" #include "scene/resources/gradient.h" #include "scene/resources/height_map_shape_3d.h" +#include "scene/resources/immediate_mesh.h" #include "scene/resources/line_shape_2d.h" #include "scene/resources/material.h" #include "scene/resources/mesh.h" @@ -203,7 +205,6 @@ #include "scene/3d/decal.h" #include "scene/3d/gpu_particles_3d.h" #include "scene/3d/gpu_particles_collision_3d.h" -#include "scene/3d/immediate_geometry_3d.h" #include "scene/3d/light_3d.h" #include "scene/3d/lightmap_gi.h" #include "scene/3d/lightmap_probe.h" @@ -260,33 +261,33 @@ void register_scene_types() { Node::init_node_hrcr(); - resource_loader_font.instance(); + resource_loader_font.instantiate(); ResourceLoader::add_resource_format_loader(resource_loader_font); #ifndef DISABLE_DEPRECATED - resource_loader_compat_font.instance(); + resource_loader_compat_font.instantiate(); ResourceLoader::add_resource_format_loader(resource_loader_compat_font); #endif /* DISABLE_DEPRECATED */ - resource_loader_stream_texture.instance(); + resource_loader_stream_texture.instantiate(); ResourceLoader::add_resource_format_loader(resource_loader_stream_texture); - resource_loader_texture_layered.instance(); + resource_loader_texture_layered.instantiate(); ResourceLoader::add_resource_format_loader(resource_loader_texture_layered); - resource_loader_texture_3d.instance(); + resource_loader_texture_3d.instantiate(); ResourceLoader::add_resource_format_loader(resource_loader_texture_3d); - resource_saver_text.instance(); + resource_saver_text.instantiate(); ResourceSaver::add_resource_format_saver(resource_saver_text, true); - resource_loader_text.instance(); + resource_loader_text.instantiate(); ResourceLoader::add_resource_format_loader(resource_loader_text, true); - resource_saver_shader.instance(); + resource_saver_shader.instantiate(); ResourceSaver::add_resource_format_saver(resource_saver_shader, true); - resource_loader_shader.instance(); + resource_loader_shader.instantiate(); ResourceLoader::add_resource_format_loader(resource_loader_shader, true); OS::get_singleton()->yield(); //may take time to init @@ -407,6 +408,11 @@ void register_scene_types() { ClassDB::register_class<AnimationPlayer>(); ClassDB::register_class<Tween>(); + ClassDB::register_virtual_class<Tweener>(); + ClassDB::register_class<PropertyTweener>(); + ClassDB::register_class<IntervalTweener>(); + ClassDB::register_class<CallbackTweener>(); + ClassDB::register_class<MethodTweener>(); ClassDB::register_class<AnimationTree>(); ClassDB::register_class<AnimationNode>(); @@ -453,7 +459,6 @@ void register_scene_types() { ClassDB::register_class<MeshInstance3D>(); ClassDB::register_class<OccluderInstance3D>(); ClassDB::register_class<Occluder3D>(); - ClassDB::register_class<ImmediateGeometry3D>(); ClassDB::register_virtual_class<SpriteBase3D>(); ClassDB::register_class<Sprite3D>(); ClassDB::register_class<AnimatedSprite3D>(); @@ -581,6 +586,7 @@ void register_scene_types() { ClassDB::register_class<VisualShaderNodeTransformDecompose>(); ClassDB::register_class<VisualShaderNodeTexture>(); ClassDB::register_class<VisualShaderNodeCurveTexture>(); + ClassDB::register_class<VisualShaderNodeCurve3Texture>(); ClassDB::register_virtual_class<VisualShaderNodeSample3D>(); ClassDB::register_class<VisualShaderNodeTexture2DArray>(); ClassDB::register_class<VisualShaderNodeTexture3D>(); @@ -712,6 +718,7 @@ void register_scene_types() { ClassDB::register_virtual_class<Mesh>(); ClassDB::register_class<ArrayMesh>(); + ClassDB::register_class<ImmediateMesh>(); ClassDB::register_class<MultiMesh>(); ClassDB::register_class<SurfaceTool>(); ClassDB::register_class<MeshDataTool>(); @@ -768,6 +775,7 @@ void register_scene_types() { ClassDB::register_class<AtlasTexture>(); ClassDB::register_class<MeshTexture>(); ClassDB::register_class<CurveTexture>(); + ClassDB::register_class<Curve3Texture>(); ClassDB::register_class<GradientTexture>(); ClassDB::register_class<ProxyTexture>(); ClassDB::register_class<AnimatedTexture>(); @@ -930,14 +938,12 @@ void register_scene_types() { ClassDB::add_compatibility_class("Physics2DServerSW", "PhysicsServer2DSW"); ClassDB::add_compatibility_class("Physics2DServer", "PhysicsServer2D"); ClassDB::add_compatibility_class("Physics2DShapeQueryParameters", "PhysicsShapeQueryParameters2D"); - ClassDB::add_compatibility_class("Physics2DShapeQueryResult", "PhysicsShapeQueryResult2D"); ClassDB::add_compatibility_class("Physics2DTestMotionResult", "PhysicsTestMotionResult2D"); ClassDB::add_compatibility_class("PhysicsBody", "PhysicsBody3D"); ClassDB::add_compatibility_class("PhysicsDirectBodyState", "PhysicsDirectBodyState3D"); ClassDB::add_compatibility_class("PhysicsDirectSpaceState", "PhysicsDirectSpaceState3D"); ClassDB::add_compatibility_class("PhysicsServer", "PhysicsServer3D"); ClassDB::add_compatibility_class("PhysicsShapeQueryParameters", "PhysicsShapeQueryParameters3D"); - ClassDB::add_compatibility_class("PhysicsShapeQueryResult", "PhysicsShapeQueryResult3D"); ClassDB::add_compatibility_class("PinJoint", "PinJoint3D"); ClassDB::add_compatibility_class("PlaneShape", "WorldMarginShape3D"); ClassDB::add_compatibility_class("ProceduralSky", "Sky"); @@ -1035,9 +1041,13 @@ void register_scene_types() { } } SceneDebugger::initialize(); + + NativeExtensionManager::get_singleton()->initialize_extensions(NativeExtension::INITIALIZATION_LEVEL_SCENE); } void unregister_scene_types() { + NativeExtensionManager::get_singleton()->deinitialize_extensions(NativeExtension::INITIALIZATION_LEVEL_SCENE); + SceneDebugger::deinitialize(); clear_default_theme(); diff --git a/scene/resources/audio_stream_sample.cpp b/scene/resources/audio_stream_sample.cpp index 81062feb46..8ffd2df112 100644 --- a/scene/resources/audio_stream_sample.cpp +++ b/scene/resources/audio_stream_sample.cpp @@ -596,7 +596,7 @@ Error AudioStreamSample::save_to_wav(const String &p_path) { Ref<AudioStreamPlayback> AudioStreamSample::instance_playback() { Ref<AudioStreamPlaybackSample> sample; - sample.instance(); + sample.instantiate(); sample->base = Ref<AudioStreamSample>(this); return sample; } diff --git a/scene/resources/bit_map.cpp b/scene/resources/bit_map.cpp index 0ffeb8a5bf..de557494c3 100644 --- a/scene/resources/bit_map.cpp +++ b/scene/resources/bit_map.cpp @@ -487,7 +487,7 @@ Vector<Vector<Vector2>> BitMap::clip_opaque_to_polygons(const Rect2 &p_rect, flo Point2i from; Ref<BitMap> fill; - fill.instance(); + fill.instantiate(); fill->create(get_size()); Vector<Vector<Vector2>> polygons; @@ -525,7 +525,7 @@ void BitMap::grow_mask(int p_pixels, const Rect2 &p_rect) { Rect2i r = Rect2i(0, 0, width, height).intersection(p_rect); Ref<BitMap> copy; - copy.instance(); + copy.instantiate(); copy->create(get_size()); copy->bitmask = bitmask; @@ -604,7 +604,7 @@ Array BitMap::_opaque_to_polygons_bind(const Rect2 &p_rect, float p_epsilon) con void BitMap::resize(const Size2 &p_new_size) { Ref<BitMap> new_bitmap; - new_bitmap.instance(); + new_bitmap.instantiate(); new_bitmap->create(p_new_size); int lw = MIN(width, p_new_size.width); int lh = MIN(height, p_new_size.height); @@ -621,7 +621,7 @@ void BitMap::resize(const Size2 &p_new_size) { Ref<Image> BitMap::convert_to_image() const { Ref<Image> image; - image.instance(); + image.instantiate(); image->create(width, height, false, Image::FORMAT_L8); for (int i = 0; i < width; i++) { diff --git a/scene/resources/camera_effects.cpp b/scene/resources/camera_effects.cpp index 34c6bc05bc..b633196424 100644 --- a/scene/resources/camera_effects.cpp +++ b/scene/resources/camera_effects.cpp @@ -175,11 +175,11 @@ void CameraEffects::_bind_methods() { ADD_GROUP("DOF Blur", "dof_blur_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "dof_blur_far_enabled"), "set_dof_blur_far_enabled", "is_dof_blur_far_enabled"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "dof_blur_far_distance", PROPERTY_HINT_EXP_RANGE, "0.01,8192,0.01"), "set_dof_blur_far_distance", "get_dof_blur_far_distance"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "dof_blur_far_transition", PROPERTY_HINT_EXP_RANGE, "0.01,8192,0.01"), "set_dof_blur_far_transition", "get_dof_blur_far_transition"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "dof_blur_far_distance", PROPERTY_HINT_RANGE, "0.01,8192,0.01,exp"), "set_dof_blur_far_distance", "get_dof_blur_far_distance"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "dof_blur_far_transition", PROPERTY_HINT_RANGE, "0.01,8192,0.01,exp"), "set_dof_blur_far_transition", "get_dof_blur_far_transition"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "dof_blur_near_enabled"), "set_dof_blur_near_enabled", "is_dof_blur_near_enabled"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "dof_blur_near_distance", PROPERTY_HINT_EXP_RANGE, "0.01,8192,0.01"), "set_dof_blur_near_distance", "get_dof_blur_near_distance"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "dof_blur_near_transition", PROPERTY_HINT_EXP_RANGE, "0.01,8192,0.01"), "set_dof_blur_near_transition", "get_dof_blur_near_transition"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "dof_blur_near_distance", PROPERTY_HINT_RANGE, "0.01,8192,0.01,exp"), "set_dof_blur_near_distance", "get_dof_blur_near_distance"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "dof_blur_near_transition", PROPERTY_HINT_RANGE, "0.01,8192,0.01,exp"), "set_dof_blur_near_transition", "get_dof_blur_near_transition"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "dof_blur_amount", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_dof_blur_amount", "get_dof_blur_amount"); // Override exposure diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index a4228d48b4..5464a46df4 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -559,7 +559,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const // ScrollContainer Ref<StyleBoxEmpty> empty; - empty.instance(); + empty.instantiate(); theme->set_stylebox("bg", "ScrollContainer", empty); // WindowDialog @@ -979,7 +979,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const void make_default_theme(bool p_hidpi, Ref<Font> p_font) { Ref<Theme> t; - t.instance(); + t.instantiate(); Ref<StyleBox> default_style; Ref<Texture2D> default_icon; @@ -993,10 +993,10 @@ void make_default_theme(bool p_hidpi, Ref<Font> p_font) { // The default DynamicFont is chosen to have a small file size since it's // embedded in both editor and export template binaries. Ref<Font> dynamic_font; - dynamic_font.instance(); + dynamic_font.instantiate(); Ref<FontData> dynamic_font_data; - dynamic_font_data.instance(); + dynamic_font_data.instantiate(); dynamic_font_data->load_memory(_font_OpenSans_SemiBold, _font_OpenSans_SemiBold_size, "ttf", default_font_size); dynamic_font->add_data(dynamic_font_data); diff --git a/scene/resources/environment.cpp b/scene/resources/environment.cpp index c04b271d81..8550af8bcb 100644 --- a/scene/resources/environment.cpp +++ b/scene/resources/environment.cpp @@ -1329,7 +1329,7 @@ void Environment::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "volumetric_fog_density", PROPERTY_HINT_RANGE, "0,1,0.0001,or_greater"), "set_volumetric_fog_density", "get_volumetric_fog_density"); ADD_PROPERTY(PropertyInfo(Variant::COLOR, "volumetric_fog_light", PROPERTY_HINT_COLOR_NO_ALPHA), "set_volumetric_fog_light", "get_volumetric_fog_light"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "volumetric_fog_light_energy", PROPERTY_HINT_RANGE, "0,1024,0.01,or_greater"), "set_volumetric_fog_light_energy", "get_volumetric_fog_light_energy"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "volumetric_fog_gi_inject", PROPERTY_HINT_EXP_RANGE, "0.00,16,0.01"), "set_volumetric_fog_gi_inject", "get_volumetric_fog_gi_inject"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "volumetric_fog_gi_inject", PROPERTY_HINT_RANGE, "0.00,16,0.01,exp"), "set_volumetric_fog_gi_inject", "get_volumetric_fog_gi_inject"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "volumetric_fog_length", PROPERTY_HINT_RANGE, "0,1024,0.01,or_greater"), "set_volumetric_fog_length", "get_volumetric_fog_length"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "volumetric_fog_detail_spread", PROPERTY_HINT_EXP_EASING, "0.01,16,0.01"), "set_volumetric_fog_detail_spread", "get_volumetric_fog_detail_spread"); ADD_SUBGROUP("Temporal Reprojection", "volumetric_fog_temporal_reprojection_"); diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp index 6f87c524d8..032171847d 100644 --- a/scene/resources/font.cpp +++ b/scene/resources/font.cpp @@ -813,7 +813,7 @@ Size2 Font::get_string_size(const String &p_text, int p_size) const { if (cache.has(hash)) { buffer = cache.get(hash); } else { - buffer.instance(); + buffer.instantiate(); int size = p_size <= 0 ? data[0]->get_base_size() : p_size; buffer->add_string(p_text, Ref<Font>(this), size, Dictionary(), TranslationServer::get_singleton()->get_tool_locale()); cache.insert(hash, buffer); @@ -838,7 +838,7 @@ Size2 Font::get_multiline_string_size(const String &p_text, float p_width, int p if (cache_wrap.has(wrp_hash)) { lines_buffer = cache_wrap.get(wrp_hash); } else { - lines_buffer.instance(); + lines_buffer.instantiate(); int size = p_size <= 0 ? data[0]->get_base_size() : p_size; lines_buffer->add_string(p_text, Ref<Font>(this), size, Dictionary(), TranslationServer::get_singleton()->get_tool_locale()); lines_buffer->set_width(p_width); @@ -870,7 +870,7 @@ void Font::draw_string(RID p_canvas_item, const Point2 &p_pos, const String &p_t if (cache.has(hash)) { buffer = cache.get(hash); } else { - buffer.instance(); + buffer.instantiate(); int size = p_size <= 0 ? data[0]->get_base_size() : p_size; buffer->add_string(p_text, Ref<Font>(this), size, Dictionary(), TranslationServer::get_singleton()->get_tool_locale()); cache.insert(hash, buffer); @@ -905,7 +905,7 @@ void Font::draw_multiline_string(RID p_canvas_item, const Point2 &p_pos, const S if (cache_wrap.has(wrp_hash)) { lines_buffer = cache_wrap.get(wrp_hash); } else { - lines_buffer.instance(); + lines_buffer.instantiate(); int size = p_size <= 0 ? data[0]->get_base_size() : p_size; lines_buffer->add_string(p_text, Ref<Font>(this), size, Dictionary(), TranslationServer::get_singleton()->get_tool_locale()); lines_buffer->set_width(p_width); @@ -1041,7 +1041,7 @@ RES ResourceFormatLoaderFont::load(const String &p_path, const String &p_origina } Ref<FontData> dfont; - dfont.instance(); + dfont.instantiate(); dfont->load_resource(p_path); if (r_error) { @@ -1096,11 +1096,11 @@ RES ResourceFormatLoaderCompatFont::load(const String &p_path, const String &p_o } Ref<FontData> dfont; - dfont.instance(); + dfont.instantiate(); dfont->load_resource(p_path); Ref<Font> font; - font.instance(); + font.instantiate(); font->add_data(dfont); if (r_error) { diff --git a/scene/resources/immediate_mesh.cpp b/scene/resources/immediate_mesh.cpp new file mode 100644 index 0000000000..ebe65605f8 --- /dev/null +++ b/scene/resources/immediate_mesh.cpp @@ -0,0 +1,416 @@ +/*************************************************************************/ +/* immediate_mesh.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "immediate_mesh.h" + +void ImmediateMesh::surface_begin(PrimitiveType p_primitive, const Ref<Material> &p_material) { + ERR_FAIL_COND_MSG(surface_active, "Already creating a new surface."); + active_surface_data.primitive = p_primitive; + active_surface_data.material = p_material; + surface_active = true; +} +void ImmediateMesh::surface_set_color(const Color &p_color) { + ERR_FAIL_COND_MSG(!surface_active, "Not creating any surface. Use surface_begin() to do it."); + + if (!uses_colors) { + colors.resize(vertices.size()); + for (uint32_t i = 0; i < colors.size(); i++) { + colors[i] = p_color; + } + uses_colors = true; + } + + current_color = p_color; +} +void ImmediateMesh::surface_set_normal(const Vector3 &p_normal) { + ERR_FAIL_COND_MSG(!surface_active, "Not creating any surface. Use surface_begin() to do it."); + + if (!uses_normals) { + normals.resize(vertices.size()); + for (uint32_t i = 0; i < normals.size(); i++) { + normals[i] = p_normal; + } + uses_normals = true; + } + + current_normal = p_normal; +} +void ImmediateMesh::surface_set_tangent(const Plane &p_tangent) { + ERR_FAIL_COND_MSG(!surface_active, "Not creating any surface. Use surface_begin() to do it."); + if (!uses_tangents) { + tangents.resize(vertices.size()); + for (uint32_t i = 0; i < tangents.size(); i++) { + tangents[i] = p_tangent; + } + uses_tangents = true; + } + + current_tangent = p_tangent; +} +void ImmediateMesh::surface_set_uv(const Vector2 &p_uv) { + ERR_FAIL_COND_MSG(!surface_active, "Not creating any surface. Use surface_begin() to do it."); + if (!uses_uvs) { + uvs.resize(vertices.size()); + for (uint32_t i = 0; i < uvs.size(); i++) { + uvs[i] = p_uv; + } + uses_uvs = true; + } + + current_uv = p_uv; +} +void ImmediateMesh::surface_set_uv2(const Vector2 &p_uv2) { + ERR_FAIL_COND_MSG(!surface_active, "Not creating any surface. Use surface_begin() to do it."); + if (!uses_uv2s) { + uv2s.resize(vertices.size()); + for (uint32_t i = 0; i < uv2s.size(); i++) { + uv2s[i] = p_uv2; + } + uses_uv2s = true; + } + + current_uv2 = p_uv2; +} +void ImmediateMesh::surface_add_vertex(const Vector3 &p_vertex) { + ERR_FAIL_COND_MSG(!surface_active, "Not creating any surface. Use surface_begin() to do it."); + ERR_FAIL_COND_MSG(vertices.size() && active_surface_data.vertex_2d, "Can't mix 2D and 3D vertices in a surface."); + + if (uses_colors) { + colors.push_back(current_color); + } + if (uses_normals) { + normals.push_back(current_normal); + } + if (uses_tangents) { + tangents.push_back(current_tangent); + } + if (uses_uvs) { + uvs.push_back(current_uv); + } + if (uses_uv2s) { + uv2s.push_back(current_uv2); + } + vertices.push_back(p_vertex); +} + +void ImmediateMesh::surface_add_vertex_2d(const Vector2 &p_vertex) { + ERR_FAIL_COND_MSG(!surface_active, "Not creating any surface. Use surface_begin() to do it."); + ERR_FAIL_COND_MSG(vertices.size() && !active_surface_data.vertex_2d, "Can't mix 2D and 3D vertices in a surface."); + + if (uses_colors) { + colors.push_back(current_color); + } + if (uses_normals) { + normals.push_back(current_normal); + } + if (uses_tangents) { + tangents.push_back(current_tangent); + } + if (uses_uvs) { + uvs.push_back(current_uv); + } + if (uses_uv2s) { + uv2s.push_back(current_uv2); + } + Vector3 v(p_vertex.x, p_vertex.y, 0); + vertices.push_back(v); + + active_surface_data.vertex_2d = true; +} +void ImmediateMesh::surface_end() { + ERR_FAIL_COND_MSG(!surface_active, "Not creating any surface. Use surface_begin() to do it."); + ERR_FAIL_COND_MSG(!vertices.size(), "No vertices were added, surface cant be created."); + + uint32_t format = ARRAY_FORMAT_VERTEX; + + uint32_t vertex_stride = 0; + if (active_surface_data.vertex_2d) { + format |= ARRAY_FLAG_USE_2D_VERTICES; + vertex_stride = sizeof(float) * 2; + } else { + vertex_stride = sizeof(float) * 3; + } + + uint32_t normal_offset = 0; + if (uses_normals) { + format |= ARRAY_FORMAT_NORMAL; + normal_offset = vertex_stride; + vertex_stride += sizeof(uint32_t); + } + uint32_t tangent_offset = 0; + if (uses_tangents) { + format |= ARRAY_FORMAT_TANGENT; + tangent_offset += vertex_stride; + vertex_stride += sizeof(uint32_t); + } + + AABB aabb; + + { + surface_vertex_create_cache.resize(vertex_stride * vertices.size()); + uint8_t *surface_vertex_ptr = surface_vertex_create_cache.ptrw(); + for (uint32_t i = 0; i < vertices.size(); i++) { + { + float *vtx = (float *)&surface_vertex_ptr[i * vertex_stride]; + vtx[0] = vertices[i].x; + vtx[1] = vertices[i].y; + if (!active_surface_data.vertex_2d) { + vtx[2] = vertices[i].z; + } + if (i == 0) { + aabb.position = vertices[i]; + } else { + aabb.expand_to(vertices[i]); + } + } + if (uses_normals) { + uint32_t *normal = (uint32_t *)&surface_vertex_ptr[i * vertex_stride + normal_offset]; + + Vector3 n = normals[i] * Vector3(0.5, 0.5, 0.5) + Vector3(0.5, 0.5, 0.5); + + uint32_t value = 0; + value |= CLAMP(int(n.x * 1023.0), 0, 1023); + value |= CLAMP(int(n.y * 1023.0), 0, 1023) << 10; + value |= CLAMP(int(n.z * 1023.0), 0, 1023) << 20; + + *normal = value; + } + if (uses_tangents) { + uint32_t *tangent = (uint32_t *)&surface_vertex_ptr[i * vertex_stride + tangent_offset]; + Plane t = tangents[i]; + uint32_t value = 0; + value |= CLAMP(int((t.normal.x * 0.5 + 0.5) * 1023.0), 0, 1023); + value |= CLAMP(int((t.normal.y * 0.5 + 0.5) * 1023.0), 0, 1023) << 10; + value |= CLAMP(int((t.normal.z * 0.5 + 0.5) * 1023.0), 0, 1023) << 20; + if (t.d > 0) { + value |= 3 << 30; + } + + *tangent = value; + } + } + } + + if (uses_colors || uses_uvs || uses_uv2s) { + uint32_t attribute_stride = 0; + + if (uses_colors) { + format |= ARRAY_FORMAT_COLOR; + attribute_stride += sizeof(uint8_t) * 4; + } + uint32_t uv_offset = 0; + if (uses_uvs) { + format |= ARRAY_FORMAT_TEX_UV; + uv_offset = attribute_stride; + attribute_stride += sizeof(float) * 2; + } + uint32_t uv2_offset = 0; + if (uses_uv2s) { + format |= ARRAY_FORMAT_TEX_UV2; + uv2_offset = attribute_stride; + attribute_stride += sizeof(float) * 2; + } + + surface_attribute_create_cache.resize(vertices.size() * attribute_stride); + + uint8_t *surface_attribute_ptr = surface_attribute_create_cache.ptrw(); + + for (uint32_t i = 0; i < vertices.size(); i++) { + if (uses_colors) { + uint8_t *color8 = (uint8_t *)&surface_attribute_ptr[i * attribute_stride]; + + color8[0] = uint8_t(CLAMP(colors[i].r * 255.0, 0.0, 255.0)); + color8[1] = uint8_t(CLAMP(colors[i].g * 255.0, 0.0, 255.0)); + color8[2] = uint8_t(CLAMP(colors[i].b * 255.0, 0.0, 255.0)); + color8[3] = uint8_t(CLAMP(colors[i].a * 255.0, 0.0, 255.0)); + } + if (uses_uvs) { + float *uv = (float *)&surface_attribute_ptr[i * attribute_stride + uv_offset]; + + uv[0] = uvs[i].x; + uv[1] = uvs[i].y; + } + + if (uses_uv2s) { + float *uv2 = (float *)&surface_attribute_ptr[i * attribute_stride + uv2_offset]; + + uv2[0] = uv2s[i].x; + uv2[1] = uv2s[i].y; + } + } + } + + RS::SurfaceData sd; + + sd.primitive = RS::PrimitiveType(active_surface_data.primitive); + sd.format = format; + sd.vertex_data = surface_vertex_create_cache; + if (uses_colors || uses_uvs || uses_uv2s) { + sd.attribute_data = surface_attribute_create_cache; + } + sd.vertex_count = vertices.size(); + sd.aabb = aabb; + if (active_surface_data.material.is_valid()) { + sd.material = active_surface_data.material->get_rid(); + } + + RS::get_singleton()->mesh_add_surface(mesh, sd); + + active_surface_data.aabb = aabb; + + active_surface_data.format = format; + active_surface_data.array_len = vertices.size(); + + surfaces.push_back(active_surface_data); + + colors.clear(); + normals.clear(); + tangents.clear(); + uvs.clear(); + uv2s.clear(); + vertices.clear(); + + uses_colors = false; + uses_normals = false; + uses_tangents = false; + uses_uvs = false; + uses_uv2s = false; + + surface_active = false; +} + +void ImmediateMesh::clear_surfaces() { + RS::get_singleton()->mesh_clear(mesh); + surfaces.clear(); + surface_active = false; + + colors.clear(); + normals.clear(); + tangents.clear(); + uvs.clear(); + uv2s.clear(); + vertices.clear(); + + uses_colors = false; + uses_normals = false; + uses_tangents = false; + uses_uvs = false; + uses_uv2s = false; +} + +int ImmediateMesh::get_surface_count() const { + return surfaces.size(); +} +int ImmediateMesh::surface_get_array_len(int p_idx) const { + ERR_FAIL_INDEX_V(p_idx, int(surfaces.size()), -1); + return surfaces[p_idx].array_len; +} +int ImmediateMesh::surface_get_array_index_len(int p_idx) const { + return 0; +} +bool ImmediateMesh::surface_is_softbody_friendly(int p_idx) const { + return false; +} +Array ImmediateMesh::surface_get_arrays(int p_surface) const { + ERR_FAIL_INDEX_V(p_surface, int(surfaces.size()), Array()); + return RS::get_singleton()->mesh_surface_get_arrays(mesh, p_surface); +} +Array ImmediateMesh::surface_get_blend_shape_arrays(int p_surface) const { + return Array(); +} +Dictionary ImmediateMesh::surface_get_lods(int p_surface) const { + return Dictionary(); +} +uint32_t ImmediateMesh::surface_get_format(int p_idx) const { + ERR_FAIL_INDEX_V(p_idx, int(surfaces.size()), 0); + return surfaces[p_idx].format; +} +Mesh::PrimitiveType ImmediateMesh::surface_get_primitive_type(int p_idx) const { + ERR_FAIL_INDEX_V(p_idx, int(surfaces.size()), PRIMITIVE_MAX); + return surfaces[p_idx].primitive; +} +void ImmediateMesh::surface_set_material(int p_idx, const Ref<Material> &p_material) { + ERR_FAIL_INDEX(p_idx, int(surfaces.size())); + surfaces[p_idx].material = p_material; + RID mat; + if (p_material.is_valid()) { + mat = p_material->get_rid(); + } + RS::get_singleton()->mesh_surface_set_material(mesh, p_idx, mat); +} +Ref<Material> ImmediateMesh::surface_get_material(int p_idx) const { + ERR_FAIL_INDEX_V(p_idx, int(surfaces.size()), Ref<Material>()); + return surfaces[p_idx].material; +} +int ImmediateMesh::get_blend_shape_count() const { + return 0; +} +StringName ImmediateMesh::get_blend_shape_name(int p_index) const { + return StringName(); +} +void ImmediateMesh::set_blend_shape_name(int p_index, const StringName &p_name) { +} + +AABB ImmediateMesh::get_aabb() const { + AABB aabb; + for (uint32_t i = 0; i < surfaces.size(); i++) { + if (i == 0) { + aabb = surfaces[i].aabb; + } else { + aabb.merge(surfaces[i].aabb); + } + } + return aabb; +} + +void ImmediateMesh::_bind_methods() { + ClassDB::bind_method(D_METHOD("surface_begin", "primitive", "material"), &ImmediateMesh::surface_begin, DEFVAL(Ref<Material>())); + ClassDB::bind_method(D_METHOD("surface_set_color", "color"), &ImmediateMesh::surface_set_color); + ClassDB::bind_method(D_METHOD("surface_set_normal", "normal"), &ImmediateMesh::surface_set_normal); + ClassDB::bind_method(D_METHOD("surface_set_tangent", "tangent"), &ImmediateMesh::surface_set_tangent); + ClassDB::bind_method(D_METHOD("surface_set_uv", "uv"), &ImmediateMesh::surface_set_uv); + ClassDB::bind_method(D_METHOD("surface_set_uv2", "uv2"), &ImmediateMesh::surface_set_uv2); + ClassDB::bind_method(D_METHOD("surface_add_vertex", "vertex"), &ImmediateMesh::surface_add_vertex); + ClassDB::bind_method(D_METHOD("surface_add_vertex_2d", "vertex"), &ImmediateMesh::surface_add_vertex_2d); + ClassDB::bind_method(D_METHOD("surface_end"), &ImmediateMesh::surface_end); + + ClassDB::bind_method(D_METHOD("clear_surfaces"), &ImmediateMesh::clear_surfaces); +} + +RID ImmediateMesh::get_rid() const { + return mesh; +} + +ImmediateMesh::ImmediateMesh() { + mesh = RS::get_singleton()->mesh_create(); +} +ImmediateMesh::~ImmediateMesh() { + RS::get_singleton()->free(mesh); +} diff --git a/scene/resources/immediate_mesh.h b/scene/resources/immediate_mesh.h new file mode 100644 index 0000000000..7010d40719 --- /dev/null +++ b/scene/resources/immediate_mesh.h @@ -0,0 +1,117 @@ +/*************************************************************************/ +/* immediate_mesh.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef IMMEDIATE_MESH_H +#define IMMEDIATE_MESH_H + +#include "core/templates/local_vector.h" +#include "scene/resources/mesh.h" + +class ImmediateMesh : public Mesh { + GDCLASS(ImmediateMesh, Mesh) + + RID mesh; + + bool uses_colors = false; + bool uses_normals = false; + bool uses_tangents = false; + bool uses_uvs = false; + bool uses_uv2s = false; + + Color current_color; + Vector3 current_normal; + Plane current_tangent; + Vector2 current_uv; + Vector2 current_uv2; + + LocalVector<Color> colors; + LocalVector<Vector3> normals; + LocalVector<Plane> tangents; + LocalVector<Vector2> uvs; + LocalVector<Vector2> uv2s; + LocalVector<Vector3> vertices; + + struct Surface { + PrimitiveType primitive; + Ref<Material> material; + bool vertex_2d = false; + int array_len = 0; + uint32_t format = 0; + AABB aabb; + }; + + LocalVector<Surface> surfaces; + + bool surface_active = false; + Surface active_surface_data; + + Vector<uint8_t> surface_vertex_create_cache; + Vector<uint8_t> surface_attribute_create_cache; + +protected: + static void _bind_methods(); + +public: + void surface_begin(PrimitiveType p_primitive, const Ref<Material> &p_material = Ref<Material>()); + void surface_set_color(const Color &p_color); + void surface_set_normal(const Vector3 &p_normal); + void surface_set_tangent(const Plane &p_tangent); + void surface_set_uv(const Vector2 &p_uv); + void surface_set_uv2(const Vector2 &p_uv2); + void surface_add_vertex(const Vector3 &p_vertex); + void surface_add_vertex_2d(const Vector2 &p_vertex); + void surface_end(); + + void clear_surfaces(); + + virtual int get_surface_count() const override; + virtual int surface_get_array_len(int p_idx) const override; + virtual int surface_get_array_index_len(int p_idx) const override; + virtual bool surface_is_softbody_friendly(int p_idx) const override; + virtual Array surface_get_arrays(int p_surface) const override; + virtual Array surface_get_blend_shape_arrays(int p_surface) const override; + virtual Dictionary surface_get_lods(int p_surface) const override; + virtual uint32_t surface_get_format(int p_idx) const override; + virtual PrimitiveType surface_get_primitive_type(int p_idx) const override; + virtual void surface_set_material(int p_idx, const Ref<Material> &p_material) override; + virtual Ref<Material> surface_get_material(int p_idx) const override; + virtual int get_blend_shape_count() const override; + virtual StringName get_blend_shape_name(int p_index) const override; + virtual void set_blend_shape_name(int p_index, const StringName &p_name) override; + + virtual AABB get_aabb() const override; + + virtual RID get_rid() const override; + + ImmediateMesh(); + ~ImmediateMesh(); +}; + +#endif // IMMEDIATEMESH_H diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index 2c5634e6ef..a264c2d1eb 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -77,7 +77,7 @@ RID Material::get_rid() const { void Material::_validate_property(PropertyInfo &property) const { if (!_can_do_next_pass() && property.name == "next_pass") { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } } @@ -130,7 +130,7 @@ bool ShaderMaterial::_set(const StringName &p_name, const Variant &p_value) { } } if (pr) { - RenderingServer::get_singleton()->material_set_param(_get_material(), pr, p_value); + set_shader_param(pr, p_value); return true; } } @@ -152,7 +152,12 @@ bool ShaderMaterial::_get(const StringName &p_name, Variant &r_ret) const { } if (pr) { - r_ret = RenderingServer::get_singleton()->material_get_param(_get_material(), pr); + const Map<StringName, Variant>::Element *E = param_cache.find(pr); + if (E) { + r_ret = E->get(); + } else { + r_ret = Variant(); + } return true; } } @@ -219,11 +224,31 @@ Ref<Shader> ShaderMaterial::get_shader() const { } void ShaderMaterial::set_shader_param(const StringName &p_param, const Variant &p_value) { - RS::get_singleton()->material_set_param(_get_material(), p_param, p_value); + if (p_value.get_type() == Variant::NIL) { + param_cache.erase(p_param); + RS::get_singleton()->material_set_param(_get_material(), p_param, Variant()); + } else { + param_cache[p_param] = p_value; + if (p_value.get_type() == Variant::OBJECT) { + RID tex_rid = p_value; + if (tex_rid == RID()) { + param_cache.erase(p_param); + RS::get_singleton()->material_set_param(_get_material(), p_param, Variant()); + } else { + RS::get_singleton()->material_set_param(_get_material(), p_param, tex_rid); + } + } else { + RS::get_singleton()->material_set_param(_get_material(), p_param, p_value); + } + } } Variant ShaderMaterial::get_shader_param(const StringName &p_param) const { - return RS::get_singleton()->material_get_param(_get_material(), p_param); + if (param_cache.has(p_param)) { + return param_cache[p_param]; + } else { + return Variant(); + } } void ShaderMaterial::_shader_changed() { @@ -345,7 +370,6 @@ void BaseMaterial3D::init_shaders() { shader_names->refraction_texture_channel = "refraction_texture_channel"; shader_names->transmittance_color = "transmittance_color"; - shader_names->transmittance_curve = "transmittance_curve"; shader_names->transmittance_depth = "transmittance_depth"; shader_names->transmittance_boost = "transmittance_boost"; @@ -692,7 +716,6 @@ void BaseMaterial3D::_update_shader() { code += "uniform vec4 transmittance_color : hint_color;\n"; code += "uniform float transmittance_depth;\n"; code += "uniform sampler2D texture_subsurface_transmittance : hint_white," + texfilter_str + ";\n"; - code += "uniform float transmittance_curve;\n"; code += "uniform float transmittance_boost;\n"; } @@ -822,9 +845,9 @@ void BaseMaterial3D::_update_shader() { code += "\tTANGENT+= vec3(1.0,0.0,0.0) * abs(NORMAL.z);\n"; code += "\tTANGENT = normalize(TANGENT);\n"; - code += "\tBINORMAL = vec3(0.0,-1.0,0.0) * abs(NORMAL.x);\n"; - code += "\tBINORMAL+= vec3(0.0,0.0,1.0) * abs(NORMAL.y);\n"; - code += "\tBINORMAL+= vec3(0.0,-1.0,0.0) * abs(NORMAL.z);\n"; + code += "\tBINORMAL = vec3(0.0,1.0,0.0) * abs(NORMAL.x);\n"; + code += "\tBINORMAL+= vec3(0.0,0.0,-1.0) * abs(NORMAL.y);\n"; + code += "\tBINORMAL+= vec3(0.0,1.0,0.0) * abs(NORMAL.z);\n"; code += "\tBINORMAL = normalize(BINORMAL);\n"; } @@ -878,6 +901,20 @@ void BaseMaterial3D::_update_shader() { code += "\tvec2 base_uv2 = UV2;\n"; } + if (features[FEATURE_HEIGHT_MAPPING] && flags[FLAG_UV1_USE_TRIPLANAR]) { + // Display both resource name and albedo texture name. + // Materials are often built-in to scenes, so displaying the resource name alone may not be meaningful. + // On the other hand, albedo textures are almost always external to the scene. + if (textures[TEXTURE_ALBEDO].is_valid()) { + WARN_PRINT(vformat("%s (albedo %s): Height mapping is not supported on triplanar materials. Ignoring height mapping in favor of triplanar mapping.", get_path(), textures[TEXTURE_ALBEDO]->get_path())); + } else if (!get_path().is_empty()) { + WARN_PRINT(vformat("%s: Height mapping is not supported on triplanar materials. Ignoring height mapping in favor of triplanar mapping.", get_path())); + } else { + // Resource wasn't saved yet. + WARN_PRINT("Height mapping is not supported on triplanar materials. Ignoring height mapping in favor of triplanar mapping."); + } + } + if (!RenderingServer::get_singleton()->is_low_end() && features[FEATURE_HEIGHT_MAPPING] && !flags[FLAG_UV1_USE_TRIPLANAR]) { //heightmap not supported with triplanar code += "\t{\n"; code += "\t\tvec3 view_dir = normalize(normalize(-VERTEX)*mat3(TANGENT*heightmap_flip.x,-BINORMAL*heightmap_flip.y,NORMAL));\n"; // binormal is negative due to mikktspace, flip 'unflips' it ;-) @@ -987,9 +1024,9 @@ void BaseMaterial3D::_update_shader() { code += "\tSPECULAR = specular;\n"; } else { if (flags[FLAG_UV1_USE_TRIPLANAR]) { - code += "\tfloat orm_tex = triplanar_texture(texture_orm,uv1_power_normal,uv1_triplanar_pos);\n"; + code += "\tvec4 orm_tex = triplanar_texture(texture_orm,uv1_power_normal,uv1_triplanar_pos);\n"; } else { - code += "\tfloat orm_tex = texture(texture_orm,base_uv);\n"; + code += "\tvec4 orm_tex = texture(texture_orm,base_uv);\n"; } code += "\tROUGHNESS = orm_tex.g;\n"; @@ -1180,7 +1217,6 @@ void BaseMaterial3D::_update_shader() { code += "\tSSS_TRANSMITTANCE_COLOR=transmittance_color*trans_color_tex;\n"; code += "\tSSS_TRANSMITTANCE_DEPTH=transmittance_depth;\n"; - code += "\tSSS_TRANSMITTANCE_CURVE=transmittance_curve;\n"; code += "\tSSS_TRANSMITTANCE_BOOST=transmittance_boost;\n"; } @@ -1424,15 +1460,6 @@ float BaseMaterial3D::get_transmittance_depth() const { return transmittance_depth; } -void BaseMaterial3D::set_transmittance_curve(float p_curve) { - transmittance_curve = p_curve; - RS::get_singleton()->material_set_param(_get_material(), shader_names->transmittance_curve, p_curve); -} - -float BaseMaterial3D::get_transmittance_curve() const { - return transmittance_curve; -} - void BaseMaterial3D::set_transmittance_boost(float p_boost) { transmittance_boost = p_boost; RS::get_singleton()->material_set_param(_get_material(), shader_names->transmittance_boost, p_boost); @@ -1696,7 +1723,7 @@ void BaseMaterial3D::_validate_property(PropertyInfo &property) const { _validate_high_end("heightmap", property); if (property.name.begins_with("particles_anim_") && billboard_mode != BILLBOARD_PARTICLES) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } if (property.name == "billboard_keep_scale" && billboard_mode == BILLBOARD_DISABLED) { @@ -1726,33 +1753,33 @@ void BaseMaterial3D::_validate_property(PropertyInfo &property) const { // alpha scissor slider isn't needed when alpha antialiasing is enabled if (property.name == "alpha_scissor_threshold" && transparency != TRANSPARENCY_ALPHA_SCISSOR) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } // alpha hash scale slider is only needed if transparency is alpha hash if (property.name == "alpha_hash_scale" && transparency != TRANSPARENCY_ALPHA_HASH) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } if (property.name == "alpha_antialiasing_mode" && !can_select_aa) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } // we can't choose an antialiasing mode if alpha isn't possible if (property.name == "alpha_antialiasing_edge" && !alpha_aa_enabled) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } if (property.name == "blend_mode" && alpha_aa_enabled) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } if ((property.name == "heightmap_min_layers" || property.name == "heightmap_max_layers") && !deep_parallax) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } - if (flags[FLAG_SUBSURFACE_MODE_SKIN] && (property.name == "subsurf_scatter_transmittance_color" || property.name == "subsurf_scatter_transmittance_texture" || property.name == "subsurf_scatter_transmittance_curve")) { - property.usage = 0; + if (flags[FLAG_SUBSURFACE_MODE_SKIN] && (property.name == "subsurf_scatter_transmittance_color" || property.name == "subsurf_scatter_transmittance_texture")) { + property.usage = PROPERTY_USAGE_NONE; } if (orm) { @@ -1761,12 +1788,12 @@ void BaseMaterial3D::_validate_property(PropertyInfo &property) const { property.hint_string = "Unshaded,Per-Pixel"; } if (property.name.begins_with("roughness") || property.name.begins_with("metallic") || property.name.begins_with("ao_texture")) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } } else { if (property.name == "orm_texture") { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } } @@ -1774,47 +1801,47 @@ void BaseMaterial3D::_validate_property(PropertyInfo &property) const { if (shading_mode != SHADING_MODE_PER_VERTEX) { //these may still work per vertex if (property.name.begins_with("ao")) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } if (property.name.begins_with("emission")) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } if (property.name.begins_with("metallic")) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } if (property.name.begins_with("rim")) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } if (property.name.begins_with("roughness")) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } if (property.name.begins_with("subsurf_scatter")) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } } //these definitely only need per pixel if (property.name.begins_with("anisotropy")) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } if (property.name.begins_with("clearcoat")) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } if (property.name.begins_with("normal")) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } if (property.name.begins_with("backlight")) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } if (property.name.begins_with("transmittance")) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } } } @@ -2063,7 +2090,7 @@ BaseMaterial3D::TextureChannel BaseMaterial3D::get_refraction_texture_channel() return refraction_texture_channel; } -RID BaseMaterial3D::get_material_rid_for_2d(bool p_shaded, bool p_transparent, bool p_double_sided, bool p_cut_alpha, bool p_opaque_prepass, bool p_billboard, bool p_billboard_y) { +Ref<Material> BaseMaterial3D::get_material_for_2d(bool p_shaded, bool p_transparent, bool p_double_sided, bool p_cut_alpha, bool p_opaque_prepass, bool p_billboard, bool p_billboard_y, RID *r_shader_rid) { int version = 0; if (p_shaded) { version = 1; @@ -2088,11 +2115,14 @@ RID BaseMaterial3D::get_material_rid_for_2d(bool p_shaded, bool p_transparent, b } if (materials_for_2d[version].is_valid()) { - return materials_for_2d[version]->get_rid(); + if (r_shader_rid) { + *r_shader_rid = materials_for_2d[version]->get_shader_rid(); + } + return materials_for_2d[version]; } Ref<StandardMaterial3D> material; - material.instance(); + material.instantiate(); material->set_shading_mode(p_shaded ? SHADING_MODE_PER_PIXEL : SHADING_MODE_UNSHADED); material->set_transparency(p_transparent ? (p_opaque_prepass ? TRANSPARENCY_ALPHA_DEPTH_PRE_PASS : (p_cut_alpha ? TRANSPARENCY_ALPHA_SCISSOR : TRANSPARENCY_ALPHA)) : TRANSPARENCY_DISABLED); @@ -2106,7 +2136,11 @@ RID BaseMaterial3D::get_material_rid_for_2d(bool p_shaded, bool p_transparent, b materials_for_2d[version] = material; - return materials_for_2d[version]->get_rid(); + if (r_shader_rid) { + *r_shader_rid = materials_for_2d[version]->get_shader_rid(); + } + + return materials_for_2d[version]; } void BaseMaterial3D::set_on_top_of_alpha() { @@ -2175,6 +2209,8 @@ BaseMaterial3D::EmissionOperator BaseMaterial3D::get_emission_operator() const { } RID BaseMaterial3D::get_shader_rid() const { + MutexLock lock(material_mutex); + ((BaseMaterial3D *)this)->_update_shader(); ERR_FAIL_COND_V(!shader_map.has(current_key), RID()); return shader_map[current_key].shader; } @@ -2246,9 +2282,6 @@ void BaseMaterial3D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_transmittance_depth", "depth"), &BaseMaterial3D::set_transmittance_depth); ClassDB::bind_method(D_METHOD("get_transmittance_depth"), &BaseMaterial3D::get_transmittance_depth); - ClassDB::bind_method(D_METHOD("set_transmittance_curve", "curve"), &BaseMaterial3D::set_transmittance_curve); - ClassDB::bind_method(D_METHOD("get_transmittance_curve"), &BaseMaterial3D::get_transmittance_curve); - ClassDB::bind_method(D_METHOD("set_transmittance_boost", "boost"), &BaseMaterial3D::set_transmittance_boost); ClassDB::bind_method(D_METHOD("get_transmittance_boost"), &BaseMaterial3D::get_transmittance_boost); @@ -2483,7 +2516,6 @@ void BaseMaterial3D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::COLOR, "subsurf_scatter_transmittance_color"), "set_transmittance_color", "get_transmittance_color"); ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "subsurf_scatter_transmittance_texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_texture", "get_texture", TEXTURE_SUBSURFACE_TRANSMITTANCE); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "subsurf_scatter_transmittance_depth", PROPERTY_HINT_RANGE, "0.001,8,0.001,or_greater"), "set_transmittance_depth", "get_transmittance_depth"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "subsurf_scatter_transmittance_curve", PROPERTY_HINT_EXP_EASING, "0.01,16,0.01"), "set_transmittance_curve", "get_transmittance_curve"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "subsurf_scatter_transmittance_boost", PROPERTY_HINT_RANGE, "0.00,1.0,0.01"), "set_transmittance_boost", "get_transmittance_boost"); ADD_GROUP("Back Lighting", "backlight_"); @@ -2700,7 +2732,6 @@ BaseMaterial3D::BaseMaterial3D(bool p_orm) : set_backlight(Color(0, 0, 0)); set_transmittance_color(Color(1, 1, 1, 1)); set_transmittance_depth(0.1); - set_transmittance_curve(1.0); set_transmittance_boost(0.0); set_refraction(0.05); set_point_size(1); diff --git a/scene/resources/material.h b/scene/resources/material.h index dc3ecdb5de..e2838e1399 100644 --- a/scene/resources/material.h +++ b/scene/resources/material.h @@ -79,6 +79,8 @@ class ShaderMaterial : public Material { GDCLASS(ShaderMaterial, Material); Ref<Shader> shader; + Map<StringName, Variant> param_cache; + protected: bool _set(const StringName &p_name, const Variant &p_value); bool _get(const StringName &p_name, Variant &r_ret) const; @@ -389,7 +391,6 @@ private: StringName heightmap_scale; StringName subsurface_scattering_strength; StringName transmittance_color; - StringName transmittance_curve; StringName transmittance_depth; StringName transmittance_boost; StringName backlight; @@ -458,7 +459,6 @@ private: float transmittance_amount; Color transmittance_color; float transmittance_depth; - float transmittance_curve; float transmittance_boost; Color backlight; @@ -602,9 +602,6 @@ public: void set_transmittance_depth(float p_depth); float get_transmittance_depth() const; - void set_transmittance_curve(float p_curve); - float get_transmittance_curve() const; - void set_transmittance_boost(float p_boost); float get_transmittance_boost() const; @@ -738,7 +735,7 @@ public: static void finish_shaders(); static void flush_changes(); - static RID get_material_rid_for_2d(bool p_shaded, bool p_transparent, bool p_double_sided, bool p_cut_alpha, bool p_opaque_prepass, bool p_billboard = false, bool p_billboard_y = false); + static Ref<Material> get_material_for_2d(bool p_shaded, bool p_transparent, bool p_double_sided, bool p_cut_alpha, bool p_opaque_prepass, bool p_billboard = false, bool p_billboard_y = false, RID *r_shader_rid = nullptr); virtual RID get_shader_rid() const override; diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp index 5e8e77c730..f44c0c3ee2 100644 --- a/scene/resources/mesh.cpp +++ b/scene/resources/mesh.cpp @@ -571,7 +571,7 @@ Vector<Ref<Shape3D>> Mesh::convex_decompose() const { } Ref<ConvexPolygonShape3D> shape; - shape.instance(); + shape.instantiate(); shape->set_points(convex_points); ret.push_back(shape); } @@ -590,157 +590,320 @@ Transform3D Mesh::get_builtin_bind_pose(int p_index) const { Mesh::Mesh() { } -#if 0 -static Vector<uint8_t> _fix_array_compatibility(const Vector<uint8_t> &p_src, uint32_t p_format, uint32_t p_elements) { - enum ArrayType { - OLD_ARRAY_VERTEX = 0, - OLD_ARRAY_NORMAL = 1, - OLD_ARRAY_TANGENT = 2, - OLD_ARRAY_COLOR = 3, - OLD_ARRAY_TEX_UV = 4, - OLD_ARRAY_TEX_UV2 = 5, - OLD_ARRAY_BONES = 6, - OLD_ARRAY_WEIGHTS = 7, - OLD_ARRAY_INDEX = 8, - OLD_ARRAY_MAX = 9 - }; - - enum ArrayFormat { - /* OLD_ARRAY FORMAT FLAGS */ - OLD_ARRAY_FORMAT_VERTEX = 1 << OLD_ARRAY_VERTEX, // mandatory - OLD_ARRAY_FORMAT_NORMAL = 1 << OLD_ARRAY_NORMAL, - OLD_ARRAY_FORMAT_TANGENT = 1 << OLD_ARRAY_TANGENT, - OLD_ARRAY_FORMAT_COLOR = 1 << OLD_ARRAY_COLOR, - OLD_ARRAY_FORMAT_TEX_UV = 1 << OLD_ARRAY_TEX_UV, - OLD_ARRAY_FORMAT_TEX_UV2 = 1 << OLD_ARRAY_TEX_UV2, - OLD_ARRAY_FORMAT_BONES = 1 << OLD_ARRAY_BONES, - OLD_ARRAY_FORMAT_WEIGHTS = 1 << OLD_ARRAY_WEIGHTS, - OLD_ARRAY_FORMAT_INDEX = 1 << OLD_ARRAY_INDEX, - - OLD_ARRAY_COMPRESS_BASE = (OLD_ARRAY_INDEX + 1), - OLD_ARRAY_COMPRESS_NORMAL = 1 << (OLD_ARRAY_NORMAL + OLD_ARRAY_COMPRESS_BASE), - OLD_ARRAY_COMPRESS_TANGENT = 1 << (OLD_ARRAY_TANGENT + OLD_ARRAY_COMPRESS_BASE), - OLD_ARRAY_COMPRESS_COLOR = 1 << (OLD_ARRAY_COLOR + OLD_ARRAY_COMPRESS_BASE), - OLD_ARRAY_COMPRESS_TEX_UV = 1 << (OLD_ARRAY_TEX_UV + OLD_ARRAY_COMPRESS_BASE), - OLD_ARRAY_COMPRESS_TEX_UV2 = 1 << (OLD_ARRAY_TEX_UV2 + OLD_ARRAY_COMPRESS_BASE), - OLD_ARRAY_COMPRESS_INDEX = 1 << (OLD_ARRAY_INDEX + OLD_ARRAY_COMPRESS_BASE), - OLD_ARRAY_COMPRESS_DEFAULT = OLD_ARRAY_COMPRESS_NORMAL | OLD_ARRAY_COMPRESS_TANGENT | OLD_ARRAY_COMPRESS_COLOR | OLD_ARRAY_COMPRESS_TEX_UV | OLD_ARRAY_COMPRESS_TEX_UV2, - - OLD_ARRAY_FLAG_USE_2D_VERTICES = OLD_ARRAY_COMPRESS_INDEX << 1, - OLD_ARRAY_FLAG_USE_DYNAMIC_UPDATE = OLD_ARRAY_COMPRESS_INDEX << 3, - }; - - bool vertex_16bit = p_format & ((1 << (OLD_ARRAY_VERTEX + OLD_ARRAY_COMPRESS_BASE))); - bool has_bones = (p_format & OLD_ARRAY_FORMAT_BONES); - bool bone_8 = has_bones && !(p_format & (OLD_ARRAY_COMPRESS_INDEX << 2)); - bool weight_32 = has_bones && !(p_format & (OLD_ARRAY_COMPRESS_TEX_UV2 << 2)); - - print_line("convert vertex16: " + itos(vertex_16bit) + " convert bone 8 " + itos(bone_8) + " convert weight 32 " + itos(weight_32)); - - if (!vertex_16bit && !bone_8 && !weight_32) { - return p_src; - } +enum OldArrayType { + OLD_ARRAY_VERTEX, + OLD_ARRAY_NORMAL, + OLD_ARRAY_TANGENT, + OLD_ARRAY_COLOR, + OLD_ARRAY_TEX_UV, + OLD_ARRAY_TEX_UV2, + OLD_ARRAY_BONES, + OLD_ARRAY_WEIGHTS, + OLD_ARRAY_INDEX, + OLD_ARRAY_MAX, +}; - bool vertex_2d = (p_format & (OLD_ARRAY_COMPRESS_INDEX << 1)); +enum OldArrayFormat { + /* OLD_ARRAY FORMAT FLAGS */ + OLD_ARRAY_FORMAT_VERTEX = 1 << OLD_ARRAY_VERTEX, // mandatory + OLD_ARRAY_FORMAT_NORMAL = 1 << OLD_ARRAY_NORMAL, + OLD_ARRAY_FORMAT_TANGENT = 1 << OLD_ARRAY_TANGENT, + OLD_ARRAY_FORMAT_COLOR = 1 << OLD_ARRAY_COLOR, + OLD_ARRAY_FORMAT_TEX_UV = 1 << OLD_ARRAY_TEX_UV, + OLD_ARRAY_FORMAT_TEX_UV2 = 1 << OLD_ARRAY_TEX_UV2, + OLD_ARRAY_FORMAT_BONES = 1 << OLD_ARRAY_BONES, + OLD_ARRAY_FORMAT_WEIGHTS = 1 << OLD_ARRAY_WEIGHTS, + OLD_ARRAY_FORMAT_INDEX = 1 << OLD_ARRAY_INDEX, + + OLD_ARRAY_COMPRESS_BASE = (OLD_ARRAY_INDEX + 1), + OLD_ARRAY_COMPRESS_VERTEX = 1 << (OLD_ARRAY_VERTEX + OLD_ARRAY_COMPRESS_BASE), // mandatory + OLD_ARRAY_COMPRESS_NORMAL = 1 << (OLD_ARRAY_NORMAL + OLD_ARRAY_COMPRESS_BASE), + OLD_ARRAY_COMPRESS_TANGENT = 1 << (OLD_ARRAY_TANGENT + OLD_ARRAY_COMPRESS_BASE), + OLD_ARRAY_COMPRESS_COLOR = 1 << (OLD_ARRAY_COLOR + OLD_ARRAY_COMPRESS_BASE), + OLD_ARRAY_COMPRESS_TEX_UV = 1 << (OLD_ARRAY_TEX_UV + OLD_ARRAY_COMPRESS_BASE), + OLD_ARRAY_COMPRESS_TEX_UV2 = 1 << (OLD_ARRAY_TEX_UV2 + OLD_ARRAY_COMPRESS_BASE), + OLD_ARRAY_COMPRESS_BONES = 1 << (OLD_ARRAY_BONES + OLD_ARRAY_COMPRESS_BASE), + OLD_ARRAY_COMPRESS_WEIGHTS = 1 << (OLD_ARRAY_WEIGHTS + OLD_ARRAY_COMPRESS_BASE), + OLD_ARRAY_COMPRESS_INDEX = 1 << (OLD_ARRAY_INDEX + OLD_ARRAY_COMPRESS_BASE), + + OLD_ARRAY_FLAG_USE_2D_VERTICES = OLD_ARRAY_COMPRESS_INDEX << 1, + OLD_ARRAY_FLAG_USE_16_BIT_BONES = OLD_ARRAY_COMPRESS_INDEX << 2, + OLD_ARRAY_FLAG_USE_DYNAMIC_UPDATE = OLD_ARRAY_COMPRESS_INDEX << 3, - uint32_t src_stride = p_src.size() / p_elements; - uint32_t dst_stride = src_stride + (vertex_16bit ? 4 : 0) + (bone_8 ? 4 : 0) - (weight_32 ? 8 : 0); +}; - Vector<uint8_t> ret = p_src; +static Array _convert_old_array(const Array &p_old) { + Array new_array; + new_array.resize(Mesh::ARRAY_MAX); + new_array[Mesh::ARRAY_VERTEX] = p_old[OLD_ARRAY_VERTEX]; + new_array[Mesh::ARRAY_NORMAL] = p_old[OLD_ARRAY_NORMAL]; + new_array[Mesh::ARRAY_TANGENT] = p_old[OLD_ARRAY_TANGENT]; + new_array[Mesh::ARRAY_COLOR] = p_old[OLD_ARRAY_COLOR]; + new_array[Mesh::ARRAY_TEX_UV] = p_old[OLD_ARRAY_TEX_UV]; + new_array[Mesh::ARRAY_TEX_UV2] = p_old[OLD_ARRAY_TEX_UV2]; + new_array[Mesh::ARRAY_BONES] = p_old[OLD_ARRAY_BONES]; + new_array[Mesh::ARRAY_WEIGHTS] = p_old[OLD_ARRAY_WEIGHTS]; + new_array[Mesh::ARRAY_INDEX] = p_old[OLD_ARRAY_INDEX]; + return new_array; +} + +static Mesh::PrimitiveType _old_primitives[7] = { + Mesh::PRIMITIVE_POINTS, + Mesh::PRIMITIVE_LINES, + Mesh::PRIMITIVE_LINE_STRIP, + Mesh::PRIMITIVE_LINES, + Mesh::PRIMITIVE_TRIANGLES, + Mesh::PRIMITIVE_TRIANGLE_STRIP, + Mesh::PRIMITIVE_TRIANGLE_STRIP +}; - ret.resize(dst_stride * p_elements); - { - uint8_t *w = ret.ptrw(); - const uint8_t *r = p_src.ptr(); - - for (uint32_t i = 0; i < p_elements; i++) { - uint32_t remaining = src_stride; - const uint8_t *src = (const uint8_t *)(r + src_stride * i); - uint8_t *dst = (uint8_t *)(w + dst_stride * i); - - if (!vertex_2d) { //3D - if (vertex_16bit) { - float *dstw = (float *)dst; - const uint16_t *srcr = (const uint16_t *)src; - dstw[0] = Math::half_to_float(srcr[0]); - dstw[1] = Math::half_to_float(srcr[1]); - dstw[2] = Math::half_to_float(srcr[2]); - remaining -= 8; - src += 8; +void _fix_array_compatibility(const Vector<uint8_t> &p_src, uint32_t p_old_format, uint32_t p_new_format, uint32_t p_elements, Vector<uint8_t> &vertex_data, Vector<uint8_t> &attribute_data, Vector<uint8_t> &skin_data) { + uint32_t dst_vertex_stride; + uint32_t dst_attribute_stride; + uint32_t dst_skin_stride; + uint32_t dst_offsets[Mesh::ARRAY_MAX]; + RenderingServer::get_singleton()->mesh_surface_make_offsets_from_format(p_new_format & (~RS::ARRAY_FORMAT_INDEX), p_elements, 0, dst_offsets, dst_vertex_stride, dst_attribute_stride, dst_skin_stride); + + vertex_data.resize(dst_vertex_stride * p_elements); + attribute_data.resize(dst_attribute_stride * p_elements); + skin_data.resize(dst_skin_stride * p_elements); + + uint8_t *dst_vertex_ptr = vertex_data.ptrw(); + uint8_t *dst_attribute_ptr = attribute_data.ptrw(); + uint8_t *dst_skin_ptr = skin_data.ptrw(); + + const uint8_t *src_vertex_ptr = p_src.ptr(); + uint32_t src_vertex_stride = p_src.size() / p_elements; + + uint32_t src_offset = 0; + for (uint32_t j = 0; j < OLD_ARRAY_INDEX; j++) { + if (!(p_old_format & (1 << j))) { + continue; + } + switch (j) { + case OLD_ARRAY_VERTEX: { + if (p_old_format & OLD_ARRAY_FLAG_USE_2D_VERTICES) { + if (p_old_format & OLD_ARRAY_COMPRESS_VERTEX) { + for (uint32_t i = 0; i < p_elements; i++) { + const uint16_t *src = (const uint16_t *)&src_vertex_ptr[i * src_vertex_stride]; + float *dst = (float *)&dst_vertex_ptr[i * dst_vertex_stride]; + dst[0] = Math::half_to_float(src[0]); + dst[1] = Math::half_to_float(src[1]); + } + src_offset += sizeof(uint16_t) * 2; + } else { + for (uint32_t i = 0; i < p_elements; i++) { + const float *src = (const float *)&src_vertex_ptr[i * src_vertex_stride]; + float *dst = (float *)&dst_vertex_ptr[i * dst_vertex_stride]; + dst[0] = src[0]; + dst[1] = src[1]; + } + src_offset += sizeof(float) * 2; + } } else { - src += 12; - remaining -= 12; + if (p_old_format & OLD_ARRAY_COMPRESS_VERTEX) { + for (uint32_t i = 0; i < p_elements; i++) { + const uint16_t *src = (const uint16_t *)&src_vertex_ptr[i * src_vertex_stride]; + float *dst = (float *)&dst_vertex_ptr[i * dst_vertex_stride]; + dst[0] = Math::half_to_float(src[0]); + dst[1] = Math::half_to_float(src[1]); + dst[2] = Math::half_to_float(src[2]); + } + src_offset += sizeof(uint16_t) * 4; //+pad + } else { + for (uint32_t i = 0; i < p_elements; i++) { + const float *src = (const float *)&src_vertex_ptr[i * src_vertex_stride]; + float *dst = (float *)&dst_vertex_ptr[i * dst_vertex_stride]; + dst[0] = src[0]; + dst[1] = src[1]; + dst[2] = src[2]; + } + src_offset += sizeof(float) * 3; + } } - dst += 12; - } else { - if (vertex_16bit) { - float *dstw = (float *)dst; - const uint16_t *srcr = (const uint16_t *)src; - dstw[0] = Math::half_to_float(srcr[0]); - dstw[1] = Math::half_to_float(srcr[1]); - remaining -= 4; - src += 4; + } break; + case OLD_ARRAY_NORMAL: { + if (p_old_format & OLD_ARRAY_COMPRESS_NORMAL) { + const float multiplier = 1.f / 127.f * 1023.0f; + + for (uint32_t i = 0; i < p_elements; i++) { + const int8_t *src = (const int8_t *)&src_vertex_ptr[i * src_vertex_stride + src_offset]; + uint32_t *dst = (uint32_t *)&dst_vertex_ptr[i * dst_vertex_stride + dst_offsets[Mesh::ARRAY_NORMAL]]; + + *dst = 0; + *dst |= CLAMP(int(src[0] * multiplier), 0, 1023); + *dst |= CLAMP(int(src[1] * multiplier), 0, 1023) << 10; + *dst |= CLAMP(int(src[2] * multiplier), 0, 1023) << 20; + } + src_offset += sizeof(uint32_t); } else { - src += 8; - remaining -= 8; + for (uint32_t i = 0; i < p_elements; i++) { + const float *src = (const float *)&src_vertex_ptr[i * src_vertex_stride + src_offset]; + uint32_t *dst = (uint32_t *)&dst_vertex_ptr[i * dst_vertex_stride + dst_offsets[Mesh::ARRAY_NORMAL]]; + + *dst = 0; + *dst |= CLAMP(int(src[0] * 1023.0), 0, 1023); + *dst |= CLAMP(int(src[1] * 1023.0), 0, 1023) << 10; + *dst |= CLAMP(int(src[2] * 1023.0), 0, 1023) << 20; + } + src_offset += sizeof(float) * 3; } - dst += 8; - } - - if (has_bones) { - remaining -= bone_8 ? 4 : 8; - remaining -= weight_32 ? 16 : 8; - } - - for (uint32_t j = 0; j < remaining; j++) { - dst[j] = src[j]; - } - - if (has_bones) { - dst += remaining; - src += remaining; - if (bone_8) { - const uint8_t *src_bones = (const uint8_t *)src; - uint16_t *dst_bones = (uint16_t *)dst; + } break; + case OLD_ARRAY_TANGENT: { + if (p_old_format & OLD_ARRAY_COMPRESS_TANGENT) { + const float multiplier = 1.f / 127.f * 1023.0f; + + for (uint32_t i = 0; i < p_elements; i++) { + const int8_t *src = (const int8_t *)&src_vertex_ptr[i * src_vertex_stride + src_offset]; + uint32_t *dst = (uint32_t *)&dst_vertex_ptr[i * dst_vertex_stride + dst_offsets[Mesh::ARRAY_TANGENT]]; + + *dst = 0; + *dst |= CLAMP(int(src[0] * multiplier), 0, 1023); + *dst |= CLAMP(int(src[1] * multiplier), 0, 1023) << 10; + *dst |= CLAMP(int(src[2] * multiplier), 0, 1023) << 20; + if (src[3] > 0) { + *dst |= 3 << 30; + } + } + src_offset += sizeof(uint32_t); + } else { + for (uint32_t i = 0; i < p_elements; i++) { + const float *src = (const float *)&src_vertex_ptr[i * src_vertex_stride + src_offset]; + uint32_t *dst = (uint32_t *)&dst_vertex_ptr[i * dst_vertex_stride + dst_offsets[Mesh::ARRAY_TANGENT]]; + + *dst = 0; + *dst |= CLAMP(int(src[0] * 1023.0), 0, 1023); + *dst |= CLAMP(int(src[1] * 1023.0), 0, 1023) << 10; + *dst |= CLAMP(int(src[2] * 1023.0), 0, 1023) << 20; + if (src[3] > 0) { + *dst |= 3 << 30; + } + } + src_offset += sizeof(float) * 4; + } - dst_bones[0] = src_bones[0]; - dst_bones[1] = src_bones[1]; - dst_bones[2] = src_bones[2]; - dst_bones[3] = src_bones[3]; + } break; + case OLD_ARRAY_COLOR: { + if (p_old_format & OLD_ARRAY_COMPRESS_COLOR) { + for (uint32_t i = 0; i < p_elements; i++) { + const uint32_t *src = (const uint32_t *)&src_vertex_ptr[i * src_vertex_stride + src_offset]; + uint32_t *dst = (uint32_t *)&dst_attribute_ptr[i * dst_attribute_stride + dst_offsets[Mesh::ARRAY_COLOR]]; - src += 4; + *dst = *src; + } + src_offset += sizeof(uint32_t); } else { - for (uint32_t j = 0; j < 8; j++) { - dst[j] = src[j]; + for (uint32_t i = 0; i < p_elements; i++) { + const float *src = (const float *)&src_vertex_ptr[i * src_vertex_stride + src_offset]; + uint8_t *dst = (uint8_t *)&dst_attribute_ptr[i * dst_attribute_stride + dst_offsets[Mesh::ARRAY_COLOR]]; + + dst[0] = uint8_t(CLAMP(src[0] * 255.0, 0.0, 255.0)); + dst[1] = uint8_t(CLAMP(src[1] * 255.0, 0.0, 255.0)); + dst[2] = uint8_t(CLAMP(src[2] * 255.0, 0.0, 255.0)); + dst[3] = uint8_t(CLAMP(src[3] * 255.0, 0.0, 255.0)); } - - src += 8; + src_offset += sizeof(float) * 4; } + } break; + case OLD_ARRAY_TEX_UV: { + if (p_old_format & OLD_ARRAY_COMPRESS_TEX_UV) { + for (uint32_t i = 0; i < p_elements; i++) { + const uint16_t *src = (const uint16_t *)&src_vertex_ptr[i * src_vertex_stride + src_offset]; + float *dst = (float *)&dst_attribute_ptr[i * dst_attribute_stride + dst_offsets[Mesh::ARRAY_TEX_UV]]; + + dst[0] = Math::half_to_float(src[0]); + dst[1] = Math::half_to_float(src[1]); + } + src_offset += sizeof(uint16_t) * 2; + } else { + for (uint32_t i = 0; i < p_elements; i++) { + const float *src = (const float *)&src_vertex_ptr[i * src_vertex_stride + src_offset]; + float *dst = (float *)&dst_attribute_ptr[i * dst_attribute_stride + dst_offsets[Mesh::ARRAY_TEX_UV]]; - dst += 8; + dst[0] = src[0]; + dst[1] = src[1]; + } + src_offset += sizeof(float) * 2; + } - if (weight_32) { - const float *src_weights = (const float *)src; - uint16_t *dst_weights = (uint16_t *)dst; + } break; + case OLD_ARRAY_TEX_UV2: { + if (p_old_format & OLD_ARRAY_COMPRESS_TEX_UV2) { + for (uint32_t i = 0; i < p_elements; i++) { + const uint16_t *src = (const uint16_t *)&src_vertex_ptr[i * src_vertex_stride + src_offset]; + float *dst = (float *)&dst_attribute_ptr[i * dst_attribute_stride + dst_offsets[Mesh::ARRAY_TEX_UV2]]; - dst_weights[0] = CLAMP(src_weights[0] * 65535, 0, 65535); //16bits unorm - dst_weights[1] = CLAMP(src_weights[1] * 65535, 0, 65535); - dst_weights[2] = CLAMP(src_weights[2] * 65535, 0, 65535); - dst_weights[3] = CLAMP(src_weights[3] * 65535, 0, 65535); + dst[0] = Math::half_to_float(src[0]); + dst[1] = Math::half_to_float(src[1]); + } + src_offset += sizeof(uint16_t) * 2; + } else { + for (uint32_t i = 0; i < p_elements; i++) { + const float *src = (const float *)&src_vertex_ptr[i * src_vertex_stride + src_offset]; + float *dst = (float *)&dst_attribute_ptr[i * dst_attribute_stride + dst_offsets[Mesh::ARRAY_TEX_UV2]]; + dst[0] = src[0]; + dst[1] = src[1]; + } + src_offset += sizeof(float) * 2; + } + } break; + case OLD_ARRAY_BONES: { + if (p_old_format & OLD_ARRAY_FLAG_USE_16_BIT_BONES) { + for (uint32_t i = 0; i < p_elements; i++) { + const uint16_t *src = (const uint16_t *)&src_vertex_ptr[i * src_vertex_stride + src_offset]; + uint16_t *dst = (uint16_t *)&dst_skin_ptr[i * dst_skin_stride + dst_offsets[Mesh::ARRAY_BONES]]; + + dst[0] = src[0]; + dst[1] = src[1]; + dst[2] = src[2]; + dst[3] = src[3]; + } + src_offset += sizeof(uint16_t) * 4; } else { - for (uint32_t j = 0; j < 8; j++) { - dst[j] = src[j]; + for (uint32_t i = 0; i < p_elements; i++) { + const uint8_t *src = (const uint8_t *)&src_vertex_ptr[i * src_vertex_stride + src_offset]; + uint16_t *dst = (uint16_t *)&dst_skin_ptr[i * dst_skin_stride + dst_offsets[Mesh::ARRAY_BONES]]; + + dst[0] = src[0]; + dst[1] = src[1]; + dst[2] = src[2]; + dst[3] = src[3]; } + src_offset += sizeof(uint8_t) * 4; } + } break; + case OLD_ARRAY_WEIGHTS: { + if (p_old_format & OLD_ARRAY_COMPRESS_WEIGHTS) { + for (uint32_t i = 0; i < p_elements; i++) { + const uint16_t *src = (const uint16_t *)&src_vertex_ptr[i * src_vertex_stride + src_offset]; + uint16_t *dst = (uint16_t *)&dst_skin_ptr[i * dst_skin_stride + dst_offsets[Mesh::ARRAY_WEIGHTS]]; + + dst[0] = src[0]; + dst[1] = src[1]; + dst[2] = src[2]; + dst[3] = src[3]; + } + src_offset += sizeof(uint16_t) * 4; + } else { + for (uint32_t i = 0; i < p_elements; i++) { + const float *src = (const float *)&src_vertex_ptr[i * src_vertex_stride + src_offset]; + uint16_t *dst = (uint16_t *)&dst_skin_ptr[i * dst_skin_stride + dst_offsets[Mesh::ARRAY_WEIGHTS]]; + + dst[0] = uint16_t(CLAMP(src[0] * 65535.0, 0, 65535.0)); + dst[1] = uint16_t(CLAMP(src[1] * 65535.0, 0, 65535.0)); + dst[2] = uint16_t(CLAMP(src[2] * 65535.0, 0, 65535.0)); + dst[3] = uint16_t(CLAMP(src[3] * 65535.0, 0, 65535.0)); + } + src_offset += sizeof(float) * 4; + } + } break; + default: { } } } - - return ret; } -#endif bool ArrayMesh::_set(const StringName &p_name, const Variant &p_value) { String sname = p_name; @@ -779,10 +942,13 @@ bool ArrayMesh::_set(const StringName &p_name, const Variant &p_value) { if (d.has("arrays")) { //oldest format (2.x) ERR_FAIL_COND_V(!d.has("morph_arrays"), false); - add_surface_from_arrays(PrimitiveType(int(d["primitive"])), d["arrays"], d["morph_arrays"]); + Array morph_arrays = d["morph_arrays"]; + for (int i = 0; i < morph_arrays.size(); i++) { + morph_arrays[i] = _convert_old_array(morph_arrays[i]); + } + add_surface_from_arrays(_old_primitives[int(d["primitive"])], _convert_old_array(d["arrays"]), morph_arrays); } else if (d.has("array_data")) { -#if 0 //print_line("array data (old style"); //older format (3.x) Vector<uint8_t> array_data = d["array_data"]; @@ -792,48 +958,76 @@ bool ArrayMesh::_set(const StringName &p_name, const Variant &p_value) { } ERR_FAIL_COND_V(!d.has("format"), false); - uint32_t format = d["format"]; + uint32_t old_format = d["format"]; uint32_t primitive = d["primitive"]; - uint32_t primitive_remap[7] = { - PRIMITIVE_POINTS, - PRIMITIVE_LINES, - PRIMITIVE_LINE_STRIP, - PRIMITIVE_LINES, - PRIMITIVE_TRIANGLES, - PRIMITIVE_TRIANGLE_STRIP, - PRIMITIVE_TRIANGLE_STRIP - }; - - primitive = primitive_remap[primitive]; //compatibility + primitive = _old_primitives[primitive]; //compatibility ERR_FAIL_COND_V(!d.has("vertex_count"), false); int vertex_count = d["vertex_count"]; - array_data = _fix_array_compatibility(array_data, format, vertex_count); + uint32_t new_format = ARRAY_FORMAT_VERTEX; + + if (old_format & OLD_ARRAY_FORMAT_NORMAL) { + new_format |= ARRAY_FORMAT_NORMAL; + } + if (old_format & OLD_ARRAY_FORMAT_TANGENT) { + new_format |= ARRAY_FORMAT_TANGENT; + } + if (old_format & OLD_ARRAY_FORMAT_COLOR) { + new_format |= ARRAY_FORMAT_COLOR; + } + if (old_format & OLD_ARRAY_FORMAT_TEX_UV) { + new_format |= ARRAY_FORMAT_TEX_UV; + } + if (old_format & OLD_ARRAY_FORMAT_TEX_UV2) { + new_format |= ARRAY_FORMAT_TEX_UV2; + } + if (old_format & OLD_ARRAY_FORMAT_BONES) { + new_format |= ARRAY_FORMAT_BONES; + } + if (old_format & OLD_ARRAY_FORMAT_WEIGHTS) { + new_format |= ARRAY_FORMAT_WEIGHTS; + } + if (old_format & OLD_ARRAY_FORMAT_INDEX) { + new_format |= ARRAY_FORMAT_INDEX; + } + if (old_format & OLD_ARRAY_FLAG_USE_2D_VERTICES) { + new_format |= OLD_ARRAY_FLAG_USE_2D_VERTICES; + } + + Vector<uint8_t> vertex_array; + Vector<uint8_t> attribute_array; + Vector<uint8_t> skin_array; + + _fix_array_compatibility(array_data, old_format, new_format, vertex_count, vertex_array, attribute_array, skin_array); int index_count = 0; if (d.has("index_count")) { index_count = d["index_count"]; } - Vector<Vector<uint8_t>> blend_shapes; + Vector<uint8_t> blend_shapes; if (d.has("blend_shape_data")) { Array blend_shape_data = d["blend_shape_data"]; for (int i = 0; i < blend_shape_data.size(); i++) { + Vector<uint8_t> blend_vertex_array; + Vector<uint8_t> blend_attribute_array; + Vector<uint8_t> blend_skin_array; + Vector<uint8_t> shape = blend_shape_data[i]; - shape = _fix_array_compatibility(shape, format, vertex_count); + _fix_array_compatibility(shape, old_format, new_format, vertex_count, blend_vertex_array, blend_attribute_array, blend_skin_array); - blend_shapes.push_back(shape); + blend_shapes.append_array(blend_vertex_array); } } //clear unused flags - print_line("format pre: " + itos(format)); - format &= ~uint32_t((1 << (ARRAY_VERTEX + ARRAY_COMPRESS_BASE)) | (ARRAY_COMPRESS_INDEX << 2) | (ARRAY_COMPRESS_TEX_UV2 << 2)); - print_line("format post: " + itos(format)); + print_line("format pre: " + itos(old_format)); + + print_line("format post: " + itos(new_format)); ERR_FAIL_COND_V(!d.has("aabb"), false); AABB aabb = d["aabb"]; @@ -848,8 +1042,8 @@ bool ArrayMesh::_set(const StringName &p_name, const Variant &p_value) { } } - add_surface(format, PrimitiveType(primitive), array_data, vertex_count, array_index_data, index_count, aabb, blend_shapes, bone_aabb); -#endif + add_surface(new_format, PrimitiveType(primitive), vertex_array, attribute_array, skin_array, vertex_count, array_index_data, index_count, aabb, blend_shapes, bone_aabb); + } else { ERR_FAIL_V(false); } @@ -1120,9 +1314,9 @@ void ArrayMesh::_get_property_list(List<PropertyInfo> *p_list) const { for (int i = 0; i < surfaces.size(); i++) { p_list->push_back(PropertyInfo(Variant::STRING, "surface_" + itos(i + 1) + "/name", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR)); if (surfaces[i].is_2d) { - p_list->push_back(PropertyInfo(Variant::OBJECT, "surface_" + itos(i + 1) + "/material", PROPERTY_HINT_RESOURCE_TYPE, "ShaderMaterial,CanvasItemMaterial", PROPERTY_USAGE_EDITOR)); + p_list->push_back(PropertyInfo(Variant::OBJECT, "surface_" + itos(i + 1) + "/material", PROPERTY_HINT_RESOURCE_TYPE, "CanvasItemMaterial,ShaderMaterial", PROPERTY_USAGE_EDITOR)); } else { - p_list->push_back(PropertyInfo(Variant::OBJECT, "surface_" + itos(i + 1) + "/material", PROPERTY_HINT_RESOURCE_TYPE, "ShaderMaterial,StandardMaterial3D", PROPERTY_USAGE_EDITOR)); + p_list->push_back(PropertyInfo(Variant::OBJECT, "surface_" + itos(i + 1) + "/material", PROPERTY_HINT_RESOURCE_TYPE, "BaseMaterial3D,ShaderMaterial", PROPERTY_USAGE_EDITOR)); } } } @@ -1335,9 +1529,21 @@ String ArrayMesh::surface_get_name(int p_idx) const { return surfaces[p_idx].name; } -void ArrayMesh::surface_update_region(int p_surface, int p_offset, const Vector<uint8_t> &p_data) { +void ArrayMesh::surface_update_vertex_region(int p_surface, int p_offset, const Vector<uint8_t> &p_data) { + ERR_FAIL_INDEX(p_surface, surfaces.size()); + RS::get_singleton()->mesh_surface_update_vertex_region(mesh, p_surface, p_offset, p_data); + emit_changed(); +} + +void ArrayMesh::surface_update_attribute_region(int p_surface, int p_offset, const Vector<uint8_t> &p_data) { + ERR_FAIL_INDEX(p_surface, surfaces.size()); + RS::get_singleton()->mesh_surface_update_attribute_region(mesh, p_surface, p_offset, p_data); + emit_changed(); +} + +void ArrayMesh::surface_update_skin_region(int p_surface, int p_offset, const Vector<uint8_t> &p_data) { ERR_FAIL_INDEX(p_surface, surfaces.size()); - RS::get_singleton()->mesh_surface_update_region(mesh, p_surface, p_offset, p_data); + RS::get_singleton()->mesh_surface_update_skin_region(mesh, p_surface, p_offset, p_data); emit_changed(); } @@ -1537,7 +1743,7 @@ Error ArrayMesh::lightmap_unwrap_cached(const Transform3D &p_base_transform, flo for (int i = 0; i < lightmap_surfaces.size(); i++) { Ref<SurfaceTool> st; - st.instance(); + st.instantiate(); st->begin(Mesh::PRIMITIVE_TRIANGLES); st->set_material(lightmap_surfaces[i].material); surfaces_tools.push_back(st); //stay there @@ -1635,7 +1841,9 @@ void ArrayMesh::_bind_methods() { ClassDB::bind_method(D_METHOD("add_surface_from_arrays", "primitive", "arrays", "blend_shapes", "lods", "compress_flags"), &ArrayMesh::add_surface_from_arrays, DEFVAL(Array()), DEFVAL(Dictionary()), DEFVAL(0)); ClassDB::bind_method(D_METHOD("clear_surfaces"), &ArrayMesh::clear_surfaces); - ClassDB::bind_method(D_METHOD("surface_update_region", "surf_idx", "offset", "data"), &ArrayMesh::surface_update_region); + ClassDB::bind_method(D_METHOD("surface_update_vertex_region", "surf_idx", "offset", "data"), &ArrayMesh::surface_update_vertex_region); + ClassDB::bind_method(D_METHOD("surface_update_attribute_region", "surf_idx", "offset", "data"), &ArrayMesh::surface_update_attribute_region); + ClassDB::bind_method(D_METHOD("surface_update_skin_region", "surf_idx", "offset", "data"), &ArrayMesh::surface_update_skin_region); ClassDB::bind_method(D_METHOD("surface_get_array_len", "surf_idx"), &ArrayMesh::surface_get_array_len); ClassDB::bind_method(D_METHOD("surface_get_array_index_len", "surf_idx"), &ArrayMesh::surface_get_array_index_len); ClassDB::bind_method(D_METHOD("surface_get_format", "surf_idx"), &ArrayMesh::surface_get_format); diff --git a/scene/resources/mesh.h b/scene/resources/mesh.h index 2dfb46782b..02cab9a5e1 100644 --- a/scene/resources/mesh.h +++ b/scene/resources/mesh.h @@ -233,7 +233,9 @@ public: void set_blend_shape_mode(BlendShapeMode p_mode); BlendShapeMode get_blend_shape_mode() const; - void surface_update_region(int p_surface, int p_offset, const Vector<uint8_t> &p_data); + void surface_update_vertex_region(int p_surface, int p_offset, const Vector<uint8_t> &p_data); + void surface_update_attribute_region(int p_surface, int p_offset, const Vector<uint8_t> &p_data); + void surface_update_skin_region(int p_surface, int p_offset, const Vector<uint8_t> &p_data); int get_surface_count() const override; diff --git a/scene/resources/navigation_mesh.cpp b/scene/resources/navigation_mesh.cpp index 0a25bb2ed1..d2be2bdba1 100644 --- a/scene/resources/navigation_mesh.cpp +++ b/scene/resources/navigation_mesh.cpp @@ -501,14 +501,14 @@ void NavigationMesh::_bind_methods() { void NavigationMesh::_validate_property(PropertyInfo &property) const { if (property.name == "geometry/collision_mask") { if (parsed_geometry_type == PARSED_GEOMETRY_MESH_INSTANCES) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; return; } } if (property.name == "geometry/source_group_name") { if (source_geometry_mode == SOURCE_GEOMETRY_NAVMESH_CHILDREN) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; return; } } diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp index ab8a4b7934..9bb2a4ddb8 100644 --- a/scene/resources/packed_scene.cpp +++ b/scene/resources/packed_scene.cpp @@ -41,11 +41,11 @@ #define PACKED_SCENE_VERSION 2 -bool SceneState::can_instance() const { +bool SceneState::can_instantiate() const { return nodes.size() > 0; } -Node *SceneState::instance(GenEditState p_edit_state) const { +Node *SceneState::instantiate(GenEditState p_edit_state) const { // nodes where instancing failed (because something is missing) List<Node *> stray_instances; @@ -109,7 +109,7 @@ Node *SceneState::instance(GenEditState p_edit_state) const { //scene inheritance on root node Ref<PackedScene> sdata = props[base_scene_idx]; ERR_FAIL_COND_V(!sdata.is_valid(), nullptr); - node = sdata->instance(p_edit_state == GEN_EDIT_STATE_DISABLED ? PackedScene::GEN_EDIT_STATE_DISABLED : PackedScene::GEN_EDIT_STATE_INSTANCE); //only main gets main edit state + node = sdata->instantiate(p_edit_state == GEN_EDIT_STATE_DISABLED ? PackedScene::GEN_EDIT_STATE_DISABLED : PackedScene::GEN_EDIT_STATE_INSTANCE); //only main gets main edit state ERR_FAIL_COND_V(!node, nullptr); if (p_edit_state != GEN_EDIT_STATE_DISABLED) { node->set_scene_inherited_state(sdata->get_state()); @@ -122,7 +122,7 @@ Node *SceneState::instance(GenEditState p_edit_state) const { if (disable_placeholders) { Ref<PackedScene> sdata = ResourceLoader::load(path, "PackedScene"); ERR_FAIL_COND_V(!sdata.is_valid(), nullptr); - node = sdata->instance(p_edit_state == GEN_EDIT_STATE_DISABLED ? PackedScene::GEN_EDIT_STATE_DISABLED : PackedScene::GEN_EDIT_STATE_INSTANCE); + node = sdata->instantiate(p_edit_state == GEN_EDIT_STATE_DISABLED ? PackedScene::GEN_EDIT_STATE_DISABLED : PackedScene::GEN_EDIT_STATE_INSTANCE); ERR_FAIL_COND_V(!node, nullptr); } else { InstancePlaceholder *ip = memnew(InstancePlaceholder); @@ -133,7 +133,7 @@ Node *SceneState::instance(GenEditState p_edit_state) const { } else { Ref<PackedScene> sdata = props[n.instance & FLAG_MASK]; ERR_FAIL_COND_V(!sdata.is_valid(), nullptr); - node = sdata->instance(p_edit_state == GEN_EDIT_STATE_DISABLED ? PackedScene::GEN_EDIT_STATE_DISABLED : PackedScene::GEN_EDIT_STATE_INSTANCE); + node = sdata->instantiate(p_edit_state == GEN_EDIT_STATE_DISABLED ? PackedScene::GEN_EDIT_STATE_DISABLED : PackedScene::GEN_EDIT_STATE_INSTANCE); ERR_FAIL_COND_V(!node, nullptr); } @@ -152,7 +152,7 @@ Node *SceneState::instance(GenEditState p_edit_state) const { if (ClassDB::is_class_enabled(snames[n.type])) { //node belongs to this scene and must be created - obj = ClassDB::instance(snames[n.type]); + obj = ClassDB::instantiate(snames[n.type]); } if (!Object::cast_to<Node>(obj)) { @@ -180,7 +180,7 @@ Node *SceneState::instance(GenEditState p_edit_state) const { } if (node) { - // may not have found the node (part of instanced scene and removed) + // may not have found the node (part of instantiated scene and removed) // if found all is good, otherwise ignore //properties @@ -266,7 +266,7 @@ Node *SceneState::instance(GenEditState p_edit_state) const { parent->move_child(node, n.index); } } else { - //it may be possible that an instanced scene has changed + //it may be possible that an instantiated scene has changed //and the node has nowhere to go anymore stray_instances.push_back(node); //can't be added, go to stray list } @@ -368,7 +368,7 @@ static int _vm_get_variant(const Variant &p_variant, HashMap<Variant, int, Varia Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map<StringName, int> &name_map, HashMap<Variant, int, VariantHasher, VariantComparator> &variant_map, Map<Node *, int> &node_map, Map<Node *, int> &nodepath_map) { // this function handles all the work related to properly packing scenes, be it - // instanced or inherited. + // instantiated or inherited. // given the complexity of this process, an attempt will be made to properly // document it. if you fail to understand something, please ask! @@ -377,7 +377,7 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map return OK; } - // save the child instanced scenes that are chosen as editable, so they can be restored + // save the child instantiated scenes that are chosen as editable, so they can be restored // upon load back if (p_node != p_owner && p_node->get_filename() != String() && p_owner->is_editable_instance(p_node)) { editable_instances.push_back(p_owner->get_path_to(p_node)); @@ -386,7 +386,7 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map NodeData nd; nd.name = _nm_get_string(p_node->get_name(), name_map); - nd.instance = -1; //not instanced by default + nd.instance = -1; //not instantiated by default //really convoluted condition, but it basically checks that index is only saved when part of an inherited scene OR the node parent is from the edited scene if (p_owner->get_scene_inherited_state().is_null() && (p_node == p_owner || (p_node->get_owner() == p_owner && (p_node->get_parent() == p_owner || p_node->get_parent()->get_owner() == p_owner)))) { @@ -396,18 +396,18 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map //This (hopefully) happens if the node is a scene root, so its index is irrelevant. nd.index = -1; } else { - //part of an inherited scene, or parent is from an instanced scene + //part of an inherited scene, or parent is from an instantiated scene nd.index = p_node->get_index(); } - // if this node is part of an instanced scene or sub-instanced scene + // if this node is part of an instantiated scene or sub-instantiated scene // we need to get the corresponding instance states. // with the instance states, we can query for identical properties/groups // and only save what has changed List<PackState> pack_state_stack; - bool instanced_by_owner = true; + bool instantiated_by_owner = true; { Node *n = p_node; @@ -423,11 +423,11 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map ps.node = node; ps.state = state; pack_state_stack.push_back(ps); - instanced_by_owner = false; + instantiated_by_owner = false; } } - if (p_node->get_filename() != String() && p_node->get_owner() == p_owner && instanced_by_owner) { + if (p_node->get_filename() != String() && p_node->get_owner() == p_owner && instantiated_by_owner) { if (p_node->get_scene_instance_load_placeholder()) { //it's a placeholder, use the placeholder path nd.instance = _vm_get_variant(p_node->get_filename(), variant_map); @@ -471,7 +471,9 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map StringName type = p_node->get_class(); Ref<Script> script = p_node->get_script(); - if (script.is_valid()) { + if (Engine::get_singleton()->is_editor_hint() && script.is_valid()) { + // Should be called in the editor only and not at runtime, + // otherwise it can cause problems because of missing instance state support. script->update_exports(); } @@ -500,8 +502,8 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map // } if (pack_state_stack.size()) { - // we are on part of an instanced subscene - // or part of instanced scene. + // we are on part of an instantiated subscene + // or part of instantiated scene. // only save what has been changed // only save changed properties in instance @@ -571,7 +573,7 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map } /* if (instance_state_node>=0 && instance_state->is_node_in_group(instance_state_node,gi.name)) - continue; //group was instanced, don't add here + continue; //group was instantiated, don't add here */ bool skip = false; @@ -594,7 +596,7 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map // save the right owner // for the saved scene root this is -1 // for nodes of the saved scene this is 0 - // for nodes of instanced scenes this is >0 + // for nodes of instantiated scenes this is >0 if (p_node == p_owner) { //saved scene root @@ -612,20 +614,20 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map //this node is not part of an instancing process, so save the type nd.type = _nm_get_string(p_node->get_class(), name_map); } else { - // this node is part of an instanced process, so do not save the type. - // instead, save that it was instanced + // this node is part of an instantiated process, so do not save the type. + // instead, save that it was instantiated nd.type = TYPE_INSTANCED; } // determine whether to save this node or not - // if this node is part of an instanced sub-scene, we can skip storing it if basically + // if this node is part of an instantiated sub-scene, we can skip storing it if basically // no properties changed and no groups were added to it. // below condition is true for all nodes of the scene being saved, and ones in subscenes // that hold changes bool save_node = nd.properties.size() || nd.groups.size(); // some local properties or groups exist save_node = save_node || p_node == p_owner; // owner is always saved - save_node = save_node || (p_node->get_owner() == p_owner && instanced_by_owner); //part of scene and not instanced + save_node = save_node || (p_node->get_owner() == p_owner && instantiated_by_owner); //part of scene and not instantiated int idx = nodes.size(); int parent_node = NO_PARENT_SAVED; @@ -893,6 +895,13 @@ Error SceneState::pack(Node *p_scene) { node_paths.write[E->get()] = scene->get_path_to(E->key()); } + if (Engine::get_singleton()->is_editor_hint()) { + // Build node path cache + for (Map<Node *, int>::Element *E = node_map.front(); E; E = E->next()) { + node_path_cache[scene->get_path_to(E->key())] = E->get(); + } + } + return OK; } @@ -927,10 +936,12 @@ Ref<SceneState> SceneState::_get_base_scene_state() const { } int SceneState::find_node_by_path(const NodePath &p_node) const { + ERR_FAIL_COND_V_MSG(node_path_cache.size() == 0, -1, "This operation requires the node cache to have been built."); + if (!node_path_cache.has(p_node)) { if (_get_base_scene_state().is_valid()) { int idx = _get_base_scene_state()->find_node_by_path(p_node); - if (idx >= 0) { + if (idx != -1) { int rkey = _find_base_scene_node_remap_key(idx); if (rkey == -1) { rkey = nodes.size() + base_scene_node_remap.size(); @@ -946,7 +957,7 @@ int SceneState::find_node_by_path(const NodePath &p_node) const { if (_get_base_scene_state().is_valid() && !base_scene_node_remap.has(nid)) { //for nodes that _do_ exist in current scene, still try to look for - //the node in the instanced scene, as a property may be missing + //the node in the instantiated scene, as a property may be missing //from the local one int idx = _get_base_scene_state()->find_node_by_path(p_node); if (idx != -1) { @@ -1614,16 +1625,16 @@ void PackedScene::clear() { state->clear(); } -bool PackedScene::can_instance() const { - return state->can_instance(); +bool PackedScene::can_instantiate() const { + return state->can_instantiate(); } -Node *PackedScene::instance(GenEditState p_edit_state) const { +Node *PackedScene::instantiate(GenEditState p_edit_state) const { #ifndef TOOLS_ENABLED ERR_FAIL_COND_V_MSG(p_edit_state != GEN_EDIT_STATE_DISABLED, nullptr, "Edit state is only for editors, does not work without tools compiled."); #endif - Node *s = state->instance((SceneState::GenEditState)p_edit_state); + Node *s = state->instantiate((SceneState::GenEditState)p_edit_state); if (!s) { return nullptr; } @@ -1671,8 +1682,8 @@ void PackedScene::reset_state() { } void PackedScene::_bind_methods() { ClassDB::bind_method(D_METHOD("pack", "path"), &PackedScene::pack); - ClassDB::bind_method(D_METHOD("instance", "edit_state"), &PackedScene::instance, DEFVAL(GEN_EDIT_STATE_DISABLED)); - ClassDB::bind_method(D_METHOD("can_instance"), &PackedScene::can_instance); + ClassDB::bind_method(D_METHOD("instantiate", "edit_state"), &PackedScene::instantiate, DEFVAL(GEN_EDIT_STATE_DISABLED)); + ClassDB::bind_method(D_METHOD("can_instantiate"), &PackedScene::can_instantiate); ClassDB::bind_method(D_METHOD("_set_bundled_scene"), &PackedScene::_set_bundled_scene); ClassDB::bind_method(D_METHOD("_get_bundled_scene"), &PackedScene::_get_bundled_scene); ClassDB::bind_method(D_METHOD("get_state"), &PackedScene::get_state); diff --git a/scene/resources/packed_scene.h b/scene/resources/packed_scene.h index e85b933439..55708f7914 100644 --- a/scene/resources/packed_scene.h +++ b/scene/resources/packed_scene.h @@ -136,8 +136,8 @@ public: void clear(); - bool can_instance() const; - Node *instance(GenEditState p_edit_state) const; + bool can_instantiate() const; + Node *instantiate(GenEditState p_edit_state) const; //unbuild API @@ -213,8 +213,8 @@ public: void clear(); - bool can_instance() const; - Node *instance(GenEditState p_edit_state = GEN_EDIT_STATE_DISABLED) const; + bool can_instantiate() const; + Node *instantiate(GenEditState p_edit_state = GEN_EDIT_STATE_DISABLED) const; void recreate_state(); void replace_state(Ref<SceneState> p_by); diff --git a/scene/resources/particles_material.cpp b/scene/resources/particles_material.cpp index 60d5566f08..2bde98abe0 100644 --- a/scene/resources/particles_material.cpp +++ b/scene/resources/particles_material.cpp @@ -852,52 +852,54 @@ void ParticlesMaterial::set_param_texture(Parameter p_param, const Ref<Texture2D tex_parameters[p_param] = p_texture; + RID tex_rid = p_texture.is_valid() ? p_texture->get_rid() : RID(); + switch (p_param) { case PARAM_INITIAL_LINEAR_VELOCITY: { //do none for this one } break; case PARAM_ANGULAR_VELOCITY: { - RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->angular_velocity_texture, p_texture); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->angular_velocity_texture, tex_rid); _adjust_curve_range(p_texture, -360, 360); } break; case PARAM_ORBIT_VELOCITY: { - RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->orbit_velocity_texture, p_texture); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->orbit_velocity_texture, tex_rid); _adjust_curve_range(p_texture, -500, 500); } break; case PARAM_LINEAR_ACCEL: { - RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->linear_accel_texture, p_texture); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->linear_accel_texture, tex_rid); _adjust_curve_range(p_texture, -200, 200); } break; case PARAM_RADIAL_ACCEL: { - RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->radial_accel_texture, p_texture); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->radial_accel_texture, tex_rid); _adjust_curve_range(p_texture, -200, 200); } break; case PARAM_TANGENTIAL_ACCEL: { - RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->tangent_accel_texture, p_texture); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->tangent_accel_texture, tex_rid); _adjust_curve_range(p_texture, -200, 200); } break; case PARAM_DAMPING: { - RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->damping_texture, p_texture); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->damping_texture, tex_rid); _adjust_curve_range(p_texture, 0, 100); } break; case PARAM_ANGLE: { - RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->angle_texture, p_texture); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->angle_texture, tex_rid); _adjust_curve_range(p_texture, -360, 360); } break; case PARAM_SCALE: { - RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->scale_texture, p_texture); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->scale_texture, tex_rid); _adjust_curve_range(p_texture, 0, 1); } break; case PARAM_HUE_VARIATION: { - RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->hue_variation_texture, p_texture); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->hue_variation_texture, tex_rid); _adjust_curve_range(p_texture, -1, 1); } break; case PARAM_ANIM_SPEED: { - RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->anim_speed_texture, p_texture); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->anim_speed_texture, tex_rid); _adjust_curve_range(p_texture, 0, 200); } break; case PARAM_ANIM_OFFSET: { - RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->anim_offset_texture, p_texture); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->anim_offset_texture, tex_rid); } break; case PARAM_MAX: break; // Can't happen, but silences warning @@ -923,7 +925,8 @@ Color ParticlesMaterial::get_color() const { void ParticlesMaterial::set_color_ramp(const Ref<Texture2D> &p_texture) { color_ramp = p_texture; - RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->color_ramp, p_texture); + RID tex_rid = p_texture.is_valid() ? p_texture->get_rid() : RID(); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->color_ramp, tex_rid); _queue_shader_change(); notify_property_list_changed(); } @@ -965,17 +968,20 @@ void ParticlesMaterial::set_emission_box_extents(Vector3 p_extents) { void ParticlesMaterial::set_emission_point_texture(const Ref<Texture2D> &p_points) { emission_point_texture = p_points; - RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_texture_points, p_points); + RID tex_rid = p_points.is_valid() ? p_points->get_rid() : RID(); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_texture_points, tex_rid); } void ParticlesMaterial::set_emission_normal_texture(const Ref<Texture2D> &p_normals) { emission_normal_texture = p_normals; - RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_texture_normal, p_normals); + RID tex_rid = p_normals.is_valid() ? p_normals->get_rid() : RID(); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_texture_normal, tex_rid); } void ParticlesMaterial::set_emission_color_texture(const Ref<Texture2D> &p_colors) { emission_color_texture = p_colors; - RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_texture_color, p_colors); + RID tex_rid = p_colors.is_valid() ? p_colors->get_rid() : RID(); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_texture_color, tex_rid); _queue_shader_change(); } @@ -1041,39 +1047,39 @@ RID ParticlesMaterial::get_shader_rid() const { void ParticlesMaterial::_validate_property(PropertyInfo &property) const { if (property.name == "color" && color_ramp.is_valid()) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } if (property.name == "emission_sphere_radius" && emission_shape != EMISSION_SHAPE_SPHERE) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } if (property.name == "emission_box_extents" && emission_shape != EMISSION_SHAPE_BOX) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } if ((property.name == "emission_point_texture" || property.name == "emission_color_texture") && (emission_shape < EMISSION_SHAPE_POINTS)) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } if (property.name == "emission_normal_texture" && emission_shape != EMISSION_SHAPE_DIRECTED_POINTS) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } if (property.name == "emission_point_count" && (emission_shape != EMISSION_SHAPE_POINTS && emission_shape != EMISSION_SHAPE_DIRECTED_POINTS)) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } if (property.name == "sub_emitter_frequency" && sub_emitter_mode != SUB_EMITTER_CONSTANT) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } if (property.name == "sub_emitter_amount_at_end" && sub_emitter_mode != SUB_EMITTER_AT_END) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } if (property.name.begins_with("orbit_") && !particle_flags[PARTICLE_FLAG_DISABLE_Z]) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } } @@ -1292,7 +1298,7 @@ void ParticlesMaterial::_bind_methods() { ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "damping_random", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_param_randomness", "get_param_randomness", PARAM_DAMPING); ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "damping_curve", PROPERTY_HINT_RESOURCE_TYPE, "CurveTexture"), "set_param_texture", "get_param_texture", PARAM_DAMPING); ADD_GROUP("Angle", ""); - ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angle", PROPERTY_HINT_RANGE, "-720,720,0.1,or_lesser,or_greater"), "set_param", "get_param", PARAM_ANGLE); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angle", PROPERTY_HINT_RANGE, "-720,720,0.1,or_lesser,or_greater,degrees"), "set_param", "get_param", PARAM_ANGLE); ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angle_random", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_param_randomness", "get_param_randomness", PARAM_ANGLE); ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "angle_curve", PROPERTY_HINT_RESOURCE_TYPE, "CurveTexture"), "set_param_texture", "get_param_texture", PARAM_ANGLE); ADD_GROUP("Scale", ""); diff --git a/scene/resources/primitive_meshes.cpp b/scene/resources/primitive_meshes.cpp index a745df522b..dfa45cc810 100644 --- a/scene/resources/primitive_meshes.cpp +++ b/scene/resources/primitive_meshes.cpp @@ -207,7 +207,7 @@ void PrimitiveMesh::_bind_methods() { ClassDB::bind_method(D_METHOD("set_flip_faces", "flip_faces"), &PrimitiveMesh::set_flip_faces); ClassDB::bind_method(D_METHOD("get_flip_faces"), &PrimitiveMesh::get_flip_faces); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "ShaderMaterial,StandardMaterial3D"), "set_material", "get_material"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "BaseMaterial3D,ShaderMaterial"), "set_material", "get_material"); ADD_PROPERTY(PropertyInfo(Variant::AABB, "custom_aabb", PROPERTY_HINT_NONE, ""), "set_custom_aabb", "get_custom_aabb"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "flip_faces"), "set_flip_faces", "get_flip_faces"); } @@ -714,7 +714,7 @@ int BoxMesh::get_subdivide_depth() const { BoxMesh::BoxMesh() {} /** - CylinderMesh + CylinderMesh */ void CylinderMesh::_create_mesh_array(Array &p_arr) const { @@ -866,9 +866,9 @@ void CylinderMesh::_bind_methods() { ClassDB::bind_method(D_METHOD("set_rings", "rings"), &CylinderMesh::set_rings); ClassDB::bind_method(D_METHOD("get_rings"), &CylinderMesh::get_rings); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "top_radius", PROPERTY_HINT_RANGE, "0.001,100.0,0.001,or_greater"), "set_top_radius", "get_top_radius"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "bottom_radius", PROPERTY_HINT_RANGE, "0.001,100.0,0.001,or_greater"), "set_bottom_radius", "get_bottom_radius"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "height", PROPERTY_HINT_RANGE, "0.001,100.0,0.001,or_greater"), "set_height", "get_height"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "top_radius", PROPERTY_HINT_RANGE, "0,100,0.001,or_greater"), "set_top_radius", "get_top_radius"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "bottom_radius", PROPERTY_HINT_RANGE, "0,100,0.001,or_greater"), "set_bottom_radius", "get_bottom_radius"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "height", PROPERTY_HINT_RANGE, "0.001,100,0.001,or_greater"), "set_height", "get_height"); ADD_PROPERTY(PropertyInfo(Variant::INT, "radial_segments", PROPERTY_HINT_RANGE, "1,100,1,or_greater"), "set_radial_segments", "get_radial_segments"); ADD_PROPERTY(PropertyInfo(Variant::INT, "rings", PROPERTY_HINT_RANGE, "1,100,1,or_greater"), "set_rings", "get_rings"); } @@ -955,7 +955,7 @@ void PlaneMesh::_create_mesh_array(Array &p_arr) const { u /= (subdivide_w + 1.0); v /= (subdivide_d + 1.0); - points.push_back(Vector3(-x, 0.0, -z)); + points.push_back(Vector3(-x, 0.0, -z) + center_offset); normals.push_back(Vector3(0.0, 1.0, 0.0)); ADD_TANGENT(1.0, 0.0, 0.0, 1.0); uvs.push_back(Vector2(1.0 - u, 1.0 - v)); /* 1.0 - uv to match orientation with Quad */ @@ -993,10 +993,13 @@ void PlaneMesh::_bind_methods() { ClassDB::bind_method(D_METHOD("get_subdivide_width"), &PlaneMesh::get_subdivide_width); ClassDB::bind_method(D_METHOD("set_subdivide_depth", "subdivide"), &PlaneMesh::set_subdivide_depth); ClassDB::bind_method(D_METHOD("get_subdivide_depth"), &PlaneMesh::get_subdivide_depth); + ClassDB::bind_method(D_METHOD("set_center_offset", "offset"), &PlaneMesh::set_center_offset); + ClassDB::bind_method(D_METHOD("get_center_offset"), &PlaneMesh::get_center_offset); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size"), "set_size", "get_size"); ADD_PROPERTY(PropertyInfo(Variant::INT, "subdivide_width", PROPERTY_HINT_RANGE, "0,100,1,or_greater"), "set_subdivide_width", "get_subdivide_width"); ADD_PROPERTY(PropertyInfo(Variant::INT, "subdivide_depth", PROPERTY_HINT_RANGE, "0,100,1,or_greater"), "set_subdivide_depth", "get_subdivide_depth"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "center_offset"), "set_center_offset", "get_center_offset"); } void PlaneMesh::set_size(const Size2 &p_size) { @@ -1026,6 +1029,15 @@ int PlaneMesh::get_subdivide_depth() const { return subdivide_d; } +void PlaneMesh::set_center_offset(const Vector3 p_offset) { + center_offset = p_offset; + _request_update(); +} + +Vector3 PlaneMesh::get_center_offset() const { + return center_offset; +} + PlaneMesh::PlaneMesh() {} /** @@ -1326,10 +1338,10 @@ void QuadMesh::_create_mesh_array(Array &p_arr) const { Vector2 _size = Vector2(size.x / 2.0f, size.y / 2.0f); Vector3 quad_faces[4] = { - Vector3(-_size.x, -_size.y, 0), - Vector3(-_size.x, _size.y, 0), - Vector3(_size.x, _size.y, 0), - Vector3(_size.x, -_size.y, 0), + Vector3(-_size.x, -_size.y, 0) + center_offset, + Vector3(-_size.x, _size.y, 0) + center_offset, + Vector3(_size.x, _size.y, 0) + center_offset, + Vector3(_size.x, -_size.y, 0) + center_offset, }; static const int indices[6] = { @@ -1365,7 +1377,11 @@ void QuadMesh::_create_mesh_array(Array &p_arr) const { void QuadMesh::_bind_methods() { ClassDB::bind_method(D_METHOD("set_size", "size"), &QuadMesh::set_size); ClassDB::bind_method(D_METHOD("get_size"), &QuadMesh::get_size); + ClassDB::bind_method(D_METHOD("set_center_offset", "center_offset"), &QuadMesh::set_center_offset); + ClassDB::bind_method(D_METHOD("get_center_offset"), &QuadMesh::get_center_offset); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size"), "set_size", "get_size"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "center_offset"), "set_center_offset", "get_center_offset"); } QuadMesh::QuadMesh() { @@ -1381,6 +1397,15 @@ Size2 QuadMesh::get_size() const { return size; } +void QuadMesh::set_center_offset(Vector3 p_center_offset) { + center_offset = p_center_offset; + _request_update(); +} + +Vector3 QuadMesh::get_center_offset() const { + return center_offset; +} + /** SphereMesh */ diff --git a/scene/resources/primitive_meshes.h b/scene/resources/primitive_meshes.h index bd6f94921e..a3de34d3e3 100644 --- a/scene/resources/primitive_meshes.h +++ b/scene/resources/primitive_meshes.h @@ -211,6 +211,7 @@ private: Size2 size = Size2(2.0, 2.0); int subdivide_w = 0; int subdivide_d = 0; + Vector3 center_offset; protected: static void _bind_methods(); @@ -226,6 +227,9 @@ public: void set_subdivide_depth(const int p_divisions); int get_subdivide_depth() const; + void set_center_offset(const Vector3 p_offset); + Vector3 get_center_offset() const; + PlaneMesh(); }; @@ -274,6 +278,7 @@ class QuadMesh : public PrimitiveMesh { private: Size2 size = Size2(1.0, 1.0); + Vector3 center_offset; protected: static void _bind_methods(); @@ -284,6 +289,9 @@ public: void set_size(const Size2 &p_size); Size2 get_size() const; + + void set_center_offset(const Vector3 p_offset); + Vector3 get_center_offset() const; }; /** diff --git a/scene/resources/resource_format_text.cpp b/scene/resources/resource_format_text.cpp index 27f0c50a79..ee61e64ed3 100644 --- a/scene/resources/resource_format_text.cpp +++ b/scene/resources/resource_format_text.cpp @@ -65,7 +65,7 @@ Error ResourceLoaderText::_parse_sub_resource_dummy(DummyReadData *p_data, Varia if (!p_data->resource_map.has(index)) { Ref<DummyResource> dr; - dr.instance(); + dr.instantiate(); dr->set_subindex(index); p_data->resource_map[index] = dr; p_data->resource_set.insert(dr); @@ -183,7 +183,7 @@ Error ResourceLoaderText::_parse_ext_resource(VariantParser::Stream *p_stream, R Ref<PackedScene> ResourceLoaderText::_parse_node_tag(VariantParser::ResourceParser &parser) { Ref<PackedScene> packed_scene; - packed_scene.instance(); + packed_scene.instantiate(); while (true) { if (next_tag.name == "node") { @@ -208,7 +208,7 @@ Ref<PackedScene> ResourceLoaderText::_parse_node_tag(VariantParser::ResourcePars if (next_tag.fields.has("type")) { type = packed_scene->get_state()->add_name(next_tag.fields["type"]); } else { - type = SceneState::TYPE_INSTANCED; //no type? assume this was instanced + type = SceneState::TYPE_INSTANCED; //no type? assume this was instantiated } if (next_tag.fields.has("instance")) { @@ -522,7 +522,7 @@ Error ResourceLoaderText::load() { } else { //create - Object *obj = ClassDB::instance(type); + Object *obj = ClassDB::instantiate(type); if (!obj) { error_text += "Can't create sub resource of type: " + type; _printerr(); @@ -604,7 +604,7 @@ Error ResourceLoaderText::load() { } if (!resource.is_valid()) { - Object *obj = ClassDB::instance(res_type); + Object *obj = ClassDB::instantiate(res_type); if (!obj) { error_text += "Can't create sub resource of type: " + res_type; _printerr(); @@ -1022,7 +1022,7 @@ Error ResourceLoaderText::save_as_binary(FileAccess *p_f, const String &p_path) int lindex = dummy_read.external_resources.size(); Ref<DummyResource> dr; - dr.instance(); + dr.instantiate(); dr->set_path("res://dummy" + itos(lindex)); //anything is good to detect it for saving as external dummy_read.external_resources[dr] = lindex; dummy_read.rev_external_resources[index] = dr; diff --git a/scene/resources/shader.cpp b/scene/resources/shader.cpp index cbd44315b7..f19d08dbb1 100644 --- a/scene/resources/shader.cpp +++ b/scene/resources/shader.cpp @@ -167,7 +167,7 @@ RES ResourceFormatLoaderShader::load(const String &p_path, const String &p_origi } Ref<Shader> shader; - shader.instance(); + shader.instantiate(); Vector<uint8_t> buffer = FileAccess::get_file_as_array(p_path); diff --git a/scene/resources/sky_material.cpp b/scene/resources/sky_material.cpp index 9d79c22159..89b3336118 100644 --- a/scene/resources/sky_material.cpp +++ b/scene/resources/sky_material.cpp @@ -270,7 +270,8 @@ ProceduralSkyMaterial::~ProceduralSkyMaterial() { void PanoramaSkyMaterial::set_panorama(const Ref<Texture2D> &p_panorama) { panorama = p_panorama; - RS::get_singleton()->material_set_param(_get_material(), "source_panorama", panorama); + RID tex_rid = p_panorama.is_valid() ? p_panorama->get_rid() : RID(); + RS::get_singleton()->material_set_param(_get_material(), "source_panorama", tex_rid); } Ref<Texture2D> PanoramaSkyMaterial::get_panorama() const { @@ -411,7 +412,8 @@ float PhysicalSkyMaterial::get_dither_strength() const { void PhysicalSkyMaterial::set_night_sky(const Ref<Texture2D> &p_night_sky) { night_sky = p_night_sky; - RS::get_singleton()->material_set_param(_get_material(), "night_sky", night_sky); + RID tex_rid = p_night_sky.is_valid() ? p_night_sky->get_rid() : RID(); + RS::get_singleton()->material_set_param(_get_material(), "night_sky", tex_rid); } Ref<Texture2D> PhysicalSkyMaterial::get_night_sky() const { diff --git a/scene/resources/surface_tool.cpp b/scene/resources/surface_tool.cpp index fee9f92ad7..9f8c35b668 100644 --- a/scene/resources/surface_tool.cpp +++ b/scene/resources/surface_tool.cpp @@ -607,7 +607,7 @@ Ref<ArrayMesh> SurfaceTool::commit(const Ref<ArrayMesh> &p_existing, uint32_t p_ if (p_existing.is_valid()) { mesh = p_existing; } else { - mesh.instance(); + mesh.instantiate(); } int varr_len = vertex_array.size(); diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp index aa85c7116b..98997e482a 100644 --- a/scene/resources/texture.cpp +++ b/scene/resources/texture.cpp @@ -88,7 +88,7 @@ void ImageTexture::reload_from_file() { } Ref<Image> img; - img.instance(); + img.instantiate(); if (ImageLoader::load_image(path, img) == OK) { create_from_image(img); @@ -138,7 +138,7 @@ void ImageTexture::_reload_hook(const RID &p_hook) { } Ref<Image> img; - img.instance(); + img.instantiate(); Error err = ImageLoader::load_image(path, img); ERR_FAIL_COND_MSG(err != OK, "Cannot load image from path '" + path + "'."); @@ -173,7 +173,7 @@ Image::Format ImageTexture::get_format() const { return format; } -void ImageTexture::update(const Ref<Image> &p_image, bool p_immediate) { +void ImageTexture::update(const Ref<Image> &p_image) { ERR_FAIL_COND_MSG(p_image.is_null(), "Invalid image"); ERR_FAIL_COND_MSG(texture.is_null(), "Texture is not initialized."); ERR_FAIL_COND_MSG(p_image->get_width() != w || p_image->get_height() != h, @@ -183,11 +183,7 @@ void ImageTexture::update(const Ref<Image> &p_image, bool p_immediate) { ERR_FAIL_COND_MSG(mipmaps != p_image->has_mipmaps(), "The new image mipmaps configuration must match the texture's image mipmaps configuration"); - if (p_immediate) { - RenderingServer::get_singleton()->texture_2d_update_immediate(texture, p_image); - } else { - RenderingServer::get_singleton()->texture_2d_update(texture, p_image); - } + RenderingServer::get_singleton()->texture_2d_update(texture, p_image); notify_property_list_changed(); emit_changed(); @@ -258,7 +254,7 @@ bool ImageTexture::is_pixel_opaque(int p_x, int p_y) const { decom->decompress(); img = decom; } - alpha_cache.instance(); + alpha_cache.instantiate(); alpha_cache->create_from_image_alpha(img); } } @@ -305,7 +301,7 @@ void ImageTexture::_bind_methods() { ClassDB::bind_method(D_METHOD("create_from_image", "image"), &ImageTexture::create_from_image); ClassDB::bind_method(D_METHOD("get_format"), &ImageTexture::get_format); - ClassDB::bind_method(D_METHOD("update", "image", "immediate"), &ImageTexture::update, DEFVAL(false)); + ClassDB::bind_method(D_METHOD("update", "image"), &ImageTexture::update); ClassDB::bind_method(D_METHOD("set_size_override", "size"), &ImageTexture::set_size_override); ClassDB::bind_method(D_METHOD("_reload_hook", "rid"), &ImageTexture::_reload_hook); } @@ -390,7 +386,7 @@ Ref<Image> StreamTexture2D::load_image_from_file(FileAccess *f, int p_size_limit //print_line("mipmap read total: " + itos(mipmap_images.size())); Ref<Image> image; - image.instance(); + image.instantiate(); if (mipmap_images.size() == 1) { //only one image (which will most likely be the case anyway for this format) @@ -442,7 +438,7 @@ Ref<Image> StreamTexture2D::load_image_from_file(FileAccess *f, int p_size_limit } Ref<Image> image; - image.instance(); + image.instantiate(); image->create(tw, th, mipmaps - i ? true : false, format, data); @@ -553,7 +549,7 @@ Error StreamTexture2D::_load_data(const String &p_path, int &r_width, int &r_hei Error StreamTexture2D::load(const String &p_path) { int lw, lh; Ref<Image> image; - image.instance(); + image.instantiate(); bool request_3d; bool request_normal; @@ -679,7 +675,7 @@ bool StreamTexture2D::is_pixel_opaque(int p_x, int p_y) const { img = decom; } - alpha_cache.instance(); + alpha_cache.instantiate(); alpha_cache->create_from_image_alpha(img); } } @@ -738,7 +734,7 @@ StreamTexture2D::~StreamTexture2D() { RES ResourceFormatLoaderStreamTexture2D::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { Ref<StreamTexture2D> st; - st.instance(); + st.instantiate(); Error err = st->load(p_path); if (r_error) { *r_error = err; @@ -1036,7 +1032,7 @@ StreamTexture3D::~StreamTexture3D() { RES ResourceFormatLoaderStreamTexture3D::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { Ref<StreamTexture3D> st; - st.instance(); + st.instantiate(); Error err = st->load(p_path); if (r_error) { *r_error = err; @@ -1411,14 +1407,26 @@ void CurveTexture::_bind_methods() { ClassDB::bind_method(D_METHOD("set_curve", "curve"), &CurveTexture::set_curve); ClassDB::bind_method(D_METHOD("get_curve"), &CurveTexture::get_curve); + ClassDB::bind_method(D_METHOD("set_texture_mode", "texture_mode"), &CurveTexture::set_texture_mode); + ClassDB::bind_method(D_METHOD("get_texture_mode"), &CurveTexture::get_texture_mode); + ClassDB::bind_method(D_METHOD("_update"), &CurveTexture::_update); - ADD_PROPERTY(PropertyInfo(Variant::INT, "width", PROPERTY_HINT_RANGE, "32,4096"), "set_width", "get_width"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "width", PROPERTY_HINT_RANGE, "1,4096"), "set_width", "get_width"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "texture_mode", PROPERTY_HINT_ENUM, "RGB,Red"), "set_texture_mode", "get_texture_mode"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_curve", "get_curve"); + + BIND_ENUM_CONSTANT(TEXTURE_MODE_RGB); + BIND_ENUM_CONSTANT(TEXTURE_MODE_RED); } void CurveTexture::set_width(int p_width) { ERR_FAIL_COND(p_width < 32 || p_width > 4096); + + if (_width == p_width) { + return; + } + _width = p_width; _update(); } @@ -1454,7 +1462,7 @@ void CurveTexture::set_curve(Ref<Curve> p_curve) { void CurveTexture::_update() { Vector<uint8_t> data; - data.resize(_width * sizeof(float)); + data.resize(_width * sizeof(float) * (texture_mode == TEXTURE_MODE_RGB ? 3 : 1)); // The array is locked in that scope { @@ -1465,24 +1473,42 @@ void CurveTexture::_update() { Curve &curve = **_curve; for (int i = 0; i < _width; ++i) { float t = i / static_cast<float>(_width); - wd[i] = curve.interpolate_baked(t); + if (texture_mode == TEXTURE_MODE_RGB) { + wd[i * 3 + 0] = curve.interpolate_baked(t); + wd[i * 3 + 1] = wd[i * 3 + 0]; + wd[i * 3 + 2] = wd[i * 3 + 0]; + } else { + wd[i] = curve.interpolate_baked(t); + } } } else { for (int i = 0; i < _width; ++i) { - wd[i] = 0; + if (texture_mode == TEXTURE_MODE_RGB) { + wd[i * 3 + 0] = 0; + wd[i * 3 + 1] = 0; + wd[i * 3 + 2] = 0; + } else { + wd[i] = 0; + } } } } - Ref<Image> image = memnew(Image(_width, 1, false, Image::FORMAT_RF, data)); + Ref<Image> image = memnew(Image(_width, 1, false, texture_mode == TEXTURE_MODE_RGB ? Image::FORMAT_RGBF : Image::FORMAT_RF, data)); if (_texture.is_valid()) { - RID new_texture = RS::get_singleton()->texture_2d_create(image); - RS::get_singleton()->texture_replace(_texture, new_texture); + if (_current_texture_mode != texture_mode || _current_width != _width) { + RID new_texture = RS::get_singleton()->texture_2d_create(image); + RS::get_singleton()->texture_replace(_texture, new_texture); + } else { + RS::get_singleton()->texture_2d_update(_texture, image); + } } else { _texture = RS::get_singleton()->texture_2d_create(image); } + _current_texture_mode = texture_mode; + _current_width = _width; emit_changed(); } @@ -1491,6 +1517,17 @@ Ref<Curve> CurveTexture::get_curve() const { return _curve; } +void CurveTexture::set_texture_mode(TextureMode p_mode) { + if (texture_mode == p_mode) { + return; + } + texture_mode = p_mode; + _update(); +} +CurveTexture::TextureMode CurveTexture::get_texture_mode() const { + return texture_mode; +} + RID CurveTexture::get_rid() const { if (!_texture.is_valid()) { _texture = RS::get_singleton()->texture_2d_placeholder_create(); @@ -1508,6 +1545,204 @@ CurveTexture::~CurveTexture() { ////////////////// +void Curve3Texture::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_width", "width"), &Curve3Texture::set_width); + + ClassDB::bind_method(D_METHOD("set_curve_x", "curve"), &Curve3Texture::set_curve_x); + ClassDB::bind_method(D_METHOD("get_curve_x"), &Curve3Texture::get_curve_x); + + ClassDB::bind_method(D_METHOD("set_curve_y", "curve"), &Curve3Texture::set_curve_y); + ClassDB::bind_method(D_METHOD("get_curve_y"), &Curve3Texture::get_curve_y); + + ClassDB::bind_method(D_METHOD("set_curve_z", "curve"), &Curve3Texture::set_curve_z); + ClassDB::bind_method(D_METHOD("get_curve_z"), &Curve3Texture::get_curve_z); + + ClassDB::bind_method(D_METHOD("_update"), &Curve3Texture::_update); + + ADD_PROPERTY(PropertyInfo(Variant::INT, "width", PROPERTY_HINT_RANGE, "1,4096"), "set_width", "get_width"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "curve_x", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_curve_x", "get_curve_x"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "curve_y", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_curve_y", "get_curve_y"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "curve_z", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_curve_z", "get_curve_z"); +} + +void Curve3Texture::set_width(int p_width) { + ERR_FAIL_COND(p_width < 32 || p_width > 4096); + + if (_width == p_width) { + return; + } + + _width = p_width; + _update(); +} + +int Curve3Texture::get_width() const { + return _width; +} + +void Curve3Texture::ensure_default_setup(float p_min, float p_max) { + if (_curve_x.is_null()) { + Ref<Curve> curve = Ref<Curve>(memnew(Curve)); + curve->add_point(Vector2(0, 1)); + curve->add_point(Vector2(1, 1)); + curve->set_min_value(p_min); + curve->set_max_value(p_max); + set_curve_x(curve); + } + + if (_curve_y.is_null()) { + Ref<Curve> curve = Ref<Curve>(memnew(Curve)); + curve->add_point(Vector2(0, 1)); + curve->add_point(Vector2(1, 1)); + curve->set_min_value(p_min); + curve->set_max_value(p_max); + set_curve_y(curve); + } + + if (_curve_z.is_null()) { + Ref<Curve> curve = Ref<Curve>(memnew(Curve)); + curve->add_point(Vector2(0, 1)); + curve->add_point(Vector2(1, 1)); + curve->set_min_value(p_min); + curve->set_max_value(p_max); + set_curve_z(curve); + } +} + +void Curve3Texture::set_curve_x(Ref<Curve> p_curve) { + if (_curve_x != p_curve) { + if (_curve_x.is_valid()) { + _curve_x->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &Curve3Texture::_update)); + } + _curve_x = p_curve; + if (_curve_x.is_valid()) { + _curve_x->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &Curve3Texture::_update), varray(), CONNECT_REFERENCE_COUNTED); + } + _update(); + } +} + +void Curve3Texture::set_curve_y(Ref<Curve> p_curve) { + if (_curve_y != p_curve) { + if (_curve_y.is_valid()) { + _curve_y->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &Curve3Texture::_update)); + } + _curve_y = p_curve; + if (_curve_y.is_valid()) { + _curve_y->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &Curve3Texture::_update), varray(), CONNECT_REFERENCE_COUNTED); + } + _update(); + } +} + +void Curve3Texture::set_curve_z(Ref<Curve> p_curve) { + if (_curve_z != p_curve) { + if (_curve_z.is_valid()) { + _curve_z->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &Curve3Texture::_update)); + } + _curve_z = p_curve; + if (_curve_z.is_valid()) { + _curve_z->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &Curve3Texture::_update), varray(), CONNECT_REFERENCE_COUNTED); + } + _update(); + } +} + +void Curve3Texture::_update() { + Vector<uint8_t> data; + data.resize(_width * sizeof(float) * 3); + + // The array is locked in that scope + { + uint8_t *wd8 = data.ptrw(); + float *wd = (float *)wd8; + + if (_curve_x.is_valid()) { + Curve &curve_x = **_curve_x; + for (int i = 0; i < _width; ++i) { + float t = i / static_cast<float>(_width); + wd[i * 3 + 0] = curve_x.interpolate_baked(t); + } + + } else { + for (int i = 0; i < _width; ++i) { + wd[i * 3 + 0] = 0; + } + } + + if (_curve_y.is_valid()) { + Curve &curve_y = **_curve_y; + for (int i = 0; i < _width; ++i) { + float t = i / static_cast<float>(_width); + wd[i * 3 + 1] = curve_y.interpolate_baked(t); + } + + } else { + for (int i = 0; i < _width; ++i) { + wd[i * 3 + 1] = 0; + } + } + + if (_curve_z.is_valid()) { + Curve &curve_z = **_curve_z; + for (int i = 0; i < _width; ++i) { + float t = i / static_cast<float>(_width); + wd[i * 3 + 2] = curve_z.interpolate_baked(t); + } + + } else { + for (int i = 0; i < _width; ++i) { + wd[i * 3 + 2] = 0; + } + } + } + + Ref<Image> image = memnew(Image(_width, 1, false, Image::FORMAT_RGBF, data)); + + if (_texture.is_valid()) { + if (_current_width != _width) { + RID new_texture = RS::get_singleton()->texture_2d_create(image); + RS::get_singleton()->texture_replace(_texture, new_texture); + } else { + RS::get_singleton()->texture_2d_update(_texture, image); + } + } else { + _texture = RS::get_singleton()->texture_2d_create(image); + } + _current_width = _width; + + emit_changed(); +} + +Ref<Curve> Curve3Texture::get_curve_x() const { + return _curve_x; +} + +Ref<Curve> Curve3Texture::get_curve_y() const { + return _curve_y; +} + +Ref<Curve> Curve3Texture::get_curve_z() const { + return _curve_z; +} + +RID Curve3Texture::get_rid() const { + if (!_texture.is_valid()) { + _texture = RS::get_singleton()->texture_2d_placeholder_create(); + } + return _texture; +} + +Curve3Texture::Curve3Texture() {} + +Curve3Texture::~Curve3Texture() { + if (_texture.is_valid()) { + RS::get_singleton()->free(_texture); + } +} + +////////////////// + GradientTexture::GradientTexture() { _queue_update(); } @@ -1527,7 +1762,7 @@ void GradientTexture::_bind_methods() { ClassDB::bind_method(D_METHOD("_update"), &GradientTexture::_update); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "gradient", PROPERTY_HINT_RESOURCE_TYPE, "Gradient"), "set_gradient", "get_gradient"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "width", PROPERTY_HINT_RANGE, "1,2048,1,or_greater"), "set_width", "get_width"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "width", PROPERTY_HINT_RANGE, "1,4096"), "set_width", "get_width"); } void GradientTexture::set_gradient(Ref<Gradient> p_gradient) { @@ -1595,6 +1830,7 @@ void GradientTexture::_update() { } void GradientTexture::set_width(int p_width) { + ERR_FAIL_COND(p_width <= 0); width = p_width; _queue_update(); } @@ -1876,7 +2112,7 @@ void AnimatedTexture::_validate_property(PropertyInfo &property) const { if (prop.begins_with("frame_")) { int frame = prop.get_slicec('/', 0).get_slicec('_', 1).to_int(); if (frame >= frame_count) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } } } @@ -2257,15 +2493,15 @@ RES ResourceFormatLoaderStreamTextureLayered::load(const String &p_path, const S Ref<StreamTextureLayered> st; if (p_path.get_extension().to_lower() == "stexarray") { Ref<StreamTexture2DArray> s; - s.instance(); + s.instantiate(); st = s; } else if (p_path.get_extension().to_lower() == "scube") { Ref<StreamCubemap> s; - s.instance(); + s.instantiate(); st = s; } else if (p_path.get_extension().to_lower() == "scubearray") { Ref<StreamCubemapArray> s; - s.instance(); + s.instantiate(); st = s; } else { if (r_error) { diff --git a/scene/resources/texture.h b/scene/resources/texture.h index 3b1815266d..73390039cb 100644 --- a/scene/resources/texture.h +++ b/scene/resources/texture.h @@ -107,7 +107,7 @@ public: Image::Format get_format() const; - void update(const Ref<Image> &p_image, bool p_immediate = false); + void update(const Ref<Image> &p_image); Ref<Image> get_image() const override; int get_width() const override; @@ -586,11 +586,19 @@ public: class CurveTexture : public Texture2D { GDCLASS(CurveTexture, Texture2D); RES_BASE_EXTENSION("curvetex") +public: + enum TextureMode { + TEXTURE_MODE_RGB, + TEXTURE_MODE_RED, + }; private: mutable RID _texture; Ref<Curve> _curve; int _width = 2048; + int _current_width = 0; + TextureMode texture_mode = TEXTURE_MODE_RGB; + TextureMode _current_texture_mode = TEXTURE_MODE_RGB; void _update(); @@ -601,6 +609,9 @@ public: void set_width(int p_width); int get_width() const override; + void set_texture_mode(TextureMode p_mode); + TextureMode get_texture_mode() const; + void ensure_default_setup(float p_min = 0, float p_max = 1); void set_curve(Ref<Curve> p_curve); @@ -614,18 +625,49 @@ public: CurveTexture(); ~CurveTexture(); }; -/* - enum CubeMapSide { - CUBEMAP_LEFT, - CUBEMAP_RIGHT, - CUBEMAP_BOTTOM, - CUBEMAP_TOP, - CUBEMAP_FRONT, - CUBEMAP_BACK, - }; -*/ -//VARIANT_ENUM_CAST( Texture::CubeMapSide ); +VARIANT_ENUM_CAST(CurveTexture::TextureMode) + +class Curve3Texture : public Texture2D { + GDCLASS(Curve3Texture, Texture2D); + RES_BASE_EXTENSION("curvetex") + +private: + mutable RID _texture; + Ref<Curve> _curve_x; + Ref<Curve> _curve_y; + Ref<Curve> _curve_z; + int _width = 2048; + int _current_width = 0; + + void _update(); + +protected: + static void _bind_methods(); + +public: + void set_width(int p_width); + int get_width() const override; + + void ensure_default_setup(float p_min = 0, float p_max = 1); + + void set_curve_x(Ref<Curve> p_curve); + Ref<Curve> get_curve_x() const; + + void set_curve_y(Ref<Curve> p_curve); + Ref<Curve> get_curve_y() const; + + void set_curve_z(Ref<Curve> p_curve); + Ref<Curve> get_curve_z() const; + + virtual RID get_rid() const override; + + virtual int get_height() const override { return 1; } + virtual bool has_alpha() const override { return false; } + + Curve3Texture(); + ~Curve3Texture(); +}; class GradientTexture : public Texture2D { GDCLASS(GradientTexture, Texture2D); diff --git a/scene/resources/tile_set.cpp b/scene/resources/tile_set.cpp index 0eeea29da4..deee22f05f 100644 --- a/scene/resources/tile_set.cpp +++ b/scene/resources/tile_set.cpp @@ -30,7 +30,10 @@ #include "tile_set.h" +#include "core/core_string_names.h" #include "core/math/geometry_2d.h" +#include "core/templates/local_vector.h" + #include "scene/2d/navigation_region_2d.h" #include "scene/gui/control.h" #include "scene/resources/convex_polygon_shape_2d.h" @@ -38,6 +41,25 @@ /////////////////////////////// TileSet ////////////////////////////////////// +const char *TileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[] = { + "right_side", + "right_corner", + "bottom_right_side", + "bottom_right_corner", + "bottom_side", + "bottom_corner", + "bottom_left_side", + "bottom_left_corner", + "left_side", + "left_corner", + "top_left_side", + "top_left_corner", + "top_side", + "top_corner", + "top_right_side", + "top_right_corner" +}; + // --- Plugins --- Vector<TileSetPlugin *> TileSet::get_tile_set_atlas_plugins() const { return tile_set_plugins_vector; @@ -51,6 +73,8 @@ void TileSet::set_tile_shape(TileSet::TileShape p_shape) { E_source->get()->notify_tile_data_properties_should_change(); } + terrain_bits_meshes_dirty = true; + tile_meshes_dirty = true; emit_changed(); } TileSet::TileShape TileSet::get_tile_shape() const { @@ -72,6 +96,8 @@ void TileSet::set_tile_offset_axis(TileSet::TileOffsetAxis p_alignment) { E_source->get()->notify_tile_data_properties_should_change(); } + terrain_bits_meshes_dirty = true; + tile_meshes_dirty = true; emit_changed(); } TileSet::TileOffsetAxis TileSet::get_tile_offset_axis() const { @@ -81,20 +107,14 @@ TileSet::TileOffsetAxis TileSet::get_tile_offset_axis() const { void TileSet::set_tile_size(Size2i p_size) { ERR_FAIL_COND(p_size.x < 1 || p_size.y < 1); tile_size = p_size; + terrain_bits_meshes_dirty = true; + tile_meshes_dirty = true; emit_changed(); } Size2i TileSet::get_tile_size() const { return tile_size; } -void TileSet::set_tile_skew(Vector2 p_skew) { - emit_changed(); - tile_skew = p_skew; -} -Vector2 TileSet::get_tile_skew() const { - return tile_skew; -} - int TileSet::get_next_source_id() const { return next_source_id; } @@ -117,7 +137,7 @@ int TileSet::add_source(Ref<TileSetSource> p_tile_set_source, int p_atlas_source p_tile_set_source->set_tile_set(this); _compute_next_source_id(); - sources[new_source_id]->connect("changed", callable_mp(this, &TileSet::_source_changed)); + sources[new_source_id]->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &TileSet::_source_changed)); emit_changed(); @@ -127,7 +147,7 @@ int TileSet::add_source(Ref<TileSetSource> p_tile_set_source, int p_atlas_source void TileSet::remove_source(int p_source_id) { ERR_FAIL_COND_MSG(!sources.has(p_source_id), vformat("Cannot remove TileSet atlas source. No tileset atlas source with id %d.", p_source_id)); - sources[p_source_id]->disconnect("changed", callable_mp(this, &TileSet::_source_changed)); + sources[p_source_id]->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &TileSet::_source_changed)); sources[p_source_id]->set_tile_set(nullptr); sources.erase(p_source_id); @@ -240,80 +260,6 @@ bool TileSet::get_occlusion_layer_sdf_collision(int p_layer_index) const { return occlusion_layers[p_layer_index].sdf_collision; } -void TileSet::draw_tile_shape(CanvasItem *p_canvas_item, Rect2 p_region, Color p_color, bool p_filled, Ref<Texture2D> p_texture) { - // TODO: optimize this with 2D meshes when they work again. - if (get_tile_shape() == TileSet::TILE_SHAPE_SQUARE) { - if (p_filled && p_texture.is_valid()) { - p_canvas_item->draw_texture_rect(p_texture, p_region, false, p_color); - } else { - p_canvas_item->draw_rect(p_region, p_color, p_filled); - } - } else { - float overlap = 0.0; - switch (get_tile_shape()) { - case TileSet::TILE_SHAPE_ISOMETRIC: - overlap = 0.5; - break; - case TileSet::TILE_SHAPE_HEXAGON: - overlap = 0.25; - break; - case TileSet::TILE_SHAPE_HALF_OFFSET_SQUARE: - overlap = 0.0; - break; - default: - break; - } - - Vector<Vector2> uvs; - uvs.append(Vector2(0.5, 0.0)); - uvs.append(Vector2(0.0, overlap)); - uvs.append(Vector2(0.0, 1.0 - overlap)); - uvs.append(Vector2(0.5, 1.0)); - uvs.append(Vector2(1.0, 1.0 - overlap)); - uvs.append(Vector2(1.0, overlap)); - uvs.append(Vector2(0.5, 0.0)); - if (get_tile_offset_axis() == TileSet::TILE_OFFSET_AXIS_VERTICAL) { - for (int i = 0; i < uvs.size(); i++) { - uvs.write[i] = Vector2(uvs[i].y, uvs[i].x); - } - } - - Vector<Vector2> points; - for (int i = 0; i < uvs.size(); i++) { - points.append(p_region.position + uvs[i] * p_region.size); - } - - if (p_filled) { - // This does hurt performances a lot. We should use a mesh if possible instead. - p_canvas_item->draw_colored_polygon(points, p_color, uvs, p_texture); - - // Should improve performances, but does not work as draw_primitive does not work with textures :/ : - /*for (int i = 0; i < 6; i += 3) { - Vector<Vector2> quad; - quad.append(points[i]); - quad.append(points[(i + 1) % points.size()]); - quad.append(points[(i + 2) % points.size()]); - quad.append(points[(i + 3) % points.size()]); - - Vector<Vector2> uv_quad; - uv_quad.append(uvs[i]); - uv_quad.append(uvs[(i + 1) % uvs.size()]); - uv_quad.append(uvs[(i + 2) % uvs.size()]); - uv_quad.append(uvs[(i + 3) % uvs.size()]); - - p_control->draw_primitive(quad, Vector<Color>(), uv_quad, p_texture); - }*/ - - } else { - // This does hurt performances a lot. We should use a mesh if possible instead. - // tile_shape_grid->draw_polyline(points, p_color); - for (int i = 0; i < points.size() - 1; i++) { - p_canvas_item->draw_line(points[i], points[i + 1], p_color); - } - } - } -} - // Physics void TileSet::set_physics_layers_count(int p_physics_layers_count) { ERR_FAIL_COND(p_physics_layers_count < 0); @@ -459,14 +405,9 @@ Color TileSet::get_terrain_color(int p_terrain_set, int p_terrain_index) const { return terrain_sets[p_terrain_set].terrains[p_terrain_index].color; } -bool TileSet::is_valid_peering_bit_terrain(int p_terrain_set, TileSet::CellNeighbor p_peering_bit) const { - if (p_terrain_set < 0 || p_terrain_set >= get_terrain_sets_count()) { - return false; - } - - TileSet::TerrainMode terrain_mode = get_terrain_set_mode(p_terrain_set); +bool TileSet::is_valid_peering_bit_for_mode(TileSet::TerrainMode p_terrain_mode, TileSet::CellNeighbor p_peering_bit) const { if (tile_shape == TileSet::TILE_SHAPE_SQUARE) { - if (terrain_mode == TileSet::TERRAIN_MODE_MATCH_CORNERS_AND_SIDES || terrain_mode == TileSet::TERRAIN_MODE_MATCH_SIDES) { + if (p_terrain_mode == TileSet::TERRAIN_MODE_MATCH_CORNERS_AND_SIDES || p_terrain_mode == TileSet::TERRAIN_MODE_MATCH_SIDES) { if (p_peering_bit == TileSet::CELL_NEIGHBOR_RIGHT_SIDE || p_peering_bit == TileSet::CELL_NEIGHBOR_BOTTOM_SIDE || p_peering_bit == TileSet::CELL_NEIGHBOR_LEFT_SIDE || @@ -474,7 +415,7 @@ bool TileSet::is_valid_peering_bit_terrain(int p_terrain_set, TileSet::CellNeigh return true; } } - if (terrain_mode == TileSet::TERRAIN_MODE_MATCH_CORNERS_AND_SIDES || terrain_mode == TileSet::TERRAIN_MODE_MATCH_CORNERS) { + if (p_terrain_mode == TileSet::TERRAIN_MODE_MATCH_CORNERS_AND_SIDES || p_terrain_mode == TileSet::TERRAIN_MODE_MATCH_CORNERS) { if (p_peering_bit == TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER || p_peering_bit == TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_CORNER || p_peering_bit == TileSet::CELL_NEIGHBOR_TOP_LEFT_CORNER || @@ -483,7 +424,7 @@ bool TileSet::is_valid_peering_bit_terrain(int p_terrain_set, TileSet::CellNeigh } } } else if (tile_shape == TileSet::TILE_SHAPE_ISOMETRIC) { - if (terrain_mode == TileSet::TERRAIN_MODE_MATCH_CORNERS_AND_SIDES || terrain_mode == TileSet::TERRAIN_MODE_MATCH_SIDES) { + if (p_terrain_mode == TileSet::TERRAIN_MODE_MATCH_CORNERS_AND_SIDES || p_terrain_mode == TileSet::TERRAIN_MODE_MATCH_SIDES) { if (p_peering_bit == TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE || p_peering_bit == TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE || p_peering_bit == TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE || @@ -491,7 +432,7 @@ bool TileSet::is_valid_peering_bit_terrain(int p_terrain_set, TileSet::CellNeigh return true; } } - if (terrain_mode == TileSet::TERRAIN_MODE_MATCH_CORNERS_AND_SIDES || terrain_mode == TileSet::TERRAIN_MODE_MATCH_CORNERS) { + if (p_terrain_mode == TileSet::TERRAIN_MODE_MATCH_CORNERS_AND_SIDES || p_terrain_mode == TileSet::TERRAIN_MODE_MATCH_CORNERS) { if (p_peering_bit == TileSet::CELL_NEIGHBOR_RIGHT_CORNER || p_peering_bit == TileSet::CELL_NEIGHBOR_BOTTOM_CORNER || p_peering_bit == TileSet::CELL_NEIGHBOR_LEFT_CORNER || @@ -501,7 +442,7 @@ bool TileSet::is_valid_peering_bit_terrain(int p_terrain_set, TileSet::CellNeigh } } else { if (get_tile_offset_axis() == TileSet::TILE_OFFSET_AXIS_HORIZONTAL) { - if (terrain_mode == TileSet::TERRAIN_MODE_MATCH_CORNERS_AND_SIDES || terrain_mode == TileSet::TERRAIN_MODE_MATCH_SIDES) { + if (p_terrain_mode == TileSet::TERRAIN_MODE_MATCH_CORNERS_AND_SIDES || p_terrain_mode == TileSet::TERRAIN_MODE_MATCH_SIDES) { if (p_peering_bit == TileSet::CELL_NEIGHBOR_RIGHT_SIDE || p_peering_bit == TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE || p_peering_bit == TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE || @@ -511,7 +452,7 @@ bool TileSet::is_valid_peering_bit_terrain(int p_terrain_set, TileSet::CellNeigh return true; } } - if (terrain_mode == TileSet::TERRAIN_MODE_MATCH_CORNERS_AND_SIDES || terrain_mode == TileSet::TERRAIN_MODE_MATCH_CORNERS) { + if (p_terrain_mode == TileSet::TERRAIN_MODE_MATCH_CORNERS_AND_SIDES || p_terrain_mode == TileSet::TERRAIN_MODE_MATCH_CORNERS) { if (p_peering_bit == TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER || p_peering_bit == TileSet::CELL_NEIGHBOR_BOTTOM_CORNER || p_peering_bit == TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_CORNER || @@ -522,7 +463,7 @@ bool TileSet::is_valid_peering_bit_terrain(int p_terrain_set, TileSet::CellNeigh } } } else { - if (terrain_mode == TileSet::TERRAIN_MODE_MATCH_CORNERS_AND_SIDES || terrain_mode == TileSet::TERRAIN_MODE_MATCH_SIDES) { + if (p_terrain_mode == TileSet::TERRAIN_MODE_MATCH_CORNERS_AND_SIDES || p_terrain_mode == TileSet::TERRAIN_MODE_MATCH_SIDES) { if (p_peering_bit == TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE || p_peering_bit == TileSet::CELL_NEIGHBOR_BOTTOM_SIDE || p_peering_bit == TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE || @@ -532,7 +473,7 @@ bool TileSet::is_valid_peering_bit_terrain(int p_terrain_set, TileSet::CellNeigh return true; } } - if (terrain_mode == TileSet::TERRAIN_MODE_MATCH_CORNERS_AND_SIDES || terrain_mode == TileSet::TERRAIN_MODE_MATCH_CORNERS) { + if (p_terrain_mode == TileSet::TERRAIN_MODE_MATCH_CORNERS_AND_SIDES || p_terrain_mode == TileSet::TERRAIN_MODE_MATCH_CORNERS) { if (p_peering_bit == TileSet::CELL_NEIGHBOR_RIGHT_CORNER || p_peering_bit == TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER || p_peering_bit == TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_CORNER || @@ -547,6 +488,15 @@ bool TileSet::is_valid_peering_bit_terrain(int p_terrain_set, TileSet::CellNeigh return false; } +bool TileSet::is_valid_peering_bit_terrain(int p_terrain_set, TileSet::CellNeighbor p_peering_bit) const { + if (p_terrain_set < 0 || p_terrain_set >= get_terrain_sets_count()) { + return false; + } + + TileSet::TerrainMode terrain_mode = get_terrain_set_mode(p_terrain_set); + return is_valid_peering_bit_for_mode(terrain_mode, p_peering_bit); +} + // Navigation void TileSet::set_navigation_layers_count(int p_navigation_layers_count) { ERR_FAIL_COND(p_navigation_layers_count < 0); @@ -657,9 +607,926 @@ Variant::Type TileSet::get_custom_data_type(int p_layer_id) const { return custom_data_layers[p_layer_id].type; } +Vector<Vector2> TileSet::get_tile_shape_polygon() { + Vector<Vector2> points; + if (tile_shape == TileSet::TILE_SHAPE_SQUARE) { + points.append(Vector2(0.0, 0.0)); + points.append(Vector2(1.0, 0.0)); + points.append(Vector2(1.0, 1.0)); + points.append(Vector2(0.0, 1.0)); + } else { + float overlap = 0.0; + switch (tile_shape) { + case TileSet::TILE_SHAPE_ISOMETRIC: + overlap = 0.5; + break; + case TileSet::TILE_SHAPE_HEXAGON: + overlap = 0.25; + break; + case TileSet::TILE_SHAPE_HALF_OFFSET_SQUARE: + overlap = 0.0; + break; + default: + break; + } + + points.append(Vector2(0.5, 0.0)); + points.append(Vector2(0.0, overlap)); + points.append(Vector2(0.0, 1.0 - overlap)); + points.append(Vector2(0.5, 1.0)); + points.append(Vector2(1.0, 1.0 - overlap)); + points.append(Vector2(1.0, overlap)); + points.append(Vector2(0.5, 0.0)); + if (get_tile_offset_axis() == TileSet::TILE_OFFSET_AXIS_VERTICAL) { + for (int i = 0; i < points.size(); i++) { + points.write[i] = Vector2(points[i].y, points[i].x); + } + } + } + for (int i = 0; i < points.size(); i++) { + points.write[i] = points[i] * tile_size - tile_size / 2; + } + return points; +} + +void TileSet::draw_tile_shape(CanvasItem *p_canvas_item, Rect2 p_region, Color p_color, bool p_filled, Ref<Texture2D> p_texture) { + if (tile_meshes_dirty) { + Vector<Vector2> uvs = get_tile_shape_polygon(); + for (int i = 0; i < uvs.size(); i++) { + uvs.write[i] = (uvs[i] + tile_size / 2) / tile_size; + } + + Vector<Color> colors; + colors.resize(uvs.size()); + colors.fill(Color(1.0, 1.0, 1.0, 1.0)); + + // Filled mesh. + tile_filled_mesh->clear_surfaces(); + Array a; + a.resize(Mesh::ARRAY_MAX); + a[Mesh::ARRAY_VERTEX] = uvs; + a[Mesh::ARRAY_TEX_UV] = uvs; + a[Mesh::ARRAY_COLOR] = colors; + a[Mesh::ARRAY_INDEX] = Geometry2D::triangulate_polygon(uvs); + tile_filled_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, a, Array(), Dictionary(), Mesh::ARRAY_FLAG_USE_2D_VERTICES); + + // Lines mesh. + tile_lines_mesh->clear_surfaces(); + a.clear(); + a.resize(Mesh::ARRAY_MAX); + // Add the first point again when drawing lines. + uvs.push_back(uvs[0]); + colors.push_back(colors[0]); + a[Mesh::ARRAY_VERTEX] = uvs; + a[Mesh::ARRAY_COLOR] = colors; + tile_lines_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_LINE_STRIP, a, Array(), Dictionary(), Mesh::ARRAY_FLAG_USE_2D_VERTICES); + + tile_meshes_dirty = false; + } + + Transform2D xform; + xform.scale(p_region.size); + xform.set_origin(p_region.get_position()); + if (p_filled) { + p_canvas_item->draw_mesh(tile_filled_mesh, p_texture, xform, p_color); + } else { + p_canvas_item->draw_mesh(tile_lines_mesh, Ref<Texture2D>(), xform, p_color); + } +} + +Vector<Point2> TileSet::get_terrain_bit_polygon(int p_terrain_set, TileSet::CellNeighbor p_bit) { + ERR_FAIL_COND_V(p_terrain_set < 0 || p_terrain_set >= get_terrain_sets_count(), Vector<Point2>()); + + TileSet::TerrainMode terrain_mode = get_terrain_set_mode(p_terrain_set); + + if (tile_shape == TileSet::TILE_SHAPE_SQUARE) { + if (terrain_mode == TileSet::TERRAIN_MODE_MATCH_CORNERS_AND_SIDES) { + return _get_square_corner_or_side_terrain_bit_polygon(tile_size, p_bit); + } else if (terrain_mode == TileSet::TERRAIN_MODE_MATCH_CORNERS) { + return _get_square_corner_terrain_bit_polygon(tile_size, p_bit); + } else { // TileData::TERRAIN_MODE_MATCH_SIDES + return _get_square_side_terrain_bit_polygon(tile_size, p_bit); + } + } else if (tile_shape == TileSet::TILE_SHAPE_ISOMETRIC) { + if (terrain_mode == TileSet::TERRAIN_MODE_MATCH_CORNERS_AND_SIDES) { + return _get_isometric_corner_or_side_terrain_bit_polygon(tile_size, p_bit); + } else if (terrain_mode == TileSet::TERRAIN_MODE_MATCH_CORNERS) { + return _get_isometric_corner_terrain_bit_polygon(tile_size, p_bit); + } else { // TileData::TERRAIN_MODE_MATCH_SIDES + return _get_isometric_side_terrain_bit_polygon(tile_size, p_bit); + } + } else { + float overlap = 0.0; + switch (tile_shape) { + case TileSet::TILE_SHAPE_HEXAGON: + overlap = 0.25; + break; + case TileSet::TILE_SHAPE_HALF_OFFSET_SQUARE: + overlap = 0.0; + break; + default: + break; + } + if (terrain_mode == TileSet::TERRAIN_MODE_MATCH_CORNERS_AND_SIDES) { + return _get_half_offset_corner_or_side_terrain_bit_polygon(tile_size, p_bit, overlap, tile_offset_axis); + } else if (terrain_mode == TileSet::TERRAIN_MODE_MATCH_CORNERS) { + return _get_half_offset_corner_terrain_bit_polygon(tile_size, p_bit, overlap, tile_offset_axis); + } else { // TileData::TERRAIN_MODE_MATCH_SIDES + return _get_half_offset_side_terrain_bit_polygon(tile_size, p_bit, overlap, tile_offset_axis); + } + } +} + +#define TERRAIN_ALPHA 0.6 + +void TileSet::draw_terrains(CanvasItem *p_canvas_item, Transform2D p_transform, const TileData *p_tile_data) { + ERR_FAIL_COND(!p_tile_data); + + if (terrain_bits_meshes_dirty) { + // Recompute the meshes. + terrain_bits_meshes.clear(); + + for (int terrain_mode_index = 0; terrain_mode_index < 3; terrain_mode_index++) { + TerrainMode terrain_mode = TerrainMode(terrain_mode_index); + for (int i = 0; i < TileSet::CELL_NEIGHBOR_MAX; i++) { + CellNeighbor bit = CellNeighbor(i); + + if (is_valid_peering_bit_for_mode(terrain_mode, bit)) { + Vector<Vector2> polygon; + if (tile_shape == TileSet::TILE_SHAPE_SQUARE) { + if (terrain_mode == TileSet::TERRAIN_MODE_MATCH_CORNERS_AND_SIDES) { + polygon = _get_square_corner_or_side_terrain_bit_polygon(tile_size, bit); + } else if (terrain_mode == TileSet::TERRAIN_MODE_MATCH_CORNERS) { + polygon = _get_square_corner_terrain_bit_polygon(tile_size, bit); + } else { // TileData::TERRAIN_MODE_MATCH_SIDES + polygon = _get_square_side_terrain_bit_polygon(tile_size, bit); + } + } else if (tile_shape == TileSet::TILE_SHAPE_ISOMETRIC) { + if (terrain_mode == TileSet::TERRAIN_MODE_MATCH_CORNERS_AND_SIDES) { + polygon = _get_isometric_corner_or_side_terrain_bit_polygon(tile_size, bit); + } else if (terrain_mode == TileSet::TERRAIN_MODE_MATCH_CORNERS) { + polygon = _get_isometric_corner_terrain_bit_polygon(tile_size, bit); + } else { // TileData::TERRAIN_MODE_MATCH_SIDES + polygon = _get_isometric_side_terrain_bit_polygon(tile_size, bit); + } + } else { + float overlap = 0.0; + switch (tile_shape) { + case TileSet::TILE_SHAPE_HEXAGON: + overlap = 0.25; + break; + case TileSet::TILE_SHAPE_HALF_OFFSET_SQUARE: + overlap = 0.0; + break; + default: + break; + } + if (terrain_mode == TileSet::TERRAIN_MODE_MATCH_CORNERS_AND_SIDES) { + polygon = _get_half_offset_corner_or_side_terrain_bit_polygon(tile_size, bit, overlap, tile_offset_axis); + } else if (terrain_mode == TileSet::TERRAIN_MODE_MATCH_CORNERS) { + polygon = _get_half_offset_corner_terrain_bit_polygon(tile_size, bit, overlap, tile_offset_axis); + } else { // TileData::TERRAIN_MODE_MATCH_SIDES + polygon = _get_half_offset_side_terrain_bit_polygon(tile_size, bit, overlap, tile_offset_axis); + } + } + + Ref<ArrayMesh> mesh; + mesh.instantiate(); + Vector<Vector2> uvs; + uvs.resize(polygon.size()); + Vector<Color> colors; + colors.resize(polygon.size()); + colors.fill(Color(1.0, 1.0, 1.0, 1.0)); + Array a; + a.resize(Mesh::ARRAY_MAX); + a[Mesh::ARRAY_VERTEX] = polygon; + a[Mesh::ARRAY_TEX_UV] = uvs; + a[Mesh::ARRAY_COLOR] = colors; + a[Mesh::ARRAY_INDEX] = Geometry2D::triangulate_polygon(polygon); + mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, a, Array(), Dictionary(), Mesh::ARRAY_FLAG_USE_2D_VERTICES); + terrain_bits_meshes[terrain_mode][bit] = mesh; + } + } + } + terrain_bits_meshes_dirty = false; + } + + int terrain_set = p_tile_data->get_terrain_set(); + if (terrain_set < 0) { + return; + } + TileSet::TerrainMode terrain_mode = get_terrain_set_mode(terrain_set); + + RenderingServer::get_singleton()->canvas_item_add_set_transform(p_canvas_item->get_canvas_item(), p_transform); + for (int i = 0; i < TileSet::CELL_NEIGHBOR_MAX; i++) { + CellNeighbor bit = CellNeighbor(i); + if (is_valid_peering_bit_terrain(terrain_set, bit)) { + int terrain_id = p_tile_data->get_peering_bit_terrain(bit); + if (terrain_id >= 0) { + Color color = get_terrain_color(terrain_set, terrain_id); + color.a = TERRAIN_ALPHA; + p_canvas_item->draw_mesh(terrain_bits_meshes[terrain_mode][bit], Ref<Texture2D>(), Transform2D(), color); + } + } + } + RenderingServer::get_singleton()->canvas_item_add_set_transform(p_canvas_item->get_canvas_item(), Transform2D()); +} + +Vector<Vector<Ref<Texture2D>>> TileSet::generate_terrains_icons(Size2i p_size) { + // Counts the number of matching terrain tiles and find the best matching icon. + struct Count { + int count = 0; + float probability = 0.0; + Ref<Texture2D> texture; + Rect2i region; + }; + Vector<Vector<Ref<Texture2D>>> output; + LocalVector<LocalVector<Count>> counts; + output.resize(get_terrain_sets_count()); + counts.resize(get_terrain_sets_count()); + for (int terrain_set = 0; terrain_set < get_terrain_sets_count(); terrain_set++) { + output.write[terrain_set].resize(get_terrains_count(terrain_set)); + counts[terrain_set].resize(get_terrains_count(terrain_set)); + } + + for (int source_index = 0; source_index < get_source_count(); source_index++) { + int source_id = get_source_id(source_index); + Ref<TileSetSource> source = get_source(source_id); + + Ref<TileSetAtlasSource> atlas_source = source; + if (atlas_source.is_valid()) { + for (int tile_index = 0; tile_index < source->get_tiles_count(); tile_index++) { + Vector2i tile_id = source->get_tile_id(tile_index); + for (int alternative_index = 0; alternative_index < source->get_alternative_tiles_count(tile_id); alternative_index++) { + int alternative_id = source->get_alternative_tile_id(tile_id, alternative_index); + + TileData *tile_data = Object::cast_to<TileData>(atlas_source->get_tile_data(tile_id, alternative_id)); + int terrain_set = tile_data->get_terrain_set(); + if (terrain_set >= 0) { + ERR_FAIL_INDEX_V(terrain_set, get_terrain_sets_count(), Vector<Vector<Ref<Texture2D>>>()); + + LocalVector<int> bit_counts; + bit_counts.resize(get_terrains_count(terrain_set)); + for (int terrain = 0; terrain < get_terrains_count(terrain_set); terrain++) { + bit_counts[terrain] = 0; + } + for (int terrain_bit = 0; terrain_bit < TileSet::CELL_NEIGHBOR_MAX; terrain_bit++) { + TileSet::CellNeighbor cell_neighbor = TileSet::CellNeighbor(terrain_bit); + if (is_valid_peering_bit_terrain(terrain_set, cell_neighbor)) { + int terrain = tile_data->get_peering_bit_terrain(cell_neighbor); + if (terrain >= 0) { + bit_counts[terrain] += 1; + } + } + } + + for (int terrain = 0; terrain < get_terrains_count(terrain_set); terrain++) { + if ((bit_counts[terrain] > counts[terrain_set][terrain].count) || (bit_counts[terrain] == counts[terrain_set][terrain].count && tile_data->get_probability() > counts[terrain_set][terrain].probability)) { + counts[terrain_set][terrain].count = bit_counts[terrain]; + counts[terrain_set][terrain].probability = tile_data->get_probability(); + counts[terrain_set][terrain].texture = atlas_source->get_texture(); + counts[terrain_set][terrain].region = atlas_source->get_tile_texture_region(tile_id); + } + } + } + } + } + } + } + + // Generate the icons. + for (int terrain_set = 0; terrain_set < get_terrain_sets_count(); terrain_set++) { + for (int terrain = 0; terrain < get_terrains_count(terrain_set); terrain++) { + Ref<Image> image; + image.instantiate(); + if (counts[terrain_set][terrain].count > 0) { + // Get the best tile. + Ref<Texture2D> texture = counts[terrain_set][terrain].texture; + Rect2 region = counts[terrain_set][terrain].region; + image->create(region.size.x, region.size.y, false, Image::FORMAT_RGBA8); + image->blit_rect(texture->get_image(), region, Point2()); + image->resize(p_size.x, p_size.y, Image::INTERPOLATE_NEAREST); + } else { + image->create(1, 1, false, Image::FORMAT_RGBA8); + image->set_pixel(0, 0, get_terrain_color(terrain_set, terrain)); + } + Ref<ImageTexture> icon; + icon.instantiate(); + icon->create_from_image(image); + icon->set_size_override(p_size); + + output.write[terrain_set].write[terrain] = icon; + } + } + return output; +} + void TileSet::_source_changed() { emit_changed(); - notify_property_list_changed(); +} + +Vector<Point2> TileSet::_get_square_corner_or_side_terrain_bit_polygon(Vector2i p_size, TileSet::CellNeighbor p_bit) { + Rect2 bit_rect; + bit_rect.size = Vector2(p_size) / 3; + switch (p_bit) { + case TileSet::CELL_NEIGHBOR_RIGHT_SIDE: + bit_rect.position = Vector2(1, -1); + break; + case TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER: + bit_rect.position = Vector2(1, 1); + break; + case TileSet::CELL_NEIGHBOR_BOTTOM_SIDE: + bit_rect.position = Vector2(-1, 1); + break; + case TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_CORNER: + bit_rect.position = Vector2(-3, 1); + break; + case TileSet::CELL_NEIGHBOR_LEFT_SIDE: + bit_rect.position = Vector2(-3, -1); + break; + case TileSet::CELL_NEIGHBOR_TOP_LEFT_CORNER: + bit_rect.position = Vector2(-3, -3); + break; + case TileSet::CELL_NEIGHBOR_TOP_SIDE: + bit_rect.position = Vector2(-1, -3); + break; + case TileSet::CELL_NEIGHBOR_TOP_RIGHT_CORNER: + bit_rect.position = Vector2(1, -3); + break; + default: + break; + } + bit_rect.position *= Vector2(p_size) / 6.0; + Vector<Vector2> polygon; + polygon.push_back(bit_rect.position); + polygon.push_back(Vector2(bit_rect.get_end().x, bit_rect.position.y)); + polygon.push_back(bit_rect.get_end()); + polygon.push_back(Vector2(bit_rect.position.x, bit_rect.get_end().y)); + return polygon; +} + +Vector<Point2> TileSet::_get_square_corner_terrain_bit_polygon(Vector2i p_size, TileSet::CellNeighbor p_bit) { + Vector2 unit = Vector2(p_size) / 6.0; + Vector<Vector2> polygon; + switch (p_bit) { + case TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER: + polygon.push_back(Vector2(0, 3) * unit); + polygon.push_back(Vector2(3, 3) * unit); + polygon.push_back(Vector2(3, 0) * unit); + polygon.push_back(Vector2(1, 0) * unit); + polygon.push_back(Vector2(1, 1) * unit); + polygon.push_back(Vector2(0, 1) * unit); + break; + case TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_CORNER: + polygon.push_back(Vector2(0, 3) * unit); + polygon.push_back(Vector2(-3, 3) * unit); + polygon.push_back(Vector2(-3, 0) * unit); + polygon.push_back(Vector2(-1, 0) * unit); + polygon.push_back(Vector2(-1, 1) * unit); + polygon.push_back(Vector2(0, 1) * unit); + break; + case TileSet::CELL_NEIGHBOR_TOP_LEFT_CORNER: + polygon.push_back(Vector2(0, -3) * unit); + polygon.push_back(Vector2(-3, -3) * unit); + polygon.push_back(Vector2(-3, 0) * unit); + polygon.push_back(Vector2(-1, 0) * unit); + polygon.push_back(Vector2(-1, -1) * unit); + polygon.push_back(Vector2(0, -1) * unit); + break; + case TileSet::CELL_NEIGHBOR_TOP_RIGHT_CORNER: + polygon.push_back(Vector2(0, -3) * unit); + polygon.push_back(Vector2(3, -3) * unit); + polygon.push_back(Vector2(3, 0) * unit); + polygon.push_back(Vector2(1, 0) * unit); + polygon.push_back(Vector2(1, -1) * unit); + polygon.push_back(Vector2(0, -1) * unit); + break; + default: + break; + } + return polygon; +} + +Vector<Point2> TileSet::_get_square_side_terrain_bit_polygon(Vector2i p_size, TileSet::CellNeighbor p_bit) { + Vector2 unit = Vector2(p_size) / 6.0; + Vector<Vector2> polygon; + switch (p_bit) { + case TileSet::CELL_NEIGHBOR_RIGHT_SIDE: + polygon.push_back(Vector2(1, -1) * unit); + polygon.push_back(Vector2(3, -3) * unit); + polygon.push_back(Vector2(3, 3) * unit); + polygon.push_back(Vector2(1, 1) * unit); + break; + case TileSet::CELL_NEIGHBOR_BOTTOM_SIDE: + polygon.push_back(Vector2(-1, 1) * unit); + polygon.push_back(Vector2(-3, 3) * unit); + polygon.push_back(Vector2(3, 3) * unit); + polygon.push_back(Vector2(1, 1) * unit); + break; + case TileSet::CELL_NEIGHBOR_LEFT_SIDE: + polygon.push_back(Vector2(-1, -1) * unit); + polygon.push_back(Vector2(-3, -3) * unit); + polygon.push_back(Vector2(-3, 3) * unit); + polygon.push_back(Vector2(-1, 1) * unit); + break; + case TileSet::CELL_NEIGHBOR_TOP_SIDE: + polygon.push_back(Vector2(-1, -1) * unit); + polygon.push_back(Vector2(-3, -3) * unit); + polygon.push_back(Vector2(3, -3) * unit); + polygon.push_back(Vector2(1, -1) * unit); + break; + default: + break; + } + return polygon; +} + +Vector<Point2> TileSet::_get_isometric_corner_or_side_terrain_bit_polygon(Vector2i p_size, TileSet::CellNeighbor p_bit) { + Vector2 unit = Vector2(p_size) / 6.0; + Vector<Vector2> polygon; + switch (p_bit) { + case TileSet::CELL_NEIGHBOR_RIGHT_CORNER: + polygon.push_back(Vector2(1, 0) * unit); + polygon.push_back(Vector2(2, -1) * unit); + polygon.push_back(Vector2(3, 0) * unit); + polygon.push_back(Vector2(2, 1) * unit); + break; + case TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE: + polygon.push_back(Vector2(0, 1) * unit); + polygon.push_back(Vector2(1, 2) * unit); + polygon.push_back(Vector2(2, 1) * unit); + polygon.push_back(Vector2(1, 0) * unit); + break; + case TileSet::CELL_NEIGHBOR_BOTTOM_CORNER: + polygon.push_back(Vector2(0, 1) * unit); + polygon.push_back(Vector2(-1, 2) * unit); + polygon.push_back(Vector2(0, 3) * unit); + polygon.push_back(Vector2(1, 2) * unit); + break; + case TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE: + polygon.push_back(Vector2(0, 1) * unit); + polygon.push_back(Vector2(-1, 2) * unit); + polygon.push_back(Vector2(-2, 1) * unit); + polygon.push_back(Vector2(-1, 0) * unit); + break; + case TileSet::CELL_NEIGHBOR_LEFT_CORNER: + polygon.push_back(Vector2(-1, 0) * unit); + polygon.push_back(Vector2(-2, -1) * unit); + polygon.push_back(Vector2(-3, 0) * unit); + polygon.push_back(Vector2(-2, 1) * unit); + break; + case TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE: + polygon.push_back(Vector2(0, -1) * unit); + polygon.push_back(Vector2(-1, -2) * unit); + polygon.push_back(Vector2(-2, -1) * unit); + polygon.push_back(Vector2(-1, 0) * unit); + break; + case TileSet::CELL_NEIGHBOR_TOP_CORNER: + polygon.push_back(Vector2(0, -1) * unit); + polygon.push_back(Vector2(-1, -2) * unit); + polygon.push_back(Vector2(0, -3) * unit); + polygon.push_back(Vector2(1, -2) * unit); + break; + case TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE: + polygon.push_back(Vector2(0, -1) * unit); + polygon.push_back(Vector2(1, -2) * unit); + polygon.push_back(Vector2(2, -1) * unit); + polygon.push_back(Vector2(1, 0) * unit); + break; + default: + break; + } + return polygon; +} + +Vector<Point2> TileSet::_get_isometric_corner_terrain_bit_polygon(Vector2i p_size, TileSet::CellNeighbor p_bit) { + Vector2 unit = Vector2(p_size) / 6.0; + Vector<Vector2> polygon; + switch (p_bit) { + case TileSet::CELL_NEIGHBOR_RIGHT_CORNER: + polygon.push_back(Vector2(0.5, -0.5) * unit); + polygon.push_back(Vector2(1.5, -1.5) * unit); + polygon.push_back(Vector2(3, 0) * unit); + polygon.push_back(Vector2(1.5, 1.5) * unit); + polygon.push_back(Vector2(0.5, 0.5) * unit); + polygon.push_back(Vector2(1, 0) * unit); + break; + case TileSet::CELL_NEIGHBOR_BOTTOM_CORNER: + polygon.push_back(Vector2(-0.5, 0.5) * unit); + polygon.push_back(Vector2(-1.5, 1.5) * unit); + polygon.push_back(Vector2(0, 3) * unit); + polygon.push_back(Vector2(1.5, 1.5) * unit); + polygon.push_back(Vector2(0.5, 0.5) * unit); + polygon.push_back(Vector2(0, 1) * unit); + break; + case TileSet::CELL_NEIGHBOR_LEFT_CORNER: + polygon.push_back(Vector2(-0.5, -0.5) * unit); + polygon.push_back(Vector2(-1.5, -1.5) * unit); + polygon.push_back(Vector2(-3, 0) * unit); + polygon.push_back(Vector2(-1.5, 1.5) * unit); + polygon.push_back(Vector2(-0.5, 0.5) * unit); + polygon.push_back(Vector2(-1, 0) * unit); + break; + case TileSet::CELL_NEIGHBOR_TOP_CORNER: + polygon.push_back(Vector2(-0.5, -0.5) * unit); + polygon.push_back(Vector2(-1.5, -1.5) * unit); + polygon.push_back(Vector2(0, -3) * unit); + polygon.push_back(Vector2(1.5, -1.5) * unit); + polygon.push_back(Vector2(0.5, -0.5) * unit); + polygon.push_back(Vector2(0, -1) * unit); + break; + default: + break; + } + return polygon; +} + +Vector<Point2> TileSet::_get_isometric_side_terrain_bit_polygon(Vector2i p_size, TileSet::CellNeighbor p_bit) { + Vector2 unit = Vector2(p_size) / 6.0; + Vector<Vector2> polygon; + switch (p_bit) { + case TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE: + polygon.push_back(Vector2(1, 0) * unit); + polygon.push_back(Vector2(3, 0) * unit); + polygon.push_back(Vector2(0, 3) * unit); + polygon.push_back(Vector2(0, 1) * unit); + break; + case TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE: + polygon.push_back(Vector2(-1, 0) * unit); + polygon.push_back(Vector2(-3, 0) * unit); + polygon.push_back(Vector2(0, 3) * unit); + polygon.push_back(Vector2(0, 1) * unit); + break; + case TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE: + polygon.push_back(Vector2(-1, 0) * unit); + polygon.push_back(Vector2(-3, 0) * unit); + polygon.push_back(Vector2(0, -3) * unit); + polygon.push_back(Vector2(0, -1) * unit); + break; + case TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE: + polygon.push_back(Vector2(1, 0) * unit); + polygon.push_back(Vector2(3, 0) * unit); + polygon.push_back(Vector2(0, -3) * unit); + polygon.push_back(Vector2(0, -1) * unit); + break; + default: + break; + } + return polygon; +} + +Vector<Point2> TileSet::_get_half_offset_corner_or_side_terrain_bit_polygon(Vector2i p_size, TileSet::CellNeighbor p_bit, float p_overlap, TileSet::TileOffsetAxis p_offset_axis) { + Vector<Vector2> point_list; + point_list.push_back(Vector2(3, (3.0 * (1.0 - p_overlap * 2.0)) / 2.0)); + point_list.push_back(Vector2(3, 3.0 * (1.0 - p_overlap * 2.0))); + point_list.push_back(Vector2(2, 3.0 * (1.0 - (p_overlap * 2.0) * 2.0 / 3.0))); + point_list.push_back(Vector2(1, 3.0 - p_overlap * 2.0)); + point_list.push_back(Vector2(0, 3)); + point_list.push_back(Vector2(-1, 3.0 - p_overlap * 2.0)); + point_list.push_back(Vector2(-2, 3.0 * (1.0 - (p_overlap * 2.0) * 2.0 / 3.0))); + point_list.push_back(Vector2(-3, 3.0 * (1.0 - p_overlap * 2.0))); + point_list.push_back(Vector2(-3, (3.0 * (1.0 - p_overlap * 2.0)) / 2.0)); + point_list.push_back(Vector2(-3, -(3.0 * (1.0 - p_overlap * 2.0)) / 2.0)); + point_list.push_back(Vector2(-3, -3.0 * (1.0 - p_overlap * 2.0))); + point_list.push_back(Vector2(-2, -3.0 * (1.0 - (p_overlap * 2.0) * 2.0 / 3.0))); + point_list.push_back(Vector2(-1, -(3.0 - p_overlap * 2.0))); + point_list.push_back(Vector2(0, -3)); + point_list.push_back(Vector2(1, -(3.0 - p_overlap * 2.0))); + point_list.push_back(Vector2(2, -3.0 * (1.0 - (p_overlap * 2.0) * 2.0 / 3.0))); + point_list.push_back(Vector2(3, -3.0 * (1.0 - p_overlap * 2.0))); + point_list.push_back(Vector2(3, -(3.0 * (1.0 - p_overlap * 2.0)) / 2.0)); + + Vector2 unit = Vector2(p_size) / 6.0; + for (int i = 0; i < point_list.size(); i++) { + point_list.write[i] = point_list[i] * unit; + } + + Vector<Vector2> polygon; + if (p_offset_axis == TileSet::TILE_OFFSET_AXIS_HORIZONTAL) { + switch (p_bit) { + case TileSet::CELL_NEIGHBOR_RIGHT_SIDE: + polygon.push_back(point_list[17]); + polygon.push_back(point_list[0]); + break; + case TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER: + polygon.push_back(point_list[0]); + polygon.push_back(point_list[1]); + polygon.push_back(point_list[2]); + break; + case TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE: + polygon.push_back(point_list[2]); + polygon.push_back(point_list[3]); + break; + case TileSet::CELL_NEIGHBOR_BOTTOM_CORNER: + polygon.push_back(point_list[3]); + polygon.push_back(point_list[4]); + polygon.push_back(point_list[5]); + break; + case TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE: + polygon.push_back(point_list[5]); + polygon.push_back(point_list[6]); + break; + case TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_CORNER: + polygon.push_back(point_list[6]); + polygon.push_back(point_list[7]); + polygon.push_back(point_list[8]); + break; + case TileSet::CELL_NEIGHBOR_LEFT_SIDE: + polygon.push_back(point_list[8]); + polygon.push_back(point_list[9]); + break; + case TileSet::CELL_NEIGHBOR_TOP_LEFT_CORNER: + polygon.push_back(point_list[9]); + polygon.push_back(point_list[10]); + polygon.push_back(point_list[11]); + break; + case TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE: + polygon.push_back(point_list[11]); + polygon.push_back(point_list[12]); + break; + case TileSet::CELL_NEIGHBOR_TOP_CORNER: + polygon.push_back(point_list[12]); + polygon.push_back(point_list[13]); + polygon.push_back(point_list[14]); + break; + case TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE: + polygon.push_back(point_list[14]); + polygon.push_back(point_list[15]); + break; + case TileSet::CELL_NEIGHBOR_TOP_RIGHT_CORNER: + polygon.push_back(point_list[15]); + polygon.push_back(point_list[16]); + polygon.push_back(point_list[17]); + break; + default: + break; + } + } else { + if (p_offset_axis == TileSet::TILE_OFFSET_AXIS_VERTICAL) { + for (int i = 0; i < point_list.size(); i++) { + point_list.write[i] = Vector2(point_list[i].y, point_list[i].x); + } + } + switch (p_bit) { + case TileSet::CELL_NEIGHBOR_RIGHT_CORNER: + polygon.push_back(point_list[3]); + polygon.push_back(point_list[4]); + polygon.push_back(point_list[5]); + break; + case TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE: + polygon.push_back(point_list[2]); + polygon.push_back(point_list[3]); + break; + case TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER: + polygon.push_back(point_list[0]); + polygon.push_back(point_list[1]); + polygon.push_back(point_list[2]); + break; + case TileSet::CELL_NEIGHBOR_BOTTOM_SIDE: + polygon.push_back(point_list[17]); + polygon.push_back(point_list[0]); + break; + case TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_CORNER: + polygon.push_back(point_list[15]); + polygon.push_back(point_list[16]); + polygon.push_back(point_list[17]); + break; + case TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE: + polygon.push_back(point_list[14]); + polygon.push_back(point_list[15]); + break; + case TileSet::CELL_NEIGHBOR_LEFT_CORNER: + polygon.push_back(point_list[12]); + polygon.push_back(point_list[13]); + polygon.push_back(point_list[14]); + break; + case TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE: + polygon.push_back(point_list[11]); + polygon.push_back(point_list[12]); + break; + case TileSet::CELL_NEIGHBOR_TOP_LEFT_CORNER: + polygon.push_back(point_list[9]); + polygon.push_back(point_list[10]); + polygon.push_back(point_list[11]); + break; + case TileSet::CELL_NEIGHBOR_TOP_SIDE: + polygon.push_back(point_list[8]); + polygon.push_back(point_list[9]); + break; + case TileSet::CELL_NEIGHBOR_TOP_RIGHT_CORNER: + polygon.push_back(point_list[6]); + polygon.push_back(point_list[7]); + polygon.push_back(point_list[8]); + break; + case TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE: + polygon.push_back(point_list[5]); + polygon.push_back(point_list[6]); + break; + default: + break; + } + } + + int half_polygon_size = polygon.size(); + for (int i = 0; i < half_polygon_size; i++) { + polygon.push_back(polygon[half_polygon_size - 1 - i] / 3.0); + } + + return polygon; +} + +Vector<Point2> TileSet::_get_half_offset_corner_terrain_bit_polygon(Vector2i p_size, TileSet::CellNeighbor p_bit, float p_overlap, TileSet::TileOffsetAxis p_offset_axis) { + Vector<Vector2> point_list; + point_list.push_back(Vector2(3, 0)); + point_list.push_back(Vector2(3, 3.0 * (1.0 - p_overlap * 2.0))); + point_list.push_back(Vector2(1.5, (3.0 * (1.0 - p_overlap * 2.0) + 3.0) / 2.0)); + point_list.push_back(Vector2(0, 3)); + point_list.push_back(Vector2(-1.5, (3.0 * (1.0 - p_overlap * 2.0) + 3.0) / 2.0)); + point_list.push_back(Vector2(-3, 3.0 * (1.0 - p_overlap * 2.0))); + point_list.push_back(Vector2(-3, 0)); + point_list.push_back(Vector2(-3, -3.0 * (1.0 - p_overlap * 2.0))); + point_list.push_back(Vector2(-1.5, -(3.0 * (1.0 - p_overlap * 2.0) + 3.0) / 2.0)); + point_list.push_back(Vector2(0, -3)); + point_list.push_back(Vector2(1.5, -(3.0 * (1.0 - p_overlap * 2.0) + 3.0) / 2.0)); + point_list.push_back(Vector2(3, -3.0 * (1.0 - p_overlap * 2.0))); + + Vector2 unit = Vector2(p_size) / 6.0; + for (int i = 0; i < point_list.size(); i++) { + point_list.write[i] = point_list[i] * unit; + } + + Vector<Vector2> polygon; + if (p_offset_axis == TileSet::TILE_OFFSET_AXIS_HORIZONTAL) { + switch (p_bit) { + case TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER: + polygon.push_back(point_list[0]); + polygon.push_back(point_list[1]); + polygon.push_back(point_list[2]); + break; + case TileSet::CELL_NEIGHBOR_BOTTOM_CORNER: + polygon.push_back(point_list[2]); + polygon.push_back(point_list[3]); + polygon.push_back(point_list[4]); + break; + case TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_CORNER: + polygon.push_back(point_list[4]); + polygon.push_back(point_list[5]); + polygon.push_back(point_list[6]); + break; + case TileSet::CELL_NEIGHBOR_TOP_LEFT_CORNER: + polygon.push_back(point_list[6]); + polygon.push_back(point_list[7]); + polygon.push_back(point_list[8]); + break; + case TileSet::CELL_NEIGHBOR_TOP_CORNER: + polygon.push_back(point_list[8]); + polygon.push_back(point_list[9]); + polygon.push_back(point_list[10]); + break; + case TileSet::CELL_NEIGHBOR_TOP_RIGHT_CORNER: + polygon.push_back(point_list[10]); + polygon.push_back(point_list[11]); + polygon.push_back(point_list[0]); + break; + default: + break; + } + } else { + if (p_offset_axis == TileSet::TILE_OFFSET_AXIS_VERTICAL) { + for (int i = 0; i < point_list.size(); i++) { + point_list.write[i] = Vector2(point_list[i].y, point_list[i].x); + } + } + switch (p_bit) { + case TileSet::CELL_NEIGHBOR_RIGHT_CORNER: + polygon.push_back(point_list[2]); + polygon.push_back(point_list[3]); + polygon.push_back(point_list[4]); + break; + case TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER: + polygon.push_back(point_list[0]); + polygon.push_back(point_list[1]); + polygon.push_back(point_list[2]); + break; + case TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_CORNER: + polygon.push_back(point_list[10]); + polygon.push_back(point_list[11]); + polygon.push_back(point_list[0]); + break; + case TileSet::CELL_NEIGHBOR_LEFT_CORNER: + polygon.push_back(point_list[8]); + polygon.push_back(point_list[9]); + polygon.push_back(point_list[10]); + break; + case TileSet::CELL_NEIGHBOR_TOP_LEFT_CORNER: + polygon.push_back(point_list[6]); + polygon.push_back(point_list[7]); + polygon.push_back(point_list[8]); + break; + case TileSet::CELL_NEIGHBOR_TOP_RIGHT_CORNER: + polygon.push_back(point_list[4]); + polygon.push_back(point_list[5]); + polygon.push_back(point_list[6]); + break; + default: + break; + } + } + + int half_polygon_size = polygon.size(); + for (int i = 0; i < half_polygon_size; i++) { + polygon.push_back(polygon[half_polygon_size - 1 - i] / 3.0); + } + + return polygon; +} + +Vector<Point2> TileSet::_get_half_offset_side_terrain_bit_polygon(Vector2i p_size, TileSet::CellNeighbor p_bit, float p_overlap, TileSet::TileOffsetAxis p_offset_axis) { + Vector<Vector2> point_list; + point_list.push_back(Vector2(3, 3.0 * (1.0 - p_overlap * 2.0))); + point_list.push_back(Vector2(0, 3)); + point_list.push_back(Vector2(-3, 3.0 * (1.0 - p_overlap * 2.0))); + point_list.push_back(Vector2(-3, -3.0 * (1.0 - p_overlap * 2.0))); + point_list.push_back(Vector2(0, -3)); + point_list.push_back(Vector2(3, -3.0 * (1.0 - p_overlap * 2.0))); + + Vector2 unit = Vector2(p_size) / 6.0; + for (int i = 0; i < point_list.size(); i++) { + point_list.write[i] = point_list[i] * unit; + } + + Vector<Vector2> polygon; + if (p_offset_axis == TileSet::TILE_OFFSET_AXIS_HORIZONTAL) { + switch (p_bit) { + case TileSet::CELL_NEIGHBOR_RIGHT_SIDE: + polygon.push_back(point_list[5]); + polygon.push_back(point_list[0]); + break; + case TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE: + polygon.push_back(point_list[0]); + polygon.push_back(point_list[1]); + break; + case TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE: + polygon.push_back(point_list[1]); + polygon.push_back(point_list[2]); + break; + case TileSet::CELL_NEIGHBOR_LEFT_SIDE: + polygon.push_back(point_list[2]); + polygon.push_back(point_list[3]); + break; + case TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE: + polygon.push_back(point_list[3]); + polygon.push_back(point_list[4]); + break; + case TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE: + polygon.push_back(point_list[4]); + polygon.push_back(point_list[5]); + break; + default: + break; + } + } else { + if (p_offset_axis == TileSet::TILE_OFFSET_AXIS_VERTICAL) { + for (int i = 0; i < point_list.size(); i++) { + point_list.write[i] = Vector2(point_list[i].y, point_list[i].x); + } + } + switch (p_bit) { + case TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE: + polygon.push_back(point_list[0]); + polygon.push_back(point_list[1]); + break; + case TileSet::CELL_NEIGHBOR_BOTTOM_SIDE: + polygon.push_back(point_list[5]); + polygon.push_back(point_list[0]); + break; + case TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE: + polygon.push_back(point_list[4]); + polygon.push_back(point_list[5]); + break; + case TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE: + polygon.push_back(point_list[3]); + polygon.push_back(point_list[4]); + break; + case TileSet::CELL_NEIGHBOR_TOP_SIDE: + polygon.push_back(point_list[2]); + polygon.push_back(point_list[3]); + break; + case TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE: + polygon.push_back(point_list[1]); + polygon.push_back(point_list[2]); + break; + default: + break; + } + } + + int half_polygon_size = polygon.size(); + for (int i = 0; i < half_polygon_size; i++) { + polygon.push_back(polygon[half_polygon_size - 1 - i] / 3.0); + } + + return polygon; } void TileSet::reset_state() { @@ -747,12 +1614,18 @@ void TileSet::compatibility_conversion() { for (int k = 0; k < ctd->shapes.size(); k++) { CompatibilityShapeData csd = ctd->shapes[k]; if (csd.autotile_coords == coords) { - tile_data->set_collision_shapes_count(0, tile_data->get_collision_shapes_count(0) + 1); - int index = tile_data->get_collision_shapes_count(0) - 1; - tile_data->set_collision_shape_one_way(0, index, csd.one_way); - tile_data->set_collision_shape_one_way_margin(0, index, csd.one_way_margin); - tile_data->set_collision_shape_shape(0, index, csd.shape); - // Ignores transform for now. + Ref<ConvexPolygonShape2D> convex_shape = csd.shape; // Only ConvexPolygonShape2D are supported, which is the default type used by the 3.x editor + if (convex_shape.is_valid()) { + Vector<Vector2> polygon = convex_shape->get_points(); + for (int point_index = 0; point_index < polygon.size(); point_index++) { + polygon.write[point_index] = csd.transform.xform(polygon[point_index]); + } + tile_data->set_collision_polygons_count(0, tile_data->get_collision_polygons_count(0) + 1); + int index = tile_data->get_collision_polygons_count(0) - 1; + tile_data->set_collision_polygon_one_way(0, index, csd.one_way); + tile_data->set_collision_polygon_one_way_margin(0, index, csd.one_way_margin); + tile_data->set_collision_polygon_points(0, index, polygon); + } } } @@ -1086,7 +1959,7 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) { return true; } } else if (components.size() == 2 && components[0] == "sources" && components[1].is_valid_int()) { - // Create source only if it does not exist. + // Create source only if it does not exists. int source_id = components[1].to_int(); if (!has_source(source_id)) { @@ -1287,14 +2160,11 @@ void TileSet::_bind_methods() { ClassDB::bind_method(D_METHOD("get_tile_offset_axis"), &TileSet::get_tile_offset_axis); ClassDB::bind_method(D_METHOD("set_tile_size", "size"), &TileSet::set_tile_size); ClassDB::bind_method(D_METHOD("get_tile_size"), &TileSet::get_tile_size); - ClassDB::bind_method(D_METHOD("set_tile_skew", "skew"), &TileSet::set_tile_skew); - ClassDB::bind_method(D_METHOD("get_tile_skew"), &TileSet::get_tile_skew); ADD_PROPERTY(PropertyInfo(Variant::INT, "tile_shape", PROPERTY_HINT_ENUM, "Square,Isometric,Half-Offset Square,Hexagon"), "set_tile_shape", "get_tile_shape"); ADD_PROPERTY(PropertyInfo(Variant::INT, "tile_layout", PROPERTY_HINT_ENUM, "Stacked,Stacked Offset,Stairs Right,Stairs Down,Diamond Right,Diamond Down"), "set_tile_layout", "get_tile_layout"); ADD_PROPERTY(PropertyInfo(Variant::INT, "tile_offset_axis", PROPERTY_HINT_ENUM, "Horizontal Offset,Vertical Offset"), "set_tile_offset_axis", "get_tile_offset_axis"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "tile_size"), "set_tile_size", "get_tile_size"); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "tile_skew"), "set_tile_skew", "get_tile_skew"); // Rendering. ClassDB::bind_method(D_METHOD("set_uv_clipping", "uv_clipping"), &TileSet::set_uv_clipping); @@ -1375,22 +2245,22 @@ void TileSet::_bind_methods() { BIND_ENUM_CONSTANT(TILE_OFFSET_AXIS_HORIZONTAL); BIND_ENUM_CONSTANT(TILE_OFFSET_AXIS_VERTICAL); - BIND_ENUM_CONSTANT(TileSet::CELL_NEIGHBOR_RIGHT_SIDE); - BIND_ENUM_CONSTANT(TileSet::CELL_NEIGHBOR_RIGHT_CORNER); - BIND_ENUM_CONSTANT(TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE); - BIND_ENUM_CONSTANT(TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER); - BIND_ENUM_CONSTANT(TileSet::CELL_NEIGHBOR_BOTTOM_SIDE); - BIND_ENUM_CONSTANT(TileSet::CELL_NEIGHBOR_BOTTOM_CORNER); - BIND_ENUM_CONSTANT(TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE); - BIND_ENUM_CONSTANT(TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_CORNER); - BIND_ENUM_CONSTANT(TileSet::CELL_NEIGHBOR_LEFT_SIDE); - BIND_ENUM_CONSTANT(TileSet::CELL_NEIGHBOR_LEFT_CORNER); - BIND_ENUM_CONSTANT(TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE); - BIND_ENUM_CONSTANT(TileSet::CELL_NEIGHBOR_TOP_LEFT_CORNER); - BIND_ENUM_CONSTANT(TileSet::CELL_NEIGHBOR_TOP_SIDE); - BIND_ENUM_CONSTANT(TileSet::CELL_NEIGHBOR_TOP_CORNER); - BIND_ENUM_CONSTANT(TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE); - BIND_ENUM_CONSTANT(TileSet::CELL_NEIGHBOR_TOP_RIGHT_CORNER); + BIND_ENUM_CONSTANT(CELL_NEIGHBOR_RIGHT_SIDE); + BIND_ENUM_CONSTANT(CELL_NEIGHBOR_RIGHT_CORNER); + BIND_ENUM_CONSTANT(CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE); + BIND_ENUM_CONSTANT(CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER); + BIND_ENUM_CONSTANT(CELL_NEIGHBOR_BOTTOM_SIDE); + BIND_ENUM_CONSTANT(CELL_NEIGHBOR_BOTTOM_CORNER); + BIND_ENUM_CONSTANT(CELL_NEIGHBOR_BOTTOM_LEFT_SIDE); + BIND_ENUM_CONSTANT(CELL_NEIGHBOR_BOTTOM_LEFT_CORNER); + BIND_ENUM_CONSTANT(CELL_NEIGHBOR_LEFT_SIDE); + BIND_ENUM_CONSTANT(CELL_NEIGHBOR_LEFT_CORNER); + BIND_ENUM_CONSTANT(CELL_NEIGHBOR_TOP_LEFT_SIDE); + BIND_ENUM_CONSTANT(CELL_NEIGHBOR_TOP_LEFT_CORNER); + BIND_ENUM_CONSTANT(CELL_NEIGHBOR_TOP_SIDE); + BIND_ENUM_CONSTANT(CELL_NEIGHBOR_TOP_CORNER); + BIND_ENUM_CONSTANT(CELL_NEIGHBOR_TOP_RIGHT_SIDE); + BIND_ENUM_CONSTANT(CELL_NEIGHBOR_TOP_RIGHT_CORNER); BIND_ENUM_CONSTANT(TERRAIN_MODE_MATCH_CORNERS_AND_SIDES); BIND_ENUM_CONSTANT(TERRAIN_MODE_MATCH_CORNERS); @@ -1398,10 +2268,13 @@ void TileSet::_bind_methods() { } TileSet::TileSet() { - // Instanciatie and list all plugins. + // Instantiate the tile meshes. + tile_lines_mesh.instantiate(); + tile_filled_mesh.instantiate(); + + // Instanciate and list all plugins. tile_set_plugins_vector.append(memnew(TileSetPluginAtlasRendering)); tile_set_plugins_vector.append(memnew(TileSetPluginAtlasPhysics)); - tile_set_plugins_vector.append(memnew(TileSetPluginAtlasTerrain)); tile_set_plugins_vector.append(memnew(TileSetPluginAtlasNavigation)); tile_set_plugins_vector.append(memnew(TileSetPluginScenesCollections)); } @@ -2237,16 +3110,14 @@ void TileSetScenesCollectionSource::_bind_methods() { void TileData::set_tile_set(const TileSet *p_tile_set) { tile_set = p_tile_set; - if (tile_set) { - occluders.resize(tile_set->get_occlusion_layers_count()); - physics.resize(tile_set->get_physics_layers_count()); - navigation.resize(tile_set->get_navigation_layers_count()); - custom_data.resize(tile_set->get_custom_data_layers_count()); - } - notify_property_list_changed(); + notify_tile_data_properties_should_change(); } void TileData::notify_tile_data_properties_should_change() { + if (!tile_set) { + return; + } + occluders.resize(tile_set->get_occlusion_layers_count()); physics.resize(tile_set->get_physics_layers_count()); for (int bit_index = 0; bit_index < 16; bit_index++) { @@ -2373,76 +3244,112 @@ Ref<OccluderPolygon2D> TileData::get_occluder(int p_layer_id) const { } // Physics -int TileData::get_collision_shapes_count(int p_layer_id) const { +int TileData::get_collision_polygons_count(int p_layer_id) const { ERR_FAIL_INDEX_V(p_layer_id, physics.size(), 0); - return physics[p_layer_id].shapes.size(); + return physics[p_layer_id].polygons.size(); } -void TileData::set_collision_shapes_count(int p_layer_id, int p_shapes_count) { +void TileData::set_collision_polygons_count(int p_layer_id, int p_polygons_count) { ERR_FAIL_INDEX(p_layer_id, physics.size()); - ERR_FAIL_COND(p_shapes_count < 0); - physics.write[p_layer_id].shapes.resize(p_shapes_count); + ERR_FAIL_COND(p_polygons_count < 0); + physics.write[p_layer_id].polygons.resize(p_polygons_count); notify_property_list_changed(); emit_signal("changed"); } -void TileData::add_collision_shape(int p_layer_id) { +void TileData::add_collision_polygon(int p_layer_id) { ERR_FAIL_INDEX(p_layer_id, physics.size()); - physics.write[p_layer_id].shapes.push_back(PhysicsLayerTileData::ShapeTileData()); + physics.write[p_layer_id].polygons.push_back(PhysicsLayerTileData::PolygonShapeTileData()); emit_signal("changed"); } -void TileData::remove_collision_shape(int p_layer_id, int p_shape_index) { +void TileData::remove_collision_polygon(int p_layer_id, int p_polygon_index) { ERR_FAIL_INDEX(p_layer_id, physics.size()); - ERR_FAIL_INDEX(p_shape_index, physics[p_layer_id].shapes.size()); - physics.write[p_layer_id].shapes.remove(p_shape_index); + ERR_FAIL_INDEX(p_polygon_index, physics[p_layer_id].polygons.size()); + physics.write[p_layer_id].polygons.remove(p_polygon_index); emit_signal("changed"); } -void TileData::set_collision_shape_shape(int p_layer_id, int p_shape_index, Ref<Shape2D> p_shape) { +void TileData::set_collision_polygon_points(int p_layer_id, int p_polygon_index, Vector<Vector2> p_polygon) { ERR_FAIL_INDEX(p_layer_id, physics.size()); - ERR_FAIL_INDEX(p_shape_index, physics[p_layer_id].shapes.size()); - physics.write[p_layer_id].shapes.write[p_shape_index].shape = p_shape; + ERR_FAIL_INDEX(p_polygon_index, physics[p_layer_id].polygons.size()); + ERR_FAIL_COND_MSG(p_polygon.size() != 0 && p_polygon.size() < 3, "Invalid polygon. Needs either 0 or more than 3 points."); + + if (p_polygon.is_empty()) { + physics.write[p_layer_id].polygons.write[p_polygon_index].shapes.clear(); + } else { + // Decompose into convex shapes. + Vector<Vector<Vector2>> decomp = Geometry2D::decompose_polygon_in_convex(p_polygon); + ERR_FAIL_COND_MSG(decomp.is_empty(), "Could not decompose the polygon into convex shapes."); + + physics.write[p_layer_id].polygons.write[p_polygon_index].shapes.resize(decomp.size()); + for (int i = 0; i < decomp.size(); i++) { + Ref<ConvexPolygonShape2D> shape; + shape.instantiate(); + shape->set_points(decomp[i]); + physics.write[p_layer_id].polygons.write[p_polygon_index].shapes[i] = shape; + } + } + physics.write[p_layer_id].polygons.write[p_polygon_index].polygon = p_polygon; emit_signal("changed"); } -Ref<Shape2D> TileData::get_collision_shape_shape(int p_layer_id, int p_shape_index) const { - ERR_FAIL_INDEX_V(p_layer_id, physics.size(), Ref<Shape2D>()); - ERR_FAIL_INDEX_V(p_shape_index, physics[p_layer_id].shapes.size(), Ref<Shape2D>()); - return physics[p_layer_id].shapes[p_shape_index].shape; +Vector<Vector2> TileData::get_collision_polygon_points(int p_layer_id, int p_polygon_index) const { + ERR_FAIL_INDEX_V(p_layer_id, physics.size(), Vector<Vector2>()); + ERR_FAIL_INDEX_V(p_polygon_index, physics[p_layer_id].polygons.size(), Vector<Vector2>()); + return physics[p_layer_id].polygons[p_polygon_index].polygon; } -void TileData::set_collision_shape_one_way(int p_layer_id, int p_shape_index, bool p_one_way) { +void TileData::set_collision_polygon_one_way(int p_layer_id, int p_polygon_index, bool p_one_way) { ERR_FAIL_INDEX(p_layer_id, physics.size()); - ERR_FAIL_INDEX(p_shape_index, physics[p_layer_id].shapes.size()); - physics.write[p_layer_id].shapes.write[p_shape_index].one_way = p_one_way; + ERR_FAIL_INDEX(p_polygon_index, physics[p_layer_id].polygons.size()); + physics.write[p_layer_id].polygons.write[p_polygon_index].one_way = p_one_way; emit_signal("changed"); } -bool TileData::is_collision_shape_one_way(int p_layer_id, int p_shape_index) const { +bool TileData::is_collision_polygon_one_way(int p_layer_id, int p_polygon_index) const { ERR_FAIL_INDEX_V(p_layer_id, physics.size(), false); - ERR_FAIL_INDEX_V(p_shape_index, physics[p_layer_id].shapes.size(), false); - return physics[p_layer_id].shapes[p_shape_index].one_way; + ERR_FAIL_INDEX_V(p_polygon_index, physics[p_layer_id].polygons.size(), false); + return physics[p_layer_id].polygons[p_polygon_index].one_way; } -void TileData::set_collision_shape_one_way_margin(int p_layer_id, int p_shape_index, float p_one_way_margin) { +void TileData::set_collision_polygon_one_way_margin(int p_layer_id, int p_polygon_index, float p_one_way_margin) { ERR_FAIL_INDEX(p_layer_id, physics.size()); - ERR_FAIL_INDEX(p_shape_index, physics[p_layer_id].shapes.size()); - physics.write[p_layer_id].shapes.write[p_shape_index].one_way_margin = p_one_way_margin; + ERR_FAIL_INDEX(p_polygon_index, physics[p_layer_id].polygons.size()); + physics.write[p_layer_id].polygons.write[p_polygon_index].one_way_margin = p_one_way_margin; emit_signal("changed"); } -float TileData::get_collision_shape_one_way_margin(int p_layer_id, int p_shape_index) const { +float TileData::get_collision_polygon_one_way_margin(int p_layer_id, int p_polygon_index) const { ERR_FAIL_INDEX_V(p_layer_id, physics.size(), 0.0); - ERR_FAIL_INDEX_V(p_shape_index, physics[p_layer_id].shapes.size(), 0.0); - return physics[p_layer_id].shapes[p_shape_index].one_way_margin; + ERR_FAIL_INDEX_V(p_polygon_index, physics[p_layer_id].polygons.size(), 0.0); + return physics[p_layer_id].polygons[p_polygon_index].one_way_margin; +} + +int TileData::get_collision_polygon_shapes_count(int p_layer_id, int p_polygon_index) const { + ERR_FAIL_INDEX_V(p_layer_id, physics.size(), 0); + ERR_FAIL_INDEX_V(p_polygon_index, physics[p_layer_id].polygons.size(), 0); + return physics[p_layer_id].polygons[p_polygon_index].shapes.size(); +} + +Ref<ConvexPolygonShape2D> TileData::get_collision_polygon_shape(int p_layer_id, int p_polygon_index, int shape_index) const { + ERR_FAIL_INDEX_V(p_layer_id, physics.size(), 0); + ERR_FAIL_INDEX_V(p_polygon_index, physics[p_layer_id].polygons.size(), Ref<ConvexPolygonShape2D>()); + ERR_FAIL_INDEX_V(shape_index, (int)physics[p_layer_id].polygons[shape_index].shapes.size(), Ref<ConvexPolygonShape2D>()); + return physics[p_layer_id].polygons[shape_index].shapes[shape_index]; } // Terrain void TileData::set_terrain_set(int p_terrain_set) { ERR_FAIL_COND(p_terrain_set < -1); + if (p_terrain_set == terrain_set) { + return; + } if (tile_set) { ERR_FAIL_COND(p_terrain_set >= tile_set->get_terrain_sets_count()); + for (int i = 0; i < 16; i++) { + terrain_peering_bits[i] = -1; + } } terrain_set = p_terrain_set; notify_property_list_changed(); @@ -2454,7 +3361,7 @@ int TileData::get_terrain_set() const { } void TileData::set_peering_bit_terrain(TileSet::CellNeighbor p_peering_bit, int p_terrain_index) { - ERR_FAIL_INDEX(p_peering_bit, TileSet::CELL_NEIGHBOR_MAX); + ERR_FAIL_COND(terrain_set < 0); ERR_FAIL_COND(p_terrain_index < -1); if (tile_set) { ERR_FAIL_COND(p_terrain_index >= tile_set->get_terrains_count(terrain_set)); @@ -2465,7 +3372,7 @@ void TileData::set_peering_bit_terrain(TileSet::CellNeighbor p_peering_bit, int } int TileData::get_peering_bit_terrain(TileSet::CellNeighbor p_peering_bit) const { - ERR_FAIL_INDEX_V(p_peering_bit, TileSet::CELL_NEIGHBOR_MAX, -1); + ERR_FAIL_COND_V(!is_valid_peering_bit_terrain(p_peering_bit), -1); return terrain_peering_bits[p_peering_bit]; } @@ -2489,7 +3396,7 @@ Ref<NavigationPolygon> TileData::get_navigation_polygon(int p_layer_id) const { // Misc void TileData::set_probability(float p_probability) { - ERR_FAIL_COND(p_probability <= 0.0); + ERR_FAIL_COND(p_probability < 0.0); probability = p_probability; emit_signal("changed"); } @@ -2550,7 +3457,7 @@ bool TileData::_set(const StringName &p_name, const Variant &p_value) { // Physics layers. int layer_index = components[0].trim_prefix("physics_layer_").to_int(); ERR_FAIL_COND_V(layer_index < 0, false); - if (components.size() == 2 && components[1] == "shapes_count") { + if (components.size() == 2 && components[1] == "polygons_count") { if (p_value.get_type() != Variant::INT) { return false; } @@ -2562,13 +3469,13 @@ bool TileData::_set(const StringName &p_name, const Variant &p_value) { physics.resize(layer_index + 1); } } - set_collision_shapes_count(layer_index, p_value); + set_collision_polygons_count(layer_index, p_value); return true; - } else if (components.size() == 3 && components[1].begins_with("shape_") && components[1].trim_prefix("shape_").is_valid_int()) { - int shape_index = components[1].trim_prefix("shape_").to_int(); - ERR_FAIL_COND_V(shape_index < 0, false); + } else if (components.size() == 3 && components[1].begins_with("polygon_") && components[1].trim_prefix("polygon_").is_valid_int()) { + int polygon_index = components[1].trim_prefix("polygon_").to_int(); + ERR_FAIL_COND_V(polygon_index < 0, false); - if (components[2] == "shape" || components[2] == "one_way" || components[2] == "one_way_margin") { + if (components[2] == "points" || components[2] == "one_way" || components[2] == "one_way_margin") { if (layer_index >= physics.size()) { if (tile_set) { return false; @@ -2577,19 +3484,19 @@ bool TileData::_set(const StringName &p_name, const Variant &p_value) { } } - if (shape_index >= physics[layer_index].shapes.size()) { - physics.write[layer_index].shapes.resize(shape_index + 1); + if (polygon_index >= physics[layer_index].polygons.size()) { + physics.write[layer_index].polygons.resize(polygon_index + 1); } } - if (components[2] == "shape") { - Ref<Shape2D> shape = p_value; - set_collision_shape_shape(layer_index, shape_index, shape); + if (components[2] == "points") { + Vector<Vector2> polygon = p_value; + set_collision_polygon_points(layer_index, polygon_index, polygon); return true; } else if (components[2] == "one_way") { - set_collision_shape_one_way(layer_index, shape_index, p_value); + set_collision_polygon_one_way(layer_index, polygon_index, p_value); return true; } else if (components[2] == "one_way_margin") { - set_collision_shape_one_way_margin(layer_index, shape_index, p_value); + set_collision_polygon_one_way_margin(layer_index, polygon_index, p_value); return true; } } @@ -2615,42 +3522,14 @@ bool TileData::_set(const StringName &p_name, const Variant &p_value) { } } else if (components.size() == 2 && components[0] == "terrains_peering_bit") { // Terrains. - if (components[1] == "right_side") { - set_peering_bit_terrain(TileSet::CELL_NEIGHBOR_RIGHT_SIDE, p_value); - } else if (components[1] == "right_corner") { - set_peering_bit_terrain(TileSet::CELL_NEIGHBOR_RIGHT_CORNER, p_value); - } else if (components[1] == "bottom_right_side") { - set_peering_bit_terrain(TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE, p_value); - } else if (components[1] == "bottom_right_corner") { - set_peering_bit_terrain(TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER, p_value); - } else if (components[1] == "bottom_side") { - set_peering_bit_terrain(TileSet::CELL_NEIGHBOR_BOTTOM_SIDE, p_value); - } else if (components[1] == "bottom_corner") { - set_peering_bit_terrain(TileSet::CELL_NEIGHBOR_BOTTOM_CORNER, p_value); - } else if (components[1] == "bottom_left_side") { - set_peering_bit_terrain(TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE, p_value); - } else if (components[1] == "bottom_left_corner") { - set_peering_bit_terrain(TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_CORNER, p_value); - } else if (components[1] == "left_side") { - set_peering_bit_terrain(TileSet::CELL_NEIGHBOR_LEFT_SIDE, p_value); - } else if (components[1] == "left_corner") { - set_peering_bit_terrain(TileSet::CELL_NEIGHBOR_LEFT_CORNER, p_value); - } else if (components[1] == "top_left_side") { - set_peering_bit_terrain(TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE, p_value); - } else if (components[1] == "top_left_corner") { - set_peering_bit_terrain(TileSet::CELL_NEIGHBOR_TOP_LEFT_CORNER, p_value); - } else if (components[1] == "top_side") { - set_peering_bit_terrain(TileSet::CELL_NEIGHBOR_TOP_SIDE, p_value); - } else if (components[1] == "top_corner") { - set_peering_bit_terrain(TileSet::CELL_NEIGHBOR_TOP_CORNER, p_value); - } else if (components[1] == "top_right_side") { - set_peering_bit_terrain(TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE, p_value); - } else if (components[1] == "top_right_corner") { - set_peering_bit_terrain(TileSet::CELL_NEIGHBOR_TOP_RIGHT_CORNER, p_value); - } else { - return false; + for (int i = 0; i < TileSet::CELL_NEIGHBOR_MAX; i++) { + TileSet::CellNeighbor bit = TileSet::CellNeighbor(i); + if (components[1] == TileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[i]) { + set_peering_bit_terrain(bit, p_value); + return true; + } } - return true; + return false; } else if (components.size() == 1 && components[0].begins_with("custom_data_") && components[0].trim_prefix("custom_data_").is_valid_int()) { // Custom data layers. int layer_index = components[0].trim_prefix("custom_data_").to_int(); @@ -2693,64 +3572,35 @@ bool TileData::_get(const StringName &p_name, Variant &r_ret) const { if (layer_index >= physics.size()) { return false; } - if (components.size() == 2 && components[1] == "shapes_count") { - r_ret = get_collision_shapes_count(layer_index); + if (components.size() == 2 && components[1] == "polygons_count") { + r_ret = get_collision_polygons_count(layer_index); return true; - } else if (components.size() == 3 && components[1].begins_with("shape_") && components[1].trim_prefix("shape_").is_valid_int()) { - int shape_index = components[1].trim_prefix("shape_").to_int(); - ERR_FAIL_COND_V(shape_index < 0, false); - if (shape_index >= physics[layer_index].shapes.size()) { + } else if (components.size() == 3 && components[1].begins_with("polygon_") && components[1].trim_prefix("polygon_").is_valid_int()) { + int polygon_index = components[1].trim_prefix("polygon_").to_int(); + ERR_FAIL_COND_V(polygon_index < 0, false); + if (polygon_index >= physics[layer_index].polygons.size()) { return false; } - if (components[2] == "shape") { - r_ret = get_collision_shape_shape(layer_index, shape_index); + if (components[2] == "points") { + r_ret = get_collision_polygon_points(layer_index, polygon_index); return true; } else if (components[2] == "one_way") { - r_ret = is_collision_shape_one_way(layer_index, shape_index); + r_ret = is_collision_polygon_one_way(layer_index, polygon_index); return true; } else if (components[2] == "one_way_margin") { - r_ret = get_collision_shape_one_way_margin(layer_index, shape_index); + r_ret = get_collision_polygon_one_way_margin(layer_index, polygon_index); return true; } } } else if (components.size() == 2 && components[0] == "terrains_peering_bit") { // Terrains. - if (components[1] == "right_side") { - r_ret = terrain_peering_bits[TileSet::CELL_NEIGHBOR_RIGHT_SIDE]; - } else if (components[1] == "right_corner") { - r_ret = terrain_peering_bits[TileSet::CELL_NEIGHBOR_RIGHT_CORNER]; - } else if (components[1] == "bottom_right_side") { - r_ret = terrain_peering_bits[TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE]; - } else if (components[1] == "bottom_right_corner") { - r_ret = terrain_peering_bits[TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER]; - } else if (components[1] == "bottom_side") { - r_ret = terrain_peering_bits[TileSet::CELL_NEIGHBOR_BOTTOM_SIDE]; - } else if (components[1] == "bottom_corner") { - r_ret = terrain_peering_bits[TileSet::CELL_NEIGHBOR_BOTTOM_CORNER]; - } else if (components[1] == "bottom_left_side") { - r_ret = terrain_peering_bits[TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE]; - } else if (components[1] == "bottom_left_corner") { - r_ret = terrain_peering_bits[TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_CORNER]; - } else if (components[1] == "left_side") { - r_ret = terrain_peering_bits[TileSet::CELL_NEIGHBOR_LEFT_SIDE]; - } else if (components[1] == "left_corner") { - r_ret = terrain_peering_bits[TileSet::CELL_NEIGHBOR_LEFT_CORNER]; - } else if (components[1] == "top_left_side") { - r_ret = terrain_peering_bits[TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE]; - } else if (components[1] == "top_left_corner") { - r_ret = terrain_peering_bits[TileSet::CELL_NEIGHBOR_TOP_LEFT_CORNER]; - } else if (components[1] == "top_side") { - r_ret = terrain_peering_bits[TileSet::CELL_NEIGHBOR_TOP_SIDE]; - } else if (components[1] == "top_corner") { - r_ret = terrain_peering_bits[TileSet::CELL_NEIGHBOR_TOP_CORNER]; - } else if (components[1] == "top_right_side") { - r_ret = terrain_peering_bits[TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE]; - } else if (components[1] == "top_right_corner") { - r_ret = terrain_peering_bits[TileSet::CELL_NEIGHBOR_TOP_RIGHT_CORNER]; - } else { - return false; + for (int i = 0; i < TileSet::CELL_NEIGHBOR_MAX; i++) { + if (components[1] == TileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[i]) { + r_ret = terrain_peering_bits[i]; + return true; + } } - return true; + return false; } else if (components.size() == 2 && components[0].begins_with("navigation_layer_") && components[0].trim_prefix("navigation_layer_").is_valid_int()) { // Occlusion layers. int layer_index = components[0].trim_prefix("navigation_layer_").to_int(); @@ -2795,26 +3645,26 @@ void TileData::_get_property_list(List<PropertyInfo> *p_list) const { // Physics layers. p_list->push_back(PropertyInfo(Variant::NIL, "Physics", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_GROUP)); for (int i = 0; i < physics.size(); i++) { - p_list->push_back(PropertyInfo(Variant::INT, vformat("physics_layer_%d/shapes_count", i), PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR)); + p_list->push_back(PropertyInfo(Variant::INT, vformat("physics_layer_%d/polygons_count", i), PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR)); - for (int j = 0; j < physics[i].shapes.size(); j++) { - // physics_layer_%d/shapes_count - property_info = PropertyInfo(Variant::OBJECT, vformat("physics_layer_%d/shape_%d/shape", i, j), PROPERTY_HINT_RESOURCE_TYPE, "Shape2D", PROPERTY_USAGE_DEFAULT); - if (!physics[i].shapes[j].shape.is_valid()) { + for (int j = 0; j < physics[i].polygons.size(); j++) { + // physics_layer_%d/points + property_info = PropertyInfo(Variant::ARRAY, vformat("physics_layer_%d/polygon_%d/points", i, j), PROPERTY_HINT_ARRAY_TYPE, "Vector2", PROPERTY_USAGE_DEFAULT); + if (physics[i].polygons[j].polygon.is_empty()) { property_info.usage ^= PROPERTY_USAGE_STORAGE; } p_list->push_back(property_info); - // physics_layer_%d/shape_%d/one_way - property_info = PropertyInfo(Variant::BOOL, vformat("physics_layer_%d/shape_%d/one_way", i, j)); - if (physics[i].shapes[j].one_way == false) { + // physics_layer_%d/polygon_%d/one_way + property_info = PropertyInfo(Variant::BOOL, vformat("physics_layer_%d/polygon_%d/one_way", i, j)); + if (physics[i].polygons[j].one_way == false) { property_info.usage ^= PROPERTY_USAGE_STORAGE; } p_list->push_back(property_info); - // physics_layer_%d/shape_%d/one_way_margin - property_info = PropertyInfo(Variant::FLOAT, vformat("physics_layer_%d/shape_%d/one_way_margin", i, j)); - if (physics[i].shapes[j].one_way_margin == 1.0) { + // physics_layer_%d/polygon_%d/one_way_margin + property_info = PropertyInfo(Variant::FLOAT, vformat("physics_layer_%d/polygon_%d/one_way_margin", i, j)); + if (physics[i].polygons[j].one_way_margin == 1.0) { property_info.usage ^= PROPERTY_USAGE_STORAGE; } p_list->push_back(property_info); @@ -2824,117 +3674,15 @@ void TileData::_get_property_list(List<PropertyInfo> *p_list) const { // Terrain data if (terrain_set >= 0) { p_list->push_back(PropertyInfo(Variant::NIL, "Terrains", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_GROUP)); - if (is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_RIGHT_SIDE)) { - property_info = PropertyInfo(Variant::INT, "terrains_peering_bit/right_side"); - if (get_peering_bit_terrain(TileSet::CELL_NEIGHBOR_RIGHT_SIDE) == -1) { - property_info.usage ^= PROPERTY_USAGE_STORAGE; - } - p_list->push_back(property_info); - } - if (is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_RIGHT_CORNER)) { - property_info = PropertyInfo(Variant::INT, "terrains_peering_bit/right_corner"); - if (get_peering_bit_terrain(TileSet::CELL_NEIGHBOR_RIGHT_CORNER) == -1) { - property_info.usage ^= PROPERTY_USAGE_STORAGE; - } - p_list->push_back(property_info); - } - if (is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE)) { - property_info = PropertyInfo(Variant::INT, "terrains_peering_bit/bottom_right_side"); - if (get_peering_bit_terrain(TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE) == -1) { - property_info.usage ^= PROPERTY_USAGE_STORAGE; - } - p_list->push_back(property_info); - } - if (is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER)) { - property_info = PropertyInfo(Variant::INT, "terrains_peering_bit/bottom_right_corner"); - if (get_peering_bit_terrain(TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER) == -1) { - property_info.usage ^= PROPERTY_USAGE_STORAGE; - } - p_list->push_back(property_info); - } - if (is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_BOTTOM_SIDE)) { - property_info = PropertyInfo(Variant::INT, "terrains_peering_bit/bottom_side"); - if (get_peering_bit_terrain(TileSet::CELL_NEIGHBOR_BOTTOM_SIDE) == -1) { - property_info.usage ^= PROPERTY_USAGE_STORAGE; - } - p_list->push_back(property_info); - } - if (is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_BOTTOM_CORNER)) { - property_info = PropertyInfo(Variant::INT, "terrains_peering_bit/bottom_corner"); - if (get_peering_bit_terrain(TileSet::CELL_NEIGHBOR_BOTTOM_CORNER) == -1) { - property_info.usage ^= PROPERTY_USAGE_STORAGE; - } - p_list->push_back(property_info); - } - if (is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE)) { - property_info = PropertyInfo(Variant::INT, "terrains_peering_bit/bottom_left_side"); - if (get_peering_bit_terrain(TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE) == -1) { - property_info.usage ^= PROPERTY_USAGE_STORAGE; - } - p_list->push_back(property_info); - } - if (is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_CORNER)) { - property_info = PropertyInfo(Variant::INT, "terrains_peering_bit/bottom_left_corner"); - if (get_peering_bit_terrain(TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_CORNER) == -1) { - property_info.usage ^= PROPERTY_USAGE_STORAGE; - } - p_list->push_back(property_info); - } - if (is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_LEFT_SIDE)) { - property_info = PropertyInfo(Variant::INT, "terrains_peering_bit/left_side"); - if (get_peering_bit_terrain(TileSet::CELL_NEIGHBOR_LEFT_SIDE) == -1) { - property_info.usage ^= PROPERTY_USAGE_STORAGE; - } - p_list->push_back(property_info); - } - if (is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_LEFT_CORNER)) { - property_info = PropertyInfo(Variant::INT, "terrains_peering_bit/left_corner"); - if (get_peering_bit_terrain(TileSet::CELL_NEIGHBOR_LEFT_CORNER) == -1) { - property_info.usage ^= PROPERTY_USAGE_STORAGE; - } - p_list->push_back(property_info); - } - if (is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE)) { - property_info = PropertyInfo(Variant::INT, "terrains_peering_bit/top_left_side"); - if (get_peering_bit_terrain(TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE) == -1) { - property_info.usage ^= PROPERTY_USAGE_STORAGE; - } - p_list->push_back(property_info); - } - if (is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_TOP_LEFT_CORNER)) { - property_info = PropertyInfo(Variant::INT, "terrains_peering_bit/top_left_corner"); - if (get_peering_bit_terrain(TileSet::CELL_NEIGHBOR_TOP_LEFT_CORNER) == -1) { - property_info.usage ^= PROPERTY_USAGE_STORAGE; - } - p_list->push_back(property_info); - } - if (is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_TOP_SIDE)) { - property_info = PropertyInfo(Variant::INT, "terrains_peering_bit/top_side"); - if (get_peering_bit_terrain(TileSet::CELL_NEIGHBOR_TOP_SIDE) == -1) { - property_info.usage ^= PROPERTY_USAGE_STORAGE; - } - p_list->push_back(property_info); - } - if (is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_TOP_CORNER)) { - property_info = PropertyInfo(Variant::INT, "terrains_peering_bit/top_corner"); - if (get_peering_bit_terrain(TileSet::CELL_NEIGHBOR_TOP_CORNER) == -1) { - property_info.usage ^= PROPERTY_USAGE_STORAGE; - } - p_list->push_back(property_info); - } - if (is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE)) { - property_info = PropertyInfo(Variant::INT, "terrains_peering_bit/top_right_side"); - if (get_peering_bit_terrain(TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE) == -1) { - property_info.usage ^= PROPERTY_USAGE_STORAGE; - } - p_list->push_back(property_info); - } - if (is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_TOP_RIGHT_CORNER)) { - property_info = PropertyInfo(Variant::INT, "terrains_peering_bit/top_right_corner"); - if (get_peering_bit_terrain(TileSet::CELL_NEIGHBOR_TOP_RIGHT_CORNER) == -1) { - property_info.usage ^= PROPERTY_USAGE_STORAGE; + for (int i = 0; i < TileSet::CELL_NEIGHBOR_MAX; i++) { + TileSet::CellNeighbor bit = TileSet::CellNeighbor(i); + if (is_valid_peering_bit_terrain(bit)) { + property_info = PropertyInfo(Variant::INT, "terrains_peering_bit/" + String(TileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[i])); + if (get_peering_bit_terrain(bit) == -1) { + property_info.usage ^= PROPERTY_USAGE_STORAGE; + } + p_list->push_back(property_info); } - p_list->push_back(property_info); } } @@ -2986,16 +3734,16 @@ void TileData::_bind_methods() { ClassDB::bind_method(D_METHOD("get_occluder", "layer_id"), &TileData::get_occluder); // Physics. - ClassDB::bind_method(D_METHOD("get_collision_shapes_count", "layer_id"), &TileData::get_collision_shapes_count); - ClassDB::bind_method(D_METHOD("set_collision_shapes_count", "layer_id", "shapes_count"), &TileData::set_collision_shapes_count); - ClassDB::bind_method(D_METHOD("add_collision_shape", "layer_id"), &TileData::add_collision_shape); - ClassDB::bind_method(D_METHOD("remove_collision_shape", "layer_id", "shape_index"), &TileData::remove_collision_shape); - ClassDB::bind_method(D_METHOD("set_collision_shape_shape", "layer_id", "shape_index", "shape"), &TileData::set_collision_shape_shape); - ClassDB::bind_method(D_METHOD("get_collision_shape_shape", "layer_id", "shape_index"), &TileData::get_collision_shape_shape); - ClassDB::bind_method(D_METHOD("set_collision_shape_one_way", "layer_id", "shape_index", "one_way"), &TileData::set_collision_shape_one_way); - ClassDB::bind_method(D_METHOD("is_collision_shape_one_way", "layer_id", "shape_index"), &TileData::is_collision_shape_one_way); - ClassDB::bind_method(D_METHOD("set_collision_shape_one_way_margin", "layer_id", "shape_index", "one_way_margin"), &TileData::set_collision_shape_one_way_margin); - ClassDB::bind_method(D_METHOD("get_collision_shape_one_way_margin", "layer_id", "shape_index"), &TileData::get_collision_shape_one_way_margin); + ClassDB::bind_method(D_METHOD("get_collision_polygons_count", "layer_id"), &TileData::get_collision_polygons_count); + ClassDB::bind_method(D_METHOD("set_collision_polygons_count", "layer_id", "polygons_count"), &TileData::set_collision_polygons_count); + ClassDB::bind_method(D_METHOD("add_collision_polygon", "layer_id"), &TileData::add_collision_polygon); + ClassDB::bind_method(D_METHOD("remove_collision_polygon", "layer_id", "polygon_index"), &TileData::remove_collision_polygon); + ClassDB::bind_method(D_METHOD("set_collision_polygon_points", "layer_id", "polygon_index", "polygon"), &TileData::set_collision_polygon_points); + ClassDB::bind_method(D_METHOD("get_collision_polygon_points", "layer_id", "polygon_index"), &TileData::get_collision_polygon_points); + ClassDB::bind_method(D_METHOD("set_collision_polygon_one_way", "layer_id", "polygon_index", "one_way"), &TileData::set_collision_polygon_one_way); + ClassDB::bind_method(D_METHOD("is_collision_polygon_one_way", "layer_id", "polygon_index"), &TileData::is_collision_polygon_one_way); + ClassDB::bind_method(D_METHOD("set_collision_polygon_one_way_margin", "layer_id", "polygon_index", "one_way_margin"), &TileData::set_collision_polygon_one_way_margin); + ClassDB::bind_method(D_METHOD("get_collision_polygon_one_way_margin", "layer_id", "polygon_index"), &TileData::get_collision_polygon_one_way_margin); // Terrain ClassDB::bind_method(D_METHOD("set_terrain_set", "terrain_set"), &TileData::set_terrain_set); @@ -3034,805 +3782,6 @@ void TileData::_bind_methods() { ADD_SIGNAL(MethodInfo("changed")); } - -/////////////////////////////// TileSetPluginAtlasTerrain ////////////////////////////////////// - -// --- PLUGINS --- -void TileSetPluginAtlasTerrain::_draw_square_corner_or_side_terrain_bit(CanvasItem *p_canvas_item, Color p_color, Vector2i p_size, TileSet::CellNeighbor p_bit) { - Rect2 bit_rect; - bit_rect.size = Vector2(p_size) / 3; - switch (p_bit) { - case TileSet::CELL_NEIGHBOR_RIGHT_SIDE: - bit_rect.position = Vector2(1, -1); - break; - case TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER: - bit_rect.position = Vector2(1, 1); - break; - case TileSet::CELL_NEIGHBOR_BOTTOM_SIDE: - bit_rect.position = Vector2(-1, 1); - break; - case TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_CORNER: - bit_rect.position = Vector2(-3, 1); - break; - case TileSet::CELL_NEIGHBOR_LEFT_SIDE: - bit_rect.position = Vector2(-3, -1); - break; - case TileSet::CELL_NEIGHBOR_TOP_LEFT_CORNER: - bit_rect.position = Vector2(-3, -3); - break; - case TileSet::CELL_NEIGHBOR_TOP_SIDE: - bit_rect.position = Vector2(-1, -3); - break; - case TileSet::CELL_NEIGHBOR_TOP_RIGHT_CORNER: - bit_rect.position = Vector2(1, -3); - break; - default: - break; - } - bit_rect.position *= Vector2(p_size) / 6.0; - p_canvas_item->draw_rect(bit_rect, p_color); -} - -void TileSetPluginAtlasTerrain::_draw_square_corner_terrain_bit(CanvasItem *p_canvas_item, Color p_color, Vector2i p_size, TileSet::CellNeighbor p_bit) { - PackedColorArray color_array; - color_array.push_back(p_color); - - Vector2 unit = Vector2(p_size) / 6.0; - PackedVector2Array polygon; - switch (p_bit) { - case TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER: - polygon.push_back(Vector2(0, 3) * unit); - polygon.push_back(Vector2(3, 3) * unit); - polygon.push_back(Vector2(3, 0) * unit); - polygon.push_back(Vector2(1, 0) * unit); - polygon.push_back(Vector2(1, 1) * unit); - polygon.push_back(Vector2(0, 1) * unit); - break; - case TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_CORNER: - polygon.push_back(Vector2(0, 3) * unit); - polygon.push_back(Vector2(-3, 3) * unit); - polygon.push_back(Vector2(-3, 0) * unit); - polygon.push_back(Vector2(-1, 0) * unit); - polygon.push_back(Vector2(-1, 1) * unit); - polygon.push_back(Vector2(0, 1) * unit); - break; - case TileSet::CELL_NEIGHBOR_TOP_LEFT_CORNER: - polygon.push_back(Vector2(0, -3) * unit); - polygon.push_back(Vector2(-3, -3) * unit); - polygon.push_back(Vector2(-3, 0) * unit); - polygon.push_back(Vector2(-1, 0) * unit); - polygon.push_back(Vector2(-1, -1) * unit); - polygon.push_back(Vector2(0, -1) * unit); - break; - case TileSet::CELL_NEIGHBOR_TOP_RIGHT_CORNER: - polygon.push_back(Vector2(0, -3) * unit); - polygon.push_back(Vector2(3, -3) * unit); - polygon.push_back(Vector2(3, 0) * unit); - polygon.push_back(Vector2(1, 0) * unit); - polygon.push_back(Vector2(1, -1) * unit); - polygon.push_back(Vector2(0, -1) * unit); - break; - default: - break; - } - if (!polygon.is_empty()) { - p_canvas_item->draw_polygon(polygon, color_array); - } -} - -void TileSetPluginAtlasTerrain::_draw_square_side_terrain_bit(CanvasItem *p_canvas_item, Color p_color, Vector2i p_size, TileSet::CellNeighbor p_bit) { - PackedColorArray color_array; - color_array.push_back(p_color); - - Vector2 unit = Vector2(p_size) / 6.0; - PackedVector2Array polygon; - switch (p_bit) { - case TileSet::CELL_NEIGHBOR_RIGHT_SIDE: - polygon.push_back(Vector2(1, -1) * unit); - polygon.push_back(Vector2(3, -3) * unit); - polygon.push_back(Vector2(3, 3) * unit); - polygon.push_back(Vector2(1, 1) * unit); - break; - case TileSet::CELL_NEIGHBOR_BOTTOM_SIDE: - polygon.push_back(Vector2(-1, 1) * unit); - polygon.push_back(Vector2(-3, 3) * unit); - polygon.push_back(Vector2(3, 3) * unit); - polygon.push_back(Vector2(1, 1) * unit); - break; - case TileSet::CELL_NEIGHBOR_LEFT_SIDE: - polygon.push_back(Vector2(-1, -1) * unit); - polygon.push_back(Vector2(-3, -3) * unit); - polygon.push_back(Vector2(-3, 3) * unit); - polygon.push_back(Vector2(-1, 1) * unit); - break; - case TileSet::CELL_NEIGHBOR_TOP_SIDE: - polygon.push_back(Vector2(-1, -1) * unit); - polygon.push_back(Vector2(-3, -3) * unit); - polygon.push_back(Vector2(3, -3) * unit); - polygon.push_back(Vector2(1, -1) * unit); - break; - default: - break; - } - if (!polygon.is_empty()) { - p_canvas_item->draw_polygon(polygon, color_array); - } -} - -void TileSetPluginAtlasTerrain::_draw_isometric_corner_or_side_terrain_bit(CanvasItem *p_canvas_item, Color p_color, Vector2i p_size, TileSet::CellNeighbor p_bit) { - PackedColorArray color_array; - color_array.push_back(p_color); - - Vector2 unit = Vector2(p_size) / 6.0; - PackedVector2Array polygon; - switch (p_bit) { - case TileSet::CELL_NEIGHBOR_RIGHT_CORNER: - polygon.push_back(Vector2(1, 0) * unit); - polygon.push_back(Vector2(2, -1) * unit); - polygon.push_back(Vector2(3, 0) * unit); - polygon.push_back(Vector2(2, 1) * unit); - break; - case TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE: - polygon.push_back(Vector2(0, 1) * unit); - polygon.push_back(Vector2(1, 2) * unit); - polygon.push_back(Vector2(2, 1) * unit); - polygon.push_back(Vector2(1, 0) * unit); - break; - case TileSet::CELL_NEIGHBOR_BOTTOM_CORNER: - polygon.push_back(Vector2(0, 1) * unit); - polygon.push_back(Vector2(-1, 2) * unit); - polygon.push_back(Vector2(0, 3) * unit); - polygon.push_back(Vector2(1, 2) * unit); - break; - case TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE: - polygon.push_back(Vector2(0, 1) * unit); - polygon.push_back(Vector2(-1, 2) * unit); - polygon.push_back(Vector2(-2, 1) * unit); - polygon.push_back(Vector2(-1, 0) * unit); - break; - case TileSet::CELL_NEIGHBOR_LEFT_CORNER: - polygon.push_back(Vector2(-1, 0) * unit); - polygon.push_back(Vector2(-2, -1) * unit); - polygon.push_back(Vector2(-3, 0) * unit); - polygon.push_back(Vector2(-2, 1) * unit); - break; - case TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE: - polygon.push_back(Vector2(0, -1) * unit); - polygon.push_back(Vector2(-1, -2) * unit); - polygon.push_back(Vector2(-2, -1) * unit); - polygon.push_back(Vector2(-1, 0) * unit); - break; - case TileSet::CELL_NEIGHBOR_TOP_CORNER: - polygon.push_back(Vector2(0, -1) * unit); - polygon.push_back(Vector2(-1, -2) * unit); - polygon.push_back(Vector2(0, -3) * unit); - polygon.push_back(Vector2(1, -2) * unit); - break; - case TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE: - polygon.push_back(Vector2(0, -1) * unit); - polygon.push_back(Vector2(1, -2) * unit); - polygon.push_back(Vector2(2, -1) * unit); - polygon.push_back(Vector2(1, 0) * unit); - break; - default: - break; - } - if (!polygon.is_empty()) { - p_canvas_item->draw_polygon(polygon, color_array); - } -} - -void TileSetPluginAtlasTerrain::_draw_isometric_corner_terrain_bit(CanvasItem *p_canvas_item, Color p_color, Vector2i p_size, TileSet::CellNeighbor p_bit) { - PackedColorArray color_array; - color_array.push_back(p_color); - - Vector2 unit = Vector2(p_size) / 6.0; - PackedVector2Array polygon; - switch (p_bit) { - case TileSet::CELL_NEIGHBOR_RIGHT_CORNER: - polygon.push_back(Vector2(0.5, -0.5) * unit); - polygon.push_back(Vector2(1.5, -1.5) * unit); - polygon.push_back(Vector2(3, 0) * unit); - polygon.push_back(Vector2(1.5, 1.5) * unit); - polygon.push_back(Vector2(0.5, 0.5) * unit); - polygon.push_back(Vector2(1, 0) * unit); - break; - case TileSet::CELL_NEIGHBOR_BOTTOM_CORNER: - polygon.push_back(Vector2(-0.5, 0.5) * unit); - polygon.push_back(Vector2(-1.5, 1.5) * unit); - polygon.push_back(Vector2(0, 3) * unit); - polygon.push_back(Vector2(1.5, 1.5) * unit); - polygon.push_back(Vector2(0.5, 0.5) * unit); - polygon.push_back(Vector2(0, 1) * unit); - break; - case TileSet::CELL_NEIGHBOR_LEFT_CORNER: - polygon.push_back(Vector2(-0.5, -0.5) * unit); - polygon.push_back(Vector2(-1.5, -1.5) * unit); - polygon.push_back(Vector2(-3, 0) * unit); - polygon.push_back(Vector2(-1.5, 1.5) * unit); - polygon.push_back(Vector2(-0.5, 0.5) * unit); - polygon.push_back(Vector2(-1, 0) * unit); - break; - case TileSet::CELL_NEIGHBOR_TOP_CORNER: - polygon.push_back(Vector2(-0.5, -0.5) * unit); - polygon.push_back(Vector2(-1.5, -1.5) * unit); - polygon.push_back(Vector2(0, -3) * unit); - polygon.push_back(Vector2(1.5, -1.5) * unit); - polygon.push_back(Vector2(0.5, -0.5) * unit); - polygon.push_back(Vector2(0, -1) * unit); - break; - default: - break; - } - if (!polygon.is_empty()) { - p_canvas_item->draw_polygon(polygon, color_array); - } -} - -void TileSetPluginAtlasTerrain::_draw_isometric_side_terrain_bit(CanvasItem *p_canvas_item, Color p_color, Vector2i p_size, TileSet::CellNeighbor p_bit) { - PackedColorArray color_array; - color_array.push_back(p_color); - - Vector2 unit = Vector2(p_size) / 6.0; - PackedVector2Array polygon; - switch (p_bit) { - case TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE: - polygon.push_back(Vector2(1, 0) * unit); - polygon.push_back(Vector2(3, 0) * unit); - polygon.push_back(Vector2(0, 3) * unit); - polygon.push_back(Vector2(0, 1) * unit); - break; - case TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE: - polygon.push_back(Vector2(-1, 0) * unit); - polygon.push_back(Vector2(-3, 0) * unit); - polygon.push_back(Vector2(0, 3) * unit); - polygon.push_back(Vector2(0, 1) * unit); - break; - case TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE: - polygon.push_back(Vector2(-1, 0) * unit); - polygon.push_back(Vector2(-3, 0) * unit); - polygon.push_back(Vector2(0, -3) * unit); - polygon.push_back(Vector2(0, -1) * unit); - break; - case TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE: - polygon.push_back(Vector2(1, 0) * unit); - polygon.push_back(Vector2(3, 0) * unit); - polygon.push_back(Vector2(0, -3) * unit); - polygon.push_back(Vector2(0, -1) * unit); - break; - default: - break; - } - if (!polygon.is_empty()) { - p_canvas_item->draw_polygon(polygon, color_array); - } -} - -void TileSetPluginAtlasTerrain::_draw_half_offset_corner_or_side_terrain_bit(CanvasItem *p_canvas_item, Color p_color, Vector2i p_size, TileSet::CellNeighbor p_bit, float p_overlap, TileSet::TileOffsetAxis p_offset_axis) { - PackedColorArray color_array; - color_array.push_back(p_color); - - PackedVector2Array point_list; - point_list.push_back(Vector2(3, (3.0 * (1.0 - p_overlap * 2.0)) / 2.0)); - point_list.push_back(Vector2(3, 3.0 * (1.0 - p_overlap * 2.0))); - point_list.push_back(Vector2(2, 3.0 * (1.0 - (p_overlap * 2.0) * 2.0 / 3.0))); - point_list.push_back(Vector2(1, 3.0 - p_overlap * 2.0)); - point_list.push_back(Vector2(0, 3)); - point_list.push_back(Vector2(-1, 3.0 - p_overlap * 2.0)); - point_list.push_back(Vector2(-2, 3.0 * (1.0 - (p_overlap * 2.0) * 2.0 / 3.0))); - point_list.push_back(Vector2(-3, 3.0 * (1.0 - p_overlap * 2.0))); - point_list.push_back(Vector2(-3, (3.0 * (1.0 - p_overlap * 2.0)) / 2.0)); - point_list.push_back(Vector2(-3, -(3.0 * (1.0 - p_overlap * 2.0)) / 2.0)); - point_list.push_back(Vector2(-3, -3.0 * (1.0 - p_overlap * 2.0))); - point_list.push_back(Vector2(-2, -3.0 * (1.0 - (p_overlap * 2.0) * 2.0 / 3.0))); - point_list.push_back(Vector2(-1, -(3.0 - p_overlap * 2.0))); - point_list.push_back(Vector2(0, -3)); - point_list.push_back(Vector2(1, -(3.0 - p_overlap * 2.0))); - point_list.push_back(Vector2(2, -3.0 * (1.0 - (p_overlap * 2.0) * 2.0 / 3.0))); - point_list.push_back(Vector2(3, -3.0 * (1.0 - p_overlap * 2.0))); - point_list.push_back(Vector2(3, -(3.0 * (1.0 - p_overlap * 2.0)) / 2.0)); - - Vector2 unit = Vector2(p_size) / 6.0; - for (int i = 0; i < point_list.size(); i++) { - point_list.write[i] = point_list[i] * unit; - } - - PackedVector2Array polygon; - if (p_offset_axis == TileSet::TILE_OFFSET_AXIS_HORIZONTAL) { - switch (p_bit) { - case TileSet::CELL_NEIGHBOR_RIGHT_SIDE: - polygon.push_back(point_list[17]); - polygon.push_back(point_list[0]); - break; - case TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER: - polygon.push_back(point_list[0]); - polygon.push_back(point_list[1]); - polygon.push_back(point_list[2]); - break; - case TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE: - polygon.push_back(point_list[2]); - polygon.push_back(point_list[3]); - break; - case TileSet::CELL_NEIGHBOR_BOTTOM_CORNER: - polygon.push_back(point_list[3]); - polygon.push_back(point_list[4]); - polygon.push_back(point_list[5]); - break; - case TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE: - polygon.push_back(point_list[5]); - polygon.push_back(point_list[6]); - break; - case TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_CORNER: - polygon.push_back(point_list[6]); - polygon.push_back(point_list[7]); - polygon.push_back(point_list[8]); - break; - case TileSet::CELL_NEIGHBOR_LEFT_SIDE: - polygon.push_back(point_list[8]); - polygon.push_back(point_list[9]); - break; - case TileSet::CELL_NEIGHBOR_TOP_LEFT_CORNER: - polygon.push_back(point_list[9]); - polygon.push_back(point_list[10]); - polygon.push_back(point_list[11]); - break; - case TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE: - polygon.push_back(point_list[11]); - polygon.push_back(point_list[12]); - break; - case TileSet::CELL_NEIGHBOR_TOP_CORNER: - polygon.push_back(point_list[12]); - polygon.push_back(point_list[13]); - polygon.push_back(point_list[14]); - break; - case TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE: - polygon.push_back(point_list[14]); - polygon.push_back(point_list[15]); - break; - case TileSet::CELL_NEIGHBOR_TOP_RIGHT_CORNER: - polygon.push_back(point_list[15]); - polygon.push_back(point_list[16]); - polygon.push_back(point_list[17]); - break; - default: - break; - } - } else { - if (p_offset_axis == TileSet::TILE_OFFSET_AXIS_VERTICAL) { - for (int i = 0; i < point_list.size(); i++) { - point_list.write[i] = Vector2(point_list[i].y, point_list[i].x); - } - } - switch (p_bit) { - case TileSet::CELL_NEIGHBOR_RIGHT_CORNER: - polygon.push_back(point_list[3]); - polygon.push_back(point_list[4]); - polygon.push_back(point_list[5]); - break; - case TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE: - polygon.push_back(point_list[2]); - polygon.push_back(point_list[3]); - break; - case TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER: - polygon.push_back(point_list[0]); - polygon.push_back(point_list[1]); - polygon.push_back(point_list[2]); - break; - case TileSet::CELL_NEIGHBOR_BOTTOM_SIDE: - polygon.push_back(point_list[17]); - polygon.push_back(point_list[0]); - break; - case TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_CORNER: - polygon.push_back(point_list[15]); - polygon.push_back(point_list[16]); - polygon.push_back(point_list[17]); - break; - case TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE: - polygon.push_back(point_list[14]); - polygon.push_back(point_list[15]); - break; - case TileSet::CELL_NEIGHBOR_LEFT_CORNER: - polygon.push_back(point_list[12]); - polygon.push_back(point_list[13]); - polygon.push_back(point_list[14]); - break; - case TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE: - polygon.push_back(point_list[11]); - polygon.push_back(point_list[12]); - break; - case TileSet::CELL_NEIGHBOR_TOP_LEFT_CORNER: - polygon.push_back(point_list[9]); - polygon.push_back(point_list[10]); - polygon.push_back(point_list[11]); - break; - case TileSet::CELL_NEIGHBOR_TOP_SIDE: - polygon.push_back(point_list[8]); - polygon.push_back(point_list[9]); - break; - case TileSet::CELL_NEIGHBOR_TOP_RIGHT_CORNER: - polygon.push_back(point_list[6]); - polygon.push_back(point_list[7]); - polygon.push_back(point_list[8]); - break; - case TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE: - polygon.push_back(point_list[5]); - polygon.push_back(point_list[6]); - break; - default: - break; - } - } - - int half_polygon_size = polygon.size(); - for (int i = 0; i < half_polygon_size; i++) { - polygon.push_back(polygon[half_polygon_size - 1 - i] / 3.0); - } - - if (!polygon.is_empty()) { - p_canvas_item->draw_polygon(polygon, color_array); - } -} - -void TileSetPluginAtlasTerrain::_draw_half_offset_corner_terrain_bit(CanvasItem *p_canvas_item, Color p_color, Vector2i p_size, TileSet::CellNeighbor p_bit, float p_overlap, TileSet::TileOffsetAxis p_offset_axis) { - PackedColorArray color_array; - color_array.push_back(p_color); - - PackedVector2Array point_list; - point_list.push_back(Vector2(3, 0)); - point_list.push_back(Vector2(3, 3.0 * (1.0 - p_overlap * 2.0))); - point_list.push_back(Vector2(1.5, (3.0 * (1.0 - p_overlap * 2.0) + 3.0) / 2.0)); - point_list.push_back(Vector2(0, 3)); - point_list.push_back(Vector2(-1.5, (3.0 * (1.0 - p_overlap * 2.0) + 3.0) / 2.0)); - point_list.push_back(Vector2(-3, 3.0 * (1.0 - p_overlap * 2.0))); - point_list.push_back(Vector2(-3, 0)); - point_list.push_back(Vector2(-3, -3.0 * (1.0 - p_overlap * 2.0))); - point_list.push_back(Vector2(-1.5, -(3.0 * (1.0 - p_overlap * 2.0) + 3.0) / 2.0)); - point_list.push_back(Vector2(0, -3)); - point_list.push_back(Vector2(1.5, -(3.0 * (1.0 - p_overlap * 2.0) + 3.0) / 2.0)); - point_list.push_back(Vector2(3, -3.0 * (1.0 - p_overlap * 2.0))); - - Vector2 unit = Vector2(p_size) / 6.0; - for (int i = 0; i < point_list.size(); i++) { - point_list.write[i] = point_list[i] * unit; - } - - PackedVector2Array polygon; - if (p_offset_axis == TileSet::TILE_OFFSET_AXIS_HORIZONTAL) { - switch (p_bit) { - case TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER: - polygon.push_back(point_list[0]); - polygon.push_back(point_list[1]); - polygon.push_back(point_list[2]); - break; - case TileSet::CELL_NEIGHBOR_BOTTOM_CORNER: - polygon.push_back(point_list[2]); - polygon.push_back(point_list[3]); - polygon.push_back(point_list[4]); - break; - case TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_CORNER: - polygon.push_back(point_list[4]); - polygon.push_back(point_list[5]); - polygon.push_back(point_list[6]); - break; - case TileSet::CELL_NEIGHBOR_TOP_LEFT_CORNER: - polygon.push_back(point_list[6]); - polygon.push_back(point_list[7]); - polygon.push_back(point_list[8]); - break; - case TileSet::CELL_NEIGHBOR_TOP_CORNER: - polygon.push_back(point_list[8]); - polygon.push_back(point_list[9]); - polygon.push_back(point_list[10]); - break; - case TileSet::CELL_NEIGHBOR_TOP_RIGHT_CORNER: - polygon.push_back(point_list[10]); - polygon.push_back(point_list[11]); - polygon.push_back(point_list[0]); - break; - default: - break; - } - } else { - if (p_offset_axis == TileSet::TILE_OFFSET_AXIS_VERTICAL) { - for (int i = 0; i < point_list.size(); i++) { - point_list.write[i] = Vector2(point_list[i].y, point_list[i].x); - } - } - switch (p_bit) { - case TileSet::CELL_NEIGHBOR_RIGHT_CORNER: - polygon.push_back(point_list[2]); - polygon.push_back(point_list[3]); - polygon.push_back(point_list[4]); - break; - case TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER: - polygon.push_back(point_list[0]); - polygon.push_back(point_list[1]); - polygon.push_back(point_list[2]); - break; - case TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_CORNER: - polygon.push_back(point_list[10]); - polygon.push_back(point_list[11]); - polygon.push_back(point_list[0]); - break; - case TileSet::CELL_NEIGHBOR_LEFT_CORNER: - polygon.push_back(point_list[8]); - polygon.push_back(point_list[9]); - polygon.push_back(point_list[10]); - break; - case TileSet::CELL_NEIGHBOR_TOP_LEFT_CORNER: - polygon.push_back(point_list[6]); - polygon.push_back(point_list[7]); - polygon.push_back(point_list[8]); - break; - case TileSet::CELL_NEIGHBOR_TOP_RIGHT_CORNER: - polygon.push_back(point_list[4]); - polygon.push_back(point_list[5]); - polygon.push_back(point_list[6]); - break; - default: - break; - } - } - - int half_polygon_size = polygon.size(); - for (int i = 0; i < half_polygon_size; i++) { - polygon.push_back(polygon[half_polygon_size - 1 - i] / 3.0); - } - - if (!polygon.is_empty()) { - p_canvas_item->draw_polygon(polygon, color_array); - } -} - -void TileSetPluginAtlasTerrain::_draw_half_offset_side_terrain_bit(CanvasItem *p_canvas_item, Color p_color, Vector2i p_size, TileSet::CellNeighbor p_bit, float p_overlap, TileSet::TileOffsetAxis p_offset_axis) { - PackedColorArray color_array; - color_array.push_back(p_color); - - PackedVector2Array point_list; - point_list.push_back(Vector2(3, 3.0 * (1.0 - p_overlap * 2.0))); - point_list.push_back(Vector2(0, 3)); - point_list.push_back(Vector2(-3, 3.0 * (1.0 - p_overlap * 2.0))); - point_list.push_back(Vector2(-3, -3.0 * (1.0 - p_overlap * 2.0))); - point_list.push_back(Vector2(0, -3)); - point_list.push_back(Vector2(3, -3.0 * (1.0 - p_overlap * 2.0))); - - Vector2 unit = Vector2(p_size) / 6.0; - for (int i = 0; i < point_list.size(); i++) { - point_list.write[i] = point_list[i] * unit; - } - - PackedVector2Array polygon; - if (p_offset_axis == TileSet::TILE_OFFSET_AXIS_HORIZONTAL) { - switch (p_bit) { - case TileSet::CELL_NEIGHBOR_RIGHT_SIDE: - polygon.push_back(point_list[5]); - polygon.push_back(point_list[0]); - break; - case TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE: - polygon.push_back(point_list[0]); - polygon.push_back(point_list[1]); - break; - case TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE: - polygon.push_back(point_list[1]); - polygon.push_back(point_list[2]); - break; - case TileSet::CELL_NEIGHBOR_LEFT_SIDE: - polygon.push_back(point_list[2]); - polygon.push_back(point_list[3]); - break; - case TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE: - polygon.push_back(point_list[3]); - polygon.push_back(point_list[4]); - break; - case TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE: - polygon.push_back(point_list[4]); - polygon.push_back(point_list[5]); - break; - default: - break; - } - } else { - if (p_offset_axis == TileSet::TILE_OFFSET_AXIS_VERTICAL) { - for (int i = 0; i < point_list.size(); i++) { - point_list.write[i] = Vector2(point_list[i].y, point_list[i].x); - } - } - switch (p_bit) { - case TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE: - polygon.push_back(point_list[0]); - polygon.push_back(point_list[1]); - break; - case TileSet::CELL_NEIGHBOR_BOTTOM_SIDE: - polygon.push_back(point_list[5]); - polygon.push_back(point_list[0]); - break; - case TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE: - polygon.push_back(point_list[4]); - polygon.push_back(point_list[5]); - break; - case TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE: - polygon.push_back(point_list[3]); - polygon.push_back(point_list[4]); - break; - case TileSet::CELL_NEIGHBOR_TOP_SIDE: - polygon.push_back(point_list[2]); - polygon.push_back(point_list[3]); - break; - case TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE: - polygon.push_back(point_list[1]); - polygon.push_back(point_list[2]); - break; - default: - break; - } - } - - int half_polygon_size = polygon.size(); - for (int i = 0; i < half_polygon_size; i++) { - polygon.push_back(polygon[half_polygon_size - 1 - i] / 3.0); - } - - if (!polygon.is_empty()) { - p_canvas_item->draw_polygon(polygon, color_array); - } -} - -#define TERRAIN_ALPHA 0.8 - -#define DRAW_TERRAIN_BIT(f, bit) \ - { \ - int terrain_id = p_tile_data->get_peering_bit_terrain((bit)); \ - if (terrain_id >= 0) { \ - Color color = p_tile_set->get_terrain_color(terrain_set, terrain_id); \ - color.a = TERRAIN_ALPHA; \ - f(p_canvas_item, color, size, (bit)); \ - } \ - } - -#define DRAW_HALF_OFFSET_TERRAIN_BIT(f, bit, overlap, half_offset_axis) \ - { \ - int terrain_id = p_tile_data->get_peering_bit_terrain((bit)); \ - if (terrain_id >= 0) { \ - Color color = p_tile_set->get_terrain_color(terrain_set, terrain_id); \ - color.a = TERRAIN_ALPHA; \ - f(p_canvas_item, color, size, (bit), overlap, half_offset_axis); \ - } \ - } - -void TileSetPluginAtlasTerrain::draw_terrains(CanvasItem *p_canvas_item, Transform2D p_transform, TileSet *p_tile_set, const TileData *p_tile_data) { - ERR_FAIL_COND(!p_tile_set); - ERR_FAIL_COND(!p_tile_data); - - int terrain_set = p_tile_data->get_terrain_set(); - if (terrain_set < 0) { - return; - } - TileSet::TerrainMode terrain_mode = p_tile_set->get_terrain_set_mode(terrain_set); - - TileSet::TileShape shape = p_tile_set->get_tile_shape(); - Vector2i size = p_tile_set->get_tile_size(); - - RenderingServer::get_singleton()->canvas_item_add_set_transform(p_canvas_item->get_canvas_item(), p_transform); - if (shape == TileSet::TILE_SHAPE_SQUARE) { - if (terrain_mode == TileSet::TERRAIN_MODE_MATCH_CORNERS_AND_SIDES) { - DRAW_TERRAIN_BIT(_draw_square_corner_or_side_terrain_bit, TileSet::CELL_NEIGHBOR_RIGHT_SIDE); - DRAW_TERRAIN_BIT(_draw_square_corner_or_side_terrain_bit, TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER); - DRAW_TERRAIN_BIT(_draw_square_corner_or_side_terrain_bit, TileSet::CELL_NEIGHBOR_BOTTOM_SIDE); - DRAW_TERRAIN_BIT(_draw_square_corner_or_side_terrain_bit, TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_CORNER); - DRAW_TERRAIN_BIT(_draw_square_corner_or_side_terrain_bit, TileSet::CELL_NEIGHBOR_LEFT_SIDE); - DRAW_TERRAIN_BIT(_draw_square_corner_or_side_terrain_bit, TileSet::CELL_NEIGHBOR_TOP_LEFT_CORNER); - DRAW_TERRAIN_BIT(_draw_square_corner_or_side_terrain_bit, TileSet::CELL_NEIGHBOR_TOP_SIDE); - DRAW_TERRAIN_BIT(_draw_square_corner_or_side_terrain_bit, TileSet::CELL_NEIGHBOR_TOP_RIGHT_CORNER); - } else if (terrain_mode == TileSet::TERRAIN_MODE_MATCH_CORNERS) { - DRAW_TERRAIN_BIT(_draw_square_corner_terrain_bit, TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER); - DRAW_TERRAIN_BIT(_draw_square_corner_terrain_bit, TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_CORNER); - DRAW_TERRAIN_BIT(_draw_square_corner_terrain_bit, TileSet::CELL_NEIGHBOR_TOP_LEFT_CORNER); - DRAW_TERRAIN_BIT(_draw_square_corner_terrain_bit, TileSet::CELL_NEIGHBOR_TOP_RIGHT_CORNER); - } else { // TileData::TERRAIN_MODE_MATCH_SIDES - DRAW_TERRAIN_BIT(_draw_square_side_terrain_bit, TileSet::CELL_NEIGHBOR_RIGHT_SIDE); - DRAW_TERRAIN_BIT(_draw_square_side_terrain_bit, TileSet::CELL_NEIGHBOR_BOTTOM_SIDE); - DRAW_TERRAIN_BIT(_draw_square_side_terrain_bit, TileSet::CELL_NEIGHBOR_LEFT_SIDE); - DRAW_TERRAIN_BIT(_draw_square_side_terrain_bit, TileSet::CELL_NEIGHBOR_TOP_SIDE); - } - } else if (shape == TileSet::TILE_SHAPE_ISOMETRIC) { - if (terrain_mode == TileSet::TERRAIN_MODE_MATCH_CORNERS_AND_SIDES) { - DRAW_TERRAIN_BIT(_draw_isometric_corner_or_side_terrain_bit, TileSet::CELL_NEIGHBOR_RIGHT_CORNER); - DRAW_TERRAIN_BIT(_draw_isometric_corner_or_side_terrain_bit, TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE); - DRAW_TERRAIN_BIT(_draw_isometric_corner_or_side_terrain_bit, TileSet::CELL_NEIGHBOR_BOTTOM_CORNER); - DRAW_TERRAIN_BIT(_draw_isometric_corner_or_side_terrain_bit, TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE); - DRAW_TERRAIN_BIT(_draw_isometric_corner_or_side_terrain_bit, TileSet::CELL_NEIGHBOR_LEFT_CORNER); - DRAW_TERRAIN_BIT(_draw_isometric_corner_or_side_terrain_bit, TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE); - DRAW_TERRAIN_BIT(_draw_isometric_corner_or_side_terrain_bit, TileSet::CELL_NEIGHBOR_TOP_CORNER); - DRAW_TERRAIN_BIT(_draw_isometric_corner_or_side_terrain_bit, TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE); - } else if (terrain_mode == TileSet::TERRAIN_MODE_MATCH_CORNERS) { - DRAW_TERRAIN_BIT(_draw_isometric_corner_terrain_bit, TileSet::CELL_NEIGHBOR_RIGHT_CORNER); - DRAW_TERRAIN_BIT(_draw_isometric_corner_terrain_bit, TileSet::CELL_NEIGHBOR_BOTTOM_CORNER); - DRAW_TERRAIN_BIT(_draw_isometric_corner_terrain_bit, TileSet::CELL_NEIGHBOR_LEFT_CORNER); - DRAW_TERRAIN_BIT(_draw_isometric_corner_terrain_bit, TileSet::CELL_NEIGHBOR_TOP_CORNER); - } else { // TileData::TERRAIN_MODE_MATCH_SIDES - DRAW_TERRAIN_BIT(_draw_isometric_side_terrain_bit, TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE); - DRAW_TERRAIN_BIT(_draw_isometric_side_terrain_bit, TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE); - DRAW_TERRAIN_BIT(_draw_isometric_side_terrain_bit, TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE); - DRAW_TERRAIN_BIT(_draw_isometric_side_terrain_bit, TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE); - } - } else { - TileSet::TileOffsetAxis offset_axis = p_tile_set->get_tile_offset_axis(); - float overlap = 0.0; - switch (p_tile_set->get_tile_shape()) { - case TileSet::TILE_SHAPE_HEXAGON: - overlap = 0.25; - break; - case TileSet::TILE_SHAPE_HALF_OFFSET_SQUARE: - overlap = 0.0; - break; - default: - break; - } - if (terrain_mode == TileSet::TERRAIN_MODE_MATCH_CORNERS_AND_SIDES) { - if (offset_axis == TileSet::TILE_OFFSET_AXIS_HORIZONTAL) { - DRAW_HALF_OFFSET_TERRAIN_BIT(_draw_half_offset_corner_or_side_terrain_bit, TileSet::CELL_NEIGHBOR_RIGHT_SIDE, overlap, offset_axis); - DRAW_HALF_OFFSET_TERRAIN_BIT(_draw_half_offset_corner_or_side_terrain_bit, TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER, overlap, offset_axis); - DRAW_HALF_OFFSET_TERRAIN_BIT(_draw_half_offset_corner_or_side_terrain_bit, TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE, overlap, offset_axis); - DRAW_HALF_OFFSET_TERRAIN_BIT(_draw_half_offset_corner_or_side_terrain_bit, TileSet::CELL_NEIGHBOR_BOTTOM_CORNER, overlap, offset_axis); - DRAW_HALF_OFFSET_TERRAIN_BIT(_draw_half_offset_corner_or_side_terrain_bit, TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE, overlap, offset_axis); - DRAW_HALF_OFFSET_TERRAIN_BIT(_draw_half_offset_corner_or_side_terrain_bit, TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_CORNER, overlap, offset_axis); - DRAW_HALF_OFFSET_TERRAIN_BIT(_draw_half_offset_corner_or_side_terrain_bit, TileSet::CELL_NEIGHBOR_LEFT_SIDE, overlap, offset_axis); - DRAW_HALF_OFFSET_TERRAIN_BIT(_draw_half_offset_corner_or_side_terrain_bit, TileSet::CELL_NEIGHBOR_TOP_LEFT_CORNER, overlap, offset_axis); - DRAW_HALF_OFFSET_TERRAIN_BIT(_draw_half_offset_corner_or_side_terrain_bit, TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE, overlap, offset_axis); - DRAW_HALF_OFFSET_TERRAIN_BIT(_draw_half_offset_corner_or_side_terrain_bit, TileSet::CELL_NEIGHBOR_TOP_CORNER, overlap, offset_axis); - DRAW_HALF_OFFSET_TERRAIN_BIT(_draw_half_offset_corner_or_side_terrain_bit, TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE, overlap, offset_axis); - DRAW_HALF_OFFSET_TERRAIN_BIT(_draw_half_offset_corner_or_side_terrain_bit, TileSet::CELL_NEIGHBOR_TOP_RIGHT_CORNER, overlap, offset_axis); - } else { - DRAW_HALF_OFFSET_TERRAIN_BIT(_draw_half_offset_corner_or_side_terrain_bit, TileSet::CELL_NEIGHBOR_RIGHT_CORNER, overlap, offset_axis); - DRAW_HALF_OFFSET_TERRAIN_BIT(_draw_half_offset_corner_or_side_terrain_bit, TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE, overlap, offset_axis); - DRAW_HALF_OFFSET_TERRAIN_BIT(_draw_half_offset_corner_or_side_terrain_bit, TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER, overlap, offset_axis); - DRAW_HALF_OFFSET_TERRAIN_BIT(_draw_half_offset_corner_or_side_terrain_bit, TileSet::CELL_NEIGHBOR_BOTTOM_SIDE, overlap, offset_axis); - DRAW_HALF_OFFSET_TERRAIN_BIT(_draw_half_offset_corner_or_side_terrain_bit, TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_CORNER, overlap, offset_axis); - DRAW_HALF_OFFSET_TERRAIN_BIT(_draw_half_offset_corner_or_side_terrain_bit, TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE, overlap, offset_axis); - DRAW_HALF_OFFSET_TERRAIN_BIT(_draw_half_offset_corner_or_side_terrain_bit, TileSet::CELL_NEIGHBOR_LEFT_CORNER, overlap, offset_axis); - DRAW_HALF_OFFSET_TERRAIN_BIT(_draw_half_offset_corner_or_side_terrain_bit, TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE, overlap, offset_axis); - DRAW_HALF_OFFSET_TERRAIN_BIT(_draw_half_offset_corner_or_side_terrain_bit, TileSet::CELL_NEIGHBOR_TOP_LEFT_CORNER, overlap, offset_axis); - DRAW_HALF_OFFSET_TERRAIN_BIT(_draw_half_offset_corner_or_side_terrain_bit, TileSet::CELL_NEIGHBOR_TOP_SIDE, overlap, offset_axis); - DRAW_HALF_OFFSET_TERRAIN_BIT(_draw_half_offset_corner_or_side_terrain_bit, TileSet::CELL_NEIGHBOR_TOP_RIGHT_CORNER, overlap, offset_axis); - DRAW_HALF_OFFSET_TERRAIN_BIT(_draw_half_offset_corner_or_side_terrain_bit, TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE, overlap, offset_axis); - } - } else if (terrain_mode == TileSet::TERRAIN_MODE_MATCH_CORNERS) { - if (offset_axis == TileSet::TILE_OFFSET_AXIS_HORIZONTAL) { - DRAW_HALF_OFFSET_TERRAIN_BIT(_draw_half_offset_corner_terrain_bit, TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER, overlap, offset_axis); - DRAW_HALF_OFFSET_TERRAIN_BIT(_draw_half_offset_corner_terrain_bit, TileSet::CELL_NEIGHBOR_BOTTOM_CORNER, overlap, offset_axis); - DRAW_HALF_OFFSET_TERRAIN_BIT(_draw_half_offset_corner_terrain_bit, TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_CORNER, overlap, offset_axis); - DRAW_HALF_OFFSET_TERRAIN_BIT(_draw_half_offset_corner_terrain_bit, TileSet::CELL_NEIGHBOR_TOP_LEFT_CORNER, overlap, offset_axis); - DRAW_HALF_OFFSET_TERRAIN_BIT(_draw_half_offset_corner_terrain_bit, TileSet::CELL_NEIGHBOR_TOP_CORNER, overlap, offset_axis); - DRAW_HALF_OFFSET_TERRAIN_BIT(_draw_half_offset_corner_terrain_bit, TileSet::CELL_NEIGHBOR_TOP_RIGHT_CORNER, overlap, offset_axis); - } else { - DRAW_HALF_OFFSET_TERRAIN_BIT(_draw_half_offset_corner_terrain_bit, TileSet::CELL_NEIGHBOR_RIGHT_CORNER, overlap, offset_axis); - DRAW_HALF_OFFSET_TERRAIN_BIT(_draw_half_offset_corner_terrain_bit, TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER, overlap, offset_axis); - DRAW_HALF_OFFSET_TERRAIN_BIT(_draw_half_offset_corner_terrain_bit, TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_CORNER, overlap, offset_axis); - DRAW_HALF_OFFSET_TERRAIN_BIT(_draw_half_offset_corner_terrain_bit, TileSet::CELL_NEIGHBOR_LEFT_CORNER, overlap, offset_axis); - DRAW_HALF_OFFSET_TERRAIN_BIT(_draw_half_offset_corner_terrain_bit, TileSet::CELL_NEIGHBOR_TOP_LEFT_CORNER, overlap, offset_axis); - DRAW_HALF_OFFSET_TERRAIN_BIT(_draw_half_offset_corner_terrain_bit, TileSet::CELL_NEIGHBOR_TOP_RIGHT_CORNER, overlap, offset_axis); - } - } else { // TileData::TERRAIN_MODE_MATCH_SIDES - if (offset_axis == TileSet::TILE_OFFSET_AXIS_HORIZONTAL) { - DRAW_HALF_OFFSET_TERRAIN_BIT(_draw_half_offset_side_terrain_bit, TileSet::CELL_NEIGHBOR_RIGHT_SIDE, overlap, offset_axis); - DRAW_HALF_OFFSET_TERRAIN_BIT(_draw_half_offset_side_terrain_bit, TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE, overlap, offset_axis); - DRAW_HALF_OFFSET_TERRAIN_BIT(_draw_half_offset_side_terrain_bit, TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE, overlap, offset_axis); - DRAW_HALF_OFFSET_TERRAIN_BIT(_draw_half_offset_side_terrain_bit, TileSet::CELL_NEIGHBOR_LEFT_SIDE, overlap, offset_axis); - DRAW_HALF_OFFSET_TERRAIN_BIT(_draw_half_offset_side_terrain_bit, TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE, overlap, offset_axis); - DRAW_HALF_OFFSET_TERRAIN_BIT(_draw_half_offset_side_terrain_bit, TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE, overlap, offset_axis); - } else { - DRAW_HALF_OFFSET_TERRAIN_BIT(_draw_half_offset_side_terrain_bit, TileSet::CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE, overlap, offset_axis); - DRAW_HALF_OFFSET_TERRAIN_BIT(_draw_half_offset_side_terrain_bit, TileSet::CELL_NEIGHBOR_BOTTOM_SIDE, overlap, offset_axis); - DRAW_HALF_OFFSET_TERRAIN_BIT(_draw_half_offset_side_terrain_bit, TileSet::CELL_NEIGHBOR_BOTTOM_LEFT_SIDE, overlap, offset_axis); - DRAW_HALF_OFFSET_TERRAIN_BIT(_draw_half_offset_side_terrain_bit, TileSet::CELL_NEIGHBOR_TOP_LEFT_SIDE, overlap, offset_axis); - DRAW_HALF_OFFSET_TERRAIN_BIT(_draw_half_offset_side_terrain_bit, TileSet::CELL_NEIGHBOR_TOP_SIDE, overlap, offset_axis); - DRAW_HALF_OFFSET_TERRAIN_BIT(_draw_half_offset_side_terrain_bit, TileSet::CELL_NEIGHBOR_TOP_RIGHT_SIDE, overlap, offset_axis); - } - } - } - RenderingServer::get_singleton()->canvas_item_add_set_transform(p_canvas_item->get_canvas_item(), Transform2D()); -} - /////////////////////////////// TileSetPluginAtlasRendering ////////////////////////////////////// void TileSetPluginAtlasRendering::tilemap_notification(TileMap *p_tile_map, int p_what) { @@ -4218,15 +4167,17 @@ void TileSetPluginAtlasPhysics::update_dirty_quadrants(TileMap *p_tile_map, Self for (int body_index = 0; body_index < q.bodies.size(); body_index++) { // Add the shapes again. - for (int shape_index = 0; shape_index < tile_data->get_collision_shapes_count(body_index); shape_index++) { - bool one_way_collision = tile_data->is_collision_shape_one_way(body_index, shape_index); - float one_way_collision_margin = tile_data->get_collision_shape_one_way_margin(body_index, shape_index); - Ref<Shape2D> shape = tile_data->get_collision_shape_shape(body_index, shape_index); - if (shape.is_valid()) { + for (int polygon_index = 0; polygon_index < tile_data->get_collision_polygons_count(body_index); polygon_index++) { + bool one_way_collision = tile_data->is_collision_polygon_one_way(body_index, polygon_index); + float one_way_collision_margin = tile_data->get_collision_polygon_one_way_margin(body_index, polygon_index); + + int shapes_count = tile_data->get_collision_polygon_shapes_count(body_index, polygon_index); + for (int shape_index = 0; shape_index < shapes_count; shape_index++) { Transform2D xform = Transform2D(); xform.set_origin(p_tile_map->map_to_world(E_cell->get()) - quadrant_pos); // Add decomposed convex shapes. + Ref<ConvexPolygonShape2D> shape = tile_data->get_collision_polygon_shape(body_index, polygon_index, shape_index); ps->body_add_shape(q.bodies[body_index], shape->get_rid(), xform); ps->body_set_shape_metadata(q.bodies[body_index], shape_index, E_cell->get()); ps->body_set_shape_as_one_way_collision(q.bodies[body_index], shape_index, one_way_collision, one_way_collision_margin); @@ -4343,11 +4294,13 @@ void TileSetPluginAtlasPhysics::draw_quadrant_debug(TileMap *p_tile_map, TileMap TileData *tile_data = Object::cast_to<TileData>(atlas_source->get_tile_data(c.get_atlas_coords(), c.alternative_tile)); for (int body_index = 0; body_index < p_quadrant->bodies.size(); body_index++) { - for (int shape_index = 0; shape_index < tile_data->get_collision_shapes_count(body_index); shape_index++) { - // Draw the debug shape. - Ref<Shape2D> shape = tile_data->get_collision_shape_shape(body_index, shape_index); - if (shape.is_valid()) { - shape->draw(p_quadrant->debug_canvas_item, debug_collision_color); + for (int polygon_index = 0; polygon_index < tile_data->get_collision_polygons_count(body_index); polygon_index++) { + // Draw the debug polygon. + Vector<Vector2> polygon = tile_data->get_collision_polygon_points(body_index, polygon_index); + if (polygon.size() >= 3) { + Vector<Color> color; + color.push_back(debug_collision_color); + rs->canvas_item_add_polygon(p_quadrant->debug_canvas_item, polygon, color); } } } @@ -4587,7 +4540,7 @@ void TileSetPluginScenesCollections::update_dirty_quadrants(TileMap *p_tile_map, if (scenes_collection_source) { Ref<PackedScene> packed_scene = scenes_collection_source->get_scene_tile_scene(c.alternative_tile); if (packed_scene.is_valid()) { - Node *scene = packed_scene->instance(); + Node *scene = packed_scene->instantiate(); p_tile_map->add_child(scene); Control *scene_as_control = Object::cast_to<Control>(scene); Node2D *scene_as_node2d = Object::cast_to<Node2D>(scene); diff --git a/scene/resources/tile_set.h b/scene/resources/tile_set.h index 6cf4198f30..dbf6dbabe6 100644 --- a/scene/resources/tile_set.h +++ b/scene/resources/tile_set.h @@ -33,19 +33,18 @@ #include "core/io/resource.h" #include "core/object/object.h" +#include "core/templates/local_vector.h" #include "scene/2d/light_occluder_2d.h" #include "scene/2d/navigation_region_2d.h" #include "scene/main/canvas_item.h" +#include "scene/resources/concave_polygon_shape_2d.h" #include "scene/resources/convex_polygon_shape_2d.h" #include "scene/resources/packed_scene.h" #include "scene/resources/physics_material.h" #include "scene/resources/shape_2d.h" #ifndef DISABLE_DEPRECATED -#include "scene/2d/light_occluder_2d.h" -#include "scene/2d/navigation_region_2d.h" #include "scene/resources/shader.h" -#include "scene/resources/shape_2d.h" #include "scene/resources/texture.h" #endif @@ -60,7 +59,6 @@ class TileSetPlugin; class TileSetPluginAtlasRendering; class TileSetPluginAtlasPhysics; class TileSetPluginAtlasNavigation; -class TileSetPluginAtlasTerrain; class TileSet : public Resource { GDCLASS(TileSet, Resource); @@ -138,6 +136,8 @@ public: CELL_NEIGHBOR_MAX, }; + static const char *CELL_NEIGHBOR_ENUM_TO_TEXT[]; + enum TerrainMode { TERRAIN_MODE_MATCH_CORNERS_AND_SIDES = 0, TERRAIN_MODE_MATCH_CORNERS, @@ -194,6 +194,10 @@ private: }; Vector<OcclusionLayer> occlusion_layers; + Ref<ArrayMesh> tile_lines_mesh; + Ref<ArrayMesh> tile_filled_mesh; + bool tile_meshes_dirty = true; + // Physics struct PhysicsLayer { uint32_t collision_layer = 1; @@ -213,6 +217,9 @@ private: }; Vector<TerrainSet> terrain_sets; + Map<TerrainMode, Map<CellNeighbor, Ref<ArrayMesh>>> terrain_bits_meshes; + bool terrain_bits_meshes_dirty = true; + // Navigation struct Navigationlayer { uint32_t layers = 1; @@ -239,6 +246,19 @@ private: void _compute_next_source_id(); void _source_changed(); + // Helpers + Vector<Point2> _get_square_corner_or_side_terrain_bit_polygon(Vector2i p_size, TileSet::CellNeighbor p_bit); + Vector<Point2> _get_square_corner_terrain_bit_polygon(Vector2i p_size, TileSet::CellNeighbor p_bit); + Vector<Point2> _get_square_side_terrain_bit_polygon(Vector2i p_size, TileSet::CellNeighbor p_bit); + + Vector<Point2> _get_isometric_corner_or_side_terrain_bit_polygon(Vector2i p_size, TileSet::CellNeighbor p_bit); + Vector<Point2> _get_isometric_corner_terrain_bit_polygon(Vector2i p_size, TileSet::CellNeighbor p_bit); + Vector<Point2> _get_isometric_side_terrain_bit_polygon(Vector2i p_size, TileSet::CellNeighbor p_bit); + + Vector<Point2> _get_half_offset_corner_or_side_terrain_bit_polygon(Vector2i p_size, TileSet::CellNeighbor p_bit, float p_overlap, TileSet::TileOffsetAxis p_offset_axis); + Vector<Point2> _get_half_offset_corner_terrain_bit_polygon(Vector2i p_size, TileSet::CellNeighbor p_bit, float p_overlap, TileSet::TileOffsetAxis p_offset_axis); + Vector<Point2> _get_half_offset_side_terrain_bit_polygon(Vector2i p_size, TileSet::CellNeighbor p_bit, float p_overlap, TileSet::TileOffsetAxis p_offset_axis); + protected: static void _bind_methods(); @@ -257,8 +277,6 @@ public: TileOffsetAxis get_tile_offset_axis() const; void set_tile_size(Size2i p_size); Size2i get_tile_size() const; - void set_tile_skew(Vector2 p_skew); - Vector2 get_tile_skew() const; // -- Sources management -- int get_next_source_id() const; @@ -305,6 +323,7 @@ public: String get_terrain_name(int p_terrain_set, int p_terrain_index) const; void set_terrain_color(int p_terrain_set, int p_terrain_index, Color p_color); Color get_terrain_color(int p_terrain_set, int p_terrain_index) const; + bool is_valid_peering_bit_for_mode(TileSet::TerrainMode p_terrain_mode, TileSet::CellNeighbor p_peering_bit) const; bool is_valid_peering_bit_terrain(int p_terrain_set, TileSet::CellNeighbor p_peering_bit) const; // Navigation @@ -323,8 +342,14 @@ public: Variant::Type get_custom_data_type(int p_layer_id) const; // Helpers + Vector<Vector2> get_tile_shape_polygon(); void draw_tile_shape(CanvasItem *p_canvas_item, Rect2 p_region, Color p_color, bool p_filled = false, Ref<Texture2D> p_texture = Ref<Texture2D>()); + Vector<Point2> get_terrain_bit_polygon(int p_terrain_set, TileSet::CellNeighbor p_bit); + void draw_terrains(CanvasItem *p_canvas_item, Transform2D p_transform, const TileData *p_tile_data); + Vector<Vector<Ref<Texture2D>>> generate_terrains_icons(Size2i p_size); + + // Resource management virtual void reset_state() override; TileSet(); @@ -509,13 +534,14 @@ private: // Physics struct PhysicsLayerTileData { - struct ShapeTileData { - Ref<Shape2D> shape = Ref<Shape2D>(); + struct PolygonShapeTileData { + LocalVector<Vector2> polygon; + LocalVector<Ref<ConvexPolygonShape2D>> shapes; bool one_way = false; float one_way_margin = 1.0; }; - Vector<ShapeTileData> shapes; + Vector<PolygonShapeTileData> polygons; }; Vector<PhysicsLayerTileData> physics; // TODO add support for areas. @@ -570,16 +596,18 @@ public: Ref<OccluderPolygon2D> get_occluder(int p_layer_id) const; // Physics - int get_collision_shapes_count(int p_layer_id) const; - void set_collision_shapes_count(int p_layer_id, int p_shapes_count); - void add_collision_shape(int p_layer_id); - void remove_collision_shape(int p_layer_id, int p_shape_index); - void set_collision_shape_shape(int p_layer_id, int p_shape_index, Ref<Shape2D> p_shape); - Ref<Shape2D> get_collision_shape_shape(int p_layer_id, int p_shape_index) const; - void set_collision_shape_one_way(int p_layer_id, int p_shape_index, bool p_one_way); - bool is_collision_shape_one_way(int p_layer_id, int p_shape_index) const; - void set_collision_shape_one_way_margin(int p_layer_id, int p_shape_index, float p_one_way_margin); - float get_collision_shape_one_way_margin(int p_layer_id, int p_shape_index) const; + int get_collision_polygons_count(int p_layer_id) const; + void set_collision_polygons_count(int p_layer_id, int p_shapes_count); + void add_collision_polygon(int p_layer_id); + void remove_collision_polygon(int p_layer_id, int p_polygon_index); + void set_collision_polygon_points(int p_layer_id, int p_polygon_index, Vector<Vector2> p_polygon); + Vector<Vector2> get_collision_polygon_points(int p_layer_id, int p_polygon_index) const; + void set_collision_polygon_one_way(int p_layer_id, int p_polygon_index, bool p_one_way); + bool is_collision_polygon_one_way(int p_layer_id, int p_polygon_index) const; + void set_collision_polygon_one_way_margin(int p_layer_id, int p_polygon_index, float p_one_way_margin); + float get_collision_polygon_one_way_margin(int p_layer_id, int p_polygon_index) const; + int get_collision_polygon_shapes_count(int p_layer_id, int p_polygon_index) const; + Ref<ConvexPolygonShape2D> get_collision_polygon_shape(int p_layer_id, int p_polygon_index, int shape_index) const; // Terrain void set_terrain_set(int p_terrain_id); @@ -637,26 +665,6 @@ public: static void draw_tile(RID p_canvas_item, Vector2i p_position, const Ref<TileSet> p_tile_set, int p_atlas_source_id, Vector2i p_atlas_coords, int p_alternative_tile, Color p_modulation = Color(1.0, 1.0, 1.0, 1.0)); }; -class TileSetPluginAtlasTerrain : public TileSetPlugin { - GDCLASS(TileSetPluginAtlasTerrain, TileSetPlugin); - -private: - static void _draw_square_corner_or_side_terrain_bit(CanvasItem *p_canvas_item, Color p_color, Vector2i p_size, TileSet::CellNeighbor p_bit); - static void _draw_square_corner_terrain_bit(CanvasItem *p_canvas_item, Color p_color, Vector2i p_size, TileSet::CellNeighbor p_bit); - static void _draw_square_side_terrain_bit(CanvasItem *p_canvas_item, Color p_color, Vector2i p_size, TileSet::CellNeighbor p_bit); - - static void _draw_isometric_corner_or_side_terrain_bit(CanvasItem *p_canvas_item, Color p_color, Vector2i p_size, TileSet::CellNeighbor p_bit); - static void _draw_isometric_corner_terrain_bit(CanvasItem *p_canvas_item, Color p_color, Vector2i p_size, TileSet::CellNeighbor p_bit); - static void _draw_isometric_side_terrain_bit(CanvasItem *p_canvas_item, Color p_color, Vector2i p_size, TileSet::CellNeighbor p_bit); - - static void _draw_half_offset_corner_or_side_terrain_bit(CanvasItem *p_canvas_item, Color p_color, Vector2i p_size, TileSet::CellNeighbor p_bit, float p_overlap, TileSet::TileOffsetAxis p_offset_axis); - static void _draw_half_offset_corner_terrain_bit(CanvasItem *p_canvas_item, Color p_color, Vector2i p_size, TileSet::CellNeighbor p_bit, float p_overlap, TileSet::TileOffsetAxis p_offset_axis); - static void _draw_half_offset_side_terrain_bit(CanvasItem *p_canvas_item, Color p_color, Vector2i p_size, TileSet::CellNeighbor p_bit, float p_overlap, TileSet::TileOffsetAxis p_offset_axis); - -public: - static void draw_terrains(CanvasItem *p_canvas_item, Transform2D p_transform, TileSet *p_tile_set, const TileData *p_tile_data); -}; - class TileSetPluginAtlasPhysics : public TileSetPlugin { GDCLASS(TileSetPluginAtlasPhysics, TileSetPlugin); diff --git a/scene/resources/visual_shader.cpp b/scene/resources/visual_shader.cpp index 5759948fe6..54bc7382db 100644 --- a/scene/resources/visual_shader.cpp +++ b/scene/resources/visual_shader.cpp @@ -617,7 +617,7 @@ void VisualShader::replace_node(Type p_type, int p_id, const StringName &p_new_c if (g->nodes[p_id].node->get_class_name() == p_new_class) { return; } - VisualShaderNode *vsn = Object::cast_to<VisualShaderNode>(ClassDB::instance(p_new_class)); + VisualShaderNode *vsn = Object::cast_to<VisualShaderNode>(ClassDB::instantiate(p_new_class)); vsn->connect("changed", callable_mp(this, &VisualShader::_queue_update)); g->nodes[p_id].node = Ref<VisualShaderNode>(vsn); @@ -2020,13 +2020,13 @@ VisualShader::VisualShader() { for (int i = 0; i < TYPE_MAX; i++) { if (i > (int)TYPE_LIGHT && i < (int)TYPE_SKY) { Ref<VisualShaderNodeParticleOutput> output; - output.instance(); + output.instantiate(); output->shader_type = Type(i); output->shader_mode = shader_mode; graph[i].nodes[NODE_ID_OUTPUT].node = output; } else { Ref<VisualShaderNodeOutput> output; - output.instance(); + output.instantiate(); output->shader_type = Type(i); output->shader_mode = shader_mode; graph[i].nodes[NODE_ID_OUTPUT].node = output; @@ -2533,6 +2533,14 @@ Vector<StringName> VisualShaderNodeInput::get_editable_properties() const { return props; } +void VisualShaderNodeInput::set_shader_type(VisualShader::Type p_shader_type) { + shader_type = p_shader_type; +} + +void VisualShaderNodeInput::set_shader_mode(Shader::Mode p_shader_mode) { + shader_mode = p_shader_mode; +} + void VisualShaderNodeInput::_bind_methods() { ClassDB::bind_method(D_METHOD("set_input_name", "name"), &VisualShaderNodeInput::set_input_name); ClassDB::bind_method(D_METHOD("get_input_name"), &VisualShaderNodeInput::get_input_name); diff --git a/scene/resources/visual_shader.h b/scene/resources/visual_shader.h index 53b165fe0f..454012b7ed 100644 --- a/scene/resources/visual_shader.h +++ b/scene/resources/visual_shader.h @@ -350,6 +350,10 @@ class VisualShaderNodeInput : public VisualShaderNode { String input_name = "[None]"; +public: + void set_shader_type(VisualShader::Type p_shader_type); + void set_shader_mode(Shader::Mode p_shader_mode); + protected: static void _bind_methods(); void _validate_property(PropertyInfo &property) const override; diff --git a/scene/resources/visual_shader_nodes.cpp b/scene/resources/visual_shader_nodes.cpp index d3b094de31..4e73b8db44 100644 --- a/scene/resources/visual_shader_nodes.cpp +++ b/scene/resources/visual_shader_nodes.cpp @@ -805,7 +805,7 @@ void VisualShaderNodeTexture::_bind_methods() { VisualShaderNodeTexture::VisualShaderNodeTexture() { } -////////////// Curve +////////////// CurveTexture String VisualShaderNodeCurveTexture::get_caption() const { return "CurveTexture"; @@ -889,6 +889,90 @@ VisualShaderNodeCurveTexture::VisualShaderNodeCurveTexture() { allow_v_resize = false; } +////////////// Curve3Texture + +String VisualShaderNodeCurve3Texture::get_caption() const { + return "Curve3Texture"; +} + +int VisualShaderNodeCurve3Texture::get_input_port_count() const { + return 1; +} + +VisualShaderNodeCurve3Texture::PortType VisualShaderNodeCurve3Texture::get_input_port_type(int p_port) const { + return PORT_TYPE_SCALAR; +} + +String VisualShaderNodeCurve3Texture::get_input_port_name(int p_port) const { + return String(); +} + +int VisualShaderNodeCurve3Texture::get_output_port_count() const { + return 1; +} + +VisualShaderNodeCurve3Texture::PortType VisualShaderNodeCurve3Texture::get_output_port_type(int p_port) const { + return PORT_TYPE_VECTOR; +} + +String VisualShaderNodeCurve3Texture::get_output_port_name(int p_port) const { + return String(); +} + +void VisualShaderNodeCurve3Texture::set_texture(Ref<Curve3Texture> p_texture) { + texture = p_texture; + emit_changed(); +} + +Ref<Curve3Texture> VisualShaderNodeCurve3Texture::get_texture() const { + return texture; +} + +Vector<StringName> VisualShaderNodeCurve3Texture::get_editable_properties() const { + Vector<StringName> props; + props.push_back("texture"); + return props; +} + +String VisualShaderNodeCurve3Texture::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const { + return "uniform sampler2D " + make_unique_id(p_type, p_id, "curve3d") + ";\n"; +} + +String VisualShaderNodeCurve3Texture::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { + if (p_input_vars[0] == String()) { + return "\t" + p_output_vars[0] + " = vec3(0.0);\n"; + } + String id = make_unique_id(p_type, p_id, "curve3d"); + String code; + code += "\t" + p_output_vars[0] + " = texture(" + id + ", vec2(" + p_input_vars[0] + ")).rgb;\n"; + return code; +} + +Vector<VisualShader::DefaultTextureParam> VisualShaderNodeCurve3Texture::get_default_texture_parameters(VisualShader::Type p_type, int p_id) const { + VisualShader::DefaultTextureParam dtp; + dtp.name = make_unique_id(p_type, p_id, "curve3d"); + dtp.param = texture; + Vector<VisualShader::DefaultTextureParam> ret; + ret.push_back(dtp); + return ret; +} + +void VisualShaderNodeCurve3Texture::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_texture", "texture"), &VisualShaderNodeCurve3Texture::set_texture); + ClassDB::bind_method(D_METHOD("get_texture"), &VisualShaderNodeCurve3Texture::get_texture); + + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Curve3Texture"), "set_texture", "get_texture"); +} + +bool VisualShaderNodeCurve3Texture::is_use_prop_slots() const { + return true; +} + +VisualShaderNodeCurve3Texture::VisualShaderNodeCurve3Texture() { + simple_decl = true; + allow_v_resize = false; +} + ////////////// Sample3D int VisualShaderNodeSample3D::get_input_port_count() const { diff --git a/scene/resources/visual_shader_nodes.h b/scene/resources/visual_shader_nodes.h index 5b44e9f776..3ae79723e9 100644 --- a/scene/resources/visual_shader_nodes.h +++ b/scene/resources/visual_shader_nodes.h @@ -338,6 +338,39 @@ public: /////////////////////////////////////// +class VisualShaderNodeCurve3Texture : public VisualShaderNodeResizableBase { + GDCLASS(VisualShaderNodeCurve3Texture, VisualShaderNodeResizableBase); + Ref<Curve3Texture> texture; + +protected: + static void _bind_methods(); + +public: + virtual String get_caption() const override; + + virtual int get_input_port_count() const override; + virtual PortType get_input_port_type(int p_port) const override; + virtual String get_input_port_name(int p_port) const override; + + virtual int get_output_port_count() const override; + virtual PortType get_output_port_type(int p_port) const override; + virtual String get_output_port_name(int p_port) const override; + + virtual Vector<VisualShader::DefaultTextureParam> get_default_texture_parameters(VisualShader::Type p_type, int p_id) const override; + virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const override; + virtual String generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview = false) const override; + + void set_texture(Ref<Curve3Texture> p_value); + Ref<Curve3Texture> get_texture() const; + + virtual Vector<StringName> get_editable_properties() const override; + virtual bool is_use_prop_slots() const override; + + VisualShaderNodeCurve3Texture(); +}; + +/////////////////////////////////////// + class VisualShaderNodeSample3D : public VisualShaderNode { GDCLASS(VisualShaderNodeSample3D, VisualShaderNode); diff --git a/scene/scene_string_names.cpp b/scene/scene_string_names.cpp index 8acab79c9e..35f8a506fc 100644 --- a/scene/scene_string_names.cpp +++ b/scene/scene_string_names.cpp @@ -103,7 +103,6 @@ SceneStringNames::SceneStringNames() { _update_scroll = StaticCString::create("_update_scroll"); _update_xform = StaticCString::create("_update_xform"); - _clips_input = StaticCString::create("_clips_input"); _structured_text_parser = StaticCString::create("_structured_text_parser"); _proxgroup_add = StaticCString::create("_proxgroup_add"); @@ -144,7 +143,7 @@ SceneStringNames::SceneStringNames() { v_offset = StaticCString::create("v_offset"); transform_pos = StaticCString::create("position"); - transform_rot = StaticCString::create("rotation_degrees"); + transform_rot = StaticCString::create("rotation"); transform_scale = StaticCString::create("scale"); _update_remote = StaticCString::create("_update_remote"); diff --git a/scene/scene_string_names.h b/scene/scene_string_names.h index 0c528a45f7..01865b0d2f 100644 --- a/scene/scene_string_names.h +++ b/scene/scene_string_names.h @@ -129,7 +129,6 @@ public: StringName _update_scroll; StringName _update_xform; - StringName _clips_input; StringName _structured_text_parser; StringName _proxgroup_add; diff --git a/servers/audio/audio_effect.h b/servers/audio/audio_effect.h index 5d14f03199..bea7292b8e 100644 --- a/servers/audio/audio_effect.h +++ b/servers/audio/audio_effect.h @@ -46,7 +46,7 @@ class AudioEffect : public Resource { GDCLASS(AudioEffect, Resource); public: - virtual Ref<AudioEffectInstance> instance() = 0; + virtual Ref<AudioEffectInstance> instantiate() = 0; AudioEffect(); }; diff --git a/servers/audio/audio_stream.cpp b/servers/audio/audio_stream.cpp index ae07f999ed..aec6932326 100644 --- a/servers/audio/audio_stream.cpp +++ b/servers/audio/audio_stream.cpp @@ -100,7 +100,7 @@ void AudioStream::_bind_methods() { Ref<AudioStreamPlayback> AudioStreamMicrophone::instance_playback() { Ref<AudioStreamPlaybackMicrophone> playback; - playback.instance(); + playback.instantiate(); playbacks.insert(playback.ptr()); @@ -256,7 +256,7 @@ float AudioStreamRandomPitch::get_random_pitch() const { Ref<AudioStreamPlayback> AudioStreamRandomPitch::instance_playback() { Ref<AudioStreamPlaybackRandomPitch> playback; - playback.instance(); + playback.instantiate(); if (audio_stream.is_valid()) { playback->playback = audio_stream->instance_playback(); } diff --git a/servers/audio/effects/audio_effect_amplify.cpp b/servers/audio/effects/audio_effect_amplify.cpp index c5c1174670..79788d334b 100644 --- a/servers/audio/effects/audio_effect_amplify.cpp +++ b/servers/audio/effects/audio_effect_amplify.cpp @@ -44,9 +44,9 @@ void AudioEffectAmplifyInstance::process(const AudioFrame *p_src_frames, AudioFr mix_volume_db = volume_db; } -Ref<AudioEffectInstance> AudioEffectAmplify::instance() { +Ref<AudioEffectInstance> AudioEffectAmplify::instantiate() { Ref<AudioEffectAmplifyInstance> ins; - ins.instance(); + ins.instantiate(); ins->base = Ref<AudioEffectAmplify>(this); ins->mix_volume_db = volume_db; return ins; diff --git a/servers/audio/effects/audio_effect_amplify.h b/servers/audio/effects/audio_effect_amplify.h index 2ece57854c..9d3facc230 100644 --- a/servers/audio/effects/audio_effect_amplify.h +++ b/servers/audio/effects/audio_effect_amplify.h @@ -56,7 +56,7 @@ protected: static void _bind_methods(); public: - Ref<AudioEffectInstance> instance() override; + Ref<AudioEffectInstance> instantiate() override; void set_volume_db(float p_volume); float get_volume_db() const; diff --git a/servers/audio/effects/audio_effect_capture.cpp b/servers/audio/effects/audio_effect_capture.cpp index 78837c7531..065065042e 100644 --- a/servers/audio/effects/audio_effect_capture.cpp +++ b/servers/audio/effects/audio_effect_capture.cpp @@ -73,7 +73,7 @@ void AudioEffectCapture::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "buffer_length", PROPERTY_HINT_RANGE, "0.01,10,0.01"), "set_buffer_length", "get_buffer_length"); } -Ref<AudioEffectInstance> AudioEffectCapture::instance() { +Ref<AudioEffectInstance> AudioEffectCapture::instantiate() { if (!buffer_initialized) { float target_buffer_size = AudioServer::get_singleton()->get_mix_rate() * buffer_length_seconds; ERR_FAIL_COND_V(target_buffer_size <= 0 || target_buffer_size >= (1 << 27), Ref<AudioEffectInstance>()); @@ -84,7 +84,7 @@ Ref<AudioEffectInstance> AudioEffectCapture::instance() { clear_buffer(); Ref<AudioEffectCaptureInstance> ins; - ins.instance(); + ins.instantiate(); ins->base = Ref<AudioEffectCapture>(this); return ins; diff --git a/servers/audio/effects/audio_effect_capture.h b/servers/audio/effects/audio_effect_capture.h index 82686d5b4c..7f50fc4965 100644 --- a/servers/audio/effects/audio_effect_capture.h +++ b/servers/audio/effects/audio_effect_capture.h @@ -64,7 +64,7 @@ protected: static void _bind_methods(); public: - virtual Ref<AudioEffectInstance> instance() override; + virtual Ref<AudioEffectInstance> instantiate() override; void set_buffer_length(float p_buffer_length_seconds); float get_buffer_length(); diff --git a/servers/audio/effects/audio_effect_chorus.cpp b/servers/audio/effects/audio_effect_chorus.cpp index eb2268aa2e..9af3ed30cc 100644 --- a/servers/audio/effects/audio_effect_chorus.cpp +++ b/servers/audio/effects/audio_effect_chorus.cpp @@ -141,9 +141,9 @@ void AudioEffectChorusInstance::_process_chunk(const AudioFrame *p_src_frames, A buffer_pos += p_frame_count; } -Ref<AudioEffectInstance> AudioEffectChorus::instance() { +Ref<AudioEffectInstance> AudioEffectChorus::instantiate() { Ref<AudioEffectChorusInstance> ins; - ins.instance(); + ins.instantiate(); ins->base = Ref<AudioEffectChorus>(this); for (int i = 0; i < 4; i++) { ins->filter_h[i] = AudioFrame(0, 0); @@ -276,7 +276,7 @@ void AudioEffectChorus::_validate_property(PropertyInfo &property) const { if (property.name.begins_with("voice/")) { int voice_idx = property.name.get_slice("/", 1).to_int(); if (voice_idx > voice_count) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } } } diff --git a/servers/audio/effects/audio_effect_chorus.h b/servers/audio/effects/audio_effect_chorus.h index f5b023734a..f81bebb0ae 100644 --- a/servers/audio/effects/audio_effect_chorus.h +++ b/servers/audio/effects/audio_effect_chorus.h @@ -128,7 +128,7 @@ public: void set_dry(float amount); float get_dry() const; - Ref<AudioEffectInstance> instance() override; + Ref<AudioEffectInstance> instantiate() override; AudioEffectChorus(); }; diff --git a/servers/audio/effects/audio_effect_compressor.cpp b/servers/audio/effects/audio_effect_compressor.cpp index bb4a90f3d6..cfa2ae6f79 100644 --- a/servers/audio/effects/audio_effect_compressor.cpp +++ b/servers/audio/effects/audio_effect_compressor.cpp @@ -112,9 +112,9 @@ void AudioEffectCompressorInstance::process(const AudioFrame *p_src_frames, Audi } } -Ref<AudioEffectInstance> AudioEffectCompressor::instance() { +Ref<AudioEffectInstance> AudioEffectCompressor::instantiate() { Ref<AudioEffectCompressorInstance> ins; - ins.instance(); + ins.instantiate(); ins->base = Ref<AudioEffectCompressor>(this); ins->rundb = 0; ins->runratio = 0; diff --git a/servers/audio/effects/audio_effect_compressor.h b/servers/audio/effects/audio_effect_compressor.h index 33c60680fc..dae4618a64 100644 --- a/servers/audio/effects/audio_effect_compressor.h +++ b/servers/audio/effects/audio_effect_compressor.h @@ -65,7 +65,7 @@ protected: static void _bind_methods(); public: - Ref<AudioEffectInstance> instance() override; + Ref<AudioEffectInstance> instantiate() override; void set_threshold(float p_threshold); float get_threshold() const; diff --git a/servers/audio/effects/audio_effect_delay.cpp b/servers/audio/effects/audio_effect_delay.cpp index ba50eeb0a3..07475e1ed4 100644 --- a/servers/audio/effects/audio_effect_delay.cpp +++ b/servers/audio/effects/audio_effect_delay.cpp @@ -111,9 +111,9 @@ void AudioEffectDelayInstance::_process_chunk(const AudioFrame *p_src_frames, Au } } -Ref<AudioEffectInstance> AudioEffectDelay::instance() { +Ref<AudioEffectInstance> AudioEffectDelay::instantiate() { Ref<AudioEffectDelayInstance> ins; - ins.instance(); + ins.instantiate(); ins->base = Ref<AudioEffectDelay>(this); float ring_buffer_max_size = MAX_DELAY_MS + 100; //add 100ms of extra room, just in case diff --git a/servers/audio/effects/audio_effect_delay.h b/servers/audio/effects/audio_effect_delay.h index ff267d5023..50a2233e5f 100644 --- a/servers/audio/effects/audio_effect_delay.h +++ b/servers/audio/effects/audio_effect_delay.h @@ -126,7 +126,7 @@ public: void set_feedback_lowpass(float p_lowpass); float get_feedback_lowpass() const; - Ref<AudioEffectInstance> instance() override; + Ref<AudioEffectInstance> instantiate() override; AudioEffectDelay(); }; diff --git a/servers/audio/effects/audio_effect_distortion.cpp b/servers/audio/effects/audio_effect_distortion.cpp index 5c076ca3fe..188b7a3301 100644 --- a/servers/audio/effects/audio_effect_distortion.cpp +++ b/servers/audio/effects/audio_effect_distortion.cpp @@ -93,9 +93,9 @@ void AudioEffectDistortionInstance::process(const AudioFrame *p_src_frames, Audi } } -Ref<AudioEffectInstance> AudioEffectDistortion::instance() { +Ref<AudioEffectInstance> AudioEffectDistortion::instantiate() { Ref<AudioEffectDistortionInstance> ins; - ins.instance(); + ins.instantiate(); ins->base = Ref<AudioEffectDistortion>(this); ins->h[0] = 0; ins->h[1] = 0; diff --git a/servers/audio/effects/audio_effect_distortion.h b/servers/audio/effects/audio_effect_distortion.h index 9da800b79f..3a762f8cf6 100644 --- a/servers/audio/effects/audio_effect_distortion.h +++ b/servers/audio/effects/audio_effect_distortion.h @@ -68,7 +68,7 @@ protected: static void _bind_methods(); public: - Ref<AudioEffectInstance> instance() override; + Ref<AudioEffectInstance> instantiate() override; void set_mode(Mode p_mode); Mode get_mode() const; diff --git a/servers/audio/effects/audio_effect_eq.cpp b/servers/audio/effects/audio_effect_eq.cpp index 01ac605bd7..e87944b74b 100644 --- a/servers/audio/effects/audio_effect_eq.cpp +++ b/servers/audio/effects/audio_effect_eq.cpp @@ -59,9 +59,9 @@ void AudioEffectEQInstance::process(const AudioFrame *p_src_frames, AudioFrame * } } -Ref<AudioEffectInstance> AudioEffectEQ::instance() { +Ref<AudioEffectInstance> AudioEffectEQ::instantiate() { Ref<AudioEffectEQInstance> ins; - ins.instance(); + ins.instantiate(); ins->base = Ref<AudioEffectEQ>(this); ins->gains.resize(eq.get_band_count()); for (int i = 0; i < 2; i++) { diff --git a/servers/audio/effects/audio_effect_eq.h b/servers/audio/effects/audio_effect_eq.h index 38c63a7d4f..b99727d7c0 100644 --- a/servers/audio/effects/audio_effect_eq.h +++ b/servers/audio/effects/audio_effect_eq.h @@ -66,7 +66,7 @@ protected: static void _bind_methods(); public: - Ref<AudioEffectInstance> instance() override; + Ref<AudioEffectInstance> instantiate() override; void set_band_gain_db(int p_band, float p_volume); float get_band_gain_db(int p_band) const; int get_band_count() const; diff --git a/servers/audio/effects/audio_effect_filter.cpp b/servers/audio/effects/audio_effect_filter.cpp index c2d6074825..1db8b1f1b5 100644 --- a/servers/audio/effects/audio_effect_filter.cpp +++ b/servers/audio/effects/audio_effect_filter.cpp @@ -100,9 +100,9 @@ AudioEffectFilterInstance::AudioEffectFilterInstance() { } } -Ref<AudioEffectInstance> AudioEffectFilter::instance() { +Ref<AudioEffectInstance> AudioEffectFilter::instantiate() { Ref<AudioEffectFilterInstance> ins; - ins.instance(); + ins.instantiate(); ins->base = Ref<AudioEffectFilter>(this); return ins; diff --git a/servers/audio/effects/audio_effect_filter.h b/servers/audio/effects/audio_effect_filter.h index 9a48ccf70b..1fa3df1570 100644 --- a/servers/audio/effects/audio_effect_filter.h +++ b/servers/audio/effects/audio_effect_filter.h @@ -88,7 +88,7 @@ public: void set_db(FilterDB p_db); FilterDB get_db() const; - Ref<AudioEffectInstance> instance() override; + Ref<AudioEffectInstance> instantiate() override; AudioEffectFilter(AudioFilterSW::Mode p_mode = AudioFilterSW::LOWPASS); }; @@ -100,7 +100,7 @@ class AudioEffectLowPassFilter : public AudioEffectFilter { void _validate_property(PropertyInfo &property) const override { if (property.name == "gain") { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } } @@ -113,7 +113,7 @@ class AudioEffectHighPassFilter : public AudioEffectFilter { GDCLASS(AudioEffectHighPassFilter, AudioEffectFilter); void _validate_property(PropertyInfo &property) const override { if (property.name == "gain") { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } } @@ -126,7 +126,7 @@ class AudioEffectBandPassFilter : public AudioEffectFilter { GDCLASS(AudioEffectBandPassFilter, AudioEffectFilter); void _validate_property(PropertyInfo &property) const override { if (property.name == "gain") { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } } diff --git a/servers/audio/effects/audio_effect_limiter.cpp b/servers/audio/effects/audio_effect_limiter.cpp index 1a4b01d947..280411641b 100644 --- a/servers/audio/effects/audio_effect_limiter.cpp +++ b/servers/audio/effects/audio_effect_limiter.cpp @@ -67,9 +67,9 @@ void AudioEffectLimiterInstance::process(const AudioFrame *p_src_frames, AudioFr } } -Ref<AudioEffectInstance> AudioEffectLimiter::instance() { +Ref<AudioEffectInstance> AudioEffectLimiter::instantiate() { Ref<AudioEffectLimiterInstance> ins; - ins.instance(); + ins.instantiate(); ins->base = Ref<AudioEffectLimiter>(this); return ins; diff --git a/servers/audio/effects/audio_effect_limiter.h b/servers/audio/effects/audio_effect_limiter.h index 8f3092c0e2..d5def670a4 100644 --- a/servers/audio/effects/audio_effect_limiter.h +++ b/servers/audio/effects/audio_effect_limiter.h @@ -71,7 +71,7 @@ public: void set_soft_clip_ratio(float p_soft_clip); float get_soft_clip_ratio() const; - Ref<AudioEffectInstance> instance() override; + Ref<AudioEffectInstance> instantiate() override; void set_volume_db(float p_volume); float get_volume_db() const; diff --git a/servers/audio/effects/audio_effect_panner.cpp b/servers/audio/effects/audio_effect_panner.cpp index 238e979e13..e2062609b9 100644 --- a/servers/audio/effects/audio_effect_panner.cpp +++ b/servers/audio/effects/audio_effect_panner.cpp @@ -40,9 +40,9 @@ void AudioEffectPannerInstance::process(const AudioFrame *p_src_frames, AudioFra } } -Ref<AudioEffectInstance> AudioEffectPanner::instance() { +Ref<AudioEffectInstance> AudioEffectPanner::instantiate() { Ref<AudioEffectPannerInstance> ins; - ins.instance(); + ins.instantiate(); ins->base = Ref<AudioEffectPanner>(this); return ins; } diff --git a/servers/audio/effects/audio_effect_panner.h b/servers/audio/effects/audio_effect_panner.h index 0938824c64..d75bcaeb95 100644 --- a/servers/audio/effects/audio_effect_panner.h +++ b/servers/audio/effects/audio_effect_panner.h @@ -54,7 +54,7 @@ protected: static void _bind_methods(); public: - Ref<AudioEffectInstance> instance() override; + Ref<AudioEffectInstance> instantiate() override; void set_pan(float p_cpanume); float get_pan() const; diff --git a/servers/audio/effects/audio_effect_phaser.cpp b/servers/audio/effects/audio_effect_phaser.cpp index 9b70f03a19..c76692eed7 100644 --- a/servers/audio/effects/audio_effect_phaser.cpp +++ b/servers/audio/effects/audio_effect_phaser.cpp @@ -78,9 +78,9 @@ void AudioEffectPhaserInstance::process(const AudioFrame *p_src_frames, AudioFra } } -Ref<AudioEffectInstance> AudioEffectPhaser::instance() { +Ref<AudioEffectInstance> AudioEffectPhaser::instantiate() { Ref<AudioEffectPhaserInstance> ins; - ins.instance(); + ins.instantiate(); ins->base = Ref<AudioEffectPhaser>(this); ins->phase = 0; ins->h = AudioFrame(0, 0); diff --git a/servers/audio/effects/audio_effect_phaser.h b/servers/audio/effects/audio_effect_phaser.h index 563927c678..2a0ed64805 100644 --- a/servers/audio/effects/audio_effect_phaser.h +++ b/servers/audio/effects/audio_effect_phaser.h @@ -83,7 +83,7 @@ protected: static void _bind_methods(); public: - Ref<AudioEffectInstance> instance() override; + Ref<AudioEffectInstance> instantiate() override; void set_range_min_hz(float p_hz); float get_range_min_hz() const; diff --git a/servers/audio/effects/audio_effect_pitch_shift.cpp b/servers/audio/effects/audio_effect_pitch_shift.cpp index 7b0151b9c1..bfbaeee3f3 100644 --- a/servers/audio/effects/audio_effect_pitch_shift.cpp +++ b/servers/audio/effects/audio_effect_pitch_shift.cpp @@ -298,9 +298,9 @@ void AudioEffectPitchShiftInstance::process(const AudioFrame *p_src_frames, Audi shift_r.PitchShift(base->pitch_scale, p_frame_count, fft_size, base->oversampling, sample_rate, in_r, out_r, 2); } -Ref<AudioEffectInstance> AudioEffectPitchShift::instance() { +Ref<AudioEffectInstance> AudioEffectPitchShift::instantiate() { Ref<AudioEffectPitchShiftInstance> ins; - ins.instance(); + ins.instantiate(); ins->base = Ref<AudioEffectPitchShift>(this); static const int fft_sizes[FFT_SIZE_MAX] = { 256, 512, 1024, 2048, 4096 }; ins->fft_size = fft_sizes[fft_size]; diff --git a/servers/audio/effects/audio_effect_pitch_shift.h b/servers/audio/effects/audio_effect_pitch_shift.h index 669943fa43..3ed096cd94 100644 --- a/servers/audio/effects/audio_effect_pitch_shift.h +++ b/servers/audio/effects/audio_effect_pitch_shift.h @@ -109,7 +109,7 @@ protected: static void _bind_methods(); public: - Ref<AudioEffectInstance> instance() override; + Ref<AudioEffectInstance> instantiate() override; void set_pitch_scale(float p_pitch_scale); float get_pitch_scale() const; diff --git a/servers/audio/effects/audio_effect_record.cpp b/servers/audio/effects/audio_effect_record.cpp index 2015ede81f..f71679d30f 100644 --- a/servers/audio/effects/audio_effect_record.cpp +++ b/servers/audio/effects/audio_effect_record.cpp @@ -134,9 +134,9 @@ AudioEffectRecordInstance::~AudioEffectRecordInstance() { finish(); } -Ref<AudioEffectInstance> AudioEffectRecord::instance() { +Ref<AudioEffectInstance> AudioEffectRecord::instantiate() { Ref<AudioEffectRecordInstance> ins; - ins.instance(); + ins.instantiate(); ins->base = Ref<AudioEffectRecord>(this); ins->is_recording = false; @@ -269,7 +269,7 @@ Ref<AudioStreamSample> AudioEffectRecord::get_recording() const { } Ref<AudioStreamSample> sample; - sample.instance(); + sample.instantiate(); sample->set_data(dst_data); sample->set_format(dst_format); sample->set_mix_rate(AudioServer::get_singleton()->get_mix_rate()); diff --git a/servers/audio/effects/audio_effect_record.h b/servers/audio/effects/audio_effect_record.h index 8f56e227e0..1a89821f80 100644 --- a/servers/audio/effects/audio_effect_record.h +++ b/servers/audio/effects/audio_effect_record.h @@ -96,7 +96,7 @@ protected: static void debug(uint64_t time_diff, int p_frame_count); public: - Ref<AudioEffectInstance> instance() override; + Ref<AudioEffectInstance> instantiate() override; void set_recording_active(bool p_record); bool is_recording_active() const; void set_format(AudioStreamSample::Format p_format); diff --git a/servers/audio/effects/audio_effect_reverb.cpp b/servers/audio/effects/audio_effect_reverb.cpp index b8d812680e..819f906773 100644 --- a/servers/audio/effects/audio_effect_reverb.cpp +++ b/servers/audio/effects/audio_effect_reverb.cpp @@ -79,9 +79,9 @@ AudioEffectReverbInstance::AudioEffectReverbInstance() { reverb[1].set_extra_spread_base(0.000521); //for stereo effect } -Ref<AudioEffectInstance> AudioEffectReverb::instance() { +Ref<AudioEffectInstance> AudioEffectReverb::instantiate() { Ref<AudioEffectReverbInstance> ins; - ins.instance(); + ins.instantiate(); ins->base = Ref<AudioEffectReverb>(this); return ins; } diff --git a/servers/audio/effects/audio_effect_reverb.h b/servers/audio/effects/audio_effect_reverb.h index 141ba48e29..d01d1120bd 100644 --- a/servers/audio/effects/audio_effect_reverb.h +++ b/servers/audio/effects/audio_effect_reverb.h @@ -89,7 +89,7 @@ public: float get_wet() const; float get_hpf() const; - Ref<AudioEffectInstance> instance() override; + Ref<AudioEffectInstance> instantiate() override; void set_volume_db(float p_volume); float get_volume_db() const; diff --git a/servers/audio/effects/audio_effect_spectrum_analyzer.cpp b/servers/audio/effects/audio_effect_spectrum_analyzer.cpp index 44b7f64d52..6f9e7ac67d 100644 --- a/servers/audio/effects/audio_effect_spectrum_analyzer.cpp +++ b/servers/audio/effects/audio_effect_spectrum_analyzer.cpp @@ -207,9 +207,9 @@ Vector2 AudioEffectSpectrumAnalyzerInstance::get_magnitude_for_frequency_range(f } } -Ref<AudioEffectInstance> AudioEffectSpectrumAnalyzer::instance() { +Ref<AudioEffectInstance> AudioEffectSpectrumAnalyzer::instantiate() { Ref<AudioEffectSpectrumAnalyzerInstance> ins; - ins.instance(); + ins.instantiate(); ins->base = Ref<AudioEffectSpectrumAnalyzer>(this); static const int fft_sizes[FFT_SIZE_MAX] = { 256, 512, 1024, 2048, 4096 }; ins->fft_size = fft_sizes[fft_size]; diff --git a/servers/audio/effects/audio_effect_spectrum_analyzer.h b/servers/audio/effects/audio_effect_spectrum_analyzer.h index fc275446f0..3c5ae4a5e8 100644 --- a/servers/audio/effects/audio_effect_spectrum_analyzer.h +++ b/servers/audio/effects/audio_effect_spectrum_analyzer.h @@ -90,7 +90,7 @@ protected: static void _bind_methods(); public: - Ref<AudioEffectInstance> instance() override; + Ref<AudioEffectInstance> instantiate() override; void set_buffer_length(float p_seconds); float get_buffer_length() const; void set_tap_back_pos(float p_seconds); diff --git a/servers/audio/effects/audio_effect_stereo_enhance.cpp b/servers/audio/effects/audio_effect_stereo_enhance.cpp index dfdf154aa4..3a016b06b8 100644 --- a/servers/audio/effects/audio_effect_stereo_enhance.cpp +++ b/servers/audio/effects/audio_effect_stereo_enhance.cpp @@ -74,9 +74,9 @@ AudioEffectStereoEnhanceInstance::~AudioEffectStereoEnhanceInstance() { memdelete_arr(delay_ringbuff); } -Ref<AudioEffectInstance> AudioEffectStereoEnhance::instance() { +Ref<AudioEffectInstance> AudioEffectStereoEnhance::instantiate() { Ref<AudioEffectStereoEnhanceInstance> ins; - ins.instance(); + ins.instantiate(); ins->base = Ref<AudioEffectStereoEnhance>(this); diff --git a/servers/audio/effects/audio_effect_stereo_enhance.h b/servers/audio/effects/audio_effect_stereo_enhance.h index f99256470b..e0f9d79a94 100644 --- a/servers/audio/effects/audio_effect_stereo_enhance.h +++ b/servers/audio/effects/audio_effect_stereo_enhance.h @@ -68,7 +68,7 @@ protected: static void _bind_methods(); public: - Ref<AudioEffectInstance> instance() override; + Ref<AudioEffectInstance> instantiate() override; void set_pan_pullout(float p_amount); float get_pan_pullout() const; diff --git a/servers/audio/effects/audio_stream_generator.cpp b/servers/audio/effects/audio_stream_generator.cpp index d1a05ccf2a..bced2997ce 100644 --- a/servers/audio/effects/audio_stream_generator.cpp +++ b/servers/audio/effects/audio_stream_generator.cpp @@ -48,7 +48,7 @@ float AudioStreamGenerator::get_buffer_length() const { Ref<AudioStreamPlayback> AudioStreamGenerator::instance_playback() { Ref<AudioStreamGeneratorPlayback> playback; - playback.instance(); + playback.instantiate(); playback->generator = this; int target_buffer_size = mix_rate * buffer_len; playback->buffer.resize(nearest_shift(target_buffer_size)); diff --git a/servers/audio_server.cpp b/servers/audio_server.cpp index acfdfa783a..667087d1ec 100644 --- a/servers/audio_server.cpp +++ b/servers/audio_server.cpp @@ -794,7 +794,7 @@ void AudioServer::_update_bus_effects(int p_bus) { for (int i = 0; i < buses[p_bus]->channels.size(); i++) { buses.write[p_bus]->channels.write[i].effect_instances.resize(buses[p_bus]->effects.size()); for (int j = 0; j < buses[p_bus]->effects.size(); j++) { - Ref<AudioEffectInstance> fx = buses.write[p_bus]->effects.write[j].effect->instance(); + Ref<AudioEffectInstance> fx = buses.write[p_bus]->effects.write[j].effect->instantiate(); if (Object::cast_to<AudioEffectCompressorInstance>(*fx)) { Object::cast_to<AudioEffectCompressorInstance>(*fx)->set_current_channel(i); } @@ -813,7 +813,7 @@ void AudioServer::add_bus_effect(int p_bus, const Ref<AudioEffect> &p_effect, in Bus::Effect fx; fx.effect = p_effect; - //fx.instance=p_effect->instance(); + //fx.instance=p_effect->instantiate(); fx.enabled = true; #ifdef DEBUG_ENABLED fx.prof_time = 0; @@ -1188,7 +1188,7 @@ void AudioServer::set_bus_layout(const Ref<AudioBusLayout> &p_bus_layout) { Ref<AudioBusLayout> AudioServer::generate_bus_layout() const { Ref<AudioBusLayout> state; - state.instance(); + state.instantiate(); state->buses.resize(buses.size()); diff --git a/servers/display_server.cpp b/servers/display_server.cpp index ded4b849ef..be2a813fd1 100644 --- a/servers/display_server.cpp +++ b/servers/display_server.cpp @@ -35,7 +35,6 @@ #include "servers/display_server_headless.h" DisplayServer *DisplayServer::singleton = nullptr; -DisplayServer::SwitchVSyncCallbackInThread DisplayServer::switch_vsync_function = nullptr; bool DisplayServer::hidpi_allowed = false; @@ -148,8 +147,8 @@ Point2i DisplayServer::mouse_get_position() const { ERR_FAIL_V_MSG(Point2i(), "Mouse is not supported by this display server."); } -int DisplayServer::mouse_get_button_state() const { - ERR_FAIL_V_MSG(0, "Mouse is not supported by this display server."); +MouseButton DisplayServer::mouse_get_button_state() const { + ERR_FAIL_V_MSG(MOUSE_BUTTON_NONE, "Mouse is not supported by this display server."); } void DisplayServer::clipboard_set(const String &p_text) { @@ -185,7 +184,7 @@ bool DisplayServer::screen_is_kept_on() const { return false; } -DisplayServer::WindowID DisplayServer::create_sub_window(WindowMode p_mode, uint32_t p_flags, const Rect2i &p_rect) { +DisplayServer::WindowID DisplayServer::create_sub_window(WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Rect2i &p_rect) { ERR_FAIL_V_MSG(INVALID_WINDOW_ID, "Sub-windows not supported by this display server."); } @@ -309,29 +308,13 @@ void DisplayServer::set_icon(const Ref<Image> &p_icon) { WARN_PRINT("Icon not supported by this display server."); } -void DisplayServer::_set_use_vsync(bool p_enable) { - WARN_PRINT("VSync not supported by this display server."); +void DisplayServer::window_set_vsync_mode(DisplayServer::VSyncMode p_vsync_mode, WindowID p_window) { + WARN_PRINT("Changing the VSync mode is not supported by this display server."); } -void DisplayServer::vsync_set_enabled(bool p_enable) { - vsync_enabled = p_enable; - if (switch_vsync_function) { //if a function was set, use function - switch_vsync_function(p_enable); - } else { //otherwise just call here - _set_use_vsync(p_enable); - } -} - -bool DisplayServer::vsync_is_enabled() const { - return vsync_enabled; -} - -void DisplayServer::vsync_set_use_via_compositor(bool p_enable) { - WARN_PRINT("VSync via compositor not supported by this display server."); -} - -bool DisplayServer::vsync_is_using_via_compositor() const { - return false; +DisplayServer::VSyncMode DisplayServer::window_get_vsync_mode(WindowID p_window) const { + WARN_PRINT("Changing the VSync mode is not supported by this display server."); + return VSyncMode::VSYNC_ENABLED; } void DisplayServer::set_context(Context p_context) { @@ -394,7 +377,7 @@ void DisplayServer::_bind_methods() { ClassDB::bind_method(D_METHOD("get_window_list"), &DisplayServer::get_window_list); ClassDB::bind_method(D_METHOD("get_window_at_screen_position", "position"), &DisplayServer::get_window_at_screen_position); - ClassDB::bind_method(D_METHOD("create_sub_window", "mode", "flags", "rect"), &DisplayServer::create_sub_window, DEFVAL(Rect2i())); + ClassDB::bind_method(D_METHOD("create_sub_window", "mode", "vsync_mode", "flags", "rect"), &DisplayServer::create_sub_window, DEFVAL(Rect2i())); ClassDB::bind_method(D_METHOD("delete_sub_window", "window_id"), &DisplayServer::delete_sub_window); ClassDB::bind_method(D_METHOD("window_set_title", "title", "window_id"), &DisplayServer::window_set_title, DEFVAL(MAIN_WINDOW_ID)); @@ -441,6 +424,9 @@ void DisplayServer::_bind_methods() { ClassDB::bind_method(D_METHOD("window_set_ime_active", "active", "window_id"), &DisplayServer::window_set_ime_active, DEFVAL(MAIN_WINDOW_ID)); ClassDB::bind_method(D_METHOD("window_set_ime_position", "position", "window_id"), &DisplayServer::window_set_ime_position, DEFVAL(MAIN_WINDOW_ID)); + ClassDB::bind_method(D_METHOD("window_set_vsync_mode", "vsync_mode", "window_id"), &DisplayServer::window_set_vsync_mode, DEFVAL(MAIN_WINDOW_ID)); + ClassDB::bind_method(D_METHOD("window_get_vsync_mode", "window_id"), &DisplayServer::window_get_vsync_mode, DEFVAL(MAIN_WINDOW_ID)); + ClassDB::bind_method(D_METHOD("ime_get_selection"), &DisplayServer::ime_get_selection); ClassDB::bind_method(D_METHOD("ime_get_text"), &DisplayServer::ime_get_text); @@ -472,12 +458,6 @@ void DisplayServer::_bind_methods() { ClassDB::bind_method(D_METHOD("process_events"), &DisplayServer::process_events); ClassDB::bind_method(D_METHOD("force_process_and_drop_events"), &DisplayServer::force_process_and_drop_events); - ClassDB::bind_method(D_METHOD("vsync_set_enabled", "enabled"), &DisplayServer::vsync_set_enabled); - ClassDB::bind_method(D_METHOD("vsync_is_enabled"), &DisplayServer::vsync_is_enabled); - - ClassDB::bind_method(D_METHOD("vsync_set_use_via_compositor", "enabled"), &DisplayServer::vsync_set_use_via_compositor); - ClassDB::bind_method(D_METHOD("vsync_is_using_via_compositor"), &DisplayServer::vsync_is_using_via_compositor); - ClassDB::bind_method(D_METHOD("set_native_icon", "filename"), &DisplayServer::set_native_icon); ClassDB::bind_method(D_METHOD("set_icon", "image"), &DisplayServer::set_icon); @@ -561,6 +541,11 @@ void DisplayServer::_bind_methods() { BIND_ENUM_CONSTANT(WINDOW_EVENT_CLOSE_REQUEST); BIND_ENUM_CONSTANT(WINDOW_EVENT_GO_BACK_REQUEST); BIND_ENUM_CONSTANT(WINDOW_EVENT_DPI_CHANGE); + + BIND_ENUM_CONSTANT(VSYNC_DISABLED); + BIND_ENUM_CONSTANT(VSYNC_ENABLED); + BIND_ENUM_CONSTANT(VSYNC_ADAPTIVE); + BIND_ENUM_CONSTANT(VSYNC_MAILBOX); } void DisplayServer::register_create_function(const char *p_name, CreateFunction p_function, GetRenderingDriversFunction p_get_drivers) { @@ -587,9 +572,9 @@ Vector<String> DisplayServer::get_create_function_rendering_drivers(int p_index) return server_create_functions[p_index].get_rendering_drivers_function(); } -DisplayServer *DisplayServer::create(int p_index, const String &p_rendering_driver, WindowMode p_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error) { +DisplayServer *DisplayServer::create(int p_index, const String &p_rendering_driver, WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error) { ERR_FAIL_INDEX_V(p_index, server_create_count, nullptr); - return server_create_functions[p_index].create_function(p_rendering_driver, p_mode, p_flags, p_resolution, r_error); + return server_create_functions[p_index].create_function(p_rendering_driver, p_mode, p_vsync_mode, p_flags, p_resolution, r_error); } void DisplayServer::_input_set_mouse_mode(Input::MouseMode p_mode) { diff --git a/servers/display_server.h b/servers/display_server.h index b8201f6fd5..8d289b10fd 100644 --- a/servers/display_server.h +++ b/servers/display_server.h @@ -42,7 +42,6 @@ class DisplayServer : public Object { GDCLASS(DisplayServer, Object) static DisplayServer *singleton; - bool vsync_enabled = true; static bool hidpi_allowed; public: @@ -57,7 +56,16 @@ public: WINDOW_MODE_FULLSCREEN }; - typedef DisplayServer *(*CreateFunction)(const String &, WindowMode, uint32_t, const Size2i &, Error &r_error); + // Keep the VSyncMode enum values in sync with the `display/window/vsync/vsync_mode` + // project setting hint. + enum VSyncMode { + VSYNC_DISABLED, + VSYNC_ENABLED, + VSYNC_ADAPTIVE, + VSYNC_MAILBOX + }; + + typedef DisplayServer *(*CreateFunction)(const String &, WindowMode, VSyncMode, uint32_t, const Size2i &, Error &r_error); typedef Vector<String> (*GetRenderingDriversFunction)(); private: @@ -84,7 +92,6 @@ protected: static int server_create_count; friend class RendererViewport; - virtual void _set_use_vsync(bool p_enable); public: enum Feature { @@ -152,7 +159,7 @@ public: virtual void mouse_warp_to_position(const Point2i &p_to); virtual Point2i mouse_get_position() const; virtual Point2i mouse_get_absolute_position() const; - virtual int mouse_get_button_state() const; + virtual MouseButton mouse_get_button_state() const; virtual void clipboard_set(const String &p_text); virtual String clipboard_get() const; @@ -221,7 +228,7 @@ public: WINDOW_FLAG_NO_FOCUS_BIT = (1 << WINDOW_FLAG_NO_FOCUS) }; - virtual WindowID create_sub_window(WindowMode p_mode, uint32_t p_flags, const Rect2i &p_rect = Rect2i()); + virtual WindowID create_sub_window(WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Rect2i &p_rect = Rect2i()); virtual void show_window(WindowID p_id); virtual void delete_sub_window(WindowID p_id); @@ -272,6 +279,9 @@ public: virtual void window_set_mode(WindowMode p_mode, WindowID p_window = MAIN_WINDOW_ID) = 0; virtual WindowMode window_get_mode(WindowID p_window = MAIN_WINDOW_ID) const = 0; + virtual void window_set_vsync_mode(VSyncMode p_vsync_mode, WindowID p_window = MAIN_WINDOW_ID); + virtual VSyncMode window_get_vsync_mode(WindowID p_window) const; + virtual bool window_is_maximize_allowed(WindowID p_window = MAIN_WINDOW_ID) const = 0; virtual void window_set_flag(WindowFlags p_flag, bool p_enabled, WindowID p_window = MAIN_WINDOW_ID) = 0; @@ -352,18 +362,6 @@ public: virtual void set_native_icon(const String &p_filename); virtual void set_icon(const Ref<Image> &p_icon); - typedef void (*SwitchVSyncCallbackInThread)(bool); - - static SwitchVSyncCallbackInThread switch_vsync_function; - - void vsync_set_enabled(bool p_enable); - bool vsync_is_enabled() const; - - virtual void vsync_set_use_via_compositor(bool p_enable); - virtual bool vsync_is_using_via_compositor() const; - - //real, actual overridable function to switch vsync, which needs to be called from graphics thread if needed - enum Context { CONTEXT_EDITOR, CONTEXT_PROJECTMAN, @@ -376,7 +374,7 @@ public: static int get_create_function_count(); static const char *get_create_function_name(int p_index); static Vector<String> get_create_function_rendering_drivers(int p_index); - static DisplayServer *create(int p_index, const String &p_rendering_driver, WindowMode p_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error); + static DisplayServer *create(int p_index, const String &p_rendering_driver, WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error); DisplayServer(); ~DisplayServer(); @@ -389,5 +387,6 @@ VARIANT_ENUM_CAST(DisplayServer::ScreenOrientation) VARIANT_ENUM_CAST(DisplayServer::WindowMode) VARIANT_ENUM_CAST(DisplayServer::WindowFlags) VARIANT_ENUM_CAST(DisplayServer::CursorShape) +VARIANT_ENUM_CAST(DisplayServer::VSyncMode) #endif // DISPLAY_SERVER_H diff --git a/servers/display_server_headless.h b/servers/display_server_headless.h index 8b386c8d9c..870401b180 100644 --- a/servers/display_server_headless.h +++ b/servers/display_server_headless.h @@ -45,7 +45,7 @@ private: return drivers; } - static DisplayServer *create_func(const String &p_rendering_driver, DisplayServer::WindowMode p_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error) { + static DisplayServer *create_func(const String &p_rendering_driver, DisplayServer::WindowMode p_mode, DisplayServer::VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error) { r_error = OK; RasterizerDummy::make_current(); return memnew(DisplayServerHeadless()); diff --git a/servers/physics_2d/area_pair_2d_sw.cpp b/servers/physics_2d/area_pair_2d_sw.cpp index eb9fc0e800..5cc5bae09b 100644 --- a/servers/physics_2d/area_pair_2d_sw.cpp +++ b/servers/physics_2d/area_pair_2d_sw.cpp @@ -33,10 +33,7 @@ bool AreaPair2DSW::setup(real_t p_step) { bool result = false; - - if (area->is_shape_set_as_disabled(area_shape) || body->is_shape_set_as_disabled(body_shape)) { - result = false; - } else if (area->test_collision_mask(body) && CollisionSolver2DSW::solve(body->get_shape(body_shape), body->get_transform() * body->get_shape_transform(body_shape), Vector2(), area->get_shape(area_shape), area->get_transform() * area->get_shape_transform(area_shape), Vector2(), nullptr, this)) { + if (area->test_collision_mask(body) && CollisionSolver2DSW::solve(body->get_shape(body_shape), body->get_transform() * body->get_shape_transform(body_shape), Vector2(), area->get_shape(area_shape), area->get_transform() * area->get_shape_transform(area_shape), Vector2(), nullptr, this)) { result = true; } @@ -113,9 +110,7 @@ AreaPair2DSW::~AreaPair2DSW() { bool Area2Pair2DSW::setup(real_t p_step) { bool result = false; - if (area_a->is_shape_set_as_disabled(shape_a) || area_b->is_shape_set_as_disabled(shape_b)) { - result = false; - } else if (area_a->test_collision_mask(area_b) && CollisionSolver2DSW::solve(area_a->get_shape(shape_a), area_a->get_transform() * area_a->get_shape_transform(shape_a), Vector2(), area_b->get_shape(shape_b), area_b->get_transform() * area_b->get_shape_transform(shape_b), Vector2(), nullptr, this)) { + if (area_a->test_collision_mask(area_b) && CollisionSolver2DSW::solve(area_a->get_shape(shape_a), area_a->get_transform() * area_a->get_shape_transform(shape_a), Vector2(), area_b->get_shape(shape_b), area_b->get_transform() * area_b->get_shape_transform(shape_b), Vector2(), nullptr, this)) { result = true; } diff --git a/servers/physics_2d/body_pair_2d_sw.cpp b/servers/physics_2d/body_pair_2d_sw.cpp index ff31825b83..e5eb374fa3 100644 --- a/servers/physics_2d/body_pair_2d_sw.cpp +++ b/servers/physics_2d/body_pair_2d_sw.cpp @@ -244,11 +244,6 @@ bool BodyPair2DSW::setup(real_t p_step) { } } - if (A->is_shape_set_as_disabled(shape_A) || B->is_shape_set_as_disabled(shape_B)) { - collided = false; - return false; - } - //use local A coordinates to avoid numerical issues on collision detection offset_B = B->get_transform().get_origin() - A->get_transform().get_origin(); diff --git a/servers/physics_2d/collision_object_2d_sw.cpp b/servers/physics_2d/collision_object_2d_sw.cpp index fa87dc1f3f..5d1ef83165 100644 --- a/servers/physics_2d/collision_object_2d_sw.cpp +++ b/servers/physics_2d/collision_object_2d_sw.cpp @@ -47,8 +47,6 @@ void CollisionObject2DSW::add_shape(Shape2DSW *p_shape, const Transform2D &p_tra if (!pending_shape_update_list.in_list()) { PhysicsServer2DSW::singletonsw->pending_shape_update_list.add(&pending_shape_update_list); } - // _update_shapes(); - // _shapes_changed(); } void CollisionObject2DSW::set_shape(int p_index, Shape2DSW *p_shape) { @@ -61,8 +59,6 @@ void CollisionObject2DSW::set_shape(int p_index, Shape2DSW *p_shape) { if (!pending_shape_update_list.in_list()) { PhysicsServer2DSW::singletonsw->pending_shape_update_list.add(&pending_shape_update_list); } - // _update_shapes(); - // _shapes_changed(); } void CollisionObject2DSW::set_shape_metadata(int p_index, const Variant &p_metadata) { @@ -79,11 +75,9 @@ void CollisionObject2DSW::set_shape_transform(int p_index, const Transform2D &p_ if (!pending_shape_update_list.in_list()) { PhysicsServer2DSW::singletonsw->pending_shape_update_list.add(&pending_shape_update_list); } - // _update_shapes(); - // _shapes_changed(); } -void CollisionObject2DSW::set_shape_as_disabled(int p_idx, bool p_disabled) { +void CollisionObject2DSW::set_shape_disabled(int p_idx, bool p_disabled) { ERR_FAIL_INDEX(p_idx, shapes.size()); CollisionObject2DSW::Shape &shape = shapes.write[p_idx]; @@ -103,12 +97,10 @@ void CollisionObject2DSW::set_shape_as_disabled(int p_idx, bool p_disabled) { if (!pending_shape_update_list.in_list()) { PhysicsServer2DSW::singletonsw->pending_shape_update_list.add(&pending_shape_update_list); } - //_update_shapes(); } else if (!p_disabled && shape.bpid == 0) { if (!pending_shape_update_list.in_list()) { PhysicsServer2DSW::singletonsw->pending_shape_update_list.add(&pending_shape_update_list); } - //_update_shapes(); // automatically adds shape with bpid == 0 } } @@ -177,7 +169,6 @@ void CollisionObject2DSW::_update_shapes() { for (int i = 0; i < shapes.size(); i++) { Shape &s = shapes.write[i]; - if (s.disabled) { continue; } diff --git a/servers/physics_2d/collision_object_2d_sw.h b/servers/physics_2d/collision_object_2d_sw.h index c395e59694..67da758d14 100644 --- a/servers/physics_2d/collision_object_2d_sw.h +++ b/servers/physics_2d/collision_object_2d_sw.h @@ -118,10 +118,6 @@ public: void set_shape_metadata(int p_index, const Variant &p_metadata); _FORCE_INLINE_ int get_shape_count() const { return shapes.size(); } - _FORCE_INLINE_ bool is_shape_disabled(int p_index) const { - CRASH_BAD_INDEX(p_index, shapes.size()); - return shapes[p_index].disabled; - } _FORCE_INLINE_ Shape2DSW *get_shape(int p_index) const { CRASH_BAD_INDEX(p_index, shapes.size()); return shapes[p_index].shape; @@ -147,9 +143,9 @@ public: _FORCE_INLINE_ const Transform2D &get_inv_transform() const { return inv_transform; } _FORCE_INLINE_ Space2DSW *get_space() const { return space; } - void set_shape_as_disabled(int p_idx, bool p_disabled); - _FORCE_INLINE_ bool is_shape_set_as_disabled(int p_idx) const { - CRASH_BAD_INDEX(p_idx, shapes.size()); + void set_shape_disabled(int p_idx, bool p_disabled); + _FORCE_INLINE_ bool is_shape_disabled(int p_idx) const { + ERR_FAIL_INDEX_V(p_idx, shapes.size(), false); return shapes[p_idx].disabled; } diff --git a/servers/physics_2d/physics_server_2d_sw.cpp b/servers/physics_2d/physics_server_2d_sw.cpp index 1c2dca0259..155dda4394 100644 --- a/servers/physics_2d/physics_server_2d_sw.cpp +++ b/servers/physics_2d/physics_server_2d_sw.cpp @@ -366,7 +366,7 @@ void PhysicsServer2DSW::area_set_shape_disabled(RID p_area, int p_shape, bool p_ ERR_FAIL_INDEX(p_shape, area->get_shape_count()); FLUSH_QUERY_CHECK(area); - area->set_shape_as_disabled(p_shape, p_disabled); + area->set_shape_disabled(p_shape, p_disabled); } int PhysicsServer2DSW::area_get_shape_count(RID p_area) const { @@ -663,7 +663,7 @@ void PhysicsServer2DSW::body_set_shape_disabled(RID p_body, int p_shape_idx, boo ERR_FAIL_INDEX(p_shape_idx, body->get_shape_count()); FLUSH_QUERY_CHECK(body); - body->set_shape_as_disabled(p_shape_idx, p_disabled); + body->set_shape_disabled(p_shape_idx, p_disabled); } void PhysicsServer2DSW::body_set_shape_as_one_way_collision(RID p_body, int p_shape_idx, bool p_enable, real_t p_margin) { diff --git a/servers/physics_2d/physics_server_2d_wrap_mt.h b/servers/physics_2d/physics_server_2d_wrap_mt.h index c776641699..a8f7ff3393 100644 --- a/servers/physics_2d/physics_server_2d_wrap_mt.h +++ b/servers/physics_2d/physics_server_2d_wrap_mt.h @@ -253,12 +253,12 @@ public: FUNC2(body_set_pickable, RID, bool); - bool body_test_motion(RID p_body, const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia, real_t p_margin = 0.001, MotionResult *r_result = nullptr, bool p_exclude_raycast_shapes = true) override { + bool body_test_motion(RID p_body, const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia, real_t p_margin = 0.08, MotionResult *r_result = nullptr, bool p_exclude_raycast_shapes = true) override { ERR_FAIL_COND_V(main_thread != Thread::get_caller_id(), false); return physics_2d_server->body_test_motion(p_body, p_from, p_motion, p_infinite_inertia, p_margin, r_result, p_exclude_raycast_shapes); } - int body_test_ray_separation(RID p_body, const Transform2D &p_transform, bool p_infinite_inertia, Vector2 &r_recover_motion, SeparationResult *r_results, int p_result_max, real_t p_margin = 0.001) override { + int body_test_ray_separation(RID p_body, const Transform2D &p_transform, bool p_infinite_inertia, Vector2 &r_recover_motion, SeparationResult *r_results, int p_result_max, real_t p_margin = 0.08) override { ERR_FAIL_COND_V(main_thread != Thread::get_caller_id(), false); return physics_2d_server->body_test_ray_separation(p_body, p_transform, p_infinite_inertia, r_recover_motion, r_results, p_result_max, p_margin); } diff --git a/servers/physics_2d/space_2d_sw.cpp b/servers/physics_2d/space_2d_sw.cpp index 1380e57b57..4b123b2d46 100644 --- a/servers/physics_2d/space_2d_sw.cpp +++ b/servers/physics_2d/space_2d_sw.cpp @@ -84,10 +84,6 @@ int PhysicsDirectSpaceState2DSW::_intersect_point_impl(const Vector2 &p_point, S int shape_idx = space->intersection_query_subindex_results[i]; - if (col_obj->is_shape_set_as_disabled(shape_idx)) { - continue; - } - Shape2DSW *shape = col_obj->get_shape(shape_idx); Vector2 local_point = (col_obj->get_transform() * col_obj->get_shape_transform(shape_idx)).affine_inverse().xform(p_point); @@ -233,10 +229,6 @@ int PhysicsDirectSpaceState2DSW::intersect_shape(const RID &p_shape, const Trans const CollisionObject2DSW *col_obj = space->intersection_query_results[i]; int shape_idx = space->intersection_query_subindex_results[i]; - if (col_obj->is_shape_set_as_disabled(shape_idx)) { - continue; - } - if (!CollisionSolver2DSW::solve(shape, p_xform, p_motion, col_obj->get_shape(shape_idx), col_obj->get_transform() * col_obj->get_shape_transform(shape_idx), Vector2(), nullptr, nullptr, nullptr, p_margin)) { continue; } @@ -280,10 +272,6 @@ bool PhysicsDirectSpaceState2DSW::cast_motion(const RID &p_shape, const Transfor const CollisionObject2DSW *col_obj = space->intersection_query_results[i]; int shape_idx = space->intersection_query_subindex_results[i]; - if (col_obj->is_shape_set_as_disabled(shape_idx)) { - continue; - } - Transform2D col_obj_xform = col_obj->get_transform() * col_obj->get_shape_transform(shape_idx); //test initial overlap, does it collide if going all the way? if (!CollisionSolver2DSW::solve(shape, p_xform, p_motion, col_obj->get_shape(shape_idx), col_obj_xform, Vector2(), nullptr, nullptr, nullptr, p_margin)) { @@ -365,10 +353,6 @@ bool PhysicsDirectSpaceState2DSW::collide_shape(RID p_shape, const Transform2D & int shape_idx = space->intersection_query_subindex_results[i]; - if (col_obj->is_shape_set_as_disabled(shape_idx)) { - continue; - } - cbk.valid_dir = Vector2(); cbk.valid_depth = 0; @@ -460,10 +444,6 @@ bool PhysicsDirectSpaceState2DSW::rest_info(RID p_shape, const Transform2D &p_sh int shape_idx = space->intersection_query_subindex_results[i]; - if (col_obj->is_shape_set_as_disabled(shape_idx)) { - continue; - } - rcd.valid_dir = Vector2(); rcd.object = col_obj; rcd.shape = shape_idx; @@ -516,8 +496,6 @@ int Space2DSW::_cull_aabb_for_body(Body2DSW *p_body, const Rect2 &p_aabb) { keep = false; } else if (static_cast<Body2DSW *>(intersection_query_results[i])->has_exception(p_body->get_self()) || p_body->has_exception(intersection_query_results[i]->get_self())) { keep = false; - } else if (static_cast<Body2DSW *>(intersection_query_results[i])->is_shape_set_as_disabled(intersection_query_subindex_results[i])) { - keep = false; } if (!keep) { @@ -540,7 +518,7 @@ int Space2DSW::test_body_ray_separation(Body2DSW *p_body, const Transform2D &p_t bool shapes_found = false; for (int i = 0; i < p_body->get_shape_count(); i++) { - if (p_body->is_shape_set_as_disabled(i)) { + if (p_body->is_shape_disabled(i)) { continue; } @@ -592,7 +570,7 @@ int Space2DSW::test_body_ray_separation(Body2DSW *p_body, const Transform2D &p_t int amount = _cull_aabb_for_body(p_body, body_aabb); for (int j = 0; j < p_body->get_shape_count(); j++) { - if (p_body->is_shape_set_as_disabled(j)) { + if (p_body->is_shape_disabled(j)) { continue; } @@ -732,7 +710,7 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co bool shapes_found = false; for (int i = 0; i < p_body->get_shape_count(); i++) { - if (p_body->is_shape_set_as_disabled(i)) { + if (p_body->is_shape_disabled(i)) { continue; } @@ -795,7 +773,7 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co int amount = _cull_aabb_for_body(p_body, body_aabb); for (int j = 0; j < p_body->get_shape_count(); j++) { - if (p_body->is_shape_set_as_disabled(j)) { + if (p_body->is_shape_disabled(j)) { continue; } @@ -918,7 +896,7 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co int amount = _cull_aabb_for_body(p_body, motion_aabb); for (int body_shape_idx = 0; body_shape_idx < p_body->get_shape_count(); body_shape_idx++) { - if (p_body->is_shape_set_as_disabled(body_shape_idx)) { + if (p_body->is_shape_disabled(body_shape_idx)) { continue; } @@ -1060,7 +1038,7 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co int to_shape = best_shape != -1 ? best_shape + 1 : p_body->get_shape_count(); for (int j = from_shape; j < to_shape; j++) { - if (p_body->is_shape_set_as_disabled(j)) { + if (p_body->is_shape_disabled(j)) { continue; } @@ -1142,6 +1120,9 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co r_result->collision_local_shape = rcd.best_local_shape; r_result->collision_normal = rcd.best_normal; r_result->collision_point = rcd.best_contact; + r_result->collision_depth = rcd.best_len; + r_result->collision_safe_fraction = safe; + r_result->collision_unsafe_fraction = unsafe; r_result->collider_metadata = rcd.best_object->get_shape_metadata(rcd.best_shape); const Body2DSW *body = static_cast<const Body2DSW *>(rcd.best_object); diff --git a/servers/physics_3d/area_pair_3d_sw.cpp b/servers/physics_3d/area_pair_3d_sw.cpp index 2073df7dee..9f93a61909 100644 --- a/servers/physics_3d/area_pair_3d_sw.cpp +++ b/servers/physics_3d/area_pair_3d_sw.cpp @@ -33,10 +33,7 @@ bool AreaPair3DSW::setup(real_t p_step) { bool result = false; - - if (area->is_shape_set_as_disabled(area_shape) || body->is_shape_set_as_disabled(body_shape)) { - result = false; - } else if (area->test_collision_mask(body) && CollisionSolver3DSW::solve_static(body->get_shape(body_shape), body->get_transform() * body->get_shape_transform(body_shape), area->get_shape(area_shape), area->get_transform() * area->get_shape_transform(area_shape), nullptr, this)) { + if (area->test_collision_mask(body) && CollisionSolver3DSW::solve_static(body->get_shape(body_shape), body->get_transform() * body->get_shape_transform(body_shape), area->get_shape(area_shape), area->get_transform() * area->get_shape_transform(area_shape), nullptr, this)) { result = true; } @@ -113,9 +110,7 @@ AreaPair3DSW::~AreaPair3DSW() { bool Area2Pair3DSW::setup(real_t p_step) { bool result = false; - if (area_a->is_shape_set_as_disabled(shape_a) || area_b->is_shape_set_as_disabled(shape_b)) { - result = false; - } else if (area_a->test_collision_mask(area_b) && CollisionSolver3DSW::solve_static(area_a->get_shape(shape_a), area_a->get_transform() * area_a->get_shape_transform(shape_a), area_b->get_shape(shape_b), area_b->get_transform() * area_b->get_shape_transform(shape_b), nullptr, this)) { + if (area_a->test_collision_mask(area_b) && CollisionSolver3DSW::solve_static(area_a->get_shape(shape_a), area_a->get_transform() * area_a->get_shape_transform(shape_a), area_b->get_shape(shape_b), area_b->get_transform() * area_b->get_shape_transform(shape_b), nullptr, this)) { result = true; } diff --git a/servers/physics_3d/body_pair_3d_sw.cpp b/servers/physics_3d/body_pair_3d_sw.cpp index aed4815c5e..6fc0fa8690 100644 --- a/servers/physics_3d/body_pair_3d_sw.cpp +++ b/servers/physics_3d/body_pair_3d_sw.cpp @@ -230,11 +230,6 @@ bool BodyPair3DSW::setup(real_t p_step) { } } - if (A->is_shape_set_as_disabled(shape_A) || B->is_shape_set_as_disabled(shape_B)) { - collided = false; - return false; - } - offset_B = B->get_transform().get_origin() - A->get_transform().get_origin(); validate_contacts(); @@ -607,11 +602,6 @@ bool BodySoftBodyPair3DSW::setup(real_t p_step) { return false; } - if (body->is_shape_set_as_disabled(body_shape)) { - collided = false; - return false; - } - const Transform3D &xform_Au = body->get_transform(); Transform3D xform_A = xform_Au * body->get_shape_transform(body_shape); diff --git a/servers/physics_3d/collision_object_3d_sw.cpp b/servers/physics_3d/collision_object_3d_sw.cpp index 51e2432071..24c7d7b85c 100644 --- a/servers/physics_3d/collision_object_3d_sw.cpp +++ b/servers/physics_3d/collision_object_3d_sw.cpp @@ -45,8 +45,6 @@ void CollisionObject3DSW::add_shape(Shape3DSW *p_shape, const Transform3D &p_tra if (!pending_shape_update_list.in_list()) { PhysicsServer3DSW::singletonsw->pending_shape_update_list.add(&pending_shape_update_list); } - //_update_shapes(); - //_shapes_changed(); } void CollisionObject3DSW::set_shape(int p_index, Shape3DSW *p_shape) { @@ -58,8 +56,6 @@ void CollisionObject3DSW::set_shape(int p_index, Shape3DSW *p_shape) { if (!pending_shape_update_list.in_list()) { PhysicsServer3DSW::singletonsw->pending_shape_update_list.add(&pending_shape_update_list); } - //_update_shapes(); - //_shapes_changed(); } void CollisionObject3DSW::set_shape_transform(int p_index, const Transform3D &p_transform) { @@ -70,14 +66,32 @@ void CollisionObject3DSW::set_shape_transform(int p_index, const Transform3D &p_ if (!pending_shape_update_list.in_list()) { PhysicsServer3DSW::singletonsw->pending_shape_update_list.add(&pending_shape_update_list); } - //_update_shapes(); - //_shapes_changed(); } -void CollisionObject3DSW::set_shape_as_disabled(int p_idx, bool p_enable) { - shapes.write[p_idx].disabled = p_enable; - if (!pending_shape_update_list.in_list()) { - PhysicsServer3DSW::singletonsw->pending_shape_update_list.add(&pending_shape_update_list); +void CollisionObject3DSW::set_shape_disabled(int p_idx, bool p_disabled) { + ERR_FAIL_INDEX(p_idx, shapes.size()); + + CollisionObject3DSW::Shape &shape = shapes.write[p_idx]; + if (shape.disabled == p_disabled) { + return; + } + + shape.disabled = p_disabled; + + if (!space) { + return; + } + + if (p_disabled && shape.bpid != 0) { + space->get_broadphase()->remove(shape.bpid); + shape.bpid = 0; + if (!pending_shape_update_list.in_list()) { + PhysicsServer3DSW::singletonsw->pending_shape_update_list.add(&pending_shape_update_list); + } + } else if (!p_disabled && shape.bpid == 0) { + if (!pending_shape_update_list.in_list()) { + PhysicsServer3DSW::singletonsw->pending_shape_update_list.add(&pending_shape_update_list); + } } } @@ -108,8 +122,6 @@ void CollisionObject3DSW::remove_shape(int p_index) { if (!pending_shape_update_list.in_list()) { PhysicsServer3DSW::singletonsw->pending_shape_update_list.add(&pending_shape_update_list); } - //_update_shapes(); - //_shapes_changed(); } void CollisionObject3DSW::_set_static(bool p_static) { @@ -146,6 +158,9 @@ void CollisionObject3DSW::_update_shapes() { for (int i = 0; i < shapes.size(); i++) { Shape &s = shapes.write[i]; + if (s.disabled) { + continue; + } //not quite correct, should compute the next matrix.. AABB shape_aabb = s.shape->get_aabb(); @@ -173,6 +188,9 @@ void CollisionObject3DSW::_update_shapes_with_motion(const Vector3 &p_motion) { for (int i = 0; i < shapes.size(); i++) { Shape &s = shapes.write[i]; + if (s.disabled) { + continue; + } //not quite correct, should compute the next matrix.. AABB shape_aabb = s.shape->get_aabb(); diff --git a/servers/physics_3d/collision_object_3d_sw.h b/servers/physics_3d/collision_object_3d_sw.h index 5505fec3da..b2b2fa0f50 100644 --- a/servers/physics_3d/collision_object_3d_sw.h +++ b/servers/physics_3d/collision_object_3d_sw.h @@ -120,15 +120,26 @@ public: void set_shape(int p_index, Shape3DSW *p_shape); void set_shape_transform(int p_index, const Transform3D &p_transform); _FORCE_INLINE_ int get_shape_count() const { return shapes.size(); } - _FORCE_INLINE_ bool is_shape_disabled(int p_index) const { + _FORCE_INLINE_ Shape3DSW *get_shape(int p_index) const { CRASH_BAD_INDEX(p_index, shapes.size()); - return shapes[p_index].disabled; + return shapes[p_index].shape; + } + _FORCE_INLINE_ const Transform3D &get_shape_transform(int p_index) const { + CRASH_BAD_INDEX(p_index, shapes.size()); + return shapes[p_index].xform; + } + _FORCE_INLINE_ const Transform3D &get_shape_inv_transform(int p_index) const { + CRASH_BAD_INDEX(p_index, shapes.size()); + return shapes[p_index].xform_inv; + } + _FORCE_INLINE_ const AABB &get_shape_aabb(int p_index) const { + CRASH_BAD_INDEX(p_index, shapes.size()); + return shapes[p_index].aabb_cache; + } + _FORCE_INLINE_ real_t get_shape_area(int p_index) const { + CRASH_BAD_INDEX(p_index, shapes.size()); + return shapes[p_index].area_cache; } - _FORCE_INLINE_ Shape3DSW *get_shape(int p_index) const { return shapes[p_index].shape; } - _FORCE_INLINE_ const Transform3D &get_shape_transform(int p_index) const { return shapes[p_index].xform; } - _FORCE_INLINE_ const Transform3D &get_shape_inv_transform(int p_index) const { return shapes[p_index].xform_inv; } - _FORCE_INLINE_ const AABB &get_shape_aabb(int p_index) const { return shapes[p_index].aabb_cache; } - _FORCE_INLINE_ real_t get_shape_area(int p_index) const { return shapes[p_index].area_cache; } _FORCE_INLINE_ const Transform3D &get_transform() const { return transform; } _FORCE_INLINE_ const Transform3D &get_inv_transform() const { return inv_transform; } @@ -137,9 +148,9 @@ public: _FORCE_INLINE_ void set_ray_pickable(bool p_enable) { ray_pickable = p_enable; } _FORCE_INLINE_ bool is_ray_pickable() const { return ray_pickable; } - void set_shape_as_disabled(int p_idx, bool p_enable); - _FORCE_INLINE_ bool is_shape_set_as_disabled(int p_idx) const { - CRASH_BAD_INDEX(p_idx, shapes.size()); + void set_shape_disabled(int p_idx, bool p_disabled); + _FORCE_INLINE_ bool is_shape_disabled(int p_idx) const { + ERR_FAIL_INDEX_V(p_idx, shapes.size(), false); return shapes[p_idx].disabled; } diff --git a/servers/physics_3d/collision_solver_3d_sat.cpp b/servers/physics_3d/collision_solver_3d_sat.cpp index b362f1ff17..1cfb9ba3ad 100644 --- a/servers/physics_3d/collision_solver_3d_sat.cpp +++ b/servers/physics_3d/collision_solver_3d_sat.cpp @@ -1024,7 +1024,7 @@ static void _collision_sphere_face(const Shape3DSW *p_a, const Transform3D &p_tr n1 *= -1.0; } - if (!separator.test_axis(n1.normalized(), !face_B->backface_collision)) { + if (!separator.test_axis(n1.normalized())) { return; } @@ -1035,7 +1035,7 @@ static void _collision_sphere_face(const Shape3DSW *p_a, const Transform3D &p_tr axis *= -1.0; } - if (!separator.test_axis(axis, !face_B->backface_collision)) { + if (!separator.test_axis(axis)) { return; } } @@ -1493,7 +1493,7 @@ static void _collision_box_face(const Shape3DSW *p_a, const Transform3D &p_trans axis *= -1.0; } - if (!separator.test_axis(axis, !face_B->backface_collision)) { + if (!separator.test_axis(axis)) { return; } } @@ -1509,7 +1509,7 @@ static void _collision_box_face(const Shape3DSW *p_a, const Transform3D &p_trans axis *= -1.0; } - if (!separator.test_axis(axis, !face_B->backface_collision)) { + if (!separator.test_axis(axis)) { return; } } @@ -1533,7 +1533,7 @@ static void _collision_box_face(const Shape3DSW *p_a, const Transform3D &p_trans axis_ab *= -1.0; } - if (!separator.test_axis(axis_ab.normalized(), !face_B->backface_collision)) { + if (!separator.test_axis(axis_ab.normalized())) { return; } @@ -1548,7 +1548,7 @@ static void _collision_box_face(const Shape3DSW *p_a, const Transform3D &p_trans axis *= -1.0; } - if (!separator.test_axis(axis, !face_B->backface_collision)) { + if (!separator.test_axis(axis)) { return; } } @@ -1578,7 +1578,7 @@ static void _collision_box_face(const Shape3DSW *p_a, const Transform3D &p_trans axis *= -1.0; } - if (!separator.test_axis(axis, !face_B->backface_collision)) { + if (!separator.test_axis(axis)) { return; } } @@ -1812,7 +1812,7 @@ static void _collision_capsule_face(const Shape3DSW *p_a, const Transform3D &p_t axis *= -1.0; } - if (!separator.test_axis(axis, !face_B->backface_collision)) { + if (!separator.test_axis(axis)) { return; } @@ -1821,7 +1821,7 @@ static void _collision_capsule_face(const Shape3DSW *p_a, const Transform3D &p_t dir_axis *= -1.0; } - if (!separator.test_axis(dir_axis, !face_B->backface_collision)) { + if (!separator.test_axis(dir_axis)) { return; } @@ -1834,7 +1834,7 @@ static void _collision_capsule_face(const Shape3DSW *p_a, const Transform3D &p_t n1 *= -1.0; } - if (!separator.test_axis(n1.normalized(), !face_B->backface_collision)) { + if (!separator.test_axis(n1.normalized())) { return; } @@ -1845,7 +1845,7 @@ static void _collision_capsule_face(const Shape3DSW *p_a, const Transform3D &p_t axis *= -1.0; } - if (!separator.test_axis(axis.normalized(), !face_B->backface_collision)) { + if (!separator.test_axis(axis.normalized())) { return; } } @@ -1955,7 +1955,7 @@ static void _collision_cylinder_face(const Shape3DSW *p_a, const Transform3D &p_ } // Cylinder end caps. - if (!separator.test_axis(cyl_axis, !face_B->backface_collision)) { + if (!separator.test_axis(cyl_axis)) { return; } @@ -1971,7 +1971,7 @@ static void _collision_cylinder_face(const Shape3DSW *p_a, const Transform3D &p_ axis *= -1.0; } - if (!separator.test_axis(axis.normalized(), !face_B->backface_collision)) { + if (!separator.test_axis(axis.normalized())) { return; } } @@ -1984,7 +1984,7 @@ static void _collision_cylinder_face(const Shape3DSW *p_a, const Transform3D &p_ axis *= -1.0; } - if (!separator.test_axis(axis, !face_B->backface_collision)) { + if (!separator.test_axis(axis)) { return; } } @@ -2021,7 +2021,7 @@ static void _collision_cylinder_face(const Shape3DSW *p_a, const Transform3D &p_ axis *= -1.0; } - if (!separator.test_axis(axis.normalized(), !face_B->backface_collision)) { + if (!separator.test_axis(axis.normalized())) { return; } } @@ -2175,7 +2175,7 @@ static void _collision_convex_polygon_face(const Shape3DSW *p_a, const Transform axis *= -1.0; } - if (!separator.test_axis(axis, !face_B->backface_collision)) { + if (!separator.test_axis(axis)) { return; } } @@ -2192,7 +2192,7 @@ static void _collision_convex_polygon_face(const Shape3DSW *p_a, const Transform axis *= -1.0; } - if (!separator.test_axis(axis, !face_B->backface_collision)) { + if (!separator.test_axis(axis)) { return; } } @@ -2209,7 +2209,7 @@ static void _collision_convex_polygon_face(const Shape3DSW *p_a, const Transform axis *= -1.0; } - if (!separator.test_axis(axis, !face_B->backface_collision)) { + if (!separator.test_axis(axis)) { return; } } @@ -2229,7 +2229,7 @@ static void _collision_convex_polygon_face(const Shape3DSW *p_a, const Transform axis *= -1.0; } - if (!separator.test_axis(axis, !face_B->backface_collision)) { + if (!separator.test_axis(axis)) { return; } } @@ -2248,7 +2248,7 @@ static void _collision_convex_polygon_face(const Shape3DSW *p_a, const Transform axis *= -1.0; } - if (!separator.test_axis(axis, !face_B->backface_collision)) { + if (!separator.test_axis(axis)) { return; } } diff --git a/servers/physics_3d/physics_server_3d_sw.cpp b/servers/physics_3d/physics_server_3d_sw.cpp index 7a95a8abc8..f26129a404 100644 --- a/servers/physics_3d/physics_server_3d_sw.cpp +++ b/servers/physics_3d/physics_server_3d_sw.cpp @@ -335,7 +335,7 @@ void PhysicsServer3DSW::area_set_shape_disabled(RID p_area, int p_shape_idx, boo ERR_FAIL_COND(!area); ERR_FAIL_INDEX(p_shape_idx, area->get_shape_count()); FLUSH_QUERY_CHECK(area); - area->set_shape_as_disabled(p_shape_idx, p_disabled); + area->set_shape_disabled(p_shape_idx, p_disabled); } void PhysicsServer3DSW::area_attach_object_instance_id(RID p_area, ObjectID p_id) { @@ -537,7 +537,7 @@ void PhysicsServer3DSW::body_set_shape_disabled(RID p_body, int p_shape_idx, boo ERR_FAIL_INDEX(p_shape_idx, body->get_shape_count()); FLUSH_QUERY_CHECK(body); - body->set_shape_as_disabled(p_shape_idx, p_disabled); + body->set_shape_disabled(p_shape_idx, p_disabled); } Transform3D PhysicsServer3DSW::body_get_shape_transform(RID p_body, int p_shape_idx) const { diff --git a/servers/physics_3d/space_3d_sw.cpp b/servers/physics_3d/space_3d_sw.cpp index c1e09c9a22..eff480396d 100644 --- a/servers/physics_3d/space_3d_sw.cpp +++ b/servers/physics_3d/space_3d_sw.cpp @@ -214,10 +214,6 @@ int PhysicsDirectSpaceState3DSW::intersect_shape(const RID &p_shape, const Trans const CollisionObject3DSW *col_obj = space->intersection_query_results[i]; int shape_idx = space->intersection_query_subindex_results[i]; - if (col_obj->is_shape_set_as_disabled(shape_idx)) { - continue; - } - if (!CollisionSolver3DSW::solve_static(shape, p_xform, col_obj->get_shape(shape_idx), col_obj->get_transform() * col_obj->get_shape_transform(shape_idx), nullptr, nullptr, nullptr, p_margin, 0)) { continue; } @@ -273,10 +269,6 @@ bool PhysicsDirectSpaceState3DSW::cast_motion(const RID &p_shape, const Transfor const CollisionObject3DSW *col_obj = space->intersection_query_results[i]; int shape_idx = space->intersection_query_subindex_results[i]; - if (col_obj->is_shape_set_as_disabled(shape_idx)) { - continue; - } - Vector3 point_A, point_B; Vector3 sep_axis = p_motion.normalized(); @@ -385,10 +377,6 @@ bool PhysicsDirectSpaceState3DSW::collide_shape(RID p_shape, const Transform3D & int shape_idx = space->intersection_query_subindex_results[i]; - if (col_obj->is_shape_set_as_disabled(shape_idx)) { - continue; - } - if (CollisionSolver3DSW::solve_static(shape, p_shape_xform, col_obj->get_shape(shape_idx), col_obj->get_transform() * col_obj->get_shape_transform(shape_idx), cbkres, cbkptr, nullptr, p_margin)) { collided = true; } @@ -460,10 +448,6 @@ bool PhysicsDirectSpaceState3DSW::rest_info(RID p_shape, const Transform3D &p_sh int shape_idx = space->intersection_query_subindex_results[i]; - if (col_obj->is_shape_set_as_disabled(shape_idx)) { - continue; - } - rcd.object = col_obj; rcd.shape = shape_idx; bool sc = CollisionSolver3DSW::solve_static(shape, p_shape_xform, col_obj->get_shape(shape_idx), col_obj->get_transform() * col_obj->get_shape_transform(shape_idx), _rest_cbk_result, &rcd, nullptr, p_margin); @@ -508,7 +492,7 @@ Vector3 PhysicsDirectSpaceState3DSW::get_closest_point_to_object_volume(RID p_ob bool shapes_found = false; for (int i = 0; i < obj->get_shape_count(); i++) { - if (obj->is_shape_set_as_disabled(i)) { + if (obj->is_shape_disabled(i)) { continue; } @@ -555,8 +539,6 @@ int Space3DSW::_cull_aabb_for_body(Body3DSW *p_body, const AABB &p_aabb) { keep = false; } else if (static_cast<Body3DSW *>(intersection_query_results[i])->has_exception(p_body->get_self()) || p_body->has_exception(intersection_query_results[i]->get_self())) { keep = false; - } else if (static_cast<Body3DSW *>(intersection_query_results[i])->is_shape_set_as_disabled(intersection_query_subindex_results[i])) { - keep = false; } if (!keep) { @@ -579,7 +561,7 @@ int Space3DSW::test_body_ray_separation(Body3DSW *p_body, const Transform3D &p_t bool shapes_found = false; for (int i = 0; i < p_body->get_shape_count(); i++) { - if (p_body->is_shape_set_as_disabled(i)) { + if (p_body->is_shape_disabled(i)) { continue; } @@ -626,7 +608,7 @@ int Space3DSW::test_body_ray_separation(Body3DSW *p_body, const Transform3D &p_t int amount = _cull_aabb_for_body(p_body, body_aabb); for (int j = 0; j < p_body->get_shape_count(); j++) { - if (p_body->is_shape_set_as_disabled(j)) { + if (p_body->is_shape_disabled(j)) { continue; } @@ -740,7 +722,7 @@ bool Space3DSW::test_body_motion(Body3DSW *p_body, const Transform3D &p_from, co bool shapes_found = false; for (int i = 0; i < p_body->get_shape_count(); i++) { - if (p_body->is_shape_set_as_disabled(i)) { + if (p_body->is_shape_disabled(i)) { continue; } @@ -793,7 +775,7 @@ bool Space3DSW::test_body_motion(Body3DSW *p_body, const Transform3D &p_from, co int amount = _cull_aabb_for_body(p_body, body_aabb); for (int j = 0; j < p_body->get_shape_count(); j++) { - if (p_body->is_shape_set_as_disabled(j)) { + if (p_body->is_shape_disabled(j)) { continue; } @@ -871,7 +853,7 @@ bool Space3DSW::test_body_motion(Body3DSW *p_body, const Transform3D &p_from, co int amount = _cull_aabb_for_body(p_body, motion_aabb); for (int j = 0; j < p_body->get_shape_count(); j++) { - if (p_body->is_shape_set_as_disabled(j)) { + if (p_body->is_shape_disabled(j)) { continue; } @@ -989,7 +971,7 @@ bool Space3DSW::test_body_motion(Body3DSW *p_body, const Transform3D &p_from, co int to_shape = best_shape != -1 ? best_shape + 1 : p_body->get_shape_count(); for (int j = from_shape; j < to_shape; j++) { - if (p_body->is_shape_set_as_disabled(j)) { + if (p_body->is_shape_disabled(j)) { continue; } @@ -1032,6 +1014,9 @@ bool Space3DSW::test_body_motion(Body3DSW *p_body, const Transform3D &p_from, co r_result->collision_local_shape = rcd.best_local_shape; r_result->collision_normal = rcd.best_normal; r_result->collision_point = rcd.best_contact; + r_result->collision_depth = rcd.best_len; + r_result->collision_safe_fraction = safe; + r_result->collision_unsafe_fraction = unsafe; //r_result->collider_metadata = rcd.best_object->get_shape_metadata(rcd.best_shape); const Body3DSW *body = static_cast<const Body3DSW *>(rcd.best_object); diff --git a/servers/physics_server_2d.cpp b/servers/physics_server_2d.cpp index faab4f43b8..ec0ff57a5e 100644 --- a/servers/physics_server_2d.cpp +++ b/servers/physics_server_2d.cpp @@ -418,37 +418,6 @@ void PhysicsDirectSpaceState2D::_bind_methods() { ClassDB::bind_method(D_METHOD("get_rest_info", "shape"), &PhysicsDirectSpaceState2D::_get_rest_info); } -int PhysicsShapeQueryResult2D::get_result_count() const { - return result.size(); -} - -RID PhysicsShapeQueryResult2D::get_result_rid(int p_idx) const { - return result[p_idx].rid; -} - -ObjectID PhysicsShapeQueryResult2D::get_result_object_id(int p_idx) const { - return result[p_idx].collider_id; -} - -Object *PhysicsShapeQueryResult2D::get_result_object(int p_idx) const { - return result[p_idx].collider; -} - -int PhysicsShapeQueryResult2D::get_result_object_shape(int p_idx) const { - return result[p_idx].shape; -} - -PhysicsShapeQueryResult2D::PhysicsShapeQueryResult2D() { -} - -void PhysicsShapeQueryResult2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_result_count"), &PhysicsShapeQueryResult2D::get_result_count); - ClassDB::bind_method(D_METHOD("get_result_rid", "idx"), &PhysicsShapeQueryResult2D::get_result_rid); - ClassDB::bind_method(D_METHOD("get_result_object_id", "idx"), &PhysicsShapeQueryResult2D::get_result_object_id); - ClassDB::bind_method(D_METHOD("get_result_object", "idx"), &PhysicsShapeQueryResult2D::get_result_object); - ClassDB::bind_method(D_METHOD("get_result_object_shape", "idx"), &PhysicsShapeQueryResult2D::get_result_object_shape); -} - /////////////////////////////// Vector2 PhysicsTestMotionResult2D::get_motion() const { @@ -487,6 +456,18 @@ int PhysicsTestMotionResult2D::get_collider_shape() const { return result.collider_shape; } +real_t PhysicsTestMotionResult2D::get_collision_depth() const { + return result.collision_depth; +} + +real_t PhysicsTestMotionResult2D::get_collision_safe_fraction() const { + return result.collision_safe_fraction; +} + +real_t PhysicsTestMotionResult2D::get_collision_unsafe_fraction() const { + return result.collision_unsafe_fraction; +} + void PhysicsTestMotionResult2D::_bind_methods() { ClassDB::bind_method(D_METHOD("get_motion"), &PhysicsTestMotionResult2D::get_motion); ClassDB::bind_method(D_METHOD("get_motion_remainder"), &PhysicsTestMotionResult2D::get_motion_remainder); @@ -497,6 +478,9 @@ void PhysicsTestMotionResult2D::_bind_methods() { ClassDB::bind_method(D_METHOD("get_collider_rid"), &PhysicsTestMotionResult2D::get_collider_rid); ClassDB::bind_method(D_METHOD("get_collider"), &PhysicsTestMotionResult2D::get_collider); ClassDB::bind_method(D_METHOD("get_collider_shape"), &PhysicsTestMotionResult2D::get_collider_shape); + ClassDB::bind_method(D_METHOD("get_collision_depth"), &PhysicsTestMotionResult2D::get_collision_depth); + ClassDB::bind_method(D_METHOD("get_collision_safe_fraction"), &PhysicsTestMotionResult2D::get_collision_safe_fraction); + ClassDB::bind_method(D_METHOD("get_collision_unsafe_fraction"), &PhysicsTestMotionResult2D::get_collision_unsafe_fraction); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "motion"), "", "get_motion"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "motion_remainder"), "", "get_motion_remainder"); @@ -507,6 +491,9 @@ void PhysicsTestMotionResult2D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::RID, "collider_rid"), "", "get_collider_rid"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "collider"), "", "get_collider"); ADD_PROPERTY(PropertyInfo(Variant::INT, "collider_shape"), "", "get_collider_shape"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "collision_depth"), "", "get_collision_depth"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "collision_safe_fraction"), "", "get_collision_safe_fraction"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "collision_unsafe_fraction"), "", "get_collision_unsafe_fraction"); } /////////////////////////////////////// diff --git a/servers/physics_server_2d.h b/servers/physics_server_2d.h index df39d6ae50..6737aacaf0 100644 --- a/servers/physics_server_2d.h +++ b/servers/physics_server_2d.h @@ -92,8 +92,6 @@ public: PhysicsDirectBodyState2D(); }; -class PhysicsShapeQueryResult2D; - //used for script class PhysicsShapeQueryParameters2D : public RefCounted { GDCLASS(PhysicsShapeQueryParameters2D, RefCounted); @@ -203,26 +201,6 @@ public: PhysicsDirectSpaceState2D(); }; -class PhysicsShapeQueryResult2D : public RefCounted { - GDCLASS(PhysicsShapeQueryResult2D, RefCounted); - - Vector<PhysicsDirectSpaceState2D::ShapeResult> result; - - friend class PhysicsDirectSpaceState2D; - -protected: - static void _bind_methods(); - -public: - int get_result_count() const; - RID get_result_rid(int p_idx) const; - ObjectID get_result_object_id(int p_idx) const; - Object *get_result_object(int p_idx) const; - int get_result_object_shape(int p_idx) const; - - PhysicsShapeQueryResult2D(); -}; - class PhysicsTestMotionResult2D; class PhysicsServer2D : public Object { @@ -493,6 +471,9 @@ public: Vector2 collision_point; Vector2 collision_normal; Vector2 collider_velocity; + real_t collision_depth = 0.0; + real_t collision_safe_fraction = 0.0; + real_t collision_unsafe_fraction = 0.0; int collision_local_shape = 0; ObjectID collider_id; RID collider; @@ -500,7 +481,7 @@ public: Variant collider_metadata; }; - virtual bool body_test_motion(RID p_body, const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia, real_t p_margin = 0.001, MotionResult *r_result = nullptr, bool p_exclude_raycast_shapes = true) = 0; + virtual bool body_test_motion(RID p_body, const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia, real_t p_margin = 0.08, MotionResult *r_result = nullptr, bool p_exclude_raycast_shapes = true) = 0; struct SeparationResult { real_t collision_depth; @@ -514,7 +495,7 @@ public: Variant collider_metadata; }; - virtual int body_test_ray_separation(RID p_body, const Transform2D &p_transform, bool p_infinite_inertia, Vector2 &r_recover_motion, SeparationResult *r_results, int p_result_max, real_t p_margin = 0.001) = 0; + virtual int body_test_ray_separation(RID p_body, const Transform2D &p_transform, bool p_infinite_inertia, Vector2 &r_recover_motion, SeparationResult *r_results, int p_result_max, real_t p_margin = 0.08) = 0; /* JOINT API */ @@ -619,6 +600,9 @@ public: RID get_collider_rid() const; Object *get_collider() const; int get_collider_shape() const; + real_t get_collision_depth() const; + real_t get_collision_safe_fraction() const; + real_t get_collision_unsafe_fraction() const; }; typedef PhysicsServer2D *(*CreatePhysicsServer2DCallback)(); diff --git a/servers/physics_server_3d.cpp b/servers/physics_server_3d.cpp index 1634169e8a..7a0253506c 100644 --- a/servers/physics_server_3d.cpp +++ b/servers/physics_server_3d.cpp @@ -365,39 +365,94 @@ void PhysicsDirectSpaceState3D::_bind_methods() { ClassDB::bind_method(D_METHOD("get_rest_info", "shape"), &PhysicsDirectSpaceState3D::_get_rest_info); } -int PhysicsShapeQueryResult3D::get_result_count() const { - return result.size(); +/////////////////////////////// + +Vector3 PhysicsTestMotionResult3D::get_motion() const { + return result.motion; +} + +Vector3 PhysicsTestMotionResult3D::get_motion_remainder() const { + return result.remainder; +} + +Vector3 PhysicsTestMotionResult3D::get_collision_point() const { + return result.collision_point; +} + +Vector3 PhysicsTestMotionResult3D::get_collision_normal() const { + return result.collision_normal; +} + +Vector3 PhysicsTestMotionResult3D::get_collider_velocity() const { + return result.collider_velocity; } -RID PhysicsShapeQueryResult3D::get_result_rid(int p_idx) const { - return result[p_idx].rid; +ObjectID PhysicsTestMotionResult3D::get_collider_id() const { + return result.collider_id; } -ObjectID PhysicsShapeQueryResult3D::get_result_object_id(int p_idx) const { - return result[p_idx].collider_id; +RID PhysicsTestMotionResult3D::get_collider_rid() const { + return result.collider; } -Object *PhysicsShapeQueryResult3D::get_result_object(int p_idx) const { - return result[p_idx].collider; +Object *PhysicsTestMotionResult3D::get_collider() const { + return ObjectDB::get_instance(result.collider_id); } -int PhysicsShapeQueryResult3D::get_result_object_shape(int p_idx) const { - return result[p_idx].shape; +int PhysicsTestMotionResult3D::get_collider_shape() const { + return result.collider_shape; } -PhysicsShapeQueryResult3D::PhysicsShapeQueryResult3D() { +real_t PhysicsTestMotionResult3D::get_collision_depth() const { + return result.collision_depth; } -void PhysicsShapeQueryResult3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_result_count"), &PhysicsShapeQueryResult3D::get_result_count); - ClassDB::bind_method(D_METHOD("get_result_rid", "idx"), &PhysicsShapeQueryResult3D::get_result_rid); - ClassDB::bind_method(D_METHOD("get_result_object_id", "idx"), &PhysicsShapeQueryResult3D::get_result_object_id); - ClassDB::bind_method(D_METHOD("get_result_object", "idx"), &PhysicsShapeQueryResult3D::get_result_object); - ClassDB::bind_method(D_METHOD("get_result_object_shape", "idx"), &PhysicsShapeQueryResult3D::get_result_object_shape); +real_t PhysicsTestMotionResult3D::get_collision_safe_fraction() const { + return result.collision_safe_fraction; +} + +real_t PhysicsTestMotionResult3D::get_collision_unsafe_fraction() const { + return result.collision_unsafe_fraction; +} + +void PhysicsTestMotionResult3D::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_motion"), &PhysicsTestMotionResult3D::get_motion); + ClassDB::bind_method(D_METHOD("get_motion_remainder"), &PhysicsTestMotionResult3D::get_motion_remainder); + ClassDB::bind_method(D_METHOD("get_collision_point"), &PhysicsTestMotionResult3D::get_collision_point); + ClassDB::bind_method(D_METHOD("get_collision_normal"), &PhysicsTestMotionResult3D::get_collision_normal); + ClassDB::bind_method(D_METHOD("get_collider_velocity"), &PhysicsTestMotionResult3D::get_collider_velocity); + ClassDB::bind_method(D_METHOD("get_collider_id"), &PhysicsTestMotionResult3D::get_collider_id); + ClassDB::bind_method(D_METHOD("get_collider_rid"), &PhysicsTestMotionResult3D::get_collider_rid); + ClassDB::bind_method(D_METHOD("get_collider"), &PhysicsTestMotionResult3D::get_collider); + ClassDB::bind_method(D_METHOD("get_collider_shape"), &PhysicsTestMotionResult3D::get_collider_shape); + ClassDB::bind_method(D_METHOD("get_collision_depth"), &PhysicsTestMotionResult3D::get_collision_depth); + ClassDB::bind_method(D_METHOD("get_collision_safe_fraction"), &PhysicsTestMotionResult3D::get_collision_safe_fraction); + ClassDB::bind_method(D_METHOD("get_collision_unsafe_fraction"), &PhysicsTestMotionResult3D::get_collision_unsafe_fraction); + + ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "motion"), "", "get_motion"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "motion_remainder"), "", "get_motion_remainder"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "collision_point"), "", "get_collision_point"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "collision_normal"), "", "get_collision_normal"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "collider_velocity"), "", "get_collider_velocity"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "collider_id", PROPERTY_HINT_OBJECT_ID), "", "get_collider_id"); + ADD_PROPERTY(PropertyInfo(Variant::RID, "collider_rid"), "", "get_collider_rid"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "collider"), "", "get_collider"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "collider_shape"), "", "get_collider_shape"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "collision_depth"), "", "get_collision_depth"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "collision_safe_fraction"), "", "get_collision_safe_fraction"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "collision_unsafe_fraction"), "", "get_collision_unsafe_fraction"); } /////////////////////////////////////// +bool PhysicsServer3D::_body_test_motion(RID p_body, const Transform3D &p_from, const Vector3 &p_motion, bool p_infinite_inertia, real_t p_margin, const Ref<PhysicsTestMotionResult3D> &p_result) { + MotionResult *r = nullptr; + if (p_result.is_valid()) { + r = p_result->get_result_ptr(); + } + return body_test_motion(p_body, p_from, p_motion, p_infinite_inertia, p_margin, r); +} + RID PhysicsServer3D::shape_create(ShapeType p_shape) { switch (p_shape) { case SHAPE_PLANE: @@ -551,6 +606,8 @@ void PhysicsServer3D::_bind_methods() { ClassDB::bind_method(D_METHOD("body_set_ray_pickable", "body", "enable"), &PhysicsServer3D::body_set_ray_pickable); + ClassDB::bind_method(D_METHOD("body_test_motion", "body", "from", "motion", "infinite_inertia", "margin", "result"), &PhysicsServer3D::_body_test_motion, DEFVAL(0.001), DEFVAL(Variant())); + ClassDB::bind_method(D_METHOD("body_get_direct_state", "body"), &PhysicsServer3D::body_get_direct_state); /* SOFT BODY API */ diff --git a/servers/physics_server_3d.h b/servers/physics_server_3d.h index d9b805de87..78fc026747 100644 --- a/servers/physics_server_3d.h +++ b/servers/physics_server_3d.h @@ -94,8 +94,6 @@ public: PhysicsDirectBodyState3D(); }; -class PhysicsShapeQueryResult3D; - class PhysicsShapeQueryParameters3D : public RefCounted { GDCLASS(PhysicsShapeQueryParameters3D, RefCounted); friend class PhysicsDirectSpaceState3D; @@ -196,26 +194,6 @@ public: PhysicsDirectSpaceState3D(); }; -class PhysicsShapeQueryResult3D : public RefCounted { - GDCLASS(PhysicsShapeQueryResult3D, RefCounted); - - Vector<PhysicsDirectSpaceState3D::ShapeResult> result; - - friend class PhysicsDirectSpaceState3D; - -protected: - static void _bind_methods(); - -public: - int get_result_count() const; - RID get_result_rid(int p_idx) const; - ObjectID get_result_object_id(int p_idx) const; - Object *get_result_object(int p_idx) const; - int get_result_object_shape(int p_idx) const; - - PhysicsShapeQueryResult3D(); -}; - class RenderingServerHandler { public: virtual void set_vertex(int p_vertex_id, const void *p_vector3) = 0; @@ -225,11 +203,15 @@ public: virtual ~RenderingServerHandler() {} }; +class PhysicsTestMotionResult3D; + class PhysicsServer3D : public Object { GDCLASS(PhysicsServer3D, Object); static PhysicsServer3D *singleton; + virtual bool _body_test_motion(RID p_body, const Transform3D &p_from, const Vector3 &p_motion, bool p_infinite_inertia, real_t p_margin = 0.001, const Ref<PhysicsTestMotionResult3D> &p_result = Ref<PhysicsTestMotionResult3D>()); + protected: static void _bind_methods(); @@ -497,6 +479,9 @@ public: Vector3 collision_point; Vector3 collision_normal; Vector3 collider_velocity; + real_t collision_depth = 0.0; + real_t collision_safe_fraction = 0.0; + real_t collision_unsafe_fraction = 0.0; int collision_local_shape = 0; ObjectID collider_id; RID collider; @@ -767,6 +752,33 @@ public: ~PhysicsServer3D(); }; +class PhysicsTestMotionResult3D : public RefCounted { + GDCLASS(PhysicsTestMotionResult3D, RefCounted); + + PhysicsServer3D::MotionResult result; + friend class PhysicsServer3D; + +protected: + static void _bind_methods(); + +public: + PhysicsServer3D::MotionResult *get_result_ptr() const { return const_cast<PhysicsServer3D::MotionResult *>(&result); } + + Vector3 get_motion() const; + Vector3 get_motion_remainder() const; + + Vector3 get_collision_point() const; + Vector3 get_collision_normal() const; + Vector3 get_collider_velocity() const; + ObjectID get_collider_id() const; + RID get_collider_rid() const; + Object *get_collider() const; + int get_collider_shape() const; + real_t get_collision_depth() const; + real_t get_collision_safe_fraction() const; + real_t get_collision_unsafe_fraction() const; +}; + typedef PhysicsServer3D *(*CreatePhysicsServer3DCallback)(); class PhysicsServer3DManager { diff --git a/servers/register_server_types.cpp b/servers/register_server_types.cpp index deb230c4fb..ef82ce5cae 100644 --- a/servers/register_server_types.cpp +++ b/servers/register_server_types.cpp @@ -55,6 +55,7 @@ #include "audio_server.h" #include "camera/camera_feed.h" #include "camera_server.h" +#include "core/extension/native_extension_manager.h" #include "display_server.h" #include "navigation_server_2d.h" #include "navigation_server_3d.h" @@ -194,6 +195,7 @@ void register_server_types() { ClassDB::register_class<RDTextureFormat>(); ClassDB::register_class<RDTextureView>(); ClassDB::register_class<RDAttachmentFormat>(); + ClassDB::register_class<RDFramebufferPass>(); ClassDB::register_class<RDSamplerState>(); ClassDB::register_class<RDVertexAttribute>(); ClassDB::register_class<RDUniform>(); @@ -205,19 +207,19 @@ void register_server_types() { ClassDB::register_class<RDShaderSource>(); ClassDB::register_class<RDShaderBytecode>(); ClassDB::register_class<RDShaderFile>(); + ClassDB::register_class<RDPipelineSpecializationConstant>(); ClassDB::register_class<CameraFeed>(); ClassDB::register_virtual_class<PhysicsDirectBodyState2D>(); ClassDB::register_virtual_class<PhysicsDirectSpaceState2D>(); - ClassDB::register_virtual_class<PhysicsShapeQueryResult2D>(); ClassDB::register_class<PhysicsTestMotionResult2D>(); ClassDB::register_class<PhysicsShapeQueryParameters2D>(); ClassDB::register_class<PhysicsShapeQueryParameters3D>(); ClassDB::register_virtual_class<PhysicsDirectBodyState3D>(); ClassDB::register_virtual_class<PhysicsDirectSpaceState3D>(); - ClassDB::register_virtual_class<PhysicsShapeQueryResult3D>(); + ClassDB::register_class<PhysicsTestMotionResult3D>(); // Physics 2D GLOBAL_DEF(PhysicsServer2DManager::setting_property_name, "DEFAULT"); @@ -232,22 +234,26 @@ void register_server_types() { PhysicsServer3DManager::register_server("GodotPhysics3D", &_createGodotPhysics3DCallback); PhysicsServer3DManager::set_default_server("GodotPhysics3D"); + + NativeExtensionManager::get_singleton()->initialize_extensions(NativeExtension::INITIALIZATION_LEVEL_SERVERS); } void unregister_server_types() { + NativeExtensionManager::get_singleton()->deinitialize_extensions(NativeExtension::INITIALIZATION_LEVEL_SERVERS); + memdelete(shader_types); TextServer::finish_hex_code_box_fonts(); } void register_server_singletons() { - Engine::get_singleton()->add_singleton(Engine::Singleton("DisplayServer", DisplayServer::get_singleton())); - Engine::get_singleton()->add_singleton(Engine::Singleton("RenderingServer", RenderingServer::get_singleton())); - Engine::get_singleton()->add_singleton(Engine::Singleton("AudioServer", AudioServer::get_singleton())); - Engine::get_singleton()->add_singleton(Engine::Singleton("PhysicsServer2D", PhysicsServer2D::get_singleton())); - Engine::get_singleton()->add_singleton(Engine::Singleton("PhysicsServer3D", PhysicsServer3D::get_singleton())); - Engine::get_singleton()->add_singleton(Engine::Singleton("NavigationServer2D", NavigationServer2D::get_singleton_mut())); - Engine::get_singleton()->add_singleton(Engine::Singleton("NavigationServer3D", NavigationServer3D::get_singleton_mut())); - Engine::get_singleton()->add_singleton(Engine::Singleton("TextServerManager", TextServerManager::get_singleton())); - Engine::get_singleton()->add_singleton(Engine::Singleton("XRServer", XRServer::get_singleton())); - Engine::get_singleton()->add_singleton(Engine::Singleton("CameraServer", CameraServer::get_singleton())); + Engine::get_singleton()->add_singleton(Engine::Singleton("DisplayServer", DisplayServer::get_singleton(), "DisplayServer")); + Engine::get_singleton()->add_singleton(Engine::Singleton("RenderingServer", RenderingServer::get_singleton(), "RenderingServer")); + Engine::get_singleton()->add_singleton(Engine::Singleton("AudioServer", AudioServer::get_singleton(), "AudioServer")); + Engine::get_singleton()->add_singleton(Engine::Singleton("PhysicsServer2D", PhysicsServer2D::get_singleton(), "PhysicsServer2D")); + Engine::get_singleton()->add_singleton(Engine::Singleton("PhysicsServer3D", PhysicsServer3D::get_singleton(), "PhysicsServer3D")); + Engine::get_singleton()->add_singleton(Engine::Singleton("NavigationServer2D", NavigationServer2D::get_singleton_mut(), "NavigationServer2D")); + Engine::get_singleton()->add_singleton(Engine::Singleton("NavigationServer3D", NavigationServer3D::get_singleton_mut(), "NavigationServer3D")); + Engine::get_singleton()->add_singleton(Engine::Singleton("TextServerManager", TextServerManager::get_singleton(), "TextServerManager")); + Engine::get_singleton()->add_singleton(Engine::Singleton("XRServer", XRServer::get_singleton(), "XRServer")); + Engine::get_singleton()->add_singleton(Engine::Singleton("CameraServer", CameraServer::get_singleton(), "CameraServer")); } diff --git a/servers/rendering/rasterizer_dummy.h b/servers/rendering/rasterizer_dummy.h index d4c25b6253..f22ca738ae 100644 --- a/servers/rendering/rasterizer_dummy.h +++ b/servers/rendering/rasterizer_dummy.h @@ -36,6 +36,7 @@ #include "core/templates/self_list.h" #include "scene/resources/mesh.h" #include "servers/rendering/renderer_compositor.h" +#include "servers/rendering/renderer_scene_render.h" #include "servers/rendering_server.h" class RasterizerSceneDummy : public RendererSceneRender { @@ -175,7 +176,7 @@ public: void voxel_gi_set_quality(RS::VoxelGIQuality) override {} - void render_scene(RID p_render_buffers, const CameraData *p_camera_data, const PagedArray<GeometryInstance *> &p_instances, const PagedArray<RID> &p_lights, const PagedArray<RID> &p_reflection_probes, const PagedArray<RID> &p_voxel_gi_instances, const PagedArray<RID> &p_decals, const PagedArray<RID> &p_lightmaps, RID p_environment, RID p_camera_effects, RID p_shadow_atlas, RID p_occluder_debug_tex, RID p_reflection_atlas, RID p_reflection_probe, int p_reflection_probe_pass, float p_screen_lod_threshold, const RenderShadowData *p_render_shadows, int p_render_shadow_count, const RenderSDFGIData *p_render_sdfgi_regions, int p_render_sdfgi_region_count, const RenderSDFGIUpdateData *p_sdfgi_update_data = nullptr) override {} + void render_scene(RID p_render_buffers, const CameraData *p_camera_data, const PagedArray<GeometryInstance *> &p_instances, const PagedArray<RID> &p_lights, const PagedArray<RID> &p_reflection_probes, const PagedArray<RID> &p_voxel_gi_instances, const PagedArray<RID> &p_decals, const PagedArray<RID> &p_lightmaps, RID p_environment, RID p_camera_effects, RID p_shadow_atlas, RID p_occluder_debug_tex, RID p_reflection_atlas, RID p_reflection_probe, int p_reflection_probe_pass, float p_screen_lod_threshold, const RenderShadowData *p_render_shadows, int p_render_shadow_count, const RenderSDFGIData *p_render_sdfgi_regions, int p_render_sdfgi_region_count, const RenderSDFGIUpdateData *p_sdfgi_update_data = nullptr, RendererScene::RenderInfo *r_info = nullptr) override {} void render_material(const Transform3D &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, const PagedArray<GeometryInstance *> &p_instances, RID p_framebuffer, const Rect2i &p_region) override {} void render_particle_collider_heightfield(RID p_collider, const Transform3D &p_transform, const PagedArray<GeometryInstance *> &p_instances) override {} @@ -225,7 +226,6 @@ public: } void texture_2d_layered_initialize(RID p_texture, const Vector<Ref<Image>> &p_layers, RS::TextureLayeredType p_layered_type) override {} - void texture_2d_update_immediate(RID p_texture, const Ref<Image> &p_image, int p_layer = 0) override {} void texture_2d_update(RID p_texture, const Ref<Image> &p_image, int p_layer = 0) override {} void texture_3d_initialize(RID p_texture, Image::Format, int p_width, int p_height, int p_depth, bool p_mipmaps, const Vector<Ref<Image>> &p_data) override {} void texture_3d_update(RID p_texture, const Vector<Ref<Image>> &p_data) override {} @@ -324,7 +324,9 @@ public: void mesh_set_blend_shape_mode(RID p_mesh, RS::BlendShapeMode p_mode) override {} RS::BlendShapeMode mesh_get_blend_shape_mode(RID p_mesh) const override { return RS::BLEND_SHAPE_MODE_NORMALIZED; } - void mesh_surface_update_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) override {} + void mesh_surface_update_vertex_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) override {} + void mesh_surface_update_attribute_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) override {} + void mesh_surface_update_skin_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) override {} void mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material) override {} RID mesh_surface_get_material(RID p_mesh, int p_surface) const override { return RID(); } @@ -365,23 +367,6 @@ public: void multimesh_set_visible_instances(RID p_multimesh, int p_visible) override {} int multimesh_get_visible_instances(RID p_multimesh) const override { return 0; } - /* IMMEDIATE API */ - - RID immediate_allocate() override { return RID(); } - void immediate_initialize(RID p_rid) override {} - void immediate_begin(RID p_immediate, RS::PrimitiveType p_rimitive, RID p_texture = RID()) override {} - void immediate_vertex(RID p_immediate, const Vector3 &p_vertex) override {} - void immediate_normal(RID p_immediate, const Vector3 &p_normal) override {} - void immediate_tangent(RID p_immediate, const Plane &p_tangent) override {} - void immediate_color(RID p_immediate, const Color &p_color) override {} - void immediate_uv(RID p_immediate, const Vector2 &tex_uv) override {} - void immediate_uv2(RID p_immediate, const Vector2 &tex_uv) override {} - void immediate_end(RID p_immediate) override {} - void immediate_clear(RID p_immediate) override {} - void immediate_set_material(RID p_immediate, RID p_material) override {} - RID immediate_get_material(RID p_immediate) const override { return RID(); } - AABB immediate_get_aabb(RID p_immediate) const override { return AABB(); } - /* SKELETON API */ RID skeleton_allocate() override { return RID(); } @@ -421,10 +406,8 @@ public: void light_directional_set_shadow_mode(RID p_light, RS::LightDirectionalShadowMode p_mode) override {} void light_directional_set_blend_splits(RID p_light, bool p_enable) override {} bool light_directional_get_blend_splits(RID p_light) const override { return false; } - void light_directional_set_shadow_depth_range_mode(RID p_light, RS::LightDirectionalShadowDepthRangeMode p_range_mode) override {} void light_directional_set_sky_only(RID p_light, bool p_sky_only) override {} bool light_directional_is_sky_only(RID p_light) const override { return false; } - RS::LightDirectionalShadowDepthRangeMode light_directional_get_shadow_depth_range_mode(RID p_light) const override { return RS::LIGHT_DIRECTIONAL_SHADOW_DEPTH_RANGE_STABLE; } RS::LightDirectionalShadowMode light_directional_get_shadow_mode(RID p_light) override { return RS::LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL; } RS::LightOmniShadowMode light_omni_get_shadow_mode(RID p_light) override { return RS::LIGHT_OMNI_SHADOW_DUAL_PARABOLOID; } @@ -506,12 +489,6 @@ public: void voxel_gi_set_energy(RID p_voxel_gi, float p_range) override {} float voxel_gi_get_energy(RID p_voxel_gi) const override { return 0.0; } - void voxel_gi_set_ao(RID p_voxel_gi, float p_ao) override {} - float voxel_gi_get_ao(RID p_voxel_gi) const override { return 0; } - - void voxel_gi_set_ao_size(RID p_voxel_gi, float p_strength) override {} - float voxel_gi_get_ao_size(RID p_voxel_gi) const override { return 0; } - void voxel_gi_set_bias(RID p_voxel_gi, float p_range) override {} float voxel_gi_get_bias(RID p_voxel_gi) const override { return 0.0; } @@ -686,17 +663,15 @@ public: return true; } + virtual void update_memory_info() override {} + virtual uint64_t get_rendering_info(RS::RenderingInfo p_info) override { return 0; } + bool has_os_feature(const String &p_feature) const override { return false; } void update_dirty_resources() override {} void set_debug_generate_wireframes(bool p_generate) override {} - void render_info_begin_capture() override {} - void render_info_end_capture() override {} - int get_captured_render_info(RS::RenderInfo p_info) override { return 0; } - - uint64_t get_render_info(RS::RenderInfo p_info) override { return 0; } String get_video_adapter_name() const override { return String(); } String get_video_adapter_vendor() const override { return String(); } @@ -734,8 +709,6 @@ public: void occluder_polygon_set_cull_mode(RID p_occluder, RS::CanvasOccluderPolygonCullMode p_mode) override {} void set_shadow_texture_size(int p_size) override {} - void draw_window_margins(int *p_margins, RID *p_margin_textures) override {} - bool free(RID p_rid) override { return true; } void update() override {} diff --git a/servers/rendering/renderer_canvas_cull.cpp b/servers/rendering/renderer_canvas_cull.cpp index 016a172f25..ec0a8347f8 100644 --- a/servers/rendering/renderer_canvas_cull.cpp +++ b/servers/rendering/renderer_canvas_cull.cpp @@ -97,7 +97,7 @@ void _collect_ysort_children(RendererCanvasCull::Item *p_canvas_item, Transform2 } } -void _mark_ysort_dirty(RendererCanvasCull::Item *ysort_owner, RID_PtrOwner<RendererCanvasCull::Item, true> &canvas_item_owner) { +void _mark_ysort_dirty(RendererCanvasCull::Item *ysort_owner, RID_Owner<RendererCanvasCull::Item, true> &canvas_item_owner) { do { ysort_owner->ysort_children_count = -1; ysort_owner = canvas_item_owner.owns(ysort_owner->parent) ? canvas_item_owner.getornull(ysort_owner->parent) : nullptr; @@ -392,8 +392,7 @@ RID RendererCanvasCull::canvas_allocate() { return canvas_owner.allocate_rid(); } void RendererCanvasCull::canvas_initialize(RID p_rid) { - Canvas *canvas = memnew(Canvas); - canvas_owner.initialize_rid(p_rid, canvas); + canvas_owner.initialize_rid(p_rid); } void RendererCanvasCull::canvas_set_item_mirroring(RID p_canvas, RID p_item, const Point2 &p_mirroring) { @@ -429,8 +428,7 @@ RID RendererCanvasCull::canvas_item_allocate() { return canvas_item_owner.allocate_rid(); } void RendererCanvasCull::canvas_item_initialize(RID p_rid) { - Item *canvas_item = memnew(Item); - canvas_item_owner.initialize_rid(p_rid, canvas_item); + canvas_item_owner.initialize_rid(p_rid); } void RendererCanvasCull::canvas_item_set_parent(RID p_item, RID p_parent) { @@ -1171,9 +1169,9 @@ RID RendererCanvasCull::canvas_light_allocate() { return canvas_light_owner.allocate_rid(); } void RendererCanvasCull::canvas_light_initialize(RID p_rid) { - RendererCanvasRender::Light *clight = memnew(RendererCanvasRender::Light); + canvas_light_owner.initialize_rid(p_rid); + RendererCanvasRender::Light *clight = canvas_light_owner.getornull(p_rid); clight->light_internal = RSG::canvas_render->light_create(); - return canvas_light_owner.initialize_rid(p_rid, clight); } void RendererCanvasCull::canvas_light_set_mode(RID p_light, RS::CanvasLightMode p_mode) { @@ -1367,9 +1365,7 @@ RID RendererCanvasCull::canvas_light_occluder_allocate() { return canvas_light_occluder_owner.allocate_rid(); } void RendererCanvasCull::canvas_light_occluder_initialize(RID p_rid) { - RendererCanvasRender::LightOccluderInstance *occluder = memnew(RendererCanvasRender::LightOccluderInstance); - - return canvas_light_occluder_owner.initialize_rid(p_rid, occluder); + return canvas_light_occluder_owner.initialize_rid(p_rid); } void RendererCanvasCull::canvas_light_occluder_attach_to_canvas(RID p_occluder, RID p_canvas) { @@ -1451,9 +1447,9 @@ RID RendererCanvasCull::canvas_occluder_polygon_allocate() { return canvas_light_occluder_polygon_owner.allocate_rid(); } void RendererCanvasCull::canvas_occluder_polygon_initialize(RID p_rid) { - LightOccluderPolygon *occluder_poly = memnew(LightOccluderPolygon); + canvas_light_occluder_polygon_owner.initialize_rid(p_rid); + LightOccluderPolygon *occluder_poly = canvas_light_occluder_polygon_owner.getornull(p_rid); occluder_poly->occluder = RSG::canvas_render->occluder_polygon_create(); - return canvas_light_occluder_polygon_owner.initialize_rid(p_rid, occluder_poly); } void RendererCanvasCull::canvas_occluder_polygon_set_shape(RID p_occluder_polygon, const Vector<Vector2> &p_shape, bool p_closed) { @@ -1596,8 +1592,6 @@ bool RendererCanvasCull::free(RID p_rid) { canvas_owner.free(p_rid); - memdelete(canvas); - } else if (canvas_item_owner.owns(p_rid)) { Item *canvas_item = canvas_item_owner.getornull(p_rid); ERR_FAIL_COND_V(!canvas_item, true); @@ -1632,8 +1626,6 @@ bool RendererCanvasCull::free(RID p_rid) { canvas_item_owner.free(p_rid); - memdelete(canvas_item); - } else if (canvas_light_owner.owns(p_rid)) { RendererCanvasRender::Light *canvas_light = canvas_light_owner.getornull(p_rid); ERR_FAIL_COND_V(!canvas_light, true); @@ -1648,7 +1640,6 @@ bool RendererCanvasCull::free(RID p_rid) { RSG::canvas_render->free(canvas_light->light_internal); canvas_light_owner.free(p_rid); - memdelete(canvas_light); } else if (canvas_light_occluder_owner.owns(p_rid)) { RendererCanvasRender::LightOccluderInstance *occluder = canvas_light_occluder_owner.getornull(p_rid); @@ -1667,7 +1658,6 @@ bool RendererCanvasCull::free(RID p_rid) { } canvas_light_occluder_owner.free(p_rid); - memdelete(occluder); } else if (canvas_light_occluder_polygon_owner.owns(p_rid)) { LightOccluderPolygon *occluder_poly = canvas_light_occluder_polygon_owner.getornull(p_rid); @@ -1680,7 +1670,6 @@ bool RendererCanvasCull::free(RID p_rid) { } canvas_light_occluder_polygon_owner.free(p_rid); - memdelete(occluder_poly); } else { return false; } diff --git a/servers/rendering/renderer_canvas_cull.h b/servers/rendering/renderer_canvas_cull.h index a51b419613..79b5450d14 100644 --- a/servers/rendering/renderer_canvas_cull.h +++ b/servers/rendering/renderer_canvas_cull.h @@ -116,9 +116,9 @@ public: } }; - RID_PtrOwner<LightOccluderPolygon, true> canvas_light_occluder_polygon_owner; + RID_Owner<LightOccluderPolygon, true> canvas_light_occluder_polygon_owner; - RID_PtrOwner<RendererCanvasRender::LightOccluderInstance, true> canvas_light_occluder_owner; + RID_Owner<RendererCanvasRender::LightOccluderInstance, true> canvas_light_occluder_owner; struct Canvas : public RendererViewport::CanvasBase { Set<RID> viewports; @@ -163,9 +163,9 @@ public: } }; - mutable RID_PtrOwner<Canvas, true> canvas_owner; - RID_PtrOwner<Item, true> canvas_item_owner; - RID_PtrOwner<RendererCanvasRender::Light, true> canvas_light_owner; + mutable RID_Owner<Canvas, true> canvas_owner; + RID_Owner<Item, true> canvas_item_owner; + RID_Owner<RendererCanvasRender::Light, true> canvas_light_owner; bool disable_scale; bool sdf_used = false; diff --git a/servers/rendering/renderer_canvas_render.h b/servers/rendering/renderer_canvas_render.h index c10b9db035..8afe9ef410 100644 --- a/servers/rendering/renderer_canvas_render.h +++ b/servers/rendering/renderer_canvas_render.h @@ -608,8 +608,6 @@ public: virtual void occluder_polygon_set_cull_mode(RID p_occluder, RS::CanvasOccluderPolygonCullMode p_mode) = 0; virtual void set_shadow_texture_size(int p_size) = 0; - virtual void draw_window_margins(int *p_margins, RID *p_margin_textures) = 0; - virtual bool free(RID p_rid) = 0; virtual void update() = 0; diff --git a/servers/rendering/renderer_compositor.h b/servers/rendering/renderer_compositor.h index eabdebf4b3..5fe9cdffba 100644 --- a/servers/rendering/renderer_compositor.h +++ b/servers/rendering/renderer_compositor.h @@ -36,10 +36,9 @@ #include "core/templates/self_list.h" #include "servers/rendering/renderer_canvas_render.h" #include "servers/rendering/renderer_scene.h" -#include "servers/rendering/renderer_scene_render.h" #include "servers/rendering/renderer_storage.h" #include "servers/rendering_server.h" - +class RendererSceneRender; struct BlitToScreen { RID render_target; Rect2i rect; diff --git a/servers/rendering/renderer_rd/effects_rd.cpp b/servers/rendering/renderer_rd/effects_rd.cpp index 4fd5520e56..5cf8895c8e 100644 --- a/servers/rendering/renderer_rd/effects_rd.cpp +++ b/servers/rendering/renderer_rd/effects_rd.cpp @@ -37,21 +37,6 @@ #include "servers/rendering/renderer_rd/renderer_compositor_rd.h" #include "thirdparty/misc/cubemap_coeffs.h" -static _FORCE_INLINE_ void store_transform_3x3(const Basis &p_basis, float *p_array) { - p_array[0] = p_basis.elements[0][0]; - p_array[1] = p_basis.elements[1][0]; - p_array[2] = p_basis.elements[2][0]; - p_array[3] = 0; - p_array[4] = p_basis.elements[0][1]; - p_array[5] = p_basis.elements[1][1]; - p_array[6] = p_basis.elements[2][1]; - p_array[7] = 0; - p_array[8] = p_basis.elements[0][2]; - p_array[9] = p_basis.elements[1][2]; - p_array[10] = p_basis.elements[2][2]; - p_array[11] = 0; -} - static _FORCE_INLINE_ void store_camera(const CameraMatrix &p_mtx, float *p_array) { for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { @@ -518,11 +503,10 @@ void EffectsRD::screen_space_reflection(RID p_diffuse, RID p_normal_roughness, R if (p_roughness_quality != RS::ENV_SSR_ROUGNESS_QUALITY_DISABLED) { RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_image_pair(p_output, p_blur_radius), 1); - RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture_pair(p_metallic, p_normal_roughness), 3); } else { RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_uniform_set_from_image(p_output), 1); - RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture(p_metallic), 3); } + RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture(p_metallic), 3); RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_uniform_set_from_image(p_scale_normal), 2); RD::get_singleton()->compute_list_dispatch_threads(compute_list, p_screen_size.width, p_screen_size.height, 1); @@ -1371,45 +1355,6 @@ void EffectsRD::cubemap_filter(RID p_source_cubemap, Vector<RID> p_dest_cubemap, RD::get_singleton()->compute_list_end(); } -void EffectsRD::render_sky(RD::DrawListID p_list, float p_time, RID p_fb, RID p_samplers, RID p_fog, PipelineCacheRD *p_pipeline, RID p_uniform_set, RID p_texture_set, uint32_t p_view_count, const CameraMatrix *p_projections, const Basis &p_orientation, float p_multiplier, const Vector3 &p_position) { - SkyPushConstant sky_push_constant; - - memset(&sky_push_constant, 0, sizeof(SkyPushConstant)); - - for (uint32_t v = 0; v < p_view_count; v++) { - // We only need key components of our projection matrix - sky_push_constant.projections[v][0] = p_projections[v].matrix[2][0]; - sky_push_constant.projections[v][1] = p_projections[v].matrix[0][0]; - sky_push_constant.projections[v][2] = p_projections[v].matrix[2][1]; - sky_push_constant.projections[v][3] = p_projections[v].matrix[1][1]; - } - sky_push_constant.position[0] = p_position.x; - sky_push_constant.position[1] = p_position.y; - sky_push_constant.position[2] = p_position.z; - sky_push_constant.multiplier = p_multiplier; - sky_push_constant.time = p_time; - store_transform_3x3(p_orientation, sky_push_constant.orientation); - - RenderingDevice::FramebufferFormatID fb_format = RD::get_singleton()->framebuffer_get_format(p_fb); - - RD::DrawListID draw_list = p_list; - - RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, p_pipeline->get_render_pipeline(RD::INVALID_ID, fb_format)); - - RD::get_singleton()->draw_list_bind_uniform_set(draw_list, p_samplers, 0); - if (p_uniform_set.is_valid()) { //material may not have uniform set - RD::get_singleton()->draw_list_bind_uniform_set(draw_list, p_uniform_set, 1); - } - RD::get_singleton()->draw_list_bind_uniform_set(draw_list, p_texture_set, 2); - RD::get_singleton()->draw_list_bind_uniform_set(draw_list, p_fog, 3); - - RD::get_singleton()->draw_list_bind_index_array(draw_list, index_array); - - RD::get_singleton()->draw_list_set_push_constant(draw_list, &sky_push_constant, sizeof(SkyPushConstant)); - - RD::get_singleton()->draw_list_draw(draw_list, true); -} - void EffectsRD::resolve_gi(RID p_source_depth, RID p_source_normal_roughness, RID p_source_voxel_gi, RID p_dest_depth, RID p_dest_normal_roughness, RID p_dest_voxel_gi, Vector2i p_screen_size, int p_samples, uint32_t p_barrier) { ResolvePushConstant push_constant; push_constant.screen_size[0] = p_screen_size.x; @@ -1432,6 +1377,24 @@ void EffectsRD::resolve_gi(RID p_source_depth, RID p_source_normal_roughness, RI RD::get_singleton()->compute_list_end(p_barrier); } +void EffectsRD::resolve_depth(RID p_source_depth, RID p_dest_depth, Vector2i p_screen_size, int p_samples, uint32_t p_barrier) { + ResolvePushConstant push_constant; + push_constant.screen_size[0] = p_screen_size.x; + push_constant.screen_size[1] = p_screen_size.y; + push_constant.samples = p_samples; + + RD::ComputeListID compute_list = RD::get_singleton()->compute_list_begin(); + RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, resolve.pipelines[RESOLVE_MODE_DEPTH]); + RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture(p_source_depth), 0); + RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_uniform_set_from_image(p_dest_depth), 1); + + RD::get_singleton()->compute_list_set_push_constant(compute_list, &push_constant, sizeof(ResolvePushConstant)); + + RD::get_singleton()->compute_list_dispatch_threads(compute_list, p_screen_size.x, p_screen_size.y, 1); + + RD::get_singleton()->compute_list_end(p_barrier); +} + void EffectsRD::sort_buffer(RID p_uniform_set, int p_size) { Sort::PushConstant push_constant; push_constant.total_elements = p_size; @@ -1934,6 +1897,7 @@ EffectsRD::EffectsRD() { Vector<String> resolve_modes; resolve_modes.push_back("\n#define MODE_RESOLVE_GI\n"); resolve_modes.push_back("\n#define MODE_RESOLVE_GI\n#define VOXEL_GI_RESOLVE\n"); + resolve_modes.push_back("\n#define MODE_RESOLVE_DEPTH\n"); resolve.shader.initialize(resolve_modes); diff --git a/servers/rendering/renderer_rd/effects_rd.h b/servers/rendering/renderer_rd/effects_rd.h index 8b31ffbbd0..33d32f0c57 100644 --- a/servers/rendering/renderer_rd/effects_rd.h +++ b/servers/rendering/renderer_rd/effects_rd.h @@ -456,15 +456,6 @@ class EffectsRD { } filter; - struct SkyPushConstant { - float orientation[12]; // 48 - 48 - float projections[RendererSceneRender::MAX_RENDER_VIEWS][4]; // 2 x 16 - 64, if we ever need more then 3 we should consider adding this to a set. - float position[3]; // 12 - 92 - float multiplier; // 4 - 96 - float time; // 4 - 100 - float pad[3]; // 12 - 112 - }; - enum SpecularMergeMode { SPECULAR_MERGE_ADD, SPECULAR_MERGE_SSR, @@ -590,6 +581,7 @@ class EffectsRD { enum ResolveMode { RESOLVE_MODE_GI, RESOLVE_MODE_GI_VOXEL_GI, + RESOLVE_MODE_DEPTH, RESOLVE_MODE_MAX }; @@ -749,13 +741,13 @@ public: void roughness_limit(RID p_source_normal, RID p_roughness, const Size2i &p_size, float p_curve); void cubemap_downsample(RID p_source_cubemap, RID p_dest_cubemap, const Size2i &p_size); void cubemap_filter(RID p_source_cubemap, Vector<RID> p_dest_cubemap, bool p_use_array); - void render_sky(RD::DrawListID p_list, float p_time, RID p_fb, RID p_samplers, RID p_fog, PipelineCacheRD *p_pipeline, RID p_uniform_set, RID p_texture_set, uint32_t p_view_count, const CameraMatrix *p_projections, const Basis &p_orientation, float p_multiplier, const Vector3 &p_position); void screen_space_reflection(RID p_diffuse, RID p_normal_roughness, RS::EnvironmentSSRRoughnessQuality p_roughness_quality, RID p_blur_radius, RID p_blur_radius2, RID p_metallic, const Color &p_metallic_mask, RID p_depth, RID p_scale_depth, RID p_scale_normal, RID p_output, RID p_output_blur, const Size2i &p_screen_size, int p_max_steps, float p_fade_in, float p_fade_out, float p_tolerance, const CameraMatrix &p_camera); void merge_specular(RID p_dest_framebuffer, RID p_specular, RID p_base, RID p_reflection); void sub_surface_scattering(RID p_diffuse, RID p_diffuse2, RID p_depth, const CameraMatrix &p_camera, const Size2i &p_screen_size, float p_scale, float p_depth_scale, RS::SubSurfaceScatteringQuality p_quality); void resolve_gi(RID p_source_depth, RID p_source_normal_roughness, RID p_source_voxel_gi, RID p_dest_depth, RID p_dest_normal_roughness, RID p_dest_voxel_gi, Vector2i p_screen_size, int p_samples, uint32_t p_barrier = RD::BARRIER_MASK_ALL); + void resolve_depth(RID p_source_depth, RID p_dest_depth, Vector2i p_screen_size, int p_samples, uint32_t p_barrier = RD::BARRIER_MASK_ALL); void sort_buffer(RID p_uniform_set, int p_size); diff --git a/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp b/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp index 1653453c5c..22bfd03115 100644 --- a/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp +++ b/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp @@ -345,8 +345,20 @@ void RenderForwardClustered::_render_list_template(RenderingDevice::DrawListID p mesh_surface = surf->surface_shadow; } else { - material_uniform_set = surf->material_uniform_set; - shader = surf->shader; +#ifdef DEBUG_ENABLED + if (unlikely(get_debug_draw_mode() == RS::VIEWPORT_DEBUG_DRAW_LIGHTING)) { + material_uniform_set = scene_shader.default_material_uniform_set; + shader = scene_shader.default_material_shader_ptr; + } else if (unlikely(get_debug_draw_mode() == RS::VIEWPORT_DEBUG_DRAW_OVERDRAW)) { + material_uniform_set = scene_shader.overdraw_material_uniform_set; + shader = scene_shader.overdraw_material_shader_ptr; + } else { +#endif + material_uniform_set = surf->material_uniform_set; + shader = surf->shader; +#ifdef DEBUG_ENABLED + } +#endif mesh_surface = surf->surface; } @@ -801,13 +813,16 @@ void RenderForwardClustered::_update_instance_data_buffer(RenderListType p_rende RD::get_singleton()->buffer_update(scene_state.instance_buffer[p_render_list], 0, sizeof(SceneState::InstanceData) * scene_state.instance_data[p_render_list].size(), scene_state.instance_data[p_render_list].ptr(), RD::BARRIER_MASK_RASTER); } } -void RenderForwardClustered::_fill_instance_data(RenderListType p_render_list, uint32_t p_offset, int32_t p_max_elements, bool p_update_buffer) { +void RenderForwardClustered::_fill_instance_data(RenderListType p_render_list, int *p_render_info, uint32_t p_offset, int32_t p_max_elements, bool p_update_buffer) { RenderList *rl = &render_list[p_render_list]; uint32_t element_total = p_max_elements >= 0 ? uint32_t(p_max_elements) : rl->elements.size(); scene_state.instance_data[p_render_list].resize(p_offset + element_total); rl->element_info.resize(p_offset + element_total); + if (p_render_info) { + p_render_info[RS::VIEWPORT_RENDER_INFO_OBJECTS_IN_FRAME] += element_total; + } uint32_t repeats = 0; GeometryInstanceSurfaceDataCache *prev_surface = nullptr; for (uint32_t i = 0; i < element_total; i++) { @@ -843,6 +858,9 @@ void RenderForwardClustered::_fill_instance_data(RenderListType p_render_list, u } } repeats = 1; + if (p_render_info) { + p_render_info[RS::VIEWPORT_RENDER_INFO_DRAW_CALLS_IN_FRAME]++; + } } RenderElementInfo &element_info = rl->element_info[p_offset + i]; @@ -869,6 +887,11 @@ void RenderForwardClustered::_fill_instance_data(RenderListType p_render_list, u } } +_FORCE_INLINE_ static uint32_t _indices_to_primitives(RS::PrimitiveType p_primitive, uint32_t p_indices) { + static const uint32_t divisor[RS::PRIMITIVE_MAX] = { 1, 2, 1, 3, 1 }; + static const uint32_t subtractor[RS::PRIMITIVE_MAX] = { 0, 0, 1, 0, 1 }; + return (p_indices - subtractor[p_primitive]) / divisor[p_primitive]; +} void RenderForwardClustered::_fill_render_list(RenderListType p_render_list, const RenderDataRD *p_render_data, PassMode p_pass_mode, bool p_using_sdfgi, bool p_using_opaque_gi, bool p_append) { if (p_render_list == RENDER_LIST_OPAQUE) { scene_state.used_sss = false; @@ -903,6 +926,9 @@ void RenderForwardClustered::_fill_render_list(RenderListType p_render_list, con uint32_t flags = inst->base_flags; //fill flags if appropriate + if (inst->non_uniform_scale) { + flags |= INSTANCE_DATA_FLAGS_NON_UNIFORM_SCALE; + } bool uses_lightmap = false; bool uses_gi = false; @@ -1008,17 +1034,41 @@ void RenderForwardClustered::_fill_render_list(RenderListType p_render_list, con distance = -distance_max; } - surf->sort.lod_index = storage->mesh_surface_get_lod(surf->surface, inst->lod_model_scale * inst->lod_bias, distance * p_render_data->lod_distance_multiplier, p_render_data->screen_lod_threshold); + uint32_t indices; + surf->sort.lod_index = storage->mesh_surface_get_lod(surf->surface, inst->lod_model_scale * inst->lod_bias, distance * p_render_data->lod_distance_multiplier, p_render_data->screen_lod_threshold, &indices); + if (p_render_data->render_info) { + indices = _indices_to_primitives(surf->primitive, indices); + if (p_render_list == RENDER_LIST_OPAQUE) { //opaque + p_render_data->render_info->info[RS::VIEWPORT_RENDER_INFO_TYPE_VISIBLE][RS::VIEWPORT_RENDER_INFO_PRIMITIVES_IN_FRAME] += indices; + } else if (p_render_list == RENDER_LIST_SECONDARY) { //shadow + p_render_data->render_info->info[RS::VIEWPORT_RENDER_INFO_TYPE_SHADOW][RS::VIEWPORT_RENDER_INFO_PRIMITIVES_IN_FRAME] += indices; + } + } } else { surf->sort.lod_index = 0; + if (p_render_data->render_info) { + uint32_t to_draw = storage->mesh_surface_get_vertices_drawn_count(surf->surface); + to_draw = _indices_to_primitives(surf->primitive, to_draw); + to_draw *= inst->instance_count; + if (p_render_list == RENDER_LIST_OPAQUE) { //opaque + p_render_data->render_info->info[RS::VIEWPORT_RENDER_INFO_TYPE_VISIBLE][RS::VIEWPORT_RENDER_INFO_PRIMITIVES_IN_FRAME] += storage->mesh_surface_get_vertices_drawn_count(surf->surface); + } else if (p_render_list == RENDER_LIST_SECONDARY) { //shadow + p_render_data->render_info->info[RS::VIEWPORT_RENDER_INFO_TYPE_SHADOW][RS::VIEWPORT_RENDER_INFO_PRIMITIVES_IN_FRAME] += storage->mesh_surface_get_vertices_drawn_count(surf->surface); + } + } } // ADD Element if (p_pass_mode == PASS_MODE_COLOR) { - if (surf->flags & (GeometryInstanceSurfaceDataCache::FLAG_PASS_DEPTH | GeometryInstanceSurfaceDataCache::FLAG_PASS_OPAQUE)) { +#ifdef DEBUG_ENABLED + bool force_alpha = unlikely(get_debug_draw_mode() == RS::VIEWPORT_DEBUG_DRAW_OVERDRAW); +#else + bool force_alpha = false; +#endif + if (!force_alpha && (surf->flags & (GeometryInstanceSurfaceDataCache::FLAG_PASS_DEPTH | GeometryInstanceSurfaceDataCache::FLAG_PASS_OPAQUE))) { rl->add_element(surf); } - if (surf->flags & GeometryInstanceSurfaceDataCache::FLAG_PASS_ALPHA) { + if (force_alpha || (surf->flags & GeometryInstanceSurfaceDataCache::FLAG_PASS_ALPHA)) { render_list[RENDER_LIST_ALPHA].add_element(surf); if (uses_gi) { surf->sort.uses_forward_gi = 1; @@ -1100,6 +1150,7 @@ void RenderForwardClustered::_render_scene(RenderDataRD *p_render_data, const Co render_buffer = (RenderBufferDataForwardClustered *)render_buffers_get_data(p_render_data->render_buffers); } RendererSceneEnvironmentRD *env = get_environment(p_render_data->environment); + static const int texture_multisamples[RS::VIEWPORT_MSAA_MAX] = { 1, 2, 4, 8, 16 }; //first of all, make a new render pass //fill up ubo @@ -1209,8 +1260,8 @@ void RenderForwardClustered::_render_scene(RenderDataRD *p_render_data, const Co _fill_render_list(RENDER_LIST_OPAQUE, p_render_data, PASS_MODE_COLOR, using_sdfgi, using_sdfgi || using_voxelgi); render_list[RENDER_LIST_OPAQUE].sort_by_key(); - render_list[RENDER_LIST_ALPHA].sort_by_depth(); - _fill_instance_data(RENDER_LIST_OPAQUE); + render_list[RENDER_LIST_ALPHA].sort_by_reverse_depth_and_priority(); + _fill_instance_data(RENDER_LIST_OPAQUE, p_render_data->render_info ? p_render_data->render_info->info[RS::VIEWPORT_RENDER_INFO_TYPE_VISIBLE] : (int *)nullptr); _fill_instance_data(RENDER_LIST_ALPHA); RD::get_singleton()->draw_command_end_label(); @@ -1340,10 +1391,9 @@ void RenderForwardClustered::_render_scene(RenderDataRD *p_render_data, const Co if (needs_pre_resolve) { RD::get_singleton()->barrier(RD::BARRIER_MASK_RASTER, RD::BARRIER_MASK_COMPUTE); } - static int texture_samples[RS::VIEWPORT_MSAA_MAX] = { 1, 2, 4, 8, 16 }; - storage->get_effects()->resolve_gi(render_buffer->depth_msaa, render_buffer->normal_roughness_buffer_msaa, using_voxelgi ? render_buffer->voxelgi_buffer_msaa : RID(), render_buffer->depth, render_buffer->normal_roughness_buffer, using_voxelgi ? render_buffer->voxelgi_buffer : RID(), Vector2i(render_buffer->width, render_buffer->height), texture_samples[render_buffer->msaa]); + storage->get_effects()->resolve_gi(render_buffer->depth_msaa, render_buffer->normal_roughness_buffer_msaa, using_voxelgi ? render_buffer->voxelgi_buffer_msaa : RID(), render_buffer->depth, render_buffer->normal_roughness_buffer, using_voxelgi ? render_buffer->voxelgi_buffer : RID(), Vector2i(render_buffer->width, render_buffer->height), texture_multisamples[render_buffer->msaa]); } else if (finish_depth) { - RD::get_singleton()->texture_resolve_multisample(render_buffer->depth_msaa, render_buffer->depth); + storage->get_effects()->resolve_depth(render_buffer->depth_msaa, render_buffer->depth, Vector2i(render_buffer->width, render_buffer->height), texture_multisamples[render_buffer->msaa]); } RD::get_singleton()->draw_command_end_label(); } @@ -1447,7 +1497,7 @@ void RenderForwardClustered::_render_scene(RenderDataRD *p_render_data, const Co } if (render_buffer && !can_continue_depth && render_buffer->msaa != RS::VIEWPORT_MSAA_DISABLED) { - RD::get_singleton()->texture_resolve_multisample(render_buffer->depth_msaa, render_buffer->depth); + storage->get_effects()->resolve_depth(render_buffer->depth_msaa, render_buffer->depth, Vector2i(render_buffer->width, render_buffer->height), texture_multisamples[render_buffer->msaa]); } if (using_separate_specular) { @@ -1503,7 +1553,7 @@ void RenderForwardClustered::_render_shadow_begin() { scene_state.instance_data[RENDER_LIST_SECONDARY].clear(); } -void RenderForwardClustered::_render_shadow_append(RID p_framebuffer, const PagedArray<GeometryInstance *> &p_instances, const CameraMatrix &p_projection, const Transform3D &p_transform, float p_zfar, float p_bias, float p_normal_bias, bool p_use_dp, bool p_use_dp_flip, bool p_use_pancake, const Plane &p_camera_plane, float p_lod_distance_multiplier, float p_screen_lod_threshold, const Rect2i &p_rect, bool p_flip_y, bool p_clear_region, bool p_begin, bool p_end) { +void RenderForwardClustered::_render_shadow_append(RID p_framebuffer, const PagedArray<GeometryInstance *> &p_instances, const CameraMatrix &p_projection, const Transform3D &p_transform, float p_zfar, float p_bias, float p_normal_bias, bool p_use_dp, bool p_use_dp_flip, bool p_use_pancake, const Plane &p_camera_plane, float p_lod_distance_multiplier, float p_screen_lod_threshold, const Rect2i &p_rect, bool p_flip_y, bool p_clear_region, bool p_begin, bool p_end, RendererScene::RenderInfo *p_render_info) { uint32_t shadow_pass_index = scene_state.shadow_passes.size(); SceneState::ShadowPass shadow_pass; @@ -1518,6 +1568,7 @@ void RenderForwardClustered::_render_shadow_append(RID p_framebuffer, const Page render_data.instances = &p_instances; render_data.lod_camera_plane = p_camera_plane; render_data.lod_distance_multiplier = p_lod_distance_multiplier; + render_data.render_info = p_render_info; scene_state.ubo.dual_paraboloid_side = p_use_dp_flip ? -1 : 1; @@ -1535,7 +1586,7 @@ void RenderForwardClustered::_render_shadow_append(RID p_framebuffer, const Page _fill_render_list(RENDER_LIST_SECONDARY, &render_data, pass_mode, false, false, true); uint32_t render_list_size = render_list[RENDER_LIST_SECONDARY].elements.size() - render_list_from; render_list[RENDER_LIST_SECONDARY].sort_by_key_range(render_list_from, render_list_size); - _fill_instance_data(RENDER_LIST_SECONDARY, render_list_from, render_list_size, false); + _fill_instance_data(RENDER_LIST_SECONDARY, p_render_info ? p_render_info->info[RS::VIEWPORT_RENDER_INFO_TYPE_SHADOW] : (int *)nullptr, render_list_from, render_list_size, false); { //regular forward for now @@ -2594,6 +2645,8 @@ void RenderForwardClustered::_geometry_instance_update(GeometryInstance *p_geome //Fill push constant + ginstance->base_flags = 0; + bool store_transform = true; if (ginstance->data->base_type == RS::INSTANCE_MULTIMESH) { @@ -2737,6 +2790,7 @@ void RenderForwardClustered::geometry_instance_set_transform(GeometryInstance *p float max_scale = MAX(model_scale_vec.x, MAX(model_scale_vec.y, model_scale_vec.z)); float min_scale = MIN(model_scale_vec.x, MIN(model_scale_vec.y, model_scale_vec.z)); + ginstance->non_uniform_scale = max_scale >= 0.0 && (min_scale / max_scale) < 0.9; ginstance->lod_model_scale = max_scale; diff --git a/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.h b/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.h index 579c8de05e..750c0167e7 100644 --- a/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.h +++ b/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.h @@ -108,7 +108,7 @@ class RenderForwardClustered : public RendererSceneRenderRD { ~RenderBufferDataForwardClustered(); }; - virtual RenderBufferData *_create_render_buffer_data(); + virtual RenderBufferData *_create_render_buffer_data() override; void _allocate_normal_roughness_texture(RenderBufferDataForwardClustered *rb); RID render_base_uniform_set; @@ -117,8 +117,8 @@ class RenderForwardClustered : public RendererSceneRenderRD { uint64_t lightmap_texture_array_version = 0xFFFFFFFF; - virtual void _base_uniforms_changed(); - virtual RID _render_buffers_get_normal_texture(RID p_render_buffers); + virtual void _base_uniforms_changed() override; + virtual RID _render_buffers_get_normal_texture(RID p_render_buffers) override; void _update_render_base_uniform_set(); RID _setup_sdfgi_render_pass_uniform_set(RID p_albedo_texture, RID p_emission_texture, RID p_emission_aniso_texture, RID p_geom_facing_texture); @@ -184,6 +184,7 @@ class RenderForwardClustered : public RendererSceneRenderRD { }; enum { + INSTANCE_DATA_FLAGS_NON_UNIFORM_SCALE = 1 << 5, INSTANCE_DATA_FLAG_USE_GI_BUFFERS = 1 << 6, INSTANCE_DATA_FLAG_USE_SDFGI = 1 << 7, INSTANCE_DATA_FLAG_USE_LIGHTMAP_CAPTURE = 1 << 8, @@ -196,7 +197,6 @@ class RenderForwardClustered : public RendererSceneRenderRD { INSTANCE_DATA_FLAG_MULTIMESH_HAS_CUSTOM_DATA = 1 << 15, INSTANCE_DATA_FLAGS_PARTICLE_TRAIL_SHIFT = 16, INSTANCE_DATA_FLAGS_PARTICLE_TRAIL_MASK = 0xFF, - INSTANCE_DATA_FLAGS_NON_UNIFORM_SCALE = 1 << 24, }; struct SceneState { @@ -371,7 +371,7 @@ class RenderForwardClustered : public RendererSceneRenderRD { uint32_t render_list_thread_threshold = 500; void _update_instance_data_buffer(RenderListType p_render_list); - void _fill_instance_data(RenderListType p_render_list, uint32_t p_offset = 0, int32_t p_max_elements = -1, bool p_update_buffer = true); + void _fill_instance_data(RenderListType p_render_list, int *p_render_info = nullptr, uint32_t p_offset = 0, int32_t p_max_elements = -1, bool p_update_buffer = true); void _fill_render_list(RenderListType p_render_list, const RenderDataRD *p_render_data, PassMode p_pass_mode, bool p_using_sdfgi = false, bool p_using_opaque_gi = false, bool p_append = false); Map<Size2i, RID> sdfgi_framebuffer_size_cache; @@ -551,7 +551,7 @@ class RenderForwardClustered : public RendererSceneRenderRD { } }; - void sort_by_reverse_depth_and_priority(bool p_alpha) { //used for alpha + void sort_by_reverse_depth_and_priority() { //used for alpha SortArray<GeometryInstanceSurfaceDataCache *, SortByReverseDepthAndPriority> sorter; sorter.sort(elements.ptr(), elements.size()); @@ -565,46 +565,46 @@ class RenderForwardClustered : public RendererSceneRenderRD { RenderList render_list[RENDER_LIST_MAX]; protected: - virtual void _render_scene(RenderDataRD *p_render_data, const Color &p_default_bg_color); + virtual void _render_scene(RenderDataRD *p_render_data, const Color &p_default_bg_color) override; - virtual void _render_shadow_begin(); - virtual void _render_shadow_append(RID p_framebuffer, const PagedArray<GeometryInstance *> &p_instances, const CameraMatrix &p_projection, const Transform3D &p_transform, float p_zfar, float p_bias, float p_normal_bias, bool p_use_dp, bool p_use_dp_flip, bool p_use_pancake, const Plane &p_camera_plane = Plane(), float p_lod_distance_multiplier = 0.0, float p_screen_lod_threshold = 0.0, const Rect2i &p_rect = Rect2i(), bool p_flip_y = false, bool p_clear_region = true, bool p_begin = true, bool p_end = true); - virtual void _render_shadow_process(); - virtual void _render_shadow_end(uint32_t p_barrier = RD::BARRIER_MASK_ALL); + virtual void _render_shadow_begin() override; + virtual void _render_shadow_append(RID p_framebuffer, const PagedArray<GeometryInstance *> &p_instances, const CameraMatrix &p_projection, const Transform3D &p_transform, float p_zfar, float p_bias, float p_normal_bias, bool p_use_dp, bool p_use_dp_flip, bool p_use_pancake, const Plane &p_camera_plane = Plane(), float p_lod_distance_multiplier = 0.0, float p_screen_lod_threshold = 0.0, const Rect2i &p_rect = Rect2i(), bool p_flip_y = false, bool p_clear_region = true, bool p_begin = true, bool p_end = true, RendererScene::RenderInfo *p_render_info = nullptr) override; + virtual void _render_shadow_process() override; + virtual void _render_shadow_end(uint32_t p_barrier = RD::BARRIER_MASK_ALL) override; - virtual void _render_material(const Transform3D &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, const PagedArray<GeometryInstance *> &p_instances, RID p_framebuffer, const Rect2i &p_region); - virtual void _render_uv2(const PagedArray<GeometryInstance *> &p_instances, RID p_framebuffer, const Rect2i &p_region); - virtual void _render_sdfgi(RID p_render_buffers, const Vector3i &p_from, const Vector3i &p_size, const AABB &p_bounds, const PagedArray<GeometryInstance *> &p_instances, const RID &p_albedo_texture, const RID &p_emission_texture, const RID &p_emission_aniso_texture, const RID &p_geom_facing_texture); - virtual void _render_particle_collider_heightfield(RID p_fb, const Transform3D &p_cam_transform, const CameraMatrix &p_cam_projection, const PagedArray<GeometryInstance *> &p_instances); + virtual void _render_material(const Transform3D &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, const PagedArray<GeometryInstance *> &p_instances, RID p_framebuffer, const Rect2i &p_region) override; + virtual void _render_uv2(const PagedArray<GeometryInstance *> &p_instances, RID p_framebuffer, const Rect2i &p_region) override; + virtual void _render_sdfgi(RID p_render_buffers, const Vector3i &p_from, const Vector3i &p_size, const AABB &p_bounds, const PagedArray<GeometryInstance *> &p_instances, const RID &p_albedo_texture, const RID &p_emission_texture, const RID &p_emission_aniso_texture, const RID &p_geom_facing_texture) override; + virtual void _render_particle_collider_heightfield(RID p_fb, const Transform3D &p_cam_transform, const CameraMatrix &p_cam_projection, const PagedArray<GeometryInstance *> &p_instances) override; public: - virtual GeometryInstance *geometry_instance_create(RID p_base); - virtual void geometry_instance_set_skeleton(GeometryInstance *p_geometry_instance, RID p_skeleton); - virtual void geometry_instance_set_material_override(GeometryInstance *p_geometry_instance, RID p_override); - virtual void geometry_instance_set_surface_materials(GeometryInstance *p_geometry_instance, const Vector<RID> &p_materials); - virtual void geometry_instance_set_mesh_instance(GeometryInstance *p_geometry_instance, RID p_mesh_instance); - virtual void geometry_instance_set_transform(GeometryInstance *p_geometry_instance, const Transform3D &p_transform, const AABB &p_aabb, const AABB &p_transformed_aabb); - virtual void geometry_instance_set_layer_mask(GeometryInstance *p_geometry_instance, uint32_t p_layer_mask); - virtual void geometry_instance_set_lod_bias(GeometryInstance *p_geometry_instance, float p_lod_bias); - virtual void geometry_instance_set_use_baked_light(GeometryInstance *p_geometry_instance, bool p_enable); - virtual void geometry_instance_set_use_dynamic_gi(GeometryInstance *p_geometry_instance, bool p_enable); - virtual void geometry_instance_set_use_lightmap(GeometryInstance *p_geometry_instance, RID p_lightmap_instance, const Rect2 &p_lightmap_uv_scale, int p_lightmap_slice_index); - virtual void geometry_instance_set_lightmap_capture(GeometryInstance *p_geometry_instance, const Color *p_sh9); - virtual void geometry_instance_set_instance_shader_parameters_offset(GeometryInstance *p_geometry_instance, int32_t p_offset); - virtual void geometry_instance_set_cast_double_sided_shadows(GeometryInstance *p_geometry_instance, bool p_enable); - - virtual Transform3D geometry_instance_get_transform(GeometryInstance *p_instance); - virtual AABB geometry_instance_get_aabb(GeometryInstance *p_instance); - - virtual void geometry_instance_free(GeometryInstance *p_geometry_instance); - - virtual uint32_t geometry_instance_get_pair_mask(); - virtual void geometry_instance_pair_light_instances(GeometryInstance *p_geometry_instance, const RID *p_light_instances, uint32_t p_light_instance_count); - virtual void geometry_instance_pair_reflection_probe_instances(GeometryInstance *p_geometry_instance, const RID *p_reflection_probe_instances, uint32_t p_reflection_probe_instance_count); - virtual void geometry_instance_pair_decal_instances(GeometryInstance *p_geometry_instance, const RID *p_decal_instances, uint32_t p_decal_instance_count); - virtual void geometry_instance_pair_voxel_gi_instances(GeometryInstance *p_geometry_instance, const RID *p_voxel_gi_instances, uint32_t p_voxel_gi_instance_count); - - virtual bool free(RID p_rid); + virtual GeometryInstance *geometry_instance_create(RID p_base) override; + virtual void geometry_instance_set_skeleton(GeometryInstance *p_geometry_instance, RID p_skeleton) override; + virtual void geometry_instance_set_material_override(GeometryInstance *p_geometry_instance, RID p_override) override; + virtual void geometry_instance_set_surface_materials(GeometryInstance *p_geometry_instance, const Vector<RID> &p_materials) override; + virtual void geometry_instance_set_mesh_instance(GeometryInstance *p_geometry_instance, RID p_mesh_instance) override; + virtual void geometry_instance_set_transform(GeometryInstance *p_geometry_instance, const Transform3D &p_transform, const AABB &p_aabb, const AABB &p_transformed_aabb) override; + virtual void geometry_instance_set_layer_mask(GeometryInstance *p_geometry_instance, uint32_t p_layer_mask) override; + virtual void geometry_instance_set_lod_bias(GeometryInstance *p_geometry_instance, float p_lod_bias) override; + virtual void geometry_instance_set_use_baked_light(GeometryInstance *p_geometry_instance, bool p_enable) override; + virtual void geometry_instance_set_use_dynamic_gi(GeometryInstance *p_geometry_instance, bool p_enable) override; + virtual void geometry_instance_set_use_lightmap(GeometryInstance *p_geometry_instance, RID p_lightmap_instance, const Rect2 &p_lightmap_uv_scale, int p_lightmap_slice_index) override; + virtual void geometry_instance_set_lightmap_capture(GeometryInstance *p_geometry_instance, const Color *p_sh9) override; + virtual void geometry_instance_set_instance_shader_parameters_offset(GeometryInstance *p_geometry_instance, int32_t p_offset) override; + virtual void geometry_instance_set_cast_double_sided_shadows(GeometryInstance *p_geometry_instance, bool p_enable) override; + + virtual Transform3D geometry_instance_get_transform(GeometryInstance *p_instance) override; + virtual AABB geometry_instance_get_aabb(GeometryInstance *p_instance) override; + + virtual void geometry_instance_free(GeometryInstance *p_geometry_instance) override; + + virtual uint32_t geometry_instance_get_pair_mask() override; + virtual void geometry_instance_pair_light_instances(GeometryInstance *p_geometry_instance, const RID *p_light_instances, uint32_t p_light_instance_count) override; + virtual void geometry_instance_pair_reflection_probe_instances(GeometryInstance *p_geometry_instance, const RID *p_reflection_probe_instances, uint32_t p_reflection_probe_instance_count) override; + virtual void geometry_instance_pair_decal_instances(GeometryInstance *p_geometry_instance, const RID *p_decal_instances, uint32_t p_decal_instance_count) override; + virtual void geometry_instance_pair_voxel_gi_instances(GeometryInstance *p_geometry_instance, const RID *p_voxel_gi_instances, uint32_t p_voxel_gi_instance_count) override; + + virtual bool free(RID p_rid) override; RenderForwardClustered(RendererStorageRD *p_storage); ~RenderForwardClustered(); diff --git a/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.cpp b/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.cpp index f125931df8..d39823a1a3 100644 --- a/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.cpp +++ b/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.cpp @@ -320,8 +320,6 @@ void SceneShaderForwardClustered::ShaderData::set_code(const String &p_code) { } else { //specular write blend_state = blend_state_opaque_specular; - depth_stencil.enable_depth_test = false; - depth_stencil.enable_depth_write = false; } } @@ -437,94 +435,14 @@ void SceneShaderForwardClustered::MaterialData::set_next_pass(RID p_pass) { next_pass = p_pass; } -void SceneShaderForwardClustered::MaterialData::update_parameters(const Map<StringName, Variant> &p_parameters, bool p_uniform_dirty, bool p_textures_dirty) { +bool SceneShaderForwardClustered::MaterialData::update_parameters(const Map<StringName, Variant> &p_parameters, bool p_uniform_dirty, bool p_textures_dirty) { SceneShaderForwardClustered *shader_singleton = (SceneShaderForwardClustered *)SceneShaderForwardClustered::singleton; - if ((uint32_t)ubo_data.size() != shader_data->ubo_size) { - p_uniform_dirty = true; - if (uniform_buffer.is_valid()) { - RD::get_singleton()->free(uniform_buffer); - uniform_buffer = RID(); - } - - ubo_data.resize(shader_data->ubo_size); - if (ubo_data.size()) { - uniform_buffer = RD::get_singleton()->uniform_buffer_create(ubo_data.size()); - memset(ubo_data.ptrw(), 0, ubo_data.size()); //clear - } - - //clear previous uniform set - if (uniform_set.is_valid() && RD::get_singleton()->uniform_set_is_valid(uniform_set)) { - RD::get_singleton()->free(uniform_set); - uniform_set = RID(); - } - } - - //check whether buffer changed - if (p_uniform_dirty && ubo_data.size()) { - update_uniform_buffer(shader_data->uniforms, shader_data->ubo_offsets.ptr(), p_parameters, ubo_data.ptrw(), ubo_data.size(), false); - RD::get_singleton()->buffer_update(uniform_buffer, 0, ubo_data.size(), ubo_data.ptrw(), RD::BARRIER_MASK_RASTER); - } - - uint32_t tex_uniform_count = shader_data->texture_uniforms.size(); - - if ((uint32_t)texture_cache.size() != tex_uniform_count) { - texture_cache.resize(tex_uniform_count); - p_textures_dirty = true; - - //clear previous uniform set - if (uniform_set.is_valid() && RD::get_singleton()->uniform_set_is_valid(uniform_set)) { - RD::get_singleton()->free(uniform_set); - uniform_set = RID(); - } - } - - if (p_textures_dirty && tex_uniform_count) { - update_textures(p_parameters, shader_data->default_texture_params, shader_data->texture_uniforms, texture_cache.ptrw(), true); - } - - if (shader_data->ubo_size == 0 && shader_data->texture_uniforms.size() == 0) { - // This material does not require an uniform set, so don't create it. - return; - } - - if (!p_textures_dirty && uniform_set.is_valid() && RD::get_singleton()->uniform_set_is_valid(uniform_set)) { - //no reason to update uniform set, only UBO (or nothing) was needed to update - return; - } - - Vector<RD::Uniform> uniforms; - - { - if (shader_data->ubo_size) { - RD::Uniform u; - u.uniform_type = RD::UNIFORM_TYPE_UNIFORM_BUFFER; - u.binding = 0; - u.ids.push_back(uniform_buffer); - uniforms.push_back(u); - } - - const RID *textures = texture_cache.ptrw(); - for (uint32_t i = 0; i < tex_uniform_count; i++) { - RD::Uniform u; - u.uniform_type = RD::UNIFORM_TYPE_TEXTURE; - u.binding = 1 + i; - u.ids.push_back(textures[i]); - uniforms.push_back(u); - } - } - - uniform_set = RD::get_singleton()->uniform_set_create(uniforms, shader_singleton->shader.version_get_shader(shader_data->version, 0), RenderForwardClustered::MATERIAL_UNIFORM_SET); + return update_parameters_uniform_set(p_parameters, p_uniform_dirty, p_textures_dirty, shader_data->uniforms, shader_data->ubo_offsets.ptr(), shader_data->texture_uniforms, shader_data->default_texture_params, shader_data->ubo_size, uniform_set, shader_singleton->shader.version_get_shader(shader_data->version, 0), RenderForwardClustered::MATERIAL_UNIFORM_SET, RD::BARRIER_MASK_RASTER); } SceneShaderForwardClustered::MaterialData::~MaterialData() { - if (uniform_set.is_valid() && RD::get_singleton()->uniform_set_is_valid(uniform_set)) { - RD::get_singleton()->free(uniform_set); - } - - if (uniform_buffer.is_valid()) { - RD::get_singleton()->free(uniform_buffer); - } + free_parameters_uniform_set(uniform_set); } RendererStorageRD::MaterialData *SceneShaderForwardClustered::_create_material_func(ShaderData *p_shader) { @@ -546,11 +464,9 @@ SceneShaderForwardClustered::~SceneShaderForwardClustered() { RD::get_singleton()->free(default_vec4_xform_buffer); RD::get_singleton()->free(shadow_sampler); - storage->free(wireframe_material_shader); storage->free(overdraw_material_shader); storage->free(default_shader); - storage->free(wireframe_material); storage->free(overdraw_material); storage->free(default_material); } @@ -633,7 +549,6 @@ void SceneShaderForwardClustered::init(RendererStorageRD *p_storage, const Strin actions.renames["SSS_STRENGTH"] = "sss_strength"; actions.renames["SSS_TRANSMITTANCE_COLOR"] = "transmittance_color"; actions.renames["SSS_TRANSMITTANCE_DEPTH"] = "transmittance_depth"; - actions.renames["SSS_TRANSMITTANCE_CURVE"] = "transmittance_curve"; actions.renames["SSS_TRANSMITTANCE_BOOST"] = "transmittance_boost"; actions.renames["BACKLIGHT"] = "backlight"; actions.renames["AO"] = "ao"; @@ -775,22 +690,23 @@ void SceneShaderForwardClustered::init(RendererStorageRD *p_storage, const Strin MaterialData *md = (MaterialData *)storage->material_get_data(default_material, RendererStorageRD::SHADER_TYPE_3D); default_shader_rd = shader.version_get_shader(md->shader_data->version, SHADER_VERSION_COLOR_PASS); default_shader_sdfgi_rd = shader.version_get_shader(md->shader_data->version, SHADER_VERSION_DEPTH_PASS_WITH_SDF); + + default_material_shader_ptr = md->shader_data; + default_material_uniform_set = md->uniform_set; } { overdraw_material_shader = storage->shader_allocate(); storage->shader_initialize(overdraw_material_shader); - storage->shader_set_code(overdraw_material_shader, "shader_type spatial;\nrender_mode blend_add,unshaded;\n void fragment() { ALBEDO=vec3(0.4,0.8,0.8); ALPHA=0.2; }"); + // Use relatively low opacity so that more "layers" of overlapping objects can be distinguished. + storage->shader_set_code(overdraw_material_shader, "shader_type spatial;\nrender_mode blend_add,unshaded;\n void fragment() { ALBEDO=vec3(0.4,0.8,0.8); ALPHA=0.1; }"); overdraw_material = storage->material_allocate(); storage->material_initialize(overdraw_material); storage->material_set_shader(overdraw_material, overdraw_material_shader); - wireframe_material_shader = storage->shader_allocate(); - storage->shader_initialize(wireframe_material_shader); - storage->shader_set_code(wireframe_material_shader, "shader_type spatial;\nrender_mode wireframe,unshaded;\n void fragment() { ALBEDO=vec3(0.0,0.0,0.0); }"); - wireframe_material = storage->material_allocate(); - storage->material_initialize(wireframe_material); - storage->material_set_shader(wireframe_material, wireframe_material_shader); + MaterialData *md = (MaterialData *)storage->material_get_data(overdraw_material, RendererStorageRD::SHADER_TYPE_3D); + overdraw_material_shader_ptr = md->shader_data; + overdraw_material_uniform_set = md->uniform_set; } { diff --git a/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.h b/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.h index 8add9f8095..810b1f3876 100644 --- a/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.h +++ b/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.h @@ -166,17 +166,14 @@ public: struct MaterialData : public RendererStorageRD::MaterialData { uint64_t last_frame; ShaderData *shader_data; - RID uniform_buffer; RID uniform_set; - Vector<RID> texture_cache; - Vector<uint8_t> ubo_data; uint64_t last_pass = 0; uint32_t index = 0; RID next_pass; uint8_t priority; virtual void set_render_priority(int p_priority); virtual void set_next_pass(RID p_pass); - virtual void update_parameters(const Map<StringName, Variant> &p_parameters, bool p_uniform_dirty, bool p_textures_dirty); + virtual bool update_parameters(const Map<StringName, Variant> &p_parameters, bool p_uniform_dirty, bool p_textures_dirty); virtual ~MaterialData(); }; @@ -192,8 +189,6 @@ public: RID default_material; RID overdraw_material_shader; RID overdraw_material; - RID wireframe_material_shader; - RID wireframe_material; RID default_shader_rd; RID default_shader_sdfgi_rd; @@ -202,6 +197,12 @@ public: RID shadow_sampler; + RID default_material_uniform_set; + ShaderData *default_material_shader_ptr = nullptr; + + RID overdraw_material_uniform_set; + ShaderData *overdraw_material_shader_ptr = nullptr; + SceneShaderForwardClustered(); ~SceneShaderForwardClustered(); diff --git a/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp b/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp index ae09d215ff..7fbd6e23b0 100644 --- a/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp +++ b/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp @@ -335,6 +335,11 @@ void RenderForwardMobile::_render_scene(RenderDataRD *p_render_data, const Color bool using_ssr = false; bool using_sss = false; + if (p_render_data->render_info) { + p_render_data->render_info->info[RS::VIEWPORT_RENDER_INFO_TYPE_VISIBLE][RS::VIEWPORT_RENDER_INFO_DRAW_CALLS_IN_FRAME] = p_render_data->instances->size(); + p_render_data->render_info->info[RS::VIEWPORT_RENDER_INFO_TYPE_VISIBLE][RS::VIEWPORT_RENDER_INFO_OBJECTS_IN_FRAME] = p_render_data->instances->size(); + } + if (render_buffer) { // setup rendering to render buffer screen_size.x = render_buffer->width; @@ -369,7 +374,7 @@ void RenderForwardMobile::_render_scene(RenderDataRD *p_render_data, const Color _fill_render_list(RENDER_LIST_OPAQUE, p_render_data, PASS_MODE_COLOR); render_list[RENDER_LIST_OPAQUE].sort_by_key(); - render_list[RENDER_LIST_ALPHA].sort_by_depth(); + render_list[RENDER_LIST_ALPHA].sort_by_reverse_depth_and_priority(); // we no longer use this... _fill_instance_data(RENDER_LIST_OPAQUE); @@ -555,11 +560,15 @@ void RenderForwardMobile::_render_shadow_begin() { render_list[RENDER_LIST_SECONDARY].clear(); } -void RenderForwardMobile::_render_shadow_append(RID p_framebuffer, const PagedArray<GeometryInstance *> &p_instances, const CameraMatrix &p_projection, const Transform3D &p_transform, float p_zfar, float p_bias, float p_normal_bias, bool p_use_dp, bool p_use_dp_flip, bool p_use_pancake, const Plane &p_camera_plane, float p_lod_distance_multiplier, float p_screen_lod_threshold, const Rect2i &p_rect, bool p_flip_y, bool p_clear_region, bool p_begin, bool p_end) { +void RenderForwardMobile::_render_shadow_append(RID p_framebuffer, const PagedArray<GeometryInstance *> &p_instances, const CameraMatrix &p_projection, const Transform3D &p_transform, float p_zfar, float p_bias, float p_normal_bias, bool p_use_dp, bool p_use_dp_flip, bool p_use_pancake, const Plane &p_camera_plane, float p_lod_distance_multiplier, float p_screen_lod_threshold, const Rect2i &p_rect, bool p_flip_y, bool p_clear_region, bool p_begin, bool p_end, RendererScene::RenderInfo *p_render_info) { uint32_t shadow_pass_index = scene_state.shadow_passes.size(); SceneState::ShadowPass shadow_pass; + if (p_render_info) { + p_render_info->info[RS::VIEWPORT_RENDER_INFO_TYPE_SHADOW][RS::VIEWPORT_RENDER_INFO_DRAW_CALLS_IN_FRAME] = p_instances.size(); + p_render_info->info[RS::VIEWPORT_RENDER_INFO_TYPE_SHADOW][RS::VIEWPORT_RENDER_INFO_OBJECTS_IN_FRAME] = p_instances.size(); + } RenderDataRD render_data; render_data.cam_projection = p_projection; render_data.cam_transform = p_transform; @@ -567,6 +576,7 @@ void RenderForwardMobile::_render_shadow_append(RID p_framebuffer, const PagedAr render_data.z_near = 0.0; render_data.z_far = p_zfar; render_data.instances = &p_instances; + render_data.render_info = p_render_info; render_data.lod_camera_plane = p_camera_plane; render_data.lod_distance_multiplier = p_lod_distance_multiplier; @@ -927,6 +937,12 @@ RID RenderForwardMobile::_render_buffers_get_normal_texture(RID p_render_buffers return RID(); } +_FORCE_INLINE_ static uint32_t _indices_to_primitives(RS::PrimitiveType p_primitive, uint32_t p_indices) { + static const uint32_t divisor[RS::PRIMITIVE_MAX] = { 1, 2, 1, 3, 1 }; + static const uint32_t subtractor[RS::PRIMITIVE_MAX] = { 0, 0, 1, 0, 1 }; + return (p_indices - subtractor[p_primitive]) / divisor[p_primitive]; +} + void RenderForwardMobile::_fill_render_list(RenderListType p_render_list, const RenderDataRD *p_render_data, PassMode p_pass_mode, bool p_append) { if (p_render_list == RENDER_LIST_OPAQUE) { scene_state.used_sss = false; @@ -963,6 +979,10 @@ void RenderForwardMobile::_fill_render_list(RenderListType p_render_list, const uint32_t flags = inst->base_flags; //fill flags if appropriate + if (inst->non_uniform_scale) { + flags |= INSTANCE_DATA_FLAGS_NON_UNIFORM_SCALE; + } + bool uses_lightmap = false; // bool uses_gi = false; @@ -1032,21 +1052,42 @@ void RenderForwardMobile::_fill_render_list(RenderListType p_render_list, const distance = -distance_max; } - surf->lod_index = storage->mesh_surface_get_lod(surf->surface, inst->lod_model_scale * inst->lod_bias, distance * p_render_data->lod_distance_multiplier, p_render_data->screen_lod_threshold); + uint32_t indices; + surf->lod_index = storage->mesh_surface_get_lod(surf->surface, inst->lod_model_scale * inst->lod_bias, distance * p_render_data->lod_distance_multiplier, p_render_data->screen_lod_threshold, &indices); + if (p_render_data->render_info) { + indices = _indices_to_primitives(surf->primitive, indices); + if (p_render_list == RENDER_LIST_OPAQUE) { //opaque + p_render_data->render_info->info[RS::VIEWPORT_RENDER_INFO_TYPE_VISIBLE][RS::VIEWPORT_RENDER_INFO_PRIMITIVES_IN_FRAME] += indices; + } else if (p_render_list == RENDER_LIST_SECONDARY) { //shadow + p_render_data->render_info->info[RS::VIEWPORT_RENDER_INFO_TYPE_SHADOW][RS::VIEWPORT_RENDER_INFO_PRIMITIVES_IN_FRAME] += indices; + } + } } else { surf->lod_index = 0; + if (p_render_data->render_info) { + uint32_t to_draw = storage->mesh_surface_get_vertices_drawn_count(surf->surface); + to_draw = _indices_to_primitives(surf->primitive, to_draw); + to_draw *= inst->instance_count; + if (p_render_list == RENDER_LIST_OPAQUE) { //opaque + p_render_data->render_info->info[RS::VIEWPORT_RENDER_INFO_TYPE_VISIBLE][RS::VIEWPORT_RENDER_INFO_PRIMITIVES_IN_FRAME] += storage->mesh_surface_get_vertices_drawn_count(surf->surface); + } else if (p_render_list == RENDER_LIST_SECONDARY) { //shadow + p_render_data->render_info->info[RS::VIEWPORT_RENDER_INFO_TYPE_SHADOW][RS::VIEWPORT_RENDER_INFO_PRIMITIVES_IN_FRAME] += storage->mesh_surface_get_vertices_drawn_count(surf->surface); + } + } } // ADD Element if (p_pass_mode == PASS_MODE_COLOR) { - if (surf->flags & (GeometryInstanceSurfaceDataCache::FLAG_PASS_DEPTH | GeometryInstanceSurfaceDataCache::FLAG_PASS_OPAQUE)) { +#ifdef DEBUG_ENABLED + bool force_alpha = unlikely(get_debug_draw_mode() == RS::VIEWPORT_DEBUG_DRAW_OVERDRAW); +#else + bool force_alpha = false; +#endif + if (!force_alpha && (surf->flags & (GeometryInstanceSurfaceDataCache::FLAG_PASS_DEPTH | GeometryInstanceSurfaceDataCache::FLAG_PASS_OPAQUE))) { rl->add_element(surf); } - if (surf->flags & GeometryInstanceSurfaceDataCache::FLAG_PASS_ALPHA) { + if (force_alpha || (surf->flags & GeometryInstanceSurfaceDataCache::FLAG_PASS_ALPHA)) { render_list[RENDER_LIST_ALPHA].add_element(surf); - // if (uses_gi) { - // surf->sort.uses_forward_gi = 1; - // } } if (uses_lightmap) { @@ -1412,8 +1453,20 @@ void RenderForwardMobile::_render_list_template(RenderingDevice::DrawListID p_dr mesh_surface = surf->surface_shadow; } else { - material_uniform_set = surf->material_uniform_set; - shader = surf->shader; +#ifdef DEBUG_ENABLED + if (unlikely(get_debug_draw_mode() == RS::VIEWPORT_DEBUG_DRAW_LIGHTING)) { + material_uniform_set = scene_shader.default_material_uniform_set; + shader = scene_shader.default_material_shader_ptr; + } else if (unlikely(get_debug_draw_mode() == RS::VIEWPORT_DEBUG_DRAW_OVERDRAW)) { + material_uniform_set = scene_shader.overdraw_material_uniform_set; + shader = scene_shader.overdraw_material_shader_ptr; + } else { +#endif + material_uniform_set = surf->material_uniform_set; + shader = surf->shader; +#ifdef DEBUG_ENABLED + } +#endif mesh_surface = surf->surface; } @@ -1995,6 +2048,7 @@ void RenderForwardMobile::_geometry_instance_update(GeometryInstance *p_geometry //Fill push constant bool store_transform = true; + ginstance->base_flags = 0; if (ginstance->data->base_type == RS::INSTANCE_MULTIMESH) { ginstance->base_flags |= INSTANCE_DATA_FLAG_MULTIMESH; diff --git a/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.h b/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.h index 99cbd45b10..f40f713c03 100644 --- a/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.h +++ b/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.h @@ -93,7 +93,7 @@ protected: ~RenderBufferDataForwardMobile(); }; - virtual RenderBufferData *_create_render_buffer_data(); + virtual RenderBufferData *_create_render_buffer_data() override; /* Rendering */ @@ -152,23 +152,23 @@ protected: }; RID _setup_render_pass_uniform_set(RenderListType p_render_list, const RenderDataRD *p_render_data, RID p_radiance_texture, bool p_use_directional_shadow_atlas = false, int p_index = 0); - virtual void _render_scene(RenderDataRD *p_render_data, const Color &p_default_bg_color); + virtual void _render_scene(RenderDataRD *p_render_data, const Color &p_default_bg_color) override; - virtual void _render_shadow_begin(); - virtual void _render_shadow_append(RID p_framebuffer, const PagedArray<GeometryInstance *> &p_instances, const CameraMatrix &p_projection, const Transform3D &p_transform, float p_zfar, float p_bias, float p_normal_bias, bool p_use_dp, bool p_use_dp_flip, bool p_use_pancake, const Plane &p_camera_plane = Plane(), float p_lod_distance_multiplier = 0.0, float p_screen_lod_threshold = 0.0, const Rect2i &p_rect = Rect2i(), bool p_flip_y = false, bool p_clear_region = true, bool p_begin = true, bool p_end = true); - virtual void _render_shadow_process(); - virtual void _render_shadow_end(uint32_t p_barrier = RD::BARRIER_MASK_ALL); + virtual void _render_shadow_begin() override; + virtual void _render_shadow_append(RID p_framebuffer, const PagedArray<GeometryInstance *> &p_instances, const CameraMatrix &p_projection, const Transform3D &p_transform, float p_zfar, float p_bias, float p_normal_bias, bool p_use_dp, bool p_use_dp_flip, bool p_use_pancake, const Plane &p_camera_plane = Plane(), float p_lod_distance_multiplier = 0.0, float p_screen_lod_threshold = 0.0, const Rect2i &p_rect = Rect2i(), bool p_flip_y = false, bool p_clear_region = true, bool p_begin = true, bool p_end = true, RendererScene::RenderInfo *p_render_info = nullptr) override; + virtual void _render_shadow_process() override; + virtual void _render_shadow_end(uint32_t p_barrier = RD::BARRIER_MASK_ALL) override; - virtual void _render_material(const Transform3D &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, const PagedArray<GeometryInstance *> &p_instances, RID p_framebuffer, const Rect2i &p_region); - virtual void _render_uv2(const PagedArray<GeometryInstance *> &p_instances, RID p_framebuffer, const Rect2i &p_region); - virtual void _render_sdfgi(RID p_render_buffers, const Vector3i &p_from, const Vector3i &p_size, const AABB &p_bounds, const PagedArray<GeometryInstance *> &p_instances, const RID &p_albedo_texture, const RID &p_emission_texture, const RID &p_emission_aniso_texture, const RID &p_geom_facing_texture); - virtual void _render_particle_collider_heightfield(RID p_fb, const Transform3D &p_cam_transform, const CameraMatrix &p_cam_projection, const PagedArray<GeometryInstance *> &p_instances); + virtual void _render_material(const Transform3D &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, const PagedArray<GeometryInstance *> &p_instances, RID p_framebuffer, const Rect2i &p_region) override; + virtual void _render_uv2(const PagedArray<GeometryInstance *> &p_instances, RID p_framebuffer, const Rect2i &p_region) override; + virtual void _render_sdfgi(RID p_render_buffers, const Vector3i &p_from, const Vector3i &p_size, const AABB &p_bounds, const PagedArray<GeometryInstance *> &p_instances, const RID &p_albedo_texture, const RID &p_emission_texture, const RID &p_emission_aniso_texture, const RID &p_geom_facing_texture) override; + virtual void _render_particle_collider_heightfield(RID p_fb, const Transform3D &p_cam_transform, const CameraMatrix &p_cam_projection, const PagedArray<GeometryInstance *> &p_instances) override; uint64_t lightmap_texture_array_version = 0xFFFFFFFF; - virtual void _base_uniforms_changed(); + virtual void _base_uniforms_changed() override; void _update_render_base_uniform_set(); - virtual RID _render_buffers_get_normal_texture(RID p_render_buffers); + virtual RID _render_buffers_get_normal_texture(RID p_render_buffers) override; void _fill_render_list(RenderListType p_render_list, const RenderDataRD *p_render_data, PassMode p_pass_mode, bool p_append = false); void _fill_instance_data(RenderListType p_render_list, uint32_t p_offset = 0, int32_t p_max_elements = -1, bool p_update_buffer = true); @@ -356,7 +356,7 @@ protected: } }; - void sort_by_reverse_depth_and_priority(bool p_alpha) { //used for alpha + void sort_by_reverse_depth_and_priority() { //used for alpha SortArray<GeometryInstanceSurfaceDataCache *, SortByReverseDepthAndPriority> sorter; sorter.sort(elements.ptr(), elements.size()); @@ -390,6 +390,7 @@ protected: // check which ones of these apply, probably all except GI and SDFGI enum { + INSTANCE_DATA_FLAGS_NON_UNIFORM_SCALE = 1 << 5, INSTANCE_DATA_FLAG_USE_GI_BUFFERS = 1 << 6, INSTANCE_DATA_FLAG_USE_SDFGI = 1 << 7, INSTANCE_DATA_FLAG_USE_LIGHTMAP_CAPTURE = 1 << 8, @@ -402,7 +403,6 @@ protected: INSTANCE_DATA_FLAG_MULTIMESH_HAS_CUSTOM_DATA = 1 << 15, INSTANCE_DATA_FLAGS_PARTICLE_TRAIL_SHIFT = 16, INSTANCE_DATA_FLAGS_PARTICLE_TRAIL_MASK = 0xFF, - INSTANCE_DATA_FLAGS_NON_UNIFORM_SCALE = 1 << 24, }; struct GeometryInstanceLightmapSH { @@ -568,38 +568,38 @@ public: void _geometry_instance_update(GeometryInstance *p_geometry_instance); void _update_dirty_geometry_instances(); - virtual GeometryInstance *geometry_instance_create(RID p_base); - virtual void geometry_instance_set_skeleton(GeometryInstance *p_geometry_instance, RID p_skeleton); - virtual void geometry_instance_set_material_override(GeometryInstance *p_geometry_instance, RID p_override); - virtual void geometry_instance_set_surface_materials(GeometryInstance *p_geometry_instance, const Vector<RID> &p_materials); - virtual void geometry_instance_set_mesh_instance(GeometryInstance *p_geometry_instance, RID p_mesh_instance); - virtual void geometry_instance_set_transform(GeometryInstance *p_geometry_instance, const Transform3D &p_transform, const AABB &p_aabb, const AABB &p_transformed_aabb); - virtual void geometry_instance_set_layer_mask(GeometryInstance *p_geometry_instance, uint32_t p_layer_mask); - virtual void geometry_instance_set_lod_bias(GeometryInstance *p_geometry_instance, float p_lod_bias); - virtual void geometry_instance_set_use_baked_light(GeometryInstance *p_geometry_instance, bool p_enable); - virtual void geometry_instance_set_use_dynamic_gi(GeometryInstance *p_geometry_instance, bool p_enable); - virtual void geometry_instance_set_use_lightmap(GeometryInstance *p_geometry_instance, RID p_lightmap_instance, const Rect2 &p_lightmap_uv_scale, int p_lightmap_slice_index); - virtual void geometry_instance_set_lightmap_capture(GeometryInstance *p_geometry_instance, const Color *p_sh9); - virtual void geometry_instance_set_instance_shader_parameters_offset(GeometryInstance *p_geometry_instance, int32_t p_offset); - virtual void geometry_instance_set_cast_double_sided_shadows(GeometryInstance *p_geometry_instance, bool p_enable); - - virtual Transform3D geometry_instance_get_transform(GeometryInstance *p_instance); - virtual AABB geometry_instance_get_aabb(GeometryInstance *p_instance); - - virtual void geometry_instance_free(GeometryInstance *p_geometry_instance); - - virtual uint32_t geometry_instance_get_pair_mask(); - virtual void geometry_instance_pair_light_instances(GeometryInstance *p_geometry_instance, const RID *p_light_instances, uint32_t p_light_instance_count); - virtual void geometry_instance_pair_reflection_probe_instances(GeometryInstance *p_geometry_instance, const RID *p_reflection_probe_instances, uint32_t p_reflection_probe_instance_count); - virtual void geometry_instance_pair_decal_instances(GeometryInstance *p_geometry_instance, const RID *p_decal_instances, uint32_t p_decal_instance_count); - virtual void geometry_instance_pair_voxel_gi_instances(GeometryInstance *p_geometry_instance, const RID *p_voxel_gi_instances, uint32_t p_voxel_gi_instance_count); - - virtual bool free(RID p_rid); - - virtual bool is_dynamic_gi_supported() const; - virtual bool is_clustered_enabled() const; - virtual bool is_volumetric_supported() const; - virtual uint32_t get_max_elements() const; + virtual GeometryInstance *geometry_instance_create(RID p_base) override; + virtual void geometry_instance_set_skeleton(GeometryInstance *p_geometry_instance, RID p_skeleton) override; + virtual void geometry_instance_set_material_override(GeometryInstance *p_geometry_instance, RID p_override) override; + virtual void geometry_instance_set_surface_materials(GeometryInstance *p_geometry_instance, const Vector<RID> &p_materials) override; + virtual void geometry_instance_set_mesh_instance(GeometryInstance *p_geometry_instance, RID p_mesh_instance) override; + virtual void geometry_instance_set_transform(GeometryInstance *p_geometry_instance, const Transform3D &p_transform, const AABB &p_aabb, const AABB &p_transformed_aabb) override; + virtual void geometry_instance_set_layer_mask(GeometryInstance *p_geometry_instance, uint32_t p_layer_mask) override; + virtual void geometry_instance_set_lod_bias(GeometryInstance *p_geometry_instance, float p_lod_bias) override; + virtual void geometry_instance_set_use_baked_light(GeometryInstance *p_geometry_instance, bool p_enable) override; + virtual void geometry_instance_set_use_dynamic_gi(GeometryInstance *p_geometry_instance, bool p_enable) override; + virtual void geometry_instance_set_use_lightmap(GeometryInstance *p_geometry_instance, RID p_lightmap_instance, const Rect2 &p_lightmap_uv_scale, int p_lightmap_slice_index) override; + virtual void geometry_instance_set_lightmap_capture(GeometryInstance *p_geometry_instance, const Color *p_sh9) override; + virtual void geometry_instance_set_instance_shader_parameters_offset(GeometryInstance *p_geometry_instance, int32_t p_offset) override; + virtual void geometry_instance_set_cast_double_sided_shadows(GeometryInstance *p_geometry_instance, bool p_enable) override; + + virtual Transform3D geometry_instance_get_transform(GeometryInstance *p_instance) override; + virtual AABB geometry_instance_get_aabb(GeometryInstance *p_instance) override; + + virtual void geometry_instance_free(GeometryInstance *p_geometry_instance) override; + + virtual uint32_t geometry_instance_get_pair_mask() override; + virtual void geometry_instance_pair_light_instances(GeometryInstance *p_geometry_instance, const RID *p_light_instances, uint32_t p_light_instance_count) override; + virtual void geometry_instance_pair_reflection_probe_instances(GeometryInstance *p_geometry_instance, const RID *p_reflection_probe_instances, uint32_t p_reflection_probe_instance_count) override; + virtual void geometry_instance_pair_decal_instances(GeometryInstance *p_geometry_instance, const RID *p_decal_instances, uint32_t p_decal_instance_count) override; + virtual void geometry_instance_pair_voxel_gi_instances(GeometryInstance *p_geometry_instance, const RID *p_voxel_gi_instances, uint32_t p_voxel_gi_instance_count) override; + + virtual bool free(RID p_rid) override; + + virtual bool is_dynamic_gi_supported() const override; + virtual bool is_clustered_enabled() const override; + virtual bool is_volumetric_supported() const override; + virtual uint32_t get_max_elements() const override; RenderForwardMobile(RendererStorageRD *p_storage); ~RenderForwardMobile(); diff --git a/servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.cpp b/servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.cpp index b5fb9fbc62..7709c8aadc 100644 --- a/servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.cpp +++ b/servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.cpp @@ -429,94 +429,14 @@ void SceneShaderForwardMobile::MaterialData::set_next_pass(RID p_pass) { next_pass = p_pass; } -void SceneShaderForwardMobile::MaterialData::update_parameters(const Map<StringName, Variant> &p_parameters, bool p_uniform_dirty, bool p_textures_dirty) { +bool SceneShaderForwardMobile::MaterialData::update_parameters(const Map<StringName, Variant> &p_parameters, bool p_uniform_dirty, bool p_textures_dirty) { SceneShaderForwardMobile *shader_singleton = (SceneShaderForwardMobile *)SceneShaderForwardMobile::singleton; - if ((uint32_t)ubo_data.size() != shader_data->ubo_size) { - p_uniform_dirty = true; - if (uniform_buffer.is_valid()) { - RD::get_singleton()->free(uniform_buffer); - uniform_buffer = RID(); - } - - ubo_data.resize(shader_data->ubo_size); - if (ubo_data.size()) { - uniform_buffer = RD::get_singleton()->uniform_buffer_create(ubo_data.size()); - memset(ubo_data.ptrw(), 0, ubo_data.size()); //clear - } - - //clear previous uniform set - if (uniform_set.is_valid() && RD::get_singleton()->uniform_set_is_valid(uniform_set)) { - RD::get_singleton()->free(uniform_set); - uniform_set = RID(); - } - } - - //check whether buffer changed - if (p_uniform_dirty && ubo_data.size()) { - update_uniform_buffer(shader_data->uniforms, shader_data->ubo_offsets.ptr(), p_parameters, ubo_data.ptrw(), ubo_data.size(), false); - RD::get_singleton()->buffer_update(uniform_buffer, 0, ubo_data.size(), ubo_data.ptrw(), RD::BARRIER_MASK_RASTER); - } - - uint32_t tex_uniform_count = shader_data->texture_uniforms.size(); - - if ((uint32_t)texture_cache.size() != tex_uniform_count) { - texture_cache.resize(tex_uniform_count); - p_textures_dirty = true; - - //clear previous uniform set - if (uniform_set.is_valid() && RD::get_singleton()->uniform_set_is_valid(uniform_set)) { - RD::get_singleton()->free(uniform_set); - uniform_set = RID(); - } - } - - if (p_textures_dirty && tex_uniform_count) { - update_textures(p_parameters, shader_data->default_texture_params, shader_data->texture_uniforms, texture_cache.ptrw(), true); - } - - if (shader_data->ubo_size == 0 && shader_data->texture_uniforms.size() == 0) { - // This material does not require an uniform set, so don't create it. - return; - } - - if (!p_textures_dirty && uniform_set.is_valid() && RD::get_singleton()->uniform_set_is_valid(uniform_set)) { - //no reason to update uniform set, only UBO (or nothing) was needed to update - return; - } - - Vector<RD::Uniform> uniforms; - - { - if (shader_data->ubo_size) { - RD::Uniform u; - u.uniform_type = RD::UNIFORM_TYPE_UNIFORM_BUFFER; - u.binding = 0; - u.ids.push_back(uniform_buffer); - uniforms.push_back(u); - } - - const RID *textures = texture_cache.ptrw(); - for (uint32_t i = 0; i < tex_uniform_count; i++) { - RD::Uniform u; - u.uniform_type = RD::UNIFORM_TYPE_TEXTURE; - u.binding = 1 + i; - u.ids.push_back(textures[i]); - uniforms.push_back(u); - } - } - - uniform_set = RD::get_singleton()->uniform_set_create(uniforms, shader_singleton->shader.version_get_shader(shader_data->version, 0), RenderForwardMobile::MATERIAL_UNIFORM_SET); + return update_parameters_uniform_set(p_parameters, p_uniform_dirty, p_textures_dirty, shader_data->uniforms, shader_data->ubo_offsets.ptr(), shader_data->texture_uniforms, shader_data->default_texture_params, shader_data->ubo_size, uniform_set, shader_singleton->shader.version_get_shader(shader_data->version, 0), RenderForwardMobile::MATERIAL_UNIFORM_SET, RD::BARRIER_MASK_RASTER); } SceneShaderForwardMobile::MaterialData::~MaterialData() { - if (uniform_set.is_valid() && RD::get_singleton()->uniform_set_is_valid(uniform_set)) { - RD::get_singleton()->free(uniform_set); - } - - if (uniform_buffer.is_valid()) { - RD::get_singleton()->free(uniform_buffer); - } + free_parameters_uniform_set(uniform_set); } RendererStorageRD::MaterialData *SceneShaderForwardMobile::_create_material_func(ShaderData *p_shader) { @@ -621,7 +541,6 @@ void SceneShaderForwardMobile::init(RendererStorageRD *p_storage, const String p actions.renames["SSS_STRENGTH"] = "sss_strength"; actions.renames["SSS_TRANSMITTANCE_COLOR"] = "transmittance_color"; actions.renames["SSS_TRANSMITTANCE_DEPTH"] = "transmittance_depth"; - actions.renames["SSS_TRANSMITTANCE_CURVE"] = "transmittance_curve"; actions.renames["SSS_TRANSMITTANCE_BOOST"] = "transmittance_boost"; actions.renames["BACKLIGHT"] = "backlight"; actions.renames["AO"] = "ao"; @@ -759,22 +678,23 @@ void SceneShaderForwardMobile::init(RendererStorageRD *p_storage, const String p MaterialData *md = (MaterialData *)storage->material_get_data(default_material, RendererStorageRD::SHADER_TYPE_3D); default_shader_rd = shader.version_get_shader(md->shader_data->version, SHADER_VERSION_COLOR_PASS); + + default_material_shader_ptr = md->shader_data; + default_material_uniform_set = md->uniform_set; } { overdraw_material_shader = storage->shader_allocate(); storage->shader_initialize(overdraw_material_shader); - storage->shader_set_code(overdraw_material_shader, "shader_type spatial;\nrender_mode blend_add,unshaded;\n void fragment() { ALBEDO=vec3(0.4,0.8,0.8); ALPHA=0.2; }"); + // Use relatively low opacity so that more "layers" of overlapping objects can be distinguished. + storage->shader_set_code(overdraw_material_shader, "shader_type spatial;\nrender_mode blend_add,unshaded;\n void fragment() { ALBEDO=vec3(0.4,0.8,0.8); ALPHA=0.1; }"); overdraw_material = storage->material_allocate(); storage->material_initialize(overdraw_material); storage->material_set_shader(overdraw_material, overdraw_material_shader); - wireframe_material_shader = storage->shader_allocate(); - storage->shader_initialize(wireframe_material_shader); - storage->shader_set_code(wireframe_material_shader, "shader_type spatial;\nrender_mode wireframe,unshaded;\n void fragment() { ALBEDO=vec3(0.0,0.0,0.0); }"); - wireframe_material = storage->material_allocate(); - storage->material_initialize(wireframe_material); - storage->material_set_shader(wireframe_material, wireframe_material_shader); + MaterialData *md = (MaterialData *)storage->material_get_data(overdraw_material, RendererStorageRD::SHADER_TYPE_3D); + overdraw_material_shader_ptr = md->shader_data; + overdraw_material_uniform_set = md->uniform_set; } { @@ -802,11 +722,9 @@ SceneShaderForwardMobile::~SceneShaderForwardMobile() { RD::get_singleton()->free(default_vec4_xform_buffer); RD::get_singleton()->free(shadow_sampler); - storage->free(wireframe_material_shader); storage->free(overdraw_material_shader); storage->free(default_shader); - storage->free(wireframe_material); storage->free(overdraw_material); storage->free(default_material); } diff --git a/servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.h b/servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.h index f4f6ceeb1d..5c9e35fd0d 100644 --- a/servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.h +++ b/servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.h @@ -163,17 +163,14 @@ public: struct MaterialData : public RendererStorageRD::MaterialData { uint64_t last_frame; ShaderData *shader_data; - RID uniform_buffer; RID uniform_set; - Vector<RID> texture_cache; - Vector<uint8_t> ubo_data; uint64_t last_pass = 0; uint32_t index = 0; RID next_pass; uint8_t priority; virtual void set_render_priority(int p_priority); virtual void set_next_pass(RID p_pass); - virtual void update_parameters(const Map<StringName, Variant> &p_parameters, bool p_uniform_dirty, bool p_textures_dirty); + virtual bool update_parameters(const Map<StringName, Variant> &p_parameters, bool p_uniform_dirty, bool p_textures_dirty); virtual ~MaterialData(); }; @@ -189,8 +186,6 @@ public: RID default_material; RID overdraw_material_shader; RID overdraw_material; - RID wireframe_material_shader; - RID wireframe_material; RID default_shader_rd; RID default_vec4_xform_buffer; @@ -198,6 +193,12 @@ public: RID shadow_sampler; + RID default_material_uniform_set; + ShaderData *default_material_shader_ptr = nullptr; + + RID overdraw_material_uniform_set; + ShaderData *overdraw_material_shader_ptr = nullptr; + SceneShaderForwardMobile(); ~SceneShaderForwardMobile(); diff --git a/servers/rendering/renderer_rd/pipeline_cache_rd.cpp b/servers/rendering/renderer_rd/pipeline_cache_rd.cpp index b2b919c40e..22888ddbe5 100644 --- a/servers/rendering/renderer_rd/pipeline_cache_rd.cpp +++ b/servers/rendering/renderer_rd/pipeline_cache_rd.cpp @@ -31,20 +31,21 @@ #include "pipeline_cache_rd.h" #include "core/os/memory.h" -RID PipelineCacheRD::_generate_version(RD::VertexFormatID p_vertex_format_id, RD::FramebufferFormatID p_framebuffer_format_id, bool p_wireframe) { +RID PipelineCacheRD::_generate_version(RD::VertexFormatID p_vertex_format_id, RD::FramebufferFormatID p_framebuffer_format_id, bool p_wireframe, uint32_t p_render_pass) { RD::PipelineMultisampleState multisample_state_version = multisample_state; - multisample_state_version.sample_count = RD::get_singleton()->framebuffer_format_get_texture_samples(p_framebuffer_format_id); + multisample_state_version.sample_count = RD::get_singleton()->framebuffer_format_get_texture_samples(p_framebuffer_format_id, p_render_pass); RD::PipelineRasterizationState raster_state_version = rasterization_state; raster_state_version.wireframe = p_wireframe; - RID pipeline = RD::get_singleton()->render_pipeline_create(shader, p_framebuffer_format_id, p_vertex_format_id, render_primitive, raster_state_version, multisample_state_version, depth_stencil_state, blend_state, dynamic_state_flags); + RID pipeline = RD::get_singleton()->render_pipeline_create(shader, p_framebuffer_format_id, p_vertex_format_id, render_primitive, raster_state_version, multisample_state_version, depth_stencil_state, blend_state, dynamic_state_flags, p_render_pass); ERR_FAIL_COND_V(pipeline.is_null(), RID()); versions = (Version *)memrealloc(versions, sizeof(Version) * (version_count + 1)); versions[version_count].framebuffer_id = p_framebuffer_format_id; versions[version_count].vertex_id = p_vertex_format_id; versions[version_count].wireframe = p_wireframe; versions[version_count].pipeline = pipeline; + versions[version_count].render_pass = p_render_pass; version_count++; return pipeline; } diff --git a/servers/rendering/renderer_rd/pipeline_cache_rd.h b/servers/rendering/renderer_rd/pipeline_cache_rd.h index b1c8f21ecc..387a8a038f 100644 --- a/servers/rendering/renderer_rd/pipeline_cache_rd.h +++ b/servers/rendering/renderer_rd/pipeline_cache_rd.h @@ -50,6 +50,7 @@ class PipelineCacheRD { struct Version { RD::VertexFormatID vertex_id; RD::FramebufferFormatID framebuffer_id; + uint32_t render_pass; bool wireframe; RID pipeline; }; @@ -57,7 +58,7 @@ class PipelineCacheRD { Version *versions; uint32_t version_count; - RID _generate_version(RD::VertexFormatID p_vertex_format_id, RD::FramebufferFormatID p_framebuffer_format_id, bool p_wireframe); + RID _generate_version(RD::VertexFormatID p_vertex_format_id, RD::FramebufferFormatID p_framebuffer_format_id, bool p_wireframe, uint32_t p_render_pass); void _clear(); @@ -65,7 +66,7 @@ public: void setup(RID p_shader, RD::RenderPrimitive p_primitive, const RD::PipelineRasterizationState &p_rasterization_state, RD::PipelineMultisampleState p_multisample, const RD::PipelineDepthStencilState &p_depth_stencil_state, const RD::PipelineColorBlendState &p_blend_state, int p_dynamic_state_flags = 0); void update_shader(RID p_shader); - _FORCE_INLINE_ RID get_render_pipeline(RD::VertexFormatID p_vertex_format_id, RD::FramebufferFormatID p_framebuffer_format_id, bool p_wireframe = false) { + _FORCE_INLINE_ RID get_render_pipeline(RD::VertexFormatID p_vertex_format_id, RD::FramebufferFormatID p_framebuffer_format_id, bool p_wireframe = false, uint32_t p_render_pass = 0) { #ifdef DEBUG_ENABLED ERR_FAIL_COND_V_MSG(shader.is_null(), RID(), "Attempted to use an unused shader variant (shader is null),"); @@ -74,13 +75,13 @@ public: spin_lock.lock(); RID result; for (uint32_t i = 0; i < version_count; i++) { - if (versions[i].vertex_id == p_vertex_format_id && versions[i].framebuffer_id == p_framebuffer_format_id && versions[i].wireframe == p_wireframe) { + if (versions[i].vertex_id == p_vertex_format_id && versions[i].framebuffer_id == p_framebuffer_format_id && versions[i].wireframe == p_wireframe && versions[i].render_pass == p_render_pass) { result = versions[i].pipeline; spin_lock.unlock(); return result; } } - result = _generate_version(p_vertex_format_id, p_framebuffer_format_id, p_wireframe); + result = _generate_version(p_vertex_format_id, p_framebuffer_format_id, p_wireframe, p_render_pass); spin_lock.unlock(); return result; } diff --git a/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp b/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp index fe6d3be82e..1e3dbe69a3 100644 --- a/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp @@ -408,6 +408,7 @@ void RendererCanvasRenderRD::_render_item(RD::DrawListID p_draw_list, RID p_rend PushConstant push_constant; Transform2D base_transform = p_canvas_transform_inverse * p_item->final_transform; + Transform2D draw_transform; _update_transform_2d_to_mat2x3(base_transform, push_constant.world); Color base_color = p_item->final_modulate; @@ -731,7 +732,7 @@ void RendererCanvasRenderRD::_render_item(RD::DrawListID p_draw_list, RID p_rend mesh_instance = m->mesh_instance; texture = m->texture; modulate = m->modulate; - _update_transform_2d_to_mat2x3(base_transform * m->transform, push_constant.world); + _update_transform_2d_to_mat2x3(base_transform * draw_transform * m->transform, push_constant.world); } else if (c->type == Item::Command::TYPE_MULTIMESH) { const Item::CommandMultiMesh *mm = static_cast<const Item::CommandMultiMesh *>(c); RID multimesh = mm->multimesh; @@ -864,10 +865,10 @@ void RendererCanvasRenderRD::_render_item(RD::DrawListID p_draw_list, RID p_rend for (int j = 0; j < 6; j++) { push_constant.world[j] = world_backup[j]; } - } break; case Item::Command::TYPE_TRANSFORM: { const Item::CommandTransform *transform = static_cast<const Item::CommandTransform *>(c); + draw_transform = transform->xform; _update_transform_2d_to_mat2x3(base_transform * transform->xform, push_constant.world); } break; @@ -2200,94 +2201,14 @@ RendererStorageRD::ShaderData *RendererCanvasRenderRD::_create_shader_func() { return shader_data; } -void RendererCanvasRenderRD::MaterialData::update_parameters(const Map<StringName, Variant> &p_parameters, bool p_uniform_dirty, bool p_textures_dirty) { +bool RendererCanvasRenderRD::MaterialData::update_parameters(const Map<StringName, Variant> &p_parameters, bool p_uniform_dirty, bool p_textures_dirty) { RendererCanvasRenderRD *canvas_singleton = (RendererCanvasRenderRD *)RendererCanvasRender::singleton; - if ((uint32_t)ubo_data.size() != shader_data->ubo_size) { - p_uniform_dirty = true; - if (uniform_buffer.is_valid()) { - RD::get_singleton()->free(uniform_buffer); - uniform_buffer = RID(); - } - - ubo_data.resize(shader_data->ubo_size); - if (ubo_data.size()) { - uniform_buffer = RD::get_singleton()->uniform_buffer_create(ubo_data.size()); - memset(ubo_data.ptrw(), 0, ubo_data.size()); //clear - } - - //clear previous uniform set - if (uniform_set.is_valid() && RD::get_singleton()->uniform_set_is_valid(uniform_set)) { - RD::get_singleton()->free(uniform_set); - uniform_set = RID(); - } - } - - //check whether buffer changed - if (p_uniform_dirty && ubo_data.size()) { - update_uniform_buffer(shader_data->uniforms, shader_data->ubo_offsets.ptr(), p_parameters, ubo_data.ptrw(), ubo_data.size(), false); - RD::get_singleton()->buffer_update(uniform_buffer, 0, ubo_data.size(), ubo_data.ptrw()); - } - - uint32_t tex_uniform_count = shader_data->texture_uniforms.size(); - - if ((uint32_t)texture_cache.size() != tex_uniform_count) { - texture_cache.resize(tex_uniform_count); - p_textures_dirty = true; - - //clear previous uniform set - if (uniform_set.is_valid() && RD::get_singleton()->uniform_set_is_valid(uniform_set)) { - RD::get_singleton()->free(uniform_set); - uniform_set = RID(); - } - } - - if (p_textures_dirty && tex_uniform_count) { - update_textures(p_parameters, shader_data->default_texture_params, shader_data->texture_uniforms, texture_cache.ptrw(), false); - } - - if (shader_data->ubo_size == 0) { - // This material does not require an uniform set, so don't create it. - return; - } - - if (!p_textures_dirty && uniform_set.is_valid() && RD::get_singleton()->uniform_set_is_valid(uniform_set)) { - //no reason to update uniform set, only UBO (or nothing) was needed to update - return; - } - - Vector<RD::Uniform> uniforms; - - { - if (shader_data->ubo_size) { - RD::Uniform u; - u.uniform_type = RD::UNIFORM_TYPE_UNIFORM_BUFFER; - u.binding = 0; - u.ids.push_back(uniform_buffer); - uniforms.push_back(u); - } - - const RID *textures = texture_cache.ptrw(); - for (uint32_t i = 0; i < tex_uniform_count; i++) { - RD::Uniform u; - u.uniform_type = RD::UNIFORM_TYPE_TEXTURE; - u.binding = 1 + i; - u.ids.push_back(textures[i]); - uniforms.push_back(u); - } - } - - uniform_set = RD::get_singleton()->uniform_set_create(uniforms, canvas_singleton->shader.canvas_shader.version_get_shader(shader_data->version, 0), MATERIAL_UNIFORM_SET); + return update_parameters_uniform_set(p_parameters, p_uniform_dirty, p_textures_dirty, shader_data->uniforms, shader_data->ubo_offsets.ptr(), shader_data->texture_uniforms, shader_data->default_texture_params, shader_data->ubo_size, uniform_set, canvas_singleton->shader.canvas_shader.version_get_shader(shader_data->version, 0), MATERIAL_UNIFORM_SET); } RendererCanvasRenderRD::MaterialData::~MaterialData() { - if (uniform_set.is_valid() && RD::get_singleton()->uniform_set_is_valid(uniform_set)) { - RD::get_singleton()->free(uniform_set); - } - - if (uniform_buffer.is_valid()) { - RD::get_singleton()->free(uniform_buffer); - } + free_parameters_uniform_set(uniform_set); } RendererStorageRD::MaterialData *RendererCanvasRenderRD::_create_material_func(ShaderData *p_shader) { diff --git a/servers/rendering/renderer_rd/renderer_canvas_render_rd.h b/servers/rendering/renderer_rd/renderer_canvas_render_rd.h index 8c1376e2dc..7c4f62832c 100644 --- a/servers/rendering/renderer_rd/renderer_canvas_render_rd.h +++ b/servers/rendering/renderer_rd/renderer_canvas_render_rd.h @@ -201,14 +201,11 @@ class RendererCanvasRenderRD : public RendererCanvasRender { struct MaterialData : public RendererStorageRD::MaterialData { uint64_t last_frame; ShaderData *shader_data; - RID uniform_buffer; RID uniform_set; - Vector<RID> texture_cache; - Vector<uint8_t> ubo_data; virtual void set_render_priority(int p_priority) {} virtual void set_next_pass(RID p_pass) {} - virtual void update_parameters(const Map<StringName, Variant> &p_parameters, bool p_uniform_dirty, bool p_textures_dirty); + virtual bool update_parameters(const Map<StringName, Variant> &p_parameters, bool p_uniform_dirty, bool p_textures_dirty); virtual ~MaterialData(); }; @@ -457,8 +454,6 @@ public: void canvas_debug_viewport_shadows(Light *p_lights_with_shadow) {} - void draw_window_margins(int *p_margins, RID *p_margin_textures) {} - virtual void set_shadow_texture_size(int p_size); void set_time(double p_time); diff --git a/servers/rendering/renderer_rd/renderer_compositor_rd.cpp b/servers/rendering/renderer_rd/renderer_compositor_rd.cpp index f9ac7c8fa3..a8f086b0f9 100644 --- a/servers/rendering/renderer_rd/renderer_compositor_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_compositor_rd.cpp @@ -60,8 +60,7 @@ void RendererCompositorRD::blit_render_targets_to_screen(DisplayServer::WindowID } Size2 screen_size(RD::get_singleton()->screen_get_width(p_screen), RD::get_singleton()->screen_get_height(p_screen)); - BlitMode mode = p_render_targets[i].lens_distortion.apply ? BLIT_MODE_LENS : p_render_targets[i].multi_view.use_layer ? BLIT_MODE_USE_LAYER : - BLIT_MODE_NORMAL; + BlitMode mode = p_render_targets[i].lens_distortion.apply ? BLIT_MODE_LENS : (p_render_targets[i].multi_view.use_layer ? BLIT_MODE_USE_LAYER : BLIT_MODE_NORMAL); RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, blit.pipelines[mode]); RD::get_singleton()->draw_list_bind_index_array(draw_list, blit.array); RD::get_singleton()->draw_list_bind_uniform_set(draw_list, render_target_descriptors[rd_texture], 0); @@ -111,13 +110,14 @@ void RendererCompositorRD::initialize() { blit_modes.push_back("\n"); blit_modes.push_back("\n#define USE_LAYER\n"); blit_modes.push_back("\n#define USE_LAYER\n#define APPLY_LENS_DISTORTION\n"); + blit_modes.push_back("\n"); blit.shader.initialize(blit_modes); blit.shader_version = blit.shader.version_create(); for (int i = 0; i < BLIT_MODE_MAX; i++) { - blit.pipelines[i] = RD::get_singleton()->render_pipeline_create(blit.shader.version_get_shader(blit.shader_version, i), RD::get_singleton()->screen_get_framebuffer_format(), RD::INVALID_ID, RD::RENDER_PRIMITIVE_TRIANGLES, RD::PipelineRasterizationState(), RD::PipelineMultisampleState(), RD::PipelineDepthStencilState(), RenderingDevice::PipelineColorBlendState::create_disabled(), 0); + blit.pipelines[i] = RD::get_singleton()->render_pipeline_create(blit.shader.version_get_shader(blit.shader_version, i), RD::get_singleton()->screen_get_framebuffer_format(), RD::INVALID_ID, RD::RENDER_PRIMITIVE_TRIANGLES, RD::PipelineRasterizationState(), RD::PipelineMultisampleState(), RD::PipelineDepthStencilState(), i == BLIT_MODE_NORMAL_ALPHA ? RenderingDevice::PipelineColorBlendState::create_blend() : RenderingDevice::PipelineColorBlendState::create_disabled(), 0); } //create index array for copy shader @@ -153,6 +153,81 @@ void RendererCompositorRD::finalize() { RD::get_singleton()->free(blit.sampler); } +void RendererCompositorRD::set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale, bool p_use_filter) { + RD::get_singleton()->prepare_screen_for_drawing(); + + RID texture = storage->texture_allocate(); + storage->texture_2d_initialize(texture, p_image); + RID rd_texture = storage->texture_get_rd_texture(texture); + + RID uset; + { + Vector<RD::Uniform> uniforms; + RD::Uniform u; + u.uniform_type = RD::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE; + u.binding = 0; + u.ids.push_back(blit.sampler); + u.ids.push_back(rd_texture); + uniforms.push_back(u); + uset = RD::get_singleton()->uniform_set_create(uniforms, blit.shader.version_get_shader(blit.shader_version, BLIT_MODE_NORMAL), 0); + } + + Size2 window_size = DisplayServer::get_singleton()->window_get_size(); + print_line("window size: " + window_size); + + Rect2 imgrect(0, 0, p_image->get_width(), p_image->get_height()); + Rect2 screenrect; + if (p_scale) { + if (window_size.width > window_size.height) { + //scale horizontally + screenrect.size.y = window_size.height; + screenrect.size.x = imgrect.size.x * window_size.height / imgrect.size.y; + screenrect.position.x = (window_size.width - screenrect.size.x) / 2; + + } else { + //scale vertically + screenrect.size.x = window_size.width; + screenrect.size.y = imgrect.size.y * window_size.width / imgrect.size.x; + screenrect.position.y = (window_size.height - screenrect.size.y) / 2; + } + } else { + screenrect = imgrect; + screenrect.position += ((Size2(window_size.width, window_size.height) - screenrect.size) / 2.0).floor(); + } + + screenrect.position /= window_size; + screenrect.size /= window_size; + + RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin_for_screen(DisplayServer::MAIN_WINDOW_ID, p_color); + + RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, blit.pipelines[BLIT_MODE_NORMAL_ALPHA]); + RD::get_singleton()->draw_list_bind_index_array(draw_list, blit.array); + RD::get_singleton()->draw_list_bind_uniform_set(draw_list, uset, 0); + + blit.push_constant.rect[0] = screenrect.position.x; + blit.push_constant.rect[1] = screenrect.position.y; + blit.push_constant.rect[2] = screenrect.size.width; + blit.push_constant.rect[3] = screenrect.size.height; + blit.push_constant.layer = 0; + blit.push_constant.eye_center[0] = 0; + blit.push_constant.eye_center[1] = 0; + blit.push_constant.k1 = 0; + blit.push_constant.k2 = 0; + blit.push_constant.upscale = 1.0; + blit.push_constant.aspect_ratio = 1.0; + + print_line("rect: " + screenrect); + + RD::get_singleton()->draw_list_set_push_constant(draw_list, &blit.push_constant, sizeof(BlitPushConstant)); + RD::get_singleton()->draw_list_draw(draw_list, true); + + RD::get_singleton()->draw_list_end(); + + RD::get_singleton()->swap_buffers(); + + RD::get_singleton()->free(texture); +} + RendererCompositorRD *RendererCompositorRD::singleton = nullptr; RendererCompositorRD::RendererCompositorRD() { diff --git a/servers/rendering/renderer_rd/renderer_compositor_rd.h b/servers/rendering/renderer_rd/renderer_compositor_rd.h index 7a78322051..15b3b77ed9 100644 --- a/servers/rendering/renderer_rd/renderer_compositor_rd.h +++ b/servers/rendering/renderer_rd/renderer_compositor_rd.h @@ -50,6 +50,7 @@ protected: BLIT_MODE_NORMAL, BLIT_MODE_USE_LAYER, BLIT_MODE_LENS, + BLIT_MODE_NORMAL_ALPHA, BLIT_MODE_MAX }; @@ -88,7 +89,7 @@ public: RendererCanvasRender *get_canvas() { return canvas; } RendererSceneRender *get_scene() { return scene; } - void set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale, bool p_use_filter) {} + void set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale, bool p_use_filter); void initialize(); void begin_frame(double frame_step); diff --git a/servers/rendering/renderer_rd/renderer_scene_gi_rd.cpp b/servers/rendering/renderer_rd/renderer_scene_gi_rd.cpp index 43a4058ab6..98d08f68e8 100644 --- a/servers/rendering/renderer_rd/renderer_scene_gi_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_scene_gi_rd.cpp @@ -1862,7 +1862,7 @@ void RendererSceneGIRD::SDFGI::render_region(RID p_render_buffers, int p_region, #if 0 Vector<uint8_t> data = RD::get_singleton()->texture_get_data(cascades[cascade].sdf, 0); Ref<Image> img; - img.instance(); + img.instantiate(); for (uint32_t i = 0; i < cascade_size; i++) { Vector<uint8_t> subarr = data.subarray(128 * 128 * i, 128 * 128 * (i + 1) - 1); img->create(cascade_size, cascade_size, false, Image::FORMAT_L8, subarr); @@ -1875,7 +1875,7 @@ void RendererSceneGIRD::SDFGI::render_region(RID p_render_buffers, int p_region, #if 0 Vector<uint8_t> data = RD::get_singleton()->texture_get_data(render_albedo, 0); Ref<Image> img; - img.instance(); + img.instantiate(); for (uint32_t i = 0; i < cascade_size; i++) { Vector<uint8_t> subarr = data.subarray(128 * 128 * i * 2, 128 * 128 * (i + 1) * 2 - 1); img->createcascade_size, cascade_size, false, Image::FORMAT_RGB565, subarr); @@ -3029,8 +3029,6 @@ void RendererSceneGIRD::setup_voxel_gi_instances(RID p_render_buffers, const Tra RID voxel_gi_buffer = p_scene_render->render_buffers_get_voxel_gi_buffer(p_render_buffers); - RD::get_singleton()->draw_command_begin_label("VoxelGIs Setup"); - VoxelGIData voxel_gi_data[MAX_VOXEL_GI_INSTANCES]; bool voxel_gi_instances_changed = false; @@ -3078,9 +3076,6 @@ void RendererSceneGIRD::setup_voxel_gi_instances(RID p_render_buffers, const Tra gipd.bias = storage->voxel_gi_get_bias(base_probe); gipd.normal_bias = storage->voxel_gi_get_normal_bias(base_probe); gipd.blend_ambient = !storage->voxel_gi_is_interior(base_probe); - gipd.anisotropy_strength = 0; - gipd.ao = storage->voxel_gi_get_ao(base_probe); - gipd.ao_size = Math::pow(storage->voxel_gi_get_ao_size(base_probe), 4.0f); gipd.mipmaps = gipi->mipmaps.size(); } @@ -3113,10 +3108,12 @@ void RendererSceneGIRD::setup_voxel_gi_instances(RID p_render_buffers, const Tra } if (p_voxel_gi_instances.size() > 0) { + RD::get_singleton()->draw_command_begin_label("VoxelGIs Setup"); + RD::get_singleton()->buffer_update(voxel_gi_buffer, 0, sizeof(VoxelGIData) * MIN((uint64_t)MAX_VOXEL_GI_INSTANCES, p_voxel_gi_instances.size()), voxel_gi_data, RD::BARRIER_MASK_COMPUTE); - } - RD::get_singleton()->draw_command_end_label(); + RD::get_singleton()->draw_command_end_label(); + } } void RendererSceneGIRD::process_gi(RID p_render_buffers, RID p_normal_roughness_buffer, RID p_voxel_gi_buffer, RID p_environment, const CameraMatrix &p_projection, const Transform3D &p_transform, const PagedArray<RID> &p_voxel_gi_instances, RendererSceneRenderRD *p_scene_render) { @@ -3349,6 +3346,7 @@ void RendererSceneGIRD::process_gi(RID p_render_buffers, RID p_normal_roughness_ } else { mode = (use_sdfgi && use_voxel_gi_instances) ? MODE_COMBINED : (use_sdfgi ? MODE_SDFGI : MODE_VOXEL_GI); } + RD::ComputeListID compute_list = RD::get_singleton()->compute_list_begin(true); RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, pipelines[mode]); RD::get_singleton()->compute_list_bind_uniform_set(compute_list, rb->gi.uniform_set, 0); diff --git a/servers/rendering/renderer_rd/renderer_scene_gi_rd.h b/servers/rendering/renderer_rd/renderer_scene_gi_rd.h index 45fc7b3951..128bf09063 100644 --- a/servers/rendering/renderer_rd/renderer_scene_gi_rd.h +++ b/servers/rendering/renderer_rd/renderer_scene_gi_rd.h @@ -611,9 +611,9 @@ public: uint32_t blend_ambient; uint32_t texture_slot; - float anisotropy_strength; - float ao; - float ao_size; + uint32_t pad0; + uint32_t pad1; + uint32_t pad2; uint32_t mipmaps; }; diff --git a/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp b/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp index be98fb42c0..a70514e9e5 100644 --- a/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp @@ -486,7 +486,7 @@ Ref<Image> RendererSceneRenderRD::environment_bake_panorama(RID p_env, bool p_ba color.b *= env->bg_energy; Ref<Image> ret; - ret.instance(); + ret.instantiate(); ret->create(p_size.width, p_size.height, false, Image::FORMAT_RGBAF); for (int i = 0; i < p_size.width; i++) { for (int j = 0; j < p_size.height; j++) { @@ -709,6 +709,10 @@ bool RendererSceneRenderRD::reflection_probe_instance_begin_render(RID p_instanc } } + if (rpi->atlas_index != -1) { // should we fail if this is still -1 ? + atlas->reflections.write[rpi->atlas_index].owner = p_instance; + } + rpi->atlas = p_reflection_atlas; rpi->rendering = true; rpi->dirty = false; @@ -3522,7 +3526,6 @@ void RendererSceneRenderRD::_pre_opaque_render(RenderDataRD *p_render_data, bool Plane camera_plane(p_render_data->cam_transform.origin, -p_render_data->cam_transform.basis.get_axis(Vector3::AXIS_Z)); float lod_distance_multiplier = p_render_data->cam_projection.get_lod_multiplier(); - { for (int i = 0; i < render_state.render_shadow_count; i++) { LightInstance *li = light_instance_owner.getornull(render_state.render_shadows[i].light); @@ -3538,7 +3541,7 @@ void RendererSceneRenderRD::_pre_opaque_render(RenderDataRD *p_render_data, bool //cube shadows are rendered in their own way for (uint32_t i = 0; i < render_state.cube_shadows.size(); i++) { - _render_shadow_pass(render_state.render_shadows[render_state.cube_shadows[i]].light, p_render_data->shadow_atlas, render_state.render_shadows[render_state.cube_shadows[i]].pass, render_state.render_shadows[render_state.cube_shadows[i]].instances, camera_plane, lod_distance_multiplier, p_render_data->screen_lod_threshold, true, true, true); + _render_shadow_pass(render_state.render_shadows[render_state.cube_shadows[i]].light, p_render_data->shadow_atlas, render_state.render_shadows[render_state.cube_shadows[i]].pass, render_state.render_shadows[render_state.cube_shadows[i]].instances, camera_plane, lod_distance_multiplier, p_render_data->screen_lod_threshold, true, true, true, p_render_data->render_info); } if (render_state.directional_shadows.size()) { @@ -3568,11 +3571,11 @@ void RendererSceneRenderRD::_pre_opaque_render(RenderDataRD *p_render_data, bool //render directional shadows for (uint32_t i = 0; i < render_state.directional_shadows.size(); i++) { - _render_shadow_pass(render_state.render_shadows[render_state.directional_shadows[i]].light, p_render_data->shadow_atlas, render_state.render_shadows[render_state.directional_shadows[i]].pass, render_state.render_shadows[render_state.directional_shadows[i]].instances, camera_plane, lod_distance_multiplier, p_render_data->screen_lod_threshold, false, i == render_state.directional_shadows.size() - 1, false); + _render_shadow_pass(render_state.render_shadows[render_state.directional_shadows[i]].light, p_render_data->shadow_atlas, render_state.render_shadows[render_state.directional_shadows[i]].pass, render_state.render_shadows[render_state.directional_shadows[i]].instances, camera_plane, lod_distance_multiplier, p_render_data->screen_lod_threshold, false, i == render_state.directional_shadows.size() - 1, false, p_render_data->render_info); } //render positional shadows for (uint32_t i = 0; i < render_state.shadows.size(); i++) { - _render_shadow_pass(render_state.render_shadows[render_state.shadows[i]].light, p_render_data->shadow_atlas, render_state.render_shadows[render_state.shadows[i]].pass, render_state.render_shadows[render_state.shadows[i]].instances, camera_plane, lod_distance_multiplier, p_render_data->screen_lod_threshold, i == 0, i == render_state.shadows.size() - 1, true); + _render_shadow_pass(render_state.render_shadows[render_state.shadows[i]].light, p_render_data->shadow_atlas, render_state.render_shadows[render_state.shadows[i]].pass, render_state.render_shadows[render_state.shadows[i]].instances, camera_plane, lod_distance_multiplier, p_render_data->screen_lod_threshold, i == 0, i == render_state.shadows.size() - 1, true, p_render_data->render_info); } _render_shadow_process(); @@ -3641,7 +3644,7 @@ void RendererSceneRenderRD::_pre_opaque_render(RenderDataRD *p_render_data, bool } } -void RendererSceneRenderRD::render_scene(RID p_render_buffers, const CameraData *p_camera_data, const PagedArray<GeometryInstance *> &p_instances, const PagedArray<RID> &p_lights, const PagedArray<RID> &p_reflection_probes, const PagedArray<RID> &p_voxel_gi_instances, const PagedArray<RID> &p_decals, const PagedArray<RID> &p_lightmaps, RID p_environment, RID p_camera_effects, RID p_shadow_atlas, RID p_occluder_debug_tex, RID p_reflection_atlas, RID p_reflection_probe, int p_reflection_probe_pass, float p_screen_lod_threshold, const RenderShadowData *p_render_shadows, int p_render_shadow_count, const RenderSDFGIData *p_render_sdfgi_regions, int p_render_sdfgi_region_count, const RenderSDFGIUpdateData *p_sdfgi_update_data) { +void RendererSceneRenderRD::render_scene(RID p_render_buffers, const CameraData *p_camera_data, const PagedArray<GeometryInstance *> &p_instances, const PagedArray<RID> &p_lights, const PagedArray<RID> &p_reflection_probes, const PagedArray<RID> &p_voxel_gi_instances, const PagedArray<RID> &p_decals, const PagedArray<RID> &p_lightmaps, RID p_environment, RID p_camera_effects, RID p_shadow_atlas, RID p_occluder_debug_tex, RID p_reflection_atlas, RID p_reflection_probe, int p_reflection_probe_pass, float p_screen_lod_threshold, const RenderShadowData *p_render_shadows, int p_render_shadow_count, const RenderSDFGIData *p_render_sdfgi_regions, int p_render_sdfgi_region_count, const RenderSDFGIUpdateData *p_sdfgi_update_data, RendererScene::RenderInfo *r_render_info) { // getting this here now so we can direct call a bunch of things more easily RenderBuffers *rb = nullptr; if (p_render_buffers.is_valid()) { @@ -3696,6 +3699,7 @@ void RendererSceneRenderRD::render_scene(RID p_render_buffers, const CameraData render_state.render_sdfgi_regions = p_render_sdfgi_regions; render_state.render_sdfgi_region_count = p_render_sdfgi_region_count; render_state.sdfgi_update_data = p_sdfgi_update_data; + render_data.render_info = r_render_info; } PagedArray<RID> empty; @@ -3759,9 +3763,7 @@ void RendererSceneRenderRD::render_scene(RID p_render_buffers, const CameraData rb->sdfgi->update_light(); } - if (p_voxel_gi_instances.size()) { - gi.setup_voxel_gi_instances(render_data.render_buffers, render_data.cam_transform, *render_data.voxel_gi_instances, render_state.voxel_gi_count, this); - } + gi.setup_voxel_gi_instances(render_data.render_buffers, render_data.cam_transform, *render_data.voxel_gi_instances, render_state.voxel_gi_count, this); } render_state.depth_prepass_used = false; @@ -3808,7 +3810,7 @@ void RendererSceneRenderRD::render_scene(RID p_render_buffers, const CameraData } } -void RendererSceneRenderRD::_render_shadow_pass(RID p_light, RID p_shadow_atlas, int p_pass, const PagedArray<GeometryInstance *> &p_instances, const Plane &p_camera_plane, float p_lod_distance_multiplier, float p_screen_lod_threshold, bool p_open_pass, bool p_close_pass, bool p_clear_region) { +void RendererSceneRenderRD::_render_shadow_pass(RID p_light, RID p_shadow_atlas, int p_pass, const PagedArray<GeometryInstance *> &p_instances, const Plane &p_camera_plane, float p_lod_distance_multiplier, float p_screen_lod_threshold, bool p_open_pass, bool p_close_pass, bool p_clear_region, RendererScene::RenderInfo *p_render_info) { LightInstance *light_instance = light_instance_owner.getornull(p_light); ERR_FAIL_COND(!light_instance); @@ -3954,7 +3956,7 @@ void RendererSceneRenderRD::_render_shadow_pass(RID p_light, RID p_shadow_atlas, if (render_cubemap) { //rendering to cubemap - _render_shadow_append(render_fb, p_instances, light_projection, light_transform, zfar, 0, 0, false, false, use_pancake, p_camera_plane, p_lod_distance_multiplier, p_screen_lod_threshold, Rect2(), false, true, true, true); + _render_shadow_append(render_fb, p_instances, light_projection, light_transform, zfar, 0, 0, false, false, use_pancake, p_camera_plane, p_lod_distance_multiplier, p_screen_lod_threshold, Rect2(), false, true, true, true, p_render_info); if (finalize_cubemap) { _render_shadow_process(); _render_shadow_end(); @@ -3975,7 +3977,7 @@ void RendererSceneRenderRD::_render_shadow_pass(RID p_light, RID p_shadow_atlas, } else { //render shadow - _render_shadow_append(render_fb, p_instances, light_projection, light_transform, zfar, 0, 0, using_dual_paraboloid, using_dual_paraboloid_flip, use_pancake, p_camera_plane, p_lod_distance_multiplier, p_screen_lod_threshold, atlas_rect, flip_y, p_clear_region, p_open_pass, p_close_pass); + _render_shadow_append(render_fb, p_instances, light_projection, light_transform, zfar, 0, 0, using_dual_paraboloid, using_dual_paraboloid_flip, use_pancake, p_camera_plane, p_lod_distance_multiplier, p_screen_lod_threshold, atlas_rect, flip_y, p_clear_region, p_open_pass, p_close_pass, p_render_info); } } @@ -4174,7 +4176,7 @@ TypedArray<Image> RendererSceneRenderRD::bake_render_uv2(RID p_base, const Vecto { PackedByteArray data = RD::get_singleton()->texture_get_data(albedo_alpha_tex, 0); Ref<Image> img; - img.instance(); + img.instantiate(); img->create(p_image_size.width, p_image_size.height, false, Image::FORMAT_RGBA8, data); RD::get_singleton()->free(albedo_alpha_tex); ret.push_back(img); @@ -4183,7 +4185,7 @@ TypedArray<Image> RendererSceneRenderRD::bake_render_uv2(RID p_base, const Vecto { PackedByteArray data = RD::get_singleton()->texture_get_data(normal_tex, 0); Ref<Image> img; - img.instance(); + img.instantiate(); img->create(p_image_size.width, p_image_size.height, false, Image::FORMAT_RGBA8, data); RD::get_singleton()->free(normal_tex); ret.push_back(img); @@ -4192,7 +4194,7 @@ TypedArray<Image> RendererSceneRenderRD::bake_render_uv2(RID p_base, const Vecto { PackedByteArray data = RD::get_singleton()->texture_get_data(orm_tex, 0); Ref<Image> img; - img.instance(); + img.instantiate(); img->create(p_image_size.width, p_image_size.height, false, Image::FORMAT_RGBA8, data); RD::get_singleton()->free(orm_tex); ret.push_back(img); @@ -4201,7 +4203,7 @@ TypedArray<Image> RendererSceneRenderRD::bake_render_uv2(RID p_base, const Vecto { PackedByteArray data = RD::get_singleton()->texture_get_data(emission_tex, 0); Ref<Image> img; - img.instance(); + img.instantiate(); img->create(p_image_size.width, p_image_size.height, false, Image::FORMAT_RGBAH, data); RD::get_singleton()->free(emission_tex); ret.push_back(img); diff --git a/servers/rendering/renderer_rd/renderer_scene_render_rd.h b/servers/rendering/renderer_rd/renderer_scene_render_rd.h index 9a793e42c5..be3d3551c7 100644 --- a/servers/rendering/renderer_rd/renderer_scene_render_rd.h +++ b/servers/rendering/renderer_rd/renderer_scene_render_rd.h @@ -40,6 +40,7 @@ #include "servers/rendering/renderer_rd/renderer_scene_sky_rd.h" #include "servers/rendering/renderer_rd/renderer_storage_rd.h" #include "servers/rendering/renderer_rd/shaders/volumetric_fog.glsl.gen.h" +#include "servers/rendering/renderer_scene.h" #include "servers/rendering/renderer_scene_render.h" #include "servers/rendering/rendering_device.h" @@ -79,6 +80,8 @@ struct RenderDataRD { uint32_t cluster_max_elements = 0; uint32_t directional_light_count = 0; + + RendererScene::RenderInfo *render_info = nullptr; }; class RendererSceneRenderRD : public RendererSceneRender { @@ -103,7 +106,7 @@ protected: virtual void _render_scene(RenderDataRD *p_render_data, const Color &p_default_color) = 0; virtual void _render_shadow_begin() = 0; - virtual void _render_shadow_append(RID p_framebuffer, const PagedArray<GeometryInstance *> &p_instances, const CameraMatrix &p_projection, const Transform3D &p_transform, float p_zfar, float p_bias, float p_normal_bias, bool p_use_dp, bool p_use_dp_flip, bool p_use_pancake, const Plane &p_camera_plane = Plane(), float p_lod_distance_multiplier = 0.0, float p_screen_lod_threshold = 0.0, const Rect2i &p_rect = Rect2i(), bool p_flip_y = false, bool p_clear_region = true, bool p_begin = true, bool p_end = true) = 0; + virtual void _render_shadow_append(RID p_framebuffer, const PagedArray<GeometryInstance *> &p_instances, const CameraMatrix &p_projection, const Transform3D &p_transform, float p_zfar, float p_bias, float p_normal_bias, bool p_use_dp, bool p_use_dp_flip, bool p_use_pancake, const Plane &p_camera_plane = Plane(), float p_lod_distance_multiplier = 0.0, float p_screen_lod_threshold = 0.0, const Rect2i &p_rect = Rect2i(), bool p_flip_y = false, bool p_clear_region = true, bool p_begin = true, bool p_end = true, RendererScene::RenderInfo *p_render_info = nullptr) = 0; virtual void _render_shadow_process() = 0; virtual void _render_shadow_end(uint32_t p_barrier = RD::BARRIER_MASK_ALL) = 0; @@ -746,7 +749,7 @@ private: uint32_t max_cluster_elements = 512; - void _render_shadow_pass(RID p_light, RID p_shadow_atlas, int p_pass, const PagedArray<GeometryInstance *> &p_instances, const Plane &p_camera_plane = Plane(), float p_lod_distance_multiplier = 0, float p_screen_lod_threshold = 0.0, bool p_open_pass = true, bool p_close_pass = true, bool p_clear_region = true); + void _render_shadow_pass(RID p_light, RID p_shadow_atlas, int p_pass, const PagedArray<GeometryInstance *> &p_instances, const Plane &p_camera_plane = Plane(), float p_lod_distance_multiplier = 0, float p_screen_lod_threshold = 0.0, bool p_open_pass = true, bool p_close_pass = true, bool p_clear_region = true, RendererScene::RenderInfo *p_render_info = nullptr); public: virtual Transform3D geometry_instance_get_transform(GeometryInstance *p_instance) = 0; @@ -754,10 +757,10 @@ public: /* SHADOW ATLAS API */ - RID shadow_atlas_create(); - void shadow_atlas_set_size(RID p_atlas, int p_size, bool p_16_bits = false); - void shadow_atlas_set_quadrant_subdivision(RID p_atlas, int p_quadrant, int p_subdivision); - bool shadow_atlas_update_light(RID p_atlas, RID p_light_intance, float p_coverage, uint64_t p_light_version); + virtual RID shadow_atlas_create() override; + virtual void shadow_atlas_set_size(RID p_atlas, int p_size, bool p_16_bits = false) override; + virtual void shadow_atlas_set_quadrant_subdivision(RID p_atlas, int p_quadrant, int p_subdivision) override; + virtual bool shadow_atlas_update_light(RID p_atlas, RID p_light_intance, float p_coverage, uint64_t p_light_version) override; _FORCE_INLINE_ bool shadow_atlas_owns_light_instance(RID p_atlas, RID p_light_intance) { ShadowAtlas *atlas = shadow_atlas_owner.getornull(p_atlas); ERR_FAIL_COND_V(!atlas, false); @@ -776,9 +779,9 @@ public: return Size2(atlas->size, atlas->size); } - void directional_shadow_atlas_set_size(int p_size, bool p_16_bits = false); - int get_directional_light_shadow_size(RID p_light_intance); - void set_directional_shadow_count(int p_count); + virtual void directional_shadow_atlas_set_size(int p_size, bool p_16_bits = false) override; + virtual int get_directional_light_shadow_size(RID p_light_intance) override; + virtual void set_directional_shadow_count(int p_count) override; _FORCE_INLINE_ RID directional_shadow_get_texture() { return directional_shadow.depth; @@ -790,43 +793,43 @@ public: /* SDFGI UPDATE */ - virtual void sdfgi_update(RID p_render_buffers, RID p_environment, const Vector3 &p_world_position); - virtual int sdfgi_get_pending_region_count(RID p_render_buffers) const; - virtual AABB sdfgi_get_pending_region_bounds(RID p_render_buffers, int p_region) const; - virtual uint32_t sdfgi_get_pending_region_cascade(RID p_render_buffers, int p_region) const; + virtual void sdfgi_update(RID p_render_buffers, RID p_environment, const Vector3 &p_world_position) override; + virtual int sdfgi_get_pending_region_count(RID p_render_buffers) const override; + virtual AABB sdfgi_get_pending_region_bounds(RID p_render_buffers, int p_region) const override; + virtual uint32_t sdfgi_get_pending_region_cascade(RID p_render_buffers, int p_region) const override; RID sdfgi_get_ubo() const { return gi.sdfgi_ubo; } /* SKY API */ - virtual RID sky_allocate(); - virtual void sky_initialize(RID p_rid); + virtual RID sky_allocate() override; + virtual void sky_initialize(RID p_rid) override; - void sky_set_radiance_size(RID p_sky, int p_radiance_size); - void sky_set_mode(RID p_sky, RS::SkyMode p_mode); - void sky_set_material(RID p_sky, RID p_material); - Ref<Image> sky_bake_panorama(RID p_sky, float p_energy, bool p_bake_irradiance, const Size2i &p_size); + virtual void sky_set_radiance_size(RID p_sky, int p_radiance_size) override; + virtual void sky_set_mode(RID p_sky, RS::SkyMode p_mode) override; + virtual void sky_set_material(RID p_sky, RID p_material) override; + virtual Ref<Image> sky_bake_panorama(RID p_sky, float p_energy, bool p_bake_irradiance, const Size2i &p_size) override; /* ENVIRONMENT API */ - virtual RID environment_allocate(); - virtual void environment_initialize(RID p_rid); + virtual RID environment_allocate() override; + virtual void environment_initialize(RID p_rid) override; - void environment_set_background(RID p_env, RS::EnvironmentBG p_bg); - void environment_set_sky(RID p_env, RID p_sky); - void environment_set_sky_custom_fov(RID p_env, float p_scale); - void environment_set_sky_orientation(RID p_env, const Basis &p_orientation); - void environment_set_bg_color(RID p_env, const Color &p_color); - void environment_set_bg_energy(RID p_env, float p_energy); - void environment_set_canvas_max_layer(RID p_env, int p_max_layer); - void environment_set_ambient_light(RID p_env, const Color &p_color, RS::EnvironmentAmbientSource p_ambient = RS::ENV_AMBIENT_SOURCE_BG, float p_energy = 1.0, float p_sky_contribution = 0.0, RS::EnvironmentReflectionSource p_reflection_source = RS::ENV_REFLECTION_SOURCE_BG, const Color &p_ao_color = Color()); + virtual void environment_set_background(RID p_env, RS::EnvironmentBG p_bg) override; + virtual void environment_set_sky(RID p_env, RID p_sky) override; + virtual void environment_set_sky_custom_fov(RID p_env, float p_scale) override; + virtual void environment_set_sky_orientation(RID p_env, const Basis &p_orientation) override; + virtual void environment_set_bg_color(RID p_env, const Color &p_color) override; + virtual void environment_set_bg_energy(RID p_env, float p_energy) override; + virtual void environment_set_canvas_max_layer(RID p_env, int p_max_layer) override; + virtual void environment_set_ambient_light(RID p_env, const Color &p_color, RS::EnvironmentAmbientSource p_ambient = RS::ENV_AMBIENT_SOURCE_BG, float p_energy = 1.0, float p_sky_contribution = 0.0, RS::EnvironmentReflectionSource p_reflection_source = RS::ENV_REFLECTION_SOURCE_BG, const Color &p_ao_color = Color()) override; - RS::EnvironmentBG environment_get_background(RID p_env) const; + virtual RS::EnvironmentBG environment_get_background(RID p_env) const override; RID environment_get_sky(RID p_env) const; float environment_get_sky_custom_fov(RID p_env) const; Basis environment_get_sky_orientation(RID p_env) const; Color environment_get_bg_color(RID p_env) const; float environment_get_bg_energy(RID p_env) const; - int environment_get_canvas_max_layer(RID p_env) const; + virtual int environment_get_canvas_max_layer(RID p_env) const override; Color environment_get_ambient_light_color(RID p_env) const; RS::EnvironmentAmbientSource environment_get_ambient_source(RID p_env) const; float environment_get_ambient_light_energy(RID p_env) const; @@ -834,13 +837,13 @@ public: RS::EnvironmentReflectionSource environment_get_reflection_source(RID p_env) const; Color environment_get_ao_color(RID p_env) const; - bool is_environment(RID p_env) const; + virtual bool is_environment(RID p_env) const override; - void environment_set_glow(RID p_env, bool p_enable, Vector<float> p_levels, float p_intensity, float p_strength, float p_mix, float p_bloom_threshold, RS::EnvironmentGlowBlendMode p_blend_mode, float p_hdr_bleed_threshold, float p_hdr_bleed_scale, float p_hdr_luminance_cap); - void environment_glow_set_use_bicubic_upscale(bool p_enable); - void environment_glow_set_use_high_quality(bool p_enable); + virtual void environment_set_glow(RID p_env, bool p_enable, Vector<float> p_levels, float p_intensity, float p_strength, float p_mix, float p_bloom_threshold, RS::EnvironmentGlowBlendMode p_blend_mode, float p_hdr_bleed_threshold, float p_hdr_bleed_scale, float p_hdr_luminance_cap) override; + virtual void environment_glow_set_use_bicubic_upscale(bool p_enable) override; + virtual void environment_glow_set_use_high_quality(bool p_enable) override; - void environment_set_fog(RID p_env, bool p_enable, const Color &p_light_color, float p_light_energy, float p_sun_scatter, float p_density, float p_height, float p_height_density, float p_aerial_perspective); + virtual void environment_set_fog(RID p_env, bool p_enable, const Color &p_light_color, float p_light_energy, float p_sun_scatter, float p_density, float p_height, float p_height_density, float p_aerial_perspective) override; bool environment_is_fog_enabled(RID p_env) const; Color environment_get_fog_light_color(RID p_env) const; float environment_get_fog_light_energy(RID p_env) const; @@ -850,47 +853,47 @@ public: float environment_get_fog_height_density(RID p_env) const; float environment_get_fog_aerial_perspective(RID p_env) const; - void environment_set_volumetric_fog(RID p_env, bool p_enable, float p_density, const Color &p_light, float p_light_energy, float p_length, float p_detail_spread, float p_gi_inject, bool p_temporal_reprojection, float p_temporal_reprojection_amount); + virtual void environment_set_volumetric_fog(RID p_env, bool p_enable, float p_density, const Color &p_light, float p_light_energy, float p_length, float p_detail_spread, float p_gi_inject, bool p_temporal_reprojection, float p_temporal_reprojection_amount) override; - virtual void environment_set_volumetric_fog_volume_size(int p_size, int p_depth); - virtual void environment_set_volumetric_fog_filter_active(bool p_enable); + virtual void environment_set_volumetric_fog_volume_size(int p_size, int p_depth) override; + virtual void environment_set_volumetric_fog_filter_active(bool p_enable) override; - void environment_set_ssr(RID p_env, bool p_enable, int p_max_steps, float p_fade_int, float p_fade_out, float p_depth_tolerance); - void environment_set_ssao(RID p_env, bool p_enable, float p_radius, float p_intensity, float p_power, float p_detail, float p_horizon, float p_sharpness, float p_light_affect, float p_ao_channel_affect); - void environment_set_ssao_quality(RS::EnvironmentSSAOQuality p_quality, bool p_half_size, float p_adaptive_target, int p_blur_passes, float p_fadeout_from, float p_fadeout_to); + virtual void environment_set_ssr(RID p_env, bool p_enable, int p_max_steps, float p_fade_int, float p_fade_out, float p_depth_tolerance) override; + virtual void environment_set_ssao(RID p_env, bool p_enable, float p_radius, float p_intensity, float p_power, float p_detail, float p_horizon, float p_sharpness, float p_light_affect, float p_ao_channel_affect) override; + virtual void environment_set_ssao_quality(RS::EnvironmentSSAOQuality p_quality, bool p_half_size, float p_adaptive_target, int p_blur_passes, float p_fadeout_from, float p_fadeout_to) override; bool environment_is_ssao_enabled(RID p_env) const; float environment_get_ssao_ao_affect(RID p_env) const; float environment_get_ssao_light_affect(RID p_env) const; bool environment_is_ssr_enabled(RID p_env) const; bool environment_is_sdfgi_enabled(RID p_env) const; - virtual void environment_set_sdfgi(RID p_env, bool p_enable, RS::EnvironmentSDFGICascades p_cascades, float p_min_cell_size, RS::EnvironmentSDFGIYScale p_y_scale, bool p_use_occlusion, float p_bounce_feedback, bool p_read_sky, float p_energy, float p_normal_bias, float p_probe_bias); - virtual void environment_set_sdfgi_ray_count(RS::EnvironmentSDFGIRayCount p_ray_count); - virtual void environment_set_sdfgi_frames_to_converge(RS::EnvironmentSDFGIFramesToConverge p_frames); - virtual void environment_set_sdfgi_frames_to_update_light(RS::EnvironmentSDFGIFramesToUpdateLight p_update); + virtual void environment_set_sdfgi(RID p_env, bool p_enable, RS::EnvironmentSDFGICascades p_cascades, float p_min_cell_size, RS::EnvironmentSDFGIYScale p_y_scale, bool p_use_occlusion, float p_bounce_feedback, bool p_read_sky, float p_energy, float p_normal_bias, float p_probe_bias) override; + virtual void environment_set_sdfgi_ray_count(RS::EnvironmentSDFGIRayCount p_ray_count) override; + virtual void environment_set_sdfgi_frames_to_converge(RS::EnvironmentSDFGIFramesToConverge p_frames) override; + virtual void environment_set_sdfgi_frames_to_update_light(RS::EnvironmentSDFGIFramesToUpdateLight p_update) override; - void environment_set_ssr_roughness_quality(RS::EnvironmentSSRRoughnessQuality p_quality); + virtual void environment_set_ssr_roughness_quality(RS::EnvironmentSSRRoughnessQuality p_quality) override; RS::EnvironmentSSRRoughnessQuality environment_get_ssr_roughness_quality() const; - void environment_set_tonemap(RID p_env, RS::EnvironmentToneMapper p_tone_mapper, float p_exposure, float p_white, bool p_auto_exposure, float p_min_luminance, float p_max_luminance, float p_auto_exp_speed, float p_auto_exp_scale); - void environment_set_adjustment(RID p_env, bool p_enable, float p_brightness, float p_contrast, float p_saturation, bool p_use_1d_color_correction, RID p_color_correction); + virtual void environment_set_tonemap(RID p_env, RS::EnvironmentToneMapper p_tone_mapper, float p_exposure, float p_white, bool p_auto_exposure, float p_min_luminance, float p_max_luminance, float p_auto_exp_speed, float p_auto_exp_scale) override; + virtual void environment_set_adjustment(RID p_env, bool p_enable, float p_brightness, float p_contrast, float p_saturation, bool p_use_1d_color_correction, RID p_color_correction) override; - virtual Ref<Image> environment_bake_panorama(RID p_env, bool p_bake_irradiance, const Size2i &p_size); + virtual Ref<Image> environment_bake_panorama(RID p_env, bool p_bake_irradiance, const Size2i &p_size) override; - virtual RID camera_effects_allocate(); - virtual void camera_effects_initialize(RID p_rid); + virtual RID camera_effects_allocate() override; + virtual void camera_effects_initialize(RID p_rid) override; - virtual void camera_effects_set_dof_blur_quality(RS::DOFBlurQuality p_quality, bool p_use_jitter); - virtual void camera_effects_set_dof_blur_bokeh_shape(RS::DOFBokehShape p_shape); + virtual void camera_effects_set_dof_blur_quality(RS::DOFBlurQuality p_quality, bool p_use_jitter) override; + virtual void camera_effects_set_dof_blur_bokeh_shape(RS::DOFBokehShape p_shape) override; - virtual void camera_effects_set_dof_blur(RID p_camera_effects, bool p_far_enable, float p_far_distance, float p_far_transition, bool p_near_enable, float p_near_distance, float p_near_transition, float p_amount); - virtual void camera_effects_set_custom_exposure(RID p_camera_effects, bool p_enable, float p_exposure); + virtual void camera_effects_set_dof_blur(RID p_camera_effects, bool p_far_enable, float p_far_distance, float p_far_transition, bool p_near_enable, float p_near_distance, float p_near_transition, float p_amount) override; + virtual void camera_effects_set_custom_exposure(RID p_camera_effects, bool p_enable, float p_exposure) override; - RID light_instance_create(RID p_light); - void light_instance_set_transform(RID p_light_instance, const Transform3D &p_transform); - void light_instance_set_aabb(RID p_light_instance, const AABB &p_aabb); - void light_instance_set_shadow_transform(RID p_light_instance, const CameraMatrix &p_projection, const Transform3D &p_transform, float p_far, float p_split, int p_pass, float p_shadow_texel_size, float p_bias_scale = 1.0, float p_range_begin = 0, const Vector2 &p_uv_scale = Vector2()); - void light_instance_mark_visible(RID p_light_instance); + virtual RID light_instance_create(RID p_light) override; + virtual void light_instance_set_transform(RID p_light_instance, const Transform3D &p_transform) override; + virtual void light_instance_set_aabb(RID p_light_instance, const AABB &p_aabb) override; + virtual void light_instance_set_shadow_transform(RID p_light_instance, const CameraMatrix &p_projection, const Transform3D &p_transform, float p_far, float p_split, int p_pass, float p_shadow_texel_size, float p_bias_scale = 1.0, float p_range_begin = 0, const Vector2 &p_uv_scale = Vector2()) override; + virtual void light_instance_mark_visible(RID p_light_instance) override; _FORCE_INLINE_ RID light_instance_get_base_light(RID p_light_instance) { LightInstance *li = light_instance_owner.getornull(p_light_instance); @@ -1017,9 +1020,9 @@ public: return li->light_type; } - virtual RID reflection_atlas_create(); - virtual void reflection_atlas_set_size(RID p_ref_atlas, int p_reflection_size, int p_reflection_count); - virtual int reflection_atlas_get_size(RID p_ref_atlas) const; + virtual RID reflection_atlas_create() override; + virtual void reflection_atlas_set_size(RID p_ref_atlas, int p_reflection_size, int p_reflection_count) override; + virtual int reflection_atlas_get_size(RID p_ref_atlas) const override; _FORCE_INLINE_ RID reflection_atlas_get_texture(RID p_ref_atlas) { ReflectionAtlas *atlas = reflection_atlas_owner.getornull(p_ref_atlas); @@ -1027,13 +1030,13 @@ public: return atlas->reflection; } - virtual RID reflection_probe_instance_create(RID p_probe); - virtual void reflection_probe_instance_set_transform(RID p_instance, const Transform3D &p_transform); - virtual void reflection_probe_release_atlas_index(RID p_instance); - virtual bool reflection_probe_instance_needs_redraw(RID p_instance); - virtual bool reflection_probe_instance_has_reflection(RID p_instance); - virtual bool reflection_probe_instance_begin_render(RID p_instance, RID p_reflection_atlas); - virtual bool reflection_probe_instance_postprocess_step(RID p_instance); + virtual RID reflection_probe_instance_create(RID p_probe) override; + virtual void reflection_probe_instance_set_transform(RID p_instance, const Transform3D &p_transform) override; + virtual void reflection_probe_release_atlas_index(RID p_instance) override; + virtual bool reflection_probe_instance_needs_redraw(RID p_instance) override; + virtual bool reflection_probe_instance_has_reflection(RID p_instance) override; + virtual bool reflection_probe_instance_begin_render(RID p_instance, RID p_reflection_atlas) override; + virtual bool reflection_probe_instance_postprocess_step(RID p_instance) override; uint32_t reflection_probe_instance_get_resolution(RID p_instance); RID reflection_probe_instance_get_framebuffer(RID p_instance, int p_index); @@ -1086,8 +1089,8 @@ public: return rpi->atlas_index; } - virtual RID decal_instance_create(RID p_decal); - virtual void decal_instance_set_transform(RID p_decal, const Transform3D &p_transform); + virtual RID decal_instance_create(RID p_decal) override; + virtual void decal_instance_set_transform(RID p_decal, const Transform3D &p_transform) override; _FORCE_INLINE_ RID decal_instance_get_base(RID p_decal) const { DecalInstance *decal = decal_instance_owner.getornull(p_decal); @@ -1099,8 +1102,8 @@ public: return decal->transform; } - virtual RID lightmap_instance_create(RID p_lightmap); - virtual void lightmap_instance_set_transform(RID p_lightmap, const Transform3D &p_transform); + virtual RID lightmap_instance_create(RID p_lightmap) override; + virtual void lightmap_instance_set_transform(RID p_lightmap, const Transform3D &p_transform) override; _FORCE_INLINE_ bool lightmap_instance_is_valid(RID p_lightmap_instance) { return lightmap_instance_owner.getornull(p_lightmap_instance) != nullptr; } @@ -1118,17 +1121,17 @@ public: /* gi light probes */ - RID voxel_gi_instance_create(RID p_base); - void voxel_gi_instance_set_transform_to_data(RID p_probe, const Transform3D &p_xform); - bool voxel_gi_needs_update(RID p_probe) const; - void voxel_gi_update(RID p_probe, bool p_update_light_instances, const Vector<RID> &p_light_instances, const PagedArray<RendererSceneRender::GeometryInstance *> &p_dynamic_objects); - void voxel_gi_set_quality(RS::VoxelGIQuality p_quality) { gi.voxel_gi_quality = p_quality; } + virtual RID voxel_gi_instance_create(RID p_base) override; + virtual void voxel_gi_instance_set_transform_to_data(RID p_probe, const Transform3D &p_xform) override; + virtual bool voxel_gi_needs_update(RID p_probe) const override; + virtual void voxel_gi_update(RID p_probe, bool p_update_light_instances, const Vector<RID> &p_light_instances, const PagedArray<RendererSceneRender::GeometryInstance *> &p_dynamic_objects) override; + virtual void voxel_gi_set_quality(RS::VoxelGIQuality p_quality) override { gi.voxel_gi_quality = p_quality; } /* render buffers */ - RID render_buffers_create(); - void render_buffers_configure(RID p_render_buffers, RID p_render_target, int p_width, int p_height, RS::ViewportMSAA p_msaa, RS::ViewportScreenSpaceAA p_screen_space_aa, bool p_use_debanding, uint32_t p_view_count); - void gi_set_use_half_resolution(bool p_enable); + virtual RID render_buffers_create() override; + virtual void render_buffers_configure(RID p_render_buffers, RID p_render_target, int p_width, int p_height, RS::ViewportMSAA p_msaa, RS::ViewportScreenSpaceAA p_screen_space_aa, bool p_use_debanding, uint32_t p_view_count) override; + virtual void gi_set_use_half_resolution(bool p_enable) override; RID render_buffers_get_ao_texture(RID p_render_buffers); RID render_buffers_get_back_buffer_texture(RID p_render_buffers); @@ -1156,30 +1159,30 @@ public: float render_buffers_get_volumetric_fog_end(RID p_render_buffers); float render_buffers_get_volumetric_fog_detail_spread(RID p_render_buffers); - void render_scene(RID p_render_buffers, const CameraData *p_camera_data, const PagedArray<GeometryInstance *> &p_instances, const PagedArray<RID> &p_lights, const PagedArray<RID> &p_reflection_probes, const PagedArray<RID> &p_voxel_gi_instances, const PagedArray<RID> &p_decals, const PagedArray<RID> &p_lightmaps, RID p_environment, RID p_camera_effects, RID p_shadow_atlas, RID p_occluder_debug_tex, RID p_reflection_atlas, RID p_reflection_probe, int p_reflection_probe_pass, float p_screen_lod_threshold, const RenderShadowData *p_render_shadows, int p_render_shadow_count, const RenderSDFGIData *p_render_sdfgi_regions, int p_render_sdfgi_region_count, const RenderSDFGIUpdateData *p_sdfgi_update_data = nullptr); + virtual void render_scene(RID p_render_buffers, const CameraData *p_camera_data, const PagedArray<GeometryInstance *> &p_instances, const PagedArray<RID> &p_lights, const PagedArray<RID> &p_reflection_probes, const PagedArray<RID> &p_voxel_gi_instances, const PagedArray<RID> &p_decals, const PagedArray<RID> &p_lightmaps, RID p_environment, RID p_camera_effects, RID p_shadow_atlas, RID p_occluder_debug_tex, RID p_reflection_atlas, RID p_reflection_probe, int p_reflection_probe_pass, float p_screen_lod_threshold, const RenderShadowData *p_render_shadows, int p_render_shadow_count, const RenderSDFGIData *p_render_sdfgi_regions, int p_render_sdfgi_region_count, const RenderSDFGIUpdateData *p_sdfgi_update_data = nullptr, RendererScene::RenderInfo *r_render_info = nullptr) override; - void render_material(const Transform3D &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, const PagedArray<GeometryInstance *> &p_instances, RID p_framebuffer, const Rect2i &p_region); + virtual void render_material(const Transform3D &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, const PagedArray<GeometryInstance *> &p_instances, RID p_framebuffer, const Rect2i &p_region) override; - void render_particle_collider_heightfield(RID p_collider, const Transform3D &p_transform, const PagedArray<GeometryInstance *> &p_instances); + virtual void render_particle_collider_heightfield(RID p_collider, const Transform3D &p_transform, const PagedArray<GeometryInstance *> &p_instances) override; - virtual void set_scene_pass(uint64_t p_pass) { + virtual void set_scene_pass(uint64_t p_pass) override { scene_pass = p_pass; } _FORCE_INLINE_ uint64_t get_scene_pass() { return scene_pass; } - virtual void screen_space_roughness_limiter_set_active(bool p_enable, float p_amount, float p_limit); - virtual bool screen_space_roughness_limiter_is_active() const; + virtual void screen_space_roughness_limiter_set_active(bool p_enable, float p_amount, float p_limit) override; + virtual bool screen_space_roughness_limiter_is_active() const override; virtual float screen_space_roughness_limiter_get_amount() const; virtual float screen_space_roughness_limiter_get_limit() const; - virtual void sub_surface_scattering_set_quality(RS::SubSurfaceScatteringQuality p_quality); + virtual void sub_surface_scattering_set_quality(RS::SubSurfaceScatteringQuality p_quality) override; RS::SubSurfaceScatteringQuality sub_surface_scattering_get_quality() const; - virtual void sub_surface_scattering_set_scale(float p_scale, float p_depth_scale); + virtual void sub_surface_scattering_set_scale(float p_scale, float p_depth_scale) override; - virtual void shadows_quality_set(RS::ShadowQuality p_quality); - virtual void directional_shadow_quality_set(RS::ShadowQuality p_quality); + virtual void shadows_quality_set(RS::ShadowQuality p_quality) override; + virtual void directional_shadow_quality_set(RS::ShadowQuality p_quality) override; _FORCE_INLINE_ RS::ShadowQuality shadows_quality_get() const { return shadows_quality; } _FORCE_INLINE_ RS::ShadowQuality directional_shadow_quality_get() const { return directional_shadow_quality; } _FORCE_INLINE_ float shadows_quality_radius_get() const { return shadows_quality_radius; } @@ -1198,18 +1201,18 @@ public: int get_roughness_layers() const; bool is_using_radiance_cubemap_array() const; - virtual TypedArray<Image> bake_render_uv2(RID p_base, const Vector<RID> &p_material_overrides, const Size2i &p_image_size); + virtual TypedArray<Image> bake_render_uv2(RID p_base, const Vector<RID> &p_material_overrides, const Size2i &p_image_size) override; - virtual bool free(RID p_rid); + virtual bool free(RID p_rid) override; - virtual void update(); + virtual void update() override; - virtual void set_debug_draw_mode(RS::ViewportDebugDraw p_debug_draw); + virtual void set_debug_draw_mode(RS::ViewportDebugDraw p_debug_draw) override; _FORCE_INLINE_ RS::ViewportDebugDraw get_debug_draw_mode() const { return debug_draw; } - void set_time(double p_time, double p_step); + virtual void set_time(double p_time, double p_step) override; RID get_reflection_probe_buffer(); RID get_omni_light_buffer(); @@ -1218,7 +1221,7 @@ public: RID get_decal_buffer(); int get_max_directional_lights() const; - void sdfgi_set_debug_probe_select(const Vector3 &p_position, const Vector3 &p_dir); + virtual void sdfgi_set_debug_probe_select(const Vector3 &p_position, const Vector3 &p_dir) override; virtual bool is_dynamic_gi_supported() const; virtual bool is_clustered_enabled() const; diff --git a/servers/rendering/renderer_rd/renderer_scene_sky_rd.cpp b/servers/rendering/renderer_rd/renderer_scene_sky_rd.cpp index 1aa01dd16e..e701219617 100644 --- a/servers/rendering/renderer_rd/renderer_scene_sky_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_scene_sky_rd.cpp @@ -230,96 +230,73 @@ RendererSceneSkyRD::SkyShaderData::~SkyShaderData() { //////////////////////////////////////////////////////////////////////////////// // Sky material -void RendererSceneSkyRD::SkyMaterialData::update_parameters(const Map<StringName, Variant> &p_parameters, bool p_uniform_dirty, bool p_textures_dirty) { +bool RendererSceneSkyRD::SkyMaterialData::update_parameters(const Map<StringName, Variant> &p_parameters, bool p_uniform_dirty, bool p_textures_dirty) { RendererSceneRenderRD *scene_singleton = (RendererSceneRenderRD *)RendererSceneRenderRD::singleton; uniform_set_updated = true; - if ((uint32_t)ubo_data.size() != shader_data->ubo_size) { - p_uniform_dirty = true; - if (uniform_buffer.is_valid()) { - RD::get_singleton()->free(uniform_buffer); - uniform_buffer = RID(); - } - - ubo_data.resize(shader_data->ubo_size); - if (ubo_data.size()) { - uniform_buffer = RD::get_singleton()->uniform_buffer_create(ubo_data.size()); - memset(ubo_data.ptrw(), 0, ubo_data.size()); //clear - } - - //clear previous uniform set - if (uniform_set.is_valid() && RD::get_singleton()->uniform_set_is_valid(uniform_set)) { - RD::get_singleton()->free(uniform_set); - uniform_set = RID(); - } - } - - //check whether buffer changed - if (p_uniform_dirty && ubo_data.size()) { - update_uniform_buffer(shader_data->uniforms, shader_data->ubo_offsets.ptr(), p_parameters, ubo_data.ptrw(), ubo_data.size(), false); - RD::get_singleton()->buffer_update(uniform_buffer, 0, ubo_data.size(), ubo_data.ptrw()); - } + return update_parameters_uniform_set(p_parameters, p_uniform_dirty, p_textures_dirty, shader_data->uniforms, shader_data->ubo_offsets.ptr(), shader_data->texture_uniforms, shader_data->default_texture_params, shader_data->ubo_size, uniform_set, scene_singleton->sky.sky_shader.shader.version_get_shader(shader_data->version, 0), SKY_SET_MATERIAL); +} - uint32_t tex_uniform_count = shader_data->texture_uniforms.size(); +RendererSceneSkyRD::SkyMaterialData::~SkyMaterialData() { + free_parameters_uniform_set(uniform_set); +} - if ((uint32_t)texture_cache.size() != tex_uniform_count) { - texture_cache.resize(tex_uniform_count); - p_textures_dirty = true; +//////////////////////////////////////////////////////////////////////////////// +// Render sky + +static _FORCE_INLINE_ void store_transform_3x3(const Basis &p_basis, float *p_array) { + p_array[0] = p_basis.elements[0][0]; + p_array[1] = p_basis.elements[1][0]; + p_array[2] = p_basis.elements[2][0]; + p_array[3] = 0; + p_array[4] = p_basis.elements[0][1]; + p_array[5] = p_basis.elements[1][1]; + p_array[6] = p_basis.elements[2][1]; + p_array[7] = 0; + p_array[8] = p_basis.elements[0][2]; + p_array[9] = p_basis.elements[1][2]; + p_array[10] = p_basis.elements[2][2]; + p_array[11] = 0; +} - //clear previous uniform set - if (uniform_set.is_valid() && RD::get_singleton()->uniform_set_is_valid(uniform_set)) { - RD::get_singleton()->free(uniform_set); - uniform_set = RID(); - } - } +void RendererSceneSkyRD::_render_sky(RD::DrawListID p_list, float p_time, RID p_fb, PipelineCacheRD *p_pipeline, RID p_uniform_set, RID p_texture_set, uint32_t p_view_count, const CameraMatrix *p_projections, const Basis &p_orientation, float p_multiplier, const Vector3 &p_position) { + SkyPushConstant sky_push_constant; - if (p_textures_dirty && tex_uniform_count) { - update_textures(p_parameters, shader_data->default_texture_params, shader_data->texture_uniforms, texture_cache.ptrw(), true); - } + memset(&sky_push_constant, 0, sizeof(SkyPushConstant)); - if (shader_data->ubo_size == 0 && shader_data->texture_uniforms.size() == 0) { - // This material does not require an uniform set, so don't create it. - return; + for (uint32_t v = 0; v < p_view_count; v++) { + // We only need key components of our projection matrix + sky_push_constant.projections[v][0] = p_projections[v].matrix[2][0]; + sky_push_constant.projections[v][1] = p_projections[v].matrix[0][0]; + sky_push_constant.projections[v][2] = p_projections[v].matrix[2][1]; + sky_push_constant.projections[v][3] = p_projections[v].matrix[1][1]; } + sky_push_constant.position[0] = p_position.x; + sky_push_constant.position[1] = p_position.y; + sky_push_constant.position[2] = p_position.z; + sky_push_constant.multiplier = p_multiplier; + sky_push_constant.time = p_time; + store_transform_3x3(p_orientation, sky_push_constant.orientation); - if (!p_textures_dirty && uniform_set.is_valid() && RD::get_singleton()->uniform_set_is_valid(uniform_set)) { - //no reason to update uniform set, only UBO (or nothing) was needed to update - return; - } + RenderingDevice::FramebufferFormatID fb_format = RD::get_singleton()->framebuffer_get_format(p_fb); - Vector<RD::Uniform> uniforms; + RD::DrawListID draw_list = p_list; - { - if (shader_data->ubo_size) { - RD::Uniform u; - u.uniform_type = RD::UNIFORM_TYPE_UNIFORM_BUFFER; - u.binding = 0; - u.ids.push_back(uniform_buffer); - uniforms.push_back(u); - } + RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, p_pipeline->get_render_pipeline(RD::INVALID_ID, fb_format)); - const RID *textures = texture_cache.ptrw(); - for (uint32_t i = 0; i < tex_uniform_count; i++) { - RD::Uniform u; - u.uniform_type = RD::UNIFORM_TYPE_TEXTURE; - u.binding = 1 + i; - u.ids.push_back(textures[i]); - uniforms.push_back(u); - } + RD::get_singleton()->draw_list_bind_uniform_set(draw_list, sky_scene_state.uniform_set, 0); + if (p_uniform_set.is_valid()) { //material may not have uniform set + RD::get_singleton()->draw_list_bind_uniform_set(draw_list, p_uniform_set, 1); } + RD::get_singleton()->draw_list_bind_uniform_set(draw_list, p_texture_set, 2); + RD::get_singleton()->draw_list_bind_uniform_set(draw_list, sky_scene_state.fog_uniform_set, 3); - uniform_set = RD::get_singleton()->uniform_set_create(uniforms, scene_singleton->sky.sky_shader.shader.version_get_shader(shader_data->version, 0), SKY_SET_MATERIAL); -} + RD::get_singleton()->draw_list_bind_index_array(draw_list, index_array); -RendererSceneSkyRD::SkyMaterialData::~SkyMaterialData() { - if (uniform_set.is_valid() && RD::get_singleton()->uniform_set_is_valid(uniform_set)) { - RD::get_singleton()->free(uniform_set); - } + RD::get_singleton()->draw_list_set_push_constant(draw_list, &sky_push_constant, sizeof(SkyPushConstant)); - if (uniform_buffer.is_valid()) { - RD::get_singleton()->free(uniform_buffer); - } + RD::get_singleton()->draw_list_draw(draw_list, true); } //////////////////////////////////////////////////////////////////////////////// @@ -628,7 +605,7 @@ Ref<Image> RendererSceneSkyRD::Sky::bake_panorama(RendererStorageRD *p_storage, RD::get_singleton()->free(rad_tex); Ref<Image> img; - img.instance(); + img.instantiate(); img->create(p_size.width, p_size.height, false, Image::FORMAT_RGBAF, data); for (int i = 0; i < p_size.width; i++) { for (int j = 0; j < p_size.height; j++) { @@ -892,6 +869,41 @@ void RendererSceneSkyRD::init(RendererStorageRD *p_storage) { sky_scene_state.fog_only_texture_uniform_set = RD::get_singleton()->uniform_set_create(uniforms, sky_shader.default_shader_rd, SKY_SET_TEXTURES); } + + { //create index array for copy shaders + Vector<uint8_t> pv; + pv.resize(6 * 4); + { + uint8_t *w = pv.ptrw(); + int *p32 = (int *)w; + p32[0] = 0; + p32[1] = 1; + p32[2] = 2; + p32[3] = 0; + p32[4] = 2; + p32[5] = 3; + } + index_buffer = RD::get_singleton()->index_buffer_create(6, RenderingDevice::INDEX_BUFFER_FORMAT_UINT32, pv); + index_array = RD::get_singleton()->index_array_create(index_buffer, 0, 6); + } +} + +RendererSceneSkyRD::~RendererSceneSkyRD() { + // TODO cleanup anything created in init... + + if (RD::get_singleton()->uniform_set_is_valid(sky_scene_state.uniform_set)) { + RD::get_singleton()->free(sky_scene_state.uniform_set); + } + + if (RD::get_singleton()->uniform_set_is_valid(sky_scene_state.default_fog_uniform_set)) { + RD::get_singleton()->free(sky_scene_state.default_fog_uniform_set); + } + + if (RD::get_singleton()->uniform_set_is_valid(sky_scene_state.fog_only_texture_uniform_set)) { + RD::get_singleton()->free(sky_scene_state.fog_only_texture_uniform_set); + } + + RD::get_singleton()->free(index_buffer); //array gets freed as dependency } void RendererSceneSkyRD::setup(RendererSceneEnvironmentRD *p_env, RID p_render_buffers, const CameraMatrix &p_projection, const Transform3D &p_transform, const Size2i p_screen_size, RendererSceneRenderRD *p_scene_render) { @@ -1156,7 +1168,7 @@ void RendererSceneSkyRD::update(RendererSceneEnvironmentRD *p_env, const CameraM RID texture_uniform_set = sky->get_textures(storage, SKY_TEXTURE_SET_CUBEMAP_QUARTER_RES, sky_shader.default_shader_rd); cubemap_draw_list = RD::get_singleton()->draw_list_begin(sky->reflection.layers[0].mipmaps[2].framebuffers[i], RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_DISCARD); - storage->get_effects()->render_sky(cubemap_draw_list, p_time, sky->reflection.layers[0].mipmaps[2].framebuffers[i], sky_scene_state.uniform_set, sky_scene_state.fog_uniform_set, pipeline, material->uniform_set, texture_uniform_set, 1, &cm, local_view.basis, multiplier, p_transform.origin); + _render_sky(cubemap_draw_list, p_time, sky->reflection.layers[0].mipmaps[2].framebuffers[i], pipeline, material->uniform_set, texture_uniform_set, 1, &cm, local_view.basis, multiplier, p_transform.origin); RD::get_singleton()->draw_list_end(); } } @@ -1174,7 +1186,7 @@ void RendererSceneSkyRD::update(RendererSceneEnvironmentRD *p_env, const CameraM RID texture_uniform_set = sky->get_textures(storage, SKY_TEXTURE_SET_CUBEMAP_HALF_RES, sky_shader.default_shader_rd); cubemap_draw_list = RD::get_singleton()->draw_list_begin(sky->reflection.layers[0].mipmaps[1].framebuffers[i], RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_DISCARD); - storage->get_effects()->render_sky(cubemap_draw_list, p_time, sky->reflection.layers[0].mipmaps[1].framebuffers[i], sky_scene_state.uniform_set, sky_scene_state.fog_uniform_set, pipeline, material->uniform_set, texture_uniform_set, 1, &cm, local_view.basis, multiplier, p_transform.origin); + _render_sky(cubemap_draw_list, p_time, sky->reflection.layers[0].mipmaps[1].framebuffers[i], pipeline, material->uniform_set, texture_uniform_set, 1, &cm, local_view.basis, multiplier, p_transform.origin); RD::get_singleton()->draw_list_end(); } } @@ -1188,7 +1200,7 @@ void RendererSceneSkyRD::update(RendererSceneEnvironmentRD *p_env, const CameraM RID texture_uniform_set = sky->get_textures(storage, SKY_TEXTURE_SET_CUBEMAP, sky_shader.default_shader_rd); cubemap_draw_list = RD::get_singleton()->draw_list_begin(sky->reflection.layers[0].mipmaps[0].framebuffers[i], RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_DISCARD); - storage->get_effects()->render_sky(cubemap_draw_list, p_time, sky->reflection.layers[0].mipmaps[0].framebuffers[i], sky_scene_state.uniform_set, sky_scene_state.fog_uniform_set, pipeline, material->uniform_set, texture_uniform_set, 1, &cm, local_view.basis, multiplier, p_transform.origin); + _render_sky(cubemap_draw_list, p_time, sky->reflection.layers[0].mipmaps[0].framebuffers[i], pipeline, material->uniform_set, texture_uniform_set, 1, &cm, local_view.basis, multiplier, p_transform.origin); RD::get_singleton()->draw_list_end(); } @@ -1305,7 +1317,7 @@ void RendererSceneSkyRD::draw(RendererSceneEnvironmentRD *p_env, bool p_can_cont clear_colors.push_back(Color(0.0, 0.0, 0.0)); RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(sky->quarter_res_framebuffer, RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_DISCARD, clear_colors); - storage->get_effects()->render_sky(draw_list, p_time, sky->quarter_res_framebuffer, sky_scene_state.uniform_set, sky_scene_state.fog_uniform_set, pipeline, material->uniform_set, texture_uniform_set, view_count, projections, sky_transform, multiplier, p_transform.origin); + _render_sky(draw_list, p_time, sky->quarter_res_framebuffer, pipeline, material->uniform_set, texture_uniform_set, view_count, projections, sky_transform, multiplier, p_transform.origin); RD::get_singleton()->draw_list_end(); } @@ -1318,7 +1330,7 @@ void RendererSceneSkyRD::draw(RendererSceneEnvironmentRD *p_env, bool p_can_cont clear_colors.push_back(Color(0.0, 0.0, 0.0)); RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(sky->half_res_framebuffer, RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_DISCARD, clear_colors); - storage->get_effects()->render_sky(draw_list, p_time, sky->half_res_framebuffer, sky_scene_state.uniform_set, sky_scene_state.fog_uniform_set, pipeline, material->uniform_set, texture_uniform_set, view_count, projections, sky_transform, multiplier, p_transform.origin); + _render_sky(draw_list, p_time, sky->half_res_framebuffer, pipeline, material->uniform_set, texture_uniform_set, view_count, projections, sky_transform, multiplier, p_transform.origin); RD::get_singleton()->draw_list_end(); } @@ -1332,7 +1344,7 @@ void RendererSceneSkyRD::draw(RendererSceneEnvironmentRD *p_env, bool p_can_cont } RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_fb, RD::INITIAL_ACTION_CONTINUE, p_can_continue_color ? RD::FINAL_ACTION_CONTINUE : RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_CONTINUE, p_can_continue_depth ? RD::FINAL_ACTION_CONTINUE : RD::FINAL_ACTION_READ); - storage->get_effects()->render_sky(draw_list, p_time, p_fb, sky_scene_state.uniform_set, sky_scene_state.fog_uniform_set, pipeline, material->uniform_set, texture_uniform_set, view_count, projections, sky_transform, multiplier, p_transform.origin); + _render_sky(draw_list, p_time, p_fb, pipeline, material->uniform_set, texture_uniform_set, view_count, projections, sky_transform, multiplier, p_transform.origin); RD::get_singleton()->draw_list_end(); } diff --git a/servers/rendering/renderer_rd/renderer_scene_sky_rd.h b/servers/rendering/renderer_rd/renderer_scene_sky_rd.h index 200902bff2..4f852e55a7 100644 --- a/servers/rendering/renderer_rd/renderer_scene_sky_rd.h +++ b/servers/rendering/renderer_rd/renderer_scene_sky_rd.h @@ -43,9 +43,6 @@ class RendererSceneRenderRD; class RendererSceneSkyRD { -private: - RendererStorageRD *storage; - public: enum SkySet { SKY_SET_UNIFORMS, @@ -55,6 +52,22 @@ public: SKY_SET_MAX }; + // Skys need less info from Directional Lights than the normal shaders + struct SkyDirectionalLightData { + float direction[3]; + float energy; + float color[3]; + float size; + uint32_t enabled; + uint32_t pad[3]; + }; + +private: + RendererStorageRD *storage; + + RID index_buffer; + RID index_array; + enum SkyTextureSetVersion { SKY_TEXTURE_SET_BACKGROUND, SKY_TEXTURE_SET_HALF_RES, @@ -80,16 +93,53 @@ public: SKY_VERSION_MAX }; - // Skys need less info from Directional Lights than the normal shaders - struct SkyDirectionalLightData { - float direction[3]; - float energy; - float color[3]; - float size; - uint32_t enabled; - uint32_t pad[3]; + struct SkyPushConstant { + float orientation[12]; // 48 - 48 + float projections[RendererSceneRender::MAX_RENDER_VIEWS][4]; // 2 x 16 - 80 + float position[3]; // 12 - 92 + float multiplier; // 4 - 96 + float time; // 4 - 100 + float pad[3]; // 12 - 112 // Using pad to align on 16 bytes + // 128 is the max size of a push constant. We can replace "pad" but we can't add any more. }; + struct SkyShaderData : public RendererStorageRD::ShaderData { + bool valid; + RID version; + + PipelineCacheRD pipelines[SKY_VERSION_MAX]; + Map<StringName, ShaderLanguage::ShaderNode::Uniform> uniforms; + Vector<ShaderCompilerRD::GeneratedCode::Texture> texture_uniforms; + + Vector<uint32_t> ubo_offsets; + uint32_t ubo_size; + + String path; + String code; + Map<StringName, RID> default_texture_params; + + bool uses_time; + bool uses_position; + bool uses_half_res; + bool uses_quarter_res; + bool uses_light; + + virtual void set_code(const String &p_Code); + virtual void set_default_texture_param(const StringName &p_name, RID p_texture); + virtual void get_param_list(List<PropertyInfo> *p_param_list) const; + virtual void get_instance_param_list(List<RendererStorage::InstanceShaderParam> *p_param_list) const; + virtual bool is_param_texture(const StringName &p_param) const; + virtual bool is_animated() const; + virtual bool casts_shadows() const; + virtual Variant get_default_parameter(const StringName &p_parameter) const; + virtual RS::ShaderNativeSourceCode get_native_source_code() const; + SkyShaderData(); + virtual ~SkyShaderData(); + }; + + void _render_sky(RD::DrawListID p_list, float p_time, RID p_fb, PipelineCacheRD *p_pipeline, RID p_uniform_set, RID p_texture_set, uint32_t p_view_count, const CameraMatrix *p_projections, const Basis &p_orientation, float p_multiplier, const Vector3 &p_position); + +public: struct SkySceneState { struct UBO { uint32_t volumetric_fog_enabled; @@ -160,40 +210,6 @@ public: void update_reflection_mipmaps(RendererStorageRD *p_storage, int p_start, int p_end); }; - struct SkyShaderData : public RendererStorageRD::ShaderData { - bool valid; - RID version; - - PipelineCacheRD pipelines[SKY_VERSION_MAX]; - Map<StringName, ShaderLanguage::ShaderNode::Uniform> uniforms; - Vector<ShaderCompilerRD::GeneratedCode::Texture> texture_uniforms; - - Vector<uint32_t> ubo_offsets; - uint32_t ubo_size; - - String path; - String code; - Map<StringName, RID> default_texture_params; - - bool uses_time; - bool uses_position; - bool uses_half_res; - bool uses_quarter_res; - bool uses_light; - - virtual void set_code(const String &p_Code); - virtual void set_default_texture_param(const StringName &p_name, RID p_texture); - virtual void get_param_list(List<PropertyInfo> *p_param_list) const; - virtual void get_instance_param_list(List<RendererStorage::InstanceShaderParam> *p_param_list) const; - virtual bool is_param_texture(const StringName &p_param) const; - virtual bool is_animated() const; - virtual bool casts_shadows() const; - virtual Variant get_default_parameter(const StringName &p_parameter) const; - virtual RS::ShaderNativeSourceCode get_native_source_code() const; - SkyShaderData(); - virtual ~SkyShaderData(); - }; - /* Sky shader */ struct SkyShader { @@ -208,15 +224,12 @@ public: struct SkyMaterialData : public RendererStorageRD::MaterialData { uint64_t last_frame; SkyShaderData *shader_data; - RID uniform_buffer; RID uniform_set; - Vector<RID> texture_cache; - Vector<uint8_t> ubo_data; bool uniform_set_updated; virtual void set_render_priority(int p_priority) {} virtual void set_next_pass(RID p_pass) {} - virtual void update_parameters(const Map<StringName, Variant> &p_parameters, bool p_uniform_dirty, bool p_textures_dirty); + virtual bool update_parameters(const Map<StringName, Variant> &p_parameters, bool p_uniform_dirty, bool p_textures_dirty); virtual ~SkyMaterialData(); }; @@ -270,8 +283,8 @@ public: static RendererStorageRD::MaterialData *_create_sky_material_funcs(RendererStorageRD::ShaderData *p_shader); RendererSceneSkyRD(); - void init(RendererStorageRD *p_storage); + ~RendererSceneSkyRD(); void setup(RendererSceneEnvironmentRD *p_env, RID p_render_buffers, const CameraMatrix &p_projection, const Transform3D &p_transform, const Size2i p_screen_size, RendererSceneRenderRD *p_scene_render); void update(RendererSceneEnvironmentRD *p_env, const CameraMatrix &p_projection, const Transform3D &p_transform, double p_time); diff --git a/servers/rendering/renderer_rd/renderer_storage_rd.cpp b/servers/rendering/renderer_rd/renderer_storage_rd.cpp index 246b5f0e4c..6738f499bd 100644 --- a/servers/rendering/renderer_rd/renderer_storage_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_storage_rd.cpp @@ -35,6 +35,7 @@ #include "core/io/resource_loader.h" #include "core/math/math_defs.h" #include "renderer_compositor_rd.h" +#include "servers/rendering/rendering_server_globals.h" #include "servers/rendering/shader_language.h" bool RendererStorageRD::can_create_resources_async() const { @@ -883,10 +884,6 @@ void RendererStorageRD::_texture_2d_update(RID p_texture, const Ref<Image> &p_im RD::get_singleton()->texture_update(tex->rd_texture, p_layer, validated->get_data()); } -void RendererStorageRD::texture_2d_update_immediate(RID p_texture, const Ref<Image> &p_image, int p_layer) { - _texture_2d_update(p_texture, p_image, p_layer, true); -} - void RendererStorageRD::texture_2d_update(RID p_texture, const Ref<Image> &p_image, int p_layer) { _texture_2d_update(p_texture, p_image, p_layer, false); } @@ -972,7 +969,7 @@ void RendererStorageRD::texture_2d_placeholder_initialize(RID p_texture) { //this could be better optimized to reuse an existing image , done this way //for now to get it working Ref<Image> image; - image.instance(); + image.instantiate(); image->create(4, 4, false, Image::FORMAT_RGBA8); for (int i = 0; i < 4; i++) { @@ -988,7 +985,7 @@ void RendererStorageRD::texture_2d_layered_placeholder_initialize(RID p_texture, //this could be better optimized to reuse an existing image , done this way //for now to get it working Ref<Image> image; - image.instance(); + image.instantiate(); image->create(4, 4, false, Image::FORMAT_RGBA8); for (int i = 0; i < 4; i++) { @@ -1014,7 +1011,7 @@ void RendererStorageRD::texture_3d_placeholder_initialize(RID p_texture) { //this could be better optimized to reuse an existing image , done this way //for now to get it working Ref<Image> image; - image.instance(); + image.instantiate(); image->create(4, 4, false, Image::FORMAT_RGBA8); for (int i = 0; i < 4; i++) { @@ -1044,7 +1041,7 @@ Ref<Image> RendererStorageRD::texture_2d_get(RID p_texture) const { Vector<uint8_t> data = RD::get_singleton()->texture_get_data(tex->rd_texture, 0); ERR_FAIL_COND_V(data.size() == 0, Ref<Image>()); Ref<Image> image; - image.instance(); + image.instantiate(); image->create(tex->width, tex->height, tex->mipmaps > 1, tex->validated_format, data); ERR_FAIL_COND_V(image->is_empty(), Ref<Image>()); if (tex->format != tex->validated_format) { @@ -1067,7 +1064,7 @@ Ref<Image> RendererStorageRD::texture_2d_layer_get(RID p_texture, int p_layer) c Vector<uint8_t> data = RD::get_singleton()->texture_get_data(tex->rd_texture, p_layer); ERR_FAIL_COND_V(data.size() == 0, Ref<Image>()); Ref<Image> image; - image.instance(); + image.instantiate(); image->create(tex->width, tex->height, tex->mipmaps > 1, tex->validated_format, data); ERR_FAIL_COND_V(image->is_empty(), Ref<Image>()); if (tex->format != tex->validated_format) { @@ -1095,7 +1092,7 @@ Vector<Ref<Image>> RendererStorageRD::texture_3d_get(RID p_texture) const { Vector<uint8_t> sub_region = all_data.subarray(bs.offset, bs.offset + bs.buffer_size - 1); Ref<Image> img; - img.instance(); + img.instantiate(); img->create(bs.size.width, bs.size.height, false, tex->validated_format, sub_region); ERR_FAIL_COND_V(img->is_empty(), Vector<Ref<Image>>()); if (tex->format != tex->validated_format) { @@ -1234,7 +1231,7 @@ RID RendererStorageRD::canvas_texture_allocate() { return canvas_texture_owner.allocate_rid(); } void RendererStorageRD::canvas_texture_initialize(RID p_rid) { - canvas_texture_owner.initialize_rid(p_rid, memnew(CanvasTexture)); + canvas_texture_owner.initialize_rid(p_rid); } void RendererStorageRD::canvas_texture_set_channel(RID p_canvas_texture, RS::CanvasTextureChannel p_channel, RID p_texture) { @@ -1529,27 +1526,18 @@ RID RendererStorageRD::material_allocate() { return material_owner.allocate_rid(); } void RendererStorageRD::material_initialize(RID p_rid) { - Material material; - material.data = nullptr; - material.shader = nullptr; - material.shader_type = SHADER_TYPE_MAX; - material.update_next = nullptr; - material.update_requested = false; - material.uniform_dirty = false; - material.texture_dirty = false; - material.priority = 0; - material.self = p_rid; - material_owner.initialize_rid(p_rid, material); + material_owner.initialize_rid(p_rid); + Material *material = material_owner.getornull(p_rid); + material->self = p_rid; } void RendererStorageRD::_material_queue_update(Material *material, bool p_uniform, bool p_texture) { - if (material->update_requested) { + if (material->update_element.in_list()) { return; } - material->update_next = material_update_list; - material_update_list = material; - material->update_requested = true; + material_update_list.add(&material->update_element); + material->uniform_dirty = material->uniform_dirty || p_uniform; material->texture_dirty = material->texture_dirty || p_texture; } @@ -1604,6 +1592,7 @@ void RendererStorageRD::material_set_param(RID p_material, const StringName &p_p if (p_value.get_type() == Variant::NIL) { material->params.erase(p_param); } else { + ERR_FAIL_COND(p_value.get_type() == Variant::OBJECT); //object not allowed material->params[p_param] = p_value; } @@ -2235,6 +2224,10 @@ RendererStorageRD::MaterialData::~MaterialData() { //unregister material from those using global textures rs->global_variables.materials_using_texture.erase(global_texture_E); } + + if (uniform_buffer.is_valid()) { + RD::get_singleton()->free(uniform_buffer); + } } void RendererStorageRD::MaterialData::update_textures(const Map<StringName, Variant> &p_parameters, const Map<StringName, RID> &p_default_textures, const Vector<ShaderCompilerRD::GeneratedCode::Texture> &p_texture_uniforms, RID *p_textures, bool p_use_linear_color) { @@ -2384,6 +2377,105 @@ void RendererStorageRD::MaterialData::update_textures(const Map<StringName, Vari } } +void RendererStorageRD::MaterialData::free_parameters_uniform_set(RID p_uniform_set) { + if (p_uniform_set.is_valid() && RD::get_singleton()->uniform_set_is_valid(p_uniform_set)) { + RD::get_singleton()->uniform_set_set_invalidation_callback(p_uniform_set, nullptr, nullptr); + RD::get_singleton()->free(p_uniform_set); + } +} + +bool RendererStorageRD::MaterialData::update_parameters_uniform_set(const Map<StringName, Variant> &p_parameters, bool p_uniform_dirty, bool p_textures_dirty, const Map<StringName, ShaderLanguage::ShaderNode::Uniform> &p_uniforms, const uint32_t *p_uniform_offsets, const Vector<ShaderCompilerRD::GeneratedCode::Texture> &p_texture_uniforms, const Map<StringName, RID> &p_default_texture_params, uint32_t p_ubo_size, RID &uniform_set, RID p_shader, uint32_t p_shader_uniform_set, uint32_t p_barrier) { + if ((uint32_t)ubo_data.size() != p_ubo_size) { + p_uniform_dirty = true; + if (uniform_buffer.is_valid()) { + RD::get_singleton()->free(uniform_buffer); + uniform_buffer = RID(); + } + + ubo_data.resize(p_ubo_size); + if (ubo_data.size()) { + uniform_buffer = RD::get_singleton()->uniform_buffer_create(ubo_data.size()); + memset(ubo_data.ptrw(), 0, ubo_data.size()); //clear + } + + //clear previous uniform set + if (uniform_set.is_valid() && RD::get_singleton()->uniform_set_is_valid(uniform_set)) { + RD::get_singleton()->uniform_set_set_invalidation_callback(uniform_set, nullptr, nullptr); + RD::get_singleton()->free(uniform_set); + uniform_set = RID(); + } + } + + //check whether buffer changed + if (p_uniform_dirty && ubo_data.size()) { + update_uniform_buffer(p_uniforms, p_uniform_offsets, p_parameters, ubo_data.ptrw(), ubo_data.size(), false); + RD::get_singleton()->buffer_update(uniform_buffer, 0, ubo_data.size(), ubo_data.ptrw(), p_barrier); + } + + uint32_t tex_uniform_count = p_texture_uniforms.size(); + + if ((uint32_t)texture_cache.size() != tex_uniform_count || p_textures_dirty) { + texture_cache.resize(tex_uniform_count); + p_textures_dirty = true; + + //clear previous uniform set + if (uniform_set.is_valid() && RD::get_singleton()->uniform_set_is_valid(uniform_set)) { + RD::get_singleton()->uniform_set_set_invalidation_callback(uniform_set, nullptr, nullptr); + RD::get_singleton()->free(uniform_set); + uniform_set = RID(); + } + } + + if (p_textures_dirty && tex_uniform_count) { + update_textures(p_parameters, p_default_texture_params, p_texture_uniforms, texture_cache.ptrw(), true); + } + + if (p_ubo_size == 0 && p_texture_uniforms.size() == 0) { + // This material does not require an uniform set, so don't create it. + return false; + } + + if (!p_textures_dirty && uniform_set.is_valid() && RD::get_singleton()->uniform_set_is_valid(uniform_set)) { + //no reason to update uniform set, only UBO (or nothing) was needed to update + return false; + } + + Vector<RD::Uniform> uniforms; + + { + if (p_ubo_size) { + RD::Uniform u; + u.uniform_type = RD::UNIFORM_TYPE_UNIFORM_BUFFER; + u.binding = 0; + u.ids.push_back(uniform_buffer); + uniforms.push_back(u); + } + + const RID *textures = texture_cache.ptrw(); + for (uint32_t i = 0; i < tex_uniform_count; i++) { + RD::Uniform u; + u.uniform_type = RD::UNIFORM_TYPE_TEXTURE; + u.binding = 1 + i; + u.ids.push_back(textures[i]); + uniforms.push_back(u); + } + } + + uniform_set = RD::get_singleton()->uniform_set_create(uniforms, p_shader, p_shader_uniform_set); + + RD::get_singleton()->uniform_set_set_invalidation_callback(uniform_set, _material_uniform_set_erased, &self); + + return true; +} + +void RendererStorageRD::_material_uniform_set_erased(const RID &p_set, void *p_material) { + RID rid = *(RID *)p_material; + Material *material = base_singleton->material_owner.getornull(rid); + if (material) { + material->dependency.changed_notify(DEPENDENCY_CHANGED_MATERIAL); + } +} + void RendererStorageRD::material_force_update_textures(RID p_material, ShaderType p_shader_type) { Material *material = material_owner.getornull(p_material); if (material->shader_type != p_shader_type) { @@ -2395,20 +2487,23 @@ void RendererStorageRD::material_force_update_textures(RID p_material, ShaderTyp } void RendererStorageRD::_update_queued_materials() { - Material *material = material_update_list; - while (material) { - Material *next = material->update_next; + while (material_update_list.first()) { + Material *material = material_update_list.first()->self(); + bool uniforms_changed = false; if (material->data) { - material->data->update_parameters(material->params, material->uniform_dirty, material->texture_dirty); + uniforms_changed = material->data->update_parameters(material->params, material->uniform_dirty, material->texture_dirty); } - material->update_requested = false; material->texture_dirty = false; material->uniform_dirty = false; - material->update_next = nullptr; - material = next; + + material_update_list.remove(&material->update_element); + + if (uniforms_changed) { + //some implementations such as 3D renderer cache the matreial uniform set, so update is required + material->dependency.changed_notify(DEPENDENCY_CHANGED_MATERIAL); + } } - material_update_list = nullptr; } /* MESH API */ @@ -2463,7 +2558,7 @@ void RendererStorageRD::mesh_add_surface(RID p_mesh, const RS::SurfaceData &p_su } break; case RS::ARRAY_COLOR: { - attrib_stride += sizeof(int16_t) * 4; + attrib_stride += sizeof(uint32_t); } break; case RS::ARRAY_TEX_UV: { attrib_stride += sizeof(float) * 2; @@ -2551,6 +2646,7 @@ void RendererStorageRD::mesh_add_surface(RID p_mesh, const RS::SurfaceData &p_su s->lods[i].index_buffer = RD::get_singleton()->index_buffer_create(indices, is_index_16 ? RD::INDEX_BUFFER_FORMAT_UINT16 : RD::INDEX_BUFFER_FORMAT_UINT32, p_surface.lods[i].index_data); s->lods[i].index_array = RD::get_singleton()->index_array_create(s->lods[i].index_buffer, 0, indices); s->lods[i].edge_length = p_surface.lods[i].edge_length; + s->lods[i].index_count = indices; } } } @@ -2655,7 +2751,7 @@ RS::BlendShapeMode RendererStorageRD::mesh_get_blend_shape_mode(RID p_mesh) cons return mesh->blend_shape_mode; } -void RendererStorageRD::mesh_surface_update_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) { +void RendererStorageRD::mesh_surface_update_vertex_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) { Mesh *mesh = mesh_owner.getornull(p_mesh); ERR_FAIL_COND(!mesh); ERR_FAIL_UNSIGNED_INDEX((uint32_t)p_surface, mesh->surface_count); @@ -2666,6 +2762,30 @@ void RendererStorageRD::mesh_surface_update_region(RID p_mesh, int p_surface, in RD::get_singleton()->buffer_update(mesh->surfaces[p_surface]->vertex_buffer, p_offset, data_size, r); } +void RendererStorageRD::mesh_surface_update_attribute_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) { + Mesh *mesh = mesh_owner.getornull(p_mesh); + ERR_FAIL_COND(!mesh); + ERR_FAIL_UNSIGNED_INDEX((uint32_t)p_surface, mesh->surface_count); + ERR_FAIL_COND(p_data.size() == 0); + ERR_FAIL_COND(mesh->surfaces[p_surface]->attribute_buffer.is_null()); + uint64_t data_size = p_data.size(); + const uint8_t *r = p_data.ptr(); + + RD::get_singleton()->buffer_update(mesh->surfaces[p_surface]->attribute_buffer, p_offset, data_size, r); +} + +void RendererStorageRD::mesh_surface_update_skin_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) { + Mesh *mesh = mesh_owner.getornull(p_mesh); + ERR_FAIL_COND(!mesh); + ERR_FAIL_UNSIGNED_INDEX((uint32_t)p_surface, mesh->surface_count); + ERR_FAIL_COND(p_data.size() == 0); + ERR_FAIL_COND(mesh->surfaces[p_surface]->skin_buffer.is_null()); + uint64_t data_size = p_data.size(); + const uint8_t *r = p_data.ptr(); + + RD::get_singleton()->buffer_update(mesh->surfaces[p_surface]->skin_buffer, p_offset, data_size, r); +} + void RendererStorageRD::mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material) { Mesh *mesh = mesh_owner.getornull(p_mesh); ERR_FAIL_COND(!mesh); @@ -2934,7 +3054,8 @@ RID RendererStorageRD::mesh_instance_create(RID p_base) { Mesh *mesh = mesh_owner.getornull(p_base); ERR_FAIL_COND_V(!mesh, RID()); - MeshInstance *mi = memnew(MeshInstance); + RID rid = mesh_instance_owner.make_rid(); + MeshInstance *mi = mesh_instance_owner.getornull(rid); mi->mesh = mesh; @@ -2946,7 +3067,7 @@ RID RendererStorageRD::mesh_instance_create(RID p_base) { mi->dirty = true; - return mesh_instance_owner.make_rid(mi); + return rid; } void RendererStorageRD::mesh_instance_set_skeleton(RID p_mesh_instance, RID p_skeleton) { MeshInstance *mi = mesh_instance_owner.getornull(p_mesh_instance); @@ -3233,8 +3354,8 @@ void RendererStorageRD::_mesh_surface_generate_version_for_input_mask(Mesh::Surf case RS::ARRAY_COLOR: { vd.offset = attribute_stride; - vd.format = RD::DATA_FORMAT_R16G16B16A16_SFLOAT; - attribute_stride += sizeof(int16_t) * 4; + vd.format = RD::DATA_FORMAT_R8G8B8A8_UNORM; + attribute_stride += sizeof(int8_t) * 4; buffer = s->attribute_buffer; } break; case RS::ARRAY_TEX_UV: { @@ -3896,6 +4017,7 @@ void RendererStorageRD::particles_set_emitting(RID p_particles, bool p_emitting) } bool RendererStorageRD::particles_get_emitting(RID p_particles) { + ERR_FAIL_COND_V_MSG(RSG::threaded, false, "This function should never be used with threaded rendering, as it stalls the renderer."); Particles *particles = particles_owner.getornull(p_particles); ERR_FAIL_COND_V(!particles, false); @@ -4218,6 +4340,10 @@ void RendererStorageRD::particles_request_process(RID p_particles) { } AABB RendererStorageRD::particles_get_current_aabb(RID p_particles) { + if (RSG::threaded) { + WARN_PRINT_ONCE("Calling this function with threaded rendering enabled stalls the renderer, use with care."); + } + const Particles *particles = particles_owner.getornull(p_particles); ERR_FAIL_COND_V(!particles, AABB()); @@ -5102,6 +5228,7 @@ void RendererStorageRD::update_particles() { } bool RendererStorageRD::particles_is_inactive(RID p_particles) const { + ERR_FAIL_COND_V_MSG(RSG::threaded, false, "This function should never be used with threaded rendering, as it stalls the renderer."); const Particles *particles = particles_owner.getornull(p_particles); ERR_FAIL_COND_V(!particles, false); return !particles->emitting && particles->inactive; @@ -5252,94 +5379,14 @@ RendererStorageRD::ShaderData *RendererStorageRD::_create_particles_shader_func( return shader_data; } -void RendererStorageRD::ParticlesMaterialData::update_parameters(const Map<StringName, Variant> &p_parameters, bool p_uniform_dirty, bool p_textures_dirty) { +bool RendererStorageRD::ParticlesMaterialData::update_parameters(const Map<StringName, Variant> &p_parameters, bool p_uniform_dirty, bool p_textures_dirty) { uniform_set_updated = true; - if ((uint32_t)ubo_data.size() != shader_data->ubo_size) { - p_uniform_dirty = true; - if (uniform_buffer.is_valid()) { - RD::get_singleton()->free(uniform_buffer); - uniform_buffer = RID(); - } - - ubo_data.resize(shader_data->ubo_size); - if (ubo_data.size()) { - uniform_buffer = RD::get_singleton()->uniform_buffer_create(ubo_data.size()); - memset(ubo_data.ptrw(), 0, ubo_data.size()); //clear - } - - //clear previous uniform set - if (uniform_set.is_valid() && RD::get_singleton()->uniform_set_is_valid(uniform_set)) { - RD::get_singleton()->free(uniform_set); - uniform_set = RID(); - } - } - - //check whether buffer changed - if (p_uniform_dirty && ubo_data.size()) { - update_uniform_buffer(shader_data->uniforms, shader_data->ubo_offsets.ptr(), p_parameters, ubo_data.ptrw(), ubo_data.size(), false); - RD::get_singleton()->buffer_update(uniform_buffer, 0, ubo_data.size(), ubo_data.ptrw()); - } - - uint32_t tex_uniform_count = shader_data->texture_uniforms.size(); - - if ((uint32_t)texture_cache.size() != tex_uniform_count) { - texture_cache.resize(tex_uniform_count); - p_textures_dirty = true; - - //clear previous uniform set - if (uniform_set.is_valid() && RD::get_singleton()->uniform_set_is_valid(uniform_set)) { - RD::get_singleton()->free(uniform_set); - uniform_set = RID(); - } - } - - if (p_textures_dirty && tex_uniform_count) { - update_textures(p_parameters, shader_data->default_texture_params, shader_data->texture_uniforms, texture_cache.ptrw(), true); - } - - if (shader_data->ubo_size == 0 && shader_data->texture_uniforms.size() == 0) { - // This material does not require an uniform set, so don't create it. - return; - } - - if (!p_textures_dirty && uniform_set.is_valid() && RD::get_singleton()->uniform_set_is_valid(uniform_set)) { - //no reason to update uniform set, only UBO (or nothing) was needed to update - return; - } - - Vector<RD::Uniform> uniforms; - - { - if (shader_data->ubo_size) { - RD::Uniform u; - u.uniform_type = RD::UNIFORM_TYPE_UNIFORM_BUFFER; - u.binding = 0; - u.ids.push_back(uniform_buffer); - uniforms.push_back(u); - } - - const RID *textures = texture_cache.ptrw(); - for (uint32_t i = 0; i < tex_uniform_count; i++) { - RD::Uniform u; - u.uniform_type = RD::UNIFORM_TYPE_TEXTURE; - u.binding = 1 + i; - u.ids.push_back(textures[i]); - uniforms.push_back(u); - } - } - - uniform_set = RD::get_singleton()->uniform_set_create(uniforms, base_singleton->particles_shader.shader.version_get_shader(shader_data->version, 0), 3); + return update_parameters_uniform_set(p_parameters, p_uniform_dirty, p_textures_dirty, shader_data->uniforms, shader_data->ubo_offsets.ptr(), shader_data->texture_uniforms, shader_data->default_texture_params, shader_data->ubo_size, uniform_set, base_singleton->particles_shader.shader.version_get_shader(shader_data->version, 0), 3); } RendererStorageRD::ParticlesMaterialData::~ParticlesMaterialData() { - if (uniform_set.is_valid() && RD::get_singleton()->uniform_set_is_valid(uniform_set)) { - RD::get_singleton()->free(uniform_set); - } - - if (uniform_buffer.is_valid()) { - RD::get_singleton()->free(uniform_buffer); - } + free_parameters_uniform_set(uniform_set); } RendererStorageRD::MaterialData *RendererStorageRD::_create_particles_material_func(ParticlesShaderData *p_shader) { @@ -6003,20 +6050,6 @@ RS::LightDirectionalShadowMode RendererStorageRD::light_directional_get_shadow_m return light->directional_shadow_mode; } -void RendererStorageRD::light_directional_set_shadow_depth_range_mode(RID p_light, RS::LightDirectionalShadowDepthRangeMode p_range_mode) { - Light *light = light_owner.getornull(p_light); - ERR_FAIL_COND(!light); - - light->directional_range_mode = p_range_mode; -} - -RS::LightDirectionalShadowDepthRangeMode RendererStorageRD::light_directional_get_shadow_depth_range_mode(RID p_light) const { - const Light *light = light_owner.getornull(p_light); - ERR_FAIL_COND_V(!light, RS::LIGHT_DIRECTIONAL_SHADOW_DEPTH_RANGE_STABLE); - - return light->directional_range_mode; -} - uint32_t RendererStorageRD::light_get_max_sdfgi_cascade(RID p_light) { const Light *light = light_owner.getornull(p_light); ERR_FAIL_COND_V(!light, 0); @@ -6610,32 +6643,6 @@ float RendererStorageRD::voxel_gi_get_energy(RID p_voxel_gi) const { return voxel_gi->energy; } -void RendererStorageRD::voxel_gi_set_ao(RID p_voxel_gi, float p_ao) { - VoxelGI *voxel_gi = voxel_gi_owner.getornull(p_voxel_gi); - ERR_FAIL_COND(!voxel_gi); - - voxel_gi->ao = p_ao; -} - -float RendererStorageRD::voxel_gi_get_ao(RID p_voxel_gi) const { - VoxelGI *voxel_gi = voxel_gi_owner.getornull(p_voxel_gi); - ERR_FAIL_COND_V(!voxel_gi, 0); - return voxel_gi->ao; -} - -void RendererStorageRD::voxel_gi_set_ao_size(RID p_voxel_gi, float p_strength) { - VoxelGI *voxel_gi = voxel_gi_owner.getornull(p_voxel_gi); - ERR_FAIL_COND(!voxel_gi); - - voxel_gi->ao_size = p_strength; -} - -float RendererStorageRD::voxel_gi_get_ao_size(RID p_voxel_gi) const { - VoxelGI *voxel_gi = voxel_gi_owner.getornull(p_voxel_gi); - ERR_FAIL_COND_V(!voxel_gi, 0); - return voxel_gi->ao_size; -} - void RendererStorageRD::voxel_gi_set_bias(RID p_voxel_gi, float p_bias) { VoxelGI *voxel_gi = voxel_gi_owner.getornull(p_voxel_gi); ERR_FAIL_COND(!voxel_gi); @@ -8333,6 +8340,9 @@ void RendererStorageRD::global_variable_set_override(const StringName &p_name, c if (!global_variables.variables.has(p_name)) { return; //variable may not exist } + + ERR_FAIL_COND(p_value.get_type() == Variant::OBJECT); + GlobalVariables::Variable &gv = global_variables.variables[p_name]; gv.override = p_value; @@ -8657,8 +8667,6 @@ bool RendererStorageRD::free(RID p_rid) { texture_owner.free(p_rid); } else if (canvas_texture_owner.owns(p_rid)) { - CanvasTexture *ct = canvas_texture_owner.getornull(p_rid); - memdelete(ct); canvas_texture_owner.free(p_rid); } else if (shader_owner.owns(p_rid)) { Shader *shader = shader_owner.getornull(p_rid); @@ -8674,9 +8682,6 @@ bool RendererStorageRD::free(RID p_rid) { } else if (material_owner.owns(p_rid)) { Material *material = material_owner.getornull(p_rid); - if (material->update_requested) { - _update_queued_materials(); - } material_set_shader(p_rid, RID()); //clean up shader material->dependency.deleted_notify(p_rid); @@ -8704,7 +8709,6 @@ bool RendererStorageRD::free(RID p_rid) { mi->I = nullptr; mesh_instance_owner.free(p_rid); - memdelete(mi); } else if (multimesh_owner.owns(p_rid)) { _update_dirty_multimeshes(); @@ -8820,6 +8824,29 @@ String RendererStorageRD::get_captured_timestamp_name(uint32_t p_index) const { return RD::get_singleton()->get_captured_timestamp_name(p_index); } +void RendererStorageRD::update_memory_info() { + texture_mem_cache = RenderingDevice::get_singleton()->get_memory_usage(RenderingDevice::MEMORY_TEXTURES); + buffer_mem_cache = RenderingDevice::get_singleton()->get_memory_usage(RenderingDevice::MEMORY_BUFFERS); + total_mem_cache = RenderingDevice::get_singleton()->get_memory_usage(RenderingDevice::MEMORY_TOTAL); +} +uint64_t RendererStorageRD::get_rendering_info(RS::RenderingInfo p_info) { + if (p_info == RS::RENDERING_INFO_TEXTURE_MEM_USED) { + return texture_mem_cache; + } else if (p_info == RS::RENDERING_INFO_BUFFER_MEM_USED) { + return buffer_mem_cache; + } else if (p_info == RS::RENDERING_INFO_VIDEO_MEM_USED) { + return total_mem_cache; + } + return 0; +} + +String RendererStorageRD::get_video_adapter_name() const { + return RenderingDevice::get_singleton()->get_device_name(); +} +String RendererStorageRD::get_video_adapter_vendor() const { + return RenderingDevice::get_singleton()->get_device_vendor_name(); +} + RendererStorageRD *RendererStorageRD::base_singleton = nullptr; RendererStorageRD::RendererStorageRD() { @@ -8840,7 +8867,6 @@ RendererStorageRD::RendererStorageRD() { memset(global_variables.buffer_dirty_regions, 0, sizeof(bool) * global_variables.buffer_size / GlobalVariables::BUFFER_DIRTY_REGION_SIZE); global_variables.buffer = RD::get_singleton()->storage_buffer_create(sizeof(GlobalVariables::Value) * global_variables.buffer_size); - material_update_list = nullptr; { //create default textures RD::TextureFormat tformat; diff --git a/servers/rendering/renderer_rd/renderer_storage_rd.h b/servers/rendering/renderer_rd/renderer_storage_rd.h index ab470cb3a6..1a33569c33 100644 --- a/servers/rendering/renderer_rd/renderer_storage_rd.h +++ b/servers/rendering/renderer_rd/renderer_storage_rd.h @@ -155,9 +155,13 @@ public: virtual void set_render_priority(int p_priority) = 0; virtual void set_next_pass(RID p_pass) = 0; - virtual void update_parameters(const Map<StringName, Variant> &p_parameters, bool p_uniform_dirty, bool p_textures_dirty) = 0; + virtual bool update_parameters(const Map<StringName, Variant> &p_parameters, bool p_uniform_dirty, bool p_textures_dirty) = 0; virtual ~MaterialData(); + //to be used internally by update_parameters, in the most common configuration of material parameters + bool update_parameters_uniform_set(const Map<StringName, Variant> &p_parameters, bool p_uniform_dirty, bool p_textures_dirty, const Map<StringName, ShaderLanguage::ShaderNode::Uniform> &p_uniforms, const uint32_t *p_uniform_offsets, const Vector<ShaderCompilerRD::GeneratedCode::Texture> &p_texture_uniforms, const Map<StringName, RID> &p_default_texture_params, uint32_t p_ubo_size, RID &uniform_set, RID p_shader, uint32_t p_shader_uniform_set, uint32_t p_barrier = RD::BARRIER_MASK_ALL); + void free_parameters_uniform_set(RID p_uniform_set); + private: friend class RendererStorageRD; RID self; @@ -165,8 +169,14 @@ public: List<RID>::Element *global_texture_E = nullptr; uint64_t global_textures_pass = 0; Map<StringName, uint64_t> used_global_textures; + + //internally by update_parameters_uniform_set + Vector<uint8_t> ubo_data; + RID uniform_buffer; + Vector<RID> texture_cache; }; typedef MaterialData *(*MaterialDataRequestFunction)(ShaderData *); + static void _material_uniform_set_erased(const RID &p_set, void *p_material); enum DefaultRDTexture { DEFAULT_RD_TEXTURE_WHITE, @@ -221,7 +231,7 @@ private: ~CanvasTexture(); }; - RID_PtrOwner<CanvasTexture, true> canvas_texture_owner; + RID_Owner<CanvasTexture, true> canvas_texture_owner; /* TEXTURE API */ struct Texture { @@ -373,25 +383,28 @@ private: struct Material { RID self; - MaterialData *data; - Shader *shader; + MaterialData *data = nullptr; + Shader *shader = nullptr; //shortcut to shader data and type - ShaderType shader_type; + ShaderType shader_type = SHADER_TYPE_MAX; uint32_t shader_id = 0; - bool update_requested; - bool uniform_dirty; - bool texture_dirty; - Material *update_next; + bool uniform_dirty = false; + bool texture_dirty = false; Map<StringName, Variant> params; - int32_t priority; + int32_t priority = 0; RID next_pass; + SelfList<Material> update_element; + Dependency dependency; + + Material() : + update_element(this) {} }; MaterialDataRequestFunction material_data_request_func[SHADER_TYPE_MAX]; mutable RID_Owner<Material, true> material_owner; - Material *material_update_list; + SelfList<Material>::List material_update_list; void _material_queue_update(Material *material, bool p_uniform, bool p_texture); void _update_queued_materials(); @@ -434,6 +447,7 @@ private: struct LOD { float edge_length = 0.0; + uint32_t index_count = 0; RID index_buffer; RID index_array; }; @@ -513,7 +527,7 @@ private: void _mesh_instance_clear(MeshInstance *mi); void _mesh_instance_add_surface(MeshInstance *mi, Mesh *mesh, uint32_t p_surface); - mutable RID_PtrOwner<MeshInstance> mesh_instance_owner; + mutable RID_Owner<MeshInstance> mesh_instance_owner; SelfList<MeshInstance>::List dirty_mesh_instance_weights; SelfList<MeshInstance>::List dirty_mesh_instance_arrays; @@ -894,17 +908,14 @@ private: } struct ParticlesMaterialData : public MaterialData { - uint64_t last_frame; - ParticlesShaderData *shader_data; - RID uniform_buffer; + uint64_t last_frame = 0; + ParticlesShaderData *shader_data = nullptr; RID uniform_set; - Vector<RID> texture_cache; - Vector<uint8_t> ubo_data; - bool uniform_set_updated; + bool uniform_set_updated = false; virtual void set_render_priority(int p_priority) {} virtual void set_next_pass(RID p_pass) {} - virtual void update_parameters(const Map<StringName, Variant> &p_parameters, bool p_uniform_dirty, bool p_textures_dirty); + virtual bool update_parameters(const Map<StringName, Variant> &p_parameters, bool p_uniform_dirty, bool p_textures_dirty); virtual ~ParticlesMaterialData(); }; @@ -1002,7 +1013,6 @@ private: uint32_t cull_mask = 0xFFFFFFFF; RS::LightOmniShadowMode omni_shadow_mode = RS::LIGHT_OMNI_SHADOW_DUAL_PARABOLOID; RS::LightDirectionalShadowMode directional_shadow_mode = RS::LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL; - RS::LightDirectionalShadowDepthRangeMode directional_range_mode = RS::LIGHT_DIRECTIONAL_SHADOW_DEPTH_RANGE_STABLE; bool directional_blend_splits = false; bool directional_sky_only = false; uint64_t version = 0; @@ -1076,8 +1086,6 @@ private: float dynamic_range = 4.0; float energy = 1.0; - float ao = 0.0; - float ao_size = 0.5; float bias = 1.4; float normal_bias = 0.0; float propagation = 0.7; @@ -1298,7 +1306,6 @@ public: virtual void _texture_2d_update(RID p_texture, const Ref<Image> &p_image, int p_layer, bool p_immediate); - virtual void texture_2d_update_immediate(RID p_texture, const Ref<Image> &p_image, int p_layer = 0); //mostly used for video and streaming virtual void texture_2d_update(RID p_texture, const Ref<Image> &p_image, int p_layer = 0); virtual void texture_3d_update(RID p_texture, const Vector<Ref<Image>> &p_data); virtual void texture_proxy_update(RID p_texture, RID p_proxy_to); @@ -1457,7 +1464,9 @@ public: virtual void mesh_set_blend_shape_mode(RID p_mesh, RS::BlendShapeMode p_mode); virtual RS::BlendShapeMode mesh_get_blend_shape_mode(RID p_mesh) const; - virtual void mesh_surface_update_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data); + virtual void mesh_surface_update_vertex_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data); + virtual void mesh_surface_update_attribute_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data); + virtual void mesh_surface_update_skin_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data); virtual void mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material); virtual RID mesh_surface_get_material(RID p_mesh, int p_surface) const; @@ -1526,10 +1535,18 @@ public: return s->lod_count > 0; } - _FORCE_INLINE_ uint32_t mesh_surface_get_lod(void *p_surface, float p_model_scale, float p_distance_threshold, float p_lod_threshold) const { + _FORCE_INLINE_ uint32_t mesh_surface_get_vertices_drawn_count(void *p_surface) const { + Mesh::Surface *s = reinterpret_cast<Mesh::Surface *>(p_surface); + return s->index_count ? s->index_count : s->vertex_count; + } + + _FORCE_INLINE_ uint32_t mesh_surface_get_lod(void *p_surface, float p_model_scale, float p_distance_threshold, float p_lod_threshold, uint32_t *r_index_count = nullptr) const { Mesh::Surface *s = reinterpret_cast<Mesh::Surface *>(p_surface); int32_t current_lod = -1; + if (r_index_count) { + *r_index_count = s->index_count; + } for (uint32_t i = 0; i < s->lod_count; i++) { float screen_size = s->lods[i].edge_length * p_model_scale / p_distance_threshold; if (screen_size > p_lod_threshold) { @@ -1540,6 +1557,9 @@ public: if (current_lod == -1) { return 0; } else { + if (r_index_count) { + *r_index_count = s->lods[current_lod].index_count; + } return current_lod + 1; } } @@ -1746,24 +1766,6 @@ public: return multimesh->uniform_set_2d; } - /* IMMEDIATE API */ - - RID immediate_allocate() { return RID(); } - void immediate_initialize(RID p_immediate) {} - - virtual void immediate_begin(RID p_immediate, RS::PrimitiveType p_rimitive, RID p_texture = RID()) {} - virtual void immediate_vertex(RID p_immediate, const Vector3 &p_vertex) {} - virtual void immediate_normal(RID p_immediate, const Vector3 &p_normal) {} - virtual void immediate_tangent(RID p_immediate, const Plane &p_tangent) {} - virtual void immediate_color(RID p_immediate, const Color &p_color) {} - virtual void immediate_uv(RID p_immediate, const Vector2 &tex_uv) {} - virtual void immediate_uv2(RID p_immediate, const Vector2 &tex_uv) {} - virtual void immediate_end(RID p_immediate) {} - virtual void immediate_clear(RID p_immediate) {} - virtual void immediate_set_material(RID p_immediate, RID p_material) {} - virtual RID immediate_get_material(RID p_immediate) const { return RID(); } - virtual AABB immediate_get_aabb(RID p_immediate) const { return AABB(); } - /* SKELETON API */ RID skeleton_allocate(); @@ -1832,8 +1834,6 @@ public: bool light_directional_get_blend_splits(RID p_light) const; void light_directional_set_sky_only(RID p_light, bool p_sky_only); bool light_directional_is_sky_only(RID p_light) const; - void light_directional_set_shadow_depth_range_mode(RID p_light, RS::LightDirectionalShadowDepthRangeMode p_range_mode); - RS::LightDirectionalShadowDepthRangeMode light_directional_get_shadow_depth_range_mode(RID p_light) const; RS::LightDirectionalShadowMode light_directional_get_shadow_mode(RID p_light); RS::LightOmniShadowMode light_omni_get_shadow_mode(RID p_light); @@ -2056,12 +2056,6 @@ public: void voxel_gi_set_energy(RID p_voxel_gi, float p_energy); float voxel_gi_get_energy(RID p_voxel_gi) const; - void voxel_gi_set_ao(RID p_voxel_gi, float p_ao); - float voxel_gi_get_ao(RID p_voxel_gi) const; - - void voxel_gi_set_ao_size(RID p_voxel_gi, float p_strength); - float voxel_gi_get_ao_size(RID p_voxel_gi) const; - void voxel_gi_set_bias(RID p_voxel_gi, float p_bias); float voxel_gi_get_bias(RID p_voxel_gi) const; @@ -2350,13 +2344,16 @@ public: void set_debug_generate_wireframes(bool p_generate) {} - void render_info_begin_capture() {} - void render_info_end_capture() {} - int get_captured_render_info(RS::RenderInfo p_info) { return 0; } + //keep cached since it can be called form any thread + uint64_t texture_mem_cache = 0; + uint64_t buffer_mem_cache = 0; + uint64_t total_mem_cache = 0; + + virtual void update_memory_info(); + virtual uint64_t get_rendering_info(RS::RenderingInfo p_info); - uint64_t get_render_info(RS::RenderInfo p_info) { return 0; } - String get_video_adapter_name() const { return String(); } - String get_video_adapter_vendor() const { return String(); } + String get_video_adapter_name() const; + String get_video_adapter_vendor() const; virtual void capture_timestamps_begin(); virtual void capture_timestamp(const String &p_name); diff --git a/servers/rendering/renderer_rd/shaders/canvas.glsl b/servers/rendering/renderer_rd/shaders/canvas.glsl index 2186bd174b..a443bcdcb8 100644 --- a/servers/rendering/renderer_rd/shaders/canvas.glsl +++ b/servers/rendering/renderer_rd/shaders/canvas.glsl @@ -65,7 +65,7 @@ void main() { #elif defined(USE_ATTRIBUTES) vec2 vertex = vertex_attrib; - vec4 color = color_attrib; + vec4 color = color_attrib * draw_data.modulation; vec2 uv = uv_attrib; uvec4 bones = bone_attrib; diff --git a/servers/rendering/renderer_rd/shaders/gi.glsl b/servers/rendering/renderer_rd/shaders/gi.glsl index 3977f4efa0..60c881881d 100644 --- a/servers/rendering/renderer_rd/shaders/gi.glsl +++ b/servers/rendering/renderer_rd/shaders/gi.glsl @@ -77,9 +77,9 @@ struct VoxelGIData { bool blend_ambient; uint texture_slot; - float anisotropy_strength; - float ambient_occlusion; - float ambient_occlusion_size; + uint pad0; + uint pad1; + uint pad2; uint mipmaps; }; @@ -551,27 +551,6 @@ void voxel_gi_compute(uint index, vec3 position, vec3 normal, vec3 ref_vec, mat3 } } - if (voxel_gi_instances.data[index].ambient_occlusion > 0.001) { - float size = 1.0 + voxel_gi_instances.data[index].ambient_occlusion_size * 7.0; - - float taps, blend; - blend = modf(size, taps); - float ao = 0.0; - for (float i = 1.0; i <= taps; i++) { - vec3 ofs = (position + normal * (i * 0.5 + 1.0)) * cell_size; - ao += textureLod(sampler3D(voxel_gi_textures[index], linear_sampler_with_mipmaps), ofs, i - 1.0).a * i; - } - - if (blend > 0.001) { - vec3 ofs = (position + normal * ((taps + 1.0) * 0.5 + 1.0)) * cell_size; - ao += textureLod(sampler3D(voxel_gi_textures[index], linear_sampler_with_mipmaps), ofs, taps).a * (taps + 1.0) * blend; - } - - ao = 1.0 - min(1.0, ao); - - light.rgb = mix(params.ao_color, light.rgb, mix(1.0, ao, voxel_gi_instances.data[index].ambient_occlusion)); - } - light.rgb *= voxel_gi_instances.data[index].dynamic_range; if (!voxel_gi_instances.data[index].blend_ambient) { light.a = 1.0; diff --git a/servers/rendering/renderer_rd/shaders/resolve.glsl b/servers/rendering/renderer_rd/shaders/resolve.glsl index a4610e081c..fecf812a8c 100644 --- a/servers/rendering/renderer_rd/shaders/resolve.glsl +++ b/servers/rendering/renderer_rd/shaders/resolve.glsl @@ -6,6 +6,11 @@ layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in; +#ifdef MODE_RESOLVE_DEPTH +layout(set = 0, binding = 0) uniform sampler2DMS source_depth; +layout(r32f, set = 1, binding = 0) uniform restrict writeonly image2D dest_depth; +#endif + #ifdef MODE_RESOLVE_GI layout(set = 0, binding = 0) uniform sampler2DMS source_depth; layout(set = 0, binding = 1) uniform sampler2DMS source_normal_roughness; @@ -34,6 +39,17 @@ void main() { return; } +#ifdef MODE_RESOLVE_DEPTH + + float depth_avg = 0.0; + for (int i = 0; i < params.sample_count; i++) { + depth_avg += texelFetch(source_depth, pos, i).r; + } + depth_avg /= float(params.sample_count); + imageStore(dest_depth, pos, vec4(depth_avg)); + +#endif + #ifdef MODE_RESOLVE_GI float best_depth = 1e20; diff --git a/servers/rendering/renderer_rd/shaders/scene_forward_clustered.glsl b/servers/rendering/renderer_rd/shaders/scene_forward_clustered.glsl index 8538030263..74d5af5cb6 100644 --- a/servers/rendering/renderer_rd/shaders/scene_forward_clustered.glsl +++ b/servers/rendering/renderer_rd/shaders/scene_forward_clustered.glsl @@ -547,9 +547,8 @@ void main() { vec3 view = -normalize(vertex_interp); vec3 albedo = vec3(1.0); vec3 backlight = vec3(0.0); - vec4 transmittance_color = vec4(0.0); + vec4 transmittance_color = vec4(0.0, 0.0, 0.0, 1.0); float transmittance_depth = 0.0; - float transmittance_curve = 1.0; float transmittance_boost = 0.0; float metallic = 0.0; float specular = 0.5; @@ -634,12 +633,8 @@ void main() { } #ifdef LIGHT_TRANSMITTANCE_USED -#ifdef SSS_MODE_SKIN - transmittance_color.a = sss_strength; -#else transmittance_color.a *= sss_strength; #endif -#endif #ifndef USE_SHADOW_TO_OPACITY @@ -1423,57 +1418,18 @@ void main() { BIAS_FUNC(v, 0) pssm_coord = (directional_lights.data[i].shadow_matrix1 * v); -#ifdef LIGHT_TRANSMITTANCE_USED - { - vec4 trans_vertex = vec4(vertex - normalize(normal_interp) * directional_lights.data[i].shadow_transmittance_bias.x, 1.0); - vec4 trans_coord = directional_lights.data[i].shadow_matrix1 * trans_vertex; - trans_coord /= trans_coord.w; - - float shadow_z = textureLod(sampler2D(directional_shadow_atlas, material_samplers[SAMPLER_LINEAR_CLAMP]), trans_coord.xy, 0.0).r; - shadow_z *= directional_lights.data[i].shadow_transmittance_z_scale.x; - float z = trans_coord.z * directional_lights.data[i].shadow_transmittance_z_scale.x; - - transmittance_z = z - shadow_z; - } -#endif } else if (depth_z < directional_lights.data[i].shadow_split_offsets.y) { vec4 v = vec4(vertex, 1.0); BIAS_FUNC(v, 1) pssm_coord = (directional_lights.data[i].shadow_matrix2 * v); -#ifdef LIGHT_TRANSMITTANCE_USED - { - vec4 trans_vertex = vec4(vertex - normalize(normal_interp) * directional_lights.data[i].shadow_transmittance_bias.y, 1.0); - vec4 trans_coord = directional_lights.data[i].shadow_matrix2 * trans_vertex; - trans_coord /= trans_coord.w; - - float shadow_z = textureLod(sampler2D(directional_shadow_atlas, material_samplers[SAMPLER_LINEAR_CLAMP]), trans_coord.xy, 0.0).r; - shadow_z *= directional_lights.data[i].shadow_transmittance_z_scale.y; - float z = trans_coord.z * directional_lights.data[i].shadow_transmittance_z_scale.y; - - transmittance_z = z - shadow_z; - } -#endif } else if (depth_z < directional_lights.data[i].shadow_split_offsets.z) { vec4 v = vec4(vertex, 1.0); BIAS_FUNC(v, 2) pssm_coord = (directional_lights.data[i].shadow_matrix3 * v); -#ifdef LIGHT_TRANSMITTANCE_USED - { - vec4 trans_vertex = vec4(vertex - normalize(normal_interp) * directional_lights.data[i].shadow_transmittance_bias.z, 1.0); - vec4 trans_coord = directional_lights.data[i].shadow_matrix3 * trans_vertex; - trans_coord /= trans_coord.w; - - float shadow_z = textureLod(sampler2D(directional_shadow_atlas, material_samplers[SAMPLER_LINEAR_CLAMP]), trans_coord.xy, 0.0).r; - shadow_z *= directional_lights.data[i].shadow_transmittance_z_scale.z; - float z = trans_coord.z * directional_lights.data[i].shadow_transmittance_z_scale.z; - - transmittance_z = z - shadow_z; - } -#endif } else { vec4 v = vec4(vertex, 1.0); @@ -1481,19 +1437,6 @@ void main() { BIAS_FUNC(v, 3) pssm_coord = (directional_lights.data[i].shadow_matrix4 * v); -#ifdef LIGHT_TRANSMITTANCE_USED - { - vec4 trans_vertex = vec4(vertex - normalize(normal_interp) * directional_lights.data[i].shadow_transmittance_bias.w, 1.0); - vec4 trans_coord = directional_lights.data[i].shadow_matrix4 * trans_vertex; - trans_coord /= trans_coord.w; - - float shadow_z = textureLod(sampler2D(directional_shadow_atlas, material_samplers[SAMPLER_LINEAR_CLAMP]), trans_coord.xy, 0.0).r; - shadow_z *= directional_lights.data[i].shadow_transmittance_z_scale.w; - float z = trans_coord.z * directional_lights.data[i].shadow_transmittance_z_scale.w; - - transmittance_z = z - shadow_z; - } -#endif } pssm_coord /= pssm_coord.w; @@ -1562,8 +1505,8 @@ void main() { trans_coord /= trans_coord.w; float shadow_z = textureLod(sampler2D(directional_shadow_atlas, material_samplers[SAMPLER_LINEAR_CLAMP]), trans_coord.xy, 0.0).r; - shadow_z *= directional_lights.data[i].shadow_transmittance_z_scale.x; - float z = trans_coord.z * directional_lights.data[i].shadow_transmittance_z_scale.x; + shadow_z *= directional_lights.data[i].shadow_z_range.x; + float z = trans_coord.z * directional_lights.data[i].shadow_z_range.x; transmittance_z = z - shadow_z; } else if (depth_z < directional_lights.data[i].shadow_split_offsets.y) { @@ -1572,8 +1515,8 @@ void main() { trans_coord /= trans_coord.w; float shadow_z = textureLod(sampler2D(directional_shadow_atlas, material_samplers[SAMPLER_LINEAR_CLAMP]), trans_coord.xy, 0.0).r; - shadow_z *= directional_lights.data[i].shadow_transmittance_z_scale.y; - float z = trans_coord.z * directional_lights.data[i].shadow_transmittance_z_scale.y; + shadow_z *= directional_lights.data[i].shadow_z_range.y; + float z = trans_coord.z * directional_lights.data[i].shadow_z_range.y; transmittance_z = z - shadow_z; } else if (depth_z < directional_lights.data[i].shadow_split_offsets.z) { @@ -1582,8 +1525,8 @@ void main() { trans_coord /= trans_coord.w; float shadow_z = textureLod(sampler2D(directional_shadow_atlas, material_samplers[SAMPLER_LINEAR_CLAMP]), trans_coord.xy, 0.0).r; - shadow_z *= directional_lights.data[i].shadow_transmittance_z_scale.z; - float z = trans_coord.z * directional_lights.data[i].shadow_transmittance_z_scale.z; + shadow_z *= directional_lights.data[i].shadow_z_range.z; + float z = trans_coord.z * directional_lights.data[i].shadow_z_range.z; transmittance_z = z - shadow_z; @@ -1593,221 +1536,219 @@ void main() { trans_coord /= trans_coord.w; float shadow_z = textureLod(sampler2D(directional_shadow_atlas, material_samplers[SAMPLER_LINEAR_CLAMP]), trans_coord.xy, 0.0).r; - shadow_z *= directional_lights.data[i].shadow_transmittance_z_scale.w; - float z = trans_coord.z * directional_lights.data[i].shadow_transmittance_z_scale.w; + shadow_z *= directional_lights.data[i].shadow_z_range.w; + float z = trans_coord.z * directional_lights.data[i].shadow_z_range.w; transmittance_z = z - shadow_z; } + } #endif - float shadow = 1.0; + float shadow = 1.0; - if (i < 4) { - shadow = float(shadow0 >> (i * 8) & 0xFF) / 255.0; - } else { - shadow = float(shadow1 >> ((i - 4) * 8) & 0xFF) / 255.0; - } + if (i < 4) { + shadow = float(shadow0 >> (i * 8) & 0xFF) / 255.0; + } else { + shadow = float(shadow1 >> ((i - 4) * 8) & 0xFF) / 255.0; + } - blur_shadow(shadow); + blur_shadow(shadow); - light_compute(normal, directional_lights.data[i].direction, normalize(view), directional_lights.data[i].color * directional_lights.data[i].energy, shadow, f0, orms, 1.0, + light_compute(normal, directional_lights.data[i].direction, normalize(view), directional_lights.data[i].color * directional_lights.data[i].energy, shadow, f0, orms, 1.0, #ifdef LIGHT_BACKLIGHT_USED - backlight, + backlight, #endif #ifdef LIGHT_TRANSMITTANCE_USED - transmittance_color, - transmittance_depth, - transmittance_curve, - transmittance_boost, - transmittance_z, + transmittance_color, + transmittance_depth, + transmittance_boost, + transmittance_z, #endif #ifdef LIGHT_RIM_USED - rim, rim_tint, albedo, + rim, rim_tint, albedo, #endif #ifdef LIGHT_CLEARCOAT_USED - clearcoat, clearcoat_gloss, + clearcoat, clearcoat_gloss, #endif #ifdef LIGHT_ANISOTROPY_USED - binormal, tangent, anisotropy, + binormal, tangent, anisotropy, #endif #ifdef USE_SOFT_SHADOW - directional_lights.data[i].size, + directional_lights.data[i].size, #endif #ifdef USE_SHADOW_TO_OPACITY - alpha, + alpha, #endif - diffuse_light, - specular_light); - } + diffuse_light, + specular_light); } + } - { //omni lights + { //omni lights - uint cluster_omni_offset = cluster_offset; + uint cluster_omni_offset = cluster_offset; - uint item_min; - uint item_max; - uint item_from; - uint item_to; + uint item_min; + uint item_max; + uint item_from; + uint item_to; - cluster_get_item_range(cluster_omni_offset + scene_data.max_cluster_element_count_div_32 + cluster_z, item_min, item_max, item_from, item_to); + cluster_get_item_range(cluster_omni_offset + scene_data.max_cluster_element_count_div_32 + cluster_z, item_min, item_max, item_from, item_to); #ifdef USE_SUBGROUPS - item_from = subgroupBroadcastFirst(subgroupMin(item_from)); - item_to = subgroupBroadcastFirst(subgroupMax(item_to)); + item_from = subgroupBroadcastFirst(subgroupMin(item_from)); + item_to = subgroupBroadcastFirst(subgroupMax(item_to)); #endif - for (uint i = item_from; i < item_to; i++) { - uint mask = cluster_buffer.data[cluster_omni_offset + i]; - mask &= cluster_get_range_clip_mask(i, item_min, item_max); + for (uint i = item_from; i < item_to; i++) { + uint mask = cluster_buffer.data[cluster_omni_offset + i]; + mask &= cluster_get_range_clip_mask(i, item_min, item_max); #ifdef USE_SUBGROUPS - uint merged_mask = subgroupBroadcastFirst(subgroupOr(mask)); + uint merged_mask = subgroupBroadcastFirst(subgroupOr(mask)); #else uint merged_mask = mask; #endif - while (merged_mask != 0) { - uint bit = findMSB(merged_mask); - merged_mask &= ~(1 << bit); + while (merged_mask != 0) { + uint bit = findMSB(merged_mask); + merged_mask &= ~(1 << bit); #ifdef USE_SUBGROUPS - if (((1 << bit) & mask) == 0) { //do not process if not originally here - continue; - } + if (((1 << bit) & mask) == 0) { //do not process if not originally here + continue; + } #endif - uint light_index = 32 * i + bit; + uint light_index = 32 * i + bit; - if (!bool(omni_lights.data[light_index].mask & instances.data[instance_index].layer_mask)) { - continue; //not masked - } + if (!bool(omni_lights.data[light_index].mask & instances.data[instance_index].layer_mask)) { + continue; //not masked + } - if (omni_lights.data[light_index].bake_mode == LIGHT_BAKE_STATIC && bool(instances.data[instance_index].flags & INSTANCE_FLAGS_USE_LIGHTMAP)) { - continue; // Statically baked light and object uses lightmap, skip - } + if (omni_lights.data[light_index].bake_mode == LIGHT_BAKE_STATIC && bool(instances.data[instance_index].flags & INSTANCE_FLAGS_USE_LIGHTMAP)) { + continue; // Statically baked light and object uses lightmap, skip + } - float shadow = light_process_omni_shadow(light_index, vertex, view); + float shadow = light_process_omni_shadow(light_index, vertex, view); - shadow = blur_shadow(shadow); + shadow = blur_shadow(shadow); - light_process_omni(light_index, vertex, view, normal, vertex_ddx, vertex_ddy, f0, orms, shadow, + light_process_omni(light_index, vertex, view, normal, vertex_ddx, vertex_ddy, f0, orms, shadow, #ifdef LIGHT_BACKLIGHT_USED - backlight, + backlight, #endif #ifdef LIGHT_TRANSMITTANCE_USED - transmittance_color, - transmittance_depth, - transmittance_curve, - transmittance_boost, + transmittance_color, + transmittance_depth, + transmittance_boost, #endif #ifdef LIGHT_RIM_USED - rim, - rim_tint, - albedo, + rim, + rim_tint, + albedo, #endif #ifdef LIGHT_CLEARCOAT_USED - clearcoat, clearcoat_gloss, + clearcoat, clearcoat_gloss, #endif #ifdef LIGHT_ANISOTROPY_USED - tangent, binormal, anisotropy, + tangent, binormal, anisotropy, #endif #ifdef USE_SHADOW_TO_OPACITY - alpha, + alpha, #endif - diffuse_light, specular_light); - } + diffuse_light, specular_light); } } + } - { //spot lights + { //spot lights - uint cluster_spot_offset = cluster_offset + scene_data.cluster_type_size; + uint cluster_spot_offset = cluster_offset + scene_data.cluster_type_size; - uint item_min; - uint item_max; - uint item_from; - uint item_to; + uint item_min; + uint item_max; + uint item_from; + uint item_to; - cluster_get_item_range(cluster_spot_offset + scene_data.max_cluster_element_count_div_32 + cluster_z, item_min, item_max, item_from, item_to); + cluster_get_item_range(cluster_spot_offset + scene_data.max_cluster_element_count_div_32 + cluster_z, item_min, item_max, item_from, item_to); #ifdef USE_SUBGROUPS - item_from = subgroupBroadcastFirst(subgroupMin(item_from)); - item_to = subgroupBroadcastFirst(subgroupMax(item_to)); + item_from = subgroupBroadcastFirst(subgroupMin(item_from)); + item_to = subgroupBroadcastFirst(subgroupMax(item_to)); #endif - for (uint i = item_from; i < item_to; i++) { - uint mask = cluster_buffer.data[cluster_spot_offset + i]; - mask &= cluster_get_range_clip_mask(i, item_min, item_max); + for (uint i = item_from; i < item_to; i++) { + uint mask = cluster_buffer.data[cluster_spot_offset + i]; + mask &= cluster_get_range_clip_mask(i, item_min, item_max); #ifdef USE_SUBGROUPS - uint merged_mask = subgroupBroadcastFirst(subgroupOr(mask)); + uint merged_mask = subgroupBroadcastFirst(subgroupOr(mask)); #else uint merged_mask = mask; #endif - while (merged_mask != 0) { - uint bit = findMSB(merged_mask); - merged_mask &= ~(1 << bit); + while (merged_mask != 0) { + uint bit = findMSB(merged_mask); + merged_mask &= ~(1 << bit); #ifdef USE_SUBGROUPS - if (((1 << bit) & mask) == 0) { //do not process if not originally here - continue; - } + if (((1 << bit) & mask) == 0) { //do not process if not originally here + continue; + } #endif - uint light_index = 32 * i + bit; + uint light_index = 32 * i + bit; - if (!bool(spot_lights.data[light_index].mask & instances.data[instance_index].layer_mask)) { - continue; //not masked - } + if (!bool(spot_lights.data[light_index].mask & instances.data[instance_index].layer_mask)) { + continue; //not masked + } - if (spot_lights.data[light_index].bake_mode == LIGHT_BAKE_STATIC && bool(instances.data[instance_index].flags & INSTANCE_FLAGS_USE_LIGHTMAP)) { - continue; // Statically baked light and object uses lightmap, skip - } + if (spot_lights.data[light_index].bake_mode == LIGHT_BAKE_STATIC && bool(instances.data[instance_index].flags & INSTANCE_FLAGS_USE_LIGHTMAP)) { + continue; // Statically baked light and object uses lightmap, skip + } - float shadow = light_process_spot_shadow(light_index, vertex, view); + float shadow = light_process_spot_shadow(light_index, vertex, view); - shadow = blur_shadow(shadow); + shadow = blur_shadow(shadow); - light_process_spot(light_index, vertex, view, normal, vertex_ddx, vertex_ddy, f0, orms, shadow, + light_process_spot(light_index, vertex, view, normal, vertex_ddx, vertex_ddy, f0, orms, shadow, #ifdef LIGHT_BACKLIGHT_USED - backlight, + backlight, #endif #ifdef LIGHT_TRANSMITTANCE_USED - transmittance_color, - transmittance_depth, - transmittance_curve, - transmittance_boost, + transmittance_color, + transmittance_depth, + transmittance_boost, #endif #ifdef LIGHT_RIM_USED - rim, - rim_tint, - albedo, + rim, + rim_tint, + albedo, #endif #ifdef LIGHT_CLEARCOAT_USED - clearcoat, clearcoat_gloss, + clearcoat, clearcoat_gloss, #endif #ifdef LIGHT_ANISOTROPY_USED - tangent, binormal, anisotropy, + tangent, binormal, anisotropy, #endif #ifdef USE_SHADOW_TO_OPACITY - alpha, + alpha, #endif - diffuse_light, specular_light); - } + diffuse_light, specular_light); } } + } #ifdef USE_SHADOW_TO_OPACITY - alpha = min(alpha, clamp(length(ambient_light), 0.0, 1.0)); + alpha = min(alpha, clamp(length(ambient_light), 0.0, 1.0)); #if defined(ALPHA_SCISSOR_USED) - if (alpha < alpha_scissor) { - discard; - } + if (alpha < alpha_scissor) { + discard; + } #endif // ALPHA_SCISSOR_USED #ifdef USE_OPAQUE_PREPASS - if (alpha < opaque_prepass_threshold) { - discard; - } + if (alpha < opaque_prepass_threshold) { + discard; + } #endif // USE_OPAQUE_PREPASS @@ -1819,126 +1760,126 @@ void main() { #ifdef MODE_RENDER_SDF - { - vec3 local_pos = (scene_data.sdf_to_bounds * vec4(vertex, 1.0)).xyz; - ivec3 grid_pos = scene_data.sdf_offset + ivec3(local_pos * vec3(scene_data.sdf_size)); - - uint albedo16 = 0x1; //solid flag - albedo16 |= clamp(uint(albedo.r * 31.0), 0, 31) << 11; - albedo16 |= clamp(uint(albedo.g * 31.0), 0, 31) << 6; - albedo16 |= clamp(uint(albedo.b * 31.0), 0, 31) << 1; - - imageStore(albedo_volume_grid, grid_pos, uvec4(albedo16)); - - uint facing_bits = 0; - const vec3 aniso_dir[6] = vec3[]( - vec3(1, 0, 0), - vec3(0, 1, 0), - vec3(0, 0, 1), - vec3(-1, 0, 0), - vec3(0, -1, 0), - vec3(0, 0, -1)); - - vec3 cam_normal = mat3(scene_data.camera_matrix) * normalize(normal_interp); - - float closest_dist = -1e20; - - for (uint i = 0; i < 6; i++) { - float d = dot(cam_normal, aniso_dir[i]); - if (d > closest_dist) { - closest_dist = d; - facing_bits = (1 << i); - } + { + vec3 local_pos = (scene_data.sdf_to_bounds * vec4(vertex, 1.0)).xyz; + ivec3 grid_pos = scene_data.sdf_offset + ivec3(local_pos * vec3(scene_data.sdf_size)); + + uint albedo16 = 0x1; //solid flag + albedo16 |= clamp(uint(albedo.r * 31.0), 0, 31) << 11; + albedo16 |= clamp(uint(albedo.g * 31.0), 0, 31) << 6; + albedo16 |= clamp(uint(albedo.b * 31.0), 0, 31) << 1; + + imageStore(albedo_volume_grid, grid_pos, uvec4(albedo16)); + + uint facing_bits = 0; + const vec3 aniso_dir[6] = vec3[]( + vec3(1, 0, 0), + vec3(0, 1, 0), + vec3(0, 0, 1), + vec3(-1, 0, 0), + vec3(0, -1, 0), + vec3(0, 0, -1)); + + vec3 cam_normal = mat3(scene_data.camera_matrix) * normalize(normal_interp); + + float closest_dist = -1e20; + + for (uint i = 0; i < 6; i++) { + float d = dot(cam_normal, aniso_dir[i]); + if (d > closest_dist) { + closest_dist = d; + facing_bits = (1 << i); } + } - imageAtomicOr(geom_facing_grid, grid_pos, facing_bits); //store facing bits + imageAtomicOr(geom_facing_grid, grid_pos, facing_bits); //store facing bits - if (length(emission) > 0.001) { - float lumas[6]; - vec3 light_total = vec3(0); + if (length(emission) > 0.001) { + float lumas[6]; + vec3 light_total = vec3(0); - for (int i = 0; i < 6; i++) { - float strength = max(0.0, dot(cam_normal, aniso_dir[i])); - vec3 light = emission * strength; - light_total += light; - lumas[i] = max(light.r, max(light.g, light.b)); - } + for (int i = 0; i < 6; i++) { + float strength = max(0.0, dot(cam_normal, aniso_dir[i])); + vec3 light = emission * strength; + light_total += light; + lumas[i] = max(light.r, max(light.g, light.b)); + } - float luma_total = max(light_total.r, max(light_total.g, light_total.b)); + float luma_total = max(light_total.r, max(light_total.g, light_total.b)); - uint light_aniso = 0; + uint light_aniso = 0; - for (int i = 0; i < 6; i++) { - light_aniso |= min(31, uint((lumas[i] / luma_total) * 31.0)) << (i * 5); - } + for (int i = 0; i < 6; i++) { + light_aniso |= min(31, uint((lumas[i] / luma_total) * 31.0)) << (i * 5); + } - //compress to RGBE9995 to save space + //compress to RGBE9995 to save space - const float pow2to9 = 512.0f; - const float B = 15.0f; - const float N = 9.0f; - const float LN2 = 0.6931471805599453094172321215; + const float pow2to9 = 512.0f; + const float B = 15.0f; + const float N = 9.0f; + const float LN2 = 0.6931471805599453094172321215; - float cRed = clamp(light_total.r, 0.0, 65408.0); - float cGreen = clamp(light_total.g, 0.0, 65408.0); - float cBlue = clamp(light_total.b, 0.0, 65408.0); + float cRed = clamp(light_total.r, 0.0, 65408.0); + float cGreen = clamp(light_total.g, 0.0, 65408.0); + float cBlue = clamp(light_total.b, 0.0, 65408.0); - float cMax = max(cRed, max(cGreen, cBlue)); + float cMax = max(cRed, max(cGreen, cBlue)); - float expp = max(-B - 1.0f, floor(log(cMax) / LN2)) + 1.0f + B; + float expp = max(-B - 1.0f, floor(log(cMax) / LN2)) + 1.0f + B; - float sMax = floor((cMax / pow(2.0f, expp - B - N)) + 0.5f); + float sMax = floor((cMax / pow(2.0f, expp - B - N)) + 0.5f); - float exps = expp + 1.0f; + float exps = expp + 1.0f; - if (0.0 <= sMax && sMax < pow2to9) { - exps = expp; - } + if (0.0 <= sMax && sMax < pow2to9) { + exps = expp; + } - float sRed = floor((cRed / pow(2.0f, exps - B - N)) + 0.5f); - float sGreen = floor((cGreen / pow(2.0f, exps - B - N)) + 0.5f); - float sBlue = floor((cBlue / pow(2.0f, exps - B - N)) + 0.5f); - //store as 8985 to have 2 extra neighbour bits - uint light_rgbe = ((uint(sRed) & 0x1FF) >> 1) | ((uint(sGreen) & 0x1FF) << 8) | (((uint(sBlue) & 0x1FF) >> 1) << 17) | ((uint(exps) & 0x1F) << 25); + float sRed = floor((cRed / pow(2.0f, exps - B - N)) + 0.5f); + float sGreen = floor((cGreen / pow(2.0f, exps - B - N)) + 0.5f); + float sBlue = floor((cBlue / pow(2.0f, exps - B - N)) + 0.5f); + //store as 8985 to have 2 extra neighbour bits + uint light_rgbe = ((uint(sRed) & 0x1FF) >> 1) | ((uint(sGreen) & 0x1FF) << 8) | (((uint(sBlue) & 0x1FF) >> 1) << 17) | ((uint(exps) & 0x1F) << 25); - imageStore(emission_grid, grid_pos, uvec4(light_rgbe)); - imageStore(emission_aniso_grid, grid_pos, uvec4(light_aniso)); - } + imageStore(emission_grid, grid_pos, uvec4(light_rgbe)); + imageStore(emission_aniso_grid, grid_pos, uvec4(light_aniso)); } + } #endif #ifdef MODE_RENDER_MATERIAL - albedo_output_buffer.rgb = albedo; - albedo_output_buffer.a = alpha; + albedo_output_buffer.rgb = albedo; + albedo_output_buffer.a = alpha; - normal_output_buffer.rgb = normal * 0.5 + 0.5; - normal_output_buffer.a = 0.0; - depth_output_buffer.r = -vertex.z; + normal_output_buffer.rgb = normal * 0.5 + 0.5; + normal_output_buffer.a = 0.0; + depth_output_buffer.r = -vertex.z; - orm_output_buffer.r = ao; - orm_output_buffer.g = roughness; - orm_output_buffer.b = metallic; - orm_output_buffer.a = sss_strength; + orm_output_buffer.r = ao; + orm_output_buffer.g = roughness; + orm_output_buffer.b = metallic; + orm_output_buffer.a = sss_strength; - emission_output_buffer.rgb = emission; - emission_output_buffer.a = 0.0; + emission_output_buffer.rgb = emission; + emission_output_buffer.a = 0.0; #endif #ifdef MODE_RENDER_NORMAL_ROUGHNESS - normal_roughness_output_buffer = vec4(normal * 0.5 + 0.5, roughness); + normal_roughness_output_buffer = vec4(normal * 0.5 + 0.5, roughness); #ifdef MODE_RENDER_VOXEL_GI - if (bool(instances.data[instance_index].flags & INSTANCE_FLAGS_USE_VOXEL_GI)) { // process voxel_gi_instances - uint index1 = instances.data[instance_index].gi_offset & 0xFFFF; - uint index2 = instances.data[instance_index].gi_offset >> 16; - voxel_gi_buffer.x = index1 & 0xFF; - voxel_gi_buffer.y = index2 & 0xFF; - } else { - voxel_gi_buffer.x = 0xFF; - voxel_gi_buffer.y = 0xFF; - } + if (bool(instances.data[instance_index].flags & INSTANCE_FLAGS_USE_VOXEL_GI)) { // process voxel_gi_instances + uint index1 = instances.data[instance_index].gi_offset & 0xFFFF; + uint index2 = instances.data[instance_index].gi_offset >> 16; + voxel_gi_buffer.x = index1 & 0xFF; + voxel_gi_buffer.y = index2 & 0xFF; + } else { + voxel_gi_buffer.x = 0xFF; + voxel_gi_buffer.y = 0xFF; + } #endif #endif //MODE_RENDER_NORMAL_ROUGHNESS @@ -1996,4 +1937,4 @@ void main() { #endif //MODE_MULTIPLE_RENDER_TARGETS #endif //MODE_RENDER_DEPTH - } +} diff --git a/servers/rendering/renderer_rd/shaders/scene_forward_clustered_inc.glsl b/servers/rendering/renderer_rd/shaders/scene_forward_clustered_inc.glsl index e64e52623e..6599a42bab 100644 --- a/servers/rendering/renderer_rd/shaders/scene_forward_clustered_inc.glsl +++ b/servers/rendering/renderer_rd/shaders/scene_forward_clustered_inc.glsl @@ -52,6 +52,7 @@ layout(set = 0, binding = 1) uniform sampler material_samplers[12]; layout(set = 0, binding = 2) uniform sampler shadow_sampler; +#define INSTANCE_FLAGS_NON_UNIFORM_SCALE (1 << 5) #define INSTANCE_FLAGS_USE_GI_BUFFERS (1 << 6) #define INSTANCE_FLAGS_USE_SDFGI (1 << 7) #define INSTANCE_FLAGS_USE_LIGHTMAP_CAPTURE (1 << 8) @@ -66,8 +67,6 @@ layout(set = 0, binding = 2) uniform sampler shadow_sampler; //3 bits of stride #define INSTANCE_FLAGS_PARTICLE_TRAIL_MASK 0xFF -#define INSTANCE_FLAGS_NON_UNIFORM_SCALE (1 << 24) - layout(set = 0, binding = 3, std430) restrict readonly buffer OmniLights { LightData data[]; } diff --git a/servers/rendering/renderer_rd/shaders/scene_forward_lights_inc.glsl b/servers/rendering/renderer_rd/shaders/scene_forward_lights_inc.glsl index 709ea45b88..b6e89acb46 100644 --- a/servers/rendering/renderer_rd/shaders/scene_forward_lights_inc.glsl +++ b/servers/rendering/renderer_rd/shaders/scene_forward_lights_inc.glsl @@ -80,7 +80,6 @@ void light_compute(vec3 N, vec3 L, vec3 V, vec3 light_color, float attenuation, #ifdef LIGHT_TRANSMITTANCE_USED vec4 transmittance_color, float transmittance_depth, - float transmittance_curve, float transmittance_boost, float transmittance_z, #endif @@ -189,9 +188,8 @@ void light_compute(vec3 N, vec3 L, vec3 V, vec3 light_color, float attenuation, #ifdef LIGHT_TRANSMITTANCE_USED -#ifdef SSS_MODE_SKIN - { +#ifdef SSS_MODE_SKIN float scale = 8.25 / transmittance_depth; float d = scale * abs(transmittance_z); float dd = -d * d; @@ -203,19 +201,15 @@ void light_compute(vec3 N, vec3 L, vec3 V, vec3 light_color, float attenuation, vec3(0.078, 0.0, 0.0) * exp(dd / 7.41); diffuse_light += profile * transmittance_color.a * light_color * clamp(transmittance_boost - NdotL, 0.0, 1.0) * (1.0 / M_PI); - } #else - if (transmittance_depth > 0.0) { - float fade = clamp(abs(transmittance_z / transmittance_depth), 0.0, 1.0); - - fade = pow(max(0.0, 1.0 - fade), transmittance_curve); - fade *= clamp(transmittance_boost - NdotL, 0.0, 1.0); - - diffuse_light += transmittance_color.rgb * light_color * (1.0 / M_PI) * transmittance_color.a * fade; + float scale = 8.25 / transmittance_depth; + float d = scale * abs(transmittance_z); + float dd = -d * d; + diffuse_light += exp(dd) * transmittance_color.rgb * transmittance_color.a * light_color * clamp(transmittance_boost - NdotL, 0.0, 1.0) * (1.0 / M_PI); +#endif } - -#endif //SSS_MODE_SKIN +#else #endif //LIGHT_TRANSMITTANCE_USED } @@ -577,7 +571,6 @@ void light_process_omni(uint idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 v #ifdef LIGHT_TRANSMITTANCE_USED vec4 transmittance_color, float transmittance_depth, - float transmittance_curve, float transmittance_boost, #endif #ifdef LIGHT_RIM_USED @@ -617,20 +610,22 @@ void light_process_omni(uint idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 v //redo shadowmapping, but shrink the model a bit to avoid arctifacts vec4 splane = (omni_lights.data[idx].shadow_matrix * vec4(vertex - normalize(normal_interp) * omni_lights.data[idx].transmittance_bias, 1.0)); - shadow_len = length(splane.xyz); - splane = normalize(splane.xyz); + float shadow_len = length(splane.xyz); + splane.xyz = normalize(splane.xyz); if (splane.z >= 0.0) { splane.z += 1.0; - + clamp_rect.y += clamp_rect.w; } else { splane.z = 1.0 - splane.z; } splane.xy /= splane.z; + splane.xy = splane.xy * 0.5 + 0.5; splane.z = shadow_len * omni_lights.data[idx].inv_radius; splane.xy = clamp_rect.xy + splane.xy * clamp_rect.zw; + // splane.xy = clamp(splane.xy,clamp_rect.xy + scene_data.shadow_atlas_pixel_size,clamp_rect.xy + clamp_rect.zw - scene_data.shadow_atlas_pixel_size ); splane.w = 1.0; //needed? i think it should be 1 already float shadow_z = textureLod(sampler2D(shadow_atlas, material_samplers[SAMPLER_LINEAR_CLAMP]), splane.xy, 0.0).r; @@ -704,7 +699,6 @@ void light_process_omni(uint idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 v #ifdef LIGHT_TRANSMITTANCE_USED transmittance_color, transmittance_depth, - transmittance_curve, transmittance_boost, transmittance_z, #endif @@ -829,7 +823,6 @@ void light_process_spot(uint idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 v #ifdef LIGHT_TRANSMITTANCE_USED vec4 transmittance_color, float transmittance_depth, - float transmittance_curve, float transmittance_boost, #endif #ifdef LIGHT_RIM_USED @@ -876,13 +869,17 @@ void light_process_spot(uint idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 v float transmittance_z = transmittance_depth; transmittance_color.a *= light_attenuation; { - splane = (spot_lights.data[idx].shadow_matrix * vec4(vertex - normalize(normal_interp) * spot_lights.data[idx].transmittance_bias, 1.0)); + vec4 splane = (spot_lights.data[idx].shadow_matrix * vec4(vertex - normalize(normal_interp) * spot_lights.data[idx].transmittance_bias, 1.0)); splane /= splane.w; splane.xy = splane.xy * spot_lights.data[idx].atlas_rect.zw + spot_lights.data[idx].atlas_rect.xy; float shadow_z = textureLod(sampler2D(shadow_atlas, material_samplers[SAMPLER_LINEAR_CLAMP]), splane.xy, 0.0).r; - //reconstruct depth - shadow_z /= spot_lights.data[idx].inv_radius; + + shadow_z = shadow_z * 2.0 - 1.0; + float z_far = 1.0 / spot_lights.data[idx].inv_radius; + float z_near = 0.01; + shadow_z = 2.0 * z_near * z_far / (z_far + z_near - shadow_z * (z_far - z_near)); + //distance to light plane float z = dot(spot_dir, -light_rel_vec); transmittance_z = z - shadow_z; @@ -898,7 +895,6 @@ void light_process_spot(uint idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 v #ifdef LIGHT_TRANSMITTANCE_USED transmittance_color, transmittance_depth, - transmittance_curve, transmittance_boost, transmittance_z, #endif diff --git a/servers/rendering/renderer_rd/shaders/scene_forward_mobile.glsl b/servers/rendering/renderer_rd/shaders/scene_forward_mobile.glsl index aa8a0b96c5..1bc17e140f 100644 --- a/servers/rendering/renderer_rd/shaders/scene_forward_mobile.glsl +++ b/servers/rendering/renderer_rd/shaders/scene_forward_mobile.glsl @@ -543,7 +543,6 @@ void main() { vec3 backlight = vec3(0.0); vec4 transmittance_color = vec4(0.0); float transmittance_depth = 0.0; - float transmittance_curve = 1.0; float transmittance_boost = 0.0; float metallic = 0.0; float specular = 0.5; @@ -1293,7 +1292,6 @@ void main() { #ifdef LIGHT_TRANSMITTANCE_USED transmittance_color, transmittance_depth, - transmittance_curve, transmittance_boost, transmittance_z, #endif @@ -1344,7 +1342,6 @@ void main() { #ifdef LIGHT_TRANSMITTANCE_USED transmittance_color, transmittance_depth, - transmittance_curve, transmittance_boost, #endif */ @@ -1393,7 +1390,6 @@ void main() { #ifdef LIGHT_TRANSMITTANCE_USED transmittance_color, transmittance_depth, - transmittance_curve, transmittance_boost, #endif */ diff --git a/servers/rendering/renderer_rd/shaders/scene_forward_mobile_inc.glsl b/servers/rendering/renderer_rd/shaders/scene_forward_mobile_inc.glsl index 7fcd84695d..d4ebcbeec4 100644 --- a/servers/rendering/renderer_rd/shaders/scene_forward_mobile_inc.glsl +++ b/servers/rendering/renderer_rd/shaders/scene_forward_mobile_inc.glsl @@ -51,6 +51,7 @@ layout(set = 0, binding = 1) uniform sampler material_samplers[12]; layout(set = 0, binding = 2) uniform sampler shadow_sampler; +#define INSTANCE_FLAGS_NON_UNIFORM_SCALE (1 << 5) #define INSTANCE_FLAGS_USE_GI_BUFFERS (1 << 6) #define INSTANCE_FLAGS_USE_SDFGI (1 << 7) #define INSTANCE_FLAGS_USE_LIGHTMAP_CAPTURE (1 << 8) @@ -65,8 +66,6 @@ layout(set = 0, binding = 2) uniform sampler shadow_sampler; //3 bits of stride #define INSTANCE_FLAGS_PARTICLE_TRAIL_MASK 0xFF -#define INSTANCE_FLAGS_NON_UNIFORM_SCALE (1 << 24) - layout(set = 0, binding = 3, std430) restrict readonly buffer OmniLights { LightData data[]; } diff --git a/servers/rendering/renderer_rd/shaders/screen_space_reflection_scale.glsl b/servers/rendering/renderer_rd/shaders/screen_space_reflection_scale.glsl index 7e06516d90..2328effe7b 100644 --- a/servers/rendering/renderer_rd/shaders/screen_space_reflection_scale.glsl +++ b/servers/rendering/renderer_rd/shaders/screen_space_reflection_scale.glsl @@ -36,12 +36,12 @@ void main() { float divisor = 0.0; vec4 color; float depth; - vec3 normal; + vec4 normal; if (params.filtered) { color = vec4(0.0); depth = 0.0; - normal = vec3(0.0); + normal = vec4(0.0); for (int i = 0; i < 4; i++) { ivec2 ofs = ssC << 1; @@ -53,7 +53,9 @@ void main() { } color += texelFetch(source_ssr, ofs, 0); float d = texelFetch(source_depth, ofs, 0).r; - normal += texelFetch(source_normal, ofs, 0).xyz * 2.0 - 1.0; + vec4 nr = texelFetch(source_normal, ofs, 0); + normal.xyz += nr.xyz * 2.0 - 1.0; + normal.w += nr.w; d = d * 2.0 - 1.0; if (params.orthogonal) { @@ -66,11 +68,12 @@ void main() { color /= 4.0; depth /= 4.0; - normal = normalize(normal / 4.0) * 0.5 + 0.5; + normal.xyz = normalize(normal.xyz / 4.0) * 0.5 + 0.5; + normal.w /= 4.0; } else { color = texelFetch(source_ssr, ssC << 1, 0); depth = texelFetch(source_depth, ssC << 1, 0).r; - normal = texelFetch(source_normal, ssC << 1, 0).xyz; + normal = texelFetch(source_normal, ssC << 1, 0); depth = depth * 2.0 - 1.0; if (params.orthogonal) { @@ -83,5 +86,5 @@ void main() { imageStore(dest_ssr, ssC, color); imageStore(dest_depth, ssC, vec4(depth)); - imageStore(dest_normal, ssC, vec4(normal, 0.0)); + imageStore(dest_normal, ssC, normal); } diff --git a/servers/rendering/renderer_scene.h b/servers/rendering/renderer_scene.h index d71425f465..8273e53d46 100644 --- a/servers/rendering/renderer_scene.h +++ b/servers/rendering/renderer_scene.h @@ -56,7 +56,6 @@ public: virtual RID scenario_allocate() = 0; virtual void scenario_initialize(RID p_rid) = 0; - virtual void scenario_set_debug(RID p_scenario, RS::ScenarioDebugMode p_debug_mode) = 0; virtual void scenario_set_environment(RID p_scenario, RID p_environment) = 0; virtual void scenario_set_camera_effects(RID p_scenario, RID p_fx) = 0; virtual void scenario_set_fallback_environment(RID p_scenario, RID p_environment) = 0; @@ -81,7 +80,6 @@ public: virtual void instance_set_custom_aabb(RID p_instance, AABB p_aabb) = 0; virtual void instance_attach_skeleton(RID p_instance, RID p_skeleton) = 0; - virtual void instance_set_exterior(RID p_instance, bool p_enabled) = 0; virtual void instance_set_extra_visibility_margin(RID p_instance, real_t p_margin) = 0; virtual void instance_set_visibility_parent(RID p_instance, RID p_parent_instance) = 0; @@ -203,7 +201,12 @@ public: virtual void sdfgi_set_debug_probe_select(const Vector3 &p_position, const Vector3 &p_dir) = 0; virtual void render_empty_scene(RID p_render_buffers, RID p_scenario, RID p_shadow_atlas) = 0; - virtual void render_camera(RID p_render_buffers, RID p_camera, RID p_scenario, RID p_viewport, Size2 p_viewport_size, float p_lod_threshold, RID p_shadow_atlas, Ref<XRInterface> &p_xr_interface) = 0; + + struct RenderInfo { + int info[RS::VIEWPORT_RENDER_INFO_TYPE_MAX][RS::VIEWPORT_RENDER_INFO_MAX] = {}; + }; + + virtual void render_camera(RID p_render_buffers, RID p_camera, RID p_scenario, RID p_viewport, Size2 p_viewport_size, float p_lod_threshold, RID p_shadow_atlas, Ref<XRInterface> &p_xr_interface, RenderInfo *r_render_info = nullptr) = 0; virtual void update() = 0; virtual void render_probes() = 0; diff --git a/servers/rendering/renderer_scene_cull.cpp b/servers/rendering/renderer_scene_cull.cpp index efaf77f30b..271c039aad 100644 --- a/servers/rendering/renderer_scene_cull.cpp +++ b/servers/rendering/renderer_scene_cull.cpp @@ -43,7 +43,7 @@ RID RendererSceneCull::camera_allocate() { return camera_owner.allocate_rid(); } void RendererSceneCull::camera_initialize(RID p_rid) { - camera_owner.initialize_rid(p_rid, memnew(Camera)); + camera_owner.initialize_rid(p_rid); } void RendererSceneCull::camera_set_perspective(RID p_camera, float p_fovy_degrees, float p_z_near, float p_z_far) { @@ -310,7 +310,9 @@ RID RendererSceneCull::scenario_allocate() { return scenario_owner.allocate_rid(); } void RendererSceneCull::scenario_initialize(RID p_rid) { - Scenario *scenario = memnew(Scenario); + scenario_owner.initialize_rid(p_rid); + + Scenario *scenario = scenario_owner.getornull(p_rid); scenario->self = p_rid; scenario->reflection_probe_shadow_atlas = scene_render->shadow_atlas_create(); @@ -326,14 +328,6 @@ void RendererSceneCull::scenario_initialize(RID p_rid) { scenario->instance_visibility.set_page_pool(&instance_visibility_data_page_pool); RendererSceneOcclusionCull::get_singleton()->add_scenario(p_rid); - - scenario_owner.initialize_rid(p_rid, scenario); -} - -void RendererSceneCull::scenario_set_debug(RID p_scenario, RS::ScenarioDebugMode p_debug_mode) { - Scenario *scenario = scenario_owner.getornull(p_scenario); - ERR_FAIL_COND(!scenario); - scenario->debug = p_debug_mode; } void RendererSceneCull::scenario_set_environment(RID p_scenario, RID p_environment) { @@ -422,10 +416,9 @@ RID RendererSceneCull::instance_allocate() { return instance_owner.allocate_rid(); } void RendererSceneCull::instance_initialize(RID p_rid) { - Instance *instance = memnew(Instance); + instance_owner.initialize_rid(p_rid); + Instance *instance = instance_owner.getornull(p_rid); instance->self = p_rid; - - instance_owner.initialize_rid(p_rid, instance); } void RendererSceneCull::_instance_update_mesh_instance(Instance *p_instance) { @@ -479,7 +472,6 @@ void RendererSceneCull::instance_set_base(RID p_instance, RID p_base) { switch (instance->base_type) { case RS::INSTANCE_MESH: case RS::INSTANCE_MULTIMESH: - case RS::INSTANCE_IMMEDIATE: case RS::INSTANCE_PARTICLES: { InstanceGeometryData *geom = static_cast<InstanceGeometryData *>(instance->base_data); scene_render->geometry_instance_free(geom->geometry_instance); @@ -591,7 +583,6 @@ void RendererSceneCull::instance_set_base(RID p_instance, RID p_base) { } break; case RS::INSTANCE_MESH: case RS::INSTANCE_MULTIMESH: - case RS::INSTANCE_IMMEDIATE: case RS::INSTANCE_PARTICLES: { InstanceGeometryData *geom = memnew(InstanceGeometryData); instance->base_data = geom; @@ -889,7 +880,7 @@ void RendererSceneCull::instance_set_visible(RID p_instance, bool p_visible) { } inline bool is_geometry_instance(RenderingServer::InstanceType p_type) { - return p_type == RS::INSTANCE_MESH || p_type == RS::INSTANCE_MULTIMESH || p_type == RS::INSTANCE_PARTICLES || p_type == RS::INSTANCE_IMMEDIATE; + return p_type == RS::INSTANCE_MESH || p_type == RS::INSTANCE_MULTIMESH || p_type == RS::INSTANCE_PARTICLES; } void RendererSceneCull::instance_set_custom_aabb(RID p_instance, AABB p_aabb) { @@ -942,9 +933,6 @@ void RendererSceneCull::instance_attach_skeleton(RID p_instance, RID p_skeleton) } } -void RendererSceneCull::instance_set_exterior(RID p_instance, bool p_enabled) { -} - void RendererSceneCull::instance_set_extra_visibility_margin(RID p_instance, real_t p_margin) { Instance *instance = instance_owner.getornull(p_instance); ERR_FAIL_COND(!instance); @@ -1327,6 +1315,8 @@ void RendererSceneCull::instance_geometry_set_shader_parameter(RID p_instance, c Instance *instance = instance_owner.getornull(p_instance); ERR_FAIL_COND(!instance); + ERR_FAIL_COND(p_value.get_type() == Variant::OBJECT); + Map<StringName, Instance::InstanceShaderParameter>::Element *E = instance->instance_shader_parameters.find(p_parameter); if (!E) { @@ -1530,7 +1520,6 @@ void RendererSceneCull::_update_instance(Instance *p_instance) { switch (p_instance->base_type) { case RS::INSTANCE_MESH: case RS::INSTANCE_MULTIMESH: - case RS::INSTANCE_IMMEDIATE: case RS::INSTANCE_PARTICLES: { InstanceGeometryData *geom = static_cast<InstanceGeometryData *>(p_instance->base_data); idata.instance_geometry = geom->geometry_instance; @@ -1749,14 +1738,6 @@ void RendererSceneCull::_update_instance_aabb(Instance *p_instance) { } } break; - case RenderingServer::INSTANCE_IMMEDIATE: { - if (p_instance->custom_aabb) { - new_aabb = *p_instance->custom_aabb; - } else { - new_aabb = RSG::storage->immediate_get_aabb(p_instance->base); - } - - } break; case RenderingServer::INSTANCE_PARTICLES: { if (p_instance->custom_aabb) { new_aabb = *p_instance->custom_aabb; @@ -1898,8 +1879,6 @@ void RendererSceneCull::_light_instance_setup_directional_shadow(int p_shadow_in max_distance = MAX(max_distance, p_cam_projection.get_z_near() + 0.001); real_t min_distance = MIN(p_cam_projection.get_z_near(), max_distance); - RS::LightDirectionalShadowDepthRangeMode depth_range_mode = RSG::storage->light_directional_get_shadow_depth_range_mode(p_instance->base); - real_t pancake_size = RSG::storage->light_get_param(p_instance->base, RS::LIGHT_PARAM_SHADOW_PANCAKE_SIZE); real_t range = max_distance - min_distance; @@ -2059,22 +2038,13 @@ void RendererSceneCull::_light_instance_setup_directional_shadow(int p_shadow_in } } - x_max_cam = x_vec.dot(center) + radius + soft_shadow_expand; - x_min_cam = x_vec.dot(center) - radius - soft_shadow_expand; - y_max_cam = y_vec.dot(center) + radius + soft_shadow_expand; - y_min_cam = y_vec.dot(center) - radius - soft_shadow_expand; - - if (depth_range_mode == RS::LIGHT_DIRECTIONAL_SHADOW_DEPTH_RANGE_STABLE) { - //this trick here is what stabilizes the shadow (make potential jaggies to not move) - //at the cost of some wasted resolution. Still the quality increase is very well worth it - - real_t unit = radius * 2.0 / texture_size; - - x_max_cam = Math::snapped(x_max_cam, unit); - x_min_cam = Math::snapped(x_min_cam, unit); - y_max_cam = Math::snapped(y_max_cam, unit); - y_min_cam = Math::snapped(y_min_cam, unit); - } + // This trick here is what stabilizes the shadow (make potential jaggies to not move) + // at the cost of some wasted resolution. Still, the quality increase is very well worth it. + const real_t unit = radius * 2.0 / texture_size; + x_max_cam = Math::snapped(x_vec.dot(center) + radius + soft_shadow_expand, unit); + x_min_cam = Math::snapped(x_vec.dot(center) - radius - soft_shadow_expand, unit); + y_max_cam = Math::snapped(y_vec.dot(center) + radius + soft_shadow_expand, unit); + y_min_cam = Math::snapped(y_vec.dot(center) - radius - soft_shadow_expand, unit); } //now that we know all ranges, we can proceed to make the light frustum planes, for culling octree @@ -2404,7 +2374,7 @@ bool RendererSceneCull::_light_instance_update_shadow(Instance *p_instance, cons return animated_material_found; } -void RendererSceneCull::render_camera(RID p_render_buffers, RID p_camera, RID p_scenario, RID p_viewport, Size2 p_viewport_size, float p_screen_lod_threshold, RID p_shadow_atlas, Ref<XRInterface> &p_xr_interface) { +void RendererSceneCull::render_camera(RID p_render_buffers, RID p_camera, RID p_scenario, RID p_viewport, Size2 p_viewport_size, float p_screen_lod_threshold, RID p_shadow_atlas, Ref<XRInterface> &p_xr_interface, RenderInfo *r_render_info) { #ifndef _3D_DISABLED Camera *camera = camera_owner.getornull(p_camera); @@ -2486,7 +2456,7 @@ void RendererSceneCull::render_camera(RID p_render_buffers, RID p_camera, RID p_ // For now just cull on the first camera RendererSceneOcclusionCull::get_singleton()->buffer_update(p_viewport, camera_data.main_transform, camera_data.main_projection, camera_data.is_ortogonal, RendererThreadPool::singleton->thread_work_pool); - _render_scene(&camera_data, p_render_buffers, environment, camera->effects, camera->visible_layers, p_scenario, p_viewport, p_shadow_atlas, RID(), -1, p_screen_lod_threshold); + _render_scene(&camera_data, p_render_buffers, environment, camera->effects, camera->visible_layers, p_scenario, p_viewport, p_shadow_atlas, RID(), -1, p_screen_lod_threshold, true, r_render_info); #endif } @@ -2578,7 +2548,7 @@ void RendererSceneCull::_scene_cull(CullData &cull_data, InstanceCullResult &cul #define HIDDEN_BY_VISIBILITY_CHECKS (visibility_flags == InstanceData::FLAG_VISIBILITY_DEPENDENCY_HIDDEN_CLOSE_RANGE || visibility_flags == InstanceData::FLAG_VISIBILITY_DEPENDENCY_HIDDEN) #define LAYER_CHECK (cull_data.visible_layers & idata.layer_mask) #define IN_FRUSTUM(f) (cull_data.scenario->instance_aabbs[i].in_frustum(f)) -#define VIS_RANGE_CHECK ((idata.visibility_index == -1) || _visibility_range_check(cull_data.scenario->instance_visibility[idata.visibility_index], cull_data.cam_transform.origin, cull_data.visibility_cull_data->viewport_mask) == 0) +#define VIS_RANGE_CHECK ((idata.visibility_index == -1) || _visibility_range_check(cull_data.scenario->instance_visibility[idata.visibility_index], cull_data.cam_transform.origin, cull_data.visibility_viewport_mask) == 0) #define VIS_PARENT_CHECK ((idata.parent_array_index == -1) || ((cull_data.scenario->instance_data[idata.parent_array_index].flags & InstanceData::FLAG_VISIBILITY_DEPENDENCY_NEEDS_CHECK) == InstanceData::FLAG_VISIBILITY_DEPENDENCY_HIDDEN_CLOSE_RANGE)) #define VIS_CHECK (visibility_check < 0 ? (visibility_check = (visibility_flags != InstanceData::FLAG_VISIBILITY_DEPENDENCY_NEEDS_CHECK || (VIS_RANGE_CHECK && VIS_PARENT_CHECK))) : visibility_check) #define OCCLUSION_CULLED (cull_data.occlusion_buffer != nullptr && (cull_data.scenario->instance_data[i].flags & InstanceData::FLAG_IGNORE_OCCLUSION_CULLING) == 0 && cull_data.occlusion_buffer->is_occluded(cull_data.scenario->instance_aabbs[i].bounds, cull_data.cam_transform.origin, inv_cam_transform, *cull_data.camera_matrix, z_near)) @@ -2792,7 +2762,7 @@ void RendererSceneCull::_scene_cull(CullData &cull_data, InstanceCullResult &cul } } -void RendererSceneCull::_render_scene(const RendererSceneRender::CameraData *p_camera_data, RID p_render_buffers, RID p_environment, RID p_force_camera_effects, uint32_t p_visible_layers, RID p_scenario, RID p_viewport, RID p_shadow_atlas, RID p_reflection_probe, int p_reflection_probe_pass, float p_screen_lod_threshold, bool p_using_shadows) { +void RendererSceneCull::_render_scene(const RendererSceneRender::CameraData *p_camera_data, RID p_render_buffers, RID p_environment, RID p_force_camera_effects, uint32_t p_visible_layers, RID p_scenario, RID p_viewport, RID p_shadow_atlas, RID p_reflection_probe, int p_reflection_probe_pass, float p_screen_lod_threshold, bool p_using_shadows, RendererScene::RenderInfo *r_render_info) { Instance *render_reflection_probe = instance_owner.getornull(p_reflection_probe); //if null, not rendering to it Scenario *scenario = scenario_owner.getornull(p_scenario); @@ -2808,12 +2778,12 @@ void RendererSceneCull::_render_scene(const RendererSceneRender::CameraData *p_c RENDER_TIMESTAMP("Visibility Dependencies"); - VisibilityCullData visibility_cull_data; if (scenario->instance_visibility.get_bin_count() > 0) { if (!scenario->viewport_visibility_masks.has(p_viewport)) { scenario_add_viewport_visibility_mask(scenario->self, p_viewport); } + VisibilityCullData visibility_cull_data; visibility_cull_data.scenario = scenario; visibility_cull_data.viewport_mask = scenario->viewport_visibility_masks[p_viewport]; visibility_cull_data.camera_position = p_camera_data->main_transform.origin; @@ -2924,6 +2894,7 @@ void RendererSceneCull::_render_scene(const RendererSceneRender::CameraData *p_c cull_data.render_reflection_probe = render_reflection_probe; cull_data.occlusion_buffer = RendererSceneOcclusionCull::get_singleton()->buffer_get_ptr(p_viewport); cull_data.camera_matrix = &p_camera_data->main_projection; + cull_data.visibility_viewport_mask = scenario->viewport_visibility_masks.has(p_viewport) ? scenario->viewport_visibility_masks[p_viewport] : 0; //#define DEBUG_CULL_TIME #ifdef DEBUG_CULL_TIME uint64_t time_from = OS::get_singleton()->get_ticks_usec(); @@ -3136,7 +3107,7 @@ void RendererSceneCull::_render_scene(const RendererSceneRender::CameraData *p_c } RENDER_TIMESTAMP("Render Scene "); - scene_render->render_scene(p_render_buffers, p_camera_data, scene_cull_result.geometry_instances, scene_cull_result.light_instances, scene_cull_result.reflections, scene_cull_result.voxel_gi_instances, scene_cull_result.decals, scene_cull_result.lightmaps, p_environment, camera_effects, p_shadow_atlas, occluders_tex, p_reflection_probe.is_valid() ? RID() : scenario->reflection_atlas, p_reflection_probe, p_reflection_probe_pass, p_screen_lod_threshold, render_shadow_data, max_shadows_used, render_sdfgi_data, cull.sdfgi.region_count, &sdfgi_update_data); + scene_render->render_scene(p_render_buffers, p_camera_data, scene_cull_result.geometry_instances, scene_cull_result.light_instances, scene_cull_result.reflections, scene_cull_result.voxel_gi_instances, scene_cull_result.decals, scene_cull_result.lightmaps, p_environment, camera_effects, p_shadow_atlas, occluders_tex, p_reflection_probe.is_valid() ? RID() : scenario->reflection_atlas, p_reflection_probe, p_reflection_probe_pass, p_screen_lod_threshold, render_shadow_data, max_shadows_used, render_sdfgi_data, cull.sdfgi.region_count, &sdfgi_update_data, r_render_info); for (uint32_t i = 0; i < max_shadows_used; i++) { render_shadow_data[i].instances.clear(); @@ -3173,7 +3144,6 @@ RID RendererSceneCull::_render_get_environment(RID p_camera, RID p_scenario) { void RendererSceneCull::render_empty_scene(RID p_render_buffers, RID p_scenario, RID p_shadow_atlas) { #ifndef _3D_DISABLED - Scenario *scenario = scenario_owner.getornull(p_scenario); RID environment; @@ -3681,25 +3651,6 @@ void RendererSceneCull::_update_dirty_instance(Instance *p_instance) { RSG::storage->base_update_dependency(mesh, &p_instance->dependency_tracker); } - } else if (p_instance->base_type == RS::INSTANCE_IMMEDIATE) { - RID mat = RSG::storage->immediate_get_material(p_instance->base); - - if (!(!mat.is_valid() || RSG::storage->material_casts_shadows(mat))) { - can_cast_shadows = false; - } - - if (mat.is_valid() && RSG::storage->material_is_animated(mat)) { - is_animated = true; - } - - if (mat.is_valid()) { - _update_instance_shader_parameters_from_material(isparams, p_instance->instance_shader_parameters, mat); - } - - if (mat.is_valid()) { - RSG::storage->material_update_dependency(mat, &p_instance->dependency_tracker); - } - } else if (p_instance->base_type == RS::INSTANCE_PARTICLES) { bool cast_shadows = false; @@ -3817,10 +3768,7 @@ bool RendererSceneCull::free(RID p_rid) { } if (camera_owner.owns(p_rid)) { - Camera *camera = camera_owner.getornull(p_rid); - camera_owner.free(p_rid); - memdelete(camera); } else if (scenario_owner.owns(p_rid)) { Scenario *scenario = scenario_owner.getornull(p_rid); @@ -3836,7 +3784,6 @@ bool RendererSceneCull::free(RID p_rid) { scene_render->free(scenario->reflection_atlas); scenario_owner.free(p_rid); RendererSceneOcclusionCull::get_singleton()->remove_scenario(p_rid); - memdelete(scenario); } else if (RendererSceneOcclusionCull::get_singleton()->is_occluder(p_rid)) { RendererSceneOcclusionCull::get_singleton()->free_occluder(p_rid); @@ -3860,7 +3807,6 @@ bool RendererSceneCull::free(RID p_rid) { update_dirty_instances(); //in case something changed this instance_owner.free(p_rid); - memdelete(instance); } else { return false; } diff --git a/servers/rendering/renderer_scene_cull.h b/servers/rendering/renderer_scene_cull.h index d9466d8b04..d586fb531f 100644 --- a/servers/rendering/renderer_scene_cull.h +++ b/servers/rendering/renderer_scene_cull.h @@ -97,7 +97,7 @@ public: } }; - mutable RID_PtrOwner<Camera, true> camera_owner; + mutable RID_Owner<Camera, true> camera_owner; virtual RID camera_allocate(); virtual void camera_initialize(RID p_rid); @@ -315,7 +315,6 @@ public: DynamicBVH indexers[INDEXER_MAX]; - RS::ScenarioDebugMode debug; RID self; List<Instance *> directional_lights; @@ -338,14 +337,13 @@ public: Scenario() { indexers[INDEXER_GEOMETRY].set_index(INDEXER_GEOMETRY); indexers[INDEXER_VOLUMES].set_index(INDEXER_VOLUMES); - debug = RS::SCENARIO_DEBUG_DISABLED; used_viewport_visibility_bits = 0; } }; int indexer_update_iterations = 0; - mutable RID_PtrOwner<Scenario, true> scenario_owner; + mutable RID_Owner<Scenario, true> scenario_owner; static void _instance_pair(Instance *p_A, Instance *p_B); static void _instance_unpair(Instance *p_A, Instance *p_B); @@ -355,7 +353,6 @@ public: virtual RID scenario_allocate(); virtual void scenario_initialize(RID p_rid); - virtual void scenario_set_debug(RID p_scenario, RS::ScenarioDebugMode p_debug_mode); virtual void scenario_set_environment(RID p_scenario, RID p_environment); virtual void scenario_set_camera_effects(RID p_scenario, RID p_fx); virtual void scenario_set_fallback_environment(RID p_scenario, RID p_environment); @@ -895,7 +892,7 @@ public: uint32_t thread_cull_threshold = 200; - RID_PtrOwner<Instance, true> instance_owner; + RID_Owner<Instance, true> instance_owner; uint32_t geometry_instance_pair_mask; // used in traditional forward, unnecessary on clustered @@ -914,7 +911,6 @@ public: virtual void instance_set_custom_aabb(RID p_instance, AABB p_aabb); virtual void instance_attach_skeleton(RID p_instance, RID p_skeleton); - virtual void instance_set_exterior(RID p_instance, bool p_enabled); virtual void instance_set_extra_visibility_margin(RID p_instance, real_t p_margin); @@ -1016,17 +1012,17 @@ public: Instance *render_reflection_probe; const RendererSceneOcclusionCull::HZBuffer *occlusion_buffer; const CameraMatrix *camera_matrix; - const VisibilityCullData *visibility_cull_data; + uint64_t visibility_viewport_mask; }; void _scene_cull_threaded(uint32_t p_thread, CullData *cull_data); void _scene_cull(CullData &cull_data, InstanceCullResult &cull_result, uint64_t p_from, uint64_t p_to); bool _render_reflection_probe_step(Instance *p_instance, int p_step); - void _render_scene(const RendererSceneRender::CameraData *p_camera_data, RID p_render_buffers, RID p_environment, RID p_force_camera_effects, uint32_t p_visible_layers, RID p_scenario, RID p_viewport, RID p_shadow_atlas, RID p_reflection_probe, int p_reflection_probe_pass, float p_screen_lod_threshold, bool p_using_shadows = true); + void _render_scene(const RendererSceneRender::CameraData *p_camera_data, RID p_render_buffers, RID p_environment, RID p_force_camera_effects, uint32_t p_visible_layers, RID p_scenario, RID p_viewport, RID p_shadow_atlas, RID p_reflection_probe, int p_reflection_probe_pass, float p_screen_lod_threshold, bool p_using_shadows = true, RenderInfo *r_render_info = nullptr); void render_empty_scene(RID p_render_buffers, RID p_scenario, RID p_shadow_atlas); - void render_camera(RID p_render_buffers, RID p_camera, RID p_scenario, RID p_viewport, Size2 p_viewport_size, float p_screen_lod_threshold, RID p_shadow_atlas, Ref<XRInterface> &p_xr_interface); + void render_camera(RID p_render_buffers, RID p_camera, RID p_scenario, RID p_viewport, Size2 p_viewport_size, float p_screen_lod_threshold, RID p_shadow_atlas, Ref<XRInterface> &p_xr_interface, RendererScene::RenderInfo *r_render_info = nullptr); void update_dirty_instances(); void render_particle_colliders(); diff --git a/servers/rendering/renderer_scene_occlusion_cull.cpp b/servers/rendering/renderer_scene_occlusion_cull.cpp index c491ccbe7a..1b8aea36d7 100644 --- a/servers/rendering/renderer_scene_occlusion_cull.cpp +++ b/servers/rendering/renderer_scene_occlusion_cull.cpp @@ -172,7 +172,7 @@ RID RendererSceneOcclusionCull::HZBuffer::get_debug_texture() { } if (debug_image.is_null()) { - debug_image.instance(); + debug_image.instantiate(); } unsigned char *ptrw = debug_data.ptrw(); @@ -185,7 +185,7 @@ RID RendererSceneOcclusionCull::HZBuffer::get_debug_texture() { if (debug_texture.is_null()) { debug_texture = RS::get_singleton()->texture_2d_create(debug_image); } else { - RenderingServer::get_singleton()->texture_2d_update_immediate(debug_texture, debug_image); + RenderingServer::get_singleton()->texture_2d_update(debug_texture, debug_image); } return debug_texture; diff --git a/servers/rendering/renderer_scene_render.cpp b/servers/rendering/renderer_scene_render.cpp index 3aa97f4084..3a230ac89d 100644 --- a/servers/rendering/renderer_scene_render.cpp +++ b/servers/rendering/renderer_scene_render.cpp @@ -175,7 +175,7 @@ void RendererSceneRender::CameraData::set_multiview_camera(uint32_t p_view_count ///////////////////////////////////////////////////////////////////////////// // 3. Copy our view data for (uint32_t v = 0; v < view_count; v++) { - view_offset[v] = p_transforms[v] * main_transform_inv; - view_projection[v] = p_projections[v] * CameraMatrix(view_offset[v]); + view_offset[v] = main_transform_inv * p_transforms[v]; + view_projection[v] = p_projections[v] * CameraMatrix(view_offset[v].inverse()); } } diff --git a/servers/rendering/renderer_scene_render.h b/servers/rendering/renderer_scene_render.h index 3682122dd3..ff0fea16d0 100644 --- a/servers/rendering/renderer_scene_render.h +++ b/servers/rendering/renderer_scene_render.h @@ -33,6 +33,7 @@ #include "core/math/camera_matrix.h" #include "core/templates/paged_array.h" +#include "servers/rendering/renderer_scene.h" #include "servers/rendering/renderer_storage.h" class RendererSceneRender { @@ -234,7 +235,7 @@ public: void set_multiview_camera(uint32_t p_view_count, const Transform3D *p_transforms, const CameraMatrix *p_projections, bool p_is_ortogonal, bool p_vaspect); }; - virtual void render_scene(RID p_render_buffers, const CameraData *p_camera_data, const PagedArray<GeometryInstance *> &p_instances, const PagedArray<RID> &p_lights, const PagedArray<RID> &p_reflection_probes, const PagedArray<RID> &p_voxel_gi_instances, const PagedArray<RID> &p_decals, const PagedArray<RID> &p_lightmaps, RID p_environment, RID p_camera_effects, RID p_shadow_atlas, RID p_occluder_debug_tex, RID p_reflection_atlas, RID p_reflection_probe, int p_reflection_probe_pass, float p_screen_lod_threshold, const RenderShadowData *p_render_shadows, int p_render_shadow_count, const RenderSDFGIData *p_render_sdfgi_regions, int p_render_sdfgi_region_count, const RenderSDFGIUpdateData *p_sdfgi_update_data = nullptr) = 0; + virtual void render_scene(RID p_render_buffers, const CameraData *p_camera_data, const PagedArray<GeometryInstance *> &p_instances, const PagedArray<RID> &p_lights, const PagedArray<RID> &p_reflection_probes, const PagedArray<RID> &p_voxel_gi_instances, const PagedArray<RID> &p_decals, const PagedArray<RID> &p_lightmaps, RID p_environment, RID p_camera_effects, RID p_shadow_atlas, RID p_occluder_debug_tex, RID p_reflection_atlas, RID p_reflection_probe, int p_reflection_probe_pass, float p_screen_lod_threshold, const RenderShadowData *p_render_shadows, int p_render_shadow_count, const RenderSDFGIData *p_render_sdfgi_regions, int p_render_sdfgi_region_count, const RenderSDFGIUpdateData *p_sdfgi_update_data = nullptr, RendererScene::RenderInfo *r_render_info = nullptr) = 0; virtual void render_material(const Transform3D &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, const PagedArray<GeometryInstance *> &p_instances, RID p_framebuffer, const Rect2i &p_region) = 0; virtual void render_particle_collider_heightfield(RID p_collider, const Transform3D &p_transform, const PagedArray<GeometryInstance *> &p_instances) = 0; diff --git a/servers/rendering/renderer_storage.h b/servers/rendering/renderer_storage.h index f22c582f48..b2aa0d27d3 100644 --- a/servers/rendering/renderer_storage.h +++ b/servers/rendering/renderer_storage.h @@ -130,7 +130,6 @@ public: virtual void texture_3d_initialize(RID p_texture, Image::Format, int p_width, int p_height, int p_depth, bool p_mipmaps, const Vector<Ref<Image>> &p_data) = 0; virtual void texture_proxy_initialize(RID p_texture, RID p_base) = 0; //all slices, then all the mipmaps, must be coherent - virtual void texture_2d_update_immediate(RID p_texture, const Ref<Image> &p_image, int p_layer = 0) = 0; //mostly used for video and streaming virtual void texture_2d_update(RID p_texture, const Ref<Image> &p_image, int p_layer = 0) = 0; virtual void texture_3d_update(RID p_texture, const Vector<Ref<Image>> &p_data) = 0; virtual void texture_proxy_update(RID p_proxy, RID p_base) = 0; @@ -230,7 +229,9 @@ public: virtual void mesh_set_blend_shape_mode(RID p_mesh, RS::BlendShapeMode p_mode) = 0; virtual RS::BlendShapeMode mesh_get_blend_shape_mode(RID p_mesh) const = 0; - virtual void mesh_surface_update_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) = 0; + virtual void mesh_surface_update_vertex_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) = 0; + virtual void mesh_surface_update_attribute_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) = 0; + virtual void mesh_surface_update_skin_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) = 0; virtual void mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material) = 0; virtual RID mesh_surface_get_material(RID p_mesh, int p_surface) const = 0; @@ -288,24 +289,6 @@ public: virtual AABB multimesh_get_aabb(RID p_multimesh) const = 0; - /* IMMEDIATE API */ - - virtual RID immediate_allocate() = 0; - virtual void immediate_initialize(RID p_rid) = 0; - - virtual void immediate_begin(RID p_immediate, RS::PrimitiveType p_rimitive, RID p_texture = RID()) = 0; - virtual void immediate_vertex(RID p_immediate, const Vector3 &p_vertex) = 0; - virtual void immediate_normal(RID p_immediate, const Vector3 &p_normal) = 0; - virtual void immediate_tangent(RID p_immediate, const Plane &p_tangent) = 0; - virtual void immediate_color(RID p_immediate, const Color &p_color) = 0; - virtual void immediate_uv(RID p_immediate, const Vector2 &tex_uv) = 0; - virtual void immediate_uv2(RID p_immediate, const Vector2 &tex_uv) = 0; - virtual void immediate_end(RID p_immediate) = 0; - virtual void immediate_clear(RID p_immediate) = 0; - virtual void immediate_set_material(RID p_immediate, RID p_material) = 0; - virtual RID immediate_get_material(RID p_immediate) const = 0; - virtual AABB immediate_get_aabb(RID p_immediate) const = 0; - /* SKELETON API */ virtual RID skeleton_allocate() = 0; @@ -348,8 +331,6 @@ public: virtual bool light_directional_get_blend_splits(RID p_light) const = 0; virtual void light_directional_set_sky_only(RID p_light, bool p_sky_only) = 0; virtual bool light_directional_is_sky_only(RID p_light) const = 0; - virtual void light_directional_set_shadow_depth_range_mode(RID p_light, RS::LightDirectionalShadowDepthRangeMode p_range_mode) = 0; - virtual RS::LightDirectionalShadowDepthRangeMode light_directional_get_shadow_depth_range_mode(RID p_light) const = 0; virtual RS::LightDirectionalShadowMode light_directional_get_shadow_mode(RID p_light) = 0; virtual RS::LightOmniShadowMode light_omni_get_shadow_mode(RID p_light) = 0; @@ -438,12 +419,6 @@ public: virtual void voxel_gi_set_energy(RID p_voxel_gi, float p_energy) = 0; virtual float voxel_gi_get_energy(RID p_voxel_gi) const = 0; - virtual void voxel_gi_set_ao(RID p_voxel_gi, float p_ao) = 0; - virtual float voxel_gi_get_ao(RID p_voxel_gi) const = 0; - - virtual void voxel_gi_set_ao_size(RID p_voxel_gi, float p_strength) = 0; - virtual float voxel_gi_get_ao_size(RID p_voxel_gi) const = 0; - virtual void voxel_gi_set_bias(RID p_voxel_gi, float p_bias) = 0; virtual float voxel_gi_get_bias(RID p_voxel_gi) const = 0; @@ -624,11 +599,9 @@ public: virtual void set_debug_generate_wireframes(bool p_generate) = 0; - virtual void render_info_begin_capture() = 0; - virtual void render_info_end_capture() = 0; - virtual int get_captured_render_info(RS::RenderInfo p_info) = 0; + virtual void update_memory_info() = 0; - virtual uint64_t get_render_info(RS::RenderInfo p_info) = 0; + virtual uint64_t get_rendering_info(RS::RenderingInfo p_info) = 0; virtual String get_video_adapter_name() const = 0; virtual String get_video_adapter_vendor() const = 0; diff --git a/servers/rendering/renderer_viewport.cpp b/servers/rendering/renderer_viewport.cpp index 34bdb15c62..15ce1dbe63 100644 --- a/servers/rendering/renderer_viewport.cpp +++ b/servers/rendering/renderer_viewport.cpp @@ -95,7 +95,7 @@ void RendererViewport::_draw_3d(Viewport *p_viewport) { } float screen_lod_threshold = p_viewport->lod_threshold / float(p_viewport->size.width); - RSG::scene->render_camera(p_viewport->render_buffers, p_viewport->camera, p_viewport->scenario, p_viewport->self, p_viewport->size, screen_lod_threshold, p_viewport->shadow_atlas, xr_interface); + RSG::scene->render_camera(p_viewport->render_buffers, p_viewport->camera, p_viewport->scenario, p_viewport->self, p_viewport->size, screen_lod_threshold, p_viewport->shadow_atlas, xr_interface, &p_viewport->render_info); RENDER_TIMESTAMP("<End Rendering 3D Scene"); } @@ -112,9 +112,15 @@ void RendererViewport::_draw_viewport(Viewport *p_viewport, uint32_t p_view_coun bool scenario_draw_canvas_bg = false; //draw canvas, or some layer of it, as BG for 3D instead of in front int scenario_canvas_max_layer = 0; + for (int i = 0; i < RS::VIEWPORT_RENDER_INFO_TYPE_MAX; i++) { + for (int j = 0; j < RS::VIEWPORT_RENDER_INFO_MAX; j++) { + p_viewport->render_info.info[i][j] = 0; + } + } + Color bgcolor = RSG::storage->get_default_clear_color(); - if (!p_viewport->hide_canvas && !p_viewport->disable_environment && RSG::scene->is_scenario(p_viewport->scenario)) { + if (!p_viewport->disable_2d && !p_viewport->disable_environment && RSG::scene->is_scenario(p_viewport->scenario)) { RID environment = RSG::scene->scenario_get_environment(p_viewport->scenario); if (RSG::scene->is_environment(environment)) { scenario_draw_canvas_bg = RSG::scene->environment_get_background(environment) == RS::ENV_BG_CANVAS; @@ -122,7 +128,7 @@ void RendererViewport::_draw_viewport(Viewport *p_viewport, uint32_t p_view_coun } } - bool can_draw_3d = RSG::scene->is_camera(p_viewport->camera); + bool can_draw_3d = RSG::scene->is_camera(p_viewport->camera) && !p_viewport->disable_3d; if (p_viewport->clear_mode != RS::VIEWPORT_CLEAR_NEVER) { if (p_viewport->transparent_bg) { @@ -145,7 +151,7 @@ void RendererViewport::_draw_viewport(Viewport *p_viewport, uint32_t p_view_coun _draw_3d(p_viewport); } - if (!p_viewport->hide_canvas) { + if (!p_viewport->disable_2d) { int i = 0; Map<Viewport::CanvasKey, Viewport::CanvasData *> canvas_map; @@ -522,6 +528,10 @@ void RendererViewport::draw_viewports() { } } + int vertices_drawn = 0; + int objects_drawn = 0; + int draw_calls_used = 0; + for (int i = 0; i < active_viewports.size(); i++) { Viewport *vp = active_viewports[i]; @@ -544,19 +554,11 @@ void RendererViewport::draw_viewports() { // render... RSG::scene->set_debug_draw_mode(vp->debug_draw); - RSG::storage->render_info_begin_capture(); // and draw viewport _draw_viewport(vp, view_count); // measure - RSG::storage->render_info_end_capture(); - vp->render_info[RS::VIEWPORT_RENDER_INFO_OBJECTS_IN_FRAME] = RSG::storage->get_captured_render_info(RS::INFO_OBJECTS_IN_FRAME); - vp->render_info[RS::VIEWPORT_RENDER_INFO_VERTICES_IN_FRAME] = RSG::storage->get_captured_render_info(RS::INFO_VERTICES_IN_FRAME); - vp->render_info[RS::VIEWPORT_RENDER_INFO_MATERIAL_CHANGES_IN_FRAME] = RSG::storage->get_captured_render_info(RS::INFO_MATERIAL_CHANGES_IN_FRAME); - vp->render_info[RS::VIEWPORT_RENDER_INFO_SHADER_CHANGES_IN_FRAME] = RSG::storage->get_captured_render_info(RS::INFO_SHADER_CHANGES_IN_FRAME); - vp->render_info[RS::VIEWPORT_RENDER_INFO_SURFACE_CHANGES_IN_FRAME] = RSG::storage->get_captured_render_info(RS::INFO_SURFACE_CHANGES_IN_FRAME); - vp->render_info[RS::VIEWPORT_RENDER_INFO_DRAW_CALLS_IN_FRAME] = RSG::storage->get_captured_render_info(RS::INFO_DRAW_CALLS_IN_FRAME); // commit our eyes Vector<BlitToScreen> blits = xr_interface->commit_views(vp->render_target, vp->viewport_to_screen_rect); @@ -576,19 +578,10 @@ void RendererViewport::draw_viewports() { RSG::storage->render_target_set_external_texture(vp->render_target, 0); RSG::scene->set_debug_draw_mode(vp->debug_draw); - RSG::storage->render_info_begin_capture(); // render standard mono camera _draw_viewport(vp, 1); - RSG::storage->render_info_end_capture(); - vp->render_info[RS::VIEWPORT_RENDER_INFO_OBJECTS_IN_FRAME] = RSG::storage->get_captured_render_info(RS::INFO_OBJECTS_IN_FRAME); - vp->render_info[RS::VIEWPORT_RENDER_INFO_VERTICES_IN_FRAME] = RSG::storage->get_captured_render_info(RS::INFO_VERTICES_IN_FRAME); - vp->render_info[RS::VIEWPORT_RENDER_INFO_MATERIAL_CHANGES_IN_FRAME] = RSG::storage->get_captured_render_info(RS::INFO_MATERIAL_CHANGES_IN_FRAME); - vp->render_info[RS::VIEWPORT_RENDER_INFO_SHADER_CHANGES_IN_FRAME] = RSG::storage->get_captured_render_info(RS::INFO_SHADER_CHANGES_IN_FRAME); - vp->render_info[RS::VIEWPORT_RENDER_INFO_SURFACE_CHANGES_IN_FRAME] = RSG::storage->get_captured_render_info(RS::INFO_SURFACE_CHANGES_IN_FRAME); - vp->render_info[RS::VIEWPORT_RENDER_INFO_DRAW_CALLS_IN_FRAME] = RSG::storage->get_captured_render_info(RS::INFO_DRAW_CALLS_IN_FRAME); - if (vp->viewport_to_screen != DisplayServer::INVALID_WINDOW_ID && (!vp->viewport_render_direct_to_screen || !RSG::rasterizer->is_low_end())) { //copy to screen if set as such BlitToScreen blit; @@ -613,9 +606,17 @@ void RendererViewport::draw_viewports() { } RENDER_TIMESTAMP("<Rendering Viewport " + itos(i)); + + objects_drawn += vp->render_info.info[RS::VIEWPORT_RENDER_INFO_TYPE_VISIBLE][RS::VIEWPORT_RENDER_INFO_OBJECTS_IN_FRAME] + vp->render_info.info[RS::VIEWPORT_RENDER_INFO_TYPE_SHADOW][RS::VIEWPORT_RENDER_INFO_OBJECTS_IN_FRAME]; + vertices_drawn += vp->render_info.info[RS::VIEWPORT_RENDER_INFO_TYPE_VISIBLE][RS::VIEWPORT_RENDER_INFO_PRIMITIVES_IN_FRAME] + vp->render_info.info[RS::VIEWPORT_RENDER_INFO_TYPE_SHADOW][RS::VIEWPORT_RENDER_INFO_PRIMITIVES_IN_FRAME]; + draw_calls_used += vp->render_info.info[RS::VIEWPORT_RENDER_INFO_TYPE_VISIBLE][RS::VIEWPORT_RENDER_INFO_DRAW_CALLS_IN_FRAME] + vp->render_info.info[RS::VIEWPORT_RENDER_INFO_TYPE_SHADOW][RS::VIEWPORT_RENDER_INFO_DRAW_CALLS_IN_FRAME]; } RSG::scene->set_debug_draw_mode(RS::VIEWPORT_DEBUG_DRAW_DISABLED); + total_objects_drawn = objects_drawn; + total_vertices_drawn = vertices_drawn; + total_draw_calls_used = draw_calls_used; + RENDER_TIMESTAMP("<Render Viewports"); //this needs to be called to make screen swapping more efficient RSG::rasterizer->prepare_for_blitting_render_targets(); @@ -630,15 +631,12 @@ RID RendererViewport::viewport_allocate() { } void RendererViewport::viewport_initialize(RID p_rid) { - Viewport *viewport = memnew(Viewport); + viewport_owner.initialize_rid(p_rid); + Viewport *viewport = viewport_owner.getornull(p_rid); viewport->self = p_rid; - viewport->hide_scenario = false; - viewport->hide_canvas = false; viewport->render_target = RSG::storage->render_target_create(); viewport->shadow_atlas = RSG::scene->shadow_atlas_create(); viewport->viewport_render_direct_to_screen = false; - - viewport_owner.initialize_rid(p_rid, viewport); } void RendererViewport::viewport_set_use_xr(RID p_viewport, bool p_use_xr) { @@ -696,7 +694,7 @@ void RendererViewport::viewport_set_active(RID p_viewport, bool p_active) { ERR_FAIL_COND(!viewport); if (p_active) { - ERR_FAIL_COND(active_viewports.find(viewport) != -1); //already active + ERR_FAIL_COND_MSG(active_viewports.find(viewport) != -1, "Can't make active a Viewport that is already active."); viewport->occlusion_buffer_dirty = true; active_viewports.push_back(viewport); } else { @@ -792,25 +790,25 @@ RID RendererViewport::viewport_get_occluder_debug_texture(RID p_viewport) const return RID(); } -void RendererViewport::viewport_set_hide_scenario(RID p_viewport, bool p_hide) { +void RendererViewport::viewport_set_disable_2d(RID p_viewport, bool p_disable) { Viewport *viewport = viewport_owner.getornull(p_viewport); ERR_FAIL_COND(!viewport); - viewport->hide_scenario = p_hide; + viewport->disable_2d = p_disable; } -void RendererViewport::viewport_set_hide_canvas(RID p_viewport, bool p_hide) { +void RendererViewport::viewport_set_disable_environment(RID p_viewport, bool p_disable) { Viewport *viewport = viewport_owner.getornull(p_viewport); ERR_FAIL_COND(!viewport); - viewport->hide_canvas = p_hide; + viewport->disable_environment = p_disable; } -void RendererViewport::viewport_set_disable_environment(RID p_viewport, bool p_disable) { +void RendererViewport::viewport_set_disable_3d(RID p_viewport, bool p_disable) { Viewport *viewport = viewport_owner.getornull(p_viewport); ERR_FAIL_COND(!viewport); - viewport->disable_environment = p_disable; + viewport->disable_3d = p_disable; } void RendererViewport::viewport_attach_camera(RID p_viewport, RID p_camera) { @@ -990,7 +988,7 @@ void RendererViewport::viewport_set_lod_threshold(RID p_viewport, float p_pixels viewport->lod_threshold = p_pixels; } -int RendererViewport::viewport_get_render_info(RID p_viewport, RS::ViewportRenderInfo p_info) { +int RendererViewport::viewport_get_render_info(RID p_viewport, RS::ViewportRenderInfoType p_type, RS::ViewportRenderInfo p_info) { ERR_FAIL_INDEX_V(p_info, RS::VIEWPORT_RENDER_INFO_MAX, -1); Viewport *viewport = viewport_owner.getornull(p_viewport); @@ -998,7 +996,7 @@ int RendererViewport::viewport_get_render_info(RID p_viewport, RS::ViewportRende return 0; //there should be a lock here.. } - return viewport->render_info[p_info]; + return viewport->render_info.info[p_type][p_info]; } void RendererViewport::viewport_set_debug_draw(RID p_viewport, RS::ViewportDebugDraw p_draw) { @@ -1085,7 +1083,6 @@ bool RendererViewport::free(RID p_rid) { } viewport_owner.free(p_rid); - memdelete(viewport); return true; } @@ -1119,9 +1116,19 @@ void RendererViewport::set_default_clear_color(const Color &p_color) { RSG::storage->set_default_clear_color(p_color); } -//workaround for setting this on thread -void RendererViewport::call_set_use_vsync(bool p_enable) { - DisplayServer::get_singleton()->_set_use_vsync(p_enable); +// Workaround for setting this on thread. +void RendererViewport::call_set_vsync_mode(DisplayServer::VSyncMode p_mode, DisplayServer::WindowID p_window) { + DisplayServer::get_singleton()->window_set_vsync_mode(p_mode, p_window); +} + +int RendererViewport::get_total_objects_drawn() const { + return total_objects_drawn; +} +int RendererViewport::get_total_vertices_drawn() const { + return total_vertices_drawn; +} +int RendererViewport::get_total_draw_calls_used() const { + return total_draw_calls_used; } RendererViewport::RendererViewport() { diff --git a/servers/rendering/renderer_viewport.h b/servers/rendering/renderer_viewport.h index ffda9ad8f0..ac7a35f97d 100644 --- a/servers/rendering/renderer_viewport.h +++ b/servers/rendering/renderer_viewport.h @@ -34,6 +34,7 @@ #include "core/templates/local_vector.h" #include "core/templates/rid_owner.h" #include "core/templates/self_list.h" +#include "servers/rendering/renderer_scene.h" #include "servers/rendering_server.h" #include "servers/xr/xr_interface.h" @@ -68,9 +69,9 @@ public: Rect2 viewport_to_screen_rect; bool viewport_render_direct_to_screen; - bool hide_scenario; - bool hide_canvas; - bool disable_environment; + bool disable_2d = false; + bool disable_environment = false; + bool disable_3d = false; bool measure_render_time; bool snap_2d_transforms_to_pixel; @@ -92,7 +93,6 @@ public: uint64_t last_pass = 0; - int render_info[RS::VIEWPORT_RENDER_INFO_MAX]; RS::ViewportDebugDraw debug_draw; RS::ViewportClearMode clear_mode; @@ -133,11 +133,13 @@ public: Map<RID, CanvasData> canvas_map; + RendererScene::RenderInfo render_info; + Viewport() { update_mode = RS::VIEWPORT_UPDATE_WHEN_VISIBLE; clear_mode = RS::VIEWPORT_CLEAR_ALWAYS; transparent_bg = false; - disable_environment = false; + viewport_to_screen = DisplayServer::INVALID_WINDOW_ID; shadow_atlas_size = 0; measure_render_time = false; @@ -152,9 +154,6 @@ public: snap_2d_transforms_to_pixel = false; snap_2d_vertices_to_pixel = false; - for (int i = 0; i < RS::VIEWPORT_RENDER_INFO_MAX; i++) { - render_info[i] = 0; - } use_xr = false; sdf_active = false; @@ -172,7 +171,7 @@ public: uint64_t draw_viewports_pass = 0; - mutable RID_PtrOwner<Viewport, true> viewport_owner; + mutable RID_Owner<Viewport, true> viewport_owner; struct ViewportSort { _FORCE_INLINE_ bool operator()(const Viewport *p_left, const Viewport *p_right) const { @@ -188,6 +187,10 @@ public: Vector<Viewport *> active_viewports; + int total_objects_drawn = 0; + int total_vertices_drawn = 0; + int total_draw_calls_used = 0; + private: void _draw_3d(Viewport *p_viewport); void _draw_viewport(Viewport *p_viewport, uint32_t p_view_count = 1); @@ -217,9 +220,9 @@ public: RID viewport_get_texture(RID p_viewport) const; RID viewport_get_occluder_debug_texture(RID p_viewport) const; - void viewport_set_hide_scenario(RID p_viewport, bool p_hide); - void viewport_set_hide_canvas(RID p_viewport, bool p_hide); + void viewport_set_disable_2d(RID p_viewport, bool p_disable); void viewport_set_disable_environment(RID p_viewport, bool p_disable); + void viewport_set_disable_3d(RID p_viewport, bool p_disable); void viewport_attach_camera(RID p_viewport, RID p_camera); void viewport_set_scenario(RID p_viewport, RID p_scenario); @@ -242,7 +245,7 @@ public: void viewport_set_occlusion_culling_build_quality(RS::ViewportOcclusionCullingBuildQuality p_quality); void viewport_set_lod_threshold(RID p_viewport, float p_pixels); - virtual int viewport_get_render_info(RID p_viewport, RS::ViewportRenderInfo p_info); + virtual int viewport_get_render_info(RID p_viewport, RS::ViewportRenderInfoType p_type, RS::ViewportRenderInfo p_info); virtual void viewport_set_debug_draw(RID p_viewport, RS::ViewportDebugDraw p_draw); void viewport_set_measure_render_time(RID p_viewport, bool p_enable); @@ -264,8 +267,12 @@ public: bool free(RID p_rid); - //workaround for setting this on thread - void call_set_use_vsync(bool p_enable); + int get_total_objects_drawn() const; + int get_total_vertices_drawn() const; + int get_total_draw_calls_used() const; + + // Workaround for setting this on thread. + void call_set_vsync_mode(DisplayServer::VSyncMode p_mode, DisplayServer::WindowID p_window); RendererViewport(); virtual ~RendererViewport() {} diff --git a/servers/rendering/rendering_device.cpp b/servers/rendering/rendering_device.cpp index 056cec4c1f..3594939362 100644 --- a/servers/rendering/rendering_device.cpp +++ b/servers/rendering/rendering_device.cpp @@ -98,7 +98,7 @@ RID RenderingDevice::_texture_create_shared_from_slice(const Ref<RDTextureView> return texture_create_shared_from_slice(p_view->base, p_with_texture, p_layer, p_mipmap, p_slice_type); } -RenderingDevice::FramebufferFormatID RenderingDevice::_framebuffer_format_create(const TypedArray<RDAttachmentFormat> &p_attachments) { +RenderingDevice::FramebufferFormatID RenderingDevice::_framebuffer_format_create(const TypedArray<RDAttachmentFormat> &p_attachments, uint32_t p_view_count) { Vector<AttachmentFormat> attachments; attachments.resize(p_attachments.size()); @@ -107,12 +107,43 @@ RenderingDevice::FramebufferFormatID RenderingDevice::_framebuffer_format_create ERR_FAIL_COND_V(af.is_null(), INVALID_FORMAT_ID); attachments.write[i] = af->base; } - return framebuffer_format_create(attachments); + return framebuffer_format_create(attachments, p_view_count); } -RID RenderingDevice::_framebuffer_create(const Array &p_textures, FramebufferFormatID p_format_check) { +RenderingDevice::FramebufferFormatID RenderingDevice::_framebuffer_format_create_multipass(const TypedArray<RDAttachmentFormat> &p_attachments, const TypedArray<RDFramebufferPass> &p_passes, uint32_t p_view_count) { + Vector<AttachmentFormat> attachments; + attachments.resize(p_attachments.size()); + + for (int i = 0; i < p_attachments.size(); i++) { + Ref<RDAttachmentFormat> af = p_attachments[i]; + ERR_FAIL_COND_V(af.is_null(), INVALID_FORMAT_ID); + attachments.write[i] = af->base; + } + + Vector<FramebufferPass> passes; + for (int i = 0; i < p_passes.size(); i++) { + Ref<RDFramebufferPass> pass = p_passes[i]; + ERR_CONTINUE(pass.is_null()); + passes.push_back(pass->base); + } + + return framebuffer_format_create_multipass(attachments, passes, p_view_count); +} + +RID RenderingDevice::_framebuffer_create(const TypedArray<RID> &p_textures, FramebufferFormatID p_format_check, uint32_t p_view_count) { + Vector<RID> textures = Variant(p_textures); + return framebuffer_create(textures, p_format_check, p_view_count); +} + +RID RenderingDevice::_framebuffer_create_multipass(const TypedArray<RID> &p_textures, const TypedArray<RDFramebufferPass> &p_passes, FramebufferFormatID p_format_check, uint32_t p_view_count) { Vector<RID> textures = Variant(p_textures); - return framebuffer_create(textures, p_format_check); + Vector<FramebufferPass> passes; + for (int i = 0; i < p_passes.size(); i++) { + Ref<RDFramebufferPass> pass = p_passes[i]; + ERR_CONTINUE(pass.is_null()); + passes.push_back(pass->base); + } + return framebuffer_create_multipass(textures, passes, p_format_check, p_view_count); } RID RenderingDevice::_sampler_create(const Ref<RDSamplerState> &p_state) { @@ -143,7 +174,7 @@ Ref<RDShaderBytecode> RenderingDevice::_shader_compile_from_source(const Ref<RDS ERR_FAIL_COND_V(p_source.is_null(), Ref<RDShaderBytecode>()); Ref<RDShaderBytecode> bytecode; - bytecode.instance(); + bytecode.instantiate(); for (int i = 0; i < RD::SHADER_STAGE_MAX; i++) { String error; @@ -190,7 +221,36 @@ Error RenderingDevice::_buffer_update(RID p_buffer, uint32_t p_offset, uint32_t return buffer_update(p_buffer, p_offset, p_size, p_data.ptr(), p_post_barrier); } -RID RenderingDevice::_render_pipeline_create(RID p_shader, FramebufferFormatID p_framebuffer_format, VertexFormatID p_vertex_format, RenderPrimitive p_render_primitive, const Ref<RDPipelineRasterizationState> &p_rasterization_state, const Ref<RDPipelineMultisampleState> &p_multisample_state, const Ref<RDPipelineDepthStencilState> &p_depth_stencil_state, const Ref<RDPipelineColorBlendState> &p_blend_state, int p_dynamic_state_flags) { +static Vector<RenderingDevice::PipelineSpecializationConstant> _get_spec_constants(const TypedArray<RDPipelineSpecializationConstant> &p_constants) { + Vector<RenderingDevice::PipelineSpecializationConstant> ret; + ret.resize(p_constants.size()); + for (int i = 0; i < p_constants.size(); i++) { + Ref<RDPipelineSpecializationConstant> c = p_constants[i]; + ERR_CONTINUE(c.is_null()); + RenderingDevice::PipelineSpecializationConstant &sc = ret.write[i]; + Variant value = c->get_value(); + switch (value.get_type()) { + case Variant::BOOL: { + sc.type = RD::PIPELINE_SPECIALIZATION_CONSTANT_TYPE_BOOL; + sc.bool_value = value; + } break; + case Variant::INT: { + sc.type = RD::PIPELINE_SPECIALIZATION_CONSTANT_TYPE_INT; + sc.int_value = value; + } break; + case Variant::FLOAT: { + sc.type = RD::PIPELINE_SPECIALIZATION_CONSTANT_TYPE_FLOAT; + sc.float_value = value; + } break; + default: { + } + } + + sc.constant_id = c->get_constant_id(); + } + return ret; +} +RID RenderingDevice::_render_pipeline_create(RID p_shader, FramebufferFormatID p_framebuffer_format, VertexFormatID p_vertex_format, RenderPrimitive p_render_primitive, const Ref<RDPipelineRasterizationState> &p_rasterization_state, const Ref<RDPipelineMultisampleState> &p_multisample_state, const Ref<RDPipelineDepthStencilState> &p_depth_stencil_state, const Ref<RDPipelineColorBlendState> &p_blend_state, int p_dynamic_state_flags, uint32_t p_for_render_pass, const TypedArray<RDPipelineSpecializationConstant> &p_specialization_constants) { PipelineRasterizationState rasterization_state; if (p_rasterization_state.is_valid()) { rasterization_state = p_rasterization_state->base; @@ -221,7 +281,11 @@ RID RenderingDevice::_render_pipeline_create(RID p_shader, FramebufferFormatID p } } - return render_pipeline_create(p_shader, p_framebuffer_format, p_vertex_format, p_render_primitive, rasterization_state, multisample_state, depth_stencil_state, color_blend_state, p_dynamic_state_flags); + return render_pipeline_create(p_shader, p_framebuffer_format, p_vertex_format, p_render_primitive, rasterization_state, multisample_state, depth_stencil_state, color_blend_state, p_dynamic_state_flags, p_for_render_pass, _get_spec_constants(p_specialization_constants)); +} + +RID RenderingDevice::_compute_pipeline_create(RID p_shader, const TypedArray<RDPipelineSpecializationConstant> &p_specialization_constants = TypedArray<RDPipelineSpecializationConstant>()) { + return compute_pipeline_create(p_shader, _get_spec_constants(p_specialization_constants)); } Vector<int64_t> RenderingDevice::_draw_list_begin_split(RID p_framebuffer, uint32_t p_splits, InitialAction p_initial_color_action, FinalAction p_final_color_action, InitialAction p_initial_depth_action, FinalAction p_final_depth_action, const Vector<Color> &p_clear_color_values, float p_clear_depth, uint32_t p_clear_stencil, const Rect2 &p_region, const TypedArray<RID> &p_storage_textures) { @@ -242,6 +306,22 @@ Vector<int64_t> RenderingDevice::_draw_list_begin_split(RID p_framebuffer, uint3 return split_ids; } +Vector<int64_t> RenderingDevice::_draw_list_switch_to_next_pass_split(uint32_t p_splits) { + Vector<DrawListID> splits; + splits.resize(p_splits); + + Error err = draw_list_switch_to_next_pass_split(p_splits, splits.ptrw()); + ERR_FAIL_COND_V(err != OK, Vector<int64_t>()); + + Vector<int64_t> split_ids; + split_ids.resize(splits.size()); + for (int i = 0; i < splits.size(); i++) { + split_ids.write[i] = splits[i]; + } + + return split_ids; +} + void RenderingDevice::_draw_list_set_push_constant(DrawListID p_list, const Vector<uint8_t> &p_data, uint32_t p_data_size) { ERR_FAIL_COND((uint32_t)p_data.size() > p_data_size); draw_list_set_push_constant(p_list, p_data.ptr(), p_data_size); @@ -269,10 +349,12 @@ void RenderingDevice::_bind_methods() { ClassDB::bind_method(D_METHOD("texture_clear", "texture", "color", "base_mipmap", "mipmap_count", "base_layer", "layer_count", "post_barrier"), &RenderingDevice::texture_clear, DEFVAL(BARRIER_MASK_ALL)); ClassDB::bind_method(D_METHOD("texture_resolve_multisample", "from_texture", "to_texture", "post_barrier"), &RenderingDevice::texture_resolve_multisample, DEFVAL(BARRIER_MASK_ALL)); - ClassDB::bind_method(D_METHOD("framebuffer_format_create", "attachments"), &RenderingDevice::_framebuffer_format_create); + ClassDB::bind_method(D_METHOD("framebuffer_format_create", "attachments", "view_count"), &RenderingDevice::_framebuffer_format_create, DEFVAL(1)); + ClassDB::bind_method(D_METHOD("framebuffer_format_create_multipass", "attachments", "passes", "view_count"), &RenderingDevice::_framebuffer_format_create_multipass, DEFVAL(1)); ClassDB::bind_method(D_METHOD("framebuffer_format_create_empty", "samples"), &RenderingDevice::framebuffer_format_create_empty, DEFVAL(TEXTURE_SAMPLES_1)); - ClassDB::bind_method(D_METHOD("framebuffer_format_get_texture_samples", "format"), &RenderingDevice::framebuffer_format_get_texture_samples); - ClassDB::bind_method(D_METHOD("framebuffer_create", "textures", "validate_with_format"), &RenderingDevice::_framebuffer_create, DEFVAL(INVALID_FORMAT_ID)); + ClassDB::bind_method(D_METHOD("framebuffer_format_get_texture_samples", "format", "render_pass"), &RenderingDevice::framebuffer_format_get_texture_samples, DEFVAL(0)); + ClassDB::bind_method(D_METHOD("framebuffer_create", "textures", "validate_with_format", "view_count"), &RenderingDevice::_framebuffer_create, DEFVAL(INVALID_FORMAT_ID), DEFVAL(1)); + ClassDB::bind_method(D_METHOD("framebuffer_create_multipass", "textures", "passes", "validate_with_format", "view_count"), &RenderingDevice::_framebuffer_create_multipass, DEFVAL(INVALID_FORMAT_ID), DEFVAL(1)); ClassDB::bind_method(D_METHOD("framebuffer_create_empty", "size", "samples", "validate_with_format"), &RenderingDevice::framebuffer_create_empty, DEFVAL(TEXTURE_SAMPLES_1), DEFVAL(INVALID_FORMAT_ID)); ClassDB::bind_method(D_METHOD("framebuffer_get_format", "framebuffer"), &RenderingDevice::framebuffer_get_format); @@ -299,10 +381,10 @@ void RenderingDevice::_bind_methods() { ClassDB::bind_method(D_METHOD("buffer_clear", "buffer", "offset", "size_bytes", "post_barrier"), &RenderingDevice::buffer_clear, DEFVAL(BARRIER_MASK_ALL)); ClassDB::bind_method(D_METHOD("buffer_get_data", "buffer"), &RenderingDevice::buffer_get_data); - ClassDB::bind_method(D_METHOD("render_pipeline_create", "shader", "framebuffer_format", "vertex_format", "primitive", "rasterization_state", "multisample_state", "stencil_state", "color_blend_state", "dynamic_state_flags"), &RenderingDevice::_render_pipeline_create, DEFVAL(0)); + ClassDB::bind_method(D_METHOD("render_pipeline_create", "shader", "framebuffer_format", "vertex_format", "primitive", "rasterization_state", "multisample_state", "stencil_state", "color_blend_state", "dynamic_state_flags", "for_render_pass", "specialization_constants"), &RenderingDevice::_render_pipeline_create, DEFVAL(0), DEFVAL(0), DEFVAL(TypedArray<RDPipelineSpecializationConstant>())); ClassDB::bind_method(D_METHOD("render_pipeline_is_valid", "render_pipeline"), &RenderingDevice::render_pipeline_is_valid); - ClassDB::bind_method(D_METHOD("compute_pipeline_create", "shader"), &RenderingDevice::compute_pipeline_create); + ClassDB::bind_method(D_METHOD("compute_pipeline_create", "shader", "specialization_constants"), &RenderingDevice::_compute_pipeline_create, DEFVAL(TypedArray<RDPipelineSpecializationConstant>())); ClassDB::bind_method(D_METHOD("compute_pipeline_is_valid", "compute_pieline"), &RenderingDevice::compute_pipeline_is_valid); ClassDB::bind_method(D_METHOD("screen_get_width", "screen"), &RenderingDevice::screen_get_width, DEFVAL(DisplayServer::MAIN_WINDOW_ID)); @@ -325,6 +407,9 @@ void RenderingDevice::_bind_methods() { ClassDB::bind_method(D_METHOD("draw_list_enable_scissor", "draw_list", "rect"), &RenderingDevice::draw_list_enable_scissor, DEFVAL(Rect2i())); ClassDB::bind_method(D_METHOD("draw_list_disable_scissor", "draw_list"), &RenderingDevice::draw_list_disable_scissor); + ClassDB::bind_method(D_METHOD("draw_list_switch_to_next_pass"), &RenderingDevice::draw_list_switch_to_next_pass); + ClassDB::bind_method(D_METHOD("draw_list_switch_to_next_pass_split", "splits"), &RenderingDevice::_draw_list_switch_to_next_pass_split); + ClassDB::bind_method(D_METHOD("draw_list_end", "post_barrier"), &RenderingDevice::draw_list_end, DEFVAL(BARRIER_MASK_ALL)); ClassDB::bind_method(D_METHOD("compute_list_begin", "allow_draw_overlap"), &RenderingDevice::compute_list_begin, DEFVAL(false)); @@ -364,6 +449,8 @@ void RenderingDevice::_bind_methods() { ClassDB::bind_method(D_METHOD("get_device_name"), &RenderingDevice::get_device_name); ClassDB::bind_method(D_METHOD("get_device_pipeline_cache_uuid"), &RenderingDevice::get_device_pipeline_cache_uuid); + ClassDB::bind_method(D_METHOD("get_memory_usage"), &RenderingDevice::get_memory_usage); + BIND_CONSTANT(BARRIER_MASK_RASTER); BIND_CONSTANT(BARRIER_MASK_COMPUTE); BIND_CONSTANT(BARRIER_MASK_TRANSFER); @@ -799,6 +886,10 @@ void RenderingDevice::_bind_methods() { BIND_ENUM_CONSTANT(SHADER_LANGUAGE_GLSL); BIND_ENUM_CONSTANT(SHADER_LANGUAGE_HLSL); + BIND_ENUM_CONSTANT(PIPELINE_SPECIALIZATION_CONSTANT_TYPE_BOOL); + BIND_ENUM_CONSTANT(PIPELINE_SPECIALIZATION_CONSTANT_TYPE_INT); + BIND_ENUM_CONSTANT(PIPELINE_SPECIALIZATION_CONSTANT_TYPE_FLOAT); + BIND_ENUM_CONSTANT(LIMIT_MAX_BOUND_UNIFORM_SETS); BIND_ENUM_CONSTANT(LIMIT_MAX_FRAMEBUFFER_COLOR_ATTACHMENTS); BIND_ENUM_CONSTANT(LIMIT_MAX_TEXTURES_PER_UNIFORM_SET); @@ -835,6 +926,10 @@ void RenderingDevice::_bind_methods() { BIND_ENUM_CONSTANT(LIMIT_MAX_COMPUTE_WORKGROUP_SIZE_Y); BIND_ENUM_CONSTANT(LIMIT_MAX_COMPUTE_WORKGROUP_SIZE_Z); + BIND_ENUM_CONSTANT(MEMORY_TEXTURES); + BIND_ENUM_CONSTANT(MEMORY_BUFFERS); + BIND_ENUM_CONSTANT(MEMORY_TOTAL); + BIND_CONSTANT(INVALID_ID); BIND_CONSTANT(INVALID_FORMAT_ID); } diff --git a/servers/rendering/rendering_device.h b/servers/rendering/rendering_device.h index c13dc01dd7..9a154ef7e9 100644 --- a/servers/rendering/rendering_device.h +++ b/servers/rendering/rendering_device.h @@ -47,6 +47,8 @@ class RDPipelineRasterizationState; class RDPipelineMultisampleState; class RDPipelineDepthStencilState; class RDPipelineColorBlendState; +class RDFramebufferPass; +class RDPipelineSpecializationConstant; class RenderingDevice : public Object { GDCLASS(RenderingDevice, Object) @@ -517,10 +519,23 @@ public: // This ID is warranted to be unique for the same formats, does not need to be freed virtual FramebufferFormatID framebuffer_format_create(const Vector<AttachmentFormat> &p_format, uint32_t p_view_count = 1) = 0; + struct FramebufferPass { + enum { + ATTACHMENT_UNUSED = -1 + }; + Vector<int32_t> color_attachments; + Vector<int32_t> input_attachments; + Vector<int32_t> resolve_attachments; + Vector<int32_t> preserve_attachments; + int32_t depth_attachment = ATTACHMENT_UNUSED; + }; + + virtual FramebufferFormatID framebuffer_format_create_multipass(const Vector<AttachmentFormat> &p_attachments, Vector<FramebufferPass> &p_passes, uint32_t p_view_count = 1) = 0; virtual FramebufferFormatID framebuffer_format_create_empty(TextureSamples p_samples = TEXTURE_SAMPLES_1) = 0; - virtual TextureSamples framebuffer_format_get_texture_samples(FramebufferFormatID p_format) = 0; + virtual TextureSamples framebuffer_format_get_texture_samples(FramebufferFormatID p_format, uint32_t p_pass = 0) = 0; virtual RID framebuffer_create(const Vector<RID> &p_texture_attachments, FramebufferFormatID p_format_check = INVALID_ID, uint32_t p_view_count = 1) = 0; + virtual RID framebuffer_create_multipass(const Vector<RID> &p_texture_attachments, Vector<FramebufferPass> &p_passes, FramebufferFormatID p_format_check = INVALID_ID, uint32_t p_view_count = 1) = 0; virtual RID framebuffer_create_empty(const Size2i &p_size, TextureSamples p_samples = TEXTURE_SAMPLES_1, FramebufferFormatID p_format_check = INVALID_ID) = 0; virtual FramebufferFormatID framebuffer_get_format(RID p_framebuffer) = 0; @@ -701,11 +716,39 @@ public: virtual RID uniform_set_create(const Vector<Uniform> &p_uniforms, RID p_shader, uint32_t p_shader_set) = 0; virtual bool uniform_set_is_valid(RID p_uniform_set) = 0; + typedef void (*UniformSetInvalidatedCallback)(const RID &, void *); + virtual void uniform_set_set_invalidation_callback(RID p_uniform_set, UniformSetInvalidatedCallback p_callback, void *p_userdata) = 0; virtual Error buffer_update(RID p_buffer, uint32_t p_offset, uint32_t p_size, const void *p_data, uint32_t p_post_barrier = BARRIER_MASK_ALL) = 0; virtual Error buffer_clear(RID p_buffer, uint32_t p_offset, uint32_t p_size, uint32_t p_post_barrier = BARRIER_MASK_ALL) = 0; virtual Vector<uint8_t> buffer_get_data(RID p_buffer) = 0; //this causes stall, only use to retrieve large buffers for saving + /******************************************/ + /**** PIPELINE SPECIALIZATION CONSTANT ****/ + /******************************************/ + + enum PipelineSpecializationConstantType { + PIPELINE_SPECIALIZATION_CONSTANT_TYPE_BOOL, + PIPELINE_SPECIALIZATION_CONSTANT_TYPE_INT, + PIPELINE_SPECIALIZATION_CONSTANT_TYPE_FLOAT, + }; + + struct PipelineSpecializationConstant { + PipelineSpecializationConstantType type; + uint32_t constant_id; + union { + uint32_t int_value; + float float_value; + bool bool_value; + }; + + PipelineSpecializationConstant() { + type = PIPELINE_SPECIALIZATION_CONSTANT_TYPE_BOOL; + constant_id = 0; + int_value = 0; + } + }; + /*************************/ /**** RENDER PIPELINE ****/ /*************************/ @@ -962,13 +1005,13 @@ public: }; virtual bool render_pipeline_is_valid(RID p_pipeline) = 0; - virtual RID render_pipeline_create(RID p_shader, FramebufferFormatID p_framebuffer_format, VertexFormatID p_vertex_format, RenderPrimitive p_render_primitive, const PipelineRasterizationState &p_rasterization_state, const PipelineMultisampleState &p_multisample_state, const PipelineDepthStencilState &p_depth_stencil_state, const PipelineColorBlendState &p_blend_state, int p_dynamic_state_flags = 0) = 0; + virtual RID render_pipeline_create(RID p_shader, FramebufferFormatID p_framebuffer_format, VertexFormatID p_vertex_format, RenderPrimitive p_render_primitive, const PipelineRasterizationState &p_rasterization_state, const PipelineMultisampleState &p_multisample_state, const PipelineDepthStencilState &p_depth_stencil_state, const PipelineColorBlendState &p_blend_state, int p_dynamic_state_flags = 0, uint32_t p_for_render_pass = 0, const Vector<PipelineSpecializationConstant> &p_specialization_constants = Vector<PipelineSpecializationConstant>()) = 0; /**************************/ /**** COMPUTE PIPELINE ****/ /**************************/ - virtual RID compute_pipeline_create(RID p_shader) = 0; + virtual RID compute_pipeline_create(RID p_shader, const Vector<PipelineSpecializationConstant> &p_specialization_constants = Vector<PipelineSpecializationConstant>()) = 0; virtual bool compute_pipeline_is_valid(RID p_pipeline) = 0; /****************/ @@ -1018,6 +1061,9 @@ public: virtual void draw_list_enable_scissor(DrawListID p_list, const Rect2 &p_rect) = 0; virtual void draw_list_disable_scissor(DrawListID p_list) = 0; + virtual DrawListID draw_list_switch_to_next_pass() = 0; + virtual Error draw_list_switch_to_next_pass_split(uint32_t p_splits, DrawListID *r_split_ids) = 0; + virtual void draw_list_end(uint32_t p_post_barrier = BARRIER_MASK_ALL) = 0; /***********************/ @@ -1111,7 +1157,13 @@ public: virtual void submit() = 0; virtual void sync() = 0; - virtual uint64_t get_memory_usage() const = 0; + enum MemoryType { + MEMORY_TEXTURES, + MEMORY_BUFFERS, + MEMORY_TOTAL + }; + + virtual uint64_t get_memory_usage(MemoryType p_type) const = 0; virtual RenderingDevice *create_local_device() = 0; @@ -1134,8 +1186,10 @@ protected: RID _texture_create_shared(const Ref<RDTextureView> &p_view, RID p_with_texture); RID _texture_create_shared_from_slice(const Ref<RDTextureView> &p_view, RID p_with_texture, uint32_t p_layer, uint32_t p_mipmap, TextureSliceType p_slice_type = TEXTURE_SLICE_2D); - FramebufferFormatID _framebuffer_format_create(const TypedArray<RDAttachmentFormat> &p_attachments); - RID _framebuffer_create(const Array &p_textures, FramebufferFormatID p_format_check = INVALID_ID); + FramebufferFormatID _framebuffer_format_create(const TypedArray<RDAttachmentFormat> &p_attachments, uint32_t p_view_count); + FramebufferFormatID _framebuffer_format_create_multipass(const TypedArray<RDAttachmentFormat> &p_attachments, const TypedArray<RDFramebufferPass> &p_passes, uint32_t p_view_count); + RID _framebuffer_create(const TypedArray<RID> &p_textures, FramebufferFormatID p_format_check = INVALID_ID, uint32_t p_view_count = 1); + RID _framebuffer_create_multipass(const TypedArray<RID> &p_textures, const TypedArray<RDFramebufferPass> &p_passes, FramebufferFormatID p_format_check = INVALID_ID, uint32_t p_view_count = 1); RID _sampler_create(const Ref<RDSamplerState> &p_state); VertexFormatID _vertex_format_create(const TypedArray<RDVertexAttribute> &p_vertex_formats); RID _vertex_array_create(uint32_t p_vertex_count, VertexFormatID p_vertex_format, const TypedArray<RID> &p_src_buffers); @@ -1146,11 +1200,13 @@ protected: Error _buffer_update(RID p_buffer, uint32_t p_offset, uint32_t p_size, const Vector<uint8_t> &p_data, uint32_t p_post_barrier = BARRIER_MASK_ALL); - RID _render_pipeline_create(RID p_shader, FramebufferFormatID p_framebuffer_format, VertexFormatID p_vertex_format, RenderPrimitive p_render_primitive, const Ref<RDPipelineRasterizationState> &p_rasterization_state, const Ref<RDPipelineMultisampleState> &p_multisample_state, const Ref<RDPipelineDepthStencilState> &p_depth_stencil_state, const Ref<RDPipelineColorBlendState> &p_blend_state, int p_dynamic_state_flags = 0); + RID _render_pipeline_create(RID p_shader, FramebufferFormatID p_framebuffer_format, VertexFormatID p_vertex_format, RenderPrimitive p_render_primitive, const Ref<RDPipelineRasterizationState> &p_rasterization_state, const Ref<RDPipelineMultisampleState> &p_multisample_state, const Ref<RDPipelineDepthStencilState> &p_depth_stencil_state, const Ref<RDPipelineColorBlendState> &p_blend_state, int p_dynamic_state_flags, uint32_t p_for_render_pass, const TypedArray<RDPipelineSpecializationConstant> &p_specialization_constants); + RID _compute_pipeline_create(RID p_shader, const TypedArray<RDPipelineSpecializationConstant> &p_specialization_constants); Vector<int64_t> _draw_list_begin_split(RID p_framebuffer, uint32_t p_splits, InitialAction p_initial_color_action, FinalAction p_final_color_action, InitialAction p_initial_depth_action, FinalAction p_final_depth_action, const Vector<Color> &p_clear_color_values = Vector<Color>(), float p_clear_depth = 1.0, uint32_t p_clear_stencil = 0, const Rect2 &p_region = Rect2(), const TypedArray<RID> &p_storage_textures = TypedArray<RID>()); void _draw_list_set_push_constant(DrawListID p_list, const Vector<uint8_t> &p_data, uint32_t p_data_size); void _compute_list_set_push_constant(ComputeListID p_list, const Vector<uint8_t> &p_data, uint32_t p_data_size); + Vector<int64_t> _draw_list_switch_to_next_pass_split(uint32_t p_splits); }; VARIANT_ENUM_CAST(RenderingDevice::ShaderStage) @@ -1177,9 +1233,11 @@ VARIANT_ENUM_CAST(RenderingDevice::LogicOperation) VARIANT_ENUM_CAST(RenderingDevice::BlendFactor) VARIANT_ENUM_CAST(RenderingDevice::BlendOperation) VARIANT_ENUM_CAST(RenderingDevice::PipelineDynamicStateFlags) +VARIANT_ENUM_CAST(RenderingDevice::PipelineSpecializationConstantType) VARIANT_ENUM_CAST(RenderingDevice::InitialAction) VARIANT_ENUM_CAST(RenderingDevice::FinalAction) VARIANT_ENUM_CAST(RenderingDevice::Limit) +VARIANT_ENUM_CAST(RenderingDevice::MemoryType) typedef RenderingDevice RD; diff --git a/servers/rendering/rendering_device_binds.cpp b/servers/rendering/rendering_device_binds.cpp index 2f11360364..2652edb1bc 100644 --- a/servers/rendering/rendering_device_binds.cpp +++ b/servers/rendering/rendering_device_binds.cpp @@ -156,7 +156,7 @@ Error RDShaderFile::parse_versions_from_text(const String &p_text, const String } Ref<RDShaderFile> shader_file; - shader_file.instance(); + shader_file.instantiate(); if (base_error == "") { if (stage_found[RD::SHADER_STAGE_COMPUTE] && stages_found > 1) { @@ -173,7 +173,7 @@ Error RDShaderFile::parse_versions_from_text(const String &p_text, const String for (Map<StringName, String>::Element *E = version_texts.front(); E; E = E->next()) { Ref<RDShaderBytecode> bytecode; - bytecode.instance(); + bytecode.instantiate(); for (int i = 0; i < RD::SHADER_STAGE_MAX; i++) { String code = stage_code[i]; diff --git a/servers/rendering/rendering_device_binds.h b/servers/rendering/rendering_device_binds.h index 912674e309..1af427b356 100644 --- a/servers/rendering/rendering_device_binds.h +++ b/servers/rendering/rendering_device_binds.h @@ -128,6 +128,34 @@ protected: } }; +class RDFramebufferPass : public RefCounted { + GDCLASS(RDFramebufferPass, RefCounted) + friend class RenderingDevice; + + RD::FramebufferPass base; + +public: + RD_SETGET(PackedInt32Array, color_attachments) + RD_SETGET(PackedInt32Array, input_attachments) + RD_SETGET(PackedInt32Array, resolve_attachments) + RD_SETGET(PackedInt32Array, preserve_attachments) + RD_SETGET(int32_t, depth_attachment) +protected: + enum { + ATTACHMENT_UNUSED = -1 + }; + + static void _bind_methods() { + RD_BIND(Variant::PACKED_INT32_ARRAY, RDFramebufferPass, color_attachments); + RD_BIND(Variant::PACKED_INT32_ARRAY, RDFramebufferPass, input_attachments); + RD_BIND(Variant::PACKED_INT32_ARRAY, RDFramebufferPass, resolve_attachments); + RD_BIND(Variant::PACKED_INT32_ARRAY, RDFramebufferPass, preserve_attachments); + RD_BIND(Variant::INT, RDFramebufferPass, depth_attachment); + + BIND_CONSTANT(ATTACHMENT_UNUSED); + } +}; + class RDSamplerState : public RefCounted { GDCLASS(RDSamplerState, RefCounted) friend class RenderingDevice; @@ -424,6 +452,41 @@ protected: ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "_ids", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL), "_set_ids", "get_ids"); } }; + +class RDPipelineSpecializationConstant : public RefCounted { + GDCLASS(RDPipelineSpecializationConstant, RefCounted) + friend class RenderingDevice; + + Variant value = false; + uint32_t constant_id; + +public: + void set_value(const Variant &p_value) { + ERR_FAIL_COND(p_value.get_type() != Variant::BOOL && p_value.get_type() != Variant::INT && p_value.get_type() != Variant::FLOAT); + value = p_value; + } + Variant get_value() const { return value; } + + void set_constant_id(uint32_t p_id) { + constant_id = p_id; + } + uint32_t get_constant_id() const { + return constant_id; + } + +protected: + static void _bind_methods() { + ClassDB::bind_method(D_METHOD("set_value", "value"), &RDPipelineSpecializationConstant::set_value); + ClassDB::bind_method(D_METHOD("get_value"), &RDPipelineSpecializationConstant::get_value); + + ClassDB::bind_method(D_METHOD("set_constant_id", "constant_id"), &RDPipelineSpecializationConstant::set_constant_id); + ClassDB::bind_method(D_METHOD("get_constant_id"), &RDPipelineSpecializationConstant::get_constant_id); + + ADD_PROPERTY(PropertyInfo(Variant::NIL, "value", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NIL_IS_VARIANT), "set_value", "get_value"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "constant_id", PROPERTY_HINT_RANGE, "0,65535,0"), "set_constant_id", "get_constant_id"); + } +}; + class RDPipelineRasterizationState : public RefCounted { GDCLASS(RDPipelineRasterizationState, RefCounted) friend class RenderingDevice; diff --git a/servers/rendering/rendering_server_default.cpp b/servers/rendering/rendering_server_default.cpp index 629d212b69..e3ebebca86 100644 --- a/servers/rendering/rendering_server_default.cpp +++ b/servers/rendering/rendering_server_default.cpp @@ -42,26 +42,6 @@ int RenderingServerDefault::changes = 0; -/* BLACK BARS */ - -void RenderingServerDefault::black_bars_set_margins(int p_left, int p_top, int p_right, int p_bottom) { - black_margin[SIDE_LEFT] = p_left; - black_margin[SIDE_TOP] = p_top; - black_margin[SIDE_RIGHT] = p_right; - black_margin[SIDE_BOTTOM] = p_bottom; -} - -void RenderingServerDefault::black_bars_set_images(RID p_left, RID p_top, RID p_right, RID p_bottom) { - black_image[SIDE_LEFT] = p_left; - black_image[SIDE_TOP] = p_top; - black_image[SIDE_RIGHT] = p_right; - black_image[SIDE_BOTTOM] = p_bottom; -} - -void RenderingServerDefault::_draw_margins() { - RSG::canvas_render->draw_window_margins(black_margin, black_image); -}; - /* FREE */ void RenderingServerDefault::_free(RID p_rid) { @@ -114,7 +94,6 @@ void RenderingServerDefault::_draw(bool p_swap_buffers, double frame_step) { RSG::viewport->draw_viewports(); RSG::canvas_render->update(); - _draw_margins(); RSG::rasterizer->end_frame(p_swap_buffers); RSG::canvas->update_visibility_notifiers(); @@ -210,6 +189,8 @@ void RenderingServerDefault::_draw(bool p_swap_buffers, double frame_step) { print_frame_profile_frame_count = 0; } } + + RSG::storage->update_memory_info(); } float RenderingServerDefault::get_frame_setup_time_cpu() const { @@ -260,8 +241,15 @@ void RenderingServerDefault::finish() { /* STATUS INFORMATION */ -uint64_t RenderingServerDefault::get_render_info(RenderInfo p_info) { - return RSG::storage->get_render_info(p_info); +uint64_t RenderingServerDefault::get_rendering_info(RenderingInfo p_info) { + if (p_info == RENDERING_INFO_TOTAL_OBJECTS_IN_FRAME) { + return RSG::viewport->get_total_objects_drawn(); + } else if (p_info == RENDERING_INFO_TOTAL_PRIMITIVES_IN_FRAME) { + return RSG::viewport->get_total_vertices_drawn(); + } else if (p_info == RENDERING_INFO_TOTAL_DRAW_CALLS_IN_FRAME) { + return RSG::viewport->get_total_draw_calls_used(); + } + return RSG::storage->get_rendering_info(p_info); } String RenderingServerDefault::get_video_adapter_name() const { @@ -410,11 +398,6 @@ RenderingServerDefault::RenderingServerDefault(bool p_create_thread) : sr->set_scene_render(RSG::rasterizer->get_scene()); frame_profile_frame = 0; - - for (int i = 0; i < 4; i++) { - black_margin[i] = 0; - black_image[i] = RID(); - } } RenderingServerDefault::~RenderingServerDefault() { diff --git a/servers/rendering/rendering_server_default.h b/servers/rendering/rendering_server_default.h index 16e9f1fc77..79665dcdd2 100644 --- a/servers/rendering/rendering_server_default.h +++ b/servers/rendering/rendering_server_default.h @@ -58,9 +58,6 @@ class RenderingServerDefault : public RenderingServer { static int changes; RID test_cube; - int black_margin[4]; - RID black_image[4]; - struct FrameDrawnCallbacks { ObjectID object; StringName method; @@ -69,7 +66,6 @@ class RenderingServerDefault : public RenderingServer { List<FrameDrawnCallbacks> frame_drawn_callbacks; - void _draw_margins(); static void _changes_changed() {} uint64_t frame_profile_frame; @@ -192,8 +188,6 @@ public: FUNCRIDTEX6(texture_3d, Image::Format, int, int, int, bool, const Vector<Ref<Image>> &) FUNCRIDTEX1(texture_proxy, RID) - //goes pass-through - FUNC3(texture_2d_update_immediate, RID, const Ref<Image> &, int) //these go through command queue if they are in another thread FUNC3(texture_2d_update, RID, const Ref<Image> &, int) FUNC2(texture_3d_update, RID, const Vector<Ref<Image>> &) @@ -290,7 +284,9 @@ public: FUNC2(mesh_set_blend_shape_mode, RID, BlendShapeMode) FUNC1RC(BlendShapeMode, mesh_get_blend_shape_mode, RID) - FUNC4(mesh_surface_update_region, RID, int, int, const Vector<uint8_t> &) + FUNC4(mesh_surface_update_vertex_region, RID, int, int, const Vector<uint8_t> &) + FUNC4(mesh_surface_update_attribute_region, RID, int, int, const Vector<uint8_t> &) + FUNC4(mesh_surface_update_skin_region, RID, int, int, const Vector<uint8_t> &) FUNC3(mesh_surface_set_material, RID, int, RID) FUNC2RC(RID, mesh_surface_get_material, RID, int) @@ -333,21 +329,6 @@ public: FUNC2(multimesh_set_visible_instances, RID, int) FUNC1RC(int, multimesh_get_visible_instances, RID) - /* IMMEDIATE API */ - - FUNCRIDSPLIT(immediate) - FUNC3(immediate_begin, RID, PrimitiveType, RID) - FUNC2(immediate_vertex, RID, const Vector3 &) - FUNC2(immediate_normal, RID, const Vector3 &) - FUNC2(immediate_tangent, RID, const Plane &) - FUNC2(immediate_color, RID, const Color &) - FUNC2(immediate_uv, RID, const Vector2 &) - FUNC2(immediate_uv2, RID, const Vector2 &) - FUNC1(immediate_end, RID) - FUNC1(immediate_clear, RID) - FUNC2(immediate_set_material, RID, RID) - FUNC1RC(RID, immediate_get_material, RID) - /* SKELETON API */ FUNCRIDSPLIT(skeleton) @@ -381,7 +362,6 @@ public: FUNC2(light_directional_set_shadow_mode, RID, LightDirectionalShadowMode) FUNC2(light_directional_set_blend_splits, RID, bool) FUNC2(light_directional_set_sky_only, RID, bool) - FUNC2(light_directional_set_shadow_depth_range_mode, RID, LightDirectionalShadowDepthRangeMode) /* PROBE API */ @@ -431,34 +411,12 @@ public: FUNC1RC(Transform3D, voxel_gi_get_to_cell_xform, RID) FUNC2(voxel_gi_set_dynamic_range, RID, float) - FUNC1RC(float, voxel_gi_get_dynamic_range, RID) - FUNC2(voxel_gi_set_propagation, RID, float) - FUNC1RC(float, voxel_gi_get_propagation, RID) - FUNC2(voxel_gi_set_energy, RID, float) - FUNC1RC(float, voxel_gi_get_energy, RID) - - FUNC2(voxel_gi_set_ao, RID, float) - FUNC1RC(float, voxel_gi_get_ao, RID) - - FUNC2(voxel_gi_set_ao_size, RID, float) - FUNC1RC(float, voxel_gi_get_ao_size, RID) - FUNC2(voxel_gi_set_bias, RID, float) - FUNC1RC(float, voxel_gi_get_bias, RID) - FUNC2(voxel_gi_set_normal_bias, RID, float) - FUNC1RC(float, voxel_gi_get_normal_bias, RID) - FUNC2(voxel_gi_set_interior, RID, bool) - FUNC1RC(bool, voxel_gi_is_interior, RID) - FUNC2(voxel_gi_set_use_two_bounces, RID, bool) - FUNC1RC(bool, voxel_gi_is_using_two_bounces, RID) - - FUNC2(voxel_gi_set_anisotropy_strength, RID, float) - FUNC1RC(float, voxel_gi_get_anisotropy_strength, RID) /* LIGHTMAP */ @@ -582,9 +540,9 @@ public: FUNC1RC(RID, viewport_get_texture, RID) - FUNC2(viewport_set_hide_scenario, RID, bool) - FUNC2(viewport_set_hide_canvas, RID, bool) + FUNC2(viewport_set_disable_2d, RID, bool) FUNC2(viewport_set_disable_environment, RID, bool) + FUNC2(viewport_set_disable_3d, RID, bool) FUNC2(viewport_attach_camera, RID, RID) FUNC2(viewport_set_scenario, RID, RID) @@ -612,14 +570,14 @@ public: FUNC1(viewport_set_occlusion_culling_build_quality, ViewportOcclusionCullingBuildQuality) FUNC2(viewport_set_lod_threshold, RID, float) - FUNC2R(int, viewport_get_render_info, RID, ViewportRenderInfo) + FUNC3R(int, viewport_get_render_info, RID, ViewportRenderInfoType, ViewportRenderInfo) FUNC2(viewport_set_debug_draw, RID, ViewportDebugDraw) FUNC2(viewport_set_measure_render_time, RID, bool) FUNC1RC(float, viewport_get_measured_render_time_cpu, RID) FUNC1RC(float, viewport_get_measured_render_time_gpu, RID) - FUNC1(call_set_use_vsync, bool) + FUNC2(call_set_vsync_mode, DisplayServer::VSyncMode, DisplayServer::WindowID) /* ENVIRONMENT API */ @@ -709,7 +667,6 @@ public: FUNCRIDSPLIT(scenario) - FUNC2(scenario_set_debug, RID, ScenarioDebugMode) FUNC2(scenario_set_environment, RID, RID) FUNC2(scenario_set_camera_effects, RID, RID) FUNC2(scenario_set_fallback_environment, RID, RID) @@ -729,7 +686,6 @@ public: FUNC2(instance_set_custom_aabb, RID, AABB) FUNC2(instance_attach_skeleton, RID, RID) - FUNC2(instance_set_exterior, RID, bool) FUNC2(instance_set_extra_visibility_margin, RID, real_t) FUNC2(instance_set_visibility_parent, RID, RID) @@ -897,11 +853,6 @@ public: #undef WRITE_ACTION #undef SYNC_DEBUG - /* BLACK BARS */ - - virtual void black_bars_set_margins(int p_left, int p_top, int p_right, int p_bottom) override; - virtual void black_bars_set_images(RID p_left, RID p_top, RID p_right, RID p_bottom) override; - /* FREE */ virtual void free(RID p_rid) override { @@ -925,7 +876,7 @@ public: /* STATUS INFORMATION */ - virtual uint64_t get_render_info(RenderInfo p_info) override; + virtual uint64_t get_rendering_info(RenderingInfo p_info) override; virtual String get_video_adapter_name() const override; virtual String get_video_adapter_vendor() const override; diff --git a/servers/rendering/shader_types.cpp b/servers/rendering/shader_types.cpp index c4e7511374..376d23ccb3 100644 --- a/servers/rendering/shader_types.cpp +++ b/servers/rendering/shader_types.cpp @@ -122,7 +122,6 @@ ShaderTypes::ShaderTypes() { shader_modes[RS::SHADER_SPATIAL].functions["fragment"].built_ins["SSS_STRENGTH"] = ShaderLanguage::TYPE_FLOAT; shader_modes[RS::SHADER_SPATIAL].functions["fragment"].built_ins["SSS_TRANSMITTANCE_COLOR"] = ShaderLanguage::TYPE_VEC4; shader_modes[RS::SHADER_SPATIAL].functions["fragment"].built_ins["SSS_TRANSMITTANCE_DEPTH"] = ShaderLanguage::TYPE_FLOAT; - shader_modes[RS::SHADER_SPATIAL].functions["fragment"].built_ins["SSS_TRANSMITTANCE_CURVE"] = ShaderLanguage::TYPE_FLOAT; shader_modes[RS::SHADER_SPATIAL].functions["fragment"].built_ins["SSS_TRANSMITTANCE_BOOST"] = ShaderLanguage::TYPE_FLOAT; shader_modes[RS::SHADER_SPATIAL].functions["fragment"].built_ins["BACKLIGHT"] = ShaderLanguage::TYPE_VEC3; shader_modes[RS::SHADER_SPATIAL].functions["fragment"].built_ins["AO"] = ShaderLanguage::TYPE_FLOAT; diff --git a/servers/rendering_server.cpp b/servers/rendering_server.cpp index f25f255321..748b372c62 100644 --- a/servers/rendering_server.cpp +++ b/servers/rendering_server.cpp @@ -31,7 +31,7 @@ #include "rendering_server.h" #include "core/config/project_settings.h" - +#include "servers/rendering/rendering_server_globals.h" RenderingServer *RenderingServer::singleton = nullptr; RenderingServer *(*RenderingServer::create_func)() = nullptr; @@ -67,12 +67,6 @@ Array RenderingServer::_texture_debug_usage_bind() { return arr; } -Array RenderingServer::_shader_get_param_list_bind(RID p_shader) const { - List<PropertyInfo> l; - shader_get_param_list(p_shader, &l); - return convert_property_list(&l); -} - static Array to_array(const Vector<ObjectID> &ids) { Array a; a.resize(ids.size()); @@ -83,16 +77,25 @@ static Array to_array(const Vector<ObjectID> &ids) { } Array RenderingServer::_instances_cull_aabb_bind(const AABB &p_aabb, RID p_scenario) const { + if (RSG::threaded) { + WARN_PRINT_ONCE("Using this function with a threaded renderer hurts performance, as it causes a server stall."); + } Vector<ObjectID> ids = instances_cull_aabb(p_aabb, p_scenario); return to_array(ids); } Array RenderingServer::_instances_cull_ray_bind(const Vector3 &p_from, const Vector3 &p_to, RID p_scenario) const { + if (RSG::threaded) { + WARN_PRINT_ONCE("Using this function with a threaded renderer hurts performance, as it causes a server stall."); + } Vector<ObjectID> ids = instances_cull_ray(p_from, p_to, p_scenario); return to_array(ids); } Array RenderingServer::_instances_cull_convex_bind(const Array &p_convex, RID p_scenario) const { + if (RSG::threaded) { + WARN_PRINT_ONCE("Using this function with a threaded renderer hurts performance, as it causes a server stall."); + } Vector<Plane> planes; for (int i = 0; i < p_convex.size(); ++i) { Variant v = p_convex[i]; @@ -438,13 +441,14 @@ Error RenderingServer::_surface_set_data(Array p_arrays, uint32_t p_format, uint ERR_FAIL_COND_V(array.size() != p_vertex_array_len, ERR_INVALID_PARAMETER); const Color *src = array.ptr(); - uint16_t color16[4]; for (int i = 0; i < p_vertex_array_len; i++) { - color16[0] = Math::make_half_float(src[i].r); - color16[1] = Math::make_half_float(src[i].g); - color16[2] = Math::make_half_float(src[i].b); - color16[3] = Math::make_half_float(src[i].a); - memcpy(&aw[p_offsets[ai] + i * p_attrib_stride], color16, 8); + uint8_t color8[4] = { + uint8_t(CLAMP(src[i].r * 255.0, 0.0, 255.0)), + uint8_t(CLAMP(src[i].g * 255.0, 0.0, 255.0)), + uint8_t(CLAMP(src[i].b * 255.0, 0.0, 255.0)), + uint8_t(CLAMP(src[i].a * 255.0, 0.0, 255.0)) + }; + memcpy(&aw[p_offsets[ai] + i * p_attrib_stride], color8, 4); } } break; case RS::ARRAY_TEX_UV: { @@ -761,7 +765,7 @@ void RenderingServer::mesh_surface_make_offsets_from_format(uint32_t p_format, i elem_size = 4; } break; case RS::ARRAY_COLOR: { - elem_size = 8; + elem_size = 4; } break; case RS::ARRAY_TEX_UV: { elem_size = 8; @@ -1123,8 +1127,9 @@ Array RenderingServer::_get_array_from_surface(uint32_t p_format, Vector<uint8_t Color *w = arr.ptrw(); for (int32_t j = 0; j < p_vertex_len; j++) { - const uint16_t *v = (const uint16_t *)&ar[j * attrib_elem_size + offsets[i]]; - w[j] = Color(Math::half_to_float(v[0]), Math::half_to_float(v[1]), Math::half_to_float(v[2]), Math::half_to_float(v[3])); + const uint8_t *v = (const uint8_t *)&ar[j * attrib_elem_size + offsets[i]]; + + w[j] = Color(v[0] / 255.0, v[1] / 255.0, v[2] / 255.0, v[3] / 255.0); } ret[i] = arr; @@ -1441,29 +1446,247 @@ RenderingDevice *RenderingServer::create_local_rendering_device() const { return RenderingDevice::get_singleton()->create_local_device(); } +static Vector<Ref<Image>> _get_imgvec(const TypedArray<Image> &p_layers) { + Vector<Ref<Image>> images; + images.resize(p_layers.size()); + for (int i = 0; i < p_layers.size(); i++) { + images.write[i] = p_layers[i]; + } + return images; +} +RID RenderingServer::_texture_2d_layered_create(const TypedArray<Image> &p_layers, TextureLayeredType p_layered_type) { + return texture_2d_layered_create(_get_imgvec(p_layers), p_layered_type); +} +RID RenderingServer::_texture_3d_create(Image::Format p_format, int p_width, int p_height, int p_depth, bool p_mipmaps, const TypedArray<Image> &p_data) { + return texture_3d_create(p_format, p_width, p_height, p_depth, p_mipmaps, _get_imgvec(p_data)); +} + +void RenderingServer::_texture_3d_update(RID p_texture, const TypedArray<Image> &p_data) { + texture_3d_update(p_texture, _get_imgvec(p_data)); +} + +TypedArray<Image> RenderingServer::_texture_3d_get(RID p_texture) const { + Vector<Ref<Image>> images = texture_3d_get(p_texture); + TypedArray<Image> ret; + ret.resize(images.size()); + for (int i = 0; i < images.size(); i++) { + ret[i] = images[i]; + } + return ret; +} + +TypedArray<Dictionary> RenderingServer::_shader_get_param_list(RID p_shader) const { + List<PropertyInfo> l; + shader_get_param_list(p_shader, &l); + return convert_property_list(&l); +} + +static RS::SurfaceData _dict_to_surf(const Dictionary &p_dictionary) { + ERR_FAIL_COND_V(!p_dictionary.has("primitive"), RS::SurfaceData()); + ERR_FAIL_COND_V(!p_dictionary.has("format"), RS::SurfaceData()); + ERR_FAIL_COND_V(!p_dictionary.has("vertex_data"), RS::SurfaceData()); + ERR_FAIL_COND_V(!p_dictionary.has("vertex_count"), RS::SurfaceData()); + ERR_FAIL_COND_V(!p_dictionary.has("aabb"), RS::SurfaceData()); + + RS::SurfaceData sd; + + sd.primitive = RS::PrimitiveType(int(p_dictionary["primitive"])); + sd.format = p_dictionary["format"]; + sd.vertex_data = p_dictionary["vertex_data"]; + if (p_dictionary.has("attribute_data")) { + sd.attribute_data = p_dictionary["attribute_data"]; + } + if (p_dictionary.has("skin_data")) { + sd.skin_data = p_dictionary["skin_data"]; + } + + sd.vertex_count = p_dictionary["vertex_count"]; + + if (p_dictionary.has("index_data")) { + sd.index_data = p_dictionary["index_data"]; + ERR_FAIL_COND_V(!p_dictionary.has("index_count"), RS::SurfaceData()); + sd.index_count = p_dictionary["index_count"]; + } + + sd.aabb = p_dictionary["aabb"]; + + if (p_dictionary.has("lods")) { + Array lods = p_dictionary["lods"]; + for (int i = 0; i < lods.size(); i++) { + Dictionary lod = lods[i]; + ERR_CONTINUE(!lod.has("edge_length")); + ERR_CONTINUE(!lod.has("index_data")); + RS::SurfaceData::LOD l; + l.edge_length = lod["edge_length"]; + l.index_data = lod["index_data"]; + sd.lods.push_back(l); + } + } + + if (p_dictionary.has("bone_aabbs")) { + Array aabbs = p_dictionary["bone_aabbs"]; + for (int i = 0; i < aabbs.size(); i++) { + AABB aabb = aabbs[i]; + sd.bone_aabbs.push_back(aabb); + } + } + + if (p_dictionary.has("blend_shape_data")) { + sd.blend_shape_data = p_dictionary["blend_shape_data"]; + } + + if (p_dictionary.has("material")) { + sd.material = p_dictionary["material"]; + } + + return sd; +} +RID RenderingServer::_mesh_create_from_surfaces(const TypedArray<Dictionary> &p_surfaces, int p_blend_shape_count) { + Vector<RS::SurfaceData> surfaces; + for (int i = 0; i < p_surfaces.size(); i++) { + surfaces.push_back(_dict_to_surf(p_surfaces[i])); + } + return mesh_create_from_surfaces(surfaces); +} +void RenderingServer::_mesh_add_surface(RID p_mesh, const Dictionary &p_surface) { + mesh_add_surface(p_mesh, _dict_to_surf(p_surface)); +} +Dictionary RenderingServer::_mesh_get_surface(RID p_mesh, int p_idx) { + RS::SurfaceData sd = mesh_get_surface(p_mesh, p_idx); + + Dictionary d; + d["primitive"] = sd.primitive; + d["format"] = sd.format; + d["vertex_data"] = sd.vertex_data; + if (sd.attribute_data.size()) { + d["attribute_data"] = sd.attribute_data; + } + if (sd.skin_data.size()) { + d["skin_data"] = sd.skin_data; + } + d["vertex_count"] = sd.vertex_count; + if (sd.index_count) { + d["index_data"] = sd.index_data; + d["index_count"] = sd.index_count; + } + d["aabb"] = sd.aabb; + + if (sd.lods.size()) { + Array lods; + for (int i = 0; i < sd.lods.size(); i++) { + Dictionary ld; + ld["edge_length"] = sd.lods[i].edge_length; + ld["index_data"] = sd.lods[i].index_data; + lods.push_back(lods); + } + d["lods"] = lods; + } + + if (sd.bone_aabbs.size()) { + Array aabbs; + for (int i = 0; i < sd.bone_aabbs.size(); i++) { + aabbs.push_back(sd.bone_aabbs[i]); + } + d["bone_aabbs"] = aabbs; + } + + if (sd.blend_shape_data.size()) { + d["blend_shape_data"] = sd.blend_shape_data; + } + + if (sd.material.is_valid()) { + d["material"] = sd.material; + } + return d; +} + +Array RenderingServer::_instance_geometry_get_shader_parameter_list(RID p_instance) const { + List<PropertyInfo> params; + instance_geometry_get_shader_parameter_list(p_instance, ¶ms); + return convert_property_list(¶ms); +} + +TypedArray<Image> RenderingServer::_bake_render_uv2(RID p_base, const TypedArray<RID> &p_material_overrides, const Size2i &p_image_size) { + Vector<RID> mat_overrides; + for (int i = 0; i < p_material_overrides.size(); i++) { + mat_overrides.push_back(p_material_overrides[i]); + } + return bake_render_uv2(p_base, mat_overrides, p_image_size); +} + +void RenderingServer::_particles_set_trail_bind_poses(RID p_particles, const TypedArray<Transform3D> &p_bind_poses) { + Vector<Transform3D> tbposes; + tbposes.resize(p_bind_poses.size()); + for (int i = 0; i < p_bind_poses.size(); i++) { + tbposes.write[i] = p_bind_poses[i]; + } + particles_set_trail_bind_poses(p_particles, tbposes); +} + void RenderingServer::_bind_methods() { - ClassDB::bind_method(D_METHOD("force_sync"), &RenderingServer::sync); - ClassDB::bind_method(D_METHOD("force_draw", "swap_buffers", "frame_step"), &RenderingServer::draw, DEFVAL(true), DEFVAL(0.0)); - ClassDB::bind_method(D_METHOD("create_local_rendering_device"), &RenderingServer::create_local_rendering_device); + BIND_CONSTANT(NO_INDEX_ARRAY); + BIND_CONSTANT(ARRAY_WEIGHTS_SIZE); + BIND_CONSTANT(CANVAS_ITEM_Z_MIN); + BIND_CONSTANT(CANVAS_ITEM_Z_MAX); + BIND_CONSTANT(MAX_GLOW_LEVELS); + BIND_CONSTANT(MAX_CURSORS); + BIND_CONSTANT(MAX_2D_DIRECTIONAL_LIGHTS); -#ifndef _MSC_VER -#warning TODO all texture methods need re-binding -#endif + /* TEXTURE */ ClassDB::bind_method(D_METHOD("texture_2d_create", "image"), &RenderingServer::texture_2d_create); + ClassDB::bind_method(D_METHOD("texture_2d_layered_create", "layers", "layered_type"), &RenderingServer::_texture_2d_layered_create); + ClassDB::bind_method(D_METHOD("texture_3d_create", "format", "width", "height", "depth", "mipmaps", "data"), &RenderingServer::_texture_3d_create); + ClassDB::bind_method(D_METHOD("texture_proxy_create", "base"), &RenderingServer::texture_proxy_create); + + ClassDB::bind_method(D_METHOD("texture_2d_update", "texture", "image", "layer"), &RenderingServer::texture_2d_update); + ClassDB::bind_method(D_METHOD("texture_3d_update", "texture", "data"), &RenderingServer::_texture_3d_update); + ClassDB::bind_method(D_METHOD("texture_proxy_update", "texture", "proxy_to"), &RenderingServer::texture_proxy_update); + + ClassDB::bind_method(D_METHOD("texture_2d_placeholder_create"), &RenderingServer::texture_2d_placeholder_create); + ClassDB::bind_method(D_METHOD("texture_2d_layered_placeholder_create", "layered_type"), &RenderingServer::texture_2d_layered_placeholder_create); + ClassDB::bind_method(D_METHOD("texture_3d_placeholder_create"), &RenderingServer::texture_3d_placeholder_create); + ClassDB::bind_method(D_METHOD("texture_2d_get", "texture"), &RenderingServer::texture_2d_get); + ClassDB::bind_method(D_METHOD("texture_2d_layer_get", "texture", "layer"), &RenderingServer::texture_2d_layer_get); + ClassDB::bind_method(D_METHOD("texture_3d_get", "texture"), &RenderingServer::_texture_3d_get); + + ClassDB::bind_method(D_METHOD("texture_replace", "texture", "by_texture"), &RenderingServer::texture_replace); + ClassDB::bind_method(D_METHOD("texture_set_size_override", "texture", "width", "height"), &RenderingServer::texture_set_size_override); + + ClassDB::bind_method(D_METHOD("texture_set_path", "texture", "path"), &RenderingServer::texture_set_path); + ClassDB::bind_method(D_METHOD("texture_get_path", "texture"), &RenderingServer::texture_get_path); + + ClassDB::bind_method(D_METHOD("texture_set_force_redraw_if_visible", "texture", "enable"), &RenderingServer::texture_set_force_redraw_if_visible); + + BIND_ENUM_CONSTANT(TEXTURE_LAYERED_2D_ARRAY); + BIND_ENUM_CONSTANT(TEXTURE_LAYERED_CUBEMAP); + BIND_ENUM_CONSTANT(TEXTURE_LAYERED_CUBEMAP_ARRAY); + + BIND_ENUM_CONSTANT(CUBEMAP_LAYER_LEFT); + BIND_ENUM_CONSTANT(CUBEMAP_LAYER_RIGHT); + BIND_ENUM_CONSTANT(CUBEMAP_LAYER_BOTTOM); + BIND_ENUM_CONSTANT(CUBEMAP_LAYER_TOP); + BIND_ENUM_CONSTANT(CUBEMAP_LAYER_FRONT); + BIND_ENUM_CONSTANT(CUBEMAP_LAYER_BACK); + + /* SHADER */ -#ifndef _3D_DISABLED - ClassDB::bind_method(D_METHOD("sky_create"), &RenderingServer::sky_create); - ClassDB::bind_method(D_METHOD("sky_set_material", "sky", "material"), &RenderingServer::sky_set_material); -#endif ClassDB::bind_method(D_METHOD("shader_create"), &RenderingServer::shader_create); - ClassDB::bind_method(D_METHOD("shader_set_code", "shader", "code"), &RenderingServer::shader_set_code); ClassDB::bind_method(D_METHOD("shader_get_code", "shader"), &RenderingServer::shader_get_code); - ClassDB::bind_method(D_METHOD("shader_get_param_list", "shader"), &RenderingServer::_shader_get_param_list_bind); - ClassDB::bind_method(D_METHOD("shader_set_default_texture_param", "shader", "name", "texture"), &RenderingServer::shader_set_default_texture_param); - ClassDB::bind_method(D_METHOD("shader_get_default_texture_param", "shader", "name"), &RenderingServer::shader_get_default_texture_param); - ClassDB::bind_method(D_METHOD("shader_get_param_default", "material", "parameter"), &RenderingServer::shader_get_param_default); + ClassDB::bind_method(D_METHOD("shader_get_param_list", "shader"), &RenderingServer::_shader_get_param_list); + ClassDB::bind_method(D_METHOD("shader_get_param_default", "shader", "param"), &RenderingServer::shader_get_param_default); + + ClassDB::bind_method(D_METHOD("shader_set_default_texture_param", "shader", "param", "texture"), &RenderingServer::shader_set_default_texture_param); + ClassDB::bind_method(D_METHOD("shader_get_default_texture_param", "shader", "param"), &RenderingServer::shader_get_default_texture_param); + + BIND_ENUM_CONSTANT(SHADER_SPATIAL); + BIND_ENUM_CONSTANT(SHADER_CANVAS_ITEM); + BIND_ENUM_CONSTANT(SHADER_PARTICLES); + BIND_ENUM_CONSTANT(SHADER_SKY); + BIND_ENUM_CONSTANT(SHADER_MAX); + + /* MATERIAL */ ClassDB::bind_method(D_METHOD("material_create"), &RenderingServer::material_create); ClassDB::bind_method(D_METHOD("material_set_shader", "shader_material", "shader"), &RenderingServer::material_set_shader); @@ -1473,18 +1696,26 @@ void RenderingServer::_bind_methods() { ClassDB::bind_method(D_METHOD("material_set_next_pass", "material", "next_material"), &RenderingServer::material_set_next_pass); + BIND_CONSTANT(MATERIAL_RENDER_PRIORITY_MIN); + BIND_CONSTANT(MATERIAL_RENDER_PRIORITY_MAX); + + /* MESH API */ + + ClassDB::bind_method(D_METHOD("mesh_create_from_surfaces", "surfaces", "blend_shape_count"), &RenderingServer::_mesh_create_from_surfaces, DEFVAL(0)); ClassDB::bind_method(D_METHOD("mesh_create"), &RenderingServer::mesh_create); ClassDB::bind_method(D_METHOD("mesh_surface_get_format_offset", "format", "vertex_count", "array_index"), &RenderingServer::mesh_surface_get_format_offset); ClassDB::bind_method(D_METHOD("mesh_surface_get_format_vertex_stride", "format", "vertex_count"), &RenderingServer::mesh_surface_get_format_vertex_stride); ClassDB::bind_method(D_METHOD("mesh_surface_get_format_attribute_stride", "format", "vertex_count"), &RenderingServer::mesh_surface_get_format_attribute_stride); ClassDB::bind_method(D_METHOD("mesh_surface_get_format_skin_stride", "format", "vertex_count"), &RenderingServer::mesh_surface_get_format_skin_stride); - //ClassDB::bind_method(D_METHOD("mesh_add_surface_from_arrays", "mesh", "primitive", "arrays", "blend_shapes", "lods", "compress_format"), &RenderingServer::mesh_add_surface_from_arrays, DEFVAL(Array()), DEFVAL(Dictionary()), DEFVAL(ARRAY_COMPRESS_DEFAULT)); + ClassDB::bind_method(D_METHOD("mesh_add_surface", "mesh", "surface"), &RenderingServer::_mesh_add_surface); + ClassDB::bind_method(D_METHOD("mesh_add_surface_from_arrays", "mesh", "primitive", "arrays", "blend_shapes", "lods", "compress_format"), &RenderingServer::mesh_add_surface_from_arrays, DEFVAL(Array()), DEFVAL(Dictionary()), DEFVAL(0)); ClassDB::bind_method(D_METHOD("mesh_get_blend_shape_count", "mesh"), &RenderingServer::mesh_get_blend_shape_count); ClassDB::bind_method(D_METHOD("mesh_set_blend_shape_mode", "mesh", "mode"), &RenderingServer::mesh_set_blend_shape_mode); ClassDB::bind_method(D_METHOD("mesh_get_blend_shape_mode", "mesh"), &RenderingServer::mesh_get_blend_shape_mode); - ClassDB::bind_method(D_METHOD("mesh_surface_update_region", "mesh", "surface", "offset", "data"), &RenderingServer::mesh_surface_update_region); + ClassDB::bind_method(D_METHOD("mesh_surface_set_material", "mesh", "surface", "material"), &RenderingServer::mesh_surface_set_material); ClassDB::bind_method(D_METHOD("mesh_surface_get_material", "mesh", "surface"), &RenderingServer::mesh_surface_get_material); + ClassDB::bind_method(D_METHOD("mesh_get_surface", "mesh", "surface"), &RenderingServer::_mesh_get_surface); ClassDB::bind_method(D_METHOD("mesh_surface_get_arrays", "mesh", "surface"), &RenderingServer::mesh_surface_get_arrays); ClassDB::bind_method(D_METHOD("mesh_surface_get_blend_shape_arrays", "mesh", "surface"), &RenderingServer::mesh_surface_get_blend_shape_arrays); ClassDB::bind_method(D_METHOD("mesh_get_surface_count", "mesh"), &RenderingServer::mesh_get_surface_count); @@ -1492,6 +1723,81 @@ void RenderingServer::_bind_methods() { ClassDB::bind_method(D_METHOD("mesh_get_custom_aabb", "mesh"), &RenderingServer::mesh_get_custom_aabb); ClassDB::bind_method(D_METHOD("mesh_clear", "mesh"), &RenderingServer::mesh_clear); + ClassDB::bind_method(D_METHOD("mesh_surface_update_vertex_region", "mesh", "surface", "offset", "data"), &RenderingServer::mesh_surface_update_vertex_region); + ClassDB::bind_method(D_METHOD("mesh_surface_update_attribute_region", "mesh", "surface", "offset", "data"), &RenderingServer::mesh_surface_update_attribute_region); + ClassDB::bind_method(D_METHOD("mesh_surface_update_skin_region", "mesh", "surface", "offset", "data"), &RenderingServer::mesh_surface_update_skin_region); + + ClassDB::bind_method(D_METHOD("mesh_set_shadow_mesh", "mesh", "shadow_mesh"), &RenderingServer::mesh_set_shadow_mesh); + + BIND_ENUM_CONSTANT(ARRAY_VERTEX); + BIND_ENUM_CONSTANT(ARRAY_NORMAL); + BIND_ENUM_CONSTANT(ARRAY_TANGENT); + BIND_ENUM_CONSTANT(ARRAY_COLOR); + BIND_ENUM_CONSTANT(ARRAY_TEX_UV); + BIND_ENUM_CONSTANT(ARRAY_TEX_UV2); + BIND_ENUM_CONSTANT(ARRAY_CUSTOM0); + BIND_ENUM_CONSTANT(ARRAY_CUSTOM1); + BIND_ENUM_CONSTANT(ARRAY_CUSTOM2); + BIND_ENUM_CONSTANT(ARRAY_CUSTOM3); + BIND_ENUM_CONSTANT(ARRAY_BONES); + BIND_ENUM_CONSTANT(ARRAY_WEIGHTS); + BIND_ENUM_CONSTANT(ARRAY_INDEX); + BIND_ENUM_CONSTANT(ARRAY_MAX); + + BIND_CONSTANT(ARRAY_CUSTOM_COUNT); + + BIND_ENUM_CONSTANT(ARRAY_CUSTOM_RGBA8_UNORM); + BIND_ENUM_CONSTANT(ARRAY_CUSTOM_RGBA8_SNORM); + BIND_ENUM_CONSTANT(ARRAY_CUSTOM_RG_HALF); + BIND_ENUM_CONSTANT(ARRAY_CUSTOM_RGBA_HALF); + BIND_ENUM_CONSTANT(ARRAY_CUSTOM_R_FLOAT); + BIND_ENUM_CONSTANT(ARRAY_CUSTOM_RG_FLOAT); + BIND_ENUM_CONSTANT(ARRAY_CUSTOM_RGB_FLOAT); + BIND_ENUM_CONSTANT(ARRAY_CUSTOM_RGBA_FLOAT); + BIND_ENUM_CONSTANT(ARRAY_CUSTOM_MAX); + + BIND_ENUM_CONSTANT(ARRAY_FORMAT_VERTEX); + BIND_ENUM_CONSTANT(ARRAY_FORMAT_NORMAL); + BIND_ENUM_CONSTANT(ARRAY_FORMAT_TANGENT); + BIND_ENUM_CONSTANT(ARRAY_FORMAT_COLOR); + BIND_ENUM_CONSTANT(ARRAY_FORMAT_TEX_UV); + BIND_ENUM_CONSTANT(ARRAY_FORMAT_TEX_UV2); + BIND_ENUM_CONSTANT(ARRAY_FORMAT_CUSTOM0); + BIND_ENUM_CONSTANT(ARRAY_FORMAT_CUSTOM1); + BIND_ENUM_CONSTANT(ARRAY_FORMAT_CUSTOM2); + BIND_ENUM_CONSTANT(ARRAY_FORMAT_CUSTOM3); + BIND_ENUM_CONSTANT(ARRAY_FORMAT_BONES); + BIND_ENUM_CONSTANT(ARRAY_FORMAT_WEIGHTS); + BIND_ENUM_CONSTANT(ARRAY_FORMAT_INDEX); + + BIND_ENUM_CONSTANT(ARRAY_FORMAT_BLEND_SHAPE_MASK); + + BIND_ENUM_CONSTANT(ARRAY_FORMAT_CUSTOM_BASE); + BIND_ENUM_CONSTANT(ARRAY_FORMAT_CUSTOM_BITS); + BIND_ENUM_CONSTANT(ARRAY_FORMAT_CUSTOM0_SHIFT); + BIND_ENUM_CONSTANT(ARRAY_FORMAT_CUSTOM1_SHIFT); + BIND_ENUM_CONSTANT(ARRAY_FORMAT_CUSTOM2_SHIFT); + BIND_ENUM_CONSTANT(ARRAY_FORMAT_CUSTOM3_SHIFT); + + BIND_ENUM_CONSTANT(ARRAY_FORMAT_CUSTOM_MASK); + BIND_ENUM_CONSTANT(ARRAY_COMPRESS_FLAGS_BASE); + + BIND_ENUM_CONSTANT(ARRAY_FLAG_USE_2D_VERTICES); + BIND_ENUM_CONSTANT(ARRAY_FLAG_USE_DYNAMIC_UPDATE); + BIND_ENUM_CONSTANT(ARRAY_FLAG_USE_8_BONE_WEIGHTS); + + BIND_ENUM_CONSTANT(PRIMITIVE_POINTS); + BIND_ENUM_CONSTANT(PRIMITIVE_LINES); + BIND_ENUM_CONSTANT(PRIMITIVE_LINE_STRIP); + BIND_ENUM_CONSTANT(PRIMITIVE_TRIANGLES); + BIND_ENUM_CONSTANT(PRIMITIVE_TRIANGLE_STRIP); + BIND_ENUM_CONSTANT(PRIMITIVE_MAX); + + BIND_ENUM_CONSTANT(BLEND_SHAPE_MODE_NORMALIZED); + BIND_ENUM_CONSTANT(BLEND_SHAPE_MODE_RELATIVE); + + /* MULTIMESH API */ + ClassDB::bind_method(D_METHOD("multimesh_create"), &RenderingServer::multimesh_create); ClassDB::bind_method(D_METHOD("multimesh_allocate_data", "multimesh", "instances", "transform_format", "color_format", "custom_data_format"), &RenderingServer::multimesh_allocate_data, DEFVAL(false), DEFVAL(false)); ClassDB::bind_method(D_METHOD("multimesh_get_instance_count", "multimesh"), &RenderingServer::multimesh_get_instance_count); @@ -1510,21 +1816,11 @@ void RenderingServer::_bind_methods() { ClassDB::bind_method(D_METHOD("multimesh_get_visible_instances", "multimesh"), &RenderingServer::multimesh_get_visible_instances); ClassDB::bind_method(D_METHOD("multimesh_set_buffer", "multimesh", "buffer"), &RenderingServer::multimesh_set_buffer); ClassDB::bind_method(D_METHOD("multimesh_get_buffer", "multimesh"), &RenderingServer::multimesh_get_buffer); -#ifndef _3D_DISABLED - ClassDB::bind_method(D_METHOD("immediate_create"), &RenderingServer::immediate_create); - ClassDB::bind_method(D_METHOD("immediate_begin", "immediate", "primitive", "texture"), &RenderingServer::immediate_begin, DEFVAL(RID())); - ClassDB::bind_method(D_METHOD("immediate_vertex", "immediate", "vertex"), &RenderingServer::immediate_vertex); - ClassDB::bind_method(D_METHOD("immediate_vertex_2d", "immediate", "vertex"), &RenderingServer::immediate_vertex_2d); - ClassDB::bind_method(D_METHOD("immediate_normal", "immediate", "normal"), &RenderingServer::immediate_normal); - ClassDB::bind_method(D_METHOD("immediate_tangent", "immediate", "tangent"), &RenderingServer::immediate_tangent); - ClassDB::bind_method(D_METHOD("immediate_color", "immediate", "color"), &RenderingServer::immediate_color); - ClassDB::bind_method(D_METHOD("immediate_uv", "immediate", "tex_uv"), &RenderingServer::immediate_uv); - ClassDB::bind_method(D_METHOD("immediate_uv2", "immediate", "tex_uv"), &RenderingServer::immediate_uv2); - ClassDB::bind_method(D_METHOD("immediate_end", "immediate"), &RenderingServer::immediate_end); - ClassDB::bind_method(D_METHOD("immediate_clear", "immediate"), &RenderingServer::immediate_clear); - ClassDB::bind_method(D_METHOD("immediate_set_material", "immediate", "material"), &RenderingServer::immediate_set_material); - ClassDB::bind_method(D_METHOD("immediate_get_material", "immediate"), &RenderingServer::immediate_get_material); -#endif + + BIND_ENUM_CONSTANT(MULTIMESH_TRANSFORM_2D); + BIND_ENUM_CONSTANT(MULTIMESH_TRANSFORM_3D); + + /* SKELETON API */ ClassDB::bind_method(D_METHOD("skeleton_create"), &RenderingServer::skeleton_create); ClassDB::bind_method(D_METHOD("skeleton_allocate_data", "skeleton", "bones", "is_2d_skeleton"), &RenderingServer::skeleton_allocate_data, DEFVAL(false)); @@ -1533,8 +1829,10 @@ void RenderingServer::_bind_methods() { ClassDB::bind_method(D_METHOD("skeleton_bone_get_transform", "skeleton", "bone"), &RenderingServer::skeleton_bone_get_transform); ClassDB::bind_method(D_METHOD("skeleton_bone_set_transform_2d", "skeleton", "bone", "transform"), &RenderingServer::skeleton_bone_set_transform_2d); ClassDB::bind_method(D_METHOD("skeleton_bone_get_transform_2d", "skeleton", "bone"), &RenderingServer::skeleton_bone_get_transform_2d); + ClassDB::bind_method(D_METHOD("skeleton_set_base_transform_2d", "skeleton", "base_transform"), &RenderingServer::skeleton_set_base_transform_2d); + + /* Light API */ -#ifndef _3D_DISABLED ClassDB::bind_method(D_METHOD("directional_light_create"), &RenderingServer::directional_light_create); ClassDB::bind_method(D_METHOD("omni_light_create"), &RenderingServer::omni_light_create); ClassDB::bind_method(D_METHOD("spot_light_create"), &RenderingServer::spot_light_create); @@ -1548,13 +1846,62 @@ void RenderingServer::_bind_methods() { ClassDB::bind_method(D_METHOD("light_set_cull_mask", "light", "mask"), &RenderingServer::light_set_cull_mask); ClassDB::bind_method(D_METHOD("light_set_reverse_cull_face_mode", "light", "enabled"), &RenderingServer::light_set_reverse_cull_face_mode); ClassDB::bind_method(D_METHOD("light_set_bake_mode", "light", "bake_mode"), &RenderingServer::light_set_bake_mode); + ClassDB::bind_method(D_METHOD("light_set_max_sdfgi_cascade", "light", "cascade"), &RenderingServer::light_set_max_sdfgi_cascade); ClassDB::bind_method(D_METHOD("light_omni_set_shadow_mode", "light", "mode"), &RenderingServer::light_omni_set_shadow_mode); ClassDB::bind_method(D_METHOD("light_directional_set_shadow_mode", "light", "mode"), &RenderingServer::light_directional_set_shadow_mode); ClassDB::bind_method(D_METHOD("light_directional_set_blend_splits", "light", "enable"), &RenderingServer::light_directional_set_blend_splits); ClassDB::bind_method(D_METHOD("light_directional_set_sky_only", "light", "enable"), &RenderingServer::light_directional_set_sky_only); - ClassDB::bind_method(D_METHOD("light_directional_set_shadow_depth_range_mode", "light", "range_mode"), &RenderingServer::light_directional_set_shadow_depth_range_mode); + + BIND_ENUM_CONSTANT(LIGHT_DIRECTIONAL); + BIND_ENUM_CONSTANT(LIGHT_OMNI); + BIND_ENUM_CONSTANT(LIGHT_SPOT); + + BIND_ENUM_CONSTANT(LIGHT_PARAM_ENERGY); + BIND_ENUM_CONSTANT(LIGHT_PARAM_INDIRECT_ENERGY); + BIND_ENUM_CONSTANT(LIGHT_PARAM_SPECULAR); + BIND_ENUM_CONSTANT(LIGHT_PARAM_RANGE); + BIND_ENUM_CONSTANT(LIGHT_PARAM_SIZE); + BIND_ENUM_CONSTANT(LIGHT_PARAM_ATTENUATION); + BIND_ENUM_CONSTANT(LIGHT_PARAM_SPOT_ANGLE); + BIND_ENUM_CONSTANT(LIGHT_PARAM_SPOT_ATTENUATION); + BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_MAX_DISTANCE); + BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_SPLIT_1_OFFSET); + BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_SPLIT_2_OFFSET); + BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_SPLIT_3_OFFSET); + BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_FADE_START); + BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_NORMAL_BIAS); + BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_BIAS); + BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_PANCAKE_SIZE); + BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_BLUR); + BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_VOLUMETRIC_FOG_FADE); + BIND_ENUM_CONSTANT(LIGHT_PARAM_TRANSMITTANCE_BIAS); + BIND_ENUM_CONSTANT(LIGHT_PARAM_MAX); + + BIND_ENUM_CONSTANT(LIGHT_BAKE_DISABLED); + BIND_ENUM_CONSTANT(LIGHT_BAKE_DYNAMIC); + BIND_ENUM_CONSTANT(LIGHT_BAKE_STATIC); + + BIND_ENUM_CONSTANT(LIGHT_OMNI_SHADOW_DUAL_PARABOLOID); + BIND_ENUM_CONSTANT(LIGHT_OMNI_SHADOW_CUBE); + + BIND_ENUM_CONSTANT(LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL); + BIND_ENUM_CONSTANT(LIGHT_DIRECTIONAL_SHADOW_PARALLEL_2_SPLITS); + BIND_ENUM_CONSTANT(LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS); + + ClassDB::bind_method(D_METHOD("shadows_quality_set", "quality"), &RenderingServer::shadows_quality_set); + ClassDB::bind_method(D_METHOD("directional_shadow_quality_set", "quality"), &RenderingServer::directional_shadow_quality_set); + ClassDB::bind_method(D_METHOD("directional_shadow_atlas_set_size", "size", "is_16bits"), &RenderingServer::directional_shadow_atlas_set_size); + + BIND_ENUM_CONSTANT(SHADOW_QUALITY_HARD); + BIND_ENUM_CONSTANT(SHADOW_QUALITY_SOFT_LOW); + BIND_ENUM_CONSTANT(SHADOW_QUALITY_SOFT_MEDIUM); + BIND_ENUM_CONSTANT(SHADOW_QUALITY_SOFT_HIGH); + BIND_ENUM_CONSTANT(SHADOW_QUALITY_SOFT_ULTRA); + BIND_ENUM_CONSTANT(SHADOW_QUALITY_MAX); + + /* REFLECTION PROBE */ ClassDB::bind_method(D_METHOD("reflection_probe_create"), &RenderingServer::reflection_probe_create); ClassDB::bind_method(D_METHOD("reflection_probe_set_update_mode", "probe", "mode"), &RenderingServer::reflection_probe_set_update_mode); @@ -1569,54 +1916,77 @@ void RenderingServer::_bind_methods() { ClassDB::bind_method(D_METHOD("reflection_probe_set_enable_box_projection", "probe", "enable"), &RenderingServer::reflection_probe_set_enable_box_projection); ClassDB::bind_method(D_METHOD("reflection_probe_set_enable_shadows", "probe", "enable"), &RenderingServer::reflection_probe_set_enable_shadows); ClassDB::bind_method(D_METHOD("reflection_probe_set_cull_mask", "probe", "layers"), &RenderingServer::reflection_probe_set_cull_mask); + ClassDB::bind_method(D_METHOD("reflection_probe_set_resolution", "probe", "resolution"), &RenderingServer::reflection_probe_set_resolution); + ClassDB::bind_method(D_METHOD("reflection_probe_set_lod_threshold", "probe", "pixels"), &RenderingServer::reflection_probe_set_lod_threshold); -#ifndef _MSC_VER -#warning TODO all voxel_gi methods need re-binding -#endif -#if 0 - ClassDB::bind_method(D_METHOD("voxel_gi_create"), &RenderingServer::voxel_gi_create); - ClassDB::bind_method(D_METHOD("voxel_gi_set_bounds", "probe", "bounds"), &RenderingServer::voxel_gi_set_bounds); - ClassDB::bind_method(D_METHOD("voxel_gi_get_bounds", "probe"), &RenderingServer::voxel_gi_get_bounds); - ClassDB::bind_method(D_METHOD("voxel_gi_set_cell_size", "probe", "range"), &RenderingServer::voxel_gi_set_cell_size); - ClassDB::bind_method(D_METHOD("voxel_gi_get_cell_size", "probe"), &RenderingServer::voxel_gi_get_cell_size); - ClassDB::bind_method(D_METHOD("voxel_gi_set_to_cell_xform", "probe", "xform"), &RenderingServer::voxel_gi_set_to_cell_xform); - ClassDB::bind_method(D_METHOD("voxel_gi_get_to_cell_xform", "probe"), &RenderingServer::voxel_gi_get_to_cell_xform); - ClassDB::bind_method(D_METHOD("voxel_gi_set_dynamic_data", "probe", "data"), &RenderingServer::voxel_gi_set_dynamic_data); - ClassDB::bind_method(D_METHOD("voxel_gi_get_dynamic_data", "probe"), &RenderingServer::voxel_gi_get_dynamic_data); - ClassDB::bind_method(D_METHOD("voxel_gi_set_dynamic_range", "probe", "range"), &RenderingServer::voxel_gi_set_dynamic_range); - ClassDB::bind_method(D_METHOD("voxel_gi_get_dynamic_range", "probe"), &RenderingServer::voxel_gi_get_dynamic_range); - ClassDB::bind_method(D_METHOD("voxel_gi_set_energy", "probe", "energy"), &RenderingServer::voxel_gi_set_energy); - ClassDB::bind_method(D_METHOD("voxel_gi_get_energy", "probe"), &RenderingServer::voxel_gi_get_energy); - ClassDB::bind_method(D_METHOD("voxel_gi_set_bias", "probe", "bias"), &RenderingServer::voxel_gi_set_bias); - ClassDB::bind_method(D_METHOD("voxel_gi_get_bias", "probe"), &RenderingServer::voxel_gi_get_bias); - ClassDB::bind_method(D_METHOD("voxel_gi_set_normal_bias", "probe", "bias"), &RenderingServer::voxel_gi_set_normal_bias); - ClassDB::bind_method(D_METHOD("voxel_gi_get_normal_bias", "probe"), &RenderingServer::voxel_gi_get_normal_bias); - ClassDB::bind_method(D_METHOD("voxel_gi_set_propagation", "probe", "propagation"), &RenderingServer::voxel_gi_set_propagation); - ClassDB::bind_method(D_METHOD("voxel_gi_get_propagation", "probe"), &RenderingServer::voxel_gi_get_propagation); - ClassDB::bind_method(D_METHOD("voxel_gi_set_interior", "probe", "enable"), &RenderingServer::voxel_gi_set_interior); - ClassDB::bind_method(D_METHOD("voxel_gi_is_interior", "probe"), &RenderingServer::voxel_gi_is_interior); - ClassDB::bind_method(D_METHOD("voxel_gi_set_compress", "probe", "enable"), &RenderingServer::voxel_gi_set_compress); - ClassDB::bind_method(D_METHOD("voxel_gi_is_compressed", "probe"), &RenderingServer::voxel_gi_is_compressed); -#endif - /* - ClassDB::bind_method(D_METHOD("lightmap_create()"), &RenderingServer::lightmap_capture_create); - ClassDB::bind_method(D_METHOD("lightmap_capture_set_bounds", "capture", "bounds"), &RenderingServer::lightmap_capture_set_bounds); - ClassDB::bind_method(D_METHOD("lightmap_capture_get_bounds", "capture"), &RenderingServer::lightmap_capture_get_bounds); - ClassDB::bind_method(D_METHOD("lightmap_capture_set_octree", "capture", "octree"), &RenderingServer::lightmap_capture_set_octree); - ClassDB::bind_method(D_METHOD("lightmap_capture_set_octree_cell_transform", "capture", "xform"), &RenderingServer::lightmap_capture_set_octree_cell_transform); - ClassDB::bind_method(D_METHOD("lightmap_capture_get_octree_cell_transform", "capture"), &RenderingServer::lightmap_capture_get_octree_cell_transform); - ClassDB::bind_method(D_METHOD("lightmap_capture_set_octree_cell_subdiv", "capture", "subdiv"), &RenderingServer::lightmap_capture_set_octree_cell_subdiv); - ClassDB::bind_method(D_METHOD("lightmap_capture_get_octree_cell_subdiv", "capture"), &RenderingServer::lightmap_capture_get_octree_cell_subdiv); - ClassDB::bind_method(D_METHOD("lightmap_capture_get_octree", "capture"), &RenderingServer::lightmap_capture_get_octree); - ClassDB::bind_method(D_METHOD("lightmap_capture_set_energy", "capture", "energy"), &RenderingServer::lightmap_capture_set_energy); - ClassDB::bind_method(D_METHOD("lightmap_capture_get_energy", "capture"), &RenderingServer::lightmap_capture_get_energy); -*/ + BIND_ENUM_CONSTANT(REFLECTION_PROBE_UPDATE_ONCE); + BIND_ENUM_CONSTANT(REFLECTION_PROBE_UPDATE_ALWAYS); - ClassDB::bind_method(D_METHOD("occluder_create"), &RenderingServer::occluder_create); - ClassDB::bind_method(D_METHOD("occluder_set_mesh"), &RenderingServer::occluder_set_mesh); + BIND_ENUM_CONSTANT(REFLECTION_PROBE_AMBIENT_DISABLED); + BIND_ENUM_CONSTANT(REFLECTION_PROBE_AMBIENT_ENVIRONMENT); + BIND_ENUM_CONSTANT(REFLECTION_PROBE_AMBIENT_COLOR); + + /* DECAL */ + + ClassDB::bind_method(D_METHOD("decal_create"), &RenderingServer::decal_create); + ClassDB::bind_method(D_METHOD("decal_set_extents", "decal", "extents"), &RenderingServer::decal_set_extents); + ClassDB::bind_method(D_METHOD("decal_set_texture", "decal", "type", "texture"), &RenderingServer::decal_set_texture); + ClassDB::bind_method(D_METHOD("decal_set_emission_energy", "decal", "energy"), &RenderingServer::decal_set_emission_energy); + ClassDB::bind_method(D_METHOD("decal_set_albedo_mix", "decal", "albedo_mix"), &RenderingServer::decal_set_albedo_mix); + ClassDB::bind_method(D_METHOD("decal_set_modulate", "decal", "color"), &RenderingServer::decal_set_modulate); + ClassDB::bind_method(D_METHOD("decal_set_cull_mask", "decal", "mask"), &RenderingServer::decal_set_cull_mask); + ClassDB::bind_method(D_METHOD("decal_set_distance_fade", "decal", "enabled", "begin", "length"), &RenderingServer::decal_set_distance_fade); + ClassDB::bind_method(D_METHOD("decal_set_fade", "decal", "above", "below"), &RenderingServer::decal_set_fade); + ClassDB::bind_method(D_METHOD("decal_set_normal_fade", "decal", "fade"), &RenderingServer::decal_set_normal_fade); + + BIND_ENUM_CONSTANT(DECAL_TEXTURE_ALBEDO); + BIND_ENUM_CONSTANT(DECAL_TEXTURE_NORMAL); + BIND_ENUM_CONSTANT(DECAL_TEXTURE_ORM); + BIND_ENUM_CONSTANT(DECAL_TEXTURE_EMISSION); + BIND_ENUM_CONSTANT(DECAL_TEXTURE_MAX); + + /* VOXEL GI API */ + + ClassDB::bind_method(D_METHOD("voxel_gi_create"), &RenderingServer::voxel_gi_create); + ClassDB::bind_method(D_METHOD("voxel_gi_allocate_data", "voxel_gi", "to_cell_xform", "aabb", "octree_size", "octree_cells", "data_cells", "distance_field", "level_counts"), &RenderingServer::voxel_gi_allocate_data); + ClassDB::bind_method(D_METHOD("voxel_gi_get_octree_size", "voxel_gi"), &RenderingServer::voxel_gi_get_octree_size); + ClassDB::bind_method(D_METHOD("voxel_gi_get_octree_cells", "voxel_gi"), &RenderingServer::voxel_gi_get_octree_cells); + ClassDB::bind_method(D_METHOD("voxel_gi_get_data_cells", "voxel_gi"), &RenderingServer::voxel_gi_get_data_cells); + ClassDB::bind_method(D_METHOD("voxel_gi_get_distance_field", "voxel_gi"), &RenderingServer::voxel_gi_get_distance_field); + ClassDB::bind_method(D_METHOD("voxel_gi_get_level_counts", "voxel_gi"), &RenderingServer::voxel_gi_get_level_counts); + ClassDB::bind_method(D_METHOD("voxel_gi_get_to_cell_xform", "voxel_gi"), &RenderingServer::voxel_gi_get_to_cell_xform); + + ClassDB::bind_method(D_METHOD("voxel_gi_set_dynamic_range", "voxel_gi", "range"), &RenderingServer::voxel_gi_set_dynamic_range); + ClassDB::bind_method(D_METHOD("voxel_gi_set_propagation", "voxel_gi", "amount"), &RenderingServer::voxel_gi_set_propagation); + ClassDB::bind_method(D_METHOD("voxel_gi_set_energy", "voxel_gi", "energy"), &RenderingServer::voxel_gi_set_energy); + ClassDB::bind_method(D_METHOD("voxel_gi_set_bias", "voxel_gi", "bias"), &RenderingServer::voxel_gi_set_bias); + ClassDB::bind_method(D_METHOD("voxel_gi_set_normal_bias", "voxel_gi", "bias"), &RenderingServer::voxel_gi_set_normal_bias); + ClassDB::bind_method(D_METHOD("voxel_gi_set_interior", "voxel_gi", "enable"), &RenderingServer::voxel_gi_set_interior); + ClassDB::bind_method(D_METHOD("voxel_gi_set_use_two_bounces", "voxel_gi", "enable"), &RenderingServer::voxel_gi_set_use_two_bounces); + + ClassDB::bind_method(D_METHOD("voxel_gi_set_quality", "quality"), &RenderingServer::voxel_gi_set_quality); + + BIND_ENUM_CONSTANT(VOXEL_GI_QUALITY_LOW); + BIND_ENUM_CONSTANT(VOXEL_GI_QUALITY_HIGH); + + /* LIGHTMAP */ + + ClassDB::bind_method(D_METHOD("lightmap_create"), &RenderingServer::lightmap_create); + ClassDB::bind_method(D_METHOD("lightmap_set_textures", "lightmap", "light", "uses_sh"), &RenderingServer::lightmap_set_textures); + ClassDB::bind_method(D_METHOD("lightmap_set_probe_bounds", "lightmap", "bounds"), &RenderingServer::lightmap_set_probe_bounds); + ClassDB::bind_method(D_METHOD("lightmap_set_probe_interior", "lightmap", "interior"), &RenderingServer::lightmap_set_probe_interior); + ClassDB::bind_method(D_METHOD("lightmap_set_probe_capture_data", "lightmap", "points", "point_sh", "tetrahedra", "bsp_tree"), &RenderingServer::lightmap_set_probe_capture_data); + ClassDB::bind_method(D_METHOD("lightmap_get_probe_capture_points", "lightmap"), &RenderingServer::lightmap_get_probe_capture_points); + ClassDB::bind_method(D_METHOD("lightmap_get_probe_capture_sh", "lightmap"), &RenderingServer::lightmap_get_probe_capture_sh); + ClassDB::bind_method(D_METHOD("lightmap_get_probe_capture_tetrahedra", "lightmap"), &RenderingServer::lightmap_get_probe_capture_tetrahedra); + ClassDB::bind_method(D_METHOD("lightmap_get_probe_capture_bsp_tree", "lightmap"), &RenderingServer::lightmap_get_probe_capture_bsp_tree); + + ClassDB::bind_method(D_METHOD("lightmap_set_probe_capture_update_speed", "speed"), &RenderingServer::lightmap_set_probe_capture_update_speed); + + /* PARTICLES API */ -#endif ClassDB::bind_method(D_METHOD("particles_create"), &RenderingServer::particles_create); + ClassDB::bind_method(D_METHOD("particles_set_mode", "particles", "mode"), &RenderingServer::particles_set_mode); ClassDB::bind_method(D_METHOD("particles_set_emitting", "particles", "emitting"), &RenderingServer::particles_set_emitting); ClassDB::bind_method(D_METHOD("particles_get_emitting", "particles"), &RenderingServer::particles_get_emitting); ClassDB::bind_method(D_METHOD("particles_set_amount", "particles", "amount"), &RenderingServer::particles_set_amount); @@ -1630,16 +2000,89 @@ void RenderingServer::_bind_methods() { ClassDB::bind_method(D_METHOD("particles_set_use_local_coordinates", "particles", "enable"), &RenderingServer::particles_set_use_local_coordinates); ClassDB::bind_method(D_METHOD("particles_set_process_material", "particles", "material"), &RenderingServer::particles_set_process_material); ClassDB::bind_method(D_METHOD("particles_set_fixed_fps", "particles", "fps"), &RenderingServer::particles_set_fixed_fps); + ClassDB::bind_method(D_METHOD("particles_set_interpolate", "particles", "enable"), &RenderingServer::particles_set_interpolate); ClassDB::bind_method(D_METHOD("particles_set_fractional_delta", "particles", "enable"), &RenderingServer::particles_set_fractional_delta); + ClassDB::bind_method(D_METHOD("particles_set_collision_base_size", "particles", "size"), &RenderingServer::particles_set_collision_base_size); + ClassDB::bind_method(D_METHOD("particles_set_transform_align", "particles", "align"), &RenderingServer::particles_set_transform_align); + ClassDB::bind_method(D_METHOD("particles_set_trails", "particles", "enable", "length_sec"), &RenderingServer::particles_set_trails); + ClassDB::bind_method(D_METHOD("particles_set_trail_bind_poses", "particles", "bind_poses"), &RenderingServer::_particles_set_trail_bind_poses); + ClassDB::bind_method(D_METHOD("particles_is_inactive", "particles"), &RenderingServer::particles_is_inactive); ClassDB::bind_method(D_METHOD("particles_request_process", "particles"), &RenderingServer::particles_request_process); ClassDB::bind_method(D_METHOD("particles_restart", "particles"), &RenderingServer::particles_restart); + + ClassDB::bind_method(D_METHOD("particles_set_subemitter", "particles", "subemitter_particles"), &RenderingServer::particles_set_subemitter); + ClassDB::bind_method(D_METHOD("particles_emit", "particles", "transform", "velocity", "color", "custom", "emit_flags"), &RenderingServer::particles_emit); + ClassDB::bind_method(D_METHOD("particles_set_draw_order", "particles", "order"), &RenderingServer::particles_set_draw_order); ClassDB::bind_method(D_METHOD("particles_set_draw_passes", "particles", "count"), &RenderingServer::particles_set_draw_passes); ClassDB::bind_method(D_METHOD("particles_set_draw_pass_mesh", "particles", "pass", "mesh"), &RenderingServer::particles_set_draw_pass_mesh); ClassDB::bind_method(D_METHOD("particles_get_current_aabb", "particles"), &RenderingServer::particles_get_current_aabb); ClassDB::bind_method(D_METHOD("particles_set_emission_transform", "particles", "transform"), &RenderingServer::particles_set_emission_transform); + BIND_ENUM_CONSTANT(PARTICLES_MODE_2D); + BIND_ENUM_CONSTANT(PARTICLES_MODE_3D); + + BIND_ENUM_CONSTANT(PARTICLES_TRANSFORM_ALIGN_DISABLED); + BIND_ENUM_CONSTANT(PARTICLES_TRANSFORM_ALIGN_Z_BILLBOARD); + BIND_ENUM_CONSTANT(PARTICLES_TRANSFORM_ALIGN_Y_TO_VELOCITY); + BIND_ENUM_CONSTANT(PARTICLES_TRANSFORM_ALIGN_Z_BILLBOARD_Y_TO_VELOCITY); + + BIND_CONSTANT(PARTICLES_EMIT_FLAG_POSITION); + BIND_CONSTANT(PARTICLES_EMIT_FLAG_ROTATION_SCALE); + BIND_CONSTANT(PARTICLES_EMIT_FLAG_VELOCITY); + BIND_CONSTANT(PARTICLES_EMIT_FLAG_COLOR); + BIND_CONSTANT(PARTICLES_EMIT_FLAG_CUSTOM); + + BIND_ENUM_CONSTANT(PARTICLES_DRAW_ORDER_INDEX); + BIND_ENUM_CONSTANT(PARTICLES_DRAW_ORDER_LIFETIME); + BIND_ENUM_CONSTANT(PARTICLES_DRAW_ORDER_REVERSE_LIFETIME); + BIND_ENUM_CONSTANT(PARTICLES_DRAW_ORDER_VIEW_DEPTH); + + /* PARTICLES COLLISION */ + + ClassDB::bind_method(D_METHOD("particles_collision_create"), &RenderingServer::particles_collision_create); + ClassDB::bind_method(D_METHOD("particles_collision_set_collision_type", "particles_collision", "type"), &RenderingServer::particles_collision_set_collision_type); + ClassDB::bind_method(D_METHOD("particles_collision_set_cull_mask", "particles_collision", "mask"), &RenderingServer::particles_collision_set_cull_mask); + ClassDB::bind_method(D_METHOD("particles_collision_set_sphere_radius", "particles_collision", "radius"), &RenderingServer::particles_collision_set_sphere_radius); + ClassDB::bind_method(D_METHOD("particles_collision_set_box_extents", "particles_collision", "extents"), &RenderingServer::particles_collision_set_box_extents); + ClassDB::bind_method(D_METHOD("particles_collision_set_attractor_strength", "particles_collision", "setrngth"), &RenderingServer::particles_collision_set_attractor_strength); + ClassDB::bind_method(D_METHOD("particles_collision_set_attractor_directionality", "particles_collision", "amount"), &RenderingServer::particles_collision_set_attractor_directionality); + ClassDB::bind_method(D_METHOD("particles_collision_set_attractor_attenuation", "particles_collision", "curve"), &RenderingServer::particles_collision_set_attractor_attenuation); + ClassDB::bind_method(D_METHOD("particles_collision_set_field_texture", "particles_collision", "texture"), &RenderingServer::particles_collision_set_field_texture); + + ClassDB::bind_method(D_METHOD("particles_collision_height_field_update", "particles_collision"), &RenderingServer::particles_collision_height_field_update); + ClassDB::bind_method(D_METHOD("particles_collision_set_height_field_resolution", "particles_collision", "resolution"), &RenderingServer::particles_collision_set_height_field_resolution); + + BIND_ENUM_CONSTANT(PARTICLES_COLLISION_TYPE_SPHERE_ATTRACT); + BIND_ENUM_CONSTANT(PARTICLES_COLLISION_TYPE_BOX_ATTRACT); + BIND_ENUM_CONSTANT(PARTICLES_COLLISION_TYPE_VECTOR_FIELD_ATTRACT); + BIND_ENUM_CONSTANT(PARTICLES_COLLISION_TYPE_SPHERE_COLLIDE); + BIND_ENUM_CONSTANT(PARTICLES_COLLISION_TYPE_BOX_COLLIDE); + BIND_ENUM_CONSTANT(PARTICLES_COLLISION_TYPE_SDF_COLLIDE); + BIND_ENUM_CONSTANT(PARTICLES_COLLISION_TYPE_HEIGHTFIELD_COLLIDE); + + BIND_ENUM_CONSTANT(PARTICLES_COLLISION_HEIGHTFIELD_RESOLUTION_256); + BIND_ENUM_CONSTANT(PARTICLES_COLLISION_HEIGHTFIELD_RESOLUTION_512); + BIND_ENUM_CONSTANT(PARTICLES_COLLISION_HEIGHTFIELD_RESOLUTION_1024); + BIND_ENUM_CONSTANT(PARTICLES_COLLISION_HEIGHTFIELD_RESOLUTION_2048); + BIND_ENUM_CONSTANT(PARTICLES_COLLISION_HEIGHTFIELD_RESOLUTION_4096); + BIND_ENUM_CONSTANT(PARTICLES_COLLISION_HEIGHTFIELD_RESOLUTION_8192); + BIND_ENUM_CONSTANT(PARTICLES_COLLISION_HEIGHTFIELD_RESOLUTION_MAX); + + /* VISIBILITY NOTIFIER */ + + ClassDB::bind_method(D_METHOD("visibility_notifier_create"), &RenderingServer::visibility_notifier_create); + ClassDB::bind_method(D_METHOD("visibility_notifier_set_aabb", "notifier", "aabb"), &RenderingServer::visibility_notifier_set_aabb); + ClassDB::bind_method(D_METHOD("visibility_notifier_set_callbacks", "notifier", "enter_callable", "exit_callable"), &RenderingServer::visibility_notifier_set_callbacks); + + /* OCCLUDER */ + + ClassDB::bind_method(D_METHOD("occluder_create"), &RenderingServer::occluder_create); + ClassDB::bind_method(D_METHOD("occluder_set_mesh", "occluder", "vertices", "indices"), &RenderingServer::occluder_set_mesh); + + /* CAMERA */ + ClassDB::bind_method(D_METHOD("camera_create"), &RenderingServer::camera_create); ClassDB::bind_method(D_METHOD("camera_set_perspective", "camera", "fovy_degrees", "z_near", "z_far"), &RenderingServer::camera_set_perspective); ClassDB::bind_method(D_METHOD("camera_set_orthogonal", "camera", "size", "z_near", "z_far"), &RenderingServer::camera_set_orthogonal); @@ -1647,8 +2090,11 @@ void RenderingServer::_bind_methods() { ClassDB::bind_method(D_METHOD("camera_set_transform", "camera", "transform"), &RenderingServer::camera_set_transform); ClassDB::bind_method(D_METHOD("camera_set_cull_mask", "camera", "layers"), &RenderingServer::camera_set_cull_mask); ClassDB::bind_method(D_METHOD("camera_set_environment", "camera", "env"), &RenderingServer::camera_set_environment); + ClassDB::bind_method(D_METHOD("camera_set_camera_effects", "camera", "effects"), &RenderingServer::camera_set_camera_effects); ClassDB::bind_method(D_METHOD("camera_set_use_vertical_aspect", "camera", "enable"), &RenderingServer::camera_set_use_vertical_aspect); + /* VIEWPORT */ + ClassDB::bind_method(D_METHOD("viewport_create"), &RenderingServer::viewport_create); ClassDB::bind_method(D_METHOD("viewport_set_use_xr", "viewport", "use_xr"), &RenderingServer::viewport_set_use_xr); ClassDB::bind_method(D_METHOD("viewport_set_size", "viewport", "width", "height"), &RenderingServer::viewport_set_size); @@ -1660,338 +2106,47 @@ void RenderingServer::_bind_methods() { ClassDB::bind_method(D_METHOD("viewport_set_update_mode", "viewport", "update_mode"), &RenderingServer::viewport_set_update_mode); ClassDB::bind_method(D_METHOD("viewport_set_clear_mode", "viewport", "clear_mode"), &RenderingServer::viewport_set_clear_mode); ClassDB::bind_method(D_METHOD("viewport_get_texture", "viewport"), &RenderingServer::viewport_get_texture); - ClassDB::bind_method(D_METHOD("viewport_set_hide_scenario", "viewport", "hidden"), &RenderingServer::viewport_set_hide_scenario); - ClassDB::bind_method(D_METHOD("viewport_set_hide_canvas", "viewport", "hidden"), &RenderingServer::viewport_set_hide_canvas); + ClassDB::bind_method(D_METHOD("viewport_set_disable_3d", "viewport", "disable"), &RenderingServer::viewport_set_disable_3d); + ClassDB::bind_method(D_METHOD("viewport_set_disable_2d", "viewport", "disable"), &RenderingServer::viewport_set_disable_2d); ClassDB::bind_method(D_METHOD("viewport_set_disable_environment", "viewport", "disabled"), &RenderingServer::viewport_set_disable_environment); ClassDB::bind_method(D_METHOD("viewport_attach_camera", "viewport", "camera"), &RenderingServer::viewport_attach_camera); ClassDB::bind_method(D_METHOD("viewport_set_scenario", "viewport", "scenario"), &RenderingServer::viewport_set_scenario); ClassDB::bind_method(D_METHOD("viewport_attach_canvas", "viewport", "canvas"), &RenderingServer::viewport_attach_canvas); ClassDB::bind_method(D_METHOD("viewport_remove_canvas", "viewport", "canvas"), &RenderingServer::viewport_remove_canvas); + ClassDB::bind_method(D_METHOD("viewport_set_snap_2d_transforms_to_pixel", "viewport", "enabled"), &RenderingServer::viewport_set_snap_2d_transforms_to_pixel); + ClassDB::bind_method(D_METHOD("viewport_set_snap_2d_vertices_to_pixel", "viewport", "enabled"), &RenderingServer::viewport_set_snap_2d_vertices_to_pixel); + + ClassDB::bind_method(D_METHOD("viewport_set_default_canvas_item_texture_filter", "viewport", "filter"), &RenderingServer::viewport_set_default_canvas_item_texture_filter); + ClassDB::bind_method(D_METHOD("viewport_set_default_canvas_item_texture_repeat", "viewport", "repeat"), &RenderingServer::viewport_set_default_canvas_item_texture_repeat); + ClassDB::bind_method(D_METHOD("viewport_set_canvas_transform", "viewport", "canvas", "offset"), &RenderingServer::viewport_set_canvas_transform); + ClassDB::bind_method(D_METHOD("viewport_set_canvas_stacking", "viewport", "canvas", "layer", "sublayer"), &RenderingServer::viewport_set_canvas_stacking); + ClassDB::bind_method(D_METHOD("viewport_set_transparent_background", "viewport", "enabled"), &RenderingServer::viewport_set_transparent_background); ClassDB::bind_method(D_METHOD("viewport_set_global_canvas_transform", "viewport", "transform"), &RenderingServer::viewport_set_global_canvas_transform); - ClassDB::bind_method(D_METHOD("viewport_set_canvas_stacking", "viewport", "canvas", "layer", "sublayer"), &RenderingServer::viewport_set_canvas_stacking); + + ClassDB::bind_method(D_METHOD("viewport_set_sdf_oversize_and_scale", "viewport", "oversize", "scale"), &RenderingServer::viewport_set_sdf_oversize_and_scale); + ClassDB::bind_method(D_METHOD("viewport_set_shadow_atlas_size", "viewport", "size", "use_16_bits"), &RenderingServer::viewport_set_shadow_atlas_size, DEFVAL(false)); ClassDB::bind_method(D_METHOD("viewport_set_shadow_atlas_quadrant_subdivision", "viewport", "quadrant", "subdivision"), &RenderingServer::viewport_set_shadow_atlas_quadrant_subdivision); ClassDB::bind_method(D_METHOD("viewport_set_msaa", "viewport", "msaa"), &RenderingServer::viewport_set_msaa); + ClassDB::bind_method(D_METHOD("viewport_set_screen_space_aa", "viewport", "mode"), &RenderingServer::viewport_set_screen_space_aa); ClassDB::bind_method(D_METHOD("viewport_set_use_debanding", "viewport", "enable"), &RenderingServer::viewport_set_use_debanding); ClassDB::bind_method(D_METHOD("viewport_set_use_occlusion_culling", "viewport", "enable"), &RenderingServer::viewport_set_use_occlusion_culling); ClassDB::bind_method(D_METHOD("viewport_set_occlusion_rays_per_thread", "rays_per_thread"), &RenderingServer::viewport_set_occlusion_rays_per_thread); ClassDB::bind_method(D_METHOD("viewport_set_occlusion_culling_build_quality", "quality"), &RenderingServer::viewport_set_occlusion_culling_build_quality); - ClassDB::bind_method(D_METHOD("viewport_get_render_info", "viewport", "info"), &RenderingServer::viewport_get_render_info); + ClassDB::bind_method(D_METHOD("viewport_get_render_info", "viewport", "type", "info"), &RenderingServer::viewport_get_render_info); ClassDB::bind_method(D_METHOD("viewport_set_debug_draw", "viewport", "draw"), &RenderingServer::viewport_set_debug_draw); ClassDB::bind_method(D_METHOD("viewport_set_measure_render_time", "viewport", "enable"), &RenderingServer::viewport_set_measure_render_time); ClassDB::bind_method(D_METHOD("viewport_get_measured_render_time_cpu", "viewport"), &RenderingServer::viewport_get_measured_render_time_cpu); - ClassDB::bind_method(D_METHOD("viewport_get_measured_render_time_gpu", "viewport"), &RenderingServer::viewport_get_measured_render_time_gpu); - - ClassDB::bind_method(D_METHOD("environment_create"), &RenderingServer::environment_create); - ClassDB::bind_method(D_METHOD("environment_set_background", "env", "bg"), &RenderingServer::environment_set_background); - ClassDB::bind_method(D_METHOD("environment_set_sky", "env", "sky"), &RenderingServer::environment_set_sky); - ClassDB::bind_method(D_METHOD("environment_set_sky_custom_fov", "env", "scale"), &RenderingServer::environment_set_sky_custom_fov); - ClassDB::bind_method(D_METHOD("environment_set_sky_orientation", "env", "orientation"), &RenderingServer::environment_set_sky_orientation); - ClassDB::bind_method(D_METHOD("environment_set_bg_color", "env", "color"), &RenderingServer::environment_set_bg_color); - ClassDB::bind_method(D_METHOD("environment_set_bg_energy", "env", "energy"), &RenderingServer::environment_set_bg_energy); - ClassDB::bind_method(D_METHOD("environment_set_canvas_max_layer", "env", "max_layer"), &RenderingServer::environment_set_canvas_max_layer); - ClassDB::bind_method(D_METHOD("environment_set_ambient_light", "env", "color", "ambient", "energy", "sky_contibution", "reflection_source", "ao_color"), &RenderingServer::environment_set_ambient_light, DEFVAL(RS::ENV_AMBIENT_SOURCE_BG), DEFVAL(1.0), DEFVAL(0.0), DEFVAL(RS::ENV_REFLECTION_SOURCE_BG), DEFVAL(Color())); - ClassDB::bind_method(D_METHOD("environment_set_glow", "env", "enable", "levels", "intensity", "strength", "mix", "bloom_threshold", "blend_mode", "hdr_bleed_threshold", "hdr_bleed_scale", "hdr_luminance_cap"), &RenderingServer::environment_set_glow); - ClassDB::bind_method(D_METHOD("environment_set_tonemap", "env", "tone_mapper", "exposure", "white", "auto_exposure", "min_luminance", "max_luminance", "auto_exp_speed", "auto_exp_grey"), &RenderingServer::environment_set_tonemap); - ClassDB::bind_method(D_METHOD("environment_set_adjustment", "env", "enable", "brightness", "contrast", "saturation", "use_1d_color_correction", "color_correction"), &RenderingServer::environment_set_adjustment); - ClassDB::bind_method(D_METHOD("environment_set_ssr", "env", "enable", "max_steps", "fade_in", "fade_out", "depth_tolerance"), &RenderingServer::environment_set_ssr); - ClassDB::bind_method(D_METHOD("environment_set_ssao", "env", "enable", "radius", "intensity", "power", "detail", "horizon", "sharpness", "light_affect", "ao_channel_affect"), &RenderingServer::environment_set_ssao); - ClassDB::bind_method(D_METHOD("environment_set_fog", "env", "enable", "light_color", "light_energy", "sun_scatter", "density", "height", "height_density", "aerial_perspective"), &RenderingServer::environment_set_fog); - - ClassDB::bind_method(D_METHOD("scenario_create"), &RenderingServer::scenario_create); - ClassDB::bind_method(D_METHOD("scenario_set_debug", "scenario", "debug_mode"), &RenderingServer::scenario_set_debug); - ClassDB::bind_method(D_METHOD("scenario_set_environment", "scenario", "environment"), &RenderingServer::scenario_set_environment); - ClassDB::bind_method(D_METHOD("scenario_set_camera_effects", "scenario", "effects"), &RenderingServer::scenario_set_camera_effects); - ClassDB::bind_method(D_METHOD("scenario_set_fallback_environment", "scenario", "environment"), &RenderingServer::scenario_set_fallback_environment); - -#ifndef _3D_DISABLED - - ClassDB::bind_method(D_METHOD("instance_create2", "base", "scenario"), &RenderingServer::instance_create2); - ClassDB::bind_method(D_METHOD("instance_create"), &RenderingServer::instance_create); - ClassDB::bind_method(D_METHOD("instance_set_base", "instance", "base"), &RenderingServer::instance_set_base); - ClassDB::bind_method(D_METHOD("instance_set_scenario", "instance", "scenario"), &RenderingServer::instance_set_scenario); - ClassDB::bind_method(D_METHOD("instance_set_layer_mask", "instance", "mask"), &RenderingServer::instance_set_layer_mask); - ClassDB::bind_method(D_METHOD("instance_set_transform", "instance", "transform"), &RenderingServer::instance_set_transform); - ClassDB::bind_method(D_METHOD("instance_attach_object_instance_id", "instance", "id"), &RenderingServer::instance_attach_object_instance_id); - ClassDB::bind_method(D_METHOD("instance_set_blend_shape_weight", "instance", "shape", "weight"), &RenderingServer::instance_set_blend_shape_weight); - ClassDB::bind_method(D_METHOD("instance_set_surface_override_material", "instance", "surface", "material"), &RenderingServer::instance_set_surface_override_material); - ClassDB::bind_method(D_METHOD("instance_set_visible", "instance", "visible"), &RenderingServer::instance_set_visible); - // ClassDB::bind_method(D_METHOD("instance_set_use_lightmap", "instance", "lightmap_instance", "lightmap"), &RenderingServer::instance_set_use_lightmap); - ClassDB::bind_method(D_METHOD("instance_set_custom_aabb", "instance", "aabb"), &RenderingServer::instance_set_custom_aabb); - ClassDB::bind_method(D_METHOD("instance_attach_skeleton", "instance", "skeleton"), &RenderingServer::instance_attach_skeleton); - ClassDB::bind_method(D_METHOD("instance_set_exterior", "instance", "enabled"), &RenderingServer::instance_set_exterior); - ClassDB::bind_method(D_METHOD("instance_set_extra_visibility_margin", "instance", "margin"), &RenderingServer::instance_set_extra_visibility_margin); - ClassDB::bind_method(D_METHOD("instance_set_visibility_parent", "instance", "parent"), &RenderingServer::instance_set_visibility_parent); - ClassDB::bind_method(D_METHOD("instance_geometry_set_flag", "instance", "flag", "enabled"), &RenderingServer::instance_geometry_set_flag); - ClassDB::bind_method(D_METHOD("instance_geometry_set_cast_shadows_setting", "instance", "shadow_casting_setting"), &RenderingServer::instance_geometry_set_cast_shadows_setting); - ClassDB::bind_method(D_METHOD("instance_geometry_set_material_override", "instance", "material"), &RenderingServer::instance_geometry_set_material_override); - ClassDB::bind_method(D_METHOD("instance_geometry_set_visibility_range", "instance", "min", "max", "min_margin", "max_margin"), &RenderingServer::instance_geometry_set_visibility_range); - - ClassDB::bind_method(D_METHOD("instances_cull_aabb", "aabb", "scenario"), &RenderingServer::_instances_cull_aabb_bind, DEFVAL(RID())); - ClassDB::bind_method(D_METHOD("instances_cull_ray", "from", "to", "scenario"), &RenderingServer::_instances_cull_ray_bind, DEFVAL(RID())); - ClassDB::bind_method(D_METHOD("instances_cull_convex", "convex", "scenario"), &RenderingServer::_instances_cull_convex_bind, DEFVAL(RID())); -#endif - ClassDB::bind_method(D_METHOD("canvas_create"), &RenderingServer::canvas_create); - ClassDB::bind_method(D_METHOD("canvas_set_item_mirroring", "canvas", "item", "mirroring"), &RenderingServer::canvas_set_item_mirroring); - ClassDB::bind_method(D_METHOD("canvas_set_modulate", "canvas", "color"), &RenderingServer::canvas_set_modulate); -#ifndef _MSC_VER -#warning TODO method bindings need to be fixed -#endif -#if 0 - - ClassDB::bind_method(D_METHOD("canvas_item_create"), &RenderingServer::canvas_item_create); - ClassDB::bind_method(D_METHOD("canvas_item_set_parent", "item", "parent"), &RenderingServer::canvas_item_set_parent); - ClassDB::bind_method(D_METHOD("canvas_item_set_visible", "item", "visible"), &RenderingServer::canvas_item_set_visible); - ClassDB::bind_method(D_METHOD("canvas_item_set_light_mask", "item", "mask"), &RenderingServer::canvas_item_set_light_mask); - ClassDB::bind_method(D_METHOD("canvas_item_set_transform", "item", "transform"), &RenderingServer::canvas_item_set_transform); - ClassDB::bind_method(D_METHOD("canvas_item_set_clip", "item", "clip"), &RenderingServer::canvas_item_set_clip); - ClassDB::bind_method(D_METHOD("canvas_item_set_distance_field_mode", "item", "enabled"), &RenderingServer::canvas_item_set_distance_field_mode); - ClassDB::bind_method(D_METHOD("canvas_item_set_custom_rect", "item", "use_custom_rect", "rect"), &RenderingServer::canvas_item_set_custom_rect, DEFVAL(Rect2())); - ClassDB::bind_method(D_METHOD("canvas_item_set_modulate", "item", "color"), &RenderingServer::canvas_item_set_modulate); - ClassDB::bind_method(D_METHOD("canvas_item_set_self_modulate", "item", "color"), &RenderingServer::canvas_item_set_self_modulate); - ClassDB::bind_method(D_METHOD("canvas_item_set_draw_behind_parent", "item", "enabled"), &RenderingServer::canvas_item_set_draw_behind_parent); - ClassDB::bind_method(D_METHOD("canvas_item_add_line", "item", "from", "to", "color", "width", "antialiased"), &RenderingServer::canvas_item_add_line, DEFVAL(1.0), DEFVAL(false)); - ClassDB::bind_method(D_METHOD("canvas_item_add_polyline", "item", "points", "colors", "width", "antialiased"), &RenderingServer::canvas_item_add_polyline, DEFVAL(1.0), DEFVAL(false)); - ClassDB::bind_method(D_METHOD("canvas_item_add_rect", "item", "rect", "color"), &RenderingServer::canvas_item_add_rect); - ClassDB::bind_method(D_METHOD("canvas_item_add_circle", "item", "pos", "radius", "color"), &RenderingServer::canvas_item_add_circle); - ClassDB::bind_method(D_METHOD("canvas_item_add_texture_rect", "item", "rect", "texture", "tile", "modulate", "transpose", "normal_map"), &RenderingServer::canvas_item_add_texture_rect, DEFVAL(false), DEFVAL(Color(1, 1, 1)), DEFVAL(false), DEFVAL(RID())); - ClassDB::bind_method(D_METHOD("canvas_item_add_texture_rect_region", "item", "rect", "texture", "src_rect", "modulate", "transpose", "normal_map", "clip_uv"), &RenderingServer::canvas_item_add_texture_rect_region, DEFVAL(Color(1, 1, 1)), DEFVAL(false), DEFVAL(RID()), DEFVAL(true)); - ClassDB::bind_method(D_METHOD("canvas_item_add_nine_patch", "item", "rect", "source", "texture", "topleft", "bottomright", "x_axis_mode", "y_axis_mode", "draw_center", "modulate", "normal_map"), &RenderingServer::canvas_item_add_nine_patch, DEFVAL(NINE_PATCH_STRETCH), DEFVAL(NINE_PATCH_STRETCH), DEFVAL(true), DEFVAL(Color(1, 1, 1)), DEFVAL(RID())); - ClassDB::bind_method(D_METHOD("canvas_item_add_primitive", "item", "points", "colors", "uvs", "texture", "width", "normal_map"), &RenderingServer::canvas_item_add_primitive, DEFVAL(1.0), DEFVAL(RID())); - ClassDB::bind_method(D_METHOD("canvas_item_add_polygon", "item", "points", "colors", "uvs", "texture", "normal_map", "antialiased"), &RenderingServer::canvas_item_add_polygon, DEFVAL(Vector<Point2>()), DEFVAL(RID()), DEFVAL(RID()), DEFVAL(false)); - ClassDB::bind_method(D_METHOD("canvas_item_add_triangle_array", "item", "indices", "points", "colors", "uvs", "bones", "weights", "texture", "count", "normal_map", "antialiased"), &RenderingServer::canvas_item_add_triangle_array, DEFVAL(Vector<Point2>()), DEFVAL(Vector<int>()), DEFVAL(Vector<float>()), DEFVAL(RID()), DEFVAL(-1), DEFVAL(RID()), DEFVAL(false)); - ClassDB::bind_method(D_METHOD("canvas_item_add_mesh", "item", "mesh", "transform", "modulate", "texture", "normal_map"), &RenderingServer::canvas_item_add_mesh, DEFVAL(Transform2D()), DEFVAL(Color(1, 1, 1)), DEFVAL(RID()), DEFVAL(RID())); - ClassDB::bind_method(D_METHOD("canvas_item_add_multimesh", "item", "mesh", "texture", "normal_map"), &RenderingServer::canvas_item_add_multimesh, DEFVAL(RID())); - ClassDB::bind_method(D_METHOD("canvas_item_add_particles", "item", "particles", "texture", "normal_map"), &RenderingServer::canvas_item_add_particles); - ClassDB::bind_method(D_METHOD("canvas_item_add_set_transform", "item", "transform"), &RenderingServer::canvas_item_add_set_transform); - ClassDB::bind_method(D_METHOD("canvas_item_add_clip_ignore", "item", "ignore"), &RenderingServer::canvas_item_add_clip_ignore); - ClassDB::bind_method(D_METHOD("canvas_item_set_sort_children_by_y", "item", "enabled"), &RenderingServer::canvas_item_set_sort_children_by_y); -#endif - ClassDB::bind_method(D_METHOD("canvas_item_set_z_index", "item", "z_index"), &RenderingServer::canvas_item_set_z_index); - ClassDB::bind_method(D_METHOD("canvas_item_set_z_as_relative_to_parent", "item", "enabled"), &RenderingServer::canvas_item_set_z_as_relative_to_parent); - ClassDB::bind_method(D_METHOD("canvas_item_set_copy_to_backbuffer", "item", "enabled", "rect"), &RenderingServer::canvas_item_set_copy_to_backbuffer); - ClassDB::bind_method(D_METHOD("canvas_item_clear", "item"), &RenderingServer::canvas_item_clear); - ClassDB::bind_method(D_METHOD("canvas_item_set_draw_index", "item", "index"), &RenderingServer::canvas_item_set_draw_index); - ClassDB::bind_method(D_METHOD("canvas_item_set_material", "item", "material"), &RenderingServer::canvas_item_set_material); - ClassDB::bind_method(D_METHOD("canvas_item_set_use_parent_material", "item", "enabled"), &RenderingServer::canvas_item_set_use_parent_material); - ClassDB::bind_method(D_METHOD("canvas_light_create"), &RenderingServer::canvas_light_create); - ClassDB::bind_method(D_METHOD("canvas_light_attach_to_canvas", "light", "canvas"), &RenderingServer::canvas_light_attach_to_canvas); - ClassDB::bind_method(D_METHOD("canvas_light_set_enabled", "light", "enabled"), &RenderingServer::canvas_light_set_enabled); - ClassDB::bind_method(D_METHOD("canvas_light_set_texture_scale", "light", "scale"), &RenderingServer::canvas_light_set_texture_scale); - ClassDB::bind_method(D_METHOD("canvas_light_set_transform", "light", "transform"), &RenderingServer::canvas_light_set_transform); - ClassDB::bind_method(D_METHOD("canvas_light_set_texture", "light", "texture"), &RenderingServer::canvas_light_set_texture); - ClassDB::bind_method(D_METHOD("canvas_light_set_texture_offset", "light", "offset"), &RenderingServer::canvas_light_set_texture_offset); - ClassDB::bind_method(D_METHOD("canvas_light_set_color", "light", "color"), &RenderingServer::canvas_light_set_color); - ClassDB::bind_method(D_METHOD("canvas_light_set_height", "light", "height"), &RenderingServer::canvas_light_set_height); - ClassDB::bind_method(D_METHOD("canvas_light_set_energy", "light", "energy"), &RenderingServer::canvas_light_set_energy); - ClassDB::bind_method(D_METHOD("canvas_light_set_z_range", "light", "min_z", "max_z"), &RenderingServer::canvas_light_set_z_range); - ClassDB::bind_method(D_METHOD("canvas_light_set_layer_range", "light", "min_layer", "max_layer"), &RenderingServer::canvas_light_set_layer_range); - ClassDB::bind_method(D_METHOD("canvas_light_set_item_cull_mask", "light", "mask"), &RenderingServer::canvas_light_set_item_cull_mask); - ClassDB::bind_method(D_METHOD("canvas_light_set_item_shadow_cull_mask", "light", "mask"), &RenderingServer::canvas_light_set_item_shadow_cull_mask); - ClassDB::bind_method(D_METHOD("canvas_light_set_mode", "light", "mode"), &RenderingServer::canvas_light_set_mode); - ClassDB::bind_method(D_METHOD("canvas_light_set_shadow_enabled", "light", "enabled"), &RenderingServer::canvas_light_set_shadow_enabled); - ClassDB::bind_method(D_METHOD("canvas_light_set_shadow_filter", "light", "filter"), &RenderingServer::canvas_light_set_shadow_filter); - ClassDB::bind_method(D_METHOD("canvas_light_set_shadow_color", "light", "color"), &RenderingServer::canvas_light_set_shadow_color); - ClassDB::bind_method(D_METHOD("canvas_light_set_shadow_smooth", "light", "smooth"), &RenderingServer::canvas_light_set_shadow_smooth); - - ClassDB::bind_method(D_METHOD("canvas_light_occluder_create"), &RenderingServer::canvas_light_occluder_create); - ClassDB::bind_method(D_METHOD("canvas_light_occluder_attach_to_canvas", "occluder", "canvas"), &RenderingServer::canvas_light_occluder_attach_to_canvas); - ClassDB::bind_method(D_METHOD("canvas_light_occluder_set_enabled", "occluder", "enabled"), &RenderingServer::canvas_light_occluder_set_enabled); - ClassDB::bind_method(D_METHOD("canvas_light_occluder_set_polygon", "occluder", "polygon"), &RenderingServer::canvas_light_occluder_set_polygon); - ClassDB::bind_method(D_METHOD("canvas_light_occluder_set_transform", "occluder", "transform"), &RenderingServer::canvas_light_occluder_set_transform); - ClassDB::bind_method(D_METHOD("canvas_light_occluder_set_light_mask", "occluder", "mask"), &RenderingServer::canvas_light_occluder_set_light_mask); - - ClassDB::bind_method(D_METHOD("canvas_occluder_polygon_create"), &RenderingServer::canvas_occluder_polygon_create); - ClassDB::bind_method(D_METHOD("canvas_occluder_polygon_set_shape", "occluder_polygon", "shape", "closed"), &RenderingServer::canvas_occluder_polygon_set_shape); - ClassDB::bind_method(D_METHOD("canvas_occluder_polygon_set_cull_mode", "occluder_polygon", "mode"), &RenderingServer::canvas_occluder_polygon_set_cull_mode); - - ClassDB::bind_method(D_METHOD("global_variable_add", "name", "type", "default_value"), &RenderingServer::global_variable_add); - ClassDB::bind_method(D_METHOD("global_variable_remove", "name"), &RenderingServer::global_variable_remove); - ClassDB::bind_method(D_METHOD("global_variable_get_list"), &RenderingServer::global_variable_get_list); - ClassDB::bind_method(D_METHOD("global_variable_set", "name", "value"), &RenderingServer::global_variable_set); - ClassDB::bind_method(D_METHOD("global_variable_get", "name"), &RenderingServer::global_variable_get); - ClassDB::bind_method(D_METHOD("global_variable_get_type", "name"), &RenderingServer::global_variable_get_type); - - ClassDB::bind_method(D_METHOD("black_bars_set_margins", "left", "top", "right", "bottom"), &RenderingServer::black_bars_set_margins); - ClassDB::bind_method(D_METHOD("black_bars_set_images", "left", "top", "right", "bottom"), &RenderingServer::black_bars_set_images); - - ClassDB::bind_method(D_METHOD("free_rid", "rid"), &RenderingServer::free); // shouldn't conflict with Object::free() - - ClassDB::bind_method(D_METHOD("request_frame_drawn_callback", "where", "method", "userdata"), &RenderingServer::request_frame_drawn_callback); - ClassDB::bind_method(D_METHOD("has_changed"), &RenderingServer::has_changed); - ClassDB::bind_method(D_METHOD("init"), &RenderingServer::init); - ClassDB::bind_method(D_METHOD("finish"), &RenderingServer::finish); - ClassDB::bind_method(D_METHOD("get_render_info", "info"), &RenderingServer::get_render_info); - ClassDB::bind_method(D_METHOD("get_video_adapter_name"), &RenderingServer::get_video_adapter_name); - ClassDB::bind_method(D_METHOD("get_video_adapter_vendor"), &RenderingServer::get_video_adapter_vendor); -#ifndef _3D_DISABLED - - ClassDB::bind_method(D_METHOD("make_sphere_mesh", "latitudes", "longitudes", "radius"), &RenderingServer::make_sphere_mesh); - ClassDB::bind_method(D_METHOD("get_test_cube"), &RenderingServer::get_test_cube); -#endif - ClassDB::bind_method(D_METHOD("get_test_texture"), &RenderingServer::get_test_texture); - ClassDB::bind_method(D_METHOD("get_white_texture"), &RenderingServer::get_white_texture); - - ClassDB::bind_method(D_METHOD("set_boot_image", "image", "color", "scale", "use_filter"), &RenderingServer::set_boot_image, DEFVAL(true)); - ClassDB::bind_method(D_METHOD("set_default_clear_color", "color"), &RenderingServer::set_default_clear_color); - - ClassDB::bind_method(D_METHOD("has_feature", "feature"), &RenderingServer::has_feature); - ClassDB::bind_method(D_METHOD("has_os_feature", "feature"), &RenderingServer::has_os_feature); - ClassDB::bind_method(D_METHOD("set_debug_generate_wireframes", "generate"), &RenderingServer::set_debug_generate_wireframes); - - ClassDB::bind_method(D_METHOD("is_render_loop_enabled"), &RenderingServer::is_render_loop_enabled); - ClassDB::bind_method(D_METHOD("set_render_loop_enabled", "enabled"), &RenderingServer::set_render_loop_enabled); - - ClassDB::bind_method(D_METHOD("get_frame_setup_time_cpu"), &RenderingServer::get_frame_setup_time_cpu); - - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "render_loop_enabled"), "set_render_loop_enabled", "is_render_loop_enabled"); - - BIND_CONSTANT(NO_INDEX_ARRAY); - BIND_CONSTANT(ARRAY_WEIGHTS_SIZE); - BIND_CONSTANT(CANVAS_ITEM_Z_MIN); - BIND_CONSTANT(CANVAS_ITEM_Z_MAX); - BIND_CONSTANT(MAX_GLOW_LEVELS); - BIND_CONSTANT(MAX_CURSORS); - - BIND_ENUM_CONSTANT(TEXTURE_LAYERED_2D_ARRAY); - BIND_ENUM_CONSTANT(TEXTURE_LAYERED_CUBEMAP); - BIND_ENUM_CONSTANT(TEXTURE_LAYERED_CUBEMAP_ARRAY); - - BIND_ENUM_CONSTANT(CUBEMAP_LAYER_LEFT); - BIND_ENUM_CONSTANT(CUBEMAP_LAYER_RIGHT); - BIND_ENUM_CONSTANT(CUBEMAP_LAYER_BOTTOM); - BIND_ENUM_CONSTANT(CUBEMAP_LAYER_TOP); - BIND_ENUM_CONSTANT(CUBEMAP_LAYER_FRONT); - BIND_ENUM_CONSTANT(CUBEMAP_LAYER_BACK); - - BIND_ENUM_CONSTANT(SHADER_SPATIAL); - BIND_ENUM_CONSTANT(SHADER_CANVAS_ITEM); - BIND_ENUM_CONSTANT(SHADER_PARTICLES); - BIND_ENUM_CONSTANT(SHADER_SKY); - BIND_ENUM_CONSTANT(SHADER_MAX); - - BIND_CONSTANT(MATERIAL_RENDER_PRIORITY_MIN); - BIND_CONSTANT(MATERIAL_RENDER_PRIORITY_MAX); - - BIND_ENUM_CONSTANT(ARRAY_VERTEX); - BIND_ENUM_CONSTANT(ARRAY_NORMAL); - BIND_ENUM_CONSTANT(ARRAY_TANGENT); - BIND_ENUM_CONSTANT(ARRAY_COLOR); - BIND_ENUM_CONSTANT(ARRAY_TEX_UV); - BIND_ENUM_CONSTANT(ARRAY_TEX_UV2); - BIND_ENUM_CONSTANT(ARRAY_CUSTOM0); - BIND_ENUM_CONSTANT(ARRAY_CUSTOM1); - BIND_ENUM_CONSTANT(ARRAY_CUSTOM2); - BIND_ENUM_CONSTANT(ARRAY_CUSTOM3); - BIND_ENUM_CONSTANT(ARRAY_BONES); - BIND_ENUM_CONSTANT(ARRAY_WEIGHTS); - BIND_ENUM_CONSTANT(ARRAY_INDEX); - BIND_ENUM_CONSTANT(ARRAY_MAX); - - BIND_ENUM_CONSTANT(ARRAY_FORMAT_VERTEX); - BIND_ENUM_CONSTANT(ARRAY_FORMAT_NORMAL); - BIND_ENUM_CONSTANT(ARRAY_FORMAT_TANGENT); - BIND_ENUM_CONSTANT(ARRAY_FORMAT_COLOR); - BIND_ENUM_CONSTANT(ARRAY_FORMAT_TEX_UV); - BIND_ENUM_CONSTANT(ARRAY_FORMAT_TEX_UV2); - BIND_ENUM_CONSTANT(ARRAY_FORMAT_CUSTOM0); - BIND_ENUM_CONSTANT(ARRAY_FORMAT_CUSTOM1); - BIND_ENUM_CONSTANT(ARRAY_FORMAT_CUSTOM2); - BIND_ENUM_CONSTANT(ARRAY_FORMAT_CUSTOM3); - BIND_ENUM_CONSTANT(ARRAY_FORMAT_BONES); - BIND_ENUM_CONSTANT(ARRAY_FORMAT_WEIGHTS); - BIND_ENUM_CONSTANT(ARRAY_FORMAT_INDEX); - BIND_ENUM_CONSTANT(ARRAY_FORMAT_BLEND_SHAPE_MASK); - - BIND_ENUM_CONSTANT(ARRAY_FORMAT_CUSTOM_BASE); - BIND_ENUM_CONSTANT(ARRAY_FORMAT_CUSTOM0_SHIFT); - BIND_ENUM_CONSTANT(ARRAY_FORMAT_CUSTOM1_SHIFT); - BIND_ENUM_CONSTANT(ARRAY_FORMAT_CUSTOM2_SHIFT); - BIND_ENUM_CONSTANT(ARRAY_FORMAT_CUSTOM3_SHIFT); - - BIND_ENUM_CONSTANT(ARRAY_FORMAT_CUSTOM_MASK); - BIND_ENUM_CONSTANT(ARRAY_COMPRESS_FLAGS_BASE); - - BIND_ENUM_CONSTANT(ARRAY_FLAG_USE_2D_VERTICES); - BIND_ENUM_CONSTANT(ARRAY_FLAG_USE_DYNAMIC_UPDATE); - BIND_ENUM_CONSTANT(ARRAY_FLAG_USE_8_BONE_WEIGHTS); - - BIND_ENUM_CONSTANT(PRIMITIVE_POINTS); - BIND_ENUM_CONSTANT(PRIMITIVE_LINES); - BIND_ENUM_CONSTANT(PRIMITIVE_LINE_STRIP); - BIND_ENUM_CONSTANT(PRIMITIVE_TRIANGLES); - BIND_ENUM_CONSTANT(PRIMITIVE_TRIANGLE_STRIP); - BIND_ENUM_CONSTANT(PRIMITIVE_MAX); - - BIND_ENUM_CONSTANT(BLEND_SHAPE_MODE_NORMALIZED); - BIND_ENUM_CONSTANT(BLEND_SHAPE_MODE_RELATIVE); - - BIND_ENUM_CONSTANT(MULTIMESH_TRANSFORM_2D); - BIND_ENUM_CONSTANT(MULTIMESH_TRANSFORM_3D); - - BIND_ENUM_CONSTANT(LIGHT_DIRECTIONAL); - BIND_ENUM_CONSTANT(LIGHT_OMNI); - BIND_ENUM_CONSTANT(LIGHT_SPOT); - - BIND_ENUM_CONSTANT(LIGHT_PARAM_ENERGY); - BIND_ENUM_CONSTANT(LIGHT_PARAM_INDIRECT_ENERGY); - BIND_ENUM_CONSTANT(LIGHT_PARAM_SPECULAR); - BIND_ENUM_CONSTANT(LIGHT_PARAM_RANGE); - BIND_ENUM_CONSTANT(LIGHT_PARAM_SIZE); - BIND_ENUM_CONSTANT(LIGHT_PARAM_ATTENUATION); - BIND_ENUM_CONSTANT(LIGHT_PARAM_SPOT_ANGLE); - BIND_ENUM_CONSTANT(LIGHT_PARAM_SPOT_ATTENUATION); - BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_MAX_DISTANCE); - BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_SPLIT_1_OFFSET); - BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_SPLIT_2_OFFSET); - BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_SPLIT_3_OFFSET); - BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_FADE_START); - BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_NORMAL_BIAS); - BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_BIAS); - BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_PANCAKE_SIZE); - BIND_ENUM_CONSTANT(LIGHT_PARAM_SHADOW_BLUR); - BIND_ENUM_CONSTANT(LIGHT_PARAM_TRANSMITTANCE_BIAS); - BIND_ENUM_CONSTANT(LIGHT_PARAM_MAX); - - BIND_ENUM_CONSTANT(LIGHT_BAKE_DISABLED); - BIND_ENUM_CONSTANT(LIGHT_BAKE_DYNAMIC); - BIND_ENUM_CONSTANT(LIGHT_BAKE_STATIC); - - BIND_ENUM_CONSTANT(LIGHT_OMNI_SHADOW_DUAL_PARABOLOID); - BIND_ENUM_CONSTANT(LIGHT_OMNI_SHADOW_CUBE); - - BIND_ENUM_CONSTANT(LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL); - BIND_ENUM_CONSTANT(LIGHT_DIRECTIONAL_SHADOW_PARALLEL_2_SPLITS); - BIND_ENUM_CONSTANT(LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS); - - BIND_ENUM_CONSTANT(LIGHT_DIRECTIONAL_SHADOW_DEPTH_RANGE_STABLE); - BIND_ENUM_CONSTANT(LIGHT_DIRECTIONAL_SHADOW_DEPTH_RANGE_OPTIMIZED); - - BIND_ENUM_CONSTANT(REFLECTION_PROBE_UPDATE_ONCE); - BIND_ENUM_CONSTANT(REFLECTION_PROBE_UPDATE_ALWAYS); - - BIND_ENUM_CONSTANT(REFLECTION_PROBE_AMBIENT_DISABLED); - BIND_ENUM_CONSTANT(REFLECTION_PROBE_AMBIENT_ENVIRONMENT); - BIND_ENUM_CONSTANT(REFLECTION_PROBE_AMBIENT_COLOR); - - BIND_ENUM_CONSTANT(DECAL_TEXTURE_ALBEDO); - BIND_ENUM_CONSTANT(DECAL_TEXTURE_NORMAL); - BIND_ENUM_CONSTANT(DECAL_TEXTURE_ORM); - BIND_ENUM_CONSTANT(DECAL_TEXTURE_EMISSION); - BIND_ENUM_CONSTANT(DECAL_TEXTURE_MAX); - - BIND_ENUM_CONSTANT(PARTICLES_DRAW_ORDER_INDEX); - BIND_ENUM_CONSTANT(PARTICLES_DRAW_ORDER_LIFETIME); - BIND_ENUM_CONSTANT(PARTICLES_DRAW_ORDER_VIEW_DEPTH); + ClassDB::bind_method(D_METHOD("viewport_get_measured_render_time_gpu", "viewport"), &RenderingServer::viewport_get_measured_render_time_gpu); BIND_ENUM_CONSTANT(VIEWPORT_UPDATE_DISABLED); - BIND_ENUM_CONSTANT(VIEWPORT_UPDATE_ONCE); - BIND_ENUM_CONSTANT(VIEWPORT_UPDATE_WHEN_VISIBLE); + BIND_ENUM_CONSTANT(VIEWPORT_UPDATE_ONCE); //then goes to disabled); must be manually updated + BIND_ENUM_CONSTANT(VIEWPORT_UPDATE_WHEN_VISIBLE); // default BIND_ENUM_CONSTANT(VIEWPORT_UPDATE_WHEN_PARENT_VISIBLE); BIND_ENUM_CONSTANT(VIEWPORT_UPDATE_ALWAYS); @@ -1999,6 +2154,17 @@ void RenderingServer::_bind_methods() { BIND_ENUM_CONSTANT(VIEWPORT_CLEAR_NEVER); BIND_ENUM_CONSTANT(VIEWPORT_CLEAR_ONLY_NEXT_FRAME); + BIND_ENUM_CONSTANT(VIEWPORT_SDF_OVERSIZE_100_PERCENT); + BIND_ENUM_CONSTANT(VIEWPORT_SDF_OVERSIZE_120_PERCENT); + BIND_ENUM_CONSTANT(VIEWPORT_SDF_OVERSIZE_150_PERCENT); + BIND_ENUM_CONSTANT(VIEWPORT_SDF_OVERSIZE_200_PERCENT); + BIND_ENUM_CONSTANT(VIEWPORT_SDF_OVERSIZE_MAX); + + BIND_ENUM_CONSTANT(VIEWPORT_SDF_SCALE_100_PERCENT); + BIND_ENUM_CONSTANT(VIEWPORT_SDF_SCALE_50_PERCENT); + BIND_ENUM_CONSTANT(VIEWPORT_SDF_SCALE_25_PERCENT); + BIND_ENUM_CONSTANT(VIEWPORT_SDF_SCALE_MAX); + BIND_ENUM_CONSTANT(VIEWPORT_MSAA_DISABLED); BIND_ENUM_CONSTANT(VIEWPORT_MSAA_2X); BIND_ENUM_CONSTANT(VIEWPORT_MSAA_4X); @@ -2010,14 +2176,19 @@ void RenderingServer::_bind_methods() { BIND_ENUM_CONSTANT(VIEWPORT_SCREEN_SPACE_AA_FXAA); BIND_ENUM_CONSTANT(VIEWPORT_SCREEN_SPACE_AA_MAX); + BIND_ENUM_CONSTANT(VIEWPORT_OCCLUSION_BUILD_QUALITY_LOW); + BIND_ENUM_CONSTANT(VIEWPORT_OCCLUSION_BUILD_QUALITY_MEDIUM); + BIND_ENUM_CONSTANT(VIEWPORT_OCCLUSION_BUILD_QUALITY_HIGH); + BIND_ENUM_CONSTANT(VIEWPORT_RENDER_INFO_OBJECTS_IN_FRAME); - BIND_ENUM_CONSTANT(VIEWPORT_RENDER_INFO_VERTICES_IN_FRAME); - BIND_ENUM_CONSTANT(VIEWPORT_RENDER_INFO_MATERIAL_CHANGES_IN_FRAME); - BIND_ENUM_CONSTANT(VIEWPORT_RENDER_INFO_SHADER_CHANGES_IN_FRAME); - BIND_ENUM_CONSTANT(VIEWPORT_RENDER_INFO_SURFACE_CHANGES_IN_FRAME); + BIND_ENUM_CONSTANT(VIEWPORT_RENDER_INFO_PRIMITIVES_IN_FRAME); BIND_ENUM_CONSTANT(VIEWPORT_RENDER_INFO_DRAW_CALLS_IN_FRAME); BIND_ENUM_CONSTANT(VIEWPORT_RENDER_INFO_MAX); + BIND_ENUM_CONSTANT(VIEWPORT_RENDER_INFO_TYPE_VISIBLE); + BIND_ENUM_CONSTANT(VIEWPORT_RENDER_INFO_TYPE_SHADOW); + BIND_ENUM_CONSTANT(VIEWPORT_RENDER_INFO_TYPE_MAX); + BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_DISABLED); BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_UNSHADED); BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_LIGHTING); @@ -2036,11 +2207,62 @@ void RenderingServer::_bind_methods() { BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_SDFGI); BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_SDFGI_PROBES); BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_GI_BUFFER); + BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_DISABLE_LOD); + BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_CLUSTER_OMNI_LIGHTS); + BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_CLUSTER_SPOT_LIGHTS); + BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_CLUSTER_DECALS); + BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_CLUSTER_REFLECTION_PROBES); BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_OCCLUDERS); + /* SKY API */ + + ClassDB::bind_method(D_METHOD("sky_create"), &RenderingServer::sky_create); + ClassDB::bind_method(D_METHOD("sky_set_radiance_size", "sky", "radiance_size"), &RenderingServer::sky_set_radiance_size); + ClassDB::bind_method(D_METHOD("sky_set_mode", "sky", "mode"), &RenderingServer::sky_set_mode); + ClassDB::bind_method(D_METHOD("sky_set_material", "sky", "material"), &RenderingServer::sky_set_material); + ClassDB::bind_method(D_METHOD("sky_bake_panorama", "sky", "energy", "bake_irradiance", "size"), &RenderingServer::sky_bake_panorama); + + BIND_ENUM_CONSTANT(SKY_MODE_AUTOMATIC); BIND_ENUM_CONSTANT(SKY_MODE_QUALITY); + BIND_ENUM_CONSTANT(SKY_MODE_INCREMENTAL); BIND_ENUM_CONSTANT(SKY_MODE_REALTIME); + /* ENVIRONMENT */ + + ClassDB::bind_method(D_METHOD("environment_create"), &RenderingServer::environment_create); + ClassDB::bind_method(D_METHOD("environment_set_background", "env", "bg"), &RenderingServer::environment_set_background); + ClassDB::bind_method(D_METHOD("environment_set_sky", "env", "sky"), &RenderingServer::environment_set_sky); + ClassDB::bind_method(D_METHOD("environment_set_sky_custom_fov", "env", "scale"), &RenderingServer::environment_set_sky_custom_fov); + ClassDB::bind_method(D_METHOD("environment_set_sky_orientation", "env", "orientation"), &RenderingServer::environment_set_sky_orientation); + ClassDB::bind_method(D_METHOD("environment_set_bg_color", "env", "color"), &RenderingServer::environment_set_bg_color); + ClassDB::bind_method(D_METHOD("environment_set_bg_energy", "env", "energy"), &RenderingServer::environment_set_bg_energy); + ClassDB::bind_method(D_METHOD("environment_set_canvas_max_layer", "env", "max_layer"), &RenderingServer::environment_set_canvas_max_layer); + ClassDB::bind_method(D_METHOD("environment_set_ambient_light", "env", "color", "ambient", "energy", "sky_contibution", "reflection_source", "ao_color"), &RenderingServer::environment_set_ambient_light, DEFVAL(RS::ENV_AMBIENT_SOURCE_BG), DEFVAL(1.0), DEFVAL(0.0), DEFVAL(RS::ENV_REFLECTION_SOURCE_BG), DEFVAL(Color())); + ClassDB::bind_method(D_METHOD("environment_set_glow", "env", "enable", "levels", "intensity", "strength", "mix", "bloom_threshold", "blend_mode", "hdr_bleed_threshold", "hdr_bleed_scale", "hdr_luminance_cap"), &RenderingServer::environment_set_glow); + ClassDB::bind_method(D_METHOD("environment_set_tonemap", "env", "tone_mapper", "exposure", "white", "auto_exposure", "min_luminance", "max_luminance", "auto_exp_speed", "auto_exp_grey"), &RenderingServer::environment_set_tonemap); + ClassDB::bind_method(D_METHOD("environment_set_adjustment", "env", "enable", "brightness", "contrast", "saturation", "use_1d_color_correction", "color_correction"), &RenderingServer::environment_set_adjustment); + ClassDB::bind_method(D_METHOD("environment_set_ssr", "env", "enable", "max_steps", "fade_in", "fade_out", "depth_tolerance"), &RenderingServer::environment_set_ssr); + ClassDB::bind_method(D_METHOD("environment_set_ssao", "env", "enable", "radius", "intensity", "power", "detail", "horizon", "sharpness", "light_affect", "ao_channel_affect"), &RenderingServer::environment_set_ssao); + ClassDB::bind_method(D_METHOD("environment_set_fog", "env", "enable", "light_color", "light_energy", "sun_scatter", "density", "height", "height_density", "aerial_perspective"), &RenderingServer::environment_set_fog); + ClassDB::bind_method(D_METHOD("environment_set_sdfgi", "env", "enable", "cascades", "min_cell_size", "y_scale", "use_occlusion", "bounce_feedback", "read_sky", "energy", "normal_bias", "probe_bias"), &RenderingServer::environment_set_sdfgi); + ClassDB::bind_method(D_METHOD("environment_set_volumetric_fog", "env", "enable", "density", "light", "light_energy", "length", "p_detail_spread", "gi_inject", "temporal_reprojection", "temporal_reprojection_amount"), &RenderingServer::environment_set_volumetric_fog); + + ClassDB::bind_method(D_METHOD("environment_glow_set_use_bicubic_upscale", "enable"), &RenderingServer::environment_glow_set_use_bicubic_upscale); + ClassDB::bind_method(D_METHOD("environment_glow_set_use_high_quality", "enable"), &RenderingServer::environment_glow_set_use_high_quality); + ClassDB::bind_method(D_METHOD("environment_set_ssr_roughness_quality", "quality"), &RenderingServer::environment_set_ssr_roughness_quality); + ClassDB::bind_method(D_METHOD("environment_set_ssao_quality", "quality", "half_size", "adaptive_target", "blur_passes", "fadeout_from", "fadeout_to"), &RenderingServer::environment_set_ssao_quality); + ClassDB::bind_method(D_METHOD("environment_set_sdfgi_ray_count", "ray_count"), &RenderingServer::environment_set_sdfgi_ray_count); + ClassDB::bind_method(D_METHOD("environment_set_sdfgi_frames_to_converge", "frames"), &RenderingServer::environment_set_sdfgi_frames_to_converge); + ClassDB::bind_method(D_METHOD("environment_set_sdfgi_frames_to_update_light", "frames"), &RenderingServer::environment_set_sdfgi_frames_to_update_light); + ClassDB::bind_method(D_METHOD("environment_set_volumetric_fog_volume_size", "size", "depth"), &RenderingServer::environment_set_volumetric_fog_volume_size); + ClassDB::bind_method(D_METHOD("environment_set_volumetric_fog_filter_active", "active"), &RenderingServer::environment_set_volumetric_fog_filter_active); + + ClassDB::bind_method(D_METHOD("environment_bake_panorama", "environment", "bake_irradiance", "size"), &RenderingServer::environment_bake_panorama); + + ClassDB::bind_method(D_METHOD("screen_space_roughness_limiter_set_active", "enable", "amount", "limit"), &RenderingServer::screen_space_roughness_limiter_set_active); + ClassDB::bind_method(D_METHOD("sub_surface_scattering_set_quality", "quality"), &RenderingServer::sub_surface_scattering_set_quality); + ClassDB::bind_method(D_METHOD("sub_surface_scattering_set_scale", "scale", "depth_scale"), &RenderingServer::sub_surface_scattering_set_scale); + BIND_ENUM_CONSTANT(ENV_BG_CLEAR_COLOR); BIND_ENUM_CONSTANT(ENV_BG_COLOR); BIND_ENUM_CONSTANT(ENV_BG_SKY); @@ -2080,40 +2302,107 @@ void RenderingServer::_bind_methods() { BIND_ENUM_CONSTANT(ENV_SSAO_QUALITY_HIGH); BIND_ENUM_CONSTANT(ENV_SSAO_QUALITY_ULTRA); + BIND_ENUM_CONSTANT(ENV_SDFGI_CASCADES_4); + BIND_ENUM_CONSTANT(ENV_SDFGI_CASCADES_6); + BIND_ENUM_CONSTANT(ENV_SDFGI_CASCADES_8); + + BIND_ENUM_CONSTANT(ENV_SDFGI_Y_SCALE_DISABLED); + BIND_ENUM_CONSTANT(ENV_SDFGI_Y_SCALE_75_PERCENT); + BIND_ENUM_CONSTANT(ENV_SDFGI_Y_SCALE_50_PERCENT); + + BIND_ENUM_CONSTANT(ENV_SDFGI_RAY_COUNT_4); + BIND_ENUM_CONSTANT(ENV_SDFGI_RAY_COUNT_8); + BIND_ENUM_CONSTANT(ENV_SDFGI_RAY_COUNT_16); + BIND_ENUM_CONSTANT(ENV_SDFGI_RAY_COUNT_32); + BIND_ENUM_CONSTANT(ENV_SDFGI_RAY_COUNT_64); + BIND_ENUM_CONSTANT(ENV_SDFGI_RAY_COUNT_96); + BIND_ENUM_CONSTANT(ENV_SDFGI_RAY_COUNT_128); + BIND_ENUM_CONSTANT(ENV_SDFGI_RAY_COUNT_MAX); + + BIND_ENUM_CONSTANT(ENV_SDFGI_CONVERGE_IN_5_FRAMES); + BIND_ENUM_CONSTANT(ENV_SDFGI_CONVERGE_IN_10_FRAMES); + BIND_ENUM_CONSTANT(ENV_SDFGI_CONVERGE_IN_15_FRAMES); + BIND_ENUM_CONSTANT(ENV_SDFGI_CONVERGE_IN_20_FRAMES); + BIND_ENUM_CONSTANT(ENV_SDFGI_CONVERGE_IN_25_FRAMES); + BIND_ENUM_CONSTANT(ENV_SDFGI_CONVERGE_IN_30_FRAMES); + BIND_ENUM_CONSTANT(ENV_SDFGI_CONVERGE_MAX); + + BIND_ENUM_CONSTANT(ENV_SDFGI_UPDATE_LIGHT_IN_1_FRAME); + BIND_ENUM_CONSTANT(ENV_SDFGI_UPDATE_LIGHT_IN_2_FRAMES); + BIND_ENUM_CONSTANT(ENV_SDFGI_UPDATE_LIGHT_IN_4_FRAMES); + BIND_ENUM_CONSTANT(ENV_SDFGI_UPDATE_LIGHT_IN_8_FRAMES); + BIND_ENUM_CONSTANT(ENV_SDFGI_UPDATE_LIGHT_IN_16_FRAMES); + BIND_ENUM_CONSTANT(ENV_SDFGI_UPDATE_LIGHT_MAX); + BIND_ENUM_CONSTANT(SUB_SURFACE_SCATTERING_QUALITY_DISABLED); BIND_ENUM_CONSTANT(SUB_SURFACE_SCATTERING_QUALITY_LOW); BIND_ENUM_CONSTANT(SUB_SURFACE_SCATTERING_QUALITY_MEDIUM); BIND_ENUM_CONSTANT(SUB_SURFACE_SCATTERING_QUALITY_HIGH); + /* CAMERA EFFECTS */ + + ClassDB::bind_method(D_METHOD("camera_effects_create"), &RenderingServer::camera_effects_create); + + ClassDB::bind_method(D_METHOD("camera_effects_set_dof_blur_quality", "quality", "use_jitter"), &RenderingServer::camera_effects_set_dof_blur_quality); + ClassDB::bind_method(D_METHOD("camera_effects_set_dof_blur_bokeh_shape", "shape"), &RenderingServer::camera_effects_set_dof_blur_bokeh_shape); + + ClassDB::bind_method(D_METHOD("camera_effects_set_dof_blur", "camera_effects", "far_enable", "far_distance", "far_transition", "near_enable", "near_distance", "near_transition", "amount"), &RenderingServer::camera_effects_set_dof_blur); + ClassDB::bind_method(D_METHOD("camera_effects_set_custom_exposure", "camera_effects", "enable", "exposure"), &RenderingServer::camera_effects_set_custom_exposure); + + BIND_ENUM_CONSTANT(DOF_BOKEH_BOX); + BIND_ENUM_CONSTANT(DOF_BOKEH_HEXAGON); + BIND_ENUM_CONSTANT(DOF_BOKEH_CIRCLE); + BIND_ENUM_CONSTANT(DOF_BLUR_QUALITY_VERY_LOW); BIND_ENUM_CONSTANT(DOF_BLUR_QUALITY_LOW); BIND_ENUM_CONSTANT(DOF_BLUR_QUALITY_MEDIUM); BIND_ENUM_CONSTANT(DOF_BLUR_QUALITY_HIGH); - BIND_ENUM_CONSTANT(DOF_BOKEH_BOX); - BIND_ENUM_CONSTANT(DOF_BOKEH_HEXAGON); - BIND_ENUM_CONSTANT(DOF_BOKEH_CIRCLE); + /* SCENARIO */ - BIND_ENUM_CONSTANT(SHADOW_QUALITY_HARD); - BIND_ENUM_CONSTANT(SHADOW_QUALITY_SOFT_LOW); - BIND_ENUM_CONSTANT(SHADOW_QUALITY_SOFT_MEDIUM); - BIND_ENUM_CONSTANT(SHADOW_QUALITY_SOFT_HIGH); - BIND_ENUM_CONSTANT(SHADOW_QUALITY_SOFT_ULTRA); - BIND_ENUM_CONSTANT(SHADOW_QUALITY_MAX); + ClassDB::bind_method(D_METHOD("scenario_create"), &RenderingServer::scenario_create); + ClassDB::bind_method(D_METHOD("scenario_set_environment", "scenario", "environment"), &RenderingServer::scenario_set_environment); + ClassDB::bind_method(D_METHOD("scenario_set_fallback_environment", "scenario", "environment"), &RenderingServer::scenario_set_fallback_environment); + ClassDB::bind_method(D_METHOD("scenario_set_camera_effects", "scenario", "effects"), &RenderingServer::scenario_set_camera_effects); - BIND_ENUM_CONSTANT(SCENARIO_DEBUG_DISABLED); - BIND_ENUM_CONSTANT(SCENARIO_DEBUG_WIREFRAME); - BIND_ENUM_CONSTANT(SCENARIO_DEBUG_OVERDRAW); - BIND_ENUM_CONSTANT(SCENARIO_DEBUG_SHADELESS); + /* INSTANCE */ - BIND_ENUM_CONSTANT(VIEWPORT_OCCLUSION_BUILD_QUALITY_LOW); - BIND_ENUM_CONSTANT(VIEWPORT_OCCLUSION_BUILD_QUALITY_MEDIUM); - BIND_ENUM_CONSTANT(VIEWPORT_OCCLUSION_BUILD_QUALITY_HIGH); + ClassDB::bind_method(D_METHOD("instance_create2", "base", "scenario"), &RenderingServer::instance_create2); + ClassDB::bind_method(D_METHOD("instance_create"), &RenderingServer::instance_create); + ClassDB::bind_method(D_METHOD("instance_set_base", "instance", "base"), &RenderingServer::instance_set_base); + ClassDB::bind_method(D_METHOD("instance_set_scenario", "instance", "scenario"), &RenderingServer::instance_set_scenario); + ClassDB::bind_method(D_METHOD("instance_set_layer_mask", "instance", "mask"), &RenderingServer::instance_set_layer_mask); + ClassDB::bind_method(D_METHOD("instance_set_transform", "instance", "transform"), &RenderingServer::instance_set_transform); + ClassDB::bind_method(D_METHOD("instance_attach_object_instance_id", "instance", "id"), &RenderingServer::instance_attach_object_instance_id); + ClassDB::bind_method(D_METHOD("instance_set_blend_shape_weight", "instance", "shape", "weight"), &RenderingServer::instance_set_blend_shape_weight); + ClassDB::bind_method(D_METHOD("instance_set_surface_override_material", "instance", "surface", "material"), &RenderingServer::instance_set_surface_override_material); + ClassDB::bind_method(D_METHOD("instance_set_visible", "instance", "visible"), &RenderingServer::instance_set_visible); + + ClassDB::bind_method(D_METHOD("instance_set_custom_aabb", "instance", "aabb"), &RenderingServer::instance_set_custom_aabb); + + ClassDB::bind_method(D_METHOD("instance_attach_skeleton", "instance", "skeleton"), &RenderingServer::instance_attach_skeleton); + ClassDB::bind_method(D_METHOD("instance_set_extra_visibility_margin", "instance", "margin"), &RenderingServer::instance_set_extra_visibility_margin); + ClassDB::bind_method(D_METHOD("instance_set_visibility_parent", "instance", "parent"), &RenderingServer::instance_set_visibility_parent); + + ClassDB::bind_method(D_METHOD("instance_geometry_set_flag", "instance", "flag", "enabled"), &RenderingServer::instance_geometry_set_flag); + ClassDB::bind_method(D_METHOD("instance_geometry_set_cast_shadows_setting", "instance", "shadow_casting_setting"), &RenderingServer::instance_geometry_set_cast_shadows_setting); + ClassDB::bind_method(D_METHOD("instance_geometry_set_material_override", "instance", "material"), &RenderingServer::instance_geometry_set_material_override); + ClassDB::bind_method(D_METHOD("instance_geometry_set_visibility_range", "instance", "min", "max", "min_margin", "max_margin"), &RenderingServer::instance_geometry_set_visibility_range); + ClassDB::bind_method(D_METHOD("instance_geometry_set_lightmap", "instance", "lightmap", "lightmap_uv_scale", "lightmap_slice"), &RenderingServer::instance_geometry_set_lightmap); + ClassDB::bind_method(D_METHOD("instance_geometry_set_lod_bias", "instance", "lod_bias"), &RenderingServer::instance_geometry_set_lod_bias); + + ClassDB::bind_method(D_METHOD("instance_geometry_set_shader_parameter", "instance", "parameter", "value"), &RenderingServer::instance_geometry_set_shader_parameter); + ClassDB::bind_method(D_METHOD("instance_geometry_get_shader_parameter", "instance", "parameter"), &RenderingServer::instance_geometry_get_shader_parameter); + ClassDB::bind_method(D_METHOD("instance_geometry_get_shader_parameter_default_value", "instance", "parameter"), &RenderingServer::instance_geometry_get_shader_parameter_default_value); + ClassDB::bind_method(D_METHOD("instance_geometry_get_shader_parameter_list", "instance"), &RenderingServer::_instance_geometry_get_shader_parameter_list); + + ClassDB::bind_method(D_METHOD("instances_cull_aabb", "aabb", "scenario"), &RenderingServer::_instances_cull_aabb_bind, DEFVAL(RID())); + ClassDB::bind_method(D_METHOD("instances_cull_ray", "from", "to", "scenario"), &RenderingServer::_instances_cull_ray_bind, DEFVAL(RID())); + ClassDB::bind_method(D_METHOD("instances_cull_convex", "convex", "scenario"), &RenderingServer::_instances_cull_convex_bind, DEFVAL(RID())); BIND_ENUM_CONSTANT(INSTANCE_NONE); BIND_ENUM_CONSTANT(INSTANCE_MESH); BIND_ENUM_CONSTANT(INSTANCE_MULTIMESH); - BIND_ENUM_CONSTANT(INSTANCE_IMMEDIATE); BIND_ENUM_CONSTANT(INSTANCE_PARTICLES); BIND_ENUM_CONSTANT(INSTANCE_PARTICLES_COLLISION); BIND_ENUM_CONSTANT(INSTANCE_LIGHT); @@ -2122,7 +2411,9 @@ void RenderingServer::_bind_methods() { BIND_ENUM_CONSTANT(INSTANCE_VOXEL_GI); BIND_ENUM_CONSTANT(INSTANCE_LIGHTMAP); BIND_ENUM_CONSTANT(INSTANCE_OCCLUDER); + BIND_ENUM_CONSTANT(INSTANCE_VISIBLITY_NOTIFIER); BIND_ENUM_CONSTANT(INSTANCE_MAX); + BIND_ENUM_CONSTANT(INSTANCE_GEOMETRY_MASK); BIND_ENUM_CONSTANT(INSTANCE_FLAG_USE_BAKED_LIGHT); @@ -2136,6 +2427,80 @@ void RenderingServer::_bind_methods() { BIND_ENUM_CONSTANT(SHADOW_CASTING_SETTING_DOUBLE_SIDED); BIND_ENUM_CONSTANT(SHADOW_CASTING_SETTING_SHADOWS_ONLY); + /* Bake 3D Object */ + + ClassDB::bind_method(D_METHOD("bake_render_uv2", "base", "material_overrides", "image_size"), &RenderingServer::bake_render_uv2); + + BIND_ENUM_CONSTANT(BAKE_CHANNEL_ALBEDO_ALPHA); + BIND_ENUM_CONSTANT(BAKE_CHANNEL_NORMAL); + BIND_ENUM_CONSTANT(BAKE_CHANNEL_ORM); + BIND_ENUM_CONSTANT(BAKE_CHANNEL_EMISSION); + + /* CANVAS (2D) */ + + ClassDB::bind_method(D_METHOD("canvas_create"), &RenderingServer::canvas_create); + ClassDB::bind_method(D_METHOD("canvas_set_item_mirroring", "canvas", "item", "mirroring"), &RenderingServer::canvas_set_item_mirroring); + ClassDB::bind_method(D_METHOD("canvas_set_modulate", "canvas", "color"), &RenderingServer::canvas_set_modulate); + ClassDB::bind_method(D_METHOD("canvas_set_disable_scale", "disable"), &RenderingServer::canvas_set_disable_scale); + + /* CANVAS TEXTURE */ + + ClassDB::bind_method(D_METHOD("canvas_texture_create"), &RenderingServer::canvas_texture_create); + ClassDB::bind_method(D_METHOD("canvas_texture_set_channel", "canvas_texture", "channel", "texture"), &RenderingServer::canvas_texture_set_channel); + ClassDB::bind_method(D_METHOD("canvas_texture_set_shading_parameters", "canvas_texture", "base_color", "shininess"), &RenderingServer::canvas_texture_set_shading_parameters); + + ClassDB::bind_method(D_METHOD("canvas_texture_set_texture_filter", "canvas_texture", "filter"), &RenderingServer::canvas_texture_set_texture_filter); + ClassDB::bind_method(D_METHOD("canvas_texture_set_texture_repeat", "canvas_texture", "repeat"), &RenderingServer::canvas_texture_set_texture_repeat); + + BIND_ENUM_CONSTANT(CANVAS_TEXTURE_CHANNEL_DIFFUSE); + BIND_ENUM_CONSTANT(CANVAS_TEXTURE_CHANNEL_NORMAL); + BIND_ENUM_CONSTANT(CANVAS_TEXTURE_CHANNEL_SPECULAR); + + /* CANVAS ITEM */ + + ClassDB::bind_method(D_METHOD("canvas_item_create"), &RenderingServer::canvas_item_create); + ClassDB::bind_method(D_METHOD("canvas_item_set_parent", "item", "parent"), &RenderingServer::canvas_item_set_parent); + ClassDB::bind_method(D_METHOD("canvas_item_set_default_texture_filter", "item", "filter"), &RenderingServer::canvas_item_set_default_texture_filter); + ClassDB::bind_method(D_METHOD("canvas_item_set_default_texture_repeat", "item", "repeat"), &RenderingServer::canvas_item_set_default_texture_repeat); + ClassDB::bind_method(D_METHOD("canvas_item_set_visible", "item", "visible"), &RenderingServer::canvas_item_set_visible); + ClassDB::bind_method(D_METHOD("canvas_item_set_light_mask", "item", "mask"), &RenderingServer::canvas_item_set_light_mask); + ClassDB::bind_method(D_METHOD("canvas_item_set_transform", "item", "transform"), &RenderingServer::canvas_item_set_transform); + ClassDB::bind_method(D_METHOD("canvas_item_set_clip", "item", "clip"), &RenderingServer::canvas_item_set_clip); + ClassDB::bind_method(D_METHOD("canvas_item_set_distance_field_mode", "item", "enabled"), &RenderingServer::canvas_item_set_distance_field_mode); + ClassDB::bind_method(D_METHOD("canvas_item_set_custom_rect", "item", "use_custom_rect", "rect"), &RenderingServer::canvas_item_set_custom_rect, DEFVAL(Rect2())); + ClassDB::bind_method(D_METHOD("canvas_item_set_modulate", "item", "color"), &RenderingServer::canvas_item_set_modulate); + ClassDB::bind_method(D_METHOD("canvas_item_set_self_modulate", "item", "color"), &RenderingServer::canvas_item_set_self_modulate); + ClassDB::bind_method(D_METHOD("canvas_item_set_draw_behind_parent", "item", "enabled"), &RenderingServer::canvas_item_set_draw_behind_parent); + //primitives + + ClassDB::bind_method(D_METHOD("canvas_item_add_line", "item", "from", "to", "color", "width"), &RenderingServer::canvas_item_add_line, DEFVAL(1.0)); + ClassDB::bind_method(D_METHOD("canvas_item_add_polyline", "item", "points", "colors", "width", "antialiased"), &RenderingServer::canvas_item_add_polyline, DEFVAL(1.0), DEFVAL(false)); + ClassDB::bind_method(D_METHOD("canvas_item_add_rect", "item", "rect", "color"), &RenderingServer::canvas_item_add_rect); + ClassDB::bind_method(D_METHOD("canvas_item_add_circle", "item", "pos", "radius", "color"), &RenderingServer::canvas_item_add_circle); + ClassDB::bind_method(D_METHOD("canvas_item_add_texture_rect", "item", "rect", "texture", "tile", "modulate", "transpose"), &RenderingServer::canvas_item_add_texture_rect, DEFVAL(false), DEFVAL(Color(1, 1, 1)), DEFVAL(false)); + ClassDB::bind_method(D_METHOD("canvas_item_add_texture_rect_region", "item", "rect", "texture", "src_rect", "modulate", "transpose", "clip_uv"), &RenderingServer::canvas_item_add_texture_rect_region, DEFVAL(Color(1, 1, 1)), DEFVAL(false), DEFVAL(true)); + ClassDB::bind_method(D_METHOD("canvas_item_add_nine_patch", "item", "rect", "source", "texture", "topleft", "bottomright", "x_axis_mode", "y_axis_mode", "draw_center", "modulate"), &RenderingServer::canvas_item_add_nine_patch, DEFVAL(NINE_PATCH_STRETCH), DEFVAL(NINE_PATCH_STRETCH), DEFVAL(true), DEFVAL(Color(1, 1, 1))); + ClassDB::bind_method(D_METHOD("canvas_item_add_primitive", "item", "points", "colors", "uvs", "texture", "width"), &RenderingServer::canvas_item_add_primitive, DEFVAL(1.0)); + ClassDB::bind_method(D_METHOD("canvas_item_add_polygon", "item", "points", "colors", "uvs", "texture"), &RenderingServer::canvas_item_add_polygon, DEFVAL(Vector<Point2>()), DEFVAL(RID())); + ClassDB::bind_method(D_METHOD("canvas_item_add_triangle_array", "item", "indices", "points", "colors", "uvs", "bones", "weights", "texture", "count"), &RenderingServer::canvas_item_add_triangle_array, DEFVAL(Vector<Point2>()), DEFVAL(Vector<int>()), DEFVAL(Vector<float>()), DEFVAL(RID()), DEFVAL(-1)); + ClassDB::bind_method(D_METHOD("canvas_item_add_mesh", "item", "mesh", "transform", "modulate", "texture"), &RenderingServer::canvas_item_add_mesh, DEFVAL(Transform2D()), DEFVAL(Color(1, 1, 1)), DEFVAL(RID())); + ClassDB::bind_method(D_METHOD("canvas_item_add_multimesh", "item", "mesh", "texture"), &RenderingServer::canvas_item_add_multimesh, DEFVAL(RID())); + ClassDB::bind_method(D_METHOD("canvas_item_add_particles", "item", "particles", "texture"), &RenderingServer::canvas_item_add_particles); + ClassDB::bind_method(D_METHOD("canvas_item_add_set_transform", "item", "transform"), &RenderingServer::canvas_item_add_set_transform); + ClassDB::bind_method(D_METHOD("canvas_item_add_clip_ignore", "item", "ignore"), &RenderingServer::canvas_item_add_clip_ignore); + ClassDB::bind_method(D_METHOD("canvas_item_set_sort_children_by_y", "item", "enabled"), &RenderingServer::canvas_item_set_sort_children_by_y); + ClassDB::bind_method(D_METHOD("canvas_item_set_z_index", "item", "z_index"), &RenderingServer::canvas_item_set_z_index); + ClassDB::bind_method(D_METHOD("canvas_item_set_z_as_relative_to_parent", "item", "enabled"), &RenderingServer::canvas_item_set_z_as_relative_to_parent); + ClassDB::bind_method(D_METHOD("canvas_item_set_copy_to_backbuffer", "item", "enabled", "rect"), &RenderingServer::canvas_item_set_copy_to_backbuffer); + + ClassDB::bind_method(D_METHOD("canvas_item_clear", "item"), &RenderingServer::canvas_item_clear); + ClassDB::bind_method(D_METHOD("canvas_item_set_draw_index", "item", "index"), &RenderingServer::canvas_item_set_draw_index); + ClassDB::bind_method(D_METHOD("canvas_item_set_material", "item", "material"), &RenderingServer::canvas_item_set_material); + ClassDB::bind_method(D_METHOD("canvas_item_set_use_parent_material", "item", "enabled"), &RenderingServer::canvas_item_set_use_parent_material); + + ClassDB::bind_method(D_METHOD("canvas_item_set_visibility_notifier", "item", "enable", "area", "enter_callable", "exit_callable"), &RenderingServer::canvas_item_set_visibility_notifier); + ClassDB::bind_method(D_METHOD("canvas_item_set_canvas_group_mode", "item", "mode", "clear_margin", "fit_empty", "fit_margin", "blur_mipmaps"), &RenderingServer::canvas_item_set_canvas_group_mode, DEFVAL(5.0), DEFVAL(false), DEFVAL(0.0), DEFVAL(false)); + BIND_ENUM_CONSTANT(NINE_PATCH_STRETCH); BIND_ENUM_CONSTANT(NINE_PATCH_TILE); BIND_ENUM_CONSTANT(NINE_PATCH_TILE_FIT); @@ -2159,6 +2524,28 @@ void RenderingServer::_bind_methods() { BIND_ENUM_CONSTANT(CANVAS_GROUP_MODE_OPAQUE); BIND_ENUM_CONSTANT(CANVAS_GROUP_MODE_TRANSPARENT); + /* CANVAS LIGHT */ + + ClassDB::bind_method(D_METHOD("canvas_light_create"), &RenderingServer::canvas_light_create); + ClassDB::bind_method(D_METHOD("canvas_light_attach_to_canvas", "light", "canvas"), &RenderingServer::canvas_light_attach_to_canvas); + ClassDB::bind_method(D_METHOD("canvas_light_set_enabled", "light", "enabled"), &RenderingServer::canvas_light_set_enabled); + ClassDB::bind_method(D_METHOD("canvas_light_set_texture_scale", "light", "scale"), &RenderingServer::canvas_light_set_texture_scale); + ClassDB::bind_method(D_METHOD("canvas_light_set_transform", "light", "transform"), &RenderingServer::canvas_light_set_transform); + ClassDB::bind_method(D_METHOD("canvas_light_set_texture", "light", "texture"), &RenderingServer::canvas_light_set_texture); + ClassDB::bind_method(D_METHOD("canvas_light_set_texture_offset", "light", "offset"), &RenderingServer::canvas_light_set_texture_offset); + ClassDB::bind_method(D_METHOD("canvas_light_set_color", "light", "color"), &RenderingServer::canvas_light_set_color); + ClassDB::bind_method(D_METHOD("canvas_light_set_height", "light", "height"), &RenderingServer::canvas_light_set_height); + ClassDB::bind_method(D_METHOD("canvas_light_set_energy", "light", "energy"), &RenderingServer::canvas_light_set_energy); + ClassDB::bind_method(D_METHOD("canvas_light_set_z_range", "light", "min_z", "max_z"), &RenderingServer::canvas_light_set_z_range); + ClassDB::bind_method(D_METHOD("canvas_light_set_layer_range", "light", "min_layer", "max_layer"), &RenderingServer::canvas_light_set_layer_range); + ClassDB::bind_method(D_METHOD("canvas_light_set_item_cull_mask", "light", "mask"), &RenderingServer::canvas_light_set_item_cull_mask); + ClassDB::bind_method(D_METHOD("canvas_light_set_item_shadow_cull_mask", "light", "mask"), &RenderingServer::canvas_light_set_item_shadow_cull_mask); + ClassDB::bind_method(D_METHOD("canvas_light_set_mode", "light", "mode"), &RenderingServer::canvas_light_set_mode); + ClassDB::bind_method(D_METHOD("canvas_light_set_shadow_enabled", "light", "enabled"), &RenderingServer::canvas_light_set_shadow_enabled); + ClassDB::bind_method(D_METHOD("canvas_light_set_shadow_filter", "light", "filter"), &RenderingServer::canvas_light_set_shadow_filter); + ClassDB::bind_method(D_METHOD("canvas_light_set_shadow_color", "light", "color"), &RenderingServer::canvas_light_set_shadow_color); + ClassDB::bind_method(D_METHOD("canvas_light_set_shadow_smooth", "light", "smooth"), &RenderingServer::canvas_light_set_shadow_smooth); + BIND_ENUM_CONSTANT(CANVAS_LIGHT_MODE_POINT); BIND_ENUM_CONSTANT(CANVAS_LIGHT_MODE_DIRECTIONAL); @@ -2171,10 +2558,38 @@ void RenderingServer::_bind_methods() { BIND_ENUM_CONSTANT(CANVAS_LIGHT_FILTER_PCF13); BIND_ENUM_CONSTANT(CANVAS_LIGHT_FILTER_MAX); + /* CANVAS OCCLUDER */ + + ClassDB::bind_method(D_METHOD("canvas_light_occluder_create"), &RenderingServer::canvas_light_occluder_create); + ClassDB::bind_method(D_METHOD("canvas_light_occluder_attach_to_canvas", "occluder", "canvas"), &RenderingServer::canvas_light_occluder_attach_to_canvas); + ClassDB::bind_method(D_METHOD("canvas_light_occluder_set_enabled", "occluder", "enabled"), &RenderingServer::canvas_light_occluder_set_enabled); + ClassDB::bind_method(D_METHOD("canvas_light_occluder_set_polygon", "occluder", "polygon"), &RenderingServer::canvas_light_occluder_set_polygon); + ClassDB::bind_method(D_METHOD("canvas_light_occluder_set_as_sdf_collision", "occluder", "enable"), &RenderingServer::canvas_light_occluder_set_as_sdf_collision); + ClassDB::bind_method(D_METHOD("canvas_light_occluder_set_transform", "occluder", "transform"), &RenderingServer::canvas_light_occluder_set_transform); + ClassDB::bind_method(D_METHOD("canvas_light_occluder_set_light_mask", "occluder", "mask"), &RenderingServer::canvas_light_occluder_set_light_mask); + + /* CANVAS LIGHT OCCLUDER POLYGON */ + + ClassDB::bind_method(D_METHOD("canvas_occluder_polygon_create"), &RenderingServer::canvas_occluder_polygon_create); + ClassDB::bind_method(D_METHOD("canvas_occluder_polygon_set_shape", "occluder_polygon", "shape", "closed"), &RenderingServer::canvas_occluder_polygon_set_shape); + ClassDB::bind_method(D_METHOD("canvas_occluder_polygon_set_cull_mode", "occluder_polygon", "mode"), &RenderingServer::canvas_occluder_polygon_set_cull_mode); + + ClassDB::bind_method(D_METHOD("canvas_set_shadow_texture_size", "size"), &RenderingServer::canvas_set_shadow_texture_size); + BIND_ENUM_CONSTANT(CANVAS_OCCLUDER_POLYGON_CULL_DISABLED); BIND_ENUM_CONSTANT(CANVAS_OCCLUDER_POLYGON_CULL_CLOCKWISE); BIND_ENUM_CONSTANT(CANVAS_OCCLUDER_POLYGON_CULL_COUNTER_CLOCKWISE); + /* GLOBAL VARIABLES */ + + ClassDB::bind_method(D_METHOD("global_variable_add", "name", "type", "default_value"), &RenderingServer::global_variable_add); + ClassDB::bind_method(D_METHOD("global_variable_remove", "name"), &RenderingServer::global_variable_remove); + ClassDB::bind_method(D_METHOD("global_variable_get_list"), &RenderingServer::global_variable_get_list); + ClassDB::bind_method(D_METHOD("global_variable_set", "name", "value"), &RenderingServer::global_variable_set); + ClassDB::bind_method(D_METHOD("global_variable_set_override", "name", "value"), &RenderingServer::global_variable_set_override); + ClassDB::bind_method(D_METHOD("global_variable_get", "name"), &RenderingServer::global_variable_get); + ClassDB::bind_method(D_METHOD("global_variable_get_type", "name"), &RenderingServer::global_variable_get_type); + BIND_ENUM_CONSTANT(GLOBAL_VAR_TYPE_BOOL); BIND_ENUM_CONSTANT(GLOBAL_VAR_TYPE_BVEC2); BIND_ENUM_CONSTANT(GLOBAL_VAR_TYPE_BVEC3); @@ -2205,22 +2620,53 @@ void RenderingServer::_bind_methods() { BIND_ENUM_CONSTANT(GLOBAL_VAR_TYPE_SAMPLERCUBE); BIND_ENUM_CONSTANT(GLOBAL_VAR_TYPE_MAX); - BIND_ENUM_CONSTANT(INFO_OBJECTS_IN_FRAME); - BIND_ENUM_CONSTANT(INFO_VERTICES_IN_FRAME); - BIND_ENUM_CONSTANT(INFO_MATERIAL_CHANGES_IN_FRAME); - BIND_ENUM_CONSTANT(INFO_SHADER_CHANGES_IN_FRAME); - BIND_ENUM_CONSTANT(INFO_SURFACE_CHANGES_IN_FRAME); - BIND_ENUM_CONSTANT(INFO_DRAW_CALLS_IN_FRAME); - BIND_ENUM_CONSTANT(INFO_USAGE_VIDEO_MEM_TOTAL); - BIND_ENUM_CONSTANT(INFO_VIDEO_MEM_USED); - BIND_ENUM_CONSTANT(INFO_TEXTURE_MEM_USED); - BIND_ENUM_CONSTANT(INFO_VERTEX_MEM_USED); + /* Free */ + ClassDB::bind_method(D_METHOD("free_rid", "rid"), &RenderingServer::free); // shouldn't conflict with Object::free() + + /* Misc */ + + ClassDB::bind_method(D_METHOD("request_frame_drawn_callback", "where", "method", "userdata"), &RenderingServer::request_frame_drawn_callback); + ClassDB::bind_method(D_METHOD("has_changed"), &RenderingServer::has_changed); + ClassDB::bind_method(D_METHOD("get_rendering_info", "info"), &RenderingServer::get_rendering_info); + ClassDB::bind_method(D_METHOD("get_video_adapter_name"), &RenderingServer::get_video_adapter_name); + ClassDB::bind_method(D_METHOD("get_video_adapter_vendor"), &RenderingServer::get_video_adapter_vendor); + + ClassDB::bind_method(D_METHOD("make_sphere_mesh", "latitudes", "longitudes", "radius"), &RenderingServer::make_sphere_mesh); + ClassDB::bind_method(D_METHOD("get_test_cube"), &RenderingServer::get_test_cube); + + ClassDB::bind_method(D_METHOD("get_test_texture"), &RenderingServer::get_test_texture); + ClassDB::bind_method(D_METHOD("get_white_texture"), &RenderingServer::get_white_texture); + + ClassDB::bind_method(D_METHOD("set_boot_image", "image", "color", "scale", "use_filter"), &RenderingServer::set_boot_image, DEFVAL(true)); + ClassDB::bind_method(D_METHOD("set_default_clear_color", "color"), &RenderingServer::set_default_clear_color); + + ClassDB::bind_method(D_METHOD("has_feature", "feature"), &RenderingServer::has_feature); + ClassDB::bind_method(D_METHOD("has_os_feature", "feature"), &RenderingServer::has_os_feature); + ClassDB::bind_method(D_METHOD("set_debug_generate_wireframes", "generate"), &RenderingServer::set_debug_generate_wireframes); + + ClassDB::bind_method(D_METHOD("is_render_loop_enabled"), &RenderingServer::is_render_loop_enabled); + ClassDB::bind_method(D_METHOD("set_render_loop_enabled", "enabled"), &RenderingServer::set_render_loop_enabled); + + ClassDB::bind_method(D_METHOD("get_frame_setup_time_cpu"), &RenderingServer::get_frame_setup_time_cpu); + + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "render_loop_enabled"), "set_render_loop_enabled", "is_render_loop_enabled"); + + BIND_ENUM_CONSTANT(RENDERING_INFO_TOTAL_OBJECTS_IN_FRAME); + BIND_ENUM_CONSTANT(RENDERING_INFO_TOTAL_PRIMITIVES_IN_FRAME); + BIND_ENUM_CONSTANT(RENDERING_INFO_TOTAL_DRAW_CALLS_IN_FRAME); + BIND_ENUM_CONSTANT(RENDERING_INFO_TEXTURE_MEM_USED); + BIND_ENUM_CONSTANT(RENDERING_INFO_BUFFER_MEM_USED); + BIND_ENUM_CONSTANT(RENDERING_INFO_VIDEO_MEM_USED); BIND_ENUM_CONSTANT(FEATURE_SHADERS); BIND_ENUM_CONSTANT(FEATURE_MULTITHREADED); ADD_SIGNAL(MethodInfo("frame_pre_draw")); ADD_SIGNAL(MethodInfo("frame_post_draw")); + + ClassDB::bind_method(D_METHOD("force_sync"), &RenderingServer::sync); + ClassDB::bind_method(D_METHOD("force_draw", "swap_buffers", "frame_step"), &RenderingServer::draw, DEFVAL(true), DEFVAL(0.0)); + ClassDB::bind_method(D_METHOD("create_local_rendering_device"), &RenderingServer::create_local_rendering_device); } void RenderingServer::mesh_add_surface_from_mesh_data(RID p_mesh, const Geometry3D::MeshData &p_mesh_data) { @@ -2253,10 +2699,6 @@ void RenderingServer::mesh_add_surface_from_planes(RID p_mesh, const Vector<Plan mesh_add_surface_from_mesh_data(p_mesh, mdata); } -void RenderingServer::immediate_vertex_2d(RID p_immediate, const Vector2 &p_vertex) { - immediate_vertex(p_immediate, Vector3(p_vertex.x, p_vertex.y, 0)); -} - RID RenderingServer::instance_create2(RID p_base, RID p_scenario) { RID instance = instance_create(); instance_set_base(instance, p_base); @@ -2330,7 +2772,6 @@ RenderingServer::RenderingServer() { GLOBAL_DEF("rendering/global_illumination/gi/use_half_resolution", false); - GLOBAL_DEF("rendering/global_illumination/voxel_gi/anisotropic", false); GLOBAL_DEF("rendering/global_illumination/voxel_gi/quality", 1); ProjectSettings::get_singleton()->set_custom_property_info("rendering/global_illumination/voxel_gi/quality", PropertyInfo(Variant::INT, "rendering/global_illumination/voxel_gi/quality", PROPERTY_HINT_ENUM, "Low (4 Cones - Fast),High (6 Cones - Slow)")); diff --git a/servers/rendering_server.h b/servers/rendering_server.h index 594e2d885c..0d01d4a2bd 100644 --- a/servers/rendering_server.h +++ b/servers/rendering_server.h @@ -103,7 +103,6 @@ public: virtual RID texture_3d_create(Image::Format, int p_width, int p_height, int p_depth, bool p_mipmaps, const Vector<Ref<Image>> &p_data) = 0; //all slices, then all the mipmaps, must be coherent virtual RID texture_proxy_create(RID p_base) = 0; - virtual void texture_2d_update_immediate(RID p_texture, const Ref<Image> &p_image, int p_layer = 0) = 0; //mostly used for video and streaming virtual void texture_2d_update(RID p_texture, const Ref<Image> &p_image, int p_layer = 0) = 0; virtual void texture_3d_update(RID p_texture, const Vector<Ref<Image>> &p_data) = 0; virtual void texture_proxy_update(RID p_texture, RID p_proxy_to) = 0; @@ -119,10 +118,6 @@ public: virtual void texture_replace(RID p_texture, RID p_by_texture) = 0; virtual void texture_set_size_override(RID p_texture, int p_width, int p_height) = 0; -// FIXME: Disabled during Vulkan refactoring, should be ported. -#if 0 - virtual void texture_bind(RID p_texture, uint32_t p_texture_no) = 0; -#endif virtual void texture_set_path(RID p_texture, const String &p_path) = 0; virtual String texture_get_path(RID p_texture) const = 0; @@ -173,7 +168,6 @@ public: virtual void shader_set_code(RID p_shader, const String &p_code) = 0; virtual String shader_get_code(RID p_shader) const = 0; virtual void shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const = 0; - Array _shader_get_param_list_bind(RID p_shader) const; virtual Variant shader_get_param_default(RID p_shader, const StringName &p_param) const = 0; virtual void shader_set_default_texture_param(RID p_shader, const StringName &p_name, RID p_texture) = 0; @@ -214,9 +208,9 @@ public: enum ArrayType { ARRAY_VERTEX = 0, // RG32F or RGB32F (depending on 2D bit) - ARRAY_NORMAL = 1, // A2B10G10R10 + ARRAY_NORMAL = 1, // A2B10G10R10, A is ignored ARRAY_TANGENT = 2, // A2B10G10R10, A flips sign of binormal - ARRAY_COLOR = 3, // RGBA16F + ARRAY_COLOR = 3, // RGBA8 ARRAY_TEX_UV = 4, // RG32F ARRAY_TEX_UV2 = 5, // RG32F ARRAY_CUSTOM0 = 6, // depends on ArrayCustomFormat @@ -342,7 +336,9 @@ public: virtual void mesh_set_blend_shape_mode(RID p_mesh, BlendShapeMode p_mode) = 0; virtual BlendShapeMode mesh_get_blend_shape_mode(RID p_mesh) const = 0; - virtual void mesh_surface_update_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) = 0; + virtual void mesh_surface_update_vertex_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) = 0; + virtual void mesh_surface_update_attribute_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) = 0; + virtual void mesh_surface_update_skin_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) = 0; virtual void mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material) = 0; virtual RID mesh_surface_get_material(RID p_mesh, int p_surface) const = 0; @@ -390,22 +386,6 @@ public: virtual void multimesh_set_visible_instances(RID p_multimesh, int p_visible) = 0; virtual int multimesh_get_visible_instances(RID p_multimesh) const = 0; - /* IMMEDIATE API */ - - virtual RID immediate_create() = 0; - virtual void immediate_begin(RID p_immediate, PrimitiveType p_rimitive, RID p_texture = RID()) = 0; - virtual void immediate_vertex(RID p_immediate, const Vector3 &p_vertex) = 0; - virtual void immediate_vertex_2d(RID p_immediate, const Vector2 &p_vertex); - virtual void immediate_normal(RID p_immediate, const Vector3 &p_normal) = 0; - virtual void immediate_tangent(RID p_immediate, const Plane &p_tangent) = 0; - virtual void immediate_color(RID p_immediate, const Color &p_color) = 0; - virtual void immediate_uv(RID p_immediate, const Vector2 &tex_uv) = 0; - virtual void immediate_uv2(RID p_immediate, const Vector2 &tex_uv) = 0; - virtual void immediate_end(RID p_immediate) = 0; - virtual void immediate_clear(RID p_immediate) = 0; - virtual void immediate_set_material(RID p_immediate, RID p_material) = 0; - virtual RID immediate_get_material(RID p_immediate) const = 0; - /* SKELETON API */ virtual RID skeleton_create() = 0; @@ -489,13 +469,19 @@ public: virtual void light_directional_set_blend_splits(RID p_light, bool p_enable) = 0; virtual void light_directional_set_sky_only(RID p_light, bool p_sky_only) = 0; - enum LightDirectionalShadowDepthRangeMode { - LIGHT_DIRECTIONAL_SHADOW_DEPTH_RANGE_STABLE, - LIGHT_DIRECTIONAL_SHADOW_DEPTH_RANGE_OPTIMIZED, - }; + virtual void directional_shadow_atlas_set_size(int p_size, bool p_16_bits = false) = 0; - virtual void light_directional_set_shadow_depth_range_mode(RID p_light, LightDirectionalShadowDepthRangeMode p_range_mode) = 0; + enum ShadowQuality { + SHADOW_QUALITY_HARD, + SHADOW_QUALITY_SOFT_LOW, + SHADOW_QUALITY_SOFT_MEDIUM, + SHADOW_QUALITY_SOFT_HIGH, + SHADOW_QUALITY_SOFT_ULTRA, + SHADOW_QUALITY_MAX + }; + virtual void shadows_quality_set(ShadowQuality p_quality) = 0; + virtual void directional_shadow_quality_set(ShadowQuality p_quality) = 0; /* PROBE API */ virtual RID reflection_probe_create() = 0; @@ -563,34 +549,12 @@ public: virtual Transform3D voxel_gi_get_to_cell_xform(RID p_voxel_gi) const = 0; virtual void voxel_gi_set_dynamic_range(RID p_voxel_gi, float p_range) = 0; - virtual float voxel_gi_get_dynamic_range(RID p_voxel_gi) const = 0; - virtual void voxel_gi_set_propagation(RID p_voxel_gi, float p_range) = 0; - virtual float voxel_gi_get_propagation(RID p_voxel_gi) const = 0; - virtual void voxel_gi_set_energy(RID p_voxel_gi, float p_energy) = 0; - virtual float voxel_gi_get_energy(RID p_voxel_gi) const = 0; - - virtual void voxel_gi_set_ao(RID p_voxel_gi, float p_ao) = 0; - virtual float voxel_gi_get_ao(RID p_voxel_gi) const = 0; - - virtual void voxel_gi_set_ao_size(RID p_voxel_gi, float p_strength) = 0; - virtual float voxel_gi_get_ao_size(RID p_voxel_gi) const = 0; - virtual void voxel_gi_set_bias(RID p_voxel_gi, float p_bias) = 0; - virtual float voxel_gi_get_bias(RID p_voxel_gi) const = 0; - virtual void voxel_gi_set_normal_bias(RID p_voxel_gi, float p_range) = 0; - virtual float voxel_gi_get_normal_bias(RID p_voxel_gi) const = 0; - virtual void voxel_gi_set_interior(RID p_voxel_gi, bool p_enable) = 0; - virtual bool voxel_gi_is_interior(RID p_voxel_gi) const = 0; - virtual void voxel_gi_set_use_two_bounces(RID p_voxel_gi, bool p_enable) = 0; - virtual bool voxel_gi_is_using_two_bounces(RID p_voxel_gi) const = 0; - - virtual void voxel_gi_set_anisotropy_strength(RID p_voxel_gi, float p_strength) = 0; - virtual float voxel_gi_get_anisotropy_strength(RID p_voxel_gi) const = 0; enum VoxelGIQuality { VOXEL_GI_QUALITY_LOW, @@ -745,7 +709,7 @@ public: virtual void camera_set_camera_effects(RID p_camera, RID p_camera_effects) = 0; virtual void camera_set_use_vertical_aspect(RID p_camera, bool p_enable) = 0; - /* VIEWPORT TARGET API */ + /* VIEWPORT API */ enum CanvasItemTextureFilter { CANVAS_ITEM_TEXTURE_FILTER_DEFAULT, //uses canvas item setting for draw command, uses global setting for canvas item @@ -796,9 +760,9 @@ public: virtual RID viewport_get_texture(RID p_viewport) const = 0; - virtual void viewport_set_hide_scenario(RID p_viewport, bool p_hide) = 0; - virtual void viewport_set_hide_canvas(RID p_viewport, bool p_hide) = 0; virtual void viewport_set_disable_environment(RID p_viewport, bool p_disable) = 0; + virtual void viewport_set_disable_3d(RID p_viewport, bool p_disable) = 0; + virtual void viewport_set_disable_2d(RID p_viewport, bool p_disable) = 0; virtual void viewport_attach_camera(RID p_viewport, RID p_camera) = 0; virtual void viewport_set_scenario(RID p_viewport, RID p_scenario) = 0; @@ -871,15 +835,18 @@ public: enum ViewportRenderInfo { VIEWPORT_RENDER_INFO_OBJECTS_IN_FRAME, - VIEWPORT_RENDER_INFO_VERTICES_IN_FRAME, - VIEWPORT_RENDER_INFO_MATERIAL_CHANGES_IN_FRAME, - VIEWPORT_RENDER_INFO_SHADER_CHANGES_IN_FRAME, - VIEWPORT_RENDER_INFO_SURFACE_CHANGES_IN_FRAME, + VIEWPORT_RENDER_INFO_PRIMITIVES_IN_FRAME, VIEWPORT_RENDER_INFO_DRAW_CALLS_IN_FRAME, VIEWPORT_RENDER_INFO_MAX, }; - virtual int viewport_get_render_info(RID p_viewport, ViewportRenderInfo p_info) = 0; + enum ViewportRenderInfoType { + VIEWPORT_RENDER_INFO_TYPE_VISIBLE, + VIEWPORT_RENDER_INFO_TYPE_SHADOW, + VIEWPORT_RENDER_INFO_TYPE_MAX + }; + + virtual int viewport_get_render_info(RID p_viewport, ViewportRenderInfoType p_type, ViewportRenderInfo p_info) = 0; enum ViewportDebugDraw { VIEWPORT_DEBUG_DRAW_DISABLED, @@ -914,8 +881,6 @@ public: virtual float viewport_get_measured_render_time_cpu(RID p_viewport) const = 0; virtual float viewport_get_measured_render_time_gpu(RID p_viewport) const = 0; - virtual void directional_shadow_atlas_set_size(int p_size, bool p_16_bits = false) = 0; - /* SKY API */ enum SkyMode { @@ -966,10 +931,6 @@ public: virtual void environment_set_bg_energy(RID p_env, float p_energy) = 0; virtual void environment_set_canvas_max_layer(RID p_env, int p_max_layer) = 0; virtual void environment_set_ambient_light(RID p_env, const Color &p_color, EnvironmentAmbientSource p_ambient = ENV_AMBIENT_SOURCE_BG, float p_energy = 1.0, float p_sky_contribution = 0.0, EnvironmentReflectionSource p_reflection_source = ENV_REFLECTION_SOURCE_BG, const Color &p_ao_color = Color()) = 0; -// FIXME: Disabled during Vulkan refactoring, should be ported. -#if 0 - virtual void environment_set_camera_feed_id(RID p_env, int p_camera_feed_id) = 0; -#endif enum EnvironmentGlowBlendMode { ENV_GLOW_BLEND_MODE_ADDITIVE, @@ -1111,30 +1072,10 @@ public: virtual void camera_effects_set_dof_blur(RID p_camera_effects, bool p_far_enable, float p_far_distance, float p_far_transition, bool p_near_enable, float p_near_distance, float p_near_transition, float p_amount) = 0; virtual void camera_effects_set_custom_exposure(RID p_camera_effects, bool p_enable, float p_exposure) = 0; - enum ShadowQuality { - SHADOW_QUALITY_HARD, - SHADOW_QUALITY_SOFT_LOW, - SHADOW_QUALITY_SOFT_MEDIUM, - SHADOW_QUALITY_SOFT_HIGH, - SHADOW_QUALITY_SOFT_ULTRA, - SHADOW_QUALITY_MAX - }; - - virtual void shadows_quality_set(ShadowQuality p_quality) = 0; - virtual void directional_shadow_quality_set(ShadowQuality p_quality) = 0; - /* SCENARIO API */ virtual RID scenario_create() = 0; - enum ScenarioDebugMode { - SCENARIO_DEBUG_DISABLED, - SCENARIO_DEBUG_WIREFRAME, - SCENARIO_DEBUG_OVERDRAW, - SCENARIO_DEBUG_SHADELESS, - }; - - virtual void scenario_set_debug(RID p_scenario, ScenarioDebugMode p_debug_mode) = 0; virtual void scenario_set_environment(RID p_scenario, RID p_environment) = 0; virtual void scenario_set_fallback_environment(RID p_scenario, RID p_environment) = 0; virtual void scenario_set_camera_effects(RID p_scenario, RID p_camera_effects) = 0; @@ -1145,7 +1086,6 @@ public: INSTANCE_NONE, INSTANCE_MESH, INSTANCE_MULTIMESH, - INSTANCE_IMMEDIATE, INSTANCE_PARTICLES, INSTANCE_PARTICLES_COLLISION, INSTANCE_LIGHT, @@ -1157,7 +1097,7 @@ public: INSTANCE_VISIBLITY_NOTIFIER, INSTANCE_MAX, - INSTANCE_GEOMETRY_MASK = (1 << INSTANCE_MESH) | (1 << INSTANCE_MULTIMESH) | (1 << INSTANCE_IMMEDIATE) | (1 << INSTANCE_PARTICLES) + INSTANCE_GEOMETRY_MASK = (1 << INSTANCE_MESH) | (1 << INSTANCE_MULTIMESH) | (1 << INSTANCE_PARTICLES) }; virtual RID instance_create2(RID p_base, RID p_scenario); @@ -1176,7 +1116,6 @@ public: virtual void instance_set_custom_aabb(RID p_instance, AABB aabb) = 0; virtual void instance_attach_skeleton(RID p_instance, RID p_skeleton) = 0; - virtual void instance_set_exterior(RID p_instance, bool p_enabled) = 0; virtual void instance_set_extra_visibility_margin(RID p_instance, real_t p_margin) = 0; virtual void instance_set_visibility_parent(RID p_instance, RID p_parent_instance) = 0; @@ -1208,7 +1147,6 @@ public: virtual void instance_geometry_set_flag(RID p_instance, InstanceFlags p_flags, bool p_enabled) = 0; virtual void instance_geometry_set_cast_shadows_setting(RID p_instance, ShadowCastingSetting p_shadow_casting_setting) = 0; virtual void instance_geometry_set_material_override(RID p_instance, RID p_material) = 0; - virtual void instance_geometry_set_visibility_range(RID p_instance, float p_min, float p_max, float p_min_margin, float p_max_margin) = 0; virtual void instance_geometry_set_lightmap(RID p_instance, RID p_lightmap, const Rect2 &p_lightmap_uv_scale, int p_lightmap_slice) = 0; virtual void instance_geometry_set_lod_bias(RID p_instance, float p_lod_bias) = 0; @@ -1238,6 +1176,7 @@ public: virtual void canvas_set_disable_scale(bool p_disable) = 0; + /* CANVAS TEXTURE */ virtual RID canvas_texture_create() = 0; enum CanvasTextureChannel { @@ -1252,6 +1191,8 @@ public: virtual void canvas_texture_set_texture_filter(RID p_canvas_texture, CanvasItemTextureFilter p_filter) = 0; virtual void canvas_texture_set_texture_repeat(RID p_canvas_texture, CanvasItemTextureRepeat p_repeat) = 0; + /* CANVAS ITEM */ + virtual RID canvas_item_create() = 0; virtual void canvas_item_set_parent(RID p_item, RID p_parent) = 0; @@ -1295,6 +1236,7 @@ public: virtual void canvas_item_add_set_transform(RID p_item, const Transform2D &p_transform) = 0; virtual void canvas_item_add_clip_ignore(RID p_item, bool p_ignore) = 0; virtual void canvas_item_add_animation_slice(RID p_item, double p_animation_length, double p_slice_begin, double p_slice_end, double p_offset) = 0; + virtual void canvas_item_set_sort_children_by_y(RID p_item, bool p_enable) = 0; virtual void canvas_item_set_z_index(RID p_item, int p_z) = 0; virtual void canvas_item_set_z_as_relative_to_parent(RID p_item, bool p_enable) = 0; @@ -1319,6 +1261,7 @@ public: virtual void canvas_item_set_canvas_group_mode(RID p_item, CanvasGroupMode p_mode, float p_clear_margin = 5.0, bool p_fit_empty = false, float p_fit_margin = 0.0, bool p_blur_mipmaps = false) = 0; + /* CANVAS LIGHT */ virtual RID canvas_light_create() = 0; enum CanvasLightMode { @@ -1365,6 +1308,8 @@ public: virtual void canvas_light_set_shadow_color(RID p_light, const Color &p_color) = 0; virtual void canvas_light_set_shadow_smooth(RID p_light, float p_smooth) = 0; + /* CANVAS LIGHT OCCLUDER */ + virtual RID canvas_light_occluder_create() = 0; virtual void canvas_light_occluder_attach_to_canvas(RID p_occluder, RID p_canvas) = 0; virtual void canvas_light_occluder_set_enabled(RID p_occluder, bool p_enabled) = 0; @@ -1373,6 +1318,8 @@ public: virtual void canvas_light_occluder_set_transform(RID p_occluder, const Transform2D &p_xform) = 0; virtual void canvas_light_occluder_set_light_mask(RID p_occluder, int p_mask) = 0; + /* CANVAS LIGHT OCCLUDER POLYGON */ + virtual RID canvas_occluder_polygon_create() = 0; virtual void canvas_occluder_polygon_set_shape(RID p_occluder_polygon, const Vector<Vector2> &p_shape, bool p_closed) = 0; @@ -1435,11 +1382,6 @@ public: static ShaderLanguage::DataType global_variable_type_get_shader_datatype(GlobalVariableType p_type); - /* BLACK BARS */ - - virtual void black_bars_set_margins(int p_left, int p_top, int p_right, int p_bottom) = 0; - virtual void black_bars_set_images(RID p_left, RID p_top, RID p_right, RID p_bottom) = 0; - /* FREE */ virtual void free(RID p_rid) = 0; ///< free RIDs associated with the visual server @@ -1456,20 +1398,17 @@ public: /* STATUS INFORMATION */ - enum RenderInfo { - INFO_OBJECTS_IN_FRAME, - INFO_VERTICES_IN_FRAME, - INFO_MATERIAL_CHANGES_IN_FRAME, - INFO_SHADER_CHANGES_IN_FRAME, - INFO_SURFACE_CHANGES_IN_FRAME, - INFO_DRAW_CALLS_IN_FRAME, - INFO_USAGE_VIDEO_MEM_TOTAL, - INFO_VIDEO_MEM_USED, - INFO_TEXTURE_MEM_USED, - INFO_VERTEX_MEM_USED, + enum RenderingInfo { + RENDERING_INFO_TOTAL_OBJECTS_IN_FRAME, + RENDERING_INFO_TOTAL_PRIMITIVES_IN_FRAME, + RENDERING_INFO_TOTAL_DRAW_CALLS_IN_FRAME, + RENDERING_INFO_TEXTURE_MEM_USED, + RENDERING_INFO_BUFFER_MEM_USED, + RENDERING_INFO_VIDEO_MEM_USED, + RENDERING_INFO_MAX }; - virtual uint64_t get_render_info(RenderInfo p_info) = 0; + virtual uint64_t get_rendering_info(RenderingInfo p_info) = 0; virtual String get_video_adapter_name() const = 0; virtual String get_video_adapter_vendor() const = 0; @@ -1515,7 +1454,7 @@ public: virtual void set_debug_generate_wireframes(bool p_generate) = 0; - virtual void call_set_use_vsync(bool p_enable) = 0; + virtual void call_set_vsync_mode(DisplayServer::VSyncMode p_mode, DisplayServer::WindowID p_window) = 0; virtual bool is_low_end() const = 0; @@ -1528,6 +1467,20 @@ public: RenderingServer(); virtual ~RenderingServer(); + +private: + //binder helpers + RID _texture_2d_layered_create(const TypedArray<Image> &p_layers, TextureLayeredType p_layered_type); + RID _texture_3d_create(Image::Format p_format, int p_width, int p_height, int p_depth, bool p_mipmaps, const TypedArray<Image> &p_data); + void _texture_3d_update(RID p_texture, const TypedArray<Image> &p_data); + TypedArray<Image> _texture_3d_get(RID p_texture) const; + TypedArray<Dictionary> _shader_get_param_list(RID p_shader) const; + RID _mesh_create_from_surfaces(const TypedArray<Dictionary> &p_surfaces, int p_blend_shape_count); + void _mesh_add_surface(RID p_mesh, const Dictionary &p_surface); + Dictionary _mesh_get_surface(RID p_mesh, int p_idx); + Array _instance_geometry_get_shader_parameter_list(RID p_instance) const; + TypedArray<Image> _bake_render_uv2(RID p_base, const TypedArray<RID> &p_material_overrides, const Size2i &p_image_size); + void _particles_set_trail_bind_poses(RID p_particles, const TypedArray<Transform3D> &p_bind_poses); }; // make variant understand the enums @@ -1536,6 +1489,7 @@ VARIANT_ENUM_CAST(RenderingServer::CubeMapLayer); VARIANT_ENUM_CAST(RenderingServer::ShaderMode); VARIANT_ENUM_CAST(RenderingServer::ArrayType); VARIANT_ENUM_CAST(RenderingServer::ArrayFormat); +VARIANT_ENUM_CAST(RenderingServer::ArrayCustomFormat); VARIANT_ENUM_CAST(RenderingServer::PrimitiveType); VARIANT_ENUM_CAST(RenderingServer::BlendShapeMode); VARIANT_ENUM_CAST(RenderingServer::MultimeshTransformFormat); @@ -1544,18 +1498,26 @@ VARIANT_ENUM_CAST(RenderingServer::LightParam); VARIANT_ENUM_CAST(RenderingServer::LightBakeMode); VARIANT_ENUM_CAST(RenderingServer::LightOmniShadowMode); VARIANT_ENUM_CAST(RenderingServer::LightDirectionalShadowMode); -VARIANT_ENUM_CAST(RenderingServer::LightDirectionalShadowDepthRangeMode); VARIANT_ENUM_CAST(RenderingServer::ReflectionProbeUpdateMode); VARIANT_ENUM_CAST(RenderingServer::ReflectionProbeAmbientMode); +VARIANT_ENUM_CAST(RenderingServer::VoxelGIQuality); VARIANT_ENUM_CAST(RenderingServer::DecalTexture); +VARIANT_ENUM_CAST(RenderingServer::ParticlesMode); +VARIANT_ENUM_CAST(RenderingServer::ParticlesTransformAlign); VARIANT_ENUM_CAST(RenderingServer::ParticlesDrawOrder); +VARIANT_ENUM_CAST(RenderingServer::ParticlesEmitFlags); +VARIANT_ENUM_CAST(RenderingServer::ParticlesCollisionType); +VARIANT_ENUM_CAST(RenderingServer::ParticlesCollisionHeightfieldResolution); VARIANT_ENUM_CAST(RenderingServer::ViewportUpdateMode); VARIANT_ENUM_CAST(RenderingServer::ViewportClearMode); VARIANT_ENUM_CAST(RenderingServer::ViewportMSAA); VARIANT_ENUM_CAST(RenderingServer::ViewportScreenSpaceAA); VARIANT_ENUM_CAST(RenderingServer::ViewportRenderInfo); +VARIANT_ENUM_CAST(RenderingServer::ViewportRenderInfoType); VARIANT_ENUM_CAST(RenderingServer::ViewportDebugDraw); VARIANT_ENUM_CAST(RenderingServer::ViewportOcclusionCullingBuildQuality); +VARIANT_ENUM_CAST(RenderingServer::ViewportSDFOversize); +VARIANT_ENUM_CAST(RenderingServer::ViewportSDFScale); VARIANT_ENUM_CAST(RenderingServer::SkyMode); VARIANT_ENUM_CAST(RenderingServer::EnvironmentBG); VARIANT_ENUM_CAST(RenderingServer::EnvironmentAmbientSource); @@ -1564,11 +1526,15 @@ VARIANT_ENUM_CAST(RenderingServer::EnvironmentGlowBlendMode); VARIANT_ENUM_CAST(RenderingServer::EnvironmentToneMapper); VARIANT_ENUM_CAST(RenderingServer::EnvironmentSSRRoughnessQuality); VARIANT_ENUM_CAST(RenderingServer::EnvironmentSSAOQuality); +VARIANT_ENUM_CAST(RenderingServer::EnvironmentSDFGICascades); +VARIANT_ENUM_CAST(RenderingServer::EnvironmentSDFGIFramesToConverge); +VARIANT_ENUM_CAST(RenderingServer::EnvironmentSDFGIRayCount); +VARIANT_ENUM_CAST(RenderingServer::EnvironmentSDFGIFramesToUpdateLight); +VARIANT_ENUM_CAST(RenderingServer::EnvironmentSDFGIYScale); VARIANT_ENUM_CAST(RenderingServer::SubSurfaceScatteringQuality); VARIANT_ENUM_CAST(RenderingServer::DOFBlurQuality); VARIANT_ENUM_CAST(RenderingServer::DOFBokehShape); VARIANT_ENUM_CAST(RenderingServer::ShadowQuality); -VARIANT_ENUM_CAST(RenderingServer::ScenarioDebugMode); VARIANT_ENUM_CAST(RenderingServer::InstanceType); VARIANT_ENUM_CAST(RenderingServer::InstanceFlags); VARIANT_ENUM_CAST(RenderingServer::ShadowCastingSetting); @@ -1581,8 +1547,10 @@ VARIANT_ENUM_CAST(RenderingServer::CanvasLightBlendMode); VARIANT_ENUM_CAST(RenderingServer::CanvasLightShadowFilter); VARIANT_ENUM_CAST(RenderingServer::CanvasOccluderPolygonCullMode); VARIANT_ENUM_CAST(RenderingServer::GlobalVariableType); -VARIANT_ENUM_CAST(RenderingServer::RenderInfo); +VARIANT_ENUM_CAST(RenderingServer::RenderingInfo); VARIANT_ENUM_CAST(RenderingServer::Features); +VARIANT_ENUM_CAST(RenderingServer::CanvasTextureChannel); +VARIANT_ENUM_CAST(RenderingServer::BakeChannels); // Alias to make it easier to use. #define RS RenderingServer diff --git a/servers/text_server.cpp b/servers/text_server.cpp index daed612b02..6f48148cab 100644 --- a/servers/text_server.cpp +++ b/servers/text_server.cpp @@ -466,16 +466,16 @@ void TextServer::initialize_hex_code_box_fonts() { Vector<uint8_t> hex_box_data; Ref<Image> image; - image.instance(); + image.instantiate(); Ref<ImageTexture> hex_code_image_tex[2]; hex_box_data.resize(tamsyn5x9_png_len); memcpy(hex_box_data.ptrw(), tamsyn5x9_png, tamsyn5x9_png_len); image->load_png_from_buffer(hex_box_data); - hex_code_image_tex[0].instance(); + hex_code_image_tex[0].instantiate(); hex_code_image_tex[0]->create_from_image(image); - hex_code_box_font_tex[0].instance(); + hex_code_box_font_tex[0].instantiate(); hex_code_box_font_tex[0]->set_diffuse_texture(hex_code_image_tex[0]); hex_code_box_font_tex[0]->set_texture_filter(CanvasItem::TEXTURE_FILTER_NEAREST); hex_box_data.clear(); @@ -483,9 +483,9 @@ void TextServer::initialize_hex_code_box_fonts() { hex_box_data.resize(tamsyn10x20_png_len); memcpy(hex_box_data.ptrw(), tamsyn10x20_png, tamsyn10x20_png_len); image->load_png_from_buffer(hex_box_data); - hex_code_image_tex[1].instance(); + hex_code_image_tex[1].instantiate(); hex_code_image_tex[1]->create_from_image(image); - hex_code_box_font_tex[1].instance(); + hex_code_box_font_tex[1].instantiate(); hex_code_box_font_tex[1]->set_diffuse_texture(hex_code_image_tex[1]); hex_code_box_font_tex[1]->set_texture_filter(CanvasItem::TEXTURE_FILTER_NEAREST); hex_box_data.clear(); diff --git a/tests/test_aabb.h b/tests/test_aabb.h index 39e3c6e45b..c4daa56e5a 100644 --- a/tests/test_aabb.h +++ b/tests/test_aabb.h @@ -278,24 +278,24 @@ TEST_CASE("[AABB] Get endpoints") { TEST_CASE("[AABB] Get longest/shortest axis") { const AABB aabb = AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 5, 6)); CHECK_MESSAGE( - aabb.get_longest_axis().is_equal_approx(Vector3(0, 0, 1)), + aabb.get_longest_axis() == Vector3(0, 0, 1), "get_longest_axis() should return the expected value."); CHECK_MESSAGE( aabb.get_longest_axis_index() == Vector3::AXIS_Z, - "get_longest_axis() should return the expected value."); + "get_longest_axis_index() should return the expected value."); CHECK_MESSAGE( - Math::is_equal_approx(aabb.get_longest_axis_size(), 6), - "get_longest_axis() should return the expected value."); + aabb.get_longest_axis_size() == 6, + "get_longest_axis_size() should return the expected value."); CHECK_MESSAGE( - aabb.get_shortest_axis().is_equal_approx(Vector3(1, 0, 0)), + aabb.get_shortest_axis() == Vector3(1, 0, 0), "get_shortest_axis() should return the expected value."); CHECK_MESSAGE( aabb.get_shortest_axis_index() == Vector3::AXIS_X, - "get_shortest_axis() should return the expected value."); + "get_shortest_axis_index() should return the expected value."); CHECK_MESSAGE( - Math::is_equal_approx(aabb.get_shortest_axis_size(), 4), - "get_shortest_axis() should return the expected value."); + aabb.get_shortest_axis_size() == 4, + "get_shortest_axis_size() should return the expected value."); } #ifndef _MSC_VER diff --git a/tests/test_class_db.h b/tests/test_class_db.h index 75785fa5ed..29edf5a4a0 100644 --- a/tests/test_class_db.h +++ b/tests/test_class_db.h @@ -754,6 +754,9 @@ void add_exposed_classes(Context &r_context) { const List<StringName> &enum_constants = enum_map.get(*k); for (const List<StringName>::Element *E = enum_constants.front(); E; E = E->next()) { const StringName &constant_name = E->get(); + TEST_FAIL_COND(String(constant_name).find("::") != -1, + "Enum constant contains '::', check bindings to remove the scope: '", + String(class_name), ".", String(enum_.name), ".", String(constant_name), "'."); int *value = class_info->constant_map.getptr(constant_name); TEST_FAIL_COND(!value, "Missing enum constant value: '", String(class_name), ".", String(enum_.name), ".", String(constant_name), "'."); @@ -773,8 +776,11 @@ void add_exposed_classes(Context &r_context) { for (const List<String>::Element *E = constants.front(); E; E = E->next()) { const String &constant_name = E->get(); + TEST_FAIL_COND(constant_name.find("::") != -1, + "Constant contains '::', check bindings to remove the scope: '", + String(class_name), ".", constant_name, "'."); int *value = class_info->constant_map.getptr(StringName(E->get())); - TEST_FAIL_COND(!value, "Missing enum constant value: '", String(class_name), ".", String(constant_name), "'."); + TEST_FAIL_COND(!value, "Missing constant value: '", String(class_name), ".", String(constant_name), "'."); ConstantData constant; constant.name = constant_name; diff --git a/tests/test_curve.h b/tests/test_curve.h index 3055cfd97b..7eeee86f32 100644 --- a/tests/test_curve.h +++ b/tests/test_curve.h @@ -80,7 +80,7 @@ TEST_CASE("[Curve] Custom curve with free tangents") { "Custom free curve should contain the expected number of points."); CHECK_MESSAGE( - Math::is_equal_approx(curve->interpolate(-0.1), 0), + Math::is_zero_approx(curve->interpolate(-0.1)), "Custom free curve should return the expected value at offset 0.1."); CHECK_MESSAGE( Math::is_equal_approx(curve->interpolate(0.1), (real_t)0.352), @@ -99,7 +99,7 @@ TEST_CASE("[Curve] Custom curve with free tangents") { "Custom free curve should return the expected value at offset 0.1."); CHECK_MESSAGE( - Math::is_equal_approx(curve->interpolate_baked(-0.1), 0), + Math::is_zero_approx(curve->interpolate_baked(-0.1)), "Custom free curve should return the expected baked value at offset 0.1."); CHECK_MESSAGE( Math::is_equal_approx(curve->interpolate_baked(0.1), (real_t)0.352), @@ -169,7 +169,7 @@ TEST_CASE("[Curve] Custom curve with linear tangents") { "Custom linear curve should contain the expected number of points."); CHECK_MESSAGE( - Math::is_equal_approx(curve->interpolate(-0.1), 0), + Math::is_zero_approx(curve->interpolate(-0.1)), "Custom linear curve should return the expected value at offset -0.1."); CHECK_MESSAGE( Math::is_equal_approx(curve->interpolate(0.1), (real_t)0.4), @@ -188,7 +188,7 @@ TEST_CASE("[Curve] Custom curve with linear tangents") { "Custom linear curve should return the expected value at offset 2.0."); CHECK_MESSAGE( - Math::is_equal_approx(curve->interpolate_baked(-0.1), 0), + Math::is_zero_approx(curve->interpolate_baked(-0.1)), "Custom linear curve should return the expected baked value at offset -0.1."); CHECK_MESSAGE( Math::is_equal_approx(curve->interpolate_baked(0.1), (real_t)0.4), diff --git a/tests/test_json.h b/tests/test_json.h index f1cb4799dc..3af58dfa1c 100644 --- a/tests/test_json.h +++ b/tests/test_json.h @@ -45,75 +45,65 @@ TEST_CASE("[JSON] Parsing single data types") { // Parsing a single data type as JSON is valid per the JSON specification. JSON json; - Variant result; - String err_str; - int err_line; - json.parse("null", result, err_str, err_line); + json.parse("null"); CHECK_MESSAGE( - err_line == 0, + json.get_error_line() == 0, "Parsing `null` as JSON should parse successfully."); CHECK_MESSAGE( - result == Variant(), + json.get_data() == Variant(), "Parsing a double quoted string as JSON should return the expected value."); - json.parse("true", result, err_str, err_line); + json.parse("true"); CHECK_MESSAGE( - err_line == 0, + json.get_error_line() == 0, "Parsing boolean `true` as JSON should parse successfully."); CHECK_MESSAGE( - result, + json.get_data(), "Parsing boolean `true` as JSON should return the expected value."); - json.parse("false", result, err_str, err_line); + json.parse("false"); CHECK_MESSAGE( - err_line == 0, + json.get_error_line() == 0, "Parsing boolean `false` as JSON should parse successfully."); CHECK_MESSAGE( - !result, + !json.get_data(), "Parsing boolean `false` as JSON should return the expected value."); - // JSON only has a floating-point number type, no integer type. - // This is why we use `is_equal_approx()` for the comparison. - json.parse("123456", result, err_str, err_line); + json.parse("123456"); CHECK_MESSAGE( - err_line == 0, + json.get_error_line() == 0, "Parsing an integer number as JSON should parse successfully."); CHECK_MESSAGE( - (int)result == 123'456, + (int)(json.get_data()) == 123456, "Parsing an integer number as JSON should return the expected value."); - json.parse("0.123456", result, err_str, err_line); + json.parse("0.123456"); CHECK_MESSAGE( - err_line == 0, + json.get_error_line() == 0, "Parsing a floating-point number as JSON should parse successfully."); CHECK_MESSAGE( - Math::is_equal_approx(result, 0.123456), + Math::is_equal_approx(double(json.get_data()), 0.123456), "Parsing a floating-point number as JSON should return the expected value."); - json.parse("\"hello\"", result, err_str, err_line); + json.parse("\"hello\""); CHECK_MESSAGE( - err_line == 0, + json.get_error_line() == 0, "Parsing a double quoted string as JSON should parse successfully."); CHECK_MESSAGE( - result == "hello", + json.get_data() == "hello", "Parsing a double quoted string as JSON should return the expected value."); } TEST_CASE("[JSON] Parsing arrays") { JSON json; - Variant result; - String err_str; - int err_line; // JSON parsing fails if it's split over several lines (even if leading indentation is removed). - json.parse( - R"(["Hello", "world.", "This is",["a","json","array.",[]], "Empty arrays ahoy:", [[["Gotcha!"]]]])", - result, err_str, err_line); + json.parse(R"(["Hello", "world.", "This is",["a","json","array.",[]], "Empty arrays ahoy:", [[["Gotcha!"]]]])"); - const Array array = result; + const Array array = json.get_data(); CHECK_MESSAGE( - err_line == 0, + json.get_error_line() == 0, "Parsing a JSON array should parse successfully."); CHECK_MESSAGE( array[0] == "Hello", @@ -136,15 +126,10 @@ TEST_CASE("[JSON] Parsing arrays") { TEST_CASE("[JSON] Parsing objects (dictionaries)") { JSON json; - Variant result; - String err_str; - int err_line; - json.parse( - R"({"name": "Godot Engine", "is_free": true, "bugs": null, "apples": {"red": 500, "green": 0, "blue": -20}, "empty_object": {}})", - result, err_str, err_line); + json.parse(R"({"name": "Godot Engine", "is_free": true, "bugs": null, "apples": {"red": 500, "green": 0, "blue": -20}, "empty_object": {}})"); - const Dictionary dictionary = result; + const Dictionary dictionary = json.get_data(); CHECK_MESSAGE( dictionary["name"] == "Godot Engine", "The parsed JSON should contain the expected values."); diff --git a/thirdparty/README.md b/thirdparty/README.md index 03a2ddf5e4..31e88180d0 100644 --- a/thirdparty/README.md +++ b/thirdparty/README.md @@ -616,6 +616,11 @@ Files extracted from upstream source: - `include` folder - `LICENSE` +Some downstream changes have been made and are identified by +`// -- GODOT begin --` and `// -- GODOT end --` comments. +They can be reapplied using the patch included in the `patches` +folder. + ## squish diff --git a/thirdparty/enet/godot.cpp b/thirdparty/enet/godot.cpp index fd7968204b..f6a56f1f5d 100644 --- a/thirdparty/enet/godot.cpp +++ b/thirdparty/enet/godot.cpp @@ -164,7 +164,7 @@ public: verify = p_verify; for_hostname = p_for_hostname; cert = p_cert; - udp.instance(); + udp.instantiate(); dtls = Ref<PacketPeerDTLS>(PacketPeerDTLS::create()); if (p_base->bound) { uint16_t port; @@ -254,7 +254,7 @@ class ENetDTLSServer : public ENetGodotSocket { public: ENetDTLSServer(ENetUDP *p_base, Ref<CryptoKey> p_key, Ref<X509Certificate> p_cert) { - udp_server.instance(); + udp_server.instantiate(); if (p_base->bound) { uint16_t port; p_base->get_socket_address(&local_address, &port); diff --git a/thirdparty/misc/easing_equations.cpp b/thirdparty/misc/easing_equations.cpp index af48aaf079..ce32c1a362 100644 --- a/thirdparty/misc/easing_equations.cpp +++ b/thirdparty/misc/easing_equations.cpp @@ -297,7 +297,7 @@ static real_t out_in(real_t t, real_t b, real_t c, real_t d) { } }; // namespace back -Tween::interpolater Tween::interpolaters[Tween::TRANS_COUNT][Tween::EASE_COUNT] = { +Tween::interpolater Tween::interpolaters[Tween::TRANS_MAX][Tween::EASE_MAX] = { { &linear::in, &linear::out, &linear::in_out, &linear::out_in }, { &sine::in, &sine::out, &sine::in_out, &sine::out_in }, { &quint::in, &quint::out, &quint::in_out, &quint::out_in }, @@ -311,7 +311,7 @@ Tween::interpolater Tween::interpolaters[Tween::TRANS_COUNT][Tween::EASE_COUNT] { &back::in, &back::out, &back::in_out, &back::out_in }, }; -real_t Tween::_run_equation(TransitionType p_trans_type, EaseType p_ease_type, real_t t, real_t b, real_t c, real_t d) { +real_t Tween::run_equation(TransitionType p_trans_type, EaseType p_ease_type, real_t t, real_t b, real_t c, real_t d) { interpolater cb = interpolaters[p_trans_type][p_ease_type]; ERR_FAIL_COND_V(cb == NULL, b); diff --git a/thirdparty/spirv-reflect/patches/specialization-constants.patch b/thirdparty/spirv-reflect/patches/specialization-constants.patch new file mode 100644 index 0000000000..8ff1dcc2e5 --- /dev/null +++ b/thirdparty/spirv-reflect/patches/specialization-constants.patch @@ -0,0 +1,293 @@ +diff --git a/thirdparty/spirv-reflect/spirv_reflect.c b/thirdparty/spirv-reflect/spirv_reflect.c +index 0fc979a8a4..3e3643717a 100644 +--- a/thirdparty/spirv-reflect/spirv_reflect.c ++++ b/thirdparty/spirv-reflect/spirv_reflect.c +@@ -124,6 +124,9 @@ typedef struct Decorations { + NumberDecoration location; + NumberDecoration offset; + NumberDecoration uav_counter_buffer; ++// -- GODOT begin -- ++ NumberDecoration specialization_constant; ++// -- GODOT end -- + StringDecoration semantic; + uint32_t array_stride; + uint32_t matrix_stride; +@@ -610,6 +613,9 @@ static SpvReflectResult ParseNodes(Parser* p_parser) + p_parser->nodes[i].decorations.offset.value = (uint32_t)INVALID_VALUE; + p_parser->nodes[i].decorations.uav_counter_buffer.value = (uint32_t)INVALID_VALUE; + p_parser->nodes[i].decorations.built_in = (SpvBuiltIn)INVALID_VALUE; ++// -- GODOT begin -- ++ p_parser->nodes[i].decorations.specialization_constant.value = (SpvBuiltIn)INVALID_VALUE; ++// -- GODOT end -- + } + // Mark source file id node + p_parser->source_file_id = (uint32_t)INVALID_VALUE; +@@ -800,10 +806,16 @@ static SpvReflectResult ParseNodes(Parser* p_parser) + CHECKED_READU32(p_parser, p_node->word_offset + 2, p_node->result_id); + } + break; +- ++// -- GODOT begin -- + case SpvOpSpecConstantTrue: + case SpvOpSpecConstantFalse: +- case SpvOpSpecConstant: ++ case SpvOpSpecConstant: { ++ CHECKED_READU32(p_parser, p_node->word_offset + 1, p_node->result_type_id); ++ CHECKED_READU32(p_parser, p_node->word_offset + 2, p_node->result_id); ++ p_node->is_type = true; ++ } ++ break; ++// -- GODOT end -- + case SpvOpSpecConstantComposite: + case SpvOpSpecConstantOp: { + CHECKED_READU32(p_parser, p_node->word_offset + 1, p_node->result_type_id); +@@ -1309,6 +1321,9 @@ static SpvReflectResult ParseDecorations(Parser* p_parser) + skip = true; + } + break; ++// -- GODOT begin -- ++ case SpvDecorationSpecId: ++// -- GODOT end -- + case SpvDecorationBlock: + case SpvDecorationBufferBlock: + case SpvDecorationColMajor: +@@ -1441,7 +1456,14 @@ static SpvReflectResult ParseDecorations(Parser* p_parser) + p_target_decorations->input_attachment_index.word_offset = word_offset; + } + break; +- ++// -- GODOT begin -- ++ case SpvDecorationSpecId: { ++ uint32_t word_offset = p_node->word_offset + member_offset+ 3; ++ CHECKED_READU32(p_parser, word_offset, p_target_decorations->specialization_constant.value); ++ p_target_decorations->specialization_constant.word_offset = word_offset; ++ } ++ break; ++// -- GODOT end -- + case SpvReflectDecorationHlslCounterBufferGOOGLE: { + uint32_t word_offset = p_node->word_offset + member_offset+ 3; + CHECKED_READU32(p_parser, word_offset, p_target_decorations->uav_counter_buffer.value); +@@ -1731,6 +1753,13 @@ static SpvReflectResult ParseType( + p_type->type_flags |= SPV_REFLECT_TYPE_FLAG_EXTERNAL_ACCELERATION_STRUCTURE; + } + break; ++// -- GODOT begin -- ++ case SpvOpSpecConstantTrue: ++ case SpvOpSpecConstantFalse: ++ case SpvOpSpecConstant: { ++ } ++ break; ++// -- GODOT end -- + } + + if (result == SPV_REFLECT_RESULT_SUCCESS) { +@@ -3187,6 +3216,69 @@ static SpvReflectResult ParseExecutionModes(Parser* p_parser, SpvReflectShaderMo + return SPV_REFLECT_RESULT_SUCCESS; + } + ++// -- GODOT begin -- ++static SpvReflectResult ParseSpecializationConstants(Parser* p_parser, SpvReflectShaderModule* p_module) ++{ ++ p_module->specialization_constant_count = 0; ++ p_module->specialization_constants = NULL; ++ for (size_t i = 0; i < p_parser->node_count; ++i) { ++ Node* p_node = &(p_parser->nodes[i]); ++ if (p_node->op == SpvOpSpecConstantTrue || p_node->op == SpvOpSpecConstantFalse || p_node->op == SpvOpSpecConstant) { ++ p_module->specialization_constant_count++; ++ } ++ } ++ ++ if (p_module->specialization_constant_count == 0) { ++ return SPV_REFLECT_RESULT_SUCCESS; ++ } ++ ++ p_module->specialization_constants = (SpvReflectSpecializationConstant*)calloc(p_module->specialization_constant_count, sizeof(SpvReflectSpecializationConstant)); ++ ++ uint32_t index = 0; ++ ++ for (size_t i = 0; i < p_parser->node_count; ++i) { ++ Node* p_node = &(p_parser->nodes[i]); ++ switch(p_node->op) { ++ default: continue; ++ case SpvOpSpecConstantTrue: { ++ p_module->specialization_constants[index].constant_type = SPV_REFLECT_SPECIALIZATION_CONSTANT_BOOL; ++ p_module->specialization_constants[index].default_value.int_bool_value = 1; ++ } break; ++ case SpvOpSpecConstantFalse: { ++ p_module->specialization_constants[index].constant_type = SPV_REFLECT_SPECIALIZATION_CONSTANT_BOOL; ++ p_module->specialization_constants[index].default_value.int_bool_value = 0; ++ } break; ++ case SpvOpSpecConstant: { ++ SpvReflectResult result = SPV_REFLECT_RESULT_SUCCESS; ++ uint32_t element_type_id = (uint32_t)INVALID_VALUE; ++ uint32_t default_value = 0; ++ IF_READU32(result, p_parser, p_node->word_offset + 1, element_type_id); ++ IF_READU32(result, p_parser, p_node->word_offset + 3, default_value); ++ ++ Node* p_next_node = FindNode(p_parser, element_type_id); ++ ++ if (p_next_node->op == SpvOpTypeInt) { ++ p_module->specialization_constants[index].constant_type = SPV_REFLECT_SPECIALIZATION_CONSTANT_INT; ++ } else if (p_next_node->op == SpvOpTypeFloat) { ++ p_module->specialization_constants[index].constant_type = SPV_REFLECT_SPECIALIZATION_CONSTANT_FLOAT; ++ } else { ++ return SPV_REFLECT_RESULT_ERROR_PARSE_FAILED; ++ } ++ ++ p_module->specialization_constants[index].default_value.int_bool_value = default_value; //bits are the same for int and float ++ } break; ++ } ++ ++ p_module->specialization_constants[index].name = p_node->name; ++ p_module->specialization_constants[index].constant_id = p_node->decorations.specialization_constant.value; ++ p_module->specialization_constants[index].spirv_id = p_node->result_id; ++ index++; ++ } ++ ++ return SPV_REFLECT_RESULT_SUCCESS; ++} ++// -- GODOT end -- ++ + static SpvReflectResult ParsePushConstantBlocks(Parser* p_parser, SpvReflectShaderModule* p_module) + { + for (size_t i = 0; i < p_parser->node_count; ++i) { +@@ -3562,6 +3654,12 @@ SpvReflectResult spvReflectCreateShaderModule( + result = ParsePushConstantBlocks(&parser, p_module); + SPV_REFLECT_ASSERT(result == SPV_REFLECT_RESULT_SUCCESS); + } ++// -- GODOT begin -- ++ if (result == SPV_REFLECT_RESULT_SUCCESS) { ++ result = ParseSpecializationConstants(&parser, p_module); ++ SPV_REFLECT_ASSERT(result == SPV_REFLECT_RESULT_SUCCESS); ++ } ++// -- GODOT end -- + if (result == SPV_REFLECT_RESULT_SUCCESS) { + result = ParseEntryPoints(&parser, p_module); + SPV_REFLECT_ASSERT(result == SPV_REFLECT_RESULT_SUCCESS); +@@ -3691,6 +3789,9 @@ void spvReflectDestroyShaderModule(SpvReflectShaderModule* p_module) + SafeFree(p_entry->used_push_constants); + } + SafeFree(p_module->entry_points); ++// -- GODOT begin -- ++ SafeFree(p_module->specialization_constants); ++// -- GODOT end -- + + // Push constants + for (size_t i = 0; i < p_module->push_constant_block_count; ++i) { +@@ -3959,6 +4060,38 @@ SpvReflectResult spvReflectEnumerateEntryPointInterfaceVariables( + return SPV_REFLECT_RESULT_SUCCESS; + } + ++// -- GODOT begin -- ++SpvReflectResult spvReflectEnumerateSpecializationConstants( ++ const SpvReflectShaderModule* p_module, ++ uint32_t* p_count, ++ SpvReflectSpecializationConstant** pp_constants ++) ++{ ++ if (IsNull(p_module)) { ++ return SPV_REFLECT_RESULT_ERROR_NULL_POINTER; ++ } ++ if (IsNull(p_count)) { ++ return SPV_REFLECT_RESULT_ERROR_NULL_POINTER; ++ } ++ ++ if (IsNotNull(pp_constants)) { ++ if (*p_count != p_module->specialization_constant_count) { ++ return SPV_REFLECT_RESULT_ERROR_COUNT_MISMATCH; ++ } ++ ++ for (uint32_t index = 0; index < *p_count; ++index) { ++ SpvReflectSpecializationConstant *p_const = &p_module->specialization_constants[index]; ++ pp_constants[index] = p_const; ++ } ++ } ++ else { ++ *p_count = p_module->specialization_constant_count; ++ } ++ ++ return SPV_REFLECT_RESULT_SUCCESS; ++} ++// -- GODOT end -- ++ + SpvReflectResult spvReflectEnumerateInputVariables( + const SpvReflectShaderModule* p_module, + uint32_t* p_count, +diff --git a/thirdparty/spirv-reflect/spirv_reflect.h b/thirdparty/spirv-reflect/spirv_reflect.h +index a5a956e9e8..21f8160770 100644 +--- a/thirdparty/spirv-reflect/spirv_reflect.h ++++ b/thirdparty/spirv-reflect/spirv_reflect.h +@@ -292,6 +292,28 @@ typedef struct SpvReflectTypeDescription { + struct SpvReflectTypeDescription* members; + } SpvReflectTypeDescription; + ++// -- GODOT begin -- ++/*! @struct SpvReflectSpecializationConstant ++ ++*/ ++ ++typedef enum SpvReflectSpecializationConstantType { ++ SPV_REFLECT_SPECIALIZATION_CONSTANT_BOOL = 0, ++ SPV_REFLECT_SPECIALIZATION_CONSTANT_INT = 1, ++ SPV_REFLECT_SPECIALIZATION_CONSTANT_FLOAT = 2, ++} SpvReflectSpecializationConstantType; ++ ++typedef struct SpvReflectSpecializationConstant { ++ const char* name; ++ uint32_t spirv_id; ++ uint32_t constant_id; ++ SpvReflectSpecializationConstantType constant_type; ++ union { ++ float float_value; ++ uint32_t int_bool_value; ++ } default_value; ++} SpvReflectSpecializationConstant; ++// -- GODOT end -- + + /*! @struct SpvReflectInterfaceVariable + +@@ -439,6 +461,10 @@ typedef struct SpvReflectShaderModule { + SpvReflectInterfaceVariable* interface_variables; + uint32_t push_constant_block_count; + SpvReflectBlockVariable* push_constant_blocks; ++ // -- GODOT begin -- ++ uint32_t specialization_constant_count; ++ SpvReflectSpecializationConstant* specialization_constants; ++ // -- GODOT end -- + + struct Internal { + size_t spirv_size; +@@ -694,6 +720,33 @@ SpvReflectResult spvReflectEnumerateInputVariables( + SpvReflectInterfaceVariable** pp_variables + ); + ++// -- GOODT begin -- ++/*! @fn spvReflectEnumerateSpecializationConstants ++ @brief If the module contains multiple entry points, this will only get ++ the specialization constants for the first one. ++ @param p_module Pointer to an instance of SpvReflectShaderModule. ++ @param p_count If pp_constants is NULL, the module's specialization constant ++ count will be stored here. ++ If pp_variables is not NULL, *p_count must contain ++ the module's specialization constant count. ++ @param pp_variables If NULL, the module's specialization constant count will be ++ written to *p_count. ++ If non-NULL, pp_constants must point to an array with ++ *p_count entries, where pointers to the module's ++ specialization constants will be written. The caller must not ++ free the specialization constants written to this array. ++ @return If successful, returns SPV_REFLECT_RESULT_SUCCESS. ++ Otherwise, the error code indicates the cause of the ++ failure. ++ ++*/ ++SpvReflectResult spvReflectEnumerateSpecializationConstants( ++ const SpvReflectShaderModule* p_module, ++ uint32_t* p_count, ++ SpvReflectSpecializationConstant** pp_constants ++); ++// -- GODOT end -- ++ + /*! @fn spvReflectEnumerateEntryPointInputVariables + @brief Enumerate the input variables for a given entry point. + @param entry_point The name of the entry point to get the input variables for. diff --git a/thirdparty/spirv-reflect/spirv_reflect.c b/thirdparty/spirv-reflect/spirv_reflect.c index 0fc979a8a4..8f614c8874 100644 --- a/thirdparty/spirv-reflect/spirv_reflect.c +++ b/thirdparty/spirv-reflect/spirv_reflect.c @@ -124,6 +124,9 @@ typedef struct Decorations { NumberDecoration location; NumberDecoration offset; NumberDecoration uav_counter_buffer; +// -- GODOT begin -- + NumberDecoration specialization_constant; +// -- GODOT end -- StringDecoration semantic; uint32_t array_stride; uint32_t matrix_stride; @@ -610,6 +613,9 @@ static SpvReflectResult ParseNodes(Parser* p_parser) p_parser->nodes[i].decorations.offset.value = (uint32_t)INVALID_VALUE; p_parser->nodes[i].decorations.uav_counter_buffer.value = (uint32_t)INVALID_VALUE; p_parser->nodes[i].decorations.built_in = (SpvBuiltIn)INVALID_VALUE; +// -- GODOT begin -- + p_parser->nodes[i].decorations.specialization_constant.value = (SpvBuiltIn)INVALID_VALUE; +// -- GODOT end -- } // Mark source file id node p_parser->source_file_id = (uint32_t)INVALID_VALUE; @@ -800,10 +806,16 @@ static SpvReflectResult ParseNodes(Parser* p_parser) CHECKED_READU32(p_parser, p_node->word_offset + 2, p_node->result_id); } break; - +// -- GODOT begin -- case SpvOpSpecConstantTrue: case SpvOpSpecConstantFalse: - case SpvOpSpecConstant: + case SpvOpSpecConstant: { + CHECKED_READU32(p_parser, p_node->word_offset + 1, p_node->result_type_id); + CHECKED_READU32(p_parser, p_node->word_offset + 2, p_node->result_id); + p_node->is_type = true; + } + break; +// -- GODOT end -- case SpvOpSpecConstantComposite: case SpvOpSpecConstantOp: { CHECKED_READU32(p_parser, p_node->word_offset + 1, p_node->result_type_id); @@ -1309,6 +1321,9 @@ static SpvReflectResult ParseDecorations(Parser* p_parser) skip = true; } break; +// -- GODOT begin -- + case SpvDecorationSpecId: +// -- GODOT end -- case SpvDecorationBlock: case SpvDecorationBufferBlock: case SpvDecorationColMajor: @@ -1441,7 +1456,14 @@ static SpvReflectResult ParseDecorations(Parser* p_parser) p_target_decorations->input_attachment_index.word_offset = word_offset; } break; - +// -- GODOT begin -- + case SpvDecorationSpecId: { + uint32_t word_offset = p_node->word_offset + member_offset+ 3; + CHECKED_READU32(p_parser, word_offset, p_target_decorations->specialization_constant.value); + p_target_decorations->specialization_constant.word_offset = word_offset; + } + break; +// -- GODOT end -- case SpvReflectDecorationHlslCounterBufferGOOGLE: { uint32_t word_offset = p_node->word_offset + member_offset+ 3; CHECKED_READU32(p_parser, word_offset, p_target_decorations->uav_counter_buffer.value); @@ -1731,6 +1753,13 @@ static SpvReflectResult ParseType( p_type->type_flags |= SPV_REFLECT_TYPE_FLAG_EXTERNAL_ACCELERATION_STRUCTURE; } break; +// -- GODOT begin -- + case SpvOpSpecConstantTrue: + case SpvOpSpecConstantFalse: + case SpvOpSpecConstant: { + } + break; +// -- GODOT end -- } if (result == SPV_REFLECT_RESULT_SUCCESS) { @@ -3187,6 +3216,69 @@ static SpvReflectResult ParseExecutionModes(Parser* p_parser, SpvReflectShaderMo return SPV_REFLECT_RESULT_SUCCESS; } +// -- GODOT begin -- +static SpvReflectResult ParseSpecializationConstants(Parser* p_parser, SpvReflectShaderModule* p_module) +{ + p_module->specialization_constant_count = 0; + p_module->specialization_constants = NULL; + for (size_t i = 0; i < p_parser->node_count; ++i) { + Node* p_node = &(p_parser->nodes[i]); + if (p_node->op == SpvOpSpecConstantTrue || p_node->op == SpvOpSpecConstantFalse || p_node->op == SpvOpSpecConstant) { + p_module->specialization_constant_count++; + } + } + + if (p_module->specialization_constant_count == 0) { + return SPV_REFLECT_RESULT_SUCCESS; + } + + p_module->specialization_constants = (SpvReflectSpecializationConstant*)calloc(p_module->specialization_constant_count, sizeof(SpvReflectSpecializationConstant)); + + uint32_t index = 0; + + for (size_t i = 0; i < p_parser->node_count; ++i) { + Node* p_node = &(p_parser->nodes[i]); + switch(p_node->op) { + default: continue; + case SpvOpSpecConstantTrue: { + p_module->specialization_constants[index].constant_type = SPV_REFLECT_SPECIALIZATION_CONSTANT_BOOL; + p_module->specialization_constants[index].default_value.int_bool_value = 1; + } break; + case SpvOpSpecConstantFalse: { + p_module->specialization_constants[index].constant_type = SPV_REFLECT_SPECIALIZATION_CONSTANT_BOOL; + p_module->specialization_constants[index].default_value.int_bool_value = 0; + } break; + case SpvOpSpecConstant: { + SpvReflectResult result = SPV_REFLECT_RESULT_SUCCESS; + uint32_t element_type_id = (uint32_t)INVALID_VALUE; + uint32_t default_value = 0; + IF_READU32(result, p_parser, p_node->word_offset + 1, element_type_id); + IF_READU32(result, p_parser, p_node->word_offset + 3, default_value); + + Node* p_next_node = FindNode(p_parser, element_type_id); + + if (p_next_node->op == SpvOpTypeInt) { + p_module->specialization_constants[index].constant_type = SPV_REFLECT_SPECIALIZATION_CONSTANT_INT; + } else if (p_next_node->op == SpvOpTypeFloat) { + p_module->specialization_constants[index].constant_type = SPV_REFLECT_SPECIALIZATION_CONSTANT_FLOAT; + } else { + return SPV_REFLECT_RESULT_ERROR_PARSE_FAILED; + } + + p_module->specialization_constants[index].default_value.int_bool_value = default_value; //bits are the same for int and float + } break; + } + + p_module->specialization_constants[index].name = p_node->name; + p_module->specialization_constants[index].constant_id = p_node->decorations.specialization_constant.value; + p_module->specialization_constants[index].spirv_id = p_node->result_id; + index++; + } + + return SPV_REFLECT_RESULT_SUCCESS; +} +// -- GODOT end -- + static SpvReflectResult ParsePushConstantBlocks(Parser* p_parser, SpvReflectShaderModule* p_module) { for (size_t i = 0; i < p_parser->node_count; ++i) { @@ -3562,6 +3654,12 @@ SpvReflectResult spvReflectCreateShaderModule( result = ParsePushConstantBlocks(&parser, p_module); SPV_REFLECT_ASSERT(result == SPV_REFLECT_RESULT_SUCCESS); } +// -- GODOT begin -- + if (result == SPV_REFLECT_RESULT_SUCCESS) { + result = ParseSpecializationConstants(&parser, p_module); + SPV_REFLECT_ASSERT(result == SPV_REFLECT_RESULT_SUCCESS); + } +// -- GODOT end -- if (result == SPV_REFLECT_RESULT_SUCCESS) { result = ParseEntryPoints(&parser, p_module); SPV_REFLECT_ASSERT(result == SPV_REFLECT_RESULT_SUCCESS); @@ -3691,6 +3789,9 @@ void spvReflectDestroyShaderModule(SpvReflectShaderModule* p_module) SafeFree(p_entry->used_push_constants); } SafeFree(p_module->entry_points); +// -- GODOT begin -- + SafeFree(p_module->specialization_constants); +// -- GODOT end -- // Push constants for (size_t i = 0; i < p_module->push_constant_block_count; ++i) { @@ -3959,6 +4060,38 @@ SpvReflectResult spvReflectEnumerateEntryPointInterfaceVariables( return SPV_REFLECT_RESULT_SUCCESS; } +// -- GODOT begin -- +SpvReflectResult spvReflectEnumerateSpecializationConstants( + const SpvReflectShaderModule* p_module, + uint32_t* p_count, + SpvReflectSpecializationConstant** pp_constants +) +{ + if (IsNull(p_module)) { + return SPV_REFLECT_RESULT_ERROR_NULL_POINTER; + } + if (IsNull(p_count)) { + return SPV_REFLECT_RESULT_ERROR_NULL_POINTER; + } + + if (IsNotNull(pp_constants)) { + if (*p_count != p_module->specialization_constant_count) { + return SPV_REFLECT_RESULT_ERROR_COUNT_MISMATCH; + } + + for (uint32_t index = 0; index < *p_count; ++index) { + SpvReflectSpecializationConstant *p_const = &p_module->specialization_constants[index]; + pp_constants[index] = p_const; + } + } + else { + *p_count = p_module->specialization_constant_count; + } + + return SPV_REFLECT_RESULT_SUCCESS; +} +// -- GODOT end -- + SpvReflectResult spvReflectEnumerateInputVariables( const SpvReflectShaderModule* p_module, uint32_t* p_count, diff --git a/thirdparty/spirv-reflect/spirv_reflect.h b/thirdparty/spirv-reflect/spirv_reflect.h index a5a956e9e8..21f8160770 100644 --- a/thirdparty/spirv-reflect/spirv_reflect.h +++ b/thirdparty/spirv-reflect/spirv_reflect.h @@ -292,6 +292,28 @@ typedef struct SpvReflectTypeDescription { struct SpvReflectTypeDescription* members; } SpvReflectTypeDescription; +// -- GODOT begin -- +/*! @struct SpvReflectSpecializationConstant + +*/ + +typedef enum SpvReflectSpecializationConstantType { + SPV_REFLECT_SPECIALIZATION_CONSTANT_BOOL = 0, + SPV_REFLECT_SPECIALIZATION_CONSTANT_INT = 1, + SPV_REFLECT_SPECIALIZATION_CONSTANT_FLOAT = 2, +} SpvReflectSpecializationConstantType; + +typedef struct SpvReflectSpecializationConstant { + const char* name; + uint32_t spirv_id; + uint32_t constant_id; + SpvReflectSpecializationConstantType constant_type; + union { + float float_value; + uint32_t int_bool_value; + } default_value; +} SpvReflectSpecializationConstant; +// -- GODOT end -- /*! @struct SpvReflectInterfaceVariable @@ -439,6 +461,10 @@ typedef struct SpvReflectShaderModule { SpvReflectInterfaceVariable* interface_variables; uint32_t push_constant_block_count; SpvReflectBlockVariable* push_constant_blocks; + // -- GODOT begin -- + uint32_t specialization_constant_count; + SpvReflectSpecializationConstant* specialization_constants; + // -- GODOT end -- struct Internal { size_t spirv_size; @@ -694,6 +720,33 @@ SpvReflectResult spvReflectEnumerateInputVariables( SpvReflectInterfaceVariable** pp_variables ); +// -- GOODT begin -- +/*! @fn spvReflectEnumerateSpecializationConstants + @brief If the module contains multiple entry points, this will only get + the specialization constants for the first one. + @param p_module Pointer to an instance of SpvReflectShaderModule. + @param p_count If pp_constants is NULL, the module's specialization constant + count will be stored here. + If pp_variables is not NULL, *p_count must contain + the module's specialization constant count. + @param pp_variables If NULL, the module's specialization constant count will be + written to *p_count. + If non-NULL, pp_constants must point to an array with + *p_count entries, where pointers to the module's + specialization constants will be written. The caller must not + free the specialization constants written to this array. + @return If successful, returns SPV_REFLECT_RESULT_SUCCESS. + Otherwise, the error code indicates the cause of the + failure. + +*/ +SpvReflectResult spvReflectEnumerateSpecializationConstants( + const SpvReflectShaderModule* p_module, + uint32_t* p_count, + SpvReflectSpecializationConstant** pp_constants +); +// -- GODOT end -- + /*! @fn spvReflectEnumerateEntryPointInputVariables @brief Enumerate the input variables for a given entry point. @param entry_point The name of the entry point to get the input variables for. |