diff options
90 files changed, 2224 insertions, 1360 deletions
diff --git a/core/core_bind.cpp b/core/core_bind.cpp index 8d03f35617..195292f7e6 100644 --- a/core/core_bind.cpp +++ b/core/core_bind.cpp @@ -2376,21 +2376,18 @@ bool EngineDebugger::is_active() { return ::EngineDebugger::is_active(); } -void EngineDebugger::register_profiler(const StringName &p_name, const Callable &p_toggle, const Callable &p_add, const Callable &p_tick) { - ERR_FAIL_COND_MSG(profilers.has(p_name) || has_profiler(p_name), "Profiler already registered: " + p_name); - profilers.insert(p_name, ProfilerCallable(p_toggle, p_add, p_tick)); - ProfilerCallable &p = profilers[p_name]; - ::EngineDebugger::Profiler profiler( - &p, - &EngineDebugger::call_toggle, - &EngineDebugger::call_add, - &EngineDebugger::call_tick); - ::EngineDebugger::register_profiler(p_name, profiler); +void EngineDebugger::register_profiler(const StringName &p_name, Ref<EngineProfiler> p_profiler) { + ERR_FAIL_COND(p_profiler.is_null()); + ERR_FAIL_COND_MSG(p_profiler->is_bound(), "Profiler already registered."); + ERR_FAIL_COND_MSG(profilers.has(p_name) || has_profiler(p_name), "Profiler name already in use: " + p_name); + Error err = p_profiler->bind(p_name); + ERR_FAIL_COND_MSG(err != OK, "Profiler failed to register with error: " + itos(err)); + profilers.insert(p_name, p_profiler); } void EngineDebugger::unregister_profiler(const StringName &p_name) { ERR_FAIL_COND_MSG(!profilers.has(p_name), "Profiler not registered: " + p_name); - ::EngineDebugger::unregister_profiler(p_name); + profilers[p_name]->unbind(); profilers.erase(p_name); } @@ -2435,45 +2432,6 @@ void EngineDebugger::send_message(const String &p_msg, const Array &p_data) { ::EngineDebugger::get_singleton()->send_message(p_msg, p_data); } -void EngineDebugger::call_toggle(void *p_user, bool p_enable, const Array &p_opts) { - Callable &toggle = ((ProfilerCallable *)p_user)->callable_toggle; - if (toggle.is_null()) { - return; - } - Variant enable = p_enable, opts = p_opts; - const Variant *args[2] = { &enable, &opts }; - Variant retval; - Callable::CallError err; - toggle.call(args, 2, retval, err); - ERR_FAIL_COND_MSG(err.error != Callable::CallError::CALL_OK, "Error calling 'toggle' to callable: " + Variant::get_callable_error_text(toggle, args, 2, err)); -} - -void EngineDebugger::call_add(void *p_user, const Array &p_data) { - Callable &add = ((ProfilerCallable *)p_user)->callable_add; - if (add.is_null()) { - return; - } - Variant data = p_data; - const Variant *args[1] = { &data }; - Variant retval; - Callable::CallError err; - add.call(args, 1, retval, err); - ERR_FAIL_COND_MSG(err.error != Callable::CallError::CALL_OK, "Error calling 'add' to callable: " + Variant::get_callable_error_text(add, args, 1, err)); -} - -void EngineDebugger::call_tick(void *p_user, double p_frame_time, double p_idle_time, double p_physics_time, double p_physics_frame_time) { - Callable &tick = ((ProfilerCallable *)p_user)->callable_tick; - if (tick.is_null()) { - return; - } - Variant frame_time = p_frame_time, idle_time = p_idle_time, physics_time = p_physics_time, physics_frame_time = p_physics_frame_time; - const Variant *args[4] = { &frame_time, &idle_time, &physics_time, &physics_frame_time }; - Variant retval; - Callable::CallError err; - tick.call(args, 4, retval, err); - ERR_FAIL_COND_MSG(err.error != Callable::CallError::CALL_OK, "Error calling 'tick' to callable: " + Variant::get_callable_error_text(tick, args, 4, err)); -} - Error EngineDebugger::call_capture(void *p_user, const String &p_cmd, const Array &p_data, bool &r_captured) { Callable &capture = *(Callable *)p_user; if (capture.is_null()) { @@ -2495,10 +2453,6 @@ EngineDebugger::~EngineDebugger() { ::EngineDebugger::unregister_message_capture(E.key); } captures.clear(); - for (const KeyValue<StringName, ProfilerCallable> &E : profilers) { - ::EngineDebugger::unregister_profiler(E.key); - } - profilers.clear(); } EngineDebugger *EngineDebugger::singleton = nullptr; @@ -2506,8 +2460,9 @@ EngineDebugger *EngineDebugger::singleton = nullptr; void EngineDebugger::_bind_methods() { ClassDB::bind_method(D_METHOD("is_active"), &EngineDebugger::is_active); - ClassDB::bind_method(D_METHOD("register_profiler", "name", "toggle", "add", "tick"), &EngineDebugger::register_profiler); + ClassDB::bind_method(D_METHOD("register_profiler", "name", "profiler"), &EngineDebugger::register_profiler); ClassDB::bind_method(D_METHOD("unregister_profiler", "name"), &EngineDebugger::unregister_profiler); + ClassDB::bind_method(D_METHOD("is_profiling", "name"), &EngineDebugger::is_profiling); ClassDB::bind_method(D_METHOD("has_profiler", "name"), &EngineDebugger::has_profiler); diff --git a/core/core_bind.h b/core/core_bind.h index ac0e92a87a..21a1fc2077 100644 --- a/core/core_bind.h +++ b/core/core_bind.h @@ -31,6 +31,7 @@ #ifndef CORE_BIND_H #define CORE_BIND_H +#include "core/debugger/engine_profiler.h" #include "core/io/compression.h" #include "core/io/dir_access.h" #include "core/io/file_access.h" @@ -673,25 +674,8 @@ public: class EngineDebugger : public Object { GDCLASS(EngineDebugger, Object); - class ProfilerCallable { - friend class EngineDebugger; - - Callable callable_toggle; - Callable callable_add; - Callable callable_tick; - - public: - ProfilerCallable() {} - - ProfilerCallable(const Callable &p_toggle, const Callable &p_add, const Callable &p_tick) { - callable_toggle = p_toggle; - callable_add = p_add; - callable_tick = p_tick; - } - }; - Map<StringName, Callable> captures; - Map<StringName, ProfilerCallable> profilers; + Map<StringName, Ref<EngineProfiler>> profilers; protected: static void _bind_methods(); @@ -702,7 +686,7 @@ public: bool is_active(); - void register_profiler(const StringName &p_name, const Callable &p_toggle, const Callable &p_add, const Callable &p_tick); + void register_profiler(const StringName &p_name, Ref<EngineProfiler> p_profiler); void unregister_profiler(const StringName &p_name); bool is_profiling(const StringName &p_name); bool has_profiler(const StringName &p_name); @@ -715,9 +699,6 @@ public: void send_message(const String &p_msg, const Array &p_data); - static void call_toggle(void *p_user, bool p_enable, const Array &p_opts); - static void call_add(void *p_user, const Array &p_data); - static void call_tick(void *p_user, double p_frame_time, double p_idle_time, double p_physics_time, double p_physics_frame_time); static Error call_capture(void *p_user, const String &p_cmd, const Array &p_data, bool &r_captured); EngineDebugger() { singleton = this; } diff --git a/core/debugger/debugger_marshalls.cpp b/core/debugger/debugger_marshalls.cpp index 1a746d59a3..4c69290c2e 100644 --- a/core/debugger/debugger_marshalls.cpp +++ b/core/debugger/debugger_marshalls.cpp @@ -35,159 +35,6 @@ #define CHECK_SIZE(arr, expected, what) ERR_FAIL_COND_V_MSG((uint32_t)arr.size() < (uint32_t)(expected), false, String("Malformed ") + what + " message from script debugger, message too short. Expected size: " + itos(expected) + ", actual size: " + itos(arr.size())) #define CHECK_END(arr, expected, what) ERR_FAIL_COND_V_MSG((uint32_t)arr.size() > (uint32_t)expected, false, String("Malformed ") + what + " message from script debugger, message too long. Expected size: " + itos(expected) + ", actual size: " + itos(arr.size())) -Array DebuggerMarshalls::ResourceUsage::serialize() { - infos.sort(); - - Array arr; - arr.push_back(infos.size() * 4); - for (const ResourceInfo &E : infos) { - arr.push_back(E.path); - arr.push_back(E.format); - arr.push_back(E.type); - arr.push_back(E.vram); - } - return arr; -} - -bool DebuggerMarshalls::ResourceUsage::deserialize(const Array &p_arr) { - CHECK_SIZE(p_arr, 1, "ResourceUsage"); - uint32_t size = p_arr[0]; - CHECK_SIZE(p_arr, size, "ResourceUsage"); - int idx = 1; - for (uint32_t i = 0; i < size / 4; i++) { - ResourceInfo info; - info.path = p_arr[idx]; - info.format = p_arr[idx + 1]; - info.type = p_arr[idx + 2]; - info.vram = p_arr[idx + 3]; - infos.push_back(info); - } - CHECK_END(p_arr, idx, "ResourceUsage"); - return true; -} - -Array DebuggerMarshalls::ScriptFunctionSignature::serialize() { - Array arr; - arr.push_back(name); - arr.push_back(id); - return arr; -} - -bool DebuggerMarshalls::ScriptFunctionSignature::deserialize(const Array &p_arr) { - CHECK_SIZE(p_arr, 2, "ScriptFunctionSignature"); - name = p_arr[0]; - id = p_arr[1]; - CHECK_END(p_arr, 2, "ScriptFunctionSignature"); - return true; -} - -Array DebuggerMarshalls::NetworkProfilerFrame::serialize() { - Array arr; - arr.push_back(infos.size() * 6); - for (int i = 0; i < infos.size(); ++i) { - arr.push_back(uint64_t(infos[i].node)); - arr.push_back(infos[i].node_path); - arr.push_back(infos[i].incoming_rpc); - arr.push_back(infos[i].incoming_rset); - arr.push_back(infos[i].outgoing_rpc); - arr.push_back(infos[i].outgoing_rset); - } - return arr; -} - -bool DebuggerMarshalls::NetworkProfilerFrame::deserialize(const Array &p_arr) { - CHECK_SIZE(p_arr, 1, "NetworkProfilerFrame"); - uint32_t size = p_arr[0]; - CHECK_SIZE(p_arr, size, "NetworkProfilerFrame"); - infos.resize(size); - int idx = 1; - for (uint32_t i = 0; i < size / 6; ++i) { - infos.write[i].node = uint64_t(p_arr[idx]); - infos.write[i].node_path = p_arr[idx + 1]; - infos.write[i].incoming_rpc = p_arr[idx + 2]; - infos.write[i].incoming_rset = p_arr[idx + 3]; - infos.write[i].outgoing_rpc = p_arr[idx + 4]; - infos.write[i].outgoing_rset = p_arr[idx + 5]; - } - CHECK_END(p_arr, idx, "NetworkProfilerFrame"); - return true; -} - -Array DebuggerMarshalls::ServersProfilerFrame::serialize() { - Array arr; - arr.push_back(frame_number); - arr.push_back(frame_time); - arr.push_back(idle_time); - arr.push_back(physics_time); - arr.push_back(physics_frame_time); - arr.push_back(script_time); - - arr.push_back(servers.size()); - for (int i = 0; i < servers.size(); i++) { - ServerInfo &s = servers[i]; - arr.push_back(s.name); - arr.push_back(s.functions.size() * 2); - for (int j = 0; j < s.functions.size(); j++) { - ServerFunctionInfo &f = s.functions[j]; - arr.push_back(f.name); - arr.push_back(f.time); - } - } - - arr.push_back(script_functions.size() * 4); - for (int i = 0; i < script_functions.size(); i++) { - arr.push_back(script_functions[i].sig_id); - arr.push_back(script_functions[i].call_count); - arr.push_back(script_functions[i].self_time); - arr.push_back(script_functions[i].total_time); - } - return arr; -} - -bool DebuggerMarshalls::ServersProfilerFrame::deserialize(const Array &p_arr) { - CHECK_SIZE(p_arr, 7, "ServersProfilerFrame"); - frame_number = p_arr[0]; - frame_time = p_arr[1]; - idle_time = p_arr[2]; - physics_time = p_arr[3]; - physics_frame_time = p_arr[4]; - script_time = p_arr[5]; - int servers_size = p_arr[6]; - int idx = 7; - while (servers_size) { - CHECK_SIZE(p_arr, idx + 2, "ServersProfilerFrame"); - servers_size--; - ServerInfo si; - si.name = p_arr[idx]; - int sub_data_size = p_arr[idx + 1]; - idx += 2; - CHECK_SIZE(p_arr, idx + sub_data_size, "ServersProfilerFrame"); - for (int j = 0; j < sub_data_size / 2; j++) { - ServerFunctionInfo sf; - sf.name = p_arr[idx]; - sf.time = p_arr[idx + 1]; - idx += 2; - si.functions.push_back(sf); - } - servers.push_back(si); - } - CHECK_SIZE(p_arr, idx + 1, "ServersProfilerFrame"); - int func_size = p_arr[idx]; - idx += 1; - CHECK_SIZE(p_arr, idx + func_size, "ServersProfilerFrame"); - for (int i = 0; i < func_size / 4; i++) { - ScriptFunctionInfo fi; - fi.sig_id = p_arr[idx]; - fi.call_count = p_arr[idx + 1]; - fi.self_time = p_arr[idx + 2]; - fi.total_time = p_arr[idx + 3]; - script_functions.push_back(fi); - idx += 4; - } - CHECK_END(p_arr, idx, "ServersProfilerFrame"); - return true; -} - Array DebuggerMarshalls::ScriptStackDump::serialize() { Array arr; arr.push_back(frames.size() * 3); @@ -298,33 +145,3 @@ bool DebuggerMarshalls::OutputError::deserialize(const Array &p_arr) { CHECK_END(p_arr, idx, "OutputError"); return true; } - -Array DebuggerMarshalls::VisualProfilerFrame::serialize() { - Array arr; - arr.push_back(frame_number); - arr.push_back(areas.size() * 3); - for (int i = 0; i < areas.size(); i++) { - arr.push_back(areas[i].name); - arr.push_back(areas[i].cpu_msec); - arr.push_back(areas[i].gpu_msec); - } - return arr; -} - -bool DebuggerMarshalls::VisualProfilerFrame::deserialize(const Array &p_arr) { - CHECK_SIZE(p_arr, 2, "VisualProfilerFrame"); - frame_number = p_arr[0]; - int size = p_arr[1]; - CHECK_SIZE(p_arr, size, "VisualProfilerFrame"); - int idx = 2; - areas.resize(size / 3); - RS::FrameProfileArea *w = areas.ptrw(); - for (int i = 0; i < size / 3; i++) { - w[i].name = p_arr[idx]; - w[i].cpu_msec = p_arr[idx + 1]; - w[i].gpu_msec = p_arr[idx + 2]; - idx += 3; - } - CHECK_END(p_arr, idx, "VisualProfilerFrame"); - return true; -} diff --git a/core/debugger/debugger_marshalls.h b/core/debugger/debugger_marshalls.h index fae766812a..378c3af8aa 100644 --- a/core/debugger/debugger_marshalls.h +++ b/core/debugger/debugger_marshalls.h @@ -32,86 +32,8 @@ #define DEBUGGER_MARSHARLLS_H #include "core/object/script_language.h" -#include "servers/rendering_server.h" struct DebuggerMarshalls { - // Memory usage - struct ResourceInfo { - String path; - String format; - String type; - RID id; - int vram = 0; - bool operator<(const ResourceInfo &p_img) const { return vram == p_img.vram ? id < p_img.id : vram > p_img.vram; } - }; - - struct ResourceUsage { - List<ResourceInfo> infos; - - Array serialize(); - bool deserialize(const Array &p_arr); - }; - - // Network profiler - struct MultiplayerNodeInfo { - ObjectID node; - String node_path; - int incoming_rpc = 0; - int incoming_rset = 0; - int outgoing_rpc = 0; - int outgoing_rset = 0; - }; - - struct NetworkProfilerFrame { - Vector<MultiplayerNodeInfo> infos; - - Array serialize(); - bool deserialize(const Array &p_arr); - }; - - // Script Profiler - class ScriptFunctionSignature { - public: - StringName name; - int id = -1; - - Array serialize(); - bool deserialize(const Array &p_arr); - }; - - struct ScriptFunctionInfo { - StringName name; - int sig_id = -1; - int call_count = 0; - double self_time = 0; - double total_time = 0; - }; - - // Servers profiler - struct ServerFunctionInfo { - StringName name; - double time = 0; - }; - - struct ServerInfo { - StringName name; - List<ServerFunctionInfo> functions; - }; - - struct ServersProfilerFrame { - int frame_number = 0; - double frame_time = 0; - double idle_time = 0; - double physics_time = 0; - double physics_frame_time = 0; - double script_time = 0; - List<ServerInfo> servers; - Vector<ScriptFunctionInfo> script_functions; - - Array serialize(); - bool deserialize(const Array &p_arr); - }; - struct ScriptStackVariable { String name; Variant value; @@ -145,15 +67,6 @@ struct DebuggerMarshalls { Array serialize(); bool deserialize(const Array &p_arr); }; - - // Visual Profiler - struct VisualProfilerFrame { - uint64_t frame_number = 0; - Vector<RS::FrameProfileArea> areas; - - Array serialize(); - bool deserialize(const Array &p_arr); - }; }; #endif // DEBUGGER_MARSHARLLS_H diff --git a/core/debugger/engine_profiler.cpp b/core/debugger/engine_profiler.cpp new file mode 100644 index 0000000000..c858b1febd --- /dev/null +++ b/core/debugger/engine_profiler.cpp @@ -0,0 +1,82 @@ +/*************************************************************************/ +/* engine_profiler.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2022 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 "engine_profiler.h" + +#include "core/debugger/engine_debugger.h" + +void EngineProfiler::_bind_methods() { + GDVIRTUAL_BIND(_toggle, "enable", "options"); + GDVIRTUAL_BIND(_add_frame, "data"); + GDVIRTUAL_BIND(_tick, "frame_time", "idle_time", "physics_time", "physics_frame_time"); +} + +void EngineProfiler::toggle(bool p_enable, const Array &p_array) { + GDVIRTUAL_CALL(_toggle, p_enable, p_array); +} + +void EngineProfiler::add(const Array &p_data) { + GDVIRTUAL_CALL(_add_frame, p_data); +} + +void EngineProfiler::tick(double p_frame_time, double p_idle_time, double p_physics_time, double p_physics_frame_time) { + GDVIRTUAL_CALL(_tick, p_frame_time, p_idle_time, p_physics_time, p_physics_frame_time); +} + +Error EngineProfiler::bind(const String &p_name) { + ERR_FAIL_COND_V(is_bound(), ERR_ALREADY_IN_USE); + EngineDebugger::Profiler prof( + this, + [](void *p_user, bool p_enable, const Array &p_opts) { + ((EngineProfiler *)p_user)->toggle(p_enable, p_opts); + }, + [](void *p_user, const Array &p_data) { + ((EngineProfiler *)p_user)->add(p_data); + }, + [](void *p_user, double p_frame_time, double p_idle_time, double p_physics_time, double p_physics_frame_time) { + ((EngineProfiler *)p_user)->tick(p_frame_time, p_idle_time, p_physics_time, p_physics_frame_time); + }); + registration = p_name; + EngineDebugger::register_profiler(p_name, prof); + return OK; +} + +Error EngineProfiler::unbind() { + ERR_FAIL_COND_V(!is_bound(), ERR_UNCONFIGURED); + EngineDebugger::unregister_profiler(registration); + registration.clear(); + return OK; +} + +EngineProfiler::~EngineProfiler() { + if (is_bound()) { + unbind(); + } +} diff --git a/core/debugger/engine_profiler.h b/core/debugger/engine_profiler.h new file mode 100644 index 0000000000..ade280a7bb --- /dev/null +++ b/core/debugger/engine_profiler.h @@ -0,0 +1,65 @@ +/*************************************************************************/ +/* engine_profiler.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2022 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 ENGINE_PROFILER_H +#define ENGINE_PROFILER_H + +#include "core/object/ref_counted.h" + +#include "core/object/gdvirtual.gen.inc" +#include "core/object/script_language.h" + +class EngineProfiler : public RefCounted { + GDCLASS(EngineProfiler, RefCounted); + +private: + String registration; + +protected: + static void _bind_methods(); + +public: + virtual void toggle(bool p_enable, const Array &p_opts); + virtual void add(const Array &p_data); + virtual void tick(double p_frame_time, double p_idle_time, double p_physics_time, double p_physics_frame_time); + + Error bind(const String &p_name); + Error unbind(); + bool is_bound() const { return registration.length() > 0; } + + GDVIRTUAL2(_toggle, bool, Array); + GDVIRTUAL1(_add_frame, Array); + GDVIRTUAL4(_tick, double, double, double, double); + + EngineProfiler() {} + virtual ~EngineProfiler(); +}; + +#endif // ENGINE_PROFILER_H diff --git a/core/debugger/remote_debugger.cpp b/core/debugger/remote_debugger.cpp index 339aa9b61f..2fce23d003 100644 --- a/core/debugger/remote_debugger.cpp +++ b/core/debugger/remote_debugger.cpp @@ -33,32 +33,13 @@ #include "core/config/project_settings.h" #include "core/debugger/debugger_marshalls.h" #include "core/debugger/engine_debugger.h" +#include "core/debugger/engine_profiler.h" #include "core/debugger/script_debugger.h" #include "core/input/input.h" #include "core/object/script_language.h" #include "core/os/os.h" -#include "scene/main/node.h" -#include "servers/display_server.h" - -template <typename T> -void RemoteDebugger::_bind_profiler(const String &p_name, T *p_prof) { - EngineDebugger::Profiler prof( - p_prof, - [](void *p_user, bool p_enable, const Array &p_opts) { - ((T *)p_user)->toggle(p_enable, p_opts); - }, - [](void *p_user, const Array &p_data) { - ((T *)p_user)->add(p_data); - }, - [](void *p_user, double p_frame_time, double p_idle_time, double p_physics_time, double p_physics_frame_time) { - ((T *)p_user)->tick(p_frame_time, p_idle_time, p_physics_time, p_physics_frame_time); - }); - EngineDebugger::register_profiler(p_name, prof); -} -struct RemoteDebugger::NetworkProfiler { -public: - typedef DebuggerMarshalls::MultiplayerNodeInfo NodeInfo; +class RemoteDebugger::MultiplayerProfiler : public EngineProfiler { struct BandwidthFrame { uint32_t timestamp; int packet_size; @@ -70,11 +51,6 @@ public: Vector<BandwidthFrame> bandwidth_out; uint64_t last_bandwidth_time = 0; - Map<ObjectID, NodeInfo> multiplayer_node_data; - uint64_t last_profile_time = 0; - - NetworkProfiler() {} - int bandwidth_usage(const Vector<BandwidthFrame> &p_buffer, int p_pointer) { ERR_FAIL_COND_V(p_buffer.size() == 0, 0); int total_bandwidth = 0; @@ -96,22 +72,8 @@ public: return total_bandwidth; } - void init_node(const ObjectID p_node) { - if (multiplayer_node_data.has(p_node)) { - return; - } - multiplayer_node_data.insert(p_node, DebuggerMarshalls::MultiplayerNodeInfo()); - multiplayer_node_data[p_node].node = p_node; - multiplayer_node_data[p_node].node_path = Object::cast_to<Node>(ObjectDB::get_instance(p_node))->get_path(); - multiplayer_node_data[p_node].incoming_rpc = 0; - multiplayer_node_data[p_node].incoming_rset = 0; - multiplayer_node_data[p_node].outgoing_rpc = 0; - multiplayer_node_data[p_node].outgoing_rset = 0; - } - +public: void toggle(bool p_enable, const Array &p_opts) { - multiplayer_node_data.clear(); - if (!p_enable) { bandwidth_in.clear(); bandwidth_out.clear(); @@ -130,37 +92,18 @@ public: } void add(const Array &p_data) { - ERR_FAIL_COND(p_data.size() < 1); - const String type = p_data[0]; - if (type == "node") { - ERR_FAIL_COND(p_data.size() < 3); - const ObjectID id = p_data[1]; - const String what = p_data[2]; - init_node(id); - NodeInfo &info = multiplayer_node_data[id]; - if (what == "rpc_in") { - info.incoming_rpc++; - } else if (what == "rpc_out") { - info.outgoing_rpc++; - } else if (what == "rset_in") { - info.incoming_rset = 0; - } else if (what == "rset_out") { - info.outgoing_rset++; - } - } else if (type == "bandwidth") { - ERR_FAIL_COND(p_data.size() < 4); - const String inout = p_data[1]; - int time = p_data[2]; - int size = p_data[3]; - if (inout == "in") { - bandwidth_in.write[bandwidth_in_ptr].timestamp = time; - bandwidth_in.write[bandwidth_in_ptr].packet_size = size; - bandwidth_in_ptr = (bandwidth_in_ptr + 1) % bandwidth_in.size(); - } else if (inout == "out") { - bandwidth_out.write[bandwidth_out_ptr].timestamp = time; - bandwidth_out.write[bandwidth_out_ptr].packet_size = size; - bandwidth_out_ptr = (bandwidth_out_ptr + 1) % bandwidth_out.size(); - } + ERR_FAIL_COND(p_data.size() < 3); + const String inout = p_data[0]; + int time = p_data[1]; + int size = p_data[2]; + if (inout == "in") { + bandwidth_in.write[bandwidth_in_ptr].timestamp = time; + bandwidth_in.write[bandwidth_in_ptr].packet_size = size; + bandwidth_in_ptr = (bandwidth_in_ptr + 1) % bandwidth_in.size(); + } else if (inout == "out") { + bandwidth_out.write[bandwidth_out_ptr].timestamp = time; + bandwidth_out.write[bandwidth_out_ptr].packet_size = size; + bandwidth_out_ptr = (bandwidth_out_ptr + 1) % bandwidth_out.size(); } } @@ -174,208 +117,17 @@ public: Array arr; arr.push_back(incoming_bandwidth); arr.push_back(outgoing_bandwidth); - EngineDebugger::get_singleton()->send_message("network:bandwidth", arr); - } - if (pt - last_profile_time > 100) { - last_profile_time = pt; - DebuggerMarshalls::NetworkProfilerFrame frame; - for (const KeyValue<ObjectID, NodeInfo> &E : multiplayer_node_data) { - frame.infos.push_back(E.value); - } - multiplayer_node_data.clear(); - EngineDebugger::get_singleton()->send_message("network:profile_frame", frame.serialize()); - } - } -}; - -struct RemoteDebugger::ScriptsProfiler { - typedef DebuggerMarshalls::ScriptFunctionSignature FunctionSignature; - typedef DebuggerMarshalls::ScriptFunctionInfo FunctionInfo; - struct ProfileInfoSort { - bool operator()(ScriptLanguage::ProfilingInfo *A, ScriptLanguage::ProfilingInfo *B) const { - return A->total_time < B->total_time; - } - }; - Vector<ScriptLanguage::ProfilingInfo> info; - Vector<ScriptLanguage::ProfilingInfo *> ptrs; - Map<StringName, int> sig_map; - int max_frame_functions = 16; - - void toggle(bool p_enable, const Array &p_opts) { - if (p_enable) { - sig_map.clear(); - for (int i = 0; i < ScriptServer::get_language_count(); i++) { - ScriptServer::get_language(i)->profiling_start(); - } - if (p_opts.size() == 1 && p_opts[0].get_type() == Variant::INT) { - max_frame_functions = MAX(0, int(p_opts[0])); - } - } else { - for (int i = 0; i < ScriptServer::get_language_count(); i++) { - ScriptServer::get_language(i)->profiling_stop(); - } + EngineDebugger::get_singleton()->send_message("multiplayer:bandwidth", arr); } } - - void write_frame_data(Vector<FunctionInfo> &r_funcs, uint64_t &r_total, bool p_accumulated) { - int ofs = 0; - for (int i = 0; i < ScriptServer::get_language_count(); i++) { - if (p_accumulated) { - ofs += ScriptServer::get_language(i)->profiling_get_accumulated_data(&info.write[ofs], info.size() - ofs); - } else { - ofs += ScriptServer::get_language(i)->profiling_get_frame_data(&info.write[ofs], info.size() - ofs); - } - } - - for (int i = 0; i < ofs; i++) { - ptrs.write[i] = &info.write[i]; - } - - SortArray<ScriptLanguage::ProfilingInfo *, ProfileInfoSort> sa; - sa.sort(ptrs.ptrw(), ofs); - - int to_send = MIN(ofs, max_frame_functions); - - // Check signatures first, and compute total time. - r_total = 0; - for (int i = 0; i < to_send; i++) { - if (!sig_map.has(ptrs[i]->signature)) { - int idx = sig_map.size(); - FunctionSignature sig; - sig.name = ptrs[i]->signature; - sig.id = idx; - EngineDebugger::get_singleton()->send_message("servers:function_signature", sig.serialize()); - sig_map[ptrs[i]->signature] = idx; - } - r_total += ptrs[i]->self_time; - } - - // Send frame, script time, functions information then - r_funcs.resize(to_send); - - FunctionInfo *w = r_funcs.ptrw(); - for (int i = 0; i < to_send; i++) { - if (sig_map.has(ptrs[i]->signature)) { - w[i].sig_id = sig_map[ptrs[i]->signature]; - } - w[i].call_count = ptrs[i]->call_count; - w[i].total_time = ptrs[i]->total_time / 1000000.0; - w[i].self_time = ptrs[i]->self_time / 1000000.0; - } - } - - ScriptsProfiler() { - info.resize(GLOBAL_GET("debug/settings/profiler/max_functions")); - ptrs.resize(info.size()); - } }; -struct RemoteDebugger::ServersProfiler { - bool skip_profile_frame = false; - typedef DebuggerMarshalls::ServerInfo ServerInfo; - typedef DebuggerMarshalls::ServerFunctionInfo ServerFunctionInfo; - - Map<StringName, ServerInfo> server_data; - ScriptsProfiler scripts_profiler; - - double frame_time = 0; - double idle_time = 0; - double physics_time = 0; - double physics_frame_time = 0; - - void toggle(bool p_enable, const Array &p_opts) { - skip_profile_frame = false; - if (p_enable) { - server_data.clear(); // Clear old profiling data. - } else { - _send_frame_data(true); // Send final frame. - } - scripts_profiler.toggle(p_enable, p_opts); - } - - void add(const Array &p_data) { - String name = p_data[0]; - if (!server_data.has(name)) { - ServerInfo info; - info.name = name; - server_data[name] = info; - } - ServerInfo &srv = server_data[name]; - - ServerFunctionInfo fi; - fi.name = p_data[1]; - fi.time = p_data[2]; - srv.functions.push_back(fi); - } - - void tick(double p_frame_time, double p_idle_time, double p_physics_time, double p_physics_frame_time) { - frame_time = p_frame_time; - idle_time = p_idle_time; - physics_time = p_physics_time; - physics_frame_time = p_physics_frame_time; - _send_frame_data(false); - } - - void _send_frame_data(bool p_final) { - DebuggerMarshalls::ServersProfilerFrame frame; - frame.frame_number = Engine::get_singleton()->get_process_frames(); - frame.frame_time = frame_time; - frame.idle_time = idle_time; - frame.physics_time = physics_time; - frame.physics_frame_time = physics_frame_time; - Map<StringName, ServerInfo>::Element *E = server_data.front(); - while (E) { - if (!p_final) { - frame.servers.push_back(E->get()); - } - E->get().functions.clear(); - E = E->next(); - } - uint64_t time = 0; - scripts_profiler.write_frame_data(frame.script_functions, time, p_final); - frame.script_time = USEC_TO_SEC(time); - if (skip_profile_frame) { - skip_profile_frame = false; - return; - } - if (p_final) { - EngineDebugger::get_singleton()->send_message("servers:profile_total", frame.serialize()); - } else { - EngineDebugger::get_singleton()->send_message("servers:profile_frame", frame.serialize()); - } - } -}; - -struct RemoteDebugger::VisualProfiler { - typedef DebuggerMarshalls::ServerInfo ServerInfo; - typedef DebuggerMarshalls::ServerFunctionInfo ServerFunctionInfo; - - Map<StringName, ServerInfo> server_data; - - void toggle(bool p_enable, const Array &p_opts) { - RS::get_singleton()->set_frame_profiling_enabled(p_enable); - } - - void add(const Array &p_data) {} - - void tick(double p_frame_time, double p_idle_time, double p_physics_time, double p_physics_frame_time) { - Vector<RS::FrameProfileArea> profile_areas = RS::get_singleton()->get_frame_profile(); - DebuggerMarshalls::VisualProfilerFrame frame; - if (!profile_areas.size()) { - return; - } - - frame.frame_number = RS::get_singleton()->get_frame_profile_frame(); - frame.areas.append_array(profile_areas); - EngineDebugger::get_singleton()->send_message("visual:profile_frame", frame.serialize()); - } -}; - -struct RemoteDebugger::PerformanceProfiler { +class RemoteDebugger::PerformanceProfiler : public EngineProfiler { Object *performance = nullptr; int last_perf_time = 0; uint64_t last_monitor_modification_time = 0; +public: void toggle(bool p_enable, const Array &p_opts) {} void add(const Array &p_data) {} void tick(double p_frame_time, double p_idle_time, double p_physics_time, double p_physics_frame_time) { @@ -421,29 +173,6 @@ struct RemoteDebugger::PerformanceProfiler { } }; -void RemoteDebugger::_send_resource_usage() { - DebuggerMarshalls::ResourceUsage usage; - - List<RS::TextureInfo> tinfo; - RS::get_singleton()->texture_debug_usage(&tinfo); - - for (const RS::TextureInfo &E : tinfo) { - DebuggerMarshalls::ResourceInfo info; - info.path = E.path; - info.vram = E.bytes; - info.id = E.texture; - info.type = "Texture"; - if (E.depth == 0) { - info.format = itos(E.width) + "x" + itos(E.height) + " " + Image::get_format_name(E.format); - } else { - info.format = itos(E.width) + "x" + itos(E.height) + "x" + itos(E.depth) + " " + Image::get_format_name(E.format); - } - usage.infos.push_back(info); - } - - EngineDebugger::get_singleton()->send_message("memory:usage", usage.serialize()); -} - Error RemoteDebugger::_put_msg(String p_message, Array p_data) { Array msg; msg.push_back(p_message); @@ -710,18 +439,12 @@ void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) { msg.push_back(script_lang->debug_get_stack_level_count() > 0); send_message("debug_enter", msg); - servers_profiler->skip_profile_frame = true; // Avoid frame time spike in debug. - Input::MouseMode mouse_mode = Input::get_singleton()->get_mouse_mode(); if (mouse_mode != Input::MOUSE_MODE_VISIBLE) { Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE); } - uint64_t loop_begin_usec = 0; - uint64_t loop_time_sec = 0; while (is_peer_connected()) { - loop_begin_usec = OS::get_singleton()->get_ticks_usec(); - flush_output(); peer->poll(); @@ -748,7 +471,6 @@ void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) { } else if (command == "continue") { script_debugger->set_depth(-1); script_debugger->set_lines_left(-1); - DisplayServer::get_singleton()->window_move_to_foreground(); break; } else if (command == "break") { @@ -824,13 +546,6 @@ void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) { OS::get_singleton()->delay_usec(10000); OS::get_singleton()->process_and_drop_events(); } - - // This is for the camera override to stay live even when the game is paused from the editor - loop_time_sec = (OS::get_singleton()->get_ticks_usec() - loop_begin_usec) / 1000000.0f; - RenderingServer::get_singleton()->sync(); - if (RenderingServer::get_singleton()->has_changed()) { - RenderingServer::get_singleton()->draw(true, loop_time_sec * Engine::get_singleton()->get_time_scale()); - } } send_message("debug_exit", Array()); @@ -897,8 +612,6 @@ Error RemoteDebugger::_core_capture(const String &p_cmd, const Array &p_data, bo } else if (p_cmd == "set_skip_breakpoints") { ERR_FAIL_COND_V(p_data.size() < 1, ERR_INVALID_DATA); script_debugger->set_skip_breakpoints(p_data[0]); - } else if (p_cmd == "memory") { - _send_resource_usage(); } else if (p_cmd == "break") { script_debugger->debug(script_debugger->get_break_language()); } else { @@ -928,23 +641,15 @@ RemoteDebugger::RemoteDebugger(Ref<RemoteDebuggerPeer> p_peer) { max_errors_per_second = GLOBAL_GET("network/limits/debugger/max_errors_per_second"); max_warnings_per_second = GLOBAL_GET("network/limits/debugger/max_warnings_per_second"); - // Network Profiler - network_profiler = memnew(NetworkProfiler); - _bind_profiler("network", network_profiler); - - // Servers Profiler (audio/physics/...) - servers_profiler = memnew(ServersProfiler); - _bind_profiler("servers", servers_profiler); - - // Visual Profiler (cpu/gpu times) - visual_profiler = memnew(VisualProfiler); - _bind_profiler("visual", visual_profiler); + // Multiplayer Profiler + multiplayer_profiler.instantiate(); + multiplayer_profiler->bind("multiplayer"); // Performance Profiler Object *perf = Engine::get_singleton()->get_singleton_object("Performance"); if (perf) { - performance_profiler = memnew(PerformanceProfiler(perf)); - _bind_profiler("performance", performance_profiler); + performance_profiler = Ref<PerformanceProfiler>(memnew(PerformanceProfiler(perf))); + performance_profiler->bind("performance"); profiler_enable("performance", true); } @@ -973,17 +678,4 @@ RemoteDebugger::RemoteDebugger(Ref<RemoteDebuggerPeer> p_peer) { RemoteDebugger::~RemoteDebugger() { remove_print_handler(&phl); remove_error_handler(&eh); - - EngineDebugger::get_singleton()->unregister_profiler("servers"); - EngineDebugger::get_singleton()->unregister_profiler("network"); - EngineDebugger::get_singleton()->unregister_profiler("visual"); - if (EngineDebugger::has_profiler("performance")) { - EngineDebugger::get_singleton()->unregister_profiler("performance"); - } - memdelete(servers_profiler); - memdelete(network_profiler); - memdelete(visual_profiler); - if (performance_profiler) { - memdelete(performance_profiler); - } } diff --git a/core/debugger/remote_debugger.h b/core/debugger/remote_debugger.h index bd64955c89..aada92da60 100644 --- a/core/debugger/remote_debugger.h +++ b/core/debugger/remote_debugger.h @@ -49,16 +49,11 @@ public: private: typedef DebuggerMarshalls::OutputError ErrorMessage; - struct NetworkProfiler; - struct ServersProfiler; - struct ScriptsProfiler; - struct VisualProfiler; - struct PerformanceProfiler; + class MultiplayerProfiler; + class PerformanceProfiler; - NetworkProfiler *network_profiler = nullptr; - ServersProfiler *servers_profiler = nullptr; - VisualProfiler *visual_profiler = nullptr; - PerformanceProfiler *performance_profiler = nullptr; + Ref<MultiplayerProfiler> multiplayer_profiler; + Ref<PerformanceProfiler> performance_profiler; Ref<RemoteDebuggerPeer> peer; @@ -97,7 +92,6 @@ private: bool is_peer_connected() { return peer->is_peer_connected(); } void flush_output(); - void _send_resource_usage(); void _send_stack_vars(List<String> &p_names, List<Variant> &p_vals, int p_type); Error _profiler_capture(const String &p_cmd, const Array &p_data, bool &r_captured); diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp index 555d4f6df4..a363cc3694 100644 --- a/core/io/marshalls.cpp +++ b/core/io/marshalls.cpp @@ -1030,7 +1030,7 @@ static void _encode_string(const String &p_string, uint8_t *&buf, int &r_len) { } Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bool p_full_objects, int p_depth) { - ERR_FAIL_COND_V_MSG(p_depth > Variant::MAX_RECURSION_DEPTH, ERR_OUT_OF_MEMORY, "Potential inifite recursion detected. Bailing."); + ERR_FAIL_COND_V_MSG(p_depth > Variant::MAX_RECURSION_DEPTH, ERR_OUT_OF_MEMORY, "Potential infinite recursion detected. Bailing."); uint8_t *buf = r_buffer; r_len = 0; diff --git a/core/multiplayer/multiplayer_api.cpp b/core/multiplayer/multiplayer_api.cpp index c8cb333e2c..3533acd103 100644 --- a/core/multiplayer/multiplayer_api.cpp +++ b/core/multiplayer/multiplayer_api.cpp @@ -47,7 +47,6 @@ MultiplayerCacheInterface *(*MultiplayerAPI::create_default_cache_interface)(Mul void MultiplayerAPI::profile_bandwidth(const String &p_inout, int p_size) { if (EngineDebugger::is_profiling("multiplayer")) { Array values; - values.push_back("bandwidth"); values.push_back(p_inout); values.push_back(OS::get_singleton()->get_ticks_msec()); values.push_back(p_size); diff --git a/core/register_core_types.cpp b/core/register_core_types.cpp index 388368d181..a4b6a589f3 100644 --- a/core/register_core_types.cpp +++ b/core/register_core_types.cpp @@ -37,6 +37,7 @@ #include "core/crypto/aes_context.h" #include "core/crypto/crypto.h" #include "core/crypto/hashing_context.h" +#include "core/debugger/engine_profiler.h" #include "core/extension/native_extension.h" #include "core/extension/native_extension_manager.h" #include "core/input/input.h" @@ -237,6 +238,8 @@ void register_core_types() { GDREGISTER_VIRTUAL_CLASS(ResourceUID); + GDREGISTER_CLASS(EngineProfiler); + resource_uid = memnew(ResourceUID); native_extension_manager = memnew(NativeExtensionManager); diff --git a/core/string/string_name.h b/core/string/string_name.h index f767f3e1ec..6f08d32981 100644 --- a/core/string/string_name.h +++ b/core/string/string_name.h @@ -188,7 +188,7 @@ StringName _scs_create(const char *p_chr, bool p_static = false); * - Control::get_theme_*(<name> and Window::get_theme_*(<name> functions. * - emit_signal(<name>,..) function * - call_deferred(<name>,..) function - * - Comparisons to a StringName in overriden _set and _get methods. + * - Comparisons to a StringName in overridden _set and _get methods. * * Use in places that can be called hundreds of times per frame (or more) is recommended, but this situation is very rare. If in doubt, do not use. */ diff --git a/doc/classes/EngineDebugger.xml b/doc/classes/EngineDebugger.xml index 861053b1c9..3c2f735e72 100644 --- a/doc/classes/EngineDebugger.xml +++ b/doc/classes/EngineDebugger.xml @@ -65,14 +65,9 @@ <method name="register_profiler"> <return type="void" /> <argument index="0" name="name" type="StringName" /> - <argument index="1" name="toggle" type="Callable" /> - <argument index="2" name="add" type="Callable" /> - <argument index="3" name="tick" type="Callable" /> + <argument index="1" name="profiler" type="EngineProfiler" /> <description> - Registers a profiler with the given [code]name[/code]. - [code]toggle[/code] callable is called when the profiler is enabled/disabled. It must take an argument array as an argument. - [code]add[/code] callable is called when data is added to profiler using [method EngineDebugger.profiler_add_frame_data]. It must take a data array as argument. - [code]tick[/code] callable is called at every active profiler iteration. It must take frame time, idle time, physics time, and physics idle time as arguments. + Registers a profiler with the given [code]name[/code]. See [EngineProfiler] for more information. </description> </method> <method name="send_message"> diff --git a/doc/classes/EngineProfiler.xml b/doc/classes/EngineProfiler.xml new file mode 100644 index 0000000000..60817338b8 --- /dev/null +++ b/doc/classes/EngineProfiler.xml @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="EngineProfiler" inherits="RefCounted" version="4.0"> + <brief_description> + Base class for creating custom profilers. + </brief_description> + <description> + This class can be used to implement custom profilers that are able to interact with the engine and editor debugger. + See [EngineDebugger] and [EditorDebuggerPlugin] for more information. + </description> + <tutorials> + </tutorials> + <methods> + <method name="_add_frame" qualifiers="virtual"> + <return type="void" /> + <argument index="0" name="data" type="Array" /> + <description> + Called when data is added to profiler using [method EngineDebugger.profiler_add_frame_data]. + </description> + </method> + <method name="_tick" qualifiers="virtual"> + <return type="void" /> + <argument index="0" name="frame_time" type="float" /> + <argument index="1" name="idle_time" type="float" /> + <argument index="2" name="physics_time" type="float" /> + <argument index="3" name="physics_frame_time" type="float" /> + <description> + Called once every engine iteration when the profiler is active with information about the current frame. + </description> + </method> + <method name="_toggle" qualifiers="virtual"> + <return type="void" /> + <argument index="0" name="enable" type="bool" /> + <argument index="1" name="options" type="Array" /> + <description> + Called when the profiler is enabled/disabled, along with a set of [code]options[/code]. + </description> + </method> + </methods> +</class> diff --git a/doc/classes/Environment.xml b/doc/classes/Environment.xml index c8c0494378..f2dbcec228 100644 --- a/doc/classes/Environment.xml +++ b/doc/classes/Environment.xml @@ -171,11 +171,11 @@ </member> <member name="reflected_light_source" type="int" setter="set_reflection_source" getter="get_reflection_source" enum="Environment.ReflectionSource" default="0"> </member> - <member name="sdfgi_bounce_feedback" type="float" setter="set_sdfgi_bounce_feedback" getter="get_sdfgi_bounce_feedback" default="0.0"> + <member name="sdfgi_bounce_feedback" type="float" setter="set_sdfgi_bounce_feedback" getter="get_sdfgi_bounce_feedback" default="0.5"> </member> <member name="sdfgi_cascade0_distance" type="float" setter="set_sdfgi_cascade0_distance" getter="get_sdfgi_cascade0_distance" default="12.8"> </member> - <member name="sdfgi_cascades" type="int" setter="set_sdfgi_cascades" getter="get_sdfgi_cascades" default="6"> + <member name="sdfgi_cascades" type="int" setter="set_sdfgi_cascades" getter="get_sdfgi_cascades" default="4"> The number of cascades to use for SDFGI (between 1 and 8). A higher number of cascades allows displaying SDFGI further away while preserving detail up close, at the cost of performance. When using SDFGI on small-scale levels, [member sdfgi_cascades] can often be decreased between [code]1[/code] and [code]4[/code] to improve performance. </member> <member name="sdfgi_enabled" type="bool" setter="set_sdfgi_enabled" getter="is_sdfgi_enabled" default="false"> @@ -185,7 +185,7 @@ </member> <member name="sdfgi_energy" type="float" setter="set_sdfgi_energy" getter="get_sdfgi_energy" default="1.0"> </member> - <member name="sdfgi_max_distance" type="float" setter="set_sdfgi_max_distance" getter="get_sdfgi_max_distance" default="819.2"> + <member name="sdfgi_max_distance" type="float" setter="set_sdfgi_max_distance" getter="get_sdfgi_max_distance" default="204.8"> </member> <member name="sdfgi_min_cell_size" type="float" setter="set_sdfgi_min_cell_size" getter="get_sdfgi_min_cell_size" default="0.2"> </member> @@ -193,11 +193,11 @@ </member> <member name="sdfgi_probe_bias" type="float" setter="set_sdfgi_probe_bias" getter="get_sdfgi_probe_bias" default="1.1"> </member> - <member name="sdfgi_read_sky_light" type="bool" setter="set_sdfgi_read_sky_light" getter="is_sdfgi_reading_sky_light" default="false"> + <member name="sdfgi_read_sky_light" type="bool" setter="set_sdfgi_read_sky_light" getter="is_sdfgi_reading_sky_light" default="true"> </member> <member name="sdfgi_use_occlusion" type="bool" setter="set_sdfgi_use_occlusion" getter="is_sdfgi_using_occlusion" default="false"> </member> - <member name="sdfgi_y_scale" type="int" setter="set_sdfgi_y_scale" getter="get_sdfgi_y_scale" enum="Environment.SDFGIYScale" default="0"> + <member name="sdfgi_y_scale" type="int" setter="set_sdfgi_y_scale" getter="get_sdfgi_y_scale" enum="Environment.SDFGIYScale" default="1"> </member> <member name="sky" type="Sky" setter="set_sky" getter="get_sky"> The [Sky] resource used for this [Environment]. @@ -379,11 +379,11 @@ <constant name="GLOW_BLEND_MODE_MIX" value="4" enum="GlowBlendMode"> Mixes the glow with the underlying color to avoid increasing brightness as much while still maintaining a glow effect. </constant> - <constant name="SDFGI_Y_SCALE_DISABLED" value="0" enum="SDFGIYScale"> + <constant name="SDFGI_Y_SCALE_50_PERCENT" value="0" enum="SDFGIYScale"> </constant> <constant name="SDFGI_Y_SCALE_75_PERCENT" value="1" enum="SDFGIYScale"> </constant> - <constant name="SDFGI_Y_SCALE_50_PERCENT" value="2" enum="SDFGIYScale"> + <constant name="SDFGI_Y_SCALE_100_PERCENT" value="2" enum="SDFGIYScale"> </constant> </constants> </class> diff --git a/doc/classes/FontData.xml b/doc/classes/FontData.xml index 55b715c3fc..658f7dd34d 100644 --- a/doc/classes/FontData.xml +++ b/doc/classes/FontData.xml @@ -577,7 +577,7 @@ Font style flags, see [enum TextServer.FontStyle]. </member> <member name="force_autohinter" type="bool" setter="set_force_autohinter" getter="is_force_autohinter" default="false"> - If set to [code]true[/code], auto-hinting is supported and preffered over font built-in hinting. Used by dynamic fonts only. + If set to [code]true[/code], auto-hinting is supported and preferred over font built-in hinting. Used by dynamic fonts only. </member> <member name="hinting" type="int" setter="set_hinting" getter="get_hinting" enum="TextServer.Hinting" default="1"> Font hinting mode. Used by dynamic fonts only. diff --git a/doc/classes/GPUParticles2D.xml b/doc/classes/GPUParticles2D.xml index f97198658e..1fde3c8463 100644 --- a/doc/classes/GPUParticles2D.xml +++ b/doc/classes/GPUParticles2D.xml @@ -119,7 +119,7 @@ Particle starts with specified color. </constant> <constant name="EMIT_FLAG_CUSTOM" value="16" enum="EmitFlags"> - Particle starts with specificed [code]CUSTOM[/code] data. + Particle starts with specified [code]CUSTOM[/code] data. </constant> </constants> </class> diff --git a/doc/classes/GPUParticles3D.xml b/doc/classes/GPUParticles3D.xml index 62ac846077..fc490eac96 100644 --- a/doc/classes/GPUParticles3D.xml +++ b/doc/classes/GPUParticles3D.xml @@ -150,7 +150,7 @@ Particle starts with specified color. </constant> <constant name="EMIT_FLAG_CUSTOM" value="16" enum="EmitFlags"> - Particle starts with specificed [code]CUSTOM[/code] data. + Particle starts with specified [code]CUSTOM[/code] data. </constant> <constant name="MAX_DRAW_PASSES" value="4"> Maximum number of draw passes supported. diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml index 8c3d578062..4b5f7b2091 100644 --- a/doc/classes/ProjectSettings.xml +++ b/doc/classes/ProjectSettings.xml @@ -1696,13 +1696,13 @@ If [code]true[/code], renders [VoxelGI] and SDFGI ([member Environment.sdfgi_enabled]) buffers at halved resolution (e.g. 960×540 when the viewport size is 1920×1080). This improves performance significantly when VoxelGI or SDFGI is enabled, at the cost of artifacts that may be visible on polygon edges. The loss in quality becomes less noticeable as the viewport resolution increases. [LightmapGI] rendering is not affected by this setting. [b]Note:[/b] This property is only read when the project starts. To set half-resolution GI at run-time, call [method RenderingServer.gi_set_use_half_resolution] instead. </member> - <member name="rendering/global_illumination/sdfgi/frames_to_converge" type="int" setter="" getter="" default="4"> + <member name="rendering/global_illumination/sdfgi/frames_to_converge" type="int" setter="" getter="" default="5"> </member> <member name="rendering/global_illumination/sdfgi/frames_to_update_lights" type="int" setter="" getter="" default="2"> </member> <member name="rendering/global_illumination/sdfgi/probe_ray_count" type="int" setter="" getter="" default="1"> </member> - <member name="rendering/global_illumination/voxel_gi/quality" type="int" setter="" getter="" default="1"> + <member name="rendering/global_illumination/voxel_gi/quality" type="int" setter="" getter="" default="0"> </member> <member name="rendering/lightmapping/bake_performance/max_rays_per_pass" type="int" setter="" getter="" default="32"> </member> @@ -1830,7 +1830,7 @@ <member name="rendering/shadows/directional_shadow/size.mobile" type="int" setter="" getter="" default="2048"> Lower-end override for [member rendering/shadows/directional_shadow/size] on mobile devices, due to performance concerns or driver support. </member> - <member name="rendering/shadows/directional_shadow/soft_shadow_quality" type="int" setter="" getter="" default="3"> + <member name="rendering/shadows/directional_shadow/soft_shadow_quality" type="int" setter="" getter="" default="2"> Quality setting for shadows cast by [DirectionalLight3D]s. Higher quality settings use more samples when reading from shadow maps and are thus slower. Low quality settings may result in shadows looking grainy. [b]Note:[/b] The Soft Very Low setting will automatically multiply [i]constant[/i] shadow blur by 0.75x to reduce the amount of noise visible. This automatic blur change only affects the constant blur factor defined in [member Light3D.shadow_blur], not the variable blur performed by [DirectionalLight3D]s' [member Light3D.light_angular_distance]. [b]Note:[/b] The Soft High and Soft Ultra settings will automatically multiply [i]constant[/i] shadow blur by 1.5× and 2× respectively to make better use of the increased sample count. This increased blur also improves stability of dynamic object shadows. @@ -1858,7 +1858,7 @@ <member name="rendering/shadows/shadow_atlas/size.mobile" type="int" setter="" getter="" default="2048"> Lower-end override for [member rendering/shadows/shadow_atlas/size] on mobile devices, due to performance concerns or driver support. </member> - <member name="rendering/shadows/shadows/soft_shadow_quality" type="int" setter="" getter="" default="3"> + <member name="rendering/shadows/shadows/soft_shadow_quality" type="int" setter="" getter="" default="2"> Quality setting for shadows cast by [OmniLight3D]s and [SpotLight3D]s. Higher quality settings use more samples when reading from shadow maps and are thus slower. Low quality settings may result in shadows looking grainy. [b]Note:[/b] The Soft Very Low setting will automatically multiply [i]constant[/i] shadow blur by 0.75x to reduce the amount of noise visible. This automatic blur change only affects the constant blur factor defined in [member Light3D.shadow_blur], not the variable blur performed by [DirectionalLight3D]s' [member Light3D.light_angular_distance]. [b]Note:[/b] The Soft High and Soft Ultra settings will automatically multiply shadow blur by 1.5× and 2× respectively to make better use of the increased sample count. This increased blur also improves stability of dynamic object shadows. diff --git a/doc/classes/RenderingServer.xml b/doc/classes/RenderingServer.xml index 82728c0570..82436b10a5 100644 --- a/doc/classes/RenderingServer.xml +++ b/doc/classes/RenderingServer.xml @@ -4181,11 +4181,11 @@ <constant name="ENV_SSIL_QUALITY_ULTRA" value="4" enum="EnvironmentSSILQuality"> Highest quality screen-space indirect lighting. Uses the adaptive target setting which can be dynamically adjusted to smoothly balance performance and visual quality. </constant> - <constant name="ENV_SDFGI_Y_SCALE_DISABLED" value="0" enum="EnvironmentSDFGIYScale"> + <constant name="ENV_SDFGI_Y_SCALE_50_PERCENT" value="0" enum="EnvironmentSDFGIYScale"> </constant> <constant name="ENV_SDFGI_Y_SCALE_75_PERCENT" value="1" enum="EnvironmentSDFGIYScale"> </constant> - <constant name="ENV_SDFGI_Y_SCALE_50_PERCENT" value="2" enum="EnvironmentSDFGIYScale"> + <constant name="ENV_SDFGI_Y_SCALE_100_PERCENT" value="2" enum="EnvironmentSDFGIYScale"> </constant> <constant name="ENV_SDFGI_RAY_COUNT_4" value="0" enum="EnvironmentSDFGIRayCount"> </constant> diff --git a/doc/classes/RichTextLabel.xml b/doc/classes/RichTextLabel.xml index 95dffd3e28..6a2812bb93 100644 --- a/doc/classes/RichTextLabel.xml +++ b/doc/classes/RichTextLabel.xml @@ -55,6 +55,12 @@ Returns the height of the content. </description> </method> + <method name="get_content_width" qualifiers="const"> + <return type="int" /> + <description> + Returns the width of the content. + </description> + </method> <method name="get_line_count" qualifiers="const"> <return type="int" /> <description> diff --git a/doc/classes/TextServerExtension.xml b/doc/classes/TextServerExtension.xml index b500bd5658..b212cec5f2 100644 --- a/doc/classes/TextServerExtension.xml +++ b/doc/classes/TextServerExtension.xml @@ -557,7 +557,7 @@ <argument index="0" name="font_rid" type="RID" /> <argument index="1" name="force_autohinter" type="bool" /> <description> - If set to [code]true[/code] auto-hinting is preffered over font built-in hinting. + If set to [code]true[/code] auto-hinting is preferred over font built-in hinting. </description> </method> <method name="_font_set_global_oversampling" qualifiers="virtual"> diff --git a/doc/classes/TranslationServer.xml b/doc/classes/TranslationServer.xml index 6ece42da6b..546b7ec242 100644 --- a/doc/classes/TranslationServer.xml +++ b/doc/classes/TranslationServer.xml @@ -138,7 +138,7 @@ <return type="String" /> <argument index="0" name="locale" type="String" /> <description> - Retunrs [code]locale[/code] string standardized to match known locales (e.g. [code]en-US[/code] would be matched to [code]en_US[/code]). + Returns [code]locale[/code] string standardized to match known locales (e.g. [code]en-US[/code] would be matched to [code]en_US[/code]). </description> </method> <method name="translate" qualifiers="const"> diff --git a/doc/classes/Viewport.xml b/doc/classes/Viewport.xml index 9d60360f1b..93c1e8417b 100644 --- a/doc/classes/Viewport.xml +++ b/doc/classes/Viewport.xml @@ -55,7 +55,7 @@ <method name="get_mouse_position" qualifiers="const"> <return type="Vector2" /> <description> - Returns the mouse's positon in this [Viewport] using the coordinate system of this [Viewport]. + Returns the mouse's position in this [Viewport] using the coordinate system of this [Viewport]. </description> </method> <method name="get_render_info"> @@ -128,7 +128,7 @@ <method name="gui_release_focus"> <return type="void" /> <description> - Removes the focus from the currently focussed [Control] within this viewport. If no [Control] has the focus, does nothing. + Removes the focus from the currently focused [Control] within this viewport. If no [Control] has the focus, does nothing. </description> </method> <method name="is_embedding_subwindows" qualifiers="const"> diff --git a/doc/tools/make_rst.py b/doc/tools/make_rst.py index 68f3b66f43..365beb434b 100755 --- a/doc/tools/make_rst.py +++ b/doc/tools/make_rst.py @@ -536,19 +536,19 @@ def make_rst_class(class_def, state, dry_run, output_dir): # type: (ClassDef, S # Inheritance tree # Ascendants if class_def.inherits: - inh = class_def.inherits.strip() + inherits = class_def.inherits.strip() f.write("**" + translate("Inherits:") + "** ") first = True - while inh in state.classes: + while inherits in state.classes: if not first: f.write(" **<** ") else: first = False - f.write(make_type(inh, state)) - inode = state.classes[inh].inherits + f.write(make_type(inherits, state)) + inode = state.classes[inherits].inherits if inode: - inh = inode.strip() + inherits = inode.strip() else: break f.write("\n\n") diff --git a/doc/translations/classes.pot b/doc/translations/classes.pot index a802e3a7ac..ca8bc21508 100644 --- a/doc/translations/classes.pot +++ b/doc/translations/classes.pot @@ -34818,7 +34818,7 @@ msgstr "" #: doc/classes/NavigationAgent.xml doc/classes/NavigationAgent2D.xml msgid "" "The minimal amount of time for which this agent's velocities, that are " -"computed with the collision avoidance algorithim, are safe with respect to " +"computed with the collision avoidance algorithm, are safe with respect to " "other agents. The larger the number, the sooner the agent will respond to " "other agents, but the less freedom in choosing its velocities. Must be " "positive." diff --git a/doc/translations/extract.py b/doc/translations/extract.py index f8223701d5..1295495392 100644 --- a/doc/translations/extract.py +++ b/doc/translations/extract.py @@ -224,6 +224,8 @@ def _make_translation_catalog(classes): if elem.tag in EXTRACT_TAGS: if not elem.text or len(elem.text) == 0: continue + if elem.tag == "link" and "$DOCS_URL" in elem.text: # No need to localize. + continue line_no = elem._start_line_number if elem.text[0] != "\n" else elem._start_line_number + 1 desc_str = elem.text.strip() code_block_regions = _make_codeblock_regions(desc_str, desc_list.path) diff --git a/drivers/gles3/rasterizer_scene_gles3.h b/drivers/gles3/rasterizer_scene_gles3.h index 246b908c14..12bb21a5a0 100644 --- a/drivers/gles3/rasterizer_scene_gles3.h +++ b/drivers/gles3/rasterizer_scene_gles3.h @@ -78,11 +78,11 @@ public: /* SHADOW ATLAS API */ RID shadow_atlas_create() override; - void shadow_atlas_set_size(RID p_atlas, int p_size, bool p_16_bits = false) override; + void shadow_atlas_set_size(RID p_atlas, int p_size, bool p_16_bits = true) override; void shadow_atlas_set_quadrant_subdivision(RID p_atlas, int p_quadrant, int p_subdivision) override; bool shadow_atlas_update_light(RID p_atlas, RID p_light_intance, float p_coverage, uint64_t p_light_version) override; - void directional_shadow_atlas_set_size(int p_size, bool p_16_bits = false) override; + void directional_shadow_atlas_set_size(int p_size, bool p_16_bits = true) override; int get_directional_light_shadow_size(RID p_light_intance) override; void set_directional_shadow_count(int p_count) override; diff --git a/drivers/vulkan/vulkan_context.cpp b/drivers/vulkan/vulkan_context.cpp index 689d76ba26..1aa1bfddc8 100644 --- a/drivers/vulkan/vulkan_context.cpp +++ b/drivers/vulkan/vulkan_context.cpp @@ -860,7 +860,7 @@ Error VulkanContext::_create_physical_device(VkSurfaceKHR p_surface) { free(device_queue_props); print_verbose(" #" + itos(i) + ": " + vendor + " " + name + " - " + (present_supported ? "Supported" : "Unsupported") + ", " + dev_type); - if (present_supported) { // Select first supported device of preffered type: Discrete > Integrated > Virtual > CPU > Other. + if (present_supported) { // Select first supported device of preferred type: Discrete > Integrated > Virtual > CPU > Other. switch (props.deviceType) { case VkPhysicalDeviceType::VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU: { if (type_selected < 4) { diff --git a/editor/animation_bezier_editor.cpp b/editor/animation_bezier_editor.cpp index da376c588e..67cdba043a 100644 --- a/editor/animation_bezier_editor.cpp +++ b/editor/animation_bezier_editor.cpp @@ -35,6 +35,8 @@ #include "scene/gui/view_panner.h" #include "scene/resources/text_line.h" +#include <limits.h> + float AnimationBezierTrackEdit::_bezier_h_to_pixel(float p_h) { float h = p_h; h = (h - v_scroll) / v_zoom; @@ -55,15 +57,16 @@ static _FORCE_INLINE_ Vector2 _bezier_interp(real_t t, const Vector2 &start, con void AnimationBezierTrackEdit::_draw_track(int p_track, const Color &p_color) { float scale = timeline->get_zoom_scale(); + int limit = timeline->get_name_limit(); - int right_limit = get_size().width - timeline->get_buttons_width(); + int right_limit = get_size().width; //selection may have altered the order of keys Map<float, int> key_order; for (int i = 0; i < animation->track_get_key_count(p_track); i++) { float ofs = animation->track_get_key_time(p_track, i); - if (moving_selection && track == p_track && selection.has(i)) { + if (moving_selection && selection.has(IntPair(p_track, i))) { ofs += moving_selection_offset.x; } @@ -82,11 +85,11 @@ void AnimationBezierTrackEdit::_draw_track(int p_track, const Color &p_color) { float offset = animation->track_get_key_time(p_track, i); float height = animation->bezier_track_get_key_value(p_track, i); Vector2 out_handle = animation->bezier_track_get_key_out_handle(p_track, i); - if (track == p_track && moving_handle != 0 && moving_handle_key == i) { + if (p_track == moving_handle_track && moving_handle != 0 && moving_handle_key == i) { out_handle = moving_handle_right; } - if (moving_selection && track == p_track && selection.has(i)) { + if (moving_selection && selection.has(IntPair(p_track, i))) { offset += moving_selection_offset.x; height += moving_selection_offset.y; } @@ -96,11 +99,11 @@ void AnimationBezierTrackEdit::_draw_track(int p_track, const Color &p_color) { float offset_n = animation->track_get_key_time(p_track, i_n); float height_n = animation->bezier_track_get_key_value(p_track, i_n); Vector2 in_handle = animation->bezier_track_get_key_in_handle(p_track, i_n); - if (track == p_track && moving_handle != 0 && moving_handle_key == i_n) { + if (p_track == moving_handle_track && moving_handle != 0 && moving_handle_key == i_n) { in_handle = moving_handle_left; } - if (moving_selection && track == p_track && selection.has(i_n)) { + if (moving_selection && selection.has(IntPair(p_track, i_n))) { offset_n += moving_selection_offset.x; height_n += moving_selection_offset.y; } @@ -221,20 +224,10 @@ void AnimationBezierTrackEdit::_notification(int p_what) { panner->setup((ViewPanner::ControlScheme)EDITOR_GET("editors/panning/animation_editors_panning_scheme").operator int(), ED_GET_SHORTCUT("canvas_item_editor/pan_view"), bool(EditorSettings::get_singleton()->get("editors/panning/simple_panning"))); } if (p_what == NOTIFICATION_THEME_CHANGED || p_what == NOTIFICATION_ENTER_TREE) { - close_button->set_icon(get_theme_icon(SNAME("Close"), SNAME("EditorIcons"))); - bezier_icon = get_theme_icon(SNAME("KeyBezierPoint"), SNAME("EditorIcons")); bezier_handle_icon = get_theme_icon(SNAME("KeyBezierHandle"), SNAME("EditorIcons")); selected_icon = get_theme_icon(SNAME("KeyBezierSelected"), SNAME("EditorIcons")); } - if (p_what == NOTIFICATION_RESIZED) { - int right_limit = get_size().width - timeline->get_buttons_width(); - int hsep = get_theme_constant(SNAME("hseparation"), SNAME("ItemList")); - int vsep = get_theme_constant(SNAME("vseparation"), SNAME("ItemList")); - - right_column->set_position(Vector2(right_limit + hsep, vsep)); - right_column->set_size(Vector2(timeline->get_buttons_width() - hsep * 2, get_size().y - vsep * 2)); - } if (p_what == NOTIFICATION_DRAW) { if (animation.is_null()) { return; @@ -258,101 +251,191 @@ void AnimationBezierTrackEdit::_notification(int p_what) { draw_line(Point2(limit, 0), Point2(limit, get_size().height), linecolor, Math::round(EDSCALE)); - int right_limit = get_size().width - timeline->get_buttons_width(); + int right_limit = get_size().width; - draw_line(Point2(right_limit, 0), Point2(right_limit, get_size().height), linecolor, Math::round(EDSCALE)); - - String base_path = animation->track_get_path(track); - int end = base_path.find(":"); - if (end != -1) { - base_path = base_path.substr(0, end + 1); - } - - // NAMES AND ICON int vofs = vsep; int margin = 0; - { - NodePath path = animation->track_get_path(track); + Map<int, Color> subtrack_colors; + Color selected_track_color; + subtracks.clear(); + subtrack_icons.clear(); + + Map<String, Vector<int>> track_indices; + int track_count = animation->get_track_count(); + for (int i = 0; i < track_count; ++i) { + if (animation->track_get_type(i) != Animation::TrackType::TYPE_BEZIER) { + continue; + } - Node *node = nullptr; + String base_path = animation->track_get_path(i); + if (is_filtered) { + if (root && root->has_node(base_path)) { + Node *node = root->get_node(base_path); + if (!node) { + continue; // No node, no filter. + } + if (!EditorNode::get_singleton()->get_editor_selection()->is_selected(node)) { + continue; // Skip track due to not selected. + } + } + } - if (root && root->has_node(path)) { - node = root->get_node(path); + int end = base_path.find(":"); + if (end != -1) { + base_path = base_path.substr(0, end + 1); } + Vector<int> indices = track_indices.has(base_path) ? track_indices[base_path] : Vector<int>(); + indices.push_back(i); + track_indices[base_path] = indices; + } - String text; + for (const KeyValue<String, Vector<int>> &E : track_indices) { + String base_path = E.key; - if (node) { - int ofs = 0; + Vector<int> tracks = E.value; - Ref<Texture2D> icon = EditorNode::get_singleton()->get_object_icon(node, "Node"); + // NAMES AND ICON + { + NodePath path = animation->track_get_path(tracks[0]); - text = node->get_name(); - ofs += hsep; - ofs += icon->get_width(); + Node *node = nullptr; - TextLine text_buf = TextLine(text, font, font_size); - text_buf.set_width(limit - ofs - hsep); + if (root && root->has_node(path)) { + node = root->get_node(path); + } - int h = MAX(text_buf.get_size().y, icon->get_height()); + String text; - draw_texture(icon, Point2(ofs, vofs + int(h - icon->get_height()) / 2)); + if (node) { + int ofs = 0; - margin = icon->get_width(); + Ref<Texture2D> icon = EditorNode::get_singleton()->get_object_icon(node, "Node"); - Vector2 string_pos = Point2(ofs, vofs + (h - text_buf.get_size().y) / 2 + text_buf.get_line_ascent()); - string_pos = string_pos.floor(); - text_buf.draw(get_canvas_item(), string_pos, color); + text = node->get_name(); + ofs += hsep; - vofs += h + vsep; - } - } + TextLine text_buf = TextLine(text, font, font_size); + text_buf.set_width(limit - ofs - icon->get_width() - hsep); - // RELATED TRACKS TITLES + int h = MAX(text_buf.get_size().y, icon->get_height()); - Map<int, Color> subtrack_colors; - subtracks.clear(); + draw_texture(icon, Point2(ofs, vofs + int(h - icon->get_height()) / 2)); + ofs += icon->get_width(); - for (int i = 0; i < animation->get_track_count(); i++) { - if (animation->track_get_type(i) != Animation::TYPE_BEZIER) { - continue; - } - String path = animation->track_get_path(i); - if (!path.begins_with(base_path)) { - continue; //another node + margin = icon->get_width(); + + Vector2 string_pos = Point2(ofs, vofs); + string_pos = string_pos.floor(); + text_buf.draw(get_canvas_item(), string_pos, color); + + vofs += h + vsep; + } } - path = path.replace_first(base_path, ""); - Color cc = color; - TextLine text_buf = TextLine(path, font, font_size); - text_buf.set_width(limit - margin - hsep); + Ref<Texture2D> remove = get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")); + float remove_hpos = limit - hsep - remove->get_width(); + + Ref<Texture2D> lock = get_theme_icon(SNAME("Lock"), SNAME("EditorIcons")); + Ref<Texture2D> unlock = get_theme_icon(SNAME("Unlock"), SNAME("EditorIcons")); + float lock_hpos = remove_hpos - hsep - lock->get_width(); + + Ref<Texture2D> visible = get_theme_icon(SNAME("GuiVisibilityVisible"), SNAME("EditorIcons")); + Ref<Texture2D> hidden = get_theme_icon(SNAME("GuiVisibilityHidden"), SNAME("EditorIcons")); + float visibility_hpos = lock_hpos - hsep - visible->get_width(); + + Ref<Texture2D> solo = get_theme_icon(SNAME("AudioBusSolo"), SNAME("EditorIcons")); + float solo_hpos = visibility_hpos - hsep - solo->get_width(); + + float buttons_width = remove->get_width() + lock->get_width() + visible->get_width() + solo->get_width() + hsep * 3; + + for (int i = 0; i < tracks.size(); ++i) { + // RELATED TRACKS TITLES + + int current_track = tracks[i]; + + String path = animation->track_get_path(current_track); + path = path.replace_first(base_path, ""); + + Color cc = color; + TextLine text_buf = TextLine(path, font, font_size); + text_buf.set_width(limit - margin - buttons_width); + + Rect2 rect = Rect2(margin, vofs, solo_hpos - hsep - solo->get_width(), text_buf.get_size().y + vsep); - Rect2 rect = Rect2(margin, vofs, limit - margin - hsep, text_buf.get_size().y + vsep); - if (i != track) { cc.a *= 0.7; - uint32_t hash = path.hash(); - hash = ((hash >> 16) ^ hash) * 0x45d9f3b; - hash = ((hash >> 16) ^ hash) * 0x45d9f3b; - hash = (hash >> 16) ^ hash; - float h = (hash % 65535) / 65536.0; - Color subcolor; - subcolor.set_hsv(h, 0.2, 0.8); - subcolor.a = 0.5; - draw_rect(Rect2(0, vofs + text_buf.get_size().y * 0.1, margin - hsep, text_buf.get_size().y * 0.8), subcolor); - subtrack_colors[i] = subcolor; - - subtracks[i] = rect; - } else { - Color ac = get_theme_color(SNAME("accent_color"), SNAME("Editor")); - ac.a = 0.5; - draw_rect(rect, ac); - } + float h; + if (path.ends_with(":x")) { + h = 0; + } else if (path.ends_with(":y")) { + h = 0.33f; + } else if (path.ends_with(":z")) { + h = 0.66f; + } else { + uint32_t hash = path.hash(); + hash = ((hash >> 16) ^ hash) * 0x45d9f3b; + hash = ((hash >> 16) ^ hash) * 0x45d9f3b; + hash = (hash >> 16) ^ hash; + h = (hash % 65535) / 65536.0; + } + + if (current_track != selected_track) { + Color track_color; + if (locked_tracks.has(current_track)) { + track_color.set_hsv(h, 0, 0.4); + } else { + track_color.set_hsv(h, 0.2, 0.8); + } + track_color.a = 0.5; + draw_rect(Rect2(0, vofs, margin - hsep, text_buf.get_size().y * 0.8), track_color); + subtrack_colors[current_track] = track_color; + + subtracks[current_track] = rect; + } else { + Color ac = get_theme_color(SNAME("accent_color"), SNAME("Editor")); + ac.a = 0.5; + draw_rect(rect, ac); + if (locked_tracks.has(selected_track)) { + selected_track_color.set_hsv(h, 0.0, 0.4); + } else { + selected_track_color.set_hsv(h, 0.8, 0.8); + } + } + + Vector2 string_pos = Point2(margin, vofs); + text_buf.draw(get_canvas_item(), string_pos, cc); + + float icon_start_height = vofs + rect.size.y / 2; + Rect2 remove_rect = Rect2(remove_hpos, icon_start_height - remove->get_height() / 2, remove->get_width(), remove->get_height()); + draw_texture(remove, remove_rect.position); + + Rect2 lock_rect = Rect2(lock_hpos, icon_start_height - lock->get_height() / 2, lock->get_width(), lock->get_height()); + if (locked_tracks.has(current_track)) { + draw_texture(lock, lock_rect.position); + } else { + draw_texture(unlock, lock_rect.position); + } + + Rect2 visible_rect = Rect2(visibility_hpos, icon_start_height - visible->get_height() / 2, visible->get_width(), visible->get_height()); + if (hidden_tracks.has(current_track)) { + draw_texture(hidden, visible_rect.position); + } else { + draw_texture(visible, visible_rect.position); + } - Vector2 string_pos = Point2(margin, vofs + text_buf.get_line_ascent()); - text_buf.draw(get_canvas_item(), string_pos, cc); + Rect2 solo_rect = Rect2(solo_hpos, icon_start_height - solo->get_height() / 2, solo->get_width(), solo->get_height()); + draw_texture(solo, solo_rect.position); - vofs += text_buf.get_size().y + vsep; + Map<int, Rect2> track_icons; + track_icons[REMOVE_ICON] = remove_rect; + track_icons[LOCK_ICON] = lock_rect; + track_icons[VISIBILITY_ICON] = visible_rect; + track_icons[SOLO_ICON] = solo_rect; + + subtrack_icons[current_track] = track_icons; + + vofs += text_buf.get_size().y + vsep; + } } Color accent = get_theme_color(SNAME("accent_color"), SNAME("Editor")); @@ -398,6 +481,9 @@ void AnimationBezierTrackEdit::_notification(int p_what) { float scale = timeline->get_zoom_scale(); Ref<Texture2D> point = get_theme_icon(SNAME("KeyValue"), SNAME("EditorIcons")); for (const KeyValue<int, Color> &E : subtrack_colors) { + if (hidden_tracks.has(E.key)) { + continue; + } _draw_track(E.key, E.value); for (int i = 0; i < animation->track_get_key_count(E.key); i++) { @@ -412,70 +498,116 @@ void AnimationBezierTrackEdit::_notification(int p_what) { } } - //draw edited curve - const Color highlight = get_theme_color(SNAME("highlight_color"), SNAME("Editor")); - _draw_track(track, highlight); + if (track_count > 0 && !hidden_tracks.has(selected_track)) { + //draw edited curve + _draw_track(selected_track, selected_track_color); + } } //draw editor handles { edit_points.clear(); - float scale = timeline->get_zoom_scale(); - for (int i = 0; i < animation->track_get_key_count(track); i++) { - float offset = animation->track_get_key_time(track, i); - float value = animation->bezier_track_get_key_value(track, i); - if (moving_selection && selection.has(i)) { - offset += moving_selection_offset.x; - value += moving_selection_offset.y; + for (int i = 0; i < track_count; ++i) { + if (animation->track_get_type(i) != Animation::TrackType::TYPE_BEZIER || hidden_tracks.has(i)) { + continue; } - Vector2 pos((offset - timeline->get_value()) * scale + limit, _bezier_h_to_pixel(value)); - - Vector2 in_vec = animation->bezier_track_get_key_in_handle(track, i); - if (moving_handle != 0 && moving_handle_key == i) { - in_vec = moving_handle_left; + if (hidden_tracks.has(i) || locked_tracks.has(i)) { + continue; } - Vector2 pos_in(((offset + in_vec.x) - timeline->get_value()) * scale + limit, _bezier_h_to_pixel(value + in_vec.y)); - Vector2 out_vec = animation->bezier_track_get_key_out_handle(track, i); + int key_count = animation->track_get_key_count(i); + String path = animation->track_get_path(i); - if (moving_handle != 0 && moving_handle_key == i) { - out_vec = moving_handle_right; + if (is_filtered) { + if (root && root->has_node(path)) { + Node *node = root->get_node(path); + if (!node) { + continue; // No node, no filter. + } + if (!EditorNode::get_singleton()->get_editor_selection()->is_selected(node)) { + continue; // Skip track due to not selected. + } + } } - Vector2 pos_out(((offset + out_vec.x) - timeline->get_value()) * scale + limit, _bezier_h_to_pixel(value + out_vec.y)); + for (int j = 0; j < key_count; ++j) { + float offset = animation->track_get_key_time(i, j); + float value = animation->bezier_track_get_key_value(i, j); + + if (moving_selection && selection.has(IntPair(i, j))) { + offset += moving_selection_offset.x; + value += moving_selection_offset.y; + } - _draw_line_clipped(pos, pos_in, accent, limit, right_limit); - _draw_line_clipped(pos, pos_out, accent, limit, right_limit); + Vector2 pos((offset - timeline->get_value()) * scale + limit, _bezier_h_to_pixel(value)); - EditPoint ep; - if (pos.x >= limit && pos.x <= right_limit) { - ep.point_rect.position = (pos - bezier_icon->get_size() / 2).floor(); - ep.point_rect.size = bezier_icon->get_size(); - if (selection.has(i)) { - draw_texture(selected_icon, ep.point_rect.position); - draw_string(font, ep.point_rect.position + Vector2(8, -font->get_height(font_size) - 8), TTR("Time:") + " " + TS->format_number(rtos(Math::snapped(offset, 0.001))), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, accent); - draw_string(font, ep.point_rect.position + Vector2(8, -8), TTR("Value:") + " " + TS->format_number(rtos(Math::snapped(value, 0.001))), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, accent); - } else { - draw_texture(bezier_icon, ep.point_rect.position); + Vector2 in_vec = animation->bezier_track_get_key_in_handle(i, j); + if (moving_handle != 0 && moving_handle_track == i && moving_handle_key == j) { + in_vec = moving_handle_left; + } + Vector2 pos_in(((offset + in_vec.x) - timeline->get_value()) * scale + limit, _bezier_h_to_pixel(value + in_vec.y)); + + Vector2 out_vec = animation->bezier_track_get_key_out_handle(i, j); + + if (moving_handle != 0 && moving_handle_track == i && moving_handle_key == j) { + out_vec = moving_handle_right; + } + + Vector2 pos_out(((offset + out_vec.x) - timeline->get_value()) * scale + limit, _bezier_h_to_pixel(value + out_vec.y)); + + if (i == selected_track || selection.has(IntPair(i, j))) { + _draw_line_clipped(pos, pos_in, accent, limit, right_limit); + _draw_line_clipped(pos, pos_out, accent, limit, right_limit); + } + + EditPoint ep; + ep.track = i; + ep.key = j; + if (pos.x >= limit && pos.x <= right_limit) { + ep.point_rect.position = (pos - bezier_icon->get_size() / 2).floor(); + ep.point_rect.size = bezier_icon->get_size(); + if (selection.has(IntPair(i, j))) { + draw_texture(selected_icon, ep.point_rect.position); + draw_string(font, ep.point_rect.position + Vector2(8, -font->get_height(font_size) - 8), TTR("Time:") + " " + TS->format_number(rtos(Math::snapped(offset, 0.001))), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, accent); + draw_string(font, ep.point_rect.position + Vector2(8, -8), TTR("Value:") + " " + TS->format_number(rtos(Math::snapped(value, 0.001))), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, accent); + } else { + Color track_color = Color(1, 1, 1, 1); + if (i != selected_track) { + track_color = subtrack_colors[i]; + } + draw_texture(bezier_icon, ep.point_rect.position, track_color); + } + ep.point_rect = ep.point_rect.grow(ep.point_rect.size.width * 0.5); + } + if (i == selected_track || selection.has(IntPair(i, j))) { + if (pos_in.x >= limit && pos_in.x <= right_limit) { + ep.in_rect.position = (pos_in - bezier_handle_icon->get_size() / 2).floor(); + ep.in_rect.size = bezier_handle_icon->get_size(); + draw_texture(bezier_handle_icon, ep.in_rect.position); + ep.in_rect = ep.in_rect.grow(ep.in_rect.size.width * 0.5); + } + if (pos_out.x >= limit && pos_out.x <= right_limit) { + ep.out_rect.position = (pos_out - bezier_handle_icon->get_size() / 2).floor(); + ep.out_rect.size = bezier_handle_icon->get_size(); + draw_texture(bezier_handle_icon, ep.out_rect.position); + ep.out_rect = ep.out_rect.grow(ep.out_rect.size.width * 0.5); + } + } + if (!locked_tracks.has(i)) { + edit_points.push_back(ep); } - ep.point_rect = ep.point_rect.grow(ep.point_rect.size.width * 0.5); - } - if (pos_in.x >= limit && pos_in.x <= right_limit) { - ep.in_rect.position = (pos_in - bezier_handle_icon->get_size() / 2).floor(); - ep.in_rect.size = bezier_handle_icon->get_size(); - draw_texture(bezier_handle_icon, ep.in_rect.position); - ep.in_rect = ep.in_rect.grow(ep.in_rect.size.width * 0.5); } - if (pos_out.x >= limit && pos_out.x <= right_limit) { - ep.out_rect.position = (pos_out - bezier_handle_icon->get_size() / 2).floor(); - ep.out_rect.size = bezier_handle_icon->get_size(); - draw_texture(bezier_handle_icon, ep.out_rect.position); - ep.out_rect = ep.out_rect.grow(ep.out_rect.size.width * 0.5); + } + + for (int i = 0; i < edit_points.size(); ++i) { + if (edit_points[i].track == selected_track) { + EditPoint ep = edit_points[i]; + edit_points.remove_at(i); + edit_points.insert(0, ep); } - edit_points.push_back(ep); } } @@ -506,15 +638,7 @@ Ref<Animation> AnimationBezierTrackEdit::get_animation() const { void AnimationBezierTrackEdit::set_animation_and_track(const Ref<Animation> &p_animation, int p_track) { animation = p_animation; - track = p_track; - if (is_connected("select_key", Callable(editor, "_key_selected"))) { - disconnect("select_key", Callable(editor, "_key_selected")); - } - if (is_connected("deselect_key", Callable(editor, "_key_deselected"))) { - disconnect("deselect_key", Callable(editor, "_key_deselected")); - } - connect("select_key", Callable(editor, "_key_selected"), varray(p_track), CONNECT_DEFERRED); - connect("deselect_key", Callable(editor, "_key_deselected"), varray(p_track), CONNECT_DEFERRED); + selected_track = p_track; update(); } @@ -529,11 +653,14 @@ void AnimationBezierTrackEdit::set_undo_redo(UndoRedo *p_undo_redo) { void AnimationBezierTrackEdit::set_timeline(AnimationTimelineEdit *p_timeline) { timeline = p_timeline; timeline->connect("zoom_changed", callable_mp(this, &AnimationBezierTrackEdit::_zoom_changed)); + timeline->connect("name_limit_changed", callable_mp(this, &AnimationBezierTrackEdit::_zoom_changed)); } void AnimationBezierTrackEdit::set_editor(AnimationTrackEditor *p_editor) { editor = p_editor; connect("clear_selection", Callable(editor, "_clear_selection"), varray(false)); + connect("select_key", Callable(editor, "_key_selected"), varray(), CONNECT_DEFERRED); + connect("deselect_key", Callable(editor, "_key_deselected"), varray(), CONNECT_DEFERRED); } void AnimationBezierTrackEdit::_play_position_draw() { @@ -544,9 +671,11 @@ void AnimationBezierTrackEdit::_play_position_draw() { float scale = timeline->get_zoom_scale(); int h = get_size().height; - int px = (-timeline->get_value() + play_position_pos) * scale + timeline->get_name_limit(); + int limit = timeline->get_name_limit(); + + int px = (-timeline->get_value() + play_position_pos) * scale + limit; - if (px >= timeline->get_name_limit() && px < (get_size().width - timeline->get_buttons_width())) { + if (px >= limit && px < (get_size().width)) { Color color = get_theme_color(SNAME("accent_color"), SNAME("Editor")); play_position->draw_line(Point2(px, 0), Point2(px, h), color, Math::round(2 * EDSCALE)); } @@ -565,11 +694,84 @@ void AnimationBezierTrackEdit::set_root(Node *p_root) { root = p_root; } +void AnimationBezierTrackEdit::set_filtered(bool p_filtered) { + is_filtered = p_filtered; + if (animation == nullptr) { + return; + } + String base_path = animation->track_get_path(selected_track); + if (is_filtered) { + if (root && root->has_node(base_path)) { + Node *node = root->get_node(base_path); + if (!node || !EditorNode::get_singleton()->get_editor_selection()->is_selected(node)) { + for (int i = 0; i < animation->get_track_count(); ++i) { + if (animation->track_get_type(i) != Animation::TrackType::TYPE_BEZIER) { + continue; + } + + base_path = animation->track_get_path(i); + if (root && root->has_node(base_path)) { + node = root->get_node(base_path); + if (!node) { + continue; // No node, no filter. + } + if (!EditorNode::get_singleton()->get_editor_selection()->is_selected(node)) { + continue; // Skip track due to not selected. + } + + set_animation_and_track(animation, i); + break; + } + } + } + } + } + update(); +} + void AnimationBezierTrackEdit::_zoom_changed() { update(); play_position->update(); } +void AnimationBezierTrackEdit::_update_locked_tracks_after(int p_track) { + if (locked_tracks.has(p_track)) { + locked_tracks.erase(p_track); + } + + Vector<int> updated_locked_tracks; + for (Set<int>::Element *E = locked_tracks.front(); E; E = E->next()) { + updated_locked_tracks.push_back(E->get()); + } + locked_tracks.clear(); + for (int i = 0; i < updated_locked_tracks.size(); ++i) { + if (updated_locked_tracks[i] > p_track) { + locked_tracks.insert(updated_locked_tracks[i] - 1); + } else { + locked_tracks.insert(updated_locked_tracks[i]); + } + } +} + +void AnimationBezierTrackEdit::_update_hidden_tracks_after(int p_track) { + if (hidden_tracks.has(p_track)) { + hidden_tracks.erase(p_track); + } + + Vector<int> updated_hidden_tracks; + for (Set<int>::Element *E = hidden_tracks.front(); E; E = E->next()) { + updated_hidden_tracks.push_back(E->get()); + } + hidden_tracks.clear(); + for (int i = 0; i < updated_hidden_tracks.size(); ++i) { + if (updated_hidden_tracks[i] > p_track) { + hidden_tracks.insert(updated_hidden_tracks[i] - 1); + } else { + hidden_tracks.insert(updated_hidden_tracks[i]); + } + } +} + String AnimationBezierTrackEdit::get_tooltip(const Point2 &p_pos) const { return Control::get_tooltip(p_pos); } @@ -583,10 +785,10 @@ void AnimationBezierTrackEdit::_clear_selection() { void AnimationBezierTrackEdit::_change_selected_keys_handle_mode(Animation::HandleMode p_mode) { undo_redo->create_action(TTR("Update Selected Key Handles")); double ratio = timeline->get_zoom_scale() * v_zoom; - for (Set<int>::Element *E = selection.back(); E; E = E->prev()) { - const int key_index = E->get(); - undo_redo->add_undo_method(animation.ptr(), "bezier_track_set_key_handle_mode", track, key_index, animation->bezier_track_get_key_handle_mode(track, key_index), ratio); - undo_redo->add_do_method(animation.ptr(), "bezier_track_set_key_handle_mode", track, key_index, p_mode, ratio); + for (SelectionSet::Element *E = selection.back(); E; E = E->prev()) { + const IntPair track_key_pair = E->get(); + undo_redo->add_undo_method(animation.ptr(), "bezier_track_set_key_handle_mode", track_key_pair.first, track_key_pair.second, animation->bezier_track_get_key_handle_mode(track_key_pair.first, track_key_pair.second), ratio); + undo_redo->add_do_method(animation.ptr(), "bezier_track_set_key_handle_mode", track_key_pair.first, track_key_pair.second, p_mode, ratio); } undo_redo->commit_action(); } @@ -606,8 +808,8 @@ void AnimationBezierTrackEdit::_select_at_anim(const Ref<Animation> &p_anim, int int idx = animation->track_find_key(p_track, p_pos, true); ERR_FAIL_COND(idx < 0); - selection.insert(idx); - emit_signal(SNAME("select_key"), idx, true); + selection.insert(IntPair(p_track, idx)); + emit_signal(SNAME("select_key"), p_track, idx, true); update(); } @@ -631,14 +833,100 @@ void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) { } } + Ref<InputEventKey> key_press = p_event; + + if (key_press.is_valid() && key_press->is_pressed()) { + if (ED_GET_SHORTCUT("animation_bezier_editor/focus")->matches_event(p_event)) { + SelectionSet focused_keys; + if (selection.is_empty()) { + for (int i = 0; i < edit_points.size(); ++i) { + IntPair key_pair = IntPair(edit_points[i].track, edit_points[i].key); + focused_keys.insert(key_pair); + } + } else { + for (SelectionSet::Element *E = selection.front(); E; E = E->next()) { + focused_keys.insert(E->get()); + if (E->get().second > 0) { + IntPair previous_key = IntPair(E->get().first, E->get().second - 1); + focused_keys.insert(previous_key); + } + if (E->get().second < animation->track_get_key_count(E->get().first) - 1) { + IntPair next_key = IntPair(E->get().first, E->get().second + 1); + focused_keys.insert(next_key); + } + } + } + if (focused_keys.is_empty()) { + accept_event(); + return; + } + + float minimum_time = INFINITY; + float maximum_time = -INFINITY; + float minimum_value = INFINITY; + float maximum_value = -INFINITY; + + for (SelectionSet::Element *E = focused_keys.front(); E; E = E->next()) { + IntPair key_pair = E->get(); + + float time = animation->track_get_key_time(key_pair.first, key_pair.second); + float value = animation->bezier_track_get_key_value(key_pair.first, key_pair.second); + + minimum_time = MIN(time, minimum_time); + maximum_time = MAX(time, maximum_time); + minimum_value = MIN(value, minimum_value); + maximum_value = MAX(value, maximum_value); + } + + float width = get_size().width - timeline->get_name_limit() - timeline->get_buttons_width(); + float padding = width * 0.1; + float desired_scale = (width - padding / 2) / (maximum_time - minimum_time); + minimum_time = MAX(0, minimum_time - (padding / 2) / desired_scale); + + float zv = Math::pow(100 / desired_scale, 0.125f); + if (zv < 1) { + zv = Math::pow(desired_scale / 100, 0.125f) - 1; + zv = 1 - zv; + } + float zoom_value = timeline->get_zoom()->get_max() - zv; + + timeline->get_zoom()->set_value(zoom_value); + timeline->call_deferred("set_value", minimum_time); + + v_scroll = (maximum_value + minimum_value) / 2.0; + v_zoom = (maximum_value - minimum_value) / ((get_size().height - timeline->get_size().height) * 0.9); + + update(); + accept_event(); + return; + } else if (ED_GET_SHORTCUT("animation_bezier_editor/select_all_keys")->matches_event(p_event)) { + for (int i = 0; i < edit_points.size(); ++i) { + selection.insert(IntPair(edit_points[i].track, edit_points[i].key)); + } + + update(); + accept_event(); + return; + } else if (ED_GET_SHORTCUT("animation_bezier_editor/deselect_all_keys")->matches_event(p_event)) { + selection.clear(); + + update(); + accept_event(); + return; + } + } + Ref<InputEventMouseButton> mb = p_event; + int limit = timeline->get_name_limit(); if (mb.is_valid() && mb->get_button_index() == MouseButton::RIGHT && mb->is_pressed()) { menu_insert_key = mb->get_position(); - if (menu_insert_key.x >= timeline->get_name_limit() && menu_insert_key.x <= get_size().width - timeline->get_buttons_width()) { + if (menu_insert_key.x >= limit && menu_insert_key.x <= get_size().width) { Vector2 popup_pos = get_screen_position() + mb->get_position(); menu->clear(); - menu->add_icon_item(bezier_icon, TTR("Insert Key Here"), MENU_KEY_INSERT); + if (!locked_tracks.has(selected_track) || locked_tracks.has(selected_track)) { + menu->add_icon_item(bezier_icon, TTR("Insert Key Here"), MENU_KEY_INSERT); + } if (selection.size()) { menu->add_separator(); menu->add_icon_item(get_theme_icon(SNAME("Duplicate"), SNAME("EditorIcons")), TTR("Duplicate Selected Key(s)"), MENU_KEY_DUPLICATE); @@ -649,50 +937,163 @@ void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) { menu->add_icon_item(get_theme_icon(SNAME("BezierHandlesBalanced"), SNAME("EditorIcons")), TTR("Make Handles Balanced"), MENU_KEY_SET_HANDLE_BALANCED); } - menu->set_as_minsize(); - menu->set_position(popup_pos); - menu->popup(); + if (menu->get_item_count()) { + menu->set_as_minsize(); + menu->set_position(popup_pos); + menu->popup(); + } } } if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT) { for (const KeyValue<int, Rect2> &E : subtracks) { if (E.value.has_point(mb->get_position())) { - set_animation_and_track(animation, E.key); - _clear_selection(); + if (!locked_tracks.has(E.key) && !hidden_tracks.has(E.key)) { + set_animation_and_track(animation, E.key); + _clear_selection(); + } return; } } + for (const KeyValue<int, Map<int, Rect2>> &E : subtrack_icons) { + int track = E.key; + Map<int, Rect2> track_icons = E.value; + for (const KeyValue<int, Rect2> &I : track_icons) { + if (I.value.has_point(mb->get_position())) { + if (I.key == REMOVE_ICON) { + undo_redo->create_action("Remove Bezier Track"); + + undo_redo->add_do_method(this, "_update_locked_tracks_after", track); + undo_redo->add_do_method(this, "_update_hidden_tracks_after", track); + + undo_redo->add_do_method(animation.ptr(), "remove_track", track); + + undo_redo->add_undo_method(animation.ptr(), "add_track", Animation::TrackType::TYPE_BEZIER, track); + undo_redo->add_undo_method(animation.ptr(), "track_set_path", track, animation->track_get_path(track)); + + for (int i = 0; i < animation->track_get_key_count(track); ++i) { + undo_redo->add_undo_method( + animation.ptr(), + "bezier_track_insert_key", + track, animation->track_get_key_time(track, i), + animation->bezier_track_get_key_value(track, i), + animation->bezier_track_get_key_in_handle(track, i), + animation->bezier_track_get_key_out_handle(track, i), + animation->bezier_track_get_key_handle_mode(track, i)); + } + + undo_redo->commit_action(); + + selected_track = CLAMP(selected_track, 0, animation->get_track_count() - 1); + return; + } else if (I.key == LOCK_ICON) { + if (locked_tracks.has(track)) { + locked_tracks.erase(track); + } else { + locked_tracks.insert(track); + if (selected_track == track) { + for (int i = 0; i < animation->get_track_count(); ++i) { + if (!locked_tracks.has(i) && animation->track_get_type(i) == Animation::TrackType::TYPE_BEZIER) { + set_animation_and_track(animation, i); + break; + } + } + } + } + update(); + return; + } else if (I.key == VISIBILITY_ICON) { + if (hidden_tracks.has(track)) { + hidden_tracks.erase(track); + } else { + hidden_tracks.insert(track); + if (selected_track == track) { + for (int i = 0; i < animation->get_track_count(); ++i) { + if (!hidden_tracks.has(i) && animation->track_get_type(i) == Animation::TrackType::TYPE_BEZIER) { + set_animation_and_track(animation, i); + break; + } + } + } + } + + Vector<int> visible_tracks; + for (int i = 0; i < animation->get_track_count(); ++i) { + if (!hidden_tracks.has(i) && animation->track_get_type(i) == Animation::TrackType::TYPE_BEZIER) { + visible_tracks.push_back(i); + } + } + + if (visible_tracks.size() == 1) { + solo_track = visible_tracks[0]; + } else { + solo_track = -1; + } + + update(); + return; + } else if (I.key == SOLO_ICON) { + if (solo_track == track) { + solo_track = -1; + + hidden_tracks.clear(); + } else { + if (hidden_tracks.has(track)) { + hidden_tracks.erase(track); + } + for (int i = 0; i < animation->get_track_count(); ++i) { + if (animation->track_get_type(i) == Animation::TrackType::TYPE_BEZIER) { + if (i != track && !hidden_tracks.has(i)) { + hidden_tracks.insert(i); + } + } + } + + set_animation_and_track(animation, track); + solo_track = track; + } + update(); + return; + } + return; + } + } + } + for (int i = 0; i < edit_points.size(); i++) { //first check point //command makes it ignore the main point, so control point editors can be force-edited //path 2D editing in the 3D and 2D editors works the same way if (!mb->is_command_pressed()) { if (edit_points[i].point_rect.has_point(mb->get_position())) { + IntPair pair = IntPair(edit_points[i].track, edit_points[i].key); if (mb->is_shift_pressed()) { //add to selection - if (selection.has(i)) { - selection.erase(i); + if (selection.has(pair)) { + selection.erase(pair); } else { - selection.insert(i); + selection.insert(pair); } update(); - select_single_attempt = -1; - } else if (selection.has(i)) { + select_single_attempt = IntPair(-1, -1); + } else if (selection.has(pair)) { moving_selection_attempt = true; moving_selection = false; - moving_selection_from_key = i; + moving_selection_from_key = pair.second; + moving_selection_from_track = pair.first; moving_selection_offset = Vector2(); - select_single_attempt = i; + select_single_attempt = pair; update(); } else { moving_selection_attempt = true; moving_selection = true; - moving_selection_from_key = i; + moving_selection_from_key = pair.second; + moving_selection_from_track = pair.first; moving_selection_offset = Vector2(); + set_animation_and_track(animation, pair.first); selection.clear(); - selection.insert(i); + selection.insert(pair); update(); } return; @@ -701,26 +1102,27 @@ void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) { if (edit_points[i].in_rect.has_point(mb->get_position())) { moving_handle = -1; - moving_handle_key = i; - moving_handle_left = animation->bezier_track_get_key_in_handle(track, i); - moving_handle_right = animation->bezier_track_get_key_out_handle(track, i); + moving_handle_key = edit_points[i].key; + moving_handle_track = edit_points[i].track; + moving_handle_left = animation->bezier_track_get_key_in_handle(edit_points[i].track, edit_points[i].key); + moving_handle_right = animation->bezier_track_get_key_out_handle(edit_points[i].track, edit_points[i].key); update(); return; } if (edit_points[i].out_rect.has_point(mb->get_position())) { moving_handle = 1; - moving_handle_key = i; - moving_handle_left = animation->bezier_track_get_key_in_handle(track, i); - moving_handle_right = animation->bezier_track_get_key_out_handle(track, i); + moving_handle_key = edit_points[i].key; + moving_handle_track = edit_points[i].track; + moving_handle_left = animation->bezier_track_get_key_in_handle(edit_points[i].track, edit_points[i].key); + moving_handle_right = animation->bezier_track_get_key_out_handle(edit_points[i].track, edit_points[i].key); update(); return; - ; } } //insert new point - if (mb->is_command_pressed() && mb->get_position().x >= timeline->get_name_limit() && mb->get_position().x < get_size().width - timeline->get_buttons_width()) { + if (mb->get_position().x >= limit && mb->get_position().x < get_size().width && mb->is_command_pressed()) { Array new_point; new_point.resize(6); @@ -733,34 +1135,35 @@ void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) { new_point[4] = 0; new_point[5] = 0; - float time = ((mb->get_position().x - timeline->get_name_limit()) / timeline->get_zoom_scale()) + timeline->get_value(); - while (animation->track_find_key(track, time, true) != -1) { + float time = ((mb->get_position().x - limit) / timeline->get_zoom_scale()) + timeline->get_value(); + while (animation->track_find_key(selected_track, time, true) != -1) { time += 0.001; } undo_redo->create_action(TTR("Add Bezier Point")); - undo_redo->add_do_method(animation.ptr(), "track_insert_key", track, time, new_point); - undo_redo->add_undo_method(animation.ptr(), "track_remove_key_at_time", track, time); + undo_redo->add_do_method(animation.ptr(), "track_insert_key", selected_track, time, new_point); + undo_redo->add_undo_method(animation.ptr(), "track_remove_key_at_time", selected_track, time); undo_redo->commit_action(); //then attempt to move - int index = animation->track_find_key(track, time, true); + int index = animation->track_find_key(selected_track, time, true); ERR_FAIL_COND(index == -1); _clear_selection(); - selection.insert(index); + selection.insert(IntPair(selected_track, index)); moving_selection_attempt = true; moving_selection = false; moving_selection_from_key = index; + moving_selection_from_track = selected_track; moving_selection_offset = Vector2(); - select_single_attempt = -1; + select_single_attempt = IntPair(-1, -1); update(); return; } //box select - if (mb->get_position().x >= timeline->get_name_limit() && mb->get_position().x < get_size().width - timeline->get_buttons_width()) { + if (mb->get_position().x >= limit && mb->get_position().x < get_size().width) { box_selecting_attempt = true; box_selecting = false; box_selecting_add = false; @@ -786,14 +1189,44 @@ void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) { } Rect2 selection_rect(bs_from, bs_to - bs_from); + bool track_set = false; for (int i = 0; i < edit_points.size(); i++) { if (edit_points[i].point_rect.intersects(selection_rect)) { - selection.insert(i); + selection.insert(IntPair(edit_points[i].track, edit_points[i].key)); + if (!track_set) { + track_set = true; + set_animation_and_track(animation, edit_points[i].track); + } } } } else { _clear_selection(); //clicked and nothing happened, so clear the selection + + //select by clicking on curve + int track_count = animation->get_track_count(); + + float animation_length = animation->get_length(); + animation->set_length(real_t(INT_MAX)); //bezier_track_interpolate doesn't find keys if they exist beyond anim length + + float time = ((mb->get_position().x - limit) / timeline->get_zoom_scale()) + timeline->get_value(); + + for (int i = 0; i < track_count; ++i) { + if (animation->track_get_type(i) != Animation::TrackType::TYPE_BEZIER || hidden_tracks.has(i) || locked_tracks.has(i)) { + continue; + } + + float track_h = animation->bezier_track_interpolate(i, time); + float track_height = _bezier_h_to_pixel(track_h); + + if (abs(mb->get_position().y - track_height) < 10) { + set_animation_and_track(animation, i); + break; + } + } + + animation->set_length(animation_length); } + box_selecting_attempt = false; box_selecting = false; update(); @@ -801,10 +1234,10 @@ void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) { if (moving_handle != 0 && mb.is_valid() && !mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT) { undo_redo->create_action(TTR("Move Bezier Points")); - undo_redo->add_do_method(animation.ptr(), "bezier_track_set_key_in_handle", track, moving_handle_key, moving_handle_left); - undo_redo->add_do_method(animation.ptr(), "bezier_track_set_key_out_handle", track, moving_handle_key, moving_handle_right); - undo_redo->add_undo_method(animation.ptr(), "bezier_track_set_key_in_handle", track, moving_handle_key, animation->bezier_track_get_key_in_handle(track, moving_handle_key)); - undo_redo->add_undo_method(animation.ptr(), "bezier_track_set_key_out_handle", track, moving_handle_key, animation->bezier_track_get_key_out_handle(track, moving_handle_key)); + undo_redo->add_do_method(animation.ptr(), "bezier_track_set_key_in_handle", selected_track, moving_handle_key, moving_handle_left); + undo_redo->add_do_method(animation.ptr(), "bezier_track_set_key_out_handle", selected_track, moving_handle_key, moving_handle_right); + undo_redo->add_undo_method(animation.ptr(), "bezier_track_set_key_in_handle", selected_track, moving_handle_key, animation->bezier_track_get_key_in_handle(selected_track, moving_handle_key)); + undo_redo->add_undo_method(animation.ptr(), "bezier_track_set_key_out_handle", selected_track, moving_handle_key, animation->bezier_track_get_key_out_handle(selected_track, moving_handle_key)); undo_redo->commit_action(); moving_handle = 0; @@ -819,60 +1252,60 @@ void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) { List<AnimMoveRestore> to_restore; // 1-remove the keys - for (Set<int>::Element *E = selection.back(); E; E = E->prev()) { - undo_redo->add_do_method(animation.ptr(), "track_remove_key", track, E->get()); + for (SelectionSet::Element *E = selection.back(); E; E = E->prev()) { + undo_redo->add_do_method(animation.ptr(), "track_remove_key", E->get().first, E->get().second); } // 2- remove overlapped keys - for (Set<int>::Element *E = selection.back(); E; E = E->prev()) { - float newtime = editor->snap_time(animation->track_get_key_time(track, E->get()) + moving_selection_offset.x); + for (SelectionSet::Element *E = selection.back(); E; E = E->prev()) { + float newtime = editor->snap_time(animation->track_get_key_time(E->get().first, E->get().second) + moving_selection_offset.x); - int idx = animation->track_find_key(track, newtime, true); + int idx = animation->track_find_key(E->get().first, newtime, true); if (idx == -1) { continue; } - if (selection.has(idx)) { + if (selection.has(IntPair(E->get().first, idx))) { continue; //already in selection, don't save } - undo_redo->add_do_method(animation.ptr(), "track_remove_key_at_time", track, newtime); + undo_redo->add_do_method(animation.ptr(), "track_remove_key_at_time", E->get().first, newtime); AnimMoveRestore amr; - amr.key = animation->track_get_key_value(track, idx); - amr.track = track; + amr.key = animation->track_get_key_value(E->get().first, idx); + amr.track = E->get().first; amr.time = newtime; to_restore.push_back(amr); } // 3-move the keys (re insert them) - for (Set<int>::Element *E = selection.back(); E; E = E->prev()) { - float newpos = editor->snap_time(animation->track_get_key_time(track, E->get()) + moving_selection_offset.x); + for (SelectionSet::Element *E = selection.back(); E; E = E->prev()) { + float newpos = editor->snap_time(animation->track_get_key_time(E->get().first, E->get().second) + moving_selection_offset.x); /* if (newpos<0) continue; //no add at the beginning */ - Array key = animation->track_get_key_value(track, E->get()); + Array key = animation->track_get_key_value(E->get().first, E->get().second); float h = key[0]; h += moving_selection_offset.y; key[0] = h; - undo_redo->add_do_method(animation.ptr(), "track_insert_key", track, newpos, key, 1); + undo_redo->add_do_method(animation.ptr(), "track_insert_key", E->get().first, newpos, key, 1); } // 4-(undo) remove inserted keys - for (Set<int>::Element *E = selection.back(); E; E = E->prev()) { - float newpos = editor->snap_time(animation->track_get_key_time(track, E->get()) + moving_selection_offset.x); + for (SelectionSet::Element *E = selection.back(); E; E = E->prev()) { + float newpos = editor->snap_time(animation->track_get_key_time(E->get().first, E->get().second) + moving_selection_offset.x); /* if (newpos<0) continue; //no remove what no inserted */ - undo_redo->add_undo_method(animation.ptr(), "track_remove_key_at_time", track, newpos); + undo_redo->add_undo_method(animation.ptr(), "track_remove_key_at_time", E->get().first, newpos); } // 5-(undo) reinsert keys - for (Set<int>::Element *E = selection.back(); E; E = E->prev()) { - float oldpos = animation->track_get_key_time(track, E->get()); - undo_redo->add_undo_method(animation.ptr(), "track_insert_key", track, oldpos, animation->track_get_key_value(track, E->get()), 1); + for (SelectionSet::Element *E = selection.back(); E; E = E->prev()) { + float oldpos = animation->track_get_key_time(E->get().first, E->get().second); + undo_redo->add_undo_method(animation.ptr(), "track_insert_key", E->get().first, oldpos, animation->track_get_key_value(E->get().first, E->get().second), 1); } // 6-(undo) reinsert overlapped keys @@ -885,20 +1318,21 @@ void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) { // 7-reselect - for (Set<int>::Element *E = selection.back(); E; E = E->prev()) { - float oldpos = animation->track_get_key_time(track, E->get()); + for (SelectionSet::Element *E = selection.back(); E; E = E->prev()) { + float oldpos = animation->track_get_key_time(E->get().first, E->get().second); float newpos = editor->snap_time(oldpos + moving_selection_offset.x); - undo_redo->add_do_method(this, "_select_at_anim", animation, track, newpos); - undo_redo->add_undo_method(this, "_select_at_anim", animation, track, oldpos); + undo_redo->add_do_method(this, "_select_at_anim", animation, E->get().first, newpos); + undo_redo->add_undo_method(this, "_select_at_anim", animation, E->get().first, oldpos); } undo_redo->commit_action(); moving_selection = false; - } else if (select_single_attempt != -1) { + } else if (select_single_attempt != IntPair(-1, -1)) { selection.clear(); selection.insert(select_single_attempt); + set_animation_and_track(animation, select_single_attempt.first); } moving_selection_attempt = false; @@ -909,13 +1343,13 @@ void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) { if (moving_selection_attempt && mm.is_valid()) { if (!moving_selection) { moving_selection = true; - select_single_attempt = -1; + select_single_attempt = IntPair(-1, -1); } float y = (get_size().height / 2 - mm->get_position().y) * v_zoom + v_scroll; - float x = editor->snap_time(((mm->get_position().x - timeline->get_name_limit()) / timeline->get_zoom_scale()) + timeline->get_value()); + float x = editor->snap_time(((mm->get_position().x - limit) / timeline->get_zoom_scale()) + timeline->get_value()); - moving_selection_offset = Vector2(x - animation->track_get_key_time(track, moving_selection_from_key), y - animation->bezier_track_get_key_value(track, moving_selection_from_key)); + moving_selection_offset = Vector2(x - animation->track_get_key_time(moving_selection_from_track, moving_selection_from_key), y - animation->bezier_track_get_key_value(moving_selection_from_track, moving_selection_from_key)); update(); } @@ -938,17 +1372,17 @@ void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) { float y = (get_size().height / 2 - mm->get_position().y) * v_zoom + v_scroll; float x = editor->snap_time((mm->get_position().x - timeline->get_name_limit()) / timeline->get_zoom_scale()) + timeline->get_value(); - Vector2 key_pos = Vector2(animation->track_get_key_time(track, moving_handle_key), animation->bezier_track_get_key_value(track, moving_handle_key)); + Vector2 key_pos = Vector2(animation->track_get_key_time(selected_track, moving_handle_key), animation->bezier_track_get_key_value(selected_track, moving_handle_key)); Vector2 moving_handle_value = Vector2(x, y) - key_pos; - moving_handle_left = animation->bezier_track_get_key_in_handle(track, moving_handle_key); - moving_handle_right = animation->bezier_track_get_key_out_handle(track, moving_handle_key); + moving_handle_left = animation->bezier_track_get_key_in_handle(moving_handle_track, moving_handle_key); + moving_handle_right = animation->bezier_track_get_key_out_handle(moving_handle_track, moving_handle_key); if (moving_handle == -1) { moving_handle_left = moving_handle_value; - if (animation->bezier_track_get_key_handle_mode(track, moving_handle_key) == Animation::HANDLE_MODE_BALANCED) { + if (animation->bezier_track_get_key_handle_mode(moving_handle_track, moving_handle_key) == Animation::HANDLE_MODE_BALANCED) { double ratio = timeline->get_zoom_scale() * v_zoom; Transform2D xform; xform.set_scale(Vector2(1.0, 1.0 / ratio)); @@ -961,7 +1395,7 @@ void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) { } else if (moving_handle == 1) { moving_handle_right = moving_handle_value; - if (animation->bezier_track_get_key_handle_mode(track, moving_handle_key) == Animation::HANDLE_MODE_BALANCED) { + if (animation->bezier_track_get_key_handle_mode(moving_handle_track, moving_handle_key) == Animation::HANDLE_MODE_BALANCED) { double ratio = timeline->get_zoom_scale() * v_zoom; Transform2D xform; xform.set_scale(Vector2(1.0, 1.0 / ratio)); @@ -980,12 +1414,12 @@ void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) { undo_redo->create_action(TTR("Move Bezier Points")); if (moving_handle == -1) { double ratio = timeline->get_zoom_scale() * v_zoom; - undo_redo->add_do_method(animation.ptr(), "bezier_track_set_key_in_handle", track, moving_handle_key, moving_handle_left, ratio); - undo_redo->add_undo_method(animation.ptr(), "bezier_track_set_key_in_handle", track, moving_handle_key, animation->bezier_track_get_key_in_handle(track, moving_handle_key), ratio); + undo_redo->add_do_method(animation.ptr(), "bezier_track_set_key_in_handle", moving_handle_track, moving_handle_key, moving_handle_left, ratio); + undo_redo->add_undo_method(animation.ptr(), "bezier_track_set_key_in_handle", moving_handle_track, moving_handle_key, animation->bezier_track_get_key_in_handle(moving_handle_track, moving_handle_key), ratio); } else if (moving_handle == 1) { double ratio = timeline->get_zoom_scale() * v_zoom; - undo_redo->add_do_method(animation.ptr(), "bezier_track_set_key_out_handle", track, moving_handle_key, moving_handle_right, ratio); - undo_redo->add_undo_method(animation.ptr(), "bezier_track_set_key_out_handle", track, moving_handle_key, animation->bezier_track_get_key_out_handle(track, moving_handle_key), ratio); + undo_redo->add_do_method(animation.ptr(), "bezier_track_set_key_out_handle", moving_handle_track, moving_handle_key, moving_handle_right, ratio); + undo_redo->add_undo_method(animation.ptr(), "bezier_track_set_key_out_handle", moving_handle_track, moving_handle_key, animation->bezier_track_get_key_out_handle(moving_handle_track, moving_handle_key), ratio); } undo_redo->commit_action(); @@ -1028,27 +1462,32 @@ void AnimationBezierTrackEdit::_zoom_callback(Vector2 p_scroll_vec, Vector2 p_or void AnimationBezierTrackEdit::_menu_selected(int p_index) { switch (p_index) { case MENU_KEY_INSERT: { - Array new_point; - new_point.resize(6); + if (animation->get_track_count() > 0) { + Array new_point; + new_point.resize(6); - float h = (get_size().height / 2 - menu_insert_key.y) * v_zoom + v_scroll; + float h = (get_size().height / 2 - menu_insert_key.y) * v_zoom + v_scroll; - new_point[0] = h; - new_point[1] = -0.25; - new_point[2] = 0; - new_point[3] = 0.25; - new_point[4] = 0; - new_point[5] = Animation::HANDLE_MODE_BALANCED; + new_point[0] = h; + new_point[1] = -0.25; + new_point[2] = 0; + new_point[3] = 0.25; + new_point[4] = 0; + new_point[5] = Animation::HANDLE_MODE_BALANCED; - float time = ((menu_insert_key.x - timeline->get_name_limit()) / timeline->get_zoom_scale()) + timeline->get_value(); - while (animation->track_find_key(track, time, true) != -1) { - time += 0.001; - } + int limit = timeline->get_name_limit(); - undo_redo->create_action(TTR("Add Bezier Point")); - undo_redo->add_do_method(animation.ptr(), "track_insert_key", track, time, new_point); - undo_redo->add_undo_method(animation.ptr(), "track_remove_key_at_time", track, time); - undo_redo->commit_action(); + float time = ((menu_insert_key.x - limit) / timeline->get_zoom_scale()) + timeline->get_value(); + + while (animation->track_find_key(selected_track, time, true) != -1) { + time += 0.001; + } + + undo_redo->create_action(TTR("Add Bezier Point")); + undo_redo->add_do_method(animation.ptr(), "track_insert_key", selected_track, time, new_point); + undo_redo->add_undo_method(animation.ptr(), "track_remove_key_at_time", selected_track, time); + undo_redo->commit_action(); + } } break; case MENU_KEY_DUPLICATE: { @@ -1072,8 +1511,8 @@ void AnimationBezierTrackEdit::duplicate_selection() { } float top_time = 1e10; - for (Set<int>::Element *E = selection.back(); E; E = E->prev()) { - float t = animation->track_get_key_time(track, E->get()); + for (SelectionSet::Element *E = selection.back(); E; E = E->prev()) { + float t = animation->track_get_key_time(E->get().first, E->get().second); if (t < top_time) { top_time = t; } @@ -1083,21 +1522,21 @@ void AnimationBezierTrackEdit::duplicate_selection() { List<Pair<int, float>> new_selection_values; - for (Set<int>::Element *E = selection.back(); E; E = E->prev()) { - float t = animation->track_get_key_time(track, E->get()); + for (SelectionSet::Element *E = selection.back(); E; E = E->prev()) { + float t = animation->track_get_key_time(E->get().first, E->get().second); float dst_time = t + (timeline->get_play_position() - top_time); - int existing_idx = animation->track_find_key(track, dst_time, true); + int existing_idx = animation->track_find_key(E->get().first, dst_time, true); - undo_redo->add_do_method(animation.ptr(), "track_insert_key", track, dst_time, animation->track_get_key_value(track, E->get()), animation->track_get_key_transition(track, E->get())); - undo_redo->add_undo_method(animation.ptr(), "track_remove_key_at_time", track, dst_time); + undo_redo->add_do_method(animation.ptr(), "track_insert_key", E->get().first, dst_time, animation->track_get_key_value(E->get().first, E->get().second), animation->track_get_key_transition(E->get().first, E->get().second)); + undo_redo->add_undo_method(animation.ptr(), "track_remove_key_at_time", E->get().first, dst_time); Pair<int, float> p; - p.first = track; + p.first = E->get().first; p.second = dst_time; new_selection_values.push_back(p); if (existing_idx != -1) { - undo_redo->add_undo_method(animation.ptr(), "track_insert_key", track, dst_time, animation->track_get_key_value(track, existing_idx), animation->track_get_key_transition(track, existing_idx)); + undo_redo->add_undo_method(animation.ptr(), "track_insert_key", E->get().first, dst_time, animation->track_get_key_value(E->get().first, existing_idx), animation->track_get_key_transition(E->get().first, existing_idx)); } } @@ -1116,7 +1555,7 @@ void AnimationBezierTrackEdit::duplicate_selection() { continue; } - selection.insert(existing_idx); + selection.insert(IntPair(track, existing_idx)); } update(); @@ -1126,9 +1565,9 @@ void AnimationBezierTrackEdit::delete_selection() { if (selection.size()) { undo_redo->create_action(TTR("Anim Delete Keys")); - for (Set<int>::Element *E = selection.back(); E; E = E->prev()) { - undo_redo->add_do_method(animation.ptr(), "track_remove_key", track, E->get()); - undo_redo->add_undo_method(animation.ptr(), "track_insert_key", track, animation->track_get_key_time(track, E->get()), animation->track_get_key_value(track, E->get()), 1); + for (SelectionSet::Element *E = selection.back(); E; E = E->prev()) { + undo_redo->add_do_method(animation.ptr(), "track_remove_key", E->get().first, E->get().second); + undo_redo->add_undo_method(animation.ptr(), "track_insert_key", E->get().first, animation->track_get_key_time(E->get().first, E->get().second), animation->track_get_key_value(E->get().first, E->get().second), 1); } undo_redo->add_do_method(this, "_clear_selection_for_anim", animation); undo_redo->add_undo_method(this, "_clear_selection_for_anim", animation); @@ -1142,12 +1581,14 @@ void AnimationBezierTrackEdit::_bind_methods() { ClassDB::bind_method("_clear_selection", &AnimationBezierTrackEdit::_clear_selection); ClassDB::bind_method("_clear_selection_for_anim", &AnimationBezierTrackEdit::_clear_selection_for_anim); ClassDB::bind_method("_select_at_anim", &AnimationBezierTrackEdit::_select_at_anim); + ClassDB::bind_method("_update_hidden_tracks_after", &AnimationBezierTrackEdit::_update_hidden_tracks_after); + ClassDB::bind_method("_update_locked_tracks_after", &AnimationBezierTrackEdit::_update_locked_tracks_after); ADD_SIGNAL(MethodInfo("timeline_changed", PropertyInfo(Variant::FLOAT, "position"), PropertyInfo(Variant::BOOL, "drag"))); ADD_SIGNAL(MethodInfo("remove_request", PropertyInfo(Variant::INT, "track"))); ADD_SIGNAL(MethodInfo("insert_key", PropertyInfo(Variant::FLOAT, "ofs"))); - ADD_SIGNAL(MethodInfo("select_key", PropertyInfo(Variant::INT, "index"), PropertyInfo(Variant::BOOL, "single"))); - ADD_SIGNAL(MethodInfo("deselect_key", PropertyInfo(Variant::INT, "index"))); + ADD_SIGNAL(MethodInfo("select_key", PropertyInfo(Variant::INT, "track"), PropertyInfo(Variant::INT, "index"), PropertyInfo(Variant::BOOL, "single"))); + ADD_SIGNAL(MethodInfo("deselect_key", PropertyInfo(Variant::INT, "track"), PropertyInfo(Variant::INT, "index"))); ADD_SIGNAL(MethodInfo("clear_selection")); ADD_SIGNAL(MethodInfo("close_request")); @@ -1170,14 +1611,9 @@ AnimationBezierTrackEdit::AnimationBezierTrackEdit() { set_clip_contents(true); - close_button = memnew(Button); - close_button->connect("pressed", Callable(this, SNAME("emit_signal")), varray(SNAME("close_request"))); - close_button->set_text(TTR("Close")); - - right_column = memnew(VBoxContainer); - right_column->add_child(close_button); - right_column->add_spacer(); - add_child(right_column); + ED_SHORTCUT("animation_bezier_editor/focus", TTR("Focus"), Key::F); + ED_SHORTCUT("animation_bezier_editor/select_all_keys", TTR("Select All Keys"), KeyModifierMask::CMD | Key::A); + ED_SHORTCUT("animation_bezier_editor/deselect_all_keys", TTR("Deselect All Keys"), KeyModifierMask::CMD | KeyModifierMask::SHIFT | Key::A); menu = memnew(PopupMenu); add_child(menu); diff --git a/editor/animation_bezier_editor.h b/editor/animation_bezier_editor.h index cf719a0355..fa6fc405f2 100644 --- a/editor/animation_bezier_editor.h +++ b/editor/animation_bezier_editor.h @@ -46,9 +46,6 @@ class AnimationBezierTrackEdit : public Control { MENU_KEY_SET_HANDLE_BALANCED, }; - VBoxContainer *right_column; - Button *close_button; - AnimationTimelineEdit *timeline = nullptr; UndoRedo *undo_redo = nullptr; Node *root = nullptr; @@ -56,7 +53,7 @@ class AnimationBezierTrackEdit : public Control { float play_position_pos = 0; Ref<Animation> animation; - int track; + int selected_track; Vector<Rect2> view_rects; @@ -66,6 +63,19 @@ class AnimationBezierTrackEdit : public Control { Map<int, Rect2> subtracks; + enum { + REMOVE_ICON, + LOCK_ICON, + SOLO_ICON, + VISIBILITY_ICON + }; + + Map<int, Map<int, Rect2>> subtrack_icons; + Set<int> locked_tracks; + Set<int> hidden_tracks; + int solo_track = -1; + bool is_filtered = false; + float v_scroll = 0; float v_zoom = 1; @@ -73,6 +83,9 @@ class AnimationBezierTrackEdit : public Control { void _zoom_changed(); + void _update_locked_tracks_after(int p_track); + void _update_hidden_tracks_after(int p_track); + virtual void gui_input(const Ref<InputEvent> &p_event) override; void _menu_selected(int p_index); @@ -80,10 +93,13 @@ class AnimationBezierTrackEdit : public Control { Vector2 insert_at_pos; + typedef Pair<int, int> IntPair; + bool moving_selection_attempt = false; - int select_single_attempt = -1; + IntPair select_single_attempt; bool moving_selection = false; int moving_selection_from_key; + int moving_selection_from_track; Vector2 moving_selection_offset; @@ -95,6 +111,7 @@ class AnimationBezierTrackEdit : public Control { int moving_handle = 0; //0 no move -1 or +1 out int moving_handle_key = 0; + int moving_handle_track = 0; Vector2 moving_handle_left; Vector2 moving_handle_right; int moving_handle_mode; // value from Animation::HandleMode @@ -119,11 +136,25 @@ class AnimationBezierTrackEdit : public Control { Rect2 point_rect; Rect2 in_rect; Rect2 out_rect; + int track; + int key; }; Vector<EditPoint> edit_points; - Set<int> selection; + struct SelectionCompare { + bool operator()(const IntPair &lh, const IntPair &rh) { + if (lh.first == rh.first) { + return lh.second < rh.second; + } else { + return lh.first < rh.first; + } + } + }; + + typedef Set<IntPair, SelectionCompare> SelectionSet; + + SelectionSet selection; Ref<ViewPanner> panner; void _scroll_callback(Vector2 p_scroll_vec, bool p_alt); @@ -151,6 +182,7 @@ public: void set_timeline(AnimationTimelineEdit *p_timeline); void set_editor(AnimationTrackEditor *p_editor); void set_root(Node *p_root); + void set_filtered(bool p_filtered); void set_play_position(float p_pos); void update_play_position(); diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index 2f33619a52..de924e84dc 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -570,7 +570,7 @@ public: p_list->push_back(PropertyInfo(Variant::VECTOR3, "position")); } break; case Animation::TYPE_ROTATION_3D: { - p_list->push_back(PropertyInfo(Variant::VECTOR3, "rotation")); + p_list->push_back(PropertyInfo(Variant::QUATERNION, "rotation")); } break; case Animation::TYPE_SCALE_3D: { p_list->push_back(PropertyInfo(Variant::VECTOR3, "scale")); @@ -2118,23 +2118,19 @@ void AnimationTrackEdit::_notification(int p_what) { update_mode_rect.position.y = 0; update_mode_rect.size.y = get_size().height; - ofs += update_icon->get_width() + hsep; - update_mode_rect.size.x += hsep; + ofs += update_icon->get_width() + hsep / 2; + update_mode_rect.size.x += hsep / 2; if (animation->track_get_type(track) == Animation::TYPE_VALUE) { draw_texture(down_icon, Vector2(ofs, int(get_size().height - down_icon->get_height()) / 2)); update_mode_rect.size.x += down_icon->get_width(); - bezier_edit_rect = Rect2(); } else if (animation->track_get_type(track) == Animation::TYPE_BEZIER) { Ref<Texture2D> bezier_icon = get_theme_icon(SNAME("EditBezier"), SNAME("EditorIcons")); update_mode_rect.size.x += down_icon->get_width(); - bezier_edit_rect.position = update_mode_rect.position + (update_mode_rect.size - bezier_icon->get_size()) / 2; - bezier_edit_rect.size = bezier_icon->get_size(); - draw_texture(bezier_icon, bezier_edit_rect.position); + update_mode_rect = Rect2(); } else { update_mode_rect = Rect2(); - bezier_edit_rect = Rect2(); } ofs += down_icon->get_width(); @@ -2160,8 +2156,8 @@ void AnimationTrackEdit::_notification(int p_what) { interp_mode_rect.position.y = 0; interp_mode_rect.size.y = get_size().height; - ofs += icon->get_width() + hsep; - interp_mode_rect.size.x += hsep; + ofs += icon->get_width() + hsep / 2; + interp_mode_rect.size.x += hsep / 2; if (!animation->track_is_compressed(track) && (animation->track_get_type(track) == Animation::TYPE_VALUE || animation->track_get_type(track) == Animation::TYPE_BLEND_SHAPE || animation->track_get_type(track) == Animation::TYPE_POSITION_3D || animation->track_get_type(track) == Animation::TYPE_SCALE_3D || animation->track_get_type(track) == Animation::TYPE_ROTATION_3D)) { draw_texture(down_icon, Vector2(ofs, int(get_size().height - down_icon->get_height()) / 2)); @@ -2193,8 +2189,8 @@ void AnimationTrackEdit::_notification(int p_what) { loop_wrap_rect.position.y = 0; loop_wrap_rect.size.y = get_size().height; - ofs += icon->get_width() + hsep; - loop_wrap_rect.size.x += hsep; + ofs += icon->get_width() + hsep / 2; + loop_wrap_rect.size.x += hsep / 2; if (!animation->track_is_compressed(track) && (animation->track_get_type(track) == Animation::TYPE_VALUE || animation->track_get_type(track) == Animation::TYPE_BLEND_SHAPE || animation->track_get_type(track) == Animation::TYPE_POSITION_3D || animation->track_get_type(track) == Animation::TYPE_SCALE_3D || animation->track_get_type(track) == Animation::TYPE_ROTATION_3D)) { draw_texture(down_icon, Vector2(ofs, int(get_size().height - down_icon->get_height()) / 2)); @@ -2213,7 +2209,7 @@ void AnimationTrackEdit::_notification(int p_what) { Ref<Texture2D> icon = get_theme_icon(animation->track_is_compressed(track) ? SNAME("Lock") : SNAME("Remove"), SNAME("EditorIcons")); - remove_rect.position.x = ofs + ((get_size().width - ofs) - icon->get_width()) / 2; + remove_rect.position.x = ofs + ((get_size().width - ofs) - icon->get_width()); remove_rect.position.y = int(get_size().height - icon->get_height()) / 2; remove_rect.size = icon->get_size(); @@ -2792,11 +2788,6 @@ void AnimationTrackEdit::gui_input(const Ref<InputEvent> &p_event) { return; } - if (bezier_edit_rect.has_point(pos)) { - emit_signal(SNAME("bezier_edit")); - accept_event(); - } - // Check keyframes. if (!animation->track_is_compressed(track)) { // Selecting compressed keyframes for editing is not possible. @@ -3326,10 +3317,21 @@ void AnimationTrackEditor::set_animation(const Ref<Animation> &p_anim) { snap->set_disabled(false); snap_mode->set_disabled(false); + bezier_edit_icon->set_disabled(true); + imported_anim_warning->hide(); + bool import_warning_done = false; + bool bezier_done = false; for (int i = 0; i < animation->get_track_count(); i++) { if (animation->track_is_imported(i)) { imported_anim_warning->show(); + import_warning_done = true; + } + if (animation->track_get_type(i) == Animation::TrackType::TYPE_BEZIER) { + bezier_edit_icon->set_disabled(false); + bezier_done = true; + } + if (import_warning_done && bezier_done) { break; } } @@ -3343,6 +3345,7 @@ void AnimationTrackEditor::set_animation(const Ref<Animation> &p_anim) { step->set_read_only(true); snap->set_disabled(true); snap_mode->set_disabled(true); + bezier_edit_icon->set_disabled(true); } } @@ -4167,13 +4170,15 @@ AnimationTrackEditor::TrackIndices AnimationTrackEditor::_confirm_insert(InsertD } break; case Animation::TYPE_BEZIER: { Array array; - array.resize(5); + array.resize(6); array[0] = p_id.value; array[1] = -0.25; array[2] = 0; array[3] = 0.25; array[4] = 0; + array[5] = Animation::HANDLE_MODE_BALANCED; value = array; + bezier_edit_icon->set_disabled(false); } break; case Animation::TYPE_ANIMATION: { @@ -4399,7 +4404,6 @@ void AnimationTrackEditor::_update_tracks() { track_edit->connect("insert_key", callable_mp(this, &AnimationTrackEditor::_insert_key_from_track), varray(i), CONNECT_DEFERRED); track_edit->connect("select_key", callable_mp(this, &AnimationTrackEditor::_key_selected), varray(i), CONNECT_DEFERRED); track_edit->connect("deselect_key", callable_mp(this, &AnimationTrackEditor::_key_deselected), varray(i), CONNECT_DEFERRED); - track_edit->connect("bezier_edit", callable_mp(this, &AnimationTrackEditor::_bezier_edit), varray(i), CONNECT_DEFERRED); track_edit->connect("move_selection_begin", callable_mp(this, &AnimationTrackEditor::_move_selection_begin)); track_edit->connect("move_selection", callable_mp(this, &AnimationTrackEditor::_move_selection)); track_edit->connect("move_selection_commit", callable_mp(this, &AnimationTrackEditor::_move_selection_commit)); @@ -4515,6 +4519,7 @@ void AnimationTrackEditor::_notification(int p_what) { if (p_what == NOTIFICATION_THEME_CHANGED || p_what == NOTIFICATION_ENTER_TREE) { zoom_icon->set_texture(get_theme_icon(SNAME("Zoom"), SNAME("EditorIcons"))); + bezier_edit_icon->set_icon(get_theme_icon(SNAME("EditBezier"), SNAME("EditorIcons"))); snap->set_icon(get_theme_icon(SNAME("Snap"), SNAME("EditorIcons"))); view_group->set_icon(get_theme_icon(view_group->is_pressed() ? SNAME("AnimationTrackList") : SNAME("AnimationTrackGroup"), SNAME("EditorIcons"))); selected_filter->set_icon(get_theme_icon(SNAME("AnimationFilter"), SNAME("EditorIcons"))); @@ -4630,6 +4635,7 @@ void AnimationTrackEditor::_new_track_node_selected(NodePath p_path) { adding_track_path = path_to; prop_selector->set_type_filter(filter); prop_selector->select_property_from_instance(node); + bezier_edit_icon->set_disabled(false); } break; case Animation::TYPE_AUDIO: { if (!node->is_class("AudioStreamPlayer") && !node->is_class("AudioStreamPlayer2D") && !node->is_class("AudioStreamPlayer3D")) { @@ -4946,7 +4952,7 @@ void AnimationTrackEditor::_add_method_key(const String &p_method) { EditorNode::get_singleton()->show_warning(TTR("Method not found in object: ") + p_method); } -void AnimationTrackEditor::_key_selected(int p_key, bool p_single, int p_track) { +void AnimationTrackEditor::_key_selected(int p_track, int p_key, bool p_single) { ERR_FAIL_INDEX(p_track, animation->get_track_count()); ERR_FAIL_INDEX(p_key, animation->track_get_key_count(p_track)); @@ -5294,6 +5300,20 @@ void AnimationTrackEditor::_scroll_input(const Ref<InputEvent> &p_event) { } } +void AnimationTrackEditor::_toggle_bezier_edit() { + if (bezier_edit->is_visible()) { + _cancel_bezier_edit(); + } else { + int track_count = animation->get_track_count(); + for (int i = 0; i < track_count; ++i) { + if (animation->track_get_type(i) == Animation::TrackType::TYPE_BEZIER) { + _bezier_edit(i); + return; + } + } + } +} + void AnimationTrackEditor::_scroll_callback(Vector2 p_scroll_vec, bool p_alt) { if (p_alt) { if (p_scroll_vec.x < 0 || p_scroll_vec.y < 0) { @@ -5322,6 +5342,7 @@ void AnimationTrackEditor::_zoom_callback(Vector2 p_scroll_vec, Vector2 p_origin void AnimationTrackEditor::_cancel_bezier_edit() { bezier_edit->hide(); scroll->show(); + bezier_edit_icon->set_pressed(false); } void AnimationTrackEditor::_bezier_edit(int p_for_track) { @@ -5908,6 +5929,7 @@ void AnimationTrackEditor::_cleanup_animation(Ref<Animation> p_animation) { void AnimationTrackEditor::_view_group_toggle() { _update_tracks(); view_group->set_icon(get_theme_icon(view_group->is_pressed() ? SNAME("AnimationTrackList") : SNAME("AnimationTrackGroup"), SNAME("EditorIcons"))); + bezier_edit->set_filtered(selected_filter->is_pressed()); } bool AnimationTrackEditor::is_grouping_tracks() { @@ -6153,6 +6175,15 @@ AnimationTrackEditor::AnimationTrackEditor() { bottom_hb->add_spacer(); + bezier_edit_icon = memnew(Button); + bezier_edit_icon->set_flat(true); + bezier_edit_icon->set_disabled(true); + bezier_edit_icon->set_toggle_mode(true); + bezier_edit_icon->connect("pressed", callable_mp(this, &AnimationTrackEditor::_toggle_bezier_edit)); + bezier_edit_icon->set_tooltip(TTR("Toggle between the bezier curve editor and track editor.")); + + bottom_hb->add_child(bezier_edit_icon); + selected_filter = memnew(Button); selected_filter->set_flat(true); selected_filter->connect("pressed", callable_mp(this, &AnimationTrackEditor::_view_group_toggle)); // Same function works the same. diff --git a/editor/animation_track_editor.h b/editor/animation_track_editor.h index 50c5c692c0..edba784310 100644 --- a/editor/animation_track_editor.h +++ b/editor/animation_track_editor.h @@ -164,7 +164,6 @@ class AnimationTrackEdit : public Control { Rect2 interp_mode_rect; Rect2 loop_wrap_rect; Rect2 remove_rect; - Rect2 bezier_edit_rect; Ref<Texture2D> type_icon; Ref<Texture2D> selected_icon; @@ -300,6 +299,7 @@ class AnimationTrackEditor : public VBoxContainer { EditorSpinSlider *step; TextureRect *zoom_icon; Button *snap; + Button *bezier_edit_icon; OptionButton *snap_mode; Button *imported_anim_warning; @@ -406,7 +406,7 @@ class AnimationTrackEditor : public VBoxContainer { Map<SelectedKey, KeyInfo> selection; - void _key_selected(int p_key, bool p_single, int p_track); + void _key_selected(int p_track, int p_key, bool p_single); void _key_deselected(int p_key, int p_track); bool moving_selection; @@ -431,6 +431,7 @@ class AnimationTrackEditor : public VBoxContainer { Vector<Ref<AnimationTrackEditPlugin>> track_edit_plugins; + void _toggle_bezier_edit(); void _cancel_bezier_edit(); void _bezier_edit(int p_for_track); diff --git a/editor/debugger/editor_network_profiler.cpp b/editor/debugger/editor_network_profiler.cpp index 698e950f57..b05134144e 100644 --- a/editor/debugger/editor_network_profiler.cpp +++ b/editor/debugger/editor_network_profiler.cpp @@ -56,7 +56,7 @@ void EditorNetworkProfiler::_update_frame() { TreeItem *root = counters_display->create_item(); - for (const KeyValue<ObjectID, DebuggerMarshalls::MultiplayerNodeInfo> &E : nodes_data) { + for (const KeyValue<ObjectID, SceneDebugger::RPCNodeInfo> &E : nodes_data) { TreeItem *node = counters_display->create_item(root); for (int j = 0; j < counters_display->get_columns(); ++j) { @@ -65,9 +65,7 @@ void EditorNetworkProfiler::_update_frame() { node->set_text(0, E.value.node_path); node->set_text(1, E.value.incoming_rpc == 0 ? "-" : itos(E.value.incoming_rpc)); - node->set_text(2, E.value.incoming_rset == 0 ? "-" : itos(E.value.incoming_rset)); - node->set_text(3, E.value.outgoing_rpc == 0 ? "-" : itos(E.value.outgoing_rpc)); - node->set_text(4, E.value.outgoing_rset == 0 ? "-" : itos(E.value.outgoing_rset)); + node->set_text(2, E.value.outgoing_rpc == 0 ? "-" : itos(E.value.outgoing_rpc)); } } @@ -91,14 +89,12 @@ void EditorNetworkProfiler::_clear_pressed() { } } -void EditorNetworkProfiler::add_node_frame_data(const DebuggerMarshalls::MultiplayerNodeInfo p_frame) { +void EditorNetworkProfiler::add_node_frame_data(const SceneDebugger::RPCNodeInfo p_frame) { if (!nodes_data.has(p_frame.node)) { nodes_data.insert(p_frame.node, p_frame); } else { nodes_data[p_frame.node].incoming_rpc += p_frame.incoming_rpc; - nodes_data[p_frame.node].incoming_rset += p_frame.incoming_rset; nodes_data[p_frame.node].outgoing_rpc += p_frame.outgoing_rpc; - nodes_data[p_frame.node].outgoing_rset += p_frame.outgoing_rset; } if (frame_delay->is_stopped()) { @@ -174,7 +170,7 @@ EditorNetworkProfiler::EditorNetworkProfiler() { counters_display->set_v_size_flags(SIZE_EXPAND_FILL); counters_display->set_hide_folding(true); counters_display->set_hide_root(true); - counters_display->set_columns(5); + counters_display->set_columns(3); counters_display->set_column_titles_visible(true); counters_display->set_column_title(0, TTR("Node")); counters_display->set_column_expand(0, true); @@ -184,18 +180,10 @@ EditorNetworkProfiler::EditorNetworkProfiler() { counters_display->set_column_expand(1, false); 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_title(2, TTR("Outgoing RPC")); counters_display->set_column_expand(2, false); 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_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_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_network_profiler.h b/editor/debugger/editor_network_profiler.h index 320dd2a826..3e95eb0de6 100644 --- a/editor/debugger/editor_network_profiler.h +++ b/editor/debugger/editor_network_profiler.h @@ -31,7 +31,7 @@ #ifndef EDITORNETWORKPROFILER_H #define EDITORNETWORKPROFILER_H -#include "core/debugger/debugger_marshalls.h" +#include "scene/debugger/scene_debugger.h" #include "scene/gui/box_container.h" #include "scene/gui/button.h" #include "scene/gui/label.h" @@ -50,7 +50,7 @@ private: Timer *frame_delay; - Map<ObjectID, DebuggerMarshalls::MultiplayerNodeInfo> nodes_data; + Map<ObjectID, SceneDebugger::RPCNodeInfo> nodes_data; void _update_frame(); @@ -62,7 +62,7 @@ protected: static void _bind_methods(); public: - void add_node_frame_data(const DebuggerMarshalls::MultiplayerNodeInfo p_frame); + void add_node_frame_data(const SceneDebugger::RPCNodeInfo p_frame); void set_bandwidth(int p_incoming, int p_outgoing); bool is_profiling(); diff --git a/editor/debugger/script_editor_debugger.cpp b/editor/debugger/script_editor_debugger.cpp index 6a2cb8ee4a..28e8edb26e 100644 --- a/editor/debugger/script_editor_debugger.cpp +++ b/editor/debugger/script_editor_debugger.cpp @@ -63,6 +63,7 @@ #include "scene/gui/texture_button.h" #include "scene/gui/tree.h" #include "scene/resources/packed_scene.h" +#include "servers/debugger/servers_debugger.h" #include "servers/display_server.h" using CameraOverride = EditorDebuggerNode::CameraOverride; @@ -127,6 +128,7 @@ void ScriptEditorDebugger::debug_continue() { _clear_execution(); _put_msg("continue", Array()); + _put_msg("servers:foreground", Array()); } void ScriptEditorDebugger::update_tabs() { @@ -277,7 +279,7 @@ void ScriptEditorDebugger::_remote_object_property_updated(ObjectID p_id, const } void ScriptEditorDebugger::_video_mem_request() { - _put_msg("core:memory", Array()); + _put_msg("servers:memory", Array()); } void ScriptEditorDebugger::_video_mem_export() { @@ -343,15 +345,15 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da if (id.is_valid()) { emit_signal(SNAME("remote_object_updated"), id); } - } else if (p_msg == "memory:usage") { + } else if (p_msg == "servers:memory_usage") { vmem_tree->clear(); TreeItem *root = vmem_tree->create_item(); - DebuggerMarshalls::ResourceUsage usage; + ServersDebugger::ResourceUsage usage; usage.deserialize(p_data); uint64_t total = 0; - for (const DebuggerMarshalls::ResourceInfo &E : usage.infos) { + for (const ServersDebugger::ResourceInfo &E : usage.infos) { TreeItem *it = vmem_tree->create_item(root); String type = E.type; int bytes = E.vram; @@ -444,7 +446,7 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da performance_profiler->add_profile_frame(frame_data); } else if (p_msg == "visual:profile_frame") { - DebuggerMarshalls::VisualProfilerFrame frame; + ServersDebugger::VisualProfilerFrame frame; frame.deserialize(p_data); EditorVisualProfiler::Metric metric; @@ -591,13 +593,13 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da } else if (p_msg == "servers:function_signature") { // Cache a profiler signature. - DebuggerMarshalls::ScriptFunctionSignature sig; + ServersDebugger::ScriptFunctionSignature sig; sig.deserialize(p_data); profiler_signature[sig.id] = sig.name; } else if (p_msg == "servers:profile_frame" || p_msg == "servers:profile_total") { EditorProfiler::Metric metric; - DebuggerMarshalls::ServersProfilerFrame frame; + ServersDebugger::ServersProfilerFrame frame; frame.deserialize(p_data); metric.valid = true; metric.frame_number = frame.frame_number; @@ -641,7 +643,7 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da } for (int i = 0; i < frame.servers.size(); i++) { - const DebuggerMarshalls::ServerInfo &srv = frame.servers[i]; + const ServersDebugger::ServerInfo &srv = frame.servers[i]; EditorProfiler::Metric::Category c; const String name = srv.name; c.name = name.capitalize(); @@ -708,14 +710,14 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da profiler->add_frame_metric(metric, true); } - } else if (p_msg == "network:profile_frame") { - DebuggerMarshalls::NetworkProfilerFrame frame; + } else if (p_msg == "multiplayer:rpc") { + SceneDebugger::RPCProfilerFrame frame; frame.deserialize(p_data); for (int i = 0; i < frame.infos.size(); i++) { network_profiler->add_node_frame_data(frame.infos[i]); } - } else if (p_msg == "network:bandwidth") { + } else if (p_msg == "multiplayer:bandwidth") { ERR_FAIL_COND(p_data.size() < 2); network_profiler->set_bandwidth(p_data[0], p_data[1]); @@ -832,6 +834,9 @@ void ScriptEditorDebugger::_notification(int p_what) { msg.push_back(cam->get_far()); _put_msg("scene:override_camera_3D:transform", msg); } + if (breaked) { + _put_msg("servers:draw", Array()); + } } const uint64_t until = OS::get_singleton()->get_ticks_msec() + 20; @@ -970,7 +975,8 @@ void ScriptEditorDebugger::_profiler_activate(bool p_enable, int p_type) { data.push_back(p_enable); switch (p_type) { case PROFILER_NETWORK: - _put_msg("profiler:network", data); + _put_msg("profiler:multiplayer", data); + _put_msg("profiler:rpc", data); break; case PROFILER_VISUAL: _put_msg("profiler:visual", data); diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index cbfd6ae6de..6bdd6a8134 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -1422,6 +1422,7 @@ EditorInspectorSection::~EditorInspectorSection() { //////////////////////////////////////////////// //////////////////////////////////////////////// + int EditorInspectorArray::_get_array_count() { if (mode == MODE_USE_MOVE_ARRAY_ELEMENT_FUNCTION) { List<PropertyInfo> object_property_list; @@ -1440,31 +1441,8 @@ void EditorInspectorArray::_add_button_pressed() { _move_element(-1, -1); } -void EditorInspectorArray::_first_page_button_pressed() { - emit_signal(SNAME("page_change_request"), 0); -} - -void EditorInspectorArray::_prev_page_button_pressed() { - emit_signal(SNAME("page_change_request"), MAX(0, page - 1)); -} - -void EditorInspectorArray::_page_line_edit_text_submitted(String p_text) { - if (p_text.is_valid_int()) { - int new_page = p_text.to_int() - 1; - new_page = MIN(MAX(0, new_page), max_page); - page_line_edit->set_text(Variant(new_page)); - emit_signal(SNAME("page_change_request"), new_page); - } else { - page_line_edit->set_text(Variant(page)); - } -} - -void EditorInspectorArray::_next_page_button_pressed() { - emit_signal(SNAME("page_change_request"), MIN(max_page, page + 1)); -} - -void EditorInspectorArray::_last_page_button_pressed() { - emit_signal(SNAME("page_change_request"), max_page); +void EditorInspectorArray::_paginator_page_changed(int p_page) { + emit_signal("page_change_request", p_page); } void EditorInspectorArray::_rmb_popup_id_pressed(int p_id) { @@ -1636,17 +1614,17 @@ void EditorInspectorArray::_move_element(int p_element_index, int p_to_pos) { // Handle page change and update counts. if (p_element_index < 0) { int added_index = p_to_pos < 0 ? count : p_to_pos; - emit_signal(SNAME("page_change_request"), added_index / page_lenght); + emit_signal(SNAME("page_change_request"), added_index / page_length); count += 1; } else if (p_to_pos < 0) { count -= 1; - if (page == max_page && (MAX(0, count - 1) / page_lenght != max_page)) { + if (page == max_page && (MAX(0, count - 1) / page_length != max_page)) { emit_signal(SNAME("page_change_request"), max_page - 1); } } - begin_array_index = page * page_lenght; - end_array_index = MIN(count, (page + 1) * page_lenght); - max_page = MAX(0, count - 1) / page_lenght; + begin_array_index = page * page_length; + end_array_index = MIN(count, (page + 1) * page_length); + max_page = MAX(0, count - 1) / page_length; } void EditorInspectorArray::_clear_array() { @@ -1860,9 +1838,9 @@ void EditorInspectorArray::_resize_dialog_confirmed() { void EditorInspectorArray::_setup() { // Setup counts. count = _get_array_count(); - begin_array_index = page * page_lenght; - end_array_index = MIN(count, (page + 1) * page_lenght); - max_page = MAX(0, count - 1) / page_lenght; + begin_array_index = page * page_length; + end_array_index = MIN(count, (page + 1) * page_length); + max_page = MAX(0, count - 1) / page_length; array_elements.resize(MAX(0, end_array_index - begin_array_index)); if (page < 0 || page > max_page) { WARN_PRINT(vformat("Invalid page number %d", page)); @@ -1920,18 +1898,12 @@ void EditorInspectorArray::_setup() { // Hide/show the add button. add_button->set_visible(page == max_page); - if (max_page == 0) { - hbox_pagination->hide(); - } else { - // Update buttons. - first_page_button->set_disabled(page == 0); - prev_page_button->set_disabled(page == 0); - next_page_button->set_disabled(page == max_page); - last_page_button->set_disabled(page == max_page); - - // Update page number and page count. - page_line_edit->set_text(vformat("%d", page + 1)); - page_count_label->set_text(vformat("/ %d", max_page + 1)); + // Add paginator if there's more than 1 page. + if (max_page > 0) { + EditorPaginator *paginator = memnew(EditorPaginator); + paginator->update(page, max_page); + paginator->connect("page_changed", callable_mp(this, &EditorInspectorArray::_paginator_page_changed)); + vbox->add_child(paginator); } } @@ -1996,10 +1968,6 @@ void EditorInspectorArray::_notification(int p_what) { } add_button->set_icon(get_theme_icon(SNAME("Add"), SNAME("EditorIcons"))); - first_page_button->set_icon(get_theme_icon(SNAME("PageFirst"), SNAME("EditorIcons"))); - prev_page_button->set_icon(get_theme_icon(SNAME("PagePrevious"), SNAME("EditorIcons"))); - next_page_button->set_icon(get_theme_icon(SNAME("PageNext"), SNAME("EditorIcons"))); - last_page_button->set_icon(get_theme_icon(SNAME("PageLast"), SNAME("EditorIcons"))); update_minimum_size(); } break; case NOTIFICATION_DRAG_BEGIN: { @@ -2092,38 +2060,6 @@ EditorInspectorArray::EditorInspectorArray() { add_button->connect("pressed", callable_mp(this, &EditorInspectorArray::_add_button_pressed)); vbox->add_child(add_button); - hbox_pagination = memnew(HBoxContainer); - hbox_pagination->set_h_size_flags(SIZE_EXPAND_FILL); - hbox_pagination->set_alignment(BoxContainer::ALIGNMENT_CENTER); - vbox->add_child(hbox_pagination); - - first_page_button = memnew(Button); - first_page_button->set_flat(true); - first_page_button->connect("pressed", callable_mp(this, &EditorInspectorArray::_first_page_button_pressed)); - hbox_pagination->add_child(first_page_button); - - prev_page_button = memnew(Button); - prev_page_button->set_flat(true); - prev_page_button->connect("pressed", callable_mp(this, &EditorInspectorArray::_prev_page_button_pressed)); - hbox_pagination->add_child(prev_page_button); - - page_line_edit = memnew(LineEdit); - page_line_edit->connect("text_submitted", callable_mp(this, &EditorInspectorArray::_page_line_edit_text_submitted)); - page_line_edit->add_theme_constant_override("minimum_character_width", 2); - hbox_pagination->add_child(page_line_edit); - - page_count_label = memnew(Label); - hbox_pagination->add_child(page_count_label); - next_page_button = memnew(Button); - next_page_button->set_flat(true); - next_page_button->connect("pressed", callable_mp(this, &EditorInspectorArray::_next_page_button_pressed)); - hbox_pagination->add_child(next_page_button); - - last_page_button = memnew(Button); - last_page_button->set_flat(true); - last_page_button->connect("pressed", callable_mp(this, &EditorInspectorArray::_last_page_button_pressed)); - hbox_pagination->add_child(last_page_button); - control_dropping = memnew(Control); control_dropping->connect("draw", callable_mp(this, &EditorInspectorArray::_control_dropping_draw)); control_dropping->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); @@ -2149,6 +2085,97 @@ EditorInspectorArray::EditorInspectorArray() { //////////////////////////////////////////////// //////////////////////////////////////////////// +void EditorPaginator::_first_page_button_pressed() { + emit_signal("page_changed", 0); +} + +void EditorPaginator::_prev_page_button_pressed() { + emit_signal("page_changed", MAX(0, page - 1)); +} + +void EditorPaginator::_page_line_edit_text_submitted(String p_text) { + if (p_text.is_valid_int()) { + int new_page = p_text.to_int() - 1; + new_page = MIN(MAX(0, new_page), max_page); + page_line_edit->set_text(Variant(new_page)); + emit_signal("page_changed", new_page); + } else { + page_line_edit->set_text(Variant(page)); + } +} + +void EditorPaginator::_next_page_button_pressed() { + emit_signal("page_changed", MIN(max_page, page + 1)); +} + +void EditorPaginator::_last_page_button_pressed() { + emit_signal("page_changed", max_page); +} + +void EditorPaginator::update(int p_page, int p_max_page) { + page = p_page; + max_page = p_max_page; + + // Update buttons. + first_page_button->set_disabled(page == 0); + prev_page_button->set_disabled(page == 0); + next_page_button->set_disabled(page == max_page); + last_page_button->set_disabled(page == max_page); + + // Update page number and page count. + page_line_edit->set_text(vformat("%d", page + 1)); + page_count_label->set_text(vformat("/ %d", max_page + 1)); +} + +void EditorPaginator::_notification(int p_what) { + if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { + first_page_button->set_icon(get_theme_icon(SNAME("PageFirst"), SNAME("EditorIcons"))); + prev_page_button->set_icon(get_theme_icon(SNAME("PagePrevious"), SNAME("EditorIcons"))); + next_page_button->set_icon(get_theme_icon(SNAME("PageNext"), SNAME("EditorIcons"))); + last_page_button->set_icon(get_theme_icon(SNAME("PageLast"), SNAME("EditorIcons"))); + } +} + +void EditorPaginator::_bind_methods() { + ADD_SIGNAL(MethodInfo("page_changed", PropertyInfo(Variant::INT, "page"))); +} + +EditorPaginator::EditorPaginator() { + set_h_size_flags(SIZE_EXPAND_FILL); + set_alignment(ALIGNMENT_CENTER); + + first_page_button = memnew(Button); + first_page_button->set_flat(true); + first_page_button->connect("pressed", callable_mp(this, &EditorPaginator::_first_page_button_pressed)); + add_child(first_page_button); + + prev_page_button = memnew(Button); + prev_page_button->set_flat(true); + prev_page_button->connect("pressed", callable_mp(this, &EditorPaginator::_prev_page_button_pressed)); + add_child(prev_page_button); + + page_line_edit = memnew(LineEdit); + page_line_edit->connect("text_submitted", callable_mp(this, &EditorPaginator::_page_line_edit_text_submitted)); + page_line_edit->add_theme_constant_override("minimum_character_width", 2); + add_child(page_line_edit); + + page_count_label = memnew(Label); + add_child(page_count_label); + + next_page_button = memnew(Button); + next_page_button->set_flat(true); + next_page_button->connect("pressed", callable_mp(this, &EditorPaginator::_next_page_button_pressed)); + add_child(next_page_button); + + last_page_button = memnew(Button); + last_page_button->set_flat(true); + last_page_button->connect("pressed", callable_mp(this, &EditorPaginator::_last_page_button_pressed)); + add_child(last_page_button); +} + +//////////////////////////////////////////////// +//////////////////////////////////////////////// + Ref<EditorInspectorPlugin> EditorInspector::inspector_plugins[MAX_PLUGINS]; int EditorInspector::inspector_plugin_count = 0; diff --git a/editor/editor_inspector.h b/editor/editor_inspector.h index 09b25065dc..162d45f8b7 100644 --- a/editor/editor_inspector.h +++ b/editor/editor_inspector.h @@ -317,18 +317,11 @@ class EditorInspectorArray : public EditorInspectorSection { LineEdit *new_size_line_edit; // Pagination - int page_lenght = 5; + int page_length = 5; int page = 0; int max_page = 0; int begin_array_index = 0; int end_array_index = 0; - HBoxContainer *hbox_pagination; - Button *first_page_button; - Button *prev_page_button; - LineEdit *page_line_edit; - Label *page_count_label; - Button *next_page_button; - Button *last_page_button; enum MenuOptions { OPTION_MOVE_UP = 0, @@ -356,12 +349,7 @@ class EditorInspectorArray : public EditorInspectorSection { int _get_array_count(); void _add_button_pressed(); - - void _first_page_button_pressed(); - void _prev_page_button_pressed(); - void _page_line_edit_text_submitted(String p_text); - void _next_page_button_pressed(); - void _last_page_button_pressed(); + void _paginator_page_changed(int p_page); void _rmb_popup_id_pressed(int p_id); @@ -402,6 +390,34 @@ public: EditorInspectorArray(); }; +class EditorPaginator : public HBoxContainer { + GDCLASS(EditorPaginator, HBoxContainer); + + int page = 0; + int max_page = 0; + Button *first_page_button; + Button *prev_page_button; + LineEdit *page_line_edit; + Label *page_count_label; + Button *next_page_button; + Button *last_page_button; + + void _first_page_button_pressed(); + void _prev_page_button_pressed(); + void _page_line_edit_text_submitted(String p_text); + void _next_page_button_pressed(); + void _last_page_button_pressed(); + +protected: + void _notification(int p_what); + static void _bind_methods(); + +public: + void update(int p_page, int p_max_page); + + EditorPaginator(); +}; + class EditorInspector : public ScrollContainer { GDCLASS(EditorInspector, ScrollContainer); diff --git a/editor/editor_properties_array_dict.cpp b/editor/editor_properties_array_dict.cpp index c28c7db2cb..fc0c0e7d7b 100644 --- a/editor/editor_properties_array_dict.cpp +++ b/editor/editor_properties_array_dict.cpp @@ -259,8 +259,8 @@ void EditorPropertyArray::update_property() { } int size = array.call("size"); - int pages = MAX(0, size - 1) / page_length + 1; - page_index = MIN(page_index, pages - 1); + int max_page = MAX(0, size - 1) / page_length; + page_index = MIN(page_index, max_page); int offset = page_index * page_length; edit->set_text(arrtype + " (size " + itos(size) + ")"); @@ -292,35 +292,37 @@ void EditorPropertyArray::update_property() { size_slider->connect("value_changed", callable_mp(this, &EditorPropertyArray::_length_changed)); hbox->add_child(size_slider); - page_hbox = memnew(HBoxContainer); - vbox->add_child(page_hbox); + property_vbox = memnew(VBoxContainer); + property_vbox->set_h_size_flags(SIZE_EXPAND_FILL); + vbox->add_child(property_vbox); - label = memnew(Label(TTR("Page: "))); - label->set_h_size_flags(SIZE_EXPAND_FILL); - page_hbox->add_child(label); + button_add_item = memnew(Button); + button_add_item->set_text(TTR("Add Element")); + button_add_item->set_icon(get_theme_icon(SNAME("Add"), SNAME("EditorIcons"))); + button_add_item->connect(SNAME("pressed"), callable_mp(this, &EditorPropertyArray::_add_element)); + vbox->add_child(button_add_item); - page_slider = memnew(EditorSpinSlider); - page_slider->set_step(1); - page_slider->set_h_size_flags(SIZE_EXPAND_FILL); - page_slider->connect("value_changed", callable_mp(this, &EditorPropertyArray::_page_changed)); - page_hbox->add_child(page_slider); + paginator = memnew(EditorPaginator); + paginator->connect("page_changed", callable_mp(this, &EditorPropertyArray::_page_changed)); + vbox->add_child(paginator); } else { // Bye bye children of the box. - for (int i = vbox->get_child_count() - 1; i >= 2; i--) { - Node *child = vbox->get_child(i); + for (int i = property_vbox->get_child_count() - 1; i >= 0; i--) { + Node *child = property_vbox->get_child(i); if (child == reorder_selected_element_hbox) { continue; // Don't remove the property that the user is moving. } child->queue_delete(); // Button still needed after pressed is called. - vbox->remove_child(child); + property_vbox->remove_child(child); } } size_slider->set_value(size); - page_slider->set_max(pages); - page_slider->set_value(page_index); - page_hbox->set_visible(pages > 1); + property_vbox->set_visible(size > 0); + button_add_item->set_visible(page_index == max_page); + paginator->update(page_index, max_page); + paginator->set_visible(max_page > 0); if (array.get_type() == Variant::ARRAY) { array = array.call("duplicate"); @@ -343,7 +345,7 @@ void EditorPropertyArray::update_property() { } HBoxContainer *hbox = memnew(HBoxContainer); - vbox->add_child(hbox); + property_vbox->add_child(hbox); Button *reorder_button = memnew(Button); reorder_button->set_icon(get_theme_icon(SNAME("TripleBar"), SNAME("EditorIcons"))); @@ -397,7 +399,7 @@ void EditorPropertyArray::update_property() { } if (reorder_to_index % page_length > 0) { - vbox->move_child(vbox->get_child(2), reorder_to_index % page_length + 2); + property_vbox->move_child(property_vbox->get_child(0), reorder_to_index % page_length); } updating = false; @@ -510,6 +512,10 @@ void EditorPropertyArray::_notification(int p_what) { } change_type->add_separator(); change_type->add_icon_item(get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")), TTR("Remove Item"), Variant::VARIANT_MAX); + + if (Object::cast_to<Button>(button_add_item)) { + button_add_item->set_icon(get_theme_icon(SNAME("Add"), SNAME("EditorIcons"))); + } } if (p_what == NOTIFICATION_DRAG_BEGIN) { @@ -542,7 +548,7 @@ void EditorPropertyArray::_edit_pressed() { update_property(); } -void EditorPropertyArray::_page_changed(double p_page) { +void EditorPropertyArray::_page_changed(int p_page) { if (updating) { return; } @@ -589,6 +595,10 @@ void EditorPropertyArray::_length_changed(double p_page) { update_property(); } +void EditorPropertyArray::_add_element() { + _length_changed(double(object->get_array().call("size")) + 1.0); +} + void EditorPropertyArray::setup(Variant::Type p_array_type, const String &p_hint_string) { array_type = p_array_type; @@ -633,9 +643,9 @@ void EditorPropertyArray::_reorder_button_gui_input(const Ref<InputEvent> &p_eve reorder_to_index += direction; if ((direction < 0 && reorder_to_index % page_length == page_length - 1) || (direction > 0 && reorder_to_index % page_length == 0)) { // Automatically move to the next/previous page. - page_slider->set_value(page_index + direction); + _page_changed(page_index + direction); } - vbox->move_child(reorder_selected_element_hbox, reorder_to_index % page_length + 2); + property_vbox->move_child(reorder_selected_element_hbox, reorder_to_index % page_length); // Ensure the moving element is visible. InspectorDock::get_inspector_singleton()->ensure_control_visible(reorder_selected_element_hbox); } @@ -645,7 +655,7 @@ void EditorPropertyArray::_reorder_button_gui_input(const Ref<InputEvent> &p_eve void EditorPropertyArray::_reorder_button_down(int p_index) { reorder_from_index = p_index; reorder_to_index = p_index; - reorder_selected_element_hbox = Object::cast_to<HBoxContainer>(vbox->get_child(p_index % page_length + 2)); + reorder_selected_element_hbox = Object::cast_to<HBoxContainer>(property_vbox->get_child(p_index % page_length)); reorder_selected_button = Object::cast_to<Button>(reorder_selected_element_hbox->get_child(0)); // Ideally it'd to be able to show the mouse but I had issues with // Control's `mouse_exit()`/`mouse_entered()` signals not getting called. @@ -685,6 +695,7 @@ void EditorPropertyArray::_bind_methods() { EditorPropertyArray::EditorPropertyArray() { object.instantiate(); page_length = int(EDITOR_GET("interface/inspector/max_array_dictionary_items_per_page")); + edit = memnew(Button); edit->set_h_size_flags(SIZE_EXPAND_FILL); edit->set_clip_text(true); @@ -694,9 +705,12 @@ EditorPropertyArray::EditorPropertyArray() { edit->connect("draw", callable_mp(this, &EditorPropertyArray::_button_draw)); add_child(edit); add_focusable(edit); + vbox = nullptr; - page_slider = nullptr; + property_vbox = nullptr; size_slider = nullptr; + button_add_item = nullptr; + paginator = nullptr; updating = false; change_type = memnew(PopupMenu); add_child(change_type); @@ -824,35 +838,32 @@ void EditorPropertyDictionary::update_property() { add_child(vbox); set_bottom_editor(vbox); - page_hbox = memnew(HBoxContainer); - vbox->add_child(page_hbox); - Label *label = memnew(Label(TTR("Page: "))); - label->set_h_size_flags(SIZE_EXPAND_FILL); - page_hbox->add_child(label); - page_slider = memnew(EditorSpinSlider); - page_slider->set_step(1); - page_hbox->add_child(page_slider); - page_slider->set_h_size_flags(SIZE_EXPAND_FILL); - page_slider->connect("value_changed", callable_mp(this, &EditorPropertyDictionary::_page_changed)); + property_vbox = memnew(VBoxContainer); + property_vbox->set_h_size_flags(SIZE_EXPAND_FILL); + vbox->add_child(property_vbox); + + paginator = memnew(EditorPaginator); + paginator->connect("page_changed", callable_mp(this, &EditorPropertyDictionary::_page_changed)); + vbox->add_child(paginator); } else { // Queue children for deletion, deleting immediately might cause errors. - for (int i = 1; i < vbox->get_child_count(); i++) { - vbox->get_child(i)->queue_delete(); + for (int i = property_vbox->get_child_count() - 1; i >= 0; i--) { + property_vbox->get_child(i)->queue_delete(); } } int size = dict.size(); - int pages = MAX(0, size - 1) / page_length + 1; + int max_page = MAX(0, size - 1) / page_length; + page_index = MIN(page_index, max_page); - page_slider->set_max(pages); - page_index = MIN(page_index, pages - 1); - page_slider->set_value(page_index); - page_hbox->set_visible(pages > 1); + paginator->update(page_index, max_page); + paginator->set_visible(max_page > 0); int offset = page_index * page_length; int amount = MIN(size - offset, page_length); + int total_amount = page_index == max_page ? amount + 2 : amount; // For the "Add Key/Value Pair" box on last page. dict = dict.duplicate(); @@ -860,7 +871,7 @@ void EditorPropertyDictionary::update_property() { VBoxContainer *add_vbox = nullptr; double default_float_step = EDITOR_GET("interface/inspector/default_float_step"); - for (int i = 0; i < amount + 2; i++) { + for (int i = 0; i < total_amount; i++) { String prop_name; Variant key; Variant value; @@ -1074,15 +1085,9 @@ void EditorPropertyDictionary::update_property() { if (i == amount) { PanelContainer *pc = memnew(PanelContainer); - vbox->add_child(pc); - Ref<StyleBoxFlat> flat; - flat.instantiate(); - for (int j = 0; j < 4; j++) { - flat->set_default_margin(Side(j), 2 * EDSCALE); - } - flat->set_bg_color(get_theme_color(SNAME("prop_subsection"), SNAME("Editor"))); + property_vbox->add_child(pc); + pc->add_theme_style_override(SNAME("panel"), get_theme_stylebox(SNAME("DictionaryAddItem"), SNAME("EditorStyles"))); - pc->add_theme_style_override("panel", flat); add_vbox = memnew(VBoxContainer); pc->add_child(add_vbox); } @@ -1110,7 +1115,7 @@ void EditorPropertyDictionary::update_property() { if (add_vbox) { add_vbox->add_child(hbox); } else { - vbox->add_child(hbox); + property_vbox->add_child(hbox); } hbox->add_child(prop); prop->set_h_size_flags(SIZE_EXPAND_FILL); @@ -1173,7 +1178,7 @@ void EditorPropertyDictionary::_edit_pressed() { update_property(); } -void EditorPropertyDictionary::_page_changed(double p_page) { +void EditorPropertyDictionary::_page_changed(int p_page) { if (updating) { return; } @@ -1187,6 +1192,7 @@ void EditorPropertyDictionary::_bind_methods() { EditorPropertyDictionary::EditorPropertyDictionary() { object.instantiate(); page_length = int(EDITOR_GET("interface/inspector/max_array_dictionary_items_per_page")); + edit = memnew(Button); edit->set_h_size_flags(SIZE_EXPAND_FILL); edit->set_clip_text(true); @@ -1194,9 +1200,10 @@ EditorPropertyDictionary::EditorPropertyDictionary() { edit->set_toggle_mode(true); add_child(edit); add_focusable(edit); + vbox = nullptr; - page_slider = nullptr; button_add_item = nullptr; + paginator = nullptr; updating = false; change_type = memnew(PopupMenu); add_child(change_type); diff --git a/editor/editor_properties_array_dict.h b/editor/editor_properties_array_dict.h index bb10cdf97e..292de6d6db 100644 --- a/editor/editor_properties_array_dict.h +++ b/editor/editor_properties_array_dict.h @@ -89,9 +89,10 @@ class EditorPropertyArray : public EditorProperty { int changing_type_index; Button *edit; VBoxContainer *vbox; + VBoxContainer *property_vbox; EditorSpinSlider *size_slider; - EditorSpinSlider *page_slider; - HBoxContainer *page_hbox; + Button *button_add_item; + EditorPaginator *paginator; Variant::Type array_type; Variant::Type subtype; PropertyHint subtype_hint; @@ -103,8 +104,9 @@ class EditorPropertyArray : public EditorProperty { HBoxContainer *reorder_selected_element_hbox = nullptr; Button *reorder_selected_button = nullptr; - void _page_changed(double p_page); + void _page_changed(int p_page); void _length_changed(double p_page); + void _add_element(); void _edit_pressed(); void _property_changed(const String &p_property, Variant p_value, const String &p_name = "", bool p_changing = false); void _change_type(Object *p_button, int p_index); @@ -144,12 +146,12 @@ class EditorPropertyDictionary : public EditorProperty { int changing_type_index; Button *edit; VBoxContainer *vbox; + VBoxContainer *property_vbox; EditorSpinSlider *size_slider; - EditorSpinSlider *page_slider; - HBoxContainer *page_hbox; Button *button_add_item; + EditorPaginator *paginator; - void _page_changed(double p_page); + void _page_changed(int p_page); void _edit_pressed(); void _property_changed(const String &p_property, Variant p_value, const String &p_name = "", bool p_changing = false); void _change_type(Object *p_button, int p_index); diff --git a/editor/editor_themes.cpp b/editor/editor_themes.cpp index 1e373239a6..54b6aa537f 100644 --- a/editor/editor_themes.cpp +++ b/editor/editor_themes.cpp @@ -159,7 +159,7 @@ void editor_register_and_generate_icons(Ref<Theme> p_theme, bool p_dark_theme = ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#ffffff", "#414141"); // Pure white ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#000000", "#bfbfbf"); // Pure black - // Keep pure RGB colors as is, but list them for explicity. + // Keep pure RGB colors as is, but list them for explicitly. ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#ff0000", "#ff0000"); // Pure red ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#00ff00", "#00ff00"); // Pure green ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#0000ff", "#0000ff"); // Pure blue @@ -1501,6 +1501,9 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { Ref<StyleBoxFlat> theme_preview_picker_label_sb = make_flat_stylebox(theme_preview_picker_label_bg_color, 4.0, 1.0, 4.0, 3.0); theme->set_stylebox("preview_picker_label", "ThemeEditor", theme_preview_picker_label_sb); + // Dictionary editor add item. + theme->set_stylebox("DictionaryAddItem", "EditorStyles", make_flat_stylebox(prop_subsection_color, 4, 4, 4, 4, corner_radius)); + // adaptive script theme constants // for comments and elements with lower relevance const Color dim_color = Color(font_color.r, font_color.g, font_color.b, 0.5); diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index aa8ad55ff3..48c5c0ebc4 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -5955,8 +5955,6 @@ bool CanvasItemEditorViewport::can_drop_data(const Point2 &p_point, const Varian continue; } memdelete(instantiated_scene); - } else { - continue; } can_instantiate = true; break; diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp index e35af6dd64..9884c45916 100644 --- a/editor/plugins/node_3d_editor_plugin.cpp +++ b/editor/plugins/node_3d_editor_plugin.cpp @@ -385,8 +385,6 @@ int Node3DEditorViewport::get_selected_count() const { } void Node3DEditorViewport::cancel_transform() { - _edit.mode = TRANSFORM_NONE; - List<Node *> &selection = editor_selection->get_selected_node_list(); for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { @@ -402,7 +400,8 @@ void Node3DEditorViewport::cancel_transform() { sp->set_global_transform(se->original); } - surface->update(); + + finish_transform(); set_message(TTR("Transform Aborted."), 3); } @@ -3959,8 +3958,6 @@ bool Node3DEditorViewport::can_drop_data_fw(const Point2 &p_point, const Variant continue; } memdelete(instantiated_scene); - } else { - continue; } can_instantiate = true; break; @@ -4063,12 +4060,9 @@ void Node3DEditorViewport::commit_transform() { undo_redo->add_undo_method(sp, "set_global_transform", se->original); } undo_redo->commit_action(); - _edit.mode = TRANSFORM_NONE; - _edit.instant = false; - spatial_editor->set_local_coords_enabled(_edit.original_local); + + finish_transform(); set_message(""); - spatial_editor->update_transform_gizmo(); - surface->update(); } void Node3DEditorViewport::update_transform(Point2 p_mousepos, bool p_shift) { @@ -4407,6 +4401,14 @@ void Node3DEditorViewport::update_transform(Point2 p_mousepos, bool p_shift) { } } +void Node3DEditorViewport::finish_transform() { + spatial_editor->set_local_coords_enabled(_edit.original_local); + spatial_editor->update_transform_gizmo(); + _edit.mode = TRANSFORM_NONE; + _edit.instant = false; + surface->update(); +} + Node3DEditorViewport::Node3DEditorViewport(Node3DEditor *p_spatial_editor, EditorNode *p_editor, int p_index) { cpu_time_history_index = 0; gpu_time_history_index = 0; diff --git a/editor/plugins/node_3d_editor_plugin.h b/editor/plugins/node_3d_editor_plugin.h index bbe5615570..cb7c5a714b 100644 --- a/editor/plugins/node_3d_editor_plugin.h +++ b/editor/plugins/node_3d_editor_plugin.h @@ -409,6 +409,7 @@ private: void begin_transform(TransformMode p_mode, bool instant); void commit_transform(); void update_transform(Point2 p_mousepos, bool p_shift); + void finish_transform(); protected: void _notification(int p_what); diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index 0e362b13c6..a4f9563840 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -1560,7 +1560,7 @@ void SceneTreeDock::perform_node_renames(Node *p_base, Map<Node *, NodePath> *p_ for (int i = 0; i < anim->get_track_count(); i++) { NodePath track_np = anim->track_get_path(i); - Node *n = root->get_node(track_np); + Node *n = root->get_node_or_null(track_np); if (!n) { continue; } diff --git a/main/main.cpp b/main/main.cpp index 0bca5bef0c..1efe3ccd94 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -2789,8 +2789,6 @@ void Main::cleanup(bool p_force) { ERR_FAIL_COND(!_start_success); } - EngineDebugger::deinitialize(); - ResourceLoader::remove_custom_loaders(); ResourceSaver::remove_custom_savers(); @@ -2833,6 +2831,8 @@ void Main::cleanup(bool p_force) { unregister_scene_types(); unregister_server_types(); + EngineDebugger::deinitialize(); + if (xr_server) { memdelete(xr_server); } diff --git a/misc/hooks/pre-commit-black b/misc/hooks/pre-commit-black index 8e22e6068e..fd93bfe73c 100755 --- a/misc/hooks/pre-commit-black +++ b/misc/hooks/pre-commit-black @@ -139,11 +139,11 @@ fi while true; do if [ $terminal = "0" ] ; then if [ -x "$ZENITY" ] ; then - ans=$($ZENITY --text-info --filename="$patch" --width=800 --height=600 --title="Do you want to apply that patch?" --ok-label="Apply" --cancel-label="Do not apply" --extra-button="Apply and stage") + choice=$($ZENITY --text-info --filename="$patch" --width=800 --height=600 --title="Do you want to apply that patch?" --ok-label="Apply" --cancel-label="Do not apply" --extra-button="Apply and stage") if [ "$?" = "0" ] ; then yn="Y" else - if [ "$ans" = "Apply and stage" ] ; then + if [ "$choice" = "Apply and stage" ] ; then yn="S" else yn="N" @@ -151,10 +151,10 @@ while true; do fi elif [ -x "$XMSG" ] ; then $XMSG -file "$patch" -buttons "Apply":100,"Apply and stage":200,"Do not apply":0 -center -default "Do not apply" -geometry 800x600 -title "Do you want to apply that patch?" - ans=$? - if [ "$ans" = "100" ] ; then + choice=$? + if [ "$choice" = "100" ] ; then yn="Y" - elif [ "$ans" = "200" ] ; then + elif [ "$choice" = "200" ] ; then yn="S" else yn="N" @@ -162,10 +162,10 @@ while true; do elif [ \( \( "$OSTYPE" = "msys" \) -o \( "$OSTYPE" = "win32" \) \) -a \( -x "$PWSH" \) ]; then winmessage="$(canonicalize_filename "./.git/hooks/winmessage.ps1")" $PWSH -noprofile -executionpolicy bypass -file "$winmessage" -file "$patch" -buttons "Apply":100,"Apply and stage":200,"Do not apply":0 -center -default "Do not apply" -geometry 800x600 -title "Do you want to apply that patch?" - ans=$? - if [ "$ans" = "100" ] ; then + choice=$? + if [ "$choice" = "100" ] ; then yn="Y" - elif [ "$ans" = "200" ] ; then + elif [ "$choice" = "200" ] ; then yn="S" else yn="N" diff --git a/misc/hooks/pre-commit-clang-format b/misc/hooks/pre-commit-clang-format index de5d9c3f06..2ee3f569d5 100755 --- a/misc/hooks/pre-commit-clang-format +++ b/misc/hooks/pre-commit-clang-format @@ -179,11 +179,11 @@ fi while true; do if [ $terminal = "0" ] ; then if [ -x "$ZENITY" ] ; then - ans=$($ZENITY --text-info --filename="$patch" --width=800 --height=600 --title="Do you want to apply that patch?" --ok-label="Apply" --cancel-label="Do not apply" --extra-button="Apply and stage") + choice=$($ZENITY --text-info --filename="$patch" --width=800 --height=600 --title="Do you want to apply that patch?" --ok-label="Apply" --cancel-label="Do not apply" --extra-button="Apply and stage") if [ "$?" = "0" ] ; then yn="Y" else - if [ "$ans" = "Apply and stage" ] ; then + if [ "$choice" = "Apply and stage" ] ; then yn="S" else yn="N" @@ -191,10 +191,10 @@ while true; do fi elif [ -x "$XMSG" ] ; then $XMSG -file "$patch" -buttons "Apply":100,"Apply and stage":200,"Do not apply":0 -center -default "Do not apply" -geometry 800x600 -title "Do you want to apply that patch?" - ans=$? - if [ "$ans" = "100" ] ; then + choice=$? + if [ "$choice" = "100" ] ; then yn="Y" - elif [ "$ans" = "200" ] ; then + elif [ "$choice" = "200" ] ; then yn="S" else yn="N" @@ -202,10 +202,10 @@ while true; do elif [ \( \( "$OSTYPE" = "msys" \) -o \( "$OSTYPE" = "win32" \) \) -a \( -x "$PWSH" \) ]; then winmessage="$(canonicalize_filename "./.git/hooks/winmessage.ps1")" $PWSH -noprofile -executionpolicy bypass -file "$winmessage" -file "$patch" -buttons "Apply":100,"Apply and stage":200,"Do not apply":0 -center -default "Do not apply" -geometry 800x600 -title "Do you want to apply that patch?" - ans=$? - if [ "$ans" = "100" ] ; then + choice=$? + if [ "$choice" = "100" ] ; then yn="Y" - elif [ "$ans" = "200" ] ; then + elif [ "$choice" = "200" ] ; then yn="S" else yn="N" diff --git a/misc/scripts/codespell.sh b/misc/scripts/codespell.sh new file mode 100644 index 0000000000..2822c6421b --- /dev/null +++ b/misc/scripts/codespell.sh @@ -0,0 +1,5 @@ +#!/bin/sh +SKIP_LIST="./thirdparty,*.gen.*,*.po,*.pot,package-lock.json,./core/string/locales.h,./DONORS.md,./misc/scripts/codespell.sh" +IGNORE_LIST="ba,childs,curvelinear,expct,fave,findn,gird,inout,lod,nd,numer,ois,ro,statics,te,varn" + +codespell -w -q 3 -S "${SKIP_LIST}" -L "${IGNORE_LIST}" diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp index 0056fee7a4..a3dcfddc7f 100644 --- a/modules/gltf/gltf_document.cpp +++ b/modules/gltf/gltf_document.cpp @@ -3373,9 +3373,9 @@ Error GLTFDocument::_serialize_materials(Ref<GLTFState> state) { orm_texture_index = _set_texture(state, orm_texture); } if (has_ao) { - Dictionary ot; - ot["index"] = orm_texture_index; - d["occlusionTexture"] = ot; + Dictionary occt; + occt["index"] = orm_texture_index; + d["occlusionTexture"] = occt; } if (has_roughness || has_metalness) { mrt["index"] = orm_texture_index; diff --git a/modules/text_server_adv/script_iterator.cpp b/modules/text_server_adv/script_iterator.cpp index 9e3d9138d0..06e934c67d 100644 --- a/modules/text_server_adv/script_iterator.cpp +++ b/modules/text_server_adv/script_iterator.cpp @@ -82,7 +82,7 @@ ScriptIterator::ScriptIterator(const String &p_string, int p_start, int p_length paren_stack[paren_sp].pair_index = ch; paren_stack[paren_sp].script_code = script_code; } else if (paren_sp >= 0) { - // If it's a close character, find the matching open on the stack, and use that script code. Any non-matching open characters above it on the stack will be poped. + // If it's a close character, find the matching open on the stack, and use that script code. Any non-matching open characters above it on the stack will be popped. UChar32 paired_ch = u_getBidiPairedBracket(ch); while (paren_sp >= 0 && paren_stack[paren_sp].pair_index != paired_ch) { paren_sp -= 1; diff --git a/modules/visual_script/editor/visual_script_property_selector.cpp b/modules/visual_script/editor/visual_script_property_selector.cpp index bba5410629..cf0111ee7c 100644 --- a/modules/visual_script/editor/visual_script_property_selector.cpp +++ b/modules/visual_script/editor/visual_script_property_selector.cpp @@ -493,7 +493,7 @@ VisualScriptPropertySelector::VisualScriptPropertySelector() { hbox->add_child(scope_combo); search_box = memnew(LineEdit); - search_box->set_tooltip(TTR("Enter \" \" to show all filterd options\nEnter \".\" to show all filterd methods, operators and constructors\nUse CTRL_KEY to drop property setters")); + search_box->set_tooltip(TTR("Enter \" \" to show all filtered options\nEnter \".\" to show all filtered methods, operators and constructors\nUse CTRL_KEY to drop property setters")); search_box->set_custom_minimum_size(Size2(200, 0) * EDSCALE); search_box->set_h_size_flags(Control::SIZE_EXPAND_FILL); search_box->connect("text_changed", callable_mp(this, &VisualScriptPropertySelector::_update_results_s)); @@ -694,7 +694,7 @@ bool VisualScriptPropertySelector::SearchRunner::_phase_match_classes_init() { class_doc.name = selector_ui->base_script; class_doc.inherits = script->get_instance_base_type(); - class_doc.brief_description = ".vs files not suported by EditorHelp::get_doc_data()"; + class_doc.brief_description = ".vs files not supported by EditorHelp::get_doc_data()"; class_doc.description = ""; Object *obj = ObjectDB::get_instance(script->get_instance_id()); @@ -711,9 +711,9 @@ bool VisualScriptPropertySelector::SearchRunner::_phase_match_classes_init() { class_doc.signals.push_back(_get_method_doc(S->get())); } - List<PropertyInfo> propertys; - Object::cast_to<Script>(obj)->get_script_property_list(&propertys); - for (List<PropertyInfo>::Element *P = propertys.front(); P; P = P->next()) { + List<PropertyInfo> properties; + Object::cast_to<Script>(obj)->get_script_property_list(&properties); + for (List<PropertyInfo>::Element *P = properties.front(); P; P = P->next()) { DocData::PropertyDoc pd = DocData::PropertyDoc(); pd.name = P->get().name; pd.type = Variant::get_type_name(P->get().type); diff --git a/modules/websocket/wsl_client.cpp b/modules/websocket/wsl_client.cpp index bebb198126..1ef571b6ee 100644 --- a/modules/websocket/wsl_client.cpp +++ b/modules/websocket/wsl_client.cpp @@ -177,7 +177,7 @@ Error WSLClient::connect_to_host(String p_host, String p_path, uint16_t p_port, } } - // We assume OK while hostname resultion is pending. + // We assume OK while hostname resolution is pending. Error err = _resolver_id != IP::RESOLVER_INVALID_ID ? OK : FAILED; while (_ip_candidates.size()) { err = _tcp->connect_to_host(_ip_candidates.pop_front(), p_port); diff --git a/platform/android/display_server_android.cpp b/platform/android/display_server_android.cpp index b0f16337ed..a7a8801bdc 100644 --- a/platform/android/display_server_android.cpp +++ b/platform/android/display_server_android.cpp @@ -164,7 +164,7 @@ int DisplayServerAndroid::screen_get_dpi(int p_screen) const { float DisplayServerAndroid::screen_get_refresh_rate(int p_screen) const { GodotIOJavaWrapper *godot_io_java = OS_Android::get_singleton()->get_godot_io_java(); if (!godot_io_java) { - ERR_PRINT("An error occured while trying to get the screen refresh rate."); + ERR_PRINT("An error occurred while trying to get the screen refresh rate."); return SCREEN_REFRESH_RATE_FALLBACK; } diff --git a/platform/android/java_godot_io_wrapper.cpp b/platform/android/java_godot_io_wrapper.cpp index 8a2788e848..ff0bcf0716 100644 --- a/platform/android/java_godot_io_wrapper.cpp +++ b/platform/android/java_godot_io_wrapper.cpp @@ -141,12 +141,12 @@ float GodotIOJavaWrapper::get_screen_refresh_rate(float fallback) { if (_get_screen_refresh_rate) { JNIEnv *env = get_jni_env(); if (env == nullptr) { - ERR_PRINT("An error occured while trying to get screen refresh rate."); + ERR_PRINT("An error occurred while trying to get screen refresh rate."); return fallback; } return (float)env->CallDoubleMethod(godot_io_instance, _get_screen_refresh_rate, (double)fallback); } - ERR_PRINT("An error occured while trying to get the screen refresh rate."); + ERR_PRINT("An error occurred while trying to get the screen refresh rate."); return fallback; } diff --git a/platform/linuxbsd/display_server_x11.cpp b/platform/linuxbsd/display_server_x11.cpp index bf9c9b1766..86c3534fc9 100644 --- a/platform/linuxbsd/display_server_x11.cpp +++ b/platform/linuxbsd/display_server_x11.cpp @@ -1077,7 +1077,7 @@ float DisplayServerX11::screen_get_refresh_rate(int p_screen) const { monitors = xrr_get_monitors(x11_display, windows[MAIN_WINDOW_ID].x11_window, true, &count); ERR_FAIL_INDEX_V(p_screen, count, SCREEN_REFRESH_RATE_FALLBACK); } else { - ERR_PRINT("An error occured while trying to get the screen refresh rate."); + ERR_PRINT("An error occurred while trying to get the screen refresh rate."); return SCREEN_REFRESH_RATE_FALLBACK; } @@ -1105,14 +1105,14 @@ float DisplayServerX11::screen_get_refresh_rate(int p_screen) const { } } - ERR_PRINT("An error occured while trying to get the screen refresh rate."); // We should have returned the refresh rate by now. An error must have occured. + ERR_PRINT("An error occurred while trying to get the screen refresh rate."); // We should have returned the refresh rate by now. An error must have occurred. return SCREEN_REFRESH_RATE_FALLBACK; } else { - ERR_PRINT("An error occured while trying to get the screen refresh rate."); + ERR_PRINT("An error occurred while trying to get the screen refresh rate."); return SCREEN_REFRESH_RATE_FALLBACK; } } - ERR_PRINT("An error occured while trying to get the screen refresh rate."); + ERR_PRINT("An error occurred while trying to get the screen refresh rate."); return SCREEN_REFRESH_RATE_FALLBACK; } diff --git a/platform/osx/display_server_osx.mm b/platform/osx/display_server_osx.mm index 2691664b96..137b1b45b0 100644 --- a/platform/osx/display_server_osx.mm +++ b/platform/osx/display_server_osx.mm @@ -1335,7 +1335,7 @@ float DisplayServerOSX::screen_get_refresh_rate(int p_screen) const { const double displayRefreshRate = CGDisplayModeGetRefreshRate(displayMode); return (float)displayRefreshRate; } - ERR_PRINT("An error occured while trying to get the screen refresh rate."); + ERR_PRINT("An error occurred while trying to get the screen refresh rate."); return SCREEN_REFRESH_RATE_FALLBACK; } diff --git a/scene/3d/spring_arm_3d.cpp b/scene/3d/spring_arm_3d.cpp index e0cd44e05b..8a8964f69a 100644 --- a/scene/3d/spring_arm_3d.cpp +++ b/scene/3d/spring_arm_3d.cpp @@ -185,14 +185,14 @@ void SpringArm3D::process_spring() { } current_spring_length = spring_length * motion_delta; - Transform3D childs_transform; - childs_transform.origin = get_global_transform().origin + cast_direction * (spring_length * motion_delta); + Transform3D child_transform; + child_transform.origin = get_global_transform().origin + cast_direction * (spring_length * motion_delta); for (int i = get_child_count() - 1; 0 <= i; --i) { Node3D *child = Object::cast_to<Node3D>(get_child(i)); if (child) { - childs_transform.basis = child->get_global_transform().basis; - child->set_global_transform(childs_transform); + child_transform.basis = child->get_global_transform().basis; + child->set_global_transform(child_transform); } } } diff --git a/scene/debugger/scene_debugger.cpp b/scene/debugger/scene_debugger.cpp index 41340f281b..e5b81f9d8d 100644 --- a/scene/debugger/scene_debugger.cpp +++ b/scene/debugger/scene_debugger.cpp @@ -31,30 +31,121 @@ #include "scene_debugger.h" #include "core/debugger/engine_debugger.h" +#include "core/debugger/engine_profiler.h" #include "core/io/marshalls.h" #include "core/object/script_language.h" #include "scene/main/scene_tree.h" #include "scene/main/window.h" #include "scene/resources/packed_scene.h" -void SceneDebugger::initialize() { +Array SceneDebugger::RPCProfilerFrame::serialize() { + Array arr; + arr.push_back(infos.size() * 4); + for (int i = 0; i < infos.size(); ++i) { + arr.push_back(uint64_t(infos[i].node)); + arr.push_back(infos[i].node_path); + arr.push_back(infos[i].incoming_rpc); + arr.push_back(infos[i].outgoing_rpc); + } + return arr; +} + +bool SceneDebugger::RPCProfilerFrame::deserialize(const Array &p_arr) { + ERR_FAIL_COND_V(p_arr.size() < 1, false); + uint32_t size = p_arr[0]; + ERR_FAIL_COND_V(size % 4, false); + ERR_FAIL_COND_V((uint32_t)p_arr.size() != size + 1, false); + infos.resize(size / 4); + int idx = 1; + for (uint32_t i = 0; i < size / 4; ++i) { + infos.write[i].node = uint64_t(p_arr[idx]); + infos.write[i].node_path = p_arr[idx + 1]; + infos.write[i].incoming_rpc = p_arr[idx + 2]; + infos.write[i].outgoing_rpc = p_arr[idx + 3]; + } + return true; +} + +class SceneDebugger::RPCProfiler : public EngineProfiler { + Map<ObjectID, RPCNodeInfo> rpc_node_data; + uint64_t last_profile_time = 0; + + void init_node(const ObjectID p_node) { + if (rpc_node_data.has(p_node)) { + return; + } + rpc_node_data.insert(p_node, RPCNodeInfo()); + rpc_node_data[p_node].node = p_node; + rpc_node_data[p_node].node_path = Object::cast_to<Node>(ObjectDB::get_instance(p_node))->get_path(); + rpc_node_data[p_node].incoming_rpc = 0; + rpc_node_data[p_node].outgoing_rpc = 0; + } + +public: + void toggle(bool p_enable, const Array &p_opts) { + rpc_node_data.clear(); + } + + void add(const Array &p_data) { + ERR_FAIL_COND(p_data.size() < 2); + const ObjectID id = p_data[0]; + const String what = p_data[1]; + init_node(id); + RPCNodeInfo &info = rpc_node_data[id]; + if (what == "rpc_in") { + info.incoming_rpc++; + } else if (what == "rpc_out") { + info.outgoing_rpc++; + } + } + + void tick(double p_frame_time, double p_idle_time, double p_physics_time, double p_physics_frame_time) { + uint64_t pt = OS::get_singleton()->get_ticks_msec(); + if (pt - last_profile_time > 100) { + last_profile_time = pt; + RPCProfilerFrame frame; + for (const KeyValue<ObjectID, RPCNodeInfo> &E : rpc_node_data) { + frame.infos.push_back(E.value); + } + rpc_node_data.clear(); + EngineDebugger::get_singleton()->send_message("multiplayer:rpc", frame.serialize()); + } + } +}; + +SceneDebugger *SceneDebugger::singleton = nullptr; + +SceneDebugger::SceneDebugger() { + singleton = this; + rpc_profiler.instantiate(); + rpc_profiler->bind("rpc"); #ifdef DEBUG_ENABLED LiveEditor::singleton = memnew(LiveEditor); EngineDebugger::register_message_capture("scene", EngineDebugger::Capture(nullptr, SceneDebugger::parse_message)); #endif } -void SceneDebugger::deinitialize() { +SceneDebugger::~SceneDebugger() { #ifdef DEBUG_ENABLED if (LiveEditor::singleton) { - // Should be removed automatically when deiniting debugger, but just in case - if (EngineDebugger::has_capture("scene")) { - EngineDebugger::unregister_message_capture("scene"); - } + EngineDebugger::unregister_message_capture("scene"); memdelete(LiveEditor::singleton); LiveEditor::singleton = nullptr; } #endif + singleton = nullptr; +} + +void SceneDebugger::initialize() { + if (EngineDebugger::is_active()) { + memnew(SceneDebugger); + } +} + +void SceneDebugger::deinitialize() { + if (singleton) { + memdelete(singleton); + } } #ifdef DEBUG_ENABLED diff --git a/scene/debugger/scene_debugger.h b/scene/debugger/scene_debugger.h index c8298391bb..dd0a17c2dc 100644 --- a/scene/debugger/scene_debugger.h +++ b/scene/debugger/scene_debugger.h @@ -32,6 +32,7 @@ #define SCENE_DEBUGGER_H #include "core/object/class_db.h" +#include "core/object/ref_counted.h" #include "core/string/ustring.h" #include "core/templates/pair.h" #include "core/variant/array.h" @@ -41,9 +42,36 @@ class Node; class SceneDebugger { public: + // RPC profiler + struct RPCNodeInfo { + ObjectID node; + String node_path; + int incoming_rpc = 0; + int outgoing_rpc = 0; + }; + + struct RPCProfilerFrame { + Vector<RPCNodeInfo> infos; + + Array serialize(); + bool deserialize(const Array &p_arr); + }; + +private: + class RPCProfiler; + + static SceneDebugger *singleton; + + Ref<RPCProfiler> rpc_profiler; + + SceneDebugger(); + +public: static void initialize(); static void deinitialize(); + ~SceneDebugger(); + #ifdef DEBUG_ENABLED private: static void _save_node(ObjectID id, const String &p_path); diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 4865b9770e..86e5afcb7c 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -4157,6 +4157,14 @@ int RichTextLabel::get_content_height() const { return total_height; } +int RichTextLabel::get_content_width() const { + int total_width = 0; + for (int i = 0; i < main->lines.size(); i++) { + total_width = MAX(total_width, main->lines[i].offset.x + main->lines[i].text_buf->get_size().x); + } + return total_width; +} + #ifndef DISABLE_DEPRECATED // People will be very angry, if their texts get erased, because of #39148. (3.x -> 4.0) // Although some people may not used bbcode_text, so we only overwrite, if bbcode_text is not empty. @@ -4279,6 +4287,7 @@ void RichTextLabel::_bind_methods() { ClassDB::bind_method(D_METHOD("get_visible_paragraph_count"), &RichTextLabel::get_visible_paragraph_count); ClassDB::bind_method(D_METHOD("get_content_height"), &RichTextLabel::get_content_height); + ClassDB::bind_method(D_METHOD("get_content_width"), &RichTextLabel::get_content_width); ClassDB::bind_method(D_METHOD("parse_expressions_for_values", "expressions"), &RichTextLabel::parse_expressions_for_values); diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h index e79244f2e4..ea3a08d7bd 100644 --- a/scene/gui/rich_text_label.h +++ b/scene/gui/rich_text_label.h @@ -554,6 +554,7 @@ public: int get_visible_line_count() const; int get_content_height() const; + int get_content_width() const; VScrollBar *get_v_scroll_bar() { return vscroll; } diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index bb259843b8..5295acce8f 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -2472,7 +2472,7 @@ void TextEdit::_update_placeholder() { return; // Not in tree? } - // Placeholder is generally smaller then text docuemnts, and updates less so this should be fast enough for now. + // Placeholder is generally smaller then text documents, and updates less so this should be fast enough for now. placeholder_data_buf->clear(); placeholder_data_buf->set_width(text.get_width()); placeholder_data_buf->set_direction((TextServer::Direction)text_direction); diff --git a/scene/multiplayer/scene_cache_interface.cpp b/scene/multiplayer/scene_cache_interface.cpp index de4a94470a..2f278ed864 100644 --- a/scene/multiplayer/scene_cache_interface.cpp +++ b/scene/multiplayer/scene_cache_interface.cpp @@ -107,6 +107,10 @@ void SceneCacheInterface::process_simplify_path(int p_from, const uint8_t *p_pac Ref<MultiplayerPeer> multiplayer_peer = multiplayer->get_multiplayer_peer(); ERR_FAIL_COND(multiplayer_peer.is_null()); +#ifdef DEBUG_ENABLED + multiplayer->profile_bandwidth("out", packet.size()); +#endif + multiplayer_peer->set_transfer_channel(0); multiplayer_peer->set_transfer_mode(Multiplayer::TRANSFER_MODE_RELIABLE); multiplayer_peer->set_target_peer(p_from); @@ -188,6 +192,10 @@ bool SceneCacheInterface::_send_confirm_path(Node *p_node, NodePath p_path, Path Ref<MultiplayerPeer> multiplayer_peer = multiplayer->get_multiplayer_peer(); ERR_FAIL_COND_V(multiplayer_peer.is_null(), false); +#ifdef DEBUG_ENABLED + multiplayer->profile_bandwidth("out", packet.size() * peers_to_add.size()); +#endif + for (int &E : peers_to_add) { multiplayer_peer->set_target_peer(E); // To all of you. multiplayer_peer->set_transfer_channel(0); diff --git a/scene/multiplayer/scene_replication_interface.cpp b/scene/multiplayer/scene_replication_interface.cpp index 2088a43ba7..25a704b37e 100644 --- a/scene/multiplayer/scene_replication_interface.cpp +++ b/scene/multiplayer/scene_replication_interface.cpp @@ -147,6 +147,11 @@ Error SceneReplicationInterface::_send_raw(const uint8_t *p_buffer, int p_size, ERR_FAIL_COND_V(!p_buffer || p_size < 1, ERR_INVALID_PARAMETER); ERR_FAIL_COND_V(!multiplayer, ERR_UNCONFIGURED); ERR_FAIL_COND_V(!multiplayer->has_multiplayer_peer(), ERR_UNCONFIGURED); + +#ifdef DEBUG_ENABLED + multiplayer->profile_bandwidth("out", p_size); +#endif + Ref<MultiplayerPeer> peer = multiplayer->get_multiplayer_peer(); peer->set_target_peer(p_peer); peer->set_transfer_channel(0); diff --git a/scene/multiplayer/scene_rpc_interface.cpp b/scene/multiplayer/scene_rpc_interface.cpp index 7d7f57b9a1..2239a5d81c 100644 --- a/scene/multiplayer/scene_rpc_interface.cpp +++ b/scene/multiplayer/scene_rpc_interface.cpp @@ -46,12 +46,11 @@ void SceneRPCInterface::make_default() { #ifdef DEBUG_ENABLED _FORCE_INLINE_ void SceneRPCInterface::_profile_node_data(const String &p_what, ObjectID p_id) { - if (EngineDebugger::is_profiling("multiplayer")) { + if (EngineDebugger::is_profiling("rpc")) { Array values; - values.push_back("node"); values.push_back(p_id); values.push_back(p_what); - EngineDebugger::profiler_add_frame_data("multiplayer", values); + EngineDebugger::profiler_add_frame_data("rpc", values); } } #else @@ -268,7 +267,7 @@ void SceneRPCInterface::_process_rpc(Node *p_node, const uint16_t p_rpc_method_i argp.resize(argc); #ifdef DEBUG_ENABLED - _profile_node_data("in_rpc", p_node->get_instance_id()); + _profile_node_data("rpc_in", p_node->get_instance_id()); #endif int out; @@ -460,7 +459,7 @@ void SceneRPCInterface::rpcp(Object *p_obj, int p_peer_id, const StringName &p_m uint16_t rpc_id = UINT16_MAX; const Multiplayer::RPCConfig config = _get_rpc_config(node, p_method, rpc_id); ERR_FAIL_COND_MSG(config.name == StringName(), - vformat("Unable to get the RPC configuration for the function \"%s\" at path: \"%s\". This happens when the method is not marked for RPCs.", p_method, node->get_path())); + vformat("Unable to get the RPC configuration for the function \"%s\" at path: \"%s\". This happens when the method is missing or not marked for RPCs in the local script.", p_method, node->get_path())); if (p_peer_id == 0 || p_peer_id == node_id || (p_peer_id < 0 && p_peer_id != -node_id)) { if (rpc_id & (1 << 15)) { call_local_native = config.call_local; @@ -471,7 +470,7 @@ void SceneRPCInterface::rpcp(Object *p_obj, int p_peer_id, const StringName &p_m if (p_peer_id != node_id) { #ifdef DEBUG_ENABLED - _profile_node_data("out_rpc", node->get_instance_id()); + _profile_node_data("rpc_out", node->get_instance_id()); #endif _send_rpc(node, p_peer_id, rpc_id, config, p_method, p_arg, p_argcount); diff --git a/scene/resources/environment.cpp b/scene/resources/environment.cpp index b13ae9d016..bf17a6ea97 100644 --- a/scene/resources/environment.cpp +++ b/scene/resources/environment.cpp @@ -1332,7 +1332,7 @@ void Environment::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "sdfgi_min_cell_size", PROPERTY_HINT_RANGE, "0.01,64,0.01"), "set_sdfgi_min_cell_size", "get_sdfgi_min_cell_size"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "sdfgi_cascade0_distance", PROPERTY_HINT_RANGE, "0.1,16384,0.1,or_greater"), "set_sdfgi_cascade0_distance", "get_sdfgi_cascade0_distance"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "sdfgi_max_distance", PROPERTY_HINT_RANGE, "0.1,16384,0.1,or_greater"), "set_sdfgi_max_distance", "get_sdfgi_max_distance"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "sdfgi_y_scale", PROPERTY_HINT_ENUM, "Disable,75%,50%"), "set_sdfgi_y_scale", "get_sdfgi_y_scale"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "sdfgi_y_scale", PROPERTY_HINT_ENUM, "50% (Compact),75% (Balanced),100% (Sparse)"), "set_sdfgi_y_scale", "get_sdfgi_y_scale"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "sdfgi_energy"), "set_sdfgi_energy", "get_sdfgi_energy"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "sdfgi_normal_bias"), "set_sdfgi_normal_bias", "get_sdfgi_normal_bias"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "sdfgi_probe_bias"), "set_sdfgi_probe_bias", "get_sdfgi_probe_bias"); @@ -1511,9 +1511,9 @@ void Environment::_bind_methods() { BIND_ENUM_CONSTANT(GLOW_BLEND_MODE_REPLACE); BIND_ENUM_CONSTANT(GLOW_BLEND_MODE_MIX); - BIND_ENUM_CONSTANT(SDFGI_Y_SCALE_DISABLED); - BIND_ENUM_CONSTANT(SDFGI_Y_SCALE_75_PERCENT); BIND_ENUM_CONSTANT(SDFGI_Y_SCALE_50_PERCENT); + BIND_ENUM_CONSTANT(SDFGI_Y_SCALE_75_PERCENT); + BIND_ENUM_CONSTANT(SDFGI_Y_SCALE_100_PERCENT); } Environment::Environment() { diff --git a/scene/resources/environment.h b/scene/resources/environment.h index b04723a221..dd1e664ca6 100644 --- a/scene/resources/environment.h +++ b/scene/resources/environment.h @@ -71,9 +71,9 @@ public: }; enum SDFGIYScale { - SDFGI_Y_SCALE_DISABLED, - SDFGI_Y_SCALE_75_PERCENT, SDFGI_Y_SCALE_50_PERCENT, + SDFGI_Y_SCALE_75_PERCENT, + SDFGI_Y_SCALE_100_PERCENT, }; enum GlowBlendMode { @@ -147,12 +147,12 @@ private: // SDFGI bool sdfgi_enabled = false; - int sdfgi_cascades = 6; + int sdfgi_cascades = 4; float sdfgi_min_cell_size = 0.2; - SDFGIYScale sdfgi_y_scale = SDFGI_Y_SCALE_DISABLED; + SDFGIYScale sdfgi_y_scale = SDFGI_Y_SCALE_75_PERCENT; bool sdfgi_use_occlusion = false; - float sdfgi_bounce_feedback = 0.0; - bool sdfgi_read_sky_light = false; + float sdfgi_bounce_feedback = 0.5; + bool sdfgi_read_sky_light = true; float sdfgi_energy = 1.0; float sdfgi_normal_bias = 1.1; float sdfgi_probe_bias = 1.1; diff --git a/servers/SCsub b/servers/SCsub index 76c11724d3..2cd4741d56 100644 --- a/servers/SCsub +++ b/servers/SCsub @@ -12,6 +12,7 @@ SConscript("physics_2d/SCsub") SConscript("rendering/SCsub") SConscript("audio/SCsub") SConscript("text/SCsub") +SConscript("debugger/SCsub") lib = env.add_library("servers", env.servers_sources) diff --git a/servers/debugger/SCsub b/servers/debugger/SCsub new file mode 100644 index 0000000000..86681f9c74 --- /dev/null +++ b/servers/debugger/SCsub @@ -0,0 +1,5 @@ +#!/usr/bin/env python + +Import("env") + +env.add_source_files(env.servers_sources, "*.cpp") diff --git a/servers/debugger/servers_debugger.cpp b/servers/debugger/servers_debugger.cpp new file mode 100644 index 0000000000..d1391937d9 --- /dev/null +++ b/servers/debugger/servers_debugger.cpp @@ -0,0 +1,463 @@ +/*************************************************************************/ +/* servers_debugger.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2022 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 "servers_debugger.h" + +#include "core/config/project_settings.h" +#include "core/debugger/engine_debugger.h" +#include "core/debugger/engine_profiler.h" +#include "core/io/marshalls.h" +#include "servers/display_server.h" + +#define CHECK_SIZE(arr, expected, what) ERR_FAIL_COND_V_MSG((uint32_t)arr.size() < (uint32_t)(expected), false, String("Malformed ") + what + " message from script debugger, message too short. Expected size: " + itos(expected) + ", actual size: " + itos(arr.size())) +#define CHECK_END(arr, expected, what) ERR_FAIL_COND_V_MSG((uint32_t)arr.size() > (uint32_t)expected, false, String("Malformed ") + what + " message from script debugger, message too long. Expected size: " + itos(expected) + ", actual size: " + itos(arr.size())) + +Array ServersDebugger::ResourceUsage::serialize() { + infos.sort(); + + Array arr; + arr.push_back(infos.size() * 4); + for (const ResourceInfo &E : infos) { + arr.push_back(E.path); + arr.push_back(E.format); + arr.push_back(E.type); + arr.push_back(E.vram); + } + return arr; +} + +bool ServersDebugger::ResourceUsage::deserialize(const Array &p_arr) { + CHECK_SIZE(p_arr, 1, "ResourceUsage"); + uint32_t size = p_arr[0]; + CHECK_SIZE(p_arr, size, "ResourceUsage"); + int idx = 1; + for (uint32_t i = 0; i < size / 4; i++) { + ResourceInfo info; + info.path = p_arr[idx]; + info.format = p_arr[idx + 1]; + info.type = p_arr[idx + 2]; + info.vram = p_arr[idx + 3]; + infos.push_back(info); + } + CHECK_END(p_arr, idx, "ResourceUsage"); + return true; +} + +Array ServersDebugger::ScriptFunctionSignature::serialize() { + Array arr; + arr.push_back(name); + arr.push_back(id); + return arr; +} + +bool ServersDebugger::ScriptFunctionSignature::deserialize(const Array &p_arr) { + CHECK_SIZE(p_arr, 2, "ScriptFunctionSignature"); + name = p_arr[0]; + id = p_arr[1]; + CHECK_END(p_arr, 2, "ScriptFunctionSignature"); + return true; +} + +Array ServersDebugger::ServersProfilerFrame::serialize() { + Array arr; + arr.push_back(frame_number); + arr.push_back(frame_time); + arr.push_back(idle_time); + arr.push_back(physics_time); + arr.push_back(physics_frame_time); + arr.push_back(script_time); + + arr.push_back(servers.size()); + for (int i = 0; i < servers.size(); i++) { + ServerInfo &s = servers[i]; + arr.push_back(s.name); + arr.push_back(s.functions.size() * 2); + for (int j = 0; j < s.functions.size(); j++) { + ServerFunctionInfo &f = s.functions[j]; + arr.push_back(f.name); + arr.push_back(f.time); + } + } + + arr.push_back(script_functions.size() * 4); + for (int i = 0; i < script_functions.size(); i++) { + arr.push_back(script_functions[i].sig_id); + arr.push_back(script_functions[i].call_count); + arr.push_back(script_functions[i].self_time); + arr.push_back(script_functions[i].total_time); + } + return arr; +} + +bool ServersDebugger::ServersProfilerFrame::deserialize(const Array &p_arr) { + CHECK_SIZE(p_arr, 7, "ServersProfilerFrame"); + frame_number = p_arr[0]; + frame_time = p_arr[1]; + idle_time = p_arr[2]; + physics_time = p_arr[3]; + physics_frame_time = p_arr[4]; + script_time = p_arr[5]; + int servers_size = p_arr[6]; + int idx = 7; + while (servers_size) { + CHECK_SIZE(p_arr, idx + 2, "ServersProfilerFrame"); + servers_size--; + ServerInfo si; + si.name = p_arr[idx]; + int sub_data_size = p_arr[idx + 1]; + idx += 2; + CHECK_SIZE(p_arr, idx + sub_data_size, "ServersProfilerFrame"); + for (int j = 0; j < sub_data_size / 2; j++) { + ServerFunctionInfo sf; + sf.name = p_arr[idx]; + sf.time = p_arr[idx + 1]; + idx += 2; + si.functions.push_back(sf); + } + servers.push_back(si); + } + CHECK_SIZE(p_arr, idx + 1, "ServersProfilerFrame"); + int func_size = p_arr[idx]; + idx += 1; + CHECK_SIZE(p_arr, idx + func_size, "ServersProfilerFrame"); + for (int i = 0; i < func_size / 4; i++) { + ScriptFunctionInfo fi; + fi.sig_id = p_arr[idx]; + fi.call_count = p_arr[idx + 1]; + fi.self_time = p_arr[idx + 2]; + fi.total_time = p_arr[idx + 3]; + script_functions.push_back(fi); + idx += 4; + } + CHECK_END(p_arr, idx, "ServersProfilerFrame"); + return true; +} + +Array ServersDebugger::VisualProfilerFrame::serialize() { + Array arr; + arr.push_back(frame_number); + arr.push_back(areas.size() * 3); + for (int i = 0; i < areas.size(); i++) { + arr.push_back(areas[i].name); + arr.push_back(areas[i].cpu_msec); + arr.push_back(areas[i].gpu_msec); + } + return arr; +} + +bool ServersDebugger::VisualProfilerFrame::deserialize(const Array &p_arr) { + CHECK_SIZE(p_arr, 2, "VisualProfilerFrame"); + frame_number = p_arr[0]; + int size = p_arr[1]; + CHECK_SIZE(p_arr, size, "VisualProfilerFrame"); + int idx = 2; + areas.resize(size / 3); + RS::FrameProfileArea *w = areas.ptrw(); + for (int i = 0; i < size / 3; i++) { + w[i].name = p_arr[idx]; + w[i].cpu_msec = p_arr[idx + 1]; + w[i].gpu_msec = p_arr[idx + 2]; + idx += 3; + } + CHECK_END(p_arr, idx, "VisualProfilerFrame"); + return true; +} +class ServersDebugger::ScriptsProfiler : public EngineProfiler { + typedef ServersDebugger::ScriptFunctionSignature FunctionSignature; + typedef ServersDebugger::ScriptFunctionInfo FunctionInfo; + struct ProfileInfoSort { + bool operator()(ScriptLanguage::ProfilingInfo *A, ScriptLanguage::ProfilingInfo *B) const { + return A->total_time < B->total_time; + } + }; + Vector<ScriptLanguage::ProfilingInfo> info; + Vector<ScriptLanguage::ProfilingInfo *> ptrs; + Map<StringName, int> sig_map; + int max_frame_functions = 16; + +public: + void toggle(bool p_enable, const Array &p_opts) { + if (p_enable) { + sig_map.clear(); + for (int i = 0; i < ScriptServer::get_language_count(); i++) { + ScriptServer::get_language(i)->profiling_start(); + } + if (p_opts.size() == 1 && p_opts[0].get_type() == Variant::INT) { + max_frame_functions = MAX(0, int(p_opts[0])); + } + } else { + for (int i = 0; i < ScriptServer::get_language_count(); i++) { + ScriptServer::get_language(i)->profiling_stop(); + } + } + } + + void write_frame_data(Vector<FunctionInfo> &r_funcs, uint64_t &r_total, bool p_accumulated) { + int ofs = 0; + for (int i = 0; i < ScriptServer::get_language_count(); i++) { + if (p_accumulated) { + ofs += ScriptServer::get_language(i)->profiling_get_accumulated_data(&info.write[ofs], info.size() - ofs); + } else { + ofs += ScriptServer::get_language(i)->profiling_get_frame_data(&info.write[ofs], info.size() - ofs); + } + } + + for (int i = 0; i < ofs; i++) { + ptrs.write[i] = &info.write[i]; + } + + SortArray<ScriptLanguage::ProfilingInfo *, ProfileInfoSort> sa; + sa.sort(ptrs.ptrw(), ofs); + + int to_send = MIN(ofs, max_frame_functions); + + // Check signatures first, and compute total time. + r_total = 0; + for (int i = 0; i < to_send; i++) { + if (!sig_map.has(ptrs[i]->signature)) { + int idx = sig_map.size(); + FunctionSignature sig; + sig.name = ptrs[i]->signature; + sig.id = idx; + EngineDebugger::get_singleton()->send_message("servers:function_signature", sig.serialize()); + sig_map[ptrs[i]->signature] = idx; + } + r_total += ptrs[i]->self_time; + } + + // Send frame, script time, functions information then + r_funcs.resize(to_send); + + FunctionInfo *w = r_funcs.ptrw(); + for (int i = 0; i < to_send; i++) { + if (sig_map.has(ptrs[i]->signature)) { + w[i].sig_id = sig_map[ptrs[i]->signature]; + } + w[i].call_count = ptrs[i]->call_count; + w[i].total_time = ptrs[i]->total_time / 1000000.0; + w[i].self_time = ptrs[i]->self_time / 1000000.0; + } + } + + ScriptsProfiler() { + info.resize(GLOBAL_GET("debug/settings/profiler/max_functions")); + ptrs.resize(info.size()); + } +}; + +class ServersDebugger::ServersProfiler : public EngineProfiler { + bool skip_profile_frame = false; + typedef ServersDebugger::ServerInfo ServerInfo; + typedef ServersDebugger::ServerFunctionInfo ServerFunctionInfo; + + Map<StringName, ServerInfo> server_data; + ScriptsProfiler scripts_profiler; + + double frame_time = 0; + double idle_time = 0; + double physics_time = 0; + double physics_frame_time = 0; + + void _send_frame_data(bool p_final) { + ServersDebugger::ServersProfilerFrame frame; + frame.frame_number = Engine::get_singleton()->get_process_frames(); + frame.frame_time = frame_time; + frame.idle_time = idle_time; + frame.physics_time = physics_time; + frame.physics_frame_time = physics_frame_time; + Map<StringName, ServerInfo>::Element *E = server_data.front(); + while (E) { + if (!p_final) { + frame.servers.push_back(E->get()); + } + E->get().functions.clear(); + E = E->next(); + } + uint64_t time = 0; + scripts_profiler.write_frame_data(frame.script_functions, time, p_final); + frame.script_time = USEC_TO_SEC(time); + if (skip_profile_frame) { + skip_profile_frame = false; + return; + } + if (p_final) { + EngineDebugger::get_singleton()->send_message("servers:profile_total", frame.serialize()); + } else { + EngineDebugger::get_singleton()->send_message("servers:profile_frame", frame.serialize()); + } + } + +public: + void toggle(bool p_enable, const Array &p_opts) { + skip_profile_frame = false; + if (p_enable) { + server_data.clear(); // Clear old profiling data. + } else { + _send_frame_data(true); // Send final frame. + } + scripts_profiler.toggle(p_enable, p_opts); + } + + void add(const Array &p_data) { + String name = p_data[0]; + if (!server_data.has(name)) { + ServerInfo info; + info.name = name; + server_data[name] = info; + } + ServerInfo &srv = server_data[name]; + + ServerFunctionInfo fi; + fi.name = p_data[1]; + fi.time = p_data[2]; + srv.functions.push_back(fi); + } + + void tick(double p_frame_time, double p_idle_time, double p_physics_time, double p_physics_frame_time) { + frame_time = p_frame_time; + idle_time = p_idle_time; + physics_time = p_physics_time; + physics_frame_time = p_physics_frame_time; + _send_frame_data(false); + } + + void skip_frame() { + skip_profile_frame = true; + } +}; + +class ServersDebugger::VisualProfiler : public EngineProfiler { + typedef ServersDebugger::ServerInfo ServerInfo; + typedef ServersDebugger::ServerFunctionInfo ServerFunctionInfo; + + Map<StringName, ServerInfo> server_data; + +public: + void toggle(bool p_enable, const Array &p_opts) { + RS::get_singleton()->set_frame_profiling_enabled(p_enable); + } + + void add(const Array &p_data) {} + + void tick(double p_frame_time, double p_idle_time, double p_physics_time, double p_physics_frame_time) { + Vector<RS::FrameProfileArea> profile_areas = RS::get_singleton()->get_frame_profile(); + ServersDebugger::VisualProfilerFrame frame; + if (!profile_areas.size()) { + return; + } + + frame.frame_number = RS::get_singleton()->get_frame_profile_frame(); + frame.areas.append_array(profile_areas); + EngineDebugger::get_singleton()->send_message("visual:profile_frame", frame.serialize()); + } +}; + +ServersDebugger *ServersDebugger::singleton = nullptr; + +void ServersDebugger::initialize() { + if (EngineDebugger::is_active()) { + memnew(ServersDebugger); + } +} + +void ServersDebugger::deinitialize() { + if (singleton) { + memdelete(singleton); + } +} + +Error ServersDebugger::_capture(void *p_user, const String &p_cmd, const Array &p_data, bool &r_captured) { + ERR_FAIL_COND_V(!singleton, ERR_BUG); + r_captured = true; + if (p_cmd == "memory") { + singleton->_send_resource_usage(); + } else if (p_cmd == "draw") { // Forced redraw. + // For camera override to stay live when the game is paused from the editor. + double delta = 0.0; + if (singleton->last_draw_time) { + delta = (OS::get_singleton()->get_ticks_usec() - singleton->last_draw_time) / 1000000.0; + } + singleton->last_draw_time = OS::get_singleton()->get_ticks_usec(); + RenderingServer::get_singleton()->sync(); + if (RenderingServer::get_singleton()->has_changed()) { + RenderingServer::get_singleton()->draw(true, delta); + } + } else if (p_cmd == "foreground") { + singleton->last_draw_time = 0.0; + DisplayServer::get_singleton()->window_move_to_foreground(); + singleton->servers_profiler->skip_frame(); + } else { + r_captured = false; + } + return OK; +} + +void ServersDebugger::_send_resource_usage() { + ServersDebugger::ResourceUsage usage; + + List<RS::TextureInfo> tinfo; + RS::get_singleton()->texture_debug_usage(&tinfo); + + for (const RS::TextureInfo &E : tinfo) { + ServersDebugger::ResourceInfo info; + info.path = E.path; + info.vram = E.bytes; + info.id = E.texture; + info.type = "Texture"; + if (E.depth == 0) { + info.format = itos(E.width) + "x" + itos(E.height) + " " + Image::get_format_name(E.format); + } else { + info.format = itos(E.width) + "x" + itos(E.height) + "x" + itos(E.depth) + " " + Image::get_format_name(E.format); + } + usage.infos.push_back(info); + } + + EngineDebugger::get_singleton()->send_message("servers:memory_usage", usage.serialize()); +} + +ServersDebugger::ServersDebugger() { + singleton = this; + + // Generic servers profiler (audio/physics/...) + servers_profiler.instantiate(); + servers_profiler->bind("servers"); + + // Visual Profiler (cpu/gpu times) + visual_profiler.instantiate(); + visual_profiler->bind("visual"); + + EngineDebugger::Capture servers_cap(nullptr, &_capture); + EngineDebugger::register_message_capture("servers", servers_cap); +} + +ServersDebugger::~ServersDebugger() { + EngineDebugger::unregister_message_capture("servers"); + singleton = nullptr; +} diff --git a/servers/debugger/servers_debugger.h b/servers/debugger/servers_debugger.h new file mode 100644 index 0000000000..d1c55dc690 --- /dev/null +++ b/servers/debugger/servers_debugger.h @@ -0,0 +1,132 @@ +/*************************************************************************/ +/* servers_debugger.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2022 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 SERVER_DEBUGGER_H +#define SERVER_DEBUGGER_H + +#include "core/debugger/debugger_marshalls.h" + +#include "servers/rendering_server.h" + +class ServersDebugger { +public: + // Memory usage + struct ResourceInfo { + String path; + String format; + String type; + RID id; + int vram = 0; + bool operator<(const ResourceInfo &p_img) const { return vram == p_img.vram ? id < p_img.id : vram > p_img.vram; } + }; + + struct ResourceUsage { + List<ResourceInfo> infos; + + Array serialize(); + bool deserialize(const Array &p_arr); + }; + + // Script Profiler + struct ScriptFunctionSignature { + StringName name; + int id = -1; + + Array serialize(); + bool deserialize(const Array &p_arr); + }; + + struct ScriptFunctionInfo { + StringName name; + int sig_id = -1; + int call_count = 0; + double self_time = 0; + double total_time = 0; + }; + + // Servers profiler + struct ServerFunctionInfo { + StringName name; + double time = 0; + }; + + struct ServerInfo { + StringName name; + List<ServerFunctionInfo> functions; + }; + + struct ServersProfilerFrame { + int frame_number = 0; + double frame_time = 0; + double idle_time = 0; + double physics_time = 0; + double physics_frame_time = 0; + double script_time = 0; + List<ServerInfo> servers; + Vector<ScriptFunctionInfo> script_functions; + + Array serialize(); + bool deserialize(const Array &p_arr); + }; + + // Visual Profiler + struct VisualProfilerFrame { + uint64_t frame_number = 0; + Vector<RS::FrameProfileArea> areas; + + Array serialize(); + bool deserialize(const Array &p_arr); + }; + +private: + class ScriptsProfiler; + class ServersProfiler; + class VisualProfiler; + + double last_draw_time = 0.0; + Ref<ServersProfiler> servers_profiler; + Ref<VisualProfiler> visual_profiler; + + static ServersDebugger *singleton; + + static Error _capture(void *p_user, const String &p_cmd, const Array &p_data, bool &r_captured); + + void _send_resource_usage(); + + ServersDebugger(); + +public: + static void initialize(); + static void deinitialize(); + + ~ServersDebugger(); +}; + +#endif // SERVERS_DEBUGGER_H diff --git a/servers/register_server_types.cpp b/servers/register_server_types.cpp index 3726bcde35..f405dea770 100644 --- a/servers/register_server_types.cpp +++ b/servers/register_server_types.cpp @@ -56,6 +56,7 @@ #include "camera/camera_feed.h" #include "camera_server.h" #include "core/extension/native_extension_manager.h" +#include "debugger/servers_debugger.h" #include "display_server.h" #include "navigation_server_2d.h" #include "navigation_server_3d.h" @@ -223,6 +224,8 @@ void register_server_types() { GDREGISTER_CLASS(PhysicsTestMotionParameters3D); GDREGISTER_CLASS(PhysicsTestMotionResult3D); + ServersDebugger::initialize(); + // Physics 2D GLOBAL_DEF(PhysicsServer2DManager::setting_property_name, "DEFAULT"); ProjectSettings::get_singleton()->set_custom_property_info(PhysicsServer2DManager::setting_property_name, PropertyInfo(Variant::STRING, PhysicsServer2DManager::setting_property_name, PROPERTY_HINT_ENUM, "DEFAULT")); @@ -241,6 +244,8 @@ void register_server_types() { } void unregister_server_types() { + ServersDebugger::deinitialize(); + NativeExtensionManager::get_singleton()->deinitialize_extensions(NativeExtension::INITIALIZATION_LEVEL_SERVERS); memdelete(shader_types); diff --git a/servers/rendering/rasterizer_dummy.h b/servers/rendering/rasterizer_dummy.h index 7032f3fb03..7d5a596c50 100644 --- a/servers/rendering/rasterizer_dummy.h +++ b/servers/rendering/rasterizer_dummy.h @@ -72,11 +72,11 @@ public: /* SHADOW ATLAS API */ RID shadow_atlas_create() override { return RID(); } - void shadow_atlas_set_size(RID p_atlas, int p_size, bool p_16_bits = false) override {} + void shadow_atlas_set_size(RID p_atlas, int p_size, bool p_16_bits = true) override {} void shadow_atlas_set_quadrant_subdivision(RID p_atlas, int p_quadrant, int p_subdivision) override {} bool shadow_atlas_update_light(RID p_atlas, RID p_light_intance, float p_coverage, uint64_t p_light_version) override { return false; } - void directional_shadow_atlas_set_size(int p_size, bool p_16_bits = false) override {} + void directional_shadow_atlas_set_size(int p_size, bool p_16_bits = true) override {} int get_directional_light_shadow_size(RID p_light_intance) override { return 0; } void set_directional_shadow_count(int p_count) override {} 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 87301a9d3a..d113fcd4f0 100644 --- a/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp +++ b/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp @@ -969,10 +969,11 @@ void RenderForwardClustered::_fill_render_list(RenderListType p_render_list, con if (inst->fade_near || inst->fade_far) { float fade_dist = inst->transform.origin.distance_to(p_render_data->cam_transform.origin); + // Use `smoothstep()` to make opacity changes more gradual and less noticeable to the player. if (inst->fade_far && fade_dist > inst->fade_far_begin) { - fade_alpha = MAX(0.0, 1.0 - (fade_dist - inst->fade_far_begin) / (inst->fade_far_end - inst->fade_far_begin)); + fade_alpha = Math::smoothstep(0.0f, 1.0f, 1.0f - (fade_dist - inst->fade_far_begin) / (inst->fade_far_end - inst->fade_far_begin)); } else if (inst->fade_near && fade_dist < inst->fade_near_end) { - fade_alpha = MAX(0.0, (fade_dist - inst->fade_near_begin) / (inst->fade_near_end - inst->fade_near_begin)); + fade_alpha = Math::smoothstep(0.0f, 1.0f, (fade_dist - inst->fade_near_begin) / (inst->fade_near_end - inst->fade_near_begin)); } } @@ -1390,7 +1391,7 @@ void RenderForwardClustered::_render_scene(RenderDataRD *p_render_data, const Co projection = correction * p_render_data->cam_projection; } - sky.setup(env, p_render_data->render_buffers, projection, p_render_data->cam_transform, screen_size, this); + sky.setup(env, p_render_data->render_buffers, *p_render_data->lights, projection, p_render_data->cam_transform, screen_size, this); RID sky_rid = env->sky; if (sky_rid.is_valid()) { 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 778d7baa5d..a623af7533 100644 --- a/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp +++ b/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp @@ -633,7 +633,7 @@ void RenderForwardMobile::_render_scene(RenderDataRD *p_render_data, const Color projection = correction * p_render_data->cam_projection; } - sky.setup(env, p_render_data->render_buffers, projection, p_render_data->cam_transform, screen_size, this); + sky.setup(env, p_render_data->render_buffers, *p_render_data->lights, projection, p_render_data->cam_transform, screen_size, this); RID sky_rid = env->sky; if (sky_rid.is_valid()) { diff --git a/servers/rendering/renderer_rd/renderer_scene_environment_rd.h b/servers/rendering/renderer_rd/renderer_scene_environment_rd.h index ed26fd467b..4e170b8cfb 100644 --- a/servers/rendering/renderer_rd/renderer_scene_environment_rd.h +++ b/servers/rendering/renderer_rd/renderer_scene_environment_rd.h @@ -135,15 +135,15 @@ public: /// SDFGI bool sdfgi_enabled = false; - int sdfgi_cascades = 6; + int sdfgi_cascades = 4; float sdfgi_min_cell_size = 0.2; bool sdfgi_use_occlusion = false; - float sdfgi_bounce_feedback = 0.0; - bool sdfgi_read_sky_light = false; + float sdfgi_bounce_feedback = 0.5; + bool sdfgi_read_sky_light = true; float sdfgi_energy = 1.0; float sdfgi_normal_bias = 1.1; float sdfgi_probe_bias = 1.1; - RS::EnvironmentSDFGIYScale sdfgi_y_scale = RS::ENV_SDFGI_Y_SCALE_DISABLED; + RS::EnvironmentSDFGIYScale sdfgi_y_scale = RS::ENV_SDFGI_Y_SCALE_75_PERCENT; /// Adjustments diff --git a/servers/rendering/renderer_rd/renderer_scene_gi_rd.cpp b/servers/rendering/renderer_rd/renderer_scene_gi_rd.cpp index 3069b1c379..cb07c75db4 100644 --- a/servers/rendering/renderer_rd/renderer_scene_gi_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_scene_gi_rd.cpp @@ -46,7 +46,7 @@ void RendererSceneGIRD::SDFGI::create(RendererSceneEnvironmentRD *p_env, const V min_cell_size = p_env->sdfgi_min_cell_size; uses_occlusion = p_env->sdfgi_use_occlusion; y_scale_mode = p_env->sdfgi_y_scale; - static const float y_scale[3] = { 1.0, 1.5, 2.0 }; + static const float y_scale[3] = { 2.0, 1.5, 1.0 }; y_mult = y_scale[y_scale_mode]; cascades.resize(num_cascades); probe_axis_count = SDFGI::PROBE_DIVISOR + 1; diff --git a/servers/rendering/renderer_rd/renderer_scene_gi_rd.h b/servers/rendering/renderer_rd/renderer_scene_gi_rd.h index 5e55262798..25f0dca3b7 100644 --- a/servers/rendering/renderer_rd/renderer_scene_gi_rd.h +++ b/servers/rendering/renderer_rd/renderer_scene_gi_rd.h @@ -392,7 +392,7 @@ public: return voxel_gi->texture; }; - RS::VoxelGIQuality voxel_gi_quality = RS::VOXEL_GI_QUALITY_HIGH; + RS::VoxelGIQuality voxel_gi_quality = RS::VOXEL_GI_QUALITY_LOW; /* SDFGI */ @@ -504,12 +504,12 @@ public: RID cascades_ubo; bool uses_occlusion = false; - float bounce_feedback = 0.0; - bool reads_sky = false; + float bounce_feedback = 0.5; + bool reads_sky = true; float energy = 1.0; float normal_bias = 1.1; float probe_bias = 1.1; - RS::EnvironmentSDFGIYScale y_scale_mode = RS::ENV_SDFGI_Y_SCALE_DISABLED; + RS::EnvironmentSDFGIYScale y_scale_mode = RS::ENV_SDFGI_Y_SCALE_75_PERCENT; float y_mult = 1.0; @@ -536,7 +536,7 @@ public: }; RS::EnvironmentSDFGIRayCount sdfgi_ray_count = RS::ENV_SDFGI_RAY_COUNT_16; - RS::EnvironmentSDFGIFramesToConverge sdfgi_frames_to_converge = RS::ENV_SDFGI_CONVERGE_IN_10_FRAMES; + RS::EnvironmentSDFGIFramesToConverge sdfgi_frames_to_converge = RS::ENV_SDFGI_CONVERGE_IN_30_FRAMES; RS::EnvironmentSDFGIFramesToUpdateLight sdfgi_frames_to_update_light = RS::ENV_SDFGI_UPDATE_LIGHT_IN_4_FRAMES; float sdfgi_solid_cell_ratio = 0.25; diff --git a/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp b/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp index 43a1812f89..2d34d2a2a0 100644 --- a/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp @@ -3263,7 +3263,6 @@ void RendererSceneRenderRD::_setup_lights(const PagedArray<RID> &p_lights, const r_directional_light_count = 0; r_positional_light_count = 0; - sky.sky_scene_state.ubo.directional_light_count = 0; Plane camera_plane(-p_camera_transform.basis.get_axis(Vector3::AXIS_Z).normalized(), p_camera_transform.origin); @@ -3284,43 +3283,7 @@ void RendererSceneRenderRD::_setup_lights(const PagedArray<RID> &p_lights, const RS::LightType type = storage->light_get_type(base); switch (type) { case RS::LIGHT_DIRECTIONAL: { - // Copy to SkyDirectionalLightData - if (r_directional_light_count < sky.sky_scene_state.max_directional_lights) { - RendererSceneSkyRD::SkyDirectionalLightData &sky_light_data = sky.sky_scene_state.directional_lights[r_directional_light_count]; - Transform3D light_transform = li->transform; - Vector3 world_direction = light_transform.basis.xform(Vector3(0, 0, 1)).normalized(); - - sky_light_data.direction[0] = world_direction.x; - sky_light_data.direction[1] = world_direction.y; - sky_light_data.direction[2] = -world_direction.z; - - float sign = storage->light_is_negative(base) ? -1 : 1; - sky_light_data.energy = sign * storage->light_get_param(base, RS::LIGHT_PARAM_ENERGY); - - Color linear_col = storage->light_get_color(base).to_linear(); - sky_light_data.color[0] = linear_col.r; - sky_light_data.color[1] = linear_col.g; - sky_light_data.color[2] = linear_col.b; - - sky_light_data.enabled = true; - - float angular_diameter = storage->light_get_param(base, RS::LIGHT_PARAM_SIZE); - if (angular_diameter > 0.0) { - // I know tan(0) is 0, but let's not risk it with numerical precision. - // technically this will keep expanding until reaching the sun, but all we care - // is expand until we reach the radius of the near plane (there can't be more occluders than that) - angular_diameter = Math::tan(Math::deg2rad(angular_diameter)); - if (storage->light_has_shadow(base)) { - r_directional_light_soft_shadows = true; - } - } else { - angular_diameter = 0.0; - } - sky_light_data.size = angular_diameter; - sky.sky_scene_state.ubo.directional_light_count++; - } - - if (r_directional_light_count >= cluster.max_directional_lights || storage->light_directional_is_sky_only(base)) { + if (r_directional_light_count >= cluster.max_directional_lights) { continue; } @@ -3397,6 +3360,9 @@ void RendererSceneRenderRD::_setup_lights(const PagedArray<RID> &p_lights, const // technically this will keep expanding until reaching the sun, but all we care // is expand until we reach the radius of the near plane (there can't be more occluders than that) angular_diameter = Math::tan(Math::deg2rad(angular_diameter)); + if (storage->light_has_shadow(base)) { + r_directional_light_soft_shadows = true; + } } else { angular_diameter = 0.0; } diff --git a/servers/rendering/renderer_rd/renderer_scene_render_rd.h b/servers/rendering/renderer_rd/renderer_scene_render_rd.h index 899d2d763d..09c828ba37 100644 --- a/servers/rendering/renderer_rd/renderer_scene_render_rd.h +++ b/servers/rendering/renderer_rd/renderer_scene_render_rd.h @@ -293,7 +293,7 @@ private: uint32_t smallest_subdiv = 0; int size = 0; - bool use_16_bits = false; + bool use_16_bits = true; RID depth; RID fb; //for copying @@ -333,7 +333,7 @@ private: int light_count = 0; int size = 0; - bool use_16_bits = false; + bool use_16_bits = true; int current_light = 0; } directional_shadow; @@ -981,7 +981,7 @@ public: /* SHADOW ATLAS API */ 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_size(RID p_atlas, int p_size, bool p_16_bits = true) 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_instance, float p_coverage, uint64_t p_light_version) override; _FORCE_INLINE_ bool shadow_atlas_owns_light_instance(RID p_atlas, RID p_light_intance) { @@ -1002,7 +1002,7 @@ public: return Size2(atlas->size, atlas->size); } - virtual void directional_shadow_atlas_set_size(int p_size, bool p_16_bits = false) override; + virtual void directional_shadow_atlas_set_size(int p_size, bool p_16_bits = true) override; virtual int get_directional_light_shadow_size(RID p_light_intance) override; virtual void set_directional_shadow_count(int p_count) override; diff --git a/servers/rendering/renderer_rd/renderer_scene_sky_rd.cpp b/servers/rendering/renderer_rd/renderer_scene_sky_rd.cpp index f6f39230f8..fb36190c3e 100644 --- a/servers/rendering/renderer_rd/renderer_scene_sky_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_scene_sky_rd.cpp @@ -1040,8 +1040,8 @@ RendererSceneSkyRD::~RendererSceneSkyRD() { 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) { - ERR_FAIL_COND(!p_env); // I guess without an environment we also can't have a sky... +void RendererSceneSkyRD::setup(RendererSceneEnvironmentRD *p_env, RID p_render_buffers, const PagedArray<RID> &p_lights, const CameraMatrix &p_projection, const Transform3D &p_transform, const Size2i p_screen_size, RendererSceneRenderRD *p_scene_render) { + ERR_FAIL_COND(!p_env); SkyMaterialData *material = nullptr; Sky *sky = get_sky(p_env->sky); @@ -1122,15 +1122,67 @@ void RendererSceneSkyRD::setup(RendererSceneEnvironmentRD *p_env, RID p_render_b } if (shader_data->uses_light) { + sky_scene_state.ubo.directional_light_count = 0; + // Run through the list of lights in the scene and pick out the Directional Lights. + // This can't be done in RenderSceneRenderRD::_setup lights because that needs to be called + // after the depth prepass, but this runs before the depth prepass + for (int i = 0; i < (int)p_lights.size(); i++) { + RendererSceneRenderRD::LightInstance *li = p_scene_render->light_instance_owner.get_or_null(p_lights[i]); + if (!li) { + continue; + } + RID base = li->light; + + ERR_CONTINUE(base.is_null()); + + RS::LightType type = storage->light_get_type(base); + if (type == RS::LIGHT_DIRECTIONAL) { + SkyDirectionalLightData &sky_light_data = sky_scene_state.directional_lights[sky_scene_state.ubo.directional_light_count]; + Transform3D light_transform = li->transform; + Vector3 world_direction = light_transform.basis.xform(Vector3(0, 0, 1)).normalized(); + + sky_light_data.direction[0] = world_direction.x; + sky_light_data.direction[1] = world_direction.y; + sky_light_data.direction[2] = -world_direction.z; + + float sign = storage->light_is_negative(base) ? -1 : 1; + sky_light_data.energy = sign * storage->light_get_param(base, RS::LIGHT_PARAM_ENERGY); + + Color linear_col = storage->light_get_color(base).to_linear(); + sky_light_data.color[0] = linear_col.r; + sky_light_data.color[1] = linear_col.g; + sky_light_data.color[2] = linear_col.b; + + sky_light_data.enabled = true; + + float angular_diameter = storage->light_get_param(base, RS::LIGHT_PARAM_SIZE); + if (angular_diameter > 0.0) { + // I know tan(0) is 0, but let's not risk it with numerical precision. + // technically this will keep expanding until reaching the sun, but all we care + // is expand until we reach the radius of the near plane (there can't be more occluders than that) + angular_diameter = Math::tan(Math::deg2rad(angular_diameter)); + } else { + angular_diameter = 0.0; + } + sky_light_data.size = angular_diameter; + sky_scene_state.ubo.directional_light_count++; + if (sky_scene_state.ubo.directional_light_count >= sky_scene_state.max_directional_lights) { + break; + } + } + } // Check whether the directional_light_buffer changes - bool light_data_dirty = false; + bool light_data_dirty = true; + // Light buffer is dirty if we have fewer or more lights + // If we have fewer lights, make sure that old lights are disabled if (sky_scene_state.ubo.directional_light_count != sky_scene_state.last_frame_directional_light_count) { light_data_dirty = true; for (uint32_t i = sky_scene_state.ubo.directional_light_count; i < sky_scene_state.max_directional_lights; i++) { sky_scene_state.directional_lights[i].enabled = false; } } + if (!light_data_dirty) { for (uint32_t i = 0; i < sky_scene_state.ubo.directional_light_count; i++) { if (sky_scene_state.directional_lights[i].direction[0] != sky_scene_state.last_frame_directional_lights[i].direction[0] || diff --git a/servers/rendering/renderer_rd/renderer_scene_sky_rd.h b/servers/rendering/renderer_rd/renderer_scene_sky_rd.h index d81a415c2d..13d24e2508 100644 --- a/servers/rendering/renderer_rd/renderer_scene_sky_rd.h +++ b/servers/rendering/renderer_rd/renderer_scene_sky_rd.h @@ -292,7 +292,7 @@ public: void set_texture_format(RD::DataFormat p_texture_format); ~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 setup(RendererSceneEnvironmentRD *p_env, RID p_render_buffers, const PagedArray<RID> &p_lights, 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, float p_luminance_multiplier = 1.0); void draw(RendererSceneEnvironmentRD *p_env, bool p_can_continue_color, bool p_can_continue_depth, RID p_fb, uint32_t p_view_count, const CameraMatrix *p_projections, const Transform3D &p_transform, double p_time); // only called by clustered renderer void update_res_buffers(RendererSceneEnvironmentRD *p_env, uint32_t p_view_count, const CameraMatrix *p_projections, const Transform3D &p_transform, double p_time, float p_luminance_multiplier = 1.0); diff --git a/servers/rendering/renderer_scene.h b/servers/rendering/renderer_scene.h index 406d946e12..4c58fce1c9 100644 --- a/servers/rendering/renderer_scene.h +++ b/servers/rendering/renderer_scene.h @@ -105,7 +105,7 @@ public: virtual Variant instance_geometry_get_shader_parameter(RID p_instance, const StringName &p_parameter) const = 0; virtual Variant instance_geometry_get_shader_parameter_default_value(RID p_instance, const StringName &p_parameter) const = 0; - virtual void directional_shadow_atlas_set_size(int p_size, bool p_16_bits = false) = 0; + virtual void directional_shadow_atlas_set_size(int p_size, bool p_16_bits = true) = 0; /* SKY API */ @@ -187,7 +187,7 @@ public: virtual void directional_shadow_quality_set(RS::ShadowQuality p_quality) = 0; virtual RID shadow_atlas_create() = 0; - virtual void shadow_atlas_set_size(RID p_atlas, int p_size, bool p_use_16_bits = false) = 0; + virtual void shadow_atlas_set_size(RID p_atlas, int p_size, bool p_use_16_bits = true) = 0; virtual void shadow_atlas_set_quadrant_subdivision(RID p_atlas, int p_quadrant, int p_subdivision) = 0; /* Render Buffers */ diff --git a/servers/rendering/renderer_scene_render.h b/servers/rendering/renderer_scene_render.h index 3eb90ccc4d..cedf6575fd 100644 --- a/servers/rendering/renderer_scene_render.h +++ b/servers/rendering/renderer_scene_render.h @@ -80,11 +80,11 @@ public: /* SHADOW ATLAS API */ virtual RID shadow_atlas_create() = 0; - virtual void shadow_atlas_set_size(RID p_atlas, int p_size, bool p_16_bits = false) = 0; + virtual void shadow_atlas_set_size(RID p_atlas, int p_size, bool p_16_bits = true) = 0; virtual void shadow_atlas_set_quadrant_subdivision(RID p_atlas, int p_quadrant, int p_subdivision) = 0; virtual bool shadow_atlas_update_light(RID p_atlas, RID p_light_intance, float p_coverage, uint64_t p_light_version) = 0; - virtual void directional_shadow_atlas_set_size(int p_size, bool p_16_bits = false) = 0; + virtual void directional_shadow_atlas_set_size(int p_size, bool p_16_bits = true) = 0; virtual int get_directional_light_shadow_size(RID p_light_intance) = 0; virtual void set_directional_shadow_count(int p_count) = 0; diff --git a/servers/rendering/renderer_viewport.h b/servers/rendering/renderer_viewport.h index 7bc8f9961b..2245d9a216 100644 --- a/servers/rendering/renderer_viewport.h +++ b/servers/rendering/renderer_viewport.h @@ -91,7 +91,7 @@ public: RID shadow_atlas; int shadow_atlas_size; - bool shadow_atlas_16_bits = false; + bool shadow_atlas_16_bits = true; bool sdf_active; @@ -247,7 +247,7 @@ public: void viewport_set_global_canvas_transform(RID p_viewport, const Transform2D &p_transform); void viewport_set_canvas_stacking(RID p_viewport, RID p_canvas, int p_layer, int p_sublayer); - void viewport_set_shadow_atlas_size(RID p_viewport, int p_size, bool p_16_bits = false); + void viewport_set_shadow_atlas_size(RID p_viewport, int p_size, bool p_16_bits = true); void viewport_set_shadow_atlas_quadrant_subdivision(RID p_viewport, int p_quadrant, int p_subdiv); void viewport_set_msaa(RID p_viewport, RS::ViewportMSAA p_msaa); diff --git a/servers/rendering/shader_language.cpp b/servers/rendering/shader_language.cpp index ead196b7dd..91201b2028 100644 --- a/servers/rendering/shader_language.cpp +++ b/servers/rendering/shader_language.cpp @@ -7871,7 +7871,7 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct if (is_sampler_type(type)) { if (uniform_scope == ShaderNode::Uniform::SCOPE_INSTANCE) { - _set_error(vformat(RTR("Uniforms with '%s' qualifiers can't be of sampler type.", "instance"))); + _set_error(vformat(RTR("The '%s' qualifier is not supported for sampler types."), "SCOPE_INSTANCE")); return ERR_PARSE_ERROR; } uniform2.texture_order = texture_uniforms++; @@ -7887,7 +7887,7 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct } } else { if (uniform_scope == ShaderNode::Uniform::SCOPE_INSTANCE && (type == TYPE_MAT2 || type == TYPE_MAT3 || type == TYPE_MAT4)) { - _set_error(vformat(RTR("Uniforms with '%s' qualifier can't be of matrix type.", "instance"))); + _set_error(vformat(RTR("The '%s' qualifier is not supported for matrix types."), "SCOPE_INSTANCE")); return ERR_PARSE_ERROR; } uniform2.texture_order = -1; diff --git a/servers/rendering_server.cpp b/servers/rendering_server.cpp index ac181cb5eb..2037268134 100644 --- a/servers/rendering_server.cpp +++ b/servers/rendering_server.cpp @@ -2388,9 +2388,9 @@ void RenderingServer::_bind_methods() { BIND_ENUM_CONSTANT(ENV_SSIL_QUALITY_HIGH); BIND_ENUM_CONSTANT(ENV_SSIL_QUALITY_ULTRA); - 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_Y_SCALE_75_PERCENT); + BIND_ENUM_CONSTANT(ENV_SDFGI_Y_SCALE_100_PERCENT); BIND_ENUM_CONSTANT(ENV_SDFGI_RAY_COUNT_4); BIND_ENUM_CONSTANT(ENV_SDFGI_RAY_COUNT_8); @@ -2830,12 +2830,12 @@ RenderingServer::RenderingServer() { GLOBAL_DEF("rendering/shadows/directional_shadow/size", 4096); GLOBAL_DEF("rendering/shadows/directional_shadow/size.mobile", 2048); ProjectSettings::get_singleton()->set_custom_property_info("rendering/shadows/directional_shadow/size", PropertyInfo(Variant::INT, "rendering/shadows/directional_shadow/size", PROPERTY_HINT_RANGE, "256,16384")); - GLOBAL_DEF("rendering/shadows/directional_shadow/soft_shadow_quality", 3); + GLOBAL_DEF("rendering/shadows/directional_shadow/soft_shadow_quality", 2); GLOBAL_DEF("rendering/shadows/directional_shadow/soft_shadow_quality.mobile", 0); ProjectSettings::get_singleton()->set_custom_property_info("rendering/shadows/directional_shadow/soft_shadow_quality", PropertyInfo(Variant::INT, "rendering/shadows/directional_shadow/soft_shadow_quality", PROPERTY_HINT_ENUM, "Hard (Fastest),Soft Very Low (Faster),Soft Low (Fast),Soft Medium (Average),Soft High (Slow),Soft Ultra (Slowest)")); GLOBAL_DEF("rendering/shadows/directional_shadow/16_bits", true); - GLOBAL_DEF("rendering/shadows/shadows/soft_shadow_quality", 3); + GLOBAL_DEF("rendering/shadows/shadows/soft_shadow_quality", 2); GLOBAL_DEF("rendering/shadows/shadows/soft_shadow_quality.mobile", 0); ProjectSettings::get_singleton()->set_custom_property_info("rendering/shadows/shadows/soft_shadow_quality", PropertyInfo(Variant::INT, "rendering/shadows/shadows/soft_shadow_quality", PROPERTY_HINT_ENUM, "Hard (Fastest),Soft Very Low (Faster),Soft Low (Fast),Soft Medium (Average),Soft High (Slow),Soft Ultra (Slowest)")); @@ -2872,7 +2872,7 @@ RenderingServer::RenderingServer() { GLOBAL_DEF("rendering/global_illumination/gi/use_half_resolution", false); - GLOBAL_DEF("rendering/global_illumination/voxel_gi/quality", 1); + GLOBAL_DEF("rendering/global_illumination/voxel_gi/quality", 0); 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)")); GLOBAL_DEF("rendering/shading/overrides/force_vertex_shading", false); @@ -2979,7 +2979,7 @@ RenderingServer::RenderingServer() { GLOBAL_DEF("rendering/global_illumination/sdfgi/probe_ray_count", 1); ProjectSettings::get_singleton()->set_custom_property_info("rendering/global_illumination/sdfgi/probe_ray_count", PropertyInfo(Variant::INT, "rendering/global_illumination/sdfgi/probe_ray_count", PROPERTY_HINT_ENUM, "8 (Fastest),16,32,64,96,128 (Slowest)")); - GLOBAL_DEF("rendering/global_illumination/sdfgi/frames_to_converge", 4); + GLOBAL_DEF("rendering/global_illumination/sdfgi/frames_to_converge", 5); ProjectSettings::get_singleton()->set_custom_property_info("rendering/global_illumination/sdfgi/frames_to_converge", PropertyInfo(Variant::INT, "rendering/global_illumination/sdfgi/frames_to_converge", PROPERTY_HINT_ENUM, "5 (Less Latency but Lower Quality),10,15,20,25,30 (More Latency but Higher Quality)")); GLOBAL_DEF("rendering/global_illumination/sdfgi/frames_to_update_lights", 2); ProjectSettings::get_singleton()->set_custom_property_info("rendering/global_illumination/sdfgi/frames_to_update_lights", PropertyInfo(Variant::INT, "rendering/global_illumination/sdfgi/frames_to_update_lights", PROPERTY_HINT_ENUM, "1 (Slower),2,4,8,16 (Faster)")); diff --git a/servers/rendering_server.h b/servers/rendering_server.h index d21f3a3299..5e58afe718 100644 --- a/servers/rendering_server.h +++ b/servers/rendering_server.h @@ -473,7 +473,7 @@ 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; - virtual void directional_shadow_atlas_set_size(int p_size, bool p_16_bits = false) = 0; + virtual void directional_shadow_atlas_set_size(int p_size, bool p_16_bits = true) = 0; enum ShadowQuality { SHADOW_QUALITY_HARD, @@ -847,7 +847,7 @@ public: virtual void viewport_set_sdf_oversize_and_scale(RID p_viewport, ViewportSDFOversize p_oversize, ViewportSDFScale p_scale) = 0; - virtual void viewport_set_shadow_atlas_size(RID p_viewport, int p_size, bool p_16_bits = false) = 0; + virtual void viewport_set_shadow_atlas_size(RID p_viewport, int p_size, bool p_16_bits = true) = 0; virtual void viewport_set_shadow_atlas_quadrant_subdivision(RID p_viewport, int p_quadrant, int p_subdiv) = 0; enum ViewportMSAA { @@ -1042,9 +1042,9 @@ public: virtual void environment_set_ssil_quality(EnvironmentSSILQuality p_quality, bool p_half_size, float p_adaptive_target, int p_blur_passes, float p_fadeout_from, float p_fadeout_to) = 0; enum EnvironmentSDFGIYScale { - ENV_SDFGI_Y_SCALE_DISABLED, + ENV_SDFGI_Y_SCALE_50_PERCENT, ENV_SDFGI_Y_SCALE_75_PERCENT, - ENV_SDFGI_Y_SCALE_50_PERCENT + ENV_SDFGI_Y_SCALE_100_PERCENT, }; virtual void environment_set_sdfgi(RID p_env, bool p_enable, int p_cascades, float p_min_cell_size, 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) = 0; diff --git a/tests/core/math/test_vector3.h b/tests/core/math/test_vector3.h index 136a531946..847a7c0b3f 100644 --- a/tests/core/math/test_vector3.h +++ b/tests/core/math/test_vector3.h @@ -58,7 +58,7 @@ TEST_CASE("[Vector3] Angle methods") { CHECK_MESSAGE( Math::is_equal_approx(vector_x.signed_angle_to(vector_y, vector_y), (real_t)Math_TAU / 4), - "Vector3 signed_angle_to edge case should be postiive."); + "Vector3 signed_angle_to edge case should be positive."); CHECK_MESSAGE( Math::is_equal_approx(vector_x.signed_angle_to(vector_yz, vector_y), (real_t)Math_TAU / -4), "Vector3 signed_angle_to should work as expected."); |