diff options
140 files changed, 2341 insertions, 594 deletions
diff --git a/.clang-format b/.clang-format index 212bc25109..3a2c39a174 100644 --- a/.clang-format +++ b/.clang-format @@ -1,6 +1,6 @@ # Commented out parameters are those with the same value as base LLVM style # We can uncomment them if we want to change their value, or enforce the -# chosen value in case the base style changes (last sync: Clang 5.0.0). +# chosen value in case the base style changes (last sync: Clang 6.0.1). --- ### General config, applies to all languages ### BasedOnStyle: LLVM @@ -32,6 +32,7 @@ AllowShortIfStatementsOnASingleLine: true # AfterObjCDeclaration: false # AfterStruct: false # AfterUnion: false +# AfterExternBlock: false # BeforeCatch: false # BeforeElse: false # IndentBraces: false @@ -60,6 +61,7 @@ Cpp11BracedListStyle: false # - foreach # - Q_FOREACH # - BOOST_FOREACH +# IncludeBlocks: Preserve IncludeCategories: - Regex: '".*"' Priority: 1 @@ -69,6 +71,7 @@ IncludeCategories: Priority: 3 # IncludeIsMainRegex: '(Test)?$' IndentCaseLabels: true +# IndentPPDirectives: None IndentWidth: 4 # IndentWrappedFunctionNames: false # JavaScriptQuotes: Leave @@ -86,6 +89,10 @@ IndentWidth: 4 # PenaltyExcessCharacter: 1000000 # PenaltyReturnTypeOnItsOwnLine: 60 # PointerAlignment: Right +# RawStringFormats: +# - Delimiter: pb +# Language: TextProto +# BasedOnStyle: google # ReflowComments: true # SortIncludes: true # SortUsingDeclarations: true diff --git a/.travis.yml b/.travis.yml index 8c24291328..133a134758 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,9 +23,11 @@ matrix: addons: apt: sources: - - llvm-toolchain-trusty-5.0 + - llvm-toolchain-trusty-6.0 + - ubuntu-toolchain-r-test packages: - - clang-format-5.0 + - clang-format-6.0 + - libstdc++6 # >= 4.9 needed for clang-format-6.0 coverity_scan: project: diff --git a/AUTHORS.md b/AUTHORS.md index 12494a487d..d3f0592c89 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -40,14 +40,15 @@ name is available. Ben Brookshire (sheepandshepherd) Benjamin (Nallebeorn) Bernard Liebl (poke1024) - Bojidar Marinov (bojidar-bg) Błażej Szczygieł (zaps166) + Bojidar Marinov (bojidar-bg) + bruvzg Carl Olsson (not-surt) Dana Olson (adolson) Daniel J. Ramirez (djrm) Dmitry Koteroff (Krakean) - Дмитрий Сальников (DmitriySalnikov) Emmanuel Leblond (touilleMan) + est31 Fabio Alessandrelli (Faless) Ferenc Arn (tagcup) Franklin Sobrinho (TheHX) @@ -68,6 +69,7 @@ name is available. J08nY Jakub Grzesik (kubecz3k) Jérôme GULLY (Nutriz) + JFonS Johan Manuel (29jm) Joshua Grams (JoshuaGrams) Juan Linietsky (reduz) @@ -76,15 +78,18 @@ name is available. Kelly Thomas (KellyThomas) Kostadin Damyanov (Max-Might) Leon Krause (eska014) - Marc Gilleron (Zylann) + m4nu3lf Marcelo Fernandez (marcelofg55) + Marc Gilleron (Zylann) Mariano Javier Suligoy (MarianoGnu) Mario Schlack (hurikhan) Martin Sjursen (binbitten) + marynate Masoud BH (masoudbh3) Matthias Hölzl (hoelzl) Max Hilbrunner (mhilbrunner) Michael Alexsander Silva Dias (YeldhamDev) + mrezai Nathan Warden (NathanWarden) Nuno Donato (nunodonato) Ovnuniarchos @@ -102,28 +107,24 @@ name is available. Ray Koopa (RayKoopa) Rémi Verschelde (akien-mga) Roberto F. Arroyo (robfram) + romulox-x + rraallvv Ruslan Mustakov (endragor) Saniko (sanikoyes) SaracenOne + sersoong Theo Hallenius (TheoXD) Thomas Herzog (karroffel) Timo (toger5) - V. Vamsi Krishna (vkbsb) Vinzenz Feenstra (vinzenz) + 박한얼 (volzhs) + V. Vamsi Krishna (vkbsb) Wilhem Barbier (nounoursheureux) Will Nations (willnationsdev) Wilson E. Alvarez (Rubonnek) Xavier Cho (mysticfall) + yg2f (SuperUserNameMan) Yuri Roubinski (Chaosus) Zher Huei Lee (leezh) ZuBsPaCe - 박한얼 (volzhs) - bruvzg - est31 - m4nu3lf - marynate - mrezai - romulox-x - rraallvv - sersoong - yg2f (SuperUserNameMan) + Дмитрий Сальников (DmitriySalnikov) @@ -70,6 +70,7 @@ generous deed immortalized in the next stable release of Godot Engine. Johannes Wuensch Josep G. Camarasa Joshua Lesperance + Kyle Szklenski Libre-Dépanne Matthew Bennett Olafur Gislason @@ -87,21 +88,21 @@ generous deed immortalized in the next stable release of Godot Engine. David Churchill Dean Harmon Dexter Miguel - Guilherme Felipe de C. G. da Silva John Justo Delgado Baudí KTL Laurence Bannister + paul gruenbacher Rami Robert Willes Robin Arys + Rodrigo Loli Ronnie Ashlock Rufus Xavier Sarsaparilla ScottMakesGames Thomas Bjarnelöf William Connell Wojciech Chojnacki - Xavier Tan Zaq Poi Alessandra Pereyra @@ -113,13 +114,15 @@ generous deed immortalized in the next stable release of Godot Engine. Cody Parker Corey Auger D - Daniel Eliasinski E.G. + Eric Eric Monson flesk + floopf G Barnes GGGames.org Giovanni Solimeno + Guilherme Felipe de C. G. da Silva Hasen Judy Heath Hayes Jay Horton @@ -133,31 +136,32 @@ generous deed immortalized in the next stable release of Godot Engine. Markus Wiesner Marvin Mohammad Taleb + Neal Barry Nick Nikitin Pablo Cholaky Patrick Schnorbus Pete Goodwin Phyronnaz Ruben Soares Luis + Sindre Sømme Sofox Stoned Xander - Ted Tim Dalporto Trent McPheron - Vladimir ## Silver donors 1D_Inc Adam Carr Adam Smeltzer + Adisibio Alder Stefano Alessandro Senese - Álvaro Domínguez López Anders Jensen-Urstad Anthony Bongiovanni Arda Erol Arthur S. Muszynski + Artur Barichello Aubrey Falconer Avencherus Bailey @@ -168,6 +172,7 @@ generous deed immortalized in the next stable release of Godot Engine. Blair Allen Brandon Bryan Stevenson + Carl Winder Carwyn Edwards Casey Foote Chris Chapin @@ -175,7 +180,6 @@ generous deed immortalized in the next stable release of Godot Engine. Christian Winter Christopher Schmitt Collin Shooltz - Daniel Delgado Corona Daniel Johnson Daniel Kaplan DanielMaximiano @@ -186,6 +190,7 @@ generous deed immortalized in the next stable release of Godot Engine. Dominik Wetzel Duy Kevin Nguyen Edward Herbert + Edwin Acosta Eric Martini Fabian Becker fengjiongmax @@ -194,10 +199,10 @@ generous deed immortalized in the next stable release of Godot Engine. Gerrit Großkopf Gerrit Procee Gilberto K. Otubo + Guillaume Laforte Guldoman Gumichan01 Heribert Hirth - hubert jenkins Hunter Jones ialex32x Ivan Vodopiviz @@ -222,16 +227,15 @@ generous deed immortalized in the next stable release of Godot Engine. Kevin Kamper Meejach Petersen Klavdij Voncina Krzysztof Jankowski - Lars pfeffer Linus Lind Lundgren Luis Moraes Macil magodev Martin Eigel Martins Odabi - Matthew Fitzpatrick Max R.R. Collada Maxwell + Mertcan Mermerkaya mhilbrunner Michael Dürwald Michael Gringauz @@ -246,10 +250,8 @@ generous deed immortalized in the next stable release of Godot Engine. Niclas Eriksen Nicolas SAN AGUSTIN Niko Leopold - nivardus Noi Sek Oleg Tyshchenko - Oleksandr Yemets Pablo Seibelt Pan Ip Pat LaBine @@ -260,28 +262,28 @@ generous deed immortalized in the next stable release of Godot Engine. Pierre-Igor Berthet Pietro Vertechi Piotr Kaczmarski - Rea Rémi Verschelde Richman Stewart Roger Burgess Roger Smith Roman Tinkov Ryan Whited - Samuel El-Borai Sasori Olkof Sootstone Stefan Butucea Theo Cranmore Thibault Barbaroux Thomas Bell + Thomas Hermansen + Thomas Holmes Thomas Kurz - Tomasz Wacławek Tom Larrow Tyler Stafos UltyX Victor Victor Gonzalez Fernandez Viktor Ferenczi + waka nya werner mendizabal Wout Standaert Yu He diff --git a/core/dvector.h b/core/dvector.h index c0190fb9e3..e03a755e6c 100644 --- a/core/dvector.h +++ b/core/dvector.h @@ -150,7 +150,7 @@ class PoolVector { } if (old_alloc->refcount.unref() == true) { - //this should never happen but.. + //this should never happen but.. #ifdef DEBUG_ENABLED MemoryPool::alloc_mutex->lock(); diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp index fcbb22b5de..f1620f1493 100644 --- a/core/io/http_client.cpp +++ b/core/io/http_client.cpp @@ -279,6 +279,7 @@ void HTTPClient::close() { chunk_left = 0; read_until_eof = false; response_num = 0; + handshaking = false; } Error HTTPClient::poll() { @@ -327,16 +328,40 @@ Error HTTPClient::poll() { } break; case StreamPeerTCP::STATUS_CONNECTED: { if (ssl) { - Ref<StreamPeerSSL> ssl = StreamPeerSSL::create(); - Error err = ssl->connect_to_stream(tcp_connection, ssl_verify_host, conn_host); - if (err != OK) { + Ref<StreamPeerSSL> ssl; + if (!handshaking) { + // Connect the StreamPeerSSL and start handshaking + ssl = Ref<StreamPeerSSL>(StreamPeerSSL::create()); + ssl->set_blocking_handshake_enabled(false); + Error err = ssl->connect_to_stream(tcp_connection, ssl_verify_host, conn_host); + if (err != OK) { + close(); + status = STATUS_SSL_HANDSHAKE_ERROR; + return ERR_CANT_CONNECT; + } + connection = ssl; + handshaking = true; + } else { + // We are already handshaking, which means we can use your already active SSL connection + ssl = static_cast<Ref<StreamPeerSSL> >(connection); + ssl->poll(); // Try to finish the handshake + } + + if (ssl->get_status() == StreamPeerSSL::STATUS_CONNECTED) { + // Handshake has been successfull + handshaking = false; + status = STATUS_CONNECTED; + return OK; + } else if (ssl->get_status() != StreamPeerSSL::STATUS_HANDSHAKING) { + // Handshake has failed close(); status = STATUS_SSL_HANDSHAKE_ERROR; return ERR_CANT_CONNECT; } - connection = ssl; + // ... we will need to poll more for handshake to finish + } else { + status = STATUS_CONNECTED; } - status = STATUS_CONNECTED; return OK; } break; case StreamPeerTCP::STATUS_ERROR: @@ -669,6 +694,7 @@ HTTPClient::HTTPClient() { response_num = 0; ssl = false; blocking = false; + handshaking = false; read_chunk_size = 4096; } diff --git a/core/io/http_client.h b/core/io/http_client.h index 38ec82ce8c..82b56b01db 100644 --- a/core/io/http_client.h +++ b/core/io/http_client.h @@ -165,6 +165,7 @@ private: bool ssl; bool ssl_verify_host; bool blocking; + bool handshaking; Vector<uint8_t> response_str; diff --git a/core/io/stream_peer_ssl.cpp b/core/io/stream_peer_ssl.cpp index 012ba78c6d..c71af6b641 100644 --- a/core/io/stream_peer_ssl.cpp +++ b/core/io/stream_peer_ssl.cpp @@ -52,6 +52,14 @@ bool StreamPeerSSL::is_available() { return available; } +void StreamPeerSSL::set_blocking_handshake_enabled(bool p_enabled) { + blocking_handshake = p_enabled; +} + +bool StreamPeerSSL::is_blocking_handshake_enabled() const { + return blocking_handshake; +} + PoolByteArray StreamPeerSSL::get_project_cert_array() { PoolByteArray out; @@ -84,16 +92,21 @@ PoolByteArray StreamPeerSSL::get_project_cert_array() { void StreamPeerSSL::_bind_methods() { ClassDB::bind_method(D_METHOD("poll"), &StreamPeerSSL::poll); - ClassDB::bind_method(D_METHOD("accept_stream", "stream"), &StreamPeerSSL::accept_stream); + ClassDB::bind_method(D_METHOD("accept_stream"), &StreamPeerSSL::accept_stream); ClassDB::bind_method(D_METHOD("connect_to_stream", "stream", "validate_certs", "for_hostname"), &StreamPeerSSL::connect_to_stream, DEFVAL(false), DEFVAL(String())); ClassDB::bind_method(D_METHOD("get_status"), &StreamPeerSSL::get_status); ClassDB::bind_method(D_METHOD("disconnect_from_stream"), &StreamPeerSSL::disconnect_from_stream); + ClassDB::bind_method(D_METHOD("set_blocking_handshake_enabled", "enabled"), &StreamPeerSSL::set_blocking_handshake_enabled); + ClassDB::bind_method(D_METHOD("is_blocking_handshake_enabled"), &StreamPeerSSL::is_blocking_handshake_enabled); + + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "blocking_handshake"), "set_blocking_handshake_enabled", "is_blocking_handshake_enabled"); BIND_ENUM_CONSTANT(STATUS_DISCONNECTED); BIND_ENUM_CONSTANT(STATUS_CONNECTED); - BIND_ENUM_CONSTANT(STATUS_ERROR_NO_CERTIFICATE); + BIND_ENUM_CONSTANT(STATUS_ERROR); BIND_ENUM_CONSTANT(STATUS_ERROR_HOSTNAME_MISMATCH); } StreamPeerSSL::StreamPeerSSL() { + blocking_handshake = true; } diff --git a/core/io/stream_peer_ssl.h b/core/io/stream_peer_ssl.h index 77301a7c87..870704e875 100644 --- a/core/io/stream_peer_ssl.h +++ b/core/io/stream_peer_ssl.h @@ -49,14 +49,20 @@ protected: friend class Main; static bool initialize_certs; + bool blocking_handshake; + public: enum Status { STATUS_DISCONNECTED, + STATUS_HANDSHAKING, STATUS_CONNECTED, - STATUS_ERROR_NO_CERTIFICATE, + STATUS_ERROR, STATUS_ERROR_HOSTNAME_MISMATCH }; + void set_blocking_handshake_enabled(bool p_enabled); + bool is_blocking_handshake_enabled() const; + virtual void poll() = 0; virtual Error accept_stream(Ref<StreamPeer> p_base) = 0; virtual Error connect_to_stream(Ref<StreamPeer> p_base, bool p_validate_certs = false, const String &p_for_hostname = String()) = 0; diff --git a/core/object.cpp b/core/object.cpp index 1d2aeb7ba5..d86c60a3b8 100644 --- a/core/object.cpp +++ b/core/object.cpp @@ -601,8 +601,12 @@ void Object::get_property_list(List<PropertyInfo> *p_list, bool p_reversed) cons _get_property_listv(p_list, p_reversed); - if (!is_class("Script")) // can still be set, but this is for userfriendlyness + if (!is_class("Script")) { // can still be set, but this is for userfriendlyness +#ifdef TOOLS_ENABLED + p_list->push_back(PropertyInfo(Variant::NIL, "Script", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_GROUP)); +#endif p_list->push_back(PropertyInfo(Variant::OBJECT, "script", PROPERTY_HINT_RESOURCE_TYPE, "Script", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_STORE_IF_NONZERO)); + } #ifdef TOOLS_ENABLED if (editor_section_folding.size()) { p_list->push_back(PropertyInfo(Variant::ARRAY, CoreStringNames::get_singleton()->_sections_unfolded, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL)); diff --git a/core/os/os.cpp b/core/os/os.cpp index 5eed10e30c..d0a7bc6fbe 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -614,6 +614,9 @@ bool OS::has_feature(const String &p_feature) { if (_check_internal_feature_support(p_feature)) return true; + if (ProjectSettings::get_singleton()->has_custom_feature(p_feature)) + return true; + return false; } diff --git a/core/project_settings.cpp b/core/project_settings.cpp index b1fd66e566..db1d0a604c 100644 --- a/core/project_settings.cpp +++ b/core/project_settings.cpp @@ -912,6 +912,10 @@ Variant ProjectSettings::get_setting(const String &p_setting) const { return get(p_setting); } +bool ProjectSettings::has_custom_feature(const String &p_feature) const { + return custom_features.has(p_feature); +} + void ProjectSettings::_bind_methods() { ClassDB::bind_method(D_METHOD("has_setting", "name"), &ProjectSettings::has_setting); diff --git a/core/project_settings.h b/core/project_settings.h index 66f3ed954e..045d942b31 100644 --- a/core/project_settings.h +++ b/core/project_settings.h @@ -151,6 +151,8 @@ public: void set_registering_order(bool p_enable); + bool has_custom_feature(const String &p_feature) const; + ProjectSettings(); ~ProjectSettings(); }; diff --git a/core/typedefs.h b/core/typedefs.h index 4758a5408d..71771ea4e6 100644 --- a/core/typedefs.h +++ b/core/typedefs.h @@ -74,7 +74,7 @@ T *_nullptr() { #define OFFSET_OF(st, m) \ ((size_t)((char *)&(_nullptr<st>()->m) - (char *)0)) - /** +/** * Some platforms (devices) not define NULL */ @@ -82,7 +82,7 @@ T *_nullptr() { #define NULL 0 #endif - /** +/** * Windows defines a lot of badly stuff we'll never ever use. undefine it. */ @@ -97,6 +97,7 @@ T *_nullptr() { #undef CLAMP // override standard definition #undef Error #undef OK +#undef CONNECT_DEFERRED // override from Windows SDK, clashes with Object enum #endif #include "int_types.h" @@ -104,7 +105,7 @@ T *_nullptr() { #include "error_list.h" #include "error_macros.h" - /** Generic ABS function, for math uses please use Math::abs */ +/** Generic ABS function, for math uses please use Math::abs */ #ifndef ABS #define ABS(m_v) ((m_v < 0) ? (-(m_v)) : (m_v)) diff --git a/core/ustring.cpp b/core/ustring.cpp index 51f05468e2..bee5f5ffdb 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -757,36 +757,32 @@ Vector<String> String::rsplit(const String &p_splitter, bool p_allow_empty, int Vector<String> ret; const int len = length(); - int from = len; + int remaining_len = len; while (true) { - int end = rfind(p_splitter, from); - if (end < 0) - end = 0; - - if (p_allow_empty || (end < from)) { - const String str = substr(end > 0 ? end + p_splitter.length() : end, end > 0 ? from - end : from + 2); - - if (p_maxsplit <= 0) { - ret.push_back(str); - } else if (p_maxsplit > 0) { - - // Put rest of the string and leave cycle. - if (p_maxsplit == ret.size()) { - ret.push_back(substr(0, from + 2)); - break; - } - - // Otherwise, push items until positive limit is reached. - ret.push_back(str); + if (remaining_len < p_splitter.length() || (p_maxsplit > 0 && p_maxsplit == ret.size())) { + // no room for another splitter or hit max splits, push what's left and we're done + if (p_allow_empty || remaining_len > 0) { + ret.push_back(substr(0, remaining_len)); } + break; } - if (end == 0) + int left_edge = rfind(p_splitter, remaining_len - p_splitter.length()); + + if (left_edge < 0) { + // no more splitters, we're done + ret.push_back(substr(0, remaining_len)); break; + } + + int substr_start = left_edge + p_splitter.length(); + if (p_allow_empty || substr_start < remaining_len) { + ret.push_back(substr(substr_start, remaining_len - substr_start)); + } - from = end - p_splitter.length(); + remaining_len = left_edge; } ret.invert(); diff --git a/doc/classes/Array.xml b/doc/classes/Array.xml index 35c120cd6a..7fcb827252 100644 --- a/doc/classes/Array.xml +++ b/doc/classes/Array.xml @@ -4,7 +4,16 @@ Generic array datatype. </brief_description> <description> - Generic array, contains several elements of any type, accessible by numerical index starting at 0. Negative indices can be used to count from the right, like in Python. Arrays are always passed by reference. + Generic array, contains several elements of any type, accessible by a numerical index starting at 0. Negative indices can be used to count from the back, like in Python (-1 is the last element, -2 the second to last, etc.). Example: + [codeblock] + var array = ["One", 2, 3, "Four"] + print(array[0]) # One + print(array[2]) # 3 + print(array[-1]) # Four + array[2] = "Three" + print(array[-2]) # Three + [/codeblock] + Arrays are always passed by reference. </description> <tutorials> </tutorials> diff --git a/doc/classes/Line2D.xml b/doc/classes/Line2D.xml index 19be34978d..c1682e71e5 100644 --- a/doc/classes/Line2D.xml +++ b/doc/classes/Line2D.xml @@ -117,5 +117,8 @@ <constant name="LINE_TEXTURE_TILE" value="1" enum="LineTextureMode"> Tiles the texture over the line. The texture need to be imported with Repeat Enabled for it to work properly. </constant> + <constant name="LINE_TEXTURE_STRETCH" value="2" enum="LineTextureMode"> + Stretches the texture across the line. Import the texture with Repeat Disabled for best results. + </constant> </constants> </class> diff --git a/doc/classes/SpriteFrames.xml b/doc/classes/SpriteFrames.xml index 91129b5850..68373ebc4f 100644 --- a/doc/classes/SpriteFrames.xml +++ b/doc/classes/SpriteFrames.xml @@ -127,6 +127,13 @@ Changes the animation's name to [code]newname[/code]. </description> </method> + <method name="get_animation_names"> + <return type="PoolStringArray"> + </return> + <description> + Returns an array containing the names associated to each animation. Values are placed in alphabetical order. + </description> + </method> <method name="set_animation_loop"> <return type="void"> </return> diff --git a/drivers/alsa/audio_driver_alsa.cpp b/drivers/alsa/audio_driver_alsa.cpp index 1e17e72532..ae85ee50d1 100644 --- a/drivers/alsa/audio_driver_alsa.cpp +++ b/drivers/alsa/audio_driver_alsa.cpp @@ -142,8 +142,6 @@ Error AudioDriverALSA::init_device() { samples_in.resize(period_size * channels); samples_out.resize(period_size * channels); - snd_pcm_nonblock(pcm_handle, 0); - return OK; } @@ -168,54 +166,50 @@ void AudioDriverALSA::thread_func(void *p_udata) { AudioDriverALSA *ad = (AudioDriverALSA *)p_udata; while (!ad->exit_thread) { + + ad->lock(); + ad->start_counting_ticks(); + if (!ad->active) { for (unsigned int i = 0; i < ad->period_size * ad->channels; i++) { ad->samples_out[i] = 0; - }; - } else { - ad->lock(); + } + } else { ad->audio_server_process(ad->period_size, ad->samples_in.ptrw()); - ad->unlock(); - for (unsigned int i = 0; i < ad->period_size * ad->channels; i++) { ad->samples_out[i] = ad->samples_in[i] >> 16; } - }; + } int todo = ad->period_size; int total = 0; - while (todo) { - if (ad->exit_thread) - break; + while (todo && !ad->exit_thread) { uint8_t *src = (uint8_t *)ad->samples_out.ptr(); int wrote = snd_pcm_writei(ad->pcm_handle, (void *)(src + (total * ad->channels)), todo); - if (wrote < 0) { - if (ad->exit_thread) - break; + if (wrote > 0) { + total += wrote; + todo -= wrote; + } else if (wrote == -EAGAIN) { + ad->stop_counting_ticks(); + ad->unlock(); - if (wrote == -EAGAIN) { - //can't write yet (though this is blocking..) - usleep(1000); - continue; - } + OS::get_singleton()->delay_usec(1000); + + ad->lock(); + ad->start_counting_ticks(); + } else { wrote = snd_pcm_recover(ad->pcm_handle, wrote, 0); if (wrote < 0) { - //absolute fail - fprintf(stderr, "ALSA failed and can't recover: %s\n", snd_strerror(wrote)); + ERR_PRINTS("ALSA: Failed and can't recover: " + String(snd_strerror(wrote))); ad->active = false; ad->exit_thread = true; - break; } - continue; - }; - - total += wrote; - todo -= wrote; - }; + } + } // User selected a new device, finish the current one so we'll init the new device if (ad->device_name != ad->new_device) { @@ -232,10 +226,12 @@ void AudioDriverALSA::thread_func(void *p_udata) { if (err != OK) { ad->active = false; ad->exit_thread = true; - break; } } } + + ad->stop_counting_ticks(); + ad->unlock(); }; ad->thread_exited = true; @@ -296,7 +292,9 @@ String AudioDriverALSA::get_device() { void AudioDriverALSA::set_device(String device) { + lock(); new_device = device; + unlock(); } void AudioDriverALSA::lock() { @@ -323,21 +321,21 @@ void AudioDriverALSA::finish_device() { void AudioDriverALSA::finish() { - if (!thread) - return; - - exit_thread = true; - Thread::wait_to_finish(thread); + if (thread) { + exit_thread = true; + Thread::wait_to_finish(thread); - finish_device(); + memdelete(thread); + thread = NULL; - memdelete(thread); - if (mutex) { - memdelete(mutex); - mutex = NULL; + if (mutex) { + memdelete(mutex); + mutex = NULL; + } } - thread = NULL; -}; + + finish_device(); +} AudioDriverALSA::AudioDriverALSA() { diff --git a/drivers/coreaudio/audio_driver_coreaudio.cpp b/drivers/coreaudio/audio_driver_coreaudio.cpp index ef7858b4ca..63af4506f3 100644 --- a/drivers/coreaudio/audio_driver_coreaudio.cpp +++ b/drivers/coreaudio/audio_driver_coreaudio.cpp @@ -163,6 +163,8 @@ OSStatus AudioDriverCoreAudio::output_callback(void *inRefCon, return 0; }; + ad->start_counting_ticks(); + for (unsigned int i = 0; i < ioData->mNumberBuffers; i++) { AudioBuffer *abuf = &ioData->mBuffers[i]; @@ -184,6 +186,7 @@ OSStatus AudioDriverCoreAudio::output_callback(void *inRefCon, }; }; + ad->stop_counting_ticks(); ad->unlock(); return 0; diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp index ab48e682d6..9ea20ff15a 100644 --- a/drivers/gles2/rasterizer_gles2.cpp +++ b/drivers/gles2/rasterizer_gles2.cpp @@ -203,7 +203,7 @@ void RasterizerGLES2::initialize() { #endif // GLAD_ENABLED - // For debugging + // For debugging #ifdef GLES_OVER_GL if (GLAD_GL_ARB_debug_output) { glDebugMessageControlARB(_EXT_DEBUG_SOURCE_API_ARB, _EXT_DEBUG_TYPE_ERROR_ARB, _EXT_DEBUG_SEVERITY_HIGH_ARB, 0, NULL, GL_TRUE); diff --git a/drivers/gles2/rasterizer_storage_gles2.cpp b/drivers/gles2/rasterizer_storage_gles2.cpp index b268d4c723..2da496d4b7 100644 --- a/drivers/gles2/rasterizer_storage_gles2.cpp +++ b/drivers/gles2/rasterizer_storage_gles2.cpp @@ -680,7 +680,6 @@ void RasterizerStorageGLES2::texture_set_force_redraw_if_visible(RID p_texture, ERR_FAIL_COND(!texture); texture->redraw_if_visible = p_enable; - } void RasterizerStorageGLES2::texture_set_detect_3d_callback(RID p_texture, VisualServer::TextureDetectCallback p_callback, void *p_userdata) { @@ -1191,7 +1190,7 @@ RID RasterizerStorageGLES2::multimesh_create() { return RID(); } -void RasterizerStorageGLES2::multimesh_allocate(RID p_multimesh, int p_instances, VS::MultimeshTransformFormat p_transform_format, VS::MultimeshColorFormat p_color_format,VS::MultimeshCustomDataFormat p_data) { +void RasterizerStorageGLES2::multimesh_allocate(RID p_multimesh, int p_instances, VS::MultimeshTransformFormat p_transform_format, VS::MultimeshColorFormat p_color_format, VS::MultimeshCustomDataFormat p_data) { } int RasterizerStorageGLES2::multimesh_get_instance_count(RID p_multimesh) const { @@ -1234,8 +1233,6 @@ Color RasterizerStorageGLES2::multimesh_instance_get_custom_data(RID p_multimesh } void RasterizerStorageGLES2::multimesh_set_as_bulk_array(RID p_multimesh, const PoolVector<float> &p_array) { - - } void RasterizerStorageGLES2::multimesh_set_visible_instances(RID p_multimesh, int p_visible) { diff --git a/drivers/gles2/rasterizer_storage_gles2.h b/drivers/gles2/rasterizer_storage_gles2.h index b2c8b620a6..30e13a9f65 100644 --- a/drivers/gles2/rasterizer_storage_gles2.h +++ b/drivers/gles2/rasterizer_storage_gles2.h @@ -176,7 +176,6 @@ public: bool active; GLenum tex_id; - uint16_t stored_cube_sides; RenderTarget *render_target; @@ -515,7 +514,7 @@ public: virtual RID multimesh_create(); - virtual void multimesh_allocate(RID p_multimesh, int p_instances, VS::MultimeshTransformFormat p_transform_format, VS::MultimeshColorFormat p_color_format,VS::MultimeshCustomDataFormat p_data=VS::MULTIMESH_CUSTOM_DATA_NONE); + virtual void multimesh_allocate(RID p_multimesh, int p_instances, VS::MultimeshTransformFormat p_transform_format, VS::MultimeshColorFormat p_color_format, VS::MultimeshCustomDataFormat p_data = VS::MULTIMESH_CUSTOM_DATA_NONE); virtual int multimesh_get_instance_count(RID p_multimesh) const; virtual void multimesh_set_mesh(RID p_multimesh, RID p_mesh); diff --git a/drivers/gles3/shader_compiler_gles3.cpp b/drivers/gles3/shader_compiler_gles3.cpp index 9ad16ac2a2..3f6fe3ec61 100644 --- a/drivers/gles3/shader_compiler_gles3.cpp +++ b/drivers/gles3/shader_compiler_gles3.cpp @@ -913,6 +913,7 @@ ShaderCompilerGLES3::ShaderCompilerGLES3() { actions[VS::SHADER_SPATIAL].render_mode_defines["specular_toon"] = "#define SPECULAR_TOON\n"; actions[VS::SHADER_SPATIAL].render_mode_defines["specular_disabled"] = "#define SPECULAR_DISABLED\n"; actions[VS::SHADER_SPATIAL].render_mode_defines["shadows_disabled"] = "#define SHADOWS_DISABLED\n"; + actions[VS::SHADER_SPATIAL].render_mode_defines["ambient_light_disabled"] = "#define AMBIENT_LIGHT_DISABLED\n"; /* PARTICLES SHADER */ diff --git a/drivers/gles3/shaders/scene.glsl b/drivers/gles3/shaders/scene.glsl index ed8df04377..abb236138f 100644 --- a/drivers/gles3/shaders/scene.glsl +++ b/drivers/gles3/shaders/scene.glsl @@ -571,11 +571,6 @@ in vec3 normal_interp; /* PBR CHANNELS */ -//used on forward mainly -uniform bool no_ambient_light; - - - #ifdef USE_RADIANCE_MAP @@ -1752,42 +1747,43 @@ FRAGMENT_SHADER_CODE #ifdef USE_RADIANCE_MAP - if (no_ambient_light) { - ambient_light=vec3(0.0,0.0,0.0); - } else { - { - - { //read radiance from dual paraboloid +#ifdef AMBIENT_LIGHT_DISABLED + ambient_light=vec3(0.0,0.0,0.0); +#else + { - vec3 ref_vec = reflect(-eye_vec,normal); //2.0 * ndotv * normal - view; // reflect(v, n); - ref_vec=normalize((radiance_inverse_xform * vec4(ref_vec,0.0)).xyz); - vec3 radiance = textureDualParaboloid(radiance_map,ref_vec,roughness) * bg_energy; - env_reflection_light = radiance; + { //read radiance from dual paraboloid - } - //no longer a cubemap - //vec3 radiance = textureLod(radiance_cube, r, lod).xyz * ( brdf.x + brdf.y); + vec3 ref_vec = reflect(-eye_vec,normal); //2.0 * ndotv * normal - view; // reflect(v, n); + ref_vec=normalize((radiance_inverse_xform * vec4(ref_vec,0.0)).xyz); + vec3 radiance = textureDualParaboloid(radiance_map,ref_vec,roughness) * bg_energy; + env_reflection_light = radiance; } + //no longer a cubemap + //vec3 radiance = textureLod(radiance_cube, r, lod).xyz * ( brdf.x + brdf.y); + + } #ifndef USE_LIGHTMAP - { + { - vec3 ambient_dir=normalize((radiance_inverse_xform * vec4(normal,0.0)).xyz); - vec3 env_ambient=textureDualParaboloid(radiance_map,ambient_dir,1.0) * bg_energy; + vec3 ambient_dir=normalize((radiance_inverse_xform * vec4(normal,0.0)).xyz); + vec3 env_ambient=textureDualParaboloid(radiance_map,ambient_dir,1.0) * bg_energy; - ambient_light=mix(ambient_light_color.rgb,env_ambient,radiance_ambient_contribution); - //ambient_light=vec3(0.0,0.0,0.0); - } -#endif + ambient_light=mix(ambient_light_color.rgb,env_ambient,radiance_ambient_contribution); + //ambient_light=vec3(0.0,0.0,0.0); } +#endif +#endif //AMBIENT_LIGHT_DISABLED #else - if (no_ambient_light){ - ambient_light=vec3(0.0,0.0,0.0); - } else { - ambient_light=ambient_light_color.rgb; - } +#ifdef AMBIENT_LIGHT_DISABLED + ambient_light=vec3(0.0,0.0,0.0); +#else + ambient_light=ambient_light_color.rgb; +#endif //AMBIENT_LIGHT_DISABLED + #endif ambient_light*=ambient_energy; diff --git a/drivers/pulseaudio/audio_driver_pulseaudio.cpp b/drivers/pulseaudio/audio_driver_pulseaudio.cpp index 0f47949b4b..ed6af04b9d 100644 --- a/drivers/pulseaudio/audio_driver_pulseaudio.cpp +++ b/drivers/pulseaudio/audio_driver_pulseaudio.cpp @@ -289,18 +289,18 @@ void AudioDriverPulseAudio::thread_func(void *p_udata) { AudioDriverPulseAudio *ad = (AudioDriverPulseAudio *)p_udata; while (!ad->exit_thread) { + + ad->lock(); + ad->start_counting_ticks(); + if (!ad->active) { for (unsigned int i = 0; i < ad->pa_buffer_size; i++) { ad->samples_out[i] = 0; } } else { - ad->lock(); - ad->audio_server_process(ad->buffer_frames, ad->samples_in.ptrw()); - ad->unlock(); - if (ad->channels == ad->pa_map.channels) { for (unsigned int i = 0; i < ad->pa_buffer_size; i++) { ad->samples_out[i] = ad->samples_in[i] >> 16; @@ -323,9 +323,6 @@ void AudioDriverPulseAudio::thread_func(void *p_udata) { int error_code; int byte_size = ad->pa_buffer_size * sizeof(int16_t); - - ad->lock(); - int ret; do { ret = pa_mainloop_iterate(ad->pa_ml, 0, NULL); @@ -350,11 +347,13 @@ void AudioDriverPulseAudio::thread_func(void *p_udata) { if (ret == 0) { // If pa_mainloop_iterate returns 0 sleep for 1 msec to wait // for the stream to be able to process more bytes + ad->stop_counting_ticks(); ad->unlock(); OS::get_singleton()->delay_usec(1000); ad->lock(); + ad->start_counting_ticks(); } } } @@ -380,6 +379,7 @@ void AudioDriverPulseAudio::thread_func(void *p_udata) { } } + ad->stop_counting_ticks(); ad->unlock(); } @@ -453,7 +453,9 @@ String AudioDriverPulseAudio::get_device() { void AudioDriverPulseAudio::set_device(String device) { + lock(); new_device = device; + unlock(); } void AudioDriverPulseAudio::lock() { diff --git a/drivers/wasapi/audio_driver_wasapi.cpp b/drivers/wasapi/audio_driver_wasapi.cpp index e1680601ad..3c54c429d9 100644 --- a/drivers/wasapi/audio_driver_wasapi.cpp +++ b/drivers/wasapi/audio_driver_wasapi.cpp @@ -335,22 +335,6 @@ Error AudioDriverWASAPI::init() { return OK; } -Error AudioDriverWASAPI::reopen() { - Error err = finish_device(); - if (err != OK) { - ERR_PRINT("WASAPI: finish_device error"); - } else { - err = init_device(); - if (err != OK) { - ERR_PRINT("WASAPI: init_device error"); - } else { - start(); - } - } - - return err; -} - int AudioDriverWASAPI::get_mix_rate() const { return mix_rate; @@ -416,7 +400,9 @@ String AudioDriverWASAPI::get_device() { void AudioDriverWASAPI::set_device(String device) { + lock(); new_device = device; + unlock(); } void AudioDriverWASAPI::write_sample(AudioDriverWASAPI *ad, BYTE *buffer, int i, int32_t sample) { @@ -453,24 +439,31 @@ void AudioDriverWASAPI::thread_func(void *p_udata) { AudioDriverWASAPI *ad = (AudioDriverWASAPI *)p_udata; while (!ad->exit_thread) { - if (ad->active) { - ad->lock(); - ad->audio_server_process(ad->buffer_frames, ad->samples_in.ptrw()); + ad->lock(); + ad->start_counting_ticks(); - ad->unlock(); + if (ad->active) { + ad->audio_server_process(ad->buffer_frames, ad->samples_in.ptrw()); } else { for (unsigned int i = 0; i < ad->buffer_size; i++) { ad->samples_in[i] = 0; } } + ad->stop_counting_ticks(); + ad->unlock(); + unsigned int left_frames = ad->buffer_frames; unsigned int buffer_idx = 0; while (left_frames > 0 && ad->audio_client) { WaitForSingleObject(ad->event, 1000); + ad->lock(); + ad->start_counting_ticks(); + UINT32 cur_frames; + bool invalidated = false; HRESULT hr = ad->audio_client->GetCurrentPadding(&cur_frames); if (hr == S_OK) { // Check how much frames are available on the WASAPI buffer @@ -506,34 +499,34 @@ void AudioDriverWASAPI::thread_func(void *p_udata) { left_frames -= write_frames; } else if (hr == AUDCLNT_E_DEVICE_INVALIDATED) { - // Device is not valid anymore, reopen it - - Error err = ad->finish_device(); - if (err != OK) { - ERR_PRINT("WASAPI: finish_device error"); - } else { - // We reopened the device and samples_in may have resized, so invalidate the current left_frames - left_frames = 0; - } + invalidated = true; } else { ERR_PRINT("WASAPI: Get buffer error"); ad->exit_thread = true; } } else if (hr == AUDCLNT_E_DEVICE_INVALIDATED) { - // Device is not valid anymore, reopen it + invalidated = true; + } else { + ERR_PRINT("WASAPI: GetCurrentPadding error"); + } + + if (invalidated) { + // Device is not valid anymore + WARN_PRINT("WASAPI: Current device invalidated, closing device"); Error err = ad->finish_device(); if (err != OK) { ERR_PRINT("WASAPI: finish_device error"); - } else { - // We reopened the device and samples_in may have resized, so invalidate the current left_frames - left_frames = 0; } - } else { - ERR_PRINT("WASAPI: GetCurrentPadding error"); } + + ad->stop_counting_ticks(); + ad->unlock(); } + ad->lock(); + ad->start_counting_ticks(); + // If we're using the Default device and it changed finish it so we'll re-init the device if (ad->device_name == "Default" && default_device_changed) { Error err = ad->finish_device(); @@ -559,6 +552,9 @@ void AudioDriverWASAPI::thread_func(void *p_udata) { ad->start(); } } + + ad->stop_counting_ticks(); + ad->unlock(); } ad->thread_exited = true; diff --git a/drivers/wasapi/audio_driver_wasapi.h b/drivers/wasapi/audio_driver_wasapi.h index c97f4c288c..f3ee5976eb 100644 --- a/drivers/wasapi/audio_driver_wasapi.h +++ b/drivers/wasapi/audio_driver_wasapi.h @@ -72,7 +72,6 @@ class AudioDriverWASAPI : public AudioDriver { Error init_device(bool reinit = false); Error finish_device(); - Error reopen(); public: virtual const char *get_name() const { diff --git a/drivers/windows/file_access_windows.cpp b/drivers/windows/file_access_windows.cpp index aa0fd34e0a..ea194e5eae 100644 --- a/drivers/windows/file_access_windows.cpp +++ b/drivers/windows/file_access_windows.cpp @@ -141,9 +141,9 @@ void FileAccessWindows::close() { bool rename_error = true; int attempts = 4; while (rename_error && attempts) { - // This workaround of trying multiple times is added to deal with paranoid Windows - // antiviruses that love reading just written files even if they are not executable, thus - // locking the file and preventing renaming from happening. + // This workaround of trying multiple times is added to deal with paranoid Windows + // antiviruses that love reading just written files even if they are not executable, thus + // locking the file and preventing renaming from happening. #ifdef UWP_ENABLED // UWP has no PathFileExists, so we check attributes instead diff --git a/editor/connections_dialog.cpp b/editor/connections_dialog.cpp index 7f93917744..8933fd7fe8 100644 --- a/editor/connections_dialog.cpp +++ b/editor/connections_dialog.cpp @@ -428,6 +428,13 @@ void ConnectionsDock::_make_or_edit_connection() { bool oshot = connect_dialog->get_oneshot(); cToMake.flags = CONNECT_PERSIST | (defer ? CONNECT_DEFERRED : 0) | (oshot ? CONNECT_ONESHOT : 0); + bool add_script_function = connect_dialog->get_make_callback(); + PoolStringArray script_function_args; + if (add_script_function) { + // pick up args here before "it" is deleted by update_tree + script_function_args = it->get_metadata(0).operator Dictionary()["args"]; + } + if (connect_dialog->is_editing()) { _disconnect(*it); _connect(cToMake); @@ -435,9 +442,12 @@ void ConnectionsDock::_make_or_edit_connection() { _connect(cToMake); } - if (connect_dialog->get_make_callback()) { - PoolStringArray args = it->get_metadata(0).operator Dictionary()["args"]; - editor->emit_signal("script_add_function_request", target, cToMake.method, args); + // IMPORTANT NOTE: _disconnect and _connect cause an update_tree, + // which will delete the object "it" is pointing to + it = NULL; + + if (add_script_function) { + editor->emit_signal("script_add_function_request", target, cToMake.method, script_function_args); hide(); } diff --git a/editor/editor_export.cpp b/editor/editor_export.cpp index 7739b08eff..317fffad64 100644 --- a/editor/editor_export.cpp +++ b/editor/editor_export.cpp @@ -409,6 +409,7 @@ void EditorExportPlatform::_edit_files_with_filter(DirAccess *da, const Vector<S String cur_dir = da->get_current_dir().replace("\\", "/"); if (!cur_dir.ends_with("/")) cur_dir += "/"; + String cur_dir_no_prefix = cur_dir.replace("res://", ""); Vector<String> dirs; String f; @@ -417,8 +418,10 @@ void EditorExportPlatform::_edit_files_with_filter(DirAccess *da, const Vector<S dirs.push_back(f); else { String fullpath = cur_dir + f; + // Test also against path without res:// so that filters like `file.txt` can work. + String fullpath_no_prefix = cur_dir_no_prefix + f; for (int i = 0; i < p_filters.size(); ++i) { - if (fullpath.matchn(p_filters[i])) { + if (fullpath.matchn(p_filters[i]) || fullpath_no_prefix.matchn(p_filters[i])) { if (!exclude) { r_list.insert(fullpath); } else { diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index 17f383c8ae..482b0dec35 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -91,6 +91,9 @@ void EditorProperty::_notification(int p_what) { Rect2 rect; Rect2 bottom_rect; + right_child_rect = Rect2(); + bottom_child_rect = Rect2(); + { int child_room = size.width * (1.0 - split_ratio); Ref<Font> font = get_font("font", "Tree"); @@ -118,7 +121,8 @@ void EditorProperty::_notification(int p_what) { if (bottom_editor) { - int m = get_constant("item_margin", "Tree"); + int m = 0; //get_constant("item_margin", "Tree"); + bottom_rect = Rect2(m, rect.size.height + get_constant("vseparation", "Tree"), size.width - m, bottom_editor->get_combined_minimum_size().height); } } @@ -147,10 +151,12 @@ void EditorProperty::_notification(int p_what) { continue; fit_child_in_rect(c, rect); + right_child_rect = rect; } if (bottom_editor) { fit_child_in_rect(bottom_editor, bottom_rect); + bottom_child_rect = bottom_rect; } update(); //need to redraw text @@ -158,6 +164,7 @@ void EditorProperty::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { Ref<Font> font = get_font("font", "Tree"); + Color dark_color = get_color("dark_color_2", "Editor"); Size2 size = get_size(); if (bottom_editor) { @@ -171,6 +178,13 @@ void EditorProperty::_notification(int p_what) { draw_style_box(sb, Rect2(Vector2(), size)); } + if (right_child_rect != Rect2()) { + draw_rect(right_child_rect, dark_color); + } + if (bottom_child_rect != Rect2()) { + draw_rect(bottom_child_rect, dark_color); + } + Color color; if (draw_red) { color = get_color("error_color", "Editor"); @@ -251,7 +265,7 @@ void EditorProperty::_notification(int p_what) { //int vs = get_constant("vseparation", "Tree"); Color guide_color = get_color("guide_color", "Tree"); int vs_height = get_size().height; // vs / 2; - draw_line(Point2(0, vs_height), Point2(get_size().width, vs_height), guide_color); + // draw_line(Point2(0, vs_height), Point2(get_size().width, vs_height), guide_color); } } @@ -926,6 +940,14 @@ EditorInspectorCategory::EditorInspectorCategory() { //////////////////////////////////////////////// //////////////////////////////////////////////// +void EditorInspectorSection::_test_unfold() { + + if (!vbox_added) { + add_child(vbox); + vbox_added = true; + } +} + void EditorInspectorSection::_notification(int p_what) { if (p_what == NOTIFICATION_SORT_CHILDREN) { @@ -936,9 +958,9 @@ void EditorInspectorSection::_notification(int p_what) { #ifdef TOOLS_ENABLED if (foldable) { if (object->editor_is_section_unfolded(section)) { - arrow = get_icon("arrow", "Tree"); + arrow = get_icon("arrow_up", "Tree"); } else { - arrow = get_icon("arrow_collapsed", "Tree"); + arrow = get_icon("arrow", "Tree"); } } #endif @@ -951,7 +973,7 @@ void EditorInspectorSection::_notification(int p_what) { } offset.y += get_constant("vseparation", "Tree"); - offset.x += get_constant("item_margin", "Tree"); + offset.x += get_constant("inspector_margin", "Editor"); Rect2 rect(offset, size - offset); @@ -979,9 +1001,9 @@ void EditorInspectorSection::_notification(int p_what) { #ifdef TOOLS_ENABLED if (foldable) { if (object->editor_is_section_unfolded(section)) { - arrow = get_icon("arrow", "Tree"); + arrow = get_icon("arrow_up", "Tree"); } else { - arrow = get_icon("arrow_collapsed", "Tree"); + arrow = get_icon("arrow", "Tree"); } } #endif @@ -998,14 +1020,14 @@ void EditorInspectorSection::_notification(int p_what) { int hs = get_constant("hseparation", "Tree"); + Color color = get_color("font_color", "Tree"); + draw_string(font, Point2(hs, font->get_ascent() + (h - font->get_height()) / 2).floor(), label, color, get_size().width); + int ofs = 0; if (arrow.is_valid()) { - draw_texture(arrow, Point2(ofs, (h - arrow->get_height()) / 2).floor()); + draw_texture(arrow, Point2(get_size().width - arrow->get_width(), (h - arrow->get_height()) / 2).floor()); ofs += hs + arrow->get_width(); } - - Color color = get_color("font_color", "Tree"); - draw_string(font, Point2(ofs, font->get_ascent() + (h - font->get_height()) / 2).floor(), label, color, get_size().width); } } @@ -1027,8 +1049,8 @@ Size2 EditorInspectorSection::get_minimum_size() const { } Ref<Font> font = get_font("font", "Tree"); - ms.height += font->get_ascent() + get_constant("vseparation", "Tree"); - ms.width += get_constant("item_margin", "Tree"); + ms.height += font->get_height() + get_constant("vseparation", "Tree"); + ms.width += get_constant("inspector_margin", "Editor"); return ms; } @@ -1041,16 +1063,20 @@ void EditorInspectorSection::setup(const String &p_section, const String &p_labe bg_color = p_bg_color; foldable = p_foldable; + if (!foldable && !vbox_added) { + add_child(vbox); + vbox_added = true; + } + #ifdef TOOLS_ENABLED if (foldable) { + _test_unfold(); if (object->editor_is_section_unfolded(section)) { vbox->show(); } else { vbox->hide(); } } - // void editor_set_section_unfold(const String &p_section, bool p_unfolded); - #endif } @@ -1063,6 +1089,9 @@ void EditorInspectorSection::_gui_input(const Ref<InputEvent> &p_event) { Ref<InputEventMouseButton> mb = p_event; if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) { + + _test_unfold(); + bool unfold = !object->editor_is_section_unfolded(section); object->editor_set_section_unfold(section, unfold); if (unfold) { @@ -1082,6 +1111,9 @@ void EditorInspectorSection::unfold() { if (!foldable) return; + + _test_unfold(); + #ifdef TOOLS_ENABLED object->editor_set_section_unfold(section, true); @@ -1094,6 +1126,8 @@ void EditorInspectorSection::fold() { if (!foldable) return; + if (!vbox_added) + return; //kinda pointless #ifdef TOOLS_ENABLED object->editor_set_section_unfold(section, false); @@ -1115,7 +1149,14 @@ EditorInspectorSection::EditorInspectorSection() { object = NULL; foldable = false; vbox = memnew(VBoxContainer); - add_child(vbox); + vbox_added = false; + //add_child(vbox); +} + +EditorInspectorSection::~EditorInspectorSection() { + if (!vbox_added) { + memdelete(vbox); + } } //////////////////////////////////////////////// @@ -1276,8 +1317,10 @@ void EditorInspector::update_tree() { String filter = search_box ? search_box->get_text() : ""; String group; String group_base; + VBoxContainer *category_vbox = NULL; - List<PropertyInfo> plist; + List<PropertyInfo> + plist; object->get_property_list(&plist, true); HashMap<String, VBoxContainer *> item_path; @@ -1329,6 +1372,7 @@ void EditorInspector::update_tree() { EditorInspectorCategory *category = memnew(EditorInspectorCategory); main_vbox->add_child(category); + category_vbox = NULL; //reset String type = p.name; if (has_icon(type, "EditorIcons")) @@ -1414,6 +1458,11 @@ void EditorInspector::update_tree() { continue; } + if (category_vbox == NULL) { + category_vbox = memnew(VBoxContainer); + main_vbox->add_child(category_vbox); + } + VBoxContainer *current_vbox = main_vbox; { @@ -1441,6 +1490,14 @@ void EditorInspector::update_tree() { current_vbox = item_path[acc_path]; level = (MIN(level + 1, 4)); } + + if (current_vbox == main_vbox) { + //do not add directly to the main vbox, given it has no spacing + if (category_vbox == NULL) { + category_vbox = memnew(VBoxContainer); + } + current_vbox = category_vbox; + } } bool checkable = false; @@ -1627,6 +1684,10 @@ void EditorInspector::edit(Object *p_object) { object = p_object; if (object) { + update_scroll_request = 0; //reset + if (scroll_cache.has(object->get_instance_id())) { //if exists, set something else + update_scroll_request = scroll_cache[object->get_instance_id()]; //done this way because wait until full size is accomodated + } object->add_change_receptor(this); update_tree(); } @@ -1732,6 +1793,19 @@ int EditorInspector::get_scroll_offset() const { return get_v_scroll(); } +void EditorInspector::set_use_sub_inspector_bg(bool p_enable) { + + use_sub_inspector_bg = p_enable; + if (!is_inside_tree()) + return; + + if (use_sub_inspector_bg) { + add_style_override("bg", get_stylebox("sub_inspector_bg", "Editor")); + } else { + add_style_override("bg", get_stylebox("bg", "Tree")); + } +} + void EditorInspector::_edit_request_change(Object *p_object, const String &p_property) { if (object != p_object) //may be undoing/redoing for a non edited object, so ignore @@ -1942,7 +2016,11 @@ void EditorInspector::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE) { get_tree()->connect("node_removed", this, "_node_removed"); - add_style_override("bg", get_stylebox("bg", "Tree")); + if (use_sub_inspector_bg) { + add_style_override("bg", get_stylebox("sub_inspector_bg", "Editor")); + } else if (is_inside_tree()) { + add_style_override("bg", get_stylebox("bg", "Tree")); + } } if (p_what == NOTIFICATION_EXIT_TREE) { @@ -1952,6 +2030,10 @@ void EditorInspector::_notification(int p_what) { if (p_what == NOTIFICATION_PROCESS) { + if (update_scroll_request >= 0) { + get_v_scrollbar()->call_deferred("set_value", update_scroll_request); + update_scroll_request = -1; + } if (refresh_countdown > 0) { refresh_countdown -= get_process_delta_time(); if (refresh_countdown <= 0) { @@ -1999,6 +2081,16 @@ void EditorInspector::_changed_callback(Object *p_changed, const char *p_prop) { _edit_request_change(p_changed, p_prop); } +void EditorInspector::_vscroll_changed(double p_offset) { + + if (update_scroll_request >= 0) //waiting, do nothing + return; + + if (object) { + scroll_cache[object->get_instance_id()] = p_offset; + } +} + void EditorInspector::_bind_methods() { ClassDB::bind_method("_property_changed", &EditorInspector::_property_changed, DEFVAL(false)); @@ -2014,6 +2106,8 @@ void EditorInspector::_bind_methods() { ClassDB::bind_method("_property_selected", &EditorInspector::_property_selected); ClassDB::bind_method("_resource_selected", &EditorInspector::_resource_selected); ClassDB::bind_method("_object_id_selected", &EditorInspector::_object_id_selected); + ClassDB::bind_method("_vscroll_changed", &EditorInspector::_vscroll_changed); + ClassDB::bind_method("refresh", &EditorInspector::refresh); ADD_SIGNAL(MethodInfo("property_keyed", PropertyInfo(Variant::STRING, "property"))); @@ -2026,6 +2120,7 @@ EditorInspector::EditorInspector() { undo_redo = NULL; main_vbox = memnew(VBoxContainer); main_vbox->set_h_size_flags(SIZE_EXPAND_FILL); + main_vbox->add_constant_override("separation", 0); add_child(main_vbox); set_enable_h_scroll(false); set_enable_v_scroll(true); @@ -2047,4 +2142,8 @@ EditorInspector::EditorInspector() { _prop_edited = "property_edited"; set_process(true); property_focusable = -1; + use_sub_inspector_bg = false; + + get_v_scrollbar()->connect("value_changed", this, "_vscroll_changed"); + update_scroll_request = -1; } diff --git a/editor/editor_inspector.h b/editor/editor_inspector.h index b7a492f114..320641c693 100644 --- a/editor/editor_inspector.h +++ b/editor/editor_inspector.h @@ -55,6 +55,9 @@ private: bool draw_red; bool keying; + Rect2 right_child_rect; + Rect2 bottom_child_rect; + Rect2 keying_rect; bool keying_hover; Rect2 revert_rect; @@ -194,9 +197,12 @@ class EditorInspectorSection : public Container { String section; Object *object; VBoxContainer *vbox; + bool vbox_added; //optimization Color bg_color; bool foldable; + void _test_unfold(); + protected: void _notification(int p_what); static void _bind_methods(); @@ -213,6 +219,7 @@ public: Object *get_edited_object(); EditorInspectorSection(); + ~EditorInspectorSection(); }; class EditorInspector : public ScrollContainer { @@ -249,16 +256,20 @@ class EditorInspector : public ScrollContainer { bool update_all_pending; bool read_only; bool keying; + bool use_sub_inspector_bg; float refresh_countdown; bool update_tree_pending; StringName _prop_edited; StringName property_selected; int property_focusable; + int update_scroll_request; Map<StringName, Map<StringName, String> > descr_cache; Map<StringName, String> class_descr_cache; + Map<ObjectID, int> scroll_cache; + void _edit_set(const String &p_name, const Variant &p_value, bool p_refresh_all, const String &p_changed_field); void _property_changed(const String &p_path, const Variant &p_value, bool changing = false); @@ -281,6 +292,8 @@ class EditorInspector : public ScrollContainer { void _filter_changed(const String &p_text); void _parse_added_editors(VBoxContainer *current_vbox, Ref<EditorInspectorPlugin> ped); + void _vscroll_changed(double); + protected: static void _bind_methods(); void _notification(int p_what); @@ -330,6 +343,8 @@ public: void set_scroll_offset(int p_offset); int get_scroll_offset() const; + void set_use_sub_inspector_bg(bool p_enable); + EditorInspector(); }; diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 70bc090bc4..52f6f1ed0e 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -73,6 +73,7 @@ #include "editor/plugins/animation_state_machine_editor.h" #include "editor/plugins/animation_tree_editor_plugin.h" #include "editor/plugins/asset_library_editor_plugin.h" +#include "editor/plugins/audio_stream_editor_plugin.h" #include "editor/plugins/baked_lightmap_editor_plugin.h" #include "editor/plugins/camera_editor_plugin.h" #include "editor/plugins/canvas_item_editor_plugin.h" @@ -1855,10 +1856,6 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { } break; - case SETTINGS_EXPORT_PREFERENCES: { - - //project_export_settings->popup_centered_ratio(); - } break; case FILE_IMPORT_SUBSCENE: { if (!editor_data.get_edited_scene_root()) { @@ -4189,7 +4186,7 @@ void EditorNode::_dropped_files(const Vector<String> &p_files, int p_screen) { for (int i = 0; i < p_files.size(); i++) { String from = p_files[i]; - if (!ResourceFormatImporter::get_singleton()->can_be_imported(from) && (just_copy.find(from.get_extension().to_lower()) != -1)) { + if (!ResourceFormatImporter::get_singleton()->can_be_imported(from) && (just_copy.find(from.get_extension().to_lower()) == -1)) { continue; } String to = to_path.plus_file(from.get_file()); @@ -4673,7 +4670,7 @@ EditorNode::EditorNode() { EDITOR_DEF("interface/inspector/capitalize_properties", true); EDITOR_DEF("interface/inspector/disable_folding", false); EDITOR_DEF("interface/inspector/open_resources_in_current_inspector", true); - EDITOR_DEF("interface/inspector/resources_types_to_open_in_new_inspector", "Material,Mesh"); + EDITOR_DEF("interface/inspector/resources_types_to_open_in_new_inspector", "SpatialMaterial"); EDITOR_DEF("run/auto_save/save_before_running", true); theme_base = memnew(Control); @@ -5445,6 +5442,7 @@ EditorNode::EditorNode() { add_editor_plugin(memnew(CollisionShape2DEditorPlugin(this))); add_editor_plugin(memnew(CurveEditorPlugin(this))); add_editor_plugin(memnew(TextureEditorPlugin(this))); + add_editor_plugin(memnew(AudioStreamEditorPlugin(this))); add_editor_plugin(memnew(AudioBusesEditorPlugin(audio_bus_editor))); add_editor_plugin(memnew(AudioBusesEditorPlugin(audio_bus_editor))); add_editor_plugin(memnew(SkeletonEditorPlugin(this))); diff --git a/editor/editor_node.h b/editor/editor_node.h index 7aa060fe14..88fe008b34 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -164,7 +164,6 @@ private: SETTINGS_UPDATE_ALWAYS, SETTINGS_UPDATE_CHANGES, SETTINGS_UPDATE_SPINNER_HIDE, - SETTINGS_EXPORT_PREFERENCES, SETTINGS_PREFERENCES, SETTINGS_LAYOUT_SAVE, SETTINGS_LAYOUT_DELETE, diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index cd0bba4c9c..0b49b5a801 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -178,6 +178,8 @@ void EditorPropertyTextEnum::_bind_methods() { EditorPropertyTextEnum::EditorPropertyTextEnum() { options = memnew(OptionButton); options->set_clip_text(true); + options->set_flat(true); + add_child(options); add_focusable(options); options->connect("item_selected", this, "_option_selected"); @@ -441,6 +443,7 @@ void EditorPropertyEnum::_bind_methods() { EditorPropertyEnum::EditorPropertyEnum() { options = memnew(OptionButton); options->set_clip_text(true); + options->set_flat(true); add_child(options); add_focusable(options); options->connect("item_selected", this, "_option_selected"); @@ -641,9 +644,11 @@ void EditorPropertyLayers::setup(LayerType p_layer_type) { } if (name == "") { - name = "Layer " + itos(i + 1); + name = TTR("Layer") + " " + itos(i + 1); } + name += "\n" + vformat(TTR("Bit %d, value %d"), i, 1 << i); + names.push_back(name); } @@ -733,6 +738,7 @@ void EditorPropertyInteger::setup(int p_min, int p_max, bool p_allow_greater, bo EditorPropertyInteger::EditorPropertyInteger() { spin = memnew(EditorSpinSlider); + spin->set_flat(true); add_child(spin); add_focusable(spin); spin->connect("value_changed", this, "_value_changed"); @@ -819,6 +825,7 @@ void EditorPropertyFloat::setup(double p_min, double p_max, double p_step, bool EditorPropertyFloat::EditorPropertyFloat() { spin = memnew(EditorSpinSlider); + spin->set_flat(true); add_child(spin); add_focusable(spin); spin->connect("value_changed", this, "_value_changed"); @@ -829,6 +836,12 @@ EditorPropertyFloat::EditorPropertyFloat() { void EditorPropertyEasing::_drag_easing(const Ref<InputEvent> &p_ev) { + Ref<InputEventMouseButton> mb = p_ev; + if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_RIGHT) { + preset->set_global_position(easing_draw->get_global_transform().xform(mb->get_position())); + preset->popup(); + } + Ref<InputEventMouseMotion> mm = p_ev; if (mm.is_valid() && mm->get_button_mask() & BUTTON_MASK_LEFT) { @@ -866,7 +879,7 @@ void EditorPropertyEasing::_draw_easing() { Size2 s = easing_draw->get_size(); Rect2 r(Point2(), s); r = r.grow(3); - get_stylebox("normal", "LineEdit")->draw(ci, r); + //get_stylebox("normal", "LineEdit")->draw(ci, r); int points = 48; @@ -876,6 +889,7 @@ void EditorPropertyEasing::_draw_easing() { Ref<Font> f = get_font("font", "Label"); Color color = get_color("font_color", "Label"); + Vector<Point2> lines; for (int i = 1; i <= points; i++) { float ifl = i / float(points); @@ -888,10 +902,12 @@ void EditorPropertyEasing::_draw_easing() { iflp = 1.0 - iflp; } - VisualServer::get_singleton()->canvas_item_add_line(ci, Point2(iflp * s.width, prev * s.height), Point2(ifl * s.width, h * s.height), color); + lines.push_back(Point2(ifl * s.width, h * s.height)); + lines.push_back(Point2(iflp * s.width, prev * s.height)); prev = h; } + easing_draw->draw_multiline(lines, color, 1.0, true); f->draw(ci, Point2(10, 10 + f->get_ascent()), String::num(exp, 2), color); } @@ -899,29 +915,17 @@ void EditorPropertyEasing::update_property() { easing_draw->update(); } -void EditorPropertyEasing::_set_preset(float p_val) { - emit_signal("property_changed", get_edited_property(), p_val); +void EditorPropertyEasing::_set_preset(int p_preset) { + static const float preset_value[EASING_MAX] = { 0.0, 1.0, 2.0, 0.5, -2.0, -0.5 }; + + emit_signal("property_changed", get_edited_property(), preset_value[p_preset]); easing_draw->update(); } void EditorPropertyEasing::setup(bool p_full, bool p_flip) { flip = p_flip; - if (p_full) { - HBoxContainer *hb2 = memnew(HBoxContainer); - vb->add_child(hb2); - button_out_in = memnew(ToolButton); - button_out_in->set_tooltip(TTR("Out-In")); - button_out_in->set_h_size_flags(SIZE_EXPAND_FILL); - button_out_in->connect("pressed", this, "_set_preset", varray(-0.5)); - hb2->add_child(button_out_in); - - button_in_out = memnew(ToolButton); - button_in_out->set_tooltip(TTR("In")); - button_in_out->set_h_size_flags(SIZE_EXPAND_FILL); - button_in_out->connect("pressed", this, "_set_preset", varray(-2)); - hb2->add_child(button_in_out); - } + full = p_full; } void EditorPropertyEasing::_notification(int p_what) { @@ -929,15 +933,19 @@ void EditorPropertyEasing::_notification(int p_what) { switch (p_what) { case NOTIFICATION_THEME_CHANGED: case NOTIFICATION_ENTER_TREE: { + preset->clear(); + preset->add_icon_item(get_icon("CurveConstant", "EditorIcons"), "Zero", EASING_ZERO); + preset->add_icon_item(get_icon("CurveLinear", "EditorIcons"), "Linear", EASING_LINEAR); + preset->add_icon_item(get_icon("CurveIn", "EditorIcons"), "In", EASING_IN); + preset->add_icon_item(get_icon("CurveOut", "EditorIcons"), "Out", EASING_OUT); + if (full) { + preset->add_icon_item(get_icon("CurveInOut", "EditorIcons"), "In-Out", EASING_IN_OUT); + preset->add_icon_item(get_icon("CurveOutIn", "EditorIcons"), "Out-In", EASING_OUT_IN); + } easing_draw->set_custom_minimum_size(Size2(0, get_font("font", "Label")->get_height() * 2)); - button_linear->set_icon(get_icon("CurveLinear", "EditorIcons")); - button_out->set_icon(get_icon("CurveOut", "EditorIcons")); - button_in->set_icon(get_icon("CurveIn", "EditorIcons")); - button_constant->set_icon(get_icon("CurveConstant", "EditorIcons")); - if (button_out_in) - button_out_in->set_icon(get_icon("CurveOutIn", "EditorIcons")); - if (button_in_out) - button_in_out->set_icon(get_icon("CurveInOut", "EditorIcons")); + } break; + case NOTIFICATION_RESIZED: { + } break; } } @@ -951,47 +959,18 @@ void EditorPropertyEasing::_bind_methods() { EditorPropertyEasing::EditorPropertyEasing() { - vb = memnew(VBoxContainer); - add_child(vb); - HBoxContainer *hb = memnew(HBoxContainer); - set_label_reference(hb); - - vb->add_child(hb); - - button_linear = memnew(ToolButton); - button_linear->set_tooltip(TTR("Linear")); - button_linear->set_h_size_flags(SIZE_EXPAND_FILL); - button_linear->connect("pressed", this, "_set_preset", varray(1)); - hb->add_child(button_linear); - - button_constant = memnew(ToolButton); - button_constant->set_tooltip(TTR("Linear")); - button_constant->set_h_size_flags(SIZE_EXPAND_FILL); - button_constant->connect("pressed", this, "_set_preset", varray(0)); - hb->add_child(button_constant); - - button_out = memnew(ToolButton); - button_out->set_tooltip(TTR("Out")); - button_out->set_h_size_flags(SIZE_EXPAND_FILL); - button_out->connect("pressed", this, "_set_preset", varray(0.5)); - hb->add_child(button_out); - - button_in = memnew(ToolButton); - button_in->set_tooltip(TTR("In")); - button_in->set_h_size_flags(SIZE_EXPAND_FILL); - button_in->connect("pressed", this, "_set_preset", varray(2)); - hb->add_child(button_in); - - button_in_out = NULL; - button_out_in = NULL; - easing_draw = memnew(Control); easing_draw->connect("draw", this, "_draw_easing"); easing_draw->connect("gui_input", this, "_drag_easing"); easing_draw->set_default_cursor_shape(Control::CURSOR_MOVE); - vb->add_child(easing_draw); + add_child(easing_draw); + + preset = memnew(PopupMenu); + add_child(preset); + preset->connect("id_pressed", this, "_set_preset"); flip = false; + full = false; } ///////////////////// VECTOR2 ///////////////////////// @@ -1014,6 +993,18 @@ void EditorPropertyVector2::update_property() { setting = false; } +void EditorPropertyVector2::_notification(int p_what) { + if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { + Color base = get_color("accent_color", "Editor"); + for (int i = 0; i < 2; i++) { + + Color c = base; + c.set_hsv(float(i) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v()); + spin[i]->set_custom_label_color(true, c); + } + } +} + void EditorPropertyVector2::_bind_methods() { ClassDB::bind_method(D_METHOD("_value_changed"), &EditorPropertyVector2::_value_changed); @@ -1034,6 +1025,7 @@ EditorPropertyVector2::EditorPropertyVector2() { static const char *desc[2] = { "x", "y" }; for (int i = 0; i < 2; i++) { spin[i] = memnew(EditorSpinSlider); + spin[i]->set_flat(true); spin[i]->set_label(desc[i]); vb->add_child(spin[i]); add_focusable(spin[i]); @@ -1066,7 +1058,17 @@ void EditorPropertyRect2::update_property() { spin[3]->set_value(val.size.y); setting = false; } +void EditorPropertyRect2::_notification(int p_what) { + if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { + Color base = get_color("accent_color", "Editor"); + for (int i = 0; i < 4; i++) { + Color c = base; + c.set_hsv(float(i % 2) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v()); + spin[i]->set_custom_label_color(true, c); + } + } +} void EditorPropertyRect2::_bind_methods() { ClassDB::bind_method(D_METHOD("_value_changed"), &EditorPropertyRect2::_value_changed); @@ -1088,6 +1090,8 @@ EditorPropertyRect2::EditorPropertyRect2() { for (int i = 0; i < 4; i++) { spin[i] = memnew(EditorSpinSlider); spin[i]->set_label(desc[i]); + spin[i]->set_flat(true); + vb->add_child(spin[i]); add_focusable(spin[i]); spin[i]->connect("value_changed", this, "_value_changed"); @@ -1116,7 +1120,17 @@ void EditorPropertyVector3::update_property() { spin[2]->set_value(val.z); setting = false; } +void EditorPropertyVector3::_notification(int p_what) { + if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { + Color base = get_color("accent_color", "Editor"); + for (int i = 0; i < 3; i++) { + Color c = base; + c.set_hsv(float(i) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v()); + spin[i]->set_custom_label_color(true, c); + } + } +} void EditorPropertyVector3::_bind_methods() { ClassDB::bind_method(D_METHOD("_value_changed"), &EditorPropertyVector3::_value_changed); @@ -1138,6 +1152,8 @@ EditorPropertyVector3::EditorPropertyVector3() { for (int i = 0; i < 3; i++) { spin[i] = memnew(EditorSpinSlider); spin[i]->set_label(desc[i]); + spin[i]->set_flat(true); + vb->add_child(spin[i]); add_focusable(spin[i]); spin[i]->connect("value_changed", this, "_value_changed"); @@ -1168,7 +1184,17 @@ void EditorPropertyPlane::update_property() { spin[3]->set_value(val.d); setting = false; } +void EditorPropertyPlane::_notification(int p_what) { + if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { + Color base = get_color("accent_color", "Editor"); + for (int i = 0; i < 3; i++) { + Color c = base; + c.set_hsv(float(i) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v()); + spin[i]->set_custom_label_color(true, c); + } + } +} void EditorPropertyPlane::_bind_methods() { ClassDB::bind_method(D_METHOD("_value_changed"), &EditorPropertyPlane::_value_changed); @@ -1190,6 +1216,7 @@ EditorPropertyPlane::EditorPropertyPlane() { for (int i = 0; i < 4; i++) { spin[i] = memnew(EditorSpinSlider); spin[i]->set_label(desc[i]); + spin[i]->set_flat(true); vb->add_child(spin[i]); add_focusable(spin[i]); spin[i]->connect("value_changed", this, "_value_changed"); @@ -1221,7 +1248,17 @@ void EditorPropertyQuat::update_property() { spin[3]->set_value(val.w); setting = false; } +void EditorPropertyQuat::_notification(int p_what) { + if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { + Color base = get_color("accent_color", "Editor"); + for (int i = 0; i < 3; i++) { + Color c = base; + c.set_hsv(float(i) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v()); + spin[i]->set_custom_label_color(true, c); + } + } +} void EditorPropertyQuat::_bind_methods() { ClassDB::bind_method(D_METHOD("_value_changed"), &EditorPropertyQuat::_value_changed); @@ -1243,6 +1280,8 @@ EditorPropertyQuat::EditorPropertyQuat() { for (int i = 0; i < 4; i++) { spin[i] = memnew(EditorSpinSlider); spin[i]->set_label(desc[i]); + spin[i]->set_flat(true); + vb->add_child(spin[i]); add_focusable(spin[i]); spin[i]->connect("value_changed", this, "_value_changed"); @@ -1280,7 +1319,17 @@ void EditorPropertyAABB::update_property() { setting = false; } +void EditorPropertyAABB::_notification(int p_what) { + if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { + Color base = get_color("accent_color", "Editor"); + for (int i = 0; i < 6; i++) { + Color c = base; + c.set_hsv(float(i % 3) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v()); + spin[i]->set_custom_label_color(true, c); + } + } +} void EditorPropertyAABB::_bind_methods() { ClassDB::bind_method(D_METHOD("_value_changed"), &EditorPropertyAABB::_value_changed); @@ -1304,6 +1353,8 @@ EditorPropertyAABB::EditorPropertyAABB() { for (int i = 0; i < 6; i++) { spin[i] = memnew(EditorSpinSlider); spin[i]->set_label(desc[i]); + spin[i]->set_flat(true); + g->add_child(spin[i]); spin[i]->set_h_size_flags(SIZE_EXPAND_FILL); add_focusable(spin[i]); @@ -1342,7 +1393,17 @@ void EditorPropertyTransform2D::update_property() { setting = false; } +void EditorPropertyTransform2D::_notification(int p_what) { + if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { + Color base = get_color("accent_color", "Editor"); + for (int i = 0; i < 6; i++) { + Color c = base; + c.set_hsv(float(i % 2) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v()); + spin[i]->set_custom_label_color(true, c); + } + } +} void EditorPropertyTransform2D::_bind_methods() { ClassDB::bind_method(D_METHOD("_value_changed"), &EditorPropertyTransform2D::_value_changed); @@ -1362,10 +1423,11 @@ EditorPropertyTransform2D::EditorPropertyTransform2D() { g->set_columns(2); add_child(g); - static const char *desc[6] = { "xx", "xy", "yx", "yy", "ox", "oy" }; + static const char *desc[6] = { "x", "y", "x", "y", "x", "y" }; for (int i = 0; i < 6; i++) { spin[i] = memnew(EditorSpinSlider); spin[i]->set_label(desc[i]); + spin[i]->set_flat(true); g->add_child(spin[i]); spin[i]->set_h_size_flags(SIZE_EXPAND_FILL); add_focusable(spin[i]); @@ -1410,7 +1472,17 @@ void EditorPropertyBasis::update_property() { setting = false; } +void EditorPropertyBasis::_notification(int p_what) { + if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { + Color base = get_color("accent_color", "Editor"); + for (int i = 0; i < 9; i++) { + Color c = base; + c.set_hsv(float(i % 3) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v()); + spin[i]->set_custom_label_color(true, c); + } + } +} void EditorPropertyBasis::_bind_methods() { ClassDB::bind_method(D_METHOD("_value_changed"), &EditorPropertyBasis::_value_changed); @@ -1430,10 +1502,11 @@ EditorPropertyBasis::EditorPropertyBasis() { g->set_columns(3); add_child(g); - static const char *desc[9] = { "xx", "xy", "xz", "yx", "yy", "yz", "zx", "zy", "zz" }; + static const char *desc[9] = { "x", "y", "z", "x", "y", "z", "x", "y", "z" }; for (int i = 0; i < 9; i++) { spin[i] = memnew(EditorSpinSlider); spin[i]->set_label(desc[i]); + spin[i]->set_flat(true); g->add_child(spin[i]); spin[i]->set_h_size_flags(SIZE_EXPAND_FILL); add_focusable(spin[i]); @@ -1484,7 +1557,17 @@ void EditorPropertyTransform::update_property() { setting = false; } +void EditorPropertyTransform::_notification(int p_what) { + if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { + Color base = get_color("accent_color", "Editor"); + for (int i = 0; i < 12; i++) { + Color c = base; + c.set_hsv(float(i % 3) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v()); + spin[i]->set_custom_label_color(true, c); + } + } +} void EditorPropertyTransform::_bind_methods() { ClassDB::bind_method(D_METHOD("_value_changed"), &EditorPropertyTransform::_value_changed); @@ -1504,10 +1587,11 @@ EditorPropertyTransform::EditorPropertyTransform() { g->set_columns(3); add_child(g); - static const char *desc[12] = { "xx", "xy", "xz", "yx", "yy", "yz", "zx", "zy", "zz", "ox", "oy", "oz" }; + static const char *desc[12] = { "x", "y", "z", "x", "y", "z", "x", "y", "z", "x", "y", "z" }; for (int i = 0; i < 12; i++) { spin[i] = memnew(EditorSpinSlider); spin[i]->set_label(desc[i]); + spin[i]->set_flat(true); g->add_child(spin[i]); spin[i]->set_h_size_flags(SIZE_EXPAND_FILL); add_focusable(spin[i]); @@ -1854,7 +1938,19 @@ void EditorPropertyResource::_resource_preview(const String &p_path, const Ref<T RES p = get_edited_object()->get(get_edited_property()); if (p.is_valid() && p->get_instance_id() == p_obj) { if (p_preview.is_valid()) { - assign->set_icon(p_preview); + String type = p->get_class_name(); + preview->set_margin(MARGIN_LEFT, assign->get_icon()->get_width() + assign->get_stylebox("normal")->get_default_margin(MARGIN_LEFT) + get_constant("hseparation", "Button")); + if (type == "GradientTexture") { + preview->set_stretch_mode(TextureRect::STRETCH_SCALE); + assign->set_custom_minimum_size(Size2(1, 1)); + } else { + preview->set_stretch_mode(TextureRect::STRETCH_KEEP_ASPECT_CENTERED); + int thumbnail_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size"); + thumbnail_size *= EDSCALE; + assign->set_custom_minimum_size(Size2(1, thumbnail_size)); + } + preview->set_texture(p_preview); + assign->set_text(""); } } } @@ -2048,6 +2144,9 @@ void EditorPropertyResource::update_property() { sub_inspector = memnew(EditorInspector); sub_inspector->set_enable_v_scroll(false); + sub_inspector->set_use_sub_inspector_bg(true); + sub_inspector->set_enable_capitalize_paths(true); + sub_inspector->connect("property_keyed", this, "_sub_inspector_property_keyed"); sub_inspector->connect("resource_selected", this, "_sub_inspector_resource_selected"); sub_inspector->connect("object_id_selected", this, "_sub_inspector_object_id_selected"); @@ -2095,6 +2194,7 @@ void EditorPropertyResource::update_property() { #endif } + preview->set_texture(Ref<Texture>()); if (res == RES()) { assign->set_icon(Ref<Texture>()); assign->set_text(TTR("[empty]")); @@ -2333,6 +2433,14 @@ EditorPropertyResource::EditorPropertyResource() { assign->connect("draw", this, "_button_draw"); hbc->add_child(assign); + preview = memnew(TextureRect); + preview->set_expand(true); + preview->set_anchors_and_margins_preset(PRESET_WIDE); + preview->set_margin(MARGIN_TOP, 1); + preview->set_margin(MARGIN_BOTTOM, -1); + preview->set_margin(MARGIN_RIGHT, -1); + assign->add_child(preview); + menu = memnew(PopupMenu); add_child(menu); edit = memnew(Button); diff --git a/editor/editor_properties.h b/editor/editor_properties.h index ecccd7274d..0afb1bf955 100644 --- a/editor/editor_properties.h +++ b/editor/editor_properties.h @@ -278,16 +278,26 @@ public: class EditorPropertyEasing : public EditorProperty { GDCLASS(EditorPropertyEasing, EditorProperty) Control *easing_draw; - ToolButton *button_out, *button_in, *button_linear, *button_constant; - ToolButton *button_in_out, *button_out_in; - VBoxContainer *vb; + PopupMenu *preset; + bool full; + + enum { + EASING_ZERO, + EASING_LINEAR, + EASING_IN, + EASING_OUT, + EASING_IN_OUT, + EASING_OUT_IN, + EASING_MAX + + }; bool flip; void _drag_easing(const Ref<InputEvent> &p_ev); void _draw_easing(); void _notification(int p_what); - void _set_preset(float p_val); + void _set_preset(int); protected: static void _bind_methods(); @@ -305,6 +315,7 @@ class EditorPropertyVector2 : public EditorProperty { void _value_changed(double p_val); protected: + void _notification(int p_what); static void _bind_methods(); public: @@ -320,6 +331,7 @@ class EditorPropertyRect2 : public EditorProperty { void _value_changed(double p_val); protected: + void _notification(int p_what); static void _bind_methods(); public: @@ -335,6 +347,7 @@ class EditorPropertyVector3 : public EditorProperty { void _value_changed(double p_val); protected: + void _notification(int p_what); static void _bind_methods(); public: @@ -350,6 +363,7 @@ class EditorPropertyPlane : public EditorProperty { void _value_changed(double p_val); protected: + void _notification(int p_what); static void _bind_methods(); public: @@ -365,6 +379,7 @@ class EditorPropertyQuat : public EditorProperty { void _value_changed(double p_val); protected: + void _notification(int p_what); static void _bind_methods(); public: @@ -380,6 +395,7 @@ class EditorPropertyAABB : public EditorProperty { void _value_changed(double p_val); protected: + void _notification(int p_what); static void _bind_methods(); public: @@ -395,6 +411,7 @@ class EditorPropertyTransform2D : public EditorProperty { void _value_changed(double p_val); protected: + void _notification(int p_what); static void _bind_methods(); public: @@ -410,6 +427,7 @@ class EditorPropertyBasis : public EditorProperty { void _value_changed(double p_val); protected: + void _notification(int p_what); static void _bind_methods(); public: @@ -425,6 +443,7 @@ class EditorPropertyTransform : public EditorProperty { void _value_changed(double p_val); protected: + void _notification(int p_what); static void _bind_methods(); public: @@ -488,6 +507,7 @@ class EditorPropertyResource : public EditorProperty { }; Button *assign; + TextureRect *preview; Button *edit; PopupMenu *menu; EditorFileDialog *file; diff --git a/editor/editor_spin_slider.cpp b/editor/editor_spin_slider.cpp index c7a33de3f1..79023a1f28 100644 --- a/editor/editor_spin_slider.cpp +++ b/editor/editor_spin_slider.cpp @@ -90,10 +90,12 @@ void EditorSpinSlider::_gui_input(const Ref<InputEvent> &p_event) { } grabbing_spinner_dist_cache += diff_x; - if (!grabbing_spinner && ABS(grabbing_spinner_dist_cache) > 4) { + if (!grabbing_spinner && ABS(grabbing_spinner_dist_cache) > 4 * EDSCALE) { Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_CAPTURED); grabbing_spinner = true; - } else { + } + + if (grabbing_spinner) { if (mm->get_control() || updown_offset != -1) { set_value(Math::round(get_value())); if (ABS(grabbing_spinner_dist_cache) > 6) { @@ -159,20 +161,20 @@ void EditorSpinSlider::_notification(int p_what) { updown_offset = -1; Ref<StyleBox> sb = get_stylebox("normal", "LineEdit"); - draw_style_box(sb, Rect2(Vector2(), get_size())); + if (!flat) { + draw_style_box(sb, Rect2(Vector2(), get_size())); + } Ref<Font> font = get_font("font", "LineEdit"); + int sep_base = 4 * EDSCALE; + int sep = sep_base + sb->get_offset().x; //make it have the same margin on both sides, looks better + + int string_width = font->get_string_size(label).width; + int number_width = get_size().width - sb->get_minimum_size().width - string_width - sep; - int avail_width = get_size().width - sb->get_minimum_size().width; - avail_width -= font->get_string_size(label).width; Ref<Texture> updown = get_icon("updown", "SpinBox"); if (get_step() == 1) { - avail_width -= updown->get_width(); - } - - if (has_focus()) { - Ref<StyleBox> focus = get_stylebox("focus", "LineEdit"); - draw_style_box(focus, Rect2(Vector2(), get_size())); + number_width -= updown->get_width(); } String numstr = get_text_value(); @@ -180,10 +182,26 @@ void EditorSpinSlider::_notification(int p_what) { int vofs = (get_size().height - font->get_height()) / 2 + font->get_ascent(); Color fc = get_color("font_color", "LineEdit"); + Color lc; + if (use_custom_label_color) { + lc = custom_label_color; + } else { + lc = fc; + } - int label_ofs = sb->get_offset().x + avail_width; - draw_string(font, Vector2(label_ofs, vofs), label, fc * Color(1, 1, 1, 0.5)); - draw_string(font, Vector2(sb->get_offset().x, vofs), numstr, fc, avail_width); + if (flat && label != String()) { + Color label_bg_color = get_color("dark_color_3", "Editor"); + draw_rect(Rect2(Vector2(), Vector2(sb->get_offset().x * 2 + string_width, get_size().height)), label_bg_color); + } + + if (has_focus()) { + Ref<StyleBox> focus = get_stylebox("focus", "LineEdit"); + draw_style_box(focus, Rect2(Vector2(), get_size())); + } + + draw_string(font, Vector2(sb->get_offset().x, vofs), label, lc * Color(1, 1, 1, 0.5)); + + draw_string(font, Vector2(sb->get_offset().x + string_width + sep, vofs), numstr, fc, number_width); if (get_step() == 1) { Ref<Texture> updown = get_icon("updown", "SpinBox"); @@ -250,9 +268,11 @@ void EditorSpinSlider::_notification(int p_what) { update(); } if (p_what == NOTIFICATION_FOCUS_ENTER) { - if (!Input::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT) && !value_input_just_closed) { + /* Sorry, I dont like this, it makes navigating the different fields with arrows more difficult + * if (!Input::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT) && !value_input_just_closed) { _focus_entered(); - } + }*/ + value_input_just_closed = false; } } @@ -334,6 +354,21 @@ bool EditorSpinSlider::is_read_only() const { return read_only; } +void EditorSpinSlider::set_flat(bool p_enable) { + + flat = p_enable; + update(); +} + +bool EditorSpinSlider::is_flat() const { + return flat; +} + +void EditorSpinSlider::set_custom_label_color(bool p_use_custom_label_color, Color p_custom_label_color) { + use_custom_label_color = p_use_custom_label_color; + custom_label_color = p_custom_label_color; +} + void EditorSpinSlider::_focus_entered() { Rect2 gr = get_global_rect(); value_input->set_text(get_text_value()); @@ -353,6 +388,9 @@ void EditorSpinSlider::_bind_methods() { ClassDB::bind_method(D_METHOD("set_read_only", "read_only"), &EditorSpinSlider::set_read_only); ClassDB::bind_method(D_METHOD("is_read_only"), &EditorSpinSlider::is_read_only); + ClassDB::bind_method(D_METHOD("set_flat", "flat"), &EditorSpinSlider::set_flat); + ClassDB::bind_method(D_METHOD("is_flat"), &EditorSpinSlider::is_flat); + ClassDB::bind_method(D_METHOD("_gui_input"), &EditorSpinSlider::_gui_input); ClassDB::bind_method(D_METHOD("_grabber_mouse_entered"), &EditorSpinSlider::_grabber_mouse_entered); ClassDB::bind_method(D_METHOD("_grabber_mouse_exited"), &EditorSpinSlider::_grabber_mouse_exited); @@ -363,10 +401,12 @@ void EditorSpinSlider::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::STRING, "label"), "set_label", "get_label"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "read_only"), "set_read_only", "is_read_only"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "flat"), "set_flat", "is_flat"); } EditorSpinSlider::EditorSpinSlider() { + flat = false; grabbing_spinner_attempt = false; grabbing_spinner = false; grabbing_spinner_dist_cache = 0; @@ -395,4 +435,5 @@ EditorSpinSlider::EditorSpinSlider() { value_input_just_closed = false; hide_slider = false; read_only = false; + use_custom_label_color = false; } diff --git a/editor/editor_spin_slider.h b/editor/editor_spin_slider.h index 5316c0264a..fb32534ef4 100644 --- a/editor/editor_spin_slider.h +++ b/editor/editor_spin_slider.h @@ -68,6 +68,10 @@ class EditorSpinSlider : public Range { void _value_input_entered(const String &); void _value_focus_exited(); bool hide_slider; + bool flat; + + bool use_custom_label_color; + Color custom_label_color; protected: void _notification(int p_what); @@ -88,6 +92,11 @@ public: void set_read_only(bool p_enable); bool is_read_only() const; + void set_flat(bool p_enable); + bool is_flat() const; + + void set_custom_label_color(bool p_use_custom_label_color, Color p_custom_label_color); + virtual Size2 get_minimum_size() const; EditorSpinSlider(); }; diff --git a/editor/editor_themes.cpp b/editor/editor_themes.cpp index 0534a398f4..084caff083 100644 --- a/editor/editor_themes.cpp +++ b/editor/editor_themes.cpp @@ -656,6 +656,14 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { theme->set_icon("visibility_xray", "PopupMenu", theme->get_icon("GuiVisibilityXray", "EditorIcons")); theme->set_constant("vseparation", "PopupMenu", (extra_spacing + default_margin_size) * EDSCALE); + Ref<StyleBoxFlat> sub_inspector_bg = make_flat_stylebox(dark_color_1, 2, 0, 0, 0); + sub_inspector_bg->set_border_width(MARGIN_LEFT, 2); + sub_inspector_bg->set_border_color(MARGIN_LEFT, accent_color * Color(1, 1, 1, 0.3)); + sub_inspector_bg->set_draw_center(true); + + theme->set_stylebox("sub_inspector_bg", "Editor", sub_inspector_bg); + theme->set_constant("inspector_margin", "Editor", 8 * EDSCALE); + // Tree & ItemList background Ref<StyleBoxFlat> style_tree_bg = style_default->duplicate(); style_tree_bg->set_bg_color(dark_color_1); @@ -666,6 +674,7 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { // Tree theme->set_icon("checked", "Tree", theme->get_icon("GuiChecked", "EditorIcons")); theme->set_icon("unchecked", "Tree", theme->get_icon("GuiUnchecked", "EditorIcons")); + theme->set_icon("arrow_up", "Tree", theme->get_icon("GuiTreeArrowUp", "EditorIcons")); theme->set_icon("arrow", "Tree", theme->get_icon("GuiTreeArrowDown", "EditorIcons")); theme->set_icon("arrow_collapsed", "Tree", theme->get_icon("GuiTreeArrowRight", "EditorIcons")); theme->set_icon("updown", "Tree", theme->get_icon("GuiTreeUpdown", "EditorIcons")); diff --git a/editor/export_template_manager.cpp b/editor/export_template_manager.cpp index 541c848ca3..931785333f 100644 --- a/editor/export_template_manager.cpp +++ b/editor/export_template_manager.cpp @@ -123,7 +123,6 @@ void ExportTemplateManager::_update_template_list() { void ExportTemplateManager::_download_template(const String &p_version) { - print_line("download " + p_version); while (template_list->get_child_count()) { memdelete(template_list->get_child(0)); } @@ -228,7 +227,10 @@ void ExportTemplateManager::_install_from_file(const String &p_file, bool p_use_ version = data_str; } - fc++; + if (file.get_file().size() != 0) { + fc++; + } + ret = unzGoToNextFile(pkg); } @@ -268,6 +270,11 @@ void ExportTemplateManager::_install_from_file(const String &p_file, bool p_use_ String file = String(fname).get_file(); + if (file.size() == 0) { + ret = unzGoToNextFile(pkg); + continue; + } + Vector<uint8_t> data; data.resize(info.uncompressed_size); @@ -344,7 +351,6 @@ void ExportTemplateManager::_http_download_mirror_completed(int p_status, int p_ bool mirrors_found = false; Dictionary d = r; - print_line(r); if (d.has("mirrors")) { Array mirrors = d["mirrors"]; for (int i = 0; i < mirrors.size(); i++) { @@ -499,7 +505,6 @@ void ExportTemplateManager::_notification(int p_what) { if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { if (!is_visible_in_tree()) { - print_line("closed"); set_process(false); } } diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index eebf1b6ab8..f65fb5365b 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -1862,7 +1862,7 @@ void FileSystemDock::_bind_methods() { ClassDB::bind_method(D_METHOD("_file_option"), &FileSystemDock::_file_option); ClassDB::bind_method(D_METHOD("_folder_option"), &FileSystemDock::_folder_option); ClassDB::bind_method(D_METHOD("_make_dir_confirm"), &FileSystemDock::_make_dir_confirm); - ClassDB::bind_method(D_METHOD("_move_operation_confirm"), &FileSystemDock::_move_operation_confirm); + ClassDB::bind_method(D_METHOD("_move_operation_confirm", "to_path", "overwrite"), &FileSystemDock::_move_operation_confirm, DEFVAL(false)); ClassDB::bind_method(D_METHOD("_move_with_overwrite"), &FileSystemDock::_move_with_overwrite); ClassDB::bind_method(D_METHOD("_rename_operation_confirm"), &FileSystemDock::_rename_operation_confirm); ClassDB::bind_method(D_METHOD("_duplicate_operation_confirm"), &FileSystemDock::_duplicate_operation_confirm); diff --git a/editor/icons/icon_GUI_tree_arrow_up.svg b/editor/icons/icon_GUI_tree_arrow_up.svg new file mode 100644 index 0000000000..4e6e8e9e29 --- /dev/null +++ b/editor/icons/icon_GUI_tree_arrow_up.svg @@ -0,0 +1,60 @@ +<?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="12" + height="12" + version="1.1" + viewBox="0 0 12 12" + id="svg6" + sodipodi:docname="icon_GUI_tree_arrow_up.svg" + inkscape:version="0.92.3 (2405546, 2018-03-11)"> + <metadata + id="metadata12"> + <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="defs10" /> + <sodipodi:namedview + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1" + objecttolerance="10" + gridtolerance="10" + guidetolerance="10" + inkscape:pageopacity="0" + inkscape:pageshadow="2" + inkscape:window-width="1673" + inkscape:window-height="594" + id="namedview8" + showgrid="false" + inkscape:zoom="19.666667" + inkscape:cx="-4.3220338" + inkscape:cy="6.0000001" + inkscape:window-x="67" + inkscape:window-y="27" + inkscape:window-maximized="0" + inkscape:current-layer="svg6" /> + <g + transform="rotate(180,6,526.08476)" + id="g4"> + <path + d="m 3,1045.4 3,3 3,-3" + id="path2" + inkscape:connector-curvature="0" + style="fill:none;stroke:#ffffff;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:0.39216003" /> + </g> +</svg> diff --git a/editor/plugins/audio_stream_editor_plugin.cpp b/editor/plugins/audio_stream_editor_plugin.cpp new file mode 100644 index 0000000000..ddb03d0250 --- /dev/null +++ b/editor/plugins/audio_stream_editor_plugin.cpp @@ -0,0 +1,284 @@ +/*************************************************************************/ +/* audio_stream_editor_plugin.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2018 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 "audio_stream_editor_plugin.h" + +#include "editor/editor_settings.h" +#include "io/resource_loader.h" +#include "project_settings.h" + +void AudioStreamEditor::_notification(int p_what) { + + if (p_what == NOTIFICATION_READY) { + AudioStreamPreviewGenerator::get_singleton()->connect("preview_updated", this, "_preview_changed"); + } + + if (p_what == NOTIFICATION_THEME_CHANGED || p_what == NOTIFICATION_ENTER_TREE) { + _play_button->set_icon(get_icon("MainPlay", "EditorIcons")); + _stop_button->set_icon(get_icon("Stop", "EditorIcons")); + _preview->set_frame_color(get_color("dark_color_2", "Editor")); + set_frame_color(get_color("dark_color_1", "Editor")); + + _indicator->update(); + _preview->update(); + } + + if (p_what == NOTIFICATION_PROCESS) { + _current = _player->get_playback_position(); + _indicator->update(); + _preview->update(); + } + + if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { + if (!is_visible_in_tree()) { + _stop(); + } + } +} + +void AudioStreamEditor::_draw_preview() { + Rect2 rect = _preview->get_rect(); + Size2 size = get_size(); + + Ref<AudioStreamPreview> preview = AudioStreamPreviewGenerator::get_singleton()->generate_preview(stream); + float preview_len = preview->get_length(); + + Vector<Vector2> lines; + lines.resize(size.width * 2); + + for (int i = 0; i < size.width; i++) { + + float ofs = i * preview_len / size.width; + float ofs_n = (i + 1) * preview_len / size.width; + float max = preview->get_max(ofs, ofs_n) * 0.5 + 0.5; + float min = preview->get_min(ofs, ofs_n) * 0.5 + 0.5; + + int idx = i; + lines[idx * 2 + 0] = Vector2(i + 1, rect.position.y + min * rect.size.y); + lines[idx * 2 + 1] = Vector2(i + 1, rect.position.y + max * rect.size.y); + } + + Vector<Color> color; + color.push_back(get_color("contrast_color_2", "Editor")); + + VS::get_singleton()->canvas_item_add_multiline(_preview->get_canvas_item(), lines, color); +} + +void AudioStreamEditor::_preview_changed(ObjectID p_which) { + + if (stream.is_valid() && stream->get_instance_id() == p_which) { + _preview->update(); + } +} + +void AudioStreamEditor::_changed_callback(Object *p_changed, const char *p_prop) { + + if (!is_visible()) + return; + update(); +} + +void AudioStreamEditor::_play() { + + if (_player->is_playing()) { + _player->stop(); + _play_button->set_icon(get_icon("MainPlay", "EditorIcons")); + set_process(false); + } else { + _player->play(_current); + _play_button->set_icon(get_icon("Pause", "EditorIcons")); + set_process(true); + } +} + +void AudioStreamEditor::_stop() { + + _player->stop(); + _on_finished(); +} + +void AudioStreamEditor::_on_finished() { + + _play_button->set_icon(get_icon("MainPlay", "EditorIcons")); + _current = 0; + _indicator->update(); + set_process(false); +} + +void AudioStreamEditor::_draw_indicator() { + + if (!stream.is_valid()) { + return; + } + + Rect2 rect = _preview->get_rect(); + float len = stream->get_length(); + float ofs_x = _current / len * rect.size.width; + _indicator->draw_line(Point2(ofs_x, 0), Point2(ofs_x, rect.size.height), get_color("accent_color", "Editor"), 1); + + _current_label->set_text(String::num(_current, 2).pad_decimals(2) + " /"); +} + +void AudioStreamEditor::_on_input_indicator(Ref<InputEvent> p_event) { + Ref<InputEventMouseButton> mb = p_event; + + if (mb.is_valid()) { + if (mb->is_pressed()) { + _seek_to(mb->get_position().x); + } + _dragging = mb->is_pressed(); + } + + Ref<InputEventMouseMotion> mm = p_event; + + if (mm.is_valid()) { + if (_dragging) { + _seek_to(mm->get_position().x); + } + } +} + +void AudioStreamEditor::_seek_to(real_t p_x) { + _current = p_x / _preview->get_rect().size.x * stream->get_length(); + _current = CLAMP(_current, 0, stream->get_length()); + _player->seek(_current); + _indicator->update(); +} + +void AudioStreamEditor::edit(Ref<AudioStream> p_stream) { + + if (!stream.is_null()) + stream->remove_change_receptor(this); + + stream = p_stream; + _player->set_stream(stream); + _current = 0; + String text = String::num(stream->get_length(), 2).pad_decimals(2) + "s"; + _duration_label->set_text(text); + + if (!stream.is_null()) { + stream->add_change_receptor(this); + update(); + } else { + hide(); + } +} + +void AudioStreamEditor::_bind_methods() { + + ClassDB::bind_method(D_METHOD("_preview_changed"), &AudioStreamEditor::_preview_changed); + ClassDB::bind_method(D_METHOD("_play"), &AudioStreamEditor::_play); + ClassDB::bind_method(D_METHOD("_stop"), &AudioStreamEditor::_stop); + ClassDB::bind_method(D_METHOD("_on_finished"), &AudioStreamEditor::_on_finished); + ClassDB::bind_method(D_METHOD("_draw_preview"), &AudioStreamEditor::_draw_preview); + ClassDB::bind_method(D_METHOD("_draw_indicator"), &AudioStreamEditor::_draw_indicator); + ClassDB::bind_method(D_METHOD("_on_input_indicator"), &AudioStreamEditor::_on_input_indicator); +} + +AudioStreamEditor::AudioStreamEditor() { + + set_custom_minimum_size(Size2(1, 100)); + _current = 0; + _dragging = false; + + _player = memnew(AudioStreamPlayer); + _player->connect("finished", this, "_on_finished"); + add_child(_player); + + VBoxContainer *vbox = memnew(VBoxContainer); + vbox->set_anchors_and_margins_preset(PRESET_WIDE, PRESET_MODE_MINSIZE, 0); + add_child(vbox); + + _preview = memnew(ColorRect); + _preview->set_v_size_flags(SIZE_EXPAND_FILL); + _preview->connect("draw", this, "_draw_preview"); + vbox->add_child(_preview); + + _indicator = memnew(Control); + _indicator->set_anchors_and_margins_preset(PRESET_WIDE); + _indicator->connect("draw", this, "_draw_indicator"); + _indicator->connect("gui_input", this, "_on_input_indicator"); + _preview->add_child(_indicator); + + HBoxContainer *hbox = memnew(HBoxContainer); + hbox->add_constant_override("separation", 0); + vbox->add_child(hbox); + + _play_button = memnew(ToolButton); + hbox->add_child(_play_button); + _play_button->set_focus_mode(Control::FOCUS_NONE); + _play_button->connect("pressed", this, "_play"); + + _stop_button = memnew(ToolButton); + hbox->add_child(_stop_button); + _stop_button->set_focus_mode(Control::FOCUS_NONE); + _stop_button->connect("pressed", this, "_stop"); + + _current_label = memnew(Label); + _current_label->set_align(Label::ALIGN_RIGHT); + _current_label->set_h_size_flags(SIZE_EXPAND_FILL); + _current_label->add_font_override("font", EditorNode::get_singleton()->get_gui_base()->get_font("status_source", "EditorFonts")); + _current_label->set_modulate(Color(1, 1, 1, 0.5)); + hbox->add_child(_current_label); + + _duration_label = memnew(Label); + _duration_label->add_font_override("font", EditorNode::get_singleton()->get_gui_base()->get_font("status_source", "EditorFonts")); + hbox->add_child(_duration_label); +} + +void AudioStreamEditorPlugin::edit(Object *p_object) { + + AudioStream *s = Object::cast_to<AudioStream>(p_object); + if (!s) + return; + + audio_editor->edit(Ref<AudioStream>(s)); +} + +bool AudioStreamEditorPlugin::handles(Object *p_object) const { + + return p_object->is_class("AudioStream"); +} + +void AudioStreamEditorPlugin::make_visible(bool p_visible) { + + audio_editor->set_visible(p_visible); +} + +AudioStreamEditorPlugin::AudioStreamEditorPlugin(EditorNode *p_node) { + + editor = p_node; + audio_editor = memnew(AudioStreamEditor); + add_control_to_container(CONTAINER_PROPERTY_EDITOR_BOTTOM, audio_editor); + audio_editor->hide(); +} + +AudioStreamEditorPlugin::~AudioStreamEditorPlugin() { +} diff --git a/editor/plugins/audio_stream_editor_plugin.h b/editor/plugins/audio_stream_editor_plugin.h new file mode 100644 index 0000000000..1887874b74 --- /dev/null +++ b/editor/plugins/audio_stream_editor_plugin.h @@ -0,0 +1,93 @@ +/*************************************************************************/ +/* audio_stream_editor_plugin.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2018 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 AUDIO_STREAM_EDITOR_PLUGIN_H +#define AUDIO_STREAM_EDITOR_PLUGIN_H + +#include "editor/editor_node.h" +#include "editor/editor_plugin.h" +#include "scene/audio/audio_player.h" +#include "scene/gui/color_rect.h" +#include "scene/resources/texture.h" + +class AudioStreamEditor : public ColorRect { + + GDCLASS(AudioStreamEditor, ColorRect); + + Ref<AudioStream> stream; + AudioStreamPlayer *_player; + ColorRect *_preview; + Control *_indicator; + Label *_current_label; + Label *_duration_label; + + ToolButton *_play_button; + ToolButton *_stop_button; + + float _current; + bool _dragging; + +protected: + void _notification(int p_what); + void _preview_changed(ObjectID p_which); + void _play(); + void _stop(); + void _on_finished(); + void _draw_preview(); + void _draw_indicator(); + void _on_input_indicator(Ref<InputEvent> p_event); + void _seek_to(real_t p_x); + void _changed_callback(Object *p_changed, const char *p_prop); + static void _bind_methods(); + +public: + void edit(Ref<AudioStream> p_stream); + AudioStreamEditor(); +}; + +class AudioStreamEditorPlugin : public EditorPlugin { + + GDCLASS(AudioStreamEditorPlugin, EditorPlugin); + + AudioStreamEditor *audio_editor; + EditorNode *editor; + +public: + virtual String get_name() const { return "Audio"; } + bool has_main_screen() const { return false; } + virtual void edit(Object *p_object); + virtual bool handles(Object *p_object) const; + virtual void make_visible(bool p_visible); + + AudioStreamEditorPlugin(EditorNode *p_node); + ~AudioStreamEditorPlugin(); +}; + +#endif // AUDIO_STREAM_EDITOR_PLUGIN_H diff --git a/editor/plugins/path_2d_editor_plugin.cpp b/editor/plugins/path_2d_editor_plugin.cpp index 5ec42b07aa..33e182faef 100644 --- a/editor/plugins/path_2d_editor_plugin.cpp +++ b/editor/plugins/path_2d_editor_plugin.cpp @@ -109,6 +109,7 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { action_point = i; moving_from = curve->get_point_out(i); moving_screen_from = gpoint; + orig_in_length = curve->get_point_in(action_point).length(); return true; } else if (dist_to_p_in < grab_threshold && i > 0) { @@ -116,6 +117,7 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { action_point = i; moving_from = curve->get_point_in(i); moving_screen_from = gpoint; + orig_out_length = curve->get_point_out(action_point).length(); return true; } } @@ -205,6 +207,11 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { undo_redo->create_action(TTR("Move In-Control in Curve")); undo_redo->add_do_method(curve.ptr(), "set_point_in", action_point, new_pos); undo_redo->add_undo_method(curve.ptr(), "set_point_in", action_point, moving_from); + + if (mirror_handle_angle) { + undo_redo->add_do_method(curve.ptr(), "set_point_out", action_point, mirror_handle_length ? -new_pos : (-new_pos.normalized() * orig_out_length)); + undo_redo->add_undo_method(curve.ptr(), "set_point_out", action_point, mirror_handle_length ? -moving_from : (-moving_from.normalized() * orig_out_length)); + } undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); undo_redo->commit_action(); @@ -216,6 +223,11 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { undo_redo->create_action(TTR("Move Out-Control in Curve")); undo_redo->add_do_method(curve.ptr(), "set_point_out", action_point, new_pos); undo_redo->add_undo_method(curve.ptr(), "set_point_out", action_point, moving_from); + + if (mirror_handle_angle) { + undo_redo->add_do_method(curve.ptr(), "set_point_in", action_point, mirror_handle_length ? -new_pos : (-new_pos.normalized() * orig_in_length)); + undo_redo->add_undo_method(curve.ptr(), "set_point_in", action_point, mirror_handle_length ? -moving_from : (-moving_from.normalized() * orig_in_length)); + } undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); undo_redo->commit_action(); @@ -255,10 +267,16 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { case ACTION_MOVING_IN: { curve->set_point_in(action_point, new_pos); + + if (mirror_handle_angle) + curve->set_point_out(action_point, mirror_handle_length ? -new_pos : (-new_pos.normalized() * orig_out_length)); } break; case ACTION_MOVING_OUT: { curve->set_point_out(action_point, new_pos); + + if (mirror_handle_angle) + curve->set_point_in(action_point, mirror_handle_length ? -new_pos : (-new_pos.normalized() * orig_in_length)); } break; } @@ -342,6 +360,7 @@ void Path2DEditor::_bind_methods() { //ClassDB::bind_method(D_METHOD("_menu_option"),&Path2DEditor::_menu_option); ClassDB::bind_method(D_METHOD("_node_visibility_changed"), &Path2DEditor::_node_visibility_changed); ClassDB::bind_method(D_METHOD("_mode_selected"), &Path2DEditor::_mode_selected); + ClassDB::bind_method(D_METHOD("_handle_option_pressed"), &Path2DEditor::_handle_option_pressed); } void Path2DEditor::_mode_selected(int p_mode) { @@ -396,11 +415,33 @@ void Path2DEditor::_mode_selected(int p_mode) { mode = Mode(p_mode); } +void Path2DEditor::_handle_option_pressed(int p_option) { + + PopupMenu *pm; + pm = handle_menu->get_popup(); + + switch (p_option) { + case HANDLE_OPTION_ANGLE: { + bool is_checked = pm->is_item_checked(HANDLE_OPTION_ANGLE); + mirror_handle_angle = !is_checked; + pm->set_item_checked(HANDLE_OPTION_ANGLE, mirror_handle_angle); + pm->set_item_disabled(HANDLE_OPTION_LENGTH, !mirror_handle_angle); + } break; + case HANDLE_OPTION_LENGTH: { + bool is_checked = pm->is_item_checked(HANDLE_OPTION_LENGTH); + mirror_handle_length = !is_checked; + pm->set_item_checked(HANDLE_OPTION_LENGTH, mirror_handle_length); + } break; + } +} + Path2DEditor::Path2DEditor(EditorNode *p_editor) { canvas_item_editor = NULL; editor = p_editor; undo_redo = editor->get_undo_redo(); + mirror_handle_angle = true; + mirror_handle_length = true; mode = MODE_EDIT; action = ACTION_NONE; @@ -444,6 +485,20 @@ Path2DEditor::Path2DEditor(EditorNode *p_editor) { curve_close->set_tooltip(TTR("Close Curve")); curve_close->connect("pressed", this, "_mode_selected", varray(ACTION_CLOSE)); base_hb->add_child(curve_close); + + PopupMenu *menu; + + handle_menu = memnew(MenuButton); + handle_menu->set_text(TTR("Options")); + base_hb->add_child(handle_menu); + + menu = handle_menu->get_popup(); + menu->add_check_item(TTR("Mirror Handle Angles")); + menu->set_item_checked(HANDLE_OPTION_ANGLE, mirror_handle_angle); + menu->add_check_item(TTR("Mirror Handle Lengths")); + menu->set_item_checked(HANDLE_OPTION_LENGTH, mirror_handle_length); + menu->connect("id_pressed", this, "_handle_option_pressed"); + base_hb->hide(); curve_edit->set_pressed(true); diff --git a/editor/plugins/path_2d_editor_plugin.h b/editor/plugins/path_2d_editor_plugin.h index c92a696967..1e3955f84f 100644 --- a/editor/plugins/path_2d_editor_plugin.h +++ b/editor/plugins/path_2d_editor_plugin.h @@ -69,6 +69,15 @@ class Path2DEditor : public HBoxContainer { ToolButton *curve_edit_curve; ToolButton *curve_del; ToolButton *curve_close; + MenuButton *handle_menu; + + bool mirror_handle_angle; + bool mirror_handle_length; + + enum HandleOption { + HANDLE_OPTION_ANGLE, + HANDLE_OPTION_LENGTH + }; enum Action { @@ -82,8 +91,11 @@ class Path2DEditor : public HBoxContainer { int action_point; Point2 moving_from; Point2 moving_screen_from; + float orig_in_length; + float orig_out_length; void _mode_selected(int p_mode); + void _handle_option_pressed(int p_option); void _node_visibility_changed(); friend class Path2DEditorPlugin; diff --git a/editor/plugins/path_editor_plugin.cpp b/editor/plugins/path_editor_plugin.cpp index 6dde639c54..72a8b55a52 100644 --- a/editor/plugins/path_editor_plugin.cpp +++ b/editor/plugins/path_editor_plugin.cpp @@ -128,11 +128,22 @@ void PathSpatialGizmo::set_handle(int p_idx, Camera *p_camera, const Point2 &p_p if (p.intersects_ray(ray_from, ray_dir, &inters)) { + if (!PathEditorPlugin::singleton->is_handle_clicked()) { + orig_in_length = c->get_point_in(idx).length(); + orig_out_length = c->get_point_out(idx).length(); + PathEditorPlugin::singleton->set_handle_clicked(true); + } + Vector3 local = gi.xform(inters) - base; if (t == 0) { c->set_point_in(idx, local); + + if (PathEditorPlugin::singleton->mirror_angle_enabled()) + c->set_point_out(idx, PathEditorPlugin::singleton->mirror_length_enabled() ? -local : (-local.normalized() * orig_out_length)); } else { c->set_point_out(idx, local); + if (PathEditorPlugin::singleton->mirror_angle_enabled()) + c->set_point_in(idx, PathEditorPlugin::singleton->mirror_length_enabled() ? -local : (-local.normalized() * orig_in_length)); } } } @@ -165,8 +176,6 @@ void PathSpatialGizmo::commit_handle(int p_idx, const Variant &p_restore, bool p int idx = p_idx / 2; int t = p_idx % 2; - Vector3 ofs; - if (t == 0) { if (p_cancel) { c->set_point_in(p_idx, p_restore); @@ -176,6 +185,11 @@ void PathSpatialGizmo::commit_handle(int p_idx, const Variant &p_restore, bool p ur->create_action(TTR("Set Curve In Position")); ur->add_do_method(c.ptr(), "set_point_in", idx, c->get_point_in(idx)); ur->add_undo_method(c.ptr(), "set_point_in", idx, p_restore); + + if (PathEditorPlugin::singleton->mirror_angle_enabled()) { + ur->add_do_method(c.ptr(), "set_point_out", idx, PathEditorPlugin::singleton->mirror_length_enabled() ? -c->get_point_in(idx) : (-c->get_point_in(idx).normalized() * orig_out_length)); + ur->add_undo_method(c.ptr(), "set_point_out", idx, PathEditorPlugin::singleton->mirror_length_enabled() ? -static_cast<Vector3>(p_restore) : (-static_cast<Vector3>(p_restore).normalized() * orig_out_length)); + } ur->commit_action(); } else { @@ -188,6 +202,11 @@ void PathSpatialGizmo::commit_handle(int p_idx, const Variant &p_restore, bool p ur->create_action(TTR("Set Curve Out Position")); ur->add_do_method(c.ptr(), "set_point_out", idx, c->get_point_out(idx)); ur->add_undo_method(c.ptr(), "set_point_out", idx, p_restore); + + if (PathEditorPlugin::singleton->mirror_angle_enabled()) { + ur->add_do_method(c.ptr(), "set_point_in", idx, PathEditorPlugin::singleton->mirror_length_enabled() ? -c->get_point_out(idx) : (-c->get_point_out(idx).normalized() * orig_in_length)); + ur->add_undo_method(c.ptr(), "set_point_in", idx, PathEditorPlugin::singleton->mirror_length_enabled() ? -static_cast<Vector3>(p_restore) : (-static_cast<Vector3>(p_restore).normalized() * orig_in_length)); + } ur->commit_action(); } } @@ -291,6 +310,9 @@ bool PathEditorPlugin::forward_spatial_gui_input(Camera *p_camera, const Ref<Inp Point2 mbpos(mb->get_position().x, mb->get_position().y); + if (!mb->is_pressed()) + set_handle_clicked(false); + if (mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT && (curve_create->is_pressed() || (curve_edit->is_pressed() && mb->get_control()))) { //click into curve, break it down PoolVector<Vector3> v3a = c->tessellate(); @@ -459,6 +481,7 @@ void PathEditorPlugin::make_visible(bool p_visible) { curve_edit->show(); curve_del->show(); curve_close->show(); + handle_menu->show(); sep->show(); } else { @@ -466,6 +489,7 @@ void PathEditorPlugin::make_visible(bool p_visible) { curve_edit->hide(); curve_del->hide(); curve_close->hide(); + handle_menu->hide(); sep->hide(); { @@ -495,6 +519,26 @@ void PathEditorPlugin::_close_curve() { c->add_point(c->get_point_position(0), c->get_point_in(0), c->get_point_out(0)); } +void PathEditorPlugin::_handle_option_pressed(int p_option) { + + PopupMenu *pm; + pm = handle_menu->get_popup(); + + switch (p_option) { + case HANDLE_OPTION_ANGLE: { + bool is_checked = pm->is_item_checked(HANDLE_OPTION_ANGLE); + mirror_handle_angle = !is_checked; + pm->set_item_checked(HANDLE_OPTION_ANGLE, mirror_handle_angle); + pm->set_item_disabled(HANDLE_OPTION_LENGTH, !mirror_handle_angle); + } break; + case HANDLE_OPTION_LENGTH: { + bool is_checked = pm->is_item_checked(HANDLE_OPTION_LENGTH); + mirror_handle_length = !is_checked; + pm->set_item_checked(HANDLE_OPTION_LENGTH, mirror_handle_length); + } break; + } +} + void PathEditorPlugin::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE) { @@ -510,6 +554,7 @@ void PathEditorPlugin::_bind_methods() { ClassDB::bind_method(D_METHOD("_mode_changed"), &PathEditorPlugin::_mode_changed); ClassDB::bind_method(D_METHOD("_close_curve"), &PathEditorPlugin::_close_curve); + ClassDB::bind_method(D_METHOD("_handle_option_pressed"), &PathEditorPlugin::_handle_option_pressed); } PathEditorPlugin *PathEditorPlugin::singleton = NULL; @@ -519,6 +564,8 @@ PathEditorPlugin::PathEditorPlugin(EditorNode *p_node) { path = NULL; editor = p_node; singleton = this; + mirror_handle_angle = true; + mirror_handle_length = true; path_material = Ref<SpatialMaterial>(memnew(SpatialMaterial)); path_material->set_albedo(Color(0.5, 0.5, 1.0, 0.8)); @@ -567,6 +614,20 @@ PathEditorPlugin::PathEditorPlugin(EditorNode *p_node) { curve_close->set_tooltip(TTR("Close Curve")); SpatialEditor::get_singleton()->add_control_to_menu_panel(curve_close); + PopupMenu *menu; + + handle_menu = memnew(MenuButton); + handle_menu->set_text(TTR("Options")); + handle_menu->hide(); + SpatialEditor::get_singleton()->add_control_to_menu_panel(handle_menu); + + menu = handle_menu->get_popup(); + menu->add_check_item(TTR("Mirror Handle Angles")); + menu->set_item_checked(HANDLE_OPTION_ANGLE, mirror_handle_angle); + menu->add_check_item(TTR("Mirror Handle Lengths")); + menu->set_item_checked(HANDLE_OPTION_LENGTH, mirror_handle_length); + menu->connect("id_pressed", this, "_handle_option_pressed"); + curve_edit->set_pressed(true); /* collision_polygon_editor = memnew( PathEditor(p_node) ); diff --git a/editor/plugins/path_editor_plugin.h b/editor/plugins/path_editor_plugin.h index 6d5f07f729..52dfb78b61 100644 --- a/editor/plugins/path_editor_plugin.h +++ b/editor/plugins/path_editor_plugin.h @@ -1,4 +1,4 @@ -/*************************************************************************/ +/*************************************************************************/ /* path_editor_plugin.h */ /*************************************************************************/ /* This file is part of: */ @@ -40,6 +40,8 @@ class PathSpatialGizmo : public EditorSpatialGizmo { Path *path; mutable Vector3 original; + mutable float orig_in_length; + mutable float orig_out_length; public: virtual String get_handle_name(int p_idx) const; @@ -60,6 +62,7 @@ class PathEditorPlugin : public EditorPlugin { ToolButton *curve_edit; ToolButton *curve_del; ToolButton *curve_close; + MenuButton *handle_menu; EditorNode *editor; @@ -67,6 +70,15 @@ class PathEditorPlugin : public EditorPlugin { void _mode_changed(int p_idx); void _close_curve(); + void _handle_option_pressed(int p_option); + bool handle_clicked; + bool mirror_handle_angle; + bool mirror_handle_length; + + enum HandleOption { + HANDLE_OPTION_ANGLE, + HANDLE_OPTION_LENGTH + }; protected: void _notification(int p_what); @@ -88,6 +100,11 @@ public: virtual bool handles(Object *p_object) const; virtual void make_visible(bool p_visible); + bool mirror_angle_enabled() { return mirror_handle_angle; } + bool mirror_length_enabled() { return mirror_handle_length; } + bool is_handle_clicked() { return handle_clicked; } + void set_handle_clicked(bool clicked) { handle_clicked = clicked; } + PathEditorPlugin(EditorNode *p_node); ~PathEditorPlugin(); }; diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index 9a351c26fa..682ca744ff 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -768,17 +768,17 @@ VisualShaderEditor::VisualShaderEditor() { add_options.push_back(AddOption("VectorOp", "Operators", "VisualShaderNodeVectorOp")); add_options.push_back(AddOption("ColorOp", "Operators", "VisualShaderNodeColorOp")); add_options.push_back(AddOption("TransformMult", "Operators", "VisualShaderNodeTransformMult")); - add_options.push_back(AddOption("TransformVecMult", "Operators", "VisualShaderNodeTransformVecMult")); + add_options.push_back(AddOption("TransformVectorMult", "Operators", "VisualShaderNodeTransformVecMult")); add_options.push_back(AddOption("ScalarFunc", "Functions", "VisualShaderNodeScalarFunc")); add_options.push_back(AddOption("VectorFunc", "Functions", "VisualShaderNodeVectorFunc")); add_options.push_back(AddOption("DotProduct", "Functions", "VisualShaderNodeDotProduct")); add_options.push_back(AddOption("VectorLen", "Functions", "VisualShaderNodeVectorLen")); add_options.push_back(AddOption("ScalarInterp", "Interpolation", "VisualShaderNodeScalarInterp")); add_options.push_back(AddOption("VectorInterp", "Interpolation", "VisualShaderNodeVectorInterp")); - add_options.push_back(AddOption("VectorConstruct", "Construct", "VisualShaderNodeVectorConstruct")); - add_options.push_back(AddOption("TransformConstruct", "Construct", "VisualShaderNodeTransformConstruct")); - add_options.push_back(AddOption("VectorDestruct", "Destruct", "VisualShaderNodeVectorDestruct")); - add_options.push_back(AddOption("TransformDestruct", "Destruct", "VisualShaderNodeTransformDestruct")); + add_options.push_back(AddOption("VectorCompose", "Compose", "VisualShaderNodeVectorCompose")); + add_options.push_back(AddOption("TransformCompose", "Compose", "VisualShaderNodeTransformCompose")); + add_options.push_back(AddOption("VectorDecompose", "Decompose", "VisualShaderNodeVectorDecompose")); + add_options.push_back(AddOption("TransformDecompose", "Decompose", "VisualShaderNodeTransformDecompose")); add_options.push_back(AddOption("Scalar", "Uniforms", "VisualShaderNodeScalarUniform")); add_options.push_back(AddOption("Vector", "Uniforms", "VisualShaderNodeVec3Uniform")); add_options.push_back(AddOption("Color", "Uniforms", "VisualShaderNodeColorUniform")); diff --git a/editor/project_export.cpp b/editor/project_export.cpp index 9f87fc82b5..170546f14c 100644 --- a/editor/project_export.cpp +++ b/editor/project_export.cpp @@ -76,6 +76,9 @@ void ProjectExportDialog::popup_export() { } _update_presets(); + if (presets->get_current() >= 0) { + _edit_preset(presets->get_current()); // triggers rescan for templates if newly installed + } // Restore valid window bounds or pop up at default size. if (EditorSettings::get_singleton()->has_setting("interface/dialogs/export_bounds")) { @@ -154,7 +157,6 @@ void ProjectExportDialog::_update_presets() { if (current_idx != -1) { presets->select(current_idx); - //_edit_preset(current_idx); } updating = false; @@ -167,6 +169,7 @@ void ProjectExportDialog::_edit_preset(int p_index) { name->set_editable(false); runnable->set_disabled(true); parameters->edit(NULL); + presets->unselect_all(); delete_preset->set_disabled(true); sections->hide(); patches->clear(); @@ -438,11 +441,9 @@ void ProjectExportDialog::_delete_preset() { void ProjectExportDialog::_delete_preset_confirm() { int idx = presets->get_current(); - parameters->edit(NULL); //to avoid crash _edit_preset(-1); EditorExport::get_singleton()->remove_export_preset(idx); _update_presets(); - _edit_preset(presets->get_current()); } Variant ProjectExportDialog::get_drag_data_fw(const Point2 &p_point, Control *p_from) { diff --git a/editor/project_settings_editor.cpp b/editor/project_settings_editor.cpp index 8c7565a441..7e4e589bb4 100644 --- a/editor/project_settings_editor.cpp +++ b/editor/project_settings_editor.cpp @@ -394,6 +394,7 @@ void ProjectSettingsEditor::_show_last_added(const Ref<InputEvent> &p_event, con while (child) { Variant input = child->get_meta("__input"); if (p_event == input) { + r->set_collapsed(false); child->select(0); found = true; break; @@ -654,6 +655,14 @@ void ProjectSettingsEditor::_update_actions() { if (setting) return; + Map<String, bool> collapsed; + + if (input_editor->get_root() && input_editor->get_root()->get_children()) { + for (TreeItem *item = input_editor->get_root()->get_children(); item; item = item->get_next()) { + collapsed[item->get_text(0)] = item->is_collapsed(); + } + } + input_editor->clear(); TreeItem *root = input_editor->create_item(); input_editor->set_hide_root(true); @@ -677,6 +686,8 @@ void ProjectSettingsEditor::_update_actions() { TreeItem *item = input_editor->create_item(root); item->set_text(0, name); item->set_custom_bg_color(0, get_color("prop_subsection", "Editor")); + if (collapsed.has(name)) + item->set_collapsed(collapsed[name]); item->set_editable(1, true); item->set_cell_mode(1, TreeItem::CELL_MODE_RANGE); diff --git a/editor/spatial_editor_gizmos.cpp b/editor/spatial_editor_gizmos.cpp index 3b0ac8864a..c45dea0df7 100644 --- a/editor/spatial_editor_gizmos.cpp +++ b/editor/spatial_editor_gizmos.cpp @@ -3272,10 +3272,10 @@ NavigationMeshSpatialGizmo::NavigationMeshSpatialGizmo(NavigationMeshInstance *p navmesh = p_navmesh; } - ////// - /// - /// - /// +////// +/// +/// +/// #define BODY_A_RADIUS 0.25 #define BODY_B_RADIUS 0.27 diff --git a/main/main.cpp b/main/main.cpp index 23acb60c89..23f2776737 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -1823,6 +1823,8 @@ bool Main::iteration() { ScriptServer::get_language(i)->frame(); } + AudioServer::get_singleton()->update(); + if (script_debugger) { if (script_debugger->is_profiling()) { script_debugger->profiling_set_frame_times(USEC_TO_SEC(frame_time), USEC_TO_SEC(idle_process_ticks), USEC_TO_SEC(physics_process_ticks), frame_slice); diff --git a/main/performance.cpp b/main/performance.cpp index fc915e2e76..70e0a5f7aa 100644 --- a/main/performance.cpp +++ b/main/performance.cpp @@ -32,6 +32,7 @@ #include "message_queue.h" #include "os/os.h" #include "scene/main/scene_tree.h" +#include "servers/audio_server.h" #include "servers/physics_2d_server.h" #include "servers/physics_server.h" #include "servers/visual_server.h" @@ -68,6 +69,7 @@ void Performance::_bind_methods() { BIND_ENUM_CONSTANT(PHYSICS_3D_ACTIVE_OBJECTS); BIND_ENUM_CONSTANT(PHYSICS_3D_COLLISION_PAIRS); BIND_ENUM_CONSTANT(PHYSICS_3D_ISLAND_COUNT); + BIND_ENUM_CONSTANT(AUDIO_OUTPUT_LATENCY); BIND_ENUM_CONSTANT(MONITOR_MAX); } @@ -104,6 +106,7 @@ String Performance::get_monitor_name(Monitor p_monitor) const { "physics_3d/active_objects", "physics_3d/collision_pairs", "physics_3d/islands", + "audio/output_latency", }; @@ -147,6 +150,7 @@ float Performance::get_monitor(Monitor p_monitor) const { case PHYSICS_3D_ACTIVE_OBJECTS: return PhysicsServer::get_singleton()->get_process_info(PhysicsServer::INFO_ACTIVE_OBJECTS); case PHYSICS_3D_COLLISION_PAIRS: return PhysicsServer::get_singleton()->get_process_info(PhysicsServer::INFO_COLLISION_PAIRS); case PHYSICS_3D_ISLAND_COUNT: return PhysicsServer::get_singleton()->get_process_info(PhysicsServer::INFO_ISLAND_COUNT); + case AUDIO_OUTPUT_LATENCY: return AudioServer::get_singleton()->get_output_latency(); default: {} } @@ -186,6 +190,7 @@ Performance::MonitorType Performance::get_monitor_type(Monitor p_monitor) const MONITOR_TYPE_QUANTITY, MONITOR_TYPE_QUANTITY, MONITOR_TYPE_QUANTITY, + MONITOR_TYPE_TIME, }; diff --git a/main/performance.h b/main/performance.h index 464226b517..de00df5ff9 100644 --- a/main/performance.h +++ b/main/performance.h @@ -77,6 +77,7 @@ public: PHYSICS_3D_COLLISION_PAIRS, PHYSICS_3D_ISLAND_COUNT, //physics + AUDIO_OUTPUT_LATENCY, MONITOR_MAX }; diff --git a/misc/travis/clang-format.sh b/misc/travis/clang-format.sh index d1e37cc10e..5463998720 100755 --- a/misc/travis/clang-format.sh +++ b/misc/travis/clang-format.sh @@ -1,6 +1,6 @@ #!/bin/sh -CLANG_FORMAT=clang-format-5.0 +CLANG_FORMAT=clang-format-6.0 if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then # Check the whole commit range against $TRAVIS_BRANCH, the base merge branch diff --git a/modules/csg/csg_shape.cpp b/modules/csg/csg_shape.cpp index 5f13474d2c..67cc7e1ba2 100644 --- a/modules/csg/csg_shape.cpp +++ b/modules/csg/csg_shape.cpp @@ -1585,7 +1585,11 @@ CSGBrush *CSGPolygon::_build_brush() { case MODE_PATH: { float bl = curve->get_baked_length(); int splits = MAX(2, Math::ceil(bl / path_interval)); - face_count = triangles.size() * 2 / 3 + splits * final_polygon.size() * 2; + if (path_joined) { + face_count = splits * final_polygon.size() * 2; + } else { + face_count = triangles.size() * 2 / 3 + splits * final_polygon.size() * 2; + } } break; } @@ -1793,8 +1797,14 @@ CSGBrush *CSGPolygon::_build_brush() { float bl = curve->get_baked_length(); int splits = MAX(2, Math::ceil(bl / path_interval)); + float u1 = 0.0; + float u2 = path_continuous_u ? 0.0 : 1.0; - Transform path_to_this = get_global_transform().affine_inverse() * path->get_global_transform(); + Transform path_to_this; + if (!path_local) { + // center on paths origin + path_to_this = get_global_transform().affine_inverse() * path->get_global_transform(); + } Transform prev_xf; @@ -1812,6 +1822,9 @@ CSGBrush *CSGPolygon::_build_brush() { for (int i = 0; i <= splits; i++) { float ofs = i * path_interval; + if (i == splits && path_joined) { + ofs = 0.0; + } Transform xf; xf.origin = curve->interpolate_baked(ofs); @@ -1836,6 +1849,11 @@ CSGBrush *CSGPolygon::_build_brush() { xf = path_to_this * xf; if (i > 0) { + if (path_continuous_u) { + u1 = u2; + u2 += (prev_xf.origin - xf.origin).length(); + }; + //put triangles where they belong //add triangles for depth for (int j = 0; j < final_polygon.size(); j++) { @@ -1850,10 +1868,10 @@ CSGBrush *CSGPolygon::_build_brush() { }; Vector2 u[4] = { - Vector2(0, 0), - Vector2(0, 1), - Vector2(1, 1), - Vector2(1, 0) + Vector2(u1, 0), + Vector2(u1, 1), + Vector2(u2, 1), + Vector2(u2, 0) }; // face 1 @@ -1888,7 +1906,7 @@ CSGBrush *CSGPolygon::_build_brush() { } } - if (i == 0) { + if (i == 0 && !path_joined) { for (int j = 0; j < triangles.size(); j += 3) { for (int k = 0; k < 3; k++) { @@ -1905,7 +1923,7 @@ CSGBrush *CSGPolygon::_build_brush() { } } - if (i == splits) { + if (i == splits && !path_joined) { for (int j = 0; j < triangles.size(); j += 3) { for (int k = 0; k < 3; k++) { @@ -2003,6 +2021,15 @@ void CSGPolygon::_bind_methods() { ClassDB::bind_method(D_METHOD("set_path_rotation", "mode"), &CSGPolygon::set_path_rotation); ClassDB::bind_method(D_METHOD("get_path_rotation"), &CSGPolygon::get_path_rotation); + ClassDB::bind_method(D_METHOD("set_path_local", "enable"), &CSGPolygon::set_path_local); + ClassDB::bind_method(D_METHOD("is_path_local"), &CSGPolygon::is_path_local); + + ClassDB::bind_method(D_METHOD("set_path_continuous_u", "enable"), &CSGPolygon::set_path_continuous_u); + ClassDB::bind_method(D_METHOD("is_path_continuous_u"), &CSGPolygon::is_path_continuous_u); + + ClassDB::bind_method(D_METHOD("set_path_joined", "enable"), &CSGPolygon::set_path_joined); + ClassDB::bind_method(D_METHOD("is_path_joined"), &CSGPolygon::is_path_joined); + ClassDB::bind_method(D_METHOD("set_material", "material"), &CSGPolygon::set_material); ClassDB::bind_method(D_METHOD("get_material"), &CSGPolygon::get_material); @@ -2023,6 +2050,9 @@ void CSGPolygon::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "path_node", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Path"), "set_path_node", "get_path_node"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "path_interval", PROPERTY_HINT_EXP_RANGE, "0.001,1000.0,0.001,or_greater"), "set_path_interval", "get_path_interval"); ADD_PROPERTY(PropertyInfo(Variant::INT, "path_rotation", PROPERTY_HINT_ENUM, "Polygon,Path,PathFollow"), "set_path_rotation", "get_path_rotation"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "path_local"), "set_path_local", "is_path_local"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "path_continuous_u"), "set_path_continuous_u", "is_path_continuous_u"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "path_joined"), "set_path_joined", "is_path_joined"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "smooth_faces"), "set_smooth_faces", "get_smooth_faces"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "SpatialMaterial,ShaderMaterial"), "set_material", "get_material"); @@ -2067,6 +2097,15 @@ float CSGPolygon::get_depth() const { return depth; } +void CSGPolygon::set_path_continuous_u(bool p_enable) { + path_continuous_u = p_enable; + _make_dirty(); +} + +bool CSGPolygon::is_path_continuous_u() const { + return path_continuous_u; +} + void CSGPolygon::set_spin_degrees(const float p_spin_degrees) { ERR_FAIL_COND(p_spin_degrees < 0.01 || p_spin_degrees > 360); spin_degrees = p_spin_degrees; @@ -2119,6 +2158,26 @@ CSGPolygon::PathRotation CSGPolygon::get_path_rotation() const { return path_rotation; } +void CSGPolygon::set_path_local(bool p_enable) { + path_local = p_enable; + _make_dirty(); + update_gizmo(); +} + +bool CSGPolygon::is_path_local() const { + return path_local; +} + +void CSGPolygon::set_path_joined(bool p_enable) { + path_joined = p_enable; + _make_dirty(); + update_gizmo(); +} + +bool CSGPolygon::is_path_joined() const { + return path_joined; +} + void CSGPolygon::set_smooth_faces(const bool p_smooth_faces) { smooth_faces = p_smooth_faces; _make_dirty(); @@ -2160,5 +2219,8 @@ CSGPolygon::CSGPolygon() { smooth_faces = false; path_interval = 1; path_rotation = PATH_ROTATION_PATH; + path_local = false; + path_continuous_u = false; + path_joined = false; path_cache = NULL; } diff --git a/modules/csg/csg_shape.h b/modules/csg/csg_shape.h index cbb5c7e041..6898cdaf64 100644 --- a/modules/csg/csg_shape.h +++ b/modules/csg/csg_shape.h @@ -334,10 +334,13 @@ private: NodePath path_node; float path_interval; PathRotation path_rotation; + bool path_local; Node *path_cache; bool smooth_faces; + bool path_continuous_u; + bool path_joined; bool _is_editable_3d_polygon() const; bool _has_editable_3d_polygon_no_depth() const; @@ -375,6 +378,15 @@ public: void set_path_rotation(PathRotation p_rotation); PathRotation get_path_rotation() const; + void set_path_local(bool p_enable); + bool is_path_local() const; + + void set_path_continuous_u(bool p_enable); + bool is_path_continuous_u() const; + + void set_path_joined(bool p_enable); + bool is_path_joined() const; + void set_smooth_faces(bool p_smooth_faces); bool get_smooth_faces() const; diff --git a/modules/csg/doc_classes/CSGBox.xml b/modules/csg/doc_classes/CSGBox.xml index 80455fda80..5ec7b5089d 100644 --- a/modules/csg/doc_classes/CSGBox.xml +++ b/modules/csg/doc_classes/CSGBox.xml @@ -1,8 +1,10 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="CSGBox" inherits="CSGPrimitive" category="Core" version="3.1"> <brief_description> + A CSG Box shape. </brief_description> <description> + This node allows you to create a box for use with the CSG system. </description> <tutorials> </tutorials> @@ -12,12 +14,16 @@ </methods> <members> <member name="depth" type="float" setter="set_depth" getter="get_depth"> + Depth of the box measured from the center of the box. </member> <member name="height" type="float" setter="set_height" getter="get_height"> + Height of the box measured from the center of the box. </member> <member name="material" type="Material" setter="set_material" getter="get_material"> + The material used to render the box. </member> <member name="width" type="float" setter="set_width" getter="get_width"> + Width of the box measured from the center of the box. </member> </members> <constants> diff --git a/modules/csg/doc_classes/CSGCombiner.xml b/modules/csg/doc_classes/CSGCombiner.xml index b2265d7703..1cfaa74b7d 100644 --- a/modules/csg/doc_classes/CSGCombiner.xml +++ b/modules/csg/doc_classes/CSGCombiner.xml @@ -1,8 +1,10 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="CSGCombiner" inherits="CSGShape" category="Core" version="3.1"> <brief_description> + A CSG node that allows you to combine other CSG modifiers. </brief_description> <description> + For complex arrangements of shapes it is sometimes needed to add structure to your CSG nodes. The CSGCombiner node allows you to create this structure. The node encapsulates the result of the CSG operations of its children. In this way it is possible to do operations on one set of shapes that are children of one CSGCombiner node, and a set of separate operations on a second set of shapes that are children of a second CSGCombiner node, and then do an operation that takes the two end results as their input to create the final shape. </description> <tutorials> </tutorials> diff --git a/modules/csg/doc_classes/CSGCylinder.xml b/modules/csg/doc_classes/CSGCylinder.xml index 0cab26ad3d..92b170ed1f 100644 --- a/modules/csg/doc_classes/CSGCylinder.xml +++ b/modules/csg/doc_classes/CSGCylinder.xml @@ -1,8 +1,10 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="CSGCylinder" inherits="CSGPrimitive" category="Core" version="3.1"> <brief_description> + A CSG Cylinder shape. </brief_description> <description> + This node allows you to create a cylinder (or cone) for use with the CSG system. </description> <tutorials> </tutorials> @@ -12,16 +14,22 @@ </methods> <members> <member name="cone" type="bool" setter="set_cone" getter="is_cone"> + If true a cone is created, the [member radius] will only apply to one side. </member> <member name="height" type="float" setter="set_height" getter="get_height"> + The height of the cylinder. </member> <member name="material" type="Material" setter="set_material" getter="get_material"> + The material used to render the cylinder. </member> <member name="radius" type="float" setter="set_radius" getter="get_radius"> + The radius of the cylinder. </member> <member name="sides" type="int" setter="set_sides" getter="get_sides"> + The number of sides of the cylinder, the higher this number the more detail there will be in the cylinder. </member> <member name="smooth_faces" type="bool" setter="set_smooth_faces" getter="get_smooth_faces"> + If true the normals of the cylinder are set to give a smooth effect making the cylinder seem rounded. When false the cylinder will have a flat shaded look. </member> </members> <constants> diff --git a/modules/csg/doc_classes/CSGMesh.xml b/modules/csg/doc_classes/CSGMesh.xml index e5c3e5ccf3..419214b7e6 100644 --- a/modules/csg/doc_classes/CSGMesh.xml +++ b/modules/csg/doc_classes/CSGMesh.xml @@ -1,8 +1,10 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="CSGMesh" inherits="CSGPrimitive" category="Core" version="3.1"> <brief_description> + A CSG Mesh shape that uses a mesh resource. </brief_description> <description> + This CSG node allows you to use any mesh resource as a CSG shape provided it is closed, does not self-intersect, does not contain internal faces and has no edges that connect to more then two faces. </description> <tutorials> </tutorials> @@ -12,6 +14,7 @@ </methods> <members> <member name="mesh" type="Mesh" setter="set_mesh" getter="get_mesh"> + The mesh resource to use as a CSG shape. </member> </members> <constants> diff --git a/modules/csg/doc_classes/CSGPolygon.xml b/modules/csg/doc_classes/CSGPolygon.xml index 379c512d6a..a33e5557cb 100644 --- a/modules/csg/doc_classes/CSGPolygon.xml +++ b/modules/csg/doc_classes/CSGPolygon.xml @@ -1,8 +1,10 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="CSGPolygon" inherits="CSGPrimitive" category="Core" version="3.1"> <brief_description> + Extrudes a 2D polygon shape to create a 3D mesh. </brief_description> <description> + This node takes a 2D polygon shape and extrudes it to create a 3D mesh. </description> <tutorials> </tutorials> @@ -12,38 +14,63 @@ </methods> <members> <member name="depth" type="float" setter="set_depth" getter="get_depth"> + Extrusion depth when [member mode] is [constant MODE_DEPTH]. </member> <member name="material" type="Material" setter="set_material" getter="get_material"> + Material to use for the resulting mesh. </member> <member name="mode" type="int" setter="set_mode" getter="get_mode" enum="CSGPolygon.Mode"> + Extrusion mode. + </member> + <member name="path_continuous_u" type="bool" setter="set_path_continuous_u" getter="is_path_continuous_u"> + If true the u component of our uv will continuously increase in unison with the distance traveled along our path when [member mode] is [constant MODE_PATH]. </member> <member name="path_interval" type="float" setter="set_path_interval" getter="get_path_interval"> + Interval at which a new extrusion slice is added along the path when [member mode] is [constant MODE_PATH]. + </member> + <member name="path_joined" type="bool" setter="set_path_joined" getter="is_path_joined"> + If true the start and end of our path are joined together ensuring there is no seam when [member mode] is [constant MODE_PATH]. + </member> + <member name="path_local" type="bool" setter="set_path_local" getter="is_path_local"> + If false we extrude centered on our path, if true we extrude in relation to the position of our CSGPolygon when [member mode] is [constant MODE_PATH]. </member> <member name="path_node" type="NodePath" setter="set_path_node" getter="get_path_node"> + The [Shape] object containing the path along which we extrude when [member mode] is [constant MODE_PATH]. </member> <member name="path_rotation" type="int" setter="set_path_rotation" getter="get_path_rotation" enum="CSGPolygon.PathRotation"> + The method by which each slice is rotated along the path when [member mode] is [constant MODE_PATH]. </member> <member name="polygon" type="PoolVector2Array" setter="set_polygon" getter="get_polygon"> + Point array that defines the shape that we'll extrude. </member> <member name="smooth_faces" type="bool" setter="set_smooth_faces" getter="get_smooth_faces"> + Generates smooth normals so smooth shading is applied to our mesh. </member> <member name="spin_degrees" type="float" setter="set_spin_degrees" getter="get_spin_degrees"> + Degrees to rotate our extrusion for each slice when [member mode] is [constant MODE_SPIN]. </member> <member name="spin_sides" type="int" setter="set_spin_sides" getter="get_spin_sides"> + Number of extrusion when [member mode] is [constant MODE_SPIN]. </member> </members> <constants> <constant name="MODE_DEPTH" value="0" enum="Mode"> + Shape is extruded to [member depth]. </constant> <constant name="MODE_SPIN" value="1" enum="Mode"> + Shape is extruded by rotating it around an axis. </constant> <constant name="MODE_PATH" value="2" enum="Mode"> + Shape is extruded along a path set by a [Shape] set in [member path_node]. </constant> <constant name="PATH_ROTATION_POLYGON" value="0" enum="PathRotation"> + Slice is not rotated. </constant> <constant name="PATH_ROTATION_PATH" value="1" enum="PathRotation"> + Slice is rotated around the up vector of the path. </constant> <constant name="PATH_ROTATION_PATH_FOLLOW" value="2" enum="PathRotation"> + Slice is rotate to match the path exactly. </constant> </constants> </class> diff --git a/modules/csg/doc_classes/CSGPrimitive.xml b/modules/csg/doc_classes/CSGPrimitive.xml index bf41c40f22..2591bab7e3 100644 --- a/modules/csg/doc_classes/CSGPrimitive.xml +++ b/modules/csg/doc_classes/CSGPrimitive.xml @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="CSGPrimitive" inherits="CSGShape" category="Core" version="3.1"> <brief_description> + Base class for CSG primitives. </brief_description> <description> </description> @@ -12,6 +13,7 @@ </methods> <members> <member name="invert_faces" type="bool" setter="set_invert_faces" getter="is_inverting_faces"> + Invert the faces of the mesh. </member> </members> <constants> diff --git a/modules/csg/doc_classes/CSGShape.xml b/modules/csg/doc_classes/CSGShape.xml index cf236a4207..90621b94f4 100644 --- a/modules/csg/doc_classes/CSGShape.xml +++ b/modules/csg/doc_classes/CSGShape.xml @@ -1,8 +1,10 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="CSGShape" inherits="VisualInstance" category="Core" version="3.1"> <brief_description> + The CSG base class. </brief_description> <description> + This is the CSG base class that provides CSG operation support to the various CSG nodes in Godot. </description> <tutorials> </tutorials> @@ -13,23 +15,29 @@ <return type="bool"> </return> <description> + Returns true if this is a root shape and is thus the object that is rendered. </description> </method> </methods> <members> <member name="operation" type="int" setter="set_operation" getter="get_operation" enum="CSGShape.Operation"> + The operation that is performed on this shape. This is ignored for the first CSG child node as the operation is between this node and the previous child of this nodes parent. </member> <member name="snap" type="float" setter="set_snap" getter="get_snap"> </member> <member name="use_collision" type="bool" setter="set_use_collision" getter="is_using_collision"> + Adds a collision shape to the physics engine for our CSG shape. This will always act like a static body. Note that the collision shape is still active even if the CSG shape itself is hidden. </member> </members> <constants> <constant name="OPERATION_UNION" value="0" enum="Operation"> + Geometry of both primitives is merged, intersecting geometry is removed. </constant> <constant name="OPERATION_INTERSECTION" value="1" enum="Operation"> + Only intersecting geometry remains, the rest is removed. </constant> <constant name="OPERATION_SUBTRACTION" value="2" enum="Operation"> + The second shape is susbtracted from the first, leaving a dent with it's shape. </constant> </constants> </class> diff --git a/modules/csg/doc_classes/CSGSphere.xml b/modules/csg/doc_classes/CSGSphere.xml index 520368506e..a0069879cb 100644 --- a/modules/csg/doc_classes/CSGSphere.xml +++ b/modules/csg/doc_classes/CSGSphere.xml @@ -1,8 +1,10 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="CSGSphere" inherits="CSGPrimitive" category="Core" version="3.1"> <brief_description> + A CSG Sphere shape. </brief_description> <description> + This node allows you to create a sphere for use with the CSG system. </description> <tutorials> </tutorials> @@ -12,14 +14,19 @@ </methods> <members> <member name="material" type="Material" setter="set_material" getter="get_material"> + The material used to render the sphere. </member> <member name="radial_segments" type="int" setter="set_radial_segments" getter="get_radial_segments"> + Number of vertical slices for the sphere. </member> <member name="radius" type="float" setter="set_radius" getter="get_radius"> + Radius of the sphere. </member> <member name="rings" type="int" setter="set_rings" getter="get_rings"> + Number of horizontal slices for the sphere. </member> <member name="smooth_faces" type="bool" setter="set_smooth_faces" getter="get_smooth_faces"> + If true the normals of the sphere are set to give a smooth effect making the sphere seem rounded. When false the sphere will have a flat shaded look. </member> </members> <constants> diff --git a/modules/csg/doc_classes/CSGTorus.xml b/modules/csg/doc_classes/CSGTorus.xml index 58bbef2600..187d71a2fa 100644 --- a/modules/csg/doc_classes/CSGTorus.xml +++ b/modules/csg/doc_classes/CSGTorus.xml @@ -1,8 +1,10 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="CSGTorus" inherits="CSGPrimitive" category="Core" version="3.1"> <brief_description> + A CSG Torus shape. </brief_description> <description> + This node allows you to create a torus for use with the CSG system. </description> <tutorials> </tutorials> @@ -12,16 +14,22 @@ </methods> <members> <member name="inner_radius" type="float" setter="set_inner_radius" getter="get_inner_radius"> + The inner radius of the torus. </member> <member name="material" type="Material" setter="set_material" getter="get_material"> + The material used to render the torus. </member> <member name="outer_radius" type="float" setter="set_outer_radius" getter="get_outer_radius"> + The outer radius of the torus. </member> <member name="ring_sides" type="int" setter="set_ring_sides" getter="get_ring_sides"> + The number of edges each ring of the torus is constructed of. </member> <member name="sides" type="int" setter="set_sides" getter="get_sides"> + The number of slices the torus is constructed of. </member> <member name="smooth_faces" type="bool" setter="set_smooth_faces" getter="get_smooth_faces"> + If true the normals of the torus are set to give a smooth effect making the torus seem rounded. When false the torus will have a flat shaded look. </member> </members> <constants> diff --git a/modules/gdscript/gdscript_compiler.cpp b/modules/gdscript/gdscript_compiler.cpp index 7ce19859ca..70f3d704ae 100644 --- a/modules/gdscript/gdscript_compiler.cpp +++ b/modules/gdscript/gdscript_compiler.cpp @@ -863,7 +863,7 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: if (on->arguments[0]->type == GDScriptParser::Node::TYPE_OPERATOR && (static_cast<GDScriptParser::OperatorNode *>(on->arguments[0])->op == GDScriptParser::OperatorNode::OP_INDEX || static_cast<GDScriptParser::OperatorNode *>(on->arguments[0])->op == GDScriptParser::OperatorNode::OP_INDEX_NAMED)) { - // SET (chained) MODE! + // SET (chained) MODE! #ifdef DEBUG_ENABLED if (static_cast<GDScriptParser::OperatorNode *>(on->arguments[0])->op == GDScriptParser::OperatorNode::OP_INDEX_NAMED) { const GDScriptParser::OperatorNode *inon = static_cast<GDScriptParser::OperatorNode *>(on->arguments[0]); diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp index c0c3bd7b06..c8d2d2e3e8 100644 --- a/modules/gdscript/gdscript_editor.cpp +++ b/modules/gdscript/gdscript_editor.cpp @@ -1820,7 +1820,7 @@ static void _find_type_arguments(GDScriptCompletionContext &context, const GDScr } else { - //regular method + //regular method #if defined(DEBUG_METHODS_ENABLED) && defined(TOOLS_ENABLED) if (p_argidx < m->get_argument_count()) { PropertyInfo pi = m->get_argument_info(p_argidx); diff --git a/modules/gdscript/gdscript_tokenizer.cpp b/modules/gdscript/gdscript_tokenizer.cpp index 9517b95f3f..1d30871e3f 100644 --- a/modules/gdscript/gdscript_tokenizer.cpp +++ b/modules/gdscript/gdscript_tokenizer.cpp @@ -1137,7 +1137,7 @@ void GDScriptTokenizerText::advance(int p_amount) { _advance(); } - ////////////////////////////////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////////////////////////////// #define BYTECODE_VERSION 13 diff --git a/modules/mbedtls/stream_peer_mbed_tls.cpp b/modules/mbedtls/stream_peer_mbed_tls.cpp index a63e53ec1f..884c26ddfe 100755 --- a/modules/mbedtls/stream_peer_mbed_tls.cpp +++ b/modules/mbedtls/stream_peer_mbed_tls.cpp @@ -29,6 +29,8 @@ /*************************************************************************/ #include "stream_peer_mbed_tls.h" +#include "mbedtls/platform_util.h" +#include "os/file_access.h" static void my_debug(void *ctx, int level, const char *file, int line, @@ -81,6 +83,36 @@ int StreamPeerMbedTLS::bio_recv(void *ctx, unsigned char *buf, size_t len) { return got; } +void StreamPeerMbedTLS::_cleanup() { + + mbedtls_ssl_free(&ssl); + mbedtls_ssl_config_free(&conf); + mbedtls_ctr_drbg_free(&ctr_drbg); + mbedtls_entropy_free(&entropy); + + base = Ref<StreamPeer>(); + status = STATUS_DISCONNECTED; +} + +Error StreamPeerMbedTLS::_do_handshake() { + int ret = 0; + while ((ret = mbedtls_ssl_handshake(&ssl)) != 0) { + if (ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE) { + ERR_PRINTS("TLS handshake error: " + itos(ret)); + _print_error(ret); + disconnect_from_stream(); + status = STATUS_ERROR; + return FAILED; + } else if (!blocking_handshake) { + // Will retry via poll later + return OK; + } + } + + status = STATUS_CONNECTED; + return OK; +} + Error StreamPeerMbedTLS::connect_to_stream(Ref<StreamPeer> p_base, bool p_validate_certs, const String &p_for_hostname) { base = p_base; @@ -95,6 +127,7 @@ Error StreamPeerMbedTLS::connect_to_stream(Ref<StreamPeer> p_base, bool p_valida ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy, NULL, 0); if (ret != 0) { ERR_PRINTS(" failed\n ! mbedtls_ctr_drbg_seed returned an error" + itos(ret)); + _cleanup(); return FAILED; } @@ -112,29 +145,24 @@ Error StreamPeerMbedTLS::connect_to_stream(Ref<StreamPeer> p_base, bool p_valida mbedtls_ssl_set_bio(&ssl, this, bio_send, bio_recv, NULL); - while ((ret = mbedtls_ssl_handshake(&ssl)) != 0) { - if (ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE) { - ERR_PRINTS("TLS handshake error: " + itos(ret)); - _print_error(ret); - status = STATUS_ERROR_HOSTNAME_MISMATCH; - return FAILED; - } - } + status = STATUS_HANDSHAKING; - connected = true; - status = STATUS_CONNECTED; + if ((ret = _do_handshake()) != OK) { + status = STATUS_ERROR_HOSTNAME_MISMATCH; + return FAILED; + } return OK; } Error StreamPeerMbedTLS::accept_stream(Ref<StreamPeer> p_base) { - return ERR_UNAVAILABLE; + return OK; } Error StreamPeerMbedTLS::put_data(const uint8_t *p_data, int p_bytes) { - ERR_FAIL_COND_V(!connected, ERR_UNCONFIGURED); + ERR_FAIL_COND_V(status != STATUS_CONNECTED, ERR_UNCONFIGURED); Error err; int sent = 0; @@ -155,7 +183,7 @@ Error StreamPeerMbedTLS::put_data(const uint8_t *p_data, int p_bytes) { Error StreamPeerMbedTLS::put_partial_data(const uint8_t *p_data, int p_bytes, int &r_sent) { - ERR_FAIL_COND_V(!connected, ERR_UNCONFIGURED); + ERR_FAIL_COND_V(status != STATUS_CONNECTED, ERR_UNCONFIGURED); r_sent = 0; @@ -177,7 +205,7 @@ Error StreamPeerMbedTLS::put_partial_data(const uint8_t *p_data, int p_bytes, in Error StreamPeerMbedTLS::get_data(uint8_t *p_buffer, int p_bytes) { - ERR_FAIL_COND_V(!connected, ERR_UNCONFIGURED); + ERR_FAIL_COND_V(status != STATUS_CONNECTED, ERR_UNCONFIGURED); Error err; @@ -199,7 +227,7 @@ Error StreamPeerMbedTLS::get_data(uint8_t *p_buffer, int p_bytes) { Error StreamPeerMbedTLS::get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_received) { - ERR_FAIL_COND_V(!connected, ERR_UNCONFIGURED); + ERR_FAIL_COND_V(status != STATUS_CONNECTED, ERR_UNCONFIGURED); r_received = 0; @@ -218,27 +246,30 @@ Error StreamPeerMbedTLS::get_partial_data(uint8_t *p_buffer, int p_bytes, int &r void StreamPeerMbedTLS::poll() { - ERR_FAIL_COND(!connected); + ERR_FAIL_COND(status != STATUS_CONNECTED && status != STATUS_HANDSHAKING); ERR_FAIL_COND(!base.is_valid()); + if (status == STATUS_HANDSHAKING) { + _do_handshake(); + return; + } + int ret = mbedtls_ssl_read(&ssl, NULL, 0); if (ret < 0 && ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE) { _print_error(ret); disconnect_from_stream(); - return; } } int StreamPeerMbedTLS::get_available_bytes() const { - ERR_FAIL_COND_V(!connected, 0); + ERR_FAIL_COND_V(status != STATUS_CONNECTED, 0); return mbedtls_ssl_get_bytes_avail(&ssl); } StreamPeerMbedTLS::StreamPeerMbedTLS() { - connected = false; status = STATUS_DISCONNECTED; } @@ -248,17 +279,10 @@ StreamPeerMbedTLS::~StreamPeerMbedTLS() { void StreamPeerMbedTLS::disconnect_from_stream() { - if (!connected) + if (status != STATUS_CONNECTED && status != STATUS_HANDSHAKING) return; - mbedtls_ssl_free(&ssl); - mbedtls_ssl_config_free(&conf); - mbedtls_ctr_drbg_free(&ctr_drbg); - mbedtls_entropy_free(&entropy); - - base = Ref<StreamPeer>(); - connected = false; - status = STATUS_DISCONNECTED; + _cleanup(); } StreamPeerMbedTLS::Status StreamPeerMbedTLS::get_status() const { diff --git a/modules/mbedtls/stream_peer_mbed_tls.h b/modules/mbedtls/stream_peer_mbed_tls.h index 2b96a194a1..7f4e5a4513 100755 --- a/modules/mbedtls/stream_peer_mbed_tls.h +++ b/modules/mbedtls/stream_peer_mbed_tls.h @@ -48,8 +48,6 @@ private: Status status; String hostname; - bool connected; - Ref<StreamPeer> base; static StreamPeerSSL *_create_func(); @@ -57,9 +55,11 @@ private: static int bio_recv(void *ctx, unsigned char *buf, size_t len); static int bio_send(void *ctx, const unsigned char *buf, size_t len); + void _cleanup(); protected: static mbedtls_x509_crt cacert; + mbedtls_entropy_context entropy; mbedtls_ctr_drbg_context ctr_drbg; mbedtls_ssl_context ssl; @@ -67,6 +67,8 @@ protected: static void _bind_methods(); + Error _do_handshake(); + public: virtual void poll(); virtual Error accept_stream(Ref<StreamPeer> p_base); diff --git a/modules/mono/editor/bindings_generator.cpp b/modules/mono/editor/bindings_generator.cpp index 4c598d4f37..6fa317ee70 100644 --- a/modules/mono/editor/bindings_generator.cpp +++ b/modules/mono/editor/bindings_generator.cpp @@ -1768,6 +1768,13 @@ void BindingsGenerator::_populate_object_type_interfaces() { continue; } + if (!ClassDB::is_class_enabled(type_cname)) { + if (verbose_output) + WARN_PRINTS("Ignoring type " + type_cname.operator String() + " because it's not enabled"); + class_list.pop_front(); + continue; + } + ClassDB::ClassInfo *class_info = ClassDB::classes.getptr(type_cname); TypeInterface itype = TypeInterface::create_object_type(type_cname, api_type); diff --git a/modules/mono/mono_gd/gd_mono.cpp b/modules/mono/mono_gd/gd_mono.cpp index bc84f43b4f..0f4e211be5 100644 --- a/modules/mono/mono_gd/gd_mono.cpp +++ b/modules/mono/mono_gd/gd_mono.cpp @@ -805,9 +805,9 @@ void GDMono::_domain_assemblies_cleanup(uint32_t p_domain_id) { void GDMono::unhandled_exception_hook(MonoObject *p_exc, void *) { -// This method will be called by the runtime when a thrown exception is not handled. -// It won't be called when we manually treat a thrown exception as unhandled. -// We assume the exception was already printed before calling this hook. + // This method will be called by the runtime when a thrown exception is not handled. + // It won't be called when we manually treat a thrown exception as unhandled. + // We assume the exception was already printed before calling this hook. #ifdef DEBUG_ENABLED GDMonoUtils::debug_send_unhandled_exception_error((MonoException *)p_exc); diff --git a/modules/mono/mono_gd/gd_mono_marshal.cpp b/modules/mono/mono_gd/gd_mono_marshal.cpp index 31c5bbb2fb..5cd77d63e2 100644 --- a/modules/mono/mono_gd/gd_mono_marshal.cpp +++ b/modules/mono/mono_gd/gd_mono_marshal.cpp @@ -884,4 +884,4 @@ Dictionary mono_object_to_Dictionary(MonoObject *p_dict) { return ret; } -} +} // namespace GDMonoMarshal diff --git a/modules/pvr/texture_loader_pvr.cpp b/modules/pvr/texture_loader_pvr.cpp index 8174bccdb7..f5d35714e1 100644 --- a/modules/pvr/texture_loader_pvr.cpp +++ b/modules/pvr/texture_loader_pvr.cpp @@ -240,11 +240,11 @@ ResourceFormatPVR::ResourceFormatPVR() { Image::_image_compress_pvrtc2_func = _compress_pvrtc4; } - ///////////////////////////////////////////////////////// +///////////////////////////////////////////////////////// - //PVRTC decompressor, Based on PVRTC decompressor by IMGTEC. +//PVRTC decompressor, Based on PVRTC decompressor by IMGTEC. - ///////////////////////////////////////////////////////// +///////////////////////////////////////////////////////// #define PT_INDEX 2 #define BLK_Y_SIZE 4 diff --git a/modules/vorbis/audio_stream_ogg_vorbis.cpp b/modules/vorbis/audio_stream_ogg_vorbis.cpp index bae8f7be5f..5bc82f267f 100644 --- a/modules/vorbis/audio_stream_ogg_vorbis.cpp +++ b/modules/vorbis/audio_stream_ogg_vorbis.cpp @@ -48,7 +48,7 @@ size_t AudioStreamPlaybackOGGVorbis::_ov_read_func(void *p_dst, size_t p_data, s int AudioStreamPlaybackOGGVorbis::_ov_seek_func(void *_f, ogg_int64_t offs, int whence) { -//printf("seek to %p, offs %i, whence %i\n",_f,(int)offs,whence); + //printf("seek to %p, offs %i, whence %i\n",_f,(int)offs,whence); #ifdef SEEK_SET //printf("seek set defined\n"); diff --git a/modules/websocket/lws_helper.h b/modules/websocket/lws_helper.h index a4920c3d54..85a1e3769f 100644 --- a/modules/websocket/lws_helper.h +++ b/modules/websocket/lws_helper.h @@ -215,6 +215,6 @@ public: \ \ protected: - /* clang-format on */ +/* clang-format on */ #endif // LWS_HELPER_H diff --git a/platform/android/audio_driver_opensl.cpp b/platform/android/audio_driver_opensl.cpp index e6bd3ff253..fd834193dd 100644 --- a/platform/android/audio_driver_opensl.cpp +++ b/platform/android/audio_driver_opensl.cpp @@ -42,7 +42,8 @@ void AudioDriverOpenSL::_buffer_callback( /* SLuint32 eventFlags, const void * pBuffer, SLuint32 bufferSize, - SLuint32 dataUsed*/) { + SLuint32 dataUsed*/ +) { bool mix = true; diff --git a/platform/android/audio_driver_opensl.h b/platform/android/audio_driver_opensl.h index 2022bad02a..88cb122414 100644 --- a/platform/android/audio_driver_opensl.h +++ b/platform/android/audio_driver_opensl.h @@ -74,7 +74,8 @@ class AudioDriverOpenSL : public AudioDriver { /* SLuint32 eventFlags, const void * pBuffer, SLuint32 bufferSize, - SLuint32 dataUsed*/); + SLuint32 dataUsed*/ + ); static void _buffer_callbacks( SLAndroidSimpleBufferQueueItf queueItf, diff --git a/platform/android/export/export.cpp b/platform/android/export/export.cpp index c3ff157f99..c562a47b00 100644 --- a/platform/android/export/export.cpp +++ b/platform/android/export/export.cpp @@ -228,7 +228,7 @@ class EditorExportAndroid : public EditorExportPlatform { }; Vector<Device> devices; - bool devices_changed; + volatile bool devices_changed; Mutex *device_lock; Thread *device_thread; volatile bool quit_request; @@ -1154,7 +1154,10 @@ public: virtual bool poll_devices() { bool dc = devices_changed; - devices_changed = false; + if (dc) { + // don't clear unless we're reporting true, to avoid race + devices_changed = false; + } return dc; } @@ -1857,9 +1860,9 @@ public: run_icon->create_from_image(img); device_lock = Mutex::create(); - device_thread = Thread::create(_device_poll_thread, this); devices_changed = true; quit_request = false; + device_thread = Thread::create(_device_poll_thread, this); } ~EditorExportAndroid() { diff --git a/platform/android/java/src/org/godotengine/godot/Godot.java b/platform/android/java/src/org/godotengine/godot/Godot.java index 8a2d789dc5..ef798fc790 100644 --- a/platform/android/java/src/org/godotengine/godot/Godot.java +++ b/platform/android/java/src/org/godotengine/godot/Godot.java @@ -297,7 +297,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC runOnUiThread(new Runnable() { @Override public void run() { - view.setKeepScreenOn("True".equals(GodotLib.getGlobal("display/driver/keep_screen_on"))); + view.setKeepScreenOn("True".equals(GodotLib.getGlobal("display/window/energy_saving/keep_screen_on"))); } }); } diff --git a/platform/android/java/src/org/godotengine/godot/payments/ConsumeTask.java b/platform/android/java/src/org/godotengine/godot/payments/ConsumeTask.java index afe5f81b6d..5d94e77cd7 100644 --- a/platform/android/java/src/org/godotengine/godot/payments/ConsumeTask.java +++ b/platform/android/java/src/org/godotengine/godot/payments/ConsumeTask.java @@ -66,7 +66,6 @@ abstract public class ConsumeTask { } final String token = _token; new AsyncTask<String, String, String>() { - @Override protected String doInBackground(String... params) { try { @@ -89,7 +88,6 @@ abstract public class ConsumeTask { error(param); } } - } .execute(); } diff --git a/platform/android/java/src/org/godotengine/godot/payments/PaymentsManager.java b/platform/android/java/src/org/godotengine/godot/payments/PaymentsManager.java index b7bf2362cc..d4c7380424 100644 --- a/platform/android/java/src/org/godotengine/godot/payments/PaymentsManager.java +++ b/platform/android/java/src/org/godotengine/godot/payments/PaymentsManager.java @@ -113,7 +113,6 @@ public class PaymentsManager { public void requestPurchase(final String sku, String transactionId) { new PurchaseTask(mService, Godot.getInstance()) { - @Override protected void error(String message) { godotPaymentV3.callbackFail(message); @@ -128,7 +127,6 @@ public class PaymentsManager { protected void alreadyOwned() { godotPaymentV3.callbackAlreadyOwned(sku); } - } .purchase(sku, transactionId); } @@ -139,7 +137,6 @@ public class PaymentsManager { public void consumeUnconsumedPurchases() { new ReleaseAllConsumablesTask(mService, activity) { - @Override protected void success(String sku, String receipt, String signature, String token) { godotPaymentV3.callbackSuccessProductMassConsumed(receipt, signature, sku); @@ -208,14 +205,12 @@ public class PaymentsManager { public void processPurchaseResponse(int resultCode, Intent data) { new HandlePurchaseTask(activity) { - @Override protected void success(final String sku, final String signature, final String ticket) { godotPaymentV3.callbackSuccess(ticket, signature, sku); if (auto_consume) { new ConsumeTask(mService, activity) { - @Override protected void success(String ticket) { } @@ -245,12 +240,10 @@ public class PaymentsManager { public void validatePurchase(String purchaseToken, final String sku) { new ValidateTask(activity, godotPaymentV3) { - @Override protected void success() { new ConsumeTask(mService, activity) { - @Override protected void success(String ticket) { godotPaymentV3.callbackSuccess(ticket, null, sku); @@ -283,7 +276,6 @@ public class PaymentsManager { public void consume(final String sku) { new ConsumeTask(mService, activity) { - @Override protected void success(String ticket) { godotPaymentV3.callbackSuccessProductMassConsumed(ticket, "", sku); diff --git a/platform/android/java/src/org/godotengine/godot/payments/ReleaseAllConsumablesTask.java b/platform/android/java/src/org/godotengine/godot/payments/ReleaseAllConsumablesTask.java index e00e37f9d1..eccc6f671b 100644 --- a/platform/android/java/src/org/godotengine/godot/payments/ReleaseAllConsumablesTask.java +++ b/platform/android/java/src/org/godotengine/godot/payments/ReleaseAllConsumablesTask.java @@ -88,7 +88,6 @@ abstract public class ReleaseAllConsumablesTask { String signature = mySignatures.get(i); //Log.d("godot", "A punto de consumir un item con token:" + token + "\n" + receipt); new GenericConsumeTask(context, mService, sku, receipt, signature, token) { - @Override public void onSuccess(String sku, String receipt, String signature, String token) { ReleaseAllConsumablesTask.this.success(sku, receipt, signature, token); diff --git a/platform/android/java/src/org/godotengine/godot/payments/ValidateTask.java b/platform/android/java/src/org/godotengine/godot/payments/ValidateTask.java index 1eb9d001e0..0626e50bb1 100644 --- a/platform/android/java/src/org/godotengine/godot/payments/ValidateTask.java +++ b/platform/android/java/src/org/godotengine/godot/payments/ValidateTask.java @@ -63,7 +63,6 @@ abstract public class ValidateTask { public void validatePurchase(final String sku) { new AsyncTask<String, String, String>() { - private ProgressDialog dialog; @Override @@ -113,7 +112,6 @@ abstract public class ValidateTask { error(e.getMessage()); } } - } .execute(); } diff --git a/platform/iphone/app_delegate.mm b/platform/iphone/app_delegate.mm index dd5ce4ab10..cc4985eb0c 100644 --- a/platform/iphone/app_delegate.mm +++ b/platform/iphone/app_delegate.mm @@ -643,7 +643,7 @@ static int frame_count = 0; view_controller.view = glView; window.rootViewController = view_controller; - _set_keep_screen_on(bool(GLOBAL_DEF("display/window/keep_screen_on", true)) ? YES : NO); + _set_keep_screen_on(bool(GLOBAL_DEF("display/window/energy_saving/keep_screen_on", true)) ? YES : NO); glView.useCADisplayLink = bool(GLOBAL_DEF("display.iOS/use_cadisplaylink", true)) ? YES : NO; printf("cadisaplylink: %d", glView.useCADisplayLink); diff --git a/platform/iphone/game_center.mm b/platform/iphone/game_center.mm index 57ff79f7bc..e210bfb862 100644 --- a/platform/iphone/game_center.mm +++ b/platform/iphone/game_center.mm @@ -139,7 +139,6 @@ Error GameCenter::post_score(Variant p_score) { [GKScore reportScores:@[ reporter ] withCompletionHandler:^(NSError *error) { - Dictionary ret; ret["type"] = "post_score"; if (error == nil) { @@ -177,7 +176,6 @@ Error GameCenter::award_achievement(Variant p_params) { [GKAchievement reportAchievements:@[ achievement ] withCompletionHandler:^(NSError *error) { - Dictionary ret; ret["type"] = "award_achievement"; if (error == nil) { @@ -196,7 +194,6 @@ Error GameCenter::award_achievement(Variant p_params) { void GameCenter::request_achievement_descriptions() { [GKAchievementDescription loadAchievementDescriptionsWithCompletionHandler:^(NSArray *descriptions, NSError *error) { - Dictionary ret; ret["type"] = "achievement_descriptions"; if (error == nil) { @@ -252,7 +249,6 @@ void GameCenter::request_achievement_descriptions() { void GameCenter::request_achievements() { [GKAchievement loadAchievementsWithCompletionHandler:^(NSArray *achievements, NSError *error) { - Dictionary ret; ret["type"] = "achievements"; if (error == nil) { @@ -347,7 +343,6 @@ Error GameCenter::request_identity_verification_signature() { GKLocalPlayer *player = [GKLocalPlayer localPlayer]; [player generateIdentityVerificationSignatureWithCompletionHandler:^(NSURL *publicKeyUrl, NSData *signature, NSData *salt, uint64_t timestamp, NSError *error) { - Dictionary ret; ret["type"] = "identity_verification_signature"; if (error == nil) { diff --git a/platform/uwp/os_uwp.cpp b/platform/uwp/os_uwp.cpp index 8cdd13df90..25326ae794 100644 --- a/platform/uwp/os_uwp.cpp +++ b/platform/uwp/os_uwp.cpp @@ -290,7 +290,7 @@ Error OSUWP::initialize(const VideoMode &p_desired, int p_video_driver, int p_au if (is_keep_screen_on()) display_request->RequestActive(); - set_keep_screen_on(GLOBAL_DEF("display/window/keep_screen_on", true)); + set_keep_screen_on(GLOBAL_DEF("display/window/energy_saving/keep_screen_on", true)); return OK; } @@ -385,7 +385,6 @@ void OSUWP::ManagedType::update_clipboard() { if (data->Contains(StandardDataFormats::Text)) { create_task(data->GetTextAsync()).then([this](Platform::String ^ clipboard_content) { - this->clipboard = clipboard_content; }); } diff --git a/platform/windows/godot_win.cpp b/platform/windows/godot_win.cpp index 80f53dd1a1..504a9a0380 100644 --- a/platform/windows/godot_win.cpp +++ b/platform/windows/godot_win.cpp @@ -176,8 +176,8 @@ int _main() { } int main(int _argc, char **_argv) { -// _argc and _argv are ignored -// we are going to use the WideChar version of them instead + // _argc and _argv are ignored + // we are going to use the WideChar version of them instead #ifdef CRASH_HANDLER_EXCEPTION __try { diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 2bc85f76c9..2adc8bfb50 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -1825,8 +1825,8 @@ void OS_X11::process_xevents() { GrabModeAsync, GrabModeAsync, x11_window, None, CurrentTime); } #ifdef TOUCH_ENABLED - // Grab touch devices to avoid OS gesture interference - /*for (int i = 0; i < touch.devices.size(); ++i) { + // Grab touch devices to avoid OS gesture interference + /*for (int i = 0; i < touch.devices.size(); ++i) { XIGrabDevice(x11_display, touch.devices[i], x11_window, CurrentTime, None, XIGrabModeAsync, XIGrabModeAsync, False, &touch.event_mask); }*/ #endif diff --git a/scene/2d/animated_sprite.cpp b/scene/2d/animated_sprite.cpp index e3d1592be0..b56eedabc7 100644 --- a/scene/2d/animated_sprite.cpp +++ b/scene/2d/animated_sprite.cpp @@ -192,6 +192,16 @@ void SpriteFrames::get_animation_list(List<StringName> *r_animations) const { } } +Vector<String> SpriteFrames::get_animation_names() const { + + Vector<String> names; + for (const Map<StringName, Anim>::Element *E = animations.front(); E; E = E->next()) { + names.push_back(E->key()); + } + names.sort(); + return names; +} + void SpriteFrames::set_animation_speed(const StringName &p_anim, float p_fps) { ERR_FAIL_COND(p_fps < 0); @@ -283,6 +293,8 @@ void SpriteFrames::_bind_methods() { ClassDB::bind_method(D_METHOD("remove_animation", "anim"), &SpriteFrames::remove_animation); ClassDB::bind_method(D_METHOD("rename_animation", "anim", "newname"), &SpriteFrames::rename_animation); + ClassDB::bind_method(D_METHOD("get_animation_names"), &SpriteFrames::get_animation_names); + ClassDB::bind_method(D_METHOD("set_animation_speed", "anim", "speed"), &SpriteFrames::set_animation_speed); ClassDB::bind_method(D_METHOD("get_animation_speed", "anim"), &SpriteFrames::get_animation_speed); diff --git a/scene/2d/animated_sprite.h b/scene/2d/animated_sprite.h index 806052a696..f6586aff36 100644 --- a/scene/2d/animated_sprite.h +++ b/scene/2d/animated_sprite.h @@ -72,6 +72,7 @@ public: void rename_animation(const StringName &p_prev, const StringName &p_next); void get_animation_list(List<StringName> *r_animations) const; + Vector<String> get_animation_names() const; void set_animation_speed(const StringName &p_anim, float p_fps); float get_animation_speed(const StringName &p_anim) const; diff --git a/scene/2d/collision_object_2d.cpp b/scene/2d/collision_object_2d.cpp index d05c818ae1..cabd7fddc2 100644 --- a/scene/2d/collision_object_2d.cpp +++ b/scene/2d/collision_object_2d.cpp @@ -38,10 +38,14 @@ void CollisionObject2D::_notification(int p_what) { case NOTIFICATION_ENTER_TREE: { + Transform2D global_transform = get_global_transform(); + if (area) - Physics2DServer::get_singleton()->area_set_transform(rid, get_global_transform()); + Physics2DServer::get_singleton()->area_set_transform(rid, global_transform); else - Physics2DServer::get_singleton()->body_set_state(rid, Physics2DServer::BODY_STATE_TRANSFORM, get_global_transform()); + Physics2DServer::get_singleton()->body_set_state(rid, Physics2DServer::BODY_STATE_TRANSFORM, global_transform); + + last_transform = global_transform; RID space = get_world_2d()->get_space(); if (area) { @@ -60,10 +64,18 @@ void CollisionObject2D::_notification(int p_what) { } break; case NOTIFICATION_TRANSFORM_CHANGED: { + Transform2D global_transform = get_global_transform(); + + if (only_update_transform_changes && global_transform == last_transform) { + return; + } + if (area) - Physics2DServer::get_singleton()->area_set_transform(rid, get_global_transform()); + Physics2DServer::get_singleton()->area_set_transform(rid, global_transform); else - Physics2DServer::get_singleton()->body_set_state(rid, Physics2DServer::BODY_STATE_TRANSFORM, get_global_transform()); + Physics2DServer::get_singleton()->body_set_state(rid, Physics2DServer::BODY_STATE_TRANSFORM, global_transform); + + last_transform = global_transform; } break; case NOTIFICATION_EXIT_TREE: { @@ -318,6 +330,10 @@ void CollisionObject2D::_mouse_exit() { emit_signal(SceneStringNames::get_singleton()->mouse_exited); } +void CollisionObject2D::set_only_update_transform_changes(bool p_enable) { + only_update_transform_changes = p_enable; +} + void CollisionObject2D::_update_pickable() { if (!is_inside_tree()) return; @@ -384,6 +400,7 @@ CollisionObject2D::CollisionObject2D(RID p_rid, bool p_area) { pickable = true; set_notify_transform(true); total_subshapes = 0; + only_update_transform_changes = false; if (p_area) { diff --git a/scene/2d/collision_object_2d.h b/scene/2d/collision_object_2d.h index 6da63d1a0b..29a00bd9f9 100644 --- a/scene/2d/collision_object_2d.h +++ b/scene/2d/collision_object_2d.h @@ -65,6 +65,8 @@ class CollisionObject2D : public Node2D { int total_subshapes; Map<uint32_t, ShapeData> shapes; + Transform2D last_transform; + bool only_update_transform_changes; //this is used for sync physics in KinematicBody protected: CollisionObject2D(RID p_rid, bool p_area); @@ -78,6 +80,8 @@ protected: void _mouse_enter(); void _mouse_exit(); + void set_only_update_transform_changes(bool p_enable); + public: uint32_t create_shape_owner(Object *p_owner); void remove_shape_owner(uint32_t owner); diff --git a/scene/2d/line_2d.cpp b/scene/2d/line_2d.cpp index 3e61dd05f4..e9e895b5bb 100644 --- a/scene/2d/line_2d.cpp +++ b/scene/2d/line_2d.cpp @@ -349,7 +349,7 @@ void Line2D::_bind_methods() { ADD_GROUP("Fill", ""); ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "gradient", PROPERTY_HINT_RESOURCE_TYPE, "Gradient"), "set_gradient", "get_gradient"); ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture"); - ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "texture_mode", PROPERTY_HINT_ENUM, "None,Tile"), "set_texture_mode", "get_texture_mode"); + ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "texture_mode", PROPERTY_HINT_ENUM, "None,Tile,Stretch"), "set_texture_mode", "get_texture_mode"); ADD_GROUP("Capping", ""); ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "joint_mode", PROPERTY_HINT_ENUM, "Sharp,Bevel,Round"), "set_joint_mode", "get_joint_mode"); ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "begin_cap_mode", PROPERTY_HINT_ENUM, "None,Box,Round"), "set_begin_cap_mode", "get_begin_cap_mode"); @@ -368,6 +368,7 @@ void Line2D::_bind_methods() { BIND_ENUM_CONSTANT(LINE_TEXTURE_NONE); BIND_ENUM_CONSTANT(LINE_TEXTURE_TILE); + BIND_ENUM_CONSTANT(LINE_TEXTURE_STRETCH); ClassDB::bind_method(D_METHOD("_gradient_changed"), &Line2D::_gradient_changed); } diff --git a/scene/2d/line_2d.h b/scene/2d/line_2d.h index 24c48982cd..6918018c12 100644 --- a/scene/2d/line_2d.h +++ b/scene/2d/line_2d.h @@ -52,8 +52,8 @@ public: enum LineTextureMode { LINE_TEXTURE_NONE = 0, - LINE_TEXTURE_TILE - // TODO STRETCH mode + LINE_TEXTURE_TILE, + LINE_TEXTURE_STRETCH }; Line2D(); diff --git a/scene/2d/line_builder.cpp b/scene/2d/line_builder.cpp index 845788bada..74ad3e79d0 100644 --- a/scene/2d/line_builder.cpp +++ b/scene/2d/line_builder.cpp @@ -146,7 +146,9 @@ void LineBuilder::build() { float current_distance1 = 0.f; float total_distance = 0.f; _interpolate_color = gradient != NULL; - bool distance_required = _interpolate_color || texture_mode == Line2D::LINE_TEXTURE_TILE; + bool distance_required = _interpolate_color || + texture_mode == Line2D::LINE_TEXTURE_TILE || + texture_mode == Line2D::LINE_TEXTURE_STRETCH; if (distance_required) total_distance = calculate_total_distance(points); if (_interpolate_color) @@ -170,7 +172,7 @@ void LineBuilder::build() { if (texture_mode == Line2D::LINE_TEXTURE_TILE) { uvx0 = 0.5f / tile_aspect; } - new_arc(pos0, pos_up0 - pos0, -Math_PI, color0, Rect2(0.f, 0.f, 1.f, 1.f)); + new_arc(pos0, pos_up0 - pos0, -Math_PI, color0, Rect2(0.f, 0.f, fmin(uvx0 * 2, 1.f), 1.f)); total_distance += width; current_distance0 += hw; current_distance1 = current_distance0; @@ -292,6 +294,9 @@ void LineBuilder::build() { if (texture_mode == Line2D::LINE_TEXTURE_TILE) { uvx0 = current_distance0 / (width * tile_aspect); uvx1 = current_distance1 / (width * tile_aspect); + } else if (texture_mode == Line2D::LINE_TEXTURE_STRETCH) { + uvx0 = current_distance0 / total_distance; + uvx1 = current_distance1 / total_distance; } strip_add_quad(pos_up1, pos_down1, color1, uvx1); @@ -378,6 +383,8 @@ void LineBuilder::build() { } if (texture_mode == Line2D::LINE_TEXTURE_TILE) { uvx1 = current_distance1 / (width * tile_aspect); + } else if (texture_mode == Line2D::LINE_TEXTURE_STRETCH) { + uvx1 = current_distance1 / total_distance; } strip_add_quad(pos_up1, pos_down1, color1, uvx1); @@ -386,7 +393,7 @@ void LineBuilder::build() { if (end_cap_mode == Line2D::LINE_CAP_ROUND) { // Note: color is not used in case we don't interpolate... Color color = _interpolate_color ? gradient->get_color(gradient->get_points_count() - 1) : Color(0, 0, 0); - new_arc(pos1, pos_up1 - pos1, Math_PI, color, Rect2(uvx1 - 0.5f, 0.f, 1.f, 1.f)); + new_arc(pos1, pos_up1 - pos1, Math_PI, color, Rect2(uvx1 - 0.5f / tile_aspect, 0.f, 1.0f / tile_aspect, 1.f)); } } diff --git a/scene/2d/node_2d.cpp b/scene/2d/node_2d.cpp index 3813bd96fe..7252602a93 100644 --- a/scene/2d/node_2d.cpp +++ b/scene/2d/node_2d.cpp @@ -130,7 +130,6 @@ void Node2D::_update_xform_values() { void Node2D::_update_transform() { - Transform2D mat(angle, pos); _mat.set_rotation_and_scale(angle, _scale); _mat.elements[2] = pos; diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp index feb11089d0..8787a2c735 100644 --- a/scene/2d/physics_body_2d.cpp +++ b/scene/2d/physics_body_2d.cpp @@ -32,8 +32,8 @@ #include "core/method_bind_ext.gen.inc" #include "engine.h" +#include "math_funcs.h" #include "scene/scene_string_names.h" - void PhysicsBody2D::_notification(int p_what) { /* @@ -971,11 +971,11 @@ RigidBody2D::~RigidBody2D() { ////////////////////////// -Ref<KinematicCollision2D> KinematicBody2D::_move(const Vector2 &p_motion, bool p_infinite_inertia) { +Ref<KinematicCollision2D> KinematicBody2D::_move(const Vector2 &p_motion, bool p_infinite_inertia, bool p_exclude_raycast_shapes, bool p_test_only) { Collision col; - if (move_and_collide(p_motion, p_infinite_inertia, col)) { + if (move_and_collide(p_motion, p_infinite_inertia, col, p_exclude_raycast_shapes, p_test_only)) { if (motion_cache.is_null()) { motion_cache.instance(); motion_cache->owner = this; @@ -989,11 +989,48 @@ Ref<KinematicCollision2D> KinematicBody2D::_move(const Vector2 &p_motion, bool p return Ref<KinematicCollision2D>(); } -bool KinematicBody2D::move_and_collide(const Vector2 &p_motion, bool p_infinite_inertia, Collision &r_collision) { +bool KinematicBody2D::separate_raycast_shapes(bool p_infinite_inertia, Collision &r_collision) { + + Physics2DServer::SeparationResult sep_res[8]; //max 8 rays + + Transform2D gt = get_global_transform(); + + Vector2 recover; + int hits = Physics2DServer::get_singleton()->body_test_ray_separation(get_rid(), gt, p_infinite_inertia, recover, sep_res, 8, margin); + int deepest = -1; + float deepest_depth; + for (int i = 0; i < hits; i++) { + if (deepest == -1 || sep_res[i].collision_depth > deepest_depth) { + deepest = i; + deepest_depth = sep_res[i].collision_depth; + } + } + + gt.elements[2] += recover; + set_global_transform(gt); + + if (deepest != -1) { + r_collision.collider = sep_res[deepest].collider_id; + r_collision.collider_metadata = sep_res[deepest].collider_metadata; + r_collision.collider_shape = sep_res[deepest].collider_shape; + r_collision.collider_vel = sep_res[deepest].collider_velocity; + r_collision.collision = sep_res[deepest].collision_point; + r_collision.normal = sep_res[deepest].collision_normal; + r_collision.local_shape = sep_res[deepest].collision_local_shape; + r_collision.travel = recover; + r_collision.remainder = Vector2(); + + return true; + } else { + return false; + } +} + +bool KinematicBody2D::move_and_collide(const Vector2 &p_motion, bool p_infinite_inertia, Collision &r_collision, bool p_exclude_raycast_shapes, bool p_test_only) { Transform2D gt = get_global_transform(); Physics2DServer::MotionResult result; - bool colliding = Physics2DServer::get_singleton()->body_test_motion(get_rid(), gt, p_motion, p_infinite_inertia, margin, &result); + bool colliding = Physics2DServer::get_singleton()->body_test_motion(get_rid(), gt, p_motion, p_infinite_inertia, margin, &result, p_exclude_raycast_shapes); if (colliding) { r_collision.collider_metadata = result.collider_metadata; @@ -1002,23 +1039,36 @@ bool KinematicBody2D::move_and_collide(const Vector2 &p_motion, bool p_infinite_ r_collision.collision = result.collision_point; r_collision.normal = result.collision_normal; r_collision.collider = result.collider_id; + r_collision.collider_rid = result.collider; r_collision.travel = result.motion; r_collision.remainder = result.remainder; r_collision.local_shape = result.collision_local_shape; } - gt.elements[2] += result.motion; - set_global_transform(gt); + if (!p_test_only) { + gt.elements[2] += result.motion; + set_global_transform(gt); + } return colliding; } Vector2 KinematicBody2D::move_and_slide(const Vector2 &p_linear_velocity, const Vector2 &p_floor_direction, bool p_infinite_inertia, float p_slope_stop_min_velocity, int p_max_slides, float p_floor_max_angle) { - Vector2 motion = (floor_velocity + p_linear_velocity) * get_physics_process_delta_time(); + Vector2 floor_motion = floor_velocity; + if (on_floor && on_floor_body.is_valid()) { + //this approach makes sure there is less delay between the actual body velocity and the one we saved + Physics2DDirectBodyState *bs = Physics2DServer::get_singleton()->body_get_direct_state(on_floor_body); + if (bs) { + floor_motion = bs->get_linear_velocity(); + } + } + + Vector2 motion = (floor_motion + p_linear_velocity) * get_physics_process_delta_time(); Vector2 lv = p_linear_velocity; on_floor = false; + on_floor_body = RID(); on_ceiling = false; on_wall = false; colliders.clear(); @@ -1027,48 +1077,68 @@ Vector2 KinematicBody2D::move_and_slide(const Vector2 &p_linear_velocity, const while (p_max_slides) { Collision collision; + bool found_collision = false; + + for (int i = 0; i < 2; i++) { + bool collided; + if (i == 0) { //collide + collided = move_and_collide(motion, p_infinite_inertia, collision); + if (!collided) { + motion = Vector2(); //clear because no collision happened and motion completed + } + } else { //separate raycasts (if any) + collided = separate_raycast_shapes(p_infinite_inertia, collision); + if (collided) { + collision.remainder = motion; //keep + collision.travel = Vector2(); + } + } - bool collided = move_and_collide(motion, p_infinite_inertia, collision); - - if (collided) { - - motion = collision.remainder; - - if (p_floor_direction == Vector2()) { - //all is a wall - on_wall = true; - } else { - if (collision.normal.dot(p_floor_direction) >= Math::cos(p_floor_max_angle)) { //floor + if (collided) { + found_collision = true; + } - on_floor = true; - floor_velocity = collision.collider_vel; + if (collided) { - Vector2 rel_v = lv - floor_velocity; - Vector2 hv = rel_v - p_floor_direction * p_floor_direction.dot(rel_v); + motion = collision.remainder; - if (collision.travel.length() < 1 && hv.length() < p_slope_stop_min_velocity) { - Transform2D gt = get_global_transform(); - gt.elements[2] -= collision.travel; - set_global_transform(gt); - return Vector2(); - } - } else if (collision.normal.dot(-p_floor_direction) >= Math::cos(p_floor_max_angle)) { //ceiling - on_ceiling = true; - } else { + if (p_floor_direction == Vector2()) { + //all is a wall on_wall = true; + } else { + if (collision.normal.dot(p_floor_direction) >= Math::cos(p_floor_max_angle)) { //floor + + on_floor = true; + on_floor_body = collision.collider_rid; + floor_velocity = collision.collider_vel; + + Vector2 rel_v = lv - floor_velocity; + Vector2 hv = rel_v - p_floor_direction * p_floor_direction.dot(rel_v); + + if (collision.travel.length() < 1 && hv.length() < p_slope_stop_min_velocity) { + Transform2D gt = get_global_transform(); + gt.elements[2] -= collision.travel; + set_global_transform(gt); + return Vector2(); + } + } else if (collision.normal.dot(-p_floor_direction) >= Math::cos(p_floor_max_angle)) { //ceiling + on_ceiling = true; + } else { + on_wall = true; + } } - } - Vector2 n = collision.normal; - motion = motion.slide(n); - lv = lv.slide(n); + Vector2 n = collision.normal; + motion = motion.slide(n); + lv = lv.slide(n); - colliders.push_back(collision); + colliders.push_back(collision); + } + } - } else { + if (!found_collision) { break; } - p_max_slides--; if (motion == Vector2()) break; @@ -1077,6 +1147,31 @@ Vector2 KinematicBody2D::move_and_slide(const Vector2 &p_linear_velocity, const return lv; } +Vector2 KinematicBody2D::move_and_slide_with_snap(const Vector2 &p_linear_velocity, const Vector2 &p_snap, const Vector2 &p_floor_direction, bool p_infinite_inertia, float p_slope_stop_min_velocity, int p_max_slides, float p_floor_max_angle) { + + bool was_on_floor = on_floor; + + Vector2 ret = move_and_slide(p_linear_velocity, p_floor_direction, p_infinite_inertia, p_slope_stop_min_velocity, p_max_slides, p_floor_max_angle); + if (!was_on_floor || p_snap == Vector2()) { + return ret; + } + + Collision col; + Transform2D gt = get_global_transform(); + + if (move_and_collide(p_snap, p_infinite_inertia, col, false, true)) { + gt.elements[2] += col.travel; + if (p_floor_direction != Vector2() && Math::acos(p_floor_direction.normalized().dot(col.normal)) < p_floor_max_angle) { + on_floor = true; + on_floor_body = col.collider_rid; + floor_velocity = col.collider_vel; + } + set_global_transform(gt); + } + + return ret; +} + bool KinematicBody2D::is_on_floor() const { return on_floor; @@ -1138,10 +1233,60 @@ Ref<KinematicCollision2D> KinematicBody2D::_get_slide_collision(int p_bounce) { return slide_colliders[p_bounce]; } +void KinematicBody2D::set_sync_to_physics(bool p_enable) { + + if (sync_to_physics == p_enable) { + return; + } + sync_to_physics = p_enable; + if (p_enable) { + Physics2DServer::get_singleton()->body_set_force_integration_callback(get_rid(), this, "_direct_state_changed"); + set_only_update_transform_changes(true); + set_notify_local_transform(true); + } else { + Physics2DServer::get_singleton()->body_set_force_integration_callback(get_rid(), NULL, ""); + set_only_update_transform_changes(false); + set_notify_local_transform(false); + } +} + +bool KinematicBody2D::is_sync_to_physics_enabled() const { + return sync_to_physics; +} + +void KinematicBody2D::_direct_state_changed(Object *p_state) { + + if (!sync_to_physics) + return; + + Physics2DDirectBodyState *state = Object::cast_to<Physics2DDirectBodyState>(p_state); + + last_valid_transform = state->get_transform(); + set_notify_local_transform(false); + set_global_transform(last_valid_transform); + set_notify_local_transform(true); +} + +void KinematicBody2D::_notification(int p_what) { + if (p_what == NOTIFICATION_ENTER_TREE) { + last_valid_transform = get_global_transform(); + } + + if (p_what == NOTIFICATION_LOCAL_TRANSFORM_CHANGED) { + //used by sync to physics, send the new transform to the physics + Transform2D new_transform = get_global_transform(); + Physics2DServer::get_singleton()->body_set_state(get_rid(), Physics2DServer::BODY_STATE_TRANSFORM, new_transform); + //but then revert changes + set_notify_local_transform(false); + set_global_transform(last_valid_transform); + set_notify_local_transform(true); + } +} void KinematicBody2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("move_and_collide", "rel_vec", "infinite_inertia"), &KinematicBody2D::_move, DEFVAL(true)); + ClassDB::bind_method(D_METHOD("move_and_collide", "rel_vec", "infinite_inertia", "exclude_raycast_shapes", "test_only"), &KinematicBody2D::_move, DEFVAL(true), DEFVAL(true), DEFVAL(false)); ClassDB::bind_method(D_METHOD("move_and_slide", "linear_velocity", "floor_normal", "infinite_inertia", "slope_stop_min_velocity", "max_bounces", "floor_max_angle"), &KinematicBody2D::move_and_slide, DEFVAL(Vector2(0, 0)), DEFVAL(true), DEFVAL(5), DEFVAL(4), DEFVAL(Math::deg2rad((float)45))); + ClassDB::bind_method(D_METHOD("move_and_slide_with_snap", "linear_velocity", "snap", "floor_normal", "infinite_inertia", "slope_stop_min_velocity", "max_bounces", "floor_max_angle"), &KinematicBody2D::move_and_slide_with_snap, DEFVAL(Vector2(0, 0)), DEFVAL(true), DEFVAL(5), DEFVAL(4), DEFVAL(Math::deg2rad((float)45))); ClassDB::bind_method(D_METHOD("test_move", "from", "rel_vec", "infinite_inertia"), &KinematicBody2D::test_move); @@ -1156,7 +1301,13 @@ void KinematicBody2D::_bind_methods() { ClassDB::bind_method(D_METHOD("get_slide_count"), &KinematicBody2D::get_slide_count); ClassDB::bind_method(D_METHOD("get_slide_collision", "slide_idx"), &KinematicBody2D::_get_slide_collision); + ClassDB::bind_method(D_METHOD("set_sync_to_physics", "enable"), &KinematicBody2D::set_sync_to_physics); + ClassDB::bind_method(D_METHOD("is_sync_to_physics_enabled"), &KinematicBody2D::is_sync_to_physics_enabled); + + ClassDB::bind_method(D_METHOD("_direct_state_changed"), &KinematicBody2D::_direct_state_changed); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "collision/safe_margin", PROPERTY_HINT_RANGE, "0.001,256,0.001"), "set_safe_margin", "get_safe_margin"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "motion/sync_to_physics"), "set_sync_to_physics", "is_sync_to_physics_enabled"); } KinematicBody2D::KinematicBody2D() : @@ -1167,6 +1318,7 @@ KinematicBody2D::KinematicBody2D() : on_floor = false; on_ceiling = false; on_wall = false; + sync_to_physics = false; } KinematicBody2D::~KinematicBody2D() { if (motion_cache.is_valid()) { diff --git a/scene/2d/physics_body_2d.h b/scene/2d/physics_body_2d.h index 0fda3c5c05..7bda6ce817 100644 --- a/scene/2d/physics_body_2d.h +++ b/scene/2d/physics_body_2d.h @@ -276,6 +276,7 @@ public: Vector2 normal; Vector2 collider_vel; ObjectID collider; + RID collider_rid; int collider_shape; Variant collider_metadata; Vector2 remainder; @@ -287,29 +288,40 @@ private: float margin; Vector2 floor_velocity; + RID on_floor_body; bool on_floor; bool on_ceiling; bool on_wall; + bool sync_to_physics; + Vector<Collision> colliders; Vector<Ref<KinematicCollision2D> > slide_colliders; Ref<KinematicCollision2D> motion_cache; _FORCE_INLINE_ bool _ignores_mode(Physics2DServer::BodyMode) const; - Ref<KinematicCollision2D> _move(const Vector2 &p_motion, bool p_infinite_inertia = true); + Ref<KinematicCollision2D> _move(const Vector2 &p_motion, bool p_infinite_inertia = true, bool p_exclude_raycast_shapes = true, bool p_test_only = false); Ref<KinematicCollision2D> _get_slide_collision(int p_bounce); + Transform2D last_valid_transform; + void _direct_state_changed(Object *p_state); + protected: + void _notification(int p_what); static void _bind_methods(); public: - bool move_and_collide(const Vector2 &p_motion, bool p_infinite_inertia, Collision &r_collision); + bool move_and_collide(const Vector2 &p_motion, bool p_infinite_inertia, Collision &r_collision, bool p_exclude_raycast_shapes = true, bool p_test_only = false); + bool test_move(const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia); + bool separate_raycast_shapes(bool p_infinite_inertia, Collision &r_collision); + void set_safe_margin(float p_margin); float get_safe_margin() const; Vector2 move_and_slide(const Vector2 &p_linear_velocity, const Vector2 &p_floor_direction = Vector2(0, 0), bool p_infinite_inertia = true, float p_slope_stop_min_velocity = 5, int p_max_slides = 4, float p_floor_max_angle = Math::deg2rad((float)45)); + Vector2 move_and_slide_with_snap(const Vector2 &p_linear_velocity, const Vector2 &p_snap, const Vector2 &p_floor_direction = Vector2(0, 0), bool p_infinite_inertia = true, float p_slope_stop_min_velocity = 5, int p_max_slides = 4, float p_floor_max_angle = Math::deg2rad((float)45)); bool is_on_floor() const; bool is_on_wall() const; bool is_on_ceiling() const; @@ -318,6 +330,9 @@ public: int get_slide_count() const; Collision get_slide_collision(int p_bounce) const; + void set_sync_to_physics(bool p_enable); + bool is_sync_to_physics_enabled() const; + KinematicBody2D(); ~KinematicBody2D(); }; diff --git a/scene/3d/audio_stream_player_3d.cpp b/scene/3d/audio_stream_player_3d.cpp index d46231a677..5f0ac3dd80 100644 --- a/scene/3d/audio_stream_player_3d.cpp +++ b/scene/3d/audio_stream_player_3d.cpp @@ -991,6 +991,7 @@ AudioStreamPlayer3D::AudioStreamPlayer3D() { velocity_tracker.instance(); AudioServer::get_singleton()->connect("bus_layout_changed", this, "_bus_layout_changed"); + set_disable_scale(true); } AudioStreamPlayer3D::~AudioStreamPlayer3D() { } diff --git a/scene/3d/baked_lightmap.cpp b/scene/3d/baked_lightmap.cpp index 204aaef7ec..26fd5ed658 100644 --- a/scene/3d/baked_lightmap.cpp +++ b/scene/3d/baked_lightmap.cpp @@ -811,4 +811,5 @@ BakedLightmap::BakedLightmap() { propagation = 1; hdr = false; image_path = "."; + set_disable_scale(true); } diff --git a/scene/3d/camera.cpp b/scene/3d/camera.cpp index e11e8abe5b..9a2046991b 100644 --- a/scene/3d/camera.cpp +++ b/scene/3d/camera.cpp @@ -613,6 +613,7 @@ Camera::Camera() { velocity_tracker.instance(); doppler_tracking = DOPPLER_TRACKING_DISABLED; set_notify_transform(true); + set_disable_scale(true); } Camera::~Camera() { diff --git a/scene/3d/gi_probe.cpp b/scene/3d/gi_probe.cpp index 4ad2eb60ee..6276d02eff 100644 --- a/scene/3d/gi_probe.cpp +++ b/scene/3d/gi_probe.cpp @@ -557,6 +557,7 @@ GIProbe::GIProbe() { compress = false; gi_probe = VS::get_singleton()->gi_probe_create(); + set_disable_scale(true); } GIProbe::~GIProbe() { diff --git a/scene/3d/light.cpp b/scene/3d/light.cpp index 7c42638107..16164cf3bf 100644 --- a/scene/3d/light.cpp +++ b/scene/3d/light.cpp @@ -306,6 +306,7 @@ Light::Light(VisualServer::LightType p_type) { set_param(PARAM_SHADOW_SPLIT_3_OFFSET, 0.5); set_param(PARAM_SHADOW_NORMAL_BIAS, 0.0); set_param(PARAM_SHADOW_BIAS, 0.15); + set_disable_scale(true); } Light::Light() { diff --git a/scene/3d/physics_body.h b/scene/3d/physics_body.h index 0190dcbfc3..7236eba685 100644 --- a/scene/3d/physics_body.h +++ b/scene/3d/physics_body.h @@ -294,7 +294,7 @@ protected: static void _bind_methods(); public: - bool move_and_collide(const Vector3 &p_motion, bool p_infinite_inertia, Collision &r_collision); + bool move_and_collide(const Vector3 &p_motion, bool p_infinite_inertia, Collision &r_collisionz); bool test_move(const Transform &p_from, const Vector3 &p_motion, bool p_infinite_inertia); void set_axis_lock(PhysicsServer::BodyAxis p_axis, bool p_lock); diff --git a/scene/3d/reflection_probe.cpp b/scene/3d/reflection_probe.cpp index 4d50945062..fe522bbe97 100644 --- a/scene/3d/reflection_probe.cpp +++ b/scene/3d/reflection_probe.cpp @@ -274,6 +274,7 @@ ReflectionProbe::ReflectionProbe() { probe = VisualServer::get_singleton()->reflection_probe_create(); VS::get_singleton()->instance_set_base(get_instance(), probe); + set_disable_scale(true); } ReflectionProbe::~ReflectionProbe() { diff --git a/scene/3d/spatial.cpp b/scene/3d/spatial.cpp index 748aa8aad4..9b27faed6a 100644 --- a/scene/3d/spatial.cpp +++ b/scene/3d/spatial.cpp @@ -280,6 +280,10 @@ Transform Spatial::get_global_transform() const { data.global_transform = data.local_transform; } + if (data.disable_scale) { + data.global_transform.basis.orthonormalize(); + } + data.dirty &= ~DIRTY_GLOBAL; } @@ -467,6 +471,15 @@ void Spatial::set_disable_gizmo(bool p_enabled) { #endif +void Spatial::set_disable_scale(bool p_enabled) { + + data.disable_scale = p_enabled; +} + +bool Spatial::is_scale_disabled() const { + return data.disable_scale; +} + void Spatial::set_as_toplevel(bool p_enabled) { if (data.toplevel == p_enabled) @@ -735,6 +748,8 @@ void Spatial::_bind_methods() { ClassDB::bind_method(D_METHOD("set_ignore_transform_notification", "enabled"), &Spatial::set_ignore_transform_notification); ClassDB::bind_method(D_METHOD("set_as_toplevel", "enable"), &Spatial::set_as_toplevel); ClassDB::bind_method(D_METHOD("is_set_as_toplevel"), &Spatial::is_set_as_toplevel); + ClassDB::bind_method(D_METHOD("set_disable_scale", "disable"), &Spatial::set_disable_scale); + ClassDB::bind_method(D_METHOD("is_scale_disabled"), &Spatial::is_scale_disabled); ClassDB::bind_method(D_METHOD("get_world"), &Spatial::get_world); ClassDB::bind_method(D_METHOD("_update_gizmo"), &Spatial::_update_gizmo); @@ -755,15 +770,6 @@ void Spatial::_bind_methods() { ClassDB::bind_method(D_METHOD("set_notify_transform", "enable"), &Spatial::set_notify_transform); ClassDB::bind_method(D_METHOD("is_transform_notification_enabled"), &Spatial::is_transform_notification_enabled); - void rotate(const Vector3 &p_axis, float p_angle); - void rotate_x(float p_angle); - void rotate_y(float p_angle); - void rotate_z(float p_angle); - void translate(const Vector3 &p_offset); - void scale(const Vector3 &p_ratio); - void global_rotate(const Vector3 &p_axis, float p_angle); - void global_translate(const Vector3 &p_offset); - ClassDB::bind_method(D_METHOD("rotate", "axis", "angle"), &Spatial::rotate); ClassDB::bind_method(D_METHOD("global_rotate", "axis", "angle"), &Spatial::global_rotate); ClassDB::bind_method(D_METHOD("global_scale", "scale"), &Spatial::global_scale); @@ -797,6 +803,7 @@ void Spatial::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "rotation_degrees", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_rotation_degrees", "get_rotation_degrees"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "rotation", PROPERTY_HINT_NONE, "", 0), "set_rotation", "get_rotation"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "scale", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_scale", "get_scale"); + ADD_GROUP("Visibility", ""); ADD_PROPERTYNO(PropertyInfo(Variant::BOOL, "visible"), "set_visible", "is_visible"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "gizmo", PROPERTY_HINT_RESOURCE_TYPE, "SpatialGizmo", 0), "set_gizmo", "get_gizmo"); @@ -817,6 +824,7 @@ Spatial::Spatial() : data.viewport = NULL; data.inside_world = false; data.visible = true; + data.disable_scale = false; #ifdef TOOLS_ENABLED data.gizmo_disabled = false; diff --git a/scene/3d/spatial.h b/scene/3d/spatial.h index a43bed3e4a..653714dc98 100644 --- a/scene/3d/spatial.h +++ b/scene/3d/spatial.h @@ -92,6 +92,7 @@ class Spatial : public Node { bool notify_transform; bool visible; + bool disable_scale; #ifdef TOOLS_ENABLED Ref<SpatialGizmo> gizmo; @@ -153,6 +154,9 @@ public: void set_as_toplevel(bool p_enabled); bool is_set_as_toplevel() const; + void set_disable_scale(bool p_enabled); + bool is_scale_disabled() const; + void set_disable_gizmo(bool p_enabled); void update_gizmo(); void set_gizmo(const Ref<SpatialGizmo> &p_gizmo); diff --git a/scene/3d/voxel_light_baker.cpp b/scene/3d/voxel_light_baker.cpp index 670df5cc7f..ba2807d4e8 100644 --- a/scene/3d/voxel_light_baker.cpp +++ b/scene/3d/voxel_light_baker.cpp @@ -113,7 +113,7 @@ static bool planeBoxOverlap(Vector3 normal, float d, Vector3 maxbox) { rad = fa * boxhalfsize.x + fb * boxhalfsize.z; \ if (min > rad || max < -rad) return false; - /*======================== Z-tests ========================*/ +/*======================== Z-tests ========================*/ #define AXISTEST_Z12(a, b, fa, fb) \ p1 = a * v1.x - b * v1.y; \ @@ -1961,7 +1961,7 @@ Error VoxelLightBaker::make_lightmap(const Transform &p_xform, Ref<Mesh> &p_mesh #endif for (int i = 0; i < height; i++) { - //print_line("bake line " + itos(i) + " / " + itos(height)); + //print_line("bake line " + itos(i) + " / " + itos(height)); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1) #endif diff --git a/scene/animation/animation_blend_space_1d.cpp b/scene/animation/animation_blend_space_1d.cpp index d3d2870c3f..1bc9fa4b12 100644 --- a/scene/animation/animation_blend_space_1d.cpp +++ b/scene/animation/animation_blend_space_1d.cpp @@ -4,10 +4,9 @@ void AnimationNodeBlendSpace1D::set_tree(AnimationTree *p_player) { AnimationRootNode::set_tree(p_player); - for(int i=0;i<blend_points_used;i++) { + for (int i = 0; i < blend_points_used; i++) { blend_points[i].node->set_tree(p_player); } - } void AnimationNodeBlendSpace1D::_validate_property(PropertyInfo &property) const { diff --git a/scene/animation/animation_blend_space_1d.h b/scene/animation/animation_blend_space_1d.h index 774894ef4b..d1ed4c6a1f 100644 --- a/scene/animation/animation_blend_space_1d.h +++ b/scene/animation/animation_blend_space_1d.h @@ -34,7 +34,6 @@ protected: static void _bind_methods(); public: - virtual void set_tree(AnimationTree *p_player); void add_blend_point(const Ref<AnimationRootNode> &p_node, float p_position, int p_at_index = -1); diff --git a/scene/animation/animation_blend_space_2d.cpp b/scene/animation/animation_blend_space_2d.cpp index 82db647124..bba25d64d9 100644 --- a/scene/animation/animation_blend_space_2d.cpp +++ b/scene/animation/animation_blend_space_2d.cpp @@ -4,12 +4,11 @@ void AnimationNodeBlendSpace2D::set_tree(AnimationTree *p_player) { AnimationRootNode::set_tree(p_player); - for(int i=0;i<blend_points_used;i++) { + for (int i = 0; i < blend_points_used; i++) { blend_points[i].node->set_tree(p_player); } } - void AnimationNodeBlendSpace2D::add_blend_point(const Ref<AnimationRootNode> &p_node, const Vector2 &p_position, int p_at_index) { ERR_FAIL_COND(blend_points_used >= MAX_BLEND_POINTS); ERR_FAIL_COND(p_node.is_null()); diff --git a/scene/animation/animation_blend_space_2d.h b/scene/animation/animation_blend_space_2d.h index 4778299df1..74d20b6013 100644 --- a/scene/animation/animation_blend_space_2d.h +++ b/scene/animation/animation_blend_space_2d.h @@ -47,7 +47,6 @@ protected: static void _bind_methods(); public: - virtual void set_tree(AnimationTree *p_player); void add_blend_point(const Ref<AnimationRootNode> &p_node, const Vector2 &p_position, int p_at_index = -1); diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index eac2c8d0c1..111620dac1 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -549,6 +549,12 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float int s = params.size(); ERR_CONTINUE(s > VARIANT_ARG_MAX); +#ifdef DEBUG_ENABLED + if (!nc->node->has_method(method)) { + ERR_PRINTS("Invalid method call '" + method + "'. '" + a->get_name() + "' at node '" + get_path() + "'."); + } +#endif + if (can_call) { MessageQueue::get_singleton()->push_call( nc->node, diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp index 72ed0e9b81..aa52739b0a 100644 --- a/scene/gui/item_list.cpp +++ b/scene/gui/item_list.cpp @@ -285,7 +285,7 @@ void ItemList::unselect_all() { items[i].selected = false; } - + current = -1; update(); } diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp index 9af479c1cc..0b36e1663c 100644 --- a/scene/gui/label.cpp +++ b/scene/gui/label.cpp @@ -75,7 +75,7 @@ void Label::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { - if (clip || autowrap) { + if (clip) { VisualServer::get_singleton()->canvas_item_set_clip(get_canvas_item(), true); } diff --git a/scene/gui/scroll_bar.cpp b/scene/gui/scroll_bar.cpp index 6ec67aca6b..e5bd1c453d 100644 --- a/scene/gui/scroll_bar.cpp +++ b/scene/gui/scroll_bar.cpp @@ -257,9 +257,7 @@ void ScrollBar::_notification(int p_what) { Point2 ofs; - VisualServer *vs = VisualServer::get_singleton(); - - vs->canvas_item_add_texture_rect(ci, Rect2(Point2(), decr->get_size()), decr->get_rid()); + decr->draw(ci, Point2()); if (orientation == HORIZONTAL) ofs.x += decr->get_width(); @@ -280,7 +278,7 @@ void ScrollBar::_notification(int p_what) { else ofs.height += area.height; - vs->canvas_item_add_texture_rect(ci, Rect2(ofs, decr->get_size()), incr->get_rid()); + incr->draw(ci, ofs); Rect2 grabber_rect; if (orientation == HORIZONTAL) { diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 6d18cce21d..e1333bcae2 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -240,7 +240,7 @@ void Node::_propagate_enter_tree() { void Node::_propagate_exit_tree() { -//block while removing children + //block while removing children #ifdef DEBUG_ENABLED diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp index 8dd378c319..8f78e137b4 100644 --- a/scene/register_scene_types.cpp +++ b/scene/register_scene_types.cpp @@ -477,10 +477,10 @@ void register_scene_types() { ClassDB::register_class<VisualShaderNodeVectorLen>(); ClassDB::register_class<VisualShaderNodeScalarInterp>(); ClassDB::register_class<VisualShaderNodeVectorInterp>(); - ClassDB::register_class<VisualShaderNodeVectorConstruct>(); - ClassDB::register_class<VisualShaderNodeTransformConstruct>(); - ClassDB::register_class<VisualShaderNodeVectorDestruct>(); - ClassDB::register_class<VisualShaderNodeTransformDestruct>(); + ClassDB::register_class<VisualShaderNodeVectorCompose>(); + ClassDB::register_class<VisualShaderNodeTransformCompose>(); + ClassDB::register_class<VisualShaderNodeVectorDecompose>(); + ClassDB::register_class<VisualShaderNodeTransformDecompose>(); ClassDB::register_class<VisualShaderNodeTexture>(); ClassDB::register_class<VisualShaderNodeCubeMap>(); ClassDB::register_virtual_class<VisualShaderNodeUniform>(); diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp index e57a2b68c8..8acfdc482a 100644 --- a/scene/resources/animation.cpp +++ b/scene/resources/animation.cpp @@ -2329,13 +2329,14 @@ float Animation::bezier_track_interpolate(int p_track, float p_time) const { int iterations = 10; - float low = 0; - float high = bt->values[idx + 1].time - bt->values[idx].time; + float duration = bt->values[idx + 1].time - bt->values[idx].time; // time duration between our two keyframes + float low = 0; // 0% of the current animation segment + float high = 1; // 100% of the current animation segment float middle = 0; Vector2 start(0, bt->values[idx].value.value); Vector2 start_out = start + bt->values[idx].value.out_handle; - Vector2 end(high, bt->values[idx + 1].value.value); + Vector2 end(duration, bt->values[idx + 1].value.value); Vector2 end_in = end + bt->values[idx + 1].value.in_handle; //narrow high and low as much as possible @@ -2355,7 +2356,6 @@ float Animation::bezier_track_interpolate(int p_track, float p_time) const { //interpolate the result: Vector2 low_pos = _bezier_interp(low, start, start_out, end_in, end); Vector2 high_pos = _bezier_interp(high, start, start_out, end_in, end); - float c = (t - low_pos.x) / (high_pos.x - low_pos.x); return low_pos.linear_interpolate(high_pos, c).y; diff --git a/scene/resources/default_theme/make_header.py b/scene/resources/default_theme/make_header.py index db449f9417..73b1ae0b0b 100755 --- a/scene/resources/default_theme/make_header.py +++ b/scene/resources/default_theme/make_header.py @@ -4,15 +4,16 @@ import os import glob import string +enc = "utf-8" # Generate include files f = open("theme_data.h", "wb") -f.write("// THIS FILE HAS BEEN AUTOGENERATED, DON'T EDIT!!\n") +f.write(b"// THIS FILE HAS BEEN AUTOGENERATED, DON\'T EDIT!!\n") # Generate png image block -f.write("\n// png image block\n"); +f.write(b"\n// png image block\n") pixmaps = glob.glob("*.png") pixmaps.sort() @@ -21,22 +22,23 @@ for x in pixmaps: var_str = x[:-4] + "_png" - f.write("\nstatic const unsigned char " + var_str + "[] = {\n\t") + s = "\nstatic const unsigned char " + var_str + "[] = {\n\t" + f.write(s.encode(enc)) pngf = open(x, "rb") b = pngf.read(1) while(len(b) == 1): - f.write(hex(ord(b))) + f.write(hex(ord(b)).encode(enc)) b = pngf.read(1) if (len(b) == 1): - f.write(", ") + f.write(b", ") - f.write("\n};\n") + f.write(b"\n};\n") pngf.close() # Generate shaders block -f.write("\n// shaders block\n"); +f.write(b"\n// shaders block\n"); shaders = glob.glob("*.gsl") shaders.sort() @@ -45,7 +47,8 @@ for x in shaders: var_str = x[:-4] + "_shader_code" - f.write("\nstatic const char *" + var_str + " = \n") + s = "\nstatic const char *" + var_str + " = \n" + f.write(s.encode(enc)) sf = open(x, "rb") @@ -55,12 +58,13 @@ for x in shaders: b = b[:-2] if (b.endswith("\n")): b = b[:-1] - f.write(" \"" + b) + s = ' \"' + b + f.write(s.encode(enc)) b = sf.readline() if (b != ""): - f.write("\"\n") + f.write(b'"\n') - f.write("\";\n") + f.write(b'";\n') sf.close() f.close() diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index 90e103c96b..56b3ee70bb 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -404,6 +404,9 @@ void SpatialMaterial::_update_shader() { if (flags[FLAG_DONT_RECEIVE_SHADOWS]) { code += ",shadows_disabled"; } + if (flags[FLAG_DISABLE_AMBIENT_LIGHT]) { + code += ",ambient_light_disabled"; + } if (flags[FLAG_ENSURE_CORRECT_NORMALS]) { code += ",ensure_correct_normals"; } @@ -1866,6 +1869,7 @@ void SpatialMaterial::_bind_methods() { ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "flags_fixed_size"), "set_flag", "get_flag", FLAG_FIXED_SIZE); ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "flags_albedo_tex_force_srgb"), "set_flag", "get_flag", FLAG_ALBEDO_TEXTURE_FORCE_SRGB); ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "flags_do_not_receive_shadows"), "set_flag", "get_flag", FLAG_DONT_RECEIVE_SHADOWS); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "flags_disable_ambient_light"), "set_flag", "get_flag", FLAG_DISABLE_AMBIENT_LIGHT); ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "flags_ensure_correct_normals"), "set_flag", "get_flag", FLAG_ENSURE_CORRECT_NORMALS); ADD_GROUP("Vertex Color", "vertex_color"); ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "vertex_color_use_as_albedo"), "set_flag", "get_flag", FLAG_ALBEDO_FROM_VERTEX_COLOR); @@ -2057,6 +2061,7 @@ void SpatialMaterial::_bind_methods() { BIND_ENUM_CONSTANT(FLAG_TRIPLANAR_USE_WORLD); BIND_ENUM_CONSTANT(FLAG_ALBEDO_TEXTURE_FORCE_SRGB); BIND_ENUM_CONSTANT(FLAG_DONT_RECEIVE_SHADOWS); + BIND_ENUM_CONSTANT(FLAG_DISABLE_AMBIENT_LIGHT); BIND_ENUM_CONSTANT(FLAG_ENSURE_CORRECT_NORMALS); BIND_ENUM_CONSTANT(FLAG_MAX); diff --git a/scene/resources/material.h b/scene/resources/material.h index 3b9d1be260..84f1005b03 100644 --- a/scene/resources/material.h +++ b/scene/resources/material.h @@ -192,6 +192,7 @@ public: FLAG_ALBEDO_TEXTURE_FORCE_SRGB, FLAG_DONT_RECEIVE_SHADOWS, FLAG_ENSURE_CORRECT_NORMALS, + FLAG_DISABLE_AMBIENT_LIGHT, FLAG_MAX }; @@ -240,7 +241,7 @@ private: uint64_t blend_mode : 2; uint64_t depth_draw_mode : 2; uint64_t cull_mode : 2; - uint64_t flags : 16; + uint64_t flags : 17; uint64_t detail_blend_mode : 2; uint64_t diffuse_mode : 3; uint64_t specular_mode : 2; diff --git a/scene/resources/visual_shader_nodes.cpp b/scene/resources/visual_shader_nodes.cpp index 90af312870..98ecdbdf30 100644 --- a/scene/resources/visual_shader_nodes.cpp +++ b/scene/resources/visual_shader_nodes.cpp @@ -183,7 +183,7 @@ VisualShaderNodeVec3Constant::VisualShaderNodeVec3Constant() { ////////////// Transform String VisualShaderNodeTransformConstant::get_caption() const { - return "Transform4x3"; + return "Transform"; } int VisualShaderNodeTransformConstant::get_input_port_count() const { @@ -587,6 +587,10 @@ void VisualShaderNodeCubeMap::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "cube_map", PROPERTY_HINT_RESOURCE_TYPE, "CubeMap"), "set_cube_map", "get_cube_map"); ADD_PROPERTY(PropertyInfo(Variant::INT, "texture_type", PROPERTY_HINT_ENUM, "Data,Color,Normalmap"), "set_texture_type", "get_texture_type"); + + BIND_ENUM_CONSTANT(TYPE_DATA); + BIND_ENUM_CONSTANT(TYPE_COLOR); + BIND_ENUM_CONSTANT(TYPE_NORMALMAP); } VisualShaderNodeCubeMap::VisualShaderNodeCubeMap() { @@ -681,7 +685,7 @@ VisualShaderNodeScalarOp::VisualShaderNodeScalarOp() { ////////////// Vector Op String VisualShaderNodeVectorOp::get_caption() const { - return "VecOp"; + return "VectorOp"; } int VisualShaderNodeVectorOp::get_input_port_count() const { @@ -894,6 +898,16 @@ void VisualShaderNodeColorOp::_bind_methods() { ClassDB::bind_method(D_METHOD("get_operator"), &VisualShaderNodeColorOp::get_operator); ADD_PROPERTY(PropertyInfo(Variant::INT, "operator", PROPERTY_HINT_ENUM, "Screen,Difference,Darken,Lighten,Overlay,Dodge,Burn,SoftLight,HardLight"), "set_operator", "get_operator"); + + BIND_ENUM_CONSTANT(OP_SCREEN); + BIND_ENUM_CONSTANT(OP_DIFFERENCE); + BIND_ENUM_CONSTANT(OP_DARKEN); + BIND_ENUM_CONSTANT(OP_LIGHTEN); + BIND_ENUM_CONSTANT(OP_OVERLAY); + BIND_ENUM_CONSTANT(OP_DODGE); + BIND_ENUM_CONSTANT(OP_BURN); + BIND_ENUM_CONSTANT(OP_SOFT_LIGHT); + BIND_ENUM_CONSTANT(OP_HARD_LIGHT); } VisualShaderNodeColorOp::VisualShaderNodeColorOp() { @@ -905,7 +919,7 @@ VisualShaderNodeColorOp::VisualShaderNodeColorOp() { ////////////// Transform Mult String VisualShaderNodeTransformMult::get_caption() const { - return "TransMult"; + return "TransformMult"; } int VisualShaderNodeTransformMult::get_input_port_count() const { @@ -960,6 +974,9 @@ void VisualShaderNodeTransformMult::_bind_methods() { ClassDB::bind_method(D_METHOD("get_operator"), &VisualShaderNodeTransformMult::get_operator); ADD_PROPERTY(PropertyInfo(Variant::INT, "operator", PROPERTY_HINT_ENUM, "A x B,B x A"), "set_operator", "get_operator"); + + BIND_ENUM_CONSTANT(OP_AxB); + BIND_ENUM_CONSTANT(OP_BxA); } VisualShaderNodeTransformMult::VisualShaderNodeTransformMult() { @@ -971,7 +988,7 @@ VisualShaderNodeTransformMult::VisualShaderNodeTransformMult() { ////////////// TransformVec Mult String VisualShaderNodeTransformVecMult::get_caption() const { - return "TransVecMult"; + return "TransformVectorMult"; } int VisualShaderNodeTransformVecMult::get_input_port_count() const { @@ -1150,7 +1167,7 @@ VisualShaderNodeScalarFunc::VisualShaderNodeScalarFunc() { ////////////// Vector Func String VisualShaderNodeVectorFunc::get_caption() const { - return "VecFunc"; + return "VectorFunc"; } int VisualShaderNodeVectorFunc::get_input_port_count() const { @@ -1251,7 +1268,7 @@ VisualShaderNodeVectorFunc::VisualShaderNodeVectorFunc() { ////////////// Dot Product String VisualShaderNodeDotProduct::get_caption() const { - return "DotProd"; + return "DotProduct"; } int VisualShaderNodeDotProduct::get_input_port_count() const { @@ -1286,7 +1303,7 @@ VisualShaderNodeDotProduct::VisualShaderNodeDotProduct() { ////////////// Vector Len String VisualShaderNodeVectorLen::get_caption() const { - return "VecLen"; + return "VectorLen"; } int VisualShaderNodeVectorLen::get_input_port_count() const { @@ -1362,7 +1379,7 @@ VisualShaderNodeScalarInterp::VisualShaderNodeScalarInterp() { ////////////// Vector Interp String VisualShaderNodeVectorInterp::get_caption() const { - return "VecInterp"; + return "VectorInterp"; } int VisualShaderNodeVectorInterp::get_input_port_count() const { @@ -1401,18 +1418,18 @@ VisualShaderNodeVectorInterp::VisualShaderNodeVectorInterp() { set_input_port_default_value(2, Vector3()); } -////////////// Vector Construct -String VisualShaderNodeVectorConstruct::get_caption() const { - return "VecConstr"; +////////////// Vector Compose +String VisualShaderNodeVectorCompose::get_caption() const { + return "VectorCompose"; } -int VisualShaderNodeVectorConstruct::get_input_port_count() const { +int VisualShaderNodeVectorCompose::get_input_port_count() const { return 3; } -VisualShaderNodeVectorConstruct::PortType VisualShaderNodeVectorConstruct::get_input_port_type(int p_port) const { +VisualShaderNodeVectorCompose::PortType VisualShaderNodeVectorCompose::get_input_port_type(int p_port) const { return PORT_TYPE_SCALAR; } -String VisualShaderNodeVectorConstruct::get_input_port_name(int p_port) const { +String VisualShaderNodeVectorCompose::get_input_port_name(int p_port) const { if (p_port == 0) { return "x"; } else if (p_port == 1) { @@ -1422,40 +1439,40 @@ String VisualShaderNodeVectorConstruct::get_input_port_name(int p_port) const { } } -int VisualShaderNodeVectorConstruct::get_output_port_count() const { +int VisualShaderNodeVectorCompose::get_output_port_count() const { return 1; } -VisualShaderNodeVectorConstruct::PortType VisualShaderNodeVectorConstruct::get_output_port_type(int p_port) const { +VisualShaderNodeVectorCompose::PortType VisualShaderNodeVectorCompose::get_output_port_type(int p_port) const { return PORT_TYPE_VECTOR; } -String VisualShaderNodeVectorConstruct::get_output_port_name(int p_port) const { +String VisualShaderNodeVectorCompose::get_output_port_name(int p_port) const { return "vec"; } -String VisualShaderNodeVectorConstruct::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars) const { +String VisualShaderNodeVectorCompose::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars) const { return "\t" + p_output_vars[0] + " = vec3( " + p_input_vars[0] + " , " + p_input_vars[1] + " , " + p_input_vars[2] + " );\n"; } -VisualShaderNodeVectorConstruct::VisualShaderNodeVectorConstruct() { +VisualShaderNodeVectorCompose::VisualShaderNodeVectorCompose() { set_input_port_default_value(0, 0.0); set_input_port_default_value(1, 0.0); set_input_port_default_value(2, 0.0); } -////////////// Transform Construct +////////////// Transform Compose -String VisualShaderNodeTransformConstruct::get_caption() const { - return "TransConstr"; +String VisualShaderNodeTransformCompose::get_caption() const { + return "TransformCompose"; } -int VisualShaderNodeTransformConstruct::get_input_port_count() const { +int VisualShaderNodeTransformCompose::get_input_port_count() const { return 4; } -VisualShaderNodeTransformConstruct::PortType VisualShaderNodeTransformConstruct::get_input_port_type(int p_port) const { +VisualShaderNodeTransformCompose::PortType VisualShaderNodeTransformCompose::get_input_port_type(int p_port) const { return PORT_TYPE_VECTOR; } -String VisualShaderNodeTransformConstruct::get_input_port_name(int p_port) const { +String VisualShaderNodeTransformCompose::get_input_port_name(int p_port) const { if (p_port == 0) { return "x"; } else if (p_port == 1) { @@ -1467,21 +1484,21 @@ String VisualShaderNodeTransformConstruct::get_input_port_name(int p_port) const } } -int VisualShaderNodeTransformConstruct::get_output_port_count() const { +int VisualShaderNodeTransformCompose::get_output_port_count() const { return 1; } -VisualShaderNodeTransformConstruct::PortType VisualShaderNodeTransformConstruct::get_output_port_type(int p_port) const { +VisualShaderNodeTransformCompose::PortType VisualShaderNodeTransformCompose::get_output_port_type(int p_port) const { return PORT_TYPE_TRANSFORM; } -String VisualShaderNodeTransformConstruct::get_output_port_name(int p_port) const { +String VisualShaderNodeTransformCompose::get_output_port_name(int p_port) const { return "xform"; } -String VisualShaderNodeTransformConstruct::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars) const { +String VisualShaderNodeTransformCompose::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars) const { return "\t" + p_output_vars[0] + " = mat4( vec4(" + p_input_vars[0] + ", 0.0) , vec4(" + p_input_vars[1] + ", 0.0) , vec4(" + p_input_vars[2] + ",0.0), vec4(" + p_input_vars[3] + ",1.0) );\n"; } -VisualShaderNodeTransformConstruct::VisualShaderNodeTransformConstruct() { +VisualShaderNodeTransformCompose::VisualShaderNodeTransformCompose() { set_input_port_default_value(0, Vector3()); set_input_port_default_value(1, Vector3()); @@ -1489,28 +1506,28 @@ VisualShaderNodeTransformConstruct::VisualShaderNodeTransformConstruct() { set_input_port_default_value(3, Vector3()); } -////////////// Vector Destruct -String VisualShaderNodeVectorDestruct::get_caption() const { - return "VecDestr"; +////////////// Vector Decompose +String VisualShaderNodeVectorDecompose::get_caption() const { + return "VectorDecompose"; } -int VisualShaderNodeVectorDestruct::get_input_port_count() const { +int VisualShaderNodeVectorDecompose::get_input_port_count() const { return 1; } -VisualShaderNodeVectorDestruct::PortType VisualShaderNodeVectorDestruct::get_input_port_type(int p_port) const { +VisualShaderNodeVectorDecompose::PortType VisualShaderNodeVectorDecompose::get_input_port_type(int p_port) const { return PORT_TYPE_VECTOR; } -String VisualShaderNodeVectorDestruct::get_input_port_name(int p_port) const { +String VisualShaderNodeVectorDecompose::get_input_port_name(int p_port) const { return "vec"; } -int VisualShaderNodeVectorDestruct::get_output_port_count() const { +int VisualShaderNodeVectorDecompose::get_output_port_count() const { return 3; } -VisualShaderNodeVectorDestruct::PortType VisualShaderNodeVectorDestruct::get_output_port_type(int p_port) const { +VisualShaderNodeVectorDecompose::PortType VisualShaderNodeVectorDecompose::get_output_port_type(int p_port) const { return PORT_TYPE_SCALAR; } -String VisualShaderNodeVectorDestruct::get_output_port_name(int p_port) const { +String VisualShaderNodeVectorDecompose::get_output_port_name(int p_port) const { if (p_port == 0) { return "x"; } else if (p_port == 1) { @@ -1520,7 +1537,7 @@ String VisualShaderNodeVectorDestruct::get_output_port_name(int p_port) const { } } -String VisualShaderNodeVectorDestruct::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars) const { +String VisualShaderNodeVectorDecompose::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars) const { String code; code += "\t" + p_output_vars[0] + " = " + p_input_vars[0] + ".x;\n"; code += "\t" + p_output_vars[1] + " = " + p_input_vars[0] + ".y;\n"; @@ -1528,33 +1545,33 @@ String VisualShaderNodeVectorDestruct::generate_code(Shader::Mode p_mode, Visual return code; } -VisualShaderNodeVectorDestruct::VisualShaderNodeVectorDestruct() { +VisualShaderNodeVectorDecompose::VisualShaderNodeVectorDecompose() { set_input_port_default_value(0, Vector3()); } -////////////// Transform Destruct +////////////// Transform Decompose -String VisualShaderNodeTransformDestruct::get_caption() const { - return "TransDestr"; +String VisualShaderNodeTransformDecompose::get_caption() const { + return "TransformDecompose"; } -int VisualShaderNodeTransformDestruct::get_input_port_count() const { +int VisualShaderNodeTransformDecompose::get_input_port_count() const { return 1; } -VisualShaderNodeTransformDestruct::PortType VisualShaderNodeTransformDestruct::get_input_port_type(int p_port) const { +VisualShaderNodeTransformDecompose::PortType VisualShaderNodeTransformDecompose::get_input_port_type(int p_port) const { return PORT_TYPE_TRANSFORM; } -String VisualShaderNodeTransformDestruct::get_input_port_name(int p_port) const { +String VisualShaderNodeTransformDecompose::get_input_port_name(int p_port) const { return "xform"; } -int VisualShaderNodeTransformDestruct::get_output_port_count() const { +int VisualShaderNodeTransformDecompose::get_output_port_count() const { return 4; } -VisualShaderNodeTransformDestruct::PortType VisualShaderNodeTransformDestruct::get_output_port_type(int p_port) const { +VisualShaderNodeTransformDecompose::PortType VisualShaderNodeTransformDecompose::get_output_port_type(int p_port) const { return PORT_TYPE_VECTOR; } -String VisualShaderNodeTransformDestruct::get_output_port_name(int p_port) const { +String VisualShaderNodeTransformDecompose::get_output_port_name(int p_port) const { if (p_port == 0) { return "x"; } else if (p_port == 1) { @@ -1566,7 +1583,7 @@ String VisualShaderNodeTransformDestruct::get_output_port_name(int p_port) const } } -String VisualShaderNodeTransformDestruct::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars) const { +String VisualShaderNodeTransformDecompose::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars) const { String code; code += "\t" + p_output_vars[0] + " = " + p_input_vars[0] + "[0].xyz;\n"; code += "\t" + p_output_vars[1] + " = " + p_input_vars[0] + "[1].xyz;\n"; @@ -1575,7 +1592,7 @@ String VisualShaderNodeTransformDestruct::generate_code(Shader::Mode p_mode, Vis return code; } -VisualShaderNodeTransformDestruct::VisualShaderNodeTransformDestruct() { +VisualShaderNodeTransformDecompose::VisualShaderNodeTransformDecompose() { set_input_port_default_value(0, Transform()); } @@ -1658,7 +1675,7 @@ VisualShaderNodeColorUniform::VisualShaderNodeColorUniform() { ////////////// Vector Uniform String VisualShaderNodeVec3Uniform::get_caption() const { - return "VecUniform"; + return "VectorUniform"; } int VisualShaderNodeVec3Uniform::get_input_port_count() const { @@ -1694,7 +1711,7 @@ VisualShaderNodeVec3Uniform::VisualShaderNodeVec3Uniform() { ////////////// Transform Uniform String VisualShaderNodeTransformUniform::get_caption() const { - return "TransUniform"; + return "TransformUniform"; } int VisualShaderNodeTransformUniform::get_input_port_count() const { @@ -1730,7 +1747,7 @@ VisualShaderNodeTransformUniform::VisualShaderNodeTransformUniform() { ////////////// Texture Uniform String VisualShaderNodeTextureUniform::get_caption() const { - return "TexUniform"; + return "TextureUniform"; } int VisualShaderNodeTextureUniform::get_input_port_count() const { @@ -1848,7 +1865,7 @@ VisualShaderNodeTextureUniform::VisualShaderNodeTextureUniform() { ////////////// CubeMap Uniform String VisualShaderNodeCubeMapUniform::get_caption() const { - return "CubeMap"; + return "CubeMapUniform"; } int VisualShaderNodeCubeMapUniform::get_input_port_count() const { diff --git a/scene/resources/visual_shader_nodes.h b/scene/resources/visual_shader_nodes.h index cf46ee3189..2ede36fbc8 100644 --- a/scene/resources/visual_shader_nodes.h +++ b/scene/resources/visual_shader_nodes.h @@ -621,8 +621,8 @@ public: /////////////////////////////////////// -class VisualShaderNodeVectorConstruct : public VisualShaderNode { - GDCLASS(VisualShaderNodeVectorConstruct, VisualShaderNode) +class VisualShaderNodeVectorCompose : public VisualShaderNode { + GDCLASS(VisualShaderNodeVectorCompose, VisualShaderNode) public: virtual String get_caption() const; @@ -637,13 +637,13 @@ public: virtual String generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars) const; //if no output is connected, the output var passed will be empty. if no input is connected and input is NIL, the input var passed will be empty - VisualShaderNodeVectorConstruct(); + VisualShaderNodeVectorCompose(); }; /////////////////////////////////////// -class VisualShaderNodeTransformConstruct : public VisualShaderNode { - GDCLASS(VisualShaderNodeTransformConstruct, VisualShaderNode) +class VisualShaderNodeTransformCompose : public VisualShaderNode { + GDCLASS(VisualShaderNodeTransformCompose, VisualShaderNode) public: virtual String get_caption() const; @@ -658,13 +658,13 @@ public: virtual String generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars) const; //if no output is connected, the output var passed will be empty. if no input is connected and input is NIL, the input var passed will be empty - VisualShaderNodeTransformConstruct(); + VisualShaderNodeTransformCompose(); }; /////////////////////////////////////// -class VisualShaderNodeVectorDestruct : public VisualShaderNode { - GDCLASS(VisualShaderNodeVectorDestruct, VisualShaderNode) +class VisualShaderNodeVectorDecompose : public VisualShaderNode { + GDCLASS(VisualShaderNodeVectorDecompose, VisualShaderNode) public: virtual String get_caption() const; @@ -679,13 +679,13 @@ public: virtual String generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars) const; //if no output is connected, the output var passed will be empty. if no input is connected and input is NIL, the input var passed will be empty - VisualShaderNodeVectorDestruct(); + VisualShaderNodeVectorDecompose(); }; /////////////////////////////////////// -class VisualShaderNodeTransformDestruct : public VisualShaderNode { - GDCLASS(VisualShaderNodeTransformDestruct, VisualShaderNode) +class VisualShaderNodeTransformDecompose : public VisualShaderNode { + GDCLASS(VisualShaderNodeTransformDecompose, VisualShaderNode) public: virtual String get_caption() const; @@ -700,7 +700,7 @@ public: virtual String generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars) const; //if no output is connected, the output var passed will be empty. if no input is connected and input is NIL, the input var passed will be empty - VisualShaderNodeTransformDestruct(); + VisualShaderNodeTransformDecompose(); }; /////////////////////////////////////// diff --git a/servers/audio_server.cpp b/servers/audio_server.cpp index f2df7119e7..ef794ac380 100644 --- a/servers/audio_server.cpp +++ b/servers/audio_server.cpp @@ -117,6 +117,10 @@ AudioDriver::AudioDriver() { _last_mix_time = 0; _mix_amount = 0; + +#ifdef DEBUG_ENABLED + prof_time = 0; +#endif } AudioDriver *AudioDriverManager::drivers[MAX_DRIVERS]; @@ -184,6 +188,10 @@ void AudioServer::_driver_process(int p_frames, int32_t *p_buffer) { int todo = p_frames; +#ifdef DEBUG_ENABLED + uint64_t prof_ticks = OS::get_singleton()->get_ticks_usec(); +#endif + if (channel_count != get_channel_count()) { // Amount of channels changed due to a device change // reinitialize the buses channels and buffers @@ -234,6 +242,17 @@ void AudioServer::_driver_process(int p_frames, int32_t *p_buffer) { todo -= to_copy; to_mix -= to_copy; } + + // Calculate latency for Performance.AUDIO_OUTPUT_LATENCY + if (OS::get_singleton()) { + uint64_t ticks = OS::get_singleton()->get_ticks_usec(); + output_latency = (ticks - output_latency_ticks) / 1000000.f; + output_latency_ticks = ticks; + } + +#ifdef DEBUG_ENABLED + prof_time += OS::get_singleton()->get_ticks_usec() - prof_ticks; +#endif } void AudioServer::_mix_step() { @@ -307,6 +326,10 @@ void AudioServer::_mix_step() { if (!bus->effects[j].enabled) continue; +#ifdef DEBUG_ENABLED + uint64_t ticks = OS::get_singleton()->get_ticks_usec(); +#endif + for (int k = 0; k < bus->channels.size(); k++) { if (!bus->channels[k].active) @@ -321,6 +344,10 @@ void AudioServer::_mix_step() { continue; SWAP(bus->channels[k].buffer, temp_buffer[k]); } + +#ifdef DEBUG_ENABLED + bus->effects[j].prof_time += OS::get_singleton()->get_ticks_usec() - ticks; +#endif } } @@ -761,6 +788,9 @@ void AudioServer::add_bus_effect(int p_bus, const Ref<AudioEffect> &p_effect, in fx.effect = p_effect; //fx.instance=p_effect->instance(); fx.enabled = true; +#ifdef DEBUG_ENABLED + fx.prof_time = 0; +#endif if (p_at_pos >= buses[p_bus]->effects.size() || p_at_pos < 0) { buses[p_bus]->effects.push_back(fx); @@ -893,6 +923,68 @@ void AudioServer::init() { GLOBAL_DEF("audio/video_delay_compensation_ms", 0); } +void AudioServer::update() { +#ifdef DEBUG_ENABLED + if (ScriptDebugger::get_singleton() && ScriptDebugger::get_singleton()->is_profiling()) { + + // Driver time includes server time + effects times + // Server time includes effects times + uint64_t driver_time = AudioDriver::get_singleton()->get_profiling_time(); + uint64_t server_time = prof_time; + + // Substract the server time from the driver time + if (driver_time > server_time) + driver_time -= server_time; + + Array values; + + for (int i = buses.size() - 1; i >= 0; i--) { + Bus *bus = buses[i]; + if (bus->bypass) + continue; + + for (int j = 0; j < bus->effects.size(); j++) { + if (!bus->effects[j].enabled) + continue; + + values.push_back(String(bus->name) + bus->effects[j].effect->get_name()); + values.push_back(USEC_TO_SEC(bus->effects[j].prof_time)); + + // Substract the effect time from the driver and server times + if (driver_time > bus->effects[j].prof_time) + driver_time -= bus->effects[j].prof_time; + if (server_time > bus->effects[j].prof_time) + server_time -= bus->effects[j].prof_time; + } + } + + values.push_back("audio_server"); + values.push_back(USEC_TO_SEC(server_time)); + values.push_back("audio_driver"); + values.push_back(USEC_TO_SEC(driver_time)); + + ScriptDebugger::get_singleton()->add_profiling_frame_data("audio_thread", values); + } + + // Reset profiling times + for (int i = buses.size() - 1; i >= 0; i--) { + Bus *bus = buses[i]; + if (bus->bypass) + continue; + + for (int j = 0; j < bus->effects.size(); j++) { + if (!bus->effects[j].enabled) + continue; + + bus->effects[j].prof_time = 0; + } + } + + AudioDriver::get_singleton()->reset_profiling_time(); + prof_time = 0; +#endif +} + void AudioServer::load_default_bus_layout() { if (FileAccess::exists("res://default_bus_layout.tres")) { @@ -1178,6 +1270,11 @@ AudioServer::AudioServer() { mix_frames = 0; channel_count = 0; to_mix = 0; + output_latency = 0; + output_latency_ticks = 0; +#ifdef DEBUG_ENABLED + prof_time = 0; +#endif } AudioServer::~AudioServer() { diff --git a/servers/audio_server.h b/servers/audio_server.h index b7fcd9c093..258fd1d9b0 100644 --- a/servers/audio_server.h +++ b/servers/audio_server.h @@ -33,6 +33,7 @@ #include "audio_frame.h" #include "object.h" +#include "os/os.h" #include "servers/audio/audio_effect.h" #include "variant.h" @@ -44,10 +45,23 @@ class AudioDriver { uint64_t _last_mix_time; uint64_t _mix_amount; +#ifdef DEBUG_ENABLED + uint64_t prof_ticks; + uint64_t prof_time; +#endif + protected: void audio_server_process(int p_frames, int32_t *p_buffer, bool p_update_mix_time = true); void update_mix_time(int p_frames); +#ifdef DEBUG_ENABLED + _FORCE_INLINE_ void start_counting_ticks() { prof_ticks = OS::get_singleton()->get_ticks_usec(); } + _FORCE_INLINE_ void stop_counting_ticks() { prof_time += OS::get_singleton()->get_ticks_usec() - prof_ticks; } +#else + _FORCE_INLINE_ void start_counting_ticks() {} + _FORCE_INLINE_ void stop_counting_ticks() {} +#endif + public: double get_mix_time() const; //useful for video -> audio sync @@ -82,6 +96,11 @@ public: SpeakerMode get_speaker_mode_by_total_channels(int p_channels) const; int get_total_channels_by_speaker_mode(SpeakerMode) const; +#ifdef DEBUG_ENABLED + uint64_t get_profiling_time() const { return prof_time; } + void reset_profiling_time() { prof_time = 0; } +#endif + AudioDriver(); virtual ~AudioDriver() {} }; @@ -129,6 +148,9 @@ private: uint32_t buffer_size; uint64_t mix_count; uint64_t mix_frames; +#ifdef DEBUG_ENABLED + uint64_t prof_time; +#endif float channel_disable_threshold_db; uint32_t channel_disable_frames; @@ -166,6 +188,9 @@ private: struct Effect { Ref<AudioEffect> effect; bool enabled; +#ifdef DEBUG_ENABLED + uint64_t prof_time; +#endif }; Vector<Effect> effects; @@ -190,6 +215,9 @@ private: Mutex *audio_data_lock; + float output_latency; + uint64_t output_latency_ticks; + void init_channels_and_buffers(); void _mix_step(); @@ -273,6 +301,7 @@ public: virtual void init(); virtual void finish(); + virtual void update(); virtual void load_default_bus_layout(); /* MISC config */ @@ -306,6 +335,8 @@ public: String get_device(); void set_device(String device); + float get_output_latency() { return output_latency; } + AudioServer(); virtual ~AudioServer(); }; diff --git a/servers/physics_2d/collision_solver_2d_sw.cpp b/servers/physics_2d/collision_solver_2d_sw.cpp index efee98a35a..6ce019f36e 100644 --- a/servers/physics_2d/collision_solver_2d_sw.cpp +++ b/servers/physics_2d/collision_solver_2d_sw.cpp @@ -72,7 +72,7 @@ bool CollisionSolver2DSW::solve_static_line(const Shape2DSW *p_shape_A, const Tr return found; } -bool CollisionSolver2DSW::solve_raycast(const Shape2DSW *p_shape_A, const Transform2D &p_transform_A, const Shape2DSW *p_shape_B, const Transform2D &p_transform_B, CallbackResult p_result_callback, void *p_userdata, bool p_swap_result, Vector2 *sep_axis) { +bool CollisionSolver2DSW::solve_raycast(const Shape2DSW *p_shape_A, const Vector2 &p_motion_A, const Transform2D &p_transform_A, const Shape2DSW *p_shape_B, const Transform2D &p_transform_B, CallbackResult p_result_callback, void *p_userdata, bool p_swap_result, Vector2 *sep_axis) { const RayShape2DSW *ray = static_cast<const RayShape2DSW *>(p_shape_A); if (p_shape_B->get_type() == Physics2DServer::SHAPE_RAY) @@ -80,6 +80,11 @@ bool CollisionSolver2DSW::solve_raycast(const Shape2DSW *p_shape_A, const Transf Vector2 from = p_transform_A.get_origin(); Vector2 to = from + p_transform_A[1] * ray->get_length(); + if (p_motion_A != Vector2()) { + //not the best but should be enough + Vector2 normal = (to - from).normalized(); + to += normal * MAX(0.0, normal.dot(p_motion_A)); + } Vector2 support_A = to; Transform2D invb = p_transform_B.affine_inverse(); @@ -270,9 +275,9 @@ bool CollisionSolver2DSW::solve(const Shape2DSW *p_shape_A, const Transform2D &p } if (swap) { - return solve_raycast(p_shape_B, p_transform_B, p_shape_A, p_transform_A, p_result_callback, p_userdata, true, sep_axis); + return solve_raycast(p_shape_B, p_motion_B, p_transform_B, p_shape_A, p_transform_A, p_result_callback, p_userdata, true, sep_axis); } else { - return solve_raycast(p_shape_A, p_transform_A, p_shape_B, p_transform_B, p_result_callback, p_userdata, false, sep_axis); + return solve_raycast(p_shape_A, p_motion_A, p_transform_A, p_shape_B, p_transform_B, p_result_callback, p_userdata, false, sep_axis); } } else if (concave_B) { diff --git a/servers/physics_2d/collision_solver_2d_sw.h b/servers/physics_2d/collision_solver_2d_sw.h index e39c41fb75..6faa166115 100644 --- a/servers/physics_2d/collision_solver_2d_sw.h +++ b/servers/physics_2d/collision_solver_2d_sw.h @@ -41,7 +41,7 @@ private: static bool solve_static_line(const Shape2DSW *p_shape_A, const Transform2D &p_transform_A, const Shape2DSW *p_shape_B, const Transform2D &p_transform_B, CallbackResult p_result_callback, void *p_userdata, bool p_swap_result); static void concave_callback(void *p_userdata, Shape2DSW *p_convex); static bool solve_concave(const Shape2DSW *p_shape_A, const Transform2D &p_transform_A, const Vector2 &p_motion_A, const Shape2DSW *p_shape_B, const Transform2D &p_transform_B, const Vector2 &p_motion_B, CallbackResult p_result_callback, void *p_userdata, bool p_swap_result, Vector2 *sep_axis = NULL, real_t p_margin_A = 0, real_t p_margin_B = 0); - static bool solve_raycast(const Shape2DSW *p_shape_A, const Transform2D &p_transform_A, const Shape2DSW *p_shape_B, const Transform2D &p_transform_B, CallbackResult p_result_callback, void *p_userdata, bool p_swap_result, Vector2 *sep_axis = NULL); + static bool solve_raycast(const Shape2DSW *p_shape_A, const Vector2 &p_motion_A, const Transform2D &p_transform_A, const Shape2DSW *p_shape_B, const Transform2D &p_transform_B, CallbackResult p_result_callback, void *p_userdata, bool p_swap_result, Vector2 *sep_axis = NULL); public: static bool solve(const Shape2DSW *p_shape_A, const Transform2D &p_transform_A, const Vector2 &p_motion_A, const Shape2DSW *p_shape_B, const Transform2D &p_transform_B, const Vector2 &p_motion_B, CallbackResult p_result_callback, void *p_userdata, Vector2 *sep_axis = NULL, real_t p_margin_A = 0, real_t p_margin_B = 0); diff --git a/servers/physics_2d/physics_2d_server_sw.cpp b/servers/physics_2d/physics_2d_server_sw.cpp index a14fed8184..a473e0beb2 100644 --- a/servers/physics_2d/physics_2d_server_sw.cpp +++ b/servers/physics_2d/physics_2d_server_sw.cpp @@ -962,22 +962,40 @@ void Physics2DServerSW::body_set_pickable(RID p_body, bool p_pickable) { body->set_pickable(p_pickable); } -bool Physics2DServerSW::body_test_motion(RID p_body, const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia, real_t p_margin, MotionResult *r_result) { +bool Physics2DServerSW::body_test_motion(RID p_body, const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia, real_t p_margin, MotionResult *r_result, bool p_exclude_raycast_shapes) { Body2DSW *body = body_owner.get(p_body); ERR_FAIL_COND_V(!body, false); ERR_FAIL_COND_V(!body->get_space(), false); ERR_FAIL_COND_V(body->get_space()->is_locked(), false); - return body->get_space()->test_body_motion(body, p_from, p_motion, p_infinite_inertia, p_margin, r_result); + return body->get_space()->test_body_motion(body, p_from, p_motion, p_infinite_inertia, p_margin, r_result, p_exclude_raycast_shapes); +} + +int Physics2DServerSW::body_test_ray_separation(RID p_body, const Transform2D &p_transform, bool p_infinite_inertia, Vector2 &r_recover_motion, SeparationResult *r_results, int p_result_max, float p_margin) { + + Body2DSW *body = body_owner.get(p_body); + ERR_FAIL_COND_V(!body, false); + ERR_FAIL_COND_V(!body->get_space(), false); + ERR_FAIL_COND_V(body->get_space()->is_locked(), false); + + return body->get_space()->test_body_ray_separation(body, p_transform, p_infinite_inertia, r_recover_motion, r_results, p_result_max, p_margin); } Physics2DDirectBodyState *Physics2DServerSW::body_get_direct_state(RID p_body) { + if ((using_threads && !doing_sync)) { + ERR_EXPLAIN("Body state is inaccessible right now, wait for iteration or physics process notification."); + ERR_FAIL_V(NULL); + } + + if (!body_owner.owns(p_body)) + return NULL; + Body2DSW *body = body_owner.get(p_body); ERR_FAIL_COND_V(!body, NULL); - if ((using_threads && !doing_sync) || body->get_space()->is_locked()) { + if (body->get_space()->is_locked()) { ERR_EXPLAIN("Body state is inaccessible right now, wait for iteration or physics process notification."); ERR_FAIL_V(NULL); diff --git a/servers/physics_2d/physics_2d_server_sw.h b/servers/physics_2d/physics_2d_server_sw.h index 036eb934e1..e5961b9011 100644 --- a/servers/physics_2d/physics_2d_server_sw.h +++ b/servers/physics_2d/physics_2d_server_sw.h @@ -232,7 +232,8 @@ public: virtual void body_set_pickable(RID p_body, bool p_pickable); - virtual bool body_test_motion(RID p_body, const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia, real_t p_margin = 0.001, MotionResult *r_result = NULL); + virtual bool body_test_motion(RID p_body, const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia, real_t p_margin = 0.001, MotionResult *r_result = NULL, bool p_exclude_raycast_shapes = true); + virtual int body_test_ray_separation(RID p_body, const Transform2D &p_transform, bool p_infinite_inertia, Vector2 &r_recover_motion, SeparationResult *r_results, int p_result_max, float p_margin = 0.001); // this function only works on physics process, errors and returns null otherwise virtual Physics2DDirectBodyState *body_get_direct_state(RID p_body); diff --git a/servers/physics_2d/physics_2d_server_wrap_mt.h b/servers/physics_2d/physics_2d_server_wrap_mt.h index a15e8bde8b..3119b930d7 100644 --- a/servers/physics_2d/physics_2d_server_wrap_mt.h +++ b/servers/physics_2d/physics_2d_server_wrap_mt.h @@ -245,10 +245,16 @@ public: FUNC2(body_set_pickable, RID, bool); - bool body_test_motion(RID p_body, const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia, real_t p_margin = 0.001, MotionResult *r_result = NULL) { + bool body_test_motion(RID p_body, const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia, real_t p_margin = 0.001, MotionResult *r_result = NULL, bool p_exclude_raycast_shapes = true) { ERR_FAIL_COND_V(main_thread != Thread::get_caller_id(), false); - return physics_2d_server->body_test_motion(p_body, p_from, p_motion, p_infinite_inertia, p_margin, r_result); + return physics_2d_server->body_test_motion(p_body, p_from, p_motion, p_infinite_inertia, p_margin, r_result, p_exclude_raycast_shapes); + } + + int body_test_ray_separation(RID p_body, const Transform2D &p_transform, bool p_infinite_inertia, Vector2 &r_recover_motion, SeparationResult *r_results, int p_result_max, float p_margin = 0.001) { + + ERR_FAIL_COND_V(main_thread != Thread::get_caller_id(), false); + return physics_2d_server->body_test_ray_separation(p_body, p_transform, p_infinite_inertia, r_recover_motion, r_results, p_result_max, p_margin); } // this function only works on physics process, errors and returns null otherwise diff --git a/servers/physics_2d/space_2d_sw.cpp b/servers/physics_2d/space_2d_sw.cpp index 0e1f74d8d0..6e45951f42 100644 --- a/servers/physics_2d/space_2d_sw.cpp +++ b/servers/physics_2d/space_2d_sw.cpp @@ -487,7 +487,156 @@ int Space2DSW::_cull_aabb_for_body(Body2DSW *p_body, const Rect2 &p_aabb) { return amount; } -bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia, real_t p_margin, Physics2DServer::MotionResult *r_result) { +int Space2DSW::test_body_ray_separation(Body2DSW *p_body, const Transform2D &p_transform, bool p_infinite_inertia, Vector2 &r_recover_motion, Physics2DServer::SeparationResult *r_results, int p_result_max, real_t p_margin) { + + Rect2 body_aabb; + + for (int i = 0; i < p_body->get_shape_count(); i++) { + + if (i == 0) + body_aabb = p_body->get_shape_aabb(i); + else + body_aabb = body_aabb.merge(p_body->get_shape_aabb(i)); + } + + // Undo the currently transform the physics server is aware of and apply the provided one + body_aabb = p_transform.xform(p_body->get_inv_transform().xform(body_aabb)); + body_aabb = body_aabb.grow(p_margin); + + Transform2D body_transform = p_transform; + + for (int i = 0; i < p_result_max; i++) { + //reset results + r_results[i].collision_depth = 0; + } + + int rays_found = 0; + + { + // raycast AND separate + + const int max_results = 32; + int recover_attempts = 4; + Vector2 sr[max_results * 2]; + Physics2DServerSW::CollCbkData cbk; + cbk.max = max_results; + Physics2DServerSW::CollCbkData *cbkptr = &cbk; + CollisionSolver2DSW::CallbackResult cbkres = Physics2DServerSW::_shape_col_cbk; + + do { + + Vector2 recover_motion; + + bool collided = false; + + int amount = _cull_aabb_for_body(p_body, body_aabb); + int ray_index = 0; + + for (int j = 0; j < p_body->get_shape_count(); j++) { + if (p_body->is_shape_set_as_disabled(j)) + continue; + + Shape2DSW *body_shape = p_body->get_shape(j); + + if (body_shape->get_type() != Physics2DServer::SHAPE_RAY) + continue; + + Transform2D body_shape_xform = body_transform * p_body->get_shape_transform(j); + + for (int i = 0; i < amount; i++) { + + const CollisionObject2DSW *col_obj = intersection_query_results[i]; + int shape_idx = intersection_query_subindex_results[i]; + + cbk.amount = 0; + cbk.ptr = sr; + cbk.invalid_by_dir = 0; + + if (CollisionObject2DSW::TYPE_BODY == col_obj->get_type()) { + const Body2DSW *b = static_cast<const Body2DSW *>(col_obj); + if (p_infinite_inertia && Physics2DServer::BODY_MODE_STATIC != b->get_mode() && Physics2DServer::BODY_MODE_KINEMATIC != b->get_mode()) { + continue; + } + } + + if (col_obj->is_shape_set_as_one_way_collision(shape_idx)) { + + cbk.valid_dir = body_shape_xform.get_axis(1).normalized(); + cbk.valid_depth = p_margin; //only valid depth is the collision margin + cbk.invalid_by_dir = 0; + + } else { + cbk.valid_dir = Vector2(); + cbk.valid_depth = 0; + cbk.invalid_by_dir = 0; + } + + Shape2DSW *against_shape = col_obj->get_shape(shape_idx); + if (CollisionSolver2DSW::solve(body_shape, body_shape_xform, Vector2(), against_shape, col_obj->get_transform() * col_obj->get_shape_transform(shape_idx), Vector2(), cbkres, cbkptr, NULL, p_margin)) { + if (cbk.amount > 0) { + collided = true; + } + + if (ray_index < p_result_max) { + Physics2DServer::SeparationResult &result = r_results[ray_index]; + + for (int k = 0; k < cbk.amount; k++) { + Vector2 a = sr[k * 2 + 0]; + Vector2 b = sr[k * 2 + 1]; + + recover_motion += (b - a) * 0.4; + + float depth = a.distance_to(b); + if (depth > result.collision_depth) { + + result.collision_depth = depth; + result.collision_point = b; + result.collision_normal = (b - a).normalized(); + result.collision_local_shape = shape_idx; + result.collider = col_obj->get_self(); + result.collider_id = col_obj->get_instance_id(); + result.collider_metadata = col_obj->get_shape_metadata(shape_idx); + if (col_obj->get_type() == CollisionObject2DSW::TYPE_BODY) { + Body2DSW *body = (Body2DSW *)col_obj; + + Vector2 rel_vec = b - body->get_transform().get_origin(); + result.collider_velocity = Vector2(-body->get_angular_velocity() * rel_vec.y, body->get_angular_velocity() * rel_vec.x) + body->get_linear_velocity(); + } + } + } + } + } + } + + ray_index++; + } + + rays_found = MAX(ray_index, rays_found); + + if (!collided || recover_motion == Vector2()) { + break; + } + + body_transform.elements[2] += recover_motion; + body_aabb.position += recover_motion; + + recover_attempts--; + } while (recover_attempts); + } + + //optimize results (remove non colliding) + for (int i = 0; i < rays_found; i++) { + if (r_results[i].collision_depth == 0) { + rays_found--; + SWAP(r_results[i], r_results[rays_found]); + } + } + + r_recover_motion = body_transform.elements[2] - p_transform.elements[2]; + return rays_found; +} + +bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia, real_t p_margin, Physics2DServer::MotionResult *r_result, bool p_exclude_raycast_shapes) { //give me back regular physics engine logic //this is madness @@ -547,8 +696,12 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co if (p_body->is_shape_set_as_disabled(j)) continue; - Transform2D body_shape_xform = body_transform * p_body->get_shape_transform(j); Shape2DSW *body_shape = p_body->get_shape(j); + if (p_exclude_raycast_shapes && body_shape->get_type() == Physics2DServer::SHAPE_RAY) { + continue; + } + + Transform2D body_shape_xform = body_transform * p_body->get_shape_transform(j); for (int i = 0; i < amount; i++) { const CollisionObject2DSW *col_obj = intersection_query_results[i]; @@ -635,8 +788,12 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co if (p_body->is_shape_set_as_disabled(body_shape_idx)) continue; - Transform2D body_shape_xform = body_transform * p_body->get_shape_transform(body_shape_idx); Shape2DSW *body_shape = p_body->get_shape(body_shape_idx); + if (p_exclude_raycast_shapes && body_shape->get_type() == Physics2DServer::SHAPE_RAY) { + continue; + } + + Transform2D body_shape_xform = body_transform * p_body->get_shape_transform(body_shape_idx); bool stuck = false; diff --git a/servers/physics_2d/space_2d_sw.h b/servers/physics_2d/space_2d_sw.h index 79349c46f3..959e15e12d 100644 --- a/servers/physics_2d/space_2d_sw.h +++ b/servers/physics_2d/space_2d_sw.h @@ -182,7 +182,8 @@ public: int get_collision_pairs() const { return collision_pairs; } - bool test_body_motion(Body2DSW *p_body, const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia, real_t p_margin, Physics2DServer::MotionResult *r_result); + bool test_body_motion(Body2DSW *p_body, const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia, real_t p_margin, Physics2DServer::MotionResult *r_result, bool p_exclude_raycast_shapes = true); + int test_body_ray_separation(Body2DSW *p_body, const Transform2D &p_transform, bool p_infinite_inertia, Vector2 &r_recover_motion, Physics2DServer::SeparationResult *r_results, int p_result_max, real_t p_margin); void set_debug_contacts(int p_amount) { contact_debug.resize(p_amount); } _FORCE_INLINE_ bool is_debugging_contacts() const { return !contact_debug.empty(); } diff --git a/servers/physics_2d_server.h b/servers/physics_2d_server.h index ba5232f7fe..1d04fbc5c6 100644 --- a/servers/physics_2d_server.h +++ b/servers/physics_2d_server.h @@ -479,7 +479,22 @@ public: Variant collider_metadata; }; - virtual bool body_test_motion(RID p_body, const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia, float p_margin = 0.001, MotionResult *r_result = NULL) = 0; + virtual bool body_test_motion(RID p_body, const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia, float p_margin = 0.001, MotionResult *r_result = NULL, bool p_exclude_raycast_shapes = true) = 0; + + struct SeparationResult { + + float collision_depth; + Vector2 collision_point; + Vector2 collision_normal; + Vector2 collider_velocity; + int collision_local_shape; + ObjectID collider_id; + RID collider; + int collider_shape; + Variant collider_metadata; + }; + + virtual int body_test_ray_separation(RID p_body, const Transform2D &p_transform, bool p_infinite_inertia, Vector2 &r_recover_motion, SeparationResult *r_results, int p_result_max, float p_margin = 0.001) = 0; /* JOINT API */ diff --git a/servers/visual/shader_language.cpp b/servers/visual/shader_language.cpp index 346b04f070..fd1eb77143 100644 --- a/servers/visual/shader_language.cpp +++ b/servers/visual/shader_language.cpp @@ -2545,7 +2545,9 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons TkPos pos = _get_tkpos(); tk = _get_token(); - if (tk.type == TK_PERIOD) { + if (tk.type == TK_CURSOR) { + //do nothing + } else if (tk.type == TK_PERIOD) { StringName identifier; if (_get_completable_identifier(p_block, COMPLETION_INDEX, identifier)) { @@ -4130,8 +4132,8 @@ Error ShaderLanguage::complete(const String &p_code, const Map<StringName, Funct switch (completion_type) { case COMPLETION_NONE: { - //do none - return ERR_PARSE_ERROR; + //do nothing + return OK; } break; case COMPLETION_RENDER_MODE: { for (int i = 0; i < p_render_modes.size(); i++) { diff --git a/servers/visual/shader_types.cpp b/servers/visual/shader_types.cpp index 92786ea740..0de8676f32 100644 --- a/servers/visual/shader_types.cpp +++ b/servers/visual/shader_types.cpp @@ -176,6 +176,7 @@ ShaderTypes::ShaderTypes() { shader_modes[VS::SHADER_SPATIAL].modes.push_back("ensure_correct_normals"); shader_modes[VS::SHADER_SPATIAL].modes.push_back("shadows_disabled"); + shader_modes[VS::SHADER_SPATIAL].modes.push_back("ambient_light_disabled"); shader_modes[VS::SHADER_SPATIAL].modes.push_back("vertex_lighting"); |