summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/SCsub2
-rw-r--r--core/config/project_settings.cpp2
-rw-r--r--core/core_constants.cpp2
-rw-r--r--core/crypto/crypto.cpp47
-rw-r--r--core/crypto/crypto.h23
-rw-r--r--core/doc_data.cpp126
-rw-r--r--core/doc_data.h152
-rw-r--r--core/input/input.cpp2
-rw-r--r--core/input/input_event.cpp248
-rw-r--r--core/input/input_event.h16
-rw-r--r--core/io/compression.cpp4
-rw-r--r--core/io/file_access_buffered.cpp150
-rw-r--r--core/io/file_access_buffered.h91
-rw-r--r--core/io/file_access_buffered_fa.h139
-rw-r--r--core/io/file_access_compressed.cpp4
-rw-r--r--core/io/file_access_encrypted.cpp6
-rw-r--r--core/io/file_access_zip.h2
-rw-r--r--core/io/image.cpp71
-rw-r--r--core/io/image.h16
-rw-r--r--core/io/logger.cpp22
-rw-r--r--core/io/marshalls.cpp5
-rw-r--r--core/io/packet_peer.cpp9
-rw-r--r--core/io/packet_peer.h1
-rw-r--r--core/io/resource_importer.cpp4
-rw-r--r--core/io/resource_importer.h2
-rw-r--r--core/math/basis.cpp12
-rw-r--r--core/math/basis.h2
-rw-r--r--core/math/color.h10
-rw-r--r--core/math/expression.cpp27
-rw-r--r--core/math/quat.cpp72
-rw-r--r--core/math/quat.h60
-rw-r--r--core/math/random_number_generator.cpp7
-rw-r--r--core/math/random_number_generator.h8
-rw-r--r--core/math/random_pcg.h7
-rw-r--r--core/math/vector2.cpp8
-rw-r--r--core/math/vector2.h26
-rw-r--r--core/math/vector3.cpp37
-rw-r--r--core/math/vector3.h51
-rw-r--r--core/object/class_db.cpp5
-rw-r--r--core/object/object.cpp16
-rw-r--r--core/object/object.h6
-rw-r--r--core/object/script_language.h10
-rw-r--r--core/os/file_access.cpp2
-rw-r--r--core/os/os.cpp4
-rw-r--r--core/os/os.h2
-rw-r--r--core/register_core_types.cpp1
-rw-r--r--core/string/node_path.cpp2
-rw-r--r--core/templates/pass_func.h100
-rw-r--r--core/variant/method_ptrcall.h9
-rw-r--r--core/variant/variant.h12
-rw-r--r--core/variant/variant_call.cpp24
-rw-r--r--core/variant/variant_construct.cpp159
-rw-r--r--core/variant/variant_internal.h19
-rw-r--r--core/variant/variant_op.cpp2
-rw-r--r--core/variant/variant_parser.cpp9
-rw-r--r--core/variant/variant_setget.cpp224
56 files changed, 1135 insertions, 944 deletions
diff --git a/core/SCsub b/core/SCsub
index 78a4395619..45918fb520 100644
--- a/core/SCsub
+++ b/core/SCsub
@@ -25,7 +25,7 @@ if "SCRIPT_AES256_ENCRYPTION_KEY" in os.environ:
txts = "0x" + e[i * 2 : i * 2 + 2]
try:
int(txts, 16)
- except:
+ except Exception:
ec_valid = False
txt += txts
if not ec_valid:
diff --git a/core/config/project_settings.cpp b/core/config/project_settings.cpp
index 8b8aff3e9e..f939fca984 100644
--- a/core/config/project_settings.cpp
+++ b/core/config/project_settings.cpp
@@ -402,7 +402,7 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b
#ifdef OSX_ENABLED
if (!found) {
// Attempt to load PCK from macOS .app bundle resources.
- found = _load_resource_pack(OS::get_singleton()->get_bundle_resource_dir().plus_file(exec_basename + ".pck"));
+ found = _load_resource_pack(OS::get_singleton()->get_bundle_resource_dir().plus_file(exec_basename + ".pck")) || _load_resource_pack(OS::get_singleton()->get_bundle_resource_dir().plus_file(exec_filename + ".pck"));
}
#endif
diff --git a/core/core_constants.cpp b/core/core_constants.cpp
index db22a9ecf6..02055012ad 100644
--- a/core/core_constants.cpp
+++ b/core/core_constants.cpp
@@ -557,7 +557,7 @@ void register_global_constants() {
BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_NIL", Variant::NIL);
BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_BOOL", Variant::BOOL);
BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_INT", Variant::INT);
- BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_REAL", Variant::FLOAT);
+ BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_FLOAT", Variant::FLOAT);
BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_STRING", Variant::STRING);
BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_VECTOR2", Variant::VECTOR2);
BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_VECTOR2I", Variant::VECTOR2I);
diff --git a/core/crypto/crypto.cpp b/core/crypto/crypto.cpp
index d12108bca0..33ba0ba704 100644
--- a/core/crypto/crypto.cpp
+++ b/core/crypto/crypto.cpp
@@ -65,6 +65,22 @@ void X509Certificate::_bind_methods() {
ClassDB::bind_method(D_METHOD("load", "path"), &X509Certificate::load);
}
+/// HMACContext
+
+void HMACContext::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("start", "hash_type", "key"), &HMACContext::start);
+ ClassDB::bind_method(D_METHOD("update", "data"), &HMACContext::update);
+ ClassDB::bind_method(D_METHOD("finish"), &HMACContext::finish);
+}
+
+HMACContext *(*HMACContext::_create)() = nullptr;
+HMACContext *HMACContext::create() {
+ if (_create) {
+ return _create();
+ }
+ ERR_FAIL_V_MSG(nullptr, "HMACContext is not available when the mbedtls module is disabled.");
+}
+
/// Crypto
void (*Crypto::_load_default_certificates)(String p_path) = nullptr;
@@ -82,6 +98,35 @@ void Crypto::load_default_certificates(String p_path) {
}
}
+PackedByteArray Crypto::hmac_digest(HashingContext::HashType p_hash_type, PackedByteArray p_key, PackedByteArray p_msg) {
+ Ref<HMACContext> ctx = Ref<HMACContext>(HMACContext::create());
+ ERR_FAIL_COND_V_MSG(ctx.is_null(), PackedByteArray(), "HMAC is not available witout mbedtls module.");
+ Error err = ctx->start(p_hash_type, p_key);
+ ERR_FAIL_COND_V(err != OK, PackedByteArray());
+ err = ctx->update(p_msg);
+ ERR_FAIL_COND_V(err != OK, PackedByteArray());
+ return ctx->finish();
+}
+
+// Compares two HMACS for equality without leaking timing information in order to prevent timing attakcs.
+// @see: https://paragonie.com/blog/2015/11/preventing-timing-attacks-on-string-comparison-with-double-hmac-strategy
+bool Crypto::constant_time_compare(PackedByteArray p_trusted, PackedByteArray p_received) {
+ const uint8_t *t = p_trusted.ptr();
+ const uint8_t *r = p_received.ptr();
+ int tlen = p_trusted.size();
+ int rlen = p_received.size();
+ // If the lengths are different then nothing else matters.
+ if (tlen != rlen) {
+ return false;
+ }
+
+ uint8_t v = 0;
+ for (int i = 0; i < tlen; i++) {
+ v |= t[i] ^ r[i];
+ }
+ return v == 0;
+}
+
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);
@@ -90,6 +135,8 @@ void Crypto::_bind_methods() {
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);
+ ClassDB::bind_method(D_METHOD("hmac_digest", "hash_type", "key", "msg"), &Crypto::hmac_digest);
+ ClassDB::bind_method(D_METHOD("constant_time_compare", "trusted", "received"), &Crypto::constant_time_compare);
}
/// Resource loader/saver
diff --git a/core/crypto/crypto.h b/core/crypto/crypto.h
index 8325f043bf..5cacddaea0 100644
--- a/core/crypto/crypto.h
+++ b/core/crypto/crypto.h
@@ -67,6 +67,23 @@ public:
virtual Error save(String p_path) = 0;
};
+class HMACContext : public Reference {
+ GDCLASS(HMACContext, Reference);
+
+protected:
+ static void _bind_methods();
+ static HMACContext *(*_create)();
+
+public:
+ static HMACContext *create();
+
+ virtual Error start(HashingContext::HashType p_hash_type, PackedByteArray p_key) = 0;
+ virtual Error update(PackedByteArray p_data) = 0;
+ virtual PackedByteArray finish() = 0;
+
+ HMACContext() {}
+};
+
class Crypto : public Reference {
GDCLASS(Crypto, Reference);
@@ -88,6 +105,12 @@ public:
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;
+ PackedByteArray hmac_digest(HashingContext::HashType p_hash_type, PackedByteArray p_key, PackedByteArray p_msg);
+
+ // Compares two PackedByteArrays for equality without leaking timing information in order to prevent timing attacks.
+ // @see: https://paragonie.com/blog/2015/11/preventing-timing-attacks-on-string-comparison-with-double-hmac-strategy
+ bool constant_time_compare(PackedByteArray p_trusted, PackedByteArray p_received);
+
Crypto() {}
};
diff --git a/core/doc_data.cpp b/core/doc_data.cpp
new file mode 100644
index 0000000000..d84ac6d05b
--- /dev/null
+++ b/core/doc_data.cpp
@@ -0,0 +1,126 @@
+/*************************************************************************/
+/* doc_data.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 "doc_data.h"
+
+void DocData::return_doc_from_retinfo(DocData::MethodDoc &p_method, const PropertyInfo &p_retinfo) {
+ if (p_retinfo.type == Variant::INT && p_retinfo.usage & PROPERTY_USAGE_CLASS_IS_ENUM) {
+ p_method.return_enum = p_retinfo.class_name;
+ if (p_method.return_enum.begins_with("_")) { //proxy class
+ p_method.return_enum = p_method.return_enum.substr(1, p_method.return_enum.length());
+ }
+ p_method.return_type = "int";
+ } else if (p_retinfo.class_name != StringName()) {
+ p_method.return_type = p_retinfo.class_name;
+ } else if (p_retinfo.type == Variant::ARRAY && p_retinfo.hint == PROPERTY_HINT_ARRAY_TYPE) {
+ p_method.return_type = p_retinfo.hint_string + "[]";
+ } else if (p_retinfo.hint == PROPERTY_HINT_RESOURCE_TYPE) {
+ p_method.return_type = p_retinfo.hint_string;
+ } else if (p_retinfo.type == Variant::NIL && p_retinfo.usage & PROPERTY_USAGE_NIL_IS_VARIANT) {
+ p_method.return_type = "Variant";
+ } else if (p_retinfo.type == Variant::NIL) {
+ p_method.return_type = "void";
+ } else {
+ p_method.return_type = Variant::get_type_name(p_retinfo.type);
+ }
+}
+
+void DocData::argument_doc_from_arginfo(DocData::ArgumentDoc &p_argument, const PropertyInfo &p_arginfo) {
+ p_argument.name = p_arginfo.name;
+
+ if (p_arginfo.type == Variant::INT && p_arginfo.usage & PROPERTY_USAGE_CLASS_IS_ENUM) {
+ p_argument.enumeration = p_arginfo.class_name;
+ if (p_argument.enumeration.begins_with("_")) { //proxy class
+ p_argument.enumeration = p_argument.enumeration.substr(1, p_argument.enumeration.length());
+ }
+ p_argument.type = "int";
+ } else if (p_arginfo.class_name != StringName()) {
+ p_argument.type = p_arginfo.class_name;
+ } else if (p_arginfo.type == Variant::ARRAY && p_arginfo.hint == PROPERTY_HINT_ARRAY_TYPE) {
+ p_argument.type = p_arginfo.hint_string + "[]";
+ } else if (p_arginfo.hint == PROPERTY_HINT_RESOURCE_TYPE) {
+ p_argument.type = p_arginfo.hint_string;
+ } else if (p_arginfo.type == Variant::NIL) {
+ // Parameters cannot be void, so PROPERTY_USAGE_NIL_IS_VARIANT is not necessary
+ p_argument.type = "Variant";
+ } else {
+ p_argument.type = Variant::get_type_name(p_arginfo.type);
+ }
+}
+
+void DocData::property_doc_from_scriptmemberinfo(DocData::PropertyDoc &p_property, const ScriptMemberInfo &p_memberinfo) {
+ p_property.name = p_memberinfo.propinfo.name;
+ p_property.description = p_memberinfo.doc_string;
+
+ if (p_memberinfo.propinfo.type == Variant::OBJECT) {
+ p_property.type = p_memberinfo.propinfo.class_name;
+ } else if (p_memberinfo.propinfo.type == Variant::NIL && p_memberinfo.propinfo.usage & PROPERTY_USAGE_NIL_IS_VARIANT) {
+ p_property.type = "Variant";
+ } else {
+ p_property.type = Variant::get_type_name(p_memberinfo.propinfo.type);
+ }
+
+ p_property.setter = p_memberinfo.setter;
+ p_property.getter = p_memberinfo.getter;
+
+ if (p_memberinfo.has_default_value && p_memberinfo.default_value.get_type() != Variant::OBJECT) {
+ p_property.default_value = p_memberinfo.default_value.get_construct_string().replace("\n", "");
+ }
+
+ p_property.overridden = false;
+}
+
+void DocData::method_doc_from_methodinfo(DocData::MethodDoc &p_method, const MethodInfo &p_methodinfo, const String &p_desc) {
+ p_method.name = p_methodinfo.name;
+ p_method.description = p_desc;
+
+ return_doc_from_retinfo(p_method, p_methodinfo.return_val);
+
+ for (int i = 0; i < p_methodinfo.arguments.size(); i++) {
+ DocData::ArgumentDoc argument;
+ argument_doc_from_arginfo(argument, p_methodinfo.arguments[i]);
+ int default_arg_index = i - (p_methodinfo.arguments.size() - p_methodinfo.default_arguments.size());
+ if (default_arg_index >= 0) {
+ Variant default_arg = p_methodinfo.default_arguments[default_arg_index];
+ argument.default_value = default_arg.get_construct_string();
+ }
+ p_method.arguments.push_back(argument);
+ }
+}
+
+void DocData::constant_doc_from_variant(DocData::ConstantDoc &p_const, const StringName &p_name, const Variant &p_value, const String &p_desc) {
+ p_const.name = p_name;
+ p_const.value = p_value;
+ p_const.description = p_desc;
+}
+
+void DocData::signal_doc_from_methodinfo(DocData::MethodDoc &p_signal, const MethodInfo &p_methodinfo, const String &p_desc) {
+ return method_doc_from_methodinfo(p_signal, p_methodinfo, p_desc);
+}
diff --git a/core/doc_data.h b/core/doc_data.h
new file mode 100644
index 0000000000..65b57d1381
--- /dev/null
+++ b/core/doc_data.h
@@ -0,0 +1,152 @@
+/*************************************************************************/
+/* doc_data.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 DOC_DATA_H
+#define DOC_DATA_H
+
+#include "core/io/xml_parser.h"
+#include "core/templates/map.h"
+#include "core/variant/variant.h"
+
+struct ScriptMemberInfo {
+ PropertyInfo propinfo;
+ String doc_string;
+ StringName setter;
+ StringName getter;
+
+ bool has_default_value = false;
+ Variant default_value;
+};
+
+class DocData {
+public:
+ struct ArgumentDoc {
+ String name;
+ String type;
+ String enumeration;
+ String default_value;
+ bool operator<(const ArgumentDoc &p_arg) const {
+ if (name == p_arg.name) {
+ return type < p_arg.type;
+ }
+ return name < p_arg.name;
+ }
+ };
+
+ struct MethodDoc {
+ String name;
+ String return_type;
+ String return_enum;
+ String qualifiers;
+ String description;
+ Vector<ArgumentDoc> arguments;
+ bool operator<(const MethodDoc &p_method) const {
+ if (name == p_method.name) {
+ // Must be a constructor since there is no overloading.
+ // We want this arbitrary order for a class "Foo":
+ // - 1. Default constructor: Foo()
+ // - 2. Copy constructor: Foo(Foo)
+ // - 3+. Other constructors Foo(Bar, ...) based on first argument's name
+ if (arguments.size() == 0 || p_method.arguments.size() == 0) { // 1.
+ return arguments.size() < p_method.arguments.size();
+ }
+ if (arguments[0].type == return_type || p_method.arguments[0].type == p_method.return_type) { // 2.
+ return (arguments[0].type == return_type) || (p_method.arguments[0].type != p_method.return_type);
+ }
+ return arguments[0] < p_method.arguments[0];
+ }
+ return name < p_method.name;
+ }
+ };
+
+ struct ConstantDoc {
+ String name;
+ String value;
+ bool is_value_valid = false;
+ String enumeration;
+ String description;
+ bool operator<(const ConstantDoc &p_const) const {
+ return name < p_const.name;
+ }
+ };
+
+ struct EnumDoc {
+ String name = "@unnamed_enum";
+ String description;
+ Vector<DocData::ConstantDoc> values;
+ };
+
+ struct PropertyDoc {
+ String name;
+ String type;
+ String enumeration;
+ String description;
+ String setter, getter;
+ String default_value;
+ bool overridden = false;
+ bool operator<(const PropertyDoc &p_prop) const {
+ return name < p_prop.name;
+ }
+ };
+
+ struct TutorialDoc {
+ String link;
+ String title;
+ };
+
+ struct ClassDoc {
+ String name;
+ String inherits;
+ String category;
+ String brief_description;
+ String description;
+ Vector<TutorialDoc> tutorials;
+ Vector<MethodDoc> methods;
+ Vector<MethodDoc> signals;
+ Vector<ConstantDoc> constants;
+ Map<String, String> enums;
+ Vector<PropertyDoc> properties;
+ Vector<PropertyDoc> theme_properties;
+ bool is_script_doc = false;
+ String script_path;
+ bool operator<(const ClassDoc &p_class) const {
+ return name < p_class.name;
+ }
+ };
+
+ static void return_doc_from_retinfo(DocData::MethodDoc &p_method, const PropertyInfo &p_retinfo);
+ static void argument_doc_from_arginfo(DocData::ArgumentDoc &p_argument, const PropertyInfo &p_arginfo);
+ static void property_doc_from_scriptmemberinfo(DocData::PropertyDoc &p_property, const ScriptMemberInfo &p_memberinfo);
+ static void method_doc_from_methodinfo(DocData::MethodDoc &p_method, const MethodInfo &p_methodinfo, const String &p_desc);
+ static void constant_doc_from_variant(DocData::ConstantDoc &p_const, const StringName &p_name, const Variant &p_value, const String &p_desc);
+ static void signal_doc_from_methodinfo(DocData::MethodDoc &p_signal, const MethodInfo &p_methodinfo, const String &p_desc);
+};
+
+#endif // DOC_DATA_H
diff --git a/core/input/input.cpp b/core/input/input.cpp
index 00a7e63a73..153656e44a 100644
--- a/core/input/input.cpp
+++ b/core/input/input.cpp
@@ -1211,7 +1211,7 @@ void Input::parse_mapping(String p_mapping) {
ERR_CONTINUE_MSG(output.length() < 1 || input.length() < 2,
String(entry[idx] + "\nInvalid device mapping entry: " + entry[idx]));
- if (output == "platform") {
+ if (output == "platform" || output == "hint") {
continue;
}
diff --git a/core/input/input_event.cpp b/core/input/input_event.cpp
index 41bc5e84b0..82bfaa82a5 100644
--- a/core/input/input_event.cpp
+++ b/core/input/input_event.cpp
@@ -84,10 +84,6 @@ Ref<InputEvent> InputEvent::xformed_by(const Transform2D &p_xform, const Vector2
return Ref<InputEvent>((InputEvent *)this);
}
-String InputEvent::as_text() const {
- return String();
-}
-
bool InputEvent::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const {
return false;
}
@@ -198,6 +194,33 @@ void InputEventWithModifiers::set_modifiers_from_event(const InputEventWithModif
set_metakey(event->get_metakey());
}
+String InputEventWithModifiers::as_text() const {
+ Vector<String> mod_names;
+
+ if (get_control()) {
+ mod_names.push_back(find_keycode_name(KEY_CONTROL));
+ }
+ if (get_shift()) {
+ mod_names.push_back(find_keycode_name(KEY_SHIFT));
+ }
+ if (get_alt()) {
+ mod_names.push_back(find_keycode_name(KEY_ALT));
+ }
+ if (get_metakey()) {
+ mod_names.push_back(find_keycode_name(KEY_META));
+ }
+
+ if (!mod_names.empty()) {
+ return String("+").join(mod_names);
+ } else {
+ return "";
+ }
+}
+
+String InputEventWithModifiers::to_string() {
+ return as_text();
+}
+
void InputEventWithModifiers::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_store_command", "enable"), &InputEventWithModifiers::set_store_command);
ClassDB::bind_method(D_METHOD("is_storing_command"), &InputEventWithModifiers::is_storing_command);
@@ -326,24 +349,39 @@ uint32_t InputEventKey::get_physical_keycode_with_modifiers() const {
}
String InputEventKey::as_text() const {
- String kc = keycode_get_string(keycode);
+ String kc;
+
+ if (keycode == 0) {
+ kc = keycode_get_string(physical_keycode) + " (" + RTR("Physical") + ")";
+ } else {
+ kc = keycode_get_string(keycode);
+ }
+
if (kc == String()) {
return kc;
}
- if (get_metakey()) {
- kc = find_keycode_name(KEY_META) + ("+" + kc);
- }
- if (get_alt()) {
- kc = find_keycode_name(KEY_ALT) + ("+" + kc);
- }
- if (get_shift()) {
- kc = find_keycode_name(KEY_SHIFT) + ("+" + kc);
- }
- if (get_control()) {
- kc = find_keycode_name(KEY_CONTROL) + ("+" + kc);
+ String mods_text = InputEventWithModifiers::as_text();
+ return mods_text == "" ? kc : mods_text + "+" + kc;
+}
+
+String InputEventKey::to_string() {
+ String p = is_pressed() ? "true" : "false";
+ String e = is_echo() ? "true" : "false";
+
+ String kc = "";
+ String physical = "false";
+ if (keycode == 0) {
+ kc = itos(physical_keycode) + " " + keycode_get_string(physical_keycode);
+ physical = "true";
+ } else {
+ kc = itos(keycode) + " " + keycode_get_string(keycode);
}
- return kc;
+
+ String mods = InputEventWithModifiers::as_text();
+ mods = mods == "" ? TTR("None") : mods;
+
+ return vformat("InputEventKey: keycode=%s mods=%s physical=%s pressed=%s echo=%s", kc, mods, physical, p, e);
}
bool InputEventKey::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const {
@@ -536,41 +574,79 @@ bool InputEventMouseButton::action_match(const Ref<InputEvent> &p_event, bool *p
return match;
}
+static const char *_mouse_button_descriptions[9] = {
+ TTRC("Left Mouse Button"),
+ TTRC("Right Mouse Button"),
+ TTRC("Middle Mouse Button"),
+ TTRC("Mouse Wheel Up"),
+ TTRC("Mouse Wheel Down"),
+ TTRC("Mouse Wheel Left"),
+ TTRC("Mouse Wheel Right"),
+ TTRC("Mouse Thumb Button 1"),
+ TTRC("Mouse Thumb Button 2")
+};
+
String InputEventMouseButton::as_text() const {
- String button_index_string = "";
- switch (get_button_index()) {
+ // Modifiers
+ String mods_text = InputEventWithModifiers::as_text();
+ String full_string = mods_text == "" ? "" : mods_text + "+";
+
+ // Button
+ int idx = get_button_index();
+ switch (idx) {
case BUTTON_LEFT:
- button_index_string = "BUTTON_LEFT";
- break;
case BUTTON_RIGHT:
- button_index_string = "BUTTON_RIGHT";
- break;
case BUTTON_MIDDLE:
- button_index_string = "BUTTON_MIDDLE";
- break;
case BUTTON_WHEEL_UP:
- button_index_string = "BUTTON_WHEEL_UP";
- break;
case BUTTON_WHEEL_DOWN:
- button_index_string = "BUTTON_WHEEL_DOWN";
- break;
case BUTTON_WHEEL_LEFT:
- button_index_string = "BUTTON_WHEEL_LEFT";
- break;
case BUTTON_WHEEL_RIGHT:
- button_index_string = "BUTTON_WHEEL_RIGHT";
- break;
case BUTTON_XBUTTON1:
- button_index_string = "BUTTON_XBUTTON1";
+ case BUTTON_XBUTTON2:
+ full_string += RTR(_mouse_button_descriptions[idx - 1]); // button index starts from 1, array index starts from 0, so subtract 1
+ break;
+ default:
+ full_string += RTR("Button") + " #" + itos(idx);
break;
+ }
+
+ // Double Click
+ if (doubleclick) {
+ full_string += " (" + RTR("Double Click") + ")";
+ }
+
+ return full_string;
+}
+
+String InputEventMouseButton::to_string() {
+ String p = is_pressed() ? "true" : "false";
+ String d = doubleclick ? "true" : "false";
+
+ int idx = get_button_index();
+ String button_string = itos(idx);
+
+ switch (idx) {
+ case BUTTON_LEFT:
+ case BUTTON_RIGHT:
+ case BUTTON_MIDDLE:
+ case BUTTON_WHEEL_UP:
+ case BUTTON_WHEEL_DOWN:
+ case BUTTON_WHEEL_LEFT:
+ case BUTTON_WHEEL_RIGHT:
+ case BUTTON_XBUTTON1:
case BUTTON_XBUTTON2:
- button_index_string = "BUTTON_XBUTTON2";
+ button_string += " (" + RTR(_mouse_button_descriptions[idx - 1]) + ")"; // button index starts from 1, array index starts from 0, so subtract 1
break;
default:
- button_index_string = itos(get_button_index());
break;
}
- return "InputEventMouseButton : button_index=" + button_index_string + ", pressed=" + (pressed ? "true" : "false") + ", position=(" + String(get_position()) + "), button_mask=" + itos(get_button_mask()) + ", doubleclick=" + (doubleclick ? "true" : "false");
+
+ String mods = InputEventWithModifiers::as_text();
+ mods = mods == "" ? TTR("None") : mods;
+
+ // Work around the fact vformat can only take 5 substitutions but 6 need to be passed.
+ String index_and_mods = vformat("button_index=%s mods=%s", button_index, mods);
+ return vformat("InputEventMouseButton: %s pressed=%s position=(%s) button_mask=%s doubleclick=%s", index_and_mods, p, String(get_position()), itos(get_button_mask()), d);
}
void InputEventMouseButton::_bind_methods() {
@@ -653,27 +729,32 @@ Ref<InputEvent> InputEventMouseMotion::xformed_by(const Transform2D &p_xform, co
}
String InputEventMouseMotion::as_text() const {
- String button_mask_string = "";
+ return vformat(RTR("Mouse motion at position (%s) with speed (%s)"), String(get_position()), String(get_speed()));
+}
+
+String InputEventMouseMotion::to_string() {
+ int button_mask = get_button_mask();
+ String button_mask_string = itos(button_mask);
switch (get_button_mask()) {
case BUTTON_MASK_LEFT:
- button_mask_string = "BUTTON_MASK_LEFT";
+ button_mask_string += " (" + RTR(_mouse_button_descriptions[BUTTON_LEFT - 1]) + ")";
break;
case BUTTON_MASK_MIDDLE:
- button_mask_string = "BUTTON_MASK_MIDDLE";
+ button_mask_string += " (" + RTR(_mouse_button_descriptions[BUTTON_MIDDLE - 1]) + ")";
break;
case BUTTON_MASK_RIGHT:
- button_mask_string = "BUTTON_MASK_RIGHT";
+ button_mask_string += " (" + RTR(_mouse_button_descriptions[BUTTON_RIGHT - 1]) + ")";
break;
case BUTTON_MASK_XBUTTON1:
- button_mask_string = "BUTTON_MASK_XBUTTON1";
+ button_mask_string += " (" + RTR(_mouse_button_descriptions[BUTTON_XBUTTON1 - 1]) + ")";
break;
case BUTTON_MASK_XBUTTON2:
- button_mask_string = "BUTTON_MASK_XBUTTON2";
+ button_mask_string += " (" + RTR(_mouse_button_descriptions[BUTTON_XBUTTON2 - 1]) + ")";
break;
default:
- button_mask_string = itos(get_button_mask());
break;
}
+
return "InputEventMouseMotion : button_mask=" + button_mask_string + ", position=(" + String(get_position()) + "), relative=(" + String(get_relative()) + "), speed=(" + String(get_speed()) + "), pressure=(" + rtos(get_pressure()) + "), tilt=(" + String(get_tilt()) + ")";
}
@@ -796,7 +877,26 @@ bool InputEventJoypadMotion::action_match(const Ref<InputEvent> &p_event, bool *
return match;
}
+static const char *_joy_axis_descriptions[JOY_AXIS_MAX] = {
+ TTRC("Left Stick X-Axis, Joystick 0 X-Axis"),
+ TTRC("Left Stick Y-Axis, Joystick 0 Y-Axis"),
+ TTRC("Right Stick X-Axis, Joystick 1 X-Axis"),
+ TTRC("Right Stick Y-Axis, Joystick 1 Y-Axis"),
+ TTRC("Joystick 2 X-Axis, Left Trigger, Sony L2, Xbox LT"),
+ TTRC("Joystick 2 Y-Axis, Right Trigger, Sony R2, Xbox RT"),
+ TTRC("Joystick 3 X-Axis"),
+ TTRC("Joystick 3 Y-Axis"),
+ TTRC("Joystick 4 X-Axis"),
+ TTRC("Joystick 4 Y-Axis"),
+};
+
String InputEventJoypadMotion::as_text() const {
+ String desc = axis < JOY_AXIS_MAX ? RTR(_joy_axis_descriptions[axis]) : TTR("Unknown Joypad Axis");
+
+ return vformat(TTR("Joypad Motion on Axis %s (%s) with Value %s"), itos(axis), desc, String(Variant(axis_value)));
+}
+
+String InputEventJoypadMotion::to_string() {
return "InputEventJoypadMotion : axis=" + itos(axis) + ", axis_value=" + String(Variant(axis_value));
}
@@ -869,7 +969,39 @@ bool InputEventJoypadButton::shortcut_match(const Ref<InputEvent> &p_event) cons
return button_index == button->button_index;
}
+static const char *_joy_button_descriptions[JOY_BUTTON_SDL_MAX] = {
+ TTRC("Bottom Action, Sony Cross, Xbox A, Nintendo B"),
+ TTRC("Right Action, Sony Circle, Xbox B, Nintendo A"),
+ TTRC("Left Action, Sony Square, Xbox X, Nintendo Y"),
+ TTRC("Top Action, Sony Triangle, Xbox Y, Nintendo X"),
+ TTRC("Back, Sony Select, Xbox Back, Nintendo -"),
+ TTRC("Guide, Sony PS, Xbox Home"),
+ TTRC("Start, Nintendo +"),
+ TTRC("Left Stick, Sony L3, Xbox L/LS"),
+ TTRC("Right Stick, Sony R3, Xbox R/RS"),
+ TTRC("Left Shoulder, Sony L1, Xbox LB"),
+ TTRC("Right Shoulder, Sony R1, Xbox RB"),
+ TTRC("D-pad Up"),
+ TTRC("D-pad Down"),
+ TTRC("D-pad Left"),
+ TTRC("D-pad Right"),
+};
+
String InputEventJoypadButton::as_text() const {
+ String text = "Joypad Button " + itos(button_index);
+
+ if (button_index < JOY_BUTTON_SDL_MAX) {
+ text += vformat(" (%s)", _joy_button_descriptions[button_index]);
+ }
+
+ if (pressure != 0) {
+ text += ", Pressure:" + String(Variant(pressure));
+ }
+
+ return text;
+}
+
+String InputEventJoypadButton::to_string() {
return "InputEventJoypadButton : button_index=" + itos(button_index) + ", pressed=" + (pressed ? "true" : "false") + ", pressure=" + String(Variant(pressure));
}
@@ -927,6 +1059,12 @@ Ref<InputEvent> InputEventScreenTouch::xformed_by(const Transform2D &p_xform, co
}
String InputEventScreenTouch::as_text() const {
+ String status = pressed ? RTR("touched") : RTR("released");
+
+ return vformat(RTR("Screen %s at (%s) with %s touch points"), status, String(get_position()), itos(index));
+}
+
+String InputEventScreenTouch::to_string() {
return "InputEventScreenTouch : index=" + itos(index) + ", pressed=" + (pressed ? "true" : "false") + ", position=(" + String(get_position()) + ")";
}
@@ -996,6 +1134,10 @@ Ref<InputEvent> InputEventScreenDrag::xformed_by(const Transform2D &p_xform, con
}
String InputEventScreenDrag::as_text() const {
+ return vformat(RTR("Screen dragged with %s touch points at position (%s) with speed of (%s)"), itos(index), String(get_position()), String(get_speed()));
+}
+
+String InputEventScreenDrag::to_string() {
return "InputEventScreenDrag : index=" + itos(index) + ", position=(" + String(get_position()) + "), relative=(" + String(get_relative()) + "), speed=(" + String(get_speed()) + ")";
}
@@ -1079,6 +1221,10 @@ bool InputEventAction::action_match(const Ref<InputEvent> &p_event, bool *p_pres
}
String InputEventAction::as_text() const {
+ return vformat(RTR("Input Action %s was %s"), action, pressed ? "pressed" : "released");
+}
+
+String InputEventAction::to_string() {
return "InputEventAction : action=" + action + ", pressed=(" + (pressed ? "true" : "false");
}
@@ -1142,6 +1288,10 @@ Ref<InputEvent> InputEventMagnifyGesture::xformed_by(const Transform2D &p_xform,
}
String InputEventMagnifyGesture::as_text() const {
+ return vformat(RTR("Magnify Gesture at (%s) with factor %s"), String(get_position()), rtos(get_factor()));
+}
+
+String InputEventMagnifyGesture::to_string() {
return "InputEventMagnifyGesture : factor=" + rtos(get_factor()) + ", position=(" + String(get_position()) + ")";
}
@@ -1178,6 +1328,10 @@ Ref<InputEvent> InputEventPanGesture::xformed_by(const Transform2D &p_xform, con
}
String InputEventPanGesture::as_text() const {
+ return vformat(RTR("Pan Gesture at (%s) with delta (%s)"), String(get_position()), String(get_delta()));
+}
+
+String InputEventPanGesture::to_string() {
return "InputEventPanGesture : delta=(" + String(get_delta()) + "), position=(" + String(get_position()) + ")";
}
@@ -1255,7 +1409,11 @@ int InputEventMIDI::get_controller_value() const {
}
String InputEventMIDI::as_text() const {
- return "InputEventMIDI : channel=(" + itos(get_channel()) + "), message=(" + itos(get_message()) + ")";
+ return vformat(RTR("MIDI Input on Channel=%s Message=%s"), itos(channel), itos(message));
+}
+
+String InputEventMIDI::to_string() {
+ return vformat("InputEvenMIDI: channel=%s message=%s pitch=%s velocity=%s pressure=%s", itos(channel), itos(message), itos(pitch), itos(velocity), itos(pressure));
}
void InputEventMIDI::_bind_methods() {
diff --git a/core/input/input_event.h b/core/input/input_event.h
index 0eae3a2bbe..6a71a24c8b 100644
--- a/core/input/input_event.h
+++ b/core/input/input_event.h
@@ -132,7 +132,7 @@ public:
virtual bool is_pressed() const;
virtual bool is_echo() const;
- virtual String as_text() const;
+ virtual String as_text() const = 0;
virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const;
@@ -207,6 +207,9 @@ public:
void set_modifiers_from_event(const InputEventWithModifiers *event);
+ virtual String as_text() const override;
+ virtual String to_string() override;
+
InputEventWithModifiers() {}
};
@@ -249,6 +252,7 @@ public:
virtual bool is_action_type() const override { return true; }
virtual String as_text() const override;
+ virtual String to_string() override;
InputEventKey() {}
};
@@ -306,6 +310,7 @@ public:
virtual bool is_action_type() const override { return true; }
virtual String as_text() const override;
+ virtual String to_string() override;
InputEventMouseButton() {}
};
@@ -336,6 +341,7 @@ public:
virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const override;
virtual String as_text() const override;
+ virtual String to_string() override;
virtual bool accumulate(const Ref<InputEvent> &p_event) override;
@@ -363,6 +369,7 @@ public:
virtual bool is_action_type() const override { return true; }
virtual String as_text() const override;
+ virtual String to_string() override;
InputEventJoypadMotion() {}
};
@@ -391,6 +398,7 @@ public:
virtual bool is_action_type() const override { return true; }
virtual String as_text() const override;
+ virtual String to_string() override;
InputEventJoypadButton() {}
};
@@ -416,6 +424,7 @@ public:
virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const override;
virtual String as_text() const override;
+ virtual String to_string() override;
InputEventScreenTouch() {}
};
@@ -445,6 +454,7 @@ public:
virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const override;
virtual String as_text() const override;
+ virtual String to_string() override;
InputEventScreenDrag() {}
};
@@ -476,6 +486,7 @@ public:
virtual bool shortcut_match(const Ref<InputEvent> &p_event) const override;
virtual bool is_action_type() const override { return true; }
virtual String as_text() const override;
+ virtual String to_string() override;
InputEventAction() {}
};
@@ -506,6 +517,7 @@ public:
virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const override;
virtual String as_text() const override;
+ virtual String to_string() override;
InputEventMagnifyGesture() {}
};
@@ -523,6 +535,7 @@ public:
virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const override;
virtual String as_text() const override;
+ virtual String to_string() override;
InputEventPanGesture() {}
};
@@ -568,6 +581,7 @@ public:
int get_controller_value() const;
virtual String as_text() const override;
+ virtual String to_string() override;
InputEventMIDI() {}
};
diff --git a/core/io/compression.cpp b/core/io/compression.cpp
index cd8793bb0a..8e613cb3ce 100644
--- a/core/io/compression.cpp
+++ b/core/io/compression.cpp
@@ -257,13 +257,13 @@ int Compression::decompress_dynamic(Vector<uint8_t> *p_dst_vect, int p_max_dst_s
} while (ret != Z_STREAM_END);
// If all done successfully, resize the output if it's larger than the actual output
- if (ret == Z_STREAM_END && (unsigned long)p_dst_vect->size() > strm.total_out) {
+ if ((unsigned long)p_dst_vect->size() > strm.total_out) {
p_dst_vect->resize(strm.total_out);
}
// clean up and return
(void)inflateEnd(&strm);
- return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR;
+ return Z_OK;
}
int Compression::zlib_level = Z_DEFAULT_COMPRESSION;
diff --git a/core/io/file_access_buffered.cpp b/core/io/file_access_buffered.cpp
deleted file mode 100644
index 714f3b6099..0000000000
--- a/core/io/file_access_buffered.cpp
+++ /dev/null
@@ -1,150 +0,0 @@
-/*************************************************************************/
-/* file_access_buffered.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 "file_access_buffered.h"
-
-#include "core/error/error_macros.h"
-
-Error FileAccessBuffered::set_error(Error p_error) const {
- return (last_error = p_error);
-}
-
-void FileAccessBuffered::set_cache_size(int p_size) {
- cache_size = p_size;
-}
-
-int FileAccessBuffered::get_cache_size() {
- return cache_size;
-}
-
-int FileAccessBuffered::cache_data_left() const {
- if (file.offset >= file.size) {
- return 0;
- }
-
- if (cache.offset == -1 || file.offset < cache.offset || file.offset >= cache.offset + cache.buffer.size()) {
- return read_data_block(file.offset, cache_size);
- }
-
- return cache.buffer.size() - (file.offset - cache.offset);
-}
-
-void FileAccessBuffered::seek(size_t p_position) {
- file.offset = p_position;
-}
-
-void FileAccessBuffered::seek_end(int64_t p_position) {
- file.offset = file.size + p_position;
-}
-
-size_t FileAccessBuffered::get_position() const {
- return file.offset;
-}
-
-size_t FileAccessBuffered::get_len() const {
- return file.size;
-}
-
-bool FileAccessBuffered::eof_reached() const {
- return file.offset > file.size;
-}
-
-uint8_t FileAccessBuffered::get_8() const {
- ERR_FAIL_COND_V_MSG(!file.open, 0, "Can't get data, when file is not opened.");
-
- uint8_t byte = 0;
- if (cache_data_left() >= 1) {
- byte = cache.buffer[file.offset - cache.offset];
- }
-
- ++file.offset;
-
- return byte;
-}
-
-int FileAccessBuffered::get_buffer(uint8_t *p_dest, int p_length) const {
- ERR_FAIL_COND_V_MSG(!file.open, -1, "Can't get buffer, when file is not opened.");
-
- if (p_length > cache_size) {
- int total_read = 0;
-
- if (!(cache.offset == -1 || file.offset < cache.offset || file.offset >= cache.offset + cache.buffer.size())) {
- int size = (cache.buffer.size() - (file.offset - cache.offset));
- size = size - (size % 4);
- //const uint8_t* read = cache.buffer.ptr();
- //memcpy(p_dest, read.ptr() + (file.offset - cache.offset), size);
- memcpy(p_dest, cache.buffer.ptr() + (file.offset - cache.offset), size);
- p_dest += size;
- p_length -= size;
- file.offset += size;
- total_read += size;
- }
-
- int err = read_data_block(file.offset, p_length, p_dest);
- if (err >= 0) {
- total_read += err;
- file.offset += err;
- }
-
- return total_read;
- }
-
- int to_read = p_length;
- int total_read = 0;
- while (to_read > 0) {
- int left = cache_data_left();
- if (left == 0) {
- file.offset += to_read;
- return total_read;
- }
- if (left < 0) {
- return left;
- }
-
- int r = MIN(left, to_read);
- //const uint8_t* read = cache.buffer.ptr();
- //memcpy(p_dest+total_read, &read.ptr()[file.offset - cache.offset], r);
- memcpy(p_dest + total_read, cache.buffer.ptr() + (file.offset - cache.offset), r);
-
- file.offset += r;
- total_read += r;
- to_read -= r;
- }
-
- return p_length;
-}
-
-bool FileAccessBuffered::is_open() const {
- return file.open;
-}
-
-Error FileAccessBuffered::get_error() const {
- return last_error;
-}
diff --git a/core/io/file_access_buffered.h b/core/io/file_access_buffered.h
deleted file mode 100644
index 7fd99b6373..0000000000
--- a/core/io/file_access_buffered.h
+++ /dev/null
@@ -1,91 +0,0 @@
-/*************************************************************************/
-/* file_access_buffered.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 FILE_ACCESS_BUFFERED_H
-#define FILE_ACCESS_BUFFERED_H
-
-#include "core/os/file_access.h"
-
-#include "core/string/ustring.h"
-
-class FileAccessBuffered : public FileAccess {
-public:
- enum {
- DEFAULT_CACHE_SIZE = 128 * 1024,
- };
-
-private:
- int cache_size = DEFAULT_CACHE_SIZE;
-
- int cache_data_left() const;
- mutable Error last_error;
-
-protected:
- Error set_error(Error p_error) const;
-
- mutable struct File {
- bool open = false;
- int size = 0;
- int offset = 0;
- String name;
- int access_flags = 0;
- } file;
-
- mutable struct Cache {
- Vector<uint8_t> buffer;
- int offset = 0;
- } cache;
-
- virtual int read_data_block(int p_offset, int p_size, uint8_t *p_dest = nullptr) const = 0;
-
- void set_cache_size(int p_size);
- int get_cache_size();
-
-public:
- virtual size_t get_position() const; ///< get position in the file
- virtual size_t get_len() const; ///< get size of the file
-
- virtual void seek(size_t p_position); ///< seek to a given position
- virtual void seek_end(int64_t p_position = 0); ///< seek from the end of file
-
- virtual bool eof_reached() const;
-
- virtual uint8_t get_8() const;
- virtual int get_buffer(uint8_t *p_dest, int p_length) const; ///< get an array of bytes
-
- virtual bool is_open() const;
-
- virtual Error get_error() const;
-
- FileAccessBuffered() {}
- virtual ~FileAccessBuffered() {}
-};
-
-#endif
diff --git a/core/io/file_access_buffered_fa.h b/core/io/file_access_buffered_fa.h
deleted file mode 100644
index f22e54e154..0000000000
--- a/core/io/file_access_buffered_fa.h
+++ /dev/null
@@ -1,139 +0,0 @@
-/*************************************************************************/
-/* file_access_buffered_fa.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 FILE_ACCESS_BUFFERED_FA_H
-#define FILE_ACCESS_BUFFERED_FA_H
-
-#include "core/io/file_access_buffered.h"
-
-template <class T>
-class FileAccessBufferedFA : public FileAccessBuffered {
- T f;
-
- int read_data_block(int p_offset, int p_size, uint8_t *p_dest = 0) const {
- ERR_FAIL_COND_V_MSG(!f.is_open(), -1, "Can't read data block when file is not opened.");
-
- ((T *)&f)->seek(p_offset);
-
- if (p_dest) {
- f.get_buffer(p_dest, p_size);
- return p_size;
-
- } else {
- cache.offset = p_offset;
- cache.buffer.resize(p_size);
-
- // on Vector
- //uint8_t* write = cache.buffer.ptrw();
- //f.get_buffer(write.ptrw(), p_size);
-
- // on vector
- f.get_buffer(cache.buffer.ptrw(), p_size);
-
- return p_size;
- }
- }
-
- static FileAccess *create() {
- return memnew(FileAccessBufferedFA<T>());
- }
-
-protected:
- virtual void _set_access_type(AccessType p_access) {
- f._set_access_type(p_access);
- FileAccessBuffered::_set_access_type(p_access);
- }
-
-public:
- void flush() {
- f.flush();
- }
-
- void store_8(uint8_t p_dest) {
- f.store_8(p_dest);
- }
-
- void store_buffer(const uint8_t *p_src, int p_length) {
- f.store_buffer(p_src, p_length);
- }
-
- bool file_exists(const String &p_name) {
- return f.file_exists(p_name);
- }
-
- Error _open(const String &p_path, int p_mode_flags) {
- close();
-
- Error ret = f._open(p_path, p_mode_flags);
- if (ret != OK)
- return ret;
- //ERR_FAIL_COND_V( ret != OK, ret );
-
- file.size = f.get_len();
- file.offset = 0;
- file.open = true;
- file.name = p_path;
- file.access_flags = p_mode_flags;
-
- cache.buffer.resize(0);
- cache.offset = 0;
-
- return set_error(OK);
- }
-
- void close() {
- f.close();
-
- file.offset = 0;
- file.size = 0;
- file.open = false;
- file.name = "";
-
- cache.buffer.resize(0);
- cache.offset = 0;
- set_error(OK);
- }
-
- virtual uint64_t _get_modified_time(const String &p_file) {
- return f._get_modified_time(p_file);
- }
-
- virtual uint32_t _get_unix_permissions(const String &p_file) {
- return f._get_unix_permissions(p_file);
- }
-
- virtual Error _set_unix_permissions(const String &p_file, uint32_t p_permissions) {
- return f._set_unix_permissions(p_file, p_permissions);
- }
-
- FileAccessBufferedFA() {}
-};
-
-#endif // FILE_ACCESS_BUFFERED_FA_H
diff --git a/core/io/file_access_compressed.cpp b/core/io/file_access_compressed.cpp
index 4424192af2..b06b3c078f 100644
--- a/core/io/file_access_compressed.cpp
+++ b/core/io/file_access_compressed.cpp
@@ -327,14 +327,14 @@ Error FileAccessCompressed::get_error() const {
void FileAccessCompressed::flush() {
ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
- ERR_FAIL_COND_MSG(!writing, "File has not been opened in read mode.");
+ ERR_FAIL_COND_MSG(!writing, "File has not been opened in write mode.");
// compressed files keep data in memory till close()
}
void FileAccessCompressed::store_8(uint8_t p_dest) {
ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
- ERR_FAIL_COND_MSG(!writing, "File has not been opened in read mode.");
+ ERR_FAIL_COND_MSG(!writing, "File has not been opened in write mode.");
WRITE_FIT(1);
write_ptr[write_pos++] = p_dest;
diff --git a/core/io/file_access_encrypted.cpp b/core/io/file_access_encrypted.cpp
index 2ac24d5169..cf5800b472 100644
--- a/core/io/file_access_encrypted.cpp
+++ b/core/io/file_access_encrypted.cpp
@@ -256,7 +256,7 @@ Error FileAccessEncrypted::get_error() const {
}
void FileAccessEncrypted::store_buffer(const uint8_t *p_src, int p_length) {
- ERR_FAIL_COND_MSG(!writing, "File has not been opened in read mode.");
+ ERR_FAIL_COND_MSG(!writing, "File has not been opened in write mode.");
if (pos < data.size()) {
for (int i = 0; i < p_length; i++) {
@@ -272,13 +272,13 @@ void FileAccessEncrypted::store_buffer(const uint8_t *p_src, int p_length) {
}
void FileAccessEncrypted::flush() {
- ERR_FAIL_COND_MSG(!writing, "File has not been opened in read mode.");
+ ERR_FAIL_COND_MSG(!writing, "File has not been opened in write mode.");
// encrypted files keep data in memory till close()
}
void FileAccessEncrypted::store_8(uint8_t p_dest) {
- ERR_FAIL_COND_MSG(!writing, "File has not been opened in read mode.");
+ ERR_FAIL_COND_MSG(!writing, "File has not been opened in write mode.");
if (pos < data.size()) {
data.write[pos] = p_dest;
diff --git a/core/io/file_access_zip.h b/core/io/file_access_zip.h
index eff07c60e2..f8e7c1e587 100644
--- a/core/io/file_access_zip.h
+++ b/core/io/file_access_zip.h
@@ -59,8 +59,6 @@ private:
static ZipArchive *instance;
- FileAccess::CreateFunc fa_create_func;
-
public:
void close_handle(unzFile p_file) const;
unzFile get_file_handle(String p_file) const;
diff --git a/core/io/image.cpp b/core/io/image.cpp
index 6dde25af32..7c32c02701 100644
--- a/core/io/image.cpp
+++ b/core/io/image.cpp
@@ -66,10 +66,10 @@ const char *Image::format_names[Image::FORMAT_MAX] = {
"BPTC_RGBA",
"BPTC_RGBF",
"BPTC_RGBFU",
- "PVRTC2", //pvrtc
- "PVRTC2A",
- "PVRTC4",
- "PVRTC4A",
+ "PVRTC1_2", //pvrtc
+ "PVRTC1_2A",
+ "PVRTC1_4",
+ "PVRTC1_4A",
"ETC", //etc1
"ETC2_R11", //etc2
"ETC2_R11S", //signed", NOT srgb.
@@ -155,13 +155,13 @@ int Image::get_format_pixel_size(Format p_format) {
return 1; //float /
case FORMAT_BPTC_RGBFU:
return 1; //unsigned float
- case FORMAT_PVRTC2:
+ case FORMAT_PVRTC1_2:
return 1; //pvrtc
- case FORMAT_PVRTC2A:
+ case FORMAT_PVRTC1_2A:
return 1;
- case FORMAT_PVRTC4:
+ case FORMAT_PVRTC1_4:
return 1;
- case FORMAT_PVRTC4A:
+ case FORMAT_PVRTC1_4A:
return 1;
case FORMAT_ETC:
return 1; //etc1
@@ -200,13 +200,13 @@ void Image::get_format_min_pixel_size(Format p_format, int &r_w, int &r_h) {
r_w = 4;
r_h = 4;
} break;
- case FORMAT_PVRTC2:
- case FORMAT_PVRTC2A: {
+ case FORMAT_PVRTC1_2:
+ case FORMAT_PVRTC1_2A: {
r_w = 16;
r_h = 8;
} break;
- case FORMAT_PVRTC4A:
- case FORMAT_PVRTC4: {
+ case FORMAT_PVRTC1_4A:
+ case FORMAT_PVRTC1_4: {
r_w = 8;
r_h = 8;
} break;
@@ -242,9 +242,9 @@ void Image::get_format_min_pixel_size(Format p_format, int &r_w, int &r_h) {
}
int Image::get_format_pixel_rshift(Format p_format) {
- if (p_format == FORMAT_DXT1 || p_format == FORMAT_RGTC_R || p_format == FORMAT_PVRTC4 || p_format == FORMAT_PVRTC4A || p_format == FORMAT_ETC || p_format == FORMAT_ETC2_R11 || p_format == FORMAT_ETC2_R11S || p_format == FORMAT_ETC2_RGB8 || p_format == FORMAT_ETC2_RGB8A1) {
+ if (p_format == FORMAT_DXT1 || p_format == FORMAT_RGTC_R || p_format == FORMAT_PVRTC1_4 || p_format == FORMAT_PVRTC1_4A || p_format == FORMAT_ETC || p_format == FORMAT_ETC2_R11 || p_format == FORMAT_ETC2_R11S || p_format == FORMAT_ETC2_RGB8 || p_format == FORMAT_ETC2_RGB8A1) {
return 1;
- } else if (p_format == FORMAT_PVRTC2 || p_format == FORMAT_PVRTC2A) {
+ } else if (p_format == FORMAT_PVRTC1_2 || p_format == FORMAT_PVRTC1_2A) {
return 2;
} else {
return 0;
@@ -261,12 +261,12 @@ int Image::get_format_block_size(Format p_format) {
return 4;
}
- case FORMAT_PVRTC2:
- case FORMAT_PVRTC2A: {
+ case FORMAT_PVRTC1_2:
+ case FORMAT_PVRTC1_2A: {
return 4;
}
- case FORMAT_PVRTC4A:
- case FORMAT_PVRTC4: {
+ case FORMAT_PVRTC1_4A:
+ case FORMAT_PVRTC1_4: {
return 4;
}
case FORMAT_ETC: {
@@ -2216,8 +2216,8 @@ bool Image::is_invisible() const {
} break;
- case FORMAT_PVRTC2A:
- case FORMAT_PVRTC4A:
+ case FORMAT_PVRTC1_2A:
+ case FORMAT_PVRTC1_4A:
case FORMAT_DXT3:
case FORMAT_DXT5: {
detected = true;
@@ -2258,8 +2258,8 @@ Image::AlphaMode Image::detect_alpha() const {
}
} break;
- case FORMAT_PVRTC2A:
- case FORMAT_PVRTC4A:
+ case FORMAT_PVRTC1_2A:
+ case FORMAT_PVRTC1_4A:
case FORMAT_DXT3:
case FORMAT_DXT5: {
detected = true;
@@ -2355,7 +2355,7 @@ Error Image::decompress() {
_image_decompress_bc(this);
} else if (format >= FORMAT_BPTC_RGBA && format <= FORMAT_BPTC_RGBFU && _image_decompress_bptc) {
_image_decompress_bptc(this);
- } else if (format >= FORMAT_PVRTC2 && format <= FORMAT_PVRTC4A && _image_decompress_pvrtc) {
+ } else if (format >= FORMAT_PVRTC1_2 && format <= FORMAT_PVRTC1_4A && _image_decompress_pvrtc) {
_image_decompress_pvrtc(this);
} else if (format == FORMAT_ETC && _image_decompress_etc1) {
_image_decompress_etc1(this);
@@ -2377,13 +2377,9 @@ Error Image::compress_from_channels(CompressMode p_mode, UsedChannels p_channels
ERR_FAIL_COND_V(!_image_compress_bc_func, ERR_UNAVAILABLE);
_image_compress_bc_func(this, p_lossy_quality, p_channels);
} break;
- case COMPRESS_PVRTC2: {
- ERR_FAIL_COND_V(!_image_compress_pvrtc2_func, ERR_UNAVAILABLE);
- _image_compress_pvrtc2_func(this);
- } break;
- case COMPRESS_PVRTC4: {
- ERR_FAIL_COND_V(!_image_compress_pvrtc4_func, ERR_UNAVAILABLE);
- _image_compress_pvrtc4_func(this);
+ case COMPRESS_PVRTC1_4: {
+ ERR_FAIL_COND_V(!_image_compress_pvrtc1_4bpp_func, ERR_UNAVAILABLE);
+ _image_compress_pvrtc1_4bpp_func(this);
} break;
case COMPRESS_ETC: {
ERR_FAIL_COND_V(!_image_compress_etc1_func, ERR_UNAVAILABLE);
@@ -2714,8 +2710,7 @@ ImageMemLoadFunc Image::_bmp_mem_loader_func = nullptr;
void (*Image::_image_compress_bc_func)(Image *, float, Image::UsedChannels) = nullptr;
void (*Image::_image_compress_bptc_func)(Image *, float, Image::UsedChannels) = nullptr;
-void (*Image::_image_compress_pvrtc2_func)(Image *) = nullptr;
-void (*Image::_image_compress_pvrtc4_func)(Image *) = nullptr;
+void (*Image::_image_compress_pvrtc1_4bpp_func)(Image *) = nullptr;
void (*Image::_image_compress_etc1_func)(Image *, float) = nullptr;
void (*Image::_image_compress_etc2_func)(Image *, float, Image::UsedChannels) = nullptr;
void (*Image::_image_decompress_pvrtc)(Image *) = nullptr;
@@ -3173,10 +3168,10 @@ void Image::_bind_methods() {
BIND_ENUM_CONSTANT(FORMAT_BPTC_RGBA); //btpc bc6h
BIND_ENUM_CONSTANT(FORMAT_BPTC_RGBF); //float /
BIND_ENUM_CONSTANT(FORMAT_BPTC_RGBFU); //unsigned float
- BIND_ENUM_CONSTANT(FORMAT_PVRTC2); //pvrtc
- BIND_ENUM_CONSTANT(FORMAT_PVRTC2A);
- BIND_ENUM_CONSTANT(FORMAT_PVRTC4);
- BIND_ENUM_CONSTANT(FORMAT_PVRTC4A);
+ BIND_ENUM_CONSTANT(FORMAT_PVRTC1_2); //pvrtc
+ BIND_ENUM_CONSTANT(FORMAT_PVRTC1_2A);
+ BIND_ENUM_CONSTANT(FORMAT_PVRTC1_4);
+ BIND_ENUM_CONSTANT(FORMAT_PVRTC1_4A);
BIND_ENUM_CONSTANT(FORMAT_ETC); //etc1
BIND_ENUM_CONSTANT(FORMAT_ETC2_R11); //etc2
BIND_ENUM_CONSTANT(FORMAT_ETC2_R11S); //signed ); NOT srgb.
@@ -3200,10 +3195,10 @@ void Image::_bind_methods() {
BIND_ENUM_CONSTANT(ALPHA_BLEND);
BIND_ENUM_CONSTANT(COMPRESS_S3TC);
- BIND_ENUM_CONSTANT(COMPRESS_PVRTC2);
- BIND_ENUM_CONSTANT(COMPRESS_PVRTC4);
+ BIND_ENUM_CONSTANT(COMPRESS_PVRTC1_4);
BIND_ENUM_CONSTANT(COMPRESS_ETC);
BIND_ENUM_CONSTANT(COMPRESS_ETC2);
+ BIND_ENUM_CONSTANT(COMPRESS_BPTC);
BIND_ENUM_CONSTANT(USED_CHANNELS_L);
BIND_ENUM_CONSTANT(USED_CHANNELS_LA);
diff --git a/core/io/image.h b/core/io/image.h
index c4c84589e5..0151df0cf9 100644
--- a/core/io/image.h
+++ b/core/io/image.h
@@ -91,10 +91,10 @@ public:
FORMAT_BPTC_RGBA, //btpc bc7
FORMAT_BPTC_RGBF, //float bc6h
FORMAT_BPTC_RGBFU, //unsigned float bc6hu
- FORMAT_PVRTC2, //pvrtc
- FORMAT_PVRTC2A,
- FORMAT_PVRTC4,
- FORMAT_PVRTC4A,
+ FORMAT_PVRTC1_2, //pvrtc1
+ FORMAT_PVRTC1_2A,
+ FORMAT_PVRTC1_4,
+ FORMAT_PVRTC1_4A,
FORMAT_ETC, //etc1
FORMAT_ETC2_R11, //etc2
FORMAT_ETC2_R11S, //signed, NOT srgb.
@@ -138,8 +138,7 @@ public:
static void (*_image_compress_bc_func)(Image *, float, UsedChannels p_channels);
static void (*_image_compress_bptc_func)(Image *, float p_lossy_quality, UsedChannels p_channels);
- static void (*_image_compress_pvrtc2_func)(Image *);
- static void (*_image_compress_pvrtc4_func)(Image *);
+ static void (*_image_compress_pvrtc1_4bpp_func)(Image *);
static void (*_image_compress_etc1_func)(Image *, float);
static void (*_image_compress_etc2_func)(Image *, float, UsedChannels p_channels);
@@ -332,11 +331,10 @@ public:
enum CompressMode {
COMPRESS_S3TC,
- COMPRESS_PVRTC2,
- COMPRESS_PVRTC4,
+ COMPRESS_PVRTC1_4,
COMPRESS_ETC,
COMPRESS_ETC2,
- COMPRESS_BPTC
+ COMPRESS_BPTC,
};
enum CompressSource {
COMPRESS_SOURCE_GENERIC,
diff --git a/core/io/logger.cpp b/core/io/logger.cpp
index 0e6a2e2c9f..241c72d310 100644
--- a/core/io/logger.cpp
+++ b/core/io/logger.cpp
@@ -30,6 +30,7 @@
#include "logger.h"
+#include "core/config/project_settings.h"
#include "core/os/dir_access.h"
#include "core/os/os.h"
#include "core/string/print_string.h"
@@ -152,7 +153,7 @@ void RotatedFileLogger::rotate_file() {
char timestamp[21];
OS::Date date = OS::get_singleton()->get_date();
OS::Time time = OS::get_singleton()->get_time();
- sprintf(timestamp, "_%04d-%02d-%02d_%02d-%02d-%02d", date.year, date.month, date.day, time.hour, time.min, time.sec);
+ sprintf(timestamp, "_%04d-%02d-%02d_%02d.%02d.%02d", date.year, date.month, date.day, time.hour, time.min, time.sec);
String backup_name = base_path.get_basename() + timestamp;
if (base_path.get_extension() != String()) {
@@ -201,15 +202,14 @@ void RotatedFileLogger::logv(const char *p_format, va_list p_list, bool p_err) {
}
va_end(list_copy);
file->store_buffer((uint8_t *)buf, len);
+
if (len >= static_buf_size) {
Memory::free_static(buf);
}
-#ifdef DEBUG_ENABLED
- const bool need_flush = true;
-#else
- bool need_flush = p_err;
-#endif
- if (need_flush) {
+
+ if (p_err || GLOBAL_GET("application/run/flush_stdout_on_print")) {
+ // Don't always flush when printing stdout to avoid performance
+ // issues when `print()` is spammed in release builds.
file->flush();
}
}
@@ -228,9 +228,11 @@ void StdLogger::logv(const char *p_format, va_list p_list, bool p_err) {
vfprintf(stderr, p_format, p_list);
} else {
vprintf(p_format, p_list);
-#ifdef DEBUG_ENABLED
- fflush(stdout);
-#endif
+ if (GLOBAL_GET("application/run/flush_stdout_on_print")) {
+ // Don't always flush when printing stdout to avoid performance
+ // issues when `print()` is spammed in release builds.
+ fflush(stdout);
+ }
}
}
diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp
index 3cf4acaf39..db12fcb7f7 100644
--- a/core/io/marshalls.cpp
+++ b/core/io/marshalls.cpp
@@ -1003,10 +1003,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
}
} break;
- case Variant::STRING: {
- _encode_string(p_variant, buf, r_len);
-
- } break;
+ case Variant::STRING:
case Variant::STRING_NAME: {
_encode_string(p_variant, buf, r_len);
diff --git a/core/io/packet_peer.cpp b/core/io/packet_peer.cpp
index b6cc5bf42a..3da494a8ef 100644
--- a/core/io/packet_peer.cpp
+++ b/core/io/packet_peer.cpp
@@ -151,11 +151,6 @@ void PacketPeer::_bind_methods() {
/***************/
-void PacketPeerStream::_set_stream_peer(REF p_peer) {
- ERR_FAIL_COND_MSG(p_peer.is_null(), "It's not a reference to a valid Resource object.");
- set_stream_peer(p_peer);
-}
-
void PacketPeerStream::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_stream_peer", "peer"), &PacketPeerStream::set_stream_peer);
ClassDB::bind_method(D_METHOD("get_stream_peer"), &PacketPeerStream::get_stream_peer);
@@ -263,10 +258,8 @@ int PacketPeerStream::get_max_packet_size() const {
}
void PacketPeerStream::set_stream_peer(const Ref<StreamPeer> &p_peer) {
- //ERR_FAIL_COND(p_peer.is_null());
-
if (p_peer.ptr() != peer.ptr()) {
- ring_buffer.advance_read(ring_buffer.data_left()); // reset the ring buffer
+ ring_buffer.advance_read(ring_buffer.data_left()); // Reset the ring buffer.
}
peer = p_peer;
diff --git a/core/io/packet_peer.h b/core/io/packet_peer.h
index f7f080aa43..a25fa03875 100644
--- a/core/io/packet_peer.h
+++ b/core/io/packet_peer.h
@@ -86,7 +86,6 @@ class PacketPeerStream : public PacketPeer {
Error _poll_buffer() const;
protected:
- void _set_stream_peer(REF p_peer);
static void _bind_methods();
public:
diff --git a/core/io/resource_importer.cpp b/core/io/resource_importer.cpp
index c88331cf9e..9b14d2c763 100644
--- a/core/io/resource_importer.cpp
+++ b/core/io/resource_importer.cpp
@@ -192,10 +192,6 @@ bool ResourceFormatImporter::recognize_path(const String &p_path, const String &
return FileAccess::exists(p_path + ".import");
}
-bool ResourceFormatImporter::can_be_imported(const String &p_path) const {
- return ResourceFormatLoader::recognize_path(p_path);
-}
-
int ResourceFormatImporter::get_import_order(const String &p_path) const {
Ref<ResourceImporter> importer;
diff --git a/core/io/resource_importer.h b/core/io/resource_importer.h
index d31a9a0194..1b300bf656 100644
--- a/core/io/resource_importer.h
+++ b/core/io/resource_importer.h
@@ -70,7 +70,6 @@ public:
virtual String get_import_group_file(const String &p_path) const;
virtual bool exists(const String &p_path) const;
- virtual bool can_be_imported(const String &p_path) const;
virtual int get_import_order(const String &p_path) const;
String get_internal_resource_path(const String &p_path) const;
@@ -102,6 +101,7 @@ public:
virtual String get_resource_type() const = 0;
virtual float get_priority() const { return 1.0; }
virtual int get_import_order() const { return 0; }
+ virtual int get_format_version() const { return 0; }
struct ImportOption {
PropertyInfo option;
diff --git a/core/math/basis.cpp b/core/math/basis.cpp
index c6030d9757..a64f29517d 100644
--- a/core/math/basis.cpp
+++ b/core/math/basis.cpp
@@ -1017,15 +1017,15 @@ void Basis::set_diagonal(const Vector3 &p_diag) {
elements[2][2] = p_diag.z;
}
-Basis Basis::slerp(const Basis &target, const real_t &t) const {
+Basis Basis::slerp(const Basis &p_to, const real_t &p_weight) const {
//consider scale
Quat from(*this);
- Quat to(target);
+ Quat to(p_to);
- Basis b(from.slerp(to, t));
- b.elements[0] *= Math::lerp(elements[0].length(), target.elements[0].length(), t);
- b.elements[1] *= Math::lerp(elements[1].length(), target.elements[1].length(), t);
- b.elements[2] *= Math::lerp(elements[2].length(), target.elements[2].length(), t);
+ Basis b(from.slerp(to, p_weight));
+ b.elements[0] *= Math::lerp(elements[0].length(), p_to.elements[0].length(), p_weight);
+ b.elements[1] *= Math::lerp(elements[1].length(), p_to.elements[1].length(), p_weight);
+ b.elements[2] *= Math::lerp(elements[2].length(), p_to.elements[2].length(), p_weight);
return b;
}
diff --git a/core/math/basis.h b/core/math/basis.h
index 2584f1ff48..4cb3d55200 100644
--- a/core/math/basis.h
+++ b/core/math/basis.h
@@ -170,7 +170,7 @@ public:
bool is_diagonal() const;
bool is_rotation() const;
- Basis slerp(const Basis &target, const real_t &t) const;
+ Basis slerp(const Basis &p_to, const real_t &p_weight) const;
void rotate_sh(real_t *p_values);
operator String() const;
diff --git a/core/math/color.h b/core/math/color.h
index a9be9e9035..b928ff8592 100644
--- a/core/math/color.h
+++ b/core/math/color.h
@@ -92,13 +92,13 @@ struct Color {
void invert();
Color inverted() const;
- _FORCE_INLINE_ Color lerp(const Color &p_b, float p_t) const {
+ _FORCE_INLINE_ Color lerp(const Color &p_to, float p_weight) const {
Color res = *this;
- res.r += (p_t * (p_b.r - r));
- res.g += (p_t * (p_b.g - g));
- res.b += (p_t * (p_b.b - b));
- res.a += (p_t * (p_b.a - a));
+ res.r += (p_weight * (p_to.r - r));
+ res.g += (p_weight * (p_to.g - g));
+ res.b += (p_weight * (p_to.b - b));
+ res.a += (p_weight * (p_to.a - a));
return res;
}
diff --git a/core/math/expression.cpp b/core/math/expression.cpp
index d1f15caa5e..29b706a3a9 100644
--- a/core/math/expression.cpp
+++ b/core/math/expression.cpp
@@ -1003,31 +1003,19 @@ Expression::ENode *Expression::_parse_expression() {
priority = 1;
unary = true;
break;
-
case Variant::OP_MULTIPLY:
- priority = 2;
- break;
case Variant::OP_DIVIDE:
- priority = 2;
- break;
case Variant::OP_MODULE:
priority = 2;
break;
-
case Variant::OP_ADD:
- priority = 3;
- break;
case Variant::OP_SUBTRACT:
priority = 3;
break;
-
case Variant::OP_SHIFT_LEFT:
- priority = 4;
- break;
case Variant::OP_SHIFT_RIGHT:
priority = 4;
break;
-
case Variant::OP_BIT_AND:
priority = 5;
break;
@@ -1037,31 +1025,17 @@ Expression::ENode *Expression::_parse_expression() {
case Variant::OP_BIT_OR:
priority = 7;
break;
-
case Variant::OP_LESS:
- priority = 8;
- break;
case Variant::OP_LESS_EQUAL:
- priority = 8;
- break;
case Variant::OP_GREATER:
- priority = 8;
- break;
case Variant::OP_GREATER_EQUAL:
- priority = 8;
- break;
-
case Variant::OP_EQUAL:
- priority = 8;
- break;
case Variant::OP_NOT_EQUAL:
priority = 8;
break;
-
case Variant::OP_IN:
priority = 10;
break;
-
case Variant::OP_NOT:
priority = 11;
unary = true;
@@ -1072,7 +1046,6 @@ Expression::ENode *Expression::_parse_expression() {
case Variant::OP_OR:
priority = 13;
break;
-
default: {
_set_error("Parser bug, invalid operator in expression: " + itos(expression[i].op));
return nullptr;
diff --git a/core/math/quat.cpp b/core/math/quat.cpp
index b6a017dd41..fc2d71c377 100644
--- a/core/math/quat.cpp
+++ b/core/math/quat.cpp
@@ -106,16 +106,16 @@ Vector3 Quat::get_euler_yxz() const {
return m.get_euler_yxz();
}
-void Quat::operator*=(const Quat &q) {
- set(w * q.x + x * q.w + y * q.z - z * q.y,
- w * q.y + y * q.w + z * q.x - x * q.z,
- w * q.z + z * q.w + x * q.y - y * q.x,
- w * q.w - x * q.x - y * q.y - z * q.z);
+void Quat::operator*=(const Quat &p_q) {
+ set(w * p_q.x + x * p_q.w + y * p_q.z - z * p_q.y,
+ w * p_q.y + y * p_q.w + z * p_q.x - x * p_q.z,
+ w * p_q.z + z * p_q.w + x * p_q.y - y * p_q.x,
+ w * p_q.w - x * p_q.x - y * p_q.y - z * p_q.z);
}
-Quat Quat::operator*(const Quat &q) const {
+Quat Quat::operator*(const Quat &p_q) const {
Quat r = *this;
- r *= q;
+ r *= p_q;
return r;
}
@@ -146,29 +146,29 @@ Quat Quat::inverse() const {
return Quat(-x, -y, -z, w);
}
-Quat Quat::slerp(const Quat &q, const real_t &t) const {
+Quat Quat::slerp(const Quat &p_to, const real_t &p_weight) const {
#ifdef MATH_CHECKS
ERR_FAIL_COND_V_MSG(!is_normalized(), Quat(), "The start quaternion must be normalized.");
- ERR_FAIL_COND_V_MSG(!q.is_normalized(), Quat(), "The end quaternion must be normalized.");
+ ERR_FAIL_COND_V_MSG(!p_to.is_normalized(), Quat(), "The end quaternion must be normalized.");
#endif
Quat to1;
real_t omega, cosom, sinom, scale0, scale1;
// calc cosine
- cosom = dot(q);
+ cosom = dot(p_to);
// adjust signs (if necessary)
if (cosom < 0.0) {
cosom = -cosom;
- to1.x = -q.x;
- to1.y = -q.y;
- to1.z = -q.z;
- to1.w = -q.w;
+ to1.x = -p_to.x;
+ to1.y = -p_to.y;
+ to1.z = -p_to.z;
+ to1.w = -p_to.w;
} else {
- to1.x = q.x;
- to1.y = q.y;
- to1.z = q.z;
- to1.w = q.w;
+ to1.x = p_to.x;
+ to1.y = p_to.y;
+ to1.z = p_to.z;
+ to1.w = p_to.w;
}
// calculate coefficients
@@ -177,13 +177,13 @@ Quat Quat::slerp(const Quat &q, const real_t &t) const {
// standard case (slerp)
omega = Math::acos(cosom);
sinom = Math::sin(omega);
- scale0 = Math::sin((1.0 - t) * omega) / sinom;
- scale1 = Math::sin(t * omega) / sinom;
+ scale0 = Math::sin((1.0 - p_weight) * omega) / sinom;
+ scale1 = Math::sin(p_weight * omega) / sinom;
} else {
// "from" and "to" quaternions are very close
// ... so we can do a linear interpolation
- scale0 = 1.0 - t;
- scale1 = t;
+ scale0 = 1.0 - p_weight;
+ scale1 = p_weight;
}
// calculate final values
return Quat(
@@ -193,14 +193,14 @@ Quat Quat::slerp(const Quat &q, const real_t &t) const {
scale0 * w + scale1 * to1.w);
}
-Quat Quat::slerpni(const Quat &q, const real_t &t) const {
+Quat Quat::slerpni(const Quat &p_to, const real_t &p_weight) const {
#ifdef MATH_CHECKS
ERR_FAIL_COND_V_MSG(!is_normalized(), Quat(), "The start quaternion must be normalized.");
- ERR_FAIL_COND_V_MSG(!q.is_normalized(), Quat(), "The end quaternion must be normalized.");
+ ERR_FAIL_COND_V_MSG(!p_to.is_normalized(), Quat(), "The end quaternion must be normalized.");
#endif
const Quat &from = *this;
- real_t dot = from.dot(q);
+ real_t dot = from.dot(p_to);
if (Math::absf(dot) > 0.9999) {
return from;
@@ -208,24 +208,24 @@ Quat Quat::slerpni(const Quat &q, const real_t &t) const {
real_t theta = Math::acos(dot),
sinT = 1.0 / Math::sin(theta),
- newFactor = Math::sin(t * theta) * sinT,
- invFactor = Math::sin((1.0 - t) * theta) * sinT;
+ newFactor = Math::sin(p_weight * theta) * sinT,
+ invFactor = Math::sin((1.0 - p_weight) * theta) * sinT;
- return Quat(invFactor * from.x + newFactor * q.x,
- invFactor * from.y + newFactor * q.y,
- invFactor * from.z + newFactor * q.z,
- invFactor * from.w + newFactor * q.w);
+ return Quat(invFactor * from.x + newFactor * p_to.x,
+ invFactor * from.y + newFactor * p_to.y,
+ invFactor * from.z + newFactor * p_to.z,
+ invFactor * from.w + newFactor * p_to.w);
}
-Quat Quat::cubic_slerp(const Quat &q, const Quat &prep, const Quat &postq, const real_t &t) const {
+Quat Quat::cubic_slerp(const Quat &p_b, const Quat &p_pre_a, const Quat &p_post_b, const real_t &p_weight) const {
#ifdef MATH_CHECKS
ERR_FAIL_COND_V_MSG(!is_normalized(), Quat(), "The start quaternion must be normalized.");
- ERR_FAIL_COND_V_MSG(!q.is_normalized(), Quat(), "The end quaternion must be normalized.");
+ ERR_FAIL_COND_V_MSG(!p_b.is_normalized(), Quat(), "The end quaternion must be normalized.");
#endif
//the only way to do slerp :|
- real_t t2 = (1.0 - t) * t * 2;
- Quat sp = this->slerp(q, t);
- Quat sq = prep.slerpni(postq, t);
+ real_t t2 = (1.0 - p_weight) * p_weight * 2;
+ Quat sp = this->slerp(p_b, p_weight);
+ Quat sq = p_pre_a.slerpni(p_post_b, p_weight);
return sp.slerpni(sq, t2);
}
diff --git a/core/math/quat.h b/core/math/quat.h
index f8ab537d7b..bb980f7677 100644
--- a/core/math/quat.h
+++ b/core/math/quat.h
@@ -63,7 +63,7 @@ public:
Quat normalized() const;
bool is_normalized() const;
Quat inverse() const;
- _FORCE_INLINE_ real_t dot(const Quat &q) const;
+ _FORCE_INLINE_ real_t dot(const Quat &p_q) const;
void set_euler_xyz(const Vector3 &p_euler);
Vector3 get_euler_xyz() const;
@@ -73,9 +73,9 @@ public:
void set_euler(const Vector3 &p_euler) { set_euler_yxz(p_euler); };
Vector3 get_euler() const { return get_euler_yxz(); };
- Quat slerp(const Quat &q, const real_t &t) const;
- Quat slerpni(const Quat &q, const real_t &t) const;
- Quat cubic_slerp(const Quat &q, const Quat &prep, const Quat &postq, const real_t &t) const;
+ Quat slerp(const Quat &p_to, const real_t &p_weight) const;
+ Quat slerpni(const Quat &p_to, const real_t &p_weight) const;
+ Quat cubic_slerp(const Quat &p_b, const Quat &p_pre_a, const Quat &p_post_b, const real_t &p_weight) const;
void set_axis_angle(const Vector3 &axis, const real_t &angle);
_FORCE_INLINE_ void get_axis_angle(Vector3 &r_axis, real_t &r_angle) const {
@@ -86,8 +86,8 @@ public:
r_axis.z = z * r;
}
- void operator*=(const Quat &q);
- Quat operator*(const Quat &q) const;
+ void operator*=(const Quat &p_q);
+ Quat operator*(const Quat &p_q) const;
Quat operator*(const Vector3 &v) const {
return Quat(w * v.x + y * v.z - z * v.y,
@@ -109,8 +109,8 @@ public:
return inverse().xform(v);
}
- _FORCE_INLINE_ void operator+=(const Quat &q);
- _FORCE_INLINE_ void operator-=(const Quat &q);
+ _FORCE_INLINE_ void operator+=(const Quat &p_q);
+ _FORCE_INLINE_ void operator-=(const Quat &p_q);
_FORCE_INLINE_ void operator*=(const real_t &s);
_FORCE_INLINE_ void operator/=(const real_t &s);
_FORCE_INLINE_ Quat operator+(const Quat &q2) const;
@@ -141,18 +141,18 @@ public:
Quat(const Vector3 &axis, const real_t &angle) { set_axis_angle(axis, angle); }
Quat(const Vector3 &euler) { set_euler(euler); }
- Quat(const Quat &q) :
- x(q.x),
- y(q.y),
- z(q.z),
- w(q.w) {
+ Quat(const Quat &p_q) :
+ x(p_q.x),
+ y(p_q.y),
+ z(p_q.z),
+ w(p_q.w) {
}
- Quat &operator=(const Quat &q) {
- x = q.x;
- y = q.y;
- z = q.z;
- w = q.w;
+ Quat &operator=(const Quat &p_q) {
+ x = p_q.x;
+ y = p_q.y;
+ z = p_q.z;
+ w = p_q.w;
return *this;
}
@@ -178,26 +178,26 @@ public:
}
};
-real_t Quat::dot(const Quat &q) const {
- return x * q.x + y * q.y + z * q.z + w * q.w;
+real_t Quat::dot(const Quat &p_q) const {
+ return x * p_q.x + y * p_q.y + z * p_q.z + w * p_q.w;
}
real_t Quat::length_squared() const {
return dot(*this);
}
-void Quat::operator+=(const Quat &q) {
- x += q.x;
- y += q.y;
- z += q.z;
- w += q.w;
+void Quat::operator+=(const Quat &p_q) {
+ x += p_q.x;
+ y += p_q.y;
+ z += p_q.z;
+ w += p_q.w;
}
-void Quat::operator-=(const Quat &q) {
- x -= q.x;
- y -= q.y;
- z -= q.z;
- w -= q.w;
+void Quat::operator-=(const Quat &p_q) {
+ x -= p_q.x;
+ y -= p_q.y;
+ z -= p_q.z;
+ w -= p_q.w;
}
void Quat::operator*=(const real_t &s) {
diff --git a/core/math/random_number_generator.cpp b/core/math/random_number_generator.cpp
index a124f63030..f045213fb9 100644
--- a/core/math/random_number_generator.cpp
+++ b/core/math/random_number_generator.cpp
@@ -34,6 +34,9 @@ void RandomNumberGenerator::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_seed", "seed"), &RandomNumberGenerator::set_seed);
ClassDB::bind_method(D_METHOD("get_seed"), &RandomNumberGenerator::get_seed);
+ ClassDB::bind_method(D_METHOD("set_state", "state"), &RandomNumberGenerator::set_state);
+ ClassDB::bind_method(D_METHOD("get_state"), &RandomNumberGenerator::get_state);
+
ClassDB::bind_method(D_METHOD("randi"), &RandomNumberGenerator::randi);
ClassDB::bind_method(D_METHOD("randf"), &RandomNumberGenerator::randf);
ClassDB::bind_method(D_METHOD("randfn", "mean", "deviation"), &RandomNumberGenerator::randfn, DEFVAL(0.0), DEFVAL(1.0));
@@ -42,6 +45,8 @@ void RandomNumberGenerator::_bind_methods() {
ClassDB::bind_method(D_METHOD("randomize"), &RandomNumberGenerator::randomize);
ADD_PROPERTY(PropertyInfo(Variant::INT, "seed"), "set_seed", "get_seed");
- // Default value is non-deterministic, override it for doc generation purposes.
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "state"), "set_state", "get_state");
+ // Default values are non-deterministic, override for doc generation purposes.
ADD_PROPERTY_DEFAULT("seed", 0);
+ ADD_PROPERTY_DEFAULT("state", 0);
}
diff --git a/core/math/random_number_generator.h b/core/math/random_number_generator.h
index 0d0ea17205..7728fd09c0 100644
--- a/core/math/random_number_generator.h
+++ b/core/math/random_number_generator.h
@@ -44,19 +44,17 @@ protected:
public:
_FORCE_INLINE_ void set_seed(uint64_t p_seed) { randbase.seed(p_seed); }
-
_FORCE_INLINE_ uint64_t get_seed() { return randbase.get_seed(); }
+ _FORCE_INLINE_ void set_state(uint64_t p_state) { randbase.set_state(p_state); }
+ _FORCE_INLINE_ uint64_t get_state() const { return randbase.get_state(); }
+
_FORCE_INLINE_ void randomize() { randbase.randomize(); }
_FORCE_INLINE_ uint32_t randi() { return randbase.rand(); }
-
_FORCE_INLINE_ real_t randf() { return randbase.randf(); }
-
_FORCE_INLINE_ real_t randf_range(real_t p_from, real_t p_to) { return randbase.random(p_from, p_to); }
-
_FORCE_INLINE_ real_t randfn(real_t p_mean = 0.0, real_t p_deviation = 1.0) { return randbase.randfn(p_mean, p_deviation); }
-
_FORCE_INLINE_ int randi_range(int p_from, int p_to) { return randbase.random(p_from, p_to); }
RandomNumberGenerator() {}
diff --git a/core/math/random_pcg.h b/core/math/random_pcg.h
index fe6b1b5639..2e257cb5b7 100644
--- a/core/math/random_pcg.h
+++ b/core/math/random_pcg.h
@@ -61,7 +61,7 @@ static int __bsr_clz32(uint32_t x) {
class RandomPCG {
pcg32_random_t pcg;
- uint64_t current_seed; // seed with this to get the same state
+ uint64_t current_seed; // The seed the current generator state started from.
uint64_t current_inc;
public:
@@ -76,13 +76,14 @@ public:
}
_FORCE_INLINE_ uint64_t get_seed() { return current_seed; }
+ _FORCE_INLINE_ void set_state(uint64_t p_state) { pcg.state = p_state; }
+ _FORCE_INLINE_ uint64_t get_state() const { return pcg.state; }
+
void randomize();
_FORCE_INLINE_ uint32_t rand() {
- current_seed = pcg.state;
return pcg32_random_r(&pcg);
}
_FORCE_INLINE_ uint32_t rand(uint32_t bounds) {
- current_seed = pcg.state;
return pcg32_boundedrand_r(&pcg, bounds);
}
diff --git a/core/math/vector2.cpp b/core/math/vector2.cpp
index 75e742a5f1..f9c2eeb57d 100644
--- a/core/math/vector2.cpp
+++ b/core/math/vector2.cpp
@@ -118,8 +118,8 @@ Vector2 Vector2::posmodv(const Vector2 &p_modv) const {
return Vector2(Math::fposmod(x, p_modv.x), Math::fposmod(y, p_modv.y));
}
-Vector2 Vector2::project(const Vector2 &p_b) const {
- return p_b * (dot(p_b) / p_b.length_squared());
+Vector2 Vector2::project(const Vector2 &p_to) const {
+ return p_to * (dot(p_to) / p_to.length_squared());
}
Vector2 Vector2::snapped(const Vector2 &p_by) const {
@@ -139,13 +139,13 @@ Vector2 Vector2::clamped(real_t p_len) const {
return v;
}
-Vector2 Vector2::cubic_interpolate(const Vector2 &p_b, const Vector2 &p_pre_a, const Vector2 &p_post_b, real_t p_t) const {
+Vector2 Vector2::cubic_interpolate(const Vector2 &p_b, const Vector2 &p_pre_a, const Vector2 &p_post_b, real_t p_weight) const {
Vector2 p0 = p_pre_a;
Vector2 p1 = *this;
Vector2 p2 = p_b;
Vector2 p3 = p_post_b;
- real_t t = p_t;
+ real_t t = p_weight;
real_t t2 = t * t;
real_t t3 = t2 * t;
diff --git a/core/math/vector2.h b/core/math/vector2.h
index 8cb63b2fb5..33f815a39c 100644
--- a/core/math/vector2.h
+++ b/core/math/vector2.h
@@ -77,21 +77,21 @@ struct Vector2 {
real_t distance_squared_to(const Vector2 &p_vector2) const;
real_t angle_to(const Vector2 &p_vector2) const;
real_t angle_to_point(const Vector2 &p_vector2) const;
- _FORCE_INLINE_ Vector2 direction_to(const Vector2 &p_b) const;
+ _FORCE_INLINE_ Vector2 direction_to(const Vector2 &p_to) const;
real_t dot(const Vector2 &p_other) const;
real_t cross(const Vector2 &p_other) const;
Vector2 posmod(const real_t p_mod) const;
Vector2 posmodv(const Vector2 &p_modv) const;
- Vector2 project(const Vector2 &p_b) const;
+ Vector2 project(const Vector2 &p_to) const;
Vector2 plane_project(real_t p_d, const Vector2 &p_vec) const;
Vector2 clamped(real_t p_len) const;
- _FORCE_INLINE_ Vector2 lerp(const Vector2 &p_b, real_t p_t) const;
- _FORCE_INLINE_ Vector2 slerp(const Vector2 &p_b, real_t p_t) const;
- Vector2 cubic_interpolate(const Vector2 &p_b, const Vector2 &p_pre_a, const Vector2 &p_post_b, real_t p_t) const;
+ _FORCE_INLINE_ Vector2 lerp(const Vector2 &p_to, real_t p_weight) const;
+ _FORCE_INLINE_ Vector2 slerp(const Vector2 &p_to, real_t p_weight) const;
+ Vector2 cubic_interpolate(const Vector2 &p_b, const Vector2 &p_pre_a, const Vector2 &p_post_b, real_t p_weight) const;
Vector2 move_toward(const Vector2 &p_to, const real_t p_delta) const;
Vector2 slide(const Vector2 &p_normal) const;
@@ -230,25 +230,25 @@ _FORCE_INLINE_ bool Vector2::operator!=(const Vector2 &p_vec2) const {
return x != p_vec2.x || y != p_vec2.y;
}
-Vector2 Vector2::lerp(const Vector2 &p_b, real_t p_t) const {
+Vector2 Vector2::lerp(const Vector2 &p_to, real_t p_weight) const {
Vector2 res = *this;
- res.x += (p_t * (p_b.x - x));
- res.y += (p_t * (p_b.y - y));
+ res.x += (p_weight * (p_to.x - x));
+ res.y += (p_weight * (p_to.y - y));
return res;
}
-Vector2 Vector2::slerp(const Vector2 &p_b, real_t p_t) const {
+Vector2 Vector2::slerp(const Vector2 &p_to, real_t p_weight) const {
#ifdef MATH_CHECKS
ERR_FAIL_COND_V_MSG(!is_normalized(), Vector2(), "The start Vector2 must be normalized.");
#endif
- real_t theta = angle_to(p_b);
- return rotated(theta * p_t);
+ real_t theta = angle_to(p_to);
+ return rotated(theta * p_weight);
}
-Vector2 Vector2::direction_to(const Vector2 &p_b) const {
- Vector2 ret(p_b.x - x, p_b.y - y);
+Vector2 Vector2::direction_to(const Vector2 &p_to) const {
+ Vector2 ret(p_to.x - x, p_to.y - y);
ret.normalize();
return ret;
}
diff --git a/core/math/vector3.cpp b/core/math/vector3.cpp
index 568df48c62..09354d8e79 100644
--- a/core/math/vector3.cpp
+++ b/core/math/vector3.cpp
@@ -72,46 +72,13 @@ Vector3 Vector3::snapped(Vector3 p_val) const {
return v;
}
-Vector3 Vector3::cubic_interpolaten(const Vector3 &p_b, const Vector3 &p_pre_a, const Vector3 &p_post_b, real_t p_t) const {
+Vector3 Vector3::cubic_interpolate(const Vector3 &p_b, const Vector3 &p_pre_a, const Vector3 &p_post_b, real_t p_weight) const {
Vector3 p0 = p_pre_a;
Vector3 p1 = *this;
Vector3 p2 = p_b;
Vector3 p3 = p_post_b;
- {
- //normalize
-
- real_t ab = p0.distance_to(p1);
- real_t bc = p1.distance_to(p2);
- real_t cd = p2.distance_to(p3);
-
- if (ab > 0) {
- p0 = p1 + (p0 - p1) * (bc / ab);
- }
- if (cd > 0) {
- p3 = p2 + (p3 - p2) * (bc / cd);
- }
- }
-
- real_t t = p_t;
- real_t t2 = t * t;
- real_t t3 = t2 * t;
-
- Vector3 out;
- out = 0.5 * ((p1 * 2.0) +
- (-p0 + p2) * t +
- (2.0 * p0 - 5.0 * p1 + 4.0 * p2 - p3) * t2 +
- (-p0 + 3.0 * p1 - 3.0 * p2 + p3) * t3);
- return out;
-}
-
-Vector3 Vector3::cubic_interpolate(const Vector3 &p_b, const Vector3 &p_pre_a, const Vector3 &p_post_b, real_t p_t) const {
- Vector3 p0 = p_pre_a;
- Vector3 p1 = *this;
- Vector3 p2 = p_b;
- Vector3 p3 = p_post_b;
-
- real_t t = p_t;
+ real_t t = p_weight;
real_t t2 = t * t;
real_t t3 = t2 * t;
diff --git a/core/math/vector3.h b/core/math/vector3.h
index ae8b9376cf..5af84377fd 100644
--- a/core/math/vector3.h
+++ b/core/math/vector3.h
@@ -86,10 +86,9 @@ struct Vector3 {
/* Static Methods between 2 vector3s */
- _FORCE_INLINE_ Vector3 lerp(const Vector3 &p_b, real_t p_t) const;
- _FORCE_INLINE_ Vector3 slerp(const Vector3 &p_b, real_t p_t) const;
- Vector3 cubic_interpolate(const Vector3 &p_b, const Vector3 &p_pre_a, const Vector3 &p_post_b, real_t p_t) const;
- Vector3 cubic_interpolaten(const Vector3 &p_b, const Vector3 &p_pre_a, const Vector3 &p_post_b, real_t p_t) const;
+ _FORCE_INLINE_ Vector3 lerp(const Vector3 &p_to, real_t p_weight) const;
+ _FORCE_INLINE_ Vector3 slerp(const Vector3 &p_to, real_t p_weight) const;
+ Vector3 cubic_interpolate(const Vector3 &p_b, const Vector3 &p_pre_a, const Vector3 &p_post_b, real_t p_weight) const;
Vector3 move_toward(const Vector3 &p_to, const real_t p_delta) const;
_FORCE_INLINE_ Vector3 cross(const Vector3 &p_b) const;
@@ -103,15 +102,15 @@ struct Vector3 {
_FORCE_INLINE_ Vector3 ceil() const;
_FORCE_INLINE_ Vector3 round() const;
- _FORCE_INLINE_ real_t distance_to(const Vector3 &p_b) const;
- _FORCE_INLINE_ real_t distance_squared_to(const Vector3 &p_b) const;
+ _FORCE_INLINE_ real_t distance_to(const Vector3 &p_to) const;
+ _FORCE_INLINE_ real_t distance_squared_to(const Vector3 &p_to) const;
_FORCE_INLINE_ Vector3 posmod(const real_t p_mod) const;
_FORCE_INLINE_ Vector3 posmodv(const Vector3 &p_modv) const;
- _FORCE_INLINE_ Vector3 project(const Vector3 &p_b) const;
+ _FORCE_INLINE_ Vector3 project(const Vector3 &p_to) const;
- _FORCE_INLINE_ real_t angle_to(const Vector3 &p_b) const;
- _FORCE_INLINE_ Vector3 direction_to(const Vector3 &p_b) const;
+ _FORCE_INLINE_ real_t angle_to(const Vector3 &p_to) const;
+ _FORCE_INLINE_ Vector3 direction_to(const Vector3 &p_to) const;
_FORCE_INLINE_ Vector3 slide(const Vector3 &p_normal) const;
_FORCE_INLINE_ Vector3 bounce(const Vector3 &p_normal) const;
@@ -195,24 +194,24 @@ Vector3 Vector3::round() const {
return Vector3(Math::round(x), Math::round(y), Math::round(z));
}
-Vector3 Vector3::lerp(const Vector3 &p_b, real_t p_t) const {
+Vector3 Vector3::lerp(const Vector3 &p_to, real_t p_weight) const {
return Vector3(
- x + (p_t * (p_b.x - x)),
- y + (p_t * (p_b.y - y)),
- z + (p_t * (p_b.z - z)));
+ x + (p_weight * (p_to.x - x)),
+ y + (p_weight * (p_to.y - y)),
+ z + (p_weight * (p_to.z - z)));
}
-Vector3 Vector3::slerp(const Vector3 &p_b, real_t p_t) const {
- real_t theta = angle_to(p_b);
- return rotated(cross(p_b).normalized(), theta * p_t);
+Vector3 Vector3::slerp(const Vector3 &p_to, real_t p_weight) const {
+ real_t theta = angle_to(p_to);
+ return rotated(cross(p_to).normalized(), theta * p_weight);
}
-real_t Vector3::distance_to(const Vector3 &p_b) const {
- return (p_b - *this).length();
+real_t Vector3::distance_to(const Vector3 &p_to) const {
+ return (p_to - *this).length();
}
-real_t Vector3::distance_squared_to(const Vector3 &p_b) const {
- return (p_b - *this).length_squared();
+real_t Vector3::distance_squared_to(const Vector3 &p_to) const {
+ return (p_to - *this).length_squared();
}
Vector3 Vector3::posmod(const real_t p_mod) const {
@@ -223,16 +222,16 @@ Vector3 Vector3::posmodv(const Vector3 &p_modv) const {
return Vector3(Math::fposmod(x, p_modv.x), Math::fposmod(y, p_modv.y), Math::fposmod(z, p_modv.z));
}
-Vector3 Vector3::project(const Vector3 &p_b) const {
- return p_b * (dot(p_b) / p_b.length_squared());
+Vector3 Vector3::project(const Vector3 &p_to) const {
+ return p_to * (dot(p_to) / p_to.length_squared());
}
-real_t Vector3::angle_to(const Vector3 &p_b) const {
- return Math::atan2(cross(p_b).length(), dot(p_b));
+real_t Vector3::angle_to(const Vector3 &p_to) const {
+ return Math::atan2(cross(p_to).length(), dot(p_to));
}
-Vector3 Vector3::direction_to(const Vector3 &p_b) const {
- Vector3 ret(p_b.x - x, p_b.y - y, p_b.z - z);
+Vector3 Vector3::direction_to(const Vector3 &p_to) const {
+ Vector3 ret(p_to.x - x, p_to.y - y, p_to.z - z);
ret.normalize();
return ret;
}
diff --git a/core/object/class_db.cpp b/core/object/class_db.cpp
index dc28fa10de..f5171f60ec 100644
--- a/core/object/class_db.cpp
+++ b/core/object/class_db.cpp
@@ -243,8 +243,11 @@ HashMap<StringName, StringName> ClassDB::resource_base_extensions;
HashMap<StringName, StringName> ClassDB::compat_classes;
bool ClassDB::_is_parent_class(const StringName &p_class, const StringName &p_inherits) {
- StringName inherits = p_class;
+ if (!classes.has(p_class)) {
+ return false;
+ }
+ StringName inherits = p_class;
while (inherits.operator String().length()) {
if (inherits == p_inherits) {
return true;
diff --git a/core/object/object.cpp b/core/object/object.cpp
index a642647853..681e1188ff 100644
--- a/core/object/object.cpp
+++ b/core/object/object.cpp
@@ -823,10 +823,6 @@ void Object::property_list_changed_notify() {
_change_notify();
}
-void Object::cancel_delete() {
- _predelete_ok = true;
-}
-
void Object::set_script_and_instance(const Variant &p_script, ScriptInstance *p_instance) {
//this function is not meant to be used in any of these ways
ERR_FAIL_COND(p_script.is_null());
@@ -1266,10 +1262,6 @@ void Object::get_signals_connected_to_this(List<Connection> *p_connections) cons
}
}
-Error Object::connect_compat(const StringName &p_signal, Object *p_to_object, const StringName &p_to_method, const Vector<Variant> &p_binds, uint32_t p_flags) {
- return connect(p_signal, Callable(p_to_object, p_to_method), p_binds, p_flags);
-}
-
Error Object::connect(const StringName &p_signal, const Callable &p_callable, const Vector<Variant> &p_binds, uint32_t p_flags) {
ERR_FAIL_COND_V(p_callable.is_null(), ERR_INVALID_PARAMETER);
@@ -1331,10 +1323,6 @@ Error Object::connect(const StringName &p_signal, const Callable &p_callable, co
return OK;
}
-bool Object::is_connected_compat(const StringName &p_signal, Object *p_to_object, const StringName &p_to_method) const {
- return is_connected(p_signal, Callable(p_to_object, p_to_method));
-}
-
bool Object::is_connected(const StringName &p_signal, const Callable &p_callable) const {
ERR_FAIL_COND_V(p_callable.is_null(), false);
const SignalData *s = signal_map.getptr(p_signal);
@@ -1358,10 +1346,6 @@ bool Object::is_connected(const StringName &p_signal, const Callable &p_callable
//return (E!=nullptr );
}
-void Object::disconnect_compat(const StringName &p_signal, Object *p_to_object, const StringName &p_to_method) {
- _disconnect(p_signal, Callable(p_to_object, p_to_method));
-}
-
void Object::disconnect(const StringName &p_signal, const Callable &p_callable) {
_disconnect(p_signal, p_callable);
}
diff --git a/core/object/object.h b/core/object/object.h
index 0bcfa42e3d..dc004f38a9 100644
--- a/core/object/object.h
+++ b/core/object/object.h
@@ -525,8 +525,6 @@ protected:
static void get_valid_parents_static(List<String> *p_parents);
static void _get_valid_parents_static(List<String> *p_parents);
- void cancel_delete();
-
virtual void _changed_callback(Object *p_changed, const char *p_prop);
//Variant _call_bind(const StringName& p_name, const Variant& p_arg1 = Variant(), const Variant& p_arg2 = Variant(), const Variant& p_arg3 = Variant(), const Variant& p_arg4 = Variant());
@@ -697,10 +695,6 @@ public:
int get_persistent_signal_connection_count() const;
void get_signals_connected_to_this(List<Connection> *p_connections) const;
- Error connect_compat(const StringName &p_signal, Object *p_to_object, const StringName &p_to_method, const Vector<Variant> &p_binds = Vector<Variant>(), uint32_t p_flags = 0);
- void disconnect_compat(const StringName &p_signal, Object *p_to_object, const StringName &p_to_method);
- bool is_connected_compat(const StringName &p_signal, Object *p_to_object, const StringName &p_to_method) const;
-
Error connect(const StringName &p_signal, const Callable &p_callable, const Vector<Variant> &p_binds = Vector<Variant>(), uint32_t p_flags = 0);
void disconnect(const StringName &p_signal, const Callable &p_callable);
bool is_connected(const StringName &p_signal, const Callable &p_callable) const;
diff --git a/core/object/script_language.h b/core/object/script_language.h
index 3fd56c2f15..f5d65cf42d 100644
--- a/core/object/script_language.h
+++ b/core/object/script_language.h
@@ -31,6 +31,7 @@
#ifndef SCRIPT_LANGUAGE_H
#define SCRIPT_LANGUAGE_H
+#include "core/doc_data.h"
#include "core/io/multiplayer_api.h"
#include "core/io/resource.h"
#include "core/templates/map.h"
@@ -145,6 +146,10 @@ public:
virtual void set_source_code(const String &p_code) = 0;
virtual Error reload(bool p_keep_state = false) = 0;
+#ifdef TOOLS_ENABLED
+ virtual const Vector<DocData::ClassDoc> &get_documentation() const = 0;
+#endif // TOOLS_ENABLED
+
virtual bool has_method(const StringName &p_method) const = 0;
virtual MethodInfo get_method_info(const StringName &p_method) const = 0;
@@ -269,8 +274,6 @@ class ScriptCodeCompletionCache {
static ScriptCodeCompletionCache *singleton;
public:
- virtual RES get_cached_resource(const String &p_path) = 0;
-
static ScriptCodeCompletionCache *get_singleton() { return singleton; }
ScriptCodeCompletionCache();
@@ -310,7 +313,8 @@ public:
virtual Script *create_script() const = 0;
virtual bool has_named_classes() const = 0;
virtual bool supports_builtin_mode() const = 0;
- virtual bool can_inherit_from_file() { return false; }
+ virtual bool supports_documentation() const { return false; }
+ virtual bool can_inherit_from_file() const { return false; }
virtual int find_function(const String &p_function, const String &p_code) const = 0;
virtual String make_function(const String &p_class, const String &p_name, const PackedStringArray &p_args) const = 0;
virtual Error open_in_external_editor(const Ref<Script> &p_script, int p_line, int p_col) { return ERR_UNAVAILABLE; }
diff --git a/core/os/file_access.cpp b/core/os/file_access.cpp
index b962f61e1f..aa95f06cff 100644
--- a/core/os/file_access.cpp
+++ b/core/os/file_access.cpp
@@ -349,7 +349,7 @@ Vector<String> FileAccess::get_csv_line(const String &p_delim) const {
strings.push_back(current);
current = String();
} else if (c == '"') {
- if (l[i + 1] == '"') {
+ if (l[i + 1] == '"' && in_quote) {
s[0] = '"';
current += s;
i++;
diff --git a/core/os/os.cpp b/core/os/os.cpp
index 552bf043bf..9400565484 100644
--- a/core/os/os.cpp
+++ b/core/os/os.cpp
@@ -505,12 +505,8 @@ void OS::add_frame_delay(bool p_can_draw) {
}
OS::OS() {
- void *volatile stack_bottom;
-
singleton = this;
- _stack_bottom = (void *)(&stack_bottom);
-
Vector<Logger *> loggers;
loggers.push_back(memnew(StdLogger));
_set_logger(memnew(CompositeLogger(loggers)));
diff --git a/core/os/os.h b/core/os/os.h
index 40104b479b..3c79d7bb87 100644
--- a/core/os/os.h
+++ b/core/os/os.h
@@ -62,8 +62,6 @@ class OS {
char *last_error;
- void *_stack_bottom;
-
CompositeLogger *_logger = nullptr;
bool restart_on_exit = false;
diff --git a/core/register_core_types.cpp b/core/register_core_types.cpp
index 7e32f215e7..9883ce12a0 100644
--- a/core/register_core_types.cpp
+++ b/core/register_core_types.cpp
@@ -168,6 +168,7 @@ void register_core_types() {
ClassDB::register_class<AESContext>();
ClassDB::register_custom_instance_class<X509Certificate>();
ClassDB::register_custom_instance_class<CryptoKey>();
+ ClassDB::register_custom_instance_class<HMACContext>();
ClassDB::register_custom_instance_class<Crypto>();
ClassDB::register_custom_instance_class<StreamPeerSSL>();
diff --git a/core/string/node_path.cpp b/core/string/node_path.cpp
index 4d152d9258..a63dde5b41 100644
--- a/core/string/node_path.cpp
+++ b/core/string/node_path.cpp
@@ -288,7 +288,7 @@ void NodePath::simplify() {
if (data->path[i].operator String() == ".") {
data->path.remove(i);
i--;
- } else if (data->path[i].operator String() == ".." && i > 0 && data->path[i - 1].operator String() != "." && data->path[i - 1].operator String() != "..") {
+ } else if (i > 0 && data->path[i].operator String() == ".." && data->path[i - 1].operator String() != "." && data->path[i - 1].operator String() != "..") {
//remove both
data->path.remove(i - 1);
data->path.remove(i - 1);
diff --git a/core/templates/pass_func.h b/core/templates/pass_func.h
new file mode 100644
index 0000000000..a074ad190d
--- /dev/null
+++ b/core/templates/pass_func.h
@@ -0,0 +1,100 @@
+/*************************************************************************/
+/* pass_func.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 PASS_FUNC_H
+#define PASS_FUNC_H
+
+#define PASS0R(m_r, m_name) \
+ m_r m_name() { return PASSBASE->m_name(); }
+#define PASS0RC(m_r, m_name) \
+ m_r m_name() const { return PASSBASE->m_name(); }
+#define PASS1R(m_r, m_name, m_type1) \
+ m_r m_name(m_type1 arg1) { return PASSBASE->m_name(arg1); }
+#define PASS1RC(m_r, m_name, m_type1) \
+ m_r m_name(m_type1 arg1) const { return PASSBASE->m_name(arg1); }
+#define PASS2R(m_r, m_name, m_type1, m_type2) \
+ m_r m_name(m_type1 arg1, m_type2 arg2) { return PASSBASE->m_name(arg1, arg2); }
+#define PASS2RC(m_r, m_name, m_type1, m_type2) \
+ m_r m_name(m_type1 arg1, m_type2 arg2) const { return PASSBASE->m_name(arg1, arg2); }
+#define PASS3R(m_r, m_name, m_type1, m_type2, m_type3) \
+ m_r m_name(m_type1 arg1, m_type2 arg2, m_type3 arg3) { return PASSBASE->m_name(arg1, arg2, arg3); }
+#define PASS3RC(m_r, m_name, m_type1, m_type2, m_type3) \
+ m_r m_name(m_type1 arg1, m_type2 arg2, m_type3 arg3) const { return PASSBASE->m_name(arg1, arg2, arg3); }
+#define PASS4R(m_r, m_name, m_type1, m_type2, m_type3, m_type4) \
+ m_r m_name(m_type1 arg1, m_type2 arg2, m_type3 arg3, m_type4 arg4) { return PASSBASE->m_name(arg1, arg2, arg3, arg4); }
+#define PASS4RC(m_r, m_name, m_type1, m_type2, m_type3, m_type4) \
+ m_r m_name(m_type1 arg1, m_type2 arg2, m_type3 arg3, m_type4 arg4) const { return PASSBASE->m_name(arg1, arg2, arg3, arg4); }
+#define PASS5R(m_r, m_name, m_type1, m_type2, m_type3, m_type4, m_type5) \
+ m_r m_name(m_type1 arg1, m_type2 arg2, m_type3 arg3, m_type4 arg4, m_type5 arg5) { return PASSBASE->m_name(arg1, arg2, arg3, arg4, arg5); }
+#define PASS5RC(m_r, m_name, m_type1, m_type2, m_type3, m_type4, m_type5) \
+ m_r m_name(m_type1 arg1, m_type2 arg2, m_type3 arg3, m_type4 arg4, m_type5 arg5) const { return PASSBASE->m_name(arg1, arg2, arg3, arg4, arg5); }
+#define PASS6R(m_r, m_name, m_type1, m_type2, m_type3, m_type4, m_type5, m_type6) \
+ m_r m_name(m_type1 arg1, m_type2 arg2, m_type3 arg3, m_type4 arg4, m_type5 arg5, m_type6 arg6) { return PASSBASE->m_name(arg1, arg2, arg3, arg4, arg5, arg6); }
+#define PASS6RC(m_r, m_name, m_type1, m_type2, m_type3, m_type4, m_type5, m_type6) \
+ m_r m_name(m_type1 arg1, m_type2 arg2, m_type3 arg3, m_type4 arg4, m_type5 arg5, m_type6 arg6) const { return PASSBASE->m_name(arg1, arg2, arg3, arg4, arg5, arg6); }
+
+#define PASS0(m_name) \
+ void m_name() { PASSBASE->m_name(); }
+#define PASS1(m_name, m_type1) \
+ void m_name(m_type1 arg1) { PASSBASE->m_name(arg1); }
+#define PASS1C(m_name, m_type1) \
+ void m_name(m_type1 arg1) const { PASSBASE->m_name(arg1); }
+#define PASS2(m_name, m_type1, m_type2) \
+ void m_name(m_type1 arg1, m_type2 arg2) { PASSBASE->m_name(arg1, arg2); }
+#define PASS2C(m_name, m_type1, m_type2) \
+ void m_name(m_type1 arg1, m_type2 arg2) const { PASSBASE->m_name(arg1, arg2); }
+#define PASS3(m_name, m_type1, m_type2, m_type3) \
+ void m_name(m_type1 arg1, m_type2 arg2, m_type3 arg3) { PASSBASE->m_name(arg1, arg2, arg3); }
+#define PASS4(m_name, m_type1, m_type2, m_type3, m_type4) \
+ void m_name(m_type1 arg1, m_type2 arg2, m_type3 arg3, m_type4 arg4) { PASSBASE->m_name(arg1, arg2, arg3, arg4); }
+#define PASS5(m_name, m_type1, m_type2, m_type3, m_type4, m_type5) \
+ void m_name(m_type1 arg1, m_type2 arg2, m_type3 arg3, m_type4 arg4, m_type5 arg5) { PASSBASE->m_name(arg1, arg2, arg3, arg4, arg5); }
+#define PASS6(m_name, m_type1, m_type2, m_type3, m_type4, m_type5, m_type6) \
+ void m_name(m_type1 arg1, m_type2 arg2, m_type3 arg3, m_type4 arg4, m_type5 arg5, m_type6 arg6) { PASSBASE->m_name(arg1, arg2, arg3, arg4, arg5, arg6); }
+#define PASS7(m_name, m_type1, m_type2, m_type3, m_type4, m_type5, m_type6, m_type7) \
+ void m_name(m_type1 arg1, m_type2 arg2, m_type3 arg3, m_type4 arg4, m_type5 arg5, m_type6 arg6, m_type7 arg7) { PASSBASE->m_name(arg1, arg2, arg3, arg4, arg5, arg6, arg7); }
+#define PASS8(m_name, m_type1, m_type2, m_type3, m_type4, m_type5, m_type6, m_type7, m_type8) \
+ void m_name(m_type1 arg1, m_type2 arg2, m_type3 arg3, m_type4 arg4, m_type5 arg5, m_type6 arg6, m_type7 arg7, m_type8 arg8) { PASSBASE->m_name(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); }
+#define PASS9(m_name, m_type1, m_type2, m_type3, m_type4, m_type5, m_type6, m_type7, m_type8, m_type9) \
+ void m_name(m_type1 arg1, m_type2 arg2, m_type3 arg3, m_type4 arg4, m_type5 arg5, m_type6 arg6, m_type7 arg7, m_type8 arg8, m_type9 arg9) { PASSBASE->m_name(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9); }
+#define PASS10(m_name, m_type1, m_type2, m_type3, m_type4, m_type5, m_type6, m_type7, m_type8, m_type9, m_type10) \
+ void m_name(m_type1 arg1, m_type2 arg2, m_type3 arg3, m_type4 arg4, m_type5 arg5, m_type6 arg6, m_type7 arg7, m_type8 arg8, m_type9 arg9, m_type10 arg10) { PASSBASE->m_name(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10); }
+#define PASS11(m_name, m_type1, m_type2, m_type3, m_type4, m_type5, m_type6, m_type7, m_type8, m_type9, m_type10, m_type11) \
+ void m_name(m_type1 arg1, m_type2 arg2, m_type3 arg3, m_type4 arg4, m_type5 arg5, m_type6 arg6, m_type7 arg7, m_type8 arg8, m_type9 arg9, m_type10 arg10, m_type11 arg11) { PASSBASE->m_name(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11); }
+#define PASS12(m_name, m_type1, m_type2, m_type3, m_type4, m_type5, m_type6, m_type7, m_type8, m_type9, m_type10, m_type11, m_type12) \
+ void m_name(m_type1 arg1, m_type2 arg2, m_type3 arg3, m_type4 arg4, m_type5 arg5, m_type6 arg6, m_type7 arg7, m_type8 arg8, m_type9 arg9, m_type10 arg10, m_type11 arg11, m_type12 arg12) { PASSBASE->m_name(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12); }
+#define PASS13(m_name, m_type1, m_type2, m_type3, m_type4, m_type5, m_type6, m_type7, m_type8, m_type9, m_type10, m_type11, m_type12, m_type13) \
+ void m_name(m_type1 arg1, m_type2 arg2, m_type3 arg3, m_type4 arg4, m_type5 arg5, m_type6 arg6, m_type7 arg7, m_type8 arg8, m_type9 arg9, m_type10 arg10, m_type11 arg11, m_type12 arg12, m_type13 arg13) { PASSBASE->m_name(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13); }
+#define PASS14(m_name, m_type1, m_type2, m_type3, m_type4, m_type5, m_type6, m_type7, m_type8, m_type9, m_type10, m_type11, m_type12, m_type13, m_type14) \
+ void m_name(m_type1 arg1, m_type2 arg2, m_type3 arg3, m_type4 arg4, m_type5 arg5, m_type6 arg6, m_type7 arg7, m_type8 arg8, m_type9 arg9, m_type10 arg10, m_type11 arg11, m_type12 arg12, m_type13 arg13, m_type14 arg14) { PASSBASE->m_name(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14); }
+#define PASS15(m_name, m_type1, m_type2, m_type3, m_type4, m_type5, m_type6, m_type7, m_type8, m_type9, m_type10, m_type11, m_type12, m_type13, m_type14, m_type15) \
+ void m_name(m_type1 arg1, m_type2 arg2, m_type3 arg3, m_type4 arg4, m_type5 arg5, m_type6 arg6, m_type7 arg7, m_type8 arg8, m_type9 arg9, m_type10 arg10, m_type11 arg11, m_type12 arg12, m_type13 arg13, m_type14 arg14, m_type15 arg15) { PASSBASE->m_name(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15); }
+
+#endif // PASS_FUNC_H
diff --git a/core/variant/method_ptrcall.h b/core/variant/method_ptrcall.h
index 40fa3543dc..b00455f8ad 100644
--- a/core/variant/method_ptrcall.h
+++ b/core/variant/method_ptrcall.h
@@ -100,6 +100,7 @@ struct PtrToArg {};
}
MAKE_PTRARG(bool);
+// Integer types.
MAKE_PTRARGCONV(uint8_t, int64_t);
MAKE_PTRARGCONV(int8_t, int64_t);
MAKE_PTRARGCONV(uint16_t, int64_t);
@@ -108,15 +109,16 @@ MAKE_PTRARGCONV(uint32_t, int64_t);
MAKE_PTRARGCONV(int32_t, int64_t);
MAKE_PTRARG(int64_t);
MAKE_PTRARG(uint64_t);
+// Float types
MAKE_PTRARGCONV(float, double);
MAKE_PTRARG(double);
MAKE_PTRARG(String);
MAKE_PTRARG(Vector2);
-MAKE_PTRARG(Rect2);
-MAKE_PTRARG_BY_REFERENCE(Vector3);
MAKE_PTRARG(Vector2i);
+MAKE_PTRARG(Rect2);
MAKE_PTRARG(Rect2i);
+MAKE_PTRARG_BY_REFERENCE(Vector3);
MAKE_PTRARG_BY_REFERENCE(Vector3i);
MAKE_PTRARG(Transform2D);
MAKE_PTRARG_BY_REFERENCE(Plane);
@@ -128,9 +130,10 @@ MAKE_PTRARG_BY_REFERENCE(Color);
MAKE_PTRARG(StringName);
MAKE_PTRARG(NodePath);
MAKE_PTRARG(RID);
-MAKE_PTRARG(Dictionary);
+// Object doesn't need this.
MAKE_PTRARG(Callable);
MAKE_PTRARG(Signal);
+MAKE_PTRARG(Dictionary);
MAKE_PTRARG(Array);
MAKE_PTRARG(PackedByteArray);
MAKE_PTRARG(PackedInt32Array);
diff --git a/core/variant/variant.h b/core/variant/variant.h
index d87078b5da..76c936a7bd 100644
--- a/core/variant/variant.h
+++ b/core/variant/variant.h
@@ -511,7 +511,7 @@ public:
/* Constructors */
- typedef void (*ValidatedConstructor)(Variant &r_base, const Variant **p_args);
+ typedef void (*ValidatedConstructor)(Variant *r_base, const Variant **p_args);
typedef void (*PTRConstructor)(void *base, const void **p_args);
static int get_constructor_count(Variant::Type p_type);
@@ -550,8 +550,8 @@ public:
static bool has_indexing(Variant::Type p_type);
static Variant::Type get_indexed_element_type(Variant::Type p_type);
- typedef void (*ValidatedIndexedSetter)(Variant *base, int64_t index, const Variant *value, bool &oob);
- typedef void (*ValidatedIndexedGetter)(const Variant *base, int64_t index, Variant *value, bool &oob);
+ typedef void (*ValidatedIndexedSetter)(Variant *base, int64_t index, const Variant *value, bool *oob);
+ typedef void (*ValidatedIndexedGetter)(const Variant *base, int64_t index, Variant *value, bool *oob);
static ValidatedIndexedSetter get_member_validated_indexed_setter(Variant::Type p_type);
static ValidatedIndexedGetter get_member_validated_indexed_getter(Variant::Type p_type);
@@ -571,9 +571,9 @@ public:
static bool is_keyed(Variant::Type p_type);
- typedef void (*ValidatedKeyedSetter)(Variant *base, const Variant *key, const Variant *value, bool &valid);
- typedef void (*ValidatedKeyedGetter)(const Variant *base, const Variant *key, Variant *value, bool &valid);
- typedef bool (*ValidatedKeyedChecker)(const Variant *base, const Variant *key, bool &valid);
+ typedef void (*ValidatedKeyedSetter)(Variant *base, const Variant *key, const Variant *value, bool *valid);
+ typedef void (*ValidatedKeyedGetter)(const Variant *base, const Variant *key, Variant *value, bool *valid);
+ typedef bool (*ValidatedKeyedChecker)(const Variant *base, const Variant *key, bool *valid);
static ValidatedKeyedSetter get_member_validated_keyed_setter(Variant::Type p_type);
static ValidatedKeyedGetter get_member_validated_keyed_getter(Variant::Type p_type);
diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp
index 214c424013..d588c83809 100644
--- a/core/variant/variant_call.cpp
+++ b/core/variant/variant_call.cpp
@@ -987,9 +987,9 @@ static void _register_variant_builtin_methods() {
bind_method(Vector2, posmod, sarray("mod"), varray());
bind_method(Vector2, posmodv, sarray("modv"), varray());
bind_method(Vector2, project, sarray("b"), varray());
- bind_method(Vector2, lerp, sarray("with", "t"), varray());
- bind_method(Vector2, slerp, sarray("with", "t"), varray());
- bind_method(Vector2, cubic_interpolate, sarray("b", "pre_a", "post_b", "t"), varray());
+ bind_method(Vector2, lerp, sarray("to", "weight"), varray());
+ bind_method(Vector2, slerp, sarray("to", "weight"), varray());
+ bind_method(Vector2, cubic_interpolate, sarray("b", "pre_a", "post_b", "weight"), varray());
bind_method(Vector2, move_toward, sarray("to", "delta"), varray());
bind_method(Vector2, rotated, sarray("phi"), varray());
bind_method(Vector2, tangent, sarray(), varray());
@@ -1060,9 +1060,9 @@ static void _register_variant_builtin_methods() {
bind_method(Vector3, inverse, sarray(), varray());
bind_method(Vector3, snapped, sarray("by"), varray());
bind_method(Vector3, rotated, sarray("by_axis", "phi"), varray());
- bind_method(Vector3, lerp, sarray("b", "t"), varray());
- bind_method(Vector3, slerp, sarray("b", "t"), varray());
- bind_method(Vector3, cubic_interpolate, sarray("b", "pre_a", "post_b", "t"), varray());
+ bind_method(Vector3, lerp, sarray("to", "weight"), varray());
+ bind_method(Vector3, slerp, sarray("to", "weight"), varray());
+ bind_method(Vector3, cubic_interpolate, sarray("b", "pre_a", "post_b", "weight"), varray());
bind_method(Vector3, move_toward, sarray("to", "delta"), varray());
bind_method(Vector3, dot, sarray("with"), varray());
bind_method(Vector3, cross, sarray("with"), varray());
@@ -1109,9 +1109,9 @@ static void _register_variant_builtin_methods() {
bind_method(Quat, is_equal_approx, sarray("to"), varray());
bind_method(Quat, inverse, sarray(), varray());
bind_method(Quat, dot, sarray("with"), varray());
- bind_method(Quat, slerp, sarray("b", "t"), varray());
- bind_method(Quat, slerpni, sarray("b", "t"), varray());
- bind_method(Quat, cubic_slerp, sarray("b", "pre_a", "post_b", "t"), varray());
+ bind_method(Quat, slerp, sarray("to", "weight"), varray());
+ bind_method(Quat, slerpni, sarray("to", "weight"), varray());
+ bind_method(Quat, cubic_slerp, sarray("b", "pre_a", "post_b", "weight"), varray());
bind_method(Quat, get_euler, sarray(), varray());
// FIXME: Quat is atomic, this should be done via construcror
@@ -1128,7 +1128,7 @@ static void _register_variant_builtin_methods() {
bind_method(Color, to_rgba64, sarray(), varray());
bind_method(Color, inverted, sarray(), varray());
- bind_method(Color, lerp, sarray("b", "t"), varray());
+ bind_method(Color, lerp, sarray("to", "weight"), varray());
bind_method(Color, lightened, sarray("amount"), varray());
bind_method(Color, darkened, sarray("amount"), varray());
bind_method(Color, to_html, sarray("with_alpha"), varray(true));
@@ -1195,7 +1195,7 @@ static void _register_variant_builtin_methods() {
bind_method(Transform2D, translated, sarray("offset"), varray());
bind_method(Transform2D, basis_xform, sarray("v"), varray());
bind_method(Transform2D, basis_xform_inv, sarray("v"), varray());
- bind_method(Transform2D, interpolate_with, sarray("xform", "t"), varray());
+ bind_method(Transform2D, interpolate_with, sarray("xform", "weight"), varray());
bind_method(Transform2D, is_equal_approx, sarray("xform"), varray());
/* Basis */
@@ -1212,7 +1212,7 @@ static void _register_variant_builtin_methods() {
bind_method(Basis, tdoty, sarray("with"), varray());
bind_method(Basis, tdotz, sarray("with"), varray());
bind_method(Basis, get_orthogonal_index, sarray(), varray());
- bind_method(Basis, slerp, sarray("b", "t"), varray());
+ bind_method(Basis, slerp, sarray("to", "weight"), varray());
bind_method(Basis, is_equal_approx, sarray("b"), varray());
bind_method(Basis, get_rotation_quat, sarray(), varray());
diff --git a/core/variant/variant_construct.cpp b/core/variant/variant_construct.cpp
index 01f5b7df59..732e7a26f2 100644
--- a/core/variant/variant_construct.cpp
+++ b/core/variant/variant_construct.cpp
@@ -39,6 +39,60 @@
#include "core/templates/local_vector.h"
#include "core/templates/oa_hash_map.h"
+template <class T>
+struct PtrConstruct {};
+
+#define MAKE_PTRCONSTRUCT(m_type) \
+ template <> \
+ struct PtrConstruct<m_type> { \
+ _FORCE_INLINE_ static void construct(const m_type &p_value, void *p_ptr) { \
+ memnew_placement(p_ptr, m_type(p_value)); \
+ } \
+ };
+
+MAKE_PTRCONSTRUCT(bool);
+MAKE_PTRCONSTRUCT(int64_t);
+MAKE_PTRCONSTRUCT(double);
+MAKE_PTRCONSTRUCT(String);
+MAKE_PTRCONSTRUCT(Vector2);
+MAKE_PTRCONSTRUCT(Vector2i);
+MAKE_PTRCONSTRUCT(Rect2);
+MAKE_PTRCONSTRUCT(Rect2i);
+MAKE_PTRCONSTRUCT(Vector3);
+MAKE_PTRCONSTRUCT(Vector3i);
+MAKE_PTRCONSTRUCT(Transform2D);
+MAKE_PTRCONSTRUCT(Plane);
+MAKE_PTRCONSTRUCT(Quat);
+MAKE_PTRCONSTRUCT(AABB);
+MAKE_PTRCONSTRUCT(Basis);
+MAKE_PTRCONSTRUCT(Transform);
+MAKE_PTRCONSTRUCT(Color);
+MAKE_PTRCONSTRUCT(StringName);
+MAKE_PTRCONSTRUCT(NodePath);
+MAKE_PTRCONSTRUCT(RID);
+
+template <>
+struct PtrConstruct<Object *> {
+ _FORCE_INLINE_ static void construct(Object *p_value, void *p_ptr) {
+ *((Object **)p_ptr) = p_value;
+ }
+};
+
+MAKE_PTRCONSTRUCT(Callable);
+MAKE_PTRCONSTRUCT(Signal);
+MAKE_PTRCONSTRUCT(Dictionary);
+MAKE_PTRCONSTRUCT(Array);
+MAKE_PTRCONSTRUCT(PackedByteArray);
+MAKE_PTRCONSTRUCT(PackedInt32Array);
+MAKE_PTRCONSTRUCT(PackedInt64Array);
+MAKE_PTRCONSTRUCT(PackedFloat32Array);
+MAKE_PTRCONSTRUCT(PackedFloat64Array);
+MAKE_PTRCONSTRUCT(PackedStringArray);
+MAKE_PTRCONSTRUCT(PackedVector2Array);
+MAKE_PTRCONSTRUCT(PackedVector3Array);
+MAKE_PTRCONSTRUCT(PackedColorArray);
+MAKE_PTRCONSTRUCT(Variant);
+
template <class T, class... P>
class VariantConstructor {
template <size_t... Is>
@@ -59,7 +113,7 @@ class VariantConstructor {
template <size_t... Is>
static _FORCE_INLINE_ void ptr_construct_helper(void *base, const void **p_args, IndexSequence<Is...>) {
- PtrToArg<T>::encode(T(PtrToArg<P>::convert(p_args[Is])...), base);
+ PtrConstruct<T>::construct(T(PtrToArg<P>::convert(p_args[Is])...), base);
}
public:
@@ -69,9 +123,9 @@ public:
construct_helper(*VariantGetInternalPtr<T>::get_ptr(&r_ret), p_args, r_error, BuildIndexSequence<sizeof...(P)>{});
}
- static void validated_construct(Variant &r_ret, const Variant **p_args) {
- VariantTypeChanger<T>::change(&r_ret);
- validated_construct_helper(*VariantGetInternalPtr<T>::get_ptr(&r_ret), p_args, BuildIndexSequence<sizeof...(P)>{});
+ static void validated_construct(Variant *r_ret, const Variant **p_args) {
+ VariantTypeChanger<T>::change(r_ret);
+ validated_construct_helper(*VariantGetInternalPtr<T>::get_ptr(r_ret), p_args, BuildIndexSequence<sizeof...(P)>{});
}
static void ptr_construct(void *base, const void **p_args) {
ptr_construct_helper(base, p_args, BuildIndexSequence<sizeof...(P)>{});
@@ -107,12 +161,12 @@ public:
}
}
- static void validated_construct(Variant &r_ret, const Variant **p_args) {
- VariantInternal::clear(&r_ret);
- VariantInternal::object_assign(&r_ret, p_args[0]);
+ static void validated_construct(Variant *r_ret, const Variant **p_args) {
+ VariantInternal::clear(r_ret);
+ VariantInternal::object_assign(r_ret, p_args[0]);
}
static void ptr_construct(void *base, const void **p_args) {
- PtrToArg<Object *>::encode(PtrToArg<Object *>::convert(p_args[0]), base);
+ PtrConstruct<Object *>::construct(PtrToArg<Object *>::convert(p_args[0]), base);
}
static int get_argument_count() {
@@ -141,12 +195,12 @@ public:
VariantInternal::object_assign_null(&r_ret);
}
- static void validated_construct(Variant &r_ret, const Variant **p_args) {
- VariantInternal::clear(&r_ret);
- VariantInternal::object_assign_null(&r_ret);
+ static void validated_construct(Variant *r_ret, const Variant **p_args) {
+ VariantInternal::clear(r_ret);
+ VariantInternal::object_assign_null(r_ret);
}
static void ptr_construct(void *base, const void **p_args) {
- PtrToArg<Object *>::encode(nullptr, base);
+ PtrConstruct<Object *>::construct(nullptr, base);
}
static int get_argument_count() {
@@ -194,12 +248,12 @@ public:
*VariantGetInternalPtr<Callable>::get_ptr(&r_ret) = Callable(object_id, method);
}
- static void validated_construct(Variant &r_ret, const Variant **p_args) {
- VariantTypeChanger<Callable>::change(&r_ret);
- *VariantGetInternalPtr<Callable>::get_ptr(&r_ret) = Callable(VariantInternal::get_object_id(p_args[0]), *VariantGetInternalPtr<StringName>::get_ptr(p_args[1]));
+ static void validated_construct(Variant *r_ret, const Variant **p_args) {
+ VariantTypeChanger<Callable>::change(r_ret);
+ *VariantGetInternalPtr<Callable>::get_ptr(r_ret) = Callable(VariantInternal::get_object_id(p_args[0]), *VariantGetInternalPtr<StringName>::get_ptr(p_args[1]));
}
static void ptr_construct(void *base, const void **p_args) {
- PtrToArg<Callable>::encode(Callable(PtrToArg<Object *>::convert(p_args[0]), PtrToArg<StringName>::convert(p_args[1])), base);
+ PtrConstruct<Callable>::construct(Callable(PtrToArg<Object *>::convert(p_args[0]), PtrToArg<StringName>::convert(p_args[1])), base);
}
static int get_argument_count() {
@@ -251,12 +305,12 @@ public:
*VariantGetInternalPtr<Signal>::get_ptr(&r_ret) = Signal(object_id, method);
}
- static void validated_construct(Variant &r_ret, const Variant **p_args) {
- VariantTypeChanger<Signal>::change(&r_ret);
- *VariantGetInternalPtr<Signal>::get_ptr(&r_ret) = Signal(VariantInternal::get_object_id(p_args[0]), *VariantGetInternalPtr<StringName>::get_ptr(p_args[1]));
+ static void validated_construct(Variant *r_ret, const Variant **p_args) {
+ VariantTypeChanger<Signal>::change(r_ret);
+ *VariantGetInternalPtr<Signal>::get_ptr(r_ret) = Signal(VariantInternal::get_object_id(p_args[0]), *VariantGetInternalPtr<StringName>::get_ptr(p_args[1]));
}
static void ptr_construct(void *base, const void **p_args) {
- PtrToArg<Signal>::encode(Signal(PtrToArg<Object *>::convert(p_args[0]), PtrToArg<StringName>::convert(p_args[1])), base);
+ PtrConstruct<Signal>::construct(Signal(PtrToArg<Object *>::convert(p_args[0]), PtrToArg<StringName>::convert(p_args[1])), base);
}
static int get_argument_count() {
@@ -298,9 +352,9 @@ public:
}
}
- static void validated_construct(Variant &r_ret, const Variant **p_args) {
- VariantTypeChanger<Array>::change(&r_ret);
- Array &dst_arr = *VariantGetInternalPtr<Array>::get_ptr(&r_ret);
+ static void validated_construct(Variant *r_ret, const Variant **p_args) {
+ VariantTypeChanger<Array>::change(r_ret);
+ Array &dst_arr = *VariantGetInternalPtr<Array>::get_ptr(r_ret);
const T &src_arr = *VariantGetInternalPtr<T>::get_ptr(p_args[0]);
int size = src_arr.size();
@@ -319,7 +373,7 @@ public:
dst_arr[i] = src_arr[i];
}
- PtrToArg<Array>::encode(dst_arr, base);
+ PtrConstruct<Array>::construct(dst_arr, base);
}
static int get_argument_count() {
@@ -357,10 +411,10 @@ public:
}
}
- static void validated_construct(Variant &r_ret, const Variant **p_args) {
- VariantTypeChanger<T>::change(&r_ret);
+ static void validated_construct(Variant *r_ret, const Variant **p_args) {
+ VariantTypeChanger<T>::change(r_ret);
const Array &src_arr = *VariantGetInternalPtr<Array>::get_ptr(p_args[0]);
- T &dst_arr = *VariantGetInternalPtr<T>::get_ptr(&r_ret);
+ T &dst_arr = *VariantGetInternalPtr<T>::get_ptr(r_ret);
int size = src_arr.size();
dst_arr.resize(size);
@@ -378,7 +432,7 @@ public:
dst_arr.write[i] = src_arr[i];
}
- PtrToArg<T>::encode(dst_arr, base);
+ PtrConstruct<T>::construct(dst_arr, base);
}
static int get_argument_count() {
@@ -408,11 +462,11 @@ public:
VariantInternal::clear(&r_ret);
}
- static void validated_construct(Variant &r_ret, const Variant **p_args) {
- VariantInternal::clear(&r_ret);
+ static void validated_construct(Variant *r_ret, const Variant **p_args) {
+ VariantInternal::clear(r_ret);
}
static void ptr_construct(void *base, const void **p_args) {
- PtrToArg<Variant>::encode(Variant(), base);
+ PtrConstruct<Variant>::construct(Variant(), base);
}
static int get_argument_count() {
@@ -436,11 +490,11 @@ public:
r_error.error = Callable::CallError::CALL_OK;
}
- static void validated_construct(Variant &r_ret, const Variant **p_args) {
- VariantTypeChanger<T>::change_and_reset(&r_ret);
+ static void validated_construct(Variant *r_ret, const Variant **p_args) {
+ VariantTypeChanger<T>::change_and_reset(r_ret);
}
static void ptr_construct(void *base, const void **p_args) {
- PtrToArg<T>::encode(T(), base);
+ PtrConstruct<T>::construct(T(), base);
}
static int get_argument_count() {
@@ -463,8 +517,8 @@ public:
r_error.error = Callable::CallError::CALL_OK;
}
- static void validated_construct(Variant &r_ret, const Variant **p_args) {
- VariantInternal::clear(&r_ret);
+ static void validated_construct(Variant *r_ret, const Variant **p_args) {
+ VariantInternal::clear(r_ret);
}
static void ptr_construct(void *base, const void **p_args) {
ERR_FAIL_MSG("can't ptrcall nil constructor");
@@ -491,12 +545,12 @@ public:
r_error.error = Callable::CallError::CALL_OK;
}
- static void validated_construct(Variant &r_ret, const Variant **p_args) {
- VariantInternal::clear(&r_ret);
- VariantInternal::object_assign_null(&r_ret);
+ static void validated_construct(Variant *r_ret, const Variant **p_args) {
+ VariantInternal::clear(r_ret);
+ VariantInternal::object_assign_null(r_ret);
}
static void ptr_construct(void *base, const void **p_args) {
- PtrToArg<Object *>::encode(nullptr, base);
+ PtrConstruct<Object *>::construct(nullptr, base);
}
static int get_argument_count() {
@@ -777,18 +831,23 @@ String Variant::get_constructor_argument_name(Variant::Type p_type, int p_constr
return construct_data[p_type][p_constructor].arg_names[p_argument];
}
-void VariantInternal::object_assign(Variant *v, const Variant *o) {
- if (o->_get_obj().obj && o->_get_obj().id.is_reference()) {
- Reference *reference = static_cast<Reference *>(o->_get_obj().obj);
- if (!reference->reference()) {
- v->_get_obj().obj = nullptr;
- v->_get_obj().id = ObjectID();
- return;
+void VariantInternal::object_assign(Variant *v, const Object *o) {
+ if (o) {
+ if (o->is_reference()) {
+ Reference *reference = const_cast<Reference *>(static_cast<const Reference *>(o));
+ if (!reference->init_ref()) {
+ v->_get_obj().obj = nullptr;
+ v->_get_obj().id = ObjectID();
+ return;
+ }
}
- }
- v->_get_obj().obj = const_cast<Object *>(o->_get_obj().obj);
- v->_get_obj().id = o->_get_obj().id;
+ v->_get_obj().obj = const_cast<Object *>(o);
+ v->_get_obj().id = o->get_instance_id();
+ } else {
+ v->_get_obj().obj = nullptr;
+ v->_get_obj().id = ObjectID();
+ }
}
void Variant::get_constructor_list(Type p_type, List<MethodInfo> *r_list) {
diff --git a/core/variant/variant_internal.h b/core/variant/variant_internal.h
index bf7e46eed7..804abf8fbc 100644
--- a/core/variant/variant_internal.h
+++ b/core/variant/variant_internal.h
@@ -100,21 +100,14 @@ public:
case Variant::PACKED_COLOR_ARRAY:
init_color_array(v);
break;
+ case Variant::OBJECT:
+ object_assign_null(v);
+ break;
default:
break;
}
}
- _FORCE_INLINE_ static void set_object(Variant *v, Object *obj) {
- if (obj) {
- v->_get_obj().obj = obj;
- v->_get_obj().id = obj->get_instance_id();
- } else {
- v->_get_obj().obj = nullptr;
- v->_get_obj().id = ObjectID();
- }
- }
-
// Atomic types.
_FORCE_INLINE_ static bool *get_bool(Variant *v) { return &v->_data._bool; }
_FORCE_INLINE_ static const bool *get_bool(const Variant *v) { return &v->_data._bool; }
@@ -285,7 +278,11 @@ public:
v->clear();
}
- static void object_assign(Variant *v, const Variant *o); //needs to use reference, do away
+ static void object_assign(Variant *v, const Object *o); // Needs Reference, so it's implemented elsewhere.
+
+ _FORCE_INLINE_ static void object_assign(Variant *v, const Variant *o) {
+ object_assign(v, o->_get_obj().obj);
+ }
_FORCE_INLINE_ static void object_assign_null(Variant *v) {
v->_get_obj().obj = nullptr;
diff --git a/core/variant/variant_op.cpp b/core/variant/variant_op.cpp
index 07b024ecb4..df29ec7b63 100644
--- a/core/variant/variant_op.cpp
+++ b/core/variant/variant_op.cpp
@@ -1399,6 +1399,8 @@ void Variant::_register_variant_operators() {
register_op<OperatorEvaluatorSub<Vector2i, Vector2i, Vector2i>>(Variant::OP_SUBTRACT, Variant::VECTOR2I, Variant::VECTOR2I);
register_op<OperatorEvaluatorSub<Vector3, Vector3, Vector3>>(Variant::OP_SUBTRACT, Variant::VECTOR3, Variant::VECTOR3);
register_op<OperatorEvaluatorSub<Vector3i, Vector3i, Vector3i>>(Variant::OP_SUBTRACT, Variant::VECTOR3I, Variant::VECTOR3I);
+ register_op<OperatorEvaluatorSub<Quat, Quat, Quat>>(Variant::OP_SUBTRACT, Variant::QUAT, Variant::QUAT);
+ register_op<OperatorEvaluatorSub<Color, Color, Color>>(Variant::OP_SUBTRACT, Variant::COLOR, Variant::COLOR);
register_op<OperatorEvaluatorMul<int64_t, int64_t, int64_t>>(Variant::OP_MULTIPLY, Variant::INT, Variant::INT);
register_op<OperatorEvaluatorMul<double, int64_t, double>>(Variant::OP_MULTIPLY, Variant::INT, Variant::FLOAT);
diff --git a/core/variant/variant_parser.cpp b/core/variant/variant_parser.cpp
index 5a0bbf041b..00d81f597a 100644
--- a/core/variant/variant_parser.cpp
+++ b/core/variant/variant_parser.cpp
@@ -743,6 +743,8 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
return ERR_PARSE_ERROR;
}
+ REF ref = REF(Object::cast_to<Reference>(obj));
+
get_token(p_stream, token, line, r_err_str);
if (token.type != TK_COMMA) {
r_err_str = "Expected ',' after object type";
@@ -767,12 +769,7 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
}
if (token2.type == TK_PARENTHESIS_CLOSE) {
- Reference *reference = Object::cast_to<Reference>(obj);
- if (reference) {
- value = REF(reference);
- } else {
- value = obj;
- }
+ value = ref.is_valid() ? Variant(ref) : Variant(obj);
return OK;
}
diff --git a/core/variant/variant_setget.cpp b/core/variant/variant_setget.cpp
index f6a2c11830..cee7465205 100644
--- a/core/variant/variant_setget.cpp
+++ b/core/variant/variant_setget.cpp
@@ -582,18 +582,18 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const {
#define INDEXED_SETGET_STRUCT_TYPED(m_base_type, m_elem_type) \
struct VariantIndexedSetGet_##m_base_type { \
- static void get(const Variant *base, int64_t index, Variant *value, bool &oob) { \
+ static void get(const Variant *base, int64_t index, Variant *value, bool *oob) { \
int64_t size = VariantGetInternalPtr<m_base_type>::get_ptr(base)->size(); \
if (index < 0) { \
index += size; \
} \
if (index < 0 || index >= size) { \
- oob = true; \
+ *oob = true; \
return; \
} \
VariantTypeAdjust<m_elem_type>::adjust(value); \
*VariantGetInternalPtr<m_elem_type>::get_ptr(value) = (*VariantGetInternalPtr<m_base_type>::get_ptr(base))[index]; \
- oob = false; \
+ *oob = false; \
} \
static void ptr_get(const void *base, int64_t index, void *member) { \
/* avoid ptrconvert for performance*/ \
@@ -603,10 +603,10 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const {
OOB_TEST(index, v.size()); \
PtrToArg<m_elem_type>::encode(v[index], member); \
} \
- static void set(Variant *base, int64_t index, const Variant *value, bool &valid, bool &oob) { \
+ static void set(Variant *base, int64_t index, const Variant *value, bool *valid, bool *oob) { \
if (value->get_type() != GetTypeInfo<m_elem_type>::VARIANT_TYPE) { \
- oob = false; \
- valid = false; \
+ *oob = false; \
+ *valid = false; \
return; \
} \
int64_t size = VariantGetInternalPtr<m_base_type>::get_ptr(base)->size(); \
@@ -614,25 +614,25 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const {
index += size; \
} \
if (index < 0 || index >= size) { \
- oob = true; \
- valid = false; \
+ *oob = true; \
+ *valid = false; \
return; \
} \
(*VariantGetInternalPtr<m_base_type>::get_ptr(base)).write[index] = *VariantGetInternalPtr<m_elem_type>::get_ptr(value); \
- oob = false; \
- valid = true; \
+ *oob = false; \
+ *valid = true; \
} \
- static void validated_set(Variant *base, int64_t index, const Variant *value, bool &oob) { \
+ static void validated_set(Variant *base, int64_t index, const Variant *value, bool *oob) { \
int64_t size = VariantGetInternalPtr<m_base_type>::get_ptr(base)->size(); \
if (index < 0) { \
index += size; \
} \
if (index < 0 || index >= size) { \
- oob = true; \
+ *oob = true; \
return; \
} \
(*VariantGetInternalPtr<m_base_type>::get_ptr(base)).write[index] = *VariantGetInternalPtr<m_elem_type>::get_ptr(value); \
- oob = false; \
+ *oob = false; \
} \
static void ptr_set(void *base, int64_t index, const void *member) { \
/* avoid ptrconvert for performance*/ \
@@ -648,18 +648,18 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const {
#define INDEXED_SETGET_STRUCT_TYPED_NUMERIC(m_base_type, m_elem_type, m_assign_type) \
struct VariantIndexedSetGet_##m_base_type { \
- static void get(const Variant *base, int64_t index, Variant *value, bool &oob) { \
+ static void get(const Variant *base, int64_t index, Variant *value, bool *oob) { \
int64_t size = VariantGetInternalPtr<m_base_type>::get_ptr(base)->size(); \
if (index < 0) { \
index += size; \
} \
if (index < 0 || index >= size) { \
- oob = true; \
+ *oob = true; \
return; \
} \
VariantTypeAdjust<m_elem_type>::adjust(value); \
*VariantGetInternalPtr<m_elem_type>::get_ptr(value) = (*VariantGetInternalPtr<m_base_type>::get_ptr(base))[index]; \
- oob = false; \
+ *oob = false; \
} \
static void ptr_get(const void *base, int64_t index, void *member) { \
/* avoid ptrconvert for performance*/ \
@@ -669,14 +669,14 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const {
OOB_TEST(index, v.size()); \
PtrToArg<m_elem_type>::encode(v[index], member); \
} \
- static void set(Variant *base, int64_t index, const Variant *value, bool &valid, bool &oob) { \
+ static void set(Variant *base, int64_t index, const Variant *value, bool *valid, bool *oob) { \
int64_t size = VariantGetInternalPtr<m_base_type>::get_ptr(base)->size(); \
if (index < 0) { \
index += size; \
} \
if (index < 0 || index >= size) { \
- oob = true; \
- valid = false; \
+ *oob = true; \
+ *valid = false; \
return; \
} \
m_assign_type num; \
@@ -685,25 +685,25 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const {
} else if (value->get_type() == Variant::FLOAT) { \
num = (m_assign_type)*VariantGetInternalPtr<double>::get_ptr(value); \
} else { \
- oob = false; \
- valid = false; \
+ *oob = false; \
+ *valid = false; \
return; \
} \
(*VariantGetInternalPtr<m_base_type>::get_ptr(base)).write[index] = num; \
- oob = false; \
- valid = true; \
+ *oob = false; \
+ *valid = true; \
} \
- static void validated_set(Variant *base, int64_t index, const Variant *value, bool &oob) { \
+ static void validated_set(Variant *base, int64_t index, const Variant *value, bool *oob) { \
int64_t size = VariantGetInternalPtr<m_base_type>::get_ptr(base)->size(); \
if (index < 0) { \
index += size; \
} \
if (index < 0 || index >= size) { \
- oob = true; \
+ *oob = true; \
return; \
} \
(*VariantGetInternalPtr<m_base_type>::get_ptr(base)).write[index] = *VariantGetInternalPtr<m_elem_type>::get_ptr(value); \
- oob = false; \
+ *oob = false; \
} \
static void ptr_set(void *base, int64_t index, const void *member) { \
/* avoid ptrconvert for performance*/ \
@@ -719,14 +719,14 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const {
#define INDEXED_SETGET_STRUCT_BULTIN_NUMERIC(m_base_type, m_elem_type, m_assign_type, m_max) \
struct VariantIndexedSetGet_##m_base_type { \
- static void get(const Variant *base, int64_t index, Variant *value, bool &oob) { \
+ static void get(const Variant *base, int64_t index, Variant *value, bool *oob) { \
if (index < 0 || index >= m_max) { \
- oob = true; \
+ *oob = true; \
return; \
} \
VariantTypeAdjust<m_elem_type>::adjust(value); \
*VariantGetInternalPtr<m_elem_type>::get_ptr(value) = (*VariantGetInternalPtr<m_base_type>::get_ptr(base))[index]; \
- oob = false; \
+ *oob = false; \
} \
static void ptr_get(const void *base, int64_t index, void *member) { \
/* avoid ptrconvert for performance*/ \
@@ -734,10 +734,10 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const {
OOB_TEST(index, m_max); \
PtrToArg<m_elem_type>::encode(v[index], member); \
} \
- static void set(Variant *base, int64_t index, const Variant *value, bool &valid, bool &oob) { \
+ static void set(Variant *base, int64_t index, const Variant *value, bool *valid, bool *oob) { \
if (index < 0 || index >= m_max) { \
- oob = true; \
- valid = false; \
+ *oob = true; \
+ *valid = false; \
return; \
} \
m_assign_type num; \
@@ -746,21 +746,21 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const {
} else if (value->get_type() == Variant::FLOAT) { \
num = (m_assign_type)*VariantGetInternalPtr<double>::get_ptr(value); \
} else { \
- oob = false; \
- valid = false; \
+ *oob = false; \
+ *valid = false; \
return; \
} \
(*VariantGetInternalPtr<m_base_type>::get_ptr(base))[index] = num; \
- oob = false; \
- valid = true; \
+ *oob = false; \
+ *valid = true; \
} \
- static void validated_set(Variant *base, int64_t index, const Variant *value, bool &oob) { \
+ static void validated_set(Variant *base, int64_t index, const Variant *value, bool *oob) { \
if (index < 0 || index >= m_max) { \
- oob = true; \
+ *oob = true; \
return; \
} \
(*VariantGetInternalPtr<m_base_type>::get_ptr(base))[index] = *VariantGetInternalPtr<m_elem_type>::get_ptr(value); \
- oob = false; \
+ *oob = false; \
} \
static void ptr_set(void *base, int64_t index, const void *member) { \
/* avoid ptrconvert for performance*/ \
@@ -774,14 +774,14 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const {
#define INDEXED_SETGET_STRUCT_BULTIN_ACCESSOR(m_base_type, m_elem_type, m_accessor, m_max) \
struct VariantIndexedSetGet_##m_base_type { \
- static void get(const Variant *base, int64_t index, Variant *value, bool &oob) { \
+ static void get(const Variant *base, int64_t index, Variant *value, bool *oob) { \
if (index < 0 || index >= m_max) { \
- oob = true; \
+ *oob = true; \
return; \
} \
VariantTypeAdjust<m_elem_type>::adjust(value); \
*VariantGetInternalPtr<m_elem_type>::get_ptr(value) = (*VariantGetInternalPtr<m_base_type>::get_ptr(base))m_accessor[index]; \
- oob = false; \
+ *oob = false; \
} \
static void ptr_get(const void *base, int64_t index, void *member) { \
/* avoid ptrconvert for performance*/ \
@@ -789,27 +789,27 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const {
OOB_TEST(index, m_max); \
PtrToArg<m_elem_type>::encode(v m_accessor[index], member); \
} \
- static void set(Variant *base, int64_t index, const Variant *value, bool &valid, bool &oob) { \
+ static void set(Variant *base, int64_t index, const Variant *value, bool *valid, bool *oob) { \
if (value->get_type() != GetTypeInfo<m_elem_type>::VARIANT_TYPE) { \
- oob = false; \
- valid = false; \
+ *oob = false; \
+ *valid = false; \
} \
if (index < 0 || index >= m_max) { \
- oob = true; \
- valid = false; \
+ *oob = true; \
+ *valid = false; \
return; \
} \
(*VariantGetInternalPtr<m_base_type>::get_ptr(base)) m_accessor[index] = *VariantGetInternalPtr<m_elem_type>::get_ptr(value); \
- oob = false; \
- valid = true; \
+ *oob = false; \
+ *valid = true; \
} \
- static void validated_set(Variant *base, int64_t index, const Variant *value, bool &oob) { \
+ static void validated_set(Variant *base, int64_t index, const Variant *value, bool *oob) { \
if (index < 0 || index >= m_max) { \
- oob = true; \
+ *oob = true; \
return; \
} \
(*VariantGetInternalPtr<m_base_type>::get_ptr(base)) m_accessor[index] = *VariantGetInternalPtr<m_elem_type>::get_ptr(value); \
- oob = false; \
+ *oob = false; \
} \
static void ptr_set(void *base, int64_t index, const void *member) { \
/* avoid ptrconvert for performance*/ \
@@ -823,14 +823,14 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const {
#define INDEXED_SETGET_STRUCT_BULTIN_FUNC(m_base_type, m_elem_type, m_set, m_get, m_max) \
struct VariantIndexedSetGet_##m_base_type { \
- static void get(const Variant *base, int64_t index, Variant *value, bool &oob) { \
+ static void get(const Variant *base, int64_t index, Variant *value, bool *oob) { \
if (index < 0 || index >= m_max) { \
- oob = true; \
+ *oob = true; \
return; \
} \
VariantTypeAdjust<m_elem_type>::adjust(value); \
*VariantGetInternalPtr<m_elem_type>::get_ptr(value) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_get(index); \
- oob = false; \
+ *oob = false; \
} \
static void ptr_get(const void *base, int64_t index, void *member) { \
/* avoid ptrconvert for performance*/ \
@@ -838,27 +838,27 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const {
OOB_TEST(index, m_max); \
PtrToArg<m_elem_type>::encode(v.m_get(index), member); \
} \
- static void set(Variant *base, int64_t index, const Variant *value, bool &valid, bool &oob) { \
+ static void set(Variant *base, int64_t index, const Variant *value, bool *valid, bool *oob) { \
if (value->get_type() != GetTypeInfo<m_elem_type>::VARIANT_TYPE) { \
- oob = false; \
- valid = false; \
+ *oob = false; \
+ *valid = false; \
} \
if (index < 0 || index >= m_max) { \
- oob = true; \
- valid = false; \
+ *oob = true; \
+ *valid = false; \
return; \
} \
VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_set(index, *VariantGetInternalPtr<m_elem_type>::get_ptr(value)); \
- oob = false; \
- valid = true; \
+ *oob = false; \
+ *valid = true; \
} \
- static void validated_set(Variant *base, int64_t index, const Variant *value, bool &oob) { \
+ static void validated_set(Variant *base, int64_t index, const Variant *value, bool *oob) { \
if (index < 0 || index >= m_max) { \
- oob = true; \
+ *oob = true; \
return; \
} \
VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_set(index, *VariantGetInternalPtr<m_elem_type>::get_ptr(value)); \
- oob = false; \
+ *oob = false; \
} \
static void ptr_set(void *base, int64_t index, const void *member) { \
/* avoid ptrconvert for performance*/ \
@@ -872,17 +872,17 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const {
#define INDEXED_SETGET_STRUCT_VARIANT(m_base_type) \
struct VariantIndexedSetGet_##m_base_type { \
- static void get(const Variant *base, int64_t index, Variant *value, bool &oob) { \
+ static void get(const Variant *base, int64_t index, Variant *value, bool *oob) { \
int64_t size = VariantGetInternalPtr<m_base_type>::get_ptr(base)->size(); \
if (index < 0) { \
index += size; \
} \
if (index < 0 || index >= size) { \
- oob = true; \
+ *oob = true; \
return; \
} \
*value = (*VariantGetInternalPtr<m_base_type>::get_ptr(base))[index]; \
- oob = false; \
+ *oob = false; \
} \
static void ptr_get(const void *base, int64_t index, void *member) { \
/* avoid ptrconvert for performance*/ \
@@ -892,31 +892,31 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const {
OOB_TEST(index, v.size()); \
PtrToArg<Variant>::encode(v[index], member); \
} \
- static void set(Variant *base, int64_t index, const Variant *value, bool &valid, bool &oob) { \
+ static void set(Variant *base, int64_t index, const Variant *value, bool *valid, bool *oob) { \
int64_t size = VariantGetInternalPtr<m_base_type>::get_ptr(base)->size(); \
if (index < 0) { \
index += size; \
} \
if (index < 0 || index >= size) { \
- oob = true; \
- valid = false; \
+ *oob = true; \
+ *valid = false; \
return; \
} \
(*VariantGetInternalPtr<m_base_type>::get_ptr(base))[index] = *value; \
- oob = false; \
- valid = true; \
+ *oob = false; \
+ *valid = true; \
} \
- static void validated_set(Variant *base, int64_t index, const Variant *value, bool &oob) { \
+ static void validated_set(Variant *base, int64_t index, const Variant *value, bool *oob) { \
int64_t size = VariantGetInternalPtr<m_base_type>::get_ptr(base)->size(); \
if (index < 0) { \
index += size; \
} \
if (index < 0 || index >= size) { \
- oob = true; \
+ *oob = true; \
return; \
} \
(*VariantGetInternalPtr<m_base_type>::get_ptr(base))[index] = *value; \
- oob = false; \
+ *oob = false; \
} \
static void ptr_set(void *base, int64_t index, const void *member) { \
/* avoid ptrconvert for performance*/ \
@@ -932,14 +932,14 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const {
#define INDEXED_SETGET_STRUCT_DICT(m_base_type) \
struct VariantIndexedSetGet_##m_base_type { \
- static void get(const Variant *base, int64_t index, Variant *value, bool &oob) { \
+ static void get(const Variant *base, int64_t index, Variant *value, bool *oob) { \
const Variant *ptr = VariantGetInternalPtr<m_base_type>::get_ptr(base)->getptr(index); \
if (!ptr) { \
- oob = true; \
+ *oob = true; \
return; \
} \
*value = *ptr; \
- oob = false; \
+ *oob = false; \
} \
static void ptr_get(const void *base, int64_t index, void *member) { \
/* avoid ptrconvert for performance*/ \
@@ -948,14 +948,14 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const {
NULL_TEST(ptr); \
PtrToArg<Variant>::encode(*ptr, member); \
} \
- static void set(Variant *base, int64_t index, const Variant *value, bool &valid, bool &oob) { \
+ static void set(Variant *base, int64_t index, const Variant *value, bool *valid, bool *oob) { \
(*VariantGetInternalPtr<m_base_type>::get_ptr(base))[index] = *value; \
- oob = false; \
- valid = true; \
+ *oob = false; \
+ *valid = true; \
} \
- static void validated_set(Variant *base, int64_t index, const Variant *value, bool &oob) { \
+ static void validated_set(Variant *base, int64_t index, const Variant *value, bool *oob) { \
(*VariantGetInternalPtr<m_base_type>::get_ptr(base))[index] = *value; \
- oob = false; \
+ *oob = false; \
} \
static void ptr_set(void *base, int64_t index, const void *member) { \
m_base_type &v = *reinterpret_cast<m_base_type *>(base); \
@@ -989,8 +989,8 @@ INDEXED_SETGET_STRUCT_VARIANT(Array)
INDEXED_SETGET_STRUCT_DICT(Dictionary)
struct VariantIndexedSetterGetterInfo {
- void (*setter)(Variant *base, int64_t index, const Variant *value, bool &valid, bool &oob);
- void (*getter)(const Variant *base, int64_t index, Variant *value, bool &oob);
+ void (*setter)(Variant *base, int64_t index, const Variant *value, bool *valid, bool *oob);
+ void (*getter)(const Variant *base, int64_t index, Variant *value, bool *oob);
Variant::ValidatedIndexedSetter validated_setter;
Variant::ValidatedIndexedGetter validated_getter;
@@ -1083,7 +1083,7 @@ Variant::PTRIndexedGetter Variant::get_member_ptr_indexed_getter(Variant::Type p
void Variant::set_indexed(int64_t p_index, const Variant &p_value, bool &r_valid, bool &r_oob) {
if (likely(variant_indexed_setters_getters[type].valid)) {
- variant_indexed_setters_getters[type].setter(this, p_index, &p_value, r_valid, r_oob);
+ variant_indexed_setters_getters[type].setter(this, p_index, &p_value, &r_valid, &r_oob);
} else {
r_valid = false;
r_oob = false;
@@ -1092,7 +1092,7 @@ void Variant::set_indexed(int64_t p_index, const Variant &p_value, bool &r_valid
Variant Variant::get_indexed(int64_t p_index, bool &r_valid, bool &r_oob) const {
if (likely(variant_indexed_setters_getters[type].valid)) {
Variant ret;
- variant_indexed_setters_getters[type].getter(this, p_index, &ret, r_oob);
+ variant_indexed_setters_getters[type].getter(this, p_index, &ret, &r_oob);
r_valid = !r_oob;
return ret;
} else {
@@ -1111,14 +1111,14 @@ uint64_t Variant::get_indexed_size() const {
}
struct VariantKeyedSetGetDictionary {
- static void get(const Variant *base, const Variant *key, Variant *value, bool &r_valid) {
+ static void get(const Variant *base, const Variant *key, Variant *value, bool *r_valid) {
const Variant *ptr = VariantGetInternalPtr<Dictionary>::get_ptr(base)->getptr(*key);
if (!ptr) {
- r_valid = false;
+ *r_valid = false;
return;
}
*value = *ptr;
- r_valid = true;
+ *r_valid = true;
}
static void ptr_get(const void *base, const void *key, void *value) {
/* avoid ptrconvert for performance*/
@@ -1127,17 +1127,17 @@ struct VariantKeyedSetGetDictionary {
NULL_TEST(ptr);
PtrToArg<Variant>::encode(*ptr, value);
}
- static void set(Variant *base, const Variant *key, const Variant *value, bool &r_valid) {
+ static void set(Variant *base, const Variant *key, const Variant *value, bool *r_valid) {
(*VariantGetInternalPtr<Dictionary>::get_ptr(base))[*key] = *value;
- r_valid = true;
+ *r_valid = true;
}
static void ptr_set(void *base, const void *key, const void *value) {
Dictionary &v = *reinterpret_cast<Dictionary *>(base);
v[PtrToArg<Variant>::convert(key)] = PtrToArg<Variant>::convert(value);
}
- static bool has(const Variant *base, const Variant *key, bool &r_valid) {
- r_valid = true;
+ static bool has(const Variant *base, const Variant *key, bool *r_valid) {
+ *r_valid = true;
return VariantGetInternalPtr<Dictionary>::get_ptr(base)->has(*key);
}
static bool ptr_has(const void *base, const void *key) {
@@ -1148,15 +1148,15 @@ struct VariantKeyedSetGetDictionary {
};
struct VariantKeyedSetGetObject {
- static void get(const Variant *base, const Variant *key, Variant *value, bool &r_valid) {
+ static void get(const Variant *base, const Variant *key, Variant *value, bool *r_valid) {
Object *obj = base->get_validated_object();
if (!obj) {
- r_valid = false;
+ *r_valid = false;
*value = Variant();
return;
}
- *value = obj->getvar(*key, &r_valid);
+ *value = obj->getvar(*key, r_valid);
}
static void ptr_get(const void *base, const void *key, void *value) {
const Object *obj = PtrToArg<Object *>::convert(base);
@@ -1164,14 +1164,14 @@ struct VariantKeyedSetGetObject {
Variant v = obj->getvar(PtrToArg<Variant>::convert(key));
PtrToArg<Variant>::encode(v, value);
}
- static void set(Variant *base, const Variant *key, const Variant *value, bool &r_valid) {
+ static void set(Variant *base, const Variant *key, const Variant *value, bool *r_valid) {
Object *obj = base->get_validated_object();
if (!obj) {
- r_valid = false;
+ *r_valid = false;
return;
}
- obj->setvar(*key, *value, &r_valid);
+ obj->setvar(*key, *value, r_valid);
}
static void ptr_set(void *base, const void *key, const void *value) {
Object *obj = PtrToArg<Object *>::convert(base);
@@ -1179,13 +1179,13 @@ struct VariantKeyedSetGetObject {
obj->setvar(PtrToArg<Variant>::convert(key), PtrToArg<Variant>::convert(value));
}
- static bool has(const Variant *base, const Variant *key, bool &r_valid) {
+ static bool has(const Variant *base, const Variant *key, bool *r_valid) {
Object *obj = base->get_validated_object();
- if (obj != nullptr) {
- r_valid = false;
+ if (!obj) {
+ *r_valid = false;
return false;
}
- r_valid = true;
+ *r_valid = true;
bool exists;
obj->getvar(*key, &exists);
return exists;
@@ -1199,14 +1199,6 @@ struct VariantKeyedSetGetObject {
}
};
-/*typedef void (*ValidatedKeyedSetter)(Variant *base, const Variant *key, const Variant *value);
-typedef void (*ValidatedKeyedGetter)(const Variant *base, const Variant *key, Variant *value, bool &valid);
-typedef bool (*ValidatedKeyedChecker)(const Variant *base, const Variant *key);
-
-typedef void (*PTRKeyedSetter)(void *base, const void *key, const void *value);
-typedef void (*PTRKeyedGetter)(const void *base, const void *key, void *value);
-typedef bool (*PTRKeyedChecker)(const void *base, const void *key);*/
-
struct VariantKeyedSetterGetterInfo {
Variant::ValidatedKeyedSetter validated_setter;
Variant::ValidatedKeyedGetter validated_getter;
@@ -1274,7 +1266,7 @@ Variant::PTRKeyedChecker Variant::get_member_ptr_keyed_checker(Variant::Type p_t
void Variant::set_keyed(const Variant &p_key, const Variant &p_value, bool &r_valid) {
if (likely(variant_keyed_setters_getters[type].valid)) {
- variant_keyed_setters_getters[type].validated_setter(this, &p_key, &p_value, r_valid);
+ variant_keyed_setters_getters[type].validated_setter(this, &p_key, &p_value, &r_valid);
} else {
r_valid = false;
}
@@ -1282,7 +1274,7 @@ void Variant::set_keyed(const Variant &p_key, const Variant &p_value, bool &r_va
Variant Variant::get_keyed(const Variant &p_key, bool &r_valid) const {
if (likely(variant_keyed_setters_getters[type].valid)) {
Variant ret;
- variant_keyed_setters_getters[type].validated_getter(this, &p_key, &ret, r_valid);
+ variant_keyed_setters_getters[type].validated_getter(this, &p_key, &ret, &r_valid);
return ret;
} else {
r_valid = false;
@@ -1291,7 +1283,7 @@ Variant Variant::get_keyed(const Variant &p_key, bool &r_valid) const {
}
bool Variant::has_key(const Variant &p_key, bool &r_valid) const {
if (likely(variant_keyed_setters_getters[type].valid)) {
- return variant_keyed_setters_getters[type].validated_checker(this, &p_key, r_valid);
+ return variant_keyed_setters_getters[type].validated_checker(this, &p_key, &r_valid);
} else {
r_valid = false;
return false;