summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/bind/core_bind.cpp22
-rw-r--r--core/bind/core_bind.h2
-rw-r--r--core/color.cpp8
-rw-r--r--core/hash_map.h33
-rw-r--r--core/hashfuncs.h34
-rw-r--r--core/io/file_access_buffered.cpp2
-rw-r--r--core/io/file_access_buffered.h2
-rw-r--r--core/io/file_access_compressed.cpp4
-rw-r--r--core/io/file_access_compressed.h2
-rw-r--r--core/io/file_access_encrypted.cpp4
-rw-r--r--core/io/file_access_encrypted.h2
-rw-r--r--core/io/file_access_memory.cpp2
-rw-r--r--core/io/file_access_memory.h2
-rw-r--r--core/io/file_access_network.cpp2
-rw-r--r--core/io/file_access_network.h2
-rw-r--r--core/io/file_access_pack.cpp8
-rw-r--r--core/io/file_access_pack.h2
-rw-r--r--core/io/file_access_zip.cpp6
-rw-r--r--core/io/file_access_zip.h2
-rw-r--r--core/io/pck_packer.cpp8
-rw-r--r--core/io/resource_format_binary.cpp8
-rw-r--r--core/io/resource_import.cpp29
-rw-r--r--core/io/resource_import.h7
-rw-r--r--core/io/resource_loader.cpp25
-rw-r--r--core/io/resource_loader.h2
-rw-r--r--core/io/stream_peer.cpp6
-rw-r--r--core/io/stream_peer.h2
-rw-r--r--core/io/xml_parser.cpp2
-rw-r--r--core/io/zip_io.h4
-rw-r--r--core/math/a_star.cpp12
-rw-r--r--core/math/a_star.h4
-rw-r--r--core/math/camera_matrix.cpp2
-rw-r--r--core/math/math_funcs.h40
-rw-r--r--core/oa_hash_map.h593
-rw-r--r--core/os/dir_access.cpp2
-rw-r--r--core/os/file_access.h4
-rw-r--r--core/os/input.cpp2
-rw-r--r--core/os/input.h2
-rw-r--r--core/os/input_event.cpp2
-rw-r--r--core/os/os.h2
-rw-r--r--core/project_settings.cpp2
-rw-r--r--core/set.h245
-rw-r--r--core/variant.cpp161
-rw-r--r--core/variant.h2
-rw-r--r--core/variant_call.cpp20
-rw-r--r--core/variant_op.cpp564
46 files changed, 1335 insertions, 558 deletions
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp
index cfd7677d6b..2477b1b187 100644
--- a/core/bind/core_bind.cpp
+++ b/core/bind/core_bind.cpp
@@ -1033,10 +1033,8 @@ void _OS::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_time", "utc"), &_OS::get_time, DEFVAL(false));
ClassDB::bind_method(D_METHOD("get_time_zone_info"), &_OS::get_time_zone_info);
ClassDB::bind_method(D_METHOD("get_unix_time"), &_OS::get_unix_time);
- ClassDB::bind_method(D_METHOD("get_datetime_from_unix_time", "unix_time_val"),
- &_OS::get_datetime_from_unix_time);
- ClassDB::bind_method(D_METHOD("get_unix_time_from_datetime", "datetime"),
- &_OS::get_unix_time_from_datetime);
+ ClassDB::bind_method(D_METHOD("get_datetime_from_unix_time", "unix_time_val"), &_OS::get_datetime_from_unix_time);
+ ClassDB::bind_method(D_METHOD("get_unix_time_from_datetime", "datetime"), &_OS::get_unix_time_from_datetime);
ClassDB::bind_method(D_METHOD("get_system_time_secs"), &_OS::get_system_time_secs);
ClassDB::bind_method(D_METHOD("set_icon", "icon"), &_OS::set_icon);
@@ -1337,7 +1335,7 @@ void _Geometry::_bind_methods() {
ClassDB::bind_method(D_METHOD("build_box_planes", "extents"), &_Geometry::build_box_planes);
ClassDB::bind_method(D_METHOD("build_cylinder_planes", "radius", "height", "sides", "axis"), &_Geometry::build_cylinder_planes, DEFVAL(Vector3::AXIS_Z));
ClassDB::bind_method(D_METHOD("build_capsule_planes", "radius", "height", "sides", "lats", "axis"), &_Geometry::build_capsule_planes, DEFVAL(Vector3::AXIS_Z));
- ClassDB::bind_method(D_METHOD("segment_intersects_circle", "segment_from", "segment_to", "circle_pos", "circle_radius"), &_Geometry::segment_intersects_circle);
+ ClassDB::bind_method(D_METHOD("segment_intersects_circle", "segment_from", "segment_to", "circle_position", "circle_radius"), &_Geometry::segment_intersects_circle);
ClassDB::bind_method(D_METHOD("segment_intersects_segment_2d", "from_a", "to_a", "from_b", "to_b"), &_Geometry::segment_intersects_segment_2d);
ClassDB::bind_method(D_METHOD("get_closest_points_between_segments_2d", "p1", "q1", "p2", "q2"), &_Geometry::get_closest_points_between_segments_2d);
@@ -1353,7 +1351,7 @@ void _Geometry::_bind_methods() {
ClassDB::bind_method(D_METHOD("ray_intersects_triangle", "from", "dir", "a", "b", "c"), &_Geometry::ray_intersects_triangle);
ClassDB::bind_method(D_METHOD("segment_intersects_triangle", "from", "to", "a", "b", "c"), &_Geometry::segment_intersects_triangle);
- ClassDB::bind_method(D_METHOD("segment_intersects_sphere", "from", "to", "spos", "sradius"), &_Geometry::segment_intersects_sphere);
+ ClassDB::bind_method(D_METHOD("segment_intersects_sphere", "from", "to", "sphere_position", "sphere_radius"), &_Geometry::segment_intersects_sphere);
ClassDB::bind_method(D_METHOD("segment_intersects_cylinder", "from", "to", "height", "radius"), &_Geometry::segment_intersects_cylinder);
ClassDB::bind_method(D_METHOD("segment_intersects_convex", "from", "to", "planes"), &_Geometry::segment_intersects_convex);
ClassDB::bind_method(D_METHOD("point_is_inside_triangle", "point", "a", "b", "c"), &_Geometry::point_is_inside_triangle);
@@ -1452,10 +1450,10 @@ void _File::seek_end(int64_t p_position) {
ERR_FAIL_COND(!f);
f->seek_end(p_position);
}
-int64_t _File::get_pos() const {
+int64_t _File::get_position() const {
ERR_FAIL_COND_V(!f, 0);
- return f->get_pos();
+ return f->get_position();
}
int64_t _File::get_len() const {
@@ -1534,7 +1532,7 @@ String _File::get_as_text() const {
ERR_FAIL_COND_V(!f, String());
String text;
- size_t original_pos = f->get_pos();
+ size_t original_pos = f->get_position();
f->seek(0);
String l = get_line();
@@ -1731,9 +1729,9 @@ 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("is_open"), &_File::is_open);
- ClassDB::bind_method(D_METHOD("seek", "pos"), &_File::seek);
- ClassDB::bind_method(D_METHOD("seek_end", "pos"), &_File::seek_end, DEFVAL(0));
- ClassDB::bind_method(D_METHOD("get_pos"), &_File::get_pos);
+ ClassDB::bind_method(D_METHOD("seek", "position"), &_File::seek);
+ ClassDB::bind_method(D_METHOD("seek_end", "position"), &_File::seek_end, DEFVAL(0));
+ ClassDB::bind_method(D_METHOD("get_position"), &_File::get_position);
ClassDB::bind_method(D_METHOD("get_len"), &_File::get_len);
ClassDB::bind_method(D_METHOD("eof_reached"), &_File::eof_reached);
ClassDB::bind_method(D_METHOD("get_8"), &_File::get_8);
diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h
index 721acf657f..1a22d45932 100644
--- a/core/bind/core_bind.h
+++ b/core/bind/core_bind.h
@@ -399,7 +399,7 @@ public:
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_pos() const; ///< get position in the file
+ int64_t get_position() const; ///< get position in the file
int64_t get_len() const; ///< get size of the file
bool eof_reached() const; ///< reading passed EOF
diff --git a/core/color.cpp b/core/color.cpp
index dd8b13c047..78b11a84df 100644
--- a/core/color.cpp
+++ b/core/color.cpp
@@ -250,6 +250,14 @@ Color Color::html(const String &p_color) {
return Color();
if (color[0] == '#')
color = color.substr(1, color.length() - 1);
+ if (color.length() == 3 || color.length() == 4) {
+ String exp_color;
+ for (int i = 0; i < color.length(); i++) {
+ exp_color += color[i];
+ exp_color += color[i];
+ }
+ color = exp_color;
+ }
bool alpha = false;
diff --git a/core/hash_map.h b/core/hash_map.h
index 37391a4c83..e100d7a904 100644
--- a/core/hash_map.h
+++ b/core/hash_map.h
@@ -37,39 +37,6 @@
#include "os/memory.h"
#include "ustring.h"
-struct HashMapHasherDefault {
- static _FORCE_INLINE_ uint32_t hash(const String &p_string) { return p_string.hash(); }
- static _FORCE_INLINE_ uint32_t hash(const char *p_cstr) { return hash_djb2(p_cstr); }
- static _FORCE_INLINE_ uint32_t hash(const uint64_t p_int) { return hash_one_uint64(p_int); }
-
- static _FORCE_INLINE_ uint32_t hash(const int64_t p_int) { return hash(uint64_t(p_int)); }
- static _FORCE_INLINE_ uint32_t hash(const float p_float) { return hash_djb2_one_float(p_float); }
- static _FORCE_INLINE_ uint32_t hash(const double p_double) { return hash_djb2_one_float(p_double); }
- static _FORCE_INLINE_ uint32_t hash(const uint32_t p_int) { return p_int; }
- static _FORCE_INLINE_ uint32_t hash(const int32_t p_int) { return (uint32_t)p_int; }
- static _FORCE_INLINE_ uint32_t hash(const uint16_t p_int) { return p_int; }
- static _FORCE_INLINE_ uint32_t hash(const int16_t p_int) { return (uint32_t)p_int; }
- static _FORCE_INLINE_ uint32_t hash(const uint8_t p_int) { return p_int; }
- static _FORCE_INLINE_ uint32_t hash(const int8_t p_int) { return (uint32_t)p_int; }
- static _FORCE_INLINE_ uint32_t hash(const wchar_t p_wchar) { return (uint32_t)p_wchar; }
- //static _FORCE_INLINE_ uint32_t hash(const void* p_ptr) { return uint32_t(uint64_t(p_ptr))*(0x9e3779b1L); }
-};
-
-template <typename T>
-struct HashMapComparatorDefault {
- static bool compare(const T &p_lhs, const T &p_rhs) {
- return p_lhs == p_rhs;
- }
-
- bool compare(const float &p_lhs, const float &p_rhs) {
- return (p_lhs == p_rhs) || (Math::is_nan(p_lhs) && Math::is_nan(p_rhs));
- }
-
- bool compare(const double &p_lhs, const double &p_rhs) {
- return (p_lhs == p_rhs) || (Math::is_nan(p_lhs) && Math::is_nan(p_rhs));
- }
-};
-
/**
* @class HashMap
* @author Juan Linietsky <reduzio@gmail.com>
diff --git a/core/hashfuncs.h b/core/hashfuncs.h
index 56d40f1dd7..2880cc451e 100644
--- a/core/hashfuncs.h
+++ b/core/hashfuncs.h
@@ -33,6 +33,7 @@
#include "math_defs.h"
#include "math_funcs.h"
#include "typedefs.h"
+#include "ustring.h"
/**
* Hashing functions
@@ -128,4 +129,37 @@ static inline uint64_t make_uint64_t(T p_in) {
return _u._u64;
}
+struct HashMapHasherDefault {
+ static _FORCE_INLINE_ uint32_t hash(const String &p_string) { return p_string.hash(); }
+ static _FORCE_INLINE_ uint32_t hash(const char *p_cstr) { return hash_djb2(p_cstr); }
+ static _FORCE_INLINE_ uint32_t hash(const uint64_t p_int) { return hash_one_uint64(p_int); }
+
+ static _FORCE_INLINE_ uint32_t hash(const int64_t p_int) { return hash(uint64_t(p_int)); }
+ static _FORCE_INLINE_ uint32_t hash(const float p_float) { return hash_djb2_one_float(p_float); }
+ static _FORCE_INLINE_ uint32_t hash(const double p_double) { return hash_djb2_one_float(p_double); }
+ static _FORCE_INLINE_ uint32_t hash(const uint32_t p_int) { return p_int; }
+ static _FORCE_INLINE_ uint32_t hash(const int32_t p_int) { return (uint32_t)p_int; }
+ static _FORCE_INLINE_ uint32_t hash(const uint16_t p_int) { return p_int; }
+ static _FORCE_INLINE_ uint32_t hash(const int16_t p_int) { return (uint32_t)p_int; }
+ static _FORCE_INLINE_ uint32_t hash(const uint8_t p_int) { return p_int; }
+ static _FORCE_INLINE_ uint32_t hash(const int8_t p_int) { return (uint32_t)p_int; }
+ static _FORCE_INLINE_ uint32_t hash(const wchar_t p_wchar) { return (uint32_t)p_wchar; }
+ //static _FORCE_INLINE_ uint32_t hash(const void* p_ptr) { return uint32_t(uint64_t(p_ptr))*(0x9e3779b1L); }
+};
+
+template <typename T>
+struct HashMapComparatorDefault {
+ static bool compare(const T &p_lhs, const T &p_rhs) {
+ return p_lhs == p_rhs;
+ }
+
+ bool compare(const float &p_lhs, const float &p_rhs) {
+ return (p_lhs == p_rhs) || (Math::is_nan(p_lhs) && Math::is_nan(p_rhs));
+ }
+
+ bool compare(const double &p_lhs, const double &p_rhs) {
+ return (p_lhs == p_rhs) || (Math::is_nan(p_lhs) && Math::is_nan(p_rhs));
+ }
+};
+
#endif
diff --git a/core/io/file_access_buffered.cpp b/core/io/file_access_buffered.cpp
index 859f2e3f8c..9ec03bf32b 100644
--- a/core/io/file_access_buffered.cpp
+++ b/core/io/file_access_buffered.cpp
@@ -76,7 +76,7 @@ void FileAccessBuffered::seek_end(int64_t p_position) {
file.offset = file.size + p_position;
};
-size_t FileAccessBuffered::get_pos() const {
+size_t FileAccessBuffered::get_position() const {
return file.offset;
};
diff --git a/core/io/file_access_buffered.h b/core/io/file_access_buffered.h
index d3137058fb..70aaeb8ae0 100644
--- a/core/io/file_access_buffered.h
+++ b/core/io/file_access_buffered.h
@@ -72,7 +72,7 @@ protected:
int get_cache_size();
public:
- virtual size_t get_pos() const; ///< get position in the file
+ virtual size_t get_position() const; ///< get position in the file
virtual size_t get_len() const; ///< get size of the file
virtual void seek(size_t p_position); ///< seek to a given position
diff --git a/core/io/file_access_compressed.cpp b/core/io/file_access_compressed.cpp
index 70430ca5d3..4750945854 100644
--- a/core/io/file_access_compressed.cpp
+++ b/core/io/file_access_compressed.cpp
@@ -62,7 +62,7 @@ Error FileAccessCompressed::open_after_magic(FileAccess *p_base) {
block_size = f->get_32();
read_total = f->get_32();
int bc = (read_total / block_size) + 1;
- int acc_ofs = f->get_pos() + bc * 4;
+ int acc_ofs = f->get_position() + bc * 4;
int max_bs = 0;
for (int i = 0; i < bc; i++) {
@@ -232,7 +232,7 @@ void FileAccessCompressed::seek_end(int64_t p_position) {
seek(read_total + p_position);
}
}
-size_t FileAccessCompressed::get_pos() const {
+size_t FileAccessCompressed::get_position() const {
ERR_FAIL_COND_V(!f, 0);
if (writing) {
diff --git a/core/io/file_access_compressed.h b/core/io/file_access_compressed.h
index ba84c9767c..1a57e2d4ee 100644
--- a/core/io/file_access_compressed.h
+++ b/core/io/file_access_compressed.h
@@ -74,7 +74,7 @@ public:
virtual void seek(size_t p_position); ///< seek to a given position
virtual void seek_end(int64_t p_position = 0); ///< seek from the end of file
- virtual size_t get_pos() const; ///< get position in the file
+ virtual size_t get_position() const; ///< get position in the file
virtual size_t get_len() const; ///< get size of the file
virtual bool eof_reached() const; ///< reading passed EOF
diff --git a/core/io/file_access_encrypted.cpp b/core/io/file_access_encrypted.cpp
index 12503f3be4..461c5bafe2 100644
--- a/core/io/file_access_encrypted.cpp
+++ b/core/io/file_access_encrypted.cpp
@@ -71,7 +71,7 @@ Error FileAccessEncrypted::open_and_parse(FileAccess *p_base, const Vector<uint8
unsigned char md5d[16];
p_base->get_buffer(md5d, 16);
length = p_base->get_64();
- base = p_base->get_pos();
+ base = p_base->get_position();
ERR_FAIL_COND_V(p_base->get_len() < base + length, ERR_FILE_CORRUPT);
uint32_t ds = length;
if (ds % 16) {
@@ -199,7 +199,7 @@ void FileAccessEncrypted::seek_end(int64_t p_position) {
seek(data.size() + p_position);
}
-size_t FileAccessEncrypted::get_pos() const {
+size_t FileAccessEncrypted::get_position() const {
return pos;
}
diff --git a/core/io/file_access_encrypted.h b/core/io/file_access_encrypted.h
index 74d00a5a8f..82f60ac654 100644
--- a/core/io/file_access_encrypted.h
+++ b/core/io/file_access_encrypted.h
@@ -61,7 +61,7 @@ public:
virtual void seek(size_t p_position); ///< seek to a given position
virtual void seek_end(int64_t p_position = 0); ///< seek from the end of file
- virtual size_t get_pos() const; ///< get position in the file
+ virtual size_t get_position() const; ///< get position in the file
virtual size_t get_len() const; ///< get size of the file
virtual bool eof_reached() const; ///< reading passed EOF
diff --git a/core/io/file_access_memory.cpp b/core/io/file_access_memory.cpp
index 5b186b7798..b948394385 100644
--- a/core/io/file_access_memory.cpp
+++ b/core/io/file_access_memory.cpp
@@ -120,7 +120,7 @@ void FileAccessMemory::seek_end(int64_t p_position) {
pos = length + p_position;
}
-size_t FileAccessMemory::get_pos() const {
+size_t FileAccessMemory::get_position() const {
ERR_FAIL_COND_V(!data, 0);
return pos;
diff --git a/core/io/file_access_memory.h b/core/io/file_access_memory.h
index 7feb16461b..b7b8430089 100644
--- a/core/io/file_access_memory.h
+++ b/core/io/file_access_memory.h
@@ -51,7 +51,7 @@ public:
virtual void seek(size_t p_position); ///< seek to a given position
virtual void seek_end(int64_t p_position); ///< seek from the end of file
- virtual size_t get_pos() const; ///< get position in the file
+ virtual size_t get_position() const; ///< get position in the file
virtual size_t get_len() const; ///< get size of the file
virtual bool eof_reached() const; ///< reading passed EOF
diff --git a/core/io/file_access_network.cpp b/core/io/file_access_network.cpp
index 58ca2d4c58..8c624226a1 100644
--- a/core/io/file_access_network.cpp
+++ b/core/io/file_access_network.cpp
@@ -350,7 +350,7 @@ void FileAccessNetwork::seek_end(int64_t p_position) {
seek(total_size + p_position);
}
-size_t FileAccessNetwork::get_pos() const {
+size_t FileAccessNetwork::get_position() const {
ERR_FAIL_COND_V(!opened, 0);
return pos;
diff --git a/core/io/file_access_network.h b/core/io/file_access_network.h
index cd5046f007..abbe378b60 100644
--- a/core/io/file_access_network.h
+++ b/core/io/file_access_network.h
@@ -145,7 +145,7 @@ public:
virtual void seek(size_t p_position); ///< seek to a given position
virtual void seek_end(int64_t p_position = 0); ///< seek from the end of file
- virtual size_t get_pos() const; ///< get position in the file
+ virtual size_t get_position() const; ///< get position in the file
virtual size_t get_len() const; ///< get size of the file
virtual bool eof_reached() const; ///< reading passed EOF
diff --git a/core/io/file_access_pack.cpp b/core/io/file_access_pack.cpp
index e511085ac5..ff4c28ec39 100644
--- a/core/io/file_access_pack.cpp
+++ b/core/io/file_access_pack.cpp
@@ -140,17 +140,17 @@ bool PackedSourcePCK::try_open_pack(const String &p_path) {
if (magic != 0x43504447) {
//maybe at he end.... self contained exe
f->seek_end();
- f->seek(f->get_pos() - 4);
+ f->seek(f->get_position() - 4);
magic = f->get_32();
if (magic != 0x43504447) {
memdelete(f);
return false;
}
- f->seek(f->get_pos() - 12);
+ f->seek(f->get_position() - 12);
uint64_t ds = f->get_64();
- f->seek(f->get_pos() - ds - 8);
+ f->seek(f->get_position() - ds - 8);
magic = f->get_32();
if (magic != 0x43504447) {
@@ -236,7 +236,7 @@ void FileAccessPack::seek_end(int64_t p_position) {
seek(pf.size + p_position);
}
-size_t FileAccessPack::get_pos() const {
+size_t FileAccessPack::get_position() const {
return pos;
}
diff --git a/core/io/file_access_pack.h b/core/io/file_access_pack.h
index 758e9afa8e..3deb0d2bd3 100644
--- a/core/io/file_access_pack.h
+++ b/core/io/file_access_pack.h
@@ -148,7 +148,7 @@ public:
virtual void seek(size_t p_position);
virtual void seek_end(int64_t p_position = 0);
- virtual size_t get_pos() const;
+ virtual size_t get_position() const;
virtual size_t get_len() const;
virtual bool eof_reached() const;
diff --git a/core/io/file_access_zip.cpp b/core/io/file_access_zip.cpp
index 8c99ef2983..73b23ac702 100644
--- a/core/io/file_access_zip.cpp
+++ b/core/io/file_access_zip.cpp
@@ -65,7 +65,7 @@ static uLong godot_write(voidpf opaque, voidpf stream, const void *buf, uLong si
static long godot_tell(voidpf opaque, voidpf stream) {
FileAccess *f = (FileAccess *)opaque;
- return f->get_pos();
+ return f->get_position();
};
static long godot_seek(voidpf opaque, voidpf stream, uLong offset, int origin) {
@@ -76,7 +76,7 @@ static long godot_seek(voidpf opaque, voidpf stream, uLong offset, int origin) {
switch (origin) {
case ZLIB_FILEFUNC_SEEK_CUR:
- pos = f->get_pos() + offset;
+ pos = f->get_position() + offset;
break;
case ZLIB_FILEFUNC_SEEK_END:
pos = f->get_len() + offset;
@@ -301,7 +301,7 @@ void FileAccessZip::seek_end(int64_t p_position) {
unzSeekCurrentFile(zfile, get_len() + p_position);
};
-size_t FileAccessZip::get_pos() const {
+size_t FileAccessZip::get_position() const {
ERR_FAIL_COND_V(!zfile, 0);
return unztell(zfile);
diff --git a/core/io/file_access_zip.h b/core/io/file_access_zip.h
index 2a8ec3fca5..a40e1a753d 100644
--- a/core/io/file_access_zip.h
+++ b/core/io/file_access_zip.h
@@ -98,7 +98,7 @@ public:
virtual void seek(size_t p_position); ///< seek to a given position
virtual void seek_end(int64_t p_position = 0); ///< seek from the end of file
- virtual size_t get_pos() const; ///< get position in the file
+ virtual size_t get_position() const; ///< get position in the file
virtual size_t get_len() const; ///< get size of the file
virtual bool eof_reached() const; ///< reading passed EOF
diff --git a/core/io/pck_packer.cpp b/core/io/pck_packer.cpp
index f1f5b6f538..23e86580d1 100644
--- a/core/io/pck_packer.cpp
+++ b/core/io/pck_packer.cpp
@@ -119,7 +119,7 @@ Error PCKPacker::flush(bool p_verbose) {
for (int i = 0; i < files.size(); i++) {
file->store_pascal_string(files[i].path);
- files[i].offset_offset = file->get_pos();
+ files[i].offset_offset = file->get_position();
file->store_64(0); // offset
file->store_64(files[i].size); // size
@@ -130,10 +130,10 @@ Error PCKPacker::flush(bool p_verbose) {
file->store_32(0);
};
- uint64_t ofs = file->get_pos();
+ uint64_t ofs = file->get_position();
ofs = _align(ofs, alignment);
- _pad(file, ofs - file->get_pos());
+ _pad(file, ofs - file->get_position());
const uint32_t buf_max = 65536;
uint8_t *buf = memnew_arr(uint8_t, buf_max);
@@ -150,7 +150,7 @@ Error PCKPacker::flush(bool p_verbose) {
to_write -= read;
};
- uint64_t pos = file->get_pos();
+ uint64_t pos = file->get_position();
file->seek(files[i].offset_offset); // go back to store the file's offset
file->store_64(ofs);
file->seek(pos);
diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp
index 16ec6cd3c5..900db7c2dc 100644
--- a/core/io/resource_format_binary.cpp
+++ b/core/io/resource_format_binary.cpp
@@ -1179,7 +1179,7 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons
save_ustring(fw, get_ustring(f)); //type
- size_t md_ofs = f->get_pos();
+ size_t md_ofs = f->get_position();
size_t importmd_ofs = f->get_64();
fw->store_64(0); //metadata offset
@@ -1227,7 +1227,7 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons
save_ustring(fw, path);
}
- int64_t size_diff = (int64_t)fw->get_pos() - (int64_t)f->get_pos();
+ int64_t size_diff = (int64_t)fw->get_position() - (int64_t)f->get_position();
//internal resources
uint32_t int_resources_size = f->get_32();
@@ -1880,7 +1880,7 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p
} else {
save_unicode_string(r->get_path()); //actual external
}
- ofs_pos.push_back(f->get_pos());
+ ofs_pos.push_back(f->get_position());
f->store_64(0); //offset in 64 bits
}
@@ -1891,7 +1891,7 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p
ResourceData &rd = E->get();
- ofs_table.push_back(f->get_pos());
+ ofs_table.push_back(f->get_position());
save_unicode_string(rd.type);
f->store_32(rd.properties.size());
diff --git a/core/io/resource_import.cpp b/core/io/resource_import.cpp
index be486a86a3..bc7ea47762 100644
--- a/core/io/resource_import.cpp
+++ b/core/io/resource_import.cpp
@@ -87,6 +87,8 @@ Error ResourceFormatImporter::_get_path_and_type(const String &p_path, PathAndTy
path_found = true; //first match must have priority
} else if (assign == "type") {
r_path_and_type.type = value;
+ } else if (assign == "importer") {
+ r_path_and_type.importer = value;
} else if (assign == "valid") {
if (r_valid) {
*r_valid = value;
@@ -184,6 +186,29 @@ bool ResourceFormatImporter::can_be_imported(const String &p_path) const {
return ResourceFormatLoader::recognize_path(p_path);
}
+int ResourceFormatImporter::get_import_order(const String &p_path) const {
+
+ Ref<ResourceImporter> importer;
+
+ if (FileAccess::exists(p_path + ".import")) {
+
+ PathAndType pat;
+ Error err = _get_path_and_type(p_path, pat);
+
+ if (err == OK) {
+ importer = get_importer_by_name(pat.importer);
+ }
+ } else {
+
+ importer = get_importer_by_extension(p_path.get_extension().to_lower());
+ }
+
+ if (importer.is_valid())
+ return importer->get_import_order();
+
+ return 0;
+}
+
bool ResourceFormatImporter::handles_type(const String &p_type) const {
for (Set<Ref<ResourceImporter> >::Element *E = importers.front(); E; E = E->next()) {
@@ -291,7 +316,7 @@ void ResourceFormatImporter::get_dependencies(const String &p_path, List<String>
return ResourceLoader::get_dependencies(pat.path, p_dependencies, p_add_types);
}
-Ref<ResourceImporter> ResourceFormatImporter::get_importer_by_name(const String &p_name) {
+Ref<ResourceImporter> ResourceFormatImporter::get_importer_by_name(const String &p_name) const {
for (Set<Ref<ResourceImporter> >::Element *E = importers.front(); E; E = E->next()) {
if (E->get()->get_importer_name() == p_name) {
@@ -315,7 +340,7 @@ void ResourceFormatImporter::get_importers_for_extension(const String &p_extensi
}
}
-Ref<ResourceImporter> ResourceFormatImporter::get_importer_by_extension(const String &p_extension) {
+Ref<ResourceImporter> ResourceFormatImporter::get_importer_by_extension(const String &p_extension) const {
Ref<ResourceImporter> importer;
float priority = 0;
diff --git a/core/io/resource_import.h b/core/io/resource_import.h
index b10255fbab..28489b5d34 100644
--- a/core/io/resource_import.h
+++ b/core/io/resource_import.h
@@ -38,6 +38,7 @@ class ResourceFormatImporter : public ResourceFormatLoader {
struct PathAndType {
String path;
String type;
+ String importer;
};
Error _get_path_and_type(const String &p_path, PathAndType &r_path_and_type, bool *r_valid = NULL) const;
@@ -58,14 +59,15 @@ public:
virtual void get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types = false);
virtual bool can_be_imported(const String &p_path) const;
+ virtual int get_import_order(const String &p_path) const;
String get_internal_resource_path(const String &p_path) const;
void get_internal_resource_path_list(const String &p_path, List<String> *r_paths);
void add_importer(const Ref<ResourceImporter> &p_importer) { importers.insert(p_importer); }
void remove_importer(const Ref<ResourceImporter> &p_importer) { importers.erase(p_importer); }
- Ref<ResourceImporter> get_importer_by_name(const String &p_name);
- Ref<ResourceImporter> get_importer_by_extension(const String &p_extension);
+ Ref<ResourceImporter> get_importer_by_name(const String &p_name) const;
+ Ref<ResourceImporter> get_importer_by_extension(const String &p_extension) const;
void get_importers_for_extension(const String &p_extension, List<Ref<ResourceImporter> > *r_importers);
String get_import_base_path(const String &p_for_file) const;
@@ -82,6 +84,7 @@ public:
virtual String get_save_extension() const = 0;
virtual String get_resource_type() const = 0;
virtual float get_priority() const { return 1.0; }
+ virtual int get_import_order() const { return 0; }
struct ImportOption {
PropertyInfo option;
diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp
index 4f266df43e..89cb4a22c2 100644
--- a/core/io/resource_loader.cpp
+++ b/core/io/resource_loader.cpp
@@ -308,6 +308,31 @@ void ResourceLoader::add_resource_format_loader(ResourceFormatLoader *p_format_l
}
}
+int ResourceLoader::get_import_order(const String &p_path) {
+
+ String path = _path_remap(p_path);
+
+ String local_path;
+ if (path.is_rel_path())
+ local_path = "res://" + path;
+ else
+ local_path = ProjectSettings::get_singleton()->localize_path(path);
+
+ for (int i = 0; i < loader_count; i++) {
+
+ if (!loader[i]->recognize_path(local_path))
+ continue;
+ /*
+ if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint))
+ continue;
+ */
+
+ return loader[i]->get_import_order(p_path);
+ }
+
+ return 0;
+}
+
bool ResourceLoader::is_import_valid(const String &p_path) {
String path = _path_remap(p_path);
diff --git a/core/io/resource_loader.h b/core/io/resource_loader.h
index a71a568569..5deffbca1a 100644
--- a/core/io/resource_loader.h
+++ b/core/io/resource_loader.h
@@ -67,6 +67,7 @@ public:
virtual void get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types = false);
virtual Error rename_dependencies(const String &p_path, const Map<String, String> &p_map) { return OK; }
virtual bool is_import_valid(const String &p_path) const { return true; }
+ virtual int get_import_order(const String &p_path) const { return 0; }
virtual ~ResourceFormatLoader() {}
};
@@ -110,6 +111,7 @@ public:
static void get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types = false);
static Error rename_dependencies(const String &p_path, const Map<String, String> &p_map);
static bool is_import_valid(const String &p_path);
+ static int get_import_order(const String &p_path);
static void set_timestamp_on_load(bool p_timestamp) { timestamp_on_load = p_timestamp; }
diff --git a/core/io/stream_peer.cpp b/core/io/stream_peer.cpp
index f4f81f0807..2583eb369d 100644
--- a/core/io/stream_peer.cpp
+++ b/core/io/stream_peer.cpp
@@ -405,9 +405,9 @@ void StreamPeer::_bind_methods() {
void StreamPeerBuffer::_bind_methods() {
- ClassDB::bind_method(D_METHOD("seek", "pos"), &StreamPeerBuffer::seek);
+ ClassDB::bind_method(D_METHOD("seek", "position"), &StreamPeerBuffer::seek);
ClassDB::bind_method(D_METHOD("get_size"), &StreamPeerBuffer::get_size);
- ClassDB::bind_method(D_METHOD("get_pos"), &StreamPeerBuffer::get_pos);
+ ClassDB::bind_method(D_METHOD("get_position"), &StreamPeerBuffer::get_position);
ClassDB::bind_method(D_METHOD("resize", "size"), &StreamPeerBuffer::resize);
ClassDB::bind_method(D_METHOD("set_data_array", "data"), &StreamPeerBuffer::set_data_array);
ClassDB::bind_method(D_METHOD("get_data_array"), &StreamPeerBuffer::get_data_array);
@@ -484,7 +484,7 @@ int StreamPeerBuffer::get_size() const {
return data.size();
}
-int StreamPeerBuffer::get_pos() const {
+int StreamPeerBuffer::get_position() const {
return pointer;
}
diff --git a/core/io/stream_peer.h b/core/io/stream_peer.h
index 1ee997c123..b120d18501 100644
--- a/core/io/stream_peer.h
+++ b/core/io/stream_peer.h
@@ -111,7 +111,7 @@ public:
void seek(int p_pos);
int get_size() const;
- int get_pos() const;
+ int get_position() const;
void resize(int p_size);
void set_data_array(const PoolVector<uint8_t> &p_data);
diff --git a/core/io/xml_parser.cpp b/core/io/xml_parser.cpp
index 3a4be7cd13..8ae68183d7 100644
--- a/core/io/xml_parser.cpp
+++ b/core/io/xml_parser.cpp
@@ -369,7 +369,7 @@ void XMLParser::_bind_methods() {
ClassDB::bind_method(D_METHOD("is_empty"), &XMLParser::is_empty);
ClassDB::bind_method(D_METHOD("get_current_line"), &XMLParser::get_current_line);
ClassDB::bind_method(D_METHOD("skip_section"), &XMLParser::skip_section);
- ClassDB::bind_method(D_METHOD("seek", "pos"), &XMLParser::seek);
+ ClassDB::bind_method(D_METHOD("seek", "position"), &XMLParser::seek);
ClassDB::bind_method(D_METHOD("open", "file"), &XMLParser::open);
ClassDB::bind_method(D_METHOD("open_buffer", "buffer"), &XMLParser::open_buffer);
diff --git a/core/io/zip_io.h b/core/io/zip_io.h
index 8cf971ee08..ce3c919b77 100644
--- a/core/io/zip_io.h
+++ b/core/io/zip_io.h
@@ -72,7 +72,7 @@ static uLong zipio_write(voidpf opaque, voidpf stream, const void *buf, uLong si
static long zipio_tell(voidpf opaque, voidpf stream) {
FileAccess *f = *(FileAccess **)opaque;
- return f->get_pos();
+ return f->get_position();
};
static long zipio_seek(voidpf opaque, voidpf stream, uLong offset, int origin) {
@@ -83,7 +83,7 @@ static long zipio_seek(voidpf opaque, voidpf stream, uLong offset, int origin) {
switch (origin) {
case ZLIB_FILEFUNC_SEEK_CUR:
- pos = f->get_pos() + offset;
+ pos = f->get_position() + offset;
break;
case ZLIB_FILEFUNC_SEEK_END:
pos = f->get_len() + offset;
diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp
index d1afcec18f..4f80fb2491 100644
--- a/core/math/a_star.cpp
+++ b/core/math/a_star.cpp
@@ -58,7 +58,7 @@ void AStar::add_point(int p_id, const Vector3 &p_pos, real_t p_weight_scale) {
}
}
-Vector3 AStar::get_point_pos(int p_id) const {
+Vector3 AStar::get_point_position(int p_id) const {
ERR_FAIL_COND_V(!points.has(p_id), Vector3());
@@ -171,7 +171,7 @@ int AStar::get_closest_point(const Vector3 &p_point) const {
return closest_id;
}
-Vector3 AStar::get_closest_pos_in_segment(const Vector3 &p_point) const {
+Vector3 AStar::get_closest_position_in_segment(const Vector3 &p_point) const {
real_t closest_dist = 1e20;
bool found = false;
@@ -412,8 +412,8 @@ PoolVector<int> AStar::get_id_path(int p_from_id, int p_to_id) {
void AStar::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_available_point_id"), &AStar::get_available_point_id);
- ClassDB::bind_method(D_METHOD("add_point", "id", "pos", "weight_scale"), &AStar::add_point, DEFVAL(1.0));
- ClassDB::bind_method(D_METHOD("get_point_pos", "id"), &AStar::get_point_pos);
+ ClassDB::bind_method(D_METHOD("add_point", "id", "position", "weight_scale"), &AStar::add_point, DEFVAL(1.0));
+ ClassDB::bind_method(D_METHOD("get_point_position", "id"), &AStar::get_point_position);
ClassDB::bind_method(D_METHOD("get_point_weight_scale", "id"), &AStar::get_point_weight_scale);
ClassDB::bind_method(D_METHOD("remove_point", "id"), &AStar::remove_point);
ClassDB::bind_method(D_METHOD("has_point", "id"), &AStar::has_point);
@@ -425,8 +425,8 @@ void AStar::_bind_methods() {
ClassDB::bind_method(D_METHOD("clear"), &AStar::clear);
- ClassDB::bind_method(D_METHOD("get_closest_point", "to_pos"), &AStar::get_closest_point);
- ClassDB::bind_method(D_METHOD("get_closest_pos_in_segment", "to_pos"), &AStar::get_closest_pos_in_segment);
+ ClassDB::bind_method(D_METHOD("get_closest_point", "to_position"), &AStar::get_closest_point);
+ ClassDB::bind_method(D_METHOD("get_closest_position_in_segment", "to_position"), &AStar::get_closest_position_in_segment);
ClassDB::bind_method(D_METHOD("get_point_path", "from_id", "to_id"), &AStar::get_point_path);
ClassDB::bind_method(D_METHOD("get_id_path", "from_id", "to_id"), &AStar::get_id_path);
diff --git a/core/math/a_star.h b/core/math/a_star.h
index 38d13d510b..2c1e2e2cf7 100644
--- a/core/math/a_star.h
+++ b/core/math/a_star.h
@@ -101,7 +101,7 @@ public:
int get_available_point_id() const;
void add_point(int p_id, const Vector3 &p_pos, real_t p_weight_scale = 1);
- Vector3 get_point_pos(int p_id) const;
+ Vector3 get_point_position(int p_id) const;
real_t get_point_weight_scale(int p_id) const;
void remove_point(int p_id);
bool has_point(int p_id) const;
@@ -114,7 +114,7 @@ public:
void clear();
int get_closest_point(const Vector3 &p_point) const;
- Vector3 get_closest_pos_in_segment(const Vector3 &p_point) const;
+ Vector3 get_closest_position_in_segment(const Vector3 &p_point) const;
PoolVector<Vector3> get_point_path(int p_from_id, int p_to_id);
PoolVector<int> get_id_path(int p_from_id, int p_to_id);
diff --git a/core/math/camera_matrix.cpp b/core/math/camera_matrix.cpp
index 7132b6573e..2c587762e8 100644
--- a/core/math/camera_matrix.cpp
+++ b/core/math/camera_matrix.cpp
@@ -577,7 +577,7 @@ real_t CameraMatrix::get_fov() const {
if ((matrix[8] == 0) && (matrix[9] == 0)) {
return Math::rad2deg(Math::acos(Math::abs(right_plane.normal.x))) * 2.0;
} else {
- // our frustum is asymetrical need to calculate the left planes angle seperately..
+ // our frustum is asymmetrical need to calculate the left planes angle separately..
Plane left_plane = Plane(matrix[3] + matrix[0],
matrix[7] + matrix[4],
matrix[11] + matrix[8],
diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h
index 9651e37f3e..d63da322a5 100644
--- a/core/math/math_funcs.h
+++ b/core/math/math_funcs.h
@@ -104,8 +104,44 @@ public:
static _ALWAYS_INLINE_ double exp(double p_x) { return ::exp(p_x); }
static _ALWAYS_INLINE_ float exp(float p_x) { return ::expf(p_x); }
- static _ALWAYS_INLINE_ bool is_nan(double p_val) { return (p_val != p_val); }
- static _ALWAYS_INLINE_ bool is_nan(float p_val) { return (p_val != p_val); }
+ static _ALWAYS_INLINE_ bool is_nan(double p_val) {
+#ifdef _MSC_VER
+ return _isnan(p_val);
+#elif defined(__GNUC__) && __GNUC__ < 6
+ union {
+ uint64_t u;
+ double f;
+ } ieee754;
+ ieee754.f = p_val;
+ // (unsigned)(0x7ff0000000000001 >> 32) : 0x7ff00000
+ return ((((unsigned)(ieee754.u >> 32) & 0x7fffffff) + ((unsigned)ieee754.u != 0)) > 0x7ff00000);
+#else
+ return isnan(p_val);
+#endif
+ }
+
+ static _ALWAYS_INLINE_ bool is_nan(float p_val) {
+#ifdef _MSC_VER
+ return _isnan(p_val);
+#elif defined(__GNUC__) && __GNUC__ < 6
+ union {
+ uint32_t u;
+ float f;
+ } ieee754;
+ ieee754.f = p_val;
+ // -----------------------------------
+ // (single-precision floating-point)
+ // NaN : s111 1111 1xxx xxxx xxxx xxxx xxxx xxxx
+ // : (> 0x7f800000)
+ // where,
+ // s : sign
+ // x : non-zero number
+ // -----------------------------------
+ return ((ieee754.u & 0x7fffffff) > 0x7f800000);
+#else
+ return isnan(p_val);
+#endif
+ }
static _ALWAYS_INLINE_ bool is_inf(double p_val) {
#ifdef _MSC_VER
diff --git a/core/oa_hash_map.h b/core/oa_hash_map.h
new file mode 100644
index 0000000000..66a1e348a1
--- /dev/null
+++ b/core/oa_hash_map.h
@@ -0,0 +1,593 @@
+/*************************************************************************/
+/* oa_hash_map.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+#ifndef OA_HASH_MAP_H
+#define OA_HASH_MAP_H
+
+#include "hashfuncs.h"
+#include "math_funcs.h"
+#include "os/copymem.h"
+#include "os/memory.h"
+
+// uncomment this to disable intial local storage.
+#define OA_HASH_MAP_INITIAL_LOCAL_STORAGE
+
+/**
+ * This class implements a hash map datastructure that uses open addressing with
+ * local probing.
+ *
+ * It can give huge performance improvements over a chained HashMap because of
+ * the increased data locality.
+ *
+ * Because of that locality property it's important to not use "large" value
+ * types as the "TData" type. If TData values are too big it can cause more
+ * cache misses then chaining. If larger values are needed then storing those
+ * in a separate array and using pointers or indices to reference them is the
+ * better solution.
+ *
+ * This hash map also implements real-time incremental rehashing.
+ *
+ */
+template <class TKey, class TData,
+ uint16_t INITIAL_NUM_ELEMENTS = 64,
+ class Hasher = HashMapHasherDefault,
+ class Comparator = HashMapComparatorDefault<TKey> >
+class OAHashMap {
+
+private:
+#ifdef OA_HASH_MAP_INITIAL_LOCAL_STORAGE
+ TData local_data[INITIAL_NUM_ELEMENTS];
+ TKey local_keys[INITIAL_NUM_ELEMENTS];
+ uint32_t local_hashes[INITIAL_NUM_ELEMENTS];
+ uint8_t local_flags[INITIAL_NUM_ELEMENTS / 4 + (INITIAL_NUM_ELEMENTS % 4 != 0 ? 1 : 0)];
+#endif
+
+ struct {
+ TData *data;
+ TKey *keys;
+ uint32_t *hashes;
+
+ // This is actually an array of bits, 4 bit pairs per octet.
+ // | ba ba ba ba | ba ba ba ba | ....
+ //
+ // if a is set it means that there is an element present.
+ // if b is set it means that an element was deleted. This is needed for
+ // the local probing to work without relocating any succeeding and
+ // colliding entries.
+ uint8_t *flags;
+
+ uint32_t capacity;
+ } table, old_table;
+
+ bool is_rehashing;
+ uint32_t rehash_position;
+ uint32_t rehash_amount;
+
+ uint32_t elements;
+
+ /* Methods */
+
+ // returns true if the value already existed, false if it's a new entry
+ bool _raw_set_with_hash(uint32_t p_hash, const TKey &p_key, const TData &p_data) {
+ for (int i = 0; i < table.capacity; i++) {
+
+ int pos = (p_hash + i) % table.capacity;
+
+ int flags_pos = pos / 4;
+ int flags_pos_offset = pos % 4;
+
+ bool is_filled_flag = table.flags[flags_pos] & (1 << (2 * flags_pos_offset));
+ bool is_deleted_flag = table.flags[flags_pos] & (1 << (2 * flags_pos_offset + 1));
+
+ if (is_filled_flag) {
+ if (table.hashes[pos] == p_hash && Comparator::compare(table.keys[pos], p_key)) {
+ table.data[pos] = p_data;
+ return true;
+ }
+ continue;
+ }
+
+ table.keys[pos] = p_key;
+ table.data[pos] = p_data;
+ table.hashes[pos] = p_hash;
+
+ table.flags[flags_pos] |= (1 << (2 * flags_pos_offset));
+ table.flags[flags_pos] &= ~(1 << (2 * flags_pos_offset + 1));
+
+ return false;
+ }
+ return false;
+ }
+
+public:
+ _FORCE_INLINE_ uint32_t get_capacity() const { return table.capacity; }
+ _FORCE_INLINE_ uint32_t get_num_elements() const { return elements; }
+
+ void set(const TKey &p_key, const TData &p_data) {
+
+ uint32_t hash = Hasher::hash(p_key);
+
+ // We don't progress the rehashing if the table just got resized
+ // to keep the cost of this function low.
+ if (is_rehashing) {
+
+ // rehash progress
+
+ for (int i = 0; i <= rehash_amount && rehash_position < old_table.capacity; rehash_position++) {
+
+ int flags_pos = rehash_position / 4;
+ int flags_pos_offset = rehash_position % 4;
+
+ bool is_filled_flag = (old_table.flags[flags_pos] & (1 << (2 * flags_pos_offset))) > 0;
+ bool is_deleted_flag = (old_table.flags[flags_pos] & (1 << (2 * flags_pos_offset + 1))) > 0;
+
+ if (is_filled_flag) {
+ _raw_set_with_hash(old_table.hashes[rehash_position], old_table.keys[rehash_position], old_table.data[rehash_position]);
+
+ old_table.keys[rehash_position].~TKey();
+ old_table.data[rehash_position].~TData();
+
+ memnew_placement(&old_table.keys[rehash_position], TKey);
+ memnew_placement(&old_table.data[rehash_position], TData);
+
+ old_table.flags[flags_pos] &= ~(1 << (2 * flags_pos_offset));
+ old_table.flags[flags_pos] |= (1 << (2 * flags_pos_offset + 1));
+ }
+ }
+
+ if (rehash_position >= old_table.capacity) {
+
+ // wohooo, we can get rid of the old table.
+ is_rehashing = false;
+
+#ifdef OA_HASH_MAP_INITIAL_LOCAL_STORAGE
+ if (old_table.data == local_data) {
+ // Everything is local, so no cleanup :P
+ } else
+#endif
+ {
+ memdelete_arr(old_table.data);
+ memdelete_arr(old_table.keys);
+ memdelete_arr(old_table.hashes);
+ memdelete_arr(old_table.flags);
+ }
+ }
+ }
+
+ // Table is almost full, resize and start rehashing process.
+ if (elements >= table.capacity * 0.7) {
+
+ old_table.capacity = table.capacity;
+ old_table.data = table.data;
+ old_table.flags = table.flags;
+ old_table.hashes = table.hashes;
+ old_table.keys = table.keys;
+
+ table.capacity = old_table.capacity * 2;
+
+ table.data = memnew_arr(TData, table.capacity);
+ table.flags = memnew_arr(uint8_t, table.capacity / 4 + (table.capacity % 4 != 0 ? 1 : 0));
+ table.hashes = memnew_arr(uint32_t, table.capacity);
+ table.keys = memnew_arr(TKey, table.capacity);
+
+ zeromem(table.flags, table.capacity / 4 + (table.capacity % 4 != 0 ? 1 : 0));
+
+ is_rehashing = true;
+ rehash_position = 0;
+ rehash_amount = (elements * 2) / (table.capacity * 0.7 - old_table.capacity);
+ }
+
+ if (!_raw_set_with_hash(hash, p_key, p_data))
+ elements++;
+ }
+
+ /**
+ * returns true if the value was found, false otherwise.
+ *
+ * if r_data is not NULL then the value will be written to the object
+ * it points to.
+ */
+ bool lookup(const TKey &p_key, TData *r_data) {
+
+ uint32_t hash = Hasher::hash(p_key);
+
+ bool check_old_table = is_rehashing;
+ bool check_new_table = true;
+
+ // search for the key and return the value associated with it
+ //
+ // if we're rehashing we need to check both the old and the
+ // current table. If we find a value in the old table we still
+ // need to continue searching in the new table as it might have
+ // been added after
+
+ TData *value = NULL;
+
+ for (int i = 0; i < table.capacity; i++) {
+
+ if (!check_new_table && !check_old_table) {
+
+ break;
+ }
+
+ // if we're rehashing check the old table
+ if (check_old_table && i < old_table.capacity) {
+
+ int pos = (hash + i) % old_table.capacity;
+
+ int flags_pos = pos / 4;
+ int flags_pos_offset = pos % 4;
+
+ bool is_filled_flag = (old_table.flags[flags_pos] & (1 << (2 * flags_pos_offset))) > 0;
+ bool is_deleted_flag = (old_table.flags[flags_pos] & (1 << (2 * flags_pos_offset + 1))) > 0;
+
+ if (is_filled_flag) {
+ // found our entry?
+ if (old_table.hashes[pos] == hash && Comparator::compare(old_table.keys[pos], p_key)) {
+ value = &old_table.data[pos];
+ check_old_table = false;
+ }
+ } else if (!is_deleted_flag) {
+
+ // we hit an empty field here, we don't
+ // need to further check this old table
+ // because we know it's not in here.
+
+ check_old_table = false;
+ }
+ }
+
+ if (check_new_table) {
+
+ int pos = (hash + i) % table.capacity;
+
+ int flags_pos = pos / 4;
+ int flags_pos_offset = pos % 4;
+
+ bool is_filled_flag = (table.flags[flags_pos] & (1 << (2 * flags_pos_offset))) > 0;
+ bool is_deleted_flag = (table.flags[flags_pos] & (1 << (2 * flags_pos_offset + 1))) > 0;
+
+ if (is_filled_flag) {
+ // found our entry?
+ if (table.hashes[pos] == hash && Comparator::compare(table.keys[pos], p_key)) {
+ if (r_data != NULL)
+ *r_data = table.data[pos];
+ return true;
+ }
+ continue;
+ } else if (is_deleted_flag) {
+ continue;
+ } else if (value != NULL) {
+
+ // We found a value in the old table
+ if (r_data != NULL)
+ *r_data = *value;
+ return true;
+ } else {
+ check_new_table = false;
+ }
+ }
+ }
+
+ if (value != NULL) {
+ if (r_data != NULL)
+ *r_data = *value;
+ return true;
+ }
+ return false;
+ }
+
+ _FORCE_INLINE_ bool has(const TKey &p_key) {
+ return lookup(p_key, NULL);
+ }
+
+ void remove(const TKey &p_key) {
+ uint32_t hash = Hasher::hash(p_key);
+
+ bool check_old_table = is_rehashing;
+ bool check_new_table = true;
+
+ for (int i = 0; i < table.capacity; i++) {
+
+ if (!check_new_table && !check_old_table) {
+ return;
+ }
+
+ // if we're rehashing check the old table
+ if (check_old_table && i < old_table.capacity) {
+
+ int pos = (hash + i) % old_table.capacity;
+
+ int flags_pos = pos / 4;
+ int flags_pos_offset = pos % 4;
+
+ bool is_filled_flag = (old_table.flags[flags_pos] & (1 << (2 * flags_pos_offset))) > 0;
+ bool is_deleted_flag = (old_table.flags[flags_pos] & (1 << (2 * flags_pos_offset + 1))) > 0;
+
+ if (is_filled_flag) {
+ // found our entry?
+ if (old_table.hashes[pos] == hash && Comparator::compare(old_table.keys[pos], p_key)) {
+ old_table.keys[pos].~TKey();
+ old_table.data[pos].~TData();
+
+ memnew_placement(&old_table.keys[pos], TKey);
+ memnew_placement(&old_table.data[pos], TData);
+
+ old_table.flags[flags_pos] &= ~(1 << (2 * flags_pos_offset));
+ old_table.flags[flags_pos] |= (1 << (2 * flags_pos_offset + 1));
+
+ elements--;
+ return;
+ }
+ } else if (!is_deleted_flag) {
+
+ // we hit an empty field here, we don't
+ // need to further check this old table
+ // because we know it's not in here.
+
+ check_old_table = false;
+ }
+ }
+
+ if (check_new_table) {
+
+ int pos = (hash + i) % table.capacity;
+
+ int flags_pos = pos / 4;
+ int flags_pos_offset = pos % 4;
+
+ bool is_filled_flag = (table.flags[flags_pos] & (1 << (2 * flags_pos_offset))) > 0;
+ bool is_deleted_flag = (table.flags[flags_pos] & (1 << (2 * flags_pos_offset + 1))) > 0;
+
+ if (is_filled_flag) {
+ // found our entry?
+ if (table.hashes[pos] == hash && Comparator::compare(table.keys[pos], p_key)) {
+ table.keys[pos].~TKey();
+ table.data[pos].~TData();
+
+ memnew_placement(&table.keys[pos], TKey);
+ memnew_placement(&table.data[pos], TData);
+
+ table.flags[flags_pos] &= ~(1 << (2 * flags_pos_offset));
+ table.flags[flags_pos] |= (1 << (2 * flags_pos_offset + 1));
+
+ // don't return here, this value might still be in the old table
+ // if it was already relocated.
+
+ elements--;
+ return;
+ }
+ continue;
+ } else if (is_deleted_flag) {
+ continue;
+ } else {
+ check_new_table = false;
+ }
+ }
+ }
+ }
+
+ struct Iterator {
+ bool valid;
+
+ uint32_t hash;
+
+ const TKey *key;
+ const TData *data;
+
+ private:
+ friend class OAHashMap;
+ bool was_from_old_table;
+ };
+
+ Iterator iter() const {
+ Iterator it;
+
+ it.valid = false;
+ it.was_from_old_table = false;
+
+ bool check_old_table = is_rehashing;
+
+ for (int i = 0; i < table.capacity; i++) {
+
+ // if we're rehashing check the old table first
+ if (check_old_table && i < old_table.capacity) {
+
+ int pos = i;
+
+ int flags_pos = pos / 4;
+ int flags_pos_offset = pos % 4;
+
+ bool is_filled_flag = (old_table.flags[flags_pos] & (1 << (2 * flags_pos_offset))) > 0;
+
+ if (is_filled_flag) {
+ it.valid = true;
+ it.hash = old_table.hashes[pos];
+ it.data = &old_table.data[pos];
+ it.key = &old_table.keys[pos];
+
+ it.was_from_old_table = true;
+
+ return it;
+ }
+ }
+
+ {
+
+ int pos = i;
+
+ int flags_pos = pos / 4;
+ int flags_pos_offset = pos % 4;
+
+ bool is_filled_flag = (table.flags[flags_pos] & (1 << (2 * flags_pos_offset))) > 0;
+
+ if (is_filled_flag) {
+ it.valid = true;
+ it.hash = table.hashes[pos];
+ it.data = &table.data[pos];
+ it.key = &table.keys[pos];
+
+ return it;
+ }
+ }
+ }
+
+ return it;
+ }
+
+ Iterator next_iter(const Iterator &p_iter) const {
+ if (!p_iter.valid) {
+ return p_iter;
+ }
+
+ Iterator it;
+
+ it.valid = false;
+ it.was_from_old_table = false;
+
+ bool check_old_table = is_rehashing;
+
+ // we use this to skip the first check or not
+ bool was_from_old_table = p_iter.was_from_old_table;
+
+ int prev_index = (p_iter.data - (p_iter.was_from_old_table ? old_table.data : table.data));
+
+ if (!was_from_old_table) {
+ prev_index++;
+ }
+
+ for (int i = prev_index; i < table.capacity; i++) {
+
+ // if we're rehashing check the old table first
+ if (check_old_table && i < old_table.capacity && !was_from_old_table) {
+
+ int pos = i;
+
+ int flags_pos = pos / 4;
+ int flags_pos_offset = pos % 4;
+
+ bool is_filled_flag = (old_table.flags[flags_pos] & (1 << (2 * flags_pos_offset))) > 0;
+
+ if (is_filled_flag) {
+ it.valid = true;
+ it.hash = old_table.hashes[pos];
+ it.data = &old_table.data[pos];
+ it.key = &old_table.keys[pos];
+
+ it.was_from_old_table = true;
+
+ return it;
+ }
+ }
+
+ was_from_old_table = false;
+
+ {
+ int pos = i;
+
+ int flags_pos = pos / 4;
+ int flags_pos_offset = pos % 4;
+
+ bool is_filled_flag = (table.flags[flags_pos] & (1 << (2 * flags_pos_offset))) > 0;
+
+ if (is_filled_flag) {
+ it.valid = true;
+ it.hash = table.hashes[pos];
+ it.data = &table.data[pos];
+ it.key = &table.keys[pos];
+
+ return it;
+ }
+ }
+ }
+
+ return it;
+ }
+
+ OAHashMap(uint32_t p_initial_capacity = INITIAL_NUM_ELEMENTS) {
+
+#ifdef OA_HASH_MAP_INITIAL_LOCAL_STORAGE
+
+ if (p_initial_capacity <= INITIAL_NUM_ELEMENTS) {
+ table.data = local_data;
+ table.keys = local_keys;
+ table.hashes = local_hashes;
+ table.flags = local_flags;
+
+ zeromem(table.flags, INITIAL_NUM_ELEMENTS / 4 + (INITIAL_NUM_ELEMENTS % 4 != 0 ? 1 : 0));
+
+ table.capacity = INITIAL_NUM_ELEMENTS;
+ elements = 0;
+ } else
+#endif
+ {
+ table.data = memnew_arr(TData, p_initial_capacity);
+ table.keys = memnew_arr(TKey, p_initial_capacity);
+ table.hashes = memnew_arr(uint32_t, p_initial_capacity);
+ table.flags = memnew_arr(uint8_t, p_initial_capacity / 4 + (p_initial_capacity % 4 != 0 ? 1 : 0));
+
+ zeromem(table.flags, p_initial_capacity / 4 + (p_initial_capacity % 4 != 0 ? 1 : 0));
+
+ table.capacity = p_initial_capacity;
+ elements = 0;
+ }
+
+ is_rehashing = false;
+ rehash_position = 0;
+ }
+
+ ~OAHashMap() {
+#ifdef OA_HASH_MAP_INITIAL_LOCAL_STORAGE
+ if (table.capacity <= INITIAL_NUM_ELEMENTS) {
+ return; // Everything is local, so no cleanup :P
+ }
+#endif
+ if (is_rehashing) {
+
+#ifdef OA_HASH_MAP_INITIAL_LOCAL_STORAGE
+ if (old_table.data == local_data) {
+ // Everything is local, so no cleanup :P
+ } else
+#endif
+ {
+ memdelete_arr(old_table.data);
+ memdelete_arr(old_table.keys);
+ memdelete_arr(old_table.hashes);
+ memdelete_arr(old_table.flags);
+ }
+ }
+
+ memdelete_arr(table.data);
+ memdelete_arr(table.keys);
+ memdelete_arr(table.hashes);
+ memdelete_arr(table.flags);
+ }
+};
+
+#endif
diff --git a/core/os/dir_access.cpp b/core/os/dir_access.cpp
index 1437e7cdfc..0875f78478 100644
--- a/core/os/dir_access.cpp
+++ b/core/os/dir_access.cpp
@@ -312,7 +312,7 @@ Error DirAccess::copy(String p_from, String p_to, int chmod_flags) {
}
fsrc->seek_end(0);
- int size = fsrc->get_pos();
+ int size = fsrc->get_position();
fsrc->seek(0);
err = OK;
while (size--) {
diff --git a/core/os/file_access.h b/core/os/file_access.h
index 151c41c263..34e7549fa3 100644
--- a/core/os/file_access.h
+++ b/core/os/file_access.h
@@ -90,7 +90,7 @@ public:
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_pos() const = 0; ///< get position in the file
+ virtual size_t get_position() const = 0; ///< get position in the file
virtual size_t get_len() const = 0; ///< get size of the file
virtual bool eof_reached() const = 0; ///< reading passed EOF
@@ -140,7 +140,7 @@ public:
virtual Error reopen(const String &p_path, int p_mode_flags); ///< does not change the AccessType
- virtual Error _chmod(const String &p_path, int p_mod) {}
+ virtual Error _chmod(const String &p_path, int p_mod) { return FAILED; }
static FileAccess *create(AccessType p_access); /// Create a file access (for the current platform) this is the only portable way of accessing files.
static FileAccess *create_for_path(const String &p_path);
diff --git a/core/os/input.cpp b/core/os/input.cpp
index 65752662d7..a4b82299a7 100644
--- a/core/os/input.cpp
+++ b/core/os/input.cpp
@@ -80,7 +80,7 @@ void Input::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_mouse_button_mask"), &Input::get_mouse_button_mask);
ClassDB::bind_method(D_METHOD("set_mouse_mode", "mode"), &Input::set_mouse_mode);
ClassDB::bind_method(D_METHOD("get_mouse_mode"), &Input::get_mouse_mode);
- ClassDB::bind_method(D_METHOD("warp_mouse_pos", "to"), &Input::warp_mouse_pos);
+ ClassDB::bind_method(D_METHOD("warp_mouse_position", "to"), &Input::warp_mouse_position);
ClassDB::bind_method(D_METHOD("action_press", "action"), &Input::action_press);
ClassDB::bind_method(D_METHOD("action_release", "action"), &Input::action_release);
ClassDB::bind_method(D_METHOD("set_custom_mouse_cursor", "image", "hotspot"), &Input::set_custom_mouse_cursor, DEFVAL(Vector2()));
diff --git a/core/os/input.h b/core/os/input.h
index f98b97e647..97d3bef4f9 100644
--- a/core/os/input.h
+++ b/core/os/input.h
@@ -81,7 +81,7 @@ public:
virtual Point2 get_last_mouse_speed() const = 0;
virtual int get_mouse_button_mask() const = 0;
- virtual void warp_mouse_pos(const Vector2 &p_to) = 0;
+ virtual void warp_mouse_position(const Vector2 &p_to) = 0;
virtual Point2i warp_mouse_motion(const Ref<InputEventMouseMotion> &p_motion, const Rect2 &p_rect) = 0;
virtual Vector3 get_gravity() const = 0;
diff --git a/core/os/input_event.cpp b/core/os/input_event.cpp
index 88037859aa..bef98ac3f2 100644
--- a/core/os/input_event.cpp
+++ b/core/os/input_event.cpp
@@ -781,7 +781,7 @@ void InputEventScreenTouch::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_index", "index"), &InputEventScreenTouch::set_index);
ClassDB::bind_method(D_METHOD("get_index"), &InputEventScreenTouch::get_index);
- ClassDB::bind_method(D_METHOD("set_position", "pos"), &InputEventScreenTouch::set_position);
+ ClassDB::bind_method(D_METHOD("set_position", "position"), &InputEventScreenTouch::set_position);
ClassDB::bind_method(D_METHOD("get_position"), &InputEventScreenTouch::get_position);
ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventScreenTouch::set_pressed);
diff --git a/core/os/os.h b/core/os/os.h
index 2fc87e44a0..38bbbc0a57 100644
--- a/core/os/os.h
+++ b/core/os/os.h
@@ -156,7 +156,7 @@ public:
virtual void set_mouse_mode(MouseMode p_mode);
virtual MouseMode get_mouse_mode() const;
- virtual void warp_mouse_pos(const Point2 &p_to) {}
+ virtual void warp_mouse_position(const Point2 &p_to) {}
virtual Point2 get_mouse_position() const = 0;
virtual int get_mouse_button_state() const = 0;
virtual void set_window_title(const String &p_title) = 0;
diff --git a/core/project_settings.cpp b/core/project_settings.cpp
index 7ea0d563a6..14ebe87dc5 100644
--- a/core/project_settings.cpp
+++ b/core/project_settings.cpp
@@ -910,7 +910,7 @@ Variant ProjectSettings::property_get_revert(const String &p_name) {
void ProjectSettings::_bind_methods() {
ClassDB::bind_method(D_METHOD("has", "name"), &ProjectSettings::has);
- ClassDB::bind_method(D_METHOD("set_order", "name", "pos"), &ProjectSettings::set_order);
+ ClassDB::bind_method(D_METHOD("set_order", "name", "position"), &ProjectSettings::set_order);
ClassDB::bind_method(D_METHOD("get_order", "name"), &ProjectSettings::get_order);
ClassDB::bind_method(D_METHOD("set_initial_value", "name", "value"), &ProjectSettings::set_initial_value);
ClassDB::bind_method(D_METHOD("add_property_info", "hint"), &ProjectSettings::_add_property_info_bind);
diff --git a/core/set.h b/core/set.h
index f68d78cea1..d91dd9b3ea 100644
--- a/core/set.h
+++ b/core/set.h
@@ -135,7 +135,6 @@ private:
#ifdef GLOBALNIL_DISABLED
memdelete_allocator<Element, A>(_nil);
#endif
- //memdelete_allocator<Element,A>(_root);
}
};
@@ -146,6 +145,7 @@ private:
ERR_FAIL_COND(p_node == _data._nil && p_color == RED);
p_node->color = p_color;
}
+
inline void _rotate_left(Element *p_node) {
Element *r = p_node->right;
@@ -194,8 +194,9 @@ private:
while (node == node->parent->right) {
node = node->parent;
}
+
if (node->parent == _data._root)
- return NULL;
+ return NULL; // No successor, as p_node is the last node.
return node->parent;
}
}
@@ -213,11 +214,11 @@ private:
} else {
while (node == node->parent->left) {
- if (node->parent == _data._root)
- return NULL;
-
node = node->parent;
}
+
+ if (node == _data._root)
+ return NULL; // No predecessor, as p_node is the first node.
return node->parent;
}
}
@@ -228,16 +229,15 @@ private:
C less;
while (node != _data._nil) {
-
if (less(p_value, node->value))
node = node->left;
else if (less(node->value, p_value))
node = node->right;
else
- break; // found
+ return node; // found
}
- return (node != _data._nil) ? node : NULL;
+ return NULL;
}
Element *_lower_bound(const T &p_value) const {
@@ -254,21 +254,16 @@ private:
else if (less(node->value, p_value))
node = node->right;
else
- break; // found
+ return node; // found
}
- if (node == _data._nil) {
- if (prev == NULL)
- return NULL;
- if (less(prev->value, p_value)) {
-
- prev = prev->_next;
- }
+ if (prev == NULL)
+ return NULL; // tree empty
- return prev;
+ if (less(prev->value, p_value))
+ prev = prev->_next;
- } else
- return node;
+ return prev;
}
Element *_insert(const T &p_value, bool &r_exists) {
@@ -291,22 +286,21 @@ private:
}
}
- Element *new_node = memnew_allocator(Element, A);
+ r_exists = false;
+ Element *new_node = memnew_allocator(Element, A);
new_node->parent = new_parent;
new_node->right = _data._nil;
new_node->left = _data._nil;
new_node->value = p_value;
//new_node->data=_data;
- if (new_parent == _data._root || less(p_value, new_parent->value)) {
+ if (new_parent == _data._root || less(p_value, new_parent->value)) {
new_parent->left = new_node;
} else {
new_parent->right = new_node;
}
- r_exists = false;
-
new_node->_next = _successor(new_node);
new_node->_prev = _predecessor(new_node);
if (new_node->_next)
@@ -324,154 +318,159 @@ private:
if (exists)
return new_node;
- Element *node = new_node;
_data.size_cache++;
+ Element *node = new_node;
+ Element *nparent = node->parent;
+ Element *ngrand_parent;
- while (node->parent->color == RED) {
-
- if (node->parent == node->parent->parent->left) {
+ while (nparent->color == RED) {
- Element *aux = node->parent->parent->right;
+ ngrand_parent = nparent->parent;
- if (aux->color == RED) {
- _set_color(node->parent, BLACK);
- _set_color(aux, BLACK);
- _set_color(node->parent->parent, RED);
- node = node->parent->parent;
+ if (nparent == ngrand_parent->left) {
+ if (ngrand_parent->right->color == RED) {
+ _set_color(nparent, BLACK);
+ _set_color(ngrand_parent->right, BLACK);
+ _set_color(ngrand_parent, RED);
+ node = ngrand_parent;
+ nparent = node->parent;
} else {
- if (node == node->parent->right) {
- node = node->parent;
- _rotate_left(node);
+ if (node == nparent->right) {
+ _rotate_left(nparent);
+ node = nparent;
+ nparent = node->parent;
}
- _set_color(node->parent, BLACK);
- _set_color(node->parent->parent, RED);
- _rotate_right(node->parent->parent);
+ _set_color(nparent, BLACK);
+ _set_color(ngrand_parent, RED);
+ _rotate_right(ngrand_parent);
}
} else {
- Element *aux = node->parent->parent->left;
-
- if (aux->color == RED) {
- _set_color(node->parent, BLACK);
- _set_color(aux, BLACK);
- _set_color(node->parent->parent, RED);
- node = node->parent->parent;
+ if (ngrand_parent->left->color == RED) {
+ _set_color(nparent, BLACK);
+ _set_color(ngrand_parent->left, BLACK);
+ _set_color(ngrand_parent, RED);
+ node = ngrand_parent;
+ nparent = node->parent;
} else {
- if (node == node->parent->left) {
- node = node->parent;
- _rotate_right(node);
+ if (node == nparent->left) {
+ _rotate_right(nparent);
+ node = nparent;
+ nparent = node->parent;
}
- _set_color(node->parent, BLACK);
- _set_color(node->parent->parent, RED);
- _rotate_left(node->parent->parent);
+ _set_color(nparent, BLACK);
+ _set_color(ngrand_parent, RED);
+ _rotate_left(ngrand_parent);
}
}
}
+
_set_color(_data._root->left, BLACK);
+
return new_node;
}
void _erase_fix(Element *p_node) {
Element *root = _data._root->left;
- Element *node = p_node;
-
- while ((node->color == BLACK) && (root != node)) {
- if (node == node->parent->left) {
- Element *aux = node->parent->right;
- if (aux->color == RED) {
- _set_color(aux, BLACK);
- _set_color(node->parent, RED);
- _rotate_left(node->parent);
- aux = node->parent->right;
- }
- if ((aux->right->color == BLACK) && (aux->left->color == BLACK)) {
- _set_color(aux, RED);
- node = node->parent;
+ Element *node = _data._nil;
+ Element *sibling = p_node;
+ Element *parent = sibling->parent;
+
+ while (node != root) { // If red node found, will exit at a break
+ if (sibling->color == RED) {
+ _set_color(sibling, BLACK);
+ _set_color(parent, RED);
+ if (sibling == parent->right) {
+ sibling = sibling->left;
+ _rotate_left(parent);
} else {
- if (aux->right->color == BLACK) {
- _set_color(aux->left, BLACK);
- _set_color(aux, RED);
- _rotate_right(aux);
- aux = node->parent->right;
- }
- _set_color(aux, node->parent->color);
- _set_color(node->parent, BLACK);
- _set_color(aux->right, BLACK);
- _rotate_left(node->parent);
- node = root; /* this is to exit while loop */
+ sibling = sibling->right;
+ _rotate_right(parent);
}
- } else { /* the code below is has left and right switched from above */
- Element *aux = node->parent->left;
- if (aux->color == RED) {
- _set_color(aux, BLACK);
- _set_color(node->parent, RED);
- _rotate_right(node->parent);
- aux = node->parent->left;
+ }
+ if ((sibling->left->color == BLACK) && (sibling->right->color == BLACK)) {
+ _set_color(sibling, RED);
+ if (parent->color == RED) {
+ _set_color(parent, BLACK);
+ break;
+ } else { // loop: haven't found any red nodes yet
+ node = parent;
+ parent = node->parent;
+ sibling = (node == parent->left) ? parent->right : parent->left;
}
- if ((aux->right->color == BLACK) && (aux->left->color == BLACK)) {
- _set_color(aux, RED);
- node = node->parent;
+ } else {
+ if (sibling == parent->right) {
+ if (sibling->right->color == BLACK) {
+ _set_color(sibling->left, BLACK);
+ _set_color(sibling, RED);
+ _rotate_right(sibling);
+ sibling = sibling->parent;
+ }
+ _set_color(sibling, parent->color);
+ _set_color(parent, BLACK);
+ _set_color(sibling->right, BLACK);
+ _rotate_left(parent);
+ break;
} else {
- if (aux->left->color == BLACK) {
- _set_color(aux->right, BLACK);
- _set_color(aux, RED);
- _rotate_left(aux);
- aux = node->parent->left;
+ if (sibling->left->color == BLACK) {
+ _set_color(sibling->right, BLACK);
+ _set_color(sibling, RED);
+ _rotate_left(sibling);
+ sibling = sibling->parent;
}
- _set_color(aux, node->parent->color);
- _set_color(node->parent, BLACK);
- _set_color(aux->left, BLACK);
- _rotate_right(node->parent);
- node = root;
+
+ _set_color(sibling, parent->color);
+ _set_color(parent, BLACK);
+ _set_color(sibling->left, BLACK);
+ _rotate_right(parent);
+ break;
}
}
}
- _set_color(node, BLACK);
-
ERR_FAIL_COND(_data._nil->color != BLACK);
}
void _erase(Element *p_node) {
- Element *rp = ((p_node->left == _data._nil) || (p_node->right == _data._nil)) ? p_node : _successor(p_node);
- if (!rp)
- rp = _data._nil;
+ Element *rp = ((p_node->left == _data._nil) || (p_node->right == _data._nil)) ? p_node : p_node->_next;
Element *node = (rp->left == _data._nil) ? rp->right : rp->left;
node->parent = rp->parent;
- if (_data._root == node->parent) {
- _data._root->left = node;
+ Element *sibling;
+ if (rp == rp->parent->left) {
+ rp->parent->left = node;
+ sibling = rp->parent->right;
} else {
- if (rp == rp->parent->left) {
- rp->parent->left = node;
- } else {
- rp->parent->right = node;
- }
+ rp->parent->right = node;
+ sibling = rp->parent->left;
+ }
+
+ if (node->color == RED) {
+ node->parent = rp->parent;
+ _set_color(node, BLACK);
+ } else if (rp->color == BLACK && rp->parent != _data._root) {
+ _erase_fix(sibling);
}
if (rp != p_node) {
ERR_FAIL_COND(rp == _data._nil);
- if (rp->color == BLACK)
- _erase_fix(node);
-
rp->left = p_node->left;
rp->right = p_node->right;
rp->parent = p_node->parent;
rp->color = p_node->color;
- p_node->left->parent = rp;
- p_node->right->parent = rp;
+ if (p_node->left != _data._nil)
+ p_node->left->parent = rp;
+ if (p_node->right != _data._nil)
+ p_node->right->parent = rp;
if (p_node == p_node->parent->left) {
p_node->parent->left = rp;
} else {
p_node->parent->right = rp;
}
- } else {
- if (p_node->color == BLACK)
- _erase_fix(node);
}
if (p_node->_next)
@@ -529,6 +528,7 @@ public:
if (!_data._root)
return NULL;
+
Element *res = _find(p_value);
return res;
}
@@ -549,8 +549,9 @@ public:
void erase(Element *p_element) {
- if (!_data._root)
+ if (!_data._root || !p_element)
return;
+
_erase(p_element);
if (_data.size_cache == 0 && _data._root)
_data._free_root();
@@ -560,9 +561,11 @@ public:
if (!_data._root)
return false;
+
Element *e = find(p_value);
if (!e)
return false;
+
_erase(e);
if (_data.size_cache == 0 && _data._root)
_data._free_root();
@@ -573,6 +576,7 @@ public:
if (!_data._root)
return NULL;
+
Element *e = _data._root->left;
if (e == _data._nil)
return NULL;
@@ -587,6 +591,7 @@ public:
if (!_data._root)
return NULL;
+
Element *e = _data._root->left;
if (e == _data._nil)
return NULL;
@@ -603,10 +608,12 @@ public:
}
inline int size() const { return _data.size_cache; }
+
int calculate_depth() const {
// used for debug mostly
if (!_data._root)
return 0;
+
int max_d = 0;
_calculate_depth(_data._root->left, max_d, 0);
return max_d;
@@ -620,7 +627,6 @@ public:
_cleanup_tree(_data._root->left);
_data._root->left = _data._nil;
_data.size_cache = 0;
- _data._nil->parent = _data._nil;
_data._free_root();
}
@@ -633,6 +639,7 @@ public:
_copy_from(p_set);
}
+
_FORCE_INLINE_ Set() {
}
diff --git a/core/variant.cpp b/core/variant.cpp
index 10d86152ee..52bdd4e22d 100644
--- a/core/variant.cpp
+++ b/core/variant.cpp
@@ -903,9 +903,6 @@ bool Variant::is_one() const {
void Variant::reference(const Variant &p_variant) {
- if (this == &p_variant)
- return;
-
clear();
type = p_variant.type;
@@ -924,17 +921,14 @@ void Variant::reference(const Variant &p_variant) {
case INT: {
_data._int = p_variant._data._int;
-
} break;
case REAL: {
_data._real = p_variant._data._real;
-
} break;
case STRING: {
memnew_placement(_data._mem, String(*reinterpret_cast<const String *>(p_variant._data._mem)));
-
} break;
// math types
@@ -942,33 +936,24 @@ void Variant::reference(const Variant &p_variant) {
case VECTOR2: {
memnew_placement(_data._mem, Vector2(*reinterpret_cast<const Vector2 *>(p_variant._data._mem)));
-
} break;
case RECT2: {
memnew_placement(_data._mem, Rect2(*reinterpret_cast<const Rect2 *>(p_variant._data._mem)));
-
} break;
case TRANSFORM2D: {
_data._transform2d = memnew(Transform2D(*p_variant._data._transform2d));
-
} break;
case VECTOR3: {
memnew_placement(_data._mem, Vector3(*reinterpret_cast<const Vector3 *>(p_variant._data._mem)));
-
} break;
case PLANE: {
memnew_placement(_data._mem, Plane(*reinterpret_cast<const Plane *>(p_variant._data._mem)));
-
} break;
- /*
- case QUAT: {
-
- } break;*/
case RECT3: {
_data._rect3 = memnew(Rect3(*p_variant._data._rect3));
@@ -986,7 +971,6 @@ void Variant::reference(const Variant &p_variant) {
case TRANSFORM: {
_data._transform = memnew(Transform(*p_variant._data._transform));
-
} break;
// misc types
@@ -1058,6 +1042,7 @@ void Variant::reference(const Variant &p_variant) {
default: {}
}
}
+
void Variant::zero() {
switch (type) {
case NIL: break;
@@ -1073,6 +1058,7 @@ void Variant::zero() {
default: this->clear(); break;
}
}
+
void Variant::clear() {
switch (type) {
@@ -1092,12 +1078,10 @@ void Variant::clear() {
case TRANSFORM2D: {
memdelete(_data._transform2d);
-
} break;
case RECT3: {
memdelete(_data._rect3);
-
} break;
case BASIS: {
@@ -1106,14 +1090,12 @@ void Variant::clear() {
case TRANSFORM: {
memdelete(_data._transform);
-
} break;
// misc types
case NODE_PATH: {
reinterpret_cast<NodePath *>(_data._mem)->~NodePath();
-
} break;
case OBJECT: {
@@ -1127,48 +1109,39 @@ void Variant::clear() {
case DICTIONARY: {
reinterpret_cast<Dictionary *>(_data._mem)->~Dictionary();
-
} break;
case ARRAY: {
reinterpret_cast<Array *>(_data._mem)->~Array();
-
} break;
// arrays
case POOL_BYTE_ARRAY: {
reinterpret_cast<PoolVector<uint8_t> *>(_data._mem)->~PoolVector<uint8_t>();
-
} break;
case POOL_INT_ARRAY: {
reinterpret_cast<PoolVector<int> *>(_data._mem)->~PoolVector<int>();
-
} break;
case POOL_REAL_ARRAY: {
reinterpret_cast<PoolVector<real_t> *>(_data._mem)->~PoolVector<real_t>();
-
} break;
case POOL_STRING_ARRAY: {
reinterpret_cast<PoolVector<String> *>(_data._mem)->~PoolVector<String>();
-
} break;
case POOL_VECTOR2_ARRAY: {
reinterpret_cast<PoolVector<Vector2> *>(_data._mem)->~PoolVector<Vector2>();
-
} break;
case POOL_VECTOR3_ARRAY: {
reinterpret_cast<PoolVector<Vector3> *>(_data._mem)->~PoolVector<Vector3>();
-
} break;
case POOL_COLOR_ARRAY: {
reinterpret_cast<PoolVector<Color> *>(_data._mem)->~PoolVector<Color>();
-
} break;
default: {} /* not needed */
}
@@ -2496,7 +2469,135 @@ Variant::Variant(const Vector<Color> &p_array) {
void Variant::operator=(const Variant &p_variant) {
- reference(p_variant);
+ if (this == &p_variant)
+ return;
+
+ if (type != p_variant.type) {
+ reference(p_variant);
+ return;
+ }
+
+ switch (p_variant.type) {
+ case NIL: {
+
+ // none
+ } break;
+
+ // atomic types
+ case BOOL: {
+
+ _data._bool = p_variant._data._bool;
+ } break;
+ case INT: {
+
+ _data._int = p_variant._data._int;
+ } break;
+ case REAL: {
+
+ _data._real = p_variant._data._real;
+ } break;
+ case STRING: {
+
+ *reinterpret_cast<String *>(_data._mem) = *reinterpret_cast<const String *>(p_variant._data._mem);
+ } break;
+
+ // math types
+
+ case VECTOR2: {
+
+ *reinterpret_cast<Vector2 *>(_data._mem) = *reinterpret_cast<const Vector2 *>(p_variant._data._mem);
+ } break;
+ case RECT2: {
+
+ *reinterpret_cast<Rect2 *>(_data._mem) = *reinterpret_cast<const Rect2 *>(p_variant._data._mem);
+ } break;
+ case TRANSFORM2D: {
+
+ *_data._transform2d = *(p_variant._data._transform2d);
+ } break;
+ case VECTOR3: {
+
+ *reinterpret_cast<Vector3 *>(_data._mem) = *reinterpret_cast<const Vector3 *>(p_variant._data._mem);
+ } break;
+ case PLANE: {
+
+ *reinterpret_cast<Plane *>(_data._mem) = *reinterpret_cast<const Plane *>(p_variant._data._mem);
+ } break;
+
+ case RECT3: {
+
+ *_data._rect3 = *(p_variant._data._rect3);
+ } break;
+ case QUAT: {
+
+ *reinterpret_cast<Quat *>(_data._mem) = *reinterpret_cast<const Quat *>(p_variant._data._mem);
+ } break;
+ case BASIS: {
+
+ *_data._basis = *(p_variant._data._basis);
+ } break;
+ case TRANSFORM: {
+
+ *_data._transform = *(p_variant._data._transform);
+ } break;
+
+ // misc types
+ case COLOR: {
+
+ *reinterpret_cast<Color *>(_data._mem) = *reinterpret_cast<const Color *>(p_variant._data._mem);
+ } break;
+ case _RID: {
+
+ *reinterpret_cast<RID *>(_data._mem) = *reinterpret_cast<const RID *>(p_variant._data._mem);
+ } break;
+ case OBJECT: {
+
+ *reinterpret_cast<ObjData *>(_data._mem) = p_variant._get_obj();
+ } break;
+ case NODE_PATH: {
+
+ *reinterpret_cast<NodePath *>(_data._mem) = *reinterpret_cast<const NodePath *>(p_variant._data._mem);
+ } break;
+ case DICTIONARY: {
+
+ *reinterpret_cast<Dictionary *>(_data._mem) = *reinterpret_cast<const Dictionary *>(p_variant._data._mem);
+ } break;
+ case ARRAY: {
+
+ *reinterpret_cast<Array *>(_data._mem) = *reinterpret_cast<const Array *>(p_variant._data._mem);
+ } break;
+
+ // arrays
+ case POOL_BYTE_ARRAY: {
+
+ *reinterpret_cast<PoolVector<uint8_t> *>(_data._mem) = *reinterpret_cast<const PoolVector<uint8_t> *>(p_variant._data._mem);
+ } break;
+ case POOL_INT_ARRAY: {
+
+ *reinterpret_cast<PoolVector<int> *>(_data._mem) = *reinterpret_cast<const PoolVector<int> *>(p_variant._data._mem);
+ } break;
+ case POOL_REAL_ARRAY: {
+
+ *reinterpret_cast<PoolVector<real_t> *>(_data._mem) = *reinterpret_cast<const PoolVector<real_t> *>(p_variant._data._mem);
+ } break;
+ case POOL_STRING_ARRAY: {
+
+ *reinterpret_cast<PoolVector<String> *>(_data._mem) = *reinterpret_cast<const PoolVector<String> *>(p_variant._data._mem);
+ } break;
+ case POOL_VECTOR2_ARRAY: {
+
+ *reinterpret_cast<PoolVector<Vector2> *>(_data._mem) = *reinterpret_cast<const PoolVector<Vector2> *>(p_variant._data._mem);
+ } break;
+ case POOL_VECTOR3_ARRAY: {
+
+ *reinterpret_cast<PoolVector<Vector3> *>(_data._mem) = *reinterpret_cast<const PoolVector<Vector3> *>(p_variant._data._mem);
+ } break;
+ case POOL_COLOR_ARRAY: {
+
+ *reinterpret_cast<PoolVector<Color> *>(_data._mem) = *reinterpret_cast<const PoolVector<Color> *>(p_variant._data._mem);
+ } break;
+ default: {}
+ }
}
Variant::Variant(const IP_Address &p_address) {
diff --git a/core/variant.h b/core/variant.h
index edc86dedd4..5ea540a63f 100644
--- a/core/variant.h
+++ b/core/variant.h
@@ -390,7 +390,7 @@ public:
uint32_t hash() const;
bool hash_compare(const Variant &p_variant) const;
- bool booleanize(bool &valid) const;
+ bool booleanize() const;
void static_assign(const Variant &p_variant);
static void get_constructor_list(Variant::Type p_type, List<MethodInfo> *p_list);
diff --git a/core/variant_call.cpp b/core/variant_call.cpp
index 19d9b0297f..7205280938 100644
--- a/core/variant_call.cpp
+++ b/core/variant_call.cpp
@@ -1394,7 +1394,7 @@ void register_variant_methods() {
ADDFUNC2(STRING, STRING, String, format, NIL, "values", STRING, "placeholder", varray("{_}"));
ADDFUNC2(STRING, STRING, String, replace, STRING, "what", STRING, "forwhat", varray());
ADDFUNC2(STRING, STRING, String, replacen, STRING, "what", STRING, "forwhat", varray());
- ADDFUNC2(STRING, STRING, String, insert, INT, "pos", STRING, "what", varray());
+ ADDFUNC2(STRING, STRING, String, insert, INT, "position", STRING, "what", varray());
ADDFUNC0(STRING, STRING, String, capitalize, varray());
ADDFUNC2(STRING, POOL_STRING_ARRAY, String, split, STRING, "divisor", BOOL, "allow_empty", varray(true));
ADDFUNC2(STRING, POOL_REAL_ARRAY, String, split_floats, STRING, "divisor", BOOL, "allow_empty", varray(true));
@@ -1402,14 +1402,14 @@ void register_variant_methods() {
ADDFUNC0(STRING, STRING, String, to_upper, varray());
ADDFUNC0(STRING, STRING, String, to_lower, varray());
- ADDFUNC1(STRING, STRING, String, left, INT, "pos", varray());
- ADDFUNC1(STRING, STRING, String, right, INT, "pos", varray());
+ ADDFUNC1(STRING, STRING, String, left, INT, "position", varray());
+ ADDFUNC1(STRING, STRING, String, right, INT, "position", varray());
ADDFUNC2(STRING, STRING, String, strip_edges, BOOL, "left", BOOL, "right", varray(true, true));
ADDFUNC0(STRING, STRING, String, get_extension, varray());
ADDFUNC0(STRING, STRING, String, get_basename, varray());
ADDFUNC1(STRING, STRING, String, plus_file, STRING, "file", varray());
ADDFUNC1(STRING, INT, String, ord_at, INT, "at", varray());
- ADDFUNC2(STRING, NIL, String, erase, INT, "pos", INT, "chars", varray());
+ ADDFUNC2(STRING, NIL, String, erase, INT, "position", INT, "chars", varray());
ADDFUNC0(STRING, INT, String, hash, varray());
ADDFUNC0(STRING, STRING, String, md5_text, varray());
ADDFUNC0(STRING, STRING, String, sha256_text, varray());
@@ -1560,9 +1560,9 @@ void register_variant_methods() {
ADDFUNC1(ARRAY, NIL, Array, push_back, NIL, "value", varray());
ADDFUNC1(ARRAY, NIL, Array, push_front, NIL, "value", varray());
ADDFUNC1(ARRAY, NIL, Array, append, NIL, "value", varray());
- ADDFUNC1(ARRAY, NIL, Array, resize, INT, "pos", varray());
- ADDFUNC2(ARRAY, NIL, Array, insert, INT, "pos", NIL, "value", varray());
- ADDFUNC1(ARRAY, NIL, Array, remove, INT, "pos", varray());
+ ADDFUNC1(ARRAY, NIL, Array, resize, INT, "size", varray());
+ ADDFUNC2(ARRAY, NIL, Array, insert, INT, "position", NIL, "value", varray());
+ ADDFUNC1(ARRAY, NIL, Array, remove, INT, "position", varray());
ADDFUNC1(ARRAY, NIL, Array, erase, NIL, "value", varray());
ADDFUNC0(ARRAY, NIL, Array, front, varray());
ADDFUNC0(ARRAY, NIL, Array, back, varray());
@@ -1728,10 +1728,10 @@ void register_variant_methods() {
_VariantCall::add_constructor(_VariantCall::Vector2_init1, Variant::VECTOR2, "x", Variant::REAL, "y", Variant::REAL);
- _VariantCall::add_constructor(_VariantCall::Rect2_init1, Variant::RECT2, "pos", Variant::VECTOR2, "size", Variant::VECTOR2);
+ _VariantCall::add_constructor(_VariantCall::Rect2_init1, Variant::RECT2, "position", Variant::VECTOR2, "size", Variant::VECTOR2);
_VariantCall::add_constructor(_VariantCall::Rect2_init2, Variant::RECT2, "x", Variant::REAL, "y", Variant::REAL, "width", Variant::REAL, "height", Variant::REAL);
- _VariantCall::add_constructor(_VariantCall::Transform2D_init2, Variant::TRANSFORM2D, "rot", Variant::REAL, "pos", Variant::VECTOR2);
+ _VariantCall::add_constructor(_VariantCall::Transform2D_init2, Variant::TRANSFORM2D, "rotation", Variant::REAL, "position", Variant::VECTOR2);
_VariantCall::add_constructor(_VariantCall::Transform2D_init3, Variant::TRANSFORM2D, "x_axis", Variant::VECTOR2, "y_axis", Variant::VECTOR2, "origin", Variant::VECTOR2);
_VariantCall::add_constructor(_VariantCall::Vector3_init1, Variant::VECTOR3, "x", Variant::REAL, "y", Variant::REAL, "z", Variant::REAL);
@@ -1746,7 +1746,7 @@ void register_variant_methods() {
_VariantCall::add_constructor(_VariantCall::Color_init1, Variant::COLOR, "r", Variant::REAL, "g", Variant::REAL, "b", Variant::REAL, "a", Variant::REAL);
_VariantCall::add_constructor(_VariantCall::Color_init2, Variant::COLOR, "r", Variant::REAL, "g", Variant::REAL, "b", Variant::REAL);
- _VariantCall::add_constructor(_VariantCall::Rect3_init1, Variant::RECT3, "pos", Variant::VECTOR3, "size", Variant::VECTOR3);
+ _VariantCall::add_constructor(_VariantCall::Rect3_init1, Variant::RECT3, "position", Variant::VECTOR3, "size", Variant::VECTOR3);
_VariantCall::add_constructor(_VariantCall::Basis_init1, Variant::BASIS, "x_axis", Variant::VECTOR3, "y_axis", Variant::VECTOR3, "z_axis", Variant::VECTOR3);
_VariantCall::add_constructor(_VariantCall::Basis_init2, Variant::BASIS, "axis", Variant::VECTOR3, "phi", Variant::REAL);
diff --git a/core/variant_op.cpp b/core/variant_op.cpp
index d67466556d..1c5a4ce8d0 100644
--- a/core/variant_op.cpp
+++ b/core/variant_op.cpp
@@ -143,56 +143,13 @@
Variant::operator bool() const {
- bool b;
- return booleanize(b);
+ return booleanize();
}
-bool Variant::booleanize(bool &r_valid) const {
-
- r_valid = true;
- switch (type) {
- case NIL:
- return false;
- case BOOL:
- return _data._bool;
- case INT:
- return _data._int;
- case REAL:
- return _data._real;
- case STRING:
- return (*reinterpret_cast<const String *>(_data._mem)) != "";
- case VECTOR2:
- case RECT2:
- case TRANSFORM2D:
- case VECTOR3:
- case PLANE:
- case RECT3:
- case QUAT:
- case BASIS:
- case TRANSFORM:
- case COLOR:
- case _RID:
- return (*reinterpret_cast<const RID *>(_data._mem)).is_valid();
- case OBJECT:
- return _get_obj().obj;
- case NODE_PATH:
- return (*reinterpret_cast<const NodePath *>(_data._mem)) != NodePath();
- case DICTIONARY:
- case ARRAY:
- case POOL_BYTE_ARRAY:
- case POOL_INT_ARRAY:
- case POOL_REAL_ARRAY:
- case POOL_STRING_ARRAY:
- case POOL_VECTOR2_ARRAY:
- case POOL_VECTOR3_ARRAY:
- case POOL_COLOR_ARRAY:
- r_valid = false;
- return false;
- default: {
- }
- }
-
- return false;
+// We consider all unitialized or empty types to be false based on the type's
+// zeroiness.
+bool Variant::booleanize() const {
+ return !is_zero();
}
#define _RETURN(m_what) \
@@ -207,50 +164,50 @@ bool Variant::booleanize(bool &r_valid) const {
return; \
}
-#define DEFAULT_OP_NUM(m_prefix, m_op_name, m_name, m_op, m_type) \
- CASE_TYPE(m_prefix, m_op_name, m_name) { \
- switch (p_b.type) { \
- case INT: _RETURN(p_a._data.m_type m_op p_b._data._int); \
- case REAL: _RETURN(p_a._data.m_type m_op p_b._data._real); \
- default: {} \
- } \
- r_valid = false; \
- return; \
+#define DEFAULT_OP_NUM(m_prefix, m_op_name, m_name, m_op, m_type) \
+ 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); \
+ \
+ _RETURN_FAIL \
+ };
+
+#define DEFAULT_OP_NUM_NULL(m_prefix, m_op_name, m_name, m_op, m_type) \
+ 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); \
+ \
+ _RETURN_FAIL \
};
#ifdef DEBUG_ENABLED
#define DEFAULT_OP_NUM_DIV(m_prefix, m_op_name, m_name, m_type) \
CASE_TYPE(m_prefix, m_op_name, m_name) { \
- switch (p_b.type) { \
- case INT: { \
- if (p_b._data._int == 0) { \
- r_valid = false; \
- _RETURN("Division By Zero"); \
- } \
- _RETURN(p_a._data.m_type / p_b._data._int); \
+ if (p_b.type == INT) { \
+ if (p_b._data._int == 0) { \
+ r_valid = false; \
+ _RETURN("Division By Zero"); \
} \
- case REAL: { \
- if (p_b._data._real == 0) { \
- r_valid = false; \
- _RETURN("Division By Zero"); \
- } \
- _RETURN(p_a._data.m_type / p_b._data._real); \
+ _RETURN(p_a._data.m_type / p_b._data._int); \
+ } \
+ if (p_b.type == REAL) { \
+ if (p_b._data._real == 0) { \
+ r_valid = false; \
+ _RETURN("Division By Zero"); \
} \
- default: {} \
+ _RETURN(p_a._data.m_type / p_b._data._real); \
} \
- r_valid = false; \
- return; \
+ \
+ _RETURN_FAIL \
};
#else
-#define DEFAULT_OP_NUM_DIV(m_prefix, m_op_name, m_name, m_type) \
- CASE_TYPE(m_prefix, m_op_name, m_name) { \
- switch (p_b.type) { \
- case INT: _RETURN(p_a._data.m_type / p_b._data._int); \
- case REAL: _RETURN(p_a._data.m_type / p_b._data._real); \
- default: {} \
- } \
- r_valid = false; \
- return; \
+#define DEFAULT_OP_NUM_DIV(m_prefix, m_op_name, m_name, m_type) \
+ CASE_TYPE(m_prefix, m_op_name, m_name) { \
+ if (p_b.type == INT) _RETURN(p_a._data.m_type / p_b._data._int); \
+ if (p_b.type == REAL) _RETURN(p_a._data.m_type / p_b._data._real); \
+ \
+ _RETURN_FAIL \
};
#endif
@@ -264,55 +221,65 @@ bool Variant::booleanize(bool &r_valid) const {
_RETURN(p_a._data.m_type); \
};
-#define DEFAULT_OP_NUM_VEC(m_prefix, m_op_name, m_name, m_op, m_type) \
- CASE_TYPE(m_prefix, m_op_name, m_name) { \
- switch (p_b.type) { \
- case INT: _RETURN(p_a._data.m_type m_op p_b._data._int); \
- case REAL: _RETURN(p_a._data.m_type m_op p_b._data._real); \
- case VECTOR2: _RETURN(p_a._data.m_type m_op *reinterpret_cast<const Vector2 *>(p_b._data._mem)); \
- case VECTOR3: _RETURN(p_a._data.m_type m_op *reinterpret_cast<const Vector3 *>(p_b._data._mem)); \
- default: {} \
- } \
- r_valid = false; \
- return; \
+#define DEFAULT_OP_NUM_VEC(m_prefix, m_op_name, m_name, m_op, m_type) \
+ 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 == VECTOR2) _RETURN(p_a._data.m_type m_op *reinterpret_cast<const Vector2 *>(p_b._data._mem)); \
+ if (p_b.type == VECTOR3) _RETURN(p_a._data.m_type m_op *reinterpret_cast<const Vector3 *>(p_b._data._mem)); \
+ \
+ _RETURN_FAIL \
+ };
+
+#define DEFAULT_OP_STR_REV(m_prefix, m_op_name, m_name, m_op, m_type) \
+ CASE_TYPE(m_prefix, m_op_name, m_name) { \
+ if (p_b.type == STRING) _RETURN(*reinterpret_cast<const m_type *>(p_b._data._mem) m_op *reinterpret_cast<const String *>(p_a._data._mem)); \
+ if (p_b.type == NODE_PATH) _RETURN(*reinterpret_cast<const m_type *>(p_b._data._mem) m_op *reinterpret_cast<const NodePath *>(p_a._data._mem)); \
+ \
+ _RETURN_FAIL \
};
-#define DEFAULT_OP_STR_REV(m_prefix, m_op_name, m_name, m_op, m_type) \
- CASE_TYPE(m_prefix, m_op_name, m_name) { \
- switch (p_b.type) { \
- case STRING: _RETURN(*reinterpret_cast<const m_type *>(p_b._data._mem) m_op *reinterpret_cast<const String *>(p_a._data._mem)); \
- case NODE_PATH: _RETURN(*reinterpret_cast<const m_type *>(p_b._data._mem) m_op *reinterpret_cast<const NodePath *>(p_a._data._mem)); \
- default: {} \
- } \
- r_valid = false; \
- return; \
+#define DEFAULT_OP_STR(m_prefix, m_op_name, m_name, m_op, m_type) \
+ 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)); \
+ \
+ _RETURN_FAIL \
};
-#define DEFAULT_OP_STR(m_prefix, m_op_name, m_name, m_op, m_type) \
- CASE_TYPE(m_prefix, m_op_name, m_name) { \
- switch (p_b.type) { \
- case STRING: _RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op *reinterpret_cast<const String *>(p_b._data._mem)); \
- case NODE_PATH: _RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op *reinterpret_cast<const NodePath *>(p_b._data._mem)); \
- default: {} \
- } \
- r_valid = false; \
- return; \
+#define DEFAULT_OP_STR_NULL(m_prefix, m_op_name, m_name, m_op, m_type) \
+ 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); \
+ \
+ _RETURN_FAIL \
};
#define DEFAULT_OP_LOCALMEM_REV(m_prefix, m_op_name, m_name, m_op, m_type) \
CASE_TYPE(m_prefix, m_op_name, m_name) { \
if (p_b.type == m_name) \
_RETURN(*reinterpret_cast<const m_type *>(p_b._data._mem) m_op *reinterpret_cast<const m_type *>(p_a._data._mem)); \
- r_valid = false; \
- return; \
+ \
+ _RETURN_FAIL \
};
#define DEFAULT_OP_LOCALMEM(m_prefix, m_op_name, m_name, m_op, m_type) \
CASE_TYPE(m_prefix, m_op_name, m_name) { \
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)); \
- r_valid = false; \
- return; \
+ \
+ _RETURN_FAIL \
+ };
+
+#define DEFAULT_OP_LOCALMEM_NULL(m_prefix, m_op_name, m_name, m_op, m_type) \
+ CASE_TYPE(m_prefix, m_op_name, m_name) { \
+ 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_FAIL \
};
#define DEFAULT_OP_LOCALMEM_NEG(m_prefix, m_op_name, m_name, m_type) \
@@ -325,38 +292,47 @@ bool Variant::booleanize(bool &r_valid) const {
_RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem)); \
}
-#define DEFAULT_OP_LOCALMEM_NUM(m_prefix, m_op_name, m_name, m_op, m_type) \
- CASE_TYPE(m_prefix, m_op_name, m_name) { \
- switch (p_b.type) { \
- case m_name: _RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op *reinterpret_cast<const m_type *>(p_b._data._mem)); \
- case INT: _RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op p_b._data._int); \
- case REAL: _RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op p_b._data._real); \
- default: {} \
- } \
- r_valid = false; \
- return; \
+#define DEFAULT_OP_LOCALMEM_NUM(m_prefix, m_op_name, m_name, m_op, m_type) \
+ CASE_TYPE(m_prefix, m_op_name, m_name) { \
+ 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 == INT) _RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op p_b._data._int); \
+ if (p_b.type == REAL) _RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op p_b._data._real); \
+ \
+ _RETURN_FAIL \
}
-#define DEFAULT_OP_PTR(m_op, m_name, m_sub) \
- case m_name: { \
- switch (p_b.type) { \
- case m_name: _RETURN(p_a._data.m_sub m_op p_b._data.m_sub); \
- default: {} \
- } \
- r_valid = false; \
- return; \
+#define DEFAULT_OP_PTR(m_op, m_name, m_sub) \
+ CASE_TYPE(m_prefix, m_op_name, m_name) { \
+ if (p_b.type == m_name) \
+ _RETURN(p_a._data.m_sub m_op p_b._data.m_sub); \
+ \
+ _RETURN_FAIL \
}
#define DEFAULT_OP_PTRREF(m_prefix, m_op_name, m_name, m_op, m_sub) \
CASE_TYPE(m_prefix, m_op_name, m_name) { \
if (p_b.type == m_name) \
_RETURN(*p_a._data.m_sub m_op *p_b._data.m_sub); \
- r_valid = false; \
- return; \
+ \
+ _RETURN_FAIL \
+ }
+
+#define DEFAULT_OP_PTRREF_NULL(m_prefix, m_op_name, m_name, m_op, m_sub) \
+ CASE_TYPE(m_prefix, m_op_name, m_name) { \
+ 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_FAIL \
}
-#define DEFAULT_OP_ARRAY_EQ(m_prefix, m_op_name, m_name, m_type) \
- DEFAULT_OP_ARRAY_OP(m_prefix, m_op_name, m_name, m_type, !=, !=, true, false, false)
+#define DEFAULT_OP_ARRAY_EQ(m_prefix, m_op_name, m_name, m_type) \
+ CASE_TYPE(m_prefix, m_op_name, m_name) { \
+ if (p_b.type == NIL) \
+ _RETURN(false) \
+ DEFAULT_OP_ARRAY_OP_BODY(m_prefix, m_op_name, m_name, m_type, !=, !=, true, false, false) \
+ }
#define DEFAULT_OP_ARRAY_LT(m_prefix, m_op_name, m_name, m_type) \
DEFAULT_OP_ARRAY_OP(m_prefix, m_op_name, m_name, m_type, <, !=, false, a_len < array_b.size(), true)
@@ -364,38 +340,39 @@ bool Variant::booleanize(bool &r_valid) const {
#define DEFAULT_OP_ARRAY_GT(m_prefix, m_op_name, m_name, m_type) \
DEFAULT_OP_ARRAY_OP(m_prefix, m_op_name, m_name, m_type, >, !=, false, a_len < array_b.size(), true)
-#define DEFAULT_OP_ARRAY_OP(m_prefix, m_op_name, m_name, m_type, m_opa, m_opb, m_ret_def, m_ret_s, m_ret_f) \
- CASE_TYPE(m_prefix, m_op_name, m_name) { \
- if (p_a.type != p_b.type) { \
- r_valid = false; \
- return; \
- } \
- const PoolVector<m_type> &array_a = *reinterpret_cast<const PoolVector<m_type> *>(p_a._data._mem); \
- const PoolVector<m_type> &array_b = *reinterpret_cast<const PoolVector<m_type> *>(p_b._data._mem); \
- \
- int a_len = array_a.size(); \
- if (a_len m_opa array_b.size()) { \
- _RETURN(m_ret_s); \
- } else { \
- \
- PoolVector<m_type>::Read ra = array_a.read(); \
- PoolVector<m_type>::Read rb = array_b.read(); \
- \
- for (int i = 0; i < a_len; i++) { \
- if (ra[i] m_opb rb[i]) \
- _RETURN(m_ret_f); \
- } \
- \
- _RETURN(m_ret_def); \
- } \
+#define DEFAULT_OP_ARRAY_OP(m_prefix, m_op_name, m_name, m_type, m_opa, m_opb, m_ret_def, m_ret_s, m_ret_f) \
+ CASE_TYPE(m_prefix, m_op_name, m_name) { \
+ DEFAULT_OP_ARRAY_OP_BODY(m_prefix, m_op_name, m_name, m_type, m_opa, m_opb, m_ret_def, m_ret_s, m_ret_f) \
+ }
+
+#define DEFAULT_OP_ARRAY_OP_BODY(m_prefix, m_op_name, m_name, m_type, m_opa, m_opb, m_ret_def, m_ret_s, m_ret_f) \
+ if (p_a.type != p_b.type) \
+ _RETURN_FAIL \
+ \
+ const PoolVector<m_type> &array_a = *reinterpret_cast<const PoolVector<m_type> *>(p_a._data._mem); \
+ const PoolVector<m_type> &array_b = *reinterpret_cast<const PoolVector<m_type> *>(p_b._data._mem); \
+ \
+ int a_len = array_a.size(); \
+ if (a_len m_opa array_b.size()) { \
+ _RETURN(m_ret_s); \
+ } else { \
+ \
+ PoolVector<m_type>::Read ra = array_a.read(); \
+ PoolVector<m_type>::Read rb = array_b.read(); \
+ \
+ for (int i = 0; i < a_len; i++) { \
+ if (ra[i] m_opb rb[i]) \
+ _RETURN(m_ret_f); \
+ } \
+ \
+ _RETURN(m_ret_def); \
}
#define DEFAULT_OP_ARRAY_ADD(m_prefix, m_op_name, m_name, m_type) \
CASE_TYPE(m_prefix, m_op_name, m_name) { \
- if (p_a.type != p_b.type) { \
- r_valid = false; \
- _RETURN(NIL); \
- } \
+ if (p_a.type != p_b.type) \
+ _RETURN_FAIL; \
+ \
const PoolVector<m_type> &array_a = *reinterpret_cast<const PoolVector<m_type> *>(p_a._data._mem); \
const PoolVector<m_type> &array_b = *reinterpret_cast<const PoolVector<m_type> *>(p_b._data._mem); \
PoolVector<m_type> sum = array_a; \
@@ -403,12 +380,6 @@ bool Variant::booleanize(bool &r_valid) const {
_RETURN(sum); \
}
-#define DEFAULT_OP_FAIL(m_name) \
- case m_name: { \
- r_valid = false; \
- return; \
- }
-
void Variant::evaluate(const Operator &p_op, const Variant &p_a,
const Variant &p_b, Variant &r_ret, bool &r_valid) {
@@ -421,11 +392,17 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a,
if (p_b.type == NIL) _RETURN(true);
if (p_b.type == OBJECT)
_RETURN(p_b._get_obj().obj == NULL);
+
_RETURN(false);
}
CASE_TYPE(math, OP_EQUAL, BOOL) {
- if (p_b.type != BOOL) _RETURN(false);
+ if (p_b.type != BOOL) {
+ if (p_b.type == NIL)
+ _RETURN(false);
+ _RETURN_FAIL;
+ }
+
_RETURN(p_a._data._bool == p_b._data._bool);
}
@@ -434,11 +411,16 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a,
_RETURN((p_a._get_obj().obj == p_b._get_obj().obj));
if (p_b.type == NIL)
_RETURN(p_a._get_obj().obj == NULL);
+
+ _RETURN_FAIL;
}
CASE_TYPE(math, OP_EQUAL, DICTIONARY) {
- if (p_b.type != DICTIONARY)
- _RETURN(false);
+ if (p_b.type != DICTIONARY) {
+ if (p_b.type == NIL)
+ _RETURN(false);
+ _RETURN_FAIL;
+ }
const Dictionary *arr_a = reinterpret_cast<const Dictionary *>(p_a._data._mem);
const Dictionary *arr_b = reinterpret_cast<const Dictionary *>(p_b._data._mem);
@@ -447,9 +429,11 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a,
}
CASE_TYPE(math, OP_EQUAL, ARRAY) {
- if (p_b.type != ARRAY)
- _RETURN(false);
-
+ if (p_b.type != ARRAY) {
+ if (p_b.type == NIL)
+ _RETURN(false);
+ _RETURN_FAIL;
+ }
const Array *arr_a = reinterpret_cast<const Array *>(p_a._data._mem);
const Array *arr_b = reinterpret_cast<const Array *>(p_b._data._mem);
@@ -465,21 +449,21 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a,
_RETURN(true);
}
- DEFAULT_OP_NUM(math, OP_EQUAL, INT, ==, _int);
- DEFAULT_OP_NUM(math, OP_EQUAL, REAL, ==, _real);
- DEFAULT_OP_STR(math, OP_EQUAL, STRING, ==, String);
- DEFAULT_OP_LOCALMEM(math, OP_EQUAL, VECTOR2, ==, Vector2);
- DEFAULT_OP_LOCALMEM(math, OP_EQUAL, RECT2, ==, Rect2);
- DEFAULT_OP_PTRREF(math, OP_EQUAL, TRANSFORM2D, ==, _transform2d);
- DEFAULT_OP_LOCALMEM(math, OP_EQUAL, VECTOR3, ==, Vector3);
- DEFAULT_OP_LOCALMEM(math, OP_EQUAL, PLANE, ==, Plane);
- DEFAULT_OP_LOCALMEM(math, OP_EQUAL, QUAT, ==, Quat);
- DEFAULT_OP_PTRREF(math, OP_EQUAL, RECT3, ==, _rect3);
- DEFAULT_OP_PTRREF(math, OP_EQUAL, BASIS, ==, _basis);
- DEFAULT_OP_PTRREF(math, OP_EQUAL, TRANSFORM, ==, _transform);
- DEFAULT_OP_LOCALMEM(math, OP_EQUAL, COLOR, ==, Color);
- DEFAULT_OP_STR(math, OP_EQUAL, NODE_PATH, ==, NodePath);
- DEFAULT_OP_LOCALMEM(math, OP_EQUAL, _RID, ==, RID);
+ DEFAULT_OP_NUM_NULL(math, OP_EQUAL, INT, ==, _int);
+ DEFAULT_OP_NUM_NULL(math, OP_EQUAL, REAL, ==, _real);
+ DEFAULT_OP_STR_NULL(math, OP_EQUAL, STRING, ==, String);
+ DEFAULT_OP_LOCALMEM_NULL(math, OP_EQUAL, VECTOR2, ==, Vector2);
+ DEFAULT_OP_LOCALMEM_NULL(math, OP_EQUAL, RECT2, ==, Rect2);
+ DEFAULT_OP_PTRREF_NULL(math, OP_EQUAL, TRANSFORM2D, ==, _transform2d);
+ DEFAULT_OP_LOCALMEM_NULL(math, OP_EQUAL, VECTOR3, ==, Vector3);
+ DEFAULT_OP_LOCALMEM_NULL(math, OP_EQUAL, PLANE, ==, Plane);
+ DEFAULT_OP_LOCALMEM_NULL(math, OP_EQUAL, QUAT, ==, Quat);
+ DEFAULT_OP_PTRREF_NULL(math, OP_EQUAL, RECT3, ==, _rect3);
+ DEFAULT_OP_PTRREF_NULL(math, OP_EQUAL, BASIS, ==, _basis);
+ DEFAULT_OP_PTRREF_NULL(math, OP_EQUAL, TRANSFORM, ==, _transform);
+ DEFAULT_OP_LOCALMEM_NULL(math, OP_EQUAL, COLOR, ==, Color);
+ DEFAULT_OP_STR_NULL(math, OP_EQUAL, NODE_PATH, ==, NodePath);
+ DEFAULT_OP_LOCALMEM_NULL(math, OP_EQUAL, _RID, ==, RID);
DEFAULT_OP_ARRAY_EQ(math, OP_EQUAL, POOL_BYTE_ARRAY, uint8_t);
DEFAULT_OP_ARRAY_EQ(math, OP_EQUAL, POOL_INT_ARRAY, int);
@@ -495,11 +479,18 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a,
if (p_b.type == NIL) _RETURN(false);
if (p_b.type == OBJECT)
_RETURN(p_b._get_obj().obj != NULL);
+
_RETURN(true);
}
CASE_TYPE(math, OP_NOT_EQUAL, BOOL) {
- if (p_b.type != BOOL) _RETURN(true);
+ if (p_b.type != BOOL) {
+ if (p_b.type == NIL)
+ _RETURN(true);
+
+ _RETURN_FAIL;
+ }
+
_RETURN(p_a._data._bool != p_b._data._bool);
}
@@ -508,11 +499,16 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a,
_RETURN((p_a._get_obj().obj != p_b._get_obj().obj));
if (p_b.type == NIL)
_RETURN(p_a._get_obj().obj != NULL);
+
+ _RETURN_FAIL;
}
CASE_TYPE(math, OP_NOT_EQUAL, DICTIONARY) {
- if (p_b.type != DICTIONARY)
- _RETURN(true);
+ if (p_b.type != DICTIONARY) {
+ if (p_b.type == NIL)
+ _RETURN(true);
+ _RETURN_FAIL;
+ }
const Dictionary *arr_a = reinterpret_cast<const Dictionary *>(p_a._data._mem);
const Dictionary *arr_b = reinterpret_cast<const Dictionary *>(p_b._data._mem);
@@ -521,8 +517,12 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a,
}
CASE_TYPE(math, OP_NOT_EQUAL, ARRAY) {
- if (p_b.type != ARRAY)
- _RETURN(true);
+ if (p_b.type != ARRAY) {
+ if (p_b.type == NIL)
+ _RETURN(true);
+
+ _RETURN_FAIL;
+ }
const Array *arr_a = reinterpret_cast<const Array *>(p_a._data._mem);
const Array *arr_b = reinterpret_cast<const Array *>(p_b._data._mem);
@@ -539,21 +539,21 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a,
_RETURN(true);
}
- DEFAULT_OP_NUM(math, OP_NOT_EQUAL, INT, !=, _int);
- DEFAULT_OP_NUM(math, OP_NOT_EQUAL, REAL, !=, _real);
- DEFAULT_OP_STR(math, OP_NOT_EQUAL, STRING, !=, String);
- DEFAULT_OP_LOCALMEM(math, OP_NOT_EQUAL, VECTOR2, !=, Vector2);
- DEFAULT_OP_LOCALMEM(math, OP_NOT_EQUAL, RECT2, !=, Rect2);
- DEFAULT_OP_PTRREF(math, OP_NOT_EQUAL, TRANSFORM2D, !=, _transform2d);
- DEFAULT_OP_LOCALMEM(math, OP_NOT_EQUAL, VECTOR3, !=, Vector3);
- DEFAULT_OP_LOCALMEM(math, OP_NOT_EQUAL, PLANE, !=, Plane);
- DEFAULT_OP_LOCALMEM(math, OP_NOT_EQUAL, QUAT, !=, Quat);
- DEFAULT_OP_PTRREF(math, OP_NOT_EQUAL, RECT3, !=, _rect3);
- DEFAULT_OP_PTRREF(math, OP_NOT_EQUAL, BASIS, !=, _basis);
- DEFAULT_OP_PTRREF(math, OP_NOT_EQUAL, TRANSFORM, !=, _transform);
- DEFAULT_OP_LOCALMEM(math, OP_NOT_EQUAL, COLOR, !=, Color);
- DEFAULT_OP_STR(math, OP_NOT_EQUAL, NODE_PATH, !=, NodePath);
- DEFAULT_OP_LOCALMEM(math, OP_NOT_EQUAL, _RID, !=, RID);
+ DEFAULT_OP_NUM_NULL(math, OP_NOT_EQUAL, INT, !=, _int);
+ DEFAULT_OP_NUM_NULL(math, OP_NOT_EQUAL, REAL, !=, _real);
+ DEFAULT_OP_STR_NULL(math, OP_NOT_EQUAL, STRING, !=, String);
+ DEFAULT_OP_LOCALMEM_NULL(math, OP_NOT_EQUAL, VECTOR2, !=, Vector2);
+ DEFAULT_OP_LOCALMEM_NULL(math, OP_NOT_EQUAL, RECT2, !=, Rect2);
+ DEFAULT_OP_PTRREF_NULL(math, OP_NOT_EQUAL, TRANSFORM2D, !=, _transform2d);
+ DEFAULT_OP_LOCALMEM_NULL(math, OP_NOT_EQUAL, VECTOR3, !=, Vector3);
+ DEFAULT_OP_LOCALMEM_NULL(math, OP_NOT_EQUAL, PLANE, !=, Plane);
+ DEFAULT_OP_LOCALMEM_NULL(math, OP_NOT_EQUAL, QUAT, !=, Quat);
+ DEFAULT_OP_PTRREF_NULL(math, OP_NOT_EQUAL, RECT3, !=, _rect3);
+ DEFAULT_OP_PTRREF_NULL(math, OP_NOT_EQUAL, BASIS, !=, _basis);
+ DEFAULT_OP_PTRREF_NULL(math, OP_NOT_EQUAL, TRANSFORM, !=, _transform);
+ DEFAULT_OP_LOCALMEM_NULL(math, OP_NOT_EQUAL, COLOR, !=, Color);
+ DEFAULT_OP_STR_NULL(math, OP_NOT_EQUAL, NODE_PATH, !=, NodePath);
+ DEFAULT_OP_LOCALMEM_NULL(math, OP_NOT_EQUAL, _RID, !=, RID);
CASE_TYPE(math, OP_NOT_EQUAL, POOL_BYTE_ARRAY);
CASE_TYPE(math, OP_NOT_EQUAL, POOL_INT_ARRAY);
@@ -580,13 +580,14 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a,
}
CASE_TYPE(math, OP_LESS, OBJECT) {
- if (p_b.type == OBJECT)
- _RETURN((p_a._get_obj().obj < p_b._get_obj().obj));
+ if (p_b.type != OBJECT)
+ _RETURN_FAIL;
+ _RETURN((p_a._get_obj().obj < p_b._get_obj().obj));
}
CASE_TYPE(math, OP_LESS, ARRAY) {
if (p_b.type != ARRAY)
- _RETURN(false);
+ _RETURN_FAIL;
const Array *arr_a = reinterpret_cast<const Array *>(p_a._data._mem);
const Array *arr_b = reinterpret_cast<const Array *>(p_b._data._mem);
@@ -633,8 +634,9 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a,
SWITCH_OP(math, OP_LESS_EQUAL, p_a.type) {
CASE_TYPE(math, OP_LESS_EQUAL, OBJECT) {
- if (p_b.type == OBJECT)
- _RETURN((p_a._get_obj().obj <= p_b._get_obj().obj));
+ if (p_b.type != OBJECT)
+ _RETURN_FAIL;
+ _RETURN((p_a._get_obj().obj <= p_b._get_obj().obj));
}
DEFAULT_OP_NUM(math, OP_LESS_EQUAL, INT, <=, _int);
@@ -682,13 +684,14 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a,
}
CASE_TYPE(math, OP_GREATER, OBJECT) {
- if (p_b.type == OBJECT)
- _RETURN((p_a._get_obj().obj > p_b._get_obj().obj));
+ if (p_b.type != OBJECT)
+ _RETURN_FAIL;
+ _RETURN((p_a._get_obj().obj > p_b._get_obj().obj));
}
CASE_TYPE(math, OP_GREATER, ARRAY) {
if (p_b.type != ARRAY)
- _RETURN(false);
+ _RETURN_FAIL;
const Array *arr_a = reinterpret_cast<const Array *>(p_a._data._mem);
const Array *arr_b = reinterpret_cast<const Array *>(p_b._data._mem);
@@ -735,8 +738,9 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a,
SWITCH_OP(math, OP_GREATER_EQUAL, p_a.type) {
CASE_TYPE(math, OP_GREATER_EQUAL, OBJECT) {
- if (p_b.type == OBJECT)
- _RETURN((p_a._get_obj().obj >= p_b._get_obj().obj));
+ if (p_b.type != OBJECT)
+ _RETURN_FAIL;
+ _RETURN((p_a._get_obj().obj >= p_b._get_obj().obj));
}
DEFAULT_OP_NUM(math, OP_GREATER_EQUAL, INT, >=, _int);
@@ -771,10 +775,9 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a,
SWITCH_OP(math, OP_ADD, p_a.type) {
CASE_TYPE(math, OP_ADD, ARRAY) {
- if (p_a.type != p_b.type) {
- r_valid = false;
- return;
- }
+ if (p_a.type != p_b.type)
+ _RETURN_FAIL;
+
const Array &array_a = *reinterpret_cast<const Array *>(p_a._data._mem);
const Array &array_b = *reinterpret_cast<const Array *>(p_b._data._mem);
Array sum;
@@ -853,65 +856,54 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a,
SWITCH_OP(math, OP_MULTIPLY, p_a.type) {
CASE_TYPE(math, OP_MULTIPLY, TRANSFORM2D) {
- if (p_b.type == TRANSFORM2D) {
- _RETURN(*p_a._data._transform2d * *p_b._data._transform2d);
- };
- if (p_b.type == VECTOR2) {
- _RETURN(p_a._data._transform2d->xform(*(const Vector2 *)p_b._data._mem));
- };
- r_valid = false;
- return;
+ switch (p_b.type) {
+ case TRANSFORM2D: {
+ _RETURN(*p_a._data._transform2d * *p_b._data._transform2d);
+ }
+ case VECTOR2: {
+ _RETURN(p_a._data._transform2d->xform(*(const Vector2 *)p_b._data._mem));
+ }
+ default: _RETURN_FAIL;
+ }
}
CASE_TYPE(math, OP_MULTIPLY, QUAT) {
switch (p_b.type) {
case VECTOR3: {
-
_RETURN(reinterpret_cast<const Quat *>(p_a._data._mem)->xform(*(const Vector3 *)p_b._data._mem));
- } break;
+ }
case QUAT: {
-
_RETURN(*reinterpret_cast<const Quat *>(p_a._data._mem) * *reinterpret_cast<const Quat *>(p_b._data._mem));
- } break;
+ }
case REAL: {
_RETURN(*reinterpret_cast<const Quat *>(p_a._data._mem) * p_b._data._real);
- } break;
- default: {}
- };
- r_valid = false;
- return;
+ }
+ default: _RETURN_FAIL;
+ }
}
CASE_TYPE(math, OP_MULTIPLY, BASIS) {
switch (p_b.type) {
case VECTOR3: {
-
_RETURN(p_a._data._basis->xform(*(const Vector3 *)p_b._data._mem));
- };
+ }
case BASIS: {
-
_RETURN(*p_a._data._basis * *p_b._data._basis);
- };
- default: {}
- };
- r_valid = false;
- return;
+ }
+ default: _RETURN_FAIL;
+ }
}
CASE_TYPE(math, OP_MULTIPLY, TRANSFORM) {
switch (p_b.type) {
case VECTOR3: {
-
_RETURN(p_a._data._transform->xform(*(const Vector3 *)p_b._data._mem));
- };
+ }
case TRANSFORM: {
-
_RETURN(*p_a._data._transform * *p_b._data._transform);
- };
- default: {}
- };
- r_valid = false;
- return;
+ }
+ default: _RETURN_FAIL;
+ }
}
DEFAULT_OP_NUM_VEC(math, OP_MULTIPLY, INT, *, _int);
@@ -943,18 +935,15 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a,
SWITCH_OP(math, OP_DIVIDE, p_a.type) {
CASE_TYPE(math, OP_DIVIDE, QUAT) {
- if (p_b.type != REAL) {
- r_valid = false;
- return;
- }
+ if (p_b.type != REAL)
+ _RETURN_FAIL;
#ifdef DEBUG_ENABLED
if (p_b._data._real == 0) {
r_valid = false;
_RETURN("Division By Zero");
}
#endif
- _RETURN(
- *reinterpret_cast<const Quat *>(p_a._data._mem) / p_b._data._real);
+ _RETURN(*reinterpret_cast<const Quat *>(p_a._data._mem) / p_b._data._real);
}
DEFAULT_OP_NUM_DIV(math, OP_DIVIDE, INT, _int);
@@ -1054,9 +1043,8 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a,
SWITCH_OP(math, OP_MODULE, p_a.type) {
CASE_TYPE(math, OP_MODULE, INT) {
- if (p_b.type != INT) {
+ if (p_b.type != INT)
_RETURN_FAIL;
- }
#ifdef DEBUG_ENABLED
if (p_b._data._int == 0) {
r_valid = false;
@@ -1067,15 +1055,13 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a,
}
CASE_TYPE(math, OP_MODULE, STRING) {
- const String *format =
- reinterpret_cast<const String *>(p_a._data._mem);
+ const String *format = reinterpret_cast<const String *>(p_a._data._mem);
String result;
bool error;
if (p_b.type == ARRAY) {
// e.g. "frog %s %d" % ["fish", 12]
- const Array *args =
- reinterpret_cast<const Array *>(p_b._data._mem);
+ const Array *args = reinterpret_cast<const Array *>(p_b._data._mem);
result = format->sprintf(*args, &error);
} else {
// e.g. "frog %d" % 12
@@ -1127,6 +1113,7 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a,
_RETURN_FAIL;
_RETURN(p_a._data._int << p_b._data._int);
}
+
CASE_TYPE_ALL_BUT_INT(math, OP_SHIFT_LEFT)
_RETURN_FAIL;
}
@@ -1137,6 +1124,7 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a,
_RETURN_FAIL;
_RETURN(p_a._data._int >> p_b._data._int);
}
+
CASE_TYPE_ALL_BUT_INT(math, OP_SHIFT_RIGHT)
_RETURN_FAIL;
}
@@ -1147,6 +1135,7 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a,
_RETURN_FAIL;
_RETURN(p_a._data._int & p_b._data._int);
}
+
CASE_TYPE_ALL_BUT_INT(math, OP_BIT_AND)
_RETURN_FAIL;
}
@@ -1157,6 +1146,7 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a,
_RETURN_FAIL;
_RETURN(p_a._data._int | p_b._data._int);
}
+
CASE_TYPE_ALL_BUT_INT(math, OP_BIT_OR)
_RETURN_FAIL;
}
@@ -1167,6 +1157,7 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a,
_RETURN_FAIL;
_RETURN(p_a._data._int ^ p_b._data._int);
}
+
CASE_TYPE_ALL_BUT_INT(math, OP_BIT_XOR)
_RETURN_FAIL;
}
@@ -1175,18 +1166,15 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a,
CASE_TYPE(math, OP_BIT_NEGATE, INT) {
_RETURN(~p_a._data._int);
}
+
CASE_TYPE_ALL_BUT_INT(math, OP_BIT_NEGATE)
_RETURN_FAIL;
}
SWITCH_OP(math, OP_AND, p_a.type) {
CASE_TYPE_ALL(math, OP_AND) {
- bool l = p_a.booleanize(r_valid);
- if (!r_valid)
- return;
- bool r = p_b.booleanize(r_valid);
- if (!r_valid)
- return;
+ bool l = p_a.booleanize();
+ bool r = p_b.booleanize();
_RETURN(l && r);
}
@@ -1194,12 +1182,8 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a,
SWITCH_OP(math, OP_OR, p_a.type) {
CASE_TYPE_ALL(math, OP_OR) {
- bool l = p_a.booleanize(r_valid);
- if (!r_valid)
- return;
- bool r = p_b.booleanize(r_valid);
- if (!r_valid)
- return;
+ bool l = p_a.booleanize();
+ bool r = p_b.booleanize();
_RETURN(l || r);
}
@@ -1207,12 +1191,8 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a,
SWITCH_OP(math, OP_XOR, p_a.type) {
CASE_TYPE_ALL(math, OP_XOR) {
- bool l = p_a.booleanize(r_valid);
- if (!r_valid)
- return;
- bool r = p_b.booleanize(r_valid);
- if (!r_valid)
- return;
+ bool l = p_a.booleanize();
+ bool r = p_b.booleanize();
_RETURN((l || r) && !(l && r));
}
@@ -1220,9 +1200,7 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a,
SWITCH_OP(math, OP_NOT, p_a.type) {
CASE_TYPE_ALL(math, OP_NOT) {
- bool l = p_a.booleanize(r_valid);
- if (!r_valid)
- return;
+ bool l = p_a.booleanize();
_RETURN(!l);
}
}
@@ -2676,7 +2654,7 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const {
return true;
} break;
case VECTOR2: {
- int64_t to = reinterpret_cast<const Vector3 *>(_data._mem)->y;
+ int64_t to = reinterpret_cast<const Vector2 *>(_data._mem)->y;
int64_t idx = r_iter;
idx++;