diff options
74 files changed, 3528 insertions, 176 deletions
diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md deleted file mode 100644 index 1ca0b3694c..0000000000 --- a/.github/ISSUE_TEMPLATE.md +++ /dev/null @@ -1,21 +0,0 @@ -<!-- Please search existing issues for potential duplicates before filing yours: -https://github.com/godotengine/godot/issues?q=is%3Aissue ---> - -**Godot version:** -<!-- Specify commit hash if non-official. --> - - -**OS/device including version:** -<!-- Specify GPU model and drivers if graphics-related. --> - - -**Issue description:** -<!-- What happened, and what was expected. --> - - -**Steps to reproduce:** - - -**Minimal reproduction project:** -<!-- Recommended as it greatly speeds up debugging. Drag and drop a zip archive to upload it. --> diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000000..91528465c0 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,18 @@ +--- +name: Bug report +about: Report a bug in Godot +title: '' +labels: '' +assignees: '' + +--- + +**Godot version:** + +**OS/device including version:** + +**Issue description:** + +**Steps to reproduce:** + +**Minimal reproduction project:** diff --git a/.github/ISSUE_TEMPLATE/feature---enhancement-request.md b/.github/ISSUE_TEMPLATE/feature---enhancement-request.md new file mode 100644 index 0000000000..496e0197ca --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature---enhancement-request.md @@ -0,0 +1,19 @@ +--- +name: Feature / Enhancement Request +about: Adding new features or improving existing ones. +title: 'IMPORTANT: This repository no longer accepts feature / enhancement requests.' +labels: '' +assignees: '' + +--- + +**IMPORTANT, PLEASE READ** + +Feature / Enhancement requests are no longer accepted in the main Godot repository. +Please open an item by filling the relevant fields in the *Proposals* repository: + +https://github.com/godotengine/godot-proposals/issues/new/choose + +Do not submit to this repository or your issue will be closed. + +**IMPORTANT, PLEASE READ** diff --git a/core/io/multiplayer_api.cpp b/core/io/multiplayer_api.cpp index d20133642b..ed6905c9a6 100644 --- a/core/io/multiplayer_api.cpp +++ b/core/io/multiplayer_api.cpp @@ -33,6 +33,10 @@ #include "core/io/marshalls.h" #include "scene/main/node.h" +#ifdef DEBUG_ENABLED +#include "core/os/os.h" +#endif + _FORCE_INLINE_ bool _should_call_local(MultiplayerAPI::RPCMode mode, bool is_master, bool &r_skip_rpc) { switch (mode) { @@ -166,6 +170,14 @@ void MultiplayerAPI::_process_packet(int p_from, const uint8_t *p_packet, int p_ ERR_FAIL_COND_MSG(root_node == NULL, "Multiplayer root node was not initialized. If you are using custom multiplayer, remember to set the root node via MultiplayerAPI.set_root_node before using it."); ERR_FAIL_COND_MSG(p_packet_len < 1, "Invalid packet received. Size too small."); +#ifdef DEBUG_ENABLED + if (profiling) { + bandwidth_incoming_data.write[bandwidth_incoming_pointer].timestamp = OS::get_singleton()->get_ticks_msec(); + bandwidth_incoming_data.write[bandwidth_incoming_pointer].packet_size = p_packet_len; + bandwidth_incoming_pointer = (bandwidth_incoming_pointer + 1) % bandwidth_incoming_data.size(); + } +#endif + uint8_t packet_type = p_packet[0]; switch (packet_type) { @@ -284,6 +296,14 @@ void MultiplayerAPI::_process_rpc(Node *p_node, const StringName &p_name, int p_ p_offset++; +#ifdef DEBUG_ENABLED + if (profiling) { + ObjectID id = p_node->get_instance_id(); + _init_node_profile(id); + profiler_frame_data[id].incoming_rpc += 1; + } +#endif + for (int i = 0; i < argc; i++) { ERR_FAIL_COND_MSG(p_offset >= p_packet_len, "Invalid packet received. Size too small."); @@ -322,6 +342,14 @@ void MultiplayerAPI::_process_rset(Node *p_node, const StringName &p_name, int p bool can_call = _can_call_mode(p_node, rset_mode, p_from); ERR_FAIL_COND_MSG(!can_call, "RSET '" + String(p_name) + "' is not allowed on node " + p_node->get_path() + " from: " + itos(p_from) + ". Mode is " + itos((int)rset_mode) + ", master is " + itos(p_node->get_network_master()) + "."); +#ifdef DEBUG_ENABLED + if (profiling) { + ObjectID id = p_node->get_instance_id(); + _init_node_profile(id); + profiler_frame_data[id].incoming_rset += 1; + } +#endif + Variant value; Error err = decode_variant(value, &p_packet[p_offset], p_packet_len - p_offset, NULL, allow_object_decoding || network_peer->is_object_decoding_allowed()); @@ -512,6 +540,14 @@ void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p } } +#ifdef DEBUG_ENABLED + if (profiling) { + bandwidth_outgoing_data.write[bandwidth_outgoing_pointer].timestamp = OS::get_singleton()->get_ticks_msec(); + bandwidth_outgoing_data.write[bandwidth_outgoing_pointer].packet_size = ofs; + bandwidth_outgoing_pointer = (bandwidth_outgoing_pointer + 1) % bandwidth_outgoing_data.size(); + } +#endif + // See if all peers have cached path (is so, call can be fast). bool has_all_peers = _send_confirm_path(from_path, psc, p_to); @@ -615,6 +651,15 @@ void MultiplayerAPI::rpcp(Node *p_node, int p_peer_id, bool p_unreliable, const } if (!skip_rpc) { + +#ifdef DEBUG_ENABLED + if (profiling) { + ObjectID id = p_node->get_instance_id(); + _init_node_profile(id); + profiler_frame_data[id].outgoing_rpc += 1; + } +#endif + _send_rpc(p_node, p_peer_id, p_unreliable, false, p_method, p_arg, p_argcount); } @@ -709,6 +754,14 @@ void MultiplayerAPI::rsetp(Node *p_node, int p_peer_id, bool p_unreliable, const return; } +#ifdef DEBUG_ENABLED + if (profiling) { + ObjectID id = p_node->get_instance_id(); + _init_node_profile(id); + profiler_frame_data[id].outgoing_rset += 1; + } +#endif + const Variant *vptr = &p_value; _send_rpc(p_node, p_peer_id, p_unreliable, true, p_property, &vptr, 1); @@ -792,6 +845,96 @@ bool MultiplayerAPI::is_object_decoding_allowed() const { return allow_object_decoding; } +void MultiplayerAPI::profiling_start() { +#ifdef DEBUG_ENABLED + profiling = true; + profiler_frame_data.clear(); + + bandwidth_incoming_pointer = 0; + bandwidth_incoming_data.resize(16384); // ~128kB + for (int i = 0; i < bandwidth_incoming_data.size(); ++i) { + bandwidth_incoming_data.write[i].packet_size = -1; + } + + bandwidth_outgoing_pointer = 0; + bandwidth_outgoing_data.resize(16384); // ~128kB + for (int i = 0; i < bandwidth_outgoing_data.size(); ++i) { + bandwidth_outgoing_data.write[i].packet_size = -1; + } +#endif +} + +void MultiplayerAPI::profiling_end() { +#ifdef DEBUG_ENABLED + profiling = false; + bandwidth_incoming_data.clear(); + bandwidth_outgoing_data.clear(); +#endif +} + +int MultiplayerAPI::get_profiling_frame(ProfilingInfo *r_info) { + int i = 0; +#ifdef DEBUG_ENABLED + for (Map<ObjectID, ProfilingInfo>::Element *E = profiler_frame_data.front(); E; E = E->next()) { + r_info[i] = E->get(); + ++i; + } + profiler_frame_data.clear(); +#endif + return i; +} + +int MultiplayerAPI::get_incoming_bandwidth_usage() { +#ifdef DEBUG_ENABLED + return _get_bandwidth_usage(bandwidth_incoming_data, bandwidth_incoming_pointer); +#else + return 0; +#endif +} + +int MultiplayerAPI::get_outgoing_bandwidth_usage() { +#ifdef DEBUG_ENABLED + return _get_bandwidth_usage(bandwidth_outgoing_data, bandwidth_outgoing_pointer); +#else + return 0; +#endif +} + +#ifdef DEBUG_ENABLED +int MultiplayerAPI::_get_bandwidth_usage(const Vector<BandwidthFrame> &p_buffer, int p_pointer) { + int total_bandwidth = 0; + + uint32_t timestamp = OS::get_singleton()->get_ticks_msec(); + uint32_t final_timestamp = timestamp - 1000; + + int i = (p_pointer + p_buffer.size() - 1) % p_buffer.size(); + + while (i != p_pointer && p_buffer[i].packet_size > 0) { + if (p_buffer[i].timestamp < final_timestamp) { + return total_bandwidth; + } + total_bandwidth += p_buffer[i].packet_size; + i = (i + p_buffer.size() - 1) % p_buffer.size(); + } + + ERR_EXPLAIN("Reached the end of the bandwidth profiler buffer, values might be inaccurate."); + ERR_FAIL_COND_V(i == p_pointer, total_bandwidth); + return total_bandwidth; +} + +void MultiplayerAPI::_init_node_profile(ObjectID p_node) { + if (profiler_frame_data.has(p_node)) + return; + profiler_frame_data.insert(p_node, ProfilingInfo()); + profiler_frame_data[p_node].node = p_node; + profiler_frame_data[p_node].node_path = Object::cast_to<Node>(ObjectDB::get_instance(p_node))->get_path(); + profiler_frame_data[p_node].incoming_rpc = 0; + profiler_frame_data[p_node].incoming_rset = 0; + profiler_frame_data[p_node].outgoing_rpc = 0; + profiler_frame_data[p_node].outgoing_rset = 0; +} +#endif + void MultiplayerAPI::_bind_methods() { ClassDB::bind_method(D_METHOD("set_root_node", "node"), &MultiplayerAPI::set_root_node); ClassDB::bind_method(D_METHOD("send_bytes", "bytes", "id", "mode"), &MultiplayerAPI::send_bytes, DEFVAL(NetworkedMultiplayerPeer::TARGET_PEER_BROADCAST), DEFVAL(NetworkedMultiplayerPeer::TRANSFER_MODE_RELIABLE)); @@ -842,6 +985,9 @@ MultiplayerAPI::MultiplayerAPI() : allow_object_decoding(false) { rpc_sender_id = 0; root_node = NULL; +#ifdef DEBUG_ENABLED + profiling = false; +#endif clear(); } diff --git a/core/io/multiplayer_api.h b/core/io/multiplayer_api.h index 5258dde5d7..b824456e0f 100644 --- a/core/io/multiplayer_api.h +++ b/core/io/multiplayer_api.h @@ -38,6 +38,16 @@ class MultiplayerAPI : public Reference { GDCLASS(MultiplayerAPI, Reference); +public: + struct ProfilingInfo { + ObjectID node; + String node_path; + int incoming_rpc; + int incoming_rset; + int outgoing_rpc; + int outgoing_rset; + }; + private: //path sent caches struct PathSentCache { @@ -55,6 +65,23 @@ private: Map<int, NodeInfo> nodes; }; +#ifdef DEBUG_ENABLED + struct BandwidthFrame { + uint32_t timestamp; + int packet_size; + }; + + int bandwidth_incoming_pointer; + Vector<BandwidthFrame> bandwidth_incoming_data; + int bandwidth_outgoing_pointer; + Vector<BandwidthFrame> bandwidth_outgoing_data; + Map<ObjectID, ProfilingInfo> profiler_frame_data; + bool profiling; + + void _init_node_profile(ObjectID p_node); + int _get_bandwidth_usage(const Vector<BandwidthFrame> &p_buffer, int p_pointer); +#endif + Ref<NetworkedMultiplayerPeer> network_peer; int rpc_sender_id; Set<int> connected_peers; @@ -130,6 +157,13 @@ public: void set_allow_object_decoding(bool p_enable); bool is_object_decoding_allowed() const; + void profiling_start(); + void profiling_end(); + + int get_profiling_frame(ProfilingInfo *r_info); + int get_incoming_bandwidth_usage(); + int get_outgoing_bandwidth_usage(); + MultiplayerAPI(); ~MultiplayerAPI(); }; diff --git a/core/script_debugger_local.cpp b/core/script_debugger_local.cpp index ac4dafcf59..e61f9f7158 100644 --- a/core/script_debugger_local.cpp +++ b/core/script_debugger_local.cpp @@ -33,7 +33,7 @@ #include "core/os/os.h" #include "scene/main/scene_tree.h" -void ScriptDebuggerLocal::debug(ScriptLanguage *p_script, bool p_can_continue) { +void ScriptDebuggerLocal::debug(ScriptLanguage *p_script, bool p_can_continue, bool p_is_error_breakpoint) { if (!target_function.empty()) { String current_function = p_script->debug_get_stack_level_function(0); diff --git a/core/script_debugger_local.h b/core/script_debugger_local.h index 19151d4cb0..b3aed5e358 100644 --- a/core/script_debugger_local.h +++ b/core/script_debugger_local.h @@ -48,7 +48,7 @@ class ScriptDebuggerLocal : public ScriptDebugger { void print_variables(const List<String> &names, const List<Variant> &values, const String &variable_prefix); public: - void debug(ScriptLanguage *p_script, bool p_can_continue); + void debug(ScriptLanguage *p_script, bool p_can_continue, bool p_is_error_breakpoint); virtual void send_message(const String &p_message, const Array &p_args); virtual void send_error(const String &p_func, const String &p_file, int p_line, const String &p_err, const String &p_descr, ErrorHandlerType p_type, const Vector<ScriptLanguage::StackInfo> &p_stack_info); diff --git a/core/script_debugger_remote.cpp b/core/script_debugger_remote.cpp index 2a061f0947..65ef2a0978 100644 --- a/core/script_debugger_remote.cpp +++ b/core/script_debugger_remote.cpp @@ -129,11 +129,14 @@ void ScriptDebuggerRemote::_save_node(ObjectID id, const String &p_path) { ResourceSaver::save(p_path, ps); } -void ScriptDebuggerRemote::debug(ScriptLanguage *p_script, bool p_can_continue) { +void ScriptDebuggerRemote::debug(ScriptLanguage *p_script, bool p_can_continue, bool p_is_error_breakpoint) { //this function is called when there is a debugger break (bug on script) //or when execution is paused from editor + if (skip_breakpoints && !p_is_error_breakpoint) + return; + ERR_FAIL_COND_MSG(!tcp_client->is_connected_to_host(), "Script Debugger failed to connect, but being used anyway."); packet_peer_stream->put_var("debug_enter"); @@ -155,6 +158,7 @@ void ScriptDebuggerRemote::debug(ScriptLanguage *p_script, bool p_can_continue) Variant var; Error err = packet_peer_stream->get_var(var); + ERR_CONTINUE(err != OK); ERR_CONTINUE(var.get_type() != Variant::ARRAY); @@ -266,7 +270,6 @@ void ScriptDebuggerRemote::debug(ScriptLanguage *p_script, bool p_can_continue) break; } else if (command == "continue") { - set_depth(-1); set_lines_left(-1); OS::get_singleton()->move_window_to_foreground(); @@ -302,6 +305,8 @@ void ScriptDebuggerRemote::debug(ScriptLanguage *p_script, bool p_can_continue) } else if (command == "save_node") { _save_node(cmd[1], cmd[2]); + } else if (command == "set_skip_breakpoints") { + skip_breakpoints = cmd[1]; } else { _parse_live_edit(cmd); } @@ -764,6 +769,14 @@ void ScriptDebuggerRemote::_poll_events() { profiling = false; _send_profiling_data(false); print_line("PROFILING END!"); + } else if (command == "start_network_profiling") { + + multiplayer->profiling_start(); + profiling_network = true; + } else if (command == "stop_network_profiling") { + + multiplayer->profiling_end(); + profiling_network = false; } else if (command == "reload_scripts") { reload_all_scripts = true; } else if (command == "breakpoint") { @@ -773,6 +786,8 @@ void ScriptDebuggerRemote::_poll_events() { insert_breakpoint(cmd[2], cmd[1]); else remove_breakpoint(cmd[2], cmd[1]); + } else if (command == "set_skip_breakpoints") { + skip_breakpoints = cmd[1]; } else { _parse_live_edit(cmd); } @@ -911,6 +926,18 @@ void ScriptDebuggerRemote::idle_poll() { } } + if (profiling_network) { + uint64_t pt = OS::get_singleton()->get_ticks_msec(); + if (pt - last_net_bandwidth_time > 200) { + last_net_bandwidth_time = pt; + _send_network_bandwidth_usage(); + } + if (pt - last_net_prof_time > 100) { + last_net_prof_time = pt; + _send_network_profiling_data(); + } + } + if (reload_all_scripts) { for (int i = 0; i < ScriptServer::get_language_count(); i++) { @@ -922,6 +949,35 @@ void ScriptDebuggerRemote::idle_poll() { _poll_events(); } +void ScriptDebuggerRemote::_send_network_profiling_data() { + ERR_FAIL_COND(multiplayer.is_null()); + + int n_nodes = multiplayer->get_profiling_frame(&network_profile_info.write[0]); + + packet_peer_stream->put_var("network_profile"); + packet_peer_stream->put_var(n_nodes * 6); + for (int i = 0; i < n_nodes; ++i) { + packet_peer_stream->put_var(network_profile_info[i].node); + packet_peer_stream->put_var(network_profile_info[i].node_path); + packet_peer_stream->put_var(network_profile_info[i].incoming_rpc); + packet_peer_stream->put_var(network_profile_info[i].incoming_rset); + packet_peer_stream->put_var(network_profile_info[i].outgoing_rpc); + packet_peer_stream->put_var(network_profile_info[i].outgoing_rset); + } +} + +void ScriptDebuggerRemote::_send_network_bandwidth_usage() { + ERR_FAIL_COND(multiplayer.is_null()); + + int incoming_bandwidth = multiplayer->get_incoming_bandwidth_usage(); + int outgoing_bandwidth = multiplayer->get_outgoing_bandwidth_usage(); + + packet_peer_stream->put_var("network_bandwidth"); + packet_peer_stream->put_var(2); + packet_peer_stream->put_var(incoming_bandwidth); + packet_peer_stream->put_var(outgoing_bandwidth); +} + void ScriptDebuggerRemote::send_message(const String &p_message, const Array &p_args) { mutex->lock(); @@ -1061,6 +1117,10 @@ void ScriptDebuggerRemote::set_live_edit_funcs(LiveEditFuncs *p_funcs) { live_edit_funcs = p_funcs; } +void ScriptDebuggerRemote::set_multiplayer(Ref<MultiplayerAPI> p_multiplayer) { + multiplayer = p_multiplayer; +} + bool ScriptDebuggerRemote::is_profiling() const { return profiling; @@ -1102,16 +1162,23 @@ void ScriptDebuggerRemote::profiling_set_frame_times(float p_frame_time, float p physics_frame_time = p_physics_frame_time; } +void ScriptDebuggerRemote::set_skip_breakpoints(bool p_skip_breakpoints) { + skip_breakpoints = p_skip_breakpoints; +} + ScriptDebuggerRemote::ResourceUsageFunc ScriptDebuggerRemote::resource_usage_func = NULL; ScriptDebuggerRemote::ScriptDebuggerRemote() : profiling(false), + profiling_network(false), max_frame_functions(16), skip_profile_frame(false), reload_all_scripts(false), tcp_client(Ref<StreamPeerTCP>(memnew(StreamPeerTCP))), packet_peer_stream(Ref<PacketPeerStream>(memnew(PacketPeerStream))), last_perf_time(0), + last_net_prof_time(0), + last_net_bandwidth_time(0), performance(Engine::get_singleton()->get_singleton_object("Performance")), requested_quit(false), mutex(Mutex::create()), @@ -1143,6 +1210,7 @@ ScriptDebuggerRemote::ScriptDebuggerRemote() : add_error_handler(&eh); profile_info.resize(GLOBAL_GET("debug/settings/profiler/max_functions")); + network_profile_info.resize(GLOBAL_GET("debug/settings/profiler/max_functions")); profile_info_ptrs.resize(profile_info.size()); } diff --git a/core/script_debugger_remote.h b/core/script_debugger_remote.h index a5bfd7a32d..b6dd925181 100644 --- a/core/script_debugger_remote.h +++ b/core/script_debugger_remote.h @@ -54,11 +54,13 @@ class ScriptDebuggerRemote : public ScriptDebugger { Vector<ScriptLanguage::ProfilingInfo> profile_info; Vector<ScriptLanguage::ProfilingInfo *> profile_info_ptrs; + Vector<MultiplayerAPI::ProfilingInfo> network_profile_info; Map<StringName, int> profiler_function_signature_map; float frame_time, idle_time, physics_time, physics_frame_time; bool profiling; + bool profiling_network; int max_frame_functions; bool skip_profile_frame; bool reload_all_scripts; @@ -67,6 +69,8 @@ class ScriptDebuggerRemote : public ScriptDebugger { Ref<PacketPeerStream> packet_peer_stream; uint64_t last_perf_time; + uint64_t last_net_prof_time; + uint64_t last_net_bandwidth_time; Object *performance; bool requested_quit; Mutex *mutex; @@ -123,10 +127,14 @@ class ScriptDebuggerRemote : public ScriptDebugger { void _send_video_memory(); LiveEditFuncs *live_edit_funcs; + Ref<MultiplayerAPI> multiplayer; + ErrorHandlerList eh; static void _err_handler(void *, const char *, const char *, int p_line, const char *, const char *, ErrorHandlerType p_type); void _send_profiling_data(bool p_for_frame); + void _send_network_profiling_data(); + void _send_network_bandwidth_usage(); struct FrameData { @@ -140,6 +148,8 @@ class ScriptDebuggerRemote : public ScriptDebugger { void _save_node(ObjectID id, const String &p_path); + bool skip_breakpoints; + public: struct ResourceUsage { @@ -156,7 +166,7 @@ public: static ResourceUsageFunc resource_usage_func; Error connect_to_host(const String &p_host, uint16_t p_port); - virtual void debug(ScriptLanguage *p_script, bool p_can_continue = true); + virtual void debug(ScriptLanguage *p_script, bool p_can_continue = true, bool p_is_error_breakpoint = false); virtual void idle_poll(); virtual void line_poll(); @@ -168,6 +178,7 @@ public: virtual void set_request_scene_tree_message_func(RequestSceneTreeMessageFunc p_func, void *p_udata); virtual void set_live_edit_funcs(LiveEditFuncs *p_funcs); + virtual void set_multiplayer(Ref<MultiplayerAPI> p_multiplayer); virtual bool is_profiling() const; virtual void add_profiling_frame_data(const StringName &p_name, const Array &p_data); @@ -176,6 +187,8 @@ public: virtual void profiling_end(); virtual void profiling_set_frame_times(float p_frame_time, float p_idle_time, float p_physics_time, float p_physics_frame_time); + virtual void set_skip_breakpoints(bool p_skip_breakpoints); + ScriptDebuggerRemote(); ~ScriptDebuggerRemote(); }; diff --git a/core/script_language.h b/core/script_language.h index 1b4f1eb4cd..116918fdc0 100644 --- a/core/script_language.h +++ b/core/script_language.h @@ -467,7 +467,7 @@ public: void clear_breakpoints(); const Map<int, Set<StringName> > &get_breakpoints() const { return breakpoints; } - virtual void debug(ScriptLanguage *p_script, bool p_can_continue = true) = 0; + virtual void debug(ScriptLanguage *p_script, bool p_can_continue = true, bool p_is_error_breakpoint = false) = 0; virtual void idle_poll(); virtual void line_poll(); @@ -482,6 +482,7 @@ public: virtual void set_request_scene_tree_message_func(RequestSceneTreeMessageFunc p_func, void *p_udata) {} virtual void set_live_edit_funcs(LiveEditFuncs *p_funcs) {} + virtual void set_multiplayer(Ref<MultiplayerAPI> p_multiplayer) {} virtual bool is_profiling() const = 0; virtual void add_profiling_frame_data(const StringName &p_name, const Array &p_data) = 0; diff --git a/core/ustring.cpp b/core/ustring.cpp index 3f5e198281..fb4bd6d802 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -3285,7 +3285,7 @@ static int _humanize_digits(int p_num) { String String::humanize_size(size_t p_size) { uint64_t _div = 1; - static const char *prefix[] = { " Bytes", " KB", " MB", " GB", " TB", " PB", " EB", "" }; + static const char *prefix[] = { " B", " KiB", " MiB", " GiB", " TiB", " PiB", " EiB", "" }; int prefix_idx = 0; while (p_size > (_div * 1024) && prefix[prefix_idx][0]) { @@ -3296,7 +3296,7 @@ String String::humanize_size(size_t p_size) { int digits = prefix_idx > 0 ? _humanize_digits(p_size / _div) : 0; double divisor = prefix_idx > 0 ? _div : 1; - return String::num(p_size / divisor).pad_decimals(digits) + prefix[prefix_idx]; + return String::num(p_size / divisor).pad_decimals(digits) + RTR(prefix[prefix_idx]); } bool String::is_abs_path() const { diff --git a/doc/classes/EditorVCSInterface.xml b/doc/classes/EditorVCSInterface.xml new file mode 100644 index 0000000000..2f58e6d54e --- /dev/null +++ b/doc/classes/EditorVCSInterface.xml @@ -0,0 +1,115 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="EditorVCSInterface" inherits="Object" category="Core" version="3.2"> + <brief_description> + Version Control System (VCS) interface which reads and writes to the local VCS in use. + </brief_description> + <description> + Used by the editor to display VCS extracted information in the editor. The implementation of this API is included in VCS addons, which are essentially GDNative plugins that need to be put into the project folder. These VCS addons are scripts which are attached (on demand) to the object instance of [code]EditorVCSInterface[/code]. All the functions listed below, instead of performing the task themselves, they call the internally defined functions in the VCS addons to provide a plug-n-play experience. + </description> + <tutorials> + </tutorials> + <methods> + <method name="commit"> + <return type="void"> + </return> + <argument index="0" name="msg" type="String"> + </argument> + <description> + Creates a version commit if the addon is initialized, else returns without doing anything. Uses the files which have been staged previously, with the commit message set to a value as provided as in the argument. + </description> + </method> + <method name="get_file_diff"> + <return type="Array"> + </return> + <argument index="0" name="file_path" type="String"> + </argument> + <description> + Returns an [Array] of [Dictionary] objects containing the diff output from the VCS in use, if a VCS addon is initialized, else returns an empty [Array] object. The diff contents also consist of some contextual lines which provide context to the observed line change in the file. + Each [Dictionary] object has the line diff contents under the keys: + - [code]"content"[/code] to store a [String] containing the line contents + - [code]"status"[/code] to store a [String] which contains [code]"+"[/code] in case the content is a line addition but it stores a [code]"-"[/code] in case of deletion and an empty string in the case the line content is neither an addition nor a deletion. + - [code]"new_line_number"[/code] to store an integer containing the new line number of the line content. + - [code]"line_count"[/code] to store an integer containing the number of lines in the line content. + - [code]"old_line_number"[/code] to store an integer containing the old line number of the line content. + - [code]"offset"[/code] to store the offset of the line change since the first contextual line content. + </description> + </method> + <method name="get_is_vcs_intialized"> + <return type="bool"> + </return> + <description> + Returns [code]true[/code] if the VCS addon has been intialized, else returns [code]false[/code]. + </description> + </method> + <method name="get_modified_files_data"> + <return type="Dictionary"> + </return> + <description> + Returns a [Dictionary] containing the path of the detected file change mapped to an integer signifying what kind of a change the corresponding file has experienced. + The following integer values are being used to signify that the detected file is: + - [code]0[/code]: New to the VCS working directory + - [code]1[/code]: Modified + - [code]2[/code]: Renamed + - [code]3[/code]: Deleted + - [code]4[/code]: Typechanged + </description> + </method> + <method name="get_project_name"> + <return type="String"> + </return> + <description> + Return the project name of the VCS working directory + </description> + </method> + <method name="get_vcs_name"> + <return type="String"> + </return> + <description> + Return the name of the VCS if the VCS has been intialized, else return an empty string. + </description> + </method> + <method name="initialize"> + <return type="bool"> + </return> + <argument index="0" name="project_root_path" type="String"> + </argument> + <description> + Initialize the VCS addon if not already. Uses the argument value as the path to the working directory of the project. Creates the initial commit if required. Returns [code]true[/code] if no failure occurs, else returns [code]false[/code]. + </description> + </method> + <method name="is_addon_ready"> + <return type="bool"> + </return> + <description> + Returns [code]true[/code] if the addon is ready to respond to function calls, else returns [code]false[/code]. + </description> + </method> + <method name="shut_down"> + <return type="bool"> + </return> + <description> + Shuts down the VCS addon to allow cleanup code to run on call. Returns [code]true[/code] is no failure occurs, else returns [code]false[/code]. + </description> + </method> + <method name="stage_file"> + <return type="void"> + </return> + <argument index="0" name="file_path" type="String"> + </argument> + <description> + Stage the file which should be committed when [method EditorVCSInterface.commit] is called. Argument should contain the absolute path. + </description> + </method> + <method name="unstage_file"> + <return type="void"> + </return> + <argument index="0" name="file_path" type="String"> + </argument> + <description> + Unstage the file which was staged previously to be committed, so that it is no longer committed when [method EditorVCSInterface.commit] is called. Argument should contain the absolute path. + </description> + </method> + </methods> + <constants> + </constants> +</class> diff --git a/drivers/gles2/shader_compiler_gles2.cpp b/drivers/gles2/shader_compiler_gles2.cpp index 640d45ae65..92bf0e29e2 100644 --- a/drivers/gles2/shader_compiler_gles2.cpp +++ b/drivers/gles2/shader_compiler_gles2.cpp @@ -353,6 +353,11 @@ String ShaderCompilerGLES2::_dump_node_code(SL::Node *p_node, int p_level, Gener varying_code += _typestr(E->get().type); varying_code += " "; varying_code += _mkid(E->key()); + if (E->get().array_size > 0) { + varying_code += "["; + varying_code += itos(E->get().array_size); + varying_code += "]"; + } varying_code += ";\n"; String final_code = varying_code.as_string(); diff --git a/drivers/gles3/shader_compiler_gles3.cpp b/drivers/gles3/shader_compiler_gles3.cpp index 0121d88f4d..3f21be8dd3 100644 --- a/drivers/gles3/shader_compiler_gles3.cpp +++ b/drivers/gles3/shader_compiler_gles3.cpp @@ -467,6 +467,11 @@ String ShaderCompilerGLES3::_dump_node_code(SL::Node *p_node, int p_level, Gener vcode += _prestr(E->get().precision); vcode += _typestr(E->get().type); vcode += " " + _mkid(E->key()); + if (E->get().array_size > 0) { + vcode += "["; + vcode += itos(E->get().array_size); + vcode += "]"; + } vcode += ";\n"; r_gen_code.vertex_global += interp_mode + "out " + vcode; r_gen_code.fragment_global += interp_mode + "in " + vcode; diff --git a/editor/editor_network_profiler.cpp b/editor/editor_network_profiler.cpp new file mode 100644 index 0000000000..b90fe96cee --- /dev/null +++ b/editor/editor_network_profiler.cpp @@ -0,0 +1,192 @@ +/*************************************************************************/ +/* editor_network_profiler.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2019 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 "editor_network_profiler.h" + +#include "core/os/os.h" +#include "editor_scale.h" +#include "editor_settings.h" + +void EditorNetworkProfiler::_bind_methods() { + ClassDB::bind_method(D_METHOD("_update_frame"), &EditorNetworkProfiler::_update_frame); + ClassDB::bind_method(D_METHOD("_activate_pressed"), &EditorNetworkProfiler::_activate_pressed); + ClassDB::bind_method(D_METHOD("_clear_pressed"), &EditorNetworkProfiler::_clear_pressed); + ADD_SIGNAL(MethodInfo("enable_profiling", PropertyInfo(Variant::BOOL, "enable"))); +} + +void EditorNetworkProfiler::_notification(int p_what) { + + if (p_what == NOTIFICATION_ENTER_TREE) { + activate->set_icon(get_icon("Play", "EditorIcons")); + clear_button->set_icon(get_icon("Clear", "EditorIcons")); + } +} + +void EditorNetworkProfiler::_update_frame() { + + counters_display->clear(); + + TreeItem *root = counters_display->create_item(); + + for (Map<ObjectID, MultiplayerAPI::ProfilingInfo>::Element *E = nodes_data.front(); E; E = E->next()) { + + TreeItem *node = counters_display->create_item(root); + + for (int j = 0; j < counters_display->get_columns(); ++j) { + node->set_text_align(j, j > 0 ? TreeItem::ALIGN_RIGHT : TreeItem::ALIGN_LEFT); + } + + node->set_text(0, E->get().node_path); + node->set_text(1, E->get().incoming_rpc == 0 ? "-" : itos(E->get().incoming_rpc)); + node->set_text(2, E->get().incoming_rset == 0 ? "-" : itos(E->get().incoming_rset)); + node->set_text(3, E->get().outgoing_rpc == 0 ? "-" : itos(E->get().outgoing_rpc)); + node->set_text(4, E->get().outgoing_rset == 0 ? "-" : itos(E->get().outgoing_rset)); + } +} + +void EditorNetworkProfiler::_activate_pressed() { + + if (activate->is_pressed()) { + activate->set_icon(get_icon("Stop", "EditorIcons")); + activate->set_text(TTR("Stop")); + } else { + activate->set_icon(get_icon("Play", "EditorIcons")); + activate->set_text(TTR("Start")); + } + emit_signal("enable_profiling", activate->is_pressed()); +} + +void EditorNetworkProfiler::_clear_pressed() { + nodes_data.clear(); + set_bandwidth(0, 0); + if (frame_delay->is_stopped()) { + frame_delay->set_wait_time(0.1); + frame_delay->start(); + } +} + +void EditorNetworkProfiler::add_node_frame_data(const MultiplayerAPI::ProfilingInfo 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()) { + frame_delay->set_wait_time(0.1); + frame_delay->start(); + } +} + +void EditorNetworkProfiler::set_bandwidth(int p_incoming, int p_outgoing) { + + incoming_bandwidth_text->set_text(vformat(TTR("%s/s"), String::humanize_size(p_incoming))); + outgoing_bandwidth_text->set_text(vformat(TTR("%s/s"), String::humanize_size(p_outgoing))); +} + +bool EditorNetworkProfiler::is_profiling() { + return activate->is_pressed(); +} + +EditorNetworkProfiler::EditorNetworkProfiler() { + + HBoxContainer *hb = memnew(HBoxContainer); + hb->add_constant_override("separation", 8 * EDSCALE); + add_child(hb); + + activate = memnew(Button); + activate->set_toggle_mode(true); + activate->set_text(TTR("Start")); + activate->connect("pressed", this, "_activate_pressed"); + hb->add_child(activate); + + clear_button = memnew(Button); + clear_button->set_text(TTR("Clear")); + clear_button->connect("pressed", this, "_clear_pressed"); + hb->add_child(clear_button); + + hb->add_spacer(); + + Label *lb = memnew(Label); + lb->set_text("Down "); + hb->add_child(lb); + + incoming_bandwidth_text = memnew(LineEdit); + incoming_bandwidth_text->set_editable(false); + incoming_bandwidth_text->set_custom_minimum_size(Size2(100, 0)); + incoming_bandwidth_text->set_align(LineEdit::Align::ALIGN_RIGHT); + incoming_bandwidth_text->set_text("0.0 B/s"); + hb->add_child(incoming_bandwidth_text); + + lb = memnew(Label); + lb->set_text("Up "); + hb->add_child(lb); + + outgoing_bandwidth_text = memnew(LineEdit); + outgoing_bandwidth_text->set_editable(false); + outgoing_bandwidth_text->set_custom_minimum_size(Size2(100, 0)); + outgoing_bandwidth_text->set_align(LineEdit::Align::ALIGN_RIGHT); + outgoing_bandwidth_text->set_text("0.0 B/s"); + hb->add_child(outgoing_bandwidth_text); + + counters_display = memnew(Tree); + counters_display->set_custom_minimum_size(Size2(300, 0) * EDSCALE); + 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_column_titles_visible(true); + counters_display->set_column_title(0, TTR("Node")); + counters_display->set_column_expand(0, true); + counters_display->set_column_min_width(0, 60); + counters_display->set_column_title(1, TTR("Incoming RPC")); + counters_display->set_column_expand(1, false); + counters_display->set_column_min_width(1, 120 * EDSCALE); + counters_display->set_column_title(2, TTR("Incoming RSET")); + counters_display->set_column_expand(2, false); + counters_display->set_column_min_width(2, 120 * EDSCALE); + counters_display->set_column_title(3, TTR("Outgoing RPC")); + counters_display->set_column_expand(3, false); + counters_display->set_column_min_width(3, 120 * EDSCALE); + counters_display->set_column_title(4, TTR("Outgoing RSET")); + counters_display->set_column_expand(4, false); + counters_display->set_column_min_width(4, 120 * EDSCALE); + add_child(counters_display); + + frame_delay = memnew(Timer); + frame_delay->set_wait_time(0.1); + frame_delay->set_one_shot(true); + add_child(frame_delay); + frame_delay->connect("timeout", this, "_update_frame"); +} diff --git a/editor/editor_network_profiler.h b/editor/editor_network_profiler.h new file mode 100644 index 0000000000..85fec340fd --- /dev/null +++ b/editor/editor_network_profiler.h @@ -0,0 +1,72 @@ +/*************************************************************************/ +/* editor_network_profiler.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2019 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 EDITORNETWORKPROFILER_H +#define EDITORNETWORKPROFILER_H + +#include "scene/gui/box_container.h" +#include "scene/gui/button.h" +#include "scene/gui/label.h" +#include "scene/gui/split_container.h" +#include "scene/gui/tree.h" + +class EditorNetworkProfiler : public VBoxContainer { + + GDCLASS(EditorNetworkProfiler, VBoxContainer) + +private: + Button *activate; + Button *clear_button; + Tree *counters_display; + LineEdit *incoming_bandwidth_text; + LineEdit *outgoing_bandwidth_text; + + Timer *frame_delay; + + Map<ObjectID, MultiplayerAPI::ProfilingInfo> nodes_data; + + void _update_frame(); + + void _activate_pressed(); + void _clear_pressed(); + +protected: + void _notification(int p_what); + static void _bind_methods(); + +public: + void add_node_frame_data(const MultiplayerAPI::ProfilingInfo p_frame); + void set_bandwidth(int p_incoming, int p_outgoing); + bool is_profiling(); + + EditorNetworkProfiler(); +}; + +#endif //EDITORNETWORKPROFILER_H diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 98f5fcbeec..a1998a1d7c 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -60,6 +60,7 @@ #include "editor/import/editor_import_collada.h" #include "editor/import/editor_scene_importer_gltf.h" #include "editor/import/resource_importer_bitmask.h" +#include "editor/import/resource_importer_csv.h" #include "editor/import/resource_importer_csv_translation.h" #include "editor/import/resource_importer_image.h" #include "editor/import/resource_importer_layered_texture.h" @@ -122,6 +123,7 @@ #include "editor/plugins/theme_editor_plugin.h" #include "editor/plugins/tile_map_editor_plugin.h" #include "editor/plugins/tile_set_editor_plugin.h" +#include "editor/plugins/version_control_editor_plugin.h" #include "editor/plugins/visual_shader_editor_plugin.h" #include "editor/pvrtc_compress.h" #include "editor/register_exporters.h" @@ -184,6 +186,20 @@ void EditorNode::_update_scene_tabs() { } } +void EditorNode::_version_control_menu_option(int p_idx) { + + switch (vcs_actions_menu->get_item_id(p_idx)) { + case RUN_VCS_SETTINGS: { + + VersionControlEditorPlugin::get_singleton()->popup_vcs_set_up_dialog(gui_base); + } break; + case RUN_VCS_SHUT_DOWN: { + + VersionControlEditorPlugin::get_singleton()->shut_down(); + } break; + } +} + void EditorNode::_update_title() { String appname = ProjectSettings::get_singleton()->get("application/config/name"); @@ -1835,6 +1851,7 @@ void EditorNode::_run(bool p_current, const String &p_custom) { String main_scene; String run_filename; String args; + bool skip_breakpoints; if (p_current || (editor_data.get_edited_scene_root() && p_custom == editor_data.get_edited_scene_root()->get_filename())) { @@ -1900,8 +1917,9 @@ void EditorNode::_run(bool p_current, const String &p_custom) { editor_data.get_editor_breakpoints(&breakpoints); args = ProjectSettings::get_singleton()->get("editor/main_run_args"); + skip_breakpoints = ScriptEditor::get_singleton()->get_debugger()->is_skip_breakpoints(); - Error error = editor_run.run(run_filename, args, breakpoints); + Error error = editor_run.run(run_filename, args, breakpoints, skip_breakpoints); if (error != OK) { @@ -3523,6 +3541,7 @@ void EditorNode::register_editor_types() { ClassDB::register_class<EditorResourcePreviewGenerator>(); ClassDB::register_virtual_class<EditorFileSystem>(); ClassDB::register_class<EditorFileSystemDirectory>(); + ClassDB::register_class<EditorVCSInterface>(); ClassDB::register_virtual_class<ScriptEditor>(); ClassDB::register_virtual_class<EditorInterface>(); ClassDB::register_class<EditorExportPlugin>(); @@ -5312,6 +5331,7 @@ void EditorNode::_bind_methods() { ClassDB::bind_method("_dropped_files", &EditorNode::_dropped_files); ClassDB::bind_method(D_METHOD("_global_menu_action"), &EditorNode::_global_menu_action, DEFVAL(Variant())); ClassDB::bind_method("_toggle_distraction_free_mode", &EditorNode::_toggle_distraction_free_mode); + ClassDB::bind_method("_version_control_menu_option", &EditorNode::_version_control_menu_option); ClassDB::bind_method("edit_item_resource", &EditorNode::edit_item_resource); ClassDB::bind_method(D_METHOD("get_gui_base"), &EditorNode::get_gui_base); @@ -5540,6 +5560,10 @@ EditorNode::EditorNode() { import_csv_translation.instance(); ResourceFormatImporter::get_singleton()->add_importer(import_csv_translation); + Ref<ResourceImporterCSV> import_csv; + import_csv.instance(); + ResourceFormatImporter::get_singleton()->add_importer(import_csv); + Ref<ResourceImporterWAV> import_wav; import_wav.instance(); ResourceFormatImporter::get_singleton()->add_importer(import_wav); @@ -5998,6 +6022,15 @@ EditorNode::EditorNode() { p->add_shortcut(ED_SHORTCUT("editor/project_settings", TTR("Project Settings...")), RUN_SETTINGS); p->connect("id_pressed", this, "_menu_option"); + vcs_actions_menu = VersionControlEditorPlugin::get_singleton()->get_version_control_actions_panel(); + vcs_actions_menu->set_name("Version Control"); + vcs_actions_menu->connect("index_pressed", this, "_version_control_menu_option"); + p->add_separator(); + p->add_child(vcs_actions_menu); + p->add_submenu_item(TTR("Version Control"), "Version Control"); + vcs_actions_menu->add_item(TTR("Set Up Version Control"), RUN_VCS_SETTINGS); + vcs_actions_menu->add_item(TTR("Shut Down Version Control"), RUN_VCS_SHUT_DOWN); + p->add_separator(); p->add_shortcut(ED_SHORTCUT("editor/export", TTR("Export...")), FILE_EXPORT_PROJECT); p->add_item(TTR("Install Android Build Template..."), FILE_INSTALL_ANDROID_SOURCE); @@ -6007,7 +6040,6 @@ EditorNode::EditorNode() { plugin_config_dialog->connect("plugin_ready", this, "_on_plugin_ready"); gui_base->add_child(plugin_config_dialog); - p->add_separator(); tool_menu = memnew(PopupMenu); tool_menu->set_name("Tools"); tool_menu->connect("index_pressed", this, "_tool_menu_option"); @@ -6472,6 +6504,7 @@ EditorNode::EditorNode() { //more visually meaningful to have this later raise_bottom_panel_item(AnimationPlayerEditor::singleton); + add_editor_plugin(VersionControlEditorPlugin::get_singleton()); add_editor_plugin(memnew(ShaderEditorPlugin(this))); add_editor_plugin(memnew(VisualShaderEditorPlugin(this))); diff --git a/editor/editor_node.h b/editor/editor_node.h index 54bcf14c1b..5ecb472e64 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -178,8 +178,12 @@ private: RUN_DEBUG_NAVIGATION, RUN_DEPLOY_REMOTE_DEBUG, RUN_RELOAD_SCRIPTS, + RUN_VCS_SETTINGS, + RUN_VCS_SHUT_DOWN, SETTINGS_UPDATE_CONTINUOUSLY, SETTINGS_UPDATE_WHEN_CHANGED, + SETTINGS_UPDATE_ALWAYS, + SETTINGS_UPDATE_CHANGES, SETTINGS_UPDATE_SPINNER_HIDE, SETTINGS_PREFERENCES, SETTINGS_LAYOUT_SAVE, @@ -322,6 +326,7 @@ private: EditorSettingsDialog *settings_config_dialog; RunSettingsDialog *run_settings_dialog; ProjectSettingsEditor *project_settings; + PopupMenu *vcs_actions_menu; EditorFileDialog *file; ExportTemplateManager *export_template_manager; EditorFeatureProfileManager *feature_profile_manager; @@ -477,6 +482,7 @@ private: void _get_scene_metadata(const String &p_file); void _update_title(); void _update_scene_tabs(); + void _version_control_menu_option(int p_idx); void _close_messages(); void _show_messages(); void _vp_resized(); diff --git a/editor/editor_path.cpp b/editor/editor_path.cpp index 23d28261d1..12510e27de 100644 --- a/editor/editor_path.cpp +++ b/editor/editor_path.cpp @@ -78,9 +78,6 @@ void EditorPath::_about_to_show() { } void EditorPath::update_path() { - set_text(""); - set_tooltip(""); - set_icon(NULL); for (int i = 0; i < history->get_path_size(); i++) { diff --git a/editor/editor_resource_preview.cpp b/editor/editor_resource_preview.cpp index 4a7a9fb863..5c15ebb1eb 100644 --- a/editor/editor_resource_preview.cpp +++ b/editor/editor_resource_preview.cpp @@ -295,8 +295,9 @@ void EditorResourcePreview::_thread() { //update modified time f = FileAccess::open(file, FileAccess::WRITE); - f->store_line(itos(modtime)); + f->store_line(itos(thumbnail_size)); f->store_line(itos(has_small_texture)); + f->store_line(itos(modtime)); f->store_line(md5); memdelete(f); } diff --git a/editor/editor_run.cpp b/editor/editor_run.cpp index e4e32b2ce0..7b5ec9e772 100644 --- a/editor/editor_run.cpp +++ b/editor/editor_run.cpp @@ -37,7 +37,8 @@ EditorRun::Status EditorRun::get_status() const { return status; } -Error EditorRun::run(const String &p_scene, const String &p_custom_args, const List<String> &p_breakpoints) { + +Error EditorRun::run(const String &p_scene, const String &p_custom_args, const List<String> &p_breakpoints, const bool &p_skip_breakpoints) { List<String> args; @@ -162,6 +163,10 @@ Error EditorRun::run(const String &p_scene, const String &p_custom_args, const L args.push_back(bpoints); } + if (p_skip_breakpoints) { + args.push_back("--skip-breakpoints"); + } + if (p_scene != "") { args.push_back(p_scene); } diff --git a/editor/editor_run.h b/editor/editor_run.h index 9127c62030..42724630b5 100644 --- a/editor/editor_run.h +++ b/editor/editor_run.h @@ -51,7 +51,7 @@ private: public: Status get_status() const; - Error run(const String &p_scene, const String &p_custom_args, const List<String> &p_breakpoints); + Error run(const String &p_scene, const String &p_custom_args, const List<String> &p_breakpoints, const bool &p_skip_breakpoints = false); void run_native_notify() { status = STATUS_PLAY; } void stop(); diff --git a/editor/editor_vcs_interface.cpp b/editor/editor_vcs_interface.cpp new file mode 100644 index 0000000000..8da1777871 --- /dev/null +++ b/editor/editor_vcs_interface.cpp @@ -0,0 +1,203 @@ +/*************************************************************************/ +/* editor_vcs_interface.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2019 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 "editor_vcs_interface.h" + +EditorVCSInterface *EditorVCSInterface::singleton = NULL; + +void EditorVCSInterface::_bind_methods() { + + // Proxy end points that act as fallbacks to unavailability of a function in the VCS addon + ClassDB::bind_method(D_METHOD("_initialize", "project_root_path"), &EditorVCSInterface::_initialize); + ClassDB::bind_method(D_METHOD("_get_is_vcs_intialized"), &EditorVCSInterface::_get_is_vcs_intialized); + ClassDB::bind_method(D_METHOD("_get_vcs_name"), &EditorVCSInterface::_get_vcs_name); + ClassDB::bind_method(D_METHOD("_shut_down"), &EditorVCSInterface::_shut_down); + ClassDB::bind_method(D_METHOD("_get_project_name"), &EditorVCSInterface::_get_project_name); + ClassDB::bind_method(D_METHOD("_get_modified_files_data"), &EditorVCSInterface::_get_modified_files_data); + ClassDB::bind_method(D_METHOD("_commit", "msg"), &EditorVCSInterface::_commit); + ClassDB::bind_method(D_METHOD("_get_file_diff", "file_path"), &EditorVCSInterface::_get_file_diff); + ClassDB::bind_method(D_METHOD("_stage_file", "file_path"), &EditorVCSInterface::_stage_file); + ClassDB::bind_method(D_METHOD("_unstage_file", "file_path"), &EditorVCSInterface::_unstage_file); + + ClassDB::bind_method(D_METHOD("is_addon_ready"), &EditorVCSInterface::is_addon_ready); + + // API methods that redirect calls to the proxy end points + ClassDB::bind_method(D_METHOD("initialize", "project_root_path"), &EditorVCSInterface::initialize); + ClassDB::bind_method(D_METHOD("get_is_vcs_intialized"), &EditorVCSInterface::get_is_vcs_intialized); + ClassDB::bind_method(D_METHOD("get_modified_files_data"), &EditorVCSInterface::get_modified_files_data); + ClassDB::bind_method(D_METHOD("stage_file", "file_path"), &EditorVCSInterface::stage_file); + ClassDB::bind_method(D_METHOD("unstage_file", "file_path"), &EditorVCSInterface::unstage_file); + ClassDB::bind_method(D_METHOD("commit", "msg"), &EditorVCSInterface::commit); + ClassDB::bind_method(D_METHOD("get_file_diff", "file_path"), &EditorVCSInterface::get_file_diff); + ClassDB::bind_method(D_METHOD("shut_down"), &EditorVCSInterface::shut_down); + ClassDB::bind_method(D_METHOD("get_project_name"), &EditorVCSInterface::get_project_name); + ClassDB::bind_method(D_METHOD("get_vcs_name"), &EditorVCSInterface::get_vcs_name); +} + +bool EditorVCSInterface::_initialize(String p_project_root_path) { + + WARN_PRINT("Selected VCS addon does not implement an initialization function. This warning will be suppressed.") + return true; +} + +bool EditorVCSInterface::_get_is_vcs_intialized() { + + return false; +} + +Dictionary EditorVCSInterface::_get_modified_files_data() { + + return Dictionary(); +} + +void EditorVCSInterface::_stage_file(String p_file_path) { + + return; +} + +void EditorVCSInterface::_unstage_file(String p_file_path) { + + return; +} + +void EditorVCSInterface::_commit(String p_msg) { + + return; +} + +Array EditorVCSInterface::_get_file_diff(String p_file_path) { + + return Array(); +} + +bool EditorVCSInterface::_shut_down() { + + return false; +} + +String EditorVCSInterface::_get_project_name() { + + return String(); +} + +String EditorVCSInterface::_get_vcs_name() { + + return ""; +} + +bool EditorVCSInterface::initialize(String p_project_root_path) { + + is_initialized = call("_initialize", p_project_root_path); + return is_initialized; +} + +bool EditorVCSInterface::get_is_vcs_intialized() { + + return call("_get_is_vcs_intialized"); +} + +Dictionary EditorVCSInterface::get_modified_files_data() { + + return call("_get_modified_files_data"); +} + +void EditorVCSInterface::stage_file(String p_file_path) { + + if (is_addon_ready()) { + + call("_stage_file", p_file_path); + } + return; +} + +void EditorVCSInterface::unstage_file(String p_file_path) { + + if (is_addon_ready()) { + + call("_unstage_file", p_file_path); + } + return; +} + +bool EditorVCSInterface::is_addon_ready() { + + return is_initialized; +} + +void EditorVCSInterface::commit(String p_msg) { + + if (is_addon_ready()) { + + call("_commit", p_msg); + } + return; +} + +Array EditorVCSInterface::get_file_diff(String p_file_path) { + + if (is_addon_ready()) { + + return call("_get_file_diff", p_file_path); + } + return Array(); +} + +bool EditorVCSInterface::shut_down() { + + return call("_shut_down"); +} + +String EditorVCSInterface::get_project_name() { + + return call("_get_project_name"); +} + +String EditorVCSInterface::get_vcs_name() { + + return call("_get_vcs_name"); +} + +EditorVCSInterface::EditorVCSInterface() { + + is_initialized = false; +} + +EditorVCSInterface::~EditorVCSInterface() { +} + +EditorVCSInterface *EditorVCSInterface::get_singleton() { + + return singleton; +} + +void EditorVCSInterface::set_singleton(EditorVCSInterface *p_singleton) { + + singleton = p_singleton; +} diff --git a/editor/editor_vcs_interface.h b/editor/editor_vcs_interface.h new file mode 100644 index 0000000000..896193ed92 --- /dev/null +++ b/editor/editor_vcs_interface.h @@ -0,0 +1,83 @@ +/*************************************************************************/ +/* editor_vcs_interface.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2019 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 EDITOR_VCS_INTERFACE_H +#define EDITOR_VCS_INTERFACE_H + +#include "core/object.h" +#include "core/ustring.h" +#include "scene/gui/panel_container.h" + +class EditorVCSInterface : public Object { + + GDCLASS(EditorVCSInterface, Object) + + bool is_initialized; + +protected: + static EditorVCSInterface *singleton; + + static void _bind_methods(); + + // Implemented by addons as end points for the proxy functions + bool _initialize(String p_project_root_path); + bool _get_is_vcs_intialized(); + Dictionary _get_modified_files_data(); + void _stage_file(String p_file_path); + void _unstage_file(String p_file_path); + void _commit(String p_msg); + Array _get_file_diff(String p_file_path); + bool _shut_down(); + String _get_project_name(); + String _get_vcs_name(); + +public: + static EditorVCSInterface *get_singleton(); + static void set_singleton(EditorVCSInterface *p_singleton); + + bool is_addon_ready(); + + // Proxy functions to the editor for use + bool initialize(String p_project_root_path); + bool get_is_vcs_intialized(); + Dictionary get_modified_files_data(); + void stage_file(String p_file_path); + void unstage_file(String p_file_path); + void commit(String p_msg); + Array get_file_diff(String p_file_path); + bool shut_down(); + String get_project_name(); + String get_vcs_name(); + + EditorVCSInterface(); + virtual ~EditorVCSInterface(); +}; + +#endif // !EDITOR_VCS_INTERFACE_H diff --git a/editor/icons/icon_debug_skip_breakpoints_off.svg b/editor/icons/icon_debug_skip_breakpoints_off.svg new file mode 100644 index 0000000000..2a0b949aa9 --- /dev/null +++ b/editor/icons/icon_debug_skip_breakpoints_off.svg @@ -0,0 +1,89 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + width="17" + height="17" + version="1.1" + viewBox="0 0 17 17" + id="svg3801" + sodipodi:docname="icon_debug_skip_breakpoints_off.svg" + inkscape:version="0.92.3 (2405546, 2018-03-11)"> + <metadata + id="metadata3807"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title /> + </cc:Work> + </rdf:RDF> + </metadata> + <defs + id="defs3805" /> + <sodipodi:namedview + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1" + objecttolerance="10" + gridtolerance="10" + guidetolerance="10" + inkscape:pageopacity="0" + inkscape:pageshadow="2" + inkscape:window-width="1887" + inkscape:window-height="2103" + id="namedview3803" + showgrid="false" + inkscape:measure-start="15.5563,28.7373" + inkscape:measure-end="0,0" + inkscape:zoom="32" + inkscape:cx="8.5156226" + inkscape:cy="-9.0970543" + inkscape:window-x="1953" + inkscape:window-y="27" + inkscape:window-maximized="0" + inkscape:current-layer="svg3801" /> + <path + id="path3835" + sodipodi:type="arc" + sodipodi:cx="3.2790968" + sodipodi:cy="3.006855" + sodipodi:rx="1.6192284" + sodipodi:ry="1.3289529" + sodipodi:start="0" + sodipodi:end="0.0073006075" + sodipodi:open="true" + d="m 4.8983252,3.006855 a 1.6192284,1.3289529 0 0 1 -4.31e-5,0.0097" + style="fill:#000000;stroke-width:0.62631863" /> + <path + style="fill:#000000;stroke-width:0.62631863" + id="path3837" + sodipodi:type="arc" + sodipodi:cx="6.233613" + sodipodi:cy="5.0553513" + sodipodi:rx="2.563139" + sodipodi:ry="3.6270869" + sodipodi:start="0" + sodipodi:end="0.0073006075" + sodipodi:open="true" + d="m 8.796752,5.0553513 a 2.563139,3.6270869 0 0 1 -6.83e-5,0.02648" /> + <path + style="fill:#ff8585;fill-opacity:0.99607843;stroke-width:1.01912296" + id="path3839" + sodipodi:type="arc" + sodipodi:cx="8.4689026" + sodipodi:cy="8.479969" + sodipodi:rx="6.1594577" + sodipodi:ry="6.0545759" + sodipodi:start="5.5685493" + sodipodi:end="5.2409356" + d="M 13.121337,4.512148 A 6.1594577,6.0545759 0 0 1 12.87255,12.713238 6.1594577,6.0545759 0 0 1 4.5370096,13.140453 6.1594577,6.0545759 0 0 1 3.4219038,5.0092664 6.1594577,6.0545759 0 0 1 11.574987,3.2515951" + sodipodi:open="true" /> +</svg> diff --git a/editor/icons/icon_debug_skip_breakpoints_on.svg b/editor/icons/icon_debug_skip_breakpoints_on.svg new file mode 100644 index 0000000000..186778a1b4 --- /dev/null +++ b/editor/icons/icon_debug_skip_breakpoints_on.svg @@ -0,0 +1,106 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + width="17" + height="17" + version="1.1" + viewBox="0 0 17 17" + id="svg3801" + sodipodi:docname="icon_debug_skip_breakpoints_on.svg" + inkscape:version="0.92.3 (2405546, 2018-03-11)"> + <metadata + id="metadata3807"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title></dc:title> + </cc:Work> + </rdf:RDF> + </metadata> + <defs + id="defs3805" /> + <sodipodi:namedview + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1" + objecttolerance="10" + gridtolerance="10" + guidetolerance="10" + inkscape:pageopacity="0" + inkscape:pageshadow="2" + inkscape:window-width="1887" + inkscape:window-height="2105" + id="namedview3803" + showgrid="false" + inkscape:measure-start="15.5563,28.7373" + inkscape:measure-end="0,0" + inkscape:zoom="40.96" + inkscape:cx="12.825686" + inkscape:cy="-5.1961973" + inkscape:window-x="1953" + inkscape:window-y="27" + inkscape:window-maximized="0" + inkscape:current-layer="layer1" /> + <g + inkscape:groupmode="layer" + id="layer1" + inkscape:label="bg" /> + <g + inkscape:groupmode="layer" + id="layer2" + inkscape:label="fg"> + <path + id="path3835" + sodipodi:type="arc" + sodipodi:cx="3.2790968" + sodipodi:cy="3.006855" + sodipodi:rx="1.6192284" + sodipodi:ry="1.3289529" + sodipodi:start="0" + sodipodi:end="0.0073006075" + sodipodi:open="true" + d="m 4.8983252,3.006855 a 1.6192284,1.3289529 0 0 1 -4.31e-5,0.0097" + style="fill:#000000;stroke-width:0.62631863" /> + <path + style="fill:#000000;stroke-width:0.62631863" + id="path3837" + sodipodi:type="arc" + sodipodi:cx="6.233613" + sodipodi:cy="5.0553513" + sodipodi:rx="2.563139" + sodipodi:ry="3.6270869" + sodipodi:start="0" + sodipodi:end="0.0073006075" + sodipodi:open="true" + d="m 8.796752,5.0553513 a 2.563139,3.6270869 0 0 1 -6.83e-5,0.02648" /> + <path + style="fill:#ff8585;fill-opacity:0.99607843;stroke-width:1.01912296" + id="path3839" + sodipodi:type="arc" + sodipodi:cx="8.4689026" + sodipodi:cy="8.479969" + sodipodi:rx="6.1594577" + sodipodi:ry="6.0545759" + sodipodi:start="5.5685493" + sodipodi:end="5.2409356" + d="M 13.121337,4.512148 A 6.1594577,6.0545759 0 0 1 12.87255,12.713238 6.1594577,6.0545759 0 0 1 4.5370096,13.140453 6.1594577,6.0545759 0 0 1 3.4219038,5.0092664 6.1594577,6.0545759 0 0 1 11.574987,3.2515951" + sodipodi:open="true" /> + <rect + style="fill:#e0e0e0;fill-opacity:1;stroke-width:1.1873318" + id="rect5375" + width="18.575495" + height="2.5187109" + x="-9.2906752" + y="10.816157" + transform="matrix(0.70605846,-0.70815355,0.70605846,0.70815355,0,0)" /> + </g> +</svg> diff --git a/editor/import/resource_importer_csv.cpp b/editor/import/resource_importer_csv.cpp new file mode 100644 index 0000000000..64b5309cab --- /dev/null +++ b/editor/import/resource_importer_csv.cpp @@ -0,0 +1,80 @@ +/*************************************************************************/ +/* resource_importer_csv.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2019 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 "resource_importer_csv.h" + +#include "core/io/resource_saver.h" +#include "core/os/file_access.h" + +String ResourceImporterCSV::get_importer_name() const { + + return "csv"; +} + +String ResourceImporterCSV::get_visible_name() const { + + return "CSV"; +} +void ResourceImporterCSV::get_recognized_extensions(List<String> *p_extensions) const { + + p_extensions->push_back("csv"); +} + +String ResourceImporterCSV::get_save_extension() const { + return ""; //does not save a single resource +} + +String ResourceImporterCSV::get_resource_type() const { + + return "TextFile"; +} + +bool ResourceImporterCSV::get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const { + + return true; +} + +int ResourceImporterCSV::get_preset_count() const { + return 0; +} +String ResourceImporterCSV::get_preset_name(int p_idx) const { + + return ""; +} + +void ResourceImporterCSV::get_import_options(List<ImportOption> *r_options, int p_preset) const { +} + +Error ResourceImporterCSV::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) { + return OK; +} + +ResourceImporterCSV::ResourceImporterCSV() { +} diff --git a/editor/import/resource_importer_csv.h b/editor/import/resource_importer_csv.h new file mode 100644 index 0000000000..7d06bdb188 --- /dev/null +++ b/editor/import/resource_importer_csv.h @@ -0,0 +1,57 @@ +/*************************************************************************/ +/* resource_importer_csv.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2019 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 RESOURCEIMPORTERCSV_H +#define RESOURCEIMPORTERCSV_H + +#include "core/io/resource_importer.h" + +class ResourceImporterCSV : public ResourceImporter { + GDCLASS(ResourceImporterCSV, ResourceImporter); + +public: + virtual String get_importer_name() const; + virtual String get_visible_name() const; + virtual void get_recognized_extensions(List<String> *p_extensions) const; + virtual String get_save_extension() const; + virtual String get_resource_type() const; + + virtual int get_preset_count() const; + virtual String get_preset_name(int p_idx) const; + + virtual void get_import_options(List<ImportOption> *r_options, int p_preset = 0) const; + virtual bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const; + + virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = NULL, Variant *r_metadata = NULL); + + ResourceImporterCSV(); +}; + +#endif // RESOURCEIMPORTERCSV_H diff --git a/editor/inspector_dock.cpp b/editor/inspector_dock.cpp index 8a0812973f..8ba7d9fba7 100644 --- a/editor/inspector_dock.cpp +++ b/editor/inspector_dock.cpp @@ -408,6 +408,10 @@ void InspectorDock::update(Object *p_object) { warning->hide(); search->set_editable(false); + editor_path->set_text(""); + editor_path->set_tooltip(""); + editor_path->set_icon(NULL); + return; } diff --git a/editor/plugins/asset_library_editor_plugin.cpp b/editor/plugins/asset_library_editor_plugin.cpp index 60b5f017d2..3d161dc5b9 100644 --- a/editor/plugins/asset_library_editor_plugin.cpp +++ b/editor/plugins/asset_library_editor_plugin.cpp @@ -578,7 +578,6 @@ void EditorAssetLibrary::_notification(int p_what) { case NOTIFICATION_READY: { error_tr->set_texture(get_icon("Error", "EditorIcons")); - reverse->set_icon(get_icon("Sort", "EditorIcons")); filter->set_right_icon(get_icon("Search", "EditorIcons")); filter->set_clear_button_enabled(true); @@ -612,7 +611,6 @@ void EditorAssetLibrary::_notification(int p_what) { library_scroll_bg->add_style_override("panel", get_stylebox("bg", "Tree")); downloads_scroll->add_style_override("bg", get_stylebox("bg", "Tree")); error_tr->set_texture(get_icon("Error", "EditorIcons")); - reverse->set_icon(get_icon("Sort", "EditorIcons")); filter->set_right_icon(get_icon("Search", "EditorIcons")); filter->set_clear_button_enabled(true); } break; @@ -645,23 +643,27 @@ void EditorAssetLibrary::_install_asset() { } const char *EditorAssetLibrary::sort_key[SORT_MAX] = { - "downloads", + "updated", + "updated", "name", + "name", + "cost", "cost", - "updated" }; const char *EditorAssetLibrary::sort_text[SORT_MAX] = { - "Downloads", - "Name", - "License", // "cost" stores the SPDX license name in the Godot Asset Library. - "Updated" + "Recently Updated", + "Least Recently Updated", + "Name (A-Z)", + "Name (Z-A)", + "License (A-Z)", // "cost" stores the SPDX license name in the Godot Asset Library. + "License (Z-A)", // "cost" stores the SPDX license name in the Godot Asset Library. }; const char *EditorAssetLibrary::support_key[SUPPORT_MAX] = { "official", "community", - "testing" + "testing", }; void EditorAssetLibrary::_select_author(int p_id) { @@ -928,8 +930,8 @@ void EditorAssetLibrary::_search(int p_page) { args += "&category=" + itos(categories->get_item_metadata(categories->get_selected())); } - if (reverse->is_pressed()) { - + // Sorting options with an odd index are always the reverse of the previous one + if (sort->get_selected() % 2 == 1) { args += "&reverse=true"; } @@ -1381,12 +1383,6 @@ EditorAssetLibrary::EditorAssetLibrary(bool p_templates_only) { sort->set_h_size_flags(SIZE_EXPAND_FILL); sort->connect("item_selected", this, "_rerun_search"); - reverse = memnew(ToolButton); - reverse->set_toggle_mode(true); - reverse->connect("toggled", this, "_rerun_search"); - reverse->set_tooltip(TTR("Reverse sorting.")); - search_hb2->add_child(reverse); - search_hb2->add_child(memnew(VSeparator)); search_hb2->add_child(memnew(Label(TTR("Category:") + " "))); diff --git a/editor/plugins/asset_library_editor_plugin.h b/editor/plugins/asset_library_editor_plugin.h index 6a3158889e..7e934ac6cb 100644 --- a/editor/plugins/asset_library_editor_plugin.h +++ b/editor/plugins/asset_library_editor_plugin.h @@ -190,7 +190,6 @@ class EditorAssetLibrary : public PanelContainer { OptionButton *categories; OptionButton *repository; OptionButton *sort; - ToolButton *reverse; Button *search; HBoxContainer *error_hb; TextureRect *error_tr; @@ -216,10 +215,12 @@ class EditorAssetLibrary : public PanelContainer { }; enum SortOrder { - SORT_DOWNLOADS, + SORT_UPDATED, + SORT_UPDATED_REVERSE, SORT_NAME, + SORT_NAME_REVERSE, SORT_COST, - SORT_UPDATED, + SORT_COST_REVERSE, SORT_MAX }; diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 413843d536..8b6bab374c 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -538,6 +538,10 @@ void ScriptEditor::_open_recent_script(int p_idx) { // if it's a path then it's most likely a deleted file not help } else if (path.find("::") != -1) { // built-in script + String scene_path = path.get_slice("::", 0); + if (!EditorNode::get_singleton()->is_scene_open(scene_path)) { + EditorNode::get_singleton()->load_scene(scene_path); + } Ref<Script> script = ResourceLoader::load(path); if (script.is_valid()) { edit(script, true); diff --git a/editor/plugins/version_control_editor_plugin.cpp b/editor/plugins/version_control_editor_plugin.cpp new file mode 100644 index 0000000000..c059977487 --- /dev/null +++ b/editor/plugins/version_control_editor_plugin.cpp @@ -0,0 +1,595 @@ +/*************************************************************************/ +/* version_control_editor_plugin.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2019 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 "version_control_editor_plugin.h" +#include "core/script_language.h" +#include "editor/editor_file_system.h" +#include "editor/editor_node.h" + +VersionControlEditorPlugin *VersionControlEditorPlugin::singleton = NULL; + +void VersionControlEditorPlugin::_bind_methods() { + + ClassDB::bind_method(D_METHOD("_selected_a_vcs"), &VersionControlEditorPlugin::_selected_a_vcs); + ClassDB::bind_method(D_METHOD("_initialize_vcs"), &VersionControlEditorPlugin::_initialize_vcs); + ClassDB::bind_method(D_METHOD("_send_commit_msg"), &VersionControlEditorPlugin::_send_commit_msg); + ClassDB::bind_method(D_METHOD("_refresh_stage_area"), &VersionControlEditorPlugin::_refresh_stage_area); + ClassDB::bind_method(D_METHOD("_stage_all"), &VersionControlEditorPlugin::_stage_all); + ClassDB::bind_method(D_METHOD("_stage_selected"), &VersionControlEditorPlugin::_stage_selected); + ClassDB::bind_method(D_METHOD("_view_file_diff"), &VersionControlEditorPlugin::_view_file_diff); + ClassDB::bind_method(D_METHOD("_refresh_file_diff"), &VersionControlEditorPlugin::_refresh_file_diff); + ClassDB::bind_method(D_METHOD("popup_vcs_set_up_dialog"), &VersionControlEditorPlugin::popup_vcs_set_up_dialog); + + // Used to track the status of files in the staging area + BIND_ENUM_CONSTANT(CHANGE_TYPE_NEW); + BIND_ENUM_CONSTANT(CHANGE_TYPE_MODIFIED); + BIND_ENUM_CONSTANT(CHANGE_TYPE_RENAMED); + BIND_ENUM_CONSTANT(CHANGE_TYPE_DELETED); + BIND_ENUM_CONSTANT(CHANGE_TYPE_TYPECHANGE); +} + +void VersionControlEditorPlugin::_selected_a_vcs(int p_id) { + + List<StringName> available_addons = get_available_vcs_names(); + const StringName selected_vcs = set_up_choice->get_item_text(p_id); + + if (available_addons.find(selected_vcs) != NULL) { + + set_up_init_button->set_disabled(false); + } else { + + set_up_init_button->set_disabled(true); + } +} + +void VersionControlEditorPlugin::_populate_available_vcs_names() { + + static bool called = false; + + if (!called) { + + set_up_choice->add_item("Select an available VCS"); + + fetch_available_vcs_addon_names(); + List<StringName> available_addons = get_available_vcs_names(); + for (int i = 0; i < available_addons.size(); i++) { + + set_up_choice->add_item(available_addons[i]); + } + + called = true; + } +} + +VersionControlEditorPlugin *VersionControlEditorPlugin::get_singleton() { + + return singleton ? singleton : memnew(VersionControlEditorPlugin); +} + +void VersionControlEditorPlugin::popup_vcs_set_up_dialog(const Control *p_gui_base) { + + Size2 popup_size = Size2(400, 100); + Size2 window_size = p_gui_base->get_viewport_rect().size; + popup_size.x = MIN(window_size.x * 0.5, popup_size.x); + popup_size.y = MIN(window_size.y * 0.5, popup_size.y); + + if (get_is_vcs_intialized()) { + + set_up_init_button->set_disabled(true); + } + + _populate_available_vcs_names(); + + set_up_dialog->popup_centered_clamped(popup_size * EDSCALE); +} + +void VersionControlEditorPlugin::_initialize_vcs() { + + register_editor(); + + if (EditorVCSInterface::get_singleton()) { + + ERR_EXPLAIN(EditorVCSInterface::get_singleton()->get_vcs_name() + " is already active"); + return; + } + + int id = set_up_choice->get_selected_id(); + String selected_addon = set_up_choice->get_item_text(id); + + String path = ScriptServer::get_global_class_path(selected_addon); + Ref<Script> script = ResourceLoader::load(path); + if (!script.is_valid()) { + + ERR_EXPLAIN("VCS Addon path is invalid"); + } + + EditorVCSInterface *vcs_interface = memnew(EditorVCSInterface); + ScriptInstance *addon_script_instance = script->instance_create(vcs_interface); + if (!addon_script_instance) { + + ERR_FAIL_NULL(addon_script_instance); + return; + } + + // The addon is attached as a script to the VCS interface as a proxy end-point + vcs_interface->set_script_and_instance(script.get_ref_ptr(), addon_script_instance); + + EditorVCSInterface::set_singleton(vcs_interface); + EditorFileSystem::get_singleton()->connect("filesystem_changed", this, "_refresh_stage_area"); + + String res_dir = OS::get_singleton()->get_resource_dir(); + if (!EditorVCSInterface::get_singleton()->initialize(res_dir)) { + + ERR_EXPLAIN("VCS was not initialized"); + } + + _refresh_stage_area(); +} + +void VersionControlEditorPlugin::_send_commit_msg() { + + String msg = commit_message->get_text(); + if (msg == "") { + + commit_status->set_text(TTR("No commit message was provided")); + return; + } + + if (EditorVCSInterface::get_singleton()) { + + if (staged_files_count == 0) { + + commit_status->set_text(TTR("No files added to stage")); + return; + } + + EditorVCSInterface::get_singleton()->commit(msg); + + commit_message->set_text(""); + version_control_dock_button->set_pressed(false); + } else { + + WARN_PRINT("No VCS addon is initialized. Select a Version Control Addon from Project menu"); + } + + _update_commit_status(); + _refresh_stage_area(); + _clear_file_diff(); +} + +void VersionControlEditorPlugin::_refresh_stage_area() { + + if (EditorVCSInterface::get_singleton()) { + + staged_files_count = 0; + clear_stage_area(); + + Dictionary modified_file_paths = EditorVCSInterface::get_singleton()->get_modified_files_data(); + String file_path; + for (int i = 0; i < modified_file_paths.size(); i++) { + + file_path = modified_file_paths.get_key_at_index(i); + TreeItem *found = stage_files->search_item_text(file_path, 0, true); + if (!found) { + + ChangeType change_index = (ChangeType)(int)modified_file_paths.get_value_at_index(i); + String change_text = file_path + " (" + change_type_to_strings[change_index] + ")"; + Color &change_color = change_type_to_color[change_index]; + TreeItem *new_item = stage_files->create_item(stage_files->get_root()); + new_item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK); + new_item->set_text(0, change_text); + new_item->set_metadata(0, file_path); + new_item->set_custom_color(0, change_color); + new_item->set_checked(0, true); + new_item->set_editable(0, true); + } else { + + if (found->get_metadata(0) == diff_file_name->get_text()) { + + _refresh_file_diff(); + } + } + commit_status->set_text("New changes detected"); + } + } else { + + WARN_PRINT("No VCS addon is initialized. Select a Version Control Addon from Project menu.") + } +} + +void VersionControlEditorPlugin::_stage_selected() { + + if (!EditorVCSInterface::get_singleton()) { + + WARN_PRINT("No VCS addon is initialized. Select a Version Control Addon from Project menu"); + return; + } + + staged_files_count = 0; + TreeItem *root = stage_files->get_root(); + if (root) { + + TreeItem *file_entry = root->get_children(); + while (file_entry) { + + if (file_entry->is_checked(0)) { + + EditorVCSInterface::get_singleton()->stage_file(file_entry->get_metadata(0)); + file_entry->set_icon_modulate(0, EditorNode::get_singleton()->get_gui_base()->get_color("success_color", "Editor")); + staged_files_count++; + } else { + + EditorVCSInterface::get_singleton()->unstage_file(file_entry->get_metadata(0)); + file_entry->set_icon_modulate(0, EditorNode::get_singleton()->get_gui_base()->get_color("error_color", "Editor")); + } + + file_entry = file_entry->get_next(); + } + } + + _update_stage_status(); +} + +void VersionControlEditorPlugin::_stage_all() { + + if (!EditorVCSInterface::get_singleton()) { + + WARN_PRINT("No VCS addon is initialized. Select a Version Control Addon from Project menu"); + return; + } + + staged_files_count = 0; + TreeItem *root = stage_files->get_root(); + if (root) { + + TreeItem *file_entry = root->get_children(); + while (file_entry) { + + EditorVCSInterface::get_singleton()->stage_file(file_entry->get_metadata(0)); + file_entry->set_icon_modulate(0, EditorNode::get_singleton()->get_gui_base()->get_color("success_color", "Editor")); + file_entry->set_checked(0, true); + staged_files_count++; + + file_entry = file_entry->get_next(); + } + } + + _update_stage_status(); +} + +void VersionControlEditorPlugin::_view_file_diff() { + + version_control_dock_button->set_pressed(true); + + String file_path = stage_files->get_selected()->get_metadata(0); + + _display_file_diff(file_path); +} + +void VersionControlEditorPlugin::_display_file_diff(String p_file_path) { + + Array diff_content = EditorVCSInterface::get_singleton()->get_file_diff(p_file_path); + + diff_file_name->set_text(p_file_path); + + diff->clear(); + diff->push_font(EditorNode::get_singleton()->get_gui_base()->get_font("source", "EditorFonts")); + for (int i = 0; i < diff_content.size(); i++) { + + Dictionary line_result = diff_content[i]; + + if (line_result["status"] == "+") { + + diff->push_color(EditorNode::get_singleton()->get_gui_base()->get_color("success_color", "Editor")); + } else if (line_result["status"] == "-") { + + diff->push_color(EditorNode::get_singleton()->get_gui_base()->get_color("error_color", "Editor")); + } else { + + diff->push_color(EditorNode::get_singleton()->get_gui_base()->get_color("font_color", "Label")); + } + + diff->add_text((String)line_result["content"]); + + diff->pop(); + } + diff->pop(); +} + +void VersionControlEditorPlugin::_refresh_file_diff() { + + String open_file = diff_file_name->get_text(); + if (open_file != "") { + + _display_file_diff(diff_file_name->get_text()); + } +} + +void VersionControlEditorPlugin::_clear_file_diff() { + + diff->clear(); + diff_file_name->set_text(""); + version_control_dock_button->set_pressed(false); +} + +void VersionControlEditorPlugin::_update_stage_status() { + + String status; + if (staged_files_count == 1) { + + status = "Stage contains 1 file"; + } else { + + status = "Stage contains " + String::num_int64(staged_files_count) + " files"; + } + commit_status->set_text(status); +} + +void VersionControlEditorPlugin::_update_commit_status() { + + String status; + if (staged_files_count == 1) { + + status = "Committed 1 file"; + } else { + + status = "Committed " + String::num_int64(staged_files_count) + " files "; + } + commit_status->set_text(status); + staged_files_count = 0; +} + +void VersionControlEditorPlugin::register_editor() { + + if (!EditorVCSInterface::get_singleton()) { + + EditorNode::get_singleton()->add_control_to_dock(EditorNode::DOCK_SLOT_RIGHT_UL, version_commit_dock); + TabContainer *dock_vbc = (TabContainer *)version_commit_dock->get_parent_control(); + dock_vbc->set_tab_title(version_commit_dock->get_index(), TTR("Commit")); + + ToolButton *vc = EditorNode::get_singleton()->add_bottom_panel_item(TTR("Version Control"), version_control_dock); + set_version_control_tool_button(vc); + } +} + +void VersionControlEditorPlugin::fetch_available_vcs_addon_names() { + + ScriptServer::get_global_class_list(&available_addons); +} + +void VersionControlEditorPlugin::clear_stage_area() { + + stage_files->get_root()->clear_children(); +} + +void VersionControlEditorPlugin::shut_down() { + + if (EditorVCSInterface::get_singleton()) { + + EditorFileSystem::get_singleton()->disconnect("filesystem_changed", this, "_refresh_stage_area"); + EditorVCSInterface::get_singleton()->shut_down(); + memdelete(EditorVCSInterface::get_singleton()); + EditorVCSInterface::set_singleton(NULL); + + EditorNode::get_singleton()->remove_control_from_dock(version_commit_dock); + EditorNode::get_singleton()->remove_bottom_panel_item(version_control_dock); + } +} + +bool VersionControlEditorPlugin::get_is_vcs_intialized() const { + + return EditorVCSInterface::get_singleton() ? EditorVCSInterface::get_singleton()->get_is_vcs_intialized() : false; +} + +const String VersionControlEditorPlugin::get_vcs_name() const { + + return EditorVCSInterface::get_singleton() ? EditorVCSInterface::get_singleton()->get_vcs_name() : ""; +} + +VersionControlEditorPlugin::VersionControlEditorPlugin() { + + singleton = this; + staged_files_count = 0; + + version_control_actions = memnew(PopupMenu); + version_control_actions->set_v_size_flags(BoxContainer::SIZE_SHRINK_CENTER); + + set_up_dialog = memnew(AcceptDialog); + set_up_dialog->set_title(TTR("Set Up Version Control")); + set_up_dialog->set_custom_minimum_size(Size2(400, 100)); + version_control_actions->add_child(set_up_dialog); + + set_up_ok_button = set_up_dialog->get_ok(); + set_up_ok_button->set_disabled(false); + set_up_ok_button->set_text(TTR("Close")); + + set_up_vbc = memnew(VBoxContainer); + set_up_vbc->set_alignment(VBoxContainer::ALIGN_CENTER); + set_up_dialog->add_child(set_up_vbc); + + set_up_hbc = memnew(HBoxContainer); + set_up_hbc->set_h_size_flags(HBoxContainer::SIZE_EXPAND_FILL); + set_up_vbc->add_child(set_up_hbc); + + set_up_vcs_status = memnew(RichTextLabel); + set_up_vcs_status->set_text(TTR("VCS Addon is not initialized")); + set_up_vbc->add_child(set_up_vcs_status); + + set_up_vcs_label = memnew(Label); + set_up_vcs_label->set_text(TTR("Version Control System")); + set_up_hbc->add_child(set_up_vcs_label); + + set_up_choice = memnew(OptionButton); + set_up_choice->set_h_size_flags(HBoxContainer::SIZE_EXPAND_FILL); + set_up_choice->connect("item_selected", this, "_selected_a_vcs"); + set_up_hbc->add_child(set_up_choice); + + set_up_init_settings = NULL; + + set_up_init_button = memnew(Button); + set_up_init_button->set_disabled(true); + set_up_init_button->set_text(TTR("Initialize")); + set_up_init_button->connect("pressed", this, "_initialize_vcs"); + set_up_vbc->add_child(set_up_init_button); + + version_control_actions->set_v_size_flags(PopupMenu::SIZE_EXPAND_FILL); + version_control_actions->set_h_size_flags(PopupMenu::SIZE_EXPAND_FILL); + + version_commit_dock = memnew(VBoxContainer); + version_commit_dock->set_visible(false); + + commit_box_vbc = memnew(VBoxContainer); + commit_box_vbc->set_alignment(VBoxContainer::ALIGN_BEGIN); + commit_box_vbc->set_h_size_flags(VBoxContainer::SIZE_EXPAND_FILL); + commit_box_vbc->set_v_size_flags(VBoxContainer::SIZE_EXPAND_FILL); + version_commit_dock->add_child(commit_box_vbc); + + stage_tools = memnew(HSplitContainer); + stage_tools->set_dragger_visibility(SplitContainer::DRAGGER_HIDDEN_COLLAPSED); + commit_box_vbc->add_child(stage_tools); + + staging_area_label = memnew(Label); + staging_area_label->set_h_size_flags(Label::SIZE_EXPAND_FILL); + staging_area_label->set_text(TTR("Staging area")); + stage_tools->add_child(staging_area_label); + + refresh_button = memnew(Button); + refresh_button->set_tooltip(TTR("Detect new changes")); + refresh_button->set_text(TTR("Refresh")); + refresh_button->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("Reload", "EditorIcons")); + refresh_button->connect("pressed", this, "_refresh_stage_area"); + stage_tools->add_child(refresh_button); + + stage_files = memnew(Tree); + stage_files->set_h_size_flags(Tree::SIZE_EXPAND_FILL); + stage_files->set_v_size_flags(Tree::SIZE_EXPAND_FILL); + stage_files->set_columns(1); + stage_files->set_column_title(0, TTR("Changes")); + stage_files->set_column_titles_visible(true); + stage_files->set_allow_reselect(true); + stage_files->set_allow_rmb_select(true); + stage_files->set_select_mode(Tree::SelectMode::SELECT_MULTI); + stage_files->set_edit_checkbox_cell_only_when_checkbox_is_pressed(true); + stage_files->connect("cell_selected", this, "_view_file_diff"); + stage_files->create_item(); + stage_files->set_hide_root(true); + commit_box_vbc->add_child(stage_files); + + change_type_to_strings[CHANGE_TYPE_NEW] = TTR("New"); + change_type_to_strings[CHANGE_TYPE_MODIFIED] = TTR("Modified"); + change_type_to_strings[CHANGE_TYPE_RENAMED] = TTR("Renamed"); + change_type_to_strings[CHANGE_TYPE_DELETED] = TTR("Deleted"); + change_type_to_strings[CHANGE_TYPE_TYPECHANGE] = TTR("Typechange"); + + change_type_to_color[CHANGE_TYPE_NEW] = EditorNode::get_singleton()->get_gui_base()->get_color("success_color", "Editor"); + change_type_to_color[CHANGE_TYPE_MODIFIED] = EditorNode::get_singleton()->get_gui_base()->get_color("warning_color", "Editor"); + change_type_to_color[CHANGE_TYPE_RENAMED] = EditorNode::get_singleton()->get_gui_base()->get_color("disabled_font_color", "Editor"); + change_type_to_color[CHANGE_TYPE_DELETED] = EditorNode::get_singleton()->get_gui_base()->get_color("error_color", "Editor"); + change_type_to_color[CHANGE_TYPE_TYPECHANGE] = EditorNode::get_singleton()->get_gui_base()->get_color("font_color", "Editor"); + + stage_buttons = memnew(HSplitContainer); + stage_buttons->set_dragger_visibility(SplitContainer::DRAGGER_HIDDEN_COLLAPSED); + commit_box_vbc->add_child(stage_buttons); + + stage_selected_button = memnew(Button); + stage_selected_button->set_h_size_flags(Button::SIZE_EXPAND_FILL); + stage_selected_button->set_text(TTR("Stage Selected")); + stage_selected_button->connect("pressed", this, "_stage_selected"); + stage_buttons->add_child(stage_selected_button); + + stage_all_button = memnew(Button); + stage_all_button->set_text(TTR("Stage All")); + stage_all_button->connect("pressed", this, "_stage_all"); + stage_buttons->add_child(stage_all_button); + + commit_box_vbc->add_child(memnew(HSeparator)); + + commit_message = memnew(TextEdit); + commit_message->set_h_size_flags(Control::SIZE_EXPAND_FILL); + commit_message->set_h_grow_direction(Control::GrowDirection::GROW_DIRECTION_BEGIN); + commit_message->set_v_grow_direction(Control::GrowDirection::GROW_DIRECTION_END); + commit_message->set_custom_minimum_size(Size2(200, 100)); + commit_message->set_wrap_enabled(true); + commit_message->set_text(TTR("Add a commit message")); + commit_box_vbc->add_child(commit_message); + + commit_button = memnew(Button); + commit_button->set_text(TTR("Commit Changes")); + commit_button->connect("pressed", this, "_send_commit_msg"); + commit_box_vbc->add_child(commit_button); + + commit_status = memnew(Label); + commit_status->set_align(Label::ALIGN_CENTER); + commit_box_vbc->add_child(commit_status); + + version_control_dock = memnew(PanelContainer); + version_control_dock->set_v_size_flags(Control::SIZE_EXPAND_FILL); + version_control_dock->hide(); + + diff_vbc = memnew(VBoxContainer); + diff_vbc->set_h_size_flags(HBoxContainer::SIZE_FILL); + diff_vbc->set_v_size_flags(HBoxContainer::SIZE_FILL); + version_control_dock->add_child(diff_vbc); + + diff_hbc = memnew(HBoxContainer); + diff_hbc->set_h_size_flags(HBoxContainer::SIZE_FILL); + diff_vbc->add_child(diff_hbc); + + diff_heading = memnew(Label); + diff_heading->set_text(TTR("Status")); + diff_heading->set_tooltip(TTR("View file diffs before commiting them to the latest version")); + diff_hbc->add_child(diff_heading); + + diff_file_name = memnew(Label); + diff_file_name->set_text(TTR("No file diff is active")); + diff_file_name->set_h_size_flags(Label::SIZE_EXPAND_FILL); + diff_file_name->set_align(Label::ALIGN_RIGHT); + diff_hbc->add_child(diff_file_name); + + diff_refresh_button = memnew(Button); + diff_refresh_button->set_tooltip(TTR("Detect changes in file diff")); + diff_refresh_button->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("Reload", "EditorIcons")); + diff_refresh_button->connect("pressed", this, "_refresh_file_diff"); + diff_hbc->add_child(diff_refresh_button); + + diff = memnew(RichTextLabel); + diff->set_h_size_flags(TextEdit::SIZE_EXPAND_FILL); + diff->set_v_size_flags(TextEdit::SIZE_EXPAND_FILL); + diff->set_selection_enabled(true); + diff_vbc->add_child(diff); +} + +VersionControlEditorPlugin::~VersionControlEditorPlugin() { + + shut_down(); + memdelete(version_control_dock); + memdelete(version_commit_dock); + memdelete(version_control_actions); +} diff --git a/editor/plugins/version_control_editor_plugin.h b/editor/plugins/version_control_editor_plugin.h new file mode 100644 index 0000000000..450ebccce1 --- /dev/null +++ b/editor/plugins/version_control_editor_plugin.h @@ -0,0 +1,146 @@ +/*************************************************************************/ +/* version_control_editor_plugin.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2019 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 VERSION_CONTROL_EDITOR_PLUGIN_H +#define VERSION_CONTROL_EDITOR_PLUGIN_H + +#include "editor/editor_plugin.h" +#include "editor/editor_vcs_interface.h" +#include "scene/gui/container.h" +#include "scene/gui/rich_text_label.h" +#include "scene/gui/text_edit.h" +#include "scene/gui/tree.h" + +class VersionControlEditorPlugin : public EditorPlugin { + + GDCLASS(VersionControlEditorPlugin, EditorPlugin) + +public: + enum ChangeType { + + CHANGE_TYPE_NEW = 0, + CHANGE_TYPE_MODIFIED = 1, + CHANGE_TYPE_RENAMED = 2, + CHANGE_TYPE_DELETED = 3, + CHANGE_TYPE_TYPECHANGE = 4 + }; + +private: + static VersionControlEditorPlugin *singleton; + + int staged_files_count; + List<StringName> available_addons; + + PopupMenu *version_control_actions; + AcceptDialog *set_up_dialog; + VBoxContainer *set_up_vbc; + HBoxContainer *set_up_hbc; + Label *set_up_vcs_label; + OptionButton *set_up_choice; + PanelContainer *set_up_init_settings; + Button *set_up_init_button; + RichTextLabel *set_up_vcs_status; + Button *set_up_ok_button; + + HashMap<ChangeType, String> change_type_to_strings; + HashMap<ChangeType, Color> change_type_to_color; + + VBoxContainer *version_commit_dock; + VBoxContainer *commit_box_vbc; + HSplitContainer *stage_tools; + Tree *stage_files; + TreeItem *new_files; + TreeItem *modified_files; + TreeItem *renamed_files; + TreeItem *deleted_files; + TreeItem *typechange_files; + Label *staging_area_label; + HSplitContainer *stage_buttons; + Button *stage_all_button; + Button *stage_selected_button; + Button *refresh_button; + TextEdit *commit_message; + Button *commit_button; + Label *commit_status; + + PanelContainer *version_control_dock; + ToolButton *version_control_dock_button; + VBoxContainer *diff_vbc; + HBoxContainer *diff_hbc; + Button *diff_refresh_button; + Label *diff_file_name; + Label *diff_heading; + RichTextLabel *diff; + + void _populate_available_vcs_names(); + void _selected_a_vcs(int p_id); + void _initialize_vcs(); + void _send_commit_msg(); + void _refresh_stage_area(); + void _stage_selected(); + void _stage_all(); + void _view_file_diff(); + void _display_file_diff(String p_file_path); + void _refresh_file_diff(); + void _clear_file_diff(); + void _update_stage_status(); + void _update_commit_status(); + + friend class EditorVCSInterface; + +protected: + static void _bind_methods(); + +public: + static VersionControlEditorPlugin *get_singleton(); + + void popup_vcs_set_up_dialog(const Control *p_gui_base); + void set_version_control_tool_button(ToolButton *p_button) { version_control_dock_button = p_button; } + + PopupMenu *get_version_control_actions_panel() const { return version_control_actions; } + VBoxContainer *get_version_commit_dock() const { return version_commit_dock; } + PanelContainer *get_version_control_dock() const { return version_control_dock; } + + List<StringName> get_available_vcs_names() const { return available_addons; } + bool get_is_vcs_intialized() const; + const String get_vcs_name() const; + + void register_editor(); + void fetch_available_vcs_addon_names(); + void clear_stage_area(); + void shut_down(); + + VersionControlEditorPlugin(); + ~VersionControlEditorPlugin(); +}; + +VARIANT_ENUM_CAST(VersionControlEditorPlugin::ChangeType); + +#endif // !VERSION_CONTROL_EDITOR_PLUGIN_H diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index 6b338ca02b..82baa99da2 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -2367,6 +2367,7 @@ VisualShaderEditor::VisualShaderEditor() { add_options.push_back(AddOption("LessThanEqual", "Conditional", "Functions", "VisualShaderNodeCompare", vformat(compare_func_desc, TTR("Less Than or Equal (<=)")), VisualShaderNodeCompare::FUNC_LESS_THAN_EQUAL, VisualShaderNode::PORT_TYPE_BOOLEAN)); add_options.push_back(AddOption("NotEqual", "Conditional", "Functions", "VisualShaderNodeCompare", vformat(compare_func_desc, TTR("Not Equal (!=)")), VisualShaderNodeCompare::FUNC_NOT_EQUAL, VisualShaderNode::PORT_TYPE_BOOLEAN)); add_options.push_back(AddOption("Switch", "Conditional", "Functions", "VisualShaderNodeSwitch", TTR("Returns an associated vector if the provided boolean value is true or false."), -1, VisualShaderNode::PORT_TYPE_VECTOR)); + add_options.push_back(AddOption("SwitchS", "Conditional", "Functions", "VisualShaderNodeScalarSwitch", TTR("Returns an associated scalar if the provided boolean value is true or false."), -1, VisualShaderNode::PORT_TYPE_SCALAR)); add_options.push_back(AddOption("Compare", "Conditional", "Common", "VisualShaderNodeCompare", TTR("Returns the boolean result of the comparison between two parameters."), -1, VisualShaderNode::PORT_TYPE_BOOLEAN)); add_options.push_back(AddOption("Is", "Conditional", "Common", "VisualShaderNodeIs", TTR("Returns the boolean result of the comparison between INF (or NaN) and a scalar parameter."), -1, VisualShaderNode::PORT_TYPE_BOOLEAN)); @@ -2382,6 +2383,7 @@ VisualShaderEditor::VisualShaderEditor() { add_options.push_back(AddOption("InvCamera", "Input", "All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "inv_camera"), "inv_camera", VisualShaderNode::PORT_TYPE_TRANSFORM, -1, Shader::MODE_SPATIAL)); add_options.push_back(AddOption("InvProjection", "Input", "All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "inv_projection"), "inv_projection", VisualShaderNode::PORT_TYPE_TRANSFORM, -1, Shader::MODE_SPATIAL)); add_options.push_back(AddOption("Normal", "Input", "All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "normal"), "normal", VisualShaderNode::PORT_TYPE_VECTOR, -1, Shader::MODE_SPATIAL)); + add_options.push_back(AddOption("OutputIsSRGB", "Input", "All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "output_is_srgb"), "output_is_srgb", VisualShaderNode::PORT_TYPE_BOOLEAN, -1, Shader::MODE_SPATIAL)); add_options.push_back(AddOption("Projection", "Input", "All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "camera"), "projection", VisualShaderNode::PORT_TYPE_TRANSFORM, -1, Shader::MODE_SPATIAL)); add_options.push_back(AddOption("Time", "Input", "All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "time"), "time", VisualShaderNode::PORT_TYPE_SCALAR, -1, Shader::MODE_SPATIAL)); add_options.push_back(AddOption("ViewportSize", "Input", "All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "viewport_size"), "viewport_size", VisualShaderNode::PORT_TYPE_VECTOR, -1, Shader::MODE_SPATIAL)); @@ -2412,6 +2414,7 @@ VisualShaderEditor::VisualShaderEditor() { add_options.push_back(AddOption("Binormal", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "binormal"), "binormal", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_FRAGMENT, Shader::MODE_SPATIAL)); add_options.push_back(AddOption("Color", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "color"), "color", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_FRAGMENT, Shader::MODE_SPATIAL)); add_options.push_back(AddOption("FragCoord", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "fragcoord"), "fragcoord", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_FRAGMENT, Shader::MODE_SPATIAL)); + add_options.push_back(AddOption("FrontFacing", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "front_facing"), "front_facing", VisualShaderNode::PORT_TYPE_BOOLEAN, VisualShader::TYPE_FRAGMENT, Shader::MODE_SPATIAL)); add_options.push_back(AddOption("PointCoord", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "point_coord"), "point_coord", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_FRAGMENT, Shader::MODE_SPATIAL)); add_options.push_back(AddOption("ScreenUV", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "screen_uv"), "screen_uv", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_FRAGMENT, Shader::MODE_SPATIAL)); add_options.push_back(AddOption("Side", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "side"), "side", VisualShaderNode::PORT_TYPE_SCALAR, VisualShader::TYPE_FRAGMENT, Shader::MODE_SPATIAL)); diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index f0114b393d..16f1575757 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -759,7 +759,16 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { _delete_confirm(); } else { - delete_dialog->set_text(TTR("Delete Node(s)?")); + if (remove_list.size() > 1) { + delete_dialog->set_text(vformat(TTR("Delete %d nodes?"), remove_list.size())); + } else { + delete_dialog->set_text(vformat(TTR("Delete node \"%s\"?"), remove_list[0]->get_name())); + } + + // Resize the dialog to its minimum size. + // This prevents the dialog from being too wide after displaying + // a deletion confirmation for a node with a long name. + delete_dialog->set_size(Size2()); delete_dialog->popup_centered_minsize(); } diff --git a/editor/script_editor_debugger.cpp b/editor/script_editor_debugger.cpp index fc5aecdbe9..6ee09012a5 100644 --- a/editor/script_editor_debugger.cpp +++ b/editor/script_editor_debugger.cpp @@ -33,6 +33,7 @@ #include "core/io/marshalls.h" #include "core/project_settings.h" #include "core/ustring.h" +#include "editor_network_profiler.h" #include "editor_node.h" #include "editor_profiler.h" #include "editor_settings.h" @@ -201,6 +202,21 @@ void ScriptEditorDebugger::debug_copy() { OS::get_singleton()->set_clipboard(msg); } +void ScriptEditorDebugger::debug_skip_breakpoints() { + skip_breakpoints_value = !skip_breakpoints_value; + if (skip_breakpoints_value) + skip_breakpoints->set_icon(get_icon("DebugSkipBreakpointsOn", "EditorIcons")); + else + skip_breakpoints->set_icon(get_icon("DebugSkipBreakpointsOff", "EditorIcons")); + + if (connection.is_valid()) { + Array msg; + msg.push_back("set_skip_breakpoints"); + msg.push_back(skip_breakpoints_value); + ppeer->put_var(msg); + } +} + void ScriptEditorDebugger::debug_next() { ERR_FAIL_COND(!breaked); @@ -977,7 +993,20 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da profiler->add_frame_metric(metric, false); else profiler->add_frame_metric(metric, true); - + } else if (p_msg == "network_profile") { + int frame_size = 6; + for (int i = 0; i < p_data.size(); i += frame_size) { + MultiplayerAPI::ProfilingInfo pi; + pi.node = p_data[i + 0]; + pi.node_path = p_data[i + 1]; + pi.incoming_rpc = p_data[i + 2]; + pi.incoming_rset = p_data[i + 3]; + pi.outgoing_rpc = p_data[i + 4]; + pi.outgoing_rset = p_data[i + 5]; + network_profiler->add_node_frame_data(pi); + } + } else if (p_msg == "network_bandwidth") { + network_profiler->set_bandwidth(p_data[0], p_data[1]); } else if (p_msg == "kill_me") { editor->call_deferred("stop_child_process"); @@ -1083,7 +1112,7 @@ void ScriptEditorDebugger::_notification(int p_what) { case NOTIFICATION_ENTER_TREE: { inspector->edit(variables); - + skip_breakpoints->set_icon(get_icon("DebugSkipBreakpointsOff", "EditorIcons")); copy->set_icon(get_icon("ActionCopy", "EditorIcons")); step->set_icon(get_icon("DebugStep", "EditorIcons")); @@ -1193,6 +1222,10 @@ void ScriptEditorDebugger::_notification(int p_what) { if (profiler->is_profiling()) { _profiler_activate(true); } + + if (network_profiler->is_profiling()) { + _network_profiler_activate(true); + } } } @@ -1376,7 +1409,7 @@ void ScriptEditorDebugger::stop() { profiler->set_enabled(true); inspect_scene_tree->clear(); - EditorNode::get_singleton()->edit_current(); + inspector->edit(NULL); EditorNode::get_singleton()->get_pause_button()->set_pressed(false); EditorNode::get_singleton()->get_pause_button()->set_disabled(true); EditorNode::get_singleton()->get_scene_tree_dock()->hide_remote_tree(); @@ -1412,6 +1445,25 @@ void ScriptEditorDebugger::_profiler_activate(bool p_enable) { } } +void ScriptEditorDebugger::_network_profiler_activate(bool p_enable) { + + if (!connection.is_valid()) + return; + + if (p_enable) { + Array msg; + msg.push_back("start_network_profiling"); + ppeer->put_var(msg); + print_verbose("Starting network profiling."); + + } else { + Array msg; + msg.push_back("stop_network_profiling"); + ppeer->put_var(msg); + print_verbose("Ending network profiling."); + } +} + void ScriptEditorDebugger::_profiler_seeked() { if (!connection.is_valid() || !connection->is_connected_to_host()) @@ -1785,6 +1837,10 @@ void ScriptEditorDebugger::reload_scripts() { } } +bool ScriptEditorDebugger::is_skip_breakpoints() { + return skip_breakpoints_value; +} + void ScriptEditorDebugger::_error_activated() { TreeItem *selected = error_tree->get_selected(); @@ -1980,6 +2036,7 @@ void ScriptEditorDebugger::_bind_methods() { ClassDB::bind_method(D_METHOD("_stack_dump_frame_selected"), &ScriptEditorDebugger::_stack_dump_frame_selected); + ClassDB::bind_method(D_METHOD("debug_skip_breakpoints"), &ScriptEditorDebugger::debug_skip_breakpoints); ClassDB::bind_method(D_METHOD("debug_copy"), &ScriptEditorDebugger::debug_copy); ClassDB::bind_method(D_METHOD("debug_next"), &ScriptEditorDebugger::debug_next); @@ -2000,6 +2057,7 @@ void ScriptEditorDebugger::_bind_methods() { ClassDB::bind_method(D_METHOD("_expand_errors_list"), &ScriptEditorDebugger::_expand_errors_list); ClassDB::bind_method(D_METHOD("_collapse_errors_list"), &ScriptEditorDebugger::_collapse_errors_list); ClassDB::bind_method(D_METHOD("_profiler_activate"), &ScriptEditorDebugger::_profiler_activate); + ClassDB::bind_method(D_METHOD("_network_profiler_activate"), &ScriptEditorDebugger::_network_profiler_activate); ClassDB::bind_method(D_METHOD("_profiler_seeked"), &ScriptEditorDebugger::_profiler_seeked); ClassDB::bind_method(D_METHOD("_clear_errors_list"), &ScriptEditorDebugger::_clear_errors_list); @@ -2067,6 +2125,13 @@ ScriptEditorDebugger::ScriptEditorDebugger(EditorNode *p_editor) { hbc->add_child(memnew(VSeparator)); + skip_breakpoints = memnew(ToolButton); + hbc->add_child(skip_breakpoints); + skip_breakpoints->set_tooltip(TTR("Skip Breakpoints")); + skip_breakpoints->connect("pressed", this, "debug_skip_breakpoints"); + + hbc->add_child(memnew(VSeparator)); + copy = memnew(ToolButton); hbc->add_child(copy); copy->set_tooltip(TTR("Copy Error")); @@ -2218,6 +2283,13 @@ ScriptEditorDebugger::ScriptEditorDebugger(EditorNode *p_editor) { profiler->connect("break_request", this, "_profiler_seeked"); } + { //network profiler + network_profiler = memnew(EditorNetworkProfiler); + network_profiler->set_name(TTR("Network Profiler")); + tabs->add_child(network_profiler); + network_profiler->connect("enable_profiling", this, "_network_profiler_activate"); + } + { //monitors HSplitContainer *hsp = memnew(HSplitContainer); diff --git a/editor/script_editor_debugger.h b/editor/script_editor_debugger.h index 947b0cca52..ce48edfe89 100644 --- a/editor/script_editor_debugger.h +++ b/editor/script_editor_debugger.h @@ -50,6 +50,7 @@ class TreeItem; class HSplitContainer; class ItemList; class EditorProfiler; +class EditorNetworkProfiler; class ScriptEditorDebuggerInspectedObject; @@ -109,12 +110,15 @@ class ScriptEditorDebugger : public Control { bool hide_on_stop; bool enable_external_editor; + + bool skip_breakpoints_value = false; Ref<Script> stack_script; TabContainer *tabs; Label *reason; + Button *skip_breakpoints; Button *copy; Button *step; Button *next; @@ -152,6 +156,7 @@ class ScriptEditorDebugger : public Control { Map<String, int> res_path_cache; EditorProfiler *profiler; + EditorNetworkProfiler *network_profiler; EditorNode *editor; @@ -196,6 +201,8 @@ class ScriptEditorDebugger : public Control { void _profiler_activate(bool p_enable); void _profiler_seeked(); + void _network_profiler_activate(bool p_enable); + void _paused(); void _set_remote_object(ObjectID p_id, ScriptEditorDebuggerInspectedObject *p_obj); @@ -219,6 +226,7 @@ public: void unpause(); void stop(); + void debug_skip_breakpoints(); void debug_copy(); void debug_next(); @@ -256,6 +264,8 @@ public: void reload_scripts(); + bool is_skip_breakpoints(); + virtual Size2 get_minimum_size() const; ScriptEditorDebugger(EditorNode *p_editor = NULL); ~ScriptEditorDebugger(); diff --git a/main/main.cpp b/main/main.cpp index f4665c4ad4..9ae885a5ce 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -386,6 +386,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph bool upwards = false; String debug_mode; String debug_host; + bool skip_breakpoints = false; String main_pack; bool quiet_stdout = false; int rtm = -1; @@ -737,6 +738,8 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph print_fps = true; } else if (I->get() == "--disable-crash-handler") { OS::get_singleton()->disable_crash_handler(); + } else if (I->get() == "--skip-breakpoints") { + skip_breakpoints = true; } else { main_args.push_back(I->get()); } @@ -806,6 +809,8 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph } Error derr = sdr->connect_to_host(debug_host, debug_port); + sdr->set_skip_breakpoints(skip_breakpoints); + if (derr != OK) { memdelete(sdr); } else { diff --git a/misc/dist/html/full-size.html b/misc/dist/html/full-size.html index 349420b3f3..12b9af21e5 100644 --- a/misc/dist/html/full-size.html +++ b/misc/dist/html/full-size.html @@ -182,7 +182,7 @@ $GODOT_HEAD_INCLUDE }); animationCallbacks = animationCallbacks.filter(function(value) { return (value != animateStatusIndeterminate); - } + }); switch (mode) { case 'progress': statusProgress.style.display = 'block'; diff --git a/modules/assimp/editor_scene_importer_assimp.cpp b/modules/assimp/editor_scene_importer_assimp.cpp index e5439fd132..a001fe9123 100644 --- a/modules/assimp/editor_scene_importer_assimp.cpp +++ b/modules/assimp/editor_scene_importer_assimp.cpp @@ -541,6 +541,25 @@ Ref<Mesh> EditorSceneImporterAssimp::_generate_mesh_from_surface_indices( mesh.instance(); bool has_uvs = false; + Map<String, uint32_t> morph_mesh_string_lookup; + + for (int i = 0; i < p_surface_indices.size(); i++) { + const unsigned int mesh_idx = p_surface_indices[0]; + const aiMesh *ai_mesh = state.assimp_scene->mMeshes[mesh_idx]; + for (size_t j = 0; j < ai_mesh->mNumAnimMeshes; j++) { + + String ai_anim_mesh_name = AssimpUtils::get_assimp_string(ai_mesh->mAnimMeshes[j]->mName); + if (!morph_mesh_string_lookup.has(ai_anim_mesh_name)) { + morph_mesh_string_lookup.insert(ai_anim_mesh_name, j); + mesh->set_blend_shape_mode(Mesh::BLEND_SHAPE_MODE_NORMALIZED); + if (ai_anim_mesh_name.empty()) { + ai_anim_mesh_name = String("morph_") + itos(j); + } + mesh->add_blend_shape(ai_anim_mesh_name); + } + } + } + // // Process Vertex Weights // @@ -680,6 +699,25 @@ Ref<Mesh> EditorSceneImporterAssimp::_generate_mesh_from_surface_indices( mat->set_cull_mode(SpatialMaterial::CULL_BACK); // Now process materials + aiTextureType base_color = aiTextureType_BASE_COLOR; + { + String filename, path; + AssimpImageData image_data; + + if (AssimpUtils::GetAssimpTexture(state, ai_material, base_color, filename, path, image_data)) { + AssimpUtils::set_texture_mapping_mode(image_data.map_mode, image_data.texture); + + // anything transparent must be culled + if (image_data.raw_image->detect_alpha() != Image::ALPHA_NONE) { + mat->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true); + mat->set_depth_draw_mode(SpatialMaterial::DepthDrawMode::DEPTH_DRAW_ALPHA_OPAQUE_PREPASS); + mat->set_cull_mode(SpatialMaterial::CULL_DISABLED); // since you can see both sides in transparent mode + } + + mat->set_texture(SpatialMaterial::TEXTURE_ALBEDO, image_data.texture); + } + } + aiTextureType tex_diffuse = aiTextureType_DIFFUSE; { String filename, path; @@ -731,6 +769,60 @@ Ref<Mesh> EditorSceneImporterAssimp::_generate_mesh_from_surface_indices( } } + aiTextureType tex_normal_camera = aiTextureType_NORMAL_CAMERA; + { + String filename, path; + Ref<ImageTexture> texture; + AssimpImageData image_data; + + // Process texture normal map + if (AssimpUtils::GetAssimpTexture(state, ai_material, tex_normal_camera, filename, path, image_data)) { + AssimpUtils::set_texture_mapping_mode(image_data.map_mode, image_data.texture); + mat->set_feature(SpatialMaterial::Feature::FEATURE_NORMAL_MAPPING, true); + mat->set_texture(SpatialMaterial::TEXTURE_NORMAL, image_data.texture); + } + } + + aiTextureType tex_emission_color = aiTextureType_EMISSION_COLOR; + { + String filename, path; + Ref<ImageTexture> texture; + AssimpImageData image_data; + + // Process texture normal map + if (AssimpUtils::GetAssimpTexture(state, ai_material, tex_emission_color, filename, path, image_data)) { + AssimpUtils::set_texture_mapping_mode(image_data.map_mode, image_data.texture); + mat->set_feature(SpatialMaterial::Feature::FEATURE_NORMAL_MAPPING, true); + mat->set_texture(SpatialMaterial::TEXTURE_NORMAL, image_data.texture); + } + } + + aiTextureType tex_metalness = aiTextureType_METALNESS; + { + String filename, path; + Ref<ImageTexture> texture; + AssimpImageData image_data; + + // Process texture normal map + if (AssimpUtils::GetAssimpTexture(state, ai_material, tex_metalness, filename, path, image_data)) { + AssimpUtils::set_texture_mapping_mode(image_data.map_mode, image_data.texture); + mat->set_texture(SpatialMaterial::TEXTURE_METALLIC, image_data.texture); + } + } + + aiTextureType tex_roughness = aiTextureType_DIFFUSE_ROUGHNESS; + { + String filename, path; + Ref<ImageTexture> texture; + AssimpImageData image_data; + + // Process texture normal map + if (AssimpUtils::GetAssimpTexture(state, ai_material, tex_roughness, filename, path, image_data)) { + AssimpUtils::set_texture_mapping_mode(image_data.map_mode, image_data.texture); + mat->set_texture(SpatialMaterial::TEXTURE_ROUGHNESS, image_data.texture); + } + } + aiTextureType tex_emissive = aiTextureType_EMISSIVE; { String filename = ""; @@ -772,16 +864,17 @@ Ref<Mesh> EditorSceneImporterAssimp::_generate_mesh_from_surface_indices( } } - aiTextureType tex_roughness = aiTextureType_SHININESS; + aiTextureType tex_ao_map = aiTextureType_AMBIENT_OCCLUSION; { String filename, path; Ref<ImageTexture> texture; AssimpImageData image_data; // Process texture normal map - if (AssimpUtils::GetAssimpTexture(state, ai_material, tex_roughness, filename, path, image_data)) { + if (AssimpUtils::GetAssimpTexture(state, ai_material, tex_ao_map, filename, path, image_data)) { AssimpUtils::set_texture_mapping_mode(image_data.map_mode, image_data.texture); - mat->set_texture(SpatialMaterial::TEXTURE_ROUGHNESS, image_data.texture); + mat->set_feature(SpatialMaterial::FEATURE_AMBIENT_OCCLUSION, true); + mat->set_texture(SpatialMaterial::TEXTURE_AMBIENT_OCCLUSION, image_data.texture); } } @@ -789,16 +882,15 @@ Ref<Mesh> EditorSceneImporterAssimp::_generate_mesh_from_surface_indices( Array morphs; morphs.resize(ai_mesh->mNumAnimMeshes); Mesh::PrimitiveType primitive = Mesh::PRIMITIVE_TRIANGLES; - Map<uint32_t, String> morph_mesh_idx_names; + for (size_t j = 0; j < ai_mesh->mNumAnimMeshes; j++) { String ai_anim_mesh_name = AssimpUtils::get_assimp_string(ai_mesh->mAnimMeshes[j]->mName); - mesh->set_blend_shape_mode(Mesh::BLEND_SHAPE_MODE_NORMALIZED); + if (ai_anim_mesh_name.empty()) { ai_anim_mesh_name = String("morph_") + itos(j); } - mesh->add_blend_shape(ai_anim_mesh_name); - morph_mesh_idx_names.insert(j, ai_anim_mesh_name); + Array array_copy; array_copy.resize(VisualServer::ARRAY_MAX); diff --git a/modules/assimp/import_state.h b/modules/assimp/import_state.h index 8d82cd3e39..56d89ffea7 100644 --- a/modules/assimp/import_state.h +++ b/modules/assimp/import_state.h @@ -79,7 +79,7 @@ struct ImportState { struct AssimpImageData { Ref<Image> raw_image; Ref<ImageTexture> texture; - aiTextureMapMode *map_mode = NULL; + aiTextureMapMode map_mode[2]; }; /** Recursive state is used to push state into functions instead of specifying them diff --git a/modules/gdscript/gdscript_compiler.cpp b/modules/gdscript/gdscript_compiler.cpp index 7166189416..9ea6b0e863 100644 --- a/modules/gdscript/gdscript_compiler.cpp +++ b/modules/gdscript/gdscript_compiler.cpp @@ -1520,8 +1520,16 @@ Error GDScriptCompiler::_parse_block(CodeGen &codegen, const GDScriptParser::Blo if (ret2 < 0) return ERR_PARSE_ERROR; + int message_ret = 0; + if (as->message) { + message_ret = _parse_expression(codegen, as->message, p_stack_level + 1, false); + if (message_ret < 0) + return ERR_PARSE_ERROR; + } + codegen.opcodes.push_back(GDScriptFunction::OPCODE_ASSERT); codegen.opcodes.push_back(ret2); + codegen.opcodes.push_back(message_ret); #endif } break; case GDScriptParser::Node::TYPE_BREAKPOINT: { diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp index b4c38e4d40..9b3bf8ad5b 100644 --- a/modules/gdscript/gdscript_editor.cpp +++ b/modules/gdscript/gdscript_editor.cpp @@ -223,7 +223,7 @@ bool GDScriptLanguage::debug_break_parse(const String &p_file, int p_line, const _debug_parse_err_line = p_line; _debug_parse_err_file = p_file; _debug_error = p_error; - ScriptDebugger::get_singleton()->debug(this, false); + ScriptDebugger::get_singleton()->debug(this, false, true); return true; } else { return false; @@ -237,7 +237,8 @@ bool GDScriptLanguage::debug_break(const String &p_error, bool p_allow_continue) _debug_parse_err_line = -1; _debug_parse_err_file = ""; _debug_error = p_error; - ScriptDebugger::get_singleton()->debug(this, p_allow_continue); + bool is_error_breakpoint = p_error != "Breakpoint"; + ScriptDebugger::get_singleton()->debug(this, p_allow_continue, is_error_breakpoint); return true; } else { return false; diff --git a/modules/gdscript/gdscript_function.cpp b/modules/gdscript/gdscript_function.cpp index 68f2a9473e..bdeea9cef3 100644 --- a/modules/gdscript/gdscript_function.cpp +++ b/modules/gdscript/gdscript_function.cpp @@ -1475,20 +1475,25 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a DISPATCH_OPCODE; OPCODE(OPCODE_ASSERT) { - CHECK_SPACE(2); + CHECK_SPACE(3); #ifdef DEBUG_ENABLED GET_VARIANT_PTR(test, 1); + GET_VARIANT_PTR(message, 2); bool result = test->booleanize(); if (!result) { - - err_text = "Assertion failed."; + const String &message_str = *message; + if (message_str.empty()) { + err_text = "Assertion failed."; + } else { + err_text = "Assertion failed: " + message_str; + } OPCODE_BREAK; } #endif - ip += 2; + ip += 3; } DISPATCH_OPCODE; diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index e96bf0238a..0253e48f9d 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -3280,15 +3280,36 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) { case GDScriptTokenizer::TK_PR_ASSERT: { tokenizer->advance(); - Node *condition = _parse_and_reduce_expression(p_block, p_static); - if (!condition) { - if (_recover_from_completion()) { - break; - } + + if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_OPEN) { + _set_error("Expected '(' after assert"); + return; + } + + tokenizer->advance(); + + Vector<Node *> args; + const bool result = _parse_arguments(p_block, args, p_static); + if (!result) { + return; + } + + if (args.empty() || args.size() > 2) { + _set_error("Wrong number of arguments, expected 1 or 2"); return; } + AssertNode *an = alloc_node<AssertNode>(); - an->condition = condition; + an->condition = _reduce_expression(args[0], p_static); + + if (args.size() == 2) { + an->message = _reduce_expression(args[1], p_static); + } else { + ConstantNode *message_node = alloc_node<ConstantNode>(); + message_node->value = String(); + an->message = message_node; + } + p_block->statements.push_back(an); if (!_end_statement()) { diff --git a/modules/gdscript/gdscript_parser.h b/modules/gdscript/gdscript_parser.h index 72aa819a8c..1e8193a63e 100644 --- a/modules/gdscript/gdscript_parser.h +++ b/modules/gdscript/gdscript_parser.h @@ -481,7 +481,12 @@ public: struct AssertNode : public Node { Node *condition; - AssertNode() { type = TYPE_ASSERT; } + Node *message; + AssertNode() : + condition(0), + message(0) { + type = TYPE_ASSERT; + } }; struct BreakpointNode : public Node { diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp index 4c9dd9c1a9..e14e919f92 100644 --- a/modules/mono/csharp_script.cpp +++ b/modules/mono/csharp_script.cpp @@ -1101,7 +1101,7 @@ bool CSharpLanguage::debug_break_parse(const String &p_file, int p_line, const S _debug_parse_err_line = p_line; _debug_parse_err_file = p_file; _debug_error = p_error; - ScriptDebugger::get_singleton()->debug(this, false); + ScriptDebugger::get_singleton()->debug(this, false, true); return true; } else { return false; diff --git a/modules/mono/editor/GodotTools/GodotTools/GodotSharpExport.cs b/modules/mono/editor/GodotTools/GodotTools/GodotSharpExport.cs index aefc51545e..4f93ef8530 100644 --- a/modules/mono/editor/GodotTools/GodotTools/GodotSharpExport.cs +++ b/modules/mono/editor/GodotTools/GodotTools/GodotSharpExport.cs @@ -16,7 +16,7 @@ namespace GodotTools { private void AddFile(string srcPath, string dstPath, bool remap = false) { - AddFile(dstPath, File.ReadAllBytes(srcPath), remap); + AddFile(dstPath.Replace("\\", "/"), File.ReadAllBytes(srcPath), remap); } public override void _ExportFile(string path, string type, string[] features) diff --git a/modules/mono/editor/editor_internal_calls.cpp b/modules/mono/editor/editor_internal_calls.cpp index cd1ca2a2c7..5a84d9e3b8 100644 --- a/modules/mono/editor/editor_internal_calls.cpp +++ b/modules/mono/editor/editor_internal_calls.cpp @@ -429,6 +429,7 @@ void register_editor_internal_calls() { mono_add_internal_call("GodotTools.Internals.Internal::internal_ScriptEditorEdit", (void *)godot_icall_Internal_ScriptEditorEdit); mono_add_internal_call("GodotTools.Internals.Internal::internal_EditorNodeShowScriptScreen", (void *)godot_icall_Internal_EditorNodeShowScriptScreen); mono_add_internal_call("GodotTools.Internals.Internal::internal_GetScriptsMetadataOrNothing", (void *)godot_icall_Internal_GetScriptsMetadataOrNothing); + mono_add_internal_call("GodotTools.Internals.Internal::internal_MonoWindowsInstallRoot", (void *)godot_icall_Internal_MonoWindowsInstallRoot); mono_add_internal_call("GodotTools.Internals.Internal::internal_EditorRunPlay", (void *)godot_icall_Internal_EditorRunPlay); mono_add_internal_call("GodotTools.Internals.Internal::internal_EditorRunStop", (void *)godot_icall_Internal_EditorRunStop); mono_add_internal_call("GodotTools.Internals.Internal::internal_ScriptEditorDebugger_ReloadScripts", (void *)godot_icall_Internal_ScriptEditorDebugger_ReloadScripts); diff --git a/modules/mono/glue/Managed/Files/Rect2.cs b/modules/mono/glue/Managed/Files/Rect2.cs index f3dc9d8490..99542d0c0a 100644 --- a/modules/mono/glue/Managed/Files/Rect2.cs +++ b/modules/mono/glue/Managed/Files/Rect2.cs @@ -157,13 +157,13 @@ namespace Godot public bool Intersects(Rect2 b) { - if (_position.x > b._position.x + b._size.x) + if (_position.x >= b._position.x + b._size.x) return false; - if (_position.x + _size.x < b._position.x) + if (_position.x + _size.x <= b._position.x) return false; - if (_position.y > b._position.y + b._size.y) + if (_position.y >= b._position.y + b._size.y) return false; - if (_position.y + _size.y < b._position.y) + if (_position.y + _size.y <= b._position.y) return false; return true; diff --git a/modules/mono/mono_gd/gd_mono_log.cpp b/modules/mono/mono_gd/gd_mono_log.cpp index 5a0d728953..6d91075ce3 100644 --- a/modules/mono/mono_gd/gd_mono_log.cpp +++ b/modules/mono/mono_gd/gd_mono_log.cpp @@ -159,7 +159,7 @@ void GDMonoLog::initialize() { log_file = FileAccess::open(log_file_path, FileAccess::WRITE); if (!log_file) { - ERR_PRINT("Mono: Cannot create log file."); + ERR_PRINTS("Mono: Cannot create log file at: " + log_file_path); } } diff --git a/modules/mono/utils/string_utils.cpp b/modules/mono/utils/string_utils.cpp index ae5a2cde81..716c712ccc 100644 --- a/modules/mono/utils/string_utils.cpp +++ b/modules/mono/utils/string_utils.cpp @@ -208,14 +208,18 @@ String str_format(const char *p_format, ...) { #endif #if defined(MINGW_ENABLED) || defined(_MSC_VER) && _MSC_VER < 1900 -#define vsnprintf(m_buffer, m_count, m_format, m_argptr) vsnprintf_s(m_buffer, m_count, _TRUNCATE, m_format, m_argptr) +#define gd_vsnprintf(m_buffer, m_count, m_format, m_args_copy) vsnprintf_s(m_buffer, m_count, _TRUNCATE, m_format, m_args_copy) +#define gd_vscprintf(m_format, m_args_copy) _vscprintf(m_format, m_args_copy) +#else +#define gd_vsnprintf(m_buffer, m_count, m_format, m_args_copy) vsnprintf(m_buffer, m_count, m_format, m_args_copy) +#define gd_vscprintf(m_format, m_args_copy) vsnprintf(NULL, 0, p_format, m_args_copy) #endif String str_format(const char *p_format, va_list p_list) { va_list list; va_copy(list, p_list); - int len = vsnprintf(NULL, 0, p_format, list); + int len = gd_vscprintf(p_format, list); va_end(list); len += 1; // for the trailing '/0' @@ -223,7 +227,7 @@ String str_format(const char *p_format, va_list p_list) { char *buffer(memnew_arr(char, len)); va_copy(list, p_list); - vsnprintf(buffer, len, p_format, list); + gd_vsnprintf(buffer, len, p_format, list); va_end(list); String res(buffer); diff --git a/modules/visual_script/visual_script.cpp b/modules/visual_script/visual_script.cpp index 3f8b2b1831..70389b6729 100644 --- a/modules/visual_script/visual_script.cpp +++ b/modules/visual_script/visual_script.cpp @@ -2450,7 +2450,7 @@ bool VisualScriptLanguage::debug_break_parse(const String &p_file, int p_node, c _debug_parse_err_node = p_node; _debug_parse_err_file = p_file; _debug_error = p_error; - ScriptDebugger::get_singleton()->debug(this, false); + ScriptDebugger::get_singleton()->debug(this, false, true); return true; } else { return false; @@ -2464,7 +2464,7 @@ bool VisualScriptLanguage::debug_break(const String &p_error, bool p_allow_conti _debug_parse_err_node = -1; _debug_parse_err_file = ""; _debug_error = p_error; - ScriptDebugger::get_singleton()->debug(this, p_allow_continue); + ScriptDebugger::get_singleton()->debug(this, p_allow_continue, true); return true; } else { return false; diff --git a/modules/visual_script/visual_script_builtin_funcs.cpp b/modules/visual_script/visual_script_builtin_funcs.cpp index 8088a71198..3fdceacebb 100644 --- a/modules/visual_script/visual_script_builtin_funcs.cpp +++ b/modules/visual_script/visual_script_builtin_funcs.cpp @@ -106,6 +106,7 @@ const char *VisualScriptBuiltinFunc::func_name[VisualScriptBuiltinFunc::FUNC_MAX "smoothstep", "posmod", "lerp_angle", + "ord", }; VisualScriptBuiltinFunc::BuiltinFunc VisualScriptBuiltinFunc::find_function(const String &p_string) { @@ -181,6 +182,7 @@ int VisualScriptBuiltinFunc::get_func_argument_count(BuiltinFunc p_func) { case OBJ_WEAKREF: case TYPE_OF: case TEXT_CHAR: + case TEXT_ORD: case TEXT_STR: case TEXT_PRINT: case TEXT_PRINTERR: @@ -438,6 +440,9 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const case TYPE_EXISTS: { return PropertyInfo(Variant::STRING, "type"); } break; + case TEXT_ORD: { + return PropertyInfo(Variant::STRING, "character"); + } break; case TEXT_CHAR: { return PropertyInfo(Variant::INT, "ascii"); } break; @@ -594,6 +599,7 @@ PropertyInfo VisualScriptBuiltinFunc::get_output_value_port_info(int p_idx) cons case TYPE_CONVERT: { } break; + case TEXT_ORD: case TYPE_OF: { t = Variant::INT; @@ -1132,6 +1138,30 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in *r_return = String(result); } break; + case VisualScriptBuiltinFunc::TEXT_ORD: { + + if (p_inputs[0]->get_type() != Variant::STRING) { + r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument = 0; + r_error.expected = Variant::STRING; + + return; + } + + String str = p_inputs[0]->operator String(); + + if (str.length() != 1) { + r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument = 0; + r_error.expected = Variant::STRING; + *r_return = "Expected a string of length 1 (a character)."; + + return; + } + + *r_return = str.get(0); + + } break; case VisualScriptBuiltinFunc::TEXT_STR: { String str = *p_inputs[0]; @@ -1374,6 +1404,7 @@ void VisualScriptBuiltinFunc::_bind_methods() { BIND_ENUM_CONSTANT(MATH_SMOOTHSTEP); BIND_ENUM_CONSTANT(MATH_POSMOD); BIND_ENUM_CONSTANT(MATH_LERP_ANGLE); + BIND_ENUM_CONSTANT(TEXT_ORD); BIND_ENUM_CONSTANT(FUNC_MAX); } @@ -1460,6 +1491,7 @@ void register_visual_script_builtin_func_node() { VisualScriptLanguage::singleton->add_register_func("functions/built_in/typeof", create_builtin_func_node<VisualScriptBuiltinFunc::TYPE_OF>); VisualScriptLanguage::singleton->add_register_func("functions/built_in/type_exists", create_builtin_func_node<VisualScriptBuiltinFunc::TYPE_EXISTS>); VisualScriptLanguage::singleton->add_register_func("functions/built_in/char", create_builtin_func_node<VisualScriptBuiltinFunc::TEXT_CHAR>); + VisualScriptLanguage::singleton->add_register_func("functions/built_in/ord", create_builtin_func_node<VisualScriptBuiltinFunc::TEXT_ORD>); VisualScriptLanguage::singleton->add_register_func("functions/built_in/str", create_builtin_func_node<VisualScriptBuiltinFunc::TEXT_STR>); VisualScriptLanguage::singleton->add_register_func("functions/built_in/print", create_builtin_func_node<VisualScriptBuiltinFunc::TEXT_PRINT>); VisualScriptLanguage::singleton->add_register_func("functions/built_in/printerr", create_builtin_func_node<VisualScriptBuiltinFunc::TEXT_PRINTERR>); diff --git a/modules/visual_script/visual_script_builtin_funcs.h b/modules/visual_script/visual_script_builtin_funcs.h index cf475d675d..998a6cbc6a 100644 --- a/modules/visual_script/visual_script_builtin_funcs.h +++ b/modules/visual_script/visual_script_builtin_funcs.h @@ -106,6 +106,7 @@ public: MATH_SMOOTHSTEP, MATH_POSMOD, MATH_LERP_ANGLE, + TEXT_ORD, FUNC_MAX }; diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index 08023c21a2..2445456a1f 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -872,7 +872,9 @@ void LineEdit::_notification(int p_what) { } break; case NOTIFICATION_FOCUS_ENTER: { - if (!caret_blink_enabled) { + if (caret_blink_enabled) { + caret_blink_timer->start(); + } else { draw_caret = true; } @@ -886,6 +888,10 @@ void LineEdit::_notification(int p_what) { } break; case NOTIFICATION_FOCUS_EXIT: { + if (caret_blink_enabled) { + caret_blink_timer->stop(); + } + OS::get_singleton()->set_ime_position(Point2()); OS::get_singleton()->set_ime_active(false); ime_text = ""; @@ -1053,11 +1059,15 @@ bool LineEdit::cursor_get_blink_enabled() const { void LineEdit::cursor_set_blink_enabled(const bool p_enabled) { caret_blink_enabled = p_enabled; - if (p_enabled) { - caret_blink_timer->start(); - } else { - caret_blink_timer->stop(); + + if (has_focus()) { + if (p_enabled) { + caret_blink_timer->start(); + } else { + caret_blink_timer->stop(); + } } + draw_caret = true; } @@ -1072,10 +1082,12 @@ void LineEdit::cursor_set_blink_speed(const float p_speed) { void LineEdit::_reset_caret_blink_timer() { if (caret_blink_enabled) { - caret_blink_timer->stop(); - caret_blink_timer->start(); draw_caret = true; - update(); + if (has_focus()) { + caret_blink_timer->stop(); + caret_blink_timer->start(); + update(); + } } } diff --git a/scene/gui/rich_text_effect.cpp b/scene/gui/rich_text_effect.cpp new file mode 100644 index 0000000000..67fa85b832 --- /dev/null +++ b/scene/gui/rich_text_effect.cpp @@ -0,0 +1,122 @@ +/*************************************************************************/ +/* rich_text_effect.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2019 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 "rich_text_effect.h" + +#include "core/script_language.h" + +void RichTextEffect::_bind_methods() { + BIND_VMETHOD(MethodInfo(Variant::BOOL, "_process_custom_fx", PropertyInfo(Variant::OBJECT, "char_fx", PROPERTY_HINT_RESOURCE_TYPE, "CharFXTransform"))); +} + +Variant RichTextEffect::get_bbcode() const { + Variant r; + if (get_script_instance()) { + if (!get_script_instance()->get("bbcode", r)) { + String path = get_script_instance()->get_script()->get_path(); + r = path.get_file().get_basename(); + } + } + return r; +} + +bool RichTextEffect::_process_effect_impl(Ref<CharFXTransform> p_cfx) { + bool return_value = false; + if (get_script_instance()) { + Variant v = get_script_instance()->call("_process_custom_fx", p_cfx); + if (v.get_type() != Variant::BOOL) { + return_value = false; + } else { + return_value = (bool)v; + } + } + return return_value; +} + +RichTextEffect::RichTextEffect() { +} + +void CharFXTransform::_bind_methods() { + + ClassDB::bind_method(D_METHOD("get_relative_index"), &CharFXTransform::get_relative_index); + ClassDB::bind_method(D_METHOD("set_relative_index", "index"), &CharFXTransform::set_relative_index); + + ClassDB::bind_method(D_METHOD("get_absolute_index"), &CharFXTransform::get_absolute_index); + ClassDB::bind_method(D_METHOD("set_absolute_index", "index"), &CharFXTransform::set_absolute_index); + + ClassDB::bind_method(D_METHOD("get_elapsed_time"), &CharFXTransform::get_elapsed_time); + ClassDB::bind_method(D_METHOD("set_elapsed_time", "time"), &CharFXTransform::set_elapsed_time); + + ClassDB::bind_method(D_METHOD("is_visible"), &CharFXTransform::is_visible); + ClassDB::bind_method(D_METHOD("set_visibility", "visibility"), &CharFXTransform::set_visibility); + + ClassDB::bind_method(D_METHOD("get_offset"), &CharFXTransform::get_offset); + ClassDB::bind_method(D_METHOD("set_offset", "offset"), &CharFXTransform::set_offset); + + ClassDB::bind_method(D_METHOD("get_color"), &CharFXTransform::get_color); + ClassDB::bind_method(D_METHOD("set_color", "color"), &CharFXTransform::set_color); + + ClassDB::bind_method(D_METHOD("get_environment"), &CharFXTransform::get_environment); + ClassDB::bind_method(D_METHOD("set_environment", "environment"), &CharFXTransform::set_environment); + + ClassDB::bind_method(D_METHOD("get_character"), &CharFXTransform::get_character); + ClassDB::bind_method(D_METHOD("set_character", "character"), &CharFXTransform::set_character); + + ClassDB::bind_method(D_METHOD("get_value_or", "key", "default_value"), &CharFXTransform::get_value_or); + + ADD_PROPERTY(PropertyInfo(Variant::INT, "relative_index"), "set_relative_index", "get_relative_index"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "absolute_index"), "set_absolute_index", "get_absolute_index"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "elapsed_time"), "set_elapsed_time", "get_elapsed_time"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "visible"), "set_visibility", "is_visible"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "offset"), "set_offset", "get_offset"); + ADD_PROPERTY(PropertyInfo(Variant::COLOR, "color"), "set_color", "get_color"); + ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "env"), "set_environment", "get_environment"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "character"), "set_character", "get_character"); +} + +Variant CharFXTransform::get_value_or(String p_key, Variant p_default_value) { + if (!this->environment.has(p_key)) + return p_default_value; + + Variant r = environment[p_key]; + if (r.get_type() != p_default_value.get_type()) + return p_default_value; + + return r; +} + +CharFXTransform::CharFXTransform() { + relative_index = 0; + absolute_index = 0; + visibility = true; + offset = Point2(); + color = Color(); + character = 0; +} diff --git a/scene/gui/rich_text_effect.h b/scene/gui/rich_text_effect.h new file mode 100644 index 0000000000..f9c3e15399 --- /dev/null +++ b/scene/gui/rich_text_effect.h @@ -0,0 +1,87 @@ +/*************************************************************************/ +/* rich_text_effect.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2019 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 RICH_TEXT_EFFECT_H +#define RICH_TEXT_EFFECT_H + +#include "core/resource.h" + +class RichTextEffect : public Resource { + GDCLASS(RichTextEffect, Resource); + OBJ_SAVE_TYPE(RichTextEffect); + +protected: + static void _bind_methods(); + +public: + Variant get_bbcode() const; + bool _process_effect_impl(Ref<class CharFXTransform> p_cfx); + + RichTextEffect(); +}; + +class CharFXTransform : public Reference { + GDCLASS(CharFXTransform, Reference); + +protected: + static void _bind_methods(); + +public: + uint64_t relative_index; + uint64_t absolute_index; + bool visibility; + Point2 offset; + Color color; + CharType character; + float elapsed_time; + Dictionary environment; + + CharFXTransform(); + uint64_t get_relative_index() { return relative_index; } + void set_relative_index(uint64_t p_index) { relative_index = p_index; } + uint64_t get_absolute_index() { return absolute_index; } + void set_absolute_index(uint64_t p_index) { absolute_index = p_index; } + float get_elapsed_time() { return elapsed_time; } + void set_elapsed_time(float p_elapsed_time) { elapsed_time = p_elapsed_time; } + bool is_visible() { return visibility; } + void set_visibility(bool p_vis) { visibility = p_vis; } + Point2 get_offset() { return offset; } + void set_offset(Point2 p_offset) { offset = p_offset; } + Color get_color() { return color; } + void set_color(Color p_color) { color = p_color; } + int get_character() { return (int)character; } + void set_character(int p_char) { character = (CharType)p_char; } + Dictionary get_environment() { return environment; } + void set_environment(Dictionary p_environment) { environment = p_environment; } + + Variant get_value_or(String p_key, Variant p_default_value); +}; + +#endif // RICH_TEXT_EFFECT_H diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 1aed858c94..d9ae42d6e6 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -30,10 +30,11 @@ #include "rich_text_label.h" +#include "core/math/math_defs.h" #include "core/os/keyboard.h" #include "core/os/os.h" +#include "modules/regex/regex.h" #include "scene/scene_string_names.h" - #ifdef TOOLS_ENABLED #include "editor/editor_scale.h" #endif @@ -139,6 +140,7 @@ Rect2 RichTextLabel::_get_text_rect() { Ref<StyleBox> style = get_stylebox("normal"); return Rect2(style->get_offset(), get_size() - style->get_minimum_size()); } + int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &y, int p_width, int p_line, ProcessMode p_mode, const Ref<Font> &p_base_font, const Color &p_base_color, const Color &p_font_color_shadow, bool p_shadow_as_outline, const Point2 &shadow_ofs, const Point2i &p_click_pos, Item **r_click_item, int *r_click_char, bool *r_outside, int p_char_count) { RID ci; @@ -292,7 +294,6 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & Color selection_bg; if (p_mode == PROCESS_DRAW) { - selection_fg = get_color("font_color_selected"); selection_bg = get_color("selection_color"); } @@ -343,18 +344,24 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & Color font_color_shadow; bool underline = false; bool strikethrough = false; + ItemFade *fade = NULL; + int it_char_start = p_char_count; + + Vector<ItemFX *> fx_stack = Vector<ItemFX *>(); + bool custom_fx_ok = true; if (p_mode == PROCESS_DRAW) { color = _find_color(text, p_base_color); font_color_shadow = _find_color(text, p_font_color_shadow); if (_find_underline(text) || (_find_meta(text, &meta) && underline_meta)) { - underline = true; } else if (_find_strikethrough(text)) { - strikethrough = true; } + fade = _fetch_by_type<ItemFade>(text, ITEM_FADE); + _fetch_item_stack<ItemFX>(text, fx_stack); + } else if (p_mode == PROCESS_CACHE) { l.char_count += text->text.length(); } @@ -431,8 +438,11 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & ofs += cw; } else if (p_mode == PROCESS_DRAW) { - bool selected = false; + Color fx_color = Color(color); + Point2 fx_offset; + CharType fx_char = c[i]; + if (selection.active) { int cofs = (&c[i]) - cf; @@ -442,8 +452,78 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & } int cw = 0; + int c_item_offset = p_char_count - it_char_start; + + float faded_visibility = 1.0f; + if (fade) { + if (c_item_offset >= fade->starting_index) { + faded_visibility -= (float)(c_item_offset - fade->starting_index) / (float)fade->length; + faded_visibility = faded_visibility < 0.0f ? 0.0f : faded_visibility; + } + fx_color.a = faded_visibility; + } + + bool visible = visible_characters < 0 || ((p_char_count < visible_characters && YRANGE_VISIBLE(y + lh - line_descent - line_ascent, line_ascent + line_descent)) && + faded_visibility > 0.0f); + + for (int j = 0; j < fx_stack.size(); j++) { + ItemCustomFX *item_custom = Object::cast_to<ItemCustomFX>(fx_stack[j]); + ItemShake *item_shake = Object::cast_to<ItemShake>(fx_stack[j]); + ItemWave *item_wave = Object::cast_to<ItemWave>(fx_stack[j]); + ItemTornado *item_tornado = Object::cast_to<ItemTornado>(fx_stack[j]); + ItemRainbow *item_rainbow = Object::cast_to<ItemRainbow>(fx_stack[j]); + + if (item_custom && custom_fx_ok) { + Ref<CharFXTransform> charfx = Ref<CharFXTransform>(memnew(CharFXTransform)); + Ref<RichTextEffect> custom_effect = _get_custom_effect_by_code(item_custom->identifier); + if (!custom_effect.is_null()) { + charfx->elapsed_time = item_custom->elapsed_time; + charfx->environment = item_custom->environment; + charfx->relative_index = c_item_offset; + charfx->absolute_index = p_char_count; + charfx->visibility = visible; + charfx->offset = fx_offset; + charfx->color = fx_color; + charfx->character = fx_char; + + bool effect_status = custom_effect->_process_effect_impl(charfx); + custom_fx_ok = effect_status; + + fx_offset += charfx->offset; + fx_color = charfx->color; + visible &= charfx->visibility; + fx_char = charfx->character; + } + } else if (item_shake) { + uint64_t char_current_rand = item_shake->offset_random(c_item_offset); + uint64_t char_previous_rand = item_shake->offset_previous_random(c_item_offset); + uint64_t max_rand = 2147483647; + double current_offset = Math::range_lerp(char_current_rand % max_rand, 0, max_rand, 0.0f, 2.f * (float)Math_PI); + double previous_offset = Math::range_lerp(char_previous_rand % max_rand, 0, max_rand, 0.0f, 2.f * (float)Math_PI); + double n_time = (double)(item_shake->elapsed_time / (0.5f / item_shake->rate)); + n_time = (n_time > 1.0) ? 1.0 : n_time; + fx_offset += Point2(Math::lerp(Math::sin(previous_offset), + Math::sin(current_offset), + n_time), + Math::lerp(Math::cos(previous_offset), + Math::cos(current_offset), + n_time)) * + (float)item_shake->strength / 10.0f; + } else if (item_wave) { + double value = Math::sin(item_wave->frequency * item_wave->elapsed_time + ((p_ofs.x + pofs) / 50)) * (item_wave->amplitude / 10.0f); + fx_offset += Point2(0, 1) * value; + } else if (item_tornado) { + double torn_x = Math::sin(item_tornado->frequency * item_tornado->elapsed_time + ((p_ofs.x + pofs) / 50)) * (item_tornado->radius); + double torn_y = Math::cos(item_tornado->frequency * item_tornado->elapsed_time + ((p_ofs.x + pofs) / 50)) * (item_tornado->radius); + fx_offset += Point2(torn_x, torn_y); + } else if (item_rainbow) { + fx_color = fx_color.from_hsv(item_rainbow->frequency * (item_rainbow->elapsed_time + ((p_ofs.x + pofs) / 50)), + item_rainbow->saturation, + item_rainbow->value, + fx_color.a); + } + } - bool visible = visible_characters < 0 || (p_char_count < visible_characters && YRANGE_VISIBLE(y + lh - line_descent - line_ascent, line_ascent + line_descent)); if (visible) line_is_blank = false; @@ -451,27 +531,28 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & visible = false; if (visible) { + if (selected) { - cw = font->get_char_size(c[i], c[i + 1]).x; + cw = font->get_char_size(fx_char, c[i + 1]).x; draw_rect(Rect2(p_ofs.x + pofs, p_ofs.y + y, cw, lh), selection_bg); } if (p_font_color_shadow.a > 0) { float x_ofs_shadow = align_ofs + pofs; float y_ofs_shadow = y + lh - line_descent; - font->draw_char(ci, Point2(x_ofs_shadow, y_ofs_shadow) + shadow_ofs, c[i], c[i + 1], p_font_color_shadow); + font->draw_char(ci, Point2(x_ofs_shadow, y_ofs_shadow) + shadow_ofs, fx_char, c[i + 1], p_font_color_shadow); if (p_shadow_as_outline) { - font->draw_char(ci, Point2(x_ofs_shadow, y_ofs_shadow) + Vector2(-shadow_ofs.x, shadow_ofs.y), c[i], c[i + 1], p_font_color_shadow); - font->draw_char(ci, Point2(x_ofs_shadow, y_ofs_shadow) + Vector2(shadow_ofs.x, -shadow_ofs.y), c[i], c[i + 1], p_font_color_shadow); - font->draw_char(ci, Point2(x_ofs_shadow, y_ofs_shadow) + Vector2(-shadow_ofs.x, -shadow_ofs.y), c[i], c[i + 1], p_font_color_shadow); + font->draw_char(ci, Point2(x_ofs_shadow, y_ofs_shadow) + Vector2(-shadow_ofs.x, shadow_ofs.y), fx_char, c[i + 1], p_font_color_shadow); + font->draw_char(ci, Point2(x_ofs_shadow, y_ofs_shadow) + Vector2(shadow_ofs.x, -shadow_ofs.y), fx_char, c[i + 1], p_font_color_shadow); + font->draw_char(ci, Point2(x_ofs_shadow, y_ofs_shadow) + Vector2(-shadow_ofs.x, -shadow_ofs.y), fx_char, c[i + 1], p_font_color_shadow); } } if (selected) { - drawer.draw_char(ci, p_ofs + Point2(align_ofs + pofs, y + lh - line_descent), c[i], c[i + 1], override_selected_font_color ? selection_fg : color); + drawer.draw_char(ci, p_ofs + Point2(align_ofs + pofs, y + lh - line_descent), fx_char, c[i + 1], override_selected_font_color ? selection_fg : fx_color); } else { - cw = drawer.draw_char(ci, p_ofs + Point2(align_ofs + pofs, y + lh - line_descent), c[i], c[i + 1], color); + cw = drawer.draw_char(ci, p_ofs + Point2(align_ofs + pofs, y + lh - line_descent) + fx_offset, fx_char, c[i + 1], fx_color); } } @@ -800,6 +881,31 @@ void RichTextLabel::_update_scroll() { } } +void RichTextLabel::_update_fx(RichTextLabel::ItemFrame *p_frame, float p_delta_time) { + Item *it = p_frame; + while (it) { + ItemFX *ifx = Object::cast_to<ItemFX>(it); + + if (!ifx) { + it = _get_next_item(it, true); + continue; + } + + ifx->elapsed_time += p_delta_time; + + ItemShake *shake = Object::cast_to<ItemShake>(it); + if (shake) { + bool cycle = (shake->elapsed_time > (1.0f / shake->rate)); + if (cycle) { + shake->elapsed_time -= (1.0f / shake->rate); + shake->reroll_random(); + } + } + + it = _get_next_item(it, true); + } +} + void RichTextLabel::_notification(int p_what) { switch (p_what) { @@ -873,6 +979,15 @@ void RichTextLabel::_notification(int p_what) { from_line++; } + } break; + case NOTIFICATION_INTERNAL_PROCESS: { + float dt = get_process_delta_time(); + + for (int i = 0; i < custom_effects.size(); i++) { + } + + _update_fx(main, dt); + update(); } } } @@ -1026,15 +1141,11 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) { } if (b->get_button_index() == BUTTON_WHEEL_UP) { - if (scroll_active) - vscroll->set_value(vscroll->get_value() - vscroll->get_page() * b->get_factor() * 0.5 / 8); } if (b->get_button_index() == BUTTON_WHEEL_DOWN) { - if (scroll_active) - vscroll->set_value(vscroll->get_value() + vscroll->get_page() * b->get_factor() * 0.5 / 8); } } @@ -1285,8 +1396,19 @@ bool RichTextLabel::_find_strikethrough(Item *p_item) { return false; } -bool RichTextLabel::_find_meta(Item *p_item, Variant *r_meta, ItemMeta **r_item) { +bool RichTextLabel::_find_by_type(Item *p_item, ItemType p_type) { + Item *item = p_item; + while (item) { + if (item->type == p_type) { + return true; + } + item = item->parent; + } + return false; +} + +bool RichTextLabel::_find_meta(Item *p_item, Variant *r_meta, ItemMeta **r_item) { Item *item = p_item; while (item) { @@ -1618,6 +1740,49 @@ void RichTextLabel::push_table(int p_columns) { _add_item(item, true, true); } +void RichTextLabel::push_fade(int p_start_index, int p_length) { + ItemFade *item = memnew(ItemFade); + item->starting_index = p_start_index; + item->length = p_length; + _add_item(item, true); +} + +void RichTextLabel::push_shake(int p_strength = 10, float p_rate = 24.0f) { + ItemShake *item = memnew(ItemShake); + item->strength = p_strength; + item->rate = p_rate; + _add_item(item, true); +} + +void RichTextLabel::push_wave(float p_frequency = 1.0f, float p_amplitude = 10.0f) { + ItemWave *item = memnew(ItemWave); + item->frequency = p_frequency; + item->amplitude = p_amplitude; + _add_item(item, true); +} + +void RichTextLabel::push_tornado(float p_frequency = 1.0f, float p_radius = 10.0f) { + ItemTornado *item = memnew(ItemTornado); + item->frequency = p_frequency; + item->radius = p_radius; + _add_item(item, true); +} + +void RichTextLabel::push_rainbow(float p_saturation, float p_value, float p_frequency) { + ItemRainbow *item = memnew(ItemRainbow); + item->frequency = p_frequency; + item->saturation = p_saturation; + item->value = p_value; + _add_item(item, true); +} + +void RichTextLabel::push_customfx(String p_identifier, Dictionary p_environment) { + ItemCustomFX *item = memnew(ItemCustomFX); + item->identifier = p_identifier; + item->environment = p_environment; + _add_item(item, true); +} + void RichTextLabel::set_table_column_expand(int p_column, bool p_expand, int p_ratio) { ERR_FAIL_COND(current->type != ITEM_TABLE); @@ -1762,6 +1927,8 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) { bool in_bold = false; bool in_italics = false; + set_process_internal(false); + while (pos < p_bbcode.length()) { int brk_pos = p_bbcode.find("[", pos); @@ -1785,7 +1952,6 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) { } String tag = p_bbcode.substr(brk_pos + 1, brk_end - brk_pos - 1); - if (tag.begins_with("/") && tag_stack.size()) { bool tag_ok = tag_stack.size() && tag_stack.front()->get() == tag.substr(1, tag.length()); @@ -1798,9 +1964,8 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) { indent_level--; if (!tag_ok) { - - add_text("["); - pos++; + add_text("[" + tag); + pos = brk_end; continue; } @@ -1992,10 +2157,145 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) { pos = brk_end + 1; tag_stack.push_front("font"); - } else { + } else if (tag.begins_with("fade")) { + Vector<String> tags = tag.split(" ", false); + int startIndex = 0; + int length = 10; + + if (tags.size() > 1) { + tags.remove(0); + for (int i = 0; i < tags.size(); i++) { + String expr = tags[i]; + if (expr.begins_with("start=")) { + String start_str = expr.substr(6, expr.length()); + startIndex = start_str.to_int(); + } else if (expr.begins_with("length=")) { + String end_str = expr.substr(7, expr.length()); + length = end_str.to_int(); + } + } + } + + push_fade(startIndex, length); + pos = brk_end + 1; + tag_stack.push_front("fade"); + } else if (tag.begins_with("shake")) { + Vector<String> tags = tag.split(" ", false); + int strength = 5; + float rate = 20.0f; + + if (tags.size() > 1) { + tags.remove(0); + for (int i = 0; i < tags.size(); i++) { + String expr = tags[i]; + if (expr.begins_with("level=")) { + String str_str = expr.substr(6, expr.length()); + strength = str_str.to_int(); + } else if (expr.begins_with("rate=")) { + String rate_str = expr.substr(5, expr.length()); + rate = rate_str.to_float(); + } + } + } + + push_shake(strength, rate); + pos = brk_end + 1; + tag_stack.push_front("shake"); + set_process_internal(true); + } else if (tag.begins_with("wave")) { + Vector<String> tags = tag.split(" ", false); + float amplitude = 20.0f; + float period = 5.0f; + + if (tags.size() > 1) { + tags.remove(0); + for (int i = 0; i < tags.size(); i++) { + String expr = tags[i]; + if (expr.begins_with("amp=")) { + String amp_str = expr.substr(4, expr.length()); + amplitude = amp_str.to_float(); + } else if (expr.begins_with("freq=")) { + String period_str = expr.substr(5, expr.length()); + period = period_str.to_float(); + } + } + } - add_text("["); //ignore - pos = brk_pos + 1; + push_wave(period, amplitude); + pos = brk_end + 1; + tag_stack.push_front("wave"); + set_process_internal(true); + } else if (tag.begins_with("tornado")) { + Vector<String> tags = tag.split(" ", false); + float radius = 10.0f; + float frequency = 1.0f; + + if (tags.size() > 1) { + tags.remove(0); + for (int i = 0; i < tags.size(); i++) { + String expr = tags[i]; + if (expr.begins_with("radius=")) { + String amp_str = expr.substr(7, expr.length()); + radius = amp_str.to_float(); + } else if (expr.begins_with("freq=")) { + String period_str = expr.substr(5, expr.length()); + frequency = period_str.to_float(); + } + } + } + + push_tornado(frequency, radius); + pos = brk_end + 1; + tag_stack.push_front("tornado"); + set_process_internal(true); + } else if (tag.begins_with("rainbow")) { + Vector<String> tags = tag.split(" ", false); + float saturation = 0.8f; + float value = 0.8f; + float frequency = 1.0f; + + if (tags.size() > 1) { + tags.remove(0); + for (int i = 0; i < tags.size(); i++) { + String expr = tags[i]; + if (expr.begins_with("sat=")) { + String sat_str = expr.substr(4, expr.length()); + saturation = sat_str.to_float(); + } else if (expr.begins_with("val=")) { + String val_str = expr.substr(4, expr.length()); + value = val_str.to_float(); + } else if (expr.begins_with("freq=")) { + String freq_str = expr.substr(5, expr.length()); + frequency = freq_str.to_float(); + } + } + } + + push_rainbow(saturation, value, frequency); + pos = brk_end + 1; + tag_stack.push_front("rainbow"); + set_process_internal(true); + } else { + Vector<String> expr = tag.split(" ", false); + if (expr.size() < 1) { + add_text("["); + pos = brk_pos + 1; + } else { + String identifier = expr[0]; + expr.remove(0); + Dictionary properties = parse_expressions_for_values(expr); + Ref<RichTextEffect> effect = _get_custom_effect_by_code(identifier); + + if (!effect.is_null()) { + push_customfx(identifier, properties); + pos = brk_end + 1; + tag_stack.push_front(identifier); + set_process_internal(true); + } else { + add_text("["); //ignore + pos = brk_pos + 1; + } + } } } @@ -2204,6 +2504,34 @@ float RichTextLabel::get_percent_visible() const { return percent_visible; } +void RichTextLabel::set_effects(const Vector<Variant> &effects) { + custom_effects.clear(); + for (int i = 0; i < effects.size(); i++) { + Ref<RichTextEffect> effect = Ref<RichTextEffect>(effects[i]); + custom_effects.push_back(effect); + } + + parse_bbcode(bbcode); +} + +Vector<Variant> RichTextLabel::get_effects() { + Vector<Variant> r; + for (int i = 0; i < custom_effects.size(); i++) { + r.push_back(custom_effects[i].get_ref_ptr()); + } + return r; +} + +void RichTextLabel::install_effect(const Variant effect) { + Ref<RichTextEffect> rteffect; + rteffect = effect; + + if (rteffect.is_valid()) { + custom_effects.push_back(effect); + parse_bbcode(bbcode); + } +} + int RichTextLabel::get_content_height() { int total_height = 0; if (main->lines.size()) @@ -2280,6 +2608,12 @@ void RichTextLabel::_bind_methods() { ClassDB::bind_method(D_METHOD("get_content_height"), &RichTextLabel::get_content_height); + ClassDB::bind_method(D_METHOD("parse_expressions_for_values", "expressions"), &RichTextLabel::parse_expressions_for_values); + + ClassDB::bind_method(D_METHOD("set_effects", "effects"), &RichTextLabel::set_effects); + ClassDB::bind_method(D_METHOD("get_effects"), &RichTextLabel::get_effects); + ClassDB::bind_method(D_METHOD("install_effect", "effect"), &RichTextLabel::install_effect); + ADD_GROUP("BBCode", "bbcode_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "bbcode_enabled"), "set_use_bbcode", "is_using_bbcode"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "bbcode_text", PROPERTY_HINT_MULTILINE_TEXT), "set_bbcode", "get_bbcode"); @@ -2297,6 +2631,8 @@ void RichTextLabel::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "selection_enabled"), "set_selection_enabled", "is_selection_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "override_selected_font_color"), "set_override_selected_font_color", "is_overriding_selected_font_color"); + ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "custom_effects", PROPERTY_HINT_RESOURCE_TYPE, "17/17:RichTextEffect", (PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE), "RichTextEffect"), "set_effects", "get_effects"); + ADD_SIGNAL(MethodInfo("meta_clicked", PropertyInfo(Variant::NIL, "meta", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NIL_IS_VARIANT))); ADD_SIGNAL(MethodInfo("meta_hover_started", PropertyInfo(Variant::NIL, "meta", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NIL_IS_VARIANT))); ADD_SIGNAL(MethodInfo("meta_hover_ended", PropertyInfo(Variant::NIL, "meta", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NIL_IS_VARIANT))); @@ -2322,11 +2658,16 @@ void RichTextLabel::_bind_methods() { BIND_ENUM_CONSTANT(ITEM_INDENT); BIND_ENUM_CONSTANT(ITEM_LIST); BIND_ENUM_CONSTANT(ITEM_TABLE); + BIND_ENUM_CONSTANT(ITEM_FADE); + BIND_ENUM_CONSTANT(ITEM_SHAKE); + BIND_ENUM_CONSTANT(ITEM_WAVE); + BIND_ENUM_CONSTANT(ITEM_TORNADO); + BIND_ENUM_CONSTANT(ITEM_RAINBOW); + BIND_ENUM_CONSTANT(ITEM_CUSTOMFX); BIND_ENUM_CONSTANT(ITEM_META); } void RichTextLabel::set_visible_characters(int p_visible) { - visible_characters = p_visible; update(); } @@ -2358,6 +2699,77 @@ Size2 RichTextLabel::get_minimum_size() const { return Size2(); } +Ref<RichTextEffect> RichTextLabel::_get_custom_effect_by_code(String p_bbcode_identifier) { + Ref<RichTextEffect> r; + for (int i = 0; i < custom_effects.size(); i++) { + if (!custom_effects[i].is_valid()) + continue; + + if (custom_effects[i]->get_bbcode() == p_bbcode_identifier) { + r = custom_effects[i]; + } + } + + return r; +} + +Dictionary RichTextLabel::parse_expressions_for_values(Vector<String> p_expressions) { + Dictionary d = Dictionary(); + for (int i = 0; i < p_expressions.size(); i++) { + String expression = p_expressions[i]; + + Array a = Array(); + Vector<String> parts = expression.split("=", true); + String key = parts[0]; + if (parts.size() != 2) { + return d; + } + + Vector<String> values = parts[1].split(",", false); + + RegEx color = RegEx(); + color.compile("^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$"); + RegEx nodepath = RegEx(); + nodepath.compile("^\\$"); + RegEx boolean = RegEx(); + boolean.compile("^(true|false)$"); + RegEx decimal = RegEx(); + decimal.compile("^-?^.?\\d+(\\.\\d+?)?$"); + RegEx numerical = RegEx(); + numerical.compile("^\\d+$"); + + for (int j = 0; j < values.size(); j++) { + if (!color.search(values[j]).is_null()) { + a.append(Color::html(values[j])); + } else if (!nodepath.search(values[j]).is_null()) { + if (values[j].begins_with("$")) { + String v = values[j].substr(1, values[j].length()); + a.append(NodePath(v)); + } + } else if (!boolean.search(values[j]).is_null()) { + if (values[j] == "true") { + a.append(true); + } else if (values[j] == "false") { + a.append(false); + } + } else if (!decimal.search(values[j]).is_null()) { + a.append(values[j].to_double()); + } else if (!numerical.search(values[j]).is_null()) { + a.append(values[j].to_int()); + } else { + a.append(values[j]); + } + } + + if (values.size() > 1) { + d[key] = a; + } else if (values.size() == 1) { + d[key] = a[0]; + } + } + return d; +} + RichTextLabel::RichTextLabel() { main = memnew(ItemFrame); diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h index 21d099c37a..6755f9ef2a 100644 --- a/scene/gui/rich_text_label.h +++ b/scene/gui/rich_text_label.h @@ -31,6 +31,7 @@ #ifndef RICH_TEXT_LABEL_H #define RICH_TEXT_LABEL_H +#include "rich_text_effect.h" #include "scene/gui/scroll_bar.h" class RichTextLabel : public Control { @@ -67,7 +68,13 @@ public: ITEM_INDENT, ITEM_LIST, ITEM_TABLE, - ITEM_META + ITEM_FADE, + ITEM_SHAKE, + ITEM_WAVE, + ITEM_TORNADO, + ITEM_RAINBOW, + ITEM_META, + ITEM_CUSTOMFX }; protected: @@ -96,7 +103,7 @@ private: } }; - struct Item { + struct Item : public Object { int index; Item *parent; @@ -214,6 +221,101 @@ private: ItemTable() { type = ITEM_TABLE; } }; + struct ItemFade : public Item { + int starting_index; + int length; + + ItemFade() { type = ITEM_FADE; } + }; + + struct ItemFX : public Item { + float elapsed_time; + + ItemFX() { + elapsed_time = 0.0f; + } + }; + + struct ItemShake : public ItemFX { + int strength; + float rate; + uint64_t _current_rng; + uint64_t _previous_rng; + + ItemShake() { + strength = 0; + rate = 0.0f; + _current_rng = 0; + type = ITEM_SHAKE; + } + + void reroll_random() { + _previous_rng = _current_rng; + _current_rng = Math::rand(); + } + + uint64_t offset_random(int index) { + return (_current_rng >> (index % 64)) | + (_current_rng << (64 - (index % 64))); + } + + uint64_t offset_previous_random(int index) { + return (_previous_rng >> (index % 64)) | + (_previous_rng << (64 - (index % 64))); + } + }; + + struct ItemWave : public ItemFX { + float frequency; + float amplitude; + + ItemWave() { + frequency = 1.0f; + amplitude = 1.0f; + type = ITEM_WAVE; + } + }; + + struct ItemTornado : public ItemFX { + float radius; + float frequency; + + ItemTornado() { + radius = 1.0f; + frequency = 1.0f; + type = ITEM_TORNADO; + } + }; + + struct ItemRainbow : public ItemFX { + float saturation; + float value; + float frequency; + + ItemRainbow() { + saturation = 0.8f; + value = 0.8f; + frequency = 1.0f; + type = ITEM_RAINBOW; + } + }; + + struct ItemCustomFX : public ItemFX { + String identifier; + Dictionary environment; + + ItemCustomFX() { + identifier = ""; + environment = Dictionary(); + type = ITEM_CUSTOMFX; + } + + virtual ~ItemCustomFX() { + _clear_children(); + environment.clear(); + } + }; + ItemFrame *main; Item *current; ItemFrame *current_frame; @@ -239,6 +341,8 @@ private: ItemMeta *meta_hovering; Variant current_meta; + Vector<Ref<RichTextEffect> > custom_effects; + void _invalidate_current_line(ItemFrame *p_frame); void _validate_line_caches(ItemFrame *p_frame); @@ -246,7 +350,6 @@ private: void _remove_item(Item *p_item, const int p_line, const int p_subitem_line); struct ProcessState { - int line_width; }; @@ -287,8 +390,36 @@ private: bool _find_strikethrough(Item *p_item); bool _find_meta(Item *p_item, Variant *r_meta, ItemMeta **r_item = NULL); bool _find_layout_subitem(Item *from, Item *to); + bool _find_by_type(Item *p_item, ItemType p_type); + template <typename T> + T *_fetch_by_type(Item *p_item, ItemType p_type) { + Item *item = p_item; + T *result = NULL; + while (item) { + if (item->type == p_type) { + result = Object::cast_to<T>(item); + if (result) + return result; + } + item = item->parent; + } + + return result; + }; + template <typename T> + void _fetch_item_stack(Item *p_item, Vector<T *> &r_stack) { + Item *item = p_item; + while (item) { + T *found = Object::cast_to<T>(item); + if (found) { + r_stack.push_back(found); + } + item = item->parent; + } + } void _update_scroll(); + void _update_fx(ItemFrame *p_frame, float p_delta_time); void _scroll_changed(double); void _gui_input(Ref<InputEvent> p_event); @@ -296,6 +427,8 @@ private: Item *_get_prev_item(Item *p_item, bool p_free = false); Rect2 _get_text_rect(); + Ref<RichTextEffect> _get_custom_effect_by_code(String p_bbcode_identifier); + virtual Dictionary parse_expressions_for_values(Vector<String> p_expressions); bool use_bbcode; String bbcode; @@ -322,6 +455,12 @@ public: void push_list(ListType p_list); void push_meta(const Variant &p_meta); void push_table(int p_columns); + void push_fade(int p_start_index, int p_length); + void push_shake(int p_level, float p_rate); + void push_wave(float p_frequency, float p_amplitude); + void push_tornado(float p_frequency, float p_radius); + void push_rainbow(float p_saturation, float p_value, float p_frequency); + void push_customfx(String p_identifier, Dictionary p_environment); void set_table_column_expand(int p_column, bool p_expand, int p_ratio = 1); int get_current_table_column() const; void push_cell(); @@ -380,6 +519,11 @@ public: void set_percent_visible(float p_percent); float get_percent_visible() const; + void set_effects(const Vector<Variant> &effects); + Vector<Variant> get_effects(); + + void install_effect(const Variant effect); + void set_fixed_size_to_width(int p_width); virtual Size2 get_minimum_size() const; diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index b5f1fd9516..5173b83407 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -1738,7 +1738,9 @@ void TextEdit::_notification(int p_what) { } break; case NOTIFICATION_FOCUS_ENTER: { - if (!caret_blink_enabled) { + if (caret_blink_enabled) { + caret_blink_timer->start(); + } else { draw_caret = true; } @@ -1751,6 +1753,10 @@ void TextEdit::_notification(int p_what) { } break; case NOTIFICATION_FOCUS_EXIT: { + if (caret_blink_enabled) { + caret_blink_timer->stop(); + } + OS::get_singleton()->set_ime_position(Point2()); OS::get_singleton()->set_ime_active(false); ime_text = ""; @@ -4426,11 +4432,14 @@ bool TextEdit::cursor_get_blink_enabled() const { void TextEdit::cursor_set_blink_enabled(const bool p_enabled) { caret_blink_enabled = p_enabled; - if (p_enabled) { - caret_blink_timer->start(); - } else { - caret_blink_timer->stop(); + if (has_focus()) { + if (p_enabled) { + caret_blink_timer->start(); + } else { + caret_blink_timer->stop(); + } } + draw_caret = true; } @@ -4848,10 +4857,12 @@ int TextEdit::get_max_chars() const { void TextEdit::_reset_caret_blink_timer() { if (caret_blink_enabled) { - caret_blink_timer->stop(); - caret_blink_timer->start(); draw_caret = true; - update(); + if (has_focus()) { + caret_blink_timer->stop(); + caret_blink_timer->start(); + update(); + } } } diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index 6c89016ea3..5483fe1d6f 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -2096,6 +2096,7 @@ SceneTree::SceneTree() { if (ScriptDebugger::get_singleton()) { ScriptDebugger::get_singleton()->set_request_scene_tree_message_func(_debugger_request_tree, this); + ScriptDebugger::get_singleton()->set_multiplayer(multiplayer); } root->set_physics_object_picking(GLOBAL_DEF("physics/common/enable_object_picking", true)); diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp index 06d84302a3..e3af521e8c 100644 --- a/scene/register_scene_types.cpp +++ b/scene/register_scene_types.cpp @@ -101,6 +101,7 @@ #include "scene/gui/popup_menu.h" #include "scene/gui/progress_bar.h" #include "scene/gui/reference_rect.h" +#include "scene/gui/rich_text_effect.h" #include "scene/gui/rich_text_label.h" #include "scene/gui/scroll_bar.h" #include "scene/gui/scroll_container.h" @@ -343,6 +344,8 @@ void register_scene_types() { ClassDB::register_class<ColorPicker>(); ClassDB::register_class<ColorPickerButton>(); ClassDB::register_class<RichTextLabel>(); + ClassDB::register_class<RichTextEffect>(); + ClassDB::register_class<CharFXTransform>(); ClassDB::register_class<PopupDialog>(); ClassDB::register_class<WindowDialog>(); ClassDB::register_class<AcceptDialog>(); @@ -528,6 +531,7 @@ void register_scene_types() { ClassDB::register_class<VisualShaderNodeCubeMapUniform>(); ClassDB::register_class<VisualShaderNodeIf>(); ClassDB::register_class<VisualShaderNodeSwitch>(); + ClassDB::register_class<VisualShaderNodeScalarSwitch>(); ClassDB::register_class<VisualShaderNodeFresnel>(); ClassDB::register_class<VisualShaderNodeExpression>(); ClassDB::register_class<VisualShaderNodeGlobalExpression>(); diff --git a/scene/resources/mesh_data_tool.cpp b/scene/resources/mesh_data_tool.cpp index 7cd765fb5d..0c39c3cbb1 100644 --- a/scene/resources/mesh_data_tool.cpp +++ b/scene/resources/mesh_data_tool.cpp @@ -165,11 +165,12 @@ Error MeshDataTool::create_from_surface(const Ref<ArrayMesh> &p_mesh, int p_surf e.vertex[0] = edge.x; e.vertex[1] = edge.y; edges.push_back(e); + v[j]->edges.push_back(face.edges[j]); + v[(j + 1) % 3]->edges.push_back(face.edges[j]); } edges.write[face.edges[j]].faces.push_back(fidx); v[j]->faces.push_back(fidx); - v[j]->edges.push_back(face.edges[j]); } faces.push_back(face); diff --git a/scene/resources/visual_shader.cpp b/scene/resources/visual_shader.cpp index e85609468b..f5ea6adc85 100644 --- a/scene/resources/visual_shader.cpp +++ b/scene/resources/visual_shader.cpp @@ -1083,7 +1083,7 @@ Error VisualShader::_write_node(Type type, StringBuilder &global_code, StringBui } else if (defval.get_type() == Variant::BOOL) { bool val = defval; inputs[i] = "n_in" + itos(node) + "p" + itos(i); - code += "\nbool " + inputs[i] + " = " + (val ? "true" : "false") + ";\n"; + code += "\tbool " + inputs[i] + " = " + (val ? "true" : "false") + ";\n"; } else if (defval.get_type() == Variant::VECTOR3) { Vector3 val = defval; inputs[i] = "n_in" + itos(node) + "p" + itos(i); @@ -1399,6 +1399,7 @@ const VisualShaderNodeInput::Port VisualShaderNodeInput::ports[] = { { Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_TRANSFORM, "inv_projection", "INV_PROJECTION_MATRIX" }, { Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_SCALAR, "time", "TIME" }, { Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR, "viewport_size", "vec3(VIEWPORT_SIZE, 0)" }, + { Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_BOOLEAN, "output_is_srgb", "OUTPUT_IS_SRGB" }, // Spatial, Fragment { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR, "fragcoord", "FRAGCOORD.xyz" }, @@ -1423,6 +1424,8 @@ const VisualShaderNodeInput::Port VisualShaderNodeInput::ports[] = { { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_TRANSFORM, "inv_projection", "INV_PROJECTION_MATRIX" }, { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SCALAR, "time", "TIME" }, { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR, "viewport_size", "vec3(VIEWPORT_SIZE, 0.0)" }, + { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_BOOLEAN, "output_is_srgb", "OUTPUT_IS_SRGB" }, + { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_BOOLEAN, "front_facing", "FRONT_FACING" }, // Spatial, Light { Shader::MODE_SPATIAL, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "fragcoord", "FRAGCOORD.xyz" }, @@ -1444,6 +1447,7 @@ const VisualShaderNodeInput::Port VisualShaderNodeInput::ports[] = { { Shader::MODE_SPATIAL, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_TRANSFORM, "inv_projection", "INV_PROJECTION_MATRIX" }, { Shader::MODE_SPATIAL, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_SCALAR, "time", "TIME" }, { Shader::MODE_SPATIAL, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "viewport_size", "vec3(VIEWPORT_SIZE, 0.0)" }, + { Shader::MODE_SPATIAL, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_BOOLEAN, "output_is_srgb", "OUTPUT_IS_SRGB" }, // Canvas Item, Vertex { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR, "vertex", "vec3(VERTEX,0.0)" }, { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR, "uv", "vec3(UV,0.0)" }, @@ -2466,6 +2470,7 @@ String VisualShaderNodeExpression::generate_code(Shader::Mode p_mode, VisualShad pre_symbols.push_back(";"); pre_symbols.push_back("{"); pre_symbols.push_back("["); + pre_symbols.push_back("]"); pre_symbols.push_back("("); pre_symbols.push_back(" "); pre_symbols.push_back("-"); @@ -2485,6 +2490,7 @@ String VisualShaderNodeExpression::generate_code(Shader::Mode p_mode, VisualShad post_symbols.push_back(","); post_symbols.push_back(";"); post_symbols.push_back("}"); + post_symbols.push_back("["); post_symbols.push_back("]"); post_symbols.push_back(")"); post_symbols.push_back(" "); diff --git a/scene/resources/visual_shader_nodes.cpp b/scene/resources/visual_shader_nodes.cpp index 9195d80cfc..b7173b157e 100644 --- a/scene/resources/visual_shader_nodes.cpp +++ b/scene/resources/visual_shader_nodes.cpp @@ -29,6 +29,7 @@ /*************************************************************************/ #include "visual_shader_nodes.h" + ////////////// Scalar String VisualShaderNodeScalarConstant::get_caption() const { @@ -38,9 +39,11 @@ String VisualShaderNodeScalarConstant::get_caption() const { int VisualShaderNodeScalarConstant::get_input_port_count() const { return 0; } + VisualShaderNodeScalarConstant::PortType VisualShaderNodeScalarConstant::get_input_port_type(int p_port) const { return PORT_TYPE_SCALAR; } + String VisualShaderNodeScalarConstant::get_input_port_name(int p_port) const { return String(); } @@ -48,9 +51,11 @@ String VisualShaderNodeScalarConstant::get_input_port_name(int p_port) const { int VisualShaderNodeScalarConstant::get_output_port_count() const { return 1; } + VisualShaderNodeScalarConstant::PortType VisualShaderNodeScalarConstant::get_output_port_type(int p_port) const { return PORT_TYPE_SCALAR; } + String VisualShaderNodeScalarConstant::get_output_port_name(int p_port) const { return ""; //no output port means the editor will be used as port } @@ -158,9 +163,11 @@ String VisualShaderNodeColorConstant::get_caption() const { int VisualShaderNodeColorConstant::get_input_port_count() const { return 0; } + VisualShaderNodeColorConstant::PortType VisualShaderNodeColorConstant::get_input_port_type(int p_port) const { return PORT_TYPE_VECTOR; } + String VisualShaderNodeColorConstant::get_input_port_name(int p_port) const { return String(); } @@ -168,9 +175,11 @@ String VisualShaderNodeColorConstant::get_input_port_name(int p_port) const { int VisualShaderNodeColorConstant::get_output_port_count() const { return 2; } + VisualShaderNodeColorConstant::PortType VisualShaderNodeColorConstant::get_output_port_type(int p_port) const { return p_port == 0 ? PORT_TYPE_VECTOR : PORT_TYPE_SCALAR; } + String VisualShaderNodeColorConstant::get_output_port_name(int p_port) const { return p_port == 0 ? "" : "alpha"; //no output port means the editor will be used as port } @@ -222,9 +231,11 @@ String VisualShaderNodeVec3Constant::get_caption() const { int VisualShaderNodeVec3Constant::get_input_port_count() const { return 0; } + VisualShaderNodeVec3Constant::PortType VisualShaderNodeVec3Constant::get_input_port_type(int p_port) const { return PORT_TYPE_VECTOR; } + String VisualShaderNodeVec3Constant::get_input_port_name(int p_port) const { return String(); } @@ -232,9 +243,11 @@ String VisualShaderNodeVec3Constant::get_input_port_name(int p_port) const { int VisualShaderNodeVec3Constant::get_output_port_count() const { return 1; } + VisualShaderNodeVec3Constant::PortType VisualShaderNodeVec3Constant::get_output_port_type(int p_port) const { return PORT_TYPE_VECTOR; } + String VisualShaderNodeVec3Constant::get_output_port_name(int p_port) const { return ""; //no output port means the editor will be used as port } @@ -280,9 +293,11 @@ String VisualShaderNodeTransformConstant::get_caption() const { int VisualShaderNodeTransformConstant::get_input_port_count() const { return 0; } + VisualShaderNodeTransformConstant::PortType VisualShaderNodeTransformConstant::get_input_port_type(int p_port) const { return PORT_TYPE_VECTOR; } + String VisualShaderNodeTransformConstant::get_input_port_name(int p_port) const { return String(); } @@ -290,9 +305,11 @@ String VisualShaderNodeTransformConstant::get_input_port_name(int p_port) const int VisualShaderNodeTransformConstant::get_output_port_count() const { return 1; } + VisualShaderNodeTransformConstant::PortType VisualShaderNodeTransformConstant::get_output_port_type(int p_port) const { return PORT_TYPE_TRANSFORM; } + String VisualShaderNodeTransformConstant::get_output_port_name(int p_port) const { return ""; //no output port means the editor will be used as port } @@ -346,9 +363,11 @@ String VisualShaderNodeTexture::get_caption() const { int VisualShaderNodeTexture::get_input_port_count() const { return 2; } + VisualShaderNodeTexture::PortType VisualShaderNodeTexture::get_input_port_type(int p_port) const { return p_port == 0 ? PORT_TYPE_VECTOR : PORT_TYPE_SCALAR; } + String VisualShaderNodeTexture::get_input_port_name(int p_port) const { return p_port == 0 ? "uv" : "lod"; } @@ -356,11 +375,13 @@ String VisualShaderNodeTexture::get_input_port_name(int p_port) const { int VisualShaderNodeTexture::get_output_port_count() const { return 2; } + VisualShaderNodeTexture::PortType VisualShaderNodeTexture::get_output_port_type(int p_port) const { if (p_port == 0 && source == SOURCE_DEPTH) return PORT_TYPE_SCALAR; return p_port == 0 ? PORT_TYPE_VECTOR : PORT_TYPE_SCALAR; } + String VisualShaderNodeTexture::get_output_port_name(int p_port) const { if (p_port == 0 && source == SOURCE_DEPTH) return "depth"; @@ -632,9 +653,11 @@ String VisualShaderNodeCubeMap::get_caption() const { int VisualShaderNodeCubeMap::get_input_port_count() const { return 2; } + VisualShaderNodeCubeMap::PortType VisualShaderNodeCubeMap::get_input_port_type(int p_port) const { return p_port == 0 ? PORT_TYPE_VECTOR : PORT_TYPE_SCALAR; } + String VisualShaderNodeCubeMap::get_input_port_name(int p_port) const { return p_port == 0 ? "uv" : "lod"; } @@ -642,9 +665,11 @@ String VisualShaderNodeCubeMap::get_input_port_name(int p_port) const { int VisualShaderNodeCubeMap::get_output_port_count() const { return 2; } + VisualShaderNodeCubeMap::PortType VisualShaderNodeCubeMap::get_output_port_type(int p_port) const { return p_port == 0 ? PORT_TYPE_VECTOR : PORT_TYPE_SCALAR; } + String VisualShaderNodeCubeMap::get_output_port_name(int p_port) const { return p_port == 0 ? "rgb" : "alpha"; } @@ -735,6 +760,7 @@ void VisualShaderNodeCubeMap::_bind_methods() { VisualShaderNodeCubeMap::VisualShaderNodeCubeMap() { texture_type = TYPE_DATA; } + ////////////// Scalar Op String VisualShaderNodeScalarOp::get_caption() const { @@ -744,9 +770,11 @@ String VisualShaderNodeScalarOp::get_caption() const { int VisualShaderNodeScalarOp::get_input_port_count() const { return 2; } + VisualShaderNodeScalarOp::PortType VisualShaderNodeScalarOp::get_input_port_type(int p_port) const { return PORT_TYPE_SCALAR; } + String VisualShaderNodeScalarOp::get_input_port_name(int p_port) const { return p_port == 0 ? "a" : "b"; } @@ -754,9 +782,11 @@ String VisualShaderNodeScalarOp::get_input_port_name(int p_port) const { int VisualShaderNodeScalarOp::get_output_port_count() const { return 1; } + VisualShaderNodeScalarOp::PortType VisualShaderNodeScalarOp::get_output_port_type(int p_port) const { return PORT_TYPE_SCALAR; } + String VisualShaderNodeScalarOp::get_output_port_name(int p_port) const { return "op"; //no output port means the editor will be used as port } @@ -832,9 +862,11 @@ String VisualShaderNodeVectorOp::get_caption() const { int VisualShaderNodeVectorOp::get_input_port_count() const { return 2; } + VisualShaderNodeVectorOp::PortType VisualShaderNodeVectorOp::get_input_port_type(int p_port) const { return PORT_TYPE_VECTOR; } + String VisualShaderNodeVectorOp::get_input_port_name(int p_port) const { return p_port == 0 ? "a" : "b"; } @@ -842,9 +874,11 @@ String VisualShaderNodeVectorOp::get_input_port_name(int p_port) const { int VisualShaderNodeVectorOp::get_output_port_count() const { return 1; } + VisualShaderNodeVectorOp::PortType VisualShaderNodeVectorOp::get_output_port_type(int p_port) const { return PORT_TYPE_VECTOR; } + String VisualShaderNodeVectorOp::get_output_port_name(int p_port) const { return "op"; //no output port means the editor will be used as port } @@ -924,9 +958,11 @@ String VisualShaderNodeColorOp::get_caption() const { int VisualShaderNodeColorOp::get_input_port_count() const { return 2; } + VisualShaderNodeColorOp::PortType VisualShaderNodeColorOp::get_input_port_type(int p_port) const { return PORT_TYPE_VECTOR; } + String VisualShaderNodeColorOp::get_input_port_name(int p_port) const { return p_port == 0 ? "a" : "b"; } @@ -934,9 +970,11 @@ String VisualShaderNodeColorOp::get_input_port_name(int p_port) const { int VisualShaderNodeColorOp::get_output_port_count() const { return 1; } + VisualShaderNodeColorOp::PortType VisualShaderNodeColorOp::get_output_port_type(int p_port) const { return PORT_TYPE_VECTOR; } + String VisualShaderNodeColorOp::get_output_port_name(int p_port) const { return "op"; //no output port means the editor will be used as port } @@ -1072,9 +1110,11 @@ String VisualShaderNodeTransformMult::get_caption() const { int VisualShaderNodeTransformMult::get_input_port_count() const { return 2; } + VisualShaderNodeTransformMult::PortType VisualShaderNodeTransformMult::get_input_port_type(int p_port) const { return PORT_TYPE_TRANSFORM; } + String VisualShaderNodeTransformMult::get_input_port_name(int p_port) const { return p_port == 0 ? "a" : "b"; } @@ -1082,9 +1122,11 @@ String VisualShaderNodeTransformMult::get_input_port_name(int p_port) const { int VisualShaderNodeTransformMult::get_output_port_count() const { return 1; } + VisualShaderNodeTransformMult::PortType VisualShaderNodeTransformMult::get_output_port_type(int p_port) const { return PORT_TYPE_TRANSFORM; } + String VisualShaderNodeTransformMult::get_output_port_name(int p_port) const { return "mult"; //no output port means the editor will be used as port } @@ -1147,9 +1189,11 @@ String VisualShaderNodeTransformVecMult::get_caption() const { int VisualShaderNodeTransformVecMult::get_input_port_count() const { return 2; } + VisualShaderNodeTransformVecMult::PortType VisualShaderNodeTransformVecMult::get_input_port_type(int p_port) const { return p_port == 0 ? PORT_TYPE_TRANSFORM : PORT_TYPE_VECTOR; } + String VisualShaderNodeTransformVecMult::get_input_port_name(int p_port) const { return p_port == 0 ? "a" : "b"; } @@ -1157,9 +1201,11 @@ String VisualShaderNodeTransformVecMult::get_input_port_name(int p_port) const { int VisualShaderNodeTransformVecMult::get_output_port_count() const { return 1; } + VisualShaderNodeTransformVecMult::PortType VisualShaderNodeTransformVecMult::get_output_port_type(int p_port) const { return PORT_TYPE_VECTOR; } + String VisualShaderNodeTransformVecMult::get_output_port_name(int p_port) const { return ""; //no output port means the editor will be used as port } @@ -1221,9 +1267,11 @@ String VisualShaderNodeScalarFunc::get_caption() const { int VisualShaderNodeScalarFunc::get_input_port_count() const { return 1; } + VisualShaderNodeScalarFunc::PortType VisualShaderNodeScalarFunc::get_input_port_type(int p_port) const { return PORT_TYPE_SCALAR; } + String VisualShaderNodeScalarFunc::get_input_port_name(int p_port) const { return ""; } @@ -1231,9 +1279,11 @@ String VisualShaderNodeScalarFunc::get_input_port_name(int p_port) const { int VisualShaderNodeScalarFunc::get_output_port_count() const { return 1; } + VisualShaderNodeScalarFunc::PortType VisualShaderNodeScalarFunc::get_output_port_type(int p_port) const { return PORT_TYPE_SCALAR; } + String VisualShaderNodeScalarFunc::get_output_port_name(int p_port) const { return ""; //no output port means the editor will be used as port } @@ -1350,9 +1400,11 @@ String VisualShaderNodeVectorFunc::get_caption() const { int VisualShaderNodeVectorFunc::get_input_port_count() const { return 1; } + VisualShaderNodeVectorFunc::PortType VisualShaderNodeVectorFunc::get_input_port_type(int p_port) const { return PORT_TYPE_VECTOR; } + String VisualShaderNodeVectorFunc::get_input_port_name(int p_port) const { return ""; } @@ -1360,9 +1412,11 @@ String VisualShaderNodeVectorFunc::get_input_port_name(int p_port) const { int VisualShaderNodeVectorFunc::get_output_port_count() const { return 1; } + VisualShaderNodeVectorFunc::PortType VisualShaderNodeVectorFunc::get_output_port_type(int p_port) const { return PORT_TYPE_VECTOR; } + String VisualShaderNodeVectorFunc::get_output_port_name(int p_port) const { return ""; //no output port means the editor will be used as port } @@ -1675,9 +1729,11 @@ String VisualShaderNodeDotProduct::get_caption() const { int VisualShaderNodeDotProduct::get_input_port_count() const { return 2; } + VisualShaderNodeDotProduct::PortType VisualShaderNodeDotProduct::get_input_port_type(int p_port) const { return PORT_TYPE_VECTOR; } + String VisualShaderNodeDotProduct::get_input_port_name(int p_port) const { return p_port == 0 ? "a" : "b"; } @@ -1685,9 +1741,11 @@ String VisualShaderNodeDotProduct::get_input_port_name(int p_port) const { int VisualShaderNodeDotProduct::get_output_port_count() const { return 1; } + VisualShaderNodeDotProduct::PortType VisualShaderNodeDotProduct::get_output_port_type(int p_port) const { return PORT_TYPE_SCALAR; } + String VisualShaderNodeDotProduct::get_output_port_name(int p_port) const { return "dot"; } @@ -1710,9 +1768,11 @@ String VisualShaderNodeVectorLen::get_caption() const { int VisualShaderNodeVectorLen::get_input_port_count() const { return 1; } + VisualShaderNodeVectorLen::PortType VisualShaderNodeVectorLen::get_input_port_type(int p_port) const { return PORT_TYPE_VECTOR; } + String VisualShaderNodeVectorLen::get_input_port_name(int p_port) const { return ""; } @@ -1720,9 +1780,11 @@ String VisualShaderNodeVectorLen::get_input_port_name(int p_port) const { int VisualShaderNodeVectorLen::get_output_port_count() const { return 1; } + VisualShaderNodeVectorLen::PortType VisualShaderNodeVectorLen::get_output_port_type(int p_port) const { return PORT_TYPE_SCALAR; } + String VisualShaderNodeVectorLen::get_output_port_name(int p_port) const { return "length"; } @@ -1745,7 +1807,7 @@ int VisualShaderNodeDeterminant::get_input_port_count() const { return 1; } -VisualShaderNodeScalarClamp::PortType VisualShaderNodeDeterminant::get_input_port_type(int p_port) const { +VisualShaderNodeDeterminant::PortType VisualShaderNodeDeterminant::get_input_port_type(int p_port) const { return PORT_TYPE_TRANSFORM; } @@ -1872,7 +1934,7 @@ int VisualShaderNodeVectorDerivativeFunc::get_output_port_count() const { return 1; } -VisualShaderNodeScalarDerivativeFunc::PortType VisualShaderNodeVectorDerivativeFunc::get_output_port_type(int p_port) const { +VisualShaderNodeVectorDerivativeFunc::PortType VisualShaderNodeVectorDerivativeFunc::get_output_port_type(int p_port) const { return PORT_TYPE_VECTOR; } @@ -2078,7 +2140,7 @@ int VisualShaderNodeOuterProduct::get_input_port_count() const { return 2; } -VisualShaderNodeFaceForward::PortType VisualShaderNodeOuterProduct::get_input_port_type(int p_port) const { +VisualShaderNodeOuterProduct::PortType VisualShaderNodeOuterProduct::get_input_port_type(int p_port) const { return PORT_TYPE_VECTOR; } @@ -2143,7 +2205,7 @@ int VisualShaderNodeVectorScalarStep::get_output_port_count() const { return 1; } -VisualShaderNodeVectorClamp::PortType VisualShaderNodeVectorScalarStep::get_output_port_type(int p_port) const { +VisualShaderNodeVectorScalarStep::PortType VisualShaderNodeVectorScalarStep::get_output_port_type(int p_port) const { return PORT_TYPE_VECTOR; } @@ -2234,7 +2296,7 @@ int VisualShaderNodeVectorSmoothStep::get_output_port_count() const { return 1; } -VisualShaderNodeVectorClamp::PortType VisualShaderNodeVectorSmoothStep::get_output_port_type(int p_port) const { +VisualShaderNodeVectorSmoothStep::PortType VisualShaderNodeVectorSmoothStep::get_output_port_type(int p_port) const { return PORT_TYPE_VECTOR; } @@ -2285,7 +2347,7 @@ int VisualShaderNodeVectorScalarSmoothStep::get_output_port_count() const { return 1; } -VisualShaderNodeVectorClamp::PortType VisualShaderNodeVectorScalarSmoothStep::get_output_port_type(int p_port) const { +VisualShaderNodeVectorScalarSmoothStep::PortType VisualShaderNodeVectorScalarSmoothStep::get_output_port_type(int p_port) const { return PORT_TYPE_VECTOR; } @@ -2540,6 +2602,7 @@ VisualShaderNodeVectorScalarMix::VisualShaderNodeVectorScalarMix() { } ////////////// Vector Compose + String VisualShaderNodeVectorCompose::get_caption() const { return "VectorCompose"; } @@ -2547,9 +2610,11 @@ String VisualShaderNodeVectorCompose::get_caption() const { int VisualShaderNodeVectorCompose::get_input_port_count() const { return 3; } + VisualShaderNodeVectorCompose::PortType VisualShaderNodeVectorCompose::get_input_port_type(int p_port) const { return PORT_TYPE_SCALAR; } + String VisualShaderNodeVectorCompose::get_input_port_name(int p_port) const { if (p_port == 0) { return "x"; @@ -2563,9 +2628,11 @@ String VisualShaderNodeVectorCompose::get_input_port_name(int p_port) const { int VisualShaderNodeVectorCompose::get_output_port_count() const { return 1; } + VisualShaderNodeVectorCompose::PortType VisualShaderNodeVectorCompose::get_output_port_type(int p_port) const { return PORT_TYPE_VECTOR; } + String VisualShaderNodeVectorCompose::get_output_port_name(int p_port) const { return "vec"; } @@ -2590,9 +2657,11 @@ String VisualShaderNodeTransformCompose::get_caption() const { int VisualShaderNodeTransformCompose::get_input_port_count() const { return 4; } + VisualShaderNodeTransformCompose::PortType VisualShaderNodeTransformCompose::get_input_port_type(int p_port) const { return PORT_TYPE_VECTOR; } + String VisualShaderNodeTransformCompose::get_input_port_name(int p_port) const { if (p_port == 0) { return "x"; @@ -2608,9 +2677,11 @@ String VisualShaderNodeTransformCompose::get_input_port_name(int p_port) const { int VisualShaderNodeTransformCompose::get_output_port_count() const { return 1; } + VisualShaderNodeTransformCompose::PortType VisualShaderNodeTransformCompose::get_output_port_type(int p_port) const { return PORT_TYPE_TRANSFORM; } + String VisualShaderNodeTransformCompose::get_output_port_name(int p_port) const { return "xform"; } @@ -2635,9 +2706,11 @@ String VisualShaderNodeVectorDecompose::get_caption() const { int VisualShaderNodeVectorDecompose::get_input_port_count() const { return 1; } + VisualShaderNodeVectorDecompose::PortType VisualShaderNodeVectorDecompose::get_input_port_type(int p_port) const { return PORT_TYPE_VECTOR; } + String VisualShaderNodeVectorDecompose::get_input_port_name(int p_port) const { return "vec"; } @@ -2645,9 +2718,11 @@ String VisualShaderNodeVectorDecompose::get_input_port_name(int p_port) const { int VisualShaderNodeVectorDecompose::get_output_port_count() const { return 3; } + VisualShaderNodeVectorDecompose::PortType VisualShaderNodeVectorDecompose::get_output_port_type(int p_port) const { return PORT_TYPE_SCALAR; } + String VisualShaderNodeVectorDecompose::get_output_port_name(int p_port) const { if (p_port == 0) { return "x"; @@ -2679,9 +2754,11 @@ String VisualShaderNodeTransformDecompose::get_caption() const { int VisualShaderNodeTransformDecompose::get_input_port_count() const { return 1; } + VisualShaderNodeTransformDecompose::PortType VisualShaderNodeTransformDecompose::get_input_port_type(int p_port) const { return PORT_TYPE_TRANSFORM; } + String VisualShaderNodeTransformDecompose::get_input_port_name(int p_port) const { return "xform"; } @@ -2689,9 +2766,11 @@ String VisualShaderNodeTransformDecompose::get_input_port_name(int p_port) const int VisualShaderNodeTransformDecompose::get_output_port_count() const { return 4; } + VisualShaderNodeTransformDecompose::PortType VisualShaderNodeTransformDecompose::get_output_port_type(int p_port) const { return PORT_TYPE_VECTOR; } + String VisualShaderNodeTransformDecompose::get_output_port_name(int p_port) const { if (p_port == 0) { return "x"; @@ -2726,9 +2805,11 @@ String VisualShaderNodeScalarUniform::get_caption() const { int VisualShaderNodeScalarUniform::get_input_port_count() const { return 0; } + VisualShaderNodeScalarUniform::PortType VisualShaderNodeScalarUniform::get_input_port_type(int p_port) const { return PORT_TYPE_SCALAR; } + String VisualShaderNodeScalarUniform::get_input_port_name(int p_port) const { return String(); } @@ -2736,9 +2817,11 @@ String VisualShaderNodeScalarUniform::get_input_port_name(int p_port) const { int VisualShaderNodeScalarUniform::get_output_port_count() const { return 1; } + VisualShaderNodeScalarUniform::PortType VisualShaderNodeScalarUniform::get_output_port_type(int p_port) const { return PORT_TYPE_SCALAR; } + String VisualShaderNodeScalarUniform::get_output_port_name(int p_port) const { return ""; //no output port means the editor will be used as port } @@ -2746,6 +2829,7 @@ String VisualShaderNodeScalarUniform::get_output_port_name(int p_port) const { String VisualShaderNodeScalarUniform::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const { return "uniform float " + get_uniform_name() + ";\n"; } + String VisualShaderNodeScalarUniform::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { return "\t" + p_output_vars[0] + " = " + get_uniform_name() + ";\n"; } @@ -2803,9 +2887,11 @@ String VisualShaderNodeColorUniform::get_caption() const { int VisualShaderNodeColorUniform::get_input_port_count() const { return 0; } + VisualShaderNodeColorUniform::PortType VisualShaderNodeColorUniform::get_input_port_type(int p_port) const { return PORT_TYPE_VECTOR; } + String VisualShaderNodeColorUniform::get_input_port_name(int p_port) const { return String(); } @@ -2813,9 +2899,11 @@ String VisualShaderNodeColorUniform::get_input_port_name(int p_port) const { int VisualShaderNodeColorUniform::get_output_port_count() const { return 2; } + VisualShaderNodeColorUniform::PortType VisualShaderNodeColorUniform::get_output_port_type(int p_port) const { return p_port == 0 ? PORT_TYPE_VECTOR : PORT_TYPE_SCALAR; } + String VisualShaderNodeColorUniform::get_output_port_name(int p_port) const { return p_port == 0 ? "color" : "alpha"; //no output port means the editor will be used as port } @@ -2843,9 +2931,11 @@ String VisualShaderNodeVec3Uniform::get_caption() const { int VisualShaderNodeVec3Uniform::get_input_port_count() const { return 0; } + VisualShaderNodeVec3Uniform::PortType VisualShaderNodeVec3Uniform::get_input_port_type(int p_port) const { return PORT_TYPE_VECTOR; } + String VisualShaderNodeVec3Uniform::get_input_port_name(int p_port) const { return String(); } @@ -2853,12 +2943,15 @@ String VisualShaderNodeVec3Uniform::get_input_port_name(int p_port) const { int VisualShaderNodeVec3Uniform::get_output_port_count() const { return 1; } + VisualShaderNodeVec3Uniform::PortType VisualShaderNodeVec3Uniform::get_output_port_type(int p_port) const { return PORT_TYPE_VECTOR; } + String VisualShaderNodeVec3Uniform::get_output_port_name(int p_port) const { return ""; //no output port means the editor will be used as port } + String VisualShaderNodeVec3Uniform::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const { return "uniform vec3 " + get_uniform_name() + ";\n"; } @@ -2879,9 +2972,11 @@ String VisualShaderNodeTransformUniform::get_caption() const { int VisualShaderNodeTransformUniform::get_input_port_count() const { return 0; } + VisualShaderNodeTransformUniform::PortType VisualShaderNodeTransformUniform::get_input_port_type(int p_port) const { return PORT_TYPE_VECTOR; } + String VisualShaderNodeTransformUniform::get_input_port_name(int p_port) const { return String(); } @@ -2889,12 +2984,15 @@ String VisualShaderNodeTransformUniform::get_input_port_name(int p_port) const { int VisualShaderNodeTransformUniform::get_output_port_count() const { return 1; } + VisualShaderNodeTransformUniform::PortType VisualShaderNodeTransformUniform::get_output_port_type(int p_port) const { return PORT_TYPE_TRANSFORM; } + String VisualShaderNodeTransformUniform::get_output_port_name(int p_port) const { return ""; //no output port means the editor will be used as port } + String VisualShaderNodeTransformUniform::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const { return "uniform mat4 " + get_uniform_name() + ";\n"; } @@ -2915,9 +3013,11 @@ String VisualShaderNodeTextureUniform::get_caption() const { int VisualShaderNodeTextureUniform::get_input_port_count() const { return 2; } + VisualShaderNodeTextureUniform::PortType VisualShaderNodeTextureUniform::get_input_port_type(int p_port) const { return p_port == 0 ? PORT_TYPE_VECTOR : PORT_TYPE_SCALAR; } + String VisualShaderNodeTextureUniform::get_input_port_name(int p_port) const { return p_port == 0 ? "uv" : "lod"; } @@ -2925,9 +3025,11 @@ String VisualShaderNodeTextureUniform::get_input_port_name(int p_port) const { int VisualShaderNodeTextureUniform::get_output_port_count() const { return 2; } + VisualShaderNodeTextureUniform::PortType VisualShaderNodeTextureUniform::get_output_port_type(int p_port) const { return p_port == 0 ? PORT_TYPE_VECTOR : PORT_TYPE_SCALAR; } + String VisualShaderNodeTextureUniform::get_output_port_name(int p_port) const { return p_port == 0 ? "rgb" : "alpha"; } @@ -2989,6 +3091,7 @@ void VisualShaderNodeTextureUniform::set_color_default(ColorDefault p_default) { color_default = p_default; emit_changed(); } + VisualShaderNodeTextureUniform::ColorDefault VisualShaderNodeTextureUniform::get_color_default() const { return color_default; } @@ -3125,9 +3228,11 @@ String VisualShaderNodeCubeMapUniform::get_caption() const { int VisualShaderNodeCubeMapUniform::get_input_port_count() const { return 2; } + VisualShaderNodeCubeMapUniform::PortType VisualShaderNodeCubeMapUniform::get_input_port_type(int p_port) const { return p_port == 0 ? PORT_TYPE_VECTOR : PORT_TYPE_SCALAR; } + String VisualShaderNodeCubeMapUniform::get_input_port_name(int p_port) const { return p_port == 0 ? "normal" : "lod"; } @@ -3135,9 +3240,11 @@ String VisualShaderNodeCubeMapUniform::get_input_port_name(int p_port) const { int VisualShaderNodeCubeMapUniform::get_output_port_count() const { return 2; } + VisualShaderNodeCubeMapUniform::PortType VisualShaderNodeCubeMapUniform::get_output_port_type(int p_port) const { return p_port == 0 ? PORT_TYPE_VECTOR : PORT_TYPE_SCALAR; } + String VisualShaderNodeCubeMapUniform::get_output_port_name(int p_port) const { return p_port == 0 ? "rgb" : "alpha"; } @@ -3227,7 +3334,7 @@ VisualShaderNodeIf::VisualShaderNodeIf() { ////////////// Switch String VisualShaderNodeSwitch::get_caption() const { - return "Switch"; + return "VectorSwitch"; } int VisualShaderNodeSwitch::get_input_port_count() const { @@ -3282,10 +3389,33 @@ String VisualShaderNodeSwitch::generate_code(Shader::Mode p_mode, VisualShader:: VisualShaderNodeSwitch::VisualShaderNodeSwitch() { set_input_port_default_value(0, false); - set_input_port_default_value(1, Vector3(0.0, 0.0, 0.0)); + set_input_port_default_value(1, Vector3(1.0, 1.0, 1.0)); set_input_port_default_value(2, Vector3(0.0, 0.0, 0.0)); } +////////////// Switch(scalar) + +String VisualShaderNodeScalarSwitch::get_caption() const { + return "ScalarSwitch"; +} + +VisualShaderNodeScalarSwitch::PortType VisualShaderNodeScalarSwitch::get_input_port_type(int p_port) const { + if (p_port == 0) { + return PORT_TYPE_BOOLEAN; + } + return PORT_TYPE_SCALAR; +} + +VisualShaderNodeScalarSwitch::PortType VisualShaderNodeScalarSwitch::get_output_port_type(int p_port) const { + return PORT_TYPE_SCALAR; +} + +VisualShaderNodeScalarSwitch::VisualShaderNodeScalarSwitch() { + set_input_port_default_value(0, false); + set_input_port_default_value(1, 1.0); + set_input_port_default_value(2, 0.0); +} + ////////////// Fresnel String VisualShaderNodeFresnel::get_caption() const { diff --git a/scene/resources/visual_shader_nodes.h b/scene/resources/visual_shader_nodes.h index f7efa396dc..0c6e060353 100644 --- a/scene/resources/visual_shader_nodes.h +++ b/scene/resources/visual_shader_nodes.h @@ -1530,6 +1530,18 @@ public: VisualShaderNodeSwitch(); }; +class VisualShaderNodeScalarSwitch : public VisualShaderNodeSwitch { + GDCLASS(VisualShaderNodeScalarSwitch, VisualShaderNodeSwitch); + +public: + virtual String get_caption() const; + + virtual PortType get_input_port_type(int p_port) const; + virtual PortType get_output_port_type(int p_port) const; + + VisualShaderNodeScalarSwitch(); +}; + /////////////////////////////////////// /// FRESNEL /////////////////////////////////////// diff --git a/servers/visual/shader_language.cpp b/servers/visual/shader_language.cpp index 4bc65a8f4f..1b9c3e2eff 100644 --- a/servers/visual/shader_language.cpp +++ b/servers/visual/shader_language.cpp @@ -924,6 +924,9 @@ bool ShaderLanguage::_find_identifier(const BlockNode *p_block, const Map<String if (r_data_type) { *r_data_type = shader->varyings[p_identifier].type; } + if (r_array_size) { + *r_array_size = shader->varyings[p_identifier].array_size; + } if (r_type) { *r_type = IDENTIFIER_VARYING; } @@ -2759,6 +2762,12 @@ bool ShaderLanguage::_validate_assign(Node *p_node, const Map<StringName, BuiltI return false; } + if (shader->varyings.has(arr->name) && current_function != String("vertex")) { + if (r_message) + *r_message = RTR("Varyings can only be assigned in vertex function."); + return false; + } + return true; } @@ -4695,7 +4704,7 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct } if (!uniform && (type < TYPE_FLOAT || type > TYPE_MAT4)) { - _set_error("Invalid type for varying, only float,vec2,vec3,vec4,mat2,mat3,mat4 allowed."); + _set_error("Invalid type for varying, only float,vec2,vec3,vec4,mat2,mat3,mat4 or array of these types allowed."); return ERR_PARSE_ERROR; } @@ -4877,13 +4886,36 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct varying.type = type; varying.precision = precision; varying.interpolation = interpolation; - shader->varyings[name] = varying; tk = _get_token(); - if (tk.type != TK_SEMICOLON) { - _set_error("Expected ';'"); + if (tk.type != TK_SEMICOLON && tk.type != TK_BRACKET_OPEN) { + _set_error("Expected ';' or '['"); return ERR_PARSE_ERROR; } + + if (tk.type == TK_BRACKET_OPEN) { + tk = _get_token(); + if (tk.type == TK_INT_CONSTANT && tk.constant > 0) { + varying.array_size = (int)tk.constant; + + tk = _get_token(); + if (tk.type == TK_BRACKET_CLOSE) { + tk = _get_token(); + if (tk.type != TK_SEMICOLON) { + _set_error("Expected ';'"); + return ERR_PARSE_ERROR; + } + } else { + _set_error("Expected ']'"); + return ERR_PARSE_ERROR; + } + } else { + _set_error("Expected single integer constant > 0"); + return ERR_PARSE_ERROR; + } + } + + shader->varyings[name] = varying; } } break; diff --git a/servers/visual/shader_language.h b/servers/visual/shader_language.h index 6753456323..3a5630ef42 100644 --- a/servers/visual/shader_language.h +++ b/servers/visual/shader_language.h @@ -519,11 +519,13 @@ public: DataType type; DataInterpolation interpolation; DataPrecision precision; + int array_size; Varying() : type(TYPE_VOID), interpolation(INTERPOLATION_FLAT), - precision(PRECISION_DEFAULT) {} + precision(PRECISION_DEFAULT), + array_size(0) {} }; struct Uniform { diff --git a/thirdparty/assimp/code/FBX/FBXConverter.cpp b/thirdparty/assimp/code/FBX/FBXConverter.cpp index 9bd970098e..3f64016ea4 100644 --- a/thirdparty/assimp/code/FBX/FBXConverter.cpp +++ b/thirdparty/assimp/code/FBX/FBXConverter.cpp @@ -78,7 +78,7 @@ namespace Assimp { #define CONVERT_FBX_TIME(time) static_cast<double>(time) / 46186158000L - FBXConverter::FBXConverter(aiScene* out, const Document& doc, bool removeEmptyBones, FbxUnit unit ) + FBXConverter::FBXConverter(aiScene* out, const Document& doc, bool removeEmptyBones ) : defaultMaterialIndex() , lights() , cameras() @@ -90,8 +90,7 @@ namespace Assimp { , mNodeNames() , anim_fps() , out(out) - , doc(doc) - , mCurrentUnit(FbxUnit::cm) { + , doc(doc) { // animations need to be converted first since this will // populate the node_anim_chain_bits map, which is needed // to determine which nodes need to be generated. @@ -2002,6 +2001,21 @@ namespace Assimp { TrySetTextureProperties(out_mat, textures, "Maya|SpecularTexture", aiTextureType_SPECULAR, mesh); TrySetTextureProperties(out_mat, textures, "Maya|FalloffTexture", aiTextureType_OPACITY, mesh); TrySetTextureProperties(out_mat, textures, "Maya|ReflectionMapTexture", aiTextureType_REFLECTION, mesh); + + // Maya PBR + TrySetTextureProperties(out_mat, textures, "Maya|baseColor|file", aiTextureType_BASE_COLOR, mesh); + TrySetTextureProperties(out_mat, textures, "Maya|normalCamera|file", aiTextureType_NORMAL_CAMERA, mesh); + TrySetTextureProperties(out_mat, textures, "Maya|emissionColor|file", aiTextureType_EMISSION_COLOR, mesh); + TrySetTextureProperties(out_mat, textures, "Maya|metalness|file", aiTextureType_METALNESS, mesh); + TrySetTextureProperties(out_mat, textures, "Maya|diffuseRoughness|file", aiTextureType_DIFFUSE_ROUGHNESS, mesh); + + // Maya stingray + TrySetTextureProperties(out_mat, textures, "Maya|TEX_color_map|file", aiTextureType_BASE_COLOR, mesh); + TrySetTextureProperties(out_mat, textures, "Maya|TEX_normal_map|file", aiTextureType_NORMAL_CAMERA, mesh); + TrySetTextureProperties(out_mat, textures, "Maya|TEX_emissive_map|file", aiTextureType_EMISSION_COLOR, mesh); + TrySetTextureProperties(out_mat, textures, "Maya|TEX_metallic_map|file", aiTextureType_METALNESS, mesh); + TrySetTextureProperties(out_mat, textures, "Maya|TEX_roughness_map|file", aiTextureType_DIFFUSE_ROUGHNESS, mesh); + TrySetTextureProperties(out_mat, textures, "Maya|TEX_ao_map|file", aiTextureType_AMBIENT_OCCLUSION, mesh); } void FBXConverter::SetTextureProperties(aiMaterial* out_mat, const LayeredTextureMap& layeredTextures, const MeshGeometry* const mesh) @@ -3589,9 +3603,9 @@ void FBXConverter::SetShadingPropertiesRaw(aiMaterial* out_mat, const PropertyTa } // ------------------------------------------------------------------------------------------------ - void ConvertToAssimpScene(aiScene* out, const Document& doc, bool removeEmptyBones, FbxUnit unit) + void ConvertToAssimpScene(aiScene* out, const Document& doc, bool removeEmptyBones) { - FBXConverter converter(out, doc, removeEmptyBones, unit); + FBXConverter converter(out, doc, removeEmptyBones); } } // !FBX diff --git a/thirdparty/assimp/code/FBX/FBXConverter.h b/thirdparty/assimp/code/FBX/FBXConverter.h index b458627392..ab610058a4 100644 --- a/thirdparty/assimp/code/FBX/FBXConverter.h +++ b/thirdparty/assimp/code/FBX/FBXConverter.h @@ -92,7 +92,7 @@ enum class FbxUnit { * @param doc Parsed FBX document * @param removeEmptyBones Will remove bones, which do not have any references to vertices. */ -void ConvertToAssimpScene(aiScene* out, const Document& doc, bool removeEmptyBones, FbxUnit unit); +void ConvertToAssimpScene(aiScene* out, const Document& doc, bool removeEmptyBones); /** Dummy class to encapsulate the conversion process */ class FBXConverter { @@ -123,7 +123,7 @@ public: }; public: - FBXConverter(aiScene* out, const Document& doc, bool removeEmptyBones, FbxUnit unit); + FBXConverter(aiScene* out, const Document& doc, bool removeEmptyBones); ~FBXConverter(); private: diff --git a/thirdparty/assimp/code/FBX/FBXImporter.cpp b/thirdparty/assimp/code/FBX/FBXImporter.cpp index bd359dbf29..271935a568 100644 --- a/thirdparty/assimp/code/FBX/FBXImporter.cpp +++ b/thirdparty/assimp/code/FBX/FBXImporter.cpp @@ -191,7 +191,7 @@ void FBXImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOS } // convert the FBX DOM to aiScene - ConvertToAssimpScene(pScene, doc, settings.removeEmptyBones, unit); + ConvertToAssimpScene(pScene, doc, settings.removeEmptyBones); // size relative to cm float size_relative_to_cm = doc.GlobalSettings().UnitScaleFactor(); diff --git a/thirdparty/assimp/include/assimp/material.h b/thirdparty/assimp/include/assimp/material.h index 4b5a1293dd..206eb2a2b0 100644 --- a/thirdparty/assimp/include/assimp/material.h +++ b/thirdparty/assimp/include/assimp/material.h @@ -196,34 +196,40 @@ enum aiTextureType * (#aiMaterialProperty::mSemantic) for all material properties * *not* related to textures. */ - aiTextureType_NONE = 0x0, + aiTextureType_NONE = 0, + + /** LEGACY API MATERIALS + * Legacy refers to materials which + * Were originally implemented in the specifications around 2000. + * These must never be removed, as most engines support them. + */ /** The texture is combined with the result of the diffuse * lighting equation. */ - aiTextureType_DIFFUSE = 0x1, + aiTextureType_DIFFUSE = 1, /** The texture is combined with the result of the specular * lighting equation. */ - aiTextureType_SPECULAR = 0x2, + aiTextureType_SPECULAR = 2, /** The texture is combined with the result of the ambient * lighting equation. */ - aiTextureType_AMBIENT = 0x3, + aiTextureType_AMBIENT = 3, /** The texture is added to the result of the lighting * calculation. It isn't influenced by incoming light. */ - aiTextureType_EMISSIVE = 0x4, + aiTextureType_EMISSIVE = 4, /** The texture is a height map. * * By convention, higher gray-scale values stand for * higher elevations from the base height. */ - aiTextureType_HEIGHT = 0x5, + aiTextureType_HEIGHT = 5, /** The texture is a (tangent space) normal-map. * @@ -231,7 +237,7 @@ enum aiTextureType * normal maps. Assimp does (intentionally) not * distinguish here. */ - aiTextureType_NORMALS = 0x6, + aiTextureType_NORMALS = 6, /** The texture defines the glossiness of the material. * @@ -240,21 +246,21 @@ enum aiTextureType * function defined to map the linear color values in the * texture to a suitable exponent. Have fun. */ - aiTextureType_SHININESS = 0x7, + aiTextureType_SHININESS = 7, /** The texture defines per-pixel opacity. * * Usually 'white' means opaque and 'black' means * 'transparency'. Or quite the opposite. Have fun. */ - aiTextureType_OPACITY = 0x8, + aiTextureType_OPACITY = 8, /** Displacement texture * * The exact purpose and format is application-dependent. * Higher color values stand for higher vertex displacements. */ - aiTextureType_DISPLACEMENT = 0x9, + aiTextureType_DISPLACEMENT = 9, /** Lightmap texture (aka Ambient Occlusion) * @@ -263,14 +269,28 @@ enum aiTextureType * scaling value for the final color value of a pixel. Its * intensity is not affected by incoming light. */ - aiTextureType_LIGHTMAP = 0xA, + aiTextureType_LIGHTMAP = 10, /** Reflection texture * * Contains the color of a perfect mirror reflection. * Rarely used, almost never for real-time applications. */ - aiTextureType_REFLECTION = 0xB, + aiTextureType_REFLECTION = 11, + + /** PBR Materials + * PBR definitions from maya and other modelling packages now use this standard. + * This was originally introduced around 2012. + * Support for this is in game engines like Godot, Unreal or Unity3D. + * Modelling packages which use this are very common now. + */ + + aiTextureType_BASE_COLOR = 12, + aiTextureType_NORMAL_CAMERA = 13, + aiTextureType_EMISSION_COLOR = 14, + aiTextureType_METALNESS = 15, + aiTextureType_DIFFUSE_ROUGHNESS = 16, + aiTextureType_AMBIENT_OCCLUSION = 17, /** Unknown texture * @@ -278,7 +298,7 @@ enum aiTextureType * above is considered to be 'unknown'. It is still imported, * but is excluded from any further post-processing. */ - aiTextureType_UNKNOWN = 0xC, + aiTextureType_UNKNOWN = 18, #ifndef SWIG |