summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/bind/core_bind.cpp12
-rw-r--r--core/bind/core_bind.h4
-rw-r--r--core/class_db.cpp18
-rw-r--r--core/crypto/aes_context.cpp116
-rw-r--r--core/crypto/aes_context.h68
-rw-r--r--core/crypto/crypto.cpp43
-rw-r--r--core/crypto/crypto.h19
-rw-r--r--core/crypto/crypto_core.cpp10
-rw-r--r--core/crypto/crypto_core.h2
-rw-r--r--core/error_macros.h8
-rw-r--r--core/image.cpp22
-rw-r--r--core/input/input_map.cpp8
-rw-r--r--core/input/input_map.h4
-rw-r--r--core/io/dtls_server.cpp5
-rw-r--r--core/io/file_access_buffered.h10
-rw-r--r--core/io/packet_peer_dtls.cpp5
-rw-r--r--core/math/a_star.cpp14
-rw-r--r--core/math/basis.cpp214
-rw-r--r--core/math/basis.h13
-rw-r--r--core/math/expression.cpp4
-rw-r--r--core/math/transform_2d.cpp7
-rw-r--r--core/object.cpp18
-rw-r--r--core/object.h1
-rw-r--r--core/os/os.cpp10
-rw-r--r--core/os/os.h4
-rw-r--r--core/register_core_types.cpp2
-rw-r--r--core/resource.cpp17
-rw-r--r--core/undo_redo.cpp2
-rw-r--r--core/ustring.cpp31
-rw-r--r--core/variant_call.cpp12
-rw-r--r--core/variant_parser.cpp79
31 files changed, 588 insertions, 194 deletions
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp
index e81351a3a6..267391c4d6 100644
--- a/core/bind/core_bind.cpp
+++ b/core/bind/core_bind.cpp
@@ -498,18 +498,10 @@ Dictionary _OS::get_time_zone_info() const {
return infod;
}
-uint64_t _OS::get_unix_time() const {
+double _OS::get_unix_time() const {
return OS::get_singleton()->get_unix_time();
}
-uint64_t _OS::get_system_time_secs() const {
- return OS::get_singleton()->get_system_time_secs();
-}
-
-uint64_t _OS::get_system_time_msecs() const {
- return OS::get_singleton()->get_system_time_msecs();
-}
-
void _OS::delay_usec(uint32_t p_usec) const {
OS::get_singleton()->delay_usec(p_usec);
}
@@ -729,8 +721,6 @@ void _OS::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_unix_time"), &_OS::get_unix_time);
ClassDB::bind_method(D_METHOD("get_datetime_from_unix_time", "unix_time_val"), &_OS::get_datetime_from_unix_time);
ClassDB::bind_method(D_METHOD("get_unix_time_from_datetime", "datetime"), &_OS::get_unix_time_from_datetime);
- ClassDB::bind_method(D_METHOD("get_system_time_secs"), &_OS::get_system_time_secs);
- ClassDB::bind_method(D_METHOD("get_system_time_msecs"), &_OS::get_system_time_msecs);
ClassDB::bind_method(D_METHOD("get_exit_code"), &_OS::get_exit_code);
ClassDB::bind_method(D_METHOD("set_exit_code", "code"), &_OS::set_exit_code);
diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h
index 26d0f7b8af..f9f5a4e7d7 100644
--- a/core/bind/core_bind.h
+++ b/core/bind/core_bind.h
@@ -199,9 +199,7 @@ public:
Dictionary get_datetime_from_unix_time(int64_t unix_time_val) const;
int64_t get_unix_time_from_datetime(Dictionary datetime) const;
Dictionary get_time_zone_info() const;
- uint64_t get_unix_time() const;
- uint64_t get_system_time_secs() const;
- uint64_t get_system_time_msecs() const;
+ double get_unix_time() const;
uint64_t get_static_memory_usage() const;
uint64_t get_static_memory_peak_usage() const;
diff --git a/core/class_db.cpp b/core/class_db.cpp
index eed9ec17cb..05c9850c39 100644
--- a/core/class_db.cpp
+++ b/core/class_db.cpp
@@ -1386,7 +1386,23 @@ Variant ClassDB::class_get_default_property_value(const StringName &p_class, con
if (r_valid != nullptr) {
*r_valid = true;
}
- return default_values[p_class][p_property];
+
+ Variant var = default_values[p_class][p_property];
+
+#ifdef DEBUG_ENABLED
+ // Some properties may have an instantiated Object as default value,
+ // (like Path2D's `curve` used to have), but that's not a good practice.
+ // Instead, those properties should use PROPERTY_USAGE_EDITOR_INSTANTIATE_OBJECT
+ // to be auto-instantiated when created in the editor.
+ if (var.get_type() == Variant::OBJECT) {
+ Object *obj = var.get_validated_object();
+ if (obj) {
+ WARN_PRINT(vformat("Instantiated %s used as default value for %s's \"%s\" property.", obj->get_class(), p_class, p_property));
+ }
+ }
+#endif
+
+ return var;
}
RWLock *ClassDB::lock = nullptr;
diff --git a/core/crypto/aes_context.cpp b/core/crypto/aes_context.cpp
new file mode 100644
index 0000000000..8ef1f4f1d4
--- /dev/null
+++ b/core/crypto/aes_context.cpp
@@ -0,0 +1,116 @@
+/*************************************************************************/
+/* aes_context.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 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 "core/crypto/aes_context.h"
+
+Error AESContext::start(Mode p_mode, PackedByteArray p_key, PackedByteArray p_iv) {
+ ERR_FAIL_COND_V_MSG(mode != MODE_MAX, ERR_ALREADY_IN_USE, "AESContext already started. Call 'finish' before starting a new one.");
+ ERR_FAIL_COND_V_MSG(p_mode < 0 || p_mode >= MODE_MAX, ERR_INVALID_PARAMETER, "Invalid mode requested.");
+ // Key check.
+ int key_bits = p_key.size() << 3;
+ ERR_FAIL_COND_V_MSG(key_bits != 128 && key_bits != 256, ERR_INVALID_PARAMETER, "AES key must be either 16 or 32 bytes");
+ // Initialization vector.
+ if (p_mode == MODE_CBC_ENCRYPT || p_mode == MODE_CBC_DECRYPT) {
+ ERR_FAIL_COND_V_MSG(p_iv.size() != 16, ERR_INVALID_PARAMETER, "The initialization vector (IV) must be exactly 16 bytes.");
+ iv.resize(0);
+ iv.append_array(p_iv);
+ }
+ // Encryption/decryption key.
+ if (p_mode == MODE_CBC_ENCRYPT || p_mode == MODE_ECB_ENCRYPT) {
+ ctx.set_encode_key(p_key.ptr(), key_bits);
+ } else {
+ ctx.set_decode_key(p_key.ptr(), key_bits);
+ }
+ mode = p_mode;
+ return OK;
+}
+
+PackedByteArray AESContext::update(PackedByteArray p_src) {
+ ERR_FAIL_COND_V_MSG(mode < 0 || mode >= MODE_MAX, PackedByteArray(), "AESContext not started. Call 'start' before calling 'update'.");
+ int len = p_src.size();
+ ERR_FAIL_COND_V_MSG(len % 16, PackedByteArray(), "The number of bytes to be encrypted must be multiple of 16. Add padding if needed");
+ PackedByteArray out;
+ out.resize(len);
+ const uint8_t *src_ptr = p_src.ptr();
+ uint8_t *out_ptr = out.ptrw();
+ switch (mode) {
+ case MODE_ECB_ENCRYPT: {
+ for (int i = 0; i < len; i += 16) {
+ Error err = ctx.encrypt_ecb(src_ptr + i, out_ptr + i);
+ ERR_FAIL_COND_V(err != OK, PackedByteArray());
+ }
+ } break;
+ case MODE_ECB_DECRYPT: {
+ for (int i = 0; i < len; i += 16) {
+ Error err = ctx.decrypt_ecb(src_ptr + i, out_ptr + i);
+ ERR_FAIL_COND_V(err != OK, PackedByteArray());
+ }
+ } break;
+ case MODE_CBC_ENCRYPT: {
+ Error err = ctx.encrypt_cbc(len, iv.ptrw(), p_src.ptr(), out.ptrw());
+ ERR_FAIL_COND_V(err != OK, PackedByteArray());
+ } break;
+ case MODE_CBC_DECRYPT: {
+ Error err = ctx.decrypt_cbc(len, iv.ptrw(), p_src.ptr(), out.ptrw());
+ ERR_FAIL_COND_V(err != OK, PackedByteArray());
+ } break;
+ default:
+ ERR_FAIL_V_MSG(PackedByteArray(), "Bug!");
+ }
+ return out;
+}
+
+PackedByteArray AESContext::get_iv_state() {
+ ERR_FAIL_COND_V_MSG(mode != MODE_CBC_ENCRYPT && mode != MODE_CBC_DECRYPT, PackedByteArray(), "Calling 'get_iv_state' only makes sense when the context is started in CBC mode.");
+ PackedByteArray out;
+ out.append_array(iv);
+ return out;
+}
+
+void AESContext::finish() {
+ mode = MODE_MAX;
+ iv.resize(0);
+}
+
+void AESContext::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("start", "mode", "key", "iv"), &AESContext::start, DEFVAL(PackedByteArray()));
+ ClassDB::bind_method(D_METHOD("update", "src"), &AESContext::update);
+ ClassDB::bind_method(D_METHOD("get_iv_state"), &AESContext::get_iv_state);
+ ClassDB::bind_method(D_METHOD("finish"), &AESContext::finish);
+ BIND_ENUM_CONSTANT(MODE_ECB_ENCRYPT);
+ BIND_ENUM_CONSTANT(MODE_ECB_DECRYPT);
+ BIND_ENUM_CONSTANT(MODE_CBC_ENCRYPT);
+ BIND_ENUM_CONSTANT(MODE_CBC_DECRYPT);
+ BIND_ENUM_CONSTANT(MODE_MAX);
+}
+
+AESContext::AESContext() {
+ mode = MODE_MAX;
+}
diff --git a/core/crypto/aes_context.h b/core/crypto/aes_context.h
new file mode 100644
index 0000000000..006ecee2ad
--- /dev/null
+++ b/core/crypto/aes_context.h
@@ -0,0 +1,68 @@
+/*************************************************************************/
+/* aes_context.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 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 AES_CONTEXT_H
+#define AES_CONTEXT_H
+
+#include "core/crypto/crypto_core.h"
+#include "core/reference.h"
+
+class AESContext : public Reference {
+ GDCLASS(AESContext, Reference);
+
+public:
+ enum Mode {
+ MODE_ECB_ENCRYPT,
+ MODE_ECB_DECRYPT,
+ MODE_CBC_ENCRYPT,
+ MODE_CBC_DECRYPT,
+ MODE_MAX
+ };
+
+private:
+ Mode mode;
+ CryptoCore::AESContext ctx;
+ PackedByteArray iv;
+
+protected:
+ static void _bind_methods();
+
+public:
+ Error start(Mode p_mode, PackedByteArray p_key, PackedByteArray p_iv = PackedByteArray());
+ PackedByteArray update(PackedByteArray p_src);
+ PackedByteArray get_iv_state();
+ void finish();
+
+ AESContext();
+};
+
+VARIANT_ENUM_CAST(AESContext::Mode);
+
+#endif // AES_CONTEXT_H
diff --git a/core/crypto/crypto.cpp b/core/crypto/crypto.cpp
index eb942c60c9..29d02e11df 100644
--- a/core/crypto/crypto.cpp
+++ b/core/crypto/crypto.cpp
@@ -45,8 +45,11 @@ CryptoKey *CryptoKey::create() {
}
void CryptoKey::_bind_methods() {
- ClassDB::bind_method(D_METHOD("save", "path"), &CryptoKey::save);
- ClassDB::bind_method(D_METHOD("load", "path"), &CryptoKey::load);
+ ClassDB::bind_method(D_METHOD("save", "path", "public_only"), &CryptoKey::save, DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("load", "path", "public_only"), &CryptoKey::load, DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("is_public_only"), &CryptoKey::is_public_only);
+ ClassDB::bind_method(D_METHOD("save_to_string", "public_only"), &CryptoKey::save_to_string, DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("load_from_string", "string_key", "public_only"), &CryptoKey::load_from_string, DEFVAL(false));
}
X509Certificate *(*X509Certificate::_create)() = nullptr;
@@ -70,7 +73,7 @@ Crypto *Crypto::create() {
if (_create) {
return _create();
}
- return memnew(Crypto);
+ ERR_FAIL_V_MSG(nullptr, "Crypto is not available when the mbedtls module is disabled.");
}
void Crypto::load_default_certificates(String p_path) {
@@ -83,18 +86,10 @@ void Crypto::_bind_methods() {
ClassDB::bind_method(D_METHOD("generate_random_bytes", "size"), &Crypto::generate_random_bytes);
ClassDB::bind_method(D_METHOD("generate_rsa", "size"), &Crypto::generate_rsa);
ClassDB::bind_method(D_METHOD("generate_self_signed_certificate", "key", "issuer_name", "not_before", "not_after"), &Crypto::generate_self_signed_certificate, DEFVAL("CN=myserver,O=myorganisation,C=IT"), DEFVAL("20140101000000"), DEFVAL("20340101000000"));
-}
-
-PackedByteArray Crypto::generate_random_bytes(int p_bytes) {
- ERR_FAIL_V_MSG(PackedByteArray(), "generate_random_bytes is not available when mbedtls module is disabled.");
-}
-
-Ref<CryptoKey> Crypto::generate_rsa(int p_bytes) {
- ERR_FAIL_V_MSG(nullptr, "generate_rsa is not available when mbedtls module is disabled.");
-}
-
-Ref<X509Certificate> Crypto::generate_self_signed_certificate(Ref<CryptoKey> p_key, String p_issuer_name, String p_not_before, String p_not_after) {
- ERR_FAIL_V_MSG(nullptr, "generate_self_signed_certificate is not available when mbedtls module is disabled.");
+ ClassDB::bind_method(D_METHOD("sign", "hash_type", "hash", "key"), &Crypto::sign);
+ ClassDB::bind_method(D_METHOD("verify", "hash_type", "hash", "signature", "key"), &Crypto::verify);
+ ClassDB::bind_method(D_METHOD("encrypt", "key", "plaintext"), &Crypto::encrypt);
+ ClassDB::bind_method(D_METHOD("decrypt", "key", "ciphertext"), &Crypto::decrypt);
}
/// Resource loader/saver
@@ -110,9 +105,14 @@ RES ResourceFormatLoaderCrypto::load(const String &p_path, const String &p_origi
} else if (el == "key") {
CryptoKey *key = CryptoKey::create();
if (key) {
- key->load(p_path);
+ key->load(p_path, false);
}
return key;
+ } else if (el == "pub") {
+ CryptoKey *key = CryptoKey::create();
+ if (key)
+ key->load(p_path, true);
+ return key;
}
return nullptr;
}
@@ -120,6 +120,7 @@ RES ResourceFormatLoaderCrypto::load(const String &p_path, const String &p_origi
void ResourceFormatLoaderCrypto::get_recognized_extensions(List<String> *p_extensions) const {
p_extensions->push_back("crt");
p_extensions->push_back("key");
+ p_extensions->push_back("pub");
}
bool ResourceFormatLoaderCrypto::handles_type(const String &p_type) const {
@@ -130,7 +131,7 @@ String ResourceFormatLoaderCrypto::get_resource_type(const String &p_path) const
String el = p_path.get_extension().to_lower();
if (el == "crt") {
return "X509Certificate";
- } else if (el == "key") {
+ } else if (el == "key" || el == "pub") {
return "CryptoKey";
}
return "";
@@ -143,7 +144,8 @@ Error ResourceFormatSaverCrypto::save(const String &p_path, const RES &p_resourc
if (cert.is_valid()) {
err = cert->save(p_path);
} else if (key.is_valid()) {
- err = key->save(p_path);
+ String el = p_path.get_extension().to_lower();
+ err = key->save(p_path, el == "pub");
} else {
ERR_FAIL_V(ERR_INVALID_PARAMETER);
}
@@ -158,7 +160,10 @@ void ResourceFormatSaverCrypto::get_recognized_extensions(const RES &p_resource,
p_extensions->push_back("crt");
}
if (key) {
- p_extensions->push_back("key");
+ if (!key->is_public_only()) {
+ p_extensions->push_back("key");
+ }
+ p_extensions->push_back("pub");
}
}
diff --git a/core/crypto/crypto.h b/core/crypto/crypto.h
index cf21648a4a..916f7798eb 100644
--- a/core/crypto/crypto.h
+++ b/core/crypto/crypto.h
@@ -31,6 +31,7 @@
#ifndef CRYPTO_H
#define CRYPTO_H
+#include "core/crypto/hashing_context.h"
#include "core/io/resource_loader.h"
#include "core/io/resource_saver.h"
#include "core/reference.h"
@@ -45,8 +46,11 @@ protected:
public:
static CryptoKey *create();
- virtual Error load(String p_path) = 0;
- virtual Error save(String p_path) = 0;
+ virtual Error load(String p_path, bool p_public_only = false) = 0;
+ virtual Error save(String p_path, bool p_public_only = false) = 0;
+ virtual String save_to_string(bool p_public_only = false) = 0;
+ virtual Error load_from_string(String p_string_key, bool p_public_only = false) = 0;
+ virtual bool is_public_only() const = 0;
};
class X509Certificate : public Resource {
@@ -75,9 +79,14 @@ public:
static Crypto *create();
static void load_default_certificates(String p_path);
- virtual PackedByteArray generate_random_bytes(int p_bytes);
- virtual Ref<CryptoKey> generate_rsa(int p_bytes);
- virtual Ref<X509Certificate> generate_self_signed_certificate(Ref<CryptoKey> p_key, String p_issuer_name, String p_not_before, String p_not_after);
+ virtual PackedByteArray generate_random_bytes(int p_bytes) = 0;
+ virtual Ref<CryptoKey> generate_rsa(int p_bytes) = 0;
+ virtual Ref<X509Certificate> generate_self_signed_certificate(Ref<CryptoKey> p_key, String p_issuer_name, String p_not_before, String p_not_after) = 0;
+
+ virtual Vector<uint8_t> sign(HashingContext::HashType p_hash_type, Vector<uint8_t> p_hash, Ref<CryptoKey> p_key) = 0;
+ virtual bool verify(HashingContext::HashType p_hash_type, Vector<uint8_t> p_hash, Vector<uint8_t> p_signature, Ref<CryptoKey> p_key) = 0;
+ virtual Vector<uint8_t> encrypt(Ref<CryptoKey> p_key, Vector<uint8_t> p_plaintext) = 0;
+ virtual Vector<uint8_t> decrypt(Ref<CryptoKey> p_key, Vector<uint8_t> p_ciphertext) = 0;
Crypto() {}
};
diff --git a/core/crypto/crypto_core.cpp b/core/crypto/crypto_core.cpp
index ec25ee0d38..b0dc47e655 100644
--- a/core/crypto/crypto_core.cpp
+++ b/core/crypto/crypto_core.cpp
@@ -145,6 +145,16 @@ Error CryptoCore::AESContext::decrypt_ecb(const uint8_t p_src[16], uint8_t r_dst
return ret ? FAILED : OK;
}
+Error CryptoCore::AESContext::encrypt_cbc(size_t p_length, uint8_t r_iv[16], const uint8_t *p_src, uint8_t *r_dst) {
+ int ret = mbedtls_aes_crypt_cbc((mbedtls_aes_context *)ctx, MBEDTLS_AES_ENCRYPT, p_length, r_iv, p_src, r_dst);
+ return ret ? FAILED : OK;
+}
+
+Error CryptoCore::AESContext::decrypt_cbc(size_t p_length, uint8_t r_iv[16], const uint8_t *p_src, uint8_t *r_dst) {
+ int ret = mbedtls_aes_crypt_cbc((mbedtls_aes_context *)ctx, MBEDTLS_AES_DECRYPT, p_length, r_iv, p_src, r_dst);
+ return ret ? FAILED : OK;
+}
+
// CryptoCore
String CryptoCore::b64_encode_str(const uint8_t *p_src, int p_src_len) {
int b64len = p_src_len / 3 * 4 + 4 + 1;
diff --git a/core/crypto/crypto_core.h b/core/crypto/crypto_core.h
index 36d8ace723..82df9c23a8 100644
--- a/core/crypto/crypto_core.h
+++ b/core/crypto/crypto_core.h
@@ -86,6 +86,8 @@ public:
Error set_decode_key(const uint8_t *p_key, size_t p_bits);
Error encrypt_ecb(const uint8_t p_src[16], uint8_t r_dst[16]);
Error decrypt_ecb(const uint8_t p_src[16], uint8_t r_dst[16]);
+ Error encrypt_cbc(size_t p_length, uint8_t r_iv[16], const uint8_t *p_src, uint8_t *r_dst);
+ Error decrypt_cbc(size_t p_length, uint8_t r_iv[16], const uint8_t *p_src, uint8_t *r_dst);
};
static String b64_encode_str(const uint8_t *p_src, int p_src_len);
diff --git a/core/error_macros.h b/core/error_macros.h
index 46a1623115..d7366be453 100644
--- a/core/error_macros.h
+++ b/core/error_macros.h
@@ -285,7 +285,7 @@ void _err_print_index_error(const char *p_function, const char *p_file, int p_li
* If it is null, the current function returns.
*/
#define ERR_FAIL_NULL(m_param) \
- if (unlikely(!m_param)) { \
+ if (unlikely(m_param == nullptr)) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter \"" _STR(m_param) "\" is null."); \
return; \
} else \
@@ -296,7 +296,7 @@ void _err_print_index_error(const char *p_function, const char *p_file, int p_li
* If it is null, prints `m_msg` and the current function returns.
*/
#define ERR_FAIL_NULL_MSG(m_param, m_msg) \
- if (unlikely(!m_param)) { \
+ if (unlikely(m_param == nullptr)) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter \"" _STR(m_param) "\" is null.", DEBUG_STR(m_msg)); \
return; \
} else \
@@ -310,7 +310,7 @@ void _err_print_index_error(const char *p_function, const char *p_file, int p_li
* If it is null, the current function returns `m_retval`.
*/
#define ERR_FAIL_NULL_V(m_param, m_retval) \
- if (unlikely(!m_param)) { \
+ if (unlikely(m_param == nullptr)) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter \"" _STR(m_param) "\" is null."); \
return m_retval; \
} else \
@@ -321,7 +321,7 @@ void _err_print_index_error(const char *p_function, const char *p_file, int p_li
* If it is null, prints `m_msg` and the current function returns `m_retval`.
*/
#define ERR_FAIL_NULL_V_MSG(m_param, m_retval, m_msg) \
- if (unlikely(!m_param)) { \
+ if (unlikely(m_param == nullptr)) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter \"" _STR(m_param) "\" is null.", DEBUG_STR(m_msg)); \
return m_retval; \
} else \
diff --git a/core/image.cpp b/core/image.cpp
index 4ab71128cd..0f15574053 100644
--- a/core/image.cpp
+++ b/core/image.cpp
@@ -2539,12 +2539,11 @@ void Image::blend_rect(const Ref<Image> &p_src, const Rect2 &p_src_rect, const P
int dst_y = dest_rect.position.y + i;
Color sc = img->get_pixel(src_x, src_y);
- Color dc = get_pixel(dst_x, dst_y);
- dc.r = (double)(sc.a * sc.r + dc.a * (1.0 - sc.a) * dc.r);
- dc.g = (double)(sc.a * sc.g + dc.a * (1.0 - sc.a) * dc.g);
- dc.b = (double)(sc.a * sc.b + dc.a * (1.0 - sc.a) * dc.b);
- dc.a = (double)(sc.a + dc.a * (1.0 - sc.a));
- set_pixel(dst_x, dst_y, dc);
+ if (sc.a != 0) {
+ Color dc = get_pixel(dst_x, dst_y);
+ dc = dc.blend(sc);
+ set_pixel(dst_x, dst_y, dc);
+ }
}
}
}
@@ -2594,12 +2593,11 @@ void Image::blend_rect_mask(const Ref<Image> &p_src, const Ref<Image> &p_mask, c
int dst_y = dest_rect.position.y + i;
Color sc = img->get_pixel(src_x, src_y);
- Color dc = get_pixel(dst_x, dst_y);
- dc.r = (double)(sc.a * sc.r + dc.a * (1.0 - sc.a) * dc.r);
- dc.g = (double)(sc.a * sc.g + dc.a * (1.0 - sc.a) * dc.g);
- dc.b = (double)(sc.a * sc.b + dc.a * (1.0 - sc.a) * dc.b);
- dc.a = (double)(sc.a + dc.a * (1.0 - sc.a));
- set_pixel(dst_x, dst_y, dc);
+ if (sc.a != 0) {
+ Color dc = get_pixel(dst_x, dst_y);
+ dc = dc.blend(sc);
+ set_pixel(dst_x, dst_y, dc);
+ }
}
}
}
diff --git a/core/input/input_map.cpp b/core/input/input_map.cpp
index 3cb4b43a26..ac032b7d10 100644
--- a/core/input/input_map.cpp
+++ b/core/input/input_map.cpp
@@ -48,7 +48,7 @@ void InputMap::_bind_methods() {
ClassDB::bind_method(D_METHOD("action_has_event", "action", "event"), &InputMap::action_has_event);
ClassDB::bind_method(D_METHOD("action_erase_event", "action", "event"), &InputMap::action_erase_event);
ClassDB::bind_method(D_METHOD("action_erase_events", "action"), &InputMap::action_erase_events);
- ClassDB::bind_method(D_METHOD("get_action_list", "action"), &InputMap::_get_action_list);
+ ClassDB::bind_method(D_METHOD("action_get_events", "action"), &InputMap::_action_get_events);
ClassDB::bind_method(D_METHOD("event_is_action", "event", "action"), &InputMap::event_is_action);
ClassDB::bind_method(D_METHOD("load_from_globals"), &InputMap::load_from_globals);
}
@@ -152,9 +152,9 @@ void InputMap::action_erase_events(const StringName &p_action) {
input_map[p_action].inputs.clear();
}
-Array InputMap::_get_action_list(const StringName &p_action) {
+Array InputMap::_action_get_events(const StringName &p_action) {
Array ret;
- const List<Ref<InputEvent>> *al = get_action_list(p_action);
+ const List<Ref<InputEvent>> *al = action_get_events(p_action);
if (al) {
for (const List<Ref<InputEvent>>::Element *E = al->front(); E; E = E->next()) {
ret.push_back(E->get());
@@ -164,7 +164,7 @@ Array InputMap::_get_action_list(const StringName &p_action) {
return ret;
}
-const List<Ref<InputEvent>> *InputMap::get_action_list(const StringName &p_action) {
+const List<Ref<InputEvent>> *InputMap::action_get_events(const StringName &p_action) {
const Map<StringName, Action>::Element *E = input_map.find(p_action);
if (!E) {
return nullptr;
diff --git a/core/input/input_map.h b/core/input/input_map.h
index 3abc224ccf..548553ed31 100644
--- a/core/input/input_map.h
+++ b/core/input/input_map.h
@@ -56,7 +56,7 @@ private:
List<Ref<InputEvent>>::Element *_find_event(Action &p_action, const Ref<InputEvent> &p_event, bool *p_pressed = nullptr, float *p_strength = nullptr) const;
- Array _get_action_list(const StringName &p_action);
+ Array _action_get_events(const StringName &p_action);
Array _get_actions();
protected:
@@ -76,7 +76,7 @@ public:
void action_erase_event(const StringName &p_action, const Ref<InputEvent> &p_event);
void action_erase_events(const StringName &p_action);
- const List<Ref<InputEvent>> *get_action_list(const StringName &p_action);
+ const List<Ref<InputEvent>> *action_get_events(const StringName &p_action);
bool event_is_action(const Ref<InputEvent> &p_event, const StringName &p_action) const;
bool event_get_action_status(const Ref<InputEvent> &p_event, const StringName &p_action, bool *p_pressed = nullptr, float *p_strength = nullptr) const;
diff --git a/core/io/dtls_server.cpp b/core/io/dtls_server.cpp
index 0278027c50..e43b1f5385 100644
--- a/core/io/dtls_server.cpp
+++ b/core/io/dtls_server.cpp
@@ -37,7 +37,10 @@ DTLSServer *(*DTLSServer::_create)() = nullptr;
bool DTLSServer::available = false;
DTLSServer *DTLSServer::create() {
- return _create();
+ if (_create) {
+ return _create();
+ }
+ return nullptr;
}
bool DTLSServer::is_available() {
diff --git a/core/io/file_access_buffered.h b/core/io/file_access_buffered.h
index 61c0fa7489..99d5ce903d 100644
--- a/core/io/file_access_buffered.h
+++ b/core/io/file_access_buffered.h
@@ -51,16 +51,16 @@ protected:
Error set_error(Error p_error) const;
mutable struct File {
- bool open;
- int size;
- int offset;
+ bool open = false;
+ int size = 0;
+ int offset = 0;
String name;
- int access_flags;
+ int access_flags = 0;
} file;
mutable struct Cache {
Vector<uint8_t> buffer;
- int offset;
+ int offset = 0;
} cache;
virtual int read_data_block(int p_offset, int p_size, uint8_t *p_dest = nullptr) const = 0;
diff --git a/core/io/packet_peer_dtls.cpp b/core/io/packet_peer_dtls.cpp
index 67579c339a..632f86a9f6 100644
--- a/core/io/packet_peer_dtls.cpp
+++ b/core/io/packet_peer_dtls.cpp
@@ -36,7 +36,10 @@ PacketPeerDTLS *(*PacketPeerDTLS::_create)() = nullptr;
bool PacketPeerDTLS::available = false;
PacketPeerDTLS *PacketPeerDTLS::create() {
- return _create();
+ if (_create) {
+ return _create();
+ }
+ return nullptr;
}
bool PacketPeerDTLS::is_available() {
diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp
index 580a7cf7bb..30f712b2c3 100644
--- a/core/math/a_star.cpp
+++ b/core/math/a_star.cpp
@@ -280,10 +280,16 @@ int AStar::get_closest_point(const Vector3 &p_point, bool p_include_disabled) co
continue; // Disabled points should not be considered.
}
+ // Keep the closest point's ID, and in case of multiple closest IDs,
+ // the smallest one (makes it deterministic).
real_t d = p_point.distance_squared_to((*it.value)->pos);
- if (closest_id < 0 || d < closest_dist) {
+ int id = *(it.key);
+ if (d <= closest_dist) {
+ if (d == closest_dist && id > closest_id) { // Keep lowest ID.
+ continue;
+ }
closest_dist = d;
- closest_id = *(it.key);
+ closest_id = id;
}
}
@@ -291,7 +297,6 @@ int AStar::get_closest_point(const Vector3 &p_point, bool p_include_disabled) co
}
Vector3 AStar::get_closest_position_in_segment(const Vector3 &p_point) const {
- bool found = false;
real_t closest_dist = 1e20;
Vector3 closest_point;
@@ -311,10 +316,9 @@ Vector3 AStar::get_closest_position_in_segment(const Vector3 &p_point) const {
Vector3 p = Geometry3D::get_closest_point_to_segment(p_point, segment);
real_t d = p_point.distance_squared_to(p);
- if (!found || d < closest_dist) {
+ if (d < closest_dist) {
closest_point = p;
closest_dist = d;
- found = true;
}
}
diff --git a/core/math/basis.cpp b/core/math/basis.cpp
index cbfd09810c..df5199b0f9 100644
--- a/core/math/basis.cpp
+++ b/core/math/basis.cpp
@@ -428,12 +428,9 @@ Vector3 Basis::get_euler_xyz() const {
// -cx*cz*sy+sx*sz cz*sx+cx*sy*sz cx*cy
Vector3 euler;
-#ifdef MATH_CHECKS
- ERR_FAIL_COND_V(!is_rotation(), euler);
-#endif
real_t sy = elements[0][2];
- if (sy < 1.0) {
- if (sy > -1.0) {
+ if (sy < (1.0 - CMP_EPSILON)) {
+ if (sy > -(1.0 - CMP_EPSILON)) {
// is this a pure Y rotation?
if (elements[1][0] == 0.0 && elements[0][1] == 0.0 && elements[1][2] == 0 && elements[2][1] == 0 && elements[1][1] == 1) {
// return the simplest form (human friendlier in editor and scripts)
@@ -446,12 +443,12 @@ Vector3 Basis::get_euler_xyz() const {
euler.z = Math::atan2(-elements[0][1], elements[0][0]);
}
} else {
- euler.x = -Math::atan2(elements[0][1], elements[1][1]);
+ euler.x = Math::atan2(elements[2][1], elements[1][1]);
euler.y = -Math_PI / 2.0;
euler.z = 0.0;
}
} else {
- euler.x = Math::atan2(elements[0][1], elements[1][1]);
+ euler.x = Math::atan2(elements[2][1], elements[1][1]);
euler.y = Math_PI / 2.0;
euler.z = 0.0;
}
@@ -481,15 +478,106 @@ void Basis::set_euler_xyz(const Vector3 &p_euler) {
*this = xmat * (ymat * zmat);
}
+Vector3 Basis::get_euler_xzy() const {
+ // Euler angles in XZY convention.
+ // See https://en.wikipedia.org/wiki/Euler_angles#Rotation_matrix
+ //
+ // rot = cz*cy -sz cz*sy
+ // sx*sy+cx*cy*sz cx*cz cx*sz*sy-cy*sx
+ // cy*sx*sz cz*sx cx*cy+sx*sz*sy
+
+ Vector3 euler;
+ real_t sz = elements[0][1];
+ if (sz < (1.0 - CMP_EPSILON)) {
+ if (sz > -(1.0 - CMP_EPSILON)) {
+ euler.x = Math::atan2(elements[2][1], elements[1][1]);
+ euler.y = Math::atan2(elements[0][2], elements[0][0]);
+ euler.z = Math::asin(-sz);
+ } else {
+ // It's -1
+ euler.x = -Math::atan2(elements[1][2], elements[2][2]);
+ euler.y = 0.0;
+ euler.z = Math_PI / 2.0;
+ }
+ } else {
+ // It's 1
+ euler.x = -Math::atan2(elements[1][2], elements[2][2]);
+ euler.y = 0.0;
+ euler.z = -Math_PI / 2.0;
+ }
+ return euler;
+}
+
+void Basis::set_euler_xzy(const Vector3 &p_euler) {
+ real_t c, s;
+
+ c = Math::cos(p_euler.x);
+ s = Math::sin(p_euler.x);
+ Basis xmat(1.0, 0.0, 0.0, 0.0, c, -s, 0.0, s, c);
+
+ c = Math::cos(p_euler.y);
+ s = Math::sin(p_euler.y);
+ Basis ymat(c, 0.0, s, 0.0, 1.0, 0.0, -s, 0.0, c);
+
+ c = Math::cos(p_euler.z);
+ s = Math::sin(p_euler.z);
+ Basis zmat(c, -s, 0.0, s, c, 0.0, 0.0, 0.0, 1.0);
+
+ *this = xmat * zmat * ymat;
+}
+
+Vector3 Basis::get_euler_yzx() const {
+ // Euler angles in YZX convention.
+ // See https://en.wikipedia.org/wiki/Euler_angles#Rotation_matrix
+ //
+ // rot = cy*cz sy*sx-cy*cx*sz cx*sy+cy*sz*sx
+ // sz cz*cx -cz*sx
+ // -cz*sy cy*sx+cx*sy*sz cy*cx-sy*sz*sx
+
+ Vector3 euler;
+ real_t sz = elements[1][0];
+ if (sz < (1.0 - CMP_EPSILON)) {
+ if (sz > -(1.0 - CMP_EPSILON)) {
+ euler.x = Math::atan2(-elements[1][2], elements[1][1]);
+ euler.y = Math::atan2(-elements[2][0], elements[0][0]);
+ euler.z = Math::asin(sz);
+ } else {
+ // It's -1
+ euler.x = Math::atan2(elements[2][1], elements[2][2]);
+ euler.y = 0.0;
+ euler.z = -Math_PI / 2.0;
+ }
+ } else {
+ // It's 1
+ euler.x = Math::atan2(elements[2][1], elements[2][2]);
+ euler.y = 0.0;
+ euler.z = Math_PI / 2.0;
+ }
+ return euler;
+}
+
+void Basis::set_euler_yzx(const Vector3 &p_euler) {
+ real_t c, s;
+
+ c = Math::cos(p_euler.x);
+ s = Math::sin(p_euler.x);
+ Basis xmat(1.0, 0.0, 0.0, 0.0, c, -s, 0.0, s, c);
+
+ c = Math::cos(p_euler.y);
+ s = Math::sin(p_euler.y);
+ Basis ymat(c, 0.0, s, 0.0, 1.0, 0.0, -s, 0.0, c);
+
+ c = Math::cos(p_euler.z);
+ s = Math::sin(p_euler.z);
+ Basis zmat(c, -s, 0.0, s, c, 0.0, 0.0, 0.0, 1.0);
+
+ *this = ymat * zmat * xmat;
+}
+
// get_euler_yxz returns a vector containing the Euler angles in the YXZ convention,
// as in first-Z, then-X, last-Y. The angles for X, Y, and Z rotations are returned
// as the x, y, and z components of a Vector3 respectively.
Vector3 Basis::get_euler_yxz() const {
- /* checking this is a bad idea, because obtaining from scaled transform is a valid use case
-#ifdef MATH_CHECKS
- ERR_FAIL_COND(!is_rotation());
-#endif
-*/
// Euler angles in YXZ convention.
// See https://en.wikipedia.org/wiki/Euler_angles#Rotation_matrix
//
@@ -501,8 +589,8 @@ Vector3 Basis::get_euler_yxz() const {
real_t m12 = elements[1][2];
- if (m12 < 1) {
- if (m12 > -1) {
+ if (m12 < (1 - CMP_EPSILON)) {
+ if (m12 > -(1 - CMP_EPSILON)) {
// is this a pure X rotation?
if (elements[1][0] == 0 && elements[0][1] == 0 && elements[0][2] == 0 && elements[2][0] == 0 && elements[0][0] == 1) {
// return the simplest form (human friendlier in editor and scripts)
@@ -516,12 +604,12 @@ Vector3 Basis::get_euler_yxz() const {
}
} else { // m12 == -1
euler.x = Math_PI * 0.5;
- euler.y = -atan2(-elements[0][1], elements[0][0]);
+ euler.y = atan2(elements[0][1], elements[0][0]);
euler.z = 0;
}
} else { // m12 == 1
euler.x = -Math_PI * 0.5;
- euler.y = -atan2(-elements[0][1], elements[0][0]);
+ euler.y = -atan2(elements[0][1], elements[0][0]);
euler.z = 0;
}
@@ -551,6 +639,100 @@ void Basis::set_euler_yxz(const Vector3 &p_euler) {
*this = ymat * xmat * zmat;
}
+Vector3 Basis::get_euler_zxy() const {
+ // Euler angles in ZXY convention.
+ // See https://en.wikipedia.org/wiki/Euler_angles#Rotation_matrix
+ //
+ // rot = cz*cy-sz*sx*sy -cx*sz cz*sy+cy*sz*sx
+ // cy*sz+cz*sx*sy cz*cx sz*sy-cz*cy*sx
+ // -cx*sy sx cx*cy
+ Vector3 euler;
+ real_t sx = elements[2][1];
+ if (sx < (1.0 - CMP_EPSILON)) {
+ if (sx > -(1.0 - CMP_EPSILON)) {
+ euler.x = Math::asin(sx);
+ euler.y = Math::atan2(-elements[2][0], elements[2][2]);
+ euler.z = Math::atan2(-elements[0][1], elements[1][1]);
+ } else {
+ // It's -1
+ euler.x = -Math_PI / 2.0;
+ euler.y = Math::atan2(elements[0][2], elements[0][0]);
+ euler.z = 0;
+ }
+ } else {
+ // It's 1
+ euler.x = Math_PI / 2.0;
+ euler.y = Math::atan2(elements[0][2], elements[0][0]);
+ euler.z = 0;
+ }
+ return euler;
+}
+
+void Basis::set_euler_zxy(const Vector3 &p_euler) {
+ real_t c, s;
+
+ c = Math::cos(p_euler.x);
+ s = Math::sin(p_euler.x);
+ Basis xmat(1.0, 0.0, 0.0, 0.0, c, -s, 0.0, s, c);
+
+ c = Math::cos(p_euler.y);
+ s = Math::sin(p_euler.y);
+ Basis ymat(c, 0.0, s, 0.0, 1.0, 0.0, -s, 0.0, c);
+
+ c = Math::cos(p_euler.z);
+ s = Math::sin(p_euler.z);
+ Basis zmat(c, -s, 0.0, s, c, 0.0, 0.0, 0.0, 1.0);
+
+ *this = zmat * xmat * ymat;
+}
+
+Vector3 Basis::get_euler_zyx() const {
+ // Euler angles in ZYX convention.
+ // See https://en.wikipedia.org/wiki/Euler_angles#Rotation_matrix
+ //
+ // rot = cz*cy cz*sy*sx-cx*sz sz*sx+cz*cx*cy
+ // cy*sz cz*cx+sz*sy*sx cx*sz*sy-cz*sx
+ // -sy cy*sx cy*cx
+ Vector3 euler;
+ real_t sy = elements[2][0];
+ if (sy < (1.0 - CMP_EPSILON)) {
+ if (sy > -(1.0 - CMP_EPSILON)) {
+ euler.x = Math::atan2(elements[2][1], elements[2][2]);
+ euler.y = Math::asin(-sy);
+ euler.z = Math::atan2(elements[1][0], elements[0][0]);
+ } else {
+ // It's -1
+ euler.x = 0;
+ euler.y = Math_PI / 2.0;
+ euler.z = -Math::atan2(elements[0][1], elements[1][1]);
+ }
+ } else {
+ // It's 1
+ euler.x = 0;
+ euler.y = -Math_PI / 2.0;
+ euler.z = -Math::atan2(elements[0][1], elements[1][1]);
+ }
+ return euler;
+}
+
+void Basis::set_euler_zyx(const Vector3 &p_euler) {
+ real_t c, s;
+
+ c = Math::cos(p_euler.x);
+ s = Math::sin(p_euler.x);
+ Basis xmat(1.0, 0.0, 0.0, 0.0, c, -s, 0.0, s, c);
+
+ c = Math::cos(p_euler.y);
+ s = Math::sin(p_euler.y);
+ Basis ymat(c, 0.0, s, 0.0, 1.0, 0.0, -s, 0.0, c);
+
+ c = Math::cos(p_euler.z);
+ s = Math::sin(p_euler.z);
+ Basis zmat(c, -s, 0.0, s, c, 0.0, 0.0, 0.0, 1.0);
+
+ *this = zmat * ymat * xmat;
+}
+
bool Basis::is_equal_approx(const Basis &p_basis) const {
return elements[0].is_equal_approx(p_basis.elements[0]) && elements[1].is_equal_approx(p_basis.elements[1]) && elements[2].is_equal_approx(p_basis.elements[2]);
}
diff --git a/core/math/basis.h b/core/math/basis.h
index d870a6b099..985fb0e44f 100644
--- a/core/math/basis.h
+++ b/core/math/basis.h
@@ -88,9 +88,22 @@ public:
Vector3 get_euler_xyz() const;
void set_euler_xyz(const Vector3 &p_euler);
+
+ Vector3 get_euler_xzy() const;
+ void set_euler_xzy(const Vector3 &p_euler);
+
+ Vector3 get_euler_yzx() const;
+ void set_euler_yzx(const Vector3 &p_euler);
+
Vector3 get_euler_yxz() const;
void set_euler_yxz(const Vector3 &p_euler);
+ Vector3 get_euler_zxy() const;
+ void set_euler_zxy(const Vector3 &p_euler);
+
+ Vector3 get_euler_zyx() const;
+ void set_euler_zyx(const Vector3 &p_euler);
+
Quat get_quat() const;
void set_quat(const Quat &p_quat);
diff --git a/core/math/expression.cpp b/core/math/expression.cpp
index db3bf2f830..6421606ca2 100644
--- a/core/math/expression.cpp
+++ b/core/math/expression.cpp
@@ -896,6 +896,7 @@ Error Expression::_get_token(Token &r_token) {
return OK;
}
+ case '\'':
case '"': {
String str;
while (true) {
@@ -905,7 +906,8 @@ Error Expression::_get_token(Token &r_token) {
_set_error("Unterminated String");
r_token.type = TK_ERROR;
return ERR_PARSE_ERROR;
- } else if (ch == '"') {
+ } else if (ch == cchar) {
+ // cchar contain a corresponding quote symbol
break;
} else if (ch == '\\') {
//escaped characters...
diff --git a/core/math/transform_2d.cpp b/core/math/transform_2d.cpp
index dee1b3b23e..180aeaa0af 100644
--- a/core/math/transform_2d.cpp
+++ b/core/math/transform_2d.cpp
@@ -78,12 +78,7 @@ void Transform2D::set_skew(float p_angle) {
}
real_t Transform2D::get_rotation() const {
- real_t det = basis_determinant();
- Transform2D m = orthonormalized();
- if (det < 0) {
- m.scale_basis(Size2(1, -1)); // convention to separate rotation and reflection for 2D is to absorb a flip along y into scaling.
- }
- return Math::atan2(m[0].y, m[0].x);
+ return Math::atan2(elements[0].y, elements[0].x);
}
void Transform2D::set_rotation(real_t p_rot) {
diff --git a/core/object.cpp b/core/object.cpp
index f3c5a13809..8abea9ca7e 100644
--- a/core/object.cpp
+++ b/core/object.cpp
@@ -2038,23 +2038,31 @@ void ObjectDB::cleanup() {
if (slot_count > 0) {
spin_lock.lock();
- WARN_PRINT("ObjectDB Instances still exist!");
+ WARN_PRINT("ObjectDB instances leaked at exit (run with --verbose for details).");
if (OS::get_singleton()->is_stdout_verbose()) {
+ // Ensure calling the native classes because if a leaked instance has a script
+ // that overrides any of those methods, it'd not be OK to call them at this point,
+ // now the scripting languages have already been terminated.
+ MethodBind *node_get_name = ClassDB::get_method("Node", "get_name");
+ MethodBind *resource_get_path = ClassDB::get_method("Resource", "get_path");
+ Callable::CallError call_error;
+
for (uint32_t i = 0; i < slot_count; i++) {
uint32_t slot = object_slots[i].next_free;
Object *obj = object_slots[slot].object;
- String node_name;
+ String extra_info;
if (obj->is_class("Node")) {
- node_name = " - Node name: " + String(obj->call("get_name"));
+ extra_info = " - Node name: " + String(node_get_name->call(obj, nullptr, 0, call_error));
}
if (obj->is_class("Resource")) {
- node_name = " - Resource name: " + String(obj->call("get_name")) + " Path: " + String(obj->call("get_path"));
+ extra_info = " - Resource path: " + String(resource_get_path->call(obj, nullptr, 0, call_error));
}
uint64_t id = uint64_t(slot) | (uint64_t(object_slots[slot].validator) << OBJECTDB_VALIDATOR_BITS) | (object_slots[slot].is_reference ? OBJECTDB_REFERENCE_BIT : 0);
- print_line("Leaked instance: " + String(obj->get_class()) + ":" + itos(id) + node_name);
+ print_line("Leaked instance: " + String(obj->get_class()) + ":" + itos(id) + extra_info);
}
+ print_line("Hint: Leaked instances typically happen when nodes are removed from the scene tree (with `remove_child()`) but not freed (with `free()` or `queue_free()`).");
}
spin_lock.unlock();
}
diff --git a/core/object.h b/core/object.h
index 95662f6208..5b46a0f93a 100644
--- a/core/object.h
+++ b/core/object.h
@@ -124,6 +124,7 @@ enum PropertyUsageFlags {
PROPERTY_USAGE_RESOURCE_NOT_PERSISTENT = 1 << 24,
PROPERTY_USAGE_KEYING_INCREMENTS = 1 << 25, // Used in inspector to increment property when keyed in animation player
PROPERTY_USAGE_DEFERRED_SET_RESOURCE = 1 << 26, // when loading, the resource for this property can be set at the end of loading
+ PROPERTY_USAGE_EDITOR_INSTANTIATE_OBJECT = 1 << 27, // For Object properties, instantiate them when creating in editor.
PROPERTY_USAGE_DEFAULT = PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_NETWORK,
PROPERTY_USAGE_DEFAULT_INTL = PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_NETWORK | PROPERTY_USAGE_INTERNATIONALIZED,
diff --git a/core/os/os.cpp b/core/os/os.cpp
index 56755bcf51..c842be333c 100644
--- a/core/os/os.cpp
+++ b/core/os/os.cpp
@@ -83,15 +83,7 @@ uint64_t OS::get_splash_tick_msec() const {
return _msec_splash;
}
-uint64_t OS::get_unix_time() const {
- return 0;
-}
-
-uint64_t OS::get_system_time_secs() const {
- return 0;
-}
-
-uint64_t OS::get_system_time_msecs() const {
+double OS::get_unix_time() const {
return 0;
}
diff --git a/core/os/os.h b/core/os/os.h
index 9ca034a01c..04e10518dc 100644
--- a/core/os/os.h
+++ b/core/os/os.h
@@ -209,9 +209,7 @@ public:
virtual Time get_time(bool local = false) const = 0;
virtual TimeZoneInfo get_time_zone_info() const = 0;
virtual String get_iso_date_time(bool local = false) const;
- virtual uint64_t get_unix_time() const;
- virtual uint64_t get_system_time_secs() const;
- virtual uint64_t get_system_time_msecs() const;
+ virtual double get_unix_time() const;
virtual void delay_usec(uint32_t p_usec) const = 0;
virtual uint64_t get_ticks_usec() const = 0;
diff --git a/core/register_core_types.cpp b/core/register_core_types.cpp
index c0f9eea76d..5dac42cacb 100644
--- a/core/register_core_types.cpp
+++ b/core/register_core_types.cpp
@@ -34,6 +34,7 @@
#include "core/class_db.h"
#include "core/compressed_translation.h"
#include "core/core_string_names.h"
+#include "core/crypto/aes_context.h"
#include "core/crypto/crypto.h"
#include "core/crypto/hashing_context.h"
#include "core/engine.h"
@@ -165,6 +166,7 @@ void register_core_types() {
// Crypto
ClassDB::register_class<HashingContext>();
+ ClassDB::register_class<AESContext>();
ClassDB::register_custom_instance_class<X509Certificate>();
ClassDB::register_custom_instance_class<CryptoKey>();
ClassDB::register_custom_instance_class<Crypto>();
diff --git a/core/resource.cpp b/core/resource.cpp
index 0af8c9c2b3..3b589793ef 100644
--- a/core/resource.cpp
+++ b/core/resource.cpp
@@ -33,6 +33,7 @@
#include "core/core_string_names.h"
#include "core/io/resource_loader.h"
#include "core/os/file_access.h"
+#include "core/os/os.h"
#include "core/script_language.h"
#include "scene/main/node.h" //only so casting works
@@ -431,7 +432,14 @@ void ResourceCache::setup() {
void ResourceCache::clear() {
if (resources.size()) {
- ERR_PRINT("Resources Still in use at Exit!");
+ ERR_PRINT("Resources still in use at exit (run with --verbose for details).");
+ if (OS::get_singleton()->is_stdout_verbose()) {
+ const String *K = nullptr;
+ while ((K = resources.next(K))) {
+ Resource *r = resources[*K];
+ print_line(vformat("Resource still in use: %s (%s)", *K, r->get_class()));
+ }
+ }
}
resources.clear();
@@ -442,12 +450,6 @@ void ResourceCache::clear() {
}
void ResourceCache::reload_externals() {
- /*
- const String *K=nullptr;
- while ((K=resources.next(K))) {
- resources[*K]->reload_external_data();
- }
- */
}
bool ResourceCache::has(const String &p_path) {
@@ -530,6 +532,5 @@ void ResourceCache::dump(const char *p_file, bool p_short) {
}
lock->read_unlock();
-
#endif
}
diff --git a/core/undo_redo.cpp b/core/undo_redo.cpp
index 90750f2c6e..1dcbb0cd6b 100644
--- a/core/undo_redo.cpp
+++ b/core/undo_redo.cpp
@@ -435,6 +435,7 @@ Variant UndoRedo::_add_do_method(const Variant **p_args, int p_argcount, Callabl
v[i] = *p_args[i + 2];
}
+ static_assert(VARIANT_ARG_MAX == 5, "This code needs to be updated if VARIANT_ARG_MAX != 5");
add_do_method(object, method, v[0], v[1], v[2], v[3], v[4]);
return Variant();
}
@@ -471,6 +472,7 @@ Variant UndoRedo::_add_undo_method(const Variant **p_args, int p_argcount, Calla
v[i] = *p_args[i + 2];
}
+ static_assert(VARIANT_ARG_MAX == 5, "This code needs to be updated if VARIANT_ARG_MAX != 5");
add_undo_method(object, method, v[0], v[1], v[2], v[3], v[4]);
return Variant();
}
diff --git a/core/ustring.cpp b/core/ustring.cpp
index cfb547742a..444338d5ae 100644
--- a/core/ustring.cpp
+++ b/core/ustring.cpp
@@ -4143,27 +4143,40 @@ String String::sprintf(const Array &values, bool *error) const {
}
double value = values[value_index];
- String str = String::num(value, min_decimals);
+ bool is_negative = (value < 0);
+ String str = String::num(ABS(value), min_decimals);
// Pad decimals out.
str = str.pad_decimals(min_decimals);
- // Show sign
- if (show_sign && str.left(1) != "-") {
- str = str.insert(0, "+");
- }
+ int initial_len = str.length();
- // Padding
+ // Padding. Leave room for sign later if required.
+ int pad_chars_count = (is_negative || show_sign) ? min_chars - 1 : min_chars;
+ String pad_char = pad_with_zeroes ? String("0") : String(" ");
if (left_justified) {
- str = str.rpad(min_chars);
+ if (pad_with_zeroes) {
+ return "left justification cannot be used with zeros as the padding";
+ } else {
+ str = str.rpad(pad_chars_count, pad_char);
+ }
} else {
- str = str.lpad(min_chars);
+ str = str.lpad(pad_chars_count, pad_char);
+ }
+
+ // Add sign if needed.
+ if (show_sign || is_negative) {
+ String sign_char = is_negative ? "-" : "+";
+ if (left_justified) {
+ str = str.insert(0, sign_char);
+ } else {
+ str = str.insert(pad_with_zeroes ? 0 : str.length() - initial_len, sign_char);
+ }
}
formatted += str;
++value_index;
in_format = false;
-
break;
}
case 's': { // String
diff --git a/core/variant_call.cpp b/core/variant_call.cpp
index f1b2a1547d..a8beac1e44 100644
--- a/core/variant_call.cpp
+++ b/core/variant_call.cpp
@@ -923,6 +923,18 @@ struct _VariantCall {
VCALL_PTR1R(Basis, scaled);
VCALL_PTR0R(Basis, get_scale);
VCALL_PTR0R(Basis, get_euler);
+ VCALL_PTR0R(Basis, get_euler_xyz);
+ VCALL_PTR1(Basis, set_euler_xyz);
+ VCALL_PTR0R(Basis, get_euler_xzy);
+ VCALL_PTR1(Basis, set_euler_xzy);
+ VCALL_PTR0R(Basis, get_euler_yzx);
+ VCALL_PTR1(Basis, set_euler_yzx);
+ VCALL_PTR0R(Basis, get_euler_yxz);
+ VCALL_PTR1(Basis, set_euler_yxz);
+ VCALL_PTR0R(Basis, get_euler_zxy);
+ VCALL_PTR1(Basis, set_euler_zxy);
+ VCALL_PTR0R(Basis, get_euler_zyx);
+ VCALL_PTR1(Basis, set_euler_zyx);
VCALL_PTR1R(Basis, tdotx);
VCALL_PTR1R(Basis, tdoty);
VCALL_PTR1R(Basis, tdotz);
diff --git a/core/variant_parser.cpp b/core/variant_parser.cpp
index bdcad03353..74f4f32c0e 100644
--- a/core/variant_parser.cpp
+++ b/core/variant_parser.cpp
@@ -479,12 +479,6 @@ Error VariantParser::_parse_construct(Stream *p_stream, Vector<T> &r_construct,
}
Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, int &line, String &r_err_str, ResourceParser *p_res_parser) {
- /* {
- Error err = get_token(p_stream,token,line,r_err_str);
- if (err)
- return err;
- }*/
-
if (token.type == TK_CURLY_BRACKET_OPEN) {
Dictionary d;
Error err = _parse_dictionary(d, p_stream, line, r_err_str, p_res_parser);
@@ -501,7 +495,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
}
value = a;
return OK;
-
} else if (token.type == TK_IDENTIFIER) {
String id = token.value;
if (id == "true") {
@@ -523,10 +516,10 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
if (args.size() != 2) {
r_err_str = "Expected 2 arguments for constructor";
+ return ERR_PARSE_ERROR;
}
value = Vector2(args[0], args[1]);
- return OK;
} else if (id == "Vector2i") {
Vector<int32_t> args;
Error err = _parse_construct<int32_t>(p_stream, args, line, r_err_str);
@@ -536,10 +529,10 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
if (args.size() != 2) {
r_err_str = "Expected 2 arguments for constructor";
+ return ERR_PARSE_ERROR;
}
value = Vector2i(args[0], args[1]);
- return OK;
} else if (id == "Rect2") {
Vector<float> args;
Error err = _parse_construct<float>(p_stream, args, line, r_err_str);
@@ -549,10 +542,10 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
if (args.size() != 4) {
r_err_str = "Expected 4 arguments for constructor";
+ return ERR_PARSE_ERROR;
}
value = Rect2(args[0], args[1], args[2], args[3]);
- return OK;
} else if (id == "Rect2i") {
Vector<int32_t> args;
Error err = _parse_construct<int32_t>(p_stream, args, line, r_err_str);
@@ -562,10 +555,10 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
if (args.size() != 4) {
r_err_str = "Expected 4 arguments for constructor";
+ return ERR_PARSE_ERROR;
}
value = Rect2i(args[0], args[1], args[2], args[3]);
- return OK;
} else if (id == "Vector3") {
Vector<float> args;
Error err = _parse_construct<float>(p_stream, args, line, r_err_str);
@@ -575,10 +568,10 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
if (args.size() != 3) {
r_err_str = "Expected 3 arguments for constructor";
+ return ERR_PARSE_ERROR;
}
value = Vector3(args[0], args[1], args[2]);
- return OK;
} else if (id == "Vector3i") {
Vector<int32_t> args;
Error err = _parse_construct<int32_t>(p_stream, args, line, r_err_str);
@@ -588,12 +581,11 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
if (args.size() != 3) {
r_err_str = "Expected 3 arguments for constructor";
+ return ERR_PARSE_ERROR;
}
value = Vector3i(args[0], args[1], args[2]);
- return OK;
} else if (id == "Transform2D" || id == "Matrix32") { //compatibility
-
Vector<float> args;
Error err = _parse_construct<float>(p_stream, args, line, r_err_str);
if (err) {
@@ -602,13 +594,14 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
if (args.size() != 6) {
r_err_str = "Expected 6 arguments for constructor";
+ return ERR_PARSE_ERROR;
}
+
Transform2D m;
m[0] = Vector2(args[0], args[1]);
m[1] = Vector2(args[2], args[3]);
m[2] = Vector2(args[4], args[5]);
value = m;
- return OK;
} else if (id == "Plane") {
Vector<float> args;
Error err = _parse_construct<float>(p_stream, args, line, r_err_str);
@@ -618,10 +611,10 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
if (args.size() != 4) {
r_err_str = "Expected 4 arguments for constructor";
+ return ERR_PARSE_ERROR;
}
value = Plane(args[0], args[1], args[2], args[3]);
- return OK;
} else if (id == "Quat") {
Vector<float> args;
Error err = _parse_construct<float>(p_stream, args, line, r_err_str);
@@ -631,11 +624,10 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
if (args.size() != 4) {
r_err_str = "Expected 4 arguments for constructor";
+ return ERR_PARSE_ERROR;
}
value = Quat(args[0], args[1], args[2], args[3]);
- return OK;
-
} else if (id == "AABB" || id == "Rect3") {
Vector<float> args;
Error err = _parse_construct<float>(p_stream, args, line, r_err_str);
@@ -645,13 +637,11 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
if (args.size() != 6) {
r_err_str = "Expected 6 arguments for constructor";
+ return ERR_PARSE_ERROR;
}
value = AABB(Vector3(args[0], args[1], args[2]), Vector3(args[3], args[4], args[5]));
- return OK;
-
} else if (id == "Basis" || id == "Matrix3") { //compatibility
-
Vector<float> args;
Error err = _parse_construct<float>(p_stream, args, line, r_err_str);
if (err) {
@@ -660,10 +650,10 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
if (args.size() != 9) {
r_err_str = "Expected 9 arguments for constructor";
+ return ERR_PARSE_ERROR;
}
value = Basis(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8]);
- return OK;
} else if (id == "Transform") {
Vector<float> args;
Error err = _parse_construct<float>(p_stream, args, line, r_err_str);
@@ -673,11 +663,10 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
if (args.size() != 12) {
r_err_str = "Expected 12 arguments for constructor";
+ return ERR_PARSE_ERROR;
}
value = Transform(Basis(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8]), Vector3(args[9], args[10], args[11]));
- return OK;
-
} else if (id == "Color") {
Vector<float> args;
Error err = _parse_construct<float>(p_stream, args, line, r_err_str);
@@ -687,11 +676,10 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
if (args.size() != 4) {
r_err_str = "Expected 4 arguments for constructor";
+ return ERR_PARSE_ERROR;
}
value = Color(args[0], args[1], args[2], args[3]);
- return OK;
-
} else if (id == "NodePath") {
get_token(p_stream, token, line, r_err_str);
if (token.type != TK_PARENTHESIS_OPEN) {
@@ -712,7 +700,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
r_err_str = "Expected ')'";
return ERR_PARSE_ERROR;
}
-
} else if (id == "RID") {
get_token(p_stream, token, line, r_err_str);
if (token.type != TK_PARENTHESIS_OPEN) {
@@ -733,8 +720,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
r_err_str = "Expected ')'";
return ERR_PARSE_ERROR;
}
-
- return OK;
} else if (id == "Object") {
get_token(p_stream, token, line, r_err_str);
if (token.type != TK_PARENTHESIS_OPEN) {
@@ -834,7 +819,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
at_key = true;
}
}
-
} else if (id == "Resource" || id == "SubResource" || id == "ExtResource") {
get_token(p_stream, token, line, r_err_str);
if (token.type != TK_PARENTHESIS_OPEN) {
@@ -850,8 +834,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
}
value = res;
-
- return OK;
} else if (p_res_parser && id == "ExtResource" && p_res_parser->ext_func) {
RES res;
Error err = p_res_parser->ext_func(p_res_parser->userdata, p_stream, res, line, r_err_str);
@@ -860,8 +842,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
}
value = res;
-
- return OK;
} else if (p_res_parser && id == "SubResource" && p_res_parser->sub_func) {
RES res;
Error err = p_res_parser->sub_func(p_res_parser->userdata, p_stream, res, line, r_err_str);
@@ -870,8 +850,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
}
value = res;
-
- return OK;
} else {
get_token(p_stream, token, line, r_err_str);
if (token.type == TK_STRING) {
@@ -889,14 +867,11 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
}
value = res;
- return OK;
-
} else {
r_err_str = "Expected string as argument for Resource().";
return ERR_PARSE_ERROR;
}
}
-
} else if (id == "PackedByteArray" || id == "PoolByteArray" || id == "ByteArray") {
Vector<uint8_t> args;
Error err = _parse_construct<uint8_t>(p_stream, args, line, r_err_str);
@@ -915,9 +890,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
}
value = arr;
-
- return OK;
-
} else if (id == "PackedInt32Array" || id == "PackedIntArray" || id == "PoolIntArray" || id == "IntArray") {
Vector<int32_t> args;
Error err = _parse_construct<int32_t>(p_stream, args, line, r_err_str);
@@ -936,9 +908,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
}
value = arr;
-
- return OK;
-
} else if (id == "PackedInt64Array") {
Vector<int64_t> args;
Error err = _parse_construct<int64_t>(p_stream, args, line, r_err_str);
@@ -957,9 +926,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
}
value = arr;
-
- return OK;
-
} else if (id == "PackedFloat32Array" || id == "PackedRealArray" || id == "PoolRealArray" || id == "FloatArray") {
Vector<float> args;
Error err = _parse_construct<float>(p_stream, args, line, r_err_str);
@@ -978,8 +944,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
}
value = arr;
-
- return OK;
} else if (id == "PackedFloat64Array") {
Vector<double> args;
Error err = _parse_construct<double>(p_stream, args, line, r_err_str);
@@ -998,8 +962,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
}
value = arr;
-
- return OK;
} else if (id == "PackedStringArray" || id == "PoolStringArray" || id == "StringArray") {
get_token(p_stream, token, line, r_err_str);
if (token.type != TK_PARENTHESIS_OPEN) {
@@ -1046,9 +1008,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
}
value = arr;
-
- return OK;
-
} else if (id == "PackedVector2Array" || id == "PoolVector2Array" || id == "Vector2Array") {
Vector<float> args;
Error err = _parse_construct<float>(p_stream, args, line, r_err_str);
@@ -1067,9 +1026,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
}
value = arr;
-
- return OK;
-
} else if (id == "PackedVector3Array" || id == "PoolVector3Array" || id == "Vector3Array") {
Vector<float> args;
Error err = _parse_construct<float>(p_stream, args, line, r_err_str);
@@ -1088,9 +1044,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
}
value = arr;
-
- return OK;
-
} else if (id == "PackedColorArray" || id == "PoolColorArray" || id == "ColorArray") {
Vector<float> args;
Error err = _parse_construct<float>(p_stream, args, line, r_err_str);
@@ -1109,15 +1062,13 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
}
value = arr;
-
- return OK;
} else {
r_err_str = "Unexpected identifier: '" + id + "'.";
return ERR_PARSE_ERROR;
}
+ // All above branches end up here unless they had an early return.
return OK;
-
} else if (token.type == TK_NUMBER) {
value = token.value;
return OK;