diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/class_db.cpp | 9 | ||||
-rw-r--r-- | core/dictionary.cpp | 2 | ||||
-rw-r--r-- | core/dictionary.h | 2 | ||||
-rw-r--r-- | core/global_constants.cpp | 37 | ||||
-rw-r--r-- | core/hash_map.h | 17 | ||||
-rw-r--r-- | core/image.cpp | 37 | ||||
-rw-r--r-- | core/image.h | 3 | ||||
-rw-r--r-- | core/io/packet_peer.cpp | 10 | ||||
-rw-r--r-- | core/io/packet_peer.h | 12 | ||||
-rw-r--r-- | core/io/resource_loader.cpp | 44 | ||||
-rw-r--r-- | core/math/a_star.cpp | 2 | ||||
-rw-r--r-- | core/math/math_2d.cpp | 63 | ||||
-rw-r--r-- | core/math/math_2d.h | 67 | ||||
-rw-r--r-- | core/math/matrix3.cpp | 9 | ||||
-rw-r--r-- | core/math/matrix3.h | 3 | ||||
-rw-r--r-- | core/os/file_access.cpp | 86 | ||||
-rw-r--r-- | core/os/file_access.h | 1 | ||||
-rw-r--r-- | core/os/input_event.cpp | 18 | ||||
-rw-r--r-- | core/os/input_event.h | 4 | ||||
-rw-r--r-- | core/os/os.cpp | 15 | ||||
-rw-r--r-- | core/os/os.h | 20 | ||||
-rw-r--r-- | core/os/threaded_array_processor.cpp | 2 | ||||
-rw-r--r-- | core/os/threaded_array_processor.h | 80 | ||||
-rw-r--r-- | core/script_language.cpp | 2 | ||||
-rw-r--r-- | core/ustring.cpp | 173 | ||||
-rw-r--r-- | core/ustring.h | 35 | ||||
-rw-r--r-- | core/variant_call.cpp | 6 |
27 files changed, 588 insertions, 171 deletions
diff --git a/core/class_db.cpp b/core/class_db.cpp index edd49fe95f..b18e3d2b65 100644 --- a/core/class_db.cpp +++ b/core/class_db.cpp @@ -348,10 +348,11 @@ uint64_t ClassDB::get_api_hash(APIType p_api) { hash = hash_djb2_one_64(mb->get_argument_type(-1), hash); //return for (int i = 0; i < mb->get_argument_count(); i++) { - hash = hash_djb2_one_64(mb->get_argument_info(i).type, hash); - hash = hash_djb2_one_64(mb->get_argument_info(i).name.hash(), hash); - hash = hash_djb2_one_64(mb->get_argument_info(i).hint, hash); - hash = hash_djb2_one_64(mb->get_argument_info(i).hint_string.hash(), hash); + const PropertyInfo info = mb->get_argument_info(i); + hash = hash_djb2_one_64(info.type, hash); + hash = hash_djb2_one_64(info.name.hash(), hash); + hash = hash_djb2_one_64(info.hint, hash); + hash = hash_djb2_one_64(info.hint_string.hash(), hash); } hash = hash_djb2_one_64(mb->get_default_argument_count(), hash); diff --git a/core/dictionary.cpp b/core/dictionary.cpp index 44fce2474f..66af6a1a9a 100644 --- a/core/dictionary.cpp +++ b/core/dictionary.cpp @@ -215,7 +215,7 @@ const Variant *Dictionary::next(const Variant *p_key) const { return NULL; } -Dictionary Dictionary::copy() const { +Dictionary Dictionary::duplicate() const { Dictionary n; diff --git a/core/dictionary.h b/core/dictionary.h index c8177d5648..1d8ca0023e 100644 --- a/core/dictionary.h +++ b/core/dictionary.h @@ -74,7 +74,7 @@ public: Array keys() const; Array values() const; - Dictionary copy() const; + Dictionary duplicate() const; Dictionary(const Dictionary &p_from); Dictionary(); diff --git a/core/global_constants.cpp b/core/global_constants.cpp index a8f6e4da6c..b390590cf2 100644 --- a/core/global_constants.cpp +++ b/core/global_constants.cpp @@ -98,6 +98,11 @@ void register_global_constants() { BIND_GLOBAL_ENUM_CONSTANT(MARGIN_RIGHT); BIND_GLOBAL_ENUM_CONSTANT(MARGIN_BOTTOM); + BIND_GLOBAL_ENUM_CONSTANT(CORNER_TOP_LEFT); + BIND_GLOBAL_ENUM_CONSTANT(CORNER_TOP_RIGHT); + BIND_GLOBAL_ENUM_CONSTANT(CORNER_BOTTOM_RIGHT); + BIND_GLOBAL_ENUM_CONSTANT(CORNER_BOTTOM_LEFT); + BIND_GLOBAL_ENUM_CONSTANT(VERTICAL); BIND_GLOBAL_ENUM_CONSTANT(HORIZONTAL); @@ -573,6 +578,38 @@ void register_global_constants() { BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_VECTOR3_ARRAY", Variant::POOL_VECTOR3_ARRAY); BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_COLOR_ARRAY", Variant::POOL_COLOR_ARRAY); BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_MAX", Variant::VARIANT_MAX); + + //comparation + BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_EQUAL", Variant::OP_EQUAL); + BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_NOT_EQUAL", Variant::OP_NOT_EQUAL); + BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_LESS", Variant::OP_LESS); + BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_LESS_EQUAL", Variant::OP_LESS_EQUAL); + BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_GREATER", Variant::OP_GREATER); + BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_GREATER_EQUAL", Variant::OP_GREATER_EQUAL); + //mathematic + BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_ADD", Variant::OP_ADD); + BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_SUBTRACT", Variant::OP_SUBTRACT); + BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_MULTIPLY", Variant::OP_MULTIPLY); + BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_DIVIDE", Variant::OP_DIVIDE); + BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_NEGATE", Variant::OP_NEGATE); + BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_POSITIVE", Variant::OP_POSITIVE); + BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_MODULE", Variant::OP_MODULE); + BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_STRING_CONCAT", Variant::OP_STRING_CONCAT); + //bitwise + BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_SHIFT_LEFT", Variant::OP_SHIFT_LEFT); + BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_SHIFT_RIGHT", Variant::OP_SHIFT_RIGHT); + BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_BIT_AND", Variant::OP_BIT_AND); + BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_BIT_OR", Variant::OP_BIT_OR); + BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_BIT_XOR", Variant::OP_BIT_XOR); + BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_BIT_NEGATE", Variant::OP_BIT_NEGATE); + //logic + BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_AND", Variant::OP_AND); + BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_OR", Variant::OP_OR); + BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_XOR", Variant::OP_XOR); + BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_NOT", Variant::OP_NOT); + //containment + BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_IN", Variant::OP_IN); + BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_MAX", Variant::OP_MAX); } void unregister_global_constants() { diff --git a/core/hash_map.h b/core/hash_map.h index a53cb53c84..3ec3961d73 100644 --- a/core/hash_map.h +++ b/core/hash_map.h @@ -313,7 +313,7 @@ public: _FORCE_INLINE_ TData *getptr(const TKey &p_key) { - if (!hash_table) + if (unlikely(!hash_table)) return NULL; Element *e = const_cast<Element *>(get_element(p_key)); @@ -326,7 +326,7 @@ public: _FORCE_INLINE_ const TData *getptr(const TKey &p_key) const { - if (!hash_table) + if (unlikely(!hash_table)) return NULL; const Element *e = const_cast<Element *>(get_element(p_key)); @@ -345,7 +345,7 @@ public: template <class C> _FORCE_INLINE_ TData *custom_getptr(C p_custom_key, uint32_t p_custom_hash) { - if (!hash_table) + if (unlikely(!hash_table)) return NULL; uint32_t hash = p_custom_hash; @@ -371,7 +371,7 @@ public: template <class C> _FORCE_INLINE_ const TData *custom_getptr(C p_custom_key, uint32_t p_custom_hash) const { - if (!hash_table) + if (unlikely(!hash_table)) return NULL; uint32_t hash = p_custom_hash; @@ -400,7 +400,7 @@ public: bool erase(const TKey &p_key) { - if (!hash_table) + if (unlikely(!hash_table)) return false; uint32_t hash = Hasher::hash(p_key); @@ -478,7 +478,8 @@ public: */ const TKey *next(const TKey *p_key) const { - if (!hash_table) return NULL; + if (unlikely(!hash_table)) + return NULL; if (!p_key) { /* get the first key */ @@ -559,7 +560,7 @@ public: } void get_key_value_ptr_array(const Pair **p_pairs) const { - if (!hash_table) + if (unlikely(!hash_table)) return; for (int i = 0; i < (1 << hash_table_power); i++) { @@ -573,7 +574,7 @@ public: } void get_key_list(List<TKey> *p_keys) const { - if (!hash_table) + if (unlikely(!hash_table)) return; for (int i = 0; i < (1 << hash_table_power); i++) { diff --git a/core/image.cpp b/core/image.cpp index 422c0e407b..ba6848eecf 100644 --- a/core/image.cpp +++ b/core/image.cpp @@ -2287,6 +2287,9 @@ void Image::_bind_methods() { ClassDB::bind_method(D_METHOD("set_pixel", "x", "y", "color"), &Image::set_pixel); ClassDB::bind_method(D_METHOD("get_pixel", "x", "y"), &Image::get_pixel); + ClassDB::bind_method(D_METHOD("load_png_from_buffer", "buffer"), &Image::load_png_from_buffer); + ClassDB::bind_method(D_METHOD("load_jpg_from_buffer", "buffer"), &Image::load_jpg_from_buffer); + ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE), "_set_data", "_get_data"); BIND_ENUM_CONSTANT(FORMAT_L8); //luminance @@ -2505,6 +2508,40 @@ String Image::get_format_name(Format p_format) { return format_names[p_format]; } +Error Image::load_png_from_buffer(const PoolVector<uint8_t> &p_array) { + + int buffer_size = p_array.size(); + + ERR_FAIL_COND_V(buffer_size == 0, ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V(!_png_mem_loader_func, ERR_INVALID_PARAMETER); + + PoolVector<uint8_t>::Read r = p_array.read(); + + Ref<Image> image = _png_mem_loader_func(r.ptr(), buffer_size); + ERR_FAIL_COND_V(!image.is_valid(), ERR_PARSE_ERROR); + + copy_internals_from(image); + + return OK; +} + +Error Image::load_jpg_from_buffer(const PoolVector<uint8_t> &p_array) { + + int buffer_size = p_array.size(); + + ERR_FAIL_COND_V(buffer_size == 0, ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V(!_jpg_mem_loader_func, ERR_INVALID_PARAMETER); + + PoolVector<uint8_t>::Read r = p_array.read(); + + Ref<Image> image = _jpg_mem_loader_func(r.ptr(), buffer_size); + ERR_FAIL_COND_V(!image.is_valid(), ERR_PARSE_ERROR); + + copy_internals_from(image); + + return OK; +} + Image::Image(const uint8_t *p_mem_png_jpg, int p_len) { width = 0; diff --git a/core/image.h b/core/image.h index 24693aa706..cf7632a1f1 100644 --- a/core/image.h +++ b/core/image.h @@ -296,6 +296,9 @@ public: static void set_compress_bc_func(void (*p_compress_func)(Image *, CompressSource)); static String get_format_name(Format p_format); + Error load_png_from_buffer(const PoolVector<uint8_t> &p_array); + Error load_jpg_from_buffer(const PoolVector<uint8_t> &p_array); + Image(const uint8_t *p_mem_png_jpg, int p_len = -1); Image(const char **p_xpm); diff --git a/core/io/packet_peer.cpp b/core/io/packet_peer.cpp index 16c73c26e7..c6b12f73ae 100644 --- a/core/io/packet_peer.cpp +++ b/core/io/packet_peer.cpp @@ -49,7 +49,7 @@ bool PacketPeer::is_object_decoding_allowed() const { return allow_object_decoding; } -Error PacketPeer::get_packet_buffer(PoolVector<uint8_t> &r_buffer) const { +Error PacketPeer::get_packet_buffer(PoolVector<uint8_t> &r_buffer) { const uint8_t *buffer; int buffer_size; @@ -78,7 +78,7 @@ Error PacketPeer::put_packet_buffer(const PoolVector<uint8_t> &p_buffer) { return put_packet(&r[0], len); } -Error PacketPeer::get_var(Variant &r_variant) const { +Error PacketPeer::get_var(Variant &r_variant) { const uint8_t *buffer; int buffer_size; @@ -107,7 +107,7 @@ Error PacketPeer::put_var(const Variant &p_packet) { return put_packet(buf, len); } -Variant PacketPeer::_bnd_get_var() const { +Variant PacketPeer::_bnd_get_var() { Variant var; get_var(var); @@ -117,7 +117,7 @@ Variant PacketPeer::_bnd_get_var() const { Error PacketPeer::_put_packet(const PoolVector<uint8_t> &p_buffer) { return put_packet_buffer(p_buffer); } -PoolVector<uint8_t> PacketPeer::_get_packet() const { +PoolVector<uint8_t> PacketPeer::_get_packet() { PoolVector<uint8_t> raw; last_get_error = get_packet_buffer(raw); @@ -202,7 +202,7 @@ int PacketPeerStream::get_available_packet_count() const { return count; } -Error PacketPeerStream::get_packet(const uint8_t **r_buffer, int &r_buffer_size) const { +Error PacketPeerStream::get_packet(const uint8_t **r_buffer, int &r_buffer_size) { ERR_FAIL_COND_V(peer.is_null(), ERR_UNCONFIGURED); _poll_buffer(); diff --git a/core/io/packet_peer.h b/core/io/packet_peer.h index b08d44ad8a..a6d363ec12 100644 --- a/core/io/packet_peer.h +++ b/core/io/packet_peer.h @@ -37,13 +37,13 @@ class PacketPeer : public Reference { GDCLASS(PacketPeer, Reference); - Variant _bnd_get_var() const; + Variant _bnd_get_var(); void _bnd_put_var(const Variant &p_var); static void _bind_methods(); Error _put_packet(const PoolVector<uint8_t> &p_buffer); - PoolVector<uint8_t> _get_packet() const; + PoolVector<uint8_t> _get_packet(); Error _get_packet_error() const; mutable Error last_get_error; @@ -52,17 +52,17 @@ class PacketPeer : public Reference { public: virtual int get_available_packet_count() const = 0; - virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size) const = 0; ///< buffer is GONE after next get_packet + virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size) = 0; ///< buffer is GONE after next get_packet virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size) = 0; virtual int get_max_packet_size() const = 0; /* helpers / binders */ - virtual Error get_packet_buffer(PoolVector<uint8_t> &r_buffer) const; + virtual Error get_packet_buffer(PoolVector<uint8_t> &r_buffer); virtual Error put_packet_buffer(const PoolVector<uint8_t> &p_buffer); - virtual Error get_var(Variant &r_variant) const; + virtual Error get_var(Variant &r_variant); virtual Error put_var(const Variant &p_packet); void set_allow_object_decoding(bool p_enable); @@ -91,7 +91,7 @@ protected: public: virtual int get_available_packet_count() const; - virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size) const; + virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size); virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size); virtual int get_max_packet_size() const; diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index d2aad1d63a..dea9f38634 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -35,6 +35,7 @@ #include "print_string.h" #include "project_settings.h" #include "translation.h" +#include "variant_parser.h" ResourceFormatLoader *ResourceLoader::loader[MAX_LOADERS]; int ResourceLoader::loader_count = 0; @@ -454,6 +455,49 @@ String ResourceLoader::_path_remap(const String &p_path, bool *r_translation_rem if (path_remaps.has(new_path)) { new_path = path_remaps[new_path]; } + + if (new_path == p_path) { //did not remap + //try file remap + Error err; + FileAccess *f = FileAccess::open(p_path + ".remap", FileAccess::READ, &err); + + if (f) { + + VariantParser::StreamFile stream; + stream.f = f; + + String assign; + Variant value; + VariantParser::Tag next_tag; + + int lines = 0; + String error_text; + while (true) { + + assign = Variant(); + next_tag.fields.clear(); + next_tag.name = String(); + + err = VariantParser::parse_tag_assign_eof(&stream, lines, error_text, next_tag, assign, value, NULL, true); + if (err == ERR_FILE_EOF) { + break; + } else if (err != OK) { + ERR_PRINTS("Parse error: " + p_path + ".remap:" + itos(lines) + " error: " + error_text); + break; + } + + if (assign == "path") { + new_path = value; + break; + } else if (next_tag.name != "remap") { + break; + } + } + + memdelete(f); + } + } + return new_path; } diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp index 4498efeb41..7c5dbc895a 100644 --- a/core/math/a_star.cpp +++ b/core/math/a_star.cpp @@ -459,7 +459,7 @@ void AStar::_bind_methods() { ClassDB::bind_method(D_METHOD("has_point", "id"), &AStar::has_point); ClassDB::bind_method(D_METHOD("get_points"), &AStar::get_points); - ClassDB::bind_method(D_METHOD("get_point_connections"), &AStar::get_point_connections); + ClassDB::bind_method(D_METHOD("get_point_connections", "id"), &AStar::get_point_connections); ClassDB::bind_method(D_METHOD("connect_points", "id", "to_id", "bidirectional"), &AStar::connect_points, DEFVAL(true)); ClassDB::bind_method(D_METHOD("disconnect_points", "id", "to_id"), &AStar::disconnect_points); diff --git a/core/math/math_2d.cpp b/core/math/math_2d.cpp index 11003c1cd5..8ad164d4dc 100644 --- a/core/math/math_2d.cpp +++ b/core/math/math_2d.cpp @@ -102,69 +102,6 @@ Vector2 Vector2::cross(real_t p_other) const { return Vector2(p_other * y, -p_other * x); } -Vector2 Vector2::operator+(const Vector2 &p_v) const { - - return Vector2(x + p_v.x, y + p_v.y); -} -void Vector2::operator+=(const Vector2 &p_v) { - - x += p_v.x; - y += p_v.y; -} -Vector2 Vector2::operator-(const Vector2 &p_v) const { - - return Vector2(x - p_v.x, y - p_v.y); -} -void Vector2::operator-=(const Vector2 &p_v) { - - x -= p_v.x; - y -= p_v.y; -} - -Vector2 Vector2::operator*(const Vector2 &p_v1) const { - - return Vector2(x * p_v1.x, y * p_v1.y); -}; - -Vector2 Vector2::operator*(const real_t &rvalue) const { - - return Vector2(x * rvalue, y * rvalue); -}; -void Vector2::operator*=(const real_t &rvalue) { - - x *= rvalue; - y *= rvalue; -}; - -Vector2 Vector2::operator/(const Vector2 &p_v1) const { - - return Vector2(x / p_v1.x, y / p_v1.y); -}; - -Vector2 Vector2::operator/(const real_t &rvalue) const { - - return Vector2(x / rvalue, y / rvalue); -}; - -void Vector2::operator/=(const real_t &rvalue) { - - x /= rvalue; - y /= rvalue; -}; - -Vector2 Vector2::operator-() const { - - return Vector2(-x, -y); -} - -bool Vector2::operator==(const Vector2 &p_vec2) const { - - return x == p_vec2.x && y == p_vec2.y; -} -bool Vector2::operator!=(const Vector2 &p_vec2) const { - - return x != p_vec2.x || y != p_vec2.y; -} Vector2 Vector2::floor() const { return Vector2(Math::floor(x), Math::floor(y)); diff --git a/core/math/math_2d.h b/core/math/math_2d.h index 60351445c0..4635a4da55 100644 --- a/core/math/math_2d.h +++ b/core/math/math_2d.h @@ -187,6 +187,70 @@ _FORCE_INLINE_ Vector2 operator*(real_t p_scalar, const Vector2 &p_vec) { return p_vec * p_scalar; } +_FORCE_INLINE_ Vector2 Vector2::operator+(const Vector2 &p_v) const { + + return Vector2(x + p_v.x, y + p_v.y); +} +_FORCE_INLINE_ void Vector2::operator+=(const Vector2 &p_v) { + + x += p_v.x; + y += p_v.y; +} +_FORCE_INLINE_ Vector2 Vector2::operator-(const Vector2 &p_v) const { + + return Vector2(x - p_v.x, y - p_v.y); +} +_FORCE_INLINE_ void Vector2::operator-=(const Vector2 &p_v) { + + x -= p_v.x; + y -= p_v.y; +} + +_FORCE_INLINE_ Vector2 Vector2::operator*(const Vector2 &p_v1) const { + + return Vector2(x * p_v1.x, y * p_v1.y); +}; + +_FORCE_INLINE_ Vector2 Vector2::operator*(const real_t &rvalue) const { + + return Vector2(x * rvalue, y * rvalue); +}; +_FORCE_INLINE_ void Vector2::operator*=(const real_t &rvalue) { + + x *= rvalue; + y *= rvalue; +}; + +_FORCE_INLINE_ Vector2 Vector2::operator/(const Vector2 &p_v1) const { + + return Vector2(x / p_v1.x, y / p_v1.y); +}; + +_FORCE_INLINE_ Vector2 Vector2::operator/(const real_t &rvalue) const { + + return Vector2(x / rvalue, y / rvalue); +}; + +_FORCE_INLINE_ void Vector2::operator/=(const real_t &rvalue) { + + x /= rvalue; + y /= rvalue; +}; + +_FORCE_INLINE_ Vector2 Vector2::operator-() const { + + return Vector2(-x, -y); +} + +_FORCE_INLINE_ bool Vector2::operator==(const Vector2 &p_vec2) const { + + return x == p_vec2.x && y == p_vec2.y; +} +_FORCE_INLINE_ bool Vector2::operator!=(const Vector2 &p_vec2) const { + + return x != p_vec2.x || y != p_vec2.y; +} + Vector2 Vector2::linear_interpolate(const Vector2 &p_b, real_t p_t) const { Vector2 res = *this; @@ -336,9 +400,10 @@ struct Rect2 { g.size.height += p_by * 2; return g; } + inline Rect2 grow_margin(Margin p_margin, real_t p_amount) const { Rect2 g = *this; - g.grow_individual((MARGIN_LEFT == p_margin) ? p_amount : 0, + g = g.grow_individual((MARGIN_LEFT == p_margin) ? p_amount : 0, (MARGIN_TOP == p_margin) ? p_amount : 0, (MARGIN_RIGHT == p_margin) ? p_amount : 0, (MARGIN_BOTTOM == p_margin) ? p_amount : 0); diff --git a/core/math/matrix3.cpp b/core/math/matrix3.cpp index ab3bca79ae..5346141470 100644 --- a/core/math/matrix3.cpp +++ b/core/math/matrix3.cpp @@ -311,6 +311,15 @@ void Basis::rotate(const Vector3 &p_axis, real_t p_phi) { *this = rotated(p_axis, p_phi); } +void Basis::rotate_local(const Vector3 &p_axis, real_t p_phi) { + + *this = rotated_local(p_axis, p_phi); +} +Basis Basis::rotated_local(const Vector3 &p_axis, real_t p_phi) const { + + return (*this) * Basis(p_axis, p_phi); +} + Basis Basis::rotated(const Vector3 &p_euler) const { return Basis(p_euler) * (*this); } diff --git a/core/math/matrix3.h b/core/math/matrix3.h index 9a33b8203d..9a75308f08 100644 --- a/core/math/matrix3.h +++ b/core/math/matrix3.h @@ -75,6 +75,9 @@ public: void rotate(const Vector3 &p_axis, real_t p_phi); Basis rotated(const Vector3 &p_axis, real_t p_phi) const; + void rotate_local(const Vector3 &p_axis, real_t p_phi); + Basis rotated_local(const Vector3 &p_axis, real_t p_phi) const; + void rotate(const Vector3 &p_euler); Basis rotated(const Vector3 &p_euler) const; diff --git a/core/os/file_access.cpp b/core/os/file_access.cpp index 7b2062936b..133c70b671 100644 --- a/core/os/file_access.cpp +++ b/core/os/file_access.cpp @@ -273,9 +273,62 @@ String FileAccess::get_token() const { return String::utf8(token.get_data()); } +class CharBuffer { + Vector<char> vector; + char stack_buffer[256]; + + char *buffer; + int capacity; + int written; + + bool grow() { + + if (vector.resize(next_power_of_2(1 + written)) != OK) { + + return false; + } + + if (buffer == stack_buffer) { // first chunk? + + for (int i = 0; i < written; i++) { + + vector[i] = stack_buffer[i]; + } + } + + buffer = vector.ptrw(); + capacity = vector.size(); + ERR_FAIL_COND_V(written >= capacity, false); + + return true; + } + +public: + _FORCE_INLINE_ CharBuffer() : + buffer(stack_buffer), + capacity(sizeof(stack_buffer) / sizeof(char)), + written(0) { + } + + _FORCE_INLINE_ void push_back(char c) { + + if (written >= capacity) { + + ERR_FAIL_COND(!grow()); + } + + buffer[written++] = c; + } + + _FORCE_INLINE_ const char *get_data() const { + + return buffer; + } +}; + String FileAccess::get_line() const { - CharString line; + CharBuffer line; CharType c = get_8(); @@ -516,6 +569,37 @@ String FileAccess::get_md5(const String &p_file) { return ret; } +String FileAccess::get_multiple_md5(const Vector<String> &p_file) { + + MD5_CTX md5; + MD5Init(&md5); + + for (int i = 0; i < p_file.size(); i++) { + FileAccess *f = FileAccess::open(p_file[i], READ); + ERR_CONTINUE(!f); + + unsigned char step[32768]; + + while (true) { + + int br = f->get_buffer(step, 32768); + if (br > 0) { + + MD5Update(&md5, step, br); + } + if (br < 4096) + break; + } + memdelete(f); + } + + MD5Final(&md5); + + String ret = String::md5(md5.digest); + + return ret; +} + String FileAccess::get_sha256(const String &p_file) { FileAccess *f = FileAccess::open(p_file, READ); diff --git a/core/os/file_access.h b/core/os/file_access.h index 6fda3d9668..548d7b71f1 100644 --- a/core/os/file_access.h +++ b/core/os/file_access.h @@ -155,6 +155,7 @@ public: static String get_md5(const String &p_file); static String get_sha256(const String &p_file); + static String get_multiple_md5(const Vector<String> &p_file); static Vector<uint8_t> get_file_as_array(const String &p_path); diff --git a/core/os/input_event.cpp b/core/os/input_event.cpp index 9b2bd30868..0cab8c10ef 100644 --- a/core/os/input_event.cpp +++ b/core/os/input_event.cpp @@ -32,14 +32,6 @@ #include "input_map.h" #include "os/keyboard.h" -void InputEvent::set_id(uint32_t p_id) { - id = p_id; -} - -uint32_t InputEvent::get_id() const { - return id; -} - void InputEvent::set_device(int p_device) { device = p_device; } @@ -99,9 +91,6 @@ bool InputEvent::is_action_type() const { void InputEvent::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_id", "id"), &InputEvent::set_id); - ClassDB::bind_method(D_METHOD("get_id"), &InputEvent::get_id); - ClassDB::bind_method(D_METHOD("set_device", "device"), &InputEvent::set_device); ClassDB::bind_method(D_METHOD("get_device"), &InputEvent::get_device); @@ -125,7 +114,6 @@ void InputEvent::_bind_methods() { InputEvent::InputEvent() { - id = 0; device = 0; } @@ -441,7 +429,6 @@ Ref<InputEvent> InputEventMouseButton::xformed_by(const Transform2D &p_xform, co Ref<InputEventMouseButton> mb; mb.instance(); - mb->set_id(get_id()); mb->set_device(get_device()); mb->set_modifiers_from_event(this); @@ -557,7 +544,6 @@ Ref<InputEvent> InputEventMouseMotion::xformed_by(const Transform2D &p_xform, co Ref<InputEventMouseMotion> mm; mm.instance(); - mm->set_id(get_id()); mm->set_device(get_device()); mm->set_modifiers_from_event(this); @@ -764,7 +750,6 @@ Ref<InputEvent> InputEventScreenTouch::xformed_by(const Transform2D &p_xform, co Ref<InputEventScreenTouch> st; st.instance(); - st->set_id(get_id()); st->set_device(get_device()); st->set_index(index); st->set_position(p_xform.xform(pos + p_local_ofs)); @@ -845,7 +830,6 @@ Ref<InputEvent> InputEventScreenDrag::xformed_by(const Transform2D &p_xform, con sd.instance(); - sd->set_id(get_id()); sd->set_device(get_device()); sd->set_index(index); @@ -968,7 +952,6 @@ Ref<InputEvent> InputEventMagnifyGesture::xformed_by(const Transform2D &p_xform, Ref<InputEventMagnifyGesture> ev; ev.instance(); - ev->set_id(get_id()); ev->set_device(get_device()); ev->set_modifiers_from_event(this); @@ -1006,7 +989,6 @@ Ref<InputEvent> InputEventPanGesture::xformed_by(const Transform2D &p_xform, con Ref<InputEventPanGesture> ev; ev.instance(); - ev->set_id(get_id()); ev->set_device(get_device()); ev->set_modifiers_from_event(this); diff --git a/core/os/input_event.h b/core/os/input_event.h index 614a3289ba..9b1a2736b1 100644 --- a/core/os/input_event.h +++ b/core/os/input_event.h @@ -144,16 +144,12 @@ enum JoystickList { class InputEvent : public Resource { GDCLASS(InputEvent, Resource) - uint32_t id; int device; protected: static void _bind_methods(); public: - void set_id(uint32_t p_id); - uint32_t get_id() const; - void set_device(int p_device); int get_device() const; diff --git a/core/os/os.cpp b/core/os/os.cpp index 8088a6fa74..7010d44930 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -536,12 +536,21 @@ String OS::get_joy_guid(int p_device) const { void OS::set_context(int p_context) { } + +OS::SwitchVSyncCallbackInThread OS::switch_vsync_function = NULL; + void OS::set_use_vsync(bool p_enable) { + _use_vsync = p_enable; + if (switch_vsync_function) { //if a function was set, use function + switch_vsync_function(p_enable); + } else { //otherwise just call here + _set_use_vsync(p_enable); + } } bool OS::is_vsync_enabled() const { - return true; + return _use_vsync; } OS::PowerState OS::get_power_state() { @@ -606,10 +615,6 @@ bool OS::has_feature(const String &p_feature) { return false; } -void *OS::get_stack_bottom() const { - return _stack_bottom; -} - OS::OS() { void *volatile stack_bottom; diff --git a/core/os/os.h b/core/os/os.h index 41500acd93..2faaa6ab8f 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -58,6 +58,7 @@ class OS { int _exit_code; int _orientation; bool _allow_hidpi; + bool _use_vsync; char *last_error; @@ -435,8 +436,16 @@ public: virtual void set_context(int p_context); - virtual void set_use_vsync(bool p_enable); - virtual bool is_vsync_enabled() const; + //amazing hack because OpenGL needs this to be set on a separate thread.. + //also core can't access servers, so a callback must be used + typedef void (*SwitchVSyncCallbackInThread)(bool); + + static SwitchVSyncCallbackInThread switch_vsync_function; + void set_use_vsync(bool p_enable); + bool is_vsync_enabled() const; + + //real, actual overridable function to switch vsync, which needs to be called from graphics thread if needed + virtual void _set_use_vsync(bool p_enable) {} virtual OS::PowerState get_power_state(); virtual int get_power_seconds_left(); @@ -445,13 +454,6 @@ public: virtual void force_process_input(){}; bool has_feature(const String &p_feature); - /** - * Returns the stack bottom of the main thread of the application. - * This may be of use when integrating languages with garbage collectors that - * need to check whether a pointer is on the stack. - */ - virtual void *get_stack_bottom() const; - bool is_hidpi_allowed() const { return _allow_hidpi; } OS(); virtual ~OS(); diff --git a/core/os/threaded_array_processor.cpp b/core/os/threaded_array_processor.cpp new file mode 100644 index 0000000000..8e92508ea5 --- /dev/null +++ b/core/os/threaded_array_processor.cpp @@ -0,0 +1,2 @@ +#include "threaded_array_processor.h" + diff --git a/core/os/threaded_array_processor.h b/core/os/threaded_array_processor.h new file mode 100644 index 0000000000..e584fbb193 --- /dev/null +++ b/core/os/threaded_array_processor.h @@ -0,0 +1,80 @@ +#ifndef THREADED_ARRAY_PROCESSOR_H +#define THREADED_ARRAY_PROCESSOR_H + +#include "os/mutex.h" +#include "os/os.h" +#include "os/thread.h" +#include "safe_refcount.h" +#include "thread_safe.h" + +template <class C, class U> +struct ThreadArrayProcessData { + uint32_t elements; + uint32_t index; + C *instance; + U userdata; + void (C::*method)(uint32_t, U); + + void process(uint32_t p_index) { + (instance->*method)(p_index, userdata); + } +}; + +#ifndef NO_THREADS + +template <class T> +void process_array_thread(void *ud) { + + T &data = *(T *)ud; + while (true) { + uint32_t index = atomic_increment(&data.index); + if (index >= data.elements) + break; + data.process(index); + } +} + +template <class C, class M, class U> +void thread_process_array(uint32_t p_elements, C *p_instance, M p_method, U p_userdata) { + + ThreadArrayProcessData<C, U> data; + data.method = p_method; + data.instance = p_instance; + data.userdata = p_userdata; + data.index = 0; + data.elements = p_elements; + data.process(data.index); //process first, let threads increment for next + + Vector<Thread *> threads; + + threads.resize(OS::get_singleton()->get_processor_count()); + + for (int i = 0; i < threads.size(); i++) { + threads[i] = Thread::create(process_array_thread<ThreadArrayProcessData<C, U> >, &data); + } + + for (int i = 0; i < threads.size(); i++) { + Thread::wait_to_finish(threads[i]); + memdelete(threads[i]); + } +} + +#else + +template <class C, class M, class U> +void thread_process_array(uint32_t p_elements, C *p_instance, M p_method, U p_userdata) { + + ThreadArrayProcessData<C, U> data; + data.method = p_method; + data.instance = p_instance; + data.userdata = p_userdata; + data.index = 0; + data.elements = p_elements; + for (uint32_t i = 0; i < p_elements; i++) { + data.process(i); + } +} + +#endif + +#endif // THREADED_ARRAY_PROCESSOR_H diff --git a/core/script_language.cpp b/core/script_language.cpp index c1e9d55872..2c32054e77 100644 --- a/core/script_language.cpp +++ b/core/script_language.cpp @@ -54,6 +54,8 @@ void Script::_bind_methods() { ClassDB::bind_method(D_METHOD("get_source_code"), &Script::get_source_code); ClassDB::bind_method(D_METHOD("set_source_code", "source"), &Script::set_source_code); ClassDB::bind_method(D_METHOD("reload", "keep_state"), &Script::reload, DEFVAL(false)); + ClassDB::bind_method(D_METHOD("get_base_script"), &Script::get_base_script); + ClassDB::bind_method(D_METHOD("get_instance_base_type"), &Script::get_instance_base_type); ClassDB::bind_method(D_METHOD("has_script_signal", "signal_name"), &Script::has_script_signal); diff --git a/core/ustring.cpp b/core/ustring.cpp index 9cd94ac919..261cc0778c 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -356,7 +356,7 @@ bool String::operator<(const CharType *p_str) const { return is_str_less(c_str(), p_str); } -bool String::operator<=(String p_str) const { +bool String::operator<=(const String &p_str) const { return (*this < p_str) || (*this == p_str); } @@ -371,7 +371,7 @@ bool String::operator<(const char *p_str) const { return is_str_less(c_str(), p_str); } -bool String::operator<(String p_str) const { +bool String::operator<(const String &p_str) const { return operator<(p_str.c_str()); } @@ -679,7 +679,7 @@ Vector<String> String::split_spaces() const { return ret; } -Vector<String> String::split(const String &p_splitter, bool p_allow_empty) const { +Vector<String> String::split(const String &p_splitter, bool p_allow_empty, int p_maxsplit) const { Vector<String> ret; int from = 0; @@ -690,8 +690,21 @@ Vector<String> String::split(const String &p_splitter, bool p_allow_empty) const int end = find(p_splitter, from); if (end < 0) end = len; - if (p_allow_empty || (end > from)) - ret.push_back(substr(from, end - from)); + if (p_allow_empty || (end > from)) { + if (p_maxsplit <= 0) + ret.push_back(substr(from, end - from)); + else if (p_maxsplit > 0) { + + // Put rest of the string and leave cycle. + if (p_maxsplit == ret.size()) { + ret.push_back(substr(from, len)); + break; + } + + // Otherwise, push items until positive limit is reached. + ret.push_back(substr(from, end - from)); + } + } if (end == len) break; @@ -834,7 +847,10 @@ String String::to_upper() const { for (int i = 0; i < upper.size(); i++) { - upper[i] = _find_upper(upper[i]); + const char s = upper[i]; + const char t = _find_upper(s); + if (s != t) // avoid copy on write + upper[i] = t; } return upper; @@ -842,20 +858,17 @@ String String::to_upper() const { String String::to_lower() const { - String upper = *this; + String lower = *this; - for (int i = 0; i < upper.size(); i++) { + for (int i = 0; i < lower.size(); i++) { - upper[i] = _find_lower(upper[i]); + const char s = lower[i]; + const char t = _find_lower(s); + if (s != t) // avoid copy on write + lower[i] = t; } - return upper; -} - -int String::length() const { - - int s = size(); - return s ? (s - 1) : 0; // length does not include zero + return lower; } const CharType *String::c_str() const { @@ -2107,7 +2120,7 @@ Vector<uint8_t> String::sha256_buffer() const { return ret; } -String String::insert(int p_at_pos, String p_string) const { +String String::insert(int p_at_pos, const String &p_string) const { if (p_at_pos < 0) return *this; @@ -2135,10 +2148,15 @@ String String::substr(int p_from, int p_chars) const { p_chars = length() - p_from; } + if (p_from == 0 && p_chars >= length()) { + + return String(*this); + } + return String(&c_str()[p_from], p_chars); } -int String::find_last(String p_str) const { +int String::find_last(const String &p_str) const { int pos = -1; int findfrom = 0; @@ -2151,19 +2169,21 @@ int String::find_last(String p_str) const { return pos; } -int String::find(String p_str, int p_from) const { + +int String::find(const String &p_str, int p_from) const { if (p_from < 0) return -1; - int src_len = p_str.length(); + const int src_len = p_str.length(); - int len = length(); + const int len = length(); if (src_len == 0 || len == 0) return -1; //wont find anything! const CharType *src = c_str(); + const CharType *str = p_str.c_str(); for (int i = p_from; i <= (len - src_len); i++) { @@ -2178,7 +2198,7 @@ int String::find(String p_str, int p_from) const { return -1; }; - if (src[read_pos] != p_str[j]) { + if (src[read_pos] != str[j]) { found = false; break; } @@ -2191,6 +2211,62 @@ int String::find(String p_str, int p_from) const { return -1; } +int String::find(const char *p_str, int p_from) const { + + if (p_from < 0) + return -1; + + const int len = length(); + + if (len == 0) + return -1; //wont find anything! + + const CharType *src = c_str(); + + int src_len = 0; + while (p_str[src_len] != '\0') + src_len++; + + if (src_len == 1) { + + const char needle = p_str[0]; + + for (int i = p_from; i < len; i++) { + + if (src[i] == needle) { + return i; + } + } + + } else { + + for (int i = p_from; i <= (len - src_len); i++) { + + bool found = true; + for (int j = 0; j < src_len; j++) { + + int read_pos = i + j; + + if (read_pos >= len) { + + ERR_PRINT("read_pos>=len"); + return -1; + }; + + if (src[read_pos] != p_str[j]) { + found = false; + break; + } + } + + if (found) + return i; + } + } + + return -1; +} + int String::findmk(const Vector<String> &p_keys, int p_from, int *r_key) const { if (p_from < 0) @@ -2245,7 +2321,7 @@ int String::findmk(const Vector<String> &p_keys, int p_from, int *r_key) const { return -1; } -int String::findn(String p_str, int p_from) const { +int String::findn(const String &p_str, int p_from) const { if (p_from < 0) return -1; @@ -2286,7 +2362,7 @@ int String::findn(String p_str, int p_from) const { return -1; } -int String::rfind(String p_str, int p_from) const { +int String::rfind(const String &p_str, int p_from) const { // establish a limit int limit = length() - p_str.length(); @@ -2332,7 +2408,7 @@ int String::rfind(String p_str, int p_from) const { return -1; } -int String::rfindn(String p_str, int p_from) const { +int String::rfindn(const String &p_str, int p_from) const { // establish a limit int limit = length() - p_str.length(); @@ -2632,7 +2708,7 @@ String String::format(const Variant &values, String placeholder) const { return new_string; } -String String::replace(String p_key, String p_with) const { +String String::replace(const String &p_key, const String &p_with) const { String new_string; int search_from = 0; @@ -2645,12 +2721,43 @@ String String::replace(String p_key, String p_with) const { search_from = result + p_key.length(); } + if (search_from == 0) { + + return *this; + } + new_string += substr(search_from, length() - search_from); return new_string; } -String String::replace_first(String p_key, String p_with) const { +String String::replace(const char *p_key, const char *p_with) const { + + String new_string; + int search_from = 0; + int result = 0; + + while ((result = find(p_key, search_from)) >= 0) { + + new_string += substr(search_from, result - search_from); + new_string += p_with; + int k = 0; + while (p_key[k] != '\0') + k++; + search_from = result + k; + } + + if (search_from == 0) { + + return *this; + } + + new_string += substr(search_from, length() - search_from); + + return new_string; +} + +String String::replace_first(const String &p_key, const String &p_with) const { String new_string; int search_from = 0; @@ -2664,11 +2771,16 @@ String String::replace_first(String p_key, String p_with) const { break; } + if (search_from == 0) { + + return *this; + } + new_string += substr(search_from, length() - search_from); return new_string; } -String String::replacen(String p_key, String p_with) const { +String String::replacen(const String &p_key, const String &p_with) const { String new_string; int search_from = 0; @@ -2681,6 +2793,11 @@ String String::replacen(String p_key, String p_with) const { search_from = result + p_key.length(); } + if (search_from == 0) { + + return *this; + } + new_string += substr(search_from, length() - search_from); return new_string; } diff --git a/core/ustring.h b/core/ustring.h index a56c90544a..1bb4719b85 100644 --- a/core/ustring.h +++ b/core/ustring.h @@ -93,8 +93,8 @@ public: bool operator!=(const CharType *p_str) const; bool operator<(const CharType *p_str) const; bool operator<(const char *p_str) const; - bool operator<(String p_str) const; - bool operator<=(String p_str) const; + bool operator<(const String &p_str) const; + bool operator<=(const String &p_str) const; signed char casecmp_to(const String &p_str) const; signed char nocasecmp_to(const String &p_str) const; @@ -103,15 +103,19 @@ public: const CharType *c_str() const; /* standard size stuff */ - int length() const; + _FORCE_INLINE_ int length() const { + int s = size(); + return s ? (s - 1) : 0; // length does not include zero + } /* complex helpers */ String substr(int p_from, int p_chars) const; - int find(String p_str, int p_from = 0) const; ///< return <0 if failed - int find_last(String p_str) const; ///< return <0 if failed - int findn(String p_str, int p_from = 0) const; ///< return <0 if failed, case insensitive - int rfind(String p_str, int p_from = -1) const; ///< return <0 if failed - int rfindn(String p_str, int p_from = -1) const; ///< return <0 if failed, case insensitive + int find(const String &p_str, int p_from = 0) const; ///< return <0 if failed + int find(const char *p_str, int p_from) const; ///< return <0 if failed + int find_last(const String &p_str) const; ///< return <0 if failed + int findn(const String &p_str, int p_from = 0) const; ///< return <0 if failed, case insensitive + int rfind(const String &p_str, int p_from = -1) const; ///< return <0 if failed + int rfindn(const String &p_str, int p_from = -1) const; ///< return <0 if failed, case insensitive int findmk(const Vector<String> &p_keys, int p_from = 0, int *r_key = NULL) const; ///< return <0 if failed bool match(const String &p_wildcard) const; bool matchn(const String &p_wildcard) const; @@ -125,10 +129,11 @@ public: Vector<String> bigrams() const; float similarity(const String &p_string) const; String format(const Variant &values, String placeholder = "{_}") const; - String replace_first(String p_key, String p_with) const; - String replace(String p_key, String p_with) const; - String replacen(String p_key, String p_with) const; - String insert(int p_at_pos, String p_string) const; + String replace_first(const String &p_key, const String &p_with) const; + String replace(const String &p_key, const String &p_with) const; + String replace(const char *p_key, const char *p_with) const; + String replacen(const String &p_key, const String &p_with) const; + String insert(int p_at_pos, const String &p_string) const; String pad_decimals(int p_digits) const; String pad_zeros(int p_digits) const; String lpad(int min_length, const String &character = " ") const; @@ -162,7 +167,7 @@ public: String get_slice(String p_splitter, int p_slice) const; String get_slicec(CharType p_splitter, int p_slice) const; - Vector<String> split(const String &p_splitter, bool p_allow_empty = true) const; + Vector<String> split(const String &p_splitter, bool p_allow_empty = true, int p_maxsplit = 0) const; Vector<String> split_spaces() const; Vector<float> split_floats(const String &p_splitter, bool p_allow_empty = true) const; Vector<float> split_floats_mk(const Vector<String> &p_splitters, bool p_allow_empty = true) const; @@ -204,7 +209,7 @@ public: Vector<uint8_t> md5_buffer() const; Vector<uint8_t> sha256_buffer() const; - inline bool empty() const { return length() == 0; } + _FORCE_INLINE_ bool empty() const { return length() == 0; } // path functions bool is_abs_path() const; @@ -242,6 +247,8 @@ public: */ /* String(CharType p_char);*/ inline String() {} + inline String(const String &p_str) : + Vector(p_str) {} String(const char *p_str); String(const CharType *p_str, int p_clip_to_len = -1); String(const StrRange &p_range); diff --git a/core/variant_call.cpp b/core/variant_call.cpp index f66cce85c9..0284c4d866 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -254,7 +254,7 @@ struct _VariantCall { VCALL_LOCALMEM2R(String, replacen); VCALL_LOCALMEM2R(String, insert); VCALL_LOCALMEM0R(String, capitalize); - VCALL_LOCALMEM2R(String, split); + VCALL_LOCALMEM3R(String, split); VCALL_LOCALMEM2R(String, split_floats); VCALL_LOCALMEM0R(String, to_upper); VCALL_LOCALMEM0R(String, to_lower); @@ -462,6 +462,7 @@ struct _VariantCall { VCALL_LOCALMEM0R(Dictionary, hash); VCALL_LOCALMEM0R(Dictionary, keys); VCALL_LOCALMEM0R(Dictionary, values); + VCALL_LOCALMEM0R(Dictionary, duplicate); VCALL_LOCALMEM2(Array, set); VCALL_LOCALMEM1R(Array, get); @@ -1446,7 +1447,7 @@ void register_variant_methods() { ADDFUNC2R(STRING, STRING, String, replacen, STRING, "what", STRING, "forwhat", varray()); ADDFUNC2R(STRING, STRING, String, insert, INT, "position", STRING, "what", varray()); ADDFUNC0R(STRING, STRING, String, capitalize, varray()); - ADDFUNC2R(STRING, POOL_STRING_ARRAY, String, split, STRING, "divisor", BOOL, "allow_empty", varray(true)); + ADDFUNC3R(STRING, POOL_STRING_ARRAY, String, split, STRING, "divisor", BOOL, "allow_empty", INT, "maxsplit", varray(true, 0)); ADDFUNC2R(STRING, POOL_REAL_ARRAY, String, split_floats, STRING, "divisor", BOOL, "allow_empty", varray(true)); ADDFUNC0R(STRING, STRING, String, to_upper, varray()); @@ -1607,6 +1608,7 @@ void register_variant_methods() { ADDFUNC0R(DICTIONARY, INT, Dictionary, hash, varray()); ADDFUNC0R(DICTIONARY, ARRAY, Dictionary, keys, varray()); ADDFUNC0R(DICTIONARY, ARRAY, Dictionary, values, varray()); + ADDFUNC0R(DICTIONARY, DICTIONARY, Dictionary, duplicate, varray()); ADDFUNC0R(ARRAY, INT, Array, size, varray()); ADDFUNC0R(ARRAY, BOOL, Array, empty, varray()); |