summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/SCsub10
-rw-r--r--core/array.cpp22
-rw-r--r--core/array.h3
-rw-r--r--core/bind/core_bind.cpp55
-rw-r--r--core/bind/core_bind.h13
-rw-r--r--core/class_db.cpp68
-rw-r--r--core/class_db.h6
-rw-r--r--core/color.cpp53
-rw-r--r--core/color.h1
-rw-r--r--core/command_queue_mt.cpp1
-rw-r--r--core/command_queue_mt.h6
-rw-r--r--core/compressed_translation.h2
-rw-r--r--core/dictionary.cpp4
-rw-r--r--core/dictionary.h2
-rw-r--r--core/error_macros.h2
-rw-r--r--core/global_constants.cpp2
-rw-r--r--core/image.cpp108
-rw-r--r--core/image.h1
-rw-r--r--core/input_map.cpp20
-rw-r--r--core/input_map.h5
-rw-r--r--core/io/file_access_network.cpp2
-rw-r--r--core/io/file_access_pack.cpp6
-rw-r--r--core/io/http_client.cpp24
-rw-r--r--core/io/ip_address.cpp2
-rw-r--r--core/io/marshalls.cpp2
-rw-r--r--core/io/multiplayer_api.cpp722
-rw-r--r--core/io/multiplayer_api.h87
-rw-r--r--core/io/resource_format_binary.cpp10
-rw-r--r--core/io/stream_peer.cpp2
-rw-r--r--core/io/stream_peer.h2
-rw-r--r--core/io/stream_peer_ssl.cpp32
-rw-r--r--core/io/stream_peer_ssl.h2
-rw-r--r--core/make_binders.py12
-rw-r--r--core/map.h4
-rw-r--r--core/math/math_2d.cpp5
-rw-r--r--core/math/math_2d.h3
-rw-r--r--core/math/math_funcs.cpp15
-rw-r--r--core/math/math_funcs.h14
-rw-r--r--core/math/triangulate.cpp42
-rw-r--r--core/math/triangulate.h5
-rw-r--r--core/message_queue.cpp2
-rw-r--r--core/os/dir_access.cpp7
-rw-r--r--core/os/file_access.h3
-rw-r--r--core/os/input.cpp2
-rw-r--r--core/os/input_event.cpp10
-rw-r--r--core/os/input_event.h2
-rw-r--r--core/os/keyboard.cpp121
-rw-r--r--core/os/keyboard.h1
-rw-r--r--core/os/os.cpp40
-rw-r--r--core/os/os.h26
-rw-r--r--core/os/thread_dummy.cpp8
-rw-r--r--core/os/thread_dummy.h17
-rw-r--r--core/pool_allocator.cpp4
-rw-r--r--core/project_settings.cpp103
-rw-r--r--core/project_settings.h3
-rw-r--r--core/reference.h5
-rw-r--r--core/register_core_types.cpp2
-rw-r--r--core/resource.cpp2
-rw-r--r--core/script_debugger_remote.cpp4
-rw-r--r--core/script_language.h5
-rw-r--r--core/set.h4
-rw-r--r--core/string_buffer.h6
-rw-r--r--core/string_builder.h6
-rw-r--r--core/translation.cpp19
-rw-r--r--core/ustring.cpp104
-rw-r--r--core/ustring.h8
-rw-r--r--core/variant.cpp2
-rw-r--r--core/variant.h3
-rw-r--r--core/variant_call.cpp16
-rw-r--r--core/variant_op.cpp25
-rw-r--r--core/version.h29
71 files changed, 1542 insertions, 424 deletions
diff --git a/core/SCsub b/core/SCsub
index 1545bc8aeb..383aaf0e12 100644
--- a/core/SCsub
+++ b/core/SCsub
@@ -18,9 +18,8 @@ gd_cpp = '#include "project_settings.h"\n'
gd_cpp += gd_inc
gd_cpp += "void ProjectSettings::register_global_defaults() {\n" + gd_call + "\n}\n"
-f = open("global_defaults.gen.cpp", "w")
-f.write(gd_cpp)
-f.close()
+with open("global_defaults.gen.cpp", "w") as f:
+ f.write(gd_cpp)
# Generate AES256 script encryption key
@@ -47,9 +46,8 @@ if ("SCRIPT_AES256_ENCRYPTION_KEY" in os.environ):
txt = "0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0"
print("Invalid AES256 encryption key, not 64 bits hex: " + e)
-f = open("script_encryption_key.gen.cpp", "w")
-f.write("#include \"project_settings.h\"\nuint8_t script_encryption_key[32]={" + txt + "};\n")
-f.close()
+with open("script_encryption_key.gen.cpp", "w") as f:
+ f.write("#include \"project_settings.h\"\nuint8_t script_encryption_key[32]={" + txt + "};\n")
# Add required thirdparty code. Header paths are hardcoded, we don't need to append
diff --git a/core/array.cpp b/core/array.cpp
index c53fea1f28..9e3250fd47 100644
--- a/core/array.cpp
+++ b/core/array.cpp
@@ -35,8 +35,8 @@
#include "variant.h"
#include "vector.h"
-struct ArrayPrivate {
-
+class ArrayPrivate {
+public:
SafeRefCount refcount;
Vector<Variant> array;
};
@@ -211,13 +211,13 @@ const Variant &Array::get(int p_idx) const {
return operator[](p_idx);
}
-Array Array::duplicate() const {
+Array Array::duplicate(bool p_deep) const {
Array new_arr;
int element_count = size();
new_arr.resize(element_count);
for (int i = 0; i < element_count; i++) {
- new_arr[i] = get(i);
+ new_arr[i] = p_deep ? get(i).duplicate(p_deep) : get(i);
}
return new_arr;
@@ -266,6 +266,20 @@ Array &Array::sort_custom(Object *p_obj, const StringName &p_function) {
return *this;
}
+void Array::shuffle() {
+
+ const int n = _p->array.size();
+ if (n < 2)
+ return;
+ Variant *data = _p->array.ptrw();
+ for (int i = n - 1; i >= 1; i--) {
+ const int j = Math::rand() % (i + 1);
+ const Variant tmp = data[j];
+ data[j] = data[i];
+ data[i] = tmp;
+ }
+}
+
template <typename Less>
_FORCE_INLINE_ int bisect(const Vector<Variant> &p_array, const Variant &p_value, bool p_before, const Less &p_less) {
diff --git a/core/array.h b/core/array.h
index 7c6fc59048..e549a886e6 100644
--- a/core/array.h
+++ b/core/array.h
@@ -71,6 +71,7 @@ public:
Array &sort();
Array &sort_custom(Object *p_obj, const StringName &p_function);
+ void shuffle();
int bsearch(const Variant &p_value, bool p_before = true);
int bsearch_custom(const Variant &p_value, Object *p_obj, const StringName &p_function, bool p_before = true);
Array &invert();
@@ -87,7 +88,7 @@ public:
Variant pop_back();
Variant pop_front();
- Array duplicate() const;
+ Array duplicate(bool p_deep = false) const;
Array(const Array &p_from);
Array();
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp
index 32b94b9b02..20adf7ff02 100644
--- a/core/bind/core_bind.cpp
+++ b/core/bind/core_bind.cpp
@@ -205,6 +205,22 @@ String _OS::get_clipboard() const {
return OS::get_singleton()->get_clipboard();
}
+int _OS::get_video_driver_count() const {
+ return OS::get_singleton()->get_video_driver_count();
+}
+
+String _OS::get_video_driver_name(int p_driver) const {
+ return OS::get_singleton()->get_video_driver_name(p_driver);
+}
+
+int _OS::get_audio_driver_count() const {
+ return OS::get_singleton()->get_audio_driver_count();
+}
+
+String _OS::get_audio_driver_name(int p_driver) const {
+ return OS::get_singleton()->get_audio_driver_name(p_driver);
+}
+
void _OS::set_video_mode(const Size2 &p_size, bool p_fullscreen, bool p_resizeable, int p_screen) {
OS::VideoMode vm;
@@ -264,6 +280,10 @@ Size2 _OS::get_window_size() const {
return OS::get_singleton()->get_window_size();
}
+Size2 _OS::get_real_window_size() const {
+ return OS::get_singleton()->get_real_window_size();
+}
+
void _OS::set_window_size(const Size2 &p_size) {
OS::get_singleton()->set_window_size(p_size);
}
@@ -300,6 +320,14 @@ bool _OS::is_window_maximized() const {
return OS::get_singleton()->is_window_maximized();
}
+void _OS::set_window_always_on_top(bool p_enabled) {
+ OS::get_singleton()->set_window_always_on_top(p_enabled);
+}
+
+bool _OS::is_window_always_on_top() const {
+ return OS::get_singleton()->is_window_always_on_top();
+}
+
void _OS::set_borderless_window(bool p_borderless) {
OS::get_singleton()->set_borderless_window(p_borderless);
}
@@ -929,6 +957,11 @@ void _OS::request_attention() {
OS::get_singleton()->request_attention();
}
+void _OS::center_window() {
+
+ OS::get_singleton()->center_window();
+}
+
bool _OS::is_debug_build() const {
#ifdef DEBUG_ENABLED
@@ -998,6 +1031,11 @@ void _OS::_bind_methods() {
//ClassDB::bind_method(D_METHOD("is_video_mode_resizable","screen"),&_OS::is_video_mode_resizable,DEFVAL(0));
//ClassDB::bind_method(D_METHOD("get_fullscreen_mode_list","screen"),&_OS::get_fullscreen_mode_list,DEFVAL(0));
+ ClassDB::bind_method(D_METHOD("get_video_driver_count"), &_OS::get_video_driver_count);
+ ClassDB::bind_method(D_METHOD("get_video_driver_name"), &_OS::get_video_driver_name);
+ ClassDB::bind_method(D_METHOD("get_audio_driver_count"), &_OS::get_audio_driver_count);
+ ClassDB::bind_method(D_METHOD("get_audio_driver_name"), &_OS::get_audio_driver_name);
+
ClassDB::bind_method(D_METHOD("get_screen_count"), &_OS::get_screen_count);
ClassDB::bind_method(D_METHOD("get_current_screen"), &_OS::get_current_screen);
ClassDB::bind_method(D_METHOD("set_current_screen", "screen"), &_OS::set_current_screen);
@@ -1016,7 +1054,11 @@ void _OS::_bind_methods() {
ClassDB::bind_method(D_METHOD("is_window_minimized"), &_OS::is_window_minimized);
ClassDB::bind_method(D_METHOD("set_window_maximized", "enabled"), &_OS::set_window_maximized);
ClassDB::bind_method(D_METHOD("is_window_maximized"), &_OS::is_window_maximized);
+ ClassDB::bind_method(D_METHOD("set_window_always_on_top", "enabled"), &_OS::set_window_always_on_top);
+ ClassDB::bind_method(D_METHOD("is_window_always_on_top"), &_OS::is_window_always_on_top);
ClassDB::bind_method(D_METHOD("request_attention"), &_OS::request_attention);
+ ClassDB::bind_method(D_METHOD("get_real_window_size"), &_OS::get_real_window_size);
+ ClassDB::bind_method(D_METHOD("center_window"), &_OS::center_window);
ClassDB::bind_method(D_METHOD("set_borderless_window", "borderless"), &_OS::set_borderless_window);
ClassDB::bind_method(D_METHOD("get_borderless_window"), &_OS::get_borderless_window);
@@ -1493,6 +1535,17 @@ bool _File::is_open() const {
return f != NULL;
}
+String _File::get_path() const {
+
+ ERR_FAIL_COND_V(!f, "");
+ return f->get_path();
+}
+
+String _File::get_path_absolute() const {
+
+ ERR_FAIL_COND_V(!f, "");
+ return f->get_path_absolute();
+}
void _File::seek(int64_t p_position) {
@@ -1782,6 +1835,8 @@ void _File::_bind_methods() {
ClassDB::bind_method(D_METHOD("open", "path", "flags"), &_File::open);
ClassDB::bind_method(D_METHOD("close"), &_File::close);
+ ClassDB::bind_method(D_METHOD("get_path"), &_File::get_path);
+ ClassDB::bind_method(D_METHOD("get_path_absolute"), &_File::get_path_absolute);
ClassDB::bind_method(D_METHOD("is_open"), &_File::is_open);
ClassDB::bind_method(D_METHOD("seek", "position"), &_File::seek);
ClassDB::bind_method(D_METHOD("seek_end", "position"), &_File::seek_end, DEFVAL(0));
diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h
index 2353b6d09f..c40abd51f6 100644
--- a/core/bind/core_bind.h
+++ b/core/bind/core_bind.h
@@ -146,6 +146,12 @@ public:
bool is_video_mode_resizable(int p_screen = 0) const;
Array get_fullscreen_mode_list(int p_screen = 0) const;
+ virtual int get_video_driver_count() const;
+ virtual String get_video_driver_name(int p_driver) const;
+
+ virtual int get_audio_driver_count() const;
+ virtual String get_audio_driver_name(int p_driver) const;
+
virtual int get_screen_count() const;
virtual int get_current_screen() const;
virtual void set_current_screen(int p_screen);
@@ -155,6 +161,7 @@ public:
virtual Point2 get_window_position() const;
virtual void set_window_position(const Point2 &p_position);
virtual Size2 get_window_size() const;
+ virtual Size2 get_real_window_size() const;
virtual void set_window_size(const Size2 &p_size);
virtual void set_window_fullscreen(bool p_enabled);
virtual bool is_window_fullscreen() const;
@@ -164,7 +171,10 @@ public:
virtual bool is_window_minimized() const;
virtual void set_window_maximized(bool p_enabled);
virtual bool is_window_maximized() const;
+ virtual void set_window_always_on_top(bool p_enabled);
+ virtual bool is_window_always_on_top() const;
virtual void request_attention();
+ virtual void center_window();
virtual void set_borderless_window(bool p_borderless);
virtual bool get_borderless_window() const;
@@ -405,6 +415,9 @@ public:
void close(); ///< close a file
bool is_open() const; ///< true when file is open
+ String get_path() const; /// returns the path for the current open file
+ String get_path_absolute() const; /// returns the absolute path for the current open file
+
void seek(int64_t p_position); ///< seek to a given position
void seek_end(int64_t p_position = 0); ///< seek from the end of file
int64_t get_position() const; ///< get position in the file
diff --git a/core/class_db.cpp b/core/class_db.cpp
index d2cd362792..92aa131e2d 100644
--- a/core/class_db.cpp
+++ b/core/class_db.cpp
@@ -33,18 +33,9 @@
#include "os/mutex.h"
#include "version.h"
-#ifdef NO_THREADS
-
-#define OBJTYPE_RLOCK
-#define OBJTYPE_WLOCK
-
-#else
-
#define OBJTYPE_RLOCK RWLockRead _rw_lockr_(lock);
#define OBJTYPE_WLOCK RWLockWrite _rw_lockw_(lock);
-#endif
-
#ifdef DEBUG_METHODS_ENABLED
MethodDefinition D_METHOD(const char *p_name) {
@@ -207,6 +198,47 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_
return md;
}
+MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9, const char *p_arg10, const char *p_arg11, const char *p_arg12) {
+
+ MethodDefinition md;
+ md.name = StaticCString::create(p_name);
+ md.args.resize(12);
+ md.args[0] = StaticCString::create(p_arg1);
+ md.args[1] = StaticCString::create(p_arg2);
+ md.args[2] = StaticCString::create(p_arg3);
+ md.args[3] = StaticCString::create(p_arg4);
+ md.args[4] = StaticCString::create(p_arg5);
+ md.args[5] = StaticCString::create(p_arg6);
+ md.args[6] = StaticCString::create(p_arg7);
+ md.args[7] = StaticCString::create(p_arg8);
+ md.args[8] = StaticCString::create(p_arg9);
+ md.args[9] = StaticCString::create(p_arg10);
+ md.args[10] = StaticCString::create(p_arg11);
+ md.args[11] = StaticCString::create(p_arg12);
+ return md;
+}
+
+MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9, const char *p_arg10, const char *p_arg11, const char *p_arg12, const char *p_arg13) {
+
+ MethodDefinition md;
+ md.name = StaticCString::create(p_name);
+ md.args.resize(13);
+ md.args[0] = StaticCString::create(p_arg1);
+ md.args[1] = StaticCString::create(p_arg2);
+ md.args[2] = StaticCString::create(p_arg3);
+ md.args[3] = StaticCString::create(p_arg4);
+ md.args[4] = StaticCString::create(p_arg5);
+ md.args[5] = StaticCString::create(p_arg6);
+ md.args[6] = StaticCString::create(p_arg7);
+ md.args[7] = StaticCString::create(p_arg8);
+ md.args[8] = StaticCString::create(p_arg9);
+ md.args[9] = StaticCString::create(p_arg10);
+ md.args[10] = StaticCString::create(p_arg11);
+ md.args[11] = StaticCString::create(p_arg12);
+ md.args[12] = StaticCString::create(p_arg13);
+ return md;
+}
+
#endif
ClassDB::APIType ClassDB::current_api = API_CORE;
@@ -306,7 +338,7 @@ uint64_t ClassDB::get_api_hash(APIType p_api) {
OBJTYPE_RLOCK;
#ifdef DEBUG_METHODS_ENABLED
- uint64_t hash = hash_djb2_one_64(HashMapHasherDefault::hash(VERSION_FULL_NAME));
+ uint64_t hash = hash_djb2_one_64(HashMapHasherDefault::hash(VERSION_FULL_CONFIG));
List<StringName> names;
@@ -619,7 +651,6 @@ void ClassDB::bind_integer_constant(const StringName &p_class, const StringName
}
type->constant_map[p_name] = p_constant;
-#ifdef DEBUG_METHODS_ENABLED
String enum_name = p_enum;
if (enum_name != String()) {
@@ -638,6 +669,7 @@ void ClassDB::bind_integer_constant(const StringName &p_class, const StringName
}
}
+#ifdef DEBUG_METHODS_ENABLED
type->constant_order.push_back(p_name);
#endif
}
@@ -693,7 +725,6 @@ int ClassDB::get_integer_constant(const StringName &p_class, const StringName &p
return 0;
}
-#ifdef DEBUG_METHODS_ENABLED
StringName ClassDB::get_integer_constant_enum(const StringName &p_class, const StringName &p_name, bool p_no_inheritance) {
OBJTYPE_RLOCK;
@@ -762,7 +793,6 @@ void ClassDB::get_enum_constants(const StringName &p_class, const StringName &p_
type = type->inherits_ptr;
}
}
-#endif
void ClassDB::add_signal(StringName p_class, const MethodInfo &p_signal) {
@@ -854,15 +884,9 @@ void ClassDB::add_property_group(StringName p_class, const String &p_name, const
void ClassDB::add_property(StringName p_class, const PropertyInfo &p_pinfo, const StringName &p_setter, const StringName &p_getter, int p_index) {
-#ifndef NO_THREADS
lock->read_lock();
-#endif
-
ClassInfo *type = classes.getptr(p_class);
-
-#ifndef NO_THREADS
lock->read_unlock();
-#endif
ERR_FAIL_COND(!type);
@@ -1339,10 +1363,7 @@ RWLock *ClassDB::lock = NULL;
void ClassDB::init() {
-#ifndef NO_THREADS
-
lock = RWLock::create();
-#endif
}
void ClassDB::cleanup() {
@@ -1365,10 +1386,7 @@ void ClassDB::cleanup() {
resource_base_extensions.clear();
compat_classes.clear();
-#ifndef NO_THREADS
-
memdelete(lock);
-#endif
}
//
diff --git a/core/class_db.h b/core/class_db.h
index 14e36e459b..2c77ffe65f 100644
--- a/core/class_db.h
+++ b/core/class_db.h
@@ -68,6 +68,8 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_
MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9);
MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9, const char *p_arg10);
MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9, const char *p_arg10, const char *p_arg11);
+MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9, const char *p_arg10, const char *p_arg11, const char *p_arg12);
+MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9, const char *p_arg10, const char *p_arg11, const char *p_arg12, const char *p_arg13);
#else
@@ -114,10 +116,10 @@ public:
ClassInfo *inherits_ptr;
HashMap<StringName, MethodBind *, StringNameHasher> method_map;
HashMap<StringName, int, StringNameHasher> constant_map;
+ HashMap<StringName, List<StringName> > enum_map;
HashMap<StringName, MethodInfo, StringNameHasher> signal_map;
List<PropertyInfo> property_list;
#ifdef DEBUG_METHODS_ENABLED
- HashMap<StringName, List<StringName> > enum_map;
List<StringName> constant_order;
List<StringName> method_order;
Set<StringName> methods_in_properties;
@@ -342,11 +344,9 @@ public:
static void get_integer_constant_list(const StringName &p_class, List<String> *p_constants, bool p_no_inheritance = false);
static int get_integer_constant(const StringName &p_class, const StringName &p_name, bool *p_success = NULL);
-#ifdef DEBUG_METHODS_ENABLED
static StringName get_integer_constant_enum(const StringName &p_class, const StringName &p_name, bool p_no_inheritance = false);
static void get_enum_list(const StringName &p_class, List<StringName> *p_enums, bool p_no_inheritance = false);
static void get_enum_constants(const StringName &p_class, const StringName &p_enum, List<StringName> *p_constants, bool p_no_inheritance = false);
-#endif
static StringName get_category(const StringName &p_node);
diff --git a/core/color.cpp b/core/color.cpp
index a0568d26ed..b2f5889166 100644
--- a/core/color.cpp
+++ b/core/color.cpp
@@ -400,6 +400,59 @@ String Color::to_html(bool p_alpha) const {
return txt;
}
+Color Color::from_hsv(float p_h, float p_s, float p_v, float p_a) {
+
+ p_h = Math::fmod(p_h * 360.0f, 360.0f);
+ if (p_h < 0.0)
+ p_h += 360.0f;
+
+ const float h_ = p_h / 60.0f;
+ const float c = p_v * p_s;
+ const float x = c * (1.0f - Math::abs(Math::fmod(h_, 2.0f) - 1.0f));
+ float r, g, b;
+
+ switch ((int)h_) {
+ case 0: {
+ r = c;
+ g = x;
+ b = 0;
+ } break;
+ case 1: {
+ r = x;
+ g = c;
+ b = 0;
+ } break;
+ case 2: {
+ r = 0;
+ g = c;
+ b = x;
+ } break;
+ case 3: {
+ r = 0;
+ g = x;
+ b = c;
+ } break;
+ case 4: {
+ r = x;
+ g = 0;
+ b = c;
+ } break;
+ case 5: {
+ r = c;
+ g = 0;
+ b = x;
+ } break;
+ default: {
+ r = 0;
+ g = 0;
+ b = 0;
+ } break;
+ }
+
+ const float m = p_v - c;
+ return Color(m + r, m + g, m + b, p_a);
+}
+
float Color::gray() const {
return (r + g + b) / 3.0;
diff --git a/core/color.h b/core/color.h
index 9af8fb0a78..a2015a34d6 100644
--- a/core/color.h
+++ b/core/color.h
@@ -190,6 +190,7 @@ struct Color {
static bool html_is_valid(const String &p_color);
static Color named(const String &p_name);
String to_html(bool p_alpha = true) const;
+ Color from_hsv(float p_h, float p_s, float p_v, float p_a);
_FORCE_INLINE_ bool operator<(const Color &p_color) const; //used in set keys
operator String() const;
diff --git a/core/command_queue_mt.cpp b/core/command_queue_mt.cpp
index 6bb3135757..a39c920dfa 100644
--- a/core/command_queue_mt.cpp
+++ b/core/command_queue_mt.cpp
@@ -105,6 +105,7 @@ CommandQueueMT::CommandQueueMT(bool p_sync) {
read_ptr = 0;
write_ptr = 0;
+ dealloc_ptr = 0;
mutex = Mutex::create();
for (int i = 0; i < SYNC_SEMAPHORES; i++) {
diff --git a/core/command_queue_mt.h b/core/command_queue_mt.h
index cecc9e405d..3942b961d3 100644
--- a/core/command_queue_mt.h
+++ b/core/command_queue_mt.h
@@ -55,7 +55,7 @@
#define _COMMA_11 ,
#define _COMMA_12 ,
-// 1-based comma separed list of ITEMs
+// 1-based comma separated list of ITEMs
#define COMMA_SEP_LIST(ITEM, LENGTH) _COMMA_SEP_LIST_##LENGTH(ITEM)
#define _COMMA_SEP_LIST_12(ITEM) \
_COMMA_SEP_LIST_11(ITEM) \
@@ -95,7 +95,7 @@
ITEM(1)
#define _COMMA_SEP_LIST_0(ITEM)
-// 1-based semicolon separed list of ITEMs
+// 1-based semicolon separated list of ITEMs
#define SEMIC_SEP_LIST(ITEM, LENGTH) _SEMIC_SEP_LIST_##LENGTH(ITEM)
#define _SEMIC_SEP_LIST_12(ITEM) \
_SEMIC_SEP_LIST_11(ITEM); \
@@ -135,7 +135,7 @@
ITEM(1)
#define _SEMIC_SEP_LIST_0(ITEM)
-// 1-based space separed list of ITEMs
+// 1-based space separated list of ITEMs
#define SPACE_SEP_LIST(ITEM, LENGTH) _SPACE_SEP_LIST_##LENGTH(ITEM)
#define _SPACE_SEP_LIST_12(ITEM) \
_SPACE_SEP_LIST_11(ITEM) \
diff --git a/core/compressed_translation.h b/core/compressed_translation.h
index 400fa4491b..ccc47d0bf6 100644
--- a/core/compressed_translation.h
+++ b/core/compressed_translation.h
@@ -38,7 +38,7 @@ class PHashTranslation : public Translation {
GDCLASS(PHashTranslation, Translation);
//this translation uses a sort of modified perfect hash algorithm
- //it requieres hashing strings twice and then does a binary search,
+ //it requires hashing strings twice and then does a binary search,
//so it's slower, but at the same time it has an extreemly high chance
//of catching untranslated strings
diff --git a/core/dictionary.cpp b/core/dictionary.cpp
index e3f4aa5f28..ba0de95861 100644
--- a/core/dictionary.cpp
+++ b/core/dictionary.cpp
@@ -211,7 +211,7 @@ const Variant *Dictionary::next(const Variant *p_key) const {
return NULL;
}
-Dictionary Dictionary::duplicate() const {
+Dictionary Dictionary::duplicate(bool p_deep) const {
Dictionary n;
@@ -219,7 +219,7 @@ Dictionary Dictionary::duplicate() const {
get_key_list(&keys);
for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
- n[E->get()] = operator[](E->get());
+ n[E->get()] = p_deep ? operator[](E->get()).duplicate(p_deep) : operator[](E->get());
}
return n;
diff --git a/core/dictionary.h b/core/dictionary.h
index f001f2d5e1..9eef265d5b 100644
--- a/core/dictionary.h
+++ b/core/dictionary.h
@@ -75,7 +75,7 @@ public:
Array keys() const;
Array values() const;
- Dictionary duplicate() const;
+ Dictionary duplicate(bool p_deep = false) const;
Dictionary(const Dictionary &p_from);
Dictionary();
diff --git a/core/error_macros.h b/core/error_macros.h
index 1f9164a99b..b8d0c7e0c3 100644
--- a/core/error_macros.h
+++ b/core/error_macros.h
@@ -33,7 +33,7 @@
#include "typedefs.h"
/**
- * Error macros. Unlike exceptions and asserts, these macros try to mantain consistency and stability
+ * Error macros. Unlike exceptions and asserts, these macros try to maintain consistency and stability
* inside the code. It is recommended to always return processable data, so in case of an error, the
* engine can stay working well.
* In most cases, bugs and/or invalid data are not fatal and should never allow a perfectly running application
diff --git a/core/global_constants.cpp b/core/global_constants.cpp
index a24bf03c9a..04810afe73 100644
--- a/core/global_constants.cpp
+++ b/core/global_constants.cpp
@@ -580,7 +580,7 @@ void register_global_constants() {
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_COLOR_ARRAY", Variant::POOL_COLOR_ARRAY);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_MAX", Variant::VARIANT_MAX);
- //comparation
+ //comparison
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_EQUAL", Variant::OP_EQUAL);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_NOT_EQUAL", Variant::OP_NOT_EQUAL);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_LESS", Variant::OP_LESS);
diff --git a/core/image.cpp b/core/image.cpp
index 07e705265d..2ac8ffea56 100644
--- a/core/image.cpp
+++ b/core/image.cpp
@@ -1077,61 +1077,29 @@ Error Image::generate_mipmaps() {
PoolVector<uint8_t>::Write wp = data.write();
- if (next_power_of_2(width) == uint32_t(width) && next_power_of_2(height) == uint32_t(height)) {
- //use fast code for powers of 2
- int prev_ofs = 0;
- int prev_h = height;
- int prev_w = width;
+ int prev_ofs = 0;
+ int prev_h = height;
+ int prev_w = width;
- for (int i = 1; i < mmcount; i++) {
+ for (int i = 1; i < mmcount; i++) {
- int ofs, w, h;
- _get_mipmap_offset_and_size(i, ofs, w, h);
+ int ofs, w, h;
+ _get_mipmap_offset_and_size(i, ofs, w, h);
- switch (format) {
+ switch (format) {
- case FORMAT_L8:
- case FORMAT_R8: _generate_po2_mipmap<1>(&wp[prev_ofs], &wp[ofs], prev_w, prev_h); break;
- case FORMAT_LA8:
- case FORMAT_RG8: _generate_po2_mipmap<2>(&wp[prev_ofs], &wp[ofs], prev_w, prev_h); break;
- case FORMAT_RGB8: _generate_po2_mipmap<3>(&wp[prev_ofs], &wp[ofs], prev_w, prev_h); break;
- case FORMAT_RGBA8: _generate_po2_mipmap<4>(&wp[prev_ofs], &wp[ofs], prev_w, prev_h); break;
- default: {}
- }
-
- prev_ofs = ofs;
- prev_w = w;
- prev_h = h;
+ case FORMAT_L8:
+ case FORMAT_R8: _generate_po2_mipmap<1>(&wp[prev_ofs], &wp[ofs], prev_w, prev_h); break;
+ case FORMAT_LA8:
+ case FORMAT_RG8: _generate_po2_mipmap<2>(&wp[prev_ofs], &wp[ofs], prev_w, prev_h); break;
+ case FORMAT_RGB8: _generate_po2_mipmap<3>(&wp[prev_ofs], &wp[ofs], prev_w, prev_h); break;
+ case FORMAT_RGBA8: _generate_po2_mipmap<4>(&wp[prev_ofs], &wp[ofs], prev_w, prev_h); break;
+ default: {}
}
- } else {
- //use slow code..
-
- //use bilinear filtered code for non powers of 2
- int prev_ofs = 0;
- int prev_h = height;
- int prev_w = width;
-
- for (int i = 1; i < mmcount; i++) {
-
- int ofs, w, h;
- _get_mipmap_offset_and_size(i, ofs, w, h);
-
- switch (format) {
-
- case FORMAT_L8:
- case FORMAT_R8: _scale_bilinear<1>(&wp[prev_ofs], &wp[ofs], prev_w, prev_h, w, h); break;
- case FORMAT_LA8:
- case FORMAT_RG8: _scale_bilinear<2>(&wp[prev_ofs], &wp[ofs], prev_w, prev_h, w, h); break;
- case FORMAT_RGB8: _scale_bilinear<3>(&wp[prev_ofs], &wp[ofs], prev_w, prev_h, w, h); break;
- case FORMAT_RGBA8: _scale_bilinear<4>(&wp[prev_ofs], &wp[ofs], prev_w, prev_h, w, h); break;
- default: {}
- }
-
- prev_ofs = ofs;
- prev_w = w;
- prev_h = h;
- }
+ prev_ofs = ofs;
+ prev_w = w;
+ prev_h = h;
}
mipmaps = true;
@@ -2271,6 +2239,7 @@ void Image::_bind_methods() {
ClassDB::bind_method(D_METHOD("premultiply_alpha"), &Image::premultiply_alpha);
ClassDB::bind_method(D_METHOD("srgb_to_linear"), &Image::srgb_to_linear);
ClassDB::bind_method(D_METHOD("normalmap_to_xy"), &Image::normalmap_to_xy);
+ ClassDB::bind_method(D_METHOD("bumpmap_to_normalmap", "bump_scale"), &Image::bumpmap_to_normalmap, DEFVAL(1.0));
ClassDB::bind_method(D_METHOD("blit_rect", "src", "src_rect", "dst"), &Image::blit_rect);
ClassDB::bind_method(D_METHOD("blit_rect_mask", "src", "mask", "src_rect", "dst"), &Image::blit_rect_mask);
@@ -2379,6 +2348,47 @@ void Image::normalmap_to_xy() {
convert(Image::FORMAT_LA8);
}
+void Image::bumpmap_to_normalmap(float bump_scale) {
+ ERR_FAIL_COND(!_can_modify(format));
+ convert(Image::FORMAT_RF);
+
+ PoolVector<uint8_t> result_image; //rgba output
+ result_image.resize(width * height * 4);
+
+ {
+ PoolVector<uint8_t>::Read rp = data.read();
+ PoolVector<uint8_t>::Write wp = result_image.write();
+
+ unsigned char *write_ptr = wp.ptr();
+ float *read_ptr = (float *)rp.ptr();
+
+ for (int ty = 0; ty < height; ty++) {
+ int py = ty + 1;
+ if (py >= height) py -= height;
+
+ for (int tx = 0; tx < width; tx++) {
+ int px = tx + 1;
+ if (px >= width) px -= width;
+ float here = read_ptr[ty * width + tx];
+ float to_right = read_ptr[ty * width + px];
+ float above = read_ptr[py * width + tx];
+ Vector3 up = Vector3(0, 1, (here - above) * bump_scale);
+ Vector3 across = Vector3(1, 0, (to_right - here) * bump_scale);
+
+ Vector3 normal = across.cross(up);
+ normal.normalize();
+
+ write_ptr[((ty * width + tx) << 2) + 0] = (127.5 + normal.x * 127.5);
+ write_ptr[((ty * width + tx) << 2) + 1] = (127.5 + normal.y * 127.5);
+ write_ptr[((ty * width + tx) << 2) + 2] = (127.5 + normal.z * 127.5);
+ write_ptr[((ty * width + tx) << 2) + 3] = 255;
+ }
+ }
+ }
+ format = FORMAT_RGBA8;
+ data = result_image;
+}
+
void Image::srgb_to_linear() {
if (data.size() == 0)
diff --git a/core/image.h b/core/image.h
index e962787ae9..17477d88ea 100644
--- a/core/image.h
+++ b/core/image.h
@@ -284,6 +284,7 @@ public:
void premultiply_alpha();
void srgb_to_linear();
void normalmap_to_xy();
+ void bumpmap_to_normalmap(float bump_scale = 1.0);
void blit_rect(const Ref<Image> &p_src, const Rect2 &p_src_rect, const Point2 &p_dest);
void blit_rect_mask(const Ref<Image> &p_src, const Ref<Image> &p_mask, const Rect2 &p_src_rect, const Point2 &p_dest);
diff --git a/core/input_map.cpp b/core/input_map.cpp
index a9ea1d9545..ea724d2595 100644
--- a/core/input_map.cpp
+++ b/core/input_map.cpp
@@ -35,6 +35,8 @@
InputMap *InputMap::singleton = NULL;
+int InputMap::ALL_DEVICES = -1;
+
void InputMap::_bind_methods() {
ClassDB::bind_method(D_METHOD("has_action", "action"), &InputMap::has_action);
@@ -103,10 +105,10 @@ List<Ref<InputEvent> >::Element *InputMap::_find_event(List<Ref<InputEvent> > &p
//if (e.type != Ref<InputEvent>::KEY && e.device != p_event.device) -- unsure about the KEY comparison, why is this here?
// continue;
- if (e->get_device() != p_event->get_device())
- continue;
- if (e->action_match(p_event))
- return E;
+ int device = e->get_device();
+ if (device == ALL_DEVICES || device == p_event->get_device())
+ if (e->action_match(p_event))
+ return E;
}
return NULL;
@@ -282,6 +284,16 @@ void InputMap::load_default() {
key->set_scancode(KEY_PAGEDOWN);
action_add_event("ui_page_down", key);
+ add_action("ui_home");
+ key.instance();
+ key->set_scancode(KEY_HOME);
+ action_add_event("ui_home", key);
+
+ add_action("ui_end");
+ key.instance();
+ key->set_scancode(KEY_END);
+ action_add_event("ui_end", key);
+
//set("display/window/handheld/orientation", "landscape");
}
diff --git a/core/input_map.h b/core/input_map.h
index 84d90f6f2a..9f3c13c2cf 100644
--- a/core/input_map.h
+++ b/core/input_map.h
@@ -39,6 +39,11 @@ class InputMap : public Object {
GDCLASS(InputMap, Object);
public:
+ /**
+ * A special value used to signify that a given Action can be triggered by any device
+ */
+ static int ALL_DEVICES;
+
struct Action {
int id;
List<Ref<InputEvent> > inputs;
diff --git a/core/io/file_access_network.cpp b/core/io/file_access_network.cpp
index ef886cdb3c..21e3a4172b 100644
--- a/core/io/file_access_network.cpp
+++ b/core/io/file_access_network.cpp
@@ -418,8 +418,6 @@ int FileAccessNetwork::get_buffer(uint8_t *p_dst, int p_length) const {
if (page != last_page) {
buffer_mutex->lock();
if (pages[page].buffer.empty()) {
- //fuck
-
waiting_on_page = page;
for (int j = 0; j < read_ahead; j++) {
diff --git a/core/io/file_access_pack.cpp b/core/io/file_access_pack.cpp
index 1a16d0f61c..efb4c7a073 100644
--- a/core/io/file_access_pack.cpp
+++ b/core/io/file_access_pack.cpp
@@ -88,7 +88,11 @@ void PackedData::add_path(const String &pkg_path, const String &path, uint64_t o
}
}
}
- cd->files.insert(path.get_file());
+ String filename = path.get_file();
+ // Don't add as a file if the path points to a directoryy
+ if (!filename.empty()) {
+ cd->files.insert(filename);
+ }
}
}
diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp
index a9eb9466b7..c787b7ec4c 100644
--- a/core/io/http_client.cpp
+++ b/core/io/http_client.cpp
@@ -298,7 +298,7 @@ Error HTTPClient::poll() {
case StreamPeerTCP::STATUS_CONNECTED: {
if (ssl) {
Ref<StreamPeerSSL> ssl = StreamPeerSSL::create();
- Error err = ssl->connect_to_stream(tcp_connection, ssl_verify_host, ssl_verify_host ? conn_host : String());
+ Error err = ssl->connect_to_stream(tcp_connection, ssl_verify_host, conn_host);
if (err != OK) {
close();
status = STATUS_SSL_HANDSHAKE_ERROR;
@@ -618,7 +618,27 @@ String HTTPClient::query_string_from_dict(const Dictionary &p_dict) {
String query = "";
Array keys = p_dict.keys();
for (int i = 0; i < keys.size(); ++i) {
- query += "&" + String(keys[i]).http_escape() + "=" + String(p_dict[keys[i]]).http_escape();
+ String encoded_key = String(keys[i]).percent_encode();
+ Variant value = p_dict[keys[i]];
+ switch (value.get_type()) {
+ case Variant::ARRAY: {
+ // Repeat the key with every values
+ Array values = value;
+ for (int j = 0; j < values.size(); ++j) {
+ query += "&" + encoded_key + "=" + String(values[j]).percent_encode();
+ }
+ break;
+ }
+ case Variant::NIL: {
+ // Add the key with no value
+ query += "&" + encoded_key;
+ break;
+ }
+ default: {
+ // Add the key-value pair
+ query += "&" + encoded_key + "=" + String(value).percent_encode();
+ }
+ }
}
query.erase(0, 1);
return query;
diff --git a/core/io/ip_address.cpp b/core/io/ip_address.cpp
index 7261363ad6..6d979d10eb 100644
--- a/core/io/ip_address.cpp
+++ b/core/io/ip_address.cpp
@@ -211,7 +211,7 @@ IP_Address::IP_Address(const String &p_string) {
clear();
if (p_string == "*") {
- // Wildcard (not a vaild IP)
+ // Wildcard (not a valid IP)
wildcard = true;
} else if (p_string.find(":") >= 0) {
diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp
index 9e21287780..2ebe8d6df7 100644
--- a/core/io/marshalls.cpp
+++ b/core/io/marshalls.cpp
@@ -813,7 +813,7 @@ static void _encode_string(const String &p_string, uint8_t *&buf, int &r_len) {
while (r_len % 4) {
r_len++; //pad
if (buf) {
- buf++;
+ *(buf++) = 0;
}
}
}
diff --git a/core/io/multiplayer_api.cpp b/core/io/multiplayer_api.cpp
new file mode 100644
index 0000000000..cbe7f87d92
--- /dev/null
+++ b/core/io/multiplayer_api.cpp
@@ -0,0 +1,722 @@
+#include "core/io/multiplayer_api.h"
+#include "core/io/marshalls.h"
+#include "scene/main/node.h"
+
+void MultiplayerAPI::poll() {
+
+ if (!network_peer.is_valid() || network_peer->get_connection_status() == NetworkedMultiplayerPeer::CONNECTION_DISCONNECTED)
+ return;
+
+ network_peer->poll();
+
+ if (!network_peer.is_valid()) //it's possible that polling might have resulted in a disconnection, so check here
+ return;
+
+ while (network_peer->get_available_packet_count()) {
+
+ int sender = network_peer->get_packet_peer();
+ const uint8_t *packet;
+ int len;
+
+ Error err = network_peer->get_packet(&packet, len);
+ if (err != OK) {
+ ERR_PRINT("Error getting packet!");
+ }
+
+ rpc_sender_id = sender;
+ _process_packet(sender, packet, len);
+ rpc_sender_id = 0;
+
+ if (!network_peer.is_valid()) {
+ break; //it's also possible that a packet or RPC caused a disconnection, so also check here
+ }
+ }
+}
+
+void MultiplayerAPI::clear() {
+ connected_peers.clear();
+ path_get_cache.clear();
+ path_send_cache.clear();
+ last_send_cache_id = 1;
+}
+
+void MultiplayerAPI::set_root_node(Node *p_node) {
+ root_node = p_node;
+}
+
+void MultiplayerAPI::set_network_peer(const Ref<NetworkedMultiplayerPeer> &p_peer) {
+
+ if (network_peer.is_valid()) {
+ network_peer->disconnect("peer_connected", this, "add_peer");
+ network_peer->disconnect("peer_disconnected", this, "del_peer");
+ network_peer->disconnect("connection_succeeded", this, "connected_to_server");
+ network_peer->disconnect("connection_failed", this, "connection_failed");
+ network_peer->disconnect("server_disconnected", this, "server_disconnected");
+ clear();
+ }
+
+ network_peer = p_peer;
+
+ ERR_EXPLAIN("Supplied NetworkedNetworkPeer must be connecting or connected.");
+ ERR_FAIL_COND(p_peer.is_valid() && p_peer->get_connection_status() == NetworkedMultiplayerPeer::CONNECTION_DISCONNECTED);
+
+ if (network_peer.is_valid()) {
+ network_peer->connect("peer_connected", this, "add_peer");
+ network_peer->connect("peer_disconnected", this, "del_peer");
+ network_peer->connect("connection_succeeded", this, "connected_to_server");
+ network_peer->connect("connection_failed", this, "connection_failed");
+ network_peer->connect("server_disconnected", this, "server_disconnected");
+ }
+}
+
+Ref<NetworkedMultiplayerPeer> MultiplayerAPI::get_network_peer() const {
+ return network_peer;
+}
+
+void MultiplayerAPI::_process_packet(int p_from, const uint8_t *p_packet, int p_packet_len) {
+
+ ERR_FAIL_COND(root_node == NULL);
+ ERR_FAIL_COND(p_packet_len < 5);
+
+ uint8_t packet_type = p_packet[0];
+
+ switch (packet_type) {
+
+ case NETWORK_COMMAND_SIMPLIFY_PATH: {
+
+ _process_simplify_path(p_from, p_packet, p_packet_len);
+ } break;
+
+ case NETWORK_COMMAND_CONFIRM_PATH: {
+
+ _process_confirm_path(p_from, p_packet, p_packet_len);
+ } break;
+
+ case NETWORK_COMMAND_REMOTE_CALL:
+ case NETWORK_COMMAND_REMOTE_SET: {
+
+ ERR_FAIL_COND(p_packet_len < 6);
+
+ Node *node = _process_get_node(p_from, p_packet, p_packet_len);
+
+ ERR_FAIL_COND(node == NULL);
+
+ //detect cstring end
+ int len_end = 5;
+ for (; len_end < p_packet_len; len_end++) {
+ if (p_packet[len_end] == 0) {
+ break;
+ }
+ }
+
+ ERR_FAIL_COND(len_end >= p_packet_len);
+
+ StringName name = String::utf8((const char *)&p_packet[5]);
+
+ if (packet_type == NETWORK_COMMAND_REMOTE_CALL) {
+
+ _process_rpc(node, name, p_from, p_packet, p_packet_len, len_end + 1);
+
+ } else {
+
+ _process_rset(node, name, p_from, p_packet, p_packet_len, len_end + 1);
+ }
+
+ } break;
+ }
+}
+
+Node *MultiplayerAPI::_process_get_node(int p_from, const uint8_t *p_packet, int p_packet_len) {
+
+ uint32_t target = decode_uint32(&p_packet[1]);
+ Node *node = NULL;
+
+ if (target & 0x80000000) {
+ //use full path (not cached yet)
+
+ int ofs = target & 0x7FFFFFFF;
+ ERR_FAIL_COND_V(ofs >= p_packet_len, NULL);
+
+ String paths;
+ paths.parse_utf8((const char *)&p_packet[ofs], p_packet_len - ofs);
+
+ NodePath np = paths;
+
+ node = root_node->get_node(np);
+
+ if (!node)
+ ERR_PRINTS("Failed to get path from RPC: " + String(np));
+ } else {
+ //use cached path
+ int id = target;
+
+ Map<int, PathGetCache>::Element *E = path_get_cache.find(p_from);
+ ERR_FAIL_COND_V(!E, NULL);
+
+ Map<int, PathGetCache::NodeInfo>::Element *F = E->get().nodes.find(id);
+ ERR_FAIL_COND_V(!F, NULL);
+
+ PathGetCache::NodeInfo *ni = &F->get();
+ //do proper caching later
+
+ node = root_node->get_node(ni->path);
+ if (!node)
+ ERR_PRINTS("Failed to get cached path from RPC: " + String(ni->path));
+ }
+ return node;
+}
+
+void MultiplayerAPI::_process_rpc(Node *p_node, const StringName &p_name, int p_from, const uint8_t *p_packet, int p_packet_len, int p_offset) {
+ if (!p_node->can_call_rpc(p_name, p_from))
+ return;
+
+ ERR_FAIL_COND(p_offset >= p_packet_len);
+
+ int argc = p_packet[p_offset];
+ Vector<Variant> args;
+ Vector<const Variant *> argp;
+ args.resize(argc);
+ argp.resize(argc);
+
+ p_offset++;
+
+ for (int i = 0; i < argc; i++) {
+
+ ERR_FAIL_COND(p_offset >= p_packet_len);
+ int vlen;
+ Error err = decode_variant(args[i], &p_packet[p_offset], p_packet_len - p_offset, &vlen);
+ ERR_FAIL_COND(err != OK);
+ //args[i]=p_packet[3+i];
+ argp[i] = &args[i];
+ p_offset += vlen;
+ }
+
+ Variant::CallError ce;
+
+ p_node->call(p_name, (const Variant **)argp.ptr(), argc, ce);
+ if (ce.error != Variant::CallError::CALL_OK) {
+ String error = Variant::get_call_error_text(p_node, p_name, (const Variant **)argp.ptr(), argc, ce);
+ error = "RPC - " + error;
+ ERR_PRINTS(error);
+ }
+}
+
+void MultiplayerAPI::_process_rset(Node *p_node, const StringName &p_name, int p_from, const uint8_t *p_packet, int p_packet_len, int p_offset) {
+
+ if (!p_node->can_call_rset(p_name, p_from))
+ return;
+
+ ERR_FAIL_COND(p_offset >= p_packet_len);
+
+ Variant value;
+ decode_variant(value, &p_packet[p_offset], p_packet_len - p_offset);
+
+ bool valid;
+
+ p_node->set(p_name, value, &valid);
+ if (!valid) {
+ String error = "Error setting remote property '" + String(p_name) + "', not found in object of type " + p_node->get_class();
+ ERR_PRINTS(error);
+ }
+}
+
+void MultiplayerAPI::_process_simplify_path(int p_from, const uint8_t *p_packet, int p_packet_len) {
+
+ ERR_FAIL_COND(p_packet_len < 5);
+ int id = decode_uint32(&p_packet[1]);
+
+ String paths;
+ paths.parse_utf8((const char *)&p_packet[5], p_packet_len - 5);
+
+ NodePath path = paths;
+
+ if (!path_get_cache.has(p_from)) {
+ path_get_cache[p_from] = PathGetCache();
+ }
+
+ PathGetCache::NodeInfo ni;
+ ni.path = path;
+ ni.instance = 0;
+
+ path_get_cache[p_from].nodes[id] = ni;
+
+ //send ack
+
+ //encode path
+ CharString pname = String(path).utf8();
+ int len = encode_cstring(pname.get_data(), NULL);
+
+ Vector<uint8_t> packet;
+
+ packet.resize(1 + len);
+ packet[0] = NETWORK_COMMAND_CONFIRM_PATH;
+ encode_cstring(pname.get_data(), &packet[1]);
+
+ network_peer->set_transfer_mode(NetworkedMultiplayerPeer::TRANSFER_MODE_RELIABLE);
+ network_peer->set_target_peer(p_from);
+ network_peer->put_packet(packet.ptr(), packet.size());
+}
+
+void MultiplayerAPI::_process_confirm_path(int p_from, const uint8_t *p_packet, int p_packet_len) {
+
+ String paths;
+ paths.parse_utf8((const char *)&p_packet[1], p_packet_len - 1);
+
+ NodePath path = paths;
+
+ PathSentCache *psc = path_send_cache.getptr(path);
+ ERR_FAIL_COND(!psc);
+
+ Map<int, bool>::Element *E = psc->confirmed_peers.find(p_from);
+ ERR_FAIL_COND(!E);
+ E->get() = true;
+}
+
+bool MultiplayerAPI::_send_confirm_path(NodePath p_path, PathSentCache *psc, int p_target) {
+ bool has_all_peers = true;
+ List<int> peers_to_add; //if one is missing, take note to add it
+
+ for (Set<int>::Element *E = connected_peers.front(); E; E = E->next()) {
+
+ if (p_target < 0 && E->get() == -p_target)
+ continue; //continue, excluded
+
+ if (p_target > 0 && E->get() != p_target)
+ continue; //continue, not for this peer
+
+ Map<int, bool>::Element *F = psc->confirmed_peers.find(E->get());
+
+ if (!F || F->get() == false) {
+ //path was not cached, or was cached but is unconfirmed
+ if (!F) {
+ //not cached at all, take note
+ peers_to_add.push_back(E->get());
+ }
+
+ has_all_peers = false;
+ }
+ }
+
+ //those that need to be added, send a message for this
+
+ for (List<int>::Element *E = peers_to_add.front(); E; E = E->next()) {
+
+ //encode function name
+ CharString pname = String(p_path).utf8();
+ int len = encode_cstring(pname.get_data(), NULL);
+
+ Vector<uint8_t> packet;
+
+ packet.resize(1 + 4 + len);
+ packet[0] = NETWORK_COMMAND_SIMPLIFY_PATH;
+ encode_uint32(psc->id, &packet[1]);
+ encode_cstring(pname.get_data(), &packet[5]);
+
+ network_peer->set_target_peer(E->get()); //to all of you
+ network_peer->set_transfer_mode(NetworkedMultiplayerPeer::TRANSFER_MODE_RELIABLE);
+ network_peer->put_packet(packet.ptr(), packet.size());
+
+ psc->confirmed_peers.insert(E->get(), false); //insert into confirmed, but as false since it was not confirmed
+ }
+
+ return has_all_peers;
+}
+
+void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p_set, const StringName &p_name, const Variant **p_arg, int p_argcount) {
+
+ if (network_peer.is_null()) {
+ ERR_EXPLAIN("Attempt to remote call/set when networking is not active in SceneTree.");
+ ERR_FAIL();
+ }
+
+ if (network_peer->get_connection_status() == NetworkedMultiplayerPeer::CONNECTION_CONNECTING) {
+ ERR_EXPLAIN("Attempt to remote call/set when networking is not connected yet in SceneTree.");
+ ERR_FAIL();
+ }
+
+ if (network_peer->get_connection_status() == NetworkedMultiplayerPeer::CONNECTION_DISCONNECTED) {
+ ERR_EXPLAIN("Attempt to remote call/set when networking is disconnected.");
+ ERR_FAIL();
+ }
+
+ if (p_argcount > 255) {
+ ERR_EXPLAIN("Too many arguments >255.");
+ ERR_FAIL();
+ }
+
+ if (p_to != 0 && !connected_peers.has(ABS(p_to))) {
+ if (p_to == network_peer->get_unique_id()) {
+ ERR_EXPLAIN("Attempt to remote call/set yourself! unique ID: " + itos(network_peer->get_unique_id()));
+ } else {
+ ERR_EXPLAIN("Attempt to remote call unexisting ID: " + itos(p_to));
+ }
+
+ ERR_FAIL();
+ }
+
+ NodePath from_path = (root_node->get_path()).rel_path_to(p_from->get_path());
+ ERR_FAIL_COND(from_path.is_empty());
+
+ //see if the path is cached
+ PathSentCache *psc = path_send_cache.getptr(from_path);
+ if (!psc) {
+ //path is not cached, create
+ path_send_cache[from_path] = PathSentCache();
+ psc = path_send_cache.getptr(from_path);
+ psc->id = last_send_cache_id++;
+ }
+
+ //create base packet, lots of hardcode because it must be tight
+
+ int ofs = 0;
+
+#define MAKE_ROOM(m_amount) \
+ if (packet_cache.size() < m_amount) packet_cache.resize(m_amount);
+
+ //encode type
+ MAKE_ROOM(1);
+ packet_cache[0] = p_set ? NETWORK_COMMAND_REMOTE_SET : NETWORK_COMMAND_REMOTE_CALL;
+ ofs += 1;
+
+ //encode ID
+ MAKE_ROOM(ofs + 4);
+ encode_uint32(psc->id, &(packet_cache[ofs]));
+ ofs += 4;
+
+ //encode function name
+ CharString name = String(p_name).utf8();
+ int len = encode_cstring(name.get_data(), NULL);
+ MAKE_ROOM(ofs + len);
+ encode_cstring(name.get_data(), &(packet_cache[ofs]));
+ ofs += len;
+
+ if (p_set) {
+ //set argument
+ Error err = encode_variant(*p_arg[0], NULL, len);
+ ERR_FAIL_COND(err != OK);
+ MAKE_ROOM(ofs + len);
+ encode_variant(*p_arg[0], &(packet_cache[ofs]), len);
+ ofs += len;
+
+ } else {
+ //call arguments
+ MAKE_ROOM(ofs + 1);
+ packet_cache[ofs] = p_argcount;
+ ofs += 1;
+ for (int i = 0; i < p_argcount; i++) {
+ Error err = encode_variant(*p_arg[i], NULL, len);
+ ERR_FAIL_COND(err != OK);
+ MAKE_ROOM(ofs + len);
+ encode_variant(*p_arg[i], &(packet_cache[ofs]), len);
+ ofs += len;
+ }
+ }
+
+ //see if all peers have cached path (is so, call can be fast)
+ bool has_all_peers = _send_confirm_path(from_path, psc, p_to);
+
+ //take chance and set transfer mode, since all send methods will use it
+ network_peer->set_transfer_mode(p_unreliable ? NetworkedMultiplayerPeer::TRANSFER_MODE_UNRELIABLE : NetworkedMultiplayerPeer::TRANSFER_MODE_RELIABLE);
+
+ if (has_all_peers) {
+
+ //they all have verified paths, so send fast
+ network_peer->set_target_peer(p_to); //to all of you
+ network_peer->put_packet(packet_cache.ptr(), ofs); //a message with love
+ } else {
+ //not all verified path, so send one by one
+
+ //apend path at the end, since we will need it for some packets
+ CharString pname = String(from_path).utf8();
+ int path_len = encode_cstring(pname.get_data(), NULL);
+ MAKE_ROOM(ofs + path_len);
+ encode_cstring(pname.get_data(), &(packet_cache[ofs]));
+
+ for (Set<int>::Element *E = connected_peers.front(); E; E = E->next()) {
+
+ if (p_to < 0 && E->get() == -p_to)
+ continue; //continue, excluded
+
+ if (p_to > 0 && E->get() != p_to)
+ continue; //continue, not for this peer
+
+ Map<int, bool>::Element *F = psc->confirmed_peers.find(E->get());
+ ERR_CONTINUE(!F); //should never happen
+
+ network_peer->set_target_peer(E->get()); //to this one specifically
+
+ if (F->get() == true) {
+ //this one confirmed path, so use id
+ encode_uint32(psc->id, &(packet_cache[1]));
+ network_peer->put_packet(packet_cache.ptr(), ofs);
+ } else {
+ //this one did not confirm path yet, so use entire path (sorry!)
+ encode_uint32(0x80000000 | ofs, &(packet_cache[1])); //offset to path and flag
+ network_peer->put_packet(packet_cache.ptr(), ofs + path_len);
+ }
+ }
+ }
+}
+
+void MultiplayerAPI::add_peer(int p_id) {
+ connected_peers.insert(p_id);
+ path_get_cache.insert(p_id, PathGetCache());
+ emit_signal("network_peer_connected", p_id);
+}
+
+void MultiplayerAPI::del_peer(int p_id) {
+ connected_peers.erase(p_id);
+ path_get_cache.erase(p_id); //I no longer need your cache, sorry
+ emit_signal("network_peer_disconnected", p_id);
+}
+
+void MultiplayerAPI::connected_to_server() {
+
+ emit_signal("connected_to_server");
+}
+
+void MultiplayerAPI::connection_failed() {
+
+ emit_signal("connection_failed");
+}
+
+void MultiplayerAPI::server_disconnected() {
+
+ emit_signal("server_disconnected");
+}
+
+bool _should_call_native(Node::RPCMode mode, bool is_master, bool &r_skip_rpc) {
+
+ switch (mode) {
+
+ case Node::RPC_MODE_DISABLED: {
+ //do nothing
+ } break;
+ case Node::RPC_MODE_REMOTE: {
+ //do nothing also, no need to call local
+ } break;
+ case Node::RPC_MODE_SYNC: {
+ //call it, sync always results in call
+ return true;
+ } break;
+ case Node::RPC_MODE_MASTER: {
+ if (is_master)
+ r_skip_rpc = true; //no other master so..
+ return is_master;
+ } break;
+ case Node::RPC_MODE_SLAVE: {
+ return !is_master;
+ } break;
+ }
+ return false;
+}
+
+bool _should_call_script(ScriptInstance::RPCMode mode, bool is_master, bool &r_skip_rpc) {
+ switch (mode) {
+
+ case ScriptInstance::RPC_MODE_DISABLED: {
+ //do nothing
+ } break;
+ case ScriptInstance::RPC_MODE_REMOTE: {
+ //do nothing also, no need to call local
+ } break;
+ case ScriptInstance::RPC_MODE_SYNC: {
+ //call it, sync always results in call
+ return true;
+ } break;
+ case ScriptInstance::RPC_MODE_MASTER: {
+ if (is_master)
+ r_skip_rpc = true; //no other master so..
+ return is_master;
+ } break;
+ case ScriptInstance::RPC_MODE_SLAVE: {
+ return !is_master;
+ } break;
+ }
+ return false;
+}
+
+void MultiplayerAPI::rpcp(Node *p_node, int p_peer_id, bool p_unreliable, const StringName &p_method, const Variant **p_arg, int p_argcount) {
+
+ ERR_FAIL_COND(!p_node->is_inside_tree());
+ ERR_FAIL_COND(!network_peer.is_valid());
+
+ int node_id = network_peer->get_unique_id();
+ bool skip_rpc = false;
+ bool call_local_native = false;
+ bool call_local_script = false;
+ bool is_master = p_node->is_network_master();
+
+ if (p_peer_id == 0 || p_peer_id == node_id || (p_peer_id < 0 && p_peer_id != -node_id)) {
+ //check that send mode can use local call
+
+ const Map<StringName, Node::RPCMode>::Element *E = p_node->get_node_rpc_mode(p_method);
+ if (E) {
+ call_local_native = _should_call_native(E->get(), is_master, skip_rpc);
+ }
+
+ if (call_local_native) {
+ // done below
+ } else if (p_node->get_script_instance()) {
+ //attempt with script
+ ScriptInstance::RPCMode rpc_mode = p_node->get_script_instance()->get_rpc_mode(p_method);
+ call_local_script = _should_call_script(rpc_mode, is_master, skip_rpc);
+ }
+ }
+
+ if (!skip_rpc) {
+ _send_rpc(p_node, p_peer_id, p_unreliable, false, p_method, p_arg, p_argcount);
+ }
+
+ if (call_local_native) {
+ Variant::CallError ce;
+ p_node->call(p_method, p_arg, p_argcount, ce);
+ if (ce.error != Variant::CallError::CALL_OK) {
+ String error = Variant::get_call_error_text(p_node, p_method, p_arg, p_argcount, ce);
+ error = "rpc() aborted in local call: - " + error;
+ ERR_PRINTS(error);
+ return;
+ }
+ }
+
+ if (call_local_script) {
+ Variant::CallError ce;
+ ce.error = Variant::CallError::CALL_OK;
+ p_node->get_script_instance()->call(p_method, p_arg, p_argcount, ce);
+ if (ce.error != Variant::CallError::CALL_OK) {
+ String error = Variant::get_call_error_text(p_node, p_method, p_arg, p_argcount, ce);
+ error = "rpc() aborted in script local call: - " + error;
+ ERR_PRINTS(error);
+ return;
+ }
+ }
+}
+
+void MultiplayerAPI::rsetp(Node *p_node, int p_peer_id, bool p_unreliable, const StringName &p_property, const Variant &p_value) {
+
+ ERR_FAIL_COND(!p_node->is_inside_tree());
+ ERR_FAIL_COND(!network_peer.is_valid());
+
+ int node_id = network_peer->get_unique_id();
+ bool is_master = p_node->is_network_master();
+ bool skip_rset = false;
+
+ if (p_peer_id == 0 || p_peer_id == node_id || (p_peer_id < 0 && p_peer_id != -node_id)) {
+ //check that send mode can use local call
+
+ bool set_local = false;
+
+ const Map<StringName, Node::RPCMode>::Element *E = p_node->get_node_rset_mode(p_property);
+ if (E) {
+
+ set_local = _should_call_native(E->get(), is_master, skip_rset);
+ }
+
+ if (set_local) {
+ bool valid;
+ p_node->set(p_property, p_value, &valid);
+
+ if (!valid) {
+ String error = "rset() aborted in local set, property not found: - " + String(p_property);
+ ERR_PRINTS(error);
+ return;
+ }
+ } else if (p_node->get_script_instance()) {
+ //attempt with script
+ ScriptInstance::RPCMode rpc_mode = p_node->get_script_instance()->get_rset_mode(p_property);
+
+ set_local = _should_call_script(rpc_mode, is_master, skip_rset);
+
+ if (set_local) {
+
+ bool valid = p_node->get_script_instance()->set(p_property, p_value);
+
+ if (!valid) {
+ String error = "rset() aborted in local script set, property not found: - " + String(p_property);
+ ERR_PRINTS(error);
+ return;
+ }
+ }
+ }
+ }
+
+ if (skip_rset)
+ return;
+
+ const Variant *vptr = &p_value;
+
+ _send_rpc(p_node, p_peer_id, p_unreliable, true, p_property, &vptr, 1);
+}
+
+int MultiplayerAPI::get_network_unique_id() const {
+
+ ERR_FAIL_COND_V(!network_peer.is_valid(), 0);
+ return network_peer->get_unique_id();
+}
+
+bool MultiplayerAPI::is_network_server() const {
+
+ ERR_FAIL_COND_V(!network_peer.is_valid(), false);
+ return network_peer->is_server();
+}
+
+void MultiplayerAPI::set_refuse_new_network_connections(bool p_refuse) {
+
+ ERR_FAIL_COND(!network_peer.is_valid());
+ network_peer->set_refuse_new_connections(p_refuse);
+}
+
+bool MultiplayerAPI::is_refusing_new_network_connections() const {
+
+ ERR_FAIL_COND_V(!network_peer.is_valid(), false);
+ return network_peer->is_refusing_new_connections();
+}
+
+Vector<int> MultiplayerAPI::get_network_connected_peers() const {
+
+ ERR_FAIL_COND_V(!network_peer.is_valid(), Vector<int>());
+
+ Vector<int> ret;
+ for (Set<int>::Element *E = connected_peers.front(); E; E = E->next()) {
+ ret.push_back(E->get());
+ }
+
+ return ret;
+}
+
+void MultiplayerAPI::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_root_node", "node"), &MultiplayerAPI::set_root_node);
+ ClassDB::bind_method(D_METHOD("has_network_peer"), &MultiplayerAPI::has_network_peer);
+ ClassDB::bind_method(D_METHOD("get_network_peer"), &MultiplayerAPI::get_network_peer);
+ ClassDB::bind_method(D_METHOD("get_network_unique_id"), &MultiplayerAPI::get_network_unique_id);
+ ClassDB::bind_method(D_METHOD("is_network_server"), &MultiplayerAPI::is_network_server);
+ ClassDB::bind_method(D_METHOD("get_rpc_sender_id"), &MultiplayerAPI::get_rpc_sender_id);
+ ClassDB::bind_method(D_METHOD("add_peer", "id"), &MultiplayerAPI::add_peer);
+ ClassDB::bind_method(D_METHOD("del_peer", "id"), &MultiplayerAPI::del_peer);
+ ClassDB::bind_method(D_METHOD("set_network_peer", "peer"), &MultiplayerAPI::set_network_peer);
+ ClassDB::bind_method(D_METHOD("poll"), &MultiplayerAPI::poll);
+ ClassDB::bind_method(D_METHOD("clear"), &MultiplayerAPI::clear);
+
+ ClassDB::bind_method(D_METHOD("connected_to_server"), &MultiplayerAPI::connected_to_server);
+ ClassDB::bind_method(D_METHOD("connection_failed"), &MultiplayerAPI::connection_failed);
+ ClassDB::bind_method(D_METHOD("server_disconnected"), &MultiplayerAPI::server_disconnected);
+ ClassDB::bind_method(D_METHOD("get_network_connected_peers"), &MultiplayerAPI::get_network_connected_peers);
+ ClassDB::bind_method(D_METHOD("set_refuse_new_network_connections", "refuse"), &MultiplayerAPI::set_refuse_new_network_connections);
+ ClassDB::bind_method(D_METHOD("is_refusing_new_network_connections"), &MultiplayerAPI::is_refusing_new_network_connections);
+ 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_SIGNAL(MethodInfo("network_peer_connected", PropertyInfo(Variant::INT, "id")));
+ ADD_SIGNAL(MethodInfo("network_peer_disconnected", PropertyInfo(Variant::INT, "id")));
+ ADD_SIGNAL(MethodInfo("connected_to_server"));
+ ADD_SIGNAL(MethodInfo("connection_failed"));
+ ADD_SIGNAL(MethodInfo("server_disconnected"));
+}
+
+MultiplayerAPI::MultiplayerAPI() {
+ clear();
+}
+
+MultiplayerAPI::~MultiplayerAPI() {
+ clear();
+}
diff --git a/core/io/multiplayer_api.h b/core/io/multiplayer_api.h
new file mode 100644
index 0000000000..e7c6ffbea6
--- /dev/null
+++ b/core/io/multiplayer_api.h
@@ -0,0 +1,87 @@
+#ifndef MULTIPLAYER_PROTOCOL_H
+#define MULTIPLAYER_PROTOCOL_H
+
+#include "core/io/networked_multiplayer_peer.h"
+#include "core/reference.h"
+
+class MultiplayerAPI : public Reference {
+
+ GDCLASS(MultiplayerAPI, Reference);
+
+private:
+ //path sent caches
+ struct PathSentCache {
+ Map<int, bool> confirmed_peers;
+ int id;
+ };
+
+ //path get caches
+ struct PathGetCache {
+ struct NodeInfo {
+ NodePath path;
+ ObjectID instance;
+ };
+
+ Map<int, NodeInfo> nodes;
+ };
+
+ Ref<NetworkedMultiplayerPeer> network_peer;
+ int rpc_sender_id;
+ Set<int> connected_peers;
+ HashMap<NodePath, PathSentCache> path_send_cache;
+ Map<int, PathGetCache> path_get_cache;
+ int last_send_cache_id;
+ Vector<uint8_t> packet_cache;
+ Node *root_node;
+
+protected:
+ static void _bind_methods();
+
+ void _process_packet(int p_from, const uint8_t *p_packet, int p_packet_len);
+ void _process_simplify_path(int p_from, const uint8_t *p_packet, int p_packet_len);
+ void _process_confirm_path(int p_from, const uint8_t *p_packet, int p_packet_len);
+ Node *_process_get_node(int p_from, const uint8_t *p_packet, int p_packet_len);
+ void _process_rpc(Node *p_node, const StringName &p_name, int p_from, const uint8_t *p_packet, int p_packet_len, int p_offset);
+ void _process_rset(Node *p_node, const StringName &p_name, int p_from, const uint8_t *p_packet, int p_packet_len, int p_offset);
+
+ void _send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p_set, const StringName &p_name, const Variant **p_arg, int p_argcount);
+ bool _send_confirm_path(NodePath p_path, PathSentCache *psc, int p_from);
+
+public:
+ enum NetworkCommands {
+ NETWORK_COMMAND_REMOTE_CALL,
+ NETWORK_COMMAND_REMOTE_SET,
+ NETWORK_COMMAND_SIMPLIFY_PATH,
+ NETWORK_COMMAND_CONFIRM_PATH,
+ };
+
+ void poll();
+ void clear();
+ void set_root_node(Node *p_node);
+ void set_network_peer(const Ref<NetworkedMultiplayerPeer> &p_peer);
+ Ref<NetworkedMultiplayerPeer> get_network_peer() const;
+
+ // Called by Node.rpc
+ void rpcp(Node *p_node, int p_peer_id, bool p_unreliable, const StringName &p_method, const Variant **p_arg, int p_argcount);
+ // Called by Node.rset
+ void rsetp(Node *p_node, int p_peer_id, bool p_unreliable, const StringName &p_property, const Variant &p_value);
+
+ void add_peer(int p_id);
+ void del_peer(int p_id);
+ void connected_to_server();
+ void connection_failed();
+ void server_disconnected();
+
+ bool has_network_peer() const { return network_peer.is_valid(); }
+ Vector<int> get_network_connected_peers() const;
+ int get_rpc_sender_id() const { return rpc_sender_id; }
+ int get_network_unique_id() const;
+ bool is_network_server() const;
+ void set_refuse_new_network_connections(bool p_refuse);
+ bool is_refusing_new_network_connections() const;
+
+ MultiplayerAPI();
+ ~MultiplayerAPI();
+};
+
+#endif // MULTIPLAYER_PROTOCOL_H
diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp
index 15c4835dc6..0c626c197b 100644
--- a/core/io/resource_format_binary.cpp
+++ b/core/io/resource_format_binary.cpp
@@ -1124,7 +1124,7 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons
DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
da->remove(p_path + ".depren");
memdelete(da);
- //fuck it, use the old approach;
+ //use the old approach
WARN_PRINT(("This file is old, so it can't refactor dependencies, opening and resaving: " + p_path).utf8().get_data());
@@ -1162,9 +1162,11 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons
ERR_FAIL_V(ERR_FILE_UNRECOGNIZED);
}
- fw->store_32(VERSION_MAJOR); //current version
- fw->store_32(VERSION_MINOR);
- fw->store_32(FORMAT_VERSION);
+ // Since we're not actually converting the file contents, leave the version
+ // numbers in the file untouched.
+ fw->store_32(ver_major);
+ fw->store_32(ver_minor);
+ fw->store_32(ver_format);
save_ustring(fw, get_ustring(f)); //type
diff --git a/core/io/stream_peer.cpp b/core/io/stream_peer.cpp
index f6c4948fc3..927b9f6366 100644
--- a/core/io/stream_peer.cpp
+++ b/core/io/stream_peer.cpp
@@ -310,7 +310,7 @@ float StreamPeer::get_float() {
return decode_float(buf);
}
-float StreamPeer::get_double() {
+double StreamPeer::get_double() {
uint8_t buf[8];
get_data(buf, 8);
diff --git a/core/io/stream_peer.h b/core/io/stream_peer.h
index ff9ae788ec..605b0a7980 100644
--- a/core/io/stream_peer.h
+++ b/core/io/stream_peer.h
@@ -83,7 +83,7 @@ public:
uint64_t get_u64();
int64_t get_64();
float get_float();
- float get_double();
+ double get_double();
String get_string(int p_bytes);
String get_utf8_string(int p_bytes);
Variant get_var();
diff --git a/core/io/stream_peer_ssl.cpp b/core/io/stream_peer_ssl.cpp
index 633b353102..012ba78c6d 100644
--- a/core/io/stream_peer_ssl.cpp
+++ b/core/io/stream_peer_ssl.cpp
@@ -29,6 +29,8 @@
/*************************************************************************/
#include "stream_peer_ssl.h"
+#include "os/file_access.h"
+#include "project_settings.h"
StreamPeerSSL *(*StreamPeerSSL::_create)() = NULL;
@@ -50,8 +52,38 @@ bool StreamPeerSSL::is_available() {
return available;
}
+PoolByteArray StreamPeerSSL::get_project_cert_array() {
+
+ PoolByteArray out;
+ String certs_path = GLOBAL_DEF("network/ssl/certificates", "");
+ ProjectSettings::get_singleton()->set_custom_property_info("network/ssl/certificates", PropertyInfo(Variant::STRING, "network/ssl/certificates", PROPERTY_HINT_FILE, "*.crt"));
+
+ if (certs_path != "") {
+
+ FileAccess *f = FileAccess::open(certs_path, FileAccess::READ);
+ if (f) {
+ int flen = f->get_len();
+ out.resize(flen + 1);
+ {
+ PoolByteArray::Write w = out.write();
+ f->get_buffer(w.ptr(), flen);
+ w[flen] = 0; //end f string
+ }
+
+ memdelete(f);
+
+#ifdef DEBUG_ENABLED
+ print_line("Loaded certs from '" + certs_path);
+#endif
+ }
+ }
+
+ return out;
+}
+
void StreamPeerSSL::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("poll"), &StreamPeerSSL::poll);
ClassDB::bind_method(D_METHOD("accept_stream", "stream"), &StreamPeerSSL::accept_stream);
ClassDB::bind_method(D_METHOD("connect_to_stream", "stream", "validate_certs", "for_hostname"), &StreamPeerSSL::connect_to_stream, DEFVAL(false), DEFVAL(String()));
ClassDB::bind_method(D_METHOD("get_status"), &StreamPeerSSL::get_status);
diff --git a/core/io/stream_peer_ssl.h b/core/io/stream_peer_ssl.h
index e4d14ebdfd..77301a7c87 100644
--- a/core/io/stream_peer_ssl.h
+++ b/core/io/stream_peer_ssl.h
@@ -57,6 +57,7 @@ public:
STATUS_ERROR_HOSTNAME_MISMATCH
};
+ virtual void poll() = 0;
virtual Error accept_stream(Ref<StreamPeer> p_base) = 0;
virtual Error connect_to_stream(Ref<StreamPeer> p_base, bool p_validate_certs = false, const String &p_for_hostname = String()) = 0;
virtual Status get_status() const = 0;
@@ -65,6 +66,7 @@ public:
static StreamPeerSSL *create();
+ static PoolByteArray get_project_cert_array();
static void load_certs_from_memory(const PoolByteArray &p_memory);
static bool is_available();
diff --git a/core/make_binders.py b/core/make_binders.py
index 6f42c6e8eb..6a7602cd5d 100644
--- a/core/make_binders.py
+++ b/core/make_binders.py
@@ -244,7 +244,7 @@ def make_version(template, nargs, argmax, const, ret):
def run(target, source, env):
- versions = 11
+ versions = 13
versions_ext = 6
text = ""
text_ext = ""
@@ -265,10 +265,8 @@ def run(target, source, env):
else:
text += t
- f = open(target[0].path, "w")
- f.write(text)
- f.close()
+ with open(target[0].path, "w") as f:
+ f.write(text)
- f = open(target[1].path, "w")
- f.write(text_ext)
- f.close()
+ with open(target[1].path, "w") as f:
+ f.write(text_ext)
diff --git a/core/map.h b/core/map.h
index 5ff269c26b..700d4b8693 100644
--- a/core/map.h
+++ b/core/map.h
@@ -197,7 +197,7 @@ private:
if (node->right != _data._nil) {
node = node->right;
- while (node->left != _data._nil) { /* returns the minium of the right subtree of node */
+ while (node->left != _data._nil) { /* returns the minimum of the right subtree of node */
node = node->left;
}
return node;
@@ -219,7 +219,7 @@ private:
if (node->left != _data._nil) {
node = node->left;
- while (node->right != _data._nil) { /* returns the minium of the left subtree of node */
+ while (node->right != _data._nil) { /* returns the minimum of the left subtree of node */
node = node->right;
}
return node;
diff --git a/core/math/math_2d.cpp b/core/math/math_2d.cpp
index d2e4101999..3767d298a1 100644
--- a/core/math/math_2d.cpp
+++ b/core/math/math_2d.cpp
@@ -98,11 +98,6 @@ real_t Vector2::cross(const Vector2 &p_other) const {
return x * p_other.y - y * p_other.x;
}
-Vector2 Vector2::cross(real_t p_other) const {
-
- return Vector2(p_other * y, -p_other * x);
-}
-
Vector2 Vector2::floor() const {
return Vector2(Math::floor(x), Math::floor(y));
diff --git a/core/math/math_2d.h b/core/math/math_2d.h
index 8928349a44..e7188da85b 100644
--- a/core/math/math_2d.h
+++ b/core/math/math_2d.h
@@ -104,7 +104,6 @@ struct Vector2 {
real_t dot(const Vector2 &p_other) const;
real_t cross(const Vector2 &p_other) const;
- Vector2 cross(real_t p_other) const;
Vector2 project(const Vector2 &p_vec) const;
Vector2 plane_project(real_t p_d, const Vector2 &p_vec) const;
@@ -304,7 +303,7 @@ struct Rect2 {
inline real_t distance_to(const Vector2 &p_point) const {
- real_t dist;
+ real_t dist = 0.0;
bool inside = true;
if (p_point.x < position.x) {
diff --git a/core/math/math_funcs.cpp b/core/math/math_funcs.cpp
index f060a8e4ab..5c8512d8bd 100644
--- a/core/math/math_funcs.cpp
+++ b/core/math/math_funcs.cpp
@@ -177,18 +177,3 @@ float Math::random(float from, float to) {
float ret = (float)r / (float)RANDOM_MAX;
return (ret) * (to - from) + from;
}
-
-int Math::wrapi(int value, int min, int max) {
- --max;
- int rng = max - min + 1;
- value = ((value - min) % rng);
- if (value < 0)
- return max + 1 + value;
- else
- return min + value;
-}
-
-float Math::wrapf(float value, float min, float max) {
- float rng = max - min;
- return min + (value - min) - (rng * floor((value - min) / rng));
-}
diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h
index e15abc6b50..26e87f009b 100644
--- a/core/math/math_funcs.h
+++ b/core/math/math_funcs.h
@@ -209,8 +209,18 @@ public:
static _ALWAYS_INLINE_ double round(double p_val) { return (p_val >= 0) ? Math::floor(p_val + 0.5) : -Math::floor(-p_val + 0.5); }
static _ALWAYS_INLINE_ float round(float p_val) { return (p_val >= 0) ? Math::floor(p_val + 0.5) : -Math::floor(-p_val + 0.5); }
- static int wrapi(int value, int min, int max);
- static float wrapf(float value, float min, float max);
+ static _ALWAYS_INLINE_ int wrapi(int value, int min, int max) {
+ int rng = max - min;
+ return min + ((((value - min) % rng) + rng) % rng);
+ }
+ static _ALWAYS_INLINE_ double wrapf(double value, double min, double max) {
+ double rng = max - min;
+ return min + (value - min) - (rng * Math::floor((value - min) / rng));
+ }
+ static _ALWAYS_INLINE_ float wrapf(float value, float min, float max) {
+ float rng = max - min;
+ return min + (value - min) - (rng * Math::floor((value - min) / rng));
+ }
// double only, as these functions are mainly used by the editor and not performance-critical,
static double ease(double p_x, double p_c);
diff --git a/core/math/triangulate.cpp b/core/math/triangulate.cpp
index 5bae74ac7e..563ba7268f 100644
--- a/core/math/triangulate.cpp
+++ b/core/math/triangulate.cpp
@@ -51,7 +51,8 @@ real_t Triangulate::get_area(const Vector<Vector2> &contour) {
bool Triangulate::is_inside_triangle(real_t Ax, real_t Ay,
real_t Bx, real_t By,
real_t Cx, real_t Cy,
- real_t Px, real_t Py)
+ real_t Px, real_t Py,
+ bool include_edges)
{
real_t ax, ay, bx, by, cx, cy, apx, apy, bpx, bpy, cpx, cpy;
@@ -74,10 +75,14 @@ bool Triangulate::is_inside_triangle(real_t Ax, real_t Ay,
cCROSSap = cx * apy - cy * apx;
bCROSScp = bx * cpy - by * cpx;
- return ((aCROSSbp > 0.0) && (bCROSScp > 0.0) && (cCROSSap > 0.0));
+ if (include_edges) {
+ return ((aCROSSbp > 0.0) && (bCROSScp > 0.0) && (cCROSSap > 0.0));
+ } else {
+ return ((aCROSSbp >= 0.0) && (bCROSScp >= 0.0) && (cCROSSap >= 0.0));
+ }
};
-bool Triangulate::snip(const Vector<Vector2> &p_contour, int u, int v, int w, int n, const Vector<int> &V) {
+bool Triangulate::snip(const Vector<Vector2> &p_contour, int u, int v, int w, int n, const Vector<int> &V, bool relaxed) {
int p;
real_t Ax, Ay, Bx, By, Cx, Cy, Px, Py;
const Vector2 *contour = &p_contour[0];
@@ -91,13 +96,20 @@ bool Triangulate::snip(const Vector<Vector2> &p_contour, int u, int v, int w, in
Cx = contour[V[w]].x;
Cy = contour[V[w]].y;
- if (CMP_EPSILON > (((Bx - Ax) * (Cy - Ay)) - ((By - Ay) * (Cx - Ax)))) return false;
+ // It can happen that the triangulation ends up with three aligned vertices to deal with.
+ // In this scenario, making the check below strict may reject the possibility of
+ // forming a last triangle with these aligned vertices, preventing the triangulatiom
+ // from completing.
+ // To avoid that we allow zero-area triangles if all else failed.
+ float threshold = relaxed ? -CMP_EPSILON : CMP_EPSILON;
+
+ if (threshold > (((Bx - Ax) * (Cy - Ay)) - ((By - Ay) * (Cx - Ax)))) return false;
for (p = 0; p < n; p++) {
if ((p == u) || (p == v) || (p == w)) continue;
Px = contour[V[p]].x;
Py = contour[V[p]].y;
- if (is_inside_triangle(Ax, Ay, Bx, By, Cx, Cy, Px, Py)) return false;
+ if (is_inside_triangle(Ax, Ay, Bx, By, Cx, Cy, Px, Py, relaxed)) return false;
}
return true;
@@ -121,6 +133,8 @@ bool Triangulate::triangulate(const Vector<Vector2> &contour, Vector<int> &resul
for (int v = 0; v < n; v++)
V[v] = (n - 1) - v;
+ bool relaxed = false;
+
int nv = n;
/* remove nv-2 Vertices, creating 1 triangle every time */
@@ -129,8 +143,20 @@ bool Triangulate::triangulate(const Vector<Vector2> &contour, Vector<int> &resul
for (int v = nv - 1; nv > 2;) {
/* if we loop, it is probably a non-simple polygon */
if (0 >= (count--)) {
- //** Triangulate: ERROR - probable bad polygon!
- return false;
+ if (relaxed) {
+ //** Triangulate: ERROR - probable bad polygon!
+ return false;
+ } else {
+ // There may be aligned vertices that the strict
+ // checks prevent from triangulating. In this situation
+ // we are better off adding flat triangles than
+ // failing, so we relax the checks and try one last
+ // round.
+ // Only relaxing the constraints as a last resort avoids
+ // degenerate triangles when they aren't necessary.
+ count = 2 * nv;
+ relaxed = true;
+ }
}
/* three consecutive vertices in current polygon, <u,v,w> */
@@ -141,7 +167,7 @@ bool Triangulate::triangulate(const Vector<Vector2> &contour, Vector<int> &resul
int w = v + 1;
if (nv <= w) w = 0; /* next */
- if (snip(contour, u, v, w, nv, V)) {
+ if (snip(contour, u, v, w, nv, V, relaxed)) {
int a, b, c, s, t;
/* true names of the vertices */
diff --git a/core/math/triangulate.h b/core/math/triangulate.h
index e336dc5756..b1a583d0c5 100644
--- a/core/math/triangulate.h
+++ b/core/math/triangulate.h
@@ -51,10 +51,11 @@ public:
static bool is_inside_triangle(real_t Ax, real_t Ay,
real_t Bx, real_t By,
real_t Cx, real_t Cy,
- real_t Px, real_t Py);
+ real_t Px, real_t Py,
+ bool include_edges);
private:
- static bool snip(const Vector<Vector2> &p_contour, int u, int v, int w, int n, const Vector<int> &V);
+ static bool snip(const Vector<Vector2> &p_contour, int u, int v, int w, int n, const Vector<int> &V, bool relaxed);
};
#endif
diff --git a/core/message_queue.cpp b/core/message_queue.cpp
index 3ceafe1a30..25ee6eafae 100644
--- a/core/message_queue.cpp
+++ b/core/message_queue.cpp
@@ -278,7 +278,7 @@ void MessageQueue::flush() {
while (read_pos < buffer_end) {
- //lock on each interation, so a call can re-add itself to the message queue
+ //lock on each iteration, so a call can re-add itself to the message queue
Message *message = (Message *)&buffer[read_pos];
diff --git a/core/os/dir_access.cpp b/core/os/dir_access.cpp
index 1941b82602..330a9153ef 100644
--- a/core/os/dir_access.cpp
+++ b/core/os/dir_access.cpp
@@ -301,8 +301,8 @@ Error DirAccess::copy(String p_from, String p_to, int p_chmod_flags) {
FileAccess *fsrc = FileAccess::open(p_from, FileAccess::READ, &err);
if (err) {
-
- ERR_FAIL_COND_V(err, err);
+ ERR_PRINTS("Failed to open " + p_from);
+ return err;
}
FileAccess *fdst = FileAccess::open(p_to, FileAccess::WRITE, &err);
@@ -310,7 +310,8 @@ Error DirAccess::copy(String p_from, String p_to, int p_chmod_flags) {
fsrc->close();
memdelete(fsrc);
- ERR_FAIL_COND_V(err, err);
+ ERR_PRINTS("Failed to open " + p_to);
+ return err;
}
fsrc->seek_end(0);
diff --git a/core/os/file_access.h b/core/os/file_access.h
index 5d10c1a9aa..c4635fdfbb 100644
--- a/core/os/file_access.h
+++ b/core/os/file_access.h
@@ -89,6 +89,9 @@ public:
virtual void close() = 0; ///< close a file
virtual bool is_open() const = 0; ///< true when file is open
+ virtual String get_path() const { return ""; } /// returns the path for the current open file
+ virtual String get_path_absolute() const { return ""; } /// returns the absolute path for the current open file
+
virtual void seek(size_t p_position) = 0; ///< seek to a given position
virtual void seek_end(int64_t p_position = 0) = 0; ///< seek from the end of file
virtual size_t get_position() const = 0; ///< get position in the file
diff --git a/core/os/input.cpp b/core/os/input.cpp
index 3089ab2ce3..1d7cd7c791 100644
--- a/core/os/input.cpp
+++ b/core/os/input.cpp
@@ -111,7 +111,7 @@ void Input::_bind_methods() {
BIND_ENUM_CONSTANT(CURSOR_HSPLIT);
BIND_ENUM_CONSTANT(CURSOR_HELP);
- ADD_SIGNAL(MethodInfo("joy_connection_changed", PropertyInfo(Variant::INT, "index"), PropertyInfo(Variant::BOOL, "connected")));
+ ADD_SIGNAL(MethodInfo("joy_connection_changed", PropertyInfo(Variant::INT, "device"), PropertyInfo(Variant::BOOL, "connected")));
}
void Input::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
diff --git a/core/os/input_event.cpp b/core/os/input_event.cpp
index 12060f31df..b9607632f7 100644
--- a/core/os/input_event.cpp
+++ b/core/os/input_event.cpp
@@ -962,6 +962,11 @@ Ref<InputEvent> InputEventMagnifyGesture::xformed_by(const Transform2D &p_xform,
return ev;
}
+String InputEventMagnifyGesture::as_text() const {
+
+ return "InputEventMagnifyGesture : factor=" + rtos(get_factor()) + ", position=(" + String(get_position()) + ")";
+}
+
void InputEventMagnifyGesture::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_factor", "factor"), &InputEventMagnifyGesture::set_factor);
@@ -999,6 +1004,11 @@ Ref<InputEvent> InputEventPanGesture::xformed_by(const Transform2D &p_xform, con
return ev;
}
+String InputEventPanGesture::as_text() const {
+
+ return "InputEventPanGesture : delta=(" + String(get_delta()) + "), position=(" + String(get_position()) + ")";
+}
+
void InputEventPanGesture::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_delta", "delta"), &InputEventPanGesture::set_delta);
diff --git a/core/os/input_event.h b/core/os/input_event.h
index ad754d0d1f..0a33ab18a7 100644
--- a/core/os/input_event.h
+++ b/core/os/input_event.h
@@ -494,6 +494,7 @@ public:
real_t get_factor() const;
virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const;
+ virtual String as_text() const;
InputEventMagnifyGesture();
};
@@ -511,6 +512,7 @@ public:
Vector2 get_delta() const;
virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const;
+ virtual String as_text() const;
InputEventPanGesture();
};
diff --git a/core/os/keyboard.cpp b/core/os/keyboard.cpp
index fa53cc85c8..9dfc91e308 100644
--- a/core/os/keyboard.cpp
+++ b/core/os/keyboard.cpp
@@ -461,99 +461,6 @@ const char *find_keycode_name(int p_keycode) {
return "";
}
-struct _KeyCodeReplace {
- int from;
- int to;
-};
-
-static const _KeyCodeReplace _keycode_replace_qwertz[] = {
- { KEY_Y, KEY_Z },
- { KEY_Z, KEY_Y },
- { 0, 0 }
-};
-
-static const _KeyCodeReplace _keycode_replace_azerty[] = {
- { KEY_W, KEY_Z },
- { KEY_Z, KEY_W },
- { KEY_A, KEY_Q },
- { KEY_Q, KEY_A },
- { KEY_SEMICOLON, KEY_M },
- { KEY_M, KEY_SEMICOLON },
- { 0, 0 }
-};
-
-static const _KeyCodeReplace _keycode_replace_qzerty[] = {
- { KEY_W, KEY_Z },
- { KEY_Z, KEY_W },
- { KEY_SEMICOLON, KEY_M },
- { KEY_M, KEY_SEMICOLON },
- { 0, 0 }
-};
-
-static const _KeyCodeReplace _keycode_replace_dvorak[] = {
- { KEY_UNDERSCORE, KEY_BRACELEFT },
- { KEY_EQUAL, KEY_BRACERIGHT },
- { KEY_Q, KEY_APOSTROPHE },
- { KEY_W, KEY_COMMA },
- { KEY_E, KEY_PERIOD },
- { KEY_R, KEY_P },
- { KEY_T, KEY_Y },
- { KEY_Y, KEY_F },
- { KEY_U, KEY_G },
- { KEY_I, KEY_C },
- { KEY_O, KEY_R },
- { KEY_P, KEY_L },
- { KEY_BRACELEFT, KEY_SLASH },
- { KEY_BRACERIGHT, KEY_EQUAL },
- { KEY_A, KEY_A },
- { KEY_S, KEY_O },
- { KEY_D, KEY_E },
- { KEY_F, KEY_U },
- { KEY_G, KEY_I },
- { KEY_H, KEY_D },
- { KEY_J, KEY_H },
- { KEY_K, KEY_T },
- { KEY_L, KEY_N },
- { KEY_SEMICOLON, KEY_S },
- { KEY_APOSTROPHE, KEY_UNDERSCORE },
- { KEY_Z, KEY_SEMICOLON },
- { KEY_X, KEY_Q },
- { KEY_C, KEY_J },
- { KEY_V, KEY_K },
- { KEY_B, KEY_X },
- { KEY_N, KEY_B },
- { KEY_M, KEY_M },
- { KEY_COMMA, KEY_W },
- { KEY_PERIOD, KEY_V },
- { KEY_SLASH, KEY_Z },
- { 0, 0 }
-};
-
-static const _KeyCodeReplace _keycode_replace_neo[] = {
- { 0, 0 }
-};
-
-static const _KeyCodeReplace _keycode_replace_colemak[] = {
- { KEY_E, KEY_F },
- { KEY_R, KEY_P },
- { KEY_T, KEY_G },
- { KEY_Y, KEY_J },
- { KEY_U, KEY_L },
- { KEY_I, KEY_U },
- { KEY_O, KEY_Y },
- { KEY_P, KEY_SEMICOLON },
- { KEY_S, KEY_R },
- { KEY_D, KEY_S },
- { KEY_F, KEY_T },
- { KEY_G, KEY_D },
- { KEY_J, KEY_N },
- { KEY_K, KEY_E },
- { KEY_L, KEY_I },
- { KEY_SEMICOLON, KEY_O },
- { KEY_N, KEY_K },
- { 0, 0 }
-};
-
int keycode_get_count() {
const _KeyCodeText *kct = &_keycodes[0];
@@ -574,31 +481,3 @@ int keycode_get_value_by_index(int p_index) {
const char *keycode_get_name_by_index(int p_index) {
return _keycodes[p_index].text;
}
-
-int latin_keyboard_keycode_convert(int p_keycode) {
-
- const _KeyCodeReplace *kcr = NULL;
- switch (OS::get_singleton()->get_latin_keyboard_variant()) {
-
- case OS::LATIN_KEYBOARD_QWERTY: return p_keycode; break;
- case OS::LATIN_KEYBOARD_QWERTZ: kcr = _keycode_replace_qwertz; break;
- case OS::LATIN_KEYBOARD_AZERTY: kcr = _keycode_replace_azerty; break;
- case OS::LATIN_KEYBOARD_QZERTY: kcr = _keycode_replace_qzerty; break;
- case OS::LATIN_KEYBOARD_DVORAK: kcr = _keycode_replace_dvorak; break;
- case OS::LATIN_KEYBOARD_NEO: kcr = _keycode_replace_neo; break;
- case OS::LATIN_KEYBOARD_COLEMAK: kcr = _keycode_replace_colemak; break;
- default: return p_keycode;
- }
-
- if (!kcr) {
- return p_keycode;
- }
-
- while (kcr->from) {
- if (kcr->from == p_keycode)
- return kcr->to;
- kcr++;
- }
-
- return p_keycode;
-}
diff --git a/core/os/keyboard.h b/core/os/keyboard.h
index 4c253fa4ce..a0e6f8b2ef 100644
--- a/core/os/keyboard.h
+++ b/core/os/keyboard.h
@@ -331,6 +331,5 @@ const char *find_keycode_name(int p_keycode);
int keycode_get_count();
int keycode_get_value_by_index(int p_index);
const char *keycode_get_name_by_index(int p_index);
-int latin_keyboard_keycode_convert(int p_keycode);
#endif
diff --git a/core/os/os.cpp b/core/os/os.cpp
index c6e5de703c..618a4bbac3 100644
--- a/core/os/os.cpp
+++ b/core/os/os.cpp
@@ -34,6 +34,7 @@
#include "input.h"
#include "os/file_access.h"
#include "project_settings.h"
+#include "servers/audio_server.h"
#include "version_generated.gen.h"
#include <stdarg.h>
@@ -616,6 +617,45 @@ bool OS::has_feature(const String &p_feature) {
return false;
}
+void OS::center_window() {
+
+ if (is_window_fullscreen()) return;
+
+ Size2 scr = get_screen_size(get_current_screen());
+ Size2 wnd = get_real_window_size();
+ int x = scr.width / 2 - wnd.width / 2;
+ int y = scr.height / 2 - wnd.height / 2;
+ set_window_position(Vector2(x, y));
+}
+
+int OS::get_video_driver_count() const {
+
+ return 2;
+}
+
+const char *OS::get_video_driver_name(int p_driver) const {
+
+ switch (p_driver) {
+ case VIDEO_DRIVER_GLES2:
+ return "GLES2";
+ case VIDEO_DRIVER_GLES3:
+ default:
+ return "GLES3";
+ }
+}
+
+int OS::get_audio_driver_count() const {
+
+ return AudioDriverManager::get_driver_count();
+}
+
+const char *OS::get_audio_driver_name(int p_driver) const {
+
+ AudioDriver *driver = AudioDriverManager::get_driver(p_driver);
+ ERR_FAIL_COND_V(!driver, "");
+ return AudioDriverManager::get_driver(p_driver)->get_name();
+}
+
OS::OS() {
void *volatile stack_bottom;
diff --git a/core/os/os.h b/core/os/os.h
index 248e1dbefa..5a2c998782 100644
--- a/core/os/os.h
+++ b/core/os/os.h
@@ -44,6 +44,12 @@
@author Juan Linietsky <reduzio@gmail.com>
*/
+enum VideoDriver {
+ VIDEO_DRIVER_GLES3,
+ VIDEO_DRIVER_GLES2,
+ VIDEO_DRIVER_MAX,
+};
+
class OS {
static OS *singleton;
@@ -94,15 +100,17 @@ public:
bool resizable;
bool borderless_window;
bool maximized;
+ bool always_on_top;
bool use_vsync;
float get_aspect() const { return (float)width / (float)height; }
- VideoMode(int p_width = 1024, int p_height = 600, bool p_fullscreen = false, bool p_resizable = true, bool p_borderless_window = false, bool p_maximized = false, bool p_use_vsync = false) {
+ VideoMode(int p_width = 1024, int p_height = 600, bool p_fullscreen = false, bool p_resizable = true, bool p_borderless_window = false, bool p_maximized = false, bool p_always_on_top = false, bool p_use_vsync = false) {
width = p_width;
height = p_height;
fullscreen = p_fullscreen;
resizable = p_resizable;
borderless_window = p_borderless_window;
maximized = p_maximized;
+ always_on_top = p_always_on_top;
use_vsync = p_use_vsync;
}
};
@@ -113,12 +121,6 @@ protected:
RenderThreadMode _render_thread_mode;
// functions used by main to initialize/deintialize the OS
- virtual int get_video_driver_count() const = 0;
- virtual const char *get_video_driver_name(int p_driver) const = 0;
-
- virtual int get_audio_driver_count() const = 0;
- virtual const char *get_audio_driver_name(int p_driver) const = 0;
-
void add_logger(Logger *p_logger);
virtual void initialize_core() = 0;
@@ -173,6 +175,12 @@ public:
virtual VideoMode get_video_mode(int p_screen = 0) const = 0;
virtual void get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen = 0) const = 0;
+ virtual int get_video_driver_count() const;
+ virtual const char *get_video_driver_name(int p_driver) const;
+
+ virtual int get_audio_driver_count() const;
+ virtual const char *get_audio_driver_name(int p_driver) const;
+
virtual int get_screen_count() const { return 1; }
virtual int get_current_screen() const { return 0; }
virtual void set_current_screen(int p_screen) {}
@@ -182,6 +190,7 @@ public:
virtual Point2 get_window_position() const { return Vector2(); }
virtual void set_window_position(const Point2 &p_position) {}
virtual Size2 get_window_size() const = 0;
+ virtual Size2 get_real_window_size() const { return get_window_size(); }
virtual void set_window_size(const Size2 p_size) {}
virtual void set_window_fullscreen(bool p_enabled) {}
virtual bool is_window_fullscreen() const { return true; }
@@ -191,7 +200,10 @@ public:
virtual bool is_window_minimized() const { return false; }
virtual void set_window_maximized(bool p_enabled) {}
virtual bool is_window_maximized() const { return true; }
+ virtual void set_window_always_on_top(bool p_enabled) {}
+ virtual bool is_window_always_on_top() const { return false; }
virtual void request_attention() {}
+ virtual void center_window();
virtual void set_borderless_window(bool p_borderless) {}
virtual bool get_borderless_window() { return 0; }
diff --git a/core/os/thread_dummy.cpp b/core/os/thread_dummy.cpp
index fa0bb3dafd..b6371235c4 100644
--- a/core/os/thread_dummy.cpp
+++ b/core/os/thread_dummy.cpp
@@ -55,3 +55,11 @@ Semaphore *SemaphoreDummy::create() {
void SemaphoreDummy::make_default() {
Semaphore::create_func = &SemaphoreDummy::create;
};
+
+RWLock *RWLockDummy::create() {
+ return memnew(RWLockDummy);
+};
+
+void RWLockDummy::make_default() {
+ RWLock::create_func = &RWLockDummy::create;
+};
diff --git a/core/os/thread_dummy.h b/core/os/thread_dummy.h
index b67b52a726..74957b95fe 100644
--- a/core/os/thread_dummy.h
+++ b/core/os/thread_dummy.h
@@ -32,6 +32,7 @@
#define THREAD_DUMMY_H
#include "mutex.h"
+#include "rw_lock.h"
#include "semaphore.h"
#include "thread.h"
@@ -69,4 +70,20 @@ public:
static void make_default();
};
+class RWLockDummy : public RWLock {
+
+ static RWLock *create();
+
+public:
+ virtual void read_lock() {}
+ virtual void read_unlock() {}
+ virtual Error read_try_lock() { return OK; }
+
+ virtual void write_lock() {}
+ virtual void write_unlock() {}
+ virtual Error write_try_lock() { return OK; }
+
+ static void make_default();
+};
+
#endif
diff --git a/core/pool_allocator.cpp b/core/pool_allocator.cpp
index d81e1912bf..017586b92a 100644
--- a/core/pool_allocator.cpp
+++ b/core/pool_allocator.cpp
@@ -90,7 +90,7 @@ bool PoolAllocator::find_hole(EntryArrayPos *p_pos, int p_for_size) {
int hole_size = entry.pos - prev_entry_end_pos;
- /* detemine if what we want fits in that hole */
+ /* determine if what we want fits in that hole */
if (hole_size >= p_for_size) {
*p_pos = i;
return true;
@@ -100,7 +100,7 @@ bool PoolAllocator::find_hole(EntryArrayPos *p_pos, int p_for_size) {
prev_entry_end_pos = entry_end(entry);
}
- /* No holes between entrys, check at the end..*/
+ /* No holes between entries, check at the end..*/
if ((pool_size - prev_entry_end_pos) >= p_for_size) {
*p_pos = entry_count;
diff --git a/core/project_settings.cpp b/core/project_settings.cpp
index 0991c0df68..20d91e7940 100644
--- a/core/project_settings.cpp
+++ b/core/project_settings.cpp
@@ -268,12 +268,12 @@ Error ProjectSettings::setup(const String &p_path, const String &p_main_pack, bo
if (FileAccessNetworkClient::get_singleton()) {
- if (_load_settings("res://project.godot") == OK || _load_settings_binary("res://project.binary") == OK) {
-
- _load_settings("res://override.cfg");
+ Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary");
+ if (err == OK) {
+ // Optional, we don't mind if it fails
+ _load_settings_text("res://override.cfg");
}
-
- return OK;
+ return err;
}
String exec_path = OS::get_singleton()->get_executable_path();
@@ -285,12 +285,13 @@ Error ProjectSettings::setup(const String &p_path, const String &p_main_pack, bo
bool ok = _load_resource_pack(p_main_pack);
ERR_FAIL_COND_V(!ok, ERR_CANT_OPEN);
- if (_load_settings("res://project.godot") == OK || _load_settings_binary("res://project.binary") == OK) {
- //load override from location of the main pack
- _load_settings(p_main_pack.get_base_dir().plus_file("override.cfg"));
+ Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary");
+ if (err == OK) {
+ // Load override from location of the main pack
+ // Optional, we don't mind if it fails
+ _load_settings_text(p_main_pack.get_base_dir().plus_file("override.cfg"));
}
-
- return OK;
+ return err;
}
//Attempt with execname.pck
@@ -313,12 +314,13 @@ Error ProjectSettings::setup(const String &p_path, const String &p_main_pack, bo
// if we opened our package, try and load our project...
if (found) {
- if (_load_settings("res://project.godot") == OK || _load_settings_binary("res://project.binary") == OK) {
- // load override from location of executable
- _load_settings(exec_path.get_base_dir().plus_file("override.cfg"));
+ Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary");
+ if (err == OK) {
+ // Load override from location of executable
+ // Optional, we don't mind if it fails
+ _load_settings_text(exec_path.get_base_dir().plus_file("override.cfg"));
}
-
- return OK;
+ return err;
}
}
@@ -334,11 +336,13 @@ Error ProjectSettings::setup(const String &p_path, const String &p_main_pack, bo
// data.pck and data.zip are deprecated and no longer supported, apologies.
// make sure this is loaded from the resource path
- if (_load_settings("res://project.godot") == OK || _load_settings_binary("res://project.binary") == OK) {
- _load_settings("res://override.cfg");
+ Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary");
+ if (err == OK) {
+ // Optional, we don't mind if it fails
+ _load_settings_text("res://override.cfg");
}
- return OK;
+ return err;
}
//Nothing was found, try to find a project.godot somewhere!
@@ -350,20 +354,23 @@ Error ProjectSettings::setup(const String &p_path, const String &p_main_pack, bo
String candidate = d->get_current_dir();
String current_dir = d->get_current_dir();
+
bool found = false;
+ Error err;
while (true) {
- //try to load settings in ascending through dirs shape!
- if (_load_settings(current_dir + "/project.godot") == OK || _load_settings_binary(current_dir + "/project.binary") == OK) {
-
- _load_settings(current_dir + "/override.cfg");
+ err = _load_settings_text_or_binary(current_dir.plus_file("project.godot"), current_dir.plus_file("project.binary"));
+ if (err == OK) {
+ // Optional, we don't mind if it fails
+ _load_settings_text(current_dir.plus_file("override.cfg"));
candidate = current_dir;
found = true;
break;
}
if (p_upwards) {
+ // Try to load settings ascending through dirs shape!
d->change_dir("..");
if (d->get_current_dir() == current_dir)
break; //not doing anything useful
@@ -378,7 +385,7 @@ Error ProjectSettings::setup(const String &p_path, const String &p_main_pack, bo
memdelete(d);
if (!found)
- return ERR_FILE_NOT_FOUND;
+ return err;
if (resource_path.length() && resource_path[resource_path.length() - 1] == '/')
resource_path = resource_path.substr(0, resource_path.length() - 1); // chop end
@@ -440,13 +447,17 @@ Error ProjectSettings::_load_settings_binary(const String p_path) {
return OK;
}
-Error ProjectSettings::_load_settings(const String p_path) {
+
+Error ProjectSettings::_load_settings_text(const String p_path) {
Error err;
FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
- if (!f)
- return ERR_CANT_OPEN;
+ if (!f) {
+ // FIXME: Above 'err' error code is ERR_FILE_CANT_OPEN if the file is missing
+ // This needs to be streamlined if we want decent error reporting
+ return ERR_FILE_NOT_FOUND;
+ }
VariantParser::StreamFile stream;
stream.f = f;
@@ -471,7 +482,7 @@ Error ProjectSettings::_load_settings(const String p_path) {
memdelete(f);
return OK;
} else if (err != OK) {
- ERR_PRINTS("ProjectSettings::load - " + p_path + ":" + itos(lines) + " error: " + error_text);
+ ERR_PRINTS("Error parsing " + p_path + " at line " + itos(lines) + ": " + error_text + " File might be corrupted.");
memdelete(f);
return err;
}
@@ -497,6 +508,23 @@ Error ProjectSettings::_load_settings(const String p_path) {
return OK;
}
+Error ProjectSettings::_load_settings_text_or_binary(const String p_text_path, const String p_bin_path) {
+
+ // Attempt first to load the text-based project.godot file
+ Error err_text = _load_settings_text(p_text_path);
+ if (err_text == OK) {
+ return OK;
+ } else if (err_text != ERR_FILE_NOT_FOUND) {
+ // If the text-based file exists but can't be loaded, we want to know it
+ ERR_PRINTS("Couldn't load file '" + p_text_path + "', error code " + itos(err_text) + ".");
+ return err_text;
+ }
+
+ // Fallback to binary project.binary file if text-based was not found
+ Error err_bin = _load_settings_binary(p_bin_path);
+ return err_bin;
+}
+
int ProjectSettings::get_order(const String &p_name) const {
ERR_FAIL_COND_V(!props.has(p_name), -1);
@@ -525,7 +553,7 @@ void ProjectSettings::clear(const String &p_name) {
Error ProjectSettings::save() {
- return save_custom(get_resource_path() + "/project.godot");
+ return save_custom(get_resource_path().plus_file("project.godot"));
}
Error ProjectSettings::_save_settings_binary(const String &p_file, const Map<String, List<String> > &props, const CustomMap &p_custom, const String &p_custom_features) {
@@ -664,7 +692,10 @@ Error ProjectSettings::_save_settings_text(const String &p_file, const Map<Strin
String vstr;
VariantWriter::write_to_string(value, vstr);
- file->store_string(F->get() + "=" + vstr + "\n");
+ if (F->get().find(" ") != -1)
+ file->store_string(F->get().quote() + "=" + vstr + "\n");
+ else
+ file->store_string(F->get() + "=" + vstr + "\n");
}
}
@@ -999,6 +1030,20 @@ ProjectSettings::ProjectSettings() {
GLOBAL_DEF("input/ui_page_down", va);
input_presets.push_back("input/ui_page_down");
+ va = Array();
+ key.instance();
+ key->set_scancode(KEY_HOME);
+ va.push_back(key);
+ GLOBAL_DEF("input/ui_home", va);
+ input_presets.push_back("input/ui_home");
+
+ va = Array();
+ key.instance();
+ key->set_scancode(KEY_END);
+ va.push_back(key);
+ GLOBAL_DEF("input/ui_end", va);
+ input_presets.push_back("input/ui_end");
+
//GLOBAL_DEF("display/window/handheld/orientation", "landscape");
custom_prop_info["display/window/handheld/orientation"] = PropertyInfo(Variant::STRING, "display/window/handheld/orientation", PROPERTY_HINT_ENUM, "landscape,portrait,reverse_landscape,reverse_portrait,sensor_landscape,sensor_portrait,sensor");
diff --git a/core/project_settings.h b/core/project_settings.h
index eba53441cf..9b51bc3ac3 100644
--- a/core/project_settings.h
+++ b/core/project_settings.h
@@ -93,8 +93,9 @@ protected:
static ProjectSettings *singleton;
- Error _load_settings(const String p_path);
+ Error _load_settings_text(const String p_path);
Error _load_settings_binary(const String p_path);
+ Error _load_settings_text_or_binary(const String p_text_path, const String p_bin_path);
Error _save_settings_text(const String &p_file, const Map<String, List<String> > &props, const CustomMap &p_custom = CustomMap(), const String &p_custom_features = String());
Error _save_settings_binary(const String &p_file, const Map<String, List<String> > &props, const CustomMap &p_custom = CustomMap(), const String &p_custom_features = String());
diff --git a/core/reference.h b/core/reference.h
index a0bdb62258..0d6b1ced6e 100644
--- a/core/reference.h
+++ b/core/reference.h
@@ -63,7 +63,7 @@ public:
template <class T>
class Ref {
- T *reference = NULL;
+ T *reference;
void ref(const Ref &p_from) {
@@ -213,10 +213,9 @@ public:
Ref(T *p_reference) {
+ reference = NULL;
if (p_reference)
ref_pointer(p_reference);
- else
- reference = NULL;
}
Ref(const Variant &p_variant) {
diff --git a/core/register_core_types.cpp b/core/register_core_types.cpp
index 006459c5f6..2a611ccf6a 100644
--- a/core/register_core_types.cpp
+++ b/core/register_core_types.cpp
@@ -42,6 +42,7 @@
#include "io/config_file.h"
#include "io/http_client.h"
#include "io/marshalls.h"
+#include "io/multiplayer_api.h"
#include "io/networked_multiplayer_peer.h"
#include "io/packet_peer.h"
#include "io/packet_peer_udp.h"
@@ -145,6 +146,7 @@ void register_core_types() {
ClassDB::register_virtual_class<PacketPeer>();
ClassDB::register_class<PacketPeerStream>();
ClassDB::register_virtual_class<NetworkedMultiplayerPeer>();
+ ClassDB::register_class<MultiplayerAPI>();
ClassDB::register_class<MainLoop>();
//ClassDB::register_type<OptimizedSaver>();
ClassDB::register_class<Translation>();
diff --git a/core/resource.cpp b/core/resource.cpp
index 2eeed50d9d..179333aa14 100644
--- a/core/resource.cpp
+++ b/core/resource.cpp
@@ -226,7 +226,7 @@ Ref<Resource> Resource::duplicate(bool p_subresources) const {
if (!(E->get().usage & PROPERTY_USAGE_STORAGE))
continue;
- Variant p = get(E->get().name);
+ Variant p = get(E->get().name).duplicate(true);
if (p.get_type() == Variant::OBJECT && p_subresources) {
RES sr = p;
diff --git a/core/script_debugger_remote.cpp b/core/script_debugger_remote.cpp
index 41071ace5d..632285f48d 100644
--- a/core/script_debugger_remote.cpp
+++ b/core/script_debugger_remote.cpp
@@ -1016,11 +1016,11 @@ void ScriptDebuggerRemote::add_profiling_frame_data(const StringName &p_name, co
}
void ScriptDebuggerRemote::profiling_start() {
- //ignores this, uses it via connnection
+ //ignores this, uses it via connection
}
void ScriptDebuggerRemote::profiling_end() {
- //ignores this, uses it via connnection
+ //ignores this, uses it via connection
}
void ScriptDebuggerRemote::profiling_set_frame_times(float p_frame_time, float p_idle_time, float p_physics_time, float p_physics_frame_time) {
diff --git a/core/script_language.h b/core/script_language.h
index d1da0a3b72..0c1f99cea6 100644
--- a/core/script_language.h
+++ b/core/script_language.h
@@ -203,6 +203,7 @@ public:
virtual void make_template(const String &p_class_name, const String &p_base_class_name, Ref<Script> &p_script) {}
virtual bool is_using_templates() { return false; }
virtual bool validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path = "", List<String> *r_functions = NULL) const = 0;
+ virtual String validate_path(const String &p_path) const { return ""; }
virtual Script *create_script() const = 0;
virtual bool has_named_classes() const = 0;
virtual bool supports_builtin_mode() const = 0;
@@ -220,7 +221,9 @@ public:
RESULT_CLASS,
RESULT_CLASS_CONSTANT,
RESULT_CLASS_PROPERTY,
- RESULT_CLASS_METHOD
+ RESULT_CLASS_METHOD,
+ RESULT_CLASS_ENUM,
+ RESULT_CLASS_TBD_GLOBALSCOPE
};
Type type;
Ref<Script> script;
diff --git a/core/set.h b/core/set.h
index 4f17c953b1..d79dd81644 100644
--- a/core/set.h
+++ b/core/set.h
@@ -185,7 +185,7 @@ private:
if (node->right != _data._nil) {
node = node->right;
- while (node->left != _data._nil) { /* returns the minium of the right subtree of node */
+ while (node->left != _data._nil) { /* returns the minimum of the right subtree of node */
node = node->left;
}
return node;
@@ -207,7 +207,7 @@ private:
if (node->left != _data._nil) {
node = node->left;
- while (node->right != _data._nil) { /* returns the minium of the left subtree of node */
+ while (node->right != _data._nil) { /* returns the minimum of the left subtree of node */
node = node->right;
}
return node;
diff --git a/core/string_buffer.h b/core/string_buffer.h
index b148e45544..7e9b151bea 100644
--- a/core/string_buffer.h
+++ b/core/string_buffer.h
@@ -39,7 +39,7 @@ class StringBuffer {
CharType short_buffer[SHORT_BUFFER_SIZE];
String buffer;
- int string_length = 0;
+ int string_length;
_FORCE_INLINE_ CharType *current_buffer_ptr() {
return static_cast<Vector<CharType> &>(buffer).empty() ? short_buffer : buffer.ptrw();
@@ -79,6 +79,10 @@ public:
_FORCE_INLINE_ operator String() {
return as_string();
}
+
+ StringBuffer() {
+ string_length = 0;
+ }
};
template <int SHORT_BUFFER_SIZE>
diff --git a/core/string_builder.h b/core/string_builder.h
index 9e2599ac32..596b3bf730 100644
--- a/core/string_builder.h
+++ b/core/string_builder.h
@@ -37,7 +37,7 @@
class StringBuilder {
- uint32_t string_length = 0;
+ uint32_t string_length;
Vector<String> strings;
Vector<const char *> c_strings;
@@ -75,6 +75,10 @@ public:
_FORCE_INLINE_ operator String() const {
return as_string();
}
+
+ StringBuilder() {
+ string_length = 0;
+ }
};
#endif // STRING_BUILDER_H
diff --git a/core/translation.cpp b/core/translation.cpp
index 32096d2eab..aaa4de5912 100644
--- a/core/translation.cpp
+++ b/core/translation.cpp
@@ -34,6 +34,14 @@
#include "os/os.h"
#include "project_settings.h"
+// 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.
+//
+// References:
+// - https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
+// - https://lh.2xlibre.net/locales/
+
static const char *locale_list[] = {
"aa", // Afar
"aa_DJ", // Afar (Djibouti)
@@ -756,8 +764,17 @@ static const char *locale_names[] = {
0
};
+// Windows has some weird locale identifiers which do not honor the ISO 639-1
+// standardized nomenclature. Whenever those don't conflict with existing ISO
+// identifiers, we override them.
+//
+// Reference:
+// - https://msdn.microsoft.com/en-us/library/windows/desktop/ms693062(v=vs.85).aspx
+
static const char *locale_renames[][2] = {
- { "no", "nb" },
+ { "in", "id" }, // Indonesian
+ { "iw", "he" }, // Hebrew
+ { "no", "nb" }, // Norwegian Bokmål
{ NULL, NULL }
};
diff --git a/core/ustring.cpp b/core/ustring.cpp
index d445e4ed47..d749146998 100644
--- a/core/ustring.cpp
+++ b/core/ustring.cpp
@@ -1135,6 +1135,36 @@ String String::num_int64(int64_t p_num, int base, bool capitalize_hex) {
return s;
}
+String String::num_uint64(uint64_t p_num, int base, bool capitalize_hex) {
+
+ uint64_t n = p_num;
+
+ int chars = 0;
+ do {
+ n /= base;
+ chars++;
+ } while (n);
+
+ String s;
+ s.resize(chars + 1);
+ CharType *c = s.ptrw();
+ c[chars] = 0;
+ n = p_num;
+ do {
+ int mod = ABS(n % base);
+ if (mod >= 10) {
+ char a = (capitalize_hex ? 'A' : 'a');
+ c[--chars] = a + (mod - 10);
+ } else {
+ c[--chars] = '0' + mod;
+ }
+
+ n /= base;
+ } while (n);
+
+ return s;
+}
+
String String::num_real(double p_num) {
String s;
@@ -3135,11 +3165,11 @@ String String::word_wrap(int p_chars_per_line) const {
return ret;
}
-String String::http_escape() const {
+String String::percent_encode() const {
const CharString temp = utf8();
String res;
- for (int i = 0; i < length(); ++i) {
- CharType ord = temp[i];
+ for (int i = 0; i < temp.length(); ++i) {
+ char ord = temp[i];
if (ord == '.' || ord == '-' || ord == '_' || ord == '~' ||
(ord >= 'a' && ord <= 'z') ||
(ord >= 'A' && ord <= 'Z') ||
@@ -3148,9 +3178,9 @@ String String::http_escape() const {
} else {
char h_Val[3];
#if defined(__GNUC__) || defined(_MSC_VER)
- snprintf(h_Val, 3, "%.2X", ord);
+ snprintf(h_Val, 3, "%hhX", ord);
#else
- sprintf(h_Val, "%.2X", ord);
+ sprintf(h_Val, "%hhX", ord);
#endif
res += "%";
res += h_Val;
@@ -3159,7 +3189,7 @@ String String::http_escape() const {
return res;
}
-String String::http_unescape() const {
+String String::percent_decode() const {
String res;
for (int i = 0; i < length(); ++i) {
if (ord_at(i) == '%' && i + 2 < length()) {
@@ -3697,68 +3727,6 @@ String String::plus_file(const String &p_file) const {
return *this + "/" + p_file;
}
-String String::percent_encode() const {
-
- CharString cs = utf8();
- String encoded;
- for (int i = 0; i < cs.length(); i++) {
- uint8_t c = cs[i];
- if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '-' || c == '_' || c == '~' || c == '.') {
-
- char p[2] = { (char)c, 0 };
- encoded += p;
- } else {
- char p[4] = { '%', 0, 0, 0 };
- static const char hex[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
-
- p[1] = hex[c >> 4];
- p[2] = hex[c & 0xF];
- encoded += p;
- }
- }
-
- return encoded;
-}
-String String::percent_decode() const {
-
- CharString pe;
-
- CharString cs = utf8();
- for (int i = 0; i < cs.length(); i++) {
-
- uint8_t c = cs[i];
- if (c == '%' && i < length() - 2) {
-
- uint8_t a = LOWERCASE(cs[i + 1]);
- uint8_t b = LOWERCASE(cs[i + 2]);
-
- c = 0;
- if (a >= '0' && a <= '9')
- c = (a - '0') << 4;
- else if (a >= 'a' && a <= 'f')
- c = (a - 'a' + 10) << 4;
- else
- continue;
-
- uint8_t d = 0;
-
- if (b >= '0' && b <= '9')
- d = (b - '0');
- else if (b >= 'a' && b <= 'f')
- d = (b - 'a' + 10);
- else
- continue;
- c += d;
- i += 2;
- }
- pe.push_back(c);
- }
-
- pe.push_back(0);
-
- return String::utf8(pe.ptr());
-}
-
String String::get_basename() const {
int pos = find_last(".");
diff --git a/core/ustring.h b/core/ustring.h
index 90496b71b6..8023c9b95d 100644
--- a/core/ustring.h
+++ b/core/ustring.h
@@ -146,6 +146,7 @@ public:
static String num_scientific(double p_num);
static String num_real(double p_num);
static String num_int64(int64_t p_num, int base = 10, bool capitalize_hex = false);
+ static String num_uint64(uint64_t p_num, int base = 10, bool capitalize_hex = false);
static String chr(CharType p_char);
static String md5(const uint8_t *p_md5);
static String hex_encode_buffer(const uint8_t *p_buffer, int p_len);
@@ -225,17 +226,14 @@ public:
String xml_escape(bool p_escape_quotes = false) const;
String xml_unescape() const;
- String http_escape() const;
- String http_unescape() const;
+ String percent_encode() const;
+ String percent_decode() const;
String c_escape() const;
String c_escape_multiline() const;
String c_unescape() const;
String json_escape() const;
String word_wrap(int p_chars_per_line) const;
- String percent_encode() const;
- String percent_decode() const;
-
bool is_valid_identifier() const;
bool is_valid_integer() const;
bool is_valid_float() const;
diff --git a/core/variant.cpp b/core/variant.cpp
index 2e26169bfe..5d48c8785e 100644
--- a/core/variant.cpp
+++ b/core/variant.cpp
@@ -1607,6 +1607,8 @@ Variant::operator Vector3() const {
if (type == VECTOR3)
return *reinterpret_cast<const Vector3 *>(_data._mem);
+ else if (type == VECTOR2)
+ return Vector3(reinterpret_cast<const Vector2 *>(_data._mem)->x, reinterpret_cast<const Vector2 *>(_data._mem)->y, 0.0);
else
return Vector3();
}
diff --git a/core/variant.h b/core/variant.h
index 51ee8ea9d1..2cdb5c9ab6 100644
--- a/core/variant.h
+++ b/core/variant.h
@@ -293,7 +293,7 @@ public:
// If this changes the table in variant_op must be updated
enum Operator {
- //comparation
+ //comparison
OP_EQUAL,
OP_NOT_EQUAL,
OP_LESS,
@@ -338,6 +338,7 @@ public:
}
void zero();
+ Variant duplicate(bool deep = false) const;
static void blend(const Variant &a, const Variant &b, float c, Variant &r_dst);
static void interpolate(const Variant &a, const Variant &b, float c, Variant &r_dst);
diff --git a/core/variant_call.cpp b/core/variant_call.cpp
index 5607751a27..c6e093010d 100644
--- a/core/variant_call.cpp
+++ b/core/variant_call.cpp
@@ -347,7 +347,7 @@ struct _VariantCall {
VCALL_LOCALMEM1R(Vector2, bounce);
VCALL_LOCALMEM1R(Vector2, reflect);
VCALL_LOCALMEM0R(Vector2, angle);
- //VCALL_LOCALMEM1R(Vector2,cross);
+ VCALL_LOCALMEM1R(Vector2, cross);
VCALL_LOCALMEM0R(Vector2, abs);
VCALL_LOCALMEM1R(Vector2, clamped);
@@ -443,6 +443,7 @@ struct _VariantCall {
VCALL_LOCALMEM1R(Color, lightened);
VCALL_LOCALMEM1R(Color, darkened);
VCALL_LOCALMEM1R(Color, to_html);
+ VCALL_LOCALMEM4R(Color, from_hsv);
VCALL_LOCALMEM0R(RID, get_id);
@@ -464,7 +465,7 @@ struct _VariantCall {
VCALL_LOCALMEM0R(Dictionary, hash);
VCALL_LOCALMEM0R(Dictionary, keys);
VCALL_LOCALMEM0R(Dictionary, values);
- VCALL_LOCALMEM0R(Dictionary, duplicate);
+ VCALL_LOCALMEM1R(Dictionary, duplicate);
VCALL_LOCALMEM2(Array, set);
VCALL_LOCALMEM1R(Array, get);
@@ -490,9 +491,10 @@ struct _VariantCall {
VCALL_LOCALMEM1(Array, erase);
VCALL_LOCALMEM0(Array, sort);
VCALL_LOCALMEM2(Array, sort_custom);
+ VCALL_LOCALMEM0(Array, shuffle);
VCALL_LOCALMEM2R(Array, bsearch);
VCALL_LOCALMEM4R(Array, bsearch_custom);
- VCALL_LOCALMEM0R(Array, duplicate);
+ VCALL_LOCALMEM1R(Array, duplicate);
VCALL_LOCALMEM0(Array, invert);
static void _call_PoolByteArray_get_string_from_ascii(Variant &r_ret, Variant &p_self, const Variant **p_args) {
@@ -1515,7 +1517,7 @@ void register_variant_methods() {
ADDFUNC1R(VECTOR2, VECTOR2, Vector2, slide, VECTOR2, "n", varray());
ADDFUNC1R(VECTOR2, VECTOR2, Vector2, bounce, VECTOR2, "n", varray());
ADDFUNC1R(VECTOR2, VECTOR2, Vector2, reflect, VECTOR2, "n", varray());
- //ADDFUNC1R(VECTOR2,REAL,Vector2,cross,VECTOR2,"with",varray());
+ ADDFUNC1R(VECTOR2, REAL, Vector2, cross, VECTOR2, "with", varray());
ADDFUNC0R(VECTOR2, VECTOR2, Vector2, abs, varray());
ADDFUNC1R(VECTOR2, VECTOR2, Vector2, clamped, REAL, "length", varray());
@@ -1589,6 +1591,7 @@ void register_variant_methods() {
ADDFUNC1R(COLOR, COLOR, Color, lightened, REAL, "amount", varray());
ADDFUNC1R(COLOR, COLOR, Color, darkened, REAL, "amount", varray());
ADDFUNC1R(COLOR, STRING, Color, to_html, BOOL, "with_alpha", varray(true));
+ ADDFUNC4R(COLOR, COLOR, Color, from_hsv, REAL, "h", REAL, "s", REAL, "v", REAL, "a", varray(1.0));
ADDFUNC0R(_RID, INT, RID, get_id, varray());
@@ -1610,7 +1613,7 @@ void register_variant_methods() {
ADDFUNC0R(DICTIONARY, INT, Dictionary, hash, varray());
ADDFUNC0R(DICTIONARY, ARRAY, Dictionary, keys, varray());
ADDFUNC0R(DICTIONARY, ARRAY, Dictionary, values, varray());
- ADDFUNC0R(DICTIONARY, DICTIONARY, Dictionary, duplicate, varray());
+ ADDFUNC1R(DICTIONARY, DICTIONARY, Dictionary, duplicate, BOOL, "deep", varray(false));
ADDFUNC0R(ARRAY, INT, Array, size, varray());
ADDFUNC0R(ARRAY, BOOL, Array, empty, varray());
@@ -1634,10 +1637,11 @@ void register_variant_methods() {
ADDFUNC0RNC(ARRAY, NIL, Array, pop_front, varray());
ADDFUNC0NC(ARRAY, NIL, Array, sort, varray());
ADDFUNC2NC(ARRAY, NIL, Array, sort_custom, OBJECT, "obj", STRING, "func", varray());
+ ADDFUNC0NC(ARRAY, NIL, Array, shuffle, varray());
ADDFUNC2R(ARRAY, INT, Array, bsearch, NIL, "value", BOOL, "before", varray(true));
ADDFUNC4R(ARRAY, INT, Array, bsearch_custom, NIL, "value", OBJECT, "obj", STRING, "func", BOOL, "before", varray(true));
ADDFUNC0NC(ARRAY, NIL, Array, invert, varray());
- ADDFUNC0RNC(ARRAY, ARRAY, Array, duplicate, varray());
+ ADDFUNC1R(ARRAY, ARRAY, Array, duplicate, BOOL, "deep", varray(false));
ADDFUNC0R(POOL_BYTE_ARRAY, INT, PoolByteArray, size, varray());
ADDFUNC2(POOL_BYTE_ARRAY, NIL, PoolByteArray, set, INT, "idx", INT, "byte", varray());
diff --git a/core/variant_op.cpp b/core/variant_op.cpp
index e46fac77ee..8ad981ed0e 100644
--- a/core/variant_op.cpp
+++ b/core/variant_op.cpp
@@ -147,7 +147,7 @@ Variant::operator bool() const {
return booleanize();
}
-// We consider all unitialized or empty types to be false based on the type's
+// We consider all uninitialized or empty types to be false based on the type's
// zeroiness.
bool Variant::booleanize() const {
return !is_zero();
@@ -177,7 +177,7 @@ bool Variant::booleanize() const {
CASE_TYPE(m_prefix, m_op_name, m_name) { \
if (p_b.type == INT) _RETURN(p_a._data.m_type m_op p_b._data._int); \
if (p_b.type == REAL) _RETURN(p_a._data.m_type m_op p_b._data._real); \
- if (p_b.type == NIL) _RETURN(!p_b.type m_op NIL); \
+ if (p_b.type == NIL) _RETURN(!(p_b.type m_op NIL)); \
\
_RETURN_FAIL \
};
@@ -252,7 +252,7 @@ bool Variant::booleanize() const {
CASE_TYPE(m_prefix, m_op_name, m_name) { \
if (p_b.type == STRING) _RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op *reinterpret_cast<const String *>(p_b._data._mem)); \
if (p_b.type == NODE_PATH) _RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op *reinterpret_cast<const NodePath *>(p_b._data._mem)); \
- if (p_b.type == NIL) _RETURN(!p_b.type m_op NIL); \
+ if (p_b.type == NIL) _RETURN(!(p_b.type m_op NIL)); \
\
_RETURN_FAIL \
};
@@ -278,7 +278,7 @@ bool Variant::booleanize() const {
if (p_b.type == m_name) \
_RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op *reinterpret_cast<const m_type *>(p_b._data._mem)); \
if (p_b.type == NIL) \
- _RETURN(!p_b.type m_op NIL); \
+ _RETURN(!(p_b.type m_op NIL)); \
\
_RETURN_FAIL \
};
@@ -323,7 +323,7 @@ bool Variant::booleanize() const {
if (p_b.type == m_name) \
_RETURN(*p_a._data.m_sub m_op *p_b._data.m_sub); \
if (p_b.type == NIL) \
- _RETURN(!p_b.type m_op NIL); \
+ _RETURN(!(p_b.type m_op NIL)); \
\
_RETURN_FAIL \
}
@@ -1501,7 +1501,7 @@ void Variant::set_named(const StringName &p_index, const Variant &p_value, bool
v->set_hsv(v->get_h(), p_value._data._real, v->get_v());
valid = true;
} else if (p_index == CoreStringNames::singleton->v) {
- v->set_hsv(v->get_h(), v->get_v(), p_value._data._real);
+ v->set_hsv(v->get_h(), v->get_s(), p_value._data._real);
valid = true;
}
}
@@ -3415,6 +3415,19 @@ Variant Variant::iter_get(const Variant &r_iter, bool &r_valid) const {
return Variant();
}
+Variant Variant::duplicate(bool deep) const {
+ switch (type) {
+ // case OBJECT:
+ // return operator Object *()->duplicate();
+ case DICTIONARY:
+ return operator Dictionary().duplicate(deep);
+ case ARRAY:
+ return operator Array().duplicate(deep);
+ default:
+ return *this;
+ }
+}
+
void Variant::blend(const Variant &a, const Variant &b, float c, Variant &r_dst) {
if (a.type != b.type) {
if (a.is_num() && b.is_num()) {
diff --git a/core/version.h b/core/version.h
index 7a55d69ad7..d39172865a 100644
--- a/core/version.h
+++ b/core/version.h
@@ -30,9 +30,32 @@
#include "version_generated.gen.h"
+// Godot versions are of the form <major>.<minor> for the initial release,
+// and then <major>.<minor>.<patch> for subsequent bugfix releases where <patch> != 0
+// That's arbitrary, but we find it pretty and it's the current policy.
+
+// Defines the main "branch" version. Patch versions in this branch should be
+// forward-compatible.
+// Example: "3.1"
+#define VERSION_BRANCH "" _MKSTR(VERSION_MAJOR) "." _MKSTR(VERSION_MINOR)
#ifdef VERSION_PATCH
-#define VERSION_MKSTRING "" _MKSTR(VERSION_MAJOR) "." _MKSTR(VERSION_MINOR) "." _MKSTR(VERSION_PATCH) "." VERSION_STATUS "." VERSION_BUILD VERSION_MODULE_CONFIG
+// Example: "3.1.4"
+#define VERSION_NUMBER "" VERSION_BRANCH "." _MKSTR(VERSION_PATCH)
#else
-#define VERSION_MKSTRING "" _MKSTR(VERSION_MAJOR) "." _MKSTR(VERSION_MINOR) "." VERSION_STATUS "." VERSION_BUILD VERSION_MODULE_CONFIG
+// Example: "3.1"
+#define VERSION_NUMBER "" VERSION_BRANCH
#endif // VERSION_PATCH
-#define VERSION_FULL_NAME "" VERSION_NAME " v" VERSION_MKSTRING
+
+// Describes the full configuration of that Godot version, including the version number,
+// the status (beta, stable, etc.) and potential module-specific features (e.g. mono).
+// Example: "3.1.4.stable.mono"
+#define VERSION_FULL_CONFIG "" VERSION_NUMBER "." VERSION_STATUS VERSION_MODULE_CONFIG
+
+// Similar to VERSION_FULL_CONFIG, but also includes the (potentially custom) VERSION_BUILD
+// description (e.g. official, custom_build, etc.).
+// Example: "3.1.4.stable.mono.official"
+#define VERSION_FULL_BUILD "" VERSION_FULL_CONFIG "." VERSION_BUILD
+
+// Same as above, but prepended with Godot's name and a cosmetic "v" for "version".
+// Example: "Godot v3.1.4.stable.official.mono"
+#define VERSION_FULL_NAME "" VERSION_NAME " v" VERSION_FULL_BUILD