summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/core_constants.cpp1
-rw-r--r--core/io/multiplayer_api.cpp6
-rw-r--r--core/io/multiplayer_api.h1
-rw-r--r--core/math/math_defs.h3
-rw-r--r--core/object/class_db.cpp1
-rw-r--r--core/os/main_loop.cpp1
-rw-r--r--core/os/main_loop.h1
-rw-r--r--core/string/translation.cpp21
-rw-r--r--core/string/translation.h2
-rw-r--r--core/string/ustring.cpp5
-rw-r--r--core/string/ustring.h7
-rw-r--r--core/templates/hashfuncs.h18
-rw-r--r--core/templates/lru.h126
-rw-r--r--core/typedefs.h2
-rw-r--r--core/variant/variant_call.cpp4
15 files changed, 189 insertions, 10 deletions
diff --git a/core/core_constants.cpp b/core/core_constants.cpp
index 57ea10c074..db22a9ecf6 100644
--- a/core/core_constants.cpp
+++ b/core/core_constants.cpp
@@ -128,6 +128,7 @@ void register_global_constants() {
BIND_CORE_ENUM_CONSTANT(HALIGN_LEFT);
BIND_CORE_ENUM_CONSTANT(HALIGN_CENTER);
BIND_CORE_ENUM_CONSTANT(HALIGN_RIGHT);
+ BIND_CORE_ENUM_CONSTANT(HALIGN_FILL);
BIND_CORE_ENUM_CONSTANT(VALIGN_TOP);
BIND_CORE_ENUM_CONSTANT(VALIGN_CENTER);
diff --git a/core/io/multiplayer_api.cpp b/core/io/multiplayer_api.cpp
index 2f17d9e746..afab00ebd6 100644
--- a/core/io/multiplayer_api.cpp
+++ b/core/io/multiplayer_api.cpp
@@ -142,6 +142,10 @@ void MultiplayerAPI::set_root_node(Node *p_node) {
root_node = p_node;
}
+Node *MultiplayerAPI::get_root_node() {
+ return root_node;
+}
+
void MultiplayerAPI::set_network_peer(const Ref<NetworkedMultiplayerPeer> &p_peer) {
if (p_peer == network_peer) {
return; // Nothing to do
@@ -1202,6 +1206,7 @@ bool MultiplayerAPI::is_object_decoding_allowed() const {
void MultiplayerAPI::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_root_node", "node"), &MultiplayerAPI::set_root_node);
+ ClassDB::bind_method(D_METHOD("get_root_node"), &MultiplayerAPI::get_root_node);
ClassDB::bind_method(D_METHOD("send_bytes", "bytes", "id", "mode"), &MultiplayerAPI::send_bytes, DEFVAL(NetworkedMultiplayerPeer::TARGET_PEER_BROADCAST), DEFVAL(NetworkedMultiplayerPeer::TRANSFER_MODE_RELIABLE));
ClassDB::bind_method(D_METHOD("has_network_peer"), &MultiplayerAPI::has_network_peer);
ClassDB::bind_method(D_METHOD("get_network_peer"), &MultiplayerAPI::get_network_peer);
@@ -1221,6 +1226,7 @@ void MultiplayerAPI::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "allow_object_decoding"), "set_allow_object_decoding", "is_object_decoding_allowed");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "refuse_new_network_connections"), "set_refuse_new_network_connections", "is_refusing_new_network_connections");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "network_peer", PROPERTY_HINT_RESOURCE_TYPE, "NetworkedMultiplayerPeer", 0), "set_network_peer", "get_network_peer");
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "root_node", PROPERTY_HINT_RESOURCE_TYPE, "Node", 0), "set_root_node", "get_root_node");
ADD_PROPERTY_DEFAULT("refuse_new_network_connections", false);
ADD_SIGNAL(MethodInfo("network_peer_connected", PropertyInfo(Variant::INT, "id")));
diff --git a/core/io/multiplayer_api.h b/core/io/multiplayer_api.h
index 5b30c2e680..ca52a1c689 100644
--- a/core/io/multiplayer_api.h
+++ b/core/io/multiplayer_api.h
@@ -114,6 +114,7 @@ public:
void poll();
void clear();
void set_root_node(Node *p_node);
+ Node *get_root_node();
void set_network_peer(const Ref<NetworkedMultiplayerPeer> &p_peer);
Ref<NetworkedMultiplayerPeer> get_network_peer() const;
Error send_bytes(Vector<uint8_t> p_data, int p_to = NetworkedMultiplayerPeer::TARGET_PEER_BROADCAST, NetworkedMultiplayerPeer::TransferMode p_mode = NetworkedMultiplayerPeer::TRANSFER_MODE_RELIABLE);
diff --git a/core/math/math_defs.h b/core/math/math_defs.h
index 5192722839..4d97f72ebf 100644
--- a/core/math/math_defs.h
+++ b/core/math/math_defs.h
@@ -73,7 +73,8 @@ enum Orientation {
enum HAlign {
HALIGN_LEFT,
HALIGN_CENTER,
- HALIGN_RIGHT
+ HALIGN_RIGHT,
+ HALIGN_FILL,
};
enum VAlign {
diff --git a/core/object/class_db.cpp b/core/object/class_db.cpp
index 64ebeb427e..dc28fa10de 100644
--- a/core/object/class_db.cpp
+++ b/core/object/class_db.cpp
@@ -978,6 +978,7 @@ void ClassDB::add_property_subgroup(StringName p_class, const String &p_name, co
type->property_list.push_back(PropertyInfo(Variant::NIL, p_name, PROPERTY_HINT_NONE, p_prefix, PROPERTY_USAGE_SUBGROUP));
}
+// NOTE: For implementation simplicity reasons, this method doesn't allow setters to have optional arguments at the end.
void ClassDB::add_property(StringName p_class, const PropertyInfo &p_pinfo, const StringName &p_setter, const StringName &p_getter, int p_index) {
lock->read_lock();
ClassInfo *type = classes.getptr(p_class);
diff --git a/core/os/main_loop.cpp b/core/os/main_loop.cpp
index d29bcd011f..9252ba0840 100644
--- a/core/os/main_loop.cpp
+++ b/core/os/main_loop.cpp
@@ -47,6 +47,7 @@ void MainLoop::_bind_methods() {
BIND_CONSTANT(NOTIFICATION_APPLICATION_PAUSED);
BIND_CONSTANT(NOTIFICATION_APPLICATION_FOCUS_IN);
BIND_CONSTANT(NOTIFICATION_APPLICATION_FOCUS_OUT);
+ BIND_CONSTANT(NOTIFICATION_TEXT_SERVER_CHANGED);
ADD_SIGNAL(MethodInfo("on_request_permissions_result", PropertyInfo(Variant::STRING, "permission"), PropertyInfo(Variant::BOOL, "granted")));
};
diff --git a/core/os/main_loop.h b/core/os/main_loop.h
index 8c46ad9b6a..7bc91fbb83 100644
--- a/core/os/main_loop.h
+++ b/core/os/main_loop.h
@@ -56,6 +56,7 @@ public:
NOTIFICATION_APPLICATION_PAUSED = 2015,
NOTIFICATION_APPLICATION_FOCUS_IN = 2016,
NOTIFICATION_APPLICATION_FOCUS_OUT = 2017,
+ NOTIFICATION_TEXT_SERVER_CHANGED = 2018,
};
virtual void init();
diff --git a/core/string/translation.cpp b/core/string/translation.cpp
index df8a26e5ce..7b8c28e2e2 100644
--- a/core/string/translation.cpp
+++ b/core/string/translation.cpp
@@ -34,6 +34,11 @@
#include "core/io/resource_loader.h"
#include "core/os/os.h"
+#ifdef TOOLS_ENABLED
+#include "editor/editor_settings.h"
+#include "main/main.h"
+#endif
+
// ISO 639-1 language codes, with the addition of glibc locales with their
// regional identifiers. This list must match the language names (in English)
// of locale_names.
@@ -1214,6 +1219,22 @@ void TranslationServer::set_tool_translation(const Ref<Translation> &p_translati
tool_translation = p_translation;
}
+Ref<Translation> TranslationServer::get_tool_translation() const {
+ return tool_translation;
+}
+
+String TranslationServer::get_tool_locale() {
+#ifdef TOOLS_ENABLED
+ if (TranslationServer::get_singleton()->get_tool_translation().is_valid() && (Engine::get_singleton()->is_editor_hint() || Main::is_project_manager())) {
+ return tool_translation->get_locale();
+ } else {
+#else
+ {
+#endif
+ return get_locale();
+ }
+}
+
StringName TranslationServer::tool_translate(const StringName &p_message, const StringName &p_context) const {
if (tool_translation.is_valid()) {
StringName r = tool_translation->get_message(p_message, p_context);
diff --git a/core/string/translation.h b/core/string/translation.h
index 8d34f7997e..c7ffe4d065 100644
--- a/core/string/translation.h
+++ b/core/string/translation.h
@@ -110,7 +110,9 @@ public:
static String standardize_locale(const String &p_locale);
static String get_language_code(const String &p_locale);
+ String get_tool_locale();
void set_tool_translation(const Ref<Translation> &p_translation);
+ Ref<Translation> get_tool_translation() const;
StringName tool_translate(const StringName &p_message, const StringName &p_context = "") const;
StringName tool_translate_plural(const StringName &p_message, const StringName &p_message_plural, int p_n, const StringName &p_context = "") const;
void set_doc_translation(const Ref<Translation> &p_translation);
diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp
index 213578485e..d630e987ea 100644
--- a/core/string/ustring.cpp
+++ b/core/string/ustring.cpp
@@ -209,7 +209,6 @@ void CharString::copy_from(const char *p_cstr) {
/* String */
/*************************************************************************/
-//TODO: move to TextServer
//kind of poor should be rewritten properly
String String::word_wrap(int p_chars_per_line) const {
int from = 0;
@@ -4796,7 +4795,7 @@ Vector<uint8_t> String::to_utf16_buffer() const {
Char16String charstr = s->utf16();
Vector<uint8_t> retval;
- size_t len = charstr.length() * 2;
+ size_t len = charstr.length() * sizeof(char16_t);
retval.resize(len);
uint8_t *w = retval.ptrw();
copymem(w, (const void *)charstr.ptr(), len);
@@ -4811,7 +4810,7 @@ Vector<uint8_t> String::to_utf32_buffer() const {
}
Vector<uint8_t> retval;
- size_t len = s->length() * 4;
+ size_t len = s->length() * sizeof(char32_t);
retval.resize(len);
uint8_t *w = retval.ptrw();
copymem(w, (const void *)s->ptr(), len);
diff --git a/core/string/ustring.h b/core/string/ustring.h
index bfae16fe64..7ff78b2d86 100644
--- a/core/string/ustring.h
+++ b/core/string/ustring.h
@@ -28,8 +28,9 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#ifndef USTRING_H
-#define USTRING_H
+#ifndef USTRING_GODOT_H
+#define USTRING_GODOT_H
+// Note: Renamed to avoid conflict with ICU header with the same name.
#include "core/templates/cowdata.h"
#include "core/templates/vector.h"
@@ -555,4 +556,4 @@ _FORCE_INLINE_ Vector<String> sarray(P... p_args) {
return arr;
}
-#endif // USTRING_H
+#endif // USTRING_GODOT_H
diff --git a/core/templates/hashfuncs.h b/core/templates/hashfuncs.h
index 86bb1b5228..1ed9ab1987 100644
--- a/core/templates/hashfuncs.h
+++ b/core/templates/hashfuncs.h
@@ -114,6 +114,24 @@ static inline uint32_t make_uint32_t(T p_in) {
return _u._u32;
}
+static inline uint64_t hash_djb2_one_float_64(double p_in, uint64_t p_prev = 5381) {
+ union {
+ double d;
+ uint64_t i;
+ } u;
+
+ // Normalize +/- 0.0 and NaN values so they hash the same.
+ if (p_in == 0.0f) {
+ u.d = 0.0;
+ } else if (Math::is_nan(p_in)) {
+ u.d = Math_NAN;
+ } else {
+ u.d = p_in;
+ }
+
+ return ((p_prev << 5) + p_prev) + u.i;
+}
+
static inline uint64_t hash_djb2_one_64(uint64_t p_in, uint64_t p_prev = 5381) {
return ((p_prev << 5) + p_prev) + p_in;
}
diff --git a/core/templates/lru.h b/core/templates/lru.h
new file mode 100644
index 0000000000..d02c4337d1
--- /dev/null
+++ b/core/templates/lru.h
@@ -0,0 +1,126 @@
+/*************************************************************************/
+/* lru.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 LRU_H
+#define LRU_H
+
+#include "core/math/math_funcs.h"
+#include "hash_map.h"
+#include "list.h"
+
+template <class TKey, class TData>
+class LRUCache {
+private:
+ struct Pair {
+ TKey key;
+ TData data;
+
+ Pair() {}
+ Pair(const TKey &p_key, const TData &p_data) :
+ key(p_key),
+ data(p_data) {
+ }
+ };
+
+ typedef typename List<Pair>::Element *Element;
+
+ List<Pair> _list;
+ HashMap<TKey, Element> _map;
+ size_t capacity;
+
+public:
+ const TData *insert(const TKey &p_key, const TData &p_value) {
+ Element *e = _map.getptr(p_key);
+ Element n = _list.push_front(Pair(p_key, p_value));
+
+ if (e) {
+ _list.erase(*e);
+ _map.erase(p_key);
+ }
+ _map[p_key] = _list.front();
+
+ while (_map.size() > capacity) {
+ Element d = _list.back();
+ _map.erase(d->get().key);
+ _list.pop_back();
+ }
+
+ return &n->get().data;
+ }
+
+ void clear() {
+ _map.clear();
+ _list.clear();
+ }
+
+ bool has(const TKey &p_key) const {
+ return _map.getptr(p_key);
+ }
+
+ const TData &get(const TKey &p_key) {
+ Element *e = _map.getptr(p_key);
+ CRASH_COND(!e);
+ _list.move_to_front(*e);
+ return (*e)->get().data;
+ };
+
+ const TData *getptr(const TKey &p_key) {
+ Element *e = _map.getptr(p_key);
+ if (!e) {
+ return nullptr;
+ } else {
+ _list.move_to_front(*e);
+ return &(*e)->get().data;
+ }
+ }
+
+ _FORCE_INLINE_ size_t get_capacity() const { return capacity; }
+
+ void set_capacity(size_t p_capacity) {
+ if (capacity > 0) {
+ capacity = p_capacity;
+ while (_map.size() > capacity) {
+ Element d = _list.back();
+ _map.erase(d->get().key);
+ _list.pop_back();
+ }
+ }
+ }
+
+ LRUCache() {
+ capacity = 64;
+ }
+
+ LRUCache(int p_capacity) {
+ capacity = p_capacity;
+ }
+};
+
+#endif
diff --git a/core/typedefs.h b/core/typedefs.h
index d7ee5ee40e..7c98bc37f7 100644
--- a/core/typedefs.h
+++ b/core/typedefs.h
@@ -92,7 +92,7 @@
#endif
#ifndef SGN
-#define SGN(m_v) (((m_v) < 0) ? (-1.0) : (+1.0))
+#define SGN(m_v) (((m_v) == 0) ? (0.0) : (((m_v) < 0) ? (-1.0) : (+1.0)))
#endif
#ifndef MIN
diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp
index 13514b7b9f..214c424013 100644
--- a/core/variant/variant_call.cpp
+++ b/core/variant/variant_call.cpp
@@ -418,7 +418,7 @@ struct _VariantCall {
String s;
if (p_instance->size() > 0) {
const uint8_t *r = p_instance->ptr();
- s.parse_utf16((const char16_t *)r, p_instance->size() / 2);
+ s.parse_utf16((const char16_t *)r, floor((double)p_instance->size() / (double)sizeof(char16_t)));
}
return s;
}
@@ -427,7 +427,7 @@ struct _VariantCall {
String s;
if (p_instance->size() > 0) {
const uint8_t *r = p_instance->ptr();
- s = String((const char32_t *)r, p_instance->size() / 4);
+ s = String((const char32_t *)r, floor((double)p_instance->size() / (double)sizeof(char32_t)));
}
return s;
}