diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/bind/core_bind.cpp | 8 | ||||
-rw-r--r-- | core/bind/core_bind.h | 5 | ||||
-rw-r--r-- | core/engine.cpp | 6 | ||||
-rw-r--r-- | core/engine.h | 4 | ||||
-rw-r--r-- | core/global_config.cpp | 4 | ||||
-rw-r--r-- | core/image.cpp | 36 | ||||
-rw-r--r-- | core/io/compression.cpp | 27 | ||||
-rw-r--r-- | core/io/compression.h | 3 | ||||
-rw-r--r-- | core/io/resource_format_binary.cpp | 73 | ||||
-rw-r--r-- | core/io/translation_loader_po.cpp | 21 | ||||
-rw-r--r-- | core/math/a_star.cpp | 7 | ||||
-rw-r--r-- | core/math/a_star.h | 1 | ||||
-rw-r--r-- | core/math/audio_frame.h | 10 | ||||
-rw-r--r-- | core/math/face3.cpp | 8 | ||||
-rw-r--r-- | core/math/vector3.h | 6 | ||||
-rw-r--r-- | core/object.cpp | 26 | ||||
-rw-r--r-- | core/object.h | 9 | ||||
-rw-r--r-- | core/os/os.h | 2 | ||||
-rw-r--r-- | core/script_language.cpp | 5 | ||||
-rw-r--r-- | core/script_language.h | 5 | ||||
-rw-r--r-- | core/self_list.h | 19 | ||||
-rw-r--r-- | core/sort.h | 10 | ||||
-rw-r--r-- | core/variant_call.cpp | 2 |
23 files changed, 239 insertions, 58 deletions
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 095f058ed9..a5ec9c1afc 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -300,6 +300,11 @@ bool _OS::get_borderless_window() const { return OS::get_singleton()->get_borderless_window(); } +void _OS::set_ime_position(const Point2 &p_pos) { + + return OS::get_singleton()->set_ime_position(p_pos); +} + void _OS::set_use_file_access_save_and_swap(bool p_enable) { FileAccess::set_backup_save(p_enable); @@ -993,6 +998,8 @@ void _OS::_bind_methods() { ClassDB::bind_method(D_METHOD("set_borderless_window", "borderless"), &_OS::set_borderless_window); ClassDB::bind_method(D_METHOD("get_borderless_window"), &_OS::get_borderless_window); + ClassDB::bind_method(D_METHOD("set_ime_position"), &_OS::set_ime_position); + ClassDB::bind_method(D_METHOD("set_screen_orientation", "orientation"), &_OS::set_screen_orientation); ClassDB::bind_method(D_METHOD("get_screen_orientation"), &_OS::get_screen_orientation); @@ -1773,6 +1780,7 @@ void _File::_bind_methods() { BIND_CONSTANT(COMPRESSION_FASTLZ); BIND_CONSTANT(COMPRESSION_DEFLATE); BIND_CONSTANT(COMPRESSION_ZSTD); + BIND_CONSTANT(COMPRESSION_GZIP); } _File::_File() { diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 87d84c0732..ec4fd3f476 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -158,6 +158,8 @@ public: virtual void set_borderless_window(bool p_borderless); virtual bool get_borderless_window() const; + virtual void set_ime_position(const Point2 &p_pos); + Error native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track); bool native_video_is_playing(); void native_video_pause(); @@ -370,7 +372,8 @@ public: enum CompressionMode { COMPRESSION_FASTLZ = Compression::MODE_FASTLZ, COMPRESSION_DEFLATE = Compression::MODE_DEFLATE, - COMPRESSION_ZSTD = Compression::MODE_ZSTD + COMPRESSION_ZSTD = Compression::MODE_ZSTD, + COMPRESSION_GZIP = Compression::MODE_GZIP }; Error open_encrypted(const String &p_path, int p_mode_flags, const Vector<uint8_t> &p_key); diff --git a/core/engine.cpp b/core/engine.cpp index 5301c4e519..c16a2903d3 100644 --- a/core/engine.cpp +++ b/core/engine.cpp @@ -30,6 +30,7 @@ #include "engine.h" #include "version.h" +#include "version_hash.gen.h" void Engine::set_iterations_per_second(int p_ips) { @@ -87,6 +88,9 @@ Dictionary Engine::get_version_info() const { dict["revision"] = _MKSTR(VERSION_REVISION); dict["year"] = VERSION_YEAR; + String hash = String(VERSION_HASH); + dict["hash"] = hash.length() == 0 ? String("unknown") : hash; + String stringver = String(dict["major"]) + "." + String(dict["minor"]); if ((int)dict["patch"] != 0) stringver += "." + String(dict["patch"]); @@ -115,4 +119,6 @@ Engine::Engine() { _fixed_frames = 0; _idle_frames = 0; _in_fixed = false; + _frame_ticks = 0; + _frame_step = 0; } diff --git a/core/engine.h b/core/engine.h index 80b11c095d..16dfb77593 100644 --- a/core/engine.h +++ b/core/engine.h @@ -42,6 +42,8 @@ class Engine { String _custom_level; uint64_t frames_drawn; uint32_t _frame_delay; + uint64_t _frame_ticks; + float _frame_step; int ips; float _fps; @@ -72,6 +74,8 @@ public: uint64_t get_fixed_frames() const { return _fixed_frames; } uint64_t get_idle_frames() const { return _idle_frames; } bool is_in_fixed_frame() const { return _in_fixed; } + uint64_t get_idle_frame_ticks() const { return _frame_ticks; } + float get_idle_frame_step() const { return _frame_step; } void set_time_scale(float p_scale); float get_time_scale() const; diff --git a/core/global_config.cpp b/core/global_config.cpp index ba0a7f3e31..d8b88afd07 100644 --- a/core/global_config.cpp +++ b/core/global_config.cpp @@ -835,7 +835,7 @@ void GlobalConfig::_bind_methods() { ClassDB::bind_method(D_METHOD("get_singleton", "name"), &GlobalConfig::get_singleton_object); ClassDB::bind_method(D_METHOD("load_resource_pack", "pack"), &GlobalConfig::_load_resource_pack); ClassDB::bind_method(D_METHOD("property_can_revert", "name"), &GlobalConfig::property_can_revert); - ClassDB::bind_method(D_METHOD("property_get_revert", "name"), &GlobalConfig::property_get_revert); + ClassDB::bind_method(D_METHOD("property_get_revert:Variant", "name"), &GlobalConfig::property_get_revert); ClassDB::bind_method(D_METHOD("save_custom", "file"), &GlobalConfig::_save_custom_bnd); } @@ -974,6 +974,8 @@ GlobalConfig::GlobalConfig() { custom_prop_info["compression/zstd/compression_level"] = PropertyInfo(Variant::INT, "compression/zstd/compression_level", PROPERTY_HINT_RANGE, "1,22,1"); GLOBAL_DEF("compression/zlib/compression_level", Z_DEFAULT_COMPRESSION); custom_prop_info["compression/zlib/compression_level"] = PropertyInfo(Variant::INT, "compression/zlib/compression_level", PROPERTY_HINT_RANGE, "-1,9,1"); + GLOBAL_DEF("compression/gzip/compression_level", Z_DEFAULT_COMPRESSION); + custom_prop_info["compression/gzip/compression_level"] = PropertyInfo(Variant::INT, "compression/gzip/compression_level", PROPERTY_HINT_RANGE, "-1,9,1"); using_datapack = false; } diff --git a/core/image.cpp b/core/image.cpp index 76f21a25de..6ab8bb6d46 100644 --- a/core/image.cpp +++ b/core/image.cpp @@ -1325,19 +1325,19 @@ void Image::create(const char **p_xpm) { line++; } } -#define DETECT_ALPHA_MAX_TRESHOLD 254 -#define DETECT_ALPHA_MIN_TRESHOLD 2 - -#define DETECT_ALPHA(m_value) \ - { \ - uint8_t value = m_value; \ - if (value < DETECT_ALPHA_MIN_TRESHOLD) \ - bit = true; \ - else if (value < DETECT_ALPHA_MAX_TRESHOLD) { \ - \ - detected = true; \ - break; \ - } \ +#define DETECT_ALPHA_MAX_THRESHOLD 254 +#define DETECT_ALPHA_MIN_THRESHOLD 2 + +#define DETECT_ALPHA(m_value) \ + { \ + uint8_t value = m_value; \ + if (value < DETECT_ALPHA_MIN_THRESHOLD) \ + bit = true; \ + else if (value < DETECT_ALPHA_MAX_THRESHOLD) { \ + \ + detected = true; \ + break; \ + } \ } #define DETECT_NON_ALPHA(m_value) \ @@ -1673,7 +1673,7 @@ void Image::blit_rect_mask(const Ref<Image> &p_src, const Ref<Image> &p_mask, co const uint8_t *src_data_ptr = rp.ptr(); int pixel_size = get_format_pixel_size(format); - + Ref<Image> msk = p_mask; msk->lock(); @@ -1683,7 +1683,7 @@ void Image::blit_rect_mask(const Ref<Image> &p_src, const Ref<Image> &p_mask, co int src_x = clipped_src_rect.position.x + j; int src_y = clipped_src_rect.position.y + i; - + if (msk->get_pixel(src_x, src_y).a != 0) { int dst_x = dest_rect.position.x + j; @@ -2434,7 +2434,7 @@ void Image::fix_alpha_edges() { unsigned char *data_ptr = wp.ptr(); const int max_radius = 4; - const int alpha_treshold = 20; + const int alpha_threshold = 20; const int max_dist = 0x7FFFFFFF; for (int i = 0; i < height; i++) { @@ -2443,7 +2443,7 @@ void Image::fix_alpha_edges() { const uint8_t *rptr = &srcptr[(i * width + j) * 4]; uint8_t *wptr = &data_ptr[(i * width + j) * 4]; - if (rptr[3] >= alpha_treshold) + if (rptr[3] >= alpha_threshold) continue; int closest_dist = max_dist; @@ -2465,7 +2465,7 @@ void Image::fix_alpha_edges() { const uint8_t *rp = &srcptr[(k * width + l) << 2]; - if (rp[3] < alpha_treshold) + if (rp[3] < alpha_threshold) continue; closest_color[0] = rp[0]; diff --git a/core/io/compression.cpp b/core/io/compression.cpp index f806c4da6d..8c8f0b3655 100644 --- a/core/io/compression.cpp +++ b/core/io/compression.cpp @@ -52,23 +52,22 @@ int Compression::compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size, } } break; - case MODE_DEFLATE: { + case MODE_DEFLATE: + case MODE_GZIP: { + + int window_bits = p_mode == MODE_DEFLATE ? 15 : 15 + 16; z_stream strm; strm.zalloc = zipio_alloc; strm.zfree = zipio_free; strm.opaque = Z_NULL; - int level = GLOBAL_GET("compression/zlib/compression_level"); - int err = deflateInit(&strm, level); + int level = p_mode == MODE_DEFLATE ? GLOBAL_GET("compression/zlib/compression_level") : GLOBAL_GET("compression/gzip/compression_level"); + int err = deflateInit2(&strm, level, Z_DEFLATED, window_bits, 8, Z_DEFAULT_STRATEGY); if (err != Z_OK) return -1; strm.avail_in = p_src_size; int aout = deflateBound(&strm, p_src_size); - /*if (aout>p_src_size) { - deflateEnd(&strm); - return -1; - }*/ strm.avail_out = aout; strm.next_in = (Bytef *)p_src; strm.next_out = p_dst; @@ -100,13 +99,16 @@ int Compression::get_max_compressed_buffer_size(int p_src_size, Mode p_mode) { return ss; } break; - case MODE_DEFLATE: { + case MODE_DEFLATE: + case MODE_GZIP: { + + int window_bits = p_mode == MODE_DEFLATE ? 15 : 15 + 16; z_stream strm; strm.zalloc = zipio_alloc; strm.zfree = zipio_free; strm.opaque = Z_NULL; - int err = deflateInit(&strm, Z_DEFAULT_COMPRESSION); + int err = deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, window_bits, 8, Z_DEFAULT_STRATEGY); if (err != Z_OK) return -1; int aout = deflateBound(&strm, p_src_size); @@ -138,7 +140,10 @@ int Compression::decompress(uint8_t *p_dst, int p_dst_max_size, const uint8_t *p } return ret_size; } break; - case MODE_DEFLATE: { + case MODE_DEFLATE: + case MODE_GZIP: { + + int window_bits = p_mode == MODE_DEFLATE ? 15 : 15 + 16; z_stream strm; strm.zalloc = zipio_alloc; @@ -146,7 +151,7 @@ int Compression::decompress(uint8_t *p_dst, int p_dst_max_size, const uint8_t *p strm.opaque = Z_NULL; strm.avail_in = 0; strm.next_in = Z_NULL; - int err = inflateInit(&strm); + int err = inflateInit2(&strm, window_bits); ERR_FAIL_COND_V(err != Z_OK, -1); strm.avail_in = p_src_size; diff --git a/core/io/compression.h b/core/io/compression.h index 742f0f4d68..bc39fc4185 100644 --- a/core/io/compression.h +++ b/core/io/compression.h @@ -37,7 +37,8 @@ public: enum Mode { MODE_FASTLZ, MODE_DEFLATE, - MODE_ZSTD + MODE_ZSTD, + MODE_GZIP }; static int compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size, Mode p_mode = MODE_ZSTD); diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index b474c2e078..728cd5d4ff 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -29,6 +29,7 @@ /*************************************************************************/ #include "resource_format_binary.h" #include "global_config.h" +#include "image.h" #include "io/file_access_compressed.h" #include "io/marshalls.h" #include "os/dir_access.h" @@ -54,7 +55,6 @@ enum { VARIANT_TRANSFORM = 17, VARIANT_MATRIX32 = 18, VARIANT_COLOR = 20, - //VARIANT_IMAGE = 21, - no longer variant type VARIANT_NODE_PATH = 22, VARIANT_RID = 23, VARIANT_OBJECT = 24, @@ -70,7 +70,13 @@ enum { VARIANT_VECTOR2_ARRAY = 37, VARIANT_INT64 = 40, VARIANT_DOUBLE = 41, - +#ifndef DISABLE_DEPRECATED + VARIANT_IMAGE = 21, // - no longer variant type + IMAGE_ENCODING_EMPTY = 0, + IMAGE_ENCODING_RAW = 1, + IMAGE_ENCODING_LOSSLESS = 2, + IMAGE_ENCODING_LOSSY = 3, +#endif OBJECT_EMPTY = 0, OBJECT_EXTERNAL_RESOURCE = 1, OBJECT_INTERNAL_RESOURCE = 2, @@ -541,7 +547,69 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { w = PoolVector<Color>::Write(); r_v = array; } break; +#ifndef DISABLE_DEPRECATED + case VARIANT_IMAGE: { + uint32_t encoding = f->get_32(); + if (encoding == IMAGE_ENCODING_EMPTY) { + r_v = Ref<Image>(); + break; + } else if (encoding == IMAGE_ENCODING_RAW) { + uint32_t width = f->get_32(); + uint32_t height = f->get_32(); + uint32_t mipmaps = f->get_32(); + uint32_t format = f->get_32(); + const uint32_t format_version_shift = 24; + const uint32_t format_version_mask = format_version_shift - 1; + + uint32_t format_version = format >> format_version_shift; + + const uint32_t current_version = 0; + if (format_version > current_version) { + + ERR_PRINT("Format version for encoded binary image is too new"); + return ERR_PARSE_ERROR; + } + + Image::Format fmt = Image::Format(format & format_version_mask); //if format changes, we can add a compatibility bit on top + + uint32_t datalen = f->get_32(); + + PoolVector<uint8_t> imgdata; + imgdata.resize(datalen); + PoolVector<uint8_t>::Write w = imgdata.write(); + f->get_buffer(w.ptr(), datalen); + _advance_padding(datalen); + w = PoolVector<uint8_t>::Write(); + + Ref<Image> image; + image.instance(); + image->create(width, height, mipmaps, fmt, imgdata); + r_v = image; + + } else { + //compressed + PoolVector<uint8_t> data; + data.resize(f->get_32()); + PoolVector<uint8_t>::Write w = data.write(); + f->get_buffer(w.ptr(), data.size()); + w = PoolVector<uint8_t>::Write(); + + Ref<Image> image; + if (encoding == IMAGE_ENCODING_LOSSY && Image::lossy_unpacker) { + + image = Image::lossy_unpacker(data); + } else if (encoding == IMAGE_ENCODING_LOSSLESS && Image::lossless_unpacker) { + + image = Image::lossless_unpacker(data); + } + _advance_padding(data.size()); + + r_v = image; + } + + } break; +#endif default: { ERR_FAIL_V(ERR_FILE_CORRUPT); } break; @@ -1644,7 +1712,6 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant get_string_index(np.get_property()); } break; - default: {} } } diff --git a/core/io/translation_loader_po.cpp b/core/io/translation_loader_po.cpp index 6104608961..1a670b0ab0 100644 --- a/core/io/translation_loader_po.cpp +++ b/core/io/translation_loader_po.cpp @@ -51,6 +51,8 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error, const S Ref<Translation> translation = Ref<Translation>(memnew(Translation)); int line = 1; + bool skip_this; + bool skip_next; while (true) { @@ -60,9 +62,10 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error, const S if (status == STATUS_READING_STRING) { - if (msg_id != "") - translation->add_message(msg_id, msg_str); - else if (config == "") + if (msg_id != "") { + if (!skip_this) + translation->add_message(msg_id, msg_str); + } else if (config == "") config = msg_str; break; @@ -85,15 +88,18 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error, const S ERR_FAIL_V(RES()); } - if (msg_id != "") - translation->add_message(msg_id, msg_str); - else if (config == "") + if (msg_id != "") { + if (!skip_this) + translation->add_message(msg_id, msg_str); + } else if (config == "") config = msg_str; l = l.substr(5, l.length()).strip_edges(); status = STATUS_READING_ID; msg_id = ""; msg_str = ""; + skip_this = skip_next; + skip_next = false; } if (l.begins_with("msgstr")) { @@ -110,6 +116,9 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error, const S } if (l == "" || l.begins_with("#")) { + if (l.find("fuzzy") != -1) { + skip_next = true; + } line++; continue; //nothing to read or comment } diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp index 838fec22f0..04e4383f03 100644 --- a/core/math/a_star.cpp +++ b/core/math/a_star.cpp @@ -123,6 +123,12 @@ void AStar::disconnect_points(int p_id, int p_with_id) { a->neighbours.erase(b); b->neighbours.erase(a); } + +bool AStar::has_point(int p_id) const { + + return points.has(p_id); +} + bool AStar::are_points_connected(int p_id, int p_with_id) const { Segment s(p_id, p_with_id); @@ -400,6 +406,7 @@ void AStar::_bind_methods() { ClassDB::bind_method(D_METHOD("get_point_pos", "id"), &AStar::get_point_pos); 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); 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/a_star.h b/core/math/a_star.h index 34a5358344..ebf1407c17 100644 --- a/core/math/a_star.h +++ b/core/math/a_star.h @@ -104,6 +104,7 @@ public: Vector3 get_point_pos(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; void connect_points(int p_id, int p_with_id, bool bidirectional = true); void disconnect_points(int p_id, int p_with_id); diff --git a/core/math/audio_frame.h b/core/math/audio_frame.h index 5ccc9d9e5e..d54f622197 100644 --- a/core/math/audio_frame.h +++ b/core/math/audio_frame.h @@ -102,6 +102,16 @@ struct AudioFrame { r = ::undenormalise(r); } + _FORCE_INLINE_ AudioFrame linear_interpolate(const AudioFrame &p_b, float p_t) const { + + AudioFrame res = *this; + + res.l += (p_t * (p_b.l - l)); + res.r += (p_t * (p_b.r - r)); + + return res; + } + _ALWAYS_INLINE_ AudioFrame(float p_l, float p_r) { l = p_l; r = p_r; diff --git a/core/math/face3.cpp b/core/math/face3.cpp index 5b66e1999a..0e292500bf 100644 --- a/core/math/face3.cpp +++ b/core/math/face3.cpp @@ -272,8 +272,8 @@ void Face3::project_range(const Vector3 &p_normal, const Transform &p_transform, void Face3::get_support(const Vector3 &p_normal, const Transform &p_transform, Vector3 *p_vertices, int *p_count, int p_max) const { -#define _FACE_IS_VALID_SUPPORT_TRESHOLD 0.98 -#define _EDGE_IS_VALID_SUPPORT_TRESHOLD 0.05 +#define _FACE_IS_VALID_SUPPORT_THRESHOLD 0.98 +#define _EDGE_IS_VALID_SUPPORT_THRESHOLD 0.05 if (p_max <= 0) return; @@ -281,7 +281,7 @@ void Face3::get_support(const Vector3 &p_normal, const Transform &p_transform, V Vector3 n = p_transform.basis.xform_inv(p_normal); /** TEST FACE AS SUPPORT **/ - if (get_plane().normal.dot(n) > _FACE_IS_VALID_SUPPORT_TRESHOLD) { + if (get_plane().normal.dot(n) > _FACE_IS_VALID_SUPPORT_THRESHOLD) { *p_count = MIN(3, p_max); @@ -318,7 +318,7 @@ void Face3::get_support(const Vector3 &p_normal, const Transform &p_transform, V // check if edge is valid as a support real_t dot = (vertex[i] - vertex[(i + 1) % 3]).normalized().dot(n); dot = ABS(dot); - if (dot < _EDGE_IS_VALID_SUPPORT_TRESHOLD) { + if (dot < _EDGE_IS_VALID_SUPPORT_THRESHOLD) { *p_count = MIN(2, p_max); diff --git a/core/math/vector3.h b/core/math/vector3.h index 7dfcedd0da..6a7974681e 100644 --- a/core/math/vector3.h +++ b/core/math/vector3.h @@ -100,6 +100,7 @@ struct Vector3 { _FORCE_INLINE_ Vector3 abs() const; _FORCE_INLINE_ Vector3 floor() const; + _FORCE_INLINE_ Vector3 sign() const; _FORCE_INLINE_ Vector3 ceil() const; _FORCE_INLINE_ real_t distance_to(const Vector3 &p_b) const; @@ -187,6 +188,11 @@ Vector3 Vector3::abs() const { return Vector3(Math::abs(x), Math::abs(y), Math::abs(z)); } +Vector3 Vector3::sign() const { + + return Vector3(SGN(x), SGN(y), SGN(z)); +} + Vector3 Vector3::floor() const { return Vector3(Math::floor(x), Math::floor(y), Math::floor(z)); diff --git a/core/object.cpp b/core/object.cpp index 3416cd8c5a..9184fb9cd0 100644 --- a/core/object.cpp +++ b/core/object.cpp @@ -1655,7 +1655,7 @@ void Object::_bind_methods() { ClassDB::bind_method(D_METHOD("get_script:Script"), &Object::get_script); ClassDB::bind_method(D_METHOD("set_meta", "name", "value"), &Object::set_meta); - ClassDB::bind_method(D_METHOD("get_meta", "name", "value"), &Object::get_meta); + ClassDB::bind_method(D_METHOD("get_meta:Variant", "name", "value"), &Object::get_meta); ClassDB::bind_method(D_METHOD("has_meta", "name"), &Object::has_meta); ClassDB::bind_method(D_METHOD("get_meta_list"), &Object::_get_meta_list_bind); @@ -1817,6 +1817,23 @@ uint32_t Object::get_edited_version() const { } #endif +void *Object::get_script_instance_binding(int p_script_language_index) { +#ifdef DEBUG_ENABLED + ERR_FAIL_INDEX_V(p_script_language_index, MAX_SCRIPT_INSTANCE_BINDINGS, NULL); +#endif + + //it's up to the script language to make this thread safe, if the function is called twice due to threads being out of syncro + //just return the same pointer. + //if you want to put a big lock in the entire function and keep allocated pointers in a map or something, feel free to do it + //as it should not really affect performance much (won't be called too often), as in far most caes the condition below will be false afterwards + + if (!_script_instance_bindings[p_script_language_index]) { + _script_instance_bindings[p_script_language_index] = ScriptServer::get_language(p_script_language_index)->alloc_instance_binding_data(this); + } + + return _script_instance_bindings[p_script_language_index]; +} + Object::Object() { _class_ptr = NULL; @@ -1826,6 +1843,7 @@ Object::Object() { _instance_ID = ObjectDB::add_instance(this); _can_translate = true; _is_queued_for_deletion = false; + memset(_script_instance_bindings, 0, sizeof(void *) * MAX_SCRIPT_INSTANCE_BINDINGS); script_instance = NULL; #ifdef TOOLS_ENABLED @@ -1877,6 +1895,12 @@ Object::~Object() { ObjectDB::remove_instance(this); _instance_ID = 0; _predelete_ok = 2; + + for (int i = 0; i < MAX_SCRIPT_INSTANCE_BINDINGS; i++) { + if (_script_instance_bindings[i]) { + ScriptServer::get_language(i)->free_instance_binding_data(_script_instance_bindings[i]); + } + } } bool predelete_handler(Object *p_object) { diff --git a/core/object.h b/core/object.h index f87705c48b..556f3f1586 100644 --- a/core/object.h +++ b/core/object.h @@ -381,6 +381,10 @@ public: }; private: + enum { + MAX_SCRIPT_INSTANCE_BINDINGS = 8 + }; + #ifdef DEBUG_ENABLED friend class _ObjectDebugLock; #endif @@ -447,6 +451,8 @@ private: void _set_bind(const String &p_set, const Variant &p_value); Variant _get_bind(const String &p_name) const; + void *_script_instance_bindings[MAX_SCRIPT_INSTANCE_BINDINGS]; + void property_list_changed_notify(); protected: @@ -683,6 +689,9 @@ public: bool editor_is_section_unfolded(const String &p_section); #endif + //used by script languages to store binding data + void *get_script_instance_binding(int p_script_language_index); + void clear_internal_resource_paths(); Object(); diff --git a/core/os/os.h b/core/os/os.h index 11fe8b44e3..cafd1f4e14 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -179,6 +179,8 @@ public: virtual void set_borderless_window(int p_borderless) {} virtual bool get_borderless_window() { return 0; } + virtual void set_ime_position(const Point2 &p_pos) {} + virtual Error open_dynamic_library(const String p_path, void *&p_library_handle) { return ERR_UNAVAILABLE; }; virtual Error close_dynamic_library(void *p_library_handle) { return ERR_UNAVAILABLE; }; virtual Error get_dynamic_library_symbol_handle(void *p_library_handle, const String p_name, void *&p_symbol_handle) { return ERR_UNAVAILABLE; }; diff --git a/core/script_language.cpp b/core/script_language.cpp index 72f0acec3b..4a7fdc9d64 100644 --- a/core/script_language.cpp +++ b/core/script_language.cpp @@ -66,11 +66,6 @@ bool ScriptServer::is_scripting_enabled() { return scripting_enabled; } -int ScriptServer::get_language_count() { - - return _language_count; -} - ScriptLanguage *ScriptServer::get_language(int p_idx) { ERR_FAIL_INDEX_V(p_idx, _language_count, NULL); diff --git a/core/script_language.h b/core/script_language.h index 6e39593a89..a81300233f 100644 --- a/core/script_language.h +++ b/core/script_language.h @@ -57,7 +57,7 @@ public: static void set_scripting_enabled(bool p_enabled); static bool is_scripting_enabled(); - static int get_language_count(); + _FORCE_INLINE_ static int get_language_count() { return _language_count; } static ScriptLanguage *get_language(int p_idx); static void register_language(ScriptLanguage *p_language); static void unregister_language(ScriptLanguage *p_language); @@ -274,6 +274,9 @@ public: virtual int profiling_get_accumulated_data(ProfilingInfo *p_info_arr, int p_info_max) = 0; virtual int profiling_get_frame_data(ProfilingInfo *p_info_arr, int p_info_max) = 0; + virtual void *alloc_instance_binding_data(Object *p_object) { return NULL; } //optional, not used by all languages + virtual void free_instance_binding_data(void *p_data) {} //optional, not used by all languages + virtual void frame(); virtual ~ScriptLanguage(){}; diff --git a/core/self_list.h b/core/self_list.h index 9edf735f7b..e229d5bf8e 100644 --- a/core/self_list.h +++ b/core/self_list.h @@ -51,6 +51,25 @@ public: _first->_prev = p_elem; _first = p_elem; } + void add_last(SelfList<T> *p_elem) { + + ERR_FAIL_COND(p_elem->_root); + + if (!_first) { + add(p_elem); + return; + } + + SelfList<T> *e = _first; + + while (e->next()) { + e = e->next(); + } + + e->_next = p_elem; + p_elem->_prev = e->_next; + p_elem->_root = this; + } void remove(SelfList<T> *p_elem) { diff --git a/core/sort.h b/core/sort.h index a45eb8865a..06c427f61e 100644 --- a/core/sort.h +++ b/core/sort.h @@ -46,7 +46,7 @@ class SortArray { enum { - INTROSORT_TRESHOLD = 16 + INTROSORT_THRESHOLD = 16 }; public: @@ -180,7 +180,7 @@ public: inline void introsort(int p_first, int p_last, T *p_array, int p_max_depth) const { - while (p_last - p_first > INTROSORT_TRESHOLD) { + while (p_last - p_first > INTROSORT_THRESHOLD) { if (p_max_depth == 0) { partial_sort(p_first, p_last, p_last, p_array); @@ -273,9 +273,9 @@ public: inline void final_insertion_sort(int p_first, int p_last, T *p_array) const { - if (p_last - p_first > INTROSORT_TRESHOLD) { - insertion_sort(p_first, p_first + INTROSORT_TRESHOLD, p_array); - unguarded_insertion_sort(p_first + INTROSORT_TRESHOLD, p_last, p_array); + if (p_last - p_first > INTROSORT_THRESHOLD) { + insertion_sort(p_first, p_first + INTROSORT_THRESHOLD, p_array); + unguarded_insertion_sort(p_first + INTROSORT_THRESHOLD, p_last, p_array); } else { insertion_sort(p_first, p_last, p_array); diff --git a/core/variant_call.cpp b/core/variant_call.cpp index 6936a362e1..4a806aec6c 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -516,7 +516,7 @@ struct _VariantCall { PoolByteArray compressed; Compression::Mode mode = (Compression::Mode)(int)(*p_args[0]); - compressed.resize(Compression::get_max_compressed_buffer_size(ba->size())); + compressed.resize(Compression::get_max_compressed_buffer_size(ba->size(), mode)); int result = Compression::compress(compressed.write().ptr(), ba->read().ptr(), ba->size(), mode); result = result >= 0 ? result : 0; |